@@ -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 4  | 
                                                        
| 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 4  | 
                                                        
| 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 | }  | 
                                                        
@@ -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 | }  | 
                                                        
@@ -223,7 +223,7 @@ discard block  | 
                                                    ||
| 223 | 223 | |
| 224 | 224 | global $smcFunc;  | 
                                                        
| 225 | 225 | |
| 226 | -		$result = $smcFunc['db_query']('',' | 
                                                        |
| 226 | +		$result = $smcFunc['db_query']('', ' | 
                                                        |
| 227 | 227 | SELECT DISTINCT id_search  | 
                                                        
| 228 | 228 |  			FROM {db_prefix}log_search_results | 
                                                        
| 229 | 229 |  			WHERE id_msg = {int:id_msg}', | 
                                                        
@@ -239,7 +239,7 @@ discard block  | 
                                                    ||
| 239 | 239 | if (count($id_searchs) < 1)  | 
                                                        
| 240 | 240 | return;  | 
                                                        
| 241 | 241 | |
| 242 | -		$smcFunc['db_query']('',' | 
                                                        |
| 242 | +		$smcFunc['db_query']('', ' | 
                                                        |
| 243 | 243 |  			DELETE FROM {db_prefix}log_search_results | 
                                                        
| 244 | 244 |  			WHERE id_search in ({array_int:id_searchs})', | 
                                                        
| 245 | 245 | array(  | 
                                                        
@@ -247,7 +247,7 @@ discard block  | 
                                                    ||
| 247 | 247 | )  | 
                                                        
| 248 | 248 | );  | 
                                                        
| 249 | 249 | |
| 250 | -		$smcFunc['db_query']('',' | 
                                                        |
| 250 | +		$smcFunc['db_query']('', ' | 
                                                        |
| 251 | 251 |  			DELETE FROM {db_prefix}log_search_topics | 
                                                        
| 252 | 252 |  			WHERE id_search in ({array_int:id_searchs})', | 
                                                        
| 253 | 253 | array(  | 
                                                        
@@ -255,7 +255,7 @@ discard block  | 
                                                    ||
| 255 | 255 | )  | 
                                                        
| 256 | 256 | );  | 
                                                        
| 257 | 257 | |
| 258 | -		$smcFunc['db_query']('',' | 
                                                        |
| 258 | +		$smcFunc['db_query']('', ' | 
                                                        |
| 259 | 259 |  			DELETE FROM {db_prefix}log_search_messages | 
                                                        
| 260 | 260 |  			WHERE id_search in ({array_int:id_searchs})', | 
                                                        
| 261 | 261 | array(  | 
                                                        
@@ -233,11 +233,13 @@  | 
                                                    ||
| 233 | 233 | );  | 
                                                        
| 234 | 234 | |
| 235 | 235 | $id_searchs = array();  | 
                                                        
| 236 | - while ($row = $smcFunc['db_fetch_assoc']($result))  | 
                                                        |
| 237 | - $id_searchs[] = $row['id_search'];  | 
                                                        |
| 236 | +		while ($row = $smcFunc['db_fetch_assoc']($result)) { | 
                                                        |
| 237 | + $id_searchs[] = $row['id_search'];  | 
                                                        |
| 238 | + }  | 
                                                        |
| 238 | 239 | |
| 239 | - if (count($id_searchs) < 1)  | 
                                                        |
| 240 | - return;  | 
                                                        |
| 240 | +		if (count($id_searchs) < 1) { | 
                                                        |
| 241 | + return;  | 
                                                        |
| 242 | + }  | 
                                                        |
| 241 | 243 | |
| 242 | 244 |  		$smcFunc['db_query']('',' | 
                                                        
| 243 | 245 |  			DELETE FROM {db_prefix}log_search_results | 
                                                        
@@ -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 4  | 
                                                        
| 14 | 14 | */  | 
                                                        
| 15 | 15 | |
| 16 | -if (!defined('SMF')) | 
                                                        |
| 16 | +if (!defined('SMF')) { | 
                                                        |
| 17 | 17 |  	die('No direct access...'); | 
                                                        
| 18 | +}  | 
                                                        |
| 18 | 19 | |
| 19 | 20 | /**  | 
                                                        
| 20 | 21 | * Add the file functions to the $smcFunc array.  | 
                                                        
@@ -53,8 +54,9 @@ discard block  | 
                                                    ||
| 53 | 54 | 'messages', 'moderator_groups', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages',  | 
                                                        
| 54 | 55 | 'pm_labeled_messages', 'pm_labels', 'pm_recipients', 'pm_rules', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys',  | 
                                                        
| 55 | 56 | 'spiders', 'subscriptions', 'themes', 'topics', 'user_alerts', 'user_alerts_prefs', 'user_drafts', 'user_likes');  | 
                                                        
| 56 | - foreach ($reservedTables as $k => $table_name)  | 
                                                        |
| 57 | - $reservedTables[$k] = strtolower($db_prefix . $table_name);  | 
                                                        |
| 57 | +	foreach ($reservedTables as $k => $table_name) { | 
                                                        |
| 58 | + $reservedTables[$k] = strtolower($db_prefix . $table_name);  | 
                                                        |
| 59 | + }  | 
                                                        |
| 58 | 60 | |
| 59 | 61 | // We in turn may need the extra stuff.  | 
                                                        
| 60 | 62 |  	db_extend('extra'); | 
                                                        
@@ -109,8 +111,9 @@ discard block  | 
                                                    ||
| 109 | 111 |  	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name); | 
                                                        
| 110 | 112 | |
| 111 | 113 | // First - no way do we touch SMF tables.  | 
                                                        
| 112 | - if (in_array(strtolower($table_name), $reservedTables))  | 
                                                        |
| 113 | - return false;  | 
                                                        |
| 114 | +	if (in_array(strtolower($table_name), $reservedTables)) { | 
                                                        |
| 115 | + return false;  | 
                                                        |
| 116 | + }  | 
                                                        |
| 114 | 117 | |
| 115 | 118 | // Log that we'll want to remove this on uninstall.  | 
                                                        
| 116 | 119 |  	$db_package_log[] = array('remove_table', $table_name); | 
                                                        
@@ -120,9 +123,9 @@ discard block  | 
                                                    ||
| 120 | 123 | if (in_array($full_table_name, $tables))  | 
                                                        
| 121 | 124 |  	{ | 
                                                        
| 122 | 125 | // This is a sad day... drop the table? If not, return false (error) by default.  | 
                                                        
| 123 | - if ($if_exists == 'overwrite')  | 
                                                        |
| 124 | - $smcFunc['db_drop_table']($table_name);  | 
                                                        |
| 125 | - else if ($if_exists == 'update')  | 
                                                        |
| 126 | +		if ($if_exists == 'overwrite') { | 
                                                        |
| 127 | + $smcFunc['db_drop_table']($table_name);  | 
                                                        |
| 128 | + } else if ($if_exists == 'update')  | 
                                                        |
| 126 | 129 |  		{ | 
                                                        
| 127 | 130 |  			$smcFunc['db_transaction']('begin'); | 
                                                        
| 128 | 131 | $db_trans = true;  | 
                                                        
@@ -134,15 +137,16 @@ discard block  | 
                                                    ||
| 134 | 137 | )  | 
                                                        
| 135 | 138 | );  | 
                                                        
| 136 | 139 | $old_table_exists = true;  | 
                                                        
| 140 | +		} else { | 
                                                        |
| 141 | + return $if_exists == 'ignore';  | 
                                                        |
| 137 | 142 | }  | 
                                                        
| 138 | - else  | 
                                                        |
| 139 | - return $if_exists == 'ignore';  | 
                                                        |
| 140 | 143 | }  | 
                                                        
| 141 | 144 | |
| 142 | 145 | // Righty - let's do the damn thing!  | 
                                                        
| 143 | 146 |  	$table_query = 'CREATE TABLE ' . $table_name . "\n" . '('; | 
                                                        
| 144 | - foreach ($columns as $column)  | 
                                                        |
| 145 | - $table_query .= "\n\t" . smf_db_create_query_column($column) . ',';  | 
                                                        |
| 147 | +	foreach ($columns as $column) { | 
                                                        |
| 148 | + $table_query .= "\n\t" . smf_db_create_query_column($column) . ',';  | 
                                                        |
| 149 | + }  | 
                                                        |
| 146 | 150 | |
| 147 | 151 | // Loop through the indexes next...  | 
                                                        
| 148 | 152 | foreach ($indexes as $index)  | 
                                                        
@@ -150,19 +154,21 @@ discard block  | 
                                                    ||
| 150 | 154 |  		$columns = implode(',', $index['columns']); | 
                                                        
| 151 | 155 | |
| 152 | 156 | // Is it the primary?  | 
                                                        
| 153 | - if (isset($index['type']) && $index['type'] == 'primary')  | 
                                                        |
| 154 | -			$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; | 
                                                        |
| 155 | - else  | 
                                                        |
| 157 | +		if (isset($index['type']) && $index['type'] == 'primary') { | 
                                                        |
| 158 | +					$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; | 
                                                        |
| 159 | + } else  | 
                                                        |
| 156 | 160 |  		{ | 
                                                        
| 157 | - if (empty($index['name']))  | 
                                                        |
| 158 | -				$index['name'] = implode('_', $index['columns']); | 
                                                        |
| 161 | +			if (empty($index['name'])) { | 
                                                        |
| 162 | +							$index['name'] = implode('_', $index['columns']); | 
                                                        |
| 163 | + }  | 
                                                        |
| 159 | 164 |  			$table_query .= "\n\t" . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : 'KEY') . ' ' . $index['name'] . ' (' . $columns . '),'; | 
                                                        
| 160 | 165 | }  | 
                                                        
| 161 | 166 | }  | 
                                                        
| 162 | 167 | |
| 163 | 168 | // No trailing commas!  | 
                                                        
| 164 | - if (substr($table_query, -1) == ',')  | 
                                                        |
| 165 | - $table_query = substr($table_query, 0, -1);  | 
                                                        |
| 169 | +	if (substr($table_query, -1) == ',') { | 
                                                        |
| 170 | + $table_query = substr($table_query, 0, -1);  | 
                                                        |
| 171 | + }  | 
                                                        |
| 166 | 172 | |
| 167 | 173 | // Which engine do we want here?  | 
                                                        
| 168 | 174 | if (empty($engines))  | 
                                                        
@@ -172,8 +178,9 @@ discard block  | 
                                                    ||
| 172 | 178 | |
| 173 | 179 | while ($row = $smcFunc['db_fetch_assoc']($get_engines))  | 
                                                        
| 174 | 180 |  		{ | 
                                                        
| 175 | - if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')  | 
                                                        |
| 176 | - $engines[] = $row['Engine'];  | 
                                                        |
| 181 | +			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') { | 
                                                        |
| 182 | + $engines[] = $row['Engine'];  | 
                                                        |
| 183 | + }  | 
                                                        |
| 177 | 184 | }  | 
                                                        
| 178 | 185 | |
| 179 | 186 | $smcFunc['db_free_result']($get_engines);  | 
                                                        
@@ -187,8 +194,9 @@ discard block  | 
                                                    ||
| 187 | 194 | }  | 
                                                        
| 188 | 195 | |
| 189 | 196 | $table_query .= ') ENGINE=' . $parameters['engine'];  | 
                                                        
| 190 | - if (!empty($db_character_set) && $db_character_set == 'utf8')  | 
                                                        |
| 191 | - $table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';  | 
                                                        |
| 197 | +	if (!empty($db_character_set) && $db_character_set == 'utf8') { | 
                                                        |
| 198 | + $table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';  | 
                                                        |
| 199 | + }  | 
                                                        |
| 192 | 200 | |
| 193 | 201 | // Create the table!  | 
                                                        
| 194 | 202 |  	$smcFunc['db_query']('', $table_query, | 
                                                        
@@ -255,8 +263,9 @@ discard block  | 
                                                    ||
| 255 | 263 |  	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name); | 
                                                        
| 256 | 264 | |
| 257 | 265 | // God no - dropping one of these = bad.  | 
                                                        
| 258 | - if (in_array(strtolower($table_name), $reservedTables))  | 
                                                        |
| 259 | - return false;  | 
                                                        |
| 266 | +	if (in_array(strtolower($table_name), $reservedTables)) { | 
                                                        |
| 267 | + return false;  | 
                                                        |
| 268 | + }  | 
                                                        |
| 260 | 269 | |
| 261 | 270 | // Does it exist?  | 
                                                        
| 262 | 271 | if (in_array($full_table_name, $smcFunc['db_list_tables']()))  | 
                                                        
@@ -297,14 +306,16 @@ discard block  | 
                                                    ||
| 297 | 306 | |
| 298 | 307 | // Does it exist - if so don't add it again!  | 
                                                        
| 299 | 308 | $columns = $smcFunc['db_list_columns']($table_name, false);  | 
                                                        
| 300 | - foreach ($columns as $column)  | 
                                                        |
| 301 | - if ($column == $column_info['name'])  | 
                                                        |
| 309 | +	foreach ($columns as $column) { | 
                                                        |
| 310 | + if ($column == $column_info['name'])  | 
                                                        |
| 302 | 311 |  		{ | 
                                                        
| 303 | 312 | // If we're going to overwrite then use change column.  | 
                                                        
| 304 | 313 | if ($if_exists == 'update')  | 
                                                        
| 305 | 314 | return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info);  | 
                                                        
| 306 | - else  | 
                                                        |
| 307 | - return false;  | 
                                                        |
| 315 | + }  | 
                                                        |
| 316 | +			else { | 
                                                        |
| 317 | + return false;  | 
                                                        |
| 318 | + }  | 
                                                        |
| 308 | 319 | }  | 
                                                        
| 309 | 320 | |
| 310 | 321 | // Get the specifics...  | 
                                                        
@@ -340,8 +351,8 @@ discard block  | 
                                                    ||
| 340 | 351 | |
| 341 | 352 | // Does it exist?  | 
                                                        
| 342 | 353 | $columns = $smcFunc['db_list_columns']($table_name, true);  | 
                                                        
| 343 | - foreach ($columns as $column)  | 
                                                        |
| 344 | - if ($column['name'] == $column_name)  | 
                                                        |
| 354 | +	foreach ($columns as $column) { | 
                                                        |
| 355 | + if ($column['name'] == $column_name)  | 
                                                        |
| 345 | 356 |  		{ | 
                                                        
| 346 | 357 |  			$smcFunc['db_query']('', ' | 
                                                        
| 347 | 358 | ALTER TABLE ' . $table_name . '  | 
                                                        
@@ -350,6 +361,7 @@ discard block  | 
                                                    ||
| 350 | 361 | 'security_override' => true,  | 
                                                        
| 351 | 362 | )  | 
                                                        
| 352 | 363 | );  | 
                                                        
| 364 | + }  | 
                                                        |
| 353 | 365 | |
| 354 | 366 | return true;  | 
                                                        
| 355 | 367 | }  | 
                                                        
@@ -375,37 +387,47 @@ discard block  | 
                                                    ||
| 375 | 387 | // Check it does exist!  | 
                                                        
| 376 | 388 | $columns = $smcFunc['db_list_columns']($table_name, true);  | 
                                                        
| 377 | 389 | $old_info = null;  | 
                                                        
| 378 | - foreach ($columns as $column)  | 
                                                        |
| 379 | - if ($column['name'] == $old_column)  | 
                                                        |
| 390 | +	foreach ($columns as $column) { | 
                                                        |
| 391 | + if ($column['name'] == $old_column)  | 
                                                        |
| 380 | 392 | $old_info = $column;  | 
                                                        
| 393 | + }  | 
                                                        |
| 381 | 394 | |
| 382 | 395 | // Nothing?  | 
                                                        
| 383 | - if ($old_info == null)  | 
                                                        |
| 384 | - return false;  | 
                                                        |
| 396 | +	if ($old_info == null) { | 
                                                        |
| 397 | + return false;  | 
                                                        |
| 398 | + }  | 
                                                        |
| 385 | 399 | |
| 386 | 400 | // Get the right bits.  | 
                                                        
| 387 | - if (!isset($column_info['name']))  | 
                                                        |
| 388 | - $column_info['name'] = $old_column;  | 
                                                        |
| 389 | - if (!isset($column_info['default']))  | 
                                                        |
| 390 | - $column_info['default'] = $old_info['default'];  | 
                                                        |
| 391 | - if (!isset($column_info['null']))  | 
                                                        |
| 392 | - $column_info['null'] = $old_info['null'];  | 
                                                        |
| 393 | - if (!isset($column_info['auto']))  | 
                                                        |
| 394 | - $column_info['auto'] = $old_info['auto'];  | 
                                                        |
| 395 | - if (!isset($column_info['type']))  | 
                                                        |
| 396 | - $column_info['type'] = $old_info['type'];  | 
                                                        |
| 397 | - if (!isset($column_info['size']) || !is_numeric($column_info['size']))  | 
                                                        |
| 398 | - $column_info['size'] = $old_info['size'];  | 
                                                        |
| 399 | -	if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) | 
                                                        |
| 400 | - $column_info['unsigned'] = '';  | 
                                                        |
| 401 | +	if (!isset($column_info['name'])) { | 
                                                        |
| 402 | + $column_info['name'] = $old_column;  | 
                                                        |
| 403 | + }  | 
                                                        |
| 404 | +	if (!isset($column_info['default'])) { | 
                                                        |
| 405 | + $column_info['default'] = $old_info['default'];  | 
                                                        |
| 406 | + }  | 
                                                        |
| 407 | +	if (!isset($column_info['null'])) { | 
                                                        |
| 408 | + $column_info['null'] = $old_info['null'];  | 
                                                        |
| 409 | + }  | 
                                                        |
| 410 | +	if (!isset($column_info['auto'])) { | 
                                                        |
| 411 | + $column_info['auto'] = $old_info['auto'];  | 
                                                        |
| 412 | + }  | 
                                                        |
| 413 | +	if (!isset($column_info['type'])) { | 
                                                        |
| 414 | + $column_info['type'] = $old_info['type'];  | 
                                                        |
| 415 | + }  | 
                                                        |
| 416 | +	if (!isset($column_info['size']) || !is_numeric($column_info['size'])) { | 
                                                        |
| 417 | + $column_info['size'] = $old_info['size'];  | 
                                                        |
| 418 | + }  | 
                                                        |
| 419 | +	if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) { | 
                                                        |
| 420 | + $column_info['unsigned'] = '';  | 
                                                        |
| 421 | + }  | 
                                                        |
| 401 | 422 | |
| 402 | 423 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']);  | 
                                                        
| 403 | 424 | |
| 404 | 425 | // Allow for unsigned integers (mysql only)  | 
                                                        
| 405 | 426 |  	$unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column_info['unsigned']) ? 'unsigned ' : ''; | 
                                                        
| 406 | 427 | |
| 407 | - if ($size !== null)  | 
                                                        |
| 408 | -		$type = $type . '(' . $size . ')'; | 
                                                        |
| 428 | +	if ($size !== null) { | 
                                                        |
| 429 | +			$type = $type . '(' . $size . ')'; | 
                                                        |
| 430 | + }  | 
                                                        |
| 409 | 431 | |
| 410 | 432 |  	$smcFunc['db_query']('', ' | 
                                                        
| 411 | 433 | ALTER TABLE ' . $table_name . '  | 
                                                        
@@ -435,18 +457,20 @@ discard block  | 
                                                    ||
| 435 | 457 |  	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name); | 
                                                        
| 436 | 458 | |
| 437 | 459 | // No columns = no index.  | 
                                                        
| 438 | - if (empty($index_info['columns']))  | 
                                                        |
| 439 | - return false;  | 
                                                        |
| 460 | +	if (empty($index_info['columns'])) { | 
                                                        |
| 461 | + return false;  | 
                                                        |
| 462 | + }  | 
                                                        |
| 440 | 463 |  	$columns = implode(',', $index_info['columns']); | 
                                                        
| 441 | 464 | |
| 442 | 465 | // No name - make it up!  | 
                                                        
| 443 | 466 | if (empty($index_info['name']))  | 
                                                        
| 444 | 467 |  	{ | 
                                                        
| 445 | 468 | // No need for primary.  | 
                                                        
| 446 | - if (isset($index_info['type']) && $index_info['type'] == 'primary')  | 
                                                        |
| 447 | - $index_info['name'] = '';  | 
                                                        |
| 448 | - else  | 
                                                        |
| 449 | -			$index_info['name'] = implode('_', $index_info['columns']); | 
                                                        |
| 469 | +		if (isset($index_info['type']) && $index_info['type'] == 'primary') { | 
                                                        |
| 470 | + $index_info['name'] = '';  | 
                                                        |
| 471 | +		} else { | 
                                                        |
| 472 | +					$index_info['name'] = implode('_', $index_info['columns']); | 
                                                        |
| 473 | + }  | 
                                                        |
| 450 | 474 | }  | 
                                                        
| 451 | 475 | |
| 452 | 476 | // Log that we are going to want to remove this!  | 
                                                        
@@ -460,10 +484,11 @@ discard block  | 
                                                    ||
| 460 | 484 | if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary'))  | 
                                                        
| 461 | 485 |  		{ | 
                                                        
| 462 | 486 | // If we want to overwrite simply remove the current one then continue.  | 
                                                        
| 463 | - if ($if_exists != 'update' || $index['type'] == 'primary')  | 
                                                        |
| 464 | - return false;  | 
                                                        |
| 465 | - else  | 
                                                        |
| 466 | - $smcFunc['db_remove_index']($table_name, $index_info['name']);  | 
                                                        |
| 487 | +			if ($if_exists != 'update' || $index['type'] == 'primary') { | 
                                                        |
| 488 | + return false;  | 
                                                        |
| 489 | +			} else { | 
                                                        |
| 490 | + $smcFunc['db_remove_index']($table_name, $index_info['name']);  | 
                                                        |
| 491 | + }  | 
                                                        |
| 467 | 492 | }  | 
                                                        
| 468 | 493 | }  | 
                                                        
| 469 | 494 | |
@@ -477,8 +502,7 @@ discard block  | 
                                                    ||
| 477 | 502 | 'security_override' => true,  | 
                                                        
| 478 | 503 | )  | 
                                                        
| 479 | 504 | );  | 
                                                        
| 480 | - }  | 
                                                        |
| 481 | - else  | 
                                                        |
| 505 | + } else  | 
                                                        |
| 482 | 506 |  	{ | 
                                                        
| 483 | 507 |  		$smcFunc['db_query']('', ' | 
                                                        
| 484 | 508 | ALTER TABLE ' . $table_name . '  | 
                                                        
@@ -562,8 +586,7 @@ discard block  | 
                                                    ||
| 562 | 586 | $types = array(  | 
                                                        
| 563 | 587 | 'inet' => 'varbinary',  | 
                                                        
| 564 | 588 | );  | 
                                                        
| 565 | - }  | 
                                                        |
| 566 | - else  | 
                                                        |
| 589 | + } else  | 
                                                        |
| 567 | 590 |  	{ | 
                                                        
| 568 | 591 | $types = array(  | 
                                                        
| 569 | 592 | 'varbinary' => 'inet',  | 
                                                        
@@ -577,16 +600,15 @@ discard block  | 
                                                    ||
| 577 | 600 |  		{ | 
                                                        
| 578 | 601 | $type_size = 16;  | 
                                                        
| 579 | 602 | $type_name = 'varbinary';  | 
                                                        
| 580 | - }  | 
                                                        |
| 581 | - elseif ($type_name == 'varbinary' && $reverse && $type_size == 16)  | 
                                                        |
| 603 | + } elseif ($type_name == 'varbinary' && $reverse && $type_size == 16)  | 
                                                        |
| 582 | 604 |  		{ | 
                                                        
| 583 | 605 | $type_name = 'inet';  | 
                                                        
| 584 | 606 | $type_size = null;  | 
                                                        
| 607 | +		} elseif ($type_name == 'varbinary') { | 
                                                        |
| 608 | + $type_name = 'varbinary';  | 
                                                        |
| 609 | +		} else { | 
                                                        |
| 610 | + $type_name = $types[$type_name];  | 
                                                        |
| 585 | 611 | }  | 
                                                        
| 586 | - elseif ($type_name == 'varbinary')  | 
                                                        |
| 587 | - $type_name = 'varbinary';  | 
                                                        |
| 588 | - else  | 
                                                        |
| 589 | - $type_name = $types[$type_name];  | 
                                                        |
| 590 | 612 | }  | 
                                                        
| 591 | 613 | |
| 592 | 614 | return array($type_name, $type_size);  | 
                                                        
@@ -653,8 +675,7 @@ discard block  | 
                                                    ||
| 653 | 675 | if (!$detail)  | 
                                                        
| 654 | 676 |  		{ | 
                                                        
| 655 | 677 | $columns[] = $row['Field'];  | 
                                                        
| 656 | - }  | 
                                                        |
| 657 | - else  | 
                                                        |
| 678 | + } else  | 
                                                        |
| 658 | 679 |  		{ | 
                                                        
| 659 | 680 | // Is there an auto_increment?  | 
                                                        
| 660 | 681 | $auto = strpos($row['Extra'], 'auto_increment') !== false ? true : false;  | 
                                                        
@@ -664,10 +685,10 @@ discard block  | 
                                                    ||
| 664 | 685 |  			{ | 
                                                        
| 665 | 686 | $type = $matches[1];  | 
                                                        
| 666 | 687 | $size = $matches[2];  | 
                                                        
| 667 | - if (!empty($matches[3]) && $matches[3] == 'unsigned')  | 
                                                        |
| 668 | - $unsigned = true;  | 
                                                        |
| 669 | - }  | 
                                                        |
| 670 | - else  | 
                                                        |
| 688 | +				if (!empty($matches[3]) && $matches[3] == 'unsigned') { | 
                                                        |
| 689 | + $unsigned = true;  | 
                                                        |
| 690 | + }  | 
                                                        |
| 691 | + } else  | 
                                                        |
| 671 | 692 |  			{ | 
                                                        
| 672 | 693 | $type = $row['Type'];  | 
                                                        
| 673 | 694 | $size = null;  | 
                                                        
@@ -718,19 +739,20 @@ discard block  | 
                                                    ||
| 718 | 739 | $indexes = array();  | 
                                                        
| 719 | 740 | while ($row = $smcFunc['db_fetch_assoc']($result))  | 
                                                        
| 720 | 741 |  	{ | 
                                                        
| 721 | - if (!$detail)  | 
                                                        |
| 722 | - $indexes[] = $row['Key_name'];  | 
                                                        |
| 723 | - else  | 
                                                        |
| 742 | +		if (!$detail) { | 
                                                        |
| 743 | + $indexes[] = $row['Key_name'];  | 
                                                        |
| 744 | + } else  | 
                                                        |
| 724 | 745 |  		{ | 
                                                        
| 725 | 746 | // What is the type?  | 
                                                        
| 726 | - if ($row['Key_name'] == 'PRIMARY')  | 
                                                        |
| 727 | - $type = 'primary';  | 
                                                        |
| 728 | - elseif (empty($row['Non_unique']))  | 
                                                        |
| 729 | - $type = 'unique';  | 
                                                        |
| 730 | - elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT')  | 
                                                        |
| 731 | - $type = 'fulltext';  | 
                                                        |
| 732 | - else  | 
                                                        |
| 733 | - $type = 'index';  | 
                                                        |
| 747 | +			if ($row['Key_name'] == 'PRIMARY') { | 
                                                        |
| 748 | + $type = 'primary';  | 
                                                        |
| 749 | +			} elseif (empty($row['Non_unique'])) { | 
                                                        |
| 750 | + $type = 'unique';  | 
                                                        |
| 751 | +			} elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') { | 
                                                        |
| 752 | + $type = 'fulltext';  | 
                                                        |
| 753 | +			} else { | 
                                                        |
| 754 | + $type = 'index';  | 
                                                        |
| 755 | + }  | 
                                                        |
| 734 | 756 | |
| 735 | 757 | // This is the first column we've seen?  | 
                                                        
| 736 | 758 | if (empty($indexes[$row['Key_name']]))  | 
                                                        
@@ -743,10 +765,11 @@ discard block  | 
                                                    ||
| 743 | 765 | }  | 
                                                        
| 744 | 766 | |
| 745 | 767 | // Is it a partial index?  | 
                                                        
| 746 | - if (!empty($row['Sub_part']))  | 
                                                        |
| 747 | -				$indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')'; | 
                                                        |
| 748 | - else  | 
                                                        |
| 749 | - $indexes[$row['Key_name']]['columns'][] = $row['Column_name'];  | 
                                                        |
| 768 | +			if (!empty($row['Sub_part'])) { | 
                                                        |
| 769 | +							$indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')'; | 
                                                        |
| 770 | +			} else { | 
                                                        |
| 771 | + $indexes[$row['Key_name']]['columns'][] = $row['Column_name'];  | 
                                                        |
| 772 | + }  | 
                                                        |
| 750 | 773 | }  | 
                                                        
| 751 | 774 | }  | 
                                                        
| 752 | 775 | $smcFunc['db_free_result']($result);  | 
                                                        
@@ -768,11 +791,11 @@ discard block  | 
                                                    ||
| 768 | 791 | if (!empty($column['auto']))  | 
                                                        
| 769 | 792 |  	{ | 
                                                        
| 770 | 793 | $default = 'auto_increment';  | 
                                                        
| 794 | +	} elseif (isset($column['default']) && $column['default'] !== null) { | 
                                                        |
| 795 | + $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';  | 
                                                        |
| 796 | +	} else { | 
                                                        |
| 797 | + $default = '';  | 
                                                        |
| 771 | 798 | }  | 
                                                        
| 772 | - elseif (isset($column['default']) && $column['default'] !== null)  | 
                                                        |
| 773 | - $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';  | 
                                                        |
| 774 | - else  | 
                                                        |
| 775 | - $default = '';  | 
                                                        |
| 776 | 799 | |
| 777 | 800 | // Sort out the size... and stuff...  | 
                                                        
| 778 | 801 | $column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null;  | 
                                                        
@@ -781,8 +804,9 @@ discard block  | 
                                                    ||
| 781 | 804 | // Allow unsigned integers (mysql only)  | 
                                                        
| 782 | 805 |  	$unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column['unsigned']) ? 'unsigned ' : ''; | 
                                                        
| 783 | 806 | |
| 784 | - if ($size !== null)  | 
                                                        |
| 785 | -		$type = $type . '(' . $size . ')'; | 
                                                        |
| 807 | +	if ($size !== null) { | 
                                                        |
| 808 | +			$type = $type . '(' . $size . ')'; | 
                                                        |
| 809 | + }  | 
                                                        |
| 786 | 810 | |
| 787 | 811 | // Now just put it together!  | 
                                                        
| 788 | 812 | return '`' . $column['name'] . '` ' . $type . ' ' . (!empty($unsigned) ? $unsigned : '') . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default;  | 
                                                        
@@ -126,9 +126,9 @@ discard block  | 
                                                    ||
| 126 | 126 |  		{ | 
                                                        
| 127 | 127 |  			$smcFunc['db_transaction']('begin'); | 
                                                        
| 128 | 128 | $db_trans = true;  | 
                                                        
| 129 | - $smcFunc['db_drop_table']($table_name.'_old');  | 
                                                        |
| 130 | -			$smcFunc['db_query']('',' | 
                                                        |
| 131 | - RENAME TABLE '. $table_name .' TO ' . $table_name . '_old',  | 
                                                        |
| 129 | + $smcFunc['db_drop_table']($table_name . '_old');  | 
                                                        |
| 130 | +			$smcFunc['db_query']('', ' | 
                                                        |
| 131 | + RENAME TABLE '. $table_name . ' TO ' . $table_name . '_old',  | 
                                                        |
| 132 | 132 | array(  | 
                                                        
| 133 | 133 | 'security_override' => true,  | 
                                                        
| 134 | 134 | )  | 
                                                        
@@ -202,15 +202,15 @@ discard block  | 
                                                    ||
| 202 | 202 |  	{ | 
                                                        
| 203 | 203 | $same_col = array();  | 
                                                        
| 204 | 204 | |
| 205 | -		$request = $smcFunc['db_query']('',' | 
                                                        |
| 205 | +		$request = $smcFunc['db_query']('', ' | 
                                                        |
| 206 | 206 | SELECT count(*), column_name  | 
                                                        
| 207 | 207 | FROM information_schema.columns  | 
                                                        
| 208 | 208 |  			WHERE table_name in ({string:table1},{string:table2}) AND table_schema = {string:schema} | 
                                                        
| 209 | 209 | GROUP BY column_name  | 
                                                        
| 210 | 210 | HAVING count(*) > 1',  | 
                                                        
| 211 | - array (  | 
                                                        |
| 211 | + array(  | 
                                                        |
| 212 | 212 | 'table1' => $table_name,  | 
                                                        
| 213 | - 'table2' => $table_name.'_old',  | 
                                                        |
| 213 | + 'table2' => $table_name . '_old',  | 
                                                        |
| 214 | 214 | 'schema' => $db_name,  | 
                                                        
| 215 | 215 | )  | 
                                                        
| 216 | 216 | );  | 
                                                        
@@ -220,8 +220,8 @@ discard block  | 
                                                    ||
| 220 | 220 | $same_col[] = $row['column_name'];  | 
                                                        
| 221 | 221 | }  | 
                                                        
| 222 | 222 | |
| 223 | -		$smcFunc['db_query']('',' | 
                                                        |
| 224 | -			INSERT INTO ' . $table_name .'(' | 
                                                        |
| 223 | +		$smcFunc['db_query']('', ' | 
                                                        |
| 224 | +			INSERT INTO ' . $table_name . '(' | 
                                                        |
| 225 | 225 | . implode($same_col, ',') .  | 
                                                        
| 226 | 226 | ')  | 
                                                        
| 227 | 227 | SELECT '. implode($same_col, ',') . '  | 
                                                        
@@ -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 |  { | 
                                                        
@@ -45,7 +45,7 @@ discard block  | 
                                                    ||
| 45 | 45 | $backtrace = debug_backtrace();  | 
                                                        
| 46 | 46 | |
| 47 | 47 | // are we in a loop?  | 
                                                        
| 48 | - if($error_call > 2)  | 
                                                        |
| 48 | + if ($error_call > 2)  | 
                                                        |
| 49 | 49 |  	{ | 
                                                        
| 50 | 50 | var_dump($backtrace);  | 
                                                        
| 51 | 51 |  		die('Error loop.'); | 
                                                        
@@ -549,7 +549,7 @@ discard block  | 
                                                    ||
| 549 | 549 | $url['error'] = $error;  | 
                                                        
| 550 | 550 | // Url field got a max length of 1024 in db  | 
                                                        
| 551 | 551 | if (strlen($url['error']) > 500)  | 
                                                        
| 552 | - $url['error'] = substr($url['error'],0,500);  | 
                                                        |
| 552 | + $url['error'] = substr($url['error'], 0, 500);  | 
                                                        |
| 553 | 553 | |
| 554 | 554 | if (!empty($sprintf))  | 
                                                        
| 555 | 555 | $url['error_params'] = $sprintf;  | 
                                                        
@@ -15,8 +15,9 @@ discard block  | 
                                                    ||
| 15 | 15 | * @version 2.1 Beta 4  | 
                                                        
| 16 | 16 | */  | 
                                                        
| 17 | 17 | |
| 18 | -if (!defined('SMF')) | 
                                                        |
| 18 | +if (!defined('SMF')) { | 
                                                        |
| 19 | 19 |  	die('No direct access...'); | 
                                                        
| 20 | +}  | 
                                                        |
| 20 | 21 | |
| 21 | 22 | /**  | 
                                                        
| 22 | 23 | * Log an error, if the error logging is enabled.  | 
                                                        
@@ -39,10 +40,11 @@ discard block  | 
                                                    ||
| 39 | 40 | $error_call++;  | 
                                                        
| 40 | 41 | |
| 41 | 42 | // Collect a backtrace  | 
                                                        
| 42 | - if (!isset($db_show_debug) || $db_show_debug === false)  | 
                                                        |
| 43 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);  | 
                                                        |
| 44 | - else  | 
                                                        |
| 45 | - $backtrace = debug_backtrace();  | 
                                                        |
| 43 | +	if (!isset($db_show_debug) || $db_show_debug === false) { | 
                                                        |
| 44 | + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);  | 
                                                        |
| 45 | +	} else { | 
                                                        |
| 46 | + $backtrace = debug_backtrace();  | 
                                                        |
| 47 | + }  | 
                                                        |
| 46 | 48 | |
| 47 | 49 | // are we in a loop?  | 
                                                        
| 48 | 50 | if($error_call > 2)  | 
                                                        
@@ -52,8 +54,9 @@ discard block  | 
                                                    ||
| 52 | 54 | }  | 
                                                        
| 53 | 55 | |
| 54 | 56 | // Check if error logging is actually on.  | 
                                                        
| 55 | - if (empty($modSettings['enableErrorLogging']))  | 
                                                        |
| 56 | - return $error_message;  | 
                                                        |
| 57 | +	if (empty($modSettings['enableErrorLogging'])) { | 
                                                        |
| 58 | + return $error_message;  | 
                                                        |
| 59 | + }  | 
                                                        |
| 57 | 60 | |
| 58 | 61 | // Basically, htmlspecialchars it minus &. (for entities!)  | 
                                                        
| 59 | 62 |  	$error_message = strtr($error_message, array('<' => '<', '>' => '>', '"' => '"')); | 
                                                        
@@ -61,33 +64,39 @@ discard block  | 
                                                    ||
| 61 | 64 | |
| 62 | 65 | // Add a file and line to the error message?  | 
                                                        
| 63 | 66 | // Don't use the actual txt entries for file and line but instead use %1$s for file and %2$s for line  | 
                                                        
| 64 | - if ($file == null)  | 
                                                        |
| 65 | - $file = '';  | 
                                                        |
| 66 | - else  | 
                                                        |
| 67 | - // Window style slashes don't play well, lets convert them to the unix style.  | 
                                                        |
| 67 | +	if ($file == null) { | 
                                                        |
| 68 | + $file = '';  | 
                                                        |
| 69 | +	} else { | 
                                                        |
| 70 | + // Window style slashes don't play well, lets convert them to the unix style.  | 
                                                        |
| 68 | 71 |  		$file = str_replace('\\', '/', $file); | 
                                                        
| 72 | + }  | 
                                                        |
| 69 | 73 | |
| 70 | - if ($line == null)  | 
                                                        |
| 71 | - $line = 0;  | 
                                                        |
| 72 | - else  | 
                                                        |
| 73 | - $line = (int) $line;  | 
                                                        |
| 74 | +	if ($line == null) { | 
                                                        |
| 75 | + $line = 0;  | 
                                                        |
| 76 | +	} else { | 
                                                        |
| 77 | + $line = (int) $line;  | 
                                                        |
| 78 | + }  | 
                                                        |
| 74 | 79 | |
| 75 | 80 | // Just in case there's no id_member or IP set yet.  | 
                                                        
| 76 | - if (empty($user_info['id']))  | 
                                                        |
| 77 | - $user_info['id'] = 0;  | 
                                                        |
| 78 | - if (empty($user_info['ip']))  | 
                                                        |
| 79 | - $user_info['ip'] = '';  | 
                                                        |
| 81 | +	if (empty($user_info['id'])) { | 
                                                        |
| 82 | + $user_info['id'] = 0;  | 
                                                        |
| 83 | + }  | 
                                                        |
| 84 | +	if (empty($user_info['ip'])) { | 
                                                        |
| 85 | + $user_info['ip'] = '';  | 
                                                        |
| 86 | + }  | 
                                                        |
| 80 | 87 | |
| 81 | 88 | // Find the best query string we can...  | 
                                                        
| 82 | 89 | $query_string = empty($_SERVER['QUERY_STRING']) ? (empty($_SERVER['REQUEST_URL']) ? '' : str_replace($scripturl, '', $_SERVER['REQUEST_URL'])) : $_SERVER['QUERY_STRING'];  | 
                                                        
| 83 | 90 | |
| 84 | 91 | // Don't log the session hash in the url twice, it's a waste.  | 
                                                        
| 85 | - if (!empty($smcFunc['htmlspecialchars']))  | 
                                                        |
| 86 | -		$query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string)); | 
                                                        |
| 92 | +	if (!empty($smcFunc['htmlspecialchars'])) { | 
                                                        |
| 93 | +			$query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string)); | 
                                                        |
| 94 | + }  | 
                                                        |
| 87 | 95 | |
| 88 | 96 | // Just so we know what board error messages are from.  | 
                                                        
| 89 | - if (isset($_POST['board']) && !isset($_GET['board']))  | 
                                                        |
| 90 | - $query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];  | 
                                                        |
| 97 | +	if (isset($_POST['board']) && !isset($_GET['board'])) { | 
                                                        |
| 98 | + $query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];  | 
                                                        |
| 99 | + }  | 
                                                        |
| 91 | 100 | |
| 92 | 101 | // What types of categories do we have?  | 
                                                        
| 93 | 102 | $known_error_types = array(  | 
                                                        
@@ -140,9 +149,9 @@ discard block  | 
                                                    ||
| 140 | 149 | |
| 141 | 150 | list($context['num_errors']) = $smcFunc['db_fetch_row']($query);  | 
                                                        
| 142 | 151 | $smcFunc['db_free_result']($query);  | 
                                                        
| 152 | +		} else { | 
                                                        |
| 153 | + $context['num_errors']++;  | 
                                                        |
| 143 | 154 | }  | 
                                                        
| 144 | - else  | 
                                                        |
| 145 | - $context['num_errors']++;  | 
                                                        |
| 146 | 155 | }  | 
                                                        
| 147 | 156 | |
| 148 | 157 | // reset error call  | 
                                                        
@@ -164,12 +173,14 @@ discard block  | 
                                                    ||
| 164 | 173 | global $txt;  | 
                                                        
| 165 | 174 | |
| 166 | 175 | // Send the appropriate HTTP 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 | // We don't have $txt yet, but that's okay...  | 
                                                        
| 171 | - if (empty($txt))  | 
                                                        |
| 172 | - die($error);  | 
                                                        |
| 181 | +	if (empty($txt)) { | 
                                                        |
| 182 | + die($error);  | 
                                                        |
| 183 | + }  | 
                                                        |
| 173 | 184 | |
| 174 | 185 | log_error_online($error, false);  | 
                                                        
| 175 | 186 | setup_fatal_error_context($log ? log_error($error, $log) : $error);  | 
                                                        
@@ -196,8 +207,9 @@ discard block  | 
                                                    ||
| 196 | 207 | static $fatal_error_called = false;  | 
                                                        
| 197 | 208 | |
| 198 | 209 | // Send the status header - set this to 0 or false if you don't want to send one at all  | 
                                                        
| 199 | - if (!empty($status))  | 
                                                        |
| 200 | - send_http_status($status);  | 
                                                        |
| 210 | +	if (!empty($status)) { | 
                                                        |
| 211 | + send_http_status($status);  | 
                                                        |
| 212 | + }  | 
                                                        |
| 201 | 213 | |
| 202 | 214 | // Try to load a theme if we don't have one.  | 
                                                        
| 203 | 215 | if (empty($context['theme_loaded']) && empty($fatal_error_called))  | 
                                                        
@@ -207,8 +219,9 @@ discard block  | 
                                                    ||
| 207 | 219 | }  | 
                                                        
| 208 | 220 | |
| 209 | 221 | // If we have no theme stuff we can't have the language file...  | 
                                                        
| 210 | - if (empty($context['theme_loaded']))  | 
                                                        |
| 211 | - die($error);  | 
                                                        |
| 222 | +	if (empty($context['theme_loaded'])) { | 
                                                        |
| 223 | + die($error);  | 
                                                        |
| 224 | + }  | 
                                                        |
| 212 | 225 | |
| 213 | 226 | $reload_lang_file = true;  | 
                                                        
| 214 | 227 | // Log the error in the forum's language, but don't waste the time if we aren't logging  | 
                                                        
@@ -244,8 +257,9 @@ discard block  | 
                                                    ||
| 244 | 257 | global $settings, $modSettings, $db_show_debug;  | 
                                                        
| 245 | 258 | |
| 246 | 259 | // Ignore errors if we're ignoring them or they are strict notices from PHP 5  | 
                                                        
| 247 | - if (error_reporting() == 0)  | 
                                                        |
| 248 | - return;  | 
                                                        |
| 260 | +	if (error_reporting() == 0) { | 
                                                        |
| 261 | + return;  | 
                                                        |
| 262 | + }  | 
                                                        |
| 249 | 263 | |
| 250 | 264 | if (strpos($file, 'eval()') !== false && !empty($settings['current_include_filename']))  | 
                                                        
| 251 | 265 |  	{ | 
                                                        
@@ -253,19 +267,22 @@ discard block  | 
                                                    ||
| 253 | 267 | $count = count($array);  | 
                                                        
| 254 | 268 | for ($i = 0; $i < $count; $i++)  | 
                                                        
| 255 | 269 |  		{ | 
                                                        
| 256 | - if ($array[$i]['function'] != 'loadSubTemplate')  | 
                                                        |
| 257 | - continue;  | 
                                                        |
| 270 | +			if ($array[$i]['function'] != 'loadSubTemplate') { | 
                                                        |
| 271 | + continue;  | 
                                                        |
| 272 | + }  | 
                                                        |
| 258 | 273 | |
| 259 | 274 | // This is a bug in PHP, with eval, it seems!  | 
                                                        
| 260 | - if (empty($array[$i]['args']))  | 
                                                        |
| 261 | - $i++;  | 
                                                        |
| 275 | +			if (empty($array[$i]['args'])) { | 
                                                        |
| 276 | + $i++;  | 
                                                        |
| 277 | + }  | 
                                                        |
| 262 | 278 | break;  | 
                                                        
| 263 | 279 | }  | 
                                                        
| 264 | 280 | |
| 265 | - if (isset($array[$i]) && !empty($array[$i]['args']))  | 
                                                        |
| 266 | -			$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)'; | 
                                                        |
| 267 | - else  | 
                                                        |
| 268 | - $file = realpath($settings['current_include_filename']) . ' (eval?)';  | 
                                                        |
| 281 | +		if (isset($array[$i]) && !empty($array[$i]['args'])) { | 
                                                        |
| 282 | +					$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)'; | 
                                                        |
| 283 | +		} else { | 
                                                        |
| 284 | + $file = realpath($settings['current_include_filename']) . ' (eval?)';  | 
                                                        |
| 285 | + }  | 
                                                        |
| 269 | 286 | }  | 
                                                        
| 270 | 287 | |
| 271 | 288 | if (isset($db_show_debug) && $db_show_debug === true)  | 
                                                        
@@ -274,8 +291,9 @@ discard block  | 
                                                    ||
| 274 | 291 | if ($error_level % 255 != E_ERROR)  | 
                                                        
| 275 | 292 |  		{ | 
                                                        
| 276 | 293 | $temporary = ob_get_contents();  | 
                                                        
| 277 | - if (substr($temporary, -2) == '="')  | 
                                                        |
| 278 | - echo '"';  | 
                                                        |
| 294 | +			if (substr($temporary, -2) == '="') { | 
                                                        |
| 295 | + echo '"';  | 
                                                        |
| 296 | + }  | 
                                                        |
| 279 | 297 | }  | 
                                                        
| 280 | 298 | |
| 281 | 299 | // Debugging! This should look like a PHP error message.  | 
                                                        
@@ -291,23 +309,27 @@ discard block  | 
                                                    ||
| 291 | 309 |  	call_integration_hook('integrate_output_error', array($message, $error_type, $error_level, $file, $line)); | 
                                                        
| 292 | 310 | |
| 293 | 311 | // Dying on these errors only causes MORE problems (blank pages!)  | 
                                                        
| 294 | - if ($file == 'Unknown')  | 
                                                        |
| 295 | - return;  | 
                                                        |
| 312 | +	if ($file == 'Unknown') { | 
                                                        |
| 313 | + return;  | 
                                                        |
| 314 | + }  | 
                                                        |
| 296 | 315 | |
| 297 | 316 | // If this is an E_ERROR or E_USER_ERROR.... die. Violently so.  | 
                                                        
| 298 | - if ($error_level % 255 == E_ERROR)  | 
                                                        |
| 299 | - obExit(false);  | 
                                                        |
| 300 | - else  | 
                                                        |
| 301 | - return;  | 
                                                        |
| 317 | +	if ($error_level % 255 == E_ERROR) { | 
                                                        |
| 318 | + obExit(false);  | 
                                                        |
| 319 | +	} else { | 
                                                        |
| 320 | + return;  | 
                                                        |
| 321 | + }  | 
                                                        |
| 302 | 322 | |
| 303 | 323 | // If this is an E_ERROR, E_USER_ERROR, E_WARNING, or E_USER_WARNING.... die. Violently so.  | 
                                                        
| 304 | - if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING)  | 
                                                        |
| 305 | -		fatal_error(allowedTo('admin_forum') ? $message : $error_string, false); | 
                                                        |
| 324 | +	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) { | 
                                                        |
| 325 | +			fatal_error(allowedTo('admin_forum') ? $message : $error_string, false); | 
                                                        |
| 326 | + }  | 
                                                        |
| 306 | 327 | |
| 307 | 328 | // We should NEVER get to this point. Any fatal error MUST quit, or very bad things can happen.  | 
                                                        
| 308 | - if ($error_level % 255 == E_ERROR)  | 
                                                        |
| 309 | -		die('No direct access...'); | 
                                                        |
| 310 | -}  | 
                                                        |
| 329 | +	if ($error_level % 255 == E_ERROR) { | 
                                                        |
| 330 | +			die('No direct access...'); | 
                                                        |
| 331 | + }  | 
                                                        |
| 332 | + }  | 
                                                        |
| 311 | 333 | |
| 312 | 334 | /**  | 
                                                        
| 313 | 335 |   * It is called by {@link fatal_error()} and {@link fatal_lang_error()}. | 
                                                        
@@ -323,24 +345,28 @@ discard block  | 
                                                    ||
| 323 | 345 | |
| 324 | 346 | // Attempt to prevent a recursive loop.  | 
                                                        
| 325 | 347 | ++$level;  | 
                                                        
| 326 | - if ($level > 1)  | 
                                                        |
| 327 | - return false;  | 
                                                        |
| 348 | +	if ($level > 1) { | 
                                                        |
| 349 | + return false;  | 
                                                        |
| 350 | + }  | 
                                                        |
| 328 | 351 | |
| 329 | 352 | // Maybe they came from dlattach or similar?  | 
                                                        
| 330 | - if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded']))  | 
                                                        |
| 331 | - loadTheme();  | 
                                                        |
| 353 | +	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) { | 
                                                        |
| 354 | + loadTheme();  | 
                                                        |
| 355 | + }  | 
                                                        |
| 332 | 356 | |
| 333 | 357 | // Don't bother indexing errors mate...  | 
                                                        
| 334 | 358 | $context['robot_no_index'] = true;  | 
                                                        
| 335 | 359 | |
| 336 | - if (!isset($context['error_title']))  | 
                                                        |
| 337 | - $context['error_title'] = $txt['error_occured'];  | 
                                                        |
| 360 | +	if (!isset($context['error_title'])) { | 
                                                        |
| 361 | + $context['error_title'] = $txt['error_occured'];  | 
                                                        |
| 362 | + }  | 
                                                        |
| 338 | 363 | $context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message;  | 
                                                        
| 339 | 364 | |
| 340 | 365 | $context['error_code'] = isset($error_code) ? 'id="' . $error_code . '" ' : '';  | 
                                                        
| 341 | 366 | |
| 342 | - if (empty($context['page_title']))  | 
                                                        |
| 343 | - $context['page_title'] = $context['error_title'];  | 
                                                        |
| 367 | +	if (empty($context['page_title'])) { | 
                                                        |
| 368 | + $context['page_title'] = $context['error_title'];  | 
                                                        |
| 369 | + }  | 
                                                        |
| 344 | 370 | |
| 345 | 371 |  	loadTemplate('Errors'); | 
                                                        
| 346 | 372 | $context['sub_template'] = 'fatal_error';  | 
                                                        
@@ -348,23 +374,26 @@ discard block  | 
                                                    ||
| 348 | 374 | // If this is SSI, what do they want us to do?  | 
                                                        
| 349 | 375 | if (SMF == 'SSI')  | 
                                                        
| 350 | 376 |  	{ | 
                                                        
| 351 | - if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method))  | 
                                                        |
| 352 | - $ssi_on_error_method();  | 
                                                        |
| 353 | - elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true)  | 
                                                        |
| 354 | -			loadSubTemplate('fatal_error'); | 
                                                        |
| 377 | +		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) { | 
                                                        |
| 378 | + $ssi_on_error_method();  | 
                                                        |
| 379 | +		} elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) { | 
                                                        |
| 380 | +					loadSubTemplate('fatal_error'); | 
                                                        |
| 381 | + }  | 
                                                        |
| 355 | 382 | |
| 356 | 383 | // No layers?  | 
                                                        
| 357 | - if (empty($ssi_on_error_method) || $ssi_on_error_method !== true)  | 
                                                        |
| 358 | - exit;  | 
                                                        |
| 384 | +		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) { | 
                                                        |
| 385 | + exit;  | 
                                                        |
| 386 | + }  | 
                                                        |
| 359 | 387 | }  | 
                                                        
| 360 | 388 | // Alternatively from the cron call?  | 
                                                        
| 361 | 389 | elseif (SMF == 'BACKGROUND')  | 
                                                        
| 362 | 390 |  	{ | 
                                                        
| 363 | 391 | // We can't rely on even having language files available.  | 
                                                        
| 364 | -		if (defined('FROM_CLI') && FROM_CLI) | 
                                                        |
| 365 | - echo 'cron error: ', $context['error_message'];  | 
                                                        |
| 366 | - else  | 
                                                        |
| 367 | - echo 'An error occurred. More information may be available in your logs.';  | 
                                                        |
| 392 | +		if (defined('FROM_CLI') && FROM_CLI) { | 
                                                        |
| 393 | + echo 'cron error: ', $context['error_message'];  | 
                                                        |
| 394 | +		} else { | 
                                                        |
| 395 | + echo 'An error occurred. More information may be available in your logs.';  | 
                                                        |
| 396 | + }  | 
                                                        |
| 368 | 397 | exit;  | 
                                                        
| 369 | 398 | }  | 
                                                        
| 370 | 399 | |
@@ -392,8 +421,8 @@ discard block  | 
                                                    ||
| 392 | 421 | |
| 393 | 422 | set_fatal_error_headers();  | 
                                                        
| 394 | 423 | |
| 395 | - if (!empty($maintenance))  | 
                                                        |
| 396 | - echo '<!DOCTYPE html>  | 
                                                        |
| 424 | +	if (!empty($maintenance)) { | 
                                                        |
| 425 | + echo '<!DOCTYPE html>  | 
                                                        |
| 397 | 426 | <html>  | 
                                                        
| 398 | 427 | <head>  | 
                                                        
| 399 | 428 | <meta name="robots" content="noindex">  | 
                                                        
@@ -404,6 +433,7 @@ discard block  | 
                                                    ||
| 404 | 433 | ', $mmessage, '  | 
                                                        
| 405 | 434 | </body>  | 
                                                        
| 406 | 435 | </html>';  | 
                                                        
| 436 | + }  | 
                                                        |
| 407 | 437 | |
| 408 | 438 | die();  | 
                                                        
| 409 | 439 | }  | 
                                                        
@@ -425,15 +455,17 @@ discard block  | 
                                                    ||
| 425 | 455 | // For our purposes, we're gonna want this on if at all possible.  | 
                                                        
| 426 | 456 | $modSettings['cache_enable'] = '1';  | 
                                                        
| 427 | 457 | |
| 428 | -	if (($temp = cache_get_data('db_last_error', 600)) !== null) | 
                                                        |
| 429 | - $db_last_error = max($db_last_error, $temp);  | 
                                                        |
| 458 | +	if (($temp = cache_get_data('db_last_error', 600)) !== null) { | 
                                                        |
| 459 | + $db_last_error = max($db_last_error, $temp);  | 
                                                        |
| 460 | + }  | 
                                                        |
| 430 | 461 | |
| 431 | 462 | if ($db_last_error < time() - 3600 * 24 * 3 && empty($maintenance) && !empty($db_error_send))  | 
                                                        
| 432 | 463 |  	{ | 
                                                        
| 433 | 464 | // Avoid writing to the Settings.php file if at all possible; use shared memory instead.  | 
                                                        
| 434 | 465 |  		cache_put_data('db_last_error', time(), 600); | 
                                                        
| 435 | -		if (($temp = cache_get_data('db_last_error', 600)) === null) | 
                                                        |
| 436 | - logLastDatabaseError();  | 
                                                        |
| 466 | +		if (($temp = cache_get_data('db_last_error', 600)) === null) { | 
                                                        |
| 467 | + logLastDatabaseError();  | 
                                                        |
| 468 | + }  | 
                                                        |
| 437 | 469 | |
| 438 | 470 | // Language files aren't loaded yet :(.  | 
                                                        
| 439 | 471 | $db_error = @$smcFunc['db_error']($db_connection);  | 
                                                        
@@ -490,8 +522,9 @@ discard block  | 
                                                    ||
| 490 | 522 | */  | 
                                                        
| 491 | 523 | function set_fatal_error_headers()  | 
                                                        
| 492 | 524 |  { | 
                                                        
| 493 | - if (headers_sent())  | 
                                                        |
| 494 | - return;  | 
                                                        |
| 525 | +	if (headers_sent()) { | 
                                                        |
| 526 | + return;  | 
                                                        |
| 527 | + }  | 
                                                        |
| 495 | 528 | |
| 496 | 529 | // Don't cache this page!  | 
                                                        
| 497 | 530 |  	header('expires: Mon, 26 Jul 1997 05:00:00 GMT'); | 
                                                        
@@ -517,12 +550,14 @@ discard block  | 
                                                    ||
| 517 | 550 | global $smcFunc, $user_info, $modSettings;  | 
                                                        
| 518 | 551 | |
| 519 | 552 | // Don't bother if Who's Online is disabled.  | 
                                                        
| 520 | - if (empty($modSettings['who_enabled']))  | 
                                                        |
| 521 | - return;  | 
                                                        |
| 553 | +	if (empty($modSettings['who_enabled'])) { | 
                                                        |
| 554 | + return;  | 
                                                        |
| 555 | + }  | 
                                                        |
| 522 | 556 | |
| 523 | 557 | // Maybe they came from SSI or similar where sessions are not recorded?  | 
                                                        
| 524 | - if (SMF == 'SSI' || SMF == 'BACKGROUND')  | 
                                                        |
| 525 | - return;  | 
                                                        |
| 558 | +	if (SMF == 'SSI' || SMF == 'BACKGROUND') { | 
                                                        |
| 559 | + return;  | 
                                                        |
| 560 | + }  | 
                                                        |
| 526 | 561 | |
| 527 | 562 | $session_id = !empty($user_info['is_guest']) ? 'ip' . $user_info['ip'] : session_id();  | 
                                                        
| 528 | 563 | |
@@ -548,11 +583,13 @@ discard block  | 
                                                    ||
| 548 | 583 | $url = $smcFunc['json_decode']($url, true);  | 
                                                        
| 549 | 584 | $url['error'] = $error;  | 
                                                        
| 550 | 585 | // Url field got a max length of 1024 in db  | 
                                                        
| 551 | - if (strlen($url['error']) > 500)  | 
                                                        |
| 552 | - $url['error'] = substr($url['error'],0,500);  | 
                                                        |
| 586 | +		if (strlen($url['error']) > 500) { | 
                                                        |
| 587 | + $url['error'] = substr($url['error'],0,500);  | 
                                                        |
| 588 | + }  | 
                                                        |
| 553 | 589 | |
| 554 | - if (!empty($sprintf))  | 
                                                        |
| 555 | - $url['error_params'] = $sprintf;  | 
                                                        |
| 590 | +		if (!empty($sprintf)) { | 
                                                        |
| 591 | + $url['error_params'] = $sprintf;  | 
                                                        |
| 592 | + }  | 
                                                        |
| 556 | 593 | |
| 557 | 594 |  		$smcFunc['db_query']('', ' | 
                                                        
| 558 | 595 |  			UPDATE {db_prefix}log_online | 
                                                        
@@ -583,10 +620,11 @@ discard block  | 
                                                    ||
| 583 | 620 | |
| 584 | 621 |  	$protocol = preg_match('~HTTP/1\.[01]~i', $_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'; | 
                                                        
| 585 | 622 | |
| 586 | - if (!isset($statuses[$code]))  | 
                                                        |
| 587 | - header($protocol . ' 500 Internal Server Error');  | 
                                                        |
| 588 | - else  | 
                                                        |
| 589 | - header($protocol . ' ' . $code . ' ' . $statuses[$code]);  | 
                                                        |
| 590 | -}  | 
                                                        |
| 623 | +	if (!isset($statuses[$code])) { | 
                                                        |
| 624 | + header($protocol . ' 500 Internal Server Error');  | 
                                                        |
| 625 | +	} else { | 
                                                        |
| 626 | + header($protocol . ' ' . $code . ' ' . $statuses[$code]);  | 
                                                        |
| 627 | + }  | 
                                                        |
| 628 | + }  | 
                                                        |
| 591 | 629 | |
| 592 | 630 | ?>  | 
                                                        
| 593 | 631 | \ 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 4  | 
                                                        
| 15 | 15 | */  | 
                                                        
| 16 | 16 | |
| 17 | -if (!defined('SMF')) | 
                                                        |
| 17 | +if (!defined('SMF')) { | 
                                                        |
| 18 | 18 |  	die('No direct access...'); | 
                                                        
| 19 | +}  | 
                                                        |
| 19 | 20 | |
| 20 | 21 | /**  | 
                                                        
| 21 | 22 | * 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(  | 
                                                        
@@ -320,8 +325,9 @@ discard block  | 
                                                    ||
| 320 | 325 | )  | 
                                                        
| 321 | 326 | );  | 
                                                        
| 322 | 327 | $bans = array();  | 
                                                        
| 323 | - while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        |
| 324 | - $bans[] = $row;  | 
                                                        |
| 328 | +	while ($row = $smcFunc['db_fetch_assoc']($request)) { | 
                                                        |
| 329 | + $bans[] = $row;  | 
                                                        |
| 330 | + }  | 
                                                        |
| 325 | 331 | |
| 326 | 332 | $smcFunc['db_free_result']($request);  | 
                                                        
| 327 | 333 | |
@@ -363,8 +369,9 @@ discard block  | 
                                                    ||
| 363 | 369 |  { | 
                                                        
| 364 | 370 | global $txt, $modSettings, $context, $scripturl, $smcFunc, $sourcedir;  | 
                                                        
| 365 | 371 | |
| 366 | - if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors']))  | 
                                                        |
| 367 | - BanEdit2();  | 
                                                        |
| 372 | +	if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors'])) { | 
                                                        |
| 373 | + BanEdit2();  | 
                                                        |
| 374 | + }  | 
                                                        |
| 368 | 375 | |
| 369 | 376 | $ban_group_id = isset($context['ban']['id']) ? $context['ban']['id'] : (isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0);  | 
                                                        
| 370 | 377 | |
@@ -373,11 +380,10 @@ discard block  | 
                                                    ||
| 373 | 380 |  	createToken('admin-bet'); | 
                                                        
| 374 | 381 | $context['form_url'] = $scripturl . '?action=admin;area=ban;sa=edit';  | 
                                                        
| 375 | 382 | |
| 376 | - if (!empty($context['ban_errors']))  | 
                                                        |
| 377 | - foreach ($context['ban_errors'] as $error)  | 
                                                        |
| 383 | +	if (!empty($context['ban_errors'])) { | 
                                                        |
| 384 | + foreach ($context['ban_errors'] as $error)  | 
                                                        |
| 378 | 385 | $context['error_messages'][$error] = $txt[$error];  | 
                                                        
| 379 | -  | 
                                                        |
| 380 | - else  | 
                                                        |
| 386 | + } else  | 
                                                        |
| 381 | 387 |  	{ | 
                                                        
| 382 | 388 | // If we're editing an existing ban, get it from the database.  | 
                                                        
| 383 | 389 | if (!empty($ban_group_id))  | 
                                                        
@@ -413,12 +419,13 @@ discard block  | 
                                                    ||
| 413 | 419 | 'data' => array(  | 
                                                        
| 414 | 420 | 'function' => function($ban_item) use ($txt)  | 
                                                        
| 415 | 421 |  							{ | 
                                                        
| 416 | -								if (in_array($ban_item['type'], array('ip', 'hostname', 'email'))) | 
                                                        |
| 417 | - return '<strong>' . $txt[$ban_item['type']] . ':</strong> ' . $ban_item[$ban_item['type']];  | 
                                                        |
| 418 | - elseif ($ban_item['type'] == 'user')  | 
                                                        |
| 419 | - return '<strong>' . $txt['username'] . ':</strong> ' . $ban_item['user']['link'];  | 
                                                        |
| 420 | - else  | 
                                                        |
| 421 | - return '<strong>' . $txt['unknown'] . ':</strong> ' . $ban_item['no_bantype_selected'];  | 
                                                        |
| 422 | +								if (in_array($ban_item['type'], array('ip', 'hostname', 'email'))) { | 
                                                        |
| 423 | + return '<strong>' . $txt[$ban_item['type']] . ':</strong> ' . $ban_item[$ban_item['type']];  | 
                                                        |
| 424 | +								} elseif ($ban_item['type'] == 'user') { | 
                                                        |
| 425 | + return '<strong>' . $txt['username'] . ':</strong> ' . $ban_item['user']['link'];  | 
                                                        |
| 426 | +								} else { | 
                                                        |
| 427 | + return '<strong>' . $txt['unknown'] . ':</strong> ' . $ban_item['no_bantype_selected'];  | 
                                                        |
| 428 | + }  | 
                                                        |
| 422 | 429 | },  | 
                                                        
| 423 | 430 | 'style' => 'text-align: left;',  | 
                                                        
| 424 | 431 | ),  | 
                                                        
@@ -556,8 +563,9 @@ discard block  | 
                                                    ||
| 556 | 563 | $context['ban']['from_user'] = true;  | 
                                                        
| 557 | 564 | |
| 558 | 565 | // Would be nice if we could also ban the hostname.  | 
                                                        
| 559 | -					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'])) | 
                                                        |
| 560 | - $context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']);  | 
                                                        |
| 566 | +					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'])) { | 
                                                        |
| 567 | + $context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']);  | 
                                                        |
| 568 | + }  | 
                                                        |
| 561 | 569 | |
| 562 | 570 | $context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);  | 
                                                        
| 563 | 571 | }  | 
                                                        
@@ -625,8 +633,9 @@ discard block  | 
                                                    ||
| 625 | 633 | 'items_per_page' => $items_per_page,  | 
                                                        
| 626 | 634 | )  | 
                                                        
| 627 | 635 | );  | 
                                                        
| 628 | - if ($smcFunc['db_num_rows']($request) == 0)  | 
                                                        |
| 629 | -		fatal_lang_error('ban_not_found', false); | 
                                                        |
| 636 | +	if ($smcFunc['db_num_rows']($request) == 0) { | 
                                                        |
| 637 | +			fatal_lang_error('ban_not_found', false); | 
                                                        |
| 638 | + }  | 
                                                        |
| 630 | 639 | |
| 631 | 640 | while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        
| 632 | 641 |  	{ | 
                                                        
@@ -663,18 +672,15 @@ discard block  | 
                                                    ||
| 663 | 672 |  			{ | 
                                                        
| 664 | 673 | $ban_items[$row['id_ban']]['type'] = 'ip';  | 
                                                        
| 665 | 674 | $ban_items[$row['id_ban']]['ip'] = range2ip($row['ip_low'], $row['ip_high']);  | 
                                                        
| 666 | - }  | 
                                                        |
| 667 | - elseif (!empty($row['hostname']))  | 
                                                        |
| 675 | + } elseif (!empty($row['hostname']))  | 
                                                        |
| 668 | 676 |  			{ | 
                                                        
| 669 | 677 | $ban_items[$row['id_ban']]['type'] = 'hostname';  | 
                                                        
| 670 | 678 |  				$ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']); | 
                                                        
| 671 | - }  | 
                                                        |
| 672 | - elseif (!empty($row['email_address']))  | 
                                                        |
| 679 | + } elseif (!empty($row['email_address']))  | 
                                                        |
| 673 | 680 |  			{ | 
                                                        
| 674 | 681 | $ban_items[$row['id_ban']]['type'] = 'email';  | 
                                                        
| 675 | 682 |  				$ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']); | 
                                                        
| 676 | - }  | 
                                                        |
| 677 | - elseif (!empty($row['id_member']))  | 
                                                        |
| 683 | + } elseif (!empty($row['id_member']))  | 
                                                        |
| 678 | 684 |  			{ | 
                                                        
| 679 | 685 | $ban_items[$row['id_ban']]['type'] = 'user';  | 
                                                        
| 680 | 686 | $ban_items[$row['id_ban']]['user'] = array(  | 
                                                        
@@ -740,9 +746,10 @@ discard block  | 
                                                    ||
| 740 | 746 |  	$search_list += array('ips_in_messages' => 'banLoadAdditionalIPsMember', 'ips_in_errors' => 'banLoadAdditionalIPsError'); | 
                                                        
| 741 | 747 | |
| 742 | 748 | $return = array();  | 
                                                        
| 743 | - foreach ($search_list as $key => $callable)  | 
                                                        |
| 744 | - if (is_callable($callable))  | 
                                                        |
| 749 | +	foreach ($search_list as $key => $callable) { | 
                                                        |
| 750 | + if (is_callable($callable))  | 
                                                        |
| 745 | 751 | $return[$key] = call_user_func($callable, $member_id);  | 
                                                        
| 752 | + }  | 
                                                        |
| 746 | 753 | |
| 747 | 754 | return $return;  | 
                                                        
| 748 | 755 | }  | 
                                                        
@@ -767,8 +774,9 @@ discard block  | 
                                                    ||
| 767 | 774 | 'current_user' => $member_id,  | 
                                                        
| 768 | 775 | )  | 
                                                        
| 769 | 776 | );  | 
                                                        
| 770 | - while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        |
| 771 | - $message_ips[] = inet_dtop($row['poster_ip']);  | 
                                                        |
| 777 | +	while ($row = $smcFunc['db_fetch_assoc']($request)) { | 
                                                        |
| 778 | + $message_ips[] = inet_dtop($row['poster_ip']);  | 
                                                        |
| 779 | + }  | 
                                                        |
| 772 | 780 | $smcFunc['db_free_result']($request);  | 
                                                        
| 773 | 781 | |
| 774 | 782 | return $message_ips;  | 
                                                        
@@ -793,8 +801,9 @@ discard block  | 
                                                    ||
| 793 | 801 | 'current_user' => $member_id,  | 
                                                        
| 794 | 802 | )  | 
                                                        
| 795 | 803 | );  | 
                                                        
| 796 | - while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        |
| 797 | - $error_ips[] = inet_dtop($row['ip']);  | 
                                                        |
| 804 | +	while ($row = $smcFunc['db_fetch_assoc']($request)) { | 
                                                        |
| 805 | + $error_ips[] = inet_dtop($row['ip']);  | 
                                                        |
| 806 | + }  | 
                                                        |
| 798 | 807 | $smcFunc['db_free_result']($request);  | 
                                                        
| 799 | 808 | |
| 800 | 809 | return $error_ips;  | 
                                                        
@@ -835,11 +844,13 @@ discard block  | 
                                                    ||
| 835 | 844 | $ban_info['cannot']['login'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_login']) ? 0 : 1;  | 
                                                        
| 836 | 845 | |
| 837 | 846 | // Adding a new ban group  | 
                                                        
| 838 | - if (empty($_REQUEST['bg']))  | 
                                                        |
| 839 | - $ban_group_id = insertBanGroup($ban_info);  | 
                                                        |
| 847 | +		if (empty($_REQUEST['bg'])) { | 
                                                        |
| 848 | + $ban_group_id = insertBanGroup($ban_info);  | 
                                                        |
| 849 | + }  | 
                                                        |
| 840 | 850 | // Editing an existing ban group  | 
                                                        
| 841 | - else  | 
                                                        |
| 842 | - $ban_group_id = updateBanGroup($ban_info);  | 
                                                        |
| 851 | +		else { | 
                                                        |
| 852 | + $ban_group_id = updateBanGroup($ban_info);  | 
                                                        |
| 853 | + }  | 
                                                        |
| 843 | 854 | |
| 844 | 855 | if (is_numeric($ban_group_id))  | 
                                                        
| 845 | 856 |  		{ | 
                                                        
@@ -850,9 +861,10 @@ discard block  | 
                                                    ||
| 850 | 861 | $context['ban'] = $ban_info;  | 
                                                        
| 851 | 862 | }  | 
                                                        
| 852 | 863 | |
| 853 | - if (isset($_POST['ban_suggestions']))  | 
                                                        |
| 854 | - // @TODO: is $_REQUEST['bi'] ever set?  | 
                                                        |
| 864 | +	if (isset($_POST['ban_suggestions'])) { | 
                                                        |
| 865 | + // @TODO: is $_REQUEST['bi'] ever set?  | 
                                                        |
| 855 | 866 | $saved_triggers = saveTriggers($_POST['ban_suggestions'], $ban_info['id'], isset($_REQUEST['u']) ? (int) $_REQUEST['u'] : 0, isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0);  | 
                                                        
| 867 | + }  | 
                                                        |
| 856 | 868 | |
| 857 | 869 | // Something went wrong somewhere... Oh well, let's go back.  | 
                                                        
| 858 | 870 | if (!empty($context['ban_errors']))  | 
                                                        
@@ -862,8 +874,9 @@ discard block  | 
                                                    ||
| 862 | 874 | $context['ban_suggestions'] = array_merge($context['ban_suggestions'], getMemberData((int) $_REQUEST['u']));  | 
                                                        
| 863 | 875 | |
| 864 | 876 | // Not strictly necessary, but it's nice  | 
                                                        
| 865 | - if (!empty($context['ban_suggestions']['member']['id']))  | 
                                                        |
| 866 | - $context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);  | 
                                                        |
| 877 | +		if (!empty($context['ban_suggestions']['member']['id'])) { | 
                                                        |
| 878 | + $context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);  | 
                                                        |
| 879 | + }  | 
                                                        |
| 867 | 880 | return BanEdit();  | 
                                                        
| 868 | 881 | }  | 
                                                        
| 869 | 882 | $context['ban_suggestions']['saved_triggers'] = !empty($saved_triggers) ? $saved_triggers : array();  | 
                                                        
@@ -910,10 +923,11 @@ discard block  | 
                                                    ||
| 910 | 923 | |
| 911 | 924 | foreach ($suggestions as $key => $value)  | 
                                                        
| 912 | 925 |  	{ | 
                                                        
| 913 | - if (is_array($value))  | 
                                                        |
| 914 | - $triggers[$key] = $value;  | 
                                                        |
| 915 | - else  | 
                                                        |
| 916 | - $triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : '';  | 
                                                        |
| 926 | +		if (is_array($value)) { | 
                                                        |
| 927 | + $triggers[$key] = $value;  | 
                                                        |
| 928 | +		} else { | 
                                                        |
| 929 | + $triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : '';  | 
                                                        |
| 930 | + }  | 
                                                        |
| 917 | 931 | }  | 
                                                        
| 918 | 932 | |
| 919 | 933 | $ban_triggers = validateTriggers($triggers);  | 
                                                        
@@ -921,16 +935,18 @@ discard block  | 
                                                    ||
| 921 | 935 | // Time to save!  | 
                                                        
| 922 | 936 | if (!empty($ban_triggers['ban_triggers']) && empty($context['ban_errors']))  | 
                                                        
| 923 | 937 |  	{ | 
                                                        
| 924 | - if (empty($ban_id))  | 
                                                        |
| 925 | - addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']);  | 
                                                        |
| 926 | - else  | 
                                                        |
| 927 | - updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']);  | 
                                                        |
| 938 | +		if (empty($ban_id)) { | 
                                                        |
| 939 | + addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']);  | 
                                                        |
| 940 | +		} else { | 
                                                        |
| 941 | + updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']);  | 
                                                        |
| 942 | + }  | 
                                                        |
| 943 | + }  | 
                                                        |
| 944 | +	if (!empty($context['ban_errors'])) { | 
                                                        |
| 945 | + return $triggers;  | 
                                                        |
| 946 | +	} else { | 
                                                        |
| 947 | + return false;  | 
                                                        |
| 948 | + }  | 
                                                        |
| 928 | 949 | }  | 
                                                        
| 929 | - if (!empty($context['ban_errors']))  | 
                                                        |
| 930 | - return $triggers;  | 
                                                        |
| 931 | - else  | 
                                                        |
| 932 | - return false;  | 
                                                        |
| 933 | -}  | 
                                                        |
| 934 | 950 | |
| 935 | 951 | /**  | 
                                                        
| 936 | 952 | * This function removes a bunch of triggers based on ids  | 
                                                        
@@ -944,14 +960,17 @@ discard block  | 
                                                    ||
| 944 | 960 |  { | 
                                                        
| 945 | 961 | global $smcFunc, $scripturl;  | 
                                                        
| 946 | 962 | |
| 947 | - if ($group_id !== false)  | 
                                                        |
| 948 | - $group_id = (int) $group_id;  | 
                                                        |
| 963 | +	if ($group_id !== false) { | 
                                                        |
| 964 | + $group_id = (int) $group_id;  | 
                                                        |
| 965 | + }  | 
                                                        |
| 949 | 966 | |
| 950 | - if (empty($group_id) && empty($items_ids))  | 
                                                        |
| 951 | - return false;  | 
                                                        |
| 967 | +	if (empty($group_id) && empty($items_ids)) { | 
                                                        |
| 968 | + return false;  | 
                                                        |
| 969 | + }  | 
                                                        |
| 952 | 970 | |
| 953 | - if (!is_array($items_ids))  | 
                                                        |
| 954 | - $items_ids = array($items_ids);  | 
                                                        |
| 971 | +	if (!is_array($items_ids)) { | 
                                                        |
| 972 | + $items_ids = array($items_ids);  | 
                                                        |
| 973 | + }  | 
                                                        |
| 955 | 974 | |
| 956 | 975 | $log_info = array();  | 
                                                        
| 957 | 976 | $ban_items = array();  | 
                                                        
@@ -989,8 +1008,7 @@ discard block  | 
                                                    ||
| 989 | 1008 | 'bantype' => ($is_range ? 'ip_range' : 'main_ip'),  | 
                                                        
| 990 | 1009 | 'value' => $ban_items[$row['id_ban']]['ip'],  | 
                                                        
| 991 | 1010 | );  | 
                                                        
| 992 | - }  | 
                                                        |
| 993 | - elseif (!empty($row['hostname']))  | 
                                                        |
| 1011 | + } elseif (!empty($row['hostname']))  | 
                                                        |
| 994 | 1012 |  			{ | 
                                                        
| 995 | 1013 | $ban_items[$row['id_ban']]['type'] = 'hostname';  | 
                                                        
| 996 | 1014 |  				$ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']); | 
                                                        
@@ -998,8 +1016,7 @@ discard block  | 
                                                    ||
| 998 | 1016 | 'bantype' => 'hostname',  | 
                                                        
| 999 | 1017 | 'value' => $row['hostname'],  | 
                                                        
| 1000 | 1018 | );  | 
                                                        
| 1001 | - }  | 
                                                        |
| 1002 | - elseif (!empty($row['email_address']))  | 
                                                        |
| 1019 | + } elseif (!empty($row['email_address']))  | 
                                                        |
| 1003 | 1020 |  			{ | 
                                                        
| 1004 | 1021 | $ban_items[$row['id_ban']]['type'] = 'email';  | 
                                                        
| 1005 | 1022 |  				$ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']); | 
                                                        
@@ -1007,8 +1024,7 @@ discard block  | 
                                                    ||
| 1007 | 1024 | 'bantype' => 'email',  | 
                                                        
| 1008 | 1025 | 'value' => $ban_items[$row['id_ban']]['email'],  | 
                                                        
| 1009 | 1026 | );  | 
                                                        
| 1010 | - }  | 
                                                        |
| 1011 | - elseif (!empty($row['id_member']))  | 
                                                        |
| 1027 | + } elseif (!empty($row['id_member']))  | 
                                                        |
| 1012 | 1028 |  			{ | 
                                                        
| 1013 | 1029 | $ban_items[$row['id_ban']]['type'] = 'user';  | 
                                                        
| 1014 | 1030 | $ban_items[$row['id_ban']]['user'] = array(  | 
                                                        
@@ -1041,8 +1057,7 @@ discard block  | 
                                                    ||
| 1041 | 1057 | 'ban_group' => $group_id,  | 
                                                        
| 1042 | 1058 | )  | 
                                                        
| 1043 | 1059 | );  | 
                                                        
| 1044 | - }  | 
                                                        |
| 1045 | - elseif (!empty($items_ids))  | 
                                                        |
| 1060 | + } elseif (!empty($items_ids))  | 
                                                        |
| 1046 | 1061 |  	{ | 
                                                        
| 1047 | 1062 |  		$smcFunc['db_query']('', ' | 
                                                        
| 1048 | 1063 |  			DELETE FROM {db_prefix}ban_items | 
                                                        
@@ -1067,13 +1082,15 @@ discard block  | 
                                                    ||
| 1067 | 1082 |  { | 
                                                        
| 1068 | 1083 | global $smcFunc;  | 
                                                        
| 1069 | 1084 | |
| 1070 | - if (!is_array($group_ids))  | 
                                                        |
| 1071 | - $group_ids = array($group_ids);  | 
                                                        |
| 1085 | +	if (!is_array($group_ids)) { | 
                                                        |
| 1086 | + $group_ids = array($group_ids);  | 
                                                        |
| 1087 | + }  | 
                                                        |
| 1072 | 1088 | |
| 1073 | 1089 | $group_ids = array_unique($group_ids);  | 
                                                        
| 1074 | 1090 | |
| 1075 | - if (empty($group_ids))  | 
                                                        |
| 1076 | - return false;  | 
                                                        |
| 1091 | +	if (empty($group_ids)) { | 
                                                        |
| 1092 | + return false;  | 
                                                        |
| 1093 | + }  | 
                                                        |
| 1077 | 1094 | |
| 1078 | 1095 |  	$smcFunc['db_query']('', ' | 
                                                        
| 1079 | 1096 |  		DELETE FROM {db_prefix}ban_groups | 
                                                        
@@ -1097,21 +1114,23 @@ discard block  | 
                                                    ||
| 1097 | 1114 |  { | 
                                                        
| 1098 | 1115 | global $smcFunc;  | 
                                                        
| 1099 | 1116 | |
| 1100 | - if (empty($ids))  | 
                                                        |
| 1101 | -		$smcFunc['db_query']('truncate_table', ' | 
                                                        |
| 1117 | +	if (empty($ids)) { | 
                                                        |
| 1118 | +			$smcFunc['db_query']('truncate_table', ' | 
                                                        |
| 1102 | 1119 |  			TRUNCATE {db_prefix}log_banned', | 
                                                        
| 1103 | 1120 | array(  | 
                                                        
| 1104 | 1121 | )  | 
                                                        
| 1105 | 1122 | );  | 
                                                        
| 1106 | - else  | 
                                                        |
| 1123 | + } else  | 
                                                        |
| 1107 | 1124 |  	{ | 
                                                        
| 1108 | - if (!is_array($ids))  | 
                                                        |
| 1109 | - $ids = array($ids);  | 
                                                        |
| 1125 | +		if (!is_array($ids)) { | 
                                                        |
| 1126 | + $ids = array($ids);  | 
                                                        |
| 1127 | + }  | 
                                                        |
| 1110 | 1128 | |
| 1111 | 1129 | $ids = array_unique($ids);  | 
                                                        
| 1112 | 1130 | |
| 1113 | - if (empty($ids))  | 
                                                        |
| 1114 | - return false;  | 
                                                        |
| 1131 | +		if (empty($ids)) { | 
                                                        |
| 1132 | + return false;  | 
                                                        |
| 1133 | + }  | 
                                                        |
| 1115 | 1134 | |
| 1116 | 1135 |  		$smcFunc['db_query']('', ' | 
                                                        
| 1117 | 1136 |  			DELETE FROM {db_prefix}log_banned | 
                                                        
@@ -1137,8 +1156,9 @@ discard block  | 
                                                    ||
| 1137 | 1156 |  { | 
                                                        
| 1138 | 1157 | global $context, $smcFunc;  | 
                                                        
| 1139 | 1158 | |
| 1140 | - if (empty($triggers))  | 
                                                        |
| 1141 | - $context['ban_erros'][] = 'ban_empty_triggers';  | 
                                                        |
| 1159 | +	if (empty($triggers)) { | 
                                                        |
| 1160 | + $context['ban_erros'][] = 'ban_empty_triggers';  | 
                                                        |
| 1161 | + }  | 
                                                        |
| 1142 | 1162 | |
| 1143 | 1163 | $ban_triggers = array();  | 
                                                        
| 1144 | 1164 | $log_info = array();  | 
                                                        
@@ -1147,39 +1167,39 @@ discard block  | 
                                                    ||
| 1147 | 1167 |  	{ | 
                                                        
| 1148 | 1168 | if (!empty($value))  | 
                                                        
| 1149 | 1169 |  		{ | 
                                                        
| 1150 | - if ($key == 'member')  | 
                                                        |
| 1151 | - continue;  | 
                                                        |
| 1170 | +			if ($key == 'member') { | 
                                                        |
| 1171 | + continue;  | 
                                                        |
| 1172 | + }  | 
                                                        |
| 1152 | 1173 | |
| 1153 | 1174 | if ($key == 'main_ip')  | 
                                                        
| 1154 | 1175 |  			{ | 
                                                        
| 1155 | 1176 | $value = trim($value);  | 
                                                        
| 1156 | 1177 | $ip_parts = ip2range($value);  | 
                                                        
| 1157 | - if (!checkExistingTriggerIP($ip_parts, $value))  | 
                                                        |
| 1158 | - $context['ban_erros'][] = 'invalid_ip';  | 
                                                        |
| 1159 | - else  | 
                                                        |
| 1178 | +				if (!checkExistingTriggerIP($ip_parts, $value)) { | 
                                                        |
| 1179 | + $context['ban_erros'][] = 'invalid_ip';  | 
                                                        |
| 1180 | + } else  | 
                                                        |
| 1160 | 1181 |  				{ | 
                                                        
| 1161 | 1182 | $ban_triggers['main_ip'] = array(  | 
                                                        
| 1162 | 1183 | 'ip_low' => $ip_parts['low'],  | 
                                                        
| 1163 | 1184 | 'ip_high' => $ip_parts['high']  | 
                                                        
| 1164 | 1185 | );  | 
                                                        
| 1165 | 1186 | }  | 
                                                        
| 1166 | - }  | 
                                                        |
| 1167 | - elseif ($key == 'hostname')  | 
                                                        |
| 1187 | + } elseif ($key == 'hostname')  | 
                                                        |
| 1168 | 1188 |  			{ | 
                                                        
| 1169 | -				if (preg_match('/[^\w.\-*]/', $value) == 1) | 
                                                        |
| 1170 | - $context['ban_erros'][] = 'invalid_hostname';  | 
                                                        |
| 1171 | - else  | 
                                                        |
| 1189 | +				if (preg_match('/[^\w.\-*]/', $value) == 1) { | 
                                                        |
| 1190 | + $context['ban_erros'][] = 'invalid_hostname';  | 
                                                        |
| 1191 | + } else  | 
                                                        |
| 1172 | 1192 |  				{ | 
                                                        
| 1173 | 1193 | // Replace the * wildcard by a MySQL wildcard %.  | 
                                                        
| 1174 | 1194 |  					$value = substr(str_replace('*', '%', $value), 0, 255); | 
                                                        
| 1175 | 1195 | |
| 1176 | 1196 | $ban_triggers['hostname']['hostname'] = $value;  | 
                                                        
| 1177 | 1197 | }  | 
                                                        
| 1178 | - }  | 
                                                        |
| 1179 | - elseif ($key == 'email')  | 
                                                        |
| 1198 | + } elseif ($key == 'email')  | 
                                                        |
| 1180 | 1199 |  			{ | 
                                                        
| 1181 | -				if (preg_match('/[^\w.\-\+*@]/', $value) == 1) | 
                                                        |
| 1182 | - $context['ban_erros'][] = 'invalid_email';  | 
                                                        |
| 1200 | +				if (preg_match('/[^\w.\-\+*@]/', $value) == 1) { | 
                                                        |
| 1201 | + $context['ban_erros'][] = 'invalid_email';  | 
                                                        |
| 1202 | + }  | 
                                                        |
| 1183 | 1203 | |
| 1184 | 1204 | // Check the user is not banning an admin.  | 
                                                        
| 1185 | 1205 |  				$request = $smcFunc['db_query']('', ' | 
                                                        
@@ -1193,15 +1213,15 @@ discard block  | 
                                                    ||
| 1193 | 1213 | 'email' => $value,  | 
                                                        
| 1194 | 1214 | )  | 
                                                        
| 1195 | 1215 | );  | 
                                                        
| 1196 | - if ($smcFunc['db_num_rows']($request) != 0)  | 
                                                        |
| 1197 | - $context['ban_erros'][] = 'no_ban_admin';  | 
                                                        |
| 1216 | +				if ($smcFunc['db_num_rows']($request) != 0) { | 
                                                        |
| 1217 | + $context['ban_erros'][] = 'no_ban_admin';  | 
                                                        |
| 1218 | + }  | 
                                                        |
| 1198 | 1219 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1199 | 1220 | |
| 1200 | 1221 |  				$value = substr(strtolower(str_replace('*', '%', $value)), 0, 255); | 
                                                        
| 1201 | 1222 | |
| 1202 | 1223 | $ban_triggers['email']['email_address'] = $value;  | 
                                                        
| 1203 | - }  | 
                                                        |
| 1204 | - elseif ($key == 'user')  | 
                                                        |
| 1224 | + } elseif ($key == 'user')  | 
                                                        |
| 1205 | 1225 |  			{ | 
                                                        
| 1206 | 1226 |  				$user = preg_replace('~&#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $smcFunc['htmlspecialchars']($value, ENT_QUOTES)); | 
                                                        
| 1207 | 1227 | |
@@ -1215,8 +1235,9 @@ discard block  | 
                                                    ||
| 1215 | 1235 | 'username' => $user,  | 
                                                        
| 1216 | 1236 | )  | 
                                                        
| 1217 | 1237 | );  | 
                                                        
| 1218 | - if ($smcFunc['db_num_rows']($request) == 0)  | 
                                                        |
| 1219 | - $context['ban_erros'][] = 'invalid_username';  | 
                                                        |
| 1238 | +				if ($smcFunc['db_num_rows']($request) == 0) { | 
                                                        |
| 1239 | + $context['ban_erros'][] = 'invalid_username';  | 
                                                        |
| 1240 | + }  | 
                                                        |
| 1220 | 1241 | list ($value, $isAdmin) = $smcFunc['db_fetch_row']($request);  | 
                                                        
| 1221 | 1242 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1222 | 1243 | |
@@ -1224,25 +1245,25 @@ discard block  | 
                                                    ||
| 1224 | 1245 |  				{ | 
                                                        
| 1225 | 1246 | unset($value);  | 
                                                        
| 1226 | 1247 | $context['ban_erros'][] = 'no_ban_admin';  | 
                                                        
| 1248 | +				} else { | 
                                                        |
| 1249 | + $ban_triggers['user']['id_member'] = $value;  | 
                                                        |
| 1227 | 1250 | }  | 
                                                        
| 1228 | - else  | 
                                                        |
| 1229 | - $ban_triggers['user']['id_member'] = $value;  | 
                                                        |
| 1230 | - }  | 
                                                        |
| 1231 | -			elseif (in_array($key, array('ips_in_messages', 'ips_in_errors'))) | 
                                                        |
| 1251 | +			} elseif (in_array($key, array('ips_in_messages', 'ips_in_errors'))) | 
                                                        |
| 1232 | 1252 |  			{ | 
                                                        
| 1233 | 1253 | // Special case, those two are arrays themselves  | 
                                                        
| 1234 | 1254 | $values = array_unique($value);  | 
                                                        
| 1235 | 1255 | // Don't add the main IP again.  | 
                                                        
| 1236 | - if (isset($triggers['main_ip']))  | 
                                                        |
| 1237 | - $values = array_diff($values, array($triggers['main_ip']));  | 
                                                        |
| 1256 | +				if (isset($triggers['main_ip'])) { | 
                                                        |
| 1257 | + $values = array_diff($values, array($triggers['main_ip']));  | 
                                                        |
| 1258 | + }  | 
                                                        |
| 1238 | 1259 | unset($value);  | 
                                                        
| 1239 | 1260 | foreach ($values as $val)  | 
                                                        
| 1240 | 1261 |  				{ | 
                                                        
| 1241 | 1262 | $val = trim($val);  | 
                                                        
| 1242 | 1263 | $ip_parts = ip2range($val);  | 
                                                        
| 1243 | - if (!checkExistingTriggerIP($ip_parts, $val))  | 
                                                        |
| 1244 | - $context['ban_erros'][] = 'invalid_ip';  | 
                                                        |
| 1245 | - else  | 
                                                        |
| 1264 | +					if (!checkExistingTriggerIP($ip_parts, $val)) { | 
                                                        |
| 1265 | + $context['ban_erros'][] = 'invalid_ip';  | 
                                                        |
| 1266 | + } else  | 
                                                        |
| 1246 | 1267 |  					{ | 
                                                        
| 1247 | 1268 | $ban_triggers[$key][] = array(  | 
                                                        
| 1248 | 1269 | 'ip_low' => $ip_parts['low'],  | 
                                                        
@@ -1255,15 +1276,16 @@ discard block  | 
                                                    ||
| 1255 | 1276 | );  | 
                                                        
| 1256 | 1277 | }  | 
                                                        
| 1257 | 1278 | }  | 
                                                        
| 1279 | +			} else { | 
                                                        |
| 1280 | + $context['ban_erros'][] = 'no_bantype_selected';  | 
                                                        |
| 1258 | 1281 | }  | 
                                                        
| 1259 | - else  | 
                                                        |
| 1260 | - $context['ban_erros'][] = 'no_bantype_selected';  | 
                                                        |
| 1261 | 1282 | |
| 1262 | - if (isset($value) && !is_array($value))  | 
                                                        |
| 1263 | - $log_info[] = array(  | 
                                                        |
| 1283 | +			if (isset($value) && !is_array($value)) { | 
                                                        |
| 1284 | + $log_info[] = array(  | 
                                                        |
| 1264 | 1285 | 'value' => $value,  | 
                                                        
| 1265 | 1286 | 'bantype' => $key,  | 
                                                        
| 1266 | 1287 | );  | 
                                                        
| 1288 | + }  | 
                                                        |
| 1267 | 1289 | }  | 
                                                        
| 1268 | 1290 | }  | 
                                                        
| 1269 | 1291 |  	return array('ban_triggers' => $ban_triggers, 'log_info' => $log_info); | 
                                                        
@@ -1283,8 +1305,9 @@ discard block  | 
                                                    ||
| 1283 | 1305 |  { | 
                                                        
| 1284 | 1306 | global $smcFunc, $context;  | 
                                                        
| 1285 | 1307 | |
| 1286 | - if (empty($group_id))  | 
                                                        |
| 1287 | - $context['ban_errors'][] = 'ban_id_empty';  | 
                                                        |
| 1308 | +	if (empty($group_id)) { | 
                                                        |
| 1309 | + $context['ban_errors'][] = 'ban_id_empty';  | 
                                                        |
| 1310 | + }  | 
                                                        |
| 1288 | 1311 | |
| 1289 | 1312 | // Preset all values that are required.  | 
                                                        
| 1290 | 1313 | $values = array(  | 
                                                        
@@ -1309,18 +1332,21 @@ discard block  | 
                                                    ||
| 1309 | 1332 | foreach ($triggers as $key => $trigger)  | 
                                                        
| 1310 | 1333 |  	{ | 
                                                        
| 1311 | 1334 | // Exceptions, exceptions, exceptions...always exceptions... :P  | 
                                                        
| 1312 | -		if (in_array($key, array('ips_in_messages', 'ips_in_errors'))) | 
                                                        |
| 1313 | - foreach ($trigger as $real_trigger)  | 
                                                        |
| 1335 | +		if (in_array($key, array('ips_in_messages', 'ips_in_errors'))) { | 
                                                        |
| 1336 | + foreach ($trigger as $real_trigger)  | 
                                                        |
| 1314 | 1337 | $insertTriggers[] = array_merge($values, $real_trigger);  | 
                                                        
| 1315 | - else  | 
                                                        |
| 1316 | - $insertTriggers[] = array_merge($values, $trigger);  | 
                                                        |
| 1338 | +		} else { | 
                                                        |
| 1339 | + $insertTriggers[] = array_merge($values, $trigger);  | 
                                                        |
| 1340 | + }  | 
                                                        |
| 1317 | 1341 | }  | 
                                                        
| 1318 | 1342 | |
| 1319 | - if (empty($insertTriggers))  | 
                                                        |
| 1320 | - $context['ban_errors'][] = 'ban_no_triggers';  | 
                                                        |
| 1343 | +	if (empty($insertTriggers)) { | 
                                                        |
| 1344 | + $context['ban_errors'][] = 'ban_no_triggers';  | 
                                                        |
| 1345 | + }  | 
                                                        |
| 1321 | 1346 | |
| 1322 | - if (!empty($context['ban_errors']))  | 
                                                        |
| 1323 | - return false;  | 
                                                        |
| 1347 | +	if (!empty($context['ban_errors'])) { | 
                                                        |
| 1348 | + return false;  | 
                                                        |
| 1349 | + }  | 
                                                        |
| 1324 | 1350 | |
| 1325 | 1351 |  	$smcFunc['db_insert']('', | 
                                                        
| 1326 | 1352 |  		'{db_prefix}ban_items', | 
                                                        
@@ -1348,15 +1374,19 @@ discard block  | 
                                                    ||
| 1348 | 1374 |  { | 
                                                        
| 1349 | 1375 | global $smcFunc, $context;  | 
                                                        
| 1350 | 1376 | |
| 1351 | - if (empty($ban_item))  | 
                                                        |
| 1352 | - $context['ban_errors'][] = 'ban_ban_item_empty';  | 
                                                        |
| 1353 | - if (empty($group_id))  | 
                                                        |
| 1354 | - $context['ban_errors'][] = 'ban_id_empty';  | 
                                                        |
| 1355 | - if (empty($trigger))  | 
                                                        |
| 1356 | - $context['ban_errors'][] = 'ban_no_triggers';  | 
                                                        |
| 1377 | +	if (empty($ban_item)) { | 
                                                        |
| 1378 | + $context['ban_errors'][] = 'ban_ban_item_empty';  | 
                                                        |
| 1379 | + }  | 
                                                        |
| 1380 | +	if (empty($group_id)) { | 
                                                        |
| 1381 | + $context['ban_errors'][] = 'ban_id_empty';  | 
                                                        |
| 1382 | + }  | 
                                                        |
| 1383 | +	if (empty($trigger)) { | 
                                                        |
| 1384 | + $context['ban_errors'][] = 'ban_no_triggers';  | 
                                                        |
| 1385 | + }  | 
                                                        |
| 1357 | 1386 | |
| 1358 | - if (!empty($context['ban_errors']))  | 
                                                        |
| 1359 | - return;  | 
                                                        |
| 1387 | +	if (!empty($context['ban_errors'])) { | 
                                                        |
| 1388 | + return;  | 
                                                        |
| 1389 | + }  | 
                                                        |
| 1360 | 1390 | |
| 1361 | 1391 | // Preset all values that are required.  | 
                                                        
| 1362 | 1392 | $values = array(  | 
                                                        
@@ -1397,8 +1427,9 @@ discard block  | 
                                                    ||
| 1397 | 1427 | */  | 
                                                        
| 1398 | 1428 | function logTriggersUpdates($logs, $new = true, $removal = false)  | 
                                                        
| 1399 | 1429 |  { | 
                                                        
| 1400 | - if (empty($logs))  | 
                                                        |
| 1401 | - return;  | 
                                                        |
| 1430 | +	if (empty($logs)) { | 
                                                        |
| 1431 | + return;  | 
                                                        |
| 1432 | + }  | 
                                                        |
| 1402 | 1433 | |
| 1403 | 1434 | $log_name_map = array(  | 
                                                        
| 1404 | 1435 | 'main_ip' => 'ip_range',  | 
                                                        
@@ -1409,14 +1440,15 @@ discard block  | 
                                                    ||
| 1409 | 1440 | );  | 
                                                        
| 1410 | 1441 | |
| 1411 | 1442 | // Log the addion of the ban entries into the moderation log.  | 
                                                        
| 1412 | - foreach ($logs as $log)  | 
                                                        |
| 1413 | -		logAction('ban' . ($removal == true ? 'remove' : ''), array( | 
                                                        |
| 1443 | +	foreach ($logs as $log) { | 
                                                        |
| 1444 | +			logAction('ban' . ($removal == true ? 'remove' : ''), array( | 
                                                        |
| 1414 | 1445 | $log_name_map[$log['bantype']] => $log['value'],  | 
                                                        
| 1415 | 1446 | 'new' => empty($new) ? 0 : 1,  | 
                                                        
| 1416 | 1447 | 'remove' => empty($removal) ? 0 : 1,  | 
                                                        
| 1417 | 1448 | 'type' => $log['bantype'],  | 
                                                        
| 1418 | 1449 | ));  | 
                                                        
| 1419 | -}  | 
                                                        |
| 1450 | + }  | 
                                                        |
| 1451 | + }  | 
                                                        |
| 1420 | 1452 | |
| 1421 | 1453 | /**  | 
                                                        
| 1422 | 1454 | * Updates an existing ban group  | 
                                                        
@@ -1430,12 +1462,15 @@ discard block  | 
                                                    ||
| 1430 | 1462 |  { | 
                                                        
| 1431 | 1463 | global $smcFunc, $context;  | 
                                                        
| 1432 | 1464 | |
| 1433 | - if (empty($ban_info['name']))  | 
                                                        |
| 1434 | - $context['ban_errors'][] = 'ban_name_empty';  | 
                                                        |
| 1435 | - if (empty($ban_info['id']))  | 
                                                        |
| 1436 | - $context['ban_errors'][] = 'ban_id_empty';  | 
                                                        |
| 1437 | - if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login']))  | 
                                                        |
| 1438 | - $context['ban_errors'][] = 'ban_unknown_restriction_type';  | 
                                                        |
| 1465 | +	if (empty($ban_info['name'])) { | 
                                                        |
| 1466 | + $context['ban_errors'][] = 'ban_name_empty';  | 
                                                        |
| 1467 | + }  | 
                                                        |
| 1468 | +	if (empty($ban_info['id'])) { | 
                                                        |
| 1469 | + $context['ban_errors'][] = 'ban_id_empty';  | 
                                                        |
| 1470 | + }  | 
                                                        |
| 1471 | +	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) { | 
                                                        |
| 1472 | + $context['ban_errors'][] = 'ban_unknown_restriction_type';  | 
                                                        |
| 1473 | + }  | 
                                                        |
| 1439 | 1474 | |
| 1440 | 1475 | if (!empty($ban_info['id']))  | 
                                                        
| 1441 | 1476 |  	{ | 
                                                        
@@ -1450,8 +1485,9 @@ discard block  | 
                                                    ||
| 1450 | 1485 | )  | 
                                                        
| 1451 | 1486 | );  | 
                                                        
| 1452 | 1487 | |
| 1453 | - if ($smcFunc['db_num_rows']($request) == 0)  | 
                                                        |
| 1454 | - $context['ban_errors'][] = 'ban_not_found';  | 
                                                        |
| 1488 | +		if ($smcFunc['db_num_rows']($request) == 0) { | 
                                                        |
| 1489 | + $context['ban_errors'][] = 'ban_not_found';  | 
                                                        |
| 1490 | + }  | 
                                                        |
| 1455 | 1491 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1456 | 1492 | }  | 
                                                        
| 1457 | 1493 | |
@@ -1469,13 +1505,15 @@ discard block  | 
                                                    ||
| 1469 | 1505 | 'new_ban_name' => $ban_info['name'],  | 
                                                        
| 1470 | 1506 | )  | 
                                                        
| 1471 | 1507 | );  | 
                                                        
| 1472 | - if ($smcFunc['db_num_rows']($request) != 0)  | 
                                                        |
| 1473 | - $context['ban_errors'][] = 'ban_name_exists';  | 
                                                        |
| 1508 | +		if ($smcFunc['db_num_rows']($request) != 0) { | 
                                                        |
| 1509 | + $context['ban_errors'][] = 'ban_name_exists';  | 
                                                        |
| 1510 | + }  | 
                                                        |
| 1474 | 1511 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1475 | 1512 | }  | 
                                                        
| 1476 | 1513 | |
| 1477 | - if (!empty($context['ban_errors']))  | 
                                                        |
| 1478 | - return $ban_info['id'];  | 
                                                        |
| 1514 | +	if (!empty($context['ban_errors'])) { | 
                                                        |
| 1515 | + return $ban_info['id'];  | 
                                                        |
| 1516 | + }  | 
                                                        |
| 1479 | 1517 | |
| 1480 | 1518 |  	$smcFunc['db_query']('', ' | 
                                                        
| 1481 | 1519 |  		UPDATE {db_prefix}ban_groups | 
                                                        
@@ -1519,10 +1557,12 @@ discard block  | 
                                                    ||
| 1519 | 1557 |  { | 
                                                        
| 1520 | 1558 | global $smcFunc, $context;  | 
                                                        
| 1521 | 1559 | |
| 1522 | - if (empty($ban_info['name']))  | 
                                                        |
| 1523 | - $context['ban_errors'][] = 'ban_name_empty';  | 
                                                        |
| 1524 | - if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login']))  | 
                                                        |
| 1525 | - $context['ban_errors'][] = 'ban_unknown_restriction_type';  | 
                                                        |
| 1560 | +	if (empty($ban_info['name'])) { | 
                                                        |
| 1561 | + $context['ban_errors'][] = 'ban_name_empty';  | 
                                                        |
| 1562 | + }  | 
                                                        |
| 1563 | +	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) { | 
                                                        |
| 1564 | + $context['ban_errors'][] = 'ban_unknown_restriction_type';  | 
                                                        |
| 1565 | + }  | 
                                                        |
| 1526 | 1566 | |
| 1527 | 1567 | if (!empty($ban_info['name']))  | 
                                                        
| 1528 | 1568 |  	{ | 
                                                        
@@ -1537,13 +1577,15 @@ discard block  | 
                                                    ||
| 1537 | 1577 | )  | 
                                                        
| 1538 | 1578 | );  | 
                                                        
| 1539 | 1579 | |
| 1540 | - if ($smcFunc['db_num_rows']($request) == 1)  | 
                                                        |
| 1541 | - $context['ban_errors'][] = 'ban_name_exists';  | 
                                                        |
| 1580 | +		if ($smcFunc['db_num_rows']($request) == 1) { | 
                                                        |
| 1581 | + $context['ban_errors'][] = 'ban_name_exists';  | 
                                                        |
| 1582 | + }  | 
                                                        |
| 1542 | 1583 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1543 | 1584 | }  | 
                                                        
| 1544 | 1585 | |
| 1545 | - if (!empty($context['ban_errors']))  | 
                                                        |
| 1546 | - return;  | 
                                                        |
| 1586 | +	if (!empty($context['ban_errors'])) { | 
                                                        |
| 1587 | + return;  | 
                                                        |
| 1588 | + }  | 
                                                        |
| 1547 | 1589 | |
| 1548 | 1590 | // Yes yes, we're ready to add now.  | 
                                                        
| 1549 | 1591 |  	$ban_info['id'] = $smcFunc['db_insert']('', | 
                                                        
@@ -1560,8 +1602,9 @@ discard block  | 
                                                    ||
| 1560 | 1602 | 1  | 
                                                        
| 1561 | 1603 | );  | 
                                                        
| 1562 | 1604 | |
| 1563 | - if (empty($ban_info['id']))  | 
                                                        |
| 1564 | - $context['ban_errors'][] = 'impossible_insert_new_bangroup';  | 
                                                        |
| 1605 | +	if (empty($ban_info['id'])) { | 
                                                        |
| 1606 | + $context['ban_errors'][] = 'impossible_insert_new_bangroup';  | 
                                                        |
| 1607 | + }  | 
                                                        |
| 1565 | 1608 | |
| 1566 | 1609 | return $ban_info['id'];  | 
                                                        
| 1567 | 1610 | }  | 
                                                        
@@ -1586,24 +1629,24 @@ discard block  | 
                                                    ||
| 1586 | 1629 | $ban_group = isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0;  | 
                                                        
| 1587 | 1630 | $ban_id = isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0;  | 
                                                        
| 1588 | 1631 | |
| 1589 | - if (empty($ban_group))  | 
                                                        |
| 1590 | -		fatal_lang_error('ban_not_found', false); | 
                                                        |
| 1632 | +	if (empty($ban_group)) { | 
                                                        |
| 1633 | +			fatal_lang_error('ban_not_found', false); | 
                                                        |
| 1634 | + }  | 
                                                        |
| 1591 | 1635 | |
| 1592 | 1636 | if (isset($_POST['add_new_trigger']) && !empty($_POST['ban_suggestions']))  | 
                                                        
| 1593 | 1637 |  	{ | 
                                                        
| 1594 | 1638 | saveTriggers($_POST['ban_suggestions'], $ban_group, 0, $ban_id);  | 
                                                        
| 1595 | 1639 |  		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : '')); | 
                                                        
| 1596 | - }  | 
                                                        |
| 1597 | - elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions']))  | 
                                                        |
| 1640 | + } elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions']))  | 
                                                        |
| 1598 | 1641 |  	{ | 
                                                        
| 1599 | 1642 | // The first replaces the old one, the others are added new (simplification, otherwise it would require another query and some work...)  | 
                                                        
| 1600 | 1643 | saveTriggers(array_shift($_POST['ban_suggestions']), $ban_group, 0, $ban_id);  | 
                                                        
| 1601 | - if (!empty($_POST['ban_suggestions']))  | 
                                                        |
| 1602 | - saveTriggers($_POST['ban_suggestions'], $ban_group);  | 
                                                        |
| 1644 | +		if (!empty($_POST['ban_suggestions'])) { | 
                                                        |
| 1645 | + saveTriggers($_POST['ban_suggestions'], $ban_group);  | 
                                                        |
| 1646 | + }  | 
                                                        |
| 1603 | 1647 | |
| 1604 | 1648 |  		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : '')); | 
                                                        
| 1605 | - }  | 
                                                        |
| 1606 | - elseif (isset($_POST['edit_trigger']))  | 
                                                        |
| 1649 | + } elseif (isset($_POST['edit_trigger']))  | 
                                                        |
| 1607 | 1650 |  	{ | 
                                                        
| 1608 | 1651 | removeBanTriggers($ban_id);  | 
                                                        
| 1609 | 1652 |  		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : '')); | 
                                                        
@@ -1634,8 +1677,7 @@ discard block  | 
                                                    ||
| 1634 | 1677 | ),  | 
                                                        
| 1635 | 1678 | 'is_new' => true,  | 
                                                        
| 1636 | 1679 | );  | 
                                                        
| 1637 | - }  | 
                                                        |
| 1638 | - else  | 
                                                        |
| 1680 | + } else  | 
                                                        |
| 1639 | 1681 |  	{ | 
                                                        
| 1640 | 1682 |  		$request = $smcFunc['db_query']('', ' | 
                                                        
| 1641 | 1683 | SELECT  | 
                                                        
@@ -1652,8 +1694,9 @@ discard block  | 
                                                    ||
| 1652 | 1694 | 'ban_group' => $ban_group,  | 
                                                        
| 1653 | 1695 | )  | 
                                                        
| 1654 | 1696 | );  | 
                                                        
| 1655 | - if ($smcFunc['db_num_rows']($request) == 0)  | 
                                                        |
| 1656 | -			fatal_lang_error('ban_not_found', false); | 
                                                        |
| 1697 | +		if ($smcFunc['db_num_rows']($request) == 0) { | 
                                                        |
| 1698 | +					fatal_lang_error('ban_not_found', false); | 
                                                        |
| 1699 | + }  | 
                                                        |
| 1657 | 1700 | $row = $smcFunc['db_fetch_assoc']($request);  | 
                                                        
| 1658 | 1701 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1659 | 1702 | |
@@ -1702,8 +1745,9 @@ discard block  | 
                                                    ||
| 1702 | 1745 | removeBanTriggers($_POST['remove']);  | 
                                                        
| 1703 | 1746 | |
| 1704 | 1747 | // Rehabilitate some members.  | 
                                                        
| 1705 | - if ($_REQUEST['entity'] == 'member')  | 
                                                        |
| 1706 | - updateBanMembers();  | 
                                                        |
| 1748 | +		if ($_REQUEST['entity'] == 'member') { | 
                                                        |
| 1749 | + updateBanMembers();  | 
                                                        |
| 1750 | + }  | 
                                                        |
| 1707 | 1751 | |
| 1708 | 1752 | // Make sure the ban cache is refreshed.  | 
                                                        
| 1709 | 1753 |  		updateSettings(array('banLastUpdated' => time())); | 
                                                        
@@ -1816,8 +1860,7 @@ discard block  | 
                                                    ||
| 1816 | 1860 | 'default' => 'bi.ip_low, bi.ip_high, bi.ip_low',  | 
                                                        
| 1817 | 1861 | 'reverse' => 'bi.ip_low DESC, bi.ip_high DESC',  | 
                                                        
| 1818 | 1862 | );  | 
                                                        
| 1819 | - }  | 
                                                        |
| 1820 | - elseif ($context['selected_entity'] === 'hostname')  | 
                                                        |
| 1863 | + } elseif ($context['selected_entity'] === 'hostname')  | 
                                                        |
| 1821 | 1864 |  	{ | 
                                                        
| 1822 | 1865 | $listOptions['columns']['banned_entity']['data'] = array(  | 
                                                        
| 1823 | 1866 | 'function' => function($rowData) use ($smcFunc)  | 
                                                        
@@ -1829,8 +1872,7 @@ discard block  | 
                                                    ||
| 1829 | 1872 | 'default' => 'bi.hostname',  | 
                                                        
| 1830 | 1873 | 'reverse' => 'bi.hostname DESC',  | 
                                                        
| 1831 | 1874 | );  | 
                                                        
| 1832 | - }  | 
                                                        |
| 1833 | - elseif ($context['selected_entity'] === 'email')  | 
                                                        |
| 1875 | + } elseif ($context['selected_entity'] === 'email')  | 
                                                        |
| 1834 | 1876 |  	{ | 
                                                        
| 1835 | 1877 | $listOptions['columns']['banned_entity']['data'] = array(  | 
                                                        
| 1836 | 1878 | 'function' => function($rowData) use ($smcFunc)  | 
                                                        
@@ -1842,8 +1884,7 @@ discard block  | 
                                                    ||
| 1842 | 1884 | 'default' => 'bi.email_address',  | 
                                                        
| 1843 | 1885 | 'reverse' => 'bi.email_address DESC',  | 
                                                        
| 1844 | 1886 | );  | 
                                                        
| 1845 | - }  | 
                                                        |
| 1846 | - elseif ($context['selected_entity'] === 'member')  | 
                                                        |
| 1887 | + } elseif ($context['selected_entity'] === 'member')  | 
                                                        |
| 1847 | 1888 |  	{ | 
                                                        
| 1848 | 1889 | $listOptions['columns']['banned_entity']['data'] = array(  | 
                                                        
| 1849 | 1890 | 'sprintf' => array(  | 
                                                        
@@ -1907,8 +1948,9 @@ discard block  | 
                                                    ||
| 1907 | 1948 | )  | 
                                                        
| 1908 | 1949 | );  | 
                                                        
| 1909 | 1950 | $ban_triggers = array();  | 
                                                        
| 1910 | - while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        |
| 1911 | - $ban_triggers[] = $row;  | 
                                                        |
| 1951 | +	while ($row = $smcFunc['db_fetch_assoc']($request)) { | 
                                                        |
| 1952 | + $ban_triggers[] = $row;  | 
                                                        |
| 1953 | + }  | 
                                                        |
| 1912 | 1954 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1913 | 1955 | |
| 1914 | 1956 | return $ban_triggers;  | 
                                                        
@@ -1964,8 +2006,9 @@ discard block  | 
                                                    ||
| 1964 | 2006 |  		validateToken('admin-bl'); | 
                                                        
| 1965 | 2007 | |
| 1966 | 2008 | // 'Delete all entries' button was pressed.  | 
                                                        
| 1967 | - if (!empty($_POST['removeAll']))  | 
                                                        |
| 1968 | - removeBanLogs();  | 
                                                        |
| 2009 | +		if (!empty($_POST['removeAll'])) { | 
                                                        |
| 2010 | + removeBanLogs();  | 
                                                        |
| 2011 | + }  | 
                                                        |
| 1969 | 2012 | // 'Delete selection' button was pressed.  | 
                                                        
| 1970 | 2013 | else  | 
                                                        
| 1971 | 2014 |  		{ | 
                                                        
@@ -2174,12 +2217,15 @@ discard block  | 
                                                    ||
| 2174 | 2217 | $low = inet_dtop($low);  | 
                                                        
| 2175 | 2218 | $high = inet_dtop($high);  | 
                                                        
| 2176 | 2219 | |
| 2177 | - if ($low == '255.255.255.255') return 'unknown';  | 
                                                        |
| 2178 | - if ($low == $high)  | 
                                                        |
| 2179 | - return $low;  | 
                                                        |
| 2180 | - else  | 
                                                        |
| 2181 | - return $low . '-' . $high;  | 
                                                        |
| 2182 | -}  | 
                                                        |
| 2220 | +	if ($low == '255.255.255.255') { | 
                                                        |
| 2221 | + return 'unknown';  | 
                                                        |
| 2222 | + }  | 
                                                        |
| 2223 | +	if ($low == $high) { | 
                                                        |
| 2224 | + return $low;  | 
                                                        |
| 2225 | +	} else { | 
                                                        |
| 2226 | + return $low . '-' . $high;  | 
                                                        |
| 2227 | + }  | 
                                                        |
| 2228 | + }  | 
                                                        |
| 2183 | 2229 | |
| 2184 | 2230 | /**  | 
                                                        
| 2185 | 2231 | * Checks whether a given IP range already exists in the trigger list.  | 
                                                        
@@ -2255,15 +2301,17 @@ discard block  | 
                                                    ||
| 2255 | 2301 | $memberEmailWild = array();  | 
                                                        
| 2256 | 2302 | while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        
| 2257 | 2303 |  	{ | 
                                                        
| 2258 | - if ($row['id_member'])  | 
                                                        |
| 2259 | - $memberIDs[$row['id_member']] = $row['id_member'];  | 
                                                        |
| 2304 | +		if ($row['id_member']) { | 
                                                        |
| 2305 | + $memberIDs[$row['id_member']] = $row['id_member'];  | 
                                                        |
| 2306 | + }  | 
                                                        |
| 2260 | 2307 | if ($row['email_address'])  | 
                                                        
| 2261 | 2308 |  		{ | 
                                                        
| 2262 | 2309 | // Does it have a wildcard - if so we can't do a IN on it.  | 
                                                        
| 2263 | - if (strpos($row['email_address'], '%') !== false)  | 
                                                        |
| 2264 | - $memberEmailWild[$row['email_address']] = $row['email_address'];  | 
                                                        |
| 2265 | - else  | 
                                                        |
| 2266 | - $memberEmails[$row['email_address']] = $row['email_address'];  | 
                                                        |
| 2310 | +			if (strpos($row['email_address'], '%') !== false) { | 
                                                        |
| 2311 | + $memberEmailWild[$row['email_address']] = $row['email_address'];  | 
                                                        |
| 2312 | +			} else { | 
                                                        |
| 2313 | + $memberEmails[$row['email_address']] = $row['email_address'];  | 
                                                        |
| 2314 | + }  | 
                                                        |
| 2267 | 2315 | }  | 
                                                        
| 2268 | 2316 | }  | 
                                                        
| 2269 | 2317 | $smcFunc['db_free_result']($request);  | 
                                                        
@@ -2314,14 +2362,15 @@ discard block  | 
                                                    ||
| 2314 | 2362 | }  | 
                                                        
| 2315 | 2363 | |
| 2316 | 2364 | // We welcome our new members in the realm of the banned.  | 
                                                        
| 2317 | - if (!empty($newMembers))  | 
                                                        |
| 2318 | -		$smcFunc['db_query']('', ' | 
                                                        |
| 2365 | +	if (!empty($newMembers)) { | 
                                                        |
| 2366 | +			$smcFunc['db_query']('', ' | 
                                                        |
| 2319 | 2367 |  			DELETE FROM {db_prefix}log_online | 
                                                        
| 2320 | 2368 |  			WHERE id_member IN ({array_int:new_banned_members})', | 
                                                        
| 2321 | 2369 | array(  | 
                                                        
| 2322 | 2370 | 'new_banned_members' => $newMembers,  | 
                                                        
| 2323 | 2371 | )  | 
                                                        
| 2324 | 2372 | );  | 
                                                        
| 2373 | + }  | 
                                                        |
| 2325 | 2374 | |
| 2326 | 2375 | // Find members that are wrongfully marked as banned.  | 
                                                        
| 2327 | 2376 |  	$request = $smcFunc['db_query']('', ' | 
                                                        
@@ -2348,9 +2397,10 @@ discard block  | 
                                                    ||
| 2348 | 2397 | }  | 
                                                        
| 2349 | 2398 | $smcFunc['db_free_result']($request);  | 
                                                        
| 2350 | 2399 | |
| 2351 | - if (!empty($updates))  | 
                                                        |
| 2352 | - foreach ($updates as $newStatus => $members)  | 
                                                        |
| 2400 | +	if (!empty($updates)) { | 
                                                        |
| 2401 | + foreach ($updates as $newStatus => $members)  | 
                                                        |
| 2353 | 2402 |  			updateMemberData($members, array('is_activated' => $newStatus)); | 
                                                        
| 2403 | + }  | 
                                                        |
| 2354 | 2404 | |
| 2355 | 2405 | // Update the latest member and our total members as banning may change them.  | 
                                                        
| 2356 | 2406 |  	updateStats('member'); | 
                                                        
@@ -283,11 +283,11 @@ discard block  | 
                                                    ||
| 283 | 283 | if (removeItems == 0)  | 
                                                        
| 284 | 284 |  			{ | 
                                                        
| 285 | 285 | e.preventDefault();  | 
                                                        
| 286 | -				return alert("'. $txt['select_item_check'] .'"); | 
                                                        |
| 286 | +				return alert("'. $txt['select_item_check'] . '"); | 
                                                        |
| 287 | 287 | }  | 
                                                        
| 288 | 288 | |
| 289 | 289 | |
| 290 | -			return confirm("'. $txt['ban_remove_selected_confirm'] .'"); | 
                                                        |
| 290 | +			return confirm("'. $txt['ban_remove_selected_confirm'] . '"); | 
                                                        |
| 291 | 291 | });',  | 
                                                        
| 292 | 292 | );  | 
                                                        
| 293 | 293 | |
@@ -486,7 +486,7 @@ discard block  | 
                                                    ||
| 486 | 486 | array(  | 
                                                        
| 487 | 487 | 'position' => 'below_table_data',  | 
                                                        
| 488 | 488 | 'value' => '  | 
                                                        
| 489 | - <input type="submit" name="remove_selection" value="' . $txt['ban_remove_selected_triggers'] . '" class="button"> <a class="button" href="' . $scripturl . '?action=admin;area=ban;sa=edittrigger;bg=' . $ban_group_id . '">' . $txt['ban_add_trigger'] . '</a>',  | 
                                                        |
| 489 | + <input type="submit" name="remove_selection" value="' . $txt['ban_remove_selected_triggers'] . '" class="button"> <a class="button" href="' . $scripturl . '?action=admin;area=ban;sa=edittrigger;bg=' . $ban_group_id . '">' . $txt['ban_add_trigger'] . '</a>',  | 
                                                        |
| 490 | 490 | 'style' => 'text-align: right;',  | 
                                                        
| 491 | 491 | ),  | 
                                                        
| 492 | 492 | array(  | 
                                                        
@@ -506,11 +506,11 @@ discard block  | 
                                                    ||
| 506 | 506 | if (removeItems == 0)  | 
                                                        
| 507 | 507 |  			{ | 
                                                        
| 508 | 508 | e.preventDefault();  | 
                                                        
| 509 | -				return alert("'. $txt['select_item_check'] .'"); | 
                                                        |
| 509 | +				return alert("'. $txt['select_item_check'] . '"); | 
                                                        |
| 510 | 510 | }  | 
                                                        
| 511 | 511 | |
| 512 | 512 | |
| 513 | -			return confirm("'. $txt['ban_remove_selected_confirm'] .'"); | 
                                                        |
| 513 | +			return confirm("'. $txt['ban_remove_selected_confirm'] . '"); | 
                                                        |
| 514 | 514 | });',  | 
                                                        
| 515 | 515 | );  | 
                                                        
| 516 | 516 | createList($listOptions);  | 
                                                        
@@ -1452,7 +1452,7 @@  | 
                                                    ||
| 1452 | 1452 | *  | 
                                                        
| 1453 | 1453 | * @param int $id_subscribe The subscription ID  | 
                                                        
| 1454 | 1454 | * @param int $id_member The ID of the member  | 
                                                        
| 1455 | - * @param int|string $renewal 0 if we're forcing start/end time, otherwise a string indicating how long to renew the subscription for ('D', 'W', 'M' or 'Y') | 
                                                        |
| 1455 | + * @param integer $renewal 0 if we're forcing start/end time, otherwise a string indicating how long to renew the subscription for ('D', 'W', 'M' or 'Y') | 
                                                        |
| 1456 | 1456 | * @param int $forceStartTime If set, forces the subscription to start at the specified time  | 
                                                        
| 1457 | 1457 | * @param int $forceEndTime If set, forces the subscription to end at the specified time  | 
                                                        
| 1458 | 1458 | */  | 
                                                        
@@ -14,8 +14,9 @@ discard block  | 
                                                    ||
| 14 | 14 | * @version 2.1 Beta 4  | 
                                                        
| 15 | 15 | */  | 
                                                        
| 16 | 16 | |
| 17 | -if (!defined('SMF')) | 
                                                        |
| 17 | +if (!defined('SMF')) { | 
                                                        |
| 18 | 18 |  	die('No direct access...'); | 
                                                        
| 19 | +}  | 
                                                        |
| 19 | 20 | |
| 20 | 21 | /**  | 
                                                        
| 21 | 22 | * The main entrance point for the 'Paid Subscription' screen, calling  | 
                                                        
@@ -32,18 +33,19 @@ discard block  | 
                                                    ||
| 32 | 33 |  	loadLanguage('ManagePaid'); | 
                                                        
| 33 | 34 |  	loadTemplate('ManagePaid'); | 
                                                        
| 34 | 35 | |
| 35 | - if (!empty($modSettings['paid_enabled']))  | 
                                                        |
| 36 | - $subActions = array(  | 
                                                        |
| 36 | +	if (!empty($modSettings['paid_enabled'])) { | 
                                                        |
| 37 | + $subActions = array(  | 
                                                        |
| 37 | 38 |  			'modify' => array('ModifySubscription', 'admin_forum'), | 
                                                        
| 38 | 39 |  			'modifyuser' => array('ModifyUserSubscription', 'admin_forum'), | 
                                                        
| 39 | 40 |  			'settings' => array('ModifySubscriptionSettings', 'admin_forum'), | 
                                                        
| 40 | 41 |  			'view' => array('ViewSubscriptions', 'admin_forum'), | 
                                                        
| 41 | 42 |  			'viewsub' => array('ViewSubscribedUsers', 'admin_forum'), | 
                                                        
| 42 | 43 | );  | 
                                                        
| 43 | - else  | 
                                                        |
| 44 | - $subActions = array(  | 
                                                        |
| 44 | +	} else { | 
                                                        |
| 45 | + $subActions = array(  | 
                                                        |
| 45 | 46 |  			'settings' => array('ModifySubscriptionSettings', 'admin_forum'), | 
                                                        
| 46 | 47 | );  | 
                                                        
| 48 | + }  | 
                                                        |
| 47 | 49 | |
| 48 | 50 | // Default the sub-action to 'view subscriptions', but only if they have already set things up..  | 
                                                        
| 49 | 51 | $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (!empty($modSettings['paid_currency_symbol']) && !empty($modSettings['paid_enabled']) ? 'view' : 'settings');  | 
                                                        
@@ -59,8 +61,8 @@ discard block  | 
                                                    ||
| 59 | 61 | 'help' => '',  | 
                                                        
| 60 | 62 | 'description' => $txt['paid_subscriptions_desc'],  | 
                                                        
| 61 | 63 | );  | 
                                                        
| 62 | - if (!empty($modSettings['paid_enabled']))  | 
                                                        |
| 63 | - $context[$context['admin_menu_name']]['tab_data']['tabs'] = array(  | 
                                                        |
| 64 | +	if (!empty($modSettings['paid_enabled'])) { | 
                                                        |
| 65 | + $context[$context['admin_menu_name']]['tab_data']['tabs'] = array(  | 
                                                        |
| 64 | 66 | 'view' => array(  | 
                                                        
| 65 | 67 | 'description' => $txt['paid_subs_view_desc'],  | 
                                                        
| 66 | 68 | ),  | 
                                                        
@@ -68,6 +70,7 @@ discard block  | 
                                                    ||
| 68 | 70 | 'description' => $txt['paid_subs_settings_desc'],  | 
                                                        
| 69 | 71 | ),  | 
                                                        
| 70 | 72 | );  | 
                                                        
| 73 | + }  | 
                                                        |
| 71 | 74 | |
| 72 | 75 |  	call_integration_hook('integrate_manage_subscriptions', array(&$subActions)); | 
                                                        
| 73 | 76 | |
@@ -92,8 +95,9 @@ discard block  | 
                                                    ||
| 92 | 95 |  	{ | 
                                                        
| 93 | 96 | // If the currency is set to something different then we need to set it to other for this to work and set it back shortly.  | 
                                                        
| 94 | 97 | $modSettings['paid_currency'] = !empty($modSettings['paid_currency_code']) ? $modSettings['paid_currency_code'] : '';  | 
                                                        
| 95 | -		if (!empty($modSettings['paid_currency_code']) && !in_array($modSettings['paid_currency_code'], array('usd', 'eur', 'gbp', 'cad', 'aud'))) | 
                                                        |
| 96 | - $modSettings['paid_currency'] = 'other';  | 
                                                        |
| 98 | +		if (!empty($modSettings['paid_currency_code']) && !in_array($modSettings['paid_currency_code'], array('usd', 'eur', 'gbp', 'cad', 'aud'))) { | 
                                                        |
| 99 | + $modSettings['paid_currency'] = 'other';  | 
                                                        |
| 100 | + }  | 
                                                        |
| 97 | 101 | |
| 98 | 102 | // These are all the default settings.  | 
                                                        
| 99 | 103 | $config_vars = array(  | 
                                                        
@@ -156,8 +160,7 @@ discard block  | 
                                                    ||
| 156 | 160 | }  | 
                                                        
| 157 | 161 | }  | 
                                                        
| 158 | 162 | toggleOther();', true);  | 
                                                        
| 159 | - }  | 
                                                        |
| 160 | - else  | 
                                                        |
| 163 | + } else  | 
                                                        |
| 161 | 164 |  	{ | 
                                                        
| 162 | 165 | $config_vars = array(  | 
                                                        
| 163 | 166 |  			array('check', 'paid_enabled'), | 
                                                        
@@ -166,8 +169,9 @@ discard block  | 
                                                    ||
| 166 | 169 | }  | 
                                                        
| 167 | 170 | |
| 168 | 171 | // Just searching?  | 
                                                        
| 169 | - if ($return_config)  | 
                                                        |
| 170 | - return $config_vars;  | 
                                                        |
| 172 | +	if ($return_config) { | 
                                                        |
| 173 | + return $config_vars;  | 
                                                        |
| 174 | + }  | 
                                                        |
| 171 | 175 | |
| 172 | 176 | // Get the settings template fired up.  | 
                                                        
| 173 | 177 | require_once($sourcedir . '/ManageServer.php');  | 
                                                        
@@ -211,8 +215,9 @@ discard block  | 
                                                    ||
| 211 | 215 |  			foreach (explode(',', $_POST['paid_email_to']) as $email) | 
                                                        
| 212 | 216 |  			{ | 
                                                        
| 213 | 217 | $email = trim($email);  | 
                                                        
| 214 | - if (!empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL))  | 
                                                        |
| 215 | - $email_addresses[] = $email;  | 
                                                        |
| 218 | +				if (!empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL)) { | 
                                                        |
| 219 | + $email_addresses[] = $email;  | 
                                                        |
| 220 | + }  | 
                                                        |
| 216 | 221 |  				$_POST['paid_email_to'] = implode(',', $email_addresses); | 
                                                        
| 217 | 222 | }  | 
                                                        
| 218 | 223 | }  | 
                                                        
@@ -249,8 +254,9 @@ discard block  | 
                                                    ||
| 249 | 254 | global $context, $txt, $modSettings, $sourcedir, $scripturl;  | 
                                                        
| 250 | 255 | |
| 251 | 256 | // Not made the settings yet?  | 
                                                        
| 252 | - if (empty($modSettings['paid_currency_symbol']))  | 
                                                        |
| 253 | -		fatal_lang_error('paid_not_set_currency', false, $scripturl . '?action=admin;area=paidsubscribe;sa=settings'); | 
                                                        |
| 257 | +	if (empty($modSettings['paid_currency_symbol'])) { | 
                                                        |
| 258 | +			fatal_lang_error('paid_not_set_currency', false, $scripturl . '?action=admin;area=paidsubscribe;sa=settings'); | 
                                                        |
| 259 | + }  | 
                                                        |
| 254 | 260 | |
| 255 | 261 | // Some basic stuff.  | 
                                                        
| 256 | 262 | $context['page_title'] = $txt['paid_subs_view'];  | 
                                                        
@@ -270,10 +276,11 @@ discard block  | 
                                                    ||
| 270 | 276 | |
| 271 | 277 | foreach ($context['subscriptions'] as $data)  | 
                                                        
| 272 | 278 |  				{ | 
                                                        
| 273 | - if (++$counter < $start)  | 
                                                        |
| 274 | - continue;  | 
                                                        |
| 275 | - elseif ($counter == $start + $items_per_page)  | 
                                                        |
| 276 | - break;  | 
                                                        |
| 279 | +					if (++$counter < $start) { | 
                                                        |
| 280 | + continue;  | 
                                                        |
| 281 | +					} elseif ($counter == $start + $items_per_page) { | 
                                                        |
| 282 | + break;  | 
                                                        |
| 283 | + }  | 
                                                        |
| 277 | 284 | |
| 278 | 285 | $subscriptions[] = $data;  | 
                                                        
| 279 | 286 | }  | 
                                                        
@@ -450,8 +457,9 @@ discard block  | 
                                                    ||
| 450 | 457 | );  | 
                                                        
| 451 | 458 | $id_group = 0;  | 
                                                        
| 452 | 459 | $add_groups = '';  | 
                                                        
| 453 | - if ($smcFunc['db_num_rows']($request))  | 
                                                        |
| 454 | - list ($id_group, $add_groups) = $smcFunc['db_fetch_row']($request);  | 
                                                        |
| 460 | +			if ($smcFunc['db_num_rows']($request)) { | 
                                                        |
| 461 | + list ($id_group, $add_groups) = $smcFunc['db_fetch_row']($request);  | 
                                                        |
| 462 | + }  | 
                                                        |
| 455 | 463 | $smcFunc['db_free_result']($request);  | 
                                                        
| 456 | 464 | |
| 457 | 465 | $changes = array();  | 
                                                        
@@ -463,8 +471,9 @@ discard block  | 
                                                    ||
| 463 | 471 |  				{ | 
                                                        
| 464 | 472 | // If their current primary group isn't what they had before the subscription, and their current group was  | 
                                                        
| 465 | 473 | // granted by the sub, remove it.  | 
                                                        
| 466 | - if ($member_data['old_id_group'] != $member_data['id_group'] && $member_data['id_group'] == $id_group)  | 
                                                        |
| 467 | - $changes[$id_member]['id_group'] = $member_data['old_id_group'];  | 
                                                        |
| 474 | +					if ($member_data['old_id_group'] != $member_data['id_group'] && $member_data['id_group'] == $id_group) { | 
                                                        |
| 475 | + $changes[$id_member]['id_group'] = $member_data['old_id_group'];  | 
                                                        |
| 476 | + }  | 
                                                        |
| 468 | 477 | }  | 
                                                        
| 469 | 478 | }  | 
                                                        
| 470 | 479 | |
@@ -477,15 +486,17 @@ discard block  | 
                                                    ||
| 477 | 486 | // First let's get their groups sorted.  | 
                                                        
| 478 | 487 |  					$current_groups = explode(',', $member_data['additional_groups']); | 
                                                        
| 479 | 488 |  					$new_groups = implode(',', array_diff($current_groups, $add_groups)); | 
                                                        
| 480 | - if ($new_groups != $member_data['additional_groups'])  | 
                                                        |
| 481 | - $changes[$id_member]['additional_groups'] = $new_groups;  | 
                                                        |
| 489 | +					if ($new_groups != $member_data['additional_groups']) { | 
                                                        |
| 490 | + $changes[$id_member]['additional_groups'] = $new_groups;  | 
                                                        |
| 491 | + }  | 
                                                        |
| 482 | 492 | }  | 
                                                        
| 483 | 493 | }  | 
                                                        
| 484 | 494 | |
| 485 | 495 | // We're going through changes...  | 
                                                        
| 486 | - if (!empty($changes))  | 
                                                        |
| 487 | - foreach ($changes as $id_member => $new_values)  | 
                                                        |
| 496 | +			if (!empty($changes)) { | 
                                                        |
| 497 | + foreach ($changes as $id_member => $new_values)  | 
                                                        |
| 488 | 498 | updateMemberData($id_member, $new_values);  | 
                                                        
| 499 | + }  | 
                                                        |
| 489 | 500 | }  | 
                                                        
| 490 | 501 | |
| 491 | 502 | // Delete the subscription  | 
                                                        
@@ -533,11 +544,13 @@ discard block  | 
                                                    ||
| 533 | 544 | 'M' => 24,  | 
                                                        
| 534 | 545 | 'Y' => 5,  | 
                                                        
| 535 | 546 | );  | 
                                                        
| 536 | - if (empty($_POST['span_unit']) || empty($limits[$_POST['span_unit']]) || empty($_POST['span_value']) || $_POST['span_value'] < 1)  | 
                                                        |
| 537 | -				fatal_lang_error('paid_invalid_duration', false); | 
                                                        |
| 547 | +			if (empty($_POST['span_unit']) || empty($limits[$_POST['span_unit']]) || empty($_POST['span_value']) || $_POST['span_value'] < 1) { | 
                                                        |
| 548 | +							fatal_lang_error('paid_invalid_duration', false); | 
                                                        |
| 549 | + }  | 
                                                        |
| 538 | 550 | |
| 539 | - if ($_POST['span_value'] > $limits[$_POST['span_unit']])  | 
                                                        |
| 540 | -				fatal_lang_error('paid_invalid_duration_' . $_POST['span_unit'], false); | 
                                                        |
| 551 | +			if ($_POST['span_value'] > $limits[$_POST['span_unit']]) { | 
                                                        |
| 552 | +							fatal_lang_error('paid_invalid_duration_' . $_POST['span_unit'], false); | 
                                                        |
| 553 | + }  | 
                                                        |
| 541 | 554 | |
| 542 | 555 | // Clean the span.  | 
                                                        
| 543 | 556 | $span = $_POST['span_value'] . $_POST['span_unit'];  | 
                                                        
@@ -546,8 +559,9 @@ discard block  | 
                                                    ||
| 546 | 559 |  			$cost = array('fixed' => sprintf('%01.2f', strtr($_POST['cost'], ',', '.'))); | 
                                                        
| 547 | 560 | |
| 548 | 561 | // There needs to be something.  | 
                                                        
| 549 | - if (empty($_POST['span_value']) || empty($_POST['cost']))  | 
                                                        |
| 550 | -				fatal_lang_error('paid_no_cost_value'); | 
                                                        |
| 562 | +			if (empty($_POST['span_value']) || empty($_POST['cost'])) { | 
                                                        |
| 563 | +							fatal_lang_error('paid_no_cost_value'); | 
                                                        |
| 564 | + }  | 
                                                        |
| 551 | 565 | }  | 
                                                        
| 552 | 566 | // Flexible is harder but more fun ;)  | 
                                                        
| 553 | 567 | else  | 
                                                        
@@ -561,8 +575,9 @@ discard block  | 
                                                    ||
| 561 | 575 |  				'year' => sprintf('%01.2f', strtr($_POST['cost_year'], ',', '.')), | 
                                                        
| 562 | 576 | );  | 
                                                        
| 563 | 577 | |
| 564 | - if (empty($_POST['cost_day']) && empty($_POST['cost_week']) && empty($_POST['cost_month']) && empty($_POST['cost_year']))  | 
                                                        |
| 565 | -				fatal_lang_error('paid_all_freq_blank'); | 
                                                        |
| 578 | +			if (empty($_POST['cost_day']) && empty($_POST['cost_week']) && empty($_POST['cost_month']) && empty($_POST['cost_year'])) { | 
                                                        |
| 579 | +							fatal_lang_error('paid_all_freq_blank'); | 
                                                        |
| 580 | + }  | 
                                                        |
| 566 | 581 | }  | 
                                                        
| 567 | 582 | $cost = $smcFunc['json_encode']($cost);  | 
                                                        
| 568 | 583 | |
@@ -571,9 +586,10 @@ discard block  | 
                                                    ||
| 571 | 586 | |
| 572 | 587 | // Yep, time to do additional groups.  | 
                                                        
| 573 | 588 | $addgroups = array();  | 
                                                        
| 574 | - if (!empty($_POST['addgroup']))  | 
                                                        |
| 575 | - foreach ($_POST['addgroup'] as $id => $dummy)  | 
                                                        |
| 589 | +		if (!empty($_POST['addgroup'])) { | 
                                                        |
| 590 | + foreach ($_POST['addgroup'] as $id => $dummy)  | 
                                                        |
| 576 | 591 | $addgroups[] = (int) $id;  | 
                                                        
| 592 | + }  | 
                                                        |
| 577 | 593 |  		$addgroups = implode(',', $addgroups); | 
                                                        
| 578 | 594 | |
| 579 | 595 | // Is it new?!  | 
                                                        
@@ -683,18 +699,18 @@ discard block  | 
                                                    ||
| 683 | 699 |  			{ | 
                                                        
| 684 | 700 | $span_value = $match[1];  | 
                                                        
| 685 | 701 | $span_unit = $match[2];  | 
                                                        
| 686 | - }  | 
                                                        |
| 687 | - else  | 
                                                        |
| 702 | + } else  | 
                                                        |
| 688 | 703 |  			{ | 
                                                        
| 689 | 704 | $span_value = 0;  | 
                                                        
| 690 | 705 | $span_unit = 'D';  | 
                                                        
| 691 | 706 | }  | 
                                                        
| 692 | 707 | |
| 693 | 708 | // Is this a flexible one?  | 
                                                        
| 694 | - if ($row['length'] == 'F')  | 
                                                        |
| 695 | - $isFlexible = true;  | 
                                                        |
| 696 | - else  | 
                                                        |
| 697 | - $isFlexible = false;  | 
                                                        |
| 709 | +			if ($row['length'] == 'F') { | 
                                                        |
| 710 | + $isFlexible = true;  | 
                                                        |
| 711 | +			} else { | 
                                                        |
| 712 | + $isFlexible = false;  | 
                                                        |
| 713 | + }  | 
                                                        |
| 698 | 714 | |
| 699 | 715 | $context['sub'] = array(  | 
                                                        
| 700 | 716 | 'name' => $row['name'],  | 
                                                        
@@ -743,8 +759,9 @@ discard block  | 
                                                    ||
| 743 | 759 | )  | 
                                                        
| 744 | 760 | );  | 
                                                        
| 745 | 761 | $context['groups'] = array();  | 
                                                        
| 746 | - while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        |
| 747 | - $context['groups'][$row['id_group']] = $row['group_name'];  | 
                                                        |
| 762 | +	while ($row = $smcFunc['db_fetch_assoc']($request)) { | 
                                                        |
| 763 | + $context['groups'][$row['id_group']] = $row['group_name'];  | 
                                                        |
| 764 | + }  | 
                                                        |
| 748 | 765 | $smcFunc['db_free_result']($request);  | 
                                                        
| 749 | 766 | |
| 750 | 767 | // This always happens.  | 
                                                        
@@ -778,8 +795,9 @@ discard block  | 
                                                    ||
| 778 | 795 | )  | 
                                                        
| 779 | 796 | );  | 
                                                        
| 780 | 797 | // Something wrong?  | 
                                                        
| 781 | - if ($smcFunc['db_num_rows']($request) == 0)  | 
                                                        |
| 782 | -		fatal_lang_error('no_access', false); | 
                                                        |
| 798 | +	if ($smcFunc['db_num_rows']($request) == 0) { | 
                                                        |
| 799 | +			fatal_lang_error('no_access', false); | 
                                                        |
| 800 | + }  | 
                                                        |
| 783 | 801 | // Do the subscription context.  | 
                                                        
| 784 | 802 | $row = $smcFunc['db_fetch_assoc']($request);  | 
                                                        
| 785 | 803 | $context['subscription'] = array(  | 
                                                        
@@ -1014,8 +1032,8 @@ discard block  | 
                                                    ||
| 1014 | 1032 | ))  | 
                                                        
| 1015 | 1033 | );  | 
                                                        
| 1016 | 1034 | $subscribers = array();  | 
                                                        
| 1017 | - while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        |
| 1018 | - $subscribers[] = array(  | 
                                                        |
| 1035 | +	while ($row = $smcFunc['db_fetch_assoc']($request)) { | 
                                                        |
| 1036 | + $subscribers[] = array(  | 
                                                        |
| 1019 | 1037 | 'id' => $row['id_sublog'],  | 
                                                        
| 1020 | 1038 | 'id_member' => $row['id_member'],  | 
                                                        
| 1021 | 1039 | 'name' => $row['name'],  | 
                                                        
@@ -1025,6 +1043,7 @@ discard block  | 
                                                    ||
| 1025 | 1043 | 'status' => $row['status'],  | 
                                                        
| 1026 | 1044 | 'status_text' => $row['status'] == 0 ? ($row['payments_pending'] == 0 ? $txt['paid_finished'] : $txt['paid_pending']) : $txt['paid_active'],  | 
                                                        
| 1027 | 1045 | );  | 
                                                        
| 1046 | + }  | 
                                                        |
| 1028 | 1047 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1029 | 1048 | |
| 1030 | 1049 | return $subscribers;  | 
                                                        
@@ -1059,14 +1078,16 @@ discard block  | 
                                                    ||
| 1059 | 1078 | 'current_log_item' => $context['log_id'],  | 
                                                        
| 1060 | 1079 | )  | 
                                                        
| 1061 | 1080 | );  | 
                                                        
| 1062 | - if ($smcFunc['db_num_rows']($request) == 0)  | 
                                                        |
| 1063 | -			fatal_lang_error('no_access', false); | 
                                                        |
| 1081 | +		if ($smcFunc['db_num_rows']($request) == 0) { | 
                                                        |
| 1082 | +					fatal_lang_error('no_access', false); | 
                                                        |
| 1083 | + }  | 
                                                        |
| 1064 | 1084 | list ($context['sub_id']) = $smcFunc['db_fetch_row']($request);  | 
                                                        
| 1065 | 1085 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1066 | 1086 | }  | 
                                                        
| 1067 | 1087 | |
| 1068 | - if (!isset($context['subscriptions'][$context['sub_id']]))  | 
                                                        |
| 1069 | -		fatal_lang_error('no_access', false); | 
                                                        |
| 1088 | +	if (!isset($context['subscriptions'][$context['sub_id']])) { | 
                                                        |
| 1089 | +			fatal_lang_error('no_access', false); | 
                                                        |
| 1090 | + }  | 
                                                        |
| 1070 | 1091 | $context['current_subscription'] = $context['subscriptions'][$context['sub_id']];  | 
                                                        
| 1071 | 1092 | |
| 1072 | 1093 | // Searching?  | 
                                                        
@@ -1099,8 +1120,9 @@ discard block  | 
                                                    ||
| 1099 | 1120 | 'name' => $_POST['name'],  | 
                                                        
| 1100 | 1121 | )  | 
                                                        
| 1101 | 1122 | );  | 
                                                        
| 1102 | - if ($smcFunc['db_num_rows']($request) == 0)  | 
                                                        |
| 1103 | -				fatal_lang_error('error_member_not_found'); | 
                                                        |
| 1123 | +			if ($smcFunc['db_num_rows']($request) == 0) { | 
                                                        |
| 1124 | +							fatal_lang_error('error_member_not_found'); | 
                                                        |
| 1125 | + }  | 
                                                        |
| 1104 | 1126 | |
| 1105 | 1127 | list ($id_member, $id_group) = $smcFunc['db_fetch_row']($request);  | 
                                                        
| 1106 | 1128 | $smcFunc['db_free_result']($request);  | 
                                                        
@@ -1116,14 +1138,15 @@ discard block  | 
                                                    ||
| 1116 | 1138 | 'current_member' => $id_member,  | 
                                                        
| 1117 | 1139 | )  | 
                                                        
| 1118 | 1140 | );  | 
                                                        
| 1119 | - if ($smcFunc['db_num_rows']($request) != 0)  | 
                                                        |
| 1120 | -				fatal_lang_error('member_already_subscribed'); | 
                                                        |
| 1141 | +			if ($smcFunc['db_num_rows']($request) != 0) { | 
                                                        |
| 1142 | +							fatal_lang_error('member_already_subscribed'); | 
                                                        |
| 1143 | + }  | 
                                                        |
| 1121 | 1144 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1122 | 1145 | |
| 1123 | 1146 | // Actually put the subscription in place.  | 
                                                        
| 1124 | - if ($status == 1)  | 
                                                        |
| 1125 | - addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime);  | 
                                                        |
| 1126 | - else  | 
                                                        |
| 1147 | +			if ($status == 1) { | 
                                                        |
| 1148 | + addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime);  | 
                                                        |
| 1149 | + } else  | 
                                                        |
| 1127 | 1150 |  			{ | 
                                                        
| 1128 | 1151 |  				$smcFunc['db_insert']('', | 
                                                        
| 1129 | 1152 |  					'{db_prefix}log_subscribed', | 
                                                        
@@ -1150,20 +1173,20 @@ discard block  | 
                                                    ||
| 1150 | 1173 | 'current_log_item' => $context['log_id'],  | 
                                                        
| 1151 | 1174 | )  | 
                                                        
| 1152 | 1175 | );  | 
                                                        
| 1153 | - if ($smcFunc['db_num_rows']($request) == 0)  | 
                                                        |
| 1154 | -				fatal_lang_error('no_access', false); | 
                                                        |
| 1176 | +			if ($smcFunc['db_num_rows']($request) == 0) { | 
                                                        |
| 1177 | +							fatal_lang_error('no_access', false); | 
                                                        |
| 1178 | + }  | 
                                                        |
| 1155 | 1179 | |
| 1156 | 1180 | list ($id_member, $old_status) = $smcFunc['db_fetch_row']($request);  | 
                                                        
| 1157 | 1181 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1158 | 1182 | |
| 1159 | 1183 | // Pick the right permission stuff depending on what the status is changing from/to.  | 
                                                        
| 1160 | - if ($old_status == 1 && $status != 1)  | 
                                                        |
| 1161 | - removeSubscription($context['sub_id'], $id_member);  | 
                                                        |
| 1162 | - elseif ($status == 1 && $old_status != 1)  | 
                                                        |
| 1184 | +			if ($old_status == 1 && $status != 1) { | 
                                                        |
| 1185 | + removeSubscription($context['sub_id'], $id_member);  | 
                                                        |
| 1186 | + } elseif ($status == 1 && $old_status != 1)  | 
                                                        |
| 1163 | 1187 |  			{ | 
                                                        
| 1164 | 1188 | addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime);  | 
                                                        
| 1165 | - }  | 
                                                        |
| 1166 | - else  | 
                                                        |
| 1189 | + } else  | 
                                                        |
| 1167 | 1190 |  			{ | 
                                                        
| 1168 | 1191 |  				$smcFunc['db_query']('', ' | 
                                                        
| 1169 | 1192 |  					UPDATE {db_prefix}log_subscribed | 
                                                        
@@ -1191,8 +1214,9 @@ discard block  | 
                                                    ||
| 1191 | 1214 | if (!empty($_REQUEST['delsub']))  | 
                                                        
| 1192 | 1215 |  		{ | 
                                                        
| 1193 | 1216 | $toDelete = array();  | 
                                                        
| 1194 | - foreach ($_REQUEST['delsub'] as $id => $dummy)  | 
                                                        |
| 1195 | - $toDelete[] = (int) $id;  | 
                                                        |
| 1217 | +			foreach ($_REQUEST['delsub'] as $id => $dummy) { | 
                                                        |
| 1218 | + $toDelete[] = (int) $id;  | 
                                                        |
| 1219 | + }  | 
                                                        |
| 1196 | 1220 | |
| 1197 | 1221 |  			$request = $smcFunc['db_query']('', ' | 
                                                        
| 1198 | 1222 | SELECT id_subscribe, id_member  | 
                                                        
@@ -1202,8 +1226,9 @@ discard block  | 
                                                    ||
| 1202 | 1226 | 'subscription_list' => $toDelete,  | 
                                                        
| 1203 | 1227 | )  | 
                                                        
| 1204 | 1228 | );  | 
                                                        
| 1205 | - while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        |
| 1206 | - removeSubscription($row['id_subscribe'], $row['id_member'], isset($_REQUEST['delete']));  | 
                                                        |
| 1229 | +			while ($row = $smcFunc['db_fetch_assoc']($request)) { | 
                                                        |
| 1230 | + removeSubscription($row['id_subscribe'], $row['id_member'], isset($_REQUEST['delete']));  | 
                                                        |
| 1231 | + }  | 
                                                        |
| 1207 | 1232 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1208 | 1233 | }  | 
                                                        
| 1209 | 1234 |  		redirectexit('action=admin;area=paidsubscribe;sa=viewsub;sid=' . $context['sub_id']); | 
                                                        
@@ -1247,9 +1272,9 @@ discard block  | 
                                                    ||
| 1247 | 1272 | );  | 
                                                        
| 1248 | 1273 | list ($context['sub']['username']) = $smcFunc['db_fetch_row']($request);  | 
                                                        
| 1249 | 1274 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1275 | +		} else { | 
                                                        |
| 1276 | + $context['sub']['username'] = '';  | 
                                                        |
| 1250 | 1277 | }  | 
                                                        
| 1251 | - else  | 
                                                        |
| 1252 | - $context['sub']['username'] = '';  | 
                                                        |
| 1253 | 1278 | }  | 
                                                        
| 1254 | 1279 | // Otherwise load the existing info.  | 
                                                        
| 1255 | 1280 | else  | 
                                                        
@@ -1266,8 +1291,9 @@ discard block  | 
                                                    ||
| 1266 | 1291 | 'blank_string' => '',  | 
                                                        
| 1267 | 1292 | )  | 
                                                        
| 1268 | 1293 | );  | 
                                                        
| 1269 | - if ($smcFunc['db_num_rows']($request) == 0)  | 
                                                        |
| 1270 | -			fatal_lang_error('no_access', false); | 
                                                        |
| 1294 | +		if ($smcFunc['db_num_rows']($request) == 0) { | 
                                                        |
| 1295 | +					fatal_lang_error('no_access', false); | 
                                                        |
| 1296 | + }  | 
                                                        |
| 1271 | 1297 | $row = $smcFunc['db_fetch_assoc']($request);  | 
                                                        
| 1272 | 1298 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1273 | 1299 | |
@@ -1288,13 +1314,13 @@ discard block  | 
                                                    ||
| 1288 | 1314 |  					{ | 
                                                        
| 1289 | 1315 | foreach ($costs as $duration => $cost)  | 
                                                        
| 1290 | 1316 |  						{ | 
                                                        
| 1291 | - if ($cost != 0 && $cost == $pending[1] && $duration == $pending[2])  | 
                                                        |
| 1292 | - $context['pending_payments'][$id] = array(  | 
                                                        |
| 1317 | +							if ($cost != 0 && $cost == $pending[1] && $duration == $pending[2]) { | 
                                                        |
| 1318 | + $context['pending_payments'][$id] = array(  | 
                                                        |
| 1293 | 1319 | 'desc' => sprintf($modSettings['paid_currency_symbol'], $cost . '/' . $txt[$duration]),  | 
                                                        
| 1294 | 1320 | );  | 
                                                        
| 1321 | + }  | 
                                                        |
| 1295 | 1322 | }  | 
                                                        
| 1296 | - }  | 
                                                        |
| 1297 | - elseif ($costs['fixed'] == $pending[1])  | 
                                                        |
| 1323 | + } elseif ($costs['fixed'] == $pending[1])  | 
                                                        |
| 1298 | 1324 |  					{ | 
                                                        
| 1299 | 1325 | $context['pending_payments'][$id] = array(  | 
                                                        
| 1300 | 1326 | 'desc' => sprintf($modSettings['paid_currency_symbol'], $costs['fixed']),  | 
                                                        
@@ -1312,8 +1338,9 @@ discard block  | 
                                                    ||
| 1312 | 1338 | if ($_GET['pending'] == $id && $pending[3] == 'payback' && isset($context['pending_payments'][$id]))  | 
                                                        
| 1313 | 1339 |  					{ | 
                                                        
| 1314 | 1340 | // Flexible?  | 
                                                        
| 1315 | - if (isset($_GET['accept']))  | 
                                                        |
| 1316 | - addSubscription($context['current_subscription']['id'], $row['id_member'], $context['current_subscription']['real_length'] == 'F' ? strtoupper(substr($pending[2], 0, 1)) : 0);  | 
                                                        |
| 1341 | +						if (isset($_GET['accept'])) { | 
                                                        |
| 1342 | + addSubscription($context['current_subscription']['id'], $row['id_member'], $context['current_subscription']['real_length'] == 'F' ? strtoupper(substr($pending[2], 0, 1)) : 0);  | 
                                                        |
| 1343 | + }  | 
                                                        |
| 1317 | 1344 | unset($pending_details[$id]);  | 
                                                        
| 1318 | 1345 | |
| 1319 | 1346 | $new_details = $smcFunc['json_encode']($pending_details);  | 
                                                        
@@ -1375,8 +1402,9 @@ discard block  | 
                                                    ||
| 1375 | 1402 | global $smcFunc;  | 
                                                        
| 1376 | 1403 | |
| 1377 | 1404 | // Make it an array.  | 
                                                        
| 1378 | - if (!is_array($users))  | 
                                                        |
| 1379 | - $users = array($users);  | 
                                                        |
| 1405 | +	if (!is_array($users)) { | 
                                                        |
| 1406 | + $users = array($users);  | 
                                                        |
| 1407 | + }  | 
                                                        |
| 1380 | 1408 | |
| 1381 | 1409 | // Get all the members current groups.  | 
                                                        
| 1382 | 1410 | $groups = array();  | 
                                                        
@@ -1414,14 +1442,16 @@ discard block  | 
                                                    ||
| 1414 | 1442 | if ($row['id_group'] != 0)  | 
                                                        
| 1415 | 1443 |  		{ | 
                                                        
| 1416 | 1444 | // If this is changing - add the old one to the additional groups so it's not lost.  | 
                                                        
| 1417 | - if ($row['id_group'] != $groups[$row['id_member']]['primary'])  | 
                                                        |
| 1418 | - $groups[$row['id_member']]['additional'][] = $groups[$row['id_member']]['primary'];  | 
                                                        |
| 1445 | +			if ($row['id_group'] != $groups[$row['id_member']]['primary']) { | 
                                                        |
| 1446 | + $groups[$row['id_member']]['additional'][] = $groups[$row['id_member']]['primary'];  | 
                                                        |
| 1447 | + }  | 
                                                        |
| 1419 | 1448 | $groups[$row['id_member']]['primary'] = $row['id_group'];  | 
                                                        
| 1420 | 1449 | }  | 
                                                        
| 1421 | 1450 | |
| 1422 | 1451 | // Additional groups.  | 
                                                        
| 1423 | - if (!empty($row['add_groups']))  | 
                                                        |
| 1424 | -			$groups[$row['id_member']]['additional'] = array_merge($groups[$row['id_member']]['additional'], explode(',', $row['add_groups'])); | 
                                                        |
| 1452 | +		if (!empty($row['add_groups'])) { | 
                                                        |
| 1453 | +					$groups[$row['id_member']]['additional'] = array_merge($groups[$row['id_member']]['additional'], explode(',', $row['add_groups'])); | 
                                                        |
| 1454 | + }  | 
                                                        |
| 1425 | 1455 | }  | 
                                                        
| 1426 | 1456 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1427 | 1457 | |
@@ -1429,9 +1459,10 @@ discard block  | 
                                                    ||
| 1429 | 1459 | foreach ($groups as $id => $group)  | 
                                                        
| 1430 | 1460 |  	{ | 
                                                        
| 1431 | 1461 | $group['additional'] = array_unique($group['additional']);  | 
                                                        
| 1432 | - foreach ($group['additional'] as $key => $value)  | 
                                                        |
| 1433 | - if (empty($value))  | 
                                                        |
| 1462 | +		foreach ($group['additional'] as $key => $value) { | 
                                                        |
| 1463 | + if (empty($value))  | 
                                                        |
| 1434 | 1464 | unset($group['additional'][$key]);  | 
                                                        
| 1465 | + }  | 
                                                        |
| 1435 | 1466 |  		$addgroups = implode(',', $group['additional']); | 
                                                        
| 1436 | 1467 | |
| 1437 | 1468 |  		$smcFunc['db_query']('', ' | 
                                                        
@@ -1465,8 +1496,9 @@ discard block  | 
                                                    ||
| 1465 | 1496 | loadSubscriptions();  | 
                                                        
| 1466 | 1497 | |
| 1467 | 1498 | // Exists, yes?  | 
                                                        
| 1468 | - if (!isset($context['subscriptions'][$id_subscribe]))  | 
                                                        |
| 1469 | - return;  | 
                                                        |
| 1499 | +	if (!isset($context['subscriptions'][$id_subscribe])) { | 
                                                        |
| 1500 | + return;  | 
                                                        |
| 1501 | + }  | 
                                                        |
| 1470 | 1502 | |
| 1471 | 1503 | $curSub = $context['subscriptions'][$id_subscribe];  | 
                                                        
| 1472 | 1504 | |
@@ -1514,16 +1546,19 @@ discard block  | 
                                                    ||
| 1514 | 1546 | list ($id_sublog, $endtime, $starttime) = $smcFunc['db_fetch_row']($request);  | 
                                                        
| 1515 | 1547 | |
| 1516 | 1548 | // If this has already expired but is active, extension means the period from now.  | 
                                                        
| 1517 | - if ($endtime < time())  | 
                                                        |
| 1518 | - $endtime = time();  | 
                                                        |
| 1519 | - if ($starttime == 0)  | 
                                                        |
| 1520 | - $starttime = time();  | 
                                                        |
| 1549 | +		if ($endtime < time()) { | 
                                                        |
| 1550 | + $endtime = time();  | 
                                                        |
| 1551 | + }  | 
                                                        |
| 1552 | +		if ($starttime == 0) { | 
                                                        |
| 1553 | + $starttime = time();  | 
                                                        |
| 1554 | + }  | 
                                                        |
| 1521 | 1555 | |
| 1522 | 1556 | // Work out the new expiry date.  | 
                                                        
| 1523 | 1557 | $endtime += $duration;  | 
                                                        
| 1524 | 1558 | |
| 1525 | - if ($forceEndTime != 0)  | 
                                                        |
| 1526 | - $endtime = $forceEndTime;  | 
                                                        |
| 1559 | +		if ($forceEndTime != 0) { | 
                                                        |
| 1560 | + $endtime = $forceEndTime;  | 
                                                        |
| 1561 | + }  | 
                                                        |
| 1527 | 1562 | |
| 1528 | 1563 | // As everything else should be good, just update!  | 
                                                        
| 1529 | 1564 |  		$smcFunc['db_query']('', ' | 
                                                        
@@ -1553,8 +1588,9 @@ discard block  | 
                                                    ||
| 1553 | 1588 | );  | 
                                                        
| 1554 | 1589 | |
| 1555 | 1590 | // Just in case the member doesn't exist.  | 
                                                        
| 1556 | - if ($smcFunc['db_num_rows']($request) == 0)  | 
                                                        |
| 1557 | - return;  | 
                                                        |
| 1591 | +	if ($smcFunc['db_num_rows']($request) == 0) { | 
                                                        |
| 1592 | + return;  | 
                                                        |
| 1593 | + }  | 
                                                        |
| 1558 | 1594 | |
| 1559 | 1595 | list ($old_id_group, $additional_groups) = $smcFunc['db_fetch_row']($request);  | 
                                                        
| 1560 | 1596 | $smcFunc['db_free_result']($request);  | 
                                                        
@@ -1571,16 +1607,18 @@ discard block  | 
                                                    ||
| 1571 | 1607 | $id_group = $curSub['prim_group'];  | 
                                                        
| 1572 | 1608 | |
| 1573 | 1609 | // Ensure their old privileges are maintained.  | 
                                                        
| 1574 | - if ($old_id_group != 0)  | 
                                                        |
| 1575 | - $newAddGroups[] = $old_id_group;  | 
                                                        |
| 1610 | +		if ($old_id_group != 0) { | 
                                                        |
| 1611 | + $newAddGroups[] = $old_id_group;  | 
                                                        |
| 1612 | + }  | 
                                                        |
| 1613 | +	} else { | 
                                                        |
| 1614 | + $id_group = $old_id_group;  | 
                                                        |
| 1576 | 1615 | }  | 
                                                        
| 1577 | - else  | 
                                                        |
| 1578 | - $id_group = $old_id_group;  | 
                                                        |
| 1579 | 1616 | |
| 1580 | 1617 | // Yep, make sure it's unique, and no empties.  | 
                                                        
| 1581 | - foreach ($newAddGroups as $k => $v)  | 
                                                        |
| 1582 | - if (empty($v))  | 
                                                        |
| 1618 | +	foreach ($newAddGroups as $k => $v) { | 
                                                        |
| 1619 | + if (empty($v))  | 
                                                        |
| 1583 | 1620 | unset($newAddGroups[$k]);  | 
                                                        
| 1621 | + }  | 
                                                        |
| 1584 | 1622 | $newAddGroups = array_unique($newAddGroups);  | 
                                                        
| 1585 | 1623 |  	$newAddGroups = implode(',', $newAddGroups); | 
                                                        
| 1586 | 1624 | |
@@ -1616,16 +1654,19 @@ discard block  | 
                                                    ||
| 1616 | 1654 | list ($id_sublog, $endtime, $starttime) = $smcFunc['db_fetch_row']($request);  | 
                                                        
| 1617 | 1655 | |
| 1618 | 1656 | // If this has already expired but is active, extension means the period from now.  | 
                                                        
| 1619 | - if ($endtime < time())  | 
                                                        |
| 1620 | - $endtime = time();  | 
                                                        |
| 1621 | - if ($starttime == 0)  | 
                                                        |
| 1622 | - $starttime = time();  | 
                                                        |
| 1657 | +		if ($endtime < time()) { | 
                                                        |
| 1658 | + $endtime = time();  | 
                                                        |
| 1659 | + }  | 
                                                        |
| 1660 | +		if ($starttime == 0) { | 
                                                        |
| 1661 | + $starttime = time();  | 
                                                        |
| 1662 | + }  | 
                                                        |
| 1623 | 1663 | |
| 1624 | 1664 | // Work out the new expiry date.  | 
                                                        
| 1625 | 1665 | $endtime += $duration;  | 
                                                        
| 1626 | 1666 | |
| 1627 | - if ($forceEndTime != 0)  | 
                                                        |
| 1628 | - $endtime = $forceEndTime;  | 
                                                        |
| 1667 | +		if ($forceEndTime != 0) { | 
                                                        |
| 1668 | + $endtime = $forceEndTime;  | 
                                                        |
| 1669 | + }  | 
                                                        |
| 1629 | 1670 | |
| 1630 | 1671 | // As everything else should be good, just update!  | 
                                                        
| 1631 | 1672 |  		$smcFunc['db_query']('', ' | 
                                                        
@@ -1648,13 +1689,15 @@ discard block  | 
                                                    ||
| 1648 | 1689 | |
| 1649 | 1690 | // Otherwise a very simple insert.  | 
                                                        
| 1650 | 1691 | $endtime = time() + $duration;  | 
                                                        
| 1651 | - if ($forceEndTime != 0)  | 
                                                        |
| 1652 | - $endtime = $forceEndTime;  | 
                                                        |
| 1692 | +	if ($forceEndTime != 0) { | 
                                                        |
| 1693 | + $endtime = $forceEndTime;  | 
                                                        |
| 1694 | + }  | 
                                                        |
| 1653 | 1695 | |
| 1654 | - if ($forceStartTime == 0)  | 
                                                        |
| 1655 | - $starttime = time();  | 
                                                        |
| 1656 | - else  | 
                                                        |
| 1657 | - $starttime = $forceStartTime;  | 
                                                        |
| 1696 | +	if ($forceStartTime == 0) { | 
                                                        |
| 1697 | + $starttime = time();  | 
                                                        |
| 1698 | +	} else { | 
                                                        |
| 1699 | + $starttime = $forceStartTime;  | 
                                                        |
| 1700 | + }  | 
                                                        |
| 1658 | 1701 | |
| 1659 | 1702 |  	$smcFunc['db_insert']('', | 
                                                        
| 1660 | 1703 |  		'{db_prefix}log_subscribed', | 
                                                        
@@ -1727,15 +1770,17 @@ discard block  | 
                                                    ||
| 1727 | 1770 | $new_id_group = -1;  | 
                                                        
| 1728 | 1771 | while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        
| 1729 | 1772 |  	{ | 
                                                        
| 1730 | - if (!isset($context['subscriptions'][$row['id_subscribe']]))  | 
                                                        |
| 1731 | - continue;  | 
                                                        |
| 1773 | +		if (!isset($context['subscriptions'][$row['id_subscribe']])) { | 
                                                        |
| 1774 | + continue;  | 
                                                        |
| 1775 | + }  | 
                                                        |
| 1732 | 1776 | |
| 1733 | 1777 | // The one we're removing?  | 
                                                        
| 1734 | 1778 | if ($row['id_subscribe'] == $id_subscribe)  | 
                                                        
| 1735 | 1779 |  		{ | 
                                                        
| 1736 | 1780 |  			$removals = explode(',', $context['subscriptions'][$row['id_subscribe']]['add_groups']); | 
                                                        
| 1737 | - if ($context['subscriptions'][$row['id_subscribe']]['prim_group'] != 0)  | 
                                                        |
| 1738 | - $removals[] = $context['subscriptions'][$row['id_subscribe']]['prim_group'];  | 
                                                        |
| 1781 | +			if ($context['subscriptions'][$row['id_subscribe']]['prim_group'] != 0) { | 
                                                        |
| 1782 | + $removals[] = $context['subscriptions'][$row['id_subscribe']]['prim_group'];  | 
                                                        |
| 1783 | + }  | 
                                                        |
| 1739 | 1784 | $old_id_group = $row['old_id_group'];  | 
                                                        
| 1740 | 1785 | }  | 
                                                        
| 1741 | 1786 | // Otherwise things we allow.  | 
                                                        
@@ -1753,30 +1798,33 @@ discard block  | 
                                                    ||
| 1753 | 1798 | |
| 1754 | 1799 | // Now, for everything we are removing check they definitely are not allowed it.  | 
                                                        
| 1755 | 1800 |  	$existingGroups = explode(',', $additional_groups); | 
                                                        
| 1756 | - foreach ($existingGroups as $key => $group)  | 
                                                        |
| 1757 | - if (empty($group) || (in_array($group, $removals) && !in_array($group, $allowed)))  | 
                                                        |
| 1801 | +	foreach ($existingGroups as $key => $group) { | 
                                                        |
| 1802 | + if (empty($group) || (in_array($group, $removals) && !in_array($group, $allowed)))  | 
                                                        |
| 1758 | 1803 | unset($existingGroups[$key]);  | 
                                                        
| 1804 | + }  | 
                                                        |
| 1759 | 1805 | |
| 1760 | 1806 | // Finally, do something with the current primary group.  | 
                                                        
| 1761 | 1807 | if (in_array($id_group, $removals))  | 
                                                        
| 1762 | 1808 |  	{ | 
                                                        
| 1763 | 1809 | // If this primary group is actually allowed keep it.  | 
                                                        
| 1764 | - if (in_array($id_group, $allowed))  | 
                                                        |
| 1765 | - $existingGroups[] = $id_group;  | 
                                                        |
| 1810 | +		if (in_array($id_group, $allowed)) { | 
                                                        |
| 1811 | + $existingGroups[] = $id_group;  | 
                                                        |
| 1812 | + }  | 
                                                        |
| 1766 | 1813 | |
| 1767 | 1814 | // Either way, change the id_group back.  | 
                                                        
| 1768 | 1815 | if ($new_id_group < 1)  | 
                                                        
| 1769 | 1816 |  		{ | 
                                                        
| 1770 | 1817 | // If we revert to the old id-group we need to ensure it wasn't from a subscription.  | 
                                                        
| 1771 | - foreach ($context['subscriptions'] as $id => $group)  | 
                                                        |
| 1772 | - // It was? Make them a regular member then!  | 
                                                        |
| 1818 | +			foreach ($context['subscriptions'] as $id => $group) { | 
                                                        |
| 1819 | + // It was? Make them a regular member then!  | 
                                                        |
| 1773 | 1820 | if ($group['prim_group'] == $old_id_group)  | 
                                                        
| 1774 | 1821 | $old_id_group = 0;  | 
                                                        
| 1822 | + }  | 
                                                        |
| 1775 | 1823 | |
| 1776 | 1824 | $id_group = $old_id_group;  | 
                                                        
| 1825 | +		} else { | 
                                                        |
| 1826 | + $id_group = $new_id_group;  | 
                                                        |
| 1777 | 1827 | }  | 
                                                        
| 1778 | - else  | 
                                                        |
| 1779 | - $id_group = $new_id_group;  | 
                                                        |
| 1780 | 1828 | }  | 
                                                        
| 1781 | 1829 | |
| 1782 | 1830 | // Crazy stuff, we seem to have our groups fixed, just make them unique  | 
                                                        
@@ -1796,8 +1844,8 @@ discard block  | 
                                                    ||
| 1796 | 1844 | );  | 
                                                        
| 1797 | 1845 | |
| 1798 | 1846 | // Disable the subscription.  | 
                                                        
| 1799 | - if (!$delete)  | 
                                                        |
| 1800 | -		$smcFunc['db_query']('', ' | 
                                                        |
| 1847 | +	if (!$delete) { | 
                                                        |
| 1848 | +			$smcFunc['db_query']('', ' | 
                                                        |
| 1801 | 1849 |  			UPDATE {db_prefix}log_subscribed | 
                                                        
| 1802 | 1850 |  			SET status = {int:not_active} | 
                                                        
| 1803 | 1851 |  			WHERE id_member = {int:current_member} | 
                                                        
@@ -1808,9 +1856,10 @@ discard block  | 
                                                    ||
| 1808 | 1856 | 'current_subscription' => $id_subscribe,  | 
                                                        
| 1809 | 1857 | )  | 
                                                        
| 1810 | 1858 | );  | 
                                                        
| 1859 | + }  | 
                                                        |
| 1811 | 1860 | // Otherwise delete it!  | 
                                                        
| 1812 | - else  | 
                                                        |
| 1813 | -		$smcFunc['db_query']('', ' | 
                                                        |
| 1861 | +	else { | 
                                                        |
| 1862 | +			$smcFunc['db_query']('', ' | 
                                                        |
| 1814 | 1863 |  			DELETE FROM {db_prefix}log_subscribed | 
                                                        
| 1815 | 1864 |  			WHERE id_member = {int:current_member} | 
                                                        
| 1816 | 1865 |  				AND id_subscribe = {int:current_subscription}', | 
                                                        
@@ -1819,7 +1868,8 @@ discard block  | 
                                                    ||
| 1819 | 1868 | 'current_subscription' => $id_subscribe,  | 
                                                        
| 1820 | 1869 | )  | 
                                                        
| 1821 | 1870 | );  | 
                                                        
| 1822 | -}  | 
                                                        |
| 1871 | + }  | 
                                                        |
| 1872 | + }  | 
                                                        |
| 1823 | 1873 | |
| 1824 | 1874 | /**  | 
                                                        
| 1825 | 1875 | * This just kind of caches all the subscription data.  | 
                                                        
@@ -1828,8 +1878,9 @@ discard block  | 
                                                    ||
| 1828 | 1878 |  { | 
                                                        
| 1829 | 1879 | global $context, $txt, $modSettings, $smcFunc;  | 
                                                        
| 1830 | 1880 | |
| 1831 | - if (!empty($context['subscriptions']))  | 
                                                        |
| 1832 | - return;  | 
                                                        |
| 1881 | +	if (!empty($context['subscriptions'])) { | 
                                                        |
| 1882 | + return;  | 
                                                        |
| 1883 | + }  | 
                                                        |
| 1833 | 1884 | |
| 1834 | 1885 | // Make sure this is loaded, just in case.  | 
                                                        
| 1835 | 1886 |  	loadLanguage('ManagePaid'); | 
                                                        
@@ -1846,10 +1897,11 @@ discard block  | 
                                                    ||
| 1846 | 1897 | // Pick a cost.  | 
                                                        
| 1847 | 1898 | $costs = $smcFunc['json_decode']($row['cost'], true);  | 
                                                        
| 1848 | 1899 | |
| 1849 | - if ($row['length'] != 'F' && !empty($modSettings['paid_currency_symbol']) && !empty($costs['fixed']))  | 
                                                        |
| 1850 | - $cost = sprintf($modSettings['paid_currency_symbol'], $costs['fixed']);  | 
                                                        |
| 1851 | - else  | 
                                                        |
| 1852 | - $cost = '???';  | 
                                                        |
| 1900 | +		if ($row['length'] != 'F' && !empty($modSettings['paid_currency_symbol']) && !empty($costs['fixed'])) { | 
                                                        |
| 1901 | + $cost = sprintf($modSettings['paid_currency_symbol'], $costs['fixed']);  | 
                                                        |
| 1902 | +		} else { | 
                                                        |
| 1903 | + $cost = '???';  | 
                                                        |
| 1904 | + }  | 
                                                        |
| 1853 | 1905 | |
| 1854 | 1906 | // Do the span.  | 
                                                        
| 1855 | 1907 |  		preg_match('~(\d*)(\w)~', $row['length'], $match); | 
                                                        
@@ -1876,9 +1928,9 @@ discard block  | 
                                                    ||
| 1876 | 1928 | $num_length *= 31556926;  | 
                                                        
| 1877 | 1929 | break;  | 
                                                        
| 1878 | 1930 | }  | 
                                                        
| 1931 | +		} else { | 
                                                        |
| 1932 | + $length = '??';  | 
                                                        |
| 1879 | 1933 | }  | 
                                                        
| 1880 | - else  | 
                                                        |
| 1881 | - $length = '??';  | 
                                                        |
| 1882 | 1934 | |
| 1883 | 1935 | $context['subscriptions'][$row['id_subscribe']] = array(  | 
                                                        
| 1884 | 1936 | 'id' => $row['id_subscribe'],  | 
                                                        
@@ -1913,8 +1965,9 @@ discard block  | 
                                                    ||
| 1913 | 1965 |  	{ | 
                                                        
| 1914 | 1966 | $ind = $row['status'] == 0 ? 'finished' : 'total';  | 
                                                        
| 1915 | 1967 | |
| 1916 | - if (isset($context['subscriptions'][$row['id_subscribe']]))  | 
                                                        |
| 1917 | - $context['subscriptions'][$row['id_subscribe']][$ind] = $row['member_count'];  | 
                                                        |
| 1968 | +		if (isset($context['subscriptions'][$row['id_subscribe']])) { | 
                                                        |
| 1969 | + $context['subscriptions'][$row['id_subscribe']][$ind] = $row['member_count'];  | 
                                                        |
| 1970 | + }  | 
                                                        |
| 1918 | 1971 | }  | 
                                                        
| 1919 | 1972 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1920 | 1973 | |
@@ -1928,8 +1981,9 @@ discard block  | 
                                                    ||
| 1928 | 1981 | );  | 
                                                        
| 1929 | 1982 | while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        
| 1930 | 1983 |  	{ | 
                                                        
| 1931 | - if (isset($context['subscriptions'][$row['id_subscribe']]))  | 
                                                        |
| 1932 | - $context['subscriptions'][$row['id_subscribe']]['pending'] = $row['total_pending'];  | 
                                                        |
| 1984 | +		if (isset($context['subscriptions'][$row['id_subscribe']])) { | 
                                                        |
| 1985 | + $context['subscriptions'][$row['id_subscribe']]['pending'] = $row['total_pending'];  | 
                                                        |
| 1986 | + }  | 
                                                        |
| 1933 | 1987 | }  | 
                                                        
| 1934 | 1988 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1935 | 1989 | }  | 
                                                        
@@ -4070,7 +4070,7 @@  | 
                                                    ||
| 4070 | 4070 | *  | 
                                                        
| 4071 | 4071 | * @param int $pmID The ID of the PM  | 
                                                        
| 4072 | 4072 | * @param string $validFor Which folders this is valud for - can be 'inbox', 'outbox' or 'in_or_outbox'  | 
                                                        
| 4073 | - * @return boolean Whether the PM is accessible in that folder for the current user  | 
                                                        |
| 4073 | + * @return boolean|null Whether the PM is accessible in that folder for the current user  | 
                                                        |
| 4074 | 4074 | */  | 
                                                        
| 4075 | 4075 | function isAccessiblePM($pmID, $validFor = 'in_or_outbox')  | 
                                                        
| 4076 | 4076 |  { | 
                                                        
@@ -15,8 +15,9 @@ discard block  | 
                                                    ||
| 15 | 15 | * @version 2.1 Beta 4  | 
                                                        
| 16 | 16 | */  | 
                                                        
| 17 | 17 | |
| 18 | -if (!defined('SMF')) | 
                                                        |
| 18 | +if (!defined('SMF')) { | 
                                                        |
| 19 | 19 |  	die('No direct access...'); | 
                                                        
| 20 | +}  | 
                                                        |
| 20 | 21 | |
| 21 | 22 | /**  | 
                                                        
| 22 | 23 | * This helps organize things...  | 
                                                        
@@ -37,13 +38,14 @@ discard block  | 
                                                    ||
| 37 | 38 | |
| 38 | 39 |  	loadLanguage('PersonalMessage+Drafts'); | 
                                                        
| 39 | 40 | |
| 40 | - if (!isset($_REQUEST['xml']))  | 
                                                        |
| 41 | -		loadTemplate('PersonalMessage'); | 
                                                        |
| 41 | +	if (!isset($_REQUEST['xml'])) { | 
                                                        |
| 42 | +			loadTemplate('PersonalMessage'); | 
                                                        |
| 43 | + }  | 
                                                        |
| 42 | 44 | |
| 43 | 45 | // Load up the members maximum message capacity.  | 
                                                        
| 44 | - if ($user_info['is_admin'])  | 
                                                        |
| 45 | - $context['message_limit'] = 0;  | 
                                                        |
| 46 | -	elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null) | 
                                                        |
| 46 | +	if ($user_info['is_admin']) { | 
                                                        |
| 47 | + $context['message_limit'] = 0;  | 
                                                        |
| 48 | +	} elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null) | 
                                                        |
| 47 | 49 |  	{ | 
                                                        
| 48 | 50 | // @todo Why do we do this? It seems like if they have any limit we should use it.  | 
                                                        
| 49 | 51 |  		$request = $smcFunc['db_query']('', ' | 
                                                        
@@ -78,8 +80,9 @@ discard block  | 
                                                    ||
| 78 | 80 | }  | 
                                                        
| 79 | 81 | |
| 80 | 82 | // a previous message was sent successfully? show a small indication.  | 
                                                        
| 81 | - if (isset($_GET['done']) && ($_GET['done'] == 'sent'))  | 
                                                        |
| 82 | - $context['pm_sent'] = true;  | 
                                                        |
| 83 | +	if (isset($_GET['done']) && ($_GET['done'] == 'sent')) { | 
                                                        |
| 84 | + $context['pm_sent'] = true;  | 
                                                        |
| 85 | + }  | 
                                                        |
| 83 | 86 | |
| 84 | 87 | $context['labels'] = array();  | 
                                                        
| 85 | 88 | |
@@ -210,11 +213,11 @@ discard block  | 
                                                    ||
| 210 | 213 |  	{ | 
                                                        
| 211 | 214 | $_REQUEST['sa'] = '';  | 
                                                        
| 212 | 215 | MessageFolder();  | 
                                                        
| 213 | - }  | 
                                                        |
| 214 | - else  | 
                                                        |
| 216 | + } else  | 
                                                        |
| 215 | 217 |  	{ | 
                                                        
| 216 | - if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup')  | 
                                                        |
| 217 | - messageIndexBar($_REQUEST['sa']);  | 
                                                        |
| 218 | +		if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup') { | 
                                                        |
| 219 | + messageIndexBar($_REQUEST['sa']);  | 
                                                        |
| 220 | + }  | 
                                                        |
| 218 | 221 | |
| 219 | 222 | call_helper($subActions[$_REQUEST['sa']]);  | 
                                                        
| 220 | 223 | }  | 
                                                        
@@ -291,16 +294,17 @@ discard block  | 
                                                    ||
| 291 | 294 | );  | 
                                                        
| 292 | 295 | |
| 293 | 296 | // Handle labels.  | 
                                                        
| 294 | - if (empty($context['currently_using_labels']))  | 
                                                        |
| 295 | - unset($pm_areas['labels']);  | 
                                                        |
| 296 | - else  | 
                                                        |
| 297 | +	if (empty($context['currently_using_labels'])) { | 
                                                        |
| 298 | + unset($pm_areas['labels']);  | 
                                                        |
| 299 | + } else  | 
                                                        |
| 297 | 300 |  	{ | 
                                                        
| 298 | 301 | // Note we send labels by id as it will have less problems in the querystring.  | 
                                                        
| 299 | 302 | $unread_in_labels = 0;  | 
                                                        
| 300 | 303 | foreach ($context['labels'] as $label)  | 
                                                        
| 301 | 304 |  		{ | 
                                                        
| 302 | - if ($label['id'] == -1)  | 
                                                        |
| 303 | - continue;  | 
                                                        |
| 305 | +			if ($label['id'] == -1) { | 
                                                        |
| 306 | + continue;  | 
                                                        |
| 307 | + }  | 
                                                        |
| 304 | 308 | |
| 305 | 309 | // Count the amount of unread items in labels.  | 
                                                        
| 306 | 310 | $unread_in_labels += $label['unread_messages'];  | 
                                                        
@@ -314,8 +318,9 @@ discard block  | 
                                                    ||
| 314 | 318 | );  | 
                                                        
| 315 | 319 | }  | 
                                                        
| 316 | 320 | |
| 317 | - if (!empty($unread_in_labels))  | 
                                                        |
| 318 | - $pm_areas['labels']['title'] .= ' <span class="amt">' . $unread_in_labels . '</span>';  | 
                                                        |
| 321 | +		if (!empty($unread_in_labels)) { | 
                                                        |
| 322 | + $pm_areas['labels']['title'] .= ' <span class="amt">' . $unread_in_labels . '</span>';  | 
                                                        |
| 323 | + }  | 
                                                        |
| 319 | 324 | }  | 
                                                        
| 320 | 325 | |
| 321 | 326 | $pm_areas['folders']['areas']['inbox']['unread_messages'] = &$context['labels'][-1]['unread_messages'];  | 
                                                        
@@ -353,8 +358,9 @@ discard block  | 
                                                    ||
| 353 | 358 | unset($pm_areas);  | 
                                                        
| 354 | 359 | |
| 355 | 360 | // No menu means no access.  | 
                                                        
| 356 | - if (!$pm_include_data && (!$user_info['is_guest'] || validateSession()))  | 
                                                        |
| 357 | -		fatal_lang_error('no_access', false); | 
                                                        |
| 361 | +	if (!$pm_include_data && (!$user_info['is_guest'] || validateSession())) { | 
                                                        |
| 362 | +			fatal_lang_error('no_access', false); | 
                                                        |
| 363 | + }  | 
                                                        |
| 358 | 364 | |
| 359 | 365 | // Make a note of the Unique ID for this menu.  | 
                                                        
| 360 | 366 | $context['pm_menu_id'] = $context['max_menu_id'];  | 
                                                        
@@ -365,9 +371,10 @@ discard block  | 
                                                    ||
| 365 | 371 | $context['menu_item_selected'] = $current_area;  | 
                                                        
| 366 | 372 | |
| 367 | 373 | // Set the template for this area and add the profile layer.  | 
                                                        
| 368 | - if (!isset($_REQUEST['xml']))  | 
                                                        |
| 369 | - $context['template_layers'][] = 'pm';  | 
                                                        |
| 370 | -}  | 
                                                        |
| 374 | +	if (!isset($_REQUEST['xml'])) { | 
                                                        |
| 375 | + $context['template_layers'][] = 'pm';  | 
                                                        |
| 376 | + }  | 
                                                        |
| 377 | + }  | 
                                                        |
| 371 | 378 | |
| 372 | 379 | /**  | 
                                                        
| 373 | 380 | * The popup for when we ask for the popup from the user.  | 
                                                        
@@ -399,8 +406,9 @@ discard block  | 
                                                    ||
| 399 | 406 | )  | 
                                                        
| 400 | 407 | );  | 
                                                        
| 401 | 408 | $pms = array();  | 
                                                        
| 402 | - while ($row = $smcFunc['db_fetch_row']($request))  | 
                                                        |
| 403 | - $pms[] = $row[0];  | 
                                                        |
| 409 | +	while ($row = $smcFunc['db_fetch_row']($request)) { | 
                                                        |
| 410 | + $pms[] = $row[0];  | 
                                                        |
| 411 | + }  | 
                                                        |
| 404 | 412 | $smcFunc['db_free_result']($request);  | 
                                                        
| 405 | 413 | |
| 406 | 414 | if (!empty($pms))  | 
                                                        
@@ -428,8 +436,9 @@ discard block  | 
                                                    ||
| 428 | 436 | );  | 
                                                        
| 429 | 437 | while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        
| 430 | 438 |  		{ | 
                                                        
| 431 | - if (!empty($row['id_member_from']))  | 
                                                        |
| 432 | - $senders[] = $row['id_member_from'];  | 
                                                        |
| 439 | +			if (!empty($row['id_member_from'])) { | 
                                                        |
| 440 | + $senders[] = $row['id_member_from'];  | 
                                                        |
| 441 | + }  | 
                                                        |
| 433 | 442 | |
| 434 | 443 | $row['replied_to_you'] = $row['id_pm'] != $row['id_pm_head'];  | 
                                                        
| 435 | 444 | $row['time'] = timeformat($row['timestamp']);  | 
                                                        
@@ -439,13 +448,15 @@ discard block  | 
                                                    ||
| 439 | 448 | $smcFunc['db_free_result']($request);  | 
                                                        
| 440 | 449 | |
| 441 | 450 | $senders = loadMemberData($senders);  | 
                                                        
| 442 | - foreach ($senders as $member)  | 
                                                        |
| 443 | - loadMemberContext($member);  | 
                                                        |
| 451 | +		foreach ($senders as $member) { | 
                                                        |
| 452 | + loadMemberContext($member);  | 
                                                        |
| 453 | + }  | 
                                                        |
| 444 | 454 | |
| 445 | 455 | // Having loaded everyone, attach them to the PMs.  | 
                                                        
| 446 | - foreach ($context['unread_pms'] as $id_pm => $details)  | 
                                                        |
| 447 | - if (!empty($memberContext[$details['id_member_from']]))  | 
                                                        |
| 456 | +		foreach ($context['unread_pms'] as $id_pm => $details) { | 
                                                        |
| 457 | + if (!empty($memberContext[$details['id_member_from']]))  | 
                                                        |
| 448 | 458 | $context['unread_pms'][$id_pm]['member'] = &$memberContext[$details['id_member_from']];  | 
                                                        
| 459 | + }  | 
                                                        |
| 449 | 460 | }  | 
                                                        
| 450 | 461 | }  | 
                                                        
| 451 | 462 | |
@@ -465,12 +476,13 @@ discard block  | 
                                                    ||
| 465 | 476 | }  | 
                                                        
| 466 | 477 | |
| 467 | 478 | // Make sure the starting location is valid.  | 
                                                        
| 468 | - if (isset($_GET['start']) && $_GET['start'] != 'new')  | 
                                                        |
| 469 | - $_GET['start'] = (int) $_GET['start'];  | 
                                                        |
| 470 | - elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first']))  | 
                                                        |
| 471 | - $_GET['start'] = 0;  | 
                                                        |
| 472 | - else  | 
                                                        |
| 473 | - $_GET['start'] = 'new';  | 
                                                        |
| 479 | +	if (isset($_GET['start']) && $_GET['start'] != 'new') { | 
                                                        |
| 480 | + $_GET['start'] = (int) $_GET['start'];  | 
                                                        |
| 481 | +	} elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first'])) { | 
                                                        |
| 482 | + $_GET['start'] = 0;  | 
                                                        |
| 483 | +	} else { | 
                                                        |
| 484 | + $_GET['start'] = 'new';  | 
                                                        |
| 485 | + }  | 
                                                        |
| 474 | 486 | |
| 475 | 487 | // Set up some basic theme stuff.  | 
                                                        
| 476 | 488 | $context['from_or_to'] = $context['folder'] != 'sent' ? 'from' : 'to';  | 
                                                        
@@ -484,9 +496,10 @@ discard block  | 
                                                    ||
| 484 | 496 |  		list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']); | 
                                                        
| 485 | 497 |  		$sig_limits = explode(',', $sig_limits); | 
                                                        
| 486 | 498 | |
| 487 | - if (!empty($sig_limits[5]) || !empty($sig_limits[6]))  | 
                                                        |
| 488 | -			addInlineCss(' | 
                                                        |
| 499 | +		if (!empty($sig_limits[5]) || !empty($sig_limits[6])) { | 
                                                        |
| 500 | +					addInlineCss(' | 
                                                        |
| 489 | 501 |  	.signature img { ' . (!empty($sig_limits[5]) ? 'max-width: ' . (int) $sig_limits[5] . 'px; ' : '') . (!empty($sig_limits[6]) ? 'max-height: ' . (int) $sig_limits[6] . 'px; ' : '') . '}'); | 
                                                        
| 502 | + }  | 
                                                        |
| 490 | 503 | }  | 
                                                        
| 491 | 504 | |
| 492 | 505 | $labelJoin = '';  | 
                                                        
@@ -498,8 +511,7 @@ discard block  | 
                                                    ||
| 498 | 511 |  	{ | 
                                                        
| 499 | 512 | $labelQuery = '  | 
                                                        
| 500 | 513 | AND pmr.in_inbox = 1';  | 
                                                        
| 501 | - }  | 
                                                        |
| 502 | - elseif ($context['folder'] != 'sent')  | 
                                                        |
| 514 | + } elseif ($context['folder'] != 'sent')  | 
                                                        |
| 503 | 515 |  	{ | 
                                                        
| 504 | 516 | $labelJoin = '  | 
                                                        
| 505 | 517 |  			INNER JOIN {db_prefix}pm_labeled_messages AS pl ON (pl.id_pm = pmr.id_pm)'; | 
                                                        
@@ -541,22 +553,24 @@ discard block  | 
                                                    ||
| 541 | 553 |  	$txt['delete_all'] = str_replace('PMBOX', $pmbox, $txt['delete_all']); | 
                                                        
| 542 | 554 | |
| 543 | 555 | // Now, build the link tree!  | 
                                                        
| 544 | - if ($context['current_label_id'] == -1)  | 
                                                        |
| 545 | - $context['linktree'][] = array(  | 
                                                        |
| 556 | +	if ($context['current_label_id'] == -1) { | 
                                                        |
| 557 | + $context['linktree'][] = array(  | 
                                                        |
| 546 | 558 | 'url' => $scripturl . '?action=pm;f=' . $context['folder'],  | 
                                                        
| 547 | 559 | 'name' => $pmbox  | 
                                                        
| 548 | 560 | );  | 
                                                        
| 561 | + }  | 
                                                        |
| 549 | 562 | |
| 550 | 563 | // Build it further for a label.  | 
                                                        
| 551 | - if ($context['current_label_id'] != -1)  | 
                                                        |
| 552 | - $context['linktree'][] = array(  | 
                                                        |
| 564 | +	if ($context['current_label_id'] != -1) { | 
                                                        |
| 565 | + $context['linktree'][] = array(  | 
                                                        |
| 553 | 566 | 'url' => $scripturl . '?action=pm;f=' . $context['folder'] . ';l=' . $context['current_label_id'],  | 
                                                        
| 554 | 567 | 'name' => $txt['pm_current_label'] . ': ' . $context['current_label']  | 
                                                        
| 555 | 568 | );  | 
                                                        
| 569 | + }  | 
                                                        |
| 556 | 570 | |
| 557 | 571 | // Figure out how many messages there are.  | 
                                                        
| 558 | - if ($context['folder'] == 'sent')  | 
                                                        |
| 559 | -		$request = $smcFunc['db_query']('', ' | 
                                                        |
| 572 | +	if ($context['folder'] == 'sent') { | 
                                                        |
| 573 | +			$request = $smcFunc['db_query']('', ' | 
                                                        |
| 560 | 574 |  			SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') | 
                                                        
| 561 | 575 |  			FROM {db_prefix}personal_messages AS pm | 
                                                        
| 562 | 576 |  			WHERE pm.id_member_from = {int:current_member} | 
                                                        
@@ -566,8 +580,8 @@ discard block  | 
                                                    ||
| 566 | 580 | 'not_deleted' => 0,  | 
                                                        
| 567 | 581 | )  | 
                                                        
| 568 | 582 | );  | 
                                                        
| 569 | - else  | 
                                                        |
| 570 | -		$request = $smcFunc['db_query']('', ' | 
                                                        |
| 583 | +	} else { | 
                                                        |
| 584 | +			$request = $smcFunc['db_query']('', ' | 
                                                        |
| 571 | 585 |  			SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') | 
                                                        
| 572 | 586 |  			FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? ' | 
                                                        
| 573 | 587 |  				INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . ' | 
                                                        
@@ -578,6 +592,7 @@ discard block  | 
                                                    ||
| 578 | 592 | 'not_deleted' => 0,  | 
                                                        
| 579 | 593 | )  | 
                                                        
| 580 | 594 | );  | 
                                                        
| 595 | + }  | 
                                                        |
| 581 | 596 | list ($max_messages) = $smcFunc['db_fetch_row']($request);  | 
                                                        
| 582 | 597 | $smcFunc['db_free_result']($request);  | 
                                                        
| 583 | 598 | |
@@ -586,10 +601,11 @@ discard block  | 
                                                    ||
| 586 | 601 | $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];  | 
                                                        
| 587 | 602 | |
| 588 | 603 | // Start on the last page.  | 
                                                        
| 589 | - if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages)  | 
                                                        |
| 590 | - $_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage);  | 
                                                        |
| 591 | - elseif ($_GET['start'] < 0)  | 
                                                        |
| 592 | - $_GET['start'] = 0;  | 
                                                        |
| 604 | +	if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages) { | 
                                                        |
| 605 | + $_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage);  | 
                                                        |
| 606 | +	} elseif ($_GET['start'] < 0) { | 
                                                        |
| 607 | + $_GET['start'] = 0;  | 
                                                        |
| 608 | + }  | 
                                                        |
| 593 | 609 | |
| 594 | 610 | // ... but wait - what if we want to start from a specific message?  | 
                                                        
| 595 | 611 | if (isset($_GET['pmid']))  | 
                                                        
@@ -597,19 +613,21 @@ discard block  | 
                                                    ||
| 597 | 613 | $pmID = (int) $_GET['pmid'];  | 
                                                        
| 598 | 614 | |
| 599 | 615 | // Make sure you have access to this PM.  | 
                                                        
| 600 | - if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox'))  | 
                                                        |
| 601 | -			fatal_lang_error('no_access', false); | 
                                                        |
| 616 | +		if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) { | 
                                                        |
| 617 | +					fatal_lang_error('no_access', false); | 
                                                        |
| 618 | + }  | 
                                                        |
| 602 | 619 | |
| 603 | 620 | $context['current_pm'] = $pmID;  | 
                                                        
| 604 | 621 | |
| 605 | 622 | // With only one page of PM's we're gonna want page 1.  | 
                                                        
| 606 | - if ($max_messages <= $maxPerPage)  | 
                                                        |
| 607 | - $_GET['start'] = 0;  | 
                                                        |
| 623 | +		if ($max_messages <= $maxPerPage) { | 
                                                        |
| 624 | + $_GET['start'] = 0;  | 
                                                        |
| 625 | + }  | 
                                                        |
| 608 | 626 | // If we pass kstart we assume we're in the right place.  | 
                                                        
| 609 | 627 | elseif (!isset($_GET['kstart']))  | 
                                                        
| 610 | 628 |  		{ | 
                                                        
| 611 | - if ($context['folder'] == 'sent')  | 
                                                        |
| 612 | -				$request = $smcFunc['db_query']('', ' | 
                                                        |
| 629 | +			if ($context['folder'] == 'sent') { | 
                                                        |
| 630 | +							$request = $smcFunc['db_query']('', ' | 
                                                        |
| 613 | 631 |  					SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') | 
                                                        
| 614 | 632 |  					FROM {db_prefix}personal_messages | 
                                                        
| 615 | 633 |  					WHERE id_member_from = {int:current_member} | 
                                                        
@@ -621,8 +639,8 @@ discard block  | 
                                                    ||
| 621 | 639 | 'id_pm' => $pmID,  | 
                                                        
| 622 | 640 | )  | 
                                                        
| 623 | 641 | );  | 
                                                        
| 624 | - else  | 
                                                        |
| 625 | -				$request = $smcFunc['db_query']('', ' | 
                                                        |
| 642 | +			} else { | 
                                                        |
| 643 | +							$request = $smcFunc['db_query']('', ' | 
                                                        |
| 626 | 644 |  					SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') | 
                                                        
| 627 | 645 |  					FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? ' | 
                                                        
| 628 | 646 |  						INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . ' | 
                                                        
@@ -635,6 +653,7 @@ discard block  | 
                                                    ||
| 635 | 653 | 'id_pm' => $pmID,  | 
                                                        
| 636 | 654 | )  | 
                                                        
| 637 | 655 | );  | 
                                                        
| 656 | + }  | 
                                                        |
| 638 | 657 | |
| 639 | 658 | list ($_GET['start']) = $smcFunc['db_fetch_row']($request);  | 
                                                        
| 640 | 659 | $smcFunc['db_free_result']($request);  | 
                                                        
@@ -649,8 +668,9 @@ discard block  | 
                                                    ||
| 649 | 668 |  	{ | 
                                                        
| 650 | 669 | $pmsg = (int) $_GET['pmsg'];  | 
                                                        
| 651 | 670 | |
| 652 | - if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox'))  | 
                                                        |
| 653 | -			fatal_lang_error('no_access', false); | 
                                                        |
| 671 | +		if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) { | 
                                                        |
| 672 | +					fatal_lang_error('no_access', false); | 
                                                        |
| 673 | + }  | 
                                                        |
| 654 | 674 | }  | 
                                                        
| 655 | 675 | |
| 656 | 676 | // Set up the page index.  | 
                                                        
@@ -744,8 +764,9 @@ discard block  | 
                                                    ||
| 744 | 764 |  	{ | 
                                                        
| 745 | 765 | if (!isset($recipients[$row['id_pm']]))  | 
                                                        
| 746 | 766 |  		{ | 
                                                        
| 747 | - if (isset($row['id_member_from']))  | 
                                                        |
| 748 | - $posters[$row['id_pm']] = $row['id_member_from'];  | 
                                                        |
| 767 | +			if (isset($row['id_member_from'])) { | 
                                                        |
| 768 | + $posters[$row['id_pm']] = $row['id_member_from'];  | 
                                                        |
| 769 | + }  | 
                                                        |
| 749 | 770 | $pms[$row['id_pm']] = $row['id_pm'];  | 
                                                        
| 750 | 771 | $recipients[$row['id_pm']] = array(  | 
                                                        
| 751 | 772 | 'to' => array(),  | 
                                                        
@@ -754,29 +775,33 @@ discard block  | 
                                                    ||
| 754 | 775 | }  | 
                                                        
| 755 | 776 | |
| 756 | 777 | // Keep track of the last message so we know what the head is without another query!  | 
                                                        
| 757 | - if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm']))  | 
                                                        |
| 758 | - $lastData = array(  | 
                                                        |
| 778 | +		if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm'])) { | 
                                                        |
| 779 | + $lastData = array(  | 
                                                        |
| 759 | 780 | 'id' => $row['id_pm'],  | 
                                                        
| 760 | 781 | 'head' => $row['id_pm_head'],  | 
                                                        
| 761 | 782 | );  | 
                                                        
| 783 | + }  | 
                                                        |
| 762 | 784 | }  | 
                                                        
| 763 | 785 | $smcFunc['db_free_result']($request);  | 
                                                        
| 764 | 786 | |
| 765 | 787 | // Make sure that we have been given a correct head pm id!  | 
                                                        
| 766 | - if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id'])  | 
                                                        |
| 767 | -		fatal_lang_error('no_access', false); | 
                                                        |
| 788 | +	if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id']) { | 
                                                        |
| 789 | +			fatal_lang_error('no_access', false); | 
                                                        |
| 790 | + }  | 
                                                        |
| 768 | 791 | |
| 769 | 792 | if (!empty($pms))  | 
                                                        
| 770 | 793 |  	{ | 
                                                        
| 771 | 794 | // Select the correct current message.  | 
                                                        
| 772 | - if (empty($pmID))  | 
                                                        |
| 773 | - $context['current_pm'] = $lastData['id'];  | 
                                                        |
| 795 | +		if (empty($pmID)) { | 
                                                        |
| 796 | + $context['current_pm'] = $lastData['id'];  | 
                                                        |
| 797 | + }  | 
                                                        |
| 774 | 798 | |
| 775 | 799 | // This is a list of the pm's that are used for "full" display.  | 
                                                        
| 776 | - if ($context['display_mode'] == 0)  | 
                                                        |
| 777 | - $display_pms = $pms;  | 
                                                        |
| 778 | - else  | 
                                                        |
| 779 | - $display_pms = array($context['current_pm']);  | 
                                                        |
| 800 | +		if ($context['display_mode'] == 0) { | 
                                                        |
| 801 | + $display_pms = $pms;  | 
                                                        |
| 802 | +		} else { | 
                                                        |
| 803 | + $display_pms = array($context['current_pm']);  | 
                                                        |
| 804 | + }  | 
                                                        |
| 780 | 805 | |
| 781 | 806 | // At this point we know the main id_pm's. But - if we are looking at conversations we need the others!  | 
                                                        
| 782 | 807 | if ($context['display_mode'] == 2)  | 
                                                        
@@ -798,16 +823,18 @@ discard block  | 
                                                    ||
| 798 | 823 | while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        
| 799 | 824 |  			{ | 
                                                        
| 800 | 825 | // This is, frankly, a joke. We will put in a workaround for people sending to themselves - yawn!  | 
                                                        
| 801 | - if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1)  | 
                                                        |
| 802 | - continue;  | 
                                                        |
| 803 | - elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1)  | 
                                                        |
| 804 | - continue;  | 
                                                        |
| 826 | +				if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1) { | 
                                                        |
| 827 | + continue;  | 
                                                        |
| 828 | +				} elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1) { | 
                                                        |
| 829 | + continue;  | 
                                                        |
| 830 | + }  | 
                                                        |
| 805 | 831 | |
| 806 | - if (!isset($recipients[$row['id_pm']]))  | 
                                                        |
| 807 | - $recipients[$row['id_pm']] = array(  | 
                                                        |
| 832 | +				if (!isset($recipients[$row['id_pm']])) { | 
                                                        |
| 833 | + $recipients[$row['id_pm']] = array(  | 
                                                        |
| 808 | 834 | 'to' => array(),  | 
                                                        
| 809 | 835 | 'bcc' => array()  | 
                                                        
| 810 | 836 | );  | 
                                                        
| 837 | + }  | 
                                                        |
| 811 | 838 | $display_pms[] = $row['id_pm'];  | 
                                                        
| 812 | 839 | $posters[$row['id_pm']] = $row['id_member_from'];  | 
                                                        
| 813 | 840 | }  | 
                                                        
@@ -858,8 +885,9 @@ discard block  | 
                                                    ||
| 858 | 885 | while ($row2 = $smcFunc['db_fetch_assoc']($request2))  | 
                                                        
| 859 | 886 |  				{ | 
                                                        
| 860 | 887 | $l_id = $row2['id_label'];  | 
                                                        
| 861 | - if (isset($context['labels'][$l_id]))  | 
                                                        |
| 862 | -						$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); | 
                                                        |
| 888 | +					if (isset($context['labels'][$l_id])) { | 
                                                        |
| 889 | +											$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); | 
                                                        |
| 890 | + }  | 
                                                        |
| 863 | 891 | }  | 
                                                        
| 864 | 892 | |
| 865 | 893 | $smcFunc['db_free_result']($request2);  | 
                                                        
@@ -876,9 +904,10 @@ discard block  | 
                                                    ||
| 876 | 904 | // Make sure we don't load unnecessary data.  | 
                                                        
| 877 | 905 | if ($context['display_mode'] == 1)  | 
                                                        
| 878 | 906 |  		{ | 
                                                        
| 879 | - foreach ($posters as $k => $v)  | 
                                                        |
| 880 | - if (!in_array($k, $display_pms))  | 
                                                        |
| 907 | +			foreach ($posters as $k => $v) { | 
                                                        |
| 908 | + if (!in_array($k, $display_pms))  | 
                                                        |
| 881 | 909 | unset($posters[$k]);  | 
                                                        
| 910 | + }  | 
                                                        |
| 882 | 911 | }  | 
                                                        
| 883 | 912 | |
| 884 | 913 | // Load any users....  | 
                                                        
@@ -889,8 +918,9 @@ discard block  | 
                                                    ||
| 889 | 918 |  		{ | 
                                                        
| 890 | 919 | // Get the order right.  | 
                                                        
| 891 | 920 | $orderBy = array();  | 
                                                        
| 892 | - foreach (array_reverse($pms) as $pm)  | 
                                                        |
| 893 | - $orderBy[] = 'pm.id_pm = ' . $pm;  | 
                                                        |
| 921 | +			foreach (array_reverse($pms) as $pm) { | 
                                                        |
| 922 | + $orderBy[] = 'pm.id_pm = ' . $pm;  | 
                                                        |
| 923 | + }  | 
                                                        |
| 894 | 924 | |
| 895 | 925 | // Seperate query for these bits!  | 
                                                        
| 896 | 926 |  			$subjects_request = $smcFunc['db_query']('', ' | 
                                                        
@@ -936,9 +966,9 @@ discard block  | 
                                                    ||
| 936 | 966 | // Allow mods to add additional buttons here  | 
                                                        
| 937 | 967 |  			call_integration_hook('integrate_conversation_buttons'); | 
                                                        
| 938 | 968 | }  | 
                                                        
| 969 | +	} else { | 
                                                        |
| 970 | + $messages_request = false;  | 
                                                        |
| 939 | 971 | }  | 
                                                        
| 940 | - else  | 
                                                        |
| 941 | - $messages_request = false;  | 
                                                        |
| 942 | 972 | |
| 943 | 973 |  	$context['can_send_pm'] = allowedTo('pm_send'); | 
                                                        
| 944 | 974 |  	$context['can_send_email'] = allowedTo('moderate_forum'); | 
                                                        
@@ -949,11 +979,13 @@ discard block  | 
                                                    ||
| 949 | 979 | if ($context['folder'] != 'sent' && !empty($context['labels'][(int) $context['current_label_id']]['unread_messages']))  | 
                                                        
| 950 | 980 |  	{ | 
                                                        
| 951 | 981 | // If the display mode is "old sk00l" do them all...  | 
                                                        
| 952 | - if ($context['display_mode'] == 0)  | 
                                                        |
| 953 | - markMessages(null, $context['current_label_id']);  | 
                                                        |
| 982 | +		if ($context['display_mode'] == 0) { | 
                                                        |
| 983 | + markMessages(null, $context['current_label_id']);  | 
                                                        |
| 984 | + }  | 
                                                        |
| 954 | 985 | // Otherwise do just the current one!  | 
                                                        
| 955 | - elseif (!empty($context['current_pm']))  | 
                                                        |
| 956 | - markMessages($display_pms, $context['current_label_id']);  | 
                                                        |
| 986 | +		elseif (!empty($context['current_pm'])) { | 
                                                        |
| 987 | + markMessages($display_pms, $context['current_label_id']);  | 
                                                        |
| 988 | + }  | 
                                                        |
| 957 | 989 | }  | 
                                                        
| 958 | 990 | }  | 
                                                        
| 959 | 991 | |
@@ -971,8 +1003,9 @@ discard block  | 
                                                    ||
| 971 | 1003 | |
| 972 | 1004 | // Count the current message number....  | 
                                                        
| 973 | 1005 | static $counter = null;  | 
                                                        
| 974 | - if ($counter === null || $reset)  | 
                                                        |
| 975 | - $counter = $context['start'];  | 
                                                        |
| 1006 | +	if ($counter === null || $reset) { | 
                                                        |
| 1007 | + $counter = $context['start'];  | 
                                                        |
| 1008 | + }  | 
                                                        |
| 976 | 1009 | |
| 977 | 1010 | static $temp_pm_selected = null;  | 
                                                        
| 978 | 1011 | if ($temp_pm_selected === null)  | 
                                                        
@@ -1017,19 +1050,22 @@ discard block  | 
                                                    ||
| 1017 | 1050 | }  | 
                                                        
| 1018 | 1051 | |
| 1019 | 1052 | // Bail if it's false, ie. no messages.  | 
                                                        
| 1020 | - if ($messages_request == false)  | 
                                                        |
| 1021 | - return false;  | 
                                                        |
| 1053 | +	if ($messages_request == false) { | 
                                                        |
| 1054 | + return false;  | 
                                                        |
| 1055 | + }  | 
                                                        |
| 1022 | 1056 | |
| 1023 | 1057 | // Reset the data?  | 
                                                        
| 1024 | - if ($reset == true)  | 
                                                        |
| 1025 | - return @$smcFunc['db_data_seek']($messages_request, 0);  | 
                                                        |
| 1058 | +	if ($reset == true) { | 
                                                        |
| 1059 | + return @$smcFunc['db_data_seek']($messages_request, 0);  | 
                                                        |
| 1060 | + }  | 
                                                        |
| 1026 | 1061 | |
| 1027 | 1062 | // Get the next one... bail if anything goes wrong.  | 
                                                        
| 1028 | 1063 | $message = $smcFunc['db_fetch_assoc']($messages_request);  | 
                                                        
| 1029 | 1064 | if (!$message)  | 
                                                        
| 1030 | 1065 |  	{ | 
                                                        
| 1031 | - if ($type != 'subject')  | 
                                                        |
| 1032 | - $smcFunc['db_free_result']($messages_request);  | 
                                                        |
| 1066 | +		if ($type != 'subject') { | 
                                                        |
| 1067 | + $smcFunc['db_free_result']($messages_request);  | 
                                                        |
| 1068 | + }  | 
                                                        |
| 1033 | 1069 | |
| 1034 | 1070 | return false;  | 
                                                        
| 1035 | 1071 | }  | 
                                                        
@@ -1049,8 +1085,7 @@ discard block  | 
                                                    ||
| 1049 | 1085 | $memberContext[$message['id_member_from']]['email'] = '';  | 
                                                        
| 1050 | 1086 | $memberContext[$message['id_member_from']]['show_email'] = false;  | 
                                                        
| 1051 | 1087 | $memberContext[$message['id_member_from']]['is_guest'] = true;  | 
                                                        
| 1052 | - }  | 
                                                        |
| 1053 | - else  | 
                                                        |
| 1088 | + } else  | 
                                                        |
| 1054 | 1089 |  	{ | 
                                                        
| 1055 | 1090 |  		$memberContext[$message['id_member_from']]['can_view_profile'] = allowedTo('profile_view') || ($message['id_member_from'] == $user_info['id'] && !$user_info['is_guest']); | 
                                                        
| 1056 | 1091 | $memberContext[$message['id_member_from']]['can_see_warning'] = !isset($context['disabled_fields']['warning_status']) && $memberContext[$message['id_member_from']]['warning_status'] && ($context['user']['can_mod'] || (!empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $message['id_member_from'] == $user_info['id'])));  | 
                                                        
@@ -1091,9 +1126,10 @@ discard block  | 
                                                    ||
| 1091 | 1126 | $counter++;  | 
                                                        
| 1092 | 1127 | |
| 1093 | 1128 | // Any custom profile fields?  | 
                                                        
| 1094 | - if (!empty($memberContext[$message['id_member_from']]['custom_fields']))  | 
                                                        |
| 1095 | - foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom)  | 
                                                        |
| 1129 | +	if (!empty($memberContext[$message['id_member_from']]['custom_fields'])) { | 
                                                        |
| 1130 | + foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom)  | 
                                                        |
| 1096 | 1131 | $output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;  | 
                                                        
| 1132 | + }  | 
                                                        |
| 1097 | 1133 | |
| 1098 | 1134 |  	call_integration_hook('integrate_prepare_pm_context', array(&$output, &$message, $counter)); | 
                                                        
| 1099 | 1135 | |
@@ -1117,22 +1153,28 @@ discard block  | 
                                                    ||
| 1117 | 1153 | $context['search_params'][$k] = $v;  | 
                                                        
| 1118 | 1154 | }  | 
                                                        
| 1119 | 1155 | }  | 
                                                        
| 1120 | - if (isset($_REQUEST['search']))  | 
                                                        |
| 1121 | - $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);  | 
                                                        |
| 1156 | +	if (isset($_REQUEST['search'])) { | 
                                                        |
| 1157 | + $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);  | 
                                                        |
| 1158 | + }  | 
                                                        |
| 1122 | 1159 | |
| 1123 | - if (isset($context['search_params']['search']))  | 
                                                        |
| 1124 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);  | 
                                                        |
| 1125 | - if (isset($context['search_params']['userspec']))  | 
                                                        |
| 1126 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);  | 
                                                        |
| 1160 | +	if (isset($context['search_params']['search'])) { | 
                                                        |
| 1161 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);  | 
                                                        |
| 1162 | + }  | 
                                                        |
| 1163 | +	if (isset($context['search_params']['userspec'])) { | 
                                                        |
| 1164 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);  | 
                                                        |
| 1165 | + }  | 
                                                        |
| 1127 | 1166 | |
| 1128 | - if (!empty($context['search_params']['searchtype']))  | 
                                                        |
| 1129 | - $context['search_params']['searchtype'] = 2;  | 
                                                        |
| 1167 | +	if (!empty($context['search_params']['searchtype'])) { | 
                                                        |
| 1168 | + $context['search_params']['searchtype'] = 2;  | 
                                                        |
| 1169 | + }  | 
                                                        |
| 1130 | 1170 | |
| 1131 | - if (!empty($context['search_params']['minage']))  | 
                                                        |
| 1132 | - $context['search_params']['minage'] = (int) $context['search_params']['minage'];  | 
                                                        |
| 1171 | +	if (!empty($context['search_params']['minage'])) { | 
                                                        |
| 1172 | + $context['search_params']['minage'] = (int) $context['search_params']['minage'];  | 
                                                        |
| 1173 | + }  | 
                                                        |
| 1133 | 1174 | |
| 1134 | - if (!empty($context['search_params']['maxage']))  | 
                                                        |
| 1135 | - $context['search_params']['maxage'] = (int) $context['search_params']['maxage'];  | 
                                                        |
| 1175 | +	if (!empty($context['search_params']['maxage'])) { | 
                                                        |
| 1176 | + $context['search_params']['maxage'] = (int) $context['search_params']['maxage'];  | 
                                                        |
| 1177 | + }  | 
                                                        |
| 1136 | 1178 | |
| 1137 | 1179 | $context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']);  | 
                                                        
| 1138 | 1180 | $context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']);  | 
                                                        
@@ -1159,8 +1201,9 @@ discard block  | 
                                                    ||
| 1159 | 1201 | $context['search_errors']['messages'] = array();  | 
                                                        
| 1160 | 1202 | foreach ($context['search_errors'] as $search_error => $dummy)  | 
                                                        
| 1161 | 1203 |  		{ | 
                                                        
| 1162 | - if ($search_error == 'messages')  | 
                                                        |
| 1163 | - continue;  | 
                                                        |
| 1204 | +			if ($search_error == 'messages') { | 
                                                        |
| 1205 | + continue;  | 
                                                        |
| 1206 | + }  | 
                                                        |
| 1164 | 1207 | |
| 1165 | 1208 | $context['search_errors']['messages'][] = $txt['error_' . $search_error];  | 
                                                        
| 1166 | 1209 | }  | 
                                                        
@@ -1182,8 +1225,9 @@ discard block  | 
                                                    ||
| 1182 | 1225 | global $scripturl, $modSettings, $user_info, $context, $txt;  | 
                                                        
| 1183 | 1226 | global $memberContext, $smcFunc;  | 
                                                        
| 1184 | 1227 | |
| 1185 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])  | 
                                                        |
| 1186 | -		fatal_lang_error('loadavg_search_disabled', false); | 
                                                        |
| 1228 | +	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) { | 
                                                        |
| 1229 | +			fatal_lang_error('loadavg_search_disabled', false); | 
                                                        |
| 1230 | + }  | 
                                                        |
| 1187 | 1231 | |
| 1188 | 1232 | /**  | 
                                                        
| 1189 | 1233 | * @todo For the moment force the folder to the inbox.  | 
                                                        
@@ -1212,35 +1256,40 @@ discard block  | 
                                                    ||
| 1212 | 1256 | $context['start'] = isset($_GET['start']) ? (int) $_GET['start'] : 0;  | 
                                                        
| 1213 | 1257 | |
| 1214 | 1258 | // Store whether simple search was used (needed if the user wants to do another query).  | 
                                                        
| 1215 | - if (!isset($search_params['advanced']))  | 
                                                        |
| 1216 | - $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;  | 
                                                        |
| 1259 | +	if (!isset($search_params['advanced'])) { | 
                                                        |
| 1260 | + $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;  | 
                                                        |
| 1261 | + }  | 
                                                        |
| 1217 | 1262 | |
| 1218 | 1263 | // 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'.  | 
                                                        
| 1219 | - if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2))  | 
                                                        |
| 1220 | - $search_params['searchtype'] = 2;  | 
                                                        |
| 1264 | +	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) { | 
                                                        |
| 1265 | + $search_params['searchtype'] = 2;  | 
                                                        |
| 1266 | + }  | 
                                                        |
| 1221 | 1267 | |
| 1222 | 1268 | // Minimum age of messages. Default to zero (don't set param in that case).  | 
                                                        
| 1223 | - if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0))  | 
                                                        |
| 1224 | - $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];  | 
                                                        |
| 1269 | +	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) { | 
                                                        |
| 1270 | + $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];  | 
                                                        |
| 1271 | + }  | 
                                                        |
| 1225 | 1272 | |
| 1226 | 1273 | // Maximum age of messages. Default to infinite (9999 days: param not set).  | 
                                                        
| 1227 | - if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999))  | 
                                                        |
| 1228 | - $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];  | 
                                                        |
| 1274 | +	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999)) { | 
                                                        |
| 1275 | + $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];  | 
                                                        |
| 1276 | + }  | 
                                                        |
| 1229 | 1277 | |
| 1230 | 1278 | $search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']);  | 
                                                        
| 1231 | 1279 | $search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']);  | 
                                                        
| 1232 | 1280 | |
| 1233 | 1281 | // Default the user name to a wildcard matching every user (*).  | 
                                                        
| 1234 | - if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*'))  | 
                                                        |
| 1235 | - $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];  | 
                                                        |
| 1282 | +	if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) { | 
                                                        |
| 1283 | + $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];  | 
                                                        |
| 1284 | + }  | 
                                                        |
| 1236 | 1285 | |
| 1237 | 1286 | // This will be full of all kinds of parameters!  | 
                                                        
| 1238 | 1287 | $searchq_parameters = array();  | 
                                                        
| 1239 | 1288 | |
| 1240 | 1289 | // If there's no specific user, then don't mention it in the main query.  | 
                                                        
| 1241 | - if (empty($search_params['userspec']))  | 
                                                        |
| 1242 | - $userQuery = '';  | 
                                                        |
| 1243 | - else  | 
                                                        |
| 1290 | +	if (empty($search_params['userspec'])) { | 
                                                        |
| 1291 | + $userQuery = '';  | 
                                                        |
| 1292 | + } else  | 
                                                        |
| 1244 | 1293 |  	{ | 
                                                        
| 1245 | 1294 |  		$userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('"' => '"')); | 
                                                        
| 1246 | 1295 |  		$userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')); | 
                                                        
@@ -1252,8 +1301,9 @@ discard block  | 
                                                    ||
| 1252 | 1301 |  		{ | 
                                                        
| 1253 | 1302 | $possible_users[$k] = trim($possible_users[$k]);  | 
                                                        
| 1254 | 1303 | |
| 1255 | - if (strlen($possible_users[$k]) == 0)  | 
                                                        |
| 1256 | - unset($possible_users[$k]);  | 
                                                        |
| 1304 | +			if (strlen($possible_users[$k]) == 0) { | 
                                                        |
| 1305 | + unset($possible_users[$k]);  | 
                                                        |
| 1306 | + }  | 
                                                        |
| 1257 | 1307 | }  | 
                                                        
| 1258 | 1308 | |
| 1259 | 1309 | if (!empty($possible_users))  | 
                                                        
@@ -1265,8 +1315,9 @@ discard block  | 
                                                    ||
| 1265 | 1315 |  			{ | 
                                                        
| 1266 | 1316 | $where_params['name_' . $k] = $v;  | 
                                                        
| 1267 | 1317 |  				$where_clause[] = '{raw:real_name} LIKE {string:name_' . $k . '}'; | 
                                                        
| 1268 | - if (!isset($where_params['real_name']))  | 
                                                        |
| 1269 | - $where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';  | 
                                                        |
| 1318 | +				if (!isset($where_params['real_name'])) { | 
                                                        |
| 1319 | + $where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';  | 
                                                        |
| 1320 | + }  | 
                                                        |
| 1270 | 1321 | }  | 
                                                        
| 1271 | 1322 | |
| 1272 | 1323 | // Who matches those criteria?  | 
                                                        
@@ -1279,28 +1330,28 @@ discard block  | 
                                                    ||
| 1279 | 1330 | );  | 
                                                        
| 1280 | 1331 | |
| 1281 | 1332 | // Simply do nothing if there're too many members matching the criteria.  | 
                                                        
| 1282 | - if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch)  | 
                                                        |
| 1283 | - $userQuery = '';  | 
                                                        |
| 1284 | - elseif ($smcFunc['db_num_rows']($request) == 0)  | 
                                                        |
| 1333 | +			if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) { | 
                                                        |
| 1334 | + $userQuery = '';  | 
                                                        |
| 1335 | + } elseif ($smcFunc['db_num_rows']($request) == 0)  | 
                                                        |
| 1285 | 1336 |  			{ | 
                                                        
| 1286 | 1337 |  				$userQuery = 'AND pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})'; | 
                                                        
| 1287 | 1338 |  				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\''; | 
                                                        
| 1288 | 1339 | $searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';  | 
                                                        
| 1289 | - }  | 
                                                        |
| 1290 | - else  | 
                                                        |
| 1340 | + } else  | 
                                                        |
| 1291 | 1341 |  			{ | 
                                                        
| 1292 | 1342 | $memberlist = array();  | 
                                                        
| 1293 | - while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        |
| 1294 | - $memberlist[] = $row['id_member'];  | 
                                                        |
| 1343 | +				while ($row = $smcFunc['db_fetch_assoc']($request)) { | 
                                                        |
| 1344 | + $memberlist[] = $row['id_member'];  | 
                                                        |
| 1345 | + }  | 
                                                        |
| 1295 | 1346 |  				$userQuery = 'AND (pm.id_member_from IN ({array_int:member_list}) OR (pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})))'; | 
                                                        
| 1296 | 1347 |  				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\''; | 
                                                        
| 1297 | 1348 | $searchq_parameters['member_list'] = $memberlist;  | 
                                                        
| 1298 | 1349 | $searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';  | 
                                                        
| 1299 | 1350 | }  | 
                                                        
| 1300 | 1351 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1352 | +		} else { | 
                                                        |
| 1353 | + $userQuery = '';  | 
                                                        |
| 1301 | 1354 | }  | 
                                                        
| 1302 | - else  | 
                                                        |
| 1303 | - $userQuery = '';  | 
                                                        |
| 1304 | 1355 | }  | 
                                                        
| 1305 | 1356 | |
| 1306 | 1357 | // Setup the sorting variables...  | 
                                                        
@@ -1308,8 +1359,9 @@ discard block  | 
                                                    ||
| 1308 | 1359 | $sort_columns = array(  | 
                                                        
| 1309 | 1360 | 'pm.id_pm',  | 
                                                        
| 1310 | 1361 | );  | 
                                                        
| 1311 | - if (empty($search_params['sort']) && !empty($_REQUEST['sort']))  | 
                                                        |
| 1312 | -		list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); | 
                                                        |
| 1362 | +	if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) { | 
                                                        |
| 1363 | +			list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); | 
                                                        |
| 1364 | + }  | 
                                                        |
| 1313 | 1365 | $search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'pm.id_pm';  | 
                                                        
| 1314 | 1366 | $search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc';  | 
                                                        
| 1315 | 1367 | |
@@ -1319,24 +1371,27 @@ discard block  | 
                                                    ||
| 1319 | 1371 | if ($context['folder'] == 'inbox' && !empty($search_params['advanced']) && $context['currently_using_labels'])  | 
                                                        
| 1320 | 1372 |  	{ | 
                                                        
| 1321 | 1373 | // Came here from pagination? Put them back into $_REQUEST for sanitization.  | 
                                                        
| 1322 | - if (isset($search_params['labels']))  | 
                                                        |
| 1323 | -			$_REQUEST['searchlabel'] = explode(',', $search_params['labels']); | 
                                                        |
| 1374 | +		if (isset($search_params['labels'])) { | 
                                                        |
| 1375 | +					$_REQUEST['searchlabel'] = explode(',', $search_params['labels']); | 
                                                        |
| 1376 | + }  | 
                                                        |
| 1324 | 1377 | |
| 1325 | 1378 | // Assuming we have some labels - make them all integers.  | 
                                                        
| 1326 | 1379 | if (!empty($_REQUEST['searchlabel']) && is_array($_REQUEST['searchlabel']))  | 
                                                        
| 1327 | 1380 |  		{ | 
                                                        
| 1328 | - foreach ($_REQUEST['searchlabel'] as $key => $id)  | 
                                                        |
| 1329 | - $_REQUEST['searchlabel'][$key] = (int) $id;  | 
                                                        |
| 1381 | +			foreach ($_REQUEST['searchlabel'] as $key => $id) { | 
                                                        |
| 1382 | + $_REQUEST['searchlabel'][$key] = (int) $id;  | 
                                                        |
| 1383 | + }  | 
                                                        |
| 1384 | +		} else { | 
                                                        |
| 1385 | + $_REQUEST['searchlabel'] = array();  | 
                                                        |
| 1330 | 1386 | }  | 
                                                        
| 1331 | - else  | 
                                                        |
| 1332 | - $_REQUEST['searchlabel'] = array();  | 
                                                        |
| 1333 | 1387 | |
| 1334 | 1388 | // Now that everything is cleaned up a bit, make the labels a param.  | 
                                                        
| 1335 | 1389 |  		$search_params['labels'] = implode(',', $_REQUEST['searchlabel']); | 
                                                        
| 1336 | 1390 | |
| 1337 | 1391 | // No labels selected? That must be an error!  | 
                                                        
| 1338 | - if (empty($_REQUEST['searchlabel']))  | 
                                                        |
| 1339 | - $context['search_errors']['no_labels_selected'] = true;  | 
                                                        |
| 1392 | +		if (empty($_REQUEST['searchlabel'])) { | 
                                                        |
| 1393 | + $context['search_errors']['no_labels_selected'] = true;  | 
                                                        |
| 1394 | + }  | 
                                                        |
| 1340 | 1395 | // Otherwise prepare the query!  | 
                                                        
| 1341 | 1396 | elseif (count($_REQUEST['searchlabel']) != count($context['labels']))  | 
                                                        
| 1342 | 1397 |  		{ | 
                                                        
@@ -1359,8 +1414,7 @@ discard block  | 
                                                    ||
| 1359 | 1414 | // Not searching the inbox - PM must be labeled  | 
                                                        
| 1360 | 1415 |  					$labelQuery = ' AND pml.id_label IN ({array_int:labels})'; | 
                                                        
| 1361 | 1416 |  					$labelJoin = ' INNER JOIN {db_prefix}pm_labeled_messages AS pml ON (pml.id_pm = pmr.id_pm)'; | 
                                                        
| 1362 | - }  | 
                                                        |
| 1363 | - else  | 
                                                        |
| 1417 | + } else  | 
                                                        |
| 1364 | 1418 |  				{ | 
                                                        
| 1365 | 1419 | // Searching the inbox - PM doesn't have to be labeled  | 
                                                        
| 1366 | 1420 |  					$labelQuery = ' AND (' . substr($labelQuery, 5) . ' OR pml.id_label IN ({array_int:labels}))'; | 
                                                        
@@ -1375,8 +1429,9 @@ discard block  | 
                                                    ||
| 1375 | 1429 | // What are we actually searching for?  | 
                                                        
| 1376 | 1430 | $search_params['search'] = !empty($search_params['search']) ? $search_params['search'] : (isset($_REQUEST['search']) ? $_REQUEST['search'] : '');  | 
                                                        
| 1377 | 1431 | // If we ain't got nothing - we should error!  | 
                                                        
| 1378 | - if (!isset($search_params['search']) || $search_params['search'] == '')  | 
                                                        |
| 1379 | - $context['search_errors']['invalid_search_string'] = true;  | 
                                                        |
| 1432 | +	if (!isset($search_params['search']) || $search_params['search'] == '') { | 
                                                        |
| 1433 | + $context['search_errors']['invalid_search_string'] = true;  | 
                                                        |
| 1434 | + }  | 
                                                        |
| 1380 | 1435 | |
| 1381 | 1436 | // Extract phrase parts first (e.g. some words "this is a phrase" some more words.)  | 
                                                        
| 1382 | 1437 |  	preg_match_all('~(?:^|\s)([-]?)"([^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), $search_params['search'], $matches, PREG_PATTERN_ORDER); | 
                                                        
@@ -1389,12 +1444,14 @@ discard block  | 
                                                    ||
| 1389 | 1444 | $excludedWords = array();  | 
                                                        
| 1390 | 1445 | |
| 1391 | 1446 | // .. first, we check for things like -"some words", but not "-some words".  | 
                                                        
| 1392 | - foreach ($matches[1] as $index => $word)  | 
                                                        |
| 1393 | - if ($word == '-')  | 
                                                        |
| 1447 | +	foreach ($matches[1] as $index => $word) { | 
                                                        |
| 1448 | + if ($word == '-')  | 
                                                        |
| 1394 | 1449 |  		{ | 
                                                        
| 1395 | 1450 | $word = $smcFunc['strtolower'](trim($searchArray[$index]));  | 
                                                        
| 1396 | - if (strlen($word) > 0)  | 
                                                        |
| 1397 | - $excludedWords[] = $word;  | 
                                                        |
| 1451 | + }  | 
                                                        |
| 1452 | +			if (strlen($word) > 0) { | 
                                                        |
| 1453 | + $excludedWords[] = $word;  | 
                                                        |
| 1454 | + }  | 
                                                        |
| 1398 | 1455 | unset($searchArray[$index]);  | 
                                                        
| 1399 | 1456 | }  | 
                                                        
| 1400 | 1457 | |
@@ -1404,8 +1461,9 @@ discard block  | 
                                                    ||
| 1404 | 1461 | if (strpos(trim($word), '-') === 0)  | 
                                                        
| 1405 | 1462 |  		{ | 
                                                        
| 1406 | 1463 | $word = substr($smcFunc['strtolower']($word), 1);  | 
                                                        
| 1407 | - if (strlen($word) > 0)  | 
                                                        |
| 1408 | - $excludedWords[] = $word;  | 
                                                        |
| 1464 | +			if (strlen($word) > 0) { | 
                                                        |
| 1465 | + $excludedWords[] = $word;  | 
                                                        |
| 1466 | + }  | 
                                                        |
| 1409 | 1467 | unset($tempSearch[$index]);  | 
                                                        
| 1410 | 1468 | }  | 
                                                        
| 1411 | 1469 | }  | 
                                                        
@@ -1416,9 +1474,9 @@ discard block  | 
                                                    ||
| 1416 | 1474 | foreach ($searchArray as $index => $value)  | 
                                                        
| 1417 | 1475 |  	{ | 
                                                        
| 1418 | 1476 | $searchArray[$index] = $smcFunc['strtolower'](trim($value));  | 
                                                        
| 1419 | - if ($searchArray[$index] == '')  | 
                                                        |
| 1420 | - unset($searchArray[$index]);  | 
                                                        |
| 1421 | - else  | 
                                                        |
| 1477 | +		if ($searchArray[$index] == '') { | 
                                                        |
| 1478 | + unset($searchArray[$index]);  | 
                                                        |
| 1479 | + } else  | 
                                                        |
| 1422 | 1480 |  		{ | 
                                                        
| 1423 | 1481 | // Sort out entities first.  | 
                                                        
| 1424 | 1482 | $searchArray[$index] = $smcFunc['htmlspecialchars']($searchArray[$index]);  | 
                                                        
@@ -1428,27 +1486,32 @@ discard block  | 
                                                    ||
| 1428 | 1486 | |
| 1429 | 1487 | // Create an array of replacements for highlighting.  | 
                                                        
| 1430 | 1488 | $context['mark'] = array();  | 
                                                        
| 1431 | - foreach ($searchArray as $word)  | 
                                                        |
| 1432 | - $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';  | 
                                                        |
| 1489 | +	foreach ($searchArray as $word) { | 
                                                        |
| 1490 | + $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';  | 
                                                        |
| 1491 | + }  | 
                                                        |
| 1433 | 1492 | |
| 1434 | 1493 | // This contains *everything*  | 
                                                        
| 1435 | 1494 | $searchWords = array_merge($searchArray, $excludedWords);  | 
                                                        
| 1436 | 1495 | |
| 1437 | 1496 | // Make sure at least one word is being searched for.  | 
                                                        
| 1438 | - if (empty($searchArray))  | 
                                                        |
| 1439 | - $context['search_errors']['invalid_search_string'] = true;  | 
                                                        |
| 1497 | +	if (empty($searchArray)) { | 
                                                        |
| 1498 | + $context['search_errors']['invalid_search_string'] = true;  | 
                                                        |
| 1499 | + }  | 
                                                        |
| 1440 | 1500 | |
| 1441 | 1501 | // Sort out the search query so the user can edit it - if they want.  | 
                                                        
| 1442 | 1502 | $context['search_params'] = $search_params;  | 
                                                        
| 1443 | - if (isset($context['search_params']['search']))  | 
                                                        |
| 1444 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);  | 
                                                        |
| 1445 | - if (isset($context['search_params']['userspec']))  | 
                                                        |
| 1446 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);  | 
                                                        |
| 1503 | +	if (isset($context['search_params']['search'])) { | 
                                                        |
| 1504 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);  | 
                                                        |
| 1505 | + }  | 
                                                        |
| 1506 | +	if (isset($context['search_params']['userspec'])) { | 
                                                        |
| 1507 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);  | 
                                                        |
| 1508 | + }  | 
                                                        |
| 1447 | 1509 | |
| 1448 | 1510 | // Now we have all the parameters, combine them together for pagination and the like...  | 
                                                        
| 1449 | 1511 | $context['params'] = array();  | 
                                                        
| 1450 | - foreach ($search_params as $k => $v)  | 
                                                        |
| 1451 | - $context['params'][] = $k . '|\'|' . $v;  | 
                                                        |
| 1512 | +	foreach ($search_params as $k => $v) { | 
                                                        |
| 1513 | + $context['params'][] = $k . '|\'|' . $v;  | 
                                                        |
| 1514 | + }  | 
                                                        |
| 1452 | 1515 |  	$context['params'] = base64_encode(implode('|"|', $context['params'])); | 
                                                        
| 1453 | 1516 | |
| 1454 | 1517 | // Compile the subject query part.  | 
                                                        
@@ -1456,26 +1519,31 @@ discard block  | 
                                                    ||
| 1456 | 1519 | |
| 1457 | 1520 | foreach ($searchWords as $index => $word)  | 
                                                        
| 1458 | 1521 |  	{ | 
                                                        
| 1459 | - if ($word == '')  | 
                                                        |
| 1460 | - continue;  | 
                                                        |
| 1522 | +		if ($word == '') { | 
                                                        |
| 1523 | + continue;  | 
                                                        |
| 1524 | + }  | 
                                                        |
| 1461 | 1525 | |
| 1462 | - if ($search_params['subject_only'])  | 
                                                        |
| 1463 | -			$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}'; | 
                                                        |
| 1464 | - else  | 
                                                        |
| 1465 | -			$andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})'; | 
                                                        |
| 1526 | +		if ($search_params['subject_only']) { | 
                                                        |
| 1527 | +					$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}'; | 
                                                        |
| 1528 | +		} else { | 
                                                        |
| 1529 | +					$andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})'; | 
                                                        |
| 1530 | + }  | 
                                                        |
| 1466 | 1531 |  		$searchq_parameters['search_' . $index] = '%' . strtr($word, array('_' => '\\_', '%' => '\\%')) . '%'; | 
                                                        
| 1467 | 1532 | }  | 
                                                        
| 1468 | 1533 | |
| 1469 | 1534 | $searchQuery = ' 1=1';  | 
                                                        
| 1470 | - if (!empty($andQueryParts))  | 
                                                        |
| 1471 | - $searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);  | 
                                                        |
| 1535 | +	if (!empty($andQueryParts)) { | 
                                                        |
| 1536 | + $searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);  | 
                                                        |
| 1537 | + }  | 
                                                        |
| 1472 | 1538 | |
| 1473 | 1539 | // Age limits?  | 
                                                        
| 1474 | 1540 | $timeQuery = '';  | 
                                                        
| 1475 | - if (!empty($search_params['minage']))  | 
                                                        |
| 1476 | - $timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);  | 
                                                        |
| 1477 | - if (!empty($search_params['maxage']))  | 
                                                        |
| 1478 | - $timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);  | 
                                                        |
| 1541 | +	if (!empty($search_params['minage'])) { | 
                                                        |
| 1542 | + $timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);  | 
                                                        |
| 1543 | + }  | 
                                                        |
| 1544 | +	if (!empty($search_params['maxage'])) { | 
                                                        |
| 1545 | + $timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);  | 
                                                        |
| 1546 | + }  | 
                                                        |
| 1479 | 1547 | |
| 1480 | 1548 | // If we have errors - return back to the first screen...  | 
                                                        
| 1481 | 1549 | if (!empty($context['search_errors']))  | 
                                                        
@@ -1561,8 +1629,9 @@ discard block  | 
                                                    ||
| 1561 | 1629 | )  | 
                                                        
| 1562 | 1630 | );  | 
                                                        
| 1563 | 1631 | $real_pm_ids = array();  | 
                                                        
| 1564 | - while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        |
| 1565 | - $real_pm_ids[$row['id_pm_head']] = $row['id_pm'];  | 
                                                        |
| 1632 | +		while ($row = $smcFunc['db_fetch_assoc']($request)) { | 
                                                        |
| 1633 | + $real_pm_ids[$row['id_pm_head']] = $row['id_pm'];  | 
                                                        |
| 1634 | + }  | 
                                                        |
| 1566 | 1635 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1567 | 1636 | }  | 
                                                        
| 1568 | 1637 | |
@@ -1592,8 +1661,9 @@ discard block  | 
                                                    ||
| 1592 | 1661 | );  | 
                                                        
| 1593 | 1662 | while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        
| 1594 | 1663 |  		{ | 
                                                        
| 1595 | - if ($context['folder'] == 'sent' || empty($row['bcc']))  | 
                                                        |
| 1596 | - $recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>';  | 
                                                        |
| 1664 | +			if ($context['folder'] == 'sent' || empty($row['bcc'])) { | 
                                                        |
| 1665 | + $recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>';  | 
                                                        |
| 1666 | + }  | 
                                                        |
| 1597 | 1667 | |
| 1598 | 1668 | if ($row['id_member_to'] == $user_info['id'] && $context['folder'] != 'sent')  | 
                                                        
| 1599 | 1669 |  			{ | 
                                                        
@@ -1614,12 +1684,14 @@ discard block  | 
                                                    ||
| 1614 | 1684 | while ($row2 = $smcFunc['db_fetch_assoc']($request2))  | 
                                                        
| 1615 | 1685 |  				{ | 
                                                        
| 1616 | 1686 | $l_id = $row2['id_label'];  | 
                                                        
| 1617 | - if (isset($context['labels'][$l_id]))  | 
                                                        |
| 1618 | -						$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); | 
                                                        |
| 1687 | +					if (isset($context['labels'][$l_id])) { | 
                                                        |
| 1688 | +											$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); | 
                                                        |
| 1689 | + }  | 
                                                        |
| 1619 | 1690 | |
| 1620 | 1691 | // Here we find the first label on a message - for linking to posts in results  | 
                                                        
| 1621 | - if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1)  | 
                                                        |
| 1622 | - $context['first_label'][$row['id_pm']] = $l_id;  | 
                                                        |
| 1692 | +					if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1) { | 
                                                        |
| 1693 | + $context['first_label'][$row['id_pm']] = $l_id;  | 
                                                        |
| 1694 | + }  | 
                                                        |
| 1623 | 1695 | }  | 
                                                        
| 1624 | 1696 | |
| 1625 | 1697 | $smcFunc['db_free_result']($request2);  | 
                                                        
@@ -1746,8 +1818,9 @@ discard block  | 
                                                    ||
| 1746 | 1818 | list ($postCount) = $smcFunc['db_fetch_row']($request);  | 
                                                        
| 1747 | 1819 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1748 | 1820 | |
| 1749 | - if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])  | 
                                                        |
| 1750 | -			fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); | 
                                                        |
| 1821 | +		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) { | 
                                                        |
| 1822 | +					fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); | 
                                                        |
| 1823 | + }  | 
                                                        |
| 1751 | 1824 | }  | 
                                                        
| 1752 | 1825 | |
| 1753 | 1826 | // Quoting/Replying to a message?  | 
                                                        
@@ -1756,8 +1829,9 @@ discard block  | 
                                                    ||
| 1756 | 1829 | $pmsg = (int) $_REQUEST['pmsg'];  | 
                                                        
| 1757 | 1830 | |
| 1758 | 1831 | // Make sure this is yours.  | 
                                                        
| 1759 | - if (!isAccessiblePM($pmsg))  | 
                                                        |
| 1760 | -			fatal_lang_error('no_access', false); | 
                                                        |
| 1832 | +		if (!isAccessiblePM($pmsg)) { | 
                                                        |
| 1833 | +					fatal_lang_error('no_access', false); | 
                                                        |
| 1834 | + }  | 
                                                        |
| 1761 | 1835 | |
| 1762 | 1836 | // Work out whether this is one you've received?  | 
                                                        
| 1763 | 1837 |  		$request = $smcFunc['db_query']('', ' | 
                                                        
@@ -1794,8 +1868,9 @@ discard block  | 
                                                    ||
| 1794 | 1868 | 'id_pm' => $pmsg,  | 
                                                        
| 1795 | 1869 | )  | 
                                                        
| 1796 | 1870 | );  | 
                                                        
| 1797 | - if ($smcFunc['db_num_rows']($request) == 0)  | 
                                                        |
| 1798 | -			fatal_lang_error('pm_not_yours', false); | 
                                                        |
| 1871 | +		if ($smcFunc['db_num_rows']($request) == 0) { | 
                                                        |
| 1872 | +					fatal_lang_error('pm_not_yours', false); | 
                                                        |
| 1873 | + }  | 
                                                        |
| 1799 | 1874 | $row_quoted = $smcFunc['db_fetch_assoc']($request);  | 
                                                        
| 1800 | 1875 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1801 | 1876 | |
@@ -1806,9 +1881,9 @@ discard block  | 
                                                    ||
| 1806 | 1881 | // Add 'Re: ' to it....  | 
                                                        
| 1807 | 1882 |  		if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) | 
                                                        
| 1808 | 1883 |  		{ | 
                                                        
| 1809 | - if ($language === $user_info['language'])  | 
                                                        |
| 1810 | - $context['response_prefix'] = $txt['response_prefix'];  | 
                                                        |
| 1811 | - else  | 
                                                        |
| 1884 | +			if ($language === $user_info['language']) { | 
                                                        |
| 1885 | + $context['response_prefix'] = $txt['response_prefix'];  | 
                                                        |
| 1886 | + } else  | 
                                                        |
| 1812 | 1887 |  			{ | 
                                                        
| 1813 | 1888 |  				loadLanguage('index', $language, false); | 
                                                        
| 1814 | 1889 | $context['response_prefix'] = $txt['response_prefix'];  | 
                                                        
@@ -1817,22 +1892,25 @@ discard block  | 
                                                    ||
| 1817 | 1892 |  			cache_put_data('response_prefix', $context['response_prefix'], 600); | 
                                                        
| 1818 | 1893 | }  | 
                                                        
| 1819 | 1894 | $form_subject = $row_quoted['subject'];  | 
                                                        
| 1820 | - if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)  | 
                                                        |
| 1821 | - $form_subject = $context['response_prefix'] . $form_subject;  | 
                                                        |
| 1895 | +		if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) { | 
                                                        |
| 1896 | + $form_subject = $context['response_prefix'] . $form_subject;  | 
                                                        |
| 1897 | + }  | 
                                                        |
| 1822 | 1898 | |
| 1823 | 1899 | if (isset($_REQUEST['quote']))  | 
                                                        
| 1824 | 1900 |  		{ | 
                                                        
| 1825 | 1901 | // Remove any nested quotes and <br>...  | 
                                                        
| 1826 | 1902 |  			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $row_quoted['body']); | 
                                                        
| 1827 | - if (!empty($modSettings['removeNestedQuotes']))  | 
                                                        |
| 1828 | -				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); | 
                                                        |
| 1829 | - if (empty($row_quoted['id_member']))  | 
                                                        |
| 1830 | - $form_message = '[quote author="' . $row_quoted['real_name'] . '"]' . "\n" . $form_message . "\n" . '[/quote]';  | 
                                                        |
| 1831 | - else  | 
                                                        |
| 1832 | - $form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]';  | 
                                                        |
| 1903 | +			if (!empty($modSettings['removeNestedQuotes'])) { | 
                                                        |
| 1904 | +							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); | 
                                                        |
| 1905 | + }  | 
                                                        |
| 1906 | +			if (empty($row_quoted['id_member'])) { | 
                                                        |
| 1907 | + $form_message = '[quote author="' . $row_quoted['real_name'] . '"]' . "\n" . $form_message . "\n" . '[/quote]';  | 
                                                        |
| 1908 | +			} else { | 
                                                        |
| 1909 | + $form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]';  | 
                                                        |
| 1910 | + }  | 
                                                        |
| 1911 | +		} else { | 
                                                        |
| 1912 | + $form_message = '';  | 
                                                        |
| 1833 | 1913 | }  | 
                                                        
| 1834 | - else  | 
                                                        |
| 1835 | - $form_message = '';  | 
                                                        |
| 1836 | 1914 | |
| 1837 | 1915 | // Do the BBC thang on the message.  | 
                                                        
| 1838 | 1916 | $row_quoted['body'] = parse_bbc($row_quoted['body'], true, 'pm' . $row_quoted['id_pm']);  | 
                                                        
@@ -1853,8 +1931,7 @@ discard block  | 
                                                    ||
| 1853 | 1931 | 'timestamp' => forum_time(true, $row_quoted['msgtime']),  | 
                                                        
| 1854 | 1932 | 'body' => $row_quoted['body']  | 
                                                        
| 1855 | 1933 | );  | 
                                                        
| 1856 | - }  | 
                                                        |
| 1857 | - else  | 
                                                        |
| 1934 | + } else  | 
                                                        |
| 1858 | 1935 |  	{ | 
                                                        
| 1859 | 1936 | $context['quoted_message'] = false;  | 
                                                        
| 1860 | 1937 | $form_subject = '';  | 
                                                        
@@ -1873,11 +1950,12 @@ discard block  | 
                                                    ||
| 1873 | 1950 | if ($_REQUEST['u'] == 'all' && isset($row_quoted))  | 
                                                        
| 1874 | 1951 |  		{ | 
                                                        
| 1875 | 1952 | // Firstly, to reply to all we clearly already have $row_quoted - so have the original member from.  | 
                                                        
| 1876 | - if ($row_quoted['id_member'] != $user_info['id'])  | 
                                                        |
| 1877 | - $context['recipients']['to'][] = array(  | 
                                                        |
| 1953 | +			if ($row_quoted['id_member'] != $user_info['id']) { | 
                                                        |
| 1954 | + $context['recipients']['to'][] = array(  | 
                                                        |
| 1878 | 1955 | 'id' => $row_quoted['id_member'],  | 
                                                        
| 1879 | 1956 | 'name' => $smcFunc['htmlspecialchars']($row_quoted['real_name']),  | 
                                                        
| 1880 | 1957 | );  | 
                                                        
| 1958 | + }  | 
                                                        |
| 1881 | 1959 | |
| 1882 | 1960 | // Now to get the others.  | 
                                                        
| 1883 | 1961 |  			$request = $smcFunc['db_query']('', ' | 
                                                        
@@ -1893,18 +1971,19 @@ discard block  | 
                                                    ||
| 1893 | 1971 | 'not_bcc' => 0,  | 
                                                        
| 1894 | 1972 | )  | 
                                                        
| 1895 | 1973 | );  | 
                                                        
| 1896 | - while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        |
| 1897 | - $context['recipients']['to'][] = array(  | 
                                                        |
| 1974 | +			while ($row = $smcFunc['db_fetch_assoc']($request)) { | 
                                                        |
| 1975 | + $context['recipients']['to'][] = array(  | 
                                                        |
| 1898 | 1976 | 'id' => $row['id_member'],  | 
                                                        
| 1899 | 1977 | 'name' => $row['real_name'],  | 
                                                        
| 1900 | 1978 | );  | 
                                                        
| 1979 | + }  | 
                                                        |
| 1901 | 1980 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1902 | - }  | 
                                                        |
| 1903 | - else  | 
                                                        |
| 1981 | + } else  | 
                                                        |
| 1904 | 1982 |  		{ | 
                                                        
| 1905 | 1983 |  			$_REQUEST['u'] = explode(',', $_REQUEST['u']); | 
                                                        
| 1906 | - foreach ($_REQUEST['u'] as $key => $uID)  | 
                                                        |
| 1907 | - $_REQUEST['u'][$key] = (int) $uID;  | 
                                                        |
| 1984 | +			foreach ($_REQUEST['u'] as $key => $uID) { | 
                                                        |
| 1985 | + $_REQUEST['u'][$key] = (int) $uID;  | 
                                                        |
| 1986 | + }  | 
                                                        |
| 1908 | 1987 | |
| 1909 | 1988 | $_REQUEST['u'] = array_unique($_REQUEST['u']);  | 
                                                        
| 1910 | 1989 | |
@@ -1918,22 +1997,24 @@ discard block  | 
                                                    ||
| 1918 | 1997 | 'limit' => count($_REQUEST['u']),  | 
                                                        
| 1919 | 1998 | )  | 
                                                        
| 1920 | 1999 | );  | 
                                                        
| 1921 | - while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        |
| 1922 | - $context['recipients']['to'][] = array(  | 
                                                        |
| 2000 | +			while ($row = $smcFunc['db_fetch_assoc']($request)) { | 
                                                        |
| 2001 | + $context['recipients']['to'][] = array(  | 
                                                        |
| 1923 | 2002 | 'id' => $row['id_member'],  | 
                                                        
| 1924 | 2003 | 'name' => $row['real_name'],  | 
                                                        
| 1925 | 2004 | );  | 
                                                        
| 2005 | + }  | 
                                                        |
| 1926 | 2006 | $smcFunc['db_free_result']($request);  | 
                                                        
| 1927 | 2007 | }  | 
                                                        
| 1928 | 2008 | |
| 1929 | 2009 | // Get a literal name list in case the user has JavaScript disabled.  | 
                                                        
| 1930 | 2010 | $names = array();  | 
                                                        
| 1931 | - foreach ($context['recipients']['to'] as $to)  | 
                                                        |
| 1932 | - $names[] = $to['name'];  | 
                                                        |
| 2011 | +		foreach ($context['recipients']['to'] as $to) { | 
                                                        |
| 2012 | + $names[] = $to['name'];  | 
                                                        |
| 2013 | + }  | 
                                                        |
| 1933 | 2014 |  		$context['to_value'] = empty($names) ? '' : '"' . implode('", "', $names) . '"'; | 
                                                        
| 2015 | +	} else { | 
                                                        |
| 2016 | + $context['to_value'] = '';  | 
                                                        |
| 1934 | 2017 | }  | 
                                                        
| 1935 | - else  | 
                                                        |
| 1936 | - $context['to_value'] = '';  | 
                                                        |
| 1937 | 2018 | |
| 1938 | 2019 | // Set the defaults...  | 
                                                        
| 1939 | 2020 | $context['subject'] = $form_subject;  | 
                                                        
@@ -2003,8 +2084,9 @@ discard block  | 
                                                    ||
| 2003 | 2084 | |
| 2004 | 2085 | // validate with loadMemberData()  | 
                                                        
| 2005 | 2086 | $memberResult = loadMemberData($user_info['id'], false);  | 
                                                        
| 2006 | - if (!$memberResult)  | 
                                                        |
| 2007 | -		fatal_lang_error('not_a_user', false); | 
                                                        |
| 2087 | +	if (!$memberResult) { | 
                                                        |
| 2088 | +			fatal_lang_error('not_a_user', false); | 
                                                        |
| 2089 | + }  | 
                                                        |
| 2008 | 2090 | list ($memID) = $memberResult;  | 
                                                        
| 2009 | 2091 | |
| 2010 | 2092 | // drafts is where the functions reside  | 
                                                        
@@ -2030,9 +2112,9 @@ discard block  | 
                                                    ||
| 2030 | 2112 | $context['sub_template'] = 'send';  | 
                                                        
| 2031 | 2113 |  		loadJavaScriptFile('PersonalMessage.js', array('defer' => false, 'minimize' => true), 'smf_pms'); | 
                                                        
| 2032 | 2114 |  		loadJavaScriptFile('suggest.js', array('defer' => false, 'minimize' => true), 'smf_suggest'); | 
                                                        
| 2115 | +	} else { | 
                                                        |
| 2116 | + $context['sub_template'] = 'pm';  | 
                                                        |
| 2033 | 2117 | }  | 
                                                        
| 2034 | - else  | 
                                                        |
| 2035 | - $context['sub_template'] = 'pm';  | 
                                                        |
| 2036 | 2118 | |
| 2037 | 2119 | $context['page_title'] = $txt['send_message'];  | 
                                                        
| 2038 | 2120 | |
@@ -2093,10 +2175,11 @@ discard block  | 
                                                    ||
| 2093 | 2175 | );  | 
                                                        
| 2094 | 2176 | if ($smcFunc['db_num_rows']($request) == 0)  | 
                                                        
| 2095 | 2177 |  		{ | 
                                                        
| 2096 | - if (!isset($_REQUEST['xml']))  | 
                                                        |
| 2097 | -				fatal_lang_error('pm_not_yours', false); | 
                                                        |
| 2098 | - else  | 
                                                        |
| 2099 | - $error_types[] = 'pm_not_yours';  | 
                                                        |
| 2178 | +			if (!isset($_REQUEST['xml'])) { | 
                                                        |
| 2179 | +							fatal_lang_error('pm_not_yours', false); | 
                                                        |
| 2180 | +			} else { | 
                                                        |
| 2181 | + $error_types[] = 'pm_not_yours';  | 
                                                        |
| 2182 | + }  | 
                                                        |
| 2100 | 2183 | }  | 
                                                        
| 2101 | 2184 | $row_quoted = $smcFunc['db_fetch_assoc']($request);  | 
                                                        
| 2102 | 2185 | $smcFunc['db_free_result']($request);  | 
                                                        
@@ -2143,14 +2226,16 @@ discard block  | 
                                                    ||
| 2143 | 2226 | $context['post_error'][$error_type] = true;  | 
                                                        
| 2144 | 2227 | if (isset($txt['error_' . $error_type]))  | 
                                                        
| 2145 | 2228 |  		{ | 
                                                        
| 2146 | - if ($error_type == 'long_message')  | 
                                                        |
| 2147 | - $txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);  | 
                                                        |
| 2229 | +			if ($error_type == 'long_message') { | 
                                                        |
| 2230 | + $txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);  | 
                                                        |
| 2231 | + }  | 
                                                        |
| 2148 | 2232 | $context['post_error']['messages'][] = $txt['error_' . $error_type];  | 
                                                        
| 2149 | 2233 | }  | 
                                                        
| 2150 | 2234 | |
| 2151 | 2235 | // If it's not a minor error flag it as such.  | 
                                                        
| 2152 | -		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'))) | 
                                                        |
| 2153 | - $context['error_type'] = 'serious';  | 
                                                        |
| 2236 | +		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'))) { | 
                                                        |
| 2237 | + $context['error_type'] = 'serious';  | 
                                                        |
| 2238 | + }  | 
                                                        |
| 2154 | 2239 | }  | 
                                                        
| 2155 | 2240 | |
| 2156 | 2241 | // We need to load the editor once more.  | 
                                                        
@@ -2208,8 +2293,9 @@ discard block  | 
                                                    ||
| 2208 | 2293 | require_once($sourcedir . '/Subs-Auth.php');  | 
                                                        
| 2209 | 2294 | |
| 2210 | 2295 | // PM Drafts enabled and needed?  | 
                                                        
| 2211 | - if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft'])))  | 
                                                        |
| 2212 | - require_once($sourcedir . '/Drafts.php');  | 
                                                        |
| 2296 | +	if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft']))) { | 
                                                        |
| 2297 | + require_once($sourcedir . '/Drafts.php');  | 
                                                        |
| 2298 | + }  | 
                                                        |
| 2213 | 2299 | |
| 2214 | 2300 |  	loadLanguage('PersonalMessage', '', false); | 
                                                        
| 2215 | 2301 | |
@@ -2239,24 +2325,27 @@ discard block  | 
                                                    ||
| 2239 | 2325 | |
| 2240 | 2326 | if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])  | 
                                                        
| 2241 | 2327 |  		{ | 
                                                        
| 2242 | - if (!isset($_REQUEST['xml']))  | 
                                                        |
| 2243 | -				fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); | 
                                                        |
| 2244 | - else  | 
                                                        |
| 2245 | - $post_errors[] = 'pm_too_many_per_hour';  | 
                                                        |
| 2328 | +			if (!isset($_REQUEST['xml'])) { | 
                                                        |
| 2329 | +							fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); | 
                                                        |
| 2330 | +			} else { | 
                                                        |
| 2331 | + $post_errors[] = 'pm_too_many_per_hour';  | 
                                                        |
| 2332 | + }  | 
                                                        |
| 2246 | 2333 | }  | 
                                                        
| 2247 | 2334 | }  | 
                                                        
| 2248 | 2335 | |
| 2249 | 2336 | // If your session timed out, show an error, but do allow to re-submit.  | 
                                                        
| 2250 | -	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '') | 
                                                        |
| 2251 | - $post_errors[] = 'session_timeout';  | 
                                                        |
| 2337 | +	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '') { | 
                                                        |
| 2338 | + $post_errors[] = 'session_timeout';  | 
                                                        |
| 2339 | + }  | 
                                                        |
| 2252 | 2340 | |
| 2253 | 2341 | $_REQUEST['subject'] = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : '';  | 
                                                        
| 2254 | 2342 | $_REQUEST['to'] = empty($_POST['to']) ? (empty($_GET['to']) ? '' : $_GET['to']) : $_POST['to'];  | 
                                                        
| 2255 | 2343 | $_REQUEST['bcc'] = empty($_POST['bcc']) ? (empty($_GET['bcc']) ? '' : $_GET['bcc']) : $_POST['bcc'];  | 
                                                        
| 2256 | 2344 | |
| 2257 | 2345 | // Route the input from the 'u' parameter to the 'to'-list.  | 
                                                        
| 2258 | - if (!empty($_POST['u']))  | 
                                                        |
| 2259 | -		$_POST['recipient_to'] = explode(',', $_POST['u']); | 
                                                        |
| 2346 | +	if (!empty($_POST['u'])) { | 
                                                        |
| 2347 | +			$_POST['recipient_to'] = explode(',', $_POST['u']); | 
                                                        |
| 2348 | + }  | 
                                                        |
| 2260 | 2349 | |
| 2261 | 2350 | // Construct the list of recipients.  | 
                                                        
| 2262 | 2351 | $recipientList = array();  | 
                                                        
@@ -2268,8 +2357,9 @@ discard block  | 
                                                    ||
| 2268 | 2357 | $recipientList[$recipientType] = array();  | 
                                                        
| 2269 | 2358 | if (!empty($_POST['recipient_' . $recipientType]) && is_array($_POST['recipient_' . $recipientType]))  | 
                                                        
| 2270 | 2359 |  		{ | 
                                                        
| 2271 | - foreach ($_POST['recipient_' . $recipientType] as $recipient)  | 
                                                        |
| 2272 | - $recipientList[$recipientType][] = (int) $recipient;  | 
                                                        |
| 2360 | +			foreach ($_POST['recipient_' . $recipientType] as $recipient) { | 
                                                        |
| 2361 | + $recipientList[$recipientType][] = (int) $recipient;  | 
                                                        |
| 2362 | + }  | 
                                                        |
| 2273 | 2363 | }  | 
                                                        
| 2274 | 2364 | |
| 2275 | 2365 | // Are there also literal names set?  | 
                                                        
@@ -2283,10 +2373,11 @@ discard block  | 
                                                    ||
| 2283 | 2373 | |
| 2284 | 2374 | foreach ($namedRecipientList[$recipientType] as $index => $recipient)  | 
                                                        
| 2285 | 2375 |  			{ | 
                                                        
| 2286 | - if (strlen(trim($recipient)) > 0)  | 
                                                        |
| 2287 | - $namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));  | 
                                                        |
| 2288 | - else  | 
                                                        |
| 2289 | - unset($namedRecipientList[$recipientType][$index]);  | 
                                                        |
| 2376 | +				if (strlen(trim($recipient)) > 0) { | 
                                                        |
| 2377 | + $namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));  | 
                                                        |
| 2378 | +				} else { | 
                                                        |
| 2379 | + unset($namedRecipientList[$recipientType][$index]);  | 
                                                        |
| 2380 | + }  | 
                                                        |
| 2290 | 2381 | }  | 
                                                        
| 2291 | 2382 | |
| 2292 | 2383 | if (!empty($namedRecipientList[$recipientType]))  | 
                                                        
@@ -2316,8 +2407,9 @@ discard block  | 
                                                    ||
| 2316 | 2407 | }  | 
                                                        
| 2317 | 2408 | |
| 2318 | 2409 | // Selected a recipient to be deleted? Remove them now.  | 
                                                        
| 2319 | - if (!empty($_POST['delete_recipient']))  | 
                                                        |
| 2320 | - $recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));  | 
                                                        |
| 2410 | +		if (!empty($_POST['delete_recipient'])) { | 
                                                        |
| 2411 | + $recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));  | 
                                                        |
| 2412 | + }  | 
                                                        |
| 2321 | 2413 | |
| 2322 | 2414 | // Make sure we don't include the same name twice  | 
                                                        
| 2323 | 2415 | $recipientList[$recipientType] = array_unique($recipientList[$recipientType]);  | 
                                                        
@@ -2327,8 +2419,9 @@ discard block  | 
                                                    ||
| 2327 | 2419 | $is_recipient_change = !empty($_POST['delete_recipient']) || !empty($_POST['to_submit']) || !empty($_POST['bcc_submit']);  | 
                                                        
| 2328 | 2420 | |
| 2329 | 2421 | // Check if there's at least one recipient.  | 
                                                        
| 2330 | - if (empty($recipientList['to']) && empty($recipientList['bcc']))  | 
                                                        |
| 2331 | - $post_errors[] = 'no_to';  | 
                                                        |
| 2422 | +	if (empty($recipientList['to']) && empty($recipientList['bcc'])) { | 
                                                        |
| 2423 | + $post_errors[] = 'no_to';  | 
                                                        |
| 2424 | + }  | 
                                                        |
| 2332 | 2425 | |
| 2333 | 2426 | // Make sure that we remove the members who did get it from the screen.  | 
                                                        
| 2334 | 2427 | if (!$is_recipient_change)  | 
                                                        
@@ -2342,28 +2435,31 @@ discard block  | 
                                                    ||
| 2342 | 2435 | // Since we already have a post error, remove the previous one.  | 
                                                        
| 2343 | 2436 |  				$post_errors = array_diff($post_errors, array('no_to')); | 
                                                        
| 2344 | 2437 | |
| 2345 | - foreach ($namesNotFound[$recipientType] as $name)  | 
                                                        |
| 2346 | - $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);  | 
                                                        |
| 2438 | +				foreach ($namesNotFound[$recipientType] as $name) { | 
                                                        |
| 2439 | + $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);  | 
                                                        |
| 2440 | + }  | 
                                                        |
| 2347 | 2441 | }  | 
                                                        
| 2348 | 2442 | }  | 
                                                        
| 2349 | 2443 | }  | 
                                                        
| 2350 | 2444 | |
| 2351 | 2445 | // Did they make any mistakes?  | 
                                                        
| 2352 | - if ($_REQUEST['subject'] == '')  | 
                                                        |
| 2353 | - $post_errors[] = 'no_subject';  | 
                                                        |
| 2354 | - if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '')  | 
                                                        |
| 2355 | - $post_errors[] = 'no_message';  | 
                                                        |
| 2356 | - elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength'])  | 
                                                        |
| 2357 | - $post_errors[] = 'long_message';  | 
                                                        |
| 2358 | - else  | 
                                                        |
| 2446 | +	if ($_REQUEST['subject'] == '') { | 
                                                        |
| 2447 | + $post_errors[] = 'no_subject';  | 
                                                        |
| 2448 | + }  | 
                                                        |
| 2449 | +	if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') { | 
                                                        |
| 2450 | + $post_errors[] = 'no_message';  | 
                                                        |
| 2451 | +	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength']) { | 
                                                        |
| 2452 | + $post_errors[] = 'long_message';  | 
                                                        |
| 2453 | + } else  | 
                                                        |
| 2359 | 2454 |  	{ | 
                                                        
| 2360 | 2455 | // Preparse the message.  | 
                                                        
| 2361 | 2456 | $message = $_REQUEST['message'];  | 
                                                        
| 2362 | 2457 | preparsecode($message);  | 
                                                        
| 2363 | 2458 | |
| 2364 | 2459 | // Make sure there's still some content left without the tags.  | 
                                                        
| 2365 | -		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false)) | 
                                                        |
| 2366 | - $post_errors[] = 'no_message';  | 
                                                        |
| 2460 | +		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false)) { | 
                                                        |
| 2461 | + $post_errors[] = 'no_message';  | 
                                                        |
| 2462 | + }  | 
                                                        |
| 2367 | 2463 | }  | 
                                                        
| 2368 | 2464 | |
| 2369 | 2465 | // Wrong verification code?  | 
                                                        
@@ -2375,13 +2471,15 @@ discard block  | 
                                                    ||
| 2375 | 2471 | );  | 
                                                        
| 2376 | 2472 | $context['require_verification'] = create_control_verification($verificationOptions, true);  | 
                                                        
| 2377 | 2473 | |
| 2378 | - if (is_array($context['require_verification']))  | 
                                                        |
| 2379 | - $post_errors = array_merge($post_errors, $context['require_verification']);  | 
                                                        |
| 2474 | +		if (is_array($context['require_verification'])) { | 
                                                        |
| 2475 | + $post_errors = array_merge($post_errors, $context['require_verification']);  | 
                                                        |
| 2476 | + }  | 
                                                        |
| 2380 | 2477 | }  | 
                                                        
| 2381 | 2478 | |
| 2382 | 2479 | // If they did, give a chance to make ammends.  | 
                                                        
| 2383 | - if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml']))  | 
                                                        |
| 2384 | - return messagePostError($post_errors, $namedRecipientList, $recipientList);  | 
                                                        |
| 2480 | +	if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml'])) { | 
                                                        |
| 2481 | + return messagePostError($post_errors, $namedRecipientList, $recipientList);  | 
                                                        |
| 2482 | + }  | 
                                                        |
| 2385 | 2483 | |
| 2386 | 2484 | // Want to take a second glance before you send?  | 
                                                        
| 2387 | 2485 | if (isset($_REQUEST['preview']))  | 
                                                        
@@ -2412,8 +2510,9 @@ discard block  | 
                                                    ||
| 2412 | 2510 | foreach ($namesNotFound as $recipientType => $names)  | 
                                                        
| 2413 | 2511 |  		{ | 
                                                        
| 2414 | 2512 | $post_errors[] = 'bad_' . $recipientType;  | 
                                                        
| 2415 | - foreach ($names as $name)  | 
                                                        |
| 2416 | - $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);  | 
                                                        |
| 2513 | +			foreach ($names as $name) { | 
                                                        |
| 2514 | + $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);  | 
                                                        |
| 2515 | + }  | 
                                                        |
| 2417 | 2516 | }  | 
                                                        
| 2418 | 2517 | |
| 2419 | 2518 | return messagePostError(array(), $namedRecipientList, $recipientList);  | 
                                                        
@@ -2443,13 +2542,14 @@ discard block  | 
                                                    ||
| 2443 | 2542 |  	checkSubmitOnce('check'); | 
                                                        
| 2444 | 2543 | |
| 2445 | 2544 | // Do the actual sending of the PM.  | 
                                                        
| 2446 | - if (!empty($recipientList['to']) || !empty($recipientList['bcc']))  | 
                                                        |
| 2447 | - $context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);  | 
                                                        |
| 2448 | - else  | 
                                                        |
| 2449 | - $context['send_log'] = array(  | 
                                                        |
| 2545 | +	if (!empty($recipientList['to']) || !empty($recipientList['bcc'])) { | 
                                                        |
| 2546 | + $context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);  | 
                                                        |
| 2547 | +	} else { | 
                                                        |
| 2548 | + $context['send_log'] = array(  | 
                                                        |
| 2450 | 2549 | 'sent' => array(),  | 
                                                        
| 2451 | 2550 | 'failed' => array()  | 
                                                        
| 2452 | 2551 | );  | 
                                                        
| 2552 | + }  | 
                                                        |
| 2453 | 2553 | |
| 2454 | 2554 | // Mark the message as "replied to".  | 
                                                        
| 2455 | 2555 | if (!empty($context['send_log']['sent']) && !empty($_REQUEST['replied_to']) && isset($_REQUEST['f']) && $_REQUEST['f'] == 'inbox')  | 
                                                        
@@ -2467,11 +2567,12 @@ discard block  | 
                                                    ||
| 2467 | 2567 | }  | 
                                                        
| 2468 | 2568 | |
| 2469 | 2569 | // If one or more of the recipient were invalid, go back to the post screen with the failed usernames.  | 
                                                        
| 2470 | - if (!empty($context['send_log']['failed']))  | 
                                                        |
| 2471 | - return messagePostError($post_errors, $namesNotFound, array(  | 
                                                        |
| 2570 | +	if (!empty($context['send_log']['failed'])) { | 
                                                        |
| 2571 | + return messagePostError($post_errors, $namesNotFound, array(  | 
                                                        |
| 2472 | 2572 | 'to' => array_intersect($recipientList['to'], $context['send_log']['failed']),  | 
                                                        
| 2473 | 2573 | 'bcc' => array_intersect($recipientList['bcc'], $context['send_log']['failed'])  | 
                                                        
| 2474 | 2574 | ));  | 
                                                        
| 2575 | + }  | 
                                                        |
| 2475 | 2576 | |
| 2476 | 2577 | // Message sent successfully?  | 
                                                        
| 2477 | 2578 | if (!empty($context['send_log']) && empty($context['send_log']['failed']))  | 
                                                        
@@ -2479,8 +2580,9 @@ discard block  | 
                                                    ||
| 2479 | 2580 | $context['current_label_redirect'] = $context['current_label_redirect'] . ';done=sent';  | 
                                                        
| 2480 | 2581 | |
| 2481 | 2582 | // If we had a PM draft for this one, then its time to remove it since it was just sent  | 
                                                        
| 2482 | - if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft']))  | 
                                                        |
| 2483 | - DeleteDraft($_POST['id_pm_draft']);  | 
                                                        |
| 2583 | +		if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft'])) { | 
                                                        |
| 2584 | + DeleteDraft($_POST['id_pm_draft']);  | 
                                                        |
| 2585 | + }  | 
                                                        |
| 2484 | 2586 | }  | 
                                                        
| 2485 | 2587 | |
| 2486 | 2588 | // Go back to the where they sent from, if possible...  | 
                                                        
@@ -2495,24 +2597,28 @@ discard block  | 
                                                    ||
| 2495 | 2597 | |
| 2496 | 2598 |  	checkSession('request'); | 
                                                        
| 2497 | 2599 | |
| 2498 | - if (isset($_REQUEST['del_selected']))  | 
                                                        |
| 2499 | - $_REQUEST['pm_action'] = 'delete';  | 
                                                        |
| 2600 | +	if (isset($_REQUEST['del_selected'])) { | 
                                                        |
| 2601 | + $_REQUEST['pm_action'] = 'delete';  | 
                                                        |
| 2602 | + }  | 
                                                        |
| 2500 | 2603 | |
| 2501 | 2604 | if (isset($_REQUEST['pm_action']) && $_REQUEST['pm_action'] != '' && !empty($_REQUEST['pms']) && is_array($_REQUEST['pms']))  | 
                                                        
| 2502 | 2605 |  	{ | 
                                                        
| 2503 | - foreach ($_REQUEST['pms'] as $pm)  | 
                                                        |
| 2504 | - $_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];  | 
                                                        |
| 2606 | +		foreach ($_REQUEST['pms'] as $pm) { | 
                                                        |
| 2607 | + $_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];  | 
                                                        |
| 2608 | + }  | 
                                                        |
| 2505 | 2609 | }  | 
                                                        
| 2506 | 2610 | |
| 2507 | - if (empty($_REQUEST['pm_actions']))  | 
                                                        |
| 2508 | - redirectexit($context['current_label_redirect']);  | 
                                                        |
| 2611 | +	if (empty($_REQUEST['pm_actions'])) { | 
                                                        |
| 2612 | + redirectexit($context['current_label_redirect']);  | 
                                                        |
| 2613 | + }  | 
                                                        |
| 2509 | 2614 | |
| 2510 | 2615 | // If we are in conversation, we may need to apply this to every message in the conversation.  | 
                                                        
| 2511 | 2616 | if ($context['display_mode'] == 2 && isset($_REQUEST['conversation']))  | 
                                                        
| 2512 | 2617 |  	{ | 
                                                        
| 2513 | 2618 | $id_pms = array();  | 
                                                        
| 2514 | - foreach ($_REQUEST['pm_actions'] as $pm => $dummy)  | 
                                                        |
| 2515 | - $id_pms[] = (int) $pm;  | 
                                                        |
| 2619 | +		foreach ($_REQUEST['pm_actions'] as $pm => $dummy) { | 
                                                        |
| 2620 | + $id_pms[] = (int) $pm;  | 
                                                        |
| 2621 | + }  | 
                                                        |
| 2516 | 2622 | |
| 2517 | 2623 |  		$request = $smcFunc['db_query']('', ' | 
                                                        
| 2518 | 2624 | SELECT id_pm_head, id_pm  | 
                                                        
@@ -2523,8 +2629,9 @@ discard block  | 
                                                    ||
| 2523 | 2629 | )  | 
                                                        
| 2524 | 2630 | );  | 
                                                        
| 2525 | 2631 | $pm_heads = array();  | 
                                                        
| 2526 | - while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        |
| 2527 | - $pm_heads[$row['id_pm_head']] = $row['id_pm'];  | 
                                                        |
| 2632 | +		while ($row = $smcFunc['db_fetch_assoc']($request)) { | 
                                                        |
| 2633 | + $pm_heads[$row['id_pm_head']] = $row['id_pm'];  | 
                                                        |
| 2634 | + }  | 
                                                        |
| 2528 | 2635 | $smcFunc['db_free_result']($request);  | 
                                                        
| 2529 | 2636 | |
| 2530 | 2637 |  		$request = $smcFunc['db_query']('', ' | 
                                                        
@@ -2538,8 +2645,9 @@ discard block  | 
                                                    ||
| 2538 | 2645 | // Copy the action from the single to PM to the others.  | 
                                                        
| 2539 | 2646 | while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        
| 2540 | 2647 |  		{ | 
                                                        
| 2541 | - if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]]))  | 
                                                        |
| 2542 | - $_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];  | 
                                                        |
| 2648 | +			if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]])) { | 
                                                        |
| 2649 | + $_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];  | 
                                                        |
| 2650 | + }  | 
                                                        |
| 2543 | 2651 | }  | 
                                                        
| 2544 | 2652 | $smcFunc['db_free_result']($request);  | 
                                                        
| 2545 | 2653 | }  | 
                                                        
@@ -2550,22 +2658,21 @@ discard block  | 
                                                    ||
| 2550 | 2658 | $labels = array();  | 
                                                        
| 2551 | 2659 | foreach ($_REQUEST['pm_actions'] as $pm => $action)  | 
                                                        
| 2552 | 2660 |  	{ | 
                                                        
| 2553 | - if ($action === 'delete')  | 
                                                        |
| 2554 | - $to_delete[] = (int) $pm;  | 
                                                        |
| 2555 | - else  | 
                                                        |
| 2661 | +		if ($action === 'delete') { | 
                                                        |
| 2662 | + $to_delete[] = (int) $pm;  | 
                                                        |
| 2663 | + } else  | 
                                                        |
| 2556 | 2664 |  		{ | 
                                                        
| 2557 | 2665 | if (substr($action, 0, 4) == 'add_')  | 
                                                        
| 2558 | 2666 |  			{ | 
                                                        
| 2559 | 2667 | $type = 'add';  | 
                                                        
| 2560 | 2668 | $action = substr($action, 4);  | 
                                                        
| 2561 | - }  | 
                                                        |
| 2562 | - elseif (substr($action, 0, 4) == 'rem_')  | 
                                                        |
| 2669 | + } elseif (substr($action, 0, 4) == 'rem_')  | 
                                                        |
| 2563 | 2670 |  			{ | 
                                                        
| 2564 | 2671 | $type = 'rem';  | 
                                                        
| 2565 | 2672 | $action = substr($action, 4);  | 
                                                        
| 2673 | +			} else { | 
                                                        |
| 2674 | + $type = 'unk';  | 
                                                        |
| 2566 | 2675 | }  | 
                                                        
| 2567 | - else  | 
                                                        |
| 2568 | - $type = 'unk';  | 
                                                        |
| 2569 | 2676 | |
| 2570 | 2677 | if ($action == '-1' || (int) $action > 0)  | 
                                                        
| 2571 | 2678 |  			{ | 
                                                        
@@ -2576,8 +2683,9 @@ discard block  | 
                                                    ||
| 2576 | 2683 | }  | 
                                                        
| 2577 | 2684 | |
| 2578 | 2685 | // Deleting, it looks like?  | 
                                                        
| 2579 | - if (!empty($to_delete))  | 
                                                        |
| 2580 | - deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);  | 
                                                        |
| 2686 | +	if (!empty($to_delete)) { | 
                                                        |
| 2687 | + deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);  | 
                                                        |
| 2688 | + }  | 
                                                        |
| 2581 | 2689 | |
| 2582 | 2690 | // Are we labeling anything?  | 
                                                        
| 2583 | 2691 | if (!empty($to_label) && $context['folder'] == 'inbox')  | 
                                                        
@@ -2643,8 +2751,7 @@ discard block  | 
                                                    ||
| 2643 | 2751 | }  | 
                                                        
| 2644 | 2752 | |
| 2645 | 2753 | $smcFunc['db_free_result']($request2);  | 
                                                        
| 2646 | - }  | 
                                                        |
| 2647 | - elseif ($type == 'rem')  | 
                                                        |
| 2754 | + } elseif ($type == 'rem')  | 
                                                        |
| 2648 | 2755 |  			{ | 
                                                        
| 2649 | 2756 | // If we're removing from the inbox, see if we have at least one other label.  | 
                                                        
| 2650 | 2757 | // This query is faster than the one above  | 
                                                        
@@ -2676,21 +2783,25 @@ discard block  | 
                                                    ||
| 2676 | 2783 | if ($to_label[$row['id_pm']] != '-1')  | 
                                                        
| 2677 | 2784 |  			{ | 
                                                        
| 2678 | 2785 | // If this label is in the list and we're not adding it, remove it  | 
                                                        
| 2679 | - if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add')  | 
                                                        |
| 2680 | - unset($labels[$to_label[$row['id_pm']]]);  | 
                                                        |
| 2681 | - else if ($type !== 'rem')  | 
                                                        |
| 2682 | - $labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];  | 
                                                        |
| 2786 | +				if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add') { | 
                                                        |
| 2787 | + unset($labels[$to_label[$row['id_pm']]]);  | 
                                                        |
| 2788 | +				} else if ($type !== 'rem') { | 
                                                        |
| 2789 | + $labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];  | 
                                                        |
| 2790 | + }  | 
                                                        |
| 2683 | 2791 | }  | 
                                                        
| 2684 | 2792 | |
| 2685 | 2793 | // Removing all labels or just removing the inbox label  | 
                                                        
| 2686 | - if ($type == 'rem' && empty($labels))  | 
                                                        |
| 2687 | - $in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);  | 
                                                        |
| 2794 | +			if ($type == 'rem' && empty($labels)) { | 
                                                        |
| 2795 | + $in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);  | 
                                                        |
| 2796 | + }  | 
                                                        |
| 2688 | 2797 | // Adding new labels, but removing inbox and applying new ones  | 
                                                        
| 2689 | - elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels))  | 
                                                        |
| 2690 | - $in_inbox = 0;  | 
                                                        |
| 2798 | +			elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels)) { | 
                                                        |
| 2799 | + $in_inbox = 0;  | 
                                                        |
| 2800 | + }  | 
                                                        |
| 2691 | 2801 | // Just adding it to the inbox  | 
                                                        
| 2692 | - else  | 
                                                        |
| 2693 | - $in_inbox = 1;  | 
                                                        |
| 2802 | +			else { | 
                                                        |
| 2803 | + $in_inbox = 1;  | 
                                                        |
| 2804 | + }  | 
                                                        |
| 2694 | 2805 | |
| 2695 | 2806 | // Are we adding it to or removing it from the inbox?  | 
                                                        
| 2696 | 2807 | if ($in_inbox != $row['in_inbox'])  | 
                                                        
@@ -2732,8 +2843,9 @@ discard block  | 
                                                    ||
| 2732 | 2843 | if (!empty($labels_to_apply))  | 
                                                        
| 2733 | 2844 |  			{ | 
                                                        
| 2734 | 2845 | $inserts = array();  | 
                                                        
| 2735 | - foreach ($labels_to_apply as $label)  | 
                                                        |
| 2736 | - $inserts[] = array($row['id_pm'], $label);  | 
                                                        |
| 2846 | +				foreach ($labels_to_apply as $label) { | 
                                                        |
| 2847 | + $inserts[] = array($row['id_pm'], $label);  | 
                                                        |
| 2848 | + }  | 
                                                        |
| 2737 | 2849 | |
| 2738 | 2850 |  				$smcFunc['db_insert']('', | 
                                                        
| 2739 | 2851 |  					'{db_prefix}pm_labeled_messages', | 
                                                        
@@ -2777,11 +2889,13 @@ discard block  | 
                                                    ||
| 2777 | 2889 |  	checkSession('get'); | 
                                                        
| 2778 | 2890 | |
| 2779 | 2891 | // If all then delete all messages the user has.  | 
                                                        
| 2780 | - if ($_REQUEST['f'] == 'all')  | 
                                                        |
| 2781 | - deleteMessages(null, null);  | 
                                                        |
| 2892 | +	if ($_REQUEST['f'] == 'all') { | 
                                                        |
| 2893 | + deleteMessages(null, null);  | 
                                                        |
| 2894 | + }  | 
                                                        |
| 2782 | 2895 | // Otherwise just the selected folder.  | 
                                                        
| 2783 | - else  | 
                                                        |
| 2784 | - deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');  | 
                                                        |
| 2896 | +	else { | 
                                                        |
| 2897 | + deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');  | 
                                                        |
| 2898 | + }  | 
                                                        |
| 2785 | 2899 | |
| 2786 | 2900 | // Done... all gone.  | 
                                                        
| 2787 | 2901 | redirectexit($context['current_label_redirect']);  | 
                                                        
@@ -2818,8 +2932,9 @@ discard block  | 
                                                    ||
| 2818 | 2932 | 'msgtime' => $deleteTime,  | 
                                                        
| 2819 | 2933 | )  | 
                                                        
| 2820 | 2934 | );  | 
                                                        
| 2821 | - while ($row = $smcFunc['db_fetch_row']($request))  | 
                                                        |
| 2822 | - $toDelete[] = $row[0];  | 
                                                        |
| 2935 | +		while ($row = $smcFunc['db_fetch_row']($request)) { | 
                                                        |
| 2936 | + $toDelete[] = $row[0];  | 
                                                        |
| 2937 | + }  | 
                                                        |
| 2823 | 2938 | $smcFunc['db_free_result']($request);  | 
                                                        
| 2824 | 2939 | |
| 2825 | 2940 | // Select all messages in their inbox older than $deleteTime.  | 
                                                        
@@ -2836,8 +2951,9 @@ discard block  | 
                                                    ||
| 2836 | 2951 | 'msgtime' => $deleteTime,  | 
                                                        
| 2837 | 2952 | )  | 
                                                        
| 2838 | 2953 | );  | 
                                                        
| 2839 | - while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        |
| 2840 | - $toDelete[] = $row['id_pm'];  | 
                                                        |
| 2954 | +		while ($row = $smcFunc['db_fetch_assoc']($request)) { | 
                                                        |
| 2955 | + $toDelete[] = $row['id_pm'];  | 
                                                        |
| 2956 | + }  | 
                                                        |
| 2841 | 2957 | $smcFunc['db_free_result']($request);  | 
                                                        
| 2842 | 2958 | |
| 2843 | 2959 | // Delete the actual messages.  | 
                                                        
@@ -2868,26 +2984,29 @@ discard block  | 
                                                    ||
| 2868 | 2984 |  { | 
                                                        
| 2869 | 2985 | global $user_info, $smcFunc;  | 
                                                        
| 2870 | 2986 | |
| 2871 | - if ($owner === null)  | 
                                                        |
| 2872 | - $owner = array($user_info['id']);  | 
                                                        |
| 2873 | - elseif (empty($owner))  | 
                                                        |
| 2874 | - return;  | 
                                                        |
| 2875 | - elseif (!is_array($owner))  | 
                                                        |
| 2876 | - $owner = array($owner);  | 
                                                        |
| 2987 | +	if ($owner === null) { | 
                                                        |
| 2988 | + $owner = array($user_info['id']);  | 
                                                        |
| 2989 | +	} elseif (empty($owner)) { | 
                                                        |
| 2990 | + return;  | 
                                                        |
| 2991 | +	} elseif (!is_array($owner)) { | 
                                                        |
| 2992 | + $owner = array($owner);  | 
                                                        |
| 2993 | + }  | 
                                                        |
| 2877 | 2994 | |
| 2878 | 2995 | if ($personal_messages !== null)  | 
                                                        
| 2879 | 2996 |  	{ | 
                                                        
| 2880 | - if (empty($personal_messages) || !is_array($personal_messages))  | 
                                                        |
| 2881 | - return;  | 
                                                        |
| 2997 | +		if (empty($personal_messages) || !is_array($personal_messages)) { | 
                                                        |
| 2998 | + return;  | 
                                                        |
| 2999 | + }  | 
                                                        |
| 2882 | 3000 | |
| 2883 | - foreach ($personal_messages as $index => $delete_id)  | 
                                                        |
| 2884 | - $personal_messages[$index] = (int) $delete_id;  | 
                                                        |
| 3001 | +		foreach ($personal_messages as $index => $delete_id) { | 
                                                        |
| 3002 | + $personal_messages[$index] = (int) $delete_id;  | 
                                                        |
| 3003 | + }  | 
                                                        |
| 2885 | 3004 | |
| 2886 | 3005 | $where = '  | 
                                                        
| 2887 | 3006 |  				AND id_pm IN ({array_int:pm_list})'; | 
                                                        
| 3007 | +	} else { | 
                                                        |
| 3008 | + $where = '';  | 
                                                        |
| 2888 | 3009 | }  | 
                                                        
| 2889 | - else  | 
                                                        |
| 2890 | - $where = '';  | 
                                                        |
| 2891 | 3010 | |
| 2892 | 3011 | if ($folder == 'sent' || $folder === null)  | 
                                                        
| 2893 | 3012 |  	{ | 
                                                        
@@ -2922,17 +3041,19 @@ discard block  | 
                                                    ||
| 2922 | 3041 | // ...And update the statistics accordingly - now including unread messages!.  | 
                                                        
| 2923 | 3042 | while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        
| 2924 | 3043 |  		{ | 
                                                        
| 2925 | - if ($row['is_read'])  | 
                                                        |
| 2926 | -				updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'])); | 
                                                        |
| 2927 | - else  | 
                                                        |
| 2928 | -				updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages'])); | 
                                                        |
| 3044 | +			if ($row['is_read']) { | 
                                                        |
| 3045 | +							updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'])); | 
                                                        |
| 3046 | +			} else { | 
                                                        |
| 3047 | +							updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages'])); | 
                                                        |
| 3048 | + }  | 
                                                        |
| 2929 | 3049 | |
| 2930 | 3050 | // If this is the current member we need to make their message count correct.  | 
                                                        
| 2931 | 3051 | if ($user_info['id'] == $row['id_member'])  | 
                                                        
| 2932 | 3052 |  			{ | 
                                                        
| 2933 | 3053 | $user_info['messages'] -= $row['num_deleted_messages'];  | 
                                                        
| 2934 | - if (!($row['is_read']))  | 
                                                        |
| 2935 | - $user_info['unread_messages'] -= $row['num_deleted_messages'];  | 
                                                        |
| 3054 | +				if (!($row['is_read'])) { | 
                                                        |
| 3055 | + $user_info['unread_messages'] -= $row['num_deleted_messages'];  | 
                                                        |
| 3056 | + }  | 
                                                        |
| 2936 | 3057 | }  | 
                                                        
| 2937 | 3058 | }  | 
                                                        
| 2938 | 3059 | $smcFunc['db_free_result']($request);  | 
                                                        
@@ -3000,8 +3121,9 @@ discard block  | 
                                                    ||
| 3000 | 3121 | )  | 
                                                        
| 3001 | 3122 | );  | 
                                                        
| 3002 | 3123 | $remove_pms = array();  | 
                                                        
| 3003 | - while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        |
| 3004 | - $remove_pms[] = $row['sender'];  | 
                                                        |
| 3124 | +	while ($row = $smcFunc['db_fetch_assoc']($request)) { | 
                                                        |
| 3125 | + $remove_pms[] = $row['sender'];  | 
                                                        |
| 3126 | + }  | 
                                                        |
| 3005 | 3127 | $smcFunc['db_free_result']($request);  | 
                                                        
| 3006 | 3128 | |
| 3007 | 3129 | if (!empty($remove_pms))  | 
                                                        
@@ -3046,8 +3168,9 @@ discard block  | 
                                                    ||
| 3046 | 3168 |  { | 
                                                        
| 3047 | 3169 | global $user_info, $context, $smcFunc;  | 
                                                        
| 3048 | 3170 | |
| 3049 | - if ($owner === null)  | 
                                                        |
| 3050 | - $owner = $user_info['id'];  | 
                                                        |
| 3171 | +	if ($owner === null) { | 
                                                        |
| 3172 | + $owner = $user_info['id'];  | 
                                                        |
| 3173 | + }  | 
                                                        |
| 3051 | 3174 | |
| 3052 | 3175 | $in_inbox = '';  | 
                                                        
| 3053 | 3176 | |
@@ -3071,8 +3194,7 @@ discard block  | 
                                                    ||
| 3071 | 3194 | }  | 
                                                        
| 3072 | 3195 | |
| 3073 | 3196 | $smcFunc['db_free_result']($get_messages);  | 
                                                        
| 3074 | - }  | 
                                                        |
| 3075 | - elseif ($label = '-1')  | 
                                                        |
| 3197 | + } elseif ($label = '-1')  | 
                                                        |
| 3076 | 3198 |  	{ | 
                                                        
| 3077 | 3199 | // Marking all PMs in your inbox read  | 
                                                        
| 3078 | 3200 | $in_inbox = '  | 
                                                        
@@ -3097,8 +3219,9 @@ discard block  | 
                                                    ||
| 3097 | 3219 |  	{ | 
                                                        
| 3098 | 3220 | if ($owner == $user_info['id'])  | 
                                                        
| 3099 | 3221 |  		{ | 
                                                        
| 3100 | - foreach ($context['labels'] as $label)  | 
                                                        |
| 3101 | - $context['labels'][(int) $label['id']]['unread_messages'] = 0;  | 
                                                        |
| 3222 | +			foreach ($context['labels'] as $label) { | 
                                                        |
| 3223 | + $context['labels'][(int) $label['id']]['unread_messages'] = 0;  | 
                                                        |
| 3224 | + }  | 
                                                        |
| 3102 | 3225 | }  | 
                                                        
| 3103 | 3226 | |
| 3104 | 3227 |  		$result = $smcFunc['db_query']('', ' | 
                                                        
@@ -3118,8 +3241,9 @@ discard block  | 
                                                    ||
| 3118 | 3241 |  		{ | 
                                                        
| 3119 | 3242 | $total_unread += $row['num'];  | 
                                                        
| 3120 | 3243 | |
| 3121 | - if ($owner != $user_info['id'] || empty($row['id_pm']))  | 
                                                        |
| 3122 | - continue;  | 
                                                        |
| 3244 | +			if ($owner != $user_info['id'] || empty($row['id_pm'])) { | 
                                                        |
| 3245 | + continue;  | 
                                                        |
| 3246 | + }  | 
                                                        |
| 3123 | 3247 | |
| 3124 | 3248 | $this_labels = array();  | 
                                                        
| 3125 | 3249 | |
@@ -3143,11 +3267,13 @@ discard block  | 
                                                    ||
| 3143 | 3267 | |
| 3144 | 3268 | $smcFunc['db_free_result']($result2);  | 
                                                        
| 3145 | 3269 | |
| 3146 | - foreach ($this_labels as $this_label)  | 
                                                        |
| 3147 | - $context['labels'][$this_label]['unread_messages'] += $row['num'];  | 
                                                        |
| 3270 | +			foreach ($this_labels as $this_label) { | 
                                                        |
| 3271 | + $context['labels'][$this_label]['unread_messages'] += $row['num'];  | 
                                                        |
| 3272 | + }  | 
                                                        |
| 3148 | 3273 | |
| 3149 | - if ($row['in_inbox'] == 1)  | 
                                                        |
| 3150 | - $context['labels'][-1]['unread_messages'] += $row['num'];  | 
                                                        |
| 3274 | +			if ($row['in_inbox'] == 1) { | 
                                                        |
| 3275 | + $context['labels'][-1]['unread_messages'] += $row['num'];  | 
                                                        |
| 3276 | + }  | 
                                                        |
| 3151 | 3277 | }  | 
                                                        
| 3152 | 3278 | $smcFunc['db_free_result']($result);  | 
                                                        
| 3153 | 3279 | |
@@ -3156,8 +3282,9 @@ discard block  | 
                                                    ||
| 3156 | 3282 |  		updateMemberData($owner, array('unread_messages' => $total_unread)); | 
                                                        
| 3157 | 3283 | |
| 3158 | 3284 | // If it was for the current member, reflect this in the $user_info array too.  | 
                                                        
| 3159 | - if ($owner == $user_info['id'])  | 
                                                        |
| 3160 | - $user_info['unread_messages'] = $total_unread;  | 
                                                        |
| 3285 | +		if ($owner == $user_info['id']) { | 
                                                        |
| 3286 | + $user_info['unread_messages'] = $total_unread;  | 
                                                        |
| 3287 | + }  | 
                                                        |
| 3161 | 3288 | }  | 
                                                        
| 3162 | 3289 | }  | 
                                                        
| 3163 | 3290 | |
@@ -3185,8 +3312,9 @@ discard block  | 
                                                    ||
| 3185 | 3312 | // Add all existing labels to the array to save, slashing them as necessary...  | 
                                                        
| 3186 | 3313 | foreach ($context['labels'] as $label)  | 
                                                        
| 3187 | 3314 |  	{ | 
                                                        
| 3188 | - if ($label['id'] != -1)  | 
                                                        |
| 3189 | - $the_labels[$label['id']] = $label['name'];  | 
                                                        |
| 3315 | +		if ($label['id'] != -1) { | 
                                                        |
| 3316 | + $the_labels[$label['id']] = $label['name'];  | 
                                                        |
| 3317 | + }  | 
                                                        |
| 3190 | 3318 | }  | 
                                                        
| 3191 | 3319 | |
| 3192 | 3320 | if (isset($_POST[$context['session_var']]))  | 
                                                        
@@ -3205,8 +3333,9 @@ discard block  | 
                                                    ||
| 3205 | 3333 |  		{ | 
                                                        
| 3206 | 3334 |  			$_POST['label'] = strtr($smcFunc['htmlspecialchars'](trim($_POST['label'])), array(',' => ',')); | 
                                                        
| 3207 | 3335 | |
| 3208 | - if ($smcFunc['strlen']($_POST['label']) > 30)  | 
                                                        |
| 3209 | - $_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);  | 
                                                        |
| 3336 | +			if ($smcFunc['strlen']($_POST['label']) > 30) { | 
                                                        |
| 3337 | + $_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);  | 
                                                        |
| 3338 | + }  | 
                                                        |
| 3210 | 3339 | if ($_POST['label'] != '')  | 
                                                        
| 3211 | 3340 |  			{ | 
                                                        
| 3212 | 3341 | $the_labels[] = $_POST['label'];  | 
                                                        
@@ -3227,23 +3356,24 @@ discard block  | 
                                                    ||
| 3227 | 3356 |  		{ | 
                                                        
| 3228 | 3357 | foreach ($the_labels as $id => $name)  | 
                                                        
| 3229 | 3358 |  			{ | 
                                                        
| 3230 | - if ($id == -1)  | 
                                                        |
| 3231 | - continue;  | 
                                                        |
| 3232 | - elseif (isset($_POST['label_name'][$id]))  | 
                                                        |
| 3359 | +				if ($id == -1) { | 
                                                        |
| 3360 | + continue;  | 
                                                        |
| 3361 | + } elseif (isset($_POST['label_name'][$id]))  | 
                                                        |
| 3233 | 3362 |  				{ | 
                                                        
| 3234 | 3363 |  					$_POST['label_name'][$id] = trim(strtr($smcFunc['htmlspecialchars']($_POST['label_name'][$id]), array(',' => ','))); | 
                                                        
| 3235 | 3364 | |
| 3236 | - if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30)  | 
                                                        |
| 3237 | - $_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);  | 
                                                        |
| 3365 | +					if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30) { | 
                                                        |
| 3366 | + $_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);  | 
                                                        |
| 3367 | + }  | 
                                                        |
| 3238 | 3368 | if ($_POST['label_name'][$id] != '')  | 
                                                        
| 3239 | 3369 |  					{ | 
                                                        
| 3240 | 3370 | // Changing the name of this label?  | 
                                                        
| 3241 | - if ($the_labels[$id] != $_POST['label_name'][$id])  | 
                                                        |
| 3242 | - $label_updates[$id] = $_POST['label_name'][$id];  | 
                                                        |
| 3371 | +						if ($the_labels[$id] != $_POST['label_name'][$id]) { | 
                                                        |
| 3372 | + $label_updates[$id] = $_POST['label_name'][$id];  | 
                                                        |
| 3373 | + }  | 
                                                        |
| 3243 | 3374 | |
| 3244 | 3375 | $the_labels[(int) $id] = $_POST['label_name'][$id];  | 
                                                        
| 3245 | - }  | 
                                                        |
| 3246 | - else  | 
                                                        |
| 3376 | + } else  | 
                                                        |
| 3247 | 3377 |  					{ | 
                                                        
| 3248 | 3378 | unset($the_labels[(int) $id]);  | 
                                                        
| 3249 | 3379 | $labels_to_remove[] = $id;  | 
                                                        
@@ -3257,8 +3387,9 @@ discard block  | 
                                                    ||
| 3257 | 3387 | if (!empty($labels_to_add))  | 
                                                        
| 3258 | 3388 |  		{ | 
                                                        
| 3259 | 3389 | $inserts = array();  | 
                                                        
| 3260 | - foreach ($labels_to_add AS $label)  | 
                                                        |
| 3261 | - $inserts[] = array($user_info['id'], $label);  | 
                                                        |
| 3390 | +			foreach ($labels_to_add AS $label) { | 
                                                        |
| 3391 | + $inserts[] = array($user_info['id'], $label);  | 
                                                        |
| 3392 | + }  | 
                                                        |
| 3262 | 3393 | |
| 3263 | 3394 |  			$smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array()); | 
                                                        
| 3264 | 3395 | }  | 
                                                        
@@ -3348,8 +3479,9 @@ discard block  | 
                                                    ||
| 3348 | 3479 | // Each action...  | 
                                                        
| 3349 | 3480 | foreach ($rule['actions'] as $k2 => $action)  | 
                                                        
| 3350 | 3481 |  				{ | 
                                                        
| 3351 | - if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove))  | 
                                                        |
| 3352 | - continue;  | 
                                                        |
| 3482 | +					if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove)) { | 
                                                        |
| 3483 | + continue;  | 
                                                        |
| 3484 | + }  | 
                                                        |
| 3353 | 3485 | |
| 3354 | 3486 | $rule_changes[] = $rule['id'];  | 
                                                        
| 3355 | 3487 | |
@@ -3364,8 +3496,8 @@ discard block  | 
                                                    ||
| 3364 | 3496 |  		{ | 
                                                        
| 3365 | 3497 | $rule_changes = array_unique($rule_changes);  | 
                                                        
| 3366 | 3498 | // Update/delete as appropriate.  | 
                                                        
| 3367 | - foreach ($rule_changes as $k => $id)  | 
                                                        |
| 3368 | - if (!empty($context['rules'][$id]['actions']))  | 
                                                        |
| 3499 | +			foreach ($rule_changes as $k => $id) { | 
                                                        |
| 3500 | + if (!empty($context['rules'][$id]['actions']))  | 
                                                        |
| 3369 | 3501 |  				{ | 
                                                        
| 3370 | 3502 |  					$smcFunc['db_query']('', ' | 
                                                        
| 3371 | 3503 |  						UPDATE {db_prefix}pm_rules | 
                                                        
@@ -3378,12 +3510,13 @@ discard block  | 
                                                    ||
| 3378 | 3510 | 'actions' => $smcFunc['json_encode']($context['rules'][$id]['actions']),  | 
                                                        
| 3379 | 3511 | )  | 
                                                        
| 3380 | 3512 | );  | 
                                                        
| 3513 | + }  | 
                                                        |
| 3381 | 3514 | unset($rule_changes[$k]);  | 
                                                        
| 3382 | 3515 | }  | 
                                                        
| 3383 | 3516 | |
| 3384 | 3517 | // Anything left here means it's lost all actions...  | 
                                                        
| 3385 | - if (!empty($rule_changes))  | 
                                                        |
| 3386 | -				$smcFunc['db_query']('', ' | 
                                                        |
| 3518 | +			if (!empty($rule_changes)) { | 
                                                        |
| 3519 | +							$smcFunc['db_query']('', ' | 
                                                        |
| 3387 | 3520 |  					DELETE FROM {db_prefix}pm_rules | 
                                                        
| 3388 | 3521 |  					WHERE id_rule IN ({array_int:rule_list}) | 
                                                        
| 3389 | 3522 |  							AND id_member = {int:current_member}', | 
                                                        
@@ -3392,6 +3525,7 @@ discard block  | 
                                                    ||
| 3392 | 3525 | 'rule_list' => $rule_changes,  | 
                                                        
| 3393 | 3526 | )  | 
                                                        
| 3394 | 3527 | );  | 
                                                        
| 3528 | + }  | 
                                                        |
| 3395 | 3529 | }  | 
                                                        
| 3396 | 3530 | |
| 3397 | 3531 | // Make sure we're not caching this!  | 
                                                        
@@ -3461,8 +3595,9 @@ discard block  | 
                                                    ||
| 3461 | 3595 | // Save the fields.  | 
                                                        
| 3462 | 3596 | saveProfileFields();  | 
                                                        
| 3463 | 3597 | |
| 3464 | - if (!empty($profile_vars))  | 
                                                        |
| 3465 | - updateMemberData($user_info['id'], $profile_vars);  | 
                                                        |
| 3598 | +		if (!empty($profile_vars)) { | 
                                                        |
| 3599 | + updateMemberData($user_info['id'], $profile_vars);  | 
                                                        |
| 3600 | + }  | 
                                                        |
| 3466 | 3601 | }  | 
                                                        
| 3467 | 3602 | |
| 3468 | 3603 | setupProfileContext(  | 
                                                        
@@ -3487,13 +3622,15 @@ discard block  | 
                                                    ||
| 3487 | 3622 | global $user_info, $language, $modSettings, $smcFunc;  | 
                                                        
| 3488 | 3623 | |
| 3489 | 3624 | // Check that this feature is even enabled!  | 
                                                        
| 3490 | - if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg']))  | 
                                                        |
| 3491 | -		fatal_lang_error('no_access', false); | 
                                                        |
| 3625 | +	if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg'])) { | 
                                                        |
| 3626 | +			fatal_lang_error('no_access', false); | 
                                                        |
| 3627 | + }  | 
                                                        |
| 3492 | 3628 | |
| 3493 | 3629 | $pmsg = (int) $_REQUEST['pmsg'];  | 
                                                        
| 3494 | 3630 | |
| 3495 | - if (!isAccessiblePM($pmsg, 'inbox'))  | 
                                                        |
| 3496 | -		fatal_lang_error('no_access', false); | 
                                                        |
| 3631 | +	if (!isAccessiblePM($pmsg, 'inbox')) { | 
                                                        |
| 3632 | +			fatal_lang_error('no_access', false); | 
                                                        |
| 3633 | + }  | 
                                                        |
| 3497 | 3634 | |
| 3498 | 3635 | $context['pm_id'] = $pmsg;  | 
                                                        
| 3499 | 3636 | $context['page_title'] = $txt['pm_report_title'];  | 
                                                        
@@ -3515,8 +3652,9 @@ discard block  | 
                                                    ||
| 3515 | 3652 | )  | 
                                                        
| 3516 | 3653 | );  | 
                                                        
| 3517 | 3654 | $context['admins'] = array();  | 
                                                        
| 3518 | - while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        |
| 3519 | - $context['admins'][$row['id_member']] = $row['real_name'];  | 
                                                        |
| 3655 | +		while ($row = $smcFunc['db_fetch_assoc']($request)) { | 
                                                        |
| 3656 | + $context['admins'][$row['id_member']] = $row['real_name'];  | 
                                                        |
| 3657 | + }  | 
                                                        |
| 3520 | 3658 | $smcFunc['db_free_result']($request);  | 
                                                        
| 3521 | 3659 | |
| 3522 | 3660 | // How many admins in total?  | 
                                                        
@@ -3545,8 +3683,9 @@ discard block  | 
                                                    ||
| 3545 | 3683 | )  | 
                                                        
| 3546 | 3684 | );  | 
                                                        
| 3547 | 3685 | // Can only be a hacker here!  | 
                                                        
| 3548 | - if ($smcFunc['db_num_rows']($request) == 0)  | 
                                                        |
| 3549 | -			fatal_lang_error('no_access', false); | 
                                                        |
| 3686 | +		if ($smcFunc['db_num_rows']($request) == 0) { | 
                                                        |
| 3687 | +					fatal_lang_error('no_access', false); | 
                                                        |
| 3688 | + }  | 
                                                        |
| 3550 | 3689 | list ($subject, $body, $time, $memberFromID, $memberFromName) = $smcFunc['db_fetch_row']($request);  | 
                                                        
| 3551 | 3690 | $smcFunc['db_free_result']($request);  | 
                                                        
| 3552 | 3691 | |
@@ -3570,15 +3709,17 @@ discard block  | 
                                                    ||
| 3570 | 3709 | while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        
| 3571 | 3710 |  		{ | 
                                                        
| 3572 | 3711 | // If it's hidden still don't reveal their names - privacy after all ;)  | 
                                                        
| 3573 | - if ($row['bcc'])  | 
                                                        |
| 3574 | - $hidden_recipients++;  | 
                                                        |
| 3575 | - else  | 
                                                        |
| 3576 | - $recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';  | 
                                                        |
| 3712 | +			if ($row['bcc']) { | 
                                                        |
| 3713 | + $hidden_recipients++;  | 
                                                        |
| 3714 | +			} else { | 
                                                        |
| 3715 | + $recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';  | 
                                                        |
| 3716 | + }  | 
                                                        |
| 3577 | 3717 | }  | 
                                                        
| 3578 | 3718 | $smcFunc['db_free_result']($request);  | 
                                                        
| 3579 | 3719 | |
| 3580 | - if ($hidden_recipients)  | 
                                                        |
| 3581 | - $recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);  | 
                                                        |
| 3720 | +		if ($hidden_recipients) { | 
                                                        |
| 3721 | + $recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);  | 
                                                        |
| 3722 | + }  | 
                                                        |
| 3582 | 3723 | |
| 3583 | 3724 | // Now let's get out and loop through the admins.  | 
                                                        
| 3584 | 3725 |  		$request = $smcFunc['db_query']('', ' | 
                                                        
@@ -3594,8 +3735,9 @@ discard block  | 
                                                    ||
| 3594 | 3735 | );  | 
                                                        
| 3595 | 3736 | |
| 3596 | 3737 | // Maybe we shouldn't advertise this?  | 
                                                        
| 3597 | - if ($smcFunc['db_num_rows']($request) == 0)  | 
                                                        |
| 3598 | -			fatal_lang_error('no_access', false); | 
                                                        |
| 3738 | +		if ($smcFunc['db_num_rows']($request) == 0) { | 
                                                        |
| 3739 | +					fatal_lang_error('no_access', false); | 
                                                        |
| 3740 | + }  | 
                                                        |
| 3599 | 3741 | |
| 3600 | 3742 | $memberFromName = un_htmlspecialchars($memberFromName);  | 
                                                        
| 3601 | 3743 | |
@@ -3614,8 +3756,9 @@ discard block  | 
                                                    ||
| 3614 | 3756 | // Make the body.  | 
                                                        
| 3615 | 3757 |  				$report_body = str_replace(array('{REPORTER}', '{SENDER}'), array(un_htmlspecialchars($user_info['name']), $memberFromName), $txt['pm_report_pm_user_sent']); | 
                                                        
| 3616 | 3758 | $report_body .= "\n" . '[b]' . $_POST['reason'] . '[/b]' . "\n\n";  | 
                                                        
| 3617 | - if (!empty($recipients))  | 
                                                        |
| 3618 | -					$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n"; | 
                                                        |
| 3759 | +				if (!empty($recipients)) { | 
                                                        |
| 3760 | +									$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n"; | 
                                                        |
| 3761 | + }  | 
                                                        |
| 3619 | 3762 | $report_body .= $txt['pm_report_pm_unedited_below'] . "\n" . '[quote author=' . (empty($memberFromID) ? '"' . $memberFromName . '"' : $memberFromName . ' link=action=profile;u=' . $memberFromID . ' date=' . $time) . ']' . "\n" . un_htmlspecialchars($body) . '[/quote]';  | 
                                                        
| 3620 | 3763 | |
| 3621 | 3764 | // Plonk it in the array ;)  | 
                                                        
@@ -3635,12 +3778,14 @@ discard block  | 
                                                    ||
| 3635 | 3778 | $smcFunc['db_free_result']($request);  | 
                                                        
| 3636 | 3779 | |
| 3637 | 3780 | // Send a different email for each language.  | 
                                                        
| 3638 | - foreach ($messagesToSend as $lang => $message)  | 
                                                        |
| 3639 | - sendpm($message['recipients'], $message['subject'], $message['body']);  | 
                                                        |
| 3781 | +		foreach ($messagesToSend as $lang => $message) { | 
                                                        |
| 3782 | + sendpm($message['recipients'], $message['subject'], $message['body']);  | 
                                                        |
| 3783 | + }  | 
                                                        |
| 3640 | 3784 | |
| 3641 | 3785 | // Give the user their own language back!  | 
                                                        
| 3642 | - if (!empty($modSettings['userLanguage']))  | 
                                                        |
| 3643 | -			loadLanguage('PersonalMessage', '', false); | 
                                                        |
| 3786 | +		if (!empty($modSettings['userLanguage'])) { | 
                                                        |
| 3787 | +					loadLanguage('PersonalMessage', '', false); | 
                                                        |
| 3788 | + }  | 
                                                        |
| 3644 | 3789 | |
| 3645 | 3790 | // Leave them with a template.  | 
                                                        
| 3646 | 3791 | $context['sub_template'] = 'report_message_complete';  | 
                                                        
@@ -3686,8 +3831,9 @@ discard block  | 
                                                    ||
| 3686 | 3831 | while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        
| 3687 | 3832 |  	{ | 
                                                        
| 3688 | 3833 | // Hide hidden groups!  | 
                                                        
| 3689 | -		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) | 
                                                        |
| 3690 | - continue;  | 
                                                        |
| 3834 | +		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) { | 
                                                        |
| 3835 | + continue;  | 
                                                        |
| 3836 | + }  | 
                                                        |
| 3691 | 3837 | |
| 3692 | 3838 | $context['groups'][$row['id_group']] = $row['group_name'];  | 
                                                        
| 3693 | 3839 | }  | 
                                                        
@@ -3713,9 +3859,10 @@ discard block  | 
                                                    ||
| 3713 | 3859 | $context['rule'] = $context['rules'][$context['rid']];  | 
                                                        
| 3714 | 3860 | $members = array();  | 
                                                        
| 3715 | 3861 | // Need to get member names!  | 
                                                        
| 3716 | - foreach ($context['rule']['criteria'] as $k => $criteria)  | 
                                                        |
| 3717 | - if ($criteria['t'] == 'mid' && !empty($criteria['v']))  | 
                                                        |
| 3862 | +			foreach ($context['rule']['criteria'] as $k => $criteria) { | 
                                                        |
| 3863 | + if ($criteria['t'] == 'mid' && !empty($criteria['v']))  | 
                                                        |
| 3718 | 3864 | $members[(int) $criteria['v']] = $k;  | 
                                                        
| 3865 | + }  | 
                                                        |
| 3719 | 3866 | |
| 3720 | 3867 | if (!empty($members))  | 
                                                        
| 3721 | 3868 |  			{ | 
                                                        
@@ -3727,19 +3874,20 @@ discard block  | 
                                                    ||
| 3727 | 3874 | 'member_list' => array_keys($members),  | 
                                                        
| 3728 | 3875 | )  | 
                                                        
| 3729 | 3876 | );  | 
                                                        
| 3730 | - while ($row = $smcFunc['db_fetch_assoc']($request))  | 
                                                        |
| 3731 | - $context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];  | 
                                                        |
| 3877 | +				while ($row = $smcFunc['db_fetch_assoc']($request)) { | 
                                                        |
| 3878 | + $context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];  | 
                                                        |
| 3879 | + }  | 
                                                        |
| 3732 | 3880 | $smcFunc['db_free_result']($request);  | 
                                                        
| 3733 | 3881 | }  | 
                                                        
| 3734 | - }  | 
                                                        |
| 3735 | - else  | 
                                                        |
| 3736 | - $context['rule'] = array(  | 
                                                        |
| 3882 | +		} else { | 
                                                        |
| 3883 | + $context['rule'] = array(  | 
                                                        |
| 3737 | 3884 | 'id' => '',  | 
                                                        
| 3738 | 3885 | 'name' => '',  | 
                                                        
| 3739 | 3886 | 'criteria' => array(),  | 
                                                        
| 3740 | 3887 | 'actions' => array(),  | 
                                                        
| 3741 | 3888 | 'logic' => 'and',  | 
                                                        
| 3742 | 3889 | );  | 
                                                        
| 3890 | + }  | 
                                                        |
| 3743 | 3891 | }  | 
                                                        
| 3744 | 3892 | // Saving?  | 
                                                        
| 3745 | 3893 | elseif (isset($_GET['save']))  | 
                                                        
@@ -3749,22 +3897,25 @@ discard block  | 
                                                    ||
| 3749 | 3897 | |
| 3750 | 3898 | // Name is easy!  | 
                                                        
| 3751 | 3899 | $ruleName = $smcFunc['htmlspecialchars'](trim($_POST['rule_name']));  | 
                                                        
| 3752 | - if (empty($ruleName))  | 
                                                        |
| 3753 | -			fatal_lang_error('pm_rule_no_name', false); | 
                                                        |
| 3900 | +		if (empty($ruleName)) { | 
                                                        |
| 3901 | +					fatal_lang_error('pm_rule_no_name', false); | 
                                                        |
| 3902 | + }  | 
                                                        |
| 3754 | 3903 | |
| 3755 | 3904 | // Sanity check...  | 
                                                        
| 3756 | - if (empty($_POST['ruletype']) || empty($_POST['acttype']))  | 
                                                        |
| 3757 | -			fatal_lang_error('pm_rule_no_criteria', false); | 
                                                        |
| 3905 | +		if (empty($_POST['ruletype']) || empty($_POST['acttype'])) { | 
                                                        |
| 3906 | +					fatal_lang_error('pm_rule_no_criteria', false); | 
                                                        |
| 3907 | + }  | 
                                                        |
| 3758 | 3908 | |
| 3759 | 3909 | // Let's do the criteria first - it's also hardest!  | 
                                                        
| 3760 | 3910 | $criteria = array();  | 
                                                        
| 3761 | 3911 | foreach ($_POST['ruletype'] as $ind => $type)  | 
                                                        
| 3762 | 3912 |  		{ | 
                                                        
| 3763 | 3913 | // Check everything is here...  | 
                                                        
| 3764 | - if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]])))  | 
                                                        |
| 3765 | - continue;  | 
                                                        |
| 3766 | - elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind]))  | 
                                                        |
| 3767 | - continue;  | 
                                                        |
| 3914 | +			if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]]))) { | 
                                                        |
| 3915 | + continue;  | 
                                                        |
| 3916 | +			} elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind])) { | 
                                                        |
| 3917 | + continue;  | 
                                                        |
| 3918 | + }  | 
                                                        |
| 3768 | 3919 | |
| 3769 | 3920 | // Members need to be found.  | 
                                                        
| 3770 | 3921 | if ($type == 'mid')  | 
                                                        
@@ -3788,13 +3939,13 @@ discard block  | 
                                                    ||
| 3788 | 3939 | $smcFunc['db_free_result']($request);  | 
                                                        
| 3789 | 3940 | |
| 3790 | 3941 |  				$criteria[] = array('t' => 'mid', 'v' => $memID); | 
                                                        
| 3942 | +			} elseif ($type == 'bud') { | 
                                                        |
| 3943 | +							$criteria[] = array('t' => 'bud', 'v' => 1); | 
                                                        |
| 3944 | +			} elseif ($type == 'gid') { | 
                                                        |
| 3945 | +							$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]); | 
                                                        |
| 3946 | +			} elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') { | 
                                                        |
| 3947 | +							$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind]))); | 
                                                        |
| 3791 | 3948 | }  | 
                                                        
| 3792 | - elseif ($type == 'bud')  | 
                                                        |
| 3793 | -				$criteria[] = array('t' => 'bud', 'v' => 1); | 
                                                        |
| 3794 | - elseif ($type == 'gid')  | 
                                                        |
| 3795 | -				$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]); | 
                                                        |
| 3796 | -			elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') | 
                                                        |
| 3797 | -				$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind]))); | 
                                                        |
| 3798 | 3949 | }  | 
                                                        
| 3799 | 3950 | |
| 3800 | 3951 | // Also do the actions!  | 
                                                        
@@ -3804,26 +3955,29 @@ discard block  | 
                                                    ||
| 3804 | 3955 | foreach ($_POST['acttype'] as $ind => $type)  | 
                                                        
| 3805 | 3956 |  		{ | 
                                                        
| 3806 | 3957 | // Picking a valid label?  | 
                                                        
| 3807 | - if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]])))  | 
                                                        |
| 3808 | - continue;  | 
                                                        |
| 3958 | +			if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]]))) { | 
                                                        |
| 3959 | + continue;  | 
                                                        |
| 3960 | + }  | 
                                                        |
| 3809 | 3961 | |
| 3810 | 3962 | // Record what we're doing.  | 
                                                        
| 3811 | - if ($type == 'del')  | 
                                                        |
| 3812 | - $doDelete = 1;  | 
                                                        |
| 3813 | - elseif ($type == 'lab')  | 
                                                        |
| 3814 | -				$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]); | 
                                                        |
| 3963 | +			if ($type == 'del') { | 
                                                        |
| 3964 | + $doDelete = 1;  | 
                                                        |
| 3965 | +			} elseif ($type == 'lab') { | 
                                                        |
| 3966 | +							$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]); | 
                                                        |
| 3967 | + }  | 
                                                        |
| 3815 | 3968 | }  | 
                                                        
| 3816 | 3969 | |
| 3817 | - if (empty($criteria) || (empty($actions) && !$doDelete))  | 
                                                        |
| 3818 | -			fatal_lang_error('pm_rule_no_criteria', false); | 
                                                        |
| 3970 | +		if (empty($criteria) || (empty($actions) && !$doDelete)) { | 
                                                        |
| 3971 | +					fatal_lang_error('pm_rule_no_criteria', false); | 
                                                        |
| 3972 | + }  | 
                                                        |
| 3819 | 3973 | |
| 3820 | 3974 | // What are we storing?  | 
                                                        
| 3821 | 3975 | $criteria = $smcFunc['json_encode']($criteria);  | 
                                                        
| 3822 | 3976 | $actions = $smcFunc['json_encode']($actions);  | 
                                                        
| 3823 | 3977 | |
| 3824 | 3978 | // Create the rule?  | 
                                                        
| 3825 | - if (empty($context['rid']))  | 
                                                        |
| 3826 | -			$smcFunc['db_insert']('', | 
                                                        |
| 3979 | +		if (empty($context['rid'])) { | 
                                                        |
| 3980 | +					$smcFunc['db_insert']('', | 
                                                        |
| 3827 | 3981 |  				'{db_prefix}pm_rules', | 
                                                        
| 3828 | 3982 | array(  | 
                                                        
| 3829 | 3983 | 'id_member' => 'int', 'rule_name' => 'string', 'criteria' => 'string', 'actions' => 'string',  | 
                                                        
@@ -3834,8 +3988,8 @@ discard block  | 
                                                    ||
| 3834 | 3988 | ),  | 
                                                        
| 3835 | 3989 |  				array('id_rule') | 
                                                        
| 3836 | 3990 | );  | 
                                                        
| 3837 | - else  | 
                                                        |
| 3838 | -			$smcFunc['db_query']('', ' | 
                                                        |
| 3991 | +		} else { | 
                                                        |
| 3992 | +					$smcFunc['db_query']('', ' | 
                                                        |
| 3839 | 3993 |  				UPDATE {db_prefix}pm_rules | 
                                                        
| 3840 | 3994 |  				SET rule_name = {string:rule_name}, criteria = {string:criteria}, actions = {string:actions}, | 
                                                        
| 3841 | 3995 |  					delete_pm = {int:delete_pm}, is_or = {int:is_or} | 
                                                        
@@ -3851,6 +4005,7 @@ discard block  | 
                                                    ||
| 3851 | 4005 | 'actions' => $actions,  | 
                                                        
| 3852 | 4006 | )  | 
                                                        
| 3853 | 4007 | );  | 
                                                        
| 4008 | + }  | 
                                                        |
| 3854 | 4009 | |
| 3855 | 4010 |  		redirectexit('action=pm;sa=manrules'); | 
                                                        
| 3856 | 4011 | }  | 
                                                        
@@ -3859,11 +4014,12 @@ discard block  | 
                                                    ||
| 3859 | 4014 |  	{ | 
                                                        
| 3860 | 4015 | checkSession();  | 
                                                        
| 3861 | 4016 | $toDelete = array();  | 
                                                        
| 3862 | - foreach ($_POST['delrule'] as $k => $v)  | 
                                                        |
| 3863 | - $toDelete[] = (int) $k;  | 
                                                        |
| 4017 | +		foreach ($_POST['delrule'] as $k => $v) { | 
                                                        |
| 4018 | + $toDelete[] = (int) $k;  | 
                                                        |
| 4019 | + }  | 
                                                        |
| 3864 | 4020 | |
| 3865 | - if (!empty($toDelete))  | 
                                                        |
| 3866 | -			$smcFunc['db_query']('', ' | 
                                                        |
| 4021 | +		if (!empty($toDelete)) { | 
                                                        |
| 4022 | +					$smcFunc['db_query']('', ' | 
                                                        |
| 3867 | 4023 |  				DELETE FROM {db_prefix}pm_rules | 
                                                        
| 3868 | 4024 |  				WHERE id_rule IN ({array_int:delete_list}) | 
                                                        
| 3869 | 4025 |  					AND id_member = {int:current_member}', | 
                                                        
@@ -3872,6 +4028,7 @@ discard block  | 
                                                    ||
| 3872 | 4028 | 'delete_list' => $toDelete,  | 
                                                        
| 3873 | 4029 | )  | 
                                                        
| 3874 | 4030 | );  | 
                                                        
| 4031 | + }  | 
                                                        |
| 3875 | 4032 | |
| 3876 | 4033 |  		redirectexit('action=pm;sa=manrules'); | 
                                                        
| 3877 | 4034 | }  | 
                                                        
@@ -3890,8 +4047,9 @@ discard block  | 
                                                    ||
| 3890 | 4047 | loadRules();  | 
                                                        
| 3891 | 4048 | |
| 3892 | 4049 | // No rules?  | 
                                                        
| 3893 | - if (empty($context['rules']))  | 
                                                        |
| 3894 | - return;  | 
                                                        |
| 4050 | +	if (empty($context['rules'])) { | 
                                                        |
| 4051 | + return;  | 
                                                        |
| 4052 | + }  | 
                                                        |
| 3895 | 4053 | |
| 3896 | 4054 | // Just unread ones?  | 
                                                        
| 3897 | 4055 | $ruleQuery = $all_messages ? '' : ' AND pmr.is_new = 1';  | 
                                                        
@@ -3921,8 +4079,9 @@ discard block  | 
                                                    ||
| 3921 | 4079 | // Loop through all the criteria hoping to make a match.  | 
                                                        
| 3922 | 4080 | foreach ($rule['criteria'] as $criterium)  | 
                                                        
| 3923 | 4081 |  			{ | 
                                                        
| 3924 | - if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false))  | 
                                                        |
| 3925 | - $match = true;  | 
                                                        |
| 4082 | +				if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false)) { | 
                                                        |
| 4083 | + $match = true;  | 
                                                        |
| 4084 | + }  | 
                                                        |
| 3926 | 4085 | // If we're adding and one criteria don't match then we stop!  | 
                                                        
| 3927 | 4086 | elseif ($rule['logic'] == 'and')  | 
                                                        
| 3928 | 4087 |  				{ | 
                                                        
@@ -3934,17 +4093,18 @@ discard block  | 
                                                    ||
| 3934 | 4093 | // If we have a match the rule must be true - act!  | 
                                                        
| 3935 | 4094 | if ($match)  | 
                                                        
| 3936 | 4095 |  			{ | 
                                                        
| 3937 | - if ($rule['delete'])  | 
                                                        |
| 3938 | - $actions['deletes'][] = $row['id_pm'];  | 
                                                        |
| 3939 | - else  | 
                                                        |
| 4096 | +				if ($rule['delete']) { | 
                                                        |
| 4097 | + $actions['deletes'][] = $row['id_pm'];  | 
                                                        |
| 4098 | + } else  | 
                                                        |
| 3940 | 4099 |  				{ | 
                                                        
| 3941 | 4100 | foreach ($rule['actions'] as $ruleAction)  | 
                                                        
| 3942 | 4101 |  					{ | 
                                                        
| 3943 | 4102 | if ($ruleAction['t'] == 'lab')  | 
                                                        
| 3944 | 4103 |  						{ | 
                                                        
| 3945 | 4104 | // Get a basic pot started!  | 
                                                        
| 3946 | - if (!isset($actions['labels'][$row['id_pm']]))  | 
                                                        |
| 3947 | - $actions['labels'][$row['id_pm']] = array();  | 
                                                        |
| 4105 | +							if (!isset($actions['labels'][$row['id_pm']])) { | 
                                                        |
| 4106 | + $actions['labels'][$row['id_pm']] = array();  | 
                                                        |
| 4107 | + }  | 
                                                        |
| 3948 | 4108 | $actions['labels'][$row['id_pm']][] = $ruleAction['v'];  | 
                                                        
| 3949 | 4109 | }  | 
                                                        
| 3950 | 4110 | }  | 
                                                        
@@ -3955,8 +4115,9 @@ discard block  | 
                                                    ||
| 3955 | 4115 | $smcFunc['db_free_result']($request);  | 
                                                        
| 3956 | 4116 | |
| 3957 | 4117 | // Deletes are easy!  | 
                                                        
| 3958 | - if (!empty($actions['deletes']))  | 
                                                        |
| 3959 | - deleteMessages($actions['deletes']);  | 
                                                        |
| 4118 | +	if (!empty($actions['deletes'])) { | 
                                                        |
| 4119 | + deleteMessages($actions['deletes']);  | 
                                                        |
| 4120 | + }  | 
                                                        |
| 3960 | 4121 | |
| 3961 | 4122 | // Relabel?  | 
                                                        
| 3962 | 4123 | if (!empty($actions['labels']))  | 
                                                        
@@ -3983,8 +4144,7 @@ discard block  | 
                                                    ||
| 3983 | 4144 | 'current_member' => $user_info['id'],  | 
                                                        
| 3984 | 4145 | )  | 
                                                        
| 3985 | 4146 | );  | 
                                                        
| 3986 | - }  | 
                                                        |
| 3987 | - else  | 
                                                        |
| 4147 | + } else  | 
                                                        |
| 3988 | 4148 |  					{ | 
                                                        
| 3989 | 4149 | $realLabels[] = $label['id'];  | 
                                                        
| 3990 | 4150 | }  | 
                                                        
@@ -3993,8 +4153,9 @@ discard block  | 
                                                    ||
| 3993 | 4153 | |
| 3994 | 4154 | $inserts = array();  | 
                                                        
| 3995 | 4155 | // Now we insert the label info  | 
                                                        
| 3996 | - foreach ($realLabels as $a_label)  | 
                                                        |
| 3997 | - $inserts[] = array($pm, $a_label);  | 
                                                        |
| 4156 | +			foreach ($realLabels as $a_label) { | 
                                                        |
| 4157 | + $inserts[] = array($pm, $a_label);  | 
                                                        |
| 4158 | + }  | 
                                                        |
| 3998 | 4159 | |
| 3999 | 4160 |  			$smcFunc['db_insert']('ignore', | 
                                                        
| 4000 | 4161 |  				'{db_prefix}pm_labeled_messages', | 
                                                        
@@ -4015,8 +4176,9 @@ discard block  | 
                                                    ||
| 4015 | 4176 |  { | 
                                                        
| 4016 | 4177 | global $user_info, $context, $smcFunc;  | 
                                                        
| 4017 | 4178 | |
| 4018 | - if (isset($context['rules']) && !$reload)  | 
                                                        |
| 4019 | - return;  | 
                                                        |
| 4179 | +	if (isset($context['rules']) && !$reload) { | 
                                                        |
| 4180 | + return;  | 
                                                        |
| 4181 | + }  | 
                                                        |
| 4020 | 4182 | |
| 4021 | 4183 |  	$request = $smcFunc['db_query']('', ' | 
                                                        
| 4022 | 4184 | SELECT  | 
                                                        
@@ -4040,8 +4202,9 @@ discard block  | 
                                                    ||
| 4040 | 4202 | 'logic' => $row['is_or'] ? 'or' : 'and',  | 
                                                        
| 4041 | 4203 | );  | 
                                                        
| 4042 | 4204 | |
| 4043 | - if ($row['delete_pm'])  | 
                                                        |
| 4044 | -			$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1); | 
                                                        |
| 4205 | +		if ($row['delete_pm']) { | 
                                                        |
| 4206 | +					$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1); | 
                                                        |
| 4207 | + }  | 
                                                        |
| 4045 | 4208 | }  | 
                                                        
| 4046 | 4209 | $smcFunc['db_free_result']($request);  | 
                                                        
| 4047 | 4210 | }  |