Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ucp_main.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 30.41 KiB


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;
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&amp;t=$topic_id&amp;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&amp;t=$topic_id&amp;view=unread") . '#unread',
174                          'U_VIEW_TOPIC'            => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;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'] . '&amp;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                  if ($unwatch)
219                  {
220                      if (check_form_key('ucp_front_subscribed'))
221                      {
222                          $forums = array_keys(request_var('f', array(0 => 0)));
223                          $topics = array_keys(request_var('t', array(0 => 0)));
224                          $msg = '';
225   
226                          if (sizeof($forums) || sizeof($topics))
227                          {
228                              $l_unwatch = '';
229                              if (sizeof($forums))
230                              {
231                                  $sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . '
232                                      WHERE ' . $db->sql_in_set('forum_id', $forums) . '
233                                          AND user_id = ' . $user->data['user_id'];
234                                  $db->sql_query($sql);
235   
236                                  $l_unwatch .= '_FORUMS';
237                              }
238   
239                              if (sizeof($topics))
240                              {
241                                  $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . '
242                                      WHERE ' . $db->sql_in_set('topic_id', $topics) . '
243                                          AND user_id = ' . $user->data['user_id'];
244                                  $db->sql_query($sql);
245   
246                                  $l_unwatch .= '_TOPICS';
247                              }
248                              $msg = $user->lang['UNWATCHED' . $l_unwatch];
249                          }
250                          else
251                          {
252                              $msg = $user->lang['NO_WATCHED_SELECTED'];
253                          }
254                      }
255                      else
256                      {
257                          $msg = $user->lang['FORM_INVALID'];
258                      }
259                      $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=subscribed") . '">', '</a>');
260                      meta_refresh(3, append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=subscribed"));
261                      trigger_error($message);
262                  }
263   
264                  $forbidden_forums = array();
265   
266                  if ($config['allow_forum_notify'])
267                  {
268                      $forbidden_forums = $auth->acl_getf('!f_read', true);
269                      $forbidden_forums = array_unique(array_keys($forbidden_forums));
270   
271                      $sql_array = array(
272                          'SELECT'    => 'f.*',
273   
274                          'FROM'        => array(
275                              FORUMS_WATCH_TABLE    => 'fw',
276                              FORUMS_TABLE        => 'f'
277                          ),
278   
279                          'WHERE'        => 'fw.user_id = ' . $user->data['user_id'] . '
280                              AND f.forum_id = fw.forum_id
281                              AND ' . $db->sql_in_set('f.forum_id', $forbidden_forums, true, true),
282   
283                          'ORDER_BY'    => 'left_id'
284                      );
285   
286                      if ($config['load_db_lastread'])
287                      {
288                          $sql_array['LEFT_JOIN'] = array(
289                              array(
290                                  'FROM'    => array(FORUMS_TRACK_TABLE => 'ft'),
291                                  'ON'    => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'
292                              )
293                          );
294   
295                          $sql_array['SELECT'] .= ', ft.mark_time ';
296                      }
297                      else
298                      {
299                          $tracking_topics = $request->variable($config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE);
300                          $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
301                      }
302   
303                      $sql = $db->sql_build_query('SELECT', $sql_array);
304                      $result = $db->sql_query($sql);
305   
306                      while ($row = $db->sql_fetchrow($result))
307                      {
308                          $forum_id = $row['forum_id'];
309   
310                          if ($config['load_db_lastread'])
311                          {
312                              $forum_check = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
313                          }
314                          else
315                          {
316                              $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'];
317                          }
318   
319                          $unread_forum = ($row['forum_last_post_time'] > $forum_check) ? true : false;
320   
321                          // Which folder should we display?
322                          if ($row['forum_status'] == ITEM_LOCKED)
323                          {
324                              $folder_image = ($unread_forum) ? 'forum_unread_locked' : 'forum_read_locked';
325                              $folder_alt = 'FORUM_LOCKED';
326                          }
327                          else
328                          {
329                              $folder_image = ($unread_forum) ? 'forum_unread' : 'forum_read';
330                              $folder_alt = ($unread_forum) ? 'UNREAD_POSTS' : 'NO_UNREAD_POSTS';
331                          }
332   
333                          // Create last post link information, if appropriate
334                          if ($row['forum_last_post_id'])
335                          {
336                              $last_post_time = $user->format_date($row['forum_last_post_time']);
337                              $last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;p=" . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
338                          }
339                          else
340                          {
341                              $last_post_time = $last_post_url = '';
342                          }
343   
344                          $template->assign_block_vars('forumrow', array(
345                              'FORUM_ID'                => $forum_id,
346                              'FORUM_IMG_STYLE'        => $folder_image,
347                              'FORUM_FOLDER_IMG'        => $user->img($folder_image, $folder_alt),
348                              'FORUM_IMAGE'            => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
349                              'FORUM_IMAGE_SRC'        => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
350                              'FORUM_NAME'            => $row['forum_name'],
351                              'FORUM_DESC'            => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
352                              'LAST_POST_SUBJECT'        => $row['forum_last_post_subject'],
353                              'LAST_POST_TIME'        => $last_post_time,
354   
355                              'LAST_POST_AUTHOR'            => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
356                              'LAST_POST_AUTHOR_COLOUR'    => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
357                              'LAST_POST_AUTHOR_FULL'        => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
358                              'U_LAST_POST_AUTHOR'        => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
359   
360                              'S_UNREAD_FORUM'        => $unread_forum,
361   
362                              'U_LAST_POST'            => $last_post_url,
363                              'U_VIEWFORUM'            => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
364                          );
365                      }
366                      $db->sql_freeresult($result);
367                  }
368   
369                  // Subscribed Topics
370                  if ($config['allow_topic_notify'])
371                  {
372                      if (empty($forbidden_forums))
373                      {
374                          $forbidden_forums = $auth->acl_getf('!f_read', true);
375                          $forbidden_forums = array_unique(array_keys($forbidden_forums));
376                      }
377                      $this->assign_topiclist('subscribed', $forbidden_forums);
378                  }
379   
380                  $template->assign_vars(array(
381                      'S_TOPIC_NOTIFY'        => $config['allow_topic_notify'],
382                      'S_FORUM_NOTIFY'        => $config['allow_forum_notify'],
383                  ));
384   
385              break;
386   
387              case 'bookmarks':
388   
389                  if (!$config['allow_bookmarks'])
390                  {
391                      $template->assign_vars(array(
392                          'S_NO_DISPLAY_BOOKMARKS'    => true)
393                      );
394                      break;
395                  }
396   
397                  include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
398   
399                  $user->add_lang('viewforum');
400   
401                  if (isset($_POST['unbookmark']))
402                  {
403                      $s_hidden_fields = array('unbookmark' => 1);
404                      $topics = (isset($_POST['t'])) ? array_keys(request_var('t', array(0 => 0))) : array();
405                      $url = $this->u_action;
406   
407                      if (!sizeof($topics))
408                      {
409                          trigger_error('NO_BOOKMARKS_SELECTED');
410                      }
411   
412                      foreach ($topics as $topic_id)
413                      {
414                          $s_hidden_fields['t'][$topic_id] = 1;
415                      }
416   
417                      if (confirm_box(true))
418                      {
419                          $sql = 'DELETE FROM ' . BOOKMARKS_TABLE . '
420                              WHERE user_id = ' . $user->data['user_id'] . '
421                                  AND ' . $db->sql_in_set('topic_id', $topics);
422                          $db->sql_query($sql);
423   
424                          meta_refresh(3, $url);
425                          $message = $user->lang['BOOKMARKS_REMOVED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $url . '">', '</a>');
426                          trigger_error($message);
427                      }
428                      else
429                      {
430                          confirm_box(false, 'REMOVE_SELECTED_BOOKMARKS', build_hidden_fields($s_hidden_fields));
431                      }
432                  }
433                  $forbidden_forums = $auth->acl_getf('!f_read', true);
434                  $forbidden_forums = array_unique(array_keys($forbidden_forums));
435   
436                  $this->assign_topiclist('bookmarks', $forbidden_forums);
437   
438              break;
439   
440              case 'drafts':
441   
442                  $pm_drafts = ($this->p_master->p_name == 'pm') ? true : false;
443                  $template->assign_var('S_SHOW_DRAFTS', true);
444   
445                  $user->add_lang('posting');
446   
447                  $edit        = (isset($_REQUEST['edit'])) ? true : false;
448                  $submit        = (isset($_POST['submit'])) ? true : false;
449                  $draft_id    = $request->variable('edit', 0);
450                  $delete        = (isset($_POST['delete'])) ? true : false;
451   
452                  $s_hidden_fields = ($edit) ? '<input type="hidden" name="edit" value="' . $draft_id . '" />' : '';
453                  $draft_subject = $draft_message = '';
454                  add_form_key('ucp_draft');
455   
456                  if ($delete)
457                  {
458                      if (check_form_key('ucp_draft'))
459                      {
460                          $drafts = array_keys(request_var('d', array(0 => 0)));
461   
462                          if (sizeof($drafts))
463                          {
464                              $sql = 'DELETE FROM ' . DRAFTS_TABLE . '
465                                  WHERE ' . $db->sql_in_set('draft_id', $drafts) . '
466                                      AND user_id = ' . $user->data['user_id'];
467                              $db->sql_query($sql);
468                          }
469                          $msg = $user->lang['DRAFTS_DELETED'];
470                          unset($drafts);
471                      }
472                      else
473                      {
474                          $msg = $user->lang['FORM_INVALID'];
475                      }
476                      $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
477                      meta_refresh(3, $this->u_action);
478                      trigger_error($message);
479                  }
480   
481                  if ($submit && $edit)
482                  {
483                      $draft_subject = utf8_normalize_nfc(request_var('subject', '', true));
484                      $draft_message = utf8_normalize_nfc(request_var('message', '', true));
485                      if (check_form_key('ucp_draft'))
486                      {
487                          if ($draft_message && $draft_subject)
488                          {
489                              $draft_row = array(
490                                  'draft_subject' => $draft_subject,
491                                  'draft_message' => $draft_message
492                              );
493   
494                              $sql = 'UPDATE ' . DRAFTS_TABLE . '
495                                  SET ' . $db->sql_build_array('UPDATE', $draft_row) . "
496                                  WHERE draft_id = $draft_id
497                                      AND user_id = " . $user->data['user_id'];
498                              $db->sql_query($sql);
499   
500                              $message = $user->lang['DRAFT_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
501   
502                              meta_refresh(3, $this->u_action);
503                              trigger_error($message);
504                          }
505                          else
506                          {
507                              $template->assign_var('ERROR', ($draft_message == '') ? $user->lang['EMPTY_DRAFT'] : (($draft_subject == '') ? $user->lang['EMPTY_DRAFT_TITLE'] : ''));
508                          }
509                      }
510                      else
511                      {
512                          $template->assign_var('ERROR', $user->lang['FORM_INVALID']);
513                      }
514                  }
515   
516                  if (!$pm_drafts)
517                  {
518                      $sql = 'SELECT d.*, f.forum_name
519                          FROM ' . DRAFTS_TABLE . ' d, ' . FORUMS_TABLE . ' f
520                          WHERE d.user_id = ' . $user->data['user_id'] . ' ' .
521                              (($edit) ? "AND d.draft_id = $draft_id" : '') . '
522                              AND f.forum_id = d.forum_id
523                          ORDER BY d.save_time DESC';
524                  }
525                  else
526                  {
527                      $sql = 'SELECT * FROM ' . DRAFTS_TABLE . '
528                          WHERE user_id = ' . $user->data['user_id'] . ' ' .
529                              (($edit) ? "AND draft_id = $draft_id" : '') . '
530                              AND forum_id = 0
531                              AND topic_id = 0
532                          ORDER BY save_time DESC';
533                  }
534                  $result = $db->sql_query($sql);
535   
536                  $draftrows = $topic_ids = array();
537   
538                  while ($row = $db->sql_fetchrow($result))
539                  {
540                      if ($row['topic_id'])
541                      {
542                          $topic_ids[] = (int) $row['topic_id'];
543                      }
544                      $draftrows[] = $row;
545                  }
546                  $db->sql_freeresult($result);
547   
548                  if (sizeof($topic_ids))
549                  {
550                      $sql = 'SELECT topic_id, forum_id, topic_title
551                          FROM ' . TOPICS_TABLE . '
552                          WHERE ' . $db->sql_in_set('topic_id', array_unique($topic_ids));
553                      $result = $db->sql_query($sql);
554   
555                      while ($row = $db->sql_fetchrow($result))
556                      {
557                          $topic_rows[$row['topic_id']] = $row;
558                      }
559                      $db->sql_freeresult($result);
560                  }
561                  unset($topic_ids);
562   
563                  $template->assign_var('S_EDIT_DRAFT', $edit);
564   
565                  $row_count = 0;
566                  foreach ($draftrows as $draft)
567                  {
568                      $link_topic = $link_forum = $link_pm = false;
569                      $insert_url = $view_url = $title = '';
570   
571                      if (isset($topic_rows[$draft['topic_id']]) && $auth->acl_get('f_read', $topic_rows[$draft['topic_id']]['forum_id']))
572                      {
573                          $link_topic = true;
574                          $view_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_rows[$draft['topic_id']]['forum_id'] . '&amp;t=' . $draft['topic_id']);
575                          $title = $topic_rows[$draft['topic_id']]['topic_title'];
576   
577                          $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']);
578                      }
579                      else if ($auth->acl_get('f_read', $draft['forum_id']))
580                      {
581                          $link_forum = true;
582                          $view_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $draft['forum_id']);
583                          $title = $draft['forum_name'];
584   
585                          $insert_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $draft['forum_id'] . '&amp;mode=post&amp;d=' . $draft['draft_id']);
586                      }
587                      else if ($pm_drafts)
588                      {
589                          $link_pm = true;
590                          $insert_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=compose&amp;d=" . $draft['draft_id']);
591                      }
592   
593                      $template_row = array(
594                          'DATE'            => $user->format_date($draft['save_time']),
595                          'DRAFT_MESSAGE'    => ($submit) ? $draft_message : $draft['draft_message'],
596                          'DRAFT_SUBJECT'    => ($submit) ? $draft_subject : $draft['draft_subject'],
597                          'TITLE'            => $title,
598   
599                          'DRAFT_ID'    => $draft['draft_id'],
600                          'FORUM_ID'    => $draft['forum_id'],
601                          'TOPIC_ID'    => $draft['topic_id'],
602   
603                          'U_VIEW'        => $view_url,
604                          'U_VIEW_EDIT'    => $this->u_action . '&amp;edit=' . $draft['draft_id'],
605                          'U_INSERT'        => $insert_url,
606   
607                          'S_LINK_TOPIC'        => $link_topic,
608                          'S_LINK_FORUM'        => $link_forum,
609                          'S_LINK_PM'            => $link_pm,
610                          'S_HIDDEN_FIELDS'    => $s_hidden_fields
611                      );
612                      $row_count++;
613   
614                      ($edit) ? $template->assign_vars($template_row) : $template->assign_block_vars('draftrow', $template_row);
615                  }
616   
617                  if (!$edit)
618                  {
619                      $template->assign_var('S_DRAFT_ROWS', $row_count);
620                  }
621   
622              break;
623          }
624   
625          $template->assign_vars(array(
626              'L_TITLE'            => $user->lang['UCP_MAIN_' . strtoupper($mode)],
627   
628              'S_DISPLAY_MARK_ALL'    => ($mode == 'watched' || ($mode == 'drafts' && !isset($_GET['edit']))) ? true : false,
629              'S_HIDDEN_FIELDS'        => (isset($s_hidden_fields)) ? $s_hidden_fields : '',
630              'S_UCP_ACTION'            => $this->u_action,
631   
632              'LAST_POST_IMG'            => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
633              'NEWEST_POST_IMG'        => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
634          ));
635   
636          // Set desired template
637          $this->tpl_name = 'ucp_main_' . $mode;
638          $this->page_title = 'UCP_MAIN_' . strtoupper($mode);
639      }
640   
641      /**
642      * Build and assign topiclist for bookmarks/subscribed topics
643      */
644      function assign_topiclist($mode = 'subscribed', $forbidden_forum_ary = array())
645      {
646          global $user, $db, $template, $config, $cache, $auth, $phpbb_root_path, $phpEx, $phpbb_container;
647   
648          $table = ($mode == 'subscribed') ? TOPICS_WATCH_TABLE : BOOKMARKS_TABLE;
649          $start = request_var('start', 0);
650          $pagination = $phpbb_container->get('pagination');
651   
652          // Grab icons
653          $icons = $cache->obtain_icons();
654   
655          $sql_array = array(
656              'SELECT'    => 'COUNT(t.topic_id) as topics_count',
657   
658              'FROM'        => array(
659                  $table            => 'i',
660                  TOPICS_TABLE    => 't'
661              ),
662   
663              'WHERE'        =>    'i.topic_id = t.topic_id
664                  AND i.user_id = ' . $user->data['user_id'] . '
665                  AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true),
666          );
667          $sql = $db->sql_build_query('SELECT', $sql_array);
668          $result = $db->sql_query($sql);
669          $topics_count = (int) $db->sql_fetchfield('topics_count');
670          $db->sql_freeresult($result);
671   
672          if ($topics_count)
673          {
674              $start = $pagination->validate_start($start, $config['topics_per_page'], $topics_count);
675              $pagination->generate_template_pagination($this->u_action, 'pagination', 'start', $topics_count, $config['topics_per_page'], $start);
676   
677              $template->assign_vars(array(
678                  'TOTAL_TOPICS'    => $user->lang('VIEW_FORUM_TOPICS', (int) $topics_count),
679              ));
680          }
681   
682          if ($mode == 'subscribed')
683          {
684              $sql_array = array(
685                  'SELECT'    => 't.*, f.forum_name',
686   
687                  'FROM'        => array(
688                      TOPICS_WATCH_TABLE    => 'tw',
689                      TOPICS_TABLE        => 't'
690                  ),
691   
692                  'WHERE'        => 'tw.user_id = ' . $user->data['user_id'] . '
693                      AND t.topic_id = tw.topic_id
694                      AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true),
695   
696                  'ORDER_BY'    => 't.topic_last_post_time DESC, t.topic_last_post_id DESC'
697              );
698   
699              $sql_array['LEFT_JOIN'] = array();
700          }
701          else
702          {
703              $sql_array = array(
704                  'SELECT'    => 't.*, f.forum_name, b.topic_id as b_topic_id',
705   
706                  'FROM'        => array(
707                      BOOKMARKS_TABLE        => 'b',
708                  ),
709   
710                  'WHERE'        => 'b.user_id = ' . $user->data['user_id'] . '
711                      AND ' . $db->sql_in_set('f.forum_id', $forbidden_forum_ary, true, true),
712   
713                  'ORDER_BY'    => 't.topic_last_post_time DESC, t.topic_last_post_id DESC'
714              );
715   
716              $sql_array['LEFT_JOIN'] = array();
717              $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TABLE => 't'), 'ON' => 'b.topic_id = t.topic_id');
718          }
719   
720          $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 't.forum_id = f.forum_id');
721   
722          if ($config['load_db_lastread'])
723          {
724              $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']);
725              $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']);
726              $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time AS forum_mark_time';
727          }
728   
729          if ($config['load_db_track'])
730          {
731              $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']);
732              $sql_array['SELECT'] .= ', tp.topic_posted';
733          }
734   
735          $sql = $db->sql_build_query('SELECT', $sql_array);
736          $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
737   
738          $topic_list = $topic_forum_list = $global_announce_list = $rowset = array();
739          while ($row = $db->sql_fetchrow($result))
740          {
741              $topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
742   
743              $topic_list[] = $topic_id;
744              $rowset[$topic_id] = $row;
745   
746              $topic_forum_list[$row['forum_id']]['forum_mark_time'] = ($config['load_db_lastread']) ? $row['forum_mark_time'] : 0;
747              $topic_forum_list[$row['forum_id']]['topics'][] = $topic_id;
748   
749              if ($row['topic_type'] == POST_GLOBAL)
750              {
751                  $global_announce_list[] = $topic_id;
752              }
753          }
754          $db->sql_freeresult($result);
755   
756          $topic_tracking_info = array();
757          if ($config['load_db_lastread'])
758          {
759              foreach ($topic_forum_list as $f_id => $topic_row)
760              {
761                  $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']));
762              }
763          }
764          else
765          {
766              foreach ($topic_forum_list as $f_id => $topic_row)
767              {
768                  $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics']);
769              }
770          }
771   
772          $phpbb_content_visibility = $phpbb_container->get('content.visibility');
773   
774          foreach ($topic_list as $topic_id)
775          {
776              $row = &$rowset[$topic_id];
777   
778              $forum_id = $row['forum_id'];
779              $topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
780   
781              $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
782   
783              // Replies
784              $replies = $phpbb_content_visibility->get_count('topic_posts', $row, $forum_id) - 1;
785   
786              if ($row['topic_status'] == ITEM_MOVED && !empty($row['topic_moved_id']))
787              {
788                  $topic_id = $row['topic_moved_id'];
789              }
790   
791              // Get folder img, topic status/type related information
792              $folder_img = $folder_alt = $topic_type = '';
793              topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
794   
795              $view_topic_url_params = "f=$forum_id&amp;t=$topic_id";
796              $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params);
797   
798              // Send vars to template
799              $template->assign_block_vars('topicrow', array(
800                  'FORUM_ID'                    => $forum_id,
801                  'TOPIC_ID'                    => $topic_id,
802                  'FIRST_POST_TIME'            => $user->format_date($row['topic_time']),
803                  'LAST_POST_SUBJECT'            => $row['topic_last_post_subject'],
804                  'LAST_POST_TIME'            => $user->format_date($row['topic_last_post_time']),
805                  'LAST_VIEW_TIME'            => $user->format_date($row['topic_last_view_time']),
806   
807                  'TOPIC_AUTHOR'                => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
808                  'TOPIC_AUTHOR_COLOUR'        => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
809                  'TOPIC_AUTHOR_FULL'            => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
810                  'U_TOPIC_AUTHOR'            => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
811   
812                  'LAST_POST_AUTHOR'            => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
813                  'LAST_POST_AUTHOR_COLOUR'    => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
814                  'LAST_POST_AUTHOR_FULL'        => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
815                  'U_LAST_POST_AUTHOR'        => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
816   
817                  'S_DELETED_TOPIC'    => (!$row['topic_id']) ? true : false,
818   
819                  'REPLIES'            => $replies,
820                  'VIEWS'                => $row['topic_views'],
821                  'TOPIC_TITLE'        => censor_text($row['topic_title']),
822                  'TOPIC_TYPE'        => $topic_type,
823                  'FORUM_NAME'        => $row['forum_name'],
824   
825                  'TOPIC_IMG_STYLE'        => $folder_img,
826                  'TOPIC_FOLDER_IMG'        => $user->img($folder_img, $folder_alt),
827                  'TOPIC_FOLDER_IMG_ALT'    => $user->lang[$folder_alt],
828                  'TOPIC_ICON_IMG'        => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
829                  'TOPIC_ICON_IMG_WIDTH'    => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
830                  'TOPIC_ICON_IMG_HEIGHT'    => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
831                  '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']) : '',
832   
833                  'S_TOPIC_TYPE'            => $row['topic_type'],
834                  'S_USER_POSTED'            => (!empty($row['topic_posted'])) ? true : false,
835                  'S_UNREAD_TOPIC'        => $unread_topic,
836   
837                  'U_NEWEST_POST'            => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;view=unread') . '#unread',
838                  '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'],
839                  'U_VIEW_TOPIC'            => $view_topic_url,
840                  'U_VIEW_FORUM'            => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
841              ));
842   
843              $pagination->generate_template_pagination(append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . "&amp;t=$topic_id"), 'topicrow.pagination', 'start', $replies + 1, $config['posts_per_page'], 1, true, true);
844          }
845      }
846  }
847