@@ -191,12 +191,15 @@ discard block |
||
191 | 191 | $tasksdir = $sourcedir . '/tasks'; |
192 | 192 | |
193 | 193 | # Make sure the paths are correct... at least try to fix them. |
194 | -if (!file_exists($boarddir) && file_exists(dirname(__FILE__) . '/agreement.txt')) |
|
194 | +if (!file_exists($boarddir) && file_exists(dirname(__FILE__) . '/agreement.txt')) { |
|
195 | 195 | $boarddir = dirname(__FILE__); |
196 | -if (!file_exists($sourcedir) && file_exists($boarddir . '/Sources')) |
|
196 | +} |
|
197 | +if (!file_exists($sourcedir) && file_exists($boarddir . '/Sources')) { |
|
197 | 198 | $sourcedir = $boarddir . '/Sources'; |
198 | -if (!file_exists($cachedir) && file_exists($boarddir . '/cache')) |
|
199 | +} |
|
200 | +if (!file_exists($cachedir) && file_exists($boarddir . '/cache')) { |
|
199 | 201 | $cachedir = $boarddir . '/cache'; |
202 | +} |
|
200 | 203 | |
201 | 204 | ######### Legacy Settings ######### |
202 | 205 | # UTF-8 is now the only character set supported in 2.1. |
@@ -204,8 +207,9 @@ discard block |
||
204 | 207 | |
205 | 208 | ########## Error-Catching ########## |
206 | 209 | # Note: You shouldn't touch these settings. |
207 | -if (file_exists((isset($cachedir) ? $cachedir : dirname(__FILE__)) . '/db_last_error.php')) |
|
210 | +if (file_exists((isset($cachedir) ? $cachedir : dirname(__FILE__)) . '/db_last_error.php')) { |
|
208 | 211 | include((isset($cachedir) ? $cachedir : dirname(__FILE__)) . '/db_last_error.php'); |
212 | +} |
|
209 | 213 | |
210 | 214 | if (!isset($db_last_error)) |
211 | 215 | { |
@@ -217,10 +221,11 @@ discard block |
||
217 | 221 | if (file_exists(dirname(__FILE__) . '/install.php')) |
218 | 222 | { |
219 | 223 | $secure = false; |
220 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
221 | - $secure = true; |
|
222 | - elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') |
|
223 | - $secure = true; |
|
224 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
225 | + $secure = true; |
|
226 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { |
|
227 | + $secure = true; |
|
228 | + } |
|
224 | 229 | |
225 | 230 | header('location: http' . ($secure ? 's' : '') . '://' . (empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']) . (strtr(dirname($_SERVER['PHP_SELF']), '\\', '/') == '/' ? '' : strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')) . '/install.php'); exit; |
226 | 231 | } |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -34,8 +35,8 @@ discard block |
||
34 | 35 | global $smcFunc; |
35 | 36 | |
36 | 37 | // Map some database specific functions, only do this once. |
37 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
38 | - $smcFunc += array( |
|
38 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
39 | + $smcFunc += array( |
|
39 | 40 | 'db_query' => 'smf_db_query', |
40 | 41 | 'db_quote' => 'smf_db_quote', |
41 | 42 | 'db_insert' => 'smf_db_insert', |
@@ -66,15 +67,18 @@ discard block |
||
66 | 67 | 'db_native_replace' => 'smf_db_native_replace', |
67 | 68 | 'db_cte_support' => 'smf_db_cte_support', |
68 | 69 | ); |
70 | + } |
|
69 | 71 | |
70 | 72 | // We are not going to make it very far without these. |
71 | - if (!function_exists('pg_pconnect')) |
|
72 | - display_db_error(); |
|
73 | + if (!function_exists('pg_pconnect')) { |
|
74 | + display_db_error(); |
|
75 | + } |
|
73 | 76 | |
74 | - if (!empty($db_options['persist'])) |
|
75 | - $connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
76 | - else |
|
77 | - $connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
77 | + if (!empty($db_options['persist'])) { |
|
78 | + $connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
79 | + } else { |
|
80 | + $connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
81 | + } |
|
78 | 82 | |
79 | 83 | // Something's wrong, show an error if its fatal (which we assume it is) |
80 | 84 | if (!$connection) |
@@ -82,15 +86,15 @@ discard block |
||
82 | 86 | if (!empty($db_options['non_fatal'])) |
83 | 87 | { |
84 | 88 | return null; |
85 | - } |
|
86 | - else |
|
89 | + } else |
|
87 | 90 | { |
88 | 91 | display_db_error(); |
89 | 92 | } |
90 | 93 | } |
91 | 94 | |
92 | - if (!empty($db_options['db_mb4'])) |
|
93 | - $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
95 | + if (!empty($db_options['db_mb4'])) { |
|
96 | + $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
97 | + } |
|
94 | 98 | |
95 | 99 | return $connection; |
96 | 100 | } |
@@ -137,31 +141,38 @@ discard block |
||
137 | 141 | |
138 | 142 | list ($values, $connection) = $db_callback; |
139 | 143 | |
140 | - if ($matches[1] === 'db_prefix') |
|
141 | - return $db_prefix; |
|
144 | + if ($matches[1] === 'db_prefix') { |
|
145 | + return $db_prefix; |
|
146 | + } |
|
142 | 147 | |
143 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
144 | - return $user_info[$matches[1]]; |
|
148 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
149 | + return $user_info[$matches[1]]; |
|
150 | + } |
|
145 | 151 | |
146 | - if ($matches[1] === 'empty') |
|
147 | - return '\'\''; |
|
152 | + if ($matches[1] === 'empty') { |
|
153 | + return '\'\''; |
|
154 | + } |
|
148 | 155 | |
149 | - if (!isset($matches[2])) |
|
150 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
156 | + if (!isset($matches[2])) { |
|
157 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
158 | + } |
|
151 | 159 | |
152 | - if ($matches[1] === 'literal') |
|
153 | - return '\'' . pg_escape_string($matches[2]) . '\''; |
|
160 | + if ($matches[1] === 'literal') { |
|
161 | + return '\'' . pg_escape_string($matches[2]) . '\''; |
|
162 | + } |
|
154 | 163 | |
155 | - if (!isset($values[$matches[2]])) |
|
156 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
164 | + if (!isset($values[$matches[2]])) { |
|
165 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
166 | + } |
|
157 | 167 | |
158 | 168 | $replacement = $values[$matches[2]]; |
159 | 169 | |
160 | 170 | switch ($matches[1]) |
161 | 171 | { |
162 | 172 | case 'int': |
163 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
164 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
173 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
174 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
175 | + } |
|
165 | 176 | return (string) (int) $replacement; |
166 | 177 | break; |
167 | 178 | |
@@ -173,65 +184,73 @@ discard block |
||
173 | 184 | case 'array_int': |
174 | 185 | if (is_array($replacement)) |
175 | 186 | { |
176 | - if (empty($replacement)) |
|
177 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
187 | + if (empty($replacement)) { |
|
188 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
189 | + } |
|
178 | 190 | |
179 | 191 | foreach ($replacement as $key => $value) |
180 | 192 | { |
181 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
182 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
193 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
194 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
195 | + } |
|
183 | 196 | |
184 | 197 | $replacement[$key] = (string) (int) $value; |
185 | 198 | } |
186 | 199 | |
187 | 200 | return implode(', ', $replacement); |
201 | + } else { |
|
202 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
188 | 203 | } |
189 | - else |
|
190 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
191 | 204 | |
192 | 205 | break; |
193 | 206 | |
194 | 207 | case 'array_string': |
195 | 208 | if (is_array($replacement)) |
196 | 209 | { |
197 | - if (empty($replacement)) |
|
198 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
210 | + if (empty($replacement)) { |
|
211 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
212 | + } |
|
199 | 213 | |
200 | - foreach ($replacement as $key => $value) |
|
201 | - $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
214 | + foreach ($replacement as $key => $value) { |
|
215 | + $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
216 | + } |
|
202 | 217 | |
203 | 218 | return implode(', ', $replacement); |
219 | + } else { |
|
220 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
204 | 221 | } |
205 | - else |
|
206 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
207 | 222 | break; |
208 | 223 | |
209 | 224 | case 'date': |
210 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
211 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
212 | - else |
|
213 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
225 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
226 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
227 | + } else { |
|
228 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
229 | + } |
|
214 | 230 | break; |
215 | 231 | |
216 | 232 | case 'time': |
217 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
218 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
219 | - else |
|
220 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
233 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
234 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
235 | + } else { |
|
236 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
237 | + } |
|
221 | 238 | break; |
222 | 239 | |
223 | 240 | case 'datetime': |
224 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
225 | - return 'to_timestamp('. |
|
241 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
242 | + return 'to_timestamp('. |
|
226 | 243 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
227 | 244 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
228 | - else |
|
229 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
245 | + } else { |
|
246 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
247 | + } |
|
230 | 248 | break; |
231 | 249 | |
232 | 250 | case 'float': |
233 | - if (!is_numeric($replacement)) |
|
234 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
251 | + if (!is_numeric($replacement)) { |
|
252 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
253 | + } |
|
235 | 254 | return (string) (float) $replacement; |
236 | 255 | break; |
237 | 256 | |
@@ -244,31 +263,36 @@ discard block |
||
244 | 263 | break; |
245 | 264 | |
246 | 265 | case 'inet': |
247 | - if ($replacement == 'null' || $replacement == '') |
|
248 | - return 'null'; |
|
249 | - if (inet_pton($replacement) === false) |
|
250 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
266 | + if ($replacement == 'null' || $replacement == '') { |
|
267 | + return 'null'; |
|
268 | + } |
|
269 | + if (inet_pton($replacement) === false) { |
|
270 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
271 | + } |
|
251 | 272 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
252 | 273 | |
253 | 274 | case 'array_inet': |
254 | 275 | if (is_array($replacement)) |
255 | 276 | { |
256 | - if (empty($replacement)) |
|
257 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
277 | + if (empty($replacement)) { |
|
278 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
279 | + } |
|
258 | 280 | |
259 | 281 | foreach ($replacement as $key => $value) |
260 | 282 | { |
261 | - if ($replacement == 'null' || $replacement == '') |
|
262 | - $replacement[$key] = 'null'; |
|
263 | - if (!isValidIP($value)) |
|
264 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
283 | + if ($replacement == 'null' || $replacement == '') { |
|
284 | + $replacement[$key] = 'null'; |
|
285 | + } |
|
286 | + if (!isValidIP($value)) { |
|
287 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
288 | + } |
|
265 | 289 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
266 | 290 | } |
267 | 291 | |
268 | 292 | return implode(', ', $replacement); |
293 | + } else { |
|
294 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
269 | 295 | } |
270 | - else |
|
271 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
272 | 296 | break; |
273 | 297 | |
274 | 298 | default: |
@@ -356,14 +380,16 @@ discard block |
||
356 | 380 | ), |
357 | 381 | ); |
358 | 382 | |
359 | - if (isset($replacements[$identifier])) |
|
360 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
383 | + if (isset($replacements[$identifier])) { |
|
384 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
385 | + } |
|
361 | 386 | |
362 | 387 | // Limits need to be a little different. |
363 | 388 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
364 | 389 | |
365 | - if (trim($db_string) == '') |
|
366 | - return false; |
|
390 | + if (trim($db_string) == '') { |
|
391 | + return false; |
|
392 | + } |
|
367 | 393 | |
368 | 394 | // Comments that are allowed in a query are preg_removed. |
369 | 395 | static $allowed_comments_from = array( |
@@ -383,8 +409,9 @@ discard block |
||
383 | 409 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
384 | 410 | $db_replace_result = 0; |
385 | 411 | |
386 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
387 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
412 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
413 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
414 | + } |
|
388 | 415 | |
389 | 416 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
390 | 417 | { |
@@ -409,17 +436,18 @@ discard block |
||
409 | 436 | while (true) |
410 | 437 | { |
411 | 438 | $pos = strpos($db_string_1, '\'', $pos + 1); |
412 | - if ($pos === false) |
|
413 | - break; |
|
439 | + if ($pos === false) { |
|
440 | + break; |
|
441 | + } |
|
414 | 442 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
415 | 443 | |
416 | 444 | while (true) |
417 | 445 | { |
418 | 446 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
419 | 447 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
420 | - if ($pos1 === false) |
|
421 | - break; |
|
422 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
448 | + if ($pos1 === false) { |
|
449 | + break; |
|
450 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
423 | 451 | { |
424 | 452 | $pos = $pos1; |
425 | 453 | break; |
@@ -435,16 +463,19 @@ discard block |
||
435 | 463 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
436 | 464 | |
437 | 465 | // Comments? We don't use comments in our queries, we leave 'em outside! |
438 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
439 | - $fail = true; |
|
466 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
467 | + $fail = true; |
|
468 | + } |
|
440 | 469 | // Trying to change passwords, slow us down, or something? |
441 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
442 | - $fail = true; |
|
443 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
444 | - $fail = true; |
|
470 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
471 | + $fail = true; |
|
472 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
473 | + $fail = true; |
|
474 | + } |
|
445 | 475 | |
446 | - if (!empty($fail) && function_exists('log_error')) |
|
447 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
476 | + if (!empty($fail) && function_exists('log_error')) { |
|
477 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
478 | + } |
|
448 | 479 | } |
449 | 480 | |
450 | 481 | // Set optimize stuff |
@@ -471,8 +502,9 @@ discard block |
||
471 | 502 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
472 | 503 | |
473 | 504 | // Initialize $db_cache if not already initialized. |
474 | - if (!isset($db_cache)) |
|
475 | - $db_cache = array(); |
|
505 | + if (!isset($db_cache)) { |
|
506 | + $db_cache = array(); |
|
507 | + } |
|
476 | 508 | |
477 | 509 | if (!empty($_SESSION['debug_redirect'])) |
478 | 510 | { |
@@ -490,12 +522,14 @@ discard block |
||
490 | 522 | |
491 | 523 | $db_last_result = @pg_query($connection, $db_string); |
492 | 524 | |
493 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
494 | - $db_last_result = smf_db_error($db_string, $connection); |
|
525 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
526 | + $db_last_result = smf_db_error($db_string, $connection); |
|
527 | + } |
|
495 | 528 | |
496 | 529 | // Debugging. |
497 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
498 | - $db_cache[$db_count]['t'] = microtime(true) - $st; |
|
530 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
531 | + $db_cache[$db_count]['t'] = microtime(true) - $st; |
|
532 | + } |
|
499 | 533 | |
500 | 534 | return $db_last_result; |
501 | 535 | } |
@@ -512,10 +546,11 @@ discard block |
||
512 | 546 | { |
513 | 547 | global $db_last_result, $db_replace_result; |
514 | 548 | |
515 | - if ($db_replace_result) |
|
516 | - return $db_replace_result; |
|
517 | - elseif ($result === null && !$db_last_result) |
|
518 | - return 0; |
|
549 | + if ($db_replace_result) { |
|
550 | + return $db_replace_result; |
|
551 | + } elseif ($result === null && !$db_last_result) { |
|
552 | + return 0; |
|
553 | + } |
|
519 | 554 | |
520 | 555 | return pg_affected_rows($result === null ? $db_last_result : $result); |
521 | 556 | } |
@@ -539,8 +574,9 @@ discard block |
||
539 | 574 | array( |
540 | 575 | ) |
541 | 576 | ); |
542 | - if (!$request) |
|
543 | - return false; |
|
577 | + if (!$request) { |
|
578 | + return false; |
|
579 | + } |
|
544 | 580 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
545 | 581 | $smcFunc['db_free_result']($request); |
546 | 582 | |
@@ -561,12 +597,13 @@ discard block |
||
561 | 597 | // Decide which connection to use |
562 | 598 | $connection = $connection === null ? $db_connection : $connection; |
563 | 599 | |
564 | - if ($type == 'begin') |
|
565 | - return @pg_query($connection, 'BEGIN'); |
|
566 | - elseif ($type == 'rollback') |
|
567 | - return @pg_query($connection, 'ROLLBACK'); |
|
568 | - elseif ($type == 'commit') |
|
569 | - return @pg_query($connection, 'COMMIT'); |
|
600 | + if ($type == 'begin') { |
|
601 | + return @pg_query($connection, 'BEGIN'); |
|
602 | + } elseif ($type == 'rollback') { |
|
603 | + return @pg_query($connection, 'ROLLBACK'); |
|
604 | + } elseif ($type == 'commit') { |
|
605 | + return @pg_query($connection, 'COMMIT'); |
|
606 | + } |
|
570 | 607 | |
571 | 608 | return false; |
572 | 609 | } |
@@ -594,19 +631,22 @@ discard block |
||
594 | 631 | $query_error = @pg_last_error($connection); |
595 | 632 | |
596 | 633 | // Log the error. |
597 | - if (function_exists('log_error')) |
|
598 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
634 | + if (function_exists('log_error')) { |
|
635 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
636 | + } |
|
599 | 637 | |
600 | 638 | // Nothing's defined yet... just die with it. |
601 | - if (empty($context) || empty($txt)) |
|
602 | - die($query_error); |
|
639 | + if (empty($context) || empty($txt)) { |
|
640 | + die($query_error); |
|
641 | + } |
|
603 | 642 | |
604 | 643 | // Show an error message, if possible. |
605 | 644 | $context['error_title'] = $txt['database_error']; |
606 | - if (allowedTo('admin_forum')) |
|
607 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
608 | - else |
|
609 | - $context['error_message'] = $txt['try_again']; |
|
645 | + if (allowedTo('admin_forum')) { |
|
646 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
647 | + } else { |
|
648 | + $context['error_message'] = $txt['try_again']; |
|
649 | + } |
|
610 | 650 | |
611 | 651 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
612 | 652 | { |
@@ -628,12 +668,14 @@ discard block |
||
628 | 668 | { |
629 | 669 | global $db_row_count; |
630 | 670 | |
631 | - if ($counter !== false) |
|
632 | - return pg_fetch_row($request, $counter); |
|
671 | + if ($counter !== false) { |
|
672 | + return pg_fetch_row($request, $counter); |
|
673 | + } |
|
633 | 674 | |
634 | 675 | // Reset the row counter... |
635 | - if (!isset($db_row_count[(int) $request])) |
|
636 | - $db_row_count[(int) $request] = 0; |
|
676 | + if (!isset($db_row_count[(int) $request])) { |
|
677 | + $db_row_count[(int) $request] = 0; |
|
678 | + } |
|
637 | 679 | |
638 | 680 | // Return the right row. |
639 | 681 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -650,12 +692,14 @@ discard block |
||
650 | 692 | { |
651 | 693 | global $db_row_count; |
652 | 694 | |
653 | - if ($counter !== false) |
|
654 | - return pg_fetch_assoc($request, $counter); |
|
695 | + if ($counter !== false) { |
|
696 | + return pg_fetch_assoc($request, $counter); |
|
697 | + } |
|
655 | 698 | |
656 | 699 | // Reset the row counter... |
657 | - if (!isset($db_row_count[(int) $request])) |
|
658 | - $db_row_count[(int) $request] = 0; |
|
700 | + if (!isset($db_row_count[(int) $request])) { |
|
701 | + $db_row_count[(int) $request] = 0; |
|
702 | + } |
|
659 | 703 | |
660 | 704 | // Return the right row. |
661 | 705 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -697,19 +741,22 @@ discard block |
||
697 | 741 | |
698 | 742 | $replace = ''; |
699 | 743 | |
700 | - if (empty($data)) |
|
701 | - return; |
|
744 | + if (empty($data)) { |
|
745 | + return; |
|
746 | + } |
|
702 | 747 | |
703 | - if (!is_array($data[array_rand($data)])) |
|
704 | - $data = array($data); |
|
748 | + if (!is_array($data[array_rand($data)])) { |
|
749 | + $data = array($data); |
|
750 | + } |
|
705 | 751 | |
706 | 752 | // Replace the prefix holder with the actual prefix. |
707 | 753 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
708 | 754 | |
709 | 755 | // Sanity check for replace is key part of the columns array |
710 | - if ($method == 'replace' && count(array_intersect_key($columns, array_flip($keys))) !== count($keys)) |
|
711 | - smf_db_error_backtrace('Primary Key field missing in insert call', |
|
756 | + if ($method == 'replace' && count(array_intersect_key($columns, array_flip($keys))) !== count($keys)) { |
|
757 | + smf_db_error_backtrace('Primary Key field missing in insert call', |
|
712 | 758 | 'Change the method of db insert to insert or add the pk field to the columns array', E_USER_ERROR, __FILE__, __LINE__); |
759 | + } |
|
713 | 760 | |
714 | 761 | // PostgreSQL doesn't support replace: we implement a MySQL-compatible behavior instead |
715 | 762 | if ($method == 'replace' || $method == 'ignore') |
@@ -732,32 +779,35 @@ discard block |
||
732 | 779 | $key_str .= ($count_pk > 0 ? ',' : ''); |
733 | 780 | $key_str .= $columnName; |
734 | 781 | $count_pk++; |
735 | - } |
|
736 | - else if ($method == 'replace') //normal field |
|
782 | + } else if ($method == 'replace') { |
|
783 | + //normal field |
|
737 | 784 | { |
738 | 785 | $col_str .= ($count > 0 ? ',' : ''); |
786 | + } |
|
739 | 787 | $col_str .= $columnName . ' = EXCLUDED.' . $columnName; |
740 | 788 | $count++; |
741 | 789 | } |
742 | 790 | } |
743 | - if ($method == 'replace') |
|
744 | - $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
745 | - else |
|
746 | - $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
747 | - } |
|
748 | - else if ($method == 'replace') |
|
791 | + if ($method == 'replace') { |
|
792 | + $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
793 | + } else { |
|
794 | + $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
795 | + } |
|
796 | + } else if ($method == 'replace') |
|
749 | 797 | { |
750 | 798 | foreach ($columns as $columnName => $type) |
751 | 799 | { |
752 | 800 | // Are we restricting the length? |
753 | - if (strpos($type, 'string-') !== false) |
|
754 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
755 | - else |
|
756 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
801 | + if (strpos($type, 'string-') !== false) { |
|
802 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
803 | + } else { |
|
804 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
805 | + } |
|
757 | 806 | |
758 | 807 | // A key? That's what we were looking for. |
759 | - if (in_array($columnName, $keys)) |
|
760 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
808 | + if (in_array($columnName, $keys)) { |
|
809 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
810 | + } |
|
761 | 811 | $count++; |
762 | 812 | } |
763 | 813 | |
@@ -793,10 +843,11 @@ discard block |
||
793 | 843 | foreach ($columns as $columnName => $type) |
794 | 844 | { |
795 | 845 | // Are we restricting the length? |
796 | - if (strpos($type, 'string-') !== false) |
|
797 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
798 | - else |
|
799 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
846 | + if (strpos($type, 'string-') !== false) { |
|
847 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
848 | + } else { |
|
849 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
850 | + } |
|
800 | 851 | } |
801 | 852 | $insertData = substr($insertData, 0, -2) . ')'; |
802 | 853 | |
@@ -805,8 +856,9 @@ discard block |
||
805 | 856 | |
806 | 857 | // Here's where the variables are injected to the query. |
807 | 858 | $insertRows = array(); |
808 | - foreach ($data as $dataRow) |
|
809 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
859 | + foreach ($data as $dataRow) { |
|
860 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
861 | + } |
|
810 | 862 | |
811 | 863 | // Do the insert. |
812 | 864 | $request = $smcFunc['db_query']('', ' |
@@ -823,19 +875,21 @@ discard block |
||
823 | 875 | |
824 | 876 | if ($with_returning && $request !== false) |
825 | 877 | { |
826 | - if ($returnmode === 2) |
|
827 | - $return_var = array(); |
|
878 | + if ($returnmode === 2) { |
|
879 | + $return_var = array(); |
|
880 | + } |
|
828 | 881 | |
829 | 882 | while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
830 | 883 | { |
831 | - if (is_numeric($row[0])) // try to emulate mysql limitation |
|
884 | + if (is_numeric($row[0])) { |
|
885 | + // try to emulate mysql limitation |
|
832 | 886 | { |
833 | 887 | if ($returnmode === 1) |
834 | 888 | $return_var = $row[0]; |
835 | - elseif ($returnmode === 2) |
|
836 | - $return_var[] = $row[0]; |
|
837 | - } |
|
838 | - else |
|
889 | + } elseif ($returnmode === 2) { |
|
890 | + $return_var[] = $row[0]; |
|
891 | + } |
|
892 | + } else |
|
839 | 893 | { |
840 | 894 | $with_returning = false; |
841 | 895 | trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR); |
@@ -844,9 +898,10 @@ discard block |
||
844 | 898 | } |
845 | 899 | } |
846 | 900 | |
847 | - if ($with_returning && !empty($return_var)) |
|
848 | - return $return_var; |
|
849 | -} |
|
901 | + if ($with_returning && !empty($return_var)) { |
|
902 | + return $return_var; |
|
903 | + } |
|
904 | + } |
|
850 | 905 | |
851 | 906 | /** |
852 | 907 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -883,8 +938,9 @@ discard block |
||
883 | 938 | */ |
884 | 939 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
885 | 940 | { |
886 | - if (empty($log_message)) |
|
887 | - $log_message = $error_message; |
|
941 | + if (empty($log_message)) { |
|
942 | + $log_message = $error_message; |
|
943 | + } |
|
888 | 944 | |
889 | 945 | foreach (debug_backtrace() as $step) |
890 | 946 | { |
@@ -903,12 +959,14 @@ discard block |
||
903 | 959 | } |
904 | 960 | |
905 | 961 | // A special case - we want the file and line numbers for debugging. |
906 | - if ($error_type == 'return') |
|
907 | - return array($file, $line); |
|
962 | + if ($error_type == 'return') { |
|
963 | + return array($file, $line); |
|
964 | + } |
|
908 | 965 | |
909 | 966 | // Is always a critical error. |
910 | - if (function_exists('log_error')) |
|
911 | - log_error($log_message, 'critical', $file, $line); |
|
967 | + if (function_exists('log_error')) { |
|
968 | + log_error($log_message, 'critical', $file, $line); |
|
969 | + } |
|
912 | 970 | |
913 | 971 | if (function_exists('fatal_error')) |
914 | 972 | { |
@@ -916,12 +974,12 @@ discard block |
||
916 | 974 | |
917 | 975 | // Cannot continue... |
918 | 976 | exit; |
977 | + } elseif ($error_type) { |
|
978 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
979 | + } else { |
|
980 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
981 | + } |
|
919 | 982 | } |
920 | - elseif ($error_type) |
|
921 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
922 | - else |
|
923 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
924 | -} |
|
925 | 983 | |
926 | 984 | /** |
927 | 985 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -938,10 +996,11 @@ discard block |
||
938 | 996 | '\\' => '\\\\', |
939 | 997 | ); |
940 | 998 | |
941 | - if ($translate_human_wildcards) |
|
942 | - $replacements += array( |
|
999 | + if ($translate_human_wildcards) { |
|
1000 | + $replacements += array( |
|
943 | 1001 | '*' => '%', |
944 | 1002 | ); |
1003 | + } |
|
945 | 1004 | |
946 | 1005 | return strtr($string, $replacements); |
947 | 1006 | } |
@@ -970,14 +1029,16 @@ discard block |
||
970 | 1029 | static $pg_error_data_prep; |
971 | 1030 | |
972 | 1031 | // without database we can't do anything |
973 | - if (empty($db_connection)) |
|
974 | - return; |
|
1032 | + if (empty($db_connection)) { |
|
1033 | + return; |
|
1034 | + } |
|
975 | 1035 | |
976 | - if (empty($pg_error_data_prep)) |
|
977 | - $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
1036 | + if (empty($pg_error_data_prep)) { |
|
1037 | + $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
978 | 1038 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line, backtrace) |
979 | 1039 | VALUES( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10)' |
980 | 1040 | ); |
1041 | + } |
|
981 | 1042 | |
982 | 1043 | pg_execute($db_connection, 'smf_log_errors', $error_array); |
983 | 1044 | } |
@@ -997,8 +1058,9 @@ discard block |
||
997 | 1058 | $count = count($array_values); |
998 | 1059 | $then = ($desc ? ' THEN -' : ' THEN '); |
999 | 1060 | |
1000 | - for ($i = 0; $i < $count; $i++) |
|
1001 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1061 | + for ($i = 0; $i < $count; $i++) { |
|
1062 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1063 | + } |
|
1002 | 1064 | |
1003 | 1065 | $return .= 'END'; |
1004 | 1066 | return $return; |
@@ -1021,11 +1083,13 @@ discard block |
||
1021 | 1083 | //pg 9.5 got replace support |
1022 | 1084 | $pg_version = $smcFunc['db_get_version'](); |
1023 | 1085 | // if we got a Beta Version |
1024 | - if (stripos($pg_version, 'beta') !== false) |
|
1025 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
1086 | + if (stripos($pg_version, 'beta') !== false) { |
|
1087 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
1088 | + } |
|
1026 | 1089 | // or RC |
1027 | - if (stripos($pg_version, 'rc') !== false) |
|
1028 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
1090 | + if (stripos($pg_version, 'rc') !== false) { |
|
1091 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
1092 | + } |
|
1029 | 1093 | |
1030 | 1094 | $replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false); |
1031 | 1095 | } |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Outputs xml data representing recent information or a profile. |
@@ -37,8 +38,9 @@ discard block |
||
37 | 38 | global $query_this_board, $smcFunc, $forum_version, $settings; |
38 | 39 | |
39 | 40 | // If it's not enabled, die. |
40 | - if (empty($modSettings['xmlnews_enable'])) |
|
41 | - obExit(false); |
|
41 | + if (empty($modSettings['xmlnews_enable'])) { |
|
42 | + obExit(false); |
|
43 | + } |
|
42 | 44 | |
43 | 45 | loadLanguage('Stats'); |
44 | 46 | |
@@ -64,8 +66,9 @@ discard block |
||
64 | 66 | if (!empty($_REQUEST['c']) && empty($board)) |
65 | 67 | { |
66 | 68 | $_REQUEST['c'] = explode(',', $_REQUEST['c']); |
67 | - foreach ($_REQUEST['c'] as $i => $c) |
|
68 | - $_REQUEST['c'][$i] = (int) $c; |
|
69 | + foreach ($_REQUEST['c'] as $i => $c) { |
|
70 | + $_REQUEST['c'][$i] = (int) $c; |
|
71 | + } |
|
69 | 72 | |
70 | 73 | if (count($_REQUEST['c']) == 1) |
71 | 74 | { |
@@ -101,18 +104,20 @@ discard block |
||
101 | 104 | } |
102 | 105 | $smcFunc['db_free_result']($request); |
103 | 106 | |
104 | - if (!empty($boards)) |
|
105 | - $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
107 | + if (!empty($boards)) { |
|
108 | + $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
109 | + } |
|
106 | 110 | |
107 | 111 | // Try to limit the number of messages we look through. |
108 | - if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) |
|
109 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5); |
|
110 | - } |
|
111 | - elseif (!empty($_REQUEST['boards'])) |
|
112 | + if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) { |
|
113 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5); |
|
114 | + } |
|
115 | + } elseif (!empty($_REQUEST['boards'])) |
|
112 | 116 | { |
113 | 117 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
114 | - foreach ($_REQUEST['boards'] as $i => $b) |
|
115 | - $_REQUEST['boards'][$i] = (int) $b; |
|
118 | + foreach ($_REQUEST['boards'] as $i => $b) { |
|
119 | + $_REQUEST['boards'][$i] = (int) $b; |
|
120 | + } |
|
116 | 121 | |
117 | 122 | $request = $smcFunc['db_query']('', ' |
118 | 123 | SELECT b.id_board, b.num_posts, b.name |
@@ -128,29 +133,32 @@ discard block |
||
128 | 133 | |
129 | 134 | // Either the board specified doesn't exist or you have no access. |
130 | 135 | $num_boards = $smcFunc['db_num_rows']($request); |
131 | - if ($num_boards == 0) |
|
132 | - fatal_lang_error('no_board'); |
|
136 | + if ($num_boards == 0) { |
|
137 | + fatal_lang_error('no_board'); |
|
138 | + } |
|
133 | 139 | |
134 | 140 | $total_posts = 0; |
135 | 141 | $boards = array(); |
136 | 142 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
137 | 143 | { |
138 | - if ($num_boards == 1) |
|
139 | - $feed_meta['title'] = ' - ' . strip_tags($row['name']); |
|
144 | + if ($num_boards == 1) { |
|
145 | + $feed_meta['title'] = ' - ' . strip_tags($row['name']); |
|
146 | + } |
|
140 | 147 | |
141 | 148 | $boards[] = $row['id_board']; |
142 | 149 | $total_posts += $row['num_posts']; |
143 | 150 | } |
144 | 151 | $smcFunc['db_free_result']($request); |
145 | 152 | |
146 | - if (!empty($boards)) |
|
147 | - $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
153 | + if (!empty($boards)) { |
|
154 | + $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
155 | + } |
|
148 | 156 | |
149 | 157 | // The more boards, the more we're going to look through... |
150 | - if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) |
|
151 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5); |
|
152 | - } |
|
153 | - elseif (!empty($board)) |
|
158 | + if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) { |
|
159 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5); |
|
160 | + } |
|
161 | + } elseif (!empty($board)) |
|
154 | 162 | { |
155 | 163 | $request = $smcFunc['db_query']('', ' |
156 | 164 | SELECT num_posts |
@@ -170,10 +178,10 @@ discard block |
||
170 | 178 | $query_this_board = 'b.id_board = ' . $board; |
171 | 179 | |
172 | 180 | // Try to look through just a few messages, if at all possible. |
173 | - if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) |
|
174 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5); |
|
175 | - } |
|
176 | - else |
|
181 | + if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) { |
|
182 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5); |
|
183 | + } |
|
184 | + } else |
|
177 | 185 | { |
178 | 186 | $query_this_board = '{query_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' |
179 | 187 | AND b.id_board != ' . $modSettings['recycle_board'] : ''); |
@@ -196,30 +204,35 @@ discard block |
||
196 | 204 | // Easy adding of sub actions |
197 | 205 | call_integration_hook('integrate_xmlfeeds', array(&$subActions)); |
198 | 206 | |
199 | - if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) |
|
200 | - $_GET['sa'] = 'recent'; |
|
207 | + if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) { |
|
208 | + $_GET['sa'] = 'recent'; |
|
209 | + } |
|
201 | 210 | |
202 | 211 | // We only want some information, not all of it. |
203 | 212 | $cachekey = array($xml_format, $_GET['action'], $_GET['limit'], $_GET['sa']); |
204 | - foreach (array('board', 'boards', 'c') as $var) |
|
205 | - if (isset($_REQUEST[$var])) |
|
213 | + foreach (array('board', 'boards', 'c') as $var) { |
|
214 | + if (isset($_REQUEST[$var])) |
|
206 | 215 | $cachekey[] = $_REQUEST[$var]; |
216 | + } |
|
207 | 217 | $cachekey = md5($smcFunc['json_encode']($cachekey) . (!empty($query_this_board) ? $query_this_board : '')); |
208 | 218 | $cache_t = microtime(true); |
209 | 219 | |
210 | 220 | // Get the associative array representing the xml. |
211 | - if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) |
|
212 | - $xml_data = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240); |
|
221 | + if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) { |
|
222 | + $xml_data = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240); |
|
223 | + } |
|
213 | 224 | if (empty($xml_data)) |
214 | 225 | { |
215 | 226 | $call = call_helper($subActions[$_GET['sa']][0], true); |
216 | 227 | |
217 | - if (!empty($call)) |
|
218 | - $xml_data = call_user_func($call, $xml_format); |
|
228 | + if (!empty($call)) { |
|
229 | + $xml_data = call_user_func($call, $xml_format); |
|
230 | + } |
|
219 | 231 | |
220 | 232 | if (!empty($modSettings['cache_enable']) && (($user_info['is_guest'] && $modSettings['cache_enable'] >= 3) |
221 | - || (!$user_info['is_guest'] && (microtime(true) - $cache_t > 0.2)))) |
|
222 | - cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml_data, 240); |
|
233 | + || (!$user_info['is_guest'] && (microtime(true) - $cache_t > 0.2)))) { |
|
234 | + cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml_data, 240); |
|
235 | + } |
|
223 | 236 | } |
224 | 237 | |
225 | 238 | $feed_meta['title'] = $smcFunc['htmlspecialchars'](strip_tags($context['forum_name'])) . (isset($feed_meta['title']) ? $feed_meta['title'] : ''); |
@@ -259,43 +272,49 @@ discard block |
||
259 | 272 | call_integration_hook('integrate_xml_data', array(&$xml_data, &$feed_meta, &$namespaces, &$extraFeedTags, &$forceCdataKeys, &$nsKeys, $xml_format, $_GET['sa'])); |
260 | 273 | |
261 | 274 | // These can't be empty |
262 | - foreach (array('title', 'desc', 'source') as $mkey) |
|
263 | - $feed_meta[$mkey] = !empty($feed_meta[$mkey]) ? $feed_meta[$mkey] : $orig_feed_meta[$mkey]; |
|
275 | + foreach (array('title', 'desc', 'source') as $mkey) { |
|
276 | + $feed_meta[$mkey] = !empty($feed_meta[$mkey]) ? $feed_meta[$mkey] : $orig_feed_meta[$mkey]; |
|
277 | + } |
|
264 | 278 | |
265 | 279 | // Sanitize basic feed metadata values |
266 | - foreach ($feed_meta as $mkey => $mvalue) |
|
267 | - $feed_meta[$mkey] = cdata_parse(strip_tags(fix_possible_url($feed_meta[$mkey]))); |
|
280 | + foreach ($feed_meta as $mkey => $mvalue) { |
|
281 | + $feed_meta[$mkey] = cdata_parse(strip_tags(fix_possible_url($feed_meta[$mkey]))); |
|
282 | + } |
|
268 | 283 | |
269 | 284 | $ns_string = ''; |
270 | 285 | if (!empty($namespaces[$xml_format])) |
271 | 286 | { |
272 | - foreach ($namespaces[$xml_format] as $nsprefix => $nsurl) |
|
273 | - $ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"'; |
|
287 | + foreach ($namespaces[$xml_format] as $nsprefix => $nsurl) { |
|
288 | + $ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"'; |
|
289 | + } |
|
274 | 290 | } |
275 | 291 | |
276 | 292 | $extraFeedTags_string = ''; |
277 | 293 | if (!empty($extraFeedTags[$xml_format])) |
278 | 294 | { |
279 | 295 | $indent = "\t" . ($xml_format !== 'atom' ? "\t" : ''); |
280 | - foreach ($extraFeedTags[$xml_format] as $extraTag) |
|
281 | - $extraFeedTags_string .= "\n" . $indent . $extraTag; |
|
296 | + foreach ($extraFeedTags[$xml_format] as $extraTag) { |
|
297 | + $extraFeedTags_string .= "\n" . $indent . $extraTag; |
|
298 | + } |
|
282 | 299 | } |
283 | 300 | |
284 | 301 | // This is an xml file.... |
285 | 302 | ob_end_clean(); |
286 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
287 | - @ob_start('ob_gzhandler'); |
|
288 | - else |
|
289 | - ob_start(); |
|
303 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
304 | + @ob_start('ob_gzhandler'); |
|
305 | + } else { |
|
306 | + ob_start(); |
|
307 | + } |
|
290 | 308 | |
291 | - if ($xml_format == 'smf' || isset($_REQUEST['debug'])) |
|
292 | - header('content-type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
293 | - elseif ($xml_format == 'rss' || $xml_format == 'rss2') |
|
294 | - header('content-type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
295 | - elseif ($xml_format == 'atom') |
|
296 | - header('content-type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
297 | - elseif ($xml_format == 'rdf') |
|
298 | - header('content-type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
309 | + if ($xml_format == 'smf' || isset($_REQUEST['debug'])) { |
|
310 | + header('content-type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
311 | + } elseif ($xml_format == 'rss' || $xml_format == 'rss2') { |
|
312 | + header('content-type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
313 | + } elseif ($xml_format == 'atom') { |
|
314 | + header('content-type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
315 | + } elseif ($xml_format == 'rdf') { |
|
316 | + header('content-type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
317 | + } |
|
299 | 318 | |
300 | 319 | // First, output the xml header. |
301 | 320 | echo '<?xml version="1.0" encoding="', $context['character_set'], '"?' . '>'; |
@@ -303,10 +322,11 @@ discard block |
||
303 | 322 | // Are we outputting an rss feed or one with more information? |
304 | 323 | if ($xml_format == 'rss' || $xml_format == 'rss2') |
305 | 324 | { |
306 | - if ($xml_format == 'rss2') |
|
307 | - foreach ($_REQUEST as $var => $val) |
|
325 | + if ($xml_format == 'rss2') { |
|
326 | + foreach ($_REQUEST as $var => $val) |
|
308 | 327 | if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
309 | 328 | $url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val); |
329 | + } |
|
310 | 330 | |
311 | 331 | // Start with an RSS 2.0 header. |
312 | 332 | echo ' |
@@ -327,9 +347,10 @@ discard block |
||
327 | 347 | <language>' . $feed_meta['language'] . '</language>' : ''; |
328 | 348 | |
329 | 349 | // RSS2 calls for this. |
330 | - if ($xml_format == 'rss2') |
|
331 | - echo ' |
|
350 | + if ($xml_format == 'rss2') { |
|
351 | + echo ' |
|
332 | 352 | <atom:link rel="self" type="application/rss+xml" href="', $scripturl, !empty($url_parts) ? '?' . implode(';', $url_parts) : '', '" />'; |
353 | + } |
|
333 | 354 | |
334 | 355 | echo $extraFeedTags_string; |
335 | 356 | |
@@ -340,12 +361,12 @@ discard block |
||
340 | 361 | echo ' |
341 | 362 | </channel> |
342 | 363 | </rss>'; |
343 | - } |
|
344 | - elseif ($xml_format == 'atom') |
|
364 | + } elseif ($xml_format == 'atom') |
|
345 | 365 | { |
346 | - foreach ($_REQUEST as $var => $val) |
|
347 | - if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
|
366 | + foreach ($_REQUEST as $var => $val) { |
|
367 | + if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
|
348 | 368 | $url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val); |
369 | + } |
|
349 | 370 | |
350 | 371 | echo ' |
351 | 372 | <feed', $ns_string, !empty($feed_meta['language']) ? ' xml:lang="' . $feed_meta['language'] . '"' : '', '> |
@@ -371,8 +392,7 @@ discard block |
||
371 | 392 | |
372 | 393 | echo ' |
373 | 394 | </feed>'; |
374 | - } |
|
375 | - elseif ($xml_format == 'rdf') |
|
395 | + } elseif ($xml_format == 'rdf') |
|
376 | 396 | { |
377 | 397 | echo ' |
378 | 398 | <rdf:RDF', $ns_string, '> |
@@ -437,13 +457,15 @@ discard block |
||
437 | 457 | { |
438 | 458 | global $modSettings, $context, $scripturl; |
439 | 459 | |
440 | - if (substr($val, 0, strlen($scripturl)) != $scripturl) |
|
441 | - return $val; |
|
460 | + if (substr($val, 0, strlen($scripturl)) != $scripturl) { |
|
461 | + return $val; |
|
462 | + } |
|
442 | 463 | |
443 | 464 | call_integration_hook('integrate_fix_url', array(&$val)); |
444 | 465 | |
445 | - if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) |
|
446 | - return $val; |
|
466 | + if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) { |
|
467 | + return $val; |
|
468 | + } |
|
447 | 469 | |
448 | 470 | $val = preg_replace_callback('~\b' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?$~', function($m) use ($scripturl) |
449 | 471 | { |
@@ -466,8 +488,9 @@ discard block |
||
466 | 488 | global $smcFunc; |
467 | 489 | |
468 | 490 | // Do we even need to do this? |
469 | - if (strpbrk($data, '<>&') == false && $force !== true) |
|
470 | - return $data; |
|
491 | + if (strpbrk($data, '<>&') == false && $force !== true) { |
|
492 | + return $data; |
|
493 | + } |
|
471 | 494 | |
472 | 495 | $cdata = '<, |
478 | 501 | $smcFunc['strpos']($data, ']', $pos), |
479 | 502 | ); |
480 | - if ($ns != '') |
|
481 | - $positions[] = $smcFunc['strpos']($data, '<', $pos); |
|
503 | + if ($ns != '') { |
|
504 | + $positions[] = $smcFunc['strpos']($data, '<', $pos); |
|
505 | + } |
|
482 | 506 | foreach ($positions as $k => $dummy) |
483 | 507 | { |
484 | - if ($dummy === false) |
|
485 | - unset($positions[$k]); |
|
508 | + if ($dummy === false) { |
|
509 | + unset($positions[$k]); |
|
510 | + } |
|
486 | 511 | } |
487 | 512 | |
488 | 513 | $old = $pos; |
489 | 514 | $pos = empty($positions) ? $n : min($positions); |
490 | 515 | |
491 | - if ($pos - $old > 0) |
|
492 | - $cdata .= $smcFunc['substr']($data, $old, $pos - $old); |
|
493 | - if ($pos >= $n) |
|
494 | - break; |
|
516 | + if ($pos - $old > 0) { |
|
517 | + $cdata .= $smcFunc['substr']($data, $old, $pos - $old); |
|
518 | + } |
|
519 | + if ($pos >= $n) { |
|
520 | + break; |
|
521 | + } |
|
495 | 522 | |
496 | 523 | if ($smcFunc['substr']($data, $pos, 1) == '<') |
497 | 524 | { |
498 | 525 | $pos2 = $smcFunc['strpos']($data, '>', $pos); |
499 | - if ($pos2 === false) |
|
500 | - $pos2 = $n; |
|
501 | - if ($smcFunc['substr']($data, $pos + 1, 1) == '/') |
|
502 | - $cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA['; |
|
503 | - else |
|
504 | - $cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '< == '/') { |
|
530 | + $cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA['; |
|
531 | + } else { |
|
532 | + $cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '< == ']') |
|
535 | + } elseif ($smcFunc['substr']($data, $pos, 1) == ']') |
|
508 | 536 | { |
509 | 537 | $cdata .= ']]>]< == '&') |
|
539 | + } elseif ($smcFunc['substr']($data, $pos, 1) == '&') |
|
513 | 540 | { |
514 | 541 | $pos2 = $smcFunc['strpos']($data, ';', $pos); |
515 | - if ($pos2 === false) |
|
516 | - $pos2 = $n; |
|
542 | + if ($pos2 === false) { |
|
543 | + $pos2 = $n; |
|
544 | + } |
|
517 | 545 | $ent = $smcFunc['substr']($data, $pos + 1, $pos2 - $pos - 1); |
518 | 546 | |
519 | - if ($smcFunc['substr']($data, $pos + 1, 1) == '#') |
|
520 | - $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
521 | - elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) |
|
522 | - $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '< == '#') { |
|
548 | + $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
549 | + } elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) { |
|
550 | + $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
551 | + } |
|
523 | 552 | |
524 | 553 | $pos = $pos2 + 1; |
525 | 554 | } |
@@ -559,8 +588,9 @@ discard block |
||
559 | 588 | 'gender', |
560 | 589 | 'blurb', |
561 | 590 | ); |
562 | - if ($xml_format != 'atom') |
|
563 | - $keysToCdata[] = 'category'; |
|
591 | + if ($xml_format != 'atom') { |
|
592 | + $keysToCdata[] = 'category'; |
|
593 | + } |
|
564 | 594 | |
565 | 595 | if (!empty($forceCdataKeys)) |
566 | 596 | { |
@@ -577,8 +607,9 @@ discard block |
||
577 | 607 | $attrs = isset($element['attributes']) ? $element['attributes'] : null; |
578 | 608 | |
579 | 609 | // Skip it, it's been set to null. |
580 | - if ($key === null || ($val === null && $attrs === null)) |
|
581 | - continue; |
|
610 | + if ($key === null || ($val === null && $attrs === null)) { |
|
611 | + continue; |
|
612 | + } |
|
582 | 613 | |
583 | 614 | $forceCdata = in_array($key, $forceCdataKeys); |
584 | 615 | $ns = !empty($nsKeys[$key]) ? $nsKeys[$key] : ''; |
@@ -591,16 +622,16 @@ discard block |
||
591 | 622 | |
592 | 623 | if (!empty($attrs)) |
593 | 624 | { |
594 | - foreach ($attrs as $attr_key => $attr_value) |
|
595 | - echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"'; |
|
625 | + foreach ($attrs as $attr_key => $attr_value) { |
|
626 | + echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"'; |
|
627 | + } |
|
596 | 628 | } |
597 | 629 | |
598 | 630 | // If it's empty, simply output an empty element. |
599 | 631 | if (empty($val)) |
600 | 632 | { |
601 | 633 | echo ' />'; |
602 | - } |
|
603 | - else |
|
634 | + } else |
|
604 | 635 | { |
605 | 636 | echo '>'; |
606 | 637 | |
@@ -612,11 +643,13 @@ discard block |
||
612 | 643 | echo "\n", str_repeat("\t", $i); |
613 | 644 | } |
614 | 645 | // A string with returns in it.... show this as a multiline element. |
615 | - elseif (strpos($val, "\n") !== false) |
|
616 | - echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i); |
|
646 | + elseif (strpos($val, "\n") !== false) { |
|
647 | + echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i); |
|
648 | + } |
|
617 | 649 | // A simple string. |
618 | - else |
|
619 | - echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val); |
|
650 | + else { |
|
651 | + echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val); |
|
652 | + } |
|
620 | 653 | |
621 | 654 | // Ending tag. |
622 | 655 | echo '</', $key, '>'; |
@@ -636,8 +669,9 @@ discard block |
||
636 | 669 | { |
637 | 670 | global $scripturl, $smcFunc; |
638 | 671 | |
639 | - if (!allowedTo('view_mlist')) |
|
640 | - return array(); |
|
672 | + if (!allowedTo('view_mlist')) { |
|
673 | + return array(); |
|
674 | + } |
|
641 | 675 | |
642 | 676 | // Find the most recent members. |
643 | 677 | $request = $smcFunc['db_query']('', ' |
@@ -656,8 +690,8 @@ discard block |
||
656 | 690 | $guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['date_registered']) . ':member=' . $row['id_member']; |
657 | 691 | |
658 | 692 | // Make the data look rss-ish. |
659 | - if ($xml_format == 'rss' || $xml_format == 'rss2') |
|
660 | - $data[] = array( |
|
693 | + if ($xml_format == 'rss' || $xml_format == 'rss2') { |
|
694 | + $data[] = array( |
|
661 | 695 | 'tag' => 'item', |
662 | 696 | 'content' => array( |
663 | 697 | array( |
@@ -685,8 +719,8 @@ discard block |
||
685 | 719 | ), |
686 | 720 | ), |
687 | 721 | ); |
688 | - elseif ($xml_format == 'rdf') |
|
689 | - $data[] = array( |
|
722 | + } elseif ($xml_format == 'rdf') { |
|
723 | + $data[] = array( |
|
690 | 724 | 'tag' => 'item', |
691 | 725 | 'attributes' => array('rdf:about' => $scripturl . '?action=profile;u=' . $row['id_member']), |
692 | 726 | 'content' => array( |
@@ -704,8 +738,8 @@ discard block |
||
704 | 738 | ), |
705 | 739 | ), |
706 | 740 | ); |
707 | - elseif ($xml_format == 'atom') |
|
708 | - $data[] = array( |
|
741 | + } elseif ($xml_format == 'atom') { |
|
742 | + $data[] = array( |
|
709 | 743 | 'tag' => 'entry', |
710 | 744 | 'content' => array( |
711 | 745 | array( |
@@ -734,9 +768,10 @@ discard block |
||
734 | 768 | ), |
735 | 769 | ), |
736 | 770 | ); |
771 | + } |
|
737 | 772 | // More logical format for the data, but harder to apply. |
738 | - else |
|
739 | - $data[] = array( |
|
773 | + else { |
|
774 | + $data[] = array( |
|
740 | 775 | 'tag' => 'member', |
741 | 776 | 'content' => array( |
742 | 777 | array( |
@@ -757,6 +792,7 @@ discard block |
||
757 | 792 | ), |
758 | 793 | ), |
759 | 794 | ); |
795 | + } |
|
760 | 796 | } |
761 | 797 | $smcFunc['db_free_result']($request); |
762 | 798 | |
@@ -817,22 +853,24 @@ discard block |
||
817 | 853 | if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit']) |
818 | 854 | { |
819 | 855 | $smcFunc['db_free_result']($request); |
820 | - if (empty($_REQUEST['boards']) && empty($board)) |
|
821 | - unset($context['optimize_msg']['lowest']); |
|
822 | - else |
|
823 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg'; |
|
856 | + if (empty($_REQUEST['boards']) && empty($board)) { |
|
857 | + unset($context['optimize_msg']['lowest']); |
|
858 | + } else { |
|
859 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg'; |
|
860 | + } |
|
824 | 861 | $context['optimize_msg']['highest'] = 'm.id_msg <= t.id_last_msg'; |
825 | 862 | $loops++; |
863 | + } else { |
|
864 | + $done = true; |
|
826 | 865 | } |
827 | - else |
|
828 | - $done = true; |
|
829 | 866 | } |
830 | 867 | $data = array(); |
831 | 868 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
832 | 869 | { |
833 | 870 | // Limit the length of the message, if the option is set. |
834 | - if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) |
|
835 | - $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
871 | + if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) { |
|
872 | + $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
873 | + } |
|
836 | 874 | |
837 | 875 | $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
838 | 876 | |
@@ -859,8 +897,9 @@ discard block |
||
859 | 897 | while ($attach = $smcFunc['db_fetch_assoc']($attach_request)) |
860 | 898 | { |
861 | 899 | // Include approved attachments only |
862 | - if ($attach['approved']) |
|
863 | - $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
900 | + if ($attach['approved']) { |
|
901 | + $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
902 | + } |
|
864 | 903 | } |
865 | 904 | $smcFunc['db_free_result']($attach_request); |
866 | 905 | |
@@ -868,16 +907,17 @@ discard block |
||
868 | 907 | if (!empty($loaded_attachments)) |
869 | 908 | { |
870 | 909 | uasort($loaded_attachments, function($a, $b) { |
871 | - if ($a['filesize'] == $b['filesize']) |
|
872 | - return 0; |
|
910 | + if ($a['filesize'] == $b['filesize']) { |
|
911 | + return 0; |
|
912 | + } |
|
873 | 913 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
874 | 914 | }); |
915 | + } else { |
|
916 | + $loaded_attachments = null; |
|
875 | 917 | } |
876 | - else |
|
877 | - $loaded_attachments = null; |
|
918 | + } else { |
|
919 | + $loaded_attachments = null; |
|
878 | 920 | } |
879 | - else |
|
880 | - $loaded_attachments = null; |
|
881 | 921 | |
882 | 922 | // Create a GUID for this topic using the tag URI scheme |
883 | 923 | $guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['poster_time']) . ':topic=' . $row['id_topic']; |
@@ -894,9 +934,9 @@ discard block |
||
894 | 934 | 'length' => $attachment['filesize'], |
895 | 935 | 'type' => $attachment['mime_type'], |
896 | 936 | ); |
937 | + } else { |
|
938 | + $enclosure = null; |
|
897 | 939 | } |
898 | - else |
|
899 | - $enclosure = null; |
|
900 | 940 | |
901 | 941 | $data[] = array( |
902 | 942 | 'tag' => 'item', |
@@ -942,8 +982,7 @@ discard block |
||
942 | 982 | ), |
943 | 983 | ), |
944 | 984 | ); |
945 | - } |
|
946 | - elseif ($xml_format == 'rdf') |
|
985 | + } elseif ($xml_format == 'rdf') |
|
947 | 986 | { |
948 | 987 | $data[] = array( |
949 | 988 | 'tag' => 'item', |
@@ -967,8 +1006,7 @@ discard block |
||
967 | 1006 | ), |
968 | 1007 | ), |
969 | 1008 | ); |
970 | - } |
|
971 | - elseif ($xml_format == 'atom') |
|
1009 | + } elseif ($xml_format == 'atom') |
|
972 | 1010 | { |
973 | 1011 | // Only one attachment allowed |
974 | 1012 | if (!empty($loaded_attachments)) |
@@ -980,9 +1018,9 @@ discard block |
||
980 | 1018 | 'length' => $attachment['filesize'], |
981 | 1019 | 'type' => $attachment['mime_type'], |
982 | 1020 | ); |
1021 | + } else { |
|
1022 | + $enclosure = null; |
|
983 | 1023 | } |
984 | - else |
|
985 | - $enclosure = null; |
|
986 | 1024 | |
987 | 1025 | $data[] = array( |
988 | 1026 | 'tag' => 'entry', |
@@ -1082,9 +1120,9 @@ discard block |
||
1082 | 1120 | ) |
1083 | 1121 | ); |
1084 | 1122 | } |
1123 | + } else { |
|
1124 | + $attachments = null; |
|
1085 | 1125 | } |
1086 | - else |
|
1087 | - $attachments = null; |
|
1088 | 1126 | |
1089 | 1127 | $data[] = array( |
1090 | 1128 | 'tag' => 'article', |
@@ -1202,22 +1240,25 @@ discard block |
||
1202 | 1240 | if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit']) |
1203 | 1241 | { |
1204 | 1242 | $smcFunc['db_free_result']($request); |
1205 | - if (empty($_REQUEST['boards']) && empty($board)) |
|
1206 | - unset($context['optimize_msg']['lowest']); |
|
1207 | - else |
|
1208 | - $context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2'; |
|
1243 | + if (empty($_REQUEST['boards']) && empty($board)) { |
|
1244 | + unset($context['optimize_msg']['lowest']); |
|
1245 | + } else { |
|
1246 | + $context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2'; |
|
1247 | + } |
|
1209 | 1248 | $loops++; |
1249 | + } else { |
|
1250 | + $done = true; |
|
1210 | 1251 | } |
1211 | - else |
|
1212 | - $done = true; |
|
1213 | 1252 | } |
1214 | 1253 | $messages = array(); |
1215 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1216 | - $messages[] = $row['id_msg']; |
|
1254 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1255 | + $messages[] = $row['id_msg']; |
|
1256 | + } |
|
1217 | 1257 | $smcFunc['db_free_result']($request); |
1218 | 1258 | |
1219 | - if (empty($messages)) |
|
1220 | - return array(); |
|
1259 | + if (empty($messages)) { |
|
1260 | + return array(); |
|
1261 | + } |
|
1221 | 1262 | |
1222 | 1263 | // Find the most recent posts this user can see. |
1223 | 1264 | $request = $smcFunc['db_query']('', ' |
@@ -1247,8 +1288,9 @@ discard block |
||
1247 | 1288 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1248 | 1289 | { |
1249 | 1290 | // Limit the length of the message, if the option is set. |
1250 | - if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) |
|
1251 | - $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
1291 | + if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) { |
|
1292 | + $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
1293 | + } |
|
1252 | 1294 | |
1253 | 1295 | $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
1254 | 1296 | |
@@ -1275,8 +1317,9 @@ discard block |
||
1275 | 1317 | while ($attach = $smcFunc['db_fetch_assoc']($attach_request)) |
1276 | 1318 | { |
1277 | 1319 | // Include approved attachments only |
1278 | - if ($attach['approved']) |
|
1279 | - $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
1320 | + if ($attach['approved']) { |
|
1321 | + $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
1322 | + } |
|
1280 | 1323 | } |
1281 | 1324 | $smcFunc['db_free_result']($attach_request); |
1282 | 1325 | |
@@ -1284,16 +1327,17 @@ discard block |
||
1284 | 1327 | if (!empty($loaded_attachments)) |
1285 | 1328 | { |
1286 | 1329 | uasort($loaded_attachments, function($a, $b) { |
1287 | - if ($a['filesize'] == $b['filesize']) |
|
1288 | - return 0; |
|
1330 | + if ($a['filesize'] == $b['filesize']) { |
|
1331 | + return 0; |
|
1332 | + } |
|
1289 | 1333 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
1290 | 1334 | }); |
1335 | + } else { |
|
1336 | + $loaded_attachments = null; |
|
1291 | 1337 | } |
1292 | - else |
|
1293 | - $loaded_attachments = null; |
|
1338 | + } else { |
|
1339 | + $loaded_attachments = null; |
|
1294 | 1340 | } |
1295 | - else |
|
1296 | - $loaded_attachments = null; |
|
1297 | 1341 | |
1298 | 1342 | // Create a GUID for this post using the tag URI scheme |
1299 | 1343 | $guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['poster_time']) . ':msg=' . $row['id_msg']; |
@@ -1310,9 +1354,9 @@ discard block |
||
1310 | 1354 | 'length' => $attachment['filesize'], |
1311 | 1355 | 'type' => $attachment['mime_type'], |
1312 | 1356 | ); |
1357 | + } else { |
|
1358 | + $enclosure = null; |
|
1313 | 1359 | } |
1314 | - else |
|
1315 | - $enclosure = null; |
|
1316 | 1360 | |
1317 | 1361 | $data[] = array( |
1318 | 1362 | 'tag' => 'item', |
@@ -1358,8 +1402,7 @@ discard block |
||
1358 | 1402 | ), |
1359 | 1403 | ), |
1360 | 1404 | ); |
1361 | - } |
|
1362 | - elseif ($xml_format == 'rdf') |
|
1405 | + } elseif ($xml_format == 'rdf') |
|
1363 | 1406 | { |
1364 | 1407 | $data[] = array( |
1365 | 1408 | 'tag' => 'item', |
@@ -1383,8 +1426,7 @@ discard block |
||
1383 | 1426 | ), |
1384 | 1427 | ), |
1385 | 1428 | ); |
1386 | - } |
|
1387 | - elseif ($xml_format == 'atom') |
|
1429 | + } elseif ($xml_format == 'atom') |
|
1388 | 1430 | { |
1389 | 1431 | // Only one attachment allowed |
1390 | 1432 | if (!empty($loaded_attachments)) |
@@ -1396,9 +1438,9 @@ discard block |
||
1396 | 1438 | 'length' => $attachment['filesize'], |
1397 | 1439 | 'type' => $attachment['mime_type'], |
1398 | 1440 | ); |
1441 | + } else { |
|
1442 | + $enclosure = null; |
|
1399 | 1443 | } |
1400 | - else |
|
1401 | - $enclosure = null; |
|
1402 | 1444 | |
1403 | 1445 | $data[] = array( |
1404 | 1446 | 'tag' => 'entry', |
@@ -1498,9 +1540,9 @@ discard block |
||
1498 | 1540 | ) |
1499 | 1541 | ); |
1500 | 1542 | } |
1543 | + } else { |
|
1544 | + $attachments = null; |
|
1501 | 1545 | } |
1502 | - else |
|
1503 | - $attachments = null; |
|
1504 | 1546 | |
1505 | 1547 | $data[] = array( |
1506 | 1548 | 'tag' => 'recent-post', |
@@ -1619,14 +1661,16 @@ discard block |
||
1619 | 1661 | global $scripturl, $memberContext, $user_profile, $user_info; |
1620 | 1662 | |
1621 | 1663 | // You must input a valid user.... |
1622 | - if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) |
|
1623 | - return array(); |
|
1664 | + if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) { |
|
1665 | + return array(); |
|
1666 | + } |
|
1624 | 1667 | |
1625 | 1668 | // Make sure the id is a number and not "I like trying to hack the database". |
1626 | 1669 | $_GET['u'] = (int) $_GET['u']; |
1627 | 1670 | // Load the member's contextual information! |
1628 | - if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) |
|
1629 | - return array(); |
|
1671 | + if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) { |
|
1672 | + return array(); |
|
1673 | + } |
|
1630 | 1674 | |
1631 | 1675 | // Okay, I admit it, I'm lazy. Stupid $_GET['u'] is long and hard to type. |
1632 | 1676 | $profile = &$memberContext[$_GET['u']]; |
@@ -1668,8 +1712,7 @@ discard block |
||
1668 | 1712 | ), |
1669 | 1713 | ) |
1670 | 1714 | ); |
1671 | - } |
|
1672 | - elseif ($xml_format == 'rdf') |
|
1715 | + } elseif ($xml_format == 'rdf') |
|
1673 | 1716 | { |
1674 | 1717 | $data[] = array( |
1675 | 1718 | 'tag' => 'item', |
@@ -1693,8 +1736,7 @@ discard block |
||
1693 | 1736 | ), |
1694 | 1737 | ) |
1695 | 1738 | ); |
1696 | - } |
|
1697 | - elseif ($xml_format == 'atom') |
|
1739 | + } elseif ($xml_format == 'atom') |
|
1698 | 1740 | { |
1699 | 1741 | $data[] = array( |
1700 | 1742 | 'tag' => 'entry', |
@@ -1747,8 +1789,7 @@ discard block |
||
1747 | 1789 | ), |
1748 | 1790 | ) |
1749 | 1791 | ); |
1750 | - } |
|
1751 | - else |
|
1792 | + } else |
|
1752 | 1793 | { |
1753 | 1794 | $data = array( |
1754 | 1795 | array( |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Scheduled tasks management dispatcher. This function checks permissions and delegates |
@@ -41,10 +42,11 @@ discard block |
||
41 | 42 | ); |
42 | 43 | |
43 | 44 | // We need to find what's the action. |
44 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
45 | - $context['sub_action'] = $_REQUEST['sa']; |
|
46 | - else |
|
47 | - $context['sub_action'] = 'tasks'; |
|
45 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
46 | + $context['sub_action'] = $_REQUEST['sa']; |
|
47 | + } else { |
|
48 | + $context['sub_action'] = 'tasks'; |
|
49 | + } |
|
48 | 50 | |
49 | 51 | // Now for the lovely tabs. That we all love. |
50 | 52 | $context[$context['admin_menu_name']]['tab_data'] = array( |
@@ -94,9 +96,10 @@ discard block |
||
94 | 96 | |
95 | 97 | // Enable and disable as required. |
96 | 98 | $enablers = array(0); |
97 | - foreach ($_POST['enable_task'] as $id => $enabled) |
|
98 | - if ($enabled) |
|
99 | + foreach ($_POST['enable_task'] as $id => $enabled) { |
|
100 | + if ($enabled) |
|
99 | 101 | $enablers[] = (int) $id; |
102 | + } |
|
100 | 103 | |
101 | 104 | // Do the update! |
102 | 105 | $smcFunc['db_query']('', ' |
@@ -134,8 +137,9 @@ discard block |
||
134 | 137 | |
135 | 138 | // Lets figure out which ones they want to run. |
136 | 139 | $tasks = array(); |
137 | - foreach ($_POST['run_task'] as $task => $dummy) |
|
138 | - $tasks[] = (int) $task; |
|
140 | + foreach ($_POST['run_task'] as $task => $dummy) { |
|
141 | + $tasks[] = (int) $task; |
|
142 | + } |
|
139 | 143 | |
140 | 144 | // Load up the tasks. |
141 | 145 | $request = $smcFunc['db_query']('', ' |
@@ -155,36 +159,41 @@ discard block |
||
155 | 159 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
156 | 160 | { |
157 | 161 | // What kind of task are we handling? |
158 | - if (!empty($row['callable'])) |
|
159 | - $task_string = $row['callable']; |
|
162 | + if (!empty($row['callable'])) { |
|
163 | + $task_string = $row['callable']; |
|
164 | + } |
|
160 | 165 | |
161 | 166 | // Default SMF task or old mods? |
162 | - elseif (function_exists('scheduled_' . $row['task'])) |
|
163 | - $task_string = 'scheduled_' . $row['task']; |
|
167 | + elseif (function_exists('scheduled_' . $row['task'])) { |
|
168 | + $task_string = 'scheduled_' . $row['task']; |
|
169 | + } |
|
164 | 170 | |
165 | 171 | // One last resource, the task name. |
166 | - elseif (!empty($row['task'])) |
|
167 | - $task_string = $row['task']; |
|
172 | + elseif (!empty($row['task'])) { |
|
173 | + $task_string = $row['task']; |
|
174 | + } |
|
168 | 175 | |
169 | 176 | $start_time = microtime(true); |
170 | 177 | // The functions got to exist for us to use it. |
171 | - if (empty($task_string)) |
|
172 | - continue; |
|
178 | + if (empty($task_string)) { |
|
179 | + continue; |
|
180 | + } |
|
173 | 181 | |
174 | 182 | // Try to stop a timeout, this would be bad... |
175 | 183 | @set_time_limit(300); |
176 | - if (function_exists('apache_reset_timeout')) |
|
177 | - @apache_reset_timeout(); |
|
184 | + if (function_exists('apache_reset_timeout')) { |
|
185 | + @apache_reset_timeout(); |
|
186 | + } |
|
178 | 187 | |
179 | 188 | // Get the callable. |
180 | 189 | $callable_task = call_helper($task_string, true); |
181 | 190 | |
182 | 191 | // Perform the task. |
183 | - if (!empty($callable_task)) |
|
184 | - $completed = call_user_func($callable_task); |
|
185 | - |
|
186 | - else |
|
187 | - $completed = false; |
|
192 | + if (!empty($callable_task)) { |
|
193 | + $completed = call_user_func($callable_task); |
|
194 | + } else { |
|
195 | + $completed = false; |
|
196 | + } |
|
188 | 197 | |
189 | 198 | // Log that we did it ;) |
190 | 199 | if ($completed) |
@@ -201,8 +210,9 @@ discard block |
||
201 | 210 | $smcFunc['db_free_result']($request); |
202 | 211 | |
203 | 212 | // If we had any errors, push them to session so we can pick them up next time to tell the user. |
204 | - if (!empty($context['scheduled_errors'])) |
|
205 | - $_SESSION['st_error'] = $context['scheduled_errors']; |
|
213 | + if (!empty($context['scheduled_errors'])) { |
|
214 | + $_SESSION['st_error'] = $context['scheduled_errors']; |
|
215 | + } |
|
206 | 216 | |
207 | 217 | redirectexit('action=admin;area=scheduledtasks;done'); |
208 | 218 | } |
@@ -374,8 +384,9 @@ discard block |
||
374 | 384 | $context['server_time'] = timeformat(time(), false, 'server'); |
375 | 385 | |
376 | 386 | // Cleaning... |
377 | - if (!isset($_GET['tid'])) |
|
378 | - fatal_lang_error('no_access', false); |
|
387 | + if (!isset($_GET['tid'])) { |
|
388 | + fatal_lang_error('no_access', false); |
|
389 | + } |
|
379 | 390 | $_GET['tid'] = (int) $_GET['tid']; |
380 | 391 | |
381 | 392 | // Saving? |
@@ -391,10 +402,12 @@ discard block |
||
391 | 402 | preg_match('~(\d{1,2}):(\d{1,2})~', $_POST['offset'], $matches); |
392 | 403 | |
393 | 404 | // If a half is empty then assume zero offset! |
394 | - if (!isset($matches[2]) || $matches[2] > 59) |
|
395 | - $matches[2] = 0; |
|
396 | - if (!isset($matches[1]) || $matches[1] > 23) |
|
397 | - $matches[1] = 0; |
|
405 | + if (!isset($matches[2]) || $matches[2] > 59) { |
|
406 | + $matches[2] = 0; |
|
407 | + } |
|
408 | + if (!isset($matches[1]) || $matches[1] > 23) { |
|
409 | + $matches[1] = 0; |
|
410 | + } |
|
398 | 411 | |
399 | 412 | // Now the offset is easy; easy peasy - except we need to offset by a few hours... |
400 | 413 | $offset = $matches[1] * 3600 + $matches[2] * 60 - date('Z'); |
@@ -404,8 +417,9 @@ discard block |
||
404 | 417 | $unit = in_array(substr($_POST['unit'], 0, 1), array('m', 'h', 'd', 'w')) ? substr($_POST['unit'], 0, 1) : 'd'; |
405 | 418 | |
406 | 419 | // Don't allow one minute intervals. |
407 | - if ($interval == 1 && $unit == 'm') |
|
408 | - $interval = 2; |
|
420 | + if ($interval == 1 && $unit == 'm') { |
|
421 | + $interval = 2; |
|
422 | + } |
|
409 | 423 | |
410 | 424 | // Is it disabled? |
411 | 425 | $disabled = !isset($_POST['enabled']) ? 1 : 0; |
@@ -443,8 +457,9 @@ discard block |
||
443 | 457 | ); |
444 | 458 | |
445 | 459 | // Should never, ever, happen! |
446 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
447 | - fatal_lang_error('no_access', false); |
|
460 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
461 | + fatal_lang_error('no_access', false); |
|
462 | + } |
|
448 | 463 | |
449 | 464 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
450 | 465 | { |
@@ -602,13 +617,14 @@ discard block |
||
602 | 617 | ) |
603 | 618 | ); |
604 | 619 | $log_entries = array(); |
605 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
606 | - $log_entries[] = array( |
|
620 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
621 | + $log_entries[] = array( |
|
607 | 622 | 'id' => $row['id_log'], |
608 | 623 | 'name' => isset($txt['scheduled_task_' . $row['task']]) ? $txt['scheduled_task_' . $row['task']] : $row['task'], |
609 | 624 | 'time_run' => $row['time_run'], |
610 | 625 | 'time_taken' => $row['time_taken'], |
611 | 626 | ); |
627 | + } |
|
612 | 628 | $smcFunc['db_free_result']($request); |
613 | 629 | |
614 | 630 | return $log_entries; |
@@ -649,8 +665,9 @@ discard block |
||
649 | 665 | |
650 | 666 | call_integration_hook('integrate_scheduled_tasks_settings', array(&$config_vars)); |
651 | 667 | |
652 | - if ($return_config) |
|
653 | - return $config_vars; |
|
668 | + if ($return_config) { |
|
669 | + return $config_vars; |
|
670 | + } |
|
654 | 671 | |
655 | 672 | // Set up the template. |
656 | 673 | $context['page_title'] = $txt['scheduled_tasks_settings']; |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Load the $modSettings array. |
@@ -25,13 +26,14 @@ discard block |
||
25 | 26 | global $cache_enable, $sourcedir, $context; |
26 | 27 | |
27 | 28 | // Most database systems have not set UTF-8 as their default input charset. |
28 | - if (!empty($db_character_set)) |
|
29 | - $smcFunc['db_query']('', ' |
|
29 | + if (!empty($db_character_set)) { |
|
30 | + $smcFunc['db_query']('', ' |
|
30 | 31 | SET NAMES {string:db_character_set}', |
31 | 32 | array( |
32 | 33 | 'db_character_set' => $db_character_set, |
33 | 34 | ) |
34 | 35 | ); |
36 | + } |
|
35 | 37 | |
36 | 38 | // We need some caching support, maybe. |
37 | 39 | loadCacheAccelerator(); |
@@ -46,28 +48,36 @@ discard block |
||
46 | 48 | ) |
47 | 49 | ); |
48 | 50 | $modSettings = array(); |
49 | - if (!$request) |
|
50 | - display_db_error(); |
|
51 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
52 | - $modSettings[$row[0]] = $row[1]; |
|
51 | + if (!$request) { |
|
52 | + display_db_error(); |
|
53 | + } |
|
54 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
55 | + $modSettings[$row[0]] = $row[1]; |
|
56 | + } |
|
53 | 57 | $smcFunc['db_free_result']($request); |
54 | 58 | |
55 | 59 | // Do a few things to protect against missing settings or settings with invalid values... |
56 | - if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) |
|
57 | - $modSettings['defaultMaxTopics'] = 20; |
|
58 | - if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) |
|
59 | - $modSettings['defaultMaxMessages'] = 15; |
|
60 | - if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) |
|
61 | - $modSettings['defaultMaxMembers'] = 30; |
|
62 | - if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) |
|
63 | - $modSettings['defaultMaxListItems'] = 15; |
|
60 | + if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) { |
|
61 | + $modSettings['defaultMaxTopics'] = 20; |
|
62 | + } |
|
63 | + if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) { |
|
64 | + $modSettings['defaultMaxMessages'] = 15; |
|
65 | + } |
|
66 | + if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) { |
|
67 | + $modSettings['defaultMaxMembers'] = 30; |
|
68 | + } |
|
69 | + if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) { |
|
70 | + $modSettings['defaultMaxListItems'] = 15; |
|
71 | + } |
|
64 | 72 | |
65 | 73 | // We explicitly do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded. |
66 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
67 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
74 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
75 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
76 | + } |
|
68 | 77 | |
69 | - if (!empty($cache_enable)) |
|
70 | - cache_put_data('modSettings', $modSettings, 90); |
|
78 | + if (!empty($cache_enable)) { |
|
79 | + cache_put_data('modSettings', $modSettings, 90); |
|
80 | + } |
|
71 | 81 | } |
72 | 82 | |
73 | 83 | $modSettings['cache_enable'] = $cache_enable; |
@@ -87,8 +97,9 @@ discard block |
||
87 | 97 | }; |
88 | 98 | $fix_utf8mb4 = function($string) use ($utf8, $smcFunc) |
89 | 99 | { |
90 | - if (!$utf8 || $smcFunc['db_mb4']) |
|
91 | - return $string; |
|
100 | + if (!$utf8 || $smcFunc['db_mb4']) { |
|
101 | + return $string; |
|
102 | + } |
|
92 | 103 | |
93 | 104 | $i = 0; |
94 | 105 | $len = strlen($string); |
@@ -100,18 +111,15 @@ discard block |
||
100 | 111 | { |
101 | 112 | $new_string .= $string[$i]; |
102 | 113 | $i++; |
103 | - } |
|
104 | - elseif ($ord < 224) |
|
114 | + } elseif ($ord < 224) |
|
105 | 115 | { |
106 | 116 | $new_string .= $string[$i] . $string[$i + 1]; |
107 | 117 | $i += 2; |
108 | - } |
|
109 | - elseif ($ord < 240) |
|
118 | + } elseif ($ord < 240) |
|
110 | 119 | { |
111 | 120 | $new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2]; |
112 | 121 | $i += 3; |
113 | - } |
|
114 | - elseif ($ord < 248) |
|
122 | + } elseif ($ord < 248) |
|
115 | 123 | { |
116 | 124 | // Magic happens. |
117 | 125 | $val = (ord($string[$i]) & 0x07) << 18; |
@@ -155,8 +163,7 @@ discard block |
||
155 | 163 | { |
156 | 164 | $result = array_search($needle, array_slice($haystack_arr, $offset)); |
157 | 165 | return is_int($result) ? $result + $offset : false; |
158 | - } |
|
159 | - else |
|
166 | + } else |
|
160 | 167 | { |
161 | 168 | $needle_arr = preg_split('~(' . $ent_list . '|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
162 | 169 | $needle_size = count($needle_arr); |
@@ -165,8 +172,9 @@ discard block |
||
165 | 172 | while ((int) $result === $result) |
166 | 173 | { |
167 | 174 | $offset += $result; |
168 | - if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) |
|
169 | - return $offset; |
|
175 | + if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) { |
|
176 | + return $offset; |
|
177 | + } |
|
170 | 178 | $result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset)); |
171 | 179 | } |
172 | 180 | return false; |
@@ -204,8 +212,9 @@ discard block |
||
204 | 212 | $string = $ent_check($string); |
205 | 213 | preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches); |
206 | 214 | $string = $matches[0]; |
207 | - while (strlen($string) > $length) |
|
208 | - $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
215 | + while (strlen($string) > $length) { |
|
216 | + $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
217 | + } |
|
209 | 218 | return $string; |
210 | 219 | }, |
211 | 220 | 'ucfirst' => $utf8 ? function($string) use (&$smcFunc) |
@@ -215,8 +224,9 @@ discard block |
||
215 | 224 | 'ucwords' => $utf8 ? function($string) use (&$smcFunc) |
216 | 225 | { |
217 | 226 | $words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE); |
218 | - for ($i = 0, $n = count($words); $i < $n; $i += 2) |
|
219 | - $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
227 | + for ($i = 0, $n = count($words); $i < $n; $i += 2) { |
|
228 | + $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
229 | + } |
|
220 | 230 | return implode('', $words); |
221 | 231 | } : 'ucwords', |
222 | 232 | 'json_decode' => 'smf_json_decode', |
@@ -224,16 +234,17 @@ discard block |
||
224 | 234 | ); |
225 | 235 | |
226 | 236 | // Setting the timezone is a requirement for some functions. |
227 | - if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
|
228 | - date_default_timezone_set($modSettings['default_timezone']); |
|
229 | - else |
|
237 | + if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) { |
|
238 | + date_default_timezone_set($modSettings['default_timezone']); |
|
239 | + } else |
|
230 | 240 | { |
231 | 241 | // Get PHP's default timezone, if set |
232 | 242 | $ini_tz = ini_get('date.timezone'); |
233 | - if (!empty($ini_tz)) |
|
234 | - $modSettings['default_timezone'] = $ini_tz; |
|
235 | - else |
|
236 | - $modSettings['default_timezone'] = ''; |
|
243 | + if (!empty($ini_tz)) { |
|
244 | + $modSettings['default_timezone'] = $ini_tz; |
|
245 | + } else { |
|
246 | + $modSettings['default_timezone'] = ''; |
|
247 | + } |
|
237 | 248 | |
238 | 249 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
239 | 250 | if (!in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
@@ -251,22 +262,26 @@ discard block |
||
251 | 262 | if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null) |
252 | 263 | { |
253 | 264 | $modSettings['load_average'] = @file_get_contents('/proc/loadavg'); |
254 | - if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) |
|
255 | - $modSettings['load_average'] = (float) $matches[1]; |
|
256 | - elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) |
|
257 | - $modSettings['load_average'] = (float) $matches[1]; |
|
258 | - else |
|
259 | - unset($modSettings['load_average']); |
|
265 | + if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) { |
|
266 | + $modSettings['load_average'] = (float) $matches[1]; |
|
267 | + } elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) { |
|
268 | + $modSettings['load_average'] = (float) $matches[1]; |
|
269 | + } else { |
|
270 | + unset($modSettings['load_average']); |
|
271 | + } |
|
260 | 272 | |
261 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
262 | - cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
273 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
274 | + cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
275 | + } |
|
263 | 276 | } |
264 | 277 | |
265 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
266 | - call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
278 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
279 | + call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
280 | + } |
|
267 | 281 | |
268 | - if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) |
|
269 | - display_loadavg_error(); |
|
282 | + if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) { |
|
283 | + display_loadavg_error(); |
|
284 | + } |
|
270 | 285 | } |
271 | 286 | |
272 | 287 | // Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is. |
@@ -287,8 +302,9 @@ discard block |
||
287 | 302 | if (defined('SMF_INTEGRATION_SETTINGS')) |
288 | 303 | { |
289 | 304 | $integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true); |
290 | - foreach ($integration_settings as $hook => $function) |
|
291 | - add_integration_function($hook, $function, '', false); |
|
305 | + foreach ($integration_settings as $hook => $function) { |
|
306 | + add_integration_function($hook, $function, '', false); |
|
307 | + } |
|
292 | 308 | } |
293 | 309 | |
294 | 310 | // Any files to pre include? |
@@ -298,8 +314,9 @@ discard block |
||
298 | 314 | foreach ($pre_includes as $include) |
299 | 315 | { |
300 | 316 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
301 | - if (file_exists($include)) |
|
302 | - require_once($include); |
|
317 | + if (file_exists($include)) { |
|
318 | + require_once($include); |
|
319 | + } |
|
303 | 320 | } |
304 | 321 | } |
305 | 322 | |
@@ -410,9 +427,9 @@ discard block |
||
410 | 427 | break; |
411 | 428 | } |
412 | 429 | } |
430 | + } else { |
|
431 | + $id_member = 0; |
|
413 | 432 | } |
414 | - else |
|
415 | - $id_member = 0; |
|
416 | 433 | |
417 | 434 | if (empty($id_member) && isset($_COOKIE[$cookiename])) |
418 | 435 | { |
@@ -420,8 +437,9 @@ discard block |
||
420 | 437 | $cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false); |
421 | 438 | |
422 | 439 | // Legacy format (for recent 2.0 --> 2.1 upgrades) |
423 | - if (empty($cookie_data)) |
|
424 | - $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
440 | + if (empty($cookie_data)) { |
|
441 | + $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
442 | + } |
|
425 | 443 | |
426 | 444 | list($id_member, $password, $login_span, $cookie_domain, $cookie_path) = array_pad((array) $cookie_data, 5, ''); |
427 | 445 | |
@@ -429,16 +447,17 @@ discard block |
||
429 | 447 | |
430 | 448 | // Make sure the cookie is set to the correct domain and path |
431 | 449 | require_once($sourcedir . '/Subs-Auth.php'); |
432 | - if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']))) |
|
433 | - setLoginCookie((int) $login_span - time(), $id_member); |
|
434 | - } |
|
435 | - elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
450 | + if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']))) { |
|
451 | + setLoginCookie((int) $login_span - time(), $id_member); |
|
452 | + } |
|
453 | + } elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
436 | 454 | { |
437 | 455 | // @todo Perhaps we can do some more checking on this, such as on the first octet of the IP? |
438 | 456 | $cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename], true); |
439 | 457 | |
440 | - if (empty($cookie_data)) |
|
441 | - $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
458 | + if (empty($cookie_data)) { |
|
459 | + $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
460 | + } |
|
442 | 461 | |
443 | 462 | list($id_member, $password, $login_span) = array_pad((array) $cookie_data, 3, ''); |
444 | 463 | $id_member = !empty($id_member) && strlen($password) == 128 && (int) $login_span > time() ? (int) $id_member : 0; |
@@ -463,30 +482,34 @@ discard block |
||
463 | 482 | $user_settings = $smcFunc['db_fetch_assoc']($request); |
464 | 483 | $smcFunc['db_free_result']($request); |
465 | 484 | |
466 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) |
|
467 | - $user_settings['avatar'] = get_proxied_url($user_settings['avatar']); |
|
485 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) { |
|
486 | + $user_settings['avatar'] = get_proxied_url($user_settings['avatar']); |
|
487 | + } |
|
468 | 488 | |
469 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
470 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
489 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
490 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
491 | + } |
|
471 | 492 | } |
472 | 493 | |
473 | 494 | // Did we find 'im? If not, junk it. |
474 | 495 | if (!empty($user_settings)) |
475 | 496 | { |
476 | 497 | // As much as the password should be right, we can assume the integration set things up. |
477 | - if (!empty($already_verified) && $already_verified === true) |
|
478 | - $check = true; |
|
498 | + if (!empty($already_verified) && $already_verified === true) { |
|
499 | + $check = true; |
|
500 | + } |
|
479 | 501 | // SHA-512 hash should be 128 characters long. |
480 | - elseif (strlen($password) == 128) |
|
481 | - $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
482 | - else |
|
483 | - $check = false; |
|
502 | + elseif (strlen($password) == 128) { |
|
503 | + $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
504 | + } else { |
|
505 | + $check = false; |
|
506 | + } |
|
484 | 507 | |
485 | 508 | // Wrong password or not activated - either way, you're going nowhere. |
486 | 509 | $id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0; |
510 | + } else { |
|
511 | + $id_member = 0; |
|
487 | 512 | } |
488 | - else |
|
489 | - $id_member = 0; |
|
490 | 513 | |
491 | 514 | // If we no longer have the member maybe they're being all hackey, stop brute force! |
492 | 515 | if (!$id_member) |
@@ -515,8 +538,9 @@ discard block |
||
515 | 538 | |
516 | 539 | list ($tfamember, $tfasecret) = array_pad((array) $tfa_data, 2, ''); |
517 | 540 | |
518 | - if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) |
|
519 | - $tfasecret = null; |
|
541 | + if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) { |
|
542 | + $tfasecret = null; |
|
543 | + } |
|
520 | 544 | } |
521 | 545 | |
522 | 546 | // They didn't finish logging in before coming here? Then they're no one to us. |
@@ -538,10 +562,12 @@ discard block |
||
538 | 562 | // Are we forcing 2FA? Need to check if the user groups actually require 2FA |
539 | 563 | elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret'])) |
540 | 564 | { |
541 | - if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups |
|
565 | + if ($modSettings['tfa_mode'] == 2) { |
|
566 | + //only do this if we are just forcing SOME membergroups |
|
542 | 567 | { |
543 | 568 | //Build an array of ALL user membergroups. |
544 | 569 | $full_groups = array($user_settings['id_group']); |
570 | + } |
|
545 | 571 | if (!empty($user_settings['additional_groups'])) |
546 | 572 | { |
547 | 573 | $full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups'])); |
@@ -561,15 +587,17 @@ discard block |
||
561 | 587 | ); |
562 | 588 | $row = $smcFunc['db_fetch_assoc']($request); |
563 | 589 | $smcFunc['db_free_result']($request); |
590 | + } else { |
|
591 | + $row['total'] = 1; |
|
564 | 592 | } |
565 | - else |
|
566 | - $row['total'] = 1; //simplifies logics in the next "if" |
|
593 | + //simplifies logics in the next "if" |
|
567 | 594 | |
568 | 595 | $area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : ''; |
569 | 596 | $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : ''; |
570 | 597 | |
571 | - if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) |
|
572 | - redirectexit('action=profile;area=tfasetup;forced'); |
|
598 | + if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) { |
|
599 | + redirectexit('action=profile;area=tfasetup;forced'); |
|
600 | + } |
|
573 | 601 | } |
574 | 602 | } |
575 | 603 | |
@@ -606,29 +634,32 @@ discard block |
||
606 | 634 | updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'])); |
607 | 635 | $user_settings['last_login'] = time(); |
608 | 636 | |
609 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
610 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
637 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
638 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
639 | + } |
|
611 | 640 | |
612 | - if (!empty($modSettings['cache_enable'])) |
|
613 | - cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
641 | + if (!empty($modSettings['cache_enable'])) { |
|
642 | + cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
643 | + } |
|
614 | 644 | } |
645 | + } elseif (empty($_SESSION['id_msg_last_visit'])) { |
|
646 | + $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
615 | 647 | } |
616 | - elseif (empty($_SESSION['id_msg_last_visit'])) |
|
617 | - $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
618 | 648 | |
619 | 649 | $username = $user_settings['member_name']; |
620 | 650 | |
621 | - if (empty($user_settings['additional_groups'])) |
|
622 | - $user_info = array( |
|
651 | + if (empty($user_settings['additional_groups'])) { |
|
652 | + $user_info = array( |
|
623 | 653 | 'groups' => array($user_settings['id_group'], $user_settings['id_post_group']) |
624 | 654 | ); |
625 | - else |
|
626 | - $user_info = array( |
|
655 | + } else { |
|
656 | + $user_info = array( |
|
627 | 657 | 'groups' => array_merge( |
628 | 658 | array($user_settings['id_group'], $user_settings['id_post_group']), |
629 | 659 | explode(',', $user_settings['additional_groups']) |
630 | 660 | ) |
631 | 661 | ); |
662 | + } |
|
632 | 663 | |
633 | 664 | // Because history has proven that it is possible for groups to go bad - clean up in case. |
634 | 665 | $user_info['groups'] = array_map('intval', $user_info['groups']); |
@@ -645,8 +676,7 @@ discard block |
||
645 | 676 | $time_system = new DateTime('now', $tz_system); |
646 | 677 | $time_user = new DateTime('now', $tz_user); |
647 | 678 | $user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600; |
648 | - } |
|
649 | - else |
|
679 | + } else |
|
650 | 680 | { |
651 | 681 | // !!! Compatibility. |
652 | 682 | $user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset']; |
@@ -660,8 +690,9 @@ discard block |
||
660 | 690 | $user_info = array('groups' => array(-1)); |
661 | 691 | $user_settings = array(); |
662 | 692 | |
663 | - if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) |
|
664 | - $_COOKIE[$cookiename] = ''; |
|
693 | + if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) { |
|
694 | + $_COOKIE[$cookiename] = ''; |
|
695 | + } |
|
665 | 696 | |
666 | 697 | // Expire the 2FA cookie |
667 | 698 | if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member'])) |
@@ -678,19 +709,20 @@ discard block |
||
678 | 709 | } |
679 | 710 | |
680 | 711 | // Create a login token if it doesn't exist yet. |
681 | - if (!isset($_SESSION['token']['post-login'])) |
|
682 | - createToken('login'); |
|
683 | - else |
|
684 | - list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
712 | + if (!isset($_SESSION['token']['post-login'])) { |
|
713 | + createToken('login'); |
|
714 | + } else { |
|
715 | + list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
716 | + } |
|
685 | 717 | |
686 | 718 | // Do we perhaps think this is a search robot? Check every five minutes just in case... |
687 | 719 | if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300)) |
688 | 720 | { |
689 | 721 | require_once($sourcedir . '/ManageSearchEngines.php'); |
690 | 722 | $user_info['possibly_robot'] = SpiderCheck(); |
723 | + } elseif (!empty($modSettings['spider_mode'])) { |
|
724 | + $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
691 | 725 | } |
692 | - elseif (!empty($modSettings['spider_mode'])) |
|
693 | - $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
694 | 726 | // If we haven't turned on proper spider hunts then have a guess! |
695 | 727 | else |
696 | 728 | { |
@@ -747,8 +779,9 @@ discard block |
||
747 | 779 | $user_info['groups'] = array_unique($user_info['groups']); |
748 | 780 | |
749 | 781 | // Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems. |
750 | - if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) |
|
751 | - unset($user_info['ignoreboards'][$tmp]); |
|
782 | + if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) { |
|
783 | + unset($user_info['ignoreboards'][$tmp]); |
|
784 | + } |
|
752 | 785 | |
753 | 786 | // Allow the user to change their language. |
754 | 787 | if (!empty($modSettings['userLanguage'])) |
@@ -761,13 +794,14 @@ discard block |
||
761 | 794 | $user_info['language'] = strtr($_GET['language'], './\\:', '____'); |
762 | 795 | |
763 | 796 | // Make it permanent for members. |
764 | - if (!empty($user_info['id'])) |
|
765 | - updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
766 | - else |
|
767 | - $_SESSION['language'] = $user_info['language']; |
|
797 | + if (!empty($user_info['id'])) { |
|
798 | + updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
799 | + } else { |
|
800 | + $_SESSION['language'] = $user_info['language']; |
|
801 | + } |
|
802 | + } elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) { |
|
803 | + $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
768 | 804 | } |
769 | - elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) |
|
770 | - $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
771 | 805 | } |
772 | 806 | |
773 | 807 | $temp = build_query_board($user_info['id']); |
@@ -830,9 +864,9 @@ discard block |
||
830 | 864 | } |
831 | 865 | |
832 | 866 | // Remember redirection is the key to avoiding fallout from your bosses. |
833 | - if (!empty($topic)) |
|
834 | - redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
835 | - else |
|
867 | + if (!empty($topic)) { |
|
868 | + redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
869 | + } else |
|
836 | 870 | { |
837 | 871 | loadPermissions(); |
838 | 872 | loadTheme(); |
@@ -850,10 +884,11 @@ discard block |
||
850 | 884 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
851 | 885 | { |
852 | 886 | // @todo SLOW? |
853 | - if (!empty($topic)) |
|
854 | - $temp = cache_get_data('topic_board-' . $topic, 120); |
|
855 | - else |
|
856 | - $temp = cache_get_data('board-' . $board, 120); |
|
887 | + if (!empty($topic)) { |
|
888 | + $temp = cache_get_data('topic_board-' . $topic, 120); |
|
889 | + } else { |
|
890 | + $temp = cache_get_data('board-' . $board, 120); |
|
891 | + } |
|
857 | 892 | |
858 | 893 | if (!empty($temp)) |
859 | 894 | { |
@@ -891,8 +926,9 @@ discard block |
||
891 | 926 | $row = $smcFunc['db_fetch_assoc']($request); |
892 | 927 | |
893 | 928 | // Set the current board. |
894 | - if (!empty($row['id_board'])) |
|
895 | - $board = $row['id_board']; |
|
929 | + if (!empty($row['id_board'])) { |
|
930 | + $board = $row['id_board']; |
|
931 | + } |
|
896 | 932 | |
897 | 933 | // Basic operating information. (globals... :/) |
898 | 934 | $board_info = array( |
@@ -928,21 +964,23 @@ discard block |
||
928 | 964 | |
929 | 965 | do |
930 | 966 | { |
931 | - if (!empty($row['id_moderator'])) |
|
932 | - $board_info['moderators'][$row['id_moderator']] = array( |
|
967 | + if (!empty($row['id_moderator'])) { |
|
968 | + $board_info['moderators'][$row['id_moderator']] = array( |
|
933 | 969 | 'id' => $row['id_moderator'], |
934 | 970 | 'name' => $row['real_name'], |
935 | 971 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
936 | 972 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
937 | 973 | ); |
974 | + } |
|
938 | 975 | |
939 | - if (!empty($row['id_moderator_group'])) |
|
940 | - $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
976 | + if (!empty($row['id_moderator_group'])) { |
|
977 | + $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
941 | 978 | 'id' => $row['id_moderator_group'], |
942 | 979 | 'name' => $row['group_name'], |
943 | 980 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
944 | 981 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
945 | 982 | ); |
983 | + } |
|
946 | 984 | } |
947 | 985 | while ($row = $smcFunc['db_fetch_assoc']($request)); |
948 | 986 | |
@@ -974,12 +1012,12 @@ discard block |
||
974 | 1012 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
975 | 1013 | { |
976 | 1014 | // @todo SLOW? |
977 | - if (!empty($topic)) |
|
978 | - cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
1015 | + if (!empty($topic)) { |
|
1016 | + cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
1017 | + } |
|
979 | 1018 | cache_put_data('board-' . $board, $board_info, 120); |
980 | 1019 | } |
981 | - } |
|
982 | - else |
|
1020 | + } else |
|
983 | 1021 | { |
984 | 1022 | // Otherwise the topic is invalid, there are no moderators, etc. |
985 | 1023 | $board_info = array( |
@@ -993,8 +1031,9 @@ discard block |
||
993 | 1031 | $smcFunc['db_free_result']($request); |
994 | 1032 | } |
995 | 1033 | |
996 | - if (!empty($topic)) |
|
997 | - $_GET['board'] = (int) $board; |
|
1034 | + if (!empty($topic)) { |
|
1035 | + $_GET['board'] = (int) $board; |
|
1036 | + } |
|
998 | 1037 | |
999 | 1038 | if (!empty($board)) |
1000 | 1039 | { |
@@ -1004,10 +1043,12 @@ discard block |
||
1004 | 1043 | // Now check if the user is a moderator. |
1005 | 1044 | $user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0; |
1006 | 1045 | |
1007 | - if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) |
|
1008 | - $board_info['error'] = 'access'; |
|
1009 | - if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) |
|
1010 | - $board_info['error'] = 'access'; |
|
1046 | + if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) { |
|
1047 | + $board_info['error'] = 'access'; |
|
1048 | + } |
|
1049 | + if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) { |
|
1050 | + $board_info['error'] = 'access'; |
|
1051 | + } |
|
1011 | 1052 | |
1012 | 1053 | // Build up the linktree. |
1013 | 1054 | $context['linktree'] = array_merge( |
@@ -1030,8 +1071,9 @@ discard block |
||
1030 | 1071 | $context['current_board'] = $board; |
1031 | 1072 | |
1032 | 1073 | // No posting in redirection boards! |
1033 | - if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) |
|
1034 | - $board_info['error'] == 'post_in_redirect'; |
|
1074 | + if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) { |
|
1075 | + $board_info['error'] == 'post_in_redirect'; |
|
1076 | + } |
|
1035 | 1077 | |
1036 | 1078 | // Hacker... you can't see this topic, I'll tell you that. (but moderators can!) |
1037 | 1079 | if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod'])) |
@@ -1057,24 +1099,23 @@ discard block |
||
1057 | 1099 | ob_end_clean(); |
1058 | 1100 | send_http_status(403); |
1059 | 1101 | die; |
1060 | - } |
|
1061 | - elseif ($board_info['error'] == 'post_in_redirect') |
|
1102 | + } elseif ($board_info['error'] == 'post_in_redirect') |
|
1062 | 1103 | { |
1063 | 1104 | // Slightly different error message here... |
1064 | 1105 | fatal_lang_error('cannot_post_redirect', false); |
1065 | - } |
|
1066 | - elseif ($user_info['is_guest']) |
|
1106 | + } elseif ($user_info['is_guest']) |
|
1067 | 1107 | { |
1068 | 1108 | loadLanguage('Errors'); |
1069 | 1109 | is_not_guest($txt['topic_gone']); |
1110 | + } else { |
|
1111 | + fatal_lang_error('topic_gone', false); |
|
1070 | 1112 | } |
1071 | - else |
|
1072 | - fatal_lang_error('topic_gone', false); |
|
1073 | 1113 | } |
1074 | 1114 | |
1075 | - if ($user_info['is_mod']) |
|
1076 | - $user_info['groups'][] = 3; |
|
1077 | -} |
|
1115 | + if ($user_info['is_mod']) { |
|
1116 | + $user_info['groups'][] = 3; |
|
1117 | + } |
|
1118 | + } |
|
1078 | 1119 | |
1079 | 1120 | /** |
1080 | 1121 | * Load this user's permissions. |
@@ -1095,8 +1136,9 @@ discard block |
||
1095 | 1136 | asort($cache_groups); |
1096 | 1137 | $cache_groups = implode(',', $cache_groups); |
1097 | 1138 | // If it's a spider then cache it different. |
1098 | - if ($user_info['possibly_robot']) |
|
1099 | - $cache_groups .= '-spider'; |
|
1139 | + if ($user_info['possibly_robot']) { |
|
1140 | + $cache_groups .= '-spider'; |
|
1141 | + } |
|
1100 | 1142 | |
1101 | 1143 | if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
1102 | 1144 | { |
@@ -1104,9 +1146,9 @@ discard block |
||
1104 | 1146 | banPermissions(); |
1105 | 1147 | |
1106 | 1148 | return; |
1149 | + } elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) { |
|
1150 | + list ($user_info['permissions'], $removals) = $temp; |
|
1107 | 1151 | } |
1108 | - elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
|
1109 | - list ($user_info['permissions'], $removals) = $temp; |
|
1110 | 1152 | } |
1111 | 1153 | |
1112 | 1154 | // If it is detected as a robot, and we are restricting permissions as a special group - then implement this. |
@@ -1128,23 +1170,26 @@ discard block |
||
1128 | 1170 | $removals = array(); |
1129 | 1171 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1130 | 1172 | { |
1131 | - if (empty($row['add_deny'])) |
|
1132 | - $removals[] = $row['permission']; |
|
1133 | - else |
|
1134 | - $user_info['permissions'][] = $row['permission']; |
|
1173 | + if (empty($row['add_deny'])) { |
|
1174 | + $removals[] = $row['permission']; |
|
1175 | + } else { |
|
1176 | + $user_info['permissions'][] = $row['permission']; |
|
1177 | + } |
|
1135 | 1178 | } |
1136 | 1179 | $smcFunc['db_free_result']($request); |
1137 | 1180 | |
1138 | - if (isset($cache_groups)) |
|
1139 | - cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
1181 | + if (isset($cache_groups)) { |
|
1182 | + cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
1183 | + } |
|
1140 | 1184 | } |
1141 | 1185 | |
1142 | 1186 | // Get the board permissions. |
1143 | 1187 | if (!empty($board)) |
1144 | 1188 | { |
1145 | 1189 | // Make sure the board (if any) has been loaded by loadBoard(). |
1146 | - if (!isset($board_info['profile'])) |
|
1147 | - fatal_lang_error('no_board'); |
|
1190 | + if (!isset($board_info['profile'])) { |
|
1191 | + fatal_lang_error('no_board'); |
|
1192 | + } |
|
1148 | 1193 | |
1149 | 1194 | $request = $smcFunc['db_query']('', ' |
1150 | 1195 | SELECT permission, add_deny |
@@ -1160,20 +1205,23 @@ discard block |
||
1160 | 1205 | ); |
1161 | 1206 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1162 | 1207 | { |
1163 | - if (empty($row['add_deny'])) |
|
1164 | - $removals[] = $row['permission']; |
|
1165 | - else |
|
1166 | - $user_info['permissions'][] = $row['permission']; |
|
1208 | + if (empty($row['add_deny'])) { |
|
1209 | + $removals[] = $row['permission']; |
|
1210 | + } else { |
|
1211 | + $user_info['permissions'][] = $row['permission']; |
|
1212 | + } |
|
1167 | 1213 | } |
1168 | 1214 | $smcFunc['db_free_result']($request); |
1169 | 1215 | } |
1170 | 1216 | |
1171 | 1217 | // Remove all the permissions they shouldn't have ;). |
1172 | - if (!empty($modSettings['permission_enable_deny'])) |
|
1173 | - $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
1218 | + if (!empty($modSettings['permission_enable_deny'])) { |
|
1219 | + $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
1220 | + } |
|
1174 | 1221 | |
1175 | - if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) |
|
1176 | - cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
1222 | + if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) { |
|
1223 | + cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
1224 | + } |
|
1177 | 1225 | |
1178 | 1226 | // Banned? Watch, don't touch.. |
1179 | 1227 | banPermissions(); |
@@ -1185,17 +1233,18 @@ discard block |
||
1185 | 1233 | { |
1186 | 1234 | require_once($sourcedir . '/Subs-Auth.php'); |
1187 | 1235 | rebuildModCache(); |
1236 | + } else { |
|
1237 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
1188 | 1238 | } |
1189 | - else |
|
1190 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
1191 | 1239 | |
1192 | 1240 | // This is a useful phantom permission added to the current user, and only the current user while they are logged in. |
1193 | 1241 | // For example this drastically simplifies certain changes to the profile area. |
1194 | 1242 | $user_info['permissions'][] = 'is_not_guest'; |
1195 | 1243 | // And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions. |
1196 | 1244 | $user_info['permissions'][] = 'profile_view_own'; |
1197 | - if (in_array('profile_view', $user_info['permissions'])) |
|
1198 | - $user_info['permissions'][] = 'profile_view_any'; |
|
1245 | + if (in_array('profile_view', $user_info['permissions'])) { |
|
1246 | + $user_info['permissions'][] = 'profile_view_any'; |
|
1247 | + } |
|
1199 | 1248 | } |
1200 | 1249 | } |
1201 | 1250 | |
@@ -1213,8 +1262,9 @@ discard block |
||
1213 | 1262 | global $image_proxy_enabled, $user_info; |
1214 | 1263 | |
1215 | 1264 | // Can't just look for no users :P. |
1216 | - if (empty($users)) |
|
1217 | - return array(); |
|
1265 | + if (empty($users)) { |
|
1266 | + return array(); |
|
1267 | + } |
|
1218 | 1268 | |
1219 | 1269 | // Pass the set value |
1220 | 1270 | $context['loadMemberContext_set'] = $set; |
@@ -1229,8 +1279,9 @@ discard block |
||
1229 | 1279 | for ($i = 0, $n = count($users); $i < $n; $i++) |
1230 | 1280 | { |
1231 | 1281 | $data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240); |
1232 | - if ($data == null) |
|
1233 | - continue; |
|
1282 | + if ($data == null) { |
|
1283 | + continue; |
|
1284 | + } |
|
1234 | 1285 | |
1235 | 1286 | $loaded_ids[] = $data['id_member']; |
1236 | 1287 | $user_profile[$data['id_member']] = $data; |
@@ -1297,16 +1348,19 @@ discard block |
||
1297 | 1348 | $row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : ''; |
1298 | 1349 | |
1299 | 1350 | // Take care of proxying avatar if required, do this here for maximum reach |
1300 | - if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) |
|
1301 | - $row['avatar'] = get_proxied_url($row['avatar']); |
|
1351 | + if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) { |
|
1352 | + $row['avatar'] = get_proxied_url($row['avatar']); |
|
1353 | + } |
|
1302 | 1354 | |
1303 | 1355 | // Keep track of the member's normal member group |
1304 | 1356 | $row['primary_group'] = !empty($row['member_group']) ? $row['member_group'] : ''; |
1305 | 1357 | |
1306 | - if (isset($row['member_ip'])) |
|
1307 | - $row['member_ip'] = inet_dtop($row['member_ip']); |
|
1308 | - if (isset($row['member_ip2'])) |
|
1309 | - $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
1358 | + if (isset($row['member_ip'])) { |
|
1359 | + $row['member_ip'] = inet_dtop($row['member_ip']); |
|
1360 | + } |
|
1361 | + if (isset($row['member_ip2'])) { |
|
1362 | + $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
1363 | + } |
|
1310 | 1364 | $row['id_member'] = (int) $row['id_member']; |
1311 | 1365 | $new_loaded_ids[] = $row['id_member']; |
1312 | 1366 | $loaded_ids[] = $row['id_member']; |
@@ -1326,8 +1380,9 @@ discard block |
||
1326 | 1380 | 'loaded_ids' => $new_loaded_ids, |
1327 | 1381 | ) |
1328 | 1382 | ); |
1329 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1330 | - $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
1383 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1384 | + $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
1385 | + } |
|
1331 | 1386 | $smcFunc['db_free_result']($request); |
1332 | 1387 | } |
1333 | 1388 | |
@@ -1338,10 +1393,11 @@ discard block |
||
1338 | 1393 | { |
1339 | 1394 | foreach ($loaded_ids as $a_member) |
1340 | 1395 | { |
1341 | - if (!empty($user_profile[$a_member]['additional_groups'])) |
|
1342 | - $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
1343 | - else |
|
1344 | - $groups = array($user_profile[$a_member]['id_group']); |
|
1396 | + if (!empty($user_profile[$a_member]['additional_groups'])) { |
|
1397 | + $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
1398 | + } else { |
|
1399 | + $groups = array($user_profile[$a_member]['id_group']); |
|
1400 | + } |
|
1345 | 1401 | |
1346 | 1402 | $temp = array_intersect($groups, array_keys($board_info['moderator_groups'])); |
1347 | 1403 | |
@@ -1354,8 +1410,9 @@ discard block |
||
1354 | 1410 | |
1355 | 1411 | if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) |
1356 | 1412 | { |
1357 | - for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) |
|
1358 | - cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
1413 | + for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) { |
|
1414 | + cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
1415 | + } |
|
1359 | 1416 | } |
1360 | 1417 | |
1361 | 1418 | // Are we loading any moderators? If so, fix their group data... |
@@ -1381,14 +1438,17 @@ discard block |
||
1381 | 1438 | foreach ($temp_mods as $id) |
1382 | 1439 | { |
1383 | 1440 | // By popular demand, don't show admins or global moderators as moderators. |
1384 | - if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) |
|
1385 | - $user_profile[$id]['member_group'] = $row['member_group']; |
|
1441 | + if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) { |
|
1442 | + $user_profile[$id]['member_group'] = $row['member_group']; |
|
1443 | + } |
|
1386 | 1444 | |
1387 | 1445 | // If the Moderator group has no color or icons, but their group does... don't overwrite. |
1388 | - if (!empty($row['icons'])) |
|
1389 | - $user_profile[$id]['icons'] = $row['icons']; |
|
1390 | - if (!empty($row['member_group_color'])) |
|
1391 | - $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
1446 | + if (!empty($row['icons'])) { |
|
1447 | + $user_profile[$id]['icons'] = $row['icons']; |
|
1448 | + } |
|
1449 | + if (!empty($row['member_group_color'])) { |
|
1450 | + $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
1451 | + } |
|
1392 | 1452 | } |
1393 | 1453 | } |
1394 | 1454 | |
@@ -1410,12 +1470,14 @@ discard block |
||
1410 | 1470 | static $loadedLanguages = array(); |
1411 | 1471 | |
1412 | 1472 | // If this person's data is already loaded, skip it. |
1413 | - if (isset($dataLoaded[$user])) |
|
1414 | - return true; |
|
1473 | + if (isset($dataLoaded[$user])) { |
|
1474 | + return true; |
|
1475 | + } |
|
1415 | 1476 | |
1416 | 1477 | // We can't load guests or members not loaded by loadMemberData()! |
1417 | - if ($user == 0) |
|
1418 | - return false; |
|
1478 | + if ($user == 0) { |
|
1479 | + return false; |
|
1480 | + } |
|
1419 | 1481 | if (!isset($user_profile[$user])) |
1420 | 1482 | { |
1421 | 1483 | trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING); |
@@ -1441,12 +1503,16 @@ discard block |
||
1441 | 1503 | $buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array(); |
1442 | 1504 | |
1443 | 1505 | //We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme |
1444 | - if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists |
|
1506 | + if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) { |
|
1507 | + //icon is set and exists |
|
1445 | 1508 | $group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1]; |
1446 | - elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default |
|
1509 | + } elseif (isset($profile['icons'][1])) { |
|
1510 | + //icon is set and doesn't exist, fallback to default |
|
1447 | 1511 | $group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1]; |
1448 | - else //not set, bye bye |
|
1512 | + } else { |
|
1513 | + //not set, bye bye |
|
1449 | 1514 | $group_icon_url = ''; |
1515 | + } |
|
1450 | 1516 | |
1451 | 1517 | // These minimal values are always loaded |
1452 | 1518 | $memberContext[$user] = array( |
@@ -1465,8 +1531,9 @@ discard block |
||
1465 | 1531 | if ($context['loadMemberContext_set'] != 'minimal') |
1466 | 1532 | { |
1467 | 1533 | // Go the extra mile and load the user's native language name. |
1468 | - if (empty($loadedLanguages)) |
|
1469 | - $loadedLanguages = getLanguages(); |
|
1534 | + if (empty($loadedLanguages)) { |
|
1535 | + $loadedLanguages = getLanguages(); |
|
1536 | + } |
|
1470 | 1537 | |
1471 | 1538 | $memberContext[$user] += array( |
1472 | 1539 | 'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>', |
@@ -1521,31 +1588,33 @@ discard block |
||
1521 | 1588 | { |
1522 | 1589 | if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://'))) |
1523 | 1590 | { |
1524 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) |
|
1525 | - $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
1526 | - else |
|
1527 | - $image = get_gravatar_url($profile['email_address']); |
|
1528 | - } |
|
1529 | - else |
|
1591 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) { |
|
1592 | + $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
1593 | + } else { |
|
1594 | + $image = get_gravatar_url($profile['email_address']); |
|
1595 | + } |
|
1596 | + } else |
|
1530 | 1597 | { |
1531 | 1598 | // So it's stored in the member table? |
1532 | 1599 | if (!empty($profile['avatar'])) |
1533 | 1600 | { |
1534 | 1601 | $image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']; |
1602 | + } elseif (!empty($profile['filename'])) { |
|
1603 | + $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
1535 | 1604 | } |
1536 | - elseif (!empty($profile['filename'])) |
|
1537 | - $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
1538 | 1605 | // Right... no avatar...use the default one |
1539 | - else |
|
1540 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
1606 | + else { |
|
1607 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
1608 | + } |
|
1541 | 1609 | } |
1542 | - if (!empty($image)) |
|
1543 | - $memberContext[$user]['avatar'] = array( |
|
1610 | + if (!empty($image)) { |
|
1611 | + $memberContext[$user]['avatar'] = array( |
|
1544 | 1612 | 'name' => $profile['avatar'], |
1545 | 1613 | 'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">', |
1546 | 1614 | 'href' => $image, |
1547 | 1615 | 'url' => $image, |
1548 | 1616 | ); |
1617 | + } |
|
1549 | 1618 | } |
1550 | 1619 | |
1551 | 1620 | // Are we also loading the members custom fields into context? |
@@ -1553,13 +1622,15 @@ discard block |
||
1553 | 1622 | { |
1554 | 1623 | $memberContext[$user]['custom_fields'] = array(); |
1555 | 1624 | |
1556 | - if (!isset($context['display_fields'])) |
|
1557 | - $context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true); |
|
1625 | + if (!isset($context['display_fields'])) { |
|
1626 | + $context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true); |
|
1627 | + } |
|
1558 | 1628 | |
1559 | 1629 | foreach ($context['display_fields'] as $custom) |
1560 | 1630 | { |
1561 | - if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) |
|
1562 | - continue; |
|
1631 | + if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) { |
|
1632 | + continue; |
|
1633 | + } |
|
1563 | 1634 | |
1564 | 1635 | $value = $profile['options'][$custom['col_name']]; |
1565 | 1636 | |
@@ -1567,31 +1638,36 @@ discard block |
||
1567 | 1638 | $currentKey = 0; |
1568 | 1639 | |
1569 | 1640 | // Create a key => value array for multiple options fields |
1570 | - if (!empty($custom['options'])) |
|
1571 | - foreach ($custom['options'] as $k => $v) |
|
1641 | + if (!empty($custom['options'])) { |
|
1642 | + foreach ($custom['options'] as $k => $v) |
|
1572 | 1643 | { |
1573 | 1644 | $fieldOptions[] = $v; |
1574 | - if (empty($currentKey)) |
|
1575 | - $currentKey = $v == $value ? $k : 0; |
|
1645 | + } |
|
1646 | + if (empty($currentKey)) { |
|
1647 | + $currentKey = $v == $value ? $k : 0; |
|
1648 | + } |
|
1576 | 1649 | } |
1577 | 1650 | |
1578 | 1651 | // BBC? |
1579 | - if ($custom['bbc']) |
|
1580 | - $value = parse_bbc($value); |
|
1652 | + if ($custom['bbc']) { |
|
1653 | + $value = parse_bbc($value); |
|
1654 | + } |
|
1581 | 1655 | |
1582 | 1656 | // ... or checkbox? |
1583 | - elseif (isset($custom['type']) && $custom['type'] == 'check') |
|
1584 | - $value = $value ? $txt['yes'] : $txt['no']; |
|
1657 | + elseif (isset($custom['type']) && $custom['type'] == 'check') { |
|
1658 | + $value = $value ? $txt['yes'] : $txt['no']; |
|
1659 | + } |
|
1585 | 1660 | |
1586 | 1661 | // Enclosing the user input within some other text? |
1587 | - if (!empty($custom['enclose'])) |
|
1588 | - $value = strtr($custom['enclose'], array( |
|
1662 | + if (!empty($custom['enclose'])) { |
|
1663 | + $value = strtr($custom['enclose'], array( |
|
1589 | 1664 | '{SCRIPTURL}' => $scripturl, |
1590 | 1665 | '{IMAGES_URL}' => $settings['images_url'], |
1591 | 1666 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
1592 | 1667 | '{INPUT}' => $value, |
1593 | 1668 | '{KEY}' => $currentKey, |
1594 | 1669 | )); |
1670 | + } |
|
1595 | 1671 | |
1596 | 1672 | $memberContext[$user]['custom_fields'][] = array( |
1597 | 1673 | 'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'], |
@@ -1618,8 +1694,9 @@ discard block |
||
1618 | 1694 | global $smcFunc, $txt, $scripturl, $settings; |
1619 | 1695 | |
1620 | 1696 | // Do not waste my time... |
1621 | - if (empty($users) || empty($params)) |
|
1622 | - return false; |
|
1697 | + if (empty($users) || empty($params)) { |
|
1698 | + return false; |
|
1699 | + } |
|
1623 | 1700 | |
1624 | 1701 | // Make sure it's an array. |
1625 | 1702 | $users = !is_array($users) ? array($users) : array_unique($users); |
@@ -1646,41 +1723,48 @@ discard block |
||
1646 | 1723 | $currentKey = 0; |
1647 | 1724 | |
1648 | 1725 | // Create a key => value array for multiple options fields |
1649 | - if (!empty($row['field_options'])) |
|
1650 | - foreach (explode(',', $row['field_options']) as $k => $v) |
|
1726 | + if (!empty($row['field_options'])) { |
|
1727 | + foreach (explode(',', $row['field_options']) as $k => $v) |
|
1651 | 1728 | { |
1652 | 1729 | $fieldOptions[] = $v; |
1653 | - if (empty($currentKey)) |
|
1654 | - $currentKey = $v == $row['value'] ? $k : 0; |
|
1730 | + } |
|
1731 | + if (empty($currentKey)) { |
|
1732 | + $currentKey = $v == $row['value'] ? $k : 0; |
|
1733 | + } |
|
1655 | 1734 | } |
1656 | 1735 | |
1657 | 1736 | // BBC? |
1658 | - if (!empty($row['bbc'])) |
|
1659 | - $row['value'] = parse_bbc($row['value']); |
|
1737 | + if (!empty($row['bbc'])) { |
|
1738 | + $row['value'] = parse_bbc($row['value']); |
|
1739 | + } |
|
1660 | 1740 | |
1661 | 1741 | // ... or checkbox? |
1662 | - elseif (isset($row['type']) && $row['type'] == 'check') |
|
1663 | - $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
1742 | + elseif (isset($row['type']) && $row['type'] == 'check') { |
|
1743 | + $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
1744 | + } |
|
1664 | 1745 | |
1665 | 1746 | // Enclosing the user input within some other text? |
1666 | - if (!empty($row['enclose'])) |
|
1667 | - $row['value'] = strtr($row['enclose'], array( |
|
1747 | + if (!empty($row['enclose'])) { |
|
1748 | + $row['value'] = strtr($row['enclose'], array( |
|
1668 | 1749 | '{SCRIPTURL}' => $scripturl, |
1669 | 1750 | '{IMAGES_URL}' => $settings['images_url'], |
1670 | 1751 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
1671 | 1752 | '{INPUT}' => un_htmlspecialchars($row['value']), |
1672 | 1753 | '{KEY}' => $currentKey, |
1673 | 1754 | )); |
1755 | + } |
|
1674 | 1756 | |
1675 | 1757 | // Send a simple array if there is just 1 param |
1676 | - if (count($params) == 1) |
|
1677 | - $return[$row['id_member']] = $row; |
|
1758 | + if (count($params) == 1) { |
|
1759 | + $return[$row['id_member']] = $row; |
|
1760 | + } |
|
1678 | 1761 | |
1679 | 1762 | // More than 1? knock yourself out... |
1680 | 1763 | else |
1681 | 1764 | { |
1682 | - if (!isset($return[$row['id_member']])) |
|
1683 | - $return[$row['id_member']] = array(); |
|
1765 | + if (!isset($return[$row['id_member']])) { |
|
1766 | + $return[$row['id_member']] = array(); |
|
1767 | + } |
|
1684 | 1768 | |
1685 | 1769 | $return[$row['id_member']][$row['variable']] = $row; |
1686 | 1770 | } |
@@ -1714,8 +1798,9 @@ discard block |
||
1714 | 1798 | global $context; |
1715 | 1799 | |
1716 | 1800 | // Don't know any browser! |
1717 | - if (empty($context['browser'])) |
|
1718 | - detectBrowser(); |
|
1801 | + if (empty($context['browser'])) { |
|
1802 | + detectBrowser(); |
|
1803 | + } |
|
1719 | 1804 | |
1720 | 1805 | return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false; |
1721 | 1806 | } |
@@ -1733,8 +1818,9 @@ discard block |
||
1733 | 1818 | global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled; |
1734 | 1819 | |
1735 | 1820 | // The theme was specified by parameter. |
1736 | - if (!empty($id_theme)) |
|
1737 | - $id_theme = (int) $id_theme; |
|
1821 | + if (!empty($id_theme)) { |
|
1822 | + $id_theme = (int) $id_theme; |
|
1823 | + } |
|
1738 | 1824 | // The theme was specified by REQUEST. |
1739 | 1825 | elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
1740 | 1826 | { |
@@ -1742,32 +1828,38 @@ discard block |
||
1742 | 1828 | $_SESSION['id_theme'] = $id_theme; |
1743 | 1829 | } |
1744 | 1830 | // The theme was specified by REQUEST... previously. |
1745 | - elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
|
1746 | - $id_theme = (int) $_SESSION['id_theme']; |
|
1831 | + elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) { |
|
1832 | + $id_theme = (int) $_SESSION['id_theme']; |
|
1833 | + } |
|
1747 | 1834 | // The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.) |
1748 | - elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) |
|
1749 | - $id_theme = $user_info['theme']; |
|
1835 | + elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) { |
|
1836 | + $id_theme = $user_info['theme']; |
|
1837 | + } |
|
1750 | 1838 | // The theme was specified by the board. |
1751 | - elseif (!empty($board_info['theme'])) |
|
1752 | - $id_theme = $board_info['theme']; |
|
1839 | + elseif (!empty($board_info['theme'])) { |
|
1840 | + $id_theme = $board_info['theme']; |
|
1841 | + } |
|
1753 | 1842 | // The theme is the forum's default. |
1754 | - else |
|
1755 | - $id_theme = $modSettings['theme_guests']; |
|
1843 | + else { |
|
1844 | + $id_theme = $modSettings['theme_guests']; |
|
1845 | + } |
|
1756 | 1846 | |
1757 | 1847 | // Verify the id_theme... no foul play. |
1758 | 1848 | // Always allow the board specific theme, if they are overriding. |
1759 | - if (!empty($board_info['theme']) && $board_info['override_theme']) |
|
1760 | - $id_theme = $board_info['theme']; |
|
1849 | + if (!empty($board_info['theme']) && $board_info['override_theme']) { |
|
1850 | + $id_theme = $board_info['theme']; |
|
1851 | + } |
|
1761 | 1852 | // If they have specified a particular theme to use with SSI allow it to be used. |
1762 | - elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) |
|
1763 | - $id_theme = (int) $id_theme; |
|
1764 | - elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
1853 | + elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) { |
|
1854 | + $id_theme = (int) $id_theme; |
|
1855 | + } elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
1765 | 1856 | { |
1766 | 1857 | $themes = explode(',', $modSettings['enableThemes']); |
1767 | - if (!in_array($id_theme, $themes)) |
|
1768 | - $id_theme = $modSettings['theme_guests']; |
|
1769 | - else |
|
1770 | - $id_theme = (int) $id_theme; |
|
1858 | + if (!in_array($id_theme, $themes)) { |
|
1859 | + $id_theme = $modSettings['theme_guests']; |
|
1860 | + } else { |
|
1861 | + $id_theme = (int) $id_theme; |
|
1862 | + } |
|
1771 | 1863 | } |
1772 | 1864 | |
1773 | 1865 | // Allow mod authors the option to override the theme id for custom page themes |
@@ -1779,18 +1871,19 @@ discard block |
||
1779 | 1871 | $member = empty($user_info['id']) ? -1 : $user_info['id']; |
1780 | 1872 | |
1781 | 1873 | // Disable image proxy if we don't have SSL enabled |
1782 | - if (empty($modSettings['force_ssl'])) |
|
1783 | - $image_proxy_enabled = false; |
|
1874 | + if (empty($modSettings['force_ssl'])) { |
|
1875 | + $image_proxy_enabled = false; |
|
1876 | + } |
|
1784 | 1877 | |
1785 | 1878 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated']) |
1786 | 1879 | { |
1787 | 1880 | $themeData = $temp; |
1788 | 1881 | $flag = true; |
1882 | + } elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) { |
|
1883 | + $themeData = $temp + array($member => array()); |
|
1884 | + } else { |
|
1885 | + $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
1789 | 1886 | } |
1790 | - elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) |
|
1791 | - $themeData = $temp + array($member => array()); |
|
1792 | - else |
|
1793 | - $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
1794 | 1887 | |
1795 | 1888 | if (empty($flag)) |
1796 | 1889 | { |
@@ -1810,31 +1903,37 @@ discard block |
||
1810 | 1903 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
1811 | 1904 | { |
1812 | 1905 | // There are just things we shouldn't be able to change as members. |
1813 | - if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) |
|
1814 | - continue; |
|
1906 | + if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) { |
|
1907 | + continue; |
|
1908 | + } |
|
1815 | 1909 | |
1816 | 1910 | // If this is the theme_dir of the default theme, store it. |
1817 | - if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) |
|
1818 | - $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
1911 | + if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) { |
|
1912 | + $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
1913 | + } |
|
1819 | 1914 | |
1820 | 1915 | // If this isn't set yet, is a theme option, or is not the default theme.. |
1821 | - if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') |
|
1822 | - $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
1916 | + if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') { |
|
1917 | + $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
1918 | + } |
|
1823 | 1919 | } |
1824 | 1920 | $smcFunc['db_free_result']($result); |
1825 | 1921 | |
1826 | - if (!empty($themeData[-1])) |
|
1827 | - foreach ($themeData[-1] as $k => $v) |
|
1922 | + if (!empty($themeData[-1])) { |
|
1923 | + foreach ($themeData[-1] as $k => $v) |
|
1828 | 1924 | { |
1829 | 1925 | if (!isset($themeData[$member][$k])) |
1830 | 1926 | $themeData[$member][$k] = $v; |
1927 | + } |
|
1831 | 1928 | } |
1832 | 1929 | |
1833 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
1834 | - cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
1930 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
1931 | + cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
1932 | + } |
|
1835 | 1933 | // Only if we didn't already load that part of the cache... |
1836 | - elseif (!isset($temp)) |
|
1837 | - cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
1934 | + elseif (!isset($temp)) { |
|
1935 | + cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
1936 | + } |
|
1838 | 1937 | } |
1839 | 1938 | |
1840 | 1939 | $settings = $themeData[0]; |
@@ -1851,17 +1950,20 @@ discard block |
||
1851 | 1950 | $settings['template_dirs'][] = $settings['theme_dir']; |
1852 | 1951 | |
1853 | 1952 | // Based on theme (if there is one). |
1854 | - if (!empty($settings['base_theme_dir'])) |
|
1855 | - $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
1953 | + if (!empty($settings['base_theme_dir'])) { |
|
1954 | + $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
1955 | + } |
|
1856 | 1956 | |
1857 | 1957 | // Lastly the default theme. |
1858 | - if ($settings['theme_dir'] != $settings['default_theme_dir']) |
|
1859 | - $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
1958 | + if ($settings['theme_dir'] != $settings['default_theme_dir']) { |
|
1959 | + $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
1960 | + } |
|
1860 | 1961 | } |
1861 | 1962 | |
1862 | 1963 | |
1863 | - if (!$initialize) |
|
1864 | - return; |
|
1964 | + if (!$initialize) { |
|
1965 | + return; |
|
1966 | + } |
|
1865 | 1967 | |
1866 | 1968 | // Check to see if we're forcing SSL |
1867 | 1969 | if (!empty($modSettings['force_ssl']) && empty($maintenance) && |
@@ -1882,8 +1984,9 @@ discard block |
||
1882 | 1984 | $detected_url = httpsOn() ? 'https://' : 'http://'; |
1883 | 1985 | $detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']; |
1884 | 1986 | $temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')); |
1885 | - if ($temp != '/') |
|
1886 | - $detected_url .= $temp; |
|
1987 | + if ($temp != '/') { |
|
1988 | + $detected_url .= $temp; |
|
1989 | + } |
|
1887 | 1990 | } |
1888 | 1991 | if (isset($detected_url) && $detected_url != $boardurl) |
1889 | 1992 | { |
@@ -1895,8 +1998,9 @@ discard block |
||
1895 | 1998 | foreach ($aliases as $alias) |
1896 | 1999 | { |
1897 | 2000 | // Rip off all the boring parts, spaces, etc. |
1898 | - if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) |
|
1899 | - $do_fix = true; |
|
2001 | + if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) { |
|
2002 | + $do_fix = true; |
|
2003 | + } |
|
1900 | 2004 | } |
1901 | 2005 | } |
1902 | 2006 | |
@@ -1904,21 +2008,23 @@ discard block |
||
1904 | 2008 | if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI') |
1905 | 2009 | { |
1906 | 2010 | // Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;). |
1907 | - if (empty($_GET)) |
|
1908 | - redirectexit('wwwRedirect'); |
|
1909 | - else |
|
2011 | + if (empty($_GET)) { |
|
2012 | + redirectexit('wwwRedirect'); |
|
2013 | + } else |
|
1910 | 2014 | { |
1911 | 2015 | $k = key($_GET); |
1912 | 2016 | $v = current($_GET); |
1913 | 2017 | |
1914 | - if ($k != 'wwwRedirect') |
|
1915 | - redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
2018 | + if ($k != 'wwwRedirect') { |
|
2019 | + redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
2020 | + } |
|
1916 | 2021 | } |
1917 | 2022 | } |
1918 | 2023 | |
1919 | 2024 | // #3 is just a check for SSL... |
1920 | - if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) |
|
1921 | - $do_fix = true; |
|
2025 | + if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) { |
|
2026 | + $do_fix = true; |
|
2027 | + } |
|
1922 | 2028 | |
1923 | 2029 | // Okay, #4 - perhaps it's an IP address? We're gonna want to use that one, then. (assuming it's the IP or something...) |
1924 | 2030 | if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1) |
@@ -1953,8 +2059,9 @@ discard block |
||
1953 | 2059 | $board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl)); |
1954 | 2060 | } |
1955 | 2061 | } |
1956 | - foreach ($context['linktree'] as $k => $dummy) |
|
1957 | - $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
2062 | + foreach ($context['linktree'] as $k => $dummy) { |
|
2063 | + $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
2064 | + } |
|
1958 | 2065 | } |
1959 | 2066 | } |
1960 | 2067 | // Set up the contextual user array. |
@@ -1973,10 +2080,11 @@ discard block |
||
1973 | 2080 | 'email' => $user_info['email'], |
1974 | 2081 | 'ignoreusers' => $user_info['ignoreusers'], |
1975 | 2082 | ); |
1976 | - if (!$context['user']['is_guest']) |
|
1977 | - $context['user']['name'] = $user_info['name']; |
|
1978 | - elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) |
|
1979 | - $context['user']['name'] = $txt['guest_title']; |
|
2083 | + if (!$context['user']['is_guest']) { |
|
2084 | + $context['user']['name'] = $user_info['name']; |
|
2085 | + } elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) { |
|
2086 | + $context['user']['name'] = $txt['guest_title']; |
|
2087 | + } |
|
1980 | 2088 | |
1981 | 2089 | // Determine the current smiley set. |
1982 | 2090 | $smiley_sets_known = explode(',', $modSettings['smiley_sets_known']); |
@@ -1990,8 +2098,7 @@ discard block |
||
1990 | 2098 | |
1991 | 2099 | // Determine global default smiley set extension |
1992 | 2100 | $context['user']['smiley_set_default_ext'] = $smiley_sets_exts[array_search($modSettings['smiley_sets_default'], $smiley_sets_known)]; |
1993 | - } |
|
1994 | - else |
|
2101 | + } else |
|
1995 | 2102 | { |
1996 | 2103 | // What to do when there is no $user_info (e.g., an error very early in the login process) |
1997 | 2104 | $context['user'] = array( |
@@ -2025,18 +2132,24 @@ discard block |
||
2025 | 2132 | } |
2026 | 2133 | |
2027 | 2134 | // Some basic information... |
2028 | - if (!isset($context['html_headers'])) |
|
2029 | - $context['html_headers'] = ''; |
|
2030 | - if (!isset($context['javascript_files'])) |
|
2031 | - $context['javascript_files'] = array(); |
|
2032 | - if (!isset($context['css_files'])) |
|
2033 | - $context['css_files'] = array(); |
|
2034 | - if (!isset($context['css_header'])) |
|
2035 | - $context['css_header'] = array(); |
|
2036 | - if (!isset($context['javascript_inline'])) |
|
2037 | - $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
2038 | - if (!isset($context['javascript_vars'])) |
|
2039 | - $context['javascript_vars'] = array(); |
|
2135 | + if (!isset($context['html_headers'])) { |
|
2136 | + $context['html_headers'] = ''; |
|
2137 | + } |
|
2138 | + if (!isset($context['javascript_files'])) { |
|
2139 | + $context['javascript_files'] = array(); |
|
2140 | + } |
|
2141 | + if (!isset($context['css_files'])) { |
|
2142 | + $context['css_files'] = array(); |
|
2143 | + } |
|
2144 | + if (!isset($context['css_header'])) { |
|
2145 | + $context['css_header'] = array(); |
|
2146 | + } |
|
2147 | + if (!isset($context['javascript_inline'])) { |
|
2148 | + $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
2149 | + } |
|
2150 | + if (!isset($context['javascript_vars'])) { |
|
2151 | + $context['javascript_vars'] = array(); |
|
2152 | + } |
|
2040 | 2153 | |
2041 | 2154 | $context['login_url'] = $scripturl . '?action=login2'; |
2042 | 2155 | $context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | '; |
@@ -2048,16 +2161,18 @@ discard block |
||
2048 | 2161 | $context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null; |
2049 | 2162 | $context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null; |
2050 | 2163 | $context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3; |
2051 | - if (isset($modSettings['load_average'])) |
|
2052 | - $context['load_average'] = $modSettings['load_average']; |
|
2164 | + if (isset($modSettings['load_average'])) { |
|
2165 | + $context['load_average'] = $modSettings['load_average']; |
|
2166 | + } |
|
2053 | 2167 | |
2054 | 2168 | // Detect the browser. This is separated out because it's also used in attachment downloads |
2055 | 2169 | detectBrowser(); |
2056 | 2170 | |
2057 | 2171 | // Set the top level linktree up. |
2058 | 2172 | // Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet... |
2059 | - if (empty($context['linktree'])) |
|
2060 | - $context['linktree'] = array(); |
|
2173 | + if (empty($context['linktree'])) { |
|
2174 | + $context['linktree'] = array(); |
|
2175 | + } |
|
2061 | 2176 | array_unshift($context['linktree'], array( |
2062 | 2177 | 'url' => $scripturl, |
2063 | 2178 | 'name' => $context['forum_name_html_safe'] |
@@ -2066,8 +2181,9 @@ discard block |
||
2066 | 2181 | // This allows sticking some HTML on the page output - useful for controls. |
2067 | 2182 | $context['insert_after_template'] = ''; |
2068 | 2183 | |
2069 | - if (!isset($txt)) |
|
2070 | - $txt = array(); |
|
2184 | + if (!isset($txt)) { |
|
2185 | + $txt = array(); |
|
2186 | + } |
|
2071 | 2187 | |
2072 | 2188 | $simpleActions = array( |
2073 | 2189 | 'findmember', |
@@ -2113,9 +2229,10 @@ discard block |
||
2113 | 2229 | |
2114 | 2230 | // See if theres any extra param to check. |
2115 | 2231 | $requiresXML = false; |
2116 | - foreach ($extraParams as $key => $extra) |
|
2117 | - if (isset($_REQUEST[$extra])) |
|
2232 | + foreach ($extraParams as $key => $extra) { |
|
2233 | + if (isset($_REQUEST[$extra])) |
|
2118 | 2234 | $requiresXML = true; |
2235 | + } |
|
2119 | 2236 | |
2120 | 2237 | // Output is fully XML, so no need for the index template. |
2121 | 2238 | if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML)) |
@@ -2130,37 +2247,39 @@ discard block |
||
2130 | 2247 | { |
2131 | 2248 | loadLanguage('index+Modifications'); |
2132 | 2249 | $context['template_layers'] = array(); |
2133 | - } |
|
2134 | - |
|
2135 | - else |
|
2250 | + } else |
|
2136 | 2251 | { |
2137 | 2252 | // Custom templates to load, or just default? |
2138 | - if (isset($settings['theme_templates'])) |
|
2139 | - $templates = explode(',', $settings['theme_templates']); |
|
2140 | - else |
|
2141 | - $templates = array('index'); |
|
2253 | + if (isset($settings['theme_templates'])) { |
|
2254 | + $templates = explode(',', $settings['theme_templates']); |
|
2255 | + } else { |
|
2256 | + $templates = array('index'); |
|
2257 | + } |
|
2142 | 2258 | |
2143 | 2259 | // Load each template... |
2144 | - foreach ($templates as $template) |
|
2145 | - loadTemplate($template); |
|
2260 | + foreach ($templates as $template) { |
|
2261 | + loadTemplate($template); |
|
2262 | + } |
|
2146 | 2263 | |
2147 | 2264 | // ...and attempt to load their associated language files. |
2148 | 2265 | $required_files = implode('+', array_merge($templates, array('Modifications'))); |
2149 | 2266 | loadLanguage($required_files, '', false); |
2150 | 2267 | |
2151 | 2268 | // Custom template layers? |
2152 | - if (isset($settings['theme_layers'])) |
|
2153 | - $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
2154 | - else |
|
2155 | - $context['template_layers'] = array('html', 'body'); |
|
2269 | + if (isset($settings['theme_layers'])) { |
|
2270 | + $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
2271 | + } else { |
|
2272 | + $context['template_layers'] = array('html', 'body'); |
|
2273 | + } |
|
2156 | 2274 | } |
2157 | 2275 | |
2158 | 2276 | // Initialize the theme. |
2159 | 2277 | loadSubTemplate('init', 'ignore'); |
2160 | 2278 | |
2161 | 2279 | // Allow overriding the board wide time/number formats. |
2162 | - if (empty($user_settings['time_format']) && !empty($txt['time_format'])) |
|
2163 | - $user_info['time_format'] = $txt['time_format']; |
|
2280 | + if (empty($user_settings['time_format']) && !empty($txt['time_format'])) { |
|
2281 | + $user_info['time_format'] = $txt['time_format']; |
|
2282 | + } |
|
2164 | 2283 | |
2165 | 2284 | // Set the character set from the template. |
2166 | 2285 | $context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']; |
@@ -2168,12 +2287,14 @@ discard block |
||
2168 | 2287 | $context['right_to_left'] = !empty($txt['lang_rtl']); |
2169 | 2288 | |
2170 | 2289 | // Guests may still need a name. |
2171 | - if ($context['user']['is_guest'] && empty($context['user']['name'])) |
|
2172 | - $context['user']['name'] = $txt['guest_title']; |
|
2290 | + if ($context['user']['is_guest'] && empty($context['user']['name'])) { |
|
2291 | + $context['user']['name'] = $txt['guest_title']; |
|
2292 | + } |
|
2173 | 2293 | |
2174 | 2294 | // Any theme-related strings that need to be loaded? |
2175 | - if (!empty($settings['require_theme_strings'])) |
|
2176 | - loadLanguage('ThemeStrings', '', false); |
|
2295 | + if (!empty($settings['require_theme_strings'])) { |
|
2296 | + loadLanguage('ThemeStrings', '', false); |
|
2297 | + } |
|
2177 | 2298 | |
2178 | 2299 | // Make a special URL for the language. |
2179 | 2300 | $settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']); |
@@ -2184,8 +2305,9 @@ discard block |
||
2184 | 2305 | // Here is my luvly Responsive CSS |
2185 | 2306 | loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true, 'order_pos' => 9000), 'smf_responsive'); |
2186 | 2307 | |
2187 | - if ($context['right_to_left']) |
|
2188 | - loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl'); |
|
2308 | + if ($context['right_to_left']) { |
|
2309 | + loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl'); |
|
2310 | + } |
|
2189 | 2311 | |
2190 | 2312 | // We allow theme variants, because we're cool. |
2191 | 2313 | $context['theme_variant'] = ''; |
@@ -2193,14 +2315,17 @@ discard block |
||
2193 | 2315 | if (!empty($settings['theme_variants'])) |
2194 | 2316 | { |
2195 | 2317 | // Overriding - for previews and that ilk. |
2196 | - if (!empty($_REQUEST['variant'])) |
|
2197 | - $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
2318 | + if (!empty($_REQUEST['variant'])) { |
|
2319 | + $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
2320 | + } |
|
2198 | 2321 | // User selection? |
2199 | - if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) |
|
2200 | - $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
2322 | + if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) { |
|
2323 | + $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
2324 | + } |
|
2201 | 2325 | // If not a user variant, select the default. |
2202 | - if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) |
|
2203 | - $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
2326 | + if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) { |
|
2327 | + $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
2328 | + } |
|
2204 | 2329 | |
2205 | 2330 | // Do this to keep things easier in the templates. |
2206 | 2331 | $context['theme_variant'] = '_' . $context['theme_variant']; |
@@ -2209,20 +2334,23 @@ discard block |
||
2209 | 2334 | if (!empty($context['theme_variant'])) |
2210 | 2335 | { |
2211 | 2336 | loadCSSFile('index' . $context['theme_variant'] . '.css', array('order_pos' => 300), 'smf_index' . $context['theme_variant']); |
2212 | - if ($context['right_to_left']) |
|
2213 | - loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']); |
|
2337 | + if ($context['right_to_left']) { |
|
2338 | + loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']); |
|
2339 | + } |
|
2214 | 2340 | } |
2215 | 2341 | } |
2216 | 2342 | |
2217 | 2343 | // Let's be compatible with old themes! |
2218 | - if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) |
|
2219 | - $context['template_layers'] = array('main'); |
|
2344 | + if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) { |
|
2345 | + $context['template_layers'] = array('main'); |
|
2346 | + } |
|
2220 | 2347 | |
2221 | 2348 | $context['tabindex'] = 1; |
2222 | 2349 | |
2223 | 2350 | // Compatibility. |
2224 | - if (!isset($settings['theme_version'])) |
|
2225 | - $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
2351 | + if (!isset($settings['theme_version'])) { |
|
2352 | + $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
2353 | + } |
|
2226 | 2354 | |
2227 | 2355 | // Default JS variables for use in every theme |
2228 | 2356 | $context['javascript_vars'] = array( |
@@ -2245,18 +2373,18 @@ discard block |
||
2245 | 2373 | ); |
2246 | 2374 | |
2247 | 2375 | // Add the JQuery library to the list of files to load. |
2248 | - if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') |
|
2249 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2250 | - |
|
2251 | - elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') |
|
2252 | - loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery'); |
|
2253 | - |
|
2254 | - elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') |
|
2255 | - loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
2376 | + if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') { |
|
2377 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2378 | + } elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') { |
|
2379 | + loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery'); |
|
2380 | + } elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') { |
|
2381 | + loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
2382 | + } |
|
2256 | 2383 | |
2257 | 2384 | // Auto loading? template_javascript() will take care of the local half of this. |
2258 | - else |
|
2259 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2385 | + else { |
|
2386 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2387 | + } |
|
2260 | 2388 | |
2261 | 2389 | // Queue our JQuery plugins! |
2262 | 2390 | loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins'); |
@@ -2279,12 +2407,12 @@ discard block |
||
2279 | 2407 | require_once($sourcedir . '/ScheduledTasks.php'); |
2280 | 2408 | |
2281 | 2409 | // What to do, what to do?! |
2282 | - if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) |
|
2283 | - AutoTask(); |
|
2284 | - else |
|
2285 | - ReduceMailQueue(); |
|
2286 | - } |
|
2287 | - else |
|
2410 | + if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) { |
|
2411 | + AutoTask(); |
|
2412 | + } else { |
|
2413 | + ReduceMailQueue(); |
|
2414 | + } |
|
2415 | + } else |
|
2288 | 2416 | { |
2289 | 2417 | $type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq'; |
2290 | 2418 | $ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time']; |
@@ -2335,8 +2463,9 @@ discard block |
||
2335 | 2463 | foreach ($theme_includes as $include) |
2336 | 2464 | { |
2337 | 2465 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
2338 | - if (file_exists($include)) |
|
2339 | - require_once($include); |
|
2466 | + if (file_exists($include)) { |
|
2467 | + require_once($include); |
|
2468 | + } |
|
2340 | 2469 | } |
2341 | 2470 | } |
2342 | 2471 | |
@@ -2366,16 +2495,19 @@ discard block |
||
2366 | 2495 | // Do any style sheets first, cause we're easy with those. |
2367 | 2496 | if (!empty($style_sheets)) |
2368 | 2497 | { |
2369 | - if (!is_array($style_sheets)) |
|
2370 | - $style_sheets = array($style_sheets); |
|
2498 | + if (!is_array($style_sheets)) { |
|
2499 | + $style_sheets = array($style_sheets); |
|
2500 | + } |
|
2371 | 2501 | |
2372 | - foreach ($style_sheets as $sheet) |
|
2373 | - loadCSSFile($sheet . '.css', array(), $sheet); |
|
2502 | + foreach ($style_sheets as $sheet) { |
|
2503 | + loadCSSFile($sheet . '.css', array(), $sheet); |
|
2504 | + } |
|
2374 | 2505 | } |
2375 | 2506 | |
2376 | 2507 | // No template to load? |
2377 | - if ($template_name === false) |
|
2378 | - return true; |
|
2508 | + if ($template_name === false) { |
|
2509 | + return true; |
|
2510 | + } |
|
2379 | 2511 | |
2380 | 2512 | $loaded = false; |
2381 | 2513 | foreach ($settings['template_dirs'] as $template_dir) |
@@ -2390,12 +2522,14 @@ discard block |
||
2390 | 2522 | |
2391 | 2523 | if ($loaded) |
2392 | 2524 | { |
2393 | - if ($db_show_debug === true) |
|
2394 | - $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
2525 | + if ($db_show_debug === true) { |
|
2526 | + $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
2527 | + } |
|
2395 | 2528 | |
2396 | 2529 | // If they have specified an initialization function for this template, go ahead and call it now. |
2397 | - if (function_exists('template_' . $template_name . '_init')) |
|
2398 | - call_user_func('template_' . $template_name . '_init'); |
|
2530 | + if (function_exists('template_' . $template_name . '_init')) { |
|
2531 | + call_user_func('template_' . $template_name . '_init'); |
|
2532 | + } |
|
2399 | 2533 | } |
2400 | 2534 | // Hmmm... doesn't exist?! I don't suppose the directory is wrong, is it? |
2401 | 2535 | elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default')) |
@@ -2415,13 +2549,14 @@ discard block |
||
2415 | 2549 | loadTemplate($template_name); |
2416 | 2550 | } |
2417 | 2551 | // Cause an error otherwise. |
2418 | - elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) |
|
2419 | - fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
2420 | - elseif ($fatal) |
|
2421 | - die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template')); |
|
2422 | - else |
|
2423 | - return false; |
|
2424 | -} |
|
2552 | + elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) { |
|
2553 | + fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
2554 | + } elseif ($fatal) { |
|
2555 | + die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template')); |
|
2556 | + } else { |
|
2557 | + return false; |
|
2558 | + } |
|
2559 | + } |
|
2425 | 2560 | |
2426 | 2561 | /** |
2427 | 2562 | * Load a sub-template. |
@@ -2439,17 +2574,19 @@ discard block |
||
2439 | 2574 | { |
2440 | 2575 | global $context, $txt, $db_show_debug; |
2441 | 2576 | |
2442 | - if ($db_show_debug === true) |
|
2443 | - $context['debug']['sub_templates'][] = $sub_template_name; |
|
2577 | + if ($db_show_debug === true) { |
|
2578 | + $context['debug']['sub_templates'][] = $sub_template_name; |
|
2579 | + } |
|
2444 | 2580 | |
2445 | 2581 | // Figure out what the template function is named. |
2446 | 2582 | $theme_function = 'template_' . $sub_template_name; |
2447 | - if (function_exists($theme_function)) |
|
2448 | - $theme_function(); |
|
2449 | - elseif ($fatal === false) |
|
2450 | - fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
2451 | - elseif ($fatal !== 'ignore') |
|
2452 | - die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template')); |
|
2583 | + if (function_exists($theme_function)) { |
|
2584 | + $theme_function(); |
|
2585 | + } elseif ($fatal === false) { |
|
2586 | + fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
2587 | + } elseif ($fatal !== 'ignore') { |
|
2588 | + die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template')); |
|
2589 | + } |
|
2453 | 2590 | |
2454 | 2591 | // Are we showing debugging for templates? Just make sure not to do it before the doctype... |
2455 | 2592 | if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml'])) |
@@ -2479,8 +2616,9 @@ discard block |
||
2479 | 2616 | { |
2480 | 2617 | global $settings, $context, $modSettings; |
2481 | 2618 | |
2482 | - if (empty($context['css_files_order'])) |
|
2483 | - $context['css_files_order'] = array(); |
|
2619 | + if (empty($context['css_files_order'])) { |
|
2620 | + $context['css_files_order'] = array(); |
|
2621 | + } |
|
2484 | 2622 | |
2485 | 2623 | $params['seed'] = (!array_key_exists('seed', $params) || (array_key_exists('seed', $params) && $params['seed'] === true)) ? (array_key_exists('browser_cache', $modSettings) ? $modSettings['browser_cache'] : '') : (is_string($params['seed']) ? ($params['seed'] = $params['seed'][0] === '?' ? $params['seed'] : '?' . $params['seed']) : ''); |
2486 | 2624 | $params['force_current'] = isset($params['force_current']) ? $params['force_current'] : false; |
@@ -2491,8 +2629,9 @@ discard block |
||
2491 | 2629 | $params['order_pos'] = isset($params['order_pos']) ? (int) $params['order_pos'] : 3000; |
2492 | 2630 | |
2493 | 2631 | // If this is an external file, automatically set this to false. |
2494 | - if (!empty($params['external'])) |
|
2495 | - $params['minimize'] = false; |
|
2632 | + if (!empty($params['external'])) { |
|
2633 | + $params['minimize'] = false; |
|
2634 | + } |
|
2496 | 2635 | |
2497 | 2636 | // Account for shorthand like admin.css?alp21 filenames |
2498 | 2637 | $has_seed = strpos($fileName, '.css?'); |
@@ -2509,16 +2648,12 @@ discard block |
||
2509 | 2648 | { |
2510 | 2649 | $fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2511 | 2650 | $filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2512 | - } |
|
2513 | - |
|
2514 | - else |
|
2651 | + } else |
|
2515 | 2652 | { |
2516 | 2653 | $fileUrl = false; |
2517 | 2654 | $filePath = false; |
2518 | 2655 | } |
2519 | - } |
|
2520 | - |
|
2521 | - else |
|
2656 | + } else |
|
2522 | 2657 | { |
2523 | 2658 | $fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2524 | 2659 | $filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2536,16 +2671,18 @@ discard block |
||
2536 | 2671 | if (!empty($fileName)) |
2537 | 2672 | { |
2538 | 2673 | // find a free number/position |
2539 | - while (isset($context['css_files_order'][$params['order_pos']])) |
|
2540 | - $params['order_pos']++; |
|
2674 | + while (isset($context['css_files_order'][$params['order_pos']])) { |
|
2675 | + $params['order_pos']++; |
|
2676 | + } |
|
2541 | 2677 | $context['css_files_order'][$params['order_pos']] = $id; |
2542 | 2678 | |
2543 | 2679 | $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
2544 | 2680 | } |
2545 | 2681 | |
2546 | - if (!empty($context['right_to_left']) && !empty($params['rtl'])) |
|
2547 | - loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
2548 | -} |
|
2682 | + if (!empty($context['right_to_left']) && !empty($params['rtl'])) { |
|
2683 | + loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
2684 | + } |
|
2685 | + } |
|
2549 | 2686 | |
2550 | 2687 | /** |
2551 | 2688 | * Add a block of inline css code to be executed later |
@@ -2562,8 +2699,9 @@ discard block |
||
2562 | 2699 | global $context; |
2563 | 2700 | |
2564 | 2701 | // Gotta add something... |
2565 | - if (empty($css)) |
|
2566 | - return false; |
|
2702 | + if (empty($css)) { |
|
2703 | + return false; |
|
2704 | + } |
|
2567 | 2705 | |
2568 | 2706 | $context['css_header'][] = $css; |
2569 | 2707 | } |
@@ -2599,8 +2737,9 @@ discard block |
||
2599 | 2737 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
2600 | 2738 | |
2601 | 2739 | // If this is an external file, automatically set this to false. |
2602 | - if (!empty($params['external'])) |
|
2603 | - $params['minimize'] = false; |
|
2740 | + if (!empty($params['external'])) { |
|
2741 | + $params['minimize'] = false; |
|
2742 | + } |
|
2604 | 2743 | |
2605 | 2744 | // Account for shorthand like admin.js?alp21 filenames |
2606 | 2745 | $has_seed = strpos($fileName, '.js?'); |
@@ -2617,16 +2756,12 @@ discard block |
||
2617 | 2756 | { |
2618 | 2757 | $fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2619 | 2758 | $filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2620 | - } |
|
2621 | - |
|
2622 | - else |
|
2759 | + } else |
|
2623 | 2760 | { |
2624 | 2761 | $fileUrl = false; |
2625 | 2762 | $filePath = false; |
2626 | 2763 | } |
2627 | - } |
|
2628 | - |
|
2629 | - else |
|
2764 | + } else |
|
2630 | 2765 | { |
2631 | 2766 | $fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2632 | 2767 | $filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2641,9 +2776,10 @@ discard block |
||
2641 | 2776 | } |
2642 | 2777 | |
2643 | 2778 | // Add it to the array for use in the template |
2644 | - if (!empty($fileName)) |
|
2645 | - $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2646 | -} |
|
2779 | + if (!empty($fileName)) { |
|
2780 | + $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2781 | + } |
|
2782 | + } |
|
2647 | 2783 | |
2648 | 2784 | /** |
2649 | 2785 | * Add a Javascript variable for output later (for feeding text strings and similar to JS) |
@@ -2657,9 +2793,10 @@ discard block |
||
2657 | 2793 | { |
2658 | 2794 | global $context; |
2659 | 2795 | |
2660 | - if (!empty($key) && (!empty($value) || $value === '0')) |
|
2661 | - $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
2662 | -} |
|
2796 | + if (!empty($key) && (!empty($value) || $value === '0')) { |
|
2797 | + $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
2798 | + } |
|
2799 | + } |
|
2663 | 2800 | |
2664 | 2801 | /** |
2665 | 2802 | * Add a block of inline Javascript code to be executed later |
@@ -2676,8 +2813,9 @@ discard block |
||
2676 | 2813 | { |
2677 | 2814 | global $context; |
2678 | 2815 | |
2679 | - if (empty($javascript)) |
|
2680 | - return false; |
|
2816 | + if (empty($javascript)) { |
|
2817 | + return false; |
|
2818 | + } |
|
2681 | 2819 | |
2682 | 2820 | $context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript; |
2683 | 2821 | } |
@@ -2698,15 +2836,18 @@ discard block |
||
2698 | 2836 | static $already_loaded = array(); |
2699 | 2837 | |
2700 | 2838 | // Default to the user's language. |
2701 | - if ($lang == '') |
|
2702 | - $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
2839 | + if ($lang == '') { |
|
2840 | + $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
2841 | + } |
|
2703 | 2842 | |
2704 | 2843 | // Do we want the English version of language file as fallback? |
2705 | - if (empty($modSettings['disable_language_fallback']) && $lang != 'english') |
|
2706 | - loadLanguage($template_name, 'english', false); |
|
2844 | + if (empty($modSettings['disable_language_fallback']) && $lang != 'english') { |
|
2845 | + loadLanguage($template_name, 'english', false); |
|
2846 | + } |
|
2707 | 2847 | |
2708 | - if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) |
|
2709 | - return $lang; |
|
2848 | + if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) { |
|
2849 | + return $lang; |
|
2850 | + } |
|
2710 | 2851 | |
2711 | 2852 | // Make sure we have $settings - if not we're in trouble and need to find it! |
2712 | 2853 | if (empty($settings['default_theme_dir'])) |
@@ -2717,8 +2858,9 @@ discard block |
||
2717 | 2858 | |
2718 | 2859 | // What theme are we in? |
2719 | 2860 | $theme_name = basename($settings['theme_url']); |
2720 | - if (empty($theme_name)) |
|
2721 | - $theme_name = 'unknown'; |
|
2861 | + if (empty($theme_name)) { |
|
2862 | + $theme_name = 'unknown'; |
|
2863 | + } |
|
2722 | 2864 | |
2723 | 2865 | // For each file open it up and write it out! |
2724 | 2866 | foreach (explode('+', $template_name) as $template) |
@@ -2760,8 +2902,9 @@ discard block |
||
2760 | 2902 | $found = true; |
2761 | 2903 | |
2762 | 2904 | // setlocale is required for basename() & pathinfo() to work properly on the selected language |
2763 | - if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) |
|
2764 | - setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
2905 | + if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) { |
|
2906 | + setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
2907 | + } |
|
2765 | 2908 | |
2766 | 2909 | break; |
2767 | 2910 | } |
@@ -2801,8 +2944,9 @@ discard block |
||
2801 | 2944 | } |
2802 | 2945 | |
2803 | 2946 | // Keep track of what we're up to soldier. |
2804 | - if ($db_show_debug === true) |
|
2805 | - $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
2947 | + if ($db_show_debug === true) { |
|
2948 | + $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
2949 | + } |
|
2806 | 2950 | |
2807 | 2951 | // Remember what we have loaded, and in which language. |
2808 | 2952 | $already_loaded[$template_name] = $lang; |
@@ -2848,8 +2992,9 @@ discard block |
||
2848 | 2992 | ) |
2849 | 2993 | ); |
2850 | 2994 | // In the EXTREMELY unlikely event this happens, give an error message. |
2851 | - if ($smcFunc['db_num_rows']($result) == 0) |
|
2852 | - fatal_lang_error('parent_not_found', 'critical'); |
|
2995 | + if ($smcFunc['db_num_rows']($result) == 0) { |
|
2996 | + fatal_lang_error('parent_not_found', 'critical'); |
|
2997 | + } |
|
2853 | 2998 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
2854 | 2999 | { |
2855 | 3000 | if (!isset($boards[$row['id_board']])) |
@@ -2866,8 +3011,8 @@ discard block |
||
2866 | 3011 | ); |
2867 | 3012 | } |
2868 | 3013 | // If a moderator exists for this board, add that moderator for all children too. |
2869 | - if (!empty($row['id_moderator'])) |
|
2870 | - foreach ($boards as $id => $dummy) |
|
3014 | + if (!empty($row['id_moderator'])) { |
|
3015 | + foreach ($boards as $id => $dummy) |
|
2871 | 3016 | { |
2872 | 3017 | $boards[$id]['moderators'][$row['id_moderator']] = array( |
2873 | 3018 | 'id' => $row['id_moderator'], |
@@ -2875,11 +3020,12 @@ discard block |
||
2875 | 3020 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
2876 | 3021 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
2877 | 3022 | ); |
3023 | + } |
|
2878 | 3024 | } |
2879 | 3025 | |
2880 | 3026 | // If a moderator group exists for this board, add that moderator group for all children too |
2881 | - if (!empty($row['id_moderator_group'])) |
|
2882 | - foreach ($boards as $id => $dummy) |
|
3027 | + if (!empty($row['id_moderator_group'])) { |
|
3028 | + foreach ($boards as $id => $dummy) |
|
2883 | 3029 | { |
2884 | 3030 | $boards[$id]['moderator_groups'][$row['id_moderator_group']] = array( |
2885 | 3031 | 'id' => $row['id_moderator_group'], |
@@ -2887,6 +3033,7 @@ discard block |
||
2887 | 3033 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
2888 | 3034 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
2889 | 3035 | ); |
3036 | + } |
|
2890 | 3037 | } |
2891 | 3038 | } |
2892 | 3039 | $smcFunc['db_free_result']($result); |
@@ -2913,23 +3060,27 @@ discard block |
||
2913 | 3060 | if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null) |
2914 | 3061 | { |
2915 | 3062 | // If we don't have our ucwords function defined yet, let's load the settings data. |
2916 | - if (empty($smcFunc['ucwords'])) |
|
2917 | - reloadSettings(); |
|
3063 | + if (empty($smcFunc['ucwords'])) { |
|
3064 | + reloadSettings(); |
|
3065 | + } |
|
2918 | 3066 | |
2919 | 3067 | // If we don't have our theme information yet, let's get it. |
2920 | - if (empty($settings['default_theme_dir'])) |
|
2921 | - loadTheme(0, false); |
|
3068 | + if (empty($settings['default_theme_dir'])) { |
|
3069 | + loadTheme(0, false); |
|
3070 | + } |
|
2922 | 3071 | |
2923 | 3072 | // Default language directories to try. |
2924 | 3073 | $language_directories = array( |
2925 | 3074 | $settings['default_theme_dir'] . '/languages', |
2926 | 3075 | ); |
2927 | - if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) |
|
2928 | - $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
3076 | + if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) { |
|
3077 | + $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
3078 | + } |
|
2929 | 3079 | |
2930 | 3080 | // We possibly have a base theme directory. |
2931 | - if (!empty($settings['base_theme_dir'])) |
|
2932 | - $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
3081 | + if (!empty($settings['base_theme_dir'])) { |
|
3082 | + $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
3083 | + } |
|
2933 | 3084 | |
2934 | 3085 | // Remove any duplicates. |
2935 | 3086 | $language_directories = array_unique($language_directories); |
@@ -2943,20 +3094,21 @@ discard block |
||
2943 | 3094 | foreach ($language_directories as $language_dir) |
2944 | 3095 | { |
2945 | 3096 | // Can't look in here... doesn't exist! |
2946 | - if (!file_exists($language_dir)) |
|
2947 | - continue; |
|
3097 | + if (!file_exists($language_dir)) { |
|
3098 | + continue; |
|
3099 | + } |
|
2948 | 3100 | |
2949 | 3101 | $dir = dir($language_dir); |
2950 | 3102 | while ($entry = $dir->read()) |
2951 | 3103 | { |
2952 | 3104 | // Look for the index language file... For good measure skip any "index.language-utf8.php" files |
2953 | - if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) |
|
2954 | - continue; |
|
2955 | - |
|
2956 | - if (!empty($langList) && !empty($langList[$matches[1]])) |
|
2957 | - $langName = $langList[$matches[1]]; |
|
3105 | + if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) { |
|
3106 | + continue; |
|
3107 | + } |
|
2958 | 3108 | |
2959 | - else |
|
3109 | + if (!empty($langList) && !empty($langList[$matches[1]])) { |
|
3110 | + $langName = $langList[$matches[1]]; |
|
3111 | + } else |
|
2960 | 3112 | { |
2961 | 3113 | $langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' '))); |
2962 | 3114 | |
@@ -2997,12 +3149,14 @@ discard block |
||
2997 | 3149 | } |
2998 | 3150 | |
2999 | 3151 | // Do we need to store the lang list? |
3000 | - if (empty($langList)) |
|
3001 | - updateSettings(array('langList' => $smcFunc['json_encode']($catchLang))); |
|
3152 | + if (empty($langList)) { |
|
3153 | + updateSettings(array('langList' => $smcFunc['json_encode']($catchLang))); |
|
3154 | + } |
|
3002 | 3155 | |
3003 | 3156 | // Let's cash in on this deal. |
3004 | - if (!empty($modSettings['cache_enable'])) |
|
3005 | - cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
3157 | + if (!empty($modSettings['cache_enable'])) { |
|
3158 | + cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
3159 | + } |
|
3006 | 3160 | } |
3007 | 3161 | |
3008 | 3162 | return $context['languages']; |
@@ -3025,8 +3179,9 @@ discard block |
||
3025 | 3179 | global $modSettings, $options, $txt; |
3026 | 3180 | static $censor_vulgar = null, $censor_proper; |
3027 | 3181 | |
3028 | - if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') |
|
3029 | - return $text; |
|
3182 | + if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') { |
|
3183 | + return $text; |
|
3184 | + } |
|
3030 | 3185 | |
3031 | 3186 | // If they haven't yet been loaded, load them. |
3032 | 3187 | if ($censor_vulgar == null) |
@@ -3057,9 +3212,9 @@ discard block |
||
3057 | 3212 | { |
3058 | 3213 | $func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace'; |
3059 | 3214 | $text = $func($censor_vulgar, $censor_proper, $text); |
3215 | + } else { |
|
3216 | + $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
3060 | 3217 | } |
3061 | - else |
|
3062 | - $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
3063 | 3218 | |
3064 | 3219 | return $text; |
3065 | 3220 | } |
@@ -3085,30 +3240,35 @@ discard block |
||
3085 | 3240 | @ini_set('track_errors', '1'); |
3086 | 3241 | |
3087 | 3242 | // Don't include the file more than once, if $once is true. |
3088 | - if ($once && in_array($filename, $templates)) |
|
3089 | - return; |
|
3243 | + if ($once && in_array($filename, $templates)) { |
|
3244 | + return; |
|
3245 | + } |
|
3090 | 3246 | // Add this file to the include list, whether $once is true or not. |
3091 | - else |
|
3092 | - $templates[] = $filename; |
|
3247 | + else { |
|
3248 | + $templates[] = $filename; |
|
3249 | + } |
|
3093 | 3250 | |
3094 | 3251 | |
3095 | 3252 | $file_found = file_exists($filename); |
3096 | 3253 | |
3097 | - if ($once && $file_found) |
|
3098 | - require_once($filename); |
|
3099 | - elseif ($file_found) |
|
3100 | - require($filename); |
|
3254 | + if ($once && $file_found) { |
|
3255 | + require_once($filename); |
|
3256 | + } elseif ($file_found) { |
|
3257 | + require($filename); |
|
3258 | + } |
|
3101 | 3259 | |
3102 | 3260 | if ($file_found !== true) |
3103 | 3261 | { |
3104 | 3262 | ob_end_clean(); |
3105 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
3106 | - @ob_start('ob_gzhandler'); |
|
3107 | - else |
|
3108 | - ob_start(); |
|
3263 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
3264 | + @ob_start('ob_gzhandler'); |
|
3265 | + } else { |
|
3266 | + ob_start(); |
|
3267 | + } |
|
3109 | 3268 | |
3110 | - if (isset($_GET['debug'])) |
|
3111 | - header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3269 | + if (isset($_GET['debug'])) { |
|
3270 | + header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3271 | + } |
|
3112 | 3272 | |
3113 | 3273 | // Don't cache error pages!! |
3114 | 3274 | header('expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -3127,12 +3287,13 @@ discard block |
||
3127 | 3287 | echo '<!DOCTYPE html> |
3128 | 3288 | <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '> |
3129 | 3289 | <head>'; |
3130 | - if (isset($context['character_set'])) |
|
3131 | - echo ' |
|
3290 | + if (isset($context['character_set'])) { |
|
3291 | + echo ' |
|
3132 | 3292 | <meta charset="', $context['character_set'], '">'; |
3293 | + } |
|
3133 | 3294 | |
3134 | - if (!empty($maintenance) && !allowedTo('admin_forum')) |
|
3135 | - echo ' |
|
3295 | + if (!empty($maintenance) && !allowedTo('admin_forum')) { |
|
3296 | + echo ' |
|
3136 | 3297 | <title>', $mtitle, '</title> |
3137 | 3298 | </head> |
3138 | 3299 | <body> |
@@ -3140,8 +3301,8 @@ discard block |
||
3140 | 3301 | ', $mmessage, ' |
3141 | 3302 | </body> |
3142 | 3303 | </html>'; |
3143 | - elseif (!allowedTo('admin_forum')) |
|
3144 | - echo ' |
|
3304 | + } elseif (!allowedTo('admin_forum')) { |
|
3305 | + echo ' |
|
3145 | 3306 | <title>', $txt['template_parse_error'], '</title> |
3146 | 3307 | </head> |
3147 | 3308 | <body> |
@@ -3149,14 +3310,16 @@ discard block |
||
3149 | 3310 | ', $txt['template_parse_error_message'], ' |
3150 | 3311 | </body> |
3151 | 3312 | </html>'; |
3152 | - else |
|
3313 | + } else |
|
3153 | 3314 | { |
3154 | 3315 | $error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
3155 | 3316 | $error_array = error_get_last(); |
3156 | - if (empty($error) && ini_get('track_errors') && !empty($error_array)) |
|
3157 | - $error = $error_array['message']; |
|
3158 | - if (empty($error)) |
|
3159 | - $error = $txt['template_parse_errmsg']; |
|
3317 | + if (empty($error) && ini_get('track_errors') && !empty($error_array)) { |
|
3318 | + $error = $error_array['message']; |
|
3319 | + } |
|
3320 | + if (empty($error)) { |
|
3321 | + $error = $txt['template_parse_errmsg']; |
|
3322 | + } |
|
3160 | 3323 | |
3161 | 3324 | $error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>')); |
3162 | 3325 | |
@@ -3167,11 +3330,12 @@ discard block |
||
3167 | 3330 | <h3>', $txt['template_parse_error'], '</h3> |
3168 | 3331 | ', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
3169 | 3332 | |
3170 | - if (!empty($error)) |
|
3171 | - echo ' |
|
3333 | + if (!empty($error)) { |
|
3334 | + echo ' |
|
3172 | 3335 | <hr> |
3173 | 3336 | |
3174 | 3337 | <div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>'; |
3338 | + } |
|
3175 | 3339 | |
3176 | 3340 | // I know, I know... this is VERY COMPLICATED. Still, it's good. |
3177 | 3341 | if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0) |
@@ -3181,10 +3345,11 @@ discard block |
||
3181 | 3345 | $data2 = preg_split('~\<br( /)?\>~', $data2); |
3182 | 3346 | |
3183 | 3347 | // Fix the PHP code stuff... |
3184 | - if (!isBrowser('gecko')) |
|
3185 | - $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
3186 | - else |
|
3187 | - $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
3348 | + if (!isBrowser('gecko')) { |
|
3349 | + $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
3350 | + } else { |
|
3351 | + $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
3352 | + } |
|
3188 | 3353 | |
3189 | 3354 | // Now we get to work around a bug in PHP where it doesn't escape <br>s! |
3190 | 3355 | $j = -1; |
@@ -3192,8 +3357,9 @@ discard block |
||
3192 | 3357 | { |
3193 | 3358 | $j++; |
3194 | 3359 | |
3195 | - if (substr_count($line, '<br>') == 0) |
|
3196 | - continue; |
|
3360 | + if (substr_count($line, '<br>') == 0) { |
|
3361 | + continue; |
|
3362 | + } |
|
3197 | 3363 | |
3198 | 3364 | $n = substr_count($line, '<br>'); |
3199 | 3365 | for ($i = 0; $i < $n; $i++) |
@@ -3212,38 +3378,42 @@ discard block |
||
3212 | 3378 | // Figure out what the color coding was before... |
3213 | 3379 | $line = max($match[1] - 9, 1); |
3214 | 3380 | $last_line = ''; |
3215 | - for ($line2 = $line - 1; $line2 > 1; $line2--) |
|
3216 | - if (strpos($data2[$line2], '<') !== false) |
|
3381 | + for ($line2 = $line - 1; $line2 > 1; $line2--) { |
|
3382 | + if (strpos($data2[$line2], '<') !== false) |
|
3217 | 3383 | { |
3218 | 3384 | if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0) |
3219 | 3385 | $last_line = $color_match[1]; |
3386 | + } |
|
3220 | 3387 | break; |
3221 | 3388 | } |
3222 | 3389 | |
3223 | 3390 | // Show the relevant lines... |
3224 | 3391 | for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++) |
3225 | 3392 | { |
3226 | - if ($line == $match[1]) |
|
3227 | - echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
3393 | + if ($line == $match[1]) { |
|
3394 | + echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
3395 | + } |
|
3228 | 3396 | |
3229 | 3397 | echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> '; |
3230 | - if (isset($data2[$line]) && $data2[$line] != '') |
|
3231 | - echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
3398 | + if (isset($data2[$line]) && $data2[$line] != '') { |
|
3399 | + echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
3400 | + } |
|
3232 | 3401 | |
3233 | 3402 | if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0) |
3234 | 3403 | { |
3235 | 3404 | $last_line = $color_match[1]; |
3236 | 3405 | echo '</', substr($last_line, 1, 4), '>'; |
3406 | + } elseif ($last_line != '' && strpos($data2[$line], '<') !== false) { |
|
3407 | + $last_line = ''; |
|
3408 | + } elseif ($last_line != '' && $data2[$line] != '') { |
|
3409 | + echo '</', substr($last_line, 1, 4), '>'; |
|
3237 | 3410 | } |
3238 | - elseif ($last_line != '' && strpos($data2[$line], '<') !== false) |
|
3239 | - $last_line = ''; |
|
3240 | - elseif ($last_line != '' && $data2[$line] != '') |
|
3241 | - echo '</', substr($last_line, 1, 4), '>'; |
|
3242 | 3411 | |
3243 | - if ($line == $match[1]) |
|
3244 | - echo '</pre></div><pre style="margin: 0;">'; |
|
3245 | - else |
|
3246 | - echo "\n"; |
|
3412 | + if ($line == $match[1]) { |
|
3413 | + echo '</pre></div><pre style="margin: 0;">'; |
|
3414 | + } else { |
|
3415 | + echo "\n"; |
|
3416 | + } |
|
3247 | 3417 | } |
3248 | 3418 | |
3249 | 3419 | echo '</pre></div>'; |
@@ -3267,8 +3437,9 @@ discard block |
||
3267 | 3437 | global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port, $db_mb4; |
3268 | 3438 | |
3269 | 3439 | // Figure out what type of database we are using. |
3270 | - if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
|
3271 | - $db_type = 'mysql'; |
|
3440 | + if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) { |
|
3441 | + $db_type = 'mysql'; |
|
3442 | + } |
|
3272 | 3443 | |
3273 | 3444 | // Load the file for the database. |
3274 | 3445 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
@@ -3276,11 +3447,13 @@ discard block |
||
3276 | 3447 | $db_options = array(); |
3277 | 3448 | |
3278 | 3449 | // Add in the port if needed |
3279 | - if (!empty($db_port)) |
|
3280 | - $db_options['port'] = $db_port; |
|
3450 | + if (!empty($db_port)) { |
|
3451 | + $db_options['port'] = $db_port; |
|
3452 | + } |
|
3281 | 3453 | |
3282 | - if (!empty($db_mb4)) |
|
3283 | - $db_options['db_mb4'] = $db_mb4; |
|
3454 | + if (!empty($db_mb4)) { |
|
3455 | + $db_options['db_mb4'] = $db_mb4; |
|
3456 | + } |
|
3284 | 3457 | |
3285 | 3458 | // If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use. |
3286 | 3459 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
@@ -3299,13 +3472,15 @@ discard block |
||
3299 | 3472 | } |
3300 | 3473 | |
3301 | 3474 | // Safe guard here, if there isn't a valid connection lets put a stop to it. |
3302 | - if (!$db_connection) |
|
3303 | - display_db_error(); |
|
3475 | + if (!$db_connection) { |
|
3476 | + display_db_error(); |
|
3477 | + } |
|
3304 | 3478 | |
3305 | 3479 | // If in SSI mode fix up the prefix. |
3306 | - if (SMF == 'SSI') |
|
3307 | - db_fix_prefix($db_prefix, $db_name); |
|
3308 | -} |
|
3480 | + if (SMF == 'SSI') { |
|
3481 | + db_fix_prefix($db_prefix, $db_name); |
|
3482 | + } |
|
3483 | + } |
|
3309 | 3484 | |
3310 | 3485 | /** |
3311 | 3486 | * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it. |
@@ -3319,14 +3494,16 @@ discard block |
||
3319 | 3494 | global $sourcedir, $cacheAPI, $cache_accelerator, $cache_enable; |
3320 | 3495 | |
3321 | 3496 | // is caching enabled? |
3322 | - if (empty($cache_enable) && empty($overrideCache)) |
|
3323 | - return false; |
|
3497 | + if (empty($cache_enable) && empty($overrideCache)) { |
|
3498 | + return false; |
|
3499 | + } |
|
3324 | 3500 | |
3325 | 3501 | // Not overriding this and we have a cacheAPI, send it back. |
3326 | - if (empty($overrideCache) && is_object($cacheAPI)) |
|
3327 | - return $cacheAPI; |
|
3328 | - elseif (is_null($cacheAPI)) |
|
3329 | - $cacheAPI = false; |
|
3502 | + if (empty($overrideCache) && is_object($cacheAPI)) { |
|
3503 | + return $cacheAPI; |
|
3504 | + } elseif (is_null($cacheAPI)) { |
|
3505 | + $cacheAPI = false; |
|
3506 | + } |
|
3330 | 3507 | |
3331 | 3508 | // Make sure our class is in session. |
3332 | 3509 | require_once($sourcedir . '/Class-CacheAPI.php'); |
@@ -3347,8 +3524,9 @@ discard block |
||
3347 | 3524 | if (!$testAPI->isSupported()) |
3348 | 3525 | { |
3349 | 3526 | // Can we save ourselves? |
3350 | - if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') |
|
3351 | - return loadCacheAccelerator(null, false); |
|
3527 | + if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') { |
|
3528 | + return loadCacheAccelerator(null, false); |
|
3529 | + } |
|
3352 | 3530 | return false; |
3353 | 3531 | } |
3354 | 3532 | |
@@ -3360,9 +3538,9 @@ discard block |
||
3360 | 3538 | { |
3361 | 3539 | $cacheAPI = $testAPI; |
3362 | 3540 | return $cacheAPI; |
3541 | + } else { |
|
3542 | + return $testAPI; |
|
3363 | 3543 | } |
3364 | - else |
|
3365 | - return $testAPI; |
|
3366 | 3544 | } |
3367 | 3545 | } |
3368 | 3546 | |
@@ -3382,8 +3560,9 @@ discard block |
||
3382 | 3560 | |
3383 | 3561 | // @todo Why are we doing this if caching is disabled? |
3384 | 3562 | |
3385 | - if (function_exists('call_integration_hook')) |
|
3386 | - call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
3563 | + if (function_exists('call_integration_hook')) { |
|
3564 | + call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
3565 | + } |
|
3387 | 3566 | |
3388 | 3567 | /* Refresh the cache if either: |
3389 | 3568 | 1. Caching is disabled. |
@@ -3397,16 +3576,19 @@ discard block |
||
3397 | 3576 | require_once($sourcedir . '/' . $file); |
3398 | 3577 | $cache_block = call_user_func_array($function, $params); |
3399 | 3578 | |
3400 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) |
|
3401 | - cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
3579 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) { |
|
3580 | + cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
3581 | + } |
|
3402 | 3582 | } |
3403 | 3583 | |
3404 | 3584 | // Some cached data may need a freshening up after retrieval. |
3405 | - if (!empty($cache_block['post_retri_eval'])) |
|
3406 | - eval($cache_block['post_retri_eval']); |
|
3585 | + if (!empty($cache_block['post_retri_eval'])) { |
|
3586 | + eval($cache_block['post_retri_eval']); |
|
3587 | + } |
|
3407 | 3588 | |
3408 | - if (function_exists('call_integration_hook')) |
|
3409 | - call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
3589 | + if (function_exists('call_integration_hook')) { |
|
3590 | + call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
3591 | + } |
|
3410 | 3592 | |
3411 | 3593 | return $cache_block['data']; |
3412 | 3594 | } |
@@ -3433,8 +3615,9 @@ discard block |
||
3433 | 3615 | global $smcFunc, $cache_enable, $cacheAPI; |
3434 | 3616 | global $cache_hits, $cache_count, $db_show_debug; |
3435 | 3617 | |
3436 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
3437 | - return; |
|
3618 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
3619 | + return; |
|
3620 | + } |
|
3438 | 3621 | |
3439 | 3622 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
3440 | 3623 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3447,12 +3630,14 @@ discard block |
||
3447 | 3630 | $value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value)); |
3448 | 3631 | $cacheAPI->putData($key, $value, $ttl); |
3449 | 3632 | |
3450 | - if (function_exists('call_integration_hook')) |
|
3451 | - call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
3633 | + if (function_exists('call_integration_hook')) { |
|
3634 | + call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
3635 | + } |
|
3452 | 3636 | |
3453 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
3454 | - $cache_hits[$cache_count]['t'] = microtime(true) - $st; |
|
3455 | -} |
|
3637 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
3638 | + $cache_hits[$cache_count]['t'] = microtime(true) - $st; |
|
3639 | + } |
|
3640 | + } |
|
3456 | 3641 | |
3457 | 3642 | /** |
3458 | 3643 | * Gets the value from the cache specified by key, so long as it is not older than ttl seconds. |
@@ -3468,8 +3653,9 @@ discard block |
||
3468 | 3653 | global $smcFunc, $cache_enable, $cacheAPI; |
3469 | 3654 | global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug; |
3470 | 3655 | |
3471 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
3472 | - return; |
|
3656 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
3657 | + return; |
|
3658 | + } |
|
3473 | 3659 | |
3474 | 3660 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
3475 | 3661 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3489,16 +3675,18 @@ discard block |
||
3489 | 3675 | |
3490 | 3676 | if (empty($value)) |
3491 | 3677 | { |
3492 | - if (!is_array($cache_misses)) |
|
3493 | - $cache_misses = array(); |
|
3678 | + if (!is_array($cache_misses)) { |
|
3679 | + $cache_misses = array(); |
|
3680 | + } |
|
3494 | 3681 | |
3495 | 3682 | $cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1; |
3496 | 3683 | $cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get'); |
3497 | 3684 | } |
3498 | 3685 | } |
3499 | 3686 | |
3500 | - if (function_exists('call_integration_hook') && isset($value)) |
|
3501 | - call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
3687 | + if (function_exists('call_integration_hook') && isset($value)) { |
|
3688 | + call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
3689 | + } |
|
3502 | 3690 | |
3503 | 3691 | return empty($value) ? null : (isset($smcFunc['json_decode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true)); |
3504 | 3692 | } |
@@ -3520,8 +3708,9 @@ discard block |
||
3520 | 3708 | global $cacheAPI; |
3521 | 3709 | |
3522 | 3710 | // If we can't get to the API, can't do this. |
3523 | - if (empty($cacheAPI)) |
|
3524 | - return; |
|
3711 | + if (empty($cacheAPI)) { |
|
3712 | + return; |
|
3713 | + } |
|
3525 | 3714 | |
3526 | 3715 | // Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure. |
3527 | 3716 | $cacheAPI->cleanCache($type); |
@@ -3546,8 +3735,9 @@ discard block |
||
3546 | 3735 | global $modSettings, $smcFunc, $image_proxy_enabled, $user_info; |
3547 | 3736 | |
3548 | 3737 | // Come on! |
3549 | - if (empty($data)) |
|
3550 | - return array(); |
|
3738 | + if (empty($data)) { |
|
3739 | + return array(); |
|
3740 | + } |
|
3551 | 3741 | |
3552 | 3742 | // Set a nice default var. |
3553 | 3743 | $image = ''; |
@@ -3555,11 +3745,11 @@ discard block |
||
3555 | 3745 | // Gravatar has been set as mandatory! |
3556 | 3746 | if (!empty($modSettings['gravatarOverride'])) |
3557 | 3747 | { |
3558 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) |
|
3559 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3560 | - |
|
3561 | - else if (!empty($data['email'])) |
|
3562 | - $image = get_gravatar_url($data['email']); |
|
3748 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) { |
|
3749 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3750 | + } else if (!empty($data['email'])) { |
|
3751 | + $image = get_gravatar_url($data['email']); |
|
3752 | + } |
|
3563 | 3753 | } |
3564 | 3754 | |
3565 | 3755 | // Look if the user has a gravatar field or has set an external url as avatar. |
@@ -3571,54 +3761,60 @@ discard block |
||
3571 | 3761 | // Gravatar. |
3572 | 3762 | if (stristr($data['avatar'], 'gravatar://')) |
3573 | 3763 | { |
3574 | - if ($data['avatar'] == 'gravatar://') |
|
3575 | - $image = get_gravatar_url($data['email']); |
|
3576 | - |
|
3577 | - elseif (!empty($modSettings['gravatarAllowExtraEmail'])) |
|
3578 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3764 | + if ($data['avatar'] == 'gravatar://') { |
|
3765 | + $image = get_gravatar_url($data['email']); |
|
3766 | + } elseif (!empty($modSettings['gravatarAllowExtraEmail'])) { |
|
3767 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3768 | + } |
|
3579 | 3769 | } |
3580 | 3770 | |
3581 | 3771 | // External url. |
3582 | 3772 | else |
3583 | 3773 | { |
3584 | 3774 | // Using ssl? |
3585 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) |
|
3586 | - $image = get_proxied_url($data['avatar']); |
|
3775 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) { |
|
3776 | + $image = get_proxied_url($data['avatar']); |
|
3777 | + } |
|
3587 | 3778 | |
3588 | 3779 | // Just a plain external url. |
3589 | - else |
|
3590 | - $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
3780 | + else { |
|
3781 | + $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
3782 | + } |
|
3591 | 3783 | } |
3592 | 3784 | } |
3593 | 3785 | |
3594 | 3786 | // Perhaps this user has an attachment as avatar... |
3595 | - else if (!empty($data['filename'])) |
|
3596 | - $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
3787 | + else if (!empty($data['filename'])) { |
|
3788 | + $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
3789 | + } |
|
3597 | 3790 | |
3598 | 3791 | // Right... no avatar... use our default image. |
3599 | - else |
|
3600 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
3792 | + else { |
|
3793 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
3794 | + } |
|
3601 | 3795 | } |
3602 | 3796 | |
3603 | 3797 | call_integration_hook('integrate_set_avatar_data', array(&$image, &$data)); |
3604 | 3798 | |
3605 | 3799 | // At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed. |
3606 | - if (!empty($image)) |
|
3607 | - return array( |
|
3800 | + if (!empty($image)) { |
|
3801 | + return array( |
|
3608 | 3802 | 'name' => !empty($data['avatar']) ? $data['avatar'] : '', |
3609 | 3803 | 'image' => '<img class="avatar" src="' . $image . '" />', |
3610 | 3804 | 'href' => $image, |
3611 | 3805 | 'url' => $image, |
3612 | 3806 | ); |
3807 | + } |
|
3613 | 3808 | |
3614 | 3809 | // Fallback to make life easier for everyone... |
3615 | - else |
|
3616 | - return array( |
|
3810 | + else { |
|
3811 | + return array( |
|
3617 | 3812 | 'name' => '', |
3618 | 3813 | 'image' => '', |
3619 | 3814 | 'href' => '', |
3620 | 3815 | 'url' => '', |
3621 | 3816 | ); |
3622 | -} |
|
3817 | + } |
|
3818 | + } |
|
3623 | 3819 | |
3624 | 3820 | ?> |
3625 | 3821 | \ No newline at end of file |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -33,8 +34,8 @@ discard block |
||
33 | 34 | global $smcFunc; |
34 | 35 | |
35 | 36 | // Map some database specific functions, only do this once. |
36 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
37 | - $smcFunc += array( |
|
37 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
38 | + $smcFunc += array( |
|
38 | 39 | 'db_query' => 'smf_db_query', |
39 | 40 | 'db_quote' => 'smf_db_quote', |
40 | 41 | 'db_fetch_assoc' => 'mysqli_fetch_assoc', |
@@ -65,13 +66,16 @@ discard block |
||
65 | 66 | 'db_native_replace' => 'smf_db_native_replace', |
66 | 67 | 'db_cte_support' => 'smf_db_cte_support', |
67 | 68 | ); |
69 | + } |
|
68 | 70 | |
69 | - if (!empty($db_options['persist'])) |
|
70 | - $db_server = 'p:' . $db_server; |
|
71 | + if (!empty($db_options['persist'])) { |
|
72 | + $db_server = 'p:' . $db_server; |
|
73 | + } |
|
71 | 74 | |
72 | 75 | // We are not going to make it very far without these. |
73 | - if (!function_exists('mysqli_init') || !function_exists('mysqli_real_connect')) |
|
74 | - display_db_error(); |
|
76 | + if (!function_exists('mysqli_init') || !function_exists('mysqli_real_connect')) { |
|
77 | + display_db_error(); |
|
78 | + } |
|
75 | 79 | |
76 | 80 | $connection = mysqli_init(); |
77 | 81 | |
@@ -81,29 +85,33 @@ discard block |
||
81 | 85 | |
82 | 86 | if ($connection) |
83 | 87 | { |
84 | - if (!empty($db_options['port'])) |
|
85 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags); |
|
86 | - else |
|
87 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags); |
|
88 | + if (!empty($db_options['port'])) { |
|
89 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags); |
|
90 | + } else { |
|
91 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags); |
|
92 | + } |
|
88 | 93 | } |
89 | 94 | |
90 | 95 | // Something's wrong, show an error if its fatal (which we assume it is) |
91 | 96 | if ($success === false) |
92 | 97 | { |
93 | - if (!empty($db_options['non_fatal'])) |
|
94 | - return null; |
|
95 | - else |
|
96 | - display_db_error(); |
|
98 | + if (!empty($db_options['non_fatal'])) { |
|
99 | + return null; |
|
100 | + } else { |
|
101 | + display_db_error(); |
|
102 | + } |
|
97 | 103 | } |
98 | 104 | |
99 | 105 | // Select the database, unless told not to |
100 | - if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) |
|
101 | - display_db_error(); |
|
106 | + if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) { |
|
107 | + display_db_error(); |
|
108 | + } |
|
102 | 109 | |
103 | 110 | mysqli_query($connection, 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\''); |
104 | 111 | |
105 | - if (!empty($db_options['db_mb4'])) |
|
106 | - $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
112 | + if (!empty($db_options['db_mb4'])) { |
|
113 | + $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
114 | + } |
|
107 | 115 | |
108 | 116 | return $connection; |
109 | 117 | } |
@@ -174,34 +182,42 @@ discard block |
||
174 | 182 | global $db_callback, $user_info, $db_prefix, $smcFunc; |
175 | 183 | |
176 | 184 | list ($values, $connection) = $db_callback; |
177 | - if (!is_object($connection)) |
|
178 | - display_db_error(); |
|
185 | + if (!is_object($connection)) { |
|
186 | + display_db_error(); |
|
187 | + } |
|
179 | 188 | |
180 | - if ($matches[1] === 'db_prefix') |
|
181 | - return $db_prefix; |
|
189 | + if ($matches[1] === 'db_prefix') { |
|
190 | + return $db_prefix; |
|
191 | + } |
|
182 | 192 | |
183 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
184 | - return $user_info[$matches[1]]; |
|
193 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
194 | + return $user_info[$matches[1]]; |
|
195 | + } |
|
185 | 196 | |
186 | - if ($matches[1] === 'empty') |
|
187 | - return '\'\''; |
|
197 | + if ($matches[1] === 'empty') { |
|
198 | + return '\'\''; |
|
199 | + } |
|
188 | 200 | |
189 | - if (!isset($matches[2])) |
|
190 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
201 | + if (!isset($matches[2])) { |
|
202 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
203 | + } |
|
191 | 204 | |
192 | - if ($matches[1] === 'literal') |
|
193 | - return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
205 | + if ($matches[1] === 'literal') { |
|
206 | + return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
207 | + } |
|
194 | 208 | |
195 | - if (!isset($values[$matches[2]])) |
|
196 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
209 | + if (!isset($values[$matches[2]])) { |
|
210 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
211 | + } |
|
197 | 212 | |
198 | 213 | $replacement = $values[$matches[2]]; |
199 | 214 | |
200 | 215 | switch ($matches[1]) |
201 | 216 | { |
202 | 217 | case 'int': |
203 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
204 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
218 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
219 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
220 | + } |
|
205 | 221 | return (string) (int) $replacement; |
206 | 222 | break; |
207 | 223 | |
@@ -213,65 +229,73 @@ discard block |
||
213 | 229 | case 'array_int': |
214 | 230 | if (is_array($replacement)) |
215 | 231 | { |
216 | - if (empty($replacement)) |
|
217 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
232 | + if (empty($replacement)) { |
|
233 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
234 | + } |
|
218 | 235 | |
219 | 236 | foreach ($replacement as $key => $value) |
220 | 237 | { |
221 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
222 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
238 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
239 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
240 | + } |
|
223 | 241 | |
224 | 242 | $replacement[$key] = (string) (int) $value; |
225 | 243 | } |
226 | 244 | |
227 | 245 | return implode(', ', $replacement); |
246 | + } else { |
|
247 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
228 | 248 | } |
229 | - else |
|
230 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
231 | 249 | |
232 | 250 | break; |
233 | 251 | |
234 | 252 | case 'array_string': |
235 | 253 | if (is_array($replacement)) |
236 | 254 | { |
237 | - if (empty($replacement)) |
|
238 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
255 | + if (empty($replacement)) { |
|
256 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
257 | + } |
|
239 | 258 | |
240 | - foreach ($replacement as $key => $value) |
|
241 | - $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
259 | + foreach ($replacement as $key => $value) { |
|
260 | + $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
261 | + } |
|
242 | 262 | |
243 | 263 | return implode(', ', $replacement); |
264 | + } else { |
|
265 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
244 | 266 | } |
245 | - else |
|
246 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
247 | 267 | break; |
248 | 268 | |
249 | 269 | case 'date': |
250 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
251 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
252 | - else |
|
253 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
270 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
271 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
272 | + } else { |
|
273 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
274 | + } |
|
254 | 275 | break; |
255 | 276 | |
256 | 277 | case 'time': |
257 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
258 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
259 | - else |
|
260 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
278 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
279 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
280 | + } else { |
|
281 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
282 | + } |
|
261 | 283 | break; |
262 | 284 | |
263 | 285 | case 'datetime': |
264 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
265 | - return 'str_to_date('. |
|
286 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
287 | + return 'str_to_date('. |
|
266 | 288 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
267 | 289 | ',\'%Y-%m-%d %h:%i:%s\')'; |
268 | - else |
|
269 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
290 | + } else { |
|
291 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
292 | + } |
|
270 | 293 | break; |
271 | 294 | |
272 | 295 | case 'float': |
273 | - if (!is_numeric($replacement)) |
|
274 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
296 | + if (!is_numeric($replacement)) { |
|
297 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
298 | + } |
|
275 | 299 | return (string) (float) $replacement; |
276 | 300 | break; |
277 | 301 | |
@@ -285,32 +309,37 @@ discard block |
||
285 | 309 | break; |
286 | 310 | |
287 | 311 | case 'inet': |
288 | - if ($replacement == 'null' || $replacement == '') |
|
289 | - return 'null'; |
|
290 | - if (!isValidIP($replacement)) |
|
291 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
312 | + if ($replacement == 'null' || $replacement == '') { |
|
313 | + return 'null'; |
|
314 | + } |
|
315 | + if (!isValidIP($replacement)) { |
|
316 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
317 | + } |
|
292 | 318 | //we don't use the native support of mysql > 5.6.2 |
293 | 319 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
294 | 320 | |
295 | 321 | case 'array_inet': |
296 | 322 | if (is_array($replacement)) |
297 | 323 | { |
298 | - if (empty($replacement)) |
|
299 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
324 | + if (empty($replacement)) { |
|
325 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
326 | + } |
|
300 | 327 | |
301 | 328 | foreach ($replacement as $key => $value) |
302 | 329 | { |
303 | - if ($replacement == 'null' || $replacement == '') |
|
304 | - $replacement[$key] = 'null'; |
|
305 | - if (!isValidIP($value)) |
|
306 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
330 | + if ($replacement == 'null' || $replacement == '') { |
|
331 | + $replacement[$key] = 'null'; |
|
332 | + } |
|
333 | + if (!isValidIP($value)) { |
|
334 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
335 | + } |
|
307 | 336 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
308 | 337 | } |
309 | 338 | |
310 | 339 | return implode(', ', $replacement); |
340 | + } else { |
|
341 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
311 | 342 | } |
312 | - else |
|
313 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
314 | 343 | break; |
315 | 344 | |
316 | 345 | default: |
@@ -381,18 +410,20 @@ discard block |
||
381 | 410 | // One more query.... |
382 | 411 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
383 | 412 | |
384 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
385 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
413 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
414 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
415 | + } |
|
386 | 416 | |
387 | 417 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
388 | 418 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
389 | 419 | { |
390 | 420 | // Add before LIMIT |
391 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
392 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
393 | - else |
|
394 | - // Append it. |
|
421 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
422 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
423 | + } else { |
|
424 | + // Append it. |
|
395 | 425 | $db_string .= "\n\t\t\tORDER BY null"; |
426 | + } |
|
396 | 427 | } |
397 | 428 | |
398 | 429 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -418,17 +449,18 @@ discard block |
||
418 | 449 | while (true) |
419 | 450 | { |
420 | 451 | $pos = strpos($db_string_1, '\'', $pos + 1); |
421 | - if ($pos === false) |
|
422 | - break; |
|
452 | + if ($pos === false) { |
|
453 | + break; |
|
454 | + } |
|
423 | 455 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
424 | 456 | |
425 | 457 | while (true) |
426 | 458 | { |
427 | 459 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
428 | 460 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
429 | - if ($pos1 === false) |
|
430 | - break; |
|
431 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
461 | + if ($pos1 === false) { |
|
462 | + break; |
|
463 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
432 | 464 | { |
433 | 465 | $pos = $pos1; |
434 | 466 | break; |
@@ -444,16 +476,19 @@ discard block |
||
444 | 476 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
445 | 477 | |
446 | 478 | // Comments? We don't use comments in our queries, we leave 'em outside! |
447 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
448 | - $fail = true; |
|
479 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
480 | + $fail = true; |
|
481 | + } |
|
449 | 482 | // Trying to change passwords, slow us down, or something? |
450 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
451 | - $fail = true; |
|
452 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
453 | - $fail = true; |
|
483 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
484 | + $fail = true; |
|
485 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
486 | + $fail = true; |
|
487 | + } |
|
454 | 488 | |
455 | - if (!empty($fail) && function_exists('log_error')) |
|
456 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
489 | + if (!empty($fail) && function_exists('log_error')) { |
|
490 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
491 | + } |
|
457 | 492 | } |
458 | 493 | |
459 | 494 | // Debugging. |
@@ -463,8 +498,9 @@ discard block |
||
463 | 498 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
464 | 499 | |
465 | 500 | // Initialize $db_cache if not already initialized. |
466 | - if (!isset($db_cache)) |
|
467 | - $db_cache = array(); |
|
501 | + if (!isset($db_cache)) { |
|
502 | + $db_cache = array(); |
|
503 | + } |
|
468 | 504 | |
469 | 505 | if (!empty($_SESSION['debug_redirect'])) |
470 | 506 | { |
@@ -480,17 +516,20 @@ discard block |
||
480 | 516 | $db_cache[$db_count]['s'] = ($st = microtime(true)) - $time_start; |
481 | 517 | } |
482 | 518 | |
483 | - if (empty($db_unbuffered)) |
|
484 | - $ret = @mysqli_query($connection, $db_string); |
|
485 | - else |
|
486 | - $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
519 | + if (empty($db_unbuffered)) { |
|
520 | + $ret = @mysqli_query($connection, $db_string); |
|
521 | + } else { |
|
522 | + $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
523 | + } |
|
487 | 524 | |
488 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
489 | - $ret = smf_db_error($db_string, $connection); |
|
525 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
526 | + $ret = smf_db_error($db_string, $connection); |
|
527 | + } |
|
490 | 528 | |
491 | 529 | // Debugging. |
492 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
493 | - $db_cache[$db_count]['t'] = microtime(true) - $st; |
|
530 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
531 | + $db_cache[$db_count]['t'] = microtime(true) - $st; |
|
532 | + } |
|
494 | 533 | |
495 | 534 | return $ret; |
496 | 535 | } |
@@ -537,12 +576,13 @@ discard block |
||
537 | 576 | // Decide which connection to use |
538 | 577 | $connection = $connection === null ? $db_connection : $connection; |
539 | 578 | |
540 | - if ($type == 'begin') |
|
541 | - return @mysqli_query($connection, 'BEGIN'); |
|
542 | - elseif ($type == 'rollback') |
|
543 | - return @mysqli_query($connection, 'ROLLBACK'); |
|
544 | - elseif ($type == 'commit') |
|
545 | - return @mysqli_query($connection, 'COMMIT'); |
|
579 | + if ($type == 'begin') { |
|
580 | + return @mysqli_query($connection, 'BEGIN'); |
|
581 | + } elseif ($type == 'rollback') { |
|
582 | + return @mysqli_query($connection, 'ROLLBACK'); |
|
583 | + } elseif ($type == 'commit') { |
|
584 | + return @mysqli_query($connection, 'COMMIT'); |
|
585 | + } |
|
546 | 586 | |
547 | 587 | return false; |
548 | 588 | } |
@@ -580,8 +620,9 @@ discard block |
||
580 | 620 | // 1213: Deadlock found. |
581 | 621 | |
582 | 622 | // Log the error. |
583 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
584 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
623 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
624 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
625 | + } |
|
585 | 626 | |
586 | 627 | // Database error auto fixing ;). |
587 | 628 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -590,8 +631,9 @@ discard block |
||
590 | 631 | $old_cache = @$modSettings['cache_enable']; |
591 | 632 | $modSettings['cache_enable'] = '1'; |
592 | 633 | |
593 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
594 | - $db_last_error = max(@$db_last_error, $temp); |
|
634 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
635 | + $db_last_error = max(@$db_last_error, $temp); |
|
636 | + } |
|
595 | 637 | |
596 | 638 | if (@$db_last_error < time() - 3600 * 24 * 3) |
597 | 639 | { |
@@ -607,8 +649,9 @@ discard block |
||
607 | 649 | foreach ($tables as $table) |
608 | 650 | { |
609 | 651 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
610 | - if (trim($table) != '') |
|
611 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
652 | + if (trim($table) != '') { |
|
653 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
654 | + } |
|
612 | 655 | } |
613 | 656 | } |
614 | 657 | |
@@ -617,8 +660,9 @@ discard block |
||
617 | 660 | // Table crashed. Let's try to fix it. |
618 | 661 | elseif ($query_errno == 1016) |
619 | 662 | { |
620 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
621 | - $fix_tables = array('`' . $match[1] . '`'); |
|
663 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
664 | + $fix_tables = array('`' . $match[1] . '`'); |
|
665 | + } |
|
622 | 666 | } |
623 | 667 | // Indexes crashed. Should be easy to fix! |
624 | 668 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -637,13 +681,15 @@ discard block |
||
637 | 681 | |
638 | 682 | // Make a note of the REPAIR... |
639 | 683 | cache_put_data('db_last_error', time(), 600); |
640 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
641 | - updateSettingsFile(array('db_last_error' => time())); |
|
684 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
685 | + updateSettingsFile(array('db_last_error' => time())); |
|
686 | + } |
|
642 | 687 | |
643 | 688 | // Attempt to find and repair the broken table. |
644 | - foreach ($fix_tables as $table) |
|
645 | - $smcFunc['db_query']('', " |
|
689 | + foreach ($fix_tables as $table) { |
|
690 | + $smcFunc['db_query']('', " |
|
646 | 691 | REPAIR TABLE $table", false, false); |
692 | + } |
|
647 | 693 | |
648 | 694 | // And send off an email! |
649 | 695 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -652,11 +698,12 @@ discard block |
||
652 | 698 | |
653 | 699 | // Try the query again...? |
654 | 700 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
655 | - if ($ret !== false) |
|
656 | - return $ret; |
|
701 | + if ($ret !== false) { |
|
702 | + return $ret; |
|
703 | + } |
|
704 | + } else { |
|
705 | + $modSettings['cache_enable'] = $old_cache; |
|
657 | 706 | } |
658 | - else |
|
659 | - $modSettings['cache_enable'] = $old_cache; |
|
660 | 707 | |
661 | 708 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
662 | 709 | if (in_array($query_errno, array(1205, 1213))) |
@@ -669,24 +716,27 @@ discard block |
||
669 | 716 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
670 | 717 | |
671 | 718 | $new_errno = mysqli_errno($db_connection); |
672 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
673 | - break; |
|
719 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
720 | + break; |
|
721 | + } |
|
674 | 722 | } |
675 | 723 | |
676 | 724 | // If it failed again, shucks to be you... we're not trying it over and over. |
677 | - if ($ret !== false) |
|
678 | - return $ret; |
|
725 | + if ($ret !== false) { |
|
726 | + return $ret; |
|
727 | + } |
|
679 | 728 | } |
680 | 729 | } |
681 | 730 | // Are they out of space, perhaps? |
682 | 731 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
683 | 732 | { |
684 | - if (!isset($txt)) |
|
685 | - $query_error .= ' - check database storage space.'; |
|
686 | - else |
|
733 | + if (!isset($txt)) { |
|
734 | + $query_error .= ' - check database storage space.'; |
|
735 | + } else |
|
687 | 736 | { |
688 | - if (!isset($txt['mysql_error_space'])) |
|
689 | - loadLanguage('Errors'); |
|
737 | + if (!isset($txt['mysql_error_space'])) { |
|
738 | + loadLanguage('Errors'); |
|
739 | + } |
|
690 | 740 | |
691 | 741 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
692 | 742 | } |
@@ -694,15 +744,17 @@ discard block |
||
694 | 744 | } |
695 | 745 | |
696 | 746 | // Nothing's defined yet... just die with it. |
697 | - if (empty($context) || empty($txt)) |
|
698 | - die($query_error); |
|
747 | + if (empty($context) || empty($txt)) { |
|
748 | + die($query_error); |
|
749 | + } |
|
699 | 750 | |
700 | 751 | // Show an error message, if possible. |
701 | 752 | $context['error_title'] = $txt['database_error']; |
702 | - if (allowedTo('admin_forum')) |
|
703 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
704 | - else |
|
705 | - $context['error_message'] = $txt['try_again']; |
|
753 | + if (allowedTo('admin_forum')) { |
|
754 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
755 | + } else { |
|
756 | + $context['error_message'] = $txt['try_again']; |
|
757 | + } |
|
706 | 758 | |
707 | 759 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
708 | 760 | { |
@@ -734,8 +786,9 @@ discard block |
||
734 | 786 | $return_var = null; |
735 | 787 | |
736 | 788 | // With nothing to insert, simply return. |
737 | - if (empty($data)) |
|
738 | - return; |
|
789 | + if (empty($data)) { |
|
790 | + return; |
|
791 | + } |
|
739 | 792 | |
740 | 793 | // Replace the prefix holder with the actual prefix. |
741 | 794 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -745,23 +798,26 @@ discard block |
||
745 | 798 | if (!empty($keys) && (count($keys) > 0) && $returnmode > 0) |
746 | 799 | { |
747 | 800 | $with_returning = true; |
748 | - if ($returnmode == 2) |
|
749 | - $return_var = array(); |
|
801 | + if ($returnmode == 2) { |
|
802 | + $return_var = array(); |
|
803 | + } |
|
750 | 804 | } |
751 | 805 | |
752 | 806 | // Inserting data as a single row can be done as a single array. |
753 | - if (!is_array($data[array_rand($data)])) |
|
754 | - $data = array($data); |
|
807 | + if (!is_array($data[array_rand($data)])) { |
|
808 | + $data = array($data); |
|
809 | + } |
|
755 | 810 | |
756 | 811 | // Create the mold for a single row insert. |
757 | 812 | $insertData = '('; |
758 | 813 | foreach ($columns as $columnName => $type) |
759 | 814 | { |
760 | 815 | // Are we restricting the length? |
761 | - if (strpos($type, 'string-') !== false) |
|
762 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
763 | - else |
|
764 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
816 | + if (strpos($type, 'string-') !== false) { |
|
817 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
818 | + } else { |
|
819 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
820 | + } |
|
765 | 821 | } |
766 | 822 | $insertData = substr($insertData, 0, -2) . ')'; |
767 | 823 | |
@@ -770,16 +826,18 @@ discard block |
||
770 | 826 | |
771 | 827 | // Here's where the variables are injected to the query. |
772 | 828 | $insertRows = array(); |
773 | - foreach ($data as $dataRow) |
|
774 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
829 | + foreach ($data as $dataRow) { |
|
830 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
831 | + } |
|
775 | 832 | |
776 | 833 | // Determine the method of insertion. |
777 | 834 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
778 | 835 | |
779 | 836 | // Sanity check for replace is key part of the columns array |
780 | - if ($method == 'replace' && count(array_intersect_key($columns, array_flip($keys))) !== count($keys)) |
|
781 | - smf_db_error_backtrace('Primary Key field missing in insert call', |
|
837 | + if ($method == 'replace' && count(array_intersect_key($columns, array_flip($keys))) !== count($keys)) { |
|
838 | + smf_db_error_backtrace('Primary Key field missing in insert call', |
|
782 | 839 | 'Change the method of db insert to insert or add the pk field to the columns array', E_USER_ERROR, __FILE__, __LINE__); |
840 | + } |
|
783 | 841 | |
784 | 842 | if (!$with_returning || $method != 'ingore') |
785 | 843 | { |
@@ -795,8 +853,7 @@ discard block |
||
795 | 853 | ), |
796 | 854 | $connection |
797 | 855 | ); |
798 | - } |
|
799 | - else //special way for ignore method with returning |
|
856 | + } else //special way for ignore method with returning |
|
800 | 857 | { |
801 | 858 | $count = count($insertRows); |
802 | 859 | $ai = 0; |
@@ -816,19 +873,21 @@ discard block |
||
816 | 873 | ); |
817 | 874 | $new_id = $smcFunc['db_insert_id'](); |
818 | 875 | |
819 | - if ($last_id != $new_id) //the inserted value was new |
|
876 | + if ($last_id != $new_id) { |
|
877 | + //the inserted value was new |
|
820 | 878 | { |
821 | 879 | $ai = $new_id; |
822 | 880 | } |
823 | - else // the inserted value already exists we need to find the pk |
|
881 | + } else // the inserted value already exists we need to find the pk |
|
824 | 882 | { |
825 | 883 | $where_string = ''; |
826 | 884 | $count2 = count($indexed_columns); |
827 | 885 | for ($x = 0; $x < $count2; $x++) |
828 | 886 | { |
829 | 887 | $where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x]; |
830 | - if (($x + 1) < $count2) |
|
831 | - $where_string += ' AND '; |
|
888 | + if (($x + 1) < $count2) { |
|
889 | + $where_string += ' AND '; |
|
890 | + } |
|
832 | 891 | } |
833 | 892 | |
834 | 893 | $request = $smcFunc['db_query']('',' |
@@ -844,25 +903,27 @@ discard block |
||
844 | 903 | } |
845 | 904 | } |
846 | 905 | |
847 | - if ($returnmode == 1) |
|
848 | - $return_var = $ai; |
|
849 | - else if ($returnmode == 2) |
|
850 | - $return_var[] = $ai; |
|
906 | + if ($returnmode == 1) { |
|
907 | + $return_var = $ai; |
|
908 | + } else if ($returnmode == 2) { |
|
909 | + $return_var[] = $ai; |
|
910 | + } |
|
851 | 911 | } |
852 | 912 | } |
853 | 913 | |
854 | 914 | |
855 | 915 | if ($with_returning) |
856 | 916 | { |
857 | - if ($returnmode == 1 && empty($return_var)) |
|
858 | - $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
859 | - else if ($returnmode == 2 && empty($return_var)) |
|
917 | + if ($returnmode == 1 && empty($return_var)) { |
|
918 | + $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
919 | + } else if ($returnmode == 2 && empty($return_var)) |
|
860 | 920 | { |
861 | 921 | $return_var = array(); |
862 | 922 | $count = count($insertRows); |
863 | 923 | $start = smf_db_insert_id($table, $keys[0]); |
864 | - for ($i = 0; $i < $count; $i++ ) |
|
865 | - $return_var[] = $start + $i; |
|
924 | + for ($i = 0; $i < $count; $i++ ) { |
|
925 | + $return_var[] = $start + $i; |
|
926 | + } |
|
866 | 927 | } |
867 | 928 | return $return_var; |
868 | 929 | } |
@@ -880,8 +941,9 @@ discard block |
||
880 | 941 | */ |
881 | 942 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
882 | 943 | { |
883 | - if (empty($log_message)) |
|
884 | - $log_message = $error_message; |
|
944 | + if (empty($log_message)) { |
|
945 | + $log_message = $error_message; |
|
946 | + } |
|
885 | 947 | |
886 | 948 | foreach (debug_backtrace() as $step) |
887 | 949 | { |
@@ -900,12 +962,14 @@ discard block |
||
900 | 962 | } |
901 | 963 | |
902 | 964 | // A special case - we want the file and line numbers for debugging. |
903 | - if ($error_type == 'return') |
|
904 | - return array($file, $line); |
|
965 | + if ($error_type == 'return') { |
|
966 | + return array($file, $line); |
|
967 | + } |
|
905 | 968 | |
906 | 969 | // Is always a critical error. |
907 | - if (function_exists('log_error')) |
|
908 | - log_error($log_message, 'critical', $file, $line); |
|
970 | + if (function_exists('log_error')) { |
|
971 | + log_error($log_message, 'critical', $file, $line); |
|
972 | + } |
|
909 | 973 | |
910 | 974 | if (function_exists('fatal_error')) |
911 | 975 | { |
@@ -913,12 +977,12 @@ discard block |
||
913 | 977 | |
914 | 978 | // Cannot continue... |
915 | 979 | exit; |
980 | + } elseif ($error_type) { |
|
981 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
982 | + } else { |
|
983 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
984 | + } |
|
916 | 985 | } |
917 | - elseif ($error_type) |
|
918 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
919 | - else |
|
920 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
921 | -} |
|
922 | 986 | |
923 | 987 | /** |
924 | 988 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -935,10 +999,11 @@ discard block |
||
935 | 999 | '\\' => '\\\\', |
936 | 1000 | ); |
937 | 1001 | |
938 | - if ($translate_human_wildcards) |
|
939 | - $replacements += array( |
|
1002 | + if ($translate_human_wildcards) { |
|
1003 | + $replacements += array( |
|
940 | 1004 | '*' => '%', |
941 | 1005 | ); |
1006 | + } |
|
942 | 1007 | |
943 | 1008 | return strtr($string, $replacements); |
944 | 1009 | } |
@@ -952,8 +1017,9 @@ discard block |
||
952 | 1017 | */ |
953 | 1018 | function smf_is_resource($result) |
954 | 1019 | { |
955 | - if ($result instanceof mysqli_result) |
|
956 | - return true; |
|
1020 | + if ($result instanceof mysqli_result) { |
|
1021 | + return true; |
|
1022 | + } |
|
957 | 1023 | |
958 | 1024 | return false; |
959 | 1025 | } |
@@ -982,19 +1048,22 @@ discard block |
||
982 | 1048 | static $mysql_error_data_prep; |
983 | 1049 | |
984 | 1050 | // without database we can't do anything |
985 | - if (empty($db_connection)) |
|
986 | - return; |
|
1051 | + if (empty($db_connection)) { |
|
1052 | + return; |
|
1053 | + } |
|
987 | 1054 | |
988 | - if (empty($mysql_error_data_prep)) |
|
989 | - $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
1055 | + if (empty($mysql_error_data_prep)) { |
|
1056 | + $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
990 | 1057 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line, backtrace) |
991 | 1058 | VALUES( ?, ?, unhex(?), ?, ?, ?, ?, ?, ?, ?)' |
992 | 1059 | ); |
1060 | + } |
|
993 | 1061 | |
994 | - if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) |
|
995 | - $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
996 | - else |
|
997 | - $error_array[2] = null; |
|
1062 | + if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) { |
|
1063 | + $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
1064 | + } else { |
|
1065 | + $error_array[2] = null; |
|
1066 | + } |
|
998 | 1067 | mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssis', |
999 | 1068 | $error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6], |
1000 | 1069 | $error_array[7], $error_array[8], $error_array[9]); |
@@ -1016,8 +1085,9 @@ discard block |
||
1016 | 1085 | $count = count($array_values); |
1017 | 1086 | $then = ($desc ? ' THEN -' : ' THEN '); |
1018 | 1087 | |
1019 | - for ($i = 0; $i < $count; $i++) |
|
1020 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1088 | + for ($i = 0; $i < $count; $i++) { |
|
1089 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1090 | + } |
|
1021 | 1091 | |
1022 | 1092 | $return .= 'END'; |
1023 | 1093 | return $return; |
@@ -1043,17 +1113,20 @@ discard block |
||
1043 | 1113 | global $smcFunc; |
1044 | 1114 | static $return; |
1045 | 1115 | |
1046 | - if (isset($return)) |
|
1047 | - return $return; |
|
1116 | + if (isset($return)) { |
|
1117 | + return $return; |
|
1118 | + } |
|
1048 | 1119 | |
1049 | 1120 | db_extend('extra'); |
1050 | 1121 | |
1051 | 1122 | $version = $smcFunc['db_get_version'](); |
1052 | 1123 | |
1053 | - if (strpos(strtolower($version), 'mariadb') !== false) |
|
1054 | - $return = version_compare($version, '10.2.2', '>='); |
|
1055 | - else //mysql |
|
1124 | + if (strpos(strtolower($version), 'mariadb') !== false) { |
|
1125 | + $return = version_compare($version, '10.2.2', '>='); |
|
1126 | + } else { |
|
1127 | + //mysql |
|
1056 | 1128 | $return = version_compare($version, '8.0.1', '>='); |
1129 | + } |
|
1057 | 1130 | |
1058 | 1131 | return $return; |
1059 | 1132 | } |
@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | * @version 2.1 Beta 4 |
16 | 16 | */ |
17 | 17 | |
18 | -if (!defined('SMF')) |
|
18 | +if (!defined('SMF')) { |
|
19 | 19 | die('No direct access...'); |
20 | +} |
|
20 | 21 | |
21 | 22 | /** |
22 | 23 | * This helps organize things... |
@@ -37,13 +38,14 @@ discard block |
||
37 | 38 | |
38 | 39 | loadLanguage('PersonalMessage+Drafts'); |
39 | 40 | |
40 | - if (!isset($_REQUEST['xml'])) |
|
41 | - loadTemplate('PersonalMessage'); |
|
41 | + if (!isset($_REQUEST['xml'])) { |
|
42 | + loadTemplate('PersonalMessage'); |
|
43 | + } |
|
42 | 44 | |
43 | 45 | // Load up the members maximum message capacity. |
44 | - if ($user_info['is_admin']) |
|
45 | - $context['message_limit'] = 0; |
|
46 | - elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null) |
|
46 | + if ($user_info['is_admin']) { |
|
47 | + $context['message_limit'] = 0; |
|
48 | + } elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null) |
|
47 | 49 | { |
48 | 50 | // @todo Why do we do this? It seems like if they have any limit we should use it. |
49 | 51 | $request = $smcFunc['db_query']('', ' |
@@ -78,8 +80,9 @@ discard block |
||
78 | 80 | } |
79 | 81 | |
80 | 82 | // a previous message was sent successfully? show a small indication. |
81 | - if (isset($_GET['done']) && ($_GET['done'] == 'sent')) |
|
82 | - $context['pm_sent'] = true; |
|
83 | + if (isset($_GET['done']) && ($_GET['done'] == 'sent')) { |
|
84 | + $context['pm_sent'] = true; |
|
85 | + } |
|
83 | 86 | |
84 | 87 | $context['labels'] = array(); |
85 | 88 | |
@@ -210,11 +213,11 @@ discard block |
||
210 | 213 | { |
211 | 214 | $_REQUEST['sa'] = ''; |
212 | 215 | MessageFolder(); |
213 | - } |
|
214 | - else |
|
216 | + } else |
|
215 | 217 | { |
216 | - if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup') |
|
217 | - messageIndexBar($_REQUEST['sa']); |
|
218 | + if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup') { |
|
219 | + messageIndexBar($_REQUEST['sa']); |
|
220 | + } |
|
218 | 221 | |
219 | 222 | call_helper($subActions[$_REQUEST['sa']]); |
220 | 223 | } |
@@ -297,15 +300,16 @@ discard block |
||
297 | 300 | ); |
298 | 301 | |
299 | 302 | // Handle labels. |
300 | - if (empty($context['currently_using_labels'])) |
|
301 | - unset($pm_areas['labels']); |
|
302 | - else |
|
303 | + if (empty($context['currently_using_labels'])) { |
|
304 | + unset($pm_areas['labels']); |
|
305 | + } else |
|
303 | 306 | { |
304 | 307 | // Note we send labels by id as it will have less problems in the querystring. |
305 | 308 | foreach ($context['labels'] as $label) |
306 | 309 | { |
307 | - if ($label['id'] == -1) |
|
308 | - continue; |
|
310 | + if ($label['id'] == -1) { |
|
311 | + continue; |
|
312 | + } |
|
309 | 313 | |
310 | 314 | // Count the amount of unread items in labels. |
311 | 315 | $pm_areas['labels']['amt'] += $label['unread_messages']; |
@@ -356,8 +360,9 @@ discard block |
||
356 | 360 | unset($pm_areas); |
357 | 361 | |
358 | 362 | // No menu means no access. |
359 | - if (!$pm_include_data && (!$user_info['is_guest'] || validateSession())) |
|
360 | - fatal_lang_error('no_access', false); |
|
363 | + if (!$pm_include_data && (!$user_info['is_guest'] || validateSession())) { |
|
364 | + fatal_lang_error('no_access', false); |
|
365 | + } |
|
361 | 366 | |
362 | 367 | // Make a note of the Unique ID for this menu. |
363 | 368 | $context['pm_menu_id'] = $context['max_menu_id']; |
@@ -368,9 +373,10 @@ discard block |
||
368 | 373 | $context['menu_item_selected'] = $current_area; |
369 | 374 | |
370 | 375 | // Set the template for this area and add the profile layer. |
371 | - if (!isset($_REQUEST['xml'])) |
|
372 | - $context['template_layers'][] = 'pm'; |
|
373 | -} |
|
376 | + if (!isset($_REQUEST['xml'])) { |
|
377 | + $context['template_layers'][] = 'pm'; |
|
378 | + } |
|
379 | + } |
|
374 | 380 | |
375 | 381 | /** |
376 | 382 | * The popup for when we ask for the popup from the user. |
@@ -402,8 +408,9 @@ discard block |
||
402 | 408 | ) |
403 | 409 | ); |
404 | 410 | $pms = array(); |
405 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
406 | - $pms[] = $row[0]; |
|
411 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
412 | + $pms[] = $row[0]; |
|
413 | + } |
|
407 | 414 | $smcFunc['db_free_result']($request); |
408 | 415 | |
409 | 416 | if (!empty($pms)) |
@@ -431,8 +438,9 @@ discard block |
||
431 | 438 | ); |
432 | 439 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
433 | 440 | { |
434 | - if (!empty($row['id_member_from'])) |
|
435 | - $senders[] = $row['id_member_from']; |
|
441 | + if (!empty($row['id_member_from'])) { |
|
442 | + $senders[] = $row['id_member_from']; |
|
443 | + } |
|
436 | 444 | |
437 | 445 | $row['replied_to_you'] = $row['id_pm'] != $row['id_pm_head']; |
438 | 446 | $row['time'] = timeformat($row['timestamp']); |
@@ -442,13 +450,15 @@ discard block |
||
442 | 450 | $smcFunc['db_free_result']($request); |
443 | 451 | |
444 | 452 | $senders = loadMemberData($senders); |
445 | - foreach ($senders as $member) |
|
446 | - loadMemberContext($member); |
|
453 | + foreach ($senders as $member) { |
|
454 | + loadMemberContext($member); |
|
455 | + } |
|
447 | 456 | |
448 | 457 | // Having loaded everyone, attach them to the PMs. |
449 | - foreach ($context['unread_pms'] as $id_pm => $details) |
|
450 | - if (!empty($memberContext[$details['id_member_from']])) |
|
458 | + foreach ($context['unread_pms'] as $id_pm => $details) { |
|
459 | + if (!empty($memberContext[$details['id_member_from']])) |
|
451 | 460 | $context['unread_pms'][$id_pm]['member'] = &$memberContext[$details['id_member_from']]; |
461 | + } |
|
452 | 462 | } |
453 | 463 | } |
454 | 464 | |
@@ -468,12 +478,13 @@ discard block |
||
468 | 478 | } |
469 | 479 | |
470 | 480 | // Make sure the starting location is valid. |
471 | - if (isset($_GET['start']) && $_GET['start'] != 'new') |
|
472 | - $_GET['start'] = (int) $_GET['start']; |
|
473 | - elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first'])) |
|
474 | - $_GET['start'] = 0; |
|
475 | - else |
|
476 | - $_GET['start'] = 'new'; |
|
481 | + if (isset($_GET['start']) && $_GET['start'] != 'new') { |
|
482 | + $_GET['start'] = (int) $_GET['start']; |
|
483 | + } elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first'])) { |
|
484 | + $_GET['start'] = 0; |
|
485 | + } else { |
|
486 | + $_GET['start'] = 'new'; |
|
487 | + } |
|
477 | 488 | |
478 | 489 | // Set up some basic theme stuff. |
479 | 490 | $context['from_or_to'] = $context['folder'] != 'sent' ? 'from' : 'to'; |
@@ -487,9 +498,10 @@ discard block |
||
487 | 498 | list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']); |
488 | 499 | $sig_limits = explode(',', $sig_limits); |
489 | 500 | |
490 | - if (!empty($sig_limits[5]) || !empty($sig_limits[6])) |
|
491 | - addInlineCss(' |
|
501 | + if (!empty($sig_limits[5]) || !empty($sig_limits[6])) { |
|
502 | + addInlineCss(' |
|
492 | 503 | .signature img { ' . (!empty($sig_limits[5]) ? 'max-width: ' . (int) $sig_limits[5] . 'px; ' : '') . (!empty($sig_limits[6]) ? 'max-height: ' . (int) $sig_limits[6] . 'px; ' : '') . '}'); |
504 | + } |
|
493 | 505 | } |
494 | 506 | |
495 | 507 | $labelJoin = ''; |
@@ -501,8 +513,7 @@ discard block |
||
501 | 513 | { |
502 | 514 | $labelQuery = ' |
503 | 515 | AND pmr.in_inbox = 1'; |
504 | - } |
|
505 | - elseif ($context['folder'] != 'sent') |
|
516 | + } elseif ($context['folder'] != 'sent') |
|
506 | 517 | { |
507 | 518 | $labelJoin = ' |
508 | 519 | INNER JOIN {db_prefix}pm_labeled_messages AS pl ON (pl.id_pm = pmr.id_pm)'; |
@@ -544,22 +555,24 @@ discard block |
||
544 | 555 | $txt['delete_all'] = str_replace('PMBOX', $pmbox, $txt['delete_all']); |
545 | 556 | |
546 | 557 | // Now, build the link tree! |
547 | - if ($context['current_label_id'] == -1) |
|
548 | - $context['linktree'][] = array( |
|
558 | + if ($context['current_label_id'] == -1) { |
|
559 | + $context['linktree'][] = array( |
|
549 | 560 | 'url' => $scripturl . '?action=pm;f=' . $context['folder'], |
550 | 561 | 'name' => $pmbox |
551 | 562 | ); |
563 | + } |
|
552 | 564 | |
553 | 565 | // Build it further for a label. |
554 | - if ($context['current_label_id'] != -1) |
|
555 | - $context['linktree'][] = array( |
|
566 | + if ($context['current_label_id'] != -1) { |
|
567 | + $context['linktree'][] = array( |
|
556 | 568 | 'url' => $scripturl . '?action=pm;f=' . $context['folder'] . ';l=' . $context['current_label_id'], |
557 | 569 | 'name' => $txt['pm_current_label'] . ': ' . $context['current_label'] |
558 | 570 | ); |
571 | + } |
|
559 | 572 | |
560 | 573 | // Figure out how many messages there are. |
561 | - if ($context['folder'] == 'sent') |
|
562 | - $request = $smcFunc['db_query']('', ' |
|
574 | + if ($context['folder'] == 'sent') { |
|
575 | + $request = $smcFunc['db_query']('', ' |
|
563 | 576 | SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') |
564 | 577 | FROM {db_prefix}personal_messages AS pm |
565 | 578 | WHERE pm.id_member_from = {int:current_member} |
@@ -569,8 +582,8 @@ discard block |
||
569 | 582 | 'not_deleted' => 0, |
570 | 583 | ) |
571 | 584 | ); |
572 | - else |
|
573 | - $request = $smcFunc['db_query']('', ' |
|
585 | + } else { |
|
586 | + $request = $smcFunc['db_query']('', ' |
|
574 | 587 | SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') |
575 | 588 | FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? ' |
576 | 589 | INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . ' |
@@ -581,6 +594,7 @@ discard block |
||
581 | 594 | 'not_deleted' => 0, |
582 | 595 | ) |
583 | 596 | ); |
597 | + } |
|
584 | 598 | list ($max_messages) = $smcFunc['db_fetch_row']($request); |
585 | 599 | $smcFunc['db_free_result']($request); |
586 | 600 | |
@@ -589,10 +603,11 @@ discard block |
||
589 | 603 | $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
590 | 604 | |
591 | 605 | // Start on the last page. |
592 | - if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages) |
|
593 | - $_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage); |
|
594 | - elseif ($_GET['start'] < 0) |
|
595 | - $_GET['start'] = 0; |
|
606 | + if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages) { |
|
607 | + $_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage); |
|
608 | + } elseif ($_GET['start'] < 0) { |
|
609 | + $_GET['start'] = 0; |
|
610 | + } |
|
596 | 611 | |
597 | 612 | // ... but wait - what if we want to start from a specific message? |
598 | 613 | if (isset($_GET['pmid'])) |
@@ -600,19 +615,21 @@ discard block |
||
600 | 615 | $pmID = (int) $_GET['pmid']; |
601 | 616 | |
602 | 617 | // Make sure you have access to this PM. |
603 | - if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) |
|
604 | - fatal_lang_error('no_access', false); |
|
618 | + if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) { |
|
619 | + fatal_lang_error('no_access', false); |
|
620 | + } |
|
605 | 621 | |
606 | 622 | $context['current_pm'] = $pmID; |
607 | 623 | |
608 | 624 | // With only one page of PM's we're gonna want page 1. |
609 | - if ($max_messages <= $maxPerPage) |
|
610 | - $_GET['start'] = 0; |
|
625 | + if ($max_messages <= $maxPerPage) { |
|
626 | + $_GET['start'] = 0; |
|
627 | + } |
|
611 | 628 | // If we pass kstart we assume we're in the right place. |
612 | 629 | elseif (!isset($_GET['kstart'])) |
613 | 630 | { |
614 | - if ($context['folder'] == 'sent') |
|
615 | - $request = $smcFunc['db_query']('', ' |
|
631 | + if ($context['folder'] == 'sent') { |
|
632 | + $request = $smcFunc['db_query']('', ' |
|
616 | 633 | SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') |
617 | 634 | FROM {db_prefix}personal_messages |
618 | 635 | WHERE id_member_from = {int:current_member} |
@@ -624,8 +641,8 @@ discard block |
||
624 | 641 | 'id_pm' => $pmID, |
625 | 642 | ) |
626 | 643 | ); |
627 | - else |
|
628 | - $request = $smcFunc['db_query']('', ' |
|
644 | + } else { |
|
645 | + $request = $smcFunc['db_query']('', ' |
|
629 | 646 | SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') |
630 | 647 | FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? ' |
631 | 648 | INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . ' |
@@ -638,6 +655,7 @@ discard block |
||
638 | 655 | 'id_pm' => $pmID, |
639 | 656 | ) |
640 | 657 | ); |
658 | + } |
|
641 | 659 | |
642 | 660 | list ($_GET['start']) = $smcFunc['db_fetch_row']($request); |
643 | 661 | $smcFunc['db_free_result']($request); |
@@ -652,8 +670,9 @@ discard block |
||
652 | 670 | { |
653 | 671 | $pmsg = (int) $_GET['pmsg']; |
654 | 672 | |
655 | - if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) |
|
656 | - fatal_lang_error('no_access', false); |
|
673 | + if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) { |
|
674 | + fatal_lang_error('no_access', false); |
|
675 | + } |
|
657 | 676 | } |
658 | 677 | |
659 | 678 | // Set up the page index. |
@@ -747,8 +766,9 @@ discard block |
||
747 | 766 | { |
748 | 767 | if (!isset($recipients[$row['id_pm']])) |
749 | 768 | { |
750 | - if (isset($row['id_member_from'])) |
|
751 | - $posters[$row['id_pm']] = $row['id_member_from']; |
|
769 | + if (isset($row['id_member_from'])) { |
|
770 | + $posters[$row['id_pm']] = $row['id_member_from']; |
|
771 | + } |
|
752 | 772 | $pms[$row['id_pm']] = $row['id_pm']; |
753 | 773 | $recipients[$row['id_pm']] = array( |
754 | 774 | 'to' => array(), |
@@ -757,29 +777,33 @@ discard block |
||
757 | 777 | } |
758 | 778 | |
759 | 779 | // Keep track of the last message so we know what the head is without another query! |
760 | - if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm'])) |
|
761 | - $lastData = array( |
|
780 | + if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm'])) { |
|
781 | + $lastData = array( |
|
762 | 782 | 'id' => $row['id_pm'], |
763 | 783 | 'head' => $row['id_pm_head'], |
764 | 784 | ); |
785 | + } |
|
765 | 786 | } |
766 | 787 | $smcFunc['db_free_result']($request); |
767 | 788 | |
768 | 789 | // Make sure that we have been given a correct head pm id! |
769 | - if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id']) |
|
770 | - fatal_lang_error('no_access', false); |
|
790 | + if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id']) { |
|
791 | + fatal_lang_error('no_access', false); |
|
792 | + } |
|
771 | 793 | |
772 | 794 | if (!empty($pms)) |
773 | 795 | { |
774 | 796 | // Select the correct current message. |
775 | - if (empty($pmID)) |
|
776 | - $context['current_pm'] = $lastData['id']; |
|
797 | + if (empty($pmID)) { |
|
798 | + $context['current_pm'] = $lastData['id']; |
|
799 | + } |
|
777 | 800 | |
778 | 801 | // This is a list of the pm's that are used for "full" display. |
779 | - if ($context['display_mode'] == 0) |
|
780 | - $display_pms = $pms; |
|
781 | - else |
|
782 | - $display_pms = array($context['current_pm']); |
|
802 | + if ($context['display_mode'] == 0) { |
|
803 | + $display_pms = $pms; |
|
804 | + } else { |
|
805 | + $display_pms = array($context['current_pm']); |
|
806 | + } |
|
783 | 807 | |
784 | 808 | // At this point we know the main id_pm's. But - if we are looking at conversations we need the others! |
785 | 809 | if ($context['display_mode'] == 2) |
@@ -801,16 +825,18 @@ discard block |
||
801 | 825 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
802 | 826 | { |
803 | 827 | // This is, frankly, a joke. We will put in a workaround for people sending to themselves - yawn! |
804 | - if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1) |
|
805 | - continue; |
|
806 | - elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1) |
|
807 | - continue; |
|
828 | + if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1) { |
|
829 | + continue; |
|
830 | + } elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1) { |
|
831 | + continue; |
|
832 | + } |
|
808 | 833 | |
809 | - if (!isset($recipients[$row['id_pm']])) |
|
810 | - $recipients[$row['id_pm']] = array( |
|
834 | + if (!isset($recipients[$row['id_pm']])) { |
|
835 | + $recipients[$row['id_pm']] = array( |
|
811 | 836 | 'to' => array(), |
812 | 837 | 'bcc' => array() |
813 | 838 | ); |
839 | + } |
|
814 | 840 | $display_pms[] = $row['id_pm']; |
815 | 841 | $posters[$row['id_pm']] = $row['id_member_from']; |
816 | 842 | } |
@@ -861,8 +887,9 @@ discard block |
||
861 | 887 | while ($row2 = $smcFunc['db_fetch_assoc']($request2)) |
862 | 888 | { |
863 | 889 | $l_id = $row2['id_label']; |
864 | - if (isset($context['labels'][$l_id])) |
|
865 | - $context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); |
|
890 | + if (isset($context['labels'][$l_id])) { |
|
891 | + $context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); |
|
892 | + } |
|
866 | 893 | } |
867 | 894 | |
868 | 895 | $smcFunc['db_free_result']($request2); |
@@ -879,9 +906,10 @@ discard block |
||
879 | 906 | // Make sure we don't load unnecessary data. |
880 | 907 | if ($context['display_mode'] == 1) |
881 | 908 | { |
882 | - foreach ($posters as $k => $v) |
|
883 | - if (!in_array($k, $display_pms)) |
|
909 | + foreach ($posters as $k => $v) { |
|
910 | + if (!in_array($k, $display_pms)) |
|
884 | 911 | unset($posters[$k]); |
912 | + } |
|
885 | 913 | } |
886 | 914 | |
887 | 915 | // Load any users.... |
@@ -892,8 +920,9 @@ discard block |
||
892 | 920 | { |
893 | 921 | // Get the order right. |
894 | 922 | $orderBy = array(); |
895 | - foreach (array_reverse($pms) as $pm) |
|
896 | - $orderBy[] = 'pm.id_pm = ' . $pm; |
|
923 | + foreach (array_reverse($pms) as $pm) { |
|
924 | + $orderBy[] = 'pm.id_pm = ' . $pm; |
|
925 | + } |
|
897 | 926 | |
898 | 927 | // Seperate query for these bits! |
899 | 928 | $subjects_request = $smcFunc['db_query']('', ' |
@@ -939,9 +968,9 @@ discard block |
||
939 | 968 | // Allow mods to add additional buttons here |
940 | 969 | call_integration_hook('integrate_conversation_buttons'); |
941 | 970 | } |
971 | + } else { |
|
972 | + $messages_request = false; |
|
942 | 973 | } |
943 | - else |
|
944 | - $messages_request = false; |
|
945 | 974 | |
946 | 975 | $context['can_send_pm'] = allowedTo('pm_send'); |
947 | 976 | $context['can_send_email'] = allowedTo('moderate_forum'); |
@@ -952,11 +981,13 @@ discard block |
||
952 | 981 | if ($context['folder'] != 'sent' && !empty($context['labels'][(int) $context['current_label_id']]['unread_messages'])) |
953 | 982 | { |
954 | 983 | // If the display mode is "old sk00l" do them all... |
955 | - if ($context['display_mode'] == 0) |
|
956 | - markMessages(null, $context['current_label_id']); |
|
984 | + if ($context['display_mode'] == 0) { |
|
985 | + markMessages(null, $context['current_label_id']); |
|
986 | + } |
|
957 | 987 | // Otherwise do just the current one! |
958 | - elseif (!empty($context['current_pm'])) |
|
959 | - markMessages($display_pms, $context['current_label_id']); |
|
988 | + elseif (!empty($context['current_pm'])) { |
|
989 | + markMessages($display_pms, $context['current_label_id']); |
|
990 | + } |
|
960 | 991 | } |
961 | 992 | } |
962 | 993 | |
@@ -974,8 +1005,9 @@ discard block |
||
974 | 1005 | |
975 | 1006 | // Count the current message number.... |
976 | 1007 | static $counter = null; |
977 | - if ($counter === null || $reset) |
|
978 | - $counter = $context['start']; |
|
1008 | + if ($counter === null || $reset) { |
|
1009 | + $counter = $context['start']; |
|
1010 | + } |
|
979 | 1011 | |
980 | 1012 | static $temp_pm_selected = null; |
981 | 1013 | if ($temp_pm_selected === null) |
@@ -1020,19 +1052,22 @@ discard block |
||
1020 | 1052 | } |
1021 | 1053 | |
1022 | 1054 | // Bail if it's false, ie. no messages. |
1023 | - if ($messages_request == false) |
|
1024 | - return false; |
|
1055 | + if ($messages_request == false) { |
|
1056 | + return false; |
|
1057 | + } |
|
1025 | 1058 | |
1026 | 1059 | // Reset the data? |
1027 | - if ($reset == true) |
|
1028 | - return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1060 | + if ($reset == true) { |
|
1061 | + return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1062 | + } |
|
1029 | 1063 | |
1030 | 1064 | // Get the next one... bail if anything goes wrong. |
1031 | 1065 | $message = $smcFunc['db_fetch_assoc']($messages_request); |
1032 | 1066 | if (!$message) |
1033 | 1067 | { |
1034 | - if ($type != 'subject') |
|
1035 | - $smcFunc['db_free_result']($messages_request); |
|
1068 | + if ($type != 'subject') { |
|
1069 | + $smcFunc['db_free_result']($messages_request); |
|
1070 | + } |
|
1036 | 1071 | |
1037 | 1072 | return false; |
1038 | 1073 | } |
@@ -1052,8 +1087,7 @@ discard block |
||
1052 | 1087 | $memberContext[$message['id_member_from']]['email'] = ''; |
1053 | 1088 | $memberContext[$message['id_member_from']]['show_email'] = false; |
1054 | 1089 | $memberContext[$message['id_member_from']]['is_guest'] = true; |
1055 | - } |
|
1056 | - else |
|
1090 | + } else |
|
1057 | 1091 | { |
1058 | 1092 | $memberContext[$message['id_member_from']]['can_view_profile'] = allowedTo('profile_view') || ($message['id_member_from'] == $user_info['id'] && !$user_info['is_guest']); |
1059 | 1093 | $memberContext[$message['id_member_from']]['can_see_warning'] = !isset($context['disabled_fields']['warning_status']) && $memberContext[$message['id_member_from']]['warning_status'] && ($context['user']['can_mod'] || (!empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $message['id_member_from'] == $user_info['id']))); |
@@ -1094,9 +1128,10 @@ discard block |
||
1094 | 1128 | $counter++; |
1095 | 1129 | |
1096 | 1130 | // Any custom profile fields? |
1097 | - if (!empty($memberContext[$message['id_member_from']]['custom_fields'])) |
|
1098 | - foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom) |
|
1131 | + if (!empty($memberContext[$message['id_member_from']]['custom_fields'])) { |
|
1132 | + foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom) |
|
1099 | 1133 | $output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom; |
1134 | + } |
|
1100 | 1135 | |
1101 | 1136 | call_integration_hook('integrate_prepare_pm_context', array(&$output, &$message, $counter)); |
1102 | 1137 | |
@@ -1120,22 +1155,28 @@ discard block |
||
1120 | 1155 | $context['search_params'][$k] = $v; |
1121 | 1156 | } |
1122 | 1157 | } |
1123 | - if (isset($_REQUEST['search'])) |
|
1124 | - $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']); |
|
1158 | + if (isset($_REQUEST['search'])) { |
|
1159 | + $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']); |
|
1160 | + } |
|
1125 | 1161 | |
1126 | - if (isset($context['search_params']['search'])) |
|
1127 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
1128 | - if (isset($context['search_params']['userspec'])) |
|
1129 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
1162 | + if (isset($context['search_params']['search'])) { |
|
1163 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
1164 | + } |
|
1165 | + if (isset($context['search_params']['userspec'])) { |
|
1166 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
1167 | + } |
|
1130 | 1168 | |
1131 | - if (!empty($context['search_params']['searchtype'])) |
|
1132 | - $context['search_params']['searchtype'] = 2; |
|
1169 | + if (!empty($context['search_params']['searchtype'])) { |
|
1170 | + $context['search_params']['searchtype'] = 2; |
|
1171 | + } |
|
1133 | 1172 | |
1134 | - if (!empty($context['search_params']['minage'])) |
|
1135 | - $context['search_params']['minage'] = (int) $context['search_params']['minage']; |
|
1173 | + if (!empty($context['search_params']['minage'])) { |
|
1174 | + $context['search_params']['minage'] = (int) $context['search_params']['minage']; |
|
1175 | + } |
|
1136 | 1176 | |
1137 | - if (!empty($context['search_params']['maxage'])) |
|
1138 | - $context['search_params']['maxage'] = (int) $context['search_params']['maxage']; |
|
1177 | + if (!empty($context['search_params']['maxage'])) { |
|
1178 | + $context['search_params']['maxage'] = (int) $context['search_params']['maxage']; |
|
1179 | + } |
|
1139 | 1180 | |
1140 | 1181 | $context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']); |
1141 | 1182 | $context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']); |
@@ -1162,8 +1203,9 @@ discard block |
||
1162 | 1203 | $context['search_errors']['messages'] = array(); |
1163 | 1204 | foreach ($context['search_errors'] as $search_error => $dummy) |
1164 | 1205 | { |
1165 | - if ($search_error == 'messages') |
|
1166 | - continue; |
|
1206 | + if ($search_error == 'messages') { |
|
1207 | + continue; |
|
1208 | + } |
|
1167 | 1209 | |
1168 | 1210 | $context['search_errors']['messages'][] = $txt['error_' . $search_error]; |
1169 | 1211 | } |
@@ -1185,8 +1227,9 @@ discard block |
||
1185 | 1227 | global $scripturl, $modSettings, $user_info, $context, $txt; |
1186 | 1228 | global $memberContext, $smcFunc; |
1187 | 1229 | |
1188 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) |
|
1189 | - fatal_lang_error('loadavg_search_disabled', false); |
|
1230 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) { |
|
1231 | + fatal_lang_error('loadavg_search_disabled', false); |
|
1232 | + } |
|
1190 | 1233 | |
1191 | 1234 | /** |
1192 | 1235 | * @todo For the moment force the folder to the inbox. |
@@ -1215,35 +1258,40 @@ discard block |
||
1215 | 1258 | $context['start'] = isset($_GET['start']) ? (int) $_GET['start'] : 0; |
1216 | 1259 | |
1217 | 1260 | // Store whether simple search was used (needed if the user wants to do another query). |
1218 | - if (!isset($search_params['advanced'])) |
|
1219 | - $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1; |
|
1261 | + if (!isset($search_params['advanced'])) { |
|
1262 | + $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1; |
|
1263 | + } |
|
1220 | 1264 | |
1221 | 1265 | // 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'. |
1222 | - if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) |
|
1223 | - $search_params['searchtype'] = 2; |
|
1266 | + if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) { |
|
1267 | + $search_params['searchtype'] = 2; |
|
1268 | + } |
|
1224 | 1269 | |
1225 | 1270 | // Minimum age of messages. Default to zero (don't set param in that case). |
1226 | - if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) |
|
1227 | - $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage']; |
|
1271 | + if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) { |
|
1272 | + $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage']; |
|
1273 | + } |
|
1228 | 1274 | |
1229 | 1275 | // Maximum age of messages. Default to infinite (9999 days: param not set). |
1230 | - if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999)) |
|
1231 | - $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage']; |
|
1276 | + if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999)) { |
|
1277 | + $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage']; |
|
1278 | + } |
|
1232 | 1279 | |
1233 | 1280 | $search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']); |
1234 | 1281 | $search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']); |
1235 | 1282 | |
1236 | 1283 | // Default the user name to a wildcard matching every user (*). |
1237 | - if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) |
|
1238 | - $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec']; |
|
1284 | + if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) { |
|
1285 | + $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec']; |
|
1286 | + } |
|
1239 | 1287 | |
1240 | 1288 | // This will be full of all kinds of parameters! |
1241 | 1289 | $searchq_parameters = array(); |
1242 | 1290 | |
1243 | 1291 | // If there's no specific user, then don't mention it in the main query. |
1244 | - if (empty($search_params['userspec'])) |
|
1245 | - $userQuery = ''; |
|
1246 | - else |
|
1292 | + if (empty($search_params['userspec'])) { |
|
1293 | + $userQuery = ''; |
|
1294 | + } else |
|
1247 | 1295 | { |
1248 | 1296 | $userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('"' => '"')); |
1249 | 1297 | $userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')); |
@@ -1255,8 +1303,9 @@ discard block |
||
1255 | 1303 | { |
1256 | 1304 | $possible_users[$k] = trim($possible_users[$k]); |
1257 | 1305 | |
1258 | - if (strlen($possible_users[$k]) == 0) |
|
1259 | - unset($possible_users[$k]); |
|
1306 | + if (strlen($possible_users[$k]) == 0) { |
|
1307 | + unset($possible_users[$k]); |
|
1308 | + } |
|
1260 | 1309 | } |
1261 | 1310 | |
1262 | 1311 | if (!empty($possible_users)) |
@@ -1268,8 +1317,9 @@ discard block |
||
1268 | 1317 | { |
1269 | 1318 | $where_params['name_' . $k] = $v; |
1270 | 1319 | $where_clause[] = '{raw:real_name} LIKE {string:name_' . $k . '}'; |
1271 | - if (!isset($where_params['real_name'])) |
|
1272 | - $where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name'; |
|
1320 | + if (!isset($where_params['real_name'])) { |
|
1321 | + $where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name'; |
|
1322 | + } |
|
1273 | 1323 | } |
1274 | 1324 | |
1275 | 1325 | // Who matches those criteria? |
@@ -1282,28 +1332,28 @@ discard block |
||
1282 | 1332 | ); |
1283 | 1333 | |
1284 | 1334 | // Simply do nothing if there're too many members matching the criteria. |
1285 | - if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) |
|
1286 | - $userQuery = ''; |
|
1287 | - elseif ($smcFunc['db_num_rows']($request) == 0) |
|
1335 | + if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) { |
|
1336 | + $userQuery = ''; |
|
1337 | + } elseif ($smcFunc['db_num_rows']($request) == 0) |
|
1288 | 1338 | { |
1289 | 1339 | $userQuery = 'AND pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})'; |
1290 | 1340 | $searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\''; |
1291 | 1341 | $searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name'; |
1292 | - } |
|
1293 | - else |
|
1342 | + } else |
|
1294 | 1343 | { |
1295 | 1344 | $memberlist = array(); |
1296 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1297 | - $memberlist[] = $row['id_member']; |
|
1345 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1346 | + $memberlist[] = $row['id_member']; |
|
1347 | + } |
|
1298 | 1348 | $userQuery = 'AND (pm.id_member_from IN ({array_int:member_list}) OR (pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})))'; |
1299 | 1349 | $searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\''; |
1300 | 1350 | $searchq_parameters['member_list'] = $memberlist; |
1301 | 1351 | $searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name'; |
1302 | 1352 | } |
1303 | 1353 | $smcFunc['db_free_result']($request); |
1354 | + } else { |
|
1355 | + $userQuery = ''; |
|
1304 | 1356 | } |
1305 | - else |
|
1306 | - $userQuery = ''; |
|
1307 | 1357 | } |
1308 | 1358 | |
1309 | 1359 | // Setup the sorting variables... |
@@ -1311,8 +1361,9 @@ discard block |
||
1311 | 1361 | $sort_columns = array( |
1312 | 1362 | 'pm.id_pm', |
1313 | 1363 | ); |
1314 | - if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) |
|
1315 | - list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); |
|
1364 | + if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) { |
|
1365 | + list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); |
|
1366 | + } |
|
1316 | 1367 | $search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'pm.id_pm'; |
1317 | 1368 | $search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc'; |
1318 | 1369 | |
@@ -1322,24 +1373,27 @@ discard block |
||
1322 | 1373 | if ($context['folder'] == 'inbox' && !empty($search_params['advanced']) && $context['currently_using_labels']) |
1323 | 1374 | { |
1324 | 1375 | // Came here from pagination? Put them back into $_REQUEST for sanitization. |
1325 | - if (isset($search_params['labels'])) |
|
1326 | - $_REQUEST['searchlabel'] = explode(',', $search_params['labels']); |
|
1376 | + if (isset($search_params['labels'])) { |
|
1377 | + $_REQUEST['searchlabel'] = explode(',', $search_params['labels']); |
|
1378 | + } |
|
1327 | 1379 | |
1328 | 1380 | // Assuming we have some labels - make them all integers. |
1329 | 1381 | if (!empty($_REQUEST['searchlabel']) && is_array($_REQUEST['searchlabel'])) |
1330 | 1382 | { |
1331 | - foreach ($_REQUEST['searchlabel'] as $key => $id) |
|
1332 | - $_REQUEST['searchlabel'][$key] = (int) $id; |
|
1383 | + foreach ($_REQUEST['searchlabel'] as $key => $id) { |
|
1384 | + $_REQUEST['searchlabel'][$key] = (int) $id; |
|
1385 | + } |
|
1386 | + } else { |
|
1387 | + $_REQUEST['searchlabel'] = array(); |
|
1333 | 1388 | } |
1334 | - else |
|
1335 | - $_REQUEST['searchlabel'] = array(); |
|
1336 | 1389 | |
1337 | 1390 | // Now that everything is cleaned up a bit, make the labels a param. |
1338 | 1391 | $search_params['labels'] = implode(',', $_REQUEST['searchlabel']); |
1339 | 1392 | |
1340 | 1393 | // No labels selected? That must be an error! |
1341 | - if (empty($_REQUEST['searchlabel'])) |
|
1342 | - $context['search_errors']['no_labels_selected'] = true; |
|
1394 | + if (empty($_REQUEST['searchlabel'])) { |
|
1395 | + $context['search_errors']['no_labels_selected'] = true; |
|
1396 | + } |
|
1343 | 1397 | // Otherwise prepare the query! |
1344 | 1398 | elseif (count($_REQUEST['searchlabel']) != count($context['labels'])) |
1345 | 1399 | { |
@@ -1362,8 +1416,7 @@ discard block |
||
1362 | 1416 | // Not searching the inbox - PM must be labeled |
1363 | 1417 | $labelQuery = ' AND pml.id_label IN ({array_int:labels})'; |
1364 | 1418 | $labelJoin = ' INNER JOIN {db_prefix}pm_labeled_messages AS pml ON (pml.id_pm = pmr.id_pm)'; |
1365 | - } |
|
1366 | - else |
|
1419 | + } else |
|
1367 | 1420 | { |
1368 | 1421 | // Searching the inbox - PM doesn't have to be labeled |
1369 | 1422 | $labelQuery = ' AND (' . substr($labelQuery, 5) . ' OR pml.id_label IN ({array_int:labels}))'; |
@@ -1378,8 +1431,9 @@ discard block |
||
1378 | 1431 | // What are we actually searching for? |
1379 | 1432 | $search_params['search'] = !empty($search_params['search']) ? $search_params['search'] : (isset($_REQUEST['search']) ? $_REQUEST['search'] : ''); |
1380 | 1433 | // If we ain't got nothing - we should error! |
1381 | - if (!isset($search_params['search']) || $search_params['search'] == '') |
|
1382 | - $context['search_errors']['invalid_search_string'] = true; |
|
1434 | + if (!isset($search_params['search']) || $search_params['search'] == '') { |
|
1435 | + $context['search_errors']['invalid_search_string'] = true; |
|
1436 | + } |
|
1383 | 1437 | |
1384 | 1438 | // Extract phrase parts first (e.g. some words "this is a phrase" some more words.) |
1385 | 1439 | preg_match_all('~(?:^|\s)([-]?)"([^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), $search_params['search'], $matches, PREG_PATTERN_ORDER); |
@@ -1392,12 +1446,14 @@ discard block |
||
1392 | 1446 | $excludedWords = array(); |
1393 | 1447 | |
1394 | 1448 | // .. first, we check for things like -"some words", but not "-some words". |
1395 | - foreach ($matches[1] as $index => $word) |
|
1396 | - if ($word == '-') |
|
1449 | + foreach ($matches[1] as $index => $word) { |
|
1450 | + if ($word == '-') |
|
1397 | 1451 | { |
1398 | 1452 | $word = $smcFunc['strtolower'](trim($searchArray[$index])); |
1399 | - if (strlen($word) > 0) |
|
1400 | - $excludedWords[] = $word; |
|
1453 | + } |
|
1454 | + if (strlen($word) > 0) { |
|
1455 | + $excludedWords[] = $word; |
|
1456 | + } |
|
1401 | 1457 | unset($searchArray[$index]); |
1402 | 1458 | } |
1403 | 1459 | |
@@ -1407,8 +1463,9 @@ discard block |
||
1407 | 1463 | if (strpos(trim($word), '-') === 0) |
1408 | 1464 | { |
1409 | 1465 | $word = substr($smcFunc['strtolower']($word), 1); |
1410 | - if (strlen($word) > 0) |
|
1411 | - $excludedWords[] = $word; |
|
1466 | + if (strlen($word) > 0) { |
|
1467 | + $excludedWords[] = $word; |
|
1468 | + } |
|
1412 | 1469 | unset($tempSearch[$index]); |
1413 | 1470 | } |
1414 | 1471 | } |
@@ -1419,9 +1476,9 @@ discard block |
||
1419 | 1476 | foreach ($searchArray as $index => $value) |
1420 | 1477 | { |
1421 | 1478 | $searchArray[$index] = $smcFunc['strtolower'](trim($value)); |
1422 | - if ($searchArray[$index] == '') |
|
1423 | - unset($searchArray[$index]); |
|
1424 | - else |
|
1479 | + if ($searchArray[$index] == '') { |
|
1480 | + unset($searchArray[$index]); |
|
1481 | + } else |
|
1425 | 1482 | { |
1426 | 1483 | // Sort out entities first. |
1427 | 1484 | $searchArray[$index] = $smcFunc['htmlspecialchars']($searchArray[$index]); |
@@ -1431,27 +1488,32 @@ discard block |
||
1431 | 1488 | |
1432 | 1489 | // Create an array of replacements for highlighting. |
1433 | 1490 | $context['mark'] = array(); |
1434 | - foreach ($searchArray as $word) |
|
1435 | - $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>'; |
|
1491 | + foreach ($searchArray as $word) { |
|
1492 | + $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>'; |
|
1493 | + } |
|
1436 | 1494 | |
1437 | 1495 | // This contains *everything* |
1438 | 1496 | $searchWords = array_merge($searchArray, $excludedWords); |
1439 | 1497 | |
1440 | 1498 | // Make sure at least one word is being searched for. |
1441 | - if (empty($searchArray)) |
|
1442 | - $context['search_errors']['invalid_search_string'] = true; |
|
1499 | + if (empty($searchArray)) { |
|
1500 | + $context['search_errors']['invalid_search_string'] = true; |
|
1501 | + } |
|
1443 | 1502 | |
1444 | 1503 | // Sort out the search query so the user can edit it - if they want. |
1445 | 1504 | $context['search_params'] = $search_params; |
1446 | - if (isset($context['search_params']['search'])) |
|
1447 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
1448 | - if (isset($context['search_params']['userspec'])) |
|
1449 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
1505 | + if (isset($context['search_params']['search'])) { |
|
1506 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
1507 | + } |
|
1508 | + if (isset($context['search_params']['userspec'])) { |
|
1509 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
1510 | + } |
|
1450 | 1511 | |
1451 | 1512 | // Now we have all the parameters, combine them together for pagination and the like... |
1452 | 1513 | $context['params'] = array(); |
1453 | - foreach ($search_params as $k => $v) |
|
1454 | - $context['params'][] = $k . '|\'|' . $v; |
|
1514 | + foreach ($search_params as $k => $v) { |
|
1515 | + $context['params'][] = $k . '|\'|' . $v; |
|
1516 | + } |
|
1455 | 1517 | $context['params'] = base64_encode(implode('|"|', $context['params'])); |
1456 | 1518 | |
1457 | 1519 | // Compile the subject query part. |
@@ -1459,26 +1521,31 @@ discard block |
||
1459 | 1521 | |
1460 | 1522 | foreach ($searchWords as $index => $word) |
1461 | 1523 | { |
1462 | - if ($word == '') |
|
1463 | - continue; |
|
1524 | + if ($word == '') { |
|
1525 | + continue; |
|
1526 | + } |
|
1464 | 1527 | |
1465 | - if ($search_params['subject_only']) |
|
1466 | - $andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}'; |
|
1467 | - else |
|
1468 | - $andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})'; |
|
1528 | + if ($search_params['subject_only']) { |
|
1529 | + $andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}'; |
|
1530 | + } else { |
|
1531 | + $andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})'; |
|
1532 | + } |
|
1469 | 1533 | $searchq_parameters['search_' . $index] = '%' . strtr($word, array('_' => '\\_', '%' => '\\%')) . '%'; |
1470 | 1534 | } |
1471 | 1535 | |
1472 | 1536 | $searchQuery = ' 1=1'; |
1473 | - if (!empty($andQueryParts)) |
|
1474 | - $searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts); |
|
1537 | + if (!empty($andQueryParts)) { |
|
1538 | + $searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts); |
|
1539 | + } |
|
1475 | 1540 | |
1476 | 1541 | // Age limits? |
1477 | 1542 | $timeQuery = ''; |
1478 | - if (!empty($search_params['minage'])) |
|
1479 | - $timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400); |
|
1480 | - if (!empty($search_params['maxage'])) |
|
1481 | - $timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400); |
|
1543 | + if (!empty($search_params['minage'])) { |
|
1544 | + $timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400); |
|
1545 | + } |
|
1546 | + if (!empty($search_params['maxage'])) { |
|
1547 | + $timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400); |
|
1548 | + } |
|
1482 | 1549 | |
1483 | 1550 | // If we have errors - return back to the first screen... |
1484 | 1551 | if (!empty($context['search_errors'])) |
@@ -1564,8 +1631,9 @@ discard block |
||
1564 | 1631 | ) |
1565 | 1632 | ); |
1566 | 1633 | $real_pm_ids = array(); |
1567 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1568 | - $real_pm_ids[$row['id_pm_head']] = $row['id_pm']; |
|
1634 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1635 | + $real_pm_ids[$row['id_pm_head']] = $row['id_pm']; |
|
1636 | + } |
|
1569 | 1637 | $smcFunc['db_free_result']($request); |
1570 | 1638 | } |
1571 | 1639 | |
@@ -1595,8 +1663,9 @@ discard block |
||
1595 | 1663 | ); |
1596 | 1664 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1597 | 1665 | { |
1598 | - if ($context['folder'] == 'sent' || empty($row['bcc'])) |
|
1599 | - $recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>'; |
|
1666 | + if ($context['folder'] == 'sent' || empty($row['bcc'])) { |
|
1667 | + $recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>'; |
|
1668 | + } |
|
1600 | 1669 | |
1601 | 1670 | if ($row['id_member_to'] == $user_info['id'] && $context['folder'] != 'sent') |
1602 | 1671 | { |
@@ -1617,12 +1686,14 @@ discard block |
||
1617 | 1686 | while ($row2 = $smcFunc['db_fetch_assoc']($request2)) |
1618 | 1687 | { |
1619 | 1688 | $l_id = $row2['id_label']; |
1620 | - if (isset($context['labels'][$l_id])) |
|
1621 | - $context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); |
|
1689 | + if (isset($context['labels'][$l_id])) { |
|
1690 | + $context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); |
|
1691 | + } |
|
1622 | 1692 | |
1623 | 1693 | // Here we find the first label on a message - for linking to posts in results |
1624 | - if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1) |
|
1625 | - $context['first_label'][$row['id_pm']] = $l_id; |
|
1694 | + if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1) { |
|
1695 | + $context['first_label'][$row['id_pm']] = $l_id; |
|
1696 | + } |
|
1626 | 1697 | } |
1627 | 1698 | |
1628 | 1699 | $smcFunc['db_free_result']($request2); |
@@ -1749,8 +1820,9 @@ discard block |
||
1749 | 1820 | list ($postCount) = $smcFunc['db_fetch_row']($request); |
1750 | 1821 | $smcFunc['db_free_result']($request); |
1751 | 1822 | |
1752 | - if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) |
|
1753 | - fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); |
|
1823 | + if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) { |
|
1824 | + fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); |
|
1825 | + } |
|
1754 | 1826 | } |
1755 | 1827 | |
1756 | 1828 | // Quoting/Replying to a message? |
@@ -1759,8 +1831,9 @@ discard block |
||
1759 | 1831 | $pmsg = (int) $_REQUEST['pmsg']; |
1760 | 1832 | |
1761 | 1833 | // Make sure this is yours. |
1762 | - if (!isAccessiblePM($pmsg)) |
|
1763 | - fatal_lang_error('no_access', false); |
|
1834 | + if (!isAccessiblePM($pmsg)) { |
|
1835 | + fatal_lang_error('no_access', false); |
|
1836 | + } |
|
1764 | 1837 | |
1765 | 1838 | // Work out whether this is one you've received? |
1766 | 1839 | $request = $smcFunc['db_query']('', ' |
@@ -1797,8 +1870,9 @@ discard block |
||
1797 | 1870 | 'id_pm' => $pmsg, |
1798 | 1871 | ) |
1799 | 1872 | ); |
1800 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
1801 | - fatal_lang_error('pm_not_yours', false); |
|
1873 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
1874 | + fatal_lang_error('pm_not_yours', false); |
|
1875 | + } |
|
1802 | 1876 | $row_quoted = $smcFunc['db_fetch_assoc']($request); |
1803 | 1877 | $smcFunc['db_free_result']($request); |
1804 | 1878 | |
@@ -1809,9 +1883,9 @@ discard block |
||
1809 | 1883 | // Add 'Re: ' to it.... |
1810 | 1884 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
1811 | 1885 | { |
1812 | - if ($language === $user_info['language']) |
|
1813 | - $context['response_prefix'] = $txt['response_prefix']; |
|
1814 | - else |
|
1886 | + if ($language === $user_info['language']) { |
|
1887 | + $context['response_prefix'] = $txt['response_prefix']; |
|
1888 | + } else |
|
1815 | 1889 | { |
1816 | 1890 | loadLanguage('index', $language, false); |
1817 | 1891 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -1820,22 +1894,25 @@ discard block |
||
1820 | 1894 | cache_put_data('response_prefix', $context['response_prefix'], 600); |
1821 | 1895 | } |
1822 | 1896 | $form_subject = $row_quoted['subject']; |
1823 | - if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
|
1824 | - $form_subject = $context['response_prefix'] . $form_subject; |
|
1897 | + if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) { |
|
1898 | + $form_subject = $context['response_prefix'] . $form_subject; |
|
1899 | + } |
|
1825 | 1900 | |
1826 | 1901 | if (isset($_REQUEST['quote'])) |
1827 | 1902 | { |
1828 | 1903 | // Remove any nested quotes and <br>... |
1829 | 1904 | $form_message = preg_replace('~<br ?/?' . '>~i', "\n", $row_quoted['body']); |
1830 | - if (!empty($modSettings['removeNestedQuotes'])) |
|
1831 | - $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
1832 | - if (empty($row_quoted['id_member'])) |
|
1833 | - $form_message = '[quote author="' . $row_quoted['real_name'] . '"]' . "\n" . $form_message . "\n" . '[/quote]'; |
|
1834 | - else |
|
1835 | - $form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]'; |
|
1905 | + if (!empty($modSettings['removeNestedQuotes'])) { |
|
1906 | + $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
1907 | + } |
|
1908 | + if (empty($row_quoted['id_member'])) { |
|
1909 | + $form_message = '[quote author="' . $row_quoted['real_name'] . '"]' . "\n" . $form_message . "\n" . '[/quote]'; |
|
1910 | + } else { |
|
1911 | + $form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]'; |
|
1912 | + } |
|
1913 | + } else { |
|
1914 | + $form_message = ''; |
|
1836 | 1915 | } |
1837 | - else |
|
1838 | - $form_message = ''; |
|
1839 | 1916 | |
1840 | 1917 | // Do the BBC thang on the message. |
1841 | 1918 | $row_quoted['body'] = parse_bbc($row_quoted['body'], true, 'pm' . $row_quoted['id_pm']); |
@@ -1856,8 +1933,7 @@ discard block |
||
1856 | 1933 | 'timestamp' => forum_time(true, $row_quoted['msgtime']), |
1857 | 1934 | 'body' => $row_quoted['body'] |
1858 | 1935 | ); |
1859 | - } |
|
1860 | - else |
|
1936 | + } else |
|
1861 | 1937 | { |
1862 | 1938 | $context['quoted_message'] = false; |
1863 | 1939 | $form_subject = ''; |
@@ -1876,11 +1952,12 @@ discard block |
||
1876 | 1952 | if ($_REQUEST['u'] == 'all' && isset($row_quoted)) |
1877 | 1953 | { |
1878 | 1954 | // Firstly, to reply to all we clearly already have $row_quoted - so have the original member from. |
1879 | - if ($row_quoted['id_member'] != $user_info['id']) |
|
1880 | - $context['recipients']['to'][] = array( |
|
1955 | + if ($row_quoted['id_member'] != $user_info['id']) { |
|
1956 | + $context['recipients']['to'][] = array( |
|
1881 | 1957 | 'id' => $row_quoted['id_member'], |
1882 | 1958 | 'name' => $smcFunc['htmlspecialchars']($row_quoted['real_name']), |
1883 | 1959 | ); |
1960 | + } |
|
1884 | 1961 | |
1885 | 1962 | // Now to get the others. |
1886 | 1963 | $request = $smcFunc['db_query']('', ' |
@@ -1896,18 +1973,19 @@ discard block |
||
1896 | 1973 | 'not_bcc' => 0, |
1897 | 1974 | ) |
1898 | 1975 | ); |
1899 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1900 | - $context['recipients']['to'][] = array( |
|
1976 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1977 | + $context['recipients']['to'][] = array( |
|
1901 | 1978 | 'id' => $row['id_member'], |
1902 | 1979 | 'name' => $row['real_name'], |
1903 | 1980 | ); |
1981 | + } |
|
1904 | 1982 | $smcFunc['db_free_result']($request); |
1905 | - } |
|
1906 | - else |
|
1983 | + } else |
|
1907 | 1984 | { |
1908 | 1985 | $_REQUEST['u'] = explode(',', $_REQUEST['u']); |
1909 | - foreach ($_REQUEST['u'] as $key => $uID) |
|
1910 | - $_REQUEST['u'][$key] = (int) $uID; |
|
1986 | + foreach ($_REQUEST['u'] as $key => $uID) { |
|
1987 | + $_REQUEST['u'][$key] = (int) $uID; |
|
1988 | + } |
|
1911 | 1989 | |
1912 | 1990 | $_REQUEST['u'] = array_unique($_REQUEST['u']); |
1913 | 1991 | |
@@ -1921,22 +1999,24 @@ discard block |
||
1921 | 1999 | 'limit' => count($_REQUEST['u']), |
1922 | 2000 | ) |
1923 | 2001 | ); |
1924 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1925 | - $context['recipients']['to'][] = array( |
|
2002 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2003 | + $context['recipients']['to'][] = array( |
|
1926 | 2004 | 'id' => $row['id_member'], |
1927 | 2005 | 'name' => $row['real_name'], |
1928 | 2006 | ); |
2007 | + } |
|
1929 | 2008 | $smcFunc['db_free_result']($request); |
1930 | 2009 | } |
1931 | 2010 | |
1932 | 2011 | // Get a literal name list in case the user has JavaScript disabled. |
1933 | 2012 | $names = array(); |
1934 | - foreach ($context['recipients']['to'] as $to) |
|
1935 | - $names[] = $to['name']; |
|
2013 | + foreach ($context['recipients']['to'] as $to) { |
|
2014 | + $names[] = $to['name']; |
|
2015 | + } |
|
1936 | 2016 | $context['to_value'] = empty($names) ? '' : '"' . implode('", "', $names) . '"'; |
2017 | + } else { |
|
2018 | + $context['to_value'] = ''; |
|
1937 | 2019 | } |
1938 | - else |
|
1939 | - $context['to_value'] = ''; |
|
1940 | 2020 | |
1941 | 2021 | // Set the defaults... |
1942 | 2022 | $context['subject'] = $form_subject; |
@@ -2006,8 +2086,9 @@ discard block |
||
2006 | 2086 | |
2007 | 2087 | // validate with loadMemberData() |
2008 | 2088 | $memberResult = loadMemberData($user_info['id'], false); |
2009 | - if (!$memberResult) |
|
2010 | - fatal_lang_error('not_a_user', false); |
|
2089 | + if (!$memberResult) { |
|
2090 | + fatal_lang_error('not_a_user', false); |
|
2091 | + } |
|
2011 | 2092 | list ($memID) = $memberResult; |
2012 | 2093 | |
2013 | 2094 | // drafts is where the functions reside |
@@ -2033,9 +2114,9 @@ discard block |
||
2033 | 2114 | $context['sub_template'] = 'send'; |
2034 | 2115 | loadJavaScriptFile('PersonalMessage.js', array('defer' => false, 'minimize' => true), 'smf_pms'); |
2035 | 2116 | loadJavaScriptFile('suggest.js', array('defer' => false, 'minimize' => true), 'smf_suggest'); |
2117 | + } else { |
|
2118 | + $context['sub_template'] = 'pm'; |
|
2036 | 2119 | } |
2037 | - else |
|
2038 | - $context['sub_template'] = 'pm'; |
|
2039 | 2120 | |
2040 | 2121 | $context['page_title'] = $txt['send_message']; |
2041 | 2122 | |
@@ -2096,10 +2177,11 @@ discard block |
||
2096 | 2177 | ); |
2097 | 2178 | if ($smcFunc['db_num_rows']($request) == 0) |
2098 | 2179 | { |
2099 | - if (!isset($_REQUEST['xml'])) |
|
2100 | - fatal_lang_error('pm_not_yours', false); |
|
2101 | - else |
|
2102 | - $error_types[] = 'pm_not_yours'; |
|
2180 | + if (!isset($_REQUEST['xml'])) { |
|
2181 | + fatal_lang_error('pm_not_yours', false); |
|
2182 | + } else { |
|
2183 | + $error_types[] = 'pm_not_yours'; |
|
2184 | + } |
|
2103 | 2185 | } |
2104 | 2186 | $row_quoted = $smcFunc['db_fetch_assoc']($request); |
2105 | 2187 | $smcFunc['db_free_result']($request); |
@@ -2146,14 +2228,16 @@ discard block |
||
2146 | 2228 | $context['post_error'][$error_type] = true; |
2147 | 2229 | if (isset($txt['error_' . $error_type])) |
2148 | 2230 | { |
2149 | - if ($error_type == 'long_message') |
|
2150 | - $txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']); |
|
2231 | + if ($error_type == 'long_message') { |
|
2232 | + $txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']); |
|
2233 | + } |
|
2151 | 2234 | $context['post_error']['messages'][] = $txt['error_' . $error_type]; |
2152 | 2235 | } |
2153 | 2236 | |
2154 | 2237 | // If it's not a minor error flag it as such. |
2155 | - if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'))) |
|
2156 | - $context['error_type'] = 'serious'; |
|
2238 | + if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'))) { |
|
2239 | + $context['error_type'] = 'serious'; |
|
2240 | + } |
|
2157 | 2241 | } |
2158 | 2242 | |
2159 | 2243 | // We need to load the editor once more. |
@@ -2211,8 +2295,9 @@ discard block |
||
2211 | 2295 | require_once($sourcedir . '/Subs-Auth.php'); |
2212 | 2296 | |
2213 | 2297 | // PM Drafts enabled and needed? |
2214 | - if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft']))) |
|
2215 | - require_once($sourcedir . '/Drafts.php'); |
|
2298 | + if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft']))) { |
|
2299 | + require_once($sourcedir . '/Drafts.php'); |
|
2300 | + } |
|
2216 | 2301 | |
2217 | 2302 | loadLanguage('PersonalMessage', '', false); |
2218 | 2303 | |
@@ -2242,24 +2327,27 @@ discard block |
||
2242 | 2327 | |
2243 | 2328 | if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) |
2244 | 2329 | { |
2245 | - if (!isset($_REQUEST['xml'])) |
|
2246 | - fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); |
|
2247 | - else |
|
2248 | - $post_errors[] = 'pm_too_many_per_hour'; |
|
2330 | + if (!isset($_REQUEST['xml'])) { |
|
2331 | + fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); |
|
2332 | + } else { |
|
2333 | + $post_errors[] = 'pm_too_many_per_hour'; |
|
2334 | + } |
|
2249 | 2335 | } |
2250 | 2336 | } |
2251 | 2337 | |
2252 | 2338 | // If your session timed out, show an error, but do allow to re-submit. |
2253 | - if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '') |
|
2254 | - $post_errors[] = 'session_timeout'; |
|
2339 | + if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '') { |
|
2340 | + $post_errors[] = 'session_timeout'; |
|
2341 | + } |
|
2255 | 2342 | |
2256 | 2343 | $_REQUEST['subject'] = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : ''; |
2257 | 2344 | $_REQUEST['to'] = empty($_POST['to']) ? (empty($_GET['to']) ? '' : $_GET['to']) : $_POST['to']; |
2258 | 2345 | $_REQUEST['bcc'] = empty($_POST['bcc']) ? (empty($_GET['bcc']) ? '' : $_GET['bcc']) : $_POST['bcc']; |
2259 | 2346 | |
2260 | 2347 | // Route the input from the 'u' parameter to the 'to'-list. |
2261 | - if (!empty($_POST['u'])) |
|
2262 | - $_POST['recipient_to'] = explode(',', $_POST['u']); |
|
2348 | + if (!empty($_POST['u'])) { |
|
2349 | + $_POST['recipient_to'] = explode(',', $_POST['u']); |
|
2350 | + } |
|
2263 | 2351 | |
2264 | 2352 | // Construct the list of recipients. |
2265 | 2353 | $recipientList = array(); |
@@ -2271,8 +2359,9 @@ discard block |
||
2271 | 2359 | $recipientList[$recipientType] = array(); |
2272 | 2360 | if (!empty($_POST['recipient_' . $recipientType]) && is_array($_POST['recipient_' . $recipientType])) |
2273 | 2361 | { |
2274 | - foreach ($_POST['recipient_' . $recipientType] as $recipient) |
|
2275 | - $recipientList[$recipientType][] = (int) $recipient; |
|
2362 | + foreach ($_POST['recipient_' . $recipientType] as $recipient) { |
|
2363 | + $recipientList[$recipientType][] = (int) $recipient; |
|
2364 | + } |
|
2276 | 2365 | } |
2277 | 2366 | |
2278 | 2367 | // Are there also literal names set? |
@@ -2286,10 +2375,11 @@ discard block |
||
2286 | 2375 | |
2287 | 2376 | foreach ($namedRecipientList[$recipientType] as $index => $recipient) |
2288 | 2377 | { |
2289 | - if (strlen(trim($recipient)) > 0) |
|
2290 | - $namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient))); |
|
2291 | - else |
|
2292 | - unset($namedRecipientList[$recipientType][$index]); |
|
2378 | + if (strlen(trim($recipient)) > 0) { |
|
2379 | + $namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient))); |
|
2380 | + } else { |
|
2381 | + unset($namedRecipientList[$recipientType][$index]); |
|
2382 | + } |
|
2293 | 2383 | } |
2294 | 2384 | |
2295 | 2385 | if (!empty($namedRecipientList[$recipientType])) |
@@ -2319,8 +2409,9 @@ discard block |
||
2319 | 2409 | } |
2320 | 2410 | |
2321 | 2411 | // Selected a recipient to be deleted? Remove them now. |
2322 | - if (!empty($_POST['delete_recipient'])) |
|
2323 | - $recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient'])); |
|
2412 | + if (!empty($_POST['delete_recipient'])) { |
|
2413 | + $recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient'])); |
|
2414 | + } |
|
2324 | 2415 | |
2325 | 2416 | // Make sure we don't include the same name twice |
2326 | 2417 | $recipientList[$recipientType] = array_unique($recipientList[$recipientType]); |
@@ -2330,8 +2421,9 @@ discard block |
||
2330 | 2421 | $is_recipient_change = !empty($_POST['delete_recipient']) || !empty($_POST['to_submit']) || !empty($_POST['bcc_submit']); |
2331 | 2422 | |
2332 | 2423 | // Check if there's at least one recipient. |
2333 | - if (empty($recipientList['to']) && empty($recipientList['bcc'])) |
|
2334 | - $post_errors[] = 'no_to'; |
|
2424 | + if (empty($recipientList['to']) && empty($recipientList['bcc'])) { |
|
2425 | + $post_errors[] = 'no_to'; |
|
2426 | + } |
|
2335 | 2427 | |
2336 | 2428 | // Make sure that we remove the members who did get it from the screen. |
2337 | 2429 | if (!$is_recipient_change) |
@@ -2345,28 +2437,31 @@ discard block |
||
2345 | 2437 | // Since we already have a post error, remove the previous one. |
2346 | 2438 | $post_errors = array_diff($post_errors, array('no_to')); |
2347 | 2439 | |
2348 | - foreach ($namesNotFound[$recipientType] as $name) |
|
2349 | - $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name); |
|
2440 | + foreach ($namesNotFound[$recipientType] as $name) { |
|
2441 | + $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name); |
|
2442 | + } |
|
2350 | 2443 | } |
2351 | 2444 | } |
2352 | 2445 | } |
2353 | 2446 | |
2354 | 2447 | // Did they make any mistakes? |
2355 | - if ($_REQUEST['subject'] == '') |
|
2356 | - $post_errors[] = 'no_subject'; |
|
2357 | - if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') |
|
2358 | - $post_errors[] = 'no_message'; |
|
2359 | - elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength']) |
|
2360 | - $post_errors[] = 'long_message'; |
|
2361 | - else |
|
2448 | + if ($_REQUEST['subject'] == '') { |
|
2449 | + $post_errors[] = 'no_subject'; |
|
2450 | + } |
|
2451 | + if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') { |
|
2452 | + $post_errors[] = 'no_message'; |
|
2453 | + } elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength']) { |
|
2454 | + $post_errors[] = 'long_message'; |
|
2455 | + } else |
|
2362 | 2456 | { |
2363 | 2457 | // Preparse the message. |
2364 | 2458 | $message = $_REQUEST['message']; |
2365 | 2459 | preparsecode($message); |
2366 | 2460 | |
2367 | 2461 | // Make sure there's still some content left without the tags. |
2368 | - if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false)) |
|
2369 | - $post_errors[] = 'no_message'; |
|
2462 | + if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false)) { |
|
2463 | + $post_errors[] = 'no_message'; |
|
2464 | + } |
|
2370 | 2465 | } |
2371 | 2466 | |
2372 | 2467 | // Wrong verification code? |
@@ -2378,13 +2473,15 @@ discard block |
||
2378 | 2473 | ); |
2379 | 2474 | $context['require_verification'] = create_control_verification($verificationOptions, true); |
2380 | 2475 | |
2381 | - if (is_array($context['require_verification'])) |
|
2382 | - $post_errors = array_merge($post_errors, $context['require_verification']); |
|
2476 | + if (is_array($context['require_verification'])) { |
|
2477 | + $post_errors = array_merge($post_errors, $context['require_verification']); |
|
2478 | + } |
|
2383 | 2479 | } |
2384 | 2480 | |
2385 | 2481 | // If they did, give a chance to make ammends. |
2386 | - if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml'])) |
|
2387 | - return messagePostError($post_errors, $namedRecipientList, $recipientList); |
|
2482 | + if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml'])) { |
|
2483 | + return messagePostError($post_errors, $namedRecipientList, $recipientList); |
|
2484 | + } |
|
2388 | 2485 | |
2389 | 2486 | // Want to take a second glance before you send? |
2390 | 2487 | if (isset($_REQUEST['preview'])) |
@@ -2415,8 +2512,9 @@ discard block |
||
2415 | 2512 | foreach ($namesNotFound as $recipientType => $names) |
2416 | 2513 | { |
2417 | 2514 | $post_errors[] = 'bad_' . $recipientType; |
2418 | - foreach ($names as $name) |
|
2419 | - $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name); |
|
2515 | + foreach ($names as $name) { |
|
2516 | + $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name); |
|
2517 | + } |
|
2420 | 2518 | } |
2421 | 2519 | |
2422 | 2520 | return messagePostError(array(), $namedRecipientList, $recipientList); |
@@ -2446,13 +2544,14 @@ discard block |
||
2446 | 2544 | checkSubmitOnce('check'); |
2447 | 2545 | |
2448 | 2546 | // Do the actual sending of the PM. |
2449 | - if (!empty($recipientList['to']) || !empty($recipientList['bcc'])) |
|
2450 | - $context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0); |
|
2451 | - else |
|
2452 | - $context['send_log'] = array( |
|
2547 | + if (!empty($recipientList['to']) || !empty($recipientList['bcc'])) { |
|
2548 | + $context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0); |
|
2549 | + } else { |
|
2550 | + $context['send_log'] = array( |
|
2453 | 2551 | 'sent' => array(), |
2454 | 2552 | 'failed' => array() |
2455 | 2553 | ); |
2554 | + } |
|
2456 | 2555 | |
2457 | 2556 | // Mark the message as "replied to". |
2458 | 2557 | if (!empty($context['send_log']['sent']) && !empty($_REQUEST['replied_to']) && isset($_REQUEST['f']) && $_REQUEST['f'] == 'inbox') |
@@ -2470,11 +2569,12 @@ discard block |
||
2470 | 2569 | } |
2471 | 2570 | |
2472 | 2571 | // If one or more of the recipient were invalid, go back to the post screen with the failed usernames. |
2473 | - if (!empty($context['send_log']['failed'])) |
|
2474 | - return messagePostError($post_errors, $namesNotFound, array( |
|
2572 | + if (!empty($context['send_log']['failed'])) { |
|
2573 | + return messagePostError($post_errors, $namesNotFound, array( |
|
2475 | 2574 | 'to' => array_intersect($recipientList['to'], $context['send_log']['failed']), |
2476 | 2575 | 'bcc' => array_intersect($recipientList['bcc'], $context['send_log']['failed']) |
2477 | 2576 | )); |
2577 | + } |
|
2478 | 2578 | |
2479 | 2579 | // Message sent successfully? |
2480 | 2580 | if (!empty($context['send_log']) && empty($context['send_log']['failed'])) |
@@ -2482,8 +2582,9 @@ discard block |
||
2482 | 2582 | $context['current_label_redirect'] = $context['current_label_redirect'] . ';done=sent'; |
2483 | 2583 | |
2484 | 2584 | // If we had a PM draft for this one, then its time to remove it since it was just sent |
2485 | - if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft'])) |
|
2486 | - DeleteDraft($_POST['id_pm_draft']); |
|
2585 | + if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft'])) { |
|
2586 | + DeleteDraft($_POST['id_pm_draft']); |
|
2587 | + } |
|
2487 | 2588 | } |
2488 | 2589 | |
2489 | 2590 | // Go back to the where they sent from, if possible... |
@@ -2498,24 +2599,28 @@ discard block |
||
2498 | 2599 | |
2499 | 2600 | checkSession('request'); |
2500 | 2601 | |
2501 | - if (isset($_REQUEST['del_selected'])) |
|
2502 | - $_REQUEST['pm_action'] = 'delete'; |
|
2602 | + if (isset($_REQUEST['del_selected'])) { |
|
2603 | + $_REQUEST['pm_action'] = 'delete'; |
|
2604 | + } |
|
2503 | 2605 | |
2504 | 2606 | if (isset($_REQUEST['pm_action']) && $_REQUEST['pm_action'] != '' && !empty($_REQUEST['pms']) && is_array($_REQUEST['pms'])) |
2505 | 2607 | { |
2506 | - foreach ($_REQUEST['pms'] as $pm) |
|
2507 | - $_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action']; |
|
2608 | + foreach ($_REQUEST['pms'] as $pm) { |
|
2609 | + $_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action']; |
|
2610 | + } |
|
2508 | 2611 | } |
2509 | 2612 | |
2510 | - if (empty($_REQUEST['pm_actions'])) |
|
2511 | - redirectexit($context['current_label_redirect']); |
|
2613 | + if (empty($_REQUEST['pm_actions'])) { |
|
2614 | + redirectexit($context['current_label_redirect']); |
|
2615 | + } |
|
2512 | 2616 | |
2513 | 2617 | // If we are in conversation, we may need to apply this to every message in the conversation. |
2514 | 2618 | if ($context['display_mode'] == 2 && isset($_REQUEST['conversation'])) |
2515 | 2619 | { |
2516 | 2620 | $id_pms = array(); |
2517 | - foreach ($_REQUEST['pm_actions'] as $pm => $dummy) |
|
2518 | - $id_pms[] = (int) $pm; |
|
2621 | + foreach ($_REQUEST['pm_actions'] as $pm => $dummy) { |
|
2622 | + $id_pms[] = (int) $pm; |
|
2623 | + } |
|
2519 | 2624 | |
2520 | 2625 | $request = $smcFunc['db_query']('', ' |
2521 | 2626 | SELECT id_pm_head, id_pm |
@@ -2526,8 +2631,9 @@ discard block |
||
2526 | 2631 | ) |
2527 | 2632 | ); |
2528 | 2633 | $pm_heads = array(); |
2529 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2530 | - $pm_heads[$row['id_pm_head']] = $row['id_pm']; |
|
2634 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2635 | + $pm_heads[$row['id_pm_head']] = $row['id_pm']; |
|
2636 | + } |
|
2531 | 2637 | $smcFunc['db_free_result']($request); |
2532 | 2638 | |
2533 | 2639 | $request = $smcFunc['db_query']('', ' |
@@ -2541,8 +2647,9 @@ discard block |
||
2541 | 2647 | // Copy the action from the single to PM to the others. |
2542 | 2648 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
2543 | 2649 | { |
2544 | - if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]])) |
|
2545 | - $_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]]; |
|
2650 | + if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]])) { |
|
2651 | + $_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]]; |
|
2652 | + } |
|
2546 | 2653 | } |
2547 | 2654 | $smcFunc['db_free_result']($request); |
2548 | 2655 | } |
@@ -2553,22 +2660,21 @@ discard block |
||
2553 | 2660 | $labels = array(); |
2554 | 2661 | foreach ($_REQUEST['pm_actions'] as $pm => $action) |
2555 | 2662 | { |
2556 | - if ($action === 'delete') |
|
2557 | - $to_delete[] = (int) $pm; |
|
2558 | - else |
|
2663 | + if ($action === 'delete') { |
|
2664 | + $to_delete[] = (int) $pm; |
|
2665 | + } else |
|
2559 | 2666 | { |
2560 | 2667 | if (substr($action, 0, 4) == 'add_') |
2561 | 2668 | { |
2562 | 2669 | $type = 'add'; |
2563 | 2670 | $action = substr($action, 4); |
2564 | - } |
|
2565 | - elseif (substr($action, 0, 4) == 'rem_') |
|
2671 | + } elseif (substr($action, 0, 4) == 'rem_') |
|
2566 | 2672 | { |
2567 | 2673 | $type = 'rem'; |
2568 | 2674 | $action = substr($action, 4); |
2675 | + } else { |
|
2676 | + $type = 'unk'; |
|
2569 | 2677 | } |
2570 | - else |
|
2571 | - $type = 'unk'; |
|
2572 | 2678 | |
2573 | 2679 | if ($action == '-1' || (int) $action > 0) |
2574 | 2680 | { |
@@ -2579,8 +2685,9 @@ discard block |
||
2579 | 2685 | } |
2580 | 2686 | |
2581 | 2687 | // Deleting, it looks like? |
2582 | - if (!empty($to_delete)) |
|
2583 | - deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']); |
|
2688 | + if (!empty($to_delete)) { |
|
2689 | + deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']); |
|
2690 | + } |
|
2584 | 2691 | |
2585 | 2692 | // Are we labeling anything? |
2586 | 2693 | if (!empty($to_label) && $context['folder'] == 'inbox') |
@@ -2646,8 +2753,7 @@ discard block |
||
2646 | 2753 | } |
2647 | 2754 | |
2648 | 2755 | $smcFunc['db_free_result']($request2); |
2649 | - } |
|
2650 | - elseif ($type == 'rem') |
|
2756 | + } elseif ($type == 'rem') |
|
2651 | 2757 | { |
2652 | 2758 | // If we're removing from the inbox, see if we have at least one other label. |
2653 | 2759 | // This query is faster than the one above |
@@ -2679,21 +2785,25 @@ discard block |
||
2679 | 2785 | if ($to_label[$row['id_pm']] != '-1') |
2680 | 2786 | { |
2681 | 2787 | // If this label is in the list and we're not adding it, remove it |
2682 | - if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add') |
|
2683 | - unset($labels[$to_label[$row['id_pm']]]); |
|
2684 | - else if ($type !== 'rem') |
|
2685 | - $labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']]; |
|
2788 | + if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add') { |
|
2789 | + unset($labels[$to_label[$row['id_pm']]]); |
|
2790 | + } else if ($type !== 'rem') { |
|
2791 | + $labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']]; |
|
2792 | + } |
|
2686 | 2793 | } |
2687 | 2794 | |
2688 | 2795 | // Removing all labels or just removing the inbox label |
2689 | - if ($type == 'rem' && empty($labels)) |
|
2690 | - $in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0); |
|
2796 | + if ($type == 'rem' && empty($labels)) { |
|
2797 | + $in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0); |
|
2798 | + } |
|
2691 | 2799 | // Adding new labels, but removing inbox and applying new ones |
2692 | - elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels)) |
|
2693 | - $in_inbox = 0; |
|
2800 | + elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels)) { |
|
2801 | + $in_inbox = 0; |
|
2802 | + } |
|
2694 | 2803 | // Just adding it to the inbox |
2695 | - else |
|
2696 | - $in_inbox = 1; |
|
2804 | + else { |
|
2805 | + $in_inbox = 1; |
|
2806 | + } |
|
2697 | 2807 | |
2698 | 2808 | // Are we adding it to or removing it from the inbox? |
2699 | 2809 | if ($in_inbox != $row['in_inbox']) |
@@ -2735,8 +2845,9 @@ discard block |
||
2735 | 2845 | if (!empty($labels_to_apply)) |
2736 | 2846 | { |
2737 | 2847 | $inserts = array(); |
2738 | - foreach ($labels_to_apply as $label) |
|
2739 | - $inserts[] = array($row['id_pm'], $label); |
|
2848 | + foreach ($labels_to_apply as $label) { |
|
2849 | + $inserts[] = array($row['id_pm'], $label); |
|
2850 | + } |
|
2740 | 2851 | |
2741 | 2852 | $smcFunc['db_insert']('', |
2742 | 2853 | '{db_prefix}pm_labeled_messages', |
@@ -2780,11 +2891,13 @@ discard block |
||
2780 | 2891 | checkSession('get'); |
2781 | 2892 | |
2782 | 2893 | // If all then delete all messages the user has. |
2783 | - if ($_REQUEST['f'] == 'all') |
|
2784 | - deleteMessages(null, null); |
|
2894 | + if ($_REQUEST['f'] == 'all') { |
|
2895 | + deleteMessages(null, null); |
|
2896 | + } |
|
2785 | 2897 | // Otherwise just the selected folder. |
2786 | - else |
|
2787 | - deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent'); |
|
2898 | + else { |
|
2899 | + deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent'); |
|
2900 | + } |
|
2788 | 2901 | |
2789 | 2902 | // Done... all gone. |
2790 | 2903 | redirectexit($context['current_label_redirect']); |
@@ -2821,8 +2934,9 @@ discard block |
||
2821 | 2934 | 'msgtime' => $deleteTime, |
2822 | 2935 | ) |
2823 | 2936 | ); |
2824 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
2825 | - $toDelete[] = $row[0]; |
|
2937 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
2938 | + $toDelete[] = $row[0]; |
|
2939 | + } |
|
2826 | 2940 | $smcFunc['db_free_result']($request); |
2827 | 2941 | |
2828 | 2942 | // Select all messages in their inbox older than $deleteTime. |
@@ -2839,8 +2953,9 @@ discard block |
||
2839 | 2953 | 'msgtime' => $deleteTime, |
2840 | 2954 | ) |
2841 | 2955 | ); |
2842 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2843 | - $toDelete[] = $row['id_pm']; |
|
2956 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2957 | + $toDelete[] = $row['id_pm']; |
|
2958 | + } |
|
2844 | 2959 | $smcFunc['db_free_result']($request); |
2845 | 2960 | |
2846 | 2961 | // Delete the actual messages. |
@@ -2871,26 +2986,29 @@ discard block |
||
2871 | 2986 | { |
2872 | 2987 | global $user_info, $smcFunc; |
2873 | 2988 | |
2874 | - if ($owner === null) |
|
2875 | - $owner = array($user_info['id']); |
|
2876 | - elseif (empty($owner)) |
|
2877 | - return; |
|
2878 | - elseif (!is_array($owner)) |
|
2879 | - $owner = array($owner); |
|
2989 | + if ($owner === null) { |
|
2990 | + $owner = array($user_info['id']); |
|
2991 | + } elseif (empty($owner)) { |
|
2992 | + return; |
|
2993 | + } elseif (!is_array($owner)) { |
|
2994 | + $owner = array($owner); |
|
2995 | + } |
|
2880 | 2996 | |
2881 | 2997 | if ($personal_messages !== null) |
2882 | 2998 | { |
2883 | - if (empty($personal_messages) || !is_array($personal_messages)) |
|
2884 | - return; |
|
2999 | + if (empty($personal_messages) || !is_array($personal_messages)) { |
|
3000 | + return; |
|
3001 | + } |
|
2885 | 3002 | |
2886 | - foreach ($personal_messages as $index => $delete_id) |
|
2887 | - $personal_messages[$index] = (int) $delete_id; |
|
3003 | + foreach ($personal_messages as $index => $delete_id) { |
|
3004 | + $personal_messages[$index] = (int) $delete_id; |
|
3005 | + } |
|
2888 | 3006 | |
2889 | 3007 | $where = ' |
2890 | 3008 | AND id_pm IN ({array_int:pm_list})'; |
3009 | + } else { |
|
3010 | + $where = ''; |
|
2891 | 3011 | } |
2892 | - else |
|
2893 | - $where = ''; |
|
2894 | 3012 | |
2895 | 3013 | if ($folder == 'sent' || $folder === null) |
2896 | 3014 | { |
@@ -2925,17 +3043,19 @@ discard block |
||
2925 | 3043 | // ...And update the statistics accordingly - now including unread messages!. |
2926 | 3044 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
2927 | 3045 | { |
2928 | - if ($row['is_read']) |
|
2929 | - updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'])); |
|
2930 | - else |
|
2931 | - updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages'])); |
|
3046 | + if ($row['is_read']) { |
|
3047 | + updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'])); |
|
3048 | + } else { |
|
3049 | + updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages'])); |
|
3050 | + } |
|
2932 | 3051 | |
2933 | 3052 | // If this is the current member we need to make their message count correct. |
2934 | 3053 | if ($user_info['id'] == $row['id_member']) |
2935 | 3054 | { |
2936 | 3055 | $user_info['messages'] -= $row['num_deleted_messages']; |
2937 | - if (!($row['is_read'])) |
|
2938 | - $user_info['unread_messages'] -= $row['num_deleted_messages']; |
|
3056 | + if (!($row['is_read'])) { |
|
3057 | + $user_info['unread_messages'] -= $row['num_deleted_messages']; |
|
3058 | + } |
|
2939 | 3059 | } |
2940 | 3060 | } |
2941 | 3061 | $smcFunc['db_free_result']($request); |
@@ -3003,8 +3123,9 @@ discard block |
||
3003 | 3123 | ) |
3004 | 3124 | ); |
3005 | 3125 | $remove_pms = array(); |
3006 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
3007 | - $remove_pms[] = $row['sender']; |
|
3126 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
3127 | + $remove_pms[] = $row['sender']; |
|
3128 | + } |
|
3008 | 3129 | $smcFunc['db_free_result']($request); |
3009 | 3130 | |
3010 | 3131 | if (!empty($remove_pms)) |
@@ -3049,8 +3170,9 @@ discard block |
||
3049 | 3170 | { |
3050 | 3171 | global $user_info, $context, $smcFunc; |
3051 | 3172 | |
3052 | - if ($owner === null) |
|
3053 | - $owner = $user_info['id']; |
|
3173 | + if ($owner === null) { |
|
3174 | + $owner = $user_info['id']; |
|
3175 | + } |
|
3054 | 3176 | |
3055 | 3177 | $in_inbox = ''; |
3056 | 3178 | |
@@ -3074,8 +3196,7 @@ discard block |
||
3074 | 3196 | } |
3075 | 3197 | |
3076 | 3198 | $smcFunc['db_free_result']($get_messages); |
3077 | - } |
|
3078 | - elseif ($label = '-1') |
|
3199 | + } elseif ($label = '-1') |
|
3079 | 3200 | { |
3080 | 3201 | // Marking all PMs in your inbox read |
3081 | 3202 | $in_inbox = ' |
@@ -3100,8 +3221,9 @@ discard block |
||
3100 | 3221 | { |
3101 | 3222 | if ($owner == $user_info['id']) |
3102 | 3223 | { |
3103 | - foreach ($context['labels'] as $label) |
|
3104 | - $context['labels'][(int) $label['id']]['unread_messages'] = 0; |
|
3224 | + foreach ($context['labels'] as $label) { |
|
3225 | + $context['labels'][(int) $label['id']]['unread_messages'] = 0; |
|
3226 | + } |
|
3105 | 3227 | } |
3106 | 3228 | |
3107 | 3229 | $result = $smcFunc['db_query']('', ' |
@@ -3121,8 +3243,9 @@ discard block |
||
3121 | 3243 | { |
3122 | 3244 | $total_unread += $row['num']; |
3123 | 3245 | |
3124 | - if ($owner != $user_info['id'] || empty($row['id_pm'])) |
|
3125 | - continue; |
|
3246 | + if ($owner != $user_info['id'] || empty($row['id_pm'])) { |
|
3247 | + continue; |
|
3248 | + } |
|
3126 | 3249 | |
3127 | 3250 | $this_labels = array(); |
3128 | 3251 | |
@@ -3146,11 +3269,13 @@ discard block |
||
3146 | 3269 | |
3147 | 3270 | $smcFunc['db_free_result']($result2); |
3148 | 3271 | |
3149 | - foreach ($this_labels as $this_label) |
|
3150 | - $context['labels'][$this_label]['unread_messages'] += $row['num']; |
|
3272 | + foreach ($this_labels as $this_label) { |
|
3273 | + $context['labels'][$this_label]['unread_messages'] += $row['num']; |
|
3274 | + } |
|
3151 | 3275 | |
3152 | - if ($row['in_inbox'] == 1) |
|
3153 | - $context['labels'][-1]['unread_messages'] += $row['num']; |
|
3276 | + if ($row['in_inbox'] == 1) { |
|
3277 | + $context['labels'][-1]['unread_messages'] += $row['num']; |
|
3278 | + } |
|
3154 | 3279 | } |
3155 | 3280 | $smcFunc['db_free_result']($result); |
3156 | 3281 | |
@@ -3159,8 +3284,9 @@ discard block |
||
3159 | 3284 | updateMemberData($owner, array('unread_messages' => $total_unread)); |
3160 | 3285 | |
3161 | 3286 | // If it was for the current member, reflect this in the $user_info array too. |
3162 | - if ($owner == $user_info['id']) |
|
3163 | - $user_info['unread_messages'] = $total_unread; |
|
3287 | + if ($owner == $user_info['id']) { |
|
3288 | + $user_info['unread_messages'] = $total_unread; |
|
3289 | + } |
|
3164 | 3290 | } |
3165 | 3291 | } |
3166 | 3292 | |
@@ -3188,8 +3314,9 @@ discard block |
||
3188 | 3314 | // Add all existing labels to the array to save, slashing them as necessary... |
3189 | 3315 | foreach ($context['labels'] as $label) |
3190 | 3316 | { |
3191 | - if ($label['id'] != -1) |
|
3192 | - $the_labels[$label['id']] = $label['name']; |
|
3317 | + if ($label['id'] != -1) { |
|
3318 | + $the_labels[$label['id']] = $label['name']; |
|
3319 | + } |
|
3193 | 3320 | } |
3194 | 3321 | |
3195 | 3322 | if (isset($_POST[$context['session_var']])) |
@@ -3208,8 +3335,9 @@ discard block |
||
3208 | 3335 | { |
3209 | 3336 | $_POST['label'] = strtr($smcFunc['htmlspecialchars'](trim($_POST['label'])), array(',' => ',')); |
3210 | 3337 | |
3211 | - if ($smcFunc['strlen']($_POST['label']) > 30) |
|
3212 | - $_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30); |
|
3338 | + if ($smcFunc['strlen']($_POST['label']) > 30) { |
|
3339 | + $_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30); |
|
3340 | + } |
|
3213 | 3341 | if ($_POST['label'] != '') |
3214 | 3342 | { |
3215 | 3343 | $the_labels[] = $_POST['label']; |
@@ -3230,23 +3358,24 @@ discard block |
||
3230 | 3358 | { |
3231 | 3359 | foreach ($the_labels as $id => $name) |
3232 | 3360 | { |
3233 | - if ($id == -1) |
|
3234 | - continue; |
|
3235 | - elseif (isset($_POST['label_name'][$id])) |
|
3361 | + if ($id == -1) { |
|
3362 | + continue; |
|
3363 | + } elseif (isset($_POST['label_name'][$id])) |
|
3236 | 3364 | { |
3237 | 3365 | $_POST['label_name'][$id] = trim(strtr($smcFunc['htmlspecialchars']($_POST['label_name'][$id]), array(',' => ','))); |
3238 | 3366 | |
3239 | - if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30) |
|
3240 | - $_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30); |
|
3367 | + if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30) { |
|
3368 | + $_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30); |
|
3369 | + } |
|
3241 | 3370 | if ($_POST['label_name'][$id] != '') |
3242 | 3371 | { |
3243 | 3372 | // Changing the name of this label? |
3244 | - if ($the_labels[$id] != $_POST['label_name'][$id]) |
|
3245 | - $label_updates[$id] = $_POST['label_name'][$id]; |
|
3373 | + if ($the_labels[$id] != $_POST['label_name'][$id]) { |
|
3374 | + $label_updates[$id] = $_POST['label_name'][$id]; |
|
3375 | + } |
|
3246 | 3376 | |
3247 | 3377 | $the_labels[(int) $id] = $_POST['label_name'][$id]; |
3248 | - } |
|
3249 | - else |
|
3378 | + } else |
|
3250 | 3379 | { |
3251 | 3380 | unset($the_labels[(int) $id]); |
3252 | 3381 | $labels_to_remove[] = $id; |
@@ -3260,8 +3389,9 @@ discard block |
||
3260 | 3389 | if (!empty($labels_to_add)) |
3261 | 3390 | { |
3262 | 3391 | $inserts = array(); |
3263 | - foreach ($labels_to_add AS $label) |
|
3264 | - $inserts[] = array($user_info['id'], $label); |
|
3392 | + foreach ($labels_to_add AS $label) { |
|
3393 | + $inserts[] = array($user_info['id'], $label); |
|
3394 | + } |
|
3265 | 3395 | |
3266 | 3396 | $smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array()); |
3267 | 3397 | } |
@@ -3351,8 +3481,9 @@ discard block |
||
3351 | 3481 | // Each action... |
3352 | 3482 | foreach ($rule['actions'] as $k2 => $action) |
3353 | 3483 | { |
3354 | - if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove)) |
|
3355 | - continue; |
|
3484 | + if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove)) { |
|
3485 | + continue; |
|
3486 | + } |
|
3356 | 3487 | |
3357 | 3488 | $rule_changes[] = $rule['id']; |
3358 | 3489 | |
@@ -3367,8 +3498,8 @@ discard block |
||
3367 | 3498 | { |
3368 | 3499 | $rule_changes = array_unique($rule_changes); |
3369 | 3500 | // Update/delete as appropriate. |
3370 | - foreach ($rule_changes as $k => $id) |
|
3371 | - if (!empty($context['rules'][$id]['actions'])) |
|
3501 | + foreach ($rule_changes as $k => $id) { |
|
3502 | + if (!empty($context['rules'][$id]['actions'])) |
|
3372 | 3503 | { |
3373 | 3504 | $smcFunc['db_query']('', ' |
3374 | 3505 | UPDATE {db_prefix}pm_rules |
@@ -3381,12 +3512,13 @@ discard block |
||
3381 | 3512 | 'actions' => $smcFunc['json_encode']($context['rules'][$id]['actions']), |
3382 | 3513 | ) |
3383 | 3514 | ); |
3515 | + } |
|
3384 | 3516 | unset($rule_changes[$k]); |
3385 | 3517 | } |
3386 | 3518 | |
3387 | 3519 | // Anything left here means it's lost all actions... |
3388 | - if (!empty($rule_changes)) |
|
3389 | - $smcFunc['db_query']('', ' |
|
3520 | + if (!empty($rule_changes)) { |
|
3521 | + $smcFunc['db_query']('', ' |
|
3390 | 3522 | DELETE FROM {db_prefix}pm_rules |
3391 | 3523 | WHERE id_rule IN ({array_int:rule_list}) |
3392 | 3524 | AND id_member = {int:current_member}', |
@@ -3395,6 +3527,7 @@ discard block |
||
3395 | 3527 | 'rule_list' => $rule_changes, |
3396 | 3528 | ) |
3397 | 3529 | ); |
3530 | + } |
|
3398 | 3531 | } |
3399 | 3532 | |
3400 | 3533 | // Make sure we're not caching this! |
@@ -3464,8 +3597,9 @@ discard block |
||
3464 | 3597 | // Save the fields. |
3465 | 3598 | saveProfileFields(); |
3466 | 3599 | |
3467 | - if (!empty($profile_vars)) |
|
3468 | - updateMemberData($user_info['id'], $profile_vars); |
|
3600 | + if (!empty($profile_vars)) { |
|
3601 | + updateMemberData($user_info['id'], $profile_vars); |
|
3602 | + } |
|
3469 | 3603 | } |
3470 | 3604 | |
3471 | 3605 | setupProfileContext( |
@@ -3490,13 +3624,15 @@ discard block |
||
3490 | 3624 | global $user_info, $language, $modSettings, $smcFunc; |
3491 | 3625 | |
3492 | 3626 | // Check that this feature is even enabled! |
3493 | - if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg'])) |
|
3494 | - fatal_lang_error('no_access', false); |
|
3627 | + if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg'])) { |
|
3628 | + fatal_lang_error('no_access', false); |
|
3629 | + } |
|
3495 | 3630 | |
3496 | 3631 | $pmsg = (int) $_REQUEST['pmsg']; |
3497 | 3632 | |
3498 | - if (!isAccessiblePM($pmsg, 'inbox')) |
|
3499 | - fatal_lang_error('no_access', false); |
|
3633 | + if (!isAccessiblePM($pmsg, 'inbox')) { |
|
3634 | + fatal_lang_error('no_access', false); |
|
3635 | + } |
|
3500 | 3636 | |
3501 | 3637 | $context['pm_id'] = $pmsg; |
3502 | 3638 | $context['page_title'] = $txt['pm_report_title']; |
@@ -3518,8 +3654,9 @@ discard block |
||
3518 | 3654 | ) |
3519 | 3655 | ); |
3520 | 3656 | $context['admins'] = array(); |
3521 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
3522 | - $context['admins'][$row['id_member']] = $row['real_name']; |
|
3657 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
3658 | + $context['admins'][$row['id_member']] = $row['real_name']; |
|
3659 | + } |
|
3523 | 3660 | $smcFunc['db_free_result']($request); |
3524 | 3661 | |
3525 | 3662 | // How many admins in total? |
@@ -3548,8 +3685,9 @@ discard block |
||
3548 | 3685 | ) |
3549 | 3686 | ); |
3550 | 3687 | // Can only be a hacker here! |
3551 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
3552 | - fatal_lang_error('no_access', false); |
|
3688 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
3689 | + fatal_lang_error('no_access', false); |
|
3690 | + } |
|
3553 | 3691 | list ($subject, $body, $time, $memberFromID, $memberFromName) = $smcFunc['db_fetch_row']($request); |
3554 | 3692 | $smcFunc['db_free_result']($request); |
3555 | 3693 | |
@@ -3573,15 +3711,17 @@ discard block |
||
3573 | 3711 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
3574 | 3712 | { |
3575 | 3713 | // If it's hidden still don't reveal their names - privacy after all ;) |
3576 | - if ($row['bcc']) |
|
3577 | - $hidden_recipients++; |
|
3578 | - else |
|
3579 | - $recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]'; |
|
3714 | + if ($row['bcc']) { |
|
3715 | + $hidden_recipients++; |
|
3716 | + } else { |
|
3717 | + $recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]'; |
|
3718 | + } |
|
3580 | 3719 | } |
3581 | 3720 | $smcFunc['db_free_result']($request); |
3582 | 3721 | |
3583 | - if ($hidden_recipients) |
|
3584 | - $recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients); |
|
3722 | + if ($hidden_recipients) { |
|
3723 | + $recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients); |
|
3724 | + } |
|
3585 | 3725 | |
3586 | 3726 | // Now let's get out and loop through the admins. |
3587 | 3727 | $request = $smcFunc['db_query']('', ' |
@@ -3597,8 +3737,9 @@ discard block |
||
3597 | 3737 | ); |
3598 | 3738 | |
3599 | 3739 | // Maybe we shouldn't advertise this? |
3600 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
3601 | - fatal_lang_error('no_access', false); |
|
3740 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
3741 | + fatal_lang_error('no_access', false); |
|
3742 | + } |
|
3602 | 3743 | |
3603 | 3744 | $memberFromName = un_htmlspecialchars($memberFromName); |
3604 | 3745 | |
@@ -3617,8 +3758,9 @@ discard block |
||
3617 | 3758 | // Make the body. |
3618 | 3759 | $report_body = str_replace(array('{REPORTER}', '{SENDER}'), array(un_htmlspecialchars($user_info['name']), $memberFromName), $txt['pm_report_pm_user_sent']); |
3619 | 3760 | $report_body .= "\n" . '[b]' . $_POST['reason'] . '[/b]' . "\n\n"; |
3620 | - if (!empty($recipients)) |
|
3621 | - $report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n"; |
|
3761 | + if (!empty($recipients)) { |
|
3762 | + $report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n"; |
|
3763 | + } |
|
3622 | 3764 | $report_body .= $txt['pm_report_pm_unedited_below'] . "\n" . '[quote author=' . (empty($memberFromID) ? '"' . $memberFromName . '"' : $memberFromName . ' link=action=profile;u=' . $memberFromID . ' date=' . $time) . ']' . "\n" . un_htmlspecialchars($body) . '[/quote]'; |
3623 | 3765 | |
3624 | 3766 | // Plonk it in the array ;) |
@@ -3638,12 +3780,14 @@ discard block |
||
3638 | 3780 | $smcFunc['db_free_result']($request); |
3639 | 3781 | |
3640 | 3782 | // Send a different email for each language. |
3641 | - foreach ($messagesToSend as $lang => $message) |
|
3642 | - sendpm($message['recipients'], $message['subject'], $message['body']); |
|
3783 | + foreach ($messagesToSend as $lang => $message) { |
|
3784 | + sendpm($message['recipients'], $message['subject'], $message['body']); |
|
3785 | + } |
|
3643 | 3786 | |
3644 | 3787 | // Give the user their own language back! |
3645 | - if (!empty($modSettings['userLanguage'])) |
|
3646 | - loadLanguage('PersonalMessage', '', false); |
|
3788 | + if (!empty($modSettings['userLanguage'])) { |
|
3789 | + loadLanguage('PersonalMessage', '', false); |
|
3790 | + } |
|
3647 | 3791 | |
3648 | 3792 | // Leave them with a template. |
3649 | 3793 | $context['sub_template'] = 'report_message_complete'; |
@@ -3689,8 +3833,9 @@ discard block |
||
3689 | 3833 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
3690 | 3834 | { |
3691 | 3835 | // Hide hidden groups! |
3692 | - if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) |
|
3693 | - continue; |
|
3836 | + if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) { |
|
3837 | + continue; |
|
3838 | + } |
|
3694 | 3839 | |
3695 | 3840 | $context['groups'][$row['id_group']] = $row['group_name']; |
3696 | 3841 | } |
@@ -3716,9 +3861,10 @@ discard block |
||
3716 | 3861 | $context['rule'] = $context['rules'][$context['rid']]; |
3717 | 3862 | $members = array(); |
3718 | 3863 | // Need to get member names! |
3719 | - foreach ($context['rule']['criteria'] as $k => $criteria) |
|
3720 | - if ($criteria['t'] == 'mid' && !empty($criteria['v'])) |
|
3864 | + foreach ($context['rule']['criteria'] as $k => $criteria) { |
|
3865 | + if ($criteria['t'] == 'mid' && !empty($criteria['v'])) |
|
3721 | 3866 | $members[(int) $criteria['v']] = $k; |
3867 | + } |
|
3722 | 3868 | |
3723 | 3869 | if (!empty($members)) |
3724 | 3870 | { |
@@ -3730,19 +3876,20 @@ discard block |
||
3730 | 3876 | 'member_list' => array_keys($members), |
3731 | 3877 | ) |
3732 | 3878 | ); |
3733 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
3734 | - $context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name']; |
|
3879 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
3880 | + $context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name']; |
|
3881 | + } |
|
3735 | 3882 | $smcFunc['db_free_result']($request); |
3736 | 3883 | } |
3737 | - } |
|
3738 | - else |
|
3739 | - $context['rule'] = array( |
|
3884 | + } else { |
|
3885 | + $context['rule'] = array( |
|
3740 | 3886 | 'id' => '', |
3741 | 3887 | 'name' => '', |
3742 | 3888 | 'criteria' => array(), |
3743 | 3889 | 'actions' => array(), |
3744 | 3890 | 'logic' => 'and', |
3745 | 3891 | ); |
3892 | + } |
|
3746 | 3893 | } |
3747 | 3894 | // Saving? |
3748 | 3895 | elseif (isset($_GET['save'])) |
@@ -3752,22 +3899,25 @@ discard block |
||
3752 | 3899 | |
3753 | 3900 | // Name is easy! |
3754 | 3901 | $ruleName = $smcFunc['htmlspecialchars'](trim($_POST['rule_name'])); |
3755 | - if (empty($ruleName)) |
|
3756 | - fatal_lang_error('pm_rule_no_name', false); |
|
3902 | + if (empty($ruleName)) { |
|
3903 | + fatal_lang_error('pm_rule_no_name', false); |
|
3904 | + } |
|
3757 | 3905 | |
3758 | 3906 | // Sanity check... |
3759 | - if (empty($_POST['ruletype']) || empty($_POST['acttype'])) |
|
3760 | - fatal_lang_error('pm_rule_no_criteria', false); |
|
3907 | + if (empty($_POST['ruletype']) || empty($_POST['acttype'])) { |
|
3908 | + fatal_lang_error('pm_rule_no_criteria', false); |
|
3909 | + } |
|
3761 | 3910 | |
3762 | 3911 | // Let's do the criteria first - it's also hardest! |
3763 | 3912 | $criteria = array(); |
3764 | 3913 | foreach ($_POST['ruletype'] as $ind => $type) |
3765 | 3914 | { |
3766 | 3915 | // Check everything is here... |
3767 | - if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]]))) |
|
3768 | - continue; |
|
3769 | - elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind])) |
|
3770 | - continue; |
|
3916 | + if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]]))) { |
|
3917 | + continue; |
|
3918 | + } elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind])) { |
|
3919 | + continue; |
|
3920 | + } |
|
3771 | 3921 | |
3772 | 3922 | // Members need to be found. |
3773 | 3923 | if ($type == 'mid') |
@@ -3791,13 +3941,13 @@ discard block |
||
3791 | 3941 | $smcFunc['db_free_result']($request); |
3792 | 3942 | |
3793 | 3943 | $criteria[] = array('t' => 'mid', 'v' => $memID); |
3944 | + } elseif ($type == 'bud') { |
|
3945 | + $criteria[] = array('t' => 'bud', 'v' => 1); |
|
3946 | + } elseif ($type == 'gid') { |
|
3947 | + $criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]); |
|
3948 | + } elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') { |
|
3949 | + $criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind]))); |
|
3794 | 3950 | } |
3795 | - elseif ($type == 'bud') |
|
3796 | - $criteria[] = array('t' => 'bud', 'v' => 1); |
|
3797 | - elseif ($type == 'gid') |
|
3798 | - $criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]); |
|
3799 | - elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') |
|
3800 | - $criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind]))); |
|
3801 | 3951 | } |
3802 | 3952 | |
3803 | 3953 | // Also do the actions! |
@@ -3807,26 +3957,29 @@ discard block |
||
3807 | 3957 | foreach ($_POST['acttype'] as $ind => $type) |
3808 | 3958 | { |
3809 | 3959 | // Picking a valid label? |
3810 | - if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]]))) |
|
3811 | - continue; |
|
3960 | + if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]]))) { |
|
3961 | + continue; |
|
3962 | + } |
|
3812 | 3963 | |
3813 | 3964 | // Record what we're doing. |
3814 | - if ($type == 'del') |
|
3815 | - $doDelete = 1; |
|
3816 | - elseif ($type == 'lab') |
|
3817 | - $actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]); |
|
3965 | + if ($type == 'del') { |
|
3966 | + $doDelete = 1; |
|
3967 | + } elseif ($type == 'lab') { |
|
3968 | + $actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]); |
|
3969 | + } |
|
3818 | 3970 | } |
3819 | 3971 | |
3820 | - if (empty($criteria) || (empty($actions) && !$doDelete)) |
|
3821 | - fatal_lang_error('pm_rule_no_criteria', false); |
|
3972 | + if (empty($criteria) || (empty($actions) && !$doDelete)) { |
|
3973 | + fatal_lang_error('pm_rule_no_criteria', false); |
|
3974 | + } |
|
3822 | 3975 | |
3823 | 3976 | // What are we storing? |
3824 | 3977 | $criteria = $smcFunc['json_encode']($criteria); |
3825 | 3978 | $actions = $smcFunc['json_encode']($actions); |
3826 | 3979 | |
3827 | 3980 | // Create the rule? |
3828 | - if (empty($context['rid'])) |
|
3829 | - $smcFunc['db_insert']('', |
|
3981 | + if (empty($context['rid'])) { |
|
3982 | + $smcFunc['db_insert']('', |
|
3830 | 3983 | '{db_prefix}pm_rules', |
3831 | 3984 | array( |
3832 | 3985 | 'id_member' => 'int', 'rule_name' => 'string', 'criteria' => 'string', 'actions' => 'string', |
@@ -3837,8 +3990,8 @@ discard block |
||
3837 | 3990 | ), |
3838 | 3991 | array('id_rule') |
3839 | 3992 | ); |
3840 | - else |
|
3841 | - $smcFunc['db_query']('', ' |
|
3993 | + } else { |
|
3994 | + $smcFunc['db_query']('', ' |
|
3842 | 3995 | UPDATE {db_prefix}pm_rules |
3843 | 3996 | SET rule_name = {string:rule_name}, criteria = {string:criteria}, actions = {string:actions}, |
3844 | 3997 | delete_pm = {int:delete_pm}, is_or = {int:is_or} |
@@ -3854,6 +4007,7 @@ discard block |
||
3854 | 4007 | 'actions' => $actions, |
3855 | 4008 | ) |
3856 | 4009 | ); |
4010 | + } |
|
3857 | 4011 | |
3858 | 4012 | redirectexit('action=pm;sa=manrules'); |
3859 | 4013 | } |
@@ -3862,11 +4016,12 @@ discard block |
||
3862 | 4016 | { |
3863 | 4017 | checkSession(); |
3864 | 4018 | $toDelete = array(); |
3865 | - foreach ($_POST['delrule'] as $k => $v) |
|
3866 | - $toDelete[] = (int) $k; |
|
4019 | + foreach ($_POST['delrule'] as $k => $v) { |
|
4020 | + $toDelete[] = (int) $k; |
|
4021 | + } |
|
3867 | 4022 | |
3868 | - if (!empty($toDelete)) |
|
3869 | - $smcFunc['db_query']('', ' |
|
4023 | + if (!empty($toDelete)) { |
|
4024 | + $smcFunc['db_query']('', ' |
|
3870 | 4025 | DELETE FROM {db_prefix}pm_rules |
3871 | 4026 | WHERE id_rule IN ({array_int:delete_list}) |
3872 | 4027 | AND id_member = {int:current_member}', |
@@ -3875,6 +4030,7 @@ discard block |
||
3875 | 4030 | 'delete_list' => $toDelete, |
3876 | 4031 | ) |
3877 | 4032 | ); |
4033 | + } |
|
3878 | 4034 | |
3879 | 4035 | redirectexit('action=pm;sa=manrules'); |
3880 | 4036 | } |
@@ -3893,8 +4049,9 @@ discard block |
||
3893 | 4049 | loadRules(); |
3894 | 4050 | |
3895 | 4051 | // No rules? |
3896 | - if (empty($context['rules'])) |
|
3897 | - return; |
|
4052 | + if (empty($context['rules'])) { |
|
4053 | + return; |
|
4054 | + } |
|
3898 | 4055 | |
3899 | 4056 | // Just unread ones? |
3900 | 4057 | $ruleQuery = $all_messages ? '' : ' AND pmr.is_new = 1'; |
@@ -3924,8 +4081,9 @@ discard block |
||
3924 | 4081 | // Loop through all the criteria hoping to make a match. |
3925 | 4082 | foreach ($rule['criteria'] as $criterium) |
3926 | 4083 | { |
3927 | - if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false)) |
|
3928 | - $match = true; |
|
4084 | + if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false)) { |
|
4085 | + $match = true; |
|
4086 | + } |
|
3929 | 4087 | // If we're adding and one criteria don't match then we stop! |
3930 | 4088 | elseif ($rule['logic'] == 'and') |
3931 | 4089 | { |
@@ -3937,17 +4095,18 @@ discard block |
||
3937 | 4095 | // If we have a match the rule must be true - act! |
3938 | 4096 | if ($match) |
3939 | 4097 | { |
3940 | - if ($rule['delete']) |
|
3941 | - $actions['deletes'][] = $row['id_pm']; |
|
3942 | - else |
|
4098 | + if ($rule['delete']) { |
|
4099 | + $actions['deletes'][] = $row['id_pm']; |
|
4100 | + } else |
|
3943 | 4101 | { |
3944 | 4102 | foreach ($rule['actions'] as $ruleAction) |
3945 | 4103 | { |
3946 | 4104 | if ($ruleAction['t'] == 'lab') |
3947 | 4105 | { |
3948 | 4106 | // Get a basic pot started! |
3949 | - if (!isset($actions['labels'][$row['id_pm']])) |
|
3950 | - $actions['labels'][$row['id_pm']] = array(); |
|
4107 | + if (!isset($actions['labels'][$row['id_pm']])) { |
|
4108 | + $actions['labels'][$row['id_pm']] = array(); |
|
4109 | + } |
|
3951 | 4110 | $actions['labels'][$row['id_pm']][] = $ruleAction['v']; |
3952 | 4111 | } |
3953 | 4112 | } |
@@ -3958,8 +4117,9 @@ discard block |
||
3958 | 4117 | $smcFunc['db_free_result']($request); |
3959 | 4118 | |
3960 | 4119 | // Deletes are easy! |
3961 | - if (!empty($actions['deletes'])) |
|
3962 | - deleteMessages($actions['deletes']); |
|
4120 | + if (!empty($actions['deletes'])) { |
|
4121 | + deleteMessages($actions['deletes']); |
|
4122 | + } |
|
3963 | 4123 | |
3964 | 4124 | // Relabel? |
3965 | 4125 | if (!empty($actions['labels'])) |
@@ -3986,8 +4146,7 @@ discard block |
||
3986 | 4146 | 'current_member' => $user_info['id'], |
3987 | 4147 | ) |
3988 | 4148 | ); |
3989 | - } |
|
3990 | - else |
|
4149 | + } else |
|
3991 | 4150 | { |
3992 | 4151 | $realLabels[] = $label['id']; |
3993 | 4152 | } |
@@ -3996,8 +4155,9 @@ discard block |
||
3996 | 4155 | |
3997 | 4156 | $inserts = array(); |
3998 | 4157 | // Now we insert the label info |
3999 | - foreach ($realLabels as $a_label) |
|
4000 | - $inserts[] = array($pm, $a_label); |
|
4158 | + foreach ($realLabels as $a_label) { |
|
4159 | + $inserts[] = array($pm, $a_label); |
|
4160 | + } |
|
4001 | 4161 | |
4002 | 4162 | $smcFunc['db_insert']('ignore', |
4003 | 4163 | '{db_prefix}pm_labeled_messages', |
@@ -4018,8 +4178,9 @@ discard block |
||
4018 | 4178 | { |
4019 | 4179 | global $user_info, $context, $smcFunc; |
4020 | 4180 | |
4021 | - if (isset($context['rules']) && !$reload) |
|
4022 | - return; |
|
4181 | + if (isset($context['rules']) && !$reload) { |
|
4182 | + return; |
|
4183 | + } |
|
4023 | 4184 | |
4024 | 4185 | $request = $smcFunc['db_query']('', ' |
4025 | 4186 | SELECT |
@@ -4043,8 +4204,9 @@ discard block |
||
4043 | 4204 | 'logic' => $row['is_or'] ? 'or' : 'and', |
4044 | 4205 | ); |
4045 | 4206 | |
4046 | - if ($row['delete_pm']) |
|
4047 | - $context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1); |
|
4207 | + if ($row['delete_pm']) { |
|
4208 | + $context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1); |
|
4209 | + } |
|
4048 | 4210 | } |
4049 | 4211 | $smcFunc['db_free_result']($request); |
4050 | 4212 | } |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 4 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * Fetches a list of boards and (optional) categories including |
@@ -37,19 +38,21 @@ discard block |
||
37 | 38 | require_once($sourcedir . '/Subs-Boards.php'); |
38 | 39 | |
39 | 40 | // For performance, track the latest post while going through the boards. |
40 | - if (!empty($boardIndexOptions['set_latest_post'])) |
|
41 | - $latest_post = array( |
|
41 | + if (!empty($boardIndexOptions['set_latest_post'])) { |
|
42 | + $latest_post = array( |
|
42 | 43 | 'timestamp' => 0, |
43 | 44 | 'ref' => 0, |
44 | 45 | ); |
46 | + } |
|
45 | 47 | |
46 | 48 | // This setting is not allowed to be empty |
47 | - if (empty($modSettings['boardindex_max_depth'])) |
|
48 | - $modSettings['boardindex_max_depth'] = 1; |
|
49 | + if (empty($modSettings['boardindex_max_depth'])) { |
|
50 | + $modSettings['boardindex_max_depth'] = 1; |
|
51 | + } |
|
49 | 52 | |
50 | 53 | // Find all boards and categories, as well as related information. This will be sorted by the natural order of boards and categories, which we control. |
51 | - if ($boardIndexOptions['parent_id'] != 0 && $smcFunc['db_cte_support']()) |
|
52 | - $result_boards = $smcFunc['db_query']('', ' |
|
54 | + if ($boardIndexOptions['parent_id'] != 0 && $smcFunc['db_cte_support']()) { |
|
55 | + $result_boards = $smcFunc['db_query']('', ' |
|
53 | 56 | WITH RECURSIVE |
54 | 57 | boards_cte (child_level, id_board, name , description, redirect, num_posts, num_topics, unapproved_posts, unapproved_topics, id_parent, id_msg_updated, id_cat, id_last_msg, board_order) |
55 | 58 | as |
@@ -91,8 +94,8 @@ discard block |
||
91 | 94 | 'id_parent' => $boardIndexOptions['parent_id'], |
92 | 95 | ) |
93 | 96 | ); |
94 | - else |
|
95 | - $result_boards = $smcFunc['db_query']('', ' |
|
97 | + } else { |
|
98 | + $result_boards = $smcFunc['db_query']('', ' |
|
96 | 99 | SELECT' . ($boardIndexOptions['include_categories'] ? ' |
97 | 100 | c.id_cat, c.name AS cat_name, c.description AS cat_desc,' : '') . ' |
98 | 101 | b.id_board, b.name AS board_name, b.description, |
@@ -120,18 +123,21 @@ discard block |
||
120 | 123 | 'blank_string' => '', |
121 | 124 | ) |
122 | 125 | ); |
126 | + } |
|
123 | 127 | |
124 | 128 | // Start with an empty array. |
125 | - if ($boardIndexOptions['include_categories']) |
|
126 | - $categories = array(); |
|
127 | - else |
|
128 | - $this_category = array(); |
|
129 | + if ($boardIndexOptions['include_categories']) { |
|
130 | + $categories = array(); |
|
131 | + } else { |
|
132 | + $this_category = array(); |
|
133 | + } |
|
129 | 134 | $boards = array(); |
130 | 135 | |
131 | 136 | // Children can affect parents, so we need to gather all the boards first and then process them after. |
132 | 137 | $row_boards = array(); |
133 | - while ($row_board = $smcFunc['db_fetch_assoc']($result_boards)) |
|
134 | - $row_boards[$row_board['id_board']] = $row_board; |
|
138 | + while ($row_board = $smcFunc['db_fetch_assoc']($result_boards)) { |
|
139 | + $row_boards[$row_board['id_board']] = $row_board; |
|
140 | + } |
|
135 | 141 | $smcFunc['db_free_result']($result_boards); |
136 | 142 | |
137 | 143 | // Run through the categories and boards (or only boards).... |
@@ -144,8 +150,9 @@ discard block |
||
144 | 150 | $row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0'; |
145 | 151 | |
146 | 152 | // Add parent boards to the $boards list later used to fetch moderators |
147 | - if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) |
|
148 | - $boards[] = $row_board['id_board']; |
|
153 | + if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) { |
|
154 | + $boards[] = $row_board['id_board']; |
|
155 | + } |
|
149 | 156 | |
150 | 157 | if ($boardIndexOptions['include_categories']) |
151 | 158 | { |
@@ -167,8 +174,9 @@ discard block |
||
167 | 174 | } |
168 | 175 | |
169 | 176 | // If this board has new posts in it (and isn't the recycle bin!) then the category is new. |
170 | - if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) |
|
171 | - $categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']); |
|
177 | + if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) { |
|
178 | + $categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']); |
|
179 | + } |
|
172 | 180 | |
173 | 181 | // Avoid showing category unread link where it only has redirection boards. |
174 | 182 | $categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect']; |
@@ -187,8 +195,9 @@ discard block |
||
187 | 195 | $isChild = false; |
188 | 196 | |
189 | 197 | // We might or might not have already added this board, so... |
190 | - if (!isset($this_category[$row_board['id_board']])) |
|
191 | - $this_category[$row_board['id_board']] = array(); |
|
198 | + if (!isset($this_category[$row_board['id_board']])) { |
|
199 | + $this_category[$row_board['id_board']] = array(); |
|
200 | + } |
|
192 | 201 | |
193 | 202 | $this_category[$row_board['id_board']] += array( |
194 | 203 | 'new' => empty($row_board['is_read']), |
@@ -221,14 +230,12 @@ discard block |
||
221 | 230 | { |
222 | 231 | $this_category[$row_board['id_board']]['board_class'] = 'redirect'; |
223 | 232 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['redirect_board']; |
224 | - } |
|
225 | - elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest']) |
|
233 | + } elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest']) |
|
226 | 234 | { |
227 | 235 | // If we're showing to guests, we want to give them the idea that something interesting is going on! |
228 | 236 | $this_category[$row_board['id_board']]['board_class'] = 'on'; |
229 | 237 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['new_posts']; |
230 | - } |
|
231 | - else |
|
238 | + } else |
|
232 | 239 | { |
233 | 240 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['old_posts']; |
234 | 241 | } |
@@ -240,12 +247,13 @@ discard block |
||
240 | 247 | $isChild = true; |
241 | 248 | |
242 | 249 | // Ensure the parent has at least the most important info defined |
243 | - if (!isset($this_category[$row_board['id_parent']])) |
|
244 | - $this_category[$row_board['id_parent']] = array( |
|
250 | + if (!isset($this_category[$row_board['id_parent']])) { |
|
251 | + $this_category[$row_board['id_parent']] = array( |
|
245 | 252 | 'children' => array(), |
246 | 253 | 'children_new' => false, |
247 | 254 | 'board_class' => 'off', |
248 | 255 | ); |
256 | + } |
|
249 | 257 | |
250 | 258 | $this_category[$row_board['id_parent']]['children'][$row_board['id_board']] = array( |
251 | 259 | 'id' => $row_board['id_board'], |
@@ -289,8 +297,9 @@ discard block |
||
289 | 297 | // Propagate some values to the parent board |
290 | 298 | if (isset($row_boards[$row_board['id_parent']])) |
291 | 299 | { |
292 | - if (empty($row_board['is_read'])) |
|
293 | - $row_boards[$row_board['id_parent']]['is_read'] = $row_board['is_read']; |
|
300 | + if (empty($row_board['is_read'])) { |
|
301 | + $row_boards[$row_board['id_parent']]['is_read'] = $row_board['is_read']; |
|
302 | + } |
|
294 | 303 | |
295 | 304 | if (!empty($boardIndexOptions['countChildPosts']) && !$row_board['is_redirect']) |
296 | 305 | { |
@@ -341,20 +350,20 @@ discard block |
||
341 | 350 | 'topic' => $row_board['id_topic'] |
342 | 351 | ); |
343 | 352 | |
344 | - if (!empty($settings['avatars_on_boardIndex'])) |
|
345 | - $this_last_post['member']['avatar'] = set_avatar_data(array( |
|
353 | + if (!empty($settings['avatars_on_boardIndex'])) { |
|
354 | + $this_last_post['member']['avatar'] = set_avatar_data(array( |
|
346 | 355 | 'avatar' => $row_board['avatar'], |
347 | 356 | 'email' => $row_board['email_address'], |
348 | 357 | 'filename' => !empty($row_board['member_filename']) ? $row_board['member_filename'] : '', |
349 | 358 | )); |
359 | + } |
|
350 | 360 | |
351 | 361 | // Provide the href and link. |
352 | 362 | if ($row_board['subject'] != '') |
353 | 363 | { |
354 | 364 | $this_last_post['href'] = $scripturl . '?topic=' . $row_board['id_topic'] . '.msg' . ($user_info['is_guest'] ? $row_board['id_msg'] : $row_board['new_from']) . (empty($row_board['is_read']) ? ';boardseen' : '') . '#new'; |
355 | 365 | $this_last_post['link'] = '<a href="' . $this_last_post['href'] . '" title="' . $row_board['subject'] . '">' . $row_board['short_subject'] . '</a>'; |
356 | - } |
|
357 | - else |
|
366 | + } else |
|
358 | 367 | { |
359 | 368 | $this_last_post['href'] = ''; |
360 | 369 | $this_last_post['link'] = $txt['not_applicable']; |
@@ -363,27 +372,31 @@ discard block |
||
363 | 372 | |
364 | 373 | // Set the last post in the parent board. |
365 | 374 | if ($isChild && !empty($row_board['poster_time']) |
366 | - && $row_boards[$row_board['id_parent']]['poster_time'] < $row_board['poster_time']) |
|
367 | - $this_category[$row_board['id_parent']]['last_post'] = $this_last_post; |
|
375 | + && $row_boards[$row_board['id_parent']]['poster_time'] < $row_board['poster_time']) { |
|
376 | + $this_category[$row_board['id_parent']]['last_post'] = $this_last_post; |
|
377 | + } |
|
368 | 378 | |
369 | 379 | // Set the last post in the root board |
370 | 380 | if (!$isChild && !empty($row_board['poster_time']) |
371 | 381 | && ( empty($this_category[$row_board['id_board']]['last_post']['timestamp']) |
372 | 382 | || $this_category[$row_board['id_board']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time']) |
373 | 383 | ) |
374 | - ) |
|
375 | - $this_category[$row_board['id_board']]['last_post'] = $this_last_post; |
|
384 | + ) { |
|
385 | + $this_category[$row_board['id_board']]['last_post'] = $this_last_post; |
|
386 | + } |
|
376 | 387 | |
377 | 388 | // Just in the child...? |
378 | - if ($isChild) |
|
379 | - $this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post; |
|
389 | + if ($isChild) { |
|
390 | + $this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post; |
|
391 | + } |
|
380 | 392 | |
381 | 393 | // Determine a global most recent topic. |
382 | - if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) |
|
383 | - $latest_post = array( |
|
394 | + if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) { |
|
395 | + $latest_post = array( |
|
384 | 396 | 'timestamp' => $row_board['poster_time'], |
385 | 397 | 'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'], |
386 | 398 | ); |
399 | + } |
|
387 | 400 | } |
388 | 401 | |
389 | 402 | /* The board's and children's 'last_post's have: |
@@ -395,16 +408,18 @@ discard block |
||
395 | 408 | $boards = array_unique($boards); |
396 | 409 | $moderators = getBoardModerators($boards); |
397 | 410 | $groups = getBoardModeratorGroups($boards); |
398 | - if ($boardIndexOptions['include_categories']) |
|
399 | - foreach ($categories as &$category) |
|
411 | + if ($boardIndexOptions['include_categories']) { |
|
412 | + foreach ($categories as &$category) |
|
400 | 413 | { |
401 | 414 | foreach ($category['boards'] as &$board ) |
402 | 415 | { |
403 | 416 | if (!empty($moderators[$board['id']])) |
404 | 417 | { |
405 | 418 | $board['moderators'] = $moderators[$board['id']]; |
406 | - foreach ($moderators[$board['id']] as $moderator) |
|
407 | - $board['link_moderators'][] = $moderator['link']; |
|
419 | + } |
|
420 | + foreach ($moderators[$board['id']] as $moderator) { |
|
421 | + $board['link_moderators'][] = $moderator['link']; |
|
422 | + } |
|
408 | 423 | } |
409 | 424 | if (!empty($groups[$board['id']])) |
410 | 425 | { |
@@ -415,18 +430,20 @@ discard block |
||
415 | 430 | $board['link_moderator_groups'][] = $group['link']; |
416 | 431 | } |
417 | 432 | } |
418 | - if (!empty($board['last_post'])) |
|
419 | - $board['last_post']['last_post_message'] = sprintf($txt['last_post_message'], $board['last_post']['member']['link'], $board['last_post']['link'], $board['last_post']['time'] > 0 ? timeformat($board['last_post']['time']) : $txt['not_applicable']); |
|
433 | + if (!empty($board['last_post'])) { |
|
434 | + $board['last_post']['last_post_message'] = sprintf($txt['last_post_message'], $board['last_post']['member']['link'], $board['last_post']['link'], $board['last_post']['time'] > 0 ? timeformat($board['last_post']['time']) : $txt['not_applicable']); |
|
435 | + } |
|
420 | 436 | } |
421 | - } |
|
422 | - else |
|
423 | - foreach ($this_category as &$board ) |
|
437 | + } else { |
|
438 | + foreach ($this_category as &$board ) |
|
424 | 439 | { |
425 | 440 | if (!empty($moderators[$board['id']])) |
426 | 441 | { |
427 | 442 | $board['moderators'] = $moderators[$board['id']]; |
428 | - foreach ($moderators[$board['id']] as $moderator) |
|
429 | - $board['link_moderators'][] = $moderator['link']; |
|
443 | + } |
|
444 | + foreach ($moderators[$board['id']] as $moderator) { |
|
445 | + $board['link_moderators'][] = $moderator['link']; |
|
446 | + } |
|
430 | 447 | } |
431 | 448 | if (!empty($groups[$board['id']])) |
432 | 449 | { |
@@ -437,26 +454,30 @@ discard block |
||
437 | 454 | $board['link_moderator_groups'][] = $group['link']; |
438 | 455 | } |
439 | 456 | } |
440 | - if (!empty($board['last_post'])) |
|
441 | - $board['last_post']['last_post_message'] = sprintf($txt['last_post_message'], $board['last_post']['member']['link'], $board['last_post']['link'], $board['last_post']['time'] > 0 ? timeformat($board['last_post']['time']) : $txt['not_applicable']); |
|
457 | + if (!empty($board['last_post'])) { |
|
458 | + $board['last_post']['last_post_message'] = sprintf($txt['last_post_message'], $board['last_post']['member']['link'], $board['last_post']['link'], $board['last_post']['time'] > 0 ? timeformat($board['last_post']['time']) : $txt['not_applicable']); |
|
459 | + } |
|
442 | 460 | } |
443 | 461 | |
444 | 462 | unset($category,$board); |
445 | 463 | |
446 | - if ($boardIndexOptions['include_categories']) |
|
447 | - sortCategories($categories); |
|
448 | - else |
|
449 | - sortBoards($this_category); |
|
464 | + if ($boardIndexOptions['include_categories']) { |
|
465 | + sortCategories($categories); |
|
466 | + } else { |
|
467 | + sortBoards($this_category); |
|
468 | + } |
|
450 | 469 | |
451 | 470 | // By now we should know the most recent post...if we wanna know it that is. |
452 | - if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) |
|
453 | - $context['latest_post'] = $latest_post['ref']; |
|
471 | + if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) { |
|
472 | + $context['latest_post'] = $latest_post['ref']; |
|
473 | + } |
|
454 | 474 | |
455 | 475 | // I can't remember why but trying to make a ternary to get this all in one line is actually a Very Bad Idea. |
456 | - if ($boardIndexOptions['include_categories']) |
|
457 | - call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories)); |
|
458 | - else |
|
459 | - call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category)); |
|
476 | + if ($boardIndexOptions['include_categories']) { |
|
477 | + call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories)); |
|
478 | + } else { |
|
479 | + call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category)); |
|
480 | + } |
|
460 | 481 | |
461 | 482 | return $boardIndexOptions['include_categories'] ? $categories : $this_category; |
462 | 483 | } |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * The main entrance point for the Manage Members screen. |
@@ -109,12 +110,13 @@ discard block |
||
109 | 110 | $context['tabs'][$context['last_tab']]['is_last'] = true; |
110 | 111 | |
111 | 112 | // Find the active tab. |
112 | - if (isset($context['tabs'][$context['current_subaction']])) |
|
113 | - $context['tabs'][$context['current_subaction']]['is_selected'] = true; |
|
114 | - elseif (isset($context['current_subaction'])) |
|
115 | - foreach ($context['tabs'] as $id_tab => $tab_data) |
|
113 | + if (isset($context['tabs'][$context['current_subaction']])) { |
|
114 | + $context['tabs'][$context['current_subaction']]['is_selected'] = true; |
|
115 | + } elseif (isset($context['current_subaction'])) { |
|
116 | + foreach ($context['tabs'] as $id_tab => $tab_data) |
|
116 | 117 | if (!empty($tab_data['selected_actions']) && in_array($context['current_subaction'], $tab_data['selected_actions'])) |
117 | 118 | $context['tabs'][$id_tab]['is_selected'] = true; |
119 | + } |
|
118 | 120 | |
119 | 121 | call_helper($subActions[$context['current_subaction']][0]); |
120 | 122 | } |
@@ -141,8 +143,9 @@ discard block |
||
141 | 143 | foreach ($_POST['delete'] as $key => $value) |
142 | 144 | { |
143 | 145 | // Don't delete yourself, idiot. |
144 | - if ($value != $user_info['id']) |
|
145 | - $delete[$key] = (int) $value; |
|
146 | + if ($value != $user_info['id']) { |
|
147 | + $delete[$key] = (int) $value; |
|
148 | + } |
|
146 | 149 | } |
147 | 150 | |
148 | 151 | if (!empty($delete)) |
@@ -178,17 +181,18 @@ discard block |
||
178 | 181 | ); |
179 | 182 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
180 | 183 | { |
181 | - if ($row['min_posts'] == -1) |
|
182 | - $context['membergroups'][] = array( |
|
184 | + if ($row['min_posts'] == -1) { |
|
185 | + $context['membergroups'][] = array( |
|
183 | 186 | 'id' => $row['id_group'], |
184 | 187 | 'name' => $row['group_name'], |
185 | 188 | 'can_be_additional' => true |
186 | 189 | ); |
187 | - else |
|
188 | - $context['postgroups'][] = array( |
|
190 | + } else { |
|
191 | + $context['postgroups'][] = array( |
|
189 | 192 | 'id' => $row['id_group'], |
190 | 193 | 'name' => $row['group_name'] |
191 | 194 | ); |
195 | + } |
|
192 | 196 | } |
193 | 197 | $smcFunc['db_free_result']($request); |
194 | 198 | |
@@ -260,14 +264,15 @@ discard block |
||
260 | 264 | call_integration_hook('integrate_view_members_params', array(&$params)); |
261 | 265 | |
262 | 266 | $search_params = array(); |
263 | - if ($context['current_subaction'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types'])) |
|
264 | - $search_params = $smcFunc['json_decode'](base64_decode($_REQUEST['params']), true); |
|
265 | - elseif (!empty($_POST)) |
|
267 | + if ($context['current_subaction'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types'])) { |
|
268 | + $search_params = $smcFunc['json_decode'](base64_decode($_REQUEST['params']), true); |
|
269 | + } elseif (!empty($_POST)) |
|
266 | 270 | { |
267 | 271 | $search_params['types'] = $_POST['types']; |
268 | - foreach ($params as $param_name => $param_info) |
|
269 | - if (isset($_POST[$param_name])) |
|
272 | + foreach ($params as $param_name => $param_info) { |
|
273 | + if (isset($_POST[$param_name])) |
|
270 | 274 | $search_params[$param_name] = $_POST[$param_name]; |
275 | + } |
|
271 | 276 | } |
272 | 277 | |
273 | 278 | $search_url_params = isset($search_params) ? base64_encode($smcFunc['json_encode']($search_params)) : null; |
@@ -280,34 +285,38 @@ discard block |
||
280 | 285 | foreach ($params as $param_name => $param_info) |
281 | 286 | { |
282 | 287 | // Not filled in? |
283 | - if (!isset($search_params[$param_name]) || $search_params[$param_name] === '') |
|
284 | - continue; |
|
288 | + if (!isset($search_params[$param_name]) || $search_params[$param_name] === '') { |
|
289 | + continue; |
|
290 | + } |
|
285 | 291 | |
286 | 292 | // Make sure numeric values are really numeric. |
287 | - if (in_array($param_info['type'], array('int', 'age'))) |
|
288 | - $search_params[$param_name] = (int) $search_params[$param_name]; |
|
293 | + if (in_array($param_info['type'], array('int', 'age'))) { |
|
294 | + $search_params[$param_name] = (int) $search_params[$param_name]; |
|
295 | + } |
|
289 | 296 | // Date values have to match the specified format. |
290 | 297 | elseif ($param_info['type'] == 'date') |
291 | 298 | { |
292 | 299 | // Check if this date format is valid. |
293 | - if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0) |
|
294 | - continue; |
|
300 | + if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0) { |
|
301 | + continue; |
|
302 | + } |
|
295 | 303 | |
296 | 304 | $search_params[$param_name] = strtotime($search_params[$param_name]); |
297 | - } |
|
298 | - elseif ($param_info['type'] == 'inet') |
|
305 | + } elseif ($param_info['type'] == 'inet') |
|
299 | 306 | { |
300 | 307 | $search_params[$param_name] = ip2range($search_params[$param_name]); |
301 | - if (empty($search_params[$param_name])) |
|
302 | - continue; |
|
308 | + if (empty($search_params[$param_name])) { |
|
309 | + continue; |
|
310 | + } |
|
303 | 311 | } |
304 | 312 | |
305 | 313 | // Those values that are in some kind of range (<, <=, =, >=, >). |
306 | 314 | if (!empty($param_info['range'])) |
307 | 315 | { |
308 | 316 | // Default to '=', just in case... |
309 | - if (empty($range_trans[$search_params['types'][$param_name]])) |
|
310 | - $search_params['types'][$param_name] = '='; |
|
317 | + if (empty($range_trans[$search_params['types'][$param_name]])) { |
|
318 | + $search_params['types'][$param_name] = '='; |
|
319 | + } |
|
311 | 320 | |
312 | 321 | // Handle special case 'age'. |
313 | 322 | if ($param_info['type'] == 'age') |
@@ -335,16 +344,17 @@ discard block |
||
335 | 344 | elseif ($param_info['type'] == 'date' && $search_params['types'][$param_name] == '=') |
336 | 345 | { |
337 | 346 | $query_parts[] = $param_info['db_fields'][0] . ' > ' . $search_params[$param_name] . ' AND ' . $param_info['db_fields'][0] . ' < ' . ($search_params[$param_name] + 86400); |
347 | + } else { |
|
348 | + $query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name]; |
|
338 | 349 | } |
339 | - else |
|
340 | - $query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name]; |
|
341 | 350 | } |
342 | 351 | // Checkboxes. |
343 | 352 | elseif ($param_info['type'] == 'checkbox') |
344 | 353 | { |
345 | 354 | // Each checkbox or no checkbox at all is checked -> ignore. |
346 | - if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values'])) |
|
347 | - continue; |
|
355 | + if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values'])) { |
|
356 | + continue; |
|
357 | + } |
|
348 | 358 | |
349 | 359 | $query_parts[] = ($param_info['db_fields'][0]) . ' IN ({array_string:' . $param_name . '_check})'; |
350 | 360 | $where_params[$param_name . '_check'] = $search_params[$param_name]; |
@@ -356,24 +366,23 @@ discard block |
||
356 | 366 | { |
357 | 367 | $query_parts[] = '(' . $param_info['db_fields'][0] . ' = {inet:' . $param_name . '})'; |
358 | 368 | $where_params[$param_name] = $search_params[$param_name][0]; |
359 | - } |
|
360 | - elseif (count($search_params[$param_name]) === 2) |
|
369 | + } elseif (count($search_params[$param_name]) === 2) |
|
361 | 370 | { |
362 | 371 | $query_parts[] = '(' . $param_info['db_fields'][0] . ' <= {inet:' . $param_name . '_high} and ' . $param_info['db_fields'][0] . ' >= {inet:' . $param_name . '_low})'; |
363 | 372 | $where_params[$param_name.'_low'] = $search_params[$param_name]['low']; |
364 | 373 | $where_params[$param_name.'_high'] = $search_params[$param_name]['high']; |
365 | 374 | } |
366 | 375 | |
367 | - } |
|
368 | - elseif ($param_info['type'] != 'groups') |
|
376 | + } elseif ($param_info['type'] != 'groups') |
|
369 | 377 | { |
370 | 378 | // Replace the wildcard characters ('*' and '?') into MySQL ones. |
371 | 379 | $parameter = strtolower(strtr($smcFunc['htmlspecialchars']($search_params[$param_name], ENT_QUOTES), array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_'))); |
372 | 380 | |
373 | - if ($smcFunc['db_case_sensitive']) |
|
374 | - $query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})'; |
|
375 | - else |
|
376 | - $query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})'; |
|
381 | + if ($smcFunc['db_case_sensitive']) { |
|
382 | + $query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})'; |
|
383 | + } else { |
|
384 | + $query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})'; |
|
385 | + } |
|
377 | 386 | $where_params[$param_name . '_normal'] = '%' . $parameter . '%'; |
378 | 387 | } |
379 | 388 | } |
@@ -389,16 +398,18 @@ discard block |
||
389 | 398 | } |
390 | 399 | |
391 | 400 | // Additional membergroups (these are only relevant if not all primary groups where selected!). |
392 | - if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1]))) |
|
393 | - foreach ($search_params['membergroups'][2] as $mg) |
|
401 | + if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1]))) { |
|
402 | + foreach ($search_params['membergroups'][2] as $mg) |
|
394 | 403 | { |
395 | 404 | $mg_query_parts[] = 'FIND_IN_SET({int:add_group_' . $mg . '}, mem.additional_groups) != 0'; |
405 | + } |
|
396 | 406 | $where_params['add_group_' . $mg] = $mg; |
397 | 407 | } |
398 | 408 | |
399 | 409 | // Combine the one or two membergroup parts into one query part linked with an OR. |
400 | - if (!empty($mg_query_parts)) |
|
401 | - $query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')'; |
|
410 | + if (!empty($mg_query_parts)) { |
|
411 | + $query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')'; |
|
412 | + } |
|
402 | 413 | |
403 | 414 | // Get all selected post count related membergroups. |
404 | 415 | if (!empty($search_params['postgroups']) && count($search_params['postgroups']) != count($context['postgroups'])) |
@@ -410,9 +421,9 @@ discard block |
||
410 | 421 | // Construct the where part of the query. |
411 | 422 | $where = empty($query_parts) ? '1=1' : implode(' |
412 | 423 | AND ', $query_parts); |
424 | + } else { |
|
425 | + $search_url_params = null; |
|
413 | 426 | } |
414 | - else |
|
415 | - $search_url_params = null; |
|
416 | 427 | |
417 | 428 | // Construct the additional URL part with the query info in it. |
418 | 429 | $context['params_url'] = $context['current_subaction'] == 'query' ? ';sa=query;params=' . $search_url_params : ''; |
@@ -535,28 +546,32 @@ discard block |
||
535 | 546 | 'function' => function($rowData) use ($txt) |
536 | 547 | { |
537 | 548 | // Calculate number of days since last online. |
538 | - if (empty($rowData['last_login'])) |
|
539 | - $difference = $txt['never']; |
|
540 | - else |
|
549 | + if (empty($rowData['last_login'])) { |
|
550 | + $difference = $txt['never']; |
|
551 | + } else |
|
541 | 552 | { |
542 | 553 | $num_days_difference = jeffsdatediff($rowData['last_login']); |
543 | 554 | |
544 | 555 | // Today. |
545 | - if (empty($num_days_difference)) |
|
546 | - $difference = $txt['viewmembers_today']; |
|
556 | + if (empty($num_days_difference)) { |
|
557 | + $difference = $txt['viewmembers_today']; |
|
558 | + } |
|
547 | 559 | |
548 | 560 | // Yesterday. |
549 | - elseif ($num_days_difference == 1) |
|
550 | - $difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']); |
|
561 | + elseif ($num_days_difference == 1) { |
|
562 | + $difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']); |
|
563 | + } |
|
551 | 564 | |
552 | 565 | // X days ago. |
553 | - else |
|
554 | - $difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']); |
|
566 | + else { |
|
567 | + $difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']); |
|
568 | + } |
|
555 | 569 | } |
556 | 570 | |
557 | 571 | // Show it in italics if they're not activated... |
558 | - if ($rowData['is_activated'] % 10 != 1) |
|
559 | - $difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference); |
|
572 | + if ($rowData['is_activated'] % 10 != 1) { |
|
573 | + $difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference); |
|
574 | + } |
|
560 | 575 | |
561 | 576 | return $difference; |
562 | 577 | }, |
@@ -608,8 +623,9 @@ discard block |
||
608 | 623 | ); |
609 | 624 | |
610 | 625 | // Without enough permissions, don't show 'delete members' checkboxes. |
611 | - if (!allowedTo('profile_remove_any')) |
|
612 | - unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']); |
|
626 | + if (!allowedTo('profile_remove_any')) { |
|
627 | + unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']); |
|
628 | + } |
|
613 | 629 | |
614 | 630 | require_once($sourcedir . '/Subs-List.php'); |
615 | 631 | createList($listOptions); |
@@ -652,17 +668,18 @@ discard block |
||
652 | 668 | ); |
653 | 669 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
654 | 670 | { |
655 | - if ($row['min_posts'] == -1) |
|
656 | - $context['membergroups'][] = array( |
|
671 | + if ($row['min_posts'] == -1) { |
|
672 | + $context['membergroups'][] = array( |
|
657 | 673 | 'id' => $row['id_group'], |
658 | 674 | 'name' => $row['group_name'], |
659 | 675 | 'can_be_additional' => true |
660 | 676 | ); |
661 | - else |
|
662 | - $context['postgroups'][] = array( |
|
677 | + } else { |
|
678 | + $context['postgroups'][] = array( |
|
663 | 679 | 'id' => $row['id_group'], |
664 | 680 | 'name' => $row['group_name'] |
665 | 681 | ); |
682 | + } |
|
666 | 683 | } |
667 | 684 | $smcFunc['db_free_result']($request); |
668 | 685 | |
@@ -689,8 +706,9 @@ discard block |
||
689 | 706 | $context['page_title'] = $txt['admin_members']; |
690 | 707 | $context['sub_template'] = 'admin_browse'; |
691 | 708 | $context['browse_type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? 'activate' : 'approve'); |
692 | - if (isset($context['tabs'][$context['browse_type']])) |
|
693 | - $context['tabs'][$context['browse_type']]['is_selected'] = true; |
|
709 | + if (isset($context['tabs'][$context['browse_type']])) { |
|
710 | + $context['tabs'][$context['browse_type']]['is_selected'] = true; |
|
711 | + } |
|
694 | 712 | |
695 | 713 | // Allowed filters are those we can have, in theory. |
696 | 714 | $context['allowed_filters'] = $context['browse_type'] == 'approve' ? array(3, 4, 5) : array(0, 2); |
@@ -701,18 +719,20 @@ discard block |
||
701 | 719 | foreach ($context['activation_numbers'] as $type => $amount) |
702 | 720 | { |
703 | 721 | // We have some of these... |
704 | - if (in_array($type, $context['allowed_filters']) && $amount > 0) |
|
705 | - $context['available_filters'][] = array( |
|
722 | + if (in_array($type, $context['allowed_filters']) && $amount > 0) { |
|
723 | + $context['available_filters'][] = array( |
|
706 | 724 | 'type' => $type, |
707 | 725 | 'amount' => $amount, |
708 | 726 | 'desc' => isset($txt['admin_browse_filter_type_' . $type]) ? $txt['admin_browse_filter_type_' . $type] : '?', |
709 | 727 | 'selected' => $type == $context['current_filter'] |
710 | 728 | ); |
729 | + } |
|
711 | 730 | } |
712 | 731 | |
713 | 732 | // If the filter was not sent, set it to whatever has people in it! |
714 | - if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount'])) |
|
715 | - $context['current_filter'] = $context['available_filters'][0]['type']; |
|
733 | + if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount'])) { |
|
734 | + $context['current_filter'] = $context['available_filters'][0]['type']; |
|
735 | + } |
|
716 | 736 | |
717 | 737 | // This little variable is used to determine if we should flag where we are looking. |
718 | 738 | $context['show_filter'] = ($context['current_filter'] != 0 && $context['current_filter'] != 3) || count($context['available_filters']) > 1; |
@@ -727,44 +747,47 @@ discard block |
||
727 | 747 | ); |
728 | 748 | |
729 | 749 | // Are we showing duplicate information? |
730 | - if (isset($_GET['showdupes'])) |
|
731 | - $_SESSION['showdupes'] = (int) $_GET['showdupes']; |
|
750 | + if (isset($_GET['showdupes'])) { |
|
751 | + $_SESSION['showdupes'] = (int) $_GET['showdupes']; |
|
752 | + } |
|
732 | 753 | $context['show_duplicates'] = !empty($_SESSION['showdupes']); |
733 | 754 | |
734 | 755 | // Determine which actions we should allow on this page. |
735 | 756 | if ($context['browse_type'] == 'approve') |
736 | 757 | { |
737 | 758 | // If we are approving deleted accounts we have a slightly different list... actually a mirror ;) |
738 | - if ($context['current_filter'] == 4) |
|
739 | - $context['allowed_actions'] = array( |
|
759 | + if ($context['current_filter'] == 4) { |
|
760 | + $context['allowed_actions'] = array( |
|
740 | 761 | 'reject' => $txt['admin_browse_w_approve_deletion'], |
741 | 762 | 'ok' => $txt['admin_browse_w_reject'], |
742 | 763 | ); |
743 | - else |
|
744 | - $context['allowed_actions'] = array( |
|
764 | + } else { |
|
765 | + $context['allowed_actions'] = array( |
|
745 | 766 | 'ok' => $txt['admin_browse_w_approve'], |
746 | 767 | 'okemail' => $txt['admin_browse_w_approve'] . ' ' . $txt['admin_browse_w_email'], |
747 | 768 | 'require_activation' => $txt['admin_browse_w_approve_require_activate'], |
748 | 769 | 'reject' => $txt['admin_browse_w_reject'], |
749 | 770 | 'rejectemail' => $txt['admin_browse_w_reject'] . ' ' . $txt['admin_browse_w_email'], |
750 | 771 | ); |
751 | - } |
|
752 | - elseif ($context['browse_type'] == 'activate') |
|
753 | - $context['allowed_actions'] = array( |
|
772 | + } |
|
773 | + } elseif ($context['browse_type'] == 'activate') { |
|
774 | + $context['allowed_actions'] = array( |
|
754 | 775 | 'ok' => $txt['admin_browse_w_activate'], |
755 | 776 | 'okemail' => $txt['admin_browse_w_activate'] . ' ' . $txt['admin_browse_w_email'], |
756 | 777 | 'delete' => $txt['admin_browse_w_delete'], |
757 | 778 | 'deleteemail' => $txt['admin_browse_w_delete'] . ' ' . $txt['admin_browse_w_email'], |
758 | 779 | 'remind' => $txt['admin_browse_w_remind'] . ' ' . $txt['admin_browse_w_email'], |
759 | 780 | ); |
781 | + } |
|
760 | 782 | |
761 | 783 | // Create an option list for actions allowed to be done with selected members. |
762 | 784 | $allowed_actions = ' |
763 | 785 | <option selected value="">' . $txt['admin_browse_with_selected'] . ':</option> |
764 | 786 | <option value="" disabled>-----------------------------</option>'; |
765 | - foreach ($context['allowed_actions'] as $key => $desc) |
|
766 | - $allowed_actions .= ' |
|
787 | + foreach ($context['allowed_actions'] as $key => $desc) { |
|
788 | + $allowed_actions .= ' |
|
767 | 789 | <option value="' . $key . '">' . $desc . '</option>'; |
790 | + } |
|
768 | 791 | |
769 | 792 | // Setup the Javascript function for selecting an action for the list. |
770 | 793 | $javascript = ' |
@@ -776,15 +799,16 @@ discard block |
||
776 | 799 | var message = "";'; |
777 | 800 | |
778 | 801 | // We have special messages for approving deletion of accounts - it's surprisingly logical - honest. |
779 | - if ($context['current_filter'] == 4) |
|
780 | - $javascript .= ' |
|
802 | + if ($context['current_filter'] == 4) { |
|
803 | + $javascript .= ' |
|
781 | 804 | if (document.forms.postForm.todo.value.indexOf("reject") != -1) |
782 | 805 | message = "' . $txt['admin_browse_w_delete'] . '"; |
783 | 806 | else |
784 | 807 | message = "' . $txt['admin_browse_w_reject'] . '";'; |
808 | + } |
|
785 | 809 | // Otherwise a nice standard message. |
786 | - else |
|
787 | - $javascript .= ' |
|
810 | + else { |
|
811 | + $javascript .= ' |
|
788 | 812 | if (document.forms.postForm.todo.value.indexOf("delete") != -1) |
789 | 813 | message = "' . $txt['admin_browse_w_delete'] . '"; |
790 | 814 | else if (document.forms.postForm.todo.value.indexOf("reject") != -1) |
@@ -793,6 +817,7 @@ discard block |
||
793 | 817 | message = "' . $txt['admin_browse_w_remind'] . '"; |
794 | 818 | else |
795 | 819 | message = "' . ($context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate']) . '";'; |
820 | + } |
|
796 | 821 | $javascript .= ' |
797 | 822 | if (confirm(message + " ' . $txt['admin_browse_warn'] . '")) |
798 | 823 | document.forms.postForm.submit(); |
@@ -925,10 +950,11 @@ discard block |
||
925 | 950 | $member_links = array(); |
926 | 951 | foreach ($rowData['duplicate_members'] as $member) |
927 | 952 | { |
928 | - if ($member['id']) |
|
929 | - $member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>'; |
|
930 | - else |
|
931 | - $member_links[] = $member['name'] . ' (' . $txt['guest'] . ')'; |
|
953 | + if ($member['id']) { |
|
954 | + $member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>'; |
|
955 | + } else { |
|
956 | + $member_links[] = $member['name'] . ' (' . $txt['guest'] . ')'; |
|
957 | + } |
|
932 | 958 | } |
933 | 959 | return implode(', ', $member_links); |
934 | 960 | }, |
@@ -977,14 +1003,16 @@ discard block |
||
977 | 1003 | ); |
978 | 1004 | |
979 | 1005 | // Pick what column to actually include if we're showing duplicates. |
980 | - if ($context['show_duplicates']) |
|
981 | - unset($listOptions['columns']['email']); |
|
982 | - else |
|
983 | - unset($listOptions['columns']['duplicates']); |
|
1006 | + if ($context['show_duplicates']) { |
|
1007 | + unset($listOptions['columns']['email']); |
|
1008 | + } else { |
|
1009 | + unset($listOptions['columns']['duplicates']); |
|
1010 | + } |
|
984 | 1011 | |
985 | 1012 | // Only show hostname on duplicates as it takes a lot of time. |
986 | - if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup'])) |
|
987 | - unset($listOptions['columns']['hostname']); |
|
1013 | + if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup'])) { |
|
1014 | + unset($listOptions['columns']['hostname']); |
|
1015 | + } |
|
988 | 1016 | |
989 | 1017 | // Is there any need to show filters? |
990 | 1018 | if (isset($context['available_filters']) && count($context['available_filters']) > 1) |
@@ -992,9 +1020,10 @@ discard block |
||
992 | 1020 | $filterOptions = ' |
993 | 1021 | <strong>' . $txt['admin_browse_filter_by'] . ':</strong> |
994 | 1022 | <select name="filter" onchange="this.form.submit();">'; |
995 | - foreach ($context['available_filters'] as $filter) |
|
996 | - $filterOptions .= ' |
|
1023 | + foreach ($context['available_filters'] as $filter) { |
|
1024 | + $filterOptions .= ' |
|
997 | 1025 | <option value="' . $filter['type'] . '"' . ($filter['selected'] ? ' selected' : '') . '>' . $filter['desc'] . ' - ' . $filter['amount'] . ' ' . ($filter['amount'] == 1 ? $txt['user'] : $txt['users']) . '</option>'; |
1026 | + } |
|
998 | 1027 | $filterOptions .= ' |
999 | 1028 | </select> |
1000 | 1029 | <noscript><input type="submit" value="' . $txt['go'] . '" name="filter" class="button"></noscript>'; |
@@ -1006,12 +1035,13 @@ discard block |
||
1006 | 1035 | } |
1007 | 1036 | |
1008 | 1037 | // What about if we only have one filter, but it's not the "standard" filter - show them what they are looking at. |
1009 | - if (!empty($context['show_filter']) && !empty($context['available_filters'])) |
|
1010 | - $listOptions['additional_rows'][] = array( |
|
1038 | + if (!empty($context['show_filter']) && !empty($context['available_filters'])) { |
|
1039 | + $listOptions['additional_rows'][] = array( |
|
1011 | 1040 | 'position' => 'above_column_headers', |
1012 | 1041 | 'value' => '<strong>' . $txt['admin_browse_filter_show'] . ':</strong> ' . ((isset($context['current_filter']) && isset($txt['admin_browse_filter_type_'.$context['current_filter']])) ? $txt['admin_browse_filter_type_'.$context['current_filter']] : $context['available_filters'][0]['desc']), |
1013 | 1042 | 'class' => 'filter_row generic_list_wrapper smalltext', |
1014 | 1043 | ); |
1044 | + } |
|
1015 | 1045 | |
1016 | 1046 | // Now that we have all the options, create the list. |
1017 | 1047 | require_once($sourcedir . '/Subs-List.php'); |
@@ -1041,12 +1071,14 @@ discard block |
||
1041 | 1071 | $current_filter = (int) $_REQUEST['orig_filter']; |
1042 | 1072 | |
1043 | 1073 | // If we are applying a filter do just that - then redirect. |
1044 | - if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) |
|
1045 | - redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']); |
|
1074 | + if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) { |
|
1075 | + redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']); |
|
1076 | + } |
|
1046 | 1077 | |
1047 | 1078 | // Nothing to do? |
1048 | - if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) |
|
1049 | - redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
1079 | + if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) { |
|
1080 | + redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
1081 | + } |
|
1050 | 1082 | |
1051 | 1083 | // Are we dealing with members who have been waiting for > set amount of time? |
1052 | 1084 | if (isset($_POST['time_passed'])) |
@@ -1059,8 +1091,9 @@ discard block |
||
1059 | 1091 | else |
1060 | 1092 | { |
1061 | 1093 | $members = array(); |
1062 | - foreach ($_POST['todoAction'] as $id) |
|
1063 | - $members[] = (int) $id; |
|
1094 | + foreach ($_POST['todoAction'] as $id) { |
|
1095 | + $members[] = (int) $id; |
|
1096 | + } |
|
1064 | 1097 | $condition = ' |
1065 | 1098 | AND id_member IN ({array_int:members})'; |
1066 | 1099 | } |
@@ -1081,8 +1114,9 @@ discard block |
||
1081 | 1114 | $member_count = $smcFunc['db_num_rows']($request); |
1082 | 1115 | |
1083 | 1116 | // If no results then just return! |
1084 | - if ($member_count == 0) |
|
1085 | - redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
1117 | + if ($member_count == 0) { |
|
1118 | + redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
1119 | + } |
|
1086 | 1120 | |
1087 | 1121 | $member_info = array(); |
1088 | 1122 | $members = array(); |
@@ -1121,8 +1155,9 @@ discard block |
||
1121 | 1155 | // Do we have to let the integration code know about the activations? |
1122 | 1156 | if (!empty($modSettings['integrate_activate'])) |
1123 | 1157 | { |
1124 | - foreach ($member_info as $member) |
|
1125 | - call_integration_hook('integrate_activate', array($member['username'])); |
|
1158 | + foreach ($member_info as $member) { |
|
1159 | + call_integration_hook('integrate_activate', array($member['username'])); |
|
1160 | + } |
|
1126 | 1161 | } |
1127 | 1162 | |
1128 | 1163 | // Check for email. |
@@ -1252,20 +1287,23 @@ discard block |
||
1252 | 1287 | $log_action = $_POST['todo'] == 'remind' ? 'remind_member' : 'approve_member'; |
1253 | 1288 | |
1254 | 1289 | require_once($sourcedir . '/Logging.php'); |
1255 | - foreach ($member_info as $member) |
|
1256 | - logAction($log_action, array('member' => $member['id']), 'admin'); |
|
1290 | + foreach ($member_info as $member) { |
|
1291 | + logAction($log_action, array('member' => $member['id']), 'admin'); |
|
1292 | + } |
|
1257 | 1293 | } |
1258 | 1294 | |
1259 | 1295 | // Although updateStats *may* catch this, best to do it manually just in case (Doesn't always sort out unapprovedMembers). |
1260 | - if (in_array($current_filter, array(3, 4, 5))) |
|
1261 | - updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0))); |
|
1296 | + if (in_array($current_filter, array(3, 4, 5))) { |
|
1297 | + updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0))); |
|
1298 | + } |
|
1262 | 1299 | |
1263 | 1300 | // Update the member's stats. (but, we know the member didn't change their name.) |
1264 | 1301 | updateStats('member', false); |
1265 | 1302 | |
1266 | 1303 | // If they haven't been deleted, update the post group statistics on them... |
1267 | - if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) |
|
1268 | - updateStats('postgroups', $members); |
|
1304 | + if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) { |
|
1305 | + updateStats('postgroups', $members); |
|
1306 | + } |
|
1269 | 1307 | |
1270 | 1308 | redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
1271 | 1309 | } |
@@ -1290,10 +1328,11 @@ discard block |
||
1290 | 1328 | $dis = time() - $old; |
1291 | 1329 | |
1292 | 1330 | // Before midnight? |
1293 | - if ($dis < $sinceMidnight) |
|
1294 | - return 0; |
|
1295 | - else |
|
1296 | - $dis -= $sinceMidnight; |
|
1331 | + if ($dis < $sinceMidnight) { |
|
1332 | + return 0; |
|
1333 | + } else { |
|
1334 | + $dis -= $sinceMidnight; |
|
1335 | + } |
|
1297 | 1336 | |
1298 | 1337 | // Divide out the seconds in a day to get the number of days. |
1299 | 1338 | return ceil($dis / (24 * 60 * 60)); |
@@ -1320,16 +1359,18 @@ discard block |
||
1320 | 1359 | $context['activation_numbers'] = array(); |
1321 | 1360 | $context['awaiting_activation'] = 0; |
1322 | 1361 | $context['awaiting_approval'] = 0; |
1323 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1324 | - $context['activation_numbers'][$row['is_activated']] = $row['total_members']; |
|
1362 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1363 | + $context['activation_numbers'][$row['is_activated']] = $row['total_members']; |
|
1364 | + } |
|
1325 | 1365 | $smcFunc['db_free_result']($request); |
1326 | 1366 | |
1327 | 1367 | foreach ($context['activation_numbers'] as $activation_type => $total_members) |
1328 | 1368 | { |
1329 | - if (in_array($activation_type, array(0, 2))) |
|
1330 | - $context['awaiting_activation'] += $total_members; |
|
1331 | - elseif (in_array($activation_type, array(3, 4, 5))) |
|
1332 | - $context['awaiting_approval'] += $total_members; |
|
1369 | + if (in_array($activation_type, array(0, 2))) { |
|
1370 | + $context['awaiting_activation'] += $total_members; |
|
1371 | + } elseif (in_array($activation_type, array(3, 4, 5))) { |
|
1372 | + $context['awaiting_approval'] += $total_members; |
|
1373 | + } |
|
1333 | 1374 | } |
1334 | 1375 | |
1335 | 1376 | } |