PageRenderTime 61ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/forum/includes/ucp/ucp_main.php

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