PageRenderTime 71ms CodeModel.GetById 39ms RepoModel.GetById 1ms app.codeStats 0ms

/thankslist.php

https://github.com/Vexilurz/phpbb_forum
PHP | 380 lines | 314 code | 41 blank | 25 comment | 49 complexity | 2e48d18cac89a011554c90083098e378 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package phpBB3
  5. * @version $Id: thankslist.php,v 123 2009-06-11 10:02:51 Палыч$
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. define('IN_PHPBB', true);
  14. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  15. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  16. include($phpbb_root_path . 'common.' . $phpEx);
  17. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  18. include($phpbb_root_path . 'includes/functions_thanks.' . $phpEx);
  19. // Start session management
  20. $user->session_begin();
  21. $auth->acl($user->data);
  22. $user->setup(array('memberlist', 'groups', 'mods/thanks_mod', 'search'));
  23. // Grab data
  24. $mode = request_var('mode', '');
  25. $author_id = request_var('author_id', ANONYMOUS);
  26. $give = request_var('give', '');
  27. $row_number = 0;
  28. $givens = array();
  29. $reseved = array();
  30. $rowsp = array();
  31. $rowsu = array();
  32. $total_users = 0;
  33. if (!$auth->acl_gets('u_viewthanks'))
  34. {
  35. if ($user->data['user_id'] != ANONYMOUS)
  36. {
  37. trigger_error('NO_VIEW_USERS');
  38. }
  39. login_box('', ((isset($user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)])) ? $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)] : $user->lang['LOGIN_EXPLAIN_MEMBERLIST']));
  40. }
  41. $start = request_var('start', 0);
  42. $submit = (isset($_POST['submit'])) ? true : false;
  43. $default_key = 'a';
  44. $sort_key = request_var('sk', $default_key);
  45. $sort_dir = request_var('sd', 'a');
  46. $topic_id = request_var('t', 0);
  47. $return_chars = request_var('ch', ($topic_id) ? -1 : 300);
  48. $order_by = '';
  49. switch ($mode)
  50. {
  51. case 'givens':
  52. $per_page = $config['posts_per_page'];
  53. $total_match_count = 0;
  54. $page_title = $user->lang['SEARCH'];
  55. $template_html = 'thanks_results.html';
  56. switch ($give)
  57. {
  58. case 'true':
  59. $u_search = append_sid("{$phpbb_root_path}thankslist.$phpEx", "mode=givens&amp;author_id=$author_id&amp;give=true");
  60. $sql = 'SELECT COUNT(user_id) AS "total_match_count"
  61. FROM ' . THANKS_TABLE . "
  62. WHERE user_id = $author_id";
  63. $where = 'user_id';
  64. break;
  65. case 'false':
  66. $u_search = append_sid("{$phpbb_root_path}thankslist.$phpEx", "mode=givens&amp;author_id=$author_id&amp;give=false");
  67. $sql = 'SELECT COUNT(DISTINCT post_id) as "total_match_count"
  68. FROM ' . THANKS_TABLE . "
  69. WHERE poster_id = $author_id";
  70. $where = 'poster_id';
  71. break;
  72. }
  73. $result = $db->sql_query($sql);
  74. if (!$row = $db->sql_fetchrow($result))
  75. {
  76. break;
  77. }
  78. else
  79. {
  80. $total_match_count = $row['total_match_count'];
  81. $db->sql_freeresult($result);
  82. $sql_array = array(
  83. 'SELECT' => 'u.username, u.user_colour, p.poster_id, p.post_id, p.topic_id, p.forum_id, p.post_time, p.post_subject, p.post_text, p.post_username, p.bbcode_bitfield, p.bbcode_uid, p.post_attachment',
  84. 'FROM' => array (THANKS_TABLE => 't'),
  85. 'WHERE' => 't.' . $where . "= $author_id"
  86. );
  87. $sql_array['LEFT_JOIN'][] = array(
  88. 'FROM' => array(USERS_TABLE => 'u'),
  89. 'ON' => 't.poster_id = u.user_id'
  90. );
  91. $sql_array['LEFT_JOIN'][] = array(
  92. 'FROM' => array(POSTS_TABLE => 'p'),
  93. 'ON' => 't.post_id = p.post_id'
  94. );
  95. $sql = $db->sql_build_query('SELECT_DISTINCT', $sql_array);
  96. $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
  97. if (!$row = $db->sql_fetchrow($result))
  98. {
  99. break;
  100. }
  101. else
  102. {
  103. $bbcode_bitfield = $text_only_message = '';
  104. do
  105. {
  106. // We pre-process some variables here for later usage
  107. $row['post_text'] = censor_text($row['post_text']);
  108. $text_only_message = $row['post_text'];
  109. // make list items visible as such
  110. if ($row['bbcode_uid'])
  111. {
  112. $text_only_message = str_replace('[*:' . $row['bbcode_uid'] . ']', '&sdot;&nbsp;', $text_only_message);
  113. // no BBCode in text only message
  114. strip_bbcode($text_only_message, $row['bbcode_uid']);
  115. }
  116. if ($return_chars == -1 || utf8_strlen($text_only_message) < ($return_chars + 3))
  117. {
  118. $row['display_text_only'] = false;
  119. $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
  120. // Does this post have an attachment? If so, add it to the list
  121. if ($row['post_attachment'] && $config['allow_attachments'])
  122. {
  123. $attach_list[$row['forum_id']][] = $row['post_id'];
  124. }
  125. }
  126. else
  127. {
  128. $row['post_text'] = $text_only_message;
  129. $row['display_text_only'] = true;
  130. }
  131. $rowset[] = $row;
  132. unset($text_only_message);
  133. // Instantiate BBCode if needed
  134. if ($bbcode_bitfield !== '')
  135. {
  136. include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
  137. $bbcode = new bbcode(base64_encode($bbcode_bitfield));
  138. }
  139. // Replace naughty words such as farty pants
  140. $row['post_subject'] = censor_text($row['post_subject']);
  141. if ($row['display_text_only'])
  142. {
  143. $row['post_text'] = bbcode_nl2br($row['post_text']);
  144. }
  145. else
  146. {
  147. // Second parse bbcode here
  148. if ($row['bbcode_bitfield'])
  149. {
  150. $bbcode->bbcode_second_pass($row['post_text'], $row['bbcode_uid'], $row['bbcode_bitfield']);
  151. }
  152. $row['post_text'] = bbcode_nl2br($row['post_text']);
  153. $row['post_text'] = smiley_text($row['post_text']);
  154. }
  155. $forum_id = $row['forum_id'];
  156. $template->assign_block_vars('searchresults', array (
  157. 'POST_AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
  158. 'POST_AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
  159. 'POST_AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
  160. 'U_POST_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
  161. 'POST_SUBJECT' => ($auth->acl_get('f_read', $row['forum_id'])) ? $row['post_subject'] : '',
  162. 'POST_DATE' => (!empty($row['post_time'])) ? $user->format_date($row['post_time']) : '',
  163. 'MESSAGE' => ($auth->acl_get('f_read', $row['forum_id'])) ? $row['post_text'] : $user->lang['SORRY_AUTH_READ'],
  164. 'FORUM_ID' => $row['forum_id'],
  165. 'TOPIC_ID' => $row['topic_id'],
  166. 'POST_ID' => $row['post_id'],
  167. 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']),
  168. 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']),
  169. 'U_VIEW_POST' => (!empty($row['post_id'])) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=" . $row['topic_id'] . '&amp;p=' . $row['post_id']) . '#p' . $row['post_id'] : '',
  170. ));
  171. }
  172. while ($row = $db->sql_fetchrow($result));
  173. $db->sql_freeresult($result);
  174. }
  175. }
  176. if ($total_match_count > 1000)
  177. {
  178. $total_match_count--;
  179. $l_search_matches = sprintf($user->lang['FOUND_MORE_SEARCH_MATCHES'], $total_match_count);
  180. }
  181. else
  182. {
  183. $l_search_matches = ($total_match_count == 1) ? sprintf($user->lang['FOUND_SEARCH_MATCH'], $total_match_count) : sprintf($user->lang['FOUND_SEARCH_MATCHES'], $total_match_count);
  184. }
  185. $template->assign_vars(array(
  186. 'PAGINATION' => generate_pagination($u_search, $total_match_count, $per_page, $start),
  187. 'PAGE_NUMBER' => on_page($total_match_count, $per_page, $start),
  188. 'TOTAL_MATCHES' => $total_match_count,
  189. 'SEARCH_MATCHES' => $l_search_matches,
  190. 'U_THANKS' => append_sid("{$phpbb_root_path}thankslist.$phpEx"),
  191. ));
  192. break;
  193. default:
  194. $page_title = $user->lang['THANKS_USER'];
  195. $template_html = 'thankslist_body.html';
  196. // Sorting
  197. $sort_key_text = array('a' => $user->lang['SORT_USERNAME'], 'b' => $user->lang['SORT_LOCATION'], 'c' => $user->lang['SORT_JOINED'], 'd' => $user->lang['SORT_POST_COUNT']);
  198. $sort_key_sql = array('a' => 'u.username_clean', 'b' => 'u.user_from', 'c' => 'u.user_regdate', 'd' => 'u.user_posts');
  199. $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
  200. if ($auth->acl_get('u_viewonline'))
  201. {
  202. $sort_key_text['l'] = $user->lang['SORT_LAST_ACTIVE'];
  203. $sort_key_sql['l'] = 'u.user_lastvisit';
  204. }
  205. $s_sort_key = '';
  206. foreach ($sort_key_text as $key => $value)
  207. {
  208. $selected = ($sort_key == $key) ? ' selected="selected"' : '';
  209. $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  210. }
  211. $s_sort_dir = '';
  212. foreach ($sort_dir_text as $key => $value)
  213. {
  214. $selected = ($sort_dir == $key) ? ' selected="selected"' : '';
  215. $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  216. }
  217. // Sorting and order
  218. if (!isset($sort_key_sql[$sort_key]))
  219. {
  220. $sort_key = $default_key;
  221. }
  222. $order_by .= $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
  223. // Build a relevant pagination_url
  224. $params = $sort_params = array();
  225. $pagination_url = append_sid("{$phpbb_root_path}thankslist.$phpEx", implode('&amp;', $params));
  226. $sort_url = append_sid("{$phpbb_root_path}thankslist.$phpEx", implode('&amp;', $sort_params));
  227. unset($search_params, $sort_params);
  228. // Grab relevant data
  229. $sql = 'SELECT user_id, COUNT(*) AS "count"
  230. FROM ' . THANKS_TABLE . "
  231. GROUP BY user_id";
  232. $result = $db->sql_query($sql);
  233. while ($row = $db->sql_fetchrow($result))
  234. {
  235. $givens[$row['user_id']] = $row['count'];
  236. }
  237. $db->sql_freeresult($result);
  238. $sql = 'SELECT poster_id, COUNT(*) AS "count"
  239. FROM ' . THANKS_TABLE . "
  240. GROUP BY poster_id";
  241. $result = $db->sql_query($sql);
  242. while ($row = $db->sql_fetchrow($result))
  243. {
  244. $reseved[$row['poster_id']] = $row['count'];
  245. }
  246. $db->sql_freeresult($result);
  247. $sql = 'SELECT DISTINCT poster_id
  248. FROM ' . THANKS_TABLE;
  249. $result = $db->sql_query($sql);
  250. while ($row = $db->sql_fetchrow($result))
  251. {
  252. $rowsp[] = $row['poster_id'];
  253. }
  254. $sql = 'SELECT DISTINCT user_id
  255. FROM ' . THANKS_TABLE;
  256. $result = $db->sql_query($sql);
  257. while ($row = $db->sql_fetchrow($result))
  258. {
  259. $rowsu[] = $row['user_id'];
  260. }
  261. $rows = array_merge($rowsp,$rowsu);
  262. $total_users = count(array_unique($rows));
  263. if (empty($rows))
  264. {
  265. break;
  266. }
  267. $sql_array = array(
  268. 'SELECT' => 'u.user_id, u.username, u.user_posts, u.user_colour, u.user_rank, u.user_inactive_reason, u.user_type, u.username_clean, u.user_regdate, u.user_website, u.user_from, u.user_lastvisit',
  269. 'FROM' => array(USERS_TABLE => 'u'),
  270. 'ORDER_BY' => $order_by,
  271. );
  272. $sql_array['WHERE'] = "u.user_id = $rows[0]";
  273. for ($i = 1, $end = sizeof($rows); $i < $end; ++$i)
  274. {
  275. $sql_array['WHERE'] .= " OR u.user_id = $rows[$i]";
  276. }
  277. $sql = $db->sql_build_query('SELECT', $sql_array);
  278. $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
  279. if (!$row = $db->sql_fetchrow($result))
  280. {
  281. trigger_error('NO_USER');
  282. }
  283. else
  284. {
  285. do
  286. {
  287. $last_visit = $row['user_lastvisit'];
  288. $user_id = $row['user_id'];
  289. $rank_title = $rank_img = $rank_img_src = '';
  290. get_user_rank($row['user_rank'], (($user_id == ANONYMOUS) ? false : $row['user_posts']), $rank_title, $rank_img, $rank_img_src);
  291. $template->assign_block_vars('memberrow', array(
  292. 'ROW_NUMBER' => $row_number + ($start + 1),
  293. 'RANK_TITLE' => $rank_title,
  294. 'RANK_IMG' => $rank_img,
  295. 'RANK_IMG_SRC' => $rank_img_src,
  296. 'GIVENS' => (!isset($givens[$user_id])) ? 0 : $givens[$user_id],
  297. 'RECEIVED' => (!isset($reseved[$user_id])) ? 0 : $reseved[$user_id],
  298. 'JOINED' => $user->format_date($row['user_regdate']),
  299. 'VISITED' => (empty($last_visit)) ? ' - ' : $user->format_date($last_visit),
  300. 'POSTS' => ($row['user_posts']) ? $row['user_posts'] : 0,
  301. 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
  302. 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
  303. 'USER_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
  304. 'U_VIEW_PROFILE' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
  305. 'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id=$user_id&amp;sr=posts") : '',
  306. 'U_SEARCH_USER_GIVENS' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}thankslist.$phpEx", "mode=givens&amp;author_id=$user_id&amp;give=true") : '',
  307. 'U_SEARCH_USER_RECEIVED'=> ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}thankslist.$phpEx", "mode=givens&amp;author_id=$user_id&amp;give=false") : '',
  308. 'L_VIEWING_PROFILE' => sprintf($user->lang['VIEWING_PROFILE'], $row['username']),
  309. 'LOCATION' => ($row['user_from']) ? $row['user_from'] : '',
  310. 'U_WWW' => (!empty($row['user_website'])) ? $row['user_website'] : '',
  311. 'VISITED' => (empty($last_visit)) ? ' - ' : $user->format_date($last_visit),
  312. ));
  313. $row_number++;
  314. }
  315. while ($row = $db->sql_fetchrow($result));
  316. $db->sql_freeresult($result);
  317. $template->assign_vars(array(
  318. 'PAGE_NUMBER' => on_page($total_users, $config['topics_per_page'], $start),
  319. 'PAGINATION' => generate_pagination($pagination_url, $total_users, $config['topics_per_page'], $start),
  320. 'U_SORT_POSTS' => $sort_url . '&amp;sk=d&amp;sd=' . (($sort_key == 'd' && $sort_dir == 'a') ? 'd' : 'a'),
  321. 'U_SORT_USERNAME' => $sort_url . '&amp;sk=a&amp;sd=' . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a'),
  322. 'U_SORT_FROM' => $sort_url . '&amp;sk=b&amp;sd=' . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'),
  323. 'U_SORT_JOINED' => $sort_url . '&amp;sk=c&amp;sd=' . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a'),
  324. 'U_SORT_ACTIVE' => ($auth->acl_get('u_viewonline')) ? $sort_url . '&amp;sk=l&amp;sd=' . (($sort_key == 'l' && $sort_dir == 'a') ? 'd' : 'a') : '',
  325. ));
  326. }
  327. break;
  328. }
  329. // Output the page
  330. $template->assign_vars(array(
  331. 'TOTAL_USERS' => ($total_users == 1) ? $user->lang['LIST_USER'] : sprintf($user->lang['LIST_USERS'], $total_users),
  332. 'U_THANKS' => append_sid("{$phpbb_root_path}thankslist.$phpEx"),
  333. ));
  334. page_header($page_title);
  335. $template->set_filenames(array(
  336. 'body' => $template_html));
  337. make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
  338. page_footer();
  339. ?>