[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Plugins/Litedown/Parser/Passes/ -> Images.php (source)

   1  <?php
   2  
   3  /*
   4  * @package   s9e\TextFormatter
   5  * @copyright Copyright (c) 2010-2019 The s9e Authors
   6  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
   7  */
   8  namespace s9e\TextFormatter\Plugins\Litedown\Parser\Passes;
   9  use s9e\TextFormatter\Plugins\Litedown\Parser\LinkAttributesSetter;
  10  class Images extends AbstractPass
  11  {
  12      use LinkAttributesSetter;
  13  	public function parse()
  14      {
  15          $pos = $this->text->indexOf('![');
  16          if ($pos === \false)
  17              return;
  18          if ($this->text->indexOf('](', $pos) !== \false)
  19              $this->parseInlineImages();
  20          if ($this->text->hasReferences)
  21              $this->parseReferenceImages();
  22      }
  23  	protected function addImageTag($startPos, $endPos, $endLen, $linkInfo, $alt)
  24      {
  25          $tag = $this->parser->addTagPair('IMG', $startPos, 2, $endPos, $endLen);
  26          $this->setLinkAttributes($tag, $linkInfo, 'src');
  27          $tag->setAttribute('alt', $this->text->decode($alt));
  28          $this->text->overwrite($startPos, $endPos + $endLen - $startPos);
  29      }
  30  	protected function parseInlineImages()
  31      {
  32          \preg_match_all(
  33              '/!\\[(?:[^\\x17[\\]]|\\[[^\\x17[\\]]*\\])*\\]\\(( *(?:[^\\x17\\s()]|\\([^\\x17\\s()]*\\))*(?=[ )]) *(?:"[^\\x17]*?"|\'[^\\x17]*?\'|\\([^\\x17)]*\\))? *)\\)/',
  34              $this->text,
  35              $matches,
  36              \PREG_OFFSET_CAPTURE | \PREG_SET_ORDER
  37          );
  38          foreach ($matches as $m)
  39          {
  40              $linkInfo = $m[1][0];
  41              $startPos = $m[0][1];
  42              $endLen   = 3 + \strlen($linkInfo);
  43              $endPos   = $startPos + \strlen($m[0][0]) - $endLen;
  44              $alt      = \substr($m[0][0], 2, \strlen($m[0][0]) - $endLen - 2);
  45              $this->addImageTag($startPos, $endPos, $endLen, $linkInfo, $alt);
  46          }
  47      }
  48  	protected function parseReferenceImages()
  49      {
  50          \preg_match_all(
  51              '/!\\[((?:[^\\x17[\\]]|\\[[^\\x17[\\]]*\\])*)\\](?: ?\\[([^\\x17[\\]]+)\\])?/',
  52              $this->text,
  53              $matches,
  54              \PREG_OFFSET_CAPTURE | \PREG_SET_ORDER
  55          );
  56          foreach ($matches as $m)
  57          {
  58              $startPos = $m[0][1];
  59              $endPos   = $startPos + 2 + \strlen($m[1][0]);
  60              $endLen   = 1;
  61              $alt      = $m[1][0];
  62              $id       = $alt;
  63              if (isset($m[2][0], $this->text->linkReferences[$m[2][0]]))
  64              {
  65                  $endLen = \strlen($m[0][0]) - \strlen($alt) - 2;
  66                  $id        = $m[2][0];
  67              }
  68              elseif (!isset($this->text->linkReferences[$id]))
  69                  continue;
  70              $this->addImageTag($startPos, $endPos, $endLen, $this->text->linkReferences[$id], $alt);
  71          }
  72      }
  73  }


Generated: Sat Oct 26 11:28:42 2019 Cross-referenced by PHPXref 0.7.1