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

Parser.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 5.73 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\Plugins\BBCodes;
009  use RuntimeException;
010  use s9e\TextFormatter\Parser\Tag;
011  use s9e\TextFormatter\Plugins\ParserBase;
012  class Parser extends ParserBase
013  {
014      protected $attributes;
015      protected $bbcodeConfig;
016      protected $bbcodeName;
017      protected $bbcodeSuffix;
018      protected $pos;
019      protected $startPos;
020      protected $text;
021      protected $textLen;
022      protected $uppercaseText;
023      public function parse($text, array $matches)
024      {
025          $this->text          = $text;
026          $this->textLen       = \strlen($text);
027          $this->uppercaseText = '';
028          foreach ($matches as $m)
029          {
030              $this->bbcodeName = \strtoupper($m[1][0]);
031              if (!isset($this->config['bbcodes'][$this->bbcodeName]))
032                  continue;
033              $this->bbcodeConfig = $this->config['bbcodes'][$this->bbcodeName];
034              $this->startPos     = $m[0][1];
035              $this->pos          = $this->startPos + \strlen($m[0][0]);
036              try
037              {
038                  $this->parseBBCode();
039              }
040              catch (RuntimeException $e)
041              {
042                  }
043          }
044      }
045      protected function addBBCodeEndTag()
046      {
047          return $this->parser->addEndTag($this->getTagName(), $this->startPos, $this->pos - $this->startPos);
048      }
049      protected function addBBCodeSelfClosingTag()
050      {
051          $tag = $this->parser->addSelfClosingTag($this->getTagName(), $this->startPos, $this->pos - $this->startPos);
052          $tag->setAttributes($this->attributes);
053          return $tag;
054      }
055      protected function addBBCodeStartTag()
056      {
057          $tag = $this->parser->addStartTag($this->getTagName(), $this->startPos, $this->pos - $this->startPos);
058          $tag->setAttributes($this->attributes);
059          return $tag;
060      }
061      protected function captureEndTag()
062      {
063          if (empty($this->uppercaseText))
064              $this->uppercaseText = \strtoupper($this->text);
065          $match     = '[/' . $this->bbcodeName . $this->bbcodeSuffix . ']';
066          $endTagPos = \strpos($this->uppercaseText, $match, $this->pos);
067          if ($endTagPos === \false)
068              return;
069          return $this->parser->addEndTag($this->getTagName(), $endTagPos, \strlen($match));
070      }
071      protected function getTagName()
072      {
073          return (isset($this->bbcodeConfig['tagName']))
074               ? $this->bbcodeConfig['tagName']
075               : $this->bbcodeName;
076      }
077      protected function parseAttributes()
078      {
079          $firstPos = $this->pos;
080          $this->attributes = array();
081          while ($this->pos < $this->textLen)
082          {
083              $c = $this->text[$this->pos];
084              if (\strpos(" \n\t", $c) !== \false)
085              {
086                  ++$this->pos;
087                  continue;
088              }
089              if (\strpos('/]', $c) !== \false)
090                  return;
091              $spn = \strspn($this->text, 'abcdefghijklmnopqrstuvwxyz_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-', $this->pos);
092              if ($spn)
093              {
094                  $attrName = \strtolower(\substr($this->text, $this->pos, $spn));
095                  $this->pos += $spn;
096                  if ($this->pos >= $this->textLen)
097                      throw new RuntimeException;
098                  if ($this->text[$this->pos] !== '=')
099                      continue;
100              }
101              elseif ($c === '=' && $this->pos === $firstPos)
102                  $attrName = (isset($this->bbcodeConfig['defaultAttribute']))
103                            ? $this->bbcodeConfig['defaultAttribute']
104                            : \strtolower($this->bbcodeName);
105              else
106                  throw new RuntimeException;
107              if (++$this->pos >= $this->textLen)
108                  throw new RuntimeException;
109              $this->attributes[$attrName] = $this->parseAttributeValue();
110          }
111      }
112      protected function parseAttributeValue()
113      {
114          if ($this->text[$this->pos] === '"' || $this->text[$this->pos] === "'")
115              return $this->parseQuotedAttributeValue();
116          if (!\preg_match('#[^\\]\\n]*?(?=\\s*(?:\\s/)?\\]|\\s+[-\\w]+=)#', $this->text, $m, \null, $this->pos))
117              throw new RuntimeException;
118          $attrValue  = $m[0];
119          $this->pos += \strlen($attrValue);
120          return $attrValue;
121      }
122      protected function parseBBCode()
123      {
124          $this->parseBBCodeSuffix();
125          if ($this->text[$this->startPos + 1] === '/')
126          {
127              if (\substr($this->text, $this->pos, 1) === ']' && $this->bbcodeSuffix === '')
128              {
129                  ++$this->pos;
130                  $this->addBBCodeEndTag();
131              }
132              return;
133          }
134          $this->parseAttributes();
135          if (isset($this->bbcodeConfig['predefinedAttributes']))
136              $this->attributes += $this->bbcodeConfig['predefinedAttributes'];
137          if (\substr($this->text, $this->pos, 1) === ']')
138              ++$this->pos;
139          else
140          {
141              if (\substr($this->text, $this->pos, 2) === '/]')
142              {
143                  $this->pos += 2;
144                  $this->addBBCodeSelfClosingTag();
145              }
146              return;
147          }
148          $contentAttributes = array();
149          if (isset($this->bbcodeConfig['contentAttributes']))
150              foreach ($this->bbcodeConfig['contentAttributes'] as $attrName)
151                  if (!isset($this->attributes[$attrName]))
152                      $contentAttributes[] = $attrName;
153          $requireEndTag = ($this->bbcodeSuffix || !empty($this->bbcodeConfig['forceLookahead']));
154          $endTag = ($requireEndTag || !empty($contentAttributes)) ? $this->captureEndTag() : \null;
155          if (isset($endTag))
156              foreach ($contentAttributes as $attrName)
157                  $this->attributes[$attrName] = \substr($this->text, $this->pos, $endTag->getPos() - $this->pos);
158          elseif ($requireEndTag)
159              return;
160          $tag = $this->addBBCodeStartTag();
161          if (isset($endTag))
162              $tag->pairWith($endTag);
163      }
164      protected function parseBBCodeSuffix()
165      {
166          $this->bbcodeSuffix = '';
167          if ($this->text[$this->pos] === ':')
168          {
169              $spn = 1 + \strspn($this->text, '0123456789', 1 + $this->pos);
170              $this->bbcodeSuffix = \substr($this->text, $this->pos, $spn);
171              $this->pos += $spn;
172          }
173      }
174      protected function parseQuotedAttributeValue()
175      {
176          $quote    = $this->text[$this->pos];
177          $valuePos = $this->pos + 1;
178          while (1)
179          {
180              $this->pos = \strpos($this->text, $quote, $this->pos + 1);
181              if ($this->pos === \false)
182                  throw new RuntimeException;
183              $n = 0;
184              do
185              {
186                  ++$n;
187              }
188              while ($this->text[$this->pos - $n] === '\\');
189              if ($n % 2)
190                  break;
191          }
192          $attrValue = \preg_replace(
193              '#\\\\([\\\\\'"])#',
194              '$1',
195              \substr($this->text, $valuePos, $this->pos - $valuePos)
196          );
197          ++$this->pos;
198          return $attrValue;
199      }
200  }