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

Repository.php

Zuletzt modifiziert: 09.10.2024, 12:59 - Dateigröße: 2.66 KiB


01  <?php
02   
03  /*
04  * @package   s9e\TextFormatter
05  * @copyright Copyright (c) 2010-2016 The s9e Authors
06  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
07  */
08  namespace s9e\TextFormatter\Plugins\BBCodes\Configurator;
09  use DOMDocument;
10  use DOMElement;
11  use DOMXPath;
12  use InvalidArgumentException;
13  use RuntimeException;
14  class Repository
15  {
16      protected $bbcodeMonkey;
17      protected $dom;
18      public function __construct($value, BBCodeMonkey $bbcodeMonkey)
19      {
20          if (!($value instanceof DOMDocument))
21          {
22              if (!\file_exists($value))
23                  throw new InvalidArgumentException('Not a DOMDocument or the path to a repository file');
24              $dom = new DOMDocument;
25              $dom->preserveWhiteSpace = \false;
26              $useErrors = \libxml_use_internal_errors(\true);
27              $success = $dom->load($value);
28              \libxml_use_internal_errors($useErrors);
29              if (!$success)
30                  throw new InvalidArgumentException('Invalid repository file');
31              $value = $dom;
32          }
33          $this->bbcodeMonkey = $bbcodeMonkey;
34          $this->dom = $value;
35      }
36      public function get($name, array $vars = array())
37      {
38          $name = \preg_replace_callback(
39              '/^[^#]+/',
40              function ($m)
41              {
42                  return BBCode::normalizeName($m[0]);
43              },
44              $name
45          );
46          $xpath = new DOMXPath($this->dom);
47          $node  = $xpath->query('//bbcode[@name="' . \htmlspecialchars($name) . '"]')->item(0);
48          if (!($node instanceof DOMElement))
49              throw new RuntimeException("Could not find '" . $name . "' in repository");
50          $clonedNode = $node->cloneNode(\true);
51          foreach ($xpath->query('.//var', $clonedNode) as $varNode)
52          {
53              $varName = $varNode->getAttribute('name');
54              if (isset($vars[$varName]))
55                  $varNode->parentNode->replaceChild(
56                      $this->dom->createTextNode($vars[$varName]),
57                      $varNode
58                  );
59          }
60          $usage      = $xpath->evaluate('string(usage)', $clonedNode);
61          $template   = $xpath->evaluate('string(template)', $clonedNode);
62          $config     = $this->bbcodeMonkey->create($usage, $template);
63          $bbcode     = $config['bbcode'];
64          $bbcodeName = $config['bbcodeName'];
65          $tag        = $config['tag'];
66          if ($node->hasAttribute('tagName'))
67              $bbcode->tagName = $node->getAttribute('tagName');
68          foreach ($xpath->query('rules/*', $node) as $ruleNode)
69          {
70              $methodName = $ruleNode->nodeName;
71              $args       = array();
72              if ($ruleNode->textContent)
73                  $args[] = $ruleNode->textContent;
74              \call_user_func_array(array($tag->rules, $methodName), $args);
75          }
76          foreach ($node->getElementsByTagName('predefinedAttributes') as $predefinedAttributes)
77              foreach ($predefinedAttributes->attributes as $attribute)
78                  $bbcode->predefinedAttributes->set($attribute->name, $attribute->value);
79          return array(
80              'bbcode'     => $bbcode,
81              'bbcodeName' => $bbcodeName,
82              'tag'        => $tag
83          );
84      }
85  }