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

HintGenerator.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 4.48 KiB


001  <?php
002   
003  /**
004  * @package   s9e\TextFormatter
005  * @copyright Copyright (c) 2010-2022 The s9e authors
006  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
007  */
008  namespace s9e\TextFormatter\Configurator\JavaScript;
009   
010  use ReflectionClass;
011  use s9e\TextFormatter\Configurator\Collections\PluginCollection;
012   
013  class HintGenerator
014  {
015      /**
016      * @var array Config on which hints are based
017      */
018      protected $config;
019   
020      /**
021      * @var array Generated hints
022      */
023      protected $hints;
024   
025      /**
026      * @var PluginCollection Configured plugins
027      */
028      protected $plugins;
029   
030      /**
031      * @var string XSL stylesheet on which hints are based
032      */
033      protected $xsl;
034   
035      /**
036      * Generate a HINT object that contains informations about the configuration
037      *
038      * @return string JavaScript Code
039      */
040      public function getHints()
041      {
042          $this->hints = [];
043          $this->setPluginsHints();
044          $this->setRenderingHints();
045          $this->setRulesHints();
046          $this->setTagsHints();
047   
048          // Build the source. Note that Closure Compiler seems to require that each of HINT's
049          // properties be declared as a const
050          $js = "/** @const */ var HINT={};\n";
051          ksort($this->hints);
052          foreach ($this->hints as $hintName => $hintValue)
053          {
054              $js .= '/** @const */ HINT.' . $hintName . '=' . json_encode($hintValue) . ";\n";
055          }
056   
057          return $js;
058      }
059   
060      /**
061      * Set the config on which hints are based
062      *
063      * @param  array $config
064      * @return void
065      */
066      public function setConfig(array $config)
067      {
068          $this->config = $config;
069      }
070   
071      /**
072      * Set the collection of plugins
073      *
074      * @param  PluginCollection $plugins
075      * @return void
076      */
077      public function setPlugins(PluginCollection $plugins)
078      {
079          $this->plugins = $plugins;
080      }
081   
082      /**
083      * Set the XSL on which hints are based
084      *
085      * @param  string $xsl
086      * @return void
087      */
088      public function setXSL($xsl)
089      {
090          $this->xsl = $xsl;
091      }
092   
093      /**
094      * Set custom hints from plugins
095      *
096      * @return void
097      */
098      protected function setPluginsHints()
099      {
100          foreach ($this->plugins as $plugin)
101          {
102              $this->hints += $plugin->getJSHints();
103          }
104   
105          $this->hints['regexp']      = 0;
106          $this->hints['regexpLimit'] = 0;
107          foreach ($this->config['plugins'] as $pluginConfig)
108          {
109              $this->hints['regexp']      |= isset($pluginConfig['regexp']);
110              $this->hints['regexpLimit'] |= isset($pluginConfig['regexpLimit']);
111          }
112      }
113   
114      /**
115      * Set hints related to rendering
116      *
117      * @return void
118      */
119      protected function setRenderingHints()
120      {
121          // Test for post-processing in templates. Theorically allows for false positives and
122          // false negatives, but not in any realistic setting
123          $hints = [
124              'hash'        => 'data-s9e-livepreview-hash',
125              'ignoreAttrs' => 'data-s9e-livepreview-ignore-attrs',
126              'onRender'    => 'data-s9e-livepreview-onrender',
127              'onUpdate'    => 'data-s9e-livepreview-onupdate'
128          ];
129          foreach ($hints as $hintName => $match)
130          {
131              $this->hints[$hintName] = (int) (strpos($this->xsl, $match) !== false);
132          }
133      }
134   
135      /**
136      * Set hints related to rules
137      *
138      * @return void
139      */
140      protected function setRulesHints()
141      {
142          $this->hints['closeAncestor']   = 0;
143          $this->hints['closeParent']     = 0;
144          $this->hints['createChild']     = 0;
145          $this->hints['fosterParent']    = 0;
146          $this->hints['requireAncestor'] = 0;
147   
148          $flags = 0;
149          foreach ($this->config['tags'] as $tagConfig)
150          {
151              // Test which rules are in use
152              foreach (array_intersect_key($tagConfig['rules'], $this->hints) as $k => $v)
153              {
154                  $this->hints[$k] = 1;
155              }
156              $flags |= $tagConfig['rules']['flags'];
157          }
158          $flags |= $this->config['rootContext']['flags'];
159   
160          // Iterate over Parser::RULE_* constants and test which flags are set
161          $parser = new ReflectionClass('s9e\\TextFormatter\\Parser');
162          foreach ($parser->getConstants() as $constName => $constValue)
163          {
164              if (substr($constName, 0, 5) === 'RULE_')
165              {
166                  // This will set HINT.RULE_AUTO_CLOSE and others
167                  $this->hints[$constName] = ($flags & $constValue) ? 1 : 0;
168              }
169          }
170      }
171   
172      /**
173      * Set hints based on given tag's attributes config
174      *
175      * @param  array $tagConfig
176      * @return void
177      */
178      protected function setTagAttributesHints(array $tagConfig)
179      {
180          if (empty($tagConfig['attributes']))
181          {
182              return;
183          }
184   
185          foreach ($tagConfig['attributes'] as $attrConfig)
186          {
187              $this->hints['attributeDefaultValue'] |= isset($attrConfig['defaultValue']);
188          }
189      }
190   
191      /**
192      * Set hints related to tags config
193      *
194      * @return void
195      */
196      protected function setTagsHints()
197      {
198          $this->hints['attributeDefaultValue'] = 0;
199          $this->hints['namespaces']            = 0;
200          foreach ($this->config['tags'] as $tagName => $tagConfig)
201          {
202              $this->hints['namespaces'] |= (strpos($tagName, ':') !== false);
203              $this->setTagAttributesHints($tagConfig);
204          }
205      }
206  }