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

ParsedText.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 4.65 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\Plugins\Litedown\Parser;
009   
010  class ParsedText
011  {
012      /**
013      * @var bool Whether to decode HTML entities when decoding text
014      */
015      public $decodeHtmlEntities = false;
016   
017      /**
018      * @var bool Whether text contains escape characters
019      */
020      protected $hasEscapedChars = false;
021   
022      /**
023      * @var bool Whether text contains link references
024      */
025      public $hasReferences = false;
026   
027      /**
028      * @var array Array of [label => link info]
029      */
030      public $linkReferences = [];
031   
032      /**
033      * @var string Text being parsed
034      */
035      protected $text;
036   
037      /**
038      * @param string $text Original text
039      */
040      public function __construct($text)
041      {
042          if (strpos($text, '\\') !== false && preg_match('/\\\\[!"\'()*<>[\\\\\\]^_`~]/', $text))
043          {
044              $this->hasEscapedChars = true;
045   
046              // Encode escaped literals that have a special meaning otherwise, so that we don't have
047              // to take them into account in regexps
048              $text = strtr(
049                  $text,
050                  [
051                      '\\!' => "\x1B0", '\\"'  => "\x1B1", "\\'" => "\x1B2", '\\(' => "\x1B3",
052                      '\\)' => "\x1B4", '\\*'  => "\x1B5", '\\<' => "\x1B6", '\\>' => "\x1B7",
053                      '\\[' => "\x1B8", '\\\\' => "\x1B9", '\\]' => "\x1BA", '\\^' => "\x1BB",
054                      '\\_' => "\x1BC", '\\`'  => "\x1BD", '\\~' => "\x1BE"
055                  ]
056              );
057          }
058   
059          // We append a couple of lines and a non-whitespace character at the end of the text in
060          // order to trigger the closure of all open blocks such as quotes and lists
061          $this->text = $text . "\n\n\x17";
062      }
063   
064      /**
065      * @return string
066      */
067      public function __toString()
068      {
069          return $this->text;
070      }
071   
072      /**
073      * Return the character at given position
074      *
075      * @param  integer $pos
076      * @return string
077      */
078      public function charAt($pos)
079      {
080          return $this->text[$pos];
081      }
082   
083      /**
084      * Decode a chunk of encoded text to be used as an attribute value
085      *
086      * Decodes escaped literals and removes slashes and 0x1A characters
087      *
088      * @param  string $str Encoded text
089      * @return string      Decoded text
090      */
091      public function decode($str)
092      {
093          if ($this->decodeHtmlEntities && strpos($str, '&') !== false)
094          {
095              $str = html_entity_decode($str, ENT_QUOTES, 'UTF-8');
096          }
097          $str = str_replace("\x1A", '', $str);
098   
099          if ($this->hasEscapedChars)
100          {
101              $str = strtr(
102                  $str,
103                  [
104                      "\x1B0" => '!', "\x1B1" => '"',  "\x1B2" => "'", "\x1B3" => '(',
105                      "\x1B4" => ')', "\x1B5" => '*',  "\x1B6" => '<', "\x1B7" => '>',
106                      "\x1B8" => '[', "\x1B9" => '\\', "\x1BA" => ']', "\x1BB" => '^',
107                      "\x1BC" => '_', "\x1BD" => '`',  "\x1BE" => '~'
108                  ]
109              );
110          }
111   
112          return $str;
113      }
114   
115      /**
116      * Find the first occurence of given substring starting at given position
117      *
118      * @param  string       $str
119      * @param  integer      $pos
120      * @return bool|integer
121      */
122      public function indexOf($str, $pos = 0)
123      {
124          return strpos($this->text, $str, $pos);
125      }
126   
127      /**
128      * Test whether given position is preceded by whitespace
129      *
130      * @param  integer $pos
131      * @return bool
132      */
133      public function isAfterWhitespace($pos)
134      {
135          return ($pos > 0 && $this->isWhitespace($this->text[$pos - 1]));
136      }
137   
138      /**
139      * Test whether given character is alphanumeric
140      *
141      * @param  string $chr
142      * @return bool
143      */
144      public function isAlnum($chr)
145      {
146          return (strpos(' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', $chr) > 0);
147      }
148   
149      /**
150      * Test whether given position is followed by whitespace
151      *
152      * @param  integer $pos
153      * @return bool
154      */
155      public function isBeforeWhitespace($pos)
156      {
157          return $this->isWhitespace($this->text[$pos + 1]);
158      }
159   
160      /**
161      * Test whether a length of text is surrounded by alphanumeric characters
162      *
163      * @param  integer $pos Start of the text
164      * @param  integer $len Length of the text
165      * @return bool
166      */
167      public function isSurroundedByAlnum($pos, $len)
168      {
169          return ($pos > 0 && $this->isAlnum($this->text[$pos - 1]) && $this->isAlnum($this->text[$pos + $len]));
170      }
171   
172      /**
173      * Test whether given character is an ASCII whitespace character
174      *
175      * NOTE: newlines are normalized to LF before parsing so we don't have to check for CR
176      *
177      * @param  string $chr
178      * @return bool
179      */
180      public function isWhitespace($chr)
181      {
182          return (strpos(" \n\t", $chr) !== false);
183      }
184   
185      /**
186      * Mark the boundary of a block in the original text
187      *
188      * @param  integer $pos
189      * @return void
190      */
191      public function markBoundary($pos)
192      {
193          $this->text[$pos] = "\x17";
194      }
195   
196      /**
197      * Overwrite part of the text with substitution characters ^Z (0x1A)
198      *
199      * @param  integer $pos Start of the range
200      * @param  integer $len Length of text to overwrite
201      * @return void
202      */
203      public function overwrite($pos, $len)
204      {
205          if ($len > 0)
206          {
207              $this->text = substr($this->text, 0, $pos) . str_repeat("\x1A", $len) . substr($this->text, $pos + $len);
208          }
209      }
210  }