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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
viglink_helper.php
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\language\language $language */
019 protected $language;
020
021 /** @var \phpbb\log\log $log */
022 protected $log;
023
024 /** @var \phpbb\user $user */
025 protected $user;
026
027 /** @var bool Use SSL or not */
028 protected $use_ssl = false;
029
030 /**
031 * Constructor
032 *
033 * @param \phpbb\cache\service $cache
034 * @param \phpbb\config\config $config
035 * @param \phpbb\file_downloader $file_downloader
036 * @param \phpbb\language\language $language
037 * @param \phpbb\log\log $log
038 * @param \phpbb\user $user
039 */
040 public function __construct(\phpbb\cache\service $cache, \phpbb\config\config $config, \phpbb\file_downloader $file_downloader, \phpbb\language\language $language, \phpbb\log\log $log, \phpbb\user $user)
041 {
042 $this->cache = $cache;
043 $this->config = $config;
044 $this->file_downloader = $file_downloader;
045 $this->language = $language;
046 $this->log = $log;
047 $this->user = $user;
048 }
049
050 /**
051 * Obtains the latest VigLink services information from phpBB
052 *
053 * @param bool $force_update Ignores cached data. Defaults to false.
054 * @param bool $force_cache Force the use of the cache. Override $force_update.
055 *
056 * @throws \RuntimeException
057 *
058 * @return void
059 */
060 public function set_viglink_services($force_update = false, $force_cache = false)
061 {
062 $cache_key = '_versioncheck_viglink_' . $this->use_ssl;
063
064 $info = $this->cache->get($cache_key);
065
066 if ($info === false && $force_cache)
067 {
068 throw new \RuntimeException($this->language->lang('VERSIONCHECK_FAIL'));
069 }
070 else if ($info === false || $force_update)
071 {
072 try
073 {
074 $info = $this->file_downloader->get('www.phpbb.com', '/viglink', 'enabled', 443);
075 }
076 catch (\phpbb\exception\runtime_exception $exception)
077 {
078 $prepare_parameters = array_merge(array($exception->getMessage()), $exception->get_parameters());
079 throw new \RuntimeException(call_user_func_array(array($this->language, 'lang'), $prepare_parameters));
080 }
081
082 if ($info === '0')
083 {
084 $this->set_viglink_configs(array(
085 'allow_viglink_phpbb' => false,
086 ));
087 }
088 else
089 {
090 $info = '1';
091 $this->set_viglink_configs(array(
092 'allow_viglink_phpbb' => true,
093 ));
094 }
095
096 $this->cache->put($cache_key, $info, 86400); // 24 hours
097 }
098 }
099
100 /**
101 * Sets VigLink service configs as determined by phpBB
102 *
103 * @param array $data Array of VigLink file data.
104 *
105 * @return void
106 */
107 protected function set_viglink_configs($data)
108 {
109 $viglink_configs = array(
110 'allow_viglink_phpbb',
111 'phpbb_viglink_api_key',
112 );
113
114 foreach ($viglink_configs as $cfg_name)
115 {
116 if (array_key_exists($cfg_name, $data) && ($data[$cfg_name] != $this->config[$cfg_name] || !isset($this->config[$cfg_name])))
117 {
118 $this->config->set($cfg_name, $data[$cfg_name]);
119 }
120 }
121
122 $this->config->set('viglink_last_gc', time(), false);
123 }
124
125 /**
126 * Log a VigLink error message to the error log
127 *
128 * @param string $message The error message
129 */
130 public function log_viglink_error($message)
131 {
132 $user_id = empty($this->user->data) ? ANONYMOUS : $this->user->data['user_id'];
133 $user_ip = empty($this->user->ip) ? '' : $this->user->ip;
134
135 $this->log->add('critical', $user_id, $user_ip, 'LOG_VIGLINK_CHECK_FAIL', false, array($message));
136 }
137 }
138