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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Links.php
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\Passes;
009
010 use s9e\TextFormatter\Plugins\Litedown\Parser\LinkAttributesSetter;
011
012 class Links extends AbstractPass
013 {
014 use LinkAttributesSetter;
015
016 /**
017 * {@inheritdoc}
018 */
019 public function parse()
020 {
021 if ($this->text->indexOf('](') !== false)
022 {
023 $this->parseInlineLinks();
024 }
025 if ($this->text->indexOf('<') !== false)
026 {
027 $this->parseAutomaticLinks();
028 }
029 if ($this->text->hasReferences)
030 {
031 $this->parseReferenceLinks();
032 }
033 }
034
035 /**
036 * Add an image tag for given text span
037 *
038 * @param integer $startPos Start tag position
039 * @param integer $endPos End tag position
040 * @param integer $endLen End tag length
041 * @param string $linkInfo URL optionally followed by space and a title
042 * @return void
043 */
044 protected function addLinkTag($startPos, $endPos, $endLen, $linkInfo)
045 {
046 // Give the link a slightly worse priority if this is a implicit reference and a slightly
047 // better priority if it's an explicit reference or an inline link or to give it precedence
048 // over possible BBCodes such as [b](https://en.wikipedia.org/wiki/B)
049 $priority = ($endLen === 1) ? 1 : -1;
050
051 $tag = $this->parser->addTagPair('URL', $startPos, 1, $endPos, $endLen, $priority);
052 $this->setLinkAttributes($tag, $linkInfo, 'url');
053
054 // Overwrite the markup without touching the link's text
055 $this->text->overwrite($startPos, 1);
056 $this->text->overwrite($endPos, $endLen);
057 }
058
059 /**
060 * Capture and return labels used in current text
061 *
062 * @return array Labels' text position as keys, lowercased text content as values
063 */
064 protected function getLabels()
065 {
066 preg_match_all(
067 '/\\[((?:[^\\x17[\\]]|\\[[^\\x17[\\]]*\\])*)\\]/',
068 $this->text,
069 $matches,
070 PREG_OFFSET_CAPTURE
071 );
072 $labels = [];
073 foreach ($matches[1] as $m)
074 {
075 $labels[$m[1] - 1] = strtolower($m[0]);
076 }
077
078 return $labels;
079 }
080
081 /**
082 * Parse automatic links markup
083 *
084 * @return void
085 */
086 protected function parseAutomaticLinks()
087 {
088 preg_match_all(
089 '/<[-+.\\w]++([:@])[^\\x17\\s>]+?(?:>|\\x1B7)/',
090 $this->text,
091 $matches,
092 PREG_OFFSET_CAPTURE
093 );
094 foreach ($matches[0] as $i => $m)
095 {
096 // Re-escape escape sequences in automatic links
097 $content = substr($this->text->decode(str_replace("\x1B", "\\\x1B", $m[0])), 1, -1);
098 $startPos = $m[1];
099 $endPos = $startPos + strlen($m[0]) - 1;
100
101 $tagName = ($matches[1][$i][0] === ':') ? 'URL' : 'EMAIL';
102 $attrName = strtolower($tagName);
103
104 $this->parser->addTagPair($tagName, $startPos, 1, $endPos, 1)
105 ->setAttribute($attrName, $content);
106 }
107 }
108
109 /**
110 * Parse inline links markup
111 *
112 * @return void
113 */
114 protected function parseInlineLinks()
115 {
116 preg_match_all(
117 '/\\[(?:[^\\x17[\\]]|\\[[^\\x17[\\]]*\\])*\\]\\(( *(?:\\([^\\x17\\s()]*\\)|[^\\x17\\s)])*(?=[ )]) *(?:"[^\\x17]*?"|\'[^\\x17]*?\'|\\([^\\x17)]*\\))? *)\\)/',
118 $this->text,
119 $matches,
120 PREG_OFFSET_CAPTURE | PREG_SET_ORDER
121 );
122 foreach ($matches as $m)
123 {
124 $linkInfo = $m[1][0];
125 $startPos = $m[0][1];
126 $endLen = 3 + strlen($linkInfo);
127 $endPos = $startPos + strlen($m[0][0]) - $endLen;
128
129 $this->addLinkTag($startPos, $endPos, $endLen, $linkInfo);
130 }
131 }
132
133 /**
134 * Parse reference links markup
135 *
136 * @return void
137 */
138 protected function parseReferenceLinks()
139 {
140 $labels = $this->getLabels();
141 foreach ($labels as $startPos => $id)
142 {
143 $labelPos = $startPos + 2 + strlen($id);
144 $endPos = $labelPos - 1;
145 $endLen = 1;
146
147 if ($this->text->charAt($labelPos) === ' ')
148 {
149 ++$labelPos;
150 }
151 if (isset($labels[$labelPos], $this->text->linkReferences[$labels[$labelPos]]))
152 {
153 $id = $labels[$labelPos];
154 $endLen = $labelPos + 2 + strlen($id) - $endPos;
155 }
156 if (isset($this->text->linkReferences[$id]))
157 {
158 $this->addLinkTag($startPos, $endPos, $endLen, $this->text->linkReferences[$id]);
159 }
160 }
161 }
162 }