[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/phpbb/ -> viewonline_helper.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;
  15  
  16  /**
  17   * Class to handle viewonline related tasks
  18   */
  19  class viewonline_helper
  20  {
  21      /** @var \phpbb\filesystem\filesystem_interface */
  22      protected $filesystem;
  23  
  24      /** @var \phpbb\db\driver\driver_interface */
  25      protected $db;
  26  
  27      /**
  28       * @param \phpbb\filesystem\filesystem_interface $filesystem    phpBB's filesystem service
  29       * @param \phpbb\db\driver\driver_interface $db
  30       */
  31  	public function __construct(\phpbb\filesystem\filesystem_interface $filesystem, \phpbb\db\driver\driver_interface $db)
  32      {
  33          $this->filesystem = $filesystem;
  34          $this->db = $db;
  35      }
  36  
  37      /**
  38       * Get forum IDs for topics
  39       *
  40       * Retrieve forum IDs and add the data into the session data array
  41       * Array structure matches sql_fethrowset() result array
  42       *
  43       * @param array $session_data_rowset Users' session data array
  44       * @return void
  45       */
  46  	public function get_forum_ids(array &$session_data_rowset): void
  47      {
  48          $topic_ids = $match = [];
  49          foreach ($session_data_rowset as $number => $row)
  50          {
  51              if ($row['session_forum_id'] == 0 && preg_match('#t=([0-9]+)#', $row['session_page'], $match))
  52              {
  53                  $topic_ids[$number] = (int) $match[1];
  54              }
  55          }
  56  
  57          if (count($topic_ids = array_unique($topic_ids)))
  58          {
  59              $sql_ary = [
  60                  'SELECT'    => 't.topic_id, t.forum_id',
  61                  'FROM'        => [
  62                      TOPICS_TABLE => 't',
  63                  ],
  64                  'WHERE'        => $this->db->sql_in_set('t.topic_id', $topic_ids),
  65                  'ORDER_BY'    => 't.topic_id',
  66              ];
  67              $result = $this->db->sql_query($this->db->sql_build_query('SELECT', $sql_ary));
  68              $forum_ids_rowset = $this->db->sql_fetchrowset($result);
  69              $this->db->sql_freeresult($result);
  70  
  71              foreach ($forum_ids_rowset as $forum_ids_row)
  72              {
  73                  $session_data_row_number = array_search((int) $forum_ids_row['topic_id'], $topic_ids);
  74                  $session_data_rowset[$session_data_row_number]['session_forum_id'] = (int) $forum_ids_row['forum_id'];
  75              }
  76          }
  77      }
  78  
  79      /**
  80       * Get user page
  81       *
  82       * @param string $session_page User's session page
  83       * @return array Match array filled by preg_match()
  84       */
  85  	public function get_user_page($session_page)
  86      {
  87          $session_page = $this->filesystem->clean_path($session_page);
  88          if (strpos($session_page, './') === 0)
  89          {
  90              $session_page = substr($session_page, 2);
  91          }
  92  
  93          preg_match('#^((\.\./)*([a-z0-9/_-]+))#i', $session_page, $on_page);
  94          if (empty($on_page))
  95          {
  96              $on_page[1] = '';
  97          }
  98  
  99          return $on_page;
 100      }
 101  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1