PageRenderTime 42ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/cpgdbal/plugins/usergal_alphatabs/codebase.php

https://github.com/cpg-contrib/coppermine
PHP | 354 lines | 308 code | 24 blank | 22 comment | 31 complexity | bb359b2155623227c56ff179ea156ec3 MD5 | raw file
  1. <?php
  2. /*************************
  3. Coppermine Photo Gallery
  4. ************************
  5. Copyright (c) 2003-2008 Dev Team
  6. v1.1 originally written by Gregory DEMAR
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License version 3
  9. as published by the Free Software Foundation.
  10. ********************************************
  11. Coppermine version: 1.5.0
  12. $HeadURL: https://coppermine.svn.sourceforge.net/svnroot/coppermine/trunk/cpg1.5.x/plugins/usergal_alphatabs/codebase.php $
  13. $Revision: 5129 $
  14. $LastChangedBy: gaugau $
  15. $Date: 2008-10-18 16:03:12 +0530 (Sat, 18 Oct 2008) $
  16. **********************************************/
  17. if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');
  18. define('CORE_PLUGIN', true);
  19. $superCage = Inspekt::makeSuperCage();
  20. if ($superCage->get->keyExists('cat') && $superCage->get->getInt('cat') == USER_GAL_CAT){
  21. if ($superCage->get->keyExists('letter')) {
  22. $thisplugin->add_action('page_start','bridge_extender');
  23. }
  24. function makejumpbox(){
  25. global $lang_plugin_php;
  26. starttable('100%', $lang_plugin_php['usergal_alphatabs_jump_by_username'], 26);
  27. echo '<tr>';
  28. foreach (range('A', 'Z') as $letter){
  29. echo '<td width="'.(100/26).'%" align="center"><a href="index.php?cat=1&letter='.$letter.'"> '.$letter.' </a></td>';
  30. }
  31. echo '</tr>';
  32. endtable();
  33. }
  34. function theme_display_thumbnails(&$thumb_list, $nbThumb, $album_name, $aid, $cat, $page, $total_pages, $sort_options, $display_tabs, $mode = 'thumb')
  35. {
  36. global $CONFIG;
  37. global $template_thumb_view_title_row,$template_fav_thumb_view_title_row, $lang_thumb_view, $template_tab_display, $template_thumbnail_view, $lang_album_list;
  38. $superCage = Inspekt::makeSuperCage();
  39. static $header = '';
  40. static $thumb_cell = '';
  41. static $empty_cell = '';
  42. static $row_separator = '';
  43. static $footer = '';
  44. static $tabs = '';
  45. static $spacer = '';
  46. if ($header == '') {
  47. $thumb_cell = template_extract_block($template_thumbnail_view, 'thumb_cell');
  48. $tabs = template_extract_block($template_thumbnail_view, 'tabs');
  49. $header = template_extract_block($template_thumbnail_view, 'header');
  50. $empty_cell = template_extract_block($template_thumbnail_view, 'empty_cell');
  51. $row_separator = template_extract_block($template_thumbnail_view, 'row_separator');
  52. $footer = template_extract_block($template_thumbnail_view, 'footer');
  53. $spacer = template_extract_block($template_thumbnail_view, 'spacer');
  54. }
  55. $cat_link = is_numeric($aid) ? '' : '&amp;cat=' . $cat;
  56. $theme_thumb_tab_tmpl = $template_tab_display;
  57. if ($mode == 'thumb') {
  58. $theme_thumb_tab_tmpl['left_text'] = strtr($theme_thumb_tab_tmpl['left_text'], array('{LEFT_TEXT}' => $aid == 'lastalb' ? $lang_album_list['album_on_page'] : $lang_thumb_view['pic_on_page']));
  59. $theme_thumb_tab_tmpl['inactive_tab'] = strtr($theme_thumb_tab_tmpl['inactive_tab'], array('{LINK}' => 'thumbnails.php?album=' . $aid . $cat_link . '&amp;page=%d'));
  60. $theme_thumb_tab_tmpl['inactive_next_tab'] = strtr($theme_thumb_tab_tmpl['inactive_next_tab'], array('{LINK}' => 'thumbnails.php?album=' . $aid . $cat_link . '&amp;page=%d'));
  61. $theme_thumb_tab_tmpl['inactive_prev_tab'] = strtr($theme_thumb_tab_tmpl['inactive_prev_tab'], array('{LINK}' => 'thumbnails.php?album=' . $aid . $cat_link . '&amp;page=%d'));
  62. } else {
  63. // start of modified section
  64. $pl = $superCage->get->getAlpha('letter') ? ('&amp;letter=' . $superCage->get->getAlpha('letter')) : '';
  65. $theme_thumb_tab_tmpl['left_text'] = strtr($theme_thumb_tab_tmpl['left_text'], array('{LEFT_TEXT}' => $lang_thumb_view['user_on_page']));
  66. $theme_thumb_tab_tmpl['inactive_tab'] = strtr($theme_thumb_tab_tmpl['inactive_tab'], array('{LINK}' => 'index.php?cat=' . $cat . '&amp;page=%d' . $pl));
  67. $theme_thumb_tab_tmpl['inactive_next_tab'] = strtr($theme_thumb_tab_tmpl['inactive_next_tab'], array('{LINK}' => 'index.php?cat=' . $cat . '&amp;page=%d' . $pl));
  68. $theme_thumb_tab_tmpl['inactive_prev_tab'] = strtr($theme_thumb_tab_tmpl['inactive_prev_tab'], array('{LINK}' => 'index.php?cat=' . $cat . '&amp;page=%d' . $pl));
  69. // end of modified section
  70. }
  71. $thumbcols = $CONFIG['thumbcols'];
  72. $cell_width = ceil(100 / $CONFIG['thumbcols']) . '%';
  73. $tabs_html = $display_tabs ? create_tabs($nbThumb, $page, $total_pages, $theme_thumb_tab_tmpl) : '';
  74. // The sort order options are not available for meta albums
  75. if ($sort_options) {
  76. $param = array('{ALBUM_NAME}' => $album_name,
  77. '{AID}' => $aid,
  78. '{PAGE}' => $page,
  79. '{NAME}' => $lang_thumb_view['name'],
  80. '{TITLE}' => $lang_thumb_view['title'],
  81. '{DATE}' => $lang_thumb_view['date'],
  82. '{SORT_TA}' => $lang_thumb_view['sort_ta'],
  83. '{SORT_TD}' => $lang_thumb_view['sort_td'],
  84. '{SORT_NA}' => $lang_thumb_view['sort_na'],
  85. '{SORT_ND}' => $lang_thumb_view['sort_nd'],
  86. '{SORT_DA}' => $lang_thumb_view['sort_da'],
  87. '{SORT_DD}' => $lang_thumb_view['sort_dd'],
  88. '{POSITION}' => $lang_thumb_view['position'],
  89. '{SORT_PA}' => $lang_thumb_view['sort_pa'],
  90. '{SORT_PD}' => $lang_thumb_view['sort_pd'],
  91. );
  92. $title = template_eval($template_thumb_view_title_row, $param);
  93. } else if ($aid == 'favpics' && $CONFIG['enable_zipdownload'] == 1) { //Lots of stuff can be added here later
  94. $param = array('{ALBUM_NAME}' => $album_name,
  95. '{DOWNLOAD_ZIP}'=>$lang_thumb_view['download_zip']
  96. );
  97. $title = template_eval($template_fav_thumb_view_title_row, $param);
  98. }else{
  99. $title = $album_name;
  100. }
  101. if ($mode == 'thumb') {
  102. starttable('100%', $title, $thumbcols);
  103. } else {
  104. makejumpbox();
  105. starttable('100%');
  106. }
  107. echo $header;
  108. $i = 0;
  109. foreach($thumb_list as $thumb) {
  110. $i++;
  111. if ($mode == 'thumb') {
  112. if ($aid == 'lastalb') {
  113. $params = array('{CELL_WIDTH}' => $cell_width,
  114. '{LINK_TGT}' => "thumbnails.php?album={$thumb['aid']}",
  115. '{THUMB}' => $thumb['image'],
  116. '{CAPTION}' => $thumb['caption'],
  117. '{ADMIN_MENU}' => $thumb['admin_menu']
  118. );
  119. } else {
  120. $params = array('{CELL_WIDTH}' => $cell_width,
  121. '{LINK_TGT}' => "displayimage.php?album=$aid$cat_link&amp;pos={$thumb['pos']}",
  122. '{THUMB}' => $thumb['image'],
  123. '{CAPTION}' => $thumb['caption'],
  124. '{ADMIN_MENU}' => $thumb['admin_menu']
  125. );
  126. }
  127. } else {
  128. $params = array('{CELL_WIDTH}' => $cell_width,
  129. '{LINK_TGT}' => "index.php?cat={$thumb['cat']}",
  130. '{THUMB}' => $thumb['image'],
  131. '{CAPTION}' => $thumb['caption'],
  132. '{ADMIN_MENU}' => ''
  133. );
  134. }
  135. echo template_eval($thumb_cell, $params);
  136. if ((($i % $thumbcols) == 0) && ($i < count($thumb_list))) {
  137. echo $row_separator;
  138. }
  139. }
  140. for (;($i % $thumbcols); $i++) {
  141. echo $empty_cell;
  142. }
  143. echo $footer;
  144. if ($display_tabs) {
  145. $params = array('{THUMB_COLS}' => $thumbcols,
  146. '{TABS}' => $tabs_html
  147. );
  148. echo template_eval($tabs, $params);
  149. }
  150. endtable();
  151. echo $spacer;
  152. }
  153. function bridge_extender()
  154. {
  155. global $cpg_udb, $cpg_db_usergal_alphatabs;
  156. ##################### DB ######################
  157. $cpgdb =& cpgDB::getInstance();
  158. $cpgdb->connect_to_existing($CONFIG['LINK_ID']);
  159. ##################################################
  160. eval('
  161. class new_udb_class extends '. get_class($cpg_udb) . ' {
  162. function new_udb_class() {}
  163. function list_users_query(&$user_count)
  164. {
  165. global $CONFIG, $FORBIDDEN_SET, $PAGE;
  166. $superCage = Inspekt::makeSuperCage();
  167. $getLetter = $superCage->get->getAlpha("letter");
  168. $f =& $this->field;
  169. if ($FORBIDDEN_SET != "") {
  170. $forbidden_with_icon = "AND ($FORBIDDEN_SET or p.galleryicon=p.pid)";
  171. $forbidden = "AND ($FORBIDDEN_SET)";
  172. } else {
  173. $forbidden_with_icon = "";
  174. $forbidden = "";
  175. }
  176. $users_per_page = $CONFIG["thumbcols"] * $CONFIG["thumbrows"];
  177. $lower_limit = ($PAGE-1) * $users_per_page;
  178. if ($this->can_join_tables){
  179. /* $sql = "SELECT {$f[\'user_id\']} as user_id,";
  180. $sql .= "{$f[\'username\']} as user_name,";
  181. $sql .= "COUNT(DISTINCT a.aid) as alb_count,";
  182. $sql .= "COUNT(DISTINCT pid) as pic_count,";
  183. $sql .= "MAX(pid) as thumb_pid, ";
  184. $sql .= "MAX(galleryicon) as gallery_pid ";
  185. $sql .= "FROM {$CONFIG[\'TABLE_ALBUMS\']} AS a ";
  186. $sql .= "INNER JOIN {$this->usertable} as u on u.{$f[\'user_id\']} = a.category - " . FIRST_USER_CAT . " ";
  187. $sql .= "INNER JOIN {$CONFIG[\'TABLE_PICTURES\']} AS p ON p.aid = a.aid ";
  188. $sql .= "WHERE ((isnull(approved) or approved=\'YES\') AND category > " . FIRST_USER_CAT . ") $forbidden_with_icon ";
  189. if ($l = $getLetter) $sql .= "AND {$f[\'username\']} LIKE \'$l%\' ";
  190. $sql .= "GROUP BY category ";
  191. $sql .= "ORDER BY category ";
  192. //$sql .= "LIMIT $lower_limit, $users_per_page ";
  193. $result = cpg_db_query($sql);
  194. while ($row = mysql_fetch_array($result)) {
  195. $users[] = $row;
  196. }
  197. mysql_free_result($result); */
  198. ################################### DB ####################################
  199. if ($l = $getLetter) {
  200. $like = "AND {$f[\'username\']} LIKE \'$l%\' ";
  201. } else {
  202. $like = "";
  203. }
  204. $cpgdb->query($cpg_db_usergal_alphatabs[\'list_users_can_join_tables\'], $f[\'user_id\'], $this->usertable,
  205. FIRST_USER_CAT, $forbidden_with_icon, $like, $lower_limit, $users_per_page);
  206. while ($row = $cpgdb->fetchRow()) {
  207. $users[] = $row;
  208. }
  209. $cpgdb->free();
  210. ###################################################################################
  211. } else {
  212. // This is the way we collect the data without a direct join to the forums user table
  213. // This query determines which users we need to collect usernames of - ie just those which have albums with pics
  214. // and are on the page we are looking at
  215. /* $sql = "SELECT category - 10000 as user_id ";
  216. $sql .= "FROM {$CONFIG[\'TABLE_ALBUMS\']} AS a ";
  217. $sql .= "INNER JOIN {$CONFIG[\'TABLE_PICTURES\']} AS p ON p.aid = a.aid ";
  218. $sql .= "WHERE ((isnull(approved) or approved=\"YES\") ";
  219. $sql .= "AND category > " . FIRST_USER_CAT . ") $forbidden_with_icon GROUP BY category ";
  220. //$sql .= "LIMIT $lower_limit, $users_per_page ";
  221. $result = cpg_db_query($sql);
  222. $user_ids = array();
  223. while ($row = mysql_fetch_array($result)) {
  224. $user_ids[] = $row["user_id"];
  225. }
  226. mysql_free_result($result); */
  227. #################################### DB ##################################
  228. $cpgdb->query($cpg_db_usergal_alphatabs[\'user_have_alb_pics\'], FIRST_USER_CAT, $forbidden_with_icon
  229. $lower_limit, $users_per_page);
  230. $user_ids = array();
  231. while ($row = $cpgdb->fetchRow()) {
  232. $user_ids[] = $row["user_id"];
  233. }
  234. $cpgdb->free();
  235. #################################################################################
  236. $userlist = implode(",", $user_ids);
  237. // This query collects an array of user_id -> username mappings for the user ids collected above
  238. /* $sql = "SELECT {$this->field[\'user_id\']} AS user_id, {$this->field[\'username\']} AS user_name FROM {$this->usertable} WHERE {$this->field[\'user_id\']} IN ($userlist)";
  239. if ($l = $getLetter) $sql .= " AND {$f[\'username\']} LIKE \'$l%\' ";
  240. $result = cpg_db_query($sql, $this->link_id);
  241. $userdata = array();
  242. while ($row = mysql_fetch_array($result)) {
  243. $userdata[$row["user_id"]] = $row["user_name"];
  244. }
  245. mysql_free_result($result); */
  246. ###################################### DB #####################################
  247. if ($l = $getLetter) {
  248. $like = " AND {$f[\'username\']} LIKE \'$l%\' ";
  249. } else {
  250. $like = "";
  251. }
  252. $this->cpgudb->query($cpg_db_usergal_alphatabs[\'$get_user_data\'], $this->field[\'user_id\'],
  253. $this->field[\'username\'], $this->usertable, $userlist, $like);
  254. while ($row = $this->cpgudb->fetchRow()) {
  255. $userdata[$row["user_id"]] = $row["user_name"];
  256. }
  257. $this->cpgudb->free();
  258. #####################################################################################
  259. // This is the main query, similar to the one in the join implementation above but without the join to the user table
  260. // We use the pics owner_id field as the user_id instead of using category - 10000 as the user_id
  261. /* $sql = "SELECT owner_id as user_id,";
  262. $sql .= "COUNT(DISTINCT a.aid) as alb_count,";
  263. $sql .= "COUNT(DISTINCT pid) as pic_count,";
  264. $sql .= "MAX(pid) as thumb_pid, ";
  265. $sql .= "MAX(galleryicon) as gallery_pid ";
  266. $sql .= "FROM {$CONFIG[\'TABLE_ALBUMS\']} AS a ";
  267. $sql .= "INNER JOIN {$CONFIG[\'TABLE_PICTURES\']} AS p ON p.aid = a.aid ";
  268. $sql .= "WHERE ((isnull(approved) or approved=\'YES\') AND category > " . FIRST_USER_CAT . ") $forbidden_with_icon GROUP BY category ";
  269. $sql .= "ORDER BY category ";
  270. $result = cpg_db_query($sql);
  271. // Here we associate the username with the album details.
  272. while ($row = mysql_fetch_array($result)) {
  273. if (strtolower($userdata[$row["user_id"]]{0}) == strtolower($getLetter)) $users[] = array_merge($row, array("user_name" => $userdata[$row["user_id"]]));
  274. }
  275. mysql_free_result($result); */
  276. ##################################### DB ####################################
  277. $cpgdb->query($cpg_db_usergal_alphatabs[\'list_users_main_query\'], FIRST_USER_CAT, $forbidden_with_icon);
  278. // Here we associate the username with the album details.
  279. while ($row = $cpgdb->fetchRow()) {
  280. if (strtolower($userdata[$row["user_id"]]{0}) == strtolower($getLetter)) $users[] = array_merge($row, array("user_name" => $userdata[$row["user_id"]]));
  281. }
  282. $cpgdb->free();
  283. #####################################################################################
  284. }
  285. $user_count = count($users);
  286. $totalPages = ceil($user_count / $users_per_page);
  287. if ($PAGE > $totalPages) $PAGE = 1;
  288. return $users;
  289. }
  290. }
  291. ');
  292. $vars = get_object_vars($cpg_udb);
  293. $cpg_udb = new new_udb_class;
  294. foreach ($vars as $name => $value) $cpg_udb->$name = $value;
  295. }
  296. }
  297. ?>