Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

OptimizeChooseText.php

Zuletzt modifiziert: 01.05.2026, 11:28 - Dateigröße: 2.88 KiB


 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\Configurator\TemplateNormalizations;
 009   
 010  use DOMElement;
 011  use DOMText;
 012   
 013  class OptimizeChooseText extends AbstractChooseOptimization
 014  {
 015      /**
 016      * Adjust length of the text nodes of current xsl:choose element's branches
 017      *
 018      * @param  string  $childType Either firstChild or lastChild
 019      * @param  integer $pos
 020      * @param  integer $len
 021      * @return void
 022      */
 023      protected function adjustTextNodes($childType, $pos, $len = PHP_INT_MAX)
 024      {
 025          foreach ($this->getBranches() as $branch)
 026          {
 027              $node            = $branch->$childType;
 028              $node->nodeValue = substr($node->textContent, $pos, $len);
 029          }
 030      }
 031   
 032      /**
 033      * Compute the number of leading characters common to all strings
 034      *
 035      * @param  string[] $strings
 036      * @return integer
 037      */
 038      protected function getPrefixLength(array $strings)
 039      {
 040          $i      = 0;
 041          $len    = 0;
 042          $maxLen = min(array_map('strlen', $strings));
 043          while ($i < $maxLen)
 044          {
 045              $c = $strings[0][$i];
 046              foreach ($strings as $string)
 047              {
 048                  if ($string[$i] !== $c)
 049                  {
 050                      break 2;
 051                  }
 052              }
 053              $len = ++$i;
 054          }
 055   
 056          return $len;
 057      }
 058   
 059      /**
 060      * Get the text content of the firstChild/lastChild of each branch if they are all text nodes
 061      *
 062      * @param  string   $childType Either firstChild or lastChild
 063      * @return string[]            List of strings or an empty array
 064      */
 065      protected function getTextContent($childType)
 066      {
 067          $strings = [];
 068          foreach ($this->getBranches() as $branch)
 069          {
 070              if (!($branch->$childType instanceof DOMText))
 071              {
 072                  return [];
 073              }
 074              $strings[] = $branch->$childType->textContent;
 075          }
 076   
 077          return $strings;
 078      }
 079   
 080      /**
 081      * {@inheritdoc}
 082      */
 083      protected function optimizeChoose()
 084      {
 085          if (!$this->hasOtherwise())
 086          {
 087              return;
 088          }
 089   
 090          $this->optimizeLeadingText();
 091          $this->optimizeTrailingText();
 092      }
 093   
 094      /**
 095      * Move common leading text outside of current choose
 096      *
 097      * @return void
 098      */
 099      protected function optimizeLeadingText()
 100      {
 101          $strings = $this->getTextContent('firstChild');
 102          if (empty($strings))
 103          {
 104              return;
 105          }
 106   
 107          $len = $this->getPrefixLength($strings);
 108          if ($len)
 109          {
 110              $this->adjustTextNodes('firstChild', $len);
 111              $this->choose->parentNode->insertBefore(
 112                  $this->createText(substr($strings[0], 0, $len)),
 113                  $this->choose
 114              );
 115          }
 116      }
 117   
 118      /**
 119      * Move common trailing text outside of current choose
 120      *
 121      * @return void
 122      */
 123      protected function optimizeTrailingText()
 124      {
 125          $strings = $this->getTextContent('lastChild');
 126          if (empty($strings))
 127          {
 128              return;
 129          }
 130   
 131          // Flip the strings before computing the prefix length to get the suffix length
 132          $len = $this->getPrefixLength(array_map('strrev', $strings));
 133          if ($len)
 134          {
 135              $this->adjustTextNodes('lastChild', 0, -$len);
 136              $this->choose->parentNode->insertBefore(
 137                  $this->createText(substr($strings[0], -$len)),
 138                  $this->choose->nextSibling
 139              );
 140          }
 141      }
 142  }