PageRenderTime 144ms CodeModel.GetById 29ms RepoModel.GetById 6ms app.codeStats 0ms

/forum/includes/functions_display.php

https://github.com/GreyTeardrop/socionicasys-forum
PHP | 1399 lines | 1157 code | 127 blank | 115 comment | 202 complexity | 93da59312c1a050fb1c2aa9b53ec8cdc MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-3.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. *
  4. * @package phpBB3
  5. * @version $Id$
  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. if (!defined('IN_PHPBB'))
  14. {
  15. exit;
  16. }
  17. /**
  18. * Display Forums
  19. */
  20. function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
  21. {
  22. global $db, $auth, $user, $template;
  23. global $phpbb_root_path, $phpEx, $config;
  24. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  25. global $phpbb_seo;
  26. // www.phpBB-SEO.com SEO TOOLKIT END
  27. $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
  28. $parent_id = $visible_forums = 0;
  29. $sql_from = '';
  30. // Mark forums read?
  31. $mark_read = request_var('mark', '');
  32. if ($mark_read == 'all')
  33. {
  34. $mark_read = '';
  35. }
  36. if (!$root_data)
  37. {
  38. if ($mark_read == 'forums')
  39. {
  40. $mark_read = 'all';
  41. }
  42. $root_data = array('forum_id' => 0);
  43. $sql_where = '';
  44. }
  45. else
  46. {
  47. $sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
  48. }
  49. // Display list of active topics for this category?
  50. $show_active = (isset($root_data['forum_flags']) && ($root_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
  51. $sql_array = array(
  52. 'SELECT' => 'f.*',
  53. 'FROM' => array(
  54. FORUMS_TABLE => 'f'
  55. ),
  56. 'LEFT_JOIN' => array(),
  57. );
  58. if ($config['load_db_lastread'] && $user->data['is_registered'])
  59. {
  60. $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id');
  61. $sql_array['SELECT'] .= ', ft.mark_time';
  62. }
  63. else if ($config['load_anon_lastread'] || $user->data['is_registered'])
  64. {
  65. $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : '';
  66. $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
  67. if (!$user->data['is_registered'])
  68. {
  69. $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
  70. }
  71. }
  72. if ($show_active)
  73. {
  74. $sql_array['LEFT_JOIN'][] = array(
  75. 'FROM' => array(FORUMS_ACCESS_TABLE => 'fa'),
  76. 'ON' => "fa.forum_id = f.forum_id AND fa.session_id = '" . $db->sql_escape($user->session_id) . "'"
  77. );
  78. $sql_array['SELECT'] .= ', fa.user_id';
  79. }
  80. // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe
  81. if (!empty($phpbb_seo->seo_opt['no_dupe']['on'])) {
  82. $sql_array['SELECT'] .= ', t.topic_id, t.topic_title, t.topic_replies, t.topic_replies_real, t.topic_status, t.topic_type, t.topic_moved_id' . (!empty($phpbb_seo->seo_opt['sql_rewrite']) ? ', t.topic_url ' : ' ');
  83. $sql_array['LEFT_JOIN'][] = array(
  84. 'FROM' => array(TOPICS_TABLE => 't'),
  85. 'ON' => "f.forum_last_post_id = t.topic_last_post_id"
  86. );
  87. }
  88. // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe
  89. $sql = $db->sql_build_query('SELECT', array(
  90. 'SELECT' => $sql_array['SELECT'],
  91. 'FROM' => $sql_array['FROM'],
  92. 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
  93. 'WHERE' => $sql_where,
  94. 'ORDER_BY' => 'f.left_id',
  95. ));
  96. $result = $db->sql_query($sql);
  97. $forum_tracking_info = array();
  98. $branch_root_id = $root_data['forum_id'];
  99. // Check for unread global announcements (index page only)
  100. $ga_unread = false;
  101. if ($root_data['forum_id'] == 0)
  102. {
  103. $unread_ga_list = get_unread_topics($user->data['user_id'], 'AND t.forum_id = 0', '', 1);
  104. if (!empty($unread_ga_list))
  105. {
  106. $ga_unread = true;
  107. }
  108. }
  109. while ($row = $db->sql_fetchrow($result))
  110. {
  111. $forum_id = $row['forum_id'];
  112. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  113. $phpbb_seo->set_url($row['forum_name'], $forum_id, 'forum');
  114. // www.phpBB-SEO.com SEO TOOLKIT END
  115. // Mark forums read?
  116. if ($mark_read == 'forums' || $mark_read == 'all')
  117. {
  118. if ($auth->acl_get('f_list', $forum_id))
  119. {
  120. $forum_ids[] = $forum_id;
  121. continue;
  122. }
  123. }
  124. // Category with no members
  125. if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
  126. {
  127. continue;
  128. }
  129. // Skip branch
  130. if (isset($right_id))
  131. {
  132. if ($row['left_id'] < $right_id)
  133. {
  134. continue;
  135. }
  136. unset($right_id);
  137. }
  138. if (!$auth->acl_get('f_list', $forum_id))
  139. {
  140. // if the user does not have permissions to list this forum, skip everything until next branch
  141. $right_id = $row['right_id'];
  142. continue;
  143. }
  144. $forum_ids[] = $forum_id;
  145. if ($config['load_db_lastread'] && $user->data['is_registered'])
  146. {
  147. $forum_tracking_info[$forum_id] = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
  148. }
  149. else if ($config['load_anon_lastread'] || $user->data['is_registered'])
  150. {
  151. if (!$user->data['is_registered'])
  152. {
  153. $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
  154. }
  155. $forum_tracking_info[$forum_id] = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
  156. }
  157. // Count the difference of real to public topics, so we can display an information to moderators
  158. $row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && ($row['forum_topics_real'] != $row['forum_topics'])) ? $forum_id : 0;
  159. // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe
  160. if (!empty($phpbb_seo->seo_opt['no_dupe']['on'])) {
  161. if ($row['topic_status'] == ITEM_MOVED) {
  162. $row['topic_id'] = $row['topic_moved_id'];
  163. }
  164. $phpbb_seo->seo_opt['topic_forum_name'][$row['topic_id']] = $row['forum_name'];
  165. if ($auth->acl_get('m_approve', $forum_id)) {
  166. $row['forum_topics'] = $row['forum_topics_real'];
  167. $replies = $row['topic_replies_real'];
  168. } else {
  169. $row['forum_topics'] = $row['forum_topics'];
  170. $replies = $row['topic_replies'];
  171. }
  172. if (($replies + 1) > $phpbb_seo->seo_opt['topic_per_page']) {
  173. $phpbb_seo->seo_opt['topic_last_page'][$row['topic_id']] = floor($replies / $phpbb_seo->seo_opt['topic_per_page']) * $phpbb_seo->seo_opt['topic_per_page'];
  174. }
  175. } else {
  176. $row['forum_topics'] = ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics'];
  177. }
  178. // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe
  179. // Display active topics from this forum?
  180. if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS))
  181. {
  182. if (!isset($active_forum_ary['forum_topics']))
  183. {
  184. $active_forum_ary['forum_topics'] = 0;
  185. }
  186. if (!isset($active_forum_ary['forum_posts']))
  187. {
  188. $active_forum_ary['forum_posts'] = 0;
  189. }
  190. $active_forum_ary['forum_id'][] = $forum_id;
  191. $active_forum_ary['enable_icons'][] = $row['enable_icons'];
  192. $active_forum_ary['forum_topics'] += $row['forum_topics'];
  193. $active_forum_ary['forum_posts'] += $row['forum_posts'];
  194. // If this is a passworded forum we do not show active topics from it if the user is not authorised to view it...
  195. if ($row['forum_password'] && $row['user_id'] != $user->data['user_id'])
  196. {
  197. $active_forum_ary['exclude_forum_id'][] = $forum_id;
  198. }
  199. }
  200. //
  201. if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id)
  202. {
  203. if ($row['forum_type'] != FORUM_CAT)
  204. {
  205. $forum_ids_moderator[] = (int) $forum_id;
  206. }
  207. // Direct child of current branch
  208. $parent_id = $forum_id;
  209. $forum_rows[$forum_id] = $row;
  210. if ($row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id'])
  211. {
  212. $branch_root_id = $forum_id;
  213. }
  214. $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
  215. $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
  216. }
  217. else if ($row['forum_type'] != FORUM_CAT)
  218. {
  219. $subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index']) ? true : false;
  220. $subforums[$parent_id][$forum_id]['name'] = $row['forum_name'];
  221. $subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
  222. $subforums[$parent_id][$forum_id]['children'] = array();
  223. if (isset($subforums[$parent_id][$row['parent_id']]) && !$row['display_on_index'])
  224. {
  225. $subforums[$parent_id][$row['parent_id']]['children'][] = $forum_id;
  226. }
  227. if (!$forum_rows[$parent_id]['forum_id_unapproved_topics'] && $row['forum_id_unapproved_topics'])
  228. {
  229. $forum_rows[$parent_id]['forum_id_unapproved_topics'] = $forum_id;
  230. }
  231. $forum_rows[$parent_id]['forum_topics'] += $row['forum_topics'];
  232. // Do not list redirects in LINK Forums as Posts.
  233. if ($row['forum_type'] != FORUM_LINK)
  234. {
  235. $forum_rows[$parent_id]['forum_posts'] += $row['forum_posts'];
  236. }
  237. if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time'])
  238. {
  239. $forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
  240. $forum_rows[$parent_id]['forum_last_post_subject'] = $row['forum_last_post_subject'];
  241. $forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
  242. $forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
  243. $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
  244. $forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour'];
  245. $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
  246. // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe
  247. if (!empty($phpbb_seo->seo_opt['no_dupe']['on'])) {
  248. $forum_rows[$parent_id]['topic_id'] = $row['topic_id'];
  249. $forum_rows[$parent_id]['topic_title'] = $row['topic_title'];
  250. $forum_rows[$parent_id]['topic_type'] = $row['topic_type'];
  251. $forum_rows[$parent_id]['forum_password'] = $row['forum_password'];
  252. $forum_rows[$parent_id]['topic_url'] = isset($row['topic_url']) ? $row['topic_url'] : '';
  253. }
  254. // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe
  255. }
  256. }
  257. }
  258. $db->sql_freeresult($result);
  259. // Handle marking posts
  260. if ($mark_read == 'forums' || $mark_read == 'all')
  261. {
  262. $redirect = build_url(array('mark', 'hash'));
  263. $token = request_var('hash', '');
  264. if (check_link_hash($token, 'global'))
  265. {
  266. if ($mark_read == 'all')
  267. {
  268. markread('all');
  269. $message = sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>');
  270. }
  271. else
  272. {
  273. // Add 0 to forums array to mark global announcements correctly
  274. $forum_ids[] = 0;
  275. markread('topics', $forum_ids);
  276. $message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
  277. }
  278. meta_refresh(3, $redirect);
  279. trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . $message);
  280. }
  281. else
  282. {
  283. $message = sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
  284. meta_refresh(3, $redirect);
  285. trigger_error($message);
  286. }
  287. }
  288. // Grab moderators ... if necessary
  289. if ($display_moderators)
  290. {
  291. if ($return_moderators)
  292. {
  293. $forum_ids_moderator[] = $root_data['forum_id'];
  294. }
  295. get_moderators($forum_moderators, $forum_ids_moderator);
  296. }
  297. // Used to tell whatever we have to create a dummy category or not.
  298. $last_catless = true;
  299. foreach ($forum_rows as $row)
  300. {
  301. // Empty category
  302. if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT)
  303. {
  304. $template->assign_block_vars('forumrow', array(
  305. 'S_IS_CAT' => true,
  306. 'FORUM_ID' => $row['forum_id'],
  307. 'FORUM_NAME' => $row['forum_name'],
  308. 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
  309. 'FORUM_FOLDER_IMG' => '',
  310. 'FORUM_FOLDER_IMG_SRC' => '',
  311. 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang['FORUM_CAT'] . '" />' : '',
  312. 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
  313. 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
  314. );
  315. continue;
  316. }
  317. $visible_forums++;
  318. $forum_id = $row['forum_id'];
  319. $forum_unread = (isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id]) ? true : false;
  320. // Mark the first visible forum on index as unread if there's any unread global announcement
  321. if ($ga_unread && !empty($forum_ids_moderator) && $forum_id == $forum_ids_moderator[0])
  322. {
  323. $forum_unread = true;
  324. }
  325. $folder_image = $folder_alt = $l_subforums = '';
  326. $subforums_list = array();
  327. // Generate list of subforums if we need to
  328. if (isset($subforums[$forum_id]))
  329. {
  330. foreach ($subforums[$forum_id] as $subforum_id => $subforum_row)
  331. {
  332. $subforum_unread = (isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id]) ? true : false;
  333. if (!$subforum_unread && !empty($subforum_row['children']))
  334. {
  335. foreach ($subforum_row['children'] as $child_id)
  336. {
  337. if (isset($forum_tracking_info[$child_id]) && $subforums[$forum_id][$child_id]['orig_forum_last_post_time'] > $forum_tracking_info[$child_id])
  338. {
  339. // Once we found an unread child forum, we can drop out of this loop
  340. $subforum_unread = true;
  341. break;
  342. }
  343. }
  344. }
  345. if ($subforum_row['display'] && $subforum_row['name'])
  346. {
  347. $subforums_list[] = array(
  348. 'link' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $subforum_id),
  349. 'name' => $subforum_row['name'],
  350. 'unread' => $subforum_unread,
  351. );
  352. }
  353. else
  354. {
  355. unset($subforums[$forum_id][$subforum_id]);
  356. }
  357. // If one subforum is unread the forum gets unread too...
  358. if ($subforum_unread)
  359. {
  360. $forum_unread = true;
  361. }
  362. }
  363. $l_subforums = (sizeof($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';
  364. $folder_image = ($forum_unread) ? 'forum_unread_subforum' : 'forum_read_subforum';
  365. }
  366. else
  367. {
  368. switch ($row['forum_type'])
  369. {
  370. case FORUM_POST:
  371. $folder_image = ($forum_unread) ? 'forum_unread' : 'forum_read';
  372. break;
  373. case FORUM_LINK:
  374. $folder_image = 'forum_link';
  375. break;
  376. }
  377. }
  378. // Which folder should we display?
  379. if ($row['forum_status'] == ITEM_LOCKED)
  380. {
  381. $folder_image = ($forum_unread) ? 'forum_unread_locked' : 'forum_read_locked';
  382. $folder_alt = 'FORUM_LOCKED';
  383. }
  384. else
  385. {
  386. $folder_alt = ($forum_unread) ? 'UNREAD_POSTS' : 'NO_UNREAD_POSTS';
  387. }
  388. // Create last post link information, if appropriate
  389. if ($row['forum_last_post_id'])
  390. {
  391. $last_post_subject = $row['forum_last_post_subject'];
  392. $last_post_time = $user->format_date($row['forum_last_post_time']);
  393. // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe
  394. if (!empty($phpbb_seo->seo_opt['no_dupe']['on']) && !$row['forum_password'] && $auth->acl_get('f_read', $row['forum_id_last_post'])) {
  395. $phpbb_seo->prepare_iurl($row, 'topic', $row['topic_type'] == POST_GLOBAL ? $phpbb_seo->seo_static['global_announce'] : $phpbb_seo->seo_url['forum'][$row['forum_id_last_post']]);
  396. $last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&amp;t=' . $row['topic_id'] . '&amp;start=' . @intval($phpbb_seo->seo_opt['topic_last_page'][$row['topic_id']]) ) . '#p' . $row['forum_last_post_id'];
  397. $topic_title = censor_text($row['topic_title']);
  398. // Limit in chars for the last post link text.
  399. $char_limit = 25;
  400. // Limit topic text link to $char_limit, without breacking words
  401. $topic_text_lilnk = $char_limit > 0 && ( ( $length = utf8_strlen($topic_title) ) > $char_limit ) ? ( utf8_strlen($fragment = utf8_substr($topic_title, 0, $char_limit + 1 - 4)) < $length + 1 ? preg_replace('`\s*\S*$`', '', $fragment) . ' ...' : $topic_title ) : $topic_title;
  402. $last_post_link = '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&amp;t=' . $row['topic_id']) . '" title="' . $topic_title . ' : ' . $phpbb_seo->seo_opt['topic_forum_name'][$row['topic_id']] . '">' . $topic_text_lilnk . '</a>';
  403. } else {
  404. $last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&amp;p=' . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
  405. $last_post_link = '';
  406. }
  407. }
  408. else
  409. {
  410. $last_post_subject = $last_post_time = $last_post_url = $last_post_link = '';
  411. // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe
  412. }
  413. // Output moderator listing ... if applicable
  414. $l_moderator = $moderators_list = '';
  415. if ($display_moderators && !empty($forum_moderators[$forum_id]))
  416. {
  417. $l_moderator = (sizeof($forum_moderators[$forum_id]) == 1) ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
  418. $moderators_list = implode(', ', $forum_moderators[$forum_id]);
  419. }
  420. $l_post_click_count = ($row['forum_type'] == FORUM_LINK) ? 'CLICKS' : 'POSTS';
  421. $post_click_count = ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? $row['forum_posts'] : '';
  422. $s_subforums_list = array();
  423. foreach ($subforums_list as $subforum)
  424. {
  425. $s_subforums_list[] = '<a href="' . $subforum['link'] . '" class="subforum ' . (($subforum['unread']) ? 'unread' : 'read') . '" title="' . (($subforum['unread']) ? $user->lang['UNREAD_POSTS'] : $user->lang['NO_UNREAD_POSTS']) . '">' . $subforum['name'] . '</a>';
  426. }
  427. $s_subforums_list = (string) implode(', ', $s_subforums_list);
  428. $catless = ($row['parent_id'] == $root_data['forum_id']) ? true : false;
  429. if ($row['forum_type'] != FORUM_LINK)
  430. {
  431. $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
  432. }
  433. else
  434. {
  435. // If the forum is a link and we count redirects we need to visit it
  436. // If the forum is having a password or no read access we do not expose the link, but instead handle it in viewforum
  437. if (($row['forum_flags'] & FORUM_FLAG_LINK_TRACK) || $row['forum_password'] || !$auth->acl_get('f_read', $forum_id))
  438. {
  439. $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
  440. }
  441. else
  442. {
  443. $u_viewforum = $row['forum_link'];
  444. }
  445. }
  446. $template->assign_block_vars('forumrow', array(
  447. 'S_IS_CAT' => false,
  448. 'S_NO_CAT' => $catless && !$last_catless,
  449. 'S_IS_LINK' => ($row['forum_type'] == FORUM_LINK) ? true : false,
  450. 'S_UNREAD_FORUM' => $forum_unread,
  451. 'S_LOCKED_FORUM' => ($row['forum_status'] == ITEM_LOCKED) ? true : false,
  452. 'S_LIST_SUBFORUMS' => ($row['display_subforum_list']) ? true : false,
  453. 'S_SUBFORUMS' => (sizeof($subforums_list)) ? true : false,
  454. 'S_FEED_ENABLED' => ($config['feed_forum'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $row['forum_options']) && $row['forum_type'] == FORUM_POST) ? true : false,
  455. 'FORUM_ID' => $row['forum_id'],
  456. 'FORUM_NAME' => $row['forum_name'],
  457. 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
  458. 'TOPICS' => $row['forum_topics'],
  459. $l_post_click_count => $post_click_count,
  460. 'FORUM_FOLDER_IMG' => $user->img($folder_image, $folder_alt),
  461. 'FORUM_FOLDER_IMG_SRC' => $user->img($folder_image, $folder_alt, false, '', 'src'),
  462. 'FORUM_FOLDER_IMG_ALT' => isset($user->lang[$folder_alt]) ? $user->lang[$folder_alt] : '',
  463. 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
  464. 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
  465. 'LAST_POST_SUBJECT' => censor_text($last_post_subject),
  466. 'LAST_POST_TIME' => $last_post_time,
  467. 'LAST_POSTER' => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  468. 'LAST_POSTER_COLOUR' => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  469. 'LAST_POSTER_FULL' => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  470. 'MODERATORS' => $moderators_list,
  471. 'SUBFORUMS' => $s_subforums_list,
  472. 'L_SUBFORUM_STR' => $l_subforums,
  473. 'L_MODERATOR_STR' => $l_moderator,
  474. 'U_UNAPPROVED_TOPICS' => ($row['forum_id_unapproved_topics']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=unapproved_topics&amp;f=' . $row['forum_id_unapproved_topics']) : '',
  475. 'U_VIEWFORUM' => $u_viewforum,
  476. 'U_LAST_POSTER' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  477. // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe
  478. 'LAST_POST_LINK' => $last_post_link,
  479. // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe
  480. 'U_LAST_POST' => $last_post_url)
  481. );
  482. // Assign subforums loop for style authors
  483. foreach ($subforums_list as $subforum)
  484. {
  485. $template->assign_block_vars('forumrow.subforum', array(
  486. 'U_SUBFORUM' => $subforum['link'],
  487. 'SUBFORUM_NAME' => $subforum['name'],
  488. 'S_UNREAD' => $subforum['unread'])
  489. );
  490. }
  491. $last_catless = $catless;
  492. }
  493. $template->assign_vars(array(
  494. 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . '&amp;f=' . $root_data['forum_id'] . '&amp;mark=forums') : '',
  495. 'S_HAS_SUBFORUM' => ($visible_forums) ? true : false,
  496. 'L_SUBFORUM' => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'],
  497. 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
  498. 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPICS_UNAPPROVED'),
  499. ));
  500. if ($return_moderators)
  501. {
  502. return array($active_forum_ary, $forum_moderators);
  503. }
  504. return array($active_forum_ary, array());
  505. }
  506. /**
  507. * Create forum rules for given forum
  508. */
  509. function generate_forum_rules(&$forum_data)
  510. {
  511. if (!$forum_data['forum_rules'] && !$forum_data['forum_rules_link'])
  512. {
  513. return;
  514. }
  515. global $template, $phpbb_root_path, $phpEx;
  516. if ($forum_data['forum_rules'])
  517. {
  518. $forum_data['forum_rules'] = generate_text_for_display($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options']);
  519. }
  520. $template->assign_vars(array(
  521. 'S_FORUM_RULES' => true,
  522. 'U_FORUM_RULES' => $forum_data['forum_rules_link'],
  523. 'FORUM_RULES' => $forum_data['forum_rules'])
  524. );
  525. }
  526. /**
  527. * Create forum navigation links for given forum, create parent
  528. * list if currently null, assign basic forum info to template
  529. */
  530. function generate_forum_nav(&$forum_data)
  531. {
  532. global $db, $user, $template, $auth, $config;
  533. global $phpEx, $phpbb_root_path;
  534. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  535. global $phpbb_seo;
  536. // www.phpBB-SEO.com SEO TOOLKIT END
  537. if (!$auth->acl_get('f_list', $forum_data['forum_id']))
  538. {
  539. return;
  540. }
  541. // Get forum parents
  542. $forum_parents = get_forum_parents($forum_data);
  543. // Build navigation links
  544. if (!empty($forum_parents))
  545. {
  546. foreach ($forum_parents as $parent_forum_id => $parent_data)
  547. {
  548. list($parent_name, $parent_type) = array_values($parent_data);
  549. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  550. $phpbb_seo->set_url($parent_name, $parent_forum_id, 'forum');
  551. // www.phpBB-SEO.com SEO TOOLKIT END
  552. // Skip this parent if the user does not have the permission to view it
  553. if (!$auth->acl_get('f_list', $parent_forum_id))
  554. {
  555. continue;
  556. }
  557. $template->assign_block_vars('navlinks', array(
  558. 'S_IS_CAT' => ($parent_type == FORUM_CAT) ? true : false,
  559. 'S_IS_LINK' => ($parent_type == FORUM_LINK) ? true : false,
  560. 'S_IS_POST' => ($parent_type == FORUM_POST) ? true : false,
  561. 'FORUM_NAME' => $parent_name,
  562. 'FORUM_ID' => $parent_forum_id,
  563. 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $parent_forum_id))
  564. );
  565. }
  566. }
  567. $template->assign_block_vars('navlinks', array(
  568. 'S_IS_CAT' => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
  569. 'S_IS_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
  570. 'S_IS_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
  571. 'FORUM_NAME' => $forum_data['forum_name'],
  572. 'FORUM_ID' => $forum_data['forum_id'],
  573. 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_data['forum_id']))
  574. );
  575. $template->assign_vars(array(
  576. 'FORUM_ID' => $forum_data['forum_id'],
  577. 'FORUM_NAME' => $forum_data['forum_name'],
  578. 'FORUM_DESC' => generate_text_for_display($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options']),
  579. 'S_ENABLE_FEEDS_FORUM' => ($config['feed_forum'] && $forum_data['forum_type'] == FORUM_POST && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $forum_data['forum_options'])) ? true : false,
  580. ));
  581. return;
  582. }
  583. /**
  584. * Returns forum parents as an array. Get them from forum_data if available, or update the database otherwise
  585. */
  586. function get_forum_parents(&$forum_data)
  587. {
  588. global $db;
  589. $forum_parents = array();
  590. if ($forum_data['parent_id'] > 0)
  591. {
  592. if ($forum_data['forum_parents'] == '')
  593. {
  594. $sql = 'SELECT forum_id, forum_name, forum_type
  595. FROM ' . FORUMS_TABLE . '
  596. WHERE left_id < ' . $forum_data['left_id'] . '
  597. AND right_id > ' . $forum_data['right_id'] . '
  598. ORDER BY left_id ASC';
  599. $result = $db->sql_query($sql);
  600. while ($row = $db->sql_fetchrow($result))
  601. {
  602. $forum_parents[$row['forum_id']] = array($row['forum_name'], (int) $row['forum_type']);
  603. }
  604. $db->sql_freeresult($result);
  605. $forum_data['forum_parents'] = serialize($forum_parents);
  606. $sql = 'UPDATE ' . FORUMS_TABLE . "
  607. SET forum_parents = '" . $db->sql_escape($forum_data['forum_parents']) . "'
  608. WHERE parent_id = " . $forum_data['parent_id'];
  609. $db->sql_query($sql);
  610. }
  611. else
  612. {
  613. $forum_parents = unserialize($forum_data['forum_parents']);
  614. }
  615. }
  616. return $forum_parents;
  617. }
  618. /**
  619. * Generate topic pagination
  620. */
  621. function topic_generate_pagination($replies, $url)
  622. {
  623. global $config, $user;
  624. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  625. global $phpbb_seo, $phpEx;
  626. // www.phpBB-SEO.com SEO TOOLKIT END
  627. // Make sure $per_page is a valid value
  628. $per_page = ($config['posts_per_page'] <= 0) ? 1 : $config['posts_per_page'];
  629. if (($replies + 1) > $per_page)
  630. {
  631. $total_pages = ceil(($replies + 1) / $per_page);
  632. $pagination = '';
  633. $times = 1;
  634. for ($j = 0; $j < $replies + 1; $j += $per_page)
  635. {
  636. $pagination .= '<a href="' . $url . ($j == 0 ? '' : '&amp;start=' . $j) . '">' . $times . '</a>';
  637. if ($times == 1 && $total_pages > 5)
  638. {
  639. $pagination .= ' ... ';
  640. // Display the last three pages
  641. $times = $total_pages - 3;
  642. $j += ($total_pages - 4) * $per_page;
  643. }
  644. else if ($times < $total_pages)
  645. {
  646. $pagination .= '<span class="page-sep">' . $user->lang['COMMA_SEPARATOR'] . '</span>';
  647. }
  648. $times++;
  649. }
  650. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  651. if (!empty($phpbb_seo->seo_opt['url_rewrite'])) {
  652. static $pagin_find = array();
  653. static $pagin_replace = array();
  654. if (empty($pagin_find)) {
  655. $pagin_find = array(
  656. // http://example.com/a_n-y/d.i.r/with.ext
  657. '`(https?\://[a-z0-9_/\.-]+/[a-z0-9_\.-]+)(\.[a-z0-9]+)(\?[\w$%&~\-;:=,@+\. ]+)?(#[a-z0-9_\.-]+)?(&amp;|\?)start=([0-9]+)`i',
  658. // http://example.com/a_n-y/d.i.r/withoutext
  659. '`(https?\://[a-z0-9_/\.-]+/[a-z0-9_-]+)/?(\?[\w$%&~\-;:=,@+\. ]+)?(#[a-z0-9_\.-]+)?(&amp;|\?)start=([0-9]+)`i'
  660. );
  661. $pagin_replace = array(
  662. // http://example.com/a_n-y/d.i.r/with-xx.ext
  663. '\1' . $phpbb_seo->seo_delim['start'] . '\6\2\3\4',
  664. // http://example.com/a_n-y/d.i.r/withoutext/pagexx.html
  665. '\1/' . $phpbb_seo->seo_static['pagination'] . '\5' . $phpbb_seo->seo_ext['pagination'] . '\2\3'
  666. );
  667. }
  668. $pagination = preg_replace( $pagin_find, $pagin_replace, $pagination );
  669. }
  670. // www.phpBB-SEO.com SEO TOOLKIT END
  671. }
  672. else
  673. {
  674. $pagination = '';
  675. }
  676. return $pagination;
  677. }
  678. /**
  679. * Obtain list of moderators of each forum
  680. */
  681. function get_moderators(&$forum_moderators, $forum_id = false)
  682. {
  683. global $config, $template, $db, $phpbb_root_path, $phpEx, $user, $auth;
  684. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  685. global $phpbb_seo;
  686. // www.phpBB-SEO.com SEO TOOLKIT END
  687. $forum_id_ary = array();
  688. if ($forum_id !== false)
  689. {
  690. if (!is_array($forum_id))
  691. {
  692. $forum_id = array($forum_id);
  693. }
  694. // Exchange key/value pair to be able to faster check for the forum id existence
  695. $forum_id_ary = array_flip($forum_id);
  696. }
  697. $sql_array = array(
  698. 'SELECT' => 'm.*, u.user_colour, g.group_colour, g.group_type',
  699. 'FROM' => array(
  700. MODERATOR_CACHE_TABLE => 'm',
  701. ),
  702. 'LEFT_JOIN' => array(
  703. array(
  704. 'FROM' => array(USERS_TABLE => 'u'),
  705. 'ON' => 'm.user_id = u.user_id',
  706. ),
  707. array(
  708. 'FROM' => array(GROUPS_TABLE => 'g'),
  709. 'ON' => 'm.group_id = g.group_id',
  710. ),
  711. ),
  712. 'WHERE' => 'm.display_on_index = 1',
  713. );
  714. // We query every forum here because for caching we should not have any parameter.
  715. $sql = $db->sql_build_query('SELECT', $sql_array);
  716. $result = $db->sql_query($sql, 3600);
  717. while ($row = $db->sql_fetchrow($result))
  718. {
  719. $f_id = (int) $row['forum_id'];
  720. if (!isset($forum_id_ary[$f_id]))
  721. {
  722. continue;
  723. }
  724. if (!empty($row['user_id']))
  725. {
  726. $forum_moderators[$f_id][] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
  727. }
  728. else
  729. {
  730. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  731. $phpbb_seo->prepare_url('group', $row['group_name'], $row['group_id']);
  732. // www.phpBB-SEO.com SEO TOOLKIT END
  733. $group_name = (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']);
  734. if ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_viewprofile'))
  735. {
  736. $forum_moderators[$f_id][] = '<span' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . '>' . $group_name . '</span>';
  737. }
  738. else
  739. {
  740. $forum_moderators[$f_id][] = '<a' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . ' href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id']) . '">' . $group_name . '</a>';
  741. }
  742. }
  743. }
  744. $db->sql_freeresult($result);
  745. return;
  746. }
  747. /**
  748. * User authorisation levels output
  749. *
  750. * @param string $mode Can be forum or topic. Not in use at the moment.
  751. * @param int $forum_id The current forum the user is in.
  752. * @param int $forum_status The forums status bit.
  753. */
  754. function gen_forum_auth_level($mode, $forum_id, $forum_status)
  755. {
  756. global $template, $auth, $user, $config;
  757. $locked = ($forum_status == ITEM_LOCKED && !$auth->acl_get('m_edit', $forum_id)) ? true : false;
  758. $rules = array(
  759. ($auth->acl_get('f_post', $forum_id) && !$locked) ? $user->lang['RULES_POST_CAN'] : $user->lang['RULES_POST_CANNOT'],
  760. ($auth->acl_get('f_reply', $forum_id) && !$locked) ? $user->lang['RULES_REPLY_CAN'] : $user->lang['RULES_REPLY_CANNOT'],
  761. ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id) && !$locked) ? $user->lang['RULES_EDIT_CAN'] : $user->lang['RULES_EDIT_CANNOT'],
  762. ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'],
  763. );
  764. if ($config['allow_attachments'])
  765. {
  766. $rules[] = ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && !$locked) ? $user->lang['RULES_ATTACH_CAN'] : $user->lang['RULES_ATTACH_CANNOT'];
  767. }
  768. foreach ($rules as $rule)
  769. {
  770. $template->assign_block_vars('rules', array('RULE' => $rule));
  771. }
  772. return;
  773. }
  774. /**
  775. * Generate topic status
  776. */
  777. function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$folder_alt, &$topic_type)
  778. {
  779. global $user, $config;
  780. $folder = $folder_new = '';
  781. if ($topic_row['topic_status'] == ITEM_MOVED)
  782. {
  783. $topic_type = $user->lang['VIEW_TOPIC_MOVED'];
  784. $folder_img = 'topic_moved';
  785. $folder_alt = 'TOPIC_MOVED';
  786. }
  787. else
  788. {
  789. switch ($topic_row['topic_type'])
  790. {
  791. case POST_GLOBAL:
  792. $topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
  793. $folder = 'global_read';
  794. $folder_new = 'global_unread';
  795. break;
  796. case POST_ANNOUNCE:
  797. $topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT'];
  798. $folder = 'announce_read';
  799. $folder_new = 'announce_unread';
  800. break;
  801. case POST_STICKY:
  802. $topic_type = $user->lang['VIEW_TOPIC_STICKY'];
  803. $folder = 'sticky_read';
  804. $folder_new = 'sticky_unread';
  805. break;
  806. default:
  807. $topic_type = '';
  808. $folder = 'topic_read';
  809. $folder_new = 'topic_unread';
  810. // Hot topic threshold is for posts in a topic, which is replies + the first post. ;)
  811. if ($config['hot_threshold'] && ($replies + 1) >= $config['hot_threshold'] && $topic_row['topic_status'] != ITEM_LOCKED)
  812. {
  813. $folder .= '_hot';
  814. $folder_new .= '_hot';
  815. }
  816. break;
  817. }
  818. if ($topic_row['topic_status'] == ITEM_LOCKED)
  819. {
  820. $topic_type = $user->lang['VIEW_TOPIC_LOCKED'];
  821. $folder .= '_locked';
  822. $folder_new .= '_locked';
  823. }
  824. $folder_img = ($unread_topic) ? $folder_new : $folder;
  825. $folder_alt = ($unread_topic) ? 'UNREAD_POSTS' : (($topic_row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_UNREAD_POSTS');
  826. // Posted image?
  827. if (!empty($topic_row['topic_posted']) && $topic_row['topic_posted'])
  828. {
  829. $folder_img .= '_mine';
  830. }
  831. }
  832. if ($topic_row['poll_start'] && $topic_row['topic_status'] != ITEM_MOVED)
  833. {
  834. $topic_type = $user->lang['VIEW_TOPIC_POLL'];
  835. }
  836. }
  837. /**
  838. * Assign/Build custom bbcodes for display in screens supporting using of bbcodes
  839. * The custom bbcodes buttons will be placed within the template block 'custom_codes'
  840. */
  841. function display_custom_bbcodes()
  842. {
  843. global $db, $template, $user;
  844. // Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)
  845. $num_predefined_bbcodes = 22;
  846. $sql = 'SELECT bbcode_id, bbcode_tag, bbcode_helpline
  847. FROM ' . BBCODES_TABLE . '
  848. WHERE display_on_posting = 1
  849. ORDER BY bbcode_tag';
  850. $result = $db->sql_query($sql);
  851. $i = 0;
  852. while ($row = $db->sql_fetchrow($result))
  853. {
  854. // If the helpline is defined within the language file, we will use the localised version, else just use the database entry...
  855. if (isset($user->lang[strtoupper($row['bbcode_helpline'])]))
  856. {
  857. $row['bbcode_helpline'] = $user->lang[strtoupper($row['bbcode_helpline'])];
  858. }
  859. $template->assign_block_vars('custom_tags', array(
  860. 'BBCODE_NAME' => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'",
  861. 'BBCODE_ID' => $num_predefined_bbcodes + ($i * 2),
  862. 'BBCODE_TAG' => $row['bbcode_tag'],
  863. 'BBCODE_HELPLINE' => $row['bbcode_helpline'],
  864. 'A_BBCODE_HELPLINE' => str_replace(array('&amp;', '&quot;', "'", '&lt;', '&gt;'), array('&', '"', "\'", '<', '>'), $row['bbcode_helpline']),
  865. ));
  866. $i++;
  867. }
  868. $db->sql_freeresult($result);
  869. }
  870. /**
  871. * Display reasons
  872. */
  873. function display_reasons($reason_id = 0)
  874. {
  875. global $db, $user, $template;
  876. $sql = 'SELECT *
  877. FROM ' . REPORTS_REASONS_TABLE . '
  878. ORDER BY reason_order ASC';
  879. $result = $db->sql_query($sql);
  880. while ($row = $db->sql_fetchrow($result))
  881. {
  882. // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
  883. if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
  884. {
  885. $row['reason_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
  886. $row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
  887. }
  888. $template->assign_block_vars('reason', array(
  889. 'ID' => $row['reason_id'],
  890. 'TITLE' => $row['reason_title'],
  891. 'DESCRIPTION' => $row['reason_description'],
  892. 'S_SELECTED' => ($row['reason_id'] == $reason_id) ? true : false)
  893. );
  894. }
  895. $db->sql_freeresult($result);
  896. }
  897. /**
  898. * Display user activity (action forum/topic)
  899. */
  900. function display_user_activity(&$userdata)
  901. {
  902. global $auth, $template, $db, $user;
  903. global $phpbb_root_path, $phpEx;
  904. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  905. global $phpbb_seo;
  906. // www.phpBB-SEO.com SEO TOOLKIT END
  907. // Do not display user activity for users having more than 5000 posts...
  908. if ($userdata['user_posts'] > 5000)
  909. {
  910. return;
  911. }
  912. $forum_ary = array();
  913. // Do not include those forums the user is not having read access to...
  914. $forum_read_ary = $auth->acl_getf('!f_read');
  915. foreach ($forum_read_ary as $forum_id => $not_allowed)
  916. {
  917. if ($not_allowed['f_read'])
  918. {
  919. $forum_ary[] = (int) $forum_id;
  920. }
  921. }
  922. $forum_ary = array_unique($forum_ary);
  923. $forum_sql = (sizeof($forum_ary)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary, true) : '';
  924. $fid_m_approve = $auth->acl_getf('m_approve', true);
  925. $sql_m_approve = (!empty($fid_m_approve)) ? 'OR ' . $db->sql_in_set('forum_id', array_keys($fid_m_approve)) : '';
  926. // Obtain active forum
  927. $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts
  928. FROM ' . POSTS_TABLE . '
  929. WHERE poster_id = ' . $userdata['user_id'] . "
  930. AND post_postcount = 1
  931. AND (post_approved = 1
  932. $sql_m_approve)
  933. $forum_sql
  934. GROUP BY forum_id
  935. ORDER BY num_posts DESC";
  936. $result = $db->sql_query_limit($sql, 1);
  937. $active_f_row = $db->sql_fetchrow($result);
  938. $db->sql_freeresult($result);
  939. if (!empty($active_f_row))
  940. {
  941. $sql = 'SELECT forum_name
  942. FROM ' . FORUMS_TABLE . '
  943. WHERE forum_id = ' . $active_f_row['forum_id'];
  944. $result = $db->sql_query($sql, 3600);
  945. $active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name');
  946. $db->sql_freeresult($result);
  947. }
  948. // Obtain active topic
  949. $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts
  950. FROM ' . POSTS_TABLE . '
  951. WHERE poster_id = ' . $userdata['user_id'] . "
  952. AND post_postcount = 1
  953. AND (post_approved = 1
  954. $sql_m_approve)
  955. $forum_sql
  956. GROUP BY topic_id
  957. ORDER BY num_posts DESC";
  958. $result = $db->sql_query_limit($sql, 1);
  959. $active_t_row = $db->sql_fetchrow($result);
  960. $db->sql_freeresult($result);
  961. if (!empty($active_t_row))
  962. {
  963. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  964. $sql_array = array(
  965. 'SELECT' => 't.topic_title, t.topic_type ' . (!empty($phpbb_seo->seo_opt['sql_rewrite']) ? ', t.topic_url' : '') . ', f.forum_id, f.forum_name',
  966. 'FROM' => array(
  967. TOPICS_TABLE => 't',
  968. ),
  969. 'LEFT_JOIN' => array(
  970. array(
  971. 'FROM' => array(FORUMS_TABLE => 'f'),
  972. 'ON' => 'f.forum_id = t.forum_id',
  973. ),
  974. ),
  975. 'WHERE' => 't.topic_id = ' . (int) $active_t_row['topic_id']
  976. );
  977. $result = $db->sql_query($db->sql_build_query('SELECT', $sql_array));
  978. $seo_active_t_row = $db->sql_fetchrow($result);
  979. $db->sql_freeresult($result);
  980. if ($seo_active_t_row) {
  981. $active_t_row = array_merge($active_t_row, $seo_active_t_row);
  982. }
  983. // www.phpBB-SEO.com SEO TOOLKIT END
  984. }
  985. $userdata['active_t_row'] = $active_t_row;
  986. $userdata['active_f_row'] = $active_f_row;
  987. $active_f_name = $active_f_id = $active_f_count = $active_f_pct = '';
  988. if (!empty($active_f_row['num_posts']))
  989. {
  990. $active_f_name = $active_f_row['forum_name'];
  991. $active_f_id = $active_f_row['forum_id'];
  992. $active_f_count = $active_f_row['num_posts'];
  993. $active_f_pct = ($userdata['user_posts']) ? ($active_f_count / $userdata['user_posts']) * 100 : 0;
  994. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  995. $phpbb_seo->set_url($active_f_name, $active_f_id, 'forum');
  996. // www.phpBB-SEO.com SEO TOOLKIT END
  997. }
  998. $active_t_name = $active_t_id = $active_t_count = $active_t_pct = '';
  999. if (!empty($active_t_row['num_posts']))
  1000. {
  1001. $active_t_name = $active_t_row['topic_title'];
  1002. $active_t_id = $active_t_row['topic_id'];
  1003. $active_t_count = $active_t_row['num_posts'];
  1004. $active_t_pct = ($userdata['user_posts']) ? ($active_t_count / $userdata['user_posts']) * 100 : 0;
  1005. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  1006. if (!empty($seo_active_t_row)) {
  1007. $active_t_forum_id = (int) $active_t_row['forum_id'];
  1008. $phpbb_seo->set_url($active_t_row['forum_name'], $active_t_forum_id, 'forum');
  1009. $phpbb_seo->prepare_iurl($active_t_row, 'topic', $active_t_row['topic_type'] == POST_GLOBAL ? $phpbb_seo->seo_static['global_announce'] : $phpbb_seo->seo_url['forum'][$active_t_forum_id]);
  1010. }
  1011. // www.phpBB-SEO.com SEO TOOLKIT END
  1012. }
  1013. $l_active_pct = ($userdata['user_id'] != ANONYMOUS && $userdata['user_id'] == $user->data['user_id']) ? $user->lang['POST_PCT_ACTIVE_OWN'] : $user->lang['POST_PCT_ACTIVE'];
  1014. $template->assign_vars(array(
  1015. 'ACTIVE_FORUM' => $active_f_name,
  1016. 'ACTIVE_FORUM_POSTS' => ($active_f_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_f_count),
  1017. 'ACTIVE_FORUM_PCT' => sprintf($l_active_pct, $active_f_pct),
  1018. 'ACTIVE_TOPIC' => censor_text($active_t_name),
  1019. 'ACTIVE_TOPIC_POSTS' => ($active_t_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_t_count),
  1020. 'ACTIVE_TOPIC_PCT' => sprintf($l_active_pct, $active_t_pct),
  1021. 'U_ACTIVE_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $active_f_id),
  1022. 'U_ACTIVE_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $active_t_id),
  1023. 'S_SHOW_ACTIVITY' => true)
  1024. );
  1025. }
  1026. /**
  1027. * Topic and forum watching common code
  1028. */
  1029. function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, $notify_status = 'unset', $start = 0)
  1030. {
  1031. global $template, $db, $user, $phpEx, $start, $phpbb_root_path;
  1032. $table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE : TOPICS_WATCH_TABLE;
  1033. $where_sql = ($mode == 'forum') ? 'forum_id' : 'topic_id';
  1034. $match_id = ($mode == 'forum') ? $forum_id : $topic_id;
  1035. $u_url = "uid={$user->data['user_id']}";
  1036. $u_url .= ($mode == 'forum') ? '&amp;f' : '&amp;f=' . $forum_id . '&amp;t';
  1037. // Is user watching this thread?
  1038. if ($user_id != ANONYMOUS)
  1039. {
  1040. $can_watch = true;
  1041. if ($notify_status == 'unset')
  1042. {
  1043. $sql = "SELECT notify_status
  1044. FROM $table_sql
  1045. WHERE $where_sql = $match_id
  1046. AND user_id = $user_id";
  1047. $result = $db->sql_query($sql);
  1048. $notify_status = ($row = $db->sql_fetchrow($result)) ? $row['notify_status'] : NULL;
  1049. $db->sql_freeresult($result);
  1050. }
  1051. if (!is_null($notify_status) && $notify_status !== '')
  1052. {
  1053. if (isset($_GET['unwatch']))
  1054. {
  1055. $uid = request_var('uid', 0);
  1056. if ($uid != $user_id)
  1057. {
  1058. $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
  1059. $message = $user->lang['ERR_UNWATCHING'] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
  1060. trigger_error($message);
  1061. }
  1062. if ($_GET['unwatch'] == $mode)
  1063. {
  1064. $is_watching = 0;
  1065. $sql = 'DELETE FROM ' . $table_sql . "
  1066. WHERE $where_sql = $match_id
  1067. AND user_id = $user_id";
  1068. $db->sql_query($sql);
  1069. }
  1070. $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
  1071. meta_refresh(3, $redirect_url);
  1072. $message = $user->lang['NOT_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
  1073. trigger_error($message);
  1074. }
  1075. else
  1076. {
  1077. $is_watching = true;
  1078. if ($notify_status != NOTIFY_YES)
  1079. {
  1080. $sql = 'UPDATE ' . $table_sql . "
  1081. SET notify_status = " . NOTIFY_YES . "
  1082. WHERE $where_sql = $match_id
  1083. AND user_id = $user_id";
  1084. $db->sql_query($sql);
  1085. }
  1086. }
  1087. }
  1088. else
  1089. {
  1090. if (isset($_GET['watch']))
  1091. {
  1092. $token = request_var('hash', '');
  1093. $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
  1094. if ($_GET['watch'] == $mode && check_link_hash($token, "{$mode}_$match_id"))
  1095. {
  1096. $is_watching = true;
  1097. $sql = 'INSERT INTO ' . $table_sql . " (user_id, $where_sql, notify_status)
  1098. VALUES ($user_id, $match_id, " . NOTIFY_YES . ')';
  1099. $db->sql_query($sql);
  1100. $message = $user->lang['ARE_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
  1101. }
  1102. else
  1103. {
  1104. $message = $user->lang['ERR_WATCHING'] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
  1105. }
  1106. meta_refresh(3, $redirect_url);
  1107. trigger_error($message);
  1108. }
  1109. else
  1110. {
  1111. $is_watching = 0;
  1112. }
  1113. }
  1114. }
  1115. else
  1116. {
  1117. if (isset($_GET['unwatch']) && $_GET['unwatch'] == $mode)
  1118. {
  1119. login_box();
  1120. }
  1121. else
  1122. {
  1123. $can_watch = 0;
  1124. $is_watching = 0;
  1125. }
  1126. }
  1127. if ($can_watch)
  1128. {
  1129. $s_watching['link'] = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;" . (($is_watching) ? 'unwatch' : 'watch') . "=$mode&amp;start=$start&amp;hash=" . generate_link_hash("{$mode}_$match_id"));
  1130. $s_watching['title'] = $user->lang[(($is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)];
  1131. $s_watching['is_watching'] = $is_watching;
  1132. }
  1133. return;
  1134. }
  1135. /**
  1136. * Get user rank title and image
  1137. *
  1138. * @param int $user_rank the current stored users rank id
  1139. * @param int $user_posts the users number of posts
  1140. * @param string &$rank_title the rank title will be stored here after execution
  1141. * @param string &$rank_img the rank image as full img tag is stored here after execution
  1142. * @param string &$rank_img_src the rank image source is stored here after execution
  1143. *
  1144. * Note: since we do not want to break backwards-compatibility, this function will only properly assign ranks to guests if you call it for them with user_posts == false
  1145. */
  1146. function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank_img_src)
  1147. {
  1148. global $ranks, $config, $phpbb_root_path;
  1149. if (empty($ranks))
  1150. {
  1151. global $cache;
  1152. $ranks = $cache->obtain_ranks();
  1153. }
  1154. if (!empty($user_rank))
  1155. {
  1156. $rank_title = (isset($ranks['special'][$user_rank]['rank_title'])) ? $ranks['special'][$user_rank]['rank_title'] : '';
  1157. $rank_img = (!empty($ranks['special'][$user_rank]['rank_image'])) ? '<img src="' . $phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] . '" alt="' . $ranks['special'][$user_rank]['rank_title'] . '" title="' . $ranks['special'][$user_rank]['rank_title'] . '" />' : '';
  1158. $rank_img_src = (!empty($ranks['special'][$user_rank]['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] : '';
  1159. }
  1160. else if ($user_posts !== false)
  1161. {
  1162. if (!empty($ranks['normal']))
  1163. {
  1164. foreach ($ranks['normal'] as $rank)
  1165. {
  1166. if ($user_posts >= $rank['rank_min'])
  1167. {
  1168. $rank_title = $rank['rank_title'];
  1169. $rank_img = (!empty($rank['rank_image'])) ? '<img src="' . $phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image'] . '" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" />' : '';
  1170. $rank_img_src = (!empty($rank['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image'] : '';
  1171. break;
  1172. }
  1173. }
  1174. }
  1175. }
  1176. }
  1177. /**
  1178. * Get user avatar
  1179. *
  1180. * @param string $avatar Users assigned avatar name
  1181. * @param int $avatar_type Type of avatar
  1182. * @param string $avatar_width Width of users avatar
  1183. * @param string $avatar_height Height of users avatar
  1184. * @param string $alt Optional language string for alt tag within image, can be a language key or text
  1185. * @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP
  1186. *
  1187. * @return string Avatar image
  1188. */
  1189. function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false)
  1190. {
  1191. global $user, $config, $phpbb_root_path, $phpEx;
  1192. if (empty($avatar) || !$avatar_type || (!$config['allow_avatar'] && !$ignore_config))
  1193. {
  1194. return '';
  1195. }
  1196. $avatar_img = '';
  1197. switch ($avatar_type)
  1198. {
  1199. case AVATAR_UPLOAD:
  1200. if (!$config['allow_avatar_upload'] && !$ignore_config)
  1201. {
  1202. return '';
  1203. }
  1204. $avatar_img = $phpbb_root_path . "download/file.$phpEx?avatar=";
  1205. break;
  1206. case AVATAR_GALLERY:
  1207. if (!$config['allow_avatar_local'] && !$ignore_config)
  1208. {
  1209. return '';
  1210. }
  1211. $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
  1212. break;
  1213. case AVATAR_REMOTE:
  1214. if (!$config['allow_avatar_remote'] && !$ignore_config)
  1215. {
  1216. return '';
  1217. }
  1218. break;
  1219. }
  1220. $avatar_img .= $avatar;
  1221. return '<img src="' . (str_replace(' ', '%20', $avatar_img)) . '" width="' . $avatar_width . '" height="' . $avatar_height . '" alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
  1222. }
  1223. ?>