PageRenderTime 24ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/album_mod/album_memberlist.php

http://github.com/MightyGorgon/icy_phoenix
PHP | 344 lines | 235 code | 55 blank | 54 comment | 33 complexity | 5c1e1b67c0c61c7476d690015d16da24 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. *
  12. * @Extra credits for this file
  13. * IdleVoid (idlevoid@slater.dk)
  14. *
  15. */
  16. if (!defined('IN_ICYPHOENIX'))
  17. {
  18. die('Hacking attempt');
  19. }
  20. // ------------------------------------------------------------------------
  21. // $album_user_id, $cat_id and $moderators_list are as default set
  22. // in album.php file in the main folder.
  23. // ------------------------------------------------------------------------
  24. // ------------------------------------------------------------------------
  25. // Get the name of this user
  26. // ------------------------------------------------------------------------
  27. $username = album_get_user_name($album_user_id);
  28. if (empty($username))
  29. {
  30. if (!defined('STATUS_404')) define('STATUS_404', true);
  31. message_die(GENERAL_MESSAGE, 'NO_USER');
  32. }
  33. // ------------------------------------
  34. // Build the thumbnail page
  35. // ------------------------------------
  36. if (check_http_var_exists('type', false))
  37. {
  38. $album_view_type = request_var('type', '');
  39. }
  40. $start = request_var('start', 0);
  41. $start = ($start < 0) ? 0 : $start;
  42. $pics_per_page = $album_config['rows_per_page'] * $album_config['cols_per_page'];
  43. $limit_sql = ($start == 0) ? $pics_per_page : $start .','. $pics_per_page;
  44. // set some initial values...
  45. // $allowed_cat is set in album.php !!!
  46. $list_sql = '';
  47. $count_sql = '';
  48. //$album_view_type = ALBUM_LISTTYPE_PICTURES;
  49. switch (strtolower($album_view_type))
  50. {
  51. case ALBUM_LISTTYPE_RATINGS:
  52. $album_view_type = ALBUM_LISTTYPE_RATINGS;
  53. // default sorting if not specified directly
  54. if (!isset($_GET['sort_method']) && !isset($_POST['sort_method']))
  55. {
  56. $sort_method = 'rating';
  57. $sort_order = 'ASC';
  58. }
  59. $count_sql = 'SELECT COUNT(rate_pic_id) AS count
  60. FROM '. ALBUM_RATE_TABLE .', '. ALBUM_TABLE .', '.ALBUM_CAT_TABLE .'
  61. WHERE rate_user_id = '. $album_user_id .'
  62. AND cat_id IN (' . $allowed_cat .')
  63. AND pic_id = rate_pic_id
  64. AND pic_cat_id = cat_id';
  65. $list_sql = "SELECT DISTINCT(p.pic_id), ct.cat_user_id, ct.cat_id, ct.cat_title, p.pic_title, p.pic_desc, p.pic_user_id, p.pic_user_ip, p.pic_time, p.pic_view_count, p.pic_lock, r.rate_pic_id, r.rate_pic_id,
  66. AVG(r.rate_point) AS rating, COUNT(DISTINCT c.comment_id) AS comments, MAX(c.comment_id) as new_comment
  67. FROM ".ALBUM_RATE_TABLE." AS r
  68. LEFT JOIN ".ALBUM_TABLE. " AS p ON p.pic_id = r.rate_pic_id
  69. LEFT JOIN ".ALBUM_COMMENT_TABLE." AS c ON p.pic_id = c.comment_pic_id
  70. LEFT JOIN ".ALBUM_CAT_TABLE." AS ct ON p.pic_cat_id = ct.cat_id
  71. WHERE r.rate_user_id = $album_user_id AND ct.cat_id IN ($allowed_cat)
  72. GROUP BY r.rate_pic_id
  73. ORDER BY $sort_method $sort_order
  74. LIMIT $limit_sql";
  75. break;
  76. case ALBUM_LISTTYPE_COMMENTS:
  77. $album_view_type = ALBUM_LISTTYPE_COMMENTS;
  78. // default sorting if not specified directly
  79. if (!isset($_GET['sort_method']) && !isset($_POST['sort_method']))
  80. {
  81. $sort_method = 'comments';
  82. $sort_order = 'ASC';
  83. }
  84. $count_sql = 'SELECT COUNT(comment_id) AS count
  85. FROM '. ALBUM_COMMENT_TABLE .', '. ALBUM_CAT_TABLE .'
  86. WHERE comment_user_id = '. $album_user_id .'
  87. AND cat_id IN (' . $allowed_cat .')
  88. AND comment_cat_id = cat_id';
  89. $list_sql = "SELECT DISTINCT(p.pic_id), ct.cat_user_id, ct.cat_id, ct.cat_title, p.pic_title, p.pic_desc, p.pic_user_id, p.pic_user_ip, p.pic_time, p.pic_view_count, p.pic_lock, r.rate_pic_id,
  90. AVG(r.rate_point) AS rating, COUNT(DISTINCT c.comment_id) AS comments, MAX(c.comment_id) as new_comment, c.comment_pic_id
  91. FROM ".ALBUM_COMMENT_TABLE." AS c
  92. LEFT JOIN ".ALBUM_TABLE. " AS p ON c.comment_pic_id = p.pic_id
  93. LEFT JOIN ".ALBUM_RATE_TABLE." AS r ON p.pic_id = r.rate_pic_id
  94. LEFT JOIN ".ALBUM_CAT_TABLE." AS ct ON p.pic_cat_id = ct.cat_id
  95. WHERE c.comment_user_id = $album_user_id AND ct.cat_id IN ($allowed_cat)
  96. GROUP BY c.comment_pic_id
  97. ORDER BY $sort_method $sort_order
  98. LIMIT $limit_sql";
  99. break;
  100. default:
  101. $album_view_type = ALBUM_LISTTYPE_PICTURES;
  102. $count_sql = 'SELECT COUNT(pic_id) AS count
  103. FROM '. ALBUM_TABLE .', '. ALBUM_CAT_TABLE .'
  104. WHERE pic_user_id = '. $album_user_id . '
  105. AND cat_id IN (' . $allowed_cat .')
  106. AND pic_cat_id = cat_id';
  107. $list_sql = "SELECT DISTINCT(p.pic_id), ct.cat_user_id, ct.cat_id, ct.cat_title, p.pic_title, p.pic_desc, p.pic_user_id, p.pic_user_ip, p.pic_time, p.pic_view_count, p.pic_lock, r.rate_pic_id,
  108. AVG(r.rate_point) AS rating, COUNT(DISTINCT c.comment_id) AS comments, MAX(c.comment_id) as new_comment
  109. FROM ".ALBUM_TABLE. " AS p
  110. LEFT JOIN ".ALBUM_RATE_TABLE." AS r ON p.pic_id = r.rate_pic_id
  111. LEFT JOIN ".ALBUM_COMMENT_TABLE." AS c ON p.pic_id = c.comment_pic_id
  112. LEFT JOIN ".ALBUM_CAT_TABLE." AS ct ON p.pic_cat_id = ct.cat_id
  113. WHERE p.pic_user_id = $album_user_id AND ct.cat_id IN ($allowed_cat)
  114. GROUP BY p.pic_id
  115. ORDER BY $sort_method $sort_order
  116. LIMIT $limit_sql";
  117. }
  118. // ------------------------------------
  119. // Count pics, comments or ratings
  120. // ------------------------------------
  121. $result = $db->sql_query($count_sql);
  122. $row = $db->sql_fetchrow($result);
  123. $total_pics = $row['count'];
  124. // ------------------------------------
  125. // Build up
  126. // ------------------------------------
  127. $album_view_mode_param = (!empty($album_view_mode)) ? '&mode=' . $album_view_mode : '';
  128. $album_view_type_param = (!empty($album_view_type)) ? '&type=' . $album_view_type : '';
  129. if ($total_pics > 0 && !empty($allowed_cat))
  130. {
  131. $result = $db->sql_query($list_sql);
  132. $picrow = array();
  133. while($row = $db->sql_fetchrow($result))
  134. {
  135. $picrow[] = $row;
  136. }
  137. // --------------------------------
  138. // Thumbnails table
  139. // --------------------------------
  140. for ($i = 0; $i < sizeof($picrow); $i += $album_config['cols_per_page'])
  141. {
  142. $template->assign_block_vars('picrow', array());
  143. for ($j = $i; $j < ($i + $album_config['cols_per_page']); $j++)
  144. {
  145. if($j >= sizeof($picrow))
  146. {
  147. break;
  148. }
  149. $pic_preview = '';
  150. $pic_preview_hs = '';
  151. if ($album_config['lb_preview'])
  152. {
  153. $slideshow_cat = '';
  154. $slideshow = !empty($slideshow_cat) ? ', { slideshowGroup: \'' . $slideshow_cat . '\' } ' : '';
  155. $pic_preview_hs = ' class="highslide" onclick="return hs.expand(this' . $slideshow . ');"';
  156. $pic_preview = 'onmouseover="showtrail(\'' . append_sid(album_append_uid('album_picm.' . PHP_EXT . '?pic_id=' . $picrow[$j]['pic_id'])) . '\',\'' . addslashes($picrow[$j]['pic_title']) . '\', ' . $album_config['midthumb_width'] . ', ' . $album_config['midthumb_height'] . ')" onmouseout="hidetrail()"';
  157. }
  158. $template_vars = array(
  159. 'PIC_PREVIEW_HS' => $pic_preview_hs,
  160. 'PIC_PREVIEW' => $pic_preview,
  161. );
  162. album_build_column_vars($template_vars, $picrow[$j]);
  163. $template->assign_block_vars('picrow.piccol', $template_vars);
  164. // is a personal category that the picture belongs to AND
  165. // is it the main category in the personal gallery ?
  166. if ($picrow[$j]['cat_user_id'] != 0 && $picrow[$j]['cat_id'] == album_get_personal_root_id($picrow[$j]['cat_user_id']))
  167. {
  168. $album_page_url = 'album.' . PHP_EXT;
  169. }
  170. else
  171. {
  172. $album_page_url = 'album_cat.' . PHP_EXT;
  173. }
  174. $image_cat_url = append_sid(album_append_uid($album_page_url . '?cat_id=' . $picrow[$j]['cat_id'] . '&amp;user_id=' . $picrow[$j]['cat_user_id']));
  175. $template_vars = array(
  176. // 'POSTER' => $memberlist_poster,
  177. 'PIC_PREVIEW_HS' => $pic_preview_hs,
  178. 'PIC_PREVIEW' => $pic_preview,
  179. 'CATEGORY' => $picrow[$j]['cat_title'],
  180. 'U_PIC_CAT' => $image_cat_url,
  181. 'GROUP_NAME' => 'memberlist',
  182. );
  183. album_build_detail_vars($template_vars, $picrow[$j]);
  184. // $template_vars['TITLE'] = htmlspecialchars($picrow[$j]['pic_title']);
  185. $template->assign_block_vars('picrow.pic_detail', $template_vars);
  186. }
  187. }
  188. // --------------------------------
  189. // Pagination
  190. // --------------------------------
  191. $template->assign_vars(array(
  192. 'PAGINATION' => generate_pagination(append_sid(album_append_uid('album.' . PHP_EXT . '?user_id=' . $album_user_id . '&amp;sort_method=' . $sort_method . '&amp;sort_order=' . $sort_order . $album_view_mode_param . $album_view_type_param)), $total_pics, $pics_per_page, $start),
  193. 'PAGE_NUMBER' => sprintf($lang['Page_of'], (floor($start / $pics_per_page) + 1), ceil($total_pics / $pics_per_page))
  194. )
  195. );
  196. }
  197. else
  198. {
  199. $template->assign_block_vars('no_pics', array());
  200. $template->assign_vars(array('S_NO_PICS' => '1'));
  201. }
  202. /*
  203. +----------------------------------------------------------
  204. | Main page...
  205. +----------------------------------------------------------
  206. */
  207. // ------------------------------------
  208. // additional sorting options
  209. // ------------------------------------
  210. $sort_rating_option = '';
  211. $sort_comments_option = '';
  212. if($album_config['rate'] == 1)
  213. {
  214. $sort_rating_option = '<option value="rating" ';
  215. $sort_rating_option .= ($sort_method == 'rating') ? 'selected="selected"' : '';
  216. $sort_rating_option .= '>' . $lang['Rating'] .'</option>';
  217. }
  218. if($album_config['comment'] == 1)
  219. {
  220. $sort_comments_option = '<option value="comments" ';
  221. $sort_comments_option .= ($sort_method == 'comments') ? 'selected="selected"' : '';
  222. $sort_comments_option .= '>' . $lang['Comments'] .'</option>';
  223. $sort_new_comment_option = '<option value="new_comment" ';
  224. $sort_new_comment_option .= ($sort_method == 'new_comment') ? 'selected="selected"' : '';
  225. $sort_new_comment_option .= '>' . $lang['New_Comment'] .'</option>';
  226. }
  227. // Start output of page
  228. $meta_content['page_title'] = $lang['Album'];
  229. $meta_content['description'] = '';
  230. $meta_content['keywords'] = '';
  231. $template_to_parse = 'album_memberlist_body.tpl';
  232. switch (strtolower($album_view_type))
  233. {
  234. case 'comment':
  235. $template->assign_block_vars('switch_show_all_pics', array());
  236. $template->assign_block_vars('switch_show_all_ratings', array());
  237. $list_title = sprintf($lang['Comment_List_Of_User'], $username);
  238. break;
  239. case 'rating':
  240. $template->assign_block_vars('switch_show_all_pics', array());
  241. $template->assign_block_vars('switch_show_all_comments', array());
  242. $list_title = sprintf($lang['Rating_List_Of_User'], $username);
  243. break;
  244. default:
  245. $template->assign_block_vars('switch_show_all_ratings', array());
  246. $template->assign_block_vars('switch_show_all_comments', array());
  247. $list_title = sprintf($lang['Picture_List_Of_User'], $username);
  248. }
  249. $template->assign_block_vars('switch_show_album_search', array());
  250. $template->assign_vars(array(
  251. 'TARGET_BLANK' => ($album_config['fullpic_popup']) ? 'target="_blank"' : '',
  252. 'S_COLS' => $album_config['cols_per_page'],
  253. 'S_COL_WIDTH' => (100/$album_config['cols_per_page']) . '%',
  254. 'S_THUMBNAIL_SIZE' => $album_config['thumbnail_size'],
  255. 'L_NO_PICTURES_BY_USER' => $lang['No_Pics'],
  256. 'U_MEMBERLIST_GALLERY' => append_sid(album_append_uid('album.' . PHP_EXT . '?user_id=' . $album_user_id . '&amp;mode=' . $album_view_mode . '&amp;type=' . $album_view_type)),
  257. 'L_MEMBERLIST_GALLERY_EXPLAIN' => $lang['Member_Picture_List_Explain'],
  258. 'U_SHOW_ALL_PICS' => append_sid(album_append_uid('album.' . PHP_EXT . '?user_id=' . $album_user_id . $album_view_mode_param . '&amp;type=pic')),
  259. 'L_SHOW_ALL_PICS' => sprintf($lang['Show_All_Pictures_Of_user'], $username),
  260. 'SHOW_ALL_PICS_IMG' => $images['show_all_pics'],
  261. 'U_SHOW_ALL_RATINGS' => append_sid(album_append_uid('album.' . PHP_EXT . '?user_id=' . $album_user_id . $album_view_mode_param . '&amp;type=rating')),
  262. 'L_SHOW_ALL_RATINGS' => sprintf($lang['Show_All_Ratings_Of_user'], $username),
  263. 'SHOW_ALL_RATINGS_IMG' => $images['show_all_ratings'],
  264. 'U_SHOW_ALL_COMMENTS' => append_sid(album_append_uid('album.' . PHP_EXT . '?user_id=' . $album_user_id . $album_view_mode_param . '&amp;type=comment')),
  265. 'L_SHOW_ALL_COMMENTS' => sprintf($lang['Show_All_Comments_Of_user'], $username),
  266. 'SHOW_ALL_COMMENTS_IMG' => $images['show_all_comments'],
  267. 'L_PICTURES_OF_USER' => $list_title,
  268. 'L_PIC_ID' => $lang['Pic_ID'],
  269. 'L_PIC_TITLE' => $lang['Pic_Image'],
  270. 'L_PIC_CAT' => $lang['Pic_Cat'],
  271. 'L_POSTED' => $lang['Posted'],
  272. 'L_VIEW' => $lang['View'],
  273. 'L_TIME' => $lang['Time'],
  274. 'L_SELECT_SORT_METHOD' => $lang['Select_sort_method'],
  275. 'L_ORDER' => $lang['Order'],
  276. 'L_SORT' => $lang['Sort'],
  277. 'SORT_TIME' => ($sort_method == 'pic_time') ? 'selected="selected"' : '',
  278. 'SORT_PIC_TITLE' => ($sort_method == 'pic_title') ? 'selected="selected"' : '',
  279. 'SORT_VIEW' => ($sort_method == 'pic_view_count') ? 'selected="selected"' : '',
  280. 'SORT_RATING_OPTION' => $sort_rating_option,
  281. 'SORT_COMMENTS_OPTION' => $sort_comments_option,
  282. 'SORT_NEW_COMMENT_OPTION' => $sort_new_comment_option,
  283. 'L_ASC' => $lang['Sort_Ascending'],
  284. 'L_DESC' => $lang['Sort_Descending'],
  285. 'SORT_ASC' => ($sort_order == 'ASC') ? 'selected="selected"' : '',
  286. 'SORT_DESC' => ($sort_order == 'DESC') ? 'selected="selected"' : ''
  287. )
  288. );
  289. ?>