Advertisement
Guest User

functions

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