PageRenderTime 51ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/phpBB/includes/ucp/ucp_main.php

https://github.com/Jipem/phpbb
PHP | 846 lines | 662 code | 150 blank | 34 comment | 83 complexity | 022db5fcd04b59ef262200c1080a96ad MD5 | raw file
Possible License(s): AGPL-1.0
  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. * ucp_main
  22. * UCP Front Panel
  23. */
  24. class ucp_main
  25. {
  26. var $p_master;
  27. var $u_action;
  28. function ucp_main(&$p_master)
  29. {
  30. $this->p_master = &$p_master;
  31. }
  32. function main($id, $mode)
  33. {
  34. global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
  35. global $request;
  36. switch ($mode)
  37. {
  38. case 'front':
  39. $user->add_lang('memberlist');
  40. $sql_from = TOPICS_TABLE . ' t ';
  41. $sql_select = '';
  42. if ($config['load_db_track'])
  43. {
  44. $sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.topic_id = t.topic_id
  45. AND tp.user_id = ' . $user->data['user_id'] . ')';
  46. $sql_select .= ', tp.topic_posted';
  47. }
  48. if ($config['load_db_lastread'])
  49. {
  50. $sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id
  51. AND tt.user_id = ' . $user->data['user_id'] . ')';
  52. $sql_select .= ', tt.mark_time';
  53. $sql_from .= ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.forum_id = t.forum_id
  54. AND ft.user_id = ' . $user->data['user_id'] . ')';
  55. $sql_select .= ', ft.mark_time AS forum_mark_time';
  56. }
  57. $topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
  58. $folder = 'global_read';
  59. $folder_new = 'global_unread';
  60. // Get cleaned up list... return only those forums having the f_read permission
  61. $forum_ary = $auth->acl_getf('f_read', true);
  62. $forum_ary = array_unique(array_keys($forum_ary));
  63. $topic_list = $rowset = array();
  64. // If the user can't see any forums, he can't read any posts because fid of 0 is invalid
  65. if (!empty($forum_ary))
  66. {
  67. $sql = "SELECT t.* $sql_select
  68. FROM $sql_from
  69. WHERE t.topic_type = " . POST_GLOBAL . '
  70. AND ' . $db->sql_in_set('t.forum_id', $forum_ary) . '
  71. ORDER BY t.topic_last_post_time DESC';
  72. $result = $db->sql_query($sql);
  73. while ($row = $db->sql_fetchrow($result))
  74. {
  75. $topic_list[] = $row['topic_id'];
  76. $rowset[$row['topic_id']] = $row;
  77. }
  78. $db->sql_freeresult($result);
  79. }
  80. $topic_forum_list = array();
  81. foreach ($rowset as $t_id => $row)
  82. {
  83. if (isset($forum_tracking_info[$row['forum_id']]))
  84. {
  85. $row['forum_mark_time'] = $forum_tracking_info[$row['forum_id']];
  86. }
  87. $topic_forum_list[$row['forum_id']]['forum_mark_time'] = ($config['load_db_lastread'] && $user->data['is_registered'] && isset($row['forum_mark_time'])) ? $row['forum_mark_time'] : 0;
  88. $topic_forum_list[$row['forum_id']]['topics'][] = (int) $t_id;
  89. }
  90. $topic_tracking_info = $tracking_topics = array();
  91. if ($config['load_db_lastread'])
  92. {
  93. foreach ($topic_forum_list as $f_id => $topic_row)
  94. {
  95. $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']));
  96. }
  97. }
  98. else
  99. {
  100. foreach ($topic_forum_list as $f_id => $topic_row)
  101. {
  102. $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics']);
  103. }
  104. }
  105. unset($topic_forum_list);
  106. foreach ($topic_list as $topic_id)
  107. {
  108. $row = &$rowset[$topic_id];
  109. $forum_id = $row['forum_id'];
  110. $topic_id = $row['topic_id'];
  111. $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
  112. $folder_img = ($unread_topic) ? $folder_new : $folder;
  113. $folder_alt = ($unread_topic) ? 'UNREAD_POSTS' : (($row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_UNREAD_POSTS');
  114. if ($row['topic_status'] == ITEM_LOCKED)
  115. {
  116. $folder_img .= '_locked';
  117. }
  118. // Posted image?
  119. if (!empty($row['topic_posted']) && $row['topic_posted'])
  120. {
  121. $folder_img .= '_mine';
  122. }
  123. $template->assign_block_vars('topicrow', array(
  124. 'FORUM_ID' => $forum_id,
  125. 'TOPIC_ID' => $topic_id,
  126. 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  127. 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  128. 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  129. 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
  130. 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']),
  131. 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
  132. 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
  133. 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  134. 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  135. 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  136. 'TOPIC_TITLE' => censor_text($row['topic_title']),
  137. 'TOPIC_TYPE' => $topic_type,
  138. 'TOPIC_IMG_STYLE' => $folder_img,
  139. 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
  140. 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', '') : '',
  141. 'S_USER_POSTED' => (!empty($row['topic_posted']) && $row['topic_posted']) ? true : false,
  142. 'S_UNREAD' => $unread_topic,
  143. 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  144. 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;p=" . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
  145. 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  146. 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;view=unread") . '#unread',
  147. 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id"))
  148. );
  149. }
  150. if ($config['load_user_activity'])
  151. {
  152. if (!function_exists('display_user_activity'))
  153. {
  154. include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  155. }
  156. display_user_activity($user->data);
  157. }
  158. // Do the relevant calculations
  159. $memberdays = max(1, round((time() - $user->data['user_regdate']) / 86400));
  160. $posts_per_day = $user->data['user_posts'] / $memberdays;
  161. $percentage = ($config['num_posts']) ? min(100, ($user->data['user_posts'] / $config['num_posts']) * 100) : 0;
  162. $template->assign_vars(array(
  163. 'USER_COLOR' => (!empty($user->data['user_colour'])) ? $user->data['user_colour'] : '',
  164. 'JOINED' => $user->format_date($user->data['user_regdate']),
  165. 'LAST_ACTIVE' => (empty($last_active)) ? ' - ' : $user->format_date($last_active),
  166. 'WARNINGS' => ($user->data['user_warnings']) ? $user->data['user_warnings'] : 0,
  167. 'POSTS' => ($user->data['user_posts']) ? $user->data['user_posts'] : 0,
  168. 'POSTS_DAY' => $user->lang('POST_DAY', $posts_per_day),
  169. 'POSTS_PCT' => $user->lang('POST_PCT', $percentage),
  170. // 'S_GROUP_OPTIONS' => $group_options,
  171. 'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $user->data['user_id'] . '&amp;sr=posts') : '',
  172. ));
  173. break;
  174. case 'subscribed':
  175. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  176. $user->add_lang('viewforum');
  177. add_form_key('ucp_front_subscribed');
  178. $unwatch = (isset($_POST['unwatch'])) ? true : false;
  179. if ($unwatch)
  180. {
  181. if (check_form_key('ucp_front_subscribed'))
  182. {
  183. $forums = array_keys(request_var('f', array(0 => 0)));
  184. $topics = array_keys(request_var('t', array(0 => 0)));
  185. $msg = '';
  186. if (sizeof($forums) || sizeof($topics))
  187. {
  188. $l_unwatch = '';
  189. if (sizeof($forums))
  190. {
  191. $sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . '
  192. WHERE ' . $db->sql_in_set('forum_id', $forums) . '
  193. AND user_id = ' . $user->data['user_id'];
  194. $db->sql_query($sql);
  195. $l_unwatch .= '_FORUMS';
  196. }
  197. if (sizeof($topics))
  198. {
  199. $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . '
  200. WHERE ' . $db->sql_in_set('topic_id', $topics) . '
  201. AND user_id = ' . $user->data['user_id'];
  202. $db->sql_query($sql);
  203. $l_unwatch .= '_TOPICS';
  204. }
  205. $msg = $user->lang['UNWATCHED' . $l_unwatch];
  206. }
  207. else
  208. {
  209. $msg = $user->lang['NO_WATCHED_SELECTED'];
  210. }
  211. }
  212. else
  213. {
  214. $msg = $user->lang['FORM_INVALID'];
  215. }
  216. $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=subscribed") . '">', '</a>');
  217. meta_refresh(3, append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=subscribed"));
  218. trigger_error($message);
  219. }
  220. $forbidden_forums = array();
  221. if ($config['allow_forum_notify'])
  222. {
  223. $forbidden_forums = $auth->acl_getf('!f_read', true);
  224. $forbidden_forums = array_unique(array_keys($forbidden_forums));
  225. $sql_array = array(
  226. 'SELECT' => 'f.*',
  227. 'FROM' => array(
  228. FORUMS_WATCH_TABLE => 'fw',
  229. FORUMS_TABLE => 'f'
  230. ),
  231. 'WHERE' => 'fw.user_id = ' . $user->data['user_id'] . '
  232. AND f.forum_id = fw.forum_id
  233. AND ' . $db->sql_in_set('f.forum_id', $forbidden_forums, true, true),
  234. 'ORDER_BY' => 'left_id'
  235. );
  236. if ($config['load_db_lastread'])
  237. {
  238. $sql_array['LEFT_JOIN'] = array(
  239. array(
  240. 'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
  241. 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'
  242. )
  243. );
  244. $sql_array['SELECT'] .= ', ft.mark_time ';
  245. }
  246. else
  247. {
  248. $tracking_topics = $request->variable($config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE);
  249. $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
  250. }
  251. $sql = $db->sql_build_query('SELECT', $sql_array);
  252. $result = $db->sql_query($sql);
  253. while ($row = $db->sql_fetchrow($result))
  254. {
  255. $forum_id = $row['forum_id'];
  256. if ($config['load_db_lastread'])
  257. {
  258. $forum_check = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
  259. }
  260. else
  261. {
  262. $forum_check = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
  263. }
  264. $unread_forum = ($row['forum_last_post_time'] > $forum_check) ? true : false;
  265. // Which folder should we display?
  266. if ($row['forum_status'] == ITEM_LOCKED)
  267. {
  268. $folder_image = ($unread_forum) ? 'forum_unread_locked' : 'forum_read_locked';
  269. $folder_alt = 'FORUM_LOCKED';
  270. }
  271. else
  272. {
  273. $folder_image = ($unread_forum) ? 'forum_unread' : 'forum_read';
  274. $folder_alt = ($unread_forum) ? 'UNREAD_POSTS' : 'NO_UNREAD_POSTS';
  275. }
  276. // Create last post link information, if appropriate
  277. if ($row['forum_last_post_id'])
  278. {
  279. $last_post_time = $user->format_date($row['forum_last_post_time']);
  280. $last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;p=" . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
  281. }
  282. else
  283. {
  284. $last_post_time = $last_post_url = '';
  285. }
  286. $template->assign_block_vars('forumrow', array(
  287. 'FORUM_ID' => $forum_id,
  288. 'FORUM_IMG_STYLE' => $folder_image,
  289. 'FORUM_FOLDER_IMG' => $user->img($folder_image, $folder_alt),
  290. 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
  291. 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
  292. 'FORUM_NAME' => $row['forum_name'],
  293. 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
  294. 'LAST_POST_SUBJECT' => $row['forum_last_post_subject'],
  295. 'LAST_POST_TIME' => $last_post_time,
  296. 'LAST_POST_AUTHOR' => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  297. 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  298. 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  299. 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  300. 'S_UNREAD_FORUM' => $unread_forum,
  301. 'U_LAST_POST' => $last_post_url,
  302. 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
  303. );
  304. }
  305. $db->sql_freeresult($result);
  306. }
  307. // Subscribed Topics
  308. if ($config['allow_topic_notify'])
  309. {
  310. if (empty($forbidden_forums))
  311. {
  312. $forbidden_forums = $auth->acl_getf('!f_read', true);
  313. $forbidden_forums = array_unique(array_keys($forbidden_forums));
  314. }
  315. $this->assign_topiclist('subscribed', $forbidden_forums);
  316. }
  317. $template->assign_vars(array(
  318. 'S_TOPIC_NOTIFY' => $config['allow_topic_notify'],
  319. 'S_FORUM_NOTIFY' => $config['allow_forum_notify'],
  320. ));
  321. break;
  322. case 'bookmarks':
  323. if (!$config['allow_bookmarks'])
  324. {
  325. $template->assign_vars(array(
  326. 'S_NO_DISPLAY_BOOKMARKS' => true)
  327. );
  328. break;
  329. }
  330. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  331. $user->add_lang('viewforum');
  332. if (isset($_POST['unbookmark']))
  333. {
  334. $s_hidden_fields = array('unbookmark' => 1);
  335. $topics = (isset($_POST['t'])) ? array_keys(request_var('t', array(0 => 0))) : array();
  336. $url = $this->u_action;
  337. if (!sizeof($topics))
  338. {
  339. trigger_error('NO_BOOKMARKS_SELECTED');
  340. }
  341. foreach ($topics as $topic_id)
  342. {
  343. $s_hidden_fields['t'][$topic_id] = 1;
  344. }
  345. if (confirm_box(true))
  346. {
  347. $sql = 'DELETE FROM ' . BOOKMARKS_TABLE . '
  348. WHERE user_id = ' . $user->data['user_id'] . '
  349. AND ' . $db->sql_in_set('topic_id', $topics);
  350. $db->sql_query($sql);
  351. meta_refresh(3, $url);
  352. $message = $user->lang['BOOKMARKS_REMOVED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $url . '">', '</a>');
  353. trigger_error($message);
  354. }
  355. else
  356. {
  357. confirm_box(false, 'REMOVE_SELECTED_BOOKMARKS', build_hidden_fields($s_hidden_fields));
  358. }
  359. }
  360. $forbidden_forums = $auth->acl_getf('!f_read', true);
  361. $forbidden_forums = array_unique(array_keys($forbidden_forums));
  362. $this->assign_topiclist('bookmarks', $forbidden_forums);
  363. break;
  364. case 'drafts':
  365. $pm_drafts = ($this->p_master->p_name == 'pm') ? true : false;
  366. $template->assign_var('S_SHOW_DRAFTS', true);
  367. $user->add_lang('posting');
  368. $edit = (isset($_REQUEST['edit'])) ? true : false;
  369. $submit = (isset($_POST['submit'])) ? true : false;
  370. $draft_id = $request->variable('edit', 0);
  371. $delete = (isset($_POST['delete'])) ? true : false;
  372. $s_hidden_fields = ($edit) ? '<input type="hidden" name="edit" value="' . $draft_id . '" />' : '';
  373. $draft_subject = $draft_message = '';
  374. add_form_key('ucp_draft');
  375. if ($delete)
  376. {
  377. if (check_form_key('ucp_draft'))
  378. {
  379. $drafts = array_keys(request_var('d', array(0 => 0)));
  380. if (sizeof($drafts))
  381. {
  382. $sql = 'DELETE FROM ' . DRAFTS_TABLE . '
  383. WHERE ' . $db->sql_in_set('draft_id', $drafts) . '
  384. AND user_id = ' . $user->data['user_id'];
  385. $db->sql_query($sql);
  386. }
  387. $msg = $user->lang['DRAFTS_DELETED'];
  388. unset($drafts);
  389. }
  390. else
  391. {
  392. $msg = $user->lang['FORM_INVALID'];
  393. }
  394. $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
  395. meta_refresh(3, $this->u_action);
  396. trigger_error($message);
  397. }
  398. if ($submit && $edit)
  399. {
  400. $draft_subject = utf8_normalize_nfc(request_var('subject', '', true));
  401. $draft_message = utf8_normalize_nfc(request_var('message', '', true));
  402. if (check_form_key('ucp_draft'))
  403. {
  404. if ($draft_message && $draft_subject)
  405. {
  406. $draft_row = array(
  407. 'draft_subject' => $draft_subject,
  408. 'draft_message' => $draft_message
  409. );
  410. $sql = 'UPDATE ' . DRAFTS_TABLE . '
  411. SET ' . $db->sql_build_array('UPDATE', $draft_row) . "
  412. WHERE draft_id = $draft_id
  413. AND user_id = " . $user->data['user_id'];
  414. $db->sql_query($sql);
  415. $message = $user->lang['DRAFT_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
  416. meta_refresh(3, $this->u_action);
  417. trigger_error($message);
  418. }
  419. else
  420. {
  421. $template->assign_var('ERROR', ($draft_message == '') ? $user->lang['EMPTY_DRAFT'] : (($draft_subject == '') ? $user->lang['EMPTY_DRAFT_TITLE'] : ''));
  422. }
  423. }
  424. else
  425. {
  426. $template->assign_var('ERROR', $user->lang['FORM_INVALID']);
  427. }
  428. }
  429. if (!$pm_drafts)
  430. {
  431. $sql = 'SELECT d.*, f.forum_name
  432. FROM ' . DRAFTS_TABLE . ' d, ' . FORUMS_TABLE . ' f
  433. WHERE d.user_id = ' . $user->data['user_id'] . ' ' .
  434. (($edit) ? "AND d.draft_id = $draft_id" : '') . '
  435. AND f.forum_id = d.forum_id
  436. ORDER BY d.save_time DESC';
  437. }
  438. else
  439. {
  440. $sql = 'SELECT * FROM ' . DRAFTS_TABLE . '
  441. WHERE user_id = ' . $user->data['user_id'] . ' ' .
  442. (($edit) ? "AND draft_id = $draft_id" : '') . '
  443. AND forum_id = 0
  444. AND topic_id = 0
  445. ORDER BY save_time DESC';
  446. }
  447. $result = $db->sql_query($sql);
  448. $draftrows = $topic_ids = array();
  449. while ($row = $db->sql_fetchrow($result))
  450. {
  451. if ($row['topic_id'])
  452. {
  453. $topic_ids[] = (int) $row['topic_id'];
  454. }
  455. $draftrows[] = $row;
  456. }
  457. $db->sql_freeresult($result);
  458. if (sizeof($topic_ids))
  459. {
  460. $sql = 'SELECT topic_id, forum_id, topic_title
  461. FROM ' . TOPICS_TABLE . '
  462. WHERE ' . $db->sql_in_set('topic_id', array_unique($topic_ids));
  463. $result = $db->sql_query($sql);
  464. while ($row = $db->sql_fetchrow($result))
  465. {
  466. $topic_rows[$row['topic_id']] = $row;
  467. }
  468. $db->sql_freeresult($result);
  469. }
  470. unset($topic_ids);
  471. $template->assign_var('S_EDIT_DRAFT', $edit);
  472. $row_count = 0;
  473. foreach ($draftrows as $draft)
  474. {
  475. $link_topic = $link_forum = $link_pm = false;
  476. $insert_url = $view_url = $title = '';
  477. if (isset($topic_rows[$draft['topic_id']]) && $auth->acl_get('f_read', $topic_rows[$draft['topic_id']]['forum_id']))
  478. {
  479. $link_topic = true;
  480. $view_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_rows[$draft['topic_id']]['forum_id'] . '&amp;t=' . $draft['topic_id']);
  481. $title = $topic_rows[$draft['topic_id']]['topic_title'];
  482. $insert_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $topic_rows[$draft['topic_id']]['forum_id'] . '&amp;t=' . $draft['topic_id'] . '&amp;mode=reply&amp;d=' . $draft['draft_id']);
  483. }
  484. else if ($auth->acl_get('f_read', $draft['forum_id']))
  485. {
  486. $link_forum = true;
  487. $view_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $draft['forum_id']);
  488. $title = $draft['forum_name'];
  489. $insert_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $draft['forum_id'] . '&amp;mode=post&amp;d=' . $draft['draft_id']);
  490. }
  491. else if ($pm_drafts)
  492. {
  493. $link_pm = true;
  494. $insert_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=compose&amp;d=" . $draft['draft_id']);
  495. }
  496. $template_row = array(
  497. 'DATE' => $user->format_date($draft['save_time']),
  498. 'DRAFT_MESSAGE' => ($submit) ? $draft_message : $draft['draft_message'],
  499. 'DRAFT_SUBJECT' => ($submit) ? $draft_subject : $draft['draft_subject'],
  500. 'TITLE' => $title,
  501. 'DRAFT_ID' => $draft['draft_id'],
  502. 'FORUM_ID' => $draft['forum_id'],
  503. 'TOPIC_ID' => $draft['topic_id'],
  504. 'U_VIEW' => $view_url,
  505. 'U_VIEW_EDIT' => $this->u_action . '&amp;edit=' . $draft['draft_id'],
  506. 'U_INSERT' => $insert_url,
  507. 'S_LINK_TOPIC' => $link_topic,
  508. 'S_LINK_FORUM' => $link_forum,
  509. 'S_LINK_PM' => $link_pm,
  510. 'S_HIDDEN_FIELDS' => $s_hidden_fields
  511. );
  512. $row_count++;
  513. ($edit) ? $template->assign_vars($template_row) : $template->assign_block_vars('draftrow', $template_row);
  514. }
  515. if (!$edit)
  516. {
  517. $template->assign_var('S_DRAFT_ROWS', $row_count);
  518. }
  519. break;
  520. }
  521. $template->assign_vars(array(
  522. 'L_TITLE' => $user->lang['UCP_MAIN_' . strtoupper($mode)],
  523. 'S_DISPLAY_MARK_ALL' => ($mode == 'watched' || ($mode == 'drafts' && !isset($_GET['edit']))) ? true : false,
  524. 'S_HIDDEN_FIELDS' => (isset($s_hidden_fields)) ? $s_hidden_fields : '',
  525. 'S_UCP_ACTION' => $this->u_action,
  526. 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
  527. 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
  528. ));
  529. // Set desired template
  530. $this->tpl_name = 'ucp_main_' . $mode;
  531. $this->page_title = 'UCP_MAIN_' . strtoupper($mode);
  532. }
  533. /**
  534. * Build and assign topiclist for bookmarks/subscribed topics
  535. */
  536. function assign_topiclist($mode = 'subscribed', $forbidden_forum_ary = array())
  537. {
  538. global $user, $db, $template, $config, $cache, $auth, $phpbb_root_path, $phpEx, $phpbb_container;
  539. $table = ($mode == 'subscribed') ? TOPICS_WATCH_TABLE : BOOKMARKS_TABLE;
  540. $start = request_var('start', 0);
  541. $pagination = $phpbb_container->get('pagination');
  542. // Grab icons
  543. $icons = $cache->obtain_icons();
  544. $sql_array = array(
  545. 'SELECT' => 'COUNT(t.topic_id) as topics_count',
  546. 'FROM' => array(
  547. $table => 'i',
  548. TOPICS_TABLE => 't'
  549. ),
  550. 'WHERE' => 'i.topic_id = t.topic_id
  551. AND i.user_id = ' . $user->data['user_id'] . '
  552. AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true),
  553. );
  554. $sql = $db->sql_build_query('SELECT', $sql_array);
  555. $result = $db->sql_query($sql);
  556. $topics_count = (int) $db->sql_fetchfield('topics_count');
  557. $db->sql_freeresult($result);
  558. if ($topics_count)
  559. {
  560. $start = $pagination->validate_start($start, $config['topics_per_page'], $topics_count);
  561. $pagination->generate_template_pagination($this->u_action, 'pagination', 'start', $topics_count, $config['topics_per_page'], $start);
  562. $template->assign_vars(array(
  563. 'TOTAL_TOPICS' => $user->lang('VIEW_FORUM_TOPICS', (int) $topics_count),
  564. ));
  565. }
  566. if ($mode == 'subscribed')
  567. {
  568. $sql_array = array(
  569. 'SELECT' => 't.*, f.forum_name',
  570. 'FROM' => array(
  571. TOPICS_WATCH_TABLE => 'tw',
  572. TOPICS_TABLE => 't'
  573. ),
  574. 'WHERE' => 'tw.user_id = ' . $user->data['user_id'] . '
  575. AND t.topic_id = tw.topic_id
  576. AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true),
  577. 'ORDER_BY' => 't.topic_last_post_time DESC'
  578. );
  579. $sql_array['LEFT_JOIN'] = array();
  580. }
  581. else
  582. {
  583. $sql_array = array(
  584. 'SELECT' => 't.*, f.forum_name, b.topic_id as b_topic_id',
  585. 'FROM' => array(
  586. BOOKMARKS_TABLE => 'b',
  587. ),
  588. 'WHERE' => 'b.user_id = ' . $user->data['user_id'] . '
  589. AND ' . $db->sql_in_set('f.forum_id', $forbidden_forum_ary, true, true),
  590. 'ORDER_BY' => 't.topic_last_post_time DESC'
  591. );
  592. $sql_array['LEFT_JOIN'] = array();
  593. $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TABLE => 't'), 'ON' => 'b.topic_id = t.topic_id');
  594. }
  595. $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 't.forum_id = f.forum_id');
  596. if ($config['load_db_lastread'])
  597. {
  598. $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id']);
  599. $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id']);
  600. $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time AS forum_mark_time';
  601. }
  602. if ($config['load_db_track'])
  603. {
  604. $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . $user->data['user_id']);
  605. $sql_array['SELECT'] .= ', tp.topic_posted';
  606. }
  607. $sql = $db->sql_build_query('SELECT', $sql_array);
  608. $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
  609. $topic_list = $topic_forum_list = $global_announce_list = $rowset = array();
  610. while ($row = $db->sql_fetchrow($result))
  611. {
  612. $topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
  613. $topic_list[] = $topic_id;
  614. $rowset[$topic_id] = $row;
  615. $topic_forum_list[$row['forum_id']]['forum_mark_time'] = ($config['load_db_lastread']) ? $row['forum_mark_time'] : 0;
  616. $topic_forum_list[$row['forum_id']]['topics'][] = $topic_id;
  617. if ($row['topic_type'] == POST_GLOBAL)
  618. {
  619. $global_announce_list[] = $topic_id;
  620. }
  621. }
  622. $db->sql_freeresult($result);
  623. $topic_tracking_info = array();
  624. if ($config['load_db_lastread'])
  625. {
  626. foreach ($topic_forum_list as $f_id => $topic_row)
  627. {
  628. $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']));
  629. }
  630. }
  631. else
  632. {
  633. foreach ($topic_forum_list as $f_id => $topic_row)
  634. {
  635. $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics']);
  636. }
  637. }
  638. $phpbb_content_visibility = $phpbb_container->get('content.visibility');
  639. foreach ($topic_list as $topic_id)
  640. {
  641. $row = &$rowset[$topic_id];
  642. $forum_id = $row['forum_id'];
  643. $topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
  644. $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
  645. // Replies
  646. $replies = $phpbb_content_visibility->get_count('topic_posts', $row, $forum_id) - 1;
  647. if ($row['topic_status'] == ITEM_MOVED && !empty($row['topic_moved_id']))
  648. {
  649. $topic_id = $row['topic_moved_id'];
  650. }
  651. // Get folder img, topic status/type related information
  652. $folder_img = $folder_alt = $topic_type = '';
  653. topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
  654. $view_topic_url_params = "f=$forum_id&amp;t=$topic_id";
  655. $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params);
  656. // Send vars to template
  657. $template->assign_block_vars('topicrow', array(
  658. 'FORUM_ID' => $forum_id,
  659. 'TOPIC_ID' => $topic_id,
  660. 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
  661. 'LAST_POST_SUBJECT' => $row['topic_last_post_subject'],
  662. 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
  663. 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
  664. 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  665. 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  666. 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  667. 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  668. 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  669. 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  670. 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  671. 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  672. 'S_DELETED_TOPIC' => (!$row['topic_id']) ? true : false,
  673. 'REPLIES' => $replies,
  674. 'VIEWS' => $row['topic_views'],
  675. 'TOPIC_TITLE' => censor_text($row['topic_title']),
  676. 'TOPIC_TYPE' => $topic_type,
  677. 'FORUM_NAME' => $row['forum_name'],
  678. 'TOPIC_IMG_STYLE' => $folder_img,
  679. 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
  680. 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt],
  681. 'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
  682. 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
  683. 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
  684. 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
  685. 'S_TOPIC_TYPE' => $row['topic_type'],
  686. 'S_USER_POSTED' => (!empty($row['topic_posted'])) ? true : false,
  687. 'S_UNREAD_TOPIC' => $unread_topic,
  688. 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;view=unread') . '#unread',
  689. 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
  690. 'U_VIEW_TOPIC' => $view_topic_url,
  691. 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
  692. ));
  693. $pagination->generate_template_pagination(append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . "&amp;t=$topic_id"), 'topicrow.pagination', 'start', $replies + 1, $config['posts_per_page'], 1, true, true);
  694. }
  695. }
  696. }