[ Index ]

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


Generated: Thu Jan 11 23:14:31 2018 Cross-referenced by PHPXref 0.7.1