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

utils.php

Zuletzt modifiziert: 01.05.2026, 11:25 - Dateigröße: 3.92 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  namespace phpbb\textformatter\s9e;
 015   
 016  /**
 017  * Text manipulation utilities
 018  *
 019  * In this implementation, "plain text" refers to regular text as it would be inputted by a user.
 020  * "Parsed text" is XML suitable to be reinserted into the database.
 021  */
 022  class utils implements \phpbb\textformatter\utils_interface
 023  {
 024      /**
 025      * Replace BBCodes and other formatting elements with whitespace
 026      *
 027      * NOTE: preserves smilies as text
 028      *
 029      * @param  string $xml Parsed text
 030      * @return string      Plain text
 031      */
 032      public function clean_formatting($xml)
 033      {
 034          // Insert a space before <s> and <e> then remove formatting
 035          $xml = preg_replace('#<[es]>#', ' $0', $xml);
 036   
 037          return \s9e\TextFormatter\Utils::removeFormatting($xml);
 038      }
 039   
 040      /**
 041      * Format given string to be used as an attribute value
 042      *
 043      * Will return the string as-is if it can be used in a BBCode without quotes. Otherwise,
 044      * it will use either single- or double- quotes depending on whichever requires less escaping.
 045      * Quotes and backslashes are escaped with backslashes where necessary
 046      *
 047      * @param  string $str Original string
 048      * @return string      Same string if possible, escaped string within quotes otherwise
 049      */
 050      protected function format_attribute_value($str)
 051      {
 052          if (!preg_match('/[ "\'\\\\\\]]/', $str))
 053          {
 054              // Return as-is if it contains none of: space, ' " \ or ]
 055              return $str;
 056          }
 057          $singleQuoted = "'" . addcslashes($str, "\\'") . "'";
 058          $doubleQuoted = '"' . addcslashes($str, '\\"') . '"';
 059   
 060          return (strlen($singleQuoted) < strlen($doubleQuoted)) ? $singleQuoted : $doubleQuoted;
 061      }
 062   
 063      /**
 064      * {@inheritdoc}
 065      */
 066      public function generate_quote($text, array $attributes = array())
 067      {
 068          $text = trim($text);
 069          $quote = '[quote';
 070          if (isset($attributes['author']))
 071          {
 072              // Add the author as the BBCode's default attribute
 073              $quote .= '=' . $this->format_attribute_value($attributes['author']);
 074              unset($attributes['author']);
 075          }
 076   
 077          if (isset($attributes['user_id']) && $attributes['user_id'] == ANONYMOUS)
 078          {
 079              unset($attributes['user_id']);
 080          }
 081   
 082          ksort($attributes);
 083          foreach ($attributes as $name => $value)
 084          {
 085              $quote .= ' ' . $name . '=' . $this->format_attribute_value($value);
 086          }
 087          $quote .= ']';
 088          $newline = (strlen($quote . $text . '[/quote]') > 80 || strpos($text, "\n") !== false) ? "\n" : '';
 089          $quote .= $newline . $text . $newline . '[/quote]';
 090   
 091          return $quote;
 092      }
 093   
 094      /**
 095      * Get a list of quote authors, limited to the outermost quotes
 096      *
 097      * @param  string   $xml Parsed text
 098      * @return string[]      List of authors
 099      */
 100      public function get_outermost_quote_authors($xml)
 101      {
 102          $authors = array();
 103          if (strpos($xml, '<QUOTE ') === false)
 104          {
 105              return $authors;
 106          }
 107   
 108          $dom = new \DOMDocument;
 109          $dom->loadXML($xml);
 110          $xpath = new \DOMXPath($dom);
 111          foreach ($xpath->query('//QUOTE[not(ancestor::QUOTE)]/@author') as $author)
 112          {
 113              $authors[] = $author->textContent;
 114          }
 115   
 116          return $authors;
 117      }
 118   
 119      /**
 120      * Remove given BBCode and its content, at given nesting depth
 121      *
 122      * @param  string  $xml         Parsed text
 123      * @param  string  $bbcode_name BBCode's name
 124      * @param  integer $depth       Minimum nesting depth (number of parents of the same name)
 125      * @return string               Parsed text
 126      */
 127      public function remove_bbcode($xml, $bbcode_name, $depth = 0)
 128      {
 129          return \s9e\TextFormatter\Utils::removeTag($xml, strtoupper($bbcode_name), $depth);
 130      }
 131   
 132      /**
 133      * Return a parsed text to its original form
 134      *
 135      * @param  string $xml Parsed text
 136      * @return string      Original plain text
 137      */
 138      public function unparse($xml)
 139      {
 140          return \s9e\TextFormatter\Unparser::unparse($xml);
 141      }
 142   
 143      /**
 144       * {@inheritdoc}
 145       */
 146      public function is_empty($text)
 147      {
 148          if ($text === null || $text === '')
 149          {
 150              return true;
 151          }
 152   
 153          return trim($this->unparse($text)) === '';
 154      }
 155  }
 156