[ Index ]

PHP Cross Reference of phpBB-3.3.11-deutsch

title

Body

[close]

/includes/ -> functions_mcp.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  * Functions used to generate additional URL paramters
  24  */
  25  function phpbb_module__url($mode, $module_row)
  26  {
  27      return phpbb_extra_url();
  28  }
  29  
  30  function phpbb_module_notes_url($mode, $module_row)
  31  {
  32      if ($mode == 'front')
  33      {
  34          return '';
  35      }
  36  
  37      global $user_id;
  38      return phpbb_extra_url();
  39  }
  40  
  41  function phpbb_module_warn_url($mode, $module_row)
  42  {
  43      if ($mode == 'front' || $mode == 'list')
  44      {
  45          global $forum_id;
  46          return phpbb_extra_url();
  47      }
  48  
  49      if ($mode == 'warn_post')
  50      {
  51          global $forum_id, $post_id;
  52          return phpbb_extra_url();
  53      }
  54      else
  55      {
  56          global $user_id;
  57          return phpbb_extra_url();
  58      }
  59  }
  60  
  61  function phpbb_module_main_url($mode, $module_row)
  62  {
  63      return phpbb_extra_url();
  64  }
  65  
  66  function phpbb_module_logs_url($mode, $module_row)
  67  {
  68      return phpbb_extra_url();
  69  }
  70  
  71  function phpbb_module_ban_url($mode, $module_row)
  72  {
  73      return phpbb_extra_url();
  74  }
  75  
  76  function phpbb_module_queue_url($mode, $module_row)
  77  {
  78      return phpbb_extra_url();
  79  }
  80  
  81  function phpbb_module_reports_url($mode, $module_row)
  82  {
  83      return phpbb_extra_url();
  84  }
  85  
  86  /**
  87   * Generate URL parameters for MCP modules
  88   *
  89   * @param array $additional_parameters    Array with additional parameters in format of ['key' => 'parameter_name']
  90   *
  91   * @return string                        String with URL parameters (empty string if not any)
  92   */
  93  function phpbb_extra_url($additional_parameters = [])
  94  {
  95      $url_extra = [];
  96      $url_parameters = array_merge([
  97          'f' => 'forum_id',
  98          't' => 'topic_id',
  99          'p' => 'post_id',
 100          'r' => 'report_id',
 101          'u' => 'user_id',
 102      ], $additional_parameters);
 103  
 104      foreach ($url_parameters as $key => $value)
 105      {
 106          global $$value;
 107          if (isset($$value) && $parameter = $$value)
 108          {
 109              $url_extra[] = "$key=$parameter";
 110          }
 111      }
 112  
 113      return implode('&amp;', $url_extra);
 114  }
 115  
 116  /**
 117  * Get simple topic data
 118  */
 119  function phpbb_get_topic_data($topic_ids, $acl_list = false, $read_tracking = false)
 120  {
 121      global $auth, $db, $config, $user;
 122      static $rowset = array();
 123  
 124      $topics = array();
 125  
 126      if (!count($topic_ids))
 127      {
 128          return array();
 129      }
 130  
 131      // cache might not contain read tracking info, so we can't use it if read
 132      // tracking information is requested
 133      if (!$read_tracking)
 134      {
 135          $cache_topic_ids = array_intersect($topic_ids, array_keys($rowset));
 136          $topic_ids = array_diff($topic_ids, array_keys($rowset));
 137      }
 138      else
 139      {
 140          $cache_topic_ids = array();
 141      }
 142  
 143      if (count($topic_ids))
 144      {
 145          $sql_array = array(
 146              'SELECT'    => 't.*, f.*',
 147  
 148              'FROM'        => array(
 149                  TOPICS_TABLE    => 't',
 150              ),
 151  
 152              'LEFT_JOIN'    => array(
 153                  array(
 154                      'FROM'    => array(FORUMS_TABLE => 'f'),
 155                      'ON'    => 'f.forum_id = t.forum_id'
 156                  )
 157              ),
 158  
 159              'WHERE'        => $db->sql_in_set('t.topic_id', $topic_ids)
 160          );
 161  
 162          if ($read_tracking && $config['load_db_lastread'])
 163          {
 164              $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as forum_mark_time';
 165  
 166              $sql_array['LEFT_JOIN'][] = array(
 167                  'FROM'    => array(TOPICS_TRACK_TABLE => 'tt'),
 168                  'ON'    => 'tt.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tt.topic_id'
 169              );
 170  
 171              $sql_array['LEFT_JOIN'][] = array(
 172                  'FROM'    => array(FORUMS_TRACK_TABLE => 'ft'),
 173                  'ON'    => 'ft.user_id = ' . $user->data['user_id'] . ' AND t.forum_id = ft.forum_id'
 174              );
 175          }
 176  
 177          $sql = $db->sql_build_query('SELECT', $sql_array);
 178          $result = $db->sql_query($sql);
 179  
 180          while ($row = $db->sql_fetchrow($result))
 181          {
 182              $rowset[$row['topic_id']] = $row;
 183  
 184              if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id']))
 185              {
 186                  continue;
 187              }
 188  
 189              $topics[$row['topic_id']] = $row;
 190          }
 191          $db->sql_freeresult($result);
 192      }
 193  
 194      foreach ($cache_topic_ids as $id)
 195      {
 196          if (!$acl_list || $auth->acl_gets($acl_list, $rowset[$id]['forum_id']))
 197          {
 198              $topics[$id] = $rowset[$id];
 199          }
 200      }
 201  
 202      return $topics;
 203  }
 204  
 205  /**
 206  * Get simple post data
 207  */
 208  function phpbb_get_post_data($post_ids, $acl_list = false, $read_tracking = false)
 209  {
 210      global $db, $auth, $config, $user, $phpbb_dispatcher, $phpbb_container;
 211  
 212      $rowset = array();
 213  
 214      if (!count($post_ids))
 215      {
 216          return array();
 217      }
 218  
 219      $sql_array = array(
 220          'SELECT'    => 'p.*, u.*, t.*, f.*',
 221  
 222          'FROM'        => array(
 223              USERS_TABLE        => 'u',
 224              POSTS_TABLE        => 'p',
 225              TOPICS_TABLE    => 't',
 226          ),
 227  
 228          'LEFT_JOIN'    => array(
 229              array(
 230                  'FROM'    => array(FORUMS_TABLE => 'f'),
 231                  'ON'    => 'f.forum_id = t.forum_id'
 232              )
 233          ),
 234  
 235          'WHERE'        => $db->sql_in_set('p.post_id', $post_ids) . '
 236              AND u.user_id = p.poster_id
 237              AND t.topic_id = p.topic_id',
 238      );
 239  
 240      if ($read_tracking && $config['load_db_lastread'])
 241      {
 242          $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as forum_mark_time';
 243  
 244          $sql_array['LEFT_JOIN'][] = array(
 245              'FROM'    => array(TOPICS_TRACK_TABLE => 'tt'),
 246              'ON'    => 'tt.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tt.topic_id'
 247          );
 248  
 249          $sql_array['LEFT_JOIN'][] = array(
 250              'FROM'    => array(FORUMS_TRACK_TABLE => 'ft'),
 251              'ON'    => 'ft.user_id = ' . $user->data['user_id'] . ' AND t.forum_id = ft.forum_id'
 252          );
 253      }
 254  
 255      $sql = $db->sql_build_query('SELECT', $sql_array);
 256      $result = $db->sql_query($sql);
 257      unset($sql_array);
 258  
 259      $phpbb_content_visibility = $phpbb_container->get('content.visibility');
 260  
 261      while ($row = $db->sql_fetchrow($result))
 262      {
 263          if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id']))
 264          {
 265              continue;
 266          }
 267  
 268          if (!$phpbb_content_visibility->is_visible('post', $row['forum_id'], $row))
 269          {
 270              // Moderators without the permission to approve post should at least not see them. ;)
 271              continue;
 272          }
 273  
 274          $rowset[$row['post_id']] = $row;
 275      }
 276      $db->sql_freeresult($result);
 277  
 278      /**
 279      * This event allows you to modify post data displayed in the MCP
 280      *
 281      * @event core.mcp_get_post_data_after
 282      * @var array    post_ids        Array with post ids that have been fetched
 283      * @var mixed    acl_list        Either false or an array with permission strings to check
 284      * @var bool        read_tracking    Whether or not to take last mark read time into account
 285      * @var array    rowset            The array of posts to be returned
 286      * @since 3.2.10-RC1
 287      * @since 3.3.1-RC1
 288      */
 289      $vars = [
 290          'post_ids',
 291          'acl_list',
 292          'read_tracking',
 293          'rowset',
 294      ];
 295      extract($phpbb_dispatcher->trigger_event('core.mcp_get_post_data_after', compact($vars)));
 296  
 297      return $rowset;
 298  }
 299  
 300  /**
 301  * Get simple forum data
 302  */
 303  function phpbb_get_forum_data($forum_id, $acl_list = 'f_list', $read_tracking = false)
 304  {
 305      global $auth, $db, $user, $config, $phpbb_container;
 306  
 307      $rowset = array();
 308  
 309      if (!is_array($forum_id))
 310      {
 311          $forum_id = array($forum_id);
 312      }
 313  
 314      if (!count($forum_id))
 315      {
 316          return array();
 317      }
 318  
 319      if ($read_tracking && $config['load_db_lastread'])
 320      {
 321          $read_tracking_join = ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . '
 322              AND ft.forum_id = f.forum_id)';
 323          $read_tracking_select = ', ft.mark_time';
 324      }
 325      else
 326      {
 327          $read_tracking_join = $read_tracking_select = '';
 328      }
 329  
 330      $sql = "SELECT f.* $read_tracking_select
 331          FROM " . FORUMS_TABLE . " f$read_tracking_join
 332          WHERE " . $db->sql_in_set('f.forum_id', $forum_id);
 333      $result = $db->sql_query($sql);
 334  
 335      /* @var $phpbb_content_visibility \phpbb\content_visibility */
 336      $phpbb_content_visibility = $phpbb_container->get('content.visibility');
 337  
 338      while ($row = $db->sql_fetchrow($result))
 339      {
 340          if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id']))
 341          {
 342              continue;
 343          }
 344  
 345          $row['forum_topics_approved'] = $phpbb_content_visibility->get_count('forum_topics', $row, $row['forum_id']);
 346  
 347          $rowset[$row['forum_id']] = $row;
 348      }
 349      $db->sql_freeresult($result);
 350  
 351      return $rowset;
 352  }
 353  
 354  /**
 355  * Get simple pm data
 356  */
 357  function phpbb_get_pm_data($pm_ids)
 358  {
 359      global $db;
 360  
 361      $rowset = array();
 362  
 363      if (!count($pm_ids))
 364      {
 365          return array();
 366      }
 367  
 368      $sql_array = array(
 369          'SELECT'    => 'p.*, u.*',
 370  
 371          'FROM'        => array(
 372              USERS_TABLE            => 'u',
 373              PRIVMSGS_TABLE        => 'p',
 374          ),
 375  
 376          'WHERE'        => $db->sql_in_set('p.msg_id', $pm_ids) . '
 377              AND u.user_id = p.author_id',
 378      );
 379  
 380      $sql = $db->sql_build_query('SELECT', $sql_array);
 381      $result = $db->sql_query($sql);
 382      unset($sql_array);
 383  
 384      while ($row = $db->sql_fetchrow($result))
 385      {
 386          $rowset[$row['msg_id']] = $row;
 387      }
 388      $db->sql_freeresult($result);
 389  
 390      return $rowset;
 391  }
 392  
 393  /**
 394  * sorting in mcp
 395  *
 396  * $where_sql should either be WHERE (default if ommited) or end with AND or OR
 397  *
 398  * $mode reports and reports_closed: the $where parameters uses aliases p for posts table and r for report table
 399  * $mode unapproved_posts: the $where parameters uses aliases p for posts table and t for topic table
 400  */
 401  function phpbb_mcp_sorting($mode, &$sort_days_val, &$sort_key_val, &$sort_dir_val, &$sort_by_sql_ary, &$sort_order_sql, &$total_val, $forum_id = 0, $topic_id = 0, $where_sql = 'WHERE')
 402  {
 403      global $db, $user, $auth, $template, $request, $phpbb_dispatcher;
 404  
 405      $sort_days_val = $request->variable('st', 0);
 406      $min_time = ($sort_days_val) ? time() - ($sort_days_val * 86400) : 0;
 407  
 408      switch ($mode)
 409      {
 410          case 'viewforum':
 411              $type = 'topics';
 412              $default_key = 't';
 413              $default_dir = 'd';
 414  
 415              $sql = 'SELECT COUNT(topic_id) AS total
 416                  FROM ' . TOPICS_TABLE . "
 417                  $where_sql forum_id = $forum_id
 418                      AND topic_type NOT IN (" . POST_ANNOUNCE . ', ' . POST_GLOBAL . ")
 419                      AND topic_last_post_time >= $min_time";
 420  
 421              if (!$auth->acl_get('m_approve', $forum_id))
 422              {
 423                  $sql .= ' AND topic_visibility = ' . ITEM_APPROVED;
 424              }
 425              break;
 426  
 427          case 'viewtopic':
 428              $type = 'posts';
 429              $default_key = 't';
 430              $default_dir = 'a';
 431  
 432              $sql = 'SELECT COUNT(post_id) AS total
 433                  FROM ' . POSTS_TABLE . "
 434                  $where_sql topic_id = $topic_id
 435                      AND post_time >= $min_time";
 436  
 437              if (!$auth->acl_get('m_approve', $forum_id))
 438              {
 439                  $sql .= ' AND post_visibility = ' . ITEM_APPROVED;
 440              }
 441              break;
 442  
 443          case 'unapproved_posts':
 444          case 'deleted_posts':
 445              $visibility_const = ($mode == 'unapproved_posts') ? array(ITEM_UNAPPROVED, ITEM_REAPPROVE) : ITEM_DELETED;
 446              $type = 'posts';
 447              $default_key = 't';
 448              $default_dir = 'd';
 449              $where_sql .= ($topic_id) ? ' p.topic_id = ' . $topic_id . ' AND' : '';
 450  
 451              $sql = 'SELECT COUNT(p.post_id) AS total
 452                  FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
 453                  $where_sql " . $db->sql_in_set('p.forum_id', ($forum_id) ? array($forum_id) : array_intersect(get_forum_list('f_read'), get_forum_list('m_approve'))) . '
 454                      AND ' . $db->sql_in_set('p.post_visibility', $visibility_const) .'
 455                      AND t.topic_id = p.topic_id
 456                      AND t.topic_visibility <> p.post_visibility';
 457  
 458              if ($min_time)
 459              {
 460                  $sql .= ' AND post_time >= ' . $min_time;
 461              }
 462              break;
 463  
 464          case 'unapproved_topics':
 465          case 'deleted_topics':
 466              $visibility_const = ($mode == 'unapproved_topics') ? array(ITEM_UNAPPROVED, ITEM_REAPPROVE) : ITEM_DELETED;
 467              $type = 'topics';
 468              $default_key = 't';
 469              $default_dir = 'd';
 470  
 471              $sql = 'SELECT COUNT(topic_id) AS total
 472                  FROM ' . TOPICS_TABLE . "
 473                  $where_sql " . $db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : array_intersect(get_forum_list('f_read'), get_forum_list('m_approve'))) . '
 474                      AND ' . $db->sql_in_set('topic_visibility', $visibility_const);
 475  
 476              if ($min_time)
 477              {
 478                  $sql .= ' AND topic_time >= ' . $min_time;
 479              }
 480              break;
 481  
 482          case 'pm_reports':
 483          case 'pm_reports_closed':
 484          case 'reports':
 485          case 'reports_closed':
 486              $pm = (strpos($mode, 'pm_') === 0) ? true : false;
 487  
 488              $type = ($pm) ? 'pm_reports' : 'reports';
 489              $default_key = 't';
 490              $default_dir = 'd';
 491              $limit_time_sql = ($min_time) ? "AND r.report_time >= $min_time" : '';
 492  
 493              if ($topic_id)
 494              {
 495                  $where_sql .= ' p.topic_id = ' . $topic_id . ' AND ';
 496              }
 497              else if ($forum_id)
 498              {
 499                  $where_sql .= ' p.forum_id = ' . $forum_id . ' AND ';
 500              }
 501              else if (!$pm)
 502              {
 503                  $where_sql .= ' ' . $db->sql_in_set('p.forum_id', get_forum_list(array('!f_read', '!m_report')), true, true) . ' AND ';
 504              }
 505  
 506              if ($mode == 'reports' || $mode == 'pm_reports')
 507              {
 508                  $where_sql .= ' r.report_closed = 0 AND ';
 509              }
 510              else
 511              {
 512                  $where_sql .= ' r.report_closed = 1 AND ';
 513              }
 514  
 515              if ($pm)
 516              {
 517                  $sql = 'SELECT COUNT(r.report_id) AS total
 518                      FROM ' . REPORTS_TABLE . ' r, ' . PRIVMSGS_TABLE . " p
 519                      $where_sql r.post_id = 0
 520                          AND p.msg_id = r.pm_id
 521                          $limit_time_sql";
 522              }
 523              else
 524              {
 525                  $sql = 'SELECT COUNT(r.report_id) AS total
 526                      FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . " p
 527                      $where_sql r.pm_id = 0
 528                          AND p.post_id = r.post_id
 529                          $limit_time_sql";
 530              }
 531              break;
 532  
 533          case 'viewlogs':
 534              $type = 'logs';
 535              $default_key = 't';
 536              $default_dir = 'd';
 537  
 538              $sql = 'SELECT COUNT(log_id) AS total
 539                  FROM ' . LOG_TABLE . "
 540                  $where_sql " . $db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : array_intersect(get_forum_list('f_read'), get_forum_list('m_'))) . '
 541                      AND log_time >= ' . $min_time . '
 542                      AND log_type = ' . LOG_MOD;
 543              break;
 544      }
 545  
 546      $sort_key_val = $request->variable('sk', $default_key);
 547      $sort_dir_val = $request->variable('sd', $default_dir);
 548      $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
 549  
 550      switch ($type)
 551      {
 552          case 'topics':
 553              $limit_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
 554              $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'tt' => $user->lang['TOPIC_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
 555  
 556              $sort_by_sql_ary = array('a' => 't.topic_first_poster_name', 't' => array('t.topic_last_post_time', 't.topic_last_post_id'), 'tt' => 't.topic_time', 'r' => (($auth->acl_get('m_approve', $forum_id)) ? 't.topic_posts_approved + t.topic_posts_unapproved + t.topic_posts_softdeleted' : 't.topic_posts_approved'), 's' => 't.topic_title', 'v' => 't.topic_views');
 557              $limit_time_sql = ($min_time) ? "AND t.topic_last_post_time >= $min_time" : '';
 558              break;
 559  
 560          case 'posts':
 561              $limit_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
 562              $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
 563              $sort_by_sql_ary = array('a' => 'u.username_clean', 't' => array('p.post_time', 'p.post_id'), 's' => 'p.post_subject');
 564              $limit_time_sql = ($min_time) ? "AND p.post_time >= $min_time" : '';
 565              break;
 566  
 567          case 'reports':
 568              $limit_days = array(0 => $user->lang['ALL_REPORTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
 569              $sort_by_text = array('a' => $user->lang['AUTHOR'], 'r' => $user->lang['REPORTER'], 'p' => $user->lang['POST_TIME'], 't' => $user->lang['REPORT_TIME'], 's' => $user->lang['SUBJECT']);
 570              $sort_by_sql_ary = array('a' => 'u.username_clean', 'r' => 'ru.username', 'p' => array('p.post_time', 'p.post_id'), 't' => 'r.report_time', 's' => 'p.post_subject');
 571              break;
 572  
 573          case 'pm_reports':
 574              $limit_days = array(0 => $user->lang['ALL_REPORTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
 575              $sort_by_text = array('a' => $user->lang['AUTHOR'], 'r' => $user->lang['REPORTER'], 'p' => $user->lang['POST_TIME'], 't' => $user->lang['REPORT_TIME'], 's' => $user->lang['SUBJECT']);
 576              $sort_by_sql_ary = array('a' => 'u.username_clean', 'r' => 'ru.username', 'p' => 'p.message_time', 't' => 'r.report_time', 's' => 'p.message_subject');
 577              break;
 578  
 579          case 'logs':
 580              $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
 581              $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
 582  
 583              $sort_by_sql_ary = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
 584              $limit_time_sql = ($min_time) ? "AND l.log_time >= $min_time" : '';
 585              break;
 586      }
 587  
 588      // Default total to -1 to allow editing by the event
 589      $total_val = -1;
 590  
 591      $sort_by_sql = $sort_by_sql_ary;
 592      $sort_days = $sort_days_val;
 593      $sort_dir = $sort_dir_val;
 594      $sort_key = $sort_key_val;
 595      $total = $total_val;
 596      /**
 597      * This event allows you to control the SQL query used to get the total number
 598      * of reports the user can access.
 599      *
 600      * This total is used for the pagination and for displaying the total number
 601      * of reports to the user
 602      *
 603      *
 604      * @event core.mcp_sorting_query_before
 605      * @var    string    sql                    The current SQL search string
 606      * @var    string    mode                An id related to the module(s) the user is viewing
 607      * @var    string    type                Which kind of information is this being used for displaying. Posts, topics, etc...
 608      * @var    int        forum_id            The forum id of the posts the user is trying to access, if not 0
 609      * @var    int        topic_id            The topic id of the posts the user is trying to access, if not 0
 610      * @var    int        sort_days            The max age of the oldest report to be shown, in days
 611      * @var    string    sort_key            The way the user has decided to sort the data.
 612      *                                    The valid values must be in the keys of the sort_by_* variables
 613      * @var    string    sort_dir            Either 'd' for "DESC" or 'a' for 'ASC' in the SQL query
 614      * @var    int        limit_days            The possible max ages of the oldest report for the user to choose, in days.
 615      * @var    array    sort_by_sql            SQL text (values) for the possible names of the ways of sorting data (keys).
 616      * @var    array    sort_by_text        Language text (values) for the possible names of the ways of sorting data (keys).
 617      * @var    int        min_time            Integer with the minimum post time that the user is searching for
 618      * @var    int        limit_time_sql        Time limiting options used in the SQL query.
 619      * @var    int        total                The total number of reports that exist. Only set if you want to override the result
 620      * @var    string    where_sql            Extra information included in the WHERE clause. It must end with "WHERE" or "AND" or "OR".
 621      *                                    Set to "WHERE" and set total above -1 to override the total value
 622      * @since 3.1.4-RC1
 623      */
 624      $vars = array(
 625          'sql',
 626          'mode',
 627          'type',
 628          'forum_id',
 629          'topic_id',
 630          'sort_days',
 631          'sort_key',
 632          'sort_dir',
 633          'limit_days',
 634          'sort_by_sql',
 635          'sort_by_text',
 636          'min_time',
 637          'limit_time_sql',
 638          'total',
 639          'where_sql',
 640      );
 641      extract($phpbb_dispatcher->trigger_event('core.mcp_sorting_query_before', compact($vars)));
 642      $sort_by_sql_ary = $sort_by_sql;
 643      $sort_days_val = $sort_days;
 644      $sort_key_val = $sort_key;
 645      $sort_dir_val = $sort_dir;
 646      $total_val = $total;
 647      unset($sort_by_sql);
 648      unset($sort_days);
 649      unset($sort_key);
 650      unset($sort_dir);
 651      unset($total);
 652  
 653      if (!isset($sort_by_sql_ary[$sort_key_val]))
 654      {
 655          $sort_key_val = $default_key;
 656      }
 657  
 658      $direction = ($sort_dir_val == 'd') ? 'DESC' : 'ASC';
 659  
 660      if (is_array($sort_by_sql_ary[$sort_key_val]))
 661      {
 662          $sort_order_sql = implode(' ' . $direction . ', ', $sort_by_sql_ary[$sort_key_val]) . ' ' . $direction;
 663      }
 664      else
 665      {
 666          $sort_order_sql = $sort_by_sql_ary[$sort_key_val] . ' ' . $direction;
 667      }
 668  
 669      $s_limit_days = $s_sort_key = $s_sort_dir = $sort_url = '';
 670      gen_sort_selects($limit_days, $sort_by_text, $sort_days_val, $sort_key_val, $sort_dir_val, $s_limit_days, $s_sort_key, $s_sort_dir, $sort_url);
 671  
 672      $template->assign_vars(array(
 673              'S_SELECT_SORT_DIR'        => $s_sort_dir,
 674              'S_SELECT_SORT_KEY'        => $s_sort_key,
 675              'S_SELECT_SORT_DAYS'    => $s_limit_days)
 676      );
 677  
 678      if (($sort_days_val && $mode != 'viewlogs') || in_array($mode, array('reports', 'unapproved_topics', 'unapproved_posts', 'deleted_topics', 'deleted_posts')) || $where_sql != 'WHERE')
 679      {
 680          $result = $db->sql_query($sql);
 681          $total_val = (int) $db->sql_fetchfield('total');
 682          $db->sql_freeresult($result);
 683      }
 684      else if ($total_val < -1)
 685      {
 686          $total_val = -1;
 687      }
 688  }
 689  
 690  /**
 691  * Validate ids
 692  *
 693  * @param    array    &$ids            The relevant ids to check
 694  * @param    string    $table            The table to find the ids in
 695  * @param    string    $sql_id            The ids relevant column name
 696  * @param    array    $acl_list        A list of permissions the user need to have
 697  * @param    mixed    $single_forum    Limit to one forum id (int) or the first forum found (true)
 698  *
 699  * @return    mixed    False if no ids were able to be retrieved, true if at least one id left.
 700  *                    Additionally, this value can be the forum_id assigned if $single_forum was set.
 701  *                    Therefore checking the result for with !== false is the best method.
 702  */
 703  function phpbb_check_ids(&$ids, $table, $sql_id, $acl_list = false, $single_forum = false)
 704  {
 705      global $db, $auth;
 706  
 707      if (!is_array($ids) || empty($ids))
 708      {
 709          return false;
 710      }
 711  
 712      $sql = "SELECT $sql_id, forum_id FROM $table
 713          WHERE " . $db->sql_in_set($sql_id, $ids);
 714      $result = $db->sql_query($sql);
 715  
 716      $ids = array();
 717      $forum_id = false;
 718  
 719      while ($row = $db->sql_fetchrow($result))
 720      {
 721          if ($acl_list && $row['forum_id'] && !$auth->acl_gets($acl_list, $row['forum_id']))
 722          {
 723              continue;
 724          }
 725  
 726          if ($acl_list && !$row['forum_id'] && !$auth->acl_getf_global($acl_list))
 727          {
 728              continue;
 729          }
 730  
 731          // Limit forum? If not, just assign the id.
 732          if ($single_forum === false)
 733          {
 734              $ids[] = $row[$sql_id];
 735              continue;
 736          }
 737  
 738          // Limit forum to a specific forum id?
 739          // This can get really tricky, because we do not want to create a failure on global topics. :)
 740          if ($row['forum_id'])
 741          {
 742              if ($single_forum !== true && $row['forum_id'] == (int) $single_forum)
 743              {
 744                  $forum_id = (int) $single_forum;
 745              }
 746              else if ($forum_id === false)
 747              {
 748                  $forum_id = $row['forum_id'];
 749              }
 750  
 751              if ($row['forum_id'] == $forum_id)
 752              {
 753                  $ids[] = $row[$sql_id];
 754              }
 755          }
 756          else
 757          {
 758              // Always add a global topic
 759              $ids[] = $row[$sql_id];
 760          }
 761      }
 762      $db->sql_freeresult($result);
 763  
 764      if (!count($ids))
 765      {
 766          return false;
 767      }
 768  
 769      // If forum id is false and ids populated we may have only global announcements selected (returning 0 because of (int) $forum_id)
 770  
 771      return ($single_forum === false) ? true : (int) $forum_id;
 772  }


Generated: Sat Nov 4 14:26:03 2023 Cross-referenced by PHPXref 0.7.1