Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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

viglink_helper.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 3.77 KiB


001  <?php
002  /**
003   *
004   * VigLink extension for the phpBB Forum Software package.
005   *
006   * @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
007   * @license GNU General Public License, version 2 (GPL-2.0)
008   *
009   */
010   
011  namespace phpbb\viglink\acp;
012   
013  /**
014   * Class to handle allowing or disallowing VigLink services
015   */
016  class viglink_helper
017  {
018      /** @var \phpbb\cache\driver\driver_interface $cache */
019      protected $cache;
020   
021      /** @var \phpbb\config\config $config */
022      protected $config;
023   
024      /** @var \phpbb\file_downloader $file_downloader */
025      protected $file_downloader;
026   
027      /** @var \phpbb\language\language $language */
028      protected $language;
029   
030      /** @var \phpbb\log\log $log */
031      protected $log;
032   
033      /** @var \phpbb\user $user */
034      protected $user;
035   
036      /** @var bool Use SSL or not */
037      protected $use_ssl = false;
038   
039      /**
040       * Constructor
041       *
042       * @param \phpbb\cache\driver\driver_interface $cache
043       * @param \phpbb\config\config                 $config
044       * @param \phpbb\file_downloader               $file_downloader
045       * @param \phpbb\language\language             $language
046       * @param \phpbb\log\log                       $log
047       * @param \phpbb\user                          $user
048       */
049      public function __construct(\phpbb\cache\driver\driver_interface $cache, \phpbb\config\config $config, \phpbb\file_downloader $file_downloader, \phpbb\language\language $language, \phpbb\log\log $log, \phpbb\user $user)
050      {
051          $this->cache = $cache;
052          $this->config = $config;
053          $this->file_downloader = $file_downloader;
054          $this->language = $language;
055          $this->log = $log;
056          $this->user = $user;
057      }
058   
059      /**
060       * Obtains the latest VigLink services information from phpBB
061       *
062       * @param bool $force_update Ignores cached data. Defaults to false.
063       * @param bool $force_cache  Force the use of the cache. Override $force_update.
064       *
065       * @throws \RuntimeException
066       *
067       * @return void
068       */
069      public function set_viglink_services($force_update = false, $force_cache = false)
070      {
071          $cache_key = '_versioncheck_viglink_' . $this->use_ssl;
072   
073          $info = $this->cache->get($cache_key);
074   
075          if ($info === false && $force_cache)
076          {
077              throw new \RuntimeException($this->language->lang('VERSIONCHECK_FAIL'));
078          }
079   
080          if ($info === false || $force_update)
081          {
082              try
083              {
084                  $info = $this->file_downloader->get('www.phpbb.com', '/viglink', 'enabled', 443);
085              }
086              catch (\phpbb\exception\runtime_exception $exception)
087              {
088                  $prepare_parameters = array_merge(array($exception->getMessage()), $exception->get_parameters());
089                  throw new \RuntimeException(call_user_func_array(array($this->language, 'lang'), $prepare_parameters));
090              }
091   
092              if ($info === '0')
093              {
094                  $this->set_viglink_configs(array(
095                      'allow_viglink_phpbb'    => false,
096                  ));
097              }
098              else
099              {
100                  $info = '1';
101                  $this->set_viglink_configs(array(
102                      'allow_viglink_phpbb'    => true,
103                  ));
104              }
105   
106              $this->cache->put($cache_key, $info, 86400); // 24 hours
107          }
108      }
109   
110      /**
111       * Sets VigLink service configs as determined by phpBB
112       *
113       * @param array $data Array of VigLink file data.
114       *
115       * @return void
116       */
117      protected function set_viglink_configs($data)
118      {
119          $viglink_configs = array(
120              'allow_viglink_phpbb',
121              'phpbb_viglink_api_key',
122          );
123   
124          foreach ($viglink_configs as $cfg_name)
125          {
126              if (array_key_exists($cfg_name, $data) && ($data[$cfg_name] != $this->config[$cfg_name] || !isset($this->config[$cfg_name])))
127              {
128                  $this->config->set($cfg_name, $data[$cfg_name]);
129              }
130          }
131   
132          $this->config->set('viglink_last_gc', time(), false);
133      }
134   
135      /**
136       * Log a VigLink error message to the error log
137       *
138       * @param string $message The error message
139       */
140      public function log_viglink_error($message)
141      {
142          $user_id = empty($this->user->data) ? ANONYMOUS : $this->user->data['user_id'];
143          $user_ip = empty($this->user->ip) ? '' : $this->user->ip;
144   
145          $this->log->add('critical', $user_id, $user_ip, 'LOG_VIGLINK_CHECK_FAIL', false, array($message));
146      }
147  }
148