Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
90.91% |
20 / 22 |
|
0.00% |
0 / 1 |
CRAP | n/a |
0 / 0 |
|
parse_cfg_file | |
90.91% |
20 / 22 |
|
0.00% |
0 / 1 |
16.19 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | /** |
15 | * @ignore |
16 | */ |
17 | if (!defined('IN_PHPBB')) |
18 | { |
19 | exit; |
20 | } |
21 | |
22 | /** |
23 | * Parse cfg file |
24 | * @param string $filename |
25 | * @param bool|array $lines |
26 | * @return array |
27 | * |
28 | * @deprecated 4.0.0-a1 (To be removed: 5.0.0) |
29 | */ |
30 | function parse_cfg_file($filename, $lines = false) |
31 | { |
32 | $parsed_items = array(); |
33 | |
34 | if ($lines === false) |
35 | { |
36 | $lines = file($filename); |
37 | } |
38 | |
39 | foreach ($lines as $line) |
40 | { |
41 | $line = trim($line); |
42 | |
43 | if (!$line || $line[0] == '#' || ($delim_pos = strpos($line, '=')) === false) |
44 | { |
45 | continue; |
46 | } |
47 | |
48 | // Determine first occurrence, since in values the equal sign is allowed |
49 | $key = htmlspecialchars(strtolower(trim(substr($line, 0, $delim_pos))), ENT_COMPAT); |
50 | $value = trim(substr($line, $delim_pos + 1)); |
51 | |
52 | if (in_array($value, array('off', 'false', '0'))) |
53 | { |
54 | $value = false; |
55 | } |
56 | else if (in_array($value, array('on', 'true', '1'))) |
57 | { |
58 | $value = true; |
59 | } |
60 | else if (!trim($value)) |
61 | { |
62 | $value = ''; |
63 | } |
64 | else if (($value[0] == "'" && $value[strlen($value) - 1] == "'") || ($value[0] == '"' && $value[strlen($value) - 1] == '"')) |
65 | { |
66 | $value = htmlspecialchars(substr($value, 1, strlen($value) - 2), ENT_COMPAT); |
67 | } |
68 | else |
69 | { |
70 | $value = htmlspecialchars($value, ENT_COMPAT); |
71 | } |
72 | |
73 | $parsed_items[$key] = $value; |
74 | } |
75 | |
76 | if (isset($parsed_items['parent']) && isset($parsed_items['name']) && $parsed_items['parent'] == $parsed_items['name']) |
77 | { |
78 | unset($parsed_items['parent']); |
79 | } |
80 | |
81 | return $parsed_items; |
82 | } |