[ Index ]

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


Generated: Sun Feb 19 19:52:41 2017 Cross-referenced by PHPXref 0.7.1