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 |
config.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\search\sphinx;
015
016 /**
017 * An object representing the sphinx configuration
018 * Can read it from file and write it back out after modification
019 */
020 class config
021 {
022 private $sections = array();
023
024 /**
025 * Constructor which optionally loads data from a variable
026 *
027 * @param string $config_data Variable containing the sphinx configuration data
028 *
029 * @access public
030 */
031 function __construct($config_data)
032 {
033 if ($config_data != '')
034 {
035 $this->read($config_data);
036 }
037 }
038
039 /**
040 * Get a section object by its name
041 *
042 * @param string $name The name of the section that shall be returned
043 * @return \phpbb\search\sphinx\config_section The section object or null if none was found
044 *
045 * @access public
046 */
047 function get_section_by_name($name)
048 {
049 for ($i = 0, $size = sizeof($this->sections); $i < $size; $i++)
050 {
051 // Make sure this is really a section object and not a comment
052 if (($this->sections[$i] instanceof \phpbb\search\sphinx\config_section) && $this->sections[$i]->get_name() == $name)
053 {
054 return $this->sections[$i];
055 }
056 }
057 }
058
059 /**
060 * Appends a new empty section to the end of the config
061 *
062 * @param string $name The name for the new section
063 * @return \phpbb\search\sphinx\config_section The newly created section object
064 *
065 * @access public
066 */
067 function add_section($name)
068 {
069 $this->sections[] = new \phpbb\search\sphinx\config_section($name, '');
070 return $this->sections[sizeof($this->sections) - 1];
071 }
072
073 /**
074 * Reads the config file data
075 *
076 * @param string $config_data The config file data
077 *
078 * @access private
079 */
080 function read($config_data)
081 {
082 $this->sections = array();
083
084 $section = null;
085 $found_opening_bracket = false;
086 $in_value = false;
087
088 foreach ($config_data as $i => $line)
089 {
090 // If the value of a variable continues to the next line because the line
091 // break was escaped then we don't trim leading space but treat it as a part of the value
092 if ($in_value)
093 {
094 $line = rtrim($line);
095 }
096 else
097 {
098 $line = trim($line);
099 }
100
101 // If we're not inside a section look for one
102 if (!$section)
103 {
104 // Add empty lines and comments as comment objects to the section list
105 // that way they're not deleted when reassembling the file from the sections
106 if (!$line || $line[0] == '#')
107 {
108 $this->sections[] = new \phpbb\search\sphinx\config_comment($config_file[$i]);
109 continue;
110 }
111 else
112 {
113 // Otherwise we scan the line reading the section name until we find
114 // an opening curly bracket or a comment
115 $section_name = '';
116 $section_name_comment = '';
117 $found_opening_bracket = false;
118 for ($j = 0, $length = strlen($line); $j < $length; $j++)
119 {
120 if ($line[$j] == '#')
121 {
122 $section_name_comment = substr($line, $j);
123 break;
124 }
125
126 if ($found_opening_bracket)
127 {
128 continue;
129 }
130
131 if ($line[$j] == '{')
132 {
133 $found_opening_bracket = true;
134 continue;
135 }
136
137 $section_name .= $line[$j];
138 }
139
140 // And then we create the new section object
141 $section_name = trim($section_name);
142 $section = new \phpbb\search\sphinx\config_section($section_name, $section_name_comment);
143 }
144 }
145 else
146 {
147 // If we're looking for variables inside a section
148 $skip_first = false;
149
150 // If we're not in a value continuing over the line feed
151 if (!$in_value)
152 {
153 // Then add empty lines and comments as comment objects to the variable list
154 // of this section so they're not deleted on reassembly
155 if (!$line || $line[0] == '#')
156 {
157 $section->add_variable(new \phpbb\search\sphinx\config_comment($config_file[$i]));
158 continue;
159 }
160
161 // As long as we haven't yet actually found an opening bracket for this section
162 // we treat everything as comments so it's not deleted either
163 if (!$found_opening_bracket)
164 {
165 if ($line[0] == '{')
166 {
167 $skip_first = true;
168 $line = substr($line, 1);
169 $found_opening_bracket = true;
170 }
171 else
172 {
173 $section->add_variable(new \phpbb\search\sphinx\config_comment($config_file[$i]));
174 continue;
175 }
176 }
177 }
178
179 // If we did not find a comment in this line or still add to the previous
180 // line's value ...
181 if ($line || $in_value)
182 {
183 if (!$in_value)
184 {
185 $name = '';
186 $value = '';
187 $comment = '';
188 $found_assignment = false;
189 }
190 $in_value = false;
191 $end_section = false;
192
193 /* ... then we should prase this line char by char:
194 - first there's the variable name
195 - then an equal sign
196 - the variable value
197 - possibly a backslash before the linefeed in this case we need to continue
198 parsing the value in the next line
199 - a # indicating that the rest of the line is a comment
200 - a closing curly bracket indicating the end of this section*/
201 for ($j = 0, $length = strlen($line); $j < $length; $j++)
202 {
203 if ($line[$j] == '#')
204 {
205 $comment = substr($line, $j);
206 break;
207 }
208 else if ($line[$j] == '}')
209 {
210 $comment = substr($line, $j + 1);
211 $end_section = true;
212 break;
213 }
214 else if (!$found_assignment)
215 {
216 if ($line[$j] == '=')
217 {
218 $found_assignment = true;
219 }
220 else
221 {
222 $name .= $line[$j];
223 }
224 }
225 else
226 {
227 if ($line[$j] == '\\' && $j == $length - 1)
228 {
229 $value .= "\n";
230 $in_value = true;
231 // Go to the next line and keep processing the value in there
232 continue 2;
233 }
234 $value .= $line[$j];
235 }
236 }
237
238 // If a name and an equal sign were found then we have append a
239 // new variable object to the section
240 if ($name && $found_assignment)
241 {
242 $section->add_variable(new \phpbb\search\sphinx\config_variable(trim($name), trim($value), ($end_section) ? '' : $comment));
243 continue;
244 }
245
246 /* If we found a closing curly bracket this section has been completed
247 and we can append it to the section list and continue with looking for
248 the next section */
249 if ($end_section)
250 {
251 $section->set_end_comment($comment);
252 $this->sections[] = $section;
253 $section = null;
254 continue;
255 }
256 }
257
258 // If we did not find anything meaningful up to here, then just treat it
259 // as a comment
260 $comment = ($skip_first) ? "\t" . substr(ltrim($config_file[$i]), 1) : $config_file[$i];
261 $section->add_variable(new \phpbb\search\sphinx\config_comment($comment));
262 }
263 }
264
265 }
266
267 /**
268 * Returns the config data
269 *
270 * @return string $data The config data that is generated
271 *
272 * @access public
273 */
274 function get_data()
275 {
276 $data = "";
277 foreach ($this->sections as $section)
278 {
279 $data .= $section->to_string();
280 }
281
282 return $data;
283 }
284 }
285