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

/includes/ucp/ucp_main.php

http://seo-phpbb.googlecode.com/
PHP | 826 lines | 644 code | 150 blank | 32 comment | 83 complexity | 07253939cda7b9692d976ff6ab38598c MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package ucp
  5. * @version $Id: ucp_main.php 8479 2008-03-29 00:22:48Z naderman $
  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. }
  198. else
  199. {
  200. $msg = $user->lang['FORM_INVALID'];
  201. }
  202. $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=subscribed") . '">', '</a>');
  203. meta_refresh(3, append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=subscribed"));
  204. trigger_error($message);
  205. }
  206. $forbidden_forums = array();
  207. if ($config['allow_forum_notify'])
  208. {
  209. $forbidden_forums = $auth->acl_getf('!f_read', true);
  210. $forbidden_forums = array_unique(array_keys($forbidden_forums));
  211. $sql_array = array(
  212. 'SELECT' => 'f.*',
  213. 'FROM' => array(
  214. FORUMS_WATCH_TABLE => 'fw',
  215. FORUMS_TABLE => 'f'
  216. ),
  217. 'WHERE' => 'fw.user_id = ' . $user->data['user_id'] . '
  218. AND f.forum_id = fw.forum_id
  219. AND ' . $db->sql_in_set('f.forum_id', $forbidden_forums, true, true),
  220. 'ORDER_BY' => 'left_id'
  221. );
  222. if ($config['load_db_lastread'])
  223. {
  224. $sql_array['LEFT_JOIN'] = array(
  225. array(
  226. 'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
  227. 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'
  228. )
  229. );
  230. $sql_array['SELECT'] .= ', ft.mark_time ';
  231. }
  232. else
  233. {
  234. $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : '';
  235. $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
  236. }
  237. $sql = $db->sql_build_query('SELECT', $sql_array);
  238. $result = $db->sql_query($sql);
  239. while ($row = $db->sql_fetchrow($result))
  240. {
  241. $forum_id = $row['forum_id'];
  242. if ($config['load_db_lastread'])
  243. {
  244. $forum_check = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
  245. }
  246. else
  247. {
  248. $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'];
  249. }
  250. $unread_forum = ($row['forum_last_post_time'] > $forum_check) ? true : false;
  251. // Which folder should we display?
  252. if ($row['forum_status'] == ITEM_LOCKED)
  253. {
  254. $folder_image = ($unread_forum) ? 'forum_unread_locked' : 'forum_read_locked';
  255. $folder_alt = 'FORUM_LOCKED';
  256. }
  257. else
  258. {
  259. $folder_image = ($unread_forum) ? 'forum_unread' : 'forum_read';
  260. $folder_alt = ($unread_forum) ? 'NEW_POSTS' : 'NO_NEW_POSTS';
  261. }
  262. // Create last post link information, if appropriate
  263. if ($row['forum_last_post_id'])
  264. {
  265. $last_post_time = $user->format_date($row['forum_last_post_time']);
  266. $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'];
  267. }
  268. else
  269. {
  270. $last_post_time = $last_post_url = '';
  271. }
  272. $template->assign_block_vars('forumrow', array(
  273. 'FORUM_ID' => $forum_id,
  274. 'FORUM_FOLDER_IMG' => $user->img($folder_image, $folder_alt),
  275. 'FORUM_FOLDER_IMG_SRC' => $user->img($folder_image, $folder_alt, false, '', 'src'),
  276. 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
  277. 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
  278. 'FORUM_NAME' => $row['forum_name'],
  279. 'LAST_POST_SUBJECT' => $row['forum_last_post_subject'],
  280. 'LAST_POST_TIME' => $last_post_time,
  281. 'LAST_POST_AUTHOR' => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  282. 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  283. 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  284. 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  285. 'U_LAST_POST' => $last_post_url,
  286. 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
  287. );
  288. }
  289. $db->sql_freeresult($result);
  290. }
  291. // Subscribed Topics
  292. if ($config['allow_topic_notify'])
  293. {
  294. if (empty($forbidden_forums))
  295. {
  296. $forbidden_forums = $auth->acl_getf('!f_read', true);
  297. $forbidden_forums = array_unique(array_keys($forbidden_forums));
  298. }
  299. $this->assign_topiclist('subscribed', $forbidden_forums);
  300. }
  301. $template->assign_vars(array(
  302. 'S_TOPIC_NOTIFY' => $config['allow_topic_notify'],
  303. 'S_FORUM_NOTIFY' => $config['allow_forum_notify'],
  304. ));
  305. break;
  306. case 'bookmarks':
  307. if (!$config['allow_bookmarks'])
  308. {
  309. $template->assign_vars(array(
  310. 'S_NO_DISPLAY_BOOKMARKS' => true)
  311. );
  312. break;
  313. }
  314. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  315. $user->add_lang('viewforum');
  316. if (isset($_POST['unbookmark']))
  317. {
  318. $s_hidden_fields = array('unbookmark' => 1);
  319. $topics = (isset($_POST['t'])) ? array_keys(request_var('t', array(0 => 0))) : array();
  320. $url = $this->u_action;
  321. if (!sizeof($topics))
  322. {
  323. trigger_error('NO_BOOKMARKS_SELECTED');
  324. }
  325. foreach ($topics as $topic_id)
  326. {
  327. $s_hidden_fields['t'][$topic_id] = 1;
  328. }
  329. if (confirm_box(true))
  330. {
  331. $sql = 'DELETE FROM ' . BOOKMARKS_TABLE . '
  332. WHERE user_id = ' . $user->data['user_id'] . '
  333. AND ' . $db->sql_in_set('topic_id', $topics);
  334. $db->sql_query($sql);
  335. meta_refresh(3, $url);
  336. $message = $user->lang['BOOKMARKS_REMOVED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $url . '">', '</a>');
  337. trigger_error($message);
  338. }
  339. else
  340. {
  341. confirm_box(false, 'REMOVE_SELECTED_BOOKMARKS', build_hidden_fields($s_hidden_fields));
  342. }
  343. }
  344. $forbidden_forums = $auth->acl_getf('!f_read', true);
  345. $forbidden_forums = array_unique(array_keys($forbidden_forums));
  346. $this->assign_topiclist('bookmarks', $forbidden_forums);
  347. break;
  348. case 'drafts':
  349. $pm_drafts = ($this->p_master->p_name == 'pm') ? true : false;
  350. $template->assign_var('S_SHOW_DRAFTS', true);
  351. $user->add_lang('posting');
  352. $edit = (isset($_REQUEST['edit'])) ? true : false;
  353. $submit = (isset($_POST['submit'])) ? true : false;
  354. $draft_id = ($edit) ? intval($_REQUEST['edit']) : 0;
  355. $delete = (isset($_POST['delete'])) ? true : false;
  356. $s_hidden_fields = ($edit) ? '<input type="hidden" name="edit" value="' . $draft_id . '" />' : '';
  357. $draft_subject = $draft_message = '';
  358. add_form_key('ucp_draft');
  359. if ($delete)
  360. {
  361. if (check_form_key('ucp_draft'))
  362. {
  363. $drafts = array_keys(request_var('d', array(0 => 0)));
  364. if (sizeof($drafts))
  365. {
  366. $sql = 'DELETE FROM ' . DRAFTS_TABLE . '
  367. WHERE ' . $db->sql_in_set('draft_id', $drafts) . '
  368. AND user_id = ' . $user->data['user_id'];
  369. $db->sql_query($sql);
  370. }
  371. $msg = $user->lang['DRAFTS_DELETED'];
  372. unset($drafts);
  373. }
  374. else
  375. {
  376. $msg = $user->lang['FORM_INVALID'];
  377. }
  378. $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
  379. meta_refresh(3, $this->u_action);
  380. trigger_error($message);
  381. }
  382. if ($submit && $edit)
  383. {
  384. $draft_subject = utf8_normalize_nfc(request_var('subject', '', true));
  385. $draft_message = utf8_normalize_nfc(request_var('message', '', true));
  386. if (check_form_key('ucp_draft'))
  387. {
  388. if ($draft_message && $draft_subject)
  389. {
  390. $draft_row = array(
  391. 'draft_subject' => $draft_subject,
  392. 'draft_message' => $draft_message
  393. );
  394. $sql = 'UPDATE ' . DRAFTS_TABLE . '
  395. SET ' . $db->sql_build_array('UPDATE', $draft_row) . "
  396. WHERE draft_id = $draft_id
  397. AND user_id = " . $user->data['user_id'];
  398. $db->sql_query($sql);
  399. $message = $user->lang['DRAFT_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
  400. meta_refresh(3, $this->u_action);
  401. trigger_error($message);
  402. }
  403. else
  404. {
  405. $template->assign_var('ERROR', ($draft_message == '') ? $user->lang['EMPTY_DRAFT'] : (($draft_subject == '') ? $user->lang['EMPTY_DRAFT_TITLE'] : ''));
  406. }
  407. }
  408. else
  409. {
  410. $template->assign_var('ERROR', $user->lang['FORM_INVALID']);
  411. }
  412. }
  413. if (!$pm_drafts)
  414. {
  415. $sql = 'SELECT d.*, f.forum_name
  416. FROM ' . DRAFTS_TABLE . ' d, ' . FORUMS_TABLE . ' f
  417. WHERE d.user_id = ' . $user->data['user_id'] . ' ' .
  418. (($edit) ? "AND d.draft_id = $draft_id" : '') . '
  419. AND f.forum_id = d.forum_id
  420. ORDER BY d.save_time DESC';
  421. }
  422. else
  423. {
  424. $sql = 'SELECT * FROM ' . DRAFTS_TABLE . '
  425. WHERE user_id = ' . $user->data['user_id'] . ' ' .
  426. (($edit) ? "AND draft_id = $draft_id" : '') . '
  427. AND forum_id = 0
  428. AND topic_id = 0
  429. ORDER BY save_time DESC';
  430. }
  431. $result = $db->sql_query($sql);
  432. $draftrows = $topic_ids = array();
  433. while ($row = $db->sql_fetchrow($result))
  434. {
  435. if ($row['topic_id'])
  436. {
  437. $topic_ids[] = (int) $row['topic_id'];
  438. }
  439. $draftrows[] = $row;
  440. }
  441. $db->sql_freeresult($result);
  442. if (sizeof($topic_ids))
  443. {
  444. $sql = 'SELECT topic_id, forum_id, topic_title
  445. FROM ' . TOPICS_TABLE . '
  446. WHERE ' . $db->sql_in_set('topic_id', array_unique($topic_ids));
  447. $result = $db->sql_query($sql);
  448. while ($row = $db->sql_fetchrow($result))
  449. {
  450. $topic_rows[$row['topic_id']] = $row;
  451. }
  452. $db->sql_freeresult($result);
  453. }
  454. unset($topic_ids);
  455. $template->assign_var('S_EDIT_DRAFT', $edit);
  456. $row_count = 0;
  457. foreach ($draftrows as $draft)
  458. {
  459. $link_topic = $link_forum = $link_pm = false;
  460. $insert_url = $view_url = $title = '';
  461. if (isset($topic_rows[$draft['topic_id']]) && $auth->acl_get('f_read', $topic_rows[$draft['topic_id']]['forum_id']))
  462. {
  463. $link_topic = true;
  464. $view_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_rows[$draft['topic_id']]['forum_id'] . '&amp;t=' . $draft['topic_id']);
  465. $title = $topic_rows[$draft['topic_id']]['topic_title'];
  466. $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']);
  467. }
  468. else if ($auth->acl_get('f_read', $draft['forum_id']))
  469. {
  470. $link_forum = true;
  471. $view_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $draft['forum_id']);
  472. $title = $draft['forum_name'];
  473. $insert_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $draft['forum_id'] . '&amp;mode=post&amp;d=' . $draft['draft_id']);
  474. }
  475. else if ($pm_drafts)
  476. {
  477. $link_pm = true;
  478. $insert_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=compose&amp;d=" . $draft['draft_id']);
  479. }
  480. $template_row = array(
  481. 'DATE' => $user->format_date($draft['save_time']),
  482. 'DRAFT_MESSAGE' => ($submit) ? $draft_message : $draft['draft_message'],
  483. 'DRAFT_SUBJECT' => ($submit) ? $draft_subject : $draft['draft_subject'],
  484. 'TITLE' => $title,
  485. 'DRAFT_ID' => $draft['draft_id'],
  486. 'FORUM_ID' => $draft['forum_id'],
  487. 'TOPIC_ID' => $draft['topic_id'],
  488. 'U_VIEW' => $view_url,
  489. 'U_VIEW_EDIT' => $this->u_action . '&amp;edit=' . $draft['draft_id'],
  490. 'U_INSERT' => $insert_url,
  491. 'S_LINK_TOPIC' => $link_topic,
  492. 'S_LINK_FORUM' => $link_forum,
  493. 'S_LINK_PM' => $link_pm,
  494. 'S_HIDDEN_FIELDS' => $s_hidden_fields
  495. );
  496. $row_count++;
  497. ($edit) ? $template->assign_vars($template_row) : $template->assign_block_vars('draftrow', $template_row);
  498. }
  499. if (!$edit)
  500. {
  501. $template->assign_var('S_DRAFT_ROWS', $row_count);
  502. }
  503. break;
  504. }
  505. $template->assign_vars(array(
  506. 'L_TITLE' => $user->lang['UCP_MAIN_' . strtoupper($mode)],
  507. 'S_DISPLAY_MARK_ALL' => ($mode == 'watched' || ($mode == 'drafts' && !isset($_GET['edit']))) ? true : false,
  508. 'S_HIDDEN_FIELDS' => (isset($s_hidden_fields)) ? $s_hidden_fields : '',
  509. 'S_UCP_ACTION' => $this->u_action,
  510. 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
  511. 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
  512. ));
  513. // Set desired template
  514. $this->tpl_name = 'ucp_main_' . $mode;
  515. $this->page_title = 'UCP_MAIN_' . strtoupper($mode);
  516. }
  517. /**
  518. * Build and assign topiclist for bookmarks/subscribed topics
  519. */
  520. function assign_topiclist($mode = 'subscribed', $forbidden_forum_ary = array())
  521. {
  522. global $user, $db, $template, $config, $auth, $phpbb_root_path, $phpEx;
  523. $table = ($mode == 'subscribed') ? TOPICS_WATCH_TABLE : BOOKMARKS_TABLE;
  524. $start = request_var('start', 0);
  525. $sql_array = array(
  526. 'SELECT' => 'COUNT(t.topic_id) as topics_count',
  527. 'FROM' => array(
  528. $table => 'i',
  529. TOPICS_TABLE => 't'
  530. ),
  531. 'WHERE' => 'i.topic_id = t.topic_id
  532. AND i.user_id = ' . $user->data['user_id'] . '
  533. AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true),
  534. );
  535. $sql = $db->sql_build_query('SELECT', $sql_array);
  536. $result = $db->sql_query($sql);
  537. $topics_count = (int) $db->sql_fetchfield('topics_count');
  538. $db->sql_freeresult($result);
  539. if ($topics_count)
  540. {
  541. $template->assign_vars(array(
  542. 'PAGINATION' => generate_pagination($this->u_action, $topics_count, $config['topics_per_page'], $start),
  543. 'PAGE_NUMBER' => on_page($topics_count, $config['topics_per_page'], $start),
  544. 'TOTAL_TOPICS' => ($topics_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $topics_count))
  545. );
  546. }
  547. if ($mode == 'subscribed')
  548. {
  549. $sql_array = array(
  550. 'SELECT' => 't.*, f.forum_name',
  551. 'FROM' => array(
  552. TOPICS_WATCH_TABLE => 'tw',
  553. TOPICS_TABLE => 't'
  554. ),
  555. 'WHERE' => 'tw.user_id = ' . $user->data['user_id'] . '
  556. AND t.topic_id = tw.topic_id
  557. AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true),
  558. 'ORDER_BY' => 't.topic_last_post_time DESC'
  559. );
  560. $sql_array['LEFT_JOIN'] = array();
  561. }
  562. else
  563. {
  564. $sql_array = array(
  565. 'SELECT' => 't.*, f.forum_name, b.topic_id as b_topic_id',
  566. 'FROM' => array(
  567. BOOKMARKS_TABLE => 'b',
  568. ),
  569. 'WHERE' => 'b.user_id = ' . $user->data['user_id'] . '
  570. AND ' . $db->sql_in_set('f.forum_id', $forbidden_forum_ary, true, true),
  571. 'ORDER_BY' => 't.topic_last_post_time DESC'
  572. );
  573. $sql_array['LEFT_JOIN'] = array();
  574. $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TABLE => 't'), 'ON' => 'b.topic_id = t.topic_id');
  575. }
  576. $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 't.forum_id = f.forum_id');
  577. if ($config['load_db_lastread'])
  578. {
  579. $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']);
  580. $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']);
  581. $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time AS forum_mark_time';
  582. }
  583. if ($config['load_db_track'])
  584. {
  585. $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']);
  586. $sql_array['SELECT'] .= ', tp.topic_posted';
  587. }
  588. $sql = $db->sql_build_query('SELECT', $sql_array);
  589. $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
  590. $topic_list = $topic_forum_list = $global_announce_list = $rowset = array();
  591. while ($row = $db->sql_fetchrow($result))
  592. {
  593. $topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
  594. $topic_list[] = $topic_id;
  595. $rowset[$topic_id] = $row;
  596. $topic_forum_list[$row['forum_id']]['forum_mark_time'] = ($config['load_db_lastread']) ? $row['forum_mark_time'] : 0;
  597. $topic_forum_list[$row['forum_id']]['topics'][] = $topic_id;
  598. if ($row['topic_type'] == POST_GLOBAL)
  599. {
  600. $global_announce_list[] = $topic_id;
  601. }
  602. }
  603. $db->sql_freeresult($result);
  604. $topic_tracking_info = array();
  605. if ($config['load_db_lastread'])
  606. {
  607. foreach ($topic_forum_list as $f_id => $topic_row)
  608. {
  609. $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);
  610. }
  611. }
  612. else
  613. {
  614. foreach ($topic_forum_list as $f_id => $topic_row)
  615. {
  616. $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics'], $global_announce_list);
  617. }
  618. }
  619. foreach ($topic_list as $topic_id)
  620. {
  621. $row = &$rowset[$topic_id];
  622. $forum_id = $row['forum_id'];
  623. $topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
  624. $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
  625. // Replies
  626. $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
  627. if ($row['topic_status'] == ITEM_MOVED && !empty($row['topic_moved_id']))
  628. {
  629. $topic_id = $row['topic_moved_id'];
  630. }
  631. // Get folder img, topic status/type related information
  632. $folder_img = $folder_alt = $topic_type = '';
  633. topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
  634. $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id");
  635. // Send vars to template
  636. $template->assign_block_vars('topicrow', array(
  637. 'FORUM_ID' => $forum_id,
  638. 'TOPIC_ID' => $topic_id,
  639. 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
  640. 'LAST_POST_SUBJECT' => $row['topic_last_post_subject'],
  641. 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
  642. 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
  643. 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  644. 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  645. 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  646. 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  647. 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  648. 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  649. 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  650. 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  651. 'S_DELETED_TOPIC' => (!$row['topic_id']) ? true : false,
  652. 'S_GLOBAL_TOPIC' => (!$forum_id) ? true : false,
  653. '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")),
  654. 'REPLIES' => $replies,
  655. 'VIEWS' => $row['topic_views'],
  656. 'TOPIC_TITLE' => censor_text($row['topic_title']),
  657. 'TOPIC_TYPE' => $topic_type,
  658. 'FORUM_NAME' => $row['forum_name'],
  659. 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
  660. 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'),
  661. 'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
  662. 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
  663. 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
  664. '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']) : '',
  665. 'S_TOPIC_TYPE' => $row['topic_type'],
  666. 'S_USER_POSTED' => (!empty($row['topic_posted'])) ? true : false,
  667. 'S_UNREAD_TOPIC' => $unread_topic,
  668. 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;view=unread") . '#unread',
  669. 'U_LAST_POST' => $view_topic_url . '&amp;p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'],
  670. 'U_VIEW_TOPIC' => $view_topic_url,
  671. 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
  672. ));
  673. }
  674. }
  675. }
  676. ?>