[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Renderers/ -> PHP.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\Renderers;
   9  use DOMNode;
  10  use DOMXPath;
  11  use RuntimeException;
  12  use s9e\TextFormatter\Renderer;
  13  use s9e\TextFormatter\Utils\XPath;
  14  abstract class PHP extends Renderer
  15  {
  16      protected $attributes;
  17      protected $dynamic;
  18      public $enableQuickRenderer = \false;
  19      protected $out;
  20      protected $quickRegexp = '((?!))';
  21      protected $quickRenderingTest = '(<[!?])';
  22      protected $static;
  23      protected $xpath;
  24      abstract protected function renderNode(DOMNode $node);
  25  	public function __sleep()
  26      {
  27          return ['enableQuickRenderer', 'params'];
  28      }
  29      protected function at(DOMNode $root, $query = \null)
  30      {
  31          if ($root->nodeType === \XML_TEXT_NODE)
  32              $this->out .= \htmlspecialchars($root->textContent,0);
  33          else
  34          {
  35              $nodes = (isset($query)) ? $this->xpath->query($query, $root) : $root->childNodes;
  36              foreach ($nodes as $node)
  37                  $this->renderNode($node);
  38          }
  39      }
  40  	protected function canQuickRender($xml)
  41      {
  42          return ($this->enableQuickRenderer && !\preg_match($this->quickRenderingTest, $xml) && \substr($xml, -4) === '</r>');
  43      }
  44  	protected function checkTagPairContent($id, $xml)
  45      {
  46          if (\strpos($xml, '<' . $id, 1) !== \false)
  47              throw new RuntimeException;
  48      }
  49  	protected function getParamAsXPath($paramName)
  50      {
  51          return (isset($this->params[$paramName])) ? XPath::export($this->params[$paramName]) : "''";
  52      }
  53  	protected function getQuickTextContent($xml)
  54      {
  55          return \htmlspecialchars_decode(\strip_tags($xml));
  56      }
  57  	protected function hasNonNullValues(array $array)
  58      {
  59          foreach ($array as $v)
  60              if (isset($v))
  61                  return \true;
  62          return \false;
  63      }
  64  	protected function matchAttributes($xml)
  65      {
  66          if (\strpos($xml, '="') === \false)
  67              return [];
  68          \preg_match_all('(([^ =]++)="([^"]*))S', \substr($xml, 0, \strpos($xml, '>')), $m);
  69          return \array_combine($m[1], $m[2]);
  70      }
  71  	protected function renderQuick($xml)
  72      {
  73          $this->attributes = [];
  74          $xml = $this->decodeSMP($xml);
  75          $html = \preg_replace_callback(
  76              $this->quickRegexp,
  77              [$this, 'renderQuickCallback'],
  78              \preg_replace(
  79                  '(<[eis]>[^<]*</[eis]>)',
  80                  '',
  81                  \substr($xml, 1 + \strpos($xml, '>'), -4)
  82              )
  83          );
  84          return \str_replace('<br/>', '<br>', $html);
  85      }
  86  	protected function renderQuickCallback(array $m)
  87      {
  88          if (isset($m[3]))
  89              return $this->renderQuickSelfClosingTag($m);
  90          if (isset($m[2]))
  91              $id = $m[2];
  92          else
  93          {
  94              $id = $m[1];
  95              $this->checkTagPairContent($id, $m[0]);
  96          }
  97          if (isset($this->static[$id]))
  98              return $this->static[$id];
  99          if (isset($this->dynamic[$id]))
 100              return \preg_replace($this->dynamic[$id][0], $this->dynamic[$id][1], $m[0], 1);
 101          return $this->renderQuickTemplate($id, $m[0]);
 102      }
 103  	protected function renderQuickSelfClosingTag(array $m)
 104      {
 105          unset($m[3]);
 106          $m[0] = \substr($m[0], 0, -2) . '>';
 107          $html = $this->renderQuickCallback($m);
 108          $m[0] = '</' . $m[2] . '>';
 109          $m[2] = '/' . $m[2];
 110          $html .= $this->renderQuickCallback($m);
 111          return $html;
 112      }
 113  	protected function renderQuickTemplate($id, $xml)
 114      {
 115          throw new RuntimeException('Not implemented');
 116      }
 117  	protected function renderRichText($xml)
 118      {
 119          try
 120          {
 121              if ($this->canQuickRender($xml))
 122                  return $this->renderQuick($xml);
 123          }
 124          catch (RuntimeException $e)
 125          {
 126              }
 127          $dom         = $this->loadXML($xml);
 128          $this->out   = '';
 129          $this->xpath = new DOMXPath($dom);
 130          $this->at($dom->documentElement);
 131          $html        = $this->out;
 132          $this->reset();
 133          return $html;
 134      }
 135  	protected function reset()
 136      {
 137          unset($this->attributes);
 138          unset($this->out);
 139          unset($this->xpath);
 140      }
 141  }


Generated: Tue Apr 7 19:42:26 2020 Cross-referenced by PHPXref 0.7.1