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

StylesheetCompressor.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 3.00 KiB


001  <?php
002   
003  /*
004  * @package   s9e\TextFormatter
005  * @copyright Copyright (c) 2010-2016 The s9e Authors
006  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
007  */
008  namespace s9e\TextFormatter\Configurator\JavaScript;
009  use s9e\TextFormatter\Configurator\Helpers\RegexpBuilder;
010  use s9e\TextFormatter\Configurator\JavaScript\Code;
011  class StylesheetCompressor
012  {
013      protected $deduplicateTargets = array(
014          '<xsl:template match="',
015          '</xsl:template>',
016          '<xsl:apply-templates/>',
017          '<param name="allowfullscreen" value="true"/>',
018          '<xsl:value-of select="',
019          '<xsl:copy-of select="@',
020          '<iframe allowfullscreen="" scrolling="no"',
021          'overflow:hidden;position:relative;padding-bottom:',
022          'display:inline-block;width:100%;max-width:',
023          ' [-:\\w]++="',
024          '\\{[^}]++\\}',
025          '@[-\\w]{4,}+',
026          '(?<=<)[-:\\w]{4,}+',
027          '(?<==")[^"]{4,}+"'
028      );
029      protected $dictionary;
030      protected $keyPrefix = '$';
031      public $minSaving = 10;
032      protected $savings;
033      protected $xsl;
034      public function encode($xsl)
035      {
036          $this->xsl = $xsl;
037          $this->estimateSavings();
038          $this->filterSavings();
039          $this->buildDictionary();
040          $js = \json_encode($this->getCompressedStylesheet());
041          if (!empty($this->dictionary))
042              $js .= '.replace(' . $this->getReplacementRegexp() . ',function(k){return' . \json_encode($this->dictionary) . '[k]})';
043          return $js;
044      }
045      protected function buildDictionary()
046      {
047          $keys = $this->getAvailableKeys();
048          \rsort($keys);
049          $this->dictionary = array();
050          \arsort($this->savings);
051          foreach (\array_keys($this->savings) as $str)
052          {
053              $key = \array_pop($keys);
054              if (!$key)
055                  break;
056              $this->dictionary[$key] = $str;
057          }
058      }
059      protected function estimateSavings()
060      {
061          $this->savings = array();
062          foreach ($this->getStringsFrequency() as $str => $cnt)
063          {
064              $len             = \strlen($str);
065              $originalCost    = $cnt * $len;
066              $replacementCost = $cnt * 2;
067              $overhead        = $len + 6;
068              $this->savings[$str] = $originalCost - ($replacementCost + $overhead);
069          }
070      }
071      protected function filterSavings()
072      {
073          $_this = $this;
074          $this->savings = \array_filter(
075              $this->savings,
076              function ($saving) use ($_this)
077              {
078                  return ($saving >= $_this->minSaving);
079              }
080          );
081      }
082      protected function getAvailableKeys()
083      {
084          return \array_diff($this->getPossibleKeys(), $this->getUnavailableKeys());
085      }
086      protected function getCompressedStylesheet()
087      {
088          return \strtr($this->xsl, \array_flip($this->dictionary));
089      }
090      protected function getPossibleKeys()
091      {
092          $keys = array();
093          foreach (\range('a', 'z') as $char)
094              $keys[] = $this->keyPrefix . $char;
095          return $keys;
096      }
097      protected function getReplacementRegexp()
098      {
099          return '/' . RegexpBuilder::fromList(\array_keys($this->dictionary)) . '/g';
100      }
101      protected function getStringsFrequency()
102      {
103          $regexp = '(' . \implode('|', $this->deduplicateTargets) . ')S';
104          \preg_match_all($regexp, $this->xsl, $matches);
105          return \array_count_values($matches[0]);
106      }
107      protected function getUnavailableKeys()
108      {
109          \preg_match_all('(' . \preg_quote($this->keyPrefix) . '.)', $this->xsl, $matches);
110          return \array_unique($matches[0]);
111      }
112  }