@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * Start the curl object |
| 63 | 63 | * - allow for user override values |
| 64 | 64 | * |
| 65 | - * @param array $options An array of cURL options |
|
| 65 | + * @param integer[] $options An array of cURL options |
|
| 66 | 66 | * @param int $max_redirect Maximum number of redirects |
| 67 | 67 | * @return void |
| 68 | 68 | */ |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | * - calls set_options to set the curl opts array values based on the defaults and user input |
| 82 | 82 | * |
| 83 | 83 | * @param string $url the site we are going to fetch |
| 84 | - * @param array $post_data any post data as form name => value |
|
| 85 | - * @return object An instance of the curl_fetch_web_data class |
|
| 84 | + * @param string $post_data any post data as form name => value |
|
| 85 | + * @return curl_fetch_web_data An instance of the curl_fetch_web_data class |
|
| 86 | 86 | */ |
| 87 | 87 | public function get_url_data($url, $post_data = array()) |
| 88 | 88 | { |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | * |
| 107 | 107 | * @param string $url The site to fetch |
| 108 | 108 | * @param bool $redirect Whether or not this was a redirect request |
| 109 | - * @return void|bool Sets various properties of the class or returns false if the URL isn't specified |
|
| 109 | + * @return false|null Sets various properties of the class or returns false if the URL isn't specified |
|
| 110 | 110 | */ |
| 111 | 111 | private function curl_request($url, $redirect = false) |
| 112 | 112 | { |
@@ -10,8 +10,9 @@ discard block |
||
| 10 | 10 | * @version 2.1 Beta 3 |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | -if (!defined('SMF')) |
|
| 13 | +if (!defined('SMF')) { |
|
| 14 | 14 | die('No direct access...'); |
| 15 | +} |
|
| 15 | 16 | |
| 16 | 17 | /** |
| 17 | 18 | * Class curl_fetch_web_data |
@@ -87,10 +88,11 @@ discard block |
||
| 87 | 88 | public function get_url_data($url, $post_data = array()) |
| 88 | 89 | { |
| 89 | 90 | // POSTing some data perhaps? |
| 90 | - if (!empty($post_data) && is_array($post_data)) |
|
| 91 | - $this->post_data = $this->build_post_data($post_data); |
|
| 92 | - elseif (!empty($post_data)) |
|
| 93 | - $this->post_data = trim($post_data); |
|
| 91 | + if (!empty($post_data) && is_array($post_data)) { |
|
| 92 | + $this->post_data = $this->build_post_data($post_data); |
|
| 93 | + } elseif (!empty($post_data)) { |
|
| 94 | + $this->post_data = trim($post_data); |
|
| 95 | + } |
|
| 94 | 96 | |
| 95 | 97 | // set the options and get it |
| 96 | 98 | $this->set_options(); |
@@ -111,10 +113,11 @@ discard block |
||
| 111 | 113 | private function curl_request($url, $redirect = false) |
| 112 | 114 | { |
| 113 | 115 | // we do have a url I hope |
| 114 | - if ($url == '') |
|
| 115 | - return false; |
|
| 116 | - else |
|
| 117 | - $this->options[CURLOPT_URL] = $url; |
|
| 116 | + if ($url == '') { |
|
| 117 | + return false; |
|
| 118 | + } else { |
|
| 119 | + $this->options[CURLOPT_URL] = $url; |
|
| 120 | + } |
|
| 118 | 121 | |
| 119 | 122 | // if we have not already been redirected, set it up so we can if needed |
| 120 | 123 | if (!$redirect) |
@@ -194,10 +197,11 @@ discard block |
||
| 194 | 197 | $max_result = count($this->response) - 1; |
| 195 | 198 | |
| 196 | 199 | // just return a specifed area or the entire result? |
| 197 | - if ($area == '') |
|
| 198 | - return $this->response[$max_result]; |
|
| 199 | - else |
|
| 200 | - return isset($this->response[$max_result][$area]) ? $this->response[$max_result][$area] : $this->response[$max_result]; |
|
| 200 | + if ($area == '') { |
|
| 201 | + return $this->response[$max_result]; |
|
| 202 | + } else { |
|
| 203 | + return isset($this->response[$max_result][$area]) ? $this->response[$max_result][$area] : $this->response[$max_result]; |
|
| 204 | + } |
|
| 201 | 205 | } |
| 202 | 206 | |
| 203 | 207 | /** |
@@ -210,9 +214,9 @@ discard block |
||
| 210 | 214 | */ |
| 211 | 215 | public function result_raw($response_number = '') |
| 212 | 216 | { |
| 213 | - if (!is_numeric($response_number)) |
|
| 214 | - return $this->response; |
|
| 215 | - else |
|
| 217 | + if (!is_numeric($response_number)) { |
|
| 218 | + return $this->response; |
|
| 219 | + } else |
|
| 216 | 220 | { |
| 217 | 221 | $response_number = min($response_number, count($this->response) - 1); |
| 218 | 222 | return $this->response[$response_number]; |
@@ -234,13 +238,14 @@ discard block |
||
| 234 | 238 | $postvars = array(); |
| 235 | 239 | |
| 236 | 240 | // build the post data, drop ones with leading @'s since those can be used to send files, we don't support that. |
| 237 | - foreach ($post_data as $name => $value) |
|
| 238 | - $postvars[] = $name . '=' . urlencode($value[0] == '@' ? '' : $value); |
|
| 241 | + foreach ($post_data as $name => $value) { |
|
| 242 | + $postvars[] = $name . '=' . urlencode($value[0] == '@' ? '' : $value); |
|
| 243 | + } |
|
| 239 | 244 | |
| 240 | 245 | return implode('&', $postvars); |
| 246 | + } else { |
|
| 247 | + return $post_data; |
|
| 241 | 248 | } |
| 242 | - else |
|
| 243 | - return $post_data; |
|
| 244 | 249 | |
| 245 | 250 | } |
| 246 | 251 | |
@@ -261,9 +266,9 @@ discard block |
||
| 261 | 266 | $keys = array_merge(array_keys($this->default_options), array_keys($this->user_options)); |
| 262 | 267 | $vals = array_merge($this->default_options, $this->user_options); |
| 263 | 268 | $this->options = array_combine($keys, $vals); |
| 269 | + } else { |
|
| 270 | + $this->options = $this->default_options; |
|
| 264 | 271 | } |
| 265 | - else |
|
| 266 | - $this->options = $this->default_options; |
|
| 267 | 272 | |
| 268 | 273 | // POST data options, here we don't allow any overide |
| 269 | 274 | if (isset($this->post_data)) |
@@ -302,8 +307,9 @@ discard block |
||
| 302 | 307 | $temp = explode(': ', $_header, 2); |
| 303 | 308 | |
| 304 | 309 | // set proper headers only |
| 305 | - if (isset($temp[0]) && isset($temp[1])) |
|
| 306 | - $this->headers[strtolower($temp[0])] = strtolower(trim($temp[1])); |
|
| 310 | + if (isset($temp[0]) && isset($temp[1])) { |
|
| 311 | + $this->headers[strtolower($temp[0])] = strtolower(trim($temp[1])); |
|
| 312 | + } |
|
| 307 | 313 | |
| 308 | 314 | // return the length of what was passed unless you want a Failed writing header error ;) |
| 309 | 315 | return strlen($header); |
@@ -94,12 +94,12 @@ discard block |
||
| 94 | 94 | public $headers; |
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | - * Start the curl object |
|
| 98 | - * - allow for user override values |
|
| 99 | - * |
|
| 100 | - * @param array $options An array of cURL options |
|
| 101 | - * @param int $max_redirect Maximum number of redirects |
|
| 102 | - */ |
|
| 97 | + * Start the curl object |
|
| 98 | + * - allow for user override values |
|
| 99 | + * |
|
| 100 | + * @param array $options An array of cURL options |
|
| 101 | + * @param int $max_redirect Maximum number of redirects |
|
| 102 | + */ |
|
| 103 | 103 | public function __construct($options = array(), $max_redirect = 3) |
| 104 | 104 | { |
| 105 | 105 | // Initialize class variables |
@@ -108,16 +108,16 @@ discard block |
||
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
| 111 | - * Main calling function, |
|
| 112 | - * - will request the page data from a given $url |
|
| 113 | - * - optionally will post data to the page form if post data is supplied |
|
| 114 | - * - passed arrays will be converted to a post string joined with &'s |
|
| 115 | - * - calls set_options to set the curl opts array values based on the defaults and user input |
|
| 116 | - * |
|
| 117 | - * @param string $url the site we are going to fetch |
|
| 118 | - * @param array $post_data any post data as form name => value |
|
| 119 | - * @return object An instance of the curl_fetch_web_data class |
|
| 120 | - */ |
|
| 111 | + * Main calling function, |
|
| 112 | + * - will request the page data from a given $url |
|
| 113 | + * - optionally will post data to the page form if post data is supplied |
|
| 114 | + * - passed arrays will be converted to a post string joined with &'s |
|
| 115 | + * - calls set_options to set the curl opts array values based on the defaults and user input |
|
| 116 | + * |
|
| 117 | + * @param string $url the site we are going to fetch |
|
| 118 | + * @param array $post_data any post data as form name => value |
|
| 119 | + * @return object An instance of the curl_fetch_web_data class |
|
| 120 | + */ |
|
| 121 | 121 | public function get_url_data($url, $post_data = array()) |
| 122 | 122 | { |
| 123 | 123 | // POSTing some data perhaps? |
@@ -134,14 +134,14 @@ discard block |
||
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
| 137 | - * Makes the actual cURL call |
|
| 138 | - * - stores responses (url, code, error, headers, body) in the response array |
|
| 139 | - * - detects 301, 302, 307 codes and will redirect to the given response header location |
|
| 140 | - * |
|
| 141 | - * @param string $url The site to fetch |
|
| 142 | - * @param bool $redirect Whether or not this was a redirect request |
|
| 143 | - * @return void|bool Sets various properties of the class or returns false if the URL isn't specified |
|
| 144 | - */ |
|
| 137 | + * Makes the actual cURL call |
|
| 138 | + * - stores responses (url, code, error, headers, body) in the response array |
|
| 139 | + * - detects 301, 302, 307 codes and will redirect to the given response header location |
|
| 140 | + * |
|
| 141 | + * @param string $url The site to fetch |
|
| 142 | + * @param bool $redirect Whether or not this was a redirect request |
|
| 143 | + * @return void|bool Sets various properties of the class or returns false if the URL isn't specified |
|
| 144 | + */ |
|
| 145 | 145 | private function curl_request($url, $redirect = false) |
| 146 | 146 | { |
| 147 | 147 | // we do have a url I hope |
@@ -193,12 +193,12 @@ discard block |
||
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
| 196 | - * Used if being redirected to ensure we have a fully qualified address |
|
| 197 | - * |
|
| 198 | - * @param string $last_url The URL we went to |
|
| 199 | - * @param string $new_url The URL we were redirected to |
|
| 200 | - * @return string The new URL that was in the HTTP header |
|
| 201 | - */ |
|
| 196 | + * Used if being redirected to ensure we have a fully qualified address |
|
| 197 | + * |
|
| 198 | + * @param string $last_url The URL we went to |
|
| 199 | + * @param string $new_url The URL we were redirected to |
|
| 200 | + * @return string The new URL that was in the HTTP header |
|
| 201 | + */ |
|
| 202 | 202 | private function get_redirect_url($last_url = '', $new_url = '') |
| 203 | 203 | { |
| 204 | 204 | // Get the elements for these urls |
@@ -216,13 +216,13 @@ discard block |
||
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
| 219 | - * Used to return the results to the calling program |
|
| 220 | - * - called as ->result() will return the full final array |
|
| 221 | - * - called as ->result('body') to just return the page source of the result |
|
| 222 | - * |
|
| 223 | - * @param string $area Used to return an area such as body, header, error |
|
| 224 | - * @return string The response |
|
| 225 | - */ |
|
| 219 | + * Used to return the results to the calling program |
|
| 220 | + * - called as ->result() will return the full final array |
|
| 221 | + * - called as ->result('body') to just return the page source of the result |
|
| 222 | + * |
|
| 223 | + * @param string $area Used to return an area such as body, header, error |
|
| 224 | + * @return string The response |
|
| 225 | + */ |
|
| 226 | 226 | public function result($area = '') |
| 227 | 227 | { |
| 228 | 228 | $max_result = count($this->response) - 1; |
@@ -235,13 +235,13 @@ discard block |
||
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
| 238 | - * Will return all results from all loops (redirects) |
|
| 239 | - * - Can be called as ->result_raw(x) where x is a specific loop results. |
|
| 240 | - * - Call as ->result_raw() for everything. |
|
| 241 | - * |
|
| 242 | - * @param string $response_number Which response we want to get |
|
| 243 | - * @return array|string The entire response array or just the specified response |
|
| 244 | - */ |
|
| 238 | + * Will return all results from all loops (redirects) |
|
| 239 | + * - Can be called as ->result_raw(x) where x is a specific loop results. |
|
| 240 | + * - Call as ->result_raw() for everything. |
|
| 241 | + * |
|
| 242 | + * @param string $response_number Which response we want to get |
|
| 243 | + * @return array|string The entire response array or just the specified response |
|
| 244 | + */ |
|
| 245 | 245 | public function result_raw($response_number = '') |
| 246 | 246 | { |
| 247 | 247 | if (!is_numeric($response_number)) |
@@ -254,13 +254,13 @@ discard block |
||
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
| 257 | - * Takes supplied POST data and url encodes it |
|
| 258 | - * - forms the date (for post) in to a string var=xyz&var2=abc&var3=123 |
|
| 259 | - * - drops vars with @ since we don't support sending files (uploading) |
|
| 260 | - * |
|
| 261 | - * @param array|string $post_data The raw POST data |
|
| 262 | - * @return string A string of post data |
|
| 263 | - */ |
|
| 257 | + * Takes supplied POST data and url encodes it |
|
| 258 | + * - forms the date (for post) in to a string var=xyz&var2=abc&var3=123 |
|
| 259 | + * - drops vars with @ since we don't support sending files (uploading) |
|
| 260 | + * |
|
| 261 | + * @param array|string $post_data The raw POST data |
|
| 262 | + * @return string A string of post data |
|
| 263 | + */ |
|
| 264 | 264 | private function build_post_data($post_data) |
| 265 | 265 | { |
| 266 | 266 | if (is_array($post_data)) |
@@ -279,11 +279,11 @@ discard block |
||
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
| 282 | - * Sets the final cURL options for the current call |
|
| 283 | - * - overwrites our default values with user supplied ones or appends new user ones to what we have |
|
| 284 | - * - sets the callback function now that $this is existing |
|
| 285 | - * @return void |
|
| 286 | - */ |
|
| 282 | + * Sets the final cURL options for the current call |
|
| 283 | + * - overwrites our default values with user supplied ones or appends new user ones to what we have |
|
| 284 | + * - sets the callback function now that $this is existing |
|
| 285 | + * @return void |
|
| 286 | + */ |
|
| 287 | 287 | private function set_options() |
| 288 | 288 | { |
| 289 | 289 | // Callback to parse the returned headers, if any |
@@ -308,12 +308,12 @@ discard block |
||
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | /** |
| 311 | - * Called to initiate a redirect from a 301, 302 or 307 header |
|
| 312 | - * - resets the cURL options for the loop, sets the referrer flag |
|
| 313 | - * |
|
| 314 | - * @param string $target_url The URL we want to redirect to |
|
| 315 | - * @param string $referer_url The URL that we're redirecting from |
|
| 316 | - */ |
|
| 311 | + * Called to initiate a redirect from a 301, 302 or 307 header |
|
| 312 | + * - resets the cURL options for the loop, sets the referrer flag |
|
| 313 | + * |
|
| 314 | + * @param string $target_url The URL we want to redirect to |
|
| 315 | + * @param string $referer_url The URL that we're redirecting from |
|
| 316 | + */ |
|
| 317 | 317 | private function redirect($target_url, $referer_url) |
| 318 | 318 | { |
| 319 | 319 | // no no I last saw that over there ... really, 301, 302, 307 |
@@ -323,13 +323,13 @@ discard block |
||
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | /** |
| 326 | - * Callback function to parse returned headers |
|
| 327 | - * - lowercases everything to make it consistent |
|
| 328 | - * |
|
| 329 | - * @param type $cr Not sure what this is used for? |
|
| 330 | - * @param string $header The header |
|
| 331 | - * @return int The length of the header |
|
| 332 | - */ |
|
| 326 | + * Callback function to parse returned headers |
|
| 327 | + * - lowercases everything to make it consistent |
|
| 328 | + * |
|
| 329 | + * @param type $cr Not sure what this is used for? |
|
| 330 | + * @param string $header The header |
|
| 331 | + * @return int The length of the header |
|
| 332 | + */ |
|
| 333 | 333 | private function header_callback($cr, $header) |
| 334 | 334 | { |
| 335 | 335 | $_header = trim($header); |
@@ -44,6 +44,10 @@ discard block |
||
| 44 | 44 | $this->Buf = range(0, 279); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | + /** |
|
| 48 | + * @param string $data |
|
| 49 | + * @param integer $datLen |
|
| 50 | + */ |
|
| 47 | 51 | public function decompress($data, &$datLen) |
| 48 | 52 | { |
| 49 | 53 | $stLen = strlen($data); |
@@ -63,6 +67,11 @@ discard block |
||
| 63 | 67 | return $ret; |
| 64 | 68 | } |
| 65 | 69 | |
| 70 | + /** |
|
| 71 | + * @param boolean $bInit |
|
| 72 | + * |
|
| 73 | + * @return integer |
|
| 74 | + */ |
|
| 66 | 75 | public function LZWCommand(&$data, $bInit) |
| 67 | 76 | { |
| 68 | 77 | if ($bInit) |
@@ -253,6 +262,10 @@ discard block |
||
| 253 | 262 | unset($this->m_nColors, $this->m_arColors); |
| 254 | 263 | } |
| 255 | 264 | |
| 265 | + /** |
|
| 266 | + * @param string $lpData |
|
| 267 | + * @param integer $num |
|
| 268 | + */ |
|
| 256 | 269 | public function load($lpData, $num) |
| 257 | 270 | { |
| 258 | 271 | $this->m_nColors = 0; |
@@ -324,6 +337,9 @@ discard block |
||
| 324 | 337 | unset($this->m_bSorted, $this->m_nTableSize, $this->m_nBgColor, $this->m_nPixelRatio, $this->m_colorTable); |
| 325 | 338 | } |
| 326 | 339 | |
| 340 | + /** |
|
| 341 | + * @param integer $hdrLen |
|
| 342 | + */ |
|
| 327 | 343 | public function load($lpData, &$hdrLen) |
| 328 | 344 | { |
| 329 | 345 | $hdrLen = 0; |
@@ -370,6 +386,10 @@ discard block |
||
| 370 | 386 | unset($this->m_bInterlace, $this->m_bSorted, $this->m_nTableSize, $this->m_colorTable); |
| 371 | 387 | } |
| 372 | 388 | |
| 389 | + /** |
|
| 390 | + * @param string $lpData |
|
| 391 | + * @param integer $hdrLen |
|
| 392 | + */ |
|
| 373 | 393 | public function load($lpData, &$hdrLen) |
| 374 | 394 | { |
| 375 | 395 | $hdrLen = 0; |
@@ -412,6 +432,10 @@ discard block |
||
| 412 | 432 | $this->m_lzw = new gif_lzw_compression(); |
| 413 | 433 | } |
| 414 | 434 | |
| 435 | + /** |
|
| 436 | + * @param string $data |
|
| 437 | + * @param integer $datLen |
|
| 438 | + */ |
|
| 415 | 439 | public function load($data, &$datLen) |
| 416 | 440 | { |
| 417 | 441 | $datLen = 0; |
@@ -464,6 +488,10 @@ discard block |
||
| 464 | 488 | return false; |
| 465 | 489 | } |
| 466 | 490 | |
| 491 | + /** |
|
| 492 | + * @param string $data |
|
| 493 | + * @param integer $extLen |
|
| 494 | + */ |
|
| 467 | 495 | public function skipExt(&$data, &$extLen) |
| 468 | 496 | { |
| 469 | 497 | $extLen = 0; |
@@ -38,8 +38,8 @@ discard block |
||
| 38 | 38 | $this->MAX_LZW_BITS = 12; |
| 39 | 39 | unset($this->Next, $this->Vals, $this->Stack, $this->Buf); |
| 40 | 40 | |
| 41 | - $this->Next = range(0, (1 << $this->MAX_LZW_BITS) - 1); |
|
| 42 | - $this->Vals = range(0, (1 << $this->MAX_LZW_BITS) - 1); |
|
| 41 | + $this->Next = range(0, (1 << $this->MAX_LZW_BITS) - 1); |
|
| 42 | + $this->Vals = range(0, (1 << $this->MAX_LZW_BITS) - 1); |
|
| 43 | 43 | $this->Stack = range(0, (1 << ($this->MAX_LZW_BITS + 1)) - 1); |
| 44 | 44 | $this->Buf = range(0, 279); |
| 45 | 45 | } |
@@ -278,9 +278,9 @@ discard block |
||
| 278 | 278 | for ($i = 0; $i < $this->m_nColors; $i++) |
| 279 | 279 | { |
| 280 | 280 | $ret .= |
| 281 | - chr(($this->m_arColors[$i] & 0x000000FF)) . // R |
|
| 282 | - chr(($this->m_arColors[$i] & 0x0000FF00) >> 8) . // G |
|
| 283 | - chr(($this->m_arColors[$i] & 0x00FF0000) >> 16); // B |
|
| 281 | + chr(($this->m_arColors[$i] & 0x000000FF)) . // R |
|
| 282 | + chr(($this->m_arColors[$i] & 0x0000FF00) >> 8) . // G |
|
| 283 | + chr(($this->m_arColors[$i] & 0x00FF0000) >> 16); // B |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | return $ret; |
@@ -290,14 +290,14 @@ discard block |
||
| 290 | 290 | { |
| 291 | 291 | $rgb = intval($rgb) & 0xFFFFFF; |
| 292 | 292 | $r1 = ($rgb & 0x0000FF); |
| 293 | - $g1 = ($rgb & 0x00FF00) >> 8; |
|
| 293 | + $g1 = ($rgb & 0x00FF00) >> 8; |
|
| 294 | 294 | $b1 = ($rgb & 0xFF0000) >> 16; |
| 295 | 295 | $idx = -1; |
| 296 | 296 | |
| 297 | 297 | for ($i = 0; $i < $this->m_nColors; $i++) |
| 298 | 298 | { |
| 299 | 299 | $r2 = ($this->m_arColors[$i] & 0x000000FF); |
| 300 | - $g2 = ($this->m_arColors[$i] & 0x0000FF00) >> 8; |
|
| 300 | + $g2 = ($this->m_arColors[$i] & 0x0000FF00) >> 8; |
|
| 301 | 301 | $b2 = ($this->m_arColors[$i] & 0x00FF0000) >> 16; |
| 302 | 302 | $d = abs($r2 - $r1) + abs($g2 - $g1) + abs($b2 - $b1); |
| 303 | 303 | |
@@ -19,8 +19,9 @@ discard block |
||
| 19 | 19 | * @version 2.1 Beta 3 |
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | -if (!defined('SMF')) |
|
| 22 | +if (!defined('SMF')) { |
|
| 23 | 23 | die('No direct access...'); |
| 24 | +} |
|
| 24 | 25 | |
| 25 | 26 | /** |
| 26 | 27 | * Class gif_lzw_compression |
@@ -52,13 +53,15 @@ discard block |
||
| 52 | 53 | |
| 53 | 54 | $this->LZWCommand($data, true); |
| 54 | 55 | |
| 55 | - while (($iIndex = $this->LZWCommand($data, false)) >= 0) |
|
| 56 | - $ret .= chr($iIndex); |
|
| 56 | + while (($iIndex = $this->LZWCommand($data, false)) >= 0) { |
|
| 57 | + $ret .= chr($iIndex); |
|
| 58 | + } |
|
| 57 | 59 | |
| 58 | 60 | $datLen = $stLen - strlen($data); |
| 59 | 61 | |
| 60 | - if ($iIndex != -2) |
|
| 61 | - return false; |
|
| 62 | + if ($iIndex != -2) { |
|
| 63 | + return false; |
|
| 64 | + } |
|
| 62 | 65 | |
| 63 | 66 | return $ret; |
| 64 | 67 | } |
@@ -140,8 +143,9 @@ discard block |
||
| 140 | 143 | return $this->FirstCode; |
| 141 | 144 | } |
| 142 | 145 | |
| 143 | - if ($Code == $this->EndCode) |
|
| 144 | - return -2; |
|
| 146 | + if ($Code == $this->EndCode) { |
|
| 147 | + return -2; |
|
| 148 | + } |
|
| 145 | 149 | |
| 146 | 150 | $InCode = $Code; |
| 147 | 151 | if ($Code >= $this->MaxCode) |
@@ -156,8 +160,10 @@ discard block |
||
| 156 | 160 | $this->Stack[$this->sp] = $this->Vals[$Code]; |
| 157 | 161 | $this->sp++; |
| 158 | 162 | |
| 159 | - if ($Code == $this->Next[$Code]) // Circular table entry, big GIF Error! |
|
| 163 | + if ($Code == $this->Next[$Code]) { |
|
| 164 | + // Circular table entry, big GIF Error! |
|
| 160 | 165 | return -1; |
| 166 | + } |
|
| 161 | 167 | |
| 162 | 168 | $Code = $this->Next[$Code]; |
| 163 | 169 | } |
@@ -207,8 +213,9 @@ discard block |
||
| 207 | 213 | if ($this->Done) |
| 208 | 214 | { |
| 209 | 215 | // Ran off the end of my bits... |
| 210 | - if ($this->CurBit >= $this->LastBit) |
|
| 211 | - return 0; |
|
| 216 | + if ($this->CurBit >= $this->LastBit) { |
|
| 217 | + return 0; |
|
| 218 | + } |
|
| 212 | 219 | |
| 213 | 220 | return -1; |
| 214 | 221 | } |
@@ -221,13 +228,14 @@ discard block |
||
| 221 | 228 | |
| 222 | 229 | if ($count) |
| 223 | 230 | { |
| 224 | - for ($i = 0; $i < $count; $i++) |
|
| 225 | - $this->Buf[2 + $i] = ord($data{$i}); |
|
| 231 | + for ($i = 0; $i < $count; $i++) { |
|
| 232 | + $this->Buf[2 + $i] = ord($data{$i}); |
|
| 233 | + } |
|
| 226 | 234 | |
| 227 | 235 | $data = substr($data, $count); |
| 236 | + } else { |
|
| 237 | + $this->Done = 1; |
|
| 228 | 238 | } |
| 229 | - else |
|
| 230 | - $this->Done = 1; |
|
| 231 | 239 | |
| 232 | 240 | $this->LastByte = 2 + $count; |
| 233 | 241 | $this->CurBit = ($this->CurBit - $this->LastBit) + 16; |
@@ -235,8 +243,9 @@ discard block |
||
| 235 | 243 | } |
| 236 | 244 | |
| 237 | 245 | $iRet = 0; |
| 238 | - for ($i = $this->CurBit, $j = 0; $j < $this->CodeSize; $i++, $j++) |
|
| 239 | - $iRet |= (($this->Buf[intval($i / 8)] & (1 << ($i % 8))) != 0) << $j; |
|
| 246 | + for ($i = $this->CurBit, $j = 0; $j < $this->CodeSize; $i++, $j++) { |
|
| 247 | + $iRet |= (($this->Buf[intval($i / 8)] & (1 << ($i % 8))) != 0) << $j; |
|
| 248 | + } |
|
| 240 | 249 | |
| 241 | 250 | $this->CurBit += $this->CodeSize; |
| 242 | 251 | return $iRet; |
@@ -261,8 +270,9 @@ discard block |
||
| 261 | 270 | for ($i = 0; $i < $num; $i++) |
| 262 | 271 | { |
| 263 | 272 | $rgb = substr($lpData, $i * 3, 3); |
| 264 | - if (strlen($rgb) < 3) |
|
| 265 | - return false; |
|
| 273 | + if (strlen($rgb) < 3) { |
|
| 274 | + return false; |
|
| 275 | + } |
|
| 266 | 276 | |
| 267 | 277 | $this->m_arColors[] = (ord($rgb[2]) << 16) + (ord($rgb[1]) << 8) + ord($rgb[0]); |
| 268 | 278 | $this->m_nColors++; |
@@ -329,13 +339,15 @@ discard block |
||
| 329 | 339 | $hdrLen = 0; |
| 330 | 340 | |
| 331 | 341 | $this->m_lpVer = substr($lpData, 0, 6); |
| 332 | - if (($this->m_lpVer != 'GIF87a') && ($this->m_lpVer != 'GIF89a')) |
|
| 333 | - return false; |
|
| 342 | + if (($this->m_lpVer != 'GIF87a') && ($this->m_lpVer != 'GIF89a')) { |
|
| 343 | + return false; |
|
| 344 | + } |
|
| 334 | 345 | |
| 335 | 346 | list ($this->m_nWidth, $this->m_nHeight) = array_values(unpack('v2', substr($lpData, 6, 4))); |
| 336 | 347 | |
| 337 | - if (!$this->m_nWidth || !$this->m_nHeight) |
|
| 338 | - return false; |
|
| 348 | + if (!$this->m_nWidth || !$this->m_nHeight) { |
|
| 349 | + return false; |
|
| 350 | + } |
|
| 339 | 351 | |
| 340 | 352 | $b = ord(substr($lpData, 10, 1)); |
| 341 | 353 | $this->m_bGlobalClr = ($b & 0x80) ? true : false; |
@@ -349,8 +361,9 @@ discard block |
||
| 349 | 361 | if ($this->m_bGlobalClr) |
| 350 | 362 | { |
| 351 | 363 | $this->m_colorTable = new gif_color_table(); |
| 352 | - if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) |
|
| 353 | - return false; |
|
| 364 | + if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) { |
|
| 365 | + return false; |
|
| 366 | + } |
|
| 354 | 367 | |
| 355 | 368 | $hdrLen += 3 * $this->m_nTableSize; |
| 356 | 369 | } |
@@ -377,8 +390,9 @@ discard block |
||
| 377 | 390 | // Get the width/height/etc. from the header. |
| 378 | 391 | list ($this->m_nLeft, $this->m_nTop, $this->m_nWidth, $this->m_nHeight) = array_values(unpack('v4', substr($lpData, 0, 8))); |
| 379 | 392 | |
| 380 | - if (!$this->m_nWidth || !$this->m_nHeight) |
|
| 381 | - return false; |
|
| 393 | + if (!$this->m_nWidth || !$this->m_nHeight) { |
|
| 394 | + return false; |
|
| 395 | + } |
|
| 382 | 396 | |
| 383 | 397 | $b = ord($lpData[8]); |
| 384 | 398 | $this->m_bLocalClr = ($b & 0x80) ? true : false; |
@@ -390,8 +404,9 @@ discard block |
||
| 390 | 404 | if ($this->m_bLocalClr) |
| 391 | 405 | { |
| 392 | 406 | $this->m_colorTable = new gif_color_table(); |
| 393 | - if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) |
|
| 394 | - return false; |
|
| 407 | + if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) { |
|
| 408 | + return false; |
|
| 409 | + } |
|
| 395 | 410 | |
| 396 | 411 | $hdrLen += 3 * $this->m_nTableSize; |
| 397 | 412 | } |
@@ -427,8 +442,9 @@ discard block |
||
| 427 | 442 | // Extension... |
| 428 | 443 | case 0x21: |
| 429 | 444 | $len = 0; |
| 430 | - if (!$this->skipExt($data, $len)) |
|
| 431 | - return false; |
|
| 445 | + if (!$this->skipExt($data, $len)) { |
|
| 446 | + return false; |
|
| 447 | + } |
|
| 432 | 448 | |
| 433 | 449 | $datLen += $len; |
| 434 | 450 | break; |
@@ -437,21 +453,24 @@ discard block |
||
| 437 | 453 | case 0x2C: |
| 438 | 454 | // Load the header and color table. |
| 439 | 455 | $len = 0; |
| 440 | - if (!$this->m_gih->load($data, $len)) |
|
| 441 | - return false; |
|
| 456 | + if (!$this->m_gih->load($data, $len)) { |
|
| 457 | + return false; |
|
| 458 | + } |
|
| 442 | 459 | |
| 443 | 460 | $data = substr($data, $len); |
| 444 | 461 | $datLen += $len; |
| 445 | 462 | |
| 446 | 463 | // Decompress the data, and ride on home ;). |
| 447 | 464 | $len = 0; |
| 448 | - if (!($this->m_data = $this->m_lzw->decompress($data, $len))) |
|
| 449 | - return false; |
|
| 465 | + if (!($this->m_data = $this->m_lzw->decompress($data, $len))) { |
|
| 466 | + return false; |
|
| 467 | + } |
|
| 450 | 468 | |
| 451 | 469 | $datLen += $len; |
| 452 | 470 | |
| 453 | - if ($this->m_gih->m_bInterlace) |
|
| 454 | - $this->deInterlace(); |
|
| 471 | + if ($this->m_gih->m_bInterlace) { |
|
| 472 | + $this->deInterlace(); |
|
| 473 | + } |
|
| 455 | 474 | |
| 456 | 475 | return true; |
| 457 | 476 | |
@@ -571,17 +590,20 @@ discard block |
||
| 571 | 590 | |
| 572 | 591 | public function loadFile($filename, $iIndex) |
| 573 | 592 | { |
| 574 | - if ($iIndex < 0) |
|
| 575 | - return false; |
|
| 593 | + if ($iIndex < 0) { |
|
| 594 | + return false; |
|
| 595 | + } |
|
| 576 | 596 | |
| 577 | 597 | $this->data = @file_get_contents($filename); |
| 578 | - if ($this->data === false) |
|
| 579 | - return false; |
|
| 598 | + if ($this->data === false) { |
|
| 599 | + return false; |
|
| 600 | + } |
|
| 580 | 601 | |
| 581 | 602 | // Tell the header to load up.... |
| 582 | 603 | $len = 0; |
| 583 | - if (!$this->header->load($this->data, $len)) |
|
| 584 | - return false; |
|
| 604 | + if (!$this->header->load($this->data, $len)) { |
|
| 605 | + return false; |
|
| 606 | + } |
|
| 585 | 607 | |
| 586 | 608 | $this->data = substr($this->data, $len); |
| 587 | 609 | |
@@ -589,8 +611,9 @@ discard block |
||
| 589 | 611 | for ($j = 0; $j <= $iIndex; $j++) |
| 590 | 612 | { |
| 591 | 613 | $imgLen = 0; |
| 592 | - if (!$this->image->load($this->data, $imgLen)) |
|
| 593 | - return false; |
|
| 614 | + if (!$this->image->load($this->data, $imgLen)) { |
|
| 615 | + return false; |
|
| 616 | + } |
|
| 594 | 617 | |
| 595 | 618 | $this->data = substr($this->data, $imgLen); |
| 596 | 619 | } |
@@ -601,8 +624,9 @@ discard block |
||
| 601 | 624 | |
| 602 | 625 | public function get_png_data($background_color) |
| 603 | 626 | { |
| 604 | - if (!$this->loaded) |
|
| 605 | - return false; |
|
| 627 | + if (!$this->loaded) { |
|
| 628 | + return false; |
|
| 629 | + } |
|
| 606 | 630 | |
| 607 | 631 | // Prepare the color table. |
| 608 | 632 | if ($this->image->m_gih->m_bLocalClr) |
@@ -610,25 +634,26 @@ discard block |
||
| 610 | 634 | $colors = $this->image->m_gih->m_nTableSize; |
| 611 | 635 | $pal = $this->image->m_gih->m_colorTable->toString(); |
| 612 | 636 | |
| 613 | - if ($background_color != -1) |
|
| 614 | - $background_color = $this->image->m_gih->m_colorTable->colorIndex($background_color); |
|
| 615 | - } |
|
| 616 | - elseif ($this->header->m_bGlobalClr) |
|
| 637 | + if ($background_color != -1) { |
|
| 638 | + $background_color = $this->image->m_gih->m_colorTable->colorIndex($background_color); |
|
| 639 | + } |
|
| 640 | + } elseif ($this->header->m_bGlobalClr) |
|
| 617 | 641 | { |
| 618 | 642 | $colors = $this->header->m_nTableSize; |
| 619 | 643 | $pal = $this->header->m_colorTable->toString(); |
| 620 | 644 | |
| 621 | - if ($background_color != -1) |
|
| 622 | - $background_color = $this->header->m_colorTable->colorIndex($background_color); |
|
| 623 | - } |
|
| 624 | - else |
|
| 645 | + if ($background_color != -1) { |
|
| 646 | + $background_color = $this->header->m_colorTable->colorIndex($background_color); |
|
| 647 | + } |
|
| 648 | + } else |
|
| 625 | 649 | { |
| 626 | 650 | $colors = 0; |
| 627 | 651 | $background_color = -1; |
| 628 | 652 | } |
| 629 | 653 | |
| 630 | - if ($background_color == -1) |
|
| 631 | - $background_color = $this->header->m_nBgColor; |
|
| 654 | + if ($background_color == -1) { |
|
| 655 | + $background_color = $this->header->m_nBgColor; |
|
| 656 | + } |
|
| 632 | 657 | |
| 633 | 658 | $data = &$this->image->m_data; |
| 634 | 659 | $header = &$this->image->m_gih; |
@@ -644,11 +669,13 @@ discard block |
||
| 644 | 669 | for ($x = 0; $x < $this->header->m_nWidth; $x++, $i++) |
| 645 | 670 | { |
| 646 | 671 | // Is this in the proper range? If so, get the specific pixel data... |
| 647 | - if ($x >= $header->m_nLeft && $y >= $header->m_nTop && $x < ($header->m_nLeft + $header->m_nWidth) && $y < ($header->m_nTop + $header->m_nHeight)) |
|
| 648 | - $bmp .= $data{$i}; |
|
| 672 | + if ($x >= $header->m_nLeft && $y >= $header->m_nTop && $x < ($header->m_nLeft + $header->m_nWidth) && $y < ($header->m_nTop + $header->m_nHeight)) { |
|
| 673 | + $bmp .= $data{$i}; |
|
| 674 | + } |
|
| 649 | 675 | // Otherwise, this is background... |
| 650 | - else |
|
| 651 | - $bmp .= chr($background_color); |
|
| 676 | + else { |
|
| 677 | + $bmp .= chr($background_color); |
|
| 678 | + } |
|
| 652 | 679 | } |
| 653 | 680 | } |
| 654 | 681 | |
@@ -677,8 +704,9 @@ discard block |
||
| 677 | 704 | $tmp = 'tRNS'; |
| 678 | 705 | |
| 679 | 706 | // Stick each color on - full transparency or none. |
| 680 | - for ($i = 0; $i < $colors; $i++) |
|
| 681 | - $tmp .= $i == $this->image->m_nTrans ? "\x00" : "\xFF"; |
|
| 707 | + for ($i = 0; $i < $colors; $i++) { |
|
| 708 | + $tmp .= $i == $this->image->m_nTrans ? "\x00" : "\xFF"; |
|
| 709 | + } |
|
| 682 | 710 | |
| 683 | 711 | $out .= $tmp . pack('N', smf_crc32($tmp)); |
| 684 | 712 | } |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * of elements, an array of xmlArray's is returned for use with foreach. |
| 258 | 258 | * Example use: |
| 259 | 259 | * foreach ($xml->set('html/body/p') as $p) |
| 260 | - * @param $path string The path to search for. |
|
| 260 | + * @param string $path string The path to search for. |
|
| 261 | 261 | * @return array An array of xmlArray objects |
| 262 | 262 | */ |
| 263 | 263 | public function set($path) |
@@ -855,7 +855,7 @@ discard block |
||
| 855 | 855 | * Changes a files atrributes (chmod) |
| 856 | 856 | * |
| 857 | 857 | * @param string $ftp_file The file to CHMOD |
| 858 | - * @param int|string $chmod The value for the CHMOD operation |
|
| 858 | + * @param integer $chmod The value for the CHMOD operation |
|
| 859 | 859 | * @return boolean Whether or not the operation was successful |
| 860 | 860 | */ |
| 861 | 861 | public function chmod($ftp_file, $chmod) |
@@ -1025,7 +1025,7 @@ discard block |
||
| 1025 | 1025 | * |
| 1026 | 1026 | * @param string $ftp_path The path to the directory |
| 1027 | 1027 | * @param bool $search Whether or not to get a recursive directory listing |
| 1028 | - * @return string|boolean The results of the command or false if unsuccessful |
|
| 1028 | + * @return false|string The results of the command or false if unsuccessful |
|
| 1029 | 1029 | */ |
| 1030 | 1030 | public function list_dir($ftp_path = '', $search = false) |
| 1031 | 1031 | { |
@@ -1070,7 +1070,7 @@ discard block |
||
| 1070 | 1070 | * |
| 1071 | 1071 | * @param string $file The name of a file |
| 1072 | 1072 | * @param string $listing A directory listing or null to generate one |
| 1073 | - * @return string|boolean The name of the file or false if it wasn't found |
|
| 1073 | + * @return string|false The name of the file or false if it wasn't found |
|
| 1074 | 1074 | */ |
| 1075 | 1075 | public function locate($file, $listing = null) |
| 1076 | 1076 | { |
@@ -793,7 +793,7 @@ discard block |
||
| 793 | 793 | if (!$this->connection) |
| 794 | 794 | { |
| 795 | 795 | $this->error = 'bad_server'; |
| 796 | - $this->last_message = 'Invalid Server'; |
|
| 796 | + $this->last_message = 'Invalid Server'; |
|
| 797 | 797 | return; |
| 798 | 798 | } |
| 799 | 799 | |
@@ -801,7 +801,7 @@ discard block |
||
| 801 | 801 | if (!$this->check_response(220)) |
| 802 | 802 | { |
| 803 | 803 | $this->error = 'bad_response'; |
| 804 | - $this->last_message = 'Bad Response'; |
|
| 804 | + $this->last_message = 'Bad Response'; |
|
| 805 | 805 | return; |
| 806 | 806 | } |
| 807 | 807 | |
@@ -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 | * Class xmlArray |
@@ -65,8 +66,9 @@ discard block |
||
| 65 | 66 | } |
| 66 | 67 | |
| 67 | 68 | // Is the input an array? (ie. passed from file()?) |
| 68 | - if (is_array($data)) |
|
| 69 | - $data = implode('', $data); |
|
| 69 | + if (is_array($data)) { |
|
| 70 | + $data = implode('', $data); |
|
| 71 | + } |
|
| 70 | 72 | |
| 71 | 73 | // Remove any xml declaration or doctype, and parse out comments and CDATA. |
| 72 | 74 | $data = preg_replace('/<!--.*?-->/s', '', $this->_to_cdata(preg_replace(array('/^<\?xml.+?\?' . '>/is', '/<!DOCTYPE[^>]+?' . '>/s'), '', $data))); |
@@ -101,8 +103,9 @@ discard block |
||
| 101 | 103 | // Get the element, in array form. |
| 102 | 104 | $array = $this->path($path); |
| 103 | 105 | |
| 104 | - if ($array === false) |
|
| 105 | - return false; |
|
| 106 | + if ($array === false) { |
|
| 107 | + return false; |
|
| 108 | + } |
|
| 106 | 109 | |
| 107 | 110 | // Getting elements into this is a bit complicated... |
| 108 | 111 | if ($get_elements && !is_string($array)) |
@@ -113,8 +116,9 @@ discard block |
||
| 113 | 116 | foreach ($array->array as $val) |
| 114 | 117 | { |
| 115 | 118 | // Skip the name and any attributes. |
| 116 | - if (is_array($val)) |
|
| 117 | - $temp .= $this->_xml($val, null); |
|
| 119 | + if (is_array($val)) { |
|
| 120 | + $temp .= $this->_xml($val, null); |
|
| 121 | + } |
|
| 118 | 122 | } |
| 119 | 123 | |
| 120 | 124 | // Just get the XML data and then take out the CDATAs. |
@@ -156,32 +160,35 @@ discard block |
||
| 156 | 160 | elseif (substr($el, 0, 1) == '@') |
| 157 | 161 | { |
| 158 | 162 | // It simplifies things if the attribute is already there ;). |
| 159 | - if (isset($array[$el])) |
|
| 160 | - return $array[$el]; |
|
| 161 | - else |
|
| 163 | + if (isset($array[$el])) { |
|
| 164 | + return $array[$el]; |
|
| 165 | + } else |
|
| 162 | 166 | { |
| 163 | 167 | $trace = debug_backtrace(); |
| 164 | 168 | $i = 0; |
| 165 | - while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) |
|
| 166 | - $i++; |
|
| 169 | + while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) { |
|
| 170 | + $i++; |
|
| 171 | + } |
|
| 167 | 172 | $debug = ' (from ' . $trace[$i - 1]['file'] . ' on line ' . $trace[$i - 1]['line'] . ')'; |
| 168 | 173 | |
| 169 | 174 | // Cause an error. |
| 170 | - if ($this->debug_level & E_NOTICE) |
|
| 171 | - trigger_error('Undefined XML attribute: ' . substr($el, 1) . $debug, E_USER_NOTICE); |
|
| 175 | + if ($this->debug_level & E_NOTICE) { |
|
| 176 | + trigger_error('Undefined XML attribute: ' . substr($el, 1) . $debug, E_USER_NOTICE); |
|
| 177 | + } |
|
| 172 | 178 | return false; |
| 173 | 179 | } |
| 180 | + } else { |
|
| 181 | + $lvl = null; |
|
| 174 | 182 | } |
| 175 | - else |
|
| 176 | - $lvl = null; |
|
| 177 | 183 | |
| 178 | 184 | // Find this element. |
| 179 | 185 | $array = $this->_path($array, $el, $lvl); |
| 180 | 186 | } |
| 181 | 187 | |
| 182 | 188 | // Clean up after $lvl, for $return_full. |
| 183 | - if ($return_full && (!isset($array['name']) || substr($array['name'], -1) != ']')) |
|
| 184 | - $array = array('name' => $el . '[]', $array); |
|
| 189 | + if ($return_full && (!isset($array['name']) || substr($array['name'], -1) != ']')) { |
|
| 190 | + $array = array('name' => $el . '[]', $array); |
|
| 191 | + } |
|
| 185 | 192 | |
| 186 | 193 | // Create the right type of class... |
| 187 | 194 | $newClass = get_class($this); |
@@ -216,10 +223,11 @@ discard block |
||
| 216 | 223 | $el = substr($el, 0, strpos($el, '[')); |
| 217 | 224 | } |
| 218 | 225 | // Find an attribute. |
| 219 | - elseif (substr($el, 0, 1) == '@') |
|
| 220 | - return isset($array[$el]); |
|
| 221 | - else |
|
| 222 | - $lvl = null; |
|
| 226 | + elseif (substr($el, 0, 1) == '@') { |
|
| 227 | + return isset($array[$el]); |
|
| 228 | + } else { |
|
| 229 | + $lvl = null; |
|
| 230 | + } |
|
| 223 | 231 | |
| 224 | 232 | // Find this element. |
| 225 | 233 | $array = $this->_path($array, $el, $lvl, true); |
@@ -244,8 +252,9 @@ discard block |
||
| 244 | 252 | $i = 0; |
| 245 | 253 | foreach ($temp->array as $item) |
| 246 | 254 | { |
| 247 | - if (is_array($item)) |
|
| 248 | - $i++; |
|
| 255 | + if (is_array($item)) { |
|
| 256 | + $i++; |
|
| 257 | + } |
|
| 249 | 258 | } |
| 250 | 259 | |
| 251 | 260 | return $i; |
@@ -269,8 +278,9 @@ discard block |
||
| 269 | 278 | foreach ($xml->array as $val) |
| 270 | 279 | { |
| 271 | 280 | // Skip these, they aren't elements. |
| 272 | - if (!is_array($val) || $val['name'] == '!') |
|
| 273 | - continue; |
|
| 281 | + if (!is_array($val) || $val['name'] == '!') { |
|
| 282 | + continue; |
|
| 283 | + } |
|
| 274 | 284 | |
| 275 | 285 | // Create the right type of class... |
| 276 | 286 | $newClass = get_class($this); |
@@ -297,14 +307,16 @@ discard block |
||
| 297 | 307 | $path = $this->path($path); |
| 298 | 308 | |
| 299 | 309 | // The path was not found |
| 300 | - if ($path === false) |
|
| 301 | - return false; |
|
| 310 | + if ($path === false) { |
|
| 311 | + return false; |
|
| 312 | + } |
|
| 302 | 313 | |
| 303 | 314 | $path = $path->array; |
| 304 | 315 | } |
| 305 | 316 | // Just use the current array. |
| 306 | - else |
|
| 307 | - $path = $this->array; |
|
| 317 | + else { |
|
| 318 | + $path = $this->array; |
|
| 319 | + } |
|
| 308 | 320 | |
| 309 | 321 | // Add the xml declaration to the front. |
| 310 | 322 | return '<?xml version="1.0"?' . '>' . $this->_xml($path, 0); |
@@ -326,14 +338,16 @@ discard block |
||
| 326 | 338 | $path = $this->path($path); |
| 327 | 339 | |
| 328 | 340 | // The path was not found |
| 329 | - if ($path === false) |
|
| 330 | - return false; |
|
| 341 | + if ($path === false) { |
|
| 342 | + return false; |
|
| 343 | + } |
|
| 331 | 344 | |
| 332 | 345 | $path = $path->array; |
| 333 | 346 | } |
| 334 | 347 | // No, so just use the current array. |
| 335 | - else |
|
| 336 | - $path = $this->array; |
|
| 348 | + else { |
|
| 349 | + $path = $this->array; |
|
| 350 | + } |
|
| 337 | 351 | |
| 338 | 352 | return $this->_array($path); |
| 339 | 353 | } |
@@ -355,8 +369,9 @@ discard block |
||
| 355 | 369 | { |
| 356 | 370 | // Find and remove the next tag. |
| 357 | 371 | preg_match('/\A<([\w\-:]+)((?:\s+.+?)?)([\s]?\/)?' . '>/', $data, $match); |
| 358 | - if (isset($match[0])) |
|
| 359 | - $data = preg_replace('/' . preg_quote($match[0], '/') . '/s', '', $data, 1); |
|
| 372 | + if (isset($match[0])) { |
|
| 373 | + $data = preg_replace('/' . preg_quote($match[0], '/') . '/s', '', $data, 1); |
|
| 374 | + } |
|
| 360 | 375 | |
| 361 | 376 | // Didn't find a tag? Keep looping.... |
| 362 | 377 | if (!isset($match[1]) || $match[1] == '') |
@@ -367,11 +382,12 @@ discard block |
||
| 367 | 382 | $text_value = $this->_from_cdata($data); |
| 368 | 383 | $data = ''; |
| 369 | 384 | |
| 370 | - if ($text_value != '') |
|
| 371 | - $current[] = array( |
|
| 385 | + if ($text_value != '') { |
|
| 386 | + $current[] = array( |
|
| 372 | 387 | 'name' => '!', |
| 373 | 388 | 'value' => $text_value |
| 374 | 389 | ); |
| 390 | + } |
|
| 375 | 391 | } |
| 376 | 392 | // If the < isn't immediately next to the current position... more data. |
| 377 | 393 | elseif (strpos($data, '<') > 0) |
@@ -379,11 +395,12 @@ discard block |
||
| 379 | 395 | $text_value = $this->_from_cdata(substr($data, 0, strpos($data, '<'))); |
| 380 | 396 | $data = substr($data, strpos($data, '<')); |
| 381 | 397 | |
| 382 | - if ($text_value != '') |
|
| 383 | - $current[] = array( |
|
| 398 | + if ($text_value != '') { |
|
| 399 | + $current[] = array( |
|
| 384 | 400 | 'name' => '!', |
| 385 | 401 | 'value' => $text_value |
| 386 | 402 | ); |
| 403 | + } |
|
| 387 | 404 | } |
| 388 | 405 | // If we're looking at a </something> with no start, kill it. |
| 389 | 406 | elseif (strpos($data, '<') !== false && strpos($data, '<') == 0) |
@@ -393,22 +410,23 @@ discard block |
||
| 393 | 410 | $text_value = $this->_from_cdata(substr($data, 0, strpos($data, '<', 1))); |
| 394 | 411 | $data = substr($data, strpos($data, '<', 1)); |
| 395 | 412 | |
| 396 | - if ($text_value != '') |
|
| 397 | - $current[] = array( |
|
| 413 | + if ($text_value != '') { |
|
| 414 | + $current[] = array( |
|
| 398 | 415 | 'name' => '!', |
| 399 | 416 | 'value' => $text_value |
| 400 | 417 | ); |
| 401 | - } |
|
| 402 | - else |
|
| 418 | + } |
|
| 419 | + } else |
|
| 403 | 420 | { |
| 404 | 421 | $text_value = $this->_from_cdata($data); |
| 405 | 422 | $data = ''; |
| 406 | 423 | |
| 407 | - if ($text_value != '') |
|
| 408 | - $current[] = array( |
|
| 424 | + if ($text_value != '') { |
|
| 425 | + $current[] = array( |
|
| 409 | 426 | 'name' => '!', |
| 410 | 427 | 'value' => $text_value |
| 411 | 428 | ); |
| 429 | + } |
|
| 412 | 430 | } |
| 413 | 431 | } |
| 414 | 432 | |
@@ -425,8 +443,9 @@ discard block |
||
| 425 | 443 | { |
| 426 | 444 | // Because PHP 5.2.0+ seems to croak using regex, we'll have to do this the less fun way. |
| 427 | 445 | $last_tag_end = strpos($data, '</' . $match[1]. '>'); |
| 428 | - if ($last_tag_end === false) |
|
| 429 | - continue; |
|
| 446 | + if ($last_tag_end === false) { |
|
| 447 | + continue; |
|
| 448 | + } |
|
| 430 | 449 | |
| 431 | 450 | $offset = 0; |
| 432 | 451 | while (1 == 1) |
@@ -434,16 +453,17 @@ discard block |
||
| 434 | 453 | // Where is the next start tag? |
| 435 | 454 | $next_tag_start = strpos($data, '<' . $match[1], $offset); |
| 436 | 455 | // If the next start tag is after the last end tag then we've found the right close. |
| 437 | - if ($next_tag_start === false || $next_tag_start > $last_tag_end) |
|
| 438 | - break; |
|
| 456 | + if ($next_tag_start === false || $next_tag_start > $last_tag_end) { |
|
| 457 | + break; |
|
| 458 | + } |
|
| 439 | 459 | |
| 440 | 460 | // If not then find the next ending tag. |
| 441 | 461 | $next_tag_end = strpos($data, '</' . $match[1]. '>', $offset); |
| 442 | 462 | |
| 443 | 463 | // Didn't find one? Then just use the last and sod it. |
| 444 | - if ($next_tag_end === false) |
|
| 445 | - break; |
|
| 446 | - else |
|
| 464 | + if ($next_tag_end === false) { |
|
| 465 | + break; |
|
| 466 | + } else |
|
| 447 | 467 | { |
| 448 | 468 | $last_tag_end = $next_tag_end; |
| 449 | 469 | $offset = $next_tag_start + 1; |
@@ -457,16 +477,17 @@ discard block |
||
| 457 | 477 | if (!empty($inner_match)) |
| 458 | 478 | { |
| 459 | 479 | // Parse the inner data. |
| 460 | - if (strpos($inner_match, '<') !== false) |
|
| 461 | - $el += $this->_parse($inner_match); |
|
| 462 | - elseif (trim($inner_match) != '') |
|
| 480 | + if (strpos($inner_match, '<') !== false) { |
|
| 481 | + $el += $this->_parse($inner_match); |
|
| 482 | + } elseif (trim($inner_match) != '') |
|
| 463 | 483 | { |
| 464 | 484 | $text_value = $this->_from_cdata($inner_match); |
| 465 | - if ($text_value != '') |
|
| 466 | - $el[] = array( |
|
| 485 | + if ($text_value != '') { |
|
| 486 | + $el[] = array( |
|
| 467 | 487 | 'name' => '!', |
| 468 | 488 | 'value' => $text_value |
| 469 | 489 | ); |
| 490 | + } |
|
| 470 | 491 | } |
| 471 | 492 | } |
| 472 | 493 | } |
@@ -478,8 +499,9 @@ discard block |
||
| 478 | 499 | preg_match_all('/([\w:]+)="(.+?)"/', $match[2], $attr, PREG_SET_ORDER); |
| 479 | 500 | |
| 480 | 501 | // Set them as @attribute-name. |
| 481 | - foreach ($attr as $match_attr) |
|
| 482 | - $el['@' . $match_attr[1]] = $match_attr[2]; |
|
| 502 | + foreach ($attr as $match_attr) { |
|
| 503 | + $el['@' . $match_attr[1]] = $match_attr[2]; |
|
| 504 | + } |
|
| 483 | 505 | } |
| 484 | 506 | } |
| 485 | 507 | |
@@ -503,16 +525,18 @@ discard block |
||
| 503 | 525 | if (is_array($array) && !isset($array['name'])) |
| 504 | 526 | { |
| 505 | 527 | $temp = ''; |
| 506 | - foreach ($array as $val) |
|
| 507 | - $temp .= $this->_xml($val, $indent); |
|
| 528 | + foreach ($array as $val) { |
|
| 529 | + $temp .= $this->_xml($val, $indent); |
|
| 530 | + } |
|
| 508 | 531 | return $temp; |
| 509 | 532 | } |
| 510 | 533 | |
| 511 | 534 | // This is just text! |
| 512 | - if ($array['name'] == '!') |
|
| 513 | - return $indentation . '<![CDATA[' . $array['value'] . ']]>'; |
|
| 514 | - elseif (substr($array['name'], -2) == '[]') |
|
| 515 | - $array['name'] = substr($array['name'], 0, -2); |
|
| 535 | + if ($array['name'] == '!') { |
|
| 536 | + return $indentation . '<![CDATA[' . $array['value'] . ']]>'; |
|
| 537 | + } elseif (substr($array['name'], -2) == '[]') { |
|
| 538 | + $array['name'] = substr($array['name'], 0, -2); |
|
| 539 | + } |
|
| 516 | 540 | |
| 517 | 541 | // Start the element. |
| 518 | 542 | $output = $indentation . '<' . $array['name']; |
@@ -523,9 +547,9 @@ discard block |
||
| 523 | 547 | // Run through and recursively output all the elements or attrbutes inside this. |
| 524 | 548 | foreach ($array as $k => $v) |
| 525 | 549 | { |
| 526 | - if (substr($k, 0, 1) == '@') |
|
| 527 | - $output .= ' ' . substr($k, 1) . '="' . $v . '"'; |
|
| 528 | - elseif (is_array($v)) |
|
| 550 | + if (substr($k, 0, 1) == '@') { |
|
| 551 | + $output .= ' ' . substr($k, 1) . '="' . $v . '"'; |
|
| 552 | + } elseif (is_array($v)) |
|
| 529 | 553 | { |
| 530 | 554 | $output_el .= $this->_xml($v, $indent === null ? null : $indent + 1); |
| 531 | 555 | $inside_elements = true; |
@@ -533,10 +557,11 @@ discard block |
||
| 533 | 557 | } |
| 534 | 558 | |
| 535 | 559 | // Indent, if necessary.... then close the tag. |
| 536 | - if ($inside_elements) |
|
| 537 | - $output .= '>' . $output_el . $indentation . '</' . $array['name'] . '>'; |
|
| 538 | - else |
|
| 539 | - $output .= ' />'; |
|
| 560 | + if ($inside_elements) { |
|
| 561 | + $output .= '>' . $output_el . $indentation . '</' . $array['name'] . '>'; |
|
| 562 | + } else { |
|
| 563 | + $output .= ' />'; |
|
| 564 | + } |
|
| 540 | 565 | |
| 541 | 566 | return $output; |
| 542 | 567 | } |
@@ -553,19 +578,22 @@ discard block |
||
| 553 | 578 | $text = ''; |
| 554 | 579 | foreach ($array as $value) |
| 555 | 580 | { |
| 556 | - if (!is_array($value) || !isset($value['name'])) |
|
| 557 | - continue; |
|
| 581 | + if (!is_array($value) || !isset($value['name'])) { |
|
| 582 | + continue; |
|
| 583 | + } |
|
| 558 | 584 | |
| 559 | - if ($value['name'] == '!') |
|
| 560 | - $text .= $value['value']; |
|
| 561 | - else |
|
| 562 | - $return[$value['name']] = $this->_array($value); |
|
| 585 | + if ($value['name'] == '!') { |
|
| 586 | + $text .= $value['value']; |
|
| 587 | + } else { |
|
| 588 | + $return[$value['name']] = $this->_array($value); |
|
| 589 | + } |
|
| 563 | 590 | } |
| 564 | 591 | |
| 565 | - if (empty($return)) |
|
| 566 | - return $text; |
|
| 567 | - else |
|
| 568 | - return $return; |
|
| 592 | + if (empty($return)) { |
|
| 593 | + return $text; |
|
| 594 | + } else { |
|
| 595 | + return $return; |
|
| 596 | + } |
|
| 569 | 597 | } |
| 570 | 598 | |
| 571 | 599 | /** |
@@ -583,24 +611,28 @@ discard block |
||
| 583 | 611 | foreach ($parts as $part) |
| 584 | 612 | { |
| 585 | 613 | // Handle XML comments. |
| 586 | - if (!$inCdata && $part === '<!--') |
|
| 587 | - $inComment = true; |
|
| 588 | - if ($inComment && $part === '-->') |
|
| 589 | - $inComment = false; |
|
| 590 | - elseif ($inComment) |
|
| 591 | - continue; |
|
| 614 | + if (!$inCdata && $part === '<!--') { |
|
| 615 | + $inComment = true; |
|
| 616 | + } |
|
| 617 | + if ($inComment && $part === '-->') { |
|
| 618 | + $inComment = false; |
|
| 619 | + } elseif ($inComment) { |
|
| 620 | + continue; |
|
| 621 | + } |
|
| 592 | 622 | |
| 593 | 623 | // Handle Cdata blocks. |
| 594 | - elseif (!$inComment && $part === '<![CDATA[') |
|
| 595 | - $inCdata = true; |
|
| 596 | - elseif ($inCdata && $part === ']]>') |
|
| 597 | - $inCdata = false; |
|
| 598 | - elseif ($inCdata) |
|
| 599 | - $output .= htmlentities($part, ENT_QUOTES); |
|
| 624 | + elseif (!$inComment && $part === '<![CDATA[') { |
|
| 625 | + $inCdata = true; |
|
| 626 | + } elseif ($inCdata && $part === ']]>') { |
|
| 627 | + $inCdata = false; |
|
| 628 | + } elseif ($inCdata) { |
|
| 629 | + $output .= htmlentities($part, ENT_QUOTES); |
|
| 630 | + } |
|
| 600 | 631 | |
| 601 | 632 | // Everything else is kept as is. |
| 602 | - else |
|
| 603 | - $output .= $part; |
|
| 633 | + else { |
|
| 634 | + $output .= $part; |
|
| 635 | + } |
|
| 604 | 636 | } |
| 605 | 637 | |
| 606 | 638 | return $output; |
@@ -635,22 +667,26 @@ discard block |
||
| 635 | 667 | protected function _fetch($array) |
| 636 | 668 | { |
| 637 | 669 | // Don't return anything if this is just a string. |
| 638 | - if (is_string($array)) |
|
| 639 | - return ''; |
|
| 670 | + if (is_string($array)) { |
|
| 671 | + return ''; |
|
| 672 | + } |
|
| 640 | 673 | |
| 641 | 674 | $temp = ''; |
| 642 | 675 | foreach ($array as $text) |
| 643 | 676 | { |
| 644 | 677 | // This means it's most likely an attribute or the name itself. |
| 645 | - if (!isset($text['name'])) |
|
| 646 | - continue; |
|
| 678 | + if (!isset($text['name'])) { |
|
| 679 | + continue; |
|
| 680 | + } |
|
| 647 | 681 | |
| 648 | 682 | // This is text! |
| 649 | - if ($text['name'] == '!') |
|
| 650 | - $temp .= $text['value']; |
|
| 683 | + if ($text['name'] == '!') { |
|
| 684 | + $temp .= $text['value']; |
|
| 685 | + } |
|
| 651 | 686 | // Another element - dive in ;). |
| 652 | - else |
|
| 653 | - $temp .= $this->_fetch($text); |
|
| 687 | + else { |
|
| 688 | + $temp .= $this->_fetch($text); |
|
| 689 | + } |
|
| 654 | 690 | } |
| 655 | 691 | |
| 656 | 692 | // Return all the bits and pieces we've put together. |
@@ -669,12 +705,14 @@ discard block |
||
| 669 | 705 | protected function _path($array, $path, $level, $no_error = false) |
| 670 | 706 | { |
| 671 | 707 | // Is $array even an array? It might be false! |
| 672 | - if (!is_array($array)) |
|
| 673 | - return false; |
|
| 708 | + if (!is_array($array)) { |
|
| 709 | + return false; |
|
| 710 | + } |
|
| 674 | 711 | |
| 675 | 712 | // Asking for *no* path? |
| 676 | - if ($path == '' || $path == '.') |
|
| 677 | - return $array; |
|
| 713 | + if ($path == '' || $path == '.') { |
|
| 714 | + return $array; |
|
| 715 | + } |
|
| 678 | 716 | $paths = explode('|', $path); |
| 679 | 717 | |
| 680 | 718 | // A * means all elements of any name. |
@@ -685,16 +723,18 @@ discard block |
||
| 685 | 723 | // Check each element. |
| 686 | 724 | foreach ($array as $value) |
| 687 | 725 | { |
| 688 | - if (!is_array($value) || $value['name'] === '!') |
|
| 689 | - continue; |
|
| 726 | + if (!is_array($value) || $value['name'] === '!') { |
|
| 727 | + continue; |
|
| 728 | + } |
|
| 690 | 729 | |
| 691 | 730 | if ($show_all || in_array($value['name'], $paths)) |
| 692 | 731 | { |
| 693 | 732 | // Skip elements before "the one". |
| 694 | - if ($level !== null && $level > 0) |
|
| 695 | - $level--; |
|
| 696 | - else |
|
| 697 | - $results[] = $value; |
|
| 733 | + if ($level !== null && $level > 0) { |
|
| 734 | + $level--; |
|
| 735 | + } else { |
|
| 736 | + $results[] = $value; |
|
| 737 | + } |
|
| 698 | 738 | } |
| 699 | 739 | } |
| 700 | 740 | |
@@ -703,21 +743,25 @@ discard block |
||
| 703 | 743 | { |
| 704 | 744 | $trace = debug_backtrace(); |
| 705 | 745 | $i = 0; |
| 706 | - while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) |
|
| 707 | - $i++; |
|
| 746 | + while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) { |
|
| 747 | + $i++; |
|
| 748 | + } |
|
| 708 | 749 | $debug = ' from ' . $trace[$i - 1]['file'] . ' on line ' . $trace[$i - 1]['line']; |
| 709 | 750 | |
| 710 | 751 | // Cause an error. |
| 711 | - if ($this->debug_level & E_NOTICE && !$no_error) |
|
| 712 | - trigger_error('Undefined XML element: ' . $path . $debug, E_USER_NOTICE); |
|
| 752 | + if ($this->debug_level & E_NOTICE && !$no_error) { |
|
| 753 | + trigger_error('Undefined XML element: ' . $path . $debug, E_USER_NOTICE); |
|
| 754 | + } |
|
| 713 | 755 | return false; |
| 714 | 756 | } |
| 715 | 757 | // Only one result. |
| 716 | - elseif (count($results) == 1 || $level !== null) |
|
| 717 | - return $results[0]; |
|
| 758 | + elseif (count($results) == 1 || $level !== null) { |
|
| 759 | + return $results[0]; |
|
| 760 | + } |
|
| 718 | 761 | // Return the result set. |
| 719 | - else |
|
| 720 | - return $results + array('name' => $path . '[]'); |
|
| 762 | + else { |
|
| 763 | + return $results + array('name' => $path . '[]'); |
|
| 764 | + } |
|
| 721 | 765 | } |
| 722 | 766 | } |
| 723 | 767 | |
@@ -764,8 +808,9 @@ discard block |
||
| 764 | 808 | $this->error = false; |
| 765 | 809 | $this->pasv = array(); |
| 766 | 810 | |
| 767 | - if ($ftp_server !== null) |
|
| 768 | - $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass); |
|
| 811 | + if ($ftp_server !== null) { |
|
| 812 | + $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass); |
|
| 813 | + } |
|
| 769 | 814 | } |
| 770 | 815 | |
| 771 | 816 | /** |
@@ -778,14 +823,16 @@ discard block |
||
| 778 | 823 | */ |
| 779 | 824 | public function connect($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = '[email protected]') |
| 780 | 825 | { |
| 781 | - if (strpos($ftp_server, 'ftp://') === 0) |
|
| 782 | - $ftp_server = substr($ftp_server, 6); |
|
| 783 | - elseif (strpos($ftp_server, 'ftps://') === 0) |
|
| 784 | - $ftp_server = 'ssl://' . substr($ftp_server, 7); |
|
| 785 | - if (strpos($ftp_server, 'http://') === 0) |
|
| 786 | - $ftp_server = substr($ftp_server, 7); |
|
| 787 | - elseif (strpos($ftp_server, 'https://') === 0) |
|
| 788 | - $ftp_server = substr($ftp_server, 8); |
|
| 826 | + if (strpos($ftp_server, 'ftp://') === 0) { |
|
| 827 | + $ftp_server = substr($ftp_server, 6); |
|
| 828 | + } elseif (strpos($ftp_server, 'ftps://') === 0) { |
|
| 829 | + $ftp_server = 'ssl://' . substr($ftp_server, 7); |
|
| 830 | + } |
|
| 831 | + if (strpos($ftp_server, 'http://') === 0) { |
|
| 832 | + $ftp_server = substr($ftp_server, 7); |
|
| 833 | + } elseif (strpos($ftp_server, 'https://') === 0) { |
|
| 834 | + $ftp_server = substr($ftp_server, 8); |
|
| 835 | + } |
|
| 789 | 836 | $ftp_server = strtr($ftp_server, array('/' => '', ':' => '', '@' => '')); |
| 790 | 837 | |
| 791 | 838 | // Connect to the FTP server. |
@@ -834,12 +881,14 @@ discard block |
||
| 834 | 881 | */ |
| 835 | 882 | public function chdir($ftp_path) |
| 836 | 883 | { |
| 837 | - if (!is_resource($this->connection)) |
|
| 838 | - return false; |
|
| 884 | + if (!is_resource($this->connection)) { |
|
| 885 | + return false; |
|
| 886 | + } |
|
| 839 | 887 | |
| 840 | 888 | // No slash on the end, please... |
| 841 | - if ($ftp_path !== '/' && substr($ftp_path, -1) === '/') |
|
| 842 | - $ftp_path = substr($ftp_path, 0, -1); |
|
| 889 | + if ($ftp_path !== '/' && substr($ftp_path, -1) === '/') { |
|
| 890 | + $ftp_path = substr($ftp_path, 0, -1); |
|
| 891 | + } |
|
| 843 | 892 | |
| 844 | 893 | fwrite($this->connection, 'CWD ' . $ftp_path . "\r\n"); |
| 845 | 894 | if (!$this->check_response(250)) |
@@ -860,11 +909,13 @@ discard block |
||
| 860 | 909 | */ |
| 861 | 910 | public function chmod($ftp_file, $chmod) |
| 862 | 911 | { |
| 863 | - if (!is_resource($this->connection)) |
|
| 864 | - return false; |
|
| 912 | + if (!is_resource($this->connection)) { |
|
| 913 | + return false; |
|
| 914 | + } |
|
| 865 | 915 | |
| 866 | - if ($ftp_file == '') |
|
| 867 | - $ftp_file = '.'; |
|
| 916 | + if ($ftp_file == '') { |
|
| 917 | + $ftp_file = '.'; |
|
| 918 | + } |
|
| 868 | 919 | |
| 869 | 920 | // Do we have a file or a dir? |
| 870 | 921 | $is_dir = is_dir($ftp_file); |
@@ -880,9 +931,7 @@ discard block |
||
| 880 | 931 | { |
| 881 | 932 | $is_writable = true; |
| 882 | 933 | break; |
| 883 | - } |
|
| 884 | - |
|
| 885 | - else |
|
| 934 | + } else |
|
| 886 | 935 | { |
| 887 | 936 | // Convert the chmod value from octal (0777) to text ("777"). |
| 888 | 937 | fwrite($this->connection, 'SITE CHMOD ' . decoct($val) . ' ' . $ftp_file . "\r\n"); |
@@ -905,8 +954,9 @@ discard block |
||
| 905 | 954 | public function unlink($ftp_file) |
| 906 | 955 | { |
| 907 | 956 | // We are actually connected, right? |
| 908 | - if (!is_resource($this->connection)) |
|
| 909 | - return false; |
|
| 957 | + if (!is_resource($this->connection)) { |
|
| 958 | + return false; |
|
| 959 | + } |
|
| 910 | 960 | |
| 911 | 961 | // Delete file X. |
| 912 | 962 | fwrite($this->connection, 'DELE ' . $ftp_file . "\r\n"); |
@@ -935,9 +985,9 @@ discard block |
||
| 935 | 985 | { |
| 936 | 986 | // Wait for a response that isn't continued with -, but don't wait too long. |
| 937 | 987 | $time = time(); |
| 938 | - do |
|
| 939 | - $this->last_message = fgets($this->connection, 1024); |
|
| 940 | - while ((strlen($this->last_message) < 4 || strpos($this->last_message, ' ') === 0 || strpos($this->last_message, ' ', 3) !== 3) && time() - $time < 5); |
|
| 988 | + do { |
|
| 989 | + $this->last_message = fgets($this->connection, 1024); |
|
| 990 | + } while ((strlen($this->last_message) < 4 || strpos($this->last_message, ' ') === 0 || strpos($this->last_message, ' ', 3) !== 3) && time() - $time < 5); |
|
| 941 | 991 | |
| 942 | 992 | // Was the desired response returned? |
| 943 | 993 | return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired; |
@@ -951,15 +1001,16 @@ discard block |
||
| 951 | 1001 | public function passive() |
| 952 | 1002 | { |
| 953 | 1003 | // We can't create a passive data connection without a primary one first being there. |
| 954 | - if (!is_resource($this->connection)) |
|
| 955 | - return false; |
|
| 1004 | + if (!is_resource($this->connection)) { |
|
| 1005 | + return false; |
|
| 1006 | + } |
|
| 956 | 1007 | |
| 957 | 1008 | // Request a passive connection - this means, we'll talk to you, you don't talk to us. |
| 958 | 1009 | @fwrite($this->connection, 'PASV' . "\r\n"); |
| 959 | 1010 | $time = time(); |
| 960 | - do |
|
| 961 | - $response = fgets($this->connection, 1024); |
|
| 962 | - while (strpos($response, ' ', 3) !== 3 && time() - $time < 5); |
|
| 1011 | + do { |
|
| 1012 | + $response = fgets($this->connection, 1024); |
|
| 1013 | + } while (strpos($response, ' ', 3) !== 3 && time() - $time < 5); |
|
| 963 | 1014 | |
| 964 | 1015 | // If it's not 227, we weren't given an IP and port, which means it failed. |
| 965 | 1016 | if (strpos($response, '227 ') !== 0) |
@@ -990,12 +1041,14 @@ discard block |
||
| 990 | 1041 | public function create_file($ftp_file) |
| 991 | 1042 | { |
| 992 | 1043 | // First, we have to be connected... very important. |
| 993 | - if (!is_resource($this->connection)) |
|
| 994 | - return false; |
|
| 1044 | + if (!is_resource($this->connection)) { |
|
| 1045 | + return false; |
|
| 1046 | + } |
|
| 995 | 1047 | |
| 996 | 1048 | // I'd like one passive mode, please! |
| 997 | - if (!$this->passive()) |
|
| 998 | - return false; |
|
| 1049 | + if (!$this->passive()) { |
|
| 1050 | + return false; |
|
| 1051 | + } |
|
| 999 | 1052 | |
| 1000 | 1053 | // Seems logical enough, so far... |
| 1001 | 1054 | fwrite($this->connection, 'STOR ' . $ftp_file . "\r\n"); |
@@ -1030,12 +1083,14 @@ discard block |
||
| 1030 | 1083 | public function list_dir($ftp_path = '', $search = false) |
| 1031 | 1084 | { |
| 1032 | 1085 | // Are we even connected...? |
| 1033 | - if (!is_resource($this->connection)) |
|
| 1034 | - return false; |
|
| 1086 | + if (!is_resource($this->connection)) { |
|
| 1087 | + return false; |
|
| 1088 | + } |
|
| 1035 | 1089 | |
| 1036 | 1090 | // Passive... non-agressive... |
| 1037 | - if (!$this->passive()) |
|
| 1038 | - return false; |
|
| 1091 | + if (!$this->passive()) { |
|
| 1092 | + return false; |
|
| 1093 | + } |
|
| 1039 | 1094 | |
| 1040 | 1095 | // Get the listing! |
| 1041 | 1096 | fwrite($this->connection, 'LIST -1' . ($search ? 'R' : '') . ($ftp_path == '' ? '' : ' ' . $ftp_path) . "\r\n"); |
@@ -1051,8 +1106,9 @@ discard block |
||
| 1051 | 1106 | |
| 1052 | 1107 | // Read in the file listing. |
| 1053 | 1108 | $data = ''; |
| 1054 | - while (!feof($fp)) |
|
| 1055 | - $data .= fread($fp, 4096); |
|
| 1109 | + while (!feof($fp)) { |
|
| 1110 | + $data .= fread($fp, 4096); |
|
| 1111 | + } |
|
| 1056 | 1112 | fclose($fp); |
| 1057 | 1113 | |
| 1058 | 1114 | // Everything go okay? |
@@ -1074,21 +1130,23 @@ discard block |
||
| 1074 | 1130 | */ |
| 1075 | 1131 | public function locate($file, $listing = null) |
| 1076 | 1132 | { |
| 1077 | - if ($listing === null) |
|
| 1078 | - $listing = $this->list_dir('', true); |
|
| 1133 | + if ($listing === null) { |
|
| 1134 | + $listing = $this->list_dir('', true); |
|
| 1135 | + } |
|
| 1079 | 1136 | $listing = explode("\n", $listing); |
| 1080 | 1137 | |
| 1081 | 1138 | @fwrite($this->connection, 'PWD' . "\r\n"); |
| 1082 | 1139 | $time = time(); |
| 1083 | - do |
|
| 1084 | - $response = fgets($this->connection, 1024); |
|
| 1085 | - while ($response[3] != ' ' && time() - $time < 5); |
|
| 1140 | + do { |
|
| 1141 | + $response = fgets($this->connection, 1024); |
|
| 1142 | + } while ($response[3] != ' ' && time() - $time < 5); |
|
| 1086 | 1143 | |
| 1087 | 1144 | // Check for 257! |
| 1088 | - if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0) |
|
| 1089 | - $current_dir = strtr($match[1], array('""' => '"')); |
|
| 1090 | - else |
|
| 1091 | - $current_dir = ''; |
|
| 1145 | + if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0) { |
|
| 1146 | + $current_dir = strtr($match[1], array('""' => '"')); |
|
| 1147 | + } else { |
|
| 1148 | + $current_dir = ''; |
|
| 1149 | + } |
|
| 1092 | 1150 | |
| 1093 | 1151 | for ($i = 0, $n = count($listing); $i < $n; $i++) |
| 1094 | 1152 | { |
@@ -1101,12 +1159,15 @@ discard block |
||
| 1101 | 1159 | // Okay, this file's name is: |
| 1102 | 1160 | $listing[$i] = $current_dir . '/' . trim(strlen($listing[$i]) > 30 ? strrchr($listing[$i], ' ') : $listing[$i]); |
| 1103 | 1161 | |
| 1104 | - if ($file[0] == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1)) |
|
| 1105 | - return $listing[$i]; |
|
| 1106 | - if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1)) |
|
| 1107 | - return $listing[$i]; |
|
| 1108 | - if (basename($listing[$i]) == $file || $listing[$i] == $file) |
|
| 1109 | - return $listing[$i]; |
|
| 1162 | + if ($file[0] == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1)) { |
|
| 1163 | + return $listing[$i]; |
|
| 1164 | + } |
|
| 1165 | + if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1)) { |
|
| 1166 | + return $listing[$i]; |
|
| 1167 | + } |
|
| 1168 | + if (basename($listing[$i]) == $file || $listing[$i] == $file) { |
|
| 1169 | + return $listing[$i]; |
|
| 1170 | + } |
|
| 1110 | 1171 | } |
| 1111 | 1172 | |
| 1112 | 1173 | return false; |
@@ -1121,8 +1182,9 @@ discard block |
||
| 1121 | 1182 | public function create_dir($ftp_dir) |
| 1122 | 1183 | { |
| 1123 | 1184 | // We must be connected to the server to do something. |
| 1124 | - if (!is_resource($this->connection)) |
|
| 1125 | - return false; |
|
| 1185 | + if (!is_resource($this->connection)) { |
|
| 1186 | + return false; |
|
| 1187 | + } |
|
| 1126 | 1188 | |
| 1127 | 1189 | // Make this new beautiful directory! |
| 1128 | 1190 | fwrite($this->connection, 'MKD ' . $ftp_dir . "\r\n"); |
@@ -1154,35 +1216,40 @@ discard block |
||
| 1154 | 1216 | |
| 1155 | 1217 | $path = strtr($_SERVER['DOCUMENT_ROOT'], array('/home/' . $match[1] . '/' => '', '/home2/' . $match[1] . '/' => '')); |
| 1156 | 1218 | |
| 1157 | - if (substr($path, -1) == '/') |
|
| 1158 | - $path = substr($path, 0, -1); |
|
| 1219 | + if (substr($path, -1) == '/') { |
|
| 1220 | + $path = substr($path, 0, -1); |
|
| 1221 | + } |
|
| 1159 | 1222 | |
| 1160 | - if (strlen(dirname($_SERVER['PHP_SELF'])) > 1) |
|
| 1161 | - $path .= dirname($_SERVER['PHP_SELF']); |
|
| 1223 | + if (strlen(dirname($_SERVER['PHP_SELF'])) > 1) { |
|
| 1224 | + $path .= dirname($_SERVER['PHP_SELF']); |
|
| 1225 | + } |
|
| 1226 | + } elseif (strpos($filesystem_path, '/var/www/') === 0) { |
|
| 1227 | + $path = substr($filesystem_path, 8); |
|
| 1228 | + } else { |
|
| 1229 | + $path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => '')); |
|
| 1162 | 1230 | } |
| 1163 | - elseif (strpos($filesystem_path, '/var/www/') === 0) |
|
| 1164 | - $path = substr($filesystem_path, 8); |
|
| 1165 | - else |
|
| 1166 | - $path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => '')); |
|
| 1231 | + } else { |
|
| 1232 | + $path = ''; |
|
| 1167 | 1233 | } |
| 1168 | - else |
|
| 1169 | - $path = ''; |
|
| 1170 | 1234 | |
| 1171 | 1235 | if (is_resource($this->connection) && $this->list_dir($path) == '') |
| 1172 | 1236 | { |
| 1173 | 1237 | $data = $this->list_dir('', true); |
| 1174 | 1238 | |
| 1175 | - if ($lookup_file === null) |
|
| 1176 | - $lookup_file = $_SERVER['PHP_SELF']; |
|
| 1239 | + if ($lookup_file === null) { |
|
| 1240 | + $lookup_file = $_SERVER['PHP_SELF']; |
|
| 1241 | + } |
|
| 1177 | 1242 | |
| 1178 | 1243 | $found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data)); |
| 1179 | - if ($found_path == false) |
|
| 1180 | - $found_path = dirname($this->locate(basename($lookup_file))); |
|
| 1181 | - if ($found_path != false) |
|
| 1182 | - $path = $found_path; |
|
| 1244 | + if ($found_path == false) { |
|
| 1245 | + $found_path = dirname($this->locate(basename($lookup_file))); |
|
| 1246 | + } |
|
| 1247 | + if ($found_path != false) { |
|
| 1248 | + $path = $found_path; |
|
| 1249 | + } |
|
| 1250 | + } elseif (is_resource($this->connection)) { |
|
| 1251 | + $found_path = true; |
|
| 1183 | 1252 | } |
| 1184 | - elseif (is_resource($this->connection)) |
|
| 1185 | - $found_path = true; |
|
| 1186 | 1253 | |
| 1187 | 1254 | return array($username, $path, isset($found_path)); |
| 1188 | 1255 | } |
@@ -56,6 +56,7 @@ discard block |
||
| 56 | 56 | * @param array $wordsSearch Search words |
| 57 | 57 | * @param array $wordsExclude Words to exclude |
| 58 | 58 | * @param bool $isExcluded Whether the specfied word should be excluded |
| 59 | + * @return void |
|
| 59 | 60 | */ |
| 60 | 61 | public function prepareIndexes($word, array &$wordsSearch, array &$wordsExclude, $isExcluded); |
| 61 | 62 | |
@@ -130,7 +131,7 @@ discard block |
||
| 130 | 131 | * @param array $excludedIndexWords Indexed words that should be excluded |
| 131 | 132 | * @param array $participants |
| 132 | 133 | * @param array $searchArray |
| 133 | - * @return mixed |
|
| 134 | + * @return integer |
|
| 134 | 135 | */ |
| 135 | 136 | public function searchQuery(array $query_params, array $searchWords, array $excludedIndexWords, array &$participants, array &$searchArray); |
| 136 | 137 | } |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | /** |
| 280 | 280 | * Generate the timestamp for the calculation |
| 281 | 281 | * |
| 282 | - * @return integer Timestamp |
|
| 282 | + * @return double Timestamp |
|
| 283 | 283 | */ |
| 284 | 284 | public function generateTimestamp() |
| 285 | 285 | { |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * Truncate the given hash down to just what we need |
| 291 | 291 | * |
| 292 | 292 | * @param string $hash Hash to truncate |
| 293 | - * @return string Truncated hash value |
|
| 293 | + * @return integer Truncated hash value |
|
| 294 | 294 | */ |
| 295 | 295 | public function truncateHash($hash) |
| 296 | 296 | { |
@@ -518,7 +518,7 @@ |
||
| 518 | 518 | * @param array $parameters Not used? |
| 519 | 519 | * @param string $if_exists What to do if the index exists. If 'update', the definition will be updated. |
| 520 | 520 | * @param string $error |
| 521 | - * @return boolean Whether or not the operation was successful |
|
| 521 | + * @return false|null Whether or not the operation was successful |
|
| 522 | 522 | */ |
| 523 | 523 | function smf_db_add_index($table_name, $index_info, $parameters = array(), $if_exists = 'update', $error = 'fatal') |
| 524 | 524 | { |
@@ -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 | * Add the file functions to the $smcFunc array. |
@@ -52,8 +53,9 @@ discard block |
||
| 52 | 53 | 'messages', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages', |
| 53 | 54 | 'pm_recipients', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys', |
| 54 | 55 | 'themes', 'topics'); |
| 55 | - foreach ($reservedTables as $k => $table_name) |
|
| 56 | - $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
| 56 | + foreach ($reservedTables as $k => $table_name) { |
|
| 57 | + $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
| 58 | + } |
|
| 57 | 59 | |
| 58 | 60 | // We in turn may need the extra stuff. |
| 59 | 61 | db_extend('extra'); |
@@ -102,8 +104,9 @@ discard block |
||
| 102 | 104 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 103 | 105 | |
| 104 | 106 | // First - no way do we touch SMF tables. |
| 105 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
| 106 | - return false; |
|
| 107 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
| 108 | + return false; |
|
| 109 | + } |
|
| 107 | 110 | |
| 108 | 111 | // Log that we'll want to remove this on uninstall. |
| 109 | 112 | $db_package_log[] = array('remove_table', $table_name); |
@@ -113,10 +116,11 @@ discard block |
||
| 113 | 116 | if (in_array($full_table_name, $tables)) |
| 114 | 117 | { |
| 115 | 118 | // This is a sad day... drop the table? If not, return false (error) by default. |
| 116 | - if ($if_exists == 'overwrite') |
|
| 117 | - $smcFunc['db_drop_table']($table_name); |
|
| 118 | - else |
|
| 119 | - return $if_exists == 'ignore'; |
|
| 119 | + if ($if_exists == 'overwrite') { |
|
| 120 | + $smcFunc['db_drop_table']($table_name); |
|
| 121 | + } else { |
|
| 122 | + return $if_exists == 'ignore'; |
|
| 123 | + } |
|
| 120 | 124 | } |
| 121 | 125 | |
| 122 | 126 | // If we've got this far - good news - no table exists. We can build our own! |
@@ -134,17 +138,18 @@ discard block |
||
| 134 | 138 | ) |
| 135 | 139 | ); |
| 136 | 140 | $default = 'default nextval(\'' . $table_name . '_seq\')'; |
| 141 | + } elseif (isset($column['default']) && $column['default'] !== null) { |
|
| 142 | + $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
| 143 | + } else { |
|
| 144 | + $default = ''; |
|
| 137 | 145 | } |
| 138 | - elseif (isset($column['default']) && $column['default'] !== null) |
|
| 139 | - $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
| 140 | - else |
|
| 141 | - $default = ''; |
|
| 142 | 146 | |
| 143 | 147 | // Sort out the size... |
| 144 | 148 | $column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null; |
| 145 | 149 | list ($type, $size) = $smcFunc['db_calculate_type']($column['type'], $column['size']); |
| 146 | - if ($size !== null) |
|
| 147 | - $type = $type . '(' . $size . ')'; |
|
| 150 | + if ($size !== null) { |
|
| 151 | + $type = $type . '(' . $size . ')'; |
|
| 152 | + } |
|
| 148 | 153 | |
| 149 | 154 | // Now just put it together! |
| 150 | 155 | $table_query .= "\n\t\"" . $column['name'] . '" ' . $type . ' ' . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default . ','; |
@@ -157,19 +162,21 @@ discard block |
||
| 157 | 162 | $columns = implode(',', $index['columns']); |
| 158 | 163 | |
| 159 | 164 | // Primary goes in the table... |
| 160 | - if (isset($index['type']) && $index['type'] == 'primary') |
|
| 161 | - $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
| 162 | - else |
|
| 165 | + if (isset($index['type']) && $index['type'] == 'primary') { |
|
| 166 | + $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
| 167 | + } else |
|
| 163 | 168 | { |
| 164 | - if (empty($index['name'])) |
|
| 165 | - $index['name'] = implode('_', $index['columns']); |
|
| 169 | + if (empty($index['name'])) { |
|
| 170 | + $index['name'] = implode('_', $index['columns']); |
|
| 171 | + } |
|
| 166 | 172 | $index_queries[] = 'CREATE ' . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $table_name . '_' . $index['name'] . ' ON ' . $table_name . ' (' . $columns . ')'; |
| 167 | 173 | } |
| 168 | 174 | } |
| 169 | 175 | |
| 170 | 176 | // No trailing commas! |
| 171 | - if (substr($table_query, -1) == ',') |
|
| 172 | - $table_query = substr($table_query, 0, -1); |
|
| 177 | + if (substr($table_query, -1) == ',') { |
|
| 178 | + $table_query = substr($table_query, 0, -1); |
|
| 179 | + } |
|
| 173 | 180 | |
| 174 | 181 | $table_query .= ')'; |
| 175 | 182 | |
@@ -180,12 +187,13 @@ discard block |
||
| 180 | 187 | ) |
| 181 | 188 | ); |
| 182 | 189 | // And the indexes... |
| 183 | - foreach ($index_queries as $query) |
|
| 184 | - $smcFunc['db_query']('', $query, |
|
| 190 | + foreach ($index_queries as $query) { |
|
| 191 | + $smcFunc['db_query']('', $query, |
|
| 185 | 192 | array( |
| 186 | 193 | 'security_override' => true, |
| 187 | 194 | ) |
| 188 | 195 | ); |
| 196 | + } |
|
| 189 | 197 | |
| 190 | 198 | // Go, go power rangers! |
| 191 | 199 | $smcFunc['db_transaction']('commit'); |
@@ -213,8 +221,9 @@ discard block |
||
| 213 | 221 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 214 | 222 | |
| 215 | 223 | // God no - dropping one of these = bad. |
| 216 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
| 217 | - return false; |
|
| 224 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
| 225 | + return false; |
|
| 226 | + } |
|
| 218 | 227 | |
| 219 | 228 | // Does it exist? |
| 220 | 229 | if (in_array($full_table_name, $smcFunc['db_list_tables']())) |
@@ -272,21 +281,24 @@ discard block |
||
| 272 | 281 | |
| 273 | 282 | // Does it exist - if so don't add it again! |
| 274 | 283 | $columns = $smcFunc['db_list_columns']($table_name, false); |
| 275 | - foreach ($columns as $column) |
|
| 276 | - if ($column == $column_info['name']) |
|
| 284 | + foreach ($columns as $column) { |
|
| 285 | + if ($column == $column_info['name']) |
|
| 277 | 286 | { |
| 278 | 287 | // If we're going to overwrite then use change column. |
| 279 | 288 | if ($if_exists == 'update') |
| 280 | 289 | return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
| 281 | - else |
|
| 282 | - return false; |
|
| 290 | + } |
|
| 291 | + else { |
|
| 292 | + return false; |
|
| 293 | + } |
|
| 283 | 294 | } |
| 284 | 295 | |
| 285 | 296 | // Get the specifics... |
| 286 | 297 | $column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null; |
| 287 | 298 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']); |
| 288 | - if ($size !== null) |
|
| 289 | - $type = $type . '(' . $size . ')'; |
|
| 299 | + if ($size !== null) { |
|
| 300 | + $type = $type . '(' . $size . ')'; |
|
| 301 | + } |
|
| 290 | 302 | |
| 291 | 303 | // Now add the thing! |
| 292 | 304 | $query = ' |
@@ -301,11 +313,12 @@ discard block |
||
| 301 | 313 | // If there's more attributes they need to be done via a change on PostgreSQL. |
| 302 | 314 | unset($column_info['type'], $column_info['size']); |
| 303 | 315 | |
| 304 | - if (count($column_info) != 1) |
|
| 305 | - return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
|
| 306 | - else |
|
| 307 | - return true; |
|
| 308 | -} |
|
| 316 | + if (count($column_info) != 1) { |
|
| 317 | + return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
|
| 318 | + } else { |
|
| 319 | + return true; |
|
| 320 | + } |
|
| 321 | + } |
|
| 309 | 322 | |
| 310 | 323 | /** |
| 311 | 324 | * Removes a column. |
@@ -324,8 +337,8 @@ discard block |
||
| 324 | 337 | |
| 325 | 338 | // Does it exist? |
| 326 | 339 | $columns = $smcFunc['db_list_columns']($table_name, true); |
| 327 | - foreach ($columns as $column) |
|
| 328 | - if ($column['name'] == $column_name) |
|
| 340 | + foreach ($columns as $column) { |
|
| 341 | + if ($column['name'] == $column_name) |
|
| 329 | 342 | { |
| 330 | 343 | // If there is an auto we need remove it! |
| 331 | 344 | if ($column['auto']) |
@@ -335,6 +348,7 @@ discard block |
||
| 335 | 348 | 'security_override' => true, |
| 336 | 349 | ) |
| 337 | 350 | ); |
| 351 | + } |
|
| 338 | 352 | |
| 339 | 353 | $smcFunc['db_query']('', ' |
| 340 | 354 | ALTER TABLE ' . $table_name . ' |
@@ -369,13 +383,15 @@ discard block |
||
| 369 | 383 | // Check it does exist! |
| 370 | 384 | $columns = $smcFunc['db_list_columns']($table_name, true); |
| 371 | 385 | $old_info = null; |
| 372 | - foreach ($columns as $column) |
|
| 373 | - if ($column['name'] == $old_column) |
|
| 386 | + foreach ($columns as $column) { |
|
| 387 | + if ($column['name'] == $old_column) |
|
| 374 | 388 | $old_info = $column; |
| 389 | + } |
|
| 375 | 390 | |
| 376 | 391 | // Nothing? |
| 377 | - if ($old_info == null) |
|
| 378 | - return false; |
|
| 392 | + if ($old_info == null) { |
|
| 393 | + return false; |
|
| 394 | + } |
|
| 379 | 395 | |
| 380 | 396 | // Now we check each bit individually and ALTER as required. |
| 381 | 397 | if (isset($column_info['name']) && $column_info['name'] != $old_column) |
@@ -432,8 +448,9 @@ discard block |
||
| 432 | 448 | { |
| 433 | 449 | $column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null; |
| 434 | 450 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']); |
| 435 | - if ($size !== null) |
|
| 436 | - $type = $type . '(' . $size . ')'; |
|
| 451 | + if ($size !== null) { |
|
| 452 | + $type = $type . '(' . $size . ')'; |
|
| 453 | + } |
|
| 437 | 454 | |
| 438 | 455 | // The alter is a pain. |
| 439 | 456 | $smcFunc['db_transaction']('begin'); |
@@ -527,21 +544,23 @@ discard block |
||
| 527 | 544 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 528 | 545 | |
| 529 | 546 | // No columns = no index. |
| 530 | - if (empty($index_info['columns'])) |
|
| 531 | - return false; |
|
| 547 | + if (empty($index_info['columns'])) { |
|
| 548 | + return false; |
|
| 549 | + } |
|
| 532 | 550 | $columns = implode(',', $index_info['columns']); |
| 533 | 551 | |
| 534 | 552 | // No name - make it up! |
| 535 | 553 | if (empty($index_info['name'])) |
| 536 | 554 | { |
| 537 | 555 | // No need for primary. |
| 538 | - if (isset($index_info['type']) && $index_info['type'] == 'primary') |
|
| 539 | - $index_info['name'] = ''; |
|
| 540 | - else |
|
| 541 | - $index_info['name'] = $table_name . implode('_', $index_info['columns']); |
|
| 556 | + if (isset($index_info['type']) && $index_info['type'] == 'primary') { |
|
| 557 | + $index_info['name'] = ''; |
|
| 558 | + } else { |
|
| 559 | + $index_info['name'] = $table_name . implode('_', $index_info['columns']); |
|
| 560 | + } |
|
| 561 | + } else { |
|
| 562 | + $index_info['name'] = $table_name . $index_info['name']; |
|
| 542 | 563 | } |
| 543 | - else |
|
| 544 | - $index_info['name'] = $table_name . $index_info['name']; |
|
| 545 | 564 | |
| 546 | 565 | // Log that we are going to want to remove this! |
| 547 | 566 | $db_package_log[] = array('remove_index', $table_name, $index_info['name']); |
@@ -554,10 +573,11 @@ discard block |
||
| 554 | 573 | if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary')) |
| 555 | 574 | { |
| 556 | 575 | // If we want to overwrite simply remove the current one then continue. |
| 557 | - if ($if_exists != 'update' || $index['type'] == 'primary') |
|
| 558 | - return false; |
|
| 559 | - else |
|
| 560 | - $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
| 576 | + if ($if_exists != 'update' || $index['type'] == 'primary') { |
|
| 577 | + return false; |
|
| 578 | + } else { |
|
| 579 | + $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
| 580 | + } |
|
| 561 | 581 | } |
| 562 | 582 | } |
| 563 | 583 | |
@@ -571,8 +591,7 @@ discard block |
||
| 571 | 591 | 'security_override' => true, |
| 572 | 592 | ) |
| 573 | 593 | ); |
| 574 | - } |
|
| 575 | - else |
|
| 594 | + } else |
|
| 576 | 595 | { |
| 577 | 596 | $smcFunc['db_query']('', ' |
| 578 | 597 | CREATE ' . (isset($index_info['type']) && $index_info['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $index_info['name'] . ' ON ' . $table_name . ' (' . $columns . ')', |
@@ -600,8 +619,9 @@ discard block |
||
| 600 | 619 | |
| 601 | 620 | // Better exist! |
| 602 | 621 | $indexes = $smcFunc['db_list_indexes']($table_name, true); |
| 603 | - if ($index_name != 'primary') |
|
| 604 | - $index_name = $table_name . '_' . $index_name; |
|
| 622 | + if ($index_name != 'primary') { |
|
| 623 | + $index_name = $table_name . '_' . $index_name; |
|
| 624 | + } |
|
| 605 | 625 | |
| 606 | 626 | foreach ($indexes as $index) |
| 607 | 627 | { |
@@ -665,8 +685,7 @@ discard block |
||
| 665 | 685 | 'datetime' => 'timestamp without time zone', |
| 666 | 686 | 'timestamp' => 'timestamp without time zone', |
| 667 | 687 | ); |
| 668 | - } |
|
| 669 | - else |
|
| 688 | + } else |
|
| 670 | 689 | { |
| 671 | 690 | $types = array( |
| 672 | 691 | 'character varying' => 'varchar', |
@@ -682,14 +701,16 @@ discard block |
||
| 682 | 701 | // Got it? Change it! |
| 683 | 702 | if (isset($types[$type_name])) |
| 684 | 703 | { |
| 685 | - if ($type_name == 'tinytext') |
|
| 686 | - $type_size = 255; |
|
| 704 | + if ($type_name == 'tinytext') { |
|
| 705 | + $type_size = 255; |
|
| 706 | + } |
|
| 687 | 707 | $type_name = $types[$type_name]; |
| 688 | 708 | } |
| 689 | 709 | |
| 690 | 710 | // Only char fields got size |
| 691 | - if (strpos($type_name, 'char') === false) |
|
| 692 | - $type_size = null; |
|
| 711 | + if (strpos($type_name, 'char') === false) { |
|
| 712 | + $type_size = null; |
|
| 713 | + } |
|
| 693 | 714 | |
| 694 | 715 | |
| 695 | 716 | return array($type_name, $type_size); |
@@ -744,8 +765,7 @@ discard block |
||
| 744 | 765 | if (!$detail) |
| 745 | 766 | { |
| 746 | 767 | $columns[] = $row['column_name']; |
| 747 | - } |
|
| 748 | - else |
|
| 768 | + } else |
|
| 749 | 769 | { |
| 750 | 770 | $auto = false; |
| 751 | 771 | // What is the default? |
@@ -753,11 +773,11 @@ discard block |
||
| 753 | 773 | { |
| 754 | 774 | $default = null; |
| 755 | 775 | $auto = true; |
| 776 | + } elseif (trim($row['column_default']) != '') { |
|
| 777 | + $default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::')); |
|
| 778 | + } else { |
|
| 779 | + $default = null; |
|
| 756 | 780 | } |
| 757 | - elseif (trim($row['column_default']) != '') |
|
| 758 | - $default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::')); |
|
| 759 | - else |
|
| 760 | - $default = null; |
|
| 761 | 781 | |
| 762 | 782 | // Make the type generic. |
| 763 | 783 | list ($type, $size) = $smcFunc['db_calculate_type']($row['data_type'], $row['character_maximum_length'], true); |
@@ -808,26 +828,30 @@ discard block |
||
| 808 | 828 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 809 | 829 | { |
| 810 | 830 | // Try get the columns that make it up. |
| 811 | - if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) |
|
| 812 | - continue; |
|
| 831 | + if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) { |
|
| 832 | + continue; |
|
| 833 | + } |
|
| 813 | 834 | |
| 814 | 835 | $columns = explode(',', $matches[1]); |
| 815 | 836 | |
| 816 | - if (empty($columns)) |
|
| 817 | - continue; |
|
| 837 | + if (empty($columns)) { |
|
| 838 | + continue; |
|
| 839 | + } |
|
| 818 | 840 | |
| 819 | - foreach ($columns as $k => $v) |
|
| 820 | - $columns[$k] = trim($v); |
|
| 841 | + foreach ($columns as $k => $v) { |
|
| 842 | + $columns[$k] = trim($v); |
|
| 843 | + } |
|
| 821 | 844 | |
| 822 | 845 | // Fix up the name to be consistent cross databases |
| 823 | - if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1) |
|
| 824 | - $row['name'] = 'PRIMARY'; |
|
| 825 | - else |
|
| 826 | - $row['name'] = str_replace($table_name . '_', '', $row['name']); |
|
| 846 | + if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1) { |
|
| 847 | + $row['name'] = 'PRIMARY'; |
|
| 848 | + } else { |
|
| 849 | + $row['name'] = str_replace($table_name . '_', '', $row['name']); |
|
| 850 | + } |
|
| 827 | 851 | |
| 828 | - if (!$detail) |
|
| 829 | - $indexes[] = $row['name']; |
|
| 830 | - else |
|
| 852 | + if (!$detail) { |
|
| 853 | + $indexes[] = $row['name']; |
|
| 854 | + } else |
|
| 831 | 855 | { |
| 832 | 856 | $indexes[$row['name']] = array( |
| 833 | 857 | 'name' => $row['name'], |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | * |
| 176 | 176 | * @param string $post_errors A string of info about errors encountered trying to save this draft |
| 177 | 177 | * @param array $recipientList An array of data about who this PM is being sent to |
| 178 | - * @return boolean false if you can't save the draft, true if we're doing this via XML more than 5 seconds after the last save, nothing otherwise |
|
| 178 | + * @return boolean|null false if you can't save the draft, true if we're doing this via XML more than 5 seconds after the last save, nothing otherwise |
|
| 179 | 179 | */ |
| 180 | 180 | function SavePMDraft(&$post_errors, $recipientList) |
| 181 | 181 | { |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | * |
| 393 | 393 | * @param int $id_draft The ID of the draft to delete |
| 394 | 394 | * @param boolean $check Whether or not to check that the draft belongs to the current user |
| 395 | - * @return boolean False if it couldn't be deleted (doesn't return anything otherwise) |
|
| 395 | + * @return false|null False if it couldn't be deleted (doesn't return anything otherwise) |
|
| 396 | 396 | */ |
| 397 | 397 | function DeleteDraft($id_draft, $check = true) |
| 398 | 398 | { |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | * @param int $member_id ID of the member to show drafts for |
| 427 | 427 | * @param boolean|integer If $type is 1, this can be set to only load drafts for posts in the specific topic |
| 428 | 428 | * @param int $draft_type The type of drafts to show - 0 for post drafts, 1 for PM drafts |
| 429 | - * @return boolean False if the drafts couldn't be loaded, nothing otherwise |
|
| 429 | + * @return false|null False if the drafts couldn't be loaded, nothing otherwise |
|
| 430 | 430 | */ |
| 431 | 431 | function ShowDrafts($member_id, $topic = false, $draft_type = 0) |
| 432 | 432 | { |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | * Allows for the deleting and loading/editing of drafts |
| 511 | 511 | * |
| 512 | 512 | * @param type $memID |
| 513 | - * @param type $draft_type |
|
| 513 | + * @param integer $draft_type |
|
| 514 | 514 | */ |
| 515 | 515 | function showProfileDrafts($memID, $draft_type = 0) |
| 516 | 516 | { |
@@ -663,7 +663,7 @@ discard block |
||
| 663 | 663 | * Uses the showpmdraft template |
| 664 | 664 | * Allows for the deleting and loading/editing of drafts |
| 665 | 665 | * |
| 666 | - * @param type $memID |
|
| 666 | + * @param integer $memID |
|
| 667 | 667 | */ |
| 668 | 668 | function showPMDrafts($memID = -1) |
| 669 | 669 | { |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 3 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | loadLanguage('Drafts'); |
| 21 | 22 | |
@@ -33,8 +34,9 @@ discard block |
||
| 33 | 34 | global $context, $user_info, $smcFunc, $modSettings, $board; |
| 34 | 35 | |
| 35 | 36 | // can you be, should you be ... here? |
| 36 | - if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft'])) |
|
| 37 | - return false; |
|
| 37 | + if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft'])) { |
|
| 38 | + return false; |
|
| 39 | + } |
|
| 38 | 40 | |
| 39 | 41 | // read in what they sent us, if anything |
| 40 | 42 | $id_draft = (int) $_POST['id_draft']; |
@@ -46,14 +48,16 @@ discard block |
||
| 46 | 48 | $context['draft_saved_on'] = $draft_info['poster_time']; |
| 47 | 49 | |
| 48 | 50 | // since we were called from the autosave function, send something back |
| 49 | - if (!empty($id_draft)) |
|
| 50 | - XmlDraft($id_draft); |
|
| 51 | + if (!empty($id_draft)) { |
|
| 52 | + XmlDraft($id_draft); |
|
| 53 | + } |
|
| 51 | 54 | |
| 52 | 55 | return true; |
| 53 | 56 | } |
| 54 | 57 | |
| 55 | - if (!isset($_POST['message'])) |
|
| 56 | - $_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : ''; |
|
| 58 | + if (!isset($_POST['message'])) { |
|
| 59 | + $_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : ''; |
|
| 60 | + } |
|
| 57 | 61 | |
| 58 | 62 | // prepare any data from the form |
| 59 | 63 | $topic_id = empty($_REQUEST['topic']) ? 0 : (int) $_REQUEST['topic']; |
@@ -66,8 +70,9 @@ discard block |
||
| 66 | 70 | |
| 67 | 71 | // message and subject still need a bit more work |
| 68 | 72 | preparsecode($draft['body']); |
| 69 | - if ($smcFunc['strlen']($draft['subject']) > 100) |
|
| 70 | - $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
| 73 | + if ($smcFunc['strlen']($draft['subject']) > 100) { |
|
| 74 | + $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
| 75 | + } |
|
| 71 | 76 | |
| 72 | 77 | // Modifying an existing draft, like hitting the save draft button or autosave enabled? |
| 73 | 78 | if (!empty($id_draft) && !empty($draft_info)) |
@@ -148,9 +153,9 @@ discard block |
||
| 148 | 153 | { |
| 149 | 154 | $context['draft_saved'] = true; |
| 150 | 155 | $context['id_draft'] = $id_draft; |
| 156 | + } else { |
|
| 157 | + $post_errors[] = 'draft_not_saved'; |
|
| 151 | 158 | } |
| 152 | - else |
|
| 153 | - $post_errors[] = 'draft_not_saved'; |
|
| 154 | 159 | |
| 155 | 160 | // cleanup |
| 156 | 161 | unset($_POST['save_draft']); |
@@ -180,8 +185,9 @@ discard block |
||
| 180 | 185 | global $context, $user_info, $smcFunc, $modSettings; |
| 181 | 186 | |
| 182 | 187 | // PM survey says ... can you stay or must you go |
| 183 | - if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) |
|
| 184 | - return false; |
|
| 188 | + if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) { |
|
| 189 | + return false; |
|
| 190 | + } |
|
| 185 | 191 | |
| 186 | 192 | // read in what you sent us |
| 187 | 193 | $id_pm_draft = (int) $_POST['id_pm_draft']; |
@@ -193,8 +199,9 @@ discard block |
||
| 193 | 199 | $context['draft_saved_on'] = $draft_info['poster_time']; |
| 194 | 200 | |
| 195 | 201 | // Send something back to the javascript caller |
| 196 | - if (!empty($id_draft)) |
|
| 197 | - XmlDraft($id_draft); |
|
| 202 | + if (!empty($id_draft)) { |
|
| 203 | + XmlDraft($id_draft); |
|
| 204 | + } |
|
| 198 | 205 | |
| 199 | 206 | return true; |
| 200 | 207 | } |
@@ -204,9 +211,9 @@ discard block |
||
| 204 | 211 | { |
| 205 | 212 | $recipientList['to'] = isset($_POST['recipient_to']) ? explode(',', $_POST['recipient_to']) : array(); |
| 206 | 213 | $recipientList['bcc'] = isset($_POST['recipient_bcc']) ? explode(',', $_POST['recipient_bcc']) : array(); |
| 214 | + } elseif (!empty($draft_info['to_list']) && empty($recipientList)) { |
|
| 215 | + $recipientList = smf_json_decode($draft_info['to_list'], true); |
|
| 207 | 216 | } |
| 208 | - elseif (!empty($draft_info['to_list']) && empty($recipientList)) |
|
| 209 | - $recipientList = smf_json_decode($draft_info['to_list'], true); |
|
| 210 | 217 | |
| 211 | 218 | // prepare the data we got from the form |
| 212 | 219 | $reply_id = empty($_POST['replied_to']) ? 0 : (int) $_POST['replied_to']; |
@@ -215,8 +222,9 @@ discard block |
||
| 215 | 222 | |
| 216 | 223 | // message and subject always need a bit more work |
| 217 | 224 | preparsecode($draft['body']); |
| 218 | - if ($smcFunc['strlen']($draft['subject']) > 100) |
|
| 219 | - $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
| 225 | + if ($smcFunc['strlen']($draft['subject']) > 100) { |
|
| 226 | + $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
| 227 | + } |
|
| 220 | 228 | |
| 221 | 229 | // Modifying an existing PM draft? |
| 222 | 230 | if (!empty($id_pm_draft) && !empty($draft_info)) |
@@ -280,9 +288,9 @@ discard block |
||
| 280 | 288 | { |
| 281 | 289 | $context['draft_saved'] = true; |
| 282 | 290 | $context['id_pm_draft'] = $id_pm_draft; |
| 291 | + } else { |
|
| 292 | + $post_errors[] = 'draft_not_saved'; |
|
| 283 | 293 | } |
| 284 | - else |
|
| 285 | - $post_errors[] = 'draft_not_saved'; |
|
| 286 | 294 | } |
| 287 | 295 | |
| 288 | 296 | // if we were called from the autosave function, send something back |
@@ -315,8 +323,9 @@ discard block |
||
| 315 | 323 | $type = (int) $type; |
| 316 | 324 | |
| 317 | 325 | // nothing to read, nothing to do |
| 318 | - if (empty($id_draft)) |
|
| 319 | - return false; |
|
| 326 | + if (empty($id_draft)) { |
|
| 327 | + return false; |
|
| 328 | + } |
|
| 320 | 329 | |
| 321 | 330 | // load in this draft from the DB |
| 322 | 331 | $request = $smcFunc['db_query']('', ' |
@@ -337,8 +346,9 @@ discard block |
||
| 337 | 346 | ); |
| 338 | 347 | |
| 339 | 348 | // no results? |
| 340 | - if (!$smcFunc['db_num_rows']($request)) |
|
| 341 | - return false; |
|
| 349 | + if (!$smcFunc['db_num_rows']($request)) { |
|
| 350 | + return false; |
|
| 351 | + } |
|
| 342 | 352 | |
| 343 | 353 | // load up the data |
| 344 | 354 | $draft_info = $smcFunc['db_fetch_assoc']($request); |
@@ -358,8 +368,7 @@ discard block |
||
| 358 | 368 | $context['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : ''; |
| 359 | 369 | $context['board'] = !empty($draft_info['id_board']) ? $draft_info['id_board'] : ''; |
| 360 | 370 | $context['id_draft'] = !empty($draft_info['id_draft']) ? $draft_info['id_draft'] : 0; |
| 361 | - } |
|
| 362 | - elseif ($type === 1) |
|
| 371 | + } elseif ($type === 1) |
|
| 363 | 372 | { |
| 364 | 373 | // one of those pm drafts? then set it up like we have an error |
| 365 | 374 | $_REQUEST['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : ''; |
@@ -395,12 +404,14 @@ discard block |
||
| 395 | 404 | global $user_info, $smcFunc; |
| 396 | 405 | |
| 397 | 406 | // Only a single draft. |
| 398 | - if (is_numeric($id_draft)) |
|
| 399 | - $id_draft = array($id_draft); |
|
| 407 | + if (is_numeric($id_draft)) { |
|
| 408 | + $id_draft = array($id_draft); |
|
| 409 | + } |
|
| 400 | 410 | |
| 401 | 411 | // can't delete nothing |
| 402 | - if (empty($id_draft) || ($check && empty($user_info['id']))) |
|
| 403 | - return false; |
|
| 412 | + if (empty($id_draft) || ($check && empty($user_info['id']))) { |
|
| 413 | + return false; |
|
| 414 | + } |
|
| 404 | 415 | |
| 405 | 416 | $smcFunc['db_query']('', ' |
| 406 | 417 | DELETE FROM {db_prefix}user_drafts |
@@ -429,14 +440,16 @@ discard block |
||
| 429 | 440 | global $smcFunc, $scripturl, $context, $txt, $modSettings; |
| 430 | 441 | |
| 431 | 442 | // Permissions |
| 432 | - if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) |
|
| 433 | - return false; |
|
| 443 | + if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) { |
|
| 444 | + return false; |
|
| 445 | + } |
|
| 434 | 446 | |
| 435 | 447 | $context['drafts'] = array(); |
| 436 | 448 | |
| 437 | 449 | // has a specific draft has been selected? Load it up if there is not a message already in the editor |
| 438 | - if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) |
|
| 439 | - ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true); |
|
| 450 | + if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) { |
|
| 451 | + ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true); |
|
| 452 | + } |
|
| 440 | 453 | |
| 441 | 454 | // load the drafts this user has available |
| 442 | 455 | $request = $smcFunc['db_query']('', ' |
@@ -459,8 +472,9 @@ discard block |
||
| 459 | 472 | // add them to the draft array for display |
| 460 | 473 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 461 | 474 | { |
| 462 | - if (empty($row['subject'])) |
|
| 463 | - $row['subject'] = $txt['no_subject']; |
|
| 475 | + if (empty($row['subject'])) { |
|
| 476 | + $row['subject'] = $txt['no_subject']; |
|
| 477 | + } |
|
| 464 | 478 | |
| 465 | 479 | // Post drafts |
| 466 | 480 | if ($draft_type === 0) |
@@ -545,8 +559,9 @@ discard block |
||
| 545 | 559 | } |
| 546 | 560 | |
| 547 | 561 | // Default to 10. |
| 548 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
| 549 | - $_REQUEST['viewscount'] = 10; |
|
| 562 | + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { |
|
| 563 | + $_REQUEST['viewscount'] = 10; |
|
| 564 | + } |
|
| 550 | 565 | |
| 551 | 566 | // Get the count of applicable drafts on the boards they can (still) see ... |
| 552 | 567 | // @todo .. should we just let them see their drafts even if they have lost board access ? |
@@ -611,12 +626,14 @@ discard block |
||
| 611 | 626 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 612 | 627 | { |
| 613 | 628 | // Censor.... |
| 614 | - if (empty($row['body'])) |
|
| 615 | - $row['body'] = ''; |
|
| 629 | + if (empty($row['body'])) { |
|
| 630 | + $row['body'] = ''; |
|
| 631 | + } |
|
| 616 | 632 | |
| 617 | 633 | $row['subject'] = $smcFunc['htmltrim']($row['subject']); |
| 618 | - if (empty($row['subject'])) |
|
| 619 | - $row['subject'] = $txt['no_subject']; |
|
| 634 | + if (empty($row['subject'])) { |
|
| 635 | + $row['subject'] = $txt['no_subject']; |
|
| 636 | + } |
|
| 620 | 637 | |
| 621 | 638 | censorText($row['body']); |
| 622 | 639 | censorText($row['subject']); |
@@ -648,8 +665,9 @@ discard block |
||
| 648 | 665 | $smcFunc['db_free_result']($request); |
| 649 | 666 | |
| 650 | 667 | // If the drafts were retrieved in reverse order, get them right again. |
| 651 | - if ($reverse) |
|
| 652 | - $context['drafts'] = array_reverse($context['drafts'], true); |
|
| 668 | + if ($reverse) { |
|
| 669 | + $context['drafts'] = array_reverse($context['drafts'], true); |
|
| 670 | + } |
|
| 653 | 671 | |
| 654 | 672 | // Menu tab |
| 655 | 673 | $context[$context['profile_menu_name']]['tab_data'] = array( |
@@ -707,8 +725,9 @@ discard block |
||
| 707 | 725 | } |
| 708 | 726 | |
| 709 | 727 | // Default to 10. |
| 710 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
| 711 | - $_REQUEST['viewscount'] = 10; |
|
| 728 | + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { |
|
| 729 | + $_REQUEST['viewscount'] = 10; |
|
| 730 | + } |
|
| 712 | 731 | |
| 713 | 732 | // Get the count of applicable drafts |
| 714 | 733 | $request = $smcFunc['db_query']('', ' |
@@ -767,12 +786,14 @@ discard block |
||
| 767 | 786 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 768 | 787 | { |
| 769 | 788 | // Censor.... |
| 770 | - if (empty($row['body'])) |
|
| 771 | - $row['body'] = ''; |
|
| 789 | + if (empty($row['body'])) { |
|
| 790 | + $row['body'] = ''; |
|
| 791 | + } |
|
| 772 | 792 | |
| 773 | 793 | $row['subject'] = $smcFunc['htmltrim']($row['subject']); |
| 774 | - if (empty($row['subject'])) |
|
| 775 | - $row['subject'] = $txt['no_subject']; |
|
| 794 | + if (empty($row['subject'])) { |
|
| 795 | + $row['subject'] = $txt['no_subject']; |
|
| 796 | + } |
|
| 776 | 797 | |
| 777 | 798 | censorText($row['body']); |
| 778 | 799 | censorText($row['subject']); |
@@ -827,8 +848,9 @@ discard block |
||
| 827 | 848 | $smcFunc['db_free_result']($request); |
| 828 | 849 | |
| 829 | 850 | // if the drafts were retrieved in reverse order, then put them in the right order again. |
| 830 | - if ($reverse) |
|
| 831 | - $context['drafts'] = array_reverse($context['drafts'], true); |
|
| 851 | + if ($reverse) { |
|
| 852 | + $context['drafts'] = array_reverse($context['drafts'], true); |
|
| 853 | + } |
|
| 832 | 854 | |
| 833 | 855 | // off to the template we go |
| 834 | 856 | $context['page_title'] = $txt['drafts']; |
@@ -474,7 +474,7 @@ |
||
| 474 | 474 | * Used by fatal_error(), fatal_lang_error() |
| 475 | 475 | * |
| 476 | 476 | * @param string $error The error |
| 477 | - * @param array $sprintf An array of data to be sprintf()'d into the specified message |
|
| 477 | + * @param boolean $sprintf An array of data to be sprintf()'d into the specified message |
|
| 478 | 478 | */ |
| 479 | 479 | function log_error_online($error, $sprintf = array()) |
| 480 | 480 | { |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * @version 2.1 Beta 3 |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -if (!defined('SMF')) |
|
| 18 | +if (!defined('SMF')) { |
|
| 19 | 19 | die('No direct access...'); |
| 20 | +} |
|
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * Log an error, if the error logging is enabled. |
@@ -36,8 +37,9 @@ discard block |
||
| 36 | 37 | static $tried_hook = false; |
| 37 | 38 | |
| 38 | 39 | // Check if error logging is actually on. |
| 39 | - if (empty($modSettings['enableErrorLogging'])) |
|
| 40 | - return $error_message; |
|
| 40 | + if (empty($modSettings['enableErrorLogging'])) { |
|
| 41 | + return $error_message; |
|
| 42 | + } |
|
| 41 | 43 | |
| 42 | 44 | // Basically, htmlspecialchars it minus &. (for entities!) |
| 43 | 45 | $error_message = strtr($error_message, array('<' => '<', '>' => '>', '"' => '"')); |
@@ -45,22 +47,26 @@ discard block |
||
| 45 | 47 | |
| 46 | 48 | // Add a file and line to the error message? |
| 47 | 49 | // Don't use the actual txt entries for file and line but instead use %1$s for file and %2$s for line |
| 48 | - if ($file == null) |
|
| 49 | - $file = ''; |
|
| 50 | - else |
|
| 51 | - // Window style slashes don't play well, lets convert them to the unix style. |
|
| 50 | + if ($file == null) { |
|
| 51 | + $file = ''; |
|
| 52 | + } else { |
|
| 53 | + // Window style slashes don't play well, lets convert them to the unix style. |
|
| 52 | 54 | $file = str_replace('\\', '/', $file); |
| 55 | + } |
|
| 53 | 56 | |
| 54 | - if ($line == null) |
|
| 55 | - $line = 0; |
|
| 56 | - else |
|
| 57 | - $line = (int) $line; |
|
| 57 | + if ($line == null) { |
|
| 58 | + $line = 0; |
|
| 59 | + } else { |
|
| 60 | + $line = (int) $line; |
|
| 61 | + } |
|
| 58 | 62 | |
| 59 | 63 | // Just in case there's no id_member or IP set yet. |
| 60 | - if (empty($user_info['id'])) |
|
| 61 | - $user_info['id'] = 0; |
|
| 62 | - if (empty($user_info['ip'])) |
|
| 63 | - $user_info['ip'] = ''; |
|
| 64 | + if (empty($user_info['id'])) { |
|
| 65 | + $user_info['id'] = 0; |
|
| 66 | + } |
|
| 67 | + if (empty($user_info['ip'])) { |
|
| 68 | + $user_info['ip'] = ''; |
|
| 69 | + } |
|
| 64 | 70 | |
| 65 | 71 | // Find the best query string we can... |
| 66 | 72 | $query_string = empty($_SERVER['QUERY_STRING']) ? (empty($_SERVER['REQUEST_URL']) ? '' : str_replace($scripturl, '', $_SERVER['REQUEST_URL'])) : $_SERVER['QUERY_STRING']; |
@@ -69,8 +75,9 @@ discard block |
||
| 69 | 75 | $query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string)); |
| 70 | 76 | |
| 71 | 77 | // Just so we know what board error messages are from. |
| 72 | - if (isset($_POST['board']) && !isset($_GET['board'])) |
|
| 73 | - $query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board']; |
|
| 78 | + if (isset($_POST['board']) && !isset($_GET['board'])) { |
|
| 79 | + $query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board']; |
|
| 80 | + } |
|
| 74 | 81 | |
| 75 | 82 | // What types of categories do we have? |
| 76 | 83 | $known_error_types = array( |
@@ -132,12 +139,14 @@ discard block |
||
| 132 | 139 | global $txt; |
| 133 | 140 | |
| 134 | 141 | // Send the appropriate HTTP status header - set this to 0 or false if you don't want to send one at all |
| 135 | - if (!empty($status)) |
|
| 136 | - send_http_status($status); |
|
| 142 | + if (!empty($status)) { |
|
| 143 | + send_http_status($status); |
|
| 144 | + } |
|
| 137 | 145 | |
| 138 | 146 | // We don't have $txt yet, but that's okay... |
| 139 | - if (empty($txt)) |
|
| 140 | - die($error); |
|
| 147 | + if (empty($txt)) { |
|
| 148 | + die($error); |
|
| 149 | + } |
|
| 141 | 150 | |
| 142 | 151 | log_error_online($error, false); |
| 143 | 152 | setup_fatal_error_context($log ? log_error($error, $log) : $error); |
@@ -164,8 +173,9 @@ discard block |
||
| 164 | 173 | static $fatal_error_called = false; |
| 165 | 174 | |
| 166 | 175 | // Send the status header - set this to 0 or false if you don't want to send one at all |
| 167 | - if (!empty($status)) |
|
| 168 | - send_http_status($status); |
|
| 176 | + if (!empty($status)) { |
|
| 177 | + send_http_status($status); |
|
| 178 | + } |
|
| 169 | 179 | |
| 170 | 180 | // Try to load a theme if we don't have one. |
| 171 | 181 | if (empty($context['theme_loaded']) && empty($fatal_error_called)) |
@@ -175,8 +185,9 @@ discard block |
||
| 175 | 185 | } |
| 176 | 186 | |
| 177 | 187 | // If we have no theme stuff we can't have the language file... |
| 178 | - if (empty($context['theme_loaded'])) |
|
| 179 | - die($error); |
|
| 188 | + if (empty($context['theme_loaded'])) { |
|
| 189 | + die($error); |
|
| 190 | + } |
|
| 180 | 191 | |
| 181 | 192 | $reload_lang_file = true; |
| 182 | 193 | // Log the error in the forum's language, but don't waste the time if we aren't logging |
@@ -212,27 +223,31 @@ discard block |
||
| 212 | 223 | global $settings, $modSettings, $db_show_debug; |
| 213 | 224 | |
| 214 | 225 | // Ignore errors if we're ignoring them or they are strict notices from PHP 5 (which cannot be solved without breaking PHP 4.) |
| 215 | - if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging']))) |
|
| 216 | - return; |
|
| 226 | + if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging']))) { |
|
| 227 | + return; |
|
| 228 | + } |
|
| 217 | 229 | |
| 218 | 230 | if (strpos($file, 'eval()') !== false && !empty($settings['current_include_filename'])) |
| 219 | 231 | { |
| 220 | 232 | $array = debug_backtrace(); |
| 221 | 233 | for ($i = 0; $i < count($array); $i++) |
| 222 | 234 | { |
| 223 | - if ($array[$i]['function'] != 'loadSubTemplate') |
|
| 224 | - continue; |
|
| 235 | + if ($array[$i]['function'] != 'loadSubTemplate') { |
|
| 236 | + continue; |
|
| 237 | + } |
|
| 225 | 238 | |
| 226 | 239 | // This is a bug in PHP, with eval, it seems! |
| 227 | - if (empty($array[$i]['args'])) |
|
| 228 | - $i++; |
|
| 240 | + if (empty($array[$i]['args'])) { |
|
| 241 | + $i++; |
|
| 242 | + } |
|
| 229 | 243 | break; |
| 230 | 244 | } |
| 231 | 245 | |
| 232 | - if (isset($array[$i]) && !empty($array[$i]['args'])) |
|
| 233 | - $file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)'; |
|
| 234 | - else |
|
| 235 | - $file = realpath($settings['current_include_filename']) . ' (eval?)'; |
|
| 246 | + if (isset($array[$i]) && !empty($array[$i]['args'])) { |
|
| 247 | + $file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)'; |
|
| 248 | + } else { |
|
| 249 | + $file = realpath($settings['current_include_filename']) . ' (eval?)'; |
|
| 250 | + } |
|
| 236 | 251 | } |
| 237 | 252 | |
| 238 | 253 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -241,8 +256,9 @@ discard block |
||
| 241 | 256 | if ($error_level % 255 != E_ERROR) |
| 242 | 257 | { |
| 243 | 258 | $temporary = ob_get_contents(); |
| 244 | - if (substr($temporary, -2) == '="') |
|
| 245 | - echo '"'; |
|
| 259 | + if (substr($temporary, -2) == '="') { |
|
| 260 | + echo '"'; |
|
| 261 | + } |
|
| 246 | 262 | } |
| 247 | 263 | |
| 248 | 264 | // Debugging! This should look like a PHP error message. |
@@ -258,23 +274,27 @@ discard block |
||
| 258 | 274 | call_integration_hook('integrate_output_error', array($message, $error_type, $error_level, $file, $line)); |
| 259 | 275 | |
| 260 | 276 | // Dying on these errors only causes MORE problems (blank pages!) |
| 261 | - if ($file == 'Unknown') |
|
| 262 | - return; |
|
| 277 | + if ($file == 'Unknown') { |
|
| 278 | + return; |
|
| 279 | + } |
|
| 263 | 280 | |
| 264 | 281 | // If this is an E_ERROR or E_USER_ERROR.... die. Violently so. |
| 265 | - if ($error_level % 255 == E_ERROR) |
|
| 266 | - obExit(false); |
|
| 267 | - else |
|
| 268 | - return; |
|
| 282 | + if ($error_level % 255 == E_ERROR) { |
|
| 283 | + obExit(false); |
|
| 284 | + } else { |
|
| 285 | + return; |
|
| 286 | + } |
|
| 269 | 287 | |
| 270 | 288 | // If this is an E_ERROR, E_USER_ERROR, E_WARNING, or E_USER_WARNING.... die. Violently so. |
| 271 | - if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) |
|
| 272 | - fatal_error(allowedTo('admin_forum') ? $message : $error_string, false); |
|
| 289 | + if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) { |
|
| 290 | + fatal_error(allowedTo('admin_forum') ? $message : $error_string, false); |
|
| 291 | + } |
|
| 273 | 292 | |
| 274 | 293 | // We should NEVER get to this point. Any fatal error MUST quit, or very bad things can happen. |
| 275 | - if ($error_level % 255 == E_ERROR) |
|
| 276 | - die('No direct access...'); |
|
| 277 | -} |
|
| 294 | + if ($error_level % 255 == E_ERROR) { |
|
| 295 | + die('No direct access...'); |
|
| 296 | + } |
|
| 297 | + } |
|
| 278 | 298 | |
| 279 | 299 | /** |
| 280 | 300 | * It is called by {@link fatal_error()} and {@link fatal_lang_error()}. |
@@ -290,24 +310,28 @@ discard block |
||
| 290 | 310 | |
| 291 | 311 | // Attempt to prevent a recursive loop. |
| 292 | 312 | ++$level; |
| 293 | - if ($level > 1) |
|
| 294 | - return false; |
|
| 313 | + if ($level > 1) { |
|
| 314 | + return false; |
|
| 315 | + } |
|
| 295 | 316 | |
| 296 | 317 | // Maybe they came from dlattach or similar? |
| 297 | - if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) |
|
| 298 | - loadTheme(); |
|
| 318 | + if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) { |
|
| 319 | + loadTheme(); |
|
| 320 | + } |
|
| 299 | 321 | |
| 300 | 322 | // Don't bother indexing errors mate... |
| 301 | 323 | $context['robot_no_index'] = true; |
| 302 | 324 | |
| 303 | - if (!isset($context['error_title'])) |
|
| 304 | - $context['error_title'] = $txt['error_occured']; |
|
| 325 | + if (!isset($context['error_title'])) { |
|
| 326 | + $context['error_title'] = $txt['error_occured']; |
|
| 327 | + } |
|
| 305 | 328 | $context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message; |
| 306 | 329 | |
| 307 | 330 | $context['error_code'] = isset($error_code) ? 'id="' . $error_code . '" ' : ''; |
| 308 | 331 | |
| 309 | - if (empty($context['page_title'])) |
|
| 310 | - $context['page_title'] = $context['error_title']; |
|
| 332 | + if (empty($context['page_title'])) { |
|
| 333 | + $context['page_title'] = $context['error_title']; |
|
| 334 | + } |
|
| 311 | 335 | |
| 312 | 336 | loadTemplate('Errors'); |
| 313 | 337 | $context['sub_template'] = 'fatal_error'; |
@@ -315,23 +339,26 @@ discard block |
||
| 315 | 339 | // If this is SSI, what do they want us to do? |
| 316 | 340 | if (SMF == 'SSI') |
| 317 | 341 | { |
| 318 | - if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) |
|
| 319 | - $ssi_on_error_method(); |
|
| 320 | - elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) |
|
| 321 | - loadSubTemplate('fatal_error'); |
|
| 342 | + if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) { |
|
| 343 | + $ssi_on_error_method(); |
|
| 344 | + } elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) { |
|
| 345 | + loadSubTemplate('fatal_error'); |
|
| 346 | + } |
|
| 322 | 347 | |
| 323 | 348 | // No layers? |
| 324 | - if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) |
|
| 325 | - exit; |
|
| 349 | + if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) { |
|
| 350 | + exit; |
|
| 351 | + } |
|
| 326 | 352 | } |
| 327 | 353 | // Alternatively from the cron call? |
| 328 | 354 | elseif (SMF == 'BACKGROUND') |
| 329 | 355 | { |
| 330 | 356 | // We can't rely on even having language files available. |
| 331 | - if (defined('FROM_CLI') && FROM_CLI) |
|
| 332 | - echo 'cron error: ', $context['error_message']; |
|
| 333 | - else |
|
| 334 | - echo 'An error occurred. More information may be available in your logs.'; |
|
| 357 | + if (defined('FROM_CLI') && FROM_CLI) { |
|
| 358 | + echo 'cron error: ', $context['error_message']; |
|
| 359 | + } else { |
|
| 360 | + echo 'An error occurred. More information may be available in your logs.'; |
|
| 361 | + } |
|
| 335 | 362 | exit; |
| 336 | 363 | } |
| 337 | 364 | |
@@ -359,8 +386,8 @@ discard block |
||
| 359 | 386 | |
| 360 | 387 | set_fatal_error_headers(); |
| 361 | 388 | |
| 362 | - if (!empty($maintenance)) |
|
| 363 | - echo '<!DOCTYPE html> |
|
| 389 | + if (!empty($maintenance)) { |
|
| 390 | + echo '<!DOCTYPE html> |
|
| 364 | 391 | <html> |
| 365 | 392 | <head> |
| 366 | 393 | <meta name="robots" content="noindex"> |
@@ -371,6 +398,7 @@ discard block |
||
| 371 | 398 | ', $mmessage, ' |
| 372 | 399 | </body> |
| 373 | 400 | </html>'; |
| 401 | + } |
|
| 374 | 402 | |
| 375 | 403 | die(); |
| 376 | 404 | } |
@@ -392,15 +420,17 @@ discard block |
||
| 392 | 420 | // For our purposes, we're gonna want this on if at all possible. |
| 393 | 421 | $modSettings['cache_enable'] = '1'; |
| 394 | 422 | |
| 395 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
| 396 | - $db_last_error = max($db_last_error, $temp); |
|
| 423 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
| 424 | + $db_last_error = max($db_last_error, $temp); |
|
| 425 | + } |
|
| 397 | 426 | |
| 398 | 427 | if ($db_last_error < time() - 3600 * 24 * 3 && empty($maintenance) && !empty($db_error_send)) |
| 399 | 428 | { |
| 400 | 429 | // Avoid writing to the Settings.php file if at all possible; use shared memory instead. |
| 401 | 430 | cache_put_data('db_last_error', time(), 600); |
| 402 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
| 403 | - logLastDatabaseError(); |
|
| 431 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
| 432 | + logLastDatabaseError(); |
|
| 433 | + } |
|
| 404 | 434 | |
| 405 | 435 | // Language files aren't loaded yet :(. |
| 406 | 436 | $db_error = @$smcFunc['db_error']($db_connection); |
@@ -481,12 +511,14 @@ discard block |
||
| 481 | 511 | global $smcFunc, $user_info, $modSettings; |
| 482 | 512 | |
| 483 | 513 | // Don't bother if Who's Online is disabled. |
| 484 | - if (empty($modSettings['who_enabled'])) |
|
| 485 | - return; |
|
| 514 | + if (empty($modSettings['who_enabled'])) { |
|
| 515 | + return; |
|
| 516 | + } |
|
| 486 | 517 | |
| 487 | 518 | // Maybe they came from SSI or similar where sessions are not recorded? |
| 488 | - if (SMF == 'SSI' || SMF == 'BACKGROUND') |
|
| 489 | - return; |
|
| 519 | + if (SMF == 'SSI' || SMF == 'BACKGROUND') { |
|
| 520 | + return; |
|
| 521 | + } |
|
| 490 | 522 | |
| 491 | 523 | $session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id(); |
| 492 | 524 | |
@@ -505,8 +537,9 @@ discard block |
||
| 505 | 537 | $url = smf_json_decode($url, true); |
| 506 | 538 | $url['error'] = $error; |
| 507 | 539 | |
| 508 | - if (!empty($sprintf)) |
|
| 509 | - $url['error_params'] = $sprintf; |
|
| 540 | + if (!empty($sprintf)) { |
|
| 541 | + $url['error_params'] = $sprintf; |
|
| 542 | + } |
|
| 510 | 543 | |
| 511 | 544 | $smcFunc['db_query']('', ' |
| 512 | 545 | UPDATE {db_prefix}log_online |
@@ -537,10 +570,11 @@ discard block |
||
| 537 | 570 | |
| 538 | 571 | $protocol = preg_match('~HTTP/1\.[01]~i', $_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'; |
| 539 | 572 | |
| 540 | - if (!isset($statuses[$code])) |
|
| 541 | - header($protocol . ' 500 Internal Server Error'); |
|
| 542 | - else |
|
| 543 | - header($protocol . ' ' . $code . ' ' . $statuses[$code]); |
|
| 544 | -} |
|
| 573 | + if (!isset($statuses[$code])) { |
|
| 574 | + header($protocol . ' 500 Internal Server Error'); |
|
| 575 | + } else { |
|
| 576 | + header($protocol . ' ' . $code . ' ' . $statuses[$code]); |
|
| 577 | + } |
|
| 578 | + } |
|
| 545 | 579 | |
| 546 | 580 | ?> |
| 547 | 581 | \ No newline at end of file |
@@ -2238,9 +2238,9 @@ discard block |
||
| 2238 | 2238 | * |
| 2239 | 2239 | * @uses the template_include() function to include the file. |
| 2240 | 2240 | * @param string $template_name The name of the template to load |
| 2241 | - * @param array|string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load |
|
| 2241 | + * @param string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load |
|
| 2242 | 2242 | * @param bool $fatal If true, dies with an error message if the template cannot be found |
| 2243 | - * @return boolean Whether or not the template was loaded |
|
| 2243 | + * @return boolean|null Whether or not the template was loaded |
|
| 2244 | 2244 | */ |
| 2245 | 2245 | function loadTemplate($template_name, $style_sheets = array(), $fatal = true) |
| 2246 | 2246 | { |
@@ -2424,7 +2424,7 @@ discard block |
||
| 2424 | 2424 | * - all code added with this function is added to the same <style> tag so do make sure your css is valid! |
| 2425 | 2425 | * |
| 2426 | 2426 | * @param string $css Some css code |
| 2427 | - * @return void|bool Adds the CSS to the $context['css_header'] array or returns if no CSS is specified |
|
| 2427 | + * @return false|null Adds the CSS to the $context['css_header'] array or returns if no CSS is specified |
|
| 2428 | 2428 | */ |
| 2429 | 2429 | function addInlineCss($css) |
| 2430 | 2430 | { |
@@ -2440,7 +2440,7 @@ discard block |
||
| 2440 | 2440 | /** |
| 2441 | 2441 | * Add a Javascript file for output later |
| 2442 | 2442 | |
| 2443 | - * @param string $filename The name of the file to load |
|
| 2443 | + * @param string $fileName The name of the file to load |
|
| 2444 | 2444 | * @param array $params An array of parameter info |
| 2445 | 2445 | * Keys are the following: |
| 2446 | 2446 | * - ['external'] (true/false): define if the file is a externally located file. Needs to be set to true if you are loading an external file |
@@ -2538,7 +2538,7 @@ discard block |
||
| 2538 | 2538 | * |
| 2539 | 2539 | * @param string $javascript Some JS code |
| 2540 | 2540 | * @param bool $defer Whether the script should load in <head> or before the closing <html> tag |
| 2541 | - * @return void|bool Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified |
|
| 2541 | + * @return false|null Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified |
|
| 2542 | 2542 | */ |
| 2543 | 2543 | function addInlineJavaScript($javascript, $defer = false) |
| 2544 | 2544 | { |
@@ -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,23 +223,25 @@ 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']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
|
| 225 | - date_default_timezone_set($modSettings['default_timezone']); |
|
| 226 | - else |
|
| 234 | + if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) { |
|
| 235 | + date_default_timezone_set($modSettings['default_timezone']); |
|
| 236 | + } else |
|
| 227 | 237 | { |
| 228 | 238 | // Get PHP's default timezone, if set |
| 229 | 239 | $ini_tz = ini_get('date.timezone'); |
| 230 | - if (!empty($ini_tz)) |
|
| 231 | - $modSettings['default_timezone'] = $ini_tz; |
|
| 232 | - else |
|
| 233 | - $modSettings['default_timezone'] = ''; |
|
| 240 | + if (!empty($ini_tz)) { |
|
| 241 | + $modSettings['default_timezone'] = $ini_tz; |
|
| 242 | + } else { |
|
| 243 | + $modSettings['default_timezone'] = ''; |
|
| 244 | + } |
|
| 234 | 245 | |
| 235 | 246 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
| 236 | 247 | if (!in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
@@ -248,22 +259,26 @@ discard block |
||
| 248 | 259 | if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null) |
| 249 | 260 | { |
| 250 | 261 | $modSettings['load_average'] = @file_get_contents('/proc/loadavg'); |
| 251 | - if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) |
|
| 252 | - $modSettings['load_average'] = (float) $matches[1]; |
|
| 253 | - elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) |
|
| 254 | - $modSettings['load_average'] = (float) $matches[1]; |
|
| 255 | - else |
|
| 256 | - unset($modSettings['load_average']); |
|
| 262 | + if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) { |
|
| 263 | + $modSettings['load_average'] = (float) $matches[1]; |
|
| 264 | + } elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) { |
|
| 265 | + $modSettings['load_average'] = (float) $matches[1]; |
|
| 266 | + } else { |
|
| 267 | + unset($modSettings['load_average']); |
|
| 268 | + } |
|
| 257 | 269 | |
| 258 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
| 259 | - cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
| 270 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
| 271 | + cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
| 272 | + } |
|
| 260 | 273 | } |
| 261 | 274 | |
| 262 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
| 263 | - call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
| 275 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
| 276 | + call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
| 277 | + } |
|
| 264 | 278 | |
| 265 | - if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) |
|
| 266 | - display_loadavg_error(); |
|
| 279 | + if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) { |
|
| 280 | + display_loadavg_error(); |
|
| 281 | + } |
|
| 267 | 282 | } |
| 268 | 283 | |
| 269 | 284 | // Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is. |
@@ -284,8 +299,9 @@ discard block |
||
| 284 | 299 | if (defined('SMF_INTEGRATION_SETTINGS')) |
| 285 | 300 | { |
| 286 | 301 | $integration_settings = smf_json_decode(SMF_INTEGRATION_SETTINGS, true); |
| 287 | - foreach ($integration_settings as $hook => $function) |
|
| 288 | - add_integration_function($hook, $function, '', false); |
|
| 302 | + foreach ($integration_settings as $hook => $function) { |
|
| 303 | + add_integration_function($hook, $function, '', false); |
|
| 304 | + } |
|
| 289 | 305 | } |
| 290 | 306 | |
| 291 | 307 | // Any files to pre include? |
@@ -295,8 +311,9 @@ discard block |
||
| 295 | 311 | foreach ($pre_includes as $include) |
| 296 | 312 | { |
| 297 | 313 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
| 298 | - if (file_exists($include)) |
|
| 299 | - require_once($include); |
|
| 314 | + if (file_exists($include)) { |
|
| 315 | + require_once($include); |
|
| 316 | + } |
|
| 300 | 317 | } |
| 301 | 318 | } |
| 302 | 319 | |
@@ -400,27 +417,28 @@ discard block |
||
| 400 | 417 | break; |
| 401 | 418 | } |
| 402 | 419 | } |
| 420 | + } else { |
|
| 421 | + $id_member = 0; |
|
| 403 | 422 | } |
| 404 | - else |
|
| 405 | - $id_member = 0; |
|
| 406 | 423 | |
| 407 | 424 | if (empty($id_member) && isset($_COOKIE[$cookiename])) |
| 408 | 425 | { |
| 409 | 426 | $cookie_data = smf_json_decode($_COOKIE[$cookiename], true, false); |
| 410 | 427 | |
| 411 | - if (empty($cookie_data)) |
|
| 412 | - $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
| 428 | + if (empty($cookie_data)) { |
|
| 429 | + $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
| 430 | + } |
|
| 413 | 431 | |
| 414 | 432 | list ($id_member, $password) = $cookie_data; |
| 415 | 433 | $id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0; |
| 416 | - } |
|
| 417 | - elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
| 434 | + } elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
| 418 | 435 | { |
| 419 | 436 | // @todo Perhaps we can do some more checking on this, such as on the first octet of the IP? |
| 420 | 437 | $cookie_data = smf_json_decode($_SESSION['login_' . $cookiename]); |
| 421 | 438 | |
| 422 | - if (empty($cookie_data)) |
|
| 423 | - $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 439 | + if (empty($cookie_data)) { |
|
| 440 | + $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 441 | + } |
|
| 424 | 442 | |
| 425 | 443 | list ($id_member, $password, $login_span) = $cookie_data; |
| 426 | 444 | $id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0; |
@@ -445,30 +463,34 @@ discard block |
||
| 445 | 463 | $user_settings = $smcFunc['db_fetch_assoc']($request); |
| 446 | 464 | $smcFunc['db_free_result']($request); |
| 447 | 465 | |
| 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); |
|
| 466 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) { |
|
| 467 | + $user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret); |
|
| 468 | + } |
|
| 450 | 469 | |
| 451 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 452 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 470 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 471 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 472 | + } |
|
| 453 | 473 | } |
| 454 | 474 | |
| 455 | 475 | // Did we find 'im? If not, junk it. |
| 456 | 476 | if (!empty($user_settings)) |
| 457 | 477 | { |
| 458 | 478 | // As much as the password should be right, we can assume the integration set things up. |
| 459 | - if (!empty($already_verified) && $already_verified === true) |
|
| 460 | - $check = true; |
|
| 479 | + if (!empty($already_verified) && $already_verified === true) { |
|
| 480 | + $check = true; |
|
| 481 | + } |
|
| 461 | 482 | // SHA-512 hash should be 128 characters long. |
| 462 | - elseif (strlen($password) == 128) |
|
| 463 | - $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
| 464 | - else |
|
| 465 | - $check = false; |
|
| 483 | + elseif (strlen($password) == 128) { |
|
| 484 | + $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
| 485 | + } else { |
|
| 486 | + $check = false; |
|
| 487 | + } |
|
| 466 | 488 | |
| 467 | 489 | // Wrong password or not activated - either way, you're going nowhere. |
| 468 | 490 | $id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0; |
| 491 | + } else { |
|
| 492 | + $id_member = 0; |
|
| 469 | 493 | } |
| 470 | - else |
|
| 471 | - $id_member = 0; |
|
| 472 | 494 | |
| 473 | 495 | // If we no longer have the member maybe they're being all hackey, stop brute force! |
| 474 | 496 | if (!$id_member) |
@@ -490,13 +512,15 @@ discard block |
||
| 490 | 512 | { |
| 491 | 513 | $tfa_data = smf_json_decode($_COOKIE[$tfacookie]); |
| 492 | 514 | |
| 493 | - if (is_null($tfa_data)) |
|
| 494 | - $tfa_data = safe_unserialize($_COOKIE[$tfacookie]); |
|
| 515 | + if (is_null($tfa_data)) { |
|
| 516 | + $tfa_data = safe_unserialize($_COOKIE[$tfacookie]); |
|
| 517 | + } |
|
| 495 | 518 | |
| 496 | 519 | list ($tfamember, $tfasecret) = $tfa_data; |
| 497 | 520 | |
| 498 | - if ((int) $tfamember != $id_member) |
|
| 499 | - $tfasecret = null; |
|
| 521 | + if ((int) $tfamember != $id_member) { |
|
| 522 | + $tfasecret = null; |
|
| 523 | + } |
|
| 500 | 524 | } |
| 501 | 525 | |
| 502 | 526 | if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret) |
@@ -516,10 +540,12 @@ discard block |
||
| 516 | 540 | // Are we forcing 2FA? Need to check if the user groups actually require 2FA |
| 517 | 541 | elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret'])) |
| 518 | 542 | { |
| 519 | - if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups |
|
| 543 | + if ($modSettings['tfa_mode'] == 2) { |
|
| 544 | + //only do this if we are just forcing SOME membergroups |
|
| 520 | 545 | { |
| 521 | 546 | //Build an array of ALL user membergroups. |
| 522 | 547 | $full_groups = array($user_settings['id_group']); |
| 548 | + } |
|
| 523 | 549 | if (!empty($user_settings['additional_groups'])) |
| 524 | 550 | { |
| 525 | 551 | $full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups'])); |
@@ -539,15 +565,17 @@ discard block |
||
| 539 | 565 | ); |
| 540 | 566 | $row = $smcFunc['db_fetch_assoc']($request); |
| 541 | 567 | $smcFunc['db_free_result']($request); |
| 568 | + } else { |
|
| 569 | + $row['total'] = 1; |
|
| 542 | 570 | } |
| 543 | - else |
|
| 544 | - $row['total'] = 1; //simplifies logics in the next "if" |
|
| 571 | + //simplifies logics in the next "if" |
|
| 545 | 572 | |
| 546 | 573 | $area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : ''; |
| 547 | 574 | $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : ''; |
| 548 | 575 | |
| 549 | - if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) |
|
| 550 | - redirectexit('action=profile;area=tfasetup;forced'); |
|
| 576 | + if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) { |
|
| 577 | + redirectexit('action=profile;area=tfasetup;forced'); |
|
| 578 | + } |
|
| 551 | 579 | } |
| 552 | 580 | } |
| 553 | 581 | |
@@ -584,33 +612,37 @@ discard block |
||
| 584 | 612 | 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'])); |
| 585 | 613 | $user_settings['last_login'] = time(); |
| 586 | 614 | |
| 587 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 588 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 615 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 616 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 617 | + } |
|
| 589 | 618 | |
| 590 | - if (!empty($modSettings['cache_enable'])) |
|
| 591 | - cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
| 619 | + if (!empty($modSettings['cache_enable'])) { |
|
| 620 | + cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
| 621 | + } |
|
| 592 | 622 | } |
| 623 | + } elseif (empty($_SESSION['id_msg_last_visit'])) { |
|
| 624 | + $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
| 593 | 625 | } |
| 594 | - elseif (empty($_SESSION['id_msg_last_visit'])) |
|
| 595 | - $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
| 596 | 626 | |
| 597 | 627 | $username = $user_settings['member_name']; |
| 598 | 628 | |
| 599 | - if (empty($user_settings['additional_groups'])) |
|
| 600 | - $user_info = array( |
|
| 629 | + if (empty($user_settings['additional_groups'])) { |
|
| 630 | + $user_info = array( |
|
| 601 | 631 | 'groups' => array($user_settings['id_group'], $user_settings['id_post_group']) |
| 602 | 632 | ); |
| 603 | - else |
|
| 604 | - $user_info = array( |
|
| 633 | + } else { |
|
| 634 | + $user_info = array( |
|
| 605 | 635 | 'groups' => array_merge( |
| 606 | 636 | array($user_settings['id_group'], $user_settings['id_post_group']), |
| 607 | 637 | explode(',', $user_settings['additional_groups']) |
| 608 | 638 | ) |
| 609 | 639 | ); |
| 640 | + } |
|
| 610 | 641 | |
| 611 | 642 | // Because history has proven that it is possible for groups to go bad - clean up in case. |
| 612 | - foreach ($user_info['groups'] as $k => $v) |
|
| 613 | - $user_info['groups'][$k] = (int) $v; |
|
| 643 | + foreach ($user_info['groups'] as $k => $v) { |
|
| 644 | + $user_info['groups'][$k] = (int) $v; |
|
| 645 | + } |
|
| 614 | 646 | |
| 615 | 647 | // This is a logged in user, so definitely not a spider. |
| 616 | 648 | $user_info['possibly_robot'] = false; |
@@ -624,8 +656,7 @@ discard block |
||
| 624 | 656 | $time_system = new DateTime('now', $tz_system); |
| 625 | 657 | $time_user = new DateTime('now', $tz_user); |
| 626 | 658 | $user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600; |
| 627 | - } |
|
| 628 | - else |
|
| 659 | + } else |
|
| 629 | 660 | { |
| 630 | 661 | // !!! Compatibility. |
| 631 | 662 | $user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset']; |
@@ -639,16 +670,18 @@ discard block |
||
| 639 | 670 | $user_info = array('groups' => array(-1)); |
| 640 | 671 | $user_settings = array(); |
| 641 | 672 | |
| 642 | - if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) |
|
| 643 | - $_COOKIE[$cookiename] = ''; |
|
| 673 | + if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) { |
|
| 674 | + $_COOKIE[$cookiename] = ''; |
|
| 675 | + } |
|
| 644 | 676 | |
| 645 | 677 | // Expire the 2FA cookie |
| 646 | 678 | if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member'])) |
| 647 | 679 | { |
| 648 | 680 | $tfa_data = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true); |
| 649 | 681 | |
| 650 | - if (is_null($tfa_data)) |
|
| 651 | - $tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']); |
|
| 682 | + if (is_null($tfa_data)) { |
|
| 683 | + $tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']); |
|
| 684 | + } |
|
| 652 | 685 | |
| 653 | 686 | list ($id, $user, $exp, $state, $preserve) = $tfa_data; |
| 654 | 687 | |
@@ -660,19 +693,20 @@ discard block |
||
| 660 | 693 | } |
| 661 | 694 | |
| 662 | 695 | // Create a login token if it doesn't exist yet. |
| 663 | - if (!isset($_SESSION['token']['post-login'])) |
|
| 664 | - createToken('login'); |
|
| 665 | - else |
|
| 666 | - list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
| 696 | + if (!isset($_SESSION['token']['post-login'])) { |
|
| 697 | + createToken('login'); |
|
| 698 | + } else { |
|
| 699 | + list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
| 700 | + } |
|
| 667 | 701 | |
| 668 | 702 | // Do we perhaps think this is a search robot? Check every five minutes just in case... |
| 669 | 703 | if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300)) |
| 670 | 704 | { |
| 671 | 705 | require_once($sourcedir . '/ManageSearchEngines.php'); |
| 672 | 706 | $user_info['possibly_robot'] = SpiderCheck(); |
| 707 | + } elseif (!empty($modSettings['spider_mode'])) { |
|
| 708 | + $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
| 673 | 709 | } |
| 674 | - elseif (!empty($modSettings['spider_mode'])) |
|
| 675 | - $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
| 676 | 710 | // If we haven't turned on proper spider hunts then have a guess! |
| 677 | 711 | else |
| 678 | 712 | { |
@@ -720,8 +754,9 @@ discard block |
||
| 720 | 754 | $user_info['groups'] = array_unique($user_info['groups']); |
| 721 | 755 | |
| 722 | 756 | // 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. |
| 723 | - if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) |
|
| 724 | - unset($user_info['ignoreboards'][$tmp]); |
|
| 757 | + if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) { |
|
| 758 | + unset($user_info['ignoreboards'][$tmp]); |
|
| 759 | + } |
|
| 725 | 760 | |
| 726 | 761 | // Allow the user to change their language. |
| 727 | 762 | if (!empty($modSettings['userLanguage'])) |
@@ -734,31 +769,36 @@ discard block |
||
| 734 | 769 | $user_info['language'] = strtr($_GET['language'], './\\:', '____'); |
| 735 | 770 | |
| 736 | 771 | // Make it permanent for members. |
| 737 | - if (!empty($user_info['id'])) |
|
| 738 | - updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
| 739 | - else |
|
| 740 | - $_SESSION['language'] = $user_info['language']; |
|
| 772 | + if (!empty($user_info['id'])) { |
|
| 773 | + updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
| 774 | + } else { |
|
| 775 | + $_SESSION['language'] = $user_info['language']; |
|
| 776 | + } |
|
| 777 | + } elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) { |
|
| 778 | + $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
| 741 | 779 | } |
| 742 | - elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) |
|
| 743 | - $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
| 744 | 780 | } |
| 745 | 781 | |
| 746 | 782 | // Just build this here, it makes it easier to change/use - administrators can see all boards. |
| 747 | - if ($user_info['is_admin']) |
|
| 748 | - $user_info['query_see_board'] = '1=1'; |
|
| 783 | + if ($user_info['is_admin']) { |
|
| 784 | + $user_info['query_see_board'] = '1=1'; |
|
| 785 | + } |
|
| 749 | 786 | // Otherwise just the groups in $user_info['groups']. |
| 750 | - else |
|
| 751 | - $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'] : '') . ')'; |
|
| 787 | + else { |
|
| 788 | + $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'] : '') . ')'; |
|
| 789 | + } |
|
| 752 | 790 | |
| 753 | 791 | // Build the list of boards they WANT to see. |
| 754 | 792 | // This will take the place of query_see_boards in certain spots, so it better include the boards they can see also |
| 755 | 793 | |
| 756 | 794 | // If they aren't ignoring any boards then they want to see all the boards they can see |
| 757 | - if (empty($user_info['ignoreboards'])) |
|
| 758 | - $user_info['query_wanna_see_board'] = $user_info['query_see_board']; |
|
| 795 | + if (empty($user_info['ignoreboards'])) { |
|
| 796 | + $user_info['query_wanna_see_board'] = $user_info['query_see_board']; |
|
| 797 | + } |
|
| 759 | 798 | // Ok I guess they don't want to see all the boards |
| 760 | - else |
|
| 761 | - $user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))'; |
|
| 799 | + else { |
|
| 800 | + $user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))'; |
|
| 801 | + } |
|
| 762 | 802 | |
| 763 | 803 | call_integration_hook('integrate_user_info'); |
| 764 | 804 | } |
@@ -816,9 +856,9 @@ discard block |
||
| 816 | 856 | } |
| 817 | 857 | |
| 818 | 858 | // Remember redirection is the key to avoiding fallout from your bosses. |
| 819 | - if (!empty($topic)) |
|
| 820 | - redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
| 821 | - else |
|
| 859 | + if (!empty($topic)) { |
|
| 860 | + redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
| 861 | + } else |
|
| 822 | 862 | { |
| 823 | 863 | loadPermissions(); |
| 824 | 864 | loadTheme(); |
@@ -836,10 +876,11 @@ discard block |
||
| 836 | 876 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
| 837 | 877 | { |
| 838 | 878 | // @todo SLOW? |
| 839 | - if (!empty($topic)) |
|
| 840 | - $temp = cache_get_data('topic_board-' . $topic, 120); |
|
| 841 | - else |
|
| 842 | - $temp = cache_get_data('board-' . $board, 120); |
|
| 879 | + if (!empty($topic)) { |
|
| 880 | + $temp = cache_get_data('topic_board-' . $topic, 120); |
|
| 881 | + } else { |
|
| 882 | + $temp = cache_get_data('board-' . $board, 120); |
|
| 883 | + } |
|
| 843 | 884 | |
| 844 | 885 | if (!empty($temp)) |
| 845 | 886 | { |
@@ -877,8 +918,9 @@ discard block |
||
| 877 | 918 | $row = $smcFunc['db_fetch_assoc']($request); |
| 878 | 919 | |
| 879 | 920 | // Set the current board. |
| 880 | - if (!empty($row['id_board'])) |
|
| 881 | - $board = $row['id_board']; |
|
| 921 | + if (!empty($row['id_board'])) { |
|
| 922 | + $board = $row['id_board']; |
|
| 923 | + } |
|
| 882 | 924 | |
| 883 | 925 | // Basic operating information. (globals... :/) |
| 884 | 926 | $board_info = array( |
@@ -914,21 +956,23 @@ discard block |
||
| 914 | 956 | |
| 915 | 957 | do |
| 916 | 958 | { |
| 917 | - if (!empty($row['id_moderator'])) |
|
| 918 | - $board_info['moderators'][$row['id_moderator']] = array( |
|
| 959 | + if (!empty($row['id_moderator'])) { |
|
| 960 | + $board_info['moderators'][$row['id_moderator']] = array( |
|
| 919 | 961 | 'id' => $row['id_moderator'], |
| 920 | 962 | 'name' => $row['real_name'], |
| 921 | 963 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
| 922 | 964 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
| 923 | 965 | ); |
| 966 | + } |
|
| 924 | 967 | |
| 925 | - if (!empty($row['id_moderator_group'])) |
|
| 926 | - $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
| 968 | + if (!empty($row['id_moderator_group'])) { |
|
| 969 | + $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
| 927 | 970 | 'id' => $row['id_moderator_group'], |
| 928 | 971 | 'name' => $row['group_name'], |
| 929 | 972 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
| 930 | 973 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
| 931 | 974 | ); |
| 975 | + } |
|
| 932 | 976 | } |
| 933 | 977 | while ($row = $smcFunc['db_fetch_assoc']($request)); |
| 934 | 978 | |
@@ -960,12 +1004,12 @@ discard block |
||
| 960 | 1004 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
| 961 | 1005 | { |
| 962 | 1006 | // @todo SLOW? |
| 963 | - if (!empty($topic)) |
|
| 964 | - cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
| 1007 | + if (!empty($topic)) { |
|
| 1008 | + cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
| 1009 | + } |
|
| 965 | 1010 | cache_put_data('board-' . $board, $board_info, 120); |
| 966 | 1011 | } |
| 967 | - } |
|
| 968 | - else |
|
| 1012 | + } else |
|
| 969 | 1013 | { |
| 970 | 1014 | // Otherwise the topic is invalid, there are no moderators, etc. |
| 971 | 1015 | $board_info = array( |
@@ -979,8 +1023,9 @@ discard block |
||
| 979 | 1023 | $smcFunc['db_free_result']($request); |
| 980 | 1024 | } |
| 981 | 1025 | |
| 982 | - if (!empty($topic)) |
|
| 983 | - $_GET['board'] = (int) $board; |
|
| 1026 | + if (!empty($topic)) { |
|
| 1027 | + $_GET['board'] = (int) $board; |
|
| 1028 | + } |
|
| 984 | 1029 | |
| 985 | 1030 | if (!empty($board)) |
| 986 | 1031 | { |
@@ -990,10 +1035,12 @@ discard block |
||
| 990 | 1035 | // Now check if the user is a moderator. |
| 991 | 1036 | $user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0; |
| 992 | 1037 | |
| 993 | - if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) |
|
| 994 | - $board_info['error'] = 'access'; |
|
| 995 | - if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) |
|
| 996 | - $board_info['error'] = 'access'; |
|
| 1038 | + if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) { |
|
| 1039 | + $board_info['error'] = 'access'; |
|
| 1040 | + } |
|
| 1041 | + if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) { |
|
| 1042 | + $board_info['error'] = 'access'; |
|
| 1043 | + } |
|
| 997 | 1044 | |
| 998 | 1045 | // Build up the linktree. |
| 999 | 1046 | $context['linktree'] = array_merge( |
@@ -1016,8 +1063,9 @@ discard block |
||
| 1016 | 1063 | $context['current_board'] = $board; |
| 1017 | 1064 | |
| 1018 | 1065 | // No posting in redirection boards! |
| 1019 | - if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) |
|
| 1020 | - $board_info['error'] == 'post_in_redirect'; |
|
| 1066 | + if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) { |
|
| 1067 | + $board_info['error'] == 'post_in_redirect'; |
|
| 1068 | + } |
|
| 1021 | 1069 | |
| 1022 | 1070 | // Hacker... you can't see this topic, I'll tell you that. (but moderators can!) |
| 1023 | 1071 | if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod'])) |
@@ -1043,24 +1091,23 @@ discard block |
||
| 1043 | 1091 | ob_end_clean(); |
| 1044 | 1092 | header('HTTP/1.1 403 Forbidden'); |
| 1045 | 1093 | die; |
| 1046 | - } |
|
| 1047 | - elseif ($board_info['error'] == 'post_in_redirect') |
|
| 1094 | + } elseif ($board_info['error'] == 'post_in_redirect') |
|
| 1048 | 1095 | { |
| 1049 | 1096 | // Slightly different error message here... |
| 1050 | 1097 | fatal_lang_error('cannot_post_redirect', false); |
| 1051 | - } |
|
| 1052 | - elseif ($user_info['is_guest']) |
|
| 1098 | + } elseif ($user_info['is_guest']) |
|
| 1053 | 1099 | { |
| 1054 | 1100 | loadLanguage('Errors'); |
| 1055 | 1101 | is_not_guest($txt['topic_gone']); |
| 1102 | + } else { |
|
| 1103 | + fatal_lang_error('topic_gone', false); |
|
| 1056 | 1104 | } |
| 1057 | - else |
|
| 1058 | - fatal_lang_error('topic_gone', false); |
|
| 1059 | 1105 | } |
| 1060 | 1106 | |
| 1061 | - if ($user_info['is_mod']) |
|
| 1062 | - $user_info['groups'][] = 3; |
|
| 1063 | -} |
|
| 1107 | + if ($user_info['is_mod']) { |
|
| 1108 | + $user_info['groups'][] = 3; |
|
| 1109 | + } |
|
| 1110 | + } |
|
| 1064 | 1111 | |
| 1065 | 1112 | /** |
| 1066 | 1113 | * Load this user's permissions. |
@@ -1081,8 +1128,9 @@ discard block |
||
| 1081 | 1128 | asort($cache_groups); |
| 1082 | 1129 | $cache_groups = implode(',', $cache_groups); |
| 1083 | 1130 | // If it's a spider then cache it different. |
| 1084 | - if ($user_info['possibly_robot']) |
|
| 1085 | - $cache_groups .= '-spider'; |
|
| 1131 | + if ($user_info['possibly_robot']) { |
|
| 1132 | + $cache_groups .= '-spider'; |
|
| 1133 | + } |
|
| 1086 | 1134 | |
| 1087 | 1135 | if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
| 1088 | 1136 | { |
@@ -1090,9 +1138,9 @@ discard block |
||
| 1090 | 1138 | banPermissions(); |
| 1091 | 1139 | |
| 1092 | 1140 | return; |
| 1141 | + } elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) { |
|
| 1142 | + list ($user_info['permissions'], $removals) = $temp; |
|
| 1093 | 1143 | } |
| 1094 | - elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
|
| 1095 | - list ($user_info['permissions'], $removals) = $temp; |
|
| 1096 | 1144 | } |
| 1097 | 1145 | |
| 1098 | 1146 | // If it is detected as a robot, and we are restricting permissions as a special group - then implement this. |
@@ -1114,23 +1162,26 @@ discard block |
||
| 1114 | 1162 | $removals = array(); |
| 1115 | 1163 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1116 | 1164 | { |
| 1117 | - if (empty($row['add_deny'])) |
|
| 1118 | - $removals[] = $row['permission']; |
|
| 1119 | - else |
|
| 1120 | - $user_info['permissions'][] = $row['permission']; |
|
| 1165 | + if (empty($row['add_deny'])) { |
|
| 1166 | + $removals[] = $row['permission']; |
|
| 1167 | + } else { |
|
| 1168 | + $user_info['permissions'][] = $row['permission']; |
|
| 1169 | + } |
|
| 1121 | 1170 | } |
| 1122 | 1171 | $smcFunc['db_free_result']($request); |
| 1123 | 1172 | |
| 1124 | - if (isset($cache_groups)) |
|
| 1125 | - cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
| 1173 | + if (isset($cache_groups)) { |
|
| 1174 | + cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
| 1175 | + } |
|
| 1126 | 1176 | } |
| 1127 | 1177 | |
| 1128 | 1178 | // Get the board permissions. |
| 1129 | 1179 | if (!empty($board)) |
| 1130 | 1180 | { |
| 1131 | 1181 | // Make sure the board (if any) has been loaded by loadBoard(). |
| 1132 | - if (!isset($board_info['profile'])) |
|
| 1133 | - fatal_lang_error('no_board'); |
|
| 1182 | + if (!isset($board_info['profile'])) { |
|
| 1183 | + fatal_lang_error('no_board'); |
|
| 1184 | + } |
|
| 1134 | 1185 | |
| 1135 | 1186 | $request = $smcFunc['db_query']('', ' |
| 1136 | 1187 | SELECT permission, add_deny |
@@ -1146,20 +1197,23 @@ discard block |
||
| 1146 | 1197 | ); |
| 1147 | 1198 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1148 | 1199 | { |
| 1149 | - if (empty($row['add_deny'])) |
|
| 1150 | - $removals[] = $row['permission']; |
|
| 1151 | - else |
|
| 1152 | - $user_info['permissions'][] = $row['permission']; |
|
| 1200 | + if (empty($row['add_deny'])) { |
|
| 1201 | + $removals[] = $row['permission']; |
|
| 1202 | + } else { |
|
| 1203 | + $user_info['permissions'][] = $row['permission']; |
|
| 1204 | + } |
|
| 1153 | 1205 | } |
| 1154 | 1206 | $smcFunc['db_free_result']($request); |
| 1155 | 1207 | } |
| 1156 | 1208 | |
| 1157 | 1209 | // Remove all the permissions they shouldn't have ;). |
| 1158 | - if (!empty($modSettings['permission_enable_deny'])) |
|
| 1159 | - $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
| 1210 | + if (!empty($modSettings['permission_enable_deny'])) { |
|
| 1211 | + $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
| 1212 | + } |
|
| 1160 | 1213 | |
| 1161 | - if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) |
|
| 1162 | - cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
| 1214 | + if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) { |
|
| 1215 | + cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
| 1216 | + } |
|
| 1163 | 1217 | |
| 1164 | 1218 | // Banned? Watch, don't touch.. |
| 1165 | 1219 | banPermissions(); |
@@ -1171,17 +1225,18 @@ discard block |
||
| 1171 | 1225 | { |
| 1172 | 1226 | require_once($sourcedir . '/Subs-Auth.php'); |
| 1173 | 1227 | rebuildModCache(); |
| 1228 | + } else { |
|
| 1229 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
| 1174 | 1230 | } |
| 1175 | - else |
|
| 1176 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
| 1177 | 1231 | |
| 1178 | 1232 | // This is a useful phantom permission added to the current user, and only the current user while they are logged in. |
| 1179 | 1233 | // For example this drastically simplifies certain changes to the profile area. |
| 1180 | 1234 | $user_info['permissions'][] = 'is_not_guest'; |
| 1181 | 1235 | // And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions. |
| 1182 | 1236 | $user_info['permissions'][] = 'profile_view_own'; |
| 1183 | - if (in_array('profile_view', $user_info['permissions'])) |
|
| 1184 | - $user_info['permissions'][] = 'profile_view_any'; |
|
| 1237 | + if (in_array('profile_view', $user_info['permissions'])) { |
|
| 1238 | + $user_info['permissions'][] = 'profile_view_any'; |
|
| 1239 | + } |
|
| 1185 | 1240 | } |
| 1186 | 1241 | } |
| 1187 | 1242 | |
@@ -1199,8 +1254,9 @@ discard block |
||
| 1199 | 1254 | global $image_proxy_enabled, $image_proxy_secret, $boardurl; |
| 1200 | 1255 | |
| 1201 | 1256 | // Can't just look for no users :P. |
| 1202 | - if (empty($users)) |
|
| 1203 | - return array(); |
|
| 1257 | + if (empty($users)) { |
|
| 1258 | + return array(); |
|
| 1259 | + } |
|
| 1204 | 1260 | |
| 1205 | 1261 | // Pass the set value |
| 1206 | 1262 | $context['loadMemberContext_set'] = $set; |
@@ -1215,8 +1271,9 @@ discard block |
||
| 1215 | 1271 | for ($i = 0, $n = count($users); $i < $n; $i++) |
| 1216 | 1272 | { |
| 1217 | 1273 | $data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240); |
| 1218 | - if ($data == null) |
|
| 1219 | - continue; |
|
| 1274 | + if ($data == null) { |
|
| 1275 | + continue; |
|
| 1276 | + } |
|
| 1220 | 1277 | |
| 1221 | 1278 | $loaded_ids[] = $data['id_member']; |
| 1222 | 1279 | $user_profile[$data['id_member']] = $data; |
@@ -1283,13 +1340,16 @@ discard block |
||
| 1283 | 1340 | $row['avatar_original'] = $row['avatar']; |
| 1284 | 1341 | |
| 1285 | 1342 | // Take care of proxying avatar if required, do this here for maximum reach |
| 1286 | - if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) |
|
| 1287 | - $row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret); |
|
| 1343 | + if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) { |
|
| 1344 | + $row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret); |
|
| 1345 | + } |
|
| 1288 | 1346 | |
| 1289 | - if (isset($row['member_ip'])) |
|
| 1290 | - $row['member_ip'] = inet_dtop($row['member_ip']); |
|
| 1291 | - if (isset($row['member_ip2'])) |
|
| 1292 | - $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
| 1347 | + if (isset($row['member_ip'])) { |
|
| 1348 | + $row['member_ip'] = inet_dtop($row['member_ip']); |
|
| 1349 | + } |
|
| 1350 | + if (isset($row['member_ip2'])) { |
|
| 1351 | + $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
| 1352 | + } |
|
| 1293 | 1353 | $new_loaded_ids[] = $row['id_member']; |
| 1294 | 1354 | $loaded_ids[] = $row['id_member']; |
| 1295 | 1355 | $row['options'] = array(); |
@@ -1308,8 +1368,9 @@ discard block |
||
| 1308 | 1368 | 'loaded_ids' => $new_loaded_ids, |
| 1309 | 1369 | ) |
| 1310 | 1370 | ); |
| 1311 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1312 | - $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
| 1371 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1372 | + $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
| 1373 | + } |
|
| 1313 | 1374 | $smcFunc['db_free_result']($request); |
| 1314 | 1375 | } |
| 1315 | 1376 | |
@@ -1320,10 +1381,11 @@ discard block |
||
| 1320 | 1381 | { |
| 1321 | 1382 | foreach ($loaded_ids as $a_member) |
| 1322 | 1383 | { |
| 1323 | - if (!empty($user_profile[$a_member]['additional_groups'])) |
|
| 1324 | - $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
| 1325 | - else |
|
| 1326 | - $groups = array($user_profile[$a_member]['id_group']); |
|
| 1384 | + if (!empty($user_profile[$a_member]['additional_groups'])) { |
|
| 1385 | + $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
| 1386 | + } else { |
|
| 1387 | + $groups = array($user_profile[$a_member]['id_group']); |
|
| 1388 | + } |
|
| 1327 | 1389 | |
| 1328 | 1390 | $temp = array_intersect($groups, array_keys($board_info['moderator_groups'])); |
| 1329 | 1391 | |
@@ -1336,8 +1398,9 @@ discard block |
||
| 1336 | 1398 | |
| 1337 | 1399 | if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) |
| 1338 | 1400 | { |
| 1339 | - for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) |
|
| 1340 | - cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
| 1401 | + for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) { |
|
| 1402 | + cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
| 1403 | + } |
|
| 1341 | 1404 | } |
| 1342 | 1405 | |
| 1343 | 1406 | // Are we loading any moderators? If so, fix their group data... |
@@ -1363,14 +1426,17 @@ discard block |
||
| 1363 | 1426 | foreach ($temp_mods as $id) |
| 1364 | 1427 | { |
| 1365 | 1428 | // By popular demand, don't show admins or global moderators as moderators. |
| 1366 | - if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) |
|
| 1367 | - $user_profile[$id]['member_group'] = $row['member_group']; |
|
| 1429 | + if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) { |
|
| 1430 | + $user_profile[$id]['member_group'] = $row['member_group']; |
|
| 1431 | + } |
|
| 1368 | 1432 | |
| 1369 | 1433 | // If the Moderator group has no color or icons, but their group does... don't overwrite. |
| 1370 | - if (!empty($row['icons'])) |
|
| 1371 | - $user_profile[$id]['icons'] = $row['icons']; |
|
| 1372 | - if (!empty($row['member_group_color'])) |
|
| 1373 | - $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
| 1434 | + if (!empty($row['icons'])) { |
|
| 1435 | + $user_profile[$id]['icons'] = $row['icons']; |
|
| 1436 | + } |
|
| 1437 | + if (!empty($row['member_group_color'])) { |
|
| 1438 | + $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
| 1439 | + } |
|
| 1374 | 1440 | } |
| 1375 | 1441 | } |
| 1376 | 1442 | |
@@ -1392,12 +1458,14 @@ discard block |
||
| 1392 | 1458 | static $loadedLanguages = array(); |
| 1393 | 1459 | |
| 1394 | 1460 | // If this person's data is already loaded, skip it. |
| 1395 | - if (isset($dataLoaded[$user])) |
|
| 1396 | - return true; |
|
| 1461 | + if (isset($dataLoaded[$user])) { |
|
| 1462 | + return true; |
|
| 1463 | + } |
|
| 1397 | 1464 | |
| 1398 | 1465 | // We can't load guests or members not loaded by loadMemberData()! |
| 1399 | - if ($user == 0) |
|
| 1400 | - return false; |
|
| 1466 | + if ($user == 0) { |
|
| 1467 | + return false; |
|
| 1468 | + } |
|
| 1401 | 1469 | if (!isset($user_profile[$user])) |
| 1402 | 1470 | { |
| 1403 | 1471 | trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING); |
@@ -1423,12 +1491,16 @@ discard block |
||
| 1423 | 1491 | $buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array(); |
| 1424 | 1492 | |
| 1425 | 1493 | //We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme |
| 1426 | - if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists |
|
| 1494 | + if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) { |
|
| 1495 | + //icon is set and exists |
|
| 1427 | 1496 | $group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1]; |
| 1428 | - elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default |
|
| 1497 | + } elseif (isset($profile['icons'][1])) { |
|
| 1498 | + //icon is set and doesn't exist, fallback to default |
|
| 1429 | 1499 | $group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1]; |
| 1430 | - else //not set, bye bye |
|
| 1500 | + } else { |
|
| 1501 | + //not set, bye bye |
|
| 1431 | 1502 | $group_icon_url = ''; |
| 1503 | + } |
|
| 1432 | 1504 | |
| 1433 | 1505 | // These minimal values are always loaded |
| 1434 | 1506 | $memberContext[$user] = array( |
@@ -1447,8 +1519,9 @@ discard block |
||
| 1447 | 1519 | if ($context['loadMemberContext_set'] != 'minimal') |
| 1448 | 1520 | { |
| 1449 | 1521 | // Go the extra mile and load the user's native language name. |
| 1450 | - if (empty($loadedLanguages)) |
|
| 1451 | - $loadedLanguages = getLanguages(); |
|
| 1522 | + if (empty($loadedLanguages)) { |
|
| 1523 | + $loadedLanguages = getLanguages(); |
|
| 1524 | + } |
|
| 1452 | 1525 | |
| 1453 | 1526 | $memberContext[$user] += array( |
| 1454 | 1527 | 'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>', |
@@ -1502,31 +1575,33 @@ discard block |
||
| 1502 | 1575 | { |
| 1503 | 1576 | if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://'))) |
| 1504 | 1577 | { |
| 1505 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) |
|
| 1506 | - $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
| 1507 | - else |
|
| 1508 | - $image = get_gravatar_url($profile['email_address']); |
|
| 1509 | - } |
|
| 1510 | - else |
|
| 1578 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) { |
|
| 1579 | + $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
| 1580 | + } else { |
|
| 1581 | + $image = get_gravatar_url($profile['email_address']); |
|
| 1582 | + } |
|
| 1583 | + } else |
|
| 1511 | 1584 | { |
| 1512 | 1585 | // So it's stored in the member table? |
| 1513 | 1586 | if (!empty($profile['avatar'])) |
| 1514 | 1587 | { |
| 1515 | 1588 | $image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']; |
| 1589 | + } elseif (!empty($profile['filename'])) { |
|
| 1590 | + $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
| 1516 | 1591 | } |
| 1517 | - elseif (!empty($profile['filename'])) |
|
| 1518 | - $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
| 1519 | 1592 | // Right... no avatar...use the default one |
| 1520 | - else |
|
| 1521 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 1593 | + else { |
|
| 1594 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 1595 | + } |
|
| 1522 | 1596 | } |
| 1523 | - if (!empty($image)) |
|
| 1524 | - $memberContext[$user]['avatar'] = array( |
|
| 1597 | + if (!empty($image)) { |
|
| 1598 | + $memberContext[$user]['avatar'] = array( |
|
| 1525 | 1599 | 'name' => $profile['avatar'], |
| 1526 | 1600 | 'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">', |
| 1527 | 1601 | 'href' => $image, |
| 1528 | 1602 | 'url' => $image, |
| 1529 | 1603 | ); |
| 1604 | + } |
|
| 1530 | 1605 | } |
| 1531 | 1606 | |
| 1532 | 1607 | // Are we also loading the members custom fields into context? |
@@ -1534,35 +1609,41 @@ discard block |
||
| 1534 | 1609 | { |
| 1535 | 1610 | $memberContext[$user]['custom_fields'] = array(); |
| 1536 | 1611 | |
| 1537 | - if (!isset($context['display_fields'])) |
|
| 1538 | - $context['display_fields'] = smf_json_decode($modSettings['displayFields'], true); |
|
| 1612 | + if (!isset($context['display_fields'])) { |
|
| 1613 | + $context['display_fields'] = smf_json_decode($modSettings['displayFields'], true); |
|
| 1614 | + } |
|
| 1539 | 1615 | |
| 1540 | 1616 | foreach ($context['display_fields'] as $custom) |
| 1541 | 1617 | { |
| 1542 | - if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) |
|
| 1543 | - continue; |
|
| 1618 | + if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) { |
|
| 1619 | + continue; |
|
| 1620 | + } |
|
| 1544 | 1621 | |
| 1545 | 1622 | $value = $profile['options'][$custom['col_name']]; |
| 1546 | 1623 | |
| 1547 | 1624 | // Don't show the "disabled" option for the "gender" field. |
| 1548 | - if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') |
|
| 1549 | - continue; |
|
| 1625 | + if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') { |
|
| 1626 | + continue; |
|
| 1627 | + } |
|
| 1550 | 1628 | |
| 1551 | 1629 | // BBC? |
| 1552 | - if ($custom['bbc']) |
|
| 1553 | - $value = parse_bbc($value); |
|
| 1630 | + if ($custom['bbc']) { |
|
| 1631 | + $value = parse_bbc($value); |
|
| 1632 | + } |
|
| 1554 | 1633 | // ... or checkbox? |
| 1555 | - elseif (isset($custom['type']) && $custom['type'] == 'check') |
|
| 1556 | - $value = $value ? $txt['yes'] : $txt['no']; |
|
| 1634 | + elseif (isset($custom['type']) && $custom['type'] == 'check') { |
|
| 1635 | + $value = $value ? $txt['yes'] : $txt['no']; |
|
| 1636 | + } |
|
| 1557 | 1637 | |
| 1558 | 1638 | // Enclosing the user input within some other text? |
| 1559 | - if (!empty($custom['enclose'])) |
|
| 1560 | - $value = strtr($custom['enclose'], array( |
|
| 1639 | + if (!empty($custom['enclose'])) { |
|
| 1640 | + $value = strtr($custom['enclose'], array( |
|
| 1561 | 1641 | '{SCRIPTURL}' => $scripturl, |
| 1562 | 1642 | '{IMAGES_URL}' => $settings['images_url'], |
| 1563 | 1643 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
| 1564 | 1644 | '{INPUT}' => $value, |
| 1565 | 1645 | )); |
| 1646 | + } |
|
| 1566 | 1647 | |
| 1567 | 1648 | $memberContext[$user]['custom_fields'][] = array( |
| 1568 | 1649 | 'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'], |
@@ -1589,8 +1670,9 @@ discard block |
||
| 1589 | 1670 | global $smcFunc, $txt, $scripturl, $settings; |
| 1590 | 1671 | |
| 1591 | 1672 | // Do not waste my time... |
| 1592 | - if (empty($users) || empty($params)) |
|
| 1593 | - return false; |
|
| 1673 | + if (empty($users) || empty($params)) { |
|
| 1674 | + return false; |
|
| 1675 | + } |
|
| 1594 | 1676 | |
| 1595 | 1677 | // Make sure it's an array. |
| 1596 | 1678 | $users = !is_array($users) ? array($users) : array_unique($users); |
@@ -1614,31 +1696,36 @@ discard block |
||
| 1614 | 1696 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1615 | 1697 | { |
| 1616 | 1698 | // BBC? |
| 1617 | - if (!empty($row['bbc'])) |
|
| 1618 | - $row['value'] = parse_bbc($row['value']); |
|
| 1699 | + if (!empty($row['bbc'])) { |
|
| 1700 | + $row['value'] = parse_bbc($row['value']); |
|
| 1701 | + } |
|
| 1619 | 1702 | |
| 1620 | 1703 | // ... or checkbox? |
| 1621 | - elseif (isset($row['type']) && $row['type'] == 'check') |
|
| 1622 | - $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
| 1704 | + elseif (isset($row['type']) && $row['type'] == 'check') { |
|
| 1705 | + $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
| 1706 | + } |
|
| 1623 | 1707 | |
| 1624 | 1708 | // Enclosing the user input within some other text? |
| 1625 | - if (!empty($row['enclose'])) |
|
| 1626 | - $row['value'] = strtr($row['enclose'], array( |
|
| 1709 | + if (!empty($row['enclose'])) { |
|
| 1710 | + $row['value'] = strtr($row['enclose'], array( |
|
| 1627 | 1711 | '{SCRIPTURL}' => $scripturl, |
| 1628 | 1712 | '{IMAGES_URL}' => $settings['images_url'], |
| 1629 | 1713 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
| 1630 | 1714 | '{INPUT}' => un_htmlspecialchars($row['value']), |
| 1631 | 1715 | )); |
| 1716 | + } |
|
| 1632 | 1717 | |
| 1633 | 1718 | // Send a simple array if there is just 1 param |
| 1634 | - if (count($params) == 1) |
|
| 1635 | - $return[$row['id_member']] = $row; |
|
| 1719 | + if (count($params) == 1) { |
|
| 1720 | + $return[$row['id_member']] = $row; |
|
| 1721 | + } |
|
| 1636 | 1722 | |
| 1637 | 1723 | // More than 1? knock yourself out... |
| 1638 | 1724 | else |
| 1639 | 1725 | { |
| 1640 | - if (!isset($return[$row['id_member']])) |
|
| 1641 | - $return[$row['id_member']] = array(); |
|
| 1726 | + if (!isset($return[$row['id_member']])) { |
|
| 1727 | + $return[$row['id_member']] = array(); |
|
| 1728 | + } |
|
| 1642 | 1729 | |
| 1643 | 1730 | $return[$row['id_member']][$row['variable']] = $row; |
| 1644 | 1731 | } |
@@ -1672,8 +1759,9 @@ discard block |
||
| 1672 | 1759 | global $context; |
| 1673 | 1760 | |
| 1674 | 1761 | // Don't know any browser! |
| 1675 | - if (empty($context['browser'])) |
|
| 1676 | - detectBrowser(); |
|
| 1762 | + if (empty($context['browser'])) { |
|
| 1763 | + detectBrowser(); |
|
| 1764 | + } |
|
| 1677 | 1765 | |
| 1678 | 1766 | return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false; |
| 1679 | 1767 | } |
@@ -1691,8 +1779,9 @@ discard block |
||
| 1691 | 1779 | global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled; |
| 1692 | 1780 | |
| 1693 | 1781 | // The theme was specified by parameter. |
| 1694 | - if (!empty($id_theme)) |
|
| 1695 | - $id_theme = (int) $id_theme; |
|
| 1782 | + if (!empty($id_theme)) { |
|
| 1783 | + $id_theme = (int) $id_theme; |
|
| 1784 | + } |
|
| 1696 | 1785 | // The theme was specified by REQUEST. |
| 1697 | 1786 | elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
| 1698 | 1787 | { |
@@ -1700,51 +1789,58 @@ discard block |
||
| 1700 | 1789 | $_SESSION['id_theme'] = $id_theme; |
| 1701 | 1790 | } |
| 1702 | 1791 | // The theme was specified by REQUEST... previously. |
| 1703 | - elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
|
| 1704 | - $id_theme = (int) $_SESSION['id_theme']; |
|
| 1792 | + elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) { |
|
| 1793 | + $id_theme = (int) $_SESSION['id_theme']; |
|
| 1794 | + } |
|
| 1705 | 1795 | // The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.) |
| 1706 | - elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) |
|
| 1707 | - $id_theme = $user_info['theme']; |
|
| 1796 | + elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) { |
|
| 1797 | + $id_theme = $user_info['theme']; |
|
| 1798 | + } |
|
| 1708 | 1799 | // The theme was specified by the board. |
| 1709 | - elseif (!empty($board_info['theme'])) |
|
| 1710 | - $id_theme = $board_info['theme']; |
|
| 1800 | + elseif (!empty($board_info['theme'])) { |
|
| 1801 | + $id_theme = $board_info['theme']; |
|
| 1802 | + } |
|
| 1711 | 1803 | // The theme is the forum's default. |
| 1712 | - else |
|
| 1713 | - $id_theme = $modSettings['theme_guests']; |
|
| 1804 | + else { |
|
| 1805 | + $id_theme = $modSettings['theme_guests']; |
|
| 1806 | + } |
|
| 1714 | 1807 | |
| 1715 | 1808 | // Verify the id_theme... no foul play. |
| 1716 | 1809 | // Always allow the board specific theme, if they are overriding. |
| 1717 | - if (!empty($board_info['theme']) && $board_info['override_theme']) |
|
| 1718 | - $id_theme = $board_info['theme']; |
|
| 1810 | + if (!empty($board_info['theme']) && $board_info['override_theme']) { |
|
| 1811 | + $id_theme = $board_info['theme']; |
|
| 1812 | + } |
|
| 1719 | 1813 | // If they have specified a particular theme to use with SSI allow it to be used. |
| 1720 | - elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) |
|
| 1721 | - $id_theme = (int) $id_theme; |
|
| 1722 | - elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
| 1814 | + elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) { |
|
| 1815 | + $id_theme = (int) $id_theme; |
|
| 1816 | + } elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
| 1723 | 1817 | { |
| 1724 | 1818 | $themes = explode(',', $modSettings['enableThemes']); |
| 1725 | - if (!in_array($id_theme, $themes)) |
|
| 1726 | - $id_theme = $modSettings['theme_guests']; |
|
| 1727 | - else |
|
| 1819 | + if (!in_array($id_theme, $themes)) { |
|
| 1820 | + $id_theme = $modSettings['theme_guests']; |
|
| 1821 | + } else { |
|
| 1822 | + $id_theme = (int) $id_theme; |
|
| 1823 | + } |
|
| 1824 | + } else { |
|
| 1728 | 1825 | $id_theme = (int) $id_theme; |
| 1729 | 1826 | } |
| 1730 | - else |
|
| 1731 | - $id_theme = (int) $id_theme; |
|
| 1732 | 1827 | |
| 1733 | 1828 | $member = empty($user_info['id']) ? -1 : $user_info['id']; |
| 1734 | 1829 | |
| 1735 | 1830 | // Disable image proxy if we don't have SSL enabled |
| 1736 | - if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) |
|
| 1737 | - $image_proxy_enabled = false; |
|
| 1831 | + if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) { |
|
| 1832 | + $image_proxy_enabled = false; |
|
| 1833 | + } |
|
| 1738 | 1834 | |
| 1739 | 1835 | 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']) |
| 1740 | 1836 | { |
| 1741 | 1837 | $themeData = $temp; |
| 1742 | 1838 | $flag = true; |
| 1839 | + } elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) { |
|
| 1840 | + $themeData = $temp + array($member => array()); |
|
| 1841 | + } else { |
|
| 1842 | + $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
| 1743 | 1843 | } |
| 1744 | - elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) |
|
| 1745 | - $themeData = $temp + array($member => array()); |
|
| 1746 | - else |
|
| 1747 | - $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
| 1748 | 1844 | |
| 1749 | 1845 | if (empty($flag)) |
| 1750 | 1846 | { |
@@ -1763,31 +1859,37 @@ discard block |
||
| 1763 | 1859 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 1764 | 1860 | { |
| 1765 | 1861 | // There are just things we shouldn't be able to change as members. |
| 1766 | - 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'))) |
|
| 1767 | - continue; |
|
| 1862 | + 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'))) { |
|
| 1863 | + continue; |
|
| 1864 | + } |
|
| 1768 | 1865 | |
| 1769 | 1866 | // If this is the theme_dir of the default theme, store it. |
| 1770 | - if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) |
|
| 1771 | - $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
| 1867 | + if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) { |
|
| 1868 | + $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
| 1869 | + } |
|
| 1772 | 1870 | |
| 1773 | 1871 | // If this isn't set yet, is a theme option, or is not the default theme.. |
| 1774 | - if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') |
|
| 1775 | - $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
| 1872 | + if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') { |
|
| 1873 | + $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
| 1874 | + } |
|
| 1776 | 1875 | } |
| 1777 | 1876 | $smcFunc['db_free_result']($result); |
| 1778 | 1877 | |
| 1779 | - if (!empty($themeData[-1])) |
|
| 1780 | - foreach ($themeData[-1] as $k => $v) |
|
| 1878 | + if (!empty($themeData[-1])) { |
|
| 1879 | + foreach ($themeData[-1] as $k => $v) |
|
| 1781 | 1880 | { |
| 1782 | 1881 | if (!isset($themeData[$member][$k])) |
| 1783 | 1882 | $themeData[$member][$k] = $v; |
| 1883 | + } |
|
| 1784 | 1884 | } |
| 1785 | 1885 | |
| 1786 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 1787 | - cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
| 1886 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 1887 | + cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
| 1888 | + } |
|
| 1788 | 1889 | // Only if we didn't already load that part of the cache... |
| 1789 | - elseif (!isset($temp)) |
|
| 1790 | - cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
| 1890 | + elseif (!isset($temp)) { |
|
| 1891 | + cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
| 1892 | + } |
|
| 1791 | 1893 | } |
| 1792 | 1894 | |
| 1793 | 1895 | $settings = $themeData[0]; |
@@ -1804,20 +1906,24 @@ discard block |
||
| 1804 | 1906 | $settings['template_dirs'][] = $settings['theme_dir']; |
| 1805 | 1907 | |
| 1806 | 1908 | // Based on theme (if there is one). |
| 1807 | - if (!empty($settings['base_theme_dir'])) |
|
| 1808 | - $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
| 1909 | + if (!empty($settings['base_theme_dir'])) { |
|
| 1910 | + $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
| 1911 | + } |
|
| 1809 | 1912 | |
| 1810 | 1913 | // Lastly the default theme. |
| 1811 | - if ($settings['theme_dir'] != $settings['default_theme_dir']) |
|
| 1812 | - $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
| 1914 | + if ($settings['theme_dir'] != $settings['default_theme_dir']) { |
|
| 1915 | + $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
| 1916 | + } |
|
| 1813 | 1917 | |
| 1814 | - if (!$initialize) |
|
| 1815 | - return; |
|
| 1918 | + if (!$initialize) { |
|
| 1919 | + return; |
|
| 1920 | + } |
|
| 1816 | 1921 | |
| 1817 | 1922 | // Check to see if we're forcing SSL |
| 1818 | 1923 | if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) && |
| 1819 | - (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') |
|
| 1820 | - redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://'))); |
|
| 1924 | + (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') { |
|
| 1925 | + redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://'))); |
|
| 1926 | + } |
|
| 1821 | 1927 | |
| 1822 | 1928 | // Check to see if they're accessing it from the wrong place. |
| 1823 | 1929 | if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME'])) |
@@ -1825,8 +1931,9 @@ discard block |
||
| 1825 | 1931 | $detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://'; |
| 1826 | 1932 | $detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']; |
| 1827 | 1933 | $temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')); |
| 1828 | - if ($temp != '/') |
|
| 1829 | - $detected_url .= $temp; |
|
| 1934 | + if ($temp != '/') { |
|
| 1935 | + $detected_url .= $temp; |
|
| 1936 | + } |
|
| 1830 | 1937 | } |
| 1831 | 1938 | if (isset($detected_url) && $detected_url != $boardurl) |
| 1832 | 1939 | { |
@@ -1838,8 +1945,9 @@ discard block |
||
| 1838 | 1945 | foreach ($aliases as $alias) |
| 1839 | 1946 | { |
| 1840 | 1947 | // Rip off all the boring parts, spaces, etc. |
| 1841 | - if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) |
|
| 1842 | - $do_fix = true; |
|
| 1948 | + if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) { |
|
| 1949 | + $do_fix = true; |
|
| 1950 | + } |
|
| 1843 | 1951 | } |
| 1844 | 1952 | } |
| 1845 | 1953 | |
@@ -1847,20 +1955,22 @@ discard block |
||
| 1847 | 1955 | if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI') |
| 1848 | 1956 | { |
| 1849 | 1957 | // Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;). |
| 1850 | - if (empty($_GET)) |
|
| 1851 | - redirectexit('wwwRedirect'); |
|
| 1852 | - else |
|
| 1958 | + if (empty($_GET)) { |
|
| 1959 | + redirectexit('wwwRedirect'); |
|
| 1960 | + } else |
|
| 1853 | 1961 | { |
| 1854 | 1962 | list ($k, $v) = each($_GET); |
| 1855 | 1963 | |
| 1856 | - if ($k != 'wwwRedirect') |
|
| 1857 | - redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
| 1964 | + if ($k != 'wwwRedirect') { |
|
| 1965 | + redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
| 1966 | + } |
|
| 1858 | 1967 | } |
| 1859 | 1968 | } |
| 1860 | 1969 | |
| 1861 | 1970 | // #3 is just a check for SSL... |
| 1862 | - if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) |
|
| 1863 | - $do_fix = true; |
|
| 1971 | + if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) { |
|
| 1972 | + $do_fix = true; |
|
| 1973 | + } |
|
| 1864 | 1974 | |
| 1865 | 1975 | // Okay, #4 - perhaps it's an IP address? We're gonna want to use that one, then. (assuming it's the IP or something...) |
| 1866 | 1976 | if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1) |
@@ -1894,8 +2004,9 @@ discard block |
||
| 1894 | 2004 | $board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl)); |
| 1895 | 2005 | } |
| 1896 | 2006 | } |
| 1897 | - foreach ($context['linktree'] as $k => $dummy) |
|
| 1898 | - $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
| 2007 | + foreach ($context['linktree'] as $k => $dummy) { |
|
| 2008 | + $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
| 2009 | + } |
|
| 1899 | 2010 | } |
| 1900 | 2011 | } |
| 1901 | 2012 | // Set up the contextual user array. |
@@ -1914,16 +2025,16 @@ discard block |
||
| 1914 | 2025 | 'email' => $user_info['email'], |
| 1915 | 2026 | 'ignoreusers' => $user_info['ignoreusers'], |
| 1916 | 2027 | ); |
| 1917 | - if (!$context['user']['is_guest']) |
|
| 1918 | - $context['user']['name'] = $user_info['name']; |
|
| 1919 | - elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) |
|
| 1920 | - $context['user']['name'] = $txt['guest_title']; |
|
| 2028 | + if (!$context['user']['is_guest']) { |
|
| 2029 | + $context['user']['name'] = $user_info['name']; |
|
| 2030 | + } elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) { |
|
| 2031 | + $context['user']['name'] = $txt['guest_title']; |
|
| 2032 | + } |
|
| 1921 | 2033 | |
| 1922 | 2034 | // Determine the current smiley set. |
| 1923 | 2035 | $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']; |
| 1924 | 2036 | $context['user']['smiley_set'] = $user_info['smiley_set']; |
| 1925 | - } |
|
| 1926 | - else |
|
| 2037 | + } else |
|
| 1927 | 2038 | { |
| 1928 | 2039 | $context['user'] = array( |
| 1929 | 2040 | 'id' => -1, |
@@ -1939,18 +2050,24 @@ discard block |
||
| 1939 | 2050 | } |
| 1940 | 2051 | |
| 1941 | 2052 | // Some basic information... |
| 1942 | - if (!isset($context['html_headers'])) |
|
| 1943 | - $context['html_headers'] = ''; |
|
| 1944 | - if (!isset($context['javascript_files'])) |
|
| 1945 | - $context['javascript_files'] = array(); |
|
| 1946 | - if (!isset($context['css_files'])) |
|
| 1947 | - $context['css_files'] = array(); |
|
| 1948 | - if (!isset($context['css_header'])) |
|
| 1949 | - $context['css_header'] = array(); |
|
| 1950 | - if (!isset($context['javascript_inline'])) |
|
| 1951 | - $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
| 1952 | - if (!isset($context['javascript_vars'])) |
|
| 1953 | - $context['javascript_vars'] = array(); |
|
| 2053 | + if (!isset($context['html_headers'])) { |
|
| 2054 | + $context['html_headers'] = ''; |
|
| 2055 | + } |
|
| 2056 | + if (!isset($context['javascript_files'])) { |
|
| 2057 | + $context['javascript_files'] = array(); |
|
| 2058 | + } |
|
| 2059 | + if (!isset($context['css_files'])) { |
|
| 2060 | + $context['css_files'] = array(); |
|
| 2061 | + } |
|
| 2062 | + if (!isset($context['css_header'])) { |
|
| 2063 | + $context['css_header'] = array(); |
|
| 2064 | + } |
|
| 2065 | + if (!isset($context['javascript_inline'])) { |
|
| 2066 | + $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
| 2067 | + } |
|
| 2068 | + if (!isset($context['javascript_vars'])) { |
|
| 2069 | + $context['javascript_vars'] = array(); |
|
| 2070 | + } |
|
| 1954 | 2071 | |
| 1955 | 2072 | $context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2'; |
| 1956 | 2073 | $context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | '; |
@@ -1962,8 +2079,9 @@ discard block |
||
| 1962 | 2079 | $context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null; |
| 1963 | 2080 | $context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null; |
| 1964 | 2081 | $context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3; |
| 1965 | - if (isset($modSettings['load_average'])) |
|
| 1966 | - $context['load_average'] = $modSettings['load_average']; |
|
| 2082 | + if (isset($modSettings['load_average'])) { |
|
| 2083 | + $context['load_average'] = $modSettings['load_average']; |
|
| 2084 | + } |
|
| 1967 | 2085 | |
| 1968 | 2086 | // Detect the browser. This is separated out because it's also used in attachment downloads |
| 1969 | 2087 | detectBrowser(); |
@@ -1977,8 +2095,9 @@ discard block |
||
| 1977 | 2095 | // This allows sticking some HTML on the page output - useful for controls. |
| 1978 | 2096 | $context['insert_after_template'] = ''; |
| 1979 | 2097 | |
| 1980 | - if (!isset($txt)) |
|
| 1981 | - $txt = array(); |
|
| 2098 | + if (!isset($txt)) { |
|
| 2099 | + $txt = array(); |
|
| 2100 | + } |
|
| 1982 | 2101 | |
| 1983 | 2102 | $simpleActions = array( |
| 1984 | 2103 | 'findmember', |
@@ -2024,9 +2143,10 @@ discard block |
||
| 2024 | 2143 | |
| 2025 | 2144 | // See if theres any extra param to check. |
| 2026 | 2145 | $requiresXML = false; |
| 2027 | - foreach ($extraParams as $key => $extra) |
|
| 2028 | - if (isset($_REQUEST[$extra])) |
|
| 2146 | + foreach ($extraParams as $key => $extra) { |
|
| 2147 | + if (isset($_REQUEST[$extra])) |
|
| 2029 | 2148 | $requiresXML = true; |
| 2149 | + } |
|
| 2030 | 2150 | |
| 2031 | 2151 | // Output is fully XML, so no need for the index template. |
| 2032 | 2152 | if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML)) |
@@ -2041,37 +2161,39 @@ discard block |
||
| 2041 | 2161 | { |
| 2042 | 2162 | loadLanguage('index+Modifications'); |
| 2043 | 2163 | $context['template_layers'] = array(); |
| 2044 | - } |
|
| 2045 | - |
|
| 2046 | - else |
|
| 2164 | + } else |
|
| 2047 | 2165 | { |
| 2048 | 2166 | // Custom templates to load, or just default? |
| 2049 | - if (isset($settings['theme_templates'])) |
|
| 2050 | - $templates = explode(',', $settings['theme_templates']); |
|
| 2051 | - else |
|
| 2052 | - $templates = array('index'); |
|
| 2167 | + if (isset($settings['theme_templates'])) { |
|
| 2168 | + $templates = explode(',', $settings['theme_templates']); |
|
| 2169 | + } else { |
|
| 2170 | + $templates = array('index'); |
|
| 2171 | + } |
|
| 2053 | 2172 | |
| 2054 | 2173 | // Load each template... |
| 2055 | - foreach ($templates as $template) |
|
| 2056 | - loadTemplate($template); |
|
| 2174 | + foreach ($templates as $template) { |
|
| 2175 | + loadTemplate($template); |
|
| 2176 | + } |
|
| 2057 | 2177 | |
| 2058 | 2178 | // ...and attempt to load their associated language files. |
| 2059 | 2179 | $required_files = implode('+', array_merge($templates, array('Modifications'))); |
| 2060 | 2180 | loadLanguage($required_files, '', false); |
| 2061 | 2181 | |
| 2062 | 2182 | // Custom template layers? |
| 2063 | - if (isset($settings['theme_layers'])) |
|
| 2064 | - $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
| 2065 | - else |
|
| 2066 | - $context['template_layers'] = array('html', 'body'); |
|
| 2183 | + if (isset($settings['theme_layers'])) { |
|
| 2184 | + $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
| 2185 | + } else { |
|
| 2186 | + $context['template_layers'] = array('html', 'body'); |
|
| 2187 | + } |
|
| 2067 | 2188 | } |
| 2068 | 2189 | |
| 2069 | 2190 | // Initialize the theme. |
| 2070 | 2191 | loadSubTemplate('init', 'ignore'); |
| 2071 | 2192 | |
| 2072 | 2193 | // Allow overriding the board wide time/number formats. |
| 2073 | - if (empty($user_settings['time_format']) && !empty($txt['time_format'])) |
|
| 2074 | - $user_info['time_format'] = $txt['time_format']; |
|
| 2194 | + if (empty($user_settings['time_format']) && !empty($txt['time_format'])) { |
|
| 2195 | + $user_info['time_format'] = $txt['time_format']; |
|
| 2196 | + } |
|
| 2075 | 2197 | |
| 2076 | 2198 | // Set the character set from the template. |
| 2077 | 2199 | $context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']; |
@@ -2079,12 +2201,14 @@ discard block |
||
| 2079 | 2201 | $context['right_to_left'] = !empty($txt['lang_rtl']); |
| 2080 | 2202 | |
| 2081 | 2203 | // Guests may still need a name. |
| 2082 | - if ($context['user']['is_guest'] && empty($context['user']['name'])) |
|
| 2083 | - $context['user']['name'] = $txt['guest_title']; |
|
| 2204 | + if ($context['user']['is_guest'] && empty($context['user']['name'])) { |
|
| 2205 | + $context['user']['name'] = $txt['guest_title']; |
|
| 2206 | + } |
|
| 2084 | 2207 | |
| 2085 | 2208 | // Any theme-related strings that need to be loaded? |
| 2086 | - if (!empty($settings['require_theme_strings'])) |
|
| 2087 | - loadLanguage('ThemeStrings', '', false); |
|
| 2209 | + if (!empty($settings['require_theme_strings'])) { |
|
| 2210 | + loadLanguage('ThemeStrings', '', false); |
|
| 2211 | + } |
|
| 2088 | 2212 | |
| 2089 | 2213 | // Make a special URL for the language. |
| 2090 | 2214 | $settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']); |
@@ -2095,8 +2219,9 @@ discard block |
||
| 2095 | 2219 | // Here is my luvly Responsive CSS |
| 2096 | 2220 | loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive'); |
| 2097 | 2221 | |
| 2098 | - if ($context['right_to_left']) |
|
| 2099 | - loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
| 2222 | + if ($context['right_to_left']) { |
|
| 2223 | + loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
| 2224 | + } |
|
| 2100 | 2225 | |
| 2101 | 2226 | // We allow theme variants, because we're cool. |
| 2102 | 2227 | $context['theme_variant'] = ''; |
@@ -2104,14 +2229,17 @@ discard block |
||
| 2104 | 2229 | if (!empty($settings['theme_variants'])) |
| 2105 | 2230 | { |
| 2106 | 2231 | // Overriding - for previews and that ilk. |
| 2107 | - if (!empty($_REQUEST['variant'])) |
|
| 2108 | - $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
| 2232 | + if (!empty($_REQUEST['variant'])) { |
|
| 2233 | + $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
| 2234 | + } |
|
| 2109 | 2235 | // User selection? |
| 2110 | - if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) |
|
| 2111 | - $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
| 2236 | + if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) { |
|
| 2237 | + $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
| 2238 | + } |
|
| 2112 | 2239 | // If not a user variant, select the default. |
| 2113 | - if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) |
|
| 2114 | - $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
| 2240 | + if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) { |
|
| 2241 | + $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
| 2242 | + } |
|
| 2115 | 2243 | |
| 2116 | 2244 | // Do this to keep things easier in the templates. |
| 2117 | 2245 | $context['theme_variant'] = '_' . $context['theme_variant']; |
@@ -2120,20 +2248,23 @@ discard block |
||
| 2120 | 2248 | if (!empty($context['theme_variant'])) |
| 2121 | 2249 | { |
| 2122 | 2250 | loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']); |
| 2123 | - if ($context['right_to_left']) |
|
| 2124 | - loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
| 2251 | + if ($context['right_to_left']) { |
|
| 2252 | + loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
| 2253 | + } |
|
| 2125 | 2254 | } |
| 2126 | 2255 | } |
| 2127 | 2256 | |
| 2128 | 2257 | // Let's be compatible with old themes! |
| 2129 | - if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) |
|
| 2130 | - $context['template_layers'] = array('main'); |
|
| 2258 | + if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) { |
|
| 2259 | + $context['template_layers'] = array('main'); |
|
| 2260 | + } |
|
| 2131 | 2261 | |
| 2132 | 2262 | $context['tabindex'] = 1; |
| 2133 | 2263 | |
| 2134 | 2264 | // Compatibility. |
| 2135 | - if (!isset($settings['theme_version'])) |
|
| 2136 | - $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
| 2265 | + if (!isset($settings['theme_version'])) { |
|
| 2266 | + $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
| 2267 | + } |
|
| 2137 | 2268 | |
| 2138 | 2269 | // Default JS variables for use in every theme |
| 2139 | 2270 | $context['javascript_vars'] = array( |
@@ -2152,18 +2283,18 @@ discard block |
||
| 2152 | 2283 | ); |
| 2153 | 2284 | |
| 2154 | 2285 | // Add the JQuery library to the list of files to load. |
| 2155 | - if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') |
|
| 2156 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2157 | - |
|
| 2158 | - elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') |
|
| 2159 | - loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery'); |
|
| 2160 | - |
|
| 2161 | - elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') |
|
| 2162 | - loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
| 2286 | + if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') { |
|
| 2287 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2288 | + } elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') { |
|
| 2289 | + loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery'); |
|
| 2290 | + } elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') { |
|
| 2291 | + loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
| 2292 | + } |
|
| 2163 | 2293 | |
| 2164 | 2294 | // Auto loading? template_javascript() will take care of the local half of this. |
| 2165 | - else |
|
| 2166 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2295 | + else { |
|
| 2296 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2297 | + } |
|
| 2167 | 2298 | |
| 2168 | 2299 | // Queue our JQuery plugins! |
| 2169 | 2300 | loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins'); |
@@ -2186,12 +2317,12 @@ discard block |
||
| 2186 | 2317 | require_once($sourcedir . '/ScheduledTasks.php'); |
| 2187 | 2318 | |
| 2188 | 2319 | // What to do, what to do?! |
| 2189 | - if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) |
|
| 2190 | - AutoTask(); |
|
| 2191 | - else |
|
| 2192 | - ReduceMailQueue(); |
|
| 2193 | - } |
|
| 2194 | - else |
|
| 2320 | + if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) { |
|
| 2321 | + AutoTask(); |
|
| 2322 | + } else { |
|
| 2323 | + ReduceMailQueue(); |
|
| 2324 | + } |
|
| 2325 | + } else |
|
| 2195 | 2326 | { |
| 2196 | 2327 | $type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq'; |
| 2197 | 2328 | $ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time']; |
@@ -2242,8 +2373,9 @@ discard block |
||
| 2242 | 2373 | foreach ($theme_includes as $include) |
| 2243 | 2374 | { |
| 2244 | 2375 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
| 2245 | - if (file_exists($include)) |
|
| 2246 | - require_once($include); |
|
| 2376 | + if (file_exists($include)) { |
|
| 2377 | + require_once($include); |
|
| 2378 | + } |
|
| 2247 | 2379 | } |
| 2248 | 2380 | } |
| 2249 | 2381 | |
@@ -2273,16 +2405,19 @@ discard block |
||
| 2273 | 2405 | // Do any style sheets first, cause we're easy with those. |
| 2274 | 2406 | if (!empty($style_sheets)) |
| 2275 | 2407 | { |
| 2276 | - if (!is_array($style_sheets)) |
|
| 2277 | - $style_sheets = array($style_sheets); |
|
| 2408 | + if (!is_array($style_sheets)) { |
|
| 2409 | + $style_sheets = array($style_sheets); |
|
| 2410 | + } |
|
| 2278 | 2411 | |
| 2279 | - foreach ($style_sheets as $sheet) |
|
| 2280 | - loadCSSFile($sheet . '.css', array(), $sheet); |
|
| 2412 | + foreach ($style_sheets as $sheet) { |
|
| 2413 | + loadCSSFile($sheet . '.css', array(), $sheet); |
|
| 2414 | + } |
|
| 2281 | 2415 | } |
| 2282 | 2416 | |
| 2283 | 2417 | // No template to load? |
| 2284 | - if ($template_name === false) |
|
| 2285 | - return true; |
|
| 2418 | + if ($template_name === false) { |
|
| 2419 | + return true; |
|
| 2420 | + } |
|
| 2286 | 2421 | |
| 2287 | 2422 | $loaded = false; |
| 2288 | 2423 | foreach ($settings['template_dirs'] as $template_dir) |
@@ -2297,12 +2432,14 @@ discard block |
||
| 2297 | 2432 | |
| 2298 | 2433 | if ($loaded) |
| 2299 | 2434 | { |
| 2300 | - if ($db_show_debug === true) |
|
| 2301 | - $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
| 2435 | + if ($db_show_debug === true) { |
|
| 2436 | + $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
| 2437 | + } |
|
| 2302 | 2438 | |
| 2303 | 2439 | // If they have specified an initialization function for this template, go ahead and call it now. |
| 2304 | - if (function_exists('template_' . $template_name . '_init')) |
|
| 2305 | - call_user_func('template_' . $template_name . '_init'); |
|
| 2440 | + if (function_exists('template_' . $template_name . '_init')) { |
|
| 2441 | + call_user_func('template_' . $template_name . '_init'); |
|
| 2442 | + } |
|
| 2306 | 2443 | } |
| 2307 | 2444 | // Hmmm... doesn't exist?! I don't suppose the directory is wrong, is it? |
| 2308 | 2445 | elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default')) |
@@ -2322,13 +2459,14 @@ discard block |
||
| 2322 | 2459 | loadTemplate($template_name); |
| 2323 | 2460 | } |
| 2324 | 2461 | // Cause an error otherwise. |
| 2325 | - elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) |
|
| 2326 | - fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
| 2327 | - elseif ($fatal) |
|
| 2328 | - 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')); |
|
| 2329 | - else |
|
| 2330 | - return false; |
|
| 2331 | -} |
|
| 2462 | + elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) { |
|
| 2463 | + fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
| 2464 | + } elseif ($fatal) { |
|
| 2465 | + 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')); |
|
| 2466 | + } else { |
|
| 2467 | + return false; |
|
| 2468 | + } |
|
| 2469 | + } |
|
| 2332 | 2470 | |
| 2333 | 2471 | /** |
| 2334 | 2472 | * Load a sub-template. |
@@ -2346,17 +2484,19 @@ discard block |
||
| 2346 | 2484 | { |
| 2347 | 2485 | global $context, $txt, $db_show_debug; |
| 2348 | 2486 | |
| 2349 | - if ($db_show_debug === true) |
|
| 2350 | - $context['debug']['sub_templates'][] = $sub_template_name; |
|
| 2487 | + if ($db_show_debug === true) { |
|
| 2488 | + $context['debug']['sub_templates'][] = $sub_template_name; |
|
| 2489 | + } |
|
| 2351 | 2490 | |
| 2352 | 2491 | // Figure out what the template function is named. |
| 2353 | 2492 | $theme_function = 'template_' . $sub_template_name; |
| 2354 | - if (function_exists($theme_function)) |
|
| 2355 | - $theme_function(); |
|
| 2356 | - elseif ($fatal === false) |
|
| 2357 | - fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
| 2358 | - elseif ($fatal !== 'ignore') |
|
| 2359 | - 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')); |
|
| 2493 | + if (function_exists($theme_function)) { |
|
| 2494 | + $theme_function(); |
|
| 2495 | + } elseif ($fatal === false) { |
|
| 2496 | + fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
| 2497 | + } elseif ($fatal !== 'ignore') { |
|
| 2498 | + 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')); |
|
| 2499 | + } |
|
| 2360 | 2500 | |
| 2361 | 2501 | // Are we showing debugging for templates? Just make sure not to do it before the doctype... |
| 2362 | 2502 | if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml'])) |
@@ -2393,8 +2533,9 @@ discard block |
||
| 2393 | 2533 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
| 2394 | 2534 | |
| 2395 | 2535 | // If this is an external file, automatically set this to false. |
| 2396 | - if (!empty($params['external'])) |
|
| 2397 | - $params['minimize'] = false; |
|
| 2536 | + if (!empty($params['external'])) { |
|
| 2537 | + $params['minimize'] = false; |
|
| 2538 | + } |
|
| 2398 | 2539 | |
| 2399 | 2540 | // Account for shorthand like admin.css?alp21 filenames |
| 2400 | 2541 | $has_seed = strpos($fileName, '.css?'); |
@@ -2411,13 +2552,10 @@ discard block |
||
| 2411 | 2552 | { |
| 2412 | 2553 | $fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2413 | 2554 | $filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2555 | + } else { |
|
| 2556 | + $fileUrl = false; |
|
| 2414 | 2557 | } |
| 2415 | - |
|
| 2416 | - else |
|
| 2417 | - $fileUrl = false; |
|
| 2418 | - } |
|
| 2419 | - |
|
| 2420 | - else |
|
| 2558 | + } else |
|
| 2421 | 2559 | { |
| 2422 | 2560 | $fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2423 | 2561 | $filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2432,12 +2570,14 @@ discard block |
||
| 2432 | 2570 | } |
| 2433 | 2571 | |
| 2434 | 2572 | // Add it to the array for use in the template |
| 2435 | - if (!empty($fileName)) |
|
| 2436 | - $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2573 | + if (!empty($fileName)) { |
|
| 2574 | + $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2575 | + } |
|
| 2437 | 2576 | |
| 2438 | - if (!empty($context['right_to_left']) && !empty($params['rtl'])) |
|
| 2439 | - loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
| 2440 | -} |
|
| 2577 | + if (!empty($context['right_to_left']) && !empty($params['rtl'])) { |
|
| 2578 | + loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
| 2579 | + } |
|
| 2580 | + } |
|
| 2441 | 2581 | |
| 2442 | 2582 | /** |
| 2443 | 2583 | * Add a block of inline css code to be executed later |
@@ -2454,8 +2594,9 @@ discard block |
||
| 2454 | 2594 | global $context; |
| 2455 | 2595 | |
| 2456 | 2596 | // Gotta add something... |
| 2457 | - if (empty($css)) |
|
| 2458 | - return false; |
|
| 2597 | + if (empty($css)) { |
|
| 2598 | + return false; |
|
| 2599 | + } |
|
| 2459 | 2600 | |
| 2460 | 2601 | $context['css_header'][] = $css; |
| 2461 | 2602 | } |
@@ -2490,8 +2631,9 @@ discard block |
||
| 2490 | 2631 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
| 2491 | 2632 | |
| 2492 | 2633 | // If this is an external file, automatically set this to false. |
| 2493 | - if (!empty($params['external'])) |
|
| 2494 | - $params['minimize'] = false; |
|
| 2634 | + if (!empty($params['external'])) { |
|
| 2635 | + $params['minimize'] = false; |
|
| 2636 | + } |
|
| 2495 | 2637 | |
| 2496 | 2638 | // Account for shorthand like admin.js?alp21 filenames |
| 2497 | 2639 | $has_seed = strpos($fileName, '.js?'); |
@@ -2508,16 +2650,12 @@ discard block |
||
| 2508 | 2650 | { |
| 2509 | 2651 | $fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2510 | 2652 | $filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2511 | - } |
|
| 2512 | - |
|
| 2513 | - else |
|
| 2653 | + } else |
|
| 2514 | 2654 | { |
| 2515 | 2655 | $fileUrl = false; |
| 2516 | 2656 | $filePath = false; |
| 2517 | 2657 | } |
| 2518 | - } |
|
| 2519 | - |
|
| 2520 | - else |
|
| 2658 | + } else |
|
| 2521 | 2659 | { |
| 2522 | 2660 | $fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2523 | 2661 | $filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2532,9 +2670,10 @@ discard block |
||
| 2532 | 2670 | } |
| 2533 | 2671 | |
| 2534 | 2672 | // Add it to the array for use in the template |
| 2535 | - if (!empty($fileName)) |
|
| 2536 | - $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2537 | -} |
|
| 2673 | + if (!empty($fileName)) { |
|
| 2674 | + $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2675 | + } |
|
| 2676 | + } |
|
| 2538 | 2677 | |
| 2539 | 2678 | /** |
| 2540 | 2679 | * Add a Javascript variable for output later (for feeding text strings and similar to JS) |
@@ -2548,9 +2687,10 @@ discard block |
||
| 2548 | 2687 | { |
| 2549 | 2688 | global $context; |
| 2550 | 2689 | |
| 2551 | - if (!empty($key) && (!empty($value) || $value === '0')) |
|
| 2552 | - $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
| 2553 | -} |
|
| 2690 | + if (!empty($key) && (!empty($value) || $value === '0')) { |
|
| 2691 | + $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
| 2692 | + } |
|
| 2693 | + } |
|
| 2554 | 2694 | |
| 2555 | 2695 | /** |
| 2556 | 2696 | * Add a block of inline Javascript code to be executed later |
@@ -2567,8 +2707,9 @@ discard block |
||
| 2567 | 2707 | { |
| 2568 | 2708 | global $context; |
| 2569 | 2709 | |
| 2570 | - if (empty($javascript)) |
|
| 2571 | - return false; |
|
| 2710 | + if (empty($javascript)) { |
|
| 2711 | + return false; |
|
| 2712 | + } |
|
| 2572 | 2713 | |
| 2573 | 2714 | $context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript; |
| 2574 | 2715 | } |
@@ -2589,15 +2730,18 @@ discard block |
||
| 2589 | 2730 | static $already_loaded = array(); |
| 2590 | 2731 | |
| 2591 | 2732 | // Default to the user's language. |
| 2592 | - if ($lang == '') |
|
| 2593 | - $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
| 2733 | + if ($lang == '') { |
|
| 2734 | + $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
| 2735 | + } |
|
| 2594 | 2736 | |
| 2595 | 2737 | // Do we want the English version of language file as fallback? |
| 2596 | - if (empty($modSettings['disable_language_fallback']) && $lang != 'english') |
|
| 2597 | - loadLanguage($template_name, 'english', false); |
|
| 2738 | + if (empty($modSettings['disable_language_fallback']) && $lang != 'english') { |
|
| 2739 | + loadLanguage($template_name, 'english', false); |
|
| 2740 | + } |
|
| 2598 | 2741 | |
| 2599 | - if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) |
|
| 2600 | - return $lang; |
|
| 2742 | + if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) { |
|
| 2743 | + return $lang; |
|
| 2744 | + } |
|
| 2601 | 2745 | |
| 2602 | 2746 | // Make sure we have $settings - if not we're in trouble and need to find it! |
| 2603 | 2747 | if (empty($settings['default_theme_dir'])) |
@@ -2608,8 +2752,9 @@ discard block |
||
| 2608 | 2752 | |
| 2609 | 2753 | // What theme are we in? |
| 2610 | 2754 | $theme_name = basename($settings['theme_url']); |
| 2611 | - if (empty($theme_name)) |
|
| 2612 | - $theme_name = 'unknown'; |
|
| 2755 | + if (empty($theme_name)) { |
|
| 2756 | + $theme_name = 'unknown'; |
|
| 2757 | + } |
|
| 2613 | 2758 | |
| 2614 | 2759 | // For each file open it up and write it out! |
| 2615 | 2760 | foreach (explode('+', $template_name) as $template) |
@@ -2688,8 +2833,9 @@ discard block |
||
| 2688 | 2833 | } |
| 2689 | 2834 | |
| 2690 | 2835 | // Keep track of what we're up to soldier. |
| 2691 | - if ($db_show_debug === true) |
|
| 2692 | - $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
| 2836 | + if ($db_show_debug === true) { |
|
| 2837 | + $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
| 2838 | + } |
|
| 2693 | 2839 | |
| 2694 | 2840 | // Remember what we have loaded, and in which language. |
| 2695 | 2841 | $already_loaded[$template_name] = $lang; |
@@ -2735,8 +2881,9 @@ discard block |
||
| 2735 | 2881 | ) |
| 2736 | 2882 | ); |
| 2737 | 2883 | // In the EXTREMELY unlikely event this happens, give an error message. |
| 2738 | - if ($smcFunc['db_num_rows']($result) == 0) |
|
| 2739 | - fatal_lang_error('parent_not_found', 'critical'); |
|
| 2884 | + if ($smcFunc['db_num_rows']($result) == 0) { |
|
| 2885 | + fatal_lang_error('parent_not_found', 'critical'); |
|
| 2886 | + } |
|
| 2740 | 2887 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 2741 | 2888 | { |
| 2742 | 2889 | if (!isset($boards[$row['id_board']])) |
@@ -2753,8 +2900,8 @@ discard block |
||
| 2753 | 2900 | ); |
| 2754 | 2901 | } |
| 2755 | 2902 | // If a moderator exists for this board, add that moderator for all children too. |
| 2756 | - if (!empty($row['id_moderator'])) |
|
| 2757 | - foreach ($boards as $id => $dummy) |
|
| 2903 | + if (!empty($row['id_moderator'])) { |
|
| 2904 | + foreach ($boards as $id => $dummy) |
|
| 2758 | 2905 | { |
| 2759 | 2906 | $boards[$id]['moderators'][$row['id_moderator']] = array( |
| 2760 | 2907 | 'id' => $row['id_moderator'], |
@@ -2762,11 +2909,12 @@ discard block |
||
| 2762 | 2909 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
| 2763 | 2910 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
| 2764 | 2911 | ); |
| 2912 | + } |
|
| 2765 | 2913 | } |
| 2766 | 2914 | |
| 2767 | 2915 | // If a moderator group exists for this board, add that moderator group for all children too |
| 2768 | - if (!empty($row['id_moderator_group'])) |
|
| 2769 | - foreach ($boards as $id => $dummy) |
|
| 2916 | + if (!empty($row['id_moderator_group'])) { |
|
| 2917 | + foreach ($boards as $id => $dummy) |
|
| 2770 | 2918 | { |
| 2771 | 2919 | $boards[$id]['moderator_groups'][$row['id_moderator_group']] = array( |
| 2772 | 2920 | 'id' => $row['id_moderator_group'], |
@@ -2774,6 +2922,7 @@ discard block |
||
| 2774 | 2922 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
| 2775 | 2923 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
| 2776 | 2924 | ); |
| 2925 | + } |
|
| 2777 | 2926 | } |
| 2778 | 2927 | } |
| 2779 | 2928 | $smcFunc['db_free_result']($result); |
@@ -2801,23 +2950,27 @@ discard block |
||
| 2801 | 2950 | if (!$use_cache || ($context['languages'] = cache_get_data('known_languages' . ($favor_utf8 ? '' : '_all'), !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null) |
| 2802 | 2951 | { |
| 2803 | 2952 | // If we don't have our ucwords function defined yet, let's load the settings data. |
| 2804 | - if (empty($smcFunc['ucwords'])) |
|
| 2805 | - reloadSettings(); |
|
| 2953 | + if (empty($smcFunc['ucwords'])) { |
|
| 2954 | + reloadSettings(); |
|
| 2955 | + } |
|
| 2806 | 2956 | |
| 2807 | 2957 | // If we don't have our theme information yet, let's get it. |
| 2808 | - if (empty($settings['default_theme_dir'])) |
|
| 2809 | - loadTheme(0, false); |
|
| 2958 | + if (empty($settings['default_theme_dir'])) { |
|
| 2959 | + loadTheme(0, false); |
|
| 2960 | + } |
|
| 2810 | 2961 | |
| 2811 | 2962 | // Default language directories to try. |
| 2812 | 2963 | $language_directories = array( |
| 2813 | 2964 | $settings['default_theme_dir'] . '/languages', |
| 2814 | 2965 | ); |
| 2815 | - if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) |
|
| 2816 | - $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
| 2966 | + if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) { |
|
| 2967 | + $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
| 2968 | + } |
|
| 2817 | 2969 | |
| 2818 | 2970 | // We possibly have a base theme directory. |
| 2819 | - if (!empty($settings['base_theme_dir'])) |
|
| 2820 | - $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
| 2971 | + if (!empty($settings['base_theme_dir'])) { |
|
| 2972 | + $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
| 2973 | + } |
|
| 2821 | 2974 | |
| 2822 | 2975 | // Remove any duplicates. |
| 2823 | 2976 | $language_directories = array_unique($language_directories); |
@@ -2831,20 +2984,21 @@ discard block |
||
| 2831 | 2984 | foreach ($language_directories as $language_dir) |
| 2832 | 2985 | { |
| 2833 | 2986 | // Can't look in here... doesn't exist! |
| 2834 | - if (!file_exists($language_dir)) |
|
| 2835 | - continue; |
|
| 2987 | + if (!file_exists($language_dir)) { |
|
| 2988 | + continue; |
|
| 2989 | + } |
|
| 2836 | 2990 | |
| 2837 | 2991 | $dir = dir($language_dir); |
| 2838 | 2992 | while ($entry = $dir->read()) |
| 2839 | 2993 | { |
| 2840 | 2994 | // Look for the index language file.... |
| 2841 | - if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches)) |
|
| 2842 | - continue; |
|
| 2843 | - |
|
| 2844 | - if (!empty($langList) && !empty($langList[$matches[1]])) |
|
| 2845 | - $langName = $langList[$matches[1]]; |
|
| 2995 | + if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches)) { |
|
| 2996 | + continue; |
|
| 2997 | + } |
|
| 2846 | 2998 | |
| 2847 | - else |
|
| 2999 | + if (!empty($langList) && !empty($langList[$matches[1]])) { |
|
| 3000 | + $langName = $langList[$matches[1]]; |
|
| 3001 | + } else |
|
| 2848 | 3002 | { |
| 2849 | 3003 | $langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' '))); |
| 2850 | 3004 | |
@@ -2885,20 +3039,23 @@ discard block |
||
| 2885 | 3039 | } |
| 2886 | 3040 | |
| 2887 | 3041 | // Do we need to store the lang list? |
| 2888 | - if (empty($langList)) |
|
| 2889 | - updateSettings(array('langList' => json_encode($catchLang))); |
|
| 3042 | + if (empty($langList)) { |
|
| 3043 | + updateSettings(array('langList' => json_encode($catchLang))); |
|
| 3044 | + } |
|
| 2890 | 3045 | |
| 2891 | 3046 | // Favoring UTF8? Then prevent us from selecting non-UTF8 versions. |
| 2892 | 3047 | if ($favor_utf8) |
| 2893 | 3048 | { |
| 2894 | - foreach ($context['languages'] as $lang) |
|
| 2895 | - if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8'])) |
|
| 3049 | + foreach ($context['languages'] as $lang) { |
|
| 3050 | + if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8'])) |
|
| 2896 | 3051 | unset($context['languages'][$lang['filename']]); |
| 3052 | + } |
|
| 2897 | 3053 | } |
| 2898 | 3054 | |
| 2899 | 3055 | // Let's cash in on this deal. |
| 2900 | - if (!empty($modSettings['cache_enable'])) |
|
| 2901 | - cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
| 3056 | + if (!empty($modSettings['cache_enable'])) { |
|
| 3057 | + cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
| 3058 | + } |
|
| 2902 | 3059 | } |
| 2903 | 3060 | |
| 2904 | 3061 | return $context['languages']; |
@@ -2921,8 +3078,9 @@ discard block |
||
| 2921 | 3078 | global $modSettings, $options, $txt; |
| 2922 | 3079 | static $censor_vulgar = null, $censor_proper; |
| 2923 | 3080 | |
| 2924 | - if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') |
|
| 2925 | - return $text; |
|
| 3081 | + if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') { |
|
| 3082 | + return $text; |
|
| 3083 | + } |
|
| 2926 | 3084 | |
| 2927 | 3085 | // If they haven't yet been loaded, load them. |
| 2928 | 3086 | if ($censor_vulgar == null) |
@@ -2950,9 +3108,9 @@ discard block |
||
| 2950 | 3108 | { |
| 2951 | 3109 | $func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace'; |
| 2952 | 3110 | $text = $func($censor_vulgar, $censor_proper, $text); |
| 3111 | + } else { |
|
| 3112 | + $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
| 2953 | 3113 | } |
| 2954 | - else |
|
| 2955 | - $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
| 2956 | 3114 | |
| 2957 | 3115 | return $text; |
| 2958 | 3116 | } |
@@ -2978,38 +3136,42 @@ discard block |
||
| 2978 | 3136 | @ini_set('track_errors', '1'); |
| 2979 | 3137 | |
| 2980 | 3138 | // Don't include the file more than once, if $once is true. |
| 2981 | - if ($once && in_array($filename, $templates)) |
|
| 2982 | - return; |
|
| 3139 | + if ($once && in_array($filename, $templates)) { |
|
| 3140 | + return; |
|
| 3141 | + } |
|
| 2983 | 3142 | // Add this file to the include list, whether $once is true or not. |
| 2984 | - else |
|
| 2985 | - $templates[] = $filename; |
|
| 3143 | + else { |
|
| 3144 | + $templates[] = $filename; |
|
| 3145 | + } |
|
| 2986 | 3146 | |
| 2987 | 3147 | // Are we going to use eval? |
| 2988 | 3148 | if (empty($modSettings['disableTemplateEval'])) |
| 2989 | 3149 | { |
| 2990 | 3150 | $file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false; |
| 2991 | 3151 | $settings['current_include_filename'] = $filename; |
| 2992 | - } |
|
| 2993 | - else |
|
| 3152 | + } else |
|
| 2994 | 3153 | { |
| 2995 | 3154 | $file_found = file_exists($filename); |
| 2996 | 3155 | |
| 2997 | - if ($once && $file_found) |
|
| 2998 | - require_once($filename); |
|
| 2999 | - elseif ($file_found) |
|
| 3000 | - require($filename); |
|
| 3156 | + if ($once && $file_found) { |
|
| 3157 | + require_once($filename); |
|
| 3158 | + } elseif ($file_found) { |
|
| 3159 | + require($filename); |
|
| 3160 | + } |
|
| 3001 | 3161 | } |
| 3002 | 3162 | |
| 3003 | 3163 | if ($file_found !== true) |
| 3004 | 3164 | { |
| 3005 | 3165 | ob_end_clean(); |
| 3006 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
| 3007 | - @ob_start('ob_gzhandler'); |
|
| 3008 | - else |
|
| 3009 | - ob_start(); |
|
| 3166 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
| 3167 | + @ob_start('ob_gzhandler'); |
|
| 3168 | + } else { |
|
| 3169 | + ob_start(); |
|
| 3170 | + } |
|
| 3010 | 3171 | |
| 3011 | - if (isset($_GET['debug'])) |
|
| 3012 | - header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3172 | + if (isset($_GET['debug'])) { |
|
| 3173 | + header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3174 | + } |
|
| 3013 | 3175 | |
| 3014 | 3176 | // Don't cache error pages!! |
| 3015 | 3177 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -3028,12 +3190,13 @@ discard block |
||
| 3028 | 3190 | echo '<!DOCTYPE html> |
| 3029 | 3191 | <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '> |
| 3030 | 3192 | <head>'; |
| 3031 | - if (isset($context['character_set'])) |
|
| 3032 | - echo ' |
|
| 3193 | + if (isset($context['character_set'])) { |
|
| 3194 | + echo ' |
|
| 3033 | 3195 | <meta charset="', $context['character_set'], '">'; |
| 3196 | + } |
|
| 3034 | 3197 | |
| 3035 | - if (!empty($maintenance) && !allowedTo('admin_forum')) |
|
| 3036 | - echo ' |
|
| 3198 | + if (!empty($maintenance) && !allowedTo('admin_forum')) { |
|
| 3199 | + echo ' |
|
| 3037 | 3200 | <title>', $mtitle, '</title> |
| 3038 | 3201 | </head> |
| 3039 | 3202 | <body> |
@@ -3041,8 +3204,8 @@ discard block |
||
| 3041 | 3204 | ', $mmessage, ' |
| 3042 | 3205 | </body> |
| 3043 | 3206 | </html>'; |
| 3044 | - elseif (!allowedTo('admin_forum')) |
|
| 3045 | - echo ' |
|
| 3207 | + } elseif (!allowedTo('admin_forum')) { |
|
| 3208 | + echo ' |
|
| 3046 | 3209 | <title>', $txt['template_parse_error'], '</title> |
| 3047 | 3210 | </head> |
| 3048 | 3211 | <body> |
@@ -3050,15 +3213,17 @@ discard block |
||
| 3050 | 3213 | ', $txt['template_parse_error_message'], ' |
| 3051 | 3214 | </body> |
| 3052 | 3215 | </html>'; |
| 3053 | - else |
|
| 3216 | + } else |
|
| 3054 | 3217 | { |
| 3055 | 3218 | require_once($sourcedir . '/Subs-Package.php'); |
| 3056 | 3219 | |
| 3057 | 3220 | $error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
| 3058 | - if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) |
|
| 3059 | - $error = $php_errormsg; |
|
| 3060 | - if (empty($error)) |
|
| 3061 | - $error = $txt['template_parse_errmsg']; |
|
| 3221 | + if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) { |
|
| 3222 | + $error = $php_errormsg; |
|
| 3223 | + } |
|
| 3224 | + if (empty($error)) { |
|
| 3225 | + $error = $txt['template_parse_errmsg']; |
|
| 3226 | + } |
|
| 3062 | 3227 | |
| 3063 | 3228 | $error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>')); |
| 3064 | 3229 | |
@@ -3069,11 +3234,12 @@ discard block |
||
| 3069 | 3234 | <h3>', $txt['template_parse_error'], '</h3> |
| 3070 | 3235 | ', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
| 3071 | 3236 | |
| 3072 | - if (!empty($error)) |
|
| 3073 | - echo ' |
|
| 3237 | + if (!empty($error)) { |
|
| 3238 | + echo ' |
|
| 3074 | 3239 | <hr> |
| 3075 | 3240 | |
| 3076 | 3241 | <div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>'; |
| 3242 | + } |
|
| 3077 | 3243 | |
| 3078 | 3244 | // I know, I know... this is VERY COMPLICATED. Still, it's good. |
| 3079 | 3245 | if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0) |
@@ -3083,10 +3249,11 @@ discard block |
||
| 3083 | 3249 | $data2 = preg_split('~\<br( /)?\>~', $data2); |
| 3084 | 3250 | |
| 3085 | 3251 | // Fix the PHP code stuff... |
| 3086 | - if (!isBrowser('gecko')) |
|
| 3087 | - $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
| 3088 | - else |
|
| 3089 | - $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
| 3252 | + if (!isBrowser('gecko')) { |
|
| 3253 | + $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
| 3254 | + } else { |
|
| 3255 | + $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
| 3256 | + } |
|
| 3090 | 3257 | |
| 3091 | 3258 | // Now we get to work around a bug in PHP where it doesn't escape <br>s! |
| 3092 | 3259 | $j = -1; |
@@ -3094,8 +3261,9 @@ discard block |
||
| 3094 | 3261 | { |
| 3095 | 3262 | $j++; |
| 3096 | 3263 | |
| 3097 | - if (substr_count($line, '<br>') == 0) |
|
| 3098 | - continue; |
|
| 3264 | + if (substr_count($line, '<br>') == 0) { |
|
| 3265 | + continue; |
|
| 3266 | + } |
|
| 3099 | 3267 | |
| 3100 | 3268 | $n = substr_count($line, '<br>'); |
| 3101 | 3269 | for ($i = 0; $i < $n; $i++) |
@@ -3114,38 +3282,42 @@ discard block |
||
| 3114 | 3282 | // Figure out what the color coding was before... |
| 3115 | 3283 | $line = max($match[1] - 9, 1); |
| 3116 | 3284 | $last_line = ''; |
| 3117 | - for ($line2 = $line - 1; $line2 > 1; $line2--) |
|
| 3118 | - if (strpos($data2[$line2], '<') !== false) |
|
| 3285 | + for ($line2 = $line - 1; $line2 > 1; $line2--) { |
|
| 3286 | + if (strpos($data2[$line2], '<') !== false) |
|
| 3119 | 3287 | { |
| 3120 | 3288 | if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0) |
| 3121 | 3289 | $last_line = $color_match[1]; |
| 3290 | + } |
|
| 3122 | 3291 | break; |
| 3123 | 3292 | } |
| 3124 | 3293 | |
| 3125 | 3294 | // Show the relevant lines... |
| 3126 | 3295 | for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++) |
| 3127 | 3296 | { |
| 3128 | - if ($line == $match[1]) |
|
| 3129 | - echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
| 3297 | + if ($line == $match[1]) { |
|
| 3298 | + echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
| 3299 | + } |
|
| 3130 | 3300 | |
| 3131 | 3301 | echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> '; |
| 3132 | - if (isset($data2[$line]) && $data2[$line] != '') |
|
| 3133 | - echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
| 3302 | + if (isset($data2[$line]) && $data2[$line] != '') { |
|
| 3303 | + echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
| 3304 | + } |
|
| 3134 | 3305 | |
| 3135 | 3306 | if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0) |
| 3136 | 3307 | { |
| 3137 | 3308 | $last_line = $color_match[1]; |
| 3138 | 3309 | echo '</', substr($last_line, 1, 4), '>'; |
| 3310 | + } elseif ($last_line != '' && strpos($data2[$line], '<') !== false) { |
|
| 3311 | + $last_line = ''; |
|
| 3312 | + } elseif ($last_line != '' && $data2[$line] != '') { |
|
| 3313 | + echo '</', substr($last_line, 1, 4), '>'; |
|
| 3139 | 3314 | } |
| 3140 | - elseif ($last_line != '' && strpos($data2[$line], '<') !== false) |
|
| 3141 | - $last_line = ''; |
|
| 3142 | - elseif ($last_line != '' && $data2[$line] != '') |
|
| 3143 | - echo '</', substr($last_line, 1, 4), '>'; |
|
| 3144 | 3315 | |
| 3145 | - if ($line == $match[1]) |
|
| 3146 | - echo '</pre></div><pre style="margin: 0;">'; |
|
| 3147 | - else |
|
| 3148 | - echo "\n"; |
|
| 3316 | + if ($line == $match[1]) { |
|
| 3317 | + echo '</pre></div><pre style="margin: 0;">'; |
|
| 3318 | + } else { |
|
| 3319 | + echo "\n"; |
|
| 3320 | + } |
|
| 3149 | 3321 | } |
| 3150 | 3322 | |
| 3151 | 3323 | echo '</pre></div>'; |
@@ -3169,8 +3341,9 @@ discard block |
||
| 3169 | 3341 | global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port; |
| 3170 | 3342 | |
| 3171 | 3343 | // Figure out what type of database we are using. |
| 3172 | - if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
|
| 3173 | - $db_type = 'mysql'; |
|
| 3344 | + if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) { |
|
| 3345 | + $db_type = 'mysql'; |
|
| 3346 | + } |
|
| 3174 | 3347 | |
| 3175 | 3348 | // Load the file for the database. |
| 3176 | 3349 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
@@ -3178,8 +3351,9 @@ discard block |
||
| 3178 | 3351 | $db_options = array(); |
| 3179 | 3352 | |
| 3180 | 3353 | // Add in the port if needed |
| 3181 | - if (!empty($db_port)) |
|
| 3182 | - $db_options['port'] = $db_port; |
|
| 3354 | + if (!empty($db_port)) { |
|
| 3355 | + $db_options['port'] = $db_port; |
|
| 3356 | + } |
|
| 3183 | 3357 | |
| 3184 | 3358 | // 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. |
| 3185 | 3359 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
@@ -3198,13 +3372,15 @@ discard block |
||
| 3198 | 3372 | } |
| 3199 | 3373 | |
| 3200 | 3374 | // Safe guard here, if there isn't a valid connection lets put a stop to it. |
| 3201 | - if (!$db_connection) |
|
| 3202 | - display_db_error(); |
|
| 3375 | + if (!$db_connection) { |
|
| 3376 | + display_db_error(); |
|
| 3377 | + } |
|
| 3203 | 3378 | |
| 3204 | 3379 | // If in SSI mode fix up the prefix. |
| 3205 | - if (SMF == 'SSI') |
|
| 3206 | - db_fix_prefix($db_prefix, $db_name); |
|
| 3207 | -} |
|
| 3380 | + if (SMF == 'SSI') { |
|
| 3381 | + db_fix_prefix($db_prefix, $db_name); |
|
| 3382 | + } |
|
| 3383 | + } |
|
| 3208 | 3384 | |
| 3209 | 3385 | /** |
| 3210 | 3386 | * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it. |
@@ -3218,10 +3394,11 @@ discard block |
||
| 3218 | 3394 | global $sourcedir, $cacheAPI, $cache_accelerator; |
| 3219 | 3395 | |
| 3220 | 3396 | // Not overriding this and we have a cacheAPI, send it back. |
| 3221 | - if (empty($overrideCache) && is_object($cacheAPI)) |
|
| 3222 | - return $cacheAPI; |
|
| 3223 | - elseif (is_null($cacheAPI)) |
|
| 3224 | - $cacheAPI = false; |
|
| 3397 | + if (empty($overrideCache) && is_object($cacheAPI)) { |
|
| 3398 | + return $cacheAPI; |
|
| 3399 | + } elseif (is_null($cacheAPI)) { |
|
| 3400 | + $cacheAPI = false; |
|
| 3401 | + } |
|
| 3225 | 3402 | |
| 3226 | 3403 | // Make sure our class is in session. |
| 3227 | 3404 | require_once($sourcedir . '/Class-CacheAPI.php'); |
@@ -3242,8 +3419,9 @@ discard block |
||
| 3242 | 3419 | if (!$testAPI->isSupported()) |
| 3243 | 3420 | { |
| 3244 | 3421 | // Can we save ourselves? |
| 3245 | - if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') |
|
| 3246 | - return loadCacheAccelerator(null, false); |
|
| 3422 | + if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') { |
|
| 3423 | + return loadCacheAccelerator(null, false); |
|
| 3424 | + } |
|
| 3247 | 3425 | return false; |
| 3248 | 3426 | } |
| 3249 | 3427 | |
@@ -3255,9 +3433,9 @@ discard block |
||
| 3255 | 3433 | { |
| 3256 | 3434 | $cacheAPI = $testAPI; |
| 3257 | 3435 | return $cacheAPI; |
| 3436 | + } else { |
|
| 3437 | + return $testAPI; |
|
| 3258 | 3438 | } |
| 3259 | - else |
|
| 3260 | - return $testAPI; |
|
| 3261 | 3439 | } |
| 3262 | 3440 | } |
| 3263 | 3441 | |
@@ -3277,8 +3455,9 @@ discard block |
||
| 3277 | 3455 | |
| 3278 | 3456 | // @todo Why are we doing this if caching is disabled? |
| 3279 | 3457 | |
| 3280 | - if (function_exists('call_integration_hook')) |
|
| 3281 | - call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
| 3458 | + if (function_exists('call_integration_hook')) { |
|
| 3459 | + call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
| 3460 | + } |
|
| 3282 | 3461 | |
| 3283 | 3462 | /* Refresh the cache if either: |
| 3284 | 3463 | 1. Caching is disabled. |
@@ -3292,16 +3471,19 @@ discard block |
||
| 3292 | 3471 | require_once($sourcedir . '/' . $file); |
| 3293 | 3472 | $cache_block = call_user_func_array($function, $params); |
| 3294 | 3473 | |
| 3295 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) |
|
| 3296 | - cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
| 3474 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) { |
|
| 3475 | + cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
| 3476 | + } |
|
| 3297 | 3477 | } |
| 3298 | 3478 | |
| 3299 | 3479 | // Some cached data may need a freshening up after retrieval. |
| 3300 | - if (!empty($cache_block['post_retri_eval'])) |
|
| 3301 | - eval($cache_block['post_retri_eval']); |
|
| 3480 | + if (!empty($cache_block['post_retri_eval'])) { |
|
| 3481 | + eval($cache_block['post_retri_eval']); |
|
| 3482 | + } |
|
| 3302 | 3483 | |
| 3303 | - if (function_exists('call_integration_hook')) |
|
| 3304 | - call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
| 3484 | + if (function_exists('call_integration_hook')) { |
|
| 3485 | + call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
| 3486 | + } |
|
| 3305 | 3487 | |
| 3306 | 3488 | return $cache_block['data']; |
| 3307 | 3489 | } |
@@ -3328,8 +3510,9 @@ discard block |
||
| 3328 | 3510 | global $boardurl, $modSettings, $cache_enable, $cacheAPI; |
| 3329 | 3511 | global $cache_hits, $cache_count, $db_show_debug; |
| 3330 | 3512 | |
| 3331 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
| 3332 | - return; |
|
| 3513 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
| 3514 | + return; |
|
| 3515 | + } |
|
| 3333 | 3516 | |
| 3334 | 3517 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
| 3335 | 3518 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3342,12 +3525,14 @@ discard block |
||
| 3342 | 3525 | $value = $value === null ? null : json_encode($value); |
| 3343 | 3526 | $cacheAPI->putData($key, $value, $ttl); |
| 3344 | 3527 | |
| 3345 | - if (function_exists('call_integration_hook')) |
|
| 3346 | - call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
| 3528 | + if (function_exists('call_integration_hook')) { |
|
| 3529 | + call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
| 3530 | + } |
|
| 3347 | 3531 | |
| 3348 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 3349 | - $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 3350 | -} |
|
| 3532 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 3533 | + $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 3534 | + } |
|
| 3535 | + } |
|
| 3351 | 3536 | |
| 3352 | 3537 | /** |
| 3353 | 3538 | * Gets the value from the cache specified by key, so long as it is not older than ttl seconds. |
@@ -3363,8 +3548,9 @@ discard block |
||
| 3363 | 3548 | global $boardurl, $modSettings, $cache_enable, $cacheAPI; |
| 3364 | 3549 | global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug; |
| 3365 | 3550 | |
| 3366 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
| 3367 | - return; |
|
| 3551 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
| 3552 | + return; |
|
| 3553 | + } |
|
| 3368 | 3554 | |
| 3369 | 3555 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
| 3370 | 3556 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3384,16 +3570,18 @@ discard block |
||
| 3384 | 3570 | |
| 3385 | 3571 | if (empty($value)) |
| 3386 | 3572 | { |
| 3387 | - if (!is_array($cache_misses)) |
|
| 3388 | - $cache_misses = array(); |
|
| 3573 | + if (!is_array($cache_misses)) { |
|
| 3574 | + $cache_misses = array(); |
|
| 3575 | + } |
|
| 3389 | 3576 | |
| 3390 | 3577 | $cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1; |
| 3391 | 3578 | $cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get'); |
| 3392 | 3579 | } |
| 3393 | 3580 | } |
| 3394 | 3581 | |
| 3395 | - if (function_exists('call_integration_hook') && isset($value)) |
|
| 3396 | - call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
| 3582 | + if (function_exists('call_integration_hook') && isset($value)) { |
|
| 3583 | + call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
| 3584 | + } |
|
| 3397 | 3585 | |
| 3398 | 3586 | return empty($value) ? null : smf_json_decode($value, true); |
| 3399 | 3587 | } |
@@ -3415,8 +3603,9 @@ discard block |
||
| 3415 | 3603 | global $cacheAPI; |
| 3416 | 3604 | |
| 3417 | 3605 | // If we can't get to the API, can't do this. |
| 3418 | - if (empty($cacheAPI)) |
|
| 3419 | - return; |
|
| 3606 | + if (empty($cacheAPI)) { |
|
| 3607 | + return; |
|
| 3608 | + } |
|
| 3420 | 3609 | |
| 3421 | 3610 | // Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure. |
| 3422 | 3611 | $cacheAPI->cleanCache($type); |
@@ -3441,8 +3630,9 @@ discard block |
||
| 3441 | 3630 | global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret; |
| 3442 | 3631 | |
| 3443 | 3632 | // Come on! |
| 3444 | - if (empty($data)) |
|
| 3445 | - return array(); |
|
| 3633 | + if (empty($data)) { |
|
| 3634 | + return array(); |
|
| 3635 | + } |
|
| 3446 | 3636 | |
| 3447 | 3637 | // Set a nice default var. |
| 3448 | 3638 | $image = ''; |
@@ -3450,11 +3640,11 @@ discard block |
||
| 3450 | 3640 | // Gravatar has been set as mandatory! |
| 3451 | 3641 | if (!empty($modSettings['gravatarOverride'])) |
| 3452 | 3642 | { |
| 3453 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) |
|
| 3454 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3455 | - |
|
| 3456 | - else if (!empty($data['email'])) |
|
| 3457 | - $image = get_gravatar_url($data['email']); |
|
| 3643 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) { |
|
| 3644 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3645 | + } else if (!empty($data['email'])) { |
|
| 3646 | + $image = get_gravatar_url($data['email']); |
|
| 3647 | + } |
|
| 3458 | 3648 | } |
| 3459 | 3649 | |
| 3460 | 3650 | // Look if the user has a gravatar field or has set an external url as avatar. |
@@ -3466,54 +3656,60 @@ discard block |
||
| 3466 | 3656 | // Gravatar. |
| 3467 | 3657 | if (stristr($data['avatar'], 'gravatar://')) |
| 3468 | 3658 | { |
| 3469 | - if ($data['avatar'] == 'gravatar://') |
|
| 3470 | - $image = get_gravatar_url($data['email']); |
|
| 3471 | - |
|
| 3472 | - elseif (!empty($modSettings['gravatarAllowExtraEmail'])) |
|
| 3473 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3659 | + if ($data['avatar'] == 'gravatar://') { |
|
| 3660 | + $image = get_gravatar_url($data['email']); |
|
| 3661 | + } elseif (!empty($modSettings['gravatarAllowExtraEmail'])) { |
|
| 3662 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3663 | + } |
|
| 3474 | 3664 | } |
| 3475 | 3665 | |
| 3476 | 3666 | // External url. |
| 3477 | 3667 | else |
| 3478 | 3668 | { |
| 3479 | 3669 | // Using ssl? |
| 3480 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) |
|
| 3481 | - $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
| 3670 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) { |
|
| 3671 | + $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
| 3672 | + } |
|
| 3482 | 3673 | |
| 3483 | 3674 | // Just a plain external url. |
| 3484 | - else |
|
| 3485 | - $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
| 3675 | + else { |
|
| 3676 | + $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
| 3677 | + } |
|
| 3486 | 3678 | } |
| 3487 | 3679 | } |
| 3488 | 3680 | |
| 3489 | 3681 | // Perhaps this user has an attachment as avatar... |
| 3490 | - else if (!empty($data['filename'])) |
|
| 3491 | - $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
| 3682 | + else if (!empty($data['filename'])) { |
|
| 3683 | + $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
| 3684 | + } |
|
| 3492 | 3685 | |
| 3493 | 3686 | // Right... no avatar... use our default image. |
| 3494 | - else |
|
| 3495 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 3687 | + else { |
|
| 3688 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 3689 | + } |
|
| 3496 | 3690 | } |
| 3497 | 3691 | |
| 3498 | 3692 | call_integration_hook('integrate_set_avatar_data', array(&$image, &$data)); |
| 3499 | 3693 | |
| 3500 | 3694 | // 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. |
| 3501 | - if (!empty($image)) |
|
| 3502 | - return array( |
|
| 3695 | + if (!empty($image)) { |
|
| 3696 | + return array( |
|
| 3503 | 3697 | 'name' => !empty($data['avatar']) ? $data['avatar'] : '', |
| 3504 | 3698 | 'image' => '<img class="avatar" src="' . $image . '" />', |
| 3505 | 3699 | 'href' => $image, |
| 3506 | 3700 | 'url' => $image, |
| 3507 | 3701 | ); |
| 3702 | + } |
|
| 3508 | 3703 | |
| 3509 | 3704 | // Fallback to make life easier for everyone... |
| 3510 | - else |
|
| 3511 | - return array( |
|
| 3705 | + else { |
|
| 3706 | + return array( |
|
| 3512 | 3707 | 'name' => '', |
| 3513 | 3708 | 'image' => '', |
| 3514 | 3709 | 'href' => '', |
| 3515 | 3710 | 'url' => '', |
| 3516 | 3711 | ); |
| 3517 | -} |
|
| 3712 | + } |
|
| 3713 | + } |
|
| 3518 | 3714 | |
| 3519 | 3715 | ?> |