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

AVTHelper.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 2.68 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\Helpers;
009   
010  use DOMAttr;
011  use RuntimeException;
012   
013  abstract class AVTHelper
014  {
015      /**
016      * Parse an attribute value template
017      *
018      * @link https://www.w3.org/TR/1999/REC-xslt-19991116#dt-attribute-value-template
019      *
020      * @param  string $attrValue Attribute value
021      * @return array             Array of tokens
022      */
023      public static function parse($attrValue)
024      {
025          preg_match_all('((*MARK:literal)(?:[^{]|\\{\\{)++|(*MARK:expression)\\{(?:[^}"\']|"[^"]*+"|\'[^\']*+\')++\\}|(*MARK:junk).++)s', $attrValue, $matches);
026   
027          $tokens  = [];
028          foreach ($matches[0] as $i => $str)
029          {
030              if ($matches['MARK'][$i] === 'expression')
031              {
032                  $tokens[] = ['expression', substr($str, 1, -1)];
033              }
034              else
035              {
036                  $tokens[] = ['literal', strtr($str, ['{{' => '{', '}}' => '}'])];
037              }
038          }
039   
040          return $tokens;
041      }
042   
043      /**
044      * Replace the value of an attribute via the provided callback
045      *
046      * The callback will receive an array containing the type and value of each token in the AVT.
047      * Its return value should use the same format
048      *
049      * @param  DOMAttr  $attribute
050      * @param  callable $callback
051      * @return void
052      */
053      public static function replace(DOMAttr $attribute, callable $callback)
054      {
055          $tokens = self::parse($attribute->value);
056          foreach ($tokens as $k => $token)
057          {
058              $tokens[$k] = $callback($token);
059          }
060   
061          $attribute->value = htmlspecialchars(self::serialize($tokens), ENT_NOQUOTES, 'UTF-8');
062      }
063   
064      /**
065      * Serialize an array of AVT tokens back into an attribute value
066      *
067      * @param  array  $tokens
068      * @return string
069      */
070      public static function serialize(array $tokens)
071      {
072          $attrValue = '';
073          foreach ($tokens as $token)
074          {
075              if ($token[0] === 'literal')
076              {
077                  $attrValue .= preg_replace('([{}])', '$0$0', $token[1]);
078              }
079              elseif ($token[0] === 'expression')
080              {
081                  $attrValue .= '{' . $token[1] . '}';
082              }
083              else
084              {
085                  throw new RuntimeException('Unknown token type');
086              }
087          }
088   
089          return $attrValue;
090      }
091   
092      /**
093      * Transform given attribute value template into an XSL fragment
094      *
095      * @param  string $attrValue
096      * @return string
097      */
098      public static function toXSL($attrValue)
099      {
100          $xsl = '';
101          foreach (self::parse($attrValue) as list($type, $content))
102          {
103              if ($type === 'expression')
104              {
105                  $xsl .= '<xsl:value-of select="' . htmlspecialchars($content, ENT_COMPAT, 'UTF-8') . '"/>';
106              }
107              elseif (trim($content) !== $content)
108              {
109                  $xsl .= '<xsl:text>' . htmlspecialchars($content, ENT_NOQUOTES, 'UTF-8') . '</xsl:text>';
110              }
111              else
112              {
113                  $xsl .= htmlspecialchars($content, ENT_NOQUOTES, 'UTF-8');
114              }
115          }
116   
117          return $xsl;
118      }
119  }