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

Utils.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 3.13 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;
009  use DOMDocument;
010  use DOMXPath;
011  abstract class Utils
012  {
013      public static function getAttributeValues($xml, $tagName, $attrName)
014      {
015          $values = array();
016          if (\strpos($xml, '<' . $tagName) !== \false)
017          {
018              $regexp = '(<' . \preg_quote($tagName) . '(?= )[^>]*? ' . \preg_quote($attrName) . '="([^"]*+))';
019              \preg_match_all($regexp, $xml, $matches);
020              foreach ($matches[1] as $value)
021                  $values[] = \html_entity_decode($value, \ENT_QUOTES, 'UTF-8');
022          }
023          return $values;
024      }
025      public static function encodeUnicodeSupplementaryCharacters($str)
026      {
027          return \preg_replace_callback(
028              '([\\xF0-\\xF4]...)S',
029              __CLASS__ . '::encodeUnicodeSupplementaryCharactersCallback',
030              $str
031          );
032      }
033      public static function removeFormatting($xml)
034      {
035          $dom   = self::loadXML($xml);
036          $xpath = new DOMXPath($dom);
037          foreach ($xpath->query('//e | //s') as $node)
038              $node->parentNode->removeChild($node);
039          return $dom->documentElement->textContent;
040      }
041      public static function removeTag($xml, $tagName, $nestingLevel = 0)
042      {
043          if (\strpos($xml, '<' . $tagName) === \false)
044              return $xml;
045          $dom   = self::loadXML($xml);
046          $xpath = new DOMXPath($dom);
047          $nodes = $xpath->query(\str_repeat('//' . $tagName, 1 + $nestingLevel));
048          foreach ($nodes as $node)
049              $node->parentNode->removeChild($node);
050          return self::saveXML($dom);
051      }
052      public static function replaceAttributes($xml, $tagName, $callback)
053      {
054          $_self = __CLASS__;
055          if (\strpos($xml, '<' . $tagName) === \false)
056              return $xml;
057          return \preg_replace_callback(
058              '((<' . \preg_quote($tagName) . ')(?=[ />])[^>]*?(/?>))',
059              function ($m) use ($callback, $_self)
060              {
061                  return $m[1] . $_self::serializeAttributes($callback($_self::parseAttributes($m[0]))) . $m[2];
062              },
063              $xml
064          );
065      }
066      protected static function encodeUnicodeSupplementaryCharactersCallback(array $m)
067      {
068          $utf8 = $m[0];
069          $cp   = (\ord($utf8[0]) << 18) + (\ord($utf8[1]) << 12) + (\ord($utf8[2]) << 6) + \ord($utf8[3]) - 0x3C82080;
070          return '&#' . $cp . ';';
071      }
072      protected static function loadXML($xml)
073      {
074          $flags = (\LIBXML_VERSION >= 20700) ? \LIBXML_COMPACT | \LIBXML_PARSEHUGE : 0;
075          $dom = new DOMDocument;
076          $dom->loadXML($xml, $flags);
077          return $dom;
078      }
079      public static function parseAttributes($xml)
080      {
081          $attributes = array();
082          if (\strpos($xml, '="') !== \false)
083          {
084              \preg_match_all('(([^ =]++)="([^"]*))S', $xml, $matches);
085              foreach ($matches[1] as $i => $attrName)
086                  $attributes[$attrName] = \html_entity_decode($matches[2][$i], \ENT_QUOTES, 'UTF-8');
087          }
088          return $attributes;
089      }
090      protected static function saveXML(DOMDocument $dom)
091      {
092          return self::encodeUnicodeSupplementaryCharacters($dom->saveXML($dom->documentElement));
093      }
094      public static function serializeAttributes(array $attributes)
095      {
096          $xml = '';
097          \ksort($attributes);
098          foreach ($attributes as $attrName => $attrValue)
099              $xml .= ' ' . \htmlspecialchars($attrName, \ENT_QUOTES) . '="' . self::encodeUnicodeSupplementaryCharacters(\htmlspecialchars($attrValue, \ENT_COMPAT)) . '"';
100          return $xml;
101      }
102  }