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

Parser.php

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


01  <?php
02   
03  /**
04  * @package   s9e\TextFormatter
05  * @copyright Copyright (c) 2010-2022 The s9e authors
06  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
07  */
08  namespace s9e\TextFormatter\Plugins\HTMLElements;
09   
10  use s9e\TextFormatter\Parser\Tag;
11  use s9e\TextFormatter\Plugins\ParserBase;
12   
13  class Parser extends ParserBase
14  {
15      /**
16      * {@inheritdoc}
17      */
18      public function parse($text, array $matches)
19      {
20          foreach ($matches as $m)
21          {
22              // Test whether this is an end tag
23              $isEnd = (bool) ($text[$m[0][1] + 1] === '/');
24   
25              $pos    = $m[0][1];
26              $len    = strlen($m[0][0]);
27              $elName = strtolower($m[2 - $isEnd][0]);
28   
29              // Use the element's alias if applicable, or the  name of the element (with the
30              // configured prefix) otherwise
31              $tagName = (isset($this->config['aliases'][$elName]['']))
32                       ? $this->config['aliases'][$elName]['']
33                       : $this->config['prefix'] . ':' . $elName;
34   
35              if ($isEnd)
36              {
37                  $this->parser->addEndTag($tagName, $pos, $len);
38                  continue;
39              }
40   
41              // Test whether it's a self-closing tag or a start tag.
42              //
43              // A self-closing tag will become one start tag consuming all of the text followed by a
44              // 0-width end tag. Alternatively, it could be replaced by a pair of 0-width tags plus
45              // an ignore tag to prevent the text in between from being output
46              $tag = (preg_match('/(<\\S+|[\'"\\s])\\/>$/', $m[0][0]))
47                   ? $this->parser->addTagPair($tagName, $pos, $len, $pos + $len, 0)
48                   : $this->parser->addStartTag($tagName, $pos, $len);
49   
50              $this->captureAttributes($tag, $elName, $m[3][0]);
51          }
52      }
53   
54      /**
55      * Capture all attributes in given string
56      *
57      * @param  Tag    $tag    Target tag
58      * @param  string $elName Name of the HTML element
59      * @param  string $str    String containing the attribute declarations
60      * @return void
61      */
62      protected function captureAttributes(Tag $tag, $elName, $str)
63      {
64          $regexp = '/([a-z][-a-z0-9]*)(?>\\s*=\\s*("[^"]*"|\'[^\']*\'|[^\\s"\'=<>`]+))?/i';
65          preg_match_all($regexp, $str, $matches, PREG_SET_ORDER);
66   
67          foreach ($matches as $m)
68          {
69              /**
70              * If there's no value, it's a boolean attribute and we generate a value equal
71              * to the attribute's name, lowercased
72              *
73              * @link http://www.w3.org/html/wg/drafts/html/master/single-page.html#boolean-attributes
74              */
75              $attrName  = strtolower($m[1]);
76              $attrValue = $m[2] ?? $attrName;
77   
78              // Use the attribute's alias if applicable
79              if (isset($this->config['aliases'][$elName][$attrName]))
80              {
81                  $attrName = $this->config['aliases'][$elName][$attrName];
82              }
83   
84              // Remove quotes around the value
85              if ($attrValue[0] === '"' || $attrValue[0] === "'")
86              {
87                  $attrValue = substr($attrValue, 1, -1);
88              }
89   
90              $tag->setAttribute($attrName, html_entity_decode($attrValue, ENT_QUOTES, 'UTF-8'));
91          }
92      }
93  }