Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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

version_helper.php

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 7.25 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;
 015   
 016  /**
 017   * Class to handle version checking and comparison
 018   */
 019  class version_helper
 020  {
 021      /**
 022       * @var string Host
 023       */
 024      protected $host = 'version.phpbb.com';
 025   
 026      /**
 027       * @var string Path to file
 028       */
 029      protected $path = '/phpbb';
 030   
 031      /**
 032       * @var string File name
 033       */
 034      protected $file = 'versions.json';
 035   
 036      /**
 037       * @var string Current version installed
 038       */
 039      protected $current_version;
 040   
 041      /**
 042       * @var null|string Null to not force stability, 'unstable' or 'stable' to
 043       *                    force the corresponding stability
 044       */
 045      protected $force_stability;
 046   
 047      /** @var \phpbb\cache\service */
 048      protected $cache;
 049   
 050      /** @var \phpbb\config\config */
 051      protected $config;
 052   
 053      /** @var \phpbb\user */
 054      protected $user;
 055   
 056      /**
 057       * Constructor
 058       *
 059       * @param \phpbb\cache\service $cache
 060       * @param \phpbb\config\config $config
 061       * @param \phpbb\user $user
 062       */
 063      public function __construct(\phpbb\cache\service $cache, \phpbb\config\config $config, \phpbb\user $user)
 064      {
 065          $this->cache = $cache;
 066          $this->config = $config;
 067          $this->user = $user;
 068   
 069          if (defined('PHPBB_QA'))
 070          {
 071              $this->force_stability = 'unstable';
 072          }
 073   
 074          $this->current_version = $this->config['version'];
 075      }
 076   
 077      /**
 078       * Set location to the file
 079       *
 080       * @param string $host Host (e.g. version.phpbb.com)
 081       * @param string $path Path to file (e.g. /phpbb)
 082       * @param string $file File name (Default: versions.json)
 083       * @return version_helper
 084       */
 085      public function set_file_location($host, $path, $file = 'versions.json')
 086      {
 087          $this->host = $host;
 088          $this->path = $path;
 089          $this->file = $file;
 090   
 091          return $this;
 092      }
 093   
 094      /**
 095       * Set current version
 096       *
 097       * @param string $version The current version
 098       * @return version_helper
 099       */
 100      public function set_current_version($version)
 101      {
 102          $this->current_version = $version;
 103   
 104          return $this;
 105      }
 106   
 107      /**
 108       * Over-ride the stability to force check to include unstable versions
 109       *
 110       * @param null|string Null to not force stability, 'unstable' or 'stable' to
 111       *                         force the corresponding stability
 112       * @return version_helper
 113       */
 114      public function force_stability($stability)
 115      {
 116          $this->force_stability = $stability;
 117   
 118          return $this;
 119      }
 120   
 121      /**
 122       * Wrapper for version_compare() that allows using uppercase A and B
 123       * for alpha and beta releases.
 124       *
 125       * See http://www.php.net/manual/en/function.version-compare.php
 126       *
 127       * @param string $version1        First version number
 128       * @param string $version2        Second version number
 129       * @param string $operator        Comparison operator (optional)
 130       *
 131       * @return mixed                Boolean (true, false) if comparison operator is specified.
 132       *                                Integer (-1, 0, 1) otherwise.
 133       */
 134      public function compare($version1, $version2, $operator = null)
 135      {
 136          return phpbb_version_compare($version1, $version2, $operator);
 137      }
 138   
 139      /**
 140       * Check whether or not a version is "stable"
 141       *
 142       * Stable means only numbers OR a pl release
 143       *
 144       * @param string $version
 145       * @return bool Bool true or false
 146       */
 147      public function is_stable($version)
 148      {
 149          $matches = false;
 150          preg_match('/^[\d\.]+/', $version, $matches);
 151   
 152          if (empty($matches[0]))
 153          {
 154              return false;
 155          }
 156   
 157          return $this->compare($version, $matches[0], '>=');
 158      }
 159   
 160      /**
 161      * Gets the latest version for the current branch the user is on
 162      *
 163      * @param bool $force_update Ignores cached data. Defaults to false.
 164      * @param bool $force_cache Force the use of the cache. Override $force_update.
 165      * @return string
 166      * @throws \RuntimeException
 167      */
 168      public function get_latest_on_current_branch($force_update = false, $force_cache = false)
 169      {
 170          $versions = $this->get_versions_matching_stability($force_update, $force_cache);
 171   
 172          $self = $this;
 173          $current_version = $this->current_version;
 174   
 175          // Filter out any versions less than to the current version
 176          $versions = array_filter($versions, function($data) use ($self, $current_version) {
 177              return $self->compare($data['current'], $current_version, '>=');
 178          });
 179   
 180          // Get the lowest version from the previous list.
 181          return array_reduce($versions, function($value, $data) use ($self) {
 182              if ($value === null || $self->compare($data['current'], $value, '<'))
 183              {
 184                  return $data['current'];
 185              }
 186   
 187              return $value;
 188          });
 189      }
 190   
 191      /**
 192      * Obtains the latest version information
 193      *
 194      * @param bool $force_update Ignores cached data. Defaults to false.
 195      * @param bool $force_cache Force the use of the cache. Override $force_update.
 196      * @return string
 197      * @throws \RuntimeException
 198      */
 199      public function get_suggested_updates($force_update = false, $force_cache = false)
 200      {
 201          $versions = $this->get_versions_matching_stability($force_update, $force_cache);
 202   
 203          $self = $this;
 204          $current_version = $this->current_version;
 205   
 206          // Filter out any versions less than or equal to the current version
 207          return array_filter($versions, function($data) use ($self, $current_version) {
 208              return $self->compare($data['current'], $current_version, '>');
 209          });
 210      }
 211   
 212      /**
 213      * Obtains the latest version information matching the stability of the current install
 214      *
 215      * @param bool $force_update Ignores cached data. Defaults to false.
 216      * @param bool $force_cache Force the use of the cache. Override $force_update.
 217      * @return string Version info
 218      * @throws \RuntimeException
 219      */
 220      public function get_versions_matching_stability($force_update = false, $force_cache = false)
 221      {
 222          $info = $this->get_versions($force_update, $force_cache);
 223   
 224          if ($this->force_stability !== null)
 225          {
 226              return ($this->force_stability === 'unstable') ? $info['unstable'] : $info['stable'];
 227          }
 228   
 229          return ($this->is_stable($this->current_version)) ? $info['stable'] : $info['unstable'];
 230      }
 231   
 232      /**
 233      * Obtains the latest version information
 234      *
 235      * @param bool $force_update Ignores cached data. Defaults to false.
 236      * @param bool $force_cache Force the use of the cache. Override $force_update.
 237      * @return string Version info, includes stable and unstable data
 238      * @throws \RuntimeException
 239      */
 240      public function get_versions($force_update = false, $force_cache = false)
 241      {
 242          $cache_file = '_versioncheck_' . $this->host . $this->path . $this->file;
 243   
 244          $info = $this->cache->get($cache_file);
 245   
 246          if ($info === false && $force_cache)
 247          {
 248              throw new \RuntimeException($this->user->lang('VERSIONCHECK_FAIL'));
 249          }
 250          else if ($info === false || $force_update)
 251          {
 252              $errstr = $errno = '';
 253              $info = get_remote_file($this->host, $this->path, $this->file, $errstr, $errno);
 254   
 255              if (!empty($errstr))
 256              {
 257                  throw new \RuntimeException($errstr);
 258              }
 259   
 260              $info = json_decode($info, true);
 261   
 262              if (empty($info['stable']) && empty($info['unstable']))
 263              {
 264                  $this->user->add_lang('acp/common');
 265   
 266                  throw new \RuntimeException($this->user->lang('VERSIONCHECK_FAIL'));
 267              }
 268   
 269              // Replace & with &amp; on announcement links
 270              foreach ($info as $stability => $branches)
 271              {
 272                  foreach ($branches as $branch => $branch_data)
 273                  {
 274                      $info[$stability][$branch]['announcement'] = str_replace('&', '&amp;', $branch_data['announcement']);
 275                  }
 276              }
 277   
 278              $info['stable'] = (empty($info['stable'])) ? array() : $info['stable'];
 279              $info['unstable'] = (empty($info['unstable'])) ? $info['stable'] : $info['unstable'];
 280   
 281              $this->cache->put($cache_file, $info, 86400); // 24 hours
 282          }
 283   
 284          return $info;
 285      }
 286  }
 287