@@ -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 |
@@ -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 | } |
@@ -1129,7 +1129,7 @@ |
||
1129 | 1129 | '{db_prefix}log_subscribed', |
1130 | 1130 | array( |
1131 | 1131 | 'id_subscribe' => 'int', 'id_member' => 'int', 'old_id_group' => 'int', 'start_time' => 'int', |
1132 | - 'end_time' => 'int', 'status' => 'int','pending_details' => 'string-65534' |
|
1132 | + 'end_time' => 'int', 'status' => 'int', 'pending_details' => 'string-65534' |
|
1133 | 1133 | ), |
1134 | 1134 | array( |
1135 | 1135 | $context['sub_id'], $id_member, $id_group, $starttime, |
@@ -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 | } |
@@ -297,15 +300,16 @@ discard block |
||
297 | 300 | ); |
298 | 301 | |
299 | 302 | // Handle labels. |
300 | - if (empty($context['currently_using_labels'])) |
|
301 | - unset($pm_areas['labels']); |
|
302 | - else |
|
303 | + if (empty($context['currently_using_labels'])) { |
|
304 | + unset($pm_areas['labels']); |
|
305 | + } else |
|
303 | 306 | { |
304 | 307 | // Note we send labels by id as it will have less problems in the querystring. |
305 | 308 | foreach ($context['labels'] as $label) |
306 | 309 | { |
307 | - if ($label['id'] == -1) |
|
308 | - continue; |
|
310 | + if ($label['id'] == -1) { |
|
311 | + continue; |
|
312 | + } |
|
309 | 313 | |
310 | 314 | // Count the amount of unread items in labels. |
311 | 315 | $pm_areas['labels']['amt'] += $label['unread_messages']; |
@@ -356,8 +360,9 @@ discard block |
||
356 | 360 | unset($pm_areas); |
357 | 361 | |
358 | 362 | // No menu means no access. |
359 | - if (!$pm_include_data && (!$user_info['is_guest'] || validateSession())) |
|
360 | - fatal_lang_error('no_access', false); |
|
363 | + if (!$pm_include_data && (!$user_info['is_guest'] || validateSession())) { |
|
364 | + fatal_lang_error('no_access', false); |
|
365 | + } |
|
361 | 366 | |
362 | 367 | // Make a note of the Unique ID for this menu. |
363 | 368 | $context['pm_menu_id'] = $context['max_menu_id']; |
@@ -368,9 +373,10 @@ discard block |
||
368 | 373 | $context['menu_item_selected'] = $current_area; |
369 | 374 | |
370 | 375 | // Set the template for this area and add the profile layer. |
371 | - if (!isset($_REQUEST['xml'])) |
|
372 | - $context['template_layers'][] = 'pm'; |
|
373 | -} |
|
376 | + if (!isset($_REQUEST['xml'])) { |
|
377 | + $context['template_layers'][] = 'pm'; |
|
378 | + } |
|
379 | + } |
|
374 | 380 | |
375 | 381 | /** |
376 | 382 | * The popup for when we ask for the popup from the user. |
@@ -402,8 +408,9 @@ discard block |
||
402 | 408 | ) |
403 | 409 | ); |
404 | 410 | $pms = array(); |
405 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
406 | - $pms[] = $row[0]; |
|
411 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
412 | + $pms[] = $row[0]; |
|
413 | + } |
|
407 | 414 | $smcFunc['db_free_result']($request); |
408 | 415 | |
409 | 416 | if (!empty($pms)) |
@@ -431,8 +438,9 @@ discard block |
||
431 | 438 | ); |
432 | 439 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
433 | 440 | { |
434 | - if (!empty($row['id_member_from'])) |
|
435 | - $senders[] = $row['id_member_from']; |
|
441 | + if (!empty($row['id_member_from'])) { |
|
442 | + $senders[] = $row['id_member_from']; |
|
443 | + } |
|
436 | 444 | |
437 | 445 | $row['replied_to_you'] = $row['id_pm'] != $row['id_pm_head']; |
438 | 446 | $row['time'] = timeformat($row['timestamp']); |
@@ -442,13 +450,15 @@ discard block |
||
442 | 450 | $smcFunc['db_free_result']($request); |
443 | 451 | |
444 | 452 | $senders = loadMemberData($senders); |
445 | - foreach ($senders as $member) |
|
446 | - loadMemberContext($member); |
|
453 | + foreach ($senders as $member) { |
|
454 | + loadMemberContext($member); |
|
455 | + } |
|
447 | 456 | |
448 | 457 | // Having loaded everyone, attach them to the PMs. |
449 | - foreach ($context['unread_pms'] as $id_pm => $details) |
|
450 | - if (!empty($memberContext[$details['id_member_from']])) |
|
458 | + foreach ($context['unread_pms'] as $id_pm => $details) { |
|
459 | + if (!empty($memberContext[$details['id_member_from']])) |
|
451 | 460 | $context['unread_pms'][$id_pm]['member'] = &$memberContext[$details['id_member_from']]; |
461 | + } |
|
452 | 462 | } |
453 | 463 | } |
454 | 464 | |
@@ -468,12 +478,13 @@ discard block |
||
468 | 478 | } |
469 | 479 | |
470 | 480 | // Make sure the starting location is valid. |
471 | - if (isset($_GET['start']) && $_GET['start'] != 'new') |
|
472 | - $_GET['start'] = (int) $_GET['start']; |
|
473 | - elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first'])) |
|
474 | - $_GET['start'] = 0; |
|
475 | - else |
|
476 | - $_GET['start'] = 'new'; |
|
481 | + if (isset($_GET['start']) && $_GET['start'] != 'new') { |
|
482 | + $_GET['start'] = (int) $_GET['start']; |
|
483 | + } elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first'])) { |
|
484 | + $_GET['start'] = 0; |
|
485 | + } else { |
|
486 | + $_GET['start'] = 'new'; |
|
487 | + } |
|
477 | 488 | |
478 | 489 | // Set up some basic theme stuff. |
479 | 490 | $context['from_or_to'] = $context['folder'] != 'sent' ? 'from' : 'to'; |
@@ -487,9 +498,10 @@ discard block |
||
487 | 498 | list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']); |
488 | 499 | $sig_limits = explode(',', $sig_limits); |
489 | 500 | |
490 | - if (!empty($sig_limits[5]) || !empty($sig_limits[6])) |
|
491 | - addInlineCss(' |
|
501 | + if (!empty($sig_limits[5]) || !empty($sig_limits[6])) { |
|
502 | + addInlineCss(' |
|
492 | 503 | .signature img { ' . (!empty($sig_limits[5]) ? 'max-width: ' . (int) $sig_limits[5] . 'px; ' : '') . (!empty($sig_limits[6]) ? 'max-height: ' . (int) $sig_limits[6] . 'px; ' : '') . '}'); |
504 | + } |
|
493 | 505 | } |
494 | 506 | |
495 | 507 | $labelJoin = ''; |
@@ -501,8 +513,7 @@ discard block |
||
501 | 513 | { |
502 | 514 | $labelQuery = ' |
503 | 515 | AND pmr.in_inbox = 1'; |
504 | - } |
|
505 | - elseif ($context['folder'] != 'sent') |
|
516 | + } elseif ($context['folder'] != 'sent') |
|
506 | 517 | { |
507 | 518 | $labelJoin = ' |
508 | 519 | INNER JOIN {db_prefix}pm_labeled_messages AS pl ON (pl.id_pm = pmr.id_pm)'; |
@@ -544,22 +555,24 @@ discard block |
||
544 | 555 | $txt['delete_all'] = str_replace('PMBOX', $pmbox, $txt['delete_all']); |
545 | 556 | |
546 | 557 | // Now, build the link tree! |
547 | - if ($context['current_label_id'] == -1) |
|
548 | - $context['linktree'][] = array( |
|
558 | + if ($context['current_label_id'] == -1) { |
|
559 | + $context['linktree'][] = array( |
|
549 | 560 | 'url' => $scripturl . '?action=pm;f=' . $context['folder'], |
550 | 561 | 'name' => $pmbox |
551 | 562 | ); |
563 | + } |
|
552 | 564 | |
553 | 565 | // Build it further for a label. |
554 | - if ($context['current_label_id'] != -1) |
|
555 | - $context['linktree'][] = array( |
|
566 | + if ($context['current_label_id'] != -1) { |
|
567 | + $context['linktree'][] = array( |
|
556 | 568 | 'url' => $scripturl . '?action=pm;f=' . $context['folder'] . ';l=' . $context['current_label_id'], |
557 | 569 | 'name' => $txt['pm_current_label'] . ': ' . $context['current_label'] |
558 | 570 | ); |
571 | + } |
|
559 | 572 | |
560 | 573 | // Figure out how many messages there are. |
561 | - if ($context['folder'] == 'sent') |
|
562 | - $request = $smcFunc['db_query']('', ' |
|
574 | + if ($context['folder'] == 'sent') { |
|
575 | + $request = $smcFunc['db_query']('', ' |
|
563 | 576 | SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') |
564 | 577 | FROM {db_prefix}personal_messages AS pm |
565 | 578 | WHERE pm.id_member_from = {int:current_member} |
@@ -569,8 +582,8 @@ discard block |
||
569 | 582 | 'not_deleted' => 0, |
570 | 583 | ) |
571 | 584 | ); |
572 | - else |
|
573 | - $request = $smcFunc['db_query']('', ' |
|
585 | + } else { |
|
586 | + $request = $smcFunc['db_query']('', ' |
|
574 | 587 | SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') |
575 | 588 | FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? ' |
576 | 589 | INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . ' |
@@ -581,6 +594,7 @@ discard block |
||
581 | 594 | 'not_deleted' => 0, |
582 | 595 | ) |
583 | 596 | ); |
597 | + } |
|
584 | 598 | list ($max_messages) = $smcFunc['db_fetch_row']($request); |
585 | 599 | $smcFunc['db_free_result']($request); |
586 | 600 | |
@@ -589,10 +603,11 @@ discard block |
||
589 | 603 | $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
590 | 604 | |
591 | 605 | // Start on the last page. |
592 | - if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages) |
|
593 | - $_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage); |
|
594 | - elseif ($_GET['start'] < 0) |
|
595 | - $_GET['start'] = 0; |
|
606 | + if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages) { |
|
607 | + $_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage); |
|
608 | + } elseif ($_GET['start'] < 0) { |
|
609 | + $_GET['start'] = 0; |
|
610 | + } |
|
596 | 611 | |
597 | 612 | // ... but wait - what if we want to start from a specific message? |
598 | 613 | if (isset($_GET['pmid'])) |
@@ -600,19 +615,21 @@ discard block |
||
600 | 615 | $pmID = (int) $_GET['pmid']; |
601 | 616 | |
602 | 617 | // Make sure you have access to this PM. |
603 | - if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) |
|
604 | - fatal_lang_error('no_access', false); |
|
618 | + if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) { |
|
619 | + fatal_lang_error('no_access', false); |
|
620 | + } |
|
605 | 621 | |
606 | 622 | $context['current_pm'] = $pmID; |
607 | 623 | |
608 | 624 | // With only one page of PM's we're gonna want page 1. |
609 | - if ($max_messages <= $maxPerPage) |
|
610 | - $_GET['start'] = 0; |
|
625 | + if ($max_messages <= $maxPerPage) { |
|
626 | + $_GET['start'] = 0; |
|
627 | + } |
|
611 | 628 | // If we pass kstart we assume we're in the right place. |
612 | 629 | elseif (!isset($_GET['kstart'])) |
613 | 630 | { |
614 | - if ($context['folder'] == 'sent') |
|
615 | - $request = $smcFunc['db_query']('', ' |
|
631 | + if ($context['folder'] == 'sent') { |
|
632 | + $request = $smcFunc['db_query']('', ' |
|
616 | 633 | SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') |
617 | 634 | FROM {db_prefix}personal_messages |
618 | 635 | WHERE id_member_from = {int:current_member} |
@@ -624,8 +641,8 @@ discard block |
||
624 | 641 | 'id_pm' => $pmID, |
625 | 642 | ) |
626 | 643 | ); |
627 | - else |
|
628 | - $request = $smcFunc['db_query']('', ' |
|
644 | + } else { |
|
645 | + $request = $smcFunc['db_query']('', ' |
|
629 | 646 | SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') |
630 | 647 | FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? ' |
631 | 648 | INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . ' |
@@ -638,6 +655,7 @@ discard block |
||
638 | 655 | 'id_pm' => $pmID, |
639 | 656 | ) |
640 | 657 | ); |
658 | + } |
|
641 | 659 | |
642 | 660 | list ($_GET['start']) = $smcFunc['db_fetch_row']($request); |
643 | 661 | $smcFunc['db_free_result']($request); |
@@ -652,8 +670,9 @@ discard block |
||
652 | 670 | { |
653 | 671 | $pmsg = (int) $_GET['pmsg']; |
654 | 672 | |
655 | - if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) |
|
656 | - fatal_lang_error('no_access', false); |
|
673 | + if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) { |
|
674 | + fatal_lang_error('no_access', false); |
|
675 | + } |
|
657 | 676 | } |
658 | 677 | |
659 | 678 | // Set up the page index. |
@@ -747,8 +766,9 @@ discard block |
||
747 | 766 | { |
748 | 767 | if (!isset($recipients[$row['id_pm']])) |
749 | 768 | { |
750 | - if (isset($row['id_member_from'])) |
|
751 | - $posters[$row['id_pm']] = $row['id_member_from']; |
|
769 | + if (isset($row['id_member_from'])) { |
|
770 | + $posters[$row['id_pm']] = $row['id_member_from']; |
|
771 | + } |
|
752 | 772 | $pms[$row['id_pm']] = $row['id_pm']; |
753 | 773 | $recipients[$row['id_pm']] = array( |
754 | 774 | 'to' => array(), |
@@ -757,29 +777,33 @@ discard block |
||
757 | 777 | } |
758 | 778 | |
759 | 779 | // Keep track of the last message so we know what the head is without another query! |
760 | - if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm'])) |
|
761 | - $lastData = array( |
|
780 | + if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm'])) { |
|
781 | + $lastData = array( |
|
762 | 782 | 'id' => $row['id_pm'], |
763 | 783 | 'head' => $row['id_pm_head'], |
764 | 784 | ); |
785 | + } |
|
765 | 786 | } |
766 | 787 | $smcFunc['db_free_result']($request); |
767 | 788 | |
768 | 789 | // Make sure that we have been given a correct head pm id! |
769 | - if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id']) |
|
770 | - fatal_lang_error('no_access', false); |
|
790 | + if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id']) { |
|
791 | + fatal_lang_error('no_access', false); |
|
792 | + } |
|
771 | 793 | |
772 | 794 | if (!empty($pms)) |
773 | 795 | { |
774 | 796 | // Select the correct current message. |
775 | - if (empty($pmID)) |
|
776 | - $context['current_pm'] = $lastData['id']; |
|
797 | + if (empty($pmID)) { |
|
798 | + $context['current_pm'] = $lastData['id']; |
|
799 | + } |
|
777 | 800 | |
778 | 801 | // This is a list of the pm's that are used for "full" display. |
779 | - if ($context['display_mode'] == 0) |
|
780 | - $display_pms = $pms; |
|
781 | - else |
|
782 | - $display_pms = array($context['current_pm']); |
|
802 | + if ($context['display_mode'] == 0) { |
|
803 | + $display_pms = $pms; |
|
804 | + } else { |
|
805 | + $display_pms = array($context['current_pm']); |
|
806 | + } |
|
783 | 807 | |
784 | 808 | // At this point we know the main id_pm's. But - if we are looking at conversations we need the others! |
785 | 809 | if ($context['display_mode'] == 2) |
@@ -801,16 +825,18 @@ discard block |
||
801 | 825 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
802 | 826 | { |
803 | 827 | // This is, frankly, a joke. We will put in a workaround for people sending to themselves - yawn! |
804 | - if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1) |
|
805 | - continue; |
|
806 | - elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1) |
|
807 | - continue; |
|
828 | + if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1) { |
|
829 | + continue; |
|
830 | + } elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1) { |
|
831 | + continue; |
|
832 | + } |
|
808 | 833 | |
809 | - if (!isset($recipients[$row['id_pm']])) |
|
810 | - $recipients[$row['id_pm']] = array( |
|
834 | + if (!isset($recipients[$row['id_pm']])) { |
|
835 | + $recipients[$row['id_pm']] = array( |
|
811 | 836 | 'to' => array(), |
812 | 837 | 'bcc' => array() |
813 | 838 | ); |
839 | + } |
|
814 | 840 | $display_pms[] = $row['id_pm']; |
815 | 841 | $posters[$row['id_pm']] = $row['id_member_from']; |
816 | 842 | } |
@@ -861,8 +887,9 @@ discard block |
||
861 | 887 | while ($row2 = $smcFunc['db_fetch_assoc']($request2)) |
862 | 888 | { |
863 | 889 | $l_id = $row2['id_label']; |
864 | - if (isset($context['labels'][$l_id])) |
|
865 | - $context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); |
|
890 | + if (isset($context['labels'][$l_id])) { |
|
891 | + $context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); |
|
892 | + } |
|
866 | 893 | } |
867 | 894 | |
868 | 895 | $smcFunc['db_free_result']($request2); |
@@ -879,9 +906,10 @@ discard block |
||
879 | 906 | // Make sure we don't load unnecessary data. |
880 | 907 | if ($context['display_mode'] == 1) |
881 | 908 | { |
882 | - foreach ($posters as $k => $v) |
|
883 | - if (!in_array($k, $display_pms)) |
|
909 | + foreach ($posters as $k => $v) { |
|
910 | + if (!in_array($k, $display_pms)) |
|
884 | 911 | unset($posters[$k]); |
912 | + } |
|
885 | 913 | } |
886 | 914 | |
887 | 915 | // Load any users.... |
@@ -892,8 +920,9 @@ discard block |
||
892 | 920 | { |
893 | 921 | // Get the order right. |
894 | 922 | $orderBy = array(); |
895 | - foreach (array_reverse($pms) as $pm) |
|
896 | - $orderBy[] = 'pm.id_pm = ' . $pm; |
|
923 | + foreach (array_reverse($pms) as $pm) { |
|
924 | + $orderBy[] = 'pm.id_pm = ' . $pm; |
|
925 | + } |
|
897 | 926 | |
898 | 927 | // Seperate query for these bits! |
899 | 928 | $subjects_request = $smcFunc['db_query']('', ' |
@@ -939,9 +968,9 @@ discard block |
||
939 | 968 | // Allow mods to add additional buttons here |
940 | 969 | call_integration_hook('integrate_conversation_buttons'); |
941 | 970 | } |
971 | + } else { |
|
972 | + $messages_request = false; |
|
942 | 973 | } |
943 | - else |
|
944 | - $messages_request = false; |
|
945 | 974 | |
946 | 975 | $context['can_send_pm'] = allowedTo('pm_send'); |
947 | 976 | $context['can_send_email'] = allowedTo('moderate_forum'); |
@@ -952,11 +981,13 @@ discard block |
||
952 | 981 | if ($context['folder'] != 'sent' && !empty($context['labels'][(int) $context['current_label_id']]['unread_messages'])) |
953 | 982 | { |
954 | 983 | // If the display mode is "old sk00l" do them all... |
955 | - if ($context['display_mode'] == 0) |
|
956 | - markMessages(null, $context['current_label_id']); |
|
984 | + if ($context['display_mode'] == 0) { |
|
985 | + markMessages(null, $context['current_label_id']); |
|
986 | + } |
|
957 | 987 | // Otherwise do just the current one! |
958 | - elseif (!empty($context['current_pm'])) |
|
959 | - markMessages($display_pms, $context['current_label_id']); |
|
988 | + elseif (!empty($context['current_pm'])) { |
|
989 | + markMessages($display_pms, $context['current_label_id']); |
|
990 | + } |
|
960 | 991 | } |
961 | 992 | } |
962 | 993 | |
@@ -974,8 +1005,9 @@ discard block |
||
974 | 1005 | |
975 | 1006 | // Count the current message number.... |
976 | 1007 | static $counter = null; |
977 | - if ($counter === null || $reset) |
|
978 | - $counter = $context['start']; |
|
1008 | + if ($counter === null || $reset) { |
|
1009 | + $counter = $context['start']; |
|
1010 | + } |
|
979 | 1011 | |
980 | 1012 | static $temp_pm_selected = null; |
981 | 1013 | if ($temp_pm_selected === null) |
@@ -1020,19 +1052,22 @@ discard block |
||
1020 | 1052 | } |
1021 | 1053 | |
1022 | 1054 | // Bail if it's false, ie. no messages. |
1023 | - if ($messages_request == false) |
|
1024 | - return false; |
|
1055 | + if ($messages_request == false) { |
|
1056 | + return false; |
|
1057 | + } |
|
1025 | 1058 | |
1026 | 1059 | // Reset the data? |
1027 | - if ($reset == true) |
|
1028 | - return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1060 | + if ($reset == true) { |
|
1061 | + return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1062 | + } |
|
1029 | 1063 | |
1030 | 1064 | // Get the next one... bail if anything goes wrong. |
1031 | 1065 | $message = $smcFunc['db_fetch_assoc']($messages_request); |
1032 | 1066 | if (!$message) |
1033 | 1067 | { |
1034 | - if ($type != 'subject') |
|
1035 | - $smcFunc['db_free_result']($messages_request); |
|
1068 | + if ($type != 'subject') { |
|
1069 | + $smcFunc['db_free_result']($messages_request); |
|
1070 | + } |
|
1036 | 1071 | |
1037 | 1072 | return false; |
1038 | 1073 | } |
@@ -1052,8 +1087,7 @@ discard block |
||
1052 | 1087 | $memberContext[$message['id_member_from']]['email'] = ''; |
1053 | 1088 | $memberContext[$message['id_member_from']]['show_email'] = false; |
1054 | 1089 | $memberContext[$message['id_member_from']]['is_guest'] = true; |
1055 | - } |
|
1056 | - else |
|
1090 | + } else |
|
1057 | 1091 | { |
1058 | 1092 | $memberContext[$message['id_member_from']]['can_view_profile'] = allowedTo('profile_view') || ($message['id_member_from'] == $user_info['id'] && !$user_info['is_guest']); |
1059 | 1093 | $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']))); |
@@ -1094,9 +1128,10 @@ discard block |
||
1094 | 1128 | $counter++; |
1095 | 1129 | |
1096 | 1130 | // Any custom profile fields? |
1097 | - if (!empty($memberContext[$message['id_member_from']]['custom_fields'])) |
|
1098 | - foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom) |
|
1131 | + if (!empty($memberContext[$message['id_member_from']]['custom_fields'])) { |
|
1132 | + foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom) |
|
1099 | 1133 | $output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom; |
1134 | + } |
|
1100 | 1135 | |
1101 | 1136 | call_integration_hook('integrate_prepare_pm_context', array(&$output, &$message, $counter)); |
1102 | 1137 | |
@@ -1120,22 +1155,28 @@ discard block |
||
1120 | 1155 | $context['search_params'][$k] = $v; |
1121 | 1156 | } |
1122 | 1157 | } |
1123 | - if (isset($_REQUEST['search'])) |
|
1124 | - $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']); |
|
1158 | + if (isset($_REQUEST['search'])) { |
|
1159 | + $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']); |
|
1160 | + } |
|
1125 | 1161 | |
1126 | - if (isset($context['search_params']['search'])) |
|
1127 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
1128 | - if (isset($context['search_params']['userspec'])) |
|
1129 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
1162 | + if (isset($context['search_params']['search'])) { |
|
1163 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
1164 | + } |
|
1165 | + if (isset($context['search_params']['userspec'])) { |
|
1166 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
1167 | + } |
|
1130 | 1168 | |
1131 | - if (!empty($context['search_params']['searchtype'])) |
|
1132 | - $context['search_params']['searchtype'] = 2; |
|
1169 | + if (!empty($context['search_params']['searchtype'])) { |
|
1170 | + $context['search_params']['searchtype'] = 2; |
|
1171 | + } |
|
1133 | 1172 | |
1134 | - if (!empty($context['search_params']['minage'])) |
|
1135 | - $context['search_params']['minage'] = (int) $context['search_params']['minage']; |
|
1173 | + if (!empty($context['search_params']['minage'])) { |
|
1174 | + $context['search_params']['minage'] = (int) $context['search_params']['minage']; |
|
1175 | + } |
|
1136 | 1176 | |
1137 | - if (!empty($context['search_params']['maxage'])) |
|
1138 | - $context['search_params']['maxage'] = (int) $context['search_params']['maxage']; |
|
1177 | + if (!empty($context['search_params']['maxage'])) { |
|
1178 | + $context['search_params']['maxage'] = (int) $context['search_params']['maxage']; |
|
1179 | + } |
|
1139 | 1180 | |
1140 | 1181 | $context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']); |
1141 | 1182 | $context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']); |
@@ -1162,8 +1203,9 @@ discard block |
||
1162 | 1203 | $context['search_errors']['messages'] = array(); |
1163 | 1204 | foreach ($context['search_errors'] as $search_error => $dummy) |
1164 | 1205 | { |
1165 | - if ($search_error == 'messages') |
|
1166 | - continue; |
|
1206 | + if ($search_error == 'messages') { |
|
1207 | + continue; |
|
1208 | + } |
|
1167 | 1209 | |
1168 | 1210 | $context['search_errors']['messages'][] = $txt['error_' . $search_error]; |
1169 | 1211 | } |
@@ -1185,8 +1227,9 @@ discard block |
||
1185 | 1227 | global $scripturl, $modSettings, $user_info, $context, $txt; |
1186 | 1228 | global $memberContext, $smcFunc; |
1187 | 1229 | |
1188 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) |
|
1189 | - fatal_lang_error('loadavg_search_disabled', false); |
|
1230 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) { |
|
1231 | + fatal_lang_error('loadavg_search_disabled', false); |
|
1232 | + } |
|
1190 | 1233 | |
1191 | 1234 | /** |
1192 | 1235 | * @todo For the moment force the folder to the inbox. |
@@ -1215,35 +1258,40 @@ discard block |
||
1215 | 1258 | $context['start'] = isset($_GET['start']) ? (int) $_GET['start'] : 0; |
1216 | 1259 | |
1217 | 1260 | // Store whether simple search was used (needed if the user wants to do another query). |
1218 | - if (!isset($search_params['advanced'])) |
|
1219 | - $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1; |
|
1261 | + if (!isset($search_params['advanced'])) { |
|
1262 | + $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1; |
|
1263 | + } |
|
1220 | 1264 | |
1221 | 1265 | // 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'. |
1222 | - if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) |
|
1223 | - $search_params['searchtype'] = 2; |
|
1266 | + if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) { |
|
1267 | + $search_params['searchtype'] = 2; |
|
1268 | + } |
|
1224 | 1269 | |
1225 | 1270 | // Minimum age of messages. Default to zero (don't set param in that case). |
1226 | - if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) |
|
1227 | - $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage']; |
|
1271 | + if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) { |
|
1272 | + $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage']; |
|
1273 | + } |
|
1228 | 1274 | |
1229 | 1275 | // Maximum age of messages. Default to infinite (9999 days: param not set). |
1230 | - if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999)) |
|
1231 | - $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage']; |
|
1276 | + if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999)) { |
|
1277 | + $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage']; |
|
1278 | + } |
|
1232 | 1279 | |
1233 | 1280 | $search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']); |
1234 | 1281 | $search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']); |
1235 | 1282 | |
1236 | 1283 | // Default the user name to a wildcard matching every user (*). |
1237 | - if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) |
|
1238 | - $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec']; |
|
1284 | + if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) { |
|
1285 | + $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec']; |
|
1286 | + } |
|
1239 | 1287 | |
1240 | 1288 | // This will be full of all kinds of parameters! |
1241 | 1289 | $searchq_parameters = array(); |
1242 | 1290 | |
1243 | 1291 | // If there's no specific user, then don't mention it in the main query. |
1244 | - if (empty($search_params['userspec'])) |
|
1245 | - $userQuery = ''; |
|
1246 | - else |
|
1292 | + if (empty($search_params['userspec'])) { |
|
1293 | + $userQuery = ''; |
|
1294 | + } else |
|
1247 | 1295 | { |
1248 | 1296 | $userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('"' => '"')); |
1249 | 1297 | $userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')); |
@@ -1255,8 +1303,9 @@ discard block |
||
1255 | 1303 | { |
1256 | 1304 | $possible_users[$k] = trim($possible_users[$k]); |
1257 | 1305 | |
1258 | - if (strlen($possible_users[$k]) == 0) |
|
1259 | - unset($possible_users[$k]); |
|
1306 | + if (strlen($possible_users[$k]) == 0) { |
|
1307 | + unset($possible_users[$k]); |
|
1308 | + } |
|
1260 | 1309 | } |
1261 | 1310 | |
1262 | 1311 | if (!empty($possible_users)) |
@@ -1268,8 +1317,9 @@ discard block |
||
1268 | 1317 | { |
1269 | 1318 | $where_params['name_' . $k] = $v; |
1270 | 1319 | $where_clause[] = '{raw:real_name} LIKE {string:name_' . $k . '}'; |
1271 | - if (!isset($where_params['real_name'])) |
|
1272 | - $where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name'; |
|
1320 | + if (!isset($where_params['real_name'])) { |
|
1321 | + $where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name'; |
|
1322 | + } |
|
1273 | 1323 | } |
1274 | 1324 | |
1275 | 1325 | // Who matches those criteria? |
@@ -1282,28 +1332,28 @@ discard block |
||
1282 | 1332 | ); |
1283 | 1333 | |
1284 | 1334 | // Simply do nothing if there're too many members matching the criteria. |
1285 | - if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) |
|
1286 | - $userQuery = ''; |
|
1287 | - elseif ($smcFunc['db_num_rows']($request) == 0) |
|
1335 | + if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) { |
|
1336 | + $userQuery = ''; |
|
1337 | + } elseif ($smcFunc['db_num_rows']($request) == 0) |
|
1288 | 1338 | { |
1289 | 1339 | $userQuery = 'AND pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})'; |
1290 | 1340 | $searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\''; |
1291 | 1341 | $searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name'; |
1292 | - } |
|
1293 | - else |
|
1342 | + } else |
|
1294 | 1343 | { |
1295 | 1344 | $memberlist = array(); |
1296 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1297 | - $memberlist[] = $row['id_member']; |
|
1345 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1346 | + $memberlist[] = $row['id_member']; |
|
1347 | + } |
|
1298 | 1348 | $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})))'; |
1299 | 1349 | $searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\''; |
1300 | 1350 | $searchq_parameters['member_list'] = $memberlist; |
1301 | 1351 | $searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name'; |
1302 | 1352 | } |
1303 | 1353 | $smcFunc['db_free_result']($request); |
1354 | + } else { |
|
1355 | + $userQuery = ''; |
|
1304 | 1356 | } |
1305 | - else |
|
1306 | - $userQuery = ''; |
|
1307 | 1357 | } |
1308 | 1358 | |
1309 | 1359 | // Setup the sorting variables... |
@@ -1311,8 +1361,9 @@ discard block |
||
1311 | 1361 | $sort_columns = array( |
1312 | 1362 | 'pm.id_pm', |
1313 | 1363 | ); |
1314 | - if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) |
|
1315 | - list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); |
|
1364 | + if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) { |
|
1365 | + list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); |
|
1366 | + } |
|
1316 | 1367 | $search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'pm.id_pm'; |
1317 | 1368 | $search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc'; |
1318 | 1369 | |
@@ -1322,24 +1373,27 @@ discard block |
||
1322 | 1373 | if ($context['folder'] == 'inbox' && !empty($search_params['advanced']) && $context['currently_using_labels']) |
1323 | 1374 | { |
1324 | 1375 | // Came here from pagination? Put them back into $_REQUEST for sanitization. |
1325 | - if (isset($search_params['labels'])) |
|
1326 | - $_REQUEST['searchlabel'] = explode(',', $search_params['labels']); |
|
1376 | + if (isset($search_params['labels'])) { |
|
1377 | + $_REQUEST['searchlabel'] = explode(',', $search_params['labels']); |
|
1378 | + } |
|
1327 | 1379 | |
1328 | 1380 | // Assuming we have some labels - make them all integers. |
1329 | 1381 | if (!empty($_REQUEST['searchlabel']) && is_array($_REQUEST['searchlabel'])) |
1330 | 1382 | { |
1331 | - foreach ($_REQUEST['searchlabel'] as $key => $id) |
|
1332 | - $_REQUEST['searchlabel'][$key] = (int) $id; |
|
1383 | + foreach ($_REQUEST['searchlabel'] as $key => $id) { |
|
1384 | + $_REQUEST['searchlabel'][$key] = (int) $id; |
|
1385 | + } |
|
1386 | + } else { |
|
1387 | + $_REQUEST['searchlabel'] = array(); |
|
1333 | 1388 | } |
1334 | - else |
|
1335 | - $_REQUEST['searchlabel'] = array(); |
|
1336 | 1389 | |
1337 | 1390 | // Now that everything is cleaned up a bit, make the labels a param. |
1338 | 1391 | $search_params['labels'] = implode(',', $_REQUEST['searchlabel']); |
1339 | 1392 | |
1340 | 1393 | // No labels selected? That must be an error! |
1341 | - if (empty($_REQUEST['searchlabel'])) |
|
1342 | - $context['search_errors']['no_labels_selected'] = true; |
|
1394 | + if (empty($_REQUEST['searchlabel'])) { |
|
1395 | + $context['search_errors']['no_labels_selected'] = true; |
|
1396 | + } |
|
1343 | 1397 | // Otherwise prepare the query! |
1344 | 1398 | elseif (count($_REQUEST['searchlabel']) != count($context['labels'])) |
1345 | 1399 | { |
@@ -1362,8 +1416,7 @@ discard block |
||
1362 | 1416 | // Not searching the inbox - PM must be labeled |
1363 | 1417 | $labelQuery = ' AND pml.id_label IN ({array_int:labels})'; |
1364 | 1418 | $labelJoin = ' INNER JOIN {db_prefix}pm_labeled_messages AS pml ON (pml.id_pm = pmr.id_pm)'; |
1365 | - } |
|
1366 | - else |
|
1419 | + } else |
|
1367 | 1420 | { |
1368 | 1421 | // Searching the inbox - PM doesn't have to be labeled |
1369 | 1422 | $labelQuery = ' AND (' . substr($labelQuery, 5) . ' OR pml.id_label IN ({array_int:labels}))'; |
@@ -1378,8 +1431,9 @@ discard block |
||
1378 | 1431 | // What are we actually searching for? |
1379 | 1432 | $search_params['search'] = !empty($search_params['search']) ? $search_params['search'] : (isset($_REQUEST['search']) ? $_REQUEST['search'] : ''); |
1380 | 1433 | // If we ain't got nothing - we should error! |
1381 | - if (!isset($search_params['search']) || $search_params['search'] == '') |
|
1382 | - $context['search_errors']['invalid_search_string'] = true; |
|
1434 | + if (!isset($search_params['search']) || $search_params['search'] == '') { |
|
1435 | + $context['search_errors']['invalid_search_string'] = true; |
|
1436 | + } |
|
1383 | 1437 | |
1384 | 1438 | // Extract phrase parts first (e.g. some words "this is a phrase" some more words.) |
1385 | 1439 | preg_match_all('~(?:^|\s)([-]?)"([^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), $search_params['search'], $matches, PREG_PATTERN_ORDER); |
@@ -1392,12 +1446,14 @@ discard block |
||
1392 | 1446 | $excludedWords = array(); |
1393 | 1447 | |
1394 | 1448 | // .. first, we check for things like -"some words", but not "-some words". |
1395 | - foreach ($matches[1] as $index => $word) |
|
1396 | - if ($word == '-') |
|
1449 | + foreach ($matches[1] as $index => $word) { |
|
1450 | + if ($word == '-') |
|
1397 | 1451 | { |
1398 | 1452 | $word = $smcFunc['strtolower'](trim($searchArray[$index])); |
1399 | - if (strlen($word) > 0) |
|
1400 | - $excludedWords[] = $word; |
|
1453 | + } |
|
1454 | + if (strlen($word) > 0) { |
|
1455 | + $excludedWords[] = $word; |
|
1456 | + } |
|
1401 | 1457 | unset($searchArray[$index]); |
1402 | 1458 | } |
1403 | 1459 | |
@@ -1407,8 +1463,9 @@ discard block |
||
1407 | 1463 | if (strpos(trim($word), '-') === 0) |
1408 | 1464 | { |
1409 | 1465 | $word = substr($smcFunc['strtolower']($word), 1); |
1410 | - if (strlen($word) > 0) |
|
1411 | - $excludedWords[] = $word; |
|
1466 | + if (strlen($word) > 0) { |
|
1467 | + $excludedWords[] = $word; |
|
1468 | + } |
|
1412 | 1469 | unset($tempSearch[$index]); |
1413 | 1470 | } |
1414 | 1471 | } |
@@ -1419,9 +1476,9 @@ discard block |
||
1419 | 1476 | foreach ($searchArray as $index => $value) |
1420 | 1477 | { |
1421 | 1478 | $searchArray[$index] = $smcFunc['strtolower'](trim($value)); |
1422 | - if ($searchArray[$index] == '') |
|
1423 | - unset($searchArray[$index]); |
|
1424 | - else |
|
1479 | + if ($searchArray[$index] == '') { |
|
1480 | + unset($searchArray[$index]); |
|
1481 | + } else |
|
1425 | 1482 | { |
1426 | 1483 | // Sort out entities first. |
1427 | 1484 | $searchArray[$index] = $smcFunc['htmlspecialchars']($searchArray[$index]); |
@@ -1431,27 +1488,32 @@ discard block |
||
1431 | 1488 | |
1432 | 1489 | // Create an array of replacements for highlighting. |
1433 | 1490 | $context['mark'] = array(); |
1434 | - foreach ($searchArray as $word) |
|
1435 | - $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>'; |
|
1491 | + foreach ($searchArray as $word) { |
|
1492 | + $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>'; |
|
1493 | + } |
|
1436 | 1494 | |
1437 | 1495 | // This contains *everything* |
1438 | 1496 | $searchWords = array_merge($searchArray, $excludedWords); |
1439 | 1497 | |
1440 | 1498 | // Make sure at least one word is being searched for. |
1441 | - if (empty($searchArray)) |
|
1442 | - $context['search_errors']['invalid_search_string'] = true; |
|
1499 | + if (empty($searchArray)) { |
|
1500 | + $context['search_errors']['invalid_search_string'] = true; |
|
1501 | + } |
|
1443 | 1502 | |
1444 | 1503 | // Sort out the search query so the user can edit it - if they want. |
1445 | 1504 | $context['search_params'] = $search_params; |
1446 | - if (isset($context['search_params']['search'])) |
|
1447 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
1448 | - if (isset($context['search_params']['userspec'])) |
|
1449 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
1505 | + if (isset($context['search_params']['search'])) { |
|
1506 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
1507 | + } |
|
1508 | + if (isset($context['search_params']['userspec'])) { |
|
1509 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
1510 | + } |
|
1450 | 1511 | |
1451 | 1512 | // Now we have all the parameters, combine them together for pagination and the like... |
1452 | 1513 | $context['params'] = array(); |
1453 | - foreach ($search_params as $k => $v) |
|
1454 | - $context['params'][] = $k . '|\'|' . $v; |
|
1514 | + foreach ($search_params as $k => $v) { |
|
1515 | + $context['params'][] = $k . '|\'|' . $v; |
|
1516 | + } |
|
1455 | 1517 | $context['params'] = base64_encode(implode('|"|', $context['params'])); |
1456 | 1518 | |
1457 | 1519 | // Compile the subject query part. |
@@ -1459,26 +1521,31 @@ discard block |
||
1459 | 1521 | |
1460 | 1522 | foreach ($searchWords as $index => $word) |
1461 | 1523 | { |
1462 | - if ($word == '') |
|
1463 | - continue; |
|
1524 | + if ($word == '') { |
|
1525 | + continue; |
|
1526 | + } |
|
1464 | 1527 | |
1465 | - if ($search_params['subject_only']) |
|
1466 | - $andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}'; |
|
1467 | - else |
|
1468 | - $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 . '})'; |
|
1528 | + if ($search_params['subject_only']) { |
|
1529 | + $andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}'; |
|
1530 | + } else { |
|
1531 | + $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 . '})'; |
|
1532 | + } |
|
1469 | 1533 | $searchq_parameters['search_' . $index] = '%' . strtr($word, array('_' => '\\_', '%' => '\\%')) . '%'; |
1470 | 1534 | } |
1471 | 1535 | |
1472 | 1536 | $searchQuery = ' 1=1'; |
1473 | - if (!empty($andQueryParts)) |
|
1474 | - $searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts); |
|
1537 | + if (!empty($andQueryParts)) { |
|
1538 | + $searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts); |
|
1539 | + } |
|
1475 | 1540 | |
1476 | 1541 | // Age limits? |
1477 | 1542 | $timeQuery = ''; |
1478 | - if (!empty($search_params['minage'])) |
|
1479 | - $timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400); |
|
1480 | - if (!empty($search_params['maxage'])) |
|
1481 | - $timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400); |
|
1543 | + if (!empty($search_params['minage'])) { |
|
1544 | + $timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400); |
|
1545 | + } |
|
1546 | + if (!empty($search_params['maxage'])) { |
|
1547 | + $timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400); |
|
1548 | + } |
|
1482 | 1549 | |
1483 | 1550 | // If we have errors - return back to the first screen... |
1484 | 1551 | if (!empty($context['search_errors'])) |
@@ -1564,8 +1631,9 @@ discard block |
||
1564 | 1631 | ) |
1565 | 1632 | ); |
1566 | 1633 | $real_pm_ids = array(); |
1567 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1568 | - $real_pm_ids[$row['id_pm_head']] = $row['id_pm']; |
|
1634 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1635 | + $real_pm_ids[$row['id_pm_head']] = $row['id_pm']; |
|
1636 | + } |
|
1569 | 1637 | $smcFunc['db_free_result']($request); |
1570 | 1638 | } |
1571 | 1639 | |
@@ -1595,8 +1663,9 @@ discard block |
||
1595 | 1663 | ); |
1596 | 1664 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1597 | 1665 | { |
1598 | - if ($context['folder'] == 'sent' || empty($row['bcc'])) |
|
1599 | - $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 | + if ($context['folder'] == 'sent' || empty($row['bcc'])) { |
|
1667 | + $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>'; |
|
1668 | + } |
|
1600 | 1669 | |
1601 | 1670 | if ($row['id_member_to'] == $user_info['id'] && $context['folder'] != 'sent') |
1602 | 1671 | { |
@@ -1617,12 +1686,14 @@ discard block |
||
1617 | 1686 | while ($row2 = $smcFunc['db_fetch_assoc']($request2)) |
1618 | 1687 | { |
1619 | 1688 | $l_id = $row2['id_label']; |
1620 | - if (isset($context['labels'][$l_id])) |
|
1621 | - $context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); |
|
1689 | + if (isset($context['labels'][$l_id])) { |
|
1690 | + $context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); |
|
1691 | + } |
|
1622 | 1692 | |
1623 | 1693 | // Here we find the first label on a message - for linking to posts in results |
1624 | - if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1) |
|
1625 | - $context['first_label'][$row['id_pm']] = $l_id; |
|
1694 | + if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1) { |
|
1695 | + $context['first_label'][$row['id_pm']] = $l_id; |
|
1696 | + } |
|
1626 | 1697 | } |
1627 | 1698 | |
1628 | 1699 | $smcFunc['db_free_result']($request2); |
@@ -1749,8 +1820,9 @@ discard block |
||
1749 | 1820 | list ($postCount) = $smcFunc['db_fetch_row']($request); |
1750 | 1821 | $smcFunc['db_free_result']($request); |
1751 | 1822 | |
1752 | - if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) |
|
1753 | - fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); |
|
1823 | + if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) { |
|
1824 | + fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); |
|
1825 | + } |
|
1754 | 1826 | } |
1755 | 1827 | |
1756 | 1828 | // Quoting/Replying to a message? |
@@ -1759,8 +1831,9 @@ discard block |
||
1759 | 1831 | $pmsg = (int) $_REQUEST['pmsg']; |
1760 | 1832 | |
1761 | 1833 | // Make sure this is yours. |
1762 | - if (!isAccessiblePM($pmsg)) |
|
1763 | - fatal_lang_error('no_access', false); |
|
1834 | + if (!isAccessiblePM($pmsg)) { |
|
1835 | + fatal_lang_error('no_access', false); |
|
1836 | + } |
|
1764 | 1837 | |
1765 | 1838 | // Work out whether this is one you've received? |
1766 | 1839 | $request = $smcFunc['db_query']('', ' |
@@ -1797,8 +1870,9 @@ discard block |
||
1797 | 1870 | 'id_pm' => $pmsg, |
1798 | 1871 | ) |
1799 | 1872 | ); |
1800 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
1801 | - fatal_lang_error('pm_not_yours', false); |
|
1873 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
1874 | + fatal_lang_error('pm_not_yours', false); |
|
1875 | + } |
|
1802 | 1876 | $row_quoted = $smcFunc['db_fetch_assoc']($request); |
1803 | 1877 | $smcFunc['db_free_result']($request); |
1804 | 1878 | |
@@ -1809,9 +1883,9 @@ discard block |
||
1809 | 1883 | // Add 'Re: ' to it.... |
1810 | 1884 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
1811 | 1885 | { |
1812 | - if ($language === $user_info['language']) |
|
1813 | - $context['response_prefix'] = $txt['response_prefix']; |
|
1814 | - else |
|
1886 | + if ($language === $user_info['language']) { |
|
1887 | + $context['response_prefix'] = $txt['response_prefix']; |
|
1888 | + } else |
|
1815 | 1889 | { |
1816 | 1890 | loadLanguage('index', $language, false); |
1817 | 1891 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -1820,22 +1894,25 @@ discard block |
||
1820 | 1894 | cache_put_data('response_prefix', $context['response_prefix'], 600); |
1821 | 1895 | } |
1822 | 1896 | $form_subject = $row_quoted['subject']; |
1823 | - if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
|
1824 | - $form_subject = $context['response_prefix'] . $form_subject; |
|
1897 | + if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) { |
|
1898 | + $form_subject = $context['response_prefix'] . $form_subject; |
|
1899 | + } |
|
1825 | 1900 | |
1826 | 1901 | if (isset($_REQUEST['quote'])) |
1827 | 1902 | { |
1828 | 1903 | // Remove any nested quotes and <br>... |
1829 | 1904 | $form_message = preg_replace('~<br ?/?' . '>~i', "\n", $row_quoted['body']); |
1830 | - if (!empty($modSettings['removeNestedQuotes'])) |
|
1831 | - $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
1832 | - if (empty($row_quoted['id_member'])) |
|
1833 | - $form_message = '[quote author="' . $row_quoted['real_name'] . '"]' . "\n" . $form_message . "\n" . '[/quote]'; |
|
1834 | - else |
|
1835 | - $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]'; |
|
1905 | + if (!empty($modSettings['removeNestedQuotes'])) { |
|
1906 | + $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
1907 | + } |
|
1908 | + if (empty($row_quoted['id_member'])) { |
|
1909 | + $form_message = '[quote author="' . $row_quoted['real_name'] . '"]' . "\n" . $form_message . "\n" . '[/quote]'; |
|
1910 | + } else { |
|
1911 | + $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]'; |
|
1912 | + } |
|
1913 | + } else { |
|
1914 | + $form_message = ''; |
|
1836 | 1915 | } |
1837 | - else |
|
1838 | - $form_message = ''; |
|
1839 | 1916 | |
1840 | 1917 | // Do the BBC thang on the message. |
1841 | 1918 | $row_quoted['body'] = parse_bbc($row_quoted['body'], true, 'pm' . $row_quoted['id_pm']); |
@@ -1856,8 +1933,7 @@ discard block |
||
1856 | 1933 | 'timestamp' => forum_time(true, $row_quoted['msgtime']), |
1857 | 1934 | 'body' => $row_quoted['body'] |
1858 | 1935 | ); |
1859 | - } |
|
1860 | - else |
|
1936 | + } else |
|
1861 | 1937 | { |
1862 | 1938 | $context['quoted_message'] = false; |
1863 | 1939 | $form_subject = ''; |
@@ -1876,11 +1952,12 @@ discard block |
||
1876 | 1952 | if ($_REQUEST['u'] == 'all' && isset($row_quoted)) |
1877 | 1953 | { |
1878 | 1954 | // Firstly, to reply to all we clearly already have $row_quoted - so have the original member from. |
1879 | - if ($row_quoted['id_member'] != $user_info['id']) |
|
1880 | - $context['recipients']['to'][] = array( |
|
1955 | + if ($row_quoted['id_member'] != $user_info['id']) { |
|
1956 | + $context['recipients']['to'][] = array( |
|
1881 | 1957 | 'id' => $row_quoted['id_member'], |
1882 | 1958 | 'name' => $smcFunc['htmlspecialchars']($row_quoted['real_name']), |
1883 | 1959 | ); |
1960 | + } |
|
1884 | 1961 | |
1885 | 1962 | // Now to get the others. |
1886 | 1963 | $request = $smcFunc['db_query']('', ' |
@@ -1896,18 +1973,19 @@ discard block |
||
1896 | 1973 | 'not_bcc' => 0, |
1897 | 1974 | ) |
1898 | 1975 | ); |
1899 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1900 | - $context['recipients']['to'][] = array( |
|
1976 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1977 | + $context['recipients']['to'][] = array( |
|
1901 | 1978 | 'id' => $row['id_member'], |
1902 | 1979 | 'name' => $row['real_name'], |
1903 | 1980 | ); |
1981 | + } |
|
1904 | 1982 | $smcFunc['db_free_result']($request); |
1905 | - } |
|
1906 | - else |
|
1983 | + } else |
|
1907 | 1984 | { |
1908 | 1985 | $_REQUEST['u'] = explode(',', $_REQUEST['u']); |
1909 | - foreach ($_REQUEST['u'] as $key => $uID) |
|
1910 | - $_REQUEST['u'][$key] = (int) $uID; |
|
1986 | + foreach ($_REQUEST['u'] as $key => $uID) { |
|
1987 | + $_REQUEST['u'][$key] = (int) $uID; |
|
1988 | + } |
|
1911 | 1989 | |
1912 | 1990 | $_REQUEST['u'] = array_unique($_REQUEST['u']); |
1913 | 1991 | |
@@ -1921,22 +1999,24 @@ discard block |
||
1921 | 1999 | 'limit' => count($_REQUEST['u']), |
1922 | 2000 | ) |
1923 | 2001 | ); |
1924 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1925 | - $context['recipients']['to'][] = array( |
|
2002 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2003 | + $context['recipients']['to'][] = array( |
|
1926 | 2004 | 'id' => $row['id_member'], |
1927 | 2005 | 'name' => $row['real_name'], |
1928 | 2006 | ); |
2007 | + } |
|
1929 | 2008 | $smcFunc['db_free_result']($request); |
1930 | 2009 | } |
1931 | 2010 | |
1932 | 2011 | // Get a literal name list in case the user has JavaScript disabled. |
1933 | 2012 | $names = array(); |
1934 | - foreach ($context['recipients']['to'] as $to) |
|
1935 | - $names[] = $to['name']; |
|
2013 | + foreach ($context['recipients']['to'] as $to) { |
|
2014 | + $names[] = $to['name']; |
|
2015 | + } |
|
1936 | 2016 | $context['to_value'] = empty($names) ? '' : '"' . implode('", "', $names) . '"'; |
2017 | + } else { |
|
2018 | + $context['to_value'] = ''; |
|
1937 | 2019 | } |
1938 | - else |
|
1939 | - $context['to_value'] = ''; |
|
1940 | 2020 | |
1941 | 2021 | // Set the defaults... |
1942 | 2022 | $context['subject'] = $form_subject; |
@@ -2006,8 +2086,9 @@ discard block |
||
2006 | 2086 | |
2007 | 2087 | // validate with loadMemberData() |
2008 | 2088 | $memberResult = loadMemberData($user_info['id'], false); |
2009 | - if (!$memberResult) |
|
2010 | - fatal_lang_error('not_a_user', false); |
|
2089 | + if (!$memberResult) { |
|
2090 | + fatal_lang_error('not_a_user', false); |
|
2091 | + } |
|
2011 | 2092 | list ($memID) = $memberResult; |
2012 | 2093 | |
2013 | 2094 | // drafts is where the functions reside |
@@ -2033,9 +2114,9 @@ discard block |
||
2033 | 2114 | $context['sub_template'] = 'send'; |
2034 | 2115 | loadJavaScriptFile('PersonalMessage.js', array('defer' => false, 'minimize' => true), 'smf_pms'); |
2035 | 2116 | loadJavaScriptFile('suggest.js', array('defer' => false, 'minimize' => true), 'smf_suggest'); |
2117 | + } else { |
|
2118 | + $context['sub_template'] = 'pm'; |
|
2036 | 2119 | } |
2037 | - else |
|
2038 | - $context['sub_template'] = 'pm'; |
|
2039 | 2120 | |
2040 | 2121 | $context['page_title'] = $txt['send_message']; |
2041 | 2122 | |
@@ -2096,10 +2177,11 @@ discard block |
||
2096 | 2177 | ); |
2097 | 2178 | if ($smcFunc['db_num_rows']($request) == 0) |
2098 | 2179 | { |
2099 | - if (!isset($_REQUEST['xml'])) |
|
2100 | - fatal_lang_error('pm_not_yours', false); |
|
2101 | - else |
|
2102 | - $error_types[] = 'pm_not_yours'; |
|
2180 | + if (!isset($_REQUEST['xml'])) { |
|
2181 | + fatal_lang_error('pm_not_yours', false); |
|
2182 | + } else { |
|
2183 | + $error_types[] = 'pm_not_yours'; |
|
2184 | + } |
|
2103 | 2185 | } |
2104 | 2186 | $row_quoted = $smcFunc['db_fetch_assoc']($request); |
2105 | 2187 | $smcFunc['db_free_result']($request); |
@@ -2146,14 +2228,16 @@ discard block |
||
2146 | 2228 | $context['post_error'][$error_type] = true; |
2147 | 2229 | if (isset($txt['error_' . $error_type])) |
2148 | 2230 | { |
2149 | - if ($error_type == 'long_message') |
|
2150 | - $txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']); |
|
2231 | + if ($error_type == 'long_message') { |
|
2232 | + $txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']); |
|
2233 | + } |
|
2151 | 2234 | $context['post_error']['messages'][] = $txt['error_' . $error_type]; |
2152 | 2235 | } |
2153 | 2236 | |
2154 | 2237 | // If it's not a minor error flag it as such. |
2155 | - if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'))) |
|
2156 | - $context['error_type'] = 'serious'; |
|
2238 | + if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'))) { |
|
2239 | + $context['error_type'] = 'serious'; |
|
2240 | + } |
|
2157 | 2241 | } |
2158 | 2242 | |
2159 | 2243 | // We need to load the editor once more. |
@@ -2211,8 +2295,9 @@ discard block |
||
2211 | 2295 | require_once($sourcedir . '/Subs-Auth.php'); |
2212 | 2296 | |
2213 | 2297 | // PM Drafts enabled and needed? |
2214 | - if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft']))) |
|
2215 | - require_once($sourcedir . '/Drafts.php'); |
|
2298 | + if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft']))) { |
|
2299 | + require_once($sourcedir . '/Drafts.php'); |
|
2300 | + } |
|
2216 | 2301 | |
2217 | 2302 | loadLanguage('PersonalMessage', '', false); |
2218 | 2303 | |
@@ -2242,24 +2327,27 @@ discard block |
||
2242 | 2327 | |
2243 | 2328 | if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) |
2244 | 2329 | { |
2245 | - if (!isset($_REQUEST['xml'])) |
|
2246 | - fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); |
|
2247 | - else |
|
2248 | - $post_errors[] = 'pm_too_many_per_hour'; |
|
2330 | + if (!isset($_REQUEST['xml'])) { |
|
2331 | + fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); |
|
2332 | + } else { |
|
2333 | + $post_errors[] = 'pm_too_many_per_hour'; |
|
2334 | + } |
|
2249 | 2335 | } |
2250 | 2336 | } |
2251 | 2337 | |
2252 | 2338 | // If your session timed out, show an error, but do allow to re-submit. |
2253 | - if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '') |
|
2254 | - $post_errors[] = 'session_timeout'; |
|
2339 | + if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '') { |
|
2340 | + $post_errors[] = 'session_timeout'; |
|
2341 | + } |
|
2255 | 2342 | |
2256 | 2343 | $_REQUEST['subject'] = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : ''; |
2257 | 2344 | $_REQUEST['to'] = empty($_POST['to']) ? (empty($_GET['to']) ? '' : $_GET['to']) : $_POST['to']; |
2258 | 2345 | $_REQUEST['bcc'] = empty($_POST['bcc']) ? (empty($_GET['bcc']) ? '' : $_GET['bcc']) : $_POST['bcc']; |
2259 | 2346 | |
2260 | 2347 | // Route the input from the 'u' parameter to the 'to'-list. |
2261 | - if (!empty($_POST['u'])) |
|
2262 | - $_POST['recipient_to'] = explode(',', $_POST['u']); |
|
2348 | + if (!empty($_POST['u'])) { |
|
2349 | + $_POST['recipient_to'] = explode(',', $_POST['u']); |
|
2350 | + } |
|
2263 | 2351 | |
2264 | 2352 | // Construct the list of recipients. |
2265 | 2353 | $recipientList = array(); |
@@ -2271,8 +2359,9 @@ discard block |
||
2271 | 2359 | $recipientList[$recipientType] = array(); |
2272 | 2360 | if (!empty($_POST['recipient_' . $recipientType]) && is_array($_POST['recipient_' . $recipientType])) |
2273 | 2361 | { |
2274 | - foreach ($_POST['recipient_' . $recipientType] as $recipient) |
|
2275 | - $recipientList[$recipientType][] = (int) $recipient; |
|
2362 | + foreach ($_POST['recipient_' . $recipientType] as $recipient) { |
|
2363 | + $recipientList[$recipientType][] = (int) $recipient; |
|
2364 | + } |
|
2276 | 2365 | } |
2277 | 2366 | |
2278 | 2367 | // Are there also literal names set? |
@@ -2286,10 +2375,11 @@ discard block |
||
2286 | 2375 | |
2287 | 2376 | foreach ($namedRecipientList[$recipientType] as $index => $recipient) |
2288 | 2377 | { |
2289 | - if (strlen(trim($recipient)) > 0) |
|
2290 | - $namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient))); |
|
2291 | - else |
|
2292 | - unset($namedRecipientList[$recipientType][$index]); |
|
2378 | + if (strlen(trim($recipient)) > 0) { |
|
2379 | + $namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient))); |
|
2380 | + } else { |
|
2381 | + unset($namedRecipientList[$recipientType][$index]); |
|
2382 | + } |
|
2293 | 2383 | } |
2294 | 2384 | |
2295 | 2385 | if (!empty($namedRecipientList[$recipientType])) |
@@ -2319,8 +2409,9 @@ discard block |
||
2319 | 2409 | } |
2320 | 2410 | |
2321 | 2411 | // Selected a recipient to be deleted? Remove them now. |
2322 | - if (!empty($_POST['delete_recipient'])) |
|
2323 | - $recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient'])); |
|
2412 | + if (!empty($_POST['delete_recipient'])) { |
|
2413 | + $recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient'])); |
|
2414 | + } |
|
2324 | 2415 | |
2325 | 2416 | // Make sure we don't include the same name twice |
2326 | 2417 | $recipientList[$recipientType] = array_unique($recipientList[$recipientType]); |
@@ -2330,8 +2421,9 @@ discard block |
||
2330 | 2421 | $is_recipient_change = !empty($_POST['delete_recipient']) || !empty($_POST['to_submit']) || !empty($_POST['bcc_submit']); |
2331 | 2422 | |
2332 | 2423 | // Check if there's at least one recipient. |
2333 | - if (empty($recipientList['to']) && empty($recipientList['bcc'])) |
|
2334 | - $post_errors[] = 'no_to'; |
|
2424 | + if (empty($recipientList['to']) && empty($recipientList['bcc'])) { |
|
2425 | + $post_errors[] = 'no_to'; |
|
2426 | + } |
|
2335 | 2427 | |
2336 | 2428 | // Make sure that we remove the members who did get it from the screen. |
2337 | 2429 | if (!$is_recipient_change) |
@@ -2345,28 +2437,31 @@ discard block |
||
2345 | 2437 | // Since we already have a post error, remove the previous one. |
2346 | 2438 | $post_errors = array_diff($post_errors, array('no_to')); |
2347 | 2439 | |
2348 | - foreach ($namesNotFound[$recipientType] as $name) |
|
2349 | - $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name); |
|
2440 | + foreach ($namesNotFound[$recipientType] as $name) { |
|
2441 | + $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name); |
|
2442 | + } |
|
2350 | 2443 | } |
2351 | 2444 | } |
2352 | 2445 | } |
2353 | 2446 | |
2354 | 2447 | // Did they make any mistakes? |
2355 | - if ($_REQUEST['subject'] == '') |
|
2356 | - $post_errors[] = 'no_subject'; |
|
2357 | - if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') |
|
2358 | - $post_errors[] = 'no_message'; |
|
2359 | - elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength']) |
|
2360 | - $post_errors[] = 'long_message'; |
|
2361 | - else |
|
2448 | + if ($_REQUEST['subject'] == '') { |
|
2449 | + $post_errors[] = 'no_subject'; |
|
2450 | + } |
|
2451 | + if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') { |
|
2452 | + $post_errors[] = 'no_message'; |
|
2453 | + } elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength']) { |
|
2454 | + $post_errors[] = 'long_message'; |
|
2455 | + } else |
|
2362 | 2456 | { |
2363 | 2457 | // Preparse the message. |
2364 | 2458 | $message = $_REQUEST['message']; |
2365 | 2459 | preparsecode($message); |
2366 | 2460 | |
2367 | 2461 | // Make sure there's still some content left without the tags. |
2368 | - if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false)) |
|
2369 | - $post_errors[] = 'no_message'; |
|
2462 | + if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false)) { |
|
2463 | + $post_errors[] = 'no_message'; |
|
2464 | + } |
|
2370 | 2465 | } |
2371 | 2466 | |
2372 | 2467 | // Wrong verification code? |
@@ -2378,13 +2473,15 @@ discard block |
||
2378 | 2473 | ); |
2379 | 2474 | $context['require_verification'] = create_control_verification($verificationOptions, true); |
2380 | 2475 | |
2381 | - if (is_array($context['require_verification'])) |
|
2382 | - $post_errors = array_merge($post_errors, $context['require_verification']); |
|
2476 | + if (is_array($context['require_verification'])) { |
|
2477 | + $post_errors = array_merge($post_errors, $context['require_verification']); |
|
2478 | + } |
|
2383 | 2479 | } |
2384 | 2480 | |
2385 | 2481 | // If they did, give a chance to make ammends. |
2386 | - if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml'])) |
|
2387 | - return messagePostError($post_errors, $namedRecipientList, $recipientList); |
|
2482 | + if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml'])) { |
|
2483 | + return messagePostError($post_errors, $namedRecipientList, $recipientList); |
|
2484 | + } |
|
2388 | 2485 | |
2389 | 2486 | // Want to take a second glance before you send? |
2390 | 2487 | if (isset($_REQUEST['preview'])) |
@@ -2415,8 +2512,9 @@ discard block |
||
2415 | 2512 | foreach ($namesNotFound as $recipientType => $names) |
2416 | 2513 | { |
2417 | 2514 | $post_errors[] = 'bad_' . $recipientType; |
2418 | - foreach ($names as $name) |
|
2419 | - $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name); |
|
2515 | + foreach ($names as $name) { |
|
2516 | + $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name); |
|
2517 | + } |
|
2420 | 2518 | } |
2421 | 2519 | |
2422 | 2520 | return messagePostError(array(), $namedRecipientList, $recipientList); |
@@ -2446,13 +2544,14 @@ discard block |
||
2446 | 2544 | checkSubmitOnce('check'); |
2447 | 2545 | |
2448 | 2546 | // Do the actual sending of the PM. |
2449 | - if (!empty($recipientList['to']) || !empty($recipientList['bcc'])) |
|
2450 | - $context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0); |
|
2451 | - else |
|
2452 | - $context['send_log'] = array( |
|
2547 | + if (!empty($recipientList['to']) || !empty($recipientList['bcc'])) { |
|
2548 | + $context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0); |
|
2549 | + } else { |
|
2550 | + $context['send_log'] = array( |
|
2453 | 2551 | 'sent' => array(), |
2454 | 2552 | 'failed' => array() |
2455 | 2553 | ); |
2554 | + } |
|
2456 | 2555 | |
2457 | 2556 | // Mark the message as "replied to". |
2458 | 2557 | if (!empty($context['send_log']['sent']) && !empty($_REQUEST['replied_to']) && isset($_REQUEST['f']) && $_REQUEST['f'] == 'inbox') |
@@ -2470,11 +2569,12 @@ discard block |
||
2470 | 2569 | } |
2471 | 2570 | |
2472 | 2571 | // If one or more of the recipient were invalid, go back to the post screen with the failed usernames. |
2473 | - if (!empty($context['send_log']['failed'])) |
|
2474 | - return messagePostError($post_errors, $namesNotFound, array( |
|
2572 | + if (!empty($context['send_log']['failed'])) { |
|
2573 | + return messagePostError($post_errors, $namesNotFound, array( |
|
2475 | 2574 | 'to' => array_intersect($recipientList['to'], $context['send_log']['failed']), |
2476 | 2575 | 'bcc' => array_intersect($recipientList['bcc'], $context['send_log']['failed']) |
2477 | 2576 | )); |
2577 | + } |
|
2478 | 2578 | |
2479 | 2579 | // Message sent successfully? |
2480 | 2580 | if (!empty($context['send_log']) && empty($context['send_log']['failed'])) |
@@ -2482,8 +2582,9 @@ discard block |
||
2482 | 2582 | $context['current_label_redirect'] = $context['current_label_redirect'] . ';done=sent'; |
2483 | 2583 | |
2484 | 2584 | // If we had a PM draft for this one, then its time to remove it since it was just sent |
2485 | - if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft'])) |
|
2486 | - DeleteDraft($_POST['id_pm_draft']); |
|
2585 | + if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft'])) { |
|
2586 | + DeleteDraft($_POST['id_pm_draft']); |
|
2587 | + } |
|
2487 | 2588 | } |
2488 | 2589 | |
2489 | 2590 | // Go back to the where they sent from, if possible... |
@@ -2498,24 +2599,28 @@ discard block |
||
2498 | 2599 | |
2499 | 2600 | checkSession('request'); |
2500 | 2601 | |
2501 | - if (isset($_REQUEST['del_selected'])) |
|
2502 | - $_REQUEST['pm_action'] = 'delete'; |
|
2602 | + if (isset($_REQUEST['del_selected'])) { |
|
2603 | + $_REQUEST['pm_action'] = 'delete'; |
|
2604 | + } |
|
2503 | 2605 | |
2504 | 2606 | if (isset($_REQUEST['pm_action']) && $_REQUEST['pm_action'] != '' && !empty($_REQUEST['pms']) && is_array($_REQUEST['pms'])) |
2505 | 2607 | { |
2506 | - foreach ($_REQUEST['pms'] as $pm) |
|
2507 | - $_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action']; |
|
2608 | + foreach ($_REQUEST['pms'] as $pm) { |
|
2609 | + $_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action']; |
|
2610 | + } |
|
2508 | 2611 | } |
2509 | 2612 | |
2510 | - if (empty($_REQUEST['pm_actions'])) |
|
2511 | - redirectexit($context['current_label_redirect']); |
|
2613 | + if (empty($_REQUEST['pm_actions'])) { |
|
2614 | + redirectexit($context['current_label_redirect']); |
|
2615 | + } |
|
2512 | 2616 | |
2513 | 2617 | // If we are in conversation, we may need to apply this to every message in the conversation. |
2514 | 2618 | if ($context['display_mode'] == 2 && isset($_REQUEST['conversation'])) |
2515 | 2619 | { |
2516 | 2620 | $id_pms = array(); |
2517 | - foreach ($_REQUEST['pm_actions'] as $pm => $dummy) |
|
2518 | - $id_pms[] = (int) $pm; |
|
2621 | + foreach ($_REQUEST['pm_actions'] as $pm => $dummy) { |
|
2622 | + $id_pms[] = (int) $pm; |
|
2623 | + } |
|
2519 | 2624 | |
2520 | 2625 | $request = $smcFunc['db_query']('', ' |
2521 | 2626 | SELECT id_pm_head, id_pm |
@@ -2526,8 +2631,9 @@ discard block |
||
2526 | 2631 | ) |
2527 | 2632 | ); |
2528 | 2633 | $pm_heads = array(); |
2529 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2530 | - $pm_heads[$row['id_pm_head']] = $row['id_pm']; |
|
2634 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2635 | + $pm_heads[$row['id_pm_head']] = $row['id_pm']; |
|
2636 | + } |
|
2531 | 2637 | $smcFunc['db_free_result']($request); |
2532 | 2638 | |
2533 | 2639 | $request = $smcFunc['db_query']('', ' |
@@ -2541,8 +2647,9 @@ discard block |
||
2541 | 2647 | // Copy the action from the single to PM to the others. |
2542 | 2648 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
2543 | 2649 | { |
2544 | - if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]])) |
|
2545 | - $_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]]; |
|
2650 | + if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]])) { |
|
2651 | + $_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]]; |
|
2652 | + } |
|
2546 | 2653 | } |
2547 | 2654 | $smcFunc['db_free_result']($request); |
2548 | 2655 | } |
@@ -2553,22 +2660,21 @@ discard block |
||
2553 | 2660 | $labels = array(); |
2554 | 2661 | foreach ($_REQUEST['pm_actions'] as $pm => $action) |
2555 | 2662 | { |
2556 | - if ($action === 'delete') |
|
2557 | - $to_delete[] = (int) $pm; |
|
2558 | - else |
|
2663 | + if ($action === 'delete') { |
|
2664 | + $to_delete[] = (int) $pm; |
|
2665 | + } else |
|
2559 | 2666 | { |
2560 | 2667 | if (substr($action, 0, 4) == 'add_') |
2561 | 2668 | { |
2562 | 2669 | $type = 'add'; |
2563 | 2670 | $action = substr($action, 4); |
2564 | - } |
|
2565 | - elseif (substr($action, 0, 4) == 'rem_') |
|
2671 | + } elseif (substr($action, 0, 4) == 'rem_') |
|
2566 | 2672 | { |
2567 | 2673 | $type = 'rem'; |
2568 | 2674 | $action = substr($action, 4); |
2675 | + } else { |
|
2676 | + $type = 'unk'; |
|
2569 | 2677 | } |
2570 | - else |
|
2571 | - $type = 'unk'; |
|
2572 | 2678 | |
2573 | 2679 | if ($action == '-1' || (int) $action > 0) |
2574 | 2680 | { |
@@ -2579,8 +2685,9 @@ discard block |
||
2579 | 2685 | } |
2580 | 2686 | |
2581 | 2687 | // Deleting, it looks like? |
2582 | - if (!empty($to_delete)) |
|
2583 | - deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']); |
|
2688 | + if (!empty($to_delete)) { |
|
2689 | + deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']); |
|
2690 | + } |
|
2584 | 2691 | |
2585 | 2692 | // Are we labeling anything? |
2586 | 2693 | if (!empty($to_label) && $context['folder'] == 'inbox') |
@@ -2646,8 +2753,7 @@ discard block |
||
2646 | 2753 | } |
2647 | 2754 | |
2648 | 2755 | $smcFunc['db_free_result']($request2); |
2649 | - } |
|
2650 | - elseif ($type == 'rem') |
|
2756 | + } elseif ($type == 'rem') |
|
2651 | 2757 | { |
2652 | 2758 | // If we're removing from the inbox, see if we have at least one other label. |
2653 | 2759 | // This query is faster than the one above |
@@ -2679,21 +2785,25 @@ discard block |
||
2679 | 2785 | if ($to_label[$row['id_pm']] != '-1') |
2680 | 2786 | { |
2681 | 2787 | // If this label is in the list and we're not adding it, remove it |
2682 | - if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add') |
|
2683 | - unset($labels[$to_label[$row['id_pm']]]); |
|
2684 | - else if ($type !== 'rem') |
|
2685 | - $labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']]; |
|
2788 | + if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add') { |
|
2789 | + unset($labels[$to_label[$row['id_pm']]]); |
|
2790 | + } else if ($type !== 'rem') { |
|
2791 | + $labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']]; |
|
2792 | + } |
|
2686 | 2793 | } |
2687 | 2794 | |
2688 | 2795 | // Removing all labels or just removing the inbox label |
2689 | - if ($type == 'rem' && empty($labels)) |
|
2690 | - $in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0); |
|
2796 | + if ($type == 'rem' && empty($labels)) { |
|
2797 | + $in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0); |
|
2798 | + } |
|
2691 | 2799 | // Adding new labels, but removing inbox and applying new ones |
2692 | - elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels)) |
|
2693 | - $in_inbox = 0; |
|
2800 | + elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels)) { |
|
2801 | + $in_inbox = 0; |
|
2802 | + } |
|
2694 | 2803 | // Just adding it to the inbox |
2695 | - else |
|
2696 | - $in_inbox = 1; |
|
2804 | + else { |
|
2805 | + $in_inbox = 1; |
|
2806 | + } |
|
2697 | 2807 | |
2698 | 2808 | // Are we adding it to or removing it from the inbox? |
2699 | 2809 | if ($in_inbox != $row['in_inbox']) |
@@ -2735,8 +2845,9 @@ discard block |
||
2735 | 2845 | if (!empty($labels_to_apply)) |
2736 | 2846 | { |
2737 | 2847 | $inserts = array(); |
2738 | - foreach ($labels_to_apply as $label) |
|
2739 | - $inserts[] = array($row['id_pm'], $label); |
|
2848 | + foreach ($labels_to_apply as $label) { |
|
2849 | + $inserts[] = array($row['id_pm'], $label); |
|
2850 | + } |
|
2740 | 2851 | |
2741 | 2852 | $smcFunc['db_insert']('', |
2742 | 2853 | '{db_prefix}pm_labeled_messages', |
@@ -2780,11 +2891,13 @@ discard block |
||
2780 | 2891 | checkSession('get'); |
2781 | 2892 | |
2782 | 2893 | // If all then delete all messages the user has. |
2783 | - if ($_REQUEST['f'] == 'all') |
|
2784 | - deleteMessages(null, null); |
|
2894 | + if ($_REQUEST['f'] == 'all') { |
|
2895 | + deleteMessages(null, null); |
|
2896 | + } |
|
2785 | 2897 | // Otherwise just the selected folder. |
2786 | - else |
|
2787 | - deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent'); |
|
2898 | + else { |
|
2899 | + deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent'); |
|
2900 | + } |
|
2788 | 2901 | |
2789 | 2902 | // Done... all gone. |
2790 | 2903 | redirectexit($context['current_label_redirect']); |
@@ -2821,8 +2934,9 @@ discard block |
||
2821 | 2934 | 'msgtime' => $deleteTime, |
2822 | 2935 | ) |
2823 | 2936 | ); |
2824 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
2825 | - $toDelete[] = $row[0]; |
|
2937 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
2938 | + $toDelete[] = $row[0]; |
|
2939 | + } |
|
2826 | 2940 | $smcFunc['db_free_result']($request); |
2827 | 2941 | |
2828 | 2942 | // Select all messages in their inbox older than $deleteTime. |
@@ -2839,8 +2953,9 @@ discard block |
||
2839 | 2953 | 'msgtime' => $deleteTime, |
2840 | 2954 | ) |
2841 | 2955 | ); |
2842 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2843 | - $toDelete[] = $row['id_pm']; |
|
2956 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2957 | + $toDelete[] = $row['id_pm']; |
|
2958 | + } |
|
2844 | 2959 | $smcFunc['db_free_result']($request); |
2845 | 2960 | |
2846 | 2961 | // Delete the actual messages. |
@@ -2871,26 +2986,29 @@ discard block |
||
2871 | 2986 | { |
2872 | 2987 | global $user_info, $smcFunc; |
2873 | 2988 | |
2874 | - if ($owner === null) |
|
2875 | - $owner = array($user_info['id']); |
|
2876 | - elseif (empty($owner)) |
|
2877 | - return; |
|
2878 | - elseif (!is_array($owner)) |
|
2879 | - $owner = array($owner); |
|
2989 | + if ($owner === null) { |
|
2990 | + $owner = array($user_info['id']); |
|
2991 | + } elseif (empty($owner)) { |
|
2992 | + return; |
|
2993 | + } elseif (!is_array($owner)) { |
|
2994 | + $owner = array($owner); |
|
2995 | + } |
|
2880 | 2996 | |
2881 | 2997 | if ($personal_messages !== null) |
2882 | 2998 | { |
2883 | - if (empty($personal_messages) || !is_array($personal_messages)) |
|
2884 | - return; |
|
2999 | + if (empty($personal_messages) || !is_array($personal_messages)) { |
|
3000 | + return; |
|
3001 | + } |
|
2885 | 3002 | |
2886 | - foreach ($personal_messages as $index => $delete_id) |
|
2887 | - $personal_messages[$index] = (int) $delete_id; |
|
3003 | + foreach ($personal_messages as $index => $delete_id) { |
|
3004 | + $personal_messages[$index] = (int) $delete_id; |
|
3005 | + } |
|
2888 | 3006 | |
2889 | 3007 | $where = ' |
2890 | 3008 | AND id_pm IN ({array_int:pm_list})'; |
3009 | + } else { |
|
3010 | + $where = ''; |
|
2891 | 3011 | } |
2892 | - else |
|
2893 | - $where = ''; |
|
2894 | 3012 | |
2895 | 3013 | if ($folder == 'sent' || $folder === null) |
2896 | 3014 | { |
@@ -2925,17 +3043,19 @@ discard block |
||
2925 | 3043 | // ...And update the statistics accordingly - now including unread messages!. |
2926 | 3044 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
2927 | 3045 | { |
2928 | - if ($row['is_read']) |
|
2929 | - updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'])); |
|
2930 | - else |
|
2931 | - 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'])); |
|
3046 | + if ($row['is_read']) { |
|
3047 | + updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'])); |
|
3048 | + } else { |
|
3049 | + 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'])); |
|
3050 | + } |
|
2932 | 3051 | |
2933 | 3052 | // If this is the current member we need to make their message count correct. |
2934 | 3053 | if ($user_info['id'] == $row['id_member']) |
2935 | 3054 | { |
2936 | 3055 | $user_info['messages'] -= $row['num_deleted_messages']; |
2937 | - if (!($row['is_read'])) |
|
2938 | - $user_info['unread_messages'] -= $row['num_deleted_messages']; |
|
3056 | + if (!($row['is_read'])) { |
|
3057 | + $user_info['unread_messages'] -= $row['num_deleted_messages']; |
|
3058 | + } |
|
2939 | 3059 | } |
2940 | 3060 | } |
2941 | 3061 | $smcFunc['db_free_result']($request); |
@@ -3003,8 +3123,9 @@ discard block |
||
3003 | 3123 | ) |
3004 | 3124 | ); |
3005 | 3125 | $remove_pms = array(); |
3006 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
3007 | - $remove_pms[] = $row['sender']; |
|
3126 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
3127 | + $remove_pms[] = $row['sender']; |
|
3128 | + } |
|
3008 | 3129 | $smcFunc['db_free_result']($request); |
3009 | 3130 | |
3010 | 3131 | if (!empty($remove_pms)) |
@@ -3049,8 +3170,9 @@ discard block |
||
3049 | 3170 | { |
3050 | 3171 | global $user_info, $context, $smcFunc; |
3051 | 3172 | |
3052 | - if ($owner === null) |
|
3053 | - $owner = $user_info['id']; |
|
3173 | + if ($owner === null) { |
|
3174 | + $owner = $user_info['id']; |
|
3175 | + } |
|
3054 | 3176 | |
3055 | 3177 | $in_inbox = ''; |
3056 | 3178 | |
@@ -3074,8 +3196,7 @@ discard block |
||
3074 | 3196 | } |
3075 | 3197 | |
3076 | 3198 | $smcFunc['db_free_result']($get_messages); |
3077 | - } |
|
3078 | - elseif ($label = '-1') |
|
3199 | + } elseif ($label = '-1') |
|
3079 | 3200 | { |
3080 | 3201 | // Marking all PMs in your inbox read |
3081 | 3202 | $in_inbox = ' |
@@ -3100,8 +3221,9 @@ discard block |
||
3100 | 3221 | { |
3101 | 3222 | if ($owner == $user_info['id']) |
3102 | 3223 | { |
3103 | - foreach ($context['labels'] as $label) |
|
3104 | - $context['labels'][(int) $label['id']]['unread_messages'] = 0; |
|
3224 | + foreach ($context['labels'] as $label) { |
|
3225 | + $context['labels'][(int) $label['id']]['unread_messages'] = 0; |
|
3226 | + } |
|
3105 | 3227 | } |
3106 | 3228 | |
3107 | 3229 | $result = $smcFunc['db_query']('', ' |
@@ -3121,8 +3243,9 @@ discard block |
||
3121 | 3243 | { |
3122 | 3244 | $total_unread += $row['num']; |
3123 | 3245 | |
3124 | - if ($owner != $user_info['id'] || empty($row['id_pm'])) |
|
3125 | - continue; |
|
3246 | + if ($owner != $user_info['id'] || empty($row['id_pm'])) { |
|
3247 | + continue; |
|
3248 | + } |
|
3126 | 3249 | |
3127 | 3250 | $this_labels = array(); |
3128 | 3251 | |
@@ -3146,11 +3269,13 @@ discard block |
||
3146 | 3269 | |
3147 | 3270 | $smcFunc['db_free_result']($result2); |
3148 | 3271 | |
3149 | - foreach ($this_labels as $this_label) |
|
3150 | - $context['labels'][$this_label]['unread_messages'] += $row['num']; |
|
3272 | + foreach ($this_labels as $this_label) { |
|
3273 | + $context['labels'][$this_label]['unread_messages'] += $row['num']; |
|
3274 | + } |
|
3151 | 3275 | |
3152 | - if ($row['in_inbox'] == 1) |
|
3153 | - $context['labels'][-1]['unread_messages'] += $row['num']; |
|
3276 | + if ($row['in_inbox'] == 1) { |
|
3277 | + $context['labels'][-1]['unread_messages'] += $row['num']; |
|
3278 | + } |
|
3154 | 3279 | } |
3155 | 3280 | $smcFunc['db_free_result']($result); |
3156 | 3281 | |
@@ -3159,8 +3284,9 @@ discard block |
||
3159 | 3284 | updateMemberData($owner, array('unread_messages' => $total_unread)); |
3160 | 3285 | |
3161 | 3286 | // If it was for the current member, reflect this in the $user_info array too. |
3162 | - if ($owner == $user_info['id']) |
|
3163 | - $user_info['unread_messages'] = $total_unread; |
|
3287 | + if ($owner == $user_info['id']) { |
|
3288 | + $user_info['unread_messages'] = $total_unread; |
|
3289 | + } |
|
3164 | 3290 | } |
3165 | 3291 | } |
3166 | 3292 | |
@@ -3188,8 +3314,9 @@ discard block |
||
3188 | 3314 | // Add all existing labels to the array to save, slashing them as necessary... |
3189 | 3315 | foreach ($context['labels'] as $label) |
3190 | 3316 | { |
3191 | - if ($label['id'] != -1) |
|
3192 | - $the_labels[$label['id']] = $label['name']; |
|
3317 | + if ($label['id'] != -1) { |
|
3318 | + $the_labels[$label['id']] = $label['name']; |
|
3319 | + } |
|
3193 | 3320 | } |
3194 | 3321 | |
3195 | 3322 | if (isset($_POST[$context['session_var']])) |
@@ -3208,8 +3335,9 @@ discard block |
||
3208 | 3335 | { |
3209 | 3336 | $_POST['label'] = strtr($smcFunc['htmlspecialchars'](trim($_POST['label'])), array(',' => ',')); |
3210 | 3337 | |
3211 | - if ($smcFunc['strlen']($_POST['label']) > 30) |
|
3212 | - $_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30); |
|
3338 | + if ($smcFunc['strlen']($_POST['label']) > 30) { |
|
3339 | + $_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30); |
|
3340 | + } |
|
3213 | 3341 | if ($_POST['label'] != '') |
3214 | 3342 | { |
3215 | 3343 | $the_labels[] = $_POST['label']; |
@@ -3230,23 +3358,24 @@ discard block |
||
3230 | 3358 | { |
3231 | 3359 | foreach ($the_labels as $id => $name) |
3232 | 3360 | { |
3233 | - if ($id == -1) |
|
3234 | - continue; |
|
3235 | - elseif (isset($_POST['label_name'][$id])) |
|
3361 | + if ($id == -1) { |
|
3362 | + continue; |
|
3363 | + } elseif (isset($_POST['label_name'][$id])) |
|
3236 | 3364 | { |
3237 | 3365 | $_POST['label_name'][$id] = trim(strtr($smcFunc['htmlspecialchars']($_POST['label_name'][$id]), array(',' => ','))); |
3238 | 3366 | |
3239 | - if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30) |
|
3240 | - $_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30); |
|
3367 | + if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30) { |
|
3368 | + $_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30); |
|
3369 | + } |
|
3241 | 3370 | if ($_POST['label_name'][$id] != '') |
3242 | 3371 | { |
3243 | 3372 | // Changing the name of this label? |
3244 | - if ($the_labels[$id] != $_POST['label_name'][$id]) |
|
3245 | - $label_updates[$id] = $_POST['label_name'][$id]; |
|
3373 | + if ($the_labels[$id] != $_POST['label_name'][$id]) { |
|
3374 | + $label_updates[$id] = $_POST['label_name'][$id]; |
|
3375 | + } |
|
3246 | 3376 | |
3247 | 3377 | $the_labels[(int) $id] = $_POST['label_name'][$id]; |
3248 | - } |
|
3249 | - else |
|
3378 | + } else |
|
3250 | 3379 | { |
3251 | 3380 | unset($the_labels[(int) $id]); |
3252 | 3381 | $labels_to_remove[] = $id; |
@@ -3260,8 +3389,9 @@ discard block |
||
3260 | 3389 | if (!empty($labels_to_add)) |
3261 | 3390 | { |
3262 | 3391 | $inserts = array(); |
3263 | - foreach ($labels_to_add AS $label) |
|
3264 | - $inserts[] = array($user_info['id'], $label); |
|
3392 | + foreach ($labels_to_add AS $label) { |
|
3393 | + $inserts[] = array($user_info['id'], $label); |
|
3394 | + } |
|
3265 | 3395 | |
3266 | 3396 | $smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array()); |
3267 | 3397 | } |
@@ -3351,8 +3481,9 @@ discard block |
||
3351 | 3481 | // Each action... |
3352 | 3482 | foreach ($rule['actions'] as $k2 => $action) |
3353 | 3483 | { |
3354 | - if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove)) |
|
3355 | - continue; |
|
3484 | + if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove)) { |
|
3485 | + continue; |
|
3486 | + } |
|
3356 | 3487 | |
3357 | 3488 | $rule_changes[] = $rule['id']; |
3358 | 3489 | |
@@ -3367,8 +3498,8 @@ discard block |
||
3367 | 3498 | { |
3368 | 3499 | $rule_changes = array_unique($rule_changes); |
3369 | 3500 | // Update/delete as appropriate. |
3370 | - foreach ($rule_changes as $k => $id) |
|
3371 | - if (!empty($context['rules'][$id]['actions'])) |
|
3501 | + foreach ($rule_changes as $k => $id) { |
|
3502 | + if (!empty($context['rules'][$id]['actions'])) |
|
3372 | 3503 | { |
3373 | 3504 | $smcFunc['db_query']('', ' |
3374 | 3505 | UPDATE {db_prefix}pm_rules |
@@ -3381,12 +3512,13 @@ discard block |
||
3381 | 3512 | 'actions' => $smcFunc['json_encode']($context['rules'][$id]['actions']), |
3382 | 3513 | ) |
3383 | 3514 | ); |
3515 | + } |
|
3384 | 3516 | unset($rule_changes[$k]); |
3385 | 3517 | } |
3386 | 3518 | |
3387 | 3519 | // Anything left here means it's lost all actions... |
3388 | - if (!empty($rule_changes)) |
|
3389 | - $smcFunc['db_query']('', ' |
|
3520 | + if (!empty($rule_changes)) { |
|
3521 | + $smcFunc['db_query']('', ' |
|
3390 | 3522 | DELETE FROM {db_prefix}pm_rules |
3391 | 3523 | WHERE id_rule IN ({array_int:rule_list}) |
3392 | 3524 | AND id_member = {int:current_member}', |
@@ -3395,6 +3527,7 @@ discard block |
||
3395 | 3527 | 'rule_list' => $rule_changes, |
3396 | 3528 | ) |
3397 | 3529 | ); |
3530 | + } |
|
3398 | 3531 | } |
3399 | 3532 | |
3400 | 3533 | // Make sure we're not caching this! |
@@ -3464,8 +3597,9 @@ discard block |
||
3464 | 3597 | // Save the fields. |
3465 | 3598 | saveProfileFields(); |
3466 | 3599 | |
3467 | - if (!empty($profile_vars)) |
|
3468 | - updateMemberData($user_info['id'], $profile_vars); |
|
3600 | + if (!empty($profile_vars)) { |
|
3601 | + updateMemberData($user_info['id'], $profile_vars); |
|
3602 | + } |
|
3469 | 3603 | } |
3470 | 3604 | |
3471 | 3605 | setupProfileContext( |
@@ -3490,13 +3624,15 @@ discard block |
||
3490 | 3624 | global $user_info, $language, $modSettings, $smcFunc; |
3491 | 3625 | |
3492 | 3626 | // Check that this feature is even enabled! |
3493 | - if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg'])) |
|
3494 | - fatal_lang_error('no_access', false); |
|
3627 | + if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg'])) { |
|
3628 | + fatal_lang_error('no_access', false); |
|
3629 | + } |
|
3495 | 3630 | |
3496 | 3631 | $pmsg = (int) $_REQUEST['pmsg']; |
3497 | 3632 | |
3498 | - if (!isAccessiblePM($pmsg, 'inbox')) |
|
3499 | - fatal_lang_error('no_access', false); |
|
3633 | + if (!isAccessiblePM($pmsg, 'inbox')) { |
|
3634 | + fatal_lang_error('no_access', false); |
|
3635 | + } |
|
3500 | 3636 | |
3501 | 3637 | $context['pm_id'] = $pmsg; |
3502 | 3638 | $context['page_title'] = $txt['pm_report_title']; |
@@ -3518,8 +3654,9 @@ discard block |
||
3518 | 3654 | ) |
3519 | 3655 | ); |
3520 | 3656 | $context['admins'] = array(); |
3521 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
3522 | - $context['admins'][$row['id_member']] = $row['real_name']; |
|
3657 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
3658 | + $context['admins'][$row['id_member']] = $row['real_name']; |
|
3659 | + } |
|
3523 | 3660 | $smcFunc['db_free_result']($request); |
3524 | 3661 | |
3525 | 3662 | // How many admins in total? |
@@ -3548,8 +3685,9 @@ discard block |
||
3548 | 3685 | ) |
3549 | 3686 | ); |
3550 | 3687 | // Can only be a hacker here! |
3551 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
3552 | - fatal_lang_error('no_access', false); |
|
3688 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
3689 | + fatal_lang_error('no_access', false); |
|
3690 | + } |
|
3553 | 3691 | list ($subject, $body, $time, $memberFromID, $memberFromName) = $smcFunc['db_fetch_row']($request); |
3554 | 3692 | $smcFunc['db_free_result']($request); |
3555 | 3693 | |
@@ -3573,15 +3711,17 @@ discard block |
||
3573 | 3711 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
3574 | 3712 | { |
3575 | 3713 | // If it's hidden still don't reveal their names - privacy after all ;) |
3576 | - if ($row['bcc']) |
|
3577 | - $hidden_recipients++; |
|
3578 | - else |
|
3579 | - $recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]'; |
|
3714 | + if ($row['bcc']) { |
|
3715 | + $hidden_recipients++; |
|
3716 | + } else { |
|
3717 | + $recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]'; |
|
3718 | + } |
|
3580 | 3719 | } |
3581 | 3720 | $smcFunc['db_free_result']($request); |
3582 | 3721 | |
3583 | - if ($hidden_recipients) |
|
3584 | - $recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients); |
|
3722 | + if ($hidden_recipients) { |
|
3723 | + $recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients); |
|
3724 | + } |
|
3585 | 3725 | |
3586 | 3726 | // Now let's get out and loop through the admins. |
3587 | 3727 | $request = $smcFunc['db_query']('', ' |
@@ -3597,8 +3737,9 @@ discard block |
||
3597 | 3737 | ); |
3598 | 3738 | |
3599 | 3739 | // Maybe we shouldn't advertise this? |
3600 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
3601 | - fatal_lang_error('no_access', false); |
|
3740 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
3741 | + fatal_lang_error('no_access', false); |
|
3742 | + } |
|
3602 | 3743 | |
3603 | 3744 | $memberFromName = un_htmlspecialchars($memberFromName); |
3604 | 3745 | |
@@ -3617,8 +3758,9 @@ discard block |
||
3617 | 3758 | // Make the body. |
3618 | 3759 | $report_body = str_replace(array('{REPORTER}', '{SENDER}'), array(un_htmlspecialchars($user_info['name']), $memberFromName), $txt['pm_report_pm_user_sent']); |
3619 | 3760 | $report_body .= "\n" . '[b]' . $_POST['reason'] . '[/b]' . "\n\n"; |
3620 | - if (!empty($recipients)) |
|
3621 | - $report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n"; |
|
3761 | + if (!empty($recipients)) { |
|
3762 | + $report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n"; |
|
3763 | + } |
|
3622 | 3764 | $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]'; |
3623 | 3765 | |
3624 | 3766 | // Plonk it in the array ;) |
@@ -3638,12 +3780,14 @@ discard block |
||
3638 | 3780 | $smcFunc['db_free_result']($request); |
3639 | 3781 | |
3640 | 3782 | // Send a different email for each language. |
3641 | - foreach ($messagesToSend as $lang => $message) |
|
3642 | - sendpm($message['recipients'], $message['subject'], $message['body']); |
|
3783 | + foreach ($messagesToSend as $lang => $message) { |
|
3784 | + sendpm($message['recipients'], $message['subject'], $message['body']); |
|
3785 | + } |
|
3643 | 3786 | |
3644 | 3787 | // Give the user their own language back! |
3645 | - if (!empty($modSettings['userLanguage'])) |
|
3646 | - loadLanguage('PersonalMessage', '', false); |
|
3788 | + if (!empty($modSettings['userLanguage'])) { |
|
3789 | + loadLanguage('PersonalMessage', '', false); |
|
3790 | + } |
|
3647 | 3791 | |
3648 | 3792 | // Leave them with a template. |
3649 | 3793 | $context['sub_template'] = 'report_message_complete'; |
@@ -3689,8 +3833,9 @@ discard block |
||
3689 | 3833 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
3690 | 3834 | { |
3691 | 3835 | // Hide hidden groups! |
3692 | - if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) |
|
3693 | - continue; |
|
3836 | + if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) { |
|
3837 | + continue; |
|
3838 | + } |
|
3694 | 3839 | |
3695 | 3840 | $context['groups'][$row['id_group']] = $row['group_name']; |
3696 | 3841 | } |
@@ -3716,9 +3861,10 @@ discard block |
||
3716 | 3861 | $context['rule'] = $context['rules'][$context['rid']]; |
3717 | 3862 | $members = array(); |
3718 | 3863 | // Need to get member names! |
3719 | - foreach ($context['rule']['criteria'] as $k => $criteria) |
|
3720 | - if ($criteria['t'] == 'mid' && !empty($criteria['v'])) |
|
3864 | + foreach ($context['rule']['criteria'] as $k => $criteria) { |
|
3865 | + if ($criteria['t'] == 'mid' && !empty($criteria['v'])) |
|
3721 | 3866 | $members[(int) $criteria['v']] = $k; |
3867 | + } |
|
3722 | 3868 | |
3723 | 3869 | if (!empty($members)) |
3724 | 3870 | { |
@@ -3730,19 +3876,20 @@ discard block |
||
3730 | 3876 | 'member_list' => array_keys($members), |
3731 | 3877 | ) |
3732 | 3878 | ); |
3733 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
3734 | - $context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name']; |
|
3879 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
3880 | + $context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name']; |
|
3881 | + } |
|
3735 | 3882 | $smcFunc['db_free_result']($request); |
3736 | 3883 | } |
3737 | - } |
|
3738 | - else |
|
3739 | - $context['rule'] = array( |
|
3884 | + } else { |
|
3885 | + $context['rule'] = array( |
|
3740 | 3886 | 'id' => '', |
3741 | 3887 | 'name' => '', |
3742 | 3888 | 'criteria' => array(), |
3743 | 3889 | 'actions' => array(), |
3744 | 3890 | 'logic' => 'and', |
3745 | 3891 | ); |
3892 | + } |
|
3746 | 3893 | } |
3747 | 3894 | // Saving? |
3748 | 3895 | elseif (isset($_GET['save'])) |
@@ -3752,22 +3899,25 @@ discard block |
||
3752 | 3899 | |
3753 | 3900 | // Name is easy! |
3754 | 3901 | $ruleName = $smcFunc['htmlspecialchars'](trim($_POST['rule_name'])); |
3755 | - if (empty($ruleName)) |
|
3756 | - fatal_lang_error('pm_rule_no_name', false); |
|
3902 | + if (empty($ruleName)) { |
|
3903 | + fatal_lang_error('pm_rule_no_name', false); |
|
3904 | + } |
|
3757 | 3905 | |
3758 | 3906 | // Sanity check... |
3759 | - if (empty($_POST['ruletype']) || empty($_POST['acttype'])) |
|
3760 | - fatal_lang_error('pm_rule_no_criteria', false); |
|
3907 | + if (empty($_POST['ruletype']) || empty($_POST['acttype'])) { |
|
3908 | + fatal_lang_error('pm_rule_no_criteria', false); |
|
3909 | + } |
|
3761 | 3910 | |
3762 | 3911 | // Let's do the criteria first - it's also hardest! |
3763 | 3912 | $criteria = array(); |
3764 | 3913 | foreach ($_POST['ruletype'] as $ind => $type) |
3765 | 3914 | { |
3766 | 3915 | // Check everything is here... |
3767 | - if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]]))) |
|
3768 | - continue; |
|
3769 | - elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind])) |
|
3770 | - continue; |
|
3916 | + if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]]))) { |
|
3917 | + continue; |
|
3918 | + } elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind])) { |
|
3919 | + continue; |
|
3920 | + } |
|
3771 | 3921 | |
3772 | 3922 | // Members need to be found. |
3773 | 3923 | if ($type == 'mid') |
@@ -3791,13 +3941,13 @@ discard block |
||
3791 | 3941 | $smcFunc['db_free_result']($request); |
3792 | 3942 | |
3793 | 3943 | $criteria[] = array('t' => 'mid', 'v' => $memID); |
3944 | + } elseif ($type == 'bud') { |
|
3945 | + $criteria[] = array('t' => 'bud', 'v' => 1); |
|
3946 | + } elseif ($type == 'gid') { |
|
3947 | + $criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]); |
|
3948 | + } elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') { |
|
3949 | + $criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind]))); |
|
3794 | 3950 | } |
3795 | - elseif ($type == 'bud') |
|
3796 | - $criteria[] = array('t' => 'bud', 'v' => 1); |
|
3797 | - elseif ($type == 'gid') |
|
3798 | - $criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]); |
|
3799 | - elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') |
|
3800 | - $criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind]))); |
|
3801 | 3951 | } |
3802 | 3952 | |
3803 | 3953 | // Also do the actions! |
@@ -3807,26 +3957,29 @@ discard block |
||
3807 | 3957 | foreach ($_POST['acttype'] as $ind => $type) |
3808 | 3958 | { |
3809 | 3959 | // Picking a valid label? |
3810 | - if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]]))) |
|
3811 | - continue; |
|
3960 | + if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]]))) { |
|
3961 | + continue; |
|
3962 | + } |
|
3812 | 3963 | |
3813 | 3964 | // Record what we're doing. |
3814 | - if ($type == 'del') |
|
3815 | - $doDelete = 1; |
|
3816 | - elseif ($type == 'lab') |
|
3817 | - $actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]); |
|
3965 | + if ($type == 'del') { |
|
3966 | + $doDelete = 1; |
|
3967 | + } elseif ($type == 'lab') { |
|
3968 | + $actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]); |
|
3969 | + } |
|
3818 | 3970 | } |
3819 | 3971 | |
3820 | - if (empty($criteria) || (empty($actions) && !$doDelete)) |
|
3821 | - fatal_lang_error('pm_rule_no_criteria', false); |
|
3972 | + if (empty($criteria) || (empty($actions) && !$doDelete)) { |
|
3973 | + fatal_lang_error('pm_rule_no_criteria', false); |
|
3974 | + } |
|
3822 | 3975 | |
3823 | 3976 | // What are we storing? |
3824 | 3977 | $criteria = $smcFunc['json_encode']($criteria); |
3825 | 3978 | $actions = $smcFunc['json_encode']($actions); |
3826 | 3979 | |
3827 | 3980 | // Create the rule? |
3828 | - if (empty($context['rid'])) |
|
3829 | - $smcFunc['db_insert']('', |
|
3981 | + if (empty($context['rid'])) { |
|
3982 | + $smcFunc['db_insert']('', |
|
3830 | 3983 | '{db_prefix}pm_rules', |
3831 | 3984 | array( |
3832 | 3985 | 'id_member' => 'int', 'rule_name' => 'string', 'criteria' => 'string', 'actions' => 'string', |
@@ -3837,8 +3990,8 @@ discard block |
||
3837 | 3990 | ), |
3838 | 3991 | array('id_rule') |
3839 | 3992 | ); |
3840 | - else |
|
3841 | - $smcFunc['db_query']('', ' |
|
3993 | + } else { |
|
3994 | + $smcFunc['db_query']('', ' |
|
3842 | 3995 | UPDATE {db_prefix}pm_rules |
3843 | 3996 | SET rule_name = {string:rule_name}, criteria = {string:criteria}, actions = {string:actions}, |
3844 | 3997 | delete_pm = {int:delete_pm}, is_or = {int:is_or} |
@@ -3854,6 +4007,7 @@ discard block |
||
3854 | 4007 | 'actions' => $actions, |
3855 | 4008 | ) |
3856 | 4009 | ); |
4010 | + } |
|
3857 | 4011 | |
3858 | 4012 | redirectexit('action=pm;sa=manrules'); |
3859 | 4013 | } |
@@ -3862,11 +4016,12 @@ discard block |
||
3862 | 4016 | { |
3863 | 4017 | checkSession(); |
3864 | 4018 | $toDelete = array(); |
3865 | - foreach ($_POST['delrule'] as $k => $v) |
|
3866 | - $toDelete[] = (int) $k; |
|
4019 | + foreach ($_POST['delrule'] as $k => $v) { |
|
4020 | + $toDelete[] = (int) $k; |
|
4021 | + } |
|
3867 | 4022 | |
3868 | - if (!empty($toDelete)) |
|
3869 | - $smcFunc['db_query']('', ' |
|
4023 | + if (!empty($toDelete)) { |
|
4024 | + $smcFunc['db_query']('', ' |
|
3870 | 4025 | DELETE FROM {db_prefix}pm_rules |
3871 | 4026 | WHERE id_rule IN ({array_int:delete_list}) |
3872 | 4027 | AND id_member = {int:current_member}', |
@@ -3875,6 +4030,7 @@ discard block |
||
3875 | 4030 | 'delete_list' => $toDelete, |
3876 | 4031 | ) |
3877 | 4032 | ); |
4033 | + } |
|
3878 | 4034 | |
3879 | 4035 | redirectexit('action=pm;sa=manrules'); |
3880 | 4036 | } |
@@ -3893,8 +4049,9 @@ discard block |
||
3893 | 4049 | loadRules(); |
3894 | 4050 | |
3895 | 4051 | // No rules? |
3896 | - if (empty($context['rules'])) |
|
3897 | - return; |
|
4052 | + if (empty($context['rules'])) { |
|
4053 | + return; |
|
4054 | + } |
|
3898 | 4055 | |
3899 | 4056 | // Just unread ones? |
3900 | 4057 | $ruleQuery = $all_messages ? '' : ' AND pmr.is_new = 1'; |
@@ -3924,8 +4081,9 @@ discard block |
||
3924 | 4081 | // Loop through all the criteria hoping to make a match. |
3925 | 4082 | foreach ($rule['criteria'] as $criterium) |
3926 | 4083 | { |
3927 | - 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)) |
|
3928 | - $match = true; |
|
4084 | + 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)) { |
|
4085 | + $match = true; |
|
4086 | + } |
|
3929 | 4087 | // If we're adding and one criteria don't match then we stop! |
3930 | 4088 | elseif ($rule['logic'] == 'and') |
3931 | 4089 | { |
@@ -3937,17 +4095,18 @@ discard block |
||
3937 | 4095 | // If we have a match the rule must be true - act! |
3938 | 4096 | if ($match) |
3939 | 4097 | { |
3940 | - if ($rule['delete']) |
|
3941 | - $actions['deletes'][] = $row['id_pm']; |
|
3942 | - else |
|
4098 | + if ($rule['delete']) { |
|
4099 | + $actions['deletes'][] = $row['id_pm']; |
|
4100 | + } else |
|
3943 | 4101 | { |
3944 | 4102 | foreach ($rule['actions'] as $ruleAction) |
3945 | 4103 | { |
3946 | 4104 | if ($ruleAction['t'] == 'lab') |
3947 | 4105 | { |
3948 | 4106 | // Get a basic pot started! |
3949 | - if (!isset($actions['labels'][$row['id_pm']])) |
|
3950 | - $actions['labels'][$row['id_pm']] = array(); |
|
4107 | + if (!isset($actions['labels'][$row['id_pm']])) { |
|
4108 | + $actions['labels'][$row['id_pm']] = array(); |
|
4109 | + } |
|
3951 | 4110 | $actions['labels'][$row['id_pm']][] = $ruleAction['v']; |
3952 | 4111 | } |
3953 | 4112 | } |
@@ -3958,8 +4117,9 @@ discard block |
||
3958 | 4117 | $smcFunc['db_free_result']($request); |
3959 | 4118 | |
3960 | 4119 | // Deletes are easy! |
3961 | - if (!empty($actions['deletes'])) |
|
3962 | - deleteMessages($actions['deletes']); |
|
4120 | + if (!empty($actions['deletes'])) { |
|
4121 | + deleteMessages($actions['deletes']); |
|
4122 | + } |
|
3963 | 4123 | |
3964 | 4124 | // Relabel? |
3965 | 4125 | if (!empty($actions['labels'])) |
@@ -3986,8 +4146,7 @@ discard block |
||
3986 | 4146 | 'current_member' => $user_info['id'], |
3987 | 4147 | ) |
3988 | 4148 | ); |
3989 | - } |
|
3990 | - else |
|
4149 | + } else |
|
3991 | 4150 | { |
3992 | 4151 | $realLabels[] = $label['id']; |
3993 | 4152 | } |
@@ -3996,8 +4155,9 @@ discard block |
||
3996 | 4155 | |
3997 | 4156 | $inserts = array(); |
3998 | 4157 | // Now we insert the label info |
3999 | - foreach ($realLabels as $a_label) |
|
4000 | - $inserts[] = array($pm, $a_label); |
|
4158 | + foreach ($realLabels as $a_label) { |
|
4159 | + $inserts[] = array($pm, $a_label); |
|
4160 | + } |
|
4001 | 4161 | |
4002 | 4162 | $smcFunc['db_insert']('ignore', |
4003 | 4163 | '{db_prefix}pm_labeled_messages', |
@@ -4018,8 +4178,9 @@ discard block |
||
4018 | 4178 | { |
4019 | 4179 | global $user_info, $context, $smcFunc; |
4020 | 4180 | |
4021 | - if (isset($context['rules']) && !$reload) |
|
4022 | - return; |
|
4181 | + if (isset($context['rules']) && !$reload) { |
|
4182 | + return; |
|
4183 | + } |
|
4023 | 4184 | |
4024 | 4185 | $request = $smcFunc['db_query']('', ' |
4025 | 4186 | SELECT |
@@ -4043,8 +4204,9 @@ discard block |
||
4043 | 4204 | 'logic' => $row['is_or'] ? 'or' : 'and', |
4044 | 4205 | ); |
4045 | 4206 | |
4046 | - if ($row['delete_pm']) |
|
4047 | - $context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1); |
|
4207 | + if ($row['delete_pm']) { |
|
4208 | + $context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1); |
|
4209 | + } |
|
4048 | 4210 | } |
4049 | 4211 | $smcFunc['db_free_result']($request); |
4050 | 4212 | } |