Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
ucp_main.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 /**
015 * @ignore
016 */
017 if (!defined('IN_PHPBB'))
018 {
019 exit;
020 }
021
022 /**
023 * ucp_main
024 * UCP Front Panel
025 */
026 class ucp_main
027 {
028 var $p_master;
029 var $u_action;
030
031 function ucp_main(&$p_master)
032 {
033 $this->p_master = &$p_master;
034 }
035
036 function main($id, $mode)
037 {
038 global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx, $phpbb_dispatcher;
039 global $request;
040
041 switch ($mode)
042 {
043 case 'front':
044
045 $user->add_lang('memberlist');
046
047 $sql_from = TOPICS_TABLE . ' t ';
048 $sql_select = '';
049
050 if ($config['load_db_track'])
051 {
052 $sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.topic_id = t.topic_id
053 AND tp.user_id = ' . $user->data['user_id'] . ')';
054 $sql_select .= ', tp.topic_posted';
055 }
056
057 if ($config['load_db_lastread'])
058 {
059 $sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id
060 AND tt.user_id = ' . $user->data['user_id'] . ')';
061 $sql_select .= ', tt.mark_time';
062
063 $sql_from .= ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.forum_id = t.forum_id
064 AND ft.user_id = ' . $user->data['user_id'] . ')';
065 $sql_select .= ', ft.mark_time AS forum_mark_time';
066 }
067
068 $topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
069 $folder = 'global_read';
070 $folder_new = 'global_unread';
071
072 // Get cleaned up list... return only those forums having the f_read permission
073 $forum_ary = $auth->acl_getf('f_read', true);
074 $forum_ary = array_unique(array_keys($forum_ary));
075 $topic_list = $rowset = array();
076
077 // If the user can't see any forums, he can't read any posts because fid of 0 is invalid
078 if (!empty($forum_ary))
079 {
080 $sql = "SELECT t.* $sql_select
081 FROM $sql_from
082 WHERE t.topic_type = " . POST_GLOBAL . '
083 AND ' . $db->sql_in_set('t.forum_id', $forum_ary) . '
084 ORDER BY t.topic_last_post_time DESC, t.topic_last_post_id DESC';
085 $result = $db->sql_query($sql);
086
087 while ($row = $db->sql_fetchrow($result))
088 {
089 $topic_list[] = $row['topic_id'];
090 $rowset[$row['topic_id']] = $row;
091 }
092 $db->sql_freeresult($result);
093 }
094
095 $topic_forum_list = array();
096 foreach ($rowset as $t_id => $row)
097 {
098 if (isset($forum_tracking_info[$row['forum_id']]))
099 {
100 $row['forum_mark_time'] = $forum_tracking_info[$row['forum_id']];
101 }
102
103 $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;
104 $topic_forum_list[$row['forum_id']]['topics'][] = (int) $t_id;
105 }
106
107 $topic_tracking_info = $tracking_topics = array();
108 if ($config['load_db_lastread'])
109 {
110 foreach ($topic_forum_list as $f_id => $topic_row)
111 {
112 $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']));
113 }
114 }
115 else
116 {
117 foreach ($topic_forum_list as $f_id => $topic_row)
118 {
119 $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics']);
120 }
121 }
122 unset($topic_forum_list);
123
124 foreach ($topic_list as $topic_id)
125 {
126 $row = &$rowset[$topic_id];
127
128 $forum_id = $row['forum_id'];
129 $topic_id = $row['topic_id'];
130
131 $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
132
133 $folder_img = ($unread_topic) ? $folder_new : $folder;
134 $folder_alt = ($unread_topic) ? 'UNREAD_POSTS' : (($row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_UNREAD_POSTS');
135
136 if ($row['topic_status'] == ITEM_LOCKED)
137 {
138 $folder_img .= '_locked';
139 }
140
141 // Posted image?
142 if (!empty($row['topic_posted']) && $row['topic_posted'])
143 {
144 $folder_img .= '_mine';
145 }
146
147 $template->assign_block_vars('topicrow', array(
148 'FORUM_ID' => $forum_id,
149 'TOPIC_ID' => $topic_id,
150 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
151 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
152 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
153 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
154 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']),
155 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
156 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
157 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
158 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
159 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
160 'TOPIC_TITLE' => censor_text($row['topic_title']),
161 'TOPIC_TYPE' => $topic_type,
162
163 'TOPIC_IMG_STYLE' => $folder_img,
164 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
165 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', '') : '',
166
167 'S_USER_POSTED' => (!empty($row['topic_posted']) && $row['topic_posted']) ? true : false,
168 'S_UNREAD' => $unread_topic,
169
170 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
171 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&p=" . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
172 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
173 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&view=unread") . '#unread',
174 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id"))
175 );
176 }
177
178 if ($config['load_user_activity'])
179 {
180 if (!function_exists('display_user_activity'))
181 {
182 include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
183 }
184 display_user_activity($user->data);
185 }
186
187 // Do the relevant calculations
188 $memberdays = max(1, round((time() - $user->data['user_regdate']) / 86400));
189 $posts_per_day = $user->data['user_posts'] / $memberdays;
190 $percentage = ($config['num_posts']) ? min(100, ($user->data['user_posts'] / $config['num_posts']) * 100) : 0;
191
192 $template->assign_vars(array(
193 'USER_COLOR' => (!empty($user->data['user_colour'])) ? $user->data['user_colour'] : '',
194 'JOINED' => $user->format_date($user->data['user_regdate']),
195 'LAST_ACTIVE' => (empty($last_active)) ? ' - ' : $user->format_date($last_active),
196 'WARNINGS' => ($user->data['user_warnings']) ? $user->data['user_warnings'] : 0,
197 'POSTS' => ($user->data['user_posts']) ? $user->data['user_posts'] : 0,
198 'POSTS_DAY' => $user->lang('POST_DAY', $posts_per_day),
199 'POSTS_PCT' => $user->lang('POST_PCT', $percentage),
200
201 // 'S_GROUP_OPTIONS' => $group_options,
202
203 'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $user->data['user_id'] . '&sr=posts') : '',
204 ));
205
206 break;
207
208 case 'subscribed':
209
210 include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
211
212 $user->add_lang('viewforum');
213
214 add_form_key('ucp_front_subscribed');
215
216 $unwatch = (isset($_POST['unwatch'])) ? true : false;
217
218 /**
219 * Read and potentially modify the post data used to remove subscriptions to forums/topics
220 *
221 * @event core.ucp_main_subscribed_post_data
222 * @since 3.1.10-RC1
223 */
224 $phpbb_dispatcher->dispatch('core.ucp_main_subscribed_post_data');
225
226 if ($unwatch)
227 {
228 if (check_form_key('ucp_front_subscribed'))
229 {
230 $forums = array_keys($request->variable('f', array(0 => 0)));
231 $topics = array_keys($request->variable('t', array(0 => 0)));
232
233 if (sizeof($forums) || sizeof($topics))
234 {
235 $l_unwatch = '';
236 if (sizeof($forums))
237 {
238 $sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . '
239 WHERE ' . $db->sql_in_set('forum_id', $forums) . '
240 AND user_id = ' . $user->data['user_id'];
241 $db->sql_query($sql);
242
243 $l_unwatch .= '_FORUMS';
244 }
245
246 if (sizeof($topics))
247 {
248 $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . '
249 WHERE ' . $db->sql_in_set('topic_id', $topics) . '
250 AND user_id = ' . $user->data['user_id'];
251 $db->sql_query($sql);
252
253 $l_unwatch .= '_TOPICS';
254 }
255 $msg = $user->lang['UNWATCHED' . $l_unwatch];
256 }
257 else
258 {
259 $msg = $user->lang['NO_WATCHED_SELECTED'];
260 }
261 }
262 else
263 {
264 $msg = $user->lang['FORM_INVALID'];
265 }
266 $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=subscribed") . '">', '</a>');
267 meta_refresh(3, append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=subscribed"));
268 trigger_error($message);
269 }
270
271 $forbidden_forums = array();
272
273 if ($config['allow_forum_notify'])
274 {
275 $forbidden_forums = $auth->acl_getf('!f_read', true);
276 $forbidden_forums = array_unique(array_keys($forbidden_forums));
277
278 $sql_array = array(
279 'SELECT' => 'f.*',
280
281 'FROM' => array(
282 FORUMS_WATCH_TABLE => 'fw',
283 FORUMS_TABLE => 'f'
284 ),
285
286 'WHERE' => 'fw.user_id = ' . $user->data['user_id'] . '
287 AND f.forum_id = fw.forum_id
288 AND ' . $db->sql_in_set('f.forum_id', $forbidden_forums, true, true),
289
290 'ORDER_BY' => 'left_id'
291 );
292
293 if ($config['load_db_lastread'])
294 {
295 $sql_array['LEFT_JOIN'] = array(
296 array(
297 'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
298 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'
299 )
300 );
301
302 $sql_array['SELECT'] .= ', ft.mark_time ';
303 }
304 else
305 {
306 $tracking_topics = $request->variable($config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE);
307 $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
308 }
309
310 /**
311 * Modify the query used to retrieve a list of subscribed forums
312 *
313 * @event core.ucp_main_subscribed_forums_modify_query
314 * @var array sql_array The subscribed forums query
315 * @var array forbidden_forums The list of forbidden forums
316 * @since 3.1.10-RC1
317 */
318 $vars = array(
319 'sql_array',
320 'forbidden_forums',
321 );
322 extract($phpbb_dispatcher->trigger_event('core.ucp_main_subscribed_forums_modify_query', compact($vars)));
323
324 $sql = $db->sql_build_query('SELECT', $sql_array);
325 $result = $db->sql_query($sql);
326
327 while ($row = $db->sql_fetchrow($result))
328 {
329 $forum_id = $row['forum_id'];
330
331 if ($config['load_db_lastread'])
332 {
333 $forum_check = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
334 }
335 else
336 {
337 $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'];
338 }
339
340 $unread_forum = ($row['forum_last_post_time'] > $forum_check) ? true : false;
341
342 // Which folder should we display?
343 if ($row['forum_status'] == ITEM_LOCKED)
344 {
345 $folder_image = ($unread_forum) ? 'forum_unread_locked' : 'forum_read_locked';
346 $folder_alt = 'FORUM_LOCKED';
347 }
348 else
349 {
350 $folder_image = ($unread_forum) ? 'forum_unread' : 'forum_read';
351 $folder_alt = ($unread_forum) ? 'UNREAD_POSTS' : 'NO_UNREAD_POSTS';
352 }
353
354 // Create last post link information, if appropriate
355 if ($row['forum_last_post_id'])
356 {
357 $last_post_time = $user->format_date($row['forum_last_post_time']);
358 $last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&p=" . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
359 }
360 else
361 {
362 $last_post_time = $last_post_url = '';
363 }
364
365 $template_vars = array(
366 'FORUM_ID' => $forum_id,
367 'FORUM_IMG_STYLE' => $folder_image,
368 'FORUM_FOLDER_IMG' => $user->img($folder_image, $folder_alt),
369 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
370 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
371 'FORUM_NAME' => $row['forum_name'],
372 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
373 'LAST_POST_SUBJECT' => $row['forum_last_post_subject'],
374 'LAST_POST_TIME' => $last_post_time,
375
376 'LAST_POST_AUTHOR' => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
377 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
378 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
379 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
380
381 'S_UNREAD_FORUM' => $unread_forum,
382
383 'U_LAST_POST' => $last_post_url,
384 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id'])
385 );
386
387 /**
388 * Add template variables to a subscribed forum row.
389 *
390 * @event core.ucp_main_subscribed_forum_modify_template_vars
391 * @var array template_vars Array containing the template variables for the row
392 * @var array row Array containing the subscribed forum row data
393 * @var int forum_id Forum ID
394 * @var string folder_image Folder image
395 * @var string folder_alt Alt text for the folder image
396 * @var bool unread_forum Whether the forum has unread content or not
397 * @var string last_post_time The time of the most recent post, expressed as a formatted date string
398 * @var string last_post_url The URL of the most recent post in the forum
399 * @since 3.1.10-RC1
400 */
401 $vars = array(
402 'template_vars',
403 'row',
404 'forum_id',
405 'folder_image',
406 'folder_alt',
407 'unread_forum',
408 'last_post_time',
409 'last_post_url',
410 );
411 extract($phpbb_dispatcher->trigger_event('core.ucp_main_subscribed_forum_modify_template_vars', compact($vars)));
412
413 $template->assign_block_vars('forumrow', $template_vars);
414 }
415 $db->sql_freeresult($result);
416 }
417
418 // Subscribed Topics
419 if ($config['allow_topic_notify'])
420 {
421 if (empty($forbidden_forums))
422 {
423 $forbidden_forums = $auth->acl_getf('!f_read', true);
424 $forbidden_forums = array_unique(array_keys($forbidden_forums));
425 }
426 $this->assign_topiclist('subscribed', $forbidden_forums);
427 }
428
429 $template->assign_vars(array(
430 'S_TOPIC_NOTIFY' => $config['allow_topic_notify'],
431 'S_FORUM_NOTIFY' => $config['allow_forum_notify'],
432 ));
433
434 break;
435
436 case 'bookmarks':
437
438 if (!$config['allow_bookmarks'])
439 {
440 $template->assign_vars(array(
441 'S_NO_DISPLAY_BOOKMARKS' => true)
442 );
443 break;
444 }
445
446 include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
447
448 $user->add_lang('viewforum');
449
450 if (isset($_POST['unbookmark']))
451 {
452 $s_hidden_fields = array('unbookmark' => 1);
453 $topics = (isset($_POST['t'])) ? array_keys($request->variable('t', array(0 => 0))) : array();
454 $url = $this->u_action;
455
456 if (!sizeof($topics))
457 {
458 trigger_error('NO_BOOKMARKS_SELECTED');
459 }
460
461 foreach ($topics as $topic_id)
462 {
463 $s_hidden_fields['t'][$topic_id] = 1;
464 }
465
466 if (confirm_box(true))
467 {
468 $sql = 'DELETE FROM ' . BOOKMARKS_TABLE . '
469 WHERE user_id = ' . $user->data['user_id'] . '
470 AND ' . $db->sql_in_set('topic_id', $topics);
471 $db->sql_query($sql);
472
473 meta_refresh(3, $url);
474 $message = $user->lang['BOOKMARKS_REMOVED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $url . '">', '</a>');
475 trigger_error($message);
476 }
477 else
478 {
479 confirm_box(false, 'REMOVE_SELECTED_BOOKMARKS', build_hidden_fields($s_hidden_fields));
480 }
481 }
482 $forbidden_forums = $auth->acl_getf('!f_read', true);
483 $forbidden_forums = array_unique(array_keys($forbidden_forums));
484
485 $this->assign_topiclist('bookmarks', $forbidden_forums);
486
487 break;
488
489 case 'drafts':
490
491 $pm_drafts = ($this->p_master->p_name == 'pm') ? true : false;
492 $template->assign_var('S_SHOW_DRAFTS', true);
493
494 $user->add_lang('posting');
495
496 $edit = (isset($_REQUEST['edit'])) ? true : false;
497 $submit = (isset($_POST['submit'])) ? true : false;
498 $draft_id = $request->variable('edit', 0);
499 $delete = (isset($_POST['delete'])) ? true : false;
500
501 $s_hidden_fields = ($edit) ? '<input type="hidden" name="edit" value="' . $draft_id . '" />' : '';
502 $draft_subject = $draft_message = '';
503 add_form_key('ucp_draft');
504
505 if ($delete)
506 {
507 if (check_form_key('ucp_draft'))
508 {
509 $drafts = array_keys($request->variable('d', array(0 => 0)));
510
511 if (sizeof($drafts))
512 {
513 $sql = 'DELETE FROM ' . DRAFTS_TABLE . '
514 WHERE ' . $db->sql_in_set('draft_id', $drafts) . '
515 AND user_id = ' . $user->data['user_id'];
516 $db->sql_query($sql);
517 }
518 $msg = $user->lang['DRAFTS_DELETED'];
519 unset($drafts);
520 }
521 else
522 {
523 $msg = $user->lang['FORM_INVALID'];
524 }
525 $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
526 meta_refresh(3, $this->u_action);
527 trigger_error($message);
528 }
529
530 if ($submit && $edit)
531 {
532 $draft_subject = $request->variable('subject', '', true);
533 $draft_message = $request->variable('message', '', true);
534 if (check_form_key('ucp_draft'))
535 {
536 if ($draft_message && $draft_subject)
537 {
538 $draft_row = array(
539 'draft_subject' => $draft_subject,
540 'draft_message' => $draft_message
541 );
542
543 $sql = 'UPDATE ' . DRAFTS_TABLE . '
544 SET ' . $db->sql_build_array('UPDATE', $draft_row) . "
545 WHERE draft_id = $draft_id
546 AND user_id = " . $user->data['user_id'];
547 $db->sql_query($sql);
548
549 $message = $user->lang['DRAFT_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
550
551 meta_refresh(3, $this->u_action);
552 trigger_error($message);
553 }
554 else
555 {
556 $template->assign_var('ERROR', ($draft_message == '') ? $user->lang['EMPTY_DRAFT'] : (($draft_subject == '') ? $user->lang['EMPTY_DRAFT_TITLE'] : ''));
557 }
558 }
559 else
560 {
561 $template->assign_var('ERROR', $user->lang['FORM_INVALID']);
562 }
563 }
564
565 if (!$pm_drafts)
566 {
567 $sql = 'SELECT d.*, f.forum_name
568 FROM ' . DRAFTS_TABLE . ' d, ' . FORUMS_TABLE . ' f
569 WHERE d.user_id = ' . $user->data['user_id'] . ' ' .
570 (($edit) ? "AND d.draft_id = $draft_id" : '') . '
571 AND f.forum_id = d.forum_id
572 ORDER BY d.save_time DESC';
573 }
574 else
575 {
576 $sql = 'SELECT * FROM ' . DRAFTS_TABLE . '
577 WHERE user_id = ' . $user->data['user_id'] . ' ' .
578 (($edit) ? "AND draft_id = $draft_id" : '') . '
579 AND forum_id = 0
580 AND topic_id = 0
581 ORDER BY save_time DESC';
582 }
583 $result = $db->sql_query($sql);
584
585 $draftrows = $topic_ids = array();
586
587 while ($row = $db->sql_fetchrow($result))
588 {
589 if ($row['topic_id'])
590 {
591 $topic_ids[] = (int) $row['topic_id'];
592 }
593 $draftrows[] = $row;
594 }
595 $db->sql_freeresult($result);
596
597 if (sizeof($topic_ids))
598 {
599 $sql = 'SELECT topic_id, forum_id, topic_title
600 FROM ' . TOPICS_TABLE . '
601 WHERE ' . $db->sql_in_set('topic_id', array_unique($topic_ids));
602 $result = $db->sql_query($sql);
603
604 while ($row = $db->sql_fetchrow($result))
605 {
606 $topic_rows[$row['topic_id']] = $row;
607 }
608 $db->sql_freeresult($result);
609 }
610 unset($topic_ids);
611
612 $template->assign_var('S_EDIT_DRAFT', $edit);
613
614 $row_count = 0;
615 foreach ($draftrows as $draft)
616 {
617 $link_topic = $link_forum = $link_pm = false;
618 $insert_url = $view_url = $title = '';
619
620 if (isset($topic_rows[$draft['topic_id']]) && $auth->acl_get('f_read', $topic_rows[$draft['topic_id']]['forum_id']))
621 {
622 $link_topic = true;
623 $view_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_rows[$draft['topic_id']]['forum_id'] . '&t=' . $draft['topic_id']);
624 $title = $topic_rows[$draft['topic_id']]['topic_title'];
625
626 $insert_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $topic_rows[$draft['topic_id']]['forum_id'] . '&t=' . $draft['topic_id'] . '&mode=reply&d=' . $draft['draft_id']);
627 }
628 else if ($auth->acl_get('f_read', $draft['forum_id']))
629 {
630 $link_forum = true;
631 $view_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $draft['forum_id']);
632 $title = $draft['forum_name'];
633
634 $insert_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $draft['forum_id'] . '&mode=post&d=' . $draft['draft_id']);
635 }
636 else if ($pm_drafts)
637 {
638 $link_pm = true;
639 $insert_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=compose&d=" . $draft['draft_id']);
640 }
641
642 $template_row = array(
643 'DATE' => $user->format_date($draft['save_time']),
644 'DRAFT_MESSAGE' => ($submit) ? $draft_message : $draft['draft_message'],
645 'DRAFT_SUBJECT' => ($submit) ? $draft_subject : $draft['draft_subject'],
646 'TITLE' => $title,
647
648 'DRAFT_ID' => $draft['draft_id'],
649 'FORUM_ID' => $draft['forum_id'],
650 'TOPIC_ID' => $draft['topic_id'],
651
652 'U_VIEW' => $view_url,
653 'U_VIEW_EDIT' => $this->u_action . '&edit=' . $draft['draft_id'],
654 'U_INSERT' => $insert_url,
655
656 'S_LINK_TOPIC' => $link_topic,
657 'S_LINK_FORUM' => $link_forum,
658 'S_LINK_PM' => $link_pm,
659 'S_HIDDEN_FIELDS' => $s_hidden_fields
660 );
661 $row_count++;
662
663 ($edit) ? $template->assign_vars($template_row) : $template->assign_block_vars('draftrow', $template_row);
664 }
665
666 if (!$edit)
667 {
668 $template->assign_var('S_DRAFT_ROWS', $row_count);
669 }
670
671 break;
672 }
673
674 $template->assign_vars(array(
675 'L_TITLE' => $user->lang['UCP_MAIN_' . strtoupper($mode)],
676
677 'S_DISPLAY_MARK_ALL' => ($mode == 'watched' || ($mode == 'drafts' && !isset($_GET['edit']))) ? true : false,
678 'S_HIDDEN_FIELDS' => (isset($s_hidden_fields)) ? $s_hidden_fields : '',
679 'S_UCP_ACTION' => $this->u_action,
680
681 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
682 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
683 ));
684
685 // Set desired template
686 $this->tpl_name = 'ucp_main_' . $mode;
687 $this->page_title = 'UCP_MAIN_' . strtoupper($mode);
688 }
689
690 /**
691 * Build and assign topiclist for bookmarks/subscribed topics
692 */
693 function assign_topiclist($mode = 'subscribed', $forbidden_forum_ary = array())
694 {
695 global $user, $db, $template, $config, $cache, $auth, $phpbb_root_path, $phpEx, $phpbb_container, $request, $phpbb_dispatcher;
696
697 /* @var $pagination \phpbb\pagination */
698 $pagination = $phpbb_container->get('pagination');
699 $table = ($mode == 'subscribed') ? TOPICS_WATCH_TABLE : BOOKMARKS_TABLE;
700 $start = $request->variable('start', 0);
701
702 // Grab icons
703 $icons = $cache->obtain_icons();
704
705 $sql_array = array(
706 'SELECT' => 'COUNT(t.topic_id) as topics_count',
707
708 'FROM' => array(
709 $table => 'i',
710 TOPICS_TABLE => 't'
711 ),
712
713 'WHERE' => 'i.topic_id = t.topic_id
714 AND i.user_id = ' . $user->data['user_id'] . '
715 AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true),
716 );
717
718 /**
719 * Modify the query used to retrieve the count of subscribed/bookmarked topics
720 *
721 * @event core.ucp_main_topiclist_count_modify_query
722 * @var array sql_array The subscribed/bookmarked topics query
723 * @var array forbidden_forum_ary The list of forbidden forums
724 * @var string mode The type of topic list ('subscribed' or 'bookmarks')
725 * @since 3.1.10-RC1
726 */
727 $vars = array(
728 'sql_array',
729 'forbidden_forum_ary',
730 'mode',
731 );
732 extract($phpbb_dispatcher->trigger_event('core.ucp_main_topiclist_count_modify_query', compact($vars)));
733
734 $sql = $db->sql_build_query('SELECT', $sql_array);
735 $result = $db->sql_query($sql);
736 $topics_count = (int) $db->sql_fetchfield('topics_count');
737 $db->sql_freeresult($result);
738
739 if ($topics_count)
740 {
741 $start = $pagination->validate_start($start, $config['topics_per_page'], $topics_count);
742 $pagination->generate_template_pagination($this->u_action, 'pagination', 'start', $topics_count, $config['topics_per_page'], $start);
743
744 $template->assign_vars(array(
745 'TOTAL_TOPICS' => $user->lang('VIEW_FORUM_TOPICS', (int) $topics_count),
746 ));
747 }
748
749 if ($mode == 'subscribed')
750 {
751 $sql_array = array(
752 'SELECT' => 't.*, f.forum_name',
753
754 'FROM' => array(
755 TOPICS_WATCH_TABLE => 'tw',
756 TOPICS_TABLE => 't'
757 ),
758
759 'WHERE' => 'tw.user_id = ' . $user->data['user_id'] . '
760 AND t.topic_id = tw.topic_id
761 AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true),
762
763 'ORDER_BY' => 't.topic_last_post_time DESC, t.topic_last_post_id DESC'
764 );
765
766 $sql_array['LEFT_JOIN'] = array();
767 }
768 else
769 {
770 $sql_array = array(
771 'SELECT' => 't.*, f.forum_name, b.topic_id as b_topic_id',
772
773 'FROM' => array(
774 BOOKMARKS_TABLE => 'b',
775 ),
776
777 'WHERE' => 'b.user_id = ' . $user->data['user_id'] . '
778 AND ' . $db->sql_in_set('f.forum_id', $forbidden_forum_ary, true, true),
779
780 'ORDER_BY' => 't.topic_last_post_time DESC, t.topic_last_post_id DESC'
781 );
782
783 $sql_array['LEFT_JOIN'] = array();
784 $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TABLE => 't'), 'ON' => 'b.topic_id = t.topic_id');
785 }
786
787 $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 't.forum_id = f.forum_id');
788
789 if ($config['load_db_lastread'])
790 {
791 $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']);
792 $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']);
793 $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time AS forum_mark_time';
794 }
795
796 if ($config['load_db_track'])
797 {
798 $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']);
799 $sql_array['SELECT'] .= ', tp.topic_posted';
800 }
801
802 /**
803 * Modify the query used to retrieve the list of subscribed/bookmarked topics
804 *
805 * @event core.ucp_main_topiclist_modify_query
806 * @var array sql_array The subscribed/bookmarked topics query
807 * @var array forbidden_forum_ary The list of forbidden forums
808 * @var string mode The type of topic list ('subscribed' or 'bookmarks')
809 * @since 3.1.10-RC1
810 */
811 $vars = array(
812 'sql_array',
813 'forbidden_forum_ary',
814 'mode',
815 );
816 extract($phpbb_dispatcher->trigger_event('core.ucp_main_topiclist_modify_query', compact($vars)));
817
818 $sql = $db->sql_build_query('SELECT', $sql_array);
819 $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
820
821 $topic_list = $topic_forum_list = $global_announce_list = $rowset = array();
822 while ($row = $db->sql_fetchrow($result))
823 {
824 $topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
825
826 $topic_list[] = $topic_id;
827 $rowset[$topic_id] = $row;
828
829 $topic_forum_list[$row['forum_id']]['forum_mark_time'] = ($config['load_db_lastread']) ? $row['forum_mark_time'] : 0;
830 $topic_forum_list[$row['forum_id']]['topics'][] = $topic_id;
831
832 if ($row['topic_type'] == POST_GLOBAL)
833 {
834 $global_announce_list[] = $topic_id;
835 }
836 }
837 $db->sql_freeresult($result);
838
839 $topic_tracking_info = array();
840 if ($config['load_db_lastread'])
841 {
842 foreach ($topic_forum_list as $f_id => $topic_row)
843 {
844 $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']));
845 }
846 }
847 else
848 {
849 foreach ($topic_forum_list as $f_id => $topic_row)
850 {
851 $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics']);
852 }
853 }
854
855 /* @var $phpbb_content_visibility \phpbb\content_visibility */
856 $phpbb_content_visibility = $phpbb_container->get('content.visibility');
857
858 foreach ($topic_list as $topic_id)
859 {
860 $row = &$rowset[$topic_id];
861
862 $forum_id = $row['forum_id'];
863 $topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
864
865 $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
866
867 // Replies
868 $replies = $phpbb_content_visibility->get_count('topic_posts', $row, $forum_id) - 1;
869
870 if ($row['topic_status'] == ITEM_MOVED && !empty($row['topic_moved_id']))
871 {
872 $topic_id = $row['topic_moved_id'];
873 }
874
875 // Get folder img, topic status/type related information
876 $folder_img = $folder_alt = $topic_type = '';
877 topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
878
879 $view_topic_url_params = "f=$forum_id&t=$topic_id";
880 $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params);
881
882 // Send vars to template
883 $template_vars = array(
884 'FORUM_ID' => $forum_id,
885 'TOPIC_ID' => $topic_id,
886 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
887 'LAST_POST_SUBJECT' => $row['topic_last_post_subject'],
888 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
889 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
890
891 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
892 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
893 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
894 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
895
896 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
897 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
898 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
899 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
900
901 'S_DELETED_TOPIC' => (!$row['topic_id']) ? true : false,
902
903 'REPLIES' => $replies,
904 'VIEWS' => $row['topic_views'],
905 'TOPIC_TITLE' => censor_text($row['topic_title']),
906 'TOPIC_TYPE' => $topic_type,
907 'FORUM_NAME' => $row['forum_name'],
908
909 'TOPIC_IMG_STYLE' => $folder_img,
910 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
911 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt],
912 'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
913 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
914 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
915 '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']) : '',
916
917 'S_TOPIC_TYPE' => $row['topic_type'],
918 'S_USER_POSTED' => (!empty($row['topic_posted'])) ? true : false,
919 'S_UNREAD_TOPIC' => $unread_topic,
920
921 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&view=unread') . '#unread',
922 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
923 'U_VIEW_TOPIC' => $view_topic_url,
924 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
925 );
926
927 /**
928 * Add template variables to a subscribed/bookmarked topic row.
929 *
930 * @event core.ucp_main_topiclist_topic_modify_template_vars
931 * @var array template_vars Array containing the template variables for the row
932 * @var array row Array containing the subscribed/bookmarked topic row data
933 * @var int forum_id ID of the forum containing the topic
934 * @var int topic_id Topic ID
935 * @var int replies Number of replies in the topic
936 * @var string topic_type Topic type
937 * @var string folder_img Folder image
938 * @var string folder_alt Alt text for the folder image
939 * @var array icons Array containing topic icons
940 * @var bool unread_topic Whether the topic has unread content or not
941 * @var string view_topic_url The URL of the topic
942 * @since 3.1.10-RC1
943 */
944 $vars = array(
945 'template_vars',
946 'row',
947 'forum_id',
948 'topic_id',
949 'replies',
950 'topic_type',
951 'folder_img',
952 'folder_alt',
953 'icons',
954 'unread_topic',
955 'view_topic_url',
956 );
957 extract($phpbb_dispatcher->trigger_event('core.ucp_main_topiclist_topic_modify_template_vars', compact($vars)));
958
959 $template->assign_block_vars('topicrow', $template_vars);
960
961 $pagination->generate_template_pagination(append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . "&t=$topic_id"), 'topicrow.pagination', 'start', $replies + 1, $config['posts_per_page'], 1, true, true);
962 }
963 }
964 }
965