@@ -1,190 +1,190 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | - function make_self_url() { |
|
4 | - $proto = is_server_https() ? 'https' : 'http'; |
|
3 | + function make_self_url() { |
|
4 | + $proto = is_server_https() ? 'https' : 'http'; |
|
5 | 5 | |
6 | - return $proto.'://'.$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]; |
|
7 | - } |
|
6 | + return $proto.'://'.$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]; |
|
7 | + } |
|
8 | 8 | |
9 | - function make_self_url_path() { |
|
10 | - $proto = is_server_https() ? 'https' : 'http'; |
|
11 | - $url_path = $proto.'://'.$_SERVER["HTTP_HOST"].parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); |
|
9 | + function make_self_url_path() { |
|
10 | + $proto = is_server_https() ? 'https' : 'http'; |
|
11 | + $url_path = $proto.'://'.$_SERVER["HTTP_HOST"].parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); |
|
12 | 12 | |
13 | - return $url_path; |
|
14 | - } |
|
13 | + return $url_path; |
|
14 | + } |
|
15 | 15 | |
16 | - function check_mysql_tables() { |
|
17 | - $pdo = Db::pdo(); |
|
16 | + function check_mysql_tables() { |
|
17 | + $pdo = Db::pdo(); |
|
18 | 18 | |
19 | - $sth = $pdo->prepare("SELECT engine, table_name FROM information_schema.tables WHERE |
|
19 | + $sth = $pdo->prepare("SELECT engine, table_name FROM information_schema.tables WHERE |
|
20 | 20 | table_schema = ? AND table_name LIKE 'ttrss_%' AND engine != 'InnoDB'"); |
21 | - $sth->execute([DB_NAME]); |
|
21 | + $sth->execute([DB_NAME]); |
|
22 | 22 | |
23 | - $bad_tables = []; |
|
23 | + $bad_tables = []; |
|
24 | 24 | |
25 | - while ($line = $sth->fetch()) { |
|
26 | - array_push($bad_tables, $line); |
|
27 | - } |
|
25 | + while ($line = $sth->fetch()) { |
|
26 | + array_push($bad_tables, $line); |
|
27 | + } |
|
28 | 28 | |
29 | - return $bad_tables; |
|
30 | - } |
|
29 | + return $bad_tables; |
|
30 | + } |
|
31 | 31 | |
32 | - function initial_sanity_check() { |
|
32 | + function initial_sanity_check() { |
|
33 | 33 | |
34 | - $errors = array(); |
|
34 | + $errors = array(); |
|
35 | 35 | |
36 | - if (!file_exists("config.php")) { |
|
37 | - array_push($errors, "Configuration file not found. Looks like you forgot to copy config.php-dist to config.php and edit it."); |
|
38 | - } else { |
|
36 | + if (!file_exists("config.php")) { |
|
37 | + array_push($errors, "Configuration file not found. Looks like you forgot to copy config.php-dist to config.php and edit it."); |
|
38 | + } else { |
|
39 | 39 | |
40 | - require_once "sanity_config.php"; |
|
40 | + require_once "sanity_config.php"; |
|
41 | 41 | |
42 | - if (file_exists("install") && !file_exists("config.php")) { |
|
43 | - array_push($errors, "Please copy config.php-dist to config.php or run the installer in install/"); |
|
44 | - } |
|
42 | + if (file_exists("install") && !file_exists("config.php")) { |
|
43 | + array_push($errors, "Please copy config.php-dist to config.php or run the installer in install/"); |
|
44 | + } |
|
45 | 45 | |
46 | - if (strpos(PLUGINS, "auth_") === false) { |
|
47 | - array_push($errors, "Please enable at least one authentication module via PLUGINS constant in config.php"); |
|
48 | - } |
|
46 | + if (strpos(PLUGINS, "auth_") === false) { |
|
47 | + array_push($errors, "Please enable at least one authentication module via PLUGINS constant in config.php"); |
|
48 | + } |
|
49 | 49 | |
50 | - if (function_exists('posix_getuid') && posix_getuid() == 0) { |
|
51 | - array_push($errors, "Please don't run this script as root."); |
|
52 | - } |
|
50 | + if (function_exists('posix_getuid') && posix_getuid() == 0) { |
|
51 | + array_push($errors, "Please don't run this script as root."); |
|
52 | + } |
|
53 | 53 | |
54 | - if (version_compare(PHP_VERSION, '5.6.0', '<')) { |
|
55 | - array_push($errors, "PHP version 5.6.0 or newer required. You're using ".PHP_VERSION."."); |
|
56 | - } |
|
54 | + if (version_compare(PHP_VERSION, '5.6.0', '<')) { |
|
55 | + array_push($errors, "PHP version 5.6.0 or newer required. You're using ".PHP_VERSION."."); |
|
56 | + } |
|
57 | 57 | |
58 | - if (!class_exists("UConverter")) { |
|
59 | - array_push($errors, "PHP UConverter class is missing, it's provided by the Internationalization (intl) module."); |
|
60 | - } |
|
58 | + if (!class_exists("UConverter")) { |
|
59 | + array_push($errors, "PHP UConverter class is missing, it's provided by the Internationalization (intl) module."); |
|
60 | + } |
|
61 | 61 | |
62 | - if (CONFIG_VERSION != EXPECTED_CONFIG_VERSION) { |
|
63 | - array_push($errors, "Configuration file (config.php) has incorrect version. Update it with new options from config.php-dist and set CONFIG_VERSION to the correct value."); |
|
64 | - } |
|
62 | + if (CONFIG_VERSION != EXPECTED_CONFIG_VERSION) { |
|
63 | + array_push($errors, "Configuration file (config.php) has incorrect version. Update it with new options from config.php-dist and set CONFIG_VERSION to the correct value."); |
|
64 | + } |
|
65 | 65 | |
66 | - if (!is_writable(CACHE_DIR."/images")) { |
|
67 | - array_push($errors, "Image cache is not writable (chmod -R 777 ".CACHE_DIR."/images)"); |
|
68 | - } |
|
66 | + if (!is_writable(CACHE_DIR."/images")) { |
|
67 | + array_push($errors, "Image cache is not writable (chmod -R 777 ".CACHE_DIR."/images)"); |
|
68 | + } |
|
69 | 69 | |
70 | - if (!is_writable(CACHE_DIR."/upload")) { |
|
71 | - array_push($errors, "Upload cache is not writable (chmod -R 777 ".CACHE_DIR."/upload)"); |
|
72 | - } |
|
70 | + if (!is_writable(CACHE_DIR."/upload")) { |
|
71 | + array_push($errors, "Upload cache is not writable (chmod -R 777 ".CACHE_DIR."/upload)"); |
|
72 | + } |
|
73 | 73 | |
74 | - if (!is_writable(CACHE_DIR."/export")) { |
|
75 | - array_push($errors, "Data export cache is not writable (chmod -R 777 ".CACHE_DIR."/export)"); |
|
76 | - } |
|
74 | + if (!is_writable(CACHE_DIR."/export")) { |
|
75 | + array_push($errors, "Data export cache is not writable (chmod -R 777 ".CACHE_DIR."/export)"); |
|
76 | + } |
|
77 | 77 | |
78 | - if (GENERATED_CONFIG_CHECK != EXPECTED_CONFIG_VERSION) { |
|
79 | - array_push($errors, |
|
80 | - "Configuration option checker sanity_config.php is outdated, please recreate it using ./utils/regen_config_checks.sh"); |
|
81 | - } |
|
78 | + if (GENERATED_CONFIG_CHECK != EXPECTED_CONFIG_VERSION) { |
|
79 | + array_push($errors, |
|
80 | + "Configuration option checker sanity_config.php is outdated, please recreate it using ./utils/regen_config_checks.sh"); |
|
81 | + } |
|
82 | 82 | |
83 | - foreach ($required_defines as $d) { |
|
84 | - if (!defined($d)) { |
|
85 | - array_push($errors, |
|
86 | - "Required configuration file parameter $d is not defined in config.php. You might need to copy it from config.php-dist."); |
|
87 | - } |
|
88 | - } |
|
83 | + foreach ($required_defines as $d) { |
|
84 | + if (!defined($d)) { |
|
85 | + array_push($errors, |
|
86 | + "Required configuration file parameter $d is not defined in config.php. You might need to copy it from config.php-dist."); |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - if (SINGLE_USER_MODE && class_exists("PDO")) { |
|
91 | - $pdo = DB::pdo(); |
|
90 | + if (SINGLE_USER_MODE && class_exists("PDO")) { |
|
91 | + $pdo = DB::pdo(); |
|
92 | 92 | |
93 | - $res = $pdo->query("SELECT id FROM ttrss_users WHERE id = 1"); |
|
93 | + $res = $pdo->query("SELECT id FROM ttrss_users WHERE id = 1"); |
|
94 | 94 | |
95 | - if (!$res->fetch()) { |
|
96 | - array_push($errors, "SINGLE_USER_MODE is enabled in config.php but default admin account is not found."); |
|
97 | - } |
|
98 | - } |
|
95 | + if (!$res->fetch()) { |
|
96 | + array_push($errors, "SINGLE_USER_MODE is enabled in config.php but default admin account is not found."); |
|
97 | + } |
|
98 | + } |
|
99 | 99 | |
100 | - $ref_self_url_path = make_self_url_path(); |
|
101 | - $ref_self_url_path = preg_replace("/\w+\.php$/", "", $ref_self_url_path); |
|
100 | + $ref_self_url_path = make_self_url_path(); |
|
101 | + $ref_self_url_path = preg_replace("/\w+\.php$/", "", $ref_self_url_path); |
|
102 | 102 | |
103 | - if (SELF_URL_PATH == "http://example.org/tt-rss/") { |
|
104 | - array_push($errors, |
|
105 | - "Please set SELF_URL_PATH to the correct value for your server (possible value: <b>$ref_self_url_path</b>)"); |
|
106 | - } |
|
103 | + if (SELF_URL_PATH == "http://example.org/tt-rss/") { |
|
104 | + array_push($errors, |
|
105 | + "Please set SELF_URL_PATH to the correct value for your server (possible value: <b>$ref_self_url_path</b>)"); |
|
106 | + } |
|
107 | 107 | |
108 | - if (isset($_SERVER["HTTP_HOST"]) && |
|
109 | - (!defined('_SKIP_SELF_URL_PATH_CHECKS') || !_SKIP_SELF_URL_PATH_CHECKS) && |
|
110 | - SELF_URL_PATH != $ref_self_url_path && SELF_URL_PATH != mb_substr($ref_self_url_path, 0, mb_strlen($ref_self_url_path) - 1)) { |
|
111 | - array_push($errors, |
|
112 | - "Please set SELF_URL_PATH to the correct value detected for your server: <b>$ref_self_url_path</b>"); |
|
113 | - } |
|
108 | + if (isset($_SERVER["HTTP_HOST"]) && |
|
109 | + (!defined('_SKIP_SELF_URL_PATH_CHECKS') || !_SKIP_SELF_URL_PATH_CHECKS) && |
|
110 | + SELF_URL_PATH != $ref_self_url_path && SELF_URL_PATH != mb_substr($ref_self_url_path, 0, mb_strlen($ref_self_url_path) - 1)) { |
|
111 | + array_push($errors, |
|
112 | + "Please set SELF_URL_PATH to the correct value detected for your server: <b>$ref_self_url_path</b>"); |
|
113 | + } |
|
114 | 114 | |
115 | - if (!is_writable(ICONS_DIR)) { |
|
116 | - array_push($errors, "ICONS_DIR defined in config.php is not writable (chmod -R 777 ".ICONS_DIR.").\n"); |
|
117 | - } |
|
115 | + if (!is_writable(ICONS_DIR)) { |
|
116 | + array_push($errors, "ICONS_DIR defined in config.php is not writable (chmod -R 777 ".ICONS_DIR.").\n"); |
|
117 | + } |
|
118 | 118 | |
119 | - if (!is_writable(LOCK_DIRECTORY)) { |
|
120 | - array_push($errors, "LOCK_DIRECTORY defined in config.php is not writable (chmod -R 777 ".LOCK_DIRECTORY.").\n"); |
|
121 | - } |
|
119 | + if (!is_writable(LOCK_DIRECTORY)) { |
|
120 | + array_push($errors, "LOCK_DIRECTORY defined in config.php is not writable (chmod -R 777 ".LOCK_DIRECTORY.").\n"); |
|
121 | + } |
|
122 | 122 | |
123 | - if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) { |
|
124 | - array_push($errors, "PHP configuration option allow_url_fopen is disabled, and CURL functions are not present. Either enable allow_url_fopen or install PHP extension for CURL."); |
|
125 | - } |
|
123 | + if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) { |
|
124 | + array_push($errors, "PHP configuration option allow_url_fopen is disabled, and CURL functions are not present. Either enable allow_url_fopen or install PHP extension for CURL."); |
|
125 | + } |
|
126 | 126 | |
127 | - if (!function_exists("json_encode")) { |
|
128 | - array_push($errors, "PHP support for JSON is required, but was not found."); |
|
129 | - } |
|
127 | + if (!function_exists("json_encode")) { |
|
128 | + array_push($errors, "PHP support for JSON is required, but was not found."); |
|
129 | + } |
|
130 | 130 | |
131 | - if (DB_TYPE == "mysql" && !function_exists("mysqli_connect")) { |
|
132 | - array_push($errors, "PHP support for MySQL is required for configured DB_TYPE in config.php."); |
|
133 | - } |
|
131 | + if (DB_TYPE == "mysql" && !function_exists("mysqli_connect")) { |
|
132 | + array_push($errors, "PHP support for MySQL is required for configured DB_TYPE in config.php."); |
|
133 | + } |
|
134 | 134 | |
135 | - if (DB_TYPE == "pgsql" && !function_exists("pg_connect")) { |
|
136 | - array_push($errors, "PHP support for PostgreSQL is required for configured DB_TYPE in config.php"); |
|
137 | - } |
|
135 | + if (DB_TYPE == "pgsql" && !function_exists("pg_connect")) { |
|
136 | + array_push($errors, "PHP support for PostgreSQL is required for configured DB_TYPE in config.php"); |
|
137 | + } |
|
138 | 138 | |
139 | - if (!class_exists("PDO")) { |
|
140 | - array_push($errors, "PHP support for PDO is required but was not found."); |
|
141 | - } |
|
139 | + if (!class_exists("PDO")) { |
|
140 | + array_push($errors, "PHP support for PDO is required but was not found."); |
|
141 | + } |
|
142 | 142 | |
143 | - if (!function_exists("mb_strlen")) { |
|
144 | - array_push($errors, "PHP support for mbstring functions is required but was not found."); |
|
145 | - } |
|
143 | + if (!function_exists("mb_strlen")) { |
|
144 | + array_push($errors, "PHP support for mbstring functions is required but was not found."); |
|
145 | + } |
|
146 | 146 | |
147 | - if (!function_exists("hash")) { |
|
148 | - array_push($errors, "PHP support for hash() function is required but was not found."); |
|
149 | - } |
|
147 | + if (!function_exists("hash")) { |
|
148 | + array_push($errors, "PHP support for hash() function is required but was not found."); |
|
149 | + } |
|
150 | 150 | |
151 | - if (ini_get("safe_mode")) { |
|
152 | - array_push($errors, "PHP safe mode setting is obsolete and not supported by tt-rss."); |
|
153 | - } |
|
151 | + if (ini_get("safe_mode")) { |
|
152 | + array_push($errors, "PHP safe mode setting is obsolete and not supported by tt-rss."); |
|
153 | + } |
|
154 | 154 | |
155 | - if (!function_exists("mime_content_type")) { |
|
156 | - array_push($errors, "PHP function mime_content_type() is missing, try enabling fileinfo module."); |
|
157 | - } |
|
155 | + if (!function_exists("mime_content_type")) { |
|
156 | + array_push($errors, "PHP function mime_content_type() is missing, try enabling fileinfo module."); |
|
157 | + } |
|
158 | 158 | |
159 | - if (!class_exists("DOMDocument")) { |
|
160 | - array_push($errors, "PHP support for DOMDocument is required, but was not found."); |
|
161 | - } |
|
159 | + if (!class_exists("DOMDocument")) { |
|
160 | + array_push($errors, "PHP support for DOMDocument is required, but was not found."); |
|
161 | + } |
|
162 | 162 | |
163 | - if (DB_TYPE == "mysql") { |
|
164 | - $bad_tables = check_mysql_tables(); |
|
163 | + if (DB_TYPE == "mysql") { |
|
164 | + $bad_tables = check_mysql_tables(); |
|
165 | 165 | |
166 | - if (count($bad_tables) > 0) { |
|
167 | - $bad_tables_fmt = []; |
|
166 | + if (count($bad_tables) > 0) { |
|
167 | + $bad_tables_fmt = []; |
|
168 | 168 | |
169 | - foreach ($bad_tables as $bt) { |
|
170 | - array_push($bad_tables_fmt, sprintf("%s (%s)", $bt['table_name'], $bt['engine'])); |
|
171 | - } |
|
169 | + foreach ($bad_tables as $bt) { |
|
170 | + array_push($bad_tables_fmt, sprintf("%s (%s)", $bt['table_name'], $bt['engine'])); |
|
171 | + } |
|
172 | 172 | |
173 | - $msg = "<p>The following tables use an unsupported MySQL engine: <b>". |
|
174 | - implode(", ", $bad_tables_fmt)."</b>.</p>"; |
|
173 | + $msg = "<p>The following tables use an unsupported MySQL engine: <b>". |
|
174 | + implode(", ", $bad_tables_fmt)."</b>.</p>"; |
|
175 | 175 | |
176 | - $msg .= "<p>The only supported engine on MySQL is InnoDB. MyISAM lacks functionality to run |
|
176 | + $msg .= "<p>The only supported engine on MySQL is InnoDB. MyISAM lacks functionality to run |
|
177 | 177 | tt-rss. |
178 | 178 | Please backup your data (via OPML) and re-import the schema before continuing.</p> |
179 | 179 | <p><b>WARNING: importing the schema would mean LOSS OF ALL YOUR DATA.</b></p>"; |
180 | 180 | |
181 | 181 | |
182 | - array_push($errors, $msg); |
|
183 | - } |
|
184 | - } |
|
185 | - } |
|
182 | + array_push($errors, $msg); |
|
183 | + } |
|
184 | + } |
|
185 | + } |
|
186 | 186 | |
187 | - if (count($errors) > 0 && $_SERVER['REQUEST_URI']) { ?> |
|
187 | + if (count($errors) > 0 && $_SERVER['REQUEST_URI']) { ?> |
|
188 | 188 | <!DOCTYPE html> |
189 | 189 | <html> |
190 | 190 | <head> |
@@ -211,22 +211,22 @@ discard block |
||
211 | 211 | </html> |
212 | 212 | |
213 | 213 | <?php |
214 | - die; |
|
215 | - } else if (count($errors) > 0) { |
|
216 | - echo "Tiny Tiny RSS was unable to start properly. This usually means a misconfiguration or an incomplete upgrade.\n"; |
|
217 | - echo "Please fix errors indicated by the following messages:\n\n"; |
|
214 | + die; |
|
215 | + } else if (count($errors) > 0) { |
|
216 | + echo "Tiny Tiny RSS was unable to start properly. This usually means a misconfiguration or an incomplete upgrade.\n"; |
|
217 | + echo "Please fix errors indicated by the following messages:\n\n"; |
|
218 | 218 | |
219 | - foreach ($errors as $error) { |
|
220 | - echo " * $error\n"; |
|
221 | - } |
|
219 | + foreach ($errors as $error) { |
|
220 | + echo " * $error\n"; |
|
221 | + } |
|
222 | 222 | |
223 | - echo "\nYou might want to check tt-rss wiki or the forums for more information.\n"; |
|
224 | - echo "Please search the forums before creating new topic for your question.\n"; |
|
223 | + echo "\nYou might want to check tt-rss wiki or the forums for more information.\n"; |
|
224 | + echo "Please search the forums before creating new topic for your question.\n"; |
|
225 | 225 | |
226 | - exit(-1); |
|
227 | - } |
|
228 | - } |
|
226 | + exit(-1); |
|
227 | + } |
|
228 | + } |
|
229 | 229 | |
230 | - initial_sanity_check(); |
|
230 | + initial_sanity_check(); |
|
231 | 231 | |
232 | 232 | ?> |
@@ -390,8 +390,8 @@ discard block |
||
390 | 390 | |
391 | 391 | // TODO: should this support POST requests or not? idk |
392 | 392 | |
393 | - $context_options = array( |
|
394 | - 'http' => array( |
|
393 | + $context_options = array( |
|
394 | + 'http' => array( |
|
395 | 395 | 'header' => array( |
396 | 396 | 'Connection: close' |
397 | 397 | ), |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | 'ignore_errors' => true, |
400 | 400 | 'timeout' => $timeout ? $timeout : FILE_FETCH_TIMEOUT, |
401 | 401 | 'protocol_version'=> 1.1) |
402 | - ); |
|
402 | + ); |
|
403 | 403 | |
404 | 404 | if (!$post_query && $last_modified) { |
405 | 405 | array_push($context_options['http']['header'], "If-Modified-Since: $last_modified"); |
@@ -681,7 +681,7 @@ discard block |
||
681 | 681 | function logout_user() { |
682 | 682 | @session_destroy(); |
683 | 683 | if (isset($_COOKIE[session_name()])) { |
684 | - setcookie(session_name(), '', time() - 42000, '/'); |
|
684 | + setcookie(session_name(), '', time() - 42000, '/'); |
|
685 | 685 | } |
686 | 686 | session_commit(); |
687 | 687 | } |
@@ -725,7 +725,7 @@ discard block |
||
725 | 725 | if (AUTH_AUTO_LOGIN && authenticate_user(null, null)) { |
726 | 726 | $_SESSION["ref_schema_version"] = get_schema_version(true); |
727 | 727 | } else { |
728 | - authenticate_user(null, null, true); |
|
728 | + authenticate_user(null, null, true); |
|
729 | 729 | } |
730 | 730 | |
731 | 731 | if (!$_SESSION["uid"]) { |
@@ -1012,9 +1012,9 @@ discard block |
||
1012 | 1012 | $params = array(); |
1013 | 1013 | |
1014 | 1014 | foreach (array("ON_CATCHUP_SHOW_NEXT_FEED", "HIDE_READ_FEEDS", |
1015 | - "ENABLE_FEED_CATS", "FEEDS_SORT_BY_UNREAD", "CONFIRM_FEED_CATCHUP", |
|
1016 | - "CDM_AUTO_CATCHUP", "FRESH_ARTICLE_MAX_AGE", |
|
1017 | - "HIDE_READ_SHOWS_SPECIAL", "COMBINED_DISPLAY_MODE") as $param) { |
|
1015 | + "ENABLE_FEED_CATS", "FEEDS_SORT_BY_UNREAD", "CONFIRM_FEED_CATCHUP", |
|
1016 | + "CDM_AUTO_CATCHUP", "FRESH_ARTICLE_MAX_AGE", |
|
1017 | + "HIDE_READ_SHOWS_SPECIAL", "COMBINED_DISPLAY_MODE") as $param) { |
|
1018 | 1018 | |
1019 | 1019 | $params[strtolower($param)] = (int) get_pref($param); |
1020 | 1020 | } |
@@ -231,14 +231,14 @@ discard block |
||
231 | 231 | $url = str_replace(' ', '%20', $url); |
232 | 232 | |
233 | 233 | if (strpos($url, "//") === 0) { |
234 | - $url = 'http:' . $url; |
|
234 | + $url = 'http:'.$url; |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | $url_host = parse_url($url, PHP_URL_HOST); |
238 | 238 | $fetch_domain_hits[$url_host] += 1; |
239 | 239 | |
240 | 240 | if ($fetch_domain_hits[$url_host] > MAX_FETCH_REQUESTS_PER_HOST) { |
241 | - user_error("Exceeded fetch request quota for $url_host: " . $fetch_domain_hits[$url_host], E_USER_WARNING); |
|
241 | + user_error("Exceeded fetch request quota for $url_host: ".$fetch_domain_hits[$url_host], E_USER_WARNING); |
|
242 | 242 | #return false; |
243 | 243 | } |
244 | 244 | |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | } |
256 | 256 | |
257 | 257 | if ($http_accept) { |
258 | - array_push($curl_http_headers, "Accept: " . $http_accept); |
|
258 | + array_push($curl_http_headers, "Accept: ".$http_accept); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | if (count($curl_http_headers) > 0) { |
@@ -270,11 +270,10 @@ discard block |
||
270 | 270 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
271 | 271 | curl_setopt($ch, CURLOPT_HEADER, true); |
272 | 272 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); |
273 | - curl_setopt($ch, CURLOPT_USERAGENT, $useragent ? $useragent : |
|
274 | - SELF_USER_AGENT); |
|
273 | + curl_setopt($ch, CURLOPT_USERAGENT, $useragent ? $useragent : SELF_USER_AGENT); |
|
275 | 274 | curl_setopt($ch, CURLOPT_ENCODING, ""); |
276 | 275 | |
277 | - if ($http_referrer) { |
|
276 | + if ($http_referrer) { |
|
278 | 277 | curl_setopt($ch, CURLOPT_REFERER, $http_referrer); |
279 | 278 | } |
280 | 279 |
@@ -1,80 +1,80 @@ |
||
1 | 1 | <?php |
2 | 2 | function format_backtrace($trace) { |
3 | - $rv = ""; |
|
4 | - $idx = 1; |
|
5 | - |
|
6 | - if (is_array($trace)) { |
|
7 | - foreach ($trace as $e) { |
|
8 | - if (isset($e["file"]) && isset($e["line"])) { |
|
9 | - $fmt_args = []; |
|
10 | - |
|
11 | - if (is_array($e["args"])) { |
|
12 | - foreach ($e["args"] as $a) { |
|
13 | - if (!is_object($a)) { |
|
14 | - array_push($fmt_args, $a); |
|
15 | - } else { |
|
16 | - array_push($fmt_args, "[".get_class($a)."]"); |
|
17 | - } |
|
18 | - } |
|
19 | - } |
|
20 | - |
|
21 | - $filename = str_replace(dirname(__DIR__)."/", "", $e["file"]); |
|
22 | - |
|
23 | - $rv .= sprintf("%d. %s(%s): %s(%s)\n", |
|
24 | - $idx, $filename, $e["line"], $e["function"], implode(", ", $fmt_args)); |
|
25 | - |
|
26 | - $idx++; |
|
27 | - } |
|
28 | - } |
|
29 | - } |
|
30 | - |
|
31 | - return $rv; |
|
3 | + $rv = ""; |
|
4 | + $idx = 1; |
|
5 | + |
|
6 | + if (is_array($trace)) { |
|
7 | + foreach ($trace as $e) { |
|
8 | + if (isset($e["file"]) && isset($e["line"])) { |
|
9 | + $fmt_args = []; |
|
10 | + |
|
11 | + if (is_array($e["args"])) { |
|
12 | + foreach ($e["args"] as $a) { |
|
13 | + if (!is_object($a)) { |
|
14 | + array_push($fmt_args, $a); |
|
15 | + } else { |
|
16 | + array_push($fmt_args, "[".get_class($a)."]"); |
|
17 | + } |
|
18 | + } |
|
19 | + } |
|
20 | + |
|
21 | + $filename = str_replace(dirname(__DIR__)."/", "", $e["file"]); |
|
22 | + |
|
23 | + $rv .= sprintf("%d. %s(%s): %s(%s)\n", |
|
24 | + $idx, $filename, $e["line"], $e["function"], implode(", ", $fmt_args)); |
|
25 | + |
|
26 | + $idx++; |
|
27 | + } |
|
28 | + } |
|
29 | + } |
|
30 | + |
|
31 | + return $rv; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | function ttrss_error_handler($errno, $errstr, $file, $line, $context) { |
35 | - if (error_reporting() == 0 || !$errno) { |
|
36 | - return false; |
|
37 | - } |
|
35 | + if (error_reporting() == 0 || !$errno) { |
|
36 | + return false; |
|
37 | + } |
|
38 | 38 | |
39 | - $file = substr(str_replace(dirname(dirname(__FILE__)), "", $file), 1); |
|
39 | + $file = substr(str_replace(dirname(dirname(__FILE__)), "", $file), 1); |
|
40 | 40 | |
41 | - $context = format_backtrace(debug_backtrace()); |
|
42 | - $errstr = truncate_middle($errstr, 16384, " (...) "); |
|
41 | + $context = format_backtrace(debug_backtrace()); |
|
42 | + $errstr = truncate_middle($errstr, 16384, " (...) "); |
|
43 | 43 | |
44 | - if (class_exists("Logger")) { |
|
45 | - return Logger::get()->log_error($errno, $errstr, $file, $line, $context); |
|
46 | - } |
|
47 | - } |
|
44 | + if (class_exists("Logger")) { |
|
45 | + return Logger::get()->log_error($errno, $errstr, $file, $line, $context); |
|
46 | + } |
|
47 | + } |
|
48 | 48 | |
49 | 49 | function ttrss_fatal_handler() { |
50 | - global $last_query; |
|
50 | + global $last_query; |
|
51 | 51 | |
52 | - $error = error_get_last(); |
|
52 | + $error = error_get_last(); |
|
53 | 53 | |
54 | - if ($error !== null) { |
|
55 | - $errno = $error["type"]; |
|
56 | - $file = $error["file"]; |
|
57 | - $line = $error["line"]; |
|
58 | - $errstr = $error["message"]; |
|
54 | + if ($error !== null) { |
|
55 | + $errno = $error["type"]; |
|
56 | + $file = $error["file"]; |
|
57 | + $line = $error["line"]; |
|
58 | + $errstr = $error["message"]; |
|
59 | 59 | |
60 | - if (!$errno) { |
|
61 | - return false; |
|
62 | - } |
|
60 | + if (!$errno) { |
|
61 | + return false; |
|
62 | + } |
|
63 | 63 | |
64 | - $context = format_backtrace(debug_backtrace()); |
|
64 | + $context = format_backtrace(debug_backtrace()); |
|
65 | 65 | |
66 | - $file = substr(str_replace(dirname(dirname(__FILE__)), "", $file), 1); |
|
66 | + $file = substr(str_replace(dirname(dirname(__FILE__)), "", $file), 1); |
|
67 | 67 | |
68 | - if ($last_query) { |
|
69 | - $errstr .= " [Last query: $last_query]"; |
|
70 | - } |
|
68 | + if ($last_query) { |
|
69 | + $errstr .= " [Last query: $last_query]"; |
|
70 | + } |
|
71 | 71 | |
72 | - if (class_exists("Logger")) { |
|
73 | - return Logger::get()->log_error($errno, $errstr, $file, $line, $context); |
|
74 | - } |
|
75 | - } |
|
72 | + if (class_exists("Logger")) { |
|
73 | + return Logger::get()->log_error($errno, $errstr, $file, $line, $context); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | - return false; |
|
77 | + return false; |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | register_shutdown_function('ttrss_fatal_handler'); |
@@ -1,38 +1,38 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | function db_escape_string($s, $strip_tags = true) { |
4 | - return Db::get()->escape_string($s, $strip_tags); |
|
4 | + return Db::get()->escape_string($s, $strip_tags); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | function db_query($query, $die_on_error = true) { |
8 | - return Db::get()->query($query, $die_on_error); |
|
8 | + return Db::get()->query($query, $die_on_error); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | function db_fetch_assoc($result) { |
12 | - return Db::get()->fetch_assoc($result); |
|
12 | + return Db::get()->fetch_assoc($result); |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | |
16 | 16 | function db_num_rows($result) { |
17 | - return Db::get()->num_rows($result); |
|
17 | + return Db::get()->num_rows($result); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | function db_fetch_result($result, $row, $param) { |
21 | - return Db::get()->fetch_result($result, $row, $param); |
|
21 | + return Db::get()->fetch_result($result, $row, $param); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | function db_affected_rows($result) { |
25 | - return Db::get()->affected_rows($result); |
|
25 | + return Db::get()->affected_rows($result); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | function db_last_error() { |
29 | - return Db::get()->last_error(); |
|
29 | + return Db::get()->last_error(); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | function db_last_query_error() { |
33 | - return Db::get()->last_query_error(); |
|
33 | + return Db::get()->last_query_error(); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | function db_quote($str) { |
37 | - return Db::get()->quote($str); |
|
37 | + return Db::get()->quote($str); |
|
38 | 38 | } |
@@ -1,28 +1,28 @@ |
||
1 | 1 | <?php |
2 | - require_once "functions.php"; |
|
2 | + require_once "functions.php"; |
|
3 | 3 | |
4 | - spl_autoload_register(function($class) { |
|
5 | - $namespace = ''; |
|
6 | - $class_name = $class; |
|
4 | + spl_autoload_register(function($class) { |
|
5 | + $namespace = ''; |
|
6 | + $class_name = $class; |
|
7 | 7 | |
8 | - if (strpos($class, '\\') !== false) { |
|
9 | - list ($namespace, $class_name) = explode('\\', $class, 2); |
|
10 | - } |
|
8 | + if (strpos($class, '\\') !== false) { |
|
9 | + list ($namespace, $class_name) = explode('\\', $class, 2); |
|
10 | + } |
|
11 | 11 | |
12 | - $root_dir = dirname(__DIR__); // we're in tt-rss/include |
|
12 | + $root_dir = dirname(__DIR__); // we're in tt-rss/include |
|
13 | 13 | |
14 | - // 1. third party libraries with namespaces are loaded from vendor/ |
|
15 | - // 2. internal tt-rss classes are loaded from classes/ and use special naming logic instead of namespaces |
|
16 | - // 3. plugin classes are loaded by PluginHandler from plugins.local/ and plugins/ (TODO: use generic autoloader?) |
|
14 | + // 1. third party libraries with namespaces are loaded from vendor/ |
|
15 | + // 2. internal tt-rss classes are loaded from classes/ and use special naming logic instead of namespaces |
|
16 | + // 3. plugin classes are loaded by PluginHandler from plugins.local/ and plugins/ (TODO: use generic autoloader?) |
|
17 | 17 | |
18 | - if ($namespace && $class_name) { |
|
19 | - $class_file = "$root_dir/vendor/$namespace/".str_replace('\\', '/', $class_name).".php"; |
|
20 | - } else { |
|
21 | - $class_file = "$root_dir/classes/".str_replace("_", "/", strtolower($class)).".php"; |
|
22 | - } |
|
18 | + if ($namespace && $class_name) { |
|
19 | + $class_file = "$root_dir/vendor/$namespace/".str_replace('\\', '/', $class_name).".php"; |
|
20 | + } else { |
|
21 | + $class_file = "$root_dir/classes/".str_replace("_", "/", strtolower($class)).".php"; |
|
22 | + } |
|
23 | 23 | |
24 | - if (file_exists($class_file)) { |
|
25 | - include $class_file; |
|
26 | - } |
|
24 | + if (file_exists($class_file)) { |
|
25 | + include $class_file; |
|
26 | + } |
|
27 | 27 | |
28 | - }); |
|
28 | + }); |
@@ -1,97 +1,97 @@ discard block |
||
1 | 1 | <?php |
2 | - // This file uses two additional include files: |
|
3 | - // |
|
4 | - // 1) templates/register_notice.txt - displayed above the registration form |
|
5 | - // 2) register_expire_do.php - contains user expiration queries when necessary |
|
2 | + // This file uses two additional include files: |
|
3 | + // |
|
4 | + // 1) templates/register_notice.txt - displayed above the registration form |
|
5 | + // 2) register_expire_do.php - contains user expiration queries when necessary |
|
6 | 6 | |
7 | - set_include_path(dirname(__FILE__)."/include".PATH_SEPARATOR. |
|
8 | - get_include_path()); |
|
7 | + set_include_path(dirname(__FILE__)."/include".PATH_SEPARATOR. |
|
8 | + get_include_path()); |
|
9 | 9 | |
10 | - require_once "autoload.php"; |
|
11 | - require_once "functions.php"; |
|
12 | - require_once "sessions.php"; |
|
13 | - require_once "sanity_check.php"; |
|
14 | - require_once "config.php"; |
|
15 | - require_once "db.php"; |
|
10 | + require_once "autoload.php"; |
|
11 | + require_once "functions.php"; |
|
12 | + require_once "sessions.php"; |
|
13 | + require_once "sanity_check.php"; |
|
14 | + require_once "config.php"; |
|
15 | + require_once "db.php"; |
|
16 | 16 | |
17 | - startup_gettext(); |
|
17 | + startup_gettext(); |
|
18 | 18 | |
19 | - $action = $_REQUEST["action"]; |
|
19 | + $action = $_REQUEST["action"]; |
|
20 | 20 | |
21 | - if (!init_plugins()) { |
|
22 | - return; |
|
23 | - } |
|
21 | + if (!init_plugins()) { |
|
22 | + return; |
|
23 | + } |
|
24 | 24 | |
25 | - if ($_REQUEST["format"] == "feed") { |
|
26 | - header("Content-Type: text/xml"); |
|
25 | + if ($_REQUEST["format"] == "feed") { |
|
26 | + header("Content-Type: text/xml"); |
|
27 | 27 | |
28 | - print '<?xml version="1.0" encoding="utf-8"?>'; |
|
29 | - print "<feed xmlns=\"http://www.w3.org/2005/Atom\"> |
|
28 | + print '<?xml version="1.0" encoding="utf-8"?>'; |
|
29 | + print "<feed xmlns=\"http://www.w3.org/2005/Atom\"> |
|
30 | 30 | <id>".htmlspecialchars(SELF_URL_PATH."/register.php")."</id> |
31 | 31 | <title>Tiny Tiny RSS registration slots</title> |
32 | 32 | <link rel=\"self\" href=\"".htmlspecialchars(SELF_URL_PATH."/register.php?format=feed")."\"/> |
33 | 33 | <link rel=\"alternate\" href=\"".htmlspecialchars(SELF_URL_PATH)."\"/>"; |
34 | 34 | |
35 | - if (ENABLE_REGISTRATION) { |
|
36 | - $result = db_query("SELECT COUNT(*) AS cu FROM ttrss_users"); |
|
37 | - $num_users = db_fetch_result($result, 0, "cu"); |
|
38 | - |
|
39 | - $num_users = REG_MAX_USERS - $num_users; |
|
40 | - if ($num_users < 0) { |
|
41 | - $num_users = 0; |
|
42 | - } |
|
43 | - $reg_suffix = "enabled"; |
|
44 | - } else { |
|
45 | - $num_users = 0; |
|
46 | - $reg_suffix = "disabled"; |
|
47 | - } |
|
48 | - |
|
49 | - print "<entry> |
|
35 | + if (ENABLE_REGISTRATION) { |
|
36 | + $result = db_query("SELECT COUNT(*) AS cu FROM ttrss_users"); |
|
37 | + $num_users = db_fetch_result($result, 0, "cu"); |
|
38 | + |
|
39 | + $num_users = REG_MAX_USERS - $num_users; |
|
40 | + if ($num_users < 0) { |
|
41 | + $num_users = 0; |
|
42 | + } |
|
43 | + $reg_suffix = "enabled"; |
|
44 | + } else { |
|
45 | + $num_users = 0; |
|
46 | + $reg_suffix = "disabled"; |
|
47 | + } |
|
48 | + |
|
49 | + print "<entry> |
|
50 | 50 | <id>".htmlspecialchars(SELF_URL_PATH)."/register.php?$num_users"."</id> |
51 | 51 | <link rel=\"alternate\" href=\"".htmlspecialchars(SELF_URL_PATH."/register.php")."\"/>"; |
52 | 52 | |
53 | - print "<title>$num_users slots are currently available, registration $reg_suffix</title>"; |
|
54 | - print "<summary>$num_users slots are currently available, registration $reg_suffix</summary>"; |
|
53 | + print "<title>$num_users slots are currently available, registration $reg_suffix</title>"; |
|
54 | + print "<summary>$num_users slots are currently available, registration $reg_suffix</summary>"; |
|
55 | 55 | |
56 | - print "</entry>"; |
|
56 | + print "</entry>"; |
|
57 | 57 | |
58 | - print "</feed>"; |
|
58 | + print "</feed>"; |
|
59 | 59 | |
60 | - return; |
|
61 | - } |
|
60 | + return; |
|
61 | + } |
|
62 | 62 | |
63 | - /* Remove users which didn't login after receiving their registration information */ |
|
63 | + /* Remove users which didn't login after receiving their registration information */ |
|
64 | 64 | |
65 | - if (DB_TYPE == "pgsql") { |
|
66 | - db_query("DELETE FROM ttrss_users WHERE last_login IS NULL |
|
65 | + if (DB_TYPE == "pgsql") { |
|
66 | + db_query("DELETE FROM ttrss_users WHERE last_login IS NULL |
|
67 | 67 | AND created < NOW() - INTERVAL '1 day' AND access_level = 0"); |
68 | - } else { |
|
69 | - db_query("DELETE FROM ttrss_users WHERE last_login IS NULL |
|
68 | + } else { |
|
69 | + db_query("DELETE FROM ttrss_users WHERE last_login IS NULL |
|
70 | 70 | AND created < DATE_SUB(NOW(), INTERVAL 1 DAY) AND access_level = 0"); |
71 | - } |
|
71 | + } |
|
72 | 72 | |
73 | - if (file_exists("register_expire_do.php")) { |
|
74 | - require_once "register_expire_do.php"; |
|
75 | - } |
|
73 | + if (file_exists("register_expire_do.php")) { |
|
74 | + require_once "register_expire_do.php"; |
|
75 | + } |
|
76 | 76 | |
77 | - if ($action == "check") { |
|
78 | - header("Content-Type: application/xml"); |
|
77 | + if ($action == "check") { |
|
78 | + header("Content-Type: application/xml"); |
|
79 | 79 | |
80 | - $login = trim(db_escape_string($_REQUEST['login'])); |
|
80 | + $login = trim(db_escape_string($_REQUEST['login'])); |
|
81 | 81 | |
82 | - $result = db_query("SELECT id FROM ttrss_users WHERE |
|
82 | + $result = db_query("SELECT id FROM ttrss_users WHERE |
|
83 | 83 | LOWER(login) = LOWER('$login')"); |
84 | 84 | |
85 | - $is_registered = db_num_rows($result) > 0; |
|
85 | + $is_registered = db_num_rows($result) > 0; |
|
86 | 86 | |
87 | - print "<result>"; |
|
87 | + print "<result>"; |
|
88 | 88 | |
89 | - printf("%d", $is_registered); |
|
89 | + printf("%d", $is_registered); |
|
90 | 90 | |
91 | - print "</result>"; |
|
91 | + print "</result>"; |
|
92 | 92 | |
93 | - return; |
|
94 | - } |
|
93 | + return; |
|
94 | + } |
|
95 | 95 | ?> |
96 | 96 | <!DOCTYPE html> |
97 | 97 | <html> |
@@ -189,20 +189,20 @@ discard block |
||
189 | 189 | <div class="content"> |
190 | 190 | |
191 | 191 | <?php |
192 | - if (!ENABLE_REGISTRATION) { |
|
193 | - print_error(__("New user registrations are administratively disabled.")); |
|
192 | + if (!ENABLE_REGISTRATION) { |
|
193 | + print_error(__("New user registrations are administratively disabled.")); |
|
194 | 194 | |
195 | - print "<p><form method=\"GET\" action=\"backend.php\"> |
|
195 | + print "<p><form method=\"GET\" action=\"backend.php\"> |
|
196 | 196 | <input type=\"hidden\" name=\"op\" value=\"logout\"> |
197 | 197 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> |
198 | 198 | </form>"; |
199 | - return; |
|
200 | - } |
|
199 | + return; |
|
200 | + } |
|
201 | 201 | ?> |
202 | 202 | |
203 | 203 | <?php if (REG_MAX_USERS > 0) { |
204 | - $result = db_query("SELECT COUNT(*) AS cu FROM ttrss_users"); |
|
205 | - $num_users = db_fetch_result($result, 0, "cu"); |
|
204 | + $result = db_query("SELECT COUNT(*) AS cu FROM ttrss_users"); |
|
205 | + $num_users = db_fetch_result($result, 0, "cu"); |
|
206 | 206 | } ?> |
207 | 207 | |
208 | 208 | <?php if (!REG_MAX_USERS || $num_users < REG_MAX_USERS) { ?> |
@@ -210,8 +210,8 @@ discard block |
||
210 | 210 | <!-- If you have any rules or ToS you'd like to display, enter them here --> |
211 | 211 | |
212 | 212 | <?php if (file_exists("templates/register_notice.txt")) { |
213 | - require_once "templates/register_notice.txt"; |
|
214 | - } ?> |
|
213 | + require_once "templates/register_notice.txt"; |
|
214 | + } ?> |
|
215 | 215 | |
216 | 216 | <?php if (!$action) { ?> |
217 | 217 | |
@@ -245,114 +245,114 @@ discard block |
||
245 | 245 | <?php } else if ($action == "do_register") { ?> |
246 | 246 | |
247 | 247 | <?php |
248 | - $login = mb_strtolower(trim(db_escape_string($_REQUEST["login"]))); |
|
249 | - $email = trim(db_escape_string($_REQUEST["email"])); |
|
250 | - $test = trim(db_escape_string($_REQUEST["turing_test"])); |
|
248 | + $login = mb_strtolower(trim(db_escape_string($_REQUEST["login"]))); |
|
249 | + $email = trim(db_escape_string($_REQUEST["email"])); |
|
250 | + $test = trim(db_escape_string($_REQUEST["turing_test"])); |
|
251 | 251 | |
252 | - if (!$login || !$email || !$test) { |
|
253 | - print_error(__("Your registration information is incomplete.")); |
|
254 | - print "<p><form method=\"GET\" action=\"index.php\"> |
|
252 | + if (!$login || !$email || !$test) { |
|
253 | + print_error(__("Your registration information is incomplete.")); |
|
254 | + print "<p><form method=\"GET\" action=\"index.php\"> |
|
255 | 255 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> |
256 | 256 | </form>"; |
257 | - return; |
|
258 | - } |
|
257 | + return; |
|
258 | + } |
|
259 | 259 | |
260 | - if ($test == "four" || $test == "4") { |
|
260 | + if ($test == "four" || $test == "4") { |
|
261 | 261 | |
262 | - $result = db_query("SELECT id FROM ttrss_users WHERE |
|
262 | + $result = db_query("SELECT id FROM ttrss_users WHERE |
|
263 | 263 | login = '$login'"); |
264 | 264 | |
265 | - $is_registered = db_num_rows($result) > 0; |
|
265 | + $is_registered = db_num_rows($result) > 0; |
|
266 | 266 | |
267 | - if ($is_registered) { |
|
268 | - print_error(__('Sorry, this username is already taken.')); |
|
269 | - print "<p><form method=\"GET\" action=\"index.php\"> |
|
267 | + if ($is_registered) { |
|
268 | + print_error(__('Sorry, this username is already taken.')); |
|
269 | + print "<p><form method=\"GET\" action=\"index.php\"> |
|
270 | 270 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> |
271 | 271 | </form>"; |
272 | - } else { |
|
272 | + } else { |
|
273 | 273 | |
274 | - $password = make_password(); |
|
274 | + $password = make_password(); |
|
275 | 275 | |
276 | - $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
277 | - $pwd_hash = encrypt_password($password, $salt, true); |
|
276 | + $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
277 | + $pwd_hash = encrypt_password($password, $salt, true); |
|
278 | 278 | |
279 | - db_query("INSERT INTO ttrss_users |
|
279 | + db_query("INSERT INTO ttrss_users |
|
280 | 280 | (login,pwd_hash,access_level,last_login, email, created, salt) |
281 | 281 | VALUES ('$login', '$pwd_hash', 0, null, '$email', NOW(), '$salt')"); |
282 | 282 | |
283 | - $result = db_query("SELECT id FROM ttrss_users WHERE |
|
283 | + $result = db_query("SELECT id FROM ttrss_users WHERE |
|
284 | 284 | login = '$login' AND pwd_hash = '$pwd_hash'"); |
285 | 285 | |
286 | - if (db_num_rows($result) != 1) { |
|
287 | - print_error(__('Registration failed.')); |
|
288 | - print "<p><form method=\"GET\" action=\"index.php\"> |
|
286 | + if (db_num_rows($result) != 1) { |
|
287 | + print_error(__('Registration failed.')); |
|
288 | + print "<p><form method=\"GET\" action=\"index.php\"> |
|
289 | 289 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> |
290 | 290 | </form>"; |
291 | - } else { |
|
292 | - |
|
293 | - $new_uid = db_fetch_result($result, 0, "id"); |
|
294 | - |
|
295 | - initialize_user($new_uid); |
|
296 | - |
|
297 | - $reg_text = "Hi!\n". |
|
298 | - "\n". |
|
299 | - "You are receiving this message, because you (or somebody else) have opened\n". |
|
300 | - "an account at Tiny Tiny RSS.\n". |
|
301 | - "\n". |
|
302 | - "Your login information is as follows:\n". |
|
303 | - "\n". |
|
304 | - "Login: $login\n". |
|
305 | - "Password: $password\n". |
|
306 | - "\n". |
|
307 | - "Don't forget to login at least once to your new account, otherwise\n". |
|
308 | - "it will be deleted in 24 hours.\n". |
|
309 | - "\n". |
|
310 | - "If that wasn't you, just ignore this message. Thanks."; |
|
311 | - |
|
312 | - $mailer = new Mailer(); |
|
313 | - $rc = $mailer->mail(["to_address" => $email, |
|
314 | - "subject" => "Registration information for Tiny Tiny RSS", |
|
315 | - "message" => $reg_text]); |
|
316 | - |
|
317 | - if (!$rc) { |
|
318 | - print_error($mailer->error()); |
|
319 | - } |
|
320 | - |
|
321 | - $reg_text = "Hi!\n". |
|
322 | - "\n". |
|
323 | - "New user had registered at your Tiny Tiny RSS installation.\n". |
|
324 | - "\n". |
|
325 | - "Login: $login\n". |
|
326 | - "Email: $email\n"; |
|
327 | - |
|
328 | - $mailer = new Mailer(); |
|
329 | - $rc = $mailer->mail(["to_address" => REG_NOTIFY_ADDRESS, |
|
330 | - "subject" => "Registration notice for Tiny Tiny RSS", |
|
331 | - "message" => $reg_text]); |
|
332 | - |
|
333 | - if (!$rc) { |
|
334 | - print_error($mailer->error()); |
|
335 | - } |
|
336 | - |
|
337 | - print_notice(__("Account created successfully.")); |
|
338 | - |
|
339 | - print "<p><form method=\"GET\" action=\"index.php\"> |
|
291 | + } else { |
|
292 | + |
|
293 | + $new_uid = db_fetch_result($result, 0, "id"); |
|
294 | + |
|
295 | + initialize_user($new_uid); |
|
296 | + |
|
297 | + $reg_text = "Hi!\n". |
|
298 | + "\n". |
|
299 | + "You are receiving this message, because you (or somebody else) have opened\n". |
|
300 | + "an account at Tiny Tiny RSS.\n". |
|
301 | + "\n". |
|
302 | + "Your login information is as follows:\n". |
|
303 | + "\n". |
|
304 | + "Login: $login\n". |
|
305 | + "Password: $password\n". |
|
306 | + "\n". |
|
307 | + "Don't forget to login at least once to your new account, otherwise\n". |
|
308 | + "it will be deleted in 24 hours.\n". |
|
309 | + "\n". |
|
310 | + "If that wasn't you, just ignore this message. Thanks."; |
|
311 | + |
|
312 | + $mailer = new Mailer(); |
|
313 | + $rc = $mailer->mail(["to_address" => $email, |
|
314 | + "subject" => "Registration information for Tiny Tiny RSS", |
|
315 | + "message" => $reg_text]); |
|
316 | + |
|
317 | + if (!$rc) { |
|
318 | + print_error($mailer->error()); |
|
319 | + } |
|
320 | + |
|
321 | + $reg_text = "Hi!\n". |
|
322 | + "\n". |
|
323 | + "New user had registered at your Tiny Tiny RSS installation.\n". |
|
324 | + "\n". |
|
325 | + "Login: $login\n". |
|
326 | + "Email: $email\n"; |
|
327 | + |
|
328 | + $mailer = new Mailer(); |
|
329 | + $rc = $mailer->mail(["to_address" => REG_NOTIFY_ADDRESS, |
|
330 | + "subject" => "Registration notice for Tiny Tiny RSS", |
|
331 | + "message" => $reg_text]); |
|
332 | + |
|
333 | + if (!$rc) { |
|
334 | + print_error($mailer->error()); |
|
335 | + } |
|
336 | + |
|
337 | + print_notice(__("Account created successfully.")); |
|
338 | + |
|
339 | + print "<p><form method=\"GET\" action=\"index.php\"> |
|
340 | 340 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> |
341 | 341 | </form>"; |
342 | 342 | |
343 | - } |
|
343 | + } |
|
344 | 344 | |
345 | - } |
|
345 | + } |
|
346 | 346 | |
347 | - } else { |
|
348 | - print_error('Plese check the form again, you have failed the robot test.'); |
|
349 | - print "<p><form method=\"GET\" action=\"index.php\"> |
|
347 | + } else { |
|
348 | + print_error('Plese check the form again, you have failed the robot test.'); |
|
349 | + print "<p><form method=\"GET\" action=\"index.php\"> |
|
350 | 350 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> |
351 | 351 | </form>"; |
352 | 352 | |
353 | - } |
|
354 | - } |
|
355 | - ?> |
|
353 | + } |
|
354 | + } |
|
355 | + ?> |
|
356 | 356 | |
357 | 357 | <?php } else { ?> |
358 | 358 |
@@ -72,41 +72,41 @@ discard block |
||
72 | 72 | function find_match($curlscore, $curcscore, $curgtlang, $langval, $charval, |
73 | 73 | $gtlang) |
74 | 74 | { |
75 | - if ($curlscore < $langval) { |
|
75 | + if ($curlscore < $langval) { |
|
76 | 76 | $curlscore = $langval; |
77 | 77 | $curcscore = $charval; |
78 | 78 | $curgtlang = $gtlang; |
79 | - } else if ($curlscore == $langval) { |
|
79 | + } else if ($curlscore == $langval) { |
|
80 | 80 | if ($curcscore < $charval) { |
81 | - $curcscore = $charval; |
|
82 | - $curgtlang = $gtlang; |
|
81 | + $curcscore = $charval; |
|
82 | + $curgtlang = $gtlang; |
|
83 | 83 | } |
84 | - } |
|
85 | - return array($curlscore, $curcscore, $curgtlang); |
|
84 | + } |
|
85 | + return array($curlscore, $curcscore, $curgtlang); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | function al2gt($gettextlangs, $mime) { |
89 | - /* default to "everything is acceptable", as RFC2616 specifies */ |
|
90 | - $acceptLang = (($_SERVER["HTTP_ACCEPT_LANGUAGE"] == '') ? '*' : $_SERVER["HTTP_ACCEPT_LANGUAGE"]); |
|
91 | - $acceptChar = (($_SERVER["HTTP_ACCEPT_CHARSET"] == '') ? '*' : $_SERVER["HTTP_ACCEPT_CHARSET"]); |
|
92 | - $alparts = @preg_split("/,/", $acceptLang); |
|
93 | - $acparts = @preg_split("/,/", $acceptChar); |
|
89 | + /* default to "everything is acceptable", as RFC2616 specifies */ |
|
90 | + $acceptLang = (($_SERVER["HTTP_ACCEPT_LANGUAGE"] == '') ? '*' : $_SERVER["HTTP_ACCEPT_LANGUAGE"]); |
|
91 | + $acceptChar = (($_SERVER["HTTP_ACCEPT_CHARSET"] == '') ? '*' : $_SERVER["HTTP_ACCEPT_CHARSET"]); |
|
92 | + $alparts = @preg_split("/,/", $acceptLang); |
|
93 | + $acparts = @preg_split("/,/", $acceptChar); |
|
94 | 94 | |
95 | - /* Parse the contents of the Accept-Language header.*/ |
|
96 | - foreach ($alparts as $part) { |
|
95 | + /* Parse the contents of the Accept-Language header.*/ |
|
96 | + foreach ($alparts as $part) { |
|
97 | 97 | $part = trim($part); |
98 | 98 | if (preg_match("/;/", $part)) { |
99 | - $lang = @preg_split("/;/", $part); |
|
100 | - $score = @preg_split("/=/", $lang[1]); |
|
101 | - $alscores[$lang[0]] = $score[1]; |
|
99 | + $lang = @preg_split("/;/", $part); |
|
100 | + $score = @preg_split("/=/", $lang[1]); |
|
101 | + $alscores[$lang[0]] = $score[1]; |
|
102 | 102 | } else { |
103 | - $alscores[$part] = 1; |
|
103 | + $alscores[$part] = 1; |
|
104 | + } |
|
104 | 105 | } |
105 | - } |
|
106 | 106 | |
107 | - /* Do the same for the Accept-Charset header. */ |
|
107 | + /* Do the same for the Accept-Charset header. */ |
|
108 | 108 | |
109 | - /* RFC2616: ``If no "*" is present in an Accept-Charset field, then |
|
109 | + /* RFC2616: ``If no "*" is present in an Accept-Charset field, then |
|
110 | 110 | * all character sets not explicitly mentioned get a quality value of |
111 | 111 | * 0, except for ISO-8859-1, which gets a quality value of 1 if not |
112 | 112 | * explicitly mentioned.'' |
@@ -114,31 +114,31 @@ discard block |
||
114 | 114 | * Making it 2 for the time being, so that we |
115 | 115 | * can distinguish between "not specified" and "specified as 1" later |
116 | 116 | * on. */ |
117 | - $acscores["ISO-8859-1"] = 2; |
|
117 | + $acscores["ISO-8859-1"] = 2; |
|
118 | 118 | |
119 | - foreach ($acparts as $part) { |
|
119 | + foreach ($acparts as $part) { |
|
120 | 120 | $part = trim($part); |
121 | 121 | if (preg_match("/;/", $part)) { |
122 | - $cs = @preg_split("/;/", $part); |
|
123 | - $score = @preg_split("/=/", $cs[1]); |
|
124 | - $acscores[strtoupper($cs[0])] = $score[1]; |
|
122 | + $cs = @preg_split("/;/", $part); |
|
123 | + $score = @preg_split("/=/", $cs[1]); |
|
124 | + $acscores[strtoupper($cs[0])] = $score[1]; |
|
125 | 125 | } else { |
126 | - $acscores[strtoupper($part)] = 1; |
|
126 | + $acscores[strtoupper($part)] = 1; |
|
127 | + } |
|
127 | 128 | } |
128 | - } |
|
129 | - if ($acscores["ISO-8859-1"] == 2) { |
|
129 | + if ($acscores["ISO-8859-1"] == 2) { |
|
130 | 130 | $acscores["ISO-8859-1"] = (isset($acscores["*"]) ? $acscores["*"] : 1); |
131 | - } |
|
131 | + } |
|
132 | 132 | |
133 | - /* |
|
133 | + /* |
|
134 | 134 | * Loop through the available languages/encodings, and pick the one |
135 | 135 | * with the highest score, excluding the ones with a charset the user |
136 | 136 | * did not include. |
137 | 137 | */ |
138 | - $curlscore = 0; |
|
139 | - $curcscore = 0; |
|
140 | - $curgtlang = null; |
|
141 | - foreach ($gettextlangs as $gtlang) { |
|
138 | + $curlscore = 0; |
|
139 | + $curcscore = 0; |
|
140 | + $curgtlang = null; |
|
141 | + foreach ($gettextlangs as $gtlang) { |
|
142 | 142 | |
143 | 143 | $tmp1 = preg_replace("/\_/", "-", $gtlang); |
144 | 144 | $tmp2 = @preg_split("/\./", $tmp1); |
@@ -147,38 +147,38 @@ discard block |
||
147 | 147 | $noct = @preg_split("/-/", $allang); |
148 | 148 | |
149 | 149 | $testvals = array( |
150 | - array(@$alscores[$allang], @$acscores[$gtcs]), |
|
151 | - array(@$alscores[$noct[0]], @$acscores[$gtcs]), |
|
152 | - array(@$alscores[$allang], @$acscores["*"]), |
|
153 | - array(@$alscores[$noct[0]], @$acscores["*"]), |
|
154 | - array(@$alscores["*"], @$acscores[$gtcs]), |
|
155 | - array(@$alscores["*"], @$acscores["*"])); |
|
150 | + array(@$alscores[$allang], @$acscores[$gtcs]), |
|
151 | + array(@$alscores[$noct[0]], @$acscores[$gtcs]), |
|
152 | + array(@$alscores[$allang], @$acscores["*"]), |
|
153 | + array(@$alscores[$noct[0]], @$acscores["*"]), |
|
154 | + array(@$alscores["*"], @$acscores[$gtcs]), |
|
155 | + array(@$alscores["*"], @$acscores["*"])); |
|
156 | 156 | |
157 | 157 | $found = false; |
158 | 158 | foreach ($testvals as $tval) { |
159 | - if (!$found && isset($tval[0]) && isset($tval[1])) { |
|
159 | + if (!$found && isset($tval[0]) && isset($tval[1])) { |
|
160 | 160 | $arr = find_match($curlscore, $curcscore, $curgtlang, $tval[0], |
161 | - $tval[1], $gtlang); |
|
161 | + $tval[1], $gtlang); |
|
162 | 162 | $curlscore = $arr[0]; |
163 | 163 | $curcscore = $arr[1]; |
164 | 164 | $curgtlang = $arr[2]; |
165 | 165 | $found = true; |
166 | - } |
|
166 | + } |
|
167 | + } |
|
167 | 168 | } |
168 | - } |
|
169 | 169 | |
170 | - /* We must re-parse the gettext-string now, since we may have found it |
|
170 | + /* We must re-parse the gettext-string now, since we may have found it |
|
171 | 171 | * through a "*" qualifier.*/ |
172 | 172 | |
173 | - $gtparts = @preg_split("/\./", $curgtlang); |
|
174 | - $tmp = strtolower($gtparts[0]); |
|
175 | - $lang = preg_replace("/\_/", "-", $tmp); |
|
176 | - $charset = $gtparts[1]; |
|
173 | + $gtparts = @preg_split("/\./", $curgtlang); |
|
174 | + $tmp = strtolower($gtparts[0]); |
|
175 | + $lang = preg_replace("/\_/", "-", $tmp); |
|
176 | + $charset = $gtparts[1]; |
|
177 | 177 | |
178 | - header("Content-Language: $lang"); |
|
179 | - header("Content-Type: $mime; charset=$charset"); |
|
178 | + header("Content-Language: $lang"); |
|
179 | + header("Content-Type: $mime; charset=$charset"); |
|
180 | 180 | |
181 | - return $curgtlang; |
|
181 | + return $curgtlang; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | ?> |
@@ -127,16 +127,16 @@ discard block |
||
127 | 127 | $bitmapinfo = unpack("Vsize", $data); |
128 | 128 | if ($bitmapinfo["size"] == 40) { |
129 | 129 | $info = unpack("Vsize/". |
130 | - "Vwidth/". |
|
131 | - "Vheight/". |
|
132 | - "vplanes/". |
|
133 | - "vbpp/". |
|
134 | - "Vcompress/". |
|
135 | - "Vsize/". |
|
136 | - "Vxres/". |
|
137 | - "Vyres/". |
|
138 | - "Vpalcolors/". |
|
139 | - "Vimpcolors/", $data); |
|
130 | + "Vwidth/". |
|
131 | + "Vheight/". |
|
132 | + "vplanes/". |
|
133 | + "vbpp/". |
|
134 | + "Vcompress/". |
|
135 | + "Vsize/". |
|
136 | + "Vxres/". |
|
137 | + "Vyres/". |
|
138 | + "Vpalcolors/". |
|
139 | + "Vimpcolors/", $data); |
|
140 | 140 | if ($e["bpp"] == 0) { |
141 | 141 | $e["bpp"] = $info["bpp"]; |
142 | 142 | } |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | for ($y = 0; $y < $height; $y++) { |
245 | 245 | for ($x = 0; $x < $width; $x++) { |
246 | 246 | imagesetpixel($img, $x, $y, |
247 | - $XOR[$y][$x]); |
|
247 | + $XOR[$y][$x]); |
|
248 | 248 | } |
249 | 249 | } |
250 | 250 | return $img; |
@@ -255,10 +255,10 @@ discard block |
||
255 | 255 | $x = 0; |
256 | 256 | while ($x < $width) { |
257 | 257 | for ($b = 0x80; |
258 | - $b > 0 && $x < $width; $b >>= 1) { |
|
258 | + $b > 0 && $x < $width; $b >>= 1) { |
|
259 | 259 | if (!(ord($data[$offset]) & $b)) { |
260 | 260 | imagesetpixel($img, $x, $y, |
261 | - $XOR[$y][$x]); |
|
261 | + $XOR[$y][$x]); |
|
262 | 262 | } |
263 | 263 | $x++; |
264 | 264 | } |
@@ -67,8 +67,9 @@ |
||
67 | 67 | $most_pixels = 0; |
68 | 68 | for ($i = 0; $i < $h["num"]; $i++) { |
69 | 69 | $entry = substr($ico, 6 + 16 * $i, 16); |
70 | - if (!$entry || strlen($entry) < 16) |
|
71 | - continue; |
|
70 | + if (!$entry || strlen($entry) < 16) { |
|
71 | + continue; |
|
72 | + } |
|
72 | 73 | $e = unpack("Cwidth/". |
73 | 74 | "Cheight/". |
74 | 75 | "Ccolors/". |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * @access public |
162 | 162 | */ |
163 | 163 | function __construct() { |
164 | - $this->templateValid = false; } |
|
164 | + $this->templateValid = false; } |
|
165 | 165 | |
166 | 166 | //--- template string handling -------------------------------------------------------------------------------------- |
167 | 167 | |
@@ -172,13 +172,13 @@ discard block |
||
172 | 172 | * @access public |
173 | 173 | */ |
174 | 174 | function readTemplateFromFile($fileName) { |
175 | - if (!$this->readFileIntoString($fileName, $s)) { |
|
176 | - $this->triggerError("Error while reading template file ".$fileName."."); |
|
177 | - return false; } |
|
178 | - if (!$this->setTemplateString($s)) { |
|
179 | - return false; |
|
180 | - } |
|
181 | - return true; } |
|
175 | + if (!$this->readFileIntoString($fileName, $s)) { |
|
176 | + $this->triggerError("Error while reading template file ".$fileName."."); |
|
177 | + return false; } |
|
178 | + if (!$this->setTemplateString($s)) { |
|
179 | + return false; |
|
180 | + } |
|
181 | + return true; } |
|
182 | 182 | |
183 | 183 | /** |
184 | 184 | * Assigns a new template string. |
@@ -187,14 +187,14 @@ discard block |
||
187 | 187 | * @access public |
188 | 188 | */ |
189 | 189 | function setTemplateString($templateString) { |
190 | - $this->templateValid = false; |
|
191 | - $this->template = $templateString; |
|
192 | - if (!$this->parseTemplate()) { |
|
193 | - return false; |
|
194 | - } |
|
195 | - $this->reset(); |
|
196 | - $this->templateValid = true; |
|
197 | - return true; } |
|
190 | + $this->templateValid = false; |
|
191 | + $this->template = $templateString; |
|
192 | + if (!$this->parseTemplate()) { |
|
193 | + return false; |
|
194 | + } |
|
195 | + $this->reset(); |
|
196 | + $this->templateValid = true; |
|
197 | + return true; } |
|
198 | 198 | |
199 | 199 | /** |
200 | 200 | * Loads the template string for a subtemplate (used for the $Include command). |
@@ -202,11 +202,11 @@ discard block |
||
202 | 202 | * @access private |
203 | 203 | */ |
204 | 204 | function loadSubtemplate($subtemplateName, &$s) { |
205 | - $subtemplateFileName = $this->combineFileSystemPath($this->subtemplateBasePath, $subtemplateName); |
|
206 | - if (!$this->readFileIntoString($subtemplateFileName, $s)) { |
|
207 | - $this->triggerError("Error while reading subtemplate file ".$subtemplateFileName."."); |
|
208 | - return false; } |
|
209 | - return true; } |
|
205 | + $subtemplateFileName = $this->combineFileSystemPath($this->subtemplateBasePath, $subtemplateName); |
|
206 | + if (!$this->readFileIntoString($subtemplateFileName, $s)) { |
|
207 | + $this->triggerError("Error while reading subtemplate file ".$subtemplateFileName."."); |
|
208 | + return false; } |
|
209 | + return true; } |
|
210 | 210 | |
211 | 211 | //--- template parsing ---------------------------------------------------------------------------------------------- |
212 | 212 | |
@@ -216,34 +216,34 @@ discard block |
||
216 | 216 | * @access private |
217 | 217 | */ |
218 | 218 | function parseTemplate() { |
219 | - $this->initParsing(); |
|
220 | - $this->beginMainBlock(); |
|
221 | - if (!$this->parseTemplateCommands()) { |
|
222 | - return false; |
|
223 | - } |
|
224 | - $this->endMainBlock(); |
|
225 | - if (!$this->checkBlockDefinitionsComplete()) { |
|
226 | - return false; |
|
227 | - } |
|
228 | - if (!$this->parseTemplateVariables()) { |
|
229 | - return false; |
|
230 | - } |
|
231 | - $this->associateVariablesWithBlocks(); |
|
232 | - return true; } |
|
219 | + $this->initParsing(); |
|
220 | + $this->beginMainBlock(); |
|
221 | + if (!$this->parseTemplateCommands()) { |
|
222 | + return false; |
|
223 | + } |
|
224 | + $this->endMainBlock(); |
|
225 | + if (!$this->checkBlockDefinitionsComplete()) { |
|
226 | + return false; |
|
227 | + } |
|
228 | + if (!$this->parseTemplateVariables()) { |
|
229 | + return false; |
|
230 | + } |
|
231 | + $this->associateVariablesWithBlocks(); |
|
232 | + return true; } |
|
233 | 233 | |
234 | 234 | /** |
235 | 235 | * @access private |
236 | 236 | */ |
237 | 237 | function initParsing() { |
238 | - $this->varTab = array(); |
|
239 | - $this->varTabCnt = 0; |
|
240 | - $this->varNameToNoMap = array(); |
|
241 | - $this->varRefTab = array(); |
|
242 | - $this->varRefTabCnt = 0; |
|
243 | - $this->blockTab = array(); |
|
244 | - $this->blockTabCnt = 0; |
|
245 | - $this->blockNameToNoMap = array(); |
|
246 | - $this->openBlocksTab = array(); } |
|
238 | + $this->varTab = array(); |
|
239 | + $this->varTabCnt = 0; |
|
240 | + $this->varNameToNoMap = array(); |
|
241 | + $this->varRefTab = array(); |
|
242 | + $this->varRefTabCnt = 0; |
|
243 | + $this->blockTab = array(); |
|
244 | + $this->blockTabCnt = 0; |
|
245 | + $this->blockNameToNoMap = array(); |
|
246 | + $this->openBlocksTab = array(); } |
|
247 | 247 | |
248 | 248 | /** |
249 | 249 | * Registers the main block. |
@@ -251,27 +251,27 @@ discard block |
||
251 | 251 | * @access private |
252 | 252 | */ |
253 | 253 | function beginMainBlock() { |
254 | - $blockNo = 0; |
|
255 | - $this->registerBlock('@@InternalMainBlock@@', $blockNo); |
|
256 | - $bte = & $this->blockTab[$blockNo]; |
|
257 | - $bte['tPosBegin'] = 0; |
|
258 | - $bte['tPosContentsBegin'] = 0; |
|
259 | - $bte['nestingLevel'] = 0; |
|
260 | - $bte['parentBlockNo'] = -1; |
|
261 | - $bte['definitionIsOpen'] = true; |
|
262 | - $this->openBlocksTab[0] = $blockNo; |
|
263 | - $this->currentNestingLevel = 1; } |
|
254 | + $blockNo = 0; |
|
255 | + $this->registerBlock('@@InternalMainBlock@@', $blockNo); |
|
256 | + $bte = & $this->blockTab[$blockNo]; |
|
257 | + $bte['tPosBegin'] = 0; |
|
258 | + $bte['tPosContentsBegin'] = 0; |
|
259 | + $bte['nestingLevel'] = 0; |
|
260 | + $bte['parentBlockNo'] = -1; |
|
261 | + $bte['definitionIsOpen'] = true; |
|
262 | + $this->openBlocksTab[0] = $blockNo; |
|
263 | + $this->currentNestingLevel = 1; } |
|
264 | 264 | |
265 | 265 | /** |
266 | 266 | * Completes the main block registration. |
267 | 267 | * @access private |
268 | 268 | */ |
269 | 269 | function endMainBlock() { |
270 | - $bte = & $this->blockTab[0]; |
|
271 | - $bte['tPosContentsEnd'] = strlen($this->template); |
|
272 | - $bte['tPosEnd'] = strlen($this->template); |
|
273 | - $bte['definitionIsOpen'] = false; |
|
274 | - $this->currentNestingLevel -= 1; } |
|
270 | + $bte = & $this->blockTab[0]; |
|
271 | + $bte['tPosContentsEnd'] = strlen($this->template); |
|
272 | + $bte['tPosEnd'] = strlen($this->template); |
|
273 | + $bte['definitionIsOpen'] = false; |
|
274 | + $this->currentNestingLevel -= 1; } |
|
275 | 275 | |
276 | 276 | /** |
277 | 277 | * Parses commands within the template in the format "<!-- $command parameters -->". |
@@ -279,46 +279,46 @@ discard block |
||
279 | 279 | * @access private |
280 | 280 | */ |
281 | 281 | function parseTemplateCommands() { |
282 | - $p = 0; |
|
283 | - while (true) { |
|
284 | - $p0 = strpos($this->template, '<!--', $p); |
|
285 | - if ($p0 === false) break; |
|
286 | - $p = strpos($this->template, '-->', $p0); |
|
287 | - if ($p === false) { |
|
288 | - $this->triggerError("Invalid HTML comment in template at offset $p0."); |
|
289 | - return false; } |
|
290 | - $p += 3; |
|
291 | - $cmdL = substr($this->template, $p0 + 4, $p - $p0 - 7); |
|
292 | - if (!$this->processTemplateCommand($cmdL, $p0, $p, $resumeFromStart)) |
|
293 | - return false; |
|
294 | - if ($resumeFromStart) $p = $p0; } |
|
295 | - return true; } |
|
282 | + $p = 0; |
|
283 | + while (true) { |
|
284 | + $p0 = strpos($this->template, '<!--', $p); |
|
285 | + if ($p0 === false) break; |
|
286 | + $p = strpos($this->template, '-->', $p0); |
|
287 | + if ($p === false) { |
|
288 | + $this->triggerError("Invalid HTML comment in template at offset $p0."); |
|
289 | + return false; } |
|
290 | + $p += 3; |
|
291 | + $cmdL = substr($this->template, $p0 + 4, $p - $p0 - 7); |
|
292 | + if (!$this->processTemplateCommand($cmdL, $p0, $p, $resumeFromStart)) |
|
293 | + return false; |
|
294 | + if ($resumeFromStart) $p = $p0; } |
|
295 | + return true; } |
|
296 | 296 | |
297 | 297 | /** |
298 | 298 | * @return boolean true on success, false on error. |
299 | 299 | * @access private |
300 | 300 | */ |
301 | 301 | function processTemplateCommand($cmdL, $cmdTPosBegin, $cmdTPosEnd, &$resumeFromStart) { |
302 | - $resumeFromStart = false; |
|
303 | - $p = 0; |
|
304 | - $cmd = ''; |
|
305 | - if (!$this->parseWord($cmdL, $p, $cmd)) return true; |
|
306 | - $parms = substr($cmdL, $p); |
|
307 | - switch (strtoupper($cmd)) { |
|
308 | - case '$BEGINBLOCK': |
|
302 | + $resumeFromStart = false; |
|
303 | + $p = 0; |
|
304 | + $cmd = ''; |
|
305 | + if (!$this->parseWord($cmdL, $p, $cmd)) return true; |
|
306 | + $parms = substr($cmdL, $p); |
|
307 | + switch (strtoupper($cmd)) { |
|
308 | + case '$BEGINBLOCK': |
|
309 | 309 | if (!$this->processBeginBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
310 | 310 | return false; |
311 | - break; |
|
312 | - case '$ENDBLOCK': |
|
311 | + break; |
|
312 | + case '$ENDBLOCK': |
|
313 | 313 | if (!$this->processEndBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
314 | 314 | return false; |
315 | - break; |
|
316 | - case '$INCLUDE': |
|
315 | + break; |
|
316 | + case '$INCLUDE': |
|
317 | 317 | if (!$this->processincludeCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
318 | 318 | return false; |
319 | - $resumeFromStart = true; |
|
320 | - break; |
|
321 | - default: |
|
319 | + $resumeFromStart = true; |
|
320 | + break; |
|
321 | + default: |
|
322 | 322 | if ($cmd{0} == '$' && !(strlen($cmd) >= 2 && $cmd{1} == '{')) { |
323 | 323 | $this->triggerError("Unknown command \"$cmd\" in template at offset $cmdTPosBegin."); |
324 | 324 | return false; }} |
@@ -330,25 +330,25 @@ discard block |
||
330 | 330 | * @access private |
331 | 331 | */ |
332 | 332 | function processBeginBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd) { |
333 | - $p = 0; |
|
334 | - if (!$this->parseWord($parms, $p, $blockName)) { |
|
335 | - $this->triggerError("Missing block name in \$BeginBlock command in template at offset $cmdTPosBegin."); |
|
336 | - return false; } |
|
337 | - if (trim(substr($parms, $p)) != '') { |
|
338 | - $this->triggerError("Extra parameter in \$BeginBlock command in template at offset $cmdTPosBegin."); |
|
339 | - return false; } |
|
340 | - $this->registerBlock($blockName, $blockNo); |
|
341 | - $btr = & $this->blockTab[$blockNo]; |
|
342 | - $btr['tPosBegin'] = $cmdTPosBegin; |
|
343 | - $btr['tPosContentsBegin'] = $cmdTPosEnd; |
|
344 | - $btr['nestingLevel'] = $this->currentNestingLevel; |
|
345 | - $btr['parentBlockNo'] = $this->openBlocksTab[$this->currentNestingLevel - 1]; |
|
346 | - $this->openBlocksTab[$this->currentNestingLevel] = $blockNo; |
|
347 | - $this->currentNestingLevel += 1; |
|
348 | - if ($this->currentNestingLevel > $this->maxNestingLevel) { |
|
349 | - $this->triggerError("Block nesting overflow in template at offset $cmdTPosBegin."); |
|
350 | - return false; } |
|
351 | - return true; } |
|
333 | + $p = 0; |
|
334 | + if (!$this->parseWord($parms, $p, $blockName)) { |
|
335 | + $this->triggerError("Missing block name in \$BeginBlock command in template at offset $cmdTPosBegin."); |
|
336 | + return false; } |
|
337 | + if (trim(substr($parms, $p)) != '') { |
|
338 | + $this->triggerError("Extra parameter in \$BeginBlock command in template at offset $cmdTPosBegin."); |
|
339 | + return false; } |
|
340 | + $this->registerBlock($blockName, $blockNo); |
|
341 | + $btr = & $this->blockTab[$blockNo]; |
|
342 | + $btr['tPosBegin'] = $cmdTPosBegin; |
|
343 | + $btr['tPosContentsBegin'] = $cmdTPosEnd; |
|
344 | + $btr['nestingLevel'] = $this->currentNestingLevel; |
|
345 | + $btr['parentBlockNo'] = $this->openBlocksTab[$this->currentNestingLevel - 1]; |
|
346 | + $this->openBlocksTab[$this->currentNestingLevel] = $blockNo; |
|
347 | + $this->currentNestingLevel += 1; |
|
348 | + if ($this->currentNestingLevel > $this->maxNestingLevel) { |
|
349 | + $this->triggerError("Block nesting overflow in template at offset $cmdTPosBegin."); |
|
350 | + return false; } |
|
351 | + return true; } |
|
352 | 352 | |
353 | 353 | /** |
354 | 354 | * Processes the $EndBlock command. |
@@ -356,47 +356,47 @@ discard block |
||
356 | 356 | * @access private |
357 | 357 | */ |
358 | 358 | function processEndBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd) { |
359 | - $p = 0; |
|
360 | - if (!$this->parseWord($parms, $p, $blockName)) { |
|
361 | - $this->triggerError("Missing block name in \$EndBlock command in template at offset $cmdTPosBegin."); |
|
362 | - return false; } |
|
363 | - if (trim(substr($parms, $p)) != '') { |
|
364 | - $this->triggerError("Extra parameter in \$EndBlock command in template at offset $cmdTPosBegin."); |
|
365 | - return false; } |
|
366 | - if (!$this->lookupBlockName($blockName, $blockNo)) { |
|
367 | - $this->triggerError("Undefined block name \"$blockName\" in \$EndBlock command in template at offset $cmdTPosBegin."); |
|
368 | - return false; } |
|
369 | - $this->currentNestingLevel -= 1; |
|
370 | - $btr = & $this->blockTab[$blockNo]; |
|
371 | - if (!$btr['definitionIsOpen']) { |
|
372 | - $this->triggerError("Multiple \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin."); |
|
373 | - return false; } |
|
374 | - if ($btr['nestingLevel'] != $this->currentNestingLevel) { |
|
375 | - $this->triggerError("Block nesting level mismatch at \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin."); |
|
376 | - return false; } |
|
377 | - $btr['tPosContentsEnd'] = $cmdTPosBegin; |
|
378 | - $btr['tPosEnd'] = $cmdTPosEnd; |
|
379 | - $btr['definitionIsOpen'] = false; |
|
380 | - return true; } |
|
359 | + $p = 0; |
|
360 | + if (!$this->parseWord($parms, $p, $blockName)) { |
|
361 | + $this->triggerError("Missing block name in \$EndBlock command in template at offset $cmdTPosBegin."); |
|
362 | + return false; } |
|
363 | + if (trim(substr($parms, $p)) != '') { |
|
364 | + $this->triggerError("Extra parameter in \$EndBlock command in template at offset $cmdTPosBegin."); |
|
365 | + return false; } |
|
366 | + if (!$this->lookupBlockName($blockName, $blockNo)) { |
|
367 | + $this->triggerError("Undefined block name \"$blockName\" in \$EndBlock command in template at offset $cmdTPosBegin."); |
|
368 | + return false; } |
|
369 | + $this->currentNestingLevel -= 1; |
|
370 | + $btr = & $this->blockTab[$blockNo]; |
|
371 | + if (!$btr['definitionIsOpen']) { |
|
372 | + $this->triggerError("Multiple \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin."); |
|
373 | + return false; } |
|
374 | + if ($btr['nestingLevel'] != $this->currentNestingLevel) { |
|
375 | + $this->triggerError("Block nesting level mismatch at \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin."); |
|
376 | + return false; } |
|
377 | + $btr['tPosContentsEnd'] = $cmdTPosBegin; |
|
378 | + $btr['tPosEnd'] = $cmdTPosEnd; |
|
379 | + $btr['definitionIsOpen'] = false; |
|
380 | + return true; } |
|
381 | 381 | |
382 | 382 | /** |
383 | 383 | * @access private |
384 | 384 | */ |
385 | 385 | function registerBlock($blockName, &$blockNo) { |
386 | - $blockNo = $this->blockTabCnt++; |
|
387 | - $btr = & $this->blockTab[$blockNo]; |
|
388 | - $btr = array(); |
|
389 | - $btr['blockName'] = $blockName; |
|
390 | - if (!$this->lookupBlockName($blockName, $btr['nextWithSameName'])) |
|
391 | - $btr['nextWithSameName'] = -1; |
|
392 | - $btr['definitionIsOpen'] = true; |
|
393 | - $btr['instances'] = 0; |
|
394 | - $btr['firstBlockInstNo'] = -1; |
|
395 | - $btr['lastBlockInstNo'] = -1; |
|
396 | - $btr['blockVarCnt'] = 0; |
|
397 | - $btr['firstVarRefNo'] = -1; |
|
398 | - $btr['blockVarNoToVarNoMap'] = array(); |
|
399 | - $this->blockNameToNoMap[strtoupper($blockName)] = $blockNo; } |
|
386 | + $blockNo = $this->blockTabCnt++; |
|
387 | + $btr = & $this->blockTab[$blockNo]; |
|
388 | + $btr = array(); |
|
389 | + $btr['blockName'] = $blockName; |
|
390 | + if (!$this->lookupBlockName($blockName, $btr['nextWithSameName'])) |
|
391 | + $btr['nextWithSameName'] = -1; |
|
392 | + $btr['definitionIsOpen'] = true; |
|
393 | + $btr['instances'] = 0; |
|
394 | + $btr['firstBlockInstNo'] = -1; |
|
395 | + $btr['lastBlockInstNo'] = -1; |
|
396 | + $btr['blockVarCnt'] = 0; |
|
397 | + $btr['firstVarRefNo'] = -1; |
|
398 | + $btr['blockVarNoToVarNoMap'] = array(); |
|
399 | + $this->blockNameToNoMap[strtoupper($blockName)] = $blockNo; } |
|
400 | 400 | |
401 | 401 | /** |
402 | 402 | * Checks that all block definitions are closed. |
@@ -404,15 +404,15 @@ discard block |
||
404 | 404 | * @access private |
405 | 405 | */ |
406 | 406 | function checkBlockDefinitionsComplete() { |
407 | - for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) { |
|
408 | - $btr = & $this->blockTab[$blockNo]; |
|
409 | - if ($btr['definitionIsOpen']) { |
|
410 | - $this->triggerError("Missing \$EndBlock command in template for block ".$btr['blockName']."."); |
|
411 | - return false; }} |
|
412 | - if ($this->currentNestingLevel != 0) { |
|
413 | - $this->triggerError("Block nesting level error at end of template."); |
|
414 | - return false; } |
|
415 | - return true; } |
|
407 | + for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) { |
|
408 | + $btr = & $this->blockTab[$blockNo]; |
|
409 | + if ($btr['definitionIsOpen']) { |
|
410 | + $this->triggerError("Missing \$EndBlock command in template for block ".$btr['blockName']."."); |
|
411 | + return false; }} |
|
412 | + if ($this->currentNestingLevel != 0) { |
|
413 | + $this->triggerError("Block nesting level error at end of template."); |
|
414 | + return false; } |
|
415 | + return true; } |
|
416 | 416 | |
417 | 417 | /** |
418 | 418 | * Processes the $Include command. |
@@ -420,14 +420,14 @@ discard block |
||
420 | 420 | * @access private |
421 | 421 | */ |
422 | 422 | function processIncludeCmd($parms, $cmdTPosBegin, $cmdTPosEnd) { |
423 | - $p = 0; |
|
424 | - if (!$this->parseWordOrQuotedString($parms, $p, $subtemplateName)) { |
|
425 | - $this->triggerError("Missing or invalid subtemplate name in \$Include command in template at offset $cmdTPosBegin."); |
|
426 | - return false; } |
|
427 | - if (trim(substr($parms, $p)) != '') { |
|
428 | - $this->triggerError("Extra parameter in \$include command in template at offset $cmdTPosBegin."); |
|
429 | - return false; } |
|
430 | - return $this->insertSubtemplate($subtemplateName, $cmdTPosBegin, $cmdTPosEnd); } |
|
423 | + $p = 0; |
|
424 | + if (!$this->parseWordOrQuotedString($parms, $p, $subtemplateName)) { |
|
425 | + $this->triggerError("Missing or invalid subtemplate name in \$Include command in template at offset $cmdTPosBegin."); |
|
426 | + return false; } |
|
427 | + if (trim(substr($parms, $p)) != '') { |
|
428 | + $this->triggerError("Extra parameter in \$include command in template at offset $cmdTPosBegin."); |
|
429 | + return false; } |
|
430 | + return $this->insertSubtemplate($subtemplateName, $cmdTPosBegin, $cmdTPosEnd); } |
|
431 | 431 | |
432 | 432 | /** |
433 | 433 | * Processes the $Include command. |
@@ -435,14 +435,14 @@ discard block |
||
435 | 435 | * @access private |
436 | 436 | */ |
437 | 437 | function insertSubtemplate($subtemplateName, $tPos1, $tPos2) { |
438 | - if (strlen($this->template) > $this->maxInclTemplateSize) { |
|
439 | - $this->triggerError("Subtemplate include aborted because the internal template string is longer than $this->maxInclTemplateSize characters."); |
|
440 | - return false; } |
|
441 | - if (!$this->loadSubtemplate($subtemplateName, $subtemplate)) return false; |
|
442 | - // (Copying the template to insert a subtemplate is a bit slow. In a future implementation of MiniTemplator, |
|
443 | - // a table could be used that contains references to the string fragments.) |
|
444 | - $this->template = substr($this->template, 0, $tPos1).$subtemplate.substr($this->template, $tPos2); |
|
445 | - return true; } |
|
438 | + if (strlen($this->template) > $this->maxInclTemplateSize) { |
|
439 | + $this->triggerError("Subtemplate include aborted because the internal template string is longer than $this->maxInclTemplateSize characters."); |
|
440 | + return false; } |
|
441 | + if (!$this->loadSubtemplate($subtemplateName, $subtemplate)) return false; |
|
442 | + // (Copying the template to insert a subtemplate is a bit slow. In a future implementation of MiniTemplator, |
|
443 | + // a table could be used that contains references to the string fragments.) |
|
444 | + $this->template = substr($this->template, 0, $tPos1).$subtemplate.substr($this->template, $tPos2); |
|
445 | + return true; } |
|
446 | 446 | |
447 | 447 | /** |
448 | 448 | * Parses variable references within the template in the format "${VarName}". |
@@ -450,79 +450,79 @@ discard block |
||
450 | 450 | * @access private |
451 | 451 | */ |
452 | 452 | function parseTemplateVariables() { |
453 | - $p = 0; |
|
454 | - while (true) { |
|
455 | - $p = strpos($this->template, '${', $p); |
|
456 | - if ($p === false) { |
|
457 | - break; |
|
458 | - } |
|
459 | - $p0 = $p; |
|
460 | - $p = strpos($this->template, '}', $p); |
|
461 | - if ($p === false) { |
|
462 | - $this->triggerError("Invalid variable reference in template at offset $p0."); |
|
463 | - return false; } |
|
464 | - $p += 1; |
|
465 | - $varName = trim(substr($this->template, $p0 + 2, $p - $p0 - 3)); |
|
466 | - if (strlen($varName) == 0) { |
|
467 | - $this->triggerError("Empty variable name in template at offset $p0."); |
|
468 | - return false; } |
|
469 | - $this->registerVariableReference($varName, $p0, $p); } |
|
470 | - return true; } |
|
453 | + $p = 0; |
|
454 | + while (true) { |
|
455 | + $p = strpos($this->template, '${', $p); |
|
456 | + if ($p === false) { |
|
457 | + break; |
|
458 | + } |
|
459 | + $p0 = $p; |
|
460 | + $p = strpos($this->template, '}', $p); |
|
461 | + if ($p === false) { |
|
462 | + $this->triggerError("Invalid variable reference in template at offset $p0."); |
|
463 | + return false; } |
|
464 | + $p += 1; |
|
465 | + $varName = trim(substr($this->template, $p0 + 2, $p - $p0 - 3)); |
|
466 | + if (strlen($varName) == 0) { |
|
467 | + $this->triggerError("Empty variable name in template at offset $p0."); |
|
468 | + return false; } |
|
469 | + $this->registerVariableReference($varName, $p0, $p); } |
|
470 | + return true; } |
|
471 | 471 | |
472 | 472 | /** |
473 | 473 | * @access private |
474 | 474 | */ |
475 | 475 | function registerVariableReference($varName, $tPosBegin, $tPosEnd) { |
476 | - if (!$this->lookupVariableName($varName, $varNo)) |
|
477 | - $this->registerVariable($varName, $varNo); |
|
478 | - $varRefNo = $this->varRefTabCnt++; |
|
479 | - $vrtr = & $this->varRefTab[$varRefNo]; |
|
480 | - $vrtr = array(); |
|
481 | - $vrtr['tPosBegin'] = $tPosBegin; |
|
482 | - $vrtr['tPosEnd'] = $tPosEnd; |
|
483 | - $vrtr['varNo'] = $varNo; } |
|
476 | + if (!$this->lookupVariableName($varName, $varNo)) |
|
477 | + $this->registerVariable($varName, $varNo); |
|
478 | + $varRefNo = $this->varRefTabCnt++; |
|
479 | + $vrtr = & $this->varRefTab[$varRefNo]; |
|
480 | + $vrtr = array(); |
|
481 | + $vrtr['tPosBegin'] = $tPosBegin; |
|
482 | + $vrtr['tPosEnd'] = $tPosEnd; |
|
483 | + $vrtr['varNo'] = $varNo; } |
|
484 | 484 | |
485 | 485 | /** |
486 | 486 | * @access private |
487 | 487 | */ |
488 | 488 | function registerVariable($varName, &$varNo) { |
489 | - $varNo = $this->varTabCnt++; |
|
490 | - $vtr = & $this->varTab[$varNo]; |
|
491 | - $vtr = array(); |
|
492 | - $vtr['varName'] = $varName; |
|
493 | - $vtr['varValue'] = ''; |
|
494 | - $this->varNameToNoMap[strtoupper($varName)] = $varNo; } |
|
489 | + $varNo = $this->varTabCnt++; |
|
490 | + $vtr = & $this->varTab[$varNo]; |
|
491 | + $vtr = array(); |
|
492 | + $vtr['varName'] = $varName; |
|
493 | + $vtr['varValue'] = ''; |
|
494 | + $this->varNameToNoMap[strtoupper($varName)] = $varNo; } |
|
495 | 495 | |
496 | 496 | /** |
497 | 497 | * Associates variable references with blocks. |
498 | 498 | * @access private |
499 | 499 | */ |
500 | 500 | function associateVariablesWithBlocks() { |
501 | - $varRefNo = 0; |
|
502 | - $activeBlockNo = 0; |
|
503 | - $nextBlockNo = 1; |
|
504 | - while ($varRefNo < $this->varRefTabCnt) { |
|
505 | - $vrtr = & $this->varRefTab[$varRefNo]; |
|
506 | - $varRefTPos = $vrtr['tPosBegin']; |
|
507 | - $varNo = $vrtr['varNo']; |
|
508 | - if ($varRefTPos >= $this->blockTab[$activeBlockNo]['tPosEnd']) { |
|
509 | - $activeBlockNo = $this->blockTab[$activeBlockNo]['parentBlockNo']; |
|
510 | - continue; } |
|
511 | - if ($nextBlockNo < $this->blockTabCnt) { |
|
512 | - if ($varRefTPos >= $this->blockTab[$nextBlockNo]['tPosBegin']) { |
|
501 | + $varRefNo = 0; |
|
502 | + $activeBlockNo = 0; |
|
503 | + $nextBlockNo = 1; |
|
504 | + while ($varRefNo < $this->varRefTabCnt) { |
|
505 | + $vrtr = & $this->varRefTab[$varRefNo]; |
|
506 | + $varRefTPos = $vrtr['tPosBegin']; |
|
507 | + $varNo = $vrtr['varNo']; |
|
508 | + if ($varRefTPos >= $this->blockTab[$activeBlockNo]['tPosEnd']) { |
|
509 | + $activeBlockNo = $this->blockTab[$activeBlockNo]['parentBlockNo']; |
|
510 | + continue; } |
|
511 | + if ($nextBlockNo < $this->blockTabCnt) { |
|
512 | + if ($varRefTPos >= $this->blockTab[$nextBlockNo]['tPosBegin']) { |
|
513 | 513 | $activeBlockNo = $nextBlockNo; |
514 | 514 | $nextBlockNo += 1; |
515 | 515 | continue; }} |
516 | - $btr = & $this->blockTab[$activeBlockNo]; |
|
517 | - if ($varRefTPos < $btr['tPosBegin']) |
|
518 | - $this->programLogicError(1); |
|
519 | - $blockVarNo = $btr['blockVarCnt']++; |
|
520 | - $btr['blockVarNoToVarNoMap'][$blockVarNo] = $varNo; |
|
521 | - if ($btr['firstVarRefNo'] == -1) |
|
522 | - $btr['firstVarRefNo'] = $varRefNo; |
|
523 | - $vrtr['blockNo'] = $activeBlockNo; |
|
524 | - $vrtr['blockVarNo'] = $blockVarNo; |
|
525 | - $varRefNo += 1; }} |
|
516 | + $btr = & $this->blockTab[$activeBlockNo]; |
|
517 | + if ($varRefTPos < $btr['tPosBegin']) |
|
518 | + $this->programLogicError(1); |
|
519 | + $blockVarNo = $btr['blockVarCnt']++; |
|
520 | + $btr['blockVarNoToVarNoMap'][$blockVarNo] = $varNo; |
|
521 | + if ($btr['firstVarRefNo'] == -1) |
|
522 | + $btr['firstVarRefNo'] = $varRefNo; |
|
523 | + $vrtr['blockNo'] = $activeBlockNo; |
|
524 | + $vrtr['blockVarNo'] = $blockVarNo; |
|
525 | + $varRefNo += 1; }} |
|
526 | 526 | |
527 | 527 | //--- build up (template variables and blocks) ---------------------------------------------------------------------- |
528 | 528 | |
@@ -535,15 +535,15 @@ discard block |
||
535 | 535 | * @access public |
536 | 536 | */ |
537 | 537 | function reset() { |
538 | - for ($varNo = 0; $varNo < $this->varTabCnt; $varNo++) |
|
539 | - $this->varTab[$varNo]['varValue'] = ''; |
|
540 | - for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) { |
|
541 | - $btr = & $this->blockTab[$blockNo]; |
|
542 | - $btr['instances'] = 0; |
|
543 | - $btr['firstBlockInstNo'] = -1; |
|
544 | - $btr['lastBlockInstNo'] = -1; } |
|
545 | - $this->blockInstTab = array(); |
|
546 | - $this->blockInstTabCnt = 0; } |
|
538 | + for ($varNo = 0; $varNo < $this->varTabCnt; $varNo++) |
|
539 | + $this->varTab[$varNo]['varValue'] = ''; |
|
540 | + for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) { |
|
541 | + $btr = & $this->blockTab[$blockNo]; |
|
542 | + $btr['instances'] = 0; |
|
543 | + $btr['firstBlockInstNo'] = -1; |
|
544 | + $btr['lastBlockInstNo'] = -1; } |
|
545 | + $this->blockInstTab = array(); |
|
546 | + $this->blockInstTabCnt = 0; } |
|
547 | 547 | |
548 | 548 | /** |
549 | 549 | * Sets a template variable. |
@@ -561,13 +561,13 @@ discard block |
||
561 | 561 | * @access public |
562 | 562 | */ |
563 | 563 | function setVariable($variableName, $variableValue, $isOptional = false) { |
564 | - if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; } |
|
565 | - if (!$this->lookupVariableName($variableName, $varNo)) { |
|
566 | - if ($isOptional) return true; |
|
567 | - $this->triggerError("Variable \"$variableName\" not defined in template."); |
|
568 | - return false; } |
|
569 | - $this->varTab[$varNo]['varValue'] = $variableValue; |
|
570 | - return true; } |
|
564 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; } |
|
565 | + if (!$this->lookupVariableName($variableName, $varNo)) { |
|
566 | + if ($isOptional) return true; |
|
567 | + $this->triggerError("Variable \"$variableName\" not defined in template."); |
|
568 | + return false; } |
|
569 | + $this->varTab[$varNo]['varValue'] = $variableValue; |
|
570 | + return true; } |
|
571 | 571 | |
572 | 572 | /** |
573 | 573 | * Sets a template variable to an escaped string. |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | * @access public |
589 | 589 | */ |
590 | 590 | function setVariableEsc($variableName, $variableValue, $isOptional = false) { |
591 | - return $this->setVariable($variableName, htmlspecialchars($variableValue, ENT_QUOTES), $isOptional); } |
|
591 | + return $this->setVariable($variableName, htmlspecialchars($variableValue, ENT_QUOTES), $isOptional); } |
|
592 | 592 | |
593 | 593 | /** |
594 | 594 | * Checks whether a variable with the specified name exists within the template. |
@@ -598,8 +598,8 @@ discard block |
||
598 | 598 | * @access public |
599 | 599 | */ |
600 | 600 | function variableExists($variableName) { |
601 | - if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; } |
|
602 | - return $this->lookupVariableName($variableName, $varNo); } |
|
601 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; } |
|
602 | + return $this->lookupVariableName($variableName, $varNo); } |
|
603 | 603 | |
604 | 604 | /** |
605 | 605 | * Adds an instance of a template block. |
@@ -615,48 +615,48 @@ discard block |
||
615 | 615 | * @access public |
616 | 616 | */ |
617 | 617 | function addBlock($blockName) { |
618 | - if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; } |
|
619 | - if (!$this->lookupBlockName($blockName, $blockNo)) { |
|
620 | - $this->triggerError("Block \"$blockName\" not defined in template."); |
|
621 | - return false; } |
|
622 | - while ($blockNo != -1) { |
|
623 | - $this->addBlockByNo($blockNo); |
|
624 | - $blockNo = $this->blockTab[$blockNo]['nextWithSameName']; } |
|
625 | - return true; } |
|
618 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; } |
|
619 | + if (!$this->lookupBlockName($blockName, $blockNo)) { |
|
620 | + $this->triggerError("Block \"$blockName\" not defined in template."); |
|
621 | + return false; } |
|
622 | + while ($blockNo != -1) { |
|
623 | + $this->addBlockByNo($blockNo); |
|
624 | + $blockNo = $this->blockTab[$blockNo]['nextWithSameName']; } |
|
625 | + return true; } |
|
626 | 626 | |
627 | 627 | /** |
628 | 628 | * @access private |
629 | 629 | */ |
630 | 630 | function addBlockByNo($blockNo) { |
631 | - $btr = & $this->blockTab[$blockNo]; |
|
632 | - $this->registerBlockInstance($blockInstNo); |
|
633 | - $bitr = & $this->blockInstTab[$blockInstNo]; |
|
634 | - if ($btr['firstBlockInstNo'] == -1) |
|
635 | - $btr['firstBlockInstNo'] = $blockInstNo; |
|
636 | - if ($btr['lastBlockInstNo'] != -1) |
|
637 | - $this->blockInstTab[$btr['lastBlockInstNo']]['nextBlockInstNo'] = $blockInstNo; |
|
638 | - // set forward pointer of chain |
|
639 | - $btr['lastBlockInstNo'] = $blockInstNo; |
|
640 | - $parentBlockNo = $btr['parentBlockNo']; |
|
641 | - $blockVarCnt = $btr['blockVarCnt']; |
|
642 | - $bitr['blockNo'] = $blockNo; |
|
643 | - $bitr['instanceLevel'] = $btr['instances']++; |
|
644 | - if ($parentBlockNo == -1) |
|
645 | - $bitr['parentInstLevel'] = -1; |
|
631 | + $btr = & $this->blockTab[$blockNo]; |
|
632 | + $this->registerBlockInstance($blockInstNo); |
|
633 | + $bitr = & $this->blockInstTab[$blockInstNo]; |
|
634 | + if ($btr['firstBlockInstNo'] == -1) |
|
635 | + $btr['firstBlockInstNo'] = $blockInstNo; |
|
636 | + if ($btr['lastBlockInstNo'] != -1) |
|
637 | + $this->blockInstTab[$btr['lastBlockInstNo']]['nextBlockInstNo'] = $blockInstNo; |
|
638 | + // set forward pointer of chain |
|
639 | + $btr['lastBlockInstNo'] = $blockInstNo; |
|
640 | + $parentBlockNo = $btr['parentBlockNo']; |
|
641 | + $blockVarCnt = $btr['blockVarCnt']; |
|
642 | + $bitr['blockNo'] = $blockNo; |
|
643 | + $bitr['instanceLevel'] = $btr['instances']++; |
|
644 | + if ($parentBlockNo == -1) |
|
645 | + $bitr['parentInstLevel'] = -1; |
|
646 | 646 | else |
647 | - $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances']; |
|
648 | - $bitr['nextBlockInstNo'] = -1; |
|
649 | - $bitr['blockVarTab'] = array(); |
|
650 | - // copy instance variables for this block |
|
651 | - for ($blockVarNo = 0; $blockVarNo < $blockVarCnt; $blockVarNo++) { |
|
652 | - $varNo = $btr['blockVarNoToVarNoMap'][$blockVarNo]; |
|
653 | - $bitr['blockVarTab'][$blockVarNo] = $this->varTab[$varNo]['varValue']; }} |
|
647 | + $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances']; |
|
648 | + $bitr['nextBlockInstNo'] = -1; |
|
649 | + $bitr['blockVarTab'] = array(); |
|
650 | + // copy instance variables for this block |
|
651 | + for ($blockVarNo = 0; $blockVarNo < $blockVarCnt; $blockVarNo++) { |
|
652 | + $varNo = $btr['blockVarNoToVarNoMap'][$blockVarNo]; |
|
653 | + $bitr['blockVarTab'][$blockVarNo] = $this->varTab[$varNo]['varValue']; }} |
|
654 | 654 | |
655 | 655 | /** |
656 | 656 | * @access private |
657 | 657 | */ |
658 | 658 | function registerBlockInstance(&$blockInstNo) { |
659 | - $blockInstNo = $this->blockInstTabCnt++; } |
|
659 | + $blockInstNo = $this->blockInstTabCnt++; } |
|
660 | 660 | |
661 | 661 | /** |
662 | 662 | * Checks whether a block with the specified name exists within the template. |
@@ -666,8 +666,8 @@ discard block |
||
666 | 666 | * @access public |
667 | 667 | */ |
668 | 668 | function blockExists($blockName) { |
669 | - if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; } |
|
670 | - return $this->lookupBlockName($blockName, $blockNo); } |
|
669 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; } |
|
670 | + return $this->lookupBlockName($blockName, $blockNo); } |
|
671 | 671 | |
672 | 672 | //--- output generation --------------------------------------------------------------------------------------------- |
673 | 673 | |
@@ -677,11 +677,11 @@ discard block |
||
677 | 677 | * @access public |
678 | 678 | */ |
679 | 679 | function generateOutput() { |
680 | - $this->outputMode = 0; |
|
681 | - if (!$this->generateOutputPage()) { |
|
682 | - return false; |
|
683 | - } |
|
684 | - return true; } |
|
680 | + $this->outputMode = 0; |
|
681 | + if (!$this->generateOutputPage()) { |
|
682 | + return false; |
|
683 | + } |
|
684 | + return true; } |
|
685 | 685 | |
686 | 686 | /** |
687 | 687 | * Generates the HTML page and writes it to a file. |
@@ -690,13 +690,13 @@ discard block |
||
690 | 690 | * @access public |
691 | 691 | */ |
692 | 692 | function generateOutputToFile($fileName) { |
693 | - $fh = fopen($fileName, "wb"); |
|
694 | - if ($fh === false) return false; |
|
695 | - $this->outputMode = 1; |
|
696 | - $this->outputFileHandle = $fh; |
|
697 | - $ok = $this->generateOutputPage(); |
|
698 | - fclose($fh); |
|
699 | - return $ok; } |
|
693 | + $fh = fopen($fileName, "wb"); |
|
694 | + if ($fh === false) return false; |
|
695 | + $this->outputMode = 1; |
|
696 | + $this->outputFileHandle = $fh; |
|
697 | + $ok = $this->generateOutputPage(); |
|
698 | + fclose($fh); |
|
699 | + return $ok; } |
|
700 | 700 | |
701 | 701 | /** |
702 | 702 | * Generates the HTML page and writes it to a string. |
@@ -706,30 +706,30 @@ discard block |
||
706 | 706 | * @access public |
707 | 707 | */ |
708 | 708 | function generateOutputToString(&$outputString) { |
709 | - $outputString = "Error"; |
|
710 | - $this->outputMode = 2; |
|
711 | - $this->outputString = ""; |
|
712 | - if (!$this->generateOutputPage()) { |
|
713 | - return false; |
|
714 | - } |
|
715 | - $outputString = $this->outputString; |
|
716 | - return true; } |
|
709 | + $outputString = "Error"; |
|
710 | + $this->outputMode = 2; |
|
711 | + $this->outputString = ""; |
|
712 | + if (!$this->generateOutputPage()) { |
|
713 | + return false; |
|
714 | + } |
|
715 | + $outputString = $this->outputString; |
|
716 | + return true; } |
|
717 | 717 | |
718 | 718 | /** |
719 | 719 | * @access private |
720 | 720 | * @return boolean true on success, false on error. |
721 | 721 | */ |
722 | 722 | function generateOutputPage() { |
723 | - if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; } |
|
724 | - if ($this->blockTab[0]['instances'] == 0) |
|
725 | - $this->addBlockByNo(0); // add main block |
|
726 | - for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) { |
|
727 | - $btr = & $this->blockTab[$blockNo]; |
|
728 | - $btr['currBlockInstNo'] = $btr['firstBlockInstNo']; } |
|
729 | - $this->outputError = false; |
|
730 | - $this->writeBlockInstances(0, -1); |
|
731 | - if ($this->outputError) return false; |
|
732 | - return true; } |
|
723 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; } |
|
724 | + if ($this->blockTab[0]['instances'] == 0) |
|
725 | + $this->addBlockByNo(0); // add main block |
|
726 | + for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) { |
|
727 | + $btr = & $this->blockTab[$blockNo]; |
|
728 | + $btr['currBlockInstNo'] = $btr['firstBlockInstNo']; } |
|
729 | + $this->outputError = false; |
|
730 | + $this->writeBlockInstances(0, -1); |
|
731 | + if ($this->outputError) return false; |
|
732 | + return true; } |
|
733 | 733 | |
734 | 734 | /** |
735 | 735 | * Writes all instances of a block that are contained within a specific |
@@ -738,64 +738,64 @@ discard block |
||
738 | 738 | * @access private |
739 | 739 | */ |
740 | 740 | function writeBlockInstances($blockNo, $parentInstLevel) { |
741 | - $btr = & $this->blockTab[$blockNo]; |
|
742 | - while (!$this->outputError) { |
|
743 | - $blockInstNo = $btr['currBlockInstNo']; |
|
744 | - if ($blockInstNo == -1) break; |
|
745 | - $bitr = & $this->blockInstTab[$blockInstNo]; |
|
746 | - if ($bitr['parentInstLevel'] < $parentInstLevel) |
|
747 | - $this->programLogicError(2); |
|
748 | - if ($bitr['parentInstLevel'] > $parentInstLevel) break; |
|
749 | - $this->writeBlockInstance($blockInstNo); |
|
750 | - $btr['currBlockInstNo'] = $bitr['nextBlockInstNo']; }} |
|
741 | + $btr = & $this->blockTab[$blockNo]; |
|
742 | + while (!$this->outputError) { |
|
743 | + $blockInstNo = $btr['currBlockInstNo']; |
|
744 | + if ($blockInstNo == -1) break; |
|
745 | + $bitr = & $this->blockInstTab[$blockInstNo]; |
|
746 | + if ($bitr['parentInstLevel'] < $parentInstLevel) |
|
747 | + $this->programLogicError(2); |
|
748 | + if ($bitr['parentInstLevel'] > $parentInstLevel) break; |
|
749 | + $this->writeBlockInstance($blockInstNo); |
|
750 | + $btr['currBlockInstNo'] = $bitr['nextBlockInstNo']; }} |
|
751 | 751 | |
752 | 752 | /** |
753 | 753 | * @access private |
754 | 754 | */ |
755 | 755 | function writeBlockInstance($blockInstNo) { |
756 | - $bitr = & $this->blockInstTab[$blockInstNo]; |
|
757 | - $blockNo = $bitr['blockNo']; |
|
758 | - $btr = & $this->blockTab[$blockNo]; |
|
759 | - $tPos = $btr['tPosContentsBegin']; |
|
760 | - $subBlockNo = $blockNo + 1; |
|
761 | - $varRefNo = $btr['firstVarRefNo']; |
|
762 | - while (!$this->outputError) { |
|
763 | - $tPos2 = $btr['tPosContentsEnd']; |
|
764 | - $kind = 0; // assume end-of-block |
|
765 | - if ($varRefNo != -1 && $varRefNo < $this->varRefTabCnt) { // check for variable reference |
|
766 | - $vrtr = & $this->varRefTab[$varRefNo]; |
|
767 | - if ($vrtr['tPosBegin'] < $tPos) { |
|
756 | + $bitr = & $this->blockInstTab[$blockInstNo]; |
|
757 | + $blockNo = $bitr['blockNo']; |
|
758 | + $btr = & $this->blockTab[$blockNo]; |
|
759 | + $tPos = $btr['tPosContentsBegin']; |
|
760 | + $subBlockNo = $blockNo + 1; |
|
761 | + $varRefNo = $btr['firstVarRefNo']; |
|
762 | + while (!$this->outputError) { |
|
763 | + $tPos2 = $btr['tPosContentsEnd']; |
|
764 | + $kind = 0; // assume end-of-block |
|
765 | + if ($varRefNo != -1 && $varRefNo < $this->varRefTabCnt) { // check for variable reference |
|
766 | + $vrtr = & $this->varRefTab[$varRefNo]; |
|
767 | + if ($vrtr['tPosBegin'] < $tPos) { |
|
768 | 768 | $varRefNo += 1; |
769 | 769 | continue; } |
770 | - if ($vrtr['tPosBegin'] < $tPos2) { |
|
770 | + if ($vrtr['tPosBegin'] < $tPos2) { |
|
771 | 771 | $tPos2 = $vrtr['tPosBegin']; |
772 | 772 | $kind = 1; }} |
773 | - if ($subBlockNo < $this->blockTabCnt) { // check for subblock |
|
774 | - $subBtr = & $this->blockTab[$subBlockNo]; |
|
775 | - if ($subBtr['tPosBegin'] < $tPos) { |
|
773 | + if ($subBlockNo < $this->blockTabCnt) { // check for subblock |
|
774 | + $subBtr = & $this->blockTab[$subBlockNo]; |
|
775 | + if ($subBtr['tPosBegin'] < $tPos) { |
|
776 | 776 | $subBlockNo += 1; |
777 | 777 | continue; } |
778 | - if ($subBtr['tPosBegin'] < $tPos2) { |
|
778 | + if ($subBtr['tPosBegin'] < $tPos2) { |
|
779 | 779 | $tPos2 = $subBtr['tPosBegin']; |
780 | 780 | $kind = 2; }} |
781 | - if ($tPos2 > $tPos) |
|
782 | - $this->writeString(substr($this->template, $tPos, $tPos2 - $tPos)); |
|
783 | - switch ($kind) { |
|
784 | - case 0: // end of block |
|
781 | + if ($tPos2 > $tPos) |
|
782 | + $this->writeString(substr($this->template, $tPos, $tPos2 - $tPos)); |
|
783 | + switch ($kind) { |
|
784 | + case 0: // end of block |
|
785 | 785 | return; |
786 | - case 1: // variable |
|
786 | + case 1: // variable |
|
787 | 787 | $vrtr = & $this->varRefTab[$varRefNo]; |
788 | 788 | if ($vrtr['blockNo'] != $blockNo) |
789 | - $this->programLogicError(4); |
|
789 | + $this->programLogicError(4); |
|
790 | 790 | $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']]; |
791 | 791 | $this->writeString($variableValue); |
792 | 792 | $tPos = $vrtr['tPosEnd']; |
793 | 793 | $varRefNo += 1; |
794 | 794 | break; |
795 | - case 2: // sub block |
|
795 | + case 2: // sub block |
|
796 | 796 | $subBtr = & $this->blockTab[$subBlockNo]; |
797 | 797 | if ($subBtr['parentBlockNo'] != $blockNo) |
798 | - $this->programLogicError(3); |
|
798 | + $this->programLogicError(3); |
|
799 | 799 | $this->writeBlockInstances($subBlockNo, $bitr['instanceLevel']); // recursive call |
800 | 800 | $tPos = $subBtr['tPosEnd']; |
801 | 801 | $subBlockNo += 1; |
@@ -805,19 +805,19 @@ discard block |
||
805 | 805 | * @access private |
806 | 806 | */ |
807 | 807 | function writeString($s) { |
808 | - if ($this->outputError) return; |
|
809 | - switch ($this->outputMode) { |
|
810 | - case 0: // output to PHP output stream |
|
808 | + if ($this->outputError) return; |
|
809 | + switch ($this->outputMode) { |
|
810 | + case 0: // output to PHP output stream |
|
811 | 811 | if (!print($s)) |
812 | 812 | $this->outputError = true; |
813 | - break; |
|
814 | - case 1: // output to file |
|
813 | + break; |
|
814 | + case 1: // output to file |
|
815 | 815 | $rc = fwrite($this->outputFileHandle, $s); |
816 | - if ($rc === false) $this->outputError = true; |
|
817 | - break; |
|
818 | - case 2: // output to string |
|
816 | + if ($rc === false) $this->outputError = true; |
|
817 | + break; |
|
818 | + case 2: // output to string |
|
819 | 819 | $this->outputString .= $s; |
820 | - break; }} |
|
820 | + break; }} |
|
821 | 821 | |
822 | 822 | //--- name lookup routines ------------------------------------------------------------------------------------------ |
823 | 823 | |
@@ -827,10 +827,10 @@ discard block |
||
827 | 827 | * @access private |
828 | 828 | */ |
829 | 829 | function lookupVariableName($varName, &$varNo) { |
830 | - $x = & $this->varNameToNoMap[strtoupper($varName)]; |
|
831 | - if (!isset($x)) return false; |
|
832 | - $varNo = $x; |
|
833 | - return true; } |
|
830 | + $x = & $this->varNameToNoMap[strtoupper($varName)]; |
|
831 | + if (!isset($x)) return false; |
|
832 | + $varNo = $x; |
|
833 | + return true; } |
|
834 | 834 | |
835 | 835 | /** |
836 | 836 | * Maps block name to block number. |
@@ -840,10 +840,10 @@ discard block |
||
840 | 840 | * @access private |
841 | 841 | */ |
842 | 842 | function lookupBlockName($blockName, &$blockNo) { |
843 | - $x = & $this->blockNameToNoMap[strtoupper($blockName)]; |
|
844 | - if (!isset($x)) return false; |
|
845 | - $blockNo = $x; |
|
846 | - return true; } |
|
843 | + $x = & $this->blockNameToNoMap[strtoupper($blockName)]; |
|
844 | + if (!isset($x)) return false; |
|
845 | + $blockNo = $x; |
|
846 | + return true; } |
|
847 | 847 | |
848 | 848 | //--- general utility routines ----------------------------------------------------------------------------------------- |
849 | 849 | |
@@ -853,92 +853,92 @@ discard block |
||
853 | 853 | * @access private |
854 | 854 | */ |
855 | 855 | function readFileIntoString($fileName, &$s) { |
856 | - if (function_exists('version_compare') && version_compare(phpversion(), "4.3.0", ">=")) { |
|
857 | - $s = file_get_contents($fileName); |
|
858 | - if ($s === false) return false; |
|
859 | - return true; } |
|
860 | - $fh = fopen($fileName, "rb"); |
|
861 | - if ($fh === false) return false; |
|
862 | - $fileSize = filesize($fileName); |
|
863 | - if ($fileSize === false) {fclose($fh); return false; } |
|
864 | - $s = fread($fh, $fileSize); |
|
865 | - fclose($fh); |
|
866 | - if (strlen($s) != $fileSize) return false; |
|
867 | - return true; } |
|
856 | + if (function_exists('version_compare') && version_compare(phpversion(), "4.3.0", ">=")) { |
|
857 | + $s = file_get_contents($fileName); |
|
858 | + if ($s === false) return false; |
|
859 | + return true; } |
|
860 | + $fh = fopen($fileName, "rb"); |
|
861 | + if ($fh === false) return false; |
|
862 | + $fileSize = filesize($fileName); |
|
863 | + if ($fileSize === false) {fclose($fh); return false; } |
|
864 | + $s = fread($fh, $fileSize); |
|
865 | + fclose($fh); |
|
866 | + if (strlen($s) != $fileSize) return false; |
|
867 | + return true; } |
|
868 | 868 | |
869 | 869 | /** |
870 | 870 | * @access private |
871 | 871 | * @return boolean true on success, false when the end of the string is reached. |
872 | 872 | */ |
873 | 873 | function parseWord($s, &$p, &$w) { |
874 | - $sLen = strlen($s); |
|
875 | - while ($p < $sLen && ord($s{$p}) <= 32) { |
|
876 | - $p++; |
|
877 | - } |
|
878 | - if ($p >= $sLen) { |
|
879 | - return false; |
|
880 | - } |
|
881 | - $p0 = $p; |
|
882 | - while ($p < $sLen && ord($s{$p}) > 32) { |
|
883 | - $p++; |
|
884 | - } |
|
885 | - $w = substr($s, $p0, $p - $p0); |
|
886 | - return true; } |
|
874 | + $sLen = strlen($s); |
|
875 | + while ($p < $sLen && ord($s{$p}) <= 32) { |
|
876 | + $p++; |
|
877 | + } |
|
878 | + if ($p >= $sLen) { |
|
879 | + return false; |
|
880 | + } |
|
881 | + $p0 = $p; |
|
882 | + while ($p < $sLen && ord($s{$p}) > 32) { |
|
883 | + $p++; |
|
884 | + } |
|
885 | + $w = substr($s, $p0, $p - $p0); |
|
886 | + return true; } |
|
887 | 887 | |
888 | 888 | /** |
889 | 889 | * @access private |
890 | 890 | * @return boolean true on success, false on error. |
891 | 891 | */ |
892 | 892 | function parseQuotedString($s, &$p, &$w) { |
893 | - $sLen = strlen($s); |
|
894 | - while ($p < $sLen && ord($s{$p}) <= 32) $p++; |
|
895 | - if ($p >= $sLen) return false; |
|
896 | - if (substr($s, $p, 1) != '"') return false; |
|
897 | - $p++; $p0 = $p; |
|
898 | - while ($p < $sLen && $s{$p} != '"') $p++; |
|
899 | - if ($p >= $sLen) return false; |
|
900 | - $w = substr($s, $p0, $p - $p0); |
|
901 | - $p++; |
|
902 | - return true; } |
|
893 | + $sLen = strlen($s); |
|
894 | + while ($p < $sLen && ord($s{$p}) <= 32) $p++; |
|
895 | + if ($p >= $sLen) return false; |
|
896 | + if (substr($s, $p, 1) != '"') return false; |
|
897 | + $p++; $p0 = $p; |
|
898 | + while ($p < $sLen && $s{$p} != '"') $p++; |
|
899 | + if ($p >= $sLen) return false; |
|
900 | + $w = substr($s, $p0, $p - $p0); |
|
901 | + $p++; |
|
902 | + return true; } |
|
903 | 903 | |
904 | 904 | /** |
905 | 905 | * @access private |
906 | 906 | * @return boolean true on success, false on error. |
907 | 907 | */ |
908 | 908 | function parseWordOrQuotedString($s, &$p, &$w) { |
909 | - $sLen = strlen($s); |
|
910 | - while ($p < $sLen && ord($s{$p}) <= 32) $p++; |
|
911 | - if ($p >= $sLen) return false; |
|
912 | - if (substr($s, $p, 1) == '"') |
|
913 | - return $this->parseQuotedString($s, $p, $w); |
|
909 | + $sLen = strlen($s); |
|
910 | + while ($p < $sLen && ord($s{$p}) <= 32) $p++; |
|
911 | + if ($p >= $sLen) return false; |
|
912 | + if (substr($s, $p, 1) == '"') |
|
913 | + return $this->parseQuotedString($s, $p, $w); |
|
914 | 914 | else |
915 | - return $this->parseWord($s, $p, $w); } |
|
915 | + return $this->parseWord($s, $p, $w); } |
|
916 | 916 | |
917 | 917 | /** |
918 | 918 | * Combine two file system paths. |
919 | 919 | * @access private |
920 | 920 | */ |
921 | 921 | function combineFileSystemPath($path1, $path2) { |
922 | - if ($path1 == '' || $path2 == '') return $path2; |
|
923 | - $s = $path1; |
|
924 | - if (substr($s, -1) != '\\' && substr($s, -1) != '/') $s = $s."/"; |
|
925 | - if (substr($path2, 0, 1) == '\\' || substr($path2, 0, 1) == '/') |
|
926 | - $s = $s.substr($path2, 1); |
|
922 | + if ($path1 == '' || $path2 == '') return $path2; |
|
923 | + $s = $path1; |
|
924 | + if (substr($s, -1) != '\\' && substr($s, -1) != '/') $s = $s."/"; |
|
925 | + if (substr($path2, 0, 1) == '\\' || substr($path2, 0, 1) == '/') |
|
926 | + $s = $s.substr($path2, 1); |
|
927 | 927 | else |
928 | - $s = $s.$path2; |
|
929 | - return $s; } |
|
928 | + $s = $s.$path2; |
|
929 | + return $s; } |
|
930 | 930 | |
931 | 931 | /** |
932 | 932 | * @access private |
933 | 933 | */ |
934 | 934 | function triggerError($msg) { |
935 | - trigger_error("MiniTemplator error: $msg", E_USER_ERROR); } |
|
935 | + trigger_error("MiniTemplator error: $msg", E_USER_ERROR); } |
|
936 | 936 | |
937 | 937 | /** |
938 | 938 | * @access private |
939 | 939 | */ |
940 | 940 | function programLogicError($errorId) { |
941 | - die ("MiniTemplator: Program logic error $errorId.\n"); } |
|
941 | + die ("MiniTemplator: Program logic error $errorId.\n"); } |
|
942 | 942 | |
943 | 943 | } |
944 | 944 | ?> |
@@ -305,23 +305,23 @@ discard block |
||
305 | 305 | if (!$this->parseWord($cmdL, $p, $cmd)) return true; |
306 | 306 | $parms = substr($cmdL, $p); |
307 | 307 | switch (strtoupper($cmd)) { |
308 | - case '$BEGINBLOCK': |
|
309 | - if (!$this->processBeginBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
|
310 | - return false; |
|
311 | - break; |
|
312 | - case '$ENDBLOCK': |
|
313 | - if (!$this->processEndBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
|
314 | - return false; |
|
315 | - break; |
|
316 | - case '$INCLUDE': |
|
317 | - if (!$this->processincludeCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
|
318 | - return false; |
|
319 | - $resumeFromStart = true; |
|
320 | - break; |
|
321 | - default: |
|
322 | - if ($cmd{0} == '$' && !(strlen($cmd) >= 2 && $cmd{1} == '{')) { |
|
323 | - $this->triggerError("Unknown command \"$cmd\" in template at offset $cmdTPosBegin."); |
|
324 | - return false; }} |
|
308 | + case '$BEGINBLOCK': |
|
309 | + if (!$this->processBeginBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
|
310 | + return false; |
|
311 | + break; |
|
312 | + case '$ENDBLOCK': |
|
313 | + if (!$this->processEndBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
|
314 | + return false; |
|
315 | + break; |
|
316 | + case '$INCLUDE': |
|
317 | + if (!$this->processincludeCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
|
318 | + return false; |
|
319 | + $resumeFromStart = true; |
|
320 | + break; |
|
321 | + default: |
|
322 | + if ($cmd{0} == '$' && !(strlen($cmd) >= 2 && $cmd{1} == '{')) { |
|
323 | + $this->triggerError("Unknown command \"$cmd\" in template at offset $cmdTPosBegin."); |
|
324 | + return false; }} |
|
325 | 325 | return true; } |
326 | 326 | |
327 | 327 | /** |
@@ -781,25 +781,25 @@ discard block |
||
781 | 781 | if ($tPos2 > $tPos) |
782 | 782 | $this->writeString(substr($this->template, $tPos, $tPos2 - $tPos)); |
783 | 783 | switch ($kind) { |
784 | - case 0: // end of block |
|
785 | - return; |
|
786 | - case 1: // variable |
|
787 | - $vrtr = & $this->varRefTab[$varRefNo]; |
|
788 | - if ($vrtr['blockNo'] != $blockNo) |
|
789 | - $this->programLogicError(4); |
|
790 | - $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']]; |
|
791 | - $this->writeString($variableValue); |
|
792 | - $tPos = $vrtr['tPosEnd']; |
|
793 | - $varRefNo += 1; |
|
794 | - break; |
|
795 | - case 2: // sub block |
|
796 | - $subBtr = & $this->blockTab[$subBlockNo]; |
|
797 | - if ($subBtr['parentBlockNo'] != $blockNo) |
|
798 | - $this->programLogicError(3); |
|
799 | - $this->writeBlockInstances($subBlockNo, $bitr['instanceLevel']); // recursive call |
|
800 | - $tPos = $subBtr['tPosEnd']; |
|
801 | - $subBlockNo += 1; |
|
802 | - break; }}} |
|
784 | + case 0: // end of block |
|
785 | + return; |
|
786 | + case 1: // variable |
|
787 | + $vrtr = & $this->varRefTab[$varRefNo]; |
|
788 | + if ($vrtr['blockNo'] != $blockNo) |
|
789 | + $this->programLogicError(4); |
|
790 | + $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']]; |
|
791 | + $this->writeString($variableValue); |
|
792 | + $tPos = $vrtr['tPosEnd']; |
|
793 | + $varRefNo += 1; |
|
794 | + break; |
|
795 | + case 2: // sub block |
|
796 | + $subBtr = & $this->blockTab[$subBlockNo]; |
|
797 | + if ($subBtr['parentBlockNo'] != $blockNo) |
|
798 | + $this->programLogicError(3); |
|
799 | + $this->writeBlockInstances($subBlockNo, $bitr['instanceLevel']); // recursive call |
|
800 | + $tPos = $subBtr['tPosEnd']; |
|
801 | + $subBlockNo += 1; |
|
802 | + break; }}} |
|
803 | 803 | |
804 | 804 | /** |
805 | 805 | * @access private |
@@ -807,17 +807,17 @@ discard block |
||
807 | 807 | function writeString($s) { |
808 | 808 | if ($this->outputError) return; |
809 | 809 | switch ($this->outputMode) { |
810 | - case 0: // output to PHP output stream |
|
811 | - if (!print($s)) |
|
812 | - $this->outputError = true; |
|
813 | - break; |
|
814 | - case 1: // output to file |
|
815 | - $rc = fwrite($this->outputFileHandle, $s); |
|
816 | - if ($rc === false) $this->outputError = true; |
|
817 | - break; |
|
818 | - case 2: // output to string |
|
819 | - $this->outputString .= $s; |
|
820 | - break; }} |
|
810 | + case 0: // output to PHP output stream |
|
811 | + if (!print($s)) |
|
812 | + $this->outputError = true; |
|
813 | + break; |
|
814 | + case 1: // output to file |
|
815 | + $rc = fwrite($this->outputFileHandle, $s); |
|
816 | + if ($rc === false) $this->outputError = true; |
|
817 | + break; |
|
818 | + case 2: // output to string |
|
819 | + $this->outputString .= $s; |
|
820 | + break; }} |
|
821 | 821 | |
822 | 822 | //--- name lookup routines ------------------------------------------------------------------------------------------ |
823 | 823 |
@@ -282,16 +282,22 @@ discard block |
||
282 | 282 | $p = 0; |
283 | 283 | while (true) { |
284 | 284 | $p0 = strpos($this->template, '<!--', $p); |
285 | - if ($p0 === false) break; |
|
285 | + if ($p0 === false) { |
|
286 | + break; |
|
287 | + } |
|
286 | 288 | $p = strpos($this->template, '-->', $p0); |
287 | 289 | if ($p === false) { |
288 | 290 | $this->triggerError("Invalid HTML comment in template at offset $p0."); |
289 | 291 | return false; } |
290 | 292 | $p += 3; |
291 | 293 | $cmdL = substr($this->template, $p0 + 4, $p - $p0 - 7); |
292 | - if (!$this->processTemplateCommand($cmdL, $p0, $p, $resumeFromStart)) |
|
293 | - return false; |
|
294 | - if ($resumeFromStart) $p = $p0; } |
|
294 | + if (!$this->processTemplateCommand($cmdL, $p0, $p, $resumeFromStart)) { |
|
295 | + return false; |
|
296 | + } |
|
297 | + if ($resumeFromStart) { |
|
298 | + $p = $p0; |
|
299 | + } |
|
300 | + } |
|
295 | 301 | return true; } |
296 | 302 | |
297 | 303 | /** |
@@ -302,20 +308,25 @@ discard block |
||
302 | 308 | $resumeFromStart = false; |
303 | 309 | $p = 0; |
304 | 310 | $cmd = ''; |
305 | - if (!$this->parseWord($cmdL, $p, $cmd)) return true; |
|
311 | + if (!$this->parseWord($cmdL, $p, $cmd)) { |
|
312 | + return true; |
|
313 | + } |
|
306 | 314 | $parms = substr($cmdL, $p); |
307 | 315 | switch (strtoupper($cmd)) { |
308 | 316 | case '$BEGINBLOCK': |
309 | - if (!$this->processBeginBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
|
310 | - return false; |
|
317 | + if (!$this->processBeginBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) { |
|
318 | + return false; |
|
319 | + } |
|
311 | 320 | break; |
312 | 321 | case '$ENDBLOCK': |
313 | - if (!$this->processEndBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
|
314 | - return false; |
|
322 | + if (!$this->processEndBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) { |
|
323 | + return false; |
|
324 | + } |
|
315 | 325 | break; |
316 | 326 | case '$INCLUDE': |
317 | - if (!$this->processincludeCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
|
318 | - return false; |
|
327 | + if (!$this->processincludeCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) { |
|
328 | + return false; |
|
329 | + } |
|
319 | 330 | $resumeFromStart = true; |
320 | 331 | break; |
321 | 332 | default: |
@@ -387,8 +398,9 @@ discard block |
||
387 | 398 | $btr = & $this->blockTab[$blockNo]; |
388 | 399 | $btr = array(); |
389 | 400 | $btr['blockName'] = $blockName; |
390 | - if (!$this->lookupBlockName($blockName, $btr['nextWithSameName'])) |
|
391 | - $btr['nextWithSameName'] = -1; |
|
401 | + if (!$this->lookupBlockName($blockName, $btr['nextWithSameName'])) { |
|
402 | + $btr['nextWithSameName'] = -1; |
|
403 | + } |
|
392 | 404 | $btr['definitionIsOpen'] = true; |
393 | 405 | $btr['instances'] = 0; |
394 | 406 | $btr['firstBlockInstNo'] = -1; |
@@ -438,7 +450,9 @@ discard block |
||
438 | 450 | if (strlen($this->template) > $this->maxInclTemplateSize) { |
439 | 451 | $this->triggerError("Subtemplate include aborted because the internal template string is longer than $this->maxInclTemplateSize characters."); |
440 | 452 | return false; } |
441 | - if (!$this->loadSubtemplate($subtemplateName, $subtemplate)) return false; |
|
453 | + if (!$this->loadSubtemplate($subtemplateName, $subtemplate)) { |
|
454 | + return false; |
|
455 | + } |
|
442 | 456 | // (Copying the template to insert a subtemplate is a bit slow. In a future implementation of MiniTemplator, |
443 | 457 | // a table could be used that contains references to the string fragments.) |
444 | 458 | $this->template = substr($this->template, 0, $tPos1).$subtemplate.substr($this->template, $tPos2); |
@@ -473,8 +487,9 @@ discard block |
||
473 | 487 | * @access private |
474 | 488 | */ |
475 | 489 | function registerVariableReference($varName, $tPosBegin, $tPosEnd) { |
476 | - if (!$this->lookupVariableName($varName, $varNo)) |
|
477 | - $this->registerVariable($varName, $varNo); |
|
490 | + if (!$this->lookupVariableName($varName, $varNo)) { |
|
491 | + $this->registerVariable($varName, $varNo); |
|
492 | + } |
|
478 | 493 | $varRefNo = $this->varRefTabCnt++; |
479 | 494 | $vrtr = & $this->varRefTab[$varRefNo]; |
480 | 495 | $vrtr = array(); |
@@ -514,12 +529,14 @@ discard block |
||
514 | 529 | $nextBlockNo += 1; |
515 | 530 | continue; }} |
516 | 531 | $btr = & $this->blockTab[$activeBlockNo]; |
517 | - if ($varRefTPos < $btr['tPosBegin']) |
|
518 | - $this->programLogicError(1); |
|
532 | + if ($varRefTPos < $btr['tPosBegin']) { |
|
533 | + $this->programLogicError(1); |
|
534 | + } |
|
519 | 535 | $blockVarNo = $btr['blockVarCnt']++; |
520 | 536 | $btr['blockVarNoToVarNoMap'][$blockVarNo] = $varNo; |
521 | - if ($btr['firstVarRefNo'] == -1) |
|
522 | - $btr['firstVarRefNo'] = $varRefNo; |
|
537 | + if ($btr['firstVarRefNo'] == -1) { |
|
538 | + $btr['firstVarRefNo'] = $varRefNo; |
|
539 | + } |
|
523 | 540 | $vrtr['blockNo'] = $activeBlockNo; |
524 | 541 | $vrtr['blockVarNo'] = $blockVarNo; |
525 | 542 | $varRefNo += 1; }} |
@@ -535,8 +552,9 @@ discard block |
||
535 | 552 | * @access public |
536 | 553 | */ |
537 | 554 | function reset() { |
538 | - for ($varNo = 0; $varNo < $this->varTabCnt; $varNo++) |
|
539 | - $this->varTab[$varNo]['varValue'] = ''; |
|
555 | + for ($varNo = 0; $varNo < $this->varTabCnt; $varNo++) { |
|
556 | + $this->varTab[$varNo]['varValue'] = ''; |
|
557 | + } |
|
540 | 558 | for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) { |
541 | 559 | $btr = & $this->blockTab[$blockNo]; |
542 | 560 | $btr['instances'] = 0; |
@@ -563,7 +581,9 @@ discard block |
||
563 | 581 | function setVariable($variableName, $variableValue, $isOptional = false) { |
564 | 582 | if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; } |
565 | 583 | if (!$this->lookupVariableName($variableName, $varNo)) { |
566 | - if ($isOptional) return true; |
|
584 | + if ($isOptional) { |
|
585 | + return true; |
|
586 | + } |
|
567 | 587 | $this->triggerError("Variable \"$variableName\" not defined in template."); |
568 | 588 | return false; } |
569 | 589 | $this->varTab[$varNo]['varValue'] = $variableValue; |
@@ -631,20 +651,23 @@ discard block |
||
631 | 651 | $btr = & $this->blockTab[$blockNo]; |
632 | 652 | $this->registerBlockInstance($blockInstNo); |
633 | 653 | $bitr = & $this->blockInstTab[$blockInstNo]; |
634 | - if ($btr['firstBlockInstNo'] == -1) |
|
635 | - $btr['firstBlockInstNo'] = $blockInstNo; |
|
636 | - if ($btr['lastBlockInstNo'] != -1) |
|
637 | - $this->blockInstTab[$btr['lastBlockInstNo']]['nextBlockInstNo'] = $blockInstNo; |
|
654 | + if ($btr['firstBlockInstNo'] == -1) { |
|
655 | + $btr['firstBlockInstNo'] = $blockInstNo; |
|
656 | + } |
|
657 | + if ($btr['lastBlockInstNo'] != -1) { |
|
658 | + $this->blockInstTab[$btr['lastBlockInstNo']]['nextBlockInstNo'] = $blockInstNo; |
|
659 | + } |
|
638 | 660 | // set forward pointer of chain |
639 | 661 | $btr['lastBlockInstNo'] = $blockInstNo; |
640 | 662 | $parentBlockNo = $btr['parentBlockNo']; |
641 | 663 | $blockVarCnt = $btr['blockVarCnt']; |
642 | 664 | $bitr['blockNo'] = $blockNo; |
643 | 665 | $bitr['instanceLevel'] = $btr['instances']++; |
644 | - if ($parentBlockNo == -1) |
|
645 | - $bitr['parentInstLevel'] = -1; |
|
646 | - else |
|
647 | - $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances']; |
|
666 | + if ($parentBlockNo == -1) { |
|
667 | + $bitr['parentInstLevel'] = -1; |
|
668 | + } else { |
|
669 | + $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances']; |
|
670 | + } |
|
648 | 671 | $bitr['nextBlockInstNo'] = -1; |
649 | 672 | $bitr['blockVarTab'] = array(); |
650 | 673 | // copy instance variables for this block |
@@ -691,7 +714,9 @@ discard block |
||
691 | 714 | */ |
692 | 715 | function generateOutputToFile($fileName) { |
693 | 716 | $fh = fopen($fileName, "wb"); |
694 | - if ($fh === false) return false; |
|
717 | + if ($fh === false) { |
|
718 | + return false; |
|
719 | + } |
|
695 | 720 | $this->outputMode = 1; |
696 | 721 | $this->outputFileHandle = $fh; |
697 | 722 | $ok = $this->generateOutputPage(); |
@@ -721,14 +746,18 @@ discard block |
||
721 | 746 | */ |
722 | 747 | function generateOutputPage() { |
723 | 748 | if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; } |
724 | - if ($this->blockTab[0]['instances'] == 0) |
|
725 | - $this->addBlockByNo(0); // add main block |
|
749 | + if ($this->blockTab[0]['instances'] == 0) { |
|
750 | + $this->addBlockByNo(0); |
|
751 | + } |
|
752 | + // add main block |
|
726 | 753 | for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) { |
727 | 754 | $btr = & $this->blockTab[$blockNo]; |
728 | 755 | $btr['currBlockInstNo'] = $btr['firstBlockInstNo']; } |
729 | 756 | $this->outputError = false; |
730 | 757 | $this->writeBlockInstances(0, -1); |
731 | - if ($this->outputError) return false; |
|
758 | + if ($this->outputError) { |
|
759 | + return false; |
|
760 | + } |
|
732 | 761 | return true; } |
733 | 762 | |
734 | 763 | /** |
@@ -741,11 +770,16 @@ discard block |
||
741 | 770 | $btr = & $this->blockTab[$blockNo]; |
742 | 771 | while (!$this->outputError) { |
743 | 772 | $blockInstNo = $btr['currBlockInstNo']; |
744 | - if ($blockInstNo == -1) break; |
|
773 | + if ($blockInstNo == -1) { |
|
774 | + break; |
|
775 | + } |
|
745 | 776 | $bitr = & $this->blockInstTab[$blockInstNo]; |
746 | - if ($bitr['parentInstLevel'] < $parentInstLevel) |
|
747 | - $this->programLogicError(2); |
|
748 | - if ($bitr['parentInstLevel'] > $parentInstLevel) break; |
|
777 | + if ($bitr['parentInstLevel'] < $parentInstLevel) { |
|
778 | + $this->programLogicError(2); |
|
779 | + } |
|
780 | + if ($bitr['parentInstLevel'] > $parentInstLevel) { |
|
781 | + break; |
|
782 | + } |
|
749 | 783 | $this->writeBlockInstance($blockInstNo); |
750 | 784 | $btr['currBlockInstNo'] = $bitr['nextBlockInstNo']; }} |
751 | 785 | |
@@ -778,15 +812,17 @@ discard block |
||
778 | 812 | if ($subBtr['tPosBegin'] < $tPos2) { |
779 | 813 | $tPos2 = $subBtr['tPosBegin']; |
780 | 814 | $kind = 2; }} |
781 | - if ($tPos2 > $tPos) |
|
782 | - $this->writeString(substr($this->template, $tPos, $tPos2 - $tPos)); |
|
815 | + if ($tPos2 > $tPos) { |
|
816 | + $this->writeString(substr($this->template, $tPos, $tPos2 - $tPos)); |
|
817 | + } |
|
783 | 818 | switch ($kind) { |
784 | 819 | case 0: // end of block |
785 | 820 | return; |
786 | 821 | case 1: // variable |
787 | 822 | $vrtr = & $this->varRefTab[$varRefNo]; |
788 | - if ($vrtr['blockNo'] != $blockNo) |
|
789 | - $this->programLogicError(4); |
|
823 | + if ($vrtr['blockNo'] != $blockNo) { |
|
824 | + $this->programLogicError(4); |
|
825 | + } |
|
790 | 826 | $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']]; |
791 | 827 | $this->writeString($variableValue); |
792 | 828 | $tPos = $vrtr['tPosEnd']; |
@@ -794,8 +830,9 @@ discard block |
||
794 | 830 | break; |
795 | 831 | case 2: // sub block |
796 | 832 | $subBtr = & $this->blockTab[$subBlockNo]; |
797 | - if ($subBtr['parentBlockNo'] != $blockNo) |
|
798 | - $this->programLogicError(3); |
|
833 | + if ($subBtr['parentBlockNo'] != $blockNo) { |
|
834 | + $this->programLogicError(3); |
|
835 | + } |
|
799 | 836 | $this->writeBlockInstances($subBlockNo, $bitr['instanceLevel']); // recursive call |
800 | 837 | $tPos = $subBtr['tPosEnd']; |
801 | 838 | $subBlockNo += 1; |
@@ -805,15 +842,20 @@ discard block |
||
805 | 842 | * @access private |
806 | 843 | */ |
807 | 844 | function writeString($s) { |
808 | - if ($this->outputError) return; |
|
845 | + if ($this->outputError) { |
|
846 | + return; |
|
847 | + } |
|
809 | 848 | switch ($this->outputMode) { |
810 | 849 | case 0: // output to PHP output stream |
811 | - if (!print($s)) |
|
812 | - $this->outputError = true; |
|
850 | + if (!print($s)) { |
|
851 | + $this->outputError = true; |
|
852 | + } |
|
813 | 853 | break; |
814 | 854 | case 1: // output to file |
815 | 855 | $rc = fwrite($this->outputFileHandle, $s); |
816 | - if ($rc === false) $this->outputError = true; |
|
856 | + if ($rc === false) { |
|
857 | + $this->outputError = true; |
|
858 | + } |
|
817 | 859 | break; |
818 | 860 | case 2: // output to string |
819 | 861 | $this->outputString .= $s; |
@@ -828,7 +870,9 @@ discard block |
||
828 | 870 | */ |
829 | 871 | function lookupVariableName($varName, &$varNo) { |
830 | 872 | $x = & $this->varNameToNoMap[strtoupper($varName)]; |
831 | - if (!isset($x)) return false; |
|
873 | + if (!isset($x)) { |
|
874 | + return false; |
|
875 | + } |
|
832 | 876 | $varNo = $x; |
833 | 877 | return true; } |
834 | 878 | |
@@ -841,7 +885,9 @@ discard block |
||
841 | 885 | */ |
842 | 886 | function lookupBlockName($blockName, &$blockNo) { |
843 | 887 | $x = & $this->blockNameToNoMap[strtoupper($blockName)]; |
844 | - if (!isset($x)) return false; |
|
888 | + if (!isset($x)) { |
|
889 | + return false; |
|
890 | + } |
|
845 | 891 | $blockNo = $x; |
846 | 892 | return true; } |
847 | 893 | |
@@ -855,15 +901,21 @@ discard block |
||
855 | 901 | function readFileIntoString($fileName, &$s) { |
856 | 902 | if (function_exists('version_compare') && version_compare(phpversion(), "4.3.0", ">=")) { |
857 | 903 | $s = file_get_contents($fileName); |
858 | - if ($s === false) return false; |
|
904 | + if ($s === false) { |
|
905 | + return false; |
|
906 | + } |
|
859 | 907 | return true; } |
860 | 908 | $fh = fopen($fileName, "rb"); |
861 | - if ($fh === false) return false; |
|
909 | + if ($fh === false) { |
|
910 | + return false; |
|
911 | + } |
|
862 | 912 | $fileSize = filesize($fileName); |
863 | 913 | if ($fileSize === false) {fclose($fh); return false; } |
864 | 914 | $s = fread($fh, $fileSize); |
865 | 915 | fclose($fh); |
866 | - if (strlen($s) != $fileSize) return false; |
|
916 | + if (strlen($s) != $fileSize) { |
|
917 | + return false; |
|
918 | + } |
|
867 | 919 | return true; } |
868 | 920 | |
869 | 921 | /** |
@@ -891,12 +943,22 @@ discard block |
||
891 | 943 | */ |
892 | 944 | function parseQuotedString($s, &$p, &$w) { |
893 | 945 | $sLen = strlen($s); |
894 | - while ($p < $sLen && ord($s{$p}) <= 32) $p++; |
|
895 | - if ($p >= $sLen) return false; |
|
896 | - if (substr($s, $p, 1) != '"') return false; |
|
946 | + while ($p < $sLen && ord($s{$p}) <= 32) { |
|
947 | + $p++; |
|
948 | + } |
|
949 | + if ($p >= $sLen) { |
|
950 | + return false; |
|
951 | + } |
|
952 | + if (substr($s, $p, 1) != '"') { |
|
953 | + return false; |
|
954 | + } |
|
897 | 955 | $p++; $p0 = $p; |
898 | - while ($p < $sLen && $s{$p} != '"') $p++; |
|
899 | - if ($p >= $sLen) return false; |
|
956 | + while ($p < $sLen && $s{$p} != '"') { |
|
957 | + $p++; |
|
958 | + } |
|
959 | + if ($p >= $sLen) { |
|
960 | + return false; |
|
961 | + } |
|
900 | 962 | $w = substr($s, $p0, $p - $p0); |
901 | 963 | $p++; |
902 | 964 | return true; } |
@@ -907,25 +969,36 @@ discard block |
||
907 | 969 | */ |
908 | 970 | function parseWordOrQuotedString($s, &$p, &$w) { |
909 | 971 | $sLen = strlen($s); |
910 | - while ($p < $sLen && ord($s{$p}) <= 32) $p++; |
|
911 | - if ($p >= $sLen) return false; |
|
912 | - if (substr($s, $p, 1) == '"') |
|
913 | - return $this->parseQuotedString($s, $p, $w); |
|
914 | - else |
|
915 | - return $this->parseWord($s, $p, $w); } |
|
972 | + while ($p < $sLen && ord($s{$p}) <= 32) { |
|
973 | + $p++; |
|
974 | + } |
|
975 | + if ($p >= $sLen) { |
|
976 | + return false; |
|
977 | + } |
|
978 | + if (substr($s, $p, 1) == '"') { |
|
979 | + return $this->parseQuotedString($s, $p, $w); |
|
980 | + } else { |
|
981 | + return $this->parseWord($s, $p, $w); |
|
982 | + } |
|
983 | + } |
|
916 | 984 | |
917 | 985 | /** |
918 | 986 | * Combine two file system paths. |
919 | 987 | * @access private |
920 | 988 | */ |
921 | 989 | function combineFileSystemPath($path1, $path2) { |
922 | - if ($path1 == '' || $path2 == '') return $path2; |
|
990 | + if ($path1 == '' || $path2 == '') { |
|
991 | + return $path2; |
|
992 | + } |
|
923 | 993 | $s = $path1; |
924 | - if (substr($s, -1) != '\\' && substr($s, -1) != '/') $s = $s."/"; |
|
925 | - if (substr($path2, 0, 1) == '\\' || substr($path2, 0, 1) == '/') |
|
926 | - $s = $s.substr($path2, 1); |
|
927 | - else |
|
928 | - $s = $s.$path2; |
|
994 | + if (substr($s, -1) != '\\' && substr($s, -1) != '/') { |
|
995 | + $s = $s."/"; |
|
996 | + } |
|
997 | + if (substr($path2, 0, 1) == '\\' || substr($path2, 0, 1) == '/') { |
|
998 | + $s = $s.substr($path2, 1); |
|
999 | + } else { |
|
1000 | + $s = $s.$path2; |
|
1001 | + } |
|
929 | 1002 | return $s; } |
930 | 1003 | |
931 | 1004 | /** |