@@ -180,7 +180,7 @@ |
||
180 | 180 | * |
181 | 181 | * @access public |
182 | 182 | * @param string $dir A valid path |
183 | - * @return boolean If this was successful or not. |
|
183 | + * @return boolean|null If this was successful or not. |
|
184 | 184 | */ |
185 | 185 | public function setCachedir($dir = null) |
186 | 186 | { |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 3 |
12 | 12 | */ |
13 | 13 | |
14 | -if (!defined('SMF')) |
|
14 | +if (!defined('SMF')) { |
|
15 | 15 | die('Hacking attempt...'); |
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * Our Cache API class |
@@ -43,8 +44,9 @@ discard block |
||
43 | 44 | { |
44 | 45 | $supported = is_writable($this->cachedir); |
45 | 46 | |
46 | - if ($test) |
|
47 | - return $supported; |
|
47 | + if ($test) { |
|
48 | + return $supported; |
|
49 | + } |
|
48 | 50 | return parent::isSupported() && $supported; |
49 | 51 | } |
50 | 52 | |
@@ -61,11 +63,13 @@ discard block |
||
61 | 63 | { |
62 | 64 | // Work around Zend's opcode caching (PHP 5.5+), they would cache older files for a couple of seconds |
63 | 65 | // causing newer files to take effect a while later. |
64 | - if (function_exists('opcache_invalidate')) |
|
65 | - opcache_invalidate($cachedir . '/data_' . $key . '.php', true); |
|
66 | + if (function_exists('opcache_invalidate')) { |
|
67 | + opcache_invalidate($cachedir . '/data_' . $key . '.php', true); |
|
68 | + } |
|
66 | 69 | |
67 | - if (function_exists('apc_delete_file')) |
|
68 | - @apc_delete_file($cachedir . '/data_' . $key . '.php'); |
|
70 | + if (function_exists('apc_delete_file')) { |
|
71 | + @apc_delete_file($cachedir . '/data_' . $key . '.php'); |
|
72 | + } |
|
69 | 73 | |
70 | 74 | // php will cache file_exists et all, we can't 100% depend on its results so proceed with caution |
71 | 75 | @include($cachedir . '/data_' . $key . '.php'); |
@@ -89,16 +93,18 @@ discard block |
||
89 | 93 | |
90 | 94 | // Work around Zend's opcode caching (PHP 5.5+), they would cache older files for a couple of seconds |
91 | 95 | // causing newer files to take effect a while later. |
92 | - if (function_exists('opcache_invalidate')) |
|
93 | - opcache_invalidate($cachedir . '/data_' . $key . '.php', true); |
|
96 | + if (function_exists('opcache_invalidate')) { |
|
97 | + opcache_invalidate($cachedir . '/data_' . $key . '.php', true); |
|
98 | + } |
|
94 | 99 | |
95 | - if (function_exists('apc_delete_file')) |
|
96 | - @apc_delete_file($cachedir . '/data_' . $key . '.php'); |
|
100 | + if (function_exists('apc_delete_file')) { |
|
101 | + @apc_delete_file($cachedir . '/data_' . $key . '.php'); |
|
102 | + } |
|
97 | 103 | |
98 | 104 | // Otherwise custom cache? |
99 | - if ($value === null) |
|
100 | - @unlink($cachedir . '/data_' . $key . '.php'); |
|
101 | - else |
|
105 | + if ($value === null) { |
|
106 | + @unlink($cachedir . '/data_' . $key . '.php'); |
|
107 | + } else |
|
102 | 108 | { |
103 | 109 | $cache_data = '<' . '?' . 'php if (!defined(\'SMF\')) die; if (' . (time() + $ttl) . ' < time()) $expired = true; else{$expired = false; $value = \'' . addcslashes($value, '\\\'') . '\';}' . '?' . '>'; |
104 | 110 | |
@@ -109,9 +115,9 @@ discard block |
||
109 | 115 | { |
110 | 116 | @unlink($cachedir . '/data_' . $key . '.php'); |
111 | 117 | return false; |
118 | + } else { |
|
119 | + return true; |
|
112 | 120 | } |
113 | - else |
|
114 | - return true; |
|
115 | 121 | } |
116 | 122 | } |
117 | 123 | |
@@ -123,15 +129,17 @@ discard block |
||
123 | 129 | $cachedir = $this->cachedir; |
124 | 130 | |
125 | 131 | // No directory = no game. |
126 | - if (!is_dir($cachedir)) |
|
127 | - return; |
|
132 | + if (!is_dir($cachedir)) { |
|
133 | + return; |
|
134 | + } |
|
128 | 135 | |
129 | 136 | // Remove the files in SMF's own disk cache, if any |
130 | 137 | $dh = opendir($cachedir); |
131 | 138 | while ($file = readdir($dh)) |
132 | 139 | { |
133 | - if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type)) |
|
134 | - @unlink($cachedir . '/' . $file); |
|
140 | + if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type)) { |
|
141 | + @unlink($cachedir . '/' . $file); |
|
142 | + } |
|
135 | 143 | } |
136 | 144 | closedir($dh); |
137 | 145 | |
@@ -165,8 +173,9 @@ discard block |
||
165 | 173 | $config_vars[] = $txt['cache_smf_settings']; |
166 | 174 | $config_vars[] = array('cachedir', $txt['cachedir'], 'file', 'text', 36, 'cache_cachedir'); |
167 | 175 | |
168 | - if (!isset($context['settings_post_javascript'])) |
|
169 | - $context['settings_post_javascript'] = ''; |
|
176 | + if (!isset($context['settings_post_javascript'])) { |
|
177 | + $context['settings_post_javascript'] = ''; |
|
178 | + } |
|
170 | 179 | |
171 | 180 | $context['settings_post_javascript'] .= ' |
172 | 181 | $("#cache_accelerator").change(function (e) { |
@@ -187,10 +196,11 @@ discard block |
||
187 | 196 | global $cachedir; |
188 | 197 | |
189 | 198 | // If its invalid, use SMF's. |
190 | - if (is_null($dir) || !is_writable($dir)) |
|
191 | - $this->cachedir = $cachedir; |
|
192 | - else |
|
193 | - $this->cachedir = $dir; |
|
199 | + if (is_null($dir) || !is_writable($dir)) { |
|
200 | + $this->cachedir = $cachedir; |
|
201 | + } else { |
|
202 | + $this->cachedir = $dir; |
|
203 | + } |
|
194 | 204 | } |
195 | 205 | |
196 | 206 | /** |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 3 |
12 | 12 | */ |
13 | 13 | |
14 | -if (!defined('SMF')) |
|
14 | +if (!defined('SMF')) { |
|
15 | 15 | die('Hacking attempt...'); |
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * Our Cache API class |
@@ -46,8 +47,9 @@ discard block |
||
46 | 47 | |
47 | 48 | $supported = function_exists('xcache_get') && function_exists('xcache_set') && ini_get('xcache.var_size') > 0; |
48 | 49 | |
49 | - if ($test) |
|
50 | - return $supported; |
|
50 | + if ($test) { |
|
51 | + return $supported; |
|
52 | + } |
|
51 | 53 | return parent::isSupported() && $supported; |
52 | 54 | } |
53 | 55 | |
@@ -68,10 +70,11 @@ discard block |
||
68 | 70 | { |
69 | 71 | $key = $this->prefix . strtr($key, ':/', '-_'); |
70 | 72 | |
71 | - if ($value === null) |
|
72 | - return xcache_unset($key); |
|
73 | - else |
|
74 | - return xcache_set($key, $value, $ttl); |
|
73 | + if ($value === null) { |
|
74 | + return xcache_unset($key); |
|
75 | + } else { |
|
76 | + return xcache_set($key, $value, $ttl); |
|
77 | + } |
|
75 | 78 | } |
76 | 79 | |
77 | 80 | /** |
@@ -90,10 +93,12 @@ discard block |
||
90 | 93 | } |
91 | 94 | |
92 | 95 | // if passed a type, clear that type out |
93 | - if ($type === '' || $type === 'user') |
|
94 | - xcache_clear_cache(XC_TYPE_VAR, 0); |
|
95 | - if ($type === '' || $type === 'data') |
|
96 | - xcache_clear_cache(XC_TYPE_PHP, 0); |
|
96 | + if ($type === '' || $type === 'user') { |
|
97 | + xcache_clear_cache(XC_TYPE_VAR, 0); |
|
98 | + } |
|
99 | + if ($type === '' || $type === 'data') { |
|
100 | + xcache_clear_cache(XC_TYPE_PHP, 0); |
|
101 | + } |
|
97 | 102 | |
98 | 103 | $this->invalidateCache(); |
99 | 104 | return true; |
@@ -112,8 +117,9 @@ discard block |
||
112 | 117 | // While we could md5 this when saving, this could be tricky to be sure it doesn't get corrupted on additional saves. |
113 | 118 | $config_vars[] = array('xcache_adminpass', $txt['cache_xcache_adminpass'], 'db', 'text', 0); |
114 | 119 | |
115 | - if (!isset($context['settings_post_javascript'])) |
|
116 | - $context['settings_post_javascript'] = ''; |
|
120 | + if (!isset($context['settings_post_javascript'])) { |
|
121 | + $context['settings_post_javascript'] = ''; |
|
122 | + } |
|
117 | 123 | |
118 | 124 | $context['settings_post_javascript'] .= ' |
119 | 125 | $("#cache_accelerator").change(function (e) { |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 3 |
12 | 12 | */ |
13 | 13 | |
14 | -if (!defined('SMF')) |
|
14 | +if (!defined('SMF')) { |
|
15 | 15 | die('Hacking attempt...'); |
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * Our Cache API class |
@@ -29,8 +30,9 @@ discard block |
||
29 | 30 | |
30 | 31 | $supported = function_exists('zend_shm_cache_fetch') || function_exists('output_cache_get'); |
31 | 32 | |
32 | - if ($test) |
|
33 | - return $supported; |
|
33 | + if ($test) { |
|
34 | + return $supported; |
|
35 | + } |
|
34 | 36 | return parent::isSupported() && $supported; |
35 | 37 | } |
36 | 38 | |
@@ -42,10 +44,11 @@ discard block |
||
42 | 44 | $key = $this->prefix . strtr($key, ':/', '-_'); |
43 | 45 | |
44 | 46 | // Zend's pricey stuff. |
45 | - if (function_exists('zend_shm_cache_fetch')) |
|
46 | - return zend_shm_cache_fetch('SMF::' . $key); |
|
47 | - elseif (function_exists('output_cache_get')) |
|
48 | - return output_cache_get($key, $ttl); |
|
47 | + if (function_exists('zend_shm_cache_fetch')) { |
|
48 | + return zend_shm_cache_fetch('SMF::' . $key); |
|
49 | + } elseif (function_exists('output_cache_get')) { |
|
50 | + return output_cache_get($key, $ttl); |
|
51 | + } |
|
49 | 52 | } |
50 | 53 | |
51 | 54 | /** |
@@ -55,10 +58,11 @@ discard block |
||
55 | 58 | { |
56 | 59 | $key = $this->prefix . strtr($key, ':/', '-_'); |
57 | 60 | |
58 | - if (function_exists('zend_shm_cache_store')) |
|
59 | - return zend_shm_cache_store('SMF::' . $key, $value, $ttl); |
|
60 | - elseif (function_exists('output_cache_put')) |
|
61 | - return output_cache_put($key, $value); |
|
61 | + if (function_exists('zend_shm_cache_store')) { |
|
62 | + return zend_shm_cache_store('SMF::' . $key, $value, $ttl); |
|
63 | + } elseif (function_exists('output_cache_put')) { |
|
64 | + return output_cache_put($key, $value); |
|
65 | + } |
|
62 | 66 | } |
63 | 67 | |
64 | 68 | /** |
@@ -61,7 +61,7 @@ |
||
61 | 61 | $server = trim($servers[array_rand($servers)]); |
62 | 62 | |
63 | 63 | // Normal host names do not contain slashes, while e.g. unix sockets do. Assume alternative transport pipe with port 0. |
64 | - if (strpos($server,'/') !== false) |
|
64 | + if (strpos($server, '/') !== false) |
|
65 | 65 | $host = $server; |
66 | 66 | else |
67 | 67 | { |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 3 |
12 | 12 | */ |
13 | 13 | |
14 | -if (!defined('SMF')) |
|
14 | +if (!defined('SMF')) { |
|
15 | 15 | die('Hacking attempt...'); |
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * Our Cache API class |
@@ -34,8 +35,9 @@ discard block |
||
34 | 35 | |
35 | 36 | $supported = class_exists('memcache'); |
36 | 37 | |
37 | - if ($test) |
|
38 | - return $supported; |
|
38 | + if ($test) { |
|
39 | + return $supported; |
|
40 | + } |
|
39 | 41 | return parent::isSupported() && $supported && !empty($cache_memcached); |
40 | 42 | } |
41 | 43 | |
@@ -61,9 +63,9 @@ discard block |
||
61 | 63 | $server = trim($servers[array_rand($servers)]); |
62 | 64 | |
63 | 65 | // Normal host names do not contain slashes, while e.g. unix sockets do. Assume alternative transport pipe with port 0. |
64 | - if (strpos($server,'/') !== false) |
|
65 | - $host = $server; |
|
66 | - else |
|
66 | + if (strpos($server,'/') !== false) { |
|
67 | + $host = $server; |
|
68 | + } else |
|
67 | 69 | { |
68 | 70 | $server = explode(':', $server); |
69 | 71 | $host = $server[0]; |
@@ -71,10 +73,11 @@ discard block |
||
71 | 73 | } |
72 | 74 | |
73 | 75 | // Don't wait too long: yes, we want the server, but we might be able to run the query faster! |
74 | - if (empty($db_persist)) |
|
75 | - $connected = $this->memcache->connect($host, $port); |
|
76 | - else |
|
77 | - $connected = $this->memcache->pconnect($host, $port); |
|
76 | + if (empty($db_persist)) { |
|
77 | + $connected = $this->memcache->connect($host, $port); |
|
78 | + } else { |
|
79 | + $connected = $this->memcache->pconnect($host, $port); |
|
80 | + } |
|
78 | 81 | } |
79 | 82 | |
80 | 83 | return $connected; |
@@ -90,8 +93,9 @@ discard block |
||
90 | 93 | $value = $this->memcache->get($key); |
91 | 94 | |
92 | 95 | // $value should return either data or false (from failure, key not found or empty array). |
93 | - if ($value === false) |
|
94 | - return null; |
|
96 | + if ($value === false) { |
|
97 | + return null; |
|
98 | + } |
|
95 | 99 | return $value; |
96 | 100 | } |
97 | 101 | |
@@ -132,8 +136,9 @@ discard block |
||
132 | 136 | $config_vars[] = $txt['cache_memcache_settings']; |
133 | 137 | $config_vars[] = array('cache_memcached', $txt['cache_memcache_servers'], 'file', 'text', 0, 'cache_memcached', 'postinput' => '<br /><div class="smalltext"><em>' . $txt['cache_memcache_servers_subtext'] . '</em></div>'); |
134 | 138 | |
135 | - if (!isset($context['settings_post_javascript'])) |
|
136 | - $context['settings_post_javascript'] = ''; |
|
139 | + if (!isset($context['settings_post_javascript'])) { |
|
140 | + $context['settings_post_javascript'] = ''; |
|
141 | + } |
|
137 | 142 | |
138 | 143 | $context['settings_post_javascript'] .= ' |
139 | 144 | $("#cache_accelerator").change(function (e) { |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
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 | * Update some basic statistics. |
@@ -122,10 +123,11 @@ discard block |
||
122 | 123 | $smcFunc['db_free_result']($result); |
123 | 124 | |
124 | 125 | // Add this to the number of unapproved members |
125 | - if (!empty($changes['unapprovedMembers'])) |
|
126 | - $changes['unapprovedMembers'] += $coppa_approvals; |
|
127 | - else |
|
128 | - $changes['unapprovedMembers'] = $coppa_approvals; |
|
126 | + if (!empty($changes['unapprovedMembers'])) { |
|
127 | + $changes['unapprovedMembers'] += $coppa_approvals; |
|
128 | + } else { |
|
129 | + $changes['unapprovedMembers'] = $coppa_approvals; |
|
130 | + } |
|
129 | 131 | } |
130 | 132 | } |
131 | 133 | } |
@@ -133,9 +135,9 @@ discard block |
||
133 | 135 | break; |
134 | 136 | |
135 | 137 | case 'message': |
136 | - if ($parameter1 === true && $parameter2 !== null) |
|
137 | - updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
138 | - else |
|
138 | + if ($parameter1 === true && $parameter2 !== null) { |
|
139 | + updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
140 | + } else |
|
139 | 141 | { |
140 | 142 | // SUM and MAX on a smaller table is better for InnoDB tables. |
141 | 143 | $result = $smcFunc['db_query']('', ' |
@@ -175,23 +177,25 @@ discard block |
||
175 | 177 | $parameter2 = text2words($parameter2); |
176 | 178 | |
177 | 179 | $inserts = array(); |
178 | - foreach ($parameter2 as $word) |
|
179 | - $inserts[] = array($word, $parameter1); |
|
180 | + foreach ($parameter2 as $word) { |
|
181 | + $inserts[] = array($word, $parameter1); |
|
182 | + } |
|
180 | 183 | |
181 | - if (!empty($inserts)) |
|
182 | - $smcFunc['db_insert']('ignore', |
|
184 | + if (!empty($inserts)) { |
|
185 | + $smcFunc['db_insert']('ignore', |
|
183 | 186 | '{db_prefix}log_search_subjects', |
184 | 187 | array('word' => 'string', 'id_topic' => 'int'), |
185 | 188 | $inserts, |
186 | 189 | array('word', 'id_topic') |
187 | 190 | ); |
191 | + } |
|
188 | 192 | } |
189 | 193 | break; |
190 | 194 | |
191 | 195 | case 'topic': |
192 | - if ($parameter1 === true) |
|
193 | - updateSettings(array('totalTopics' => true), true); |
|
194 | - else |
|
196 | + if ($parameter1 === true) { |
|
197 | + updateSettings(array('totalTopics' => true), true); |
|
198 | + } else |
|
195 | 199 | { |
196 | 200 | // Get the number of topics - a SUM is better for InnoDB tables. |
197 | 201 | // We also ignore the recycle bin here because there will probably be a bunch of one-post topics there. |
@@ -212,8 +216,9 @@ discard block |
||
212 | 216 | |
213 | 217 | case 'postgroups': |
214 | 218 | // Parameter two is the updated columns: we should check to see if we base groups off any of these. |
215 | - if ($parameter2 !== null && !in_array('posts', $parameter2)) |
|
216 | - return; |
|
219 | + if ($parameter2 !== null && !in_array('posts', $parameter2)) { |
|
220 | + return; |
|
221 | + } |
|
217 | 222 | |
218 | 223 | $postgroups = cache_get_data('updateStats:postgroups', 360); |
219 | 224 | if ($postgroups == null || $parameter1 == null) |
@@ -228,8 +233,9 @@ discard block |
||
228 | 233 | ) |
229 | 234 | ); |
230 | 235 | $postgroups = array(); |
231 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
232 | - $postgroups[$row['id_group']] = $row['min_posts']; |
|
236 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
237 | + $postgroups[$row['id_group']] = $row['min_posts']; |
|
238 | + } |
|
233 | 239 | $smcFunc['db_free_result']($request); |
234 | 240 | |
235 | 241 | // Sort them this way because if it's done with MySQL it causes a filesort :(. |
@@ -239,8 +245,9 @@ discard block |
||
239 | 245 | } |
240 | 246 | |
241 | 247 | // Oh great, they've screwed their post groups. |
242 | - if (empty($postgroups)) |
|
243 | - return; |
|
248 | + if (empty($postgroups)) { |
|
249 | + return; |
|
250 | + } |
|
244 | 251 | |
245 | 252 | // Set all membergroups from most posts to least posts. |
246 | 253 | $conditions = ''; |
@@ -298,10 +305,9 @@ discard block |
||
298 | 305 | { |
299 | 306 | $condition = 'id_member IN ({array_int:members})'; |
300 | 307 | $parameters['members'] = $members; |
301 | - } |
|
302 | - elseif ($members === null) |
|
303 | - $condition = '1=1'; |
|
304 | - else |
|
308 | + } elseif ($members === null) { |
|
309 | + $condition = '1=1'; |
|
310 | + } else |
|
305 | 311 | { |
306 | 312 | $condition = 'id_member = {int:member}'; |
307 | 313 | $parameters['member'] = $members; |
@@ -341,9 +347,9 @@ discard block |
||
341 | 347 | if (count($vars_to_integrate) != 0) |
342 | 348 | { |
343 | 349 | // Fetch a list of member_names if necessary |
344 | - if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) |
|
345 | - $member_names = array($user_info['username']); |
|
346 | - else |
|
350 | + if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) { |
|
351 | + $member_names = array($user_info['username']); |
|
352 | + } else |
|
347 | 353 | { |
348 | 354 | $member_names = array(); |
349 | 355 | $request = $smcFunc['db_query']('', ' |
@@ -352,14 +358,16 @@ discard block |
||
352 | 358 | WHERE ' . $condition, |
353 | 359 | $parameters |
354 | 360 | ); |
355 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
356 | - $member_names[] = $row['member_name']; |
|
361 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
362 | + $member_names[] = $row['member_name']; |
|
363 | + } |
|
357 | 364 | $smcFunc['db_free_result']($request); |
358 | 365 | } |
359 | 366 | |
360 | - if (!empty($member_names)) |
|
361 | - foreach ($vars_to_integrate as $var) |
|
367 | + if (!empty($member_names)) { |
|
368 | + foreach ($vars_to_integrate as $var) |
|
362 | 369 | call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats)); |
370 | + } |
|
363 | 371 | } |
364 | 372 | } |
365 | 373 | |
@@ -367,16 +375,17 @@ discard block |
||
367 | 375 | foreach ($data as $var => $val) |
368 | 376 | { |
369 | 377 | $type = 'string'; |
370 | - if (in_array($var, $knownInts)) |
|
371 | - $type = 'int'; |
|
372 | - elseif (in_array($var, $knownFloats)) |
|
373 | - $type = 'float'; |
|
374 | - elseif ($var == 'birthdate') |
|
375 | - $type = 'date'; |
|
376 | - elseif ($var == 'member_ip') |
|
377 | - $type = 'inet'; |
|
378 | - elseif ($var == 'member_ip2') |
|
379 | - $type = 'inet'; |
|
378 | + if (in_array($var, $knownInts)) { |
|
379 | + $type = 'int'; |
|
380 | + } elseif (in_array($var, $knownFloats)) { |
|
381 | + $type = 'float'; |
|
382 | + } elseif ($var == 'birthdate') { |
|
383 | + $type = 'date'; |
|
384 | + } elseif ($var == 'member_ip') { |
|
385 | + $type = 'inet'; |
|
386 | + } elseif ($var == 'member_ip2') { |
|
387 | + $type = 'inet'; |
|
388 | + } |
|
380 | 389 | |
381 | 390 | // Doing an increment? |
382 | 391 | if ($type == 'int' && ($val === '+' || $val === '-')) |
@@ -390,8 +399,9 @@ discard block |
||
390 | 399 | { |
391 | 400 | if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match)) |
392 | 401 | { |
393 | - if ($match[1] != '+ ') |
|
394 | - $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
402 | + if ($match[1] != '+ ') { |
|
403 | + $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
404 | + } |
|
395 | 405 | $type = 'raw'; |
396 | 406 | } |
397 | 407 | } |
@@ -412,8 +422,9 @@ discard block |
||
412 | 422 | // Clear any caching? |
413 | 423 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members)) |
414 | 424 | { |
415 | - if (!is_array($members)) |
|
416 | - $members = array($members); |
|
425 | + if (!is_array($members)) { |
|
426 | + $members = array($members); |
|
427 | + } |
|
417 | 428 | |
418 | 429 | foreach ($members as $member) |
419 | 430 | { |
@@ -446,29 +457,32 @@ discard block |
||
446 | 457 | { |
447 | 458 | global $modSettings, $smcFunc; |
448 | 459 | |
449 | - if (empty($changeArray) || !is_array($changeArray)) |
|
450 | - return; |
|
460 | + if (empty($changeArray) || !is_array($changeArray)) { |
|
461 | + return; |
|
462 | + } |
|
451 | 463 | |
452 | 464 | $toRemove = array(); |
453 | 465 | |
454 | 466 | // Go check if there is any setting to be removed. |
455 | - foreach ($changeArray as $k => $v) |
|
456 | - if ($v === null) |
|
467 | + foreach ($changeArray as $k => $v) { |
|
468 | + if ($v === null) |
|
457 | 469 | { |
458 | 470 | // Found some, remove them from the original array and add them to ours. |
459 | 471 | unset($changeArray[$k]); |
472 | + } |
|
460 | 473 | $toRemove[] = $k; |
461 | 474 | } |
462 | 475 | |
463 | 476 | // Proceed with the deletion. |
464 | - if (!empty($toRemove)) |
|
465 | - $smcFunc['db_query']('', ' |
|
477 | + if (!empty($toRemove)) { |
|
478 | + $smcFunc['db_query']('', ' |
|
466 | 479 | DELETE FROM {db_prefix}settings |
467 | 480 | WHERE variable IN ({array_string:remove})', |
468 | 481 | array( |
469 | 482 | 'remove' => $toRemove, |
470 | 483 | ) |
471 | 484 | ); |
485 | + } |
|
472 | 486 | |
473 | 487 | // In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs. |
474 | 488 | if ($update) |
@@ -497,19 +511,22 @@ discard block |
||
497 | 511 | foreach ($changeArray as $variable => $value) |
498 | 512 | { |
499 | 513 | // Don't bother if it's already like that ;). |
500 | - if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) |
|
501 | - continue; |
|
514 | + if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) { |
|
515 | + continue; |
|
516 | + } |
|
502 | 517 | // If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it. |
503 | - elseif (!isset($modSettings[$variable]) && empty($value)) |
|
504 | - continue; |
|
518 | + elseif (!isset($modSettings[$variable]) && empty($value)) { |
|
519 | + continue; |
|
520 | + } |
|
505 | 521 | |
506 | 522 | $replaceArray[] = array($variable, $value); |
507 | 523 | |
508 | 524 | $modSettings[$variable] = $value; |
509 | 525 | } |
510 | 526 | |
511 | - if (empty($replaceArray)) |
|
512 | - return; |
|
527 | + if (empty($replaceArray)) { |
|
528 | + return; |
|
529 | + } |
|
513 | 530 | |
514 | 531 | $smcFunc['db_insert']('replace', |
515 | 532 | '{db_prefix}settings', |
@@ -555,14 +572,17 @@ discard block |
||
555 | 572 | $start_invalid = $start < 0; |
556 | 573 | |
557 | 574 | // Make sure $start is a proper variable - not less than 0. |
558 | - if ($start_invalid) |
|
559 | - $start = 0; |
|
575 | + if ($start_invalid) { |
|
576 | + $start = 0; |
|
577 | + } |
|
560 | 578 | // Not greater than the upper bound. |
561 | - elseif ($start >= $max_value) |
|
562 | - $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
579 | + elseif ($start >= $max_value) { |
|
580 | + $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
581 | + } |
|
563 | 582 | // And it has to be a multiple of $num_per_page! |
564 | - else |
|
565 | - $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
583 | + else { |
|
584 | + $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
585 | + } |
|
566 | 586 | |
567 | 587 | $context['current_page'] = $start / $num_per_page; |
568 | 588 | |
@@ -592,77 +612,87 @@ discard block |
||
592 | 612 | |
593 | 613 | // Show all the pages. |
594 | 614 | $display_page = 1; |
595 | - for ($counter = 0; $counter < $max_value; $counter += $num_per_page) |
|
596 | - $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
615 | + for ($counter = 0; $counter < $max_value; $counter += $num_per_page) { |
|
616 | + $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
617 | + } |
|
597 | 618 | |
598 | 619 | // Show the right arrow. |
599 | 620 | $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page); |
600 | - if ($start != $counter - $max_value && !$start_invalid) |
|
601 | - $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
602 | - } |
|
603 | - else |
|
621 | + if ($start != $counter - $max_value && !$start_invalid) { |
|
622 | + $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
623 | + } |
|
624 | + } else |
|
604 | 625 | { |
605 | 626 | // If they didn't enter an odd value, pretend they did. |
606 | 627 | $PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2; |
607 | 628 | |
608 | 629 | // Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page) |
609 | - if (!empty($start) && $show_prevnext) |
|
610 | - $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
611 | - else |
|
612 | - $pageindex .= ''; |
|
630 | + if (!empty($start) && $show_prevnext) { |
|
631 | + $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
632 | + } else { |
|
633 | + $pageindex .= ''; |
|
634 | + } |
|
613 | 635 | |
614 | 636 | // Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15) |
615 | - if ($start > $num_per_page * $PageContiguous) |
|
616 | - $pageindex .= sprintf($base_link, 0, '1'); |
|
637 | + if ($start > $num_per_page * $PageContiguous) { |
|
638 | + $pageindex .= sprintf($base_link, 0, '1'); |
|
639 | + } |
|
617 | 640 | |
618 | 641 | // Show the ... after the first page. (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page) |
619 | - if ($start > $num_per_page * ($PageContiguous + 1)) |
|
620 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
642 | + if ($start > $num_per_page * ($PageContiguous + 1)) { |
|
643 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
621 | 644 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
622 | 645 | '{FIRST_PAGE}' => $num_per_page, |
623 | 646 | '{LAST_PAGE}' => $start - $num_per_page * $PageContiguous, |
624 | 647 | '{PER_PAGE}' => $num_per_page, |
625 | 648 | )); |
649 | + } |
|
626 | 650 | |
627 | 651 | // Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page) |
628 | - for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) |
|
629 | - if ($start >= $num_per_page * $nCont) |
|
652 | + for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) { |
|
653 | + if ($start >= $num_per_page * $nCont) |
|
630 | 654 | { |
631 | 655 | $tmpStart = $start - $num_per_page * $nCont; |
656 | + } |
|
632 | 657 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
633 | 658 | } |
634 | 659 | |
635 | 660 | // Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page) |
636 | - if (!$start_invalid) |
|
637 | - $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
638 | - else |
|
639 | - $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
661 | + if (!$start_invalid) { |
|
662 | + $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
663 | + } else { |
|
664 | + $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
665 | + } |
|
640 | 666 | |
641 | 667 | // Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page) |
642 | 668 | $tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page; |
643 | - for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) |
|
644 | - if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
669 | + for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) { |
|
670 | + if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
645 | 671 | { |
646 | 672 | $tmpStart = $start + $num_per_page * $nCont; |
673 | + } |
|
647 | 674 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
648 | 675 | } |
649 | 676 | |
650 | 677 | // Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page) |
651 | - if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) |
|
652 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
678 | + if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) { |
|
679 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
653 | 680 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
654 | 681 | '{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1), |
655 | 682 | '{LAST_PAGE}' => $tmpMaxPages, |
656 | 683 | '{PER_PAGE}' => $num_per_page, |
657 | 684 | )); |
685 | + } |
|
658 | 686 | |
659 | 687 | // Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15< next page) |
660 | - if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) |
|
661 | - $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
688 | + if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) { |
|
689 | + $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
690 | + } |
|
662 | 691 | |
663 | 692 | // Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<) |
664 | - if ($start != $tmpMaxPages && $show_prevnext) |
|
665 | - $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
693 | + if ($start != $tmpMaxPages && $show_prevnext) { |
|
694 | + $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
695 | + } |
|
666 | 696 | } |
667 | 697 | $pageindex .= $settings['page_index']['extra_after']; |
668 | 698 | |
@@ -688,8 +718,9 @@ discard block |
||
688 | 718 | if ($decimal_separator === null) |
689 | 719 | { |
690 | 720 | // Not set for whatever reason? |
691 | - if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) |
|
692 | - return $number; |
|
721 | + if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) { |
|
722 | + return $number; |
|
723 | + } |
|
693 | 724 | |
694 | 725 | // Cache these each load... |
695 | 726 | $thousands_separator = $matches[1]; |
@@ -721,17 +752,20 @@ discard block |
||
721 | 752 | static $non_twelve_hour; |
722 | 753 | |
723 | 754 | // Offset the time. |
724 | - if (!$offset_type) |
|
725 | - $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
755 | + if (!$offset_type) { |
|
756 | + $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
757 | + } |
|
726 | 758 | // Just the forum offset? |
727 | - elseif ($offset_type == 'forum') |
|
728 | - $time = $log_time + $modSettings['time_offset'] * 3600; |
|
729 | - else |
|
730 | - $time = $log_time; |
|
759 | + elseif ($offset_type == 'forum') { |
|
760 | + $time = $log_time + $modSettings['time_offset'] * 3600; |
|
761 | + } else { |
|
762 | + $time = $log_time; |
|
763 | + } |
|
731 | 764 | |
732 | 765 | // We can't have a negative date (on Windows, at least.) |
733 | - if ($log_time < 0) |
|
734 | - $log_time = 0; |
|
766 | + if ($log_time < 0) { |
|
767 | + $log_time = 0; |
|
768 | + } |
|
735 | 769 | |
736 | 770 | // Today and Yesterday? |
737 | 771 | if ($modSettings['todayMod'] >= 1 && $show_today === true) |
@@ -748,46 +782,53 @@ discard block |
||
748 | 782 | { |
749 | 783 | $h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l'; |
750 | 784 | $today_fmt = $h . ':%M' . $s . ' %p'; |
785 | + } else { |
|
786 | + $today_fmt = '%H:%M' . $s; |
|
751 | 787 | } |
752 | - else |
|
753 | - $today_fmt = '%H:%M' . $s; |
|
754 | 788 | |
755 | 789 | // Same day of the year, same year.... Today! |
756 | - if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) |
|
757 | - return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
790 | + if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) { |
|
791 | + return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
792 | + } |
|
758 | 793 | |
759 | 794 | // Day-of-year is one less and same year, or it's the first of the year and that's the last of the year... |
760 | - if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) |
|
761 | - return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
795 | + if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) { |
|
796 | + return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
797 | + } |
|
762 | 798 | } |
763 | 799 | |
764 | 800 | $str = !is_bool($show_today) ? $show_today : $user_info['time_format']; |
765 | 801 | |
766 | 802 | if (setlocale(LC_TIME, $txt['lang_locale'])) |
767 | 803 | { |
768 | - if (!isset($non_twelve_hour)) |
|
769 | - $non_twelve_hour = trim(strftime('%p')) === ''; |
|
770 | - if ($non_twelve_hour && strpos($str, '%p') !== false) |
|
771 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
804 | + if (!isset($non_twelve_hour)) { |
|
805 | + $non_twelve_hour = trim(strftime('%p')) === ''; |
|
806 | + } |
|
807 | + if ($non_twelve_hour && strpos($str, '%p') !== false) { |
|
808 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
809 | + } |
|
772 | 810 | |
773 | - foreach (array('%a', '%A', '%b', '%B') as $token) |
|
774 | - if (strpos($str, $token) !== false) |
|
811 | + foreach (array('%a', '%A', '%b', '%B') as $token) { |
|
812 | + if (strpos($str, $token) !== false) |
|
775 | 813 | $str = str_replace($token, strftime($token, $time), $str); |
776 | - } |
|
777 | - else |
|
814 | + } |
|
815 | + } else |
|
778 | 816 | { |
779 | 817 | // Do-it-yourself time localization. Fun. |
780 | - foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) |
|
781 | - if (strpos($str, $token) !== false) |
|
818 | + foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) { |
|
819 | + if (strpos($str, $token) !== false) |
|
782 | 820 | $str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str); |
821 | + } |
|
783 | 822 | |
784 | - if (strpos($str, '%p') !== false) |
|
785 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
823 | + if (strpos($str, '%p') !== false) { |
|
824 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
825 | + } |
|
786 | 826 | } |
787 | 827 | |
788 | 828 | // Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that. |
789 | - if ($context['server']['is_windows'] && strpos($str, '%e') !== false) |
|
790 | - $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
829 | + if ($context['server']['is_windows'] && strpos($str, '%e') !== false) { |
|
830 | + $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
831 | + } |
|
791 | 832 | |
792 | 833 | // Format any other characters.. |
793 | 834 | return strftime($str, $time); |
@@ -809,16 +850,19 @@ discard block |
||
809 | 850 | static $translation = array(); |
810 | 851 | |
811 | 852 | // Determine the character set... Default to UTF-8 |
812 | - if (empty($context['character_set'])) |
|
813 | - $charset = 'UTF-8'; |
|
853 | + if (empty($context['character_set'])) { |
|
854 | + $charset = 'UTF-8'; |
|
855 | + } |
|
814 | 856 | // Use ISO-8859-1 in place of non-supported ISO-8859 charsets... |
815 | - elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) |
|
816 | - $charset = 'ISO-8859-1'; |
|
817 | - else |
|
818 | - $charset = $context['character_set']; |
|
857 | + elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) { |
|
858 | + $charset = 'ISO-8859-1'; |
|
859 | + } else { |
|
860 | + $charset = $context['character_set']; |
|
861 | + } |
|
819 | 862 | |
820 | - if (empty($translation)) |
|
821 | - $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
863 | + if (empty($translation)) { |
|
864 | + $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
865 | + } |
|
822 | 866 | |
823 | 867 | return strtr($string, $translation); |
824 | 868 | } |
@@ -840,8 +884,9 @@ discard block |
||
840 | 884 | global $smcFunc; |
841 | 885 | |
842 | 886 | // It was already short enough! |
843 | - if ($smcFunc['strlen']($subject) <= $len) |
|
844 | - return $subject; |
|
887 | + if ($smcFunc['strlen']($subject) <= $len) { |
|
888 | + return $subject; |
|
889 | + } |
|
845 | 890 | |
846 | 891 | // Shorten it by the length it was too long, and strip off junk from the end. |
847 | 892 | return $smcFunc['substr']($subject, 0, $len) . '...'; |
@@ -860,10 +905,11 @@ discard block |
||
860 | 905 | { |
861 | 906 | global $user_info, $modSettings; |
862 | 907 | |
863 | - if ($timestamp === null) |
|
864 | - $timestamp = time(); |
|
865 | - elseif ($timestamp == 0) |
|
866 | - return 0; |
|
908 | + if ($timestamp === null) { |
|
909 | + $timestamp = time(); |
|
910 | + } elseif ($timestamp == 0) { |
|
911 | + return 0; |
|
912 | + } |
|
867 | 913 | |
868 | 914 | return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600; |
869 | 915 | } |
@@ -892,8 +938,9 @@ discard block |
||
892 | 938 | $array[$i] = $array[$j]; |
893 | 939 | $array[$j] = $temp; |
894 | 940 | |
895 | - for ($i = 1; $p[$i] == 0; $i++) |
|
896 | - $p[$i] = 1; |
|
941 | + for ($i = 1; $p[$i] == 0; $i++) { |
|
942 | + $p[$i] = 1; |
|
943 | + } |
|
897 | 944 | |
898 | 945 | $orders[] = $array; |
899 | 946 | } |
@@ -925,12 +972,14 @@ discard block |
||
925 | 972 | static $disabled; |
926 | 973 | |
927 | 974 | // Don't waste cycles |
928 | - if ($message === '') |
|
929 | - return ''; |
|
975 | + if ($message === '') { |
|
976 | + return ''; |
|
977 | + } |
|
930 | 978 | |
931 | 979 | // Just in case it wasn't determined yet whether UTF-8 is enabled. |
932 | - if (!isset($context['utf8'])) |
|
933 | - $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
980 | + if (!isset($context['utf8'])) { |
|
981 | + $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
982 | + } |
|
934 | 983 | |
935 | 984 | // Clean up any cut/paste issues we may have |
936 | 985 | $message = sanitizeMSCutPaste($message); |
@@ -942,13 +991,15 @@ discard block |
||
942 | 991 | return $message; |
943 | 992 | } |
944 | 993 | |
945 | - if ($smileys !== null && ($smileys == '1' || $smileys == '0')) |
|
946 | - $smileys = (bool) $smileys; |
|
994 | + if ($smileys !== null && ($smileys == '1' || $smileys == '0')) { |
|
995 | + $smileys = (bool) $smileys; |
|
996 | + } |
|
947 | 997 | |
948 | 998 | if (empty($modSettings['enableBBC']) && $message !== false) |
949 | 999 | { |
950 | - if ($smileys === true) |
|
951 | - parsesmileys($message); |
|
1000 | + if ($smileys === true) { |
|
1001 | + parsesmileys($message); |
|
1002 | + } |
|
952 | 1003 | |
953 | 1004 | return $message; |
954 | 1005 | } |
@@ -961,8 +1012,9 @@ discard block |
||
961 | 1012 | } |
962 | 1013 | |
963 | 1014 | // Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker |
964 | - if (!empty($modSettings['autoLinkUrls'])) |
|
965 | - set_tld_regex(); |
|
1015 | + if (!empty($modSettings['autoLinkUrls'])) { |
|
1016 | + set_tld_regex(); |
|
1017 | + } |
|
966 | 1018 | |
967 | 1019 | // Allow mods access before entering the main parse_bbc loop |
968 | 1020 | call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
@@ -976,12 +1028,14 @@ discard block |
||
976 | 1028 | |
977 | 1029 | $temp = explode(',', strtolower($modSettings['disabledBBC'])); |
978 | 1030 | |
979 | - foreach ($temp as $tag) |
|
980 | - $disabled[trim($tag)] = true; |
|
1031 | + foreach ($temp as $tag) { |
|
1032 | + $disabled[trim($tag)] = true; |
|
1033 | + } |
|
981 | 1034 | } |
982 | 1035 | |
983 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
984 | - $disabled['flash'] = true; |
|
1036 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
1037 | + $disabled['flash'] = true; |
|
1038 | + } |
|
985 | 1039 | |
986 | 1040 | /* The following bbc are formatted as an array, with keys as follows: |
987 | 1041 | |
@@ -1102,8 +1156,9 @@ discard block |
||
1102 | 1156 | $returnContext = ''; |
1103 | 1157 | |
1104 | 1158 | // BBC or the entire attachments feature is disabled |
1105 | - if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) |
|
1106 | - return $data; |
|
1159 | + if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) { |
|
1160 | + return $data; |
|
1161 | + } |
|
1107 | 1162 | |
1108 | 1163 | // Save the attach ID. |
1109 | 1164 | $attachID = $data; |
@@ -1114,8 +1169,9 @@ discard block |
||
1114 | 1169 | $currentAttachment = parseAttachBBC($attachID); |
1115 | 1170 | |
1116 | 1171 | // parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do. |
1117 | - if (is_string($currentAttachment)) |
|
1118 | - return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
1172 | + if (is_string($currentAttachment)) { |
|
1173 | + return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
1174 | + } |
|
1119 | 1175 | |
1120 | 1176 | if (!empty($currentAttachment['is_image'])) |
1121 | 1177 | { |
@@ -1131,15 +1187,17 @@ discard block |
||
1131 | 1187 | $height = ' height="' . $currentAttachment['height'] . '"'; |
1132 | 1188 | } |
1133 | 1189 | |
1134 | - if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) |
|
1135 | - $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '" alt="' . $currentAttachment['name'] . '" id="thumb_'. $currentAttachment['id']. '"></a>'; |
|
1136 | - else |
|
1137 | - $returnContext .= '<img src="' . $currentAttachment['href'] . ';image" alt="' . $currentAttachment['name'] . '"' . $width . $height . '/>'; |
|
1190 | + if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) { |
|
1191 | + $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '" alt="' . $currentAttachment['name'] . '" id="thumb_'. $currentAttachment['id']. '"></a>'; |
|
1192 | + } else { |
|
1193 | + $returnContext .= '<img src="' . $currentAttachment['href'] . ';image" alt="' . $currentAttachment['name'] . '"' . $width . $height . '/>'; |
|
1194 | + } |
|
1138 | 1195 | } |
1139 | 1196 | |
1140 | 1197 | // No image. Show a link. |
1141 | - else |
|
1142 | - $returnContext .= $currentAttachment['link']; |
|
1198 | + else { |
|
1199 | + $returnContext .= $currentAttachment['link']; |
|
1200 | + } |
|
1143 | 1201 | |
1144 | 1202 | // Gotta append what we just did. |
1145 | 1203 | $data = $returnContext; |
@@ -1170,8 +1228,9 @@ discard block |
||
1170 | 1228 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
1171 | 1229 | { |
1172 | 1230 | // Do PHP code coloring? |
1173 | - if ($php_parts[$php_i] != '<?php') |
|
1174 | - continue; |
|
1231 | + if ($php_parts[$php_i] != '<?php') { |
|
1232 | + continue; |
|
1233 | + } |
|
1175 | 1234 | |
1176 | 1235 | $php_string = ''; |
1177 | 1236 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1187,8 +1246,9 @@ discard block |
||
1187 | 1246 | $data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data); |
1188 | 1247 | |
1189 | 1248 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
1190 | - if ($context['browser']['is_opera']) |
|
1191 | - $data .= ' '; |
|
1249 | + if ($context['browser']['is_opera']) { |
|
1250 | + $data .= ' '; |
|
1251 | + } |
|
1192 | 1252 | } |
1193 | 1253 | }, |
1194 | 1254 | 'block_level' => true, |
@@ -1207,8 +1267,9 @@ discard block |
||
1207 | 1267 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
1208 | 1268 | { |
1209 | 1269 | // Do PHP code coloring? |
1210 | - if ($php_parts[$php_i] != '<?php') |
|
1211 | - continue; |
|
1270 | + if ($php_parts[$php_i] != '<?php') { |
|
1271 | + continue; |
|
1272 | + } |
|
1212 | 1273 | |
1213 | 1274 | $php_string = ''; |
1214 | 1275 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1224,8 +1285,9 @@ discard block |
||
1224 | 1285 | $data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]); |
1225 | 1286 | |
1226 | 1287 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
1227 | - if ($context['browser']['is_opera']) |
|
1228 | - $data[0] .= ' '; |
|
1288 | + if ($context['browser']['is_opera']) { |
|
1289 | + $data[0] .= ' '; |
|
1290 | + } |
|
1229 | 1291 | } |
1230 | 1292 | }, |
1231 | 1293 | 'block_level' => true, |
@@ -1263,11 +1325,13 @@ discard block |
||
1263 | 1325 | 'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">', |
1264 | 1326 | 'validate' => function (&$tag, &$data, $disabled) |
1265 | 1327 | { |
1266 | - if (isset($disabled['url'])) |
|
1267 | - $tag['content'] = '$1'; |
|
1328 | + if (isset($disabled['url'])) { |
|
1329 | + $tag['content'] = '$1'; |
|
1330 | + } |
|
1268 | 1331 | $scheme = parse_url($data[0], PHP_URL_SCHEME); |
1269 | - if (empty($scheme)) |
|
1270 | - $data[0] = '//' . ltrim($data[0], ':/'); |
|
1332 | + if (empty($scheme)) { |
|
1333 | + $data[0] = '//' . ltrim($data[0], ':/'); |
|
1334 | + } |
|
1271 | 1335 | }, |
1272 | 1336 | 'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>', |
1273 | 1337 | ), |
@@ -1314,14 +1378,16 @@ discard block |
||
1314 | 1378 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1315 | 1379 | if ($image_proxy_enabled) |
1316 | 1380 | { |
1317 | - if (empty($scheme)) |
|
1318 | - $data = 'http://' . ltrim($data, ':/'); |
|
1381 | + if (empty($scheme)) { |
|
1382 | + $data = 'http://' . ltrim($data, ':/'); |
|
1383 | + } |
|
1319 | 1384 | |
1320 | - if ($scheme != 'https') |
|
1321 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1385 | + if ($scheme != 'https') { |
|
1386 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1387 | + } |
|
1388 | + } elseif (empty($scheme)) { |
|
1389 | + $data = '//' . ltrim($data, ':/'); |
|
1322 | 1390 | } |
1323 | - elseif (empty($scheme)) |
|
1324 | - $data = '//' . ltrim($data, ':/'); |
|
1325 | 1391 | }, |
1326 | 1392 | 'disabled_content' => '($1)', |
1327 | 1393 | ), |
@@ -1337,14 +1403,16 @@ discard block |
||
1337 | 1403 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1338 | 1404 | if ($image_proxy_enabled) |
1339 | 1405 | { |
1340 | - if (empty($scheme)) |
|
1341 | - $data = 'http://' . ltrim($data, ':/'); |
|
1406 | + if (empty($scheme)) { |
|
1407 | + $data = 'http://' . ltrim($data, ':/'); |
|
1408 | + } |
|
1342 | 1409 | |
1343 | - if ($scheme != 'https') |
|
1344 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1410 | + if ($scheme != 'https') { |
|
1411 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1412 | + } |
|
1413 | + } elseif (empty($scheme)) { |
|
1414 | + $data = '//' . ltrim($data, ':/'); |
|
1345 | 1415 | } |
1346 | - elseif (empty($scheme)) |
|
1347 | - $data = '//' . ltrim($data, ':/'); |
|
1348 | 1416 | }, |
1349 | 1417 | 'disabled_content' => '($1)', |
1350 | 1418 | ), |
@@ -1356,8 +1424,9 @@ discard block |
||
1356 | 1424 | { |
1357 | 1425 | $data = strtr($data, array('<br>' => '')); |
1358 | 1426 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1359 | - if (empty($scheme)) |
|
1360 | - $data = '//' . ltrim($data, ':/'); |
|
1427 | + if (empty($scheme)) { |
|
1428 | + $data = '//' . ltrim($data, ':/'); |
|
1429 | + } |
|
1361 | 1430 | }, |
1362 | 1431 | ), |
1363 | 1432 | array( |
@@ -1368,13 +1437,14 @@ discard block |
||
1368 | 1437 | 'after' => '</a>', |
1369 | 1438 | 'validate' => function (&$tag, &$data, $disabled) |
1370 | 1439 | { |
1371 | - if (substr($data, 0, 1) == '#') |
|
1372 | - $data = '#post_' . substr($data, 1); |
|
1373 | - else |
|
1440 | + if (substr($data, 0, 1) == '#') { |
|
1441 | + $data = '#post_' . substr($data, 1); |
|
1442 | + } else |
|
1374 | 1443 | { |
1375 | 1444 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1376 | - if (empty($scheme)) |
|
1377 | - $data = '//' . ltrim($data, ':/'); |
|
1445 | + if (empty($scheme)) { |
|
1446 | + $data = '//' . ltrim($data, ':/'); |
|
1447 | + } |
|
1378 | 1448 | } |
1379 | 1449 | }, |
1380 | 1450 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
@@ -1452,8 +1522,9 @@ discard block |
||
1452 | 1522 | { |
1453 | 1523 | $add_begin = substr(trim($data), 0, 5) != '<?'; |
1454 | 1524 | $data = highlight_php_code($add_begin ? '<?php ' . $data . '?>' : $data); |
1455 | - if ($add_begin) |
|
1456 | - $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
1525 | + if ($add_begin) { |
|
1526 | + $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
1527 | + } |
|
1457 | 1528 | } |
1458 | 1529 | }, |
1459 | 1530 | 'block_level' => false, |
@@ -1584,10 +1655,11 @@ discard block |
||
1584 | 1655 | 'content' => '$1', |
1585 | 1656 | 'validate' => function (&$tag, &$data, $disabled) |
1586 | 1657 | { |
1587 | - if (is_numeric($data)) |
|
1588 | - $data = timeformat($data); |
|
1589 | - else |
|
1590 | - $tag['content'] = '[time]$1[/time]'; |
|
1658 | + if (is_numeric($data)) { |
|
1659 | + $data = timeformat($data); |
|
1660 | + } else { |
|
1661 | + $tag['content'] = '[time]$1[/time]'; |
|
1662 | + } |
|
1591 | 1663 | }, |
1592 | 1664 | ), |
1593 | 1665 | array( |
@@ -1614,8 +1686,9 @@ discard block |
||
1614 | 1686 | { |
1615 | 1687 | $data = strtr($data, array('<br>' => '')); |
1616 | 1688 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1617 | - if (empty($scheme)) |
|
1618 | - $data = '//' . ltrim($data, ':/'); |
|
1689 | + if (empty($scheme)) { |
|
1690 | + $data = '//' . ltrim($data, ':/'); |
|
1691 | + } |
|
1619 | 1692 | }, |
1620 | 1693 | ), |
1621 | 1694 | array( |
@@ -1627,8 +1700,9 @@ discard block |
||
1627 | 1700 | 'validate' => function (&$tag, &$data, $disabled) |
1628 | 1701 | { |
1629 | 1702 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1630 | - if (empty($scheme)) |
|
1631 | - $data = '//' . ltrim($data, ':/'); |
|
1703 | + if (empty($scheme)) { |
|
1704 | + $data = '//' . ltrim($data, ':/'); |
|
1705 | + } |
|
1632 | 1706 | }, |
1633 | 1707 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
1634 | 1708 | 'disabled_after' => ' ($1)', |
@@ -1648,8 +1722,9 @@ discard block |
||
1648 | 1722 | // This is mainly for the bbc manager, so it's easy to add tags above. Custom BBC should be added above this line. |
1649 | 1723 | if ($message === false) |
1650 | 1724 | { |
1651 | - if (isset($temp_bbc)) |
|
1652 | - $bbc_codes = $temp_bbc; |
|
1725 | + if (isset($temp_bbc)) { |
|
1726 | + $bbc_codes = $temp_bbc; |
|
1727 | + } |
|
1653 | 1728 | usort($codes, function ($a, $b) { |
1654 | 1729 | return strcmp($a['tag'], $b['tag']); |
1655 | 1730 | }); |
@@ -1669,8 +1744,9 @@ discard block |
||
1669 | 1744 | ); |
1670 | 1745 | if (!isset($disabled['li']) && !isset($disabled['list'])) |
1671 | 1746 | { |
1672 | - foreach ($itemcodes as $c => $dummy) |
|
1673 | - $bbc_codes[$c] = array(); |
|
1747 | + foreach ($itemcodes as $c => $dummy) { |
|
1748 | + $bbc_codes[$c] = array(); |
|
1749 | + } |
|
1674 | 1750 | } |
1675 | 1751 | |
1676 | 1752 | // Shhhh! |
@@ -1691,12 +1767,14 @@ discard block |
||
1691 | 1767 | foreach ($codes as $code) |
1692 | 1768 | { |
1693 | 1769 | // Make it easier to process parameters later |
1694 | - if (!empty($code['parameters'])) |
|
1695 | - ksort($code['parameters'], SORT_STRING); |
|
1770 | + if (!empty($code['parameters'])) { |
|
1771 | + ksort($code['parameters'], SORT_STRING); |
|
1772 | + } |
|
1696 | 1773 | |
1697 | 1774 | // If we are not doing every tag only do ones we are interested in. |
1698 | - if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) |
|
1699 | - $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
1775 | + if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) { |
|
1776 | + $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
1777 | + } |
|
1700 | 1778 | } |
1701 | 1779 | $codes = null; |
1702 | 1780 | } |
@@ -1707,8 +1785,9 @@ discard block |
||
1707 | 1785 | // It's likely this will change if the message is modified. |
1708 | 1786 | $cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . json_encode($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']); |
1709 | 1787 | |
1710 | - if (($temp = cache_get_data($cache_key, 240)) != null) |
|
1711 | - return $temp; |
|
1788 | + if (($temp = cache_get_data($cache_key, 240)) != null) { |
|
1789 | + return $temp; |
|
1790 | + } |
|
1712 | 1791 | |
1713 | 1792 | $cache_t = microtime(); |
1714 | 1793 | } |
@@ -1740,8 +1819,9 @@ discard block |
||
1740 | 1819 | $disabled['flash'] = true; |
1741 | 1820 | |
1742 | 1821 | // @todo Change maybe? |
1743 | - if (!isset($_GET['images'])) |
|
1744 | - $disabled['img'] = true; |
|
1822 | + if (!isset($_GET['images'])) { |
|
1823 | + $disabled['img'] = true; |
|
1824 | + } |
|
1745 | 1825 | |
1746 | 1826 | // @todo Interface/setting to add more? |
1747 | 1827 | } |
@@ -1767,8 +1847,9 @@ discard block |
||
1767 | 1847 | $pos = isset($matches[0][1]) ? $matches[0][1] : false; |
1768 | 1848 | |
1769 | 1849 | // Failsafe. |
1770 | - if ($pos === false || $last_pos > $pos) |
|
1771 | - $pos = strlen($message) + 1; |
|
1850 | + if ($pos === false || $last_pos > $pos) { |
|
1851 | + $pos = strlen($message) + 1; |
|
1852 | + } |
|
1772 | 1853 | |
1773 | 1854 | // Can't have a one letter smiley, URL, or email! (sorry.) |
1774 | 1855 | if ($last_pos < $pos - 1) |
@@ -1787,8 +1868,9 @@ discard block |
||
1787 | 1868 | |
1788 | 1869 | // <br> should be empty. |
1789 | 1870 | $empty_tags = array('br', 'hr'); |
1790 | - foreach ($empty_tags as $tag) |
|
1791 | - $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
1871 | + foreach ($empty_tags as $tag) { |
|
1872 | + $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
1873 | + } |
|
1792 | 1874 | |
1793 | 1875 | // b, u, i, s, pre... basic tags. |
1794 | 1876 | $closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote'); |
@@ -1797,8 +1879,9 @@ discard block |
||
1797 | 1879 | $diff = substr_count($data, '<' . $tag . '>') - substr_count($data, '</' . $tag . '>'); |
1798 | 1880 | $data = strtr($data, array('<' . $tag . '>' => '<' . $tag . '>', '</' . $tag . '>' => '</' . $tag . '>')); |
1799 | 1881 | |
1800 | - if ($diff > 0) |
|
1801 | - $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
1882 | + if ($diff > 0) { |
|
1883 | + $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
1884 | + } |
|
1802 | 1885 | } |
1803 | 1886 | |
1804 | 1887 | // Do <img ...> - with security... action= -> action-. |
@@ -1811,8 +1894,9 @@ discard block |
||
1811 | 1894 | $alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^"|"$~', '', $matches[3][$match]); |
1812 | 1895 | |
1813 | 1896 | // Remove action= from the URL - no funny business, now. |
1814 | - if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) |
|
1815 | - $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
1897 | + if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) { |
|
1898 | + $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
1899 | + } |
|
1816 | 1900 | |
1817 | 1901 | // Check if the image is larger than allowed. |
1818 | 1902 | if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height'])) |
@@ -1833,9 +1917,9 @@ discard block |
||
1833 | 1917 | |
1834 | 1918 | // Set the new image tag. |
1835 | 1919 | $replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]'; |
1920 | + } else { |
|
1921 | + $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
1836 | 1922 | } |
1837 | - else |
|
1838 | - $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
1839 | 1923 | } |
1840 | 1924 | |
1841 | 1925 | $data = strtr($data, $replaces); |
@@ -1848,16 +1932,18 @@ discard block |
||
1848 | 1932 | $no_autolink_area = false; |
1849 | 1933 | if (!empty($open_tags)) |
1850 | 1934 | { |
1851 | - foreach ($open_tags as $open_tag) |
|
1852 | - if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
1935 | + foreach ($open_tags as $open_tag) { |
|
1936 | + if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
1853 | 1937 | $no_autolink_area = true; |
1938 | + } |
|
1854 | 1939 | } |
1855 | 1940 | |
1856 | 1941 | // Don't go backwards. |
1857 | 1942 | // @todo Don't think is the real solution.... |
1858 | 1943 | $lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0; |
1859 | - if ($pos < $lastAutoPos) |
|
1860 | - $no_autolink_area = true; |
|
1944 | + if ($pos < $lastAutoPos) { |
|
1945 | + $no_autolink_area = true; |
|
1946 | + } |
|
1861 | 1947 | $lastAutoPos = $pos; |
1862 | 1948 | |
1863 | 1949 | if (!$no_autolink_area) |
@@ -1966,17 +2052,19 @@ discard block |
||
1966 | 2052 | if ($scheme == 'mailto') |
1967 | 2053 | { |
1968 | 2054 | $email_address = str_replace('mailto:', '', $url); |
1969 | - if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) |
|
1970 | - return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
1971 | - else |
|
1972 | - return $url; |
|
2055 | + if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) { |
|
2056 | + return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
2057 | + } else { |
|
2058 | + return $url; |
|
2059 | + } |
|
1973 | 2060 | } |
1974 | 2061 | |
1975 | 2062 | // Are we linking a schemeless URL or naked domain name (e.g. "example.com")? |
1976 | - if (empty($scheme)) |
|
1977 | - $fullUrl = '//' . ltrim($url, ':/'); |
|
1978 | - else |
|
1979 | - $fullUrl = $url; |
|
2063 | + if (empty($scheme)) { |
|
2064 | + $fullUrl = '//' . ltrim($url, ':/'); |
|
2065 | + } else { |
|
2066 | + $fullUrl = $url; |
|
2067 | + } |
|
1980 | 2068 | |
1981 | 2069 | return '[url="' . str_replace(array('[', ']'), array('[', ']'), $fullUrl) . '"]' . $url . '[/url]'; |
1982 | 2070 | }, $data); |
@@ -2025,16 +2113,18 @@ discard block |
||
2025 | 2113 | } |
2026 | 2114 | |
2027 | 2115 | // Are we there yet? Are we there yet? |
2028 | - if ($pos >= strlen($message) - 1) |
|
2029 | - break; |
|
2116 | + if ($pos >= strlen($message) - 1) { |
|
2117 | + break; |
|
2118 | + } |
|
2030 | 2119 | |
2031 | 2120 | $tags = strtolower($message[$pos + 1]); |
2032 | 2121 | |
2033 | 2122 | if ($tags == '/' && !empty($open_tags)) |
2034 | 2123 | { |
2035 | 2124 | $pos2 = strpos($message, ']', $pos + 1); |
2036 | - if ($pos2 == $pos + 2) |
|
2037 | - continue; |
|
2125 | + if ($pos2 == $pos + 2) { |
|
2126 | + continue; |
|
2127 | + } |
|
2038 | 2128 | |
2039 | 2129 | $look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2)); |
2040 | 2130 | |
@@ -2044,8 +2134,9 @@ discard block |
||
2044 | 2134 | do |
2045 | 2135 | { |
2046 | 2136 | $tag = array_pop($open_tags); |
2047 | - if (!$tag) |
|
2048 | - break; |
|
2137 | + if (!$tag) { |
|
2138 | + break; |
|
2139 | + } |
|
2049 | 2140 | |
2050 | 2141 | if (!empty($tag['block_level'])) |
2051 | 2142 | { |
@@ -2059,10 +2150,11 @@ discard block |
||
2059 | 2150 | // The idea is, if we are LOOKING for a block level tag, we can close them on the way. |
2060 | 2151 | if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]])) |
2061 | 2152 | { |
2062 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
2063 | - if ($temp['tag'] == $look_for) |
|
2153 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
2154 | + if ($temp['tag'] == $look_for) |
|
2064 | 2155 | { |
2065 | 2156 | $block_level = !empty($temp['block_level']); |
2157 | + } |
|
2066 | 2158 | break; |
2067 | 2159 | } |
2068 | 2160 | } |
@@ -2084,15 +2176,15 @@ discard block |
||
2084 | 2176 | { |
2085 | 2177 | $open_tags = $to_close; |
2086 | 2178 | continue; |
2087 | - } |
|
2088 | - elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
2179 | + } elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
2089 | 2180 | { |
2090 | 2181 | if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]])) |
2091 | 2182 | { |
2092 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
2093 | - if ($temp['tag'] == $look_for) |
|
2183 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
2184 | + if ($temp['tag'] == $look_for) |
|
2094 | 2185 | { |
2095 | 2186 | $block_level = !empty($temp['block_level']); |
2187 | + } |
|
2096 | 2188 | break; |
2097 | 2189 | } |
2098 | 2190 | } |
@@ -2100,8 +2192,9 @@ discard block |
||
2100 | 2192 | // We're not looking for a block level tag (or maybe even a tag that exists...) |
2101 | 2193 | if (!$block_level) |
2102 | 2194 | { |
2103 | - foreach ($to_close as $tag) |
|
2104 | - array_push($open_tags, $tag); |
|
2195 | + foreach ($to_close as $tag) { |
|
2196 | + array_push($open_tags, $tag); |
|
2197 | + } |
|
2105 | 2198 | continue; |
2106 | 2199 | } |
2107 | 2200 | } |
@@ -2113,10 +2206,12 @@ discard block |
||
2113 | 2206 | $pos2 = $pos - 1; |
2114 | 2207 | |
2115 | 2208 | // See the comment at the end of the big loop - just eating whitespace ;). |
2116 | - if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>') |
|
2117 | - $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
2118 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) |
|
2119 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2209 | + if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>') { |
|
2210 | + $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
2211 | + } |
|
2212 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) { |
|
2213 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2214 | + } |
|
2120 | 2215 | } |
2121 | 2216 | |
2122 | 2217 | if (!empty($to_close)) |
@@ -2129,8 +2224,9 @@ discard block |
||
2129 | 2224 | } |
2130 | 2225 | |
2131 | 2226 | // No tags for this character, so just keep going (fastest possible course.) |
2132 | - if (!isset($bbc_codes[$tags])) |
|
2133 | - continue; |
|
2227 | + if (!isset($bbc_codes[$tags])) { |
|
2228 | + continue; |
|
2229 | + } |
|
2134 | 2230 | |
2135 | 2231 | $inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1]; |
2136 | 2232 | $tag = null; |
@@ -2139,44 +2235,52 @@ discard block |
||
2139 | 2235 | $pt_strlen = strlen($possible['tag']); |
2140 | 2236 | |
2141 | 2237 | // Not a match? |
2142 | - if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) |
|
2143 | - continue; |
|
2238 | + if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) { |
|
2239 | + continue; |
|
2240 | + } |
|
2144 | 2241 | |
2145 | 2242 | $next_c = $message[$pos + 1 + $pt_strlen]; |
2146 | 2243 | |
2147 | 2244 | // A test validation? |
2148 | - if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) |
|
2149 | - continue; |
|
2245 | + if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) { |
|
2246 | + continue; |
|
2247 | + } |
|
2150 | 2248 | // Do we want parameters? |
2151 | 2249 | elseif (!empty($possible['parameters'])) |
2152 | 2250 | { |
2153 | - if ($next_c != ' ') |
|
2154 | - continue; |
|
2155 | - } |
|
2156 | - elseif (isset($possible['type'])) |
|
2251 | + if ($next_c != ' ') { |
|
2252 | + continue; |
|
2253 | + } |
|
2254 | + } elseif (isset($possible['type'])) |
|
2157 | 2255 | { |
2158 | 2256 | // Do we need an equal sign? |
2159 | - if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') |
|
2160 | - continue; |
|
2257 | + if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') { |
|
2258 | + continue; |
|
2259 | + } |
|
2161 | 2260 | // Maybe we just want a /... |
2162 | - if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') |
|
2163 | - continue; |
|
2261 | + if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') { |
|
2262 | + continue; |
|
2263 | + } |
|
2164 | 2264 | // An immediate ]? |
2165 | - if ($possible['type'] == 'unparsed_content' && $next_c != ']') |
|
2166 | - continue; |
|
2265 | + if ($possible['type'] == 'unparsed_content' && $next_c != ']') { |
|
2266 | + continue; |
|
2267 | + } |
|
2167 | 2268 | } |
2168 | 2269 | // No type means 'parsed_content', which demands an immediate ] without parameters! |
2169 | - elseif ($next_c != ']') |
|
2170 | - continue; |
|
2270 | + elseif ($next_c != ']') { |
|
2271 | + continue; |
|
2272 | + } |
|
2171 | 2273 | |
2172 | 2274 | // Check allowed tree? |
2173 | - if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) |
|
2174 | - continue; |
|
2175 | - elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) |
|
2176 | - continue; |
|
2275 | + if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) { |
|
2276 | + continue; |
|
2277 | + } elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) { |
|
2278 | + continue; |
|
2279 | + } |
|
2177 | 2280 | // If this is in the list of disallowed child tags, don't parse it. |
2178 | - elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) |
|
2179 | - continue; |
|
2281 | + elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) { |
|
2282 | + continue; |
|
2283 | + } |
|
2180 | 2284 | |
2181 | 2285 | $pos1 = $pos + 1 + $pt_strlen + 1; |
2182 | 2286 | |
@@ -2188,8 +2292,9 @@ discard block |
||
2188 | 2292 | foreach ($open_tags as $open_quote) |
2189 | 2293 | { |
2190 | 2294 | // Every parent quote this quote has flips the styling |
2191 | - if ($open_quote['tag'] == 'quote') |
|
2192 | - $quote_alt = !$quote_alt; |
|
2295 | + if ($open_quote['tag'] == 'quote') { |
|
2296 | + $quote_alt = !$quote_alt; |
|
2297 | + } |
|
2193 | 2298 | } |
2194 | 2299 | // Add a class to the quote to style alternating blockquotes |
2195 | 2300 | $possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">')); |
@@ -2200,8 +2305,9 @@ discard block |
||
2200 | 2305 | { |
2201 | 2306 | // Build a regular expression for each parameter for the current tag. |
2202 | 2307 | $preg = array(); |
2203 | - foreach ($possible['parameters'] as $p => $info) |
|
2204 | - $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
2308 | + foreach ($possible['parameters'] as $p => $info) { |
|
2309 | + $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
2310 | + } |
|
2205 | 2311 | |
2206 | 2312 | // Extract the string that potentially holds our parameters. |
2207 | 2313 | $blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos)); |
@@ -2221,24 +2327,27 @@ discard block |
||
2221 | 2327 | |
2222 | 2328 | $match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0; |
2223 | 2329 | |
2224 | - if ($match) |
|
2225 | - $blob_counter = count($blobs) + 1; |
|
2330 | + if ($match) { |
|
2331 | + $blob_counter = count($blobs) + 1; |
|
2332 | + } |
|
2226 | 2333 | } |
2227 | 2334 | |
2228 | 2335 | // Didn't match our parameter list, try the next possible. |
2229 | - if (!$match) |
|
2230 | - continue; |
|
2336 | + if (!$match) { |
|
2337 | + continue; |
|
2338 | + } |
|
2231 | 2339 | |
2232 | 2340 | $params = array(); |
2233 | 2341 | for ($i = 1, $n = count($matches); $i < $n; $i += 2) |
2234 | 2342 | { |
2235 | 2343 | $key = strtok(ltrim($matches[$i]), '='); |
2236 | - if (isset($possible['parameters'][$key]['value'])) |
|
2237 | - $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
2238 | - elseif (isset($possible['parameters'][$key]['validate'])) |
|
2239 | - $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
2240 | - else |
|
2241 | - $params['{' . $key . '}'] = $matches[$i + 1]; |
|
2344 | + if (isset($possible['parameters'][$key]['value'])) { |
|
2345 | + $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
2346 | + } elseif (isset($possible['parameters'][$key]['validate'])) { |
|
2347 | + $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
2348 | + } else { |
|
2349 | + $params['{' . $key . '}'] = $matches[$i + 1]; |
|
2350 | + } |
|
2242 | 2351 | |
2243 | 2352 | // Just to make sure: replace any $ or { so they can't interpolate wrongly. |
2244 | 2353 | $params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '$', '{' => '{')); |
@@ -2246,23 +2355,26 @@ discard block |
||
2246 | 2355 | |
2247 | 2356 | foreach ($possible['parameters'] as $p => $info) |
2248 | 2357 | { |
2249 | - if (!isset($params['{' . $p . '}'])) |
|
2250 | - $params['{' . $p . '}'] = ''; |
|
2358 | + if (!isset($params['{' . $p . '}'])) { |
|
2359 | + $params['{' . $p . '}'] = ''; |
|
2360 | + } |
|
2251 | 2361 | } |
2252 | 2362 | |
2253 | 2363 | $tag = $possible; |
2254 | 2364 | |
2255 | 2365 | // Put the parameters into the string. |
2256 | - if (isset($tag['before'])) |
|
2257 | - $tag['before'] = strtr($tag['before'], $params); |
|
2258 | - if (isset($tag['after'])) |
|
2259 | - $tag['after'] = strtr($tag['after'], $params); |
|
2260 | - if (isset($tag['content'])) |
|
2261 | - $tag['content'] = strtr($tag['content'], $params); |
|
2366 | + if (isset($tag['before'])) { |
|
2367 | + $tag['before'] = strtr($tag['before'], $params); |
|
2368 | + } |
|
2369 | + if (isset($tag['after'])) { |
|
2370 | + $tag['after'] = strtr($tag['after'], $params); |
|
2371 | + } |
|
2372 | + if (isset($tag['content'])) { |
|
2373 | + $tag['content'] = strtr($tag['content'], $params); |
|
2374 | + } |
|
2262 | 2375 | |
2263 | 2376 | $pos1 += strlen($given_param_string); |
2264 | - } |
|
2265 | - else |
|
2377 | + } else |
|
2266 | 2378 | { |
2267 | 2379 | $tag = $possible; |
2268 | 2380 | $params = array(); |
@@ -2273,8 +2385,9 @@ discard block |
||
2273 | 2385 | // Item codes are complicated buggers... they are implicit [li]s and can make [list]s! |
2274 | 2386 | if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li'])) |
2275 | 2387 | { |
2276 | - if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) |
|
2277 | - continue; |
|
2388 | + if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) { |
|
2389 | + continue; |
|
2390 | + } |
|
2278 | 2391 | |
2279 | 2392 | $tag = $itemcodes[$message[$pos + 1]]; |
2280 | 2393 | |
@@ -2295,9 +2408,9 @@ discard block |
||
2295 | 2408 | { |
2296 | 2409 | array_pop($open_tags); |
2297 | 2410 | $code = '</li>'; |
2411 | + } else { |
|
2412 | + $code = ''; |
|
2298 | 2413 | } |
2299 | - else |
|
2300 | - $code = ''; |
|
2301 | 2414 | |
2302 | 2415 | // Now we open a new tag. |
2303 | 2416 | $open_tags[] = array( |
@@ -2344,12 +2457,14 @@ discard block |
||
2344 | 2457 | } |
2345 | 2458 | |
2346 | 2459 | // No tag? Keep looking, then. Silly people using brackets without actual tags. |
2347 | - if ($tag === null) |
|
2348 | - continue; |
|
2460 | + if ($tag === null) { |
|
2461 | + continue; |
|
2462 | + } |
|
2349 | 2463 | |
2350 | 2464 | // Propagate the list to the child (so wrapping the disallowed tag won't work either.) |
2351 | - if (isset($inside['disallow_children'])) |
|
2352 | - $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
2465 | + if (isset($inside['disallow_children'])) { |
|
2466 | + $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
2467 | + } |
|
2353 | 2468 | |
2354 | 2469 | // Is this tag disabled? |
2355 | 2470 | if (isset($disabled[$tag['tag']])) |
@@ -2359,14 +2474,13 @@ discard block |
||
2359 | 2474 | $tag['before'] = !empty($tag['block_level']) ? '<div>' : ''; |
2360 | 2475 | $tag['after'] = !empty($tag['block_level']) ? '</div>' : ''; |
2361 | 2476 | $tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1'); |
2362 | - } |
|
2363 | - elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
2477 | + } elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
2364 | 2478 | { |
2365 | 2479 | $tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : ''); |
2366 | 2480 | $tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : ''); |
2481 | + } else { |
|
2482 | + $tag['content'] = $tag['disabled_content']; |
|
2367 | 2483 | } |
2368 | - else |
|
2369 | - $tag['content'] = $tag['disabled_content']; |
|
2370 | 2484 | } |
2371 | 2485 | |
2372 | 2486 | // we use this a lot |
@@ -2376,8 +2490,9 @@ discard block |
||
2376 | 2490 | if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level'])) |
2377 | 2491 | { |
2378 | 2492 | $n = count($open_tags) - 1; |
2379 | - while (empty($open_tags[$n]['block_level']) && $n >= 0) |
|
2380 | - $n--; |
|
2493 | + while (empty($open_tags[$n]['block_level']) && $n >= 0) { |
|
2494 | + $n--; |
|
2495 | + } |
|
2381 | 2496 | |
2382 | 2497 | // Close all the non block level tags so this tag isn't surrounded by them. |
2383 | 2498 | for ($i = count($open_tags) - 1; $i > $n; $i--) |
@@ -2388,10 +2503,12 @@ discard block |
||
2388 | 2503 | $pos1 += $ot_strlen + 2; |
2389 | 2504 | |
2390 | 2505 | // Trim or eat trailing stuff... see comment at the end of the big loop. |
2391 | - if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>') |
|
2392 | - $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
2393 | - if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) |
|
2394 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2506 | + if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>') { |
|
2507 | + $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
2508 | + } |
|
2509 | + if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) { |
|
2510 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2511 | + } |
|
2395 | 2512 | |
2396 | 2513 | array_pop($open_tags); |
2397 | 2514 | } |
@@ -2409,16 +2526,19 @@ discard block |
||
2409 | 2526 | elseif ($tag['type'] == 'unparsed_content') |
2410 | 2527 | { |
2411 | 2528 | $pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1); |
2412 | - if ($pos2 === false) |
|
2413 | - continue; |
|
2529 | + if ($pos2 === false) { |
|
2530 | + continue; |
|
2531 | + } |
|
2414 | 2532 | |
2415 | 2533 | $data = substr($message, $pos1, $pos2 - $pos1); |
2416 | 2534 | |
2417 | - if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') |
|
2418 | - $data = substr($data, 4); |
|
2535 | + if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') { |
|
2536 | + $data = substr($data, 4); |
|
2537 | + } |
|
2419 | 2538 | |
2420 | - if (isset($tag['validate'])) |
|
2421 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2539 | + if (isset($tag['validate'])) { |
|
2540 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2541 | + } |
|
2422 | 2542 | |
2423 | 2543 | $code = strtr($tag['content'], array('$1' => $data)); |
2424 | 2544 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen); |
@@ -2434,34 +2554,40 @@ discard block |
||
2434 | 2554 | if (isset($tag['quoted'])) |
2435 | 2555 | { |
2436 | 2556 | $quoted = substr($message, $pos1, 6) == '"'; |
2437 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
2438 | - continue; |
|
2557 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
2558 | + continue; |
|
2559 | + } |
|
2439 | 2560 | |
2440 | - if ($quoted) |
|
2441 | - $pos1 += 6; |
|
2561 | + if ($quoted) { |
|
2562 | + $pos1 += 6; |
|
2563 | + } |
|
2564 | + } else { |
|
2565 | + $quoted = false; |
|
2442 | 2566 | } |
2443 | - else |
|
2444 | - $quoted = false; |
|
2445 | 2567 | |
2446 | 2568 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
2447 | - if ($pos2 === false) |
|
2448 | - continue; |
|
2569 | + if ($pos2 === false) { |
|
2570 | + continue; |
|
2571 | + } |
|
2449 | 2572 | |
2450 | 2573 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
2451 | - if ($pos3 === false) |
|
2452 | - continue; |
|
2574 | + if ($pos3 === false) { |
|
2575 | + continue; |
|
2576 | + } |
|
2453 | 2577 | |
2454 | 2578 | $data = array( |
2455 | 2579 | substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))), |
2456 | 2580 | substr($message, $pos1, $pos2 - $pos1) |
2457 | 2581 | ); |
2458 | 2582 | |
2459 | - if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') |
|
2460 | - $data[0] = substr($data[0], 4); |
|
2583 | + if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') { |
|
2584 | + $data[0] = substr($data[0], 4); |
|
2585 | + } |
|
2461 | 2586 | |
2462 | 2587 | // Validation for my parking, please! |
2463 | - if (isset($tag['validate'])) |
|
2464 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2588 | + if (isset($tag['validate'])) { |
|
2589 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2590 | + } |
|
2465 | 2591 | |
2466 | 2592 | $code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1])); |
2467 | 2593 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
@@ -2478,23 +2604,27 @@ discard block |
||
2478 | 2604 | elseif ($tag['type'] == 'unparsed_commas_content') |
2479 | 2605 | { |
2480 | 2606 | $pos2 = strpos($message, ']', $pos1); |
2481 | - if ($pos2 === false) |
|
2482 | - continue; |
|
2607 | + if ($pos2 === false) { |
|
2608 | + continue; |
|
2609 | + } |
|
2483 | 2610 | |
2484 | 2611 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
2485 | - if ($pos3 === false) |
|
2486 | - continue; |
|
2612 | + if ($pos3 === false) { |
|
2613 | + continue; |
|
2614 | + } |
|
2487 | 2615 | |
2488 | 2616 | // We want $1 to be the content, and the rest to be csv. |
2489 | 2617 | $data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1)); |
2490 | 2618 | $data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1); |
2491 | 2619 | |
2492 | - if (isset($tag['validate'])) |
|
2493 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2620 | + if (isset($tag['validate'])) { |
|
2621 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2622 | + } |
|
2494 | 2623 | |
2495 | 2624 | $code = $tag['content']; |
2496 | - foreach ($data as $k => $d) |
|
2497 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2625 | + foreach ($data as $k => $d) { |
|
2626 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2627 | + } |
|
2498 | 2628 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
2499 | 2629 | $pos += strlen($code) - 1 + 2; |
2500 | 2630 | } |
@@ -2502,24 +2632,28 @@ discard block |
||
2502 | 2632 | elseif ($tag['type'] == 'unparsed_commas') |
2503 | 2633 | { |
2504 | 2634 | $pos2 = strpos($message, ']', $pos1); |
2505 | - if ($pos2 === false) |
|
2506 | - continue; |
|
2635 | + if ($pos2 === false) { |
|
2636 | + continue; |
|
2637 | + } |
|
2507 | 2638 | |
2508 | 2639 | $data = explode(',', substr($message, $pos1, $pos2 - $pos1)); |
2509 | 2640 | |
2510 | - if (isset($tag['validate'])) |
|
2511 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2641 | + if (isset($tag['validate'])) { |
|
2642 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2643 | + } |
|
2512 | 2644 | |
2513 | 2645 | // Fix after, for disabled code mainly. |
2514 | - foreach ($data as $k => $d) |
|
2515 | - $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
2646 | + foreach ($data as $k => $d) { |
|
2647 | + $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
2648 | + } |
|
2516 | 2649 | |
2517 | 2650 | $open_tags[] = $tag; |
2518 | 2651 | |
2519 | 2652 | // Replace them out, $1, $2, $3, $4, etc. |
2520 | 2653 | $code = $tag['before']; |
2521 | - foreach ($data as $k => $d) |
|
2522 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2654 | + foreach ($data as $k => $d) { |
|
2655 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2656 | + } |
|
2523 | 2657 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1); |
2524 | 2658 | $pos += strlen($code) - 1 + 2; |
2525 | 2659 | } |
@@ -2530,28 +2664,33 @@ discard block |
||
2530 | 2664 | if (isset($tag['quoted'])) |
2531 | 2665 | { |
2532 | 2666 | $quoted = substr($message, $pos1, 6) == '"'; |
2533 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
2534 | - continue; |
|
2667 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
2668 | + continue; |
|
2669 | + } |
|
2535 | 2670 | |
2536 | - if ($quoted) |
|
2537 | - $pos1 += 6; |
|
2671 | + if ($quoted) { |
|
2672 | + $pos1 += 6; |
|
2673 | + } |
|
2674 | + } else { |
|
2675 | + $quoted = false; |
|
2538 | 2676 | } |
2539 | - else |
|
2540 | - $quoted = false; |
|
2541 | 2677 | |
2542 | 2678 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
2543 | - if ($pos2 === false) |
|
2544 | - continue; |
|
2679 | + if ($pos2 === false) { |
|
2680 | + continue; |
|
2681 | + } |
|
2545 | 2682 | |
2546 | 2683 | $data = substr($message, $pos1, $pos2 - $pos1); |
2547 | 2684 | |
2548 | 2685 | // Validation for my parking, please! |
2549 | - if (isset($tag['validate'])) |
|
2550 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2686 | + if (isset($tag['validate'])) { |
|
2687 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2688 | + } |
|
2551 | 2689 | |
2552 | 2690 | // For parsed content, we must recurse to avoid security problems. |
2553 | - if ($tag['type'] != 'unparsed_equals') |
|
2554 | - $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
2691 | + if ($tag['type'] != 'unparsed_equals') { |
|
2692 | + $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
2693 | + } |
|
2555 | 2694 | |
2556 | 2695 | $tag['after'] = strtr($tag['after'], array('$1' => $data)); |
2557 | 2696 | |
@@ -2563,34 +2702,40 @@ discard block |
||
2563 | 2702 | } |
2564 | 2703 | |
2565 | 2704 | // If this is block level, eat any breaks after it. |
2566 | - if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') |
|
2567 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
2705 | + if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') { |
|
2706 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
2707 | + } |
|
2568 | 2708 | |
2569 | 2709 | // Are we trimming outside this tag? |
2570 | - if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) |
|
2571 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
2710 | + if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) { |
|
2711 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
2712 | + } |
|
2572 | 2713 | } |
2573 | 2714 | |
2574 | 2715 | // Close any remaining tags. |
2575 | - while ($tag = array_pop($open_tags)) |
|
2576 | - $message .= "\n" . $tag['after'] . "\n"; |
|
2716 | + while ($tag = array_pop($open_tags)) { |
|
2717 | + $message .= "\n" . $tag['after'] . "\n"; |
|
2718 | + } |
|
2577 | 2719 | |
2578 | 2720 | // Parse the smileys within the parts where it can be done safely. |
2579 | 2721 | if ($smileys === true) |
2580 | 2722 | { |
2581 | 2723 | $message_parts = explode("\n", $message); |
2582 | - for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) |
|
2583 | - parsesmileys($message_parts[$i]); |
|
2724 | + for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) { |
|
2725 | + parsesmileys($message_parts[$i]); |
|
2726 | + } |
|
2584 | 2727 | |
2585 | 2728 | $message = implode('', $message_parts); |
2586 | 2729 | } |
2587 | 2730 | |
2588 | 2731 | // No smileys, just get rid of the markers. |
2589 | - else |
|
2590 | - $message = strtr($message, array("\n" => '')); |
|
2732 | + else { |
|
2733 | + $message = strtr($message, array("\n" => '')); |
|
2734 | + } |
|
2591 | 2735 | |
2592 | - if ($message !== '' && $message[0] === ' ') |
|
2593 | - $message = ' ' . substr($message, 1); |
|
2736 | + if ($message !== '' && $message[0] === ' ') { |
|
2737 | + $message = ' ' . substr($message, 1); |
|
2738 | + } |
|
2594 | 2739 | |
2595 | 2740 | // Cleanup whitespace. |
2596 | 2741 | $message = strtr($message, array(' ' => ' ', "\r" => '', "\n" => '<br>', '<br> ' => '<br> ', ' ' => "\n")); |
@@ -2599,15 +2744,16 @@ discard block |
||
2599 | 2744 | call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
2600 | 2745 | |
2601 | 2746 | // Cache the output if it took some time... |
2602 | - if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) |
|
2603 | - cache_put_data($cache_key, $message, 240); |
|
2747 | + if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) { |
|
2748 | + cache_put_data($cache_key, $message, 240); |
|
2749 | + } |
|
2604 | 2750 | |
2605 | 2751 | // If this was a force parse revert if needed. |
2606 | 2752 | if (!empty($parse_tags)) |
2607 | 2753 | { |
2608 | - if (empty($temp_bbc)) |
|
2609 | - $bbc_codes = array(); |
|
2610 | - else |
|
2754 | + if (empty($temp_bbc)) { |
|
2755 | + $bbc_codes = array(); |
|
2756 | + } else |
|
2611 | 2757 | { |
2612 | 2758 | $bbc_codes = $temp_bbc; |
2613 | 2759 | unset($temp_bbc); |
@@ -2634,8 +2780,9 @@ discard block |
||
2634 | 2780 | static $smileyPregSearch = null, $smileyPregReplacements = array(); |
2635 | 2781 | |
2636 | 2782 | // No smiley set at all?! |
2637 | - if ($user_info['smiley_set'] == 'none' || trim($message) == '') |
|
2638 | - return; |
|
2783 | + if ($user_info['smiley_set'] == 'none' || trim($message) == '') { |
|
2784 | + return; |
|
2785 | + } |
|
2639 | 2786 | |
2640 | 2787 | // If smileyPregSearch hasn't been set, do it now. |
2641 | 2788 | if (empty($smileyPregSearch)) |
@@ -2646,8 +2793,7 @@ discard block |
||
2646 | 2793 | $smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)'); |
2647 | 2794 | $smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif'); |
2648 | 2795 | $smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', ''); |
2649 | - } |
|
2650 | - else |
|
2796 | + } else |
|
2651 | 2797 | { |
2652 | 2798 | // Load the smileys in reverse order by length so they don't get parsed wrong. |
2653 | 2799 | if (($temp = cache_get_data('parsing_smileys', 480)) == null) |
@@ -2671,9 +2817,9 @@ discard block |
||
2671 | 2817 | $smcFunc['db_free_result']($result); |
2672 | 2818 | |
2673 | 2819 | cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480); |
2820 | + } else { |
|
2821 | + list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
2674 | 2822 | } |
2675 | - else |
|
2676 | - list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
2677 | 2823 | } |
2678 | 2824 | |
2679 | 2825 | // The non-breaking-space is a complex thing... |
@@ -2750,35 +2896,41 @@ discard block |
||
2750 | 2896 | global $scripturl, $context, $modSettings, $db_show_debug, $db_cache; |
2751 | 2897 | |
2752 | 2898 | // In case we have mail to send, better do that - as obExit doesn't always quite make it... |
2753 | - if (!empty($context['flush_mail'])) |
|
2754 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2899 | + if (!empty($context['flush_mail'])) { |
|
2900 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2755 | 2901 | AddMailQueue(true); |
2902 | + } |
|
2756 | 2903 | |
2757 | 2904 | $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:'; |
2758 | 2905 | |
2759 | - if ($add) |
|
2760 | - $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
2906 | + if ($add) { |
|
2907 | + $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
2908 | + } |
|
2761 | 2909 | |
2762 | 2910 | // Put the session ID in. |
2763 | - if (defined('SID') && SID != '') |
|
2764 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
2911 | + if (defined('SID') && SID != '') { |
|
2912 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
2913 | + } |
|
2765 | 2914 | // Keep that debug in their for template debugging! |
2766 | - elseif (isset($_GET['debug'])) |
|
2767 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
2915 | + elseif (isset($_GET['debug'])) { |
|
2916 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
2917 | + } |
|
2768 | 2918 | |
2769 | 2919 | if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed']))) |
2770 | 2920 | { |
2771 | - if (defined('SID') && SID != '') |
|
2772 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
2921 | + if (defined('SID') && SID != '') { |
|
2922 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
2773 | 2923 | function ($m) use ($scripturl) |
2774 | 2924 | { |
2775 | 2925 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : ""); |
2926 | + } |
|
2776 | 2927 | }, $setLocation); |
2777 | - else |
|
2778 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
2928 | + else { |
|
2929 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
2779 | 2930 | function ($m) use ($scripturl) |
2780 | 2931 | { |
2781 | 2932 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : ""); |
2933 | + } |
|
2782 | 2934 | }, $setLocation); |
2783 | 2935 | } |
2784 | 2936 | |
@@ -2789,8 +2941,9 @@ discard block |
||
2789 | 2941 | header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302); |
2790 | 2942 | |
2791 | 2943 | // Debugging. |
2792 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
2793 | - $_SESSION['debug_redirect'] = $db_cache; |
|
2944 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
2945 | + $_SESSION['debug_redirect'] = $db_cache; |
|
2946 | + } |
|
2794 | 2947 | |
2795 | 2948 | obExit(false); |
2796 | 2949 | } |
@@ -2809,51 +2962,60 @@ discard block |
||
2809 | 2962 | |
2810 | 2963 | // Attempt to prevent a recursive loop. |
2811 | 2964 | ++$level; |
2812 | - if ($level > 1 && !$from_fatal_error && !$has_fatal_error) |
|
2813 | - exit; |
|
2814 | - if ($from_fatal_error) |
|
2815 | - $has_fatal_error = true; |
|
2965 | + if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { |
|
2966 | + exit; |
|
2967 | + } |
|
2968 | + if ($from_fatal_error) { |
|
2969 | + $has_fatal_error = true; |
|
2970 | + } |
|
2816 | 2971 | |
2817 | 2972 | // Clear out the stat cache. |
2818 | 2973 | trackStats(); |
2819 | 2974 | |
2820 | 2975 | // If we have mail to send, send it. |
2821 | - if (!empty($context['flush_mail'])) |
|
2822 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2976 | + if (!empty($context['flush_mail'])) { |
|
2977 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2823 | 2978 | AddMailQueue(true); |
2979 | + } |
|
2824 | 2980 | |
2825 | 2981 | $do_header = $header === null ? !$header_done : $header; |
2826 | - if ($do_footer === null) |
|
2827 | - $do_footer = $do_header; |
|
2982 | + if ($do_footer === null) { |
|
2983 | + $do_footer = $do_header; |
|
2984 | + } |
|
2828 | 2985 | |
2829 | 2986 | // Has the template/header been done yet? |
2830 | 2987 | if ($do_header) |
2831 | 2988 | { |
2832 | 2989 | // Was the page title set last minute? Also update the HTML safe one. |
2833 | - if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) |
|
2834 | - $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
2990 | + if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { |
|
2991 | + $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
2992 | + } |
|
2835 | 2993 | |
2836 | 2994 | // Start up the session URL fixer. |
2837 | 2995 | ob_start('ob_sessrewrite'); |
2838 | 2996 | |
2839 | - if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) |
|
2840 | - $buffers = explode(',', $settings['output_buffers']); |
|
2841 | - elseif (!empty($settings['output_buffers'])) |
|
2842 | - $buffers = $settings['output_buffers']; |
|
2843 | - else |
|
2844 | - $buffers = array(); |
|
2997 | + if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) { |
|
2998 | + $buffers = explode(',', $settings['output_buffers']); |
|
2999 | + } elseif (!empty($settings['output_buffers'])) { |
|
3000 | + $buffers = $settings['output_buffers']; |
|
3001 | + } else { |
|
3002 | + $buffers = array(); |
|
3003 | + } |
|
2845 | 3004 | |
2846 | - if (isset($modSettings['integrate_buffer'])) |
|
2847 | - $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
3005 | + if (isset($modSettings['integrate_buffer'])) { |
|
3006 | + $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
3007 | + } |
|
2848 | 3008 | |
2849 | - if (!empty($buffers)) |
|
2850 | - foreach ($buffers as $function) |
|
3009 | + if (!empty($buffers)) { |
|
3010 | + foreach ($buffers as $function) |
|
2851 | 3011 | { |
2852 | 3012 | $call = call_helper($function, true); |
3013 | + } |
|
2853 | 3014 | |
2854 | 3015 | // Is it valid? |
2855 | - if (!empty($call)) |
|
2856 | - ob_start($call); |
|
3016 | + if (!empty($call)) { |
|
3017 | + ob_start($call); |
|
3018 | + } |
|
2857 | 3019 | } |
2858 | 3020 | |
2859 | 3021 | // Display the screen in the logical order. |
@@ -2865,8 +3027,9 @@ discard block |
||
2865 | 3027 | loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main'); |
2866 | 3028 | |
2867 | 3029 | // Anything special to put out? |
2868 | - if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) |
|
2869 | - echo $context['insert_after_template']; |
|
3030 | + if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) { |
|
3031 | + echo $context['insert_after_template']; |
|
3032 | + } |
|
2870 | 3033 | |
2871 | 3034 | // Just so we don't get caught in an endless loop of errors from the footer... |
2872 | 3035 | if (!$footer_done) |
@@ -2875,14 +3038,16 @@ discard block |
||
2875 | 3038 | template_footer(); |
2876 | 3039 | |
2877 | 3040 | // (since this is just debugging... it's okay that it's after </html>.) |
2878 | - if (!isset($_REQUEST['xml'])) |
|
2879 | - displayDebug(); |
|
3041 | + if (!isset($_REQUEST['xml'])) { |
|
3042 | + displayDebug(); |
|
3043 | + } |
|
2880 | 3044 | } |
2881 | 3045 | } |
2882 | 3046 | |
2883 | 3047 | // Remember this URL in case someone doesn't like sending HTTP_REFERER. |
2884 | - if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) |
|
2885 | - $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
3048 | + if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) { |
|
3049 | + $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
3050 | + } |
|
2886 | 3051 | |
2887 | 3052 | // For session check verification.... don't switch browsers... |
2888 | 3053 | $_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT']; |
@@ -2891,9 +3056,10 @@ discard block |
||
2891 | 3056 | call_integration_hook('integrate_exit', array($do_footer)); |
2892 | 3057 | |
2893 | 3058 | // Don't exit if we're coming from index.php; that will pass through normally. |
2894 | - if (!$from_index) |
|
2895 | - exit; |
|
2896 | -} |
|
3059 | + if (!$from_index) { |
|
3060 | + exit; |
|
3061 | + } |
|
3062 | + } |
|
2897 | 3063 | |
2898 | 3064 | /** |
2899 | 3065 | * Get the size of a specified image with better error handling. |
@@ -2912,8 +3078,9 @@ discard block |
||
2912 | 3078 | $url = str_replace(' ', '%20', $url); |
2913 | 3079 | |
2914 | 3080 | // Can we pull this from the cache... please please? |
2915 | - if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) |
|
2916 | - return $temp; |
|
3081 | + if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) { |
|
3082 | + return $temp; |
|
3083 | + } |
|
2917 | 3084 | $t = microtime(); |
2918 | 3085 | |
2919 | 3086 | // Get the host to pester... |
@@ -2923,12 +3090,10 @@ discard block |
||
2923 | 3090 | if ($url == '' || $url == 'http://' || $url == 'https://') |
2924 | 3091 | { |
2925 | 3092 | return false; |
2926 | - } |
|
2927 | - elseif (!isset($match[1])) |
|
3093 | + } elseif (!isset($match[1])) |
|
2928 | 3094 | { |
2929 | 3095 | $size = @getimagesize($url); |
2930 | - } |
|
2931 | - else |
|
3096 | + } else |
|
2932 | 3097 | { |
2933 | 3098 | // Try to connect to the server... give it half a second. |
2934 | 3099 | $temp = 0; |
@@ -2967,12 +3132,14 @@ discard block |
||
2967 | 3132 | } |
2968 | 3133 | |
2969 | 3134 | // If we didn't get it, we failed. |
2970 | - if (!isset($size)) |
|
2971 | - $size = false; |
|
3135 | + if (!isset($size)) { |
|
3136 | + $size = false; |
|
3137 | + } |
|
2972 | 3138 | |
2973 | 3139 | // If this took a long time, we may never have to do it again, but then again we might... |
2974 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) |
|
2975 | - cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
3140 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) { |
|
3141 | + cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
3142 | + } |
|
2976 | 3143 | |
2977 | 3144 | // Didn't work. |
2978 | 3145 | return $size; |
@@ -2990,8 +3157,9 @@ discard block |
||
2990 | 3157 | |
2991 | 3158 | // Under SSI this function can be called more then once. That can cause some problems. |
2992 | 3159 | // So only run the function once unless we are forced to run it again. |
2993 | - if ($loaded && !$forceload) |
|
2994 | - return; |
|
3160 | + if ($loaded && !$forceload) { |
|
3161 | + return; |
|
3162 | + } |
|
2995 | 3163 | |
2996 | 3164 | $loaded = true; |
2997 | 3165 | |
@@ -3003,14 +3171,16 @@ discard block |
||
3003 | 3171 | $context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news']))))); |
3004 | 3172 | for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++) |
3005 | 3173 | { |
3006 | - if (trim($context['news_lines'][$i]) == '') |
|
3007 | - continue; |
|
3174 | + if (trim($context['news_lines'][$i]) == '') { |
|
3175 | + continue; |
|
3176 | + } |
|
3008 | 3177 | |
3009 | 3178 | // Clean it up for presentation ;). |
3010 | 3179 | $context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i); |
3011 | 3180 | } |
3012 | - if (!empty($context['news_lines'])) |
|
3013 | - $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
3181 | + if (!empty($context['news_lines'])) { |
|
3182 | + $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
3183 | + } |
|
3014 | 3184 | |
3015 | 3185 | if (!$user_info['is_guest']) |
3016 | 3186 | { |
@@ -3019,40 +3189,48 @@ discard block |
||
3019 | 3189 | $context['user']['alerts'] = &$user_info['alerts']; |
3020 | 3190 | |
3021 | 3191 | // Personal message popup... |
3022 | - if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) |
|
3023 | - $context['user']['popup_messages'] = true; |
|
3024 | - else |
|
3025 | - $context['user']['popup_messages'] = false; |
|
3192 | + if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) { |
|
3193 | + $context['user']['popup_messages'] = true; |
|
3194 | + } else { |
|
3195 | + $context['user']['popup_messages'] = false; |
|
3196 | + } |
|
3026 | 3197 | $_SESSION['unread_messages'] = $user_info['unread_messages']; |
3027 | 3198 | |
3028 | - if (allowedTo('moderate_forum')) |
|
3029 | - $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
3199 | + if (allowedTo('moderate_forum')) { |
|
3200 | + $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
3201 | + } |
|
3030 | 3202 | |
3031 | 3203 | $context['user']['avatar'] = array(); |
3032 | 3204 | |
3033 | 3205 | // Check for gravatar first since we might be forcing them... |
3034 | 3206 | if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride'])) |
3035 | 3207 | { |
3036 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) |
|
3037 | - $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
3038 | - else |
|
3039 | - $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
3208 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) { |
|
3209 | + $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
3210 | + } else { |
|
3211 | + $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
3212 | + } |
|
3040 | 3213 | } |
3041 | 3214 | // Uploaded? |
3042 | - elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) |
|
3043 | - $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar'; |
|
3215 | + elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) { |
|
3216 | + $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar'; |
|
3217 | + } |
|
3044 | 3218 | // Full URL? |
3045 | - elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) |
|
3046 | - $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
3219 | + elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) { |
|
3220 | + $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
3221 | + } |
|
3047 | 3222 | // Otherwise we assume it's server stored. |
3048 | - elseif ($user_info['avatar']['url'] != '') |
|
3049 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
3223 | + elseif ($user_info['avatar']['url'] != '') { |
|
3224 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
3225 | + } |
|
3050 | 3226 | // No avatar at all? Fine, we have a big fat default avatar ;) |
3051 | - else |
|
3052 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
3227 | + else { |
|
3228 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
3229 | + } |
|
3053 | 3230 | |
3054 | - if (!empty($context['user']['avatar'])) |
|
3055 | - $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
3231 | + if (!empty($context['user']['avatar'])) { |
|
3232 | + $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
3233 | + } |
|
3056 | 3234 | |
3057 | 3235 | // Figure out how long they've been logged in. |
3058 | 3236 | $context['user']['total_time_logged_in'] = array( |
@@ -3060,8 +3238,7 @@ discard block |
||
3060 | 3238 | 'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600), |
3061 | 3239 | 'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60) |
3062 | 3240 | ); |
3063 | - } |
|
3064 | - else |
|
3241 | + } else |
|
3065 | 3242 | { |
3066 | 3243 | $context['user']['messages'] = 0; |
3067 | 3244 | $context['user']['unread_messages'] = 0; |
@@ -3069,12 +3246,14 @@ discard block |
||
3069 | 3246 | $context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0); |
3070 | 3247 | $context['user']['popup_messages'] = false; |
3071 | 3248 | |
3072 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) |
|
3073 | - $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
3249 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) { |
|
3250 | + $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
3251 | + } |
|
3074 | 3252 | |
3075 | 3253 | // If we've upgraded recently, go easy on the passwords. |
3076 | - if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) |
|
3077 | - $context['disable_login_hashing'] = true; |
|
3254 | + if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) { |
|
3255 | + $context['disable_login_hashing'] = true; |
|
3256 | + } |
|
3078 | 3257 | } |
3079 | 3258 | |
3080 | 3259 | // Setup the main menu items. |
@@ -3087,8 +3266,8 @@ discard block |
||
3087 | 3266 | $context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm'); |
3088 | 3267 | |
3089 | 3268 | // 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array. |
3090 | - if ($context['show_pm_popup']) |
|
3091 | - addInlineJavaScript(' |
|
3269 | + if ($context['show_pm_popup']) { |
|
3270 | + addInlineJavaScript(' |
|
3092 | 3271 | jQuery(document).ready(function($) { |
3093 | 3272 | new smc_Popup({ |
3094 | 3273 | heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ', |
@@ -3096,15 +3275,17 @@ discard block |
||
3096 | 3275 | icon_class: \'generic_icons mail_new\' |
3097 | 3276 | }); |
3098 | 3277 | });'); |
3278 | + } |
|
3099 | 3279 | |
3100 | 3280 | // Add a generic "Are you sure?" confirmation message. |
3101 | 3281 | addInlineJavaScript(' |
3102 | 3282 | var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';'); |
3103 | 3283 | |
3104 | 3284 | // Now add the capping code for avatars. |
3105 | - if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') |
|
3106 | - addInlineCss(' |
|
3285 | + if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') { |
|
3286 | + addInlineCss(' |
|
3107 | 3287 | img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }'); |
3288 | + } |
|
3108 | 3289 | |
3109 | 3290 | // This looks weird, but it's because BoardIndex.php references the variable. |
3110 | 3291 | $context['common_stats']['latest_member'] = array( |
@@ -3121,11 +3302,13 @@ discard block |
||
3121 | 3302 | ); |
3122 | 3303 | $context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']); |
3123 | 3304 | |
3124 | - if (empty($settings['theme_version'])) |
|
3125 | - addJavaScriptVar('smf_scripturl', $scripturl); |
|
3305 | + if (empty($settings['theme_version'])) { |
|
3306 | + addJavaScriptVar('smf_scripturl', $scripturl); |
|
3307 | + } |
|
3126 | 3308 | |
3127 | - if (!isset($context['page_title'])) |
|
3128 | - $context['page_title'] = ''; |
|
3309 | + if (!isset($context['page_title'])) { |
|
3310 | + $context['page_title'] = ''; |
|
3311 | + } |
|
3129 | 3312 | |
3130 | 3313 | // Set some specific vars. |
3131 | 3314 | $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
@@ -3135,21 +3318,23 @@ discard block |
||
3135 | 3318 | $context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']); |
3136 | 3319 | $context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']); |
3137 | 3320 | |
3138 | - if (!empty($context['meta_keywords'])) |
|
3139 | - $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
3321 | + if (!empty($context['meta_keywords'])) { |
|
3322 | + $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
3323 | + } |
|
3140 | 3324 | |
3141 | - if (!empty($context['canonical_url'])) |
|
3142 | - $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
3325 | + if (!empty($context['canonical_url'])) { |
|
3326 | + $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
3327 | + } |
|
3143 | 3328 | |
3144 | - if (!empty($settings['og_image'])) |
|
3145 | - $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
3329 | + if (!empty($settings['og_image'])) { |
|
3330 | + $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
3331 | + } |
|
3146 | 3332 | |
3147 | 3333 | if (!empty($context['meta_description'])) |
3148 | 3334 | { |
3149 | 3335 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']); |
3150 | 3336 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']); |
3151 | - } |
|
3152 | - else |
|
3337 | + } else |
|
3153 | 3338 | { |
3154 | 3339 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']); |
3155 | 3340 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']); |
@@ -3175,8 +3360,9 @@ discard block |
||
3175 | 3360 | $memory_needed = memoryReturnBytes($needed); |
3176 | 3361 | |
3177 | 3362 | // should we account for how much is currently being used? |
3178 | - if ($in_use) |
|
3179 | - $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
3363 | + if ($in_use) { |
|
3364 | + $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
3365 | + } |
|
3180 | 3366 | |
3181 | 3367 | // if more is needed, request it |
3182 | 3368 | if ($memory_current < $memory_needed) |
@@ -3199,8 +3385,9 @@ discard block |
||
3199 | 3385 | */ |
3200 | 3386 | function memoryReturnBytes($val) |
3201 | 3387 | { |
3202 | - if (is_integer($val)) |
|
3203 | - return $val; |
|
3388 | + if (is_integer($val)) { |
|
3389 | + return $val; |
|
3390 | + } |
|
3204 | 3391 | |
3205 | 3392 | // Separate the number from the designator |
3206 | 3393 | $val = trim($val); |
@@ -3236,10 +3423,11 @@ discard block |
||
3236 | 3423 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
3237 | 3424 | |
3238 | 3425 | // Are we debugging the template/html content? |
3239 | - if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) |
|
3240 | - header('Content-Type: application/xhtml+xml'); |
|
3241 | - elseif (!isset($_REQUEST['xml'])) |
|
3242 | - header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3426 | + if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) { |
|
3427 | + header('Content-Type: application/xhtml+xml'); |
|
3428 | + } elseif (!isset($_REQUEST['xml'])) { |
|
3429 | + header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3430 | + } |
|
3243 | 3431 | } |
3244 | 3432 | |
3245 | 3433 | header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
@@ -3248,8 +3436,9 @@ discard block |
||
3248 | 3436 | if ($context['in_maintenance'] && $context['user']['is_admin']) |
3249 | 3437 | { |
3250 | 3438 | $position = array_search('body', $context['template_layers']); |
3251 | - if ($position === false) |
|
3252 | - $position = array_search('main', $context['template_layers']); |
|
3439 | + if ($position === false) { |
|
3440 | + $position = array_search('main', $context['template_layers']); |
|
3441 | + } |
|
3253 | 3442 | |
3254 | 3443 | if ($position !== false) |
3255 | 3444 | { |
@@ -3277,15 +3466,15 @@ discard block |
||
3277 | 3466 | |
3278 | 3467 | foreach ($securityFiles as $i => $securityFile) |
3279 | 3468 | { |
3280 | - if (!file_exists($boarddir . '/' . $securityFile)) |
|
3281 | - unset($securityFiles[$i]); |
|
3469 | + if (!file_exists($boarddir . '/' . $securityFile)) { |
|
3470 | + unset($securityFiles[$i]); |
|
3471 | + } |
|
3282 | 3472 | } |
3283 | 3473 | |
3284 | 3474 | // We are already checking so many files...just few more doesn't make any difference! :P |
3285 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
3286 | - $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
3287 | - |
|
3288 | - else |
|
3475 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
3476 | + $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
3477 | + } else |
|
3289 | 3478 | { |
3290 | 3479 | $path = $modSettings['attachmentUploadDir']; |
3291 | 3480 | $id_folder_thumb = 1; |
@@ -3294,8 +3483,9 @@ discard block |
||
3294 | 3483 | secureDirectory($cachedir); |
3295 | 3484 | |
3296 | 3485 | // If agreement is enabled, at least the english version shall exists |
3297 | - if ($modSettings['requireAgreement']) |
|
3298 | - $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
3486 | + if ($modSettings['requireAgreement']) { |
|
3487 | + $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
3488 | + } |
|
3299 | 3489 | |
3300 | 3490 | if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement)) |
3301 | 3491 | { |
@@ -3310,18 +3500,21 @@ discard block |
||
3310 | 3500 | echo ' |
3311 | 3501 | ', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>'; |
3312 | 3502 | |
3313 | - if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') |
|
3314 | - echo ' |
|
3503 | + if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') { |
|
3504 | + echo ' |
|
3315 | 3505 | ', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>'; |
3506 | + } |
|
3316 | 3507 | } |
3317 | 3508 | |
3318 | - if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) |
|
3319 | - echo ' |
|
3509 | + if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) { |
|
3510 | + echo ' |
|
3320 | 3511 | <strong>', $txt['cache_writable'], '</strong><br>'; |
3512 | + } |
|
3321 | 3513 | |
3322 | - if (!empty($agreement)) |
|
3323 | - echo ' |
|
3514 | + if (!empty($agreement)) { |
|
3515 | + echo ' |
|
3324 | 3516 | <strong>', $txt['agreement_missing'], '</strong><br>'; |
3517 | + } |
|
3325 | 3518 | |
3326 | 3519 | echo ' |
3327 | 3520 | </p> |
@@ -3336,16 +3529,18 @@ discard block |
||
3336 | 3529 | <div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;"> |
3337 | 3530 | ', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']); |
3338 | 3531 | |
3339 | - if (!empty($_SESSION['ban']['cannot_post']['reason'])) |
|
3340 | - echo ' |
|
3532 | + if (!empty($_SESSION['ban']['cannot_post']['reason'])) { |
|
3533 | + echo ' |
|
3341 | 3534 | <div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>'; |
3535 | + } |
|
3342 | 3536 | |
3343 | - if (!empty($_SESSION['ban']['expire_time'])) |
|
3344 | - echo ' |
|
3537 | + if (!empty($_SESSION['ban']['expire_time'])) { |
|
3538 | + echo ' |
|
3345 | 3539 | <div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>'; |
3346 | - else |
|
3347 | - echo ' |
|
3540 | + } else { |
|
3541 | + echo ' |
|
3348 | 3542 | <div>', $txt['your_ban_expires_never'], '</div>'; |
3543 | + } |
|
3349 | 3544 | |
3350 | 3545 | echo ' |
3351 | 3546 | </div>'; |
@@ -3361,8 +3556,9 @@ discard block |
||
3361 | 3556 | global $forum_copyright, $software_year, $forum_version; |
3362 | 3557 | |
3363 | 3558 | // Don't display copyright for things like SSI. |
3364 | - if (!isset($forum_version) || !isset($software_year)) |
|
3365 | - return; |
|
3559 | + if (!isset($forum_version) || !isset($software_year)) { |
|
3560 | + return; |
|
3561 | + } |
|
3366 | 3562 | |
3367 | 3563 | // Put in the version... |
3368 | 3564 | printf($forum_copyright, $forum_version, $software_year); |
@@ -3380,9 +3576,10 @@ discard block |
||
3380 | 3576 | $context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3)); |
3381 | 3577 | $context['load_queries'] = $db_count; |
3382 | 3578 | |
3383 | - foreach (array_reverse($context['template_layers']) as $layer) |
|
3384 | - loadSubTemplate($layer . '_below', true); |
|
3385 | -} |
|
3579 | + foreach (array_reverse($context['template_layers']) as $layer) { |
|
3580 | + loadSubTemplate($layer . '_below', true); |
|
3581 | + } |
|
3582 | + } |
|
3386 | 3583 | |
3387 | 3584 | /** |
3388 | 3585 | * Output the Javascript files |
@@ -3413,8 +3610,7 @@ discard block |
||
3413 | 3610 | { |
3414 | 3611 | echo ' |
3415 | 3612 | var ', $key, ';'; |
3416 | - } |
|
3417 | - else |
|
3613 | + } else |
|
3418 | 3614 | { |
3419 | 3615 | echo ' |
3420 | 3616 | var ', $key, ' = ', $value, ';'; |
@@ -3429,26 +3625,27 @@ discard block |
||
3429 | 3625 | foreach ($context['javascript_files'] as $id => $js_file) |
3430 | 3626 | { |
3431 | 3627 | // Last minute call! allow theme authors to disable single files. |
3432 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
3433 | - continue; |
|
3628 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
3629 | + continue; |
|
3630 | + } |
|
3434 | 3631 | |
3435 | 3632 | // By default all files don't get minimized unless the file explicitly says so! |
3436 | 3633 | if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
3437 | 3634 | { |
3438 | - if ($do_deferred && !empty($js_file['options']['defer'])) |
|
3439 | - $toMinifyDefer[] = $js_file; |
|
3440 | - |
|
3441 | - elseif (!$do_deferred && empty($js_file['options']['defer'])) |
|
3442 | - $toMinify[] = $js_file; |
|
3635 | + if ($do_deferred && !empty($js_file['options']['defer'])) { |
|
3636 | + $toMinifyDefer[] = $js_file; |
|
3637 | + } elseif (!$do_deferred && empty($js_file['options']['defer'])) { |
|
3638 | + $toMinify[] = $js_file; |
|
3639 | + } |
|
3443 | 3640 | |
3444 | 3641 | // Grab a random seed. |
3445 | - if (!isset($minSeed)) |
|
3446 | - $minSeed = $js_file['options']['seed']; |
|
3447 | - } |
|
3448 | - |
|
3449 | - elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) |
|
3450 | - echo ' |
|
3642 | + if (!isset($minSeed)) { |
|
3643 | + $minSeed = $js_file['options']['seed']; |
|
3644 | + } |
|
3645 | + } elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) { |
|
3646 | + echo ' |
|
3451 | 3647 | <script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>'; |
3648 | + } |
|
3452 | 3649 | } |
3453 | 3650 | |
3454 | 3651 | if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer))) |
@@ -3456,14 +3653,14 @@ discard block |
||
3456 | 3653 | $result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred); |
3457 | 3654 | |
3458 | 3655 | // Minify process couldn't work, print each individual files. |
3459 | - if (!empty($result) && is_array($result)) |
|
3460 | - foreach ($result as $minFailedFile) |
|
3656 | + if (!empty($result) && is_array($result)) { |
|
3657 | + foreach ($result as $minFailedFile) |
|
3461 | 3658 | echo ' |
3462 | 3659 | <script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>'; |
3463 | - |
|
3464 | - else |
|
3465 | - echo ' |
|
3660 | + } else { |
|
3661 | + echo ' |
|
3466 | 3662 | <script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>'; |
3663 | + } |
|
3467 | 3664 | } |
3468 | 3665 | |
3469 | 3666 | // Inline JavaScript - Actually useful some times! |
@@ -3474,8 +3671,9 @@ discard block |
||
3474 | 3671 | echo ' |
3475 | 3672 | <script>'; |
3476 | 3673 | |
3477 | - foreach ($context['javascript_inline']['defer'] as $js_code) |
|
3478 | - echo $js_code; |
|
3674 | + foreach ($context['javascript_inline']['defer'] as $js_code) { |
|
3675 | + echo $js_code; |
|
3676 | + } |
|
3479 | 3677 | |
3480 | 3678 | echo ' |
3481 | 3679 | </script>'; |
@@ -3486,8 +3684,9 @@ discard block |
||
3486 | 3684 | echo ' |
3487 | 3685 | <script>'; |
3488 | 3686 | |
3489 | - foreach ($context['javascript_inline']['standard'] as $js_code) |
|
3490 | - echo $js_code; |
|
3687 | + foreach ($context['javascript_inline']['standard'] as $js_code) { |
|
3688 | + echo $js_code; |
|
3689 | + } |
|
3491 | 3690 | |
3492 | 3691 | echo ' |
3493 | 3692 | </script>'; |
@@ -3512,8 +3711,9 @@ discard block |
||
3512 | 3711 | foreach ($context['css_files'] as $id => $file) |
3513 | 3712 | { |
3514 | 3713 | // Last minute call! allow theme authors to disable single files. |
3515 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
3516 | - continue; |
|
3714 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
3715 | + continue; |
|
3716 | + } |
|
3517 | 3717 | |
3518 | 3718 | // By default all files don't get minimized unless the file explicitly says so! |
3519 | 3719 | if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
@@ -3521,12 +3721,12 @@ discard block |
||
3521 | 3721 | $toMinify[] = $file; |
3522 | 3722 | |
3523 | 3723 | // Grab a random seed. |
3524 | - if (!isset($minSeed)) |
|
3525 | - $minSeed = $file['options']['seed']; |
|
3724 | + if (!isset($minSeed)) { |
|
3725 | + $minSeed = $file['options']['seed']; |
|
3726 | + } |
|
3727 | + } else { |
|
3728 | + $normal[] = $file['fileUrl']; |
|
3526 | 3729 | } |
3527 | - |
|
3528 | - else |
|
3529 | - $normal[] = $file['fileUrl']; |
|
3530 | 3730 | } |
3531 | 3731 | |
3532 | 3732 | if (!empty($toMinify)) |
@@ -3534,28 +3734,30 @@ discard block |
||
3534 | 3734 | $result = custMinify($toMinify, 'css'); |
3535 | 3735 | |
3536 | 3736 | // Minify process couldn't work, print each individual files. |
3537 | - if (!empty($result) && is_array($result)) |
|
3538 | - foreach ($result as $minFailedFile) |
|
3737 | + if (!empty($result) && is_array($result)) { |
|
3738 | + foreach ($result as $minFailedFile) |
|
3539 | 3739 | echo ' |
3540 | 3740 | <link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">'; |
3541 | - |
|
3542 | - else |
|
3543 | - echo ' |
|
3741 | + } else { |
|
3742 | + echo ' |
|
3544 | 3743 | <link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">'; |
3744 | + } |
|
3545 | 3745 | } |
3546 | 3746 | |
3547 | 3747 | // Print the rest after the minified files. |
3548 | - if (!empty($normal)) |
|
3549 | - foreach ($normal as $nf) |
|
3748 | + if (!empty($normal)) { |
|
3749 | + foreach ($normal as $nf) |
|
3550 | 3750 | echo ' |
3551 | 3751 | <link rel="stylesheet" href="', $nf ,'">'; |
3752 | + } |
|
3552 | 3753 | |
3553 | 3754 | if ($db_show_debug === true) |
3554 | 3755 | { |
3555 | 3756 | // Try to keep only what's useful. |
3556 | 3757 | $repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => ''); |
3557 | - foreach ($context['css_files'] as $file) |
|
3558 | - $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
3758 | + foreach ($context['css_files'] as $file) { |
|
3759 | + $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
3760 | + } |
|
3559 | 3761 | } |
3560 | 3762 | |
3561 | 3763 | if (!empty($context['css_header'])) |
@@ -3563,9 +3765,10 @@ discard block |
||
3563 | 3765 | echo ' |
3564 | 3766 | <style>'; |
3565 | 3767 | |
3566 | - foreach ($context['css_header'] as $css) |
|
3567 | - echo $css .' |
|
3768 | + foreach ($context['css_header'] as $css) { |
|
3769 | + echo $css .' |
|
3568 | 3770 | '; |
3771 | + } |
|
3569 | 3772 | |
3570 | 3773 | echo' |
3571 | 3774 | </style>'; |
@@ -3590,15 +3793,17 @@ discard block |
||
3590 | 3793 | $data = !empty($data) ? $data : false; |
3591 | 3794 | $minFailed = array(); |
3592 | 3795 | |
3593 | - if (empty($type) || empty($data)) |
|
3594 | - return false; |
|
3796 | + if (empty($type) || empty($data)) { |
|
3797 | + return false; |
|
3798 | + } |
|
3595 | 3799 | |
3596 | 3800 | // Did we already did this? |
3597 | 3801 | $toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400); |
3598 | 3802 | |
3599 | 3803 | // Already done? |
3600 | - if (!empty($toCache)) |
|
3601 | - return true; |
|
3804 | + if (!empty($toCache)) { |
|
3805 | + return true; |
|
3806 | + } |
|
3602 | 3807 | |
3603 | 3808 | // Yep, need a bunch of files. |
3604 | 3809 | require_once($sourcedir . '/minify/src/Minify.php'); |
@@ -3686,8 +3891,9 @@ discard block |
||
3686 | 3891 | global $modSettings, $smcFunc; |
3687 | 3892 | |
3688 | 3893 | // Just make up a nice hash... |
3689 | - if ($new) |
|
3690 | - return sha1(md5($filename . time()) . mt_rand()); |
|
3894 | + if ($new) { |
|
3895 | + return sha1(md5($filename . time()) . mt_rand()); |
|
3896 | + } |
|
3691 | 3897 | |
3692 | 3898 | // Grab the file hash if it wasn't added. |
3693 | 3899 | // Left this for legacy. |
@@ -3701,23 +3907,25 @@ discard block |
||
3701 | 3907 | 'id_attach' => $attachment_id, |
3702 | 3908 | )); |
3703 | 3909 | |
3704 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
3705 | - return false; |
|
3910 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
3911 | + return false; |
|
3912 | + } |
|
3706 | 3913 | |
3707 | 3914 | list ($file_hash) = $smcFunc['db_fetch_row']($request); |
3708 | 3915 | $smcFunc['db_free_result']($request); |
3709 | 3916 | } |
3710 | 3917 | |
3711 | 3918 | // Still no hash? mmm... |
3712 | - if (empty($file_hash)) |
|
3713 | - $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
3919 | + if (empty($file_hash)) { |
|
3920 | + $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
3921 | + } |
|
3714 | 3922 | |
3715 | 3923 | // Are we using multiple directories? |
3716 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
3717 | - $path = $modSettings['attachmentUploadDir'][$dir]; |
|
3718 | - |
|
3719 | - else |
|
3720 | - $path = $modSettings['attachmentUploadDir']; |
|
3924 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
3925 | + $path = $modSettings['attachmentUploadDir'][$dir]; |
|
3926 | + } else { |
|
3927 | + $path = $modSettings['attachmentUploadDir']; |
|
3928 | + } |
|
3721 | 3929 | |
3722 | 3930 | return $path . '/' . $attachment_id . '_' . $file_hash .'.dat'; |
3723 | 3931 | } |
@@ -3732,8 +3940,9 @@ discard block |
||
3732 | 3940 | function ip2range($fullip) |
3733 | 3941 | { |
3734 | 3942 | // Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.) |
3735 | - if ($fullip == 'unknown') |
|
3736 | - $fullip = '255.255.255.255'; |
|
3943 | + if ($fullip == 'unknown') { |
|
3944 | + $fullip = '255.255.255.255'; |
|
3945 | + } |
|
3737 | 3946 | |
3738 | 3947 | $ip_parts = explode('-', $fullip); |
3739 | 3948 | $ip_array = array(); |
@@ -3757,10 +3966,11 @@ discard block |
||
3757 | 3966 | $ip_array['low'] = $ip_parts[0]; |
3758 | 3967 | $ip_array['high'] = $ip_parts[1]; |
3759 | 3968 | return $ip_array; |
3760 | - } |
|
3761 | - elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.* |
|
3969 | + } elseif (count($ip_parts) == 2) { |
|
3970 | + // if ip 22.22.*-22.22.* |
|
3762 | 3971 | { |
3763 | 3972 | $valid_low = isValidIP($ip_parts[0]); |
3973 | + } |
|
3764 | 3974 | $valid_high = isValidIP($ip_parts[1]); |
3765 | 3975 | $count = 0; |
3766 | 3976 | $mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.'); |
@@ -3775,7 +3985,9 @@ discard block |
||
3775 | 3985 | $ip_parts[0] .= $mode . $min; |
3776 | 3986 | $valid_low = isValidIP($ip_parts[0]); |
3777 | 3987 | $count++; |
3778 | - if ($count > 9) break; |
|
3988 | + if ($count > 9) { |
|
3989 | + break; |
|
3990 | + } |
|
3779 | 3991 | } |
3780 | 3992 | } |
3781 | 3993 | |
@@ -3789,7 +4001,9 @@ discard block |
||
3789 | 4001 | $ip_parts[1] .= $mode . $max; |
3790 | 4002 | $valid_high = isValidIP($ip_parts[1]); |
3791 | 4003 | $count++; |
3792 | - if ($count > 9) break; |
|
4004 | + if ($count > 9) { |
|
4005 | + break; |
|
4006 | + } |
|
3793 | 4007 | } |
3794 | 4008 | } |
3795 | 4009 | |
@@ -3814,46 +4028,54 @@ discard block |
||
3814 | 4028 | { |
3815 | 4029 | global $modSettings; |
3816 | 4030 | |
3817 | - if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) |
|
3818 | - return $host; |
|
4031 | + if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) { |
|
4032 | + return $host; |
|
4033 | + } |
|
3819 | 4034 | $t = microtime(); |
3820 | 4035 | |
3821 | 4036 | // Try the Linux host command, perhaps? |
3822 | 4037 | if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1) |
3823 | 4038 | { |
3824 | - if (!isset($modSettings['host_to_dis'])) |
|
3825 | - $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
3826 | - else |
|
3827 | - $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
4039 | + if (!isset($modSettings['host_to_dis'])) { |
|
4040 | + $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
4041 | + } else { |
|
4042 | + $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
4043 | + } |
|
3828 | 4044 | |
3829 | 4045 | // Did host say it didn't find anything? |
3830 | - if (strpos($test, 'not found') !== false) |
|
3831 | - $host = ''; |
|
4046 | + if (strpos($test, 'not found') !== false) { |
|
4047 | + $host = ''; |
|
4048 | + } |
|
3832 | 4049 | // Invalid server option? |
3833 | - elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) |
|
3834 | - updateSettings(array('host_to_dis' => 1)); |
|
4050 | + elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) { |
|
4051 | + updateSettings(array('host_to_dis' => 1)); |
|
4052 | + } |
|
3835 | 4053 | // Maybe it found something, after all? |
3836 | - elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) |
|
3837 | - $host = $match[1]; |
|
4054 | + elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) { |
|
4055 | + $host = $match[1]; |
|
4056 | + } |
|
3838 | 4057 | } |
3839 | 4058 | |
3840 | 4059 | // This is nslookup; usually only Windows, but possibly some Unix? |
3841 | 4060 | if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1) |
3842 | 4061 | { |
3843 | 4062 | $test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip)); |
3844 | - if (strpos($test, 'Non-existent domain') !== false) |
|
3845 | - $host = ''; |
|
3846 | - elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) |
|
3847 | - $host = $match[1]; |
|
4063 | + if (strpos($test, 'Non-existent domain') !== false) { |
|
4064 | + $host = ''; |
|
4065 | + } elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) { |
|
4066 | + $host = $match[1]; |
|
4067 | + } |
|
3848 | 4068 | } |
3849 | 4069 | |
3850 | 4070 | // This is the last try :/. |
3851 | - if (!isset($host) || $host === false) |
|
3852 | - $host = @gethostbyaddr($ip); |
|
4071 | + if (!isset($host) || $host === false) { |
|
4072 | + $host = @gethostbyaddr($ip); |
|
4073 | + } |
|
3853 | 4074 | |
3854 | 4075 | // It took a long time, so let's cache it! |
3855 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) |
|
3856 | - cache_put_data('hostlookup-' . $ip, $host, 600); |
|
4076 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) { |
|
4077 | + cache_put_data('hostlookup-' . $ip, $host, 600); |
|
4078 | + } |
|
3857 | 4079 | |
3858 | 4080 | return $host; |
3859 | 4081 | } |
@@ -3889,20 +4111,21 @@ discard block |
||
3889 | 4111 | { |
3890 | 4112 | $encrypted = substr(crypt($word, 'uk'), 2, $max_chars); |
3891 | 4113 | $total = 0; |
3892 | - for ($i = 0; $i < $max_chars; $i++) |
|
3893 | - $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
4114 | + for ($i = 0; $i < $max_chars; $i++) { |
|
4115 | + $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
4116 | + } |
|
3894 | 4117 | $returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total; |
3895 | 4118 | } |
3896 | 4119 | } |
3897 | 4120 | return array_unique($returned_ints); |
3898 | - } |
|
3899 | - else |
|
4121 | + } else |
|
3900 | 4122 | { |
3901 | 4123 | // Trim characters before and after and add slashes for database insertion. |
3902 | 4124 | $returned_words = array(); |
3903 | - foreach ($words as $word) |
|
3904 | - if (($word = trim($word, '-_\'')) !== '') |
|
4125 | + foreach ($words as $word) { |
|
4126 | + if (($word = trim($word, '-_\'')) !== '') |
|
3905 | 4127 | $returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars); |
4128 | + } |
|
3906 | 4129 | |
3907 | 4130 | // Filter out all words that occur more than once. |
3908 | 4131 | return array_unique($returned_words); |
@@ -3924,16 +4147,18 @@ discard block |
||
3924 | 4147 | global $settings, $txt; |
3925 | 4148 | |
3926 | 4149 | // Does the current loaded theme have this and we are not forcing the usage of this function? |
3927 | - if (function_exists('template_create_button') && !$force_use) |
|
3928 | - return template_create_button($name, $alt, $label = '', $custom = ''); |
|
4150 | + if (function_exists('template_create_button') && !$force_use) { |
|
4151 | + return template_create_button($name, $alt, $label = '', $custom = ''); |
|
4152 | + } |
|
3929 | 4153 | |
3930 | - if (!$settings['use_image_buttons']) |
|
3931 | - return $txt[$alt]; |
|
3932 | - elseif (!empty($settings['use_buttons'])) |
|
3933 | - return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
3934 | - else |
|
3935 | - return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
3936 | -} |
|
4154 | + if (!$settings['use_image_buttons']) { |
|
4155 | + return $txt[$alt]; |
|
4156 | + } elseif (!empty($settings['use_buttons'])) { |
|
4157 | + return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
4158 | + } else { |
|
4159 | + return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
4160 | + } |
|
4161 | + } |
|
3937 | 4162 | |
3938 | 4163 | /** |
3939 | 4164 | * Sets up all of the top menu buttons |
@@ -3976,9 +4201,10 @@ discard block |
||
3976 | 4201 | var user_menus = new smc_PopupMenu(); |
3977 | 4202 | user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup"); |
3978 | 4203 | user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true); |
3979 | - if ($context['allow_pm']) |
|
3980 | - addInlineJavaScript(' |
|
4204 | + if ($context['allow_pm']) { |
|
4205 | + addInlineJavaScript(' |
|
3981 | 4206 | user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true); |
4207 | + } |
|
3982 | 4208 | |
3983 | 4209 | if (!empty($modSettings['enable_ajax_alerts'])) |
3984 | 4210 | { |
@@ -4138,88 +4364,96 @@ discard block |
||
4138 | 4364 | |
4139 | 4365 | // Now we put the buttons in the context so the theme can use them. |
4140 | 4366 | $menu_buttons = array(); |
4141 | - foreach ($buttons as $act => $button) |
|
4142 | - if (!empty($button['show'])) |
|
4367 | + foreach ($buttons as $act => $button) { |
|
4368 | + if (!empty($button['show'])) |
|
4143 | 4369 | { |
4144 | 4370 | $button['active_button'] = false; |
4371 | + } |
|
4145 | 4372 | |
4146 | 4373 | // This button needs some action. |
4147 | - if (isset($button['action_hook'])) |
|
4148 | - $needs_action_hook = true; |
|
4374 | + if (isset($button['action_hook'])) { |
|
4375 | + $needs_action_hook = true; |
|
4376 | + } |
|
4149 | 4377 | |
4150 | 4378 | // Make sure the last button truly is the last button. |
4151 | 4379 | if (!empty($button['is_last'])) |
4152 | 4380 | { |
4153 | - if (isset($last_button)) |
|
4154 | - unset($menu_buttons[$last_button]['is_last']); |
|
4381 | + if (isset($last_button)) { |
|
4382 | + unset($menu_buttons[$last_button]['is_last']); |
|
4383 | + } |
|
4155 | 4384 | $last_button = $act; |
4156 | 4385 | } |
4157 | 4386 | |
4158 | 4387 | // Go through the sub buttons if there are any. |
4159 | - if (!empty($button['sub_buttons'])) |
|
4160 | - foreach ($button['sub_buttons'] as $key => $subbutton) |
|
4388 | + if (!empty($button['sub_buttons'])) { |
|
4389 | + foreach ($button['sub_buttons'] as $key => $subbutton) |
|
4161 | 4390 | { |
4162 | 4391 | if (empty($subbutton['show'])) |
4163 | 4392 | unset($button['sub_buttons'][$key]); |
4393 | + } |
|
4164 | 4394 | |
4165 | 4395 | // 2nd level sub buttons next... |
4166 | 4396 | if (!empty($subbutton['sub_buttons'])) |
4167 | 4397 | { |
4168 | 4398 | foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2) |
4169 | 4399 | { |
4170 | - if (empty($sub_button2['show'])) |
|
4171 | - unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
4400 | + if (empty($sub_button2['show'])) { |
|
4401 | + unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
4402 | + } |
|
4172 | 4403 | } |
4173 | 4404 | } |
4174 | 4405 | } |
4175 | 4406 | |
4176 | 4407 | // Does this button have its own icon? |
4177 | - if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) |
|
4178 | - $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4179 | - elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) |
|
4180 | - $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4181 | - elseif (isset($button['icon'])) |
|
4182 | - $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
4183 | - else |
|
4184 | - $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
4408 | + if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) { |
|
4409 | + $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4410 | + } elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) { |
|
4411 | + $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4412 | + } elseif (isset($button['icon'])) { |
|
4413 | + $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
4414 | + } else { |
|
4415 | + $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
4416 | + } |
|
4185 | 4417 | |
4186 | 4418 | $menu_buttons[$act] = $button; |
4187 | 4419 | } |
4188 | 4420 | |
4189 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
4190 | - cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
4421 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
4422 | + cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
4423 | + } |
|
4191 | 4424 | } |
4192 | 4425 | |
4193 | 4426 | $context['menu_buttons'] = $menu_buttons; |
4194 | 4427 | |
4195 | 4428 | // Logging out requires the session id in the url. |
4196 | - if (isset($context['menu_buttons']['logout'])) |
|
4197 | - $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
4429 | + if (isset($context['menu_buttons']['logout'])) { |
|
4430 | + $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
4431 | + } |
|
4198 | 4432 | |
4199 | 4433 | // Figure out which action we are doing so we can set the active tab. |
4200 | 4434 | // Default to home. |
4201 | 4435 | $current_action = 'home'; |
4202 | 4436 | |
4203 | - if (isset($context['menu_buttons'][$context['current_action']])) |
|
4204 | - $current_action = $context['current_action']; |
|
4205 | - elseif ($context['current_action'] == 'search2') |
|
4206 | - $current_action = 'search'; |
|
4207 | - elseif ($context['current_action'] == 'theme') |
|
4208 | - $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
4209 | - elseif ($context['current_action'] == 'register2') |
|
4210 | - $current_action = 'register'; |
|
4211 | - elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) |
|
4212 | - $current_action = 'login'; |
|
4213 | - elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) |
|
4214 | - $current_action = 'moderate'; |
|
4437 | + if (isset($context['menu_buttons'][$context['current_action']])) { |
|
4438 | + $current_action = $context['current_action']; |
|
4439 | + } elseif ($context['current_action'] == 'search2') { |
|
4440 | + $current_action = 'search'; |
|
4441 | + } elseif ($context['current_action'] == 'theme') { |
|
4442 | + $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
4443 | + } elseif ($context['current_action'] == 'register2') { |
|
4444 | + $current_action = 'register'; |
|
4445 | + } elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) { |
|
4446 | + $current_action = 'login'; |
|
4447 | + } elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) { |
|
4448 | + $current_action = 'moderate'; |
|
4449 | + } |
|
4215 | 4450 | |
4216 | 4451 | // There are certain exceptions to the above where we don't want anything on the menu highlighted. |
4217 | 4452 | if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner'])) |
4218 | 4453 | { |
4219 | 4454 | $current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile'; |
4220 | 4455 | $context[$current_action] = true; |
4221 | - } |
|
4222 | - elseif ($context['current_action'] == 'pm') |
|
4456 | + } elseif ($context['current_action'] == 'pm') |
|
4223 | 4457 | { |
4224 | 4458 | $current_action = 'self_pm'; |
4225 | 4459 | $context['self_pm'] = true; |
@@ -4262,12 +4496,14 @@ discard block |
||
4262 | 4496 | } |
4263 | 4497 | |
4264 | 4498 | // Not all actions are simple. |
4265 | - if (!empty($needs_action_hook)) |
|
4266 | - call_integration_hook('integrate_current_action', array(&$current_action)); |
|
4499 | + if (!empty($needs_action_hook)) { |
|
4500 | + call_integration_hook('integrate_current_action', array(&$current_action)); |
|
4501 | + } |
|
4267 | 4502 | |
4268 | - if (isset($context['menu_buttons'][$current_action])) |
|
4269 | - $context['menu_buttons'][$current_action]['active_button'] = true; |
|
4270 | -} |
|
4503 | + if (isset($context['menu_buttons'][$current_action])) { |
|
4504 | + $context['menu_buttons'][$current_action]['active_button'] = true; |
|
4505 | + } |
|
4506 | + } |
|
4271 | 4507 | |
4272 | 4508 | /** |
4273 | 4509 | * Generate a random seed and ensure it's stored in settings. |
@@ -4291,16 +4527,19 @@ discard block |
||
4291 | 4527 | global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug; |
4292 | 4528 | global $context, $txt; |
4293 | 4529 | |
4294 | - if ($db_show_debug === true) |
|
4295 | - $context['debug']['hooks'][] = $hook; |
|
4530 | + if ($db_show_debug === true) { |
|
4531 | + $context['debug']['hooks'][] = $hook; |
|
4532 | + } |
|
4296 | 4533 | |
4297 | 4534 | // Need to have some control. |
4298 | - if (!isset($context['instances'])) |
|
4299 | - $context['instances'] = array(); |
|
4535 | + if (!isset($context['instances'])) { |
|
4536 | + $context['instances'] = array(); |
|
4537 | + } |
|
4300 | 4538 | |
4301 | 4539 | $results = array(); |
4302 | - if (empty($modSettings[$hook])) |
|
4303 | - return $results; |
|
4540 | + if (empty($modSettings[$hook])) { |
|
4541 | + return $results; |
|
4542 | + } |
|
4304 | 4543 | |
4305 | 4544 | // Define some needed vars. |
4306 | 4545 | $function = false; |
@@ -4310,14 +4549,16 @@ discard block |
||
4310 | 4549 | foreach ($functions as $function) |
4311 | 4550 | { |
4312 | 4551 | // Hook has been marked as "disabled". Skip it! |
4313 | - if (strpos($function, '!') !== false) |
|
4314 | - continue; |
|
4552 | + if (strpos($function, '!') !== false) { |
|
4553 | + continue; |
|
4554 | + } |
|
4315 | 4555 | |
4316 | 4556 | $call = call_helper($function, true); |
4317 | 4557 | |
4318 | 4558 | // Is it valid? |
4319 | - if (!empty($call)) |
|
4320 | - $results[$function] = call_user_func_array($call, $parameters); |
|
4559 | + if (!empty($call)) { |
|
4560 | + $results[$function] = call_user_func_array($call, $parameters); |
|
4561 | + } |
|
4321 | 4562 | |
4322 | 4563 | // Whatever it was suppose to call, it failed :( |
4323 | 4564 | elseif (!empty($function)) |
@@ -4333,8 +4574,9 @@ discard block |
||
4333 | 4574 | } |
4334 | 4575 | |
4335 | 4576 | // "Assume" the file resides on $boarddir somewhere... |
4336 | - else |
|
4337 | - log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
4577 | + else { |
|
4578 | + log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
4579 | + } |
|
4338 | 4580 | } |
4339 | 4581 | } |
4340 | 4582 | |
@@ -4356,12 +4598,14 @@ discard block |
||
4356 | 4598 | global $smcFunc, $modSettings; |
4357 | 4599 | |
4358 | 4600 | // Any objects? |
4359 | - if ($object) |
|
4360 | - $function = $function . '#'; |
|
4601 | + if ($object) { |
|
4602 | + $function = $function . '#'; |
|
4603 | + } |
|
4361 | 4604 | |
4362 | 4605 | // Any files to load? |
4363 | - if (!empty($file) && is_string($file)) |
|
4364 | - $function = $file . (!empty($function) ? '|' . $function : ''); |
|
4606 | + if (!empty($file) && is_string($file)) { |
|
4607 | + $function = $file . (!empty($function) ? '|' . $function : ''); |
|
4608 | + } |
|
4365 | 4609 | |
4366 | 4610 | // Get the correct string. |
4367 | 4611 | $integration_call = $function; |
@@ -4383,13 +4627,14 @@ discard block |
||
4383 | 4627 | if (!empty($current_functions)) |
4384 | 4628 | { |
4385 | 4629 | $current_functions = explode(',', $current_functions); |
4386 | - if (in_array($integration_call, $current_functions)) |
|
4387 | - return; |
|
4630 | + if (in_array($integration_call, $current_functions)) { |
|
4631 | + return; |
|
4632 | + } |
|
4388 | 4633 | |
4389 | 4634 | $permanent_functions = array_merge($current_functions, array($integration_call)); |
4635 | + } else { |
|
4636 | + $permanent_functions = array($integration_call); |
|
4390 | 4637 | } |
4391 | - else |
|
4392 | - $permanent_functions = array($integration_call); |
|
4393 | 4638 | |
4394 | 4639 | updateSettings(array($hook => implode(',', $permanent_functions))); |
4395 | 4640 | } |
@@ -4398,8 +4643,9 @@ discard block |
||
4398 | 4643 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
4399 | 4644 | |
4400 | 4645 | // Do nothing, if it's already there. |
4401 | - if (in_array($integration_call, $functions)) |
|
4402 | - return; |
|
4646 | + if (in_array($integration_call, $functions)) { |
|
4647 | + return; |
|
4648 | + } |
|
4403 | 4649 | |
4404 | 4650 | $functions[] = $integration_call; |
4405 | 4651 | $modSettings[$hook] = implode(',', $functions); |
@@ -4422,12 +4668,14 @@ discard block |
||
4422 | 4668 | global $smcFunc, $modSettings; |
4423 | 4669 | |
4424 | 4670 | // Any objects? |
4425 | - if ($object) |
|
4426 | - $function = $function . '#'; |
|
4671 | + if ($object) { |
|
4672 | + $function = $function . '#'; |
|
4673 | + } |
|
4427 | 4674 | |
4428 | 4675 | // Any files to load? |
4429 | - if (!empty($file) && is_string($file)) |
|
4430 | - $function = $file . '|' . $function; |
|
4676 | + if (!empty($file) && is_string($file)) { |
|
4677 | + $function = $file . '|' . $function; |
|
4678 | + } |
|
4431 | 4679 | |
4432 | 4680 | // Get the correct string. |
4433 | 4681 | $integration_call = $function; |
@@ -4448,16 +4696,18 @@ discard block |
||
4448 | 4696 | { |
4449 | 4697 | $current_functions = explode(',', $current_functions); |
4450 | 4698 | |
4451 | - if (in_array($integration_call, $current_functions)) |
|
4452 | - updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
4699 | + if (in_array($integration_call, $current_functions)) { |
|
4700 | + updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
4701 | + } |
|
4453 | 4702 | } |
4454 | 4703 | |
4455 | 4704 | // Turn the function list into something usable. |
4456 | 4705 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
4457 | 4706 | |
4458 | 4707 | // You can only remove it if it's available. |
4459 | - if (!in_array($integration_call, $functions)) |
|
4460 | - return; |
|
4708 | + if (!in_array($integration_call, $functions)) { |
|
4709 | + return; |
|
4710 | + } |
|
4461 | 4711 | |
4462 | 4712 | $functions = array_diff($functions, array($integration_call)); |
4463 | 4713 | $modSettings[$hook] = implode(',', $functions); |
@@ -4478,17 +4728,20 @@ discard block |
||
4478 | 4728 | global $context, $smcFunc, $txt, $db_show_debug; |
4479 | 4729 | |
4480 | 4730 | // Really? |
4481 | - if (empty($string)) |
|
4482 | - return false; |
|
4731 | + if (empty($string)) { |
|
4732 | + return false; |
|
4733 | + } |
|
4483 | 4734 | |
4484 | 4735 | // An array? should be a "callable" array IE array(object/class, valid_callable). |
4485 | 4736 | // A closure? should be a callable one. |
4486 | - if (is_array($string) || $string instanceof Closure) |
|
4487 | - return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
4737 | + if (is_array($string) || $string instanceof Closure) { |
|
4738 | + return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
4739 | + } |
|
4488 | 4740 | |
4489 | 4741 | // No full objects, sorry! pass a method or a property instead! |
4490 | - if (is_object($string)) |
|
4491 | - return false; |
|
4742 | + if (is_object($string)) { |
|
4743 | + return false; |
|
4744 | + } |
|
4492 | 4745 | |
4493 | 4746 | // Stay vitaminized my friends... |
4494 | 4747 | $string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string)); |
@@ -4500,8 +4753,9 @@ discard block |
||
4500 | 4753 | $string = load_file($string); |
4501 | 4754 | |
4502 | 4755 | // Loaded file failed |
4503 | - if (empty($string)) |
|
4504 | - return false; |
|
4756 | + if (empty($string)) { |
|
4757 | + return false; |
|
4758 | + } |
|
4505 | 4759 | |
4506 | 4760 | // Found a method. |
4507 | 4761 | if (strpos($string, '::') !== false) |
@@ -4522,8 +4776,9 @@ discard block |
||
4522 | 4776 | // Add another one to the list. |
4523 | 4777 | if ($db_show_debug === true) |
4524 | 4778 | { |
4525 | - if (!isset($context['debug']['instances'])) |
|
4526 | - $context['debug']['instances'] = array(); |
|
4779 | + if (!isset($context['debug']['instances'])) { |
|
4780 | + $context['debug']['instances'] = array(); |
|
4781 | + } |
|
4527 | 4782 | |
4528 | 4783 | $context['debug']['instances'][$class] = $class; |
4529 | 4784 | } |
@@ -4533,13 +4788,15 @@ discard block |
||
4533 | 4788 | } |
4534 | 4789 | |
4535 | 4790 | // Right then. This is a call to a static method. |
4536 | - else |
|
4537 | - $func = array($class, $method); |
|
4791 | + else { |
|
4792 | + $func = array($class, $method); |
|
4793 | + } |
|
4538 | 4794 | } |
4539 | 4795 | |
4540 | 4796 | // Nope! just a plain regular function. |
4541 | - else |
|
4542 | - $func = $string; |
|
4797 | + else { |
|
4798 | + $func = $string; |
|
4799 | + } |
|
4543 | 4800 | |
4544 | 4801 | // Right, we got what we need, time to do some checks. |
4545 | 4802 | if (!is_callable($func, false, $callable_name)) |
@@ -4555,17 +4812,18 @@ discard block |
||
4555 | 4812 | else |
4556 | 4813 | { |
4557 | 4814 | // What are we gonna do about it? |
4558 | - if ($return) |
|
4559 | - return $func; |
|
4815 | + if ($return) { |
|
4816 | + return $func; |
|
4817 | + } |
|
4560 | 4818 | |
4561 | 4819 | // If this is a plain function, avoid the heat of calling call_user_func(). |
4562 | 4820 | else |
4563 | 4821 | { |
4564 | - if (is_array($func)) |
|
4565 | - call_user_func($func); |
|
4566 | - |
|
4567 | - else |
|
4568 | - $func(); |
|
4822 | + if (is_array($func)) { |
|
4823 | + call_user_func($func); |
|
4824 | + } else { |
|
4825 | + $func(); |
|
4826 | + } |
|
4569 | 4827 | } |
4570 | 4828 | } |
4571 | 4829 | } |
@@ -4582,31 +4840,34 @@ discard block |
||
4582 | 4840 | { |
4583 | 4841 | global $sourcedir, $txt, $boarddir, $settings; |
4584 | 4842 | |
4585 | - if (empty($string)) |
|
4586 | - return false; |
|
4843 | + if (empty($string)) { |
|
4844 | + return false; |
|
4845 | + } |
|
4587 | 4846 | |
4588 | 4847 | if (strpos($string, '|') !== false) |
4589 | 4848 | { |
4590 | 4849 | list ($file, $string) = explode('|', $string); |
4591 | 4850 | |
4592 | 4851 | // Match the wildcards to their regular vars. |
4593 | - if (empty($settings['theme_dir'])) |
|
4594 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
4595 | - |
|
4596 | - else |
|
4597 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
4852 | + if (empty($settings['theme_dir'])) { |
|
4853 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
4854 | + } else { |
|
4855 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
4856 | + } |
|
4598 | 4857 | |
4599 | 4858 | // Load the file if it can be loaded. |
4600 | - if (file_exists($absPath)) |
|
4601 | - require_once($absPath); |
|
4859 | + if (file_exists($absPath)) { |
|
4860 | + require_once($absPath); |
|
4861 | + } |
|
4602 | 4862 | |
4603 | 4863 | // No? try a fallback to $sourcedir |
4604 | 4864 | else |
4605 | 4865 | { |
4606 | 4866 | $absPath = $sourcedir .'/'. $file; |
4607 | 4867 | |
4608 | - if (file_exists($absPath)) |
|
4609 | - require_once($absPath); |
|
4868 | + if (file_exists($absPath)) { |
|
4869 | + require_once($absPath); |
|
4870 | + } |
|
4610 | 4871 | |
4611 | 4872 | // Sorry, can't do much for you at this point. |
4612 | 4873 | else |
@@ -4633,8 +4894,9 @@ discard block |
||
4633 | 4894 | global $user_info, $smcFunc; |
4634 | 4895 | |
4635 | 4896 | // Make sure we have something to work with. |
4636 | - if (empty($topic)) |
|
4637 | - return array(); |
|
4897 | + if (empty($topic)) { |
|
4898 | + return array(); |
|
4899 | + } |
|
4638 | 4900 | |
4639 | 4901 | |
4640 | 4902 | // We already know the number of likes per message, we just want to know whether the current user liked it or not. |
@@ -4657,8 +4919,9 @@ discard block |
||
4657 | 4919 | 'topic' => $topic, |
4658 | 4920 | ) |
4659 | 4921 | ); |
4660 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
4661 | - $temp[] = (int) $row['content_id']; |
|
4922 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
4923 | + $temp[] = (int) $row['content_id']; |
|
4924 | + } |
|
4662 | 4925 | |
4663 | 4926 | cache_put_data($cache_key, $temp, $ttl); |
4664 | 4927 | } |
@@ -4679,8 +4942,9 @@ discard block |
||
4679 | 4942 | { |
4680 | 4943 | global $context; |
4681 | 4944 | |
4682 | - if (empty($string)) |
|
4683 | - return $string; |
|
4945 | + if (empty($string)) { |
|
4946 | + return $string; |
|
4947 | + } |
|
4684 | 4948 | |
4685 | 4949 | // UTF-8 occurences of MS special characters |
4686 | 4950 | $findchars_utf8 = array( |
@@ -4721,10 +4985,11 @@ discard block |
||
4721 | 4985 | '--', // — |
4722 | 4986 | ); |
4723 | 4987 | |
4724 | - if ($context['utf8']) |
|
4725 | - $string = str_replace($findchars_utf8, $replacechars, $string); |
|
4726 | - else |
|
4727 | - $string = str_replace($findchars_iso, $replacechars, $string); |
|
4988 | + if ($context['utf8']) { |
|
4989 | + $string = str_replace($findchars_utf8, $replacechars, $string); |
|
4990 | + } else { |
|
4991 | + $string = str_replace($findchars_iso, $replacechars, $string); |
|
4992 | + } |
|
4728 | 4993 | |
4729 | 4994 | return $string; |
4730 | 4995 | } |
@@ -4743,49 +5008,59 @@ discard block |
||
4743 | 5008 | { |
4744 | 5009 | global $context; |
4745 | 5010 | |
4746 | - if (!isset($matches[2])) |
|
4747 | - return ''; |
|
5011 | + if (!isset($matches[2])) { |
|
5012 | + return ''; |
|
5013 | + } |
|
4748 | 5014 | |
4749 | 5015 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
4750 | 5016 | |
4751 | 5017 | // remove left to right / right to left overrides |
4752 | - if ($num === 0x202D || $num === 0x202E) |
|
4753 | - return ''; |
|
5018 | + if ($num === 0x202D || $num === 0x202E) { |
|
5019 | + return ''; |
|
5020 | + } |
|
4754 | 5021 | |
4755 | 5022 | // Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced |
4756 | - if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) |
|
4757 | - return '&#' . $num . ';'; |
|
5023 | + if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) { |
|
5024 | + return '&#' . $num . ';'; |
|
5025 | + } |
|
4758 | 5026 | |
4759 | 5027 | if (empty($context['utf8'])) |
4760 | 5028 | { |
4761 | 5029 | // no control characters |
4762 | - if ($num < 0x20) |
|
4763 | - return ''; |
|
5030 | + if ($num < 0x20) { |
|
5031 | + return ''; |
|
5032 | + } |
|
4764 | 5033 | // text is text |
4765 | - elseif ($num < 0x80) |
|
4766 | - return chr($num); |
|
5034 | + elseif ($num < 0x80) { |
|
5035 | + return chr($num); |
|
5036 | + } |
|
4767 | 5037 | // all others get html-ised |
4768 | - else |
|
4769 | - return '&#' . $matches[2] . ';'; |
|
4770 | - } |
|
4771 | - else |
|
5038 | + else { |
|
5039 | + return '&#' . $matches[2] . ';'; |
|
5040 | + } |
|
5041 | + } else |
|
4772 | 5042 | { |
4773 | 5043 | // <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set |
4774 | 5044 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text) |
4775 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) |
|
4776 | - return ''; |
|
5045 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) { |
|
5046 | + return ''; |
|
5047 | + } |
|
4777 | 5048 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
4778 | - elseif ($num < 0x80) |
|
4779 | - return chr($num); |
|
5049 | + elseif ($num < 0x80) { |
|
5050 | + return chr($num); |
|
5051 | + } |
|
4780 | 5052 | // <0x800 (2048) |
4781 | - elseif ($num < 0x800) |
|
4782 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5053 | + elseif ($num < 0x800) { |
|
5054 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5055 | + } |
|
4783 | 5056 | // < 0x10000 (65536) |
4784 | - elseif ($num < 0x10000) |
|
4785 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5057 | + elseif ($num < 0x10000) { |
|
5058 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5059 | + } |
|
4786 | 5060 | // <= 0x10FFFF (1114111) |
4787 | - else |
|
4788 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5061 | + else { |
|
5062 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5063 | + } |
|
4789 | 5064 | } |
4790 | 5065 | } |
4791 | 5066 | |
@@ -4801,28 +5076,34 @@ discard block |
||
4801 | 5076 | */ |
4802 | 5077 | function fixchar__callback($matches) |
4803 | 5078 | { |
4804 | - if (!isset($matches[1])) |
|
4805 | - return ''; |
|
5079 | + if (!isset($matches[1])) { |
|
5080 | + return ''; |
|
5081 | + } |
|
4806 | 5082 | |
4807 | 5083 | $num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1]; |
4808 | 5084 | |
4809 | 5085 | // <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set |
4810 | 5086 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides |
4811 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) |
|
4812 | - return ''; |
|
5087 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) { |
|
5088 | + return ''; |
|
5089 | + } |
|
4813 | 5090 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
4814 | - elseif ($num < 0x80) |
|
4815 | - return chr($num); |
|
5091 | + elseif ($num < 0x80) { |
|
5092 | + return chr($num); |
|
5093 | + } |
|
4816 | 5094 | // <0x800 (2048) |
4817 | - elseif ($num < 0x800) |
|
4818 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5095 | + elseif ($num < 0x800) { |
|
5096 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5097 | + } |
|
4819 | 5098 | // < 0x10000 (65536) |
4820 | - elseif ($num < 0x10000) |
|
4821 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5099 | + elseif ($num < 0x10000) { |
|
5100 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5101 | + } |
|
4822 | 5102 | // <= 0x10FFFF (1114111) |
4823 | - else |
|
4824 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
4825 | -} |
|
5103 | + else { |
|
5104 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5105 | + } |
|
5106 | + } |
|
4826 | 5107 | |
4827 | 5108 | /** |
4828 | 5109 | * Strips out invalid html entities, replaces others with html style { codes |
@@ -4835,17 +5116,19 @@ discard block |
||
4835 | 5116 | */ |
4836 | 5117 | function entity_fix__callback($matches) |
4837 | 5118 | { |
4838 | - if (!isset($matches[2])) |
|
4839 | - return ''; |
|
5119 | + if (!isset($matches[2])) { |
|
5120 | + return ''; |
|
5121 | + } |
|
4840 | 5122 | |
4841 | 5123 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
4842 | 5124 | |
4843 | 5125 | // we don't allow control characters, characters out of range, byte markers, etc |
4844 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) |
|
4845 | - return ''; |
|
4846 | - else |
|
4847 | - return '&#' . $num . ';'; |
|
4848 | -} |
|
5126 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) { |
|
5127 | + return ''; |
|
5128 | + } else { |
|
5129 | + return '&#' . $num . ';'; |
|
5130 | + } |
|
5131 | + } |
|
4849 | 5132 | |
4850 | 5133 | /** |
4851 | 5134 | * Return a Gravatar URL based on |
@@ -4869,18 +5152,23 @@ discard block |
||
4869 | 5152 | $ratings = array('G', 'PG', 'R', 'X'); |
4870 | 5153 | $defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'); |
4871 | 5154 | $url_params = array(); |
4872 | - if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) |
|
4873 | - $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
4874 | - if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) |
|
4875 | - $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
4876 | - if (!empty($modSettings['avatar_max_width_external'])) |
|
4877 | - $size_string = (int) $modSettings['avatar_max_width_external']; |
|
4878 | - if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) |
|
4879 | - if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
5155 | + if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) { |
|
5156 | + $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
5157 | + } |
|
5158 | + if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) { |
|
5159 | + $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
5160 | + } |
|
5161 | + if (!empty($modSettings['avatar_max_width_external'])) { |
|
5162 | + $size_string = (int) $modSettings['avatar_max_width_external']; |
|
5163 | + } |
|
5164 | + if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) { |
|
5165 | + if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
4880 | 5166 | $size_string = $modSettings['avatar_max_height_external']; |
5167 | + } |
|
4881 | 5168 | |
4882 | - if (!empty($size_string)) |
|
4883 | - $url_params[] = 's=' . $size_string; |
|
5169 | + if (!empty($size_string)) { |
|
5170 | + $url_params[] = 's=' . $size_string; |
|
5171 | + } |
|
4884 | 5172 | } |
4885 | 5173 | $http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www'; |
4886 | 5174 | |
@@ -4991,8 +5279,9 @@ discard block |
||
4991 | 5279 | */ |
4992 | 5280 | function inet_ptod($ip_address) |
4993 | 5281 | { |
4994 | - if (!isValidIP($ip_address)) |
|
4995 | - return $ip_address; |
|
5282 | + if (!isValidIP($ip_address)) { |
|
5283 | + return $ip_address; |
|
5284 | + } |
|
4996 | 5285 | |
4997 | 5286 | $bin = inet_pton($ip_address); |
4998 | 5287 | return $bin; |
@@ -5004,13 +5293,15 @@ discard block |
||
5004 | 5293 | */ |
5005 | 5294 | function inet_dtop($bin) |
5006 | 5295 | { |
5007 | - if(empty($bin)) |
|
5008 | - return ''; |
|
5296 | + if(empty($bin)) { |
|
5297 | + return ''; |
|
5298 | + } |
|
5009 | 5299 | |
5010 | 5300 | global $db_type; |
5011 | 5301 | |
5012 | - if ($db_type == 'postgresql') |
|
5013 | - return $bin; |
|
5302 | + if ($db_type == 'postgresql') { |
|
5303 | + return $bin; |
|
5304 | + } |
|
5014 | 5305 | |
5015 | 5306 | $ip_address = inet_ntop($bin); |
5016 | 5307 | |
@@ -5035,26 +5326,32 @@ discard block |
||
5035 | 5326 | */ |
5036 | 5327 | function _safe_serialize($value) |
5037 | 5328 | { |
5038 | - if(is_null($value)) |
|
5039 | - return 'N;'; |
|
5329 | + if(is_null($value)) { |
|
5330 | + return 'N;'; |
|
5331 | + } |
|
5040 | 5332 | |
5041 | - if(is_bool($value)) |
|
5042 | - return 'b:'. (int) $value .';'; |
|
5333 | + if(is_bool($value)) { |
|
5334 | + return 'b:'. (int) $value .';'; |
|
5335 | + } |
|
5043 | 5336 | |
5044 | - if(is_int($value)) |
|
5045 | - return 'i:'. $value .';'; |
|
5337 | + if(is_int($value)) { |
|
5338 | + return 'i:'. $value .';'; |
|
5339 | + } |
|
5046 | 5340 | |
5047 | - if(is_float($value)) |
|
5048 | - return 'd:'. str_replace(',', '.', $value) .';'; |
|
5341 | + if(is_float($value)) { |
|
5342 | + return 'd:'. str_replace(',', '.', $value) .';'; |
|
5343 | + } |
|
5049 | 5344 | |
5050 | - if(is_string($value)) |
|
5051 | - return 's:'. strlen($value) .':"'. $value .'";'; |
|
5345 | + if(is_string($value)) { |
|
5346 | + return 's:'. strlen($value) .':"'. $value .'";'; |
|
5347 | + } |
|
5052 | 5348 | |
5053 | 5349 | if(is_array($value)) |
5054 | 5350 | { |
5055 | 5351 | $out = ''; |
5056 | - foreach($value as $k => $v) |
|
5057 | - $out .= _safe_serialize($k) . _safe_serialize($v); |
|
5352 | + foreach($value as $k => $v) { |
|
5353 | + $out .= _safe_serialize($k) . _safe_serialize($v); |
|
5354 | + } |
|
5058 | 5355 | |
5059 | 5356 | return 'a:'. count($value) .':{'. $out .'}'; |
5060 | 5357 | } |
@@ -5080,8 +5377,9 @@ discard block |
||
5080 | 5377 | |
5081 | 5378 | $out = _safe_serialize($value); |
5082 | 5379 | |
5083 | - if (isset($mbIntEnc)) |
|
5084 | - mb_internal_encoding($mbIntEnc); |
|
5380 | + if (isset($mbIntEnc)) { |
|
5381 | + mb_internal_encoding($mbIntEnc); |
|
5382 | + } |
|
5085 | 5383 | |
5086 | 5384 | return $out; |
5087 | 5385 | } |
@@ -5098,8 +5396,9 @@ discard block |
||
5098 | 5396 | function _safe_unserialize($str) |
5099 | 5397 | { |
5100 | 5398 | // Input is not a string. |
5101 | - if(empty($str) || !is_string($str)) |
|
5102 | - return false; |
|
5399 | + if(empty($str) || !is_string($str)) { |
|
5400 | + return false; |
|
5401 | + } |
|
5103 | 5402 | |
5104 | 5403 | $stack = array(); |
5105 | 5404 | $expected = array(); |
@@ -5115,43 +5414,38 @@ discard block |
||
5115 | 5414 | while($state != 1) |
5116 | 5415 | { |
5117 | 5416 | $type = isset($str[0]) ? $str[0] : ''; |
5118 | - if($type == '}') |
|
5119 | - $str = substr($str, 1); |
|
5120 | - |
|
5121 | - else if($type == 'N' && $str[1] == ';') |
|
5417 | + if($type == '}') { |
|
5418 | + $str = substr($str, 1); |
|
5419 | + } else if($type == 'N' && $str[1] == ';') |
|
5122 | 5420 | { |
5123 | 5421 | $value = null; |
5124 | 5422 | $str = substr($str, 2); |
5125 | - } |
|
5126 | - else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
5423 | + } else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
5127 | 5424 | { |
5128 | 5425 | $value = $matches[1] == '1' ? true : false; |
5129 | 5426 | $str = substr($str, 4); |
5130 | - } |
|
5131 | - else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
5427 | + } else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
5132 | 5428 | { |
5133 | 5429 | $value = (int)$matches[1]; |
5134 | 5430 | $str = $matches[2]; |
5135 | - } |
|
5136 | - else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
5431 | + } else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
5137 | 5432 | { |
5138 | 5433 | $value = (float)$matches[1]; |
5139 | 5434 | $str = $matches[3]; |
5140 | - } |
|
5141 | - else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
5435 | + } else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
5142 | 5436 | { |
5143 | 5437 | $value = substr($matches[2], 0, (int)$matches[1]); |
5144 | 5438 | $str = substr($matches[2], (int)$matches[1] + 2); |
5145 | - } |
|
5146 | - else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
5439 | + } else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
5147 | 5440 | { |
5148 | 5441 | $expectedLength = (int)$matches[1]; |
5149 | 5442 | $str = $matches[2]; |
5150 | 5443 | } |
5151 | 5444 | |
5152 | 5445 | // Object or unknown/malformed type. |
5153 | - else |
|
5154 | - return false; |
|
5446 | + else { |
|
5447 | + return false; |
|
5448 | + } |
|
5155 | 5449 | |
5156 | 5450 | switch($state) |
5157 | 5451 | { |
@@ -5179,8 +5473,9 @@ discard block |
||
5179 | 5473 | if($type == '}') |
5180 | 5474 | { |
5181 | 5475 | // Array size is less than expected. |
5182 | - if(count($list) < end($expected)) |
|
5183 | - return false; |
|
5476 | + if(count($list) < end($expected)) { |
|
5477 | + return false; |
|
5478 | + } |
|
5184 | 5479 | |
5185 | 5480 | unset($list); |
5186 | 5481 | $list = &$stack[count($stack)-1]; |
@@ -5189,8 +5484,9 @@ discard block |
||
5189 | 5484 | // Go to terminal state if we're at the end of the root array. |
5190 | 5485 | array_pop($expected); |
5191 | 5486 | |
5192 | - if(count($expected) == 0) |
|
5193 | - $state = 1; |
|
5487 | + if(count($expected) == 0) { |
|
5488 | + $state = 1; |
|
5489 | + } |
|
5194 | 5490 | |
5195 | 5491 | break; |
5196 | 5492 | } |
@@ -5198,8 +5494,9 @@ discard block |
||
5198 | 5494 | if($type == 'i' || $type == 's') |
5199 | 5495 | { |
5200 | 5496 | // Array size exceeds expected length. |
5201 | - if(count($list) >= end($expected)) |
|
5202 | - return false; |
|
5497 | + if(count($list) >= end($expected)) { |
|
5498 | + return false; |
|
5499 | + } |
|
5203 | 5500 | |
5204 | 5501 | $key = $value; |
5205 | 5502 | $state = 3; |
@@ -5233,8 +5530,9 @@ discard block |
||
5233 | 5530 | } |
5234 | 5531 | |
5235 | 5532 | // Trailing data in input. |
5236 | - if(!empty($str)) |
|
5237 | - return false; |
|
5533 | + if(!empty($str)) { |
|
5534 | + return false; |
|
5535 | + } |
|
5238 | 5536 | |
5239 | 5537 | return $data; |
5240 | 5538 | } |
@@ -5257,8 +5555,9 @@ discard block |
||
5257 | 5555 | |
5258 | 5556 | $out = _safe_unserialize($str); |
5259 | 5557 | |
5260 | - if (isset($mbIntEnc)) |
|
5261 | - mb_internal_encoding($mbIntEnc); |
|
5558 | + if (isset($mbIntEnc)) { |
|
5559 | + mb_internal_encoding($mbIntEnc); |
|
5560 | + } |
|
5262 | 5561 | |
5263 | 5562 | return $out; |
5264 | 5563 | } |
@@ -5273,12 +5572,14 @@ discard block |
||
5273 | 5572 | function smf_chmod($file, $value = 0) |
5274 | 5573 | { |
5275 | 5574 | // No file? no checks! |
5276 | - if (empty($file)) |
|
5277 | - return false; |
|
5575 | + if (empty($file)) { |
|
5576 | + return false; |
|
5577 | + } |
|
5278 | 5578 | |
5279 | 5579 | // Already writable? |
5280 | - if (is_writable($file)) |
|
5281 | - return true; |
|
5580 | + if (is_writable($file)) { |
|
5581 | + return true; |
|
5582 | + } |
|
5282 | 5583 | |
5283 | 5584 | // Do we have a file or a dir? |
5284 | 5585 | $isDir = is_dir($file); |
@@ -5294,10 +5595,9 @@ discard block |
||
5294 | 5595 | { |
5295 | 5596 | $isWritable = true; |
5296 | 5597 | break; |
5598 | + } else { |
|
5599 | + @chmod($file, $val); |
|
5297 | 5600 | } |
5298 | - |
|
5299 | - else |
|
5300 | - @chmod($file, $val); |
|
5301 | 5601 | } |
5302 | 5602 | |
5303 | 5603 | return $isWritable; |
@@ -5316,8 +5616,9 @@ discard block |
||
5316 | 5616 | global $txt; |
5317 | 5617 | |
5318 | 5618 | // Come on... |
5319 | - if (empty($json) || !is_string($json)) |
|
5320 | - return array(); |
|
5619 | + if (empty($json) || !is_string($json)) { |
|
5620 | + return array(); |
|
5621 | + } |
|
5321 | 5622 | |
5322 | 5623 | $returnArray = array(); |
5323 | 5624 | $jsonError = false; |
@@ -5358,11 +5659,11 @@ discard block |
||
5358 | 5659 | $jsonDebug = $jsonDebug[0]; |
5359 | 5660 | loadLanguage('Errors'); |
5360 | 5661 | |
5361 | - if (!empty($jsonDebug)) |
|
5362 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
5363 | - |
|
5364 | - else |
|
5365 | - log_error($txt['json_'. $jsonError], 'critical'); |
|
5662 | + if (!empty($jsonDebug)) { |
|
5663 | + log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
5664 | + } else { |
|
5665 | + log_error($txt['json_'. $jsonError], 'critical'); |
|
5666 | + } |
|
5366 | 5667 | |
5367 | 5668 | // Everyone expects an array. |
5368 | 5669 | return array(); |
@@ -5392,8 +5693,9 @@ discard block |
||
5392 | 5693 | global $db_show_debug, $modSettings; |
5393 | 5694 | |
5394 | 5695 | // Defensive programming anyone? |
5395 | - if (empty($data)) |
|
5396 | - return false; |
|
5696 | + if (empty($data)) { |
|
5697 | + return false; |
|
5698 | + } |
|
5397 | 5699 | |
5398 | 5700 | // Don't need extra stuff... |
5399 | 5701 | $db_show_debug = false; |
@@ -5401,11 +5703,11 @@ discard block |
||
5401 | 5703 | // Kill anything else. |
5402 | 5704 | ob_end_clean(); |
5403 | 5705 | |
5404 | - if (!empty($modSettings['CompressedOutput'])) |
|
5405 | - @ob_start('ob_gzhandler'); |
|
5406 | - |
|
5407 | - else |
|
5408 | - ob_start(); |
|
5706 | + if (!empty($modSettings['CompressedOutput'])) { |
|
5707 | + @ob_start('ob_gzhandler'); |
|
5708 | + } else { |
|
5709 | + ob_start(); |
|
5710 | + } |
|
5409 | 5711 | |
5410 | 5712 | // Set the header. |
5411 | 5713 | header($type); |
@@ -5437,8 +5739,9 @@ discard block |
||
5437 | 5739 | static $done = false; |
5438 | 5740 | |
5439 | 5741 | // If we don't need to do anything, don't |
5440 | - if (!$update && $done) |
|
5441 | - return; |
|
5742 | + if (!$update && $done) { |
|
5743 | + return; |
|
5744 | + } |
|
5442 | 5745 | |
5443 | 5746 | // Should we get a new copy of the official list of TLDs? |
5444 | 5747 | if ($update) |
@@ -5459,10 +5762,11 @@ discard block |
||
5459 | 5762 | // Clean $tlds and convert it to an array |
5460 | 5763 | $tlds = array_filter(explode("\n", strtolower($tlds)), function($line) { |
5461 | 5764 | $line = trim($line); |
5462 | - if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) |
|
5463 | - return false; |
|
5464 | - else |
|
5465 | - return true; |
|
5765 | + if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) { |
|
5766 | + return false; |
|
5767 | + } else { |
|
5768 | + return true; |
|
5769 | + } |
|
5466 | 5770 | }); |
5467 | 5771 | |
5468 | 5772 | // Convert Punycode to Unicode |
@@ -5516,8 +5820,9 @@ discard block |
||
5516 | 5820 | $idx += $digit * $w; |
5517 | 5821 | $t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias)); |
5518 | 5822 | |
5519 | - if ($digit < $t) |
|
5520 | - break; |
|
5823 | + if ($digit < $t) { |
|
5824 | + break; |
|
5825 | + } |
|
5521 | 5826 | |
5522 | 5827 | $w = (int) ($w * ($base - $t)); |
5523 | 5828 | } |
@@ -5526,8 +5831,9 @@ discard block |
||
5526 | 5831 | $delta = intval($is_first ? ($delta / $damp) : ($delta / 2)); |
5527 | 5832 | $delta += intval($delta / ($deco_len + 1)); |
5528 | 5833 | |
5529 | - for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) |
|
5530 | - $delta = intval($delta / ($base - $tmin)); |
|
5834 | + for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) { |
|
5835 | + $delta = intval($delta / ($base - $tmin)); |
|
5836 | + } |
|
5531 | 5837 | |
5532 | 5838 | $bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew)); |
5533 | 5839 | $is_first = false; |
@@ -5536,8 +5842,9 @@ discard block |
||
5536 | 5842 | |
5537 | 5843 | if ($deco_len > 0) |
5538 | 5844 | { |
5539 | - for ($i = $deco_len; $i > $idx; $i--) |
|
5540 | - $decoded[$i] = $decoded[($i - 1)]; |
|
5845 | + for ($i = $deco_len; $i > $idx; $i--) { |
|
5846 | + $decoded[$i] = $decoded[($i - 1)]; |
|
5847 | + } |
|
5541 | 5848 | } |
5542 | 5849 | $decoded[$idx++] = $char; |
5543 | 5850 | } |
@@ -5545,24 +5852,29 @@ discard block |
||
5545 | 5852 | foreach ($decoded as $k => $v) |
5546 | 5853 | { |
5547 | 5854 | // 7bit are transferred literally |
5548 | - if ($v < 128) |
|
5549 | - $output .= chr($v); |
|
5855 | + if ($v < 128) { |
|
5856 | + $output .= chr($v); |
|
5857 | + } |
|
5550 | 5858 | |
5551 | 5859 | // 2 bytes |
5552 | - elseif ($v < (1 << 11)) |
|
5553 | - $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
5860 | + elseif ($v < (1 << 11)) { |
|
5861 | + $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
5862 | + } |
|
5554 | 5863 | |
5555 | 5864 | // 3 bytes |
5556 | - elseif ($v < (1 << 16)) |
|
5557 | - $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
5865 | + elseif ($v < (1 << 16)) { |
|
5866 | + $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
5867 | + } |
|
5558 | 5868 | |
5559 | 5869 | // 4 bytes |
5560 | - elseif ($v < (1 << 21)) |
|
5561 | - $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
5870 | + elseif ($v < (1 << 21)) { |
|
5871 | + $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
5872 | + } |
|
5562 | 5873 | |
5563 | 5874 | // 'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k |
5564 | - else |
|
5565 | - $output .= $safe_char; |
|
5875 | + else { |
|
5876 | + $output .= $safe_char; |
|
5877 | + } |
|
5566 | 5878 | } |
5567 | 5879 | |
5568 | 5880 | $output_parts[] = $output; |
@@ -5657,8 +5969,7 @@ discard block |
||
5657 | 5969 | |
5658 | 5970 | $strlen = 'mb_strlen'; |
5659 | 5971 | $substr = 'mb_substr'; |
5660 | - } |
|
5661 | - else |
|
5972 | + } else |
|
5662 | 5973 | { |
5663 | 5974 | $strlen = $smcFunc['strlen']; |
5664 | 5975 | $substr = $smcFunc['substr']; |
@@ -5672,20 +5983,21 @@ discard block |
||
5672 | 5983 | |
5673 | 5984 | $first = $substr($string, 0, 1); |
5674 | 5985 | |
5675 | - if (empty($index[$first])) |
|
5676 | - $index[$first] = array(); |
|
5986 | + if (empty($index[$first])) { |
|
5987 | + $index[$first] = array(); |
|
5988 | + } |
|
5677 | 5989 | |
5678 | 5990 | if ($strlen($string) > 1) |
5679 | 5991 | { |
5680 | 5992 | // Sanity check on recursion |
5681 | - if ($depth > 99) |
|
5682 | - $index[$first][$substr($string, 1)] = ''; |
|
5683 | - |
|
5684 | - else |
|
5685 | - $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
5993 | + if ($depth > 99) { |
|
5994 | + $index[$first][$substr($string, 1)] = ''; |
|
5995 | + } else { |
|
5996 | + $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
5997 | + } |
|
5998 | + } else { |
|
5999 | + $index[$first][''] = ''; |
|
5686 | 6000 | } |
5687 | - else |
|
5688 | - $index[$first][''] = ''; |
|
5689 | 6001 | |
5690 | 6002 | $depth--; |
5691 | 6003 | return $index; |
@@ -5708,9 +6020,9 @@ discard block |
||
5708 | 6020 | $key_regex = preg_quote($key, $delim); |
5709 | 6021 | $new_key = $key; |
5710 | 6022 | |
5711 | - if (empty($value)) |
|
5712 | - $sub_regex = ''; |
|
5713 | - else |
|
6023 | + if (empty($value)) { |
|
6024 | + $sub_regex = ''; |
|
6025 | + } else |
|
5714 | 6026 | { |
5715 | 6027 | $sub_regex = $index_to_regex($value, $delim); |
5716 | 6028 | |
@@ -5718,22 +6030,22 @@ discard block |
||
5718 | 6030 | { |
5719 | 6031 | $new_key_array = explode('(?'.'>', $sub_regex); |
5720 | 6032 | $new_key .= $new_key_array[0]; |
6033 | + } else { |
|
6034 | + $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
5721 | 6035 | } |
5722 | - else |
|
5723 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
5724 | 6036 | } |
5725 | 6037 | |
5726 | - if ($depth > 1) |
|
5727 | - $regex[$new_key] = $key_regex . $sub_regex; |
|
5728 | - else |
|
6038 | + if ($depth > 1) { |
|
6039 | + $regex[$new_key] = $key_regex . $sub_regex; |
|
6040 | + } else |
|
5729 | 6041 | { |
5730 | 6042 | if (($length += strlen($key_regex) + 1) < $max_length || empty($regex)) |
5731 | 6043 | { |
5732 | 6044 | $regex[$new_key] = $key_regex . $sub_regex; |
5733 | 6045 | unset($index[$key]); |
6046 | + } else { |
|
6047 | + break; |
|
5734 | 6048 | } |
5735 | - else |
|
5736 | - break; |
|
5737 | 6049 | } |
5738 | 6050 | } |
5739 | 6051 | |
@@ -5742,10 +6054,11 @@ discard block |
||
5742 | 6054 | $l1 = $strlen($k1); |
5743 | 6055 | $l2 = $strlen($k2); |
5744 | 6056 | |
5745 | - if ($l1 == $l2) |
|
5746 | - return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
5747 | - else |
|
5748 | - return $l1 > $l2 ? -1 : 1; |
|
6057 | + if ($l1 == $l2) { |
|
6058 | + return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
6059 | + } else { |
|
6060 | + return $l1 > $l2 ? -1 : 1; |
|
6061 | + } |
|
5749 | 6062 | }); |
5750 | 6063 | |
5751 | 6064 | $depth--; |
@@ -5756,15 +6069,18 @@ discard block |
||
5756 | 6069 | $index = array(); |
5757 | 6070 | $regexes = array(); |
5758 | 6071 | |
5759 | - foreach ($strings as $string) |
|
5760 | - $index = $add_string_to_index($string, $index); |
|
6072 | + foreach ($strings as $string) { |
|
6073 | + $index = $add_string_to_index($string, $index); |
|
6074 | + } |
|
5761 | 6075 | |
5762 | - while (!empty($index)) |
|
5763 | - $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6076 | + while (!empty($index)) { |
|
6077 | + $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6078 | + } |
|
5764 | 6079 | |
5765 | 6080 | // Restore PHP's internal character encoding to whatever it was originally |
5766 | - if (!empty($current_encoding)) |
|
5767 | - mb_internal_encoding($current_encoding); |
|
6081 | + if (!empty($current_encoding)) { |
|
6082 | + mb_internal_encoding($current_encoding); |
|
6083 | + } |
|
5768 | 6084 | |
5769 | 6085 | return $regexes; |
5770 | 6086 | } |
@@ -76,15 +76,15 @@ discard block |
||
76 | 76 | |
77 | 77 | // Set a list of common functions. |
78 | 78 | $ent_list = empty($modSettings['disableEntityCheck']) ? '&(#\d{1,7}|quot|amp|lt|gt|nbsp);' : '&(#021|quot|amp|lt|gt|nbsp);'; |
79 | - $ent_check = empty($modSettings['disableEntityCheck']) ? function ($string) |
|
79 | + $ent_check = empty($modSettings['disableEntityCheck']) ? function($string) |
|
80 | 80 | { |
81 | 81 | $string = preg_replace_callback('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', $string); |
82 | 82 | return $string; |
83 | - } : function ($string) |
|
83 | + } : function($string) |
|
84 | 84 | { |
85 | 85 | return $string; |
86 | 86 | }; |
87 | - $fix_utf8mb4 = function ($string) use ($utf8) |
|
87 | + $fix_utf8mb4 = function($string) use ($utf8) |
|
88 | 88 | { |
89 | 89 | if (!$utf8) |
90 | 90 | return $string; |
@@ -102,21 +102,21 @@ discard block |
||
102 | 102 | } |
103 | 103 | elseif ($ord < 224) |
104 | 104 | { |
105 | - $new_string .= $string[$i] . $string[$i+1]; |
|
105 | + $new_string .= $string[$i] . $string[$i + 1]; |
|
106 | 106 | $i += 2; |
107 | 107 | } |
108 | 108 | elseif ($ord < 240) |
109 | 109 | { |
110 | - $new_string .= $string[$i] . $string[$i+1] . $string[$i+2]; |
|
110 | + $new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2]; |
|
111 | 111 | $i += 3; |
112 | 112 | } |
113 | 113 | elseif ($ord < 248) |
114 | 114 | { |
115 | 115 | // Magic happens. |
116 | 116 | $val = (ord($string[$i]) & 0x07) << 18; |
117 | - $val += (ord($string[$i+1]) & 0x3F) << 12; |
|
118 | - $val += (ord($string[$i+2]) & 0x3F) << 6; |
|
119 | - $val += (ord($string[$i+3]) & 0x3F); |
|
117 | + $val += (ord($string[$i + 1]) & 0x3F) << 12; |
|
118 | + $val += (ord($string[$i + 2]) & 0x3F) << 6; |
|
119 | + $val += (ord($string[$i + 3]) & 0x3F); |
|
120 | 120 | $new_string .= '&#' . $val . ';'; |
121 | 121 | $i += 4; |
122 | 122 | } |
@@ -129,24 +129,24 @@ discard block |
||
129 | 129 | |
130 | 130 | // global array of anonymous helper functions, used mostly to properly handle multi byte strings |
131 | 131 | $smcFunc += array( |
132 | - 'entity_fix' => function ($string) |
|
132 | + 'entity_fix' => function($string) |
|
133 | 133 | { |
134 | 134 | $num = $string[0] === 'x' ? hexdec(substr($string, 1)) : (int) $string; |
135 | 135 | return $num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202E || $num === 0x202D ? '' : '&#' . $num . ';'; |
136 | 136 | }, |
137 | - 'htmlspecialchars' => function ($string, $quote_style = ENT_COMPAT, $charset = 'ISO-8859-1') use ($ent_check, $utf8, $fix_utf8mb4) |
|
137 | + 'htmlspecialchars' => function($string, $quote_style = ENT_COMPAT, $charset = 'ISO-8859-1') use ($ent_check, $utf8, $fix_utf8mb4) |
|
138 | 138 | { |
139 | 139 | return $fix_utf8mb4($ent_check(htmlspecialchars($string, $quote_style, $utf8 ? 'UTF-8' : $charset))); |
140 | 140 | }, |
141 | - 'htmltrim' => function ($string) use ($utf8, $space_chars, $ent_check) |
|
141 | + 'htmltrim' => function($string) use ($utf8, $space_chars, $ent_check) |
|
142 | 142 | { |
143 | 143 | return preg_replace('~^(?:[ \t\n\r\x0B\x00' . $space_chars . ']| )+|(?:[ \t\n\r\x0B\x00' . $space_chars . ']| )+$~' . ($utf8 ? 'u' : ''), '', $ent_check($string)); |
144 | 144 | }, |
145 | - 'strlen' => function ($string) use ($ent_list, $utf8, $ent_check) |
|
145 | + 'strlen' => function($string) use ($ent_list, $utf8, $ent_check) |
|
146 | 146 | { |
147 | 147 | return strlen(preg_replace('~' . $ent_list . ($utf8 ? '|.~u' : '~'), '_', $ent_check($string))); |
148 | 148 | }, |
149 | - 'strpos' => function ($haystack, $needle, $offset = 0) use ($utf8, $ent_check, $modSettings) |
|
149 | + 'strpos' => function($haystack, $needle, $offset = 0) use ($utf8, $ent_check, $modSettings) |
|
150 | 150 | { |
151 | 151 | $haystack_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|"|&|<|>| |.)~' . ($utf8 ? 'u' : ''), $ent_check($haystack), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
152 | 152 | |
@@ -171,12 +171,12 @@ discard block |
||
171 | 171 | return false; |
172 | 172 | } |
173 | 173 | }, |
174 | - 'substr' => function ($string, $start, $length = null) use ($utf8, $ent_check, $modSettings) |
|
174 | + 'substr' => function($string, $start, $length = null) use ($utf8, $ent_check, $modSettings) |
|
175 | 175 | { |
176 | 176 | $ent_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|"|&|<|>| |.)~' . ($utf8 ? 'u' : '') . '', $ent_check($string), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
177 | 177 | return $length === null ? implode('', array_slice($ent_arr, $start)) : implode('', array_slice($ent_arr, $start, $length)); |
178 | 178 | }, |
179 | - 'strtolower' => $utf8 ? function ($string) use ($sourcedir) |
|
179 | + 'strtolower' => $utf8 ? function($string) use ($sourcedir) |
|
180 | 180 | { |
181 | 181 | if (!function_exists('mb_strtolower')) |
182 | 182 | { |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | |
187 | 187 | return mb_strtolower($string, 'UTF-8'); |
188 | 188 | } : 'strtolower', |
189 | - 'strtoupper' => $utf8 ? function ($string) |
|
189 | + 'strtoupper' => $utf8 ? function($string) |
|
190 | 190 | { |
191 | 191 | global $sourcedir; |
192 | 192 | |
@@ -201,17 +201,17 @@ discard block |
||
201 | 201 | 'truncate' => function($string, $length) use ($utf8, $ent_check, $ent_list, &$smcFunc) |
202 | 202 | { |
203 | 203 | $string = $ent_check($string); |
204 | - preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~'. ($utf8 ? 'u' : ''), $string, $matches); |
|
204 | + preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches); |
|
205 | 205 | $string = $matches[0]; |
206 | 206 | while (strlen($string) > $length) |
207 | - $string = preg_replace('~(?:' . $ent_list . '|.)$~'. ($utf8 ? 'u' : ''), '', $string); |
|
207 | + $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
208 | 208 | return $string; |
209 | 209 | }, |
210 | - 'ucfirst' => $utf8 ? function ($string) use (&$smcFunc) |
|
210 | + 'ucfirst' => $utf8 ? function($string) use (&$smcFunc) |
|
211 | 211 | { |
212 | 212 | return $smcFunc['strtoupper']($smcFunc['substr']($string, 0, 1)) . $smcFunc['substr']($string, 1); |
213 | 213 | } : 'ucfirst', |
214 | - 'ucwords' => $utf8 ? function ($string) use (&$smcFunc) |
|
214 | + 'ucwords' => $utf8 ? function($string) use (&$smcFunc) |
|
215 | 215 | { |
216 | 216 | $words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE); |
217 | 217 | for ($i = 0, $n = count($words); $i < $n; $i += 2) |
@@ -610,7 +610,7 @@ discard block |
||
610 | 610 | else |
611 | 611 | { |
612 | 612 | // !!! Compatibility. |
613 | - $user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 :$user_settings['time_offset']; |
|
613 | + $user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset']; |
|
614 | 614 | } |
615 | 615 | } |
616 | 616 | // If the user is a guest, initialize all the critical user settings. |
@@ -1265,9 +1265,9 @@ discard block |
||
1265 | 1265 | if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) |
1266 | 1266 | $row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret); |
1267 | 1267 | |
1268 | - if ( isset($row['member_ip']) ) |
|
1268 | + if (isset($row['member_ip'])) |
|
1269 | 1269 | $row['member_ip'] = inet_dtop($row['member_ip']); |
1270 | - if ( isset($row['member_ip2']) ) |
|
1270 | + if (isset($row['member_ip2'])) |
|
1271 | 1271 | $row['member_ip2'] = inet_dtop($row['member_ip2']); |
1272 | 1272 | $new_loaded_ids[] = $row['id_member']; |
1273 | 1273 | $loaded_ids[] = $row['id_member']; |
@@ -1415,7 +1415,7 @@ discard block |
||
1415 | 1415 | 'name' => $profile['real_name'], |
1416 | 1416 | 'id' => $profile['id_member'], |
1417 | 1417 | 'href' => $scripturl . '?action=profile;u=' . $profile['id_member'], |
1418 | - 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $profile['id_member'] . '" title="' . $txt['profile_of'] . ' ' . $profile['real_name'] . '" '. (!empty($modSettings['onlineEnable']) ? 'class="pm_icon"' : '').'>' . $profile['real_name'] . '</a>', |
|
1418 | + 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $profile['id_member'] . '" title="' . $txt['profile_of'] . ' ' . $profile['real_name'] . '" ' . (!empty($modSettings['onlineEnable']) ? 'class="pm_icon"' : '') . '>' . $profile['real_name'] . '</a>', |
|
1419 | 1419 | 'email' => $profile['email_address'], |
1420 | 1420 | 'show_email' => !$user_info['is_guest'] && ($user_info['id'] == $profile['id_member'] || allowedTo('moderate_forum')), |
1421 | 1421 | 'registered' => empty($profile['date_registered']) ? $txt['not_applicable'] : timeformat($profile['date_registered']), |
@@ -1430,9 +1430,9 @@ discard block |
||
1430 | 1430 | $loadedLanguages = getLanguages(); |
1431 | 1431 | |
1432 | 1432 | $memberContext[$user] += array( |
1433 | - 'username_color' => '<span '. (!empty($profile['member_group_color']) ? 'style="color:'. $profile['member_group_color'] .';"' : '') .'>'. $profile['member_name'] .'</span>', |
|
1434 | - 'name_color' => '<span '. (!empty($profile['member_group_color']) ? 'style="color:'. $profile['member_group_color'] .';"' : '') .'>'. $profile['real_name'] .'</span>', |
|
1435 | - 'link_color' => '<a href="' . $scripturl . '?action=profile;u=' . $profile['id_member'] . '" title="' . $txt['profile_of'] . ' ' . $profile['real_name'] . '" '. (!empty($profile['member_group_color']) ? 'style="color:'. $profile['member_group_color'] .';"' : '') .'>' . $profile['real_name'] . '</a>', |
|
1433 | + 'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>', |
|
1434 | + 'name_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['real_name'] . '</span>', |
|
1435 | + 'link_color' => '<a href="' . $scripturl . '?action=profile;u=' . $profile['id_member'] . '" title="' . $txt['profile_of'] . ' ' . $profile['real_name'] . '" ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['real_name'] . '</a>', |
|
1436 | 1436 | 'is_buddy' => $profile['buddy'], |
1437 | 1437 | 'is_reverse_buddy' => in_array($user_info['id'], $buddy_list), |
1438 | 1438 | 'buddies' => $buddy_list, |
@@ -1502,7 +1502,7 @@ discard block |
||
1502 | 1502 | if (!empty($image)) |
1503 | 1503 | $memberContext[$user]['avatar'] = array( |
1504 | 1504 | 'name' => $profile['avatar'], |
1505 | - 'image' => '<img class="avatar" src="' . $image . '" alt="avatar_'. $profile['member_name'].'">', |
|
1505 | + 'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">', |
|
1506 | 1506 | 'href' => $image, |
1507 | 1507 | 'url' => $image, |
1508 | 1508 | ); |
@@ -2828,7 +2828,7 @@ discard block |
||
2828 | 2828 | $langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' '))); |
2829 | 2829 | |
2830 | 2830 | // Get the line we need. |
2831 | - $fp = @fopen($language_dir .'/'. $entry); |
|
2831 | + $fp = @fopen($language_dir . '/' . $entry); |
|
2832 | 2832 | |
2833 | 2833 | // Yay! |
2834 | 2834 | if ($fp) |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
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,27 +48,35 @@ 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 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
66 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
73 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
74 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
75 | + } |
|
67 | 76 | |
68 | - if (!empty($cache_enable)) |
|
69 | - cache_put_data('modSettings', $modSettings, 90); |
|
77 | + if (!empty($cache_enable)) { |
|
78 | + cache_put_data('modSettings', $modSettings, 90); |
|
79 | + } |
|
70 | 80 | } |
71 | 81 | |
72 | 82 | $modSettings['cache_enable'] = $cache_enable; |
@@ -86,8 +96,9 @@ discard block |
||
86 | 96 | }; |
87 | 97 | $fix_utf8mb4 = function ($string) use ($utf8) |
88 | 98 | { |
89 | - if (!$utf8) |
|
90 | - return $string; |
|
99 | + if (!$utf8) { |
|
100 | + return $string; |
|
101 | + } |
|
91 | 102 | |
92 | 103 | $i = 0; |
93 | 104 | $len = strlen($string); |
@@ -99,18 +110,15 @@ discard block |
||
99 | 110 | { |
100 | 111 | $new_string .= $string[$i]; |
101 | 112 | $i++; |
102 | - } |
|
103 | - elseif ($ord < 224) |
|
113 | + } elseif ($ord < 224) |
|
104 | 114 | { |
105 | 115 | $new_string .= $string[$i] . $string[$i+1]; |
106 | 116 | $i += 2; |
107 | - } |
|
108 | - elseif ($ord < 240) |
|
117 | + } elseif ($ord < 240) |
|
109 | 118 | { |
110 | 119 | $new_string .= $string[$i] . $string[$i+1] . $string[$i+2]; |
111 | 120 | $i += 3; |
112 | - } |
|
113 | - elseif ($ord < 248) |
|
121 | + } elseif ($ord < 248) |
|
114 | 122 | { |
115 | 123 | // Magic happens. |
116 | 124 | $val = (ord($string[$i]) & 0x07) << 18; |
@@ -154,8 +162,7 @@ discard block |
||
154 | 162 | { |
155 | 163 | $result = array_search($needle, array_slice($haystack_arr, $offset)); |
156 | 164 | return is_int($result) ? $result + $offset : false; |
157 | - } |
|
158 | - else |
|
165 | + } else |
|
159 | 166 | { |
160 | 167 | $needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|"|&|<|>| |.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
161 | 168 | $needle_size = count($needle_arr); |
@@ -164,8 +171,9 @@ discard block |
||
164 | 171 | while ((int) $result === $result) |
165 | 172 | { |
166 | 173 | $offset += $result; |
167 | - if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) |
|
168 | - return $offset; |
|
174 | + if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) { |
|
175 | + return $offset; |
|
176 | + } |
|
169 | 177 | $result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset)); |
170 | 178 | } |
171 | 179 | return false; |
@@ -203,8 +211,9 @@ discard block |
||
203 | 211 | $string = $ent_check($string); |
204 | 212 | preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~'. ($utf8 ? 'u' : ''), $string, $matches); |
205 | 213 | $string = $matches[0]; |
206 | - while (strlen($string) > $length) |
|
207 | - $string = preg_replace('~(?:' . $ent_list . '|.)$~'. ($utf8 ? 'u' : ''), '', $string); |
|
214 | + while (strlen($string) > $length) { |
|
215 | + $string = preg_replace('~(?:' . $ent_list . '|.)$~'. ($utf8 ? 'u' : ''), '', $string); |
|
216 | + } |
|
208 | 217 | return $string; |
209 | 218 | }, |
210 | 219 | 'ucfirst' => $utf8 ? function ($string) use (&$smcFunc) |
@@ -214,15 +223,17 @@ discard block |
||
214 | 223 | 'ucwords' => $utf8 ? function ($string) use (&$smcFunc) |
215 | 224 | { |
216 | 225 | $words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE); |
217 | - for ($i = 0, $n = count($words); $i < $n; $i += 2) |
|
218 | - $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
226 | + for ($i = 0, $n = count($words); $i < $n; $i += 2) { |
|
227 | + $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
228 | + } |
|
219 | 229 | return implode('', $words); |
220 | 230 | } : 'ucwords', |
221 | 231 | ); |
222 | 232 | |
223 | 233 | // Setting the timezone is a requirement for some functions. |
224 | - if (isset($modSettings['default_timezone'])) |
|
225 | - date_default_timezone_set($modSettings['default_timezone']); |
|
234 | + if (isset($modSettings['default_timezone'])) { |
|
235 | + date_default_timezone_set($modSettings['default_timezone']); |
|
236 | + } |
|
226 | 237 | |
227 | 238 | // Check the load averages? |
228 | 239 | if (!empty($modSettings['loadavg_enable'])) |
@@ -230,22 +241,26 @@ discard block |
||
230 | 241 | if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null) |
231 | 242 | { |
232 | 243 | $modSettings['load_average'] = @file_get_contents('/proc/loadavg'); |
233 | - if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) |
|
234 | - $modSettings['load_average'] = (float) $matches[1]; |
|
235 | - elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) |
|
236 | - $modSettings['load_average'] = (float) $matches[1]; |
|
237 | - else |
|
238 | - unset($modSettings['load_average']); |
|
244 | + if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) { |
|
245 | + $modSettings['load_average'] = (float) $matches[1]; |
|
246 | + } elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) { |
|
247 | + $modSettings['load_average'] = (float) $matches[1]; |
|
248 | + } else { |
|
249 | + unset($modSettings['load_average']); |
|
250 | + } |
|
239 | 251 | |
240 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
241 | - cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
252 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
253 | + cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
254 | + } |
|
242 | 255 | } |
243 | 256 | |
244 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
245 | - call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
257 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
258 | + call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
259 | + } |
|
246 | 260 | |
247 | - if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) |
|
248 | - display_loadavg_error(); |
|
261 | + if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) { |
|
262 | + display_loadavg_error(); |
|
263 | + } |
|
249 | 264 | } |
250 | 265 | |
251 | 266 | // Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is. |
@@ -266,8 +281,9 @@ discard block |
||
266 | 281 | if (defined('SMF_INTEGRATION_SETTINGS')) |
267 | 282 | { |
268 | 283 | $integration_settings = smf_json_decode(SMF_INTEGRATION_SETTINGS, true); |
269 | - foreach ($integration_settings as $hook => $function) |
|
270 | - add_integration_function($hook, $function, '', false); |
|
284 | + foreach ($integration_settings as $hook => $function) { |
|
285 | + add_integration_function($hook, $function, '', false); |
|
286 | + } |
|
271 | 287 | } |
272 | 288 | |
273 | 289 | // Any files to pre include? |
@@ -277,8 +293,9 @@ discard block |
||
277 | 293 | foreach ($pre_includes as $include) |
278 | 294 | { |
279 | 295 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
280 | - if (file_exists($include)) |
|
281 | - require_once($include); |
|
296 | + if (file_exists($include)) { |
|
297 | + require_once($include); |
|
298 | + } |
|
282 | 299 | } |
283 | 300 | } |
284 | 301 | |
@@ -382,27 +399,28 @@ discard block |
||
382 | 399 | break; |
383 | 400 | } |
384 | 401 | } |
402 | + } else { |
|
403 | + $id_member = 0; |
|
385 | 404 | } |
386 | - else |
|
387 | - $id_member = 0; |
|
388 | 405 | |
389 | 406 | if (empty($id_member) && isset($_COOKIE[$cookiename])) |
390 | 407 | { |
391 | 408 | $cookie_data = smf_json_decode($_COOKIE[$cookiename], true, false); |
392 | 409 | |
393 | - if (empty($cookie_data)) |
|
394 | - $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
410 | + if (empty($cookie_data)) { |
|
411 | + $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
412 | + } |
|
395 | 413 | |
396 | 414 | list ($id_member, $password) = $cookie_data; |
397 | 415 | $id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0; |
398 | - } |
|
399 | - elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
416 | + } elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
400 | 417 | { |
401 | 418 | // @todo Perhaps we can do some more checking on this, such as on the first octet of the IP? |
402 | 419 | $cookie_data = smf_json_decode($_SESSION['login_' . $cookiename]); |
403 | 420 | |
404 | - if (empty($cookie_data)) |
|
405 | - $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
421 | + if (empty($cookie_data)) { |
|
422 | + $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
423 | + } |
|
406 | 424 | |
407 | 425 | list ($id_member, $password, $login_span) = $cookie_data; |
408 | 426 | $id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0; |
@@ -427,30 +445,34 @@ discard block |
||
427 | 445 | $user_settings = $smcFunc['db_fetch_assoc']($request); |
428 | 446 | $smcFunc['db_free_result']($request); |
429 | 447 | |
430 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) |
|
431 | - $user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret); |
|
448 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) { |
|
449 | + $user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret); |
|
450 | + } |
|
432 | 451 | |
433 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
434 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
452 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
453 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
454 | + } |
|
435 | 455 | } |
436 | 456 | |
437 | 457 | // Did we find 'im? If not, junk it. |
438 | 458 | if (!empty($user_settings)) |
439 | 459 | { |
440 | 460 | // As much as the password should be right, we can assume the integration set things up. |
441 | - if (!empty($already_verified) && $already_verified === true) |
|
442 | - $check = true; |
|
461 | + if (!empty($already_verified) && $already_verified === true) { |
|
462 | + $check = true; |
|
463 | + } |
|
443 | 464 | // SHA-512 hash should be 128 characters long. |
444 | - elseif (strlen($password) == 128) |
|
445 | - $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
446 | - else |
|
447 | - $check = false; |
|
465 | + elseif (strlen($password) == 128) { |
|
466 | + $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
467 | + } else { |
|
468 | + $check = false; |
|
469 | + } |
|
448 | 470 | |
449 | 471 | // Wrong password or not activated - either way, you're going nowhere. |
450 | 472 | $id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0; |
473 | + } else { |
|
474 | + $id_member = 0; |
|
451 | 475 | } |
452 | - else |
|
453 | - $id_member = 0; |
|
454 | 476 | |
455 | 477 | // If we no longer have the member maybe they're being all hackey, stop brute force! |
456 | 478 | if (!$id_member) |
@@ -472,13 +494,15 @@ discard block |
||
472 | 494 | { |
473 | 495 | $tfa_data = smf_json_decode($_COOKIE[$tfacookie]); |
474 | 496 | |
475 | - if (is_null($tfa_data)) |
|
476 | - $tfa_data = safe_unserialize($_COOKIE[$tfacookie]); |
|
497 | + if (is_null($tfa_data)) { |
|
498 | + $tfa_data = safe_unserialize($_COOKIE[$tfacookie]); |
|
499 | + } |
|
477 | 500 | |
478 | 501 | list ($tfamember, $tfasecret) = $tfa_data; |
479 | 502 | |
480 | - if ((int) $tfamember != $id_member) |
|
481 | - $tfasecret = null; |
|
503 | + if ((int) $tfamember != $id_member) { |
|
504 | + $tfasecret = null; |
|
505 | + } |
|
482 | 506 | } |
483 | 507 | |
484 | 508 | if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret) |
@@ -498,10 +522,12 @@ discard block |
||
498 | 522 | // Are we forcing 2FA? Need to check if the user groups actually require 2FA |
499 | 523 | elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret'])) |
500 | 524 | { |
501 | - if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups |
|
525 | + if ($modSettings['tfa_mode'] == 2) { |
|
526 | + //only do this if we are just forcing SOME membergroups |
|
502 | 527 | { |
503 | 528 | //Build an array of ALL user membergroups. |
504 | 529 | $full_groups = array($user_settings['id_group']); |
530 | + } |
|
505 | 531 | if (!empty($user_settings['additional_groups'])) |
506 | 532 | { |
507 | 533 | $full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups'])); |
@@ -521,15 +547,17 @@ discard block |
||
521 | 547 | ); |
522 | 548 | $row = $smcFunc['db_fetch_assoc']($request); |
523 | 549 | $smcFunc['db_free_result']($request); |
550 | + } else { |
|
551 | + $row['total'] = 1; |
|
524 | 552 | } |
525 | - else |
|
526 | - $row['total'] = 1; //simplifies logics in the next "if" |
|
553 | + //simplifies logics in the next "if" |
|
527 | 554 | |
528 | 555 | $area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : ''; |
529 | 556 | $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : ''; |
530 | 557 | |
531 | - if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) |
|
532 | - redirectexit('action=profile;area=tfasetup;forced'); |
|
558 | + if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) { |
|
559 | + redirectexit('action=profile;area=tfasetup;forced'); |
|
560 | + } |
|
533 | 561 | } |
534 | 562 | } |
535 | 563 | |
@@ -566,33 +594,37 @@ discard block |
||
566 | 594 | 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'])); |
567 | 595 | $user_settings['last_login'] = time(); |
568 | 596 | |
569 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
570 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
597 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
598 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
599 | + } |
|
571 | 600 | |
572 | - if (!empty($modSettings['cache_enable'])) |
|
573 | - cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
601 | + if (!empty($modSettings['cache_enable'])) { |
|
602 | + cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
603 | + } |
|
574 | 604 | } |
605 | + } elseif (empty($_SESSION['id_msg_last_visit'])) { |
|
606 | + $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
575 | 607 | } |
576 | - elseif (empty($_SESSION['id_msg_last_visit'])) |
|
577 | - $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
578 | 608 | |
579 | 609 | $username = $user_settings['member_name']; |
580 | 610 | |
581 | - if (empty($user_settings['additional_groups'])) |
|
582 | - $user_info = array( |
|
611 | + if (empty($user_settings['additional_groups'])) { |
|
612 | + $user_info = array( |
|
583 | 613 | 'groups' => array($user_settings['id_group'], $user_settings['id_post_group']) |
584 | 614 | ); |
585 | - else |
|
586 | - $user_info = array( |
|
615 | + } else { |
|
616 | + $user_info = array( |
|
587 | 617 | 'groups' => array_merge( |
588 | 618 | array($user_settings['id_group'], $user_settings['id_post_group']), |
589 | 619 | explode(',', $user_settings['additional_groups']) |
590 | 620 | ) |
591 | 621 | ); |
622 | + } |
|
592 | 623 | |
593 | 624 | // Because history has proven that it is possible for groups to go bad - clean up in case. |
594 | - foreach ($user_info['groups'] as $k => $v) |
|
595 | - $user_info['groups'][$k] = (int) $v; |
|
625 | + foreach ($user_info['groups'] as $k => $v) { |
|
626 | + $user_info['groups'][$k] = (int) $v; |
|
627 | + } |
|
596 | 628 | |
597 | 629 | // This is a logged in user, so definitely not a spider. |
598 | 630 | $user_info['possibly_robot'] = false; |
@@ -606,8 +638,7 @@ discard block |
||
606 | 638 | $time_system = new DateTime('now', $tz_system); |
607 | 639 | $time_user = new DateTime('now', $tz_user); |
608 | 640 | $user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600; |
609 | - } |
|
610 | - else |
|
641 | + } else |
|
611 | 642 | { |
612 | 643 | // !!! Compatibility. |
613 | 644 | $user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 :$user_settings['time_offset']; |
@@ -621,16 +652,18 @@ discard block |
||
621 | 652 | $user_info = array('groups' => array(-1)); |
622 | 653 | $user_settings = array(); |
623 | 654 | |
624 | - if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) |
|
625 | - $_COOKIE[$cookiename] = ''; |
|
655 | + if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) { |
|
656 | + $_COOKIE[$cookiename] = ''; |
|
657 | + } |
|
626 | 658 | |
627 | 659 | // Expire the 2FA cookie |
628 | 660 | if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member'])) |
629 | 661 | { |
630 | 662 | $tfa_data = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true); |
631 | 663 | |
632 | - if (is_null($tfa_data)) |
|
633 | - $tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']); |
|
664 | + if (is_null($tfa_data)) { |
|
665 | + $tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']); |
|
666 | + } |
|
634 | 667 | |
635 | 668 | list ($id, $user, $exp, $state, $preserve) = $tfa_data; |
636 | 669 | |
@@ -642,19 +675,20 @@ discard block |
||
642 | 675 | } |
643 | 676 | |
644 | 677 | // Create a login token if it doesn't exist yet. |
645 | - if (!isset($_SESSION['token']['post-login'])) |
|
646 | - createToken('login'); |
|
647 | - else |
|
648 | - list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
678 | + if (!isset($_SESSION['token']['post-login'])) { |
|
679 | + createToken('login'); |
|
680 | + } else { |
|
681 | + list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
682 | + } |
|
649 | 683 | |
650 | 684 | // Do we perhaps think this is a search robot? Check every five minutes just in case... |
651 | 685 | if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300)) |
652 | 686 | { |
653 | 687 | require_once($sourcedir . '/ManageSearchEngines.php'); |
654 | 688 | $user_info['possibly_robot'] = SpiderCheck(); |
689 | + } elseif (!empty($modSettings['spider_mode'])) { |
|
690 | + $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
655 | 691 | } |
656 | - elseif (!empty($modSettings['spider_mode'])) |
|
657 | - $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
658 | 692 | // If we haven't turned on proper spider hunts then have a guess! |
659 | 693 | else |
660 | 694 | { |
@@ -702,8 +736,9 @@ discard block |
||
702 | 736 | $user_info['groups'] = array_unique($user_info['groups']); |
703 | 737 | |
704 | 738 | // 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. |
705 | - if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) |
|
706 | - unset($user_info['ignoreboards'][$tmp]); |
|
739 | + if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) { |
|
740 | + unset($user_info['ignoreboards'][$tmp]); |
|
741 | + } |
|
707 | 742 | |
708 | 743 | // Allow the user to change their language. |
709 | 744 | if (!empty($modSettings['userLanguage'])) |
@@ -716,31 +751,36 @@ discard block |
||
716 | 751 | $user_info['language'] = strtr($_GET['language'], './\\:', '____'); |
717 | 752 | |
718 | 753 | // Make it permanent for members. |
719 | - if (!empty($user_info['id'])) |
|
720 | - updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
721 | - else |
|
722 | - $_SESSION['language'] = $user_info['language']; |
|
754 | + if (!empty($user_info['id'])) { |
|
755 | + updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
756 | + } else { |
|
757 | + $_SESSION['language'] = $user_info['language']; |
|
758 | + } |
|
759 | + } elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) { |
|
760 | + $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
723 | 761 | } |
724 | - elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) |
|
725 | - $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
726 | 762 | } |
727 | 763 | |
728 | 764 | // Just build this here, it makes it easier to change/use - administrators can see all boards. |
729 | - if ($user_info['is_admin']) |
|
730 | - $user_info['query_see_board'] = '1=1'; |
|
765 | + if ($user_info['is_admin']) { |
|
766 | + $user_info['query_see_board'] = '1=1'; |
|
767 | + } |
|
731 | 768 | // Otherwise just the groups in $user_info['groups']. |
732 | - else |
|
733 | - $user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')'; |
|
769 | + else { |
|
770 | + $user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')'; |
|
771 | + } |
|
734 | 772 | |
735 | 773 | // Build the list of boards they WANT to see. |
736 | 774 | // This will take the place of query_see_boards in certain spots, so it better include the boards they can see also |
737 | 775 | |
738 | 776 | // If they aren't ignoring any boards then they want to see all the boards they can see |
739 | - if (empty($user_info['ignoreboards'])) |
|
740 | - $user_info['query_wanna_see_board'] = $user_info['query_see_board']; |
|
777 | + if (empty($user_info['ignoreboards'])) { |
|
778 | + $user_info['query_wanna_see_board'] = $user_info['query_see_board']; |
|
779 | + } |
|
741 | 780 | // Ok I guess they don't want to see all the boards |
742 | - else |
|
743 | - $user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))'; |
|
781 | + else { |
|
782 | + $user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))'; |
|
783 | + } |
|
744 | 784 | |
745 | 785 | call_integration_hook('integrate_user_info'); |
746 | 786 | } |
@@ -798,9 +838,9 @@ discard block |
||
798 | 838 | } |
799 | 839 | |
800 | 840 | // Remember redirection is the key to avoiding fallout from your bosses. |
801 | - if (!empty($topic)) |
|
802 | - redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
803 | - else |
|
841 | + if (!empty($topic)) { |
|
842 | + redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
843 | + } else |
|
804 | 844 | { |
805 | 845 | loadPermissions(); |
806 | 846 | loadTheme(); |
@@ -818,10 +858,11 @@ discard block |
||
818 | 858 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
819 | 859 | { |
820 | 860 | // @todo SLOW? |
821 | - if (!empty($topic)) |
|
822 | - $temp = cache_get_data('topic_board-' . $topic, 120); |
|
823 | - else |
|
824 | - $temp = cache_get_data('board-' . $board, 120); |
|
861 | + if (!empty($topic)) { |
|
862 | + $temp = cache_get_data('topic_board-' . $topic, 120); |
|
863 | + } else { |
|
864 | + $temp = cache_get_data('board-' . $board, 120); |
|
865 | + } |
|
825 | 866 | |
826 | 867 | if (!empty($temp)) |
827 | 868 | { |
@@ -859,8 +900,9 @@ discard block |
||
859 | 900 | $row = $smcFunc['db_fetch_assoc']($request); |
860 | 901 | |
861 | 902 | // Set the current board. |
862 | - if (!empty($row['id_board'])) |
|
863 | - $board = $row['id_board']; |
|
903 | + if (!empty($row['id_board'])) { |
|
904 | + $board = $row['id_board']; |
|
905 | + } |
|
864 | 906 | |
865 | 907 | // Basic operating information. (globals... :/) |
866 | 908 | $board_info = array( |
@@ -896,21 +938,23 @@ discard block |
||
896 | 938 | |
897 | 939 | do |
898 | 940 | { |
899 | - if (!empty($row['id_moderator'])) |
|
900 | - $board_info['moderators'][$row['id_moderator']] = array( |
|
941 | + if (!empty($row['id_moderator'])) { |
|
942 | + $board_info['moderators'][$row['id_moderator']] = array( |
|
901 | 943 | 'id' => $row['id_moderator'], |
902 | 944 | 'name' => $row['real_name'], |
903 | 945 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
904 | 946 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
905 | 947 | ); |
948 | + } |
|
906 | 949 | |
907 | - if (!empty($row['id_moderator_group'])) |
|
908 | - $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
950 | + if (!empty($row['id_moderator_group'])) { |
|
951 | + $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
909 | 952 | 'id' => $row['id_moderator_group'], |
910 | 953 | 'name' => $row['group_name'], |
911 | 954 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
912 | 955 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
913 | 956 | ); |
957 | + } |
|
914 | 958 | } |
915 | 959 | while ($row = $smcFunc['db_fetch_assoc']($request)); |
916 | 960 | |
@@ -942,12 +986,12 @@ discard block |
||
942 | 986 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
943 | 987 | { |
944 | 988 | // @todo SLOW? |
945 | - if (!empty($topic)) |
|
946 | - cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
989 | + if (!empty($topic)) { |
|
990 | + cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
991 | + } |
|
947 | 992 | cache_put_data('board-' . $board, $board_info, 120); |
948 | 993 | } |
949 | - } |
|
950 | - else |
|
994 | + } else |
|
951 | 995 | { |
952 | 996 | // Otherwise the topic is invalid, there are no moderators, etc. |
953 | 997 | $board_info = array( |
@@ -961,8 +1005,9 @@ discard block |
||
961 | 1005 | $smcFunc['db_free_result']($request); |
962 | 1006 | } |
963 | 1007 | |
964 | - if (!empty($topic)) |
|
965 | - $_GET['board'] = (int) $board; |
|
1008 | + if (!empty($topic)) { |
|
1009 | + $_GET['board'] = (int) $board; |
|
1010 | + } |
|
966 | 1011 | |
967 | 1012 | if (!empty($board)) |
968 | 1013 | { |
@@ -972,10 +1017,12 @@ discard block |
||
972 | 1017 | // Now check if the user is a moderator. |
973 | 1018 | $user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0; |
974 | 1019 | |
975 | - if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) |
|
976 | - $board_info['error'] = 'access'; |
|
977 | - if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) |
|
978 | - $board_info['error'] = 'access'; |
|
1020 | + if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) { |
|
1021 | + $board_info['error'] = 'access'; |
|
1022 | + } |
|
1023 | + if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) { |
|
1024 | + $board_info['error'] = 'access'; |
|
1025 | + } |
|
979 | 1026 | |
980 | 1027 | // Build up the linktree. |
981 | 1028 | $context['linktree'] = array_merge( |
@@ -998,8 +1045,9 @@ discard block |
||
998 | 1045 | $context['current_board'] = $board; |
999 | 1046 | |
1000 | 1047 | // No posting in redirection boards! |
1001 | - if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) |
|
1002 | - $board_info['error'] == 'post_in_redirect'; |
|
1048 | + if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) { |
|
1049 | + $board_info['error'] == 'post_in_redirect'; |
|
1050 | + } |
|
1003 | 1051 | |
1004 | 1052 | // Hacker... you can't see this topic, I'll tell you that. (but moderators can!) |
1005 | 1053 | if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod'])) |
@@ -1025,24 +1073,23 @@ discard block |
||
1025 | 1073 | ob_end_clean(); |
1026 | 1074 | header('HTTP/1.1 403 Forbidden'); |
1027 | 1075 | die; |
1028 | - } |
|
1029 | - elseif ($board_info['error'] == 'post_in_redirect') |
|
1076 | + } elseif ($board_info['error'] == 'post_in_redirect') |
|
1030 | 1077 | { |
1031 | 1078 | // Slightly different error message here... |
1032 | 1079 | fatal_lang_error('cannot_post_redirect', false); |
1033 | - } |
|
1034 | - elseif ($user_info['is_guest']) |
|
1080 | + } elseif ($user_info['is_guest']) |
|
1035 | 1081 | { |
1036 | 1082 | loadLanguage('Errors'); |
1037 | 1083 | is_not_guest($txt['topic_gone']); |
1084 | + } else { |
|
1085 | + fatal_lang_error('topic_gone', false); |
|
1038 | 1086 | } |
1039 | - else |
|
1040 | - fatal_lang_error('topic_gone', false); |
|
1041 | 1087 | } |
1042 | 1088 | |
1043 | - if ($user_info['is_mod']) |
|
1044 | - $user_info['groups'][] = 3; |
|
1045 | -} |
|
1089 | + if ($user_info['is_mod']) { |
|
1090 | + $user_info['groups'][] = 3; |
|
1091 | + } |
|
1092 | + } |
|
1046 | 1093 | |
1047 | 1094 | /** |
1048 | 1095 | * Load this user's permissions. |
@@ -1063,8 +1110,9 @@ discard block |
||
1063 | 1110 | asort($cache_groups); |
1064 | 1111 | $cache_groups = implode(',', $cache_groups); |
1065 | 1112 | // If it's a spider then cache it different. |
1066 | - if ($user_info['possibly_robot']) |
|
1067 | - $cache_groups .= '-spider'; |
|
1113 | + if ($user_info['possibly_robot']) { |
|
1114 | + $cache_groups .= '-spider'; |
|
1115 | + } |
|
1068 | 1116 | |
1069 | 1117 | if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
1070 | 1118 | { |
@@ -1072,9 +1120,9 @@ discard block |
||
1072 | 1120 | banPermissions(); |
1073 | 1121 | |
1074 | 1122 | return; |
1123 | + } elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) { |
|
1124 | + list ($user_info['permissions'], $removals) = $temp; |
|
1075 | 1125 | } |
1076 | - elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
|
1077 | - list ($user_info['permissions'], $removals) = $temp; |
|
1078 | 1126 | } |
1079 | 1127 | |
1080 | 1128 | // If it is detected as a robot, and we are restricting permissions as a special group - then implement this. |
@@ -1096,23 +1144,26 @@ discard block |
||
1096 | 1144 | $removals = array(); |
1097 | 1145 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1098 | 1146 | { |
1099 | - if (empty($row['add_deny'])) |
|
1100 | - $removals[] = $row['permission']; |
|
1101 | - else |
|
1102 | - $user_info['permissions'][] = $row['permission']; |
|
1147 | + if (empty($row['add_deny'])) { |
|
1148 | + $removals[] = $row['permission']; |
|
1149 | + } else { |
|
1150 | + $user_info['permissions'][] = $row['permission']; |
|
1151 | + } |
|
1103 | 1152 | } |
1104 | 1153 | $smcFunc['db_free_result']($request); |
1105 | 1154 | |
1106 | - if (isset($cache_groups)) |
|
1107 | - cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
1155 | + if (isset($cache_groups)) { |
|
1156 | + cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
1157 | + } |
|
1108 | 1158 | } |
1109 | 1159 | |
1110 | 1160 | // Get the board permissions. |
1111 | 1161 | if (!empty($board)) |
1112 | 1162 | { |
1113 | 1163 | // Make sure the board (if any) has been loaded by loadBoard(). |
1114 | - if (!isset($board_info['profile'])) |
|
1115 | - fatal_lang_error('no_board'); |
|
1164 | + if (!isset($board_info['profile'])) { |
|
1165 | + fatal_lang_error('no_board'); |
|
1166 | + } |
|
1116 | 1167 | |
1117 | 1168 | $request = $smcFunc['db_query']('', ' |
1118 | 1169 | SELECT permission, add_deny |
@@ -1128,20 +1179,23 @@ discard block |
||
1128 | 1179 | ); |
1129 | 1180 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1130 | 1181 | { |
1131 | - if (empty($row['add_deny'])) |
|
1132 | - $removals[] = $row['permission']; |
|
1133 | - else |
|
1134 | - $user_info['permissions'][] = $row['permission']; |
|
1182 | + if (empty($row['add_deny'])) { |
|
1183 | + $removals[] = $row['permission']; |
|
1184 | + } else { |
|
1185 | + $user_info['permissions'][] = $row['permission']; |
|
1186 | + } |
|
1135 | 1187 | } |
1136 | 1188 | $smcFunc['db_free_result']($request); |
1137 | 1189 | } |
1138 | 1190 | |
1139 | 1191 | // Remove all the permissions they shouldn't have ;). |
1140 | - if (!empty($modSettings['permission_enable_deny'])) |
|
1141 | - $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
1192 | + if (!empty($modSettings['permission_enable_deny'])) { |
|
1193 | + $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
1194 | + } |
|
1142 | 1195 | |
1143 | - if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) |
|
1144 | - cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
1196 | + if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) { |
|
1197 | + cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
1198 | + } |
|
1145 | 1199 | |
1146 | 1200 | // Banned? Watch, don't touch.. |
1147 | 1201 | banPermissions(); |
@@ -1153,17 +1207,18 @@ discard block |
||
1153 | 1207 | { |
1154 | 1208 | require_once($sourcedir . '/Subs-Auth.php'); |
1155 | 1209 | rebuildModCache(); |
1210 | + } else { |
|
1211 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
1156 | 1212 | } |
1157 | - else |
|
1158 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
1159 | 1213 | |
1160 | 1214 | // This is a useful phantom permission added to the current user, and only the current user while they are logged in. |
1161 | 1215 | // For example this drastically simplifies certain changes to the profile area. |
1162 | 1216 | $user_info['permissions'][] = 'is_not_guest'; |
1163 | 1217 | // And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions. |
1164 | 1218 | $user_info['permissions'][] = 'profile_view_own'; |
1165 | - if (in_array('profile_view', $user_info['permissions'])) |
|
1166 | - $user_info['permissions'][] = 'profile_view_any'; |
|
1219 | + if (in_array('profile_view', $user_info['permissions'])) { |
|
1220 | + $user_info['permissions'][] = 'profile_view_any'; |
|
1221 | + } |
|
1167 | 1222 | } |
1168 | 1223 | } |
1169 | 1224 | |
@@ -1181,8 +1236,9 @@ discard block |
||
1181 | 1236 | global $image_proxy_enabled, $image_proxy_secret, $boardurl; |
1182 | 1237 | |
1183 | 1238 | // Can't just look for no users :P. |
1184 | - if (empty($users)) |
|
1185 | - return array(); |
|
1239 | + if (empty($users)) { |
|
1240 | + return array(); |
|
1241 | + } |
|
1186 | 1242 | |
1187 | 1243 | // Pass the set value |
1188 | 1244 | $context['loadMemberContext_set'] = $set; |
@@ -1197,8 +1253,9 @@ discard block |
||
1197 | 1253 | for ($i = 0, $n = count($users); $i < $n; $i++) |
1198 | 1254 | { |
1199 | 1255 | $data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240); |
1200 | - if ($data == null) |
|
1201 | - continue; |
|
1256 | + if ($data == null) { |
|
1257 | + continue; |
|
1258 | + } |
|
1202 | 1259 | |
1203 | 1260 | $loaded_ids[] = $data['id_member']; |
1204 | 1261 | $user_profile[$data['id_member']] = $data; |
@@ -1262,13 +1319,16 @@ discard block |
||
1262 | 1319 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1263 | 1320 | { |
1264 | 1321 | // Take care of proxying avatar if required, do this here for maximum reach |
1265 | - if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) |
|
1266 | - $row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret); |
|
1322 | + if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) { |
|
1323 | + $row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret); |
|
1324 | + } |
|
1267 | 1325 | |
1268 | - if ( isset($row['member_ip']) ) |
|
1269 | - $row['member_ip'] = inet_dtop($row['member_ip']); |
|
1270 | - if ( isset($row['member_ip2']) ) |
|
1271 | - $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
1326 | + if ( isset($row['member_ip']) ) { |
|
1327 | + $row['member_ip'] = inet_dtop($row['member_ip']); |
|
1328 | + } |
|
1329 | + if ( isset($row['member_ip2']) ) { |
|
1330 | + $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
1331 | + } |
|
1272 | 1332 | $new_loaded_ids[] = $row['id_member']; |
1273 | 1333 | $loaded_ids[] = $row['id_member']; |
1274 | 1334 | $row['options'] = array(); |
@@ -1287,8 +1347,9 @@ discard block |
||
1287 | 1347 | 'loaded_ids' => $new_loaded_ids, |
1288 | 1348 | ) |
1289 | 1349 | ); |
1290 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1291 | - $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
1350 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1351 | + $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
1352 | + } |
|
1292 | 1353 | $smcFunc['db_free_result']($request); |
1293 | 1354 | } |
1294 | 1355 | |
@@ -1299,10 +1360,11 @@ discard block |
||
1299 | 1360 | { |
1300 | 1361 | foreach ($loaded_ids as $a_member) |
1301 | 1362 | { |
1302 | - if (!empty($user_profile[$a_member]['additional_groups'])) |
|
1303 | - $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
1304 | - else |
|
1305 | - $groups = array($user_profile[$a_member]['id_group']); |
|
1363 | + if (!empty($user_profile[$a_member]['additional_groups'])) { |
|
1364 | + $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
1365 | + } else { |
|
1366 | + $groups = array($user_profile[$a_member]['id_group']); |
|
1367 | + } |
|
1306 | 1368 | |
1307 | 1369 | $temp = array_intersect($groups, array_keys($board_info['moderator_groups'])); |
1308 | 1370 | |
@@ -1315,8 +1377,9 @@ discard block |
||
1315 | 1377 | |
1316 | 1378 | if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) |
1317 | 1379 | { |
1318 | - for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) |
|
1319 | - cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
1380 | + for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) { |
|
1381 | + cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
1382 | + } |
|
1320 | 1383 | } |
1321 | 1384 | |
1322 | 1385 | // Are we loading any moderators? If so, fix their group data... |
@@ -1342,14 +1405,17 @@ discard block |
||
1342 | 1405 | foreach ($temp_mods as $id) |
1343 | 1406 | { |
1344 | 1407 | // By popular demand, don't show admins or global moderators as moderators. |
1345 | - if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) |
|
1346 | - $user_profile[$id]['member_group'] = $row['member_group']; |
|
1408 | + if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) { |
|
1409 | + $user_profile[$id]['member_group'] = $row['member_group']; |
|
1410 | + } |
|
1347 | 1411 | |
1348 | 1412 | // If the Moderator group has no color or icons, but their group does... don't overwrite. |
1349 | - if (!empty($row['icons'])) |
|
1350 | - $user_profile[$id]['icons'] = $row['icons']; |
|
1351 | - if (!empty($row['member_group_color'])) |
|
1352 | - $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
1413 | + if (!empty($row['icons'])) { |
|
1414 | + $user_profile[$id]['icons'] = $row['icons']; |
|
1415 | + } |
|
1416 | + if (!empty($row['member_group_color'])) { |
|
1417 | + $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
1418 | + } |
|
1353 | 1419 | } |
1354 | 1420 | } |
1355 | 1421 | |
@@ -1371,12 +1437,14 @@ discard block |
||
1371 | 1437 | static $loadedLanguages = array(); |
1372 | 1438 | |
1373 | 1439 | // If this person's data is already loaded, skip it. |
1374 | - if (isset($dataLoaded[$user])) |
|
1375 | - return true; |
|
1440 | + if (isset($dataLoaded[$user])) { |
|
1441 | + return true; |
|
1442 | + } |
|
1376 | 1443 | |
1377 | 1444 | // We can't load guests or members not loaded by loadMemberData()! |
1378 | - if ($user == 0) |
|
1379 | - return false; |
|
1445 | + if ($user == 0) { |
|
1446 | + return false; |
|
1447 | + } |
|
1380 | 1448 | if (!isset($user_profile[$user])) |
1381 | 1449 | { |
1382 | 1450 | trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING); |
@@ -1402,12 +1470,16 @@ discard block |
||
1402 | 1470 | $buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array(); |
1403 | 1471 | |
1404 | 1472 | //We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme |
1405 | - if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists |
|
1473 | + if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) { |
|
1474 | + //icon is set and exists |
|
1406 | 1475 | $group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1]; |
1407 | - elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default |
|
1476 | + } elseif (isset($profile['icons'][1])) { |
|
1477 | + //icon is set and doesn't exist, fallback to default |
|
1408 | 1478 | $group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1]; |
1409 | - else //not set, bye bye |
|
1479 | + } else { |
|
1480 | + //not set, bye bye |
|
1410 | 1481 | $group_icon_url = ''; |
1482 | + } |
|
1411 | 1483 | |
1412 | 1484 | // These minimal values are always loaded |
1413 | 1485 | $memberContext[$user] = array( |
@@ -1426,8 +1498,9 @@ discard block |
||
1426 | 1498 | if ($context['loadMemberContext_set'] != 'minimal') |
1427 | 1499 | { |
1428 | 1500 | // Go the extra mile and load the user's native language name. |
1429 | - if (empty($loadedLanguages)) |
|
1430 | - $loadedLanguages = getLanguages(); |
|
1501 | + if (empty($loadedLanguages)) { |
|
1502 | + $loadedLanguages = getLanguages(); |
|
1503 | + } |
|
1431 | 1504 | |
1432 | 1505 | $memberContext[$user] += array( |
1433 | 1506 | 'username_color' => '<span '. (!empty($profile['member_group_color']) ? 'style="color:'. $profile['member_group_color'] .';"' : '') .'>'. $profile['member_name'] .'</span>', |
@@ -1481,31 +1554,33 @@ discard block |
||
1481 | 1554 | { |
1482 | 1555 | if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://'))) |
1483 | 1556 | { |
1484 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) |
|
1485 | - $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
1486 | - else |
|
1487 | - $image = get_gravatar_url($profile['email_address']); |
|
1488 | - } |
|
1489 | - else |
|
1557 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) { |
|
1558 | + $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
1559 | + } else { |
|
1560 | + $image = get_gravatar_url($profile['email_address']); |
|
1561 | + } |
|
1562 | + } else |
|
1490 | 1563 | { |
1491 | 1564 | // So it's stored in the member table? |
1492 | 1565 | if (!empty($profile['avatar'])) |
1493 | 1566 | { |
1494 | 1567 | $image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']; |
1568 | + } elseif (!empty($profile['filename'])) { |
|
1569 | + $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
1495 | 1570 | } |
1496 | - elseif (!empty($profile['filename'])) |
|
1497 | - $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
1498 | 1571 | // Right... no avatar...use the default one |
1499 | - else |
|
1500 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
1572 | + else { |
|
1573 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
1574 | + } |
|
1501 | 1575 | } |
1502 | - if (!empty($image)) |
|
1503 | - $memberContext[$user]['avatar'] = array( |
|
1576 | + if (!empty($image)) { |
|
1577 | + $memberContext[$user]['avatar'] = array( |
|
1504 | 1578 | 'name' => $profile['avatar'], |
1505 | 1579 | 'image' => '<img class="avatar" src="' . $image . '" alt="avatar_'. $profile['member_name'].'">', |
1506 | 1580 | 'href' => $image, |
1507 | 1581 | 'url' => $image, |
1508 | 1582 | ); |
1583 | + } |
|
1509 | 1584 | } |
1510 | 1585 | |
1511 | 1586 | // Are we also loading the members custom fields into context? |
@@ -1513,35 +1588,41 @@ discard block |
||
1513 | 1588 | { |
1514 | 1589 | $memberContext[$user]['custom_fields'] = array(); |
1515 | 1590 | |
1516 | - if (!isset($context['display_fields'])) |
|
1517 | - $context['display_fields'] = smf_json_decode($modSettings['displayFields'], true); |
|
1591 | + if (!isset($context['display_fields'])) { |
|
1592 | + $context['display_fields'] = smf_json_decode($modSettings['displayFields'], true); |
|
1593 | + } |
|
1518 | 1594 | |
1519 | 1595 | foreach ($context['display_fields'] as $custom) |
1520 | 1596 | { |
1521 | - if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) |
|
1522 | - continue; |
|
1597 | + if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) { |
|
1598 | + continue; |
|
1599 | + } |
|
1523 | 1600 | |
1524 | 1601 | $value = $profile['options'][$custom['col_name']]; |
1525 | 1602 | |
1526 | 1603 | // Don't show the "disabled" option for the "gender" field. |
1527 | - if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') |
|
1528 | - continue; |
|
1604 | + if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') { |
|
1605 | + continue; |
|
1606 | + } |
|
1529 | 1607 | |
1530 | 1608 | // BBC? |
1531 | - if ($custom['bbc']) |
|
1532 | - $value = parse_bbc($value); |
|
1609 | + if ($custom['bbc']) { |
|
1610 | + $value = parse_bbc($value); |
|
1611 | + } |
|
1533 | 1612 | // ... or checkbox? |
1534 | - elseif (isset($custom['type']) && $custom['type'] == 'check') |
|
1535 | - $value = $value ? $txt['yes'] : $txt['no']; |
|
1613 | + elseif (isset($custom['type']) && $custom['type'] == 'check') { |
|
1614 | + $value = $value ? $txt['yes'] : $txt['no']; |
|
1615 | + } |
|
1536 | 1616 | |
1537 | 1617 | // Enclosing the user input within some other text? |
1538 | - if (!empty($custom['enclose'])) |
|
1539 | - $value = strtr($custom['enclose'], array( |
|
1618 | + if (!empty($custom['enclose'])) { |
|
1619 | + $value = strtr($custom['enclose'], array( |
|
1540 | 1620 | '{SCRIPTURL}' => $scripturl, |
1541 | 1621 | '{IMAGES_URL}' => $settings['images_url'], |
1542 | 1622 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
1543 | 1623 | '{INPUT}' => $value, |
1544 | 1624 | )); |
1625 | + } |
|
1545 | 1626 | |
1546 | 1627 | $memberContext[$user]['custom_fields'][] = array( |
1547 | 1628 | 'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'], |
@@ -1568,8 +1649,9 @@ discard block |
||
1568 | 1649 | global $smcFunc, $txt, $scripturl, $settings; |
1569 | 1650 | |
1570 | 1651 | // Do not waste my time... |
1571 | - if (empty($users) || empty($params)) |
|
1572 | - return false; |
|
1652 | + if (empty($users) || empty($params)) { |
|
1653 | + return false; |
|
1654 | + } |
|
1573 | 1655 | |
1574 | 1656 | // Make sure it's an array. |
1575 | 1657 | $users = !is_array($users) ? array($users) : array_unique($users); |
@@ -1593,31 +1675,36 @@ discard block |
||
1593 | 1675 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1594 | 1676 | { |
1595 | 1677 | // BBC? |
1596 | - if (!empty($row['bbc'])) |
|
1597 | - $row['value'] = parse_bbc($row['value']); |
|
1678 | + if (!empty($row['bbc'])) { |
|
1679 | + $row['value'] = parse_bbc($row['value']); |
|
1680 | + } |
|
1598 | 1681 | |
1599 | 1682 | // ... or checkbox? |
1600 | - elseif (isset($row['type']) && $row['type'] == 'check') |
|
1601 | - $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
1683 | + elseif (isset($row['type']) && $row['type'] == 'check') { |
|
1684 | + $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
1685 | + } |
|
1602 | 1686 | |
1603 | 1687 | // Enclosing the user input within some other text? |
1604 | - if (!empty($row['enclose'])) |
|
1605 | - $row['value'] = strtr($row['enclose'], array( |
|
1688 | + if (!empty($row['enclose'])) { |
|
1689 | + $row['value'] = strtr($row['enclose'], array( |
|
1606 | 1690 | '{SCRIPTURL}' => $scripturl, |
1607 | 1691 | '{IMAGES_URL}' => $settings['images_url'], |
1608 | 1692 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
1609 | 1693 | '{INPUT}' => un_htmlspecialchars($row['value']), |
1610 | 1694 | )); |
1695 | + } |
|
1611 | 1696 | |
1612 | 1697 | // Send a simple array if there is just 1 param |
1613 | - if (count($params) == 1) |
|
1614 | - $return[$row['id_member']] = $row; |
|
1698 | + if (count($params) == 1) { |
|
1699 | + $return[$row['id_member']] = $row; |
|
1700 | + } |
|
1615 | 1701 | |
1616 | 1702 | // More than 1? knock yourself out... |
1617 | 1703 | else |
1618 | 1704 | { |
1619 | - if (!isset($return[$row['id_member']])) |
|
1620 | - $return[$row['id_member']] = array(); |
|
1705 | + if (!isset($return[$row['id_member']])) { |
|
1706 | + $return[$row['id_member']] = array(); |
|
1707 | + } |
|
1621 | 1708 | |
1622 | 1709 | $return[$row['id_member']][$row['variable']] = $row; |
1623 | 1710 | } |
@@ -1651,8 +1738,9 @@ discard block |
||
1651 | 1738 | global $context; |
1652 | 1739 | |
1653 | 1740 | // Don't know any browser! |
1654 | - if (empty($context['browser'])) |
|
1655 | - detectBrowser(); |
|
1741 | + if (empty($context['browser'])) { |
|
1742 | + detectBrowser(); |
|
1743 | + } |
|
1656 | 1744 | |
1657 | 1745 | return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false; |
1658 | 1746 | } |
@@ -1670,8 +1758,9 @@ discard block |
||
1670 | 1758 | global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled; |
1671 | 1759 | |
1672 | 1760 | // The theme was specified by parameter. |
1673 | - if (!empty($id_theme)) |
|
1674 | - $id_theme = (int) $id_theme; |
|
1761 | + if (!empty($id_theme)) { |
|
1762 | + $id_theme = (int) $id_theme; |
|
1763 | + } |
|
1675 | 1764 | // The theme was specified by REQUEST. |
1676 | 1765 | elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
1677 | 1766 | { |
@@ -1679,51 +1768,58 @@ discard block |
||
1679 | 1768 | $_SESSION['id_theme'] = $id_theme; |
1680 | 1769 | } |
1681 | 1770 | // The theme was specified by REQUEST... previously. |
1682 | - elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
|
1683 | - $id_theme = (int) $_SESSION['id_theme']; |
|
1771 | + elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) { |
|
1772 | + $id_theme = (int) $_SESSION['id_theme']; |
|
1773 | + } |
|
1684 | 1774 | // The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.) |
1685 | - elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) |
|
1686 | - $id_theme = $user_info['theme']; |
|
1775 | + elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) { |
|
1776 | + $id_theme = $user_info['theme']; |
|
1777 | + } |
|
1687 | 1778 | // The theme was specified by the board. |
1688 | - elseif (!empty($board_info['theme'])) |
|
1689 | - $id_theme = $board_info['theme']; |
|
1779 | + elseif (!empty($board_info['theme'])) { |
|
1780 | + $id_theme = $board_info['theme']; |
|
1781 | + } |
|
1690 | 1782 | // The theme is the forum's default. |
1691 | - else |
|
1692 | - $id_theme = $modSettings['theme_guests']; |
|
1783 | + else { |
|
1784 | + $id_theme = $modSettings['theme_guests']; |
|
1785 | + } |
|
1693 | 1786 | |
1694 | 1787 | // Verify the id_theme... no foul play. |
1695 | 1788 | // Always allow the board specific theme, if they are overriding. |
1696 | - if (!empty($board_info['theme']) && $board_info['override_theme']) |
|
1697 | - $id_theme = $board_info['theme']; |
|
1789 | + if (!empty($board_info['theme']) && $board_info['override_theme']) { |
|
1790 | + $id_theme = $board_info['theme']; |
|
1791 | + } |
|
1698 | 1792 | // If they have specified a particular theme to use with SSI allow it to be used. |
1699 | - elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) |
|
1700 | - $id_theme = (int) $id_theme; |
|
1701 | - elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
1793 | + elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) { |
|
1794 | + $id_theme = (int) $id_theme; |
|
1795 | + } elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
1702 | 1796 | { |
1703 | 1797 | $themes = explode(',', $modSettings['enableThemes']); |
1704 | - if (!in_array($id_theme, $themes)) |
|
1705 | - $id_theme = $modSettings['theme_guests']; |
|
1706 | - else |
|
1798 | + if (!in_array($id_theme, $themes)) { |
|
1799 | + $id_theme = $modSettings['theme_guests']; |
|
1800 | + } else { |
|
1801 | + $id_theme = (int) $id_theme; |
|
1802 | + } |
|
1803 | + } else { |
|
1707 | 1804 | $id_theme = (int) $id_theme; |
1708 | 1805 | } |
1709 | - else |
|
1710 | - $id_theme = (int) $id_theme; |
|
1711 | 1806 | |
1712 | 1807 | $member = empty($user_info['id']) ? -1 : $user_info['id']; |
1713 | 1808 | |
1714 | 1809 | // Disable image proxy if we don't have SSL enabled |
1715 | - if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) |
|
1716 | - $image_proxy_enabled = false; |
|
1810 | + if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) { |
|
1811 | + $image_proxy_enabled = false; |
|
1812 | + } |
|
1717 | 1813 | |
1718 | 1814 | 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']) |
1719 | 1815 | { |
1720 | 1816 | $themeData = $temp; |
1721 | 1817 | $flag = true; |
1818 | + } elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) { |
|
1819 | + $themeData = $temp + array($member => array()); |
|
1820 | + } else { |
|
1821 | + $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
1722 | 1822 | } |
1723 | - elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) |
|
1724 | - $themeData = $temp + array($member => array()); |
|
1725 | - else |
|
1726 | - $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
1727 | 1823 | |
1728 | 1824 | if (empty($flag)) |
1729 | 1825 | { |
@@ -1742,31 +1838,37 @@ discard block |
||
1742 | 1838 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
1743 | 1839 | { |
1744 | 1840 | // There are just things we shouldn't be able to change as members. |
1745 | - 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'))) |
|
1746 | - continue; |
|
1841 | + 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'))) { |
|
1842 | + continue; |
|
1843 | + } |
|
1747 | 1844 | |
1748 | 1845 | // If this is the theme_dir of the default theme, store it. |
1749 | - if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) |
|
1750 | - $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
1846 | + if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) { |
|
1847 | + $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
1848 | + } |
|
1751 | 1849 | |
1752 | 1850 | // If this isn't set yet, is a theme option, or is not the default theme.. |
1753 | - if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') |
|
1754 | - $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
1851 | + if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') { |
|
1852 | + $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
1853 | + } |
|
1755 | 1854 | } |
1756 | 1855 | $smcFunc['db_free_result']($result); |
1757 | 1856 | |
1758 | - if (!empty($themeData[-1])) |
|
1759 | - foreach ($themeData[-1] as $k => $v) |
|
1857 | + if (!empty($themeData[-1])) { |
|
1858 | + foreach ($themeData[-1] as $k => $v) |
|
1760 | 1859 | { |
1761 | 1860 | if (!isset($themeData[$member][$k])) |
1762 | 1861 | $themeData[$member][$k] = $v; |
1862 | + } |
|
1763 | 1863 | } |
1764 | 1864 | |
1765 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
1766 | - cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
1865 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
1866 | + cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
1867 | + } |
|
1767 | 1868 | // Only if we didn't already load that part of the cache... |
1768 | - elseif (!isset($temp)) |
|
1769 | - cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
1869 | + elseif (!isset($temp)) { |
|
1870 | + cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
1871 | + } |
|
1770 | 1872 | } |
1771 | 1873 | |
1772 | 1874 | $settings = $themeData[0]; |
@@ -1783,20 +1885,24 @@ discard block |
||
1783 | 1885 | $settings['template_dirs'][] = $settings['theme_dir']; |
1784 | 1886 | |
1785 | 1887 | // Based on theme (if there is one). |
1786 | - if (!empty($settings['base_theme_dir'])) |
|
1787 | - $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
1888 | + if (!empty($settings['base_theme_dir'])) { |
|
1889 | + $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
1890 | + } |
|
1788 | 1891 | |
1789 | 1892 | // Lastly the default theme. |
1790 | - if ($settings['theme_dir'] != $settings['default_theme_dir']) |
|
1791 | - $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
1893 | + if ($settings['theme_dir'] != $settings['default_theme_dir']) { |
|
1894 | + $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
1895 | + } |
|
1792 | 1896 | |
1793 | - if (!$initialize) |
|
1794 | - return; |
|
1897 | + if (!$initialize) { |
|
1898 | + return; |
|
1899 | + } |
|
1795 | 1900 | |
1796 | 1901 | // Check to see if we're forcing SSL |
1797 | 1902 | if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) && |
1798 | - (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') |
|
1799 | - redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://'))); |
|
1903 | + (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') { |
|
1904 | + redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://'))); |
|
1905 | + } |
|
1800 | 1906 | |
1801 | 1907 | // Check to see if they're accessing it from the wrong place. |
1802 | 1908 | if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME'])) |
@@ -1804,8 +1910,9 @@ discard block |
||
1804 | 1910 | $detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://'; |
1805 | 1911 | $detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']; |
1806 | 1912 | $temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')); |
1807 | - if ($temp != '/') |
|
1808 | - $detected_url .= $temp; |
|
1913 | + if ($temp != '/') { |
|
1914 | + $detected_url .= $temp; |
|
1915 | + } |
|
1809 | 1916 | } |
1810 | 1917 | if (isset($detected_url) && $detected_url != $boardurl) |
1811 | 1918 | { |
@@ -1817,8 +1924,9 @@ discard block |
||
1817 | 1924 | foreach ($aliases as $alias) |
1818 | 1925 | { |
1819 | 1926 | // Rip off all the boring parts, spaces, etc. |
1820 | - if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) |
|
1821 | - $do_fix = true; |
|
1927 | + if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) { |
|
1928 | + $do_fix = true; |
|
1929 | + } |
|
1822 | 1930 | } |
1823 | 1931 | } |
1824 | 1932 | |
@@ -1826,20 +1934,22 @@ discard block |
||
1826 | 1934 | if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI') |
1827 | 1935 | { |
1828 | 1936 | // Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;). |
1829 | - if (empty($_GET)) |
|
1830 | - redirectexit('wwwRedirect'); |
|
1831 | - else |
|
1937 | + if (empty($_GET)) { |
|
1938 | + redirectexit('wwwRedirect'); |
|
1939 | + } else |
|
1832 | 1940 | { |
1833 | 1941 | list ($k, $v) = each($_GET); |
1834 | 1942 | |
1835 | - if ($k != 'wwwRedirect') |
|
1836 | - redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
1943 | + if ($k != 'wwwRedirect') { |
|
1944 | + redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
1945 | + } |
|
1837 | 1946 | } |
1838 | 1947 | } |
1839 | 1948 | |
1840 | 1949 | // #3 is just a check for SSL... |
1841 | - if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) |
|
1842 | - $do_fix = true; |
|
1950 | + if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) { |
|
1951 | + $do_fix = true; |
|
1952 | + } |
|
1843 | 1953 | |
1844 | 1954 | // Okay, #4 - perhaps it's an IP address? We're gonna want to use that one, then. (assuming it's the IP or something...) |
1845 | 1955 | if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1) |
@@ -1873,8 +1983,9 @@ discard block |
||
1873 | 1983 | $board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl)); |
1874 | 1984 | } |
1875 | 1985 | } |
1876 | - foreach ($context['linktree'] as $k => $dummy) |
|
1877 | - $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
1986 | + foreach ($context['linktree'] as $k => $dummy) { |
|
1987 | + $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
1988 | + } |
|
1878 | 1989 | } |
1879 | 1990 | } |
1880 | 1991 | // Set up the contextual user array. |
@@ -1893,16 +2004,16 @@ discard block |
||
1893 | 2004 | 'email' => $user_info['email'], |
1894 | 2005 | 'ignoreusers' => $user_info['ignoreusers'], |
1895 | 2006 | ); |
1896 | - if (!$context['user']['is_guest']) |
|
1897 | - $context['user']['name'] = $user_info['name']; |
|
1898 | - elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) |
|
1899 | - $context['user']['name'] = $txt['guest_title']; |
|
2007 | + if (!$context['user']['is_guest']) { |
|
2008 | + $context['user']['name'] = $user_info['name']; |
|
2009 | + } elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) { |
|
2010 | + $context['user']['name'] = $txt['guest_title']; |
|
2011 | + } |
|
1900 | 2012 | |
1901 | 2013 | // Determine the current smiley set. |
1902 | 2014 | $user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set']; |
1903 | 2015 | $context['user']['smiley_set'] = $user_info['smiley_set']; |
1904 | - } |
|
1905 | - else |
|
2016 | + } else |
|
1906 | 2017 | { |
1907 | 2018 | $context['user'] = array( |
1908 | 2019 | 'id' => -1, |
@@ -1918,18 +2029,24 @@ discard block |
||
1918 | 2029 | } |
1919 | 2030 | |
1920 | 2031 | // Some basic information... |
1921 | - if (!isset($context['html_headers'])) |
|
1922 | - $context['html_headers'] = ''; |
|
1923 | - if (!isset($context['javascript_files'])) |
|
1924 | - $context['javascript_files'] = array(); |
|
1925 | - if (!isset($context['css_files'])) |
|
1926 | - $context['css_files'] = array(); |
|
1927 | - if (!isset($context['css_header'])) |
|
1928 | - $context['css_header'] = array(); |
|
1929 | - if (!isset($context['javascript_inline'])) |
|
1930 | - $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
1931 | - if (!isset($context['javascript_vars'])) |
|
1932 | - $context['javascript_vars'] = array(); |
|
2032 | + if (!isset($context['html_headers'])) { |
|
2033 | + $context['html_headers'] = ''; |
|
2034 | + } |
|
2035 | + if (!isset($context['javascript_files'])) { |
|
2036 | + $context['javascript_files'] = array(); |
|
2037 | + } |
|
2038 | + if (!isset($context['css_files'])) { |
|
2039 | + $context['css_files'] = array(); |
|
2040 | + } |
|
2041 | + if (!isset($context['css_header'])) { |
|
2042 | + $context['css_header'] = array(); |
|
2043 | + } |
|
2044 | + if (!isset($context['javascript_inline'])) { |
|
2045 | + $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
2046 | + } |
|
2047 | + if (!isset($context['javascript_vars'])) { |
|
2048 | + $context['javascript_vars'] = array(); |
|
2049 | + } |
|
1933 | 2050 | |
1934 | 2051 | $context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2'; |
1935 | 2052 | $context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | '; |
@@ -1941,8 +2058,9 @@ discard block |
||
1941 | 2058 | $context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null; |
1942 | 2059 | $context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null; |
1943 | 2060 | $context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3; |
1944 | - if (isset($modSettings['load_average'])) |
|
1945 | - $context['load_average'] = $modSettings['load_average']; |
|
2061 | + if (isset($modSettings['load_average'])) { |
|
2062 | + $context['load_average'] = $modSettings['load_average']; |
|
2063 | + } |
|
1946 | 2064 | |
1947 | 2065 | // Detect the browser. This is separated out because it's also used in attachment downloads |
1948 | 2066 | detectBrowser(); |
@@ -1956,8 +2074,9 @@ discard block |
||
1956 | 2074 | // This allows sticking some HTML on the page output - useful for controls. |
1957 | 2075 | $context['insert_after_template'] = ''; |
1958 | 2076 | |
1959 | - if (!isset($txt)) |
|
1960 | - $txt = array(); |
|
2077 | + if (!isset($txt)) { |
|
2078 | + $txt = array(); |
|
2079 | + } |
|
1961 | 2080 | |
1962 | 2081 | $simpleActions = array( |
1963 | 2082 | 'findmember', |
@@ -2003,9 +2122,10 @@ discard block |
||
2003 | 2122 | |
2004 | 2123 | // See if theres any extra param to check. |
2005 | 2124 | $requiresXML = false; |
2006 | - foreach ($extraParams as $key => $extra) |
|
2007 | - if (isset($_REQUEST[$extra])) |
|
2125 | + foreach ($extraParams as $key => $extra) { |
|
2126 | + if (isset($_REQUEST[$extra])) |
|
2008 | 2127 | $requiresXML = true; |
2128 | + } |
|
2009 | 2129 | |
2010 | 2130 | // Output is fully XML, so no need for the index template. |
2011 | 2131 | if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML)) |
@@ -2020,37 +2140,39 @@ discard block |
||
2020 | 2140 | { |
2021 | 2141 | loadLanguage('index+Modifications'); |
2022 | 2142 | $context['template_layers'] = array(); |
2023 | - } |
|
2024 | - |
|
2025 | - else |
|
2143 | + } else |
|
2026 | 2144 | { |
2027 | 2145 | // Custom templates to load, or just default? |
2028 | - if (isset($settings['theme_templates'])) |
|
2029 | - $templates = explode(',', $settings['theme_templates']); |
|
2030 | - else |
|
2031 | - $templates = array('index'); |
|
2146 | + if (isset($settings['theme_templates'])) { |
|
2147 | + $templates = explode(',', $settings['theme_templates']); |
|
2148 | + } else { |
|
2149 | + $templates = array('index'); |
|
2150 | + } |
|
2032 | 2151 | |
2033 | 2152 | // Load each template... |
2034 | - foreach ($templates as $template) |
|
2035 | - loadTemplate($template); |
|
2153 | + foreach ($templates as $template) { |
|
2154 | + loadTemplate($template); |
|
2155 | + } |
|
2036 | 2156 | |
2037 | 2157 | // ...and attempt to load their associated language files. |
2038 | 2158 | $required_files = implode('+', array_merge($templates, array('Modifications'))); |
2039 | 2159 | loadLanguage($required_files, '', false); |
2040 | 2160 | |
2041 | 2161 | // Custom template layers? |
2042 | - if (isset($settings['theme_layers'])) |
|
2043 | - $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
2044 | - else |
|
2045 | - $context['template_layers'] = array('html', 'body'); |
|
2162 | + if (isset($settings['theme_layers'])) { |
|
2163 | + $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
2164 | + } else { |
|
2165 | + $context['template_layers'] = array('html', 'body'); |
|
2166 | + } |
|
2046 | 2167 | } |
2047 | 2168 | |
2048 | 2169 | // Initialize the theme. |
2049 | 2170 | loadSubTemplate('init', 'ignore'); |
2050 | 2171 | |
2051 | 2172 | // Allow overriding the board wide time/number formats. |
2052 | - if (empty($user_settings['time_format']) && !empty($txt['time_format'])) |
|
2053 | - $user_info['time_format'] = $txt['time_format']; |
|
2173 | + if (empty($user_settings['time_format']) && !empty($txt['time_format'])) { |
|
2174 | + $user_info['time_format'] = $txt['time_format']; |
|
2175 | + } |
|
2054 | 2176 | |
2055 | 2177 | // Set the character set from the template. |
2056 | 2178 | $context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']; |
@@ -2058,12 +2180,14 @@ discard block |
||
2058 | 2180 | $context['right_to_left'] = !empty($txt['lang_rtl']); |
2059 | 2181 | |
2060 | 2182 | // Guests may still need a name. |
2061 | - if ($context['user']['is_guest'] && empty($context['user']['name'])) |
|
2062 | - $context['user']['name'] = $txt['guest_title']; |
|
2183 | + if ($context['user']['is_guest'] && empty($context['user']['name'])) { |
|
2184 | + $context['user']['name'] = $txt['guest_title']; |
|
2185 | + } |
|
2063 | 2186 | |
2064 | 2187 | // Any theme-related strings that need to be loaded? |
2065 | - if (!empty($settings['require_theme_strings'])) |
|
2066 | - loadLanguage('ThemeStrings', '', false); |
|
2188 | + if (!empty($settings['require_theme_strings'])) { |
|
2189 | + loadLanguage('ThemeStrings', '', false); |
|
2190 | + } |
|
2067 | 2191 | |
2068 | 2192 | // Make a special URL for the language. |
2069 | 2193 | $settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']); |
@@ -2074,8 +2198,9 @@ discard block |
||
2074 | 2198 | // Here is my luvly Responsive CSS |
2075 | 2199 | loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive'); |
2076 | 2200 | |
2077 | - if ($context['right_to_left']) |
|
2078 | - loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
2201 | + if ($context['right_to_left']) { |
|
2202 | + loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
2203 | + } |
|
2079 | 2204 | |
2080 | 2205 | // We allow theme variants, because we're cool. |
2081 | 2206 | $context['theme_variant'] = ''; |
@@ -2083,14 +2208,17 @@ discard block |
||
2083 | 2208 | if (!empty($settings['theme_variants'])) |
2084 | 2209 | { |
2085 | 2210 | // Overriding - for previews and that ilk. |
2086 | - if (!empty($_REQUEST['variant'])) |
|
2087 | - $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
2211 | + if (!empty($_REQUEST['variant'])) { |
|
2212 | + $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
2213 | + } |
|
2088 | 2214 | // User selection? |
2089 | - if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) |
|
2090 | - $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
2215 | + if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) { |
|
2216 | + $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
2217 | + } |
|
2091 | 2218 | // If not a user variant, select the default. |
2092 | - if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) |
|
2093 | - $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
2219 | + if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) { |
|
2220 | + $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
2221 | + } |
|
2094 | 2222 | |
2095 | 2223 | // Do this to keep things easier in the templates. |
2096 | 2224 | $context['theme_variant'] = '_' . $context['theme_variant']; |
@@ -2099,20 +2227,23 @@ discard block |
||
2099 | 2227 | if (!empty($context['theme_variant'])) |
2100 | 2228 | { |
2101 | 2229 | loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']); |
2102 | - if ($context['right_to_left']) |
|
2103 | - loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
2230 | + if ($context['right_to_left']) { |
|
2231 | + loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
2232 | + } |
|
2104 | 2233 | } |
2105 | 2234 | } |
2106 | 2235 | |
2107 | 2236 | // Let's be compatible with old themes! |
2108 | - if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) |
|
2109 | - $context['template_layers'] = array('main'); |
|
2237 | + if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) { |
|
2238 | + $context['template_layers'] = array('main'); |
|
2239 | + } |
|
2110 | 2240 | |
2111 | 2241 | $context['tabindex'] = 1; |
2112 | 2242 | |
2113 | 2243 | // Compatibility. |
2114 | - if (!isset($settings['theme_version'])) |
|
2115 | - $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
2244 | + if (!isset($settings['theme_version'])) { |
|
2245 | + $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
2246 | + } |
|
2116 | 2247 | |
2117 | 2248 | // Default JS variables for use in every theme |
2118 | 2249 | $context['javascript_vars'] = array( |
@@ -2131,18 +2262,18 @@ discard block |
||
2131 | 2262 | ); |
2132 | 2263 | |
2133 | 2264 | // Add the JQuery library to the list of files to load. |
2134 | - if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') |
|
2135 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2136 | - |
|
2137 | - elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') |
|
2138 | - loadJavaScriptFile('jquery-2.1.4.min.js', array('seed' => false), 'smf_jquery'); |
|
2139 | - |
|
2140 | - elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') |
|
2141 | - loadJavaScriptFile($modSettings['jquery_custom'], array(), 'smf_jquery'); |
|
2265 | + if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') { |
|
2266 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2267 | + } elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') { |
|
2268 | + loadJavaScriptFile('jquery-2.1.4.min.js', array('seed' => false), 'smf_jquery'); |
|
2269 | + } elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') { |
|
2270 | + loadJavaScriptFile($modSettings['jquery_custom'], array(), 'smf_jquery'); |
|
2271 | + } |
|
2142 | 2272 | |
2143 | 2273 | // Auto loading? template_javascript() will take care of the local half of this. |
2144 | - else |
|
2145 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2274 | + else { |
|
2275 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2276 | + } |
|
2146 | 2277 | |
2147 | 2278 | // Queue our JQuery plugins! |
2148 | 2279 | loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins'); |
@@ -2165,12 +2296,12 @@ discard block |
||
2165 | 2296 | require_once($sourcedir . '/ScheduledTasks.php'); |
2166 | 2297 | |
2167 | 2298 | // What to do, what to do?! |
2168 | - if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) |
|
2169 | - AutoTask(); |
|
2170 | - else |
|
2171 | - ReduceMailQueue(); |
|
2172 | - } |
|
2173 | - else |
|
2299 | + if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) { |
|
2300 | + AutoTask(); |
|
2301 | + } else { |
|
2302 | + ReduceMailQueue(); |
|
2303 | + } |
|
2304 | + } else |
|
2174 | 2305 | { |
2175 | 2306 | $type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq'; |
2176 | 2307 | $ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time']; |
@@ -2221,8 +2352,9 @@ discard block |
||
2221 | 2352 | foreach ($theme_includes as $include) |
2222 | 2353 | { |
2223 | 2354 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
2224 | - if (file_exists($include)) |
|
2225 | - require_once($include); |
|
2355 | + if (file_exists($include)) { |
|
2356 | + require_once($include); |
|
2357 | + } |
|
2226 | 2358 | } |
2227 | 2359 | } |
2228 | 2360 | |
@@ -2252,16 +2384,19 @@ discard block |
||
2252 | 2384 | // Do any style sheets first, cause we're easy with those. |
2253 | 2385 | if (!empty($style_sheets)) |
2254 | 2386 | { |
2255 | - if (!is_array($style_sheets)) |
|
2256 | - $style_sheets = array($style_sheets); |
|
2387 | + if (!is_array($style_sheets)) { |
|
2388 | + $style_sheets = array($style_sheets); |
|
2389 | + } |
|
2257 | 2390 | |
2258 | - foreach ($style_sheets as $sheet) |
|
2259 | - loadCSSFile($sheet . '.css', array(), $sheet); |
|
2391 | + foreach ($style_sheets as $sheet) { |
|
2392 | + loadCSSFile($sheet . '.css', array(), $sheet); |
|
2393 | + } |
|
2260 | 2394 | } |
2261 | 2395 | |
2262 | 2396 | // No template to load? |
2263 | - if ($template_name === false) |
|
2264 | - return true; |
|
2397 | + if ($template_name === false) { |
|
2398 | + return true; |
|
2399 | + } |
|
2265 | 2400 | |
2266 | 2401 | $loaded = false; |
2267 | 2402 | foreach ($settings['template_dirs'] as $template_dir) |
@@ -2276,12 +2411,14 @@ discard block |
||
2276 | 2411 | |
2277 | 2412 | if ($loaded) |
2278 | 2413 | { |
2279 | - if ($db_show_debug === true) |
|
2280 | - $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
2414 | + if ($db_show_debug === true) { |
|
2415 | + $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
2416 | + } |
|
2281 | 2417 | |
2282 | 2418 | // If they have specified an initialization function for this template, go ahead and call it now. |
2283 | - if (function_exists('template_' . $template_name . '_init')) |
|
2284 | - call_user_func('template_' . $template_name . '_init'); |
|
2419 | + if (function_exists('template_' . $template_name . '_init')) { |
|
2420 | + call_user_func('template_' . $template_name . '_init'); |
|
2421 | + } |
|
2285 | 2422 | } |
2286 | 2423 | // Hmmm... doesn't exist?! I don't suppose the directory is wrong, is it? |
2287 | 2424 | elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default')) |
@@ -2301,13 +2438,14 @@ discard block |
||
2301 | 2438 | loadTemplate($template_name); |
2302 | 2439 | } |
2303 | 2440 | // Cause an error otherwise. |
2304 | - elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) |
|
2305 | - fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
2306 | - elseif ($fatal) |
|
2307 | - 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')); |
|
2308 | - else |
|
2309 | - return false; |
|
2310 | -} |
|
2441 | + elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) { |
|
2442 | + fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
2443 | + } elseif ($fatal) { |
|
2444 | + 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')); |
|
2445 | + } else { |
|
2446 | + return false; |
|
2447 | + } |
|
2448 | + } |
|
2311 | 2449 | |
2312 | 2450 | /** |
2313 | 2451 | * Load a sub-template. |
@@ -2325,17 +2463,19 @@ discard block |
||
2325 | 2463 | { |
2326 | 2464 | global $context, $txt, $db_show_debug; |
2327 | 2465 | |
2328 | - if ($db_show_debug === true) |
|
2329 | - $context['debug']['sub_templates'][] = $sub_template_name; |
|
2466 | + if ($db_show_debug === true) { |
|
2467 | + $context['debug']['sub_templates'][] = $sub_template_name; |
|
2468 | + } |
|
2330 | 2469 | |
2331 | 2470 | // Figure out what the template function is named. |
2332 | 2471 | $theme_function = 'template_' . $sub_template_name; |
2333 | - if (function_exists($theme_function)) |
|
2334 | - $theme_function(); |
|
2335 | - elseif ($fatal === false) |
|
2336 | - fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
2337 | - elseif ($fatal !== 'ignore') |
|
2338 | - 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')); |
|
2472 | + if (function_exists($theme_function)) { |
|
2473 | + $theme_function(); |
|
2474 | + } elseif ($fatal === false) { |
|
2475 | + fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
2476 | + } elseif ($fatal !== 'ignore') { |
|
2477 | + 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')); |
|
2478 | + } |
|
2339 | 2479 | |
2340 | 2480 | // Are we showing debugging for templates? Just make sure not to do it before the doctype... |
2341 | 2481 | if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml'])) |
@@ -2372,8 +2512,9 @@ discard block |
||
2372 | 2512 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
2373 | 2513 | |
2374 | 2514 | // If this is an external file, automatically set this to false. |
2375 | - if (!empty($params['external'])) |
|
2376 | - $params['minimize'] = false; |
|
2515 | + if (!empty($params['external'])) { |
|
2516 | + $params['minimize'] = false; |
|
2517 | + } |
|
2377 | 2518 | |
2378 | 2519 | // Account for shorthand like admin.css?alp21 filenames |
2379 | 2520 | $has_seed = strpos($fileName, '.css?'); |
@@ -2390,13 +2531,10 @@ discard block |
||
2390 | 2531 | { |
2391 | 2532 | $fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2392 | 2533 | $filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2534 | + } else { |
|
2535 | + $fileUrl = false; |
|
2393 | 2536 | } |
2394 | - |
|
2395 | - else |
|
2396 | - $fileUrl = false; |
|
2397 | - } |
|
2398 | - |
|
2399 | - else |
|
2537 | + } else |
|
2400 | 2538 | { |
2401 | 2539 | $fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2402 | 2540 | $filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2411,12 +2549,14 @@ discard block |
||
2411 | 2549 | } |
2412 | 2550 | |
2413 | 2551 | // Add it to the array for use in the template |
2414 | - if (!empty($fileName)) |
|
2415 | - $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2552 | + if (!empty($fileName)) { |
|
2553 | + $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2554 | + } |
|
2416 | 2555 | |
2417 | - if (!empty($context['right_to_left']) && !empty($params['rtl'])) |
|
2418 | - loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
2419 | -} |
|
2556 | + if (!empty($context['right_to_left']) && !empty($params['rtl'])) { |
|
2557 | + loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
2558 | + } |
|
2559 | + } |
|
2420 | 2560 | |
2421 | 2561 | /** |
2422 | 2562 | * Add a block of inline css code to be executed later |
@@ -2433,8 +2573,9 @@ discard block |
||
2433 | 2573 | global $context; |
2434 | 2574 | |
2435 | 2575 | // Gotta add something... |
2436 | - if (empty($css)) |
|
2437 | - return false; |
|
2576 | + if (empty($css)) { |
|
2577 | + return false; |
|
2578 | + } |
|
2438 | 2579 | |
2439 | 2580 | $context['css_header'][] = $css; |
2440 | 2581 | } |
@@ -2469,8 +2610,9 @@ discard block |
||
2469 | 2610 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
2470 | 2611 | |
2471 | 2612 | // If this is an external file, automatically set this to false. |
2472 | - if (!empty($params['external'])) |
|
2473 | - $params['minimize'] = false; |
|
2613 | + if (!empty($params['external'])) { |
|
2614 | + $params['minimize'] = false; |
|
2615 | + } |
|
2474 | 2616 | |
2475 | 2617 | // Account for shorthand like admin.js?alp21 filenames |
2476 | 2618 | $has_seed = strpos($fileName, '.js?'); |
@@ -2487,16 +2629,12 @@ discard block |
||
2487 | 2629 | { |
2488 | 2630 | $fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2489 | 2631 | $filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2490 | - } |
|
2491 | - |
|
2492 | - else |
|
2632 | + } else |
|
2493 | 2633 | { |
2494 | 2634 | $fileUrl = false; |
2495 | 2635 | $filePath = false; |
2496 | 2636 | } |
2497 | - } |
|
2498 | - |
|
2499 | - else |
|
2637 | + } else |
|
2500 | 2638 | { |
2501 | 2639 | $fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2502 | 2640 | $filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2511,9 +2649,10 @@ discard block |
||
2511 | 2649 | } |
2512 | 2650 | |
2513 | 2651 | // Add it to the array for use in the template |
2514 | - if (!empty($fileName)) |
|
2515 | - $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2516 | -} |
|
2652 | + if (!empty($fileName)) { |
|
2653 | + $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2654 | + } |
|
2655 | + } |
|
2517 | 2656 | |
2518 | 2657 | /** |
2519 | 2658 | * Add a Javascript variable for output later (for feeding text strings and similar to JS) |
@@ -2527,9 +2666,10 @@ discard block |
||
2527 | 2666 | { |
2528 | 2667 | global $context; |
2529 | 2668 | |
2530 | - if (!empty($key) && (!empty($value) || $value === '0')) |
|
2531 | - $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
2532 | -} |
|
2669 | + if (!empty($key) && (!empty($value) || $value === '0')) { |
|
2670 | + $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
2671 | + } |
|
2672 | + } |
|
2533 | 2673 | |
2534 | 2674 | /** |
2535 | 2675 | * Add a block of inline Javascript code to be executed later |
@@ -2546,8 +2686,9 @@ discard block |
||
2546 | 2686 | { |
2547 | 2687 | global $context; |
2548 | 2688 | |
2549 | - if (empty($javascript)) |
|
2550 | - return false; |
|
2689 | + if (empty($javascript)) { |
|
2690 | + return false; |
|
2691 | + } |
|
2551 | 2692 | |
2552 | 2693 | $context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript; |
2553 | 2694 | } |
@@ -2568,15 +2709,18 @@ discard block |
||
2568 | 2709 | static $already_loaded = array(); |
2569 | 2710 | |
2570 | 2711 | // Default to the user's language. |
2571 | - if ($lang == '') |
|
2572 | - $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
2712 | + if ($lang == '') { |
|
2713 | + $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
2714 | + } |
|
2573 | 2715 | |
2574 | 2716 | // Do we want the English version of language file as fallback? |
2575 | - if (empty($modSettings['disable_language_fallback']) && $lang != 'english') |
|
2576 | - loadLanguage($template_name, 'english', false); |
|
2717 | + if (empty($modSettings['disable_language_fallback']) && $lang != 'english') { |
|
2718 | + loadLanguage($template_name, 'english', false); |
|
2719 | + } |
|
2577 | 2720 | |
2578 | - if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) |
|
2579 | - return $lang; |
|
2721 | + if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) { |
|
2722 | + return $lang; |
|
2723 | + } |
|
2580 | 2724 | |
2581 | 2725 | // Make sure we have $settings - if not we're in trouble and need to find it! |
2582 | 2726 | if (empty($settings['default_theme_dir'])) |
@@ -2587,8 +2731,9 @@ discard block |
||
2587 | 2731 | |
2588 | 2732 | // What theme are we in? |
2589 | 2733 | $theme_name = basename($settings['theme_url']); |
2590 | - if (empty($theme_name)) |
|
2591 | - $theme_name = 'unknown'; |
|
2734 | + if (empty($theme_name)) { |
|
2735 | + $theme_name = 'unknown'; |
|
2736 | + } |
|
2592 | 2737 | |
2593 | 2738 | // For each file open it up and write it out! |
2594 | 2739 | foreach (explode('+', $template_name) as $template) |
@@ -2667,8 +2812,9 @@ discard block |
||
2667 | 2812 | } |
2668 | 2813 | |
2669 | 2814 | // Keep track of what we're up to soldier. |
2670 | - if ($db_show_debug === true) |
|
2671 | - $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
2815 | + if ($db_show_debug === true) { |
|
2816 | + $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
2817 | + } |
|
2672 | 2818 | |
2673 | 2819 | // Remember what we have loaded, and in which language. |
2674 | 2820 | $already_loaded[$template_name] = $lang; |
@@ -2714,8 +2860,9 @@ discard block |
||
2714 | 2860 | ) |
2715 | 2861 | ); |
2716 | 2862 | // In the EXTREMELY unlikely event this happens, give an error message. |
2717 | - if ($smcFunc['db_num_rows']($result) == 0) |
|
2718 | - fatal_lang_error('parent_not_found', 'critical'); |
|
2863 | + if ($smcFunc['db_num_rows']($result) == 0) { |
|
2864 | + fatal_lang_error('parent_not_found', 'critical'); |
|
2865 | + } |
|
2719 | 2866 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
2720 | 2867 | { |
2721 | 2868 | if (!isset($boards[$row['id_board']])) |
@@ -2732,8 +2879,8 @@ discard block |
||
2732 | 2879 | ); |
2733 | 2880 | } |
2734 | 2881 | // If a moderator exists for this board, add that moderator for all children too. |
2735 | - if (!empty($row['id_moderator'])) |
|
2736 | - foreach ($boards as $id => $dummy) |
|
2882 | + if (!empty($row['id_moderator'])) { |
|
2883 | + foreach ($boards as $id => $dummy) |
|
2737 | 2884 | { |
2738 | 2885 | $boards[$id]['moderators'][$row['id_moderator']] = array( |
2739 | 2886 | 'id' => $row['id_moderator'], |
@@ -2741,11 +2888,12 @@ discard block |
||
2741 | 2888 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
2742 | 2889 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
2743 | 2890 | ); |
2891 | + } |
|
2744 | 2892 | } |
2745 | 2893 | |
2746 | 2894 | // If a moderator group exists for this board, add that moderator group for all children too |
2747 | - if (!empty($row['id_moderator_group'])) |
|
2748 | - foreach ($boards as $id => $dummy) |
|
2895 | + if (!empty($row['id_moderator_group'])) { |
|
2896 | + foreach ($boards as $id => $dummy) |
|
2749 | 2897 | { |
2750 | 2898 | $boards[$id]['moderator_groups'][$row['id_moderator_group']] = array( |
2751 | 2899 | 'id' => $row['id_moderator_group'], |
@@ -2753,6 +2901,7 @@ discard block |
||
2753 | 2901 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
2754 | 2902 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
2755 | 2903 | ); |
2904 | + } |
|
2756 | 2905 | } |
2757 | 2906 | } |
2758 | 2907 | $smcFunc['db_free_result']($result); |
@@ -2780,23 +2929,27 @@ discard block |
||
2780 | 2929 | if (!$use_cache || ($context['languages'] = cache_get_data('known_languages' . ($favor_utf8 ? '' : '_all'), !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null) |
2781 | 2930 | { |
2782 | 2931 | // If we don't have our ucwords function defined yet, let's load the settings data. |
2783 | - if (empty($smcFunc['ucwords'])) |
|
2784 | - reloadSettings(); |
|
2932 | + if (empty($smcFunc['ucwords'])) { |
|
2933 | + reloadSettings(); |
|
2934 | + } |
|
2785 | 2935 | |
2786 | 2936 | // If we don't have our theme information yet, let's get it. |
2787 | - if (empty($settings['default_theme_dir'])) |
|
2788 | - loadTheme(0, false); |
|
2937 | + if (empty($settings['default_theme_dir'])) { |
|
2938 | + loadTheme(0, false); |
|
2939 | + } |
|
2789 | 2940 | |
2790 | 2941 | // Default language directories to try. |
2791 | 2942 | $language_directories = array( |
2792 | 2943 | $settings['default_theme_dir'] . '/languages', |
2793 | 2944 | ); |
2794 | - if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) |
|
2795 | - $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
2945 | + if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) { |
|
2946 | + $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
2947 | + } |
|
2796 | 2948 | |
2797 | 2949 | // We possibly have a base theme directory. |
2798 | - if (!empty($settings['base_theme_dir'])) |
|
2799 | - $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
2950 | + if (!empty($settings['base_theme_dir'])) { |
|
2951 | + $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
2952 | + } |
|
2800 | 2953 | |
2801 | 2954 | // Remove any duplicates. |
2802 | 2955 | $language_directories = array_unique($language_directories); |
@@ -2810,20 +2963,21 @@ discard block |
||
2810 | 2963 | foreach ($language_directories as $language_dir) |
2811 | 2964 | { |
2812 | 2965 | // Can't look in here... doesn't exist! |
2813 | - if (!file_exists($language_dir)) |
|
2814 | - continue; |
|
2966 | + if (!file_exists($language_dir)) { |
|
2967 | + continue; |
|
2968 | + } |
|
2815 | 2969 | |
2816 | 2970 | $dir = dir($language_dir); |
2817 | 2971 | while ($entry = $dir->read()) |
2818 | 2972 | { |
2819 | 2973 | // Look for the index language file.... |
2820 | - if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches)) |
|
2821 | - continue; |
|
2822 | - |
|
2823 | - if (!empty($langList) && !empty($langList[$matches[1]])) |
|
2824 | - $langName = $langList[$matches[1]]; |
|
2974 | + if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches)) { |
|
2975 | + continue; |
|
2976 | + } |
|
2825 | 2977 | |
2826 | - else |
|
2978 | + if (!empty($langList) && !empty($langList[$matches[1]])) { |
|
2979 | + $langName = $langList[$matches[1]]; |
|
2980 | + } else |
|
2827 | 2981 | { |
2828 | 2982 | $langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' '))); |
2829 | 2983 | |
@@ -2866,20 +3020,23 @@ discard block |
||
2866 | 3020 | } |
2867 | 3021 | |
2868 | 3022 | // Do we need to store the lang list? |
2869 | - if (empty($langList)) |
|
2870 | - updateSettings(array('langList' => json_encode($catchLang))); |
|
3023 | + if (empty($langList)) { |
|
3024 | + updateSettings(array('langList' => json_encode($catchLang))); |
|
3025 | + } |
|
2871 | 3026 | |
2872 | 3027 | // Favoring UTF8? Then prevent us from selecting non-UTF8 versions. |
2873 | 3028 | if ($favor_utf8) |
2874 | 3029 | { |
2875 | - foreach ($context['languages'] as $lang) |
|
2876 | - if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8'])) |
|
3030 | + foreach ($context['languages'] as $lang) { |
|
3031 | + if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8'])) |
|
2877 | 3032 | unset($context['languages'][$lang['filename']]); |
3033 | + } |
|
2878 | 3034 | } |
2879 | 3035 | |
2880 | 3036 | // Let's cash in on this deal. |
2881 | - if (!empty($modSettings['cache_enable'])) |
|
2882 | - cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
3037 | + if (!empty($modSettings['cache_enable'])) { |
|
3038 | + cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
3039 | + } |
|
2883 | 3040 | } |
2884 | 3041 | |
2885 | 3042 | return $context['languages']; |
@@ -2902,8 +3059,9 @@ discard block |
||
2902 | 3059 | global $modSettings, $options, $txt; |
2903 | 3060 | static $censor_vulgar = null, $censor_proper; |
2904 | 3061 | |
2905 | - if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') |
|
2906 | - return $text; |
|
3062 | + if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') { |
|
3063 | + return $text; |
|
3064 | + } |
|
2907 | 3065 | |
2908 | 3066 | // If they haven't yet been loaded, load them. |
2909 | 3067 | if ($censor_vulgar == null) |
@@ -2931,9 +3089,9 @@ discard block |
||
2931 | 3089 | { |
2932 | 3090 | $func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace'; |
2933 | 3091 | $text = $func($censor_vulgar, $censor_proper, $text); |
3092 | + } else { |
|
3093 | + $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
2934 | 3094 | } |
2935 | - else |
|
2936 | - $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
2937 | 3095 | |
2938 | 3096 | return $text; |
2939 | 3097 | } |
@@ -2959,38 +3117,42 @@ discard block |
||
2959 | 3117 | @ini_set('track_errors', '1'); |
2960 | 3118 | |
2961 | 3119 | // Don't include the file more than once, if $once is true. |
2962 | - if ($once && in_array($filename, $templates)) |
|
2963 | - return; |
|
3120 | + if ($once && in_array($filename, $templates)) { |
|
3121 | + return; |
|
3122 | + } |
|
2964 | 3123 | // Add this file to the include list, whether $once is true or not. |
2965 | - else |
|
2966 | - $templates[] = $filename; |
|
3124 | + else { |
|
3125 | + $templates[] = $filename; |
|
3126 | + } |
|
2967 | 3127 | |
2968 | 3128 | // Are we going to use eval? |
2969 | 3129 | if (empty($modSettings['disableTemplateEval'])) |
2970 | 3130 | { |
2971 | 3131 | $file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false; |
2972 | 3132 | $settings['current_include_filename'] = $filename; |
2973 | - } |
|
2974 | - else |
|
3133 | + } else |
|
2975 | 3134 | { |
2976 | 3135 | $file_found = file_exists($filename); |
2977 | 3136 | |
2978 | - if ($once && $file_found) |
|
2979 | - require_once($filename); |
|
2980 | - elseif ($file_found) |
|
2981 | - require($filename); |
|
3137 | + if ($once && $file_found) { |
|
3138 | + require_once($filename); |
|
3139 | + } elseif ($file_found) { |
|
3140 | + require($filename); |
|
3141 | + } |
|
2982 | 3142 | } |
2983 | 3143 | |
2984 | 3144 | if ($file_found !== true) |
2985 | 3145 | { |
2986 | 3146 | ob_end_clean(); |
2987 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
2988 | - @ob_start('ob_gzhandler'); |
|
2989 | - else |
|
2990 | - ob_start(); |
|
3147 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
3148 | + @ob_start('ob_gzhandler'); |
|
3149 | + } else { |
|
3150 | + ob_start(); |
|
3151 | + } |
|
2991 | 3152 | |
2992 | - if (isset($_GET['debug'])) |
|
2993 | - header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3153 | + if (isset($_GET['debug'])) { |
|
3154 | + header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3155 | + } |
|
2994 | 3156 | |
2995 | 3157 | // Don't cache error pages!! |
2996 | 3158 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -3009,12 +3171,13 @@ discard block |
||
3009 | 3171 | echo '<!DOCTYPE html> |
3010 | 3172 | <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '> |
3011 | 3173 | <head>'; |
3012 | - if (isset($context['character_set'])) |
|
3013 | - echo ' |
|
3174 | + if (isset($context['character_set'])) { |
|
3175 | + echo ' |
|
3014 | 3176 | <meta charset="', $context['character_set'], '">'; |
3177 | + } |
|
3015 | 3178 | |
3016 | - if (!empty($maintenance) && !allowedTo('admin_forum')) |
|
3017 | - echo ' |
|
3179 | + if (!empty($maintenance) && !allowedTo('admin_forum')) { |
|
3180 | + echo ' |
|
3018 | 3181 | <title>', $mtitle, '</title> |
3019 | 3182 | </head> |
3020 | 3183 | <body> |
@@ -3022,8 +3185,8 @@ discard block |
||
3022 | 3185 | ', $mmessage, ' |
3023 | 3186 | </body> |
3024 | 3187 | </html>'; |
3025 | - elseif (!allowedTo('admin_forum')) |
|
3026 | - echo ' |
|
3188 | + } elseif (!allowedTo('admin_forum')) { |
|
3189 | + echo ' |
|
3027 | 3190 | <title>', $txt['template_parse_error'], '</title> |
3028 | 3191 | </head> |
3029 | 3192 | <body> |
@@ -3031,15 +3194,17 @@ discard block |
||
3031 | 3194 | ', $txt['template_parse_error_message'], ' |
3032 | 3195 | </body> |
3033 | 3196 | </html>'; |
3034 | - else |
|
3197 | + } else |
|
3035 | 3198 | { |
3036 | 3199 | require_once($sourcedir . '/Subs-Package.php'); |
3037 | 3200 | |
3038 | 3201 | $error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
3039 | - if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) |
|
3040 | - $error = $php_errormsg; |
|
3041 | - if (empty($error)) |
|
3042 | - $error = $txt['template_parse_errmsg']; |
|
3202 | + if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) { |
|
3203 | + $error = $php_errormsg; |
|
3204 | + } |
|
3205 | + if (empty($error)) { |
|
3206 | + $error = $txt['template_parse_errmsg']; |
|
3207 | + } |
|
3043 | 3208 | |
3044 | 3209 | $error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>')); |
3045 | 3210 | |
@@ -3050,11 +3215,12 @@ discard block |
||
3050 | 3215 | <h3>', $txt['template_parse_error'], '</h3> |
3051 | 3216 | ', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
3052 | 3217 | |
3053 | - if (!empty($error)) |
|
3054 | - echo ' |
|
3218 | + if (!empty($error)) { |
|
3219 | + echo ' |
|
3055 | 3220 | <hr> |
3056 | 3221 | |
3057 | 3222 | <div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>'; |
3223 | + } |
|
3058 | 3224 | |
3059 | 3225 | // I know, I know... this is VERY COMPLICATED. Still, it's good. |
3060 | 3226 | if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0) |
@@ -3064,10 +3230,11 @@ discard block |
||
3064 | 3230 | $data2 = preg_split('~\<br( /)?\>~', $data2); |
3065 | 3231 | |
3066 | 3232 | // Fix the PHP code stuff... |
3067 | - if (!isBrowser('gecko')) |
|
3068 | - $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
3069 | - else |
|
3070 | - $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
3233 | + if (!isBrowser('gecko')) { |
|
3234 | + $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
3235 | + } else { |
|
3236 | + $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
3237 | + } |
|
3071 | 3238 | |
3072 | 3239 | // Now we get to work around a bug in PHP where it doesn't escape <br>s! |
3073 | 3240 | $j = -1; |
@@ -3075,8 +3242,9 @@ discard block |
||
3075 | 3242 | { |
3076 | 3243 | $j++; |
3077 | 3244 | |
3078 | - if (substr_count($line, '<br>') == 0) |
|
3079 | - continue; |
|
3245 | + if (substr_count($line, '<br>') == 0) { |
|
3246 | + continue; |
|
3247 | + } |
|
3080 | 3248 | |
3081 | 3249 | $n = substr_count($line, '<br>'); |
3082 | 3250 | for ($i = 0; $i < $n; $i++) |
@@ -3095,38 +3263,42 @@ discard block |
||
3095 | 3263 | // Figure out what the color coding was before... |
3096 | 3264 | $line = max($match[1] - 9, 1); |
3097 | 3265 | $last_line = ''; |
3098 | - for ($line2 = $line - 1; $line2 > 1; $line2--) |
|
3099 | - if (strpos($data2[$line2], '<') !== false) |
|
3266 | + for ($line2 = $line - 1; $line2 > 1; $line2--) { |
|
3267 | + if (strpos($data2[$line2], '<') !== false) |
|
3100 | 3268 | { |
3101 | 3269 | if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0) |
3102 | 3270 | $last_line = $color_match[1]; |
3271 | + } |
|
3103 | 3272 | break; |
3104 | 3273 | } |
3105 | 3274 | |
3106 | 3275 | // Show the relevant lines... |
3107 | 3276 | for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++) |
3108 | 3277 | { |
3109 | - if ($line == $match[1]) |
|
3110 | - echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
3278 | + if ($line == $match[1]) { |
|
3279 | + echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
3280 | + } |
|
3111 | 3281 | |
3112 | 3282 | echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> '; |
3113 | - if (isset($data2[$line]) && $data2[$line] != '') |
|
3114 | - echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
3283 | + if (isset($data2[$line]) && $data2[$line] != '') { |
|
3284 | + echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
3285 | + } |
|
3115 | 3286 | |
3116 | 3287 | if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0) |
3117 | 3288 | { |
3118 | 3289 | $last_line = $color_match[1]; |
3119 | 3290 | echo '</', substr($last_line, 1, 4), '>'; |
3291 | + } elseif ($last_line != '' && strpos($data2[$line], '<') !== false) { |
|
3292 | + $last_line = ''; |
|
3293 | + } elseif ($last_line != '' && $data2[$line] != '') { |
|
3294 | + echo '</', substr($last_line, 1, 4), '>'; |
|
3120 | 3295 | } |
3121 | - elseif ($last_line != '' && strpos($data2[$line], '<') !== false) |
|
3122 | - $last_line = ''; |
|
3123 | - elseif ($last_line != '' && $data2[$line] != '') |
|
3124 | - echo '</', substr($last_line, 1, 4), '>'; |
|
3125 | 3296 | |
3126 | - if ($line == $match[1]) |
|
3127 | - echo '</pre></div><pre style="margin: 0;">'; |
|
3128 | - else |
|
3129 | - echo "\n"; |
|
3297 | + if ($line == $match[1]) { |
|
3298 | + echo '</pre></div><pre style="margin: 0;">'; |
|
3299 | + } else { |
|
3300 | + echo "\n"; |
|
3301 | + } |
|
3130 | 3302 | } |
3131 | 3303 | |
3132 | 3304 | echo '</pre></div>'; |
@@ -3150,8 +3322,9 @@ discard block |
||
3150 | 3322 | global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port; |
3151 | 3323 | |
3152 | 3324 | // Figure out what type of database we are using. |
3153 | - if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
|
3154 | - $db_type = 'mysql'; |
|
3325 | + if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) { |
|
3326 | + $db_type = 'mysql'; |
|
3327 | + } |
|
3155 | 3328 | |
3156 | 3329 | // Load the file for the database. |
3157 | 3330 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
@@ -3159,8 +3332,9 @@ discard block |
||
3159 | 3332 | $db_options = array(); |
3160 | 3333 | |
3161 | 3334 | // Add in the port if needed |
3162 | - if (!empty($db_port)) |
|
3163 | - $db_options['port'] = $db_port; |
|
3335 | + if (!empty($db_port)) { |
|
3336 | + $db_options['port'] = $db_port; |
|
3337 | + } |
|
3164 | 3338 | |
3165 | 3339 | // 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. |
3166 | 3340 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
@@ -3179,13 +3353,15 @@ discard block |
||
3179 | 3353 | } |
3180 | 3354 | |
3181 | 3355 | // Safe guard here, if there isn't a valid connection lets put a stop to it. |
3182 | - if (!$db_connection) |
|
3183 | - display_db_error(); |
|
3356 | + if (!$db_connection) { |
|
3357 | + display_db_error(); |
|
3358 | + } |
|
3184 | 3359 | |
3185 | 3360 | // If in SSI mode fix up the prefix. |
3186 | - if (SMF == 'SSI') |
|
3187 | - db_fix_prefix($db_prefix, $db_name); |
|
3188 | -} |
|
3361 | + if (SMF == 'SSI') { |
|
3362 | + db_fix_prefix($db_prefix, $db_name); |
|
3363 | + } |
|
3364 | + } |
|
3189 | 3365 | |
3190 | 3366 | /** |
3191 | 3367 | * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it. |
@@ -3199,10 +3375,11 @@ discard block |
||
3199 | 3375 | global $sourcedir, $cacheAPI, $cache_accelerator; |
3200 | 3376 | |
3201 | 3377 | // Not overriding this and we have a cacheAPI, send it back. |
3202 | - if (empty($overrideCache) && is_object($cacheAPI)) |
|
3203 | - return $cacheAPI; |
|
3204 | - elseif (is_null($cacheAPI)) |
|
3205 | - $cacheAPI = false; |
|
3378 | + if (empty($overrideCache) && is_object($cacheAPI)) { |
|
3379 | + return $cacheAPI; |
|
3380 | + } elseif (is_null($cacheAPI)) { |
|
3381 | + $cacheAPI = false; |
|
3382 | + } |
|
3206 | 3383 | |
3207 | 3384 | // Make sure our class is in session. |
3208 | 3385 | require_once($sourcedir . '/Class-CacheAPI.php'); |
@@ -3223,8 +3400,9 @@ discard block |
||
3223 | 3400 | if (!$testAPI->isSupported()) |
3224 | 3401 | { |
3225 | 3402 | // Can we save ourselves? |
3226 | - if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') |
|
3227 | - return loadCacheAccelerator(null, false); |
|
3403 | + if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') { |
|
3404 | + return loadCacheAccelerator(null, false); |
|
3405 | + } |
|
3228 | 3406 | return false; |
3229 | 3407 | } |
3230 | 3408 | |
@@ -3236,9 +3414,9 @@ discard block |
||
3236 | 3414 | { |
3237 | 3415 | $cacheAPI = $testAPI; |
3238 | 3416 | return $cacheAPI; |
3417 | + } else { |
|
3418 | + return $testAPI; |
|
3239 | 3419 | } |
3240 | - else |
|
3241 | - return $testAPI; |
|
3242 | 3420 | } |
3243 | 3421 | } |
3244 | 3422 | |
@@ -3258,8 +3436,9 @@ discard block |
||
3258 | 3436 | |
3259 | 3437 | // @todo Why are we doing this if caching is disabled? |
3260 | 3438 | |
3261 | - if (function_exists('call_integration_hook')) |
|
3262 | - call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
3439 | + if (function_exists('call_integration_hook')) { |
|
3440 | + call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
3441 | + } |
|
3263 | 3442 | |
3264 | 3443 | /* Refresh the cache if either: |
3265 | 3444 | 1. Caching is disabled. |
@@ -3273,16 +3452,19 @@ discard block |
||
3273 | 3452 | require_once($sourcedir . '/' . $file); |
3274 | 3453 | $cache_block = call_user_func_array($function, $params); |
3275 | 3454 | |
3276 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) |
|
3277 | - cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
3455 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) { |
|
3456 | + cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
3457 | + } |
|
3278 | 3458 | } |
3279 | 3459 | |
3280 | 3460 | // Some cached data may need a freshening up after retrieval. |
3281 | - if (!empty($cache_block['post_retri_eval'])) |
|
3282 | - eval($cache_block['post_retri_eval']); |
|
3461 | + if (!empty($cache_block['post_retri_eval'])) { |
|
3462 | + eval($cache_block['post_retri_eval']); |
|
3463 | + } |
|
3283 | 3464 | |
3284 | - if (function_exists('call_integration_hook')) |
|
3285 | - call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
3465 | + if (function_exists('call_integration_hook')) { |
|
3466 | + call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
3467 | + } |
|
3286 | 3468 | |
3287 | 3469 | return $cache_block['data']; |
3288 | 3470 | } |
@@ -3309,8 +3491,9 @@ discard block |
||
3309 | 3491 | global $boardurl, $modSettings, $cache_enable, $cacheAPI; |
3310 | 3492 | global $cache_hits, $cache_count, $db_show_debug; |
3311 | 3493 | |
3312 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
3313 | - return; |
|
3494 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
3495 | + return; |
|
3496 | + } |
|
3314 | 3497 | |
3315 | 3498 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
3316 | 3499 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3323,12 +3506,14 @@ discard block |
||
3323 | 3506 | $value = $value === null ? null : json_encode($value); |
3324 | 3507 | $result = $cacheAPI->putData($key, $value, $ttl); |
3325 | 3508 | |
3326 | - if (function_exists('call_integration_hook')) |
|
3327 | - call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
3509 | + if (function_exists('call_integration_hook')) { |
|
3510 | + call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
3511 | + } |
|
3328 | 3512 | |
3329 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
3330 | - $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
3331 | -} |
|
3513 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
3514 | + $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
3515 | + } |
|
3516 | + } |
|
3332 | 3517 | |
3333 | 3518 | /** |
3334 | 3519 | * Gets the value from the cache specified by key, so long as it is not older than ttl seconds. |
@@ -3344,8 +3529,9 @@ discard block |
||
3344 | 3529 | global $boardurl, $modSettings, $cache_enable, $cacheAPI; |
3345 | 3530 | global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug; |
3346 | 3531 | |
3347 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
3348 | - return; |
|
3532 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
3533 | + return; |
|
3534 | + } |
|
3349 | 3535 | |
3350 | 3536 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
3351 | 3537 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3365,16 +3551,18 @@ discard block |
||
3365 | 3551 | |
3366 | 3552 | if (empty($value)) |
3367 | 3553 | { |
3368 | - if (!is_array($cache_misses)) |
|
3369 | - $cache_misses = array(); |
|
3554 | + if (!is_array($cache_misses)) { |
|
3555 | + $cache_misses = array(); |
|
3556 | + } |
|
3370 | 3557 | |
3371 | 3558 | $cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1; |
3372 | 3559 | $cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get'); |
3373 | 3560 | } |
3374 | 3561 | } |
3375 | 3562 | |
3376 | - if (function_exists('call_integration_hook') && isset($value)) |
|
3377 | - call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
3563 | + if (function_exists('call_integration_hook') && isset($value)) { |
|
3564 | + call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
3565 | + } |
|
3378 | 3566 | |
3379 | 3567 | return empty($value) ? null : smf_json_decode($value, true); |
3380 | 3568 | } |
@@ -3396,8 +3584,9 @@ discard block |
||
3396 | 3584 | global $cachedir, $sourcedir, $modSettings; |
3397 | 3585 | |
3398 | 3586 | // If we can't get to the API, can't do this. |
3399 | - if (empty($cacheAPI)) |
|
3400 | - return false; |
|
3587 | + if (empty($cacheAPI)) { |
|
3588 | + return false; |
|
3589 | + } |
|
3401 | 3590 | |
3402 | 3591 | // Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure. |
3403 | 3592 | $value = $cacheAPI->cleanCache($type); |
@@ -3422,8 +3611,9 @@ discard block |
||
3422 | 3611 | global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret; |
3423 | 3612 | |
3424 | 3613 | // Come on! |
3425 | - if (empty($data)) |
|
3426 | - return array(); |
|
3614 | + if (empty($data)) { |
|
3615 | + return array(); |
|
3616 | + } |
|
3427 | 3617 | |
3428 | 3618 | // Set a nice default var. |
3429 | 3619 | $image = ''; |
@@ -3431,11 +3621,11 @@ discard block |
||
3431 | 3621 | // Gravatar has been set as mandatory! |
3432 | 3622 | if (!empty($modSettings['gravatarOverride'])) |
3433 | 3623 | { |
3434 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) |
|
3435 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3436 | - |
|
3437 | - else if (!empty($data['email'])) |
|
3438 | - $image = get_gravatar_url($data['email']); |
|
3624 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) { |
|
3625 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3626 | + } else if (!empty($data['email'])) { |
|
3627 | + $image = get_gravatar_url($data['email']); |
|
3628 | + } |
|
3439 | 3629 | } |
3440 | 3630 | |
3441 | 3631 | // Look if the user has a gravatar field or has set an external url as avatar. |
@@ -3447,54 +3637,60 @@ discard block |
||
3447 | 3637 | // Gravatar. |
3448 | 3638 | if (stristr($data['avatar'], 'gravatar://')) |
3449 | 3639 | { |
3450 | - if ($data['avatar'] == 'gravatar://') |
|
3451 | - $image = get_gravatar_url($data['email']); |
|
3452 | - |
|
3453 | - elseif (!empty($modSettings['gravatarAllowExtraEmail'])) |
|
3454 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3640 | + if ($data['avatar'] == 'gravatar://') { |
|
3641 | + $image = get_gravatar_url($data['email']); |
|
3642 | + } elseif (!empty($modSettings['gravatarAllowExtraEmail'])) { |
|
3643 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3644 | + } |
|
3455 | 3645 | } |
3456 | 3646 | |
3457 | 3647 | // External url. |
3458 | 3648 | else |
3459 | 3649 | { |
3460 | 3650 | // Using ssl? |
3461 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) |
|
3462 | - $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
3651 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) { |
|
3652 | + $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
3653 | + } |
|
3463 | 3654 | |
3464 | 3655 | // Just a plain external url. |
3465 | - else |
|
3466 | - $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
3656 | + else { |
|
3657 | + $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
3658 | + } |
|
3467 | 3659 | } |
3468 | 3660 | } |
3469 | 3661 | |
3470 | 3662 | // Perhaps this user has an attachment as avatar... |
3471 | - else if (!empty($data['filename'])) |
|
3472 | - $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
3663 | + else if (!empty($data['filename'])) { |
|
3664 | + $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
3665 | + } |
|
3473 | 3666 | |
3474 | 3667 | // Right... no avatar... use our default image. |
3475 | - else |
|
3476 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
3668 | + else { |
|
3669 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
3670 | + } |
|
3477 | 3671 | } |
3478 | 3672 | |
3479 | 3673 | call_integration_hook('integrate_set_avatar_data', array(&$image, &$data)); |
3480 | 3674 | |
3481 | 3675 | // 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. |
3482 | - if (!empty($image)) |
|
3483 | - return array( |
|
3676 | + if (!empty($image)) { |
|
3677 | + return array( |
|
3484 | 3678 | 'name' => !empty($data['avatar']) ? $data['avatar'] : '', |
3485 | 3679 | 'image' => '<img class="avatar" src="' . $image . '" />', |
3486 | 3680 | 'href' => $image, |
3487 | 3681 | 'url' => $image, |
3488 | 3682 | ); |
3683 | + } |
|
3489 | 3684 | |
3490 | 3685 | // Fallback to make life easier for everyone... |
3491 | - else |
|
3492 | - return array( |
|
3686 | + else { |
|
3687 | + return array( |
|
3493 | 3688 | 'name' => '', |
3494 | 3689 | 'image' => '', |
3495 | 3690 | 'href' => '', |
3496 | 3691 | 'url' => '', |
3497 | 3692 | ); |
3498 | -} |
|
3693 | + } |
|
3694 | + } |
|
3499 | 3695 | |
3500 | 3696 | ?> |
3501 | 3697 | \ No newline at end of file |
@@ -181,14 +181,14 @@ discard block |
||
181 | 181 | { |
182 | 182 | collapsedDiv.show(\'slow\'); |
183 | 183 | icon.removeClass(\'toggle_down\').addClass(\'toggle_up\'); |
184 | - icon.prop(\'title\', '. JavaScriptEscape($txt['hide']) .'); |
|
184 | + icon.prop(\'title\', '. JavaScriptEscape($txt['hide']) . '); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | else |
188 | 188 | { |
189 | 189 | collapsedDiv.hide(\'slow\'); |
190 | 190 | icon.removeClass(\'toggle_up\').addClass(\'toggle_down\'); |
191 | - icon.prop(\'title\', '. JavaScriptEscape($txt['show']) .'); |
|
191 | + icon.prop(\'title\', '. JavaScriptEscape($txt['show']) . '); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | });', true); |
@@ -641,7 +641,7 @@ discard block |
||
641 | 641 | |
642 | 642 | // Setup the correct template, even though I'll admit we ain't downloading ;) |
643 | 643 | $context['sub_template'] = 'downloaded'; |
644 | - $allowext = array('.zip','.tgz','.gz'); |
|
644 | + $allowext = array('.zip', '.tgz', '.gz'); |
|
645 | 645 | // @todo Use FTP if the Packages directory is not writable. |
646 | 646 | |
647 | 647 | // Check the file was even sent! |
@@ -653,13 +653,13 @@ discard block |
||
653 | 653 | // Make sure it has a sane filename. |
654 | 654 | $_FILES['package']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['package']['name']); |
655 | 655 | $extension = substr(strrchr(strtolower($_FILES['package']['name']), '.'), 0); |
656 | - if(!in_array($extension, $allowext)) |
|
656 | + if (!in_array($extension, $allowext)) |
|
657 | 657 | { |
658 | 658 | fatal_lang_error('package_upload_error_supports', false, array('zip, tgz, tar.gz')); |
659 | 659 | } |
660 | 660 | |
661 | 661 | // We only need the filename... |
662 | - $extension = ($extension == '.gz') ? '.tar.gz' : $extension ; |
|
662 | + $extension = ($extension == '.gz') ? '.tar.gz' : $extension; |
|
663 | 663 | $packageName = time() . $extension; |
664 | 664 | |
665 | 665 | // Setup the destination and throw an error if the file is already there! |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
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 | * Browse the list of package servers, add servers... |
@@ -43,13 +44,15 @@ discard block |
||
43 | 44 | ); |
44 | 45 | |
45 | 46 | // Now let's decide where we are taking this... |
46 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
47 | - $context['sub_action'] = $_REQUEST['sa']; |
|
47 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
48 | + $context['sub_action'] = $_REQUEST['sa']; |
|
49 | + } |
|
48 | 50 | // We need to support possible old javascript links... |
49 | - elseif (isset($_GET['pgdownload'])) |
|
50 | - $context['sub_action'] = 'download'; |
|
51 | - else |
|
52 | - $context['sub_action'] = 'servers'; |
|
51 | + elseif (isset($_GET['pgdownload'])) { |
|
52 | + $context['sub_action'] = 'download'; |
|
53 | + } else { |
|
54 | + $context['sub_action'] = 'servers'; |
|
55 | + } |
|
53 | 56 | |
54 | 57 | // We need to force the "Download" tab as selected. |
55 | 58 | $context['menu_data_' . $context['admin_menu_id']]['current_subsection'] = 'packageget'; |
@@ -141,17 +144,19 @@ discard block |
||
141 | 144 | { |
142 | 145 | require_once($sourcedir . '/Class-Package.php'); |
143 | 146 | $ftp = new ftp_connection(null); |
147 | + } elseif ($ftp->error !== false && !isset($ftp_error)) { |
|
148 | + $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
144 | 149 | } |
145 | - elseif ($ftp->error !== false && !isset($ftp_error)) |
|
146 | - $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
147 | 150 | |
148 | 151 | list ($username, $detect_path, $found_path) = $ftp->detect_path($packagesdir); |
149 | 152 | |
150 | - if ($found_path || !isset($_POST['ftp_path'])) |
|
151 | - $_POST['ftp_path'] = $detect_path; |
|
153 | + if ($found_path || !isset($_POST['ftp_path'])) { |
|
154 | + $_POST['ftp_path'] = $detect_path; |
|
155 | + } |
|
152 | 156 | |
153 | - if (!isset($_POST['ftp_username'])) |
|
154 | - $_POST['ftp_username'] = $username; |
|
157 | + if (!isset($_POST['ftp_username'])) { |
|
158 | + $_POST['ftp_username'] = $username; |
|
159 | + } |
|
155 | 160 | |
156 | 161 | $context['package_ftp'] = array( |
157 | 162 | 'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'), |
@@ -160,8 +165,7 @@ discard block |
||
160 | 165 | 'path' => $_POST['ftp_path'], |
161 | 166 | 'error' => empty($ftp_error) ? null : $ftp_error, |
162 | 167 | ); |
163 | - } |
|
164 | - else |
|
168 | + } else |
|
165 | 169 | { |
166 | 170 | $context['package_download_broken'] = false; |
167 | 171 | |
@@ -203,8 +207,9 @@ discard block |
||
203 | 207 | |
204 | 208 | if (isset($_GET['server'])) |
205 | 209 | { |
206 | - if ($_GET['server'] == '') |
|
207 | - redirectexit('action=admin;area=packages;get'); |
|
210 | + if ($_GET['server'] == '') { |
|
211 | + redirectexit('action=admin;area=packages;get'); |
|
212 | + } |
|
208 | 213 | |
209 | 214 | $server = (int) $_GET['server']; |
210 | 215 | |
@@ -222,17 +227,18 @@ discard block |
||
222 | 227 | $smcFunc['db_free_result']($request); |
223 | 228 | |
224 | 229 | // If the server does not exist, dump out. |
225 | - if (empty($url)) |
|
226 | - fatal_lang_error('couldnt_connect', false); |
|
230 | + if (empty($url)) { |
|
231 | + fatal_lang_error('couldnt_connect', false); |
|
232 | + } |
|
227 | 233 | |
228 | 234 | // If there is a relative link, append to the stored server url. |
229 | - if (isset($_GET['relative'])) |
|
230 | - $url = $url . (substr($url, -1) == '/' ? '' : '/') . $_GET['relative']; |
|
235 | + if (isset($_GET['relative'])) { |
|
236 | + $url = $url . (substr($url, -1) == '/' ? '' : '/') . $_GET['relative']; |
|
237 | + } |
|
231 | 238 | |
232 | 239 | // Clear any "absolute" URL. Since "server" is present, "absolute" is garbage. |
233 | 240 | unset($_GET['absolute']); |
234 | - } |
|
235 | - elseif (isset($_GET['absolute']) && $_GET['absolute'] != '') |
|
241 | + } elseif (isset($_GET['absolute']) && $_GET['absolute'] != '') |
|
236 | 242 | { |
237 | 243 | // Initialize the requried variables. |
238 | 244 | $server = ''; |
@@ -256,16 +262,19 @@ discard block |
||
256 | 262 | } |
257 | 263 | } |
258 | 264 | // Minimum required parameter did not exist so dump out. |
259 | - else |
|
260 | - fatal_lang_error('couldnt_connect', false); |
|
265 | + else { |
|
266 | + fatal_lang_error('couldnt_connect', false); |
|
267 | + } |
|
261 | 268 | |
262 | 269 | // Attempt to connect. If unsuccessful... try the URL. |
263 | - if (!isset($_GET['package']) || file_exists($_GET['package'])) |
|
264 | - $_GET['package'] = $url . '/packages.xml?language=' . $context['user']['language']; |
|
270 | + if (!isset($_GET['package']) || file_exists($_GET['package'])) { |
|
271 | + $_GET['package'] = $url . '/packages.xml?language=' . $context['user']['language']; |
|
272 | + } |
|
265 | 273 | |
266 | 274 | // Check to be sure the packages.xml file actually exists where it is should be... or dump out. |
267 | - if ((isset($_GET['absolute']) || isset($_GET['relative'])) && !url_exists($_GET['package'])) |
|
268 | - fatal_lang_error('packageget_unable', false, array($url . '/index.php')); |
|
275 | + if ((isset($_GET['absolute']) || isset($_GET['relative'])) && !url_exists($_GET['package'])) { |
|
276 | + fatal_lang_error('packageget_unable', false, array($url . '/index.php')); |
|
277 | + } |
|
269 | 278 | |
270 | 279 | // Might take some time. |
271 | 280 | @set_time_limit(600); |
@@ -275,8 +284,9 @@ discard block |
||
275 | 284 | $listing = new xmlArray(fetch_web_data($_GET['package']), true); |
276 | 285 | |
277 | 286 | // Errm.... empty file? Try the URL.... |
278 | - if (!$listing->exists('package-list')) |
|
279 | - fatal_lang_error('packageget_unable', false, array($url . '/index.php')); |
|
287 | + if (!$listing->exists('package-list')) { |
|
288 | + fatal_lang_error('packageget_unable', false, array($url . '/index.php')); |
|
289 | + } |
|
280 | 290 | |
281 | 291 | // List out the packages... |
282 | 292 | $context['package_list'] = array(); |
@@ -284,8 +294,9 @@ discard block |
||
284 | 294 | $listing = $listing->path('package-list[0]'); |
285 | 295 | |
286 | 296 | // Use the package list's name if it exists. |
287 | - if ($listing->exists('list-title')) |
|
288 | - $name = $smcFunc['htmlspecialchars']($listing->fetch('list-title')); |
|
297 | + if ($listing->exists('list-title')) { |
|
298 | + $name = $smcFunc['htmlspecialchars']($listing->fetch('list-title')); |
|
299 | + } |
|
289 | 300 | |
290 | 301 | // Pick the correct template. |
291 | 302 | $context['sub_template'] = 'package_list'; |
@@ -300,28 +311,32 @@ discard block |
||
300 | 311 | |
301 | 312 | $installed_mods = array(); |
302 | 313 | // Look through the list of installed mods... |
303 | - foreach ($instmods as $installed_mod) |
|
304 | - $installed_mods[$installed_mod['package_id']] = $installed_mod['version']; |
|
314 | + foreach ($instmods as $installed_mod) { |
|
315 | + $installed_mods[$installed_mod['package_id']] = $installed_mod['version']; |
|
316 | + } |
|
305 | 317 | |
306 | 318 | // Get default author and email if they exist. |
307 | 319 | if ($listing->exists('default-author')) |
308 | 320 | { |
309 | 321 | $default_author = $smcFunc['htmlspecialchars']($listing->fetch('default-author')); |
310 | - if ($listing->exists('default-author/@email') && filter_var($listing->fetch('default-author/@email'), FILTER_VALIDATE_EMAIL)) |
|
311 | - $default_email = $smcFunc['htmlspecialchars']($listing->fetch('default-author/@email')); |
|
322 | + if ($listing->exists('default-author/@email') && filter_var($listing->fetch('default-author/@email'), FILTER_VALIDATE_EMAIL)) { |
|
323 | + $default_email = $smcFunc['htmlspecialchars']($listing->fetch('default-author/@email')); |
|
324 | + } |
|
312 | 325 | } |
313 | 326 | |
314 | 327 | // Get default web site if it exists. |
315 | 328 | if ($listing->exists('default-website')) |
316 | 329 | { |
317 | 330 | $default_website = $smcFunc['htmlspecialchars']($listing->fetch('default-website')); |
318 | - if ($listing->exists('default-website/@title')) |
|
319 | - $default_title = $smcFunc['htmlspecialchars']($listing->fetch('default-website/@title')); |
|
331 | + if ($listing->exists('default-website/@title')) { |
|
332 | + $default_title = $smcFunc['htmlspecialchars']($listing->fetch('default-website/@title')); |
|
333 | + } |
|
320 | 334 | } |
321 | 335 | |
322 | 336 | $the_version = strtr($forum_version, array('SMF ' => '')); |
323 | - if (!empty($_SESSION['version_emulate'])) |
|
324 | - $the_version = $_SESSION['version_emulate']; |
|
337 | + if (!empty($_SESSION['version_emulate'])) { |
|
338 | + $the_version = $_SESSION['version_emulate']; |
|
339 | + } |
|
325 | 340 | |
326 | 341 | $packageNum = 0; |
327 | 342 | $packageSection = 0; |
@@ -342,11 +357,13 @@ discard block |
||
342 | 357 | 'type' => $thisPackage->name(), |
343 | 358 | ); |
344 | 359 | |
345 | - if (in_array($package['type'], array('title', 'text'))) |
|
346 | - $context['package_list'][$packageSection][$package['type']] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.')); |
|
360 | + if (in_array($package['type'], array('title', 'text'))) { |
|
361 | + $context['package_list'][$packageSection][$package['type']] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.')); |
|
362 | + } |
|
347 | 363 | // It's a Title, Heading, Rule or Text. |
348 | - elseif (in_array($package['type'], array('heading', 'rule'))) |
|
349 | - $package['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.')); |
|
364 | + elseif (in_array($package['type'], array('heading', 'rule'))) { |
|
365 | + $package['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.')); |
|
366 | + } |
|
350 | 367 | // It's a Remote link. |
351 | 368 | elseif ($package['type'] == 'remote') |
352 | 369 | { |
@@ -354,20 +371,21 @@ discard block |
||
354 | 371 | |
355 | 372 | if ($remote_type == 'relative' && substr($thisPackage->fetch('@href'), 0, 7) != 'http://' && substr($thisPackage->fetch('@href'), 0, 8) != 'https://') |
356 | 373 | { |
357 | - if (isset($_GET['absolute'])) |
|
358 | - $current_url = $_GET['absolute'] . '/'; |
|
359 | - elseif (isset($_GET['relative'])) |
|
360 | - $current_url = $_GET['relative'] . '/'; |
|
361 | - else |
|
362 | - $current_url = ''; |
|
374 | + if (isset($_GET['absolute'])) { |
|
375 | + $current_url = $_GET['absolute'] . '/'; |
|
376 | + } elseif (isset($_GET['relative'])) { |
|
377 | + $current_url = $_GET['relative'] . '/'; |
|
378 | + } else { |
|
379 | + $current_url = ''; |
|
380 | + } |
|
363 | 381 | |
364 | 382 | $current_url .= $thisPackage->fetch('@href'); |
365 | - if (isset($_GET['absolute'])) |
|
366 | - $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url; |
|
367 | - else |
|
368 | - $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $context['package_server'] . ';relative=' . $current_url; |
|
369 | - } |
|
370 | - else |
|
383 | + if (isset($_GET['absolute'])) { |
|
384 | + $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url; |
|
385 | + } else { |
|
386 | + $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $context['package_server'] . ';relative=' . $current_url; |
|
387 | + } |
|
388 | + } else |
|
371 | 389 | { |
372 | 390 | $current_url = $thisPackage->fetch('@href'); |
373 | 391 | $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url; |
@@ -379,25 +397,28 @@ discard block |
||
379 | 397 | // It's a package... |
380 | 398 | else |
381 | 399 | { |
382 | - if (isset($_GET['absolute'])) |
|
383 | - $current_url = $_GET['absolute'] . '/'; |
|
384 | - elseif (isset($_GET['relative'])) |
|
385 | - $current_url = $_GET['relative'] . '/'; |
|
386 | - else |
|
387 | - $current_url = ''; |
|
400 | + if (isset($_GET['absolute'])) { |
|
401 | + $current_url = $_GET['absolute'] . '/'; |
|
402 | + } elseif (isset($_GET['relative'])) { |
|
403 | + $current_url = $_GET['relative'] . '/'; |
|
404 | + } else { |
|
405 | + $current_url = ''; |
|
406 | + } |
|
388 | 407 | |
389 | 408 | $server_att = $server != '' ? ';server=' . $server : ''; |
390 | 409 | |
391 | 410 | $package += $thisPackage->to_array(); |
392 | 411 | |
393 | - if (isset($package['website'])) |
|
394 | - unset($package['website']); |
|
412 | + if (isset($package['website'])) { |
|
413 | + unset($package['website']); |
|
414 | + } |
|
395 | 415 | $package['author'] = array(); |
396 | 416 | |
397 | - if ($package['description'] == '') |
|
398 | - $package['description'] = $txt['package_no_description']; |
|
399 | - else |
|
400 | - $package['description'] = parse_bbc(preg_replace('~\[[/]?html\]~i', '', $smcFunc['htmlspecialchars']($package['description']))); |
|
417 | + if ($package['description'] == '') { |
|
418 | + $package['description'] = $txt['package_no_description']; |
|
419 | + } else { |
|
420 | + $package['description'] = parse_bbc(preg_replace('~\[[/]?html\]~i', '', $smcFunc['htmlspecialchars']($package['description']))); |
|
421 | + } |
|
401 | 422 | |
402 | 423 | $package['is_installed'] = isset($installed_mods[$package['id']]); |
403 | 424 | $package['is_current'] = $package['is_installed'] && ($installed_mods[$package['id']] == $package['version']); |
@@ -406,12 +427,14 @@ discard block |
||
406 | 427 | // This package is either not installed, or installed but old. Is it supported on this version of SMF? |
407 | 428 | if (!$package['is_installed'] || (!$package['is_current'] && !$package['is_newer'])) |
408 | 429 | { |
409 | - if ($thisPackage->exists('version/@for')) |
|
410 | - $package['can_install'] = matchPackageVersion($the_version, $thisPackage->fetch('version/@for')); |
|
430 | + if ($thisPackage->exists('version/@for')) { |
|
431 | + $package['can_install'] = matchPackageVersion($the_version, $thisPackage->fetch('version/@for')); |
|
432 | + } |
|
411 | 433 | } |
412 | 434 | // Okay, it's already installed AND up to date. |
413 | - else |
|
414 | - $package['can_install'] = false; |
|
435 | + else { |
|
436 | + $package['can_install'] = false; |
|
437 | + } |
|
415 | 438 | |
416 | 439 | $already_exists = getPackageInfo(basename($package['filename'])); |
417 | 440 | $package['download_conflict'] = is_array($already_exists) && $already_exists['id'] == $package['id'] && $already_exists['version'] != $package['version']; |
@@ -423,40 +446,44 @@ discard block |
||
423 | 446 | |
424 | 447 | if ($thisPackage->exists('author') || isset($default_author)) |
425 | 448 | { |
426 | - if ($thisPackage->exists('author/@email') && filter_var($thisPackage->fetch('author/@email'), FILTER_VALIDATE_EMAIL)) |
|
427 | - $package['author']['email'] = $thisPackage->fetch('author/@email'); |
|
428 | - elseif (isset($default_email)) |
|
429 | - $package['author']['email'] = $default_email; |
|
430 | - |
|
431 | - if ($thisPackage->exists('author') && $thisPackage->fetch('author') != '') |
|
432 | - $package['author']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('author')); |
|
433 | - else |
|
434 | - $package['author']['name'] = $default_author; |
|
435 | - |
|
436 | - if (!empty($package['author']['email'])) |
|
437 | - $package['author']['link'] = '<a href="mailto:' . $package['author']['email'] . '">' . $package['author']['name'] . '</a>'; |
|
449 | + if ($thisPackage->exists('author/@email') && filter_var($thisPackage->fetch('author/@email'), FILTER_VALIDATE_EMAIL)) { |
|
450 | + $package['author']['email'] = $thisPackage->fetch('author/@email'); |
|
451 | + } elseif (isset($default_email)) { |
|
452 | + $package['author']['email'] = $default_email; |
|
453 | + } |
|
454 | + |
|
455 | + if ($thisPackage->exists('author') && $thisPackage->fetch('author') != '') { |
|
456 | + $package['author']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('author')); |
|
457 | + } else { |
|
458 | + $package['author']['name'] = $default_author; |
|
459 | + } |
|
460 | + |
|
461 | + if (!empty($package['author']['email'])) { |
|
462 | + $package['author']['link'] = '<a href="mailto:' . $package['author']['email'] . '">' . $package['author']['name'] . '</a>'; |
|
463 | + } |
|
438 | 464 | } |
439 | 465 | |
440 | 466 | if ($thisPackage->exists('website') || isset($default_website)) |
441 | 467 | { |
442 | - if ($thisPackage->exists('website') && $thisPackage->exists('website/@title')) |
|
443 | - $package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website/@title')); |
|
444 | - elseif (isset($default_title)) |
|
445 | - $package['author']['website']['name'] = $default_title; |
|
446 | - elseif ($thisPackage->exists('website')) |
|
447 | - $package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website')); |
|
448 | - else |
|
449 | - $package['author']['website']['name'] = $default_website; |
|
450 | - |
|
451 | - if ($thisPackage->exists('website') && $thisPackage->fetch('website') != '') |
|
452 | - $authorhompage = $smcFunc['htmlspecialchars']($thisPackage->fetch('website')); |
|
453 | - else |
|
454 | - $authorhompage = $default_website; |
|
468 | + if ($thisPackage->exists('website') && $thisPackage->exists('website/@title')) { |
|
469 | + $package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website/@title')); |
|
470 | + } elseif (isset($default_title)) { |
|
471 | + $package['author']['website']['name'] = $default_title; |
|
472 | + } elseif ($thisPackage->exists('website')) { |
|
473 | + $package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website')); |
|
474 | + } else { |
|
475 | + $package['author']['website']['name'] = $default_website; |
|
476 | + } |
|
477 | + |
|
478 | + if ($thisPackage->exists('website') && $thisPackage->fetch('website') != '') { |
|
479 | + $authorhompage = $smcFunc['htmlspecialchars']($thisPackage->fetch('website')); |
|
480 | + } else { |
|
481 | + $authorhompage = $default_website; |
|
482 | + } |
|
455 | 483 | |
456 | 484 | $package['author']['website']['href'] = $authorhompage; |
457 | 485 | $package['author']['website']['link'] = '<a href="' . $authorhompage . '">' . $package['author']['website']['name'] . '</a>'; |
458 | - } |
|
459 | - else |
|
486 | + } else |
|
460 | 487 | { |
461 | 488 | $package['author']['website']['href'] = ''; |
462 | 489 | $package['author']['website']['link'] = ''; |
@@ -472,11 +499,13 @@ discard block |
||
472 | 499 | $packageNum = in_array($package['type'], array('title', 'heading', 'text', 'remote', 'rule')) ? 0 : $packageNum + 1; |
473 | 500 | $package['count'] = $packageNum; |
474 | 501 | |
475 | - if (!in_array($package['type'], array('title', 'text'))) |
|
476 | - $context['package_list'][$packageSection]['items'][] = $package; |
|
502 | + if (!in_array($package['type'], array('title', 'text'))) { |
|
503 | + $context['package_list'][$packageSection]['items'][] = $package; |
|
504 | + } |
|
477 | 505 | |
478 | - if ($package['count'] > 1) |
|
479 | - $context['list_type'] = 'ol'; |
|
506 | + if ($package['count'] > 1) { |
|
507 | + $context['list_type'] = 'ol'; |
|
508 | + } |
|
480 | 509 | } |
481 | 510 | |
482 | 511 | $packageSection++; |
@@ -489,8 +518,9 @@ discard block |
||
489 | 518 | { |
490 | 519 | foreach ($packageSection['items'] as $i => $package) |
491 | 520 | { |
492 | - if ($package['count'] == 0 || isset($package['can_install'])) |
|
493 | - continue; |
|
521 | + if ($package['count'] == 0 || isset($package['can_install'])) { |
|
522 | + continue; |
|
523 | + } |
|
494 | 524 | |
495 | 525 | $context['package_list'][$ps_id]['items'][$i]['can_install'] = false; |
496 | 526 | |
@@ -539,8 +569,9 @@ discard block |
||
539 | 569 | checkSession('get'); |
540 | 570 | |
541 | 571 | // To download something, we need a valid server or url. |
542 | - if (empty($_GET['server']) && (!empty($_GET['get']) && !empty($_REQUEST['package']))) |
|
543 | - fatal_lang_error('package_get_error_is_zero', false); |
|
572 | + if (empty($_GET['server']) && (!empty($_GET['get']) && !empty($_REQUEST['package']))) { |
|
573 | + fatal_lang_error('package_get_error_is_zero', false); |
|
574 | + } |
|
544 | 575 | |
545 | 576 | if (isset($_GET['server'])) |
546 | 577 | { |
@@ -560,22 +591,23 @@ discard block |
||
560 | 591 | $smcFunc['db_free_result']($request); |
561 | 592 | |
562 | 593 | // If server does not exist then dump out. |
563 | - if (empty($url)) |
|
564 | - fatal_lang_error('couldnt_connect', false); |
|
594 | + if (empty($url)) { |
|
595 | + fatal_lang_error('couldnt_connect', false); |
|
596 | + } |
|
565 | 597 | |
566 | 598 | $url = $url . '/'; |
567 | - } |
|
568 | - else |
|
599 | + } else |
|
569 | 600 | { |
570 | 601 | // Initialize the requried variables. |
571 | 602 | $server = ''; |
572 | 603 | $url = ''; |
573 | 604 | } |
574 | 605 | |
575 | - if (isset($_REQUEST['byurl']) && !empty($_POST['filename'])) |
|
576 | - $package_name = basename($_REQUEST['filename']); |
|
577 | - else |
|
578 | - $package_name = basename($_REQUEST['package']); |
|
606 | + if (isset($_REQUEST['byurl']) && !empty($_POST['filename'])) { |
|
607 | + $package_name = basename($_REQUEST['filename']); |
|
608 | + } else { |
|
609 | + $package_name = basename($_REQUEST['package']); |
|
610 | + } |
|
579 | 611 | |
580 | 612 | if (isset($_REQUEST['conflict']) || (isset($_REQUEST['auto']) && file_exists($packagesdir . '/' . $package_name))) |
581 | 613 | { |
@@ -584,14 +616,15 @@ discard block |
||
584 | 616 | { |
585 | 617 | $ext = substr($package_name, strrpos(substr($package_name, 0, -3), '.')); |
586 | 618 | $package_name = substr($package_name, 0, strrpos(substr($package_name, 0, -3), '.')) . '_'; |
619 | + } else { |
|
620 | + $ext = ''; |
|
587 | 621 | } |
588 | - else |
|
589 | - $ext = ''; |
|
590 | 622 | |
591 | 623 | // Find the first available. |
592 | 624 | $i = 1; |
593 | - while (file_exists($packagesdir . '/' . $package_name . $i . $ext)) |
|
594 | - $i++; |
|
625 | + while (file_exists($packagesdir . '/' . $package_name . $i . $ext)) { |
|
626 | + $i++; |
|
627 | + } |
|
595 | 628 | |
596 | 629 | $package_name = $package_name . $i . $ext; |
597 | 630 | } |
@@ -601,25 +634,28 @@ discard block |
||
601 | 634 | package_put_contents($packagesdir . '/' . $package_name, fetch_web_data($url . $_REQUEST['package'])); |
602 | 635 | |
603 | 636 | // Done! Did we get this package automatically? |
604 | - if (preg_match('~^http://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['package']) == 1 && strpos($_REQUEST['package'], 'dlattach') === false && isset($_REQUEST['auto'])) |
|
605 | - redirectexit('action=admin;area=packages;sa=install;package=' . $package_name); |
|
637 | + if (preg_match('~^http://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['package']) == 1 && strpos($_REQUEST['package'], 'dlattach') === false && isset($_REQUEST['auto'])) { |
|
638 | + redirectexit('action=admin;area=packages;sa=install;package=' . $package_name); |
|
639 | + } |
|
606 | 640 | |
607 | 641 | // You just downloaded a mod from SERVER_NAME_GOES_HERE. |
608 | 642 | $context['package_server'] = $server; |
609 | 643 | |
610 | 644 | $context['package'] = getPackageInfo($package_name); |
611 | 645 | |
612 | - if (!is_array($context['package'])) |
|
613 | - fatal_lang_error('package_cant_download', false); |
|
646 | + if (!is_array($context['package'])) { |
|
647 | + fatal_lang_error('package_cant_download', false); |
|
648 | + } |
|
614 | 649 | |
615 | - if ($context['package']['type'] == 'modification') |
|
616 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>'; |
|
617 | - elseif ($context['package']['type'] == 'avatar') |
|
618 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>'; |
|
619 | - elseif ($context['package']['type'] == 'language') |
|
620 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>'; |
|
621 | - else |
|
622 | - $context['package']['install']['link'] = ''; |
|
650 | + if ($context['package']['type'] == 'modification') { |
|
651 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>'; |
|
652 | + } elseif ($context['package']['type'] == 'avatar') { |
|
653 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>'; |
|
654 | + } elseif ($context['package']['type'] == 'language') { |
|
655 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>'; |
|
656 | + } else { |
|
657 | + $context['package']['install']['link'] = ''; |
|
658 | + } |
|
623 | 659 | |
624 | 660 | // Does a 3rd party hook want to do some additional changes? |
625 | 661 | call_integration_hook('integrate_package_download'); |
@@ -645,10 +681,11 @@ discard block |
||
645 | 681 | // @todo Use FTP if the Packages directory is not writable. |
646 | 682 | |
647 | 683 | // Check the file was even sent! |
648 | - if (!isset($_FILES['package']['name']) || $_FILES['package']['name'] == '') |
|
649 | - fatal_lang_error('package_upload_error_nofile'); |
|
650 | - elseif (!is_uploaded_file($_FILES['package']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['package']['tmp_name']))) |
|
651 | - fatal_lang_error('package_upload_error_failed'); |
|
684 | + if (!isset($_FILES['package']['name']) || $_FILES['package']['name'] == '') { |
|
685 | + fatal_lang_error('package_upload_error_nofile'); |
|
686 | + } elseif (!is_uploaded_file($_FILES['package']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['package']['tmp_name']))) { |
|
687 | + fatal_lang_error('package_upload_error_failed'); |
|
688 | + } |
|
652 | 689 | |
653 | 690 | // Make sure it has a sane filename. |
654 | 691 | $_FILES['package']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['package']['name']); |
@@ -665,8 +702,9 @@ discard block |
||
665 | 702 | // Setup the destination and throw an error if the file is already there! |
666 | 703 | $destination = $packagesdir . '/' . $packageName; |
667 | 704 | // @todo Maybe just roll it like we do for downloads? |
668 | - if (file_exists($destination)) |
|
669 | - fatal_lang_error('package_upload_error_exists'); |
|
705 | + if (file_exists($destination)) { |
|
706 | + fatal_lang_error('package_upload_error_exists'); |
|
707 | + } |
|
670 | 708 | |
671 | 709 | // Now move the file. |
672 | 710 | move_uploaded_file($_FILES['package']['tmp_name'], $destination); |
@@ -689,12 +727,14 @@ discard block |
||
689 | 727 | { |
690 | 728 | while ($package = readdir($dir)) |
691 | 729 | { |
692 | - if ($package == '.' || $package == '..' || $package == 'temp' || $package == $packageName || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) |
|
693 | - continue; |
|
730 | + if ($package == '.' || $package == '..' || $package == 'temp' || $package == $packageName || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) { |
|
731 | + continue; |
|
732 | + } |
|
694 | 733 | |
695 | 734 | $packageInfo = getPackageInfo($package); |
696 | - if (!is_array($packageInfo)) |
|
697 | - continue; |
|
735 | + if (!is_array($packageInfo)) { |
|
736 | + continue; |
|
737 | + } |
|
698 | 738 | |
699 | 739 | if ($packageInfo['id'] == $context['package']['id'] && $packageInfo['version'] == $context['package']['version']) |
700 | 740 | { |
@@ -706,14 +746,15 @@ discard block |
||
706 | 746 | closedir($dir); |
707 | 747 | } |
708 | 748 | |
709 | - if ($context['package']['type'] == 'modification') |
|
710 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>'; |
|
711 | - elseif ($context['package']['type'] == 'avatar') |
|
712 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>'; |
|
713 | - elseif ($context['package']['type'] == 'language') |
|
714 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>'; |
|
715 | - else |
|
716 | - $context['package']['install']['link'] = ''; |
|
749 | + if ($context['package']['type'] == 'modification') { |
|
750 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>'; |
|
751 | + } elseif ($context['package']['type'] == 'avatar') { |
|
752 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>'; |
|
753 | + } elseif ($context['package']['type'] == 'language') { |
|
754 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>'; |
|
755 | + } else { |
|
756 | + $context['package']['install']['link'] = ''; |
|
757 | + } |
|
717 | 758 | |
718 | 759 | // Does a 3rd party hook want to do some additional changes? |
719 | 760 | call_integration_hook('integrate_package_upload'); |
@@ -736,16 +777,18 @@ discard block |
||
736 | 777 | checkSession(); |
737 | 778 | |
738 | 779 | // If they put a slash on the end, get rid of it. |
739 | - if (substr($_POST['serverurl'], -1) == '/') |
|
740 | - $_POST['serverurl'] = substr($_POST['serverurl'], 0, -1); |
|
780 | + if (substr($_POST['serverurl'], -1) == '/') { |
|
781 | + $_POST['serverurl'] = substr($_POST['serverurl'], 0, -1); |
|
782 | + } |
|
741 | 783 | |
742 | 784 | // Are they both nice and clean? |
743 | 785 | $servername = trim($smcFunc['htmlspecialchars']($_POST['servername'])); |
744 | 786 | $serverurl = trim($smcFunc['htmlspecialchars']($_POST['serverurl'])); |
745 | 787 | |
746 | 788 | // Make sure the URL has the correct prefix. |
747 | - if (strpos($serverurl, 'http://') !== 0 && strpos($serverurl, 'https://') !== 0) |
|
748 | - $serverurl = 'http://' . $serverurl; |
|
789 | + if (strpos($serverurl, 'http://') !== 0 && strpos($serverurl, 'https://') !== 0) { |
|
790 | + $serverurl = 'http://' . $serverurl; |
|
791 | + } |
|
749 | 792 | |
750 | 793 | $smcFunc['db_insert']('', |
751 | 794 | '{db_prefix}package_servers', |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 3 |
12 | 12 | */ |
13 | 13 | |
14 | -if (!defined('SMF')) |
|
14 | +if (!defined('SMF')) { |
|
15 | 15 | die('Hacking attempt...'); |
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * Interface cache_api_interface |
@@ -186,8 +187,9 @@ discard block |
||
186 | 187 | { |
187 | 188 | global $cache_enable; |
188 | 189 | |
189 | - if ($test) |
|
190 | - return true; |
|
190 | + if ($test) { |
|
191 | + return true; |
|
192 | + } |
|
191 | 193 | return !empty($cache_enable); |
192 | 194 | } |
193 | 195 | |
@@ -206,10 +208,11 @@ discard block |
||
206 | 208 | global $boardurl, $cachedir; |
207 | 209 | |
208 | 210 | // Set the default if no prefix was specified. |
209 | - if (empty($prefix)) |
|
210 | - $this->prefix = md5($boardurl . filemtime($cachedir . '/' . 'index.php')) . '-SMF-'; |
|
211 | - else |
|
212 | - $this->prefix = $prefix; |
|
211 | + if (empty($prefix)) { |
|
212 | + $this->prefix = md5($boardurl . filemtime($cachedir . '/' . 'index.php')) . '-SMF-'; |
|
213 | + } else { |
|
214 | + $this->prefix = $prefix; |
|
215 | + } |
|
213 | 216 | |
214 | 217 | return true; |
215 | 218 | } |
@@ -272,8 +275,9 @@ discard block |
||
272 | 275 | |
273 | 276 | // Invalidate cache, to be sure! |
274 | 277 | // ... as long as index.php can be modified, anyway. |
275 | - if (is_writable($cachedir . '/' . 'index.php')) |
|
276 | - @touch($cachedir . '/' . 'index.php'); |
|
278 | + if (is_writable($cachedir . '/' . 'index.php')) { |
|
279 | + @touch($cachedir . '/' . 'index.php'); |
|
280 | + } |
|
277 | 281 | |
278 | 282 | return true; |
279 | 283 | } |
@@ -59,8 +59,9 @@ discard block |
||
59 | 59 | * @version 2.1 Beta 3 |
60 | 60 | */ |
61 | 61 | |
62 | -if (!defined('SMF')) |
|
62 | +if (!defined('SMF')) { |
|
63 | 63 | die('No direct access...'); |
64 | +} |
|
64 | 65 | |
65 | 66 | /** |
66 | 67 | * This is the main dispatcher. Sets up all the available sub-actions, all the tabs and selects |
@@ -111,10 +112,11 @@ discard block |
||
111 | 112 | $settings_not_writable = !is_writable($boarddir . '/Settings.php'); |
112 | 113 | $settings_backup_fail = !@is_writable($boarddir . '/Settings_bak.php') || !@copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php'); |
113 | 114 | |
114 | - if ($settings_not_writable) |
|
115 | - $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>'; |
|
116 | - elseif ($settings_backup_fail) |
|
117 | - $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>'; |
|
115 | + if ($settings_not_writable) { |
|
116 | + $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>'; |
|
117 | + } elseif ($settings_backup_fail) { |
|
118 | + $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>'; |
|
119 | + } |
|
118 | 120 | |
119 | 121 | $context['settings_not_writable'] = $settings_not_writable; |
120 | 122 | |
@@ -166,8 +168,9 @@ discard block |
||
166 | 168 | |
167 | 169 | call_integration_hook('integrate_general_settings', array(&$config_vars)); |
168 | 170 | |
169 | - if ($return_config) |
|
170 | - return $config_vars; |
|
171 | + if ($return_config) { |
|
172 | + return $config_vars; |
|
173 | + } |
|
171 | 174 | |
172 | 175 | // Setup the template stuff. |
173 | 176 | $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=general;save'; |
@@ -232,8 +235,9 @@ discard block |
||
232 | 235 | |
233 | 236 | call_integration_hook('integrate_database_settings', array(&$config_vars)); |
234 | 237 | |
235 | - if ($return_config) |
|
236 | - return $config_vars; |
|
238 | + if ($return_config) { |
|
239 | + return $config_vars; |
|
240 | + } |
|
237 | 241 | |
238 | 242 | // Setup the template stuff. |
239 | 243 | $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=database;save'; |
@@ -308,13 +312,15 @@ discard block |
||
308 | 312 | hideGlobalCookies(); |
309 | 313 | });', true); |
310 | 314 | |
311 | - if (empty($user_settings['tfa_secret'])) |
|
312 | - addInlineJavaScript(''); |
|
315 | + if (empty($user_settings['tfa_secret'])) { |
|
316 | + addInlineJavaScript(''); |
|
317 | + } |
|
313 | 318 | |
314 | 319 | call_integration_hook('integrate_cookie_settings', array(&$config_vars)); |
315 | 320 | |
316 | - if ($return_config) |
|
317 | - return $config_vars; |
|
321 | + if ($return_config) { |
|
322 | + return $config_vars; |
|
323 | + } |
|
318 | 324 | |
319 | 325 | $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=cookie;save'; |
320 | 326 | $context['settings_title'] = $txt['cookies_sessions_settings']; |
@@ -325,11 +331,13 @@ discard block |
||
325 | 331 | call_integration_hook('integrate_save_cookie_settings'); |
326 | 332 | |
327 | 333 | // Local and global do not play nicely together. |
328 | - if (!empty($_POST['localCookies']) && empty($_POST['globalCookies'])) |
|
329 | - unset ($_POST['globalCookies']); |
|
334 | + if (!empty($_POST['localCookies']) && empty($_POST['globalCookies'])) { |
|
335 | + unset ($_POST['globalCookies']); |
|
336 | + } |
|
330 | 337 | |
331 | - if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false) |
|
332 | - fatal_lang_error('invalid_cookie_domain', false); |
|
338 | + if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false) { |
|
339 | + fatal_lang_error('invalid_cookie_domain', false); |
|
340 | + } |
|
333 | 341 | |
334 | 342 | saveSettings($config_vars); |
335 | 343 | |
@@ -412,8 +420,9 @@ discard block |
||
412 | 420 | |
413 | 421 | call_integration_hook('integrate_general_security_settings', array(&$config_vars)); |
414 | 422 | |
415 | - if ($return_config) |
|
416 | - return $config_vars; |
|
423 | + if ($return_config) { |
|
424 | + return $config_vars; |
|
425 | + } |
|
417 | 426 | |
418 | 427 | // Saving? |
419 | 428 | if (isset($_GET['save'])) |
@@ -452,8 +461,7 @@ discard block |
||
452 | 461 | $txt['cache_settings_message'] = $txt['detected_no_caching']; |
453 | 462 | $cache_level = array($txt['cache_off']); |
454 | 463 | $detected['none'] = $txt['cache_off']; |
455 | - } |
|
456 | - else |
|
464 | + } else |
|
457 | 465 | { |
458 | 466 | $txt['cache_settings_message'] = sprintf($txt['detected_accelerators'], implode(', ', $detected)); |
459 | 467 | $cache_level = array($txt['cache_off'], $txt['cache_level1'], $txt['cache_level2'], $txt['cache_level3']); |
@@ -490,8 +498,9 @@ discard block |
||
490 | 498 | } |
491 | 499 | } |
492 | 500 | } |
493 | - if ($return_config) |
|
494 | - return $config_vars; |
|
501 | + if ($return_config) { |
|
502 | + return $config_vars; |
|
503 | + } |
|
495 | 504 | |
496 | 505 | // Saving again? |
497 | 506 | if (isset($_GET['save'])) |
@@ -519,8 +528,9 @@ discard block |
||
519 | 528 | $context['save_disabled'] = $context['settings_not_writable']; |
520 | 529 | |
521 | 530 | // Decide what message to show. |
522 | - if (!$context['save_disabled']) |
|
523 | - $context['settings_message'] = $txt['caching_information']; |
|
531 | + if (!$context['save_disabled']) { |
|
532 | + $context['settings_message'] = $txt['caching_information']; |
|
533 | + } |
|
524 | 534 | |
525 | 535 | // Prepare the template. |
526 | 536 | prepareServerSettingsContext($config_vars); |
@@ -543,24 +553,25 @@ discard block |
||
543 | 553 | if (stripos(PHP_OS, 'win') === 0) |
544 | 554 | { |
545 | 555 | $context['settings_message'] = $txt['loadavg_disabled_windows']; |
546 | - if (isset($_GET['save'])) |
|
547 | - $_SESSION['adm-save'] = $txt['loadavg_disabled_windows']; |
|
548 | - } |
|
549 | - elseif (stripos(PHP_OS, 'darwin') === 0) |
|
556 | + if (isset($_GET['save'])) { |
|
557 | + $_SESSION['adm-save'] = $txt['loadavg_disabled_windows']; |
|
558 | + } |
|
559 | + } elseif (stripos(PHP_OS, 'darwin') === 0) |
|
550 | 560 | { |
551 | 561 | $context['settings_message'] = $txt['loadavg_disabled_osx']; |
552 | - if (isset($_GET['save'])) |
|
553 | - $_SESSION['adm-save'] = $txt['loadavg_disabled_osx']; |
|
554 | - } |
|
555 | - else |
|
562 | + if (isset($_GET['save'])) { |
|
563 | + $_SESSION['adm-save'] = $txt['loadavg_disabled_osx']; |
|
564 | + } |
|
565 | + } else |
|
556 | 566 | { |
557 | 567 | $modSettings['load_average'] = @file_get_contents('/proc/loadavg'); |
558 | - if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0) |
|
559 | - $modSettings['load_average'] = (float) $matches[1]; |
|
560 | - elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0) |
|
561 | - $modSettings['load_average'] = (float) $matches[1]; |
|
562 | - else |
|
563 | - unset($modSettings['load_average']); |
|
568 | + if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0) { |
|
569 | + $modSettings['load_average'] = (float) $matches[1]; |
|
570 | + } elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0) { |
|
571 | + $modSettings['load_average'] = (float) $matches[1]; |
|
572 | + } else { |
|
573 | + unset($modSettings['load_average']); |
|
574 | + } |
|
564 | 575 | |
565 | 576 | if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
566 | 577 | { |
@@ -596,8 +607,9 @@ discard block |
||
596 | 607 | |
597 | 608 | call_integration_hook('integrate_loadavg_settings', array(&$config_vars)); |
598 | 609 | |
599 | - if ($return_config) |
|
600 | - return $config_vars; |
|
610 | + if ($return_config) { |
|
611 | + return $config_vars; |
|
612 | + } |
|
601 | 613 | |
602 | 614 | $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=loads;save'; |
603 | 615 | $context['settings_title'] = $txt['load_balancing_settings']; |
@@ -608,24 +620,27 @@ discard block |
||
608 | 620 | // Stupidity is not allowed. |
609 | 621 | foreach ($_POST as $key => $value) |
610 | 622 | { |
611 | - if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values))) |
|
612 | - continue; |
|
613 | - else |
|
614 | - $_POST[$key] = (float) $value; |
|
615 | - |
|
616 | - if ($key == 'loadavg_auto_opt' && $value <= 1) |
|
617 | - $_POST['loadavg_auto_opt'] = 1.0; |
|
618 | - elseif ($key == 'loadavg_forum' && $value < 10) |
|
619 | - $_POST['loadavg_forum'] = 10.0; |
|
620 | - elseif ($value < 2) |
|
621 | - $_POST[$key] = 2.0; |
|
623 | + if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values))) { |
|
624 | + continue; |
|
625 | + } else { |
|
626 | + $_POST[$key] = (float) $value; |
|
627 | + } |
|
628 | + |
|
629 | + if ($key == 'loadavg_auto_opt' && $value <= 1) { |
|
630 | + $_POST['loadavg_auto_opt'] = 1.0; |
|
631 | + } elseif ($key == 'loadavg_forum' && $value < 10) { |
|
632 | + $_POST['loadavg_forum'] = 10.0; |
|
633 | + } elseif ($value < 2) { |
|
634 | + $_POST[$key] = 2.0; |
|
635 | + } |
|
622 | 636 | } |
623 | 637 | |
624 | 638 | call_integration_hook('integrate_save_loadavg_settings'); |
625 | 639 | |
626 | 640 | saveDBSettings($config_vars); |
627 | - if (!isset($_SESSION['adm-save'])) |
|
628 | - $_SESSION['adm-save'] = true; |
|
641 | + if (!isset($_SESSION['adm-save'])) { |
|
642 | + $_SESSION['adm-save'] = true; |
|
643 | + } |
|
629 | 644 | redirectexit('action=admin;area=serversettings;sa=loads;' . $context['session_var'] . '=' . $context['session_id']); |
630 | 645 | } |
631 | 646 | |
@@ -661,10 +676,11 @@ discard block |
||
661 | 676 | |
662 | 677 | if (isset($_SESSION['adm-save'])) |
663 | 678 | { |
664 | - if ($_SESSION['adm-save'] === true) |
|
665 | - $context['saved_successful'] = true; |
|
666 | - else |
|
667 | - $context['saved_failed'] = $_SESSION['adm-save']; |
|
679 | + if ($_SESSION['adm-save'] === true) { |
|
680 | + $context['saved_successful'] = true; |
|
681 | + } else { |
|
682 | + $context['saved_failed'] = $_SESSION['adm-save']; |
|
683 | + } |
|
668 | 684 | |
669 | 685 | unset($_SESSION['adm-save']); |
670 | 686 | } |
@@ -672,9 +688,9 @@ discard block |
||
672 | 688 | $context['config_vars'] = array(); |
673 | 689 | foreach ($config_vars as $identifier => $config_var) |
674 | 690 | { |
675 | - if (!is_array($config_var) || !isset($config_var[1])) |
|
676 | - $context['config_vars'][] = $config_var; |
|
677 | - else |
|
691 | + if (!is_array($config_var) || !isset($config_var[1])) { |
|
692 | + $context['config_vars'][] = $config_var; |
|
693 | + } else |
|
678 | 694 | { |
679 | 695 | $varname = $config_var[0]; |
680 | 696 | global $$varname; |
@@ -709,16 +725,19 @@ discard block |
||
709 | 725 | if ($config_var[3] == 'int' || $config_var[3] == 'float') |
710 | 726 | { |
711 | 727 | // Default to a min of 0 if one isn't set |
712 | - if (isset($config_var['min'])) |
|
713 | - $context['config_vars'][$config_var[0]]['min'] = $config_var['min']; |
|
714 | - else |
|
715 | - $context['config_vars'][$config_var[0]]['min'] = 0; |
|
728 | + if (isset($config_var['min'])) { |
|
729 | + $context['config_vars'][$config_var[0]]['min'] = $config_var['min']; |
|
730 | + } else { |
|
731 | + $context['config_vars'][$config_var[0]]['min'] = 0; |
|
732 | + } |
|
716 | 733 | |
717 | - if (isset($config_var['max'])) |
|
718 | - $context['config_vars'][$config_var[0]]['max'] = $config_var['max']; |
|
734 | + if (isset($config_var['max'])) { |
|
735 | + $context['config_vars'][$config_var[0]]['max'] = $config_var['max']; |
|
736 | + } |
|
719 | 737 | |
720 | - if (isset($config_var['step'])) |
|
721 | - $context['config_vars'][$config_var[0]]['step'] = $config_var['step']; |
|
738 | + if (isset($config_var['step'])) { |
|
739 | + $context['config_vars'][$config_var[0]]['step'] = $config_var['step']; |
|
740 | + } |
|
722 | 741 | } |
723 | 742 | |
724 | 743 | // If this is a select box handle any data. |
@@ -726,12 +745,13 @@ discard block |
||
726 | 745 | { |
727 | 746 | // If it's associative |
728 | 747 | $config_values = array_values($config_var[4]); |
729 | - if (isset($config_values[0]) && is_array($config_values[0])) |
|
730 | - $context['config_vars'][$config_var[0]]['data'] = $config_var[4]; |
|
731 | - else |
|
748 | + if (isset($config_values[0]) && is_array($config_values[0])) { |
|
749 | + $context['config_vars'][$config_var[0]]['data'] = $config_var[4]; |
|
750 | + } else |
|
732 | 751 | { |
733 | - foreach ($config_var[4] as $key => $item) |
|
734 | - $context['config_vars'][$config_var[0]]['data'][] = array($key, $item); |
|
752 | + foreach ($config_var[4] as $key => $item) { |
|
753 | + $context['config_vars'][$config_var[0]]['data'][] = array($key, $item); |
|
754 | + } |
|
735 | 755 | } |
736 | 756 | } |
737 | 757 | } |
@@ -756,10 +776,11 @@ discard block |
||
756 | 776 | |
757 | 777 | if (isset($_SESSION['adm-save'])) |
758 | 778 | { |
759 | - if ($_SESSION['adm-save'] === true) |
|
760 | - $context['saved_successful'] = true; |
|
761 | - else |
|
762 | - $context['saved_failed'] = $_SESSION['adm-save']; |
|
779 | + if ($_SESSION['adm-save'] === true) { |
|
780 | + $context['saved_successful'] = true; |
|
781 | + } else { |
|
782 | + $context['saved_failed'] = $_SESSION['adm-save']; |
|
783 | + } |
|
763 | 784 | |
764 | 785 | unset($_SESSION['adm-save']); |
765 | 786 | } |
@@ -771,26 +792,30 @@ discard block |
||
771 | 792 | foreach ($config_vars as $config_var) |
772 | 793 | { |
773 | 794 | // HR? |
774 | - if (!is_array($config_var)) |
|
775 | - $context['config_vars'][] = $config_var; |
|
776 | - else |
|
795 | + if (!is_array($config_var)) { |
|
796 | + $context['config_vars'][] = $config_var; |
|
797 | + } else |
|
777 | 798 | { |
778 | 799 | // If it has no name it doesn't have any purpose! |
779 | - if (empty($config_var[1])) |
|
780 | - continue; |
|
800 | + if (empty($config_var[1])) { |
|
801 | + continue; |
|
802 | + } |
|
781 | 803 | |
782 | 804 | // Special case for inline permissions |
783 | - if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) |
|
784 | - $inlinePermissions[] = $config_var[1]; |
|
785 | - elseif ($config_var[0] == 'permissions') |
|
786 | - continue; |
|
805 | + if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) { |
|
806 | + $inlinePermissions[] = $config_var[1]; |
|
807 | + } elseif ($config_var[0] == 'permissions') { |
|
808 | + continue; |
|
809 | + } |
|
787 | 810 | |
788 | - if ($config_var[0] == 'boards') |
|
789 | - $board_list = true; |
|
811 | + if ($config_var[0] == 'boards') { |
|
812 | + $board_list = true; |
|
813 | + } |
|
790 | 814 | |
791 | 815 | // Are we showing the BBC selection box? |
792 | - if ($config_var[0] == 'bbc') |
|
793 | - $bbcChoice[] = $config_var[1]; |
|
816 | + if ($config_var[0] == 'bbc') { |
|
817 | + $bbcChoice[] = $config_var[1]; |
|
818 | + } |
|
794 | 819 | |
795 | 820 | // We need to do some parsing of the value before we pass it in. |
796 | 821 | if (isset($modSettings[$config_var[1]])) |
@@ -809,8 +834,7 @@ discard block |
||
809 | 834 | default: |
810 | 835 | $value = $smcFunc['htmlspecialchars']($modSettings[$config_var[1]]); |
811 | 836 | } |
812 | - } |
|
813 | - else |
|
837 | + } else |
|
814 | 838 | { |
815 | 839 | // Darn, it's empty. What type is expected? |
816 | 840 | switch ($config_var[0]) |
@@ -850,16 +874,19 @@ discard block |
||
850 | 874 | if ($config_var[0] == 'int' || $config_var[0] == 'float') |
851 | 875 | { |
852 | 876 | // Default to a min of 0 if one isn't set |
853 | - if (isset($config_var['min'])) |
|
854 | - $context['config_vars'][$config_var[1]]['min'] = $config_var['min']; |
|
855 | - else |
|
856 | - $context['config_vars'][$config_var[1]]['min'] = 0; |
|
877 | + if (isset($config_var['min'])) { |
|
878 | + $context['config_vars'][$config_var[1]]['min'] = $config_var['min']; |
|
879 | + } else { |
|
880 | + $context['config_vars'][$config_var[1]]['min'] = 0; |
|
881 | + } |
|
857 | 882 | |
858 | - if (isset($config_var['max'])) |
|
859 | - $context['config_vars'][$config_var[1]]['max'] = $config_var['max']; |
|
883 | + if (isset($config_var['max'])) { |
|
884 | + $context['config_vars'][$config_var[1]]['max'] = $config_var['max']; |
|
885 | + } |
|
860 | 886 | |
861 | - if (isset($config_var['step'])) |
|
862 | - $context['config_vars'][$config_var[1]]['step'] = $config_var['step']; |
|
887 | + if (isset($config_var['step'])) { |
|
888 | + $context['config_vars'][$config_var[1]]['step'] = $config_var['step']; |
|
889 | + } |
|
863 | 890 | } |
864 | 891 | |
865 | 892 | // If this is a select box handle any data. |
@@ -873,12 +900,13 @@ discard block |
||
873 | 900 | } |
874 | 901 | |
875 | 902 | // If it's associative |
876 | - if (isset($config_var[2][0]) && is_array($config_var[2][0])) |
|
877 | - $context['config_vars'][$config_var[1]]['data'] = $config_var[2]; |
|
878 | - else |
|
903 | + if (isset($config_var[2][0]) && is_array($config_var[2][0])) { |
|
904 | + $context['config_vars'][$config_var[1]]['data'] = $config_var[2]; |
|
905 | + } else |
|
879 | 906 | { |
880 | - foreach ($config_var[2] as $key => $item) |
|
881 | - $context['config_vars'][$config_var[1]]['data'][] = array($key, $item); |
|
907 | + foreach ($config_var[2] as $key => $item) { |
|
908 | + $context['config_vars'][$config_var[1]]['data'][] = array($key, $item); |
|
909 | + } |
|
882 | 910 | } |
883 | 911 | } |
884 | 912 | |
@@ -887,17 +915,19 @@ discard block |
||
887 | 915 | { |
888 | 916 | if (!is_numeric($k)) |
889 | 917 | { |
890 | - if (substr($k, 0, 2) == 'on') |
|
891 | - $context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"'; |
|
892 | - else |
|
893 | - $context['config_vars'][$config_var[1]][$k] = $v; |
|
918 | + if (substr($k, 0, 2) == 'on') { |
|
919 | + $context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"'; |
|
920 | + } else { |
|
921 | + $context['config_vars'][$config_var[1]][$k] = $v; |
|
922 | + } |
|
894 | 923 | } |
895 | 924 | |
896 | 925 | // See if there are any other labels that might fit? |
897 | - if (isset($txt['setting_' . $config_var[1]])) |
|
898 | - $context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]]; |
|
899 | - elseif (isset($txt['groups_' . $config_var[1]])) |
|
900 | - $context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]]; |
|
926 | + if (isset($txt['setting_' . $config_var[1]])) { |
|
927 | + $context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]]; |
|
928 | + } elseif (isset($txt['groups_' . $config_var[1]])) { |
|
929 | + $context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]]; |
|
930 | + } |
|
901 | 931 | } |
902 | 932 | |
903 | 933 | // Set the subtext in case it's part of the label. |
@@ -930,8 +960,9 @@ discard block |
||
930 | 960 | // What are the options, eh? |
931 | 961 | $temp = parse_bbc(false); |
932 | 962 | $bbcTags = array(); |
933 | - foreach ($temp as $tag) |
|
934 | - $bbcTags[] = $tag['tag']; |
|
963 | + foreach ($temp as $tag) { |
|
964 | + $bbcTags[] = $tag['tag']; |
|
965 | + } |
|
935 | 966 | |
936 | 967 | $bbcTags = array_unique($bbcTags); |
937 | 968 | $totalTags = count($bbcTags); |
@@ -946,8 +977,9 @@ discard block |
||
946 | 977 | $col = 0; $i = 0; |
947 | 978 | foreach ($bbcTags as $tag) |
948 | 979 | { |
949 | - if ($i % $tagsPerColumn == 0 && $i != 0) |
|
950 | - $col++; |
|
980 | + if ($i % $tagsPerColumn == 0 && $i != 0) { |
|
981 | + $col++; |
|
982 | + } |
|
951 | 983 | |
952 | 984 | $context['bbc_columns'][$col][] = array( |
953 | 985 | 'tag' => $tag, |
@@ -990,18 +1022,21 @@ discard block |
||
990 | 1022 | validateToken('admin-ssc'); |
991 | 1023 | |
992 | 1024 | // Fix the darn stupid cookiename! (more may not be allowed, but these for sure!) |
993 | - if (isset($_POST['cookiename'])) |
|
994 | - $_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']); |
|
1025 | + if (isset($_POST['cookiename'])) { |
|
1026 | + $_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']); |
|
1027 | + } |
|
995 | 1028 | |
996 | 1029 | // Fix the forum's URL if necessary. |
997 | 1030 | if (isset($_POST['boardurl'])) |
998 | 1031 | { |
999 | - if (substr($_POST['boardurl'], -10) == '/index.php') |
|
1000 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
1001 | - elseif (substr($_POST['boardurl'], -1) == '/') |
|
1002 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
1003 | - if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') |
|
1004 | - $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
1032 | + if (substr($_POST['boardurl'], -10) == '/index.php') { |
|
1033 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
1034 | + } elseif (substr($_POST['boardurl'], -1) == '/') { |
|
1035 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
1036 | + } |
|
1037 | + if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') { |
|
1038 | + $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
1039 | + } |
|
1005 | 1040 | } |
1006 | 1041 | |
1007 | 1042 | // Any passwords? |
@@ -1036,21 +1071,21 @@ discard block |
||
1036 | 1071 | // Figure out which config vars we're saving here... |
1037 | 1072 | foreach ($config_vars as $var) |
1038 | 1073 | { |
1039 | - if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]]))) |
|
1040 | - continue; |
|
1074 | + if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]]))) { |
|
1075 | + continue; |
|
1076 | + } |
|
1041 | 1077 | |
1042 | 1078 | $config_var = $var[0]; |
1043 | 1079 | |
1044 | 1080 | if (in_array($config_var, $config_passwords)) |
1045 | 1081 | { |
1046 | - if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1]) |
|
1047 | - $new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\''; |
|
1048 | - } |
|
1049 | - elseif (in_array($config_var, $config_strs)) |
|
1082 | + if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1]) { |
|
1083 | + $new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\''; |
|
1084 | + } |
|
1085 | + } elseif (in_array($config_var, $config_strs)) |
|
1050 | 1086 | { |
1051 | 1087 | $new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var], '\'\\') . '\''; |
1052 | - } |
|
1053 | - elseif (in_array($config_var, $config_ints)) |
|
1088 | + } elseif (in_array($config_var, $config_ints)) |
|
1054 | 1089 | { |
1055 | 1090 | $new_settings[$config_var] = (int) $_POST[$config_var]; |
1056 | 1091 | |
@@ -1059,17 +1094,17 @@ discard block |
||
1059 | 1094 | $new_settings[$config_var] = max($min, $new_settings[$config_var]); |
1060 | 1095 | |
1061 | 1096 | // Is there a max value for this as well? |
1062 | - if (isset($var['max'])) |
|
1063 | - $new_settings[$config_var] = min($var['max'], $new_settings[$config_var]); |
|
1064 | - } |
|
1065 | - elseif (in_array($config_var, $config_bools)) |
|
1097 | + if (isset($var['max'])) { |
|
1098 | + $new_settings[$config_var] = min($var['max'], $new_settings[$config_var]); |
|
1099 | + } |
|
1100 | + } elseif (in_array($config_var, $config_bools)) |
|
1066 | 1101 | { |
1067 | - if (!empty($_POST[$config_var])) |
|
1068 | - $new_settings[$config_var] = '1'; |
|
1069 | - else |
|
1070 | - $new_settings[$config_var] = '0'; |
|
1071 | - } |
|
1072 | - else |
|
1102 | + if (!empty($_POST[$config_var])) { |
|
1103 | + $new_settings[$config_var] = '1'; |
|
1104 | + } else { |
|
1105 | + $new_settings[$config_var] = '0'; |
|
1106 | + } |
|
1107 | + } else |
|
1073 | 1108 | { |
1074 | 1109 | // This shouldn't happen, but it might... |
1075 | 1110 | fatal_error('Unknown config_var \'' . $config_var . '\''); |
@@ -1085,30 +1120,35 @@ discard block |
||
1085 | 1120 | foreach ($config_vars as $config_var) |
1086 | 1121 | { |
1087 | 1122 | // We just saved the file-based settings, so skip their definitions. |
1088 | - if (!is_array($config_var) || $config_var[2] == 'file') |
|
1089 | - continue; |
|
1123 | + if (!is_array($config_var) || $config_var[2] == 'file') { |
|
1124 | + continue; |
|
1125 | + } |
|
1090 | 1126 | |
1091 | 1127 | $new_setting = array($config_var[3], $config_var[0]); |
1092 | 1128 | |
1093 | 1129 | // Select options need carried over, too. |
1094 | - if (isset($config_var[4])) |
|
1095 | - $new_setting[] = $config_var[4]; |
|
1130 | + if (isset($config_var[4])) { |
|
1131 | + $new_setting[] = $config_var[4]; |
|
1132 | + } |
|
1096 | 1133 | |
1097 | 1134 | // Include min and max if necessary |
1098 | - if (isset($config_var['min'])) |
|
1099 | - $new_setting['min'] = $config_var['min']; |
|
1135 | + if (isset($config_var['min'])) { |
|
1136 | + $new_setting['min'] = $config_var['min']; |
|
1137 | + } |
|
1100 | 1138 | |
1101 | - if (isset($config_var['max'])) |
|
1102 | - $new_setting['max'] = $config_var['max']; |
|
1139 | + if (isset($config_var['max'])) { |
|
1140 | + $new_setting['max'] = $config_var['max']; |
|
1141 | + } |
|
1103 | 1142 | |
1104 | 1143 | // Rewrite the definition a bit. |
1105 | 1144 | $new_settings[] = $new_setting; |
1106 | 1145 | } |
1107 | 1146 | |
1108 | 1147 | // Save the new database-based settings, if any. |
1109 | - if (!empty($new_settings)) |
|
1110 | - saveDBSettings($new_settings); |
|
1111 | -} |
|
1148 | + if (!empty($new_settings)) { |
|
1149 | + saveDBSettings($new_settings); |
|
1150 | + } |
|
1151 | + } |
|
1112 | 1152 | |
1113 | 1153 | /** |
1114 | 1154 | * Helper function for saving database settings. |
@@ -1126,22 +1166,25 @@ discard block |
||
1126 | 1166 | $inlinePermissions = array(); |
1127 | 1167 | foreach ($config_vars as $var) |
1128 | 1168 | { |
1129 | - if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags'])))) |
|
1130 | - continue; |
|
1169 | + if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags'])))) { |
|
1170 | + continue; |
|
1171 | + } |
|
1131 | 1172 | |
1132 | 1173 | // Checkboxes! |
1133 | - elseif ($var[0] == 'check') |
|
1134 | - $setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0'; |
|
1174 | + elseif ($var[0] == 'check') { |
|
1175 | + $setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0'; |
|
1176 | + } |
|
1135 | 1177 | // Select boxes! |
1136 | - elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) |
|
1137 | - $setArray[$var[1]] = $_POST[$var[1]]; |
|
1138 | - elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array()) |
|
1178 | + elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) { |
|
1179 | + $setArray[$var[1]] = $_POST[$var[1]]; |
|
1180 | + } elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array()) |
|
1139 | 1181 | { |
1140 | 1182 | // For security purposes we validate this line by line. |
1141 | 1183 | $lOptions = array(); |
1142 | - foreach ($_POST[$var[1]] as $invar) |
|
1143 | - if (in_array($invar, array_keys($var[2]))) |
|
1184 | + foreach ($_POST[$var[1]] as $invar) { |
|
1185 | + if (in_array($invar, array_keys($var[2]))) |
|
1144 | 1186 | $lOptions[] = $invar; |
1187 | + } |
|
1145 | 1188 | |
1146 | 1189 | $setArray[$var[1]] = json_encode($lOptions); |
1147 | 1190 | } |
@@ -1155,18 +1198,20 @@ discard block |
||
1155 | 1198 | $request = $smcFunc['db_query']('', ' |
1156 | 1199 | SELECT id_board |
1157 | 1200 | FROM {db_prefix}boards'); |
1158 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
1159 | - $board_list[$row[0]] = true; |
|
1201 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
1202 | + $board_list[$row[0]] = true; |
|
1203 | + } |
|
1160 | 1204 | |
1161 | 1205 | $smcFunc['db_free_result']($request); |
1162 | 1206 | } |
1163 | 1207 | |
1164 | 1208 | $lOptions = array(); |
1165 | 1209 | |
1166 | - if (!empty($_POST[$var[1]])) |
|
1167 | - foreach ($_POST[$var[1]] as $invar => $dummy) |
|
1210 | + if (!empty($_POST[$var[1]])) { |
|
1211 | + foreach ($_POST[$var[1]] as $invar => $dummy) |
|
1168 | 1212 | if (isset($board_list[$invar])) |
1169 | 1213 | $lOptions[] = $invar; |
1214 | + } |
|
1170 | 1215 | |
1171 | 1216 | $setArray[$var[1]] = !empty($lOptions) ? implode(',', $lOptions) : ''; |
1172 | 1217 | } |
@@ -1180,8 +1225,9 @@ discard block |
||
1180 | 1225 | $setArray[$var[1]] = max($min, $setArray[$var[1]]); |
1181 | 1226 | |
1182 | 1227 | // Do we have a max value for this as well? |
1183 | - if (isset($var['max'])) |
|
1184 | - $setArray[$var[1]] = min($var['max'], $setArray[$var[1]]); |
|
1228 | + if (isset($var['max'])) { |
|
1229 | + $setArray[$var[1]] = min($var['max'], $setArray[$var[1]]); |
|
1230 | + } |
|
1185 | 1231 | } |
1186 | 1232 | // Floating point! |
1187 | 1233 | elseif ($var[0] == 'float') |
@@ -1193,40 +1239,47 @@ discard block |
||
1193 | 1239 | $setArray[$var[1]] = max($min, $setArray[$var[1]]); |
1194 | 1240 | |
1195 | 1241 | // Do we have a max value for this as well? |
1196 | - if (isset($var['max'])) |
|
1197 | - $setArray[$var[1]] = min($var['max'], $setArray[$var[1]]); |
|
1242 | + if (isset($var['max'])) { |
|
1243 | + $setArray[$var[1]] = min($var['max'], $setArray[$var[1]]); |
|
1244 | + } |
|
1198 | 1245 | } |
1199 | 1246 | // Text! |
1200 | - elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'))) |
|
1201 | - $setArray[$var[1]] = $_POST[$var[1]]; |
|
1247 | + elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'))) { |
|
1248 | + $setArray[$var[1]] = $_POST[$var[1]]; |
|
1249 | + } |
|
1202 | 1250 | // Passwords! |
1203 | 1251 | elseif ($var[0] == 'password') |
1204 | 1252 | { |
1205 | - if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1]) |
|
1206 | - $setArray[$var[1]] = $_POST[$var[1]][0]; |
|
1253 | + if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1]) { |
|
1254 | + $setArray[$var[1]] = $_POST[$var[1]][0]; |
|
1255 | + } |
|
1207 | 1256 | } |
1208 | 1257 | // BBC. |
1209 | 1258 | elseif ($var[0] == 'bbc') |
1210 | 1259 | { |
1211 | 1260 | |
1212 | 1261 | $bbcTags = array(); |
1213 | - foreach (parse_bbc(false) as $tag) |
|
1214 | - $bbcTags[] = $tag['tag']; |
|
1262 | + foreach (parse_bbc(false) as $tag) { |
|
1263 | + $bbcTags[] = $tag['tag']; |
|
1264 | + } |
|
1215 | 1265 | |
1216 | - if (!isset($_POST[$var[1] . '_enabledTags'])) |
|
1217 | - $_POST[$var[1] . '_enabledTags'] = array(); |
|
1218 | - elseif (!is_array($_POST[$var[1] . '_enabledTags'])) |
|
1219 | - $_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']); |
|
1266 | + if (!isset($_POST[$var[1] . '_enabledTags'])) { |
|
1267 | + $_POST[$var[1] . '_enabledTags'] = array(); |
|
1268 | + } elseif (!is_array($_POST[$var[1] . '_enabledTags'])) { |
|
1269 | + $_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']); |
|
1270 | + } |
|
1220 | 1271 | |
1221 | 1272 | $setArray[$var[1]] = implode(',', array_diff($bbcTags, $_POST[$var[1] . '_enabledTags'])); |
1222 | 1273 | } |
1223 | 1274 | // Permissions? |
1224 | - elseif ($var[0] == 'permissions') |
|
1225 | - $inlinePermissions[] = $var[1]; |
|
1275 | + elseif ($var[0] == 'permissions') { |
|
1276 | + $inlinePermissions[] = $var[1]; |
|
1277 | + } |
|
1226 | 1278 | } |
1227 | 1279 | |
1228 | - if (!empty($setArray)) |
|
1229 | - updateSettings($setArray); |
|
1280 | + if (!empty($setArray)) { |
|
1281 | + updateSettings($setArray); |
|
1282 | + } |
|
1230 | 1283 | |
1231 | 1284 | // If we have inline permissions we need to save them. |
1232 | 1285 | if (!empty($inlinePermissions) && allowedTo('manage_permissions')) |
@@ -1264,18 +1317,21 @@ discard block |
||
1264 | 1317 | // put all of it into an array |
1265 | 1318 | foreach ($info_lines as $line) |
1266 | 1319 | { |
1267 | - if (preg_match('~(' . $remove . ')~', $line)) |
|
1268 | - continue; |
|
1320 | + if (preg_match('~(' . $remove . ')~', $line)) { |
|
1321 | + continue; |
|
1322 | + } |
|
1269 | 1323 | |
1270 | 1324 | // new category? |
1271 | - if (strpos($line, '<h2>') !== false) |
|
1272 | - $category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category; |
|
1325 | + if (strpos($line, '<h2>') !== false) { |
|
1326 | + $category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category; |
|
1327 | + } |
|
1273 | 1328 | |
1274 | 1329 | // load it as setting => value or the old setting local master |
1275 | - if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) |
|
1276 | - $pinfo[$category][$val[1]] = $val[2]; |
|
1277 | - elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) |
|
1278 | - $pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]); |
|
1330 | + if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) { |
|
1331 | + $pinfo[$category][$val[1]] = $val[2]; |
|
1332 | + } elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) { |
|
1333 | + $pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]); |
|
1334 | + } |
|
1279 | 1335 | } |
1280 | 1336 | |
1281 | 1337 | // load it in to context and display it |
@@ -1310,8 +1366,9 @@ discard block |
||
1310 | 1366 | $testAPI = new $cache_class_name(); |
1311 | 1367 | |
1312 | 1368 | // No Support? NEXT! |
1313 | - if (!$testAPI->isSupported(true)) |
|
1314 | - continue; |
|
1369 | + if (!$testAPI->isSupported(true)) { |
|
1370 | + continue; |
|
1371 | + } |
|
1315 | 1372 | |
1316 | 1373 | $apis[$tryCache] = isset($txt[$tryCache . '_cache']) ? $txt[$tryCache . '_cache'] : $tryCache; |
1317 | 1374 | } |