| @@ -180,7 +180,7 @@ | ||
| 180 | 180 | * | 
| 181 | 181 | * @access public | 
| 182 | 182 | * @param string $dir A valid path | 
| 183 | - * @return boolean If this was successful or not. | |
| 183 | + * @return boolean|null If this was successful or not. | |
| 184 | 184 | */ | 
| 185 | 185 | public function setCachedir($dir = null) | 
| 186 | 186 |  	{ | 
| @@ -11,8 +11,9 @@ discard block | ||
| 11 | 11 | * @version 2.1 Beta 3 | 
| 12 | 12 | */ | 
| 13 | 13 | |
| 14 | -if (!defined('SMF')) | |
| 14 | +if (!defined('SMF')) { | |
| 15 | 15 |  	die('Hacking attempt...'); | 
| 16 | +} | |
| 16 | 17 | |
| 17 | 18 | /** | 
| 18 | 19 | * Our Cache API class | 
| @@ -43,8 +44,9 @@ discard block | ||
| 43 | 44 |  	{ | 
| 44 | 45 | $supported = is_writable($this->cachedir); | 
| 45 | 46 | |
| 46 | - if ($test) | |
| 47 | - return $supported; | |
| 47 | +		if ($test) { | |
| 48 | + return $supported; | |
| 49 | + } | |
| 48 | 50 | return parent::isSupported() && $supported; | 
| 49 | 51 | } | 
| 50 | 52 | |
| @@ -61,11 +63,13 @@ discard block | ||
| 61 | 63 |  		{ | 
| 62 | 64 | // Work around Zend's opcode caching (PHP 5.5+), they would cache older files for a couple of seconds | 
| 63 | 65 | // causing newer files to take effect a while later. | 
| 64 | -			if (function_exists('opcache_invalidate')) | |
| 65 | - opcache_invalidate($cachedir . '/data_' . $key . '.php', true); | |
| 66 | +			if (function_exists('opcache_invalidate')) { | |
| 67 | + opcache_invalidate($cachedir . '/data_' . $key . '.php', true); | |
| 68 | + } | |
| 66 | 69 | |
| 67 | -			if (function_exists('apc_delete_file')) | |
| 68 | - @apc_delete_file($cachedir . '/data_' . $key . '.php'); | |
| 70 | +			if (function_exists('apc_delete_file')) { | |
| 71 | + @apc_delete_file($cachedir . '/data_' . $key . '.php'); | |
| 72 | + } | |
| 69 | 73 | |
| 70 | 74 | // php will cache file_exists et all, we can't 100% depend on its results so proceed with caution | 
| 71 | 75 | @include($cachedir . '/data_' . $key . '.php'); | 
| @@ -89,16 +93,18 @@ discard block | ||
| 89 | 93 | |
| 90 | 94 | // Work around Zend's opcode caching (PHP 5.5+), they would cache older files for a couple of seconds | 
| 91 | 95 | // causing newer files to take effect a while later. | 
| 92 | -		if (function_exists('opcache_invalidate')) | |
| 93 | - opcache_invalidate($cachedir . '/data_' . $key . '.php', true); | |
| 96 | +		if (function_exists('opcache_invalidate')) { | |
| 97 | + opcache_invalidate($cachedir . '/data_' . $key . '.php', true); | |
| 98 | + } | |
| 94 | 99 | |
| 95 | -		if (function_exists('apc_delete_file')) | |
| 96 | - @apc_delete_file($cachedir . '/data_' . $key . '.php'); | |
| 100 | +		if (function_exists('apc_delete_file')) { | |
| 101 | + @apc_delete_file($cachedir . '/data_' . $key . '.php'); | |
| 102 | + } | |
| 97 | 103 | |
| 98 | 104 | // Otherwise custom cache? | 
| 99 | - if ($value === null) | |
| 100 | - @unlink($cachedir . '/data_' . $key . '.php'); | |
| 101 | - else | |
| 105 | +		if ($value === null) { | |
| 106 | + @unlink($cachedir . '/data_' . $key . '.php'); | |
| 107 | + } else | |
| 102 | 108 |  		{ | 
| 103 | 109 |  			$cache_data = '<' . '?' . 'php if (!defined(\'SMF\')) die; if (' . (time() + $ttl) . ' < time()) $expired = true; else{$expired = false; $value = \'' . addcslashes($value, '\\\'') . '\';}' . '?' . '>'; | 
| 104 | 110 | |
| @@ -109,9 +115,9 @@ discard block | ||
| 109 | 115 |  			{ | 
| 110 | 116 | @unlink($cachedir . '/data_' . $key . '.php'); | 
| 111 | 117 | return false; | 
| 118 | +			} else { | |
| 119 | + return true; | |
| 112 | 120 | } | 
| 113 | - else | |
| 114 | - return true; | |
| 115 | 121 | } | 
| 116 | 122 | } | 
| 117 | 123 | |
| @@ -123,15 +129,17 @@ discard block | ||
| 123 | 129 | $cachedir = $this->cachedir; | 
| 124 | 130 | |
| 125 | 131 | // No directory = no game. | 
| 126 | - if (!is_dir($cachedir)) | |
| 127 | - return; | |
| 132 | +		if (!is_dir($cachedir)) { | |
| 133 | + return; | |
| 134 | + } | |
| 128 | 135 | |
| 129 | 136 | // Remove the files in SMF's own disk cache, if any | 
| 130 | 137 | $dh = opendir($cachedir); | 
| 131 | 138 | while ($file = readdir($dh)) | 
| 132 | 139 |  		{ | 
| 133 | - if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type)) | |
| 134 | - @unlink($cachedir . '/' . $file); | |
| 140 | +			if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type)) { | |
| 141 | + @unlink($cachedir . '/' . $file); | |
| 142 | + } | |
| 135 | 143 | } | 
| 136 | 144 | closedir($dh); | 
| 137 | 145 | |
| @@ -165,8 +173,9 @@ discard block | ||
| 165 | 173 | $config_vars[] = $txt['cache_smf_settings']; | 
| 166 | 174 |  		$config_vars[] = array('cachedir', $txt['cachedir'], 'file', 'text', 36, 'cache_cachedir'); | 
| 167 | 175 | |
| 168 | - if (!isset($context['settings_post_javascript'])) | |
| 169 | - $context['settings_post_javascript'] = ''; | |
| 176 | +		if (!isset($context['settings_post_javascript'])) { | |
| 177 | + $context['settings_post_javascript'] = ''; | |
| 178 | + } | |
| 170 | 179 | |
| 171 | 180 | $context['settings_post_javascript'] .= ' | 
| 172 | 181 |  			$("#cache_accelerator").change(function (e) { | 
| @@ -187,10 +196,11 @@ discard block | ||
| 187 | 196 | global $cachedir; | 
| 188 | 197 | |
| 189 | 198 | // If its invalid, use SMF's. | 
| 190 | - if (is_null($dir) || !is_writable($dir)) | |
| 191 | - $this->cachedir = $cachedir; | |
| 192 | - else | |
| 193 | - $this->cachedir = $dir; | |
| 199 | +		if (is_null($dir) || !is_writable($dir)) { | |
| 200 | + $this->cachedir = $cachedir; | |
| 201 | +		} else { | |
| 202 | + $this->cachedir = $dir; | |
| 203 | + } | |
| 194 | 204 | } | 
| 195 | 205 | |
| 196 | 206 | /** | 
| @@ -44,6 +44,10 @@ discard block | ||
| 44 | 44 | $this->Buf = range(0, 279); | 
| 45 | 45 | } | 
| 46 | 46 | |
| 47 | + /** | |
| 48 | + * @param string $data | |
| 49 | + * @param integer $datLen | |
| 50 | + */ | |
| 47 | 51 | public function decompress($data, &$datLen) | 
| 48 | 52 |  	{ | 
| 49 | 53 | $stLen = strlen($data); | 
| @@ -63,6 +67,11 @@ discard block | ||
| 63 | 67 | return $ret; | 
| 64 | 68 | } | 
| 65 | 69 | |
| 70 | + /** | |
| 71 | + * @param boolean $bInit | |
| 72 | + * | |
| 73 | + * @return integer | |
| 74 | + */ | |
| 66 | 75 | public function LZWCommand(&$data, $bInit) | 
| 67 | 76 |  	{ | 
| 68 | 77 | if ($bInit) | 
| @@ -253,6 +262,10 @@ discard block | ||
| 253 | 262 | unset($this->m_nColors, $this->m_arColors); | 
| 254 | 263 | } | 
| 255 | 264 | |
| 265 | + /** | |
| 266 | + * @param string $lpData | |
| 267 | + * @param integer $num | |
| 268 | + */ | |
| 256 | 269 | public function load($lpData, $num) | 
| 257 | 270 |  	{ | 
| 258 | 271 | $this->m_nColors = 0; | 
| @@ -324,6 +337,9 @@ discard block | ||
| 324 | 337 | unset($this->m_bSorted, $this->m_nTableSize, $this->m_nBgColor, $this->m_nPixelRatio, $this->m_colorTable); | 
| 325 | 338 | } | 
| 326 | 339 | |
| 340 | + /** | |
| 341 | + * @param integer $hdrLen | |
| 342 | + */ | |
| 327 | 343 | public function load($lpData, &$hdrLen) | 
| 328 | 344 |  	{ | 
| 329 | 345 | $hdrLen = 0; | 
| @@ -370,6 +386,10 @@ discard block | ||
| 370 | 386 | unset($this->m_bInterlace, $this->m_bSorted, $this->m_nTableSize, $this->m_colorTable); | 
| 371 | 387 | } | 
| 372 | 388 | |
| 389 | + /** | |
| 390 | + * @param string $lpData | |
| 391 | + * @param integer $hdrLen | |
| 392 | + */ | |
| 373 | 393 | public function load($lpData, &$hdrLen) | 
| 374 | 394 |  	{ | 
| 375 | 395 | $hdrLen = 0; | 
| @@ -412,6 +432,10 @@ discard block | ||
| 412 | 432 | $this->m_lzw = new gif_lzw_compression(); | 
| 413 | 433 | } | 
| 414 | 434 | |
| 435 | + /** | |
| 436 | + * @param string $data | |
| 437 | + * @param integer $datLen | |
| 438 | + */ | |
| 415 | 439 | public function load($data, &$datLen) | 
| 416 | 440 |  	{ | 
| 417 | 441 | $datLen = 0; | 
| @@ -464,6 +488,10 @@ discard block | ||
| 464 | 488 | return false; | 
| 465 | 489 | } | 
| 466 | 490 | |
| 491 | + /** | |
| 492 | + * @param string $data | |
| 493 | + * @param integer $extLen | |
| 494 | + */ | |
| 467 | 495 | public function skipExt(&$data, &$extLen) | 
| 468 | 496 |  	{ | 
| 469 | 497 | $extLen = 0; | 
| @@ -38,8 +38,8 @@ discard block | ||
| 38 | 38 | $this->MAX_LZW_BITS = 12; | 
| 39 | 39 | unset($this->Next, $this->Vals, $this->Stack, $this->Buf); | 
| 40 | 40 | |
| 41 | - $this->Next = range(0, (1 << $this->MAX_LZW_BITS) - 1); | |
| 42 | - $this->Vals = range(0, (1 << $this->MAX_LZW_BITS) - 1); | |
| 41 | + $this->Next = range(0, (1 << $this->MAX_LZW_BITS) - 1); | |
| 42 | + $this->Vals = range(0, (1 << $this->MAX_LZW_BITS) - 1); | |
| 43 | 43 | $this->Stack = range(0, (1 << ($this->MAX_LZW_BITS + 1)) - 1); | 
| 44 | 44 | $this->Buf = range(0, 279); | 
| 45 | 45 | } | 
| @@ -278,9 +278,9 @@ discard block | ||
| 278 | 278 | for ($i = 0; $i < $this->m_nColors; $i++) | 
| 279 | 279 |  		{ | 
| 280 | 280 | $ret .= | 
| 281 | - chr(($this->m_arColors[$i] & 0x000000FF)) . // R | |
| 282 | - chr(($this->m_arColors[$i] & 0x0000FF00) >> 8) . // G | |
| 283 | - chr(($this->m_arColors[$i] & 0x00FF0000) >> 16); // B | |
| 281 | + chr(($this->m_arColors[$i] & 0x000000FF)) . // R | |
| 282 | + chr(($this->m_arColors[$i] & 0x0000FF00) >> 8) . // G | |
| 283 | + chr(($this->m_arColors[$i] & 0x00FF0000) >> 16); // B | |
| 284 | 284 | } | 
| 285 | 285 | |
| 286 | 286 | return $ret; | 
| @@ -290,14 +290,14 @@ discard block | ||
| 290 | 290 |  	{ | 
| 291 | 291 | $rgb = intval($rgb) & 0xFFFFFF; | 
| 292 | 292 | $r1 = ($rgb & 0x0000FF); | 
| 293 | - $g1 = ($rgb & 0x00FF00) >> 8; | |
| 293 | + $g1 = ($rgb & 0x00FF00) >> 8; | |
| 294 | 294 | $b1 = ($rgb & 0xFF0000) >> 16; | 
| 295 | 295 | $idx = -1; | 
| 296 | 296 | |
| 297 | 297 | for ($i = 0; $i < $this->m_nColors; $i++) | 
| 298 | 298 |  		{ | 
| 299 | 299 | $r2 = ($this->m_arColors[$i] & 0x000000FF); | 
| 300 | - $g2 = ($this->m_arColors[$i] & 0x0000FF00) >> 8; | |
| 300 | + $g2 = ($this->m_arColors[$i] & 0x0000FF00) >> 8; | |
| 301 | 301 | $b2 = ($this->m_arColors[$i] & 0x00FF0000) >> 16; | 
| 302 | 302 | $d = abs($r2 - $r1) + abs($g2 - $g1) + abs($b2 - $b1); | 
| 303 | 303 | |
| @@ -19,8 +19,9 @@ discard block | ||
| 19 | 19 | * @version 2.1 Beta 3 | 
| 20 | 20 | */ | 
| 21 | 21 | |
| 22 | -if (!defined('SMF')) | |
| 22 | +if (!defined('SMF')) { | |
| 23 | 23 |  	die('No direct access...'); | 
| 24 | +} | |
| 24 | 25 | |
| 25 | 26 | /** | 
| 26 | 27 | * Class gif_lzw_compression | 
| @@ -52,13 +53,15 @@ discard block | ||
| 52 | 53 | |
| 53 | 54 | $this->LZWCommand($data, true); | 
| 54 | 55 | |
| 55 | - while (($iIndex = $this->LZWCommand($data, false)) >= 0) | |
| 56 | - $ret .= chr($iIndex); | |
| 56 | +		while (($iIndex = $this->LZWCommand($data, false)) >= 0) { | |
| 57 | + $ret .= chr($iIndex); | |
| 58 | + } | |
| 57 | 59 | |
| 58 | 60 | $datLen = $stLen - strlen($data); | 
| 59 | 61 | |
| 60 | - if ($iIndex != -2) | |
| 61 | - return false; | |
| 62 | +		if ($iIndex != -2) { | |
| 63 | + return false; | |
| 64 | + } | |
| 62 | 65 | |
| 63 | 66 | return $ret; | 
| 64 | 67 | } | 
| @@ -140,8 +143,9 @@ discard block | ||
| 140 | 143 | return $this->FirstCode; | 
| 141 | 144 | } | 
| 142 | 145 | |
| 143 | - if ($Code == $this->EndCode) | |
| 144 | - return -2; | |
| 146 | +			if ($Code == $this->EndCode) { | |
| 147 | + return -2; | |
| 148 | + } | |
| 145 | 149 | |
| 146 | 150 | $InCode = $Code; | 
| 147 | 151 | if ($Code >= $this->MaxCode) | 
| @@ -156,8 +160,10 @@ discard block | ||
| 156 | 160 | $this->Stack[$this->sp] = $this->Vals[$Code]; | 
| 157 | 161 | $this->sp++; | 
| 158 | 162 | |
| 159 | - if ($Code == $this->Next[$Code]) // Circular table entry, big GIF Error! | |
| 163 | +				if ($Code == $this->Next[$Code]) { | |
| 164 | + // Circular table entry, big GIF Error! | |
| 160 | 165 | return -1; | 
| 166 | + } | |
| 161 | 167 | |
| 162 | 168 | $Code = $this->Next[$Code]; | 
| 163 | 169 | } | 
| @@ -207,8 +213,9 @@ discard block | ||
| 207 | 213 | if ($this->Done) | 
| 208 | 214 |  			{ | 
| 209 | 215 | // Ran off the end of my bits... | 
| 210 | - if ($this->CurBit >= $this->LastBit) | |
| 211 | - return 0; | |
| 216 | +				if ($this->CurBit >= $this->LastBit) { | |
| 217 | + return 0; | |
| 218 | + } | |
| 212 | 219 | |
| 213 | 220 | return -1; | 
| 214 | 221 | } | 
| @@ -221,13 +228,14 @@ discard block | ||
| 221 | 228 | |
| 222 | 229 | if ($count) | 
| 223 | 230 |  			{ | 
| 224 | - for ($i = 0; $i < $count; $i++) | |
| 225 | -					$this->Buf[2 + $i] = ord($data{$i}); | |
| 231 | +				for ($i = 0; $i < $count; $i++) { | |
| 232 | +									$this->Buf[2 + $i] = ord($data{$i}); | |
| 233 | + } | |
| 226 | 234 | |
| 227 | 235 | $data = substr($data, $count); | 
| 236 | +			} else { | |
| 237 | + $this->Done = 1; | |
| 228 | 238 | } | 
| 229 | - else | |
| 230 | - $this->Done = 1; | |
| 231 | 239 | |
| 232 | 240 | $this->LastByte = 2 + $count; | 
| 233 | 241 | $this->CurBit = ($this->CurBit - $this->LastBit) + 16; | 
| @@ -235,8 +243,9 @@ discard block | ||
| 235 | 243 | } | 
| 236 | 244 | |
| 237 | 245 | $iRet = 0; | 
| 238 | - for ($i = $this->CurBit, $j = 0; $j < $this->CodeSize; $i++, $j++) | |
| 239 | - $iRet |= (($this->Buf[intval($i / 8)] & (1 << ($i % 8))) != 0) << $j; | |
| 246 | +		for ($i = $this->CurBit, $j = 0; $j < $this->CodeSize; $i++, $j++) { | |
| 247 | + $iRet |= (($this->Buf[intval($i / 8)] & (1 << ($i % 8))) != 0) << $j; | |
| 248 | + } | |
| 240 | 249 | |
| 241 | 250 | $this->CurBit += $this->CodeSize; | 
| 242 | 251 | return $iRet; | 
| @@ -261,8 +270,9 @@ discard block | ||
| 261 | 270 | for ($i = 0; $i < $num; $i++) | 
| 262 | 271 |  		{ | 
| 263 | 272 | $rgb = substr($lpData, $i * 3, 3); | 
| 264 | - if (strlen($rgb) < 3) | |
| 265 | - return false; | |
| 273 | +			if (strlen($rgb) < 3) { | |
| 274 | + return false; | |
| 275 | + } | |
| 266 | 276 | |
| 267 | 277 | $this->m_arColors[] = (ord($rgb[2]) << 16) + (ord($rgb[1]) << 8) + ord($rgb[0]); | 
| 268 | 278 | $this->m_nColors++; | 
| @@ -329,13 +339,15 @@ discard block | ||
| 329 | 339 | $hdrLen = 0; | 
| 330 | 340 | |
| 331 | 341 | $this->m_lpVer = substr($lpData, 0, 6); | 
| 332 | - if (($this->m_lpVer != 'GIF87a') && ($this->m_lpVer != 'GIF89a')) | |
| 333 | - return false; | |
| 342 | +		if (($this->m_lpVer != 'GIF87a') && ($this->m_lpVer != 'GIF89a')) { | |
| 343 | + return false; | |
| 344 | + } | |
| 334 | 345 | |
| 335 | 346 |  		list ($this->m_nWidth, $this->m_nHeight) = array_values(unpack('v2', substr($lpData, 6, 4))); | 
| 336 | 347 | |
| 337 | - if (!$this->m_nWidth || !$this->m_nHeight) | |
| 338 | - return false; | |
| 348 | +		if (!$this->m_nWidth || !$this->m_nHeight) { | |
| 349 | + return false; | |
| 350 | + } | |
| 339 | 351 | |
| 340 | 352 | $b = ord(substr($lpData, 10, 1)); | 
| 341 | 353 | $this->m_bGlobalClr = ($b & 0x80) ? true : false; | 
| @@ -349,8 +361,9 @@ discard block | ||
| 349 | 361 | if ($this->m_bGlobalClr) | 
| 350 | 362 |  		{ | 
| 351 | 363 | $this->m_colorTable = new gif_color_table(); | 
| 352 | - if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) | |
| 353 | - return false; | |
| 364 | +			if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) { | |
| 365 | + return false; | |
| 366 | + } | |
| 354 | 367 | |
| 355 | 368 | $hdrLen += 3 * $this->m_nTableSize; | 
| 356 | 369 | } | 
| @@ -377,8 +390,9 @@ discard block | ||
| 377 | 390 | // Get the width/height/etc. from the header. | 
| 378 | 391 |  		list ($this->m_nLeft, $this->m_nTop, $this->m_nWidth, $this->m_nHeight) = array_values(unpack('v4', substr($lpData, 0, 8))); | 
| 379 | 392 | |
| 380 | - if (!$this->m_nWidth || !$this->m_nHeight) | |
| 381 | - return false; | |
| 393 | +		if (!$this->m_nWidth || !$this->m_nHeight) { | |
| 394 | + return false; | |
| 395 | + } | |
| 382 | 396 | |
| 383 | 397 | $b = ord($lpData[8]); | 
| 384 | 398 | $this->m_bLocalClr = ($b & 0x80) ? true : false; | 
| @@ -390,8 +404,9 @@ discard block | ||
| 390 | 404 | if ($this->m_bLocalClr) | 
| 391 | 405 |  		{ | 
| 392 | 406 | $this->m_colorTable = new gif_color_table(); | 
| 393 | - if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) | |
| 394 | - return false; | |
| 407 | +			if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) { | |
| 408 | + return false; | |
| 409 | + } | |
| 395 | 410 | |
| 396 | 411 | $hdrLen += 3 * $this->m_nTableSize; | 
| 397 | 412 | } | 
| @@ -427,8 +442,9 @@ discard block | ||
| 427 | 442 | // Extension... | 
| 428 | 443 | case 0x21: | 
| 429 | 444 | $len = 0; | 
| 430 | - if (!$this->skipExt($data, $len)) | |
| 431 | - return false; | |
| 445 | +					if (!$this->skipExt($data, $len)) { | |
| 446 | + return false; | |
| 447 | + } | |
| 432 | 448 | |
| 433 | 449 | $datLen += $len; | 
| 434 | 450 | break; | 
| @@ -437,21 +453,24 @@ discard block | ||
| 437 | 453 | case 0x2C: | 
| 438 | 454 | // Load the header and color table. | 
| 439 | 455 | $len = 0; | 
| 440 | - if (!$this->m_gih->load($data, $len)) | |
| 441 | - return false; | |
| 456 | +					if (!$this->m_gih->load($data, $len)) { | |
| 457 | + return false; | |
| 458 | + } | |
| 442 | 459 | |
| 443 | 460 | $data = substr($data, $len); | 
| 444 | 461 | $datLen += $len; | 
| 445 | 462 | |
| 446 | 463 | // Decompress the data, and ride on home ;). | 
| 447 | 464 | $len = 0; | 
| 448 | - if (!($this->m_data = $this->m_lzw->decompress($data, $len))) | |
| 449 | - return false; | |
| 465 | +					if (!($this->m_data = $this->m_lzw->decompress($data, $len))) { | |
| 466 | + return false; | |
| 467 | + } | |
| 450 | 468 | |
| 451 | 469 | $datLen += $len; | 
| 452 | 470 | |
| 453 | - if ($this->m_gih->m_bInterlace) | |
| 454 | - $this->deInterlace(); | |
| 471 | +					if ($this->m_gih->m_bInterlace) { | |
| 472 | + $this->deInterlace(); | |
| 473 | + } | |
| 455 | 474 | |
| 456 | 475 | return true; | 
| 457 | 476 | |
| @@ -571,17 +590,20 @@ discard block | ||
| 571 | 590 | |
| 572 | 591 | public function loadFile($filename, $iIndex) | 
| 573 | 592 |  	{ | 
| 574 | - if ($iIndex < 0) | |
| 575 | - return false; | |
| 593 | +		if ($iIndex < 0) { | |
| 594 | + return false; | |
| 595 | + } | |
| 576 | 596 | |
| 577 | 597 | $this->data = @file_get_contents($filename); | 
| 578 | - if ($this->data === false) | |
| 579 | - return false; | |
| 598 | +		if ($this->data === false) { | |
| 599 | + return false; | |
| 600 | + } | |
| 580 | 601 | |
| 581 | 602 | // Tell the header to load up.... | 
| 582 | 603 | $len = 0; | 
| 583 | - if (!$this->header->load($this->data, $len)) | |
| 584 | - return false; | |
| 604 | +		if (!$this->header->load($this->data, $len)) { | |
| 605 | + return false; | |
| 606 | + } | |
| 585 | 607 | |
| 586 | 608 | $this->data = substr($this->data, $len); | 
| 587 | 609 | |
| @@ -589,8 +611,9 @@ discard block | ||
| 589 | 611 | for ($j = 0; $j <= $iIndex; $j++) | 
| 590 | 612 |  		{ | 
| 591 | 613 | $imgLen = 0; | 
| 592 | - if (!$this->image->load($this->data, $imgLen)) | |
| 593 | - return false; | |
| 614 | +			if (!$this->image->load($this->data, $imgLen)) { | |
| 615 | + return false; | |
| 616 | + } | |
| 594 | 617 | |
| 595 | 618 | $this->data = substr($this->data, $imgLen); | 
| 596 | 619 | } | 
| @@ -601,8 +624,9 @@ discard block | ||
| 601 | 624 | |
| 602 | 625 | public function get_png_data($background_color) | 
| 603 | 626 |  	{ | 
| 604 | - if (!$this->loaded) | |
| 605 | - return false; | |
| 627 | +		if (!$this->loaded) { | |
| 628 | + return false; | |
| 629 | + } | |
| 606 | 630 | |
| 607 | 631 | // Prepare the color table. | 
| 608 | 632 | if ($this->image->m_gih->m_bLocalClr) | 
| @@ -610,25 +634,26 @@ discard block | ||
| 610 | 634 | $colors = $this->image->m_gih->m_nTableSize; | 
| 611 | 635 | $pal = $this->image->m_gih->m_colorTable->toString(); | 
| 612 | 636 | |
| 613 | - if ($background_color != -1) | |
| 614 | - $background_color = $this->image->m_gih->m_colorTable->colorIndex($background_color); | |
| 615 | - } | |
| 616 | - elseif ($this->header->m_bGlobalClr) | |
| 637 | +			if ($background_color != -1) { | |
| 638 | + $background_color = $this->image->m_gih->m_colorTable->colorIndex($background_color); | |
| 639 | + } | |
| 640 | + } elseif ($this->header->m_bGlobalClr) | |
| 617 | 641 |  		{ | 
| 618 | 642 | $colors = $this->header->m_nTableSize; | 
| 619 | 643 | $pal = $this->header->m_colorTable->toString(); | 
| 620 | 644 | |
| 621 | - if ($background_color != -1) | |
| 622 | - $background_color = $this->header->m_colorTable->colorIndex($background_color); | |
| 623 | - } | |
| 624 | - else | |
| 645 | +			if ($background_color != -1) { | |
| 646 | + $background_color = $this->header->m_colorTable->colorIndex($background_color); | |
| 647 | + } | |
| 648 | + } else | |
| 625 | 649 |  		{ | 
| 626 | 650 | $colors = 0; | 
| 627 | 651 | $background_color = -1; | 
| 628 | 652 | } | 
| 629 | 653 | |
| 630 | - if ($background_color == -1) | |
| 631 | - $background_color = $this->header->m_nBgColor; | |
| 654 | +		if ($background_color == -1) { | |
| 655 | + $background_color = $this->header->m_nBgColor; | |
| 656 | + } | |
| 632 | 657 | |
| 633 | 658 | $data = &$this->image->m_data; | 
| 634 | 659 | $header = &$this->image->m_gih; | 
| @@ -644,11 +669,13 @@ discard block | ||
| 644 | 669 | for ($x = 0; $x < $this->header->m_nWidth; $x++, $i++) | 
| 645 | 670 |  			{ | 
| 646 | 671 | // Is this in the proper range? If so, get the specific pixel data... | 
| 647 | - if ($x >= $header->m_nLeft && $y >= $header->m_nTop && $x < ($header->m_nLeft + $header->m_nWidth) && $y < ($header->m_nTop + $header->m_nHeight)) | |
| 648 | -					$bmp .= $data{$i}; | |
| 672 | +				if ($x >= $header->m_nLeft && $y >= $header->m_nTop && $x < ($header->m_nLeft + $header->m_nWidth) && $y < ($header->m_nTop + $header->m_nHeight)) { | |
| 673 | +									$bmp .= $data{$i}; | |
| 674 | + } | |
| 649 | 675 | // Otherwise, this is background... | 
| 650 | - else | |
| 651 | - $bmp .= chr($background_color); | |
| 676 | +				else { | |
| 677 | + $bmp .= chr($background_color); | |
| 678 | + } | |
| 652 | 679 | } | 
| 653 | 680 | } | 
| 654 | 681 | |
| @@ -677,8 +704,9 @@ discard block | ||
| 677 | 704 | $tmp = 'tRNS'; | 
| 678 | 705 | |
| 679 | 706 | // Stick each color on - full transparency or none. | 
| 680 | - for ($i = 0; $i < $colors; $i++) | |
| 681 | - $tmp .= $i == $this->image->m_nTrans ? "\x00" : "\xFF"; | |
| 707 | +			for ($i = 0; $i < $colors; $i++) { | |
| 708 | + $tmp .= $i == $this->image->m_nTrans ? "\x00" : "\xFF"; | |
| 709 | + } | |
| 682 | 710 | |
| 683 | 711 |  			$out .= $tmp . pack('N', smf_crc32($tmp)); | 
| 684 | 712 | } | 
| @@ -257,7 +257,7 @@ discard block | ||
| 257 | 257 | * of elements, an array of xmlArray's is returned for use with foreach. | 
| 258 | 258 | * Example use: | 
| 259 | 259 |  	 *  foreach ($xml->set('html/body/p') as $p) | 
| 260 | - * @param $path string The path to search for. | |
| 260 | + * @param string $path string The path to search for. | |
| 261 | 261 | * @return array An array of xmlArray objects | 
| 262 | 262 | */ | 
| 263 | 263 | public function set($path) | 
| @@ -855,7 +855,7 @@ discard block | ||
| 855 | 855 | * Changes a files atrributes (chmod) | 
| 856 | 856 | * | 
| 857 | 857 | * @param string $ftp_file The file to CHMOD | 
| 858 | - * @param int|string $chmod The value for the CHMOD operation | |
| 858 | + * @param integer $chmod The value for the CHMOD operation | |
| 859 | 859 | * @return boolean Whether or not the operation was successful | 
| 860 | 860 | */ | 
| 861 | 861 | public function chmod($ftp_file, $chmod) | 
| @@ -1025,7 +1025,7 @@ discard block | ||
| 1025 | 1025 | * | 
| 1026 | 1026 | * @param string $ftp_path The path to the directory | 
| 1027 | 1027 | * @param bool $search Whether or not to get a recursive directory listing | 
| 1028 | - * @return string|boolean The results of the command or false if unsuccessful | |
| 1028 | + * @return false|string The results of the command or false if unsuccessful | |
| 1029 | 1029 | */ | 
| 1030 | 1030 | public function list_dir($ftp_path = '', $search = false) | 
| 1031 | 1031 |  	{ | 
| @@ -1070,7 +1070,7 @@ discard block | ||
| 1070 | 1070 | * | 
| 1071 | 1071 | * @param string $file The name of a file | 
| 1072 | 1072 | * @param string $listing A directory listing or null to generate one | 
| 1073 | - * @return string|boolean The name of the file or false if it wasn't found | |
| 1073 | + * @return string|false The name of the file or false if it wasn't found | |
| 1074 | 1074 | */ | 
| 1075 | 1075 | public function locate($file, $listing = null) | 
| 1076 | 1076 |  	{ | 
| @@ -793,7 +793,7 @@ discard block | ||
| 793 | 793 | if (!$this->connection) | 
| 794 | 794 |  		{ | 
| 795 | 795 | $this->error = 'bad_server'; | 
| 796 | - $this->last_message = 'Invalid Server'; | |
| 796 | + $this->last_message = 'Invalid Server'; | |
| 797 | 797 | return; | 
| 798 | 798 | } | 
| 799 | 799 | |
| @@ -801,7 +801,7 @@ discard block | ||
| 801 | 801 | if (!$this->check_response(220)) | 
| 802 | 802 |  		{ | 
| 803 | 803 | $this->error = 'bad_response'; | 
| 804 | - $this->last_message = 'Bad Response'; | |
| 804 | + $this->last_message = 'Bad Response'; | |
| 805 | 805 | return; | 
| 806 | 806 | } | 
| 807 | 807 | |
| @@ -13,8 +13,9 @@ discard block | ||
| 13 | 13 | * @version 2.1 Beta 3 | 
| 14 | 14 | */ | 
| 15 | 15 | |
| 16 | -if (!defined('SMF')) | |
| 16 | +if (!defined('SMF')) { | |
| 17 | 17 |  	die('No direct access...'); | 
| 18 | +} | |
| 18 | 19 | |
| 19 | 20 | /** | 
| 20 | 21 | * Class xmlArray | 
| @@ -65,8 +66,9 @@ discard block | ||
| 65 | 66 | } | 
| 66 | 67 | |
| 67 | 68 | // Is the input an array? (ie. passed from file()?) | 
| 68 | - if (is_array($data)) | |
| 69 | -			$data = implode('', $data); | |
| 69 | +		if (is_array($data)) { | |
| 70 | +					$data = implode('', $data); | |
| 71 | + } | |
| 70 | 72 | |
| 71 | 73 | // Remove any xml declaration or doctype, and parse out comments and CDATA. | 
| 72 | 74 |  		$data = preg_replace('/<!--.*?-->/s', '', $this->_to_cdata(preg_replace(array('/^<\?xml.+?\?' . '>/is', '/<!DOCTYPE[^>]+?' . '>/s'), '', $data))); | 
| @@ -101,8 +103,9 @@ discard block | ||
| 101 | 103 | // Get the element, in array form. | 
| 102 | 104 | $array = $this->path($path); | 
| 103 | 105 | |
| 104 | - if ($array === false) | |
| 105 | - return false; | |
| 106 | +		if ($array === false) { | |
| 107 | + return false; | |
| 108 | + } | |
| 106 | 109 | |
| 107 | 110 | // Getting elements into this is a bit complicated... | 
| 108 | 111 | if ($get_elements && !is_string($array)) | 
| @@ -113,8 +116,9 @@ discard block | ||
| 113 | 116 | foreach ($array->array as $val) | 
| 114 | 117 |  			{ | 
| 115 | 118 | // Skip the name and any attributes. | 
| 116 | - if (is_array($val)) | |
| 117 | - $temp .= $this->_xml($val, null); | |
| 119 | +				if (is_array($val)) { | |
| 120 | + $temp .= $this->_xml($val, null); | |
| 121 | + } | |
| 118 | 122 | } | 
| 119 | 123 | |
| 120 | 124 | // Just get the XML data and then take out the CDATAs. | 
| @@ -156,32 +160,35 @@ discard block | ||
| 156 | 160 | elseif (substr($el, 0, 1) == '@') | 
| 157 | 161 |  			{ | 
| 158 | 162 | // It simplifies things if the attribute is already there ;). | 
| 159 | - if (isset($array[$el])) | |
| 160 | - return $array[$el]; | |
| 161 | - else | |
| 163 | +				if (isset($array[$el])) { | |
| 164 | + return $array[$el]; | |
| 165 | + } else | |
| 162 | 166 |  				{ | 
| 163 | 167 | $trace = debug_backtrace(); | 
| 164 | 168 | $i = 0; | 
| 165 | - while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) | |
| 166 | - $i++; | |
| 169 | +					while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) { | |
| 170 | + $i++; | |
| 171 | + } | |
| 167 | 172 | $debug = ' (from ' . $trace[$i - 1]['file'] . ' on line ' . $trace[$i - 1]['line'] . ')'; | 
| 168 | 173 | |
| 169 | 174 | // Cause an error. | 
| 170 | - if ($this->debug_level & E_NOTICE) | |
| 171 | -						trigger_error('Undefined XML attribute: ' . substr($el, 1) . $debug, E_USER_NOTICE); | |
| 175 | +					if ($this->debug_level & E_NOTICE) { | |
| 176 | +											trigger_error('Undefined XML attribute: ' . substr($el, 1) . $debug, E_USER_NOTICE); | |
| 177 | + } | |
| 172 | 178 | return false; | 
| 173 | 179 | } | 
| 180 | +			} else { | |
| 181 | + $lvl = null; | |
| 174 | 182 | } | 
| 175 | - else | |
| 176 | - $lvl = null; | |
| 177 | 183 | |
| 178 | 184 | // Find this element. | 
| 179 | 185 | $array = $this->_path($array, $el, $lvl); | 
| 180 | 186 | } | 
| 181 | 187 | |
| 182 | 188 | // Clean up after $lvl, for $return_full. | 
| 183 | - if ($return_full && (!isset($array['name']) || substr($array['name'], -1) != ']')) | |
| 184 | -			$array = array('name' => $el . '[]', $array); | |
| 189 | +		if ($return_full && (!isset($array['name']) || substr($array['name'], -1) != ']')) { | |
| 190 | +					$array = array('name' => $el . '[]', $array); | |
| 191 | + } | |
| 185 | 192 | |
| 186 | 193 | // Create the right type of class... | 
| 187 | 194 | $newClass = get_class($this); | 
| @@ -216,10 +223,11 @@ discard block | ||
| 216 | 223 | $el = substr($el, 0, strpos($el, '[')); | 
| 217 | 224 | } | 
| 218 | 225 | // Find an attribute. | 
| 219 | - elseif (substr($el, 0, 1) == '@') | |
| 220 | - return isset($array[$el]); | |
| 221 | - else | |
| 222 | - $lvl = null; | |
| 226 | +			elseif (substr($el, 0, 1) == '@') { | |
| 227 | + return isset($array[$el]); | |
| 228 | +			} else { | |
| 229 | + $lvl = null; | |
| 230 | + } | |
| 223 | 231 | |
| 224 | 232 | // Find this element. | 
| 225 | 233 | $array = $this->_path($array, $el, $lvl, true); | 
| @@ -244,8 +252,9 @@ discard block | ||
| 244 | 252 | $i = 0; | 
| 245 | 253 | foreach ($temp->array as $item) | 
| 246 | 254 |  		{ | 
| 247 | - if (is_array($item)) | |
| 248 | - $i++; | |
| 255 | +			if (is_array($item)) { | |
| 256 | + $i++; | |
| 257 | + } | |
| 249 | 258 | } | 
| 250 | 259 | |
| 251 | 260 | return $i; | 
| @@ -269,8 +278,9 @@ discard block | ||
| 269 | 278 | foreach ($xml->array as $val) | 
| 270 | 279 |  		{ | 
| 271 | 280 | // Skip these, they aren't elements. | 
| 272 | - if (!is_array($val) || $val['name'] == '!') | |
| 273 | - continue; | |
| 281 | +			if (!is_array($val) || $val['name'] == '!') { | |
| 282 | + continue; | |
| 283 | + } | |
| 274 | 284 | |
| 275 | 285 | // Create the right type of class... | 
| 276 | 286 | $newClass = get_class($this); | 
| @@ -297,14 +307,16 @@ discard block | ||
| 297 | 307 | $path = $this->path($path); | 
| 298 | 308 | |
| 299 | 309 | // The path was not found | 
| 300 | - if ($path === false) | |
| 301 | - return false; | |
| 310 | +			if ($path === false) { | |
| 311 | + return false; | |
| 312 | + } | |
| 302 | 313 | |
| 303 | 314 | $path = $path->array; | 
| 304 | 315 | } | 
| 305 | 316 | // Just use the current array. | 
| 306 | - else | |
| 307 | - $path = $this->array; | |
| 317 | +		else { | |
| 318 | + $path = $this->array; | |
| 319 | + } | |
| 308 | 320 | |
| 309 | 321 | // Add the xml declaration to the front. | 
| 310 | 322 | return '<?xml version="1.0"?' . '>' . $this->_xml($path, 0); | 
| @@ -326,14 +338,16 @@ discard block | ||
| 326 | 338 | $path = $this->path($path); | 
| 327 | 339 | |
| 328 | 340 | // The path was not found | 
| 329 | - if ($path === false) | |
| 330 | - return false; | |
| 341 | +			if ($path === false) { | |
| 342 | + return false; | |
| 343 | + } | |
| 331 | 344 | |
| 332 | 345 | $path = $path->array; | 
| 333 | 346 | } | 
| 334 | 347 | // No, so just use the current array. | 
| 335 | - else | |
| 336 | - $path = $this->array; | |
| 348 | +		else { | |
| 349 | + $path = $this->array; | |
| 350 | + } | |
| 337 | 351 | |
| 338 | 352 | return $this->_array($path); | 
| 339 | 353 | } | 
| @@ -355,8 +369,9 @@ discard block | ||
| 355 | 369 |  		{ | 
| 356 | 370 | // Find and remove the next tag. | 
| 357 | 371 |  			preg_match('/\A<([\w\-:]+)((?:\s+.+?)?)([\s]?\/)?' . '>/', $data, $match); | 
| 358 | - if (isset($match[0])) | |
| 359 | -				$data = preg_replace('/' . preg_quote($match[0], '/') . '/s', '', $data, 1); | |
| 372 | +			if (isset($match[0])) { | |
| 373 | +							$data = preg_replace('/' . preg_quote($match[0], '/') . '/s', '', $data, 1); | |
| 374 | + } | |
| 360 | 375 | |
| 361 | 376 | // Didn't find a tag? Keep looping.... | 
| 362 | 377 | if (!isset($match[1]) || $match[1] == '') | 
| @@ -367,11 +382,12 @@ discard block | ||
| 367 | 382 | $text_value = $this->_from_cdata($data); | 
| 368 | 383 | $data = ''; | 
| 369 | 384 | |
| 370 | - if ($text_value != '') | |
| 371 | - $current[] = array( | |
| 385 | +					if ($text_value != '') { | |
| 386 | + $current[] = array( | |
| 372 | 387 | 'name' => '!', | 
| 373 | 388 | 'value' => $text_value | 
| 374 | 389 | ); | 
| 390 | + } | |
| 375 | 391 | } | 
| 376 | 392 | // If the < isn't immediately next to the current position... more data. | 
| 377 | 393 | elseif (strpos($data, '<') > 0) | 
| @@ -379,11 +395,12 @@ discard block | ||
| 379 | 395 | $text_value = $this->_from_cdata(substr($data, 0, strpos($data, '<'))); | 
| 380 | 396 | $data = substr($data, strpos($data, '<')); | 
| 381 | 397 | |
| 382 | - if ($text_value != '') | |
| 383 | - $current[] = array( | |
| 398 | +					if ($text_value != '') { | |
| 399 | + $current[] = array( | |
| 384 | 400 | 'name' => '!', | 
| 385 | 401 | 'value' => $text_value | 
| 386 | 402 | ); | 
| 403 | + } | |
| 387 | 404 | } | 
| 388 | 405 | // If we're looking at a </something> with no start, kill it. | 
| 389 | 406 | elseif (strpos($data, '<') !== false && strpos($data, '<') == 0) | 
| @@ -393,22 +410,23 @@ discard block | ||
| 393 | 410 | $text_value = $this->_from_cdata(substr($data, 0, strpos($data, '<', 1))); | 
| 394 | 411 | $data = substr($data, strpos($data, '<', 1)); | 
| 395 | 412 | |
| 396 | - if ($text_value != '') | |
| 397 | - $current[] = array( | |
| 413 | +						if ($text_value != '') { | |
| 414 | + $current[] = array( | |
| 398 | 415 | 'name' => '!', | 
| 399 | 416 | 'value' => $text_value | 
| 400 | 417 | ); | 
| 401 | - } | |
| 402 | - else | |
| 418 | + } | |
| 419 | + } else | |
| 403 | 420 |  					{ | 
| 404 | 421 | $text_value = $this->_from_cdata($data); | 
| 405 | 422 | $data = ''; | 
| 406 | 423 | |
| 407 | - if ($text_value != '') | |
| 408 | - $current[] = array( | |
| 424 | +						if ($text_value != '') { | |
| 425 | + $current[] = array( | |
| 409 | 426 | 'name' => '!', | 
| 410 | 427 | 'value' => $text_value | 
| 411 | 428 | ); | 
| 429 | + } | |
| 412 | 430 | } | 
| 413 | 431 | } | 
| 414 | 432 | |
| @@ -425,8 +443,9 @@ discard block | ||
| 425 | 443 |  			{ | 
| 426 | 444 | // Because PHP 5.2.0+ seems to croak using regex, we'll have to do this the less fun way. | 
| 427 | 445 | $last_tag_end = strpos($data, '</' . $match[1] . '>'); | 
| 428 | - if ($last_tag_end === false) | |
| 429 | - continue; | |
| 446 | +				if ($last_tag_end === false) { | |
| 447 | + continue; | |
| 448 | + } | |
| 430 | 449 | |
| 431 | 450 | $offset = 0; | 
| 432 | 451 | while (1 == 1) | 
| @@ -434,16 +453,17 @@ discard block | ||
| 434 | 453 | // Where is the next start tag? | 
| 435 | 454 | $next_tag_start = strpos($data, '<' . $match[1], $offset); | 
| 436 | 455 | // If the next start tag is after the last end tag then we've found the right close. | 
| 437 | - if ($next_tag_start === false || $next_tag_start > $last_tag_end) | |
| 438 | - break; | |
| 456 | +					if ($next_tag_start === false || $next_tag_start > $last_tag_end) { | |
| 457 | + break; | |
| 458 | + } | |
| 439 | 459 | |
| 440 | 460 | // If not then find the next ending tag. | 
| 441 | 461 | $next_tag_end = strpos($data, '</' . $match[1] . '>', $offset); | 
| 442 | 462 | |
| 443 | 463 | // Didn't find one? Then just use the last and sod it. | 
| 444 | - if ($next_tag_end === false) | |
| 445 | - break; | |
| 446 | - else | |
| 464 | +					if ($next_tag_end === false) { | |
| 465 | + break; | |
| 466 | + } else | |
| 447 | 467 |  					{ | 
| 448 | 468 | $last_tag_end = $next_tag_end; | 
| 449 | 469 | $offset = $next_tag_start + 1; | 
| @@ -457,16 +477,17 @@ discard block | ||
| 457 | 477 | if (!empty($inner_match)) | 
| 458 | 478 |  				{ | 
| 459 | 479 | // Parse the inner data. | 
| 460 | - if (strpos($inner_match, '<') !== false) | |
| 461 | - $el += $this->_parse($inner_match); | |
| 462 | - elseif (trim($inner_match) != '') | |
| 480 | +					if (strpos($inner_match, '<') !== false) { | |
| 481 | + $el += $this->_parse($inner_match); | |
| 482 | + } elseif (trim($inner_match) != '') | |
| 463 | 483 |  					{ | 
| 464 | 484 | $text_value = $this->_from_cdata($inner_match); | 
| 465 | - if ($text_value != '') | |
| 466 | - $el[] = array( | |
| 485 | +						if ($text_value != '') { | |
| 486 | + $el[] = array( | |
| 467 | 487 | 'name' => '!', | 
| 468 | 488 | 'value' => $text_value | 
| 469 | 489 | ); | 
| 490 | + } | |
| 470 | 491 | } | 
| 471 | 492 | } | 
| 472 | 493 | } | 
| @@ -478,8 +499,9 @@ discard block | ||
| 478 | 499 |  				preg_match_all('/([\w:]+)="(.+?)"/', $match[2], $attr, PREG_SET_ORDER); | 
| 479 | 500 | |
| 480 | 501 | // Set them as @attribute-name. | 
| 481 | - foreach ($attr as $match_attr) | |
| 482 | - $el['@' . $match_attr[1]] = $match_attr[2]; | |
| 502 | +				foreach ($attr as $match_attr) { | |
| 503 | + $el['@' . $match_attr[1]] = $match_attr[2]; | |
| 504 | + } | |
| 483 | 505 | } | 
| 484 | 506 | } | 
| 485 | 507 | |
| @@ -503,16 +525,18 @@ discard block | ||
| 503 | 525 | if (is_array($array) && !isset($array['name'])) | 
| 504 | 526 |  		{ | 
| 505 | 527 | $temp = ''; | 
| 506 | - foreach ($array as $val) | |
| 507 | - $temp .= $this->_xml($val, $indent); | |
| 528 | +			foreach ($array as $val) { | |
| 529 | + $temp .= $this->_xml($val, $indent); | |
| 530 | + } | |
| 508 | 531 | return $temp; | 
| 509 | 532 | } | 
| 510 | 533 | |
| 511 | 534 | // This is just text! | 
| 512 | - if ($array['name'] == '!') | |
| 513 | - return $indentation . '<![CDATA[' . $array['value'] . ']]>'; | |
| 514 | - elseif (substr($array['name'], -2) == '[]') | |
| 515 | - $array['name'] = substr($array['name'], 0, -2); | |
| 535 | +		if ($array['name'] == '!') { | |
| 536 | + return $indentation . '<![CDATA[' . $array['value'] . ']]>'; | |
| 537 | +		} elseif (substr($array['name'], -2) == '[]') { | |
| 538 | + $array['name'] = substr($array['name'], 0, -2); | |
| 539 | + } | |
| 516 | 540 | |
| 517 | 541 | // Start the element. | 
| 518 | 542 | $output = $indentation . '<' . $array['name']; | 
| @@ -523,9 +547,9 @@ discard block | ||
| 523 | 547 | // Run through and recursively output all the elements or attrbutes inside this. | 
| 524 | 548 | foreach ($array as $k => $v) | 
| 525 | 549 |  		{ | 
| 526 | - if (substr($k, 0, 1) == '@') | |
| 527 | - $output .= ' ' . substr($k, 1) . '="' . $v . '"'; | |
| 528 | - elseif (is_array($v)) | |
| 550 | +			if (substr($k, 0, 1) == '@') { | |
| 551 | + $output .= ' ' . substr($k, 1) . '="' . $v . '"'; | |
| 552 | + } elseif (is_array($v)) | |
| 529 | 553 |  			{ | 
| 530 | 554 | $output_el .= $this->_xml($v, $indent === null ? null : $indent + 1); | 
| 531 | 555 | $inside_elements = true; | 
| @@ -533,10 +557,11 @@ discard block | ||
| 533 | 557 | } | 
| 534 | 558 | |
| 535 | 559 | // Indent, if necessary.... then close the tag. | 
| 536 | - if ($inside_elements) | |
| 537 | - $output .= '>' . $output_el . $indentation . '</' . $array['name'] . '>'; | |
| 538 | - else | |
| 539 | - $output .= ' />'; | |
| 560 | +		if ($inside_elements) { | |
| 561 | + $output .= '>' . $output_el . $indentation . '</' . $array['name'] . '>'; | |
| 562 | +		} else { | |
| 563 | + $output .= ' />'; | |
| 564 | + } | |
| 540 | 565 | |
| 541 | 566 | return $output; | 
| 542 | 567 | } | 
| @@ -553,19 +578,22 @@ discard block | ||
| 553 | 578 | $text = ''; | 
| 554 | 579 | foreach ($array as $value) | 
| 555 | 580 |  		{ | 
| 556 | - if (!is_array($value) || !isset($value['name'])) | |
| 557 | - continue; | |
| 581 | +			if (!is_array($value) || !isset($value['name'])) { | |
| 582 | + continue; | |
| 583 | + } | |
| 558 | 584 | |
| 559 | - if ($value['name'] == '!') | |
| 560 | - $text .= $value['value']; | |
| 561 | - else | |
| 562 | - $return[$value['name']] = $this->_array($value); | |
| 585 | +			if ($value['name'] == '!') { | |
| 586 | + $text .= $value['value']; | |
| 587 | +			} else { | |
| 588 | + $return[$value['name']] = $this->_array($value); | |
| 589 | + } | |
| 563 | 590 | } | 
| 564 | 591 | |
| 565 | - if (empty($return)) | |
| 566 | - return $text; | |
| 567 | - else | |
| 568 | - return $return; | |
| 592 | +		if (empty($return)) { | |
| 593 | + return $text; | |
| 594 | +		} else { | |
| 595 | + return $return; | |
| 596 | + } | |
| 569 | 597 | } | 
| 570 | 598 | |
| 571 | 599 | /** | 
| @@ -583,24 +611,28 @@ discard block | ||
| 583 | 611 | foreach ($parts as $part) | 
| 584 | 612 |  		{ | 
| 585 | 613 | // Handle XML comments. | 
| 586 | - if (!$inCdata && $part === '<!--') | |
| 587 | - $inComment = true; | |
| 588 | - if ($inComment && $part === '-->') | |
| 589 | - $inComment = false; | |
| 590 | - elseif ($inComment) | |
| 591 | - continue; | |
| 614 | +			if (!$inCdata && $part === '<!--') { | |
| 615 | + $inComment = true; | |
| 616 | + } | |
| 617 | +			if ($inComment && $part === '-->') { | |
| 618 | + $inComment = false; | |
| 619 | +			} elseif ($inComment) { | |
| 620 | + continue; | |
| 621 | + } | |
| 592 | 622 | |
| 593 | 623 | // Handle Cdata blocks. | 
| 594 | - elseif (!$inComment && $part === '<![CDATA[') | |
| 595 | - $inCdata = true; | |
| 596 | - elseif ($inCdata && $part === ']]>') | |
| 597 | - $inCdata = false; | |
| 598 | - elseif ($inCdata) | |
| 599 | - $output .= htmlentities($part, ENT_QUOTES); | |
| 624 | +			elseif (!$inComment && $part === '<![CDATA[') { | |
| 625 | + $inCdata = true; | |
| 626 | +			} elseif ($inCdata && $part === ']]>') { | |
| 627 | + $inCdata = false; | |
| 628 | +			} elseif ($inCdata) { | |
| 629 | + $output .= htmlentities($part, ENT_QUOTES); | |
| 630 | + } | |
| 600 | 631 | |
| 601 | 632 | // Everything else is kept as is. | 
| 602 | - else | |
| 603 | - $output .= $part; | |
| 633 | +			else { | |
| 634 | + $output .= $part; | |
| 635 | + } | |
| 604 | 636 | } | 
| 605 | 637 | |
| 606 | 638 | return $output; | 
| @@ -635,22 +667,26 @@ discard block | ||
| 635 | 667 | protected function _fetch($array) | 
| 636 | 668 |  	{ | 
| 637 | 669 | // Don't return anything if this is just a string. | 
| 638 | - if (is_string($array)) | |
| 639 | - return ''; | |
| 670 | +		if (is_string($array)) { | |
| 671 | + return ''; | |
| 672 | + } | |
| 640 | 673 | |
| 641 | 674 | $temp = ''; | 
| 642 | 675 | foreach ($array as $text) | 
| 643 | 676 |  		{ | 
| 644 | 677 | // This means it's most likely an attribute or the name itself. | 
| 645 | - if (!isset($text['name'])) | |
| 646 | - continue; | |
| 678 | +			if (!isset($text['name'])) { | |
| 679 | + continue; | |
| 680 | + } | |
| 647 | 681 | |
| 648 | 682 | // This is text! | 
| 649 | - if ($text['name'] == '!') | |
| 650 | - $temp .= $text['value']; | |
| 683 | +			if ($text['name'] == '!') { | |
| 684 | + $temp .= $text['value']; | |
| 685 | + } | |
| 651 | 686 | // Another element - dive in ;). | 
| 652 | - else | |
| 653 | - $temp .= $this->_fetch($text); | |
| 687 | +			else { | |
| 688 | + $temp .= $this->_fetch($text); | |
| 689 | + } | |
| 654 | 690 | } | 
| 655 | 691 | |
| 656 | 692 | // Return all the bits and pieces we've put together. | 
| @@ -669,12 +705,14 @@ discard block | ||
| 669 | 705 | protected function _path($array, $path, $level, $no_error = false) | 
| 670 | 706 |  	{ | 
| 671 | 707 | // Is $array even an array? It might be false! | 
| 672 | - if (!is_array($array)) | |
| 673 | - return false; | |
| 708 | +		if (!is_array($array)) { | |
| 709 | + return false; | |
| 710 | + } | |
| 674 | 711 | |
| 675 | 712 | // Asking for *no* path? | 
| 676 | - if ($path == '' || $path == '.') | |
| 677 | - return $array; | |
| 713 | +		if ($path == '' || $path == '.') { | |
| 714 | + return $array; | |
| 715 | + } | |
| 678 | 716 |  		$paths = explode('|', $path); | 
| 679 | 717 | |
| 680 | 718 | // A * means all elements of any name. | 
| @@ -685,16 +723,18 @@ discard block | ||
| 685 | 723 | // Check each element. | 
| 686 | 724 | foreach ($array as $value) | 
| 687 | 725 |  		{ | 
| 688 | - if (!is_array($value) || $value['name'] === '!') | |
| 689 | - continue; | |
| 726 | +			if (!is_array($value) || $value['name'] === '!') { | |
| 727 | + continue; | |
| 728 | + } | |
| 690 | 729 | |
| 691 | 730 | if ($show_all || in_array($value['name'], $paths)) | 
| 692 | 731 |  			{ | 
| 693 | 732 | // Skip elements before "the one". | 
| 694 | - if ($level !== null && $level > 0) | |
| 695 | - $level--; | |
| 696 | - else | |
| 697 | - $results[] = $value; | |
| 733 | +				if ($level !== null && $level > 0) { | |
| 734 | + $level--; | |
| 735 | +				} else { | |
| 736 | + $results[] = $value; | |
| 737 | + } | |
| 698 | 738 | } | 
| 699 | 739 | } | 
| 700 | 740 | |
| @@ -703,21 +743,25 @@ discard block | ||
| 703 | 743 |  		{ | 
| 704 | 744 | $trace = debug_backtrace(); | 
| 705 | 745 | $i = 0; | 
| 706 | - while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) | |
| 707 | - $i++; | |
| 746 | +			while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) { | |
| 747 | + $i++; | |
| 748 | + } | |
| 708 | 749 | $debug = ' from ' . $trace[$i - 1]['file'] . ' on line ' . $trace[$i - 1]['line']; | 
| 709 | 750 | |
| 710 | 751 | // Cause an error. | 
| 711 | - if ($this->debug_level & E_NOTICE && !$no_error) | |
| 712 | -				trigger_error('Undefined XML element: ' . $path . $debug, E_USER_NOTICE); | |
| 752 | +			if ($this->debug_level & E_NOTICE && !$no_error) { | |
| 753 | +							trigger_error('Undefined XML element: ' . $path . $debug, E_USER_NOTICE); | |
| 754 | + } | |
| 713 | 755 | return false; | 
| 714 | 756 | } | 
| 715 | 757 | // Only one result. | 
| 716 | - elseif (count($results) == 1 || $level !== null) | |
| 717 | - return $results[0]; | |
| 758 | +		elseif (count($results) == 1 || $level !== null) { | |
| 759 | + return $results[0]; | |
| 760 | + } | |
| 718 | 761 | // Return the result set. | 
| 719 | - else | |
| 720 | -			return $results + array('name' => $path . '[]'); | |
| 762 | +		else { | |
| 763 | +					return $results + array('name' => $path . '[]'); | |
| 764 | + } | |
| 721 | 765 | } | 
| 722 | 766 | } | 
| 723 | 767 | |
| @@ -764,8 +808,9 @@ discard block | ||
| 764 | 808 | $this->error = false; | 
| 765 | 809 | $this->pasv = array(); | 
| 766 | 810 | |
| 767 | - if ($ftp_server !== null) | |
| 768 | - $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass); | |
| 811 | +		if ($ftp_server !== null) { | |
| 812 | + $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass); | |
| 813 | + } | |
| 769 | 814 | } | 
| 770 | 815 | |
| 771 | 816 | /** | 
| @@ -778,14 +823,16 @@ discard block | ||
| 778 | 823 | */ | 
| 779 | 824 | public function connect($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = '[email protected]') | 
| 780 | 825 |  	{ | 
| 781 | - if (strpos($ftp_server, 'ftp://') === 0) | |
| 782 | - $ftp_server = substr($ftp_server, 6); | |
| 783 | - elseif (strpos($ftp_server, 'ftps://') === 0) | |
| 784 | - $ftp_server = 'ssl://' . substr($ftp_server, 7); | |
| 785 | - if (strpos($ftp_server, 'http://') === 0) | |
| 786 | - $ftp_server = substr($ftp_server, 7); | |
| 787 | - elseif (strpos($ftp_server, 'https://') === 0) | |
| 788 | - $ftp_server = substr($ftp_server, 8); | |
| 826 | +		if (strpos($ftp_server, 'ftp://') === 0) { | |
| 827 | + $ftp_server = substr($ftp_server, 6); | |
| 828 | +		} elseif (strpos($ftp_server, 'ftps://') === 0) { | |
| 829 | + $ftp_server = 'ssl://' . substr($ftp_server, 7); | |
| 830 | + } | |
| 831 | +		if (strpos($ftp_server, 'http://') === 0) { | |
| 832 | + $ftp_server = substr($ftp_server, 7); | |
| 833 | +		} elseif (strpos($ftp_server, 'https://') === 0) { | |
| 834 | + $ftp_server = substr($ftp_server, 8); | |
| 835 | + } | |
| 789 | 836 |  		$ftp_server = strtr($ftp_server, array('/' => '', ':' => '', '@' => '')); | 
| 790 | 837 | |
| 791 | 838 | // Connect to the FTP server. | 
| @@ -834,12 +881,14 @@ discard block | ||
| 834 | 881 | */ | 
| 835 | 882 | public function chdir($ftp_path) | 
| 836 | 883 |  	{ | 
| 837 | - if (!is_resource($this->connection)) | |
| 838 | - return false; | |
| 884 | +		if (!is_resource($this->connection)) { | |
| 885 | + return false; | |
| 886 | + } | |
| 839 | 887 | |
| 840 | 888 | // No slash on the end, please... | 
| 841 | - if ($ftp_path !== '/' && substr($ftp_path, -1) === '/') | |
| 842 | - $ftp_path = substr($ftp_path, 0, -1); | |
| 889 | +		if ($ftp_path !== '/' && substr($ftp_path, -1) === '/') { | |
| 890 | + $ftp_path = substr($ftp_path, 0, -1); | |
| 891 | + } | |
| 843 | 892 | |
| 844 | 893 | fwrite($this->connection, 'CWD ' . $ftp_path . "\r\n"); | 
| 845 | 894 | if (!$this->check_response(250)) | 
| @@ -860,11 +909,13 @@ discard block | ||
| 860 | 909 | */ | 
| 861 | 910 | public function chmod($ftp_file, $chmod) | 
| 862 | 911 |  	{ | 
| 863 | - if (!is_resource($this->connection)) | |
| 864 | - return false; | |
| 912 | +		if (!is_resource($this->connection)) { | |
| 913 | + return false; | |
| 914 | + } | |
| 865 | 915 | |
| 866 | - if ($ftp_file == '') | |
| 867 | - $ftp_file = '.'; | |
| 916 | +		if ($ftp_file == '') { | |
| 917 | + $ftp_file = '.'; | |
| 918 | + } | |
| 868 | 919 | |
| 869 | 920 | // Do we have a file or a dir? | 
| 870 | 921 | $is_dir = is_dir($ftp_file); | 
| @@ -880,9 +931,7 @@ discard block | ||
| 880 | 931 |  			{ | 
| 881 | 932 | $is_writable = true; | 
| 882 | 933 | break; | 
| 883 | - } | |
| 884 | - | |
| 885 | - else | |
| 934 | + } else | |
| 886 | 935 |  			{ | 
| 887 | 936 |  				// Convert the chmod value from octal (0777) to text ("777"). | 
| 888 | 937 | fwrite($this->connection, 'SITE CHMOD ' . decoct($val) . ' ' . $ftp_file . "\r\n"); | 
| @@ -905,8 +954,9 @@ discard block | ||
| 905 | 954 | public function unlink($ftp_file) | 
| 906 | 955 |  	{ | 
| 907 | 956 | // We are actually connected, right? | 
| 908 | - if (!is_resource($this->connection)) | |
| 909 | - return false; | |
| 957 | +		if (!is_resource($this->connection)) { | |
| 958 | + return false; | |
| 959 | + } | |
| 910 | 960 | |
| 911 | 961 | // Delete file X. | 
| 912 | 962 | fwrite($this->connection, 'DELE ' . $ftp_file . "\r\n"); | 
| @@ -935,9 +985,9 @@ discard block | ||
| 935 | 985 |  	{ | 
| 936 | 986 | // Wait for a response that isn't continued with -, but don't wait too long. | 
| 937 | 987 | $time = time(); | 
| 938 | - do | |
| 939 | - $this->last_message = fgets($this->connection, 1024); | |
| 940 | - while ((strlen($this->last_message) < 4 || strpos($this->last_message, ' ') === 0 || strpos($this->last_message, ' ', 3) !== 3) && time() - $time < 5); | |
| 988 | +		do { | |
| 989 | + $this->last_message = fgets($this->connection, 1024); | |
| 990 | + } while ((strlen($this->last_message) < 4 || strpos($this->last_message, ' ') === 0 || strpos($this->last_message, ' ', 3) !== 3) && time() - $time < 5); | |
| 941 | 991 | |
| 942 | 992 | // Was the desired response returned? | 
| 943 | 993 | return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired; | 
| @@ -951,15 +1001,16 @@ discard block | ||
| 951 | 1001 | public function passive() | 
| 952 | 1002 |  	{ | 
| 953 | 1003 | // We can't create a passive data connection without a primary one first being there. | 
| 954 | - if (!is_resource($this->connection)) | |
| 955 | - return false; | |
| 1004 | +		if (!is_resource($this->connection)) { | |
| 1005 | + return false; | |
| 1006 | + } | |
| 956 | 1007 | |
| 957 | 1008 | // Request a passive connection - this means, we'll talk to you, you don't talk to us. | 
| 958 | 1009 | @fwrite($this->connection, 'PASV' . "\r\n"); | 
| 959 | 1010 | $time = time(); | 
| 960 | - do | |
| 961 | - $response = fgets($this->connection, 1024); | |
| 962 | - while (strpos($response, ' ', 3) !== 3 && time() - $time < 5); | |
| 1011 | +		do { | |
| 1012 | + $response = fgets($this->connection, 1024); | |
| 1013 | + } while (strpos($response, ' ', 3) !== 3 && time() - $time < 5); | |
| 963 | 1014 | |
| 964 | 1015 | // If it's not 227, we weren't given an IP and port, which means it failed. | 
| 965 | 1016 | if (strpos($response, '227 ') !== 0) | 
| @@ -990,12 +1041,14 @@ discard block | ||
| 990 | 1041 | public function create_file($ftp_file) | 
| 991 | 1042 |  	{ | 
| 992 | 1043 | // First, we have to be connected... very important. | 
| 993 | - if (!is_resource($this->connection)) | |
| 994 | - return false; | |
| 1044 | +		if (!is_resource($this->connection)) { | |
| 1045 | + return false; | |
| 1046 | + } | |
| 995 | 1047 | |
| 996 | 1048 | // I'd like one passive mode, please! | 
| 997 | - if (!$this->passive()) | |
| 998 | - return false; | |
| 1049 | +		if (!$this->passive()) { | |
| 1050 | + return false; | |
| 1051 | + } | |
| 999 | 1052 | |
| 1000 | 1053 | // Seems logical enough, so far... | 
| 1001 | 1054 | fwrite($this->connection, 'STOR ' . $ftp_file . "\r\n"); | 
| @@ -1030,12 +1083,14 @@ discard block | ||
| 1030 | 1083 | public function list_dir($ftp_path = '', $search = false) | 
| 1031 | 1084 |  	{ | 
| 1032 | 1085 | // Are we even connected...? | 
| 1033 | - if (!is_resource($this->connection)) | |
| 1034 | - return false; | |
| 1086 | +		if (!is_resource($this->connection)) { | |
| 1087 | + return false; | |
| 1088 | + } | |
| 1035 | 1089 | |
| 1036 | 1090 | // Passive... non-agressive... | 
| 1037 | - if (!$this->passive()) | |
| 1038 | - return false; | |
| 1091 | +		if (!$this->passive()) { | |
| 1092 | + return false; | |
| 1093 | + } | |
| 1039 | 1094 | |
| 1040 | 1095 | // Get the listing! | 
| 1041 | 1096 | fwrite($this->connection, 'LIST -1' . ($search ? 'R' : '') . ($ftp_path == '' ? '' : ' ' . $ftp_path) . "\r\n"); | 
| @@ -1051,8 +1106,9 @@ discard block | ||
| 1051 | 1106 | |
| 1052 | 1107 | // Read in the file listing. | 
| 1053 | 1108 | $data = ''; | 
| 1054 | - while (!feof($fp)) | |
| 1055 | - $data .= fread($fp, 4096); | |
| 1109 | +		while (!feof($fp)) { | |
| 1110 | + $data .= fread($fp, 4096); | |
| 1111 | + } | |
| 1056 | 1112 | fclose($fp); | 
| 1057 | 1113 | |
| 1058 | 1114 | // Everything go okay? | 
| @@ -1074,21 +1130,23 @@ discard block | ||
| 1074 | 1130 | */ | 
| 1075 | 1131 | public function locate($file, $listing = null) | 
| 1076 | 1132 |  	{ | 
| 1077 | - if ($listing === null) | |
| 1078 | -			$listing = $this->list_dir('', true); | |
| 1133 | +		if ($listing === null) { | |
| 1134 | +					$listing = $this->list_dir('', true); | |
| 1135 | + } | |
| 1079 | 1136 |  		$listing = explode("\n", $listing); | 
| 1080 | 1137 | |
| 1081 | 1138 | @fwrite($this->connection, 'PWD' . "\r\n"); | 
| 1082 | 1139 | $time = time(); | 
| 1083 | - do | |
| 1084 | - $response = fgets($this->connection, 1024); | |
| 1085 | - while ($response[3] != ' ' && time() - $time < 5); | |
| 1140 | +		do { | |
| 1141 | + $response = fgets($this->connection, 1024); | |
| 1142 | + } while ($response[3] != ' ' && time() - $time < 5); | |
| 1086 | 1143 | |
| 1087 | 1144 | // Check for 257! | 
| 1088 | -		if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0) | |
| 1089 | -			$current_dir = strtr($match[1], array('""' => '"')); | |
| 1090 | - else | |
| 1091 | - $current_dir = ''; | |
| 1145 | +		if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0) { | |
| 1146 | +					$current_dir = strtr($match[1], array('""' => '"')); | |
| 1147 | +		} else { | |
| 1148 | + $current_dir = ''; | |
| 1149 | + } | |
| 1092 | 1150 | |
| 1093 | 1151 | for ($i = 0, $n = count($listing); $i < $n; $i++) | 
| 1094 | 1152 |  		{ | 
| @@ -1101,12 +1159,15 @@ discard block | ||
| 1101 | 1159 | // Okay, this file's name is: | 
| 1102 | 1160 | $listing[$i] = $current_dir . '/' . trim(strlen($listing[$i]) > 30 ? strrchr($listing[$i], ' ') : $listing[$i]); | 
| 1103 | 1161 | |
| 1104 | - if ($file[0] == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1)) | |
| 1105 | - return $listing[$i]; | |
| 1106 | - if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1)) | |
| 1107 | - return $listing[$i]; | |
| 1108 | - if (basename($listing[$i]) == $file || $listing[$i] == $file) | |
| 1109 | - return $listing[$i]; | |
| 1162 | +			if ($file[0] == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1)) { | |
| 1163 | + return $listing[$i]; | |
| 1164 | + } | |
| 1165 | +			if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1)) { | |
| 1166 | + return $listing[$i]; | |
| 1167 | + } | |
| 1168 | +			if (basename($listing[$i]) == $file || $listing[$i] == $file) { | |
| 1169 | + return $listing[$i]; | |
| 1170 | + } | |
| 1110 | 1171 | } | 
| 1111 | 1172 | |
| 1112 | 1173 | return false; | 
| @@ -1121,8 +1182,9 @@ discard block | ||
| 1121 | 1182 | public function create_dir($ftp_dir) | 
| 1122 | 1183 |  	{ | 
| 1123 | 1184 | // We must be connected to the server to do something. | 
| 1124 | - if (!is_resource($this->connection)) | |
| 1125 | - return false; | |
| 1185 | +		if (!is_resource($this->connection)) { | |
| 1186 | + return false; | |
| 1187 | + } | |
| 1126 | 1188 | |
| 1127 | 1189 | // Make this new beautiful directory! | 
| 1128 | 1190 | fwrite($this->connection, 'MKD ' . $ftp_dir . "\r\n"); | 
| @@ -1154,35 +1216,40 @@ discard block | ||
| 1154 | 1216 | |
| 1155 | 1217 |  				$path = strtr($_SERVER['DOCUMENT_ROOT'], array('/home/' . $match[1] . '/' => '', '/home2/' . $match[1] . '/' => '')); | 
| 1156 | 1218 | |
| 1157 | - if (substr($path, -1) == '/') | |
| 1158 | - $path = substr($path, 0, -1); | |
| 1219 | +				if (substr($path, -1) == '/') { | |
| 1220 | + $path = substr($path, 0, -1); | |
| 1221 | + } | |
| 1159 | 1222 | |
| 1160 | - if (strlen(dirname($_SERVER['PHP_SELF'])) > 1) | |
| 1161 | - $path .= dirname($_SERVER['PHP_SELF']); | |
| 1223 | +				if (strlen(dirname($_SERVER['PHP_SELF'])) > 1) { | |
| 1224 | + $path .= dirname($_SERVER['PHP_SELF']); | |
| 1225 | + } | |
| 1226 | +			} elseif (strpos($filesystem_path, '/var/www/') === 0) { | |
| 1227 | + $path = substr($filesystem_path, 8); | |
| 1228 | +			} else { | |
| 1229 | +							$path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => '')); | |
| 1162 | 1230 | } | 
| 1163 | - elseif (strpos($filesystem_path, '/var/www/') === 0) | |
| 1164 | - $path = substr($filesystem_path, 8); | |
| 1165 | - else | |
| 1166 | -				$path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => '')); | |
| 1231 | +		} else { | |
| 1232 | + $path = ''; | |
| 1167 | 1233 | } | 
| 1168 | - else | |
| 1169 | - $path = ''; | |
| 1170 | 1234 | |
| 1171 | 1235 | if (is_resource($this->connection) && $this->list_dir($path) == '') | 
| 1172 | 1236 |  		{ | 
| 1173 | 1237 |  			$data = $this->list_dir('', true); | 
| 1174 | 1238 | |
| 1175 | - if ($lookup_file === null) | |
| 1176 | - $lookup_file = $_SERVER['PHP_SELF']; | |
| 1239 | +			if ($lookup_file === null) { | |
| 1240 | + $lookup_file = $_SERVER['PHP_SELF']; | |
| 1241 | + } | |
| 1177 | 1242 | |
| 1178 | 1243 |  			$found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data)); | 
| 1179 | - if ($found_path == false) | |
| 1180 | - $found_path = dirname($this->locate(basename($lookup_file))); | |
| 1181 | - if ($found_path != false) | |
| 1182 | - $path = $found_path; | |
| 1244 | +			if ($found_path == false) { | |
| 1245 | + $found_path = dirname($this->locate(basename($lookup_file))); | |
| 1246 | + } | |
| 1247 | +			if ($found_path != false) { | |
| 1248 | + $path = $found_path; | |
| 1249 | + } | |
| 1250 | +		} elseif (is_resource($this->connection)) { | |
| 1251 | + $found_path = true; | |
| 1183 | 1252 | } | 
| 1184 | - elseif (is_resource($this->connection)) | |
| 1185 | - $found_path = true; | |
| 1186 | 1253 | |
| 1187 | 1254 | return array($username, $path, isset($found_path)); | 
| 1188 | 1255 | } | 
| @@ -56,6 +56,7 @@ discard block | ||
| 56 | 56 | * @param array $wordsSearch Search words | 
| 57 | 57 | * @param array $wordsExclude Words to exclude | 
| 58 | 58 | * @param bool $isExcluded Whether the specfied word should be excluded | 
| 59 | + * @return void | |
| 59 | 60 | */ | 
| 60 | 61 | public function prepareIndexes($word, array &$wordsSearch, array &$wordsExclude, $isExcluded); | 
| 61 | 62 | |
| @@ -130,7 +131,7 @@ discard block | ||
| 130 | 131 | * @param array $excludedIndexWords Indexed words that should be excluded | 
| 131 | 132 | * @param array $participants | 
| 132 | 133 | * @param array $searchArray | 
| 133 | - * @return mixed | |
| 134 | + * @return integer | |
| 134 | 135 | */ | 
| 135 | 136 | public function searchQuery(array $query_params, array $searchWords, array $excludedIndexWords, array &$participants, array &$searchArray); | 
| 136 | 137 | } | 
| @@ -279,7 +279,7 @@ discard block | ||
| 279 | 279 | /** | 
| 280 | 280 | * Generate the timestamp for the calculation | 
| 281 | 281 | * | 
| 282 | - * @return integer Timestamp | |
| 282 | + * @return double Timestamp | |
| 283 | 283 | */ | 
| 284 | 284 | public function generateTimestamp() | 
| 285 | 285 |  	{ | 
| @@ -290,7 +290,7 @@ discard block | ||
| 290 | 290 | * Truncate the given hash down to just what we need | 
| 291 | 291 | * | 
| 292 | 292 | * @param string $hash Hash to truncate | 
| 293 | - * @return string Truncated hash value | |
| 293 | + * @return integer Truncated hash value | |
| 294 | 294 | */ | 
| 295 | 295 | public function truncateHash($hash) | 
| 296 | 296 |  	{ | 
| @@ -382,7 +382,7 @@ | ||
| 382 | 382 | * @param array $parameters Not used? | 
| 383 | 383 | * @param string $if_exists What to do if the index exists. If 'update', the definition will be updated. | 
| 384 | 384 | * @param string $error | 
| 385 | - * @return boolean Whether or not the operation was successful | |
| 385 | + * @return false|null Whether or not the operation was successful | |
| 386 | 386 | */ | 
| 387 | 387 | function smf_db_add_index($table_name, $index_info, $parameters = array(), $if_exists = 'update', $error = 'fatal') | 
| 388 | 388 |  { | 
| @@ -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'); | 
| @@ -105,8 +107,9 @@ discard block | ||
| 105 | 107 |  	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name); | 
| 106 | 108 | |
| 107 | 109 | // First - no way do we touch SMF tables. | 
| 108 | - if (in_array(strtolower($table_name), $reservedTables)) | |
| 109 | - return false; | |
| 110 | +	if (in_array(strtolower($table_name), $reservedTables)) { | |
| 111 | + return false; | |
| 112 | + } | |
| 110 | 113 | |
| 111 | 114 | // Log that we'll want to remove this on uninstall. | 
| 112 | 115 |  	$db_package_log[] = array('remove_table', $table_name); | 
| @@ -116,16 +119,18 @@ discard block | ||
| 116 | 119 | if (in_array($full_table_name, $tables)) | 
| 117 | 120 |  	{ | 
| 118 | 121 | // This is a sad day... drop the table? If not, return false (error) by default. | 
| 119 | - if ($if_exists == 'overwrite') | |
| 120 | - $smcFunc['db_drop_table']($table_name); | |
| 121 | - else | |
| 122 | - return $if_exists == 'ignore'; | |
| 122 | +		if ($if_exists == 'overwrite') { | |
| 123 | + $smcFunc['db_drop_table']($table_name); | |
| 124 | +		} else { | |
| 125 | + return $if_exists == 'ignore'; | |
| 126 | + } | |
| 123 | 127 | } | 
| 124 | 128 | |
| 125 | 129 | // Righty - let's do the damn thing! | 
| 126 | 130 |  	$table_query = 'CREATE TABLE ' . $table_name . "\n" . '('; | 
| 127 | - foreach ($columns as $column) | |
| 128 | - $table_query .= "\n\t" . smf_db_create_query_column($column) . ','; | |
| 131 | +	foreach ($columns as $column) { | |
| 132 | + $table_query .= "\n\t" . smf_db_create_query_column($column) . ','; | |
| 133 | + } | |
| 129 | 134 | |
| 130 | 135 | // Loop through the indexes next... | 
| 131 | 136 | foreach ($indexes as $index) | 
| @@ -133,19 +138,21 @@ discard block | ||
| 133 | 138 |  		$columns = implode(',', $index['columns']); | 
| 134 | 139 | |
| 135 | 140 | // Is it the primary? | 
| 136 | - if (isset($index['type']) && $index['type'] == 'primary') | |
| 137 | -			$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; | |
| 138 | - else | |
| 141 | +		if (isset($index['type']) && $index['type'] == 'primary') { | |
| 142 | +					$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; | |
| 143 | + } else | |
| 139 | 144 |  		{ | 
| 140 | - if (empty($index['name'])) | |
| 141 | -				$index['name'] = implode('_', $index['columns']); | |
| 145 | +			if (empty($index['name'])) { | |
| 146 | +							$index['name'] = implode('_', $index['columns']); | |
| 147 | + } | |
| 142 | 148 |  			$table_query .= "\n\t" . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : 'KEY') . ' ' . $index['name'] . ' (' . $columns . '),'; | 
| 143 | 149 | } | 
| 144 | 150 | } | 
| 145 | 151 | |
| 146 | 152 | // No trailing commas! | 
| 147 | - if (substr($table_query, -1) == ',') | |
| 148 | - $table_query = substr($table_query, 0, -1); | |
| 153 | +	if (substr($table_query, -1) == ',') { | |
| 154 | + $table_query = substr($table_query, 0, -1); | |
| 155 | + } | |
| 149 | 156 | |
| 150 | 157 | // Which engine do we want here? | 
| 151 | 158 | if (empty($engines)) | 
| @@ -155,8 +162,9 @@ discard block | ||
| 155 | 162 | |
| 156 | 163 | while ($row = $smcFunc['db_fetch_assoc']($get_engines)) | 
| 157 | 164 |  		{ | 
| 158 | - if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') | |
| 159 | - $engines[] = $row['Engine']; | |
| 165 | +			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') { | |
| 166 | + $engines[] = $row['Engine']; | |
| 167 | + } | |
| 160 | 168 | } | 
| 161 | 169 | |
| 162 | 170 | $smcFunc['db_free_result']($get_engines); | 
| @@ -170,8 +178,9 @@ discard block | ||
| 170 | 178 | } | 
| 171 | 179 | |
| 172 | 180 | $table_query .= ') ENGINE=' . $parameters['engine']; | 
| 173 | - if (!empty($db_character_set) && $db_character_set == 'utf8') | |
| 174 | - $table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; | |
| 181 | +	if (!empty($db_character_set) && $db_character_set == 'utf8') { | |
| 182 | + $table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; | |
| 183 | + } | |
| 175 | 184 | |
| 176 | 185 | // Create the table! | 
| 177 | 186 |  	$smcFunc['db_query']('', $table_query, | 
| @@ -203,8 +212,9 @@ discard block | ||
| 203 | 212 |  	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name); | 
| 204 | 213 | |
| 205 | 214 | // God no - dropping one of these = bad. | 
| 206 | - if (in_array(strtolower($table_name), $reservedTables)) | |
| 207 | - return false; | |
| 215 | +	if (in_array(strtolower($table_name), $reservedTables)) { | |
| 216 | + return false; | |
| 217 | + } | |
| 208 | 218 | |
| 209 | 219 | // Does it exist? | 
| 210 | 220 | if (in_array($full_table_name, $smcFunc['db_list_tables']())) | 
| @@ -245,14 +255,16 @@ discard block | ||
| 245 | 255 | |
| 246 | 256 | // Does it exist - if so don't add it again! | 
| 247 | 257 | $columns = $smcFunc['db_list_columns']($table_name, false); | 
| 248 | - foreach ($columns as $column) | |
| 249 | - if ($column == $column_info['name']) | |
| 258 | +	foreach ($columns as $column) { | |
| 259 | + if ($column == $column_info['name']) | |
| 250 | 260 |  		{ | 
| 251 | 261 | // If we're going to overwrite then use change column. | 
| 252 | 262 | if ($if_exists == 'update') | 
| 253 | 263 | return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); | 
| 254 | - else | |
| 255 | - return false; | |
| 264 | + } | |
| 265 | +			else { | |
| 266 | + return false; | |
| 267 | + } | |
| 256 | 268 | } | 
| 257 | 269 | |
| 258 | 270 | // Get the specifics... | 
| @@ -288,8 +300,8 @@ discard block | ||
| 288 | 300 | |
| 289 | 301 | // Does it exist? | 
| 290 | 302 | $columns = $smcFunc['db_list_columns']($table_name, true); | 
| 291 | - foreach ($columns as $column) | |
| 292 | - if ($column['name'] == $column_name) | |
| 303 | +	foreach ($columns as $column) { | |
| 304 | + if ($column['name'] == $column_name) | |
| 293 | 305 |  		{ | 
| 294 | 306 |  			$smcFunc['db_query']('', ' | 
| 295 | 307 | ALTER TABLE ' . $table_name . ' | 
| @@ -298,6 +310,7 @@ discard block | ||
| 298 | 310 | 'security_override' => true, | 
| 299 | 311 | ) | 
| 300 | 312 | ); | 
| 313 | + } | |
| 301 | 314 | |
| 302 | 315 | return true; | 
| 303 | 316 | } | 
| @@ -324,37 +337,47 @@ discard block | ||
| 324 | 337 | // Check it does exist! | 
| 325 | 338 | $columns = $smcFunc['db_list_columns']($table_name, true); | 
| 326 | 339 | $old_info = null; | 
| 327 | - foreach ($columns as $column) | |
| 328 | - if ($column['name'] == $old_column) | |
| 340 | +	foreach ($columns as $column) { | |
| 341 | + if ($column['name'] == $old_column) | |
| 329 | 342 | $old_info = $column; | 
| 343 | + } | |
| 330 | 344 | |
| 331 | 345 | // Nothing? | 
| 332 | - if ($old_info == null) | |
| 333 | - return false; | |
| 346 | +	if ($old_info == null) { | |
| 347 | + return false; | |
| 348 | + } | |
| 334 | 349 | |
| 335 | 350 | // Get the right bits. | 
| 336 | - if (!isset($column_info['name'])) | |
| 337 | - $column_info['name'] = $old_column; | |
| 338 | - if (!isset($column_info['default'])) | |
| 339 | - $column_info['default'] = $old_info['default']; | |
| 340 | - if (!isset($column_info['null'])) | |
| 341 | - $column_info['null'] = $old_info['null']; | |
| 342 | - if (!isset($column_info['auto'])) | |
| 343 | - $column_info['auto'] = $old_info['auto']; | |
| 344 | - if (!isset($column_info['type'])) | |
| 345 | - $column_info['type'] = $old_info['type']; | |
| 346 | - if (!isset($column_info['size']) || !is_numeric($column_info['size'])) | |
| 347 | - $column_info['size'] = $old_info['size']; | |
| 348 | -	if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) | |
| 349 | - $column_info['unsigned'] = ''; | |
| 351 | +	if (!isset($column_info['name'])) { | |
| 352 | + $column_info['name'] = $old_column; | |
| 353 | + } | |
| 354 | +	if (!isset($column_info['default'])) { | |
| 355 | + $column_info['default'] = $old_info['default']; | |
| 356 | + } | |
| 357 | +	if (!isset($column_info['null'])) { | |
| 358 | + $column_info['null'] = $old_info['null']; | |
| 359 | + } | |
| 360 | +	if (!isset($column_info['auto'])) { | |
| 361 | + $column_info['auto'] = $old_info['auto']; | |
| 362 | + } | |
| 363 | +	if (!isset($column_info['type'])) { | |
| 364 | + $column_info['type'] = $old_info['type']; | |
| 365 | + } | |
| 366 | +	if (!isset($column_info['size']) || !is_numeric($column_info['size'])) { | |
| 367 | + $column_info['size'] = $old_info['size']; | |
| 368 | + } | |
| 369 | +	if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) { | |
| 370 | + $column_info['unsigned'] = ''; | |
| 371 | + } | |
| 350 | 372 | |
| 351 | 373 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']); | 
| 352 | 374 | |
| 353 | 375 | // Allow for unsigned integers (mysql only) | 
| 354 | 376 |  	$unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column_info['unsigned']) ? 'unsigned ' : ''; | 
| 355 | 377 | |
| 356 | - if ($size !== null) | |
| 357 | -		$type = $type . '(' . $size . ')'; | |
| 378 | +	if ($size !== null) { | |
| 379 | +			$type = $type . '(' . $size . ')'; | |
| 380 | + } | |
| 358 | 381 | |
| 359 | 382 |  	$smcFunc['db_query']('', ' | 
| 360 | 383 | ALTER TABLE ' . $table_name . ' | 
| @@ -384,21 +407,23 @@ discard block | ||
| 384 | 407 |  	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name); | 
| 385 | 408 | |
| 386 | 409 | // No columns = no index. | 
| 387 | - if (empty($index_info['columns'])) | |
| 388 | - return false; | |
| 410 | +	if (empty($index_info['columns'])) { | |
| 411 | + return false; | |
| 412 | + } | |
| 389 | 413 |  	$columns = implode(',', $index_info['columns']); | 
| 390 | 414 | |
| 391 | 415 | // No name - make it up! | 
| 392 | 416 | if (empty($index_info['name'])) | 
| 393 | 417 |  	{ | 
| 394 | 418 | // No need for primary. | 
| 395 | - if (isset($index_info['type']) && $index_info['type'] == 'primary') | |
| 396 | - $index_info['name'] = ''; | |
| 397 | - else | |
| 398 | -			$index_info['name'] = implode('_', $index_info['columns']); | |
| 419 | +		if (isset($index_info['type']) && $index_info['type'] == 'primary') { | |
| 420 | + $index_info['name'] = ''; | |
| 421 | +		} else { | |
| 422 | +					$index_info['name'] = implode('_', $index_info['columns']); | |
| 423 | + } | |
| 424 | +	} else { | |
| 425 | + $index_info['name'] = $index_info['name']; | |
| 399 | 426 | } | 
| 400 | - else | |
| 401 | - $index_info['name'] = $index_info['name']; | |
| 402 | 427 | |
| 403 | 428 | // Log that we are going to want to remove this! | 
| 404 | 429 |  	$db_package_log[] = array('remove_index', $table_name, $index_info['name']); | 
| @@ -411,10 +436,11 @@ discard block | ||
| 411 | 436 | if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary')) | 
| 412 | 437 |  		{ | 
| 413 | 438 | // If we want to overwrite simply remove the current one then continue. | 
| 414 | - if ($if_exists != 'update' || $index['type'] == 'primary') | |
| 415 | - return false; | |
| 416 | - else | |
| 417 | - $smcFunc['db_remove_index']($table_name, $index_info['name']); | |
| 439 | +			if ($if_exists != 'update' || $index['type'] == 'primary') { | |
| 440 | + return false; | |
| 441 | +			} else { | |
| 442 | + $smcFunc['db_remove_index']($table_name, $index_info['name']); | |
| 443 | + } | |
| 418 | 444 | } | 
| 419 | 445 | } | 
| 420 | 446 | |
| @@ -428,8 +454,7 @@ discard block | ||
| 428 | 454 | 'security_override' => true, | 
| 429 | 455 | ) | 
| 430 | 456 | ); | 
| 431 | - } | |
| 432 | - else | |
| 457 | + } else | |
| 433 | 458 |  	{ | 
| 434 | 459 |  		$smcFunc['db_query']('', ' | 
| 435 | 460 | ALTER TABLE ' . $table_name . ' | 
| @@ -513,8 +538,7 @@ discard block | ||
| 513 | 538 | $types = array( | 
| 514 | 539 | 'inet' => 'varbinary', | 
| 515 | 540 | ); | 
| 516 | - } | |
| 517 | - else | |
| 541 | + } else | |
| 518 | 542 |  	{ | 
| 519 | 543 | $types = array( | 
| 520 | 544 | 'varbinary' => 'inet', | 
| @@ -528,16 +552,15 @@ discard block | ||
| 528 | 552 |  		{ | 
| 529 | 553 | $type_size = 16; | 
| 530 | 554 | $type_name = 'varbinary'; | 
| 531 | - } | |
| 532 | - elseif ($type_name == 'varbinary' && $reverse && $type_size == 16) | |
| 555 | + } elseif ($type_name == 'varbinary' && $reverse && $type_size == 16) | |
| 533 | 556 |  		{ | 
| 534 | 557 | $type_name = 'inet'; | 
| 535 | 558 | $type_size = null; | 
| 559 | +		} elseif ($type_name == 'varbinary') { | |
| 560 | + $type_name = 'varbinary'; | |
| 561 | +		} else { | |
| 562 | + $type_name = $types[$type_name]; | |
| 536 | 563 | } | 
| 537 | - elseif ($type_name == 'varbinary') | |
| 538 | - $type_name = 'varbinary'; | |
| 539 | - else | |
| 540 | - $type_name = $types[$type_name]; | |
| 541 | 564 | } | 
| 542 | 565 | |
| 543 | 566 | return array($type_name, $type_size); | 
| @@ -605,8 +628,7 @@ discard block | ||
| 605 | 628 | if (!$detail) | 
| 606 | 629 |  		{ | 
| 607 | 630 | $columns[] = $row['Field']; | 
| 608 | - } | |
| 609 | - else | |
| 631 | + } else | |
| 610 | 632 |  		{ | 
| 611 | 633 | // Is there an auto_increment? | 
| 612 | 634 | $auto = strpos($row['Extra'], 'auto_increment') !== false ? true : false; | 
| @@ -616,10 +638,10 @@ discard block | ||
| 616 | 638 |  			{ | 
| 617 | 639 | $type = $matches[1]; | 
| 618 | 640 | $size = $matches[2]; | 
| 619 | - if (!empty($matches[3]) && $matches[3] == 'unsigned') | |
| 620 | - $unsigned = true; | |
| 621 | - } | |
| 622 | - else | |
| 641 | +				if (!empty($matches[3]) && $matches[3] == 'unsigned') { | |
| 642 | + $unsigned = true; | |
| 643 | + } | |
| 644 | + } else | |
| 623 | 645 |  			{ | 
| 624 | 646 | $type = $row['Type']; | 
| 625 | 647 | $size = null; | 
| @@ -670,19 +692,20 @@ discard block | ||
| 670 | 692 | $indexes = array(); | 
| 671 | 693 | while ($row = $smcFunc['db_fetch_assoc']($result)) | 
| 672 | 694 |  	{ | 
| 673 | - if (!$detail) | |
| 674 | - $indexes[] = $row['Key_name']; | |
| 675 | - else | |
| 695 | +		if (!$detail) { | |
| 696 | + $indexes[] = $row['Key_name']; | |
| 697 | + } else | |
| 676 | 698 |  		{ | 
| 677 | 699 | // What is the type? | 
| 678 | - if ($row['Key_name'] == 'PRIMARY') | |
| 679 | - $type = 'primary'; | |
| 680 | - elseif (empty($row['Non_unique'])) | |
| 681 | - $type = 'unique'; | |
| 682 | - elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') | |
| 683 | - $type = 'fulltext'; | |
| 684 | - else | |
| 685 | - $type = 'index'; | |
| 700 | +			if ($row['Key_name'] == 'PRIMARY') { | |
| 701 | + $type = 'primary'; | |
| 702 | +			} elseif (empty($row['Non_unique'])) { | |
| 703 | + $type = 'unique'; | |
| 704 | +			} elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') { | |
| 705 | + $type = 'fulltext'; | |
| 706 | +			} else { | |
| 707 | + $type = 'index'; | |
| 708 | + } | |
| 686 | 709 | |
| 687 | 710 | // This is the first column we've seen? | 
| 688 | 711 | if (empty($indexes[$row['Key_name']])) | 
| @@ -695,10 +718,11 @@ discard block | ||
| 695 | 718 | } | 
| 696 | 719 | |
| 697 | 720 | // Is it a partial index? | 
| 698 | - if (!empty($row['Sub_part'])) | |
| 699 | -				$indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')'; | |
| 700 | - else | |
| 701 | - $indexes[$row['Key_name']]['columns'][] = $row['Column_name']; | |
| 721 | +			if (!empty($row['Sub_part'])) { | |
| 722 | +							$indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')'; | |
| 723 | +			} else { | |
| 724 | + $indexes[$row['Key_name']]['columns'][] = $row['Column_name']; | |
| 725 | + } | |
| 702 | 726 | } | 
| 703 | 727 | } | 
| 704 | 728 | $smcFunc['db_free_result']($result); | 
| @@ -720,11 +744,11 @@ discard block | ||
| 720 | 744 | if (!empty($column['auto'])) | 
| 721 | 745 |  	{ | 
| 722 | 746 | $default = 'auto_increment'; | 
| 747 | +	} elseif (isset($column['default']) && $column['default'] !== null) { | |
| 748 | + $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; | |
| 749 | +	} else { | |
| 750 | + $default = ''; | |
| 723 | 751 | } | 
| 724 | - elseif (isset($column['default']) && $column['default'] !== null) | |
| 725 | - $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; | |
| 726 | - else | |
| 727 | - $default = ''; | |
| 728 | 752 | |
| 729 | 753 | // Sort out the size... and stuff... | 
| 730 | 754 | $column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null; | 
| @@ -733,8 +757,9 @@ discard block | ||
| 733 | 757 | // Allow unsigned integers (mysql only) | 
| 734 | 758 |  	$unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column['unsigned']) ? 'unsigned ' : ''; | 
| 735 | 759 | |
| 736 | - if ($size !== null) | |
| 737 | -		$type = $type . '(' . $size . ')'; | |
| 760 | +	if ($size !== null) { | |
| 761 | +			$type = $type . '(' . $size . ')'; | |
| 762 | + } | |
| 738 | 763 | |
| 739 | 764 | // Now just put it together! | 
| 740 | 765 | return '`' . $column['name'] . '` ' . $type . ' ' . (!empty($unsigned) ? $unsigned : '') . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default; | 
| @@ -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 |  { | 
| @@ -393,7 +393,7 @@ discard block | ||
| 393 | 393 | * | 
| 394 | 394 | * @param int $id_draft The ID of the draft to delete | 
| 395 | 395 | * @param boolean $check Whether or not to check that the draft belongs to the current user | 
| 396 | - * @return boolean False if it couldn't be deleted (doesn't return anything otherwise) | |
| 396 | + * @return false|null False if it couldn't be deleted (doesn't return anything otherwise) | |
| 397 | 397 | */ | 
| 398 | 398 | function DeleteDraft($id_draft, $check = true) | 
| 399 | 399 |  { | 
| @@ -427,7 +427,7 @@ discard block | ||
| 427 | 427 | * @param int $member_id ID of the member to show drafts for | 
| 428 | 428 | * @param boolean|integer If $type is 1, this can be set to only load drafts for posts in the specific topic | 
| 429 | 429 | * @param int $draft_type The type of drafts to show - 0 for post drafts, 1 for PM drafts | 
| 430 | - * @return boolean False if the drafts couldn't be loaded, nothing otherwise | |
| 430 | + * @return false|null False if the drafts couldn't be loaded, nothing otherwise | |
| 431 | 431 | */ | 
| 432 | 432 | function ShowDrafts($member_id, $topic = false, $draft_type = 0) | 
| 433 | 433 |  { | 
| @@ -511,7 +511,7 @@ discard block | ||
| 511 | 511 | * Allows for the deleting and loading/editing of drafts | 
| 512 | 512 | * | 
| 513 | 513 | * @param type $memID | 
| 514 | - * @param type $draft_type | |
| 514 | + * @param integer $draft_type | |
| 515 | 515 | */ | 
| 516 | 516 | function showProfileDrafts($memID, $draft_type = 0) | 
| 517 | 517 |  { | 
| @@ -664,7 +664,7 @@ discard block | ||
| 664 | 664 | * Uses the showpmdraft template | 
| 665 | 665 | * Allows for the deleting and loading/editing of drafts | 
| 666 | 666 | * | 
| 667 | - * @param type $memID | |
| 667 | + * @param integer $memID | |
| 668 | 668 | */ | 
| 669 | 669 | function showPMDrafts($memID = -1) | 
| 670 | 670 |  { | 
| @@ -14,8 +14,9 @@ discard block | ||
| 14 | 14 | * @version 2.1 Beta 3 | 
| 15 | 15 | */ | 
| 16 | 16 | |
| 17 | -if (!defined('SMF')) | |
| 17 | +if (!defined('SMF')) { | |
| 18 | 18 |  	die('No direct access...'); | 
| 19 | +} | |
| 19 | 20 | |
| 20 | 21 |  loadLanguage('Drafts'); | 
| 21 | 22 | |
| @@ -33,8 +34,9 @@ discard block | ||
| 33 | 34 | global $context, $user_info, $smcFunc, $modSettings, $board; | 
| 34 | 35 | |
| 35 | 36 | // can you be, should you be ... here? | 
| 36 | -	if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft'])) | |
| 37 | - return false; | |
| 37 | +	if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft'])) { | |
| 38 | + return false; | |
| 39 | + } | |
| 38 | 40 | |
| 39 | 41 | // read in what they sent us, if anything | 
| 40 | 42 | $id_draft = (int) $_POST['id_draft']; | 
| @@ -46,14 +48,16 @@ discard block | ||
| 46 | 48 | $context['draft_saved_on'] = $draft_info['poster_time']; | 
| 47 | 49 | |
| 48 | 50 | // since we were called from the autosave function, send something back | 
| 49 | - if (!empty($id_draft)) | |
| 50 | - XmlDraft($id_draft); | |
| 51 | +		if (!empty($id_draft)) { | |
| 52 | + XmlDraft($id_draft); | |
| 53 | + } | |
| 51 | 54 | |
| 52 | 55 | return true; | 
| 53 | 56 | } | 
| 54 | 57 | |
| 55 | - if (!isset($_POST['message'])) | |
| 56 | - $_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : ''; | |
| 58 | +	if (!isset($_POST['message'])) { | |
| 59 | + $_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : ''; | |
| 60 | + } | |
| 57 | 61 | |
| 58 | 62 | // prepare any data from the form | 
| 59 | 63 | $topic_id = empty($_REQUEST['topic']) ? 0 : (int) $_REQUEST['topic']; | 
| @@ -66,8 +70,9 @@ discard block | ||
| 66 | 70 | |
| 67 | 71 | // message and subject still need a bit more work | 
| 68 | 72 | preparsecode($draft['body']); | 
| 69 | - if ($smcFunc['strlen']($draft['subject']) > 100) | |
| 70 | - $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); | |
| 73 | +	if ($smcFunc['strlen']($draft['subject']) > 100) { | |
| 74 | + $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); | |
| 75 | + } | |
| 71 | 76 | |
| 72 | 77 | // Modifying an existing draft, like hitting the save draft button or autosave enabled? | 
| 73 | 78 | if (!empty($id_draft) && !empty($draft_info)) | 
| @@ -148,9 +153,9 @@ discard block | ||
| 148 | 153 |  		{ | 
| 149 | 154 | $context['draft_saved'] = true; | 
| 150 | 155 | $context['id_draft'] = $id_draft; | 
| 156 | +		} else { | |
| 157 | + $post_errors[] = 'draft_not_saved'; | |
| 151 | 158 | } | 
| 152 | - else | |
| 153 | - $post_errors[] = 'draft_not_saved'; | |
| 154 | 159 | |
| 155 | 160 | // cleanup | 
| 156 | 161 | unset($_POST['save_draft']); | 
| @@ -180,8 +185,9 @@ discard block | ||
| 180 | 185 | global $context, $user_info, $smcFunc, $modSettings; | 
| 181 | 186 | |
| 182 | 187 | // PM survey says ... can you stay or must you go | 
| 183 | -	if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) | |
| 184 | - return false; | |
| 188 | +	if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) { | |
| 189 | + return false; | |
| 190 | + } | |
| 185 | 191 | |
| 186 | 192 | // read in what you sent us | 
| 187 | 193 | $id_pm_draft = (int) $_POST['id_pm_draft']; | 
| @@ -193,8 +199,9 @@ discard block | ||
| 193 | 199 | $context['draft_saved_on'] = $draft_info['poster_time']; | 
| 194 | 200 | |
| 195 | 201 | // Send something back to the javascript caller | 
| 196 | - if (!empty($id_draft)) | |
| 197 | - XmlDraft($id_draft); | |
| 202 | +		if (!empty($id_draft)) { | |
| 203 | + XmlDraft($id_draft); | |
| 204 | + } | |
| 198 | 205 | |
| 199 | 206 | return true; | 
| 200 | 207 | } | 
| @@ -204,9 +211,9 @@ discard block | ||
| 204 | 211 |  	{ | 
| 205 | 212 |  		$recipientList['to'] = isset($_POST['recipient_to']) ? explode(',', $_POST['recipient_to']) : array(); | 
| 206 | 213 |  		$recipientList['bcc'] = isset($_POST['recipient_bcc']) ? explode(',', $_POST['recipient_bcc']) : array(); | 
| 214 | +	} elseif (!empty($draft_info['to_list']) && empty($recipientList)) { | |
| 215 | + $recipientList = smf_json_decode($draft_info['to_list'], true); | |
| 207 | 216 | } | 
| 208 | - elseif (!empty($draft_info['to_list']) && empty($recipientList)) | |
| 209 | - $recipientList = smf_json_decode($draft_info['to_list'], true); | |
| 210 | 217 | |
| 211 | 218 | // prepare the data we got from the form | 
| 212 | 219 | $reply_id = empty($_POST['replied_to']) ? 0 : (int) $_POST['replied_to']; | 
| @@ -215,8 +222,9 @@ discard block | ||
| 215 | 222 | |
| 216 | 223 | // message and subject always need a bit more work | 
| 217 | 224 | preparsecode($draft['body']); | 
| 218 | - if ($smcFunc['strlen']($draft['subject']) > 100) | |
| 219 | - $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); | |
| 225 | +	if ($smcFunc['strlen']($draft['subject']) > 100) { | |
| 226 | + $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); | |
| 227 | + } | |
| 220 | 228 | |
| 221 | 229 | // Modifying an existing PM draft? | 
| 222 | 230 | if (!empty($id_pm_draft) && !empty($draft_info)) | 
| @@ -280,9 +288,9 @@ discard block | ||
| 280 | 288 |  		{ | 
| 281 | 289 | $context['draft_saved'] = true; | 
| 282 | 290 | $context['id_pm_draft'] = $id_pm_draft; | 
| 291 | +		} else { | |
| 292 | + $post_errors[] = 'draft_not_saved'; | |
| 283 | 293 | } | 
| 284 | - else | |
| 285 | - $post_errors[] = 'draft_not_saved'; | |
| 286 | 294 | } | 
| 287 | 295 | |
| 288 | 296 | // if we were called from the autosave function, send something back | 
| @@ -315,8 +323,9 @@ discard block | ||
| 315 | 323 | $type = (int) $type; | 
| 316 | 324 | |
| 317 | 325 | // nothing to read, nothing to do | 
| 318 | - if (empty($id_draft)) | |
| 319 | - return false; | |
| 326 | +	if (empty($id_draft)) { | |
| 327 | + return false; | |
| 328 | + } | |
| 320 | 329 | |
| 321 | 330 | // load in this draft from the DB | 
| 322 | 331 |  	$request = $smcFunc['db_query']('', ' | 
| @@ -337,8 +346,9 @@ discard block | ||
| 337 | 346 | ); | 
| 338 | 347 | |
| 339 | 348 | // no results? | 
| 340 | - if (!$smcFunc['db_num_rows']($request)) | |
| 341 | - return false; | |
| 349 | +	if (!$smcFunc['db_num_rows']($request)) { | |
| 350 | + return false; | |
| 351 | + } | |
| 342 | 352 | |
| 343 | 353 | // load up the data | 
| 344 | 354 | $draft_info = $smcFunc['db_fetch_assoc']($request); | 
| @@ -358,8 +368,7 @@ discard block | ||
| 358 | 368 | $context['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : ''; | 
| 359 | 369 | $context['board'] = !empty($draft_info['id_board']) ? $draft_info['id_board'] : ''; | 
| 360 | 370 | $context['id_draft'] = !empty($draft_info['id_draft']) ? $draft_info['id_draft'] : 0; | 
| 361 | - } | |
| 362 | - elseif ($type === 1) | |
| 371 | + } elseif ($type === 1) | |
| 363 | 372 |  		{ | 
| 364 | 373 | // one of those pm drafts? then set it up like we have an error | 
| 365 | 374 | $_REQUEST['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : ''; | 
| @@ -395,12 +404,14 @@ discard block | ||
| 395 | 404 | global $user_info, $smcFunc; | 
| 396 | 405 | |
| 397 | 406 | // Only a single draft. | 
| 398 | - if (is_numeric($id_draft)) | |
| 399 | - $id_draft = array($id_draft); | |
| 407 | +	if (is_numeric($id_draft)) { | |
| 408 | + $id_draft = array($id_draft); | |
| 409 | + } | |
| 400 | 410 | |
| 401 | 411 | // can't delete nothing | 
| 402 | - if (empty($id_draft) || ($check && empty($user_info['id']))) | |
| 403 | - return false; | |
| 412 | +	if (empty($id_draft) || ($check && empty($user_info['id']))) { | |
| 413 | + return false; | |
| 414 | + } | |
| 404 | 415 | |
| 405 | 416 |  	$smcFunc['db_query']('', ' | 
| 406 | 417 |  		DELETE FROM {db_prefix}user_drafts | 
| @@ -429,14 +440,16 @@ discard block | ||
| 429 | 440 | global $smcFunc, $scripturl, $context, $txt, $modSettings; | 
| 430 | 441 | |
| 431 | 442 | // Permissions | 
| 432 | - if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) | |
| 433 | - return false; | |
| 443 | +	if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) { | |
| 444 | + return false; | |
| 445 | + } | |
| 434 | 446 | |
| 435 | 447 | $context['drafts'] = array(); | 
| 436 | 448 | |
| 437 | 449 | // has a specific draft has been selected? Load it up if there is not a message already in the editor | 
| 438 | - if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) | |
| 439 | - ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true); | |
| 450 | +	if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) { | |
| 451 | + ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true); | |
| 452 | + } | |
| 440 | 453 | |
| 441 | 454 | // load the drafts this user has available | 
| 442 | 455 |  	$request = $smcFunc['db_query']('', ' | 
| @@ -459,8 +472,9 @@ discard block | ||
| 459 | 472 | // add them to the draft array for display | 
| 460 | 473 | while ($row = $smcFunc['db_fetch_assoc']($request)) | 
| 461 | 474 |  	{ | 
| 462 | - if (empty($row['subject'])) | |
| 463 | - $row['subject'] = $txt['no_subject']; | |
| 475 | +		if (empty($row['subject'])) { | |
| 476 | + $row['subject'] = $txt['no_subject']; | |
| 477 | + } | |
| 464 | 478 | |
| 465 | 479 | // Post drafts | 
| 466 | 480 | if ($draft_type === 0) | 
| @@ -545,8 +559,9 @@ discard block | ||
| 545 | 559 | } | 
| 546 | 560 | |
| 547 | 561 | // Default to 10. | 
| 548 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) | |
| 549 | - $_REQUEST['viewscount'] = 10; | |
| 562 | +	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { | |
| 563 | + $_REQUEST['viewscount'] = 10; | |
| 564 | + } | |
| 550 | 565 | |
| 551 | 566 | // Get the count of applicable drafts on the boards they can (still) see ... | 
| 552 | 567 | // @todo .. should we just let them see their drafts even if they have lost board access ? | 
| @@ -611,12 +626,14 @@ discard block | ||
| 611 | 626 | while ($row = $smcFunc['db_fetch_assoc']($request)) | 
| 612 | 627 |  	{ | 
| 613 | 628 | // Censor.... | 
| 614 | - if (empty($row['body'])) | |
| 615 | - $row['body'] = ''; | |
| 629 | +		if (empty($row['body'])) { | |
| 630 | + $row['body'] = ''; | |
| 631 | + } | |
| 616 | 632 | |
| 617 | 633 | $row['subject'] = $smcFunc['htmltrim']($row['subject']); | 
| 618 | - if (empty($row['subject'])) | |
| 619 | - $row['subject'] = $txt['no_subject']; | |
| 634 | +		if (empty($row['subject'])) { | |
| 635 | + $row['subject'] = $txt['no_subject']; | |
| 636 | + } | |
| 620 | 637 | |
| 621 | 638 | censorText($row['body']); | 
| 622 | 639 | censorText($row['subject']); | 
| @@ -648,8 +665,9 @@ discard block | ||
| 648 | 665 | $smcFunc['db_free_result']($request); | 
| 649 | 666 | |
| 650 | 667 | // If the drafts were retrieved in reverse order, get them right again. | 
| 651 | - if ($reverse) | |
| 652 | - $context['drafts'] = array_reverse($context['drafts'], true); | |
| 668 | +	if ($reverse) { | |
| 669 | + $context['drafts'] = array_reverse($context['drafts'], true); | |
| 670 | + } | |
| 653 | 671 | |
| 654 | 672 | // Menu tab | 
| 655 | 673 | $context[$context['profile_menu_name']]['tab_data'] = array( | 
| @@ -707,8 +725,9 @@ discard block | ||
| 707 | 725 | } | 
| 708 | 726 | |
| 709 | 727 | // Default to 10. | 
| 710 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) | |
| 711 | - $_REQUEST['viewscount'] = 10; | |
| 728 | +	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { | |
| 729 | + $_REQUEST['viewscount'] = 10; | |
| 730 | + } | |
| 712 | 731 | |
| 713 | 732 | // Get the count of applicable drafts | 
| 714 | 733 |  	$request = $smcFunc['db_query']('', ' | 
| @@ -767,12 +786,14 @@ discard block | ||
| 767 | 786 | while ($row = $smcFunc['db_fetch_assoc']($request)) | 
| 768 | 787 |  	{ | 
| 769 | 788 | // Censor.... | 
| 770 | - if (empty($row['body'])) | |
| 771 | - $row['body'] = ''; | |
| 789 | +		if (empty($row['body'])) { | |
| 790 | + $row['body'] = ''; | |
| 791 | + } | |
| 772 | 792 | |
| 773 | 793 | $row['subject'] = $smcFunc['htmltrim']($row['subject']); | 
| 774 | - if (empty($row['subject'])) | |
| 775 | - $row['subject'] = $txt['no_subject']; | |
| 794 | +		if (empty($row['subject'])) { | |
| 795 | + $row['subject'] = $txt['no_subject']; | |
| 796 | + } | |
| 776 | 797 | |
| 777 | 798 | censorText($row['body']); | 
| 778 | 799 | censorText($row['subject']); | 
| @@ -827,8 +848,9 @@ discard block | ||
| 827 | 848 | $smcFunc['db_free_result']($request); | 
| 828 | 849 | |
| 829 | 850 | // if the drafts were retrieved in reverse order, then put them in the right order again. | 
| 830 | - if ($reverse) | |
| 831 | - $context['drafts'] = array_reverse($context['drafts'], true); | |
| 851 | +	if ($reverse) { | |
| 852 | + $context['drafts'] = array_reverse($context['drafts'], true); | |
| 853 | + } | |
| 832 | 854 | |
| 833 | 855 | // off to the template we go | 
| 834 | 856 | $context['page_title'] = $txt['drafts']; | 
| @@ -475,7 +475,7 @@ | ||
| 475 | 475 | * Used by fatal_error(), fatal_lang_error() | 
| 476 | 476 | * | 
| 477 | 477 | * @param string $error The error | 
| 478 | - * @param array $sprintf An array of data to be sprintf()'d into the specified message | |
| 478 | + * @param boolean $sprintf An array of data to be sprintf()'d into the specified message | |
| 479 | 479 | */ | 
| 480 | 480 | function log_error_online($error, $sprintf = array()) | 
| 481 | 481 |  { | 
| @@ -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,8 +223,9 @@ 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 |  	{ | 
| @@ -221,19 +233,22 @@ discard block | ||
| 221 | 233 | $count = count($array); | 
| 222 | 234 | for ($i = 0; $i < $count; $i++) | 
| 223 | 235 |  		{ | 
| 224 | - if ($array[$i]['function'] != 'loadSubTemplate') | |
| 225 | - continue; | |
| 236 | +			if ($array[$i]['function'] != 'loadSubTemplate') { | |
| 237 | + continue; | |
| 238 | + } | |
| 226 | 239 | |
| 227 | 240 | // This is a bug in PHP, with eval, it seems! | 
| 228 | - if (empty($array[$i]['args'])) | |
| 229 | - $i++; | |
| 241 | +			if (empty($array[$i]['args'])) { | |
| 242 | + $i++; | |
| 243 | + } | |
| 230 | 244 | break; | 
| 231 | 245 | } | 
| 232 | 246 | |
| 233 | - if (isset($array[$i]) && !empty($array[$i]['args'])) | |
| 234 | -			$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)'; | |
| 235 | - else | |
| 236 | - $file = realpath($settings['current_include_filename']) . ' (eval?)'; | |
| 247 | +		if (isset($array[$i]) && !empty($array[$i]['args'])) { | |
| 248 | +					$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)'; | |
| 249 | +		} else { | |
| 250 | + $file = realpath($settings['current_include_filename']) . ' (eval?)'; | |
| 251 | + } | |
| 237 | 252 | } | 
| 238 | 253 | |
| 239 | 254 | if (isset($db_show_debug) && $db_show_debug === true) | 
| @@ -242,8 +257,9 @@ discard block | ||
| 242 | 257 | if ($error_level % 255 != E_ERROR) | 
| 243 | 258 |  		{ | 
| 244 | 259 | $temporary = ob_get_contents(); | 
| 245 | - if (substr($temporary, -2) == '="') | |
| 246 | - echo '"'; | |
| 260 | +			if (substr($temporary, -2) == '="') { | |
| 261 | + echo '"'; | |
| 262 | + } | |
| 247 | 263 | } | 
| 248 | 264 | |
| 249 | 265 | // Debugging! This should look like a PHP error message. | 
| @@ -259,23 +275,27 @@ discard block | ||
| 259 | 275 |  	call_integration_hook('integrate_output_error', array($message, $error_type, $error_level, $file, $line)); | 
| 260 | 276 | |
| 261 | 277 | // Dying on these errors only causes MORE problems (blank pages!) | 
| 262 | - if ($file == 'Unknown') | |
| 263 | - return; | |
| 278 | +	if ($file == 'Unknown') { | |
| 279 | + return; | |
| 280 | + } | |
| 264 | 281 | |
| 265 | 282 | // If this is an E_ERROR or E_USER_ERROR.... die. Violently so. | 
| 266 | - if ($error_level % 255 == E_ERROR) | |
| 267 | - obExit(false); | |
| 268 | - else | |
| 269 | - return; | |
| 283 | +	if ($error_level % 255 == E_ERROR) { | |
| 284 | + obExit(false); | |
| 285 | +	} else { | |
| 286 | + return; | |
| 287 | + } | |
| 270 | 288 | |
| 271 | 289 | // If this is an E_ERROR, E_USER_ERROR, E_WARNING, or E_USER_WARNING.... die. Violently so. | 
| 272 | - if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) | |
| 273 | -		fatal_error(allowedTo('admin_forum') ? $message : $error_string, false); | |
| 290 | +	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) { | |
| 291 | +			fatal_error(allowedTo('admin_forum') ? $message : $error_string, false); | |
| 292 | + } | |
| 274 | 293 | |
| 275 | 294 | // We should NEVER get to this point. Any fatal error MUST quit, or very bad things can happen. | 
| 276 | - if ($error_level % 255 == E_ERROR) | |
| 277 | -		die('No direct access...'); | |
| 278 | -} | |
| 295 | +	if ($error_level % 255 == E_ERROR) { | |
| 296 | +			die('No direct access...'); | |
| 297 | + } | |
| 298 | + } | |
| 279 | 299 | |
| 280 | 300 | /** | 
| 281 | 301 |   * It is called by {@link fatal_error()} and {@link fatal_lang_error()}. | 
| @@ -291,24 +311,28 @@ discard block | ||
| 291 | 311 | |
| 292 | 312 | // Attempt to prevent a recursive loop. | 
| 293 | 313 | ++$level; | 
| 294 | - if ($level > 1) | |
| 295 | - return false; | |
| 314 | +	if ($level > 1) { | |
| 315 | + return false; | |
| 316 | + } | |
| 296 | 317 | |
| 297 | 318 | // Maybe they came from dlattach or similar? | 
| 298 | - if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) | |
| 299 | - loadTheme(); | |
| 319 | +	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) { | |
| 320 | + loadTheme(); | |
| 321 | + } | |
| 300 | 322 | |
| 301 | 323 | // Don't bother indexing errors mate... | 
| 302 | 324 | $context['robot_no_index'] = true; | 
| 303 | 325 | |
| 304 | - if (!isset($context['error_title'])) | |
| 305 | - $context['error_title'] = $txt['error_occured']; | |
| 326 | +	if (!isset($context['error_title'])) { | |
| 327 | + $context['error_title'] = $txt['error_occured']; | |
| 328 | + } | |
| 306 | 329 | $context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message; | 
| 307 | 330 | |
| 308 | 331 | $context['error_code'] = isset($error_code) ? 'id="' . $error_code . '" ' : ''; | 
| 309 | 332 | |
| 310 | - if (empty($context['page_title'])) | |
| 311 | - $context['page_title'] = $context['error_title']; | |
| 333 | +	if (empty($context['page_title'])) { | |
| 334 | + $context['page_title'] = $context['error_title']; | |
| 335 | + } | |
| 312 | 336 | |
| 313 | 337 |  	loadTemplate('Errors'); | 
| 314 | 338 | $context['sub_template'] = 'fatal_error'; | 
| @@ -316,23 +340,26 @@ discard block | ||
| 316 | 340 | // If this is SSI, what do they want us to do? | 
| 317 | 341 | if (SMF == 'SSI') | 
| 318 | 342 |  	{ | 
| 319 | - if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) | |
| 320 | - $ssi_on_error_method(); | |
| 321 | - elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) | |
| 322 | -			loadSubTemplate('fatal_error'); | |
| 343 | +		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) { | |
| 344 | + $ssi_on_error_method(); | |
| 345 | +		} elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) { | |
| 346 | +					loadSubTemplate('fatal_error'); | |
| 347 | + } | |
| 323 | 348 | |
| 324 | 349 | // No layers? | 
| 325 | - if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) | |
| 326 | - exit; | |
| 350 | +		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) { | |
| 351 | + exit; | |
| 352 | + } | |
| 327 | 353 | } | 
| 328 | 354 | // Alternatively from the cron call? | 
| 329 | 355 | elseif (SMF == 'BACKGROUND') | 
| 330 | 356 |  	{ | 
| 331 | 357 | // We can't rely on even having language files available. | 
| 332 | -		if (defined('FROM_CLI') && FROM_CLI) | |
| 333 | - echo 'cron error: ', $context['error_message']; | |
| 334 | - else | |
| 335 | - echo 'An error occurred. More information may be available in your logs.'; | |
| 358 | +		if (defined('FROM_CLI') && FROM_CLI) { | |
| 359 | + echo 'cron error: ', $context['error_message']; | |
| 360 | +		} else { | |
| 361 | + echo 'An error occurred. More information may be available in your logs.'; | |
| 362 | + } | |
| 336 | 363 | exit; | 
| 337 | 364 | } | 
| 338 | 365 | |
| @@ -360,8 +387,8 @@ discard block | ||
| 360 | 387 | |
| 361 | 388 | set_fatal_error_headers(); | 
| 362 | 389 | |
| 363 | - if (!empty($maintenance)) | |
| 364 | - echo '<!DOCTYPE html> | |
| 390 | +	if (!empty($maintenance)) { | |
| 391 | + echo '<!DOCTYPE html> | |
| 365 | 392 | <html> | 
| 366 | 393 | <head> | 
| 367 | 394 | <meta name="robots" content="noindex"> | 
| @@ -372,6 +399,7 @@ discard block | ||
| 372 | 399 | ', $mmessage, ' | 
| 373 | 400 | </body> | 
| 374 | 401 | </html>'; | 
| 402 | + } | |
| 375 | 403 | |
| 376 | 404 | die(); | 
| 377 | 405 | } | 
| @@ -393,15 +421,17 @@ discard block | ||
| 393 | 421 | // For our purposes, we're gonna want this on if at all possible. | 
| 394 | 422 | $modSettings['cache_enable'] = '1'; | 
| 395 | 423 | |
| 396 | -	if (($temp = cache_get_data('db_last_error', 600)) !== null) | |
| 397 | - $db_last_error = max($db_last_error, $temp); | |
| 424 | +	if (($temp = cache_get_data('db_last_error', 600)) !== null) { | |
| 425 | + $db_last_error = max($db_last_error, $temp); | |
| 426 | + } | |
| 398 | 427 | |
| 399 | 428 | if ($db_last_error < time() - 3600 * 24 * 3 && empty($maintenance) && !empty($db_error_send)) | 
| 400 | 429 |  	{ | 
| 401 | 430 | // Avoid writing to the Settings.php file if at all possible; use shared memory instead. | 
| 402 | 431 |  		cache_put_data('db_last_error', time(), 600); | 
| 403 | -		if (($temp = cache_get_data('db_last_error', 600)) === null) | |
| 404 | - logLastDatabaseError(); | |
| 432 | +		if (($temp = cache_get_data('db_last_error', 600)) === null) { | |
| 433 | + logLastDatabaseError(); | |
| 434 | + } | |
| 405 | 435 | |
| 406 | 436 | // Language files aren't loaded yet :(. | 
| 407 | 437 | $db_error = @$smcFunc['db_error']($db_connection); | 
| @@ -482,12 +512,14 @@ discard block | ||
| 482 | 512 | global $smcFunc, $user_info, $modSettings; | 
| 483 | 513 | |
| 484 | 514 | // Don't bother if Who's Online is disabled. | 
| 485 | - if (empty($modSettings['who_enabled'])) | |
| 486 | - return; | |
| 515 | +	if (empty($modSettings['who_enabled'])) { | |
| 516 | + return; | |
| 517 | + } | |
| 487 | 518 | |
| 488 | 519 | // Maybe they came from SSI or similar where sessions are not recorded? | 
| 489 | - if (SMF == 'SSI' || SMF == 'BACKGROUND') | |
| 490 | - return; | |
| 520 | +	if (SMF == 'SSI' || SMF == 'BACKGROUND') { | |
| 521 | + return; | |
| 522 | + } | |
| 491 | 523 | |
| 492 | 524 | $session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id(); | 
| 493 | 525 | |
| @@ -506,8 +538,9 @@ discard block | ||
| 506 | 538 | $url = smf_json_decode($url, true); | 
| 507 | 539 | $url['error'] = $error; | 
| 508 | 540 | |
| 509 | - if (!empty($sprintf)) | |
| 510 | - $url['error_params'] = $sprintf; | |
| 541 | +		if (!empty($sprintf)) { | |
| 542 | + $url['error_params'] = $sprintf; | |
| 543 | + } | |
| 511 | 544 | |
| 512 | 545 |  		$smcFunc['db_query']('', ' | 
| 513 | 546 |  			UPDATE {db_prefix}log_online | 
| @@ -538,10 +571,11 @@ discard block | ||
| 538 | 571 | |
| 539 | 572 |  	$protocol = preg_match('~HTTP/1\.[01]~i', $_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'; | 
| 540 | 573 | |
| 541 | - if (!isset($statuses[$code])) | |
| 542 | - header($protocol . ' 500 Internal Server Error'); | |
| 543 | - else | |
| 544 | - header($protocol . ' ' . $code . ' ' . $statuses[$code]); | |
| 545 | -} | |
| 574 | +	if (!isset($statuses[$code])) { | |
| 575 | + header($protocol . ' 500 Internal Server Error'); | |
| 576 | +	} else { | |
| 577 | + header($protocol . ' ' . $code . ' ' . $statuses[$code]); | |
| 578 | + } | |
| 579 | + } | |
| 546 | 580 | |
| 547 | 581 | ?> | 
| 548 | 582 | \ No newline at end of file | 
| @@ -929,7 +929,7 @@ discard block | ||
| 929 | 929 | * Doesn't clean the inputs | 
| 930 | 930 | * | 
| 931 | 931 | * @param array $items_ids The items to remove | 
| 932 | - * @param bool|int $group_id The ID of the group these triggers are associated with or false if deleting them from all groups | |
| 932 | + * @param integer $group_id The ID of the group these triggers are associated with or false if deleting them from all groups | |
| 933 | 933 | * @return bool Always returns true | 
| 934 | 934 | */ | 
| 935 | 935 | function removeBanTriggers($items_ids = array(), $group_id = false) | 
| @@ -1123,7 +1123,7 @@ discard block | ||
| 1123 | 1123 | * Errors in $context['ban_errors'] | 
| 1124 | 1124 | * | 
| 1125 | 1125 | * @param array $triggers The triggers to validate | 
| 1126 | - * @return array An array of riggers and log info ready to be used | |
| 1126 | + * @return integer An array of riggers and log info ready to be used | |
| 1127 | 1127 | */ | 
| 1128 | 1128 | function validateTriggers(&$triggers) | 
| 1129 | 1129 |  { | 
| @@ -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 | /** | 
| @@ -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(); | 
| @@ -900,10 +914,11 @@ discard block | ||
| 900 | 914 | |
| 901 | 915 | foreach ($suggestions as $key => $value) | 
| 902 | 916 |  	{ | 
| 903 | - if (is_array($value)) | |
| 904 | - $triggers[$key] = $value; | |
| 905 | - else | |
| 906 | - $triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : ''; | |
| 917 | +		if (is_array($value)) { | |
| 918 | + $triggers[$key] = $value; | |
| 919 | +		} else { | |
| 920 | + $triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : ''; | |
| 921 | + } | |
| 907 | 922 | } | 
| 908 | 923 | |
| 909 | 924 | $ban_triggers = validateTriggers($triggers); | 
| @@ -911,16 +926,18 @@ discard block | ||
| 911 | 926 | // Time to save! | 
| 912 | 927 | if (!empty($ban_triggers['ban_triggers']) && empty($context['ban_errors'])) | 
| 913 | 928 |  	{ | 
| 914 | - if (empty($ban_id)) | |
| 915 | - addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']); | |
| 916 | - else | |
| 917 | - updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']); | |
| 929 | +		if (empty($ban_id)) { | |
| 930 | + addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']); | |
| 931 | +		} else { | |
| 932 | + updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']); | |
| 933 | + } | |
| 934 | + } | |
| 935 | +	if (!empty($context['ban_errors'])) { | |
| 936 | + return $triggers; | |
| 937 | +	} else { | |
| 938 | + return false; | |
| 939 | + } | |
| 918 | 940 | } | 
| 919 | - if (!empty($context['ban_errors'])) | |
| 920 | - return $triggers; | |
| 921 | - else | |
| 922 | - return false; | |
| 923 | -} | |
| 924 | 941 | |
| 925 | 942 | /** | 
| 926 | 943 | * This function removes a bunch of triggers based on ids | 
| @@ -934,14 +951,17 @@ discard block | ||
| 934 | 951 |  { | 
| 935 | 952 | global $smcFunc, $scripturl; | 
| 936 | 953 | |
| 937 | - if ($group_id !== false) | |
| 938 | - $group_id = (int) $group_id; | |
| 954 | +	if ($group_id !== false) { | |
| 955 | + $group_id = (int) $group_id; | |
| 956 | + } | |
| 939 | 957 | |
| 940 | - if (empty($group_id) && empty($items_ids)) | |
| 941 | - return false; | |
| 958 | +	if (empty($group_id) && empty($items_ids)) { | |
| 959 | + return false; | |
| 960 | + } | |
| 942 | 961 | |
| 943 | - if (!is_array($items_ids)) | |
| 944 | - $items_ids = array($items_ids); | |
| 962 | +	if (!is_array($items_ids)) { | |
| 963 | + $items_ids = array($items_ids); | |
| 964 | + } | |
| 945 | 965 | |
| 946 | 966 | $log_info = array(); | 
| 947 | 967 | $ban_items = array(); | 
| @@ -979,8 +999,7 @@ discard block | ||
| 979 | 999 | 'bantype' => ($is_range ? 'ip_range' : 'main_ip'), | 
| 980 | 1000 | 'value' => $ban_items[$row['id_ban']]['ip'], | 
| 981 | 1001 | ); | 
| 982 | - } | |
| 983 | - elseif (!empty($row['hostname'])) | |
| 1002 | + } elseif (!empty($row['hostname'])) | |
| 984 | 1003 |  			{ | 
| 985 | 1004 | $ban_items[$row['id_ban']]['type'] = 'hostname'; | 
| 986 | 1005 |  				$ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']); | 
| @@ -988,8 +1007,7 @@ discard block | ||
| 988 | 1007 | 'bantype' => 'hostname', | 
| 989 | 1008 | 'value' => $row['hostname'], | 
| 990 | 1009 | ); | 
| 991 | - } | |
| 992 | - elseif (!empty($row['email_address'])) | |
| 1010 | + } elseif (!empty($row['email_address'])) | |
| 993 | 1011 |  			{ | 
| 994 | 1012 | $ban_items[$row['id_ban']]['type'] = 'email'; | 
| 995 | 1013 |  				$ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']); | 
| @@ -997,8 +1015,7 @@ discard block | ||
| 997 | 1015 | 'bantype' => 'email', | 
| 998 | 1016 | 'value' => $ban_items[$row['id_ban']]['email'], | 
| 999 | 1017 | ); | 
| 1000 | - } | |
| 1001 | - elseif (!empty($row['id_member'])) | |
| 1018 | + } elseif (!empty($row['id_member'])) | |
| 1002 | 1019 |  			{ | 
| 1003 | 1020 | $ban_items[$row['id_ban']]['type'] = 'user'; | 
| 1004 | 1021 | $ban_items[$row['id_ban']]['user'] = array( | 
| @@ -1031,8 +1048,7 @@ discard block | ||
| 1031 | 1048 | 'ban_group' => $group_id, | 
| 1032 | 1049 | ) | 
| 1033 | 1050 | ); | 
| 1034 | - } | |
| 1035 | - elseif (!empty($items_ids)) | |
| 1051 | + } elseif (!empty($items_ids)) | |
| 1036 | 1052 |  	{ | 
| 1037 | 1053 |  		$smcFunc['db_query']('', ' | 
| 1038 | 1054 |  			DELETE FROM {db_prefix}ban_items | 
| @@ -1057,13 +1073,15 @@ discard block | ||
| 1057 | 1073 |  { | 
| 1058 | 1074 | global $smcFunc; | 
| 1059 | 1075 | |
| 1060 | - if (!is_array($group_ids)) | |
| 1061 | - $group_ids = array($group_ids); | |
| 1076 | +	if (!is_array($group_ids)) { | |
| 1077 | + $group_ids = array($group_ids); | |
| 1078 | + } | |
| 1062 | 1079 | |
| 1063 | 1080 | $group_ids = array_unique($group_ids); | 
| 1064 | 1081 | |
| 1065 | - if (empty($group_ids)) | |
| 1066 | - return false; | |
| 1082 | +	if (empty($group_ids)) { | |
| 1083 | + return false; | |
| 1084 | + } | |
| 1067 | 1085 | |
| 1068 | 1086 |  	$smcFunc['db_query']('', ' | 
| 1069 | 1087 |  		DELETE FROM {db_prefix}ban_groups | 
| @@ -1087,21 +1105,23 @@ discard block | ||
| 1087 | 1105 |  { | 
| 1088 | 1106 | global $smcFunc; | 
| 1089 | 1107 | |
| 1090 | - if (empty($ids)) | |
| 1091 | -		$smcFunc['db_query']('truncate_table', ' | |
| 1108 | +	if (empty($ids)) { | |
| 1109 | +			$smcFunc['db_query']('truncate_table', ' | |
| 1092 | 1110 |  			TRUNCATE {db_prefix}log_banned', | 
| 1093 | 1111 | array( | 
| 1094 | 1112 | ) | 
| 1095 | 1113 | ); | 
| 1096 | - else | |
| 1114 | + } else | |
| 1097 | 1115 |  	{ | 
| 1098 | - if (!is_array($ids)) | |
| 1099 | - $ids = array($ids); | |
| 1116 | +		if (!is_array($ids)) { | |
| 1117 | + $ids = array($ids); | |
| 1118 | + } | |
| 1100 | 1119 | |
| 1101 | 1120 | $ids = array_unique($ids); | 
| 1102 | 1121 | |
| 1103 | - if (empty($ids)) | |
| 1104 | - return false; | |
| 1122 | +		if (empty($ids)) { | |
| 1123 | + return false; | |
| 1124 | + } | |
| 1105 | 1125 | |
| 1106 | 1126 |  		$smcFunc['db_query']('', ' | 
| 1107 | 1127 |  			DELETE FROM {db_prefix}log_banned | 
| @@ -1127,8 +1147,9 @@ discard block | ||
| 1127 | 1147 |  { | 
| 1128 | 1148 | global $context, $smcFunc; | 
| 1129 | 1149 | |
| 1130 | - if (empty($triggers)) | |
| 1131 | - $context['ban_erros'][] = 'ban_empty_triggers'; | |
| 1150 | +	if (empty($triggers)) { | |
| 1151 | + $context['ban_erros'][] = 'ban_empty_triggers'; | |
| 1152 | + } | |
| 1132 | 1153 | |
| 1133 | 1154 | $ban_triggers = array(); | 
| 1134 | 1155 | $log_info = array(); | 
| @@ -1137,39 +1158,39 @@ discard block | ||
| 1137 | 1158 |  	{ | 
| 1138 | 1159 | if (!empty($value)) | 
| 1139 | 1160 |  		{ | 
| 1140 | - if ($key == 'member') | |
| 1141 | - continue; | |
| 1161 | +			if ($key == 'member') { | |
| 1162 | + continue; | |
| 1163 | + } | |
| 1142 | 1164 | |
| 1143 | 1165 | if ($key == 'main_ip') | 
| 1144 | 1166 |  			{ | 
| 1145 | 1167 | $value = trim($value); | 
| 1146 | 1168 | $ip_parts = ip2range($value); | 
| 1147 | - if (!checkExistingTriggerIP($ip_parts, $value)) | |
| 1148 | - $context['ban_erros'][] = 'invalid_ip'; | |
| 1149 | - else | |
| 1169 | +				if (!checkExistingTriggerIP($ip_parts, $value)) { | |
| 1170 | + $context['ban_erros'][] = 'invalid_ip'; | |
| 1171 | + } else | |
| 1150 | 1172 |  				{ | 
| 1151 | 1173 | $ban_triggers['main_ip'] = array( | 
| 1152 | 1174 | 'ip_low' => $ip_parts['low'], | 
| 1153 | 1175 | 'ip_high' => $ip_parts['high'] | 
| 1154 | 1176 | ); | 
| 1155 | 1177 | } | 
| 1156 | - } | |
| 1157 | - elseif ($key == 'hostname') | |
| 1178 | + } elseif ($key == 'hostname') | |
| 1158 | 1179 |  			{ | 
| 1159 | -				if (preg_match('/[^\w.\-*]/', $value) == 1) | |
| 1160 | - $context['ban_erros'][] = 'invalid_hostname'; | |
| 1161 | - else | |
| 1180 | +				if (preg_match('/[^\w.\-*]/', $value) == 1) { | |
| 1181 | + $context['ban_erros'][] = 'invalid_hostname'; | |
| 1182 | + } else | |
| 1162 | 1183 |  				{ | 
| 1163 | 1184 | // Replace the * wildcard by a MySQL wildcard %. | 
| 1164 | 1185 |  					$value = substr(str_replace('*', '%', $value), 0, 255); | 
| 1165 | 1186 | |
| 1166 | 1187 | $ban_triggers['hostname']['hostname'] = $value; | 
| 1167 | 1188 | } | 
| 1168 | - } | |
| 1169 | - elseif ($key == 'email') | |
| 1189 | + } elseif ($key == 'email') | |
| 1170 | 1190 |  			{ | 
| 1171 | -				if (preg_match('/[^\w.\-\+*@]/', $value) == 1) | |
| 1172 | - $context['ban_erros'][] = 'invalid_email'; | |
| 1191 | +				if (preg_match('/[^\w.\-\+*@]/', $value) == 1) { | |
| 1192 | + $context['ban_erros'][] = 'invalid_email'; | |
| 1193 | + } | |
| 1173 | 1194 | |
| 1174 | 1195 | // Check the user is not banning an admin. | 
| 1175 | 1196 |  				$request = $smcFunc['db_query']('', ' | 
| @@ -1183,15 +1204,15 @@ discard block | ||
| 1183 | 1204 | 'email' => $value, | 
| 1184 | 1205 | ) | 
| 1185 | 1206 | ); | 
| 1186 | - if ($smcFunc['db_num_rows']($request) != 0) | |
| 1187 | - $context['ban_erros'][] = 'no_ban_admin'; | |
| 1207 | +				if ($smcFunc['db_num_rows']($request) != 0) { | |
| 1208 | + $context['ban_erros'][] = 'no_ban_admin'; | |
| 1209 | + } | |
| 1188 | 1210 | $smcFunc['db_free_result']($request); | 
| 1189 | 1211 | |
| 1190 | 1212 |  				$value = substr(strtolower(str_replace('*', '%', $value)), 0, 255); | 
| 1191 | 1213 | |
| 1192 | 1214 | $ban_triggers['email']['email_address'] = $value; | 
| 1193 | - } | |
| 1194 | - elseif ($key == 'user') | |
| 1215 | + } elseif ($key == 'user') | |
| 1195 | 1216 |  			{ | 
| 1196 | 1217 |  				$user = preg_replace('~&#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $smcFunc['htmlspecialchars']($value, ENT_QUOTES)); | 
| 1197 | 1218 | |
| @@ -1205,8 +1226,9 @@ discard block | ||
| 1205 | 1226 | 'username' => $user, | 
| 1206 | 1227 | ) | 
| 1207 | 1228 | ); | 
| 1208 | - if ($smcFunc['db_num_rows']($request) == 0) | |
| 1209 | - $context['ban_erros'][] = 'invalid_username'; | |
| 1229 | +				if ($smcFunc['db_num_rows']($request) == 0) { | |
| 1230 | + $context['ban_erros'][] = 'invalid_username'; | |
| 1231 | + } | |
| 1210 | 1232 | list ($value, $isAdmin) = $smcFunc['db_fetch_row']($request); | 
| 1211 | 1233 | $smcFunc['db_free_result']($request); | 
| 1212 | 1234 | |
| @@ -1214,25 +1236,25 @@ discard block | ||
| 1214 | 1236 |  				{ | 
| 1215 | 1237 | unset($value); | 
| 1216 | 1238 | $context['ban_erros'][] = 'no_ban_admin'; | 
| 1239 | +				} else { | |
| 1240 | + $ban_triggers['user']['id_member'] = $value; | |
| 1217 | 1241 | } | 
| 1218 | - else | |
| 1219 | - $ban_triggers['user']['id_member'] = $value; | |
| 1220 | - } | |
| 1221 | -			elseif (in_array($key, array('ips_in_messages', 'ips_in_errors'))) | |
| 1242 | +			} elseif (in_array($key, array('ips_in_messages', 'ips_in_errors'))) | |
| 1222 | 1243 |  			{ | 
| 1223 | 1244 | // Special case, those two are arrays themselves | 
| 1224 | 1245 | $values = array_unique($value); | 
| 1225 | 1246 | // Don't add the main IP again. | 
| 1226 | - if (isset($triggers['main_ip'])) | |
| 1227 | - $values = array_diff($values, array($triggers['main_ip'])); | |
| 1247 | +				if (isset($triggers['main_ip'])) { | |
| 1248 | + $values = array_diff($values, array($triggers['main_ip'])); | |
| 1249 | + } | |
| 1228 | 1250 | unset($value); | 
| 1229 | 1251 | foreach ($values as $val) | 
| 1230 | 1252 |  				{ | 
| 1231 | 1253 | $val = trim($val); | 
| 1232 | 1254 | $ip_parts = ip2range($val); | 
| 1233 | - if (!checkExistingTriggerIP($ip_parts, $val)) | |
| 1234 | - $context['ban_erros'][] = 'invalid_ip'; | |
| 1235 | - else | |
| 1255 | +					if (!checkExistingTriggerIP($ip_parts, $val)) { | |
| 1256 | + $context['ban_erros'][] = 'invalid_ip'; | |
| 1257 | + } else | |
| 1236 | 1258 |  					{ | 
| 1237 | 1259 | $ban_triggers[$key][] = array( | 
| 1238 | 1260 | 'ip_low' => $ip_parts['low'], | 
| @@ -1245,15 +1267,16 @@ discard block | ||
| 1245 | 1267 | ); | 
| 1246 | 1268 | } | 
| 1247 | 1269 | } | 
| 1270 | +			} else { | |
| 1271 | + $context['ban_erros'][] = 'no_bantype_selected'; | |
| 1248 | 1272 | } | 
| 1249 | - else | |
| 1250 | - $context['ban_erros'][] = 'no_bantype_selected'; | |
| 1251 | 1273 | |
| 1252 | - if (isset($value) && !is_array($value)) | |
| 1253 | - $log_info[] = array( | |
| 1274 | +			if (isset($value) && !is_array($value)) { | |
| 1275 | + $log_info[] = array( | |
| 1254 | 1276 | 'value' => $value, | 
| 1255 | 1277 | 'bantype' => $key, | 
| 1256 | 1278 | ); | 
| 1279 | + } | |
| 1257 | 1280 | } | 
| 1258 | 1281 | } | 
| 1259 | 1282 |  	return array('ban_triggers' => $ban_triggers, 'log_info' => $log_info); | 
| @@ -1273,8 +1296,9 @@ discard block | ||
| 1273 | 1296 |  { | 
| 1274 | 1297 | global $smcFunc, $context; | 
| 1275 | 1298 | |
| 1276 | - if (empty($group_id)) | |
| 1277 | - $context['ban_errors'][] = 'ban_id_empty'; | |
| 1299 | +	if (empty($group_id)) { | |
| 1300 | + $context['ban_errors'][] = 'ban_id_empty'; | |
| 1301 | + } | |
| 1278 | 1302 | |
| 1279 | 1303 | // Preset all values that are required. | 
| 1280 | 1304 | $values = array( | 
| @@ -1299,18 +1323,21 @@ discard block | ||
| 1299 | 1323 | foreach ($triggers as $key => $trigger) | 
| 1300 | 1324 |  	{ | 
| 1301 | 1325 | // Exceptions, exceptions, exceptions...always exceptions... :P | 
| 1302 | -		if (in_array($key, array('ips_in_messages', 'ips_in_errors'))) | |
| 1303 | - foreach ($trigger as $real_trigger) | |
| 1326 | +		if (in_array($key, array('ips_in_messages', 'ips_in_errors'))) { | |
| 1327 | + foreach ($trigger as $real_trigger) | |
| 1304 | 1328 | $insertTriggers[] = array_merge($values, $real_trigger); | 
| 1305 | - else | |
| 1306 | - $insertTriggers[] = array_merge($values, $trigger); | |
| 1329 | +		} else { | |
| 1330 | + $insertTriggers[] = array_merge($values, $trigger); | |
| 1331 | + } | |
| 1307 | 1332 | } | 
| 1308 | 1333 | |
| 1309 | - if (empty($insertTriggers)) | |
| 1310 | - $context['ban_errors'][] = 'ban_no_triggers'; | |
| 1334 | +	if (empty($insertTriggers)) { | |
| 1335 | + $context['ban_errors'][] = 'ban_no_triggers'; | |
| 1336 | + } | |
| 1311 | 1337 | |
| 1312 | - if (!empty($context['ban_errors'])) | |
| 1313 | - return false; | |
| 1338 | +	if (!empty($context['ban_errors'])) { | |
| 1339 | + return false; | |
| 1340 | + } | |
| 1314 | 1341 | |
| 1315 | 1342 |  	$smcFunc['db_insert']('', | 
| 1316 | 1343 |  		'{db_prefix}ban_items', | 
| @@ -1338,15 +1365,19 @@ discard block | ||
| 1338 | 1365 |  { | 
| 1339 | 1366 | global $smcFunc, $context; | 
| 1340 | 1367 | |
| 1341 | - if (empty($ban_item)) | |
| 1342 | - $context['ban_errors'][] = 'ban_ban_item_empty'; | |
| 1343 | - if (empty($group_id)) | |
| 1344 | - $context['ban_errors'][] = 'ban_id_empty'; | |
| 1345 | - if (empty($trigger)) | |
| 1346 | - $context['ban_errors'][] = 'ban_no_triggers'; | |
| 1368 | +	if (empty($ban_item)) { | |
| 1369 | + $context['ban_errors'][] = 'ban_ban_item_empty'; | |
| 1370 | + } | |
| 1371 | +	if (empty($group_id)) { | |
| 1372 | + $context['ban_errors'][] = 'ban_id_empty'; | |
| 1373 | + } | |
| 1374 | +	if (empty($trigger)) { | |
| 1375 | + $context['ban_errors'][] = 'ban_no_triggers'; | |
| 1376 | + } | |
| 1347 | 1377 | |
| 1348 | - if (!empty($context['ban_errors'])) | |
| 1349 | - return; | |
| 1378 | +	if (!empty($context['ban_errors'])) { | |
| 1379 | + return; | |
| 1380 | + } | |
| 1350 | 1381 | |
| 1351 | 1382 | // Preset all values that are required. | 
| 1352 | 1383 | $values = array( | 
| @@ -1387,8 +1418,9 @@ discard block | ||
| 1387 | 1418 | */ | 
| 1388 | 1419 | function logTriggersUpdates($logs, $new = true, $removal = false) | 
| 1389 | 1420 |  { | 
| 1390 | - if (empty($logs)) | |
| 1391 | - return; | |
| 1421 | +	if (empty($logs)) { | |
| 1422 | + return; | |
| 1423 | + } | |
| 1392 | 1424 | |
| 1393 | 1425 | $log_name_map = array( | 
| 1394 | 1426 | 'main_ip' => 'ip_range', | 
| @@ -1399,14 +1431,15 @@ discard block | ||
| 1399 | 1431 | ); | 
| 1400 | 1432 | |
| 1401 | 1433 | // Log the addion of the ban entries into the moderation log. | 
| 1402 | - foreach ($logs as $log) | |
| 1403 | -		logAction('ban' . ($removal == true ? 'remove' : ''), array( | |
| 1434 | +	foreach ($logs as $log) { | |
| 1435 | +			logAction('ban' . ($removal == true ? 'remove' : ''), array( | |
| 1404 | 1436 | $log_name_map[$log['bantype']] => $log['value'], | 
| 1405 | 1437 | 'new' => empty($new) ? 0 : 1, | 
| 1406 | 1438 | 'remove' => empty($removal) ? 0 : 1, | 
| 1407 | 1439 | 'type' => $log['bantype'], | 
| 1408 | 1440 | )); | 
| 1409 | -} | |
| 1441 | + } | |
| 1442 | + } | |
| 1410 | 1443 | |
| 1411 | 1444 | /** | 
| 1412 | 1445 | * Updates an existing ban group | 
| @@ -1420,12 +1453,15 @@ discard block | ||
| 1420 | 1453 |  { | 
| 1421 | 1454 | global $smcFunc, $context; | 
| 1422 | 1455 | |
| 1423 | - if (empty($ban_info['name'])) | |
| 1424 | - $context['ban_errors'][] = 'ban_name_empty'; | |
| 1425 | - if (empty($ban_info['id'])) | |
| 1426 | - $context['ban_errors'][] = 'ban_id_empty'; | |
| 1427 | - if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) | |
| 1428 | - $context['ban_errors'][] = 'ban_unknown_restriction_type'; | |
| 1456 | +	if (empty($ban_info['name'])) { | |
| 1457 | + $context['ban_errors'][] = 'ban_name_empty'; | |
| 1458 | + } | |
| 1459 | +	if (empty($ban_info['id'])) { | |
| 1460 | + $context['ban_errors'][] = 'ban_id_empty'; | |
| 1461 | + } | |
| 1462 | +	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) { | |
| 1463 | + $context['ban_errors'][] = 'ban_unknown_restriction_type'; | |
| 1464 | + } | |
| 1429 | 1465 | |
| 1430 | 1466 | if (!empty($ban_info['id'])) | 
| 1431 | 1467 |  	{ | 
| @@ -1440,8 +1476,9 @@ discard block | ||
| 1440 | 1476 | ) | 
| 1441 | 1477 | ); | 
| 1442 | 1478 | |
| 1443 | - if ($smcFunc['db_num_rows']($request) == 0) | |
| 1444 | - $context['ban_errors'][] = 'ban_not_found'; | |
| 1479 | +		if ($smcFunc['db_num_rows']($request) == 0) { | |
| 1480 | + $context['ban_errors'][] = 'ban_not_found'; | |
| 1481 | + } | |
| 1445 | 1482 | $smcFunc['db_free_result']($request); | 
| 1446 | 1483 | } | 
| 1447 | 1484 | |
| @@ -1459,13 +1496,15 @@ discard block | ||
| 1459 | 1496 | 'new_ban_name' => $ban_info['name'], | 
| 1460 | 1497 | ) | 
| 1461 | 1498 | ); | 
| 1462 | - if ($smcFunc['db_num_rows']($request) != 0) | |
| 1463 | - $context['ban_errors'][] = 'ban_name_exists'; | |
| 1499 | +		if ($smcFunc['db_num_rows']($request) != 0) { | |
| 1500 | + $context['ban_errors'][] = 'ban_name_exists'; | |
| 1501 | + } | |
| 1464 | 1502 | $smcFunc['db_free_result']($request); | 
| 1465 | 1503 | } | 
| 1466 | 1504 | |
| 1467 | - if (!empty($context['ban_errors'])) | |
| 1468 | - return $ban_info['id']; | |
| 1505 | +	if (!empty($context['ban_errors'])) { | |
| 1506 | + return $ban_info['id']; | |
| 1507 | + } | |
| 1469 | 1508 | |
| 1470 | 1509 |  	$smcFunc['db_query']('', ' | 
| 1471 | 1510 |  		UPDATE {db_prefix}ban_groups | 
| @@ -1509,10 +1548,12 @@ discard block | ||
| 1509 | 1548 |  { | 
| 1510 | 1549 | global $smcFunc, $context; | 
| 1511 | 1550 | |
| 1512 | - if (empty($ban_info['name'])) | |
| 1513 | - $context['ban_errors'][] = 'ban_name_empty'; | |
| 1514 | - if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) | |
| 1515 | - $context['ban_errors'][] = 'ban_unknown_restriction_type'; | |
| 1551 | +	if (empty($ban_info['name'])) { | |
| 1552 | + $context['ban_errors'][] = 'ban_name_empty'; | |
| 1553 | + } | |
| 1554 | +	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) { | |
| 1555 | + $context['ban_errors'][] = 'ban_unknown_restriction_type'; | |
| 1556 | + } | |
| 1516 | 1557 | |
| 1517 | 1558 | if (!empty($ban_info['name'])) | 
| 1518 | 1559 |  	{ | 
| @@ -1527,13 +1568,15 @@ discard block | ||
| 1527 | 1568 | ) | 
| 1528 | 1569 | ); | 
| 1529 | 1570 | |
| 1530 | - if ($smcFunc['db_num_rows']($request) == 1) | |
| 1531 | - $context['ban_errors'][] = 'ban_name_exists'; | |
| 1571 | +		if ($smcFunc['db_num_rows']($request) == 1) { | |
| 1572 | + $context['ban_errors'][] = 'ban_name_exists'; | |
| 1573 | + } | |
| 1532 | 1574 | $smcFunc['db_free_result']($request); | 
| 1533 | 1575 | } | 
| 1534 | 1576 | |
| 1535 | - if (!empty($context['ban_errors'])) | |
| 1536 | - return; | |
| 1577 | +	if (!empty($context['ban_errors'])) { | |
| 1578 | + return; | |
| 1579 | + } | |
| 1537 | 1580 | |
| 1538 | 1581 | // Yes yes, we're ready to add now. | 
| 1539 | 1582 |  	$ban_info['id'] = $smcFunc['db_insert']('', | 
| @@ -1550,8 +1593,9 @@ discard block | ||
| 1550 | 1593 | 1 | 
| 1551 | 1594 | ); | 
| 1552 | 1595 | |
| 1553 | - if (empty($ban_info['id'])) | |
| 1554 | - $context['ban_errors'][] = 'impossible_insert_new_bangroup'; | |
| 1596 | +	if (empty($ban_info['id'])) { | |
| 1597 | + $context['ban_errors'][] = 'impossible_insert_new_bangroup'; | |
| 1598 | + } | |
| 1555 | 1599 | |
| 1556 | 1600 | return $ban_info['id']; | 
| 1557 | 1601 | } | 
| @@ -1576,24 +1620,24 @@ discard block | ||
| 1576 | 1620 | $ban_group = isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0; | 
| 1577 | 1621 | $ban_id = isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0; | 
| 1578 | 1622 | |
| 1579 | - if (empty($ban_group)) | |
| 1580 | -		fatal_lang_error('ban_not_found', false); | |
| 1623 | +	if (empty($ban_group)) { | |
| 1624 | +			fatal_lang_error('ban_not_found', false); | |
| 1625 | + } | |
| 1581 | 1626 | |
| 1582 | 1627 | if (isset($_POST['add_new_trigger']) && !empty($_POST['ban_suggestions'])) | 
| 1583 | 1628 |  	{ | 
| 1584 | 1629 | saveTriggers($_POST['ban_suggestions'], $ban_group, 0, $ban_id); | 
| 1585 | 1630 |  		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : '')); | 
| 1586 | - } | |
| 1587 | - elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions'])) | |
| 1631 | + } elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions'])) | |
| 1588 | 1632 |  	{ | 
| 1589 | 1633 | // The first replaces the old one, the others are added new (simplification, otherwise it would require another query and some work...) | 
| 1590 | 1634 | saveTriggers(array_shift($_POST['ban_suggestions']), $ban_group, 0, $ban_id); | 
| 1591 | - if (!empty($_POST['ban_suggestions'])) | |
| 1592 | - saveTriggers($_POST['ban_suggestions'], $ban_group); | |
| 1635 | +		if (!empty($_POST['ban_suggestions'])) { | |
| 1636 | + saveTriggers($_POST['ban_suggestions'], $ban_group); | |
| 1637 | + } | |
| 1593 | 1638 | |
| 1594 | 1639 |  		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : '')); | 
| 1595 | - } | |
| 1596 | - elseif (isset($_POST['edit_trigger'])) | |
| 1640 | + } elseif (isset($_POST['edit_trigger'])) | |
| 1597 | 1641 |  	{ | 
| 1598 | 1642 | removeBanTriggers($ban_id); | 
| 1599 | 1643 |  		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : '')); | 
| @@ -1624,8 +1668,7 @@ discard block | ||
| 1624 | 1668 | ), | 
| 1625 | 1669 | 'is_new' => true, | 
| 1626 | 1670 | ); | 
| 1627 | - } | |
| 1628 | - else | |
| 1671 | + } else | |
| 1629 | 1672 |  	{ | 
| 1630 | 1673 |  		$request = $smcFunc['db_query']('', ' | 
| 1631 | 1674 | SELECT | 
| @@ -1642,8 +1685,9 @@ discard block | ||
| 1642 | 1685 | 'ban_group' => $ban_group, | 
| 1643 | 1686 | ) | 
| 1644 | 1687 | ); | 
| 1645 | - if ($smcFunc['db_num_rows']($request) == 0) | |
| 1646 | -			fatal_lang_error('ban_not_found', false); | |
| 1688 | +		if ($smcFunc['db_num_rows']($request) == 0) { | |
| 1689 | +					fatal_lang_error('ban_not_found', false); | |
| 1690 | + } | |
| 1647 | 1691 | $row = $smcFunc['db_fetch_assoc']($request); | 
| 1648 | 1692 | $smcFunc['db_free_result']($request); | 
| 1649 | 1693 | |
| @@ -1692,8 +1736,9 @@ discard block | ||
| 1692 | 1736 | removeBanTriggers($_POST['remove']); | 
| 1693 | 1737 | |
| 1694 | 1738 | // Rehabilitate some members. | 
| 1695 | - if ($_REQUEST['entity'] == 'member') | |
| 1696 | - updateBanMembers(); | |
| 1739 | +		if ($_REQUEST['entity'] == 'member') { | |
| 1740 | + updateBanMembers(); | |
| 1741 | + } | |
| 1697 | 1742 | |
| 1698 | 1743 | // Make sure the ban cache is refreshed. | 
| 1699 | 1744 |  		updateSettings(array('banLastUpdated' => time())); | 
| @@ -1806,8 +1851,7 @@ discard block | ||
| 1806 | 1851 | 'default' => 'bi.ip_low, bi.ip_high, bi.ip_low', | 
| 1807 | 1852 | 'reverse' => 'bi.ip_low DESC, bi.ip_high DESC', | 
| 1808 | 1853 | ); | 
| 1809 | - } | |
| 1810 | - elseif ($context['selected_entity'] === 'hostname') | |
| 1854 | + } elseif ($context['selected_entity'] === 'hostname') | |
| 1811 | 1855 |  	{ | 
| 1812 | 1856 | $listOptions['columns']['banned_entity']['data'] = array( | 
| 1813 | 1857 | 'function' => function($rowData) use ($smcFunc) | 
| @@ -1819,8 +1863,7 @@ discard block | ||
| 1819 | 1863 | 'default' => 'bi.hostname', | 
| 1820 | 1864 | 'reverse' => 'bi.hostname DESC', | 
| 1821 | 1865 | ); | 
| 1822 | - } | |
| 1823 | - elseif ($context['selected_entity'] === 'email') | |
| 1866 | + } elseif ($context['selected_entity'] === 'email') | |
| 1824 | 1867 |  	{ | 
| 1825 | 1868 | $listOptions['columns']['banned_entity']['data'] = array( | 
| 1826 | 1869 | 'function' => function($rowData) use ($smcFunc) | 
| @@ -1832,8 +1875,7 @@ discard block | ||
| 1832 | 1875 | 'default' => 'bi.email_address', | 
| 1833 | 1876 | 'reverse' => 'bi.email_address DESC', | 
| 1834 | 1877 | ); | 
| 1835 | - } | |
| 1836 | - elseif ($context['selected_entity'] === 'member') | |
| 1878 | + } elseif ($context['selected_entity'] === 'member') | |
| 1837 | 1879 |  	{ | 
| 1838 | 1880 | $listOptions['columns']['banned_entity']['data'] = array( | 
| 1839 | 1881 | 'sprintf' => array( | 
| @@ -1897,8 +1939,9 @@ discard block | ||
| 1897 | 1939 | ) | 
| 1898 | 1940 | ); | 
| 1899 | 1941 | $ban_triggers = array(); | 
| 1900 | - while ($row = $smcFunc['db_fetch_assoc']($request)) | |
| 1901 | - $ban_triggers[] = $row; | |
| 1942 | +	while ($row = $smcFunc['db_fetch_assoc']($request)) { | |
| 1943 | + $ban_triggers[] = $row; | |
| 1944 | + } | |
| 1902 | 1945 | $smcFunc['db_free_result']($request); | 
| 1903 | 1946 | |
| 1904 | 1947 | return $ban_triggers; | 
| @@ -1954,8 +1997,9 @@ discard block | ||
| 1954 | 1997 |  		validateToken('admin-bl'); | 
| 1955 | 1998 | |
| 1956 | 1999 | // 'Delete all entries' button was pressed. | 
| 1957 | - if (!empty($_POST['removeAll'])) | |
| 1958 | - removeBanLogs(); | |
| 2000 | +		if (!empty($_POST['removeAll'])) { | |
| 2001 | + removeBanLogs(); | |
| 2002 | + } | |
| 1959 | 2003 | // 'Delete selection' button was pressed. | 
| 1960 | 2004 | else | 
| 1961 | 2005 |  		{ | 
| @@ -2164,12 +2208,15 @@ discard block | ||
| 2164 | 2208 | $low = inet_dtop($low); | 
| 2165 | 2209 | $high = inet_dtop($high); | 
| 2166 | 2210 | |
| 2167 | - if ($low == '255.255.255.255') return 'unknown'; | |
| 2168 | - if ($low == $high) | |
| 2169 | - return $low; | |
| 2170 | - else | |
| 2171 | - return $low . '-' . $high; | |
| 2172 | -} | |
| 2211 | +	if ($low == '255.255.255.255') { | |
| 2212 | + return 'unknown'; | |
| 2213 | + } | |
| 2214 | +	if ($low == $high) { | |
| 2215 | + return $low; | |
| 2216 | +	} else { | |
| 2217 | + return $low . '-' . $high; | |
| 2218 | + } | |
| 2219 | + } | |
| 2173 | 2220 | |
| 2174 | 2221 | /** | 
| 2175 | 2222 | * Checks whether a given IP range already exists in the trigger list. | 
| @@ -2245,15 +2292,17 @@ discard block | ||
| 2245 | 2292 | $memberEmailWild = array(); | 
| 2246 | 2293 | while ($row = $smcFunc['db_fetch_assoc']($request)) | 
| 2247 | 2294 |  	{ | 
| 2248 | - if ($row['id_member']) | |
| 2249 | - $memberIDs[$row['id_member']] = $row['id_member']; | |
| 2295 | +		if ($row['id_member']) { | |
| 2296 | + $memberIDs[$row['id_member']] = $row['id_member']; | |
| 2297 | + } | |
| 2250 | 2298 | if ($row['email_address']) | 
| 2251 | 2299 |  		{ | 
| 2252 | 2300 | // Does it have a wildcard - if so we can't do a IN on it. | 
| 2253 | - if (strpos($row['email_address'], '%') !== false) | |
| 2254 | - $memberEmailWild[$row['email_address']] = $row['email_address']; | |
| 2255 | - else | |
| 2256 | - $memberEmails[$row['email_address']] = $row['email_address']; | |
| 2301 | +			if (strpos($row['email_address'], '%') !== false) { | |
| 2302 | + $memberEmailWild[$row['email_address']] = $row['email_address']; | |
| 2303 | +			} else { | |
| 2304 | + $memberEmails[$row['email_address']] = $row['email_address']; | |
| 2305 | + } | |
| 2257 | 2306 | } | 
| 2258 | 2307 | } | 
| 2259 | 2308 | $smcFunc['db_free_result']($request); | 
| @@ -2304,14 +2353,15 @@ discard block | ||
| 2304 | 2353 | } | 
| 2305 | 2354 | |
| 2306 | 2355 | // We welcome our new members in the realm of the banned. | 
| 2307 | - if (!empty($newMembers)) | |
| 2308 | -		$smcFunc['db_query']('', ' | |
| 2356 | +	if (!empty($newMembers)) { | |
| 2357 | +			$smcFunc['db_query']('', ' | |
| 2309 | 2358 |  			DELETE FROM {db_prefix}log_online | 
| 2310 | 2359 |  			WHERE id_member IN ({array_int:new_banned_members})', | 
| 2311 | 2360 | array( | 
| 2312 | 2361 | 'new_banned_members' => $newMembers, | 
| 2313 | 2362 | ) | 
| 2314 | 2363 | ); | 
| 2364 | + } | |
| 2315 | 2365 | |
| 2316 | 2366 | // Find members that are wrongfully marked as banned. | 
| 2317 | 2367 |  	$request = $smcFunc['db_query']('', ' | 
| @@ -2338,9 +2388,10 @@ discard block | ||
| 2338 | 2388 | } | 
| 2339 | 2389 | $smcFunc['db_free_result']($request); | 
| 2340 | 2390 | |
| 2341 | - if (!empty($updates)) | |
| 2342 | - foreach ($updates as $newStatus => $members) | |
| 2391 | +	if (!empty($updates)) { | |
| 2392 | + foreach ($updates as $newStatus => $members) | |
| 2343 | 2393 |  			updateMemberData($members, array('is_activated' => $newStatus)); | 
| 2394 | + } | |
| 2344 | 2395 | |
| 2345 | 2396 | // Update the latest member and our total members as banning may change them. | 
| 2346 | 2397 |  	updateStats('member'); |