[ Index ]

PHP Cross Reference of phpBB-3.2.0-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      /* @var $phpbb_content_visibility \phpbb\content_visibility */
 305      $phpbb_content_visibility = $phpbb_container->get('content.visibility');
 306  
 307      while ($row = $db->sql_fetchrow($result))
 308      {
 309          if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id']))
 310          {
 311              continue;
 312          }
 313  
 314          $row['forum_topics_approved'] = $phpbb_content_visibility->get_count('forum_topics', $row, $row['forum_id']);
 315  
 316          $rowset[$row['forum_id']] = $row;
 317      }
 318      $db->sql_freeresult($result);
 319  
 320      return $rowset;
 321  }
 322  
 323  /**
 324  * Get simple pm data
 325  */
 326  function phpbb_get_pm_data($pm_ids)
 327  {
 328      global $db;
 329  
 330      $rowset = array();
 331  
 332      if (!sizeof($pm_ids))
 333      {
 334          return array();
 335      }
 336  
 337      $sql_array = array(
 338          'SELECT'    => 'p.*, u.*',
 339  
 340          'FROM'        => array(
 341              USERS_TABLE            => 'u',
 342              PRIVMSGS_TABLE        => 'p',
 343          ),
 344  
 345          'WHERE'        => $db->sql_in_set('p.msg_id', $pm_ids) . '
 346              AND u.user_id = p.author_id',
 347      );
 348  
 349      $sql = $db->sql_build_query('SELECT', $sql_array);
 350      $result = $db->sql_query($sql);
 351      unset($sql_array);
 352  
 353      while ($row = $db->sql_fetchrow($result))
 354      {
 355          $rowset[$row['msg_id']] = $row;
 356      }
 357      $db->sql_freeresult($result);
 358  
 359      return $rowset;
 360  }
 361  
 362  /**
 363  * sorting in mcp
 364  *
 365  * @param string $where_sql should either be WHERE (default if ommited) or end with AND or OR
 366  *
 367  * $mode reports and reports_closed: the $where parameters uses aliases p for posts table and r for report table
 368  * $mode unapproved_posts: the $where parameters uses aliases p for posts table and t for topic table
 369  */
 370  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')
 371  {
 372      global $db, $user, $auth, $template, $request, $phpbb_dispatcher;
 373  
 374      $sort_days_val = $request->variable('st', 0);
 375      $min_time = ($sort_days_val) ? time() - ($sort_days_val * 86400) : 0;
 376  
 377      switch ($mode)
 378      {
 379          case 'viewforum':
 380              $type = 'topics';
 381              $default_key = 't';
 382              $default_dir = 'd';
 383  
 384              $sql = 'SELECT COUNT(topic_id) AS total
 385                  FROM ' . TOPICS_TABLE . "
 386                  $where_sql forum_id = $forum_id
 387                      AND topic_type NOT IN (" . POST_ANNOUNCE . ', ' . POST_GLOBAL . ")
 388                      AND topic_last_post_time >= $min_time";
 389  
 390              if (!$auth->acl_get('m_approve', $forum_id))
 391              {
 392                  $sql .= ' AND topic_visibility = ' . ITEM_APPROVED;
 393              }
 394              break;
 395  
 396          case 'viewtopic':
 397              $type = 'posts';
 398              $default_key = 't';
 399              $default_dir = 'a';
 400  
 401              $sql = 'SELECT COUNT(post_id) AS total
 402                  FROM ' . POSTS_TABLE . "
 403                  $where_sql topic_id = $topic_id
 404                      AND post_time >= $min_time";
 405  
 406              if (!$auth->acl_get('m_approve', $forum_id))
 407              {
 408                  $sql .= ' AND post_visibility = ' . ITEM_APPROVED;
 409              }
 410              break;
 411  
 412          case 'unapproved_posts':
 413          case 'deleted_posts':
 414              $visibility_const = ($mode == 'unapproved_posts') ? array(ITEM_UNAPPROVED, ITEM_REAPPROVE) : ITEM_DELETED;
 415              $type = 'posts';
 416              $default_key = 't';
 417              $default_dir = 'd';
 418              $where_sql .= ($topic_id) ? ' p.topic_id = ' . $topic_id . ' AND' : '';
 419  
 420              $sql = 'SELECT COUNT(p.post_id) AS total
 421                  FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
 422                  $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'))) . '
 423                      AND ' . $db->sql_in_set('p.post_visibility', $visibility_const) .'
 424                      AND t.topic_id = p.topic_id
 425                      AND t.topic_visibility <> p.post_visibility';
 426  
 427              if ($min_time)
 428              {
 429                  $sql .= ' AND post_time >= ' . $min_time;
 430              }
 431              break;
 432  
 433          case 'unapproved_topics':
 434          case 'deleted_topics':
 435              $visibility_const = ($mode == 'unapproved_topics') ? array(ITEM_UNAPPROVED, ITEM_REAPPROVE) : ITEM_DELETED;
 436              $type = 'topics';
 437              $default_key = 't';
 438              $default_dir = 'd';
 439  
 440              $sql = 'SELECT COUNT(topic_id) AS total
 441                  FROM ' . TOPICS_TABLE . "
 442                  $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'))) . '
 443                      AND ' . $db->sql_in_set('topic_visibility', $visibility_const);
 444  
 445              if ($min_time)
 446              {
 447                  $sql .= ' AND topic_time >= ' . $min_time;
 448              }
 449              break;
 450  
 451          case 'pm_reports':
 452          case 'pm_reports_closed':
 453          case 'reports':
 454          case 'reports_closed':
 455              $pm = (strpos($mode, 'pm_') === 0) ? true : false;
 456  
 457              $type = ($pm) ? 'pm_reports' : 'reports';
 458              $default_key = 't';
 459              $default_dir = 'd';
 460              $limit_time_sql = ($min_time) ? "AND r.report_time >= $min_time" : '';
 461  
 462              if ($topic_id)
 463              {
 464                  $where_sql .= ' p.topic_id = ' . $topic_id . ' AND ';
 465              }
 466              else if ($forum_id)
 467              {
 468                  $where_sql .= ' p.forum_id = ' . $forum_id . ' AND ';
 469              }
 470              else if (!$pm)
 471              {
 472                  $where_sql .= ' ' . $db->sql_in_set('p.forum_id', get_forum_list(array('!f_read', '!m_report')), true, true) . ' AND ';
 473              }
 474  
 475              if ($mode == 'reports' || $mode == 'pm_reports')
 476              {
 477                  $where_sql .= ' r.report_closed = 0 AND ';
 478              }
 479              else
 480              {
 481                  $where_sql .= ' r.report_closed = 1 AND ';
 482              }
 483  
 484              if ($pm)
 485              {
 486                  $sql = 'SELECT COUNT(r.report_id) AS total
 487                      FROM ' . REPORTS_TABLE . ' r, ' . PRIVMSGS_TABLE . " p
 488                      $where_sql r.post_id = 0
 489                          AND p.msg_id = r.pm_id
 490                          $limit_time_sql";
 491              }
 492              else
 493              {
 494                  $sql = 'SELECT COUNT(r.report_id) AS total
 495                      FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . " p
 496                      $where_sql r.pm_id = 0
 497                          AND p.post_id = r.post_id
 498                          $limit_time_sql";
 499              }
 500              break;
 501  
 502          case 'viewlogs':
 503              $type = 'logs';
 504              $default_key = 't';
 505              $default_dir = 'd';
 506  
 507              $sql = 'SELECT COUNT(log_id) AS total
 508                  FROM ' . LOG_TABLE . "
 509                  $where_sql " . $db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : array_intersect(get_forum_list('f_read'), get_forum_list('m_'))) . '
 510                      AND log_time >= ' . $min_time . '
 511                      AND log_type = ' . LOG_MOD;
 512              break;
 513      }
 514  
 515      $sort_key_val = $request->variable('sk', $default_key);
 516      $sort_dir_val = $request->variable('sd', $default_dir);
 517      $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
 518  
 519      switch ($type)
 520      {
 521          case 'topics':
 522              $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']);
 523              $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']);
 524  
 525              $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');
 526              $limit_time_sql = ($min_time) ? "AND t.topic_last_post_time >= $min_time" : '';
 527              break;
 528  
 529          case 'posts':
 530              $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']);
 531              $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
 532              $sort_by_sql_ary = array('a' => 'u.username_clean', 't' => array('p.post_time', 'p.post_id'), 's' => 'p.post_subject');
 533              $limit_time_sql = ($min_time) ? "AND p.post_time >= $min_time" : '';
 534              break;
 535  
 536          case 'reports':
 537              $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']);
 538              $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']);
 539              $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');
 540              break;
 541  
 542          case 'pm_reports':
 543              $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']);
 544              $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']);
 545              $sort_by_sql_ary = array('a' => 'u.username_clean', 'r' => 'ru.username', 'p' => 'p.message_time', 't' => 'r.report_time', 's' => 'p.message_subject');
 546              break;
 547  
 548          case 'logs':
 549              $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']);
 550              $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
 551  
 552              $sort_by_sql_ary = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
 553              $limit_time_sql = ($min_time) ? "AND l.log_time >= $min_time" : '';
 554              break;
 555      }
 556  
 557      // Default total to -1 to allow editing by the event
 558      $total_val = -1;
 559  
 560      $sort_by_sql = $sort_by_sql_ary;
 561      $sort_days = $sort_days_val;
 562      $sort_dir = $sort_dir_val;
 563      $sort_key = $sort_key_val;
 564      $total = $total_val;
 565      /**
 566      * This event allows you to control the SQL query used to get the total number
 567      * of reports the user can access.
 568      *
 569      * This total is used for the pagination and for displaying the total number
 570      * of reports to the user
 571      *
 572      *
 573      * @event core.mcp_sorting_query_before
 574      * @var    string    sql                    The current SQL search string
 575      * @var    string    mode                An id related to the module(s) the user is viewing
 576      * @var    string    type                Which kind of information is this being used for displaying. Posts, topics, etc...
 577      * @var    int        forum_id            The forum id of the posts the user is trying to access, if not 0
 578      * @var    int        topic_id            The topic id of the posts the user is trying to access, if not 0
 579      * @var    int        sort_days            The max age of the oldest report to be shown, in days
 580      * @var    string    sort_key            The way the user has decided to sort the data.
 581      *                                    The valid values must be in the keys of the sort_by_* variables
 582      * @var    string    sort_dir            Either 'd' for "DESC" or 'a' for 'ASC' in the SQL query
 583      * @var    int        limit_days            The possible max ages of the oldest report for the user to choose, in days.
 584      * @var    array    sort_by_sql            SQL text (values) for the possible names of the ways of sorting data (keys).
 585      * @var    array    sort_by_text        Language text (values) for the possible names of the ways of sorting data (keys).
 586      * @var    int        min_time            Integer with the minimum post time that the user is searching for
 587      * @var    int        limit_time_sql        Time limiting options used in the SQL query.
 588      * @var    int        total                The total number of reports that exist. Only set if you want to override the result
 589      * @var    string    where_sql            Extra information included in the WHERE clause. It must end with "WHERE" or "AND" or "OR".
 590      *                                    Set to "WHERE" and set total above -1 to override the total value
 591      * @since 3.1.4-RC1
 592      */
 593      $vars = array(
 594          'sql',
 595          'mode',
 596          'type',
 597          'forum_id',
 598          'topic_id',
 599          'sort_days',
 600          'sort_key',
 601          'sort_dir',
 602          'limit_days',
 603          'sort_by_sql',
 604          'sort_by_text',
 605          'min_time',
 606          'limit_time_sql',
 607          'total',
 608          'where_sql',
 609      );
 610      extract($phpbb_dispatcher->trigger_event('core.mcp_sorting_query_before', compact($vars)));
 611      $sort_by_sql_ary = $sort_by_sql;
 612      $sort_days_val = $sort_days;
 613      $sort_key_val = $sort_key;
 614      $sort_dir_val = $sort_dir;
 615      $total_val = $total;
 616      unset($sort_by_sql);
 617      unset($sort_days);
 618      unset($sort_key);
 619      unset($sort_dir);
 620      unset($total);
 621  
 622      if (!isset($sort_by_sql_ary[$sort_key_val]))
 623      {
 624          $sort_key_val = $default_key;
 625      }
 626  
 627      $direction = ($sort_dir_val == 'd') ? 'DESC' : 'ASC';
 628  
 629      if (is_array($sort_by_sql_ary[$sort_key_val]))
 630      {
 631          $sort_order_sql = implode(' ' . $direction . ', ', $sort_by_sql_ary[$sort_key_val]) . ' ' . $direction;
 632      }
 633      else
 634      {
 635          $sort_order_sql = $sort_by_sql_ary[$sort_key_val] . ' ' . $direction;
 636      }
 637  
 638      $s_limit_days = $s_sort_key = $s_sort_dir = $sort_url = '';
 639      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);
 640  
 641      $template->assign_vars(array(
 642              'S_SELECT_SORT_DIR'        => $s_sort_dir,
 643              'S_SELECT_SORT_KEY'        => $s_sort_key,
 644              'S_SELECT_SORT_DAYS'    => $s_limit_days)
 645      );
 646  
 647      if (($sort_days_val && $mode != 'viewlogs') || in_array($mode, array('reports', 'unapproved_topics', 'unapproved_posts', 'deleted_topics', 'deleted_posts')) || $where_sql != 'WHERE')
 648      {
 649          $result = $db->sql_query($sql);
 650          $total_val = (int) $db->sql_fetchfield('total');
 651          $db->sql_freeresult($result);
 652      }
 653      else if ($total_val < -1)
 654      {
 655          $total_val = -1;
 656      }
 657  }
 658  
 659  /**
 660  * Validate ids
 661  *
 662  * @param    array    &$ids            The relevant ids to check
 663  * @param    string    $table            The table to find the ids in
 664  * @param    string    $sql_id            The ids relevant column name
 665  * @param    array    $acl_list        A list of permissions the user need to have
 666  * @param    mixed    $singe_forum    Limit to one forum id (int) or the first forum found (true)
 667  *
 668  * @return    mixed    False if no ids were able to be retrieved, true if at least one id left.
 669  *                    Additionally, this value can be the forum_id assigned if $single_forum was set.
 670  *                    Therefore checking the result for with !== false is the best method.
 671  */
 672  function phpbb_check_ids(&$ids, $table, $sql_id, $acl_list = false, $single_forum = false)
 673  {
 674      global $db, $auth;
 675  
 676      if (!is_array($ids) || empty($ids))
 677      {
 678          return false;
 679      }
 680  
 681      $sql = "SELECT $sql_id, forum_id FROM $table
 682          WHERE " . $db->sql_in_set($sql_id, $ids);
 683      $result = $db->sql_query($sql);
 684  
 685      $ids = array();
 686      $forum_id = false;
 687  
 688      while ($row = $db->sql_fetchrow($result))
 689      {
 690          if ($acl_list && $row['forum_id'] && !$auth->acl_gets($acl_list, $row['forum_id']))
 691          {
 692              continue;
 693          }
 694  
 695          if ($acl_list && !$row['forum_id'] && !$auth->acl_getf_global($acl_list))
 696          {
 697              continue;
 698          }
 699  
 700          // Limit forum? If not, just assign the id.
 701          if ($single_forum === false)
 702          {
 703              $ids[] = $row[$sql_id];
 704              continue;
 705          }
 706  
 707          // Limit forum to a specific forum id?
 708          // This can get really tricky, because we do not want to create a failure on global topics. :)
 709          if ($row['forum_id'])
 710          {
 711              if ($single_forum !== true && $row['forum_id'] == (int) $single_forum)
 712              {
 713                  $forum_id = (int) $single_forum;
 714              }
 715              else if ($forum_id === false)
 716              {
 717                  $forum_id = $row['forum_id'];
 718              }
 719  
 720              if ($row['forum_id'] == $forum_id)
 721              {
 722                  $ids[] = $row[$sql_id];
 723              }
 724          }
 725          else
 726          {
 727              // Always add a global topic
 728              $ids[] = $row[$sql_id];
 729          }
 730      }
 731      $db->sql_freeresult($result);
 732  
 733      if (!sizeof($ids))
 734      {
 735          return false;
 736      }
 737  
 738      // If forum id is false and ids populated we may have only global announcements selected (returning 0 because of (int) $forum_id)
 739  
 740      return ($single_forum === false) ? true : (int) $forum_id;
 741  }


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