PageRenderTime 61ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/phpBB/includes/ucp/ucp_main.php

http://github.com/phpbb/phpbb3
PHP | 1028 lines | 741 code | 166 blank | 121 comment | 90 complexity | 7eb563d741afd4854058285fab6e2d26 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 __construct($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, $phpbb_dispatcher;
  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. /**
  68. * Modify sql variables before query is processed
  69. *
  70. * @event core.ucp_main_front_modify_sql
  71. * @var string sql_select SQL select
  72. * @var string sql_from SQL from
  73. * @var array forum_ary Forum array
  74. * @since 3.2.4-RC1
  75. */
  76. $vars = array(
  77. 'sql_select',
  78. 'sql_from',
  79. 'forum_ary',
  80. );
  81. extract($phpbb_dispatcher->trigger_event('core.ucp_main_front_modify_sql', compact($vars)));
  82. $sql = "SELECT t.* $sql_select
  83. FROM $sql_from
  84. WHERE t.topic_type = " . POST_GLOBAL . '
  85. AND ' . $db->sql_in_set('t.forum_id', $forum_ary) . '
  86. ORDER BY t.topic_last_post_time DESC, t.topic_last_post_id DESC';
  87. $result = $db->sql_query($sql);
  88. while ($row = $db->sql_fetchrow($result))
  89. {
  90. $topic_list[] = $row['topic_id'];
  91. $rowset[$row['topic_id']] = $row;
  92. }
  93. $db->sql_freeresult($result);
  94. }
  95. $topic_forum_list = array();
  96. foreach ($rowset as $t_id => $row)
  97. {
  98. if (isset($forum_tracking_info[$row['forum_id']]))
  99. {
  100. $row['forum_mark_time'] = $forum_tracking_info[$row['forum_id']];
  101. }
  102. $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;
  103. $topic_forum_list[$row['forum_id']]['topics'][] = (int) $t_id;
  104. }
  105. $topic_tracking_info = $tracking_topics = array();
  106. if ($config['load_db_lastread'])
  107. {
  108. foreach ($topic_forum_list as $f_id => $topic_row)
  109. {
  110. $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']));
  111. }
  112. }
  113. else
  114. {
  115. foreach ($topic_forum_list as $f_id => $topic_row)
  116. {
  117. $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics']);
  118. }
  119. }
  120. unset($topic_forum_list);
  121. foreach ($topic_list as $topic_id)
  122. {
  123. $row = &$rowset[$topic_id];
  124. $forum_id = $row['forum_id'];
  125. $topic_id = $row['topic_id'];
  126. $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
  127. $folder_img = ($unread_topic) ? $folder_new : $folder;
  128. $folder_alt = ($unread_topic) ? 'UNREAD_POSTS' : (($row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_UNREAD_POSTS');
  129. if ($row['topic_status'] == ITEM_LOCKED)
  130. {
  131. $folder_img .= '_locked';
  132. }
  133. // Posted image?
  134. if (!empty($row['topic_posted']) && $row['topic_posted'])
  135. {
  136. $folder_img .= '_mine';
  137. }
  138. $topicrow = array(
  139. 'FORUM_ID' => $forum_id,
  140. 'TOPIC_ID' => $topic_id,
  141. 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  142. 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  143. 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  144. 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
  145. 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']),
  146. 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
  147. 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
  148. 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  149. 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  150. 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  151. 'TOPIC_TITLE' => censor_text($row['topic_title']),
  152. 'TOPIC_TYPE' => $topic_type,
  153. 'TOPIC_IMG_STYLE' => $folder_img,
  154. 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
  155. 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', '') : '',
  156. 'S_USER_POSTED' => (!empty($row['topic_posted']) && $row['topic_posted']) ? true : false,
  157. 'S_UNREAD' => $unread_topic,
  158. 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  159. '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'],
  160. 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  161. 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;view=unread") . '#unread',
  162. 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id"),
  163. );
  164. /**
  165. * Add template variables to a front topics row.
  166. *
  167. * @event core.ucp_main_front_modify_template_vars
  168. * @var array topicrow Array containing the template variables for the row
  169. * @var array row Array containing the subscribed forum row data
  170. * @var int forum_id Forum ID
  171. * @var string folder_img Folder image
  172. * @var string folder_alt Alt text for the folder image
  173. * @since 3.2.4-RC1
  174. */
  175. $vars = array(
  176. 'topicrow',
  177. 'row',
  178. 'forum_id',
  179. 'folder_img',
  180. 'folder_alt',
  181. );
  182. extract($phpbb_dispatcher->trigger_event('core.ucp_main_front_modify_template_vars', compact($vars)));
  183. $template->assign_block_vars('topicrow', $topicrow);
  184. }
  185. if ($config['load_user_activity'])
  186. {
  187. if (!function_exists('display_user_activity'))
  188. {
  189. include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  190. }
  191. display_user_activity($user->data);
  192. }
  193. // Do the relevant calculations
  194. $memberdays = max(1, round((time() - $user->data['user_regdate']) / 86400));
  195. $posts_per_day = $user->data['user_posts'] / $memberdays;
  196. $percentage = ($config['num_posts']) ? min(100, ($user->data['user_posts'] / $config['num_posts']) * 100) : 0;
  197. $template->assign_vars(array(
  198. 'USER_COLOR' => (!empty($user->data['user_colour'])) ? $user->data['user_colour'] : '',
  199. 'JOINED' => $user->format_date($user->data['user_regdate']),
  200. 'LAST_ACTIVE' => (empty($last_active)) ? ' - ' : $user->format_date($last_active),
  201. 'WARNINGS' => ($user->data['user_warnings']) ? $user->data['user_warnings'] : 0,
  202. 'POSTS' => ($user->data['user_posts']) ? $user->data['user_posts'] : 0,
  203. 'POSTS_DAY' => $user->lang('POST_DAY', $posts_per_day),
  204. 'POSTS_PCT' => $user->lang('POST_PCT', $percentage),
  205. // 'S_GROUP_OPTIONS' => $group_options,
  206. 'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $user->data['user_id'] . '&amp;sr=posts') : '',
  207. ));
  208. break;
  209. case 'subscribed':
  210. if (!function_exists('topic_status'))
  211. {
  212. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  213. }
  214. $user->add_lang('viewforum');
  215. add_form_key('ucp_front_subscribed');
  216. $unwatch = (isset($_POST['unwatch'])) ? true : false;
  217. /**
  218. * Read and potentially modify the post data used to remove subscriptions to forums/topics
  219. *
  220. * @event core.ucp_main_subscribed_post_data
  221. * @since 3.1.10-RC1
  222. */
  223. $phpbb_dispatcher->dispatch('core.ucp_main_subscribed_post_data');
  224. if ($unwatch)
  225. {
  226. if (check_form_key('ucp_front_subscribed'))
  227. {
  228. $forums = array_keys($request->variable('f', array(0 => 0)));
  229. $topics = array_keys($request->variable('t', array(0 => 0)));
  230. if (count($forums) || count($topics))
  231. {
  232. $l_unwatch = '';
  233. if (count($forums))
  234. {
  235. $sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . '
  236. WHERE ' . $db->sql_in_set('forum_id', $forums) . '
  237. AND user_id = ' . $user->data['user_id'];
  238. $db->sql_query($sql);
  239. $l_unwatch .= '_FORUMS';
  240. }
  241. if (count($topics))
  242. {
  243. $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . '
  244. WHERE ' . $db->sql_in_set('topic_id', $topics) . '
  245. AND user_id = ' . $user->data['user_id'];
  246. $db->sql_query($sql);
  247. $l_unwatch .= '_TOPICS';
  248. }
  249. $msg = $user->lang['UNWATCHED' . $l_unwatch];
  250. }
  251. else
  252. {
  253. $msg = $user->lang['NO_WATCHED_SELECTED'];
  254. }
  255. }
  256. else
  257. {
  258. $msg = $user->lang['FORM_INVALID'];
  259. }
  260. $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=subscribed") . '">', '</a>');
  261. meta_refresh(3, append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=subscribed"));
  262. trigger_error($message);
  263. }
  264. $forbidden_forums = array();
  265. if ($config['allow_forum_notify'])
  266. {
  267. $forbidden_forums = $auth->acl_getf('!f_read', true);
  268. $forbidden_forums = array_unique(array_keys($forbidden_forums));
  269. $sql_array = array(
  270. 'SELECT' => 'f.*',
  271. 'FROM' => array(
  272. FORUMS_WATCH_TABLE => 'fw',
  273. FORUMS_TABLE => 'f'
  274. ),
  275. 'WHERE' => 'fw.user_id = ' . $user->data['user_id'] . '
  276. AND f.forum_id = fw.forum_id
  277. AND ' . $db->sql_in_set('f.forum_id', $forbidden_forums, true, true),
  278. 'ORDER_BY' => 'left_id'
  279. );
  280. if ($config['load_db_lastread'])
  281. {
  282. $sql_array['LEFT_JOIN'] = array(
  283. array(
  284. 'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
  285. 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'
  286. )
  287. );
  288. $sql_array['SELECT'] .= ', ft.mark_time ';
  289. }
  290. else
  291. {
  292. $tracking_topics = $request->variable($config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE);
  293. $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
  294. }
  295. /**
  296. * Modify the query used to retrieve a list of subscribed forums
  297. *
  298. * @event core.ucp_main_subscribed_forums_modify_query
  299. * @var array sql_array The subscribed forums query
  300. * @var array forbidden_forums The list of forbidden forums
  301. * @since 3.1.10-RC1
  302. */
  303. $vars = array(
  304. 'sql_array',
  305. 'forbidden_forums',
  306. );
  307. extract($phpbb_dispatcher->trigger_event('core.ucp_main_subscribed_forums_modify_query', compact($vars)));
  308. $sql = $db->sql_build_query('SELECT', $sql_array);
  309. $result = $db->sql_query($sql);
  310. while ($row = $db->sql_fetchrow($result))
  311. {
  312. $forum_id = $row['forum_id'];
  313. if ($config['load_db_lastread'])
  314. {
  315. $forum_check = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
  316. }
  317. else
  318. {
  319. $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'];
  320. }
  321. $unread_forum = ($row['forum_last_post_time'] > $forum_check) ? true : false;
  322. // Which folder should we display?
  323. if ($row['forum_status'] == ITEM_LOCKED)
  324. {
  325. $folder_image = ($unread_forum) ? 'forum_unread_locked' : 'forum_read_locked';
  326. $folder_alt = 'FORUM_LOCKED';
  327. }
  328. else
  329. {
  330. $folder_image = ($unread_forum) ? 'forum_unread' : 'forum_read';
  331. $folder_alt = ($unread_forum) ? 'UNREAD_POSTS' : 'NO_UNREAD_POSTS';
  332. }
  333. // Create last post link information, if appropriate
  334. if ($row['forum_last_post_id'])
  335. {
  336. $last_post_time = $user->format_date($row['forum_last_post_time']);
  337. $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'];
  338. }
  339. else
  340. {
  341. $last_post_time = $last_post_url = '';
  342. }
  343. $template_vars = array(
  344. 'FORUM_ID' => $forum_id,
  345. 'FORUM_IMG_STYLE' => $folder_image,
  346. 'FORUM_FOLDER_IMG' => $user->img($folder_image, $folder_alt),
  347. 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
  348. 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
  349. 'FORUM_NAME' => $row['forum_name'],
  350. 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
  351. 'LAST_POST_SUBJECT' => $row['forum_last_post_subject'],
  352. 'LAST_POST_TIME' => $last_post_time,
  353. 'LAST_POST_AUTHOR' => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  354. 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  355. 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  356. 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  357. 'S_UNREAD_FORUM' => $unread_forum,
  358. 'U_LAST_POST' => $last_post_url,
  359. 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id'])
  360. );
  361. /**
  362. * Add template variables to a subscribed forum row.
  363. *
  364. * @event core.ucp_main_subscribed_forum_modify_template_vars
  365. * @var array template_vars Array containing the template variables for the row
  366. * @var array row Array containing the subscribed forum row data
  367. * @var int forum_id Forum ID
  368. * @var string folder_image Folder image
  369. * @var string folder_alt Alt text for the folder image
  370. * @var bool unread_forum Whether the forum has unread content or not
  371. * @var string last_post_time The time of the most recent post, expressed as a formatted date string
  372. * @var string last_post_url The URL of the most recent post in the forum
  373. * @since 3.1.10-RC1
  374. */
  375. $vars = array(
  376. 'template_vars',
  377. 'row',
  378. 'forum_id',
  379. 'folder_image',
  380. 'folder_alt',
  381. 'unread_forum',
  382. 'last_post_time',
  383. 'last_post_url',
  384. );
  385. extract($phpbb_dispatcher->trigger_event('core.ucp_main_subscribed_forum_modify_template_vars', compact($vars)));
  386. $template->assign_block_vars('forumrow', $template_vars);
  387. }
  388. $db->sql_freeresult($result);
  389. }
  390. // Subscribed Topics
  391. if ($config['allow_topic_notify'])
  392. {
  393. if (empty($forbidden_forums))
  394. {
  395. $forbidden_forums = $auth->acl_getf('!f_read', true);
  396. $forbidden_forums = array_unique(array_keys($forbidden_forums));
  397. }
  398. $this->assign_topiclist('subscribed', $forbidden_forums);
  399. }
  400. $template->assign_vars(array(
  401. 'S_TOPIC_NOTIFY' => $config['allow_topic_notify'],
  402. 'S_FORUM_NOTIFY' => $config['allow_forum_notify'],
  403. ));
  404. break;
  405. case 'bookmarks':
  406. if (!$config['allow_bookmarks'])
  407. {
  408. $template->assign_vars(array(
  409. 'S_NO_DISPLAY_BOOKMARKS' => true)
  410. );
  411. break;
  412. }
  413. if (!function_exists('topic_status'))
  414. {
  415. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  416. }
  417. $user->add_lang('viewforum');
  418. if (isset($_POST['unbookmark']))
  419. {
  420. $s_hidden_fields = array('unbookmark' => 1);
  421. $topics = (isset($_POST['t'])) ? array_keys($request->variable('t', array(0 => 0))) : array();
  422. $url = $this->u_action;
  423. if (!count($topics))
  424. {
  425. trigger_error('NO_BOOKMARKS_SELECTED');
  426. }
  427. foreach ($topics as $topic_id)
  428. {
  429. $s_hidden_fields['t'][$topic_id] = 1;
  430. }
  431. if (confirm_box(true))
  432. {
  433. $sql = 'DELETE FROM ' . BOOKMARKS_TABLE . '
  434. WHERE user_id = ' . $user->data['user_id'] . '
  435. AND ' . $db->sql_in_set('topic_id', $topics);
  436. $db->sql_query($sql);
  437. meta_refresh(3, $url);
  438. $message = $user->lang['BOOKMARKS_REMOVED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $url . '">', '</a>');
  439. trigger_error($message);
  440. }
  441. else
  442. {
  443. confirm_box(false, 'REMOVE_SELECTED_BOOKMARKS', build_hidden_fields($s_hidden_fields));
  444. }
  445. }
  446. $forbidden_forums = $auth->acl_getf('!f_read', true);
  447. $forbidden_forums = array_unique(array_keys($forbidden_forums));
  448. $this->assign_topiclist('bookmarks', $forbidden_forums);
  449. break;
  450. case 'drafts':
  451. $pm_drafts = ($this->p_master->p_name == 'pm') ? true : false;
  452. $template->assign_var('S_SHOW_DRAFTS', true);
  453. $user->add_lang('posting');
  454. $edit = (isset($_REQUEST['edit'])) ? true : false;
  455. $submit = (isset($_POST['submit'])) ? true : false;
  456. $draft_id = $request->variable('edit', 0);
  457. $delete = (isset($_POST['delete'])) ? true : false;
  458. $s_hidden_fields = ($edit) ? '<input type="hidden" name="edit" value="' . $draft_id . '" />' : '';
  459. $draft_subject = $draft_message = '';
  460. add_form_key('ucp_draft');
  461. include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);
  462. $message_parser = new parse_message();
  463. if ($delete)
  464. {
  465. if (check_form_key('ucp_draft'))
  466. {
  467. $drafts = array_keys($request->variable('d', array(0 => 0)));
  468. if (count($drafts))
  469. {
  470. $sql = 'DELETE FROM ' . DRAFTS_TABLE . '
  471. WHERE ' . $db->sql_in_set('draft_id', $drafts) . '
  472. AND user_id = ' . $user->data['user_id'];
  473. $db->sql_query($sql);
  474. }
  475. $msg = $user->lang['DRAFTS_DELETED'];
  476. unset($drafts);
  477. }
  478. else
  479. {
  480. $msg = $user->lang['FORM_INVALID'];
  481. }
  482. $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
  483. meta_refresh(3, $this->u_action);
  484. trigger_error($message);
  485. }
  486. if ($submit && $edit)
  487. {
  488. $draft_subject = $request->variable('subject', '', true);
  489. $draft_message = $request->variable('message', '', true);
  490. if (check_form_key('ucp_draft'))
  491. {
  492. if ($draft_message && $draft_subject)
  493. {
  494. // $auth->acl_gets can't be used here because it will check for global forum permissions in this case
  495. // In general we don't need too harsh checking here for permissions, as this will be handled later when submitting
  496. $bbcode_status = $auth->acl_get('u_pm_bbcode') || $auth->acl_getf_global('f_bbcode');
  497. $smilies_status = $auth->acl_get('u_pm_smilies') || $auth->acl_getf_global('f_smilies');
  498. $img_status = $auth->acl_get('u_pm_img') || $auth->acl_getf_global('f_img');
  499. $flash_status = $auth->acl_get('u_pm_flash') || $auth->acl_getf_global('f_flash');
  500. $message_parser->message = $draft_message;
  501. $message_parser->parse($bbcode_status, $config['allow_post_links'], $smilies_status, $img_status, $flash_status, true, $config['allow_post_links']);
  502. $draft_row = array(
  503. 'draft_subject' => $draft_subject,
  504. 'draft_message' => $message_parser->message,
  505. );
  506. $sql = 'UPDATE ' . DRAFTS_TABLE . '
  507. SET ' . $db->sql_build_array('UPDATE', $draft_row) . "
  508. WHERE draft_id = $draft_id
  509. AND user_id = " . $user->data['user_id'];
  510. $db->sql_query($sql);
  511. $message = $user->lang['DRAFT_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
  512. meta_refresh(3, $this->u_action);
  513. trigger_error($message);
  514. }
  515. else
  516. {
  517. $template->assign_var('ERROR', ($draft_message == '') ? $user->lang['EMPTY_DRAFT'] : (($draft_subject == '') ? $user->lang['EMPTY_DRAFT_TITLE'] : ''));
  518. }
  519. }
  520. else
  521. {
  522. $template->assign_var('ERROR', $user->lang['FORM_INVALID']);
  523. }
  524. }
  525. if (!$pm_drafts)
  526. {
  527. $sql = 'SELECT d.*, f.forum_name
  528. FROM ' . DRAFTS_TABLE . ' d, ' . FORUMS_TABLE . ' f
  529. WHERE d.user_id = ' . $user->data['user_id'] . ' ' .
  530. (($edit) ? "AND d.draft_id = $draft_id" : '') . '
  531. AND f.forum_id = d.forum_id
  532. ORDER BY d.save_time DESC';
  533. }
  534. else
  535. {
  536. $sql = 'SELECT * FROM ' . DRAFTS_TABLE . '
  537. WHERE user_id = ' . $user->data['user_id'] . ' ' .
  538. (($edit) ? "AND draft_id = $draft_id" : '') . '
  539. AND forum_id = 0
  540. AND topic_id = 0
  541. ORDER BY save_time DESC';
  542. }
  543. $result = $db->sql_query($sql);
  544. $draftrows = $topic_ids = array();
  545. while ($row = $db->sql_fetchrow($result))
  546. {
  547. if ($row['topic_id'])
  548. {
  549. $topic_ids[] = (int) $row['topic_id'];
  550. }
  551. $draftrows[] = $row;
  552. }
  553. $db->sql_freeresult($result);
  554. if (count($topic_ids))
  555. {
  556. $sql = 'SELECT topic_id, forum_id, topic_title
  557. FROM ' . TOPICS_TABLE . '
  558. WHERE ' . $db->sql_in_set('topic_id', array_unique($topic_ids));
  559. $result = $db->sql_query($sql);
  560. while ($row = $db->sql_fetchrow($result))
  561. {
  562. $topic_rows[$row['topic_id']] = $row;
  563. }
  564. $db->sql_freeresult($result);
  565. }
  566. unset($topic_ids);
  567. $template->assign_var('S_EDIT_DRAFT', $edit);
  568. $row_count = 0;
  569. foreach ($draftrows as $draft)
  570. {
  571. $link_topic = $link_forum = $link_pm = false;
  572. $insert_url = $view_url = $title = '';
  573. if (isset($topic_rows[$draft['topic_id']]) && $auth->acl_get('f_read', $topic_rows[$draft['topic_id']]['forum_id']))
  574. {
  575. $link_topic = true;
  576. $view_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_rows[$draft['topic_id']]['forum_id'] . '&amp;t=' . $draft['topic_id']);
  577. $title = $topic_rows[$draft['topic_id']]['topic_title'];
  578. $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']);
  579. }
  580. else if ($auth->acl_get('f_read', $draft['forum_id']))
  581. {
  582. $link_forum = true;
  583. $view_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $draft['forum_id']);
  584. $title = $draft['forum_name'];
  585. $insert_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $draft['forum_id'] . '&amp;mode=post&amp;d=' . $draft['draft_id']);
  586. }
  587. else if ($pm_drafts)
  588. {
  589. $link_pm = true;
  590. $insert_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=compose&amp;d=" . $draft['draft_id']);
  591. }
  592. if (!$submit)
  593. {
  594. $message_parser->message = $draft['draft_message'];
  595. $message_parser->decode_message();
  596. $draft_message = $message_parser->message;
  597. }
  598. $template_row = array(
  599. 'DATE' => $user->format_date($draft['save_time']),
  600. 'DRAFT_MESSAGE' => $draft_message,
  601. 'DRAFT_SUBJECT' => ($submit) ? $draft_subject : $draft['draft_subject'],
  602. 'TITLE' => $title,
  603. 'DRAFT_ID' => $draft['draft_id'],
  604. 'FORUM_ID' => $draft['forum_id'],
  605. 'TOPIC_ID' => $draft['topic_id'],
  606. 'U_VIEW' => $view_url,
  607. 'U_VIEW_EDIT' => $this->u_action . '&amp;edit=' . $draft['draft_id'],
  608. 'U_INSERT' => $insert_url,
  609. 'S_LINK_TOPIC' => $link_topic,
  610. 'S_LINK_FORUM' => $link_forum,
  611. 'S_LINK_PM' => $link_pm,
  612. 'S_HIDDEN_FIELDS' => $s_hidden_fields
  613. );
  614. $row_count++;
  615. ($edit) ? $template->assign_vars($template_row) : $template->assign_block_vars('draftrow', $template_row);
  616. }
  617. if (!$edit)
  618. {
  619. $template->assign_var('S_DRAFT_ROWS', $row_count);
  620. }
  621. break;
  622. }
  623. $template->assign_vars(array(
  624. 'L_TITLE' => $user->lang['UCP_MAIN_' . strtoupper($mode)],
  625. 'S_DISPLAY_MARK_ALL' => ($mode == 'watched' || ($mode == 'drafts' && !isset($_GET['edit']))) ? true : false,
  626. 'S_HIDDEN_FIELDS' => (isset($s_hidden_fields)) ? $s_hidden_fields : '',
  627. 'S_UCP_ACTION' => $this->u_action,
  628. 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
  629. 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
  630. ));
  631. // Set desired template
  632. $this->tpl_name = 'ucp_main_' . $mode;
  633. $this->page_title = 'UCP_MAIN_' . strtoupper($mode);
  634. }
  635. /**
  636. * Build and assign topiclist for bookmarks/subscribed topics
  637. */
  638. function assign_topiclist($mode = 'subscribed', $forbidden_forum_ary = array())
  639. {
  640. global $user, $db, $template, $config, $cache, $auth, $phpbb_root_path, $phpEx, $phpbb_container, $request, $phpbb_dispatcher;
  641. /* @var $pagination \phpbb\pagination */
  642. $pagination = $phpbb_container->get('pagination');
  643. $table = ($mode == 'subscribed') ? TOPICS_WATCH_TABLE : BOOKMARKS_TABLE;
  644. $start = $request->variable('start', 0);
  645. // Grab icons
  646. $icons = $cache->obtain_icons();
  647. $sql_array = array(
  648. 'SELECT' => 'COUNT(t.topic_id) as topics_count',
  649. 'FROM' => array(
  650. $table => 'i',
  651. TOPICS_TABLE => 't'
  652. ),
  653. 'WHERE' => 'i.topic_id = t.topic_id
  654. AND i.user_id = ' . $user->data['user_id'] . '
  655. AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true),
  656. );
  657. /**
  658. * Modify the query used to retrieve the count of subscribed/bookmarked topics
  659. *
  660. * @event core.ucp_main_topiclist_count_modify_query
  661. * @var array sql_array The subscribed/bookmarked topics query
  662. * @var array forbidden_forum_ary The list of forbidden forums
  663. * @var string mode The type of topic list ('subscribed' or 'bookmarks')
  664. * @since 3.1.10-RC1
  665. */
  666. $vars = array(
  667. 'sql_array',
  668. 'forbidden_forum_ary',
  669. 'mode',
  670. );
  671. extract($phpbb_dispatcher->trigger_event('core.ucp_main_topiclist_count_modify_query', compact($vars)));
  672. $sql = $db->sql_build_query('SELECT', $sql_array);
  673. $result = $db->sql_query($sql);
  674. $topics_count = (int) $db->sql_fetchfield('topics_count');
  675. $db->sql_freeresult($result);
  676. if ($topics_count)
  677. {
  678. $start = $pagination->validate_start($start, $config['topics_per_page'], $topics_count);
  679. $pagination->generate_template_pagination($this->u_action, 'pagination', 'start', $topics_count, $config['topics_per_page'], $start);
  680. $template->assign_vars(array(
  681. 'TOTAL_TOPICS' => $user->lang('VIEW_FORUM_TOPICS', (int) $topics_count),
  682. ));
  683. }
  684. if ($mode == 'subscribed')
  685. {
  686. $sql_array = array(
  687. 'SELECT' => 't.*, f.forum_name',
  688. 'FROM' => array(
  689. TOPICS_WATCH_TABLE => 'tw',
  690. TOPICS_TABLE => 't'
  691. ),
  692. 'WHERE' => 'tw.user_id = ' . $user->data['user_id'] . '
  693. AND t.topic_id = tw.topic_id
  694. AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true),
  695. 'ORDER_BY' => 't.topic_last_post_time DESC, t.topic_last_post_id DESC'
  696. );
  697. $sql_array['LEFT_JOIN'] = array();
  698. }
  699. else
  700. {
  701. $sql_array = array(
  702. 'SELECT' => 't.*, f.forum_name, b.topic_id as b_topic_id',
  703. 'FROM' => array(
  704. BOOKMARKS_TABLE => 'b',
  705. ),
  706. 'WHERE' => 'b.user_id = ' . $user->data['user_id'] . '
  707. AND ' . $db->sql_in_set('f.forum_id', $forbidden_forum_ary, true, true),
  708. 'ORDER_BY' => 't.topic_last_post_time DESC, t.topic_last_post_id DESC'
  709. );
  710. $sql_array['LEFT_JOIN'] = array();
  711. $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TABLE => 't'), 'ON' => 'b.topic_id = t.topic_id');
  712. }
  713. $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 't.forum_id = f.forum_id');
  714. if ($config['load_db_lastread'])
  715. {
  716. $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']);
  717. $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']);
  718. $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time AS forum_mark_time';
  719. }
  720. if ($config['load_db_track'])
  721. {
  722. $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']);
  723. $sql_array['SELECT'] .= ', tp.topic_posted';
  724. }
  725. /**
  726. * Modify the query used to retrieve the list of subscribed/bookmarked topics
  727. *
  728. * @event core.ucp_main_topiclist_modify_query
  729. * @var array sql_array The subscribed/bookmarked topics query
  730. * @var array forbidden_forum_ary The list of forbidden forums
  731. * @var string mode The type of topic list ('subscribed' or 'bookmarks')
  732. * @since 3.1.10-RC1
  733. */
  734. $vars = array(
  735. 'sql_array',
  736. 'forbidden_forum_ary',
  737. 'mode',
  738. );
  739. extract($phpbb_dispatcher->trigger_event('core.ucp_main_topiclist_modify_query', compact($vars)));
  740. $sql = $db->sql_build_query('SELECT', $sql_array);
  741. $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
  742. $topic_list = $topic_forum_list = $global_announce_list = $rowset = array();
  743. while ($row = $db->sql_fetchrow($result))
  744. {
  745. $topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
  746. $topic_list[] = $topic_id;
  747. $rowset[$topic_id] = $row;
  748. $topic_forum_list[$row['forum_id']]['forum_mark_time'] = ($config['load_db_lastread']) ? $row['forum_mark_time'] : 0;
  749. $topic_forum_list[$row['forum_id']]['topics'][] = $topic_id;
  750. if ($row['topic_type'] == POST_GLOBAL)
  751. {
  752. $global_announce_list[] = $topic_id;
  753. }
  754. }
  755. $db->sql_freeresult($result);
  756. $topic_tracking_info = array();
  757. if ($config['load_db_lastread'])
  758. {
  759. foreach ($topic_forum_list as $f_id => $topic_row)
  760. {
  761. $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']));
  762. }
  763. }
  764. else
  765. {
  766. foreach ($topic_forum_list as $f_id => $topic_row)
  767. {
  768. $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics']);
  769. }
  770. }
  771. /* @var $phpbb_content_visibility \phpbb\content_visibility */
  772. $phpbb_content_visibility = $phpbb_container->get('content.visibility');
  773. foreach ($topic_list as $topic_id)
  774. {
  775. $row = &$rowset[$topic_id];
  776. $forum_id = $row['forum_id'];
  777. $topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
  778. $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
  779. // Replies
  780. $replies = $phpbb_content_visibility->get_count('topic_posts', $row, $forum_id) - 1;
  781. if ($row['topic_status'] == ITEM_MOVED && !empty($row['topic_moved_id']))
  782. {
  783. $topic_id = $row['topic_moved_id'];
  784. }
  785. // Get folder img, topic status/type related information
  786. $folder_img = $folder_alt = $topic_type = '';
  787. topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
  788. $view_topic_url_params = "f=$forum_id&amp;t=$topic_id";
  789. $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params);
  790. // Send vars to template
  791. $template_vars = array(
  792. 'FORUM_ID' => $forum_id,
  793. 'TOPIC_ID' => $topic_id,
  794. 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
  795. 'LAST_POST_SUBJECT' => $row['topic_last_post_subject'],
  796. 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
  797. 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
  798. 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  799. 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  800. 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  801. 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  802. 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  803. 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  804. 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  805. 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  806. 'S_DELETED_TOPIC' => (!$row['topic_id']) ? true : false,
  807. 'REPLIES' => $replies,
  808. 'VIEWS' => $row['topic_views'],
  809. 'TOPIC_TITLE' => censor_text($row['topic_title']),
  810. 'TOPIC_TYPE' => $topic_type,
  811. 'FORUM_NAME' => $row['forum_name'],
  812. 'TOPIC_IMG_STYLE' => $folder_img,
  813. 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
  814. 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt],
  815. 'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
  816. 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
  817. 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
  818. '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']) : '',
  819. 'S_TOPIC_TYPE' => $row['topic_type'],
  820. 'S_USER_POSTED' => (!empty($row['topic_posted'])) ? true : false,
  821. 'S_UNREAD_TOPIC' => $unread_topic,
  822. 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;view=unread') . '#unread',
  823. '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'],
  824. 'U_VIEW_TOPIC' => $view_topic_url,
  825. 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
  826. );
  827. /**
  828. * Add template variables to a subscribed/bookmarked topic row.
  829. *
  830. * @event core.ucp_main_topiclist_topic_modify_template_vars
  831. * @var array template_vars Array containing the template variables for the row
  832. * @var array row Array containing the subscribed/bookmarked topic row data
  833. * @var int forum_id ID of the forum containing the topic
  834. * @var int topic_id Topic ID
  835. * @var int replies Number of replies in the topic
  836. * @var string topic_type Topic type
  837. * @var string folder_img Folder image
  838. * @var string folder_alt Alt text for the folder image
  839. * @var array icons Array containing topic icons
  840. * @var bool unread_topic Whether the topic has unread content or not
  841. * @var string view_topic_url The URL of the topic
  842. * @since 3.1.10-RC1
  843. */
  844. $vars = array(
  845. 'template_vars',
  846. 'row',
  847. 'forum_id',
  848. 'topic_id',
  849. 'replies',
  850. 'topic_type',
  851. 'folder_img',
  852. 'folder_alt',
  853. 'icons',
  854. 'unread_topic',
  855. 'view_topic_url',
  856. );
  857. extract($phpbb_dispatcher->trigger_event('core.ucp_main_topiclist_topic_modify_template_vars', compact($vars)));
  858. $template->assign_block_vars('topicrow', $template_vars);
  859. $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);
  860. }
  861. }
  862. }