Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

service.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 8.80 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  namespace phpbb\cache;
 015   
 016  /**
 017  * Class for grabbing/handling cached entries
 018  */
 019  class service
 020  {
 021      /**
 022      * Cache driver.
 023      *
 024      * @var \phpbb\cache\driver\driver_interface
 025      */
 026      protected $driver;
 027   
 028      /**
 029      * The config.
 030      *
 031      * @var \phpbb\config\config
 032      */
 033      protected $config;
 034   
 035      /**
 036      * Database connection.
 037      *
 038      * @var \phpbb\db\driver\driver_interface
 039      */
 040      protected $db;
 041   
 042      /**
 043      * Root path.
 044      *
 045      * @var string
 046      */
 047      protected $phpbb_root_path;
 048   
 049      /**
 050      * PHP file extension.
 051      *
 052      * @var string
 053      */
 054      protected $php_ext;
 055   
 056      /**
 057      * Creates a cache service around a cache driver
 058      *
 059      * @param \phpbb\cache\driver\driver_interface $driver The cache driver
 060      * @param \phpbb\config\config $config The config
 061      * @param \phpbb\db\driver\driver_interface $db Database connection
 062      * @param string $phpbb_root_path Root path
 063      * @param string $php_ext PHP file extension
 064      */
 065      public function __construct(\phpbb\cache\driver\driver_interface $driver, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, $phpbb_root_path, $php_ext)
 066      {
 067          $this->set_driver($driver);
 068          $this->config = $config;
 069          $this->db = $db;
 070          $this->phpbb_root_path = $phpbb_root_path;
 071          $this->php_ext = $php_ext;
 072      }
 073   
 074      /**
 075      * Returns the cache driver used by this cache service.
 076      *
 077      * @return \phpbb\cache\driver\driver_interface The cache driver
 078      */
 079      public function get_driver()
 080      {
 081          return $this->driver;
 082      }
 083   
 084      /**
 085      * Replaces the cache driver used by this cache service.
 086      *
 087      * @param \phpbb\cache\driver\driver_interface $driver The cache driver
 088      */
 089      public function set_driver(\phpbb\cache\driver\driver_interface $driver)
 090      {
 091          $this->driver = $driver;
 092      }
 093   
 094      public function __call($method, $arguments)
 095      {
 096          return call_user_func_array(array($this->driver, $method), $arguments);
 097      }
 098   
 099      /**
 100      * Obtain list of naughty words and build preg style replacement arrays for use by the
 101      * calling script
 102      */
 103      function obtain_word_list()
 104      {
 105          if (($censors = $this->driver->get('_word_censors')) === false)
 106          {
 107              $sql = 'SELECT word, replacement
 108                  FROM ' . WORDS_TABLE;
 109              $result = $this->db->sql_query($sql);
 110   
 111              $censors = array();
 112              while ($row = $this->db->sql_fetchrow($result))
 113              {
 114                  $censors['match'][] = get_censor_preg_expression($row['word']);
 115                  $censors['replace'][] = $row['replacement'];
 116              }
 117              $this->db->sql_freeresult($result);
 118   
 119              $this->driver->put('_word_censors', $censors);
 120          }
 121   
 122          return $censors;
 123      }
 124   
 125      /**
 126      * Obtain currently listed icons
 127      */
 128      function obtain_icons()
 129      {
 130          if (($icons = $this->driver->get('_icons')) === false)
 131          {
 132              // Topic icons
 133              $sql = 'SELECT *
 134                  FROM ' . ICONS_TABLE . '
 135                  ORDER BY icons_order';
 136              $result = $this->db->sql_query($sql);
 137   
 138              $icons = array();
 139              while ($row = $this->db->sql_fetchrow($result))
 140              {
 141                  $icons[$row['icons_id']]['img'] = $row['icons_url'];
 142                  $icons[$row['icons_id']]['width'] = (int) $row['icons_width'];
 143                  $icons[$row['icons_id']]['height'] = (int) $row['icons_height'];
 144                  $icons[$row['icons_id']]['alt'] = ($row['icons_alt']) ? $row['icons_alt'] : '';
 145                  $icons[$row['icons_id']]['display'] = (bool) $row['display_on_posting'];
 146              }
 147              $this->db->sql_freeresult($result);
 148   
 149              $this->driver->put('_icons', $icons);
 150          }
 151   
 152          return $icons;
 153      }
 154   
 155      /**
 156      * Obtain ranks
 157      */
 158      function obtain_ranks()
 159      {
 160          if (($ranks = $this->driver->get('_ranks')) === false)
 161          {
 162              $sql = 'SELECT *
 163                  FROM ' . RANKS_TABLE . '
 164                  ORDER BY rank_min DESC';
 165              $result = $this->db->sql_query($sql);
 166   
 167              $ranks = array();
 168              while ($row = $this->db->sql_fetchrow($result))
 169              {
 170                  if ($row['rank_special'])
 171                  {
 172                      unset($row['rank_min']);
 173                      $ranks['special'][$row['rank_id']] = $row;
 174                  }
 175                  else
 176                  {
 177                      $ranks['normal'][$row['rank_id']] = $row;
 178                  }
 179              }
 180              $this->db->sql_freeresult($result);
 181   
 182              $this->driver->put('_ranks', $ranks);
 183          }
 184   
 185          return $ranks;
 186      }
 187   
 188      /**
 189      * Obtain allowed extensions
 190      *
 191      * @param mixed $forum_id If false then check for private messaging, if int then check for forum id. If true, then only return extension informations.
 192      *
 193      * @return array allowed extensions array.
 194      */
 195      function obtain_attach_extensions($forum_id)
 196      {
 197          if (($extensions = $this->driver->get('_extensions')) === false)
 198          {
 199              $extensions = array(
 200                  '_allowed_post'    => array(),
 201                  '_allowed_pm'    => array(),
 202              );
 203   
 204              // The rule is to only allow those extensions defined. ;)
 205              $sql = 'SELECT e.extension, g.*
 206                  FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g
 207                  WHERE e.group_id = g.group_id
 208                      AND (g.allow_group = 1 OR g.allow_in_pm = 1)';
 209              $result = $this->db->sql_query($sql);
 210   
 211              while ($row = $this->db->sql_fetchrow($result))
 212              {
 213                  $extension = strtolower(trim($row['extension']));
 214   
 215                  $extensions[$extension] = array(
 216                      'display_cat'    => (int) $row['cat_id'],
 217                      'download_mode'    => (int) $row['download_mode'],
 218                      'upload_icon'    => trim($row['upload_icon']),
 219                      'max_filesize'    => (int) $row['max_filesize'],
 220                      'allow_group'    => $row['allow_group'],
 221                      'allow_in_pm'    => $row['allow_in_pm'],
 222                      'group_name'    => $row['group_name'],
 223                  );
 224   
 225                  $allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array();
 226   
 227                  // Store allowed extensions forum wise
 228                  if ($row['allow_group'])
 229                  {
 230                      $extensions['_allowed_post'][$extension] = (!sizeof($allowed_forums)) ? 0 : $allowed_forums;
 231                  }
 232   
 233                  if ($row['allow_in_pm'])
 234                  {
 235                      $extensions['_allowed_pm'][$extension] = 0;
 236                  }
 237              }
 238              $this->db->sql_freeresult($result);
 239   
 240              $this->driver->put('_extensions', $extensions);
 241          }
 242   
 243          // Forum post
 244          if ($forum_id === false)
 245          {
 246              // We are checking for private messages, therefore we only need to get the pm extensions...
 247              $return = array('_allowed_' => array());
 248   
 249              foreach ($extensions['_allowed_pm'] as $extension => $check)
 250              {
 251                  $return['_allowed_'][$extension] = 0;
 252                  $return[$extension] = $extensions[$extension];
 253              }
 254   
 255              $extensions = $return;
 256          }
 257          else if ($forum_id === true)
 258          {
 259              return $extensions;
 260          }
 261          else
 262          {
 263              $forum_id = (int) $forum_id;
 264              $return = array('_allowed_' => array());
 265   
 266              foreach ($extensions['_allowed_post'] as $extension => $check)
 267              {
 268                  // Check for allowed forums
 269                  if (is_array($check))
 270                  {
 271                      $allowed = (!in_array($forum_id, $check)) ? false : true;
 272                  }
 273                  else
 274                  {
 275                      $allowed = true;
 276                  }
 277   
 278                  if ($allowed)
 279                  {
 280                      $return['_allowed_'][$extension] = 0;
 281                      $return[$extension] = $extensions[$extension];
 282                  }
 283              }
 284   
 285              $extensions = $return;
 286          }
 287   
 288          if (!isset($extensions['_allowed_']))
 289          {
 290              $extensions['_allowed_'] = array();
 291          }
 292   
 293          return $extensions;
 294      }
 295   
 296      /**
 297      * Obtain active bots
 298      */
 299      function obtain_bots()
 300      {
 301          if (($bots = $this->driver->get('_bots')) === false)
 302          {
 303              switch ($this->db->get_sql_layer())
 304              {
 305                  case 'mssql_odbc':
 306                  case 'mssqlnative':
 307                      $sql = 'SELECT user_id, bot_agent, bot_ip
 308                          FROM ' . BOTS_TABLE . '
 309                          WHERE bot_active = 1
 310                      ORDER BY LEN(bot_agent) DESC';
 311                  break;
 312   
 313                  // LENGTH supported by MySQL, IBM DB2 and Oracle for sure...
 314                  default:
 315                      $sql = 'SELECT user_id, bot_agent, bot_ip
 316                          FROM ' . BOTS_TABLE . '
 317                          WHERE bot_active = 1
 318                      ORDER BY LENGTH(bot_agent) DESC';
 319                  break;
 320              }
 321              $result = $this->db->sql_query($sql);
 322   
 323              $bots = array();
 324              while ($row = $this->db->sql_fetchrow($result))
 325              {
 326                  $bots[] = $row;
 327              }
 328              $this->db->sql_freeresult($result);
 329   
 330              $this->driver->put('_bots', $bots);
 331          }
 332   
 333          return $bots;
 334      }
 335   
 336      /**
 337      * Obtain cfg file data
 338      */
 339      function obtain_cfg_items($style)
 340      {
 341          $parsed_array = $this->driver->get('_cfg_' . $style['style_path']);
 342   
 343          if ($parsed_array === false)
 344          {
 345              $parsed_array = array();
 346          }
 347   
 348          $filename = $this->phpbb_root_path . 'styles/' . $style['style_path'] . '/style.cfg';
 349   
 350          if (!file_exists($filename))
 351          {
 352              return $parsed_array;
 353          }
 354   
 355          if (!isset($parsed_array['filetime']) || (($this->config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime'])))
 356          {
 357              // Re-parse cfg file
 358              $parsed_array = parse_cfg_file($filename);
 359              $parsed_array['filetime'] = @filemtime($filename);
 360   
 361              $this->driver->put('_cfg_' . $style['style_path'], $parsed_array);
 362          }
 363   
 364          return $parsed_array;
 365      }
 366   
 367      /**
 368      * Obtain disallowed usernames
 369      */
 370      function obtain_disallowed_usernames()
 371      {
 372          if (($usernames = $this->driver->get('_disallowed_usernames')) === false)
 373          {
 374              $sql = 'SELECT disallow_username
 375                  FROM ' . DISALLOW_TABLE;
 376              $result = $this->db->sql_query($sql);
 377   
 378              $usernames = array();
 379              while ($row = $this->db->sql_fetchrow($result))
 380              {
 381                  $usernames[] = str_replace('%', '.*?', preg_quote(utf8_clean_string($row['disallow_username']), '#'));
 382              }
 383              $this->db->sql_freeresult($result);
 384   
 385              $this->driver->put('_disallowed_usernames', $usernames);
 386          }
 387   
 388          return $usernames;
 389      }
 390  }
 391