PageRenderTime 82ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/phpBB/includes/functions_display.php

http://github.com/phpbb/phpbb3
PHP | 1728 lines | 1209 code | 236 blank | 283 comment | 287 complexity | 204e8ecc400dc8a8d9e09d1c702b2353 MD5 | raw file
Possible License(s): AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. *
  4. * This file is part of the phpBB Forum Software package.
  5. *
  6. * @copyright (c) phpBB Limited <https://www.phpbb.com>
  7. * @license GNU General Public License, version 2 (GPL-2.0)
  8. *
  9. * For full copyright and license information, please see
  10. * the docs/CREDITS.txt file.
  11. *
  12. */
  13. /**
  14. * @ignore
  15. */
  16. if (!defined('IN_PHPBB'))
  17. {
  18. exit;
  19. }
  20. /**
  21. * Display Forums
  22. */
  23. function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
  24. {
  25. global $db, $auth, $user, $template;
  26. global $phpbb_root_path, $phpEx, $config;
  27. global $request, $phpbb_dispatcher, $phpbb_container;
  28. $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
  29. $parent_id = $visible_forums = 0;
  30. $parent_subforum_limit = false;
  31. // Mark forums read?
  32. $mark_read = $request->variable('mark', '');
  33. if ($mark_read == 'all')
  34. {
  35. $mark_read = '';
  36. }
  37. if (!$root_data)
  38. {
  39. if ($mark_read == 'forums')
  40. {
  41. $mark_read = 'all';
  42. }
  43. $root_data = array('forum_id' => 0);
  44. $sql_where = '';
  45. }
  46. else
  47. {
  48. $sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
  49. }
  50. // Handle marking everything read
  51. if ($mark_read == 'all')
  52. {
  53. $redirect = build_url(array('mark', 'hash', 'mark_time'));
  54. meta_refresh(3, $redirect);
  55. if (check_link_hash($request->variable('hash', ''), 'global'))
  56. {
  57. markread('all', false, false, $request->variable('mark_time', 0));
  58. if ($request->is_ajax())
  59. {
  60. // Tell the ajax script what language vars and URL need to be replaced
  61. $data = array(
  62. 'NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'],
  63. 'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'],
  64. 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}index.$phpEx", 'hash=' . generate_link_hash('global') . '&mark=forums&mark_time=' . time(), false) : '',
  65. 'MESSAGE_TITLE' => $user->lang['INFORMATION'],
  66. 'MESSAGE_TEXT' => $user->lang['FORUMS_MARKED']
  67. );
  68. $json_response = new \phpbb\json_response();
  69. $json_response->send($data);
  70. }
  71. trigger_error(
  72. $user->lang['FORUMS_MARKED'] . '<br /><br />' .
  73. sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>')
  74. );
  75. }
  76. else
  77. {
  78. trigger_error(sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
  79. }
  80. }
  81. // Display list of active topics for this category?
  82. $show_active = (isset($root_data['forum_flags']) && ($root_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
  83. $sql_array = array(
  84. 'SELECT' => 'f.*',
  85. 'FROM' => array(
  86. FORUMS_TABLE => 'f'
  87. ),
  88. 'LEFT_JOIN' => array(),
  89. );
  90. if ($config['load_db_lastread'] && $user->data['is_registered'])
  91. {
  92. $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');
  93. $sql_array['SELECT'] .= ', ft.mark_time';
  94. }
  95. else if ($config['load_anon_lastread'] || $user->data['is_registered'])
  96. {
  97. $tracking_topics = $request->variable($config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE);
  98. $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
  99. if (!$user->data['is_registered'])
  100. {
  101. $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
  102. }
  103. }
  104. if ($show_active)
  105. {
  106. $sql_array['LEFT_JOIN'][] = array(
  107. 'FROM' => array(FORUMS_ACCESS_TABLE => 'fa'),
  108. 'ON' => "fa.forum_id = f.forum_id AND fa.session_id = '" . $db->sql_escape($user->session_id) . "'"
  109. );
  110. $sql_array['SELECT'] .= ', fa.user_id';
  111. }
  112. $sql_ary = array(
  113. 'SELECT' => $sql_array['SELECT'],
  114. 'FROM' => $sql_array['FROM'],
  115. 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
  116. 'WHERE' => $sql_where,
  117. 'ORDER_BY' => 'f.left_id',
  118. );
  119. /**
  120. * Event to modify the SQL query before the forum data is queried
  121. *
  122. * @event core.display_forums_modify_sql
  123. * @var array sql_ary The SQL array to get the data of the forums
  124. * @since 3.1.0-a1
  125. */
  126. $vars = array('sql_ary');
  127. extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_sql', compact($vars)));
  128. $sql = $db->sql_build_query('SELECT', $sql_ary);
  129. $result = $db->sql_query($sql);
  130. $forum_tracking_info = $valid_categories = array();
  131. $branch_root_id = $root_data['forum_id'];
  132. /* @var $phpbb_content_visibility \phpbb\content_visibility */
  133. $phpbb_content_visibility = $phpbb_container->get('content.visibility');
  134. while ($row = $db->sql_fetchrow($result))
  135. {
  136. /**
  137. * Event to modify the data set of a forum
  138. *
  139. * This event is triggered once per forum
  140. *
  141. * @event core.display_forums_modify_row
  142. * @var int branch_root_id Last top-level forum
  143. * @var array row The data of the forum
  144. * @since 3.1.0-a1
  145. */
  146. $vars = array('branch_root_id', 'row');
  147. extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_row', compact($vars)));
  148. $forum_id = $row['forum_id'];
  149. // Mark forums read?
  150. if ($mark_read == 'forums')
  151. {
  152. if ($auth->acl_get('f_list', $forum_id))
  153. {
  154. $forum_ids[] = $forum_id;
  155. }
  156. continue;
  157. }
  158. // Category with no members
  159. if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
  160. {
  161. continue;
  162. }
  163. // Skip branch
  164. if (isset($right_id))
  165. {
  166. if ($row['left_id'] < $right_id)
  167. {
  168. continue;
  169. }
  170. unset($right_id);
  171. }
  172. if (!$auth->acl_get('f_list', $forum_id))
  173. {
  174. // if the user does not have permissions to list this forum, skip everything until next branch
  175. $right_id = $row['right_id'];
  176. continue;
  177. }
  178. if ($config['load_db_lastread'] && $user->data['is_registered'])
  179. {
  180. $forum_tracking_info[$forum_id] = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
  181. }
  182. else if ($config['load_anon_lastread'] || $user->data['is_registered'])
  183. {
  184. if (!$user->data['is_registered'])
  185. {
  186. $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
  187. }
  188. $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'];
  189. }
  190. // Lets check whether there are unapproved topics/posts, so we can display an information to moderators
  191. $row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && $row['forum_topics_unapproved']) ? $forum_id : 0;
  192. $row['forum_id_unapproved_posts'] = ($auth->acl_get('m_approve', $forum_id) && $row['forum_posts_unapproved']) ? $forum_id : 0;
  193. $row['forum_posts'] = $phpbb_content_visibility->get_count('forum_posts', $row, $forum_id);
  194. $row['forum_topics'] = $phpbb_content_visibility->get_count('forum_topics', $row, $forum_id);
  195. // Display active topics from this forum?
  196. if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS))
  197. {
  198. if (!isset($active_forum_ary['forum_topics']))
  199. {
  200. $active_forum_ary['forum_topics'] = 0;
  201. }
  202. if (!isset($active_forum_ary['forum_posts']))
  203. {
  204. $active_forum_ary['forum_posts'] = 0;
  205. }
  206. $active_forum_ary['forum_id'][] = $forum_id;
  207. $active_forum_ary['enable_icons'][] = $row['enable_icons'];
  208. $active_forum_ary['forum_topics'] += $row['forum_topics'];
  209. $active_forum_ary['forum_posts'] += $row['forum_posts'];
  210. // If this is a passworded forum we do not show active topics from it if the user is not authorised to view it...
  211. if ($row['forum_password'] && $row['user_id'] != $user->data['user_id'])
  212. {
  213. $active_forum_ary['exclude_forum_id'][] = $forum_id;
  214. }
  215. }
  216. // Fill list of categories with forums
  217. if (isset($forum_rows[$row['parent_id']]))
  218. {
  219. $valid_categories[$row['parent_id']] = true;
  220. }
  221. //
  222. if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id)
  223. {
  224. if ($row['forum_type'] != FORUM_CAT)
  225. {
  226. $forum_ids_moderator[] = (int) $forum_id;
  227. }
  228. // Direct child of current branch
  229. $parent_id = $forum_id;
  230. $parent_subforum_limit = $row['display_subforum_limit'] ?? false;
  231. $forum_rows[$forum_id] = $row;
  232. if ($row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id'])
  233. {
  234. $branch_root_id = $forum_id;
  235. }
  236. $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
  237. $forum_rows[$parent_id]['forum_password_last_post'] = $row['forum_password'];
  238. $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
  239. }
  240. else if ($row['forum_type'] != FORUM_CAT)
  241. {
  242. $subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index'] && (!$parent_subforum_limit || $parent_id == $row['parent_id']));
  243. $subforums[$parent_id][$forum_id]['name'] = $row['forum_name'];
  244. $subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
  245. $subforums[$parent_id][$forum_id]['children'] = array();
  246. $subforums[$parent_id][$forum_id]['type'] = $row['forum_type'];
  247. if (isset($subforums[$parent_id][$row['parent_id']]) && !$row['display_on_index'])
  248. {
  249. $subforums[$parent_id][$row['parent_id']]['children'][] = $forum_id;
  250. }
  251. if (!$forum_rows[$parent_id]['forum_id_unapproved_topics'] && $row['forum_id_unapproved_topics'])
  252. {
  253. $forum_rows[$parent_id]['forum_id_unapproved_topics'] = $forum_id;
  254. }
  255. if (!$forum_rows[$parent_id]['forum_id_unapproved_posts'] && $row['forum_id_unapproved_posts'])
  256. {
  257. $forum_rows[$parent_id]['forum_id_unapproved_posts'] = $forum_id;
  258. }
  259. $forum_rows[$parent_id]['forum_topics'] += $row['forum_topics'];
  260. // Do not list redirects in LINK Forums as Posts.
  261. if ($row['forum_type'] != FORUM_LINK)
  262. {
  263. $forum_rows[$parent_id]['forum_posts'] += $row['forum_posts'];
  264. }
  265. if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time'])
  266. {
  267. $forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
  268. $forum_rows[$parent_id]['forum_last_post_subject'] = $row['forum_last_post_subject'];
  269. $forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
  270. $forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
  271. $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
  272. $forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour'];
  273. $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
  274. $forum_rows[$parent_id]['forum_password_last_post'] = $row['forum_password'];
  275. }
  276. }
  277. /**
  278. * Event to modify the forum rows data set
  279. *
  280. * This event is triggered once per forum
  281. *
  282. * @event core.display_forums_modify_forum_rows
  283. * @var array forum_rows Data array of all forums we display
  284. * @var array subforums Data array of all subforums we display
  285. * @var int branch_root_id Current top-level forum
  286. * @var int parent_id Current parent forum
  287. * @var array row The data of the forum
  288. * @since 3.1.0-a1
  289. */
  290. $vars = array('forum_rows', 'subforums', 'branch_root_id', 'parent_id', 'row');
  291. extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_forum_rows', compact($vars)));
  292. }
  293. $db->sql_freeresult($result);
  294. // Handle marking posts
  295. if ($mark_read == 'forums')
  296. {
  297. $redirect = build_url(array('mark', 'hash', 'mark_time'));
  298. $token = $request->variable('hash', '');
  299. if (check_link_hash($token, 'global'))
  300. {
  301. markread('topics', $forum_ids, false, $request->variable('mark_time', 0));
  302. $message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
  303. meta_refresh(3, $redirect);
  304. if ($request->is_ajax())
  305. {
  306. // Tell the ajax script what language vars and URL need to be replaced
  307. $data = array(
  308. 'NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'],
  309. 'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'],
  310. 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . '&f=' . $root_data['forum_id'] . '&mark=forums&mark_time=' . time(), false) : '',
  311. 'MESSAGE_TITLE' => $user->lang['INFORMATION'],
  312. 'MESSAGE_TEXT' => $user->lang['FORUMS_MARKED']
  313. );
  314. $json_response = new \phpbb\json_response();
  315. $json_response->send($data);
  316. }
  317. trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . $message);
  318. }
  319. else
  320. {
  321. $message = sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
  322. meta_refresh(3, $redirect);
  323. trigger_error($message);
  324. }
  325. }
  326. // Grab moderators ... if necessary
  327. if ($display_moderators)
  328. {
  329. if ($return_moderators)
  330. {
  331. $forum_ids_moderator[] = $root_data['forum_id'];
  332. }
  333. get_moderators($forum_moderators, $forum_ids_moderator);
  334. }
  335. /**
  336. * Event to perform additional actions before the forum list is being generated
  337. *
  338. * @event core.display_forums_before
  339. * @var array active_forum_ary Array with forum data to display active topics
  340. * @var bool display_moderators Flag indicating if we display forum moderators
  341. * @var array forum_moderators Array with forum moderators list
  342. * @var array forum_rows Data array of all forums we display
  343. * @var bool return_moderators Flag indicating if moderators list should be returned
  344. * @var array root_data Array with the root forum data
  345. * @since 3.1.4-RC1
  346. */
  347. $vars = array(
  348. 'active_forum_ary',
  349. 'display_moderators',
  350. 'forum_moderators',
  351. 'forum_rows',
  352. 'return_moderators',
  353. 'root_data',
  354. );
  355. extract($phpbb_dispatcher->trigger_event('core.display_forums_before', compact($vars)));
  356. // Used to tell whatever we have to create a dummy category or not.
  357. $last_catless = true;
  358. foreach ($forum_rows as $row)
  359. {
  360. // Category
  361. if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT)
  362. {
  363. // Do not display categories without any forums to display
  364. if (!isset($valid_categories[$row['forum_id']]))
  365. {
  366. continue;
  367. }
  368. $cat_row = array(
  369. 'S_IS_CAT' => true,
  370. 'FORUM_ID' => $row['forum_id'],
  371. 'FORUM_NAME' => $row['forum_name'],
  372. 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
  373. 'FORUM_FOLDER_IMG' => '',
  374. 'FORUM_FOLDER_IMG_SRC' => '',
  375. 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang['FORUM_CAT'] . '" />' : '',
  376. 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
  377. 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']),
  378. );
  379. /**
  380. * Modify the template data block of the 'category'
  381. *
  382. * This event is triggered once per 'category'
  383. *
  384. * @event core.display_forums_modify_category_template_vars
  385. * @var array cat_row Template data of the 'category'
  386. * @var bool last_catless The flag indicating whether the last forum had a parent category
  387. * @var array root_data Array with the root forum data
  388. * @var array row The data of the 'category'
  389. * @since 3.1.0-RC4
  390. * @changed 3.1.7-RC1 Removed undefined catless variable
  391. */
  392. $vars = array(
  393. 'cat_row',
  394. 'last_catless',
  395. 'root_data',
  396. 'row',
  397. );
  398. extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_category_template_vars', compact($vars)));
  399. $template->assign_block_vars('forumrow', $cat_row);
  400. continue;
  401. }
  402. $visible_forums++;
  403. $forum_id = $row['forum_id'];
  404. $forum_unread = (isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id]) ? true : false;
  405. $folder_image = $folder_alt = $l_subforums = '';
  406. $subforums_list = array();
  407. // Generate list of subforums if we need to
  408. if (isset($subforums[$forum_id]))
  409. {
  410. foreach ($subforums[$forum_id] as $subforum_id => $subforum_row)
  411. {
  412. $subforum_unread = (isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id]) ? true : false;
  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. if ($subforum_row['display'] && $subforum_row['name'])
  426. {
  427. $subforums_list[] = array(
  428. 'link' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $subforum_id),
  429. 'name' => $subforum_row['name'],
  430. 'unread' => $subforum_unread,
  431. 'type' => $subforum_row['type'],
  432. );
  433. }
  434. else
  435. {
  436. unset($subforums[$forum_id][$subforum_id]);
  437. }
  438. // If one subforum is unread the forum gets unread too...
  439. if ($subforum_unread)
  440. {
  441. $forum_unread = true;
  442. }
  443. }
  444. $l_subforums = (count($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'];
  445. $folder_image = ($forum_unread) ? 'forum_unread_subforum' : 'forum_read_subforum';
  446. }
  447. else
  448. {
  449. switch ($row['forum_type'])
  450. {
  451. case FORUM_POST:
  452. $folder_image = ($forum_unread) ? 'forum_unread' : 'forum_read';
  453. break;
  454. case FORUM_LINK:
  455. $folder_image = 'forum_link';
  456. break;
  457. }
  458. }
  459. // Which folder should we display?
  460. if ($row['forum_status'] == ITEM_LOCKED)
  461. {
  462. $folder_image = ($forum_unread) ? 'forum_unread_locked' : 'forum_read_locked';
  463. $folder_alt = 'FORUM_LOCKED';
  464. }
  465. else
  466. {
  467. $folder_alt = ($forum_unread) ? 'UNREAD_POSTS' : 'NO_UNREAD_POSTS';
  468. }
  469. // Create last post link information, if appropriate
  470. if ($row['forum_last_post_id'])
  471. {
  472. if ($row['forum_password_last_post'] === '' && $auth->acl_gets('f_read', 'f_list_topics', $row['forum_id_last_post']))
  473. {
  474. $last_post_subject = utf8_decode_ncr(censor_text($row['forum_last_post_subject']));
  475. $last_post_subject_truncated = truncate_string($last_post_subject, 30, 255, false, $user->lang['ELLIPSIS']);
  476. }
  477. else
  478. {
  479. $last_post_subject = $last_post_subject_truncated = '';
  480. }
  481. $last_post_time = $user->format_date($row['forum_last_post_time']);
  482. $last_post_time_rfc3339 = gmdate(DATE_RFC3339, $row['forum_last_post_time']);
  483. $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'];
  484. }
  485. else
  486. {
  487. $last_post_subject = $last_post_time = $last_post_time_rfc3339 = $last_post_url = $last_post_subject_truncated = '';
  488. }
  489. // Output moderator listing ... if applicable
  490. $l_moderator = $moderators_list = '';
  491. if ($display_moderators && !empty($forum_moderators[$forum_id]))
  492. {
  493. $l_moderator = (count($forum_moderators[$forum_id]) == 1) ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
  494. $moderators_list = implode($user->lang['COMMA_SEPARATOR'], $forum_moderators[$forum_id]);
  495. }
  496. $l_post_click_count = ($row['forum_type'] == FORUM_LINK) ? 'CLICKS' : 'POSTS';
  497. $post_click_count = ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? $row['forum_posts'] : '';
  498. $s_subforums_list = $subforums_row = array();
  499. foreach ($subforums_list as $subforum)
  500. {
  501. $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>';
  502. $subforums_row[] = array(
  503. 'U_SUBFORUM' => $subforum['link'],
  504. 'SUBFORUM_NAME' => $subforum['name'],
  505. 'S_UNREAD' => $subforum['unread'],
  506. 'IS_LINK' => $subforum['type'] == FORUM_LINK,
  507. );
  508. }
  509. $s_subforums_list = (string) implode($user->lang['COMMA_SEPARATOR'], $s_subforums_list);
  510. $catless = ($row['parent_id'] == $root_data['forum_id']) ? true : false;
  511. if ($row['forum_type'] != FORUM_LINK)
  512. {
  513. $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
  514. }
  515. else
  516. {
  517. // If the forum is a link and we count redirects we need to visit it
  518. // If the forum is having a password or no read access we do not expose the link, but instead handle it in viewforum
  519. if (($row['forum_flags'] & FORUM_FLAG_LINK_TRACK) || $row['forum_password'] || !$auth->acl_get('f_read', $forum_id))
  520. {
  521. $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
  522. }
  523. else
  524. {
  525. $u_viewforum = $row['forum_link'];
  526. }
  527. }
  528. $forum_row = array(
  529. 'S_IS_CAT' => false,
  530. 'S_NO_CAT' => $catless && !$last_catless,
  531. 'S_IS_LINK' => ($row['forum_type'] == FORUM_LINK) ? true : false,
  532. 'S_UNREAD_FORUM' => $forum_unread,
  533. 'S_AUTH_READ' => $auth->acl_get('f_read', $row['forum_id']),
  534. 'S_LOCKED_FORUM' => ($row['forum_status'] == ITEM_LOCKED) ? true : false,
  535. 'S_LIST_SUBFORUMS' => ($row['display_subforum_list']) ? true : false,
  536. 'S_SUBFORUMS' => (count($subforums_list)) ? true : false,
  537. 'S_DISPLAY_SUBJECT' => ($last_post_subject !== '' && $config['display_last_subject']) ? true : false,
  538. 'S_FEED_ENABLED' => ($config['feed_forum'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $row['forum_options']) && $row['forum_type'] == FORUM_POST) ? true : false,
  539. 'FORUM_ID' => $row['forum_id'],
  540. 'FORUM_NAME' => $row['forum_name'],
  541. 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
  542. 'TOPICS' => $row['forum_topics'],
  543. $l_post_click_count => $post_click_count,
  544. 'FORUM_IMG_STYLE' => $folder_image,
  545. 'FORUM_FOLDER_IMG' => $user->img($folder_image, $folder_alt),
  546. 'FORUM_FOLDER_IMG_ALT' => isset($user->lang[$folder_alt]) ? $user->lang[$folder_alt] : '',
  547. 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
  548. 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
  549. 'LAST_POST_SUBJECT' => $last_post_subject,
  550. 'LAST_POST_SUBJECT_TRUNCATED' => $last_post_subject_truncated,
  551. 'LAST_POST_TIME' => $last_post_time,
  552. 'LAST_POST_TIME_RFC3339'=> $last_post_time_rfc3339,
  553. 'LAST_POSTER' => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  554. 'LAST_POSTER_COLOUR' => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  555. 'LAST_POSTER_FULL' => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  556. 'MODERATORS' => $moderators_list,
  557. 'SUBFORUMS' => $s_subforums_list,
  558. 'L_SUBFORUM_STR' => $l_subforums,
  559. 'L_MODERATOR_STR' => $l_moderator,
  560. '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']) : '',
  561. 'U_UNAPPROVED_POSTS' => ($row['forum_id_unapproved_posts']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=unapproved_posts&amp;f=' . $row['forum_id_unapproved_posts']) : '',
  562. 'U_VIEWFORUM' => $u_viewforum,
  563. 'U_LAST_POSTER' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  564. 'U_LAST_POST' => $last_post_url,
  565. );
  566. /**
  567. * Modify the template data block of the forum
  568. *
  569. * This event is triggered once per forum
  570. *
  571. * @event core.display_forums_modify_template_vars
  572. * @var array forum_row Template data of the forum
  573. * @var array row The data of the forum
  574. * @var array subforums_row Template data of subforums
  575. * @since 3.1.0-a1
  576. * @changed 3.1.0-b5 Added var subforums_row
  577. */
  578. $vars = array('forum_row', 'row', 'subforums_row');
  579. extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_template_vars', compact($vars)));
  580. $template->assign_block_vars('forumrow', $forum_row);
  581. // Assign subforums loop for style authors
  582. $template->assign_block_vars_array('forumrow.subforum', $subforums_row);
  583. /**
  584. * Modify and/or assign additional template data for the forum
  585. * after forumrow loop has been assigned. This can be used
  586. * to create additional forumrow subloops in extensions.
  587. *
  588. * This event is triggered once per forum
  589. *
  590. * @event core.display_forums_add_template_data
  591. * @var array forum_row Template data of the forum
  592. * @var array row The data of the forum
  593. * @var array subforums_list The data of subforums
  594. * @var array subforums_row Template data of subforums
  595. * @var bool catless The flag indicating whether a forum has a parent category
  596. * @since 3.1.0-b5
  597. */
  598. $vars = array(
  599. 'forum_row',
  600. 'row',
  601. 'subforums_list',
  602. 'subforums_row',
  603. 'catless',
  604. );
  605. extract($phpbb_dispatcher->trigger_event('core.display_forums_add_template_data', compact($vars)));
  606. $last_catless = $catless;
  607. }
  608. $template->assign_vars(array(
  609. '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&amp;mark_time=' . time()) : '',
  610. 'S_HAS_SUBFORUM' => ($visible_forums) ? true : false,
  611. 'L_SUBFORUM' => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'],
  612. 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
  613. 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPICS_UNAPPROVED'),
  614. 'UNAPPROVED_POST_IMG' => $user->img('icon_topic_unapproved', 'POSTS_UNAPPROVED_FORUM'),
  615. ));
  616. /**
  617. * Event to perform additional actions after the forum list has been generated
  618. *
  619. * @event core.display_forums_after
  620. * @var array active_forum_ary Array with forum data to display active topics
  621. * @var bool display_moderators Flag indicating if we display forum moderators
  622. * @var array forum_moderators Array with forum moderators list
  623. * @var array forum_rows Data array of all forums we display
  624. * @var bool return_moderators Flag indicating if moderators list should be returned
  625. * @var array root_data Array with the root forum data
  626. * @since 3.1.0-RC5
  627. */
  628. $vars = array(
  629. 'active_forum_ary',
  630. 'display_moderators',
  631. 'forum_moderators',
  632. 'forum_rows',
  633. 'return_moderators',
  634. 'root_data',
  635. );
  636. extract($phpbb_dispatcher->trigger_event('core.display_forums_after', compact($vars)));
  637. if ($return_moderators)
  638. {
  639. return array($active_forum_ary, $forum_moderators);
  640. }
  641. return array($active_forum_ary, array());
  642. }
  643. /**
  644. * Create forum rules for given forum
  645. */
  646. function generate_forum_rules(&$forum_data)
  647. {
  648. if ($forum_data['forum_rules'])
  649. {
  650. $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']);
  651. }
  652. if (!$forum_data['forum_rules'] && !$forum_data['forum_rules_link'])
  653. {
  654. return;
  655. }
  656. global $template;
  657. $template->assign_vars(array(
  658. 'S_FORUM_RULES' => true,
  659. 'U_FORUM_RULES' => $forum_data['forum_rules_link'],
  660. 'FORUM_RULES' => $forum_data['forum_rules'])
  661. );
  662. }
  663. /**
  664. * Create forum navigation links for given forum, create parent
  665. * list if currently null, assign basic forum info to template
  666. */
  667. function generate_forum_nav(&$forum_data_ary)
  668. {
  669. global $template, $auth, $config;
  670. global $phpEx, $phpbb_root_path, $phpbb_dispatcher;
  671. if (!$auth->acl_get('f_list', $forum_data_ary['forum_id']))
  672. {
  673. return;
  674. }
  675. $navlinks_parents = $forum_template_data = array();
  676. // Get forum parents
  677. $forum_parents = get_forum_parents($forum_data_ary);
  678. $microdata_attr = 'data-forum-id';
  679. // Build navigation links
  680. if (!empty($forum_parents))
  681. {
  682. foreach ($forum_parents as $parent_forum_id => $parent_data)
  683. {
  684. list($parent_name, $parent_type) = array_values($parent_data);
  685. // Skip this parent if the user does not have the permission to view it
  686. if (!$auth->acl_get('f_list', $parent_forum_id))
  687. {
  688. continue;
  689. }
  690. $navlinks_parents[] = array(
  691. 'S_IS_CAT' => ($parent_type == FORUM_CAT) ? true : false,
  692. 'S_IS_LINK' => ($parent_type == FORUM_LINK) ? true : false,
  693. 'S_IS_POST' => ($parent_type == FORUM_POST) ? true : false,
  694. 'BREADCRUMB_NAME' => $parent_name,
  695. 'FORUM_ID' => $parent_forum_id,
  696. 'MICRODATA' => $microdata_attr . '="' . $parent_forum_id . '"',
  697. 'U_BREADCRUMB' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $parent_forum_id),
  698. );
  699. }
  700. }
  701. $navlinks = array(
  702. 'S_IS_CAT' => ($forum_data_ary['forum_type'] == FORUM_CAT) ? true : false,
  703. 'S_IS_LINK' => ($forum_data_ary['forum_type'] == FORUM_LINK) ? true : false,
  704. 'S_IS_POST' => ($forum_data_ary['forum_type'] == FORUM_POST) ? true : false,
  705. 'BREADCRUMB_NAME' => $forum_data_ary['forum_name'],
  706. 'FORUM_ID' => $forum_data_ary['forum_id'],
  707. 'MICRODATA' => $microdata_attr . '="' . $forum_data_ary['forum_id'] . '"',
  708. 'U_BREADCRUMB' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_data_ary['forum_id']),
  709. );
  710. $forum_template_data = array(
  711. 'FORUM_ID' => $forum_data_ary['forum_id'],
  712. 'FORUM_NAME' => $forum_data_ary['forum_name'],
  713. 'FORUM_DESC' => generate_text_for_display($forum_data_ary['forum_desc'], $forum_data_ary['forum_desc_uid'], $forum_data_ary['forum_desc_bitfield'], $forum_data_ary['forum_desc_options']),
  714. 'S_ENABLE_FEEDS_FORUM' => ($config['feed_forum'] && $forum_data_ary['forum_type'] == FORUM_POST && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $forum_data_ary['forum_options'])) ? true : false,
  715. );
  716. $forum_data = $forum_data_ary;
  717. /**
  718. * Event to modify the navlinks text
  719. *
  720. * @event core.generate_forum_nav
  721. * @var array forum_data Array with the forum data
  722. * @var array forum_template_data Array with generic forum template data
  723. * @var string microdata_attr The microdata attribute
  724. * @var array navlinks_parents Array with the forum parents navlinks data
  725. * @var array navlinks Array with the forum navlinks data
  726. * @since 3.1.5-RC1
  727. */
  728. $vars = array(
  729. 'forum_data',
  730. 'forum_template_data',
  731. 'microdata_attr',
  732. 'navlinks_parents',
  733. 'navlinks',
  734. );
  735. extract($phpbb_dispatcher->trigger_event('core.generate_forum_nav', compact($vars)));
  736. $forum_data_ary = $forum_data;
  737. unset($forum_data);
  738. $template->assign_block_vars_array('navlinks', $navlinks_parents);
  739. $template->assign_block_vars('navlinks', $navlinks);
  740. $template->assign_vars($forum_template_data);
  741. return;
  742. }
  743. /**
  744. * Returns forum parents as an array. Get them from forum_data if available, or update the database otherwise
  745. */
  746. function get_forum_parents(&$forum_data)
  747. {
  748. global $db;
  749. $forum_parents = array();
  750. if ($forum_data['parent_id'] > 0)
  751. {
  752. if ($forum_data['forum_parents'] == '')
  753. {
  754. $sql = 'SELECT forum_id, forum_name, forum_type
  755. FROM ' . FORUMS_TABLE . '
  756. WHERE left_id < ' . $forum_data['left_id'] . '
  757. AND right_id > ' . $forum_data['right_id'] . '
  758. ORDER BY left_id ASC';
  759. $result = $db->sql_query($sql);
  760. while ($row = $db->sql_fetchrow($result))
  761. {
  762. $forum_parents[$row['forum_id']] = array($row['forum_name'], (int) $row['forum_type']);
  763. }
  764. $db->sql_freeresult($result);
  765. $forum_data['forum_parents'] = serialize($forum_parents);
  766. $sql = 'UPDATE ' . FORUMS_TABLE . "
  767. SET forum_parents = '" . $db->sql_escape($forum_data['forum_parents']) . "'
  768. WHERE parent_id = " . $forum_data['parent_id'];
  769. $db->sql_query($sql);
  770. }
  771. else
  772. {
  773. $forum_parents = unserialize($forum_data['forum_parents']);
  774. }
  775. }
  776. return $forum_parents;
  777. }
  778. /**
  779. * Obtain list of moderators of each forum
  780. */
  781. function get_moderators(&$forum_moderators, $forum_id = false)
  782. {
  783. global $db, $phpbb_root_path, $phpEx, $user, $auth;
  784. global $phpbb_container;
  785. $forum_id_ary = array();
  786. if ($forum_id !== false)
  787. {
  788. if (!is_array($forum_id))
  789. {
  790. $forum_id = array($forum_id);
  791. }
  792. // Exchange key/value pair to be able to faster check for the forum id existence
  793. $forum_id_ary = array_flip($forum_id);
  794. }
  795. $sql_array = array(
  796. 'SELECT' => 'm.*, u.user_colour, g.group_colour, g.group_type',
  797. 'FROM' => array(
  798. MODERATOR_CACHE_TABLE => 'm',
  799. ),
  800. 'LEFT_JOIN' => array(
  801. array(
  802. 'FROM' => array(USERS_TABLE => 'u'),
  803. 'ON' => 'm.user_id = u.user_id',
  804. ),
  805. array(
  806. 'FROM' => array(GROUPS_TABLE => 'g'),
  807. 'ON' => 'm.group_id = g.group_id',
  808. ),
  809. ),
  810. 'WHERE' => 'm.display_on_index = 1',
  811. );
  812. /** @var \phpbb\group\helper $group_helper */
  813. $group_helper = $phpbb_container->get('group_helper');
  814. // We query every forum here because for caching we should not have any parameter.
  815. $sql = $db->sql_build_query('SELECT', $sql_array);
  816. $result = $db->sql_query($sql, 3600);
  817. while ($row = $db->sql_fetchrow($result))
  818. {
  819. $f_id = (int) $row['forum_id'];
  820. if (!isset($forum_id_ary[$f_id]))
  821. {
  822. continue;
  823. }
  824. if (!empty($row['user_id']))
  825. {
  826. $forum_moderators[$f_id][] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
  827. }
  828. else
  829. {
  830. $group_name = $group_helper->get_name($row['group_name']);
  831. if ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_viewprofile'))
  832. {
  833. $forum_moderators[$f_id][] = '<span' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . '>' . $group_name . '</span>';
  834. }
  835. else
  836. {
  837. $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>';
  838. }
  839. }
  840. }
  841. $db->sql_freeresult($result);
  842. return;
  843. }
  844. /**
  845. * User authorisation levels output
  846. *
  847. * @param string $mode Can be forum or topic. Not in use at the moment.
  848. * @param int $forum_id The current forum the user is in.
  849. * @param int $forum_status The forums status bit.
  850. */
  851. function gen_forum_auth_level($mode, $forum_id, $forum_status)
  852. {
  853. global $template, $auth, $user, $config;
  854. $locked = ($forum_status == ITEM_LOCKED && !$auth->acl_get('m_edit', $forum_id)) ? true : false;
  855. $rules = array(
  856. ($auth->acl_get('f_post', $forum_id) && !$locked) ? $user->lang['RULES_POST_CAN'] : $user->lang['RULES_POST_CANNOT'],
  857. ($auth->acl_get('f_reply', $forum_id) && !$locked) ? $user->lang['RULES_REPLY_CAN'] : $user->lang['RULES_REPLY_CANNOT'],
  858. ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id) && !$locked) ? $user->lang['RULES_EDIT_CAN'] : $user->lang['RULES_EDIT_CANNOT'],
  859. ($user->data['is_registered'] && ($auth->acl_gets('f_delete', 'm_delete', $forum_id) || $auth->acl_gets('f_softdelete', 'm_softdelete', $forum_id)) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'],
  860. );
  861. if ($config['allow_attachments'])
  862. {
  863. $rules[] = ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && !$locked) ? $user->lang['RULES_ATTACH_CAN'] : $user->lang['RULES_ATTACH_CANNOT'];
  864. }
  865. foreach ($rules as $rule)
  866. {
  867. $template->assign_block_vars('rules', array('RULE' => $rule));
  868. }
  869. return;
  870. }
  871. /**
  872. * Generate topic status
  873. */
  874. function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$folder_alt, &$topic_type)
  875. {
  876. global $user, $config;
  877. if ($topic_row['topic_status'] == ITEM_MOVED)
  878. {
  879. $topic_type = $user->lang['VIEW_TOPIC_MOVED'];
  880. $folder_img = 'topic_moved';
  881. $folder_alt = 'TOPIC_MOVED';
  882. }
  883. else
  884. {
  885. switch ($topic_row['topic_type'])
  886. {
  887. case POST_GLOBAL:
  888. $topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
  889. $folder = 'global_read';
  890. $folder_new = 'global_unread';
  891. break;
  892. case POST_ANNOUNCE:
  893. $topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT'];
  894. $folder = 'announce_read';
  895. $folder_new = 'announce_unread';
  896. break;
  897. case POST_STICKY:
  898. $topic_type = $user->lang['VIEW_TOPIC_STICKY'];
  899. $folder = 'sticky_read';
  900. $folder_new = 'sticky_unread';
  901. break;
  902. default:
  903. $topic_type = '';
  904. $folder = 'topic_read';
  905. $folder_new = 'topic_unread';
  906. // Hot topic threshold is for posts in a topic, which is replies + the first post. ;)
  907. if ($config['hot_threshold'] && ($replies + 1) >= $config['hot_threshold'] && $topic_row['topic_status'] != ITEM_LOCKED)
  908. {
  909. $folder .= '_hot';
  910. $folder_new .= '_hot';
  911. }
  912. break;
  913. }
  914. if ($topic_row['topic_status'] == ITEM_LOCKED)
  915. {
  916. $topic_type = $user->lang['VIEW_TOPIC_LOCKED'];
  917. $folder .= '_locked';
  918. $folder_new .= '_locked';
  919. }
  920. $folder_img = ($unread_topic) ? $folder_new : $folder;
  921. $folder_alt = ($unread_topic) ? 'UNREAD_POSTS' : (($topic_row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_UNREAD_POSTS');
  922. // Posted image?
  923. if (!empty($topic_row['topic_posted']) && $topic_row['topic_posted'])
  924. {
  925. $folder_img .= '_mine';
  926. }
  927. }
  928. if ($topic_row['poll_start'] && $topic_row['topic_status'] != ITEM_MOVED)
  929. {
  930. $topic_type = $user->lang['VIEW_TOPIC_POLL'];
  931. }
  932. }
  933. /**
  934. * Assign/Build custom bbcodes for display in screens supporting using of bbcodes
  935. * The custom bbcodes buttons will be placed within the template block 'custom_tags'
  936. */
  937. function display_custom_bbcodes()
  938. {
  939. global $db, $template, $user, $phpbb_dispatcher;
  940. // Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)
  941. $num_predefined_bbcodes = NUM_PREDEFINED_BBCODES;
  942. $sql_ary = array(
  943. 'SELECT' => 'b.bbcode_id, b.bbcode_tag, b.bbcode_helpline',
  944. 'FROM' => array(BBCODES_TABLE => 'b'),
  945. 'WHERE' => 'b.display_on_posting = 1',
  946. 'ORDER_BY' => 'b.bbcode_tag',
  947. );
  948. /**
  949. * Event to modify the SQL query before custom bbcode data is queried
  950. *
  951. * @event core.display_custom_bbcodes_modify_sql
  952. * @var array sql_ary The SQL array to get the bbcode data
  953. * @var int num_predefined_bbcodes The number of predefined core bbcodes
  954. * (multiplied by factor of 2)
  955. * @since 3.1.0-a3
  956. */
  957. $vars = array('sql_ary', 'num_predefined_bbcodes');
  958. extract($phpbb_dispatcher->trigger_event('core.display_custom_bbcodes_modify_sql', compact($vars)));
  959. $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));
  960. $i = 0;
  961. while ($row = $db->sql_fetchrow($result))
  962. {
  963. // If the helpline is defined within the language file, we will use the localised version, else just use the database entry...
  964. if (isset($user->lang[strtoupper($row['bbcode_helpline'])]))
  965. {
  966. $row['bbcode_helpline'] = $user->lang[strtoupper($row['bbcode_helpline'])];
  967. }
  968. // Convert Numeric Character References to UTF-8 chars.
  969. $row['bbcode_helpline'] = utf8_decode_ncr($row['bbcode_helpline']);
  970. $custom_tags = array(
  971. 'BBCODE_NAME' => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'",
  972. 'BBCODE_ID' => $num_predefined_bbcodes + ($i * 2),
  973. 'BBCODE_TAG' => $row['bbcode_tag'],
  974. 'BBCODE_TAG_CLEAN' => str_replace('=', '-', $row['bbcode_tag']),
  975. 'BBCODE_HELPLINE' => $row['bbcode_helpline'],
  976. );
  977. /**
  978. * Event to modify the template data block of a custom bbcode
  979. *
  980. * This event is triggered once per bbcode
  981. *
  982. * @event core.display_custom_bbcodes_modify_row
  983. * @var array custom_tags Template data of the bbcode
  984. * @var array row The data of the bbcode
  985. * @since 3.1.0-a1
  986. */
  987. $vars = array('custom_tags', 'row');
  988. extract($phpbb_dispatcher->trigger_event('core.display_custom_bbcodes_modify_row', compact($vars)));
  989. $template->assign_block_vars('custom_tags', $custom_tags);
  990. $i++;
  991. }
  992. $db->sql_freeresult($result);
  993. /**
  994. * Display custom bbcodes
  995. *
  996. * @event core.display_custom_bbcodes
  997. * @since 3.1.0-a1
  998. */
  999. $phpbb_dispatcher->dispatch('core.display_custom_bbcodes');
  1000. }
  1001. /**
  1002. * Display user activity (action forum/topic)
  1003. */
  1004. function display_user_activity(&$userdata_ary)
  1005. {
  1006. global $auth, $template, $db, $user, $config;
  1007. global $phpbb_root_path, $phpEx;
  1008. global $phpbb_container, $phpbb_dispatcher;
  1009. // Do not display user activity for users having too many posts...
  1010. $limit = $config['load_user_activity_limit'];
  1011. if ($userdata_ary['user_posts'] > $limit && $limit != 0)
  1012. {
  1013. return;
  1014. }
  1015. $forum_ary = array();
  1016. $forum_read_ary = $auth->acl_getf('f_read');
  1017. foreach ($forum_read_ary as $forum_id => $allowed)
  1018. {
  1019. if ($allowed['f_read'])
  1020. {
  1021. $forum_ary[] = (int) $forum_id;
  1022. }
  1023. }
  1024. $forum_ary = array_diff($forum_ary, $user->get_passworded_forums());
  1025. $active_f_row = $active_t_row = array();
  1026. if (!empty($forum_ary))
  1027. {
  1028. /* @var $phpbb_content_visibility \phpbb\content_visibility */
  1029. $phpbb_content_visibility = $phpbb_container->get('content.visibility');
  1030. // Obtain active forum
  1031. $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts
  1032. FROM ' . POSTS_TABLE . '
  1033. WHERE poster_id = ' . $userdata_ary['user_id'] . '
  1034. AND post_postcount = 1
  1035. AND ' . $phpbb_content_visibility->get_forums_visibility_sql('post', $forum_ary) . '
  1036. GROUP BY forum_id
  1037. ORDER BY num_posts DESC';
  1038. $result = $db->sql_query_limit($sql, 1);
  1039. $active_f_row = $db->sql_fetchrow($result);
  1040. $db->sql_freeresult($result);
  1041. if (!empty($active_f_row))
  1042. {
  1043. $sql = 'SELECT forum_name
  1044. FROM ' . FORUMS_TABLE . '
  1045. WHERE forum_id = ' . $active_f_row['forum_id'];
  1046. $result = $db->sql_query($sql, 3600);
  1047. $active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name');
  1048. $db->sql_freeresult($result);
  1049. }
  1050. // Obtain active topic
  1051. $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts
  1052. FROM ' . POSTS_TABLE . '
  1053. WHERE poster_id = ' . $userdata_ary['user_id'] . '
  1054. AND post_postcount = 1
  1055. AND ' . $phpbb_content_visibility->get_forums_visibility_sql('post', $forum_ary) . '
  1056. GROUP BY topic_id
  1057. ORDER BY num_posts DESC';
  1058. $result = $db->sql_query_limit($sql, 1);
  1059. $active_t_row = $db->sql_fetchrow($result);
  1060. $db->sql_freeresult($result);
  1061. if (!empty($active_t_row))
  1062. {
  1063. $sql = 'SELECT topic_title
  1064. FROM ' . TOPICS_TABLE . '
  1065. WHERE topic_id = ' . $active_t_row['topic_id'];
  1066. $result = $db->sql_query($sql);
  1067. $active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title');
  1068. $db->sql_freeresult($result);
  1069. }
  1070. }
  1071. $userdata = $userdata_ary;
  1072. $show_user_activity = true;
  1073. /**
  1074. * Alter list of forums and topics to display as active
  1075. *
  1076. * @event core.display_user_activity_modify_actives
  1077. * @var array userdata User's data
  1078. * @var array active_f_row List of active forums
  1079. * @var array active_t_row List of active posts
  1080. * @var bool show_user_activity Show user forum and topic activity
  1081. * @since 3.1.0-RC3
  1082. * @changed 3.2.5-RC1 Added show_user_activity into event
  1083. */
  1084. $vars = array('userdata', 'active_f_row', 'active_t_row', 'show_user_activity');
  1085. extract($phpbb_dispatcher->trigger_event('core.display_user_activity_modify_actives', compact($vars)));
  1086. $userdata_ary = $userdata;
  1087. unset($userdata);
  1088. $userdata_ary['active_t_row'] = $active_t_row;
  1089. $userdata_ary['active_f_row'] = $active_f_row;
  1090. $active_f_name = $active_f_id = $active_f_count = $active_f_pct = '';
  1091. if (!empty($active_f_row['num_posts']))
  1092. {
  1093. $active_f_name = $active_f_row['forum_name'];
  1094. $active_f_id = $active_f_row['forum_id'];
  1095. $active_f_count = $active_f_row['num_posts'];
  1096. $active_f_pct = ($userdata_ary['user_posts']) ? ($active_f_count / $userdata_ary['user_posts']) * 100 : 0;
  1097. }
  1098. $active_t_name = $active_t_id = $active_t_count = $active_t_pct = '';
  1099. if (!empty($active_t_row['num_posts']))
  1100. {
  1101. $active_t_name = $active_t_row['topic_title'];
  1102. $active_t_id = $active_t_row['topic_id'];
  1103. $active_t_count = $active_t_row['num_posts'];
  1104. $active_t_pct = ($userdata_ary['user_posts']) ? ($active_t_count / $userdata_ary['user_posts']) * 100 : 0;
  1105. }
  1106. $l_active_pct = ($userdata_ary['user_id'] != ANONYMOUS && $userdata_ary['user_id'] == $user->data['user_id']) ? $user->lang['POST_PCT_ACTIVE_OWN'] : $user->lang['POST_PCT_ACTIVE'];
  1107. $template->assign_vars(array(
  1108. 'ACTIVE_FORUM' => $active_f_name,
  1109. 'ACTIVE_FORUM_POSTS' => $user->lang('USER_POSTS', (int) $active_f_count),
  1110. 'ACTIVE_FORUM_PCT' => sprintf($l_active_pct, $active_f_pct),
  1111. 'ACTIVE_TOPIC' => censor_text($active_t_name),
  1112. 'ACTIVE_TOPIC_POSTS' => $user->lang('USER_POSTS', (int) $active_t_count),
  1113. 'ACTIVE_TOPIC_PCT' => sprintf($l_active_pct, $active_t_pct),
  1114. 'U_ACTIVE_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $active_f_id),
  1115. 'U_ACTIVE_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $active_t_id),
  1116. 'S_SHOW_ACTIVITY' => $show_user_activity)
  1117. );
  1118. }
  1119. /**
  1120. * Topic and forum watching common code
  1121. */
  1122. function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, $notify_status = 'unset', $start = 0, $item_title = '')
  1123. {
  1124. global $db, $user, $phpEx, $start, $phpbb_root_path;
  1125. global $request;
  1126. $table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE : TOPICS_WATCH_TABLE;
  1127. $where_sql = ($mode == 'forum') ? 'forum_id' : 'topic_id';
  1128. $match_id = ($mode == 'forum') ? $forum_id : $topic_id;
  1129. $u_url = "uid={$user->data['user_id']}";
  1130. $u_url .= ($mode == 'forum') ? '&amp;f' : '&amp;f=' . $forum_id . '&amp;t';
  1131. $is_watching = 0;
  1132. // Is user watching this topic?
  1133. if ($user_id != ANONYMOUS)
  1134. {
  1135. $can_watch = true;
  1136. if ($notify_status == 'unset')
  1137. {
  1138. $sql = "SELECT notify_status
  1139. FROM $table_sql
  1140. WHERE $where_sql = $match_id
  1141. AND user_id = $user_id";
  1142. $result = $db->sql_query($sql);
  1143. $notify_status = ($row = $db->sql_fetchrow($result)) ? $row['notify_status'] : NULL;
  1144. $db->sql_freeresult($result);
  1145. }
  1146. if (!is_null($notify_status) && $notify_status !== '')
  1147. {
  1148. if (isset($_GET['unwatch']))
  1149. {
  1150. $uid = $request->variable('uid', 0);
  1151. $token = $request->variable('hash', '');
  1152. if ($token && check_link_hash($token, "{$mode}_$match_id") || confirm_box(true))
  1153. {
  1154. if ($uid != $user_id || $request->variable('unwatch', '', false, \phpbb\request\request_interface::GET) != $mode)
  1155. {
  1156. $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
  1157. $message = $user->lang['ERR_UNWATCHING'];
  1158. if (!$request->is_ajax())
  1159. {
  1160. $message .= '<br /><br />' . $user->lang('RETURN_' . strtoupper($mode), '<a href="' . $redirect_url . '">', '</a>');
  1161. }
  1162. trigger_error($message);
  1163. }
  1164. $sql = 'DELETE FROM ' . $table_sql . "
  1165. WHERE $where_sql = $match_id
  1166. AND user_id = $user_id";
  1167. $db->sql_query($sql);
  1168. $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
  1169. $message = $user->lang['NOT_WATCHING_' . strtoupper($mode)];
  1170. if (!$request->is_ajax())
  1171. {
  1172. $message .= '<br /><br />' . $user->lang('RETURN_' . strtoupper($mode), '<a href="' . $redirect_url . '">', '</a>');
  1173. }
  1174. meta_refresh(3, $redirect_url);
  1175. trigger_error($message);
  1176. }
  1177. else
  1178. {
  1179. $s_hidden_fields = array(
  1180. 'uid' => $user->data['user_id'],
  1181. 'unwatch' => $mode,
  1182. 'start' => $start,
  1183. 'f' => $forum_id,
  1184. );
  1185. if ($mode != 'forum')
  1186. {
  1187. $s_hidden_fields['t'] = $topic_id;
  1188. }
  1189. if ($item_title == '')
  1190. {
  1191. $confirm_box_message = 'UNWATCH_' . strtoupper($mode);
  1192. }
  1193. else
  1194. {
  1195. $confirm_box_message = $user->lang('UNWATCH_' . strtoupper($mode) . '_DETAILED', $item_title);
  1196. }
  1197. confirm_box(false, $confirm_box_message, build_hidden_fields($s_hidden_fields));
  1198. }
  1199. }
  1200. else
  1201. {
  1202. $is_watching = true;
  1203. if ($notify_status != NOTIFY_YES)
  1204. {
  1205. $sql = 'UPDATE ' . $table_sql . "
  1206. SET notify_status = " . NOTIFY_YES . "
  1207. WHERE $where_sql = $match_id
  1208. AND user_id = $user_id";
  1209. $db->sql_query($sql);
  1210. }
  1211. }
  1212. }
  1213. else
  1214. {
  1215. if (isset($_GET['watch']))
  1216. {
  1217. $uid = $request->variable('uid', 0);
  1218. $token = $request->variable('hash', '');
  1219. if ($token && check_link_hash($token, "{$mode}_$match_id") || confirm_box(true))
  1220. {
  1221. if ($uid != $user_id || $request->variable('watch', '', false, \phpbb\request\request_interface::GET) != $mode)
  1222. {
  1223. $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
  1224. $message = $user->lang['ERR_WATCHING'];
  1225. if (!$request->is_ajax())
  1226. {
  1227. $message .= '<br /><br />' . $user->lang('RETURN_' . strtoupper($mode), '<a href="' . $redirect_url . '">', '</a>');
  1228. }
  1229. trigger_error($message);
  1230. }
  1231. $is_watching = true;
  1232. $sql = 'INSERT INTO ' . $table_sql . " (user_id, $where_sql, notify_status)
  1233. VALUES ($user_id, $match_id, " . NOTIFY_YES . ')';
  1234. $db->sql_query($sql);
  1235. $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
  1236. $message = $user->lang['ARE_WATCHING_' . strtoupper($mode)];
  1237. if (!$request->is_ajax())
  1238. {
  1239. $message .= '<br /><br />' . $user->lang('RETURN_' . strtoupper($mode), '<a href="' . $redirect_url . '">', '</a>');
  1240. }
  1241. meta_refresh(3, $redirect_url);
  1242. trigger_error($message);
  1243. }
  1244. else
  1245. {
  1246. $s_hidden_fields = array(
  1247. 'uid' => $user->data['user_id'],
  1248. 'watch' => $mode,
  1249. 'start' => $start,
  1250. 'f' => $forum_id,
  1251. );
  1252. if ($mode != 'forum')
  1253. {
  1254. $s_hidden_fields['t'] = $topic_id;
  1255. }
  1256. $confirm_box_message = (($item_title == '') ? 'WATCH_' . strtoupper($mode) : $user->lang('WATCH_' . strtoupper($mode) . '_DETAILED', $item_title));
  1257. confirm_box(false, $confirm_box_message, build_hidden_fields($s_hidden_fields));
  1258. }
  1259. }
  1260. else
  1261. {
  1262. $is_watching = 0;
  1263. }
  1264. }
  1265. }
  1266. else
  1267. {
  1268. if ((isset($_GET['unwatch']) && $request->variable('unwatch', '', false, \phpbb\request\request_interface::GET) == $mode) ||
  1269. (isset($_GET['watch']) && $request->variable('watch…

Large files files are truncated, but you can click here to view the full file