PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/functions_display.php

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