[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Renderers/ -> XSLT.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 XSLTProcessor;
  10  use s9e\TextFormatter\Renderer;
  11  class XSLT extends Renderer
  12  {
  13      protected $proc;
  14      protected $reloadParams = \false;
  15      protected $stylesheet;
  16  	public function __construct($stylesheet)
  17      {
  18          $this->stylesheet = $stylesheet;
  19          \preg_match_all('#<xsl:param name="([^"]+)"(?>/>|>([^<]+))#', $stylesheet, $matches);
  20          foreach ($matches[1] as $k => $paramName)
  21              $this->params[$paramName] = (isset($matches[2][$k]))
  22                                        ? \htmlspecialchars_decode($matches[2][$k])
  23                                        : '';
  24      }
  25  	public function __sleep()
  26      {
  27          $props = \get_object_vars($this);
  28          unset($props['proc']);
  29          if (empty($props['reloadParams']))
  30              unset($props['reloadParams']);
  31          return \array_keys($props);
  32      }
  33  	public function __wakeup()
  34      {
  35          if (!empty($this->reloadParams))
  36          {
  37              $this->setParameters($this->params);
  38              $this->reloadParams = \false;
  39          }
  40      }
  41  	public function setParameter($paramName, $paramValue)
  42      {
  43          if (\strpos($paramValue, '"') !== \false && \strpos($paramValue, "'") !== \false)
  44              $paramValue = \str_replace('"', "\xEF\xBC\x82", $paramValue);
  45          else
  46              $paramValue = (string) $paramValue;
  47          if (!isset($this->params[$paramName]) || $this->params[$paramName] !== $paramValue)
  48          {
  49              $this->load();
  50              $this->proc->setParameter('', $paramName, $paramValue);
  51              $this->params[$paramName] = $paramValue;
  52              $this->reloadParams = \true;
  53          }
  54      }
  55  	protected function renderRichText($xml)
  56      {
  57          $dom = $this->loadXML($xml);
  58          $this->load();
  59          $output = (string) $this->proc->transformToXml($dom);
  60          $output = \str_replace('</embed>', '', $output);
  61          if (\substr($output, -1) === "\n")
  62              $output = \substr($output, 0, -1);
  63          if (\strpos($output, "='") !== \false)
  64              $output = $this->normalizeAttributes($output);
  65          return $output;
  66      }
  67  	protected function load()
  68      {
  69          if (!isset($this->proc))
  70          {
  71              $xsl = $this->loadXML($this->stylesheet);
  72              $this->proc = new XSLTProcessor;
  73              $this->proc->importStylesheet($xsl);
  74          }
  75      }
  76  	protected function normalizeAttribute(array $m)
  77      {
  78          if ($m[0][0] === '"')
  79              return $m[0];
  80          return '"' . \str_replace('"', '&quot;', \substr($m[0], 1, -1)) . '"';
  81      }
  82  	protected function normalizeAttributes($html)
  83      {
  84          return \preg_replace_callback('(<\\S++ [^>]++>)', [$this, 'normalizeElement'], $html);
  85      }
  86  	protected function normalizeElement(array $m)
  87      {
  88          if (\strpos($m[0], "='") === \false)
  89              return $m[0];
  90          return \preg_replace_callback('((?:"[^"]*"|\'[^\']*\'))S', [$this, 'normalizeAttribute'], $m[0]);
  91      }
  92  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1