[ Index ]

PHP Cross Reference of phpBB-3.3.0-deutsch

title

Body

[close]

/includes/ -> functions_display.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  /**
  15  * @ignore
  16  */
  17  if (!defined('IN_PHPBB'))
  18  {
  19      exit;
  20  }
  21  
  22  /**
  23  * Display Forums
  24  */
  25  function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
  26  {
  27      global $db, $auth, $user, $template;
  28      global $phpbb_root_path, $phpEx, $config;
  29      global $request, $phpbb_dispatcher, $phpbb_container;
  30  
  31      $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
  32      $parent_id = $visible_forums = 0;
  33      $parent_subforum_limit = false;
  34  
  35      // Mark forums read?
  36      $mark_read = $request->variable('mark', '');
  37  
  38      if ($mark_read == 'all')
  39      {
  40          $mark_read = '';
  41      }
  42  
  43      if (!$root_data)
  44      {
  45          if ($mark_read == 'forums')
  46          {
  47              $mark_read = 'all';
  48          }
  49  
  50          $root_data = array('forum_id' => 0);
  51          $sql_where = '';
  52      }
  53      else
  54      {
  55          $sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
  56      }
  57  
  58      // Handle marking everything read
  59      if ($mark_read == 'all')
  60      {
  61          $redirect = build_url(array('mark', 'hash', 'mark_time'));
  62          meta_refresh(3, $redirect);
  63  
  64          if (check_link_hash($request->variable('hash', ''), 'global'))
  65          {
  66              markread('all', false, false, $request->variable('mark_time', 0));
  67  
  68              if ($request->is_ajax())
  69              {
  70                  // Tell the ajax script what language vars and URL need to be replaced
  71                  $data = array(
  72                      'NO_UNREAD_POSTS'    => $user->lang['NO_UNREAD_POSTS'],
  73                      'UNREAD_POSTS'        => $user->lang['UNREAD_POSTS'],
  74                      'U_MARK_FORUMS'        => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}index.$phpEx", 'hash=' . generate_link_hash('global') . '&mark=forums&mark_time=' . time(), false) : '',
  75                      'MESSAGE_TITLE'        => $user->lang['INFORMATION'],
  76                      'MESSAGE_TEXT'        => $user->lang['FORUMS_MARKED']
  77                  );
  78                  $json_response = new \phpbb\json_response();
  79                  $json_response->send($data);
  80              }
  81  
  82              trigger_error(
  83                  $user->lang['FORUMS_MARKED'] . '<br /><br />' .
  84                  sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>')
  85              );
  86          }
  87          else
  88          {
  89              trigger_error(sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
  90          }
  91      }
  92  
  93      // Display list of active topics for this category?
  94      $show_active = (isset($root_data['forum_flags']) && ($root_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
  95  
  96      $sql_array = array(
  97          'SELECT'    => 'f.*',
  98          'FROM'        => array(
  99              FORUMS_TABLE        => 'f'
 100          ),
 101          'LEFT_JOIN'    => array(),
 102      );
 103  
 104      if ($config['load_db_lastread'] && $user->data['is_registered'])
 105      {
 106          $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id');
 107          $sql_array['SELECT'] .= ', ft.mark_time';
 108      }
 109      else if ($config['load_anon_lastread'] || $user->data['is_registered'])
 110      {
 111          $tracking_topics = $request->variable($config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE);
 112          $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
 113  
 114          if (!$user->data['is_registered'])
 115          {
 116              $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
 117          }
 118      }
 119  
 120      if ($show_active)
 121      {
 122          $sql_array['LEFT_JOIN'][] = array(
 123              'FROM'    => array(FORUMS_ACCESS_TABLE => 'fa'),
 124              'ON'    => "fa.forum_id = f.forum_id AND fa.session_id = '" . $db->sql_escape($user->session_id) . "'"
 125          );
 126  
 127          $sql_array['SELECT'] .= ', fa.user_id';
 128      }
 129  
 130      $sql_ary = array(
 131          'SELECT'    => $sql_array['SELECT'],
 132          'FROM'        => $sql_array['FROM'],
 133          'LEFT_JOIN'    => $sql_array['LEFT_JOIN'],
 134  
 135          'WHERE'        => $sql_where,
 136  
 137          'ORDER_BY'    => 'f.left_id',
 138      );
 139  
 140      /**
 141      * Event to modify the SQL query before the forum data is queried
 142      *
 143      * @event core.display_forums_modify_sql
 144      * @var    array    sql_ary        The SQL array to get the data of the forums
 145      * @since 3.1.0-a1
 146      */
 147      $vars = array('sql_ary');
 148      extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_sql', compact($vars)));
 149  
 150      $sql = $db->sql_build_query('SELECT', $sql_ary);
 151      $result = $db->sql_query($sql);
 152  
 153      $forum_tracking_info = $valid_categories = array();
 154      $branch_root_id = $root_data['forum_id'];
 155  
 156      /* @var $phpbb_content_visibility \phpbb\content_visibility */
 157      $phpbb_content_visibility = $phpbb_container->get('content.visibility');
 158  
 159      while ($row = $db->sql_fetchrow($result))
 160      {
 161          /**
 162          * Event to modify the data set of a forum
 163          *
 164          * This event is triggered once per forum
 165          *
 166          * @event core.display_forums_modify_row
 167          * @var    int        branch_root_id    Last top-level forum
 168          * @var    array    row                The data of the forum
 169          * @since 3.1.0-a1
 170          */
 171          $vars = array('branch_root_id', 'row');
 172          extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_row', compact($vars)));
 173  
 174          $forum_id = $row['forum_id'];
 175  
 176          // Mark forums read?
 177          if ($mark_read == 'forums')
 178          {
 179              if ($auth->acl_get('f_list', $forum_id))
 180              {
 181                  $forum_ids[] = $forum_id;
 182              }
 183  
 184              continue;
 185          }
 186  
 187          // Category with no members
 188          if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
 189          {
 190              continue;
 191          }
 192  
 193          // Skip branch
 194          if (isset($right_id))
 195          {
 196              if ($row['left_id'] < $right_id)
 197              {
 198                  continue;
 199              }
 200              unset($right_id);
 201          }
 202  
 203          if (!$auth->acl_get('f_list', $forum_id))
 204          {
 205              // if the user does not have permissions to list this forum, skip everything until next branch
 206              $right_id = $row['right_id'];
 207              continue;
 208          }
 209  
 210          if ($config['load_db_lastread'] && $user->data['is_registered'])
 211          {
 212              $forum_tracking_info[$forum_id] = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
 213          }
 214          else if ($config['load_anon_lastread'] || $user->data['is_registered'])
 215          {
 216              if (!$user->data['is_registered'])
 217              {
 218                  $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
 219              }
 220              $forum_tracking_info[$forum_id] = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
 221          }
 222  
 223          // Lets check whether there are unapproved topics/posts, so we can display an information to moderators
 224          $row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && $row['forum_topics_unapproved']) ? $forum_id : 0;
 225          $row['forum_id_unapproved_posts'] = ($auth->acl_get('m_approve', $forum_id) && $row['forum_posts_unapproved']) ? $forum_id : 0;
 226          $row['forum_posts'] = $phpbb_content_visibility->get_count('forum_posts', $row, $forum_id);
 227          $row['forum_topics'] = $phpbb_content_visibility->get_count('forum_topics', $row, $forum_id);
 228  
 229          // Display active topics from this forum?
 230          if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS))
 231          {
 232              if (!isset($active_forum_ary['forum_topics']))
 233              {
 234                  $active_forum_ary['forum_topics'] = 0;
 235              }
 236  
 237              if (!isset($active_forum_ary['forum_posts']))
 238              {
 239                  $active_forum_ary['forum_posts'] = 0;
 240              }
 241  
 242              $active_forum_ary['forum_id'][]        = $forum_id;
 243              $active_forum_ary['enable_icons'][]    = $row['enable_icons'];
 244              $active_forum_ary['forum_topics']    += $row['forum_topics'];
 245              $active_forum_ary['forum_posts']    += $row['forum_posts'];
 246  
 247              // If this is a passworded forum we do not show active topics from it if the user is not authorised to view it...
 248              if ($row['forum_password'] && $row['user_id'] != $user->data['user_id'])
 249              {
 250                  $active_forum_ary['exclude_forum_id'][] = $forum_id;
 251              }
 252          }
 253  
 254          // Fill list of categories with forums
 255          if (isset($forum_rows[$row['parent_id']]))
 256          {
 257              $valid_categories[$row['parent_id']] = true;
 258          }
 259  
 260          //
 261          if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id)
 262          {
 263              if ($row['forum_type'] != FORUM_CAT)
 264              {
 265                  $forum_ids_moderator[] = (int) $forum_id;
 266              }
 267  
 268              // Direct child of current branch
 269              $parent_id = $forum_id;
 270              $parent_subforum_limit = $row['display_subforum_limit'];
 271              $forum_rows[$forum_id] = $row;
 272  
 273              if ($row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id'])
 274              {
 275                  $branch_root_id = $forum_id;
 276              }
 277              $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
 278              $forum_rows[$parent_id]['forum_password_last_post'] = $row['forum_password'];
 279              $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
 280          }
 281          else if ($row['forum_type'] != FORUM_CAT)
 282          {
 283              $subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index'] && (!$parent_subforum_limit || $parent_id == $row['parent_id']));
 284              $subforums[$parent_id][$forum_id]['name'] = $row['forum_name'];
 285              $subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
 286              $subforums[$parent_id][$forum_id]['children'] = array();
 287              $subforums[$parent_id][$forum_id]['type'] = $row['forum_type'];
 288  
 289              if (isset($subforums[$parent_id][$row['parent_id']]) && !$row['display_on_index'])
 290              {
 291                  $subforums[$parent_id][$row['parent_id']]['children'][] = $forum_id;
 292              }
 293  
 294              if (!$forum_rows[$parent_id]['forum_id_unapproved_topics'] && $row['forum_id_unapproved_topics'])
 295              {
 296                  $forum_rows[$parent_id]['forum_id_unapproved_topics'] = $forum_id;
 297              }
 298  
 299              if (!$forum_rows[$parent_id]['forum_id_unapproved_posts'] && $row['forum_id_unapproved_posts'])
 300              {
 301                  $forum_rows[$parent_id]['forum_id_unapproved_posts'] = $forum_id;
 302              }
 303  
 304              $forum_rows[$parent_id]['forum_topics'] += $row['forum_topics'];
 305  
 306              // Do not list redirects in LINK Forums as Posts.
 307              if ($row['forum_type'] != FORUM_LINK)
 308              {
 309                  $forum_rows[$parent_id]['forum_posts'] += $row['forum_posts'];
 310              }
 311  
 312              if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time'])
 313              {
 314                  $forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
 315                  $forum_rows[$parent_id]['forum_last_post_subject'] = $row['forum_last_post_subject'];
 316                  $forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
 317                  $forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
 318                  $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
 319                  $forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour'];
 320                  $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
 321                  $forum_rows[$parent_id]['forum_password_last_post'] = $row['forum_password'];
 322              }
 323          }
 324  
 325          /**
 326          * Event to modify the forum rows data set
 327          *
 328          * This event is triggered once per forum
 329          *
 330          * @event core.display_forums_modify_forum_rows
 331          * @var    array    forum_rows        Data array of all forums we display
 332          * @var    array    subforums        Data array of all subforums we display
 333          * @var    int        branch_root_id    Current top-level forum
 334          * @var    int        parent_id        Current parent forum
 335          * @var    array    row                The data of the forum
 336          * @since 3.1.0-a1
 337          */
 338          $vars = array('forum_rows', 'subforums', 'branch_root_id', 'parent_id', 'row');
 339          extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_forum_rows', compact($vars)));
 340      }
 341      $db->sql_freeresult($result);
 342  
 343      // Handle marking posts
 344      if ($mark_read == 'forums')
 345      {
 346          $redirect = build_url(array('mark', 'hash', 'mark_time'));
 347          $token = $request->variable('hash', '');
 348          if (check_link_hash($token, 'global'))
 349          {
 350              markread('topics', $forum_ids, false, $request->variable('mark_time', 0));
 351              $message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
 352              meta_refresh(3, $redirect);
 353  
 354              if ($request->is_ajax())
 355              {
 356                  // Tell the ajax script what language vars and URL need to be replaced
 357                  $data = array(
 358                      'NO_UNREAD_POSTS'    => $user->lang['NO_UNREAD_POSTS'],
 359                      'UNREAD_POSTS'        => $user->lang['UNREAD_POSTS'],
 360                      'U_MARK_FORUMS'        => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . '&f=' . $root_data['forum_id'] . '&mark=forums&mark_time=' . time(), false) : '',
 361                      'MESSAGE_TITLE'        => $user->lang['INFORMATION'],
 362                      'MESSAGE_TEXT'        => $user->lang['FORUMS_MARKED']
 363                  );
 364                  $json_response = new \phpbb\json_response();
 365                  $json_response->send($data);
 366              }
 367  
 368              trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . $message);
 369          }
 370          else
 371          {
 372              $message = sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
 373              meta_refresh(3, $redirect);
 374              trigger_error($message);
 375          }
 376  
 377      }
 378  
 379      // Grab moderators ... if necessary
 380      if ($display_moderators)
 381      {
 382          if ($return_moderators)
 383          {
 384              $forum_ids_moderator[] = $root_data['forum_id'];
 385          }
 386          get_moderators($forum_moderators, $forum_ids_moderator);
 387      }
 388  
 389      /**
 390      * Event to perform additional actions before the forum list is being generated
 391      *
 392      * @event core.display_forums_before
 393      * @var    array    active_forum_ary    Array with forum data to display active topics
 394      * @var    bool    display_moderators    Flag indicating if we display forum moderators
 395      * @var    array    forum_moderators    Array with forum moderators list
 396      * @var    array    forum_rows            Data array of all forums we display
 397      * @var    bool    return_moderators    Flag indicating if moderators list should be returned
 398      * @var    array    root_data            Array with the root forum data
 399      * @since 3.1.4-RC1
 400      */
 401      $vars = array(
 402          'active_forum_ary',
 403          'display_moderators',
 404          'forum_moderators',
 405          'forum_rows',
 406          'return_moderators',
 407          'root_data',
 408      );
 409      extract($phpbb_dispatcher->trigger_event('core.display_forums_before', compact($vars)));
 410  
 411      // Used to tell whatever we have to create a dummy category or not.
 412      $last_catless = true;
 413      foreach ($forum_rows as $row)
 414      {
 415          // Category
 416          if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT)
 417          {
 418              // Do not display categories without any forums to display
 419              if (!isset($valid_categories[$row['forum_id']]))
 420              {
 421                  continue;
 422              }
 423  
 424              $cat_row = array(
 425                  'S_IS_CAT'                => true,
 426                  'FORUM_ID'                => $row['forum_id'],
 427                  'FORUM_NAME'            => $row['forum_name'],
 428                  'FORUM_DESC'            => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
 429                  'FORUM_FOLDER_IMG'        => '',
 430                  'FORUM_FOLDER_IMG_SRC'    => '',
 431                  'FORUM_IMAGE'            => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang['FORUM_CAT'] . '" />' : '',
 432                  'FORUM_IMAGE_SRC'        => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
 433                  'U_VIEWFORUM'            => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']),
 434              );
 435  
 436              /**
 437              * Modify the template data block of the 'category'
 438              *
 439              * This event is triggered once per 'category'
 440              *
 441              * @event core.display_forums_modify_category_template_vars
 442              * @var    array    cat_row            Template data of the 'category'
 443              * @var    bool    last_catless    The flag indicating whether the last forum had a parent category
 444              * @var    array    root_data        Array with the root forum data
 445              * @var    array    row                The data of the 'category'
 446              * @since 3.1.0-RC4
 447              * @changed 3.1.7-RC1 Removed undefined catless variable
 448              */
 449              $vars = array(
 450                  'cat_row',
 451                  'last_catless',
 452                  'root_data',
 453                  'row',
 454              );
 455              extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_category_template_vars', compact($vars)));
 456  
 457              $template->assign_block_vars('forumrow', $cat_row);
 458  
 459              continue;
 460          }
 461  
 462          $visible_forums++;
 463          $forum_id = $row['forum_id'];
 464  
 465          $forum_unread = (isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id]) ? true : false;
 466  
 467          $folder_image = $folder_alt = $l_subforums = '';
 468          $subforums_list = array();
 469  
 470          // Generate list of subforums if we need to
 471          if (isset($subforums[$forum_id]))
 472          {
 473              foreach ($subforums[$forum_id] as $subforum_id => $subforum_row)
 474              {
 475                  $subforum_unread = (isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id]) ? true : false;
 476  
 477                  if (!$subforum_unread && !empty($subforum_row['children']))
 478                  {
 479                      foreach ($subforum_row['children'] as $child_id)
 480                      {
 481                          if (isset($forum_tracking_info[$child_id]) && $subforums[$forum_id][$child_id]['orig_forum_last_post_time'] > $forum_tracking_info[$child_id])
 482                          {
 483                              // Once we found an unread child forum, we can drop out of this loop
 484                              $subforum_unread = true;
 485                              break;
 486                          }
 487                      }
 488                  }
 489  
 490                  if ($subforum_row['display'] && $subforum_row['name'])
 491                  {
 492                      $subforums_list[] = array(
 493                          'link'        => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $subforum_id),
 494                          'name'        => $subforum_row['name'],
 495                          'unread'    => $subforum_unread,
 496                          'type'        => $subforum_row['type'],
 497                      );
 498                  }
 499                  else
 500                  {
 501                      unset($subforums[$forum_id][$subforum_id]);
 502                  }
 503  
 504                  // If one subforum is unread the forum gets unread too...
 505                  if ($subforum_unread)
 506                  {
 507                      $forum_unread = true;
 508                  }
 509              }
 510  
 511              $l_subforums = (count($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'];
 512              $folder_image = ($forum_unread) ? 'forum_unread_subforum' : 'forum_read_subforum';
 513          }
 514          else
 515          {
 516              switch ($row['forum_type'])
 517              {
 518                  case FORUM_POST:
 519                      $folder_image = ($forum_unread) ? 'forum_unread' : 'forum_read';
 520                  break;
 521  
 522                  case FORUM_LINK:
 523                      $folder_image = 'forum_link';
 524                  break;
 525              }
 526          }
 527  
 528          // Which folder should we display?
 529          if ($row['forum_status'] == ITEM_LOCKED)
 530          {
 531              $folder_image = ($forum_unread) ? 'forum_unread_locked' : 'forum_read_locked';
 532              $folder_alt = 'FORUM_LOCKED';
 533          }
 534          else
 535          {
 536              $folder_alt = ($forum_unread) ? 'UNREAD_POSTS' : 'NO_UNREAD_POSTS';
 537          }
 538  
 539          // Create last post link information, if appropriate
 540          if ($row['forum_last_post_id'])
 541          {
 542              if ($row['forum_password_last_post'] === '' && $auth->acl_gets('f_read', 'f_list_topics', $row['forum_id_last_post']))
 543              {
 544                  $last_post_subject = utf8_decode_ncr(censor_text($row['forum_last_post_subject']));
 545  
 546                  $last_post_subject_truncated = truncate_string($last_post_subject, 30, 255, false, $user->lang['ELLIPSIS']);
 547              }
 548              else
 549              {
 550                  $last_post_subject = $last_post_subject_truncated = '';
 551              }
 552              $last_post_time = $user->format_date($row['forum_last_post_time']);
 553              $last_post_time_rfc3339 = gmdate(DATE_RFC3339, $row['forum_last_post_time']);
 554              $last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&amp;p=' . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
 555          }
 556          else
 557          {
 558              $last_post_subject = $last_post_time = $last_post_time_rfc3339 = $last_post_url = $last_post_subject_truncated = '';
 559          }
 560  
 561          // Output moderator listing ... if applicable
 562          $l_moderator = $moderators_list = '';
 563          if ($display_moderators && !empty($forum_moderators[$forum_id]))
 564          {
 565              $l_moderator = (count($forum_moderators[$forum_id]) == 1) ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
 566              $moderators_list = implode($user->lang['COMMA_SEPARATOR'], $forum_moderators[$forum_id]);
 567          }
 568  
 569          $l_post_click_count = ($row['forum_type'] == FORUM_LINK) ? 'CLICKS' : 'POSTS';
 570          $post_click_count = ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? $row['forum_posts'] : '';
 571  
 572          $s_subforums_list = $subforums_row = array();
 573          foreach ($subforums_list as $subforum)
 574          {
 575              $s_subforums_list[] = '<a href="' . $subforum['link'] . '" class="subforum ' . (($subforum['unread']) ? 'unread' : 'read') . '" title="' . (($subforum['unread']) ? $user->lang['UNREAD_POSTS'] : $user->lang['NO_UNREAD_POSTS']) . '">' . $subforum['name'] . '</a>';
 576              $subforums_row[] = array(
 577                  'U_SUBFORUM'    => $subforum['link'],
 578                  'SUBFORUM_NAME'    => $subforum['name'],
 579                  'S_UNREAD'        => $subforum['unread'],
 580                  'IS_LINK'        => $subforum['type'] == FORUM_LINK,
 581              );
 582          }
 583          $s_subforums_list = (string) implode($user->lang['COMMA_SEPARATOR'], $s_subforums_list);
 584          $catless = ($row['parent_id'] == $root_data['forum_id']) ? true : false;
 585  
 586          if ($row['forum_type'] != FORUM_LINK)
 587          {
 588              $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
 589          }
 590          else
 591          {
 592              // If the forum is a link and we count redirects we need to visit it
 593              // If the forum is having a password or no read access we do not expose the link, but instead handle it in viewforum
 594              if (($row['forum_flags'] & FORUM_FLAG_LINK_TRACK) || $row['forum_password'] || !$auth->acl_get('f_read', $forum_id))
 595              {
 596                  $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
 597              }
 598              else
 599              {
 600                  $u_viewforum = $row['forum_link'];
 601              }
 602          }
 603  
 604          $forum_row = array(
 605              'S_IS_CAT'            => false,
 606              'S_NO_CAT'            => $catless && !$last_catless,
 607              'S_IS_LINK'            => ($row['forum_type'] == FORUM_LINK) ? true : false,
 608              'S_UNREAD_FORUM'    => $forum_unread,
 609              'S_AUTH_READ'        => $auth->acl_get('f_read', $row['forum_id']),
 610              'S_LOCKED_FORUM'    => ($row['forum_status'] == ITEM_LOCKED) ? true : false,
 611              'S_LIST_SUBFORUMS'    => ($row['display_subforum_list']) ? true : false,
 612              'S_SUBFORUMS'        => (count($subforums_list)) ? true : false,
 613              'S_DISPLAY_SUBJECT'    =>    ($last_post_subject !== '' && $config['display_last_subject']) ? true : false,
 614              'S_FEED_ENABLED'    => ($config['feed_forum'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $row['forum_options']) && $row['forum_type'] == FORUM_POST) ? true : false,
 615  
 616              'FORUM_ID'                => $row['forum_id'],
 617              'FORUM_NAME'            => $row['forum_name'],
 618              'FORUM_DESC'            => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
 619              'TOPICS'                => $row['forum_topics'],
 620              $l_post_click_count        => $post_click_count,
 621              'FORUM_IMG_STYLE'        => $folder_image,
 622              'FORUM_FOLDER_IMG'        => $user->img($folder_image, $folder_alt),
 623              'FORUM_FOLDER_IMG_ALT'    => isset($user->lang[$folder_alt]) ? $user->lang[$folder_alt] : '',
 624              'FORUM_IMAGE'            => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
 625              'FORUM_IMAGE_SRC'        => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
 626              'LAST_POST_SUBJECT'        => $last_post_subject,
 627              'LAST_POST_SUBJECT_TRUNCATED'    => $last_post_subject_truncated,
 628              'LAST_POST_TIME'        => $last_post_time,
 629              'LAST_POST_TIME_RFC3339'=> $last_post_time_rfc3339,
 630              'LAST_POSTER'            => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
 631              'LAST_POSTER_COLOUR'    => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
 632              'LAST_POSTER_FULL'        => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
 633              'MODERATORS'            => $moderators_list,
 634              'SUBFORUMS'                => $s_subforums_list,
 635  
 636              'L_SUBFORUM_STR'        => $l_subforums,
 637              'L_MODERATOR_STR'        => $l_moderator,
 638  
 639              'U_UNAPPROVED_TOPICS'    => ($row['forum_id_unapproved_topics']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=unapproved_topics&amp;f=' . $row['forum_id_unapproved_topics']) : '',
 640              'U_UNAPPROVED_POSTS'    => ($row['forum_id_unapproved_posts']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=unapproved_posts&amp;f=' . $row['forum_id_unapproved_posts']) : '',
 641              'U_VIEWFORUM'        => $u_viewforum,
 642              'U_LAST_POSTER'        => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
 643              'U_LAST_POST'        => $last_post_url,
 644          );
 645  
 646          /**
 647          * Modify the template data block of the forum
 648          *
 649          * This event is triggered once per forum
 650          *
 651          * @event core.display_forums_modify_template_vars
 652          * @var    array    forum_row        Template data of the forum
 653          * @var    array    row                The data of the forum
 654          * @var    array    subforums_row    Template data of subforums
 655          * @since 3.1.0-a1
 656          * @changed 3.1.0-b5 Added var subforums_row
 657          */
 658          $vars = array('forum_row', 'row', 'subforums_row');
 659          extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_template_vars', compact($vars)));
 660  
 661          $template->assign_block_vars('forumrow', $forum_row);
 662  
 663          // Assign subforums loop for style authors
 664          $template->assign_block_vars_array('forumrow.subforum', $subforums_row);
 665  
 666          /**
 667          * Modify and/or assign additional template data for the forum
 668          * after forumrow loop has been assigned. This can be used
 669          * to create additional forumrow subloops in extensions.
 670          *
 671          * This event is triggered once per forum
 672          *
 673          * @event core.display_forums_add_template_data
 674          * @var    array    forum_row        Template data of the forum
 675          * @var    array    row                The data of the forum
 676          * @var    array    subforums_list    The data of subforums
 677          * @var    array    subforums_row    Template data of subforums
 678          * @var    bool    catless            The flag indicating whether a forum has a parent category
 679          * @since 3.1.0-b5
 680          */
 681          $vars = array(
 682              'forum_row',
 683              'row',
 684              'subforums_list',
 685              'subforums_row',
 686              'catless',
 687          );
 688          extract($phpbb_dispatcher->trigger_event('core.display_forums_add_template_data', compact($vars)));
 689  
 690          $last_catless = $catless;
 691      }
 692  
 693      $template->assign_vars(array(
 694          'U_MARK_FORUMS'        => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . '&amp;f=' . $root_data['forum_id'] . '&amp;mark=forums&amp;mark_time=' . time()) : '',
 695          'S_HAS_SUBFORUM'    => ($visible_forums) ? true : false,
 696          'L_SUBFORUM'        => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'],
 697          'LAST_POST_IMG'        => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
 698          'UNAPPROVED_IMG'    => $user->img('icon_topic_unapproved', 'TOPICS_UNAPPROVED'),
 699          'UNAPPROVED_POST_IMG'    => $user->img('icon_topic_unapproved', 'POSTS_UNAPPROVED_FORUM'),
 700      ));
 701  
 702      /**
 703      * Event to perform additional actions after the forum list has been generated
 704      *
 705      * @event core.display_forums_after
 706      * @var    array    active_forum_ary    Array with forum data to display active topics
 707      * @var    bool    display_moderators    Flag indicating if we display forum moderators
 708      * @var    array    forum_moderators    Array with forum moderators list
 709      * @var    array    forum_rows            Data array of all forums we display
 710      * @var    bool    return_moderators    Flag indicating if moderators list should be returned
 711      * @var    array    root_data            Array with the root forum data
 712      * @since 3.1.0-RC5
 713      */
 714      $vars = array(
 715          'active_forum_ary',
 716          'display_moderators',
 717          'forum_moderators',
 718          'forum_rows',
 719          'return_moderators',
 720          'root_data',
 721      );
 722      extract($phpbb_dispatcher->trigger_event('core.display_forums_after', compact($vars)));
 723  
 724      if ($return_moderators)
 725      {
 726          return array($active_forum_ary, $forum_moderators);
 727      }
 728  
 729      return array($active_forum_ary, array());
 730  }
 731  
 732  /**
 733  * Create forum rules for given forum
 734  */
 735  function generate_forum_rules(&$forum_data)
 736  {
 737      if ($forum_data['forum_rules'])
 738      {
 739          $forum_data['forum_rules'] = generate_text_for_display($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options']);
 740      }
 741  
 742      if (!$forum_data['forum_rules'] && !$forum_data['forum_rules_link'])
 743      {
 744          return;
 745      }
 746  
 747      global $template;
 748  
 749      $template->assign_vars(array(
 750          'S_FORUM_RULES'    => true,
 751          'U_FORUM_RULES'    => $forum_data['forum_rules_link'],
 752          'FORUM_RULES'    => $forum_data['forum_rules'])
 753      );
 754  }
 755  
 756  /**
 757  * Create forum navigation links for given forum, create parent
 758  * list if currently null, assign basic forum info to template
 759  */
 760  function generate_forum_nav(&$forum_data_ary)
 761  {
 762      global $template, $auth, $config;
 763      global $phpEx, $phpbb_root_path, $phpbb_dispatcher;
 764  
 765      if (!$auth->acl_get('f_list', $forum_data_ary['forum_id']))
 766      {
 767          return;
 768      }
 769  
 770      $navlinks_parents = $forum_template_data = array();
 771  
 772      // Get forum parents
 773      $forum_parents = get_forum_parents($forum_data_ary);
 774  
 775      $microdata_attr = 'data-forum-id';
 776  
 777      // Build navigation links
 778      if (!empty($forum_parents))
 779      {
 780          foreach ($forum_parents as $parent_forum_id => $parent_data)
 781          {
 782              list($parent_name, $parent_type) = array_values($parent_data);
 783  
 784              // Skip this parent if the user does not have the permission to view it
 785              if (!$auth->acl_get('f_list', $parent_forum_id))
 786              {
 787                  continue;
 788              }
 789  
 790              $navlinks_parents[] = array(
 791                  'S_IS_CAT'            => ($parent_type == FORUM_CAT) ? true : false,
 792                  'S_IS_LINK'            => ($parent_type == FORUM_LINK) ? true : false,
 793                  'S_IS_POST'            => ($parent_type == FORUM_POST) ? true : false,
 794                  'BREADCRUMB_NAME'    => $parent_name,
 795                  'FORUM_ID'            => $parent_forum_id,
 796                  'MICRODATA'            => $microdata_attr . '="' . $parent_forum_id . '"',
 797                  'U_BREADCRUMB'        => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $parent_forum_id),
 798              );
 799          }
 800      }
 801  
 802      $navlinks = array(
 803          'S_IS_CAT'            => ($forum_data_ary['forum_type'] == FORUM_CAT) ? true : false,
 804          'S_IS_LINK'            => ($forum_data_ary['forum_type'] == FORUM_LINK) ? true : false,
 805          'S_IS_POST'            => ($forum_data_ary['forum_type'] == FORUM_POST) ? true : false,
 806          'BREADCRUMB_NAME'    => $forum_data_ary['forum_name'],
 807          'FORUM_ID'            => $forum_data_ary['forum_id'],
 808          'MICRODATA'            => $microdata_attr . '="' . $forum_data_ary['forum_id'] . '"',
 809          'U_BREADCRUMB'        => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_data_ary['forum_id']),
 810      );
 811  
 812      $forum_template_data = array(
 813          'FORUM_ID'         => $forum_data_ary['forum_id'],
 814          'FORUM_NAME'    => $forum_data_ary['forum_name'],
 815          'FORUM_DESC'    => generate_text_for_display($forum_data_ary['forum_desc'], $forum_data_ary['forum_desc_uid'], $forum_data_ary['forum_desc_bitfield'], $forum_data_ary['forum_desc_options']),
 816  
 817          'S_ENABLE_FEEDS_FORUM'    => ($config['feed_forum'] && $forum_data_ary['forum_type'] == FORUM_POST && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $forum_data_ary['forum_options'])) ? true : false,
 818      );
 819  
 820      $forum_data = $forum_data_ary;
 821      /**
 822      * Event to modify the navlinks text
 823      *
 824      * @event core.generate_forum_nav
 825      * @var    array    forum_data                Array with the forum data
 826      * @var    array    forum_template_data        Array with generic forum template data
 827      * @var    string    microdata_attr            The microdata attribute
 828      * @var    array    navlinks_parents        Array with the forum parents navlinks data
 829      * @var    array    navlinks                Array with the forum navlinks data
 830      * @since 3.1.5-RC1
 831      */
 832      $vars = array(
 833          'forum_data',
 834          'forum_template_data',
 835          'microdata_attr',
 836          'navlinks_parents',
 837          'navlinks',
 838      );
 839      extract($phpbb_dispatcher->trigger_event('core.generate_forum_nav', compact($vars)));
 840      $forum_data_ary = $forum_data;
 841      unset($forum_data);
 842  
 843      $template->assign_block_vars_array('navlinks', $navlinks_parents);
 844      $template->assign_block_vars('navlinks', $navlinks);
 845      $template->assign_vars($forum_template_data);
 846  
 847      return;
 848  }
 849  
 850  /**
 851  * Returns forum parents as an array. Get them from forum_data if available, or update the database otherwise
 852  */
 853  function get_forum_parents(&$forum_data)
 854  {
 855      global $db;
 856  
 857      $forum_parents = array();
 858  
 859      if ($forum_data['parent_id'] > 0)
 860      {
 861          if ($forum_data['forum_parents'] == '')
 862          {
 863              $sql = 'SELECT forum_id, forum_name, forum_type
 864                  FROM ' . FORUMS_TABLE . '
 865                  WHERE left_id < ' . $forum_data['left_id'] . '
 866                      AND right_id > ' . $forum_data['right_id'] . '
 867                  ORDER BY left_id ASC';
 868              $result = $db->sql_query($sql);
 869  
 870              while ($row = $db->sql_fetchrow($result))
 871              {
 872                  $forum_parents[$row['forum_id']] = array($row['forum_name'], (int) $row['forum_type']);
 873              }
 874              $db->sql_freeresult($result);
 875  
 876              $forum_data['forum_parents'] = serialize($forum_parents);
 877  
 878              $sql = 'UPDATE ' . FORUMS_TABLE . "
 879                  SET forum_parents = '" . $db->sql_escape($forum_data['forum_parents']) . "'
 880                  WHERE parent_id = " . $forum_data['parent_id'];
 881              $db->sql_query($sql);
 882          }
 883          else
 884          {
 885              $forum_parents = unserialize($forum_data['forum_parents']);
 886          }
 887      }
 888  
 889      return $forum_parents;
 890  }
 891  
 892  /**
 893  * Obtain list of moderators of each forum
 894  */
 895  function get_moderators(&$forum_moderators, $forum_id = false)
 896  {
 897      global $db, $phpbb_root_path, $phpEx, $user, $auth;
 898      global $phpbb_container;
 899  
 900      $forum_id_ary = array();
 901  
 902      if ($forum_id !== false)
 903      {
 904          if (!is_array($forum_id))
 905          {
 906              $forum_id = array($forum_id);
 907          }
 908  
 909          // Exchange key/value pair to be able to faster check for the forum id existence
 910          $forum_id_ary = array_flip($forum_id);
 911      }
 912  
 913      $sql_array = array(
 914          'SELECT'    => 'm.*, u.user_colour, g.group_colour, g.group_type',
 915  
 916          'FROM'        => array(
 917              MODERATOR_CACHE_TABLE    => 'm',
 918          ),
 919  
 920          'LEFT_JOIN'    => array(
 921              array(
 922                  'FROM'    => array(USERS_TABLE => 'u'),
 923                  'ON'    => 'm.user_id = u.user_id',
 924              ),
 925              array(
 926                  'FROM'    => array(GROUPS_TABLE => 'g'),
 927                  'ON'    => 'm.group_id = g.group_id',
 928              ),
 929          ),
 930  
 931          'WHERE'        => 'm.display_on_index = 1',
 932      );
 933  
 934      /** @var \phpbb\group\helper $group_helper */
 935      $group_helper = $phpbb_container->get('group_helper');
 936  
 937      // We query every forum here because for caching we should not have any parameter.
 938      $sql = $db->sql_build_query('SELECT', $sql_array);
 939      $result = $db->sql_query($sql, 3600);
 940  
 941      while ($row = $db->sql_fetchrow($result))
 942      {
 943          $f_id = (int) $row['forum_id'];
 944  
 945          if (!isset($forum_id_ary[$f_id]))
 946          {
 947              continue;
 948          }
 949  
 950          if (!empty($row['user_id']))
 951          {
 952              $forum_moderators[$f_id][] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
 953          }
 954          else
 955          {
 956              $group_name = $group_helper->get_name($row['group_name']);
 957  
 958              if ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_viewprofile'))
 959              {
 960                  $forum_moderators[$f_id][] = '<span' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . '>' . $group_name . '</span>';
 961              }
 962              else
 963              {
 964                  $forum_moderators[$f_id][] = '<a' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . ' href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id']) . '">' . $group_name . '</a>';
 965              }
 966          }
 967      }
 968      $db->sql_freeresult($result);
 969  
 970      return;
 971  }
 972  
 973  /**
 974  * User authorisation levels output
 975  *
 976  * @param    string    $mode            Can be forum or topic. Not in use at the moment.
 977  * @param    int        $forum_id        The current forum the user is in.
 978  * @param    int        $forum_status    The forums status bit.
 979  */
 980  function gen_forum_auth_level($mode, $forum_id, $forum_status)
 981  {
 982      global $template, $auth, $user, $config;
 983  
 984      $locked = ($forum_status == ITEM_LOCKED && !$auth->acl_get('m_edit', $forum_id)) ? true : false;
 985  
 986      $rules = array(
 987          ($auth->acl_get('f_post', $forum_id) && !$locked) ? $user->lang['RULES_POST_CAN'] : $user->lang['RULES_POST_CANNOT'],
 988          ($auth->acl_get('f_reply', $forum_id) && !$locked) ? $user->lang['RULES_REPLY_CAN'] : $user->lang['RULES_REPLY_CANNOT'],
 989          ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id) && !$locked) ? $user->lang['RULES_EDIT_CAN'] : $user->lang['RULES_EDIT_CANNOT'],
 990          ($user->data['is_registered'] && ($auth->acl_gets('f_delete', 'm_delete', $forum_id) || $auth->acl_gets('f_softdelete', 'm_softdelete', $forum_id)) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'],
 991      );
 992  
 993      if ($config['allow_attachments'])
 994      {
 995          $rules[] = ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && !$locked) ? $user->lang['RULES_ATTACH_CAN'] : $user->lang['RULES_ATTACH_CANNOT'];
 996      }
 997  
 998      foreach ($rules as $rule)
 999      {
1000          $template->assign_block_vars('rules', array('RULE' => $rule));
1001      }
1002  
1003      return;
1004  }
1005  
1006  /**
1007  * Generate topic status
1008  */
1009  function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$folder_alt, &$topic_type)
1010  {
1011      global $user, $config;
1012  
1013      if ($topic_row['topic_status'] == ITEM_MOVED)
1014      {
1015          $topic_type = $user->lang['VIEW_TOPIC_MOVED'];
1016          $folder_img = 'topic_moved';
1017          $folder_alt = 'TOPIC_MOVED';
1018      }
1019      else
1020      {
1021          switch ($topic_row['topic_type'])
1022          {
1023              case POST_GLOBAL:
1024                  $topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
1025                  $folder = 'global_read';
1026                  $folder_new = 'global_unread';
1027              break;
1028  
1029              case POST_ANNOUNCE:
1030                  $topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT'];
1031                  $folder = 'announce_read';
1032                  $folder_new = 'announce_unread';
1033              break;
1034  
1035              case POST_STICKY:
1036                  $topic_type = $user->lang['VIEW_TOPIC_STICKY'];
1037                  $folder = 'sticky_read';
1038                  $folder_new = 'sticky_unread';
1039              break;
1040  
1041              default:
1042                  $topic_type = '';
1043                  $folder = 'topic_read';
1044                  $folder_new = 'topic_unread';
1045  
1046                  // Hot topic threshold is for posts in a topic, which is replies + the first post. ;)
1047                  if ($config['hot_threshold'] && ($replies + 1) >= $config['hot_threshold'] && $topic_row['topic_status'] != ITEM_LOCKED)
1048                  {
1049                      $folder .= '_hot';
1050                      $folder_new .= '_hot';
1051                  }
1052              break;
1053          }
1054  
1055          if ($topic_row['topic_status'] == ITEM_LOCKED)
1056          {
1057              $topic_type = $user->lang['VIEW_TOPIC_LOCKED'];
1058              $folder .= '_locked';
1059              $folder_new .= '_locked';
1060          }
1061  
1062          $folder_img = ($unread_topic) ? $folder_new : $folder;
1063          $folder_alt = ($unread_topic) ? 'UNREAD_POSTS' : (($topic_row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_UNREAD_POSTS');
1064  
1065          // Posted image?
1066          if (!empty($topic_row['topic_posted']) && $topic_row['topic_posted'])
1067          {
1068              $folder_img .= '_mine';
1069          }
1070      }
1071  
1072      if ($topic_row['poll_start'] && $topic_row['topic_status'] != ITEM_MOVED)
1073      {
1074          $topic_type = $user->lang['VIEW_TOPIC_POLL'];
1075      }
1076  }
1077  
1078  /**
1079  * Assign/Build custom bbcodes for display in screens supporting using of bbcodes
1080  * The custom bbcodes buttons will be placed within the template block 'custom_tags'
1081  */
1082  function display_custom_bbcodes()
1083  {
1084      global $db, $template, $user, $phpbb_dispatcher;
1085  
1086      // Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)
1087      $num_predefined_bbcodes = NUM_PREDEFINED_BBCODES;
1088  
1089      $sql_ary = array(
1090          'SELECT'    => 'b.bbcode_id, b.bbcode_tag, b.bbcode_helpline',
1091          'FROM'        => array(BBCODES_TABLE => 'b'),
1092          'WHERE'        => 'b.display_on_posting = 1',
1093          'ORDER_BY'    => 'b.bbcode_tag',
1094      );
1095  
1096      /**
1097      * Event to modify the SQL query before custom bbcode data is queried
1098      *
1099      * @event core.display_custom_bbcodes_modify_sql
1100      * @var    array    sql_ary                    The SQL array to get the bbcode data
1101      * @var    int        num_predefined_bbcodes    The number of predefined core bbcodes
1102      *                                        (multiplied by factor of 2)
1103      * @since 3.1.0-a3
1104      */
1105      $vars = array('sql_ary', 'num_predefined_bbcodes');
1106      extract($phpbb_dispatcher->trigger_event('core.display_custom_bbcodes_modify_sql', compact($vars)));
1107  
1108      $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));
1109  
1110      $i = 0;
1111      while ($row = $db->sql_fetchrow($result))
1112      {
1113          // If the helpline is defined within the language file, we will use the localised version, else just use the database entry...
1114          if (isset($user->lang[strtoupper($row['bbcode_helpline'])]))
1115          {
1116              $row['bbcode_helpline'] = $user->lang[strtoupper($row['bbcode_helpline'])];
1117          }
1118  
1119          $custom_tags = array(
1120              'BBCODE_NAME'        => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'",
1121              'BBCODE_ID'            => $num_predefined_bbcodes + ($i * 2),
1122              'BBCODE_TAG'        => $row['bbcode_tag'],
1123              'BBCODE_TAG_CLEAN'    => str_replace('=', '-', $row['bbcode_tag']),
1124              'BBCODE_HELPLINE'    => $row['bbcode_helpline'],
1125          );
1126  
1127          /**
1128          * Event to modify the template data block of a custom bbcode
1129          *
1130          * This event is triggered once per bbcode
1131          *
1132          * @event core.display_custom_bbcodes_modify_row
1133          * @var    array    custom_tags        Template data of the bbcode
1134          * @var    array    row                The data of the bbcode
1135          * @since 3.1.0-a1
1136          */
1137          $vars = array('custom_tags', 'row');
1138          extract($phpbb_dispatcher->trigger_event('core.display_custom_bbcodes_modify_row', compact($vars)));
1139  
1140          $template->assign_block_vars('custom_tags', $custom_tags);
1141  
1142          $i++;
1143      }
1144      $db->sql_freeresult($result);
1145  
1146      /**
1147      * Display custom bbcodes
1148      *
1149      * @event core.display_custom_bbcodes
1150      * @since 3.1.0-a1
1151      */
1152      $phpbb_dispatcher->dispatch('core.display_custom_bbcodes');
1153  }
1154  
1155  /**
1156  * Display user activity (action forum/topic)
1157  */
1158  function display_user_activity(&$userdata_ary)
1159  {
1160      global $auth, $template, $db, $user, $config;
1161      global $phpbb_root_path, $phpEx;
1162      global $phpbb_container, $phpbb_dispatcher;
1163  
1164      // Do not display user activity for users having too many posts...
1165      $limit = $config['load_user_activity_limit'];
1166      if ($userdata_ary['user_posts'] > $limit && $limit != 0)
1167      {
1168          return;
1169      }
1170  
1171      $forum_ary = array();
1172  
1173      $forum_read_ary = $auth->acl_getf('f_read');
1174      foreach ($forum_read_ary as $forum_id => $allowed)
1175      {
1176          if ($allowed['f_read'])
1177          {
1178              $forum_ary[] = (int) $forum_id;
1179          }
1180      }
1181  
1182      $forum_ary = array_diff($forum_ary, $user->get_passworded_forums());
1183  
1184      $active_f_row = $active_t_row = array();
1185      if (!empty($forum_ary))
1186      {
1187          /* @var $phpbb_content_visibility \phpbb\content_visibility */
1188          $phpbb_content_visibility = $phpbb_container->get('content.visibility');
1189  
1190          // Obtain active forum
1191          $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts
1192              FROM ' . POSTS_TABLE . '
1193              WHERE poster_id = ' . $userdata_ary['user_id'] . '
1194                  AND post_postcount = 1
1195                  AND ' . $phpbb_content_visibility->get_forums_visibility_sql('post', $forum_ary) . '
1196              GROUP BY forum_id
1197              ORDER BY num_posts DESC';
1198          $result = $db->sql_query_limit($sql, 1);
1199          $active_f_row = $db->sql_fetchrow($result);
1200          $db->sql_freeresult($result);
1201  
1202          if (!empty($active_f_row))
1203          {
1204              $sql = 'SELECT forum_name
1205                  FROM ' . FORUMS_TABLE . '
1206                  WHERE forum_id = ' . $active_f_row['forum_id'];
1207              $result = $db->sql_query($sql, 3600);
1208              $active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name');
1209              $db->sql_freeresult($result);
1210          }
1211  
1212          // Obtain active topic
1213          $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts
1214              FROM ' . POSTS_TABLE . '
1215              WHERE poster_id = ' . $userdata_ary['user_id'] . '
1216                  AND post_postcount = 1
1217                  AND ' . $phpbb_content_visibility->get_forums_visibility_sql('post', $forum_ary) . '
1218              GROUP BY topic_id
1219              ORDER BY num_posts DESC';
1220          $result = $db->sql_query_limit($sql, 1);
1221          $active_t_row = $db->sql_fetchrow($result);
1222          $db->sql_freeresult($result);
1223  
1224          if (!empty($active_t_row))
1225          {
1226              $sql = 'SELECT topic_title
1227                  FROM ' . TOPICS_TABLE . '
1228                  WHERE topic_id = ' . $active_t_row['topic_id'];
1229              $result = $db->sql_query($sql);
1230              $active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title');
1231              $db->sql_freeresult($result);
1232          }
1233      }
1234  
1235      $userdata = $userdata_ary;
1236      $show_user_activity = true;
1237      /**
1238      * Alter list of forums and topics to display as active
1239      *
1240      * @event core.display_user_activity_modify_actives
1241      * @var    array    userdata                        User's data
1242      * @var    array    active_f_row                    List of active forums
1243      * @var    array    active_t_row                    List of active posts
1244      * @var    bool    show_user_activity                Show user forum and topic activity
1245      * @since 3.1.0-RC3
1246      * @changed 3.2.5-RC1 Added show_user_activity into event
1247      */
1248      $vars = array('userdata', 'active_f_row', 'active_t_row', 'show_user_activity');
1249      extract($phpbb_dispatcher->trigger_event('core.display_user_activity_modify_actives', compact($vars)));
1250      $userdata_ary = $userdata;
1251      unset($userdata);
1252  
1253      $userdata_ary['active_t_row'] = $active_t_row;
1254      $userdata_ary['active_f_row'] = $active_f_row;
1255  
1256      $active_f_name = $active_f_id = $active_f_count = $active_f_pct = '';
1257      if (!empty($active_f_row['num_posts']))
1258      {
1259          $active_f_name = $active_f_row['forum_name'];
1260          $active_f_id = $active_f_row['forum_id'];
1261          $active_f_count = $active_f_row['num_posts'];
1262          $active_f_pct = ($userdata_ary['user_posts']) ? ($active_f_count / $userdata_ary['user_posts']) * 100 : 0;
1263      }
1264  
1265      $active_t_name = $active_t_id = $active_t_count = $active_t_pct = '';
1266      if (!empty($active_t_row['num_posts']))
1267      {
1268          $active_t_name = $active_t_row['topic_title'];
1269          $active_t_id = $active_t_row['topic_id'];
1270          $active_t_count = $active_t_row['num_posts'];
1271          $active_t_pct = ($userdata_ary['user_posts']) ? ($active_t_count / $userdata_ary['user_posts']) * 100 : 0;
1272      }
1273  
1274      $l_active_pct = ($userdata_ary['user_id'] != ANONYMOUS && $userdata_ary['user_id'] == $user->data['user_id']) ? $user->lang['POST_PCT_ACTIVE_OWN'] : $user->lang['POST_PCT_ACTIVE'];
1275  
1276      $template->assign_vars(array(
1277          'ACTIVE_FORUM'            => $active_f_name,
1278          'ACTIVE_FORUM_POSTS'    => $user->lang('USER_POSTS', (int) $active_f_count),
1279          'ACTIVE_FORUM_PCT'        => sprintf($l_active_pct, $active_f_pct),
1280          'ACTIVE_TOPIC'            => censor_text($active_t_name),
1281          'ACTIVE_TOPIC_POSTS'    => $user->lang('USER_POSTS', (int) $active_t_count),
1282          'ACTIVE_TOPIC_PCT'        => sprintf($l_active_pct, $active_t_pct),
1283          'U_ACTIVE_FORUM'        => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $active_f_id),
1284          'U_ACTIVE_TOPIC'        => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $active_t_id),
1285          'S_SHOW_ACTIVITY'        => $show_user_activity)
1286      );
1287  }
1288  
1289  /**
1290  * Topic and forum watching common code
1291  */
1292  function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, $notify_status = 'unset', $start = 0, $item_title = '')
1293  {
1294      global $db, $user, $phpEx, $start, $phpbb_root_path;
1295      global $request;
1296  
1297      $table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE : TOPICS_WATCH_TABLE;
1298      $where_sql = ($mode == 'forum') ? 'forum_id' : 'topic_id';
1299      $match_id = ($mode == 'forum') ? $forum_id : $topic_id;
1300      $u_url = "uid={$user->data['user_id']}";
1301      $u_url .= ($mode == 'forum') ? '&amp;f' : '&amp;f=' . $forum_id . '&amp;t';
1302      $is_watching = 0;
1303  
1304      // Is user watching this topic?
1305      if ($user_id != ANONYMOUS)
1306      {
1307          $can_watch = true;
1308  
1309          if ($notify_status == 'unset')
1310          {
1311              $sql = "SELECT notify_status
1312                  FROM $table_sql
1313                  WHERE $where_sql = $match_id
1314                      AND user_id = $user_id";
1315              $result = $db->sql_query($sql);
1316  
1317              $notify_status = ($row = $db->sql_fetchrow($result)) ? $row['notify_status'] : NULL;
1318              $db->sql_freeresult($result);
1319          }
1320  
1321          if (!is_null($notify_status) && $notify_status !== '')
1322          {
1323              if (isset($_GET['unwatch']))
1324              {
1325                  $uid = $request->variable('uid', 0);
1326                  $token = $request->variable('hash', '');
1327  
1328                  if ($token && check_link_hash($token, "{$mode}_$match_id") || confirm_box(true))
1329                  {
1330                      if ($uid != $user_id || $request->variable('unwatch', '', false, \phpbb\request\request_interface::GET) != $mode)
1331                      {
1332                          $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
1333                          $message = $user->lang['ERR_UNWATCHING'];
1334  
1335                          if (!$request->is_ajax())
1336                          {
1337                              $message .= '<br /><br />' . $user->lang('RETURN_' . strtoupper($mode), '<a href="' . $redirect_url . '">', '</a>');
1338                          }
1339                          trigger_error($message);
1340                      }
1341  
1342                      $sql = 'DELETE FROM ' . $table_sql . "
1343                          WHERE $where_sql = $match_id
1344                              AND user_id = $user_id";
1345                      $db->sql_query($sql);
1346  
1347                      $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
1348                      $message = $user->lang['NOT_WATCHING_' . strtoupper($mode)];
1349  
1350                      if (!$request->is_ajax())
1351                      {
1352                          $message .= '<br /><br />' . $user->lang('RETURN_' . strtoupper($mode), '<a href="' . $redirect_url . '">', '</a>');
1353                      }
1354                      meta_refresh(3, $redirect_url);
1355                      trigger_error($message);
1356                  }
1357                  else
1358                  {
1359                      $s_hidden_fields = array(
1360                          'uid'        => $user->data['user_id'],
1361                          'unwatch'    => $mode,
1362                          'start'        => $start,
1363                          'f'            => $forum_id,
1364                      );
1365                      if ($mode != 'forum')
1366                      {
1367                          $s_hidden_fields['t'] = $topic_id;
1368                      }
1369  
1370                      if ($item_title == '')
1371                      {
1372                          $confirm_box_message = 'UNWATCH_' . strtoupper($mode);
1373                      }
1374                      else
1375                      {
1376                          $confirm_box_message = $user->lang('UNWATCH_' . strtoupper($mode) . '_DETAILED', $item_title);
1377                      }
1378                      confirm_box(false, $confirm_box_message, build_hidden_fields($s_hidden_fields));
1379                  }
1380              }
1381              else
1382              {
1383                  $is_watching = true;
1384  
1385                  if ($notify_status != NOTIFY_YES)
1386                  {
1387                      $sql = 'UPDATE ' . $table_sql . "
1388                          SET notify_status = " . NOTIFY_YES . "
1389                          WHERE $where_sql = $match_id
1390                              AND user_id = $user_id";
1391                      $db->sql_query($sql);
1392                  }
1393              }
1394          }
1395          else
1396          {
1397              if (isset($_GET['watch']))
1398              {
1399                  $uid = $request->variable('uid', 0);
1400                  $token = $request->variable('hash', '');
1401  
1402                  if ($token && check_link_hash($token, "{$mode}_$match_id") || confirm_box(true))
1403                  {
1404                      if ($uid != $user_id || $request->variable('watch', '', false, \phpbb\request\request_interface::GET) != $mode)
1405                      {
1406                          $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
1407                          $message = $user->lang['ERR_WATCHING'];
1408  
1409                          if (!$request->is_ajax())
1410                          {
1411                              $message .= '<br /><br />' . $user->lang('RETURN_' . strtoupper($mode), '<a href="' . $redirect_url . '">', '</a>');
1412                          }
1413                          trigger_error($message);
1414                      }
1415  
1416                      $is_watching = true;
1417  
1418                      $sql = 'INSERT INTO ' . $table_sql . " (user_id, $where_sql, notify_status)
1419                          VALUES ($user_id, $match_id, " . NOTIFY_YES . ')';
1420                      $db->sql_query($sql);
1421  
1422                      $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
1423                      $message = $user->lang['ARE_WATCHING_' . strtoupper($mode)];
1424  
1425                      if (!$request->is_ajax())
1426                      {
1427                          $message .= '<br /><br />' . $user->lang('RETURN_' . strtoupper($mode), '<a href="' . $redirect_url . '">', '</a>');
1428                      }
1429                      meta_refresh(3, $redirect_url);
1430                      trigger_error($message);
1431                  }
1432                  else
1433                  {
1434                      $s_hidden_fields = array(
1435                          'uid'        => $user->data['user_id'],
1436                          'watch'        => $mode,
1437                          'start'        => $start,
1438                          'f'            => $forum_id,
1439                      );
1440                      if ($mode != 'forum')
1441                      {
1442                          $s_hidden_fields['t'] = $topic_id;
1443                      }
1444  
1445                      $confirm_box_message = (($item_title == '') ? 'WATCH_' . strtoupper($mode) : $user->lang('WATCH_' . strtoupper($mode) . '_DETAILED', $item_title));
1446                      confirm_box(false, $confirm_box_message, build_hidden_fields($s_hidden_fields));
1447                  }
1448              }
1449              else
1450              {
1451                  $is_watching = 0;
1452              }
1453          }
1454      }
1455      else
1456      {
1457          if ((isset($_GET['unwatch']) && $request->variable('unwatch', '', false, \phpbb\request\request_interface::GET) == $mode) ||
1458              (isset($_GET['watch']) && $request->variable('watch', '', false, \phpbb\request\request_interface::GET) == $mode))
1459          {
1460              login_box();
1461          }
1462          else
1463          {
1464              $can_watch = 0;
1465              $is_watching = 0;
1466          }
1467      }
1468  
1469      if ($can_watch)
1470      {
1471          $s_watching['link'] = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;" . (($is_watching) ? 'unwatch' : 'watch') . "=$mode&amp;start=$start&amp;hash=" . generate_link_hash("{$mode}_$match_id"));
1472          $s_watching['link_toggle'] = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;" . ((!$is_watching) ? 'unwatch' : 'watch') . "=$mode&amp;start=$start&amp;hash=" . generate_link_hash("{$mode}_$match_id"));
1473          $s_watching['title'] = $user->lang[(($is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)];
1474          $s_watching['title_toggle'] = $user->lang[((!$is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)];
1475          $s_watching['is_watching'] = $is_watching;
1476      }
1477  
1478      return;
1479  }
1480  
1481  /**
1482  * Get user rank title and image
1483  *
1484  * @param array $user_data the current stored users data
1485  * @param int $user_posts the users number of posts
1486  *
1487  * @return array An associative array containing the rank title (title), the rank image as full img tag (img) and the rank image source (img_src)
1488  *
1489  * Note: since we do not want to break backwards-compatibility, this function will only properly assign ranks to guests if you call it for them with user_posts == false
1490  */
1491  function phpbb_get_user_rank($user_data, $user_posts)
1492  {
1493      global $ranks, $config, $phpbb_root_path, $phpbb_path_helper, $phpbb_dispatcher;
1494  
1495      $user_rank_data = array(
1496          'title'        => null,
1497          'img'        => null,
1498          'img_src'    => null,
1499      );
1500  
1501      /**
1502      * Preparing a user's rank before displaying
1503      *
1504      * @event core.modify_user_rank
1505      * @var    array    user_data        Array with user's data
1506      * @var    int        user_posts        User_posts to change
1507      * @since 3.1.0-RC4
1508      */
1509  
1510      $vars = array('user_data', 'user_posts');
1511      extract($phpbb_dispatcher->trigger_event('core.modify_user_rank', compact($vars)));
1512  
1513      if (empty($ranks))
1514      {
1515          global $cache;
1516          $ranks = $cache->obtain_ranks();
1517      }
1518  
1519      if (!empty($user_data['user_rank']))
1520      {
1521  
1522          $user_rank_data['title'] = (isset($ranks['special'][$user_data['user_rank']]['rank_title'])) ? $ranks['special'][$user_data['user_rank']]['rank_title'] : '';
1523  
1524          $user_rank_data['img_src'] = (!empty($ranks['special'][$user_data['user_rank']]['rank_image'])) ? $phpbb_path_helper->update_web_root_path($phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_data['user_rank']]['rank_image']) : '';
1525  
1526          $user_rank_data['img'] = (!empty($ranks['special'][$user_data['user_rank']]['rank_image'])) ? '<img src="' . $user_rank_data['img_src'] . '" alt="' . $ranks['special'][$user_data['user_rank']]['rank_title'] . '" title="' . $ranks['special'][$user_data['user_rank']]['rank_title'] . '" />' : '';
1527      }
1528      else if ($user_posts !== false)
1529      {
1530          if (!empty($ranks['normal']))
1531          {
1532              foreach ($ranks['normal'] as $rank)
1533              {
1534                  if ($user_posts >= $rank['rank_min'])
1535                  {
1536                      $user_rank_data['title'] = $rank['rank_title'];
1537                      $user_rank_data['img_src'] = (!empty($rank['rank_image'])) ? $phpbb_path_helper->update_web_root_path($phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image']) : '';
1538                      $user_rank_data['img'] = (!empty($rank['rank_image'])) ? '<img src="' . $user_rank_data['img_src'] . '" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" />' : '';
1539                      break;
1540                  }
1541              }
1542          }
1543      }
1544  
1545      /**
1546      * Modify a user's rank before displaying
1547      *
1548      * @event core.get_user_rank_after
1549      * @var    array    user_data        Array with user's data
1550      * @var    int        user_posts        User_posts to change
1551      * @var    array    user_rank_data    User rank data
1552      * @since 3.1.11-RC1
1553      */
1554  
1555      $vars = array(
1556          'user_data',
1557          'user_posts',
1558          'user_rank_data',
1559      );
1560      extract($phpbb_dispatcher->trigger_event('core.get_user_rank_after', compact($vars)));
1561  
1562      return $user_rank_data;
1563  }
1564  
1565  /**
1566  * Prepare profile data
1567  */
1568  function phpbb_show_profile($data, $user_notes_enabled = false, $warn_user_enabled = false, $check_can_receive_pm = true)
1569  {
1570      global $config, $auth, $user, $phpEx, $phpbb_root_path, $phpbb_dispatcher;
1571  
1572      $username = $data['username'];
1573      $user_id = $data['user_id'];
1574  
1575      $user_rank_data = phpbb_get_user_rank($data, (($user_id == ANONYMOUS) ? false : $data['user_posts']));
1576  
1577      if ((!empty($data['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_user'))
1578      {
1579          $email = ($config['board_email_form'] && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&amp;u=' . $user_id) : (($config['board_hide_emails'] && !$auth->acl_get('a_user')) ? '' : 'mailto:' . $data['user_email']);
1580      }
1581      else
1582      {
1583          $email = '';
1584      }
1585  
1586      if ($config['load_onlinetrack'])
1587      {
1588          $update_time = $config['load_online_time'] * 60;
1589          $online = (time() - $update_time < $data['session_time'] && ((isset($data['session_viewonline']) && $data['session_viewonline']) || $auth->acl_get('u_viewonline'))) ? true : false;
1590      }
1591      else
1592      {
1593          $online = false;
1594      }
1595  
1596      if ($data['user_allow_viewonline'] || $auth->acl_get('u_viewonline'))
1597      {
1598          $last_active = (!empty($data['session_time'])) ? $data['session_time'] : $data['user_lastvisit'];
1599      }
1600      else
1601      {
1602          $last_active = '';
1603      }
1604  
1605      $age = '';
1606  
1607      if ($config['allow_birthdays'] && $data['user_birthday'])
1608      {
1609          list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $data['user_birthday']));
1610  
1611          if ($bday_year)
1612          {
1613              $now = $user->create_datetime();
1614              $now = phpbb_gmgetdate($now->getTimestamp() + $now->getOffset());
1615  
1616              $diff = $now['mon'] - $bday_month;
1617              if ($diff == 0)
1618              {
1619                  $diff = ($now['mday'] - $bday_day < 0) ? 1 : 0;
1620              }
1621              else
1622              {
1623                  $diff = ($diff < 0) ? 1 : 0;
1624              }
1625  
1626              $age = max(0, (int) ($now['year'] - $bday_year - $diff));
1627          }
1628      }
1629  
1630      if (!function_exists('phpbb_get_banned_user_ids'))
1631      {
1632          include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
1633      }
1634  
1635      // Can this user receive a Private Message?
1636      $can_receive_pm = $check_can_receive_pm && (
1637          // They must be a "normal" user
1638          $data['user_type'] != USER_IGNORE &&
1639  
1640          // They must not be deactivated by the administrator
1641          ($data['user_type'] != USER_INACTIVE || $data['user_inactive_reason'] != INACTIVE_MANUAL) &&
1642  
1643          // They must be able to read PMs
1644          count($auth->acl_get_list($user_id, 'u_readpm')) &&
1645  
1646          // They must not be permanently banned
1647          !count(phpbb_get_banned_user_ids($user_id, false)) &&
1648  
1649          // They must allow users to contact via PM
1650          (($auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')) || $data['user_allow_pm'])
1651      );
1652  
1653      // Dump it out to the template
1654      $template_data = array(
1655          'AGE'            => $age,
1656          'RANK_TITLE'    => $user_rank_data['title'],
1657          'JOINED'        => $user->format_date($data['user_regdate']),
1658          'LAST_ACTIVE'    => (empty($last_active)) ? ' - ' : $user->format_date($last_active),
1659          'POSTS'            => ($data['user_posts']) ? $data['user_posts'] : 0,
1660          'WARNINGS'        => isset($data['user_warnings']) ? $data['user_warnings'] : 0,
1661  
1662          'USERNAME_FULL'        => get_username_string('full', $user_id, $username, $data['user_colour']),
1663          'USERNAME'            => get_username_string('username', $user_id, $username, $data['user_colour']),
1664          'USER_COLOR'        => get_username_string('colour', $user_id, $username, $data['user_colour']),
1665          'U_VIEW_PROFILE'    => get_username_string('profile', $user_id, $username, $data['user_colour']),
1666  
1667          'A_USERNAME'        => addslashes(get_username_string('username', $user_id, $username, $data['user_colour'])),
1668  
1669          'AVATAR_IMG'        => phpbb_get_user_avatar($data),
1670          'ONLINE_IMG'        => (!$config['load_onlinetrack']) ? '' : (($online) ? $user->img('icon_user_online', 'ONLINE') : $user->img('icon_user_offline', 'OFFLINE')),
1671          'S_ONLINE'            => ($config['load_onlinetrack'] && $online) ? true : false,
1672          'RANK_IMG'            => $user_rank_data['img'],
1673          'RANK_IMG_SRC'        => $user_rank_data['img_src'],
1674          'S_JABBER_ENABLED'    => ($config['jab_enable']) ? true : false,
1675  
1676          'S_WARNINGS'    => ($auth->acl_getf_global('m_') || $auth->acl_get('m_warn')) ? true : false,
1677  
1678          'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id=$user_id&amp;sr=posts") : '',
1679          'U_NOTES'        => ($user_notes_enabled && $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $user_id, true, $user->session_id) : '',
1680          'U_WARN'        => ($warn_user_enabled && $auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&amp;mode=warn_user&amp;u=' . $user_id, true, $user->session_id) : '',
1681          'U_PM'            => ($config['allow_privmsg'] && $auth->acl_get('u_sendpm') && $can_receive_pm) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=compose&amp;u=' . $user_id) : '',
1682          'U_EMAIL'        => $email,
1683          'U_JABBER'        => ($data['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&amp;action=jabber&amp;u=' . $user_id) : '',
1684  
1685          'USER_JABBER'        => ($config['jab_enable']) ? $data['user_jabber'] : '',
1686          'USER_JABBER_IMG'    => ($config['jab_enable'] && $data['user_jabber']) ? $user->img('icon_contact_jabber', $data['user_jabber']) : '',
1687  
1688          'L_SEND_EMAIL_USER' => $user->lang('SEND_EMAIL_USER', $username),
1689          'L_CONTACT_USER'    => $user->lang('CONTACT_USER', $username),
1690          'L_VIEWING_PROFILE' => $user->lang('VIEWING_PROFILE', $username),
1691      );
1692  
1693      /**
1694      * Preparing a user's data before displaying it in profile and memberlist
1695      *
1696      * @event core.memberlist_prepare_profile_data
1697      * @var    array    data                Array with user's data
1698      * @var    array    template_data        Template array with user's data
1699      * @since 3.1.0-a1
1700      */
1701      $vars = array('data', 'template_data');
1702      extract($phpbb_dispatcher->trigger_event('core.memberlist_prepare_profile_data', compact($vars)));
1703  
1704      return $template_data;
1705  }
1706  
1707  function phpbb_sort_last_active($first, $second)
1708  {
1709      global $id_cache, $sort_dir;
1710  
1711      $lesser_than = ($sort_dir === 'd') ? -1 : 1;
1712  
1713      if (isset($id_cache[$first]['group_leader']) && $id_cache[$first]['group_leader'] && (!isset($id_cache[$second]['group_leader']) || !$id_cache[$second]['group_leader']))
1714      {
1715          return -1;
1716      }
1717      else if (isset($id_cache[$second]['group_leader']) && (!isset($id_cache[$first]['group_leader']) || !$id_cache[$first]['group_leader']) && $id_cache[$second]['group_leader'])
1718      {
1719          return 1;
1720      }
1721      else
1722      {
1723          return $lesser_than * (int) ($id_cache[$first]['last_visit'] - $id_cache[$second]['last_visit']);
1724      }
1725  }


Generated: Tue Apr 7 19:44:41 2020 Cross-referenced by PHPXref 0.7.1