[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/phpbb/log/ -> log.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  namespace phpbb\log;
  15  
  16  /**
  17  * This class is used to add entries into the log table.
  18  */
  19  class log implements \phpbb\log\log_interface
  20  {
  21      /**
  22      * If set, administrative user profile links will be returned and messages
  23      * will not be censored.
  24      * @var bool
  25      */
  26      protected $is_in_admin;
  27  
  28      /**
  29      * An array with the disabled log types. Logs of such types will not be
  30      * added when add_log() is called.
  31      * @var array
  32      */
  33      protected $disabled_types;
  34  
  35      /**
  36      * Keeps the total log count of the last call to get_logs()
  37      * @var int
  38      */
  39      protected $entry_count;
  40  
  41      /**
  42      * Keeps the offset of the last valid page of the last call to get_logs()
  43      * @var int
  44      */
  45      protected $last_page_offset;
  46  
  47      /**
  48      * The table we use to store our logs.
  49      * @var string
  50      */
  51      protected $log_table;
  52  
  53      /**
  54      * Database object
  55      * @var \phpbb\db\driver\driver
  56      */
  57      protected $db;
  58  
  59      /**
  60      * User object
  61      * @var \phpbb\user
  62      */
  63      protected $user;
  64  
  65      /**
  66      * Auth object
  67      * @var \phpbb\auth\auth
  68      */
  69      protected $auth;
  70  
  71      /**
  72      * Event dispatcher object
  73      * @var \phpbb\event\dispatcher_interface
  74      */
  75      protected $dispatcher;
  76  
  77      /**
  78      * phpBB root path
  79      * @var string
  80      */
  81      protected $phpbb_root_path;
  82  
  83      /**
  84      * Admin root path
  85      * @var string
  86      */
  87      protected $phpbb_admin_path;
  88  
  89      /**
  90      * PHP Extension
  91      * @var string
  92      */
  93      protected $php_ext;
  94  
  95      /**
  96      * Constructor
  97      *
  98      * @param    \phpbb\db\driver\driver_interface    $db        Database object
  99      * @param    \phpbb\user        $user    User object
 100      * @param    \phpbb\auth\auth        $auth    Auth object
 101      * @param    \phpbb\event\dispatcher_interface    $phpbb_dispatcher    Event dispatcher
 102      * @param    string        $phpbb_root_path        Root path
 103      * @param    string        $relative_admin_path    Relative admin root path
 104      * @param    string        $php_ext            PHP Extension
 105      * @param    string        $log_table        Name of the table we use to store our logs
 106      */
 107  	public function __construct($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, $relative_admin_path, $php_ext, $log_table)
 108      {
 109          $this->db = $db;
 110          $this->user = $user;
 111          $this->auth = $auth;
 112          $this->dispatcher = $phpbb_dispatcher;
 113          $this->phpbb_root_path = $phpbb_root_path;
 114          $this->phpbb_admin_path = $this->phpbb_root_path . $relative_admin_path;
 115          $this->php_ext = $php_ext;
 116          $this->log_table = $log_table;
 117  
 118          /*
 119          * IN_ADMIN is set after the session is created,
 120          * so we need to take ADMIN_START into account as well, otherwise
 121          * it will not work for the \phpbb\log\log object we create in common.php
 122          */
 123          $this->set_is_admin((defined('ADMIN_START') && ADMIN_START) || (defined('IN_ADMIN') && IN_ADMIN));
 124          $this->enable();
 125      }
 126  
 127      /**
 128      * Set is_in_admin in order to return administrative user profile links
 129      * in get_logs()
 130      *
 131      * @param    bool    $is_in_admin        Are we called from within the acp?
 132      * @return    null
 133      */
 134  	public function set_is_admin($is_in_admin)
 135      {
 136          $this->is_in_admin = (bool) $is_in_admin;
 137      }
 138  
 139      /**
 140      * Returns the is_in_admin option
 141      *
 142      * @return    bool
 143      */
 144  	public function get_is_admin()
 145      {
 146          return $this->is_in_admin;
 147      }
 148  
 149      /**
 150      * Set table name
 151      *
 152      * @param    string    $log_table        Can overwrite the table to use for the logs
 153      * @return    null
 154      */
 155  	public function set_log_table($log_table)
 156      {
 157          $this->log_table = $log_table;
 158      }
 159  
 160      /**
 161      * {@inheritDoc}
 162      */
 163  	public function is_enabled($type = '')
 164      {
 165          if ($type == '' || $type == 'all')
 166          {
 167              return !isset($this->disabled_types['all']);
 168          }
 169          return !isset($this->disabled_types[$type]) && !isset($this->disabled_types['all']);
 170      }
 171  
 172      /**
 173      * {@inheritDoc}
 174      */
 175  	public function disable($type = '')
 176      {
 177          if (is_array($type))
 178          {
 179              foreach ($type as $disable_type)
 180              {
 181                  $this->disable($disable_type);
 182              }
 183              return;
 184          }
 185  
 186          // Empty string is an equivalent for all types.
 187          if ($type == '')
 188          {
 189              $type = 'all';
 190          }
 191          $this->disabled_types[$type] = true;
 192      }
 193  
 194      /**
 195      * {@inheritDoc}
 196      */
 197  	public function enable($type = '')
 198      {
 199          if (is_array($type))
 200          {
 201              foreach ($type as $enable_type)
 202              {
 203                  $this->enable($enable_type);
 204              }
 205              return;
 206          }
 207  
 208          if ($type == '' || $type == 'all')
 209          {
 210              $this->disabled_types = array();
 211              return;
 212          }
 213          unset($this->disabled_types[$type]);
 214      }
 215  
 216      /**
 217      * {@inheritDoc}
 218      */
 219  	public function add($mode, $user_id, $log_ip, $log_operation, $log_time = false, $additional_data = array())
 220      {
 221          if (!$this->is_enabled($mode))
 222          {
 223              return false;
 224          }
 225  
 226          if ($log_time == false)
 227          {
 228              $log_time = time();
 229          }
 230  
 231          $sql_ary = array(
 232              'user_id'        => !empty($user_id) ? $user_id : ANONYMOUS,
 233              'log_ip'        => !empty($log_ip) ? $log_ip : '',
 234              'log_time'        => $log_time,
 235              'log_operation'    => $log_operation,
 236          );
 237  
 238          switch ($mode)
 239          {
 240              case 'admin':
 241                  $sql_ary += array(
 242                      'log_type'        => LOG_ADMIN,
 243                      'log_data'        => (!empty($additional_data)) ? serialize($additional_data) : '',
 244                  );
 245              break;
 246  
 247              case 'mod':
 248                  $forum_id = isset($additional_data['forum_id']) ? (int) $additional_data['forum_id'] : 0;
 249                  unset($additional_data['forum_id']);
 250                  $topic_id = isset($additional_data['topic_id']) ? (int) $additional_data['topic_id'] : 0;
 251                  unset($additional_data['topic_id']);
 252                  $sql_ary += array(
 253                      'log_type'        => LOG_MOD,
 254                      'forum_id'        => $forum_id,
 255                      'topic_id'        => $topic_id,
 256                      'log_data'        => (!empty($additional_data)) ? serialize($additional_data) : '',
 257                  );
 258              break;
 259  
 260              case 'user':
 261                  $reportee_id = (int) $additional_data['reportee_id'];
 262                  unset($additional_data['reportee_id']);
 263  
 264                  $sql_ary += array(
 265                      'log_type'        => LOG_USERS,
 266                      'reportee_id'    => $reportee_id,
 267                      'log_data'        => (!empty($additional_data)) ? serialize($additional_data) : '',
 268                  );
 269              break;
 270  
 271              case 'critical':
 272                  $sql_ary += array(
 273                      'log_type'        => LOG_CRITICAL,
 274                      'log_data'        => (!empty($additional_data)) ? serialize($additional_data) : '',
 275                  );
 276              break;
 277          }
 278  
 279          /**
 280          * Allows to modify log data before we add it to the database
 281          *
 282          * NOTE: if sql_ary does not contain a log_type value, the entry will
 283          * not be stored in the database. So ensure to set it, if needed.
 284          *
 285          * @event core.add_log
 286          * @var    string    mode            Mode of the entry we log
 287          * @var    int        user_id            ID of the user who triggered the log
 288          * @var    string    log_ip            IP of the user who triggered the log
 289          * @var    string    log_operation    Language key of the log operation
 290          * @var    int        log_time        Timestamp, when the log was added
 291          * @var    array    additional_data    Array with additional log data
 292          * @var    array    sql_ary            Array with log data we insert into the
 293          *                            database. If sql_ary[log_type] is not set,
 294          *                            we won't add the entry to the database.
 295          * @since 3.1.0-a1
 296          */
 297          $vars = array(
 298              'mode',
 299              'user_id',
 300              'log_ip',
 301              'log_operation',
 302              'log_time',
 303              'additional_data',
 304              'sql_ary',
 305          );
 306          extract($this->dispatcher->trigger_event('core.add_log', compact($vars)));
 307  
 308          // We didn't find a log_type, so we don't save it in the database.
 309          if (!isset($sql_ary['log_type']))
 310          {
 311              return false;
 312          }
 313  
 314          $this->db->sql_query('INSERT INTO ' . $this->log_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary));
 315  
 316          return $this->db->sql_nextid();
 317      }
 318  
 319      /**
 320      * {@inheritDoc}
 321      */
 322  	public function delete($mode, $conditions = array())
 323      {
 324          switch ($mode)
 325          {
 326              case 'admin':
 327                  $log_type = LOG_ADMIN;
 328                  break;
 329  
 330              case 'mod':
 331                  $log_type = LOG_MOD;
 332                  break;
 333  
 334              case 'user':
 335                  $log_type = LOG_USERS;
 336                  break;
 337  
 338              case 'users':
 339                  $log_type = LOG_USERS;
 340                  break;
 341  
 342              case 'critical':
 343                  $log_type = LOG_CRITICAL;
 344                  break;
 345  
 346              default:
 347                  $log_type = false;
 348          }
 349  
 350          /**
 351          * Allows to modify log data before we delete it from the database
 352          *
 353          * NOTE: if sql_ary does not contain a log_type value, the entry will
 354          * not be deleted in the database. So ensure to set it, if needed.
 355          *
 356          * @event core.delete_log
 357          * @var    string    mode            Mode of the entry we log
 358          * @var    string    log_type        Type ID of the log (should be different than false)
 359          * @var    array    conditions        An array of conditions, 3 different  forms are accepted
 360          *                                 1) <key> => <value> transformed into 'AND <key> = <value>' (value should be an integer)
 361          *                                2) <key> => array(<operator>, <value>) transformed into 'AND <key> <operator> <value>' (values can't be an array)
 362          *                                3) <key> => array('IN' => array(<values>)) transformed into 'AND <key> IN <values>'
 363          *                                A special field, keywords, can also be defined. In this case only the log entries that have the keywords in log_operation or log_data will be deleted.
 364          * @since 3.1.0-b4
 365          */
 366          $vars = array(
 367              'mode',
 368              'log_type',
 369              'conditions',
 370          );
 371          extract($this->dispatcher->trigger_event('core.delete_log', compact($vars)));
 372  
 373          if ($log_type === false)
 374          {
 375              return;
 376          }
 377  
 378          $sql_where = 'WHERE log_type = ' . $log_type;
 379  
 380          if (isset($conditions['keywords']))
 381          {
 382              $sql_where .= $this->generate_sql_keyword($conditions['keywords'], '');
 383  
 384              unset($conditions['keywords']);
 385          }
 386  
 387          foreach ($conditions as $field => $field_value)
 388          {
 389              $sql_where .= ' AND ';
 390  
 391              if (is_array($field_value) && sizeof($field_value) == 2 && !is_array($field_value[1]))
 392              {
 393                  $sql_where .= $field . ' ' . $field_value[0] . ' ' . $field_value[1];
 394              }
 395              else if (is_array($field_value) && isset($field_value['IN']) && is_array($field_value['IN']))
 396              {
 397                  $sql_where .= $this->db->sql_in_set($field, $field_value['IN']);
 398              }
 399              else
 400              {
 401                  $sql_where .= $field . ' = ' . $field_value;
 402              }
 403          }
 404  
 405          $sql = 'DELETE FROM ' . $this->log_table . "
 406                      $sql_where";
 407          $this->db->sql_query($sql);
 408  
 409          $this->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_CLEAR_' . strtoupper($mode));
 410      }
 411  
 412      /**
 413      * {@inheritDoc}
 414      */
 415  	public function get_logs($mode, $count_logs = true, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $log_time = 0, $sort_by = 'l.log_time DESC', $keywords = '')
 416      {
 417          $this->entry_count = 0;
 418          $this->last_page_offset = $offset;
 419  
 420          $topic_id_list = $reportee_id_list = array();
 421  
 422          $profile_url = ($this->get_is_admin() && $this->phpbb_admin_path) ? append_sid("{$this->phpbb_admin_path}index.{$this->php_ext}", 'i=users&amp;mode=overview') : append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=viewprofile');
 423  
 424          switch ($mode)
 425          {
 426              case 'admin':
 427                  $log_type = LOG_ADMIN;
 428                  $sql_additional = '';
 429              break;
 430  
 431              case 'mod':
 432                  $log_type = LOG_MOD;
 433                  $sql_additional = '';
 434  
 435                  if ($topic_id)
 436                  {
 437                      $sql_additional = 'AND l.topic_id = ' . (int) $topic_id;
 438                  }
 439                  else if (is_array($forum_id))
 440                  {
 441                      $sql_additional = 'AND ' . $this->db->sql_in_set('l.forum_id', array_map('intval', $forum_id));
 442                  }
 443                  else if ($forum_id)
 444                  {
 445                      $sql_additional = 'AND l.forum_id = ' . (int) $forum_id;
 446                  }
 447              break;
 448  
 449              case 'user':
 450                  $log_type = LOG_USERS;
 451                  $sql_additional = 'AND l.reportee_id = ' . (int) $user_id;
 452              break;
 453  
 454              case 'users':
 455                  $log_type = LOG_USERS;
 456                  $sql_additional = '';
 457              break;
 458  
 459              case 'critical':
 460                  $log_type = LOG_CRITICAL;
 461                  $sql_additional = '';
 462              break;
 463  
 464              default:
 465                  $log_type = false;
 466                  $sql_additional = '';
 467          }
 468  
 469          /**
 470          * Overwrite log type and limitations before we count and get the logs
 471          *
 472          * NOTE: if log_type is false, no entries will be returned.
 473          *
 474          * @event core.get_logs_modify_type
 475          * @var    string    mode        Mode of the entries we display
 476          * @var    bool    count_logs    Do we count all matching entries?
 477          * @var    int        limit        Limit the number of entries
 478          * @var    int        offset        Offset when fetching the entries
 479          * @var    mixed    forum_id    Limit entries to the forum_id,
 480          *                            can also be an array of forum_ids
 481          * @var    int        topic_id    Limit entries to the topic_id
 482          * @var    int        user_id        Limit entries to the user_id
 483          * @var    int        log_time    Limit maximum age of log entries
 484          * @var    string    sort_by        SQL order option
 485          * @var    string    keywords    Will only return entries that have the
 486          *                            keywords in log_operation or log_data
 487          * @var    string    profile_url    URL to the users profile
 488          * @var    int        log_type    Limit logs to a certain type. If log_type
 489          *                            is false, no entries will be returned.
 490          * @var    string    sql_additional    Additional conditions for the entries,
 491          *                                e.g.: 'AND l.forum_id = 1'
 492          * @since 3.1.0-a1
 493          */
 494          $vars = array(
 495              'mode',
 496              'count_logs',
 497              'limit',
 498              'offset',
 499              'forum_id',
 500              'topic_id',
 501              'user_id',
 502              'log_time',
 503              'sort_by',
 504              'keywords',
 505              'profile_url',
 506              'log_type',
 507              'sql_additional',
 508          );
 509          extract($this->dispatcher->trigger_event('core.get_logs_modify_type', compact($vars)));
 510  
 511          if ($log_type === false)
 512          {
 513              $this->last_page_offset = 0;
 514              return array();
 515          }
 516  
 517          $sql_keywords = '';
 518          if (!empty($keywords))
 519          {
 520              // Get the SQL condition for our keywords
 521              $sql_keywords = $this->generate_sql_keyword($keywords);
 522          }
 523  
 524          $get_logs_sql_ary = array(
 525              'SELECT' => 'l.*, u.username, u.username_clean, u.user_colour',
 526              'FROM' => array(
 527                          $this->log_table => 'l',
 528                          USERS_TABLE => 'u',
 529                      ),
 530              'WHERE' => 'l.log_type = ' . (int) $log_type . "
 531                      AND l.user_id = u.user_id
 532                      $sql_keywords
 533                      $sql_additional",
 534  
 535              'ORDER_BY' => $sort_by,
 536          );
 537  
 538          if ($log_time)
 539          {
 540              $get_logs_sql_ary['WHERE'] = 'l.log_time >= ' . (int) $log_time . '
 541                      AND ' . $get_logs_sql_ary['WHERE'];
 542          }
 543  
 544          /**
 545          * Modify the query to obtain the logs data
 546          *
 547          * @event core.get_logs_main_query_before
 548          * @var    array    get_logs_sql_ary    The array in the format of the query builder with the query
 549          *                                    to get the log count and the log list
 550          * @var    string    mode                Mode of the entries we display
 551          * @var    bool    count_logs            Do we count all matching entries?
 552          * @var    int        limit                Limit the number of entries
 553          * @var    int        offset                Offset when fetching the entries
 554          * @var    mixed    forum_id            Limit entries to the forum_id,
 555          *                                    can also be an array of forum_ids
 556          * @var    int        topic_id            Limit entries to the topic_id
 557          * @var    int        user_id                Limit entries to the user_id
 558          * @var    int        log_time            Limit maximum age of log entries
 559          * @var    string    sort_by                SQL order option
 560          * @var    string    keywords            Will only return entries that have the
 561          *                                    keywords in log_operation or log_data
 562          * @var    string    profile_url            URL to the users profile
 563          * @var    int        log_type            Limit logs to a certain type. If log_type
 564          *                                    is false, no entries will be returned.
 565          * @var    string    sql_additional        Additional conditions for the entries,
 566          *                                    e.g.: 'AND l.forum_id = 1'
 567          * @since 3.1.5-RC1
 568          */
 569          $vars = array(
 570              'get_logs_sql_ary',
 571              'mode',
 572              'count_logs',
 573              'limit',
 574              'offset',
 575              'forum_id',
 576              'topic_id',
 577              'user_id',
 578              'log_time',
 579              'sort_by',
 580              'keywords',
 581              'profile_url',
 582              'log_type',
 583              'sql_additional',
 584          );
 585          extract($this->dispatcher->trigger_event('core.get_logs_main_query_before', compact($vars)));
 586  
 587          if ($count_logs)
 588          {
 589              $count_logs_sql_ary = $get_logs_sql_ary;
 590  
 591              $count_logs_sql_ary['SELECT'] = 'COUNT(l.log_id) AS total_entries';
 592              unset($count_logs_sql_ary['ORDER_BY']);
 593  
 594              $sql = $this->db->sql_build_query('SELECT', $count_logs_sql_ary);
 595              $result = $this->db->sql_query($sql);
 596              $this->entry_count = (int) $this->db->sql_fetchfield('total_entries');
 597              $this->db->sql_freeresult($result);
 598  
 599              if ($this->entry_count == 0)
 600              {
 601                  // Save the queries, because there are no logs to display
 602                  $this->last_page_offset = 0;
 603                  return array();
 604              }
 605  
 606              // Return the user to the last page that is valid
 607              while ($this->last_page_offset >= $this->entry_count)
 608              {
 609                  $this->last_page_offset = max(0, $this->last_page_offset - $limit);
 610              }
 611          }
 612  
 613          $sql = $this->db->sql_build_query('SELECT', $get_logs_sql_ary);
 614          $result = $this->db->sql_query_limit($sql, $limit, $this->last_page_offset);
 615  
 616          $i = 0;
 617          $log = array();
 618          while ($row = $this->db->sql_fetchrow($result))
 619          {
 620              $row['forum_id'] = (int) $row['forum_id'];
 621              if ($row['topic_id'])
 622              {
 623                  $topic_id_list[] = (int) $row['topic_id'];
 624              }
 625  
 626              if ($row['reportee_id'])
 627              {
 628                  $reportee_id_list[] = (int) $row['reportee_id'];
 629              }
 630  
 631              $log_entry_data = array(
 632                  'id'                => (int) $row['log_id'],
 633  
 634                  'reportee_id'            => (int) $row['reportee_id'],
 635                  'reportee_username'        => '',
 636                  'reportee_username_full'=> '',
 637  
 638                  'user_id'            => (int) $row['user_id'],
 639                  'username'            => $row['username'],
 640                  'username_full'        => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], false, $profile_url),
 641  
 642                  'ip'                => $row['log_ip'],
 643                  'time'                => (int) $row['log_time'],
 644                  'forum_id'            => (int) $row['forum_id'],
 645                  'topic_id'            => (int) $row['topic_id'],
 646  
 647                  'viewforum'            => ($row['forum_id'] && $this->auth->acl_get('f_read', $row['forum_id'])) ? append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $row['forum_id']) : false,
 648                  'action'            => (isset($this->user->lang[$row['log_operation']])) ? $row['log_operation'] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}',
 649              );
 650  
 651              /**
 652              * Modify the entry's data before it is returned
 653              *
 654              * @event core.get_logs_modify_entry_data
 655              * @var    array    row            Entry data from the database
 656              * @var    array    log_entry_data    Entry's data which is returned
 657              * @since 3.1.0-a1
 658              */
 659              $vars = array('row', 'log_entry_data');
 660              extract($this->dispatcher->trigger_event('core.get_logs_modify_entry_data', compact($vars)));
 661  
 662              $log[$i] = $log_entry_data;
 663  
 664              if (!empty($row['log_data']))
 665              {
 666                  $log_data_ary = unserialize($row['log_data']);
 667                  $log_data_ary = ($log_data_ary !== false) ? $log_data_ary : array();
 668  
 669                  if (isset($this->user->lang[$row['log_operation']]))
 670                  {
 671                      // Check if there are more occurrences of % than
 672                      // arguments, if there are we fill out the arguments
 673                      // array. It doesn't matter if we add more arguments than
 674                      // placeholders.
 675                      $num_args = 0;
 676                      if (!is_array($this->user->lang[$row['log_operation']]))
 677                      {
 678                          $num_args = substr_count($this->user->lang[$row['log_operation']], '%');
 679                      }
 680                      else
 681                      {
 682                          foreach ($this->user->lang[$row['log_operation']] as $case => $plural_string)
 683                          {
 684                              $num_args = max($num_args, substr_count($plural_string, '%'));
 685                          }
 686                      }
 687  
 688                      if (($num_args - sizeof($log_data_ary)) > 0)
 689                      {
 690                          $log_data_ary = array_merge($log_data_ary, array_fill(0, $num_args - sizeof($log_data_ary), ''));
 691                      }
 692  
 693                      $lang_arguments = array_merge(array($log[$i]['action']), $log_data_ary);
 694                      $log[$i]['action'] = call_user_func_array(array($this->user, 'lang'), $lang_arguments);
 695  
 696                      // If within the admin panel we do not censor text out
 697                      if ($this->get_is_admin())
 698                      {
 699                          $log[$i]['action'] = bbcode_nl2br($log[$i]['action']);
 700                      }
 701                      else
 702                      {
 703                          $log[$i]['action'] = bbcode_nl2br(censor_text($log[$i]['action']));
 704                      }
 705                  }
 706                  else if (!empty($log_data_ary))
 707                  {
 708                      $log[$i]['action'] .= '<br />' . implode('', $log_data_ary);
 709                  }
 710  
 711                  /* Apply make_clickable... has to be seen if it is for good. :/
 712                  // Seems to be not for the moment, reconsider later...
 713                  $log[$i]['action'] = make_clickable($log[$i]['action']);
 714                  */
 715              }
 716              else
 717              {
 718                  $log[$i]['action'] = $this->user->lang($log[$i]['action']);
 719              }
 720  
 721              $i++;
 722          }
 723          $this->db->sql_freeresult($result);
 724  
 725          /**
 726          * Get some additional data after we got all log entries
 727          *
 728          * @event core.get_logs_get_additional_data
 729          * @var    array    log            Array with all our log entries
 730          * @var    array    topic_id_list        Array of topic ids, for which we
 731          *                                    get the permission data
 732          * @var    array    reportee_id_list    Array of additional user IDs we
 733          *                                    get the username strings for
 734          * @since 3.1.0-a1
 735          */
 736          $vars = array('log', 'topic_id_list', 'reportee_id_list');
 737          extract($this->dispatcher->trigger_event('core.get_logs_get_additional_data', compact($vars)));
 738  
 739          if (sizeof($topic_id_list))
 740          {
 741              $topic_auth = $this->get_topic_auth($topic_id_list);
 742  
 743              foreach ($log as $key => $row)
 744              {
 745                  $log[$key]['viewtopic'] = (isset($topic_auth['f_read'][$row['topic_id']])) ? append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $topic_auth['f_read'][$row['topic_id']] . '&amp;t=' . $row['topic_id']) : false;
 746                  $log[$key]['viewlogs'] = (isset($topic_auth['m_'][$row['topic_id']])) ? append_sid("{$this->phpbb_root_path}mcp.{$this->php_ext}", 'i=logs&amp;mode=topic_logs&amp;t=' . $row['topic_id'], true, $this->user->session_id) : false;
 747              }
 748          }
 749  
 750          if (sizeof($reportee_id_list))
 751          {
 752              $reportee_data_list = $this->get_reportee_data($reportee_id_list);
 753  
 754              foreach ($log as $key => $row)
 755              {
 756                  if (!isset($reportee_data_list[$row['reportee_id']]))
 757                  {
 758                      continue;
 759                  }
 760  
 761                  $log[$key]['reportee_username'] = $reportee_data_list[$row['reportee_id']]['username'];
 762                  $log[$key]['reportee_username_full'] = get_username_string('full', $row['reportee_id'], $reportee_data_list[$row['reportee_id']]['username'], $reportee_data_list[$row['reportee_id']]['user_colour'], false, $profile_url);
 763              }
 764          }
 765  
 766          /**
 767          * Allow modifying or execute extra final filter on log entries
 768          *
 769          * @event core.get_logs_after
 770          * @var    array    log            Array with all our log entries
 771          * @var    array    topic_id_list        Array of topic ids, for which we
 772          *                                    get the permission data
 773          * @var    array    reportee_id_list    Array of additional user IDs we
 774          *                                    get the username strings for
 775          * @var    string    mode        Mode of the entries we display
 776          * @var    bool    count_logs    Do we count all matching entries?
 777          * @var    int        limit        Limit the number of entries
 778          * @var    int        offset        Offset when fetching the entries
 779          * @var    mixed    forum_id    Limit entries to the forum_id,
 780          *                            can also be an array of forum_ids
 781          * @var    int        topic_id    Limit entries to the topic_id
 782          * @var    int        user_id        Limit entries to the user_id
 783          * @var    int        log_time    Limit maximum age of log entries
 784          * @var    string    sort_by        SQL order option
 785          * @var    string    keywords    Will only return entries that have the
 786          *                            keywords in log_operation or log_data
 787          * @var    string    profile_url    URL to the users profile
 788          * @var    int        log_type    The type of logs it was filtered
 789          * @since 3.1.3-RC1
 790          */
 791          $vars = array(
 792              'log',
 793              'topic_id_list',
 794              'reportee_id_list',
 795              'mode',
 796              'count_logs',
 797              'limit',
 798              'offset',
 799              'forum_id',
 800              'topic_id',
 801              'user_id',
 802              'log_time',
 803              'sort_by',
 804              'keywords',
 805              'profile_url',
 806              'log_type',
 807          );
 808          extract($this->dispatcher->trigger_event('core.get_logs_after', compact($vars)));
 809  
 810          return $log;
 811      }
 812  
 813      /**
 814      * Generates a sql condition for the specified keywords
 815      *
 816      * @param    string    $keywords            The keywords the user specified to search for
 817      * @param    string    $table_alias        The alias of the logs' table ('l.' by default)
 818      * @param    string    $statement_operator    The operator used to prefix the statement ('AND' by default)
 819      *
 820      * @return    string        Returns the SQL condition searching for the keywords
 821      */
 822  	protected function generate_sql_keyword($keywords, $table_alias = 'l.', $statement_operator = 'AND')
 823      {
 824          // Use no preg_quote for $keywords because this would lead to sole
 825          // backslashes being added. We also use an OR connection here for
 826          // spaces and the | string. Currently, regex is not supported for
 827          // searching (but may come later).
 828          $keywords = preg_split('#[\s|]+#u', utf8_strtolower($keywords), 0, PREG_SPLIT_NO_EMPTY);
 829          $sql_keywords = '';
 830  
 831          if (!empty($keywords))
 832          {
 833              $keywords_pattern = array();
 834  
 835              // Build pattern and keywords...
 836              for ($i = 0, $num_keywords = sizeof($keywords); $i < $num_keywords; $i++)
 837              {
 838                  $keywords_pattern[] = preg_quote($keywords[$i], '#');
 839                  $keywords[$i] = $this->db->sql_like_expression($this->db->get_any_char() . $keywords[$i] . $this->db->get_any_char());
 840              }
 841  
 842              $keywords_pattern = '#' . implode('|', $keywords_pattern) . '#ui';
 843  
 844              $operations = array();
 845              foreach ($this->user->lang as $key => $value)
 846              {
 847                  if (substr($key, 0, 4) == 'LOG_')
 848                  {
 849                      if (is_array($value))
 850                      {
 851                          foreach ($value as $plural_value)
 852                          {
 853                              if (preg_match($keywords_pattern, $plural_value))
 854                              {
 855                                  $operations[] = $key;
 856                                  break;
 857                              }
 858                          }
 859                      }
 860                      else if (preg_match($keywords_pattern, $value))
 861                      {
 862                          $operations[] = $key;
 863                      }
 864                  }
 865              }
 866  
 867              $sql_keywords = ' ' . $statement_operator . ' (';
 868              if (!empty($operations))
 869              {
 870                  $sql_keywords .= $this->db->sql_in_set($table_alias . 'log_operation', $operations) . ' OR ';
 871              }
 872              $sql_lower = $this->db->sql_lower_text($table_alias . 'log_data');
 873              $sql_keywords .= " $sql_lower " . implode(" OR $sql_lower ", $keywords) . ')';
 874          }
 875  
 876          return $sql_keywords;
 877      }
 878  
 879      /**
 880      * Determine whether the user is allowed to read and/or moderate the forum of the topic
 881      *
 882      * @param    array    $topic_ids    Array with the topic ids
 883      *
 884      * @return    array        Returns an array with two keys 'm_' and 'read_f' which are also an array of topic_id => forum_id sets when the permissions are given. Sample:
 885      *                        array(
 886      *                            'permission' => array(
 887      *                                topic_id => forum_id
 888      *                            ),
 889      *                        ),
 890      */
 891  	protected function get_topic_auth(array $topic_ids)
 892      {
 893          $forum_auth = array('f_read' => array(), 'm_' => array());
 894          $topic_ids = array_unique($topic_ids);
 895  
 896          $sql_ary = array(
 897              'SELECT'    => 'topic_id, forum_id',
 898              'FROM'        => array(
 899                  TOPICS_TABLE    => 't',
 900              ),
 901              'WHERE'        => $this->db->sql_in_set('topic_id', array_map('intval', $topic_ids)),
 902          );
 903  
 904          /**
 905          * Allow modifying SQL query before topic data is retrieved.
 906          *
 907          * @event core.phpbb_log_get_topic_auth_sql_before
 908          * @var    array    topic_ids    Array with unique topic IDs
 909          * @var    array    sql_ary        SQL array
 910          * @since 3.1.11-RC1
 911          */
 912          $vars = array(
 913              'topic_ids',
 914              'sql_ary',
 915          );
 916          extract($this->dispatcher->trigger_event('core.phpbb_log_get_topic_auth_sql_before', compact($vars)));
 917  
 918          $sql = $this->db->sql_build_query('SELECT', $sql_ary);
 919          $result = $this->db->sql_query($sql);
 920  
 921          while ($row = $this->db->sql_fetchrow($result))
 922          {
 923              $row['topic_id'] = (int) $row['topic_id'];
 924              $row['forum_id'] = (int) $row['forum_id'];
 925  
 926              if ($this->auth->acl_get('f_read', $row['forum_id']))
 927              {
 928                  $forum_auth['f_read'][$row['topic_id']] = $row['forum_id'];
 929              }
 930  
 931              if ($this->auth->acl_gets('a_', 'm_', $row['forum_id']))
 932              {
 933                  $forum_auth['m_'][$row['topic_id']] = $row['forum_id'];
 934              }
 935          }
 936          $this->db->sql_freeresult($result);
 937  
 938          return $forum_auth;
 939      }
 940  
 941      /**
 942      * Get the data for all reportee from the database
 943      *
 944      * @param    array    $reportee_ids    Array with the user ids of the reportees
 945      *
 946      * @return    array        Returns an array with the reportee data
 947      */
 948  	protected function get_reportee_data(array $reportee_ids)
 949      {
 950          $reportee_ids = array_unique($reportee_ids);
 951          $reportee_data_list = array();
 952  
 953          $sql = 'SELECT user_id, username, user_colour
 954              FROM ' . USERS_TABLE . '
 955              WHERE ' . $this->db->sql_in_set('user_id', $reportee_ids);
 956          $result = $this->db->sql_query($sql);
 957  
 958          while ($row = $this->db->sql_fetchrow($result))
 959          {
 960              $reportee_data_list[$row['user_id']] = $row;
 961          }
 962          $this->db->sql_freeresult($result);
 963  
 964          return $reportee_data_list;
 965      }
 966  
 967      /**
 968      * {@inheritDoc}
 969      */
 970  	public function get_log_count()
 971      {
 972          return ($this->entry_count) ? $this->entry_count : 0;
 973      }
 974  
 975      /**
 976      * {@inheritDoc}
 977      */
 978  	public function get_valid_offset()
 979      {
 980          return ($this->last_page_offset) ? $this->last_page_offset : 0;
 981      }
 982  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1