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 |
Images.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 Images extends AbstractPass
013 {
014 use LinkAttributesSetter;
015
016 /**
017 * {@inheritdoc}
018 */
019 public function parse()
020 {
021 $pos = $this->text->indexOf(' !== false)
027 {
028 $this->parseInlineImages();
029 }
030 if ($this->text->hasReferences)
031 {
032 $this->parseReferenceImages();
033 }
034 }
035
036 /**
037 * Add an image tag for given text span
038 *
039 * @param integer $startPos Start tag position
040 * @param integer $endPos End tag position
041 * @param integer $endLen End tag length
042 * @param string $linkInfo URL optionally followed by space and a title
043 * @param string $alt Value for the alt attribute
044 * @return void
045 */
046 protected function addImageTag($startPos, $endPos, $endLen, $linkInfo, $alt)
047 {
048 $tag = $this->parser->addTagPair('IMG', $startPos, 2, $endPos, $endLen);
049 $this->setLinkAttributes($tag, $linkInfo, 'src');
050 $tag->setAttribute('alt', $this->text->decode($alt));
051
052 // Overwrite the markup
053 $this->text->overwrite($startPos, $endPos + $endLen - $startPos);
054 }
055
056 /**
057 * Parse inline images markup
058 *
059 * @return void
060 */
061 protected function parseInlineImages()
062 {
063 preg_match_all(
064 '/!\\[(?:[^\\x17[\\]]|\\[[^\\x17[\\]]*\\])*\\]\\(( *(?:[^\\x17\\s()]|\\([^\\x17\\s()]*\\))*(?=[ )]) *(?:"[^\\x17]*?"|\'[^\\x17]*?\'|\\([^\\x17)]*\\))? *)\\)/',
065 $this->text,
066 $matches,
067 PREG_OFFSET_CAPTURE | PREG_SET_ORDER
068 );
069 foreach ($matches as $m)
070 {
071 $linkInfo = $m[1][0];
072 $startPos = $m[0][1];
073 $endLen = 3 + strlen($linkInfo);
074 $endPos = $startPos + strlen($m[0][0]) - $endLen;
075 $alt = substr($m[0][0], 2, strlen($m[0][0]) - $endLen - 2);
076
077 $this->addImageTag($startPos, $endPos, $endLen, $linkInfo, $alt);
078 }
079 }
080
081 /**
082 * Parse reference images markup
083 *
084 * @return void
085 */
086 protected function parseReferenceImages()
087 {
088 preg_match_all(
089 '/!\\[((?:[^\\x17[\\]]|\\[[^\\x17[\\]]*\\])*)\\](?: ?\\[([^\\x17[\\]]+)\\])?/',
090 $this->text,
091 $matches,
092 PREG_OFFSET_CAPTURE | PREG_SET_ORDER
093 );
094 foreach ($matches as $m)
095 {
096 $startPos = $m[0][1];
097 $endPos = $startPos + 2 + strlen($m[1][0]);
098 $endLen = 1;
099 $alt = $m[1][0];
100 $id = $alt;
101
102 if (isset($m[2][0], $this->text->linkReferences[$m[2][0]]))
103 {
104 $endLen = strlen($m[0][0]) - strlen($alt) - 2;
105 $id = $m[2][0];
106 }
107 elseif (!isset($this->text->linkReferences[$id]))
108 {
109 continue;
110 }
111
112 $this->addImageTag($startPos, $endPos, $endLen, $this->text->linkReferences[$id], $alt);
113 }
114 }
115 }