Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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

Template.php

Zuletzt modifiziert: 01.05.2026, 11:28 - Dateigröße: 4.16 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\Items;
 009   
 010  use DOMDocument;
 011  use s9e\TextFormatter\Configurator\Helpers\NodeLocator;
 012  use s9e\TextFormatter\Configurator\Helpers\TemplateHelper;
 013  use s9e\TextFormatter\Configurator\Helpers\TemplateInspector;
 014  use s9e\TextFormatter\Configurator\Helpers\TemplateModifier;
 015  use s9e\TextFormatter\Configurator\TemplateNormalizer;
 016   
 017  class Template
 018  {
 019      /**
 020      * @var TemplateInspector Instance of TemplateInspector based on the content of this template
 021      */
 022      protected $inspector;
 023   
 024      /**
 025      * @var bool Whether this template has been normalized
 026      */
 027      protected $isNormalized = false;
 028   
 029      /**
 030      * @var string This template's content
 031      */
 032      protected $template;
 033   
 034      /**
 035      * Constructor
 036      *
 037      * @param  string $template This template's content
 038      */
 039      public function __construct($template)
 040      {
 041          $this->template = $template;
 042      }
 043   
 044      /**
 045      * Handle calls to undefined methods
 046      *
 047      * Forwards calls to this template's TemplateInspector instance
 048      *
 049      * @return mixed
 050      */
 051      public function __call($methodName, $args)
 052      {
 053          return call_user_func_array([$this->getInspector(), $methodName], $args);
 054      }
 055   
 056      /**
 057      * Return this template's content
 058      *
 059      * @return string
 060      */
 061      public function __toString()
 062      {
 063          return $this->template;
 064      }
 065   
 066      /**
 067      * Return the content of this template as a DOMDocument
 068      *
 069      * NOTE: the content is wrapped in an <xsl:template/> node
 070      *
 071      * @return DOMDocument
 072      */
 073      public function asDOM()
 074      {
 075          $xml = '<xsl:template xmlns:xsl="http://www.w3.org/1999/XSL/Transform">'
 076               . $this->__toString()
 077               . '</xsl:template>';
 078   
 079          $dom = new TemplateDocument($this);
 080          $dom->loadXML($xml);
 081   
 082          return $dom;
 083      }
 084   
 085      /**
 086      * Return all the nodes in this template whose content type is CSS
 087      *
 088      * @return array
 089      */
 090      public function getCSSNodes()
 091      {
 092          return NodeLocator::getCSSNodes($this->asDOM());
 093      }
 094   
 095      /**
 096      * Return an instance of TemplateInspector based on this template's content
 097      *
 098      * @return TemplateInspector
 099      */
 100      public function getInspector()
 101      {
 102          if (!isset($this->inspector))
 103          {
 104              $this->inspector = new TemplateInspector($this->__toString());
 105          }
 106   
 107          return $this->inspector;
 108      }
 109   
 110      /**
 111      * Return all the nodes in this template whose content type is JavaScript
 112      *
 113      * @return array
 114      */
 115      public function getJSNodes()
 116      {
 117          return NodeLocator::getJSNodes($this->asDOM());
 118      }
 119   
 120      /**
 121      * Return all the nodes in this template whose value is an URL
 122      *
 123      * @return array
 124      */
 125      public function getURLNodes()
 126      {
 127          return NodeLocator::getURLNodes($this->asDOM());
 128      }
 129   
 130      /**
 131      * Return a list of parameters in use in this template
 132      *
 133      * @return array Alphabetically sorted list of unique parameter names
 134      */
 135      public function getParameters()
 136      {
 137          return TemplateHelper::getParametersFromXSL($this->__toString());
 138      }
 139   
 140      /**
 141      * Set and/or return whether this template has been normalized
 142      *
 143      * @param  bool $bool If present, the new value for this template's isNormalized flag
 144      * @return bool       Whether this template has been normalized
 145      */
 146      public function isNormalized($bool = null)
 147      {
 148          if (isset($bool))
 149          {
 150              $this->isNormalized = $bool;
 151          }
 152   
 153          return $this->isNormalized;
 154      }
 155   
 156      /**
 157      * Normalize this template's content
 158      *
 159      * @param  TemplateNormalizer $templateNormalizer
 160      * @return void
 161      */
 162      public function normalize(TemplateNormalizer $templateNormalizer)
 163      {
 164          $this->inspector    = null;
 165          $this->template     = $templateNormalizer->normalizeTemplate($this->template);
 166          $this->isNormalized = true;
 167      }
 168   
 169      /**
 170      * Replace parts of this template that match given regexp
 171      *
 172      * @param  string   $regexp Regexp for matching parts that need replacement
 173      * @param  callable $fn     Callback used to get the replacement
 174      * @return void
 175      */
 176      public function replaceTokens($regexp, $fn)
 177      {
 178          $this->inspector    = null;
 179          $this->template     = TemplateModifier::replaceTokens($this->template, $regexp, $fn);
 180          $this->isNormalized = false;
 181      }
 182   
 183      /**
 184      * Replace this template's content
 185      *
 186      * @param  string $template New content
 187      * @return void
 188      */
 189      public function setContent($template)
 190      {
 191          $this->inspector    = null;
 192          $this->template     = (string) $template;
 193          $this->isNormalized = false;
 194      }
 195  }