[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/ -> Renderer.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;
   9  use DOMDocument;
  10  use InvalidArgumentException;
  11  abstract class Renderer
  12  {
  13      protected $params = [];
  14  	protected function loadXML($xml)
  15      {
  16          $this->checkUnsupported($xml);
  17          $flags = (\LIBXML_VERSION >= 20700) ? \LIBXML_COMPACT | \LIBXML_PARSEHUGE : 0;
  18          $useErrors = \libxml_use_internal_errors(\true);
  19          $dom       = new DOMDocument;
  20          $success   = $dom->loadXML($xml, $flags);
  21          \libxml_use_internal_errors($useErrors);
  22          if (!$success)
  23              throw new InvalidArgumentException('Cannot load XML: ' . \libxml_get_last_error()->message);
  24          return $dom;
  25      }
  26  	public function render($xml)
  27      {
  28          if (\substr($xml, 0, 3) === '<t>' && \substr($xml, -4) === '</t>')
  29              return $this->renderPlainText($xml);
  30          else
  31              return $this->renderRichText(\preg_replace('(<[eis]>[^<]*</[eis]>)', '', $xml));
  32      }
  33  	protected function renderPlainText($xml)
  34      {
  35          $html = \substr($xml, 3, -4);
  36          $html = \str_replace('<br/>', '<br>', $html);
  37          $html = $this->decodeSMP($html);
  38          return $html;
  39      }
  40      abstract protected function renderRichText($xml);
  41  	public function getParameter($paramName)
  42      {
  43          return (isset($this->params[$paramName])) ? $this->params[$paramName] : '';
  44      }
  45  	public function getParameters()
  46      {
  47          return $this->params;
  48      }
  49  	public function setParameter($paramName, $paramValue)
  50      {
  51          $this->params[$paramName] = (string) $paramValue;
  52      }
  53  	public function setParameters(array $params)
  54      {
  55          foreach ($params as $paramName => $paramValue)
  56              $this->setParameter($paramName, $paramValue);
  57      }
  58  	protected function checkUnsupported($xml)
  59      {
  60          if (\strpos($xml, '<!') !== \false)
  61              throw new InvalidArgumentException('DTDs, CDATA nodes and comments are not allowed');
  62          if (\strpos($xml, '<?') !== \false)
  63              throw new InvalidArgumentException('Processing instructions are not allowed');
  64      }
  65  	protected function decodeSMP($str)
  66      {
  67          if (\strpos($str, '&#') === \false)
  68              return $str;
  69          return \preg_replace_callback('(&#(?:x[0-9A-Fa-f]+|[0-9]+);)', __CLASS__ . '::decodeEntity', $str);
  70      }
  71  	protected static function decodeEntity(array $m)
  72      {
  73          return \htmlspecialchars(\html_entity_decode($m[0], \ENT_QUOTES, 'UTF-8'), \ENT_COMPAT);
  74      }
  75  }


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