@@ -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 | { |
@@ -59,13 +59,13 @@ discard block |
||
| 59 | 59 | ); |
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | - * Start the curl object |
|
| 63 | - * - allow for user override values |
|
| 64 | - * |
|
| 65 | - * @param array $options An array of cURL options |
|
| 66 | - * @param int $max_redirect Maximum number of redirects |
|
| 67 | - * @return void |
|
| 68 | - */ |
|
| 62 | + * Start the curl object |
|
| 63 | + * - allow for user override values |
|
| 64 | + * |
|
| 65 | + * @param array $options An array of cURL options |
|
| 66 | + * @param int $max_redirect Maximum number of redirects |
|
| 67 | + * @return void |
|
| 68 | + */ |
|
| 69 | 69 | public function __construct($options = array(), $max_redirect = 3) |
| 70 | 70 | { |
| 71 | 71 | // Initialize class variables |
@@ -74,16 +74,16 @@ discard block |
||
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | - * Main calling function, |
|
| 78 | - * - will request the page data from a given $url |
|
| 79 | - * - optionally will post data to the page form if post data is supplied |
|
| 80 | - * - passed arrays will be converted to a post string joined with &'s |
|
| 81 | - * - calls set_options to set the curl opts array values based on the defaults and user input |
|
| 82 | - * |
|
| 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 |
|
| 86 | - */ |
|
| 77 | + * Main calling function, |
|
| 78 | + * - will request the page data from a given $url |
|
| 79 | + * - optionally will post data to the page form if post data is supplied |
|
| 80 | + * - passed arrays will be converted to a post string joined with &'s |
|
| 81 | + * - calls set_options to set the curl opts array values based on the defaults and user input |
|
| 82 | + * |
|
| 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 |
|
| 86 | + */ |
|
| 87 | 87 | public function get_url_data($url, $post_data = array()) |
| 88 | 88 | { |
| 89 | 89 | // POSTing some data perhaps? |
@@ -100,14 +100,14 @@ discard block |
||
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
| 103 | - * Makes the actual cURL call |
|
| 104 | - * - stores responses (url, code, error, headers, body) in the response array |
|
| 105 | - * - detects 301, 302, 307 codes and will redirect to the given response header location |
|
| 106 | - * |
|
| 107 | - * @param string $url The site to fetch |
|
| 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 |
|
| 110 | - */ |
|
| 103 | + * Makes the actual cURL call |
|
| 104 | + * - stores responses (url, code, error, headers, body) in the response array |
|
| 105 | + * - detects 301, 302, 307 codes and will redirect to the given response header location |
|
| 106 | + * |
|
| 107 | + * @param string $url The site to fetch |
|
| 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 |
|
| 110 | + */ |
|
| 111 | 111 | private function curl_request($url, $redirect = false) |
| 112 | 112 | { |
| 113 | 113 | // we do have a url I hope |
@@ -159,12 +159,12 @@ discard block |
||
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
| 162 | - * Used if being redirected to ensure we have a fully qualified address |
|
| 163 | - * |
|
| 164 | - * @param string $last_url The URL we went to |
|
| 165 | - * @param string $new_url The URL we were redirected to |
|
| 166 | - * @return string The new URL that was in the HTTP header |
|
| 167 | - */ |
|
| 162 | + * Used if being redirected to ensure we have a fully qualified address |
|
| 163 | + * |
|
| 164 | + * @param string $last_url The URL we went to |
|
| 165 | + * @param string $new_url The URL we were redirected to |
|
| 166 | + * @return string The new URL that was in the HTTP header |
|
| 167 | + */ |
|
| 168 | 168 | private function get_redirect_url($last_url = '', $new_url = '') |
| 169 | 169 | { |
| 170 | 170 | // Get the elements for these urls |
@@ -182,13 +182,13 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | - * Used to return the results to the calling program |
|
| 186 | - * - called as ->result() will return the full final array |
|
| 187 | - * - called as ->result('body') to just return the page source of the result |
|
| 188 | - * |
|
| 189 | - * @param string $area Used to return an area such as body, header, error |
|
| 190 | - * @return string The response |
|
| 191 | - */ |
|
| 185 | + * Used to return the results to the calling program |
|
| 186 | + * - called as ->result() will return the full final array |
|
| 187 | + * - called as ->result('body') to just return the page source of the result |
|
| 188 | + * |
|
| 189 | + * @param string $area Used to return an area such as body, header, error |
|
| 190 | + * @return string The response |
|
| 191 | + */ |
|
| 192 | 192 | public function result($area = '') |
| 193 | 193 | { |
| 194 | 194 | $max_result = count($this->response) - 1; |
@@ -201,13 +201,13 @@ discard block |
||
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
| 204 | - * Will return all results from all loops (redirects) |
|
| 205 | - * - Can be called as ->result_raw(x) where x is a specific loop results. |
|
| 206 | - * - Call as ->result_raw() for everything. |
|
| 207 | - * |
|
| 208 | - * @param string $response_number Which response we want to get |
|
| 209 | - * @return array|string The entire response array or just the specified response |
|
| 210 | - */ |
|
| 204 | + * Will return all results from all loops (redirects) |
|
| 205 | + * - Can be called as ->result_raw(x) where x is a specific loop results. |
|
| 206 | + * - Call as ->result_raw() for everything. |
|
| 207 | + * |
|
| 208 | + * @param string $response_number Which response we want to get |
|
| 209 | + * @return array|string The entire response array or just the specified response |
|
| 210 | + */ |
|
| 211 | 211 | public function result_raw($response_number = '') |
| 212 | 212 | { |
| 213 | 213 | if (!is_numeric($response_number)) |
@@ -220,13 +220,13 @@ discard block |
||
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
| 223 | - * Takes supplied POST data and url encodes it |
|
| 224 | - * - forms the date (for post) in to a string var=xyz&var2=abc&var3=123 |
|
| 225 | - * - drops vars with @ since we don't support sending files (uploading) |
|
| 226 | - * |
|
| 227 | - * @param array|string $post_data The raw POST data |
|
| 228 | - * @return string A string of post data |
|
| 229 | - */ |
|
| 223 | + * Takes supplied POST data and url encodes it |
|
| 224 | + * - forms the date (for post) in to a string var=xyz&var2=abc&var3=123 |
|
| 225 | + * - drops vars with @ since we don't support sending files (uploading) |
|
| 226 | + * |
|
| 227 | + * @param array|string $post_data The raw POST data |
|
| 228 | + * @return string A string of post data |
|
| 229 | + */ |
|
| 230 | 230 | private function build_post_data($post_data) |
| 231 | 231 | { |
| 232 | 232 | if (is_array($post_data)) |
@@ -245,11 +245,11 @@ discard block |
||
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
| 248 | - * Sets the final cURL options for the current call |
|
| 249 | - * - overwrites our default values with user supplied ones or appends new user ones to what we have |
|
| 250 | - * - sets the callback function now that $this is existing |
|
| 251 | - * @return void |
|
| 252 | - */ |
|
| 248 | + * Sets the final cURL options for the current call |
|
| 249 | + * - overwrites our default values with user supplied ones or appends new user ones to what we have |
|
| 250 | + * - sets the callback function now that $this is existing |
|
| 251 | + * @return void |
|
| 252 | + */ |
|
| 253 | 253 | private function set_options() |
| 254 | 254 | { |
| 255 | 255 | // Callback to parse the returned headers, if any |
@@ -274,12 +274,12 @@ discard block |
||
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
| 277 | - * Called to initiate a redirect from a 301, 302 or 307 header |
|
| 278 | - * - resets the cURL options for the loop, sets the referrer flag |
|
| 279 | - * |
|
| 280 | - * @param string $target_url The URL we want to redirect to |
|
| 281 | - * @param string $referer_url The URL that we're redirecting from |
|
| 282 | - */ |
|
| 277 | + * Called to initiate a redirect from a 301, 302 or 307 header |
|
| 278 | + * - resets the cURL options for the loop, sets the referrer flag |
|
| 279 | + * |
|
| 280 | + * @param string $target_url The URL we want to redirect to |
|
| 281 | + * @param string $referer_url The URL that we're redirecting from |
|
| 282 | + */ |
|
| 283 | 283 | private function redirect($target_url, $referer_url) |
| 284 | 284 | { |
| 285 | 285 | // no no I last saw that over there ... really, 301, 302, 307 |
@@ -289,13 +289,13 @@ discard block |
||
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
| 292 | - * Callback function to parse returned headers |
|
| 293 | - * - lowercases everything to make it consistent |
|
| 294 | - * |
|
| 295 | - * @param type $cr Not sure what this is used for? |
|
| 296 | - * @param string $header The header |
|
| 297 | - * @return int The length of the header |
|
| 298 | - */ |
|
| 292 | + * Callback function to parse returned headers |
|
| 293 | + * - lowercases everything to make it consistent |
|
| 294 | + * |
|
| 295 | + * @param type $cr Not sure what this is used for? |
|
| 296 | + * @param string $header The header |
|
| 297 | + * @return int The length of the header |
|
| 298 | + */ |
|
| 299 | 299 | private function header_callback($cr, $header) |
| 300 | 300 | { |
| 301 | 301 | $_header = trim($header); |
@@ -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); |
@@ -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; |
@@ -425,40 +425,40 @@ discard block |
||
| 425 | 425 | switch ($b) |
| 426 | 426 | { |
| 427 | 427 | // Extension... |
| 428 | - case 0x21: |
|
| 429 | - $len = 0; |
|
| 430 | - if (!$this->skipExt($data, $len)) |
|
| 431 | - return false; |
|
| 428 | + case 0x21: |
|
| 429 | + $len = 0; |
|
| 430 | + if (!$this->skipExt($data, $len)) |
|
| 431 | + return false; |
|
| 432 | 432 | |
| 433 | - $datLen += $len; |
|
| 434 | - break; |
|
| 433 | + $datLen += $len; |
|
| 434 | + break; |
|
| 435 | 435 | |
| 436 | - // Image... |
|
| 437 | - case 0x2C: |
|
| 438 | - // Load the header and color table. |
|
| 439 | - $len = 0; |
|
| 440 | - if (!$this->m_gih->load($data, $len)) |
|
| 441 | - return false; |
|
| 436 | + // Image... |
|
| 437 | + case 0x2C: |
|
| 438 | + // Load the header and color table. |
|
| 439 | + $len = 0; |
|
| 440 | + if (!$this->m_gih->load($data, $len)) |
|
| 441 | + return false; |
|
| 442 | 442 | |
| 443 | - $data = substr($data, $len); |
|
| 444 | - $datLen += $len; |
|
| 443 | + $data = substr($data, $len); |
|
| 444 | + $datLen += $len; |
|
| 445 | 445 | |
| 446 | - // Decompress the data, and ride on home ;). |
|
| 447 | - $len = 0; |
|
| 448 | - if (!($this->m_data = $this->m_lzw->decompress($data, $len))) |
|
| 449 | - return false; |
|
| 446 | + // Decompress the data, and ride on home ;). |
|
| 447 | + $len = 0; |
|
| 448 | + if (!($this->m_data = $this->m_lzw->decompress($data, $len))) |
|
| 449 | + return false; |
|
| 450 | 450 | |
| 451 | - $data = substr($data, $len); |
|
| 452 | - $datLen += $len; |
|
| 451 | + $data = substr($data, $len); |
|
| 452 | + $datLen += $len; |
|
| 453 | 453 | |
| 454 | - if ($this->m_gih->m_bInterlace) |
|
| 455 | - $this->deInterlace(); |
|
| 454 | + if ($this->m_gih->m_bInterlace) |
|
| 455 | + $this->deInterlace(); |
|
| 456 | 456 | |
| 457 | - return true; |
|
| 457 | + return true; |
|
| 458 | 458 | |
| 459 | - case 0x3B: // EOF |
|
| 460 | - default: |
|
| 461 | - return false; |
|
| 459 | + case 0x3B: // EOF |
|
| 460 | + default: |
|
| 461 | + return false; |
|
| 462 | 462 | } |
| 463 | 463 | } |
| 464 | 464 | return false; |
@@ -475,27 +475,27 @@ discard block |
||
| 475 | 475 | switch ($b) |
| 476 | 476 | { |
| 477 | 477 | // Graphic Control... |
| 478 | - case 0xF9: |
|
| 479 | - $b = ord($data[1]); |
|
| 480 | - $this->m_disp = ($b & 0x1C) >> 2; |
|
| 481 | - $this->m_bUser = ($b & 0x02) ? true : false; |
|
| 482 | - $this->m_bTrans = ($b & 0x01) ? true : false; |
|
| 483 | - list ($this->m_nDelay) = array_values(unpack('v', substr($data, 2, 2))); |
|
| 484 | - $this->m_nTrans = ord($data[4]); |
|
| 485 | - break; |
|
| 486 | - |
|
| 487 | - // Comment... |
|
| 488 | - case 0xFE: |
|
| 489 | - $this->m_lpComm = substr($data, 1, ord($data[0])); |
|
| 490 | - break; |
|
| 491 | - |
|
| 492 | - // Plain text... |
|
| 493 | - case 0x01: |
|
| 494 | - break; |
|
| 495 | - |
|
| 496 | - // Application... |
|
| 497 | - case 0xFF: |
|
| 498 | - break; |
|
| 478 | + case 0xF9: |
|
| 479 | + $b = ord($data[1]); |
|
| 480 | + $this->m_disp = ($b & 0x1C) >> 2; |
|
| 481 | + $this->m_bUser = ($b & 0x02) ? true : false; |
|
| 482 | + $this->m_bTrans = ($b & 0x01) ? true : false; |
|
| 483 | + list ($this->m_nDelay) = array_values(unpack('v', substr($data, 2, 2))); |
|
| 484 | + $this->m_nTrans = ord($data[4]); |
|
| 485 | + break; |
|
| 486 | + |
|
| 487 | + // Comment... |
|
| 488 | + case 0xFE: |
|
| 489 | + $this->m_lpComm = substr($data, 1, ord($data[0])); |
|
| 490 | + break; |
|
| 491 | + |
|
| 492 | + // Plain text... |
|
| 493 | + case 0x01: |
|
| 494 | + break; |
|
| 495 | + |
|
| 496 | + // Application... |
|
| 497 | + case 0xFF: |
|
| 498 | + break; |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | // Skip default as defs may change. |
@@ -521,25 +521,25 @@ discard block |
||
| 521 | 521 | { |
| 522 | 522 | switch ($i) |
| 523 | 523 | { |
| 524 | - case 0: |
|
| 525 | - $s = 8; |
|
| 526 | - $y = 0; |
|
| 527 | - break; |
|
| 528 | - |
|
| 529 | - case 1: |
|
| 530 | - $s = 8; |
|
| 531 | - $y = 4; |
|
| 532 | - break; |
|
| 533 | - |
|
| 534 | - case 2: |
|
| 535 | - $s = 4; |
|
| 536 | - $y = 2; |
|
| 537 | - break; |
|
| 538 | - |
|
| 539 | - case 3: |
|
| 540 | - $s = 2; |
|
| 541 | - $y = 1; |
|
| 542 | - break; |
|
| 524 | + case 0: |
|
| 525 | + $s = 8; |
|
| 526 | + $y = 0; |
|
| 527 | + break; |
|
| 528 | + |
|
| 529 | + case 1: |
|
| 530 | + $s = 8; |
|
| 531 | + $y = 4; |
|
| 532 | + break; |
|
| 533 | + |
|
| 534 | + case 2: |
|
| 535 | + $s = 4; |
|
| 536 | + $y = 2; |
|
| 537 | + break; |
|
| 538 | + |
|
| 539 | + case 3: |
|
| 540 | + $s = 2; |
|
| 541 | + $y = 1; |
|
| 542 | + break; |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | for (; $y < $this->m_gih->m_nHeight; $y += $s) |
@@ -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,22 +453,25 @@ 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 | $data = substr($data, $len); |
| 452 | 470 | $datLen += $len; |
| 453 | 471 | |
| 454 | - if ($this->m_gih->m_bInterlace) |
|
| 455 | - $this->deInterlace(); |
|
| 472 | + if ($this->m_gih->m_bInterlace) { |
|
| 473 | + $this->deInterlace(); |
|
| 474 | + } |
|
| 456 | 475 | |
| 457 | 476 | return true; |
| 458 | 477 | |
@@ -572,17 +591,20 @@ discard block |
||
| 572 | 591 | |
| 573 | 592 | public function loadFile($filename, $iIndex) |
| 574 | 593 | { |
| 575 | - if ($iIndex < 0) |
|
| 576 | - return false; |
|
| 594 | + if ($iIndex < 0) { |
|
| 595 | + return false; |
|
| 596 | + } |
|
| 577 | 597 | |
| 578 | 598 | $this->data = @file_get_contents($filename); |
| 579 | - if ($this->data === false) |
|
| 580 | - return false; |
|
| 599 | + if ($this->data === false) { |
|
| 600 | + return false; |
|
| 601 | + } |
|
| 581 | 602 | |
| 582 | 603 | // Tell the header to load up.... |
| 583 | 604 | $len = 0; |
| 584 | - if (!$this->header->load($this->data, $len)) |
|
| 585 | - return false; |
|
| 605 | + if (!$this->header->load($this->data, $len)) { |
|
| 606 | + return false; |
|
| 607 | + } |
|
| 586 | 608 | |
| 587 | 609 | $this->data = substr($this->data, $len); |
| 588 | 610 | |
@@ -590,8 +612,9 @@ discard block |
||
| 590 | 612 | for ($j = 0; $j <= $iIndex; $j++) |
| 591 | 613 | { |
| 592 | 614 | $imgLen = 0; |
| 593 | - if (!$this->image->load($this->data, $imgLen)) |
|
| 594 | - return false; |
|
| 615 | + if (!$this->image->load($this->data, $imgLen)) { |
|
| 616 | + return false; |
|
| 617 | + } |
|
| 595 | 618 | |
| 596 | 619 | $this->data = substr($this->data, $imgLen); |
| 597 | 620 | } |
@@ -602,8 +625,9 @@ discard block |
||
| 602 | 625 | |
| 603 | 626 | public function get_png_data($background_color) |
| 604 | 627 | { |
| 605 | - if (!$this->loaded) |
|
| 606 | - return false; |
|
| 628 | + if (!$this->loaded) { |
|
| 629 | + return false; |
|
| 630 | + } |
|
| 607 | 631 | |
| 608 | 632 | // Prepare the color table. |
| 609 | 633 | if ($this->image->m_gih->m_bLocalClr) |
@@ -611,25 +635,26 @@ discard block |
||
| 611 | 635 | $colors = $this->image->m_gih->m_nTableSize; |
| 612 | 636 | $pal = $this->image->m_gih->m_colorTable->toString(); |
| 613 | 637 | |
| 614 | - if ($background_color != -1) |
|
| 615 | - $background_color = $this->image->m_gih->m_colorTable->colorIndex($background_color); |
|
| 616 | - } |
|
| 617 | - elseif ($this->header->m_bGlobalClr) |
|
| 638 | + if ($background_color != -1) { |
|
| 639 | + $background_color = $this->image->m_gih->m_colorTable->colorIndex($background_color); |
|
| 640 | + } |
|
| 641 | + } elseif ($this->header->m_bGlobalClr) |
|
| 618 | 642 | { |
| 619 | 643 | $colors = $this->header->m_nTableSize; |
| 620 | 644 | $pal = $this->header->m_colorTable->toString(); |
| 621 | 645 | |
| 622 | - if ($background_color != -1) |
|
| 623 | - $background_color = $this->header->m_colorTable->colorIndex($background_color); |
|
| 624 | - } |
|
| 625 | - else |
|
| 646 | + if ($background_color != -1) { |
|
| 647 | + $background_color = $this->header->m_colorTable->colorIndex($background_color); |
|
| 648 | + } |
|
| 649 | + } else |
|
| 626 | 650 | { |
| 627 | 651 | $colors = 0; |
| 628 | 652 | $background_color = -1; |
| 629 | 653 | } |
| 630 | 654 | |
| 631 | - if ($background_color == -1) |
|
| 632 | - $background_color = $this->header->m_nBgColor; |
|
| 655 | + if ($background_color == -1) { |
|
| 656 | + $background_color = $this->header->m_nBgColor; |
|
| 657 | + } |
|
| 633 | 658 | |
| 634 | 659 | $data = &$this->image->m_data; |
| 635 | 660 | $header = &$this->image->m_gih; |
@@ -645,11 +670,13 @@ discard block |
||
| 645 | 670 | for ($x = 0; $x < $this->header->m_nWidth; $x++, $i++) |
| 646 | 671 | { |
| 647 | 672 | // Is this in the proper range? If so, get the specific pixel data... |
| 648 | - if ($x >= $header->m_nLeft && $y >= $header->m_nTop && $x < ($header->m_nLeft + $header->m_nWidth) && $y < ($header->m_nTop + $header->m_nHeight)) |
|
| 649 | - $bmp .= $data{$i}; |
|
| 673 | + if ($x >= $header->m_nLeft && $y >= $header->m_nTop && $x < ($header->m_nLeft + $header->m_nWidth) && $y < ($header->m_nTop + $header->m_nHeight)) { |
|
| 674 | + $bmp .= $data{$i}; |
|
| 675 | + } |
|
| 650 | 676 | // Otherwise, this is background... |
| 651 | - else |
|
| 652 | - $bmp .= chr($background_color); |
|
| 677 | + else { |
|
| 678 | + $bmp .= chr($background_color); |
|
| 679 | + } |
|
| 653 | 680 | } |
| 654 | 681 | } |
| 655 | 682 | |
@@ -678,8 +705,9 @@ discard block |
||
| 678 | 705 | $tmp = 'tRNS'; |
| 679 | 706 | |
| 680 | 707 | // Stick each color on - full transparency or none. |
| 681 | - for ($i = 0; $i < $colors; $i++) |
|
| 682 | - $tmp .= $i == $this->image->m_nTrans ? "\x00" : "\xFF"; |
|
| 708 | + for ($i = 0; $i < $colors; $i++) { |
|
| 709 | + $tmp .= $i == $this->image->m_nTrans ? "\x00" : "\xFF"; |
|
| 710 | + } |
|
| 683 | 711 | |
| 684 | 712 | $out .= $tmp . pack('N', smf_crc32($tmp)); |
| 685 | 713 | } |
@@ -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 | { |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | public function setInitKey($key) |
| 116 | 116 | { |
| 117 | - if (preg_match('/^['.implode('', array_keys($this->getLookup())).']+$/', $key) == false) { |
|
| 117 | + if (preg_match('/^[' . implode('', array_keys($this->getLookup())) . ']+$/', $key) == false) { |
|
| 118 | 118 | throw new \InvalidArgumentException('Invalid base32 hash!'); |
| 119 | 119 | } |
| 120 | 120 | $this->initKey = $key; |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | $initKey = ($initKey == null) ? $this->getInitKey() : $initKey; |
| 248 | 248 | $timestamp = ($timestamp == null) ? $this->generateTimestamp() : $timestamp; |
| 249 | 249 | |
| 250 | - $hash = hash_hmac ( |
|
| 250 | + $hash = hash_hmac( |
|
| 251 | 251 | 'sha1', |
| 252 | 252 | pack('N*', 0) . pack('N*', $timestamp), |
| 253 | 253 | $initKey, |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | $code = ''; |
| 271 | 271 | |
| 272 | 272 | for ($i = 0; $i < $length; $i++) { |
| 273 | - $code .= $lookup[mt_rand(0, strlen($lookup)-1)]; |
|
| 273 | + $code .= $lookup[mt_rand(0, strlen($lookup) - 1)]; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | return $code; |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | */ |
| 284 | 284 | public function generateTimestamp() |
| 285 | 285 | { |
| 286 | - return floor(microtime(true)/$this->getRefresh()); |
|
| 286 | + return floor(microtime(true) / $this->getRefresh()); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | /** |
@@ -297,10 +297,10 @@ discard block |
||
| 297 | 297 | $offset = ord($hash[19]) & 0xf; |
| 298 | 298 | |
| 299 | 299 | return ( |
| 300 | - ((ord($hash[$offset+0]) & 0x7f) << 24 ) | |
|
| 301 | - ((ord($hash[$offset+1]) & 0xff) << 16 ) | |
|
| 302 | - ((ord($hash[$offset+2]) & 0xff) << 8 ) | |
|
| 303 | - (ord($hash[$offset+3]) & 0xff) |
|
| 300 | + ((ord($hash[$offset + 0]) & 0x7f) << 24) | |
|
| 301 | + ((ord($hash[$offset + 1]) & 0xff) << 16) | |
|
| 302 | + ((ord($hash[$offset + 2]) & 0xff) << 8) | |
|
| 303 | + (ord($hash[$offset + 3]) & 0xff) |
|
| 304 | 304 | ) % pow(10, $this->getCodeLength()); |
| 305 | 305 | } |
| 306 | 306 | |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | { |
| 316 | 316 | $lookup = $this->getLookup(); |
| 317 | 317 | |
| 318 | - if (preg_match('/^['.implode('', array_keys($lookup)).']+$/', $hash) == false) { |
|
| 318 | + if (preg_match('/^[' . implode('', array_keys($lookup)) . ']+$/', $hash) == false) { |
|
| 319 | 319 | throw new \InvalidArgumentException('Invalid base32 hash!'); |
| 320 | 320 | } |
| 321 | 321 | |
@@ -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 | { |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | locked = {int:locked}, |
| 86 | 86 | is_sticky = {int:is_sticky} |
| 87 | 87 | WHERE id_draft = {int:id_draft}', |
| 88 | - array ( |
|
| 88 | + array( |
|
| 89 | 89 | 'id_topic' => $topic_id, |
| 90 | 90 | 'id_board' => $board, |
| 91 | 91 | 'poster_time' => time(), |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | DELETE FROM {db_prefix}user_drafts |
| 411 | 411 | WHERE id_draft IN ({array_int:id_draft})' . ($check ? ' |
| 412 | 412 | AND id_member = {int:id_member}' : ''), |
| 413 | - array ( |
|
| 413 | + array( |
|
| 414 | 414 | 'id_draft' => $id_draft, |
| 415 | 415 | 'id_member' => empty($user_info['id']) ? -1 : $user_info['id'], |
| 416 | 416 | ) |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | $context['drafts'][] = array( |
| 472 | 472 | 'subject' => censorText(shorten_subject(stripslashes($row['subject']), 24)), |
| 473 | 473 | 'poster_time' => timeformat($row['poster_time']), |
| 474 | - 'link' => '<a href="' . $scripturl . '?action=post;board=' . $row['id_board'] . ';' . (!empty($row['id_topic']) ? 'topic='. $row['id_topic'] .'.0;' : '') . 'id_draft=' . $row['id_draft'] . '">' . $row['subject'] . '</a>', |
|
| 474 | + 'link' => '<a href="' . $scripturl . '?action=post;board=' . $row['id_board'] . ';' . (!empty($row['id_topic']) ? 'topic=' . $row['id_topic'] . '.0;' : '') . 'id_draft=' . $row['id_draft'] . '">' . $row['subject'] . '</a>', |
|
| 475 | 475 | ); |
| 476 | 476 | // PM drafts |
| 477 | 477 | elseif ($draft_type === 1) |
@@ -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) && $draft_info['id_member'] == $user_info['id']) |
@@ -150,9 +155,9 @@ discard block |
||
| 150 | 155 | { |
| 151 | 156 | $context['draft_saved'] = true; |
| 152 | 157 | $context['id_draft'] = $id_draft; |
| 158 | + } else { |
|
| 159 | + $post_errors[] = 'draft_not_saved'; |
|
| 153 | 160 | } |
| 154 | - else |
|
| 155 | - $post_errors[] = 'draft_not_saved'; |
|
| 156 | 161 | |
| 157 | 162 | // cleanup |
| 158 | 163 | unset($_POST['save_draft']); |
@@ -182,8 +187,9 @@ discard block |
||
| 182 | 187 | global $context, $user_info, $smcFunc, $modSettings; |
| 183 | 188 | |
| 184 | 189 | // PM survey says ... can you stay or must you go |
| 185 | - if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) |
|
| 186 | - return false; |
|
| 190 | + if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) { |
|
| 191 | + return false; |
|
| 192 | + } |
|
| 187 | 193 | |
| 188 | 194 | // read in what you sent us |
| 189 | 195 | $id_pm_draft = (int) $_POST['id_pm_draft']; |
@@ -195,8 +201,9 @@ discard block |
||
| 195 | 201 | $context['draft_saved_on'] = $draft_info['poster_time']; |
| 196 | 202 | |
| 197 | 203 | // Send something back to the javascript caller |
| 198 | - if (!empty($id_draft)) |
|
| 199 | - XmlDraft($id_draft); |
|
| 204 | + if (!empty($id_draft)) { |
|
| 205 | + XmlDraft($id_draft); |
|
| 206 | + } |
|
| 200 | 207 | |
| 201 | 208 | return true; |
| 202 | 209 | } |
@@ -206,9 +213,9 @@ discard block |
||
| 206 | 213 | { |
| 207 | 214 | $recipientList['to'] = isset($_POST['recipient_to']) ? explode(',', $_POST['recipient_to']) : array(); |
| 208 | 215 | $recipientList['bcc'] = isset($_POST['recipient_bcc']) ? explode(',', $_POST['recipient_bcc']) : array(); |
| 216 | + } elseif (!empty($draft_info['to_list']) && empty($recipientList)) { |
|
| 217 | + $recipientList = smf_json_decode($draft_info['to_list'], true); |
|
| 209 | 218 | } |
| 210 | - elseif (!empty($draft_info['to_list']) && empty($recipientList)) |
|
| 211 | - $recipientList = smf_json_decode($draft_info['to_list'], true); |
|
| 212 | 219 | |
| 213 | 220 | // prepare the data we got from the form |
| 214 | 221 | $reply_id = empty($_POST['replied_to']) ? 0 : (int) $_POST['replied_to']; |
@@ -217,8 +224,9 @@ discard block |
||
| 217 | 224 | |
| 218 | 225 | // message and subject always need a bit more work |
| 219 | 226 | preparsecode($draft['body']); |
| 220 | - if ($smcFunc['strlen']($draft['subject']) > 100) |
|
| 221 | - $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
| 227 | + if ($smcFunc['strlen']($draft['subject']) > 100) { |
|
| 228 | + $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
| 229 | + } |
|
| 222 | 230 | |
| 223 | 231 | // Modifying an existing PM draft? |
| 224 | 232 | if (!empty($id_pm_draft) && !empty($draft_info) && $draft_info['id_member'] == $user_info['id']) |
@@ -284,9 +292,9 @@ discard block |
||
| 284 | 292 | { |
| 285 | 293 | $context['draft_saved'] = true; |
| 286 | 294 | $context['id_pm_draft'] = $id_pm_draft; |
| 295 | + } else { |
|
| 296 | + $post_errors[] = 'draft_not_saved'; |
|
| 287 | 297 | } |
| 288 | - else |
|
| 289 | - $post_errors[] = 'draft_not_saved'; |
|
| 290 | 298 | } |
| 291 | 299 | |
| 292 | 300 | // if we were called from the autosave function, send something back |
@@ -319,8 +327,9 @@ discard block |
||
| 319 | 327 | $type = (int) $type; |
| 320 | 328 | |
| 321 | 329 | // nothing to read, nothing to do |
| 322 | - if (empty($id_draft)) |
|
| 323 | - return false; |
|
| 330 | + if (empty($id_draft)) { |
|
| 331 | + return false; |
|
| 332 | + } |
|
| 324 | 333 | |
| 325 | 334 | // load in this draft from the DB |
| 326 | 335 | $request = $smcFunc['db_query']('', ' |
@@ -340,8 +349,9 @@ discard block |
||
| 340 | 349 | ); |
| 341 | 350 | |
| 342 | 351 | // no results? |
| 343 | - if (!$smcFunc['db_num_rows']($request)) |
|
| 344 | - return false; |
|
| 352 | + if (!$smcFunc['db_num_rows']($request)) { |
|
| 353 | + return false; |
|
| 354 | + } |
|
| 345 | 355 | |
| 346 | 356 | // load up the data |
| 347 | 357 | $draft_info = $smcFunc['db_fetch_assoc']($request); |
@@ -362,8 +372,7 @@ discard block |
||
| 362 | 372 | $context['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : ''; |
| 363 | 373 | $context['board'] = !empty($draft_info['board_id']) ? $draft_info['id_board'] : ''; |
| 364 | 374 | $context['id_draft'] = !empty($draft_info['id_draft']) ? $draft_info['id_draft'] : 0; |
| 365 | - } |
|
| 366 | - elseif ($type === 1) |
|
| 375 | + } elseif ($type === 1) |
|
| 367 | 376 | { |
| 368 | 377 | // one of those pm drafts? then set it up like we have an error |
| 369 | 378 | $_REQUEST['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : ''; |
@@ -399,12 +408,14 @@ discard block |
||
| 399 | 408 | global $user_info, $smcFunc; |
| 400 | 409 | |
| 401 | 410 | // Only a single draft. |
| 402 | - if (is_numeric($id_draft)) |
|
| 403 | - $id_draft = array($id_draft); |
|
| 411 | + if (is_numeric($id_draft)) { |
|
| 412 | + $id_draft = array($id_draft); |
|
| 413 | + } |
|
| 404 | 414 | |
| 405 | 415 | // can't delete nothing |
| 406 | - if (empty($id_draft) || ($check && empty($user_info['id']))) |
|
| 407 | - return false; |
|
| 416 | + if (empty($id_draft) || ($check && empty($user_info['id']))) { |
|
| 417 | + return false; |
|
| 418 | + } |
|
| 408 | 419 | |
| 409 | 420 | $smcFunc['db_query']('', ' |
| 410 | 421 | DELETE FROM {db_prefix}user_drafts |
@@ -433,14 +444,16 @@ discard block |
||
| 433 | 444 | global $smcFunc, $scripturl, $context, $txt, $modSettings; |
| 434 | 445 | |
| 435 | 446 | // Permissions |
| 436 | - if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) |
|
| 437 | - return false; |
|
| 447 | + if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) { |
|
| 448 | + return false; |
|
| 449 | + } |
|
| 438 | 450 | |
| 439 | 451 | $context['drafts'] = array(); |
| 440 | 452 | |
| 441 | 453 | // has a specific draft has been selected? Load it up if there is not a message already in the editor |
| 442 | - if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) |
|
| 443 | - ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true); |
|
| 454 | + if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) { |
|
| 455 | + ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true); |
|
| 456 | + } |
|
| 444 | 457 | |
| 445 | 458 | // load the drafts this user has available |
| 446 | 459 | $request = $smcFunc['db_query']('', ' |
@@ -463,23 +476,26 @@ discard block |
||
| 463 | 476 | // add them to the draft array for display |
| 464 | 477 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 465 | 478 | { |
| 466 | - if (empty($row['subject'])) |
|
| 467 | - $row['subject'] = $txt['no_subject']; |
|
| 479 | + if (empty($row['subject'])) { |
|
| 480 | + $row['subject'] = $txt['no_subject']; |
|
| 481 | + } |
|
| 468 | 482 | |
| 469 | 483 | // Post drafts |
| 470 | - if ($draft_type === 0) |
|
| 471 | - $context['drafts'][] = array( |
|
| 484 | + if ($draft_type === 0) { |
|
| 485 | + $context['drafts'][] = array( |
|
| 472 | 486 | 'subject' => censorText(shorten_subject(stripslashes($row['subject']), 24)), |
| 473 | 487 | 'poster_time' => timeformat($row['poster_time']), |
| 474 | 488 | 'link' => '<a href="' . $scripturl . '?action=post;board=' . $row['id_board'] . ';' . (!empty($row['id_topic']) ? 'topic='. $row['id_topic'] .'.0;' : '') . 'id_draft=' . $row['id_draft'] . '">' . $row['subject'] . '</a>', |
| 475 | 489 | ); |
| 490 | + } |
|
| 476 | 491 | // PM drafts |
| 477 | - elseif ($draft_type === 1) |
|
| 478 | - $context['drafts'][] = array( |
|
| 492 | + elseif ($draft_type === 1) { |
|
| 493 | + $context['drafts'][] = array( |
|
| 479 | 494 | 'subject' => censorText(shorten_subject(stripslashes($row['subject']), 24)), |
| 480 | 495 | 'poster_time' => timeformat($row['poster_time']), |
| 481 | 496 | 'link' => '<a href="' . $scripturl . '?action=pm;sa=send;id_draft=' . $row['id_draft'] . '">' . (!empty($row['subject']) ? $row['subject'] : $txt['drafts_none']) . '</a>', |
| 482 | 497 | ); |
| 498 | + } |
|
| 483 | 499 | } |
| 484 | 500 | $smcFunc['db_free_result']($request); |
| 485 | 501 | } |
@@ -543,8 +559,9 @@ discard block |
||
| 543 | 559 | } |
| 544 | 560 | |
| 545 | 561 | // Default to 10. |
| 546 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
| 547 | - $_REQUEST['viewscount'] = 10; |
|
| 562 | + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { |
|
| 563 | + $_REQUEST['viewscount'] = 10; |
|
| 564 | + } |
|
| 548 | 565 | |
| 549 | 566 | // Get the count of applicable drafts on the boards they can (still) see ... |
| 550 | 567 | // @todo .. should we just let them see their drafts even if they have lost board access ? |
@@ -609,12 +626,14 @@ discard block |
||
| 609 | 626 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 610 | 627 | { |
| 611 | 628 | // Censor.... |
| 612 | - if (empty($row['body'])) |
|
| 613 | - $row['body'] = ''; |
|
| 629 | + if (empty($row['body'])) { |
|
| 630 | + $row['body'] = ''; |
|
| 631 | + } |
|
| 614 | 632 | |
| 615 | 633 | $row['subject'] = $smcFunc['htmltrim']($row['subject']); |
| 616 | - if (empty($row['subject'])) |
|
| 617 | - $row['subject'] = $txt['no_subject']; |
|
| 634 | + if (empty($row['subject'])) { |
|
| 635 | + $row['subject'] = $txt['no_subject']; |
|
| 636 | + } |
|
| 618 | 637 | |
| 619 | 638 | censorText($row['body']); |
| 620 | 639 | censorText($row['subject']); |
@@ -646,8 +665,9 @@ discard block |
||
| 646 | 665 | $smcFunc['db_free_result']($request); |
| 647 | 666 | |
| 648 | 667 | // If the drafts were retrieved in reverse order, get them right again. |
| 649 | - if ($reverse) |
|
| 650 | - $context['drafts'] = array_reverse($context['drafts'], true); |
|
| 668 | + if ($reverse) { |
|
| 669 | + $context['drafts'] = array_reverse($context['drafts'], true); |
|
| 670 | + } |
|
| 651 | 671 | |
| 652 | 672 | // Menu tab |
| 653 | 673 | $context[$context['profile_menu_name']]['tab_data'] = array( |
@@ -705,8 +725,9 @@ discard block |
||
| 705 | 725 | } |
| 706 | 726 | |
| 707 | 727 | // Default to 10. |
| 708 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
| 709 | - $_REQUEST['viewscount'] = 10; |
|
| 728 | + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { |
|
| 729 | + $_REQUEST['viewscount'] = 10; |
|
| 730 | + } |
|
| 710 | 731 | |
| 711 | 732 | // Get the count of applicable drafts |
| 712 | 733 | $request = $smcFunc['db_query']('', ' |
@@ -765,12 +786,14 @@ discard block |
||
| 765 | 786 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 766 | 787 | { |
| 767 | 788 | // Censor.... |
| 768 | - if (empty($row['body'])) |
|
| 769 | - $row['body'] = ''; |
|
| 789 | + if (empty($row['body'])) { |
|
| 790 | + $row['body'] = ''; |
|
| 791 | + } |
|
| 770 | 792 | |
| 771 | 793 | $row['subject'] = $smcFunc['htmltrim']($row['subject']); |
| 772 | - if (empty($row['subject'])) |
|
| 773 | - $row['subject'] = $txt['no_subject']; |
|
| 794 | + if (empty($row['subject'])) { |
|
| 795 | + $row['subject'] = $txt['no_subject']; |
|
| 796 | + } |
|
| 774 | 797 | |
| 775 | 798 | censorText($row['body']); |
| 776 | 799 | censorText($row['subject']); |
@@ -825,8 +848,9 @@ discard block |
||
| 825 | 848 | $smcFunc['db_free_result']($request); |
| 826 | 849 | |
| 827 | 850 | // if the drafts were retrieved in reverse order, then put them in the right order again. |
| 828 | - if ($reverse) |
|
| 829 | - $context['drafts'] = array_reverse($context['drafts'], true); |
|
| 851 | + if ($reverse) { |
|
| 852 | + $context['drafts'] = array_reverse($context['drafts'], true); |
|
| 853 | + } |
|
| 830 | 854 | |
| 831 | 855 | // off to the template we go |
| 832 | 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 = 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 |
@@ -925,7 +925,7 @@ discard block |
||
| 925 | 925 | * Doesn't clean the inputs |
| 926 | 926 | * |
| 927 | 927 | * @param array $items_ids The items to remove |
| 928 | - * @param bool|int $group_id The ID of the group these triggers are associated with or false if deleting them from all groups |
|
| 928 | + * @param integer $group_id The ID of the group these triggers are associated with or false if deleting them from all groups |
|
| 929 | 929 | * @return bool Always returns true |
| 930 | 930 | */ |
| 931 | 931 | function removeBanTriggers($items_ids = array(), $group_id = false) |
@@ -1119,7 +1119,7 @@ discard block |
||
| 1119 | 1119 | * Errors in $context['ban_errors'] |
| 1120 | 1120 | * |
| 1121 | 1121 | * @param array $triggers The triggers to validate |
| 1122 | - * @return array An array of riggers and log info ready to be used |
|
| 1122 | + * @return integer An array of riggers and log info ready to be used |
|
| 1123 | 1123 | */ |
| 1124 | 1124 | function validateTriggers(&$triggers) |
| 1125 | 1125 | { |
@@ -784,7 +784,7 @@ discard block |
||
| 784 | 784 | ) |
| 785 | 785 | ); |
| 786 | 786 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 787 | - $error_ips[] = inet_dtop($row['ip']); |
|
| 787 | + $error_ips[] = inet_dtop($row['ip']); |
|
| 788 | 788 | $smcFunc['db_free_result']($request); |
| 789 | 789 | |
| 790 | 790 | return $error_ips; |
@@ -2168,9 +2168,9 @@ discard block |
||
| 2168 | 2168 | |
| 2169 | 2169 | if ($low == '255.255.255.255') return 'unknown'; |
| 2170 | 2170 | if ($low == $high) |
| 2171 | - return $low; |
|
| 2171 | + return $low; |
|
| 2172 | 2172 | else |
| 2173 | - return $low . '-'.$high; |
|
| 2173 | + return $low . '-'.$high; |
|
| 2174 | 2174 | } |
| 2175 | 2175 | |
| 2176 | 2176 | /** |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | 'value' => $txt['ban_added'], |
| 184 | 184 | ), |
| 185 | 185 | 'data' => array( |
| 186 | - 'function' => function ($rowData) use ($context) |
|
| 186 | + 'function' => function($rowData) use ($context) |
|
| 187 | 187 | { |
| 188 | 188 | return timeformat($rowData['ban_time'], empty($context['ban_time_format']) ? true : $context['ban_time_format']); |
| 189 | 189 | }, |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | 'value' => $txt['ban_expires'], |
| 199 | 199 | ), |
| 200 | 200 | 'data' => array( |
| 201 | - 'function' => function ($rowData) use ($txt) |
|
| 201 | + 'function' => function($rowData) use ($txt) |
|
| 202 | 202 | { |
| 203 | 203 | // This ban never expires...whahaha. |
| 204 | 204 | if ($rowData['expire_time'] === null) |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | 'style' => 'width: 60%;text-align: left;', |
| 402 | 402 | ), |
| 403 | 403 | 'data' => array( |
| 404 | - 'function' => function ($ban_item) use ($txt) |
|
| 404 | + 'function' => function($ban_item) use ($txt) |
|
| 405 | 405 | { |
| 406 | 406 | if (in_array($ban_item['type'], array('ip', 'hostname', 'email'))) |
| 407 | 407 | return '<strong>' . $txt[$ban_item['type']] . ':</strong> ' . $ban_item[$ban_item['type']]; |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | 'style' => 'width: 15%; text-align: center;', |
| 430 | 430 | ), |
| 431 | 431 | 'data' => array( |
| 432 | - 'function' => function ($ban_item) use ($txt, $context, $scripturl) |
|
| 432 | + 'function' => function($ban_item) use ($txt, $context, $scripturl) |
|
| 433 | 433 | { |
| 434 | 434 | return '<a href="' . $scripturl . '?action=admin;area=ban;sa=edittrigger;bg=' . $context['ban_group_id'] . ';bi=' . $ban_item['id'] . '">' . $txt['ban_edit_trigger'] . '</a>'; |
| 435 | 435 | }, |
@@ -554,7 +554,7 @@ discard block |
||
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | // We come from the mod center. |
| 557 | - elseif(isset($_GET['msg']) && !empty($_GET['msg'])) |
|
| 557 | + elseif (isset($_GET['msg']) && !empty($_GET['msg'])) |
|
| 558 | 558 | { |
| 559 | 559 | $request = $smcFunc['db_query']('', ' |
| 560 | 560 | SELECT poster_name, poster_ip, poster_email |
@@ -1429,7 +1429,7 @@ discard block |
||
| 1429 | 1429 | if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) |
| 1430 | 1430 | $context['ban_errors'][] = 'ban_unknown_restriction_type'; |
| 1431 | 1431 | |
| 1432 | - if(!empty($ban_info['id'])) |
|
| 1432 | + if (!empty($ban_info['id'])) |
|
| 1433 | 1433 | { |
| 1434 | 1434 | // Verify the ban group exists. |
| 1435 | 1435 | $request = $smcFunc['db_query']('', ' |
@@ -1447,7 +1447,7 @@ discard block |
||
| 1447 | 1447 | $smcFunc['db_free_result']($request); |
| 1448 | 1448 | } |
| 1449 | 1449 | |
| 1450 | - if(!empty($ban_info['name'])) |
|
| 1450 | + if (!empty($ban_info['name'])) |
|
| 1451 | 1451 | { |
| 1452 | 1452 | // Make sure the name does not already exist (Of course, if it exists in the ban group we are editing, proceed.) |
| 1453 | 1453 | $request = $smcFunc['db_query']('', ' |
@@ -1516,7 +1516,7 @@ discard block |
||
| 1516 | 1516 | if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) |
| 1517 | 1517 | $context['ban_errors'][] = 'ban_unknown_restriction_type'; |
| 1518 | 1518 | |
| 1519 | - if(!empty($ban_info['name'])) |
|
| 1519 | + if (!empty($ban_info['name'])) |
|
| 1520 | 1520 | { |
| 1521 | 1521 | // Check whether a ban with this name already exists. |
| 1522 | 1522 | $request = $smcFunc['db_query']('', ' |
@@ -1795,7 +1795,7 @@ discard block |
||
| 1795 | 1795 | if ($context['selected_entity'] === 'ip') |
| 1796 | 1796 | { |
| 1797 | 1797 | $listOptions['columns']['banned_entity']['data'] = array( |
| 1798 | - 'function' => function ($rowData) |
|
| 1798 | + 'function' => function($rowData) |
|
| 1799 | 1799 | { |
| 1800 | 1800 | return range2ip( |
| 1801 | 1801 | $rowData['ip_low'] |
@@ -1812,7 +1812,7 @@ discard block |
||
| 1812 | 1812 | elseif ($context['selected_entity'] === 'hostname') |
| 1813 | 1813 | { |
| 1814 | 1814 | $listOptions['columns']['banned_entity']['data'] = array( |
| 1815 | - 'function' => function ($rowData) use ($smcFunc) |
|
| 1815 | + 'function' => function($rowData) use ($smcFunc) |
|
| 1816 | 1816 | { |
| 1817 | 1817 | return strtr($smcFunc['htmlspecialchars']($rowData['hostname']), array('%' => '*')); |
| 1818 | 1818 | }, |
@@ -1825,7 +1825,7 @@ discard block |
||
| 1825 | 1825 | elseif ($context['selected_entity'] === 'email') |
| 1826 | 1826 | { |
| 1827 | 1827 | $listOptions['columns']['banned_entity']['data'] = array( |
| 1828 | - 'function' => function ($rowData) use ($smcFunc) |
|
| 1828 | + 'function' => function($rowData) use ($smcFunc) |
|
| 1829 | 1829 | { |
| 1830 | 1830 | return strtr($smcFunc['htmlspecialchars']($rowData['email_address']), array('%' => '*')); |
| 1831 | 1831 | }, |
@@ -2032,7 +2032,7 @@ discard block |
||
| 2032 | 2032 | 'value' => $txt['ban_log_date'], |
| 2033 | 2033 | ), |
| 2034 | 2034 | 'data' => array( |
| 2035 | - 'function' => function ($rowData) |
|
| 2035 | + 'function' => function($rowData) |
|
| 2036 | 2036 | { |
| 2037 | 2037 | return timeformat($rowData['log_time']); |
| 2038 | 2038 | }, |
@@ -2122,7 +2122,7 @@ discard block |
||
| 2122 | 2122 | $log_entries = array(); |
| 2123 | 2123 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2124 | 2124 | { |
| 2125 | - $row['ip'] = $row['ip'] === null? $dash : inet_dtop($row['ip']); |
|
| 2125 | + $row['ip'] = $row['ip'] === null ? $dash : inet_dtop($row['ip']); |
|
| 2126 | 2126 | $log_entries[] = $row; |
| 2127 | 2127 | } |
| 2128 | 2128 | $smcFunc['db_free_result']($request); |
@@ -2170,7 +2170,7 @@ discard block |
||
| 2170 | 2170 | if ($low == $high) |
| 2171 | 2171 | return $low; |
| 2172 | 2172 | else |
| 2173 | - return $low . '-'.$high; |
|
| 2173 | + return $low . '-' . $high; |
|
| 2174 | 2174 | } |
| 2175 | 2175 | |
| 2176 | 2176 | /** |
@@ -2286,7 +2286,7 @@ discard block |
||
| 2286 | 2286 | $request = $smcFunc['db_query']('', ' |
| 2287 | 2287 | SELECT mem.id_member, mem.is_activated |
| 2288 | 2288 | FROM {db_prefix}members AS mem |
| 2289 | - WHERE ' . implode( ' OR ', $queryPart), |
|
| 2289 | + WHERE ' . implode(' OR ', $queryPart), |
|
| 2290 | 2290 | $queryValues |
| 2291 | 2291 | ); |
| 2292 | 2292 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
@@ -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 | /** |
| 21 | 22 | * Ban center. The main entrance point for all ban center functions. |
@@ -120,10 +121,11 @@ discard block |
||
| 120 | 121 | } |
| 121 | 122 | |
| 122 | 123 | // Create a date string so we don't overload them with date info. |
| 123 | - if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
| 124 | - $context['ban_time_format'] = $user_info['time_format']; |
|
| 125 | - else |
|
| 126 | - $context['ban_time_format'] = $matches[0]; |
|
| 124 | + if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
| 125 | + $context['ban_time_format'] = $user_info['time_format']; |
|
| 126 | + } else { |
|
| 127 | + $context['ban_time_format'] = $matches[0]; |
|
| 128 | + } |
|
| 127 | 129 | |
| 128 | 130 | $listOptions = array( |
| 129 | 131 | 'id' => 'ban_list', |
@@ -201,16 +203,19 @@ discard block |
||
| 201 | 203 | 'function' => function ($rowData) use ($txt) |
| 202 | 204 | { |
| 203 | 205 | // This ban never expires...whahaha. |
| 204 | - if ($rowData['expire_time'] === null) |
|
| 205 | - return $txt['never']; |
|
| 206 | + if ($rowData['expire_time'] === null) { |
|
| 207 | + return $txt['never']; |
|
| 208 | + } |
|
| 206 | 209 | |
| 207 | 210 | // This ban has already expired. |
| 208 | - elseif ($rowData['expire_time'] < time()) |
|
| 209 | - return sprintf('<span class="red">%1$s</span>', $txt['ban_expired']); |
|
| 211 | + elseif ($rowData['expire_time'] < time()) { |
|
| 212 | + return sprintf('<span class="red">%1$s</span>', $txt['ban_expired']); |
|
| 213 | + } |
|
| 210 | 214 | |
| 211 | 215 | // Still need to wait a few days for this ban to expire. |
| 212 | - else |
|
| 213 | - return sprintf('%1$d %2$s', ceil(($rowData['expire_time'] - time()) / (60 * 60 * 24)), $txt['ban_days']); |
|
| 216 | + else { |
|
| 217 | + return sprintf('%1$d %2$s', ceil(($rowData['expire_time'] - time()) / (60 * 60 * 24)), $txt['ban_days']); |
|
| 218 | + } |
|
| 214 | 219 | }, |
| 215 | 220 | ), |
| 216 | 221 | 'sort' => array( |
@@ -309,8 +314,9 @@ discard block |
||
| 309 | 314 | ) |
| 310 | 315 | ); |
| 311 | 316 | $bans = array(); |
| 312 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 313 | - $bans[] = $row; |
|
| 317 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 318 | + $bans[] = $row; |
|
| 319 | + } |
|
| 314 | 320 | |
| 315 | 321 | $smcFunc['db_free_result']($request); |
| 316 | 322 | |
@@ -352,8 +358,9 @@ discard block |
||
| 352 | 358 | { |
| 353 | 359 | global $txt, $modSettings, $context, $scripturl, $smcFunc, $sourcedir; |
| 354 | 360 | |
| 355 | - if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors'])) |
|
| 356 | - BanEdit2(); |
|
| 361 | + if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors'])) { |
|
| 362 | + BanEdit2(); |
|
| 363 | + } |
|
| 357 | 364 | |
| 358 | 365 | $ban_group_id = isset($context['ban']['id']) ? $context['ban']['id'] : (isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0); |
| 359 | 366 | |
@@ -364,10 +371,10 @@ discard block |
||
| 364 | 371 | |
| 365 | 372 | if (!empty($context['ban_errors'])) |
| 366 | 373 | { |
| 367 | - foreach ($context['ban_errors'] as $error) |
|
| 368 | - $context['error_messages'][$error] = $txt[$error]; |
|
| 369 | - } |
|
| 370 | - else |
|
| 374 | + foreach ($context['ban_errors'] as $error) { |
|
| 375 | + $context['error_messages'][$error] = $txt[$error]; |
|
| 376 | + } |
|
| 377 | + } else |
|
| 371 | 378 | { |
| 372 | 379 | // If we're editing an existing ban, get it from the database. |
| 373 | 380 | if (!empty($ban_group_id)) |
@@ -403,12 +410,13 @@ discard block |
||
| 403 | 410 | 'data' => array( |
| 404 | 411 | 'function' => function ($ban_item) use ($txt) |
| 405 | 412 | { |
| 406 | - if (in_array($ban_item['type'], array('ip', 'hostname', 'email'))) |
|
| 407 | - return '<strong>' . $txt[$ban_item['type']] . ':</strong> ' . $ban_item[$ban_item['type']]; |
|
| 408 | - elseif ($ban_item['type'] == 'user') |
|
| 409 | - return '<strong>' . $txt['username'] . ':</strong> ' . $ban_item['user']['link']; |
|
| 410 | - else |
|
| 411 | - return '<strong>' . $txt['unknown'] . ':</strong> ' . $ban_item['no_bantype_selected']; |
|
| 413 | + if (in_array($ban_item['type'], array('ip', 'hostname', 'email'))) { |
|
| 414 | + return '<strong>' . $txt[$ban_item['type']] . ':</strong> ' . $ban_item[$ban_item['type']]; |
|
| 415 | + } elseif ($ban_item['type'] == 'user') { |
|
| 416 | + return '<strong>' . $txt['username'] . ':</strong> ' . $ban_item['user']['link']; |
|
| 417 | + } else { |
|
| 418 | + return '<strong>' . $txt['unknown'] . ':</strong> ' . $ban_item['no_bantype_selected']; |
|
| 419 | + } |
|
| 412 | 420 | }, |
| 413 | 421 | 'style' => 'text-align: left;', |
| 414 | 422 | ), |
@@ -546,8 +554,9 @@ discard block |
||
| 546 | 554 | $context['ban']['from_user'] = true; |
| 547 | 555 | |
| 548 | 556 | // Would be nice if we could also ban the hostname. |
| 549 | - if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 || isValidIPv6($context['ban_suggestions']['main_ip'])) && empty($modSettings['disableHostnameLookup'])) |
|
| 550 | - $context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']); |
|
| 557 | + if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 || isValidIPv6($context['ban_suggestions']['main_ip'])) && empty($modSettings['disableHostnameLookup'])) { |
|
| 558 | + $context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']); |
|
| 559 | + } |
|
| 551 | 560 | |
| 552 | 561 | $context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']); |
| 553 | 562 | } |
@@ -615,8 +624,9 @@ discard block |
||
| 615 | 624 | 'items_per_page' => $items_per_page, |
| 616 | 625 | ) |
| 617 | 626 | ); |
| 618 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 619 | - fatal_lang_error('ban_not_found', false); |
|
| 627 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 628 | + fatal_lang_error('ban_not_found', false); |
|
| 629 | + } |
|
| 620 | 630 | |
| 621 | 631 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 622 | 632 | { |
@@ -653,18 +663,15 @@ discard block |
||
| 653 | 663 | { |
| 654 | 664 | $ban_items[$row['id_ban']]['type'] = 'ip'; |
| 655 | 665 | $ban_items[$row['id_ban']]['ip'] = range2ip($row['ip_low'], $row['ip_high']); |
| 656 | - } |
|
| 657 | - elseif (!empty($row['hostname'])) |
|
| 666 | + } elseif (!empty($row['hostname'])) |
|
| 658 | 667 | { |
| 659 | 668 | $ban_items[$row['id_ban']]['type'] = 'hostname'; |
| 660 | 669 | $ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']); |
| 661 | - } |
|
| 662 | - elseif (!empty($row['email_address'])) |
|
| 670 | + } elseif (!empty($row['email_address'])) |
|
| 663 | 671 | { |
| 664 | 672 | $ban_items[$row['id_ban']]['type'] = 'email'; |
| 665 | 673 | $ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']); |
| 666 | - } |
|
| 667 | - elseif (!empty($row['id_member'])) |
|
| 674 | + } elseif (!empty($row['id_member'])) |
|
| 668 | 675 | { |
| 669 | 676 | $ban_items[$row['id_ban']]['type'] = 'user'; |
| 670 | 677 | $ban_items[$row['id_ban']]['user'] = array( |
@@ -730,9 +737,10 @@ discard block |
||
| 730 | 737 | $search_list += array('ips_in_messages' => 'banLoadAdditionalIPsMember', 'ips_in_errors' => 'banLoadAdditionalIPsError'); |
| 731 | 738 | |
| 732 | 739 | $return = array(); |
| 733 | - foreach ($search_list as $key => $callable) |
|
| 734 | - if (is_callable($callable)) |
|
| 740 | + foreach ($search_list as $key => $callable) { |
|
| 741 | + if (is_callable($callable)) |
|
| 735 | 742 | $return[$key] = call_user_func($callable, $member_id); |
| 743 | + } |
|
| 736 | 744 | |
| 737 | 745 | return $return; |
| 738 | 746 | } |
@@ -757,8 +765,9 @@ discard block |
||
| 757 | 765 | 'current_user' => $member_id, |
| 758 | 766 | ) |
| 759 | 767 | ); |
| 760 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 761 | - $message_ips[] = inet_dtop($row['poster_ip']); |
|
| 768 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 769 | + $message_ips[] = inet_dtop($row['poster_ip']); |
|
| 770 | + } |
|
| 762 | 771 | $smcFunc['db_free_result']($request); |
| 763 | 772 | |
| 764 | 773 | return $message_ips; |
@@ -783,8 +792,9 @@ discard block |
||
| 783 | 792 | 'current_user' => $member_id, |
| 784 | 793 | ) |
| 785 | 794 | ); |
| 786 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 787 | - $error_ips[] = inet_dtop($row['ip']); |
|
| 795 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 796 | + $error_ips[] = inet_dtop($row['ip']); |
|
| 797 | + } |
|
| 788 | 798 | $smcFunc['db_free_result']($request); |
| 789 | 799 | |
| 790 | 800 | return $error_ips; |
@@ -825,11 +835,13 @@ discard block |
||
| 825 | 835 | $ban_info['cannot']['login'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_login']) ? 0 : 1; |
| 826 | 836 | |
| 827 | 837 | // Adding a new ban group |
| 828 | - if (empty($_REQUEST['bg'])) |
|
| 829 | - $ban_group_id = insertBanGroup($ban_info); |
|
| 838 | + if (empty($_REQUEST['bg'])) { |
|
| 839 | + $ban_group_id = insertBanGroup($ban_info); |
|
| 840 | + } |
|
| 830 | 841 | // Editing an existing ban group |
| 831 | - else |
|
| 832 | - $ban_group_id = updateBanGroup($ban_info); |
|
| 842 | + else { |
|
| 843 | + $ban_group_id = updateBanGroup($ban_info); |
|
| 844 | + } |
|
| 833 | 845 | |
| 834 | 846 | if (is_numeric($ban_group_id)) |
| 835 | 847 | { |
@@ -840,9 +852,10 @@ discard block |
||
| 840 | 852 | $context['ban'] = $ban_info; |
| 841 | 853 | } |
| 842 | 854 | |
| 843 | - if (isset($_POST['ban_suggestions'])) |
|
| 844 | - // @TODO: is $_REQUEST['bi'] ever set? |
|
| 855 | + if (isset($_POST['ban_suggestions'])) { |
|
| 856 | + // @TODO: is $_REQUEST['bi'] ever set? |
|
| 845 | 857 | $saved_triggers = saveTriggers($_POST['ban_suggestions'], $ban_info['id'], isset($_REQUEST['u']) ? (int) $_REQUEST['u'] : 0, isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0); |
| 858 | + } |
|
| 846 | 859 | |
| 847 | 860 | // Something went wrong somewhere... Oh well, let's go back. |
| 848 | 861 | if (!empty($context['ban_errors'])) |
@@ -852,8 +865,9 @@ discard block |
||
| 852 | 865 | $context['ban_suggestions'] = array_merge($context['ban_suggestions'], getMemberData((int) $_REQUEST['u'])); |
| 853 | 866 | |
| 854 | 867 | // Not strictly necessary, but it's nice |
| 855 | - if (!empty($context['ban_suggestions']['member']['id'])) |
|
| 856 | - $context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']); |
|
| 868 | + if (!empty($context['ban_suggestions']['member']['id'])) { |
|
| 869 | + $context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']); |
|
| 870 | + } |
|
| 857 | 871 | return BanEdit(); |
| 858 | 872 | } |
| 859 | 873 | $context['ban_suggestions']['saved_triggers'] = !empty($saved_triggers) ? $saved_triggers : array(); |
@@ -902,10 +916,11 @@ discard block |
||
| 902 | 916 | |
| 903 | 917 | foreach ($suggestions as $key => $value) |
| 904 | 918 | { |
| 905 | - if (is_array($value)) |
|
| 906 | - $triggers[$key] = $value; |
|
| 907 | - else |
|
| 908 | - $triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : ''; |
|
| 919 | + if (is_array($value)) { |
|
| 920 | + $triggers[$key] = $value; |
|
| 921 | + } else { |
|
| 922 | + $triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : ''; |
|
| 923 | + } |
|
| 909 | 924 | } |
| 910 | 925 | |
| 911 | 926 | $ban_triggers = validateTriggers($triggers); |
@@ -913,16 +928,18 @@ discard block |
||
| 913 | 928 | // Time to save! |
| 914 | 929 | if (!empty($ban_triggers['ban_triggers']) && empty($context['ban_errors'])) |
| 915 | 930 | { |
| 916 | - if (empty($ban_id)) |
|
| 917 | - addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']); |
|
| 918 | - else |
|
| 919 | - updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']); |
|
| 931 | + if (empty($ban_id)) { |
|
| 932 | + addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']); |
|
| 933 | + } else { |
|
| 934 | + updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']); |
|
| 935 | + } |
|
| 936 | + } |
|
| 937 | + if (!empty($context['ban_errors'])) { |
|
| 938 | + return $triggers; |
|
| 939 | + } else { |
|
| 940 | + return false; |
|
| 941 | + } |
|
| 920 | 942 | } |
| 921 | - if (!empty($context['ban_errors'])) |
|
| 922 | - return $triggers; |
|
| 923 | - else |
|
| 924 | - return false; |
|
| 925 | -} |
|
| 926 | 943 | |
| 927 | 944 | /** |
| 928 | 945 | * This function removes a bunch of triggers based on ids |
@@ -936,14 +953,17 @@ discard block |
||
| 936 | 953 | { |
| 937 | 954 | global $smcFunc, $scripturl; |
| 938 | 955 | |
| 939 | - if ($group_id !== false) |
|
| 940 | - $group_id = (int) $group_id; |
|
| 956 | + if ($group_id !== false) { |
|
| 957 | + $group_id = (int) $group_id; |
|
| 958 | + } |
|
| 941 | 959 | |
| 942 | - if (empty($group_id) && empty($items_ids)) |
|
| 943 | - return false; |
|
| 960 | + if (empty($group_id) && empty($items_ids)) { |
|
| 961 | + return false; |
|
| 962 | + } |
|
| 944 | 963 | |
| 945 | - if (!is_array($items_ids)) |
|
| 946 | - $items_ids = array($items_ids); |
|
| 964 | + if (!is_array($items_ids)) { |
|
| 965 | + $items_ids = array($items_ids); |
|
| 966 | + } |
|
| 947 | 967 | |
| 948 | 968 | $log_info = array(); |
| 949 | 969 | $ban_items = array(); |
@@ -981,8 +1001,7 @@ discard block |
||
| 981 | 1001 | 'bantype' => ($is_range ? 'ip_range' : 'main_ip'), |
| 982 | 1002 | 'value' => $ban_items[$row['id_ban']]['ip'], |
| 983 | 1003 | ); |
| 984 | - } |
|
| 985 | - elseif (!empty($row['hostname'])) |
|
| 1004 | + } elseif (!empty($row['hostname'])) |
|
| 986 | 1005 | { |
| 987 | 1006 | $ban_items[$row['id_ban']]['type'] = 'hostname'; |
| 988 | 1007 | $ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']); |
@@ -990,8 +1009,7 @@ discard block |
||
| 990 | 1009 | 'bantype' => 'hostname', |
| 991 | 1010 | 'value' => $row['hostname'], |
| 992 | 1011 | ); |
| 993 | - } |
|
| 994 | - elseif (!empty($row['email_address'])) |
|
| 1012 | + } elseif (!empty($row['email_address'])) |
|
| 995 | 1013 | { |
| 996 | 1014 | $ban_items[$row['id_ban']]['type'] = 'email'; |
| 997 | 1015 | $ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']); |
@@ -999,8 +1017,7 @@ discard block |
||
| 999 | 1017 | 'bantype' => 'email', |
| 1000 | 1018 | 'value' => $ban_items[$row['id_ban']]['email'], |
| 1001 | 1019 | ); |
| 1002 | - } |
|
| 1003 | - elseif (!empty($row['id_member'])) |
|
| 1020 | + } elseif (!empty($row['id_member'])) |
|
| 1004 | 1021 | { |
| 1005 | 1022 | $ban_items[$row['id_ban']]['type'] = 'user'; |
| 1006 | 1023 | $ban_items[$row['id_ban']]['user'] = array( |
@@ -1033,8 +1050,7 @@ discard block |
||
| 1033 | 1050 | 'ban_group' => $group_id, |
| 1034 | 1051 | ) |
| 1035 | 1052 | ); |
| 1036 | - } |
|
| 1037 | - elseif (!empty($items_ids)) |
|
| 1053 | + } elseif (!empty($items_ids)) |
|
| 1038 | 1054 | { |
| 1039 | 1055 | $smcFunc['db_query']('', ' |
| 1040 | 1056 | DELETE FROM {db_prefix}ban_items |
@@ -1059,13 +1075,15 @@ discard block |
||
| 1059 | 1075 | { |
| 1060 | 1076 | global $smcFunc; |
| 1061 | 1077 | |
| 1062 | - if (!is_array($group_ids)) |
|
| 1063 | - $group_ids = array($group_ids); |
|
| 1078 | + if (!is_array($group_ids)) { |
|
| 1079 | + $group_ids = array($group_ids); |
|
| 1080 | + } |
|
| 1064 | 1081 | |
| 1065 | 1082 | $group_ids = array_unique($group_ids); |
| 1066 | 1083 | |
| 1067 | - if (empty($group_ids)) |
|
| 1068 | - return false; |
|
| 1084 | + if (empty($group_ids)) { |
|
| 1085 | + return false; |
|
| 1086 | + } |
|
| 1069 | 1087 | |
| 1070 | 1088 | $smcFunc['db_query']('', ' |
| 1071 | 1089 | DELETE FROM {db_prefix}ban_groups |
@@ -1089,21 +1107,23 @@ discard block |
||
| 1089 | 1107 | { |
| 1090 | 1108 | global $smcFunc; |
| 1091 | 1109 | |
| 1092 | - if (empty($ids)) |
|
| 1093 | - $smcFunc['db_query']('truncate_table', ' |
|
| 1110 | + if (empty($ids)) { |
|
| 1111 | + $smcFunc['db_query']('truncate_table', ' |
|
| 1094 | 1112 | TRUNCATE {db_prefix}log_banned', |
| 1095 | 1113 | array( |
| 1096 | 1114 | ) |
| 1097 | 1115 | ); |
| 1098 | - else |
|
| 1116 | + } else |
|
| 1099 | 1117 | { |
| 1100 | - if (!is_array($ids)) |
|
| 1101 | - $ids = array($ids); |
|
| 1118 | + if (!is_array($ids)) { |
|
| 1119 | + $ids = array($ids); |
|
| 1120 | + } |
|
| 1102 | 1121 | |
| 1103 | 1122 | $ids = array_unique($ids); |
| 1104 | 1123 | |
| 1105 | - if (empty($ids)) |
|
| 1106 | - return false; |
|
| 1124 | + if (empty($ids)) { |
|
| 1125 | + return false; |
|
| 1126 | + } |
|
| 1107 | 1127 | |
| 1108 | 1128 | $smcFunc['db_query']('', ' |
| 1109 | 1129 | DELETE FROM {db_prefix}log_banned |
@@ -1129,8 +1149,9 @@ discard block |
||
| 1129 | 1149 | { |
| 1130 | 1150 | global $context, $smcFunc; |
| 1131 | 1151 | |
| 1132 | - if (empty($triggers)) |
|
| 1133 | - $context['ban_erros'][] = 'ban_empty_triggers'; |
|
| 1152 | + if (empty($triggers)) { |
|
| 1153 | + $context['ban_erros'][] = 'ban_empty_triggers'; |
|
| 1154 | + } |
|
| 1134 | 1155 | |
| 1135 | 1156 | $ban_triggers = array(); |
| 1136 | 1157 | $log_info = array(); |
@@ -1139,39 +1160,39 @@ discard block |
||
| 1139 | 1160 | { |
| 1140 | 1161 | if (!empty($value)) |
| 1141 | 1162 | { |
| 1142 | - if ($key == 'member') |
|
| 1143 | - continue; |
|
| 1163 | + if ($key == 'member') { |
|
| 1164 | + continue; |
|
| 1165 | + } |
|
| 1144 | 1166 | |
| 1145 | 1167 | if ($key == 'main_ip') |
| 1146 | 1168 | { |
| 1147 | 1169 | $value = trim($value); |
| 1148 | 1170 | $ip_parts = ip2range($value); |
| 1149 | - if (!checkExistingTriggerIP($ip_parts, $value)) |
|
| 1150 | - $context['ban_erros'][] = 'invalid_ip'; |
|
| 1151 | - else |
|
| 1171 | + if (!checkExistingTriggerIP($ip_parts, $value)) { |
|
| 1172 | + $context['ban_erros'][] = 'invalid_ip'; |
|
| 1173 | + } else |
|
| 1152 | 1174 | { |
| 1153 | 1175 | $ban_triggers['main_ip'] = array( |
| 1154 | 1176 | 'ip_low' => $ip_parts['low'], |
| 1155 | 1177 | 'ip_high' => $ip_parts['high'] |
| 1156 | 1178 | ); |
| 1157 | 1179 | } |
| 1158 | - } |
|
| 1159 | - elseif ($key == 'hostname') |
|
| 1180 | + } elseif ($key == 'hostname') |
|
| 1160 | 1181 | { |
| 1161 | - if (preg_match('/[^\w.\-*]/', $value) == 1) |
|
| 1162 | - $context['ban_erros'][] = 'invalid_hostname'; |
|
| 1163 | - else |
|
| 1182 | + if (preg_match('/[^\w.\-*]/', $value) == 1) { |
|
| 1183 | + $context['ban_erros'][] = 'invalid_hostname'; |
|
| 1184 | + } else |
|
| 1164 | 1185 | { |
| 1165 | 1186 | // Replace the * wildcard by a MySQL wildcard %. |
| 1166 | 1187 | $value = substr(str_replace('*', '%', $value), 0, 255); |
| 1167 | 1188 | |
| 1168 | 1189 | $ban_triggers['hostname']['hostname'] = $value; |
| 1169 | 1190 | } |
| 1170 | - } |
|
| 1171 | - elseif ($key == 'email') |
|
| 1191 | + } elseif ($key == 'email') |
|
| 1172 | 1192 | { |
| 1173 | - if (preg_match('/[^\w.\-\+*@]/', $value) == 1) |
|
| 1174 | - $context['ban_erros'][] = 'invalid_email'; |
|
| 1193 | + if (preg_match('/[^\w.\-\+*@]/', $value) == 1) { |
|
| 1194 | + $context['ban_erros'][] = 'invalid_email'; |
|
| 1195 | + } |
|
| 1175 | 1196 | |
| 1176 | 1197 | // Check the user is not banning an admin. |
| 1177 | 1198 | $request = $smcFunc['db_query']('', ' |
@@ -1185,15 +1206,15 @@ discard block |
||
| 1185 | 1206 | 'email' => $value, |
| 1186 | 1207 | ) |
| 1187 | 1208 | ); |
| 1188 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 1189 | - $context['ban_erros'][] = 'no_ban_admin'; |
|
| 1209 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 1210 | + $context['ban_erros'][] = 'no_ban_admin'; |
|
| 1211 | + } |
|
| 1190 | 1212 | $smcFunc['db_free_result']($request); |
| 1191 | 1213 | |
| 1192 | 1214 | $value = substr(strtolower(str_replace('*', '%', $value)), 0, 255); |
| 1193 | 1215 | |
| 1194 | 1216 | $ban_triggers['email']['email_address'] = $value; |
| 1195 | - } |
|
| 1196 | - elseif ($key == 'user') |
|
| 1217 | + } elseif ($key == 'user') |
|
| 1197 | 1218 | { |
| 1198 | 1219 | $user = preg_replace('~&#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $smcFunc['htmlspecialchars']($value, ENT_QUOTES)); |
| 1199 | 1220 | |
@@ -1207,8 +1228,9 @@ discard block |
||
| 1207 | 1228 | 'username' => $user, |
| 1208 | 1229 | ) |
| 1209 | 1230 | ); |
| 1210 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1211 | - $context['ban_erros'][] = 'invalid_username'; |
|
| 1231 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1232 | + $context['ban_erros'][] = 'invalid_username'; |
|
| 1233 | + } |
|
| 1212 | 1234 | list ($value, $isAdmin) = $smcFunc['db_fetch_row']($request); |
| 1213 | 1235 | $smcFunc['db_free_result']($request); |
| 1214 | 1236 | |
@@ -1216,25 +1238,25 @@ discard block |
||
| 1216 | 1238 | { |
| 1217 | 1239 | unset($value); |
| 1218 | 1240 | $context['ban_erros'][] = 'no_ban_admin'; |
| 1241 | + } else { |
|
| 1242 | + $ban_triggers['user']['id_member'] = $value; |
|
| 1219 | 1243 | } |
| 1220 | - else |
|
| 1221 | - $ban_triggers['user']['id_member'] = $value; |
|
| 1222 | - } |
|
| 1223 | - elseif (in_array($key, array('ips_in_messages', 'ips_in_errors'))) |
|
| 1244 | + } elseif (in_array($key, array('ips_in_messages', 'ips_in_errors'))) |
|
| 1224 | 1245 | { |
| 1225 | 1246 | // Special case, those two are arrays themselves |
| 1226 | 1247 | $values = array_unique($value); |
| 1227 | 1248 | // Don't add the main IP again. |
| 1228 | - if (isset($triggers['main_ip'])) |
|
| 1229 | - $values = array_diff($values, array($triggers['main_ip'])); |
|
| 1249 | + if (isset($triggers['main_ip'])) { |
|
| 1250 | + $values = array_diff($values, array($triggers['main_ip'])); |
|
| 1251 | + } |
|
| 1230 | 1252 | unset($value); |
| 1231 | 1253 | foreach ($values as $val) |
| 1232 | 1254 | { |
| 1233 | 1255 | $val = trim($val); |
| 1234 | 1256 | $ip_parts = ip2range($val); |
| 1235 | - if (!checkExistingTriggerIP($ip_parts, $val)) |
|
| 1236 | - $context['ban_erros'][] = 'invalid_ip'; |
|
| 1237 | - else |
|
| 1257 | + if (!checkExistingTriggerIP($ip_parts, $val)) { |
|
| 1258 | + $context['ban_erros'][] = 'invalid_ip'; |
|
| 1259 | + } else |
|
| 1238 | 1260 | { |
| 1239 | 1261 | $ban_triggers[$key][] = array( |
| 1240 | 1262 | 'ip_low' => $ip_parts['low'], |
@@ -1247,15 +1269,16 @@ discard block |
||
| 1247 | 1269 | ); |
| 1248 | 1270 | } |
| 1249 | 1271 | } |
| 1272 | + } else { |
|
| 1273 | + $context['ban_erros'][] = 'no_bantype_selected'; |
|
| 1250 | 1274 | } |
| 1251 | - else |
|
| 1252 | - $context['ban_erros'][] = 'no_bantype_selected'; |
|
| 1253 | 1275 | |
| 1254 | - if (isset($value) && !is_array($value)) |
|
| 1255 | - $log_info[] = array( |
|
| 1276 | + if (isset($value) && !is_array($value)) { |
|
| 1277 | + $log_info[] = array( |
|
| 1256 | 1278 | 'value' => $value, |
| 1257 | 1279 | 'bantype' => $key, |
| 1258 | 1280 | ); |
| 1281 | + } |
|
| 1259 | 1282 | } |
| 1260 | 1283 | } |
| 1261 | 1284 | return array('ban_triggers' => $ban_triggers, 'log_info' => $log_info); |
@@ -1275,8 +1298,9 @@ discard block |
||
| 1275 | 1298 | { |
| 1276 | 1299 | global $smcFunc, $context; |
| 1277 | 1300 | |
| 1278 | - if (empty($group_id)) |
|
| 1279 | - $context['ban_errors'][] = 'ban_id_empty'; |
|
| 1301 | + if (empty($group_id)) { |
|
| 1302 | + $context['ban_errors'][] = 'ban_id_empty'; |
|
| 1303 | + } |
|
| 1280 | 1304 | |
| 1281 | 1305 | // Preset all values that are required. |
| 1282 | 1306 | $values = array( |
@@ -1301,18 +1325,21 @@ discard block |
||
| 1301 | 1325 | foreach ($triggers as $key => $trigger) |
| 1302 | 1326 | { |
| 1303 | 1327 | // Exceptions, exceptions, exceptions...always exceptions... :P |
| 1304 | - if (in_array($key, array('ips_in_messages', 'ips_in_errors'))) |
|
| 1305 | - foreach ($trigger as $real_trigger) |
|
| 1328 | + if (in_array($key, array('ips_in_messages', 'ips_in_errors'))) { |
|
| 1329 | + foreach ($trigger as $real_trigger) |
|
| 1306 | 1330 | $insertTriggers[] = array_merge($values, $real_trigger); |
| 1307 | - else |
|
| 1308 | - $insertTriggers[] = array_merge($values, $trigger); |
|
| 1331 | + } else { |
|
| 1332 | + $insertTriggers[] = array_merge($values, $trigger); |
|
| 1333 | + } |
|
| 1309 | 1334 | } |
| 1310 | 1335 | |
| 1311 | - if (empty($insertTriggers)) |
|
| 1312 | - $context['ban_errors'][] = 'ban_no_triggers'; |
|
| 1336 | + if (empty($insertTriggers)) { |
|
| 1337 | + $context['ban_errors'][] = 'ban_no_triggers'; |
|
| 1338 | + } |
|
| 1313 | 1339 | |
| 1314 | - if (!empty($context['ban_errors'])) |
|
| 1315 | - return false; |
|
| 1340 | + if (!empty($context['ban_errors'])) { |
|
| 1341 | + return false; |
|
| 1342 | + } |
|
| 1316 | 1343 | |
| 1317 | 1344 | $smcFunc['db_insert']('', |
| 1318 | 1345 | '{db_prefix}ban_items', |
@@ -1340,15 +1367,19 @@ discard block |
||
| 1340 | 1367 | { |
| 1341 | 1368 | global $smcFunc, $context; |
| 1342 | 1369 | |
| 1343 | - if (empty($ban_item)) |
|
| 1344 | - $context['ban_errors'][] = 'ban_ban_item_empty'; |
|
| 1345 | - if (empty($group_id)) |
|
| 1346 | - $context['ban_errors'][] = 'ban_id_empty'; |
|
| 1347 | - if (empty($trigger)) |
|
| 1348 | - $context['ban_errors'][] = 'ban_no_triggers'; |
|
| 1370 | + if (empty($ban_item)) { |
|
| 1371 | + $context['ban_errors'][] = 'ban_ban_item_empty'; |
|
| 1372 | + } |
|
| 1373 | + if (empty($group_id)) { |
|
| 1374 | + $context['ban_errors'][] = 'ban_id_empty'; |
|
| 1375 | + } |
|
| 1376 | + if (empty($trigger)) { |
|
| 1377 | + $context['ban_errors'][] = 'ban_no_triggers'; |
|
| 1378 | + } |
|
| 1349 | 1379 | |
| 1350 | - if (!empty($context['ban_errors'])) |
|
| 1351 | - return; |
|
| 1380 | + if (!empty($context['ban_errors'])) { |
|
| 1381 | + return; |
|
| 1382 | + } |
|
| 1352 | 1383 | |
| 1353 | 1384 | // Preset all values that are required. |
| 1354 | 1385 | $values = array( |
@@ -1389,8 +1420,9 @@ discard block |
||
| 1389 | 1420 | */ |
| 1390 | 1421 | function logTriggersUpdates($logs, $new = true, $removal = false) |
| 1391 | 1422 | { |
| 1392 | - if (empty($logs)) |
|
| 1393 | - return; |
|
| 1423 | + if (empty($logs)) { |
|
| 1424 | + return; |
|
| 1425 | + } |
|
| 1394 | 1426 | |
| 1395 | 1427 | $log_name_map = array( |
| 1396 | 1428 | 'main_ip' => 'ip_range', |
@@ -1401,14 +1433,15 @@ discard block |
||
| 1401 | 1433 | ); |
| 1402 | 1434 | |
| 1403 | 1435 | // Log the addion of the ban entries into the moderation log. |
| 1404 | - foreach ($logs as $log) |
|
| 1405 | - logAction('ban' . ($removal == true ? 'remove' : ''), array( |
|
| 1436 | + foreach ($logs as $log) { |
|
| 1437 | + logAction('ban' . ($removal == true ? 'remove' : ''), array( |
|
| 1406 | 1438 | $log_name_map[$log['bantype']] => $log['value'], |
| 1407 | 1439 | 'new' => empty($new) ? 0 : 1, |
| 1408 | 1440 | 'remove' => empty($removal) ? 0 : 1, |
| 1409 | 1441 | 'type' => $log['bantype'], |
| 1410 | 1442 | )); |
| 1411 | -} |
|
| 1443 | + } |
|
| 1444 | + } |
|
| 1412 | 1445 | |
| 1413 | 1446 | /** |
| 1414 | 1447 | * Updates an existing ban group |
@@ -1422,12 +1455,15 @@ discard block |
||
| 1422 | 1455 | { |
| 1423 | 1456 | global $smcFunc, $context; |
| 1424 | 1457 | |
| 1425 | - if (empty($ban_info['name'])) |
|
| 1426 | - $context['ban_errors'][] = 'ban_name_empty'; |
|
| 1427 | - if (empty($ban_info['id'])) |
|
| 1428 | - $context['ban_errors'][] = 'ban_id_empty'; |
|
| 1429 | - if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) |
|
| 1430 | - $context['ban_errors'][] = 'ban_unknown_restriction_type'; |
|
| 1458 | + if (empty($ban_info['name'])) { |
|
| 1459 | + $context['ban_errors'][] = 'ban_name_empty'; |
|
| 1460 | + } |
|
| 1461 | + if (empty($ban_info['id'])) { |
|
| 1462 | + $context['ban_errors'][] = 'ban_id_empty'; |
|
| 1463 | + } |
|
| 1464 | + if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) { |
|
| 1465 | + $context['ban_errors'][] = 'ban_unknown_restriction_type'; |
|
| 1466 | + } |
|
| 1431 | 1467 | |
| 1432 | 1468 | if(!empty($ban_info['id'])) |
| 1433 | 1469 | { |
@@ -1442,8 +1478,9 @@ discard block |
||
| 1442 | 1478 | ) |
| 1443 | 1479 | ); |
| 1444 | 1480 | |
| 1445 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1446 | - $context['ban_errors'][] = 'ban_not_found'; |
|
| 1481 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1482 | + $context['ban_errors'][] = 'ban_not_found'; |
|
| 1483 | + } |
|
| 1447 | 1484 | $smcFunc['db_free_result']($request); |
| 1448 | 1485 | } |
| 1449 | 1486 | |
@@ -1461,13 +1498,15 @@ discard block |
||
| 1461 | 1498 | 'new_ban_name' => $ban_info['name'], |
| 1462 | 1499 | ) |
| 1463 | 1500 | ); |
| 1464 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 1465 | - $context['ban_errors'][] = 'ban_name_exists'; |
|
| 1501 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 1502 | + $context['ban_errors'][] = 'ban_name_exists'; |
|
| 1503 | + } |
|
| 1466 | 1504 | $smcFunc['db_free_result']($request); |
| 1467 | 1505 | } |
| 1468 | 1506 | |
| 1469 | - if (!empty($context['ban_errors'])) |
|
| 1470 | - return $ban_info['id']; |
|
| 1507 | + if (!empty($context['ban_errors'])) { |
|
| 1508 | + return $ban_info['id']; |
|
| 1509 | + } |
|
| 1471 | 1510 | |
| 1472 | 1511 | $smcFunc['db_query']('', ' |
| 1473 | 1512 | UPDATE {db_prefix}ban_groups |
@@ -1511,10 +1550,12 @@ discard block |
||
| 1511 | 1550 | { |
| 1512 | 1551 | global $smcFunc, $context; |
| 1513 | 1552 | |
| 1514 | - if (empty($ban_info['name'])) |
|
| 1515 | - $context['ban_errors'][] = 'ban_name_empty'; |
|
| 1516 | - if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) |
|
| 1517 | - $context['ban_errors'][] = 'ban_unknown_restriction_type'; |
|
| 1553 | + if (empty($ban_info['name'])) { |
|
| 1554 | + $context['ban_errors'][] = 'ban_name_empty'; |
|
| 1555 | + } |
|
| 1556 | + if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) { |
|
| 1557 | + $context['ban_errors'][] = 'ban_unknown_restriction_type'; |
|
| 1558 | + } |
|
| 1518 | 1559 | |
| 1519 | 1560 | if(!empty($ban_info['name'])) |
| 1520 | 1561 | { |
@@ -1529,13 +1570,15 @@ discard block |
||
| 1529 | 1570 | ) |
| 1530 | 1571 | ); |
| 1531 | 1572 | |
| 1532 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
| 1533 | - $context['ban_errors'][] = 'ban_name_exists'; |
|
| 1573 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
| 1574 | + $context['ban_errors'][] = 'ban_name_exists'; |
|
| 1575 | + } |
|
| 1534 | 1576 | $smcFunc['db_free_result']($request); |
| 1535 | 1577 | } |
| 1536 | 1578 | |
| 1537 | - if (!empty($context['ban_errors'])) |
|
| 1538 | - return; |
|
| 1579 | + if (!empty($context['ban_errors'])) { |
|
| 1580 | + return; |
|
| 1581 | + } |
|
| 1539 | 1582 | |
| 1540 | 1583 | // Yes yes, we're ready to add now. |
| 1541 | 1584 | $smcFunc['db_insert']('', |
@@ -1552,8 +1595,9 @@ discard block |
||
| 1552 | 1595 | ); |
| 1553 | 1596 | $ban_info['id'] = $smcFunc['db_insert_id']('{db_prefix}ban_groups', 'id_ban_group'); |
| 1554 | 1597 | |
| 1555 | - if (empty($ban_info['id'])) |
|
| 1556 | - $context['ban_errors'][] = 'impossible_insert_new_bangroup'; |
|
| 1598 | + if (empty($ban_info['id'])) { |
|
| 1599 | + $context['ban_errors'][] = 'impossible_insert_new_bangroup'; |
|
| 1600 | + } |
|
| 1557 | 1601 | |
| 1558 | 1602 | return $ban_info['id']; |
| 1559 | 1603 | } |
@@ -1578,24 +1622,24 @@ discard block |
||
| 1578 | 1622 | $ban_group = isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0; |
| 1579 | 1623 | $ban_id = isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0; |
| 1580 | 1624 | |
| 1581 | - if (empty($ban_group)) |
|
| 1582 | - fatal_lang_error('ban_not_found', false); |
|
| 1625 | + if (empty($ban_group)) { |
|
| 1626 | + fatal_lang_error('ban_not_found', false); |
|
| 1627 | + } |
|
| 1583 | 1628 | |
| 1584 | 1629 | if (isset($_POST['add_new_trigger']) && !empty($_POST['ban_suggestions'])) |
| 1585 | 1630 | { |
| 1586 | 1631 | saveTriggers($_POST['ban_suggestions'], $ban_group, 0, $ban_id); |
| 1587 | 1632 | redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : '')); |
| 1588 | - } |
|
| 1589 | - elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions'])) |
|
| 1633 | + } elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions'])) |
|
| 1590 | 1634 | { |
| 1591 | 1635 | // The first replaces the old one, the others are added new (simplification, otherwise it would require another query and some work...) |
| 1592 | 1636 | saveTriggers(array_shift($_POST['ban_suggestions']), $ban_group, 0, $ban_id); |
| 1593 | - if (!empty($_POST['ban_suggestions'])) |
|
| 1594 | - saveTriggers($_POST['ban_suggestions'], $ban_group); |
|
| 1637 | + if (!empty($_POST['ban_suggestions'])) { |
|
| 1638 | + saveTriggers($_POST['ban_suggestions'], $ban_group); |
|
| 1639 | + } |
|
| 1595 | 1640 | |
| 1596 | 1641 | redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : '')); |
| 1597 | - } |
|
| 1598 | - elseif (isset($_POST['edit_trigger'])) |
|
| 1642 | + } elseif (isset($_POST['edit_trigger'])) |
|
| 1599 | 1643 | { |
| 1600 | 1644 | removeBanTriggers($ban_id); |
| 1601 | 1645 | redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : '')); |
@@ -1626,8 +1670,7 @@ discard block |
||
| 1626 | 1670 | ), |
| 1627 | 1671 | 'is_new' => true, |
| 1628 | 1672 | ); |
| 1629 | - } |
|
| 1630 | - else |
|
| 1673 | + } else |
|
| 1631 | 1674 | { |
| 1632 | 1675 | $request = $smcFunc['db_query']('', ' |
| 1633 | 1676 | SELECT |
@@ -1644,8 +1687,9 @@ discard block |
||
| 1644 | 1687 | 'ban_group' => $ban_group, |
| 1645 | 1688 | ) |
| 1646 | 1689 | ); |
| 1647 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1648 | - fatal_lang_error('ban_not_found', false); |
|
| 1690 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1691 | + fatal_lang_error('ban_not_found', false); |
|
| 1692 | + } |
|
| 1649 | 1693 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1650 | 1694 | $smcFunc['db_free_result']($request); |
| 1651 | 1695 | |
@@ -1694,8 +1738,9 @@ discard block |
||
| 1694 | 1738 | removeBanTriggers($_POST['remove']); |
| 1695 | 1739 | |
| 1696 | 1740 | // Rehabilitate some members. |
| 1697 | - if ($_REQUEST['entity'] == 'member') |
|
| 1698 | - updateBanMembers(); |
|
| 1741 | + if ($_REQUEST['entity'] == 'member') { |
|
| 1742 | + updateBanMembers(); |
|
| 1743 | + } |
|
| 1699 | 1744 | |
| 1700 | 1745 | // Make sure the ban cache is refreshed. |
| 1701 | 1746 | updateSettings(array('banLastUpdated' => time())); |
@@ -1808,8 +1853,7 @@ discard block |
||
| 1808 | 1853 | 'default' => 'bi.ip_low, bi.ip_high, bi.ip_low', |
| 1809 | 1854 | 'reverse' => 'bi.ip_low DESC, bi.ip_high DESC', |
| 1810 | 1855 | ); |
| 1811 | - } |
|
| 1812 | - elseif ($context['selected_entity'] === 'hostname') |
|
| 1856 | + } elseif ($context['selected_entity'] === 'hostname') |
|
| 1813 | 1857 | { |
| 1814 | 1858 | $listOptions['columns']['banned_entity']['data'] = array( |
| 1815 | 1859 | 'function' => function ($rowData) use ($smcFunc) |
@@ -1821,8 +1865,7 @@ discard block |
||
| 1821 | 1865 | 'default' => 'bi.hostname', |
| 1822 | 1866 | 'reverse' => 'bi.hostname DESC', |
| 1823 | 1867 | ); |
| 1824 | - } |
|
| 1825 | - elseif ($context['selected_entity'] === 'email') |
|
| 1868 | + } elseif ($context['selected_entity'] === 'email') |
|
| 1826 | 1869 | { |
| 1827 | 1870 | $listOptions['columns']['banned_entity']['data'] = array( |
| 1828 | 1871 | 'function' => function ($rowData) use ($smcFunc) |
@@ -1834,8 +1877,7 @@ discard block |
||
| 1834 | 1877 | 'default' => 'bi.email_address', |
| 1835 | 1878 | 'reverse' => 'bi.email_address DESC', |
| 1836 | 1879 | ); |
| 1837 | - } |
|
| 1838 | - elseif ($context['selected_entity'] === 'member') |
|
| 1880 | + } elseif ($context['selected_entity'] === 'member') |
|
| 1839 | 1881 | { |
| 1840 | 1882 | $listOptions['columns']['banned_entity']['data'] = array( |
| 1841 | 1883 | 'sprintf' => array( |
@@ -1899,8 +1941,9 @@ discard block |
||
| 1899 | 1941 | ) |
| 1900 | 1942 | ); |
| 1901 | 1943 | $ban_triggers = array(); |
| 1902 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1903 | - $ban_triggers[] = $row; |
|
| 1944 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1945 | + $ban_triggers[] = $row; |
|
| 1946 | + } |
|
| 1904 | 1947 | $smcFunc['db_free_result']($request); |
| 1905 | 1948 | |
| 1906 | 1949 | return $ban_triggers; |
@@ -1956,8 +1999,9 @@ discard block |
||
| 1956 | 1999 | validateToken('admin-bl'); |
| 1957 | 2000 | |
| 1958 | 2001 | // 'Delete all entries' button was pressed. |
| 1959 | - if (!empty($_POST['removeAll'])) |
|
| 1960 | - removeBanLogs(); |
|
| 2002 | + if (!empty($_POST['removeAll'])) { |
|
| 2003 | + removeBanLogs(); |
|
| 2004 | + } |
|
| 1961 | 2005 | // 'Delete selection' button was pressed. |
| 1962 | 2006 | else |
| 1963 | 2007 | { |
@@ -2166,12 +2210,15 @@ discard block |
||
| 2166 | 2210 | $low = inet_dtop($low); |
| 2167 | 2211 | $high = inet_dtop($high); |
| 2168 | 2212 | |
| 2169 | - if ($low == '255.255.255.255') return 'unknown'; |
|
| 2170 | - if ($low == $high) |
|
| 2171 | - return $low; |
|
| 2172 | - else |
|
| 2173 | - return $low . '-'.$high; |
|
| 2174 | -} |
|
| 2213 | + if ($low == '255.255.255.255') { |
|
| 2214 | + return 'unknown'; |
|
| 2215 | + } |
|
| 2216 | + if ($low == $high) { |
|
| 2217 | + return $low; |
|
| 2218 | + } else { |
|
| 2219 | + return $low . '-'.$high; |
|
| 2220 | + } |
|
| 2221 | + } |
|
| 2175 | 2222 | |
| 2176 | 2223 | /** |
| 2177 | 2224 | * Checks whether a given IP range already exists in the trigger list. |
@@ -2247,15 +2294,17 @@ discard block |
||
| 2247 | 2294 | $memberEmailWild = array(); |
| 2248 | 2295 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2249 | 2296 | { |
| 2250 | - if ($row['id_member']) |
|
| 2251 | - $memberIDs[$row['id_member']] = $row['id_member']; |
|
| 2297 | + if ($row['id_member']) { |
|
| 2298 | + $memberIDs[$row['id_member']] = $row['id_member']; |
|
| 2299 | + } |
|
| 2252 | 2300 | if ($row['email_address']) |
| 2253 | 2301 | { |
| 2254 | 2302 | // Does it have a wildcard - if so we can't do a IN on it. |
| 2255 | - if (strpos($row['email_address'], '%') !== false) |
|
| 2256 | - $memberEmailWild[$row['email_address']] = $row['email_address']; |
|
| 2257 | - else |
|
| 2258 | - $memberEmails[$row['email_address']] = $row['email_address']; |
|
| 2303 | + if (strpos($row['email_address'], '%') !== false) { |
|
| 2304 | + $memberEmailWild[$row['email_address']] = $row['email_address']; |
|
| 2305 | + } else { |
|
| 2306 | + $memberEmails[$row['email_address']] = $row['email_address']; |
|
| 2307 | + } |
|
| 2259 | 2308 | } |
| 2260 | 2309 | } |
| 2261 | 2310 | $smcFunc['db_free_result']($request); |
@@ -2306,14 +2355,15 @@ discard block |
||
| 2306 | 2355 | } |
| 2307 | 2356 | |
| 2308 | 2357 | // We welcome our new members in the realm of the banned. |
| 2309 | - if (!empty($newMembers)) |
|
| 2310 | - $smcFunc['db_query']('', ' |
|
| 2358 | + if (!empty($newMembers)) { |
|
| 2359 | + $smcFunc['db_query']('', ' |
|
| 2311 | 2360 | DELETE FROM {db_prefix}log_online |
| 2312 | 2361 | WHERE id_member IN ({array_int:new_banned_members})', |
| 2313 | 2362 | array( |
| 2314 | 2363 | 'new_banned_members' => $newMembers, |
| 2315 | 2364 | ) |
| 2316 | 2365 | ); |
| 2366 | + } |
|
| 2317 | 2367 | |
| 2318 | 2368 | // Find members that are wrongfully marked as banned. |
| 2319 | 2369 | $request = $smcFunc['db_query']('', ' |
@@ -2340,9 +2390,10 @@ discard block |
||
| 2340 | 2390 | } |
| 2341 | 2391 | $smcFunc['db_free_result']($request); |
| 2342 | 2392 | |
| 2343 | - if (!empty($updates)) |
|
| 2344 | - foreach ($updates as $newStatus => $members) |
|
| 2393 | + if (!empty($updates)) { |
|
| 2394 | + foreach ($updates as $newStatus => $members) |
|
| 2345 | 2395 | updateMemberData($members, array('is_activated' => $newStatus)); |
| 2396 | + } |
|
| 2346 | 2397 | |
| 2347 | 2398 | // Update the latest member and our total members as banning may change them. |
| 2348 | 2399 | updateStats('member'); |
@@ -1452,7 +1452,7 @@ |
||
| 1452 | 1452 | * |
| 1453 | 1453 | * @param int $id_subscribe The subscription ID |
| 1454 | 1454 | * @param int $id_member The ID of the member |
| 1455 | - * @param int|string $renewal 0 if we're forcing start/end time, otherwise a string indicating how long to renew the subscription for ('D', 'W', 'M' or 'Y') |
|
| 1455 | + * @param integer $renewal 0 if we're forcing start/end time, otherwise a string indicating how long to renew the subscription for ('D', 'W', 'M' or 'Y') |
|
| 1456 | 1456 | * @param int $forceStartTime If set, forces the subscription to start at the specified time |
| 1457 | 1457 | * @param int $forceEndTime If set, forces the subscription to end at the specified time |
| 1458 | 1458 | */ |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | 'items_per_page' => $modSettings['defaultMaxListItems'], |
| 263 | 263 | 'base_href' => $scripturl . '?action=admin;area=paidsubscribe;sa=view', |
| 264 | 264 | 'get_items' => array( |
| 265 | - 'function' => function ($start, $items_per_page) use ($context) |
|
| 265 | + 'function' => function($start, $items_per_page) use ($context) |
|
| 266 | 266 | { |
| 267 | 267 | $subscriptions = array(); |
| 268 | 268 | $counter = 0; |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | }, |
| 282 | 282 | ), |
| 283 | 283 | 'get_count' => array( |
| 284 | - 'function' => function () use ($context) |
|
| 284 | + 'function' => function() use ($context) |
|
| 285 | 285 | { |
| 286 | 286 | return count($context['subscriptions']); |
| 287 | 287 | }, |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | 'style' => 'width: 35%;', |
| 295 | 295 | ), |
| 296 | 296 | 'data' => array( |
| 297 | - 'function' => function ($rowData) use ($scripturl) |
|
| 297 | + 'function' => function($rowData) use ($scripturl) |
|
| 298 | 298 | { |
| 299 | 299 | return sprintf('<a href="%1$s?action=admin;area=paidsubscribe;sa=viewsub;sid=%2$s">%3$s</a>', $scripturl, $rowData['id'], $rowData['name']); |
| 300 | 300 | }, |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | 'value' => $txt['paid_cost'], |
| 306 | 306 | ), |
| 307 | 307 | 'data' => array( |
| 308 | - 'function' => function ($rowData) use ($txt) |
|
| 308 | + 'function' => function($rowData) use ($txt) |
|
| 309 | 309 | { |
| 310 | 310 | return $rowData['flexible'] ? '<em>' . $txt['flexible'] . '</em>' : $rowData['cost'] . ' / ' . $rowData['length']; |
| 311 | 311 | }, |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | 'class' => 'centercol', |
| 349 | 349 | ), |
| 350 | 350 | 'data' => array( |
| 351 | - 'function' => function ($rowData) use ($txt) |
|
| 351 | + 'function' => function($rowData) use ($txt) |
|
| 352 | 352 | { |
| 353 | 353 | return '<span style="color: ' . ($rowData['active'] ? 'green' : 'red') . '">' . ($rowData['active'] ? $txt['yes'] : $txt['no']) . '</span>'; |
| 354 | 354 | }, |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | ), |
| 358 | 358 | 'modify' => array( |
| 359 | 359 | 'data' => array( |
| 360 | - 'function' => function ($rowData) use ($txt, $scripturl) |
|
| 360 | + 'function' => function($rowData) use ($txt, $scripturl) |
|
| 361 | 361 | { |
| 362 | 362 | return '<a href="' . $scripturl . '?action=admin;area=paidsubscribe;sa=modify;sid=' . $rowData['id'] . '">' . $txt['modify'] . '</a>'; |
| 363 | 363 | }, |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | ), |
| 367 | 367 | 'delete' => array( |
| 368 | 368 | 'data' => array( |
| 369 | - 'function' => function ($rowData) use ($scripturl, $txt) |
|
| 369 | + 'function' => function($rowData) use ($scripturl, $txt) |
|
| 370 | 370 | { |
| 371 | 371 | return '<a href="' . $scripturl . '?action=admin;area=paidsubscribe;sa=modify;delete;sid=' . $rowData['id'] . '">' . $txt['delete'] . '</a>'; |
| 372 | 372 | }, |
@@ -823,7 +823,7 @@ discard block |
||
| 823 | 823 | 'style' => 'width: 20%;', |
| 824 | 824 | ), |
| 825 | 825 | 'data' => array( |
| 826 | - 'function' => function ($rowData) use ($scripturl, $txt) |
|
| 826 | + 'function' => function($rowData) use ($scripturl, $txt) |
|
| 827 | 827 | { |
| 828 | 828 | return $rowData['id_member'] == 0 ? $txt['guest'] : '<a href="' . $scripturl . '?action=profile;u=' . $rowData['id_member'] . '">' . $rowData['name'] . '</a>'; |
| 829 | 829 | }, |
@@ -893,7 +893,7 @@ discard block |
||
| 893 | 893 | 'class' => 'centercol', |
| 894 | 894 | ), |
| 895 | 895 | 'data' => array( |
| 896 | - 'function' => function ($rowData) use ($scripturl, $txt) |
|
| 896 | + 'function' => function($rowData) use ($scripturl, $txt) |
|
| 897 | 897 | { |
| 898 | 898 | return '<a href="' . $scripturl . '?action=admin;area=paidsubscribe;sa=modifyuser;lid=' . $rowData['id'] . '">' . $txt['modify'] . '</a>'; |
| 899 | 899 | }, |
@@ -906,7 +906,7 @@ discard block |
||
| 906 | 906 | 'class' => 'centercol', |
| 907 | 907 | ), |
| 908 | 908 | 'data' => array( |
| 909 | - 'function' => function ($rowData) |
|
| 909 | + 'function' => function($rowData) |
|
| 910 | 910 | { |
| 911 | 911 | return '<input type="checkbox" name="delsub[' . $rowData['id'] . ']" class="input_check">'; |
| 912 | 912 | }, |
@@ -1950,7 +1950,7 @@ discard block |
||
| 1950 | 1950 | { |
| 1951 | 1951 | while (($file = readdir($dh)) !== false) |
| 1952 | 1952 | { |
| 1953 | - if (is_file($sourcedir .'/'. $file) && preg_match('~^Subscriptions-([A-Za-z\d]+)\.php$~', $file, $matches)) |
|
| 1953 | + if (is_file($sourcedir . '/' . $file) && preg_match('~^Subscriptions-([A-Za-z\d]+)\.php$~', $file, $matches)) |
|
| 1954 | 1954 | { |
| 1955 | 1955 | // Check this is definitely a valid gateway! |
| 1956 | 1956 | $fp = fopen($sourcedir . '/' . $file, 'rb'); |
@@ -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 | /** |
| 21 | 22 | * The main entrance point for the 'Paid Subscription' screen, calling |
@@ -32,18 +33,19 @@ discard block |
||
| 32 | 33 | loadLanguage('ManagePaid'); |
| 33 | 34 | loadTemplate('ManagePaid'); |
| 34 | 35 | |
| 35 | - if (!empty($modSettings['paid_enabled'])) |
|
| 36 | - $subActions = array( |
|
| 36 | + if (!empty($modSettings['paid_enabled'])) { |
|
| 37 | + $subActions = array( |
|
| 37 | 38 | 'modify' => array('ModifySubscription', 'admin_forum'), |
| 38 | 39 | 'modifyuser' => array('ModifyUserSubscription', 'admin_forum'), |
| 39 | 40 | 'settings' => array('ModifySubscriptionSettings', 'admin_forum'), |
| 40 | 41 | 'view' => array('ViewSubscriptions', 'admin_forum'), |
| 41 | 42 | 'viewsub' => array('ViewSubscribedUsers', 'admin_forum'), |
| 42 | 43 | ); |
| 43 | - else |
|
| 44 | - $subActions = array( |
|
| 44 | + } else { |
|
| 45 | + $subActions = array( |
|
| 45 | 46 | 'settings' => array('ModifySubscriptionSettings', 'admin_forum'), |
| 46 | 47 | ); |
| 48 | + } |
|
| 47 | 49 | |
| 48 | 50 | // Default the sub-action to 'view subscriptions', but only if they have already set things up.. |
| 49 | 51 | $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (!empty($modSettings['paid_currency_symbol']) && !empty($modSettings['paid_enabled']) ? 'view' : 'settings'); |
@@ -59,8 +61,8 @@ discard block |
||
| 59 | 61 | 'help' => '', |
| 60 | 62 | 'description' => $txt['paid_subscriptions_desc'], |
| 61 | 63 | ); |
| 62 | - if (!empty($modSettings['paid_enabled'])) |
|
| 63 | - $context[$context['admin_menu_name']]['tab_data']['tabs'] = array( |
|
| 64 | + if (!empty($modSettings['paid_enabled'])) { |
|
| 65 | + $context[$context['admin_menu_name']]['tab_data']['tabs'] = array( |
|
| 64 | 66 | 'view' => array( |
| 65 | 67 | 'description' => $txt['paid_subs_view_desc'], |
| 66 | 68 | ), |
@@ -68,6 +70,7 @@ discard block |
||
| 68 | 70 | 'description' => $txt['paid_subs_settings_desc'], |
| 69 | 71 | ), |
| 70 | 72 | ); |
| 73 | + } |
|
| 71 | 74 | |
| 72 | 75 | call_integration_hook('integrate_manage_subscriptions', array(&$subActions)); |
| 73 | 76 | |
@@ -92,8 +95,9 @@ discard block |
||
| 92 | 95 | { |
| 93 | 96 | // If the currency is set to something different then we need to set it to other for this to work and set it back shortly. |
| 94 | 97 | $modSettings['paid_currency'] = !empty($modSettings['paid_currency_code']) ? $modSettings['paid_currency_code'] : ''; |
| 95 | - if (!empty($modSettings['paid_currency_code']) && !in_array($modSettings['paid_currency_code'], array('usd', 'eur', 'gbp', 'cad', 'aud'))) |
|
| 96 | - $modSettings['paid_currency'] = 'other'; |
|
| 98 | + if (!empty($modSettings['paid_currency_code']) && !in_array($modSettings['paid_currency_code'], array('usd', 'eur', 'gbp', 'cad', 'aud'))) { |
|
| 99 | + $modSettings['paid_currency'] = 'other'; |
|
| 100 | + } |
|
| 97 | 101 | |
| 98 | 102 | // These are all the default settings. |
| 99 | 103 | $config_vars = array( |
@@ -156,8 +160,7 @@ discard block |
||
| 156 | 160 | } |
| 157 | 161 | } |
| 158 | 162 | toggleOther();', true); |
| 159 | - } |
|
| 160 | - else |
|
| 163 | + } else |
|
| 161 | 164 | { |
| 162 | 165 | $config_vars = array( |
| 163 | 166 | array('check', 'paid_enabled'), |
@@ -166,8 +169,9 @@ discard block |
||
| 166 | 169 | } |
| 167 | 170 | |
| 168 | 171 | // Just searching? |
| 169 | - if ($return_config) |
|
| 170 | - return $config_vars; |
|
| 172 | + if ($return_config) { |
|
| 173 | + return $config_vars; |
|
| 174 | + } |
|
| 171 | 175 | |
| 172 | 176 | // Get the settings template fired up. |
| 173 | 177 | require_once($sourcedir . '/ManageServer.php'); |
@@ -211,8 +215,9 @@ discard block |
||
| 211 | 215 | foreach (explode(',', $_POST['paid_email_to']) as $email) |
| 212 | 216 | { |
| 213 | 217 | $email = trim($email); |
| 214 | - if (!empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL)) |
|
| 215 | - $email_addresses[] = $email; |
|
| 218 | + if (!empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL)) { |
|
| 219 | + $email_addresses[] = $email; |
|
| 220 | + } |
|
| 216 | 221 | $_POST['paid_email_to'] = implode(',', $email_addresses); |
| 217 | 222 | } |
| 218 | 223 | } |
@@ -249,8 +254,9 @@ discard block |
||
| 249 | 254 | global $context, $txt, $modSettings, $sourcedir, $scripturl; |
| 250 | 255 | |
| 251 | 256 | // Not made the settings yet? |
| 252 | - if (empty($modSettings['paid_currency_symbol'])) |
|
| 253 | - fatal_lang_error('paid_not_set_currency', false, $scripturl . '?action=admin;area=paidsubscribe;sa=settings'); |
|
| 257 | + if (empty($modSettings['paid_currency_symbol'])) { |
|
| 258 | + fatal_lang_error('paid_not_set_currency', false, $scripturl . '?action=admin;area=paidsubscribe;sa=settings'); |
|
| 259 | + } |
|
| 254 | 260 | |
| 255 | 261 | // Some basic stuff. |
| 256 | 262 | $context['page_title'] = $txt['paid_subs_view']; |
@@ -270,10 +276,11 @@ discard block |
||
| 270 | 276 | |
| 271 | 277 | foreach ($context['subscriptions'] as $data) |
| 272 | 278 | { |
| 273 | - if (++$counter < $start) |
|
| 274 | - continue; |
|
| 275 | - elseif ($counter == $start + $items_per_page) |
|
| 276 | - break; |
|
| 279 | + if (++$counter < $start) { |
|
| 280 | + continue; |
|
| 281 | + } elseif ($counter == $start + $items_per_page) { |
|
| 282 | + break; |
|
| 283 | + } |
|
| 277 | 284 | |
| 278 | 285 | $subscriptions[] = $data; |
| 279 | 286 | } |
@@ -450,8 +457,9 @@ discard block |
||
| 450 | 457 | ); |
| 451 | 458 | $id_group = 0; |
| 452 | 459 | $add_groups = ''; |
| 453 | - if ($smcFunc['db_num_rows']($request)) |
|
| 454 | - list ($id_group, $add_groups) = $smcFunc['db_fetch_row']($request); |
|
| 460 | + if ($smcFunc['db_num_rows']($request)) { |
|
| 461 | + list ($id_group, $add_groups) = $smcFunc['db_fetch_row']($request); |
|
| 462 | + } |
|
| 455 | 463 | $smcFunc['db_free_result']($request); |
| 456 | 464 | |
| 457 | 465 | $changes = array(); |
@@ -463,8 +471,9 @@ discard block |
||
| 463 | 471 | { |
| 464 | 472 | // If their current primary group isn't what they had before the subscription, and their current group was |
| 465 | 473 | // granted by the sub, remove it. |
| 466 | - if ($member_data['old_id_group'] != $member_data['id_group'] && $member_data['id_group'] == $id_group) |
|
| 467 | - $changes[$id_member]['id_group'] = $member_data['old_id_group']; |
|
| 474 | + if ($member_data['old_id_group'] != $member_data['id_group'] && $member_data['id_group'] == $id_group) { |
|
| 475 | + $changes[$id_member]['id_group'] = $member_data['old_id_group']; |
|
| 476 | + } |
|
| 468 | 477 | } |
| 469 | 478 | } |
| 470 | 479 | |
@@ -477,15 +486,17 @@ discard block |
||
| 477 | 486 | // First let's get their groups sorted. |
| 478 | 487 | $current_groups = explode(',', $member_data['additional_groups']); |
| 479 | 488 | $new_groups = implode(',', array_diff($current_groups, $add_groups)); |
| 480 | - if ($new_groups != $member_data['additional_groups']) |
|
| 481 | - $changes[$id_member]['additional_groups'] = $new_groups; |
|
| 489 | + if ($new_groups != $member_data['additional_groups']) { |
|
| 490 | + $changes[$id_member]['additional_groups'] = $new_groups; |
|
| 491 | + } |
|
| 482 | 492 | } |
| 483 | 493 | } |
| 484 | 494 | |
| 485 | 495 | // We're going through changes... |
| 486 | - if (!empty($changes)) |
|
| 487 | - foreach ($changes as $id_member => $new_values) |
|
| 496 | + if (!empty($changes)) { |
|
| 497 | + foreach ($changes as $id_member => $new_values) |
|
| 488 | 498 | updateMemberData($id_member, $new_values); |
| 499 | + } |
|
| 489 | 500 | } |
| 490 | 501 | |
| 491 | 502 | // Delete the subscription |
@@ -533,11 +544,13 @@ discard block |
||
| 533 | 544 | 'M' => 24, |
| 534 | 545 | 'Y' => 5, |
| 535 | 546 | ); |
| 536 | - if (empty($_POST['span_unit']) || empty($limits[$_POST['span_unit']]) || empty($_POST['span_value']) || $_POST['span_value'] < 1) |
|
| 537 | - fatal_lang_error('paid_invalid_duration', false); |
|
| 547 | + if (empty($_POST['span_unit']) || empty($limits[$_POST['span_unit']]) || empty($_POST['span_value']) || $_POST['span_value'] < 1) { |
|
| 548 | + fatal_lang_error('paid_invalid_duration', false); |
|
| 549 | + } |
|
| 538 | 550 | |
| 539 | - if ($_POST['span_value'] > $limits[$_POST['span_unit']]) |
|
| 540 | - fatal_lang_error('paid_invalid_duration_' . $_POST['span_unit'], false); |
|
| 551 | + if ($_POST['span_value'] > $limits[$_POST['span_unit']]) { |
|
| 552 | + fatal_lang_error('paid_invalid_duration_' . $_POST['span_unit'], false); |
|
| 553 | + } |
|
| 541 | 554 | |
| 542 | 555 | // Clean the span. |
| 543 | 556 | $span = $_POST['span_value'] . $_POST['span_unit']; |
@@ -546,8 +559,9 @@ discard block |
||
| 546 | 559 | $cost = array('fixed' => sprintf('%01.2f', strtr($_POST['cost'], ',', '.'))); |
| 547 | 560 | |
| 548 | 561 | // There needs to be something. |
| 549 | - if (empty($_POST['span_value']) || empty($_POST['cost'])) |
|
| 550 | - fatal_lang_error('paid_no_cost_value'); |
|
| 562 | + if (empty($_POST['span_value']) || empty($_POST['cost'])) { |
|
| 563 | + fatal_lang_error('paid_no_cost_value'); |
|
| 564 | + } |
|
| 551 | 565 | } |
| 552 | 566 | // Flexible is harder but more fun ;) |
| 553 | 567 | else |
@@ -561,8 +575,9 @@ discard block |
||
| 561 | 575 | 'year' => sprintf('%01.2f', strtr($_POST['cost_year'], ',', '.')), |
| 562 | 576 | ); |
| 563 | 577 | |
| 564 | - if (empty($_POST['cost_day']) && empty($_POST['cost_week']) && empty($_POST['cost_month']) && empty($_POST['cost_year'])) |
|
| 565 | - fatal_lang_error('paid_all_freq_blank'); |
|
| 578 | + if (empty($_POST['cost_day']) && empty($_POST['cost_week']) && empty($_POST['cost_month']) && empty($_POST['cost_year'])) { |
|
| 579 | + fatal_lang_error('paid_all_freq_blank'); |
|
| 580 | + } |
|
| 566 | 581 | } |
| 567 | 582 | $cost = json_encode($cost); |
| 568 | 583 | |
@@ -571,9 +586,10 @@ discard block |
||
| 571 | 586 | |
| 572 | 587 | // Yep, time to do additional groups. |
| 573 | 588 | $addgroups = array(); |
| 574 | - if (!empty($_POST['addgroup'])) |
|
| 575 | - foreach ($_POST['addgroup'] as $id => $dummy) |
|
| 589 | + if (!empty($_POST['addgroup'])) { |
|
| 590 | + foreach ($_POST['addgroup'] as $id => $dummy) |
|
| 576 | 591 | $addgroups[] = (int) $id; |
| 592 | + } |
|
| 577 | 593 | $addgroups = implode(',', $addgroups); |
| 578 | 594 | |
| 579 | 595 | // Is it new?! |
@@ -682,18 +698,18 @@ discard block |
||
| 682 | 698 | { |
| 683 | 699 | $span_value = $match[1]; |
| 684 | 700 | $span_unit = $match[2]; |
| 685 | - } |
|
| 686 | - else |
|
| 701 | + } else |
|
| 687 | 702 | { |
| 688 | 703 | $span_value = 0; |
| 689 | 704 | $span_unit = 'D'; |
| 690 | 705 | } |
| 691 | 706 | |
| 692 | 707 | // Is this a flexible one? |
| 693 | - if ($row['length'] == 'F') |
|
| 694 | - $isFlexible = true; |
|
| 695 | - else |
|
| 696 | - $isFlexible = false; |
|
| 708 | + if ($row['length'] == 'F') { |
|
| 709 | + $isFlexible = true; |
|
| 710 | + } else { |
|
| 711 | + $isFlexible = false; |
|
| 712 | + } |
|
| 697 | 713 | |
| 698 | 714 | $context['sub'] = array( |
| 699 | 715 | 'name' => $row['name'], |
@@ -742,8 +758,9 @@ discard block |
||
| 742 | 758 | ) |
| 743 | 759 | ); |
| 744 | 760 | $context['groups'] = array(); |
| 745 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 746 | - $context['groups'][$row['id_group']] = $row['group_name']; |
|
| 761 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 762 | + $context['groups'][$row['id_group']] = $row['group_name']; |
|
| 763 | + } |
|
| 747 | 764 | $smcFunc['db_free_result']($request); |
| 748 | 765 | |
| 749 | 766 | // This always happens. |
@@ -777,8 +794,9 @@ discard block |
||
| 777 | 794 | ) |
| 778 | 795 | ); |
| 779 | 796 | // Something wrong? |
| 780 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 781 | - fatal_lang_error('no_access', false); |
|
| 797 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 798 | + fatal_lang_error('no_access', false); |
|
| 799 | + } |
|
| 782 | 800 | // Do the subscription context. |
| 783 | 801 | $row = $smcFunc['db_fetch_assoc']($request); |
| 784 | 802 | $context['subscription'] = array( |
@@ -1013,8 +1031,8 @@ discard block |
||
| 1013 | 1031 | )) |
| 1014 | 1032 | ); |
| 1015 | 1033 | $subscribers = array(); |
| 1016 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1017 | - $subscribers[] = array( |
|
| 1034 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1035 | + $subscribers[] = array( |
|
| 1018 | 1036 | 'id' => $row['id_sublog'], |
| 1019 | 1037 | 'id_member' => $row['id_member'], |
| 1020 | 1038 | 'name' => $row['name'], |
@@ -1024,6 +1042,7 @@ discard block |
||
| 1024 | 1042 | 'status' => $row['status'], |
| 1025 | 1043 | 'status_text' => $row['status'] == 0 ? ($row['payments_pending'] == 0 ? $txt['paid_finished'] : $txt['paid_pending']) : $txt['paid_active'], |
| 1026 | 1044 | ); |
| 1045 | + } |
|
| 1027 | 1046 | $smcFunc['db_free_result']($request); |
| 1028 | 1047 | |
| 1029 | 1048 | return $subscribers; |
@@ -1058,14 +1077,16 @@ discard block |
||
| 1058 | 1077 | 'current_log_item' => $context['log_id'], |
| 1059 | 1078 | ) |
| 1060 | 1079 | ); |
| 1061 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1062 | - fatal_lang_error('no_access', false); |
|
| 1080 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1081 | + fatal_lang_error('no_access', false); |
|
| 1082 | + } |
|
| 1063 | 1083 | list ($context['sub_id']) = $smcFunc['db_fetch_row']($request); |
| 1064 | 1084 | $smcFunc['db_free_result']($request); |
| 1065 | 1085 | } |
| 1066 | 1086 | |
| 1067 | - if (!isset($context['subscriptions'][$context['sub_id']])) |
|
| 1068 | - fatal_lang_error('no_access', false); |
|
| 1087 | + if (!isset($context['subscriptions'][$context['sub_id']])) { |
|
| 1088 | + fatal_lang_error('no_access', false); |
|
| 1089 | + } |
|
| 1069 | 1090 | $context['current_subscription'] = $context['subscriptions'][$context['sub_id']]; |
| 1070 | 1091 | |
| 1071 | 1092 | // Searching? |
@@ -1098,8 +1119,9 @@ discard block |
||
| 1098 | 1119 | 'name' => $_POST['name'], |
| 1099 | 1120 | ) |
| 1100 | 1121 | ); |
| 1101 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1102 | - fatal_lang_error('error_member_not_found'); |
|
| 1122 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1123 | + fatal_lang_error('error_member_not_found'); |
|
| 1124 | + } |
|
| 1103 | 1125 | |
| 1104 | 1126 | list ($id_member, $id_group) = $smcFunc['db_fetch_row']($request); |
| 1105 | 1127 | $smcFunc['db_free_result']($request); |
@@ -1115,14 +1137,15 @@ discard block |
||
| 1115 | 1137 | 'current_member' => $id_member, |
| 1116 | 1138 | ) |
| 1117 | 1139 | ); |
| 1118 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 1119 | - fatal_lang_error('member_already_subscribed'); |
|
| 1140 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 1141 | + fatal_lang_error('member_already_subscribed'); |
|
| 1142 | + } |
|
| 1120 | 1143 | $smcFunc['db_free_result']($request); |
| 1121 | 1144 | |
| 1122 | 1145 | // Actually put the subscription in place. |
| 1123 | - if ($status == 1) |
|
| 1124 | - addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime); |
|
| 1125 | - else |
|
| 1146 | + if ($status == 1) { |
|
| 1147 | + addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime); |
|
| 1148 | + } else |
|
| 1126 | 1149 | { |
| 1127 | 1150 | $smcFunc['db_insert']('', |
| 1128 | 1151 | '{db_prefix}log_subscribed', |
@@ -1149,20 +1172,20 @@ discard block |
||
| 1149 | 1172 | 'current_log_item' => $context['log_id'], |
| 1150 | 1173 | ) |
| 1151 | 1174 | ); |
| 1152 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1153 | - fatal_lang_error('no_access', false); |
|
| 1175 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1176 | + fatal_lang_error('no_access', false); |
|
| 1177 | + } |
|
| 1154 | 1178 | |
| 1155 | 1179 | list ($id_member, $old_status) = $smcFunc['db_fetch_row']($request); |
| 1156 | 1180 | $smcFunc['db_free_result']($request); |
| 1157 | 1181 | |
| 1158 | 1182 | // Pick the right permission stuff depending on what the status is changing from/to. |
| 1159 | - if ($old_status == 1 && $status != 1) |
|
| 1160 | - removeSubscription($context['sub_id'], $id_member); |
|
| 1161 | - elseif ($status == 1 && $old_status != 1) |
|
| 1183 | + if ($old_status == 1 && $status != 1) { |
|
| 1184 | + removeSubscription($context['sub_id'], $id_member); |
|
| 1185 | + } elseif ($status == 1 && $old_status != 1) |
|
| 1162 | 1186 | { |
| 1163 | 1187 | addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime); |
| 1164 | - } |
|
| 1165 | - else |
|
| 1188 | + } else |
|
| 1166 | 1189 | { |
| 1167 | 1190 | $smcFunc['db_query']('', ' |
| 1168 | 1191 | UPDATE {db_prefix}log_subscribed |
@@ -1190,8 +1213,9 @@ discard block |
||
| 1190 | 1213 | if (!empty($_REQUEST['delsub'])) |
| 1191 | 1214 | { |
| 1192 | 1215 | $toDelete = array(); |
| 1193 | - foreach ($_REQUEST['delsub'] as $id => $dummy) |
|
| 1194 | - $toDelete[] = (int) $id; |
|
| 1216 | + foreach ($_REQUEST['delsub'] as $id => $dummy) { |
|
| 1217 | + $toDelete[] = (int) $id; |
|
| 1218 | + } |
|
| 1195 | 1219 | |
| 1196 | 1220 | $request = $smcFunc['db_query']('', ' |
| 1197 | 1221 | SELECT id_subscribe, id_member |
@@ -1201,8 +1225,9 @@ discard block |
||
| 1201 | 1225 | 'subscription_list' => $toDelete, |
| 1202 | 1226 | ) |
| 1203 | 1227 | ); |
| 1204 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1205 | - removeSubscription($row['id_subscribe'], $row['id_member'], isset($_REQUEST['delete'])); |
|
| 1228 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1229 | + removeSubscription($row['id_subscribe'], $row['id_member'], isset($_REQUEST['delete'])); |
|
| 1230 | + } |
|
| 1206 | 1231 | $smcFunc['db_free_result']($request); |
| 1207 | 1232 | } |
| 1208 | 1233 | redirectexit('action=admin;area=paidsubscribe;sa=viewsub;sid=' . $context['sub_id']); |
@@ -1246,9 +1271,9 @@ discard block |
||
| 1246 | 1271 | ); |
| 1247 | 1272 | list ($context['sub']['username']) = $smcFunc['db_fetch_row']($request); |
| 1248 | 1273 | $smcFunc['db_free_result']($request); |
| 1274 | + } else { |
|
| 1275 | + $context['sub']['username'] = ''; |
|
| 1249 | 1276 | } |
| 1250 | - else |
|
| 1251 | - $context['sub']['username'] = ''; |
|
| 1252 | 1277 | } |
| 1253 | 1278 | // Otherwise load the existing info. |
| 1254 | 1279 | else |
@@ -1265,8 +1290,9 @@ discard block |
||
| 1265 | 1290 | 'blank_string' => '', |
| 1266 | 1291 | ) |
| 1267 | 1292 | ); |
| 1268 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1269 | - fatal_lang_error('no_access', false); |
|
| 1293 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1294 | + fatal_lang_error('no_access', false); |
|
| 1295 | + } |
|
| 1270 | 1296 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1271 | 1297 | $smcFunc['db_free_result']($request); |
| 1272 | 1298 | |
@@ -1287,13 +1313,13 @@ discard block |
||
| 1287 | 1313 | { |
| 1288 | 1314 | foreach ($costs as $duration => $cost) |
| 1289 | 1315 | { |
| 1290 | - if ($cost != 0 && $cost == $pending[1] && $duration == $pending[2]) |
|
| 1291 | - $context['pending_payments'][$id] = array( |
|
| 1316 | + if ($cost != 0 && $cost == $pending[1] && $duration == $pending[2]) { |
|
| 1317 | + $context['pending_payments'][$id] = array( |
|
| 1292 | 1318 | 'desc' => sprintf($modSettings['paid_currency_symbol'], $cost . '/' . $txt[$duration]), |
| 1293 | 1319 | ); |
| 1320 | + } |
|
| 1294 | 1321 | } |
| 1295 | - } |
|
| 1296 | - elseif ($costs['fixed'] == $pending[1]) |
|
| 1322 | + } elseif ($costs['fixed'] == $pending[1]) |
|
| 1297 | 1323 | { |
| 1298 | 1324 | $context['pending_payments'][$id] = array( |
| 1299 | 1325 | 'desc' => sprintf($modSettings['paid_currency_symbol'], $costs['fixed']), |
@@ -1311,8 +1337,9 @@ discard block |
||
| 1311 | 1337 | if ($_GET['pending'] == $id && $pending[3] == 'payback' && isset($context['pending_payments'][$id])) |
| 1312 | 1338 | { |
| 1313 | 1339 | // Flexible? |
| 1314 | - if (isset($_GET['accept'])) |
|
| 1315 | - addSubscription($context['current_subscription']['id'], $row['id_member'], $context['current_subscription']['real_length'] == 'F' ? strtoupper(substr($pending[2], 0, 1)) : 0); |
|
| 1340 | + if (isset($_GET['accept'])) { |
|
| 1341 | + addSubscription($context['current_subscription']['id'], $row['id_member'], $context['current_subscription']['real_length'] == 'F' ? strtoupper(substr($pending[2], 0, 1)) : 0); |
|
| 1342 | + } |
|
| 1316 | 1343 | unset($pending_details[$id]); |
| 1317 | 1344 | |
| 1318 | 1345 | $new_details = json_encode($pending_details); |
@@ -1374,8 +1401,9 @@ discard block |
||
| 1374 | 1401 | global $smcFunc; |
| 1375 | 1402 | |
| 1376 | 1403 | // Make it an array. |
| 1377 | - if (!is_array($users)) |
|
| 1378 | - $users = array($users); |
|
| 1404 | + if (!is_array($users)) { |
|
| 1405 | + $users = array($users); |
|
| 1406 | + } |
|
| 1379 | 1407 | |
| 1380 | 1408 | // Get all the members current groups. |
| 1381 | 1409 | $groups = array(); |
@@ -1413,14 +1441,16 @@ discard block |
||
| 1413 | 1441 | if ($row['id_group'] != 0) |
| 1414 | 1442 | { |
| 1415 | 1443 | // If this is changing - add the old one to the additional groups so it's not lost. |
| 1416 | - if ($row['id_group'] != $groups[$row['id_member']]['primary']) |
|
| 1417 | - $groups[$row['id_member']]['additional'][] = $groups[$row['id_member']]['primary']; |
|
| 1444 | + if ($row['id_group'] != $groups[$row['id_member']]['primary']) { |
|
| 1445 | + $groups[$row['id_member']]['additional'][] = $groups[$row['id_member']]['primary']; |
|
| 1446 | + } |
|
| 1418 | 1447 | $groups[$row['id_member']]['primary'] = $row['id_group']; |
| 1419 | 1448 | } |
| 1420 | 1449 | |
| 1421 | 1450 | // Additional groups. |
| 1422 | - if (!empty($row['add_groups'])) |
|
| 1423 | - $groups[$row['id_member']]['additional'] = array_merge($groups[$row['id_member']]['additional'], explode(',', $row['add_groups'])); |
|
| 1451 | + if (!empty($row['add_groups'])) { |
|
| 1452 | + $groups[$row['id_member']]['additional'] = array_merge($groups[$row['id_member']]['additional'], explode(',', $row['add_groups'])); |
|
| 1453 | + } |
|
| 1424 | 1454 | } |
| 1425 | 1455 | $smcFunc['db_free_result']($request); |
| 1426 | 1456 | |
@@ -1428,9 +1458,10 @@ discard block |
||
| 1428 | 1458 | foreach ($groups as $id => $group) |
| 1429 | 1459 | { |
| 1430 | 1460 | $group['additional'] = array_unique($group['additional']); |
| 1431 | - foreach ($group['additional'] as $key => $value) |
|
| 1432 | - if (empty($value)) |
|
| 1461 | + foreach ($group['additional'] as $key => $value) { |
|
| 1462 | + if (empty($value)) |
|
| 1433 | 1463 | unset($group['additional'][$key]); |
| 1464 | + } |
|
| 1434 | 1465 | $addgroups = implode(',', $group['additional']); |
| 1435 | 1466 | |
| 1436 | 1467 | $smcFunc['db_query']('', ' |
@@ -1464,8 +1495,9 @@ discard block |
||
| 1464 | 1495 | loadSubscriptions(); |
| 1465 | 1496 | |
| 1466 | 1497 | // Exists, yes? |
| 1467 | - if (!isset($context['subscriptions'][$id_subscribe])) |
|
| 1468 | - return; |
|
| 1498 | + if (!isset($context['subscriptions'][$id_subscribe])) { |
|
| 1499 | + return; |
|
| 1500 | + } |
|
| 1469 | 1501 | |
| 1470 | 1502 | $curSub = $context['subscriptions'][$id_subscribe]; |
| 1471 | 1503 | |
@@ -1513,16 +1545,19 @@ discard block |
||
| 1513 | 1545 | list ($id_sublog, $endtime, $starttime) = $smcFunc['db_fetch_row']($request); |
| 1514 | 1546 | |
| 1515 | 1547 | // If this has already expired but is active, extension means the period from now. |
| 1516 | - if ($endtime < time()) |
|
| 1517 | - $endtime = time(); |
|
| 1518 | - if ($starttime == 0) |
|
| 1519 | - $starttime = time(); |
|
| 1548 | + if ($endtime < time()) { |
|
| 1549 | + $endtime = time(); |
|
| 1550 | + } |
|
| 1551 | + if ($starttime == 0) { |
|
| 1552 | + $starttime = time(); |
|
| 1553 | + } |
|
| 1520 | 1554 | |
| 1521 | 1555 | // Work out the new expiry date. |
| 1522 | 1556 | $endtime += $duration; |
| 1523 | 1557 | |
| 1524 | - if ($forceEndTime != 0) |
|
| 1525 | - $endtime = $forceEndTime; |
|
| 1558 | + if ($forceEndTime != 0) { |
|
| 1559 | + $endtime = $forceEndTime; |
|
| 1560 | + } |
|
| 1526 | 1561 | |
| 1527 | 1562 | // As everything else should be good, just update! |
| 1528 | 1563 | $smcFunc['db_query']('', ' |
@@ -1552,8 +1587,9 @@ discard block |
||
| 1552 | 1587 | ); |
| 1553 | 1588 | |
| 1554 | 1589 | // Just in case the member doesn't exist. |
| 1555 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1556 | - return; |
|
| 1590 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1591 | + return; |
|
| 1592 | + } |
|
| 1557 | 1593 | |
| 1558 | 1594 | list ($old_id_group, $additional_groups) = $smcFunc['db_fetch_row']($request); |
| 1559 | 1595 | $smcFunc['db_free_result']($request); |
@@ -1570,16 +1606,18 @@ discard block |
||
| 1570 | 1606 | $id_group = $curSub['prim_group']; |
| 1571 | 1607 | |
| 1572 | 1608 | // Ensure their old privileges are maintained. |
| 1573 | - if ($old_id_group != 0) |
|
| 1574 | - $newAddGroups[] = $old_id_group; |
|
| 1609 | + if ($old_id_group != 0) { |
|
| 1610 | + $newAddGroups[] = $old_id_group; |
|
| 1611 | + } |
|
| 1612 | + } else { |
|
| 1613 | + $id_group = $old_id_group; |
|
| 1575 | 1614 | } |
| 1576 | - else |
|
| 1577 | - $id_group = $old_id_group; |
|
| 1578 | 1615 | |
| 1579 | 1616 | // Yep, make sure it's unique, and no empties. |
| 1580 | - foreach ($newAddGroups as $k => $v) |
|
| 1581 | - if (empty($v)) |
|
| 1617 | + foreach ($newAddGroups as $k => $v) { |
|
| 1618 | + if (empty($v)) |
|
| 1582 | 1619 | unset($newAddGroups[$k]); |
| 1620 | + } |
|
| 1583 | 1621 | $newAddGroups = array_unique($newAddGroups); |
| 1584 | 1622 | $newAddGroups = implode(',', $newAddGroups); |
| 1585 | 1623 | |
@@ -1615,16 +1653,19 @@ discard block |
||
| 1615 | 1653 | list ($id_sublog, $endtime, $starttime) = $smcFunc['db_fetch_row']($request); |
| 1616 | 1654 | |
| 1617 | 1655 | // If this has already expired but is active, extension means the period from now. |
| 1618 | - if ($endtime < time()) |
|
| 1619 | - $endtime = time(); |
|
| 1620 | - if ($starttime == 0) |
|
| 1621 | - $starttime = time(); |
|
| 1656 | + if ($endtime < time()) { |
|
| 1657 | + $endtime = time(); |
|
| 1658 | + } |
|
| 1659 | + if ($starttime == 0) { |
|
| 1660 | + $starttime = time(); |
|
| 1661 | + } |
|
| 1622 | 1662 | |
| 1623 | 1663 | // Work out the new expiry date. |
| 1624 | 1664 | $endtime += $duration; |
| 1625 | 1665 | |
| 1626 | - if ($forceEndTime != 0) |
|
| 1627 | - $endtime = $forceEndTime; |
|
| 1666 | + if ($forceEndTime != 0) { |
|
| 1667 | + $endtime = $forceEndTime; |
|
| 1668 | + } |
|
| 1628 | 1669 | |
| 1629 | 1670 | // As everything else should be good, just update! |
| 1630 | 1671 | $smcFunc['db_query']('', ' |
@@ -1647,13 +1688,15 @@ discard block |
||
| 1647 | 1688 | |
| 1648 | 1689 | // Otherwise a very simple insert. |
| 1649 | 1690 | $endtime = time() + $duration; |
| 1650 | - if ($forceEndTime != 0) |
|
| 1651 | - $endtime = $forceEndTime; |
|
| 1691 | + if ($forceEndTime != 0) { |
|
| 1692 | + $endtime = $forceEndTime; |
|
| 1693 | + } |
|
| 1652 | 1694 | |
| 1653 | - if ($forceStartTime == 0) |
|
| 1654 | - $starttime = time(); |
|
| 1655 | - else |
|
| 1656 | - $starttime = $forceStartTime; |
|
| 1695 | + if ($forceStartTime == 0) { |
|
| 1696 | + $starttime = time(); |
|
| 1697 | + } else { |
|
| 1698 | + $starttime = $forceStartTime; |
|
| 1699 | + } |
|
| 1657 | 1700 | |
| 1658 | 1701 | $smcFunc['db_insert']('', |
| 1659 | 1702 | '{db_prefix}log_subscribed', |
@@ -1726,15 +1769,17 @@ discard block |
||
| 1726 | 1769 | $new_id_group = -1; |
| 1727 | 1770 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1728 | 1771 | { |
| 1729 | - if (!isset($context['subscriptions'][$row['id_subscribe']])) |
|
| 1730 | - continue; |
|
| 1772 | + if (!isset($context['subscriptions'][$row['id_subscribe']])) { |
|
| 1773 | + continue; |
|
| 1774 | + } |
|
| 1731 | 1775 | |
| 1732 | 1776 | // The one we're removing? |
| 1733 | 1777 | if ($row['id_subscribe'] == $id_subscribe) |
| 1734 | 1778 | { |
| 1735 | 1779 | $removals = explode(',', $context['subscriptions'][$row['id_subscribe']]['add_groups']); |
| 1736 | - if ($context['subscriptions'][$row['id_subscribe']]['prim_group'] != 0) |
|
| 1737 | - $removals[] = $context['subscriptions'][$row['id_subscribe']]['prim_group']; |
|
| 1780 | + if ($context['subscriptions'][$row['id_subscribe']]['prim_group'] != 0) { |
|
| 1781 | + $removals[] = $context['subscriptions'][$row['id_subscribe']]['prim_group']; |
|
| 1782 | + } |
|
| 1738 | 1783 | $old_id_group = $row['old_id_group']; |
| 1739 | 1784 | } |
| 1740 | 1785 | // Otherwise things we allow. |
@@ -1752,30 +1797,33 @@ discard block |
||
| 1752 | 1797 | |
| 1753 | 1798 | // Now, for everything we are removing check they definitely are not allowed it. |
| 1754 | 1799 | $existingGroups = explode(',', $additional_groups); |
| 1755 | - foreach ($existingGroups as $key => $group) |
|
| 1756 | - if (empty($group) || (in_array($group, $removals) && !in_array($group, $allowed))) |
|
| 1800 | + foreach ($existingGroups as $key => $group) { |
|
| 1801 | + if (empty($group) || (in_array($group, $removals) && !in_array($group, $allowed))) |
|
| 1757 | 1802 | unset($existingGroups[$key]); |
| 1803 | + } |
|
| 1758 | 1804 | |
| 1759 | 1805 | // Finally, do something with the current primary group. |
| 1760 | 1806 | if (in_array($id_group, $removals)) |
| 1761 | 1807 | { |
| 1762 | 1808 | // If this primary group is actually allowed keep it. |
| 1763 | - if (in_array($id_group, $allowed)) |
|
| 1764 | - $existingGroups[] = $id_group; |
|
| 1809 | + if (in_array($id_group, $allowed)) { |
|
| 1810 | + $existingGroups[] = $id_group; |
|
| 1811 | + } |
|
| 1765 | 1812 | |
| 1766 | 1813 | // Either way, change the id_group back. |
| 1767 | 1814 | if ($new_id_group < 1) |
| 1768 | 1815 | { |
| 1769 | 1816 | // If we revert to the old id-group we need to ensure it wasn't from a subscription. |
| 1770 | - foreach ($context['subscriptions'] as $id => $group) |
|
| 1771 | - // It was? Make them a regular member then! |
|
| 1817 | + foreach ($context['subscriptions'] as $id => $group) { |
|
| 1818 | + // It was? Make them a regular member then! |
|
| 1772 | 1819 | if ($group['prim_group'] == $old_id_group) |
| 1773 | 1820 | $old_id_group = 0; |
| 1821 | + } |
|
| 1774 | 1822 | |
| 1775 | 1823 | $id_group = $old_id_group; |
| 1824 | + } else { |
|
| 1825 | + $id_group = $new_id_group; |
|
| 1776 | 1826 | } |
| 1777 | - else |
|
| 1778 | - $id_group = $new_id_group; |
|
| 1779 | 1827 | } |
| 1780 | 1828 | |
| 1781 | 1829 | // Crazy stuff, we seem to have our groups fixed, just make them unique |
@@ -1795,8 +1843,8 @@ discard block |
||
| 1795 | 1843 | ); |
| 1796 | 1844 | |
| 1797 | 1845 | // Disable the subscription. |
| 1798 | - if (!$delete) |
|
| 1799 | - $smcFunc['db_query']('', ' |
|
| 1846 | + if (!$delete) { |
|
| 1847 | + $smcFunc['db_query']('', ' |
|
| 1800 | 1848 | UPDATE {db_prefix}log_subscribed |
| 1801 | 1849 | SET status = {int:not_active} |
| 1802 | 1850 | WHERE id_member = {int:current_member} |
@@ -1807,9 +1855,10 @@ discard block |
||
| 1807 | 1855 | 'current_subscription' => $id_subscribe, |
| 1808 | 1856 | ) |
| 1809 | 1857 | ); |
| 1858 | + } |
|
| 1810 | 1859 | // Otherwise delete it! |
| 1811 | - else |
|
| 1812 | - $smcFunc['db_query']('', ' |
|
| 1860 | + else { |
|
| 1861 | + $smcFunc['db_query']('', ' |
|
| 1813 | 1862 | DELETE FROM {db_prefix}log_subscribed |
| 1814 | 1863 | WHERE id_member = {int:current_member} |
| 1815 | 1864 | AND id_subscribe = {int:current_subscription}', |
@@ -1818,7 +1867,8 @@ discard block |
||
| 1818 | 1867 | 'current_subscription' => $id_subscribe, |
| 1819 | 1868 | ) |
| 1820 | 1869 | ); |
| 1821 | -} |
|
| 1870 | + } |
|
| 1871 | + } |
|
| 1822 | 1872 | |
| 1823 | 1873 | /** |
| 1824 | 1874 | * This just kind of caches all the subscription data. |
@@ -1827,8 +1877,9 @@ discard block |
||
| 1827 | 1877 | { |
| 1828 | 1878 | global $context, $txt, $modSettings, $smcFunc; |
| 1829 | 1879 | |
| 1830 | - if (!empty($context['subscriptions'])) |
|
| 1831 | - return; |
|
| 1880 | + if (!empty($context['subscriptions'])) { |
|
| 1881 | + return; |
|
| 1882 | + } |
|
| 1832 | 1883 | |
| 1833 | 1884 | // Make sure this is loaded, just in case. |
| 1834 | 1885 | loadLanguage('ManagePaid'); |
@@ -1845,10 +1896,11 @@ discard block |
||
| 1845 | 1896 | // Pick a cost. |
| 1846 | 1897 | $costs = @json_decode($row['cost'], true); |
| 1847 | 1898 | |
| 1848 | - if ($row['length'] != 'F' && !empty($modSettings['paid_currency_symbol']) && !empty($costs['fixed'])) |
|
| 1849 | - $cost = sprintf($modSettings['paid_currency_symbol'], $costs['fixed']); |
|
| 1850 | - else |
|
| 1851 | - $cost = '???'; |
|
| 1899 | + if ($row['length'] != 'F' && !empty($modSettings['paid_currency_symbol']) && !empty($costs['fixed'])) { |
|
| 1900 | + $cost = sprintf($modSettings['paid_currency_symbol'], $costs['fixed']); |
|
| 1901 | + } else { |
|
| 1902 | + $cost = '???'; |
|
| 1903 | + } |
|
| 1852 | 1904 | |
| 1853 | 1905 | // Do the span. |
| 1854 | 1906 | preg_match('~(\d*)(\w)~', $row['length'], $match); |
@@ -1875,9 +1927,9 @@ discard block |
||
| 1875 | 1927 | $num_length *= 31556926; |
| 1876 | 1928 | break; |
| 1877 | 1929 | } |
| 1930 | + } else { |
|
| 1931 | + $length = '??'; |
|
| 1878 | 1932 | } |
| 1879 | - else |
|
| 1880 | - $length = '??'; |
|
| 1881 | 1933 | |
| 1882 | 1934 | $context['subscriptions'][$row['id_subscribe']] = array( |
| 1883 | 1935 | 'id' => $row['id_subscribe'], |
@@ -1912,8 +1964,9 @@ discard block |
||
| 1912 | 1964 | { |
| 1913 | 1965 | $ind = $row['status'] == 0 ? 'finished' : 'total'; |
| 1914 | 1966 | |
| 1915 | - if (isset($context['subscriptions'][$row['id_subscribe']])) |
|
| 1916 | - $context['subscriptions'][$row['id_subscribe']][$ind] = $row['member_count']; |
|
| 1967 | + if (isset($context['subscriptions'][$row['id_subscribe']])) { |
|
| 1968 | + $context['subscriptions'][$row['id_subscribe']][$ind] = $row['member_count']; |
|
| 1969 | + } |
|
| 1917 | 1970 | } |
| 1918 | 1971 | $smcFunc['db_free_result']($request); |
| 1919 | 1972 | |
@@ -1927,8 +1980,9 @@ discard block |
||
| 1927 | 1980 | ); |
| 1928 | 1981 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1929 | 1982 | { |
| 1930 | - if (isset($context['subscriptions'][$row['id_subscribe']])) |
|
| 1931 | - $context['subscriptions'][$row['id_subscribe']]['pending'] = $row['total_pending']; |
|
| 1983 | + if (isset($context['subscriptions'][$row['id_subscribe']])) { |
|
| 1984 | + $context['subscriptions'][$row['id_subscribe']]['pending'] = $row['total_pending']; |
|
| 1985 | + } |
|
| 1932 | 1986 | } |
| 1933 | 1987 | $smcFunc['db_free_result']($request); |
| 1934 | 1988 | } |