Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
utils.php
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 class utils implements \phpbb\textformatter\utils_interface
020 {
021 /**
022 * Replace BBCodes and other formatting elements with whitespace
023 *
024 * NOTE: preserves smilies as text
025 *
026 * @param string $xml Parsed text
027 * @return string Plain text
028 */
029 public function clean_formatting($xml)
030 {
031 // Insert a space before <s> and <e> then remove formatting
032 $xml = preg_replace('#<[es]>#', ' $0', $xml);
033
034 return \s9e\TextFormatter\Utils::removeFormatting($xml);
035 }
036
037 /**
038 * Format given string to be used as an attribute value
039 *
040 * Will return the string as-is if it can be used in a BBCode without quotes. Otherwise,
041 * it will use either single- or double- quotes depending on whichever requires less escaping.
042 * Quotes and backslashes are escaped with backslashes where necessary
043 *
044 * @param string $str Original string
045 * @return string Same string if possible, escaped string within quotes otherwise
046 */
047 protected function format_attribute_value($str)
048 {
049 if (!preg_match('/[ "\'\\\\\\]]/', $str))
050 {
051 // Return as-is if it contains none of: space, ' " \ or ]
052 return $str;
053 }
054 $singleQuoted = "'" . addcslashes($str, "\\'") . "'";
055 $doubleQuoted = '"' . addcslashes($str, '\\"') . '"';
056
057 return (strlen($singleQuoted) < strlen($doubleQuoted)) ? $singleQuoted : $doubleQuoted;
058 }
059
060 /**
061 * {@inheritdoc}
062 */
063 public function generate_quote($text, array $attributes = array())
064 {
065 $text = trim($text);
066 $quote = '[quote';
067 if (isset($attributes['author']))
068 {
069 // Add the author as the BBCode's default attribute
070 $quote .= '=' . $this->format_attribute_value($attributes['author']);
071 unset($attributes['author']);
072 }
073
074 if (isset($attributes['user_id']) && $attributes['user_id'] == ANONYMOUS)
075 {
076 unset($attributes['user_id']);
077 }
078
079 ksort($attributes);
080 foreach ($attributes as $name => $value)
081 {
082 $quote .= ' ' . $name . '=' . $this->format_attribute_value($value);
083 }
084 $quote .= ']';
085 $newline = (strlen($quote . $text . '[/quote]') > 80 || strpos($text, "\n") !== false) ? "\n" : '';
086 $quote .= $newline . $text . $newline . '[/quote]';
087
088 return $quote;
089 }
090
091 /**
092 * Get a list of quote authors, limited to the outermost quotes
093 *
094 * @param string $xml Parsed text
095 * @return string[] List of authors
096 */
097 public function get_outermost_quote_authors($xml)
098 {
099 $authors = array();
100 if (strpos($xml, '<QUOTE ') === false)
101 {
102 return $authors;
103 }
104
105 $dom = new \DOMDocument;
106 $dom->loadXML($xml);
107 $xpath = new \DOMXPath($dom);
108 foreach ($xpath->query('//QUOTE[not(ancestor::QUOTE)]/@author') as $author)
109 {
110 $authors[] = $author->textContent;
111 }
112
113 return $authors;
114 }
115
116 /**
117 * Remove given BBCode and its content, at given nesting depth
118 *
119 * @param string $xml Parsed text
120 * @param string $bbcode_name BBCode's name
121 * @param integer $depth Minimum nesting depth (number of parents of the same name)
122 * @return string Parsed text
123 */
124 public function remove_bbcode($xml, $bbcode_name, $depth = 0)
125 {
126 return \s9e\TextFormatter\Utils::removeTag($xml, strtoupper($bbcode_name), $depth);
127 }
128
129 /**
130 * Return a parsed text to its original form
131 *
132 * @param string $xml Parsed text
133 * @return string Original plain text
134 */
135 public function unparse($xml)
136 {
137 return \s9e\TextFormatter\Unparser::unparse($xml);
138 }
139
140 /**
141 * {@inheritdoc}
142 */
143 public function is_empty($text)
144 {
145 if ($text === null || $text === '')
146 {
147 return true;
148 }
149
150 return trim($this->unparse($text)) === '';
151 }
152 }
153