[ Index ]

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


Generated: Sun Feb 19 19:47:08 2017 Cross-referenced by PHPXref 0.7.1