@@ -16,8 +16,9 @@ discard block |
||
| 16 | 16 | * @version 2.1 Beta 3 |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | -if (!defined('SMF')) |
|
| 19 | +if (!defined('SMF')) { |
|
| 20 | 20 | die('No direct access...'); |
| 21 | +} |
|
| 21 | 22 | |
| 22 | 23 | |
| 23 | 24 | /** |
@@ -28,14 +29,16 @@ discard block |
||
| 28 | 29 | function sha1_smf($str) |
| 29 | 30 | { |
| 30 | 31 | // If we have mhash loaded in, use it instead! |
| 31 | - if (function_exists('mhash') && defined('MHASH_SHA1')) |
|
| 32 | - return bin2hex(mhash(MHASH_SHA1, $str)); |
|
| 32 | + if (function_exists('mhash') && defined('MHASH_SHA1')) { |
|
| 33 | + return bin2hex(mhash(MHASH_SHA1, $str)); |
|
| 34 | + } |
|
| 33 | 35 | |
| 34 | 36 | $nblk = (strlen($str) + 8 >> 6) + 1; |
| 35 | 37 | $blks = array_pad(array(), $nblk * 16, 0); |
| 36 | 38 | |
| 37 | - for ($i = 0; $i < strlen($str); $i++) |
|
| 38 | - $blks[$i >> 2] |= ord($str{$i}) << (24 - ($i % 4) * 8); |
|
| 39 | + for ($i = 0; $i < strlen($str); $i++) { |
|
| 40 | + $blks[$i >> 2] |= ord($str{$i}) << (24 - ($i % 4) * 8); |
|
| 41 | + } |
|
| 39 | 42 | |
| 40 | 43 | $blks[$i >> 2] |= 0x80 << (24 - ($i % 4) * 8); |
| 41 | 44 | |
@@ -70,10 +73,11 @@ discard block |
||
| 70 | 73 | |
| 71 | 74 | for ($j = 0; $j < 80; $j++) |
| 72 | 75 | { |
| 73 | - if ($j < 16) |
|
| 74 | - $w[$j] = isset($x[$i + $j]) ? $x[$i + $j] : 0; |
|
| 75 | - else |
|
| 76 | - $w[$j] = sha1_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1); |
|
| 76 | + if ($j < 16) { |
|
| 77 | + $w[$j] = isset($x[$i + $j]) ? $x[$i + $j] : 0; |
|
| 78 | + } else { |
|
| 79 | + $w[$j] = sha1_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1); |
|
| 80 | + } |
|
| 77 | 81 | |
| 78 | 82 | $t = sha1_rol($a, 5) + sha1_ft($j, $b, $c, $d) + $e + $w[$j] + sha1_kt($j); |
| 79 | 83 | $e = $d; |
@@ -103,12 +107,15 @@ discard block |
||
| 103 | 107 | */ |
| 104 | 108 | function sha1_ft($t, $b, $c, $d) |
| 105 | 109 | { |
| 106 | - if ($t < 20) |
|
| 107 | - return ($b & $c) | ((~$b) & $d); |
|
| 108 | - if ($t < 40) |
|
| 109 | - return $b ^ $c ^ $d; |
|
| 110 | - if ($t < 60) |
|
| 111 | - return ($b & $c) | ($b & $d) | ($c & $d); |
|
| 110 | + if ($t < 20) { |
|
| 111 | + return ($b & $c) | ((~$b) & $d); |
|
| 112 | + } |
|
| 113 | + if ($t < 40) { |
|
| 114 | + return $b ^ $c ^ $d; |
|
| 115 | + } |
|
| 116 | + if ($t < 60) { |
|
| 117 | + return ($b & $c) | ($b & $d) | ($c & $d); |
|
| 118 | + } |
|
| 112 | 119 | |
| 113 | 120 | return $b ^ $c ^ $d; |
| 114 | 121 | } |
@@ -132,10 +139,11 @@ discard block |
||
| 132 | 139 | function sha1_rol($num, $cnt) |
| 133 | 140 | { |
| 134 | 141 | // Unfortunately, PHP uses unsigned 32-bit longs only. So we have to kludge it a bit. |
| 135 | - if ($num & 0x80000000) |
|
| 136 | - $a = ($num >> 1 & 0x7fffffff) >> (31 - $cnt); |
|
| 137 | - else |
|
| 138 | - $a = $num >> (32 - $cnt); |
|
| 142 | + if ($num & 0x80000000) { |
|
| 143 | + $a = ($num >> 1 & 0x7fffffff) >> (31 - $cnt); |
|
| 144 | + } else { |
|
| 145 | + $a = $num >> (32 - $cnt); |
|
| 146 | + } |
|
| 139 | 147 | |
| 140 | 148 | return ($num << $cnt) | $a; |
| 141 | 149 | } |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Shows an avatar based on $_GET['attach'] |
@@ -35,11 +36,11 @@ discard block |
||
| 35 | 36 | |
| 36 | 37 | if (!empty($modSettings['enableCompressedOutput']) && !headers_sent() && ob_get_length() == 0) |
| 37 | 38 | { |
| 38 | - if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') |
|
| 39 | - $modSettings['enableCompressedOutput'] = 0; |
|
| 40 | - |
|
| 41 | - else |
|
| 42 | - ob_start('ob_gzhandler'); |
|
| 39 | + if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') { |
|
| 40 | + $modSettings['enableCompressedOutput'] = 0; |
|
| 41 | + } else { |
|
| 42 | + ob_start('ob_gzhandler'); |
|
| 43 | + } |
|
| 43 | 44 | } |
| 44 | 45 | |
| 45 | 46 | if (empty($modSettings['enableCompressedOutput'])) |
@@ -71,8 +72,9 @@ discard block |
||
| 71 | 72 | } |
| 72 | 73 | |
| 73 | 74 | // Use cache when possible. |
| 74 | - if (($cache = cache_get_data('attachment_lookup_id-'. $attachId)) != null) |
|
| 75 | - list($file, $thumbFile) = $cache; |
|
| 75 | + if (($cache = cache_get_data('attachment_lookup_id-'. $attachId)) != null) { |
|
| 76 | + list($file, $thumbFile) = $cache; |
|
| 77 | + } |
|
| 76 | 78 | |
| 77 | 79 | // Get the info from the DB. |
| 78 | 80 | if(empty($file) || empty($thumbFile) && !empty($file['id_thumb'])) |
@@ -80,10 +82,9 @@ discard block |
||
| 80 | 82 | // Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request. |
| 81 | 83 | $attachRequest = null; |
| 82 | 84 | call_integration_hook('integrate_download_request', array(&$attachRequest)); |
| 83 | - if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) |
|
| 84 | - $request = $attachRequest; |
|
| 85 | - |
|
| 86 | - else |
|
| 85 | + if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) { |
|
| 86 | + $request = $attachRequest; |
|
| 87 | + } else |
|
| 87 | 88 | { |
| 88 | 89 | // Make sure this attachment is on this board and load its info while we are at it. |
| 89 | 90 | $request = $smcFunc['db_query']('', ' |
@@ -176,13 +177,14 @@ discard block |
||
| 176 | 177 | } |
| 177 | 178 | |
| 178 | 179 | // Cache it. |
| 179 | - if(!empty($file) || !empty($thumbFile)) |
|
| 180 | - cache_put_data('attachment_lookup_id-'. $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900)); |
|
| 180 | + if(!empty($file) || !empty($thumbFile)) { |
|
| 181 | + cache_put_data('attachment_lookup_id-'. $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900)); |
|
| 182 | + } |
|
| 181 | 183 | } |
| 182 | 184 | |
| 183 | 185 | // Update the download counter (unless it's a thumbnail). |
| 184 | - if ($file['attachment_type'] != 3 && empty($showThumb)) |
|
| 185 | - $smcFunc['db_query']('attach_download_increase', ' |
|
| 186 | + if ($file['attachment_type'] != 3 && empty($showThumb)) { |
|
| 187 | + $smcFunc['db_query']('attach_download_increase', ' |
|
| 186 | 188 | UPDATE LOW_PRIORITY {db_prefix}attachments |
| 187 | 189 | SET downloads = downloads + 1 |
| 188 | 190 | WHERE id_attach = {int:id_attach}', |
@@ -190,10 +192,12 @@ discard block |
||
| 190 | 192 | 'id_attach' => $attachId, |
| 191 | 193 | ) |
| 192 | 194 | ); |
| 195 | + } |
|
| 193 | 196 | |
| 194 | 197 | // Replace the normal file with its thumbnail if it has one! |
| 195 | - if (!empty($showThumb) && !empty($thumbFile)) |
|
| 196 | - $file = $thumbFile; |
|
| 198 | + if (!empty($showThumb) && !empty($thumbFile)) { |
|
| 199 | + $file = $thumbFile; |
|
| 200 | + } |
|
| 197 | 201 | |
| 198 | 202 | // No point in a nicer message, because this is supposed to be an attachment anyway... |
| 199 | 203 | if (!file_exists($file['filePath'])) |
@@ -232,8 +236,9 @@ discard block |
||
| 232 | 236 | // Send the attachment headers. |
| 233 | 237 | header('Pragma: '); |
| 234 | 238 | |
| 235 | - if (!isBrowser('gecko')) |
|
| 236 | - header('Content-Transfer-Encoding: binary'); |
|
| 239 | + if (!isBrowser('gecko')) { |
|
| 240 | + header('Content-Transfer-Encoding: binary'); |
|
| 241 | + } |
|
| 237 | 242 | |
| 238 | 243 | header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT'); |
| 239 | 244 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($file['filePath'])) . ' GMT'); |
@@ -242,18 +247,19 @@ discard block |
||
| 242 | 247 | header('ETag: ' . $eTag); |
| 243 | 248 | |
| 244 | 249 | // Make sure the mime type warrants an inline display. |
| 245 | - if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) |
|
| 246 | - unset($_REQUEST['image']); |
|
| 250 | + if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) { |
|
| 251 | + unset($_REQUEST['image']); |
|
| 252 | + } |
|
| 247 | 253 | |
| 248 | 254 | // Does this have a mime type? |
| 249 | - elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) |
|
| 250 | - header('Content-Type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp'))); |
|
| 251 | - |
|
| 252 | - else |
|
| 255 | + elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) { |
|
| 256 | + header('Content-Type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp'))); |
|
| 257 | + } else |
|
| 253 | 258 | { |
| 254 | 259 | header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream')); |
| 255 | - if (isset($_REQUEST['image'])) |
|
| 256 | - unset($_REQUEST['image']); |
|
| 260 | + if (isset($_REQUEST['image'])) { |
|
| 261 | + unset($_REQUEST['image']); |
|
| 262 | + } |
|
| 257 | 263 | } |
| 258 | 264 | |
| 259 | 265 | // Convert the file to UTF-8, cuz most browsers dig that. |
@@ -261,24 +267,22 @@ discard block |
||
| 261 | 267 | $disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline'; |
| 262 | 268 | |
| 263 | 269 | // Different browsers like different standards... |
| 264 | - if (isBrowser('firefox')) |
|
| 265 | - header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
| 266 | - |
|
| 267 | - elseif (isBrowser('opera')) |
|
| 268 | - header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
| 269 | - |
|
| 270 | - elseif (isBrowser('ie')) |
|
| 271 | - header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
| 272 | - |
|
| 273 | - else |
|
| 274 | - header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
| 270 | + if (isBrowser('firefox')) { |
|
| 271 | + header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
| 272 | + } elseif (isBrowser('opera')) { |
|
| 273 | + header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
| 274 | + } elseif (isBrowser('ie')) { |
|
| 275 | + header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
| 276 | + } else { |
|
| 277 | + header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
| 278 | + } |
|
| 275 | 279 | |
| 276 | 280 | // If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE. |
| 277 | - if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) |
|
| 278 | - header('Cache-Control: no-cache'); |
|
| 279 | - |
|
| 280 | - else |
|
| 281 | - header('Cache-Control: max-age=' . (525600 * 60) . ', private'); |
|
| 281 | + if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) { |
|
| 282 | + header('Cache-Control: no-cache'); |
|
| 283 | + } else { |
|
| 284 | + header('Cache-Control: max-age=' . (525600 * 60) . ', private'); |
|
| 285 | + } |
|
| 282 | 286 | |
| 283 | 287 | header('Content-Length: ' . filesize($file['filePath'])); |
| 284 | 288 | |
@@ -288,20 +292,23 @@ discard block |
||
| 288 | 292 | // Recode line endings for text files, if enabled. |
| 289 | 293 | if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file['fileext'], array('txt', 'css', 'htm', 'html', 'php', 'xml'))) |
| 290 | 294 | { |
| 291 | - if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) |
|
| 292 | - $callback = function ($buffer) |
|
| 295 | + if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) { |
|
| 296 | + $callback = function ($buffer) |
|
| 293 | 297 | { |
| 294 | 298 | return preg_replace('~[\r]?\n~', "\r\n", $buffer); |
| 299 | + } |
|
| 295 | 300 | }; |
| 296 | - elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) |
|
| 297 | - $callback = function ($buffer) |
|
| 301 | + elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) { |
|
| 302 | + $callback = function ($buffer) |
|
| 298 | 303 | { |
| 299 | 304 | return preg_replace('~[\r]?\n~', "\r", $buffer); |
| 305 | + } |
|
| 300 | 306 | }; |
| 301 | - else |
|
| 302 | - $callback = function ($buffer) |
|
| 307 | + else { |
|
| 308 | + $callback = function ($buffer) |
|
| 303 | 309 | { |
| 304 | 310 | return preg_replace('~[\r]?\n~', "\n", $buffer); |
| 311 | + } |
|
| 305 | 312 | }; |
| 306 | 313 | } |
| 307 | 314 | |
@@ -309,8 +316,9 @@ discard block |
||
| 309 | 316 | if (filesize($file['filePath']) > 4194304) |
| 310 | 317 | { |
| 311 | 318 | // Forcibly end any output buffering going on. |
| 312 | - while (@ob_get_level() > 0) |
|
| 313 | - @ob_end_clean(); |
|
| 319 | + while (@ob_get_level() > 0) { |
|
| 320 | + @ob_end_clean(); |
|
| 321 | + } |
|
| 314 | 322 | |
| 315 | 323 | $fp = fopen($file['filePath'], 'rb'); |
| 316 | 324 | while (!feof($fp)) |
@@ -322,8 +330,9 @@ discard block |
||
| 322 | 330 | } |
| 323 | 331 | |
| 324 | 332 | // On some of the less-bright hosts, readfile() is disabled. It's just a faster, more byte safe, version of what's in the if. |
| 325 | - elseif (@readfile($file['filePath']) === null) |
|
| 326 | - echo file_get_contents($file['filePath']); |
|
| 333 | + elseif (@readfile($file['filePath']) === null) { |
|
| 334 | + echo file_get_contents($file['filePath']); |
|
| 335 | + } |
|
| 327 | 336 | |
| 328 | 337 | die(); |
| 329 | 338 | } |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 3 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * Check if the current directory is still valid or not. |
@@ -28,22 +29,24 @@ discard block |
||
| 28 | 29 | global $boarddir, $modSettings, $context; |
| 29 | 30 | |
| 30 | 31 | // Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found. |
| 31 | - if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') |
|
| 32 | - $doit = true; |
|
| 33 | - elseif (empty($modSettings['automanage_attachments'])) |
|
| 34 | - return; |
|
| 35 | - elseif (!isset($_FILES)) |
|
| 36 | - return; |
|
| 37 | - elseif (isset($_FILES['attachment'])) |
|
| 38 | - foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
| 32 | + if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') { |
|
| 33 | + $doit = true; |
|
| 34 | + } elseif (empty($modSettings['automanage_attachments'])) { |
|
| 35 | + return; |
|
| 36 | + } elseif (!isset($_FILES)) { |
|
| 37 | + return; |
|
| 38 | + } elseif (isset($_FILES['attachment'])) { |
|
| 39 | + foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
| 39 | 40 | if (!empty($dummy)) |
| 40 | 41 | { |
| 41 | 42 | $doit = true; |
| 43 | + } |
|
| 42 | 44 | break; |
| 43 | 45 | } |
| 44 | 46 | |
| 45 | - if (!isset($doit)) |
|
| 46 | - return; |
|
| 47 | + if (!isset($doit)) { |
|
| 48 | + return; |
|
| 49 | + } |
|
| 47 | 50 | |
| 48 | 51 | $year = date('Y'); |
| 49 | 52 | $month = date('m'); |
@@ -55,21 +58,25 @@ discard block |
||
| 55 | 58 | |
| 56 | 59 | if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments'])) |
| 57 | 60 | { |
| 58 | - if (!is_array($modSettings['attachment_basedirectories'])) |
|
| 59 | - $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 61 | + if (!is_array($modSettings['attachment_basedirectories'])) { |
|
| 62 | + $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 63 | + } |
|
| 60 | 64 | $base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']); |
| 65 | + } else { |
|
| 66 | + $base_dir = 0; |
|
| 61 | 67 | } |
| 62 | - else |
|
| 63 | - $base_dir = 0; |
|
| 64 | 68 | |
| 65 | 69 | if ($modSettings['automanage_attachments'] == 1) |
| 66 | 70 | { |
| 67 | - if (!isset($modSettings['last_attachments_directory'])) |
|
| 68 | - $modSettings['last_attachments_directory'] = array(); |
|
| 69 | - if (!is_array($modSettings['last_attachments_directory'])) |
|
| 70 | - $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
| 71 | - if (!isset($modSettings['last_attachments_directory'][$base_dir])) |
|
| 72 | - $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
| 71 | + if (!isset($modSettings['last_attachments_directory'])) { |
|
| 72 | + $modSettings['last_attachments_directory'] = array(); |
|
| 73 | + } |
|
| 74 | + if (!is_array($modSettings['last_attachments_directory'])) { |
|
| 75 | + $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
| 76 | + } |
|
| 77 | + if (!isset($modSettings['last_attachments_directory'][$base_dir])) { |
|
| 78 | + $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
| 79 | + } |
|
| 73 | 80 | } |
| 74 | 81 | |
| 75 | 82 | $basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
@@ -98,12 +105,14 @@ discard block |
||
| 98 | 105 | $updir = ''; |
| 99 | 106 | } |
| 100 | 107 | |
| 101 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
| 102 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 103 | - if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) |
|
| 104 | - $outputCreation = automanage_attachments_create_directory($updir); |
|
| 105 | - elseif (in_array($updir, $modSettings['attachmentUploadDir'])) |
|
| 106 | - $outputCreation = true; |
|
| 108 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
| 109 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 110 | + } |
|
| 111 | + if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) { |
|
| 112 | + $outputCreation = automanage_attachments_create_directory($updir); |
|
| 113 | + } elseif (in_array($updir, $modSettings['attachmentUploadDir'])) { |
|
| 114 | + $outputCreation = true; |
|
| 115 | + } |
|
| 107 | 116 | |
| 108 | 117 | if ($outputCreation) |
| 109 | 118 | { |
@@ -140,8 +149,9 @@ discard block |
||
| 140 | 149 | $count = count($tree); |
| 141 | 150 | |
| 142 | 151 | $directory = attachments_init_dir($tree, $count); |
| 143 | - if ($directory === false) |
|
| 144 | - return false; |
|
| 152 | + if ($directory === false) { |
|
| 153 | + return false; |
|
| 154 | + } |
|
| 145 | 155 | } |
| 146 | 156 | |
| 147 | 157 | $directory .= DIRECTORY_SEPARATOR . array_shift($tree); |
@@ -169,8 +179,9 @@ discard block |
||
| 169 | 179 | } |
| 170 | 180 | |
| 171 | 181 | // Everything seems fine...let's create the .htaccess |
| 172 | - if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) |
|
| 173 | - secureDirectory($updir, true); |
|
| 182 | + if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) { |
|
| 183 | + secureDirectory($updir, true); |
|
| 184 | + } |
|
| 174 | 185 | |
| 175 | 186 | $sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR; |
| 176 | 187 | $updir = rtrim($updir, $sep); |
@@ -202,8 +213,9 @@ discard block |
||
| 202 | 213 | { |
| 203 | 214 | global $modSettings, $boarddir; |
| 204 | 215 | |
| 205 | - if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) |
|
| 206 | - return; |
|
| 216 | + if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) { |
|
| 217 | + return; |
|
| 218 | + } |
|
| 207 | 219 | |
| 208 | 220 | $basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir; |
| 209 | 221 | // Just to be sure: I don't want directory separators at the end |
@@ -215,13 +227,14 @@ discard block |
||
| 215 | 227 | { |
| 216 | 228 | $base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']); |
| 217 | 229 | $base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0; |
| 230 | + } else { |
|
| 231 | + $base_dir = 0; |
|
| 218 | 232 | } |
| 219 | - else |
|
| 220 | - $base_dir = 0; |
|
| 221 | 233 | |
| 222 | 234 | // Get the last attachment directory for that base directory |
| 223 | - if (empty($modSettings['last_attachments_directory'][$base_dir])) |
|
| 224 | - $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
| 235 | + if (empty($modSettings['last_attachments_directory'][$base_dir])) { |
|
| 236 | + $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
| 237 | + } |
|
| 225 | 238 | // And increment it. |
| 226 | 239 | $modSettings['last_attachments_directory'][$base_dir]++; |
| 227 | 240 | |
@@ -236,10 +249,10 @@ discard block |
||
| 236 | 249 | $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
| 237 | 250 | |
| 238 | 251 | return true; |
| 252 | + } else { |
|
| 253 | + return false; |
|
| 254 | + } |
|
| 239 | 255 | } |
| 240 | - else |
|
| 241 | - return false; |
|
| 242 | -} |
|
| 243 | 256 | |
| 244 | 257 | /** |
| 245 | 258 | * Split a path into a list of all directories and subdirectories |
@@ -257,12 +270,13 @@ discard block |
||
| 257 | 270 | * in Windows we need to explode for both \ and / |
| 258 | 271 | * while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR) |
| 259 | 272 | */ |
| 260 | - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') |
|
| 261 | - $tree = preg_split('#[\\\/]#', $directory); |
|
| 262 | - else |
|
| 273 | + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
|
| 274 | + $tree = preg_split('#[\\\/]#', $directory); |
|
| 275 | + } else |
|
| 263 | 276 | { |
| 264 | - if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) |
|
| 265 | - return false; |
|
| 277 | + if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) { |
|
| 278 | + return false; |
|
| 279 | + } |
|
| 266 | 280 | |
| 267 | 281 | $tree = explode(DIRECTORY_SEPARATOR, trim($directory,DIRECTORY_SEPARATOR)); |
| 268 | 282 | } |
@@ -286,10 +300,11 @@ discard block |
||
| 286 | 300 | //Better be sure that the first part of the path is actually a drive letter... |
| 287 | 301 | //...even if, I should check this in the admin page...isn't it? |
| 288 | 302 | //...NHAAA Let's leave space for users' complains! :P |
| 289 | - if (preg_match('/^[a-z]:$/i',$tree[0])) |
|
| 290 | - $directory = array_shift($tree); |
|
| 291 | - else |
|
| 292 | - return false; |
|
| 303 | + if (preg_match('/^[a-z]:$/i',$tree[0])) { |
|
| 304 | + $directory = array_shift($tree); |
|
| 305 | + } else { |
|
| 306 | + return false; |
|
| 307 | + } |
|
| 293 | 308 | |
| 294 | 309 | $count--; |
| 295 | 310 | } |
@@ -304,18 +319,20 @@ discard block |
||
| 304 | 319 | global $context, $modSettings, $smcFunc, $txt, $user_info; |
| 305 | 320 | |
| 306 | 321 | // Make sure we're uploading to the right place. |
| 307 | - if (!empty($modSettings['automanage_attachments'])) |
|
| 308 | - automanage_attachments_check_directory(); |
|
| 322 | + if (!empty($modSettings['automanage_attachments'])) { |
|
| 323 | + automanage_attachments_check_directory(); |
|
| 324 | + } |
|
| 309 | 325 | |
| 310 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
| 311 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 326 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
| 327 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 328 | + } |
|
| 312 | 329 | |
| 313 | 330 | $context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
| 314 | 331 | |
| 315 | 332 | // Is the attachments folder actualy there? |
| 316 | - if (!empty($context['dir_creation_error'])) |
|
| 317 | - $initial_error = $context['dir_creation_error']; |
|
| 318 | - elseif (!is_dir($context['attach_dir'])) |
|
| 333 | + if (!empty($context['dir_creation_error'])) { |
|
| 334 | + $initial_error = $context['dir_creation_error']; |
|
| 335 | + } elseif (!is_dir($context['attach_dir'])) |
|
| 319 | 336 | { |
| 320 | 337 | $initial_error = 'attach_folder_warning'; |
| 321 | 338 | log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical'); |
@@ -338,12 +355,12 @@ discard block |
||
| 338 | 355 | ); |
| 339 | 356 | list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request); |
| 340 | 357 | $smcFunc['db_free_result']($request); |
| 341 | - } |
|
| 342 | - else |
|
| 343 | - $context['attachments'] = array( |
|
| 358 | + } else { |
|
| 359 | + $context['attachments'] = array( |
|
| 344 | 360 | 'quantity' => 0, |
| 345 | 361 | 'total_size' => 0, |
| 346 | 362 | ); |
| 363 | + } |
|
| 347 | 364 | } |
| 348 | 365 | |
| 349 | 366 | // Hmm. There are still files in session. |
@@ -353,39 +370,44 @@ discard block |
||
| 353 | 370 | // Let's try to keep them. But... |
| 354 | 371 | $ignore_temp = true; |
| 355 | 372 | // If new files are being added. We can't ignore those |
| 356 | - foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
| 357 | - if (!empty($dummy)) |
|
| 373 | + foreach ($_FILES['attachment']['tmp_name'] as $dummy) { |
|
| 374 | + if (!empty($dummy)) |
|
| 358 | 375 | { |
| 359 | 376 | $ignore_temp = false; |
| 377 | + } |
|
| 360 | 378 | break; |
| 361 | 379 | } |
| 362 | 380 | |
| 363 | 381 | // Need to make space for the new files. So, bye bye. |
| 364 | 382 | if (!$ignore_temp) |
| 365 | 383 | { |
| 366 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
| 367 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
| 384 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) { |
|
| 385 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
| 368 | 386 | unlink($attachment['tmp_name']); |
| 387 | + } |
|
| 369 | 388 | |
| 370 | 389 | $context['we_are_history'] = $txt['error_temp_attachments_flushed']; |
| 371 | 390 | $_SESSION['temp_attachments'] = array(); |
| 372 | 391 | } |
| 373 | 392 | } |
| 374 | 393 | |
| 375 | - if (!isset($_FILES['attachment']['name'])) |
|
| 376 | - $_FILES['attachment']['tmp_name'] = array(); |
|
| 394 | + if (!isset($_FILES['attachment']['name'])) { |
|
| 395 | + $_FILES['attachment']['tmp_name'] = array(); |
|
| 396 | + } |
|
| 377 | 397 | |
| 378 | - if (!isset($_SESSION['temp_attachments'])) |
|
| 379 | - $_SESSION['temp_attachments'] = array(); |
|
| 398 | + if (!isset($_SESSION['temp_attachments'])) { |
|
| 399 | + $_SESSION['temp_attachments'] = array(); |
|
| 400 | + } |
|
| 380 | 401 | |
| 381 | 402 | // Remember where we are at. If it's anywhere at all. |
| 382 | - if (!$ignore_temp) |
|
| 383 | - $_SESSION['temp_attachments']['post'] = array( |
|
| 403 | + if (!$ignore_temp) { |
|
| 404 | + $_SESSION['temp_attachments']['post'] = array( |
|
| 384 | 405 | 'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0, |
| 385 | 406 | 'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0, |
| 386 | 407 | 'topic' => !empty($topic) ? $topic : 0, |
| 387 | 408 | 'board' => !empty($board) ? $board : 0, |
| 388 | 409 | ); |
| 410 | + } |
|
| 389 | 411 | |
| 390 | 412 | // If we have an initial error, lets just display it. |
| 391 | 413 | if (!empty($initial_error)) |
@@ -393,9 +415,10 @@ discard block |
||
| 393 | 415 | $_SESSION['temp_attachments']['initial_error'] = $initial_error; |
| 394 | 416 | |
| 395 | 417 | // And delete the files 'cos they ain't going nowhere. |
| 396 | - foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
|
| 397 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 418 | + foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) { |
|
| 419 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 398 | 420 | unlink($_FILES['attachment']['tmp_name'][$n]); |
| 421 | + } |
|
| 399 | 422 | |
| 400 | 423 | $_FILES['attachment']['tmp_name'] = array(); |
| 401 | 424 | } |
@@ -403,21 +426,24 @@ discard block |
||
| 403 | 426 | // Loop through $_FILES['attachment'] array and move each file to the current attachments folder. |
| 404 | 427 | foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
| 405 | 428 | { |
| 406 | - if ($_FILES['attachment']['name'][$n] == '') |
|
| 407 | - continue; |
|
| 429 | + if ($_FILES['attachment']['name'][$n] == '') { |
|
| 430 | + continue; |
|
| 431 | + } |
|
| 408 | 432 | |
| 409 | 433 | // First, let's first check for PHP upload errors. |
| 410 | 434 | $errors = array(); |
| 411 | 435 | if (!empty($_FILES['attachment']['error'][$n])) |
| 412 | 436 | { |
| 413 | - if ($_FILES['attachment']['error'][$n] == 2) |
|
| 414 | - $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
| 415 | - elseif ($_FILES['attachment']['error'][$n] == 6) |
|
| 416 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
| 417 | - else |
|
| 418 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
| 419 | - if (empty($errors)) |
|
| 420 | - $errors[] = 'attach_php_error'; |
|
| 437 | + if ($_FILES['attachment']['error'][$n] == 2) { |
|
| 438 | + $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
| 439 | + } elseif ($_FILES['attachment']['error'][$n] == 6) { |
|
| 440 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
| 441 | + } else { |
|
| 442 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
| 443 | + } |
|
| 444 | + if (empty($errors)) { |
|
| 445 | + $errors[] = 'attach_php_error'; |
|
| 446 | + } |
|
| 421 | 447 | } |
| 422 | 448 | |
| 423 | 449 | // Try to move and rename the file before doing any more checks on it. |
@@ -435,16 +461,16 @@ discard block |
||
| 435 | 461 | ); |
| 436 | 462 | |
| 437 | 463 | // Move the file to the attachments folder with a temp name for now. |
| 438 | - if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) |
|
| 439 | - smf_chmod($destName, 0644); |
|
| 440 | - else |
|
| 464 | + if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) { |
|
| 465 | + smf_chmod($destName, 0644); |
|
| 466 | + } else |
|
| 441 | 467 | { |
| 442 | 468 | $_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout'; |
| 443 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 444 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 469 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
| 470 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 471 | + } |
|
| 445 | 472 | } |
| 446 | - } |
|
| 447 | - else |
|
| 473 | + } else |
|
| 448 | 474 | { |
| 449 | 475 | $_SESSION['temp_attachments'][$attachID] = array( |
| 450 | 476 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -452,12 +478,14 @@ discard block |
||
| 452 | 478 | 'errors' => $errors, |
| 453 | 479 | ); |
| 454 | 480 | |
| 455 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 456 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 481 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
| 482 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 483 | + } |
|
| 457 | 484 | } |
| 458 | 485 | // If there's no errors to this point. We still do need to apply some additional checks before we are finished. |
| 459 | - if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
|
| 460 | - attachmentChecks($attachID); |
|
| 486 | + if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) { |
|
| 487 | + attachmentChecks($attachID); |
|
| 488 | + } |
|
| 461 | 489 | } |
| 462 | 490 | // Mod authors, finally a hook to hang an alternate attachment upload system upon |
| 463 | 491 | // Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand()) |
@@ -484,21 +512,20 @@ discard block |
||
| 484 | 512 | global $modSettings, $context, $sourcedir, $smcFunc; |
| 485 | 513 | |
| 486 | 514 | // No data or missing data .... Not necessarily needed, but in case a mod author missed something. |
| 487 | - if ( empty($_SESSION['temp_attachments'][$attachID])) |
|
| 488 | - $error = '$_SESSION[\'temp_attachments\'][$attachID]'; |
|
| 489 | - |
|
| 490 | - elseif (empty($attachID)) |
|
| 491 | - $error = '$attachID'; |
|
| 492 | - |
|
| 493 | - elseif (empty($context['attachments'])) |
|
| 494 | - $error = '$context[\'attachments\']'; |
|
| 495 | - |
|
| 496 | - elseif (empty($context['attach_dir'])) |
|
| 497 | - $error = '$context[\'attach_dir\']'; |
|
| 515 | + if ( empty($_SESSION['temp_attachments'][$attachID])) { |
|
| 516 | + $error = '$_SESSION[\'temp_attachments\'][$attachID]'; |
|
| 517 | + } elseif (empty($attachID)) { |
|
| 518 | + $error = '$attachID'; |
|
| 519 | + } elseif (empty($context['attachments'])) { |
|
| 520 | + $error = '$context[\'attachments\']'; |
|
| 521 | + } elseif (empty($context['attach_dir'])) { |
|
| 522 | + $error = '$context[\'attach_dir\']'; |
|
| 523 | + } |
|
| 498 | 524 | |
| 499 | 525 | // Let's get their attention. |
| 500 | - if (!empty($error)) |
|
| 501 | - fatal_lang_error('attach_check_nag', 'debug', array($error)); |
|
| 526 | + if (!empty($error)) { |
|
| 527 | + fatal_lang_error('attach_check_nag', 'debug', array($error)); |
|
| 528 | + } |
|
| 502 | 529 | |
| 503 | 530 | // Just in case this slipped by the first checks, we stop it here and now |
| 504 | 531 | if ($_SESSION['temp_attachments'][$attachID]['size'] == 0) |
@@ -527,8 +554,9 @@ discard block |
||
| 527 | 554 | $size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']); |
| 528 | 555 | if (!(empty($size)) && ($size[2] != $old_format)) |
| 529 | 556 | { |
| 530 | - if (isset($context['validImageTypes'][$size[2]])) |
|
| 531 | - $_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
| 557 | + if (isset($context['validImageTypes'][$size[2]])) { |
|
| 558 | + $_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
| 559 | + } |
|
| 532 | 560 | } |
| 533 | 561 | } |
| 534 | 562 | } |
@@ -582,42 +610,48 @@ discard block |
||
| 582 | 610 | // Or, let the user know that it ain't gonna happen. |
| 583 | 611 | else |
| 584 | 612 | { |
| 585 | - if (isset($context['dir_creation_error'])) |
|
| 586 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error']; |
|
| 587 | - else |
|
| 588 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
| 613 | + if (isset($context['dir_creation_error'])) { |
|
| 614 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error']; |
|
| 615 | + } else { |
|
| 616 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
| 617 | + } |
|
| 589 | 618 | } |
| 619 | + } else { |
|
| 620 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
| 590 | 621 | } |
| 591 | - else |
|
| 592 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
| 593 | 622 | } |
| 594 | 623 | } |
| 595 | 624 | |
| 596 | 625 | // Is the file too big? |
| 597 | 626 | $context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size']; |
| 598 | - if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) |
|
| 599 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0))); |
|
| 627 | + if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) { |
|
| 628 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0))); |
|
| 629 | + } |
|
| 600 | 630 | |
| 601 | 631 | // Check the total upload size for this post... |
| 602 | - if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) |
|
| 603 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0))); |
|
| 632 | + if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) { |
|
| 633 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0))); |
|
| 634 | + } |
|
| 604 | 635 | |
| 605 | 636 | // Have we reached the maximum number of files we are allowed? |
| 606 | 637 | $context['attachments']['quantity']++; |
| 607 | 638 | |
| 608 | 639 | // Set a max limit if none exists |
| 609 | - if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) |
|
| 610 | - $modSettings['attachmentNumPerPostLimit'] = 50; |
|
| 640 | + if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) { |
|
| 641 | + $modSettings['attachmentNumPerPostLimit'] = 50; |
|
| 642 | + } |
|
| 611 | 643 | |
| 612 | - if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) |
|
| 613 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit'])); |
|
| 644 | + if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) { |
|
| 645 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit'])); |
|
| 646 | + } |
|
| 614 | 647 | |
| 615 | 648 | // File extension check |
| 616 | 649 | if (!empty($modSettings['attachmentCheckExtensions'])) |
| 617 | 650 | { |
| 618 | 651 | $allowed = explode(',', strtolower($modSettings['attachmentExtensions'])); |
| 619 | - foreach ($allowed as $k => $dummy) |
|
| 620 | - $allowed[$k] = trim($dummy); |
|
| 652 | + foreach ($allowed as $k => $dummy) { |
|
| 653 | + $allowed[$k] = trim($dummy); |
|
| 654 | + } |
|
| 621 | 655 | |
| 622 | 656 | if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed)) |
| 623 | 657 | { |
@@ -629,10 +663,12 @@ discard block |
||
| 629 | 663 | // Undo the math if there's an error |
| 630 | 664 | if (!empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
| 631 | 665 | { |
| 632 | - if (isset($context['dir_size'])) |
|
| 633 | - $context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
|
| 634 | - if (isset($context['dir_files'])) |
|
| 635 | - $context['dir_files']--; |
|
| 666 | + if (isset($context['dir_size'])) { |
|
| 667 | + $context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
|
| 668 | + } |
|
| 669 | + if (isset($context['dir_files'])) { |
|
| 670 | + $context['dir_files']--; |
|
| 671 | + } |
|
| 636 | 672 | $context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
| 637 | 673 | $context['attachments']['quantity']--; |
| 638 | 674 | return false; |
@@ -664,12 +700,14 @@ discard block |
||
| 664 | 700 | if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width']) |
| 665 | 701 | { |
| 666 | 702 | // Got a proper mime type? |
| 667 | - if (!empty($size['mime'])) |
|
| 668 | - $attachmentOptions['mime_type'] = $size['mime']; |
|
| 703 | + if (!empty($size['mime'])) { |
|
| 704 | + $attachmentOptions['mime_type'] = $size['mime']; |
|
| 705 | + } |
|
| 669 | 706 | |
| 670 | 707 | // Otherwise a valid one? |
| 671 | - elseif (isset($context['validImageTypes'][$size[2]])) |
|
| 672 | - $attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
| 708 | + elseif (isset($context['validImageTypes'][$size[2]])) { |
|
| 709 | + $attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
| 710 | + } |
|
| 673 | 711 | } |
| 674 | 712 | |
| 675 | 713 | // It is possible we might have a MIME type that isn't actually an image but still have a size. |
@@ -681,15 +719,17 @@ discard block |
||
| 681 | 719 | } |
| 682 | 720 | |
| 683 | 721 | // Get the hash if no hash has been given yet. |
| 684 | - if (empty($attachmentOptions['file_hash'])) |
|
| 685 | - $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true); |
|
| 722 | + if (empty($attachmentOptions['file_hash'])) { |
|
| 723 | + $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true); |
|
| 724 | + } |
|
| 686 | 725 | |
| 687 | 726 | // Assuming no-one set the extension let's take a look at it. |
| 688 | 727 | if (empty($attachmentOptions['fileext'])) |
| 689 | 728 | { |
| 690 | 729 | $attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : ''); |
| 691 | - if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) |
|
| 692 | - $attachmentOptions['fileext'] = ''; |
|
| 730 | + if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) { |
|
| 731 | + $attachmentOptions['fileext'] = ''; |
|
| 732 | + } |
|
| 693 | 733 | } |
| 694 | 734 | |
| 695 | 735 | // Last chance to change stuff! |
@@ -698,8 +738,9 @@ discard block |
||
| 698 | 738 | // Make sure the folder is valid... |
| 699 | 739 | $tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : smf_json_decode($modSettings['attachmentUploadDir'], true); |
| 700 | 740 | $folders = array_keys($tmp); |
| 701 | - if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) |
|
| 702 | - $attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir']; |
|
| 741 | + if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) { |
|
| 742 | + $attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir']; |
|
| 743 | + } |
|
| 703 | 744 | |
| 704 | 745 | $smcFunc['db_insert']('', |
| 705 | 746 | '{db_prefix}attachments', |
@@ -730,8 +771,8 @@ discard block |
||
| 730 | 771 | rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']); |
| 731 | 772 | |
| 732 | 773 | // If it's not approved then add to the approval queue. |
| 733 | - if (!$attachmentOptions['approved']) |
|
| 734 | - $smcFunc['db_insert']('', |
|
| 774 | + if (!$attachmentOptions['approved']) { |
|
| 775 | + $smcFunc['db_insert']('', |
|
| 735 | 776 | '{db_prefix}approval_queue', |
| 736 | 777 | array( |
| 737 | 778 | 'id_attach' => 'int', 'id_msg' => 'int', |
@@ -741,9 +782,11 @@ discard block |
||
| 741 | 782 | ), |
| 742 | 783 | array() |
| 743 | 784 | ); |
| 785 | + } |
|
| 744 | 786 | |
| 745 | - if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) |
|
| 746 | - return true; |
|
| 787 | + if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) { |
|
| 788 | + return true; |
|
| 789 | + } |
|
| 747 | 790 | |
| 748 | 791 | // Like thumbnails, do we? |
| 749 | 792 | if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight'])) |
@@ -754,13 +797,15 @@ discard block |
||
| 754 | 797 | $size = @getimagesize($attachmentOptions['destination'] . '_thumb'); |
| 755 | 798 | list ($thumb_width, $thumb_height) = $size; |
| 756 | 799 | |
| 757 | - if (!empty($size['mime'])) |
|
| 758 | - $thumb_mime = $size['mime']; |
|
| 759 | - elseif (isset($context['validImageTypes'][$size[2]])) |
|
| 760 | - $thumb_mime = 'image/' . $context['validImageTypes'][$size[2]]; |
|
| 800 | + if (!empty($size['mime'])) { |
|
| 801 | + $thumb_mime = $size['mime']; |
|
| 802 | + } elseif (isset($context['validImageTypes'][$size[2]])) { |
|
| 803 | + $thumb_mime = 'image/' . $context['validImageTypes'][$size[2]]; |
|
| 804 | + } |
|
| 761 | 805 | // Lord only knows how this happened... |
| 762 | - else |
|
| 763 | - $thumb_mime = ''; |
|
| 806 | + else { |
|
| 807 | + $thumb_mime = ''; |
|
| 808 | + } |
|
| 764 | 809 | |
| 765 | 810 | $thumb_filename = $attachmentOptions['name'] . '_thumb'; |
| 766 | 811 | $thumb_size = filesize($attachmentOptions['destination'] . '_thumb'); |
@@ -840,15 +885,17 @@ discard block |
||
| 840 | 885 | global $smcFunc; |
| 841 | 886 | |
| 842 | 887 | // Oh, come on! |
| 843 | - if (empty($attachIDs) || empty($msgID)) |
|
| 844 | - return false; |
|
| 888 | + if (empty($attachIDs) || empty($msgID)) { |
|
| 889 | + return false; |
|
| 890 | + } |
|
| 845 | 891 | |
| 846 | 892 | // "I see what is right and approve, but I do what is wrong." |
| 847 | 893 | call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID)); |
| 848 | 894 | |
| 849 | 895 | // One last check |
| 850 | - if (empty($attachIDs)) |
|
| 851 | - return false; |
|
| 896 | + if (empty($attachIDs)) { |
|
| 897 | + return false; |
|
| 898 | + } |
|
| 852 | 899 | |
| 853 | 900 | // Perform. |
| 854 | 901 | $smcFunc['db_query']('', ' |
@@ -880,8 +927,9 @@ discard block |
||
| 880 | 927 | $externalParse = false; |
| 881 | 928 | |
| 882 | 929 | // Meh... |
| 883 | - if (empty($attachID)) |
|
| 884 | - return 'attachments_no_data_loaded'; |
|
| 930 | + if (empty($attachID)) { |
|
| 931 | + return 'attachments_no_data_loaded'; |
|
| 932 | + } |
|
| 885 | 933 | |
| 886 | 934 | // Make it easy. |
| 887 | 935 | $msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0; |
@@ -890,20 +938,23 @@ discard block |
||
| 890 | 938 | $externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID)); |
| 891 | 939 | |
| 892 | 940 | // "I am innocent of the blood of this just person: see ye to it." |
| 893 | - if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) |
|
| 894 | - return $externalParse; |
|
| 941 | + if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) { |
|
| 942 | + return $externalParse; |
|
| 943 | + } |
|
| 895 | 944 | |
| 896 | 945 | //Are attachments enable? |
| 897 | - if (empty($modSettings['attachmentEnable'])) |
|
| 898 | - return 'attachments_not_enable'; |
|
| 946 | + if (empty($modSettings['attachmentEnable'])) { |
|
| 947 | + return 'attachments_not_enable'; |
|
| 948 | + } |
|
| 899 | 949 | |
| 900 | 950 | // Previewing much? no msg ID has been set yet. |
| 901 | 951 | if (!empty($context['preview_message'])) |
| 902 | 952 | { |
| 903 | 953 | $allAttachments = getAttachsByMsg(0); |
| 904 | 954 | |
| 905 | - if (empty($allAttachments[0][$attachID])) |
|
| 906 | - return 'attachments_no_data_loaded'; |
|
| 955 | + if (empty($allAttachments[0][$attachID])) { |
|
| 956 | + return 'attachments_no_data_loaded'; |
|
| 957 | + } |
|
| 907 | 958 | |
| 908 | 959 | $attachContext = $allAttachments[0][$attachID]; |
| 909 | 960 | $attachLoaded = loadAttachmentContext(0, $allAttachments); |
@@ -916,57 +967,66 @@ discard block |
||
| 916 | 967 | $attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID .';type=preview'. (empty($attachContext['is_image']) ? ';file' : '') .'">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>'; |
| 917 | 968 | |
| 918 | 969 | // Fix the thumbnail too, if the image has one. |
| 919 | - if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) |
|
| 920 | - $attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview'; |
|
| 970 | + if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) { |
|
| 971 | + $attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview'; |
|
| 972 | + } |
|
| 921 | 973 | |
| 922 | 974 | return $attachContext; |
| 923 | 975 | } |
| 924 | 976 | |
| 925 | 977 | // There is always the chance someone else has already done our dirty work... |
| 926 | 978 | // If so, all pertinent checks were already done. Hopefully... |
| 927 | - if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) |
|
| 928 | - return $context['current_attachments'][$attachID]; |
|
| 979 | + if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) { |
|
| 980 | + return $context['current_attachments'][$attachID]; |
|
| 981 | + } |
|
| 929 | 982 | |
| 930 | 983 | // If we are lucky enough to be in $board's scope then check it! |
| 931 | - if (!empty($board) && !allowedTo('view_attachments', $board)) |
|
| 932 | - return 'attachments_not_allowed_to_see'; |
|
| 984 | + if (!empty($board) && !allowedTo('view_attachments', $board)) { |
|
| 985 | + return 'attachments_not_allowed_to_see'; |
|
| 986 | + } |
|
| 933 | 987 | |
| 934 | 988 | // Get the message info associated with this particular attach ID. |
| 935 | 989 | $attachInfo = getAttachMsgInfo($attachID); |
| 936 | 990 | |
| 937 | 991 | // There is always the chance this attachment no longer exists or isn't associated to a message anymore... |
| 938 | - if (empty($attachInfo) || empty($attachInfo['msg'])) |
|
| 939 | - return 'attachments_no_msg_associated'; |
|
| 992 | + if (empty($attachInfo) || empty($attachInfo['msg'])) { |
|
| 993 | + return 'attachments_no_msg_associated'; |
|
| 994 | + } |
|
| 940 | 995 | |
| 941 | 996 | // Hold it! got the info now check if you can see this attachment. |
| 942 | - if (!allowedTo('view_attachments', $attachInfo['board'])) |
|
| 943 | - return 'attachments_not_allowed_to_see'; |
|
| 997 | + if (!allowedTo('view_attachments', $attachInfo['board'])) { |
|
| 998 | + return 'attachments_not_allowed_to_see'; |
|
| 999 | + } |
|
| 944 | 1000 | |
| 945 | 1001 | $allAttachments = getAttachsByMsg($attachInfo['msg']); |
| 946 | 1002 | $attachContext = $allAttachments[$attachInfo['msg']][$attachID]; |
| 947 | 1003 | |
| 948 | 1004 | // No point in keep going further. |
| 949 | - if (!allowedTo('view_attachments', $attachContext['board'])) |
|
| 950 | - return 'attachments_not_allowed_to_see'; |
|
| 1005 | + if (!allowedTo('view_attachments', $attachContext['board'])) { |
|
| 1006 | + return 'attachments_not_allowed_to_see'; |
|
| 1007 | + } |
|
| 951 | 1008 | |
| 952 | 1009 | // Load this particular attach's context. |
| 953 | - if (!empty($attachContext)) |
|
| 954 | - $attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments); |
|
| 1010 | + if (!empty($attachContext)) { |
|
| 1011 | + $attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments); |
|
| 1012 | + } |
|
| 955 | 1013 | |
| 956 | 1014 | // One last check, you know, gotta be paranoid... |
| 957 | - else |
|
| 958 | - return 'attachments_no_data_loaded'; |
|
| 1015 | + else { |
|
| 1016 | + return 'attachments_no_data_loaded'; |
|
| 1017 | + } |
|
| 959 | 1018 | |
| 960 | 1019 | // This is the last "if" I promise! |
| 961 | - if (empty($attachLoaded)) |
|
| 962 | - return 'attachments_no_data_loaded'; |
|
| 963 | - |
|
| 964 | - else |
|
| 965 | - $attachContext = $attachLoaded[$attachID]; |
|
| 1020 | + if (empty($attachLoaded)) { |
|
| 1021 | + return 'attachments_no_data_loaded'; |
|
| 1022 | + } else { |
|
| 1023 | + $attachContext = $attachLoaded[$attachID]; |
|
| 1024 | + } |
|
| 966 | 1025 | |
| 967 | 1026 | // You may or may not want to show this under the post. |
| 968 | - if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) |
|
| 969 | - $context['show_attach_under_post'][$attachID] = $attachID; |
|
| 1027 | + if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) { |
|
| 1028 | + $context['show_attach_under_post'][$attachID] = $attachID; |
|
| 1029 | + } |
|
| 970 | 1030 | |
| 971 | 1031 | // Last minute changes? |
| 972 | 1032 | call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext)); |
@@ -986,8 +1046,9 @@ discard block |
||
| 986 | 1046 | { |
| 987 | 1047 | global $smcFunc, $modSettings; |
| 988 | 1048 | |
| 989 | - if (empty($attachIDs)) |
|
| 990 | - return array(); |
|
| 1049 | + if (empty($attachIDs)) { |
|
| 1050 | + return array(); |
|
| 1051 | + } |
|
| 991 | 1052 | |
| 992 | 1053 | $return = array(); |
| 993 | 1054 | |
@@ -1003,11 +1064,12 @@ discard block |
||
| 1003 | 1064 | ) |
| 1004 | 1065 | ); |
| 1005 | 1066 | |
| 1006 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
| 1007 | - return array(); |
|
| 1067 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
| 1068 | + return array(); |
|
| 1069 | + } |
|
| 1008 | 1070 | |
| 1009 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1010 | - $return[$row['id_attach']] = array( |
|
| 1071 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1072 | + $return[$row['id_attach']] = array( |
|
| 1011 | 1073 | 'name' => $smcFunc['htmlspecialchars']($row['filename']), |
| 1012 | 1074 | 'size' => $row['size'], |
| 1013 | 1075 | 'attachID' => $row['id_attach'], |
@@ -1016,6 +1078,7 @@ discard block |
||
| 1016 | 1078 | 'mime_type' => $row['mime_type'], |
| 1017 | 1079 | 'thumb' => $row['id_thumb'], |
| 1018 | 1080 | ); |
| 1081 | + } |
|
| 1019 | 1082 | $smcFunc['db_free_result']($request); |
| 1020 | 1083 | |
| 1021 | 1084 | return $return; |
@@ -1032,8 +1095,9 @@ discard block |
||
| 1032 | 1095 | { |
| 1033 | 1096 | global $smcFunc; |
| 1034 | 1097 | |
| 1035 | - if (empty($attachID)) |
|
| 1036 | - return array(); |
|
| 1098 | + if (empty($attachID)) { |
|
| 1099 | + return array(); |
|
| 1100 | + } |
|
| 1037 | 1101 | |
| 1038 | 1102 | $request = $smcFunc['db_query']('', ' |
| 1039 | 1103 | SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board |
@@ -1046,8 +1110,9 @@ discard block |
||
| 1046 | 1110 | ) |
| 1047 | 1111 | ); |
| 1048 | 1112 | |
| 1049 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
| 1050 | - return array(); |
|
| 1113 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
| 1114 | + return array(); |
|
| 1115 | + } |
|
| 1051 | 1116 | |
| 1052 | 1117 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1053 | 1118 | $smcFunc['db_free_result']($request); |
@@ -1088,8 +1153,9 @@ discard block |
||
| 1088 | 1153 | $temp = array(); |
| 1089 | 1154 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1090 | 1155 | { |
| 1091 | - if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) |
|
| 1092 | - continue; |
|
| 1156 | + if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) { |
|
| 1157 | + continue; |
|
| 1158 | + } |
|
| 1093 | 1159 | |
| 1094 | 1160 | $temp[$row['id_attach']] = $row; |
| 1095 | 1161 | } |
@@ -1118,8 +1184,9 @@ discard block |
||
| 1118 | 1184 | { |
| 1119 | 1185 | global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc; |
| 1120 | 1186 | |
| 1121 | - if (empty($attachments) || empty($attachments[$id_msg])) |
|
| 1122 | - return array(); |
|
| 1187 | + if (empty($attachments) || empty($attachments[$id_msg])) { |
|
| 1188 | + return array(); |
|
| 1189 | + } |
|
| 1123 | 1190 | |
| 1124 | 1191 | // Set up the attachment info - based on code by Meriadoc. |
| 1125 | 1192 | $attachmentData = array(); |
@@ -1143,11 +1210,13 @@ discard block |
||
| 1143 | 1210 | ); |
| 1144 | 1211 | |
| 1145 | 1212 | // If something is unapproved we'll note it so we can sort them. |
| 1146 | - if (!$attachment['approved']) |
|
| 1147 | - $have_unapproved = true; |
|
| 1213 | + if (!$attachment['approved']) { |
|
| 1214 | + $have_unapproved = true; |
|
| 1215 | + } |
|
| 1148 | 1216 | |
| 1149 | - if (!$attachmentData[$i]['is_image']) |
|
| 1150 | - continue; |
|
| 1217 | + if (!$attachmentData[$i]['is_image']) { |
|
| 1218 | + continue; |
|
| 1219 | + } |
|
| 1151 | 1220 | |
| 1152 | 1221 | $attachmentData[$i]['real_width'] = $attachment['width']; |
| 1153 | 1222 | $attachmentData[$i]['width'] = $attachment['width']; |
@@ -1168,12 +1237,12 @@ discard block |
||
| 1168 | 1237 | // So what folder are we putting this image in? |
| 1169 | 1238 | if (!empty($modSettings['currentAttachmentUploadDir'])) |
| 1170 | 1239 | { |
| 1171 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
| 1172 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 1240 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
| 1241 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 1242 | + } |
|
| 1173 | 1243 | $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
| 1174 | 1244 | $id_folder_thumb = $modSettings['currentAttachmentUploadDir']; |
| 1175 | - } |
|
| 1176 | - else |
|
| 1245 | + } else |
|
| 1177 | 1246 | { |
| 1178 | 1247 | $path = $modSettings['attachmentUploadDir']; |
| 1179 | 1248 | $id_folder_thumb = 1; |
@@ -1188,10 +1257,11 @@ discard block |
||
| 1188 | 1257 | $thumb_ext = isset($context['validImageTypes'][$size[2]]) ? $context['validImageTypes'][$size[2]] : ''; |
| 1189 | 1258 | |
| 1190 | 1259 | // Figure out the mime type. |
| 1191 | - if (!empty($size['mime'])) |
|
| 1192 | - $thumb_mime = $size['mime']; |
|
| 1193 | - else |
|
| 1194 | - $thumb_mime = 'image/' . $thumb_ext; |
|
| 1260 | + if (!empty($size['mime'])) { |
|
| 1261 | + $thumb_mime = $size['mime']; |
|
| 1262 | + } else { |
|
| 1263 | + $thumb_mime = 'image/' . $thumb_ext; |
|
| 1264 | + } |
|
| 1195 | 1265 | |
| 1196 | 1266 | $thumb_filename = $attachment['filename'] . '_thumb'; |
| 1197 | 1267 | $thumb_hash = getAttachmentFilename($thumb_filename, false, null, true); |
@@ -1238,11 +1308,12 @@ discard block |
||
| 1238 | 1308 | } |
| 1239 | 1309 | } |
| 1240 | 1310 | |
| 1241 | - if (!empty($attachment['id_thumb'])) |
|
| 1242 | - $attachmentData[$i]['thumbnail'] = array( |
|
| 1311 | + if (!empty($attachment['id_thumb'])) { |
|
| 1312 | + $attachmentData[$i]['thumbnail'] = array( |
|
| 1243 | 1313 | 'id' => $attachment['id_thumb'], |
| 1244 | 1314 | 'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image', |
| 1245 | 1315 | ); |
| 1316 | + } |
|
| 1246 | 1317 | $attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']); |
| 1247 | 1318 | |
| 1248 | 1319 | // If thumbnails are disabled, check the maximum size of the image. |
@@ -1252,30 +1323,31 @@ discard block |
||
| 1252 | 1323 | { |
| 1253 | 1324 | $attachmentData[$i]['width'] = $modSettings['max_image_width']; |
| 1254 | 1325 | $attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']); |
| 1255 | - } |
|
| 1256 | - elseif (!empty($modSettings['max_image_width'])) |
|
| 1326 | + } elseif (!empty($modSettings['max_image_width'])) |
|
| 1257 | 1327 | { |
| 1258 | 1328 | $attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']); |
| 1259 | 1329 | $attachmentData[$i]['height'] = $modSettings['max_image_height']; |
| 1260 | 1330 | } |
| 1261 | - } |
|
| 1262 | - elseif ($attachmentData[$i]['thumbnail']['has_thumb']) |
|
| 1331 | + } elseif ($attachmentData[$i]['thumbnail']['has_thumb']) |
|
| 1263 | 1332 | { |
| 1264 | 1333 | // If the image is too large to show inline, make it a popup. |
| 1265 | - if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) |
|
| 1266 | - $attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);'; |
|
| 1267 | - else |
|
| 1268 | - $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');'; |
|
| 1334 | + if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) { |
|
| 1335 | + $attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);'; |
|
| 1336 | + } else { |
|
| 1337 | + $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');'; |
|
| 1338 | + } |
|
| 1269 | 1339 | } |
| 1270 | 1340 | |
| 1271 | - if (!$attachmentData[$i]['thumbnail']['has_thumb']) |
|
| 1272 | - $attachmentData[$i]['downloads']++; |
|
| 1341 | + if (!$attachmentData[$i]['thumbnail']['has_thumb']) { |
|
| 1342 | + $attachmentData[$i]['downloads']++; |
|
| 1343 | + } |
|
| 1273 | 1344 | } |
| 1274 | 1345 | } |
| 1275 | 1346 | |
| 1276 | 1347 | // Do we need to instigate a sort? |
| 1277 | - if ($have_unapproved) |
|
| 1278 | - usort($attachmentData, 'approved_attach_sort'); |
|
| 1348 | + if ($have_unapproved) { |
|
| 1349 | + usort($attachmentData, 'approved_attach_sort'); |
|
| 1350 | + } |
|
| 1279 | 1351 | |
| 1280 | 1352 | return $attachmentData; |
| 1281 | 1353 | } |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Scheduled tasks management dispatcher. This function checks permissions and delegates |
@@ -40,10 +41,11 @@ discard block |
||
| 40 | 41 | ); |
| 41 | 42 | |
| 42 | 43 | // We need to find what's the action. |
| 43 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
| 44 | - $context['sub_action'] = $_REQUEST['sa']; |
|
| 45 | - else |
|
| 46 | - $context['sub_action'] = 'tasks'; |
|
| 44 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
| 45 | + $context['sub_action'] = $_REQUEST['sa']; |
|
| 46 | + } else { |
|
| 47 | + $context['sub_action'] = 'tasks'; |
|
| 48 | + } |
|
| 47 | 49 | |
| 48 | 50 | // Now for the lovely tabs. That we all love. |
| 49 | 51 | $context[$context['admin_menu_name']]['tab_data'] = array( |
@@ -90,9 +92,10 @@ discard block |
||
| 90 | 92 | |
| 91 | 93 | // Enable and disable as required. |
| 92 | 94 | $enablers = array(0); |
| 93 | - foreach ($_POST['enable_task'] as $id => $enabled) |
|
| 94 | - if ($enabled) |
|
| 95 | + foreach ($_POST['enable_task'] as $id => $enabled) { |
|
| 96 | + if ($enabled) |
|
| 95 | 97 | $enablers[] = (int) $id; |
| 98 | + } |
|
| 96 | 99 | |
| 97 | 100 | // Do the update! |
| 98 | 101 | $smcFunc['db_query']('', ' |
@@ -130,8 +133,9 @@ discard block |
||
| 130 | 133 | |
| 131 | 134 | // Lets figure out which ones they want to run. |
| 132 | 135 | $tasks = array(); |
| 133 | - foreach ($_POST['run_task'] as $task => $dummy) |
|
| 134 | - $tasks[] = (int) $task; |
|
| 136 | + foreach ($_POST['run_task'] as $task => $dummy) { |
|
| 137 | + $tasks[] = (int) $task; |
|
| 138 | + } |
|
| 135 | 139 | |
| 136 | 140 | // Load up the tasks. |
| 137 | 141 | $request = $smcFunc['db_query']('', ' |
@@ -151,36 +155,41 @@ discard block |
||
| 151 | 155 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 152 | 156 | { |
| 153 | 157 | // What kind of task are we handling? |
| 154 | - if (!empty($row['callable'])) |
|
| 155 | - $task_string = $row['callable']; |
|
| 158 | + if (!empty($row['callable'])) { |
|
| 159 | + $task_string = $row['callable']; |
|
| 160 | + } |
|
| 156 | 161 | |
| 157 | 162 | // Default SMF task or old mods? |
| 158 | - elseif (function_exists('scheduled_' . $row['task'])) |
|
| 159 | - $task_string = 'scheduled_' . $row['task']; |
|
| 163 | + elseif (function_exists('scheduled_' . $row['task'])) { |
|
| 164 | + $task_string = 'scheduled_' . $row['task']; |
|
| 165 | + } |
|
| 160 | 166 | |
| 161 | 167 | // One last resource, the task name. |
| 162 | - elseif (!empty($row['task'])) |
|
| 163 | - $task_string = $row['task']; |
|
| 168 | + elseif (!empty($row['task'])) { |
|
| 169 | + $task_string = $row['task']; |
|
| 170 | + } |
|
| 164 | 171 | |
| 165 | 172 | $start_time = microtime(); |
| 166 | 173 | // The functions got to exist for us to use it. |
| 167 | - if (empty($task_string)) |
|
| 168 | - continue; |
|
| 174 | + if (empty($task_string)) { |
|
| 175 | + continue; |
|
| 176 | + } |
|
| 169 | 177 | |
| 170 | 178 | // Try to stop a timeout, this would be bad... |
| 171 | 179 | @set_time_limit(300); |
| 172 | - if (function_exists('apache_reset_timeout')) |
|
| 173 | - @apache_reset_timeout(); |
|
| 180 | + if (function_exists('apache_reset_timeout')) { |
|
| 181 | + @apache_reset_timeout(); |
|
| 182 | + } |
|
| 174 | 183 | |
| 175 | 184 | // Get the callable. |
| 176 | 185 | $callable_task = call_helper($task_string, true); |
| 177 | 186 | |
| 178 | 187 | // Perform the task. |
| 179 | - if (!empty($callable_task)) |
|
| 180 | - $completed = call_user_func($callable_task); |
|
| 181 | - |
|
| 182 | - else |
|
| 183 | - $completed = false; |
|
| 188 | + if (!empty($callable_task)) { |
|
| 189 | + $completed = call_user_func($callable_task); |
|
| 190 | + } else { |
|
| 191 | + $completed = false; |
|
| 192 | + } |
|
| 184 | 193 | |
| 185 | 194 | // Log that we did it ;) |
| 186 | 195 | if ($completed) |
@@ -197,8 +206,9 @@ discard block |
||
| 197 | 206 | $smcFunc['db_free_result']($request); |
| 198 | 207 | |
| 199 | 208 | // If we had any errors, push them to session so we can pick them up next time to tell the user. |
| 200 | - if (!empty($context['scheduled_errors'])) |
|
| 201 | - $_SESSION['st_error'] = $context['scheduled_errors']; |
|
| 209 | + if (!empty($context['scheduled_errors'])) { |
|
| 210 | + $_SESSION['st_error'] = $context['scheduled_errors']; |
|
| 211 | + } |
|
| 202 | 212 | |
| 203 | 213 | redirectexit('action=admin;area=scheduledtasks;done'); |
| 204 | 214 | } |
@@ -370,8 +380,9 @@ discard block |
||
| 370 | 380 | $context['server_time'] = timeformat(time(), false, 'server'); |
| 371 | 381 | |
| 372 | 382 | // Cleaning... |
| 373 | - if (!isset($_GET['tid'])) |
|
| 374 | - fatal_lang_error('no_access', false); |
|
| 383 | + if (!isset($_GET['tid'])) { |
|
| 384 | + fatal_lang_error('no_access', false); |
|
| 385 | + } |
|
| 375 | 386 | $_GET['tid'] = (int) $_GET['tid']; |
| 376 | 387 | |
| 377 | 388 | // Saving? |
@@ -387,10 +398,12 @@ discard block |
||
| 387 | 398 | preg_match('~(\d{1,2}):(\d{1,2})~', $_POST['offset'], $matches); |
| 388 | 399 | |
| 389 | 400 | // If a half is empty then assume zero offset! |
| 390 | - if (!isset($matches[2]) || $matches[2] > 59) |
|
| 391 | - $matches[2] = 0; |
|
| 392 | - if (!isset($matches[1]) || $matches[1] > 23) |
|
| 393 | - $matches[1] = 0; |
|
| 401 | + if (!isset($matches[2]) || $matches[2] > 59) { |
|
| 402 | + $matches[2] = 0; |
|
| 403 | + } |
|
| 404 | + if (!isset($matches[1]) || $matches[1] > 23) { |
|
| 405 | + $matches[1] = 0; |
|
| 406 | + } |
|
| 394 | 407 | |
| 395 | 408 | // Now the offset is easy; easy peasy - except we need to offset by a few hours... |
| 396 | 409 | $offset = $matches[1] * 3600 + $matches[2] * 60 - date('Z'); |
@@ -400,8 +413,9 @@ discard block |
||
| 400 | 413 | $unit = in_array(substr($_POST['unit'], 0, 1), array('m', 'h', 'd', 'w')) ? substr($_POST['unit'], 0, 1) : 'd'; |
| 401 | 414 | |
| 402 | 415 | // Don't allow one minute intervals. |
| 403 | - if ($interval == 1 && $unit == 'm') |
|
| 404 | - $interval = 2; |
|
| 416 | + if ($interval == 1 && $unit == 'm') { |
|
| 417 | + $interval = 2; |
|
| 418 | + } |
|
| 405 | 419 | |
| 406 | 420 | // Is it disabled? |
| 407 | 421 | $disabled = !isset($_POST['enabled']) ? 1 : 0; |
@@ -439,8 +453,9 @@ discard block |
||
| 439 | 453 | ); |
| 440 | 454 | |
| 441 | 455 | // Should never, ever, happen! |
| 442 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 443 | - fatal_lang_error('no_access', false); |
|
| 456 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 457 | + fatal_lang_error('no_access', false); |
|
| 458 | + } |
|
| 444 | 459 | |
| 445 | 460 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 446 | 461 | { |
@@ -598,13 +613,14 @@ discard block |
||
| 598 | 613 | ) |
| 599 | 614 | ); |
| 600 | 615 | $log_entries = array(); |
| 601 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 602 | - $log_entries[] = array( |
|
| 616 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 617 | + $log_entries[] = array( |
|
| 603 | 618 | 'id' => $row['id_log'], |
| 604 | 619 | 'name' => isset($txt['scheduled_task_' . $row['task']]) ? $txt['scheduled_task_' . $row['task']] : $row['task'], |
| 605 | 620 | 'time_run' => $row['time_run'], |
| 606 | 621 | 'time_taken' => $row['time_taken'], |
| 607 | 622 | ); |
| 623 | + } |
|
| 608 | 624 | $smcFunc['db_free_result']($request); |
| 609 | 625 | |
| 610 | 626 | return $log_entries; |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 3 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * !!!Compatibility!!! |
@@ -30,8 +31,9 @@ discard block |
||
| 30 | 31 | { |
| 31 | 32 | global $modSettings; |
| 32 | 33 | |
| 33 | - if (!$compat_mode) |
|
| 34 | - return $text; |
|
| 34 | + if (!$compat_mode) { |
|
| 35 | + return $text; |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | // Turn line breaks back into br's. |
| 37 | 39 | $text = strtr($text, array("\r" => '', "\n" => '<br>')); |
@@ -48,8 +50,9 @@ discard block |
||
| 48 | 50 | for ($i = 0, $n = count($parts); $i < $n; $i++) |
| 49 | 51 | { |
| 50 | 52 | // Value of 2 means we're inside the tag. |
| 51 | - if ($i % 4 == 2) |
|
| 52 | - $parts[$i] = strtr($parts[$i], array('[' => '[', ']' => ']', "'" => "'")); |
|
| 53 | + if ($i % 4 == 2) { |
|
| 54 | + $parts[$i] = strtr($parts[$i], array('[' => '[', ']' => ']', "'" => "'")); |
|
| 55 | + } |
|
| 53 | 56 | } |
| 54 | 57 | // Put our humpty dumpty message back together again. |
| 55 | 58 | $text = implode('', $parts); |
@@ -107,8 +110,9 @@ discard block |
||
| 107 | 110 | $text = preg_replace('~</p>\s*(?!<)~i', '</p><br>', $text); |
| 108 | 111 | |
| 109 | 112 | // Safari/webkit wraps lines in Wysiwyg in <div>'s. |
| 110 | - if (isBrowser('webkit')) |
|
| 111 | - $text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text); |
|
| 113 | + if (isBrowser('webkit')) { |
|
| 114 | + $text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text); |
|
| 115 | + } |
|
| 112 | 116 | |
| 113 | 117 | // If there's a trailing break get rid of it - Firefox tends to add one. |
| 114 | 118 | $text = preg_replace('~<br\s?/?' . '>$~i', '', $text); |
@@ -123,8 +127,9 @@ discard block |
||
| 123 | 127 | for ($i = 0, $n = count($parts); $i < $n; $i++) |
| 124 | 128 | { |
| 125 | 129 | // Value of 2 means we're inside the tag. |
| 126 | - if ($i % 4 == 2) |
|
| 127 | - $parts[$i] = strip_tags($parts[$i]); |
|
| 130 | + if ($i % 4 == 2) { |
|
| 131 | + $parts[$i] = strip_tags($parts[$i]); |
|
| 132 | + } |
|
| 128 | 133 | } |
| 129 | 134 | |
| 130 | 135 | $text = strtr(implode('', $parts), array('#smf_br_spec_grudge_cool!#' => '<br>')); |
@@ -150,18 +155,19 @@ discard block |
||
| 150 | 155 | { |
| 151 | 156 | $found = array_search($file, $smileysto); |
| 152 | 157 | // Note the weirdness here is to stop double spaces between smileys. |
| 153 | - if ($found) |
|
| 154 | - $matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#'; |
|
| 155 | - else |
|
| 156 | - $matches[1][$k] = ''; |
|
| 158 | + if ($found) { |
|
| 159 | + $matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#'; |
|
| 160 | + } else { |
|
| 161 | + $matches[1][$k] = ''; |
|
| 162 | + } |
|
| 157 | 163 | } |
| 158 | - } |
|
| 159 | - else |
|
| 164 | + } else |
|
| 160 | 165 | { |
| 161 | 166 | // Load all the smileys. |
| 162 | 167 | $names = array(); |
| 163 | - foreach ($matches[1] as $file) |
|
| 164 | - $names[] = $file; |
|
| 168 | + foreach ($matches[1] as $file) { |
|
| 169 | + $names[] = $file; |
|
| 170 | + } |
|
| 165 | 171 | $names = array_unique($names); |
| 166 | 172 | |
| 167 | 173 | if (!empty($names)) |
@@ -175,13 +181,15 @@ discard block |
||
| 175 | 181 | ) |
| 176 | 182 | ); |
| 177 | 183 | $mappings = array(); |
| 178 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 179 | - $mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']); |
|
| 184 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 185 | + $mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']); |
|
| 186 | + } |
|
| 180 | 187 | $smcFunc['db_free_result']($request); |
| 181 | 188 | |
| 182 | - foreach ($matches[1] as $k => $file) |
|
| 183 | - if (isset($mappings[$file])) |
|
| 189 | + foreach ($matches[1] as $k => $file) { |
|
| 190 | + if (isset($mappings[$file])) |
|
| 184 | 191 | $matches[1][$k] = '-[]-smf_smily_start#|#' . $mappings[$file] . '-[]-smf_smily_end#|#'; |
| 192 | + } |
|
| 185 | 193 | } |
| 186 | 194 | } |
| 187 | 195 | |
@@ -193,8 +201,9 @@ discard block |
||
| 193 | 201 | } |
| 194 | 202 | |
| 195 | 203 | // Only try to buy more time if the client didn't quit. |
| 196 | - if (connection_aborted() && $context['server']['is_apache']) |
|
| 197 | - @apache_reset_timeout(); |
|
| 204 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
| 205 | + @apache_reset_timeout(); |
|
| 206 | + } |
|
| 198 | 207 | |
| 199 | 208 | $parts = preg_split('~(<[A-Za-z]+\s*[^<>]*?style="?[^<>"]+"?[^<>]*?(?:/?)>|</[A-Za-z]+>)~', $text, -1, PREG_SPLIT_DELIM_CAPTURE); |
| 200 | 209 | $replacement = ''; |
@@ -205,9 +214,9 @@ discard block |
||
| 205 | 214 | if (preg_match('~(<([A-Za-z]+)\s*[^<>]*?)style="?([^<>"]+)"?([^<>]*?(/?)>)~', $part, $matches) === 1) |
| 206 | 215 | { |
| 207 | 216 | // If it's being closed instantly, we can't deal with it...yet. |
| 208 | - if ($matches[5] === '/') |
|
| 209 | - continue; |
|
| 210 | - else |
|
| 217 | + if ($matches[5] === '/') { |
|
| 218 | + continue; |
|
| 219 | + } else |
|
| 211 | 220 | { |
| 212 | 221 | // Get an array of styles that apply to this element. (The strtr is there to combat HTML generated by Word.) |
| 213 | 222 | $styles = explode(';', strtr($matches[3], array('"' => ''))); |
@@ -223,8 +232,9 @@ discard block |
||
| 223 | 232 | $clean_type_value_pair = strtolower(strtr(trim($type_value_pair), '=', ':')); |
| 224 | 233 | |
| 225 | 234 | // Something like 'font-weight: bold' is expected here. |
| 226 | - if (strpos($clean_type_value_pair, ':') === false) |
|
| 227 | - continue; |
|
| 235 | + if (strpos($clean_type_value_pair, ':') === false) { |
|
| 236 | + continue; |
|
| 237 | + } |
|
| 228 | 238 | |
| 229 | 239 | // Capture the elements of a single style item (e.g. 'font-weight' and 'bold'). |
| 230 | 240 | list ($style_type, $style_value) = explode(':', $type_value_pair); |
@@ -246,8 +256,7 @@ discard block |
||
| 246 | 256 | { |
| 247 | 257 | $curCloseTags .= '[/u]'; |
| 248 | 258 | $replacement .= '[u]'; |
| 249 | - } |
|
| 250 | - elseif ($style_value == 'line-through') |
|
| 259 | + } elseif ($style_value == 'line-through') |
|
| 251 | 260 | { |
| 252 | 261 | $curCloseTags .= '[/s]'; |
| 253 | 262 | $replacement .= '[s]'; |
@@ -259,13 +268,11 @@ discard block |
||
| 259 | 268 | { |
| 260 | 269 | $curCloseTags .= '[/left]'; |
| 261 | 270 | $replacement .= '[left]'; |
| 262 | - } |
|
| 263 | - elseif ($style_value == 'center') |
|
| 271 | + } elseif ($style_value == 'center') |
|
| 264 | 272 | { |
| 265 | 273 | $curCloseTags .= '[/center]'; |
| 266 | 274 | $replacement .= '[center]'; |
| 267 | - } |
|
| 268 | - elseif ($style_value == 'right') |
|
| 275 | + } elseif ($style_value == 'right') |
|
| 269 | 276 | { |
| 270 | 277 | $curCloseTags .= '[/right]'; |
| 271 | 278 | $replacement .= '[right]'; |
@@ -287,8 +294,9 @@ discard block |
||
| 287 | 294 | |
| 288 | 295 | case 'font-size': |
| 289 | 296 | // Sometimes people put decimals where decimals should not be. |
| 290 | - if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) |
|
| 291 | - $style_value = $dec_matches[1] . $dec_matches[2]; |
|
| 297 | + if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) { |
|
| 298 | + $style_value = $dec_matches[1] . $dec_matches[2]; |
|
| 299 | + } |
|
| 292 | 300 | |
| 293 | 301 | $curCloseTags .= '[/size]'; |
| 294 | 302 | $replacement .= '[size=' . $style_value . ']'; |
@@ -296,8 +304,9 @@ discard block |
||
| 296 | 304 | |
| 297 | 305 | case 'font-family': |
| 298 | 306 | // Only get the first freaking font if there's a list! |
| 299 | - if (strpos($style_value, ',') !== false) |
|
| 300 | - $style_value = substr($style_value, 0, strpos($style_value, ',')); |
|
| 307 | + if (strpos($style_value, ',') !== false) { |
|
| 308 | + $style_value = substr($style_value, 0, strpos($style_value, ',')); |
|
| 309 | + } |
|
| 301 | 310 | |
| 302 | 311 | $curCloseTags .= '[/font]'; |
| 303 | 312 | $replacement .= '[font=' . strtr($style_value, array("'" => '')) . ']'; |
@@ -306,13 +315,15 @@ discard block |
||
| 306 | 315 | // This is a hack for images with dimensions embedded. |
| 307 | 316 | case 'width': |
| 308 | 317 | case 'height': |
| 309 | - if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) |
|
| 310 | - $extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"'; |
|
| 318 | + if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) { |
|
| 319 | + $extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"'; |
|
| 320 | + } |
|
| 311 | 321 | break; |
| 312 | 322 | |
| 313 | 323 | case 'list-style-type': |
| 314 | - if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) |
|
| 315 | - $extra_attr .= ' listtype="' . $listType[0] . '"'; |
|
| 324 | + if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) { |
|
| 325 | + $extra_attr .= ' listtype="' . $listType[0] . '"'; |
|
| 326 | + } |
|
| 316 | 327 | break; |
| 317 | 328 | } |
| 318 | 329 | } |
@@ -325,18 +336,17 @@ discard block |
||
| 325 | 336 | } |
| 326 | 337 | |
| 327 | 338 | // If there's something that still needs closing, push it to the stack. |
| 328 | - if (!empty($curCloseTags)) |
|
| 329 | - array_push($stack, array( |
|
| 339 | + if (!empty($curCloseTags)) { |
|
| 340 | + array_push($stack, array( |
|
| 330 | 341 | 'element' => strtolower($curElement), |
| 331 | 342 | 'closeTags' => $curCloseTags |
| 332 | 343 | ) |
| 333 | 344 | ); |
| 334 | - elseif (!empty($extra_attr)) |
|
| 335 | - $replacement .= $precedingStyle . $extra_attr . $afterStyle; |
|
| 345 | + } elseif (!empty($extra_attr)) { |
|
| 346 | + $replacement .= $precedingStyle . $extra_attr . $afterStyle; |
|
| 347 | + } |
|
| 336 | 348 | } |
| 337 | - } |
|
| 338 | - |
|
| 339 | - elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1) |
|
| 349 | + } elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1) |
|
| 340 | 350 | { |
| 341 | 351 | // Is this the element that we've been waiting for to be closed? |
| 342 | 352 | if (!empty($stack) && strtolower($matches[1]) === $stack[count($stack) - 1]['element']) |
@@ -346,28 +356,32 @@ discard block |
||
| 346 | 356 | } |
| 347 | 357 | |
| 348 | 358 | // Must've been something else. |
| 349 | - else |
|
| 350 | - $replacement .= $part; |
|
| 359 | + else { |
|
| 360 | + $replacement .= $part; |
|
| 361 | + } |
|
| 351 | 362 | } |
| 352 | 363 | // In all other cases, just add the part to the replacement. |
| 353 | - else |
|
| 354 | - $replacement .= $part; |
|
| 364 | + else { |
|
| 365 | + $replacement .= $part; |
|
| 366 | + } |
|
| 355 | 367 | } |
| 356 | 368 | |
| 357 | 369 | // Now put back the replacement in the text. |
| 358 | 370 | $text = $replacement; |
| 359 | 371 | |
| 360 | 372 | // We are not finished yet, request more time. |
| 361 | - if (connection_aborted() && $context['server']['is_apache']) |
|
| 362 | - @apache_reset_timeout(); |
|
| 373 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
| 374 | + @apache_reset_timeout(); |
|
| 375 | + } |
|
| 363 | 376 | |
| 364 | 377 | // Let's pull out any legacy alignments. |
| 365 | 378 | while (preg_match('~<([A-Za-z]+)\s+[^<>]*?(align="*(left|center|right)"*)[^<>]*?(/?)>~i', $text, $matches) === 1) |
| 366 | 379 | { |
| 367 | 380 | // Find the position in the text of this tag over again. |
| 368 | 381 | $start_pos = strpos($text, $matches[0]); |
| 369 | - if ($start_pos === false) |
|
| 370 | - break; |
|
| 382 | + if ($start_pos === false) { |
|
| 383 | + break; |
|
| 384 | + } |
|
| 371 | 385 | |
| 372 | 386 | // End tag? |
| 373 | 387 | if ($matches[4] != '/' && strpos($text, '</' . $matches[1] . '>', $start_pos) !== false) |
@@ -382,8 +396,7 @@ discard block |
||
| 382 | 396 | |
| 383 | 397 | // Put the tags back into the body. |
| 384 | 398 | $text = substr($text, 0, $start_pos) . $tag . '[' . $matches[3] . ']' . $content . '[/' . $matches[3] . ']' . substr($text, $end_pos); |
| 385 | - } |
|
| 386 | - else |
|
| 399 | + } else |
|
| 387 | 400 | { |
| 388 | 401 | // Just get rid of this evil tag. |
| 389 | 402 | $text = substr($text, 0, $start_pos) . substr($text, $start_pos + strlen($matches[0])); |
@@ -396,8 +409,9 @@ discard block |
||
| 396 | 409 | // Find the position of this again. |
| 397 | 410 | $start_pos = strpos($text, $matches[0]); |
| 398 | 411 | $end_pos = false; |
| 399 | - if ($start_pos === false) |
|
| 400 | - break; |
|
| 412 | + if ($start_pos === false) { |
|
| 413 | + break; |
|
| 414 | + } |
|
| 401 | 415 | |
| 402 | 416 | // This must have an end tag - and we must find the right one. |
| 403 | 417 | $lower_text = strtolower($text); |
@@ -430,8 +444,9 @@ discard block |
||
| 430 | 444 | break; |
| 431 | 445 | } |
| 432 | 446 | } |
| 433 | - if ($end_pos === false) |
|
| 434 | - break; |
|
| 447 | + if ($end_pos === false) { |
|
| 448 | + break; |
|
| 449 | + } |
|
| 435 | 450 | |
| 436 | 451 | // Now work out what the attributes are. |
| 437 | 452 | $attribs = fetchTagAttributes($matches[1]); |
@@ -445,11 +460,11 @@ discard block |
||
| 445 | 460 | $v = (int) trim($v); |
| 446 | 461 | $v = empty($v) ? 1 : $v; |
| 447 | 462 | $tags[] = array('[size=' . $sizes_equivalence[$v] . ']', '[/size]'); |
| 463 | + } elseif ($s == 'face') { |
|
| 464 | + $tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]'); |
|
| 465 | + } elseif ($s == 'color') { |
|
| 466 | + $tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]'); |
|
| 448 | 467 | } |
| 449 | - elseif ($s == 'face') |
|
| 450 | - $tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]'); |
|
| 451 | - elseif ($s == 'color') |
|
| 452 | - $tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]'); |
|
| 453 | 468 | } |
| 454 | 469 | |
| 455 | 470 | // As before add in our tags. |
@@ -457,8 +472,9 @@ discard block |
||
| 457 | 472 | foreach ($tags as $tag) |
| 458 | 473 | { |
| 459 | 474 | $before .= $tag[0]; |
| 460 | - if (isset($tag[1])) |
|
| 461 | - $after = $tag[1] . $after; |
|
| 475 | + if (isset($tag[1])) { |
|
| 476 | + $after = $tag[1] . $after; |
|
| 477 | + } |
|
| 462 | 478 | } |
| 463 | 479 | |
| 464 | 480 | // Remove the tag so it's never checked again. |
@@ -469,8 +485,9 @@ discard block |
||
| 469 | 485 | } |
| 470 | 486 | |
| 471 | 487 | // Almost there, just a little more time. |
| 472 | - if (connection_aborted() && $context['server']['is_apache']) |
|
| 473 | - @apache_reset_timeout(); |
|
| 488 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
| 489 | + @apache_reset_timeout(); |
|
| 490 | + } |
|
| 474 | 491 | |
| 475 | 492 | if (count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $text, null, PREG_SPLIT_DELIM_CAPTURE)) > 1) |
| 476 | 493 | { |
@@ -526,12 +543,13 @@ discard block |
||
| 526 | 543 | { |
| 527 | 544 | $inList = true; |
| 528 | 545 | |
| 529 | - if ($tag === 'ol') |
|
| 530 | - $listType = 'decimal'; |
|
| 531 | - elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) |
|
| 532 | - $listType = $listTypeMapping[$match[1]]; |
|
| 533 | - else |
|
| 534 | - $listType = null; |
|
| 546 | + if ($tag === 'ol') { |
|
| 547 | + $listType = 'decimal'; |
|
| 548 | + } elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) { |
|
| 549 | + $listType = $listTypeMapping[$match[1]]; |
|
| 550 | + } else { |
|
| 551 | + $listType = null; |
|
| 552 | + } |
|
| 535 | 553 | |
| 536 | 554 | $listDepth++; |
| 537 | 555 | |
@@ -595,9 +613,7 @@ discard block |
||
| 595 | 613 | $parts[$i + 1] = ''; |
| 596 | 614 | $parts[$i + 2] = str_repeat("\t", $listDepth) . '[/list]'; |
| 597 | 615 | $parts[$i + 3] = ''; |
| 598 | - } |
|
| 599 | - |
|
| 600 | - else |
|
| 616 | + } else |
|
| 601 | 617 | { |
| 602 | 618 | // We're in a list item. |
| 603 | 619 | if ($listDepth > 0) |
@@ -634,9 +650,7 @@ discard block |
||
| 634 | 650 | $parts[$i + 1] = ''; |
| 635 | 651 | $parts[$i + 2] = ''; |
| 636 | 652 | $parts[$i + 3] = ''; |
| 637 | - } |
|
| 638 | - |
|
| 639 | - else |
|
| 653 | + } else |
|
| 640 | 654 | { |
| 641 | 655 | // Remove the trailing breaks from the list item. |
| 642 | 656 | $parts[$i] = preg_replace('~\s*<br\s*' . '/?' . '>\s*$~', '', $parts[$i]); |
@@ -674,8 +688,9 @@ discard block |
||
| 674 | 688 | $text .= str_repeat("\t", $listDepth) . '[/list]'; |
| 675 | 689 | } |
| 676 | 690 | |
| 677 | - for ($i = $listDepth; $i > 0; $i--) |
|
| 678 | - $text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]'; |
|
| 691 | + for ($i = $listDepth; $i > 0; $i--) { |
|
| 692 | + $text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]'; |
|
| 693 | + } |
|
| 679 | 694 | |
| 680 | 695 | } |
| 681 | 696 | |
@@ -684,8 +699,9 @@ discard block |
||
| 684 | 699 | { |
| 685 | 700 | // Find the position of the image. |
| 686 | 701 | $start_pos = strpos($text, $matches[0]); |
| 687 | - if ($start_pos === false) |
|
| 688 | - break; |
|
| 702 | + if ($start_pos === false) { |
|
| 703 | + break; |
|
| 704 | + } |
|
| 689 | 705 | $end_pos = $start_pos + strlen($matches[0]); |
| 690 | 706 | |
| 691 | 707 | $params = ''; |
@@ -695,12 +711,13 @@ discard block |
||
| 695 | 711 | $attrs = fetchTagAttributes($matches[1]); |
| 696 | 712 | foreach ($attrs as $attrib => $value) |
| 697 | 713 | { |
| 698 | - if (in_array($attrib, array('width', 'height'))) |
|
| 699 | - $params .= ' ' . $attrib . '=' . (int) $value; |
|
| 700 | - elseif ($attrib == 'alt' && trim($value) != '') |
|
| 701 | - $params .= ' alt=' . trim($value); |
|
| 702 | - elseif ($attrib == 'src') |
|
| 703 | - $src = trim($value); |
|
| 714 | + if (in_array($attrib, array('width', 'height'))) { |
|
| 715 | + $params .= ' ' . $attrib . '=' . (int) $value; |
|
| 716 | + } elseif ($attrib == 'alt' && trim($value) != '') { |
|
| 717 | + $params .= ' alt=' . trim($value); |
|
| 718 | + } elseif ($attrib == 'src') { |
|
| 719 | + $src = trim($value); |
|
| 720 | + } |
|
| 704 | 721 | } |
| 705 | 722 | |
| 706 | 723 | $tag = ''; |
@@ -711,10 +728,11 @@ discard block |
||
| 711 | 728 | { |
| 712 | 729 | $baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']); |
| 713 | 730 | |
| 714 | - if (substr($src, 0, 1) === '/') |
|
| 715 | - $src = $baseURL . $src; |
|
| 716 | - else |
|
| 717 | - $src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src; |
|
| 731 | + if (substr($src, 0, 1) === '/') { |
|
| 732 | + $src = $baseURL . $src; |
|
| 733 | + } else { |
|
| 734 | + $src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src; |
|
| 735 | + } |
|
| 718 | 736 | } |
| 719 | 737 | |
| 720 | 738 | $tag = '[img' . $params . ']' . $src . '[/img]'; |
@@ -892,20 +910,23 @@ discard block |
||
| 892 | 910 | }, |
| 893 | 911 | ); |
| 894 | 912 | |
| 895 | - foreach ($tags as $tag => $replace) |
|
| 896 | - $text = preg_replace_callback($tag, $replace, $text); |
|
| 913 | + foreach ($tags as $tag => $replace) { |
|
| 914 | + $text = preg_replace_callback($tag, $replace, $text); |
|
| 915 | + } |
|
| 897 | 916 | |
| 898 | 917 | // Please give us just a little more time. |
| 899 | - if (connection_aborted() && $context['server']['is_apache']) |
|
| 900 | - @apache_reset_timeout(); |
|
| 918 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
| 919 | + @apache_reset_timeout(); |
|
| 920 | + } |
|
| 901 | 921 | |
| 902 | 922 | // What about URL's - the pain in the ass of the tag world. |
| 903 | 923 | while (preg_match('~<a\s+([^<>]*)>([^<>]*)</a>~i', $text, $matches) === 1) |
| 904 | 924 | { |
| 905 | 925 | // Find the position of the URL. |
| 906 | 926 | $start_pos = strpos($text, $matches[0]); |
| 907 | - if ($start_pos === false) |
|
| 908 | - break; |
|
| 927 | + if ($start_pos === false) { |
|
| 928 | + break; |
|
| 929 | + } |
|
| 909 | 930 | $end_pos = $start_pos + strlen($matches[0]); |
| 910 | 931 | |
| 911 | 932 | $tag_type = 'url'; |
@@ -919,8 +940,9 @@ discard block |
||
| 919 | 940 | $href = trim($value); |
| 920 | 941 | |
| 921 | 942 | // Are we dealing with an FTP link? |
| 922 | - if (preg_match('~^ftps?://~', $href) === 1) |
|
| 923 | - $tag_type = 'ftp'; |
|
| 943 | + if (preg_match('~^ftps?://~', $href) === 1) { |
|
| 944 | + $tag_type = 'ftp'; |
|
| 945 | + } |
|
| 924 | 946 | |
| 925 | 947 | // Or is this a link to an email address? |
| 926 | 948 | elseif (substr($href, 0, 7) == 'mailto:') |
@@ -934,28 +956,31 @@ discard block |
||
| 934 | 956 | { |
| 935 | 957 | $baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']); |
| 936 | 958 | |
| 937 | - if (substr($href, 0, 1) === '/') |
|
| 938 | - $href = $baseURL . $href; |
|
| 939 | - else |
|
| 940 | - $href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href; |
|
| 959 | + if (substr($href, 0, 1) === '/') { |
|
| 960 | + $href = $baseURL . $href; |
|
| 961 | + } else { |
|
| 962 | + $href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href; |
|
| 963 | + } |
|
| 941 | 964 | } |
| 942 | 965 | } |
| 943 | 966 | |
| 944 | 967 | // External URL? |
| 945 | 968 | if ($attrib == 'target' && $tag_type == 'url') |
| 946 | 969 | { |
| 947 | - if (trim($value) == '_blank') |
|
| 948 | - $tag_type == 'iurl'; |
|
| 970 | + if (trim($value) == '_blank') { |
|
| 971 | + $tag_type == 'iurl'; |
|
| 972 | + } |
|
| 949 | 973 | } |
| 950 | 974 | } |
| 951 | 975 | |
| 952 | 976 | $tag = ''; |
| 953 | 977 | if ($href != '') |
| 954 | 978 | { |
| 955 | - if ($matches[2] == $href) |
|
| 956 | - $tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']'; |
|
| 957 | - else |
|
| 958 | - $tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']'; |
|
| 979 | + if ($matches[2] == $href) { |
|
| 980 | + $tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']'; |
|
| 981 | + } else { |
|
| 982 | + $tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']'; |
|
| 983 | + } |
|
| 959 | 984 | } |
| 960 | 985 | |
| 961 | 986 | // Replace the tag |
@@ -995,17 +1020,18 @@ discard block |
||
| 995 | 1020 | // We're either moving from the key to the attribute or we're in a string and this is fine. |
| 996 | 1021 | if ($text[$i] == '=') |
| 997 | 1022 | { |
| 998 | - if ($tag_state == 0) |
|
| 999 | - $tag_state = 1; |
|
| 1000 | - elseif ($tag_state == 2) |
|
| 1001 | - $value .= '='; |
|
| 1023 | + if ($tag_state == 0) { |
|
| 1024 | + $tag_state = 1; |
|
| 1025 | + } elseif ($tag_state == 2) { |
|
| 1026 | + $value .= '='; |
|
| 1027 | + } |
|
| 1002 | 1028 | } |
| 1003 | 1029 | // A space is either moving from an attribute back to a potential key or in a string is fine. |
| 1004 | 1030 | elseif ($text[$i] == ' ') |
| 1005 | 1031 | { |
| 1006 | - if ($tag_state == 2) |
|
| 1007 | - $value .= ' '; |
|
| 1008 | - elseif ($tag_state == 1) |
|
| 1032 | + if ($tag_state == 2) { |
|
| 1033 | + $value .= ' '; |
|
| 1034 | + } elseif ($tag_state == 1) |
|
| 1009 | 1035 | { |
| 1010 | 1036 | $attribs[$key] = $value; |
| 1011 | 1037 | $key = $value = ''; |
@@ -1016,24 +1042,27 @@ discard block |
||
| 1016 | 1042 | elseif ($text[$i] == '"') |
| 1017 | 1043 | { |
| 1018 | 1044 | // Must be either going into or out of a string. |
| 1019 | - if ($tag_state == 1) |
|
| 1020 | - $tag_state = 2; |
|
| 1021 | - else |
|
| 1022 | - $tag_state = 1; |
|
| 1045 | + if ($tag_state == 1) { |
|
| 1046 | + $tag_state = 2; |
|
| 1047 | + } else { |
|
| 1048 | + $tag_state = 1; |
|
| 1049 | + } |
|
| 1023 | 1050 | } |
| 1024 | 1051 | // Otherwise it's fine. |
| 1025 | 1052 | else |
| 1026 | 1053 | { |
| 1027 | - if ($tag_state == 0) |
|
| 1028 | - $key .= $text[$i]; |
|
| 1029 | - else |
|
| 1030 | - $value .= $text[$i]; |
|
| 1054 | + if ($tag_state == 0) { |
|
| 1055 | + $key .= $text[$i]; |
|
| 1056 | + } else { |
|
| 1057 | + $value .= $text[$i]; |
|
| 1058 | + } |
|
| 1031 | 1059 | } |
| 1032 | 1060 | } |
| 1033 | 1061 | |
| 1034 | 1062 | // Anything left? |
| 1035 | - if ($key != '' && $value != '') |
|
| 1036 | - $attribs[$key] = $value; |
|
| 1063 | + if ($key != '' && $value != '') { |
|
| 1064 | + $attribs[$key] = $value; |
|
| 1065 | + } |
|
| 1037 | 1066 | |
| 1038 | 1067 | return $attribs; |
| 1039 | 1068 | } |
@@ -1049,8 +1078,9 @@ discard block |
||
| 1049 | 1078 | global $modSettings; |
| 1050 | 1079 | |
| 1051 | 1080 | // Don't care about the texts that are too short. |
| 1052 | - if (strlen($text) < 3) |
|
| 1053 | - return $text; |
|
| 1081 | + if (strlen($text) < 3) { |
|
| 1082 | + return $text; |
|
| 1083 | + } |
|
| 1054 | 1084 | |
| 1055 | 1085 | // We are going to cycle through the BBC and keep track of tags as they arise - in order. If get to a block level tag we're going to make sure it's not in a non-block level tag! |
| 1056 | 1086 | // This will keep the order of tags that are open. |
@@ -1063,8 +1093,9 @@ discard block |
||
| 1063 | 1093 | $disabled = empty($modSettings['disabledBBC']) ? array() : array_flip(explode(',', strtolower($modSettings['disabledBBC']))); |
| 1064 | 1094 | |
| 1065 | 1095 | // Add flash if it's disabled as embedded tag. |
| 1066 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
| 1067 | - $disabled['flash'] = true; |
|
| 1096 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
| 1097 | + $disabled['flash'] = true; |
|
| 1098 | + } |
|
| 1068 | 1099 | |
| 1069 | 1100 | // Get a list of all the tags that are not disabled. |
| 1070 | 1101 | $all_tags = parse_bbc(false); |
@@ -1072,10 +1103,12 @@ discard block |
||
| 1072 | 1103 | $self_closing_tags = array(); |
| 1073 | 1104 | foreach ($all_tags as $tag) |
| 1074 | 1105 | { |
| 1075 | - if (!isset($disabled[$tag['tag']])) |
|
| 1076 | - $valid_tags[$tag['tag']] = !empty($tag['block_level']); |
|
| 1077 | - if (isset($tag['type']) && $tag['type'] == 'closed') |
|
| 1078 | - $self_closing_tags[] = $tag['tag']; |
|
| 1106 | + if (!isset($disabled[$tag['tag']])) { |
|
| 1107 | + $valid_tags[$tag['tag']] = !empty($tag['block_level']); |
|
| 1108 | + } |
|
| 1109 | + if (isset($tag['type']) && $tag['type'] == 'closed') { |
|
| 1110 | + $self_closing_tags[] = $tag['tag']; |
|
| 1111 | + } |
|
| 1079 | 1112 | } |
| 1080 | 1113 | |
| 1081 | 1114 | // Don't worry if we're in a code/nobbc. |
@@ -1105,16 +1138,19 @@ discard block |
||
| 1105 | 1138 | $tagName = substr($match, $isClosingTag ? 2 : 1, -1); |
| 1106 | 1139 | |
| 1107 | 1140 | // We're closing the exact same tag that we opened. |
| 1108 | - if ($isClosingTag && $insideTag === $tagName) |
|
| 1109 | - $insideTag = null; |
|
| 1141 | + if ($isClosingTag && $insideTag === $tagName) { |
|
| 1142 | + $insideTag = null; |
|
| 1143 | + } |
|
| 1110 | 1144 | |
| 1111 | 1145 | // We're opening a tag and we're not yet inside one either |
| 1112 | - elseif (!$isClosingTag && $insideTag === null) |
|
| 1113 | - $insideTag = $tagName; |
|
| 1146 | + elseif (!$isClosingTag && $insideTag === null) { |
|
| 1147 | + $insideTag = $tagName; |
|
| 1148 | + } |
|
| 1114 | 1149 | |
| 1115 | 1150 | // In all other cases, this tag must be invalid |
| 1116 | - else |
|
| 1117 | - unset($matches[$i]); |
|
| 1151 | + else { |
|
| 1152 | + unset($matches[$i]); |
|
| 1153 | + } |
|
| 1118 | 1154 | } |
| 1119 | 1155 | |
| 1120 | 1156 | // The next one is gonna be the other one. |
@@ -1122,8 +1158,9 @@ discard block |
||
| 1122 | 1158 | } |
| 1123 | 1159 | |
| 1124 | 1160 | // We're still inside a tag and had no chance for closure? |
| 1125 | - if ($insideTag !== null) |
|
| 1126 | - $matches[] = '[/' . $insideTag . ']'; |
|
| 1161 | + if ($insideTag !== null) { |
|
| 1162 | + $matches[] = '[/' . $insideTag . ']'; |
|
| 1163 | + } |
|
| 1127 | 1164 | |
| 1128 | 1165 | // And a complete text string again. |
| 1129 | 1166 | $text = implode('', $matches); |
@@ -1132,8 +1169,9 @@ discard block |
||
| 1132 | 1169 | // Quickly remove any tags which are back to back. |
| 1133 | 1170 | $backToBackPattern = '~\\[(' . implode('|', array_diff(array_keys($valid_tags), array('td', 'anchor'))) . ')[^<>\\[\\]]*\\]\s*\\[/\\1\\]~'; |
| 1134 | 1171 | $lastlen = 0; |
| 1135 | - while (strlen($text) !== $lastlen) |
|
| 1136 | - $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
| 1172 | + while (strlen($text) !== $lastlen) { |
|
| 1173 | + $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
| 1174 | + } |
|
| 1137 | 1175 | |
| 1138 | 1176 | // Need to sort the tags my name length. |
| 1139 | 1177 | uksort($valid_tags, 'sort_array_length'); |
@@ -1177,8 +1215,9 @@ discard block |
||
| 1177 | 1215 | $isCompetingTag = in_array($tag, $competing_tags); |
| 1178 | 1216 | |
| 1179 | 1217 | // Check if this might be one of those cleaned out tags. |
| 1180 | - if ($tag === '') |
|
| 1181 | - continue; |
|
| 1218 | + if ($tag === '') { |
|
| 1219 | + continue; |
|
| 1220 | + } |
|
| 1182 | 1221 | |
| 1183 | 1222 | // Special case: inside [code] blocks any code is left untouched. |
| 1184 | 1223 | elseif ($tag === 'code') |
@@ -1189,8 +1228,9 @@ discard block |
||
| 1189 | 1228 | $inCode = false; |
| 1190 | 1229 | |
| 1191 | 1230 | // Reopen tags that were closed before the code block. |
| 1192 | - if (!empty($inlineElements)) |
|
| 1193 | - $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
| 1231 | + if (!empty($inlineElements)) { |
|
| 1232 | + $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
| 1233 | + } |
|
| 1194 | 1234 | } |
| 1195 | 1235 | |
| 1196 | 1236 | // We're outside a coding and nobbc block and opening it. |
@@ -1219,8 +1259,9 @@ discard block |
||
| 1219 | 1259 | $inNoBbc = false; |
| 1220 | 1260 | |
| 1221 | 1261 | // Some inline elements might've been closed that need reopening. |
| 1222 | - if (!empty($inlineElements)) |
|
| 1223 | - $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
| 1262 | + if (!empty($inlineElements)) { |
|
| 1263 | + $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
| 1264 | + } |
|
| 1224 | 1265 | } |
| 1225 | 1266 | |
| 1226 | 1267 | // We're outside a nobbc and coding block and opening it. |
@@ -1240,8 +1281,9 @@ discard block |
||
| 1240 | 1281 | } |
| 1241 | 1282 | |
| 1242 | 1283 | // So, we're inside one of the special blocks: ignore any tag. |
| 1243 | - elseif ($inCode || $inNoBbc) |
|
| 1244 | - continue; |
|
| 1284 | + elseif ($inCode || $inNoBbc) { |
|
| 1285 | + continue; |
|
| 1286 | + } |
|
| 1245 | 1287 | |
| 1246 | 1288 | // We're dealing with an opening tag. |
| 1247 | 1289 | if ($isOpeningTag) |
@@ -1282,8 +1324,9 @@ discard block |
||
| 1282 | 1324 | if ($parts[$j + 3] === $tag) |
| 1283 | 1325 | { |
| 1284 | 1326 | // If it's an opening tag, increase the level. |
| 1285 | - if ($parts[$j + 2] === '') |
|
| 1286 | - $curLevel++; |
|
| 1327 | + if ($parts[$j + 2] === '') { |
|
| 1328 | + $curLevel++; |
|
| 1329 | + } |
|
| 1287 | 1330 | |
| 1288 | 1331 | // A closing tag, decrease the level. |
| 1289 | 1332 | else |
@@ -1306,13 +1349,15 @@ discard block |
||
| 1306 | 1349 | { |
| 1307 | 1350 | if ($isCompetingTag) |
| 1308 | 1351 | { |
| 1309 | - if (!isset($competingElements[$tag])) |
|
| 1310 | - $competingElements[$tag] = array(); |
|
| 1352 | + if (!isset($competingElements[$tag])) { |
|
| 1353 | + $competingElements[$tag] = array(); |
|
| 1354 | + } |
|
| 1311 | 1355 | |
| 1312 | 1356 | $competingElements[$tag][] = $parts[$i + 4]; |
| 1313 | 1357 | |
| 1314 | - if (count($competingElements[$tag]) > 1) |
|
| 1315 | - $parts[$i] .= '[/' . $tag . ']'; |
|
| 1358 | + if (count($competingElements[$tag]) > 1) { |
|
| 1359 | + $parts[$i] .= '[/' . $tag . ']'; |
|
| 1360 | + } |
|
| 1316 | 1361 | } |
| 1317 | 1362 | |
| 1318 | 1363 | $inlineElements[$elementContent] = $tag; |
@@ -1333,15 +1378,17 @@ discard block |
||
| 1333 | 1378 | $addClosingTags = array(); |
| 1334 | 1379 | while ($element = array_pop($blockElements)) |
| 1335 | 1380 | { |
| 1336 | - if ($element === $tag) |
|
| 1337 | - break; |
|
| 1381 | + if ($element === $tag) { |
|
| 1382 | + break; |
|
| 1383 | + } |
|
| 1338 | 1384 | |
| 1339 | 1385 | // Still a block tag was open not equal to this tag. |
| 1340 | 1386 | $addClosingTags[] = $element['type']; |
| 1341 | 1387 | } |
| 1342 | 1388 | |
| 1343 | - if (!empty($addClosingTags)) |
|
| 1344 | - $parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1]; |
|
| 1389 | + if (!empty($addClosingTags)) { |
|
| 1390 | + $parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1]; |
|
| 1391 | + } |
|
| 1345 | 1392 | |
| 1346 | 1393 | // Apparently the closing tag was not found on the stack. |
| 1347 | 1394 | if (!is_string($element) || $element !== $tag) |
@@ -1351,8 +1398,7 @@ discard block |
||
| 1351 | 1398 | $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
| 1352 | 1399 | continue; |
| 1353 | 1400 | } |
| 1354 | - } |
|
| 1355 | - else |
|
| 1401 | + } else |
|
| 1356 | 1402 | { |
| 1357 | 1403 | // Get rid of this closing tag! |
| 1358 | 1404 | $parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
@@ -1381,53 +1427,62 @@ discard block |
||
| 1381 | 1427 | unset($inlineElements[$tagContentToBeClosed]); |
| 1382 | 1428 | |
| 1383 | 1429 | // Was this the tag we were looking for? |
| 1384 | - if ($tagToBeClosed === $tag) |
|
| 1385 | - break; |
|
| 1430 | + if ($tagToBeClosed === $tag) { |
|
| 1431 | + break; |
|
| 1432 | + } |
|
| 1386 | 1433 | |
| 1387 | 1434 | // Nope, close it and look further! |
| 1388 | - else |
|
| 1389 | - $parts[$i] .= '[/' . $tagToBeClosed . ']'; |
|
| 1435 | + else { |
|
| 1436 | + $parts[$i] .= '[/' . $tagToBeClosed . ']'; |
|
| 1437 | + } |
|
| 1390 | 1438 | } |
| 1391 | 1439 | |
| 1392 | 1440 | if ($isCompetingTag && !empty($competingElements[$tag])) |
| 1393 | 1441 | { |
| 1394 | 1442 | array_pop($competingElements[$tag]); |
| 1395 | 1443 | |
| 1396 | - if (count($competingElements[$tag]) > 0) |
|
| 1397 | - $parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5]; |
|
| 1444 | + if (count($competingElements[$tag]) > 0) { |
|
| 1445 | + $parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5]; |
|
| 1446 | + } |
|
| 1398 | 1447 | } |
| 1399 | 1448 | } |
| 1400 | 1449 | |
| 1401 | 1450 | // Unexpected closing tag, ex-ter-mi-nate. |
| 1402 | - else |
|
| 1403 | - $parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
|
| 1451 | + else { |
|
| 1452 | + $parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
|
| 1453 | + } |
|
| 1404 | 1454 | } |
| 1405 | 1455 | } |
| 1406 | 1456 | } |
| 1407 | 1457 | |
| 1408 | 1458 | // Close the code tags. |
| 1409 | - if ($inCode) |
|
| 1410 | - $parts[$i] .= '[/code]'; |
|
| 1459 | + if ($inCode) { |
|
| 1460 | + $parts[$i] .= '[/code]'; |
|
| 1461 | + } |
|
| 1411 | 1462 | |
| 1412 | 1463 | // The same for nobbc tags. |
| 1413 | - elseif ($inNoBbc) |
|
| 1414 | - $parts[$i] .= '[/nobbc]'; |
|
| 1464 | + elseif ($inNoBbc) { |
|
| 1465 | + $parts[$i] .= '[/nobbc]'; |
|
| 1466 | + } |
|
| 1415 | 1467 | |
| 1416 | 1468 | // Still inline tags left unclosed? Close them now, better late than never. |
| 1417 | - elseif (!empty($inlineElements)) |
|
| 1418 | - $parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']'; |
|
| 1469 | + elseif (!empty($inlineElements)) { |
|
| 1470 | + $parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']'; |
|
| 1471 | + } |
|
| 1419 | 1472 | |
| 1420 | 1473 | // Now close the block elements. |
| 1421 | - if (!empty($blockElements)) |
|
| 1422 | - $parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']'; |
|
| 1474 | + if (!empty($blockElements)) { |
|
| 1475 | + $parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']'; |
|
| 1476 | + } |
|
| 1423 | 1477 | |
| 1424 | 1478 | $text = implode('', $parts); |
| 1425 | 1479 | } |
| 1426 | 1480 | |
| 1427 | 1481 | // Final clean up of back to back tags. |
| 1428 | 1482 | $lastlen = 0; |
| 1429 | - while (strlen($text) !== $lastlen) |
|
| 1430 | - $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
| 1483 | + while (strlen($text) !== $lastlen) { |
|
| 1484 | + $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
| 1485 | + } |
|
| 1431 | 1486 | |
| 1432 | 1487 | return $text; |
| 1433 | 1488 | } |
@@ -1456,22 +1511,25 @@ discard block |
||
| 1456 | 1511 | $context['template_layers'] = array(); |
| 1457 | 1512 | // Lets make sure we aren't going to output anything nasty. |
| 1458 | 1513 | @ob_end_clean(); |
| 1459 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
| 1460 | - @ob_start('ob_gzhandler'); |
|
| 1461 | - else |
|
| 1462 | - @ob_start(); |
|
| 1514 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
| 1515 | + @ob_start('ob_gzhandler'); |
|
| 1516 | + } else { |
|
| 1517 | + @ob_start(); |
|
| 1518 | + } |
|
| 1463 | 1519 | |
| 1464 | 1520 | // If we don't have any locale better avoid broken js |
| 1465 | - if (empty($txt['lang_locale'])) |
|
| 1466 | - die(); |
|
| 1521 | + if (empty($txt['lang_locale'])) { |
|
| 1522 | + die(); |
|
| 1523 | + } |
|
| 1467 | 1524 | |
| 1468 | 1525 | $file_data = '(function ($) { |
| 1469 | 1526 | \'use strict\'; |
| 1470 | 1527 | |
| 1471 | 1528 | $.sceditor.locale[' . javaScriptEscape($txt['lang_locale']) . '] = {'; |
| 1472 | - foreach ($editortxt as $key => $val) |
|
| 1473 | - $file_data .= ' |
|
| 1529 | + foreach ($editortxt as $key => $val) { |
|
| 1530 | + $file_data .= ' |
|
| 1474 | 1531 | ' . javaScriptEscape($key) . ': ' . javaScriptEscape($val) . ','; |
| 1532 | + } |
|
| 1475 | 1533 | |
| 1476 | 1534 | $file_data .= ' |
| 1477 | 1535 | dateFormat: "day.month.year" |
@@ -1539,8 +1597,9 @@ discard block |
||
| 1539 | 1597 | ) |
| 1540 | 1598 | ); |
| 1541 | 1599 | $icon_data = array(); |
| 1542 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1543 | - $icon_data[] = $row; |
|
| 1600 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1601 | + $icon_data[] = $row; |
|
| 1602 | + } |
|
| 1544 | 1603 | $smcFunc['db_free_result']($request); |
| 1545 | 1604 | |
| 1546 | 1605 | $icons = array(); |
@@ -1555,9 +1614,9 @@ discard block |
||
| 1555 | 1614 | } |
| 1556 | 1615 | |
| 1557 | 1616 | cache_put_data('posting_icons-' . $board_id, $icons, 480); |
| 1617 | + } else { |
|
| 1618 | + $icons = $temp; |
|
| 1558 | 1619 | } |
| 1559 | - else |
|
| 1560 | - $icons = $temp; |
|
| 1561 | 1620 | } |
| 1562 | 1621 | call_integration_hook('integrate_load_message_icons', array(&$icons)); |
| 1563 | 1622 | |
@@ -1598,8 +1657,9 @@ discard block |
||
| 1598 | 1657 | { |
| 1599 | 1658 | // Some general stuff. |
| 1600 | 1659 | $settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set']; |
| 1601 | - if (!empty($context['drafts_autosave'])) |
|
| 1602 | - $context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000; |
|
| 1660 | + if (!empty($context['drafts_autosave'])) { |
|
| 1661 | + $context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000; |
|
| 1662 | + } |
|
| 1603 | 1663 | |
| 1604 | 1664 | // This really has some WYSIWYG stuff. |
| 1605 | 1665 | loadCSSFile('jquery.sceditor.css', array('force_current' => false, 'validate' => true), 'smf_jquery_sceditor'); |
@@ -1615,8 +1675,9 @@ discard block |
||
| 1615 | 1675 | var bbc_quote = \'' . addcslashes($txt['quote'], "'") . '\'; |
| 1616 | 1676 | var bbc_search_on = \'' . addcslashes($txt['search_on'], "'") . '\';'); |
| 1617 | 1677 | // editor language file |
| 1618 | - if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') |
|
| 1619 | - loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language'); |
|
| 1678 | + if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') { |
|
| 1679 | + loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language'); |
|
| 1680 | + } |
|
| 1620 | 1681 | |
| 1621 | 1682 | $context['shortcuts_text'] = $txt['shortcuts' . (!empty($context['drafts_save']) ? '_drafts' : '') . (isBrowser('is_firefox') ? '_firefox' : '')]; |
| 1622 | 1683 | $context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv')))); |
@@ -1625,11 +1686,12 @@ discard block |
||
| 1625 | 1686 | loadJavaScriptFile('spellcheck.js', array(), 'smf_spellcheck'); |
| 1626 | 1687 | |
| 1627 | 1688 | // Some hidden information is needed in order to make the spell checking work. |
| 1628 | - if (!isset($_REQUEST['xml'])) |
|
| 1629 | - $context['insert_after_template'] .= ' |
|
| 1689 | + if (!isset($_REQUEST['xml'])) { |
|
| 1690 | + $context['insert_after_template'] .= ' |
|
| 1630 | 1691 | <form name="spell_form" id="spell_form" method="post" accept-charset="' . $context['character_set'] . '" target="spellWindow" action="' . $scripturl . '?action=spellcheck"> |
| 1631 | 1692 | <input type="hidden" name="spellstring" value=""> |
| 1632 | 1693 | </form>'; |
| 1694 | + } |
|
| 1633 | 1695 | } |
| 1634 | 1696 | } |
| 1635 | 1697 | |
@@ -1786,10 +1848,12 @@ discard block |
||
| 1786 | 1848 | |
| 1787 | 1849 | // Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this. |
| 1788 | 1850 | $disabled_tags = array(); |
| 1789 | - if (!empty($modSettings['disabledBBC'])) |
|
| 1790 | - $disabled_tags = explode(',', $modSettings['disabledBBC']); |
|
| 1791 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
| 1792 | - $disabled_tags[] = 'flash'; |
|
| 1851 | + if (!empty($modSettings['disabledBBC'])) { |
|
| 1852 | + $disabled_tags = explode(',', $modSettings['disabledBBC']); |
|
| 1853 | + } |
|
| 1854 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
| 1855 | + $disabled_tags[] = 'flash'; |
|
| 1856 | + } |
|
| 1793 | 1857 | |
| 1794 | 1858 | foreach ($disabled_tags as $tag) |
| 1795 | 1859 | { |
@@ -1799,9 +1863,10 @@ discard block |
||
| 1799 | 1863 | $context['disabled_tags']['orderedlist'] = true; |
| 1800 | 1864 | } |
| 1801 | 1865 | |
| 1802 | - foreach ($editor_tag_map as $thisTag => $tagNameBBC) |
|
| 1803 | - if ($tag === $thisTag) |
|
| 1866 | + foreach ($editor_tag_map as $thisTag => $tagNameBBC) { |
|
| 1867 | + if ($tag === $thisTag) |
|
| 1804 | 1868 | $context['disabled_tags'][$tagNameBBC] = true; |
| 1869 | + } |
|
| 1805 | 1870 | |
| 1806 | 1871 | $context['disabled_tags'][trim($tag)] = true; |
| 1807 | 1872 | } |
@@ -1811,19 +1876,21 @@ discard block |
||
| 1811 | 1876 | $context['bbc_toolbar'] = array(); |
| 1812 | 1877 | foreach ($context['bbc_tags'] as $row => $tagRow) |
| 1813 | 1878 | { |
| 1814 | - if (!isset($context['bbc_toolbar'][$row])) |
|
| 1815 | - $context['bbc_toolbar'][$row] = array(); |
|
| 1879 | + if (!isset($context['bbc_toolbar'][$row])) { |
|
| 1880 | + $context['bbc_toolbar'][$row] = array(); |
|
| 1881 | + } |
|
| 1816 | 1882 | $tagsRow = array(); |
| 1817 | 1883 | foreach ($tagRow as $tag) |
| 1818 | 1884 | { |
| 1819 | 1885 | if ((!empty($tag['code'])) && empty($context['disabled_tags'][$tag['code']])) |
| 1820 | 1886 | { |
| 1821 | 1887 | $tagsRow[] = $tag['code']; |
| 1822 | - if (isset($tag['image'])) |
|
| 1823 | - $bbcodes_styles .= ' |
|
| 1888 | + if (isset($tag['image'])) { |
|
| 1889 | + $bbcodes_styles .= ' |
|
| 1824 | 1890 | .sceditor-button-' . $tag['code'] . ' div { |
| 1825 | 1891 | background: url(\'' . $settings['default_theme_url'] . '/images/bbc/' . $tag['image'] . '.png\'); |
| 1826 | 1892 | }'; |
| 1893 | + } |
|
| 1827 | 1894 | if (isset($tag['before'])) |
| 1828 | 1895 | { |
| 1829 | 1896 | $context['bbcodes_handlers'] .= ' |
@@ -1837,8 +1904,7 @@ discard block |
||
| 1837 | 1904 | });'; |
| 1838 | 1905 | } |
| 1839 | 1906 | |
| 1840 | - } |
|
| 1841 | - else |
|
| 1907 | + } else |
|
| 1842 | 1908 | { |
| 1843 | 1909 | $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
| 1844 | 1910 | $tagsRow = array(); |
@@ -1849,14 +1915,16 @@ discard block |
||
| 1849 | 1915 | { |
| 1850 | 1916 | $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
| 1851 | 1917 | $tagsRow = array(); |
| 1852 | - if (!isset($context['disabled_tags']['font'])) |
|
| 1853 | - $tagsRow[] = 'font'; |
|
| 1854 | - if (!isset($context['disabled_tags']['size'])) |
|
| 1855 | - $tagsRow[] = 'size'; |
|
| 1856 | - if (!isset($context['disabled_tags']['color'])) |
|
| 1857 | - $tagsRow[] = 'color'; |
|
| 1858 | - } |
|
| 1859 | - elseif ($row == 1 && empty($modSettings['disable_wysiwyg'])) |
|
| 1918 | + if (!isset($context['disabled_tags']['font'])) { |
|
| 1919 | + $tagsRow[] = 'font'; |
|
| 1920 | + } |
|
| 1921 | + if (!isset($context['disabled_tags']['size'])) { |
|
| 1922 | + $tagsRow[] = 'size'; |
|
| 1923 | + } |
|
| 1924 | + if (!isset($context['disabled_tags']['color'])) { |
|
| 1925 | + $tagsRow[] = 'color'; |
|
| 1926 | + } |
|
| 1927 | + } elseif ($row == 1 && empty($modSettings['disable_wysiwyg'])) |
|
| 1860 | 1928 | { |
| 1861 | 1929 | $tmp = array(); |
| 1862 | 1930 | $tagsRow[] = 'removeformat'; |
@@ -1867,13 +1935,15 @@ discard block |
||
| 1867 | 1935 | } |
| 1868 | 1936 | } |
| 1869 | 1937 | |
| 1870 | - if (!empty($tagsRow)) |
|
| 1871 | - $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
|
| 1938 | + if (!empty($tagsRow)) { |
|
| 1939 | + $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
|
| 1940 | + } |
|
| 1872 | 1941 | } |
| 1873 | - if (!empty($bbcodes_styles)) |
|
| 1874 | - $context['html_headers'] .= ' |
|
| 1942 | + if (!empty($bbcodes_styles)) { |
|
| 1943 | + $context['html_headers'] .= ' |
|
| 1875 | 1944 | <style>' . $bbcodes_styles . ' |
| 1876 | 1945 | </style>'; |
| 1946 | + } |
|
| 1877 | 1947 | } |
| 1878 | 1948 | |
| 1879 | 1949 | // Initialize smiley array... if not loaded before. |
@@ -1885,8 +1955,8 @@ discard block |
||
| 1885 | 1955 | ); |
| 1886 | 1956 | |
| 1887 | 1957 | // Load smileys - don't bother to run a query if we're not using the database's ones anyhow. |
| 1888 | - if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') |
|
| 1889 | - $context['smileys']['postform'][] = array( |
|
| 1958 | + if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') { |
|
| 1959 | + $context['smileys']['postform'][] = array( |
|
| 1890 | 1960 | 'smileys' => array( |
| 1891 | 1961 | array( |
| 1892 | 1962 | 'code' => ':)', |
@@ -1972,7 +2042,7 @@ discard block |
||
| 1972 | 2042 | ), |
| 1973 | 2043 | 'isLast' => true, |
| 1974 | 2044 | ); |
| 1975 | - elseif ($user_info['smiley_set'] != 'none') |
|
| 2045 | + } elseif ($user_info['smiley_set'] != 'none') |
|
| 1976 | 2046 | { |
| 1977 | 2047 | if (($temp = cache_get_data('posting_smileys', 480)) == null) |
| 1978 | 2048 | { |
@@ -1995,17 +2065,19 @@ discard block |
||
| 1995 | 2065 | |
| 1996 | 2066 | foreach ($context['smileys'] as $section => $smileyRows) |
| 1997 | 2067 | { |
| 1998 | - foreach ($smileyRows as $rowIndex => $smileys) |
|
| 1999 | - $context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true; |
|
| 2068 | + foreach ($smileyRows as $rowIndex => $smileys) { |
|
| 2069 | + $context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true; |
|
| 2070 | + } |
|
| 2000 | 2071 | |
| 2001 | - if (!empty($smileyRows)) |
|
| 2002 | - $context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true; |
|
| 2072 | + if (!empty($smileyRows)) { |
|
| 2073 | + $context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true; |
|
| 2074 | + } |
|
| 2003 | 2075 | } |
| 2004 | 2076 | |
| 2005 | 2077 | cache_put_data('posting_smileys', $context['smileys'], 480); |
| 2078 | + } else { |
|
| 2079 | + $context['smileys'] = $temp; |
|
| 2006 | 2080 | } |
| 2007 | - else |
|
| 2008 | - $context['smileys'] = $temp; |
|
| 2009 | 2081 | } |
| 2010 | 2082 | } |
| 2011 | 2083 | |
@@ -2031,8 +2103,9 @@ discard block |
||
| 2031 | 2103 | loadTemplate('GenericControls'); |
| 2032 | 2104 | |
| 2033 | 2105 | // Some javascript ma'am? |
| 2034 | - if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) |
|
| 2035 | - loadJavaScriptFile('captcha.js', array(), 'smf_captcha'); |
|
| 2106 | + if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) { |
|
| 2107 | + loadJavaScriptFile('captcha.js', array(), 'smf_captcha'); |
|
| 2108 | + } |
|
| 2036 | 2109 | |
| 2037 | 2110 | $context['use_graphic_library'] = in_array('gd', get_loaded_extensions()); |
| 2038 | 2111 | |
@@ -2045,8 +2118,8 @@ discard block |
||
| 2045 | 2118 | $isNew = !isset($context['controls']['verification'][$verificationOptions['id']]); |
| 2046 | 2119 | |
| 2047 | 2120 | // Log this into our collection. |
| 2048 | - if ($isNew) |
|
| 2049 | - $context['controls']['verification'][$verificationOptions['id']] = array( |
|
| 2121 | + if ($isNew) { |
|
| 2122 | + $context['controls']['verification'][$verificationOptions['id']] = array( |
|
| 2050 | 2123 | 'id' => $verificationOptions['id'], |
| 2051 | 2124 | 'empty_field' => empty($verificationOptions['no_empty_field']), |
| 2052 | 2125 | 'show_visual' => !empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])), |
@@ -2056,20 +2129,23 @@ discard block |
||
| 2056 | 2129 | 'text_value' => '', |
| 2057 | 2130 | 'questions' => array(), |
| 2058 | 2131 | ); |
| 2132 | + } |
|
| 2059 | 2133 | $thisVerification = &$context['controls']['verification'][$verificationOptions['id']]; |
| 2060 | 2134 | |
| 2061 | 2135 | // Add javascript for the object. |
| 2062 | - if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) |
|
| 2063 | - $context['insert_after_template'] .= ' |
|
| 2136 | + if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) { |
|
| 2137 | + $context['insert_after_template'] .= ' |
|
| 2064 | 2138 | <script> |
| 2065 | 2139 | var verification' . $verificationOptions['id'] . 'Handle = new smfCaptcha("' . $thisVerification['image_href'] . '", "' . $verificationOptions['id'] . '", ' . ($context['use_graphic_library'] ? 1 : 0) . '); |
| 2066 | 2140 | </script>'; |
| 2141 | + } |
|
| 2067 | 2142 | |
| 2068 | 2143 | // Is there actually going to be anything? |
| 2069 | - if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions'])) |
|
| 2070 | - return false; |
|
| 2071 | - elseif (!$isNew && !$do_test) |
|
| 2072 | - return true; |
|
| 2144 | + if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions'])) { |
|
| 2145 | + return false; |
|
| 2146 | + } elseif (!$isNew && !$do_test) { |
|
| 2147 | + return true; |
|
| 2148 | + } |
|
| 2073 | 2149 | |
| 2074 | 2150 | // If we want questions do we have a cache of all the IDs? |
| 2075 | 2151 | if (!empty($thisVerification['number_questions']) && empty($modSettings['question_id_cache'])) |
@@ -2092,8 +2168,9 @@ discard block |
||
| 2092 | 2168 | unset ($row['id_question']); |
| 2093 | 2169 | // Make them all lowercase. We can't directly use $smcFunc['strtolower'] with array_walk, so do it manually, eh? |
| 2094 | 2170 | $row['answers'] = smf_json_decode($row['answers'], true); |
| 2095 | - foreach ($row['answers'] as $k => $v) |
|
| 2096 | - $row['answers'][$k] = $smcFunc['strtolower']($v); |
|
| 2171 | + foreach ($row['answers'] as $k => $v) { |
|
| 2172 | + $row['answers'][$k] = $smcFunc['strtolower']($v); |
|
| 2173 | + } |
|
| 2097 | 2174 | |
| 2098 | 2175 | $modSettings['question_id_cache']['questions'][$id_question] = $row; |
| 2099 | 2176 | $modSettings['question_id_cache']['langs'][$row['lngfile']][] = $id_question; |
@@ -2104,46 +2181,55 @@ discard block |
||
| 2104 | 2181 | } |
| 2105 | 2182 | } |
| 2106 | 2183 | |
| 2107 | - if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) |
|
| 2108 | - $_SESSION[$verificationOptions['id'] . '_vv'] = array(); |
|
| 2184 | + if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) { |
|
| 2185 | + $_SESSION[$verificationOptions['id'] . '_vv'] = array(); |
|
| 2186 | + } |
|
| 2109 | 2187 | |
| 2110 | 2188 | // Do we need to refresh the verification? |
| 2111 | - if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) |
|
| 2112 | - $force_refresh = true; |
|
| 2113 | - else |
|
| 2114 | - $force_refresh = false; |
|
| 2189 | + if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) { |
|
| 2190 | + $force_refresh = true; |
|
| 2191 | + } else { |
|
| 2192 | + $force_refresh = false; |
|
| 2193 | + } |
|
| 2115 | 2194 | |
| 2116 | 2195 | // This can also force a fresh, although unlikely. |
| 2117 | - if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) |
|
| 2118 | - $force_refresh = true; |
|
| 2196 | + if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) { |
|
| 2197 | + $force_refresh = true; |
|
| 2198 | + } |
|
| 2119 | 2199 | |
| 2120 | 2200 | $verification_errors = array(); |
| 2121 | 2201 | // Start with any testing. |
| 2122 | 2202 | if ($do_test) |
| 2123 | 2203 | { |
| 2124 | 2204 | // This cannot happen! |
| 2125 | - if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) |
|
| 2126 | - fatal_lang_error('no_access', false); |
|
| 2205 | + if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) { |
|
| 2206 | + fatal_lang_error('no_access', false); |
|
| 2207 | + } |
|
| 2127 | 2208 | // ... nor this! |
| 2128 | - if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) |
|
| 2129 | - fatal_lang_error('no_access', false); |
|
| 2209 | + if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) { |
|
| 2210 | + fatal_lang_error('no_access', false); |
|
| 2211 | + } |
|
| 2130 | 2212 | // Hmm, it's requested but not actually declared. This shouldn't happen. |
| 2131 | - if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) |
|
| 2132 | - fatal_lang_error('no_access', false); |
|
| 2213 | + if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) { |
|
| 2214 | + fatal_lang_error('no_access', false); |
|
| 2215 | + } |
|
| 2133 | 2216 | // While we're here, did the user do something bad? |
| 2134 | - if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) |
|
| 2135 | - $verification_errors[] = 'wrong_verification_answer'; |
|
| 2217 | + if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) { |
|
| 2218 | + $verification_errors[] = 'wrong_verification_answer'; |
|
| 2219 | + } |
|
| 2136 | 2220 | |
| 2137 | - if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) |
|
| 2138 | - $verification_errors[] = 'wrong_verification_code'; |
|
| 2221 | + if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) { |
|
| 2222 | + $verification_errors[] = 'wrong_verification_code'; |
|
| 2223 | + } |
|
| 2139 | 2224 | if ($thisVerification['number_questions']) |
| 2140 | 2225 | { |
| 2141 | 2226 | $incorrectQuestions = array(); |
| 2142 | 2227 | foreach ($_SESSION[$verificationOptions['id'] . '_vv']['q'] as $q) |
| 2143 | 2228 | { |
| 2144 | 2229 | // We don't have this question any more, thus no answers. |
| 2145 | - if (!isset($modSettings['question_id_cache']['questions'][$q])) |
|
| 2146 | - continue; |
|
| 2230 | + if (!isset($modSettings['question_id_cache']['questions'][$q])) { |
|
| 2231 | + continue; |
|
| 2232 | + } |
|
| 2147 | 2233 | // This is quite complex. We have our question but it might have multiple answers. |
| 2148 | 2234 | // First, did they actually answer this question? |
| 2149 | 2235 | if (!isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) || trim($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) == '') |
@@ -2155,24 +2241,28 @@ discard block |
||
| 2155 | 2241 | else |
| 2156 | 2242 | { |
| 2157 | 2243 | $given_answer = trim($smcFunc['htmlspecialchars'](strtolower($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]))); |
| 2158 | - if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) |
|
| 2159 | - $incorrectQuestions[] = $q; |
|
| 2244 | + if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) { |
|
| 2245 | + $incorrectQuestions[] = $q; |
|
| 2246 | + } |
|
| 2160 | 2247 | } |
| 2161 | 2248 | } |
| 2162 | 2249 | |
| 2163 | - if (!empty($incorrectQuestions)) |
|
| 2164 | - $verification_errors[] = 'wrong_verification_answer'; |
|
| 2250 | + if (!empty($incorrectQuestions)) { |
|
| 2251 | + $verification_errors[] = 'wrong_verification_answer'; |
|
| 2252 | + } |
|
| 2165 | 2253 | } |
| 2166 | 2254 | } |
| 2167 | 2255 | |
| 2168 | 2256 | // Any errors means we refresh potentially. |
| 2169 | 2257 | if (!empty($verification_errors)) |
| 2170 | 2258 | { |
| 2171 | - if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) |
|
| 2172 | - $_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0; |
|
| 2259 | + if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) { |
|
| 2260 | + $_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0; |
|
| 2261 | + } |
|
| 2173 | 2262 | // Too many errors? |
| 2174 | - elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) |
|
| 2175 | - $force_refresh = true; |
|
| 2263 | + elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) { |
|
| 2264 | + $force_refresh = true; |
|
| 2265 | + } |
|
| 2176 | 2266 | |
| 2177 | 2267 | // Keep a track of these. |
| 2178 | 2268 | $_SESSION[$verificationOptions['id'] . '_vv']['errors']++; |
@@ -2205,8 +2295,9 @@ discard block |
||
| 2205 | 2295 | // Are we overriding the range? |
| 2206 | 2296 | $character_range = !empty($verificationOptions['override_range']) ? $verificationOptions['override_range'] : $context['standard_captcha_range']; |
| 2207 | 2297 | |
| 2208 | - for ($i = 0; $i < 6; $i++) |
|
| 2209 | - $_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)]; |
|
| 2298 | + for ($i = 0; $i < 6; $i++) { |
|
| 2299 | + $_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)]; |
|
| 2300 | + } |
|
| 2210 | 2301 | } |
| 2211 | 2302 | |
| 2212 | 2303 | // Getting some new questions? |
@@ -2214,8 +2305,9 @@ discard block |
||
| 2214 | 2305 | { |
| 2215 | 2306 | // Attempt to try the current page's language, followed by the user's preference, followed by the site default. |
| 2216 | 2307 | $possible_langs = array(); |
| 2217 | - if (isset($_SESSION['language'])) |
|
| 2218 | - $possible_langs[] = strtr($_SESSION['language'], array('-utf8' => '')); |
|
| 2308 | + if (isset($_SESSION['language'])) { |
|
| 2309 | + $possible_langs[] = strtr($_SESSION['language'], array('-utf8' => '')); |
|
| 2310 | + } |
|
| 2219 | 2311 | if (!empty($user_info['language'])); |
| 2220 | 2312 | $possible_langs[] = $user_info['language']; |
| 2221 | 2313 | $possible_langs[] = $language; |
@@ -2234,8 +2326,7 @@ discard block |
||
| 2234 | 2326 | } |
| 2235 | 2327 | } |
| 2236 | 2328 | } |
| 2237 | - } |
|
| 2238 | - else |
|
| 2329 | + } else |
|
| 2239 | 2330 | { |
| 2240 | 2331 | // Same questions as before. |
| 2241 | 2332 | $questionIDs = !empty($_SESSION[$verificationOptions['id'] . '_vv']['q']) ? $_SESSION[$verificationOptions['id'] . '_vv']['q'] : array(); |
@@ -2245,8 +2336,9 @@ discard block |
||
| 2245 | 2336 | // If we do have an empty field, it would be nice to hide it from legitimate users who shouldn't be populating it anyway. |
| 2246 | 2337 | if (!empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) |
| 2247 | 2338 | { |
| 2248 | - if (!isset($context['html_headers'])) |
|
| 2249 | - $context['html_headers'] = ''; |
|
| 2339 | + if (!isset($context['html_headers'])) { |
|
| 2340 | + $context['html_headers'] = ''; |
|
| 2341 | + } |
|
| 2250 | 2342 | $context['html_headers'] .= '<style>.vv_special { display:none; }</style>'; |
| 2251 | 2343 | } |
| 2252 | 2344 | |
@@ -2272,11 +2364,13 @@ discard block |
||
| 2272 | 2364 | $_SESSION[$verificationOptions['id'] . '_vv']['count'] = empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) ? 1 : $_SESSION[$verificationOptions['id'] . '_vv']['count'] + 1; |
| 2273 | 2365 | |
| 2274 | 2366 | // Return errors if we have them. |
| 2275 | - if (!empty($verification_errors)) |
|
| 2276 | - return $verification_errors; |
|
| 2367 | + if (!empty($verification_errors)) { |
|
| 2368 | + return $verification_errors; |
|
| 2369 | + } |
|
| 2277 | 2370 | // If we had a test that one, make a note. |
| 2278 | - elseif ($do_test) |
|
| 2279 | - $_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true; |
|
| 2371 | + elseif ($do_test) { |
|
| 2372 | + $_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true; |
|
| 2373 | + } |
|
| 2280 | 2374 | |
| 2281 | 2375 | // Say that everything went well chaps. |
| 2282 | 2376 | return true; |
@@ -2301,8 +2395,9 @@ discard block |
||
| 2301 | 2395 | call_integration_hook('integrate_autosuggest', array(&$searchTypes)); |
| 2302 | 2396 | |
| 2303 | 2397 | // If we're just checking the callback function is registered return true or false. |
| 2304 | - if ($checkRegistered != null) |
|
| 2305 | - return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered); |
|
| 2398 | + if ($checkRegistered != null) { |
|
| 2399 | + return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered); |
|
| 2400 | + } |
|
| 2306 | 2401 | |
| 2307 | 2402 | checkSession('get'); |
| 2308 | 2403 | loadTemplate('Xml'); |
@@ -2453,24 +2548,27 @@ discard block |
||
| 2453 | 2548 | foreach ($possible_versions as $ver) |
| 2454 | 2549 | { |
| 2455 | 2550 | $ver = trim($ver); |
| 2456 | - if (strpos($ver, 'SMF') === 0) |
|
| 2457 | - $versions[] = $ver; |
|
| 2551 | + if (strpos($ver, 'SMF') === 0) { |
|
| 2552 | + $versions[] = $ver; |
|
| 2553 | + } |
|
| 2458 | 2554 | } |
| 2459 | 2555 | } |
| 2460 | 2556 | $smcFunc['db_free_result']($request); |
| 2461 | 2557 | |
| 2462 | 2558 | // Just in case we don't have ANYthing. |
| 2463 | - if (empty($versions)) |
|
| 2464 | - $versions = array('SMF 2.0'); |
|
| 2559 | + if (empty($versions)) { |
|
| 2560 | + $versions = array('SMF 2.0'); |
|
| 2561 | + } |
|
| 2465 | 2562 | |
| 2466 | - foreach ($versions as $id => $version) |
|
| 2467 | - if (strpos($version, strtoupper($_REQUEST['search'])) !== false) |
|
| 2563 | + foreach ($versions as $id => $version) { |
|
| 2564 | + if (strpos($version, strtoupper($_REQUEST['search'])) !== false) |
|
| 2468 | 2565 | $xml_data['items']['children'][] = array( |
| 2469 | 2566 | 'attributes' => array( |
| 2470 | 2567 | 'id' => $id, |
| 2471 | 2568 | ), |
| 2472 | 2569 | 'value' => $version, |
| 2473 | 2570 | ); |
| 2571 | + } |
|
| 2474 | 2572 | |
| 2475 | 2573 | return $xml_data; |
| 2476 | 2574 | } |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Get the latest post made on the system |
@@ -44,8 +45,9 @@ discard block |
||
| 44 | 45 | 'is_approved' => 1, |
| 45 | 46 | ) |
| 46 | 47 | ); |
| 47 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 48 | - return array(); |
|
| 48 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 49 | + return array(); |
|
| 50 | + } |
|
| 49 | 51 | $row = $smcFunc['db_fetch_assoc']($request); |
| 50 | 52 | $smcFunc['db_free_result']($request); |
| 51 | 53 | |
@@ -54,8 +56,9 @@ discard block |
||
| 54 | 56 | censorText($row['body']); |
| 55 | 57 | |
| 56 | 58 | $row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled']), array('<br>' => ' '))); |
| 57 | - if ($smcFunc['strlen']($row['body']) > 128) |
|
| 58 | - $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...'; |
|
| 59 | + if ($smcFunc['strlen']($row['body']) > 128) { |
|
| 60 | + $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...'; |
|
| 61 | + } |
|
| 59 | 62 | |
| 60 | 63 | // Send the data. |
| 61 | 64 | return array( |
@@ -83,15 +86,17 @@ discard block |
||
| 83 | 86 | |
| 84 | 87 | $context['is_redirect'] = false; |
| 85 | 88 | |
| 86 | - if (isset($_REQUEST['start']) && $_REQUEST['start'] > 95) |
|
| 87 | - $_REQUEST['start'] = 95; |
|
| 89 | + if (isset($_REQUEST['start']) && $_REQUEST['start'] > 95) { |
|
| 90 | + $_REQUEST['start'] = 95; |
|
| 91 | + } |
|
| 88 | 92 | |
| 89 | 93 | $query_parameters = array(); |
| 90 | 94 | if (!empty($_REQUEST['c']) && empty($board)) |
| 91 | 95 | { |
| 92 | 96 | $_REQUEST['c'] = explode(',', $_REQUEST['c']); |
| 93 | - foreach ($_REQUEST['c'] as $i => $c) |
|
| 94 | - $_REQUEST['c'][$i] = (int) $c; |
|
| 97 | + foreach ($_REQUEST['c'] as $i => $c) { |
|
| 98 | + $_REQUEST['c'][$i] = (int) $c; |
|
| 99 | + } |
|
| 95 | 100 | |
| 96 | 101 | if (count($_REQUEST['c']) == 1) |
| 97 | 102 | { |
@@ -107,8 +112,9 @@ discard block |
||
| 107 | 112 | list ($name) = $smcFunc['db_fetch_row']($request); |
| 108 | 113 | $smcFunc['db_free_result']($request); |
| 109 | 114 | |
| 110 | - if (empty($name)) |
|
| 111 | - fatal_lang_error('no_access', false); |
|
| 115 | + if (empty($name)) { |
|
| 116 | + fatal_lang_error('no_access', false); |
|
| 117 | + } |
|
| 112 | 118 | |
| 113 | 119 | $context['linktree'][] = array( |
| 114 | 120 | 'url' => $scripturl . '#c' . (int) $_REQUEST['c'], |
@@ -140,8 +146,9 @@ discard block |
||
| 140 | 146 | } |
| 141 | 147 | $smcFunc['db_free_result']($request); |
| 142 | 148 | |
| 143 | - if (empty($boards)) |
|
| 144 | - fatal_lang_error('error_no_boards_selected'); |
|
| 149 | + if (empty($boards)) { |
|
| 150 | + fatal_lang_error('error_no_boards_selected'); |
|
| 151 | + } |
|
| 145 | 152 | |
| 146 | 153 | $query_this_board = 'b.id_board IN ({array_int:boards})'; |
| 147 | 154 | $query_parameters['boards'] = $boards; |
@@ -155,12 +162,12 @@ discard block |
||
| 155 | 162 | } |
| 156 | 163 | |
| 157 | 164 | $context['page_index'] = constructPageIndex($scripturl . '?action=recent;c=' . implode(',', $_REQUEST['c']), $_REQUEST['start'], min(100, $total_cat_posts), 10, false); |
| 158 | - } |
|
| 159 | - elseif (!empty($_REQUEST['boards'])) |
|
| 165 | + } elseif (!empty($_REQUEST['boards'])) |
|
| 160 | 166 | { |
| 161 | 167 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
| 162 | - foreach ($_REQUEST['boards'] as $i => $b) |
|
| 163 | - $_REQUEST['boards'][$i] = (int) $b; |
|
| 168 | + foreach ($_REQUEST['boards'] as $i => $b) { |
|
| 169 | + $_REQUEST['boards'][$i] = (int) $b; |
|
| 170 | + } |
|
| 164 | 171 | |
| 165 | 172 | $request = $smcFunc['db_query']('', ' |
| 166 | 173 | SELECT b.id_board, b.num_posts |
@@ -184,8 +191,9 @@ discard block |
||
| 184 | 191 | } |
| 185 | 192 | $smcFunc['db_free_result']($request); |
| 186 | 193 | |
| 187 | - if (empty($boards)) |
|
| 188 | - fatal_lang_error('error_no_boards_selected'); |
|
| 194 | + if (empty($boards)) { |
|
| 195 | + fatal_lang_error('error_no_boards_selected'); |
|
| 196 | + } |
|
| 189 | 197 | |
| 190 | 198 | $query_this_board = 'b.id_board IN ({array_int:boards})'; |
| 191 | 199 | $query_parameters['boards'] = $boards; |
@@ -199,8 +207,7 @@ discard block |
||
| 199 | 207 | } |
| 200 | 208 | |
| 201 | 209 | $context['page_index'] = constructPageIndex($scripturl . '?action=recent;boards=' . implode(',', $_REQUEST['boards']), $_REQUEST['start'], min(100, $total_posts), 10, false); |
| 202 | - } |
|
| 203 | - elseif (!empty($board)) |
|
| 210 | + } elseif (!empty($board)) |
|
| 204 | 211 | { |
| 205 | 212 | $request = $smcFunc['db_query']('', ' |
| 206 | 213 | SELECT num_posts, redirect |
@@ -233,8 +240,7 @@ discard block |
||
| 233 | 240 | } |
| 234 | 241 | |
| 235 | 242 | $context['page_index'] = constructPageIndex($scripturl . '?action=recent;board=' . $board . '.%1$d', $_REQUEST['start'], min(100, $total_posts), 10, true); |
| 236 | - } |
|
| 237 | - else |
|
| 243 | + } else |
|
| 238 | 244 | { |
| 239 | 245 | $query_this_board = '{query_wanna_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' |
| 240 | 246 | AND b.id_board != {int:recycle_board}' : ''). ' |
@@ -269,8 +275,9 @@ discard block |
||
| 269 | 275 | ); |
| 270 | 276 | |
| 271 | 277 | // If you selected a redirection board, don't try getting posts for it... |
| 272 | - if ($context['is_redirect']) |
|
| 273 | - $messages = 0; |
|
| 278 | + if ($context['is_redirect']) { |
|
| 279 | + $messages = 0; |
|
| 280 | + } |
|
| 274 | 281 | |
| 275 | 282 | $key = 'recent-' . $user_info['id'] . '-' . md5(json_encode(array_diff_key($query_parameters, array('max_id_msg' => 0)))) . '-' . (int) $_REQUEST['start']; |
| 276 | 283 | if (!$context['is_redirect'] && (empty($modSettings['cache_enable']) || ($messages = cache_get_data($key, 120)) == null)) |
@@ -301,16 +308,18 @@ discard block |
||
| 301 | 308 | $query_this_board = str_replace('AND m.id_msg >= {int:max_id_msg}', '', $query_this_board); |
| 302 | 309 | $cache_results = true; |
| 303 | 310 | unset($query_parameters['max_id_msg']); |
| 311 | + } else { |
|
| 312 | + $done = true; |
|
| 304 | 313 | } |
| 305 | - else |
|
| 306 | - $done = true; |
|
| 307 | 314 | } |
| 308 | 315 | $messages = array(); |
| 309 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 310 | - $messages[] = $row['id_msg']; |
|
| 316 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 317 | + $messages[] = $row['id_msg']; |
|
| 318 | + } |
|
| 311 | 319 | $smcFunc['db_free_result']($request); |
| 312 | - if (!empty($cache_results)) |
|
| 313 | - cache_put_data($key, $messages, 120); |
|
| 320 | + if (!empty($cache_results)) { |
|
| 321 | + cache_put_data($key, $messages, 120); |
|
| 322 | + } |
|
| 314 | 323 | } |
| 315 | 324 | |
| 316 | 325 | // Nothing here... Or at least, nothing you can see... |
@@ -397,8 +406,9 @@ discard block |
||
| 397 | 406 | 'css_class' => 'windowbg', |
| 398 | 407 | ); |
| 399 | 408 | |
| 400 | - if ($user_info['id'] == $row['id_first_member']) |
|
| 401 | - $board_ids['own'][$row['id_board']][] = $row['id_msg']; |
|
| 409 | + if ($user_info['id'] == $row['id_first_member']) { |
|
| 410 | + $board_ids['own'][$row['id_board']][] = $row['id_msg']; |
|
| 411 | + } |
|
| 402 | 412 | $board_ids['any'][$row['id_board']][] = $row['id_msg']; |
| 403 | 413 | } |
| 404 | 414 | $smcFunc['db_free_result']($request); |
@@ -424,20 +434,23 @@ discard block |
||
| 424 | 434 | $boards = boardsAllowedTo($permission); |
| 425 | 435 | |
| 426 | 436 | // If 0 is the only thing in the array, they can do it everywhere! |
| 427 | - if (!empty($boards) && $boards[0] == 0) |
|
| 428 | - $boards = array_keys($board_ids[$type]); |
|
| 437 | + if (!empty($boards) && $boards[0] == 0) { |
|
| 438 | + $boards = array_keys($board_ids[$type]); |
|
| 439 | + } |
|
| 429 | 440 | |
| 430 | 441 | // Go through the boards, and look for posts they can do this on. |
| 431 | 442 | foreach ($boards as $board_id) |
| 432 | 443 | { |
| 433 | 444 | // Hmm, they have permission, but there are no topics from that board on this page. |
| 434 | - if (!isset($board_ids[$type][$board_id])) |
|
| 435 | - continue; |
|
| 445 | + if (!isset($board_ids[$type][$board_id])) { |
|
| 446 | + continue; |
|
| 447 | + } |
|
| 436 | 448 | |
| 437 | 449 | // Okay, looks like they can do it for these posts. |
| 438 | - foreach ($board_ids[$type][$board_id] as $counter) |
|
| 439 | - if ($type == 'any' || $context['posts'][$counter]['poster']['id'] == $user_info['id']) |
|
| 450 | + foreach ($board_ids[$type][$board_id] as $counter) { |
|
| 451 | + if ($type == 'any' || $context['posts'][$counter]['poster']['id'] == $user_info['id']) |
|
| 440 | 452 | $context['posts'][$counter][$allowed] = true; |
| 453 | + } |
|
| 441 | 454 | } |
| 442 | 455 | } |
| 443 | 456 | } |
@@ -480,17 +493,19 @@ discard block |
||
| 480 | 493 | $context['showing_all_topics'] = isset($_GET['all']); |
| 481 | 494 | $context['start'] = (int) $_REQUEST['start']; |
| 482 | 495 | $context['topics_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics']; |
| 483 | - if ($_REQUEST['action'] == 'unread') |
|
| 484 | - $context['page_title'] = $context['showing_all_topics'] ? $txt['unread_topics_all'] : $txt['unread_topics_visit']; |
|
| 485 | - else |
|
| 486 | - $context['page_title'] = $txt['unread_replies']; |
|
| 496 | + if ($_REQUEST['action'] == 'unread') { |
|
| 497 | + $context['page_title'] = $context['showing_all_topics'] ? $txt['unread_topics_all'] : $txt['unread_topics_visit']; |
|
| 498 | + } else { |
|
| 499 | + $context['page_title'] = $txt['unread_replies']; |
|
| 500 | + } |
|
| 487 | 501 | |
| 488 | - if ($context['showing_all_topics'] && !empty($context['load_average']) && !empty($modSettings['loadavg_allunread']) && $context['load_average'] >= $modSettings['loadavg_allunread']) |
|
| 489 | - fatal_lang_error('loadavg_allunread_disabled', false); |
|
| 490 | - elseif ($_REQUEST['action'] != 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unreadreplies']) && $context['load_average'] >= $modSettings['loadavg_unreadreplies']) |
|
| 491 | - fatal_lang_error('loadavg_unreadreplies_disabled', false); |
|
| 492 | - elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unread']) && $context['load_average'] >= $modSettings['loadavg_unread']) |
|
| 493 | - fatal_lang_error('loadavg_unread_disabled', false); |
|
| 502 | + if ($context['showing_all_topics'] && !empty($context['load_average']) && !empty($modSettings['loadavg_allunread']) && $context['load_average'] >= $modSettings['loadavg_allunread']) { |
|
| 503 | + fatal_lang_error('loadavg_allunread_disabled', false); |
|
| 504 | + } elseif ($_REQUEST['action'] != 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unreadreplies']) && $context['load_average'] >= $modSettings['loadavg_unreadreplies']) { |
|
| 505 | + fatal_lang_error('loadavg_unreadreplies_disabled', false); |
|
| 506 | + } elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unread']) && $context['load_average'] >= $modSettings['loadavg_unread']) { |
|
| 507 | + fatal_lang_error('loadavg_unread_disabled', false); |
|
| 508 | + } |
|
| 494 | 509 | |
| 495 | 510 | // Parameters for the main query. |
| 496 | 511 | $query_parameters = array(); |
@@ -503,12 +518,14 @@ discard block |
||
| 503 | 518 | if (!empty($_REQUEST['boards'])) |
| 504 | 519 | { |
| 505 | 520 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
| 506 | - foreach ($_REQUEST['boards'] as $b) |
|
| 507 | - $boards[] = (int) $b; |
|
| 521 | + foreach ($_REQUEST['boards'] as $b) { |
|
| 522 | + $boards[] = (int) $b; |
|
| 523 | + } |
|
| 508 | 524 | } |
| 509 | 525 | |
| 510 | - if (!empty($board)) |
|
| 511 | - $boards[] = (int) $board; |
|
| 526 | + if (!empty($board)) { |
|
| 527 | + $boards[] = (int) $board; |
|
| 528 | + } |
|
| 512 | 529 | |
| 513 | 530 | // The easiest thing is to just get all the boards they can see, but since we've specified the top of tree we ignore some of them |
| 514 | 531 | $request = $smcFunc['db_query']('', ' |
@@ -525,30 +542,31 @@ discard block |
||
| 525 | 542 | ) |
| 526 | 543 | ); |
| 527 | 544 | |
| 528 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 529 | - if (in_array($row['id_parent'], $boards)) |
|
| 545 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 546 | + if (in_array($row['id_parent'], $boards)) |
|
| 530 | 547 | $boards[] = $row['id_board']; |
| 548 | + } |
|
| 531 | 549 | |
| 532 | 550 | $smcFunc['db_free_result']($request); |
| 533 | 551 | |
| 534 | - if (empty($boards)) |
|
| 535 | - fatal_lang_error('error_no_boards_selected'); |
|
| 552 | + if (empty($boards)) { |
|
| 553 | + fatal_lang_error('error_no_boards_selected'); |
|
| 554 | + } |
|
| 536 | 555 | |
| 537 | 556 | $query_this_board = 'id_board IN ({array_int:boards})'; |
| 538 | 557 | $query_parameters['boards'] = $boards; |
| 539 | 558 | $context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%d'; |
| 540 | - } |
|
| 541 | - elseif (!empty($board)) |
|
| 559 | + } elseif (!empty($board)) |
|
| 542 | 560 | { |
| 543 | 561 | $query_this_board = 'id_board = {int:board}'; |
| 544 | 562 | $query_parameters['board'] = $board; |
| 545 | 563 | $context['querystring_board_limits'] = ';board=' . $board . '.%1$d'; |
| 546 | - } |
|
| 547 | - elseif (!empty($_REQUEST['boards'])) |
|
| 564 | + } elseif (!empty($_REQUEST['boards'])) |
|
| 548 | 565 | { |
| 549 | 566 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
| 550 | - foreach ($_REQUEST['boards'] as $i => $b) |
|
| 551 | - $_REQUEST['boards'][$i] = (int) $b; |
|
| 567 | + foreach ($_REQUEST['boards'] as $i => $b) { |
|
| 568 | + $_REQUEST['boards'][$i] = (int) $b; |
|
| 569 | + } |
|
| 552 | 570 | |
| 553 | 571 | $request = $smcFunc['db_query']('', ' |
| 554 | 572 | SELECT b.id_board |
@@ -560,22 +578,24 @@ discard block |
||
| 560 | 578 | ) |
| 561 | 579 | ); |
| 562 | 580 | $boards = array(); |
| 563 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 564 | - $boards[] = $row['id_board']; |
|
| 581 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 582 | + $boards[] = $row['id_board']; |
|
| 583 | + } |
|
| 565 | 584 | $smcFunc['db_free_result']($request); |
| 566 | 585 | |
| 567 | - if (empty($boards)) |
|
| 568 | - fatal_lang_error('error_no_boards_selected'); |
|
| 586 | + if (empty($boards)) { |
|
| 587 | + fatal_lang_error('error_no_boards_selected'); |
|
| 588 | + } |
|
| 569 | 589 | |
| 570 | 590 | $query_this_board = 'id_board IN ({array_int:boards})'; |
| 571 | 591 | $query_parameters['boards'] = $boards; |
| 572 | 592 | $context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%1$d'; |
| 573 | - } |
|
| 574 | - elseif (!empty($_REQUEST['c'])) |
|
| 593 | + } elseif (!empty($_REQUEST['c'])) |
|
| 575 | 594 | { |
| 576 | 595 | $_REQUEST['c'] = explode(',', $_REQUEST['c']); |
| 577 | - foreach ($_REQUEST['c'] as $i => $c) |
|
| 578 | - $_REQUEST['c'][$i] = (int) $c; |
|
| 596 | + foreach ($_REQUEST['c'] as $i => $c) { |
|
| 597 | + $_REQUEST['c'][$i] = (int) $c; |
|
| 598 | + } |
|
| 579 | 599 | |
| 580 | 600 | $see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board'; |
| 581 | 601 | $request = $smcFunc['db_query']('', ' |
@@ -588,18 +608,19 @@ discard block |
||
| 588 | 608 | ) |
| 589 | 609 | ); |
| 590 | 610 | $boards = array(); |
| 591 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 592 | - $boards[] = $row['id_board']; |
|
| 611 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 612 | + $boards[] = $row['id_board']; |
|
| 613 | + } |
|
| 593 | 614 | $smcFunc['db_free_result']($request); |
| 594 | 615 | |
| 595 | - if (empty($boards)) |
|
| 596 | - fatal_lang_error('error_no_boards_selected'); |
|
| 616 | + if (empty($boards)) { |
|
| 617 | + fatal_lang_error('error_no_boards_selected'); |
|
| 618 | + } |
|
| 597 | 619 | |
| 598 | 620 | $query_this_board = 'id_board IN ({array_int:boards})'; |
| 599 | 621 | $query_parameters['boards'] = $boards; |
| 600 | 622 | $context['querystring_board_limits'] = ';c=' . implode(',', $_REQUEST['c']) . ';start=%1$d'; |
| 601 | - } |
|
| 602 | - else |
|
| 623 | + } else |
|
| 603 | 624 | { |
| 604 | 625 | $see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board'; |
| 605 | 626 | // Don't bother to show deleted posts! |
@@ -613,12 +634,14 @@ discard block |
||
| 613 | 634 | ) |
| 614 | 635 | ); |
| 615 | 636 | $boards = array(); |
| 616 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 617 | - $boards[] = $row['id_board']; |
|
| 637 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 638 | + $boards[] = $row['id_board']; |
|
| 639 | + } |
|
| 618 | 640 | $smcFunc['db_free_result']($request); |
| 619 | 641 | |
| 620 | - if (empty($boards)) |
|
| 621 | - fatal_lang_error('error_no_boards_available', false); |
|
| 642 | + if (empty($boards)) { |
|
| 643 | + fatal_lang_error('error_no_boards_available', false); |
|
| 644 | + } |
|
| 622 | 645 | |
| 623 | 646 | $query_this_board = 'id_board IN ({array_int:boards})'; |
| 624 | 647 | $query_parameters['boards'] = $boards; |
@@ -680,13 +703,14 @@ discard block |
||
| 680 | 703 | 'name' => $_REQUEST['action'] == 'unread' ? $txt['unread_topics_visit'] : $txt['unread_replies'] |
| 681 | 704 | ); |
| 682 | 705 | |
| 683 | - if ($context['showing_all_topics']) |
|
| 684 | - $context['linktree'][] = array( |
|
| 706 | + if ($context['showing_all_topics']) { |
|
| 707 | + $context['linktree'][] = array( |
|
| 685 | 708 | 'url' => $scripturl . '?action=' . $_REQUEST['action'] . ';all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'], |
| 686 | 709 | 'name' => $txt['unread_topics_all'] |
| 687 | 710 | ); |
| 688 | - else |
|
| 689 | - $txt['unread_topics_visit_none'] = strtr($txt['unread_topics_visit_none'], array('?action=unread;all' => '?action=unread;all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'])); |
|
| 711 | + } else { |
|
| 712 | + $txt['unread_topics_visit_none'] = strtr($txt['unread_topics_visit_none'], array('?action=unread;all' => '?action=unread;all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'])); |
|
| 713 | + } |
|
| 690 | 714 | |
| 691 | 715 | loadTemplate('Recent'); |
| 692 | 716 | loadTemplate('MessageIndex'); |
@@ -694,8 +718,9 @@ discard block |
||
| 694 | 718 | |
| 695 | 719 | // Setup the default topic icons... for checking they exist and the like ;) |
| 696 | 720 | $context['icon_sources'] = array(); |
| 697 | - foreach ($context['stable_icons'] as $icon) |
|
| 698 | - $context['icon_sources'][$icon] = 'images_url'; |
|
| 721 | + foreach ($context['stable_icons'] as $icon) { |
|
| 722 | + $context['icon_sources'][$icon] = 'images_url'; |
|
| 723 | + } |
|
| 699 | 724 | |
| 700 | 725 | $is_topics = $_REQUEST['action'] == 'unread'; |
| 701 | 726 | |
@@ -725,8 +750,7 @@ discard block |
||
| 725 | 750 | ); |
| 726 | 751 | list ($earliest_msg) = $smcFunc['db_fetch_row']($request); |
| 727 | 752 | $smcFunc['db_free_result']($request); |
| 728 | - } |
|
| 729 | - else |
|
| 753 | + } else |
|
| 730 | 754 | { |
| 731 | 755 | $request = $smcFunc['db_query']('', ' |
| 732 | 756 | SELECT MIN(lmr.id_msg) |
@@ -742,14 +766,14 @@ discard block |
||
| 742 | 766 | } |
| 743 | 767 | |
| 744 | 768 | // This is needed in case of topics marked unread. |
| 745 | - if (empty($earliest_msg)) |
|
| 746 | - $earliest_msg = 0; |
|
| 747 | - else |
|
| 769 | + if (empty($earliest_msg)) { |
|
| 770 | + $earliest_msg = 0; |
|
| 771 | + } else |
|
| 748 | 772 | { |
| 749 | 773 | // Using caching, when possible, to ignore the below slow query. |
| 750 | - if (isset($_SESSION['cached_log_time']) && $_SESSION['cached_log_time'][0] + 45 > time()) |
|
| 751 | - $earliest_msg2 = $_SESSION['cached_log_time'][1]; |
|
| 752 | - else |
|
| 774 | + if (isset($_SESSION['cached_log_time']) && $_SESSION['cached_log_time'][0] + 45 > time()) { |
|
| 775 | + $earliest_msg2 = $_SESSION['cached_log_time'][1]; |
|
| 776 | + } else |
|
| 753 | 777 | { |
| 754 | 778 | // This query is pretty slow, but it's needed to ensure nothing crucial is ignored. |
| 755 | 779 | $request = $smcFunc['db_query']('', ' |
@@ -764,8 +788,9 @@ discard block |
||
| 764 | 788 | $smcFunc['db_free_result']($request); |
| 765 | 789 | |
| 766 | 790 | // In theory this could be zero, if the first ever post is unread, so fudge it ;) |
| 767 | - if ($earliest_msg2 == 0) |
|
| 768 | - $earliest_msg2 = -1; |
|
| 791 | + if ($earliest_msg2 == 0) { |
|
| 792 | + $earliest_msg2 = -1; |
|
| 793 | + } |
|
| 769 | 794 | |
| 770 | 795 | $_SESSION['cached_log_time'] = array(time(), $earliest_msg2); |
| 771 | 796 | } |
@@ -803,9 +828,9 @@ discard block |
||
| 803 | 828 | 'db_error_skip' => true, |
| 804 | 829 | )) |
| 805 | 830 | ) !== false; |
| 831 | + } else { |
|
| 832 | + $have_temp_table = false; |
|
| 806 | 833 | } |
| 807 | - else |
|
| 808 | - $have_temp_table = false; |
|
| 809 | 834 | |
| 810 | 835 | if ($context['showing_all_topics'] && $have_temp_table) |
| 811 | 836 | { |
@@ -851,14 +876,15 @@ discard block |
||
| 851 | 876 | |
| 852 | 877 | $context['topics'] = array(); |
| 853 | 878 | $context['no_topic_listing'] = true; |
| 854 | - if ($context['querystring_board_limits'] == ';start=%1$d') |
|
| 855 | - $context['querystring_board_limits'] = ''; |
|
| 856 | - else |
|
| 857 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 879 | + if ($context['querystring_board_limits'] == ';start=%1$d') { |
|
| 880 | + $context['querystring_board_limits'] = ''; |
|
| 881 | + } else { |
|
| 882 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 883 | + } |
|
| 858 | 884 | return; |
| 885 | + } else { |
|
| 886 | + $min_message = (int) $min_message; |
|
| 859 | 887 | } |
| 860 | - else |
|
| 861 | - $min_message = (int) $min_message; |
|
| 862 | 888 | |
| 863 | 889 | $request = $smcFunc['db_query']('substring', ' |
| 864 | 890 | SELECT ' . $select_clause . ' |
@@ -887,8 +913,7 @@ discard block |
||
| 887 | 913 | 'limit' => $context['topics_per_page'], |
| 888 | 914 | )) |
| 889 | 915 | ); |
| 890 | - } |
|
| 891 | - elseif ($is_topics) |
|
| 916 | + } elseif ($is_topics) |
|
| 892 | 917 | { |
| 893 | 918 | $request = $smcFunc['db_query']('', ' |
| 894 | 919 | SELECT COUNT(*), MIN(t.id_last_msg) |
@@ -939,14 +964,15 @@ discard block |
||
| 939 | 964 | |
| 940 | 965 | $context['topics'] = array(); |
| 941 | 966 | $context['no_topic_listing'] = true; |
| 942 | - if ($context['querystring_board_limits'] == ';start=%d') |
|
| 943 | - $context['querystring_board_limits'] = ''; |
|
| 944 | - else |
|
| 945 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 967 | + if ($context['querystring_board_limits'] == ';start=%d') { |
|
| 968 | + $context['querystring_board_limits'] = ''; |
|
| 969 | + } else { |
|
| 970 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 971 | + } |
|
| 946 | 972 | return; |
| 973 | + } else { |
|
| 974 | + $min_message = (int) $min_message; |
|
| 947 | 975 | } |
| 948 | - else |
|
| 949 | - $min_message = (int) $min_message; |
|
| 950 | 976 | |
| 951 | 977 | $request = $smcFunc['db_query']('substring', ' |
| 952 | 978 | SELECT ' . $select_clause . ' |
@@ -976,8 +1002,7 @@ discard block |
||
| 976 | 1002 | 'limit' => $context['topics_per_page'], |
| 977 | 1003 | )) |
| 978 | 1004 | ); |
| 979 | - } |
|
| 980 | - else |
|
| 1005 | + } else |
|
| 981 | 1006 | { |
| 982 | 1007 | if ($modSettings['totalMessages'] > 100000) |
| 983 | 1008 | { |
@@ -1029,8 +1054,8 @@ discard block |
||
| 1029 | 1054 | ) !== false; |
| 1030 | 1055 | |
| 1031 | 1056 | // If that worked, create a sample of the log_topics table too. |
| 1032 | - if ($have_temp_table) |
|
| 1033 | - $have_temp_table = $smcFunc['db_query']('', ' |
|
| 1057 | + if ($have_temp_table) { |
|
| 1058 | + $have_temp_table = $smcFunc['db_query']('', ' |
|
| 1034 | 1059 | CREATE TEMPORARY TABLE {db_prefix}log_topics_posted_in ( |
| 1035 | 1060 | PRIMARY KEY (id_topic) |
| 1036 | 1061 | ) |
@@ -1043,6 +1068,7 @@ discard block |
||
| 1043 | 1068 | 'db_error_skip' => true, |
| 1044 | 1069 | ) |
| 1045 | 1070 | ) !== false; |
| 1071 | + } |
|
| 1046 | 1072 | } |
| 1047 | 1073 | |
| 1048 | 1074 | if (!empty($have_temp_table)) |
@@ -1058,8 +1084,7 @@ discard block |
||
| 1058 | 1084 | ); |
| 1059 | 1085 | list ($num_topics) = $smcFunc['db_fetch_row']($request); |
| 1060 | 1086 | $smcFunc['db_free_result']($request); |
| 1061 | - } |
|
| 1062 | - else |
|
| 1087 | + } else |
|
| 1063 | 1088 | { |
| 1064 | 1089 | $request = $smcFunc['db_query']('unread_fetch_topic_count', ' |
| 1065 | 1090 | SELECT COUNT(DISTINCT t.id_topic), MIN(t.id_last_msg) |
@@ -1100,15 +1125,16 @@ discard block |
||
| 1100 | 1125 | { |
| 1101 | 1126 | $context['topics'] = array(); |
| 1102 | 1127 | $context['no_topic_listing'] = true; |
| 1103 | - if ($context['querystring_board_limits'] == ';start=%d') |
|
| 1104 | - $context['querystring_board_limits'] = ''; |
|
| 1105 | - else |
|
| 1106 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 1128 | + if ($context['querystring_board_limits'] == ';start=%d') { |
|
| 1129 | + $context['querystring_board_limits'] = ''; |
|
| 1130 | + } else { |
|
| 1131 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 1132 | + } |
|
| 1107 | 1133 | return; |
| 1108 | 1134 | } |
| 1109 | 1135 | |
| 1110 | - if (!empty($have_temp_table)) |
|
| 1111 | - $request = $smcFunc['db_query']('', ' |
|
| 1136 | + if (!empty($have_temp_table)) { |
|
| 1137 | + $request = $smcFunc['db_query']('', ' |
|
| 1112 | 1138 | SELECT t.id_topic |
| 1113 | 1139 | FROM {db_prefix}topics_posted_in AS t |
| 1114 | 1140 | LEFT JOIN {db_prefix}log_topics_posted_in AS lt ON (lt.id_topic = t.id_topic) |
@@ -1122,8 +1148,8 @@ discard block |
||
| 1122 | 1148 | 'limit' => $context['topics_per_page'], |
| 1123 | 1149 | )) |
| 1124 | 1150 | ); |
| 1125 | - else |
|
| 1126 | - $request = $smcFunc['db_query']('', ' |
|
| 1151 | + } else { |
|
| 1152 | + $request = $smcFunc['db_query']('', ' |
|
| 1127 | 1153 | SELECT DISTINCT t.id_topic,'.$_REQUEST['sort'].' |
| 1128 | 1154 | FROM {db_prefix}topics AS t |
| 1129 | 1155 | INNER JOIN {db_prefix}messages AS m ON (m.id_topic = t.id_topic AND m.id_member = {int:current_member})' . (strpos($_REQUEST['sort'], 'ms.') === false ? '' : ' |
@@ -1147,10 +1173,12 @@ discard block |
||
| 1147 | 1173 | 'sort' => $_REQUEST['sort'], |
| 1148 | 1174 | )) |
| 1149 | 1175 | ); |
| 1176 | + } |
|
| 1150 | 1177 | |
| 1151 | 1178 | $topics = array(); |
| 1152 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1153 | - $topics[] = $row['id_topic']; |
|
| 1179 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1180 | + $topics[] = $row['id_topic']; |
|
| 1181 | + } |
|
| 1154 | 1182 | $smcFunc['db_free_result']($request); |
| 1155 | 1183 | |
| 1156 | 1184 | // Sanity... where have you gone? |
@@ -1158,10 +1186,11 @@ discard block |
||
| 1158 | 1186 | { |
| 1159 | 1187 | $context['topics'] = array(); |
| 1160 | 1188 | $context['no_topic_listing'] = true; |
| 1161 | - if ($context['querystring_board_limits'] == ';start=%d') |
|
| 1162 | - $context['querystring_board_limits'] = ''; |
|
| 1163 | - else |
|
| 1164 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 1189 | + if ($context['querystring_board_limits'] == ';start=%d') { |
|
| 1190 | + $context['querystring_board_limits'] = ''; |
|
| 1191 | + } else { |
|
| 1192 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 1193 | + } |
|
| 1165 | 1194 | return; |
| 1166 | 1195 | } |
| 1167 | 1196 | |
@@ -1195,8 +1224,9 @@ discard block |
||
| 1195 | 1224 | |
| 1196 | 1225 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1197 | 1226 | { |
| 1198 | - if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') |
|
| 1199 | - continue; |
|
| 1227 | + if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') { |
|
| 1228 | + continue; |
|
| 1229 | + } |
|
| 1200 | 1230 | |
| 1201 | 1231 | $topic_ids[] = $row['id_topic']; |
| 1202 | 1232 | |
@@ -1204,11 +1234,13 @@ discard block |
||
| 1204 | 1234 | { |
| 1205 | 1235 | // Limit them to 128 characters - do this FIRST because it's a lot of wasted censoring otherwise. |
| 1206 | 1236 | $row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => ' '))); |
| 1207 | - if ($smcFunc['strlen']($row['first_body']) > 128) |
|
| 1208 | - $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...'; |
|
| 1237 | + if ($smcFunc['strlen']($row['first_body']) > 128) { |
|
| 1238 | + $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...'; |
|
| 1239 | + } |
|
| 1209 | 1240 | $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => ' '))); |
| 1210 | - if ($smcFunc['strlen']($row['last_body']) > 128) |
|
| 1211 | - $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...'; |
|
| 1241 | + if ($smcFunc['strlen']($row['last_body']) > 128) { |
|
| 1242 | + $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...'; |
|
| 1243 | + } |
|
| 1212 | 1244 | |
| 1213 | 1245 | // Censor the subject and message preview. |
| 1214 | 1246 | censorText($row['first_subject']); |
@@ -1219,23 +1251,22 @@ discard block |
||
| 1219 | 1251 | { |
| 1220 | 1252 | $row['last_subject'] = $row['first_subject']; |
| 1221 | 1253 | $row['last_body'] = $row['first_body']; |
| 1222 | - } |
|
| 1223 | - else |
|
| 1254 | + } else |
|
| 1224 | 1255 | { |
| 1225 | 1256 | censorText($row['last_subject']); |
| 1226 | 1257 | censorText($row['last_body']); |
| 1227 | 1258 | } |
| 1228 | - } |
|
| 1229 | - else |
|
| 1259 | + } else |
|
| 1230 | 1260 | { |
| 1231 | 1261 | $row['first_body'] = ''; |
| 1232 | 1262 | $row['last_body'] = ''; |
| 1233 | 1263 | censorText($row['first_subject']); |
| 1234 | 1264 | |
| 1235 | - if ($row['id_first_msg'] == $row['id_last_msg']) |
|
| 1236 | - $row['last_subject'] = $row['first_subject']; |
|
| 1237 | - else |
|
| 1238 | - censorText($row['last_subject']); |
|
| 1265 | + if ($row['id_first_msg'] == $row['id_last_msg']) { |
|
| 1266 | + $row['last_subject'] = $row['first_subject']; |
|
| 1267 | + } else { |
|
| 1268 | + censorText($row['last_subject']); |
|
| 1269 | + } |
|
| 1239 | 1270 | } |
| 1240 | 1271 | |
| 1241 | 1272 | // Decide how many pages the topic should have. |
@@ -1247,22 +1278,24 @@ discard block |
||
| 1247 | 1278 | $pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $topic_length, $messages_per_page, true, false); |
| 1248 | 1279 | |
| 1249 | 1280 | // If we can use all, show all. |
| 1250 | - if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages']) |
|
| 1251 | - $pages .= ' <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>'; |
|
| 1281 | + if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages']) { |
|
| 1282 | + $pages .= ' <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>'; |
|
| 1283 | + } |
|
| 1284 | + } else { |
|
| 1285 | + $pages = ''; |
|
| 1252 | 1286 | } |
| 1253 | 1287 | |
| 1254 | - else |
|
| 1255 | - $pages = ''; |
|
| 1256 | - |
|
| 1257 | 1288 | // We need to check the topic icons exist... you can never be too sure! |
| 1258 | 1289 | if (!empty($modSettings['messageIconChecks_enable'])) |
| 1259 | 1290 | { |
| 1260 | 1291 | // First icon first... as you'd expect. |
| 1261 | - if (!isset($context['icon_sources'][$row['first_icon']])) |
|
| 1262 | - $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1292 | + if (!isset($context['icon_sources'][$row['first_icon']])) { |
|
| 1293 | + $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1294 | + } |
|
| 1263 | 1295 | // Last icon... last... duh. |
| 1264 | - if (!isset($context['icon_sources'][$row['last_icon']])) |
|
| 1265 | - $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1296 | + if (!isset($context['icon_sources'][$row['last_icon']])) { |
|
| 1297 | + $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1298 | + } |
|
| 1266 | 1299 | } |
| 1267 | 1300 | |
| 1268 | 1301 | // Force the recycling icon if appropriate |
@@ -1276,12 +1309,14 @@ discard block |
||
| 1276 | 1309 | $colorClass = 'windowbg'; |
| 1277 | 1310 | |
| 1278 | 1311 | // Sticky topics should get a different color, too. |
| 1279 | - if ($row['is_sticky']) |
|
| 1280 | - $colorClass .= ' sticky'; |
|
| 1312 | + if ($row['is_sticky']) { |
|
| 1313 | + $colorClass .= ' sticky'; |
|
| 1314 | + } |
|
| 1281 | 1315 | |
| 1282 | 1316 | // Locked topics get special treatment as well. |
| 1283 | - if ($row['locked']) |
|
| 1284 | - $colorClass .= ' locked'; |
|
| 1317 | + if ($row['locked']) { |
|
| 1318 | + $colorClass .= ' locked'; |
|
| 1319 | + } |
|
| 1285 | 1320 | |
| 1286 | 1321 | // And build the array. |
| 1287 | 1322 | $context['topics'][$row['id_topic']] = array( |
@@ -1378,8 +1413,9 @@ discard block |
||
| 1378 | 1413 | ); |
| 1379 | 1414 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 1380 | 1415 | { |
| 1381 | - if (empty($context['topics'][$row['id_topic']]['is_posted_in'])) |
|
| 1382 | - $context['topics'][$row['id_topic']]['is_posted_in'] = true; |
|
| 1416 | + if (empty($context['topics'][$row['id_topic']]['is_posted_in'])) { |
|
| 1417 | + $context['topics'][$row['id_topic']]['is_posted_in'] = true; |
|
| 1418 | + } |
|
| 1383 | 1419 | } |
| 1384 | 1420 | $smcFunc['db_free_result']($result); |
| 1385 | 1421 | } |
@@ -1394,28 +1430,30 @@ discard block |
||
| 1394 | 1430 | 'markread' => array('text' => !empty($context['no_board_limits']) ? 'mark_as_read' : 'mark_read_short', 'image' => 'markread.png', 'custom' => 'data-confirm="'. $txt['are_sure_mark_read'] .'"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=' . (!empty($context['no_board_limits']) ? 'all' : 'board' . $context['querystring_board_limits']) . ';' . $context['session_var'] . '=' . $context['session_id']), |
| 1395 | 1431 | ); |
| 1396 | 1432 | |
| 1397 | - if ($context['showCheckboxes']) |
|
| 1398 | - $context['recent_buttons']['markselectread'] = array( |
|
| 1433 | + if ($context['showCheckboxes']) { |
|
| 1434 | + $context['recent_buttons']['markselectread'] = array( |
|
| 1399 | 1435 | 'text' => 'quick_mod_markread', |
| 1400 | 1436 | 'image' => 'markselectedread.png', |
| 1401 | 1437 | 'url' => 'javascript:document.quickModForm.submit();', |
| 1402 | 1438 | ); |
| 1439 | + } |
|
| 1403 | 1440 | |
| 1404 | - if (!empty($context['topics']) && !$context['showing_all_topics']) |
|
| 1405 | - $context['recent_buttons']['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.png', 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true); |
|
| 1406 | - } |
|
| 1407 | - elseif (!$is_topics && isset($context['topics_to_mark'])) |
|
| 1441 | + if (!empty($context['topics']) && !$context['showing_all_topics']) { |
|
| 1442 | + $context['recent_buttons']['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.png', 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true); |
|
| 1443 | + } |
|
| 1444 | + } elseif (!$is_topics && isset($context['topics_to_mark'])) |
|
| 1408 | 1445 | { |
| 1409 | 1446 | $context['recent_buttons'] = array( |
| 1410 | 1447 | 'markread' => array('text' => 'mark_as_read', 'image' => 'markread.png', 'custom' => 'data-confirm="'. $txt['are_sure_mark_read'] .'"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=unreadreplies;topics=' . $context['topics_to_mark'] . ';' . $context['session_var'] . '=' . $context['session_id']), |
| 1411 | 1448 | ); |
| 1412 | 1449 | |
| 1413 | - if ($context['showCheckboxes']) |
|
| 1414 | - $context['recent_buttons']['markselectread'] = array( |
|
| 1450 | + if ($context['showCheckboxes']) { |
|
| 1451 | + $context['recent_buttons']['markselectread'] = array( |
|
| 1415 | 1452 | 'text' => 'quick_mod_markread', |
| 1416 | 1453 | 'image' => 'markselectedread.png', |
| 1417 | 1454 | 'url' => 'javascript:document.quickModForm.submit();', |
| 1418 | 1455 | ); |
| 1456 | + } |
|
| 1419 | 1457 | } |
| 1420 | 1458 | |
| 1421 | 1459 | // Allow mods to add additional buttons here |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * @version 2.1 Beta 3 |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -if (!defined('SMF')) |
|
| 18 | +if (!defined('SMF')) { |
|
| 19 | 19 | die('No direct access...'); |
| 20 | +} |
|
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * Log an error, if the error logging is enabled. |
@@ -36,8 +37,9 @@ discard block |
||
| 36 | 37 | static $tried_hook = false; |
| 37 | 38 | |
| 38 | 39 | // Check if error logging is actually on. |
| 39 | - if (empty($modSettings['enableErrorLogging'])) |
|
| 40 | - return $error_message; |
|
| 40 | + if (empty($modSettings['enableErrorLogging'])) { |
|
| 41 | + return $error_message; |
|
| 42 | + } |
|
| 41 | 43 | |
| 42 | 44 | // Basically, htmlspecialchars it minus &. (for entities!) |
| 43 | 45 | $error_message = strtr($error_message, array('<' => '<', '>' => '>', '"' => '"')); |
@@ -45,22 +47,26 @@ discard block |
||
| 45 | 47 | |
| 46 | 48 | // Add a file and line to the error message? |
| 47 | 49 | // Don't use the actual txt entries for file and line but instead use %1$s for file and %2$s for line |
| 48 | - if ($file == null) |
|
| 49 | - $file = ''; |
|
| 50 | - else |
|
| 51 | - // Window style slashes don't play well, lets convert them to the unix style. |
|
| 50 | + if ($file == null) { |
|
| 51 | + $file = ''; |
|
| 52 | + } else { |
|
| 53 | + // Window style slashes don't play well, lets convert them to the unix style. |
|
| 52 | 54 | $file = str_replace('\\', '/', $file); |
| 55 | + } |
|
| 53 | 56 | |
| 54 | - if ($line == null) |
|
| 55 | - $line = 0; |
|
| 56 | - else |
|
| 57 | - $line = (int) $line; |
|
| 57 | + if ($line == null) { |
|
| 58 | + $line = 0; |
|
| 59 | + } else { |
|
| 60 | + $line = (int) $line; |
|
| 61 | + } |
|
| 58 | 62 | |
| 59 | 63 | // Just in case there's no id_member or IP set yet. |
| 60 | - if (empty($user_info['id'])) |
|
| 61 | - $user_info['id'] = 0; |
|
| 62 | - if (empty($user_info['ip'])) |
|
| 63 | - $user_info['ip'] = ''; |
|
| 64 | + if (empty($user_info['id'])) { |
|
| 65 | + $user_info['id'] = 0; |
|
| 66 | + } |
|
| 67 | + if (empty($user_info['ip'])) { |
|
| 68 | + $user_info['ip'] = ''; |
|
| 69 | + } |
|
| 64 | 70 | |
| 65 | 71 | // Find the best query string we can... |
| 66 | 72 | $query_string = empty($_SERVER['QUERY_STRING']) ? (empty($_SERVER['REQUEST_URL']) ? '' : str_replace($scripturl, '', $_SERVER['REQUEST_URL'])) : $_SERVER['QUERY_STRING']; |
@@ -69,8 +75,9 @@ discard block |
||
| 69 | 75 | $query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string)); |
| 70 | 76 | |
| 71 | 77 | // Just so we know what board error messages are from. |
| 72 | - if (isset($_POST['board']) && !isset($_GET['board'])) |
|
| 73 | - $query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board']; |
|
| 78 | + if (isset($_POST['board']) && !isset($_GET['board'])) { |
|
| 79 | + $query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board']; |
|
| 80 | + } |
|
| 74 | 81 | |
| 75 | 82 | // What types of categories do we have? |
| 76 | 83 | $known_error_types = array( |
@@ -132,12 +139,14 @@ discard block |
||
| 132 | 139 | global $txt; |
| 133 | 140 | |
| 134 | 141 | // Send the appropriate HTTP status header - set this to 0 or false if you don't want to send one at all |
| 135 | - if (!empty($status)) |
|
| 136 | - send_http_status($status); |
|
| 142 | + if (!empty($status)) { |
|
| 143 | + send_http_status($status); |
|
| 144 | + } |
|
| 137 | 145 | |
| 138 | 146 | // We don't have $txt yet, but that's okay... |
| 139 | - if (empty($txt)) |
|
| 140 | - die($error); |
|
| 147 | + if (empty($txt)) { |
|
| 148 | + die($error); |
|
| 149 | + } |
|
| 141 | 150 | |
| 142 | 151 | log_error_online($error, false); |
| 143 | 152 | setup_fatal_error_context($log ? log_error($error, $log) : $error); |
@@ -164,8 +173,9 @@ discard block |
||
| 164 | 173 | static $fatal_error_called = false; |
| 165 | 174 | |
| 166 | 175 | // Send the status header - set this to 0 or false if you don't want to send one at all |
| 167 | - if (!empty($status)) |
|
| 168 | - send_http_status($status); |
|
| 176 | + if (!empty($status)) { |
|
| 177 | + send_http_status($status); |
|
| 178 | + } |
|
| 169 | 179 | |
| 170 | 180 | // Try to load a theme if we don't have one. |
| 171 | 181 | if (empty($context['theme_loaded']) && empty($fatal_error_called)) |
@@ -175,8 +185,9 @@ discard block |
||
| 175 | 185 | } |
| 176 | 186 | |
| 177 | 187 | // If we have no theme stuff we can't have the language file... |
| 178 | - if (empty($context['theme_loaded'])) |
|
| 179 | - die($error); |
|
| 188 | + if (empty($context['theme_loaded'])) { |
|
| 189 | + die($error); |
|
| 190 | + } |
|
| 180 | 191 | |
| 181 | 192 | $reload_lang_file = true; |
| 182 | 193 | // Log the error in the forum's language, but don't waste the time if we aren't logging |
@@ -212,27 +223,31 @@ discard block |
||
| 212 | 223 | global $settings, $modSettings, $db_show_debug; |
| 213 | 224 | |
| 214 | 225 | // Ignore errors if we're ignoring them or they are strict notices from PHP 5 (which cannot be solved without breaking PHP 4.) |
| 215 | - if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging']))) |
|
| 216 | - return; |
|
| 226 | + if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging']))) { |
|
| 227 | + return; |
|
| 228 | + } |
|
| 217 | 229 | |
| 218 | 230 | if (strpos($file, 'eval()') !== false && !empty($settings['current_include_filename'])) |
| 219 | 231 | { |
| 220 | 232 | $array = debug_backtrace(); |
| 221 | 233 | for ($i = 0; $i < count($array); $i++) |
| 222 | 234 | { |
| 223 | - if ($array[$i]['function'] != 'loadSubTemplate') |
|
| 224 | - continue; |
|
| 235 | + if ($array[$i]['function'] != 'loadSubTemplate') { |
|
| 236 | + continue; |
|
| 237 | + } |
|
| 225 | 238 | |
| 226 | 239 | // This is a bug in PHP, with eval, it seems! |
| 227 | - if (empty($array[$i]['args'])) |
|
| 228 | - $i++; |
|
| 240 | + if (empty($array[$i]['args'])) { |
|
| 241 | + $i++; |
|
| 242 | + } |
|
| 229 | 243 | break; |
| 230 | 244 | } |
| 231 | 245 | |
| 232 | - if (isset($array[$i]) && !empty($array[$i]['args'])) |
|
| 233 | - $file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)'; |
|
| 234 | - else |
|
| 235 | - $file = realpath($settings['current_include_filename']) . ' (eval?)'; |
|
| 246 | + if (isset($array[$i]) && !empty($array[$i]['args'])) { |
|
| 247 | + $file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)'; |
|
| 248 | + } else { |
|
| 249 | + $file = realpath($settings['current_include_filename']) . ' (eval?)'; |
|
| 250 | + } |
|
| 236 | 251 | } |
| 237 | 252 | |
| 238 | 253 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -241,8 +256,9 @@ discard block |
||
| 241 | 256 | if ($error_level % 255 != E_ERROR) |
| 242 | 257 | { |
| 243 | 258 | $temporary = ob_get_contents(); |
| 244 | - if (substr($temporary, -2) == '="') |
|
| 245 | - echo '"'; |
|
| 259 | + if (substr($temporary, -2) == '="') { |
|
| 260 | + echo '"'; |
|
| 261 | + } |
|
| 246 | 262 | } |
| 247 | 263 | |
| 248 | 264 | // Debugging! This should look like a PHP error message. |
@@ -258,23 +274,27 @@ discard block |
||
| 258 | 274 | call_integration_hook('integrate_output_error', array($message, $error_type, $error_level, $file, $line)); |
| 259 | 275 | |
| 260 | 276 | // Dying on these errors only causes MORE problems (blank pages!) |
| 261 | - if ($file == 'Unknown') |
|
| 262 | - return; |
|
| 277 | + if ($file == 'Unknown') { |
|
| 278 | + return; |
|
| 279 | + } |
|
| 263 | 280 | |
| 264 | 281 | // If this is an E_ERROR or E_USER_ERROR.... die. Violently so. |
| 265 | - if ($error_level % 255 == E_ERROR) |
|
| 266 | - obExit(false); |
|
| 267 | - else |
|
| 268 | - return; |
|
| 282 | + if ($error_level % 255 == E_ERROR) { |
|
| 283 | + obExit(false); |
|
| 284 | + } else { |
|
| 285 | + return; |
|
| 286 | + } |
|
| 269 | 287 | |
| 270 | 288 | // If this is an E_ERROR, E_USER_ERROR, E_WARNING, or E_USER_WARNING.... die. Violently so. |
| 271 | - if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) |
|
| 272 | - fatal_error(allowedTo('admin_forum') ? $message : $error_string, false); |
|
| 289 | + if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) { |
|
| 290 | + fatal_error(allowedTo('admin_forum') ? $message : $error_string, false); |
|
| 291 | + } |
|
| 273 | 292 | |
| 274 | 293 | // We should NEVER get to this point. Any fatal error MUST quit, or very bad things can happen. |
| 275 | - if ($error_level % 255 == E_ERROR) |
|
| 276 | - die('No direct access...'); |
|
| 277 | -} |
|
| 294 | + if ($error_level % 255 == E_ERROR) { |
|
| 295 | + die('No direct access...'); |
|
| 296 | + } |
|
| 297 | + } |
|
| 278 | 298 | |
| 279 | 299 | /** |
| 280 | 300 | * It is called by {@link fatal_error()} and {@link fatal_lang_error()}. |
@@ -290,24 +310,28 @@ discard block |
||
| 290 | 310 | |
| 291 | 311 | // Attempt to prevent a recursive loop. |
| 292 | 312 | ++$level; |
| 293 | - if ($level > 1) |
|
| 294 | - return false; |
|
| 313 | + if ($level > 1) { |
|
| 314 | + return false; |
|
| 315 | + } |
|
| 295 | 316 | |
| 296 | 317 | // Maybe they came from dlattach or similar? |
| 297 | - if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) |
|
| 298 | - loadTheme(); |
|
| 318 | + if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) { |
|
| 319 | + loadTheme(); |
|
| 320 | + } |
|
| 299 | 321 | |
| 300 | 322 | // Don't bother indexing errors mate... |
| 301 | 323 | $context['robot_no_index'] = true; |
| 302 | 324 | |
| 303 | - if (!isset($context['error_title'])) |
|
| 304 | - $context['error_title'] = $txt['error_occured']; |
|
| 325 | + if (!isset($context['error_title'])) { |
|
| 326 | + $context['error_title'] = $txt['error_occured']; |
|
| 327 | + } |
|
| 305 | 328 | $context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message; |
| 306 | 329 | |
| 307 | 330 | $context['error_code'] = isset($error_code) ? 'id="' . $error_code . '" ' : ''; |
| 308 | 331 | |
| 309 | - if (empty($context['page_title'])) |
|
| 310 | - $context['page_title'] = $context['error_title']; |
|
| 332 | + if (empty($context['page_title'])) { |
|
| 333 | + $context['page_title'] = $context['error_title']; |
|
| 334 | + } |
|
| 311 | 335 | |
| 312 | 336 | loadTemplate('Errors'); |
| 313 | 337 | $context['sub_template'] = 'fatal_error'; |
@@ -315,23 +339,26 @@ discard block |
||
| 315 | 339 | // If this is SSI, what do they want us to do? |
| 316 | 340 | if (SMF == 'SSI') |
| 317 | 341 | { |
| 318 | - if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) |
|
| 319 | - $ssi_on_error_method(); |
|
| 320 | - elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) |
|
| 321 | - loadSubTemplate('fatal_error'); |
|
| 342 | + if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) { |
|
| 343 | + $ssi_on_error_method(); |
|
| 344 | + } elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) { |
|
| 345 | + loadSubTemplate('fatal_error'); |
|
| 346 | + } |
|
| 322 | 347 | |
| 323 | 348 | // No layers? |
| 324 | - if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) |
|
| 325 | - exit; |
|
| 349 | + if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) { |
|
| 350 | + exit; |
|
| 351 | + } |
|
| 326 | 352 | } |
| 327 | 353 | // Alternatively from the cron call? |
| 328 | 354 | elseif (SMF == 'BACKGROUND') |
| 329 | 355 | { |
| 330 | 356 | // We can't rely on even having language files available. |
| 331 | - if (defined('FROM_CLI') && FROM_CLI) |
|
| 332 | - echo 'cron error: ', $context['error_message']; |
|
| 333 | - else |
|
| 334 | - echo 'An error occurred. More information may be available in your logs.'; |
|
| 357 | + if (defined('FROM_CLI') && FROM_CLI) { |
|
| 358 | + echo 'cron error: ', $context['error_message']; |
|
| 359 | + } else { |
|
| 360 | + echo 'An error occurred. More information may be available in your logs.'; |
|
| 361 | + } |
|
| 335 | 362 | exit; |
| 336 | 363 | } |
| 337 | 364 | |
@@ -359,8 +386,8 @@ discard block |
||
| 359 | 386 | |
| 360 | 387 | set_fatal_error_headers(); |
| 361 | 388 | |
| 362 | - if (!empty($maintenance)) |
|
| 363 | - echo '<!DOCTYPE html> |
|
| 389 | + if (!empty($maintenance)) { |
|
| 390 | + echo '<!DOCTYPE html> |
|
| 364 | 391 | <html> |
| 365 | 392 | <head> |
| 366 | 393 | <meta name="robots" content="noindex"> |
@@ -371,6 +398,7 @@ discard block |
||
| 371 | 398 | ', $mmessage, ' |
| 372 | 399 | </body> |
| 373 | 400 | </html>'; |
| 401 | + } |
|
| 374 | 402 | |
| 375 | 403 | die(); |
| 376 | 404 | } |
@@ -392,15 +420,17 @@ discard block |
||
| 392 | 420 | // For our purposes, we're gonna want this on if at all possible. |
| 393 | 421 | $modSettings['cache_enable'] = '1'; |
| 394 | 422 | |
| 395 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
| 396 | - $db_last_error = max($db_last_error, $temp); |
|
| 423 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
| 424 | + $db_last_error = max($db_last_error, $temp); |
|
| 425 | + } |
|
| 397 | 426 | |
| 398 | 427 | if ($db_last_error < time() - 3600 * 24 * 3 && empty($maintenance) && !empty($db_error_send)) |
| 399 | 428 | { |
| 400 | 429 | // Avoid writing to the Settings.php file if at all possible; use shared memory instead. |
| 401 | 430 | cache_put_data('db_last_error', time(), 600); |
| 402 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
| 403 | - logLastDatabaseError(); |
|
| 431 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
| 432 | + logLastDatabaseError(); |
|
| 433 | + } |
|
| 404 | 434 | |
| 405 | 435 | // Language files aren't loaded yet :(. |
| 406 | 436 | $db_error = @$smcFunc['db_error']($db_connection); |
@@ -481,12 +511,14 @@ discard block |
||
| 481 | 511 | global $smcFunc, $user_info, $modSettings; |
| 482 | 512 | |
| 483 | 513 | // Don't bother if Who's Online is disabled. |
| 484 | - if (empty($modSettings['who_enabled'])) |
|
| 485 | - return; |
|
| 514 | + if (empty($modSettings['who_enabled'])) { |
|
| 515 | + return; |
|
| 516 | + } |
|
| 486 | 517 | |
| 487 | 518 | // Maybe they came from SSI or similar where sessions are not recorded? |
| 488 | - if (SMF == 'SSI' || SMF == 'BACKGROUND') |
|
| 489 | - return; |
|
| 519 | + if (SMF == 'SSI' || SMF == 'BACKGROUND') { |
|
| 520 | + return; |
|
| 521 | + } |
|
| 490 | 522 | |
| 491 | 523 | $session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id(); |
| 492 | 524 | |
@@ -505,8 +537,9 @@ discard block |
||
| 505 | 537 | $url = smf_json_decode($url, true); |
| 506 | 538 | $url['error'] = $error; |
| 507 | 539 | |
| 508 | - if (!empty($sprintf)) |
|
| 509 | - $url['error_params'] = $sprintf; |
|
| 540 | + if (!empty($sprintf)) { |
|
| 541 | + $url['error_params'] = $sprintf; |
|
| 542 | + } |
|
| 510 | 543 | |
| 511 | 544 | $smcFunc['db_query']('', ' |
| 512 | 545 | UPDATE {db_prefix}log_online |
@@ -537,10 +570,11 @@ discard block |
||
| 537 | 570 | |
| 538 | 571 | $protocol = preg_match('~HTTP/1\.[01]~i', $_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'; |
| 539 | 572 | |
| 540 | - if (!isset($statuses[$code])) |
|
| 541 | - header($protocol . ' 500 Internal Server Error'); |
|
| 542 | - else |
|
| 543 | - header($protocol . ' ' . $code . ' ' . $statuses[$code]); |
|
| 544 | -} |
|
| 573 | + if (!isset($statuses[$code])) { |
|
| 574 | + header($protocol . ' 500 Internal Server Error'); |
|
| 575 | + } else { |
|
| 576 | + header($protocol . ' ' . $code . ' ' . $statuses[$code]); |
|
| 577 | + } |
|
| 578 | + } |
|
| 545 | 579 | |
| 546 | 580 | ?> |
| 547 | 581 | \ No newline at end of file |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 3 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * Handles showing the post screen, loading the post to be modified, and loading any post quoted. |
@@ -35,12 +36,14 @@ discard block |
||
| 35 | 36 | global $sourcedir, $smcFunc, $language; |
| 36 | 37 | |
| 37 | 38 | loadLanguage('Post'); |
| 38 | - if (!empty($modSettings['drafts_post_enabled'])) |
|
| 39 | - loadLanguage('Drafts'); |
|
| 39 | + if (!empty($modSettings['drafts_post_enabled'])) { |
|
| 40 | + loadLanguage('Drafts'); |
|
| 41 | + } |
|
| 40 | 42 | |
| 41 | 43 | // You can't reply with a poll... hacker. |
| 42 | - if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) |
|
| 43 | - unset($_REQUEST['poll']); |
|
| 44 | + if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) { |
|
| 45 | + unset($_REQUEST['poll']); |
|
| 46 | + } |
|
| 44 | 47 | |
| 45 | 48 | // Posting an event? |
| 46 | 49 | $context['make_event'] = isset($_REQUEST['calendar']); |
@@ -55,8 +58,9 @@ discard block |
||
| 55 | 58 | $context['auto_notify'] = !empty($context['notify_prefs']['msg_auto_notify']); |
| 56 | 59 | |
| 57 | 60 | // You must be posting to *some* board. |
| 58 | - if (empty($board) && !$context['make_event']) |
|
| 59 | - fatal_lang_error('no_board', false); |
|
| 61 | + if (empty($board) && !$context['make_event']) { |
|
| 62 | + fatal_lang_error('no_board', false); |
|
| 63 | + } |
|
| 60 | 64 | |
| 61 | 65 | require_once($sourcedir . '/Subs-Post.php'); |
| 62 | 66 | |
@@ -79,10 +83,11 @@ discard block |
||
| 79 | 83 | array( |
| 80 | 84 | 'msg' => (int) $_REQUEST['msg'], |
| 81 | 85 | )); |
| 82 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
| 83 | - unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']); |
|
| 84 | - else |
|
| 85 | - list ($topic) = $smcFunc['db_fetch_row']($request); |
|
| 86 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
| 87 | + unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']); |
|
| 88 | + } else { |
|
| 89 | + list ($topic) = $smcFunc['db_fetch_row']($request); |
|
| 90 | + } |
|
| 86 | 91 | $smcFunc['db_free_result']($request); |
| 87 | 92 | } |
| 88 | 93 | |
@@ -109,33 +114,36 @@ discard block |
||
| 109 | 114 | $smcFunc['db_free_result']($request); |
| 110 | 115 | |
| 111 | 116 | // If this topic already has a poll, they sure can't add another. |
| 112 | - if (isset($_REQUEST['poll']) && $pollID > 0) |
|
| 113 | - unset($_REQUEST['poll']); |
|
| 117 | + if (isset($_REQUEST['poll']) && $pollID > 0) { |
|
| 118 | + unset($_REQUEST['poll']); |
|
| 119 | + } |
|
| 114 | 120 | |
| 115 | 121 | if (empty($_REQUEST['msg'])) |
| 116 | 122 | { |
| 117 | - if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) |
|
| 118 | - is_not_guest(); |
|
| 123 | + if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) { |
|
| 124 | + is_not_guest(); |
|
| 125 | + } |
|
| 119 | 126 | |
| 120 | 127 | // By default the reply will be approved... |
| 121 | 128 | $context['becomes_approved'] = true; |
| 122 | 129 | if ($id_member_poster != $user_info['id'] || $user_info['is_guest']) |
| 123 | 130 | { |
| 124 | - if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) |
|
| 125 | - $context['becomes_approved'] = false; |
|
| 126 | - else |
|
| 127 | - isAllowedTo('post_reply_any'); |
|
| 128 | - } |
|
| 129 | - elseif (!allowedTo('post_reply_any')) |
|
| 131 | + if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) { |
|
| 132 | + $context['becomes_approved'] = false; |
|
| 133 | + } else { |
|
| 134 | + isAllowedTo('post_reply_any'); |
|
| 135 | + } |
|
| 136 | + } elseif (!allowedTo('post_reply_any')) |
|
| 130 | 137 | { |
| 131 | - if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) |
|
| 132 | - $context['becomes_approved'] = false; |
|
| 133 | - else |
|
| 134 | - isAllowedTo('post_reply_own'); |
|
| 138 | + if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) { |
|
| 139 | + $context['becomes_approved'] = false; |
|
| 140 | + } else { |
|
| 141 | + isAllowedTo('post_reply_own'); |
|
| 142 | + } |
|
| 135 | 143 | } |
| 144 | + } else { |
|
| 145 | + $context['becomes_approved'] = true; |
|
| 136 | 146 | } |
| 137 | - else |
|
| 138 | - $context['becomes_approved'] = true; |
|
| 139 | 147 | |
| 140 | 148 | $context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own')); |
| 141 | 149 | $context['can_sticky'] = allowedTo('make_sticky'); |
@@ -147,18 +155,19 @@ discard block |
||
| 147 | 155 | $context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky; |
| 148 | 156 | |
| 149 | 157 | // Check whether this is a really old post being bumped... |
| 150 | - if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) |
|
| 151 | - $post_errors[] = array('old_topic', array($modSettings['oldTopicDays'])); |
|
| 152 | - } |
|
| 153 | - else |
|
| 158 | + if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) { |
|
| 159 | + $post_errors[] = array('old_topic', array($modSettings['oldTopicDays'])); |
|
| 160 | + } |
|
| 161 | + } else |
|
| 154 | 162 | { |
| 155 | 163 | $context['becomes_approved'] = true; |
| 156 | 164 | if ((!$context['make_event'] || !empty($board))) |
| 157 | 165 | { |
| 158 | - if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) |
|
| 159 | - $context['becomes_approved'] = false; |
|
| 160 | - else |
|
| 161 | - isAllowedTo('post_new'); |
|
| 166 | + if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) { |
|
| 167 | + $context['becomes_approved'] = false; |
|
| 168 | + } else { |
|
| 169 | + isAllowedTo('post_new'); |
|
| 170 | + } |
|
| 162 | 171 | } |
| 163 | 172 | |
| 164 | 173 | $locked = 0; |
@@ -196,20 +205,24 @@ discard block |
||
| 196 | 205 | } |
| 197 | 206 | |
| 198 | 207 | // Don't allow a post if it's locked and you aren't all powerful. |
| 199 | - if ($locked && !allowedTo('moderate_board')) |
|
| 200 | - fatal_lang_error('topic_locked', false); |
|
| 208 | + if ($locked && !allowedTo('moderate_board')) { |
|
| 209 | + fatal_lang_error('topic_locked', false); |
|
| 210 | + } |
|
| 201 | 211 | // Check the users permissions - is the user allowed to add or post a poll? |
| 202 | 212 | if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1') |
| 203 | 213 | { |
| 204 | 214 | // New topic, new poll. |
| 205 | - if (empty($topic)) |
|
| 206 | - isAllowedTo('poll_post'); |
|
| 215 | + if (empty($topic)) { |
|
| 216 | + isAllowedTo('poll_post'); |
|
| 217 | + } |
|
| 207 | 218 | // This is an old topic - but it is yours! Can you add to it? |
| 208 | - elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) |
|
| 209 | - isAllowedTo('poll_add_own'); |
|
| 219 | + elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) { |
|
| 220 | + isAllowedTo('poll_add_own'); |
|
| 221 | + } |
|
| 210 | 222 | // If you're not the owner, can you add to any poll? |
| 211 | - else |
|
| 212 | - isAllowedTo('poll_add_any'); |
|
| 223 | + else { |
|
| 224 | + isAllowedTo('poll_add_any'); |
|
| 225 | + } |
|
| 213 | 226 | |
| 214 | 227 | require_once($sourcedir . '/Subs-Members.php'); |
| 215 | 228 | $allowedVoteGroups = groupsAllowedTo('poll_vote', $board); |
@@ -238,8 +251,9 @@ discard block |
||
| 238 | 251 | if ($context['make_event']) |
| 239 | 252 | { |
| 240 | 253 | // They might want to pick a board. |
| 241 | - if (!isset($context['current_board'])) |
|
| 242 | - $context['current_board'] = 0; |
|
| 254 | + if (!isset($context['current_board'])) { |
|
| 255 | + $context['current_board'] = 0; |
|
| 256 | + } |
|
| 243 | 257 | |
| 244 | 258 | // Start loading up the event info. |
| 245 | 259 | $context['event'] = array(); |
@@ -277,26 +291,28 @@ discard block |
||
| 277 | 291 | $smcFunc['db_free_result']($request); |
| 278 | 292 | |
| 279 | 293 | // Make sure the user is allowed to edit this event. |
| 280 | - if ($row['id_member'] != $user_info['id']) |
|
| 281 | - isAllowedTo('calendar_edit_any'); |
|
| 282 | - elseif (!allowedTo('calendar_edit_any')) |
|
| 283 | - isAllowedTo('calendar_edit_own'); |
|
| 294 | + if ($row['id_member'] != $user_info['id']) { |
|
| 295 | + isAllowedTo('calendar_edit_any'); |
|
| 296 | + } elseif (!allowedTo('calendar_edit_any')) { |
|
| 297 | + isAllowedTo('calendar_edit_own'); |
|
| 298 | + } |
|
| 284 | 299 | |
| 285 | 300 | $context['event']['month'] = $row['month']; |
| 286 | 301 | $context['event']['day'] = $row['day']; |
| 287 | 302 | $context['event']['year'] = $row['year']; |
| 288 | 303 | $context['event']['title'] = $row['title']; |
| 289 | 304 | $context['event']['span'] = $row['span'] + 1; |
| 290 | - } |
|
| 291 | - else |
|
| 305 | + } else |
|
| 292 | 306 | { |
| 293 | 307 | $today = getdate(); |
| 294 | 308 | |
| 295 | 309 | // You must have a month and year specified! |
| 296 | - if (!isset($_REQUEST['month'])) |
|
| 297 | - $_REQUEST['month'] = $today['mon']; |
|
| 298 | - if (!isset($_REQUEST['year'])) |
|
| 299 | - $_REQUEST['year'] = $today['year']; |
|
| 310 | + if (!isset($_REQUEST['month'])) { |
|
| 311 | + $_REQUEST['month'] = $today['mon']; |
|
| 312 | + } |
|
| 313 | + if (!isset($_REQUEST['year'])) { |
|
| 314 | + $_REQUEST['year'] = $today['year']; |
|
| 315 | + } |
|
| 300 | 316 | |
| 301 | 317 | $context['event']['month'] = (int) $_REQUEST['month']; |
| 302 | 318 | $context['event']['year'] = (int) $_REQUEST['year']; |
@@ -304,15 +320,18 @@ discard block |
||
| 304 | 320 | $context['event']['span'] = isset($_REQUEST['span']) ? $_REQUEST['span'] : 1; |
| 305 | 321 | |
| 306 | 322 | // Make sure the year and month are in the valid range. |
| 307 | - if ($context['event']['month'] < 1 || $context['event']['month'] > 12) |
|
| 308 | - fatal_lang_error('invalid_month', false); |
|
| 309 | - if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) |
|
| 310 | - fatal_lang_error('invalid_year', false); |
|
| 323 | + if ($context['event']['month'] < 1 || $context['event']['month'] > 12) { |
|
| 324 | + fatal_lang_error('invalid_month', false); |
|
| 325 | + } |
|
| 326 | + if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) { |
|
| 327 | + fatal_lang_error('invalid_year', false); |
|
| 328 | + } |
|
| 311 | 329 | |
| 312 | 330 | // Get a list of boards they can post in. |
| 313 | 331 | $boards = boardsAllowedTo('post_new'); |
| 314 | - if (empty($boards)) |
|
| 315 | - fatal_lang_error('cannot_post_new', 'user'); |
|
| 332 | + if (empty($boards)) { |
|
| 333 | + fatal_lang_error('cannot_post_new', 'user'); |
|
| 334 | + } |
|
| 316 | 335 | |
| 317 | 336 | // Load a list of boards for this event in the context. |
| 318 | 337 | require_once($sourcedir . '/Subs-MessageIndex.php'); |
@@ -357,10 +376,11 @@ discard block |
||
| 357 | 376 | |
| 358 | 377 | if (!empty($context['new_replies'])) |
| 359 | 378 | { |
| 360 | - if ($context['new_replies'] == 1) |
|
| 361 | - $txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply']; |
|
| 362 | - else |
|
| 363 | - $txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']); |
|
| 379 | + if ($context['new_replies'] == 1) { |
|
| 380 | + $txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply']; |
|
| 381 | + } else { |
|
| 382 | + $txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']); |
|
| 383 | + } |
|
| 364 | 384 | |
| 365 | 385 | $post_errors[] = 'new_replies'; |
| 366 | 386 | |
@@ -372,9 +392,9 @@ discard block |
||
| 372 | 392 | // Get a response prefix (like 'Re:') in the default forum language. |
| 373 | 393 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
| 374 | 394 | { |
| 375 | - if ($language === $user_info['language']) |
|
| 376 | - $context['response_prefix'] = $txt['response_prefix']; |
|
| 377 | - else |
|
| 395 | + if ($language === $user_info['language']) { |
|
| 396 | + $context['response_prefix'] = $txt['response_prefix']; |
|
| 397 | + } else |
|
| 378 | 398 | { |
| 379 | 399 | loadLanguage('index', $language, false); |
| 380 | 400 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -387,8 +407,9 @@ discard block |
||
| 387 | 407 | // Do we have a body, but an error happened. |
| 388 | 408 | if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error'])) |
| 389 | 409 | { |
| 390 | - if (isset($_REQUEST['quickReply'])) |
|
| 391 | - $_REQUEST['message'] = $_REQUEST['quickReply']; |
|
| 410 | + if (isset($_REQUEST['quickReply'])) { |
|
| 411 | + $_REQUEST['message'] = $_REQUEST['quickReply']; |
|
| 412 | + } |
|
| 392 | 413 | |
| 393 | 414 | // Validate inputs. |
| 394 | 415 | if (empty($context['post_error'])) |
@@ -396,15 +417,17 @@ discard block |
||
| 396 | 417 | // This means they didn't click Post and get an error. |
| 397 | 418 | $really_previewing = true; |
| 398 | 419 | |
| 399 | - } |
|
| 400 | - else |
|
| 420 | + } else |
|
| 401 | 421 | { |
| 402 | - if (!isset($_REQUEST['subject'])) |
|
| 403 | - $_REQUEST['subject'] = ''; |
|
| 404 | - if (!isset($_REQUEST['message'])) |
|
| 405 | - $_REQUEST['message'] = ''; |
|
| 406 | - if (!isset($_REQUEST['icon'])) |
|
| 407 | - $_REQUEST['icon'] = 'xx'; |
|
| 422 | + if (!isset($_REQUEST['subject'])) { |
|
| 423 | + $_REQUEST['subject'] = ''; |
|
| 424 | + } |
|
| 425 | + if (!isset($_REQUEST['message'])) { |
|
| 426 | + $_REQUEST['message'] = ''; |
|
| 427 | + } |
|
| 428 | + if (!isset($_REQUEST['icon'])) { |
|
| 429 | + $_REQUEST['icon'] = 'xx'; |
|
| 430 | + } |
|
| 408 | 431 | |
| 409 | 432 | // They are previewing if they asked to preview (i.e. came from quick reply). |
| 410 | 433 | $really_previewing = !empty($_POST['preview']); |
@@ -420,8 +443,9 @@ discard block |
||
| 420 | 443 | $form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES); |
| 421 | 444 | |
| 422 | 445 | // Make sure the subject isn't too long - taking into account special characters. |
| 423 | - if ($smcFunc['strlen']($form_subject) > 100) |
|
| 424 | - $form_subject = $smcFunc['substr']($form_subject, 0, 100); |
|
| 446 | + if ($smcFunc['strlen']($form_subject) > 100) { |
|
| 447 | + $form_subject = $smcFunc['substr']($form_subject, 0, 100); |
|
| 448 | + } |
|
| 425 | 449 | |
| 426 | 450 | if (isset($_REQUEST['poll'])) |
| 427 | 451 | { |
@@ -433,8 +457,9 @@ discard block |
||
| 433 | 457 | $_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']); |
| 434 | 458 | foreach ($_POST['options'] as $option) |
| 435 | 459 | { |
| 436 | - if (trim($option) == '') |
|
| 437 | - continue; |
|
| 460 | + if (trim($option) == '') { |
|
| 461 | + continue; |
|
| 462 | + } |
|
| 438 | 463 | |
| 439 | 464 | $context['choices'][] = array( |
| 440 | 465 | 'id' => $choice_id++, |
@@ -496,13 +521,14 @@ discard block |
||
| 496 | 521 | $context['preview_subject'] = $form_subject; |
| 497 | 522 | |
| 498 | 523 | censorText($context['preview_subject']); |
| 524 | + } else { |
|
| 525 | + $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>'; |
|
| 499 | 526 | } |
| 500 | - else |
|
| 501 | - $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>'; |
|
| 502 | 527 | |
| 503 | 528 | // Protect any CDATA blocks. |
| 504 | - if (isset($_REQUEST['xml'])) |
|
| 505 | - $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>')); |
|
| 529 | + if (isset($_REQUEST['xml'])) { |
|
| 530 | + $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]>< == 0) |
|
| 545 | - fatal_lang_error('no_board', false); |
|
| 570 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 571 | + fatal_lang_error('no_board', false); |
|
| 572 | + } |
|
| 546 | 573 | $row = $smcFunc['db_fetch_assoc']($request); |
| 547 | 574 | |
| 548 | 575 | $attachment_stuff = array($row); |
| 549 | - while ($row2 = $smcFunc['db_fetch_assoc']($request)) |
|
| 550 | - $attachment_stuff[] = $row2; |
|
| 576 | + while ($row2 = $smcFunc['db_fetch_assoc']($request)) { |
|
| 577 | + $attachment_stuff[] = $row2; |
|
| 578 | + } |
|
| 551 | 579 | $smcFunc['db_free_result']($request); |
| 552 | 580 | |
| 553 | 581 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
| 554 | 582 | { |
| 555 | 583 | // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public. |
| 556 | - if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
| 557 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 558 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) |
|
| 559 | - isAllowedTo('modify_replies'); |
|
| 560 | - else |
|
| 561 | - isAllowedTo('modify_own'); |
|
| 584 | + if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
| 585 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 586 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
| 587 | + isAllowedTo('modify_replies'); |
|
| 588 | + } else { |
|
| 589 | + isAllowedTo('modify_own'); |
|
| 590 | + } |
|
| 591 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) { |
|
| 592 | + isAllowedTo('modify_replies'); |
|
| 593 | + } else { |
|
| 594 | + isAllowedTo('modify_any'); |
|
| 562 | 595 | } |
| 563 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 564 | - isAllowedTo('modify_replies'); |
|
| 565 | - else |
|
| 566 | - isAllowedTo('modify_any'); |
|
| 567 | 596 | |
| 568 | 597 | if ($context['can_announce'] && !empty($row['id_action'])) |
| 569 | 598 | { |
@@ -587,8 +616,9 @@ discard block |
||
| 587 | 616 | |
| 588 | 617 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 589 | 618 | { |
| 590 | - if ($row['filesize'] <= 0) |
|
| 591 | - continue; |
|
| 619 | + if ($row['filesize'] <= 0) { |
|
| 620 | + continue; |
|
| 621 | + } |
|
| 592 | 622 | $context['current_attachments'][$row['id_attach']] = array( |
| 593 | 623 | 'name' => $smcFunc['htmlspecialchars']($row['filename']), |
| 594 | 624 | 'size' => $row['filesize'], |
@@ -658,29 +688,32 @@ discard block |
||
| 658 | 688 | ) |
| 659 | 689 | ); |
| 660 | 690 | // The message they were trying to edit was most likely deleted. |
| 661 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 662 | - fatal_lang_error('no_message', false); |
|
| 691 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 692 | + fatal_lang_error('no_message', false); |
|
| 693 | + } |
|
| 663 | 694 | $row = $smcFunc['db_fetch_assoc']($request); |
| 664 | 695 | |
| 665 | 696 | $attachment_stuff = array($row); |
| 666 | - while ($row2 = $smcFunc['db_fetch_assoc']($request)) |
|
| 667 | - $attachment_stuff[] = $row2; |
|
| 697 | + while ($row2 = $smcFunc['db_fetch_assoc']($request)) { |
|
| 698 | + $attachment_stuff[] = $row2; |
|
| 699 | + } |
|
| 668 | 700 | $smcFunc['db_free_result']($request); |
| 669 | 701 | |
| 670 | 702 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
| 671 | 703 | { |
| 672 | 704 | // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public. |
| 673 | - if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
| 674 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 675 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) |
|
| 676 | - isAllowedTo('modify_replies'); |
|
| 677 | - else |
|
| 678 | - isAllowedTo('modify_own'); |
|
| 705 | + if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
| 706 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 707 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
| 708 | + isAllowedTo('modify_replies'); |
|
| 709 | + } else { |
|
| 710 | + isAllowedTo('modify_own'); |
|
| 711 | + } |
|
| 712 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) { |
|
| 713 | + isAllowedTo('modify_replies'); |
|
| 714 | + } else { |
|
| 715 | + isAllowedTo('modify_any'); |
|
| 679 | 716 | } |
| 680 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 681 | - isAllowedTo('modify_replies'); |
|
| 682 | - else |
|
| 683 | - isAllowedTo('modify_any'); |
|
| 684 | 717 | |
| 685 | 718 | if ($context['can_announce'] && !empty($row['id_action'])) |
| 686 | 719 | { |
@@ -707,15 +740,17 @@ discard block |
||
| 707 | 740 | $context['icon'] = $row['icon']; |
| 708 | 741 | |
| 709 | 742 | // Show an "approve" box if the user can approve it, and the message isn't approved. |
| 710 | - if (!$row['approved'] && !$context['show_approval']) |
|
| 711 | - $context['show_approval'] = allowedTo('approve_posts'); |
|
| 743 | + if (!$row['approved'] && !$context['show_approval']) { |
|
| 744 | + $context['show_approval'] = allowedTo('approve_posts'); |
|
| 745 | + } |
|
| 712 | 746 | |
| 713 | 747 | // Sort the attachments so they are in the order saved |
| 714 | 748 | $temp = array(); |
| 715 | 749 | foreach ($attachment_stuff as $attachment) |
| 716 | 750 | { |
| 717 | - if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) |
|
| 718 | - $temp[$attachment['id_attach']] = $attachment; |
|
| 751 | + if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) { |
|
| 752 | + $temp[$attachment['id_attach']] = $attachment; |
|
| 753 | + } |
|
| 719 | 754 | |
| 720 | 755 | } |
| 721 | 756 | ksort($temp); |
@@ -777,14 +812,16 @@ discard block |
||
| 777 | 812 | 'is_approved' => 1, |
| 778 | 813 | ) |
| 779 | 814 | ); |
| 780 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 781 | - fatal_lang_error('quoted_post_deleted', false); |
|
| 815 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 816 | + fatal_lang_error('quoted_post_deleted', false); |
|
| 817 | + } |
|
| 782 | 818 | list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request); |
| 783 | 819 | $smcFunc['db_free_result']($request); |
| 784 | 820 | |
| 785 | 821 | // Add 'Re: ' to the front of the quoted subject. |
| 786 | - if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
|
| 787 | - $form_subject = $context['response_prefix'] . $form_subject; |
|
| 822 | + if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) { |
|
| 823 | + $form_subject = $context['response_prefix'] . $form_subject; |
|
| 824 | + } |
|
| 788 | 825 | |
| 789 | 826 | // Censor the message and subject. |
| 790 | 827 | censorText($form_message); |
@@ -797,10 +834,11 @@ discard block |
||
| 797 | 834 | for ($i = 0, $n = count($parts); $i < $n; $i++) |
| 798 | 835 | { |
| 799 | 836 | // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat. |
| 800 | - if ($i % 4 == 0) |
|
| 801 | - $parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function ($m) |
|
| 837 | + if ($i % 4 == 0) { |
|
| 838 | + $parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function ($m) |
|
| 802 | 839 | { |
| 803 | 840 | return '[html]' . preg_replace('~<br\s?/?' . '>~i', '<br /><br>', "$m[1]") . '[/html]'; |
| 841 | + } |
|
| 804 | 842 | }, $parts[$i]); |
| 805 | 843 | } |
| 806 | 844 | $form_message = implode('', $parts); |
@@ -809,8 +847,9 @@ discard block |
||
| 809 | 847 | $form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message); |
| 810 | 848 | |
| 811 | 849 | // Remove any nested quotes, if necessary. |
| 812 | - if (!empty($modSettings['removeNestedQuotes'])) |
|
| 813 | - $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
| 850 | + if (!empty($modSettings['removeNestedQuotes'])) { |
|
| 851 | + $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
| 852 | + } |
|
| 814 | 853 | |
| 815 | 854 | // Add a quote string on the front and end. |
| 816 | 855 | $form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]'; |
@@ -822,15 +861,15 @@ discard block |
||
| 822 | 861 | $form_subject = $first_subject; |
| 823 | 862 | |
| 824 | 863 | // Add 'Re: ' to the front of the subject. |
| 825 | - if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
|
| 826 | - $form_subject = $context['response_prefix'] . $form_subject; |
|
| 864 | + if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) { |
|
| 865 | + $form_subject = $context['response_prefix'] . $form_subject; |
|
| 866 | + } |
|
| 827 | 867 | |
| 828 | 868 | // Censor the subject. |
| 829 | 869 | censorText($form_subject); |
| 830 | 870 | |
| 831 | 871 | $form_message = ''; |
| 832 | - } |
|
| 833 | - else |
|
| 872 | + } else |
|
| 834 | 873 | { |
| 835 | 874 | $form_subject = isset($_GET['subject']) ? $_GET['subject'] : ''; |
| 836 | 875 | $form_message = ''; |
@@ -848,13 +887,15 @@ discard block |
||
| 848 | 887 | if (isset($_REQUEST['msg'])) |
| 849 | 888 | { |
| 850 | 889 | $context['attachments']['quantity'] = count($context['current_attachments']); |
| 851 | - foreach ($context['current_attachments'] as $attachment) |
|
| 852 | - $context['attachments']['total_size'] += $attachment['size']; |
|
| 890 | + foreach ($context['current_attachments'] as $attachment) { |
|
| 891 | + $context['attachments']['total_size'] += $attachment['size']; |
|
| 892 | + } |
|
| 853 | 893 | } |
| 854 | 894 | |
| 855 | 895 | // A bit of house keeping first. |
| 856 | - if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) |
|
| 857 | - unset($_SESSION['temp_attachments']); |
|
| 896 | + if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) { |
|
| 897 | + unset($_SESSION['temp_attachments']); |
|
| 898 | + } |
|
| 858 | 899 | |
| 859 | 900 | if (!empty($_SESSION['temp_attachments'])) |
| 860 | 901 | { |
@@ -863,9 +904,10 @@ discard block |
||
| 863 | 904 | { |
| 864 | 905 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
| 865 | 906 | { |
| 866 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
| 867 | - if (file_exists($attachment['tmp_name'])) |
|
| 907 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) { |
|
| 908 | + if (file_exists($attachment['tmp_name'])) |
|
| 868 | 909 | unlink($attachment['tmp_name']); |
| 910 | + } |
|
| 869 | 911 | } |
| 870 | 912 | $post_errors[] = 'temp_attachments_gone'; |
| 871 | 913 | $_SESSION['temp_attachments'] = array(); |
@@ -879,8 +921,9 @@ discard block |
||
| 879 | 921 | // See if any files still exist before showing the warning message and the files attached. |
| 880 | 922 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
| 881 | 923 | { |
| 882 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
|
| 883 | - continue; |
|
| 924 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { |
|
| 925 | + continue; |
|
| 926 | + } |
|
| 884 | 927 | |
| 885 | 928 | if (file_exists($attachment['tmp_name'])) |
| 886 | 929 | { |
@@ -890,20 +933,21 @@ discard block |
||
| 890 | 933 | break; |
| 891 | 934 | } |
| 892 | 935 | } |
| 893 | - } |
|
| 894 | - else |
|
| 936 | + } else |
|
| 895 | 937 | { |
| 896 | 938 | // Since, they don't belong here. Let's inform the user that they exist.. |
| 897 | - if (!empty($topic)) |
|
| 898 | - $delete_url = $scripturl . '?action=post' .(!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp'; |
|
| 899 | - else |
|
| 900 | - $delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp'; |
|
| 939 | + if (!empty($topic)) { |
|
| 940 | + $delete_url = $scripturl . '?action=post' .(!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp'; |
|
| 941 | + } else { |
|
| 942 | + $delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp'; |
|
| 943 | + } |
|
| 901 | 944 | |
| 902 | 945 | // Compile a list of the files to show the user. |
| 903 | 946 | $file_list = array(); |
| 904 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
| 905 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
| 947 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) { |
|
| 948 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
| 906 | 949 | $file_list[] = $attachment['name']; |
| 950 | + } |
|
| 907 | 951 | |
| 908 | 952 | $_SESSION['temp_attachments']['post']['files'] = $file_list; |
| 909 | 953 | $file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>'; |
@@ -915,8 +959,7 @@ discard block |
||
| 915 | 959 | |
| 916 | 960 | $post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list)); |
| 917 | 961 | $context['ignore_temp_attachments'] = true; |
| 918 | - } |
|
| 919 | - else |
|
| 962 | + } else |
|
| 920 | 963 | { |
| 921 | 964 | $post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list)); |
| 922 | 965 | $context['ignore_temp_attachments'] = true; |
@@ -924,16 +967,19 @@ discard block |
||
| 924 | 967 | } |
| 925 | 968 | } |
| 926 | 969 | |
| 927 | - if (!empty($context['we_are_history'])) |
|
| 928 | - $post_errors[] = $context['we_are_history']; |
|
| 970 | + if (!empty($context['we_are_history'])) { |
|
| 971 | + $post_errors[] = $context['we_are_history']; |
|
| 972 | + } |
|
| 929 | 973 | |
| 930 | 974 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
| 931 | 975 | { |
| 932 | - if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) |
|
| 933 | - break; |
|
| 976 | + if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) { |
|
| 977 | + break; |
|
| 978 | + } |
|
| 934 | 979 | |
| 935 | - if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
|
| 936 | - continue; |
|
| 980 | + if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { |
|
| 981 | + continue; |
|
| 982 | + } |
|
| 937 | 983 | |
| 938 | 984 | if ($attachID == 'initial_error') |
| 939 | 985 | { |
@@ -948,15 +994,17 @@ discard block |
||
| 948 | 994 | { |
| 949 | 995 | $txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : ''; |
| 950 | 996 | $txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">'; |
| 951 | - foreach ($attachment['errors'] as $error) |
|
| 952 | - $txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >'; |
|
| 997 | + foreach ($attachment['errors'] as $error) { |
|
| 998 | + $txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >'; |
|
| 999 | + } |
|
| 953 | 1000 | $txt['error_attach_errors'] .= '</div>'; |
| 954 | 1001 | $post_errors[] = 'attach_errors'; |
| 955 | 1002 | |
| 956 | 1003 | // Take out the trash. |
| 957 | 1004 | unset($_SESSION['temp_attachments'][$attachID]); |
| 958 | - if (file_exists($attachment['tmp_name'])) |
|
| 959 | - unlink($attachment['tmp_name']); |
|
| 1005 | + if (file_exists($attachment['tmp_name'])) { |
|
| 1006 | + unlink($attachment['tmp_name']); |
|
| 1007 | + } |
|
| 960 | 1008 | continue; |
| 961 | 1009 | } |
| 962 | 1010 | |
@@ -969,8 +1017,9 @@ discard block |
||
| 969 | 1017 | |
| 970 | 1018 | $context['attachments']['quantity']++; |
| 971 | 1019 | $context['attachments']['total_size'] += $attachment['size']; |
| 972 | - if (!isset($context['files_in_session_warning'])) |
|
| 973 | - $context['files_in_session_warning'] = $txt['attached_files_in_session']; |
|
| 1020 | + if (!isset($context['files_in_session_warning'])) { |
|
| 1021 | + $context['files_in_session_warning'] = $txt['attached_files_in_session']; |
|
| 1022 | + } |
|
| 974 | 1023 | |
| 975 | 1024 | $context['current_attachments'][$attachID] = array( |
| 976 | 1025 | 'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>', |
@@ -998,8 +1047,9 @@ discard block |
||
| 998 | 1047 | } |
| 999 | 1048 | |
| 1000 | 1049 | // If they came from quick reply, and have to enter verification details, give them some notice. |
| 1001 | - if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) |
|
| 1002 | - $post_errors[] = 'need_qr_verification'; |
|
| 1050 | + if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) { |
|
| 1051 | + $post_errors[] = 'need_qr_verification'; |
|
| 1052 | + } |
|
| 1003 | 1053 | |
| 1004 | 1054 | /* |
| 1005 | 1055 | * There are two error types: serious and minor. Serious errors |
@@ -1016,52 +1066,56 @@ discard block |
||
| 1016 | 1066 | { |
| 1017 | 1067 | loadLanguage('Errors'); |
| 1018 | 1068 | $context['error_type'] = 'minor'; |
| 1019 | - foreach ($post_errors as $post_error) |
|
| 1020 | - if (is_array($post_error)) |
|
| 1069 | + foreach ($post_errors as $post_error) { |
|
| 1070 | + if (is_array($post_error)) |
|
| 1021 | 1071 | { |
| 1022 | 1072 | $post_error_id = $post_error[0]; |
| 1073 | + } |
|
| 1023 | 1074 | $context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]); |
| 1024 | 1075 | |
| 1025 | 1076 | // If it's not a minor error flag it as such. |
| 1026 | - if (!in_array($post_error_id, $minor_errors)) |
|
| 1027 | - $context['error_type'] = 'serious'; |
|
| 1028 | - } |
|
| 1029 | - else |
|
| 1077 | + if (!in_array($post_error_id, $minor_errors)) { |
|
| 1078 | + $context['error_type'] = 'serious'; |
|
| 1079 | + } |
|
| 1080 | + } else |
|
| 1030 | 1081 | { |
| 1031 | 1082 | $context['post_error'][$post_error] = $txt['error_' . $post_error]; |
| 1032 | 1083 | |
| 1033 | 1084 | // If it's not a minor error flag it as such. |
| 1034 | - if (!in_array($post_error, $minor_errors)) |
|
| 1035 | - $context['error_type'] = 'serious'; |
|
| 1085 | + if (!in_array($post_error, $minor_errors)) { |
|
| 1086 | + $context['error_type'] = 'serious'; |
|
| 1087 | + } |
|
| 1036 | 1088 | } |
| 1037 | 1089 | } |
| 1038 | 1090 | |
| 1039 | 1091 | // What are you doing? Posting a poll, modifying, previewing, new post, or reply... |
| 1040 | - if (isset($_REQUEST['poll'])) |
|
| 1041 | - $context['page_title'] = $txt['new_poll']; |
|
| 1042 | - elseif ($context['make_event']) |
|
| 1043 | - $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit']; |
|
| 1044 | - elseif (isset($_REQUEST['msg'])) |
|
| 1045 | - $context['page_title'] = $txt['modify_msg']; |
|
| 1046 | - elseif (isset($_REQUEST['subject'], $context['preview_subject'])) |
|
| 1047 | - $context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']); |
|
| 1048 | - elseif (empty($topic)) |
|
| 1049 | - $context['page_title'] = $txt['start_new_topic']; |
|
| 1050 | - else |
|
| 1051 | - $context['page_title'] = $txt['post_reply']; |
|
| 1092 | + if (isset($_REQUEST['poll'])) { |
|
| 1093 | + $context['page_title'] = $txt['new_poll']; |
|
| 1094 | + } elseif ($context['make_event']) { |
|
| 1095 | + $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit']; |
|
| 1096 | + } elseif (isset($_REQUEST['msg'])) { |
|
| 1097 | + $context['page_title'] = $txt['modify_msg']; |
|
| 1098 | + } elseif (isset($_REQUEST['subject'], $context['preview_subject'])) { |
|
| 1099 | + $context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']); |
|
| 1100 | + } elseif (empty($topic)) { |
|
| 1101 | + $context['page_title'] = $txt['start_new_topic']; |
|
| 1102 | + } else { |
|
| 1103 | + $context['page_title'] = $txt['post_reply']; |
|
| 1104 | + } |
|
| 1052 | 1105 | |
| 1053 | 1106 | // Build the link tree. |
| 1054 | - if (empty($topic)) |
|
| 1055 | - $context['linktree'][] = array( |
|
| 1107 | + if (empty($topic)) { |
|
| 1108 | + $context['linktree'][] = array( |
|
| 1056 | 1109 | 'name' => '<em>' . $txt['start_new_topic'] . '</em>' |
| 1057 | 1110 | ); |
| 1058 | - else |
|
| 1059 | - $context['linktree'][] = array( |
|
| 1111 | + } else { |
|
| 1112 | + $context['linktree'][] = array( |
|
| 1060 | 1113 | 'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'], |
| 1061 | 1114 | 'name' => $form_subject, |
| 1062 | 1115 | 'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>', |
| 1063 | 1116 | 'extra_after' => '<span><strong class="nav">)</strong></span>' |
| 1064 | 1117 | ); |
| 1118 | + } |
|
| 1065 | 1119 | |
| 1066 | 1120 | $context['subject'] = addcslashes($form_subject, '"'); |
| 1067 | 1121 | $context['message'] = str_replace(array('"', '<', '>', ' '), array('"', '<', '>', ' '), $form_message); |
@@ -1105,8 +1159,9 @@ discard block |
||
| 1105 | 1159 | // Message icons - customized icons are off? |
| 1106 | 1160 | $context['icons'] = getMessageIcons($board); |
| 1107 | 1161 | |
| 1108 | - if (!empty($context['icons'])) |
|
| 1109 | - $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
| 1162 | + if (!empty($context['icons'])) { |
|
| 1163 | + $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
| 1164 | + } |
|
| 1110 | 1165 | |
| 1111 | 1166 | // Are we starting a poll? if set the poll icon as selected if its available |
| 1112 | 1167 | if (isset($_REQUEST['poll'])) |
@@ -1126,8 +1181,9 @@ discard block |
||
| 1126 | 1181 | for ($i = 0, $n = count($context['icons']); $i < $n; $i++) |
| 1127 | 1182 | { |
| 1128 | 1183 | $context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value']; |
| 1129 | - if ($context['icons'][$i]['selected']) |
|
| 1130 | - $context['icon_url'] = $context['icons'][$i]['url']; |
|
| 1184 | + if ($context['icons'][$i]['selected']) { |
|
| 1185 | + $context['icon_url'] = $context['icons'][$i]['url']; |
|
| 1186 | + } |
|
| 1131 | 1187 | } |
| 1132 | 1188 | if (empty($context['icon_url'])) |
| 1133 | 1189 | { |
@@ -1141,8 +1197,9 @@ discard block |
||
| 1141 | 1197 | )); |
| 1142 | 1198 | } |
| 1143 | 1199 | |
| 1144 | - if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) |
|
| 1145 | - getTopic(); |
|
| 1200 | + if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) { |
|
| 1201 | + getTopic(); |
|
| 1202 | + } |
|
| 1146 | 1203 | |
| 1147 | 1204 | // If the user can post attachments prepare the warning labels. |
| 1148 | 1205 | if ($context['can_post_attachment']) |
@@ -1153,15 +1210,17 @@ discard block |
||
| 1153 | 1210 | $context['attachment_restrictions'] = array(); |
| 1154 | 1211 | $context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', ')); |
| 1155 | 1212 | $attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit'); |
| 1156 | - foreach ($attachmentRestrictionTypes as $type) |
|
| 1157 | - if (!empty($modSettings[$type])) |
|
| 1213 | + foreach ($attachmentRestrictionTypes as $type) { |
|
| 1214 | + if (!empty($modSettings[$type])) |
|
| 1158 | 1215 | { |
| 1159 | 1216 | $context['attachment_restrictions'][] = sprintf($txt['attach_restrict_' . $type . ($modSettings[$type] >= 1024 ? '_MB' : '')], comma_format($modSettings[$type], 0)); |
| 1217 | + } |
|
| 1160 | 1218 | // Show some numbers. If they exist. |
| 1161 | - if ($type == 'attachmentNumPerPostLimit' && $context['attachments']['quantity'] > 0) |
|
| 1162 | - $context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']); |
|
| 1163 | - elseif ($type == 'attachmentPostLimit' && $context['attachments']['total_size'] > 0) |
|
| 1164 | - $context['attachment_restrictions'][] = sprintf($txt['attach_available'], comma_format(round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)), 0)); |
|
| 1219 | + if ($type == 'attachmentNumPerPostLimit' && $context['attachments']['quantity'] > 0) { |
|
| 1220 | + $context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']); |
|
| 1221 | + } elseif ($type == 'attachmentPostLimit' && $context['attachments']['total_size'] > 0) { |
|
| 1222 | + $context['attachment_restrictions'][] = sprintf($txt['attach_available'], comma_format(round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)), 0)); |
|
| 1223 | + } |
|
| 1165 | 1224 | } |
| 1166 | 1225 | } |
| 1167 | 1226 | |
@@ -1195,8 +1254,8 @@ discard block |
||
| 1195 | 1254 | |
| 1196 | 1255 | if (!empty($context['current_attachments'])) |
| 1197 | 1256 | { |
| 1198 | - foreach ($context['current_attachments'] as $key => $mock) |
|
| 1199 | - addInlineJavaScript(' |
|
| 1257 | + foreach ($context['current_attachments'] as $key => $mock) { |
|
| 1258 | + addInlineJavaScript(' |
|
| 1200 | 1259 | current_attachments.push({ |
| 1201 | 1260 | name: '. JavaScriptEscape($mock['name']) .', |
| 1202 | 1261 | size: '. $mock['size'] .', |
@@ -1205,6 +1264,7 @@ discard block |
||
| 1205 | 1264 | type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') .', |
| 1206 | 1265 | thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) .' |
| 1207 | 1266 | });', true); |
| 1267 | + } |
|
| 1208 | 1268 | } |
| 1209 | 1269 | |
| 1210 | 1270 | // File Upload. |
@@ -1249,8 +1309,9 @@ discard block |
||
| 1249 | 1309 | var current_board = '. (empty($context['current_board']) ? 'null' : $context['current_board']) .';', false); |
| 1250 | 1310 | |
| 1251 | 1311 | // Finally, load the template. |
| 1252 | - if (!isset($_REQUEST['xml'])) |
|
| 1253 | - loadTemplate('Post'); |
|
| 1312 | + if (!isset($_REQUEST['xml'])) { |
|
| 1313 | + loadTemplate('Post'); |
|
| 1314 | + } |
|
| 1254 | 1315 | |
| 1255 | 1316 | call_integration_hook('integrate_post_end'); |
| 1256 | 1317 | } |
@@ -1271,13 +1332,14 @@ discard block |
||
| 1271 | 1332 | // Sneaking off, are we? |
| 1272 | 1333 | if (empty($_POST) && empty($topic)) |
| 1273 | 1334 | { |
| 1274 | - if (empty($_SERVER['CONTENT_LENGTH'])) |
|
| 1275 | - redirectexit('action=post;board=' . $board . '.0'); |
|
| 1276 | - else |
|
| 1277 | - fatal_lang_error('post_upload_error', false); |
|
| 1335 | + if (empty($_SERVER['CONTENT_LENGTH'])) { |
|
| 1336 | + redirectexit('action=post;board=' . $board . '.0'); |
|
| 1337 | + } else { |
|
| 1338 | + fatal_lang_error('post_upload_error', false); |
|
| 1339 | + } |
|
| 1340 | + } elseif (empty($_POST) && !empty($topic)) { |
|
| 1341 | + redirectexit('action=post;topic=' . $topic . '.0'); |
|
| 1278 | 1342 | } |
| 1279 | - elseif (empty($_POST) && !empty($topic)) |
|
| 1280 | - redirectexit('action=post;topic=' . $topic . '.0'); |
|
| 1281 | 1343 | |
| 1282 | 1344 | // No need! |
| 1283 | 1345 | $context['robot_no_index'] = true; |
@@ -1289,8 +1351,9 @@ discard block |
||
| 1289 | 1351 | $post_errors = array(); |
| 1290 | 1352 | |
| 1291 | 1353 | // If the session has timed out, let the user re-submit their form. |
| 1292 | - if (checkSession('post', '', false) != '') |
|
| 1293 | - $post_errors[] = 'session_timeout'; |
|
| 1354 | + if (checkSession('post', '', false) != '') { |
|
| 1355 | + $post_errors[] = 'session_timeout'; |
|
| 1356 | + } |
|
| 1294 | 1357 | |
| 1295 | 1358 | // Wrong verification code? |
| 1296 | 1359 | if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1))) |
@@ -1300,33 +1363,38 @@ discard block |
||
| 1300 | 1363 | 'id' => 'post', |
| 1301 | 1364 | ); |
| 1302 | 1365 | $context['require_verification'] = create_control_verification($verificationOptions, true); |
| 1303 | - if (is_array($context['require_verification'])) |
|
| 1304 | - $post_errors = array_merge($post_errors, $context['require_verification']); |
|
| 1366 | + if (is_array($context['require_verification'])) { |
|
| 1367 | + $post_errors = array_merge($post_errors, $context['require_verification']); |
|
| 1368 | + } |
|
| 1305 | 1369 | } |
| 1306 | 1370 | |
| 1307 | 1371 | require_once($sourcedir . '/Subs-Post.php'); |
| 1308 | 1372 | loadLanguage('Post'); |
| 1309 | 1373 | |
| 1310 | 1374 | // Drafts enabled and needed? |
| 1311 | - if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) |
|
| 1312 | - require_once($sourcedir . '/Drafts.php'); |
|
| 1375 | + if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) { |
|
| 1376 | + require_once($sourcedir . '/Drafts.php'); |
|
| 1377 | + } |
|
| 1313 | 1378 | |
| 1314 | 1379 | // First check to see if they are trying to delete any current attachments. |
| 1315 | 1380 | if (isset($_POST['attach_del'])) |
| 1316 | 1381 | { |
| 1317 | 1382 | $keep_temp = array(); |
| 1318 | 1383 | $keep_ids = array(); |
| 1319 | - foreach ($_POST['attach_del'] as $dummy) |
|
| 1320 | - if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false) |
|
| 1384 | + foreach ($_POST['attach_del'] as $dummy) { |
|
| 1385 | + if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false) |
|
| 1321 | 1386 | $keep_temp[] = $dummy; |
| 1322 | - else |
|
| 1323 | - $keep_ids[] = (int) $dummy; |
|
| 1387 | + } |
|
| 1388 | + else { |
|
| 1389 | + $keep_ids[] = (int) $dummy; |
|
| 1390 | + } |
|
| 1324 | 1391 | |
| 1325 | - if (isset($_SESSION['temp_attachments'])) |
|
| 1326 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
| 1392 | + if (isset($_SESSION['temp_attachments'])) { |
|
| 1393 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
| 1327 | 1394 | { |
| 1328 | 1395 | if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
| 1329 | 1396 | continue; |
| 1397 | + } |
|
| 1330 | 1398 | |
| 1331 | 1399 | unset($_SESSION['temp_attachments'][$attachID]); |
| 1332 | 1400 | unlink($attachment['tmp_name']); |
@@ -1368,24 +1436,28 @@ discard block |
||
| 1368 | 1436 | $smcFunc['db_free_result']($request); |
| 1369 | 1437 | |
| 1370 | 1438 | // Though the topic should be there, it might have vanished. |
| 1371 | - if (!is_array($topic_info)) |
|
| 1372 | - fatal_lang_error('topic_doesnt_exist', 404); |
|
| 1439 | + if (!is_array($topic_info)) { |
|
| 1440 | + fatal_lang_error('topic_doesnt_exist', 404); |
|
| 1441 | + } |
|
| 1373 | 1442 | |
| 1374 | 1443 | // Did this topic suddenly move? Just checking... |
| 1375 | - if ($topic_info['id_board'] != $board) |
|
| 1376 | - fatal_lang_error('not_a_topic'); |
|
| 1444 | + if ($topic_info['id_board'] != $board) { |
|
| 1445 | + fatal_lang_error('not_a_topic'); |
|
| 1446 | + } |
|
| 1377 | 1447 | } |
| 1378 | 1448 | |
| 1379 | 1449 | // Replying to a topic? |
| 1380 | 1450 | if (!empty($topic) && !isset($_REQUEST['msg'])) |
| 1381 | 1451 | { |
| 1382 | 1452 | // Don't allow a post if it's locked. |
| 1383 | - if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) |
|
| 1384 | - fatal_lang_error('topic_locked', false); |
|
| 1453 | + if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) { |
|
| 1454 | + fatal_lang_error('topic_locked', false); |
|
| 1455 | + } |
|
| 1385 | 1456 | |
| 1386 | 1457 | // Sorry, multiple polls aren't allowed... yet. You should stop giving me ideas :P. |
| 1387 | - if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) |
|
| 1388 | - unset($_REQUEST['poll']); |
|
| 1458 | + if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) { |
|
| 1459 | + unset($_REQUEST['poll']); |
|
| 1460 | + } |
|
| 1389 | 1461 | |
| 1390 | 1462 | // Do the permissions and approval stuff... |
| 1391 | 1463 | $becomesApproved = true; |
@@ -1401,44 +1473,43 @@ discard block |
||
| 1401 | 1473 | |
| 1402 | 1474 | // Set a nice session var... |
| 1403 | 1475 | $_SESSION['becomesUnapproved'] = true; |
| 1404 | - } |
|
| 1405 | - |
|
| 1406 | - elseif ($topic_info['id_member_started'] != $user_info['id']) |
|
| 1476 | + } elseif ($topic_info['id_member_started'] != $user_info['id']) |
|
| 1407 | 1477 | { |
| 1408 | - if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) |
|
| 1409 | - $becomesApproved = false; |
|
| 1410 | - |
|
| 1411 | - else |
|
| 1412 | - isAllowedTo('post_reply_any'); |
|
| 1413 | - } |
|
| 1414 | - elseif (!allowedTo('post_reply_any')) |
|
| 1478 | + if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) { |
|
| 1479 | + $becomesApproved = false; |
|
| 1480 | + } else { |
|
| 1481 | + isAllowedTo('post_reply_any'); |
|
| 1482 | + } |
|
| 1483 | + } elseif (!allowedTo('post_reply_any')) |
|
| 1415 | 1484 | { |
| 1416 | - if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) |
|
| 1417 | - $becomesApproved = false; |
|
| 1418 | - |
|
| 1419 | - else |
|
| 1420 | - isAllowedTo('post_reply_own'); |
|
| 1485 | + if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) { |
|
| 1486 | + $becomesApproved = false; |
|
| 1487 | + } else { |
|
| 1488 | + isAllowedTo('post_reply_own'); |
|
| 1489 | + } |
|
| 1421 | 1490 | } |
| 1422 | 1491 | |
| 1423 | 1492 | if (isset($_POST['lock'])) |
| 1424 | 1493 | { |
| 1425 | 1494 | // Nothing is changed to the lock. |
| 1426 | - if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) |
|
| 1427 | - unset($_POST['lock']); |
|
| 1495 | + if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) { |
|
| 1496 | + unset($_POST['lock']); |
|
| 1497 | + } |
|
| 1428 | 1498 | |
| 1429 | 1499 | // You're have no permission to lock this topic. |
| 1430 | - elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) |
|
| 1431 | - unset($_POST['lock']); |
|
| 1500 | + elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) { |
|
| 1501 | + unset($_POST['lock']); |
|
| 1502 | + } |
|
| 1432 | 1503 | |
| 1433 | 1504 | // You are allowed to (un)lock your own topic only. |
| 1434 | 1505 | elseif (!allowedTo('lock_any')) |
| 1435 | 1506 | { |
| 1436 | 1507 | // You cannot override a moderator lock. |
| 1437 | - if ($topic_info['locked'] == 1) |
|
| 1438 | - unset($_POST['lock']); |
|
| 1439 | - |
|
| 1440 | - else |
|
| 1441 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 1508 | + if ($topic_info['locked'] == 1) { |
|
| 1509 | + unset($_POST['lock']); |
|
| 1510 | + } else { |
|
| 1511 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 1512 | + } |
|
| 1442 | 1513 | } |
| 1443 | 1514 | // Hail mighty moderator, (un)lock this topic immediately. |
| 1444 | 1515 | else |
@@ -1446,19 +1517,21 @@ discard block |
||
| 1446 | 1517 | $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
| 1447 | 1518 | |
| 1448 | 1519 | // Did someone (un)lock this while you were posting? |
| 1449 | - if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) |
|
| 1450 | - $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
| 1520 | + if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) { |
|
| 1521 | + $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
| 1522 | + } |
|
| 1451 | 1523 | } |
| 1452 | 1524 | } |
| 1453 | 1525 | |
| 1454 | 1526 | // So you wanna (un)sticky this...let's see. |
| 1455 | - if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) |
|
| 1456 | - unset($_POST['sticky']); |
|
| 1457 | - elseif (isset($_POST['sticky'])) |
|
| 1527 | + if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) { |
|
| 1528 | + unset($_POST['sticky']); |
|
| 1529 | + } elseif (isset($_POST['sticky'])) |
|
| 1458 | 1530 | { |
| 1459 | 1531 | // Did someone (un)sticky this while you were posting? |
| 1460 | - if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) |
|
| 1461 | - $post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky'; |
|
| 1532 | + if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) { |
|
| 1533 | + $post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky'; |
|
| 1534 | + } |
|
| 1462 | 1535 | } |
| 1463 | 1536 | |
| 1464 | 1537 | // If drafts are enabled, then pass this off |
@@ -1485,26 +1558,31 @@ discard block |
||
| 1485 | 1558 | |
| 1486 | 1559 | // Do like, the permissions, for safety and stuff... |
| 1487 | 1560 | $becomesApproved = true; |
| 1488 | - if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) |
|
| 1489 | - $becomesApproved = false; |
|
| 1490 | - else |
|
| 1491 | - isAllowedTo('post_new'); |
|
| 1561 | + if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) { |
|
| 1562 | + $becomesApproved = false; |
|
| 1563 | + } else { |
|
| 1564 | + isAllowedTo('post_new'); |
|
| 1565 | + } |
|
| 1492 | 1566 | |
| 1493 | 1567 | if (isset($_POST['lock'])) |
| 1494 | 1568 | { |
| 1495 | 1569 | // New topics are by default not locked. |
| 1496 | - if (empty($_POST['lock'])) |
|
| 1497 | - unset($_POST['lock']); |
|
| 1570 | + if (empty($_POST['lock'])) { |
|
| 1571 | + unset($_POST['lock']); |
|
| 1572 | + } |
|
| 1498 | 1573 | // Besides, you need permission. |
| 1499 | - elseif (!allowedTo(array('lock_any', 'lock_own'))) |
|
| 1500 | - unset($_POST['lock']); |
|
| 1574 | + elseif (!allowedTo(array('lock_any', 'lock_own'))) { |
|
| 1575 | + unset($_POST['lock']); |
|
| 1576 | + } |
|
| 1501 | 1577 | // A moderator-lock (1) can override a user-lock (2). |
| 1502 | - else |
|
| 1503 | - $_POST['lock'] = allowedTo('lock_any') ? 1 : 2; |
|
| 1578 | + else { |
|
| 1579 | + $_POST['lock'] = allowedTo('lock_any') ? 1 : 2; |
|
| 1580 | + } |
|
| 1504 | 1581 | } |
| 1505 | 1582 | |
| 1506 | - if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) |
|
| 1507 | - unset($_POST['sticky']); |
|
| 1583 | + if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) { |
|
| 1584 | + unset($_POST['sticky']); |
|
| 1585 | + } |
|
| 1508 | 1586 | |
| 1509 | 1587 | // Saving your new topic as a draft first? |
| 1510 | 1588 | if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft'])) |
@@ -1529,31 +1607,37 @@ discard block |
||
| 1529 | 1607 | 'id_msg' => $_REQUEST['msg'], |
| 1530 | 1608 | ) |
| 1531 | 1609 | ); |
| 1532 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1533 | - fatal_lang_error('cant_find_messages', false); |
|
| 1610 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1611 | + fatal_lang_error('cant_find_messages', false); |
|
| 1612 | + } |
|
| 1534 | 1613 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1535 | 1614 | $smcFunc['db_free_result']($request); |
| 1536 | 1615 | |
| 1537 | - if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) |
|
| 1538 | - fatal_lang_error('topic_locked', false); |
|
| 1616 | + if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) { |
|
| 1617 | + fatal_lang_error('topic_locked', false); |
|
| 1618 | + } |
|
| 1539 | 1619 | |
| 1540 | 1620 | if (isset($_POST['lock'])) |
| 1541 | 1621 | { |
| 1542 | 1622 | // Nothing changes to the lock status. |
| 1543 | - if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) |
|
| 1544 | - unset($_POST['lock']); |
|
| 1623 | + if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) { |
|
| 1624 | + unset($_POST['lock']); |
|
| 1625 | + } |
|
| 1545 | 1626 | // You're simply not allowed to (un)lock this. |
| 1546 | - elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) |
|
| 1547 | - unset($_POST['lock']); |
|
| 1627 | + elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) { |
|
| 1628 | + unset($_POST['lock']); |
|
| 1629 | + } |
|
| 1548 | 1630 | // You're only allowed to lock your own topics. |
| 1549 | 1631 | elseif (!allowedTo('lock_any')) |
| 1550 | 1632 | { |
| 1551 | 1633 | // You're not allowed to break a moderator's lock. |
| 1552 | - if ($topic_info['locked'] == 1) |
|
| 1553 | - unset($_POST['lock']); |
|
| 1634 | + if ($topic_info['locked'] == 1) { |
|
| 1635 | + unset($_POST['lock']); |
|
| 1636 | + } |
|
| 1554 | 1637 | // Lock it with a soft lock or unlock it. |
| 1555 | - else |
|
| 1556 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 1638 | + else { |
|
| 1639 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 1640 | + } |
|
| 1557 | 1641 | } |
| 1558 | 1642 | // You must be the moderator. |
| 1559 | 1643 | else |
@@ -1561,44 +1645,46 @@ discard block |
||
| 1561 | 1645 | $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
| 1562 | 1646 | |
| 1563 | 1647 | // Did someone (un)lock this while you were posting? |
| 1564 | - if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) |
|
| 1565 | - $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
| 1648 | + if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) { |
|
| 1649 | + $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
| 1650 | + } |
|
| 1566 | 1651 | } |
| 1567 | 1652 | } |
| 1568 | 1653 | |
| 1569 | 1654 | // Change the sticky status of this topic? |
| 1570 | - if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) |
|
| 1571 | - unset($_POST['sticky']); |
|
| 1572 | - elseif (isset($_POST['sticky'])) |
|
| 1655 | + if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) { |
|
| 1656 | + unset($_POST['sticky']); |
|
| 1657 | + } elseif (isset($_POST['sticky'])) |
|
| 1573 | 1658 | { |
| 1574 | 1659 | // Did someone (un)sticky this while you were posting? |
| 1575 | - if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) |
|
| 1576 | - $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied'; |
|
| 1660 | + if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) { |
|
| 1661 | + $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied'; |
|
| 1662 | + } |
|
| 1577 | 1663 | } |
| 1578 | 1664 | |
| 1579 | 1665 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
| 1580 | 1666 | { |
| 1581 | - if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
| 1582 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 1583 | - elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) |
|
| 1584 | - isAllowedTo('modify_replies'); |
|
| 1585 | - else |
|
| 1586 | - isAllowedTo('modify_own'); |
|
| 1587 | - } |
|
| 1588 | - elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 1667 | + if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
| 1668 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 1669 | + } elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
| 1670 | + isAllowedTo('modify_replies'); |
|
| 1671 | + } else { |
|
| 1672 | + isAllowedTo('modify_own'); |
|
| 1673 | + } |
|
| 1674 | + } elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 1589 | 1675 | { |
| 1590 | 1676 | isAllowedTo('modify_replies'); |
| 1591 | 1677 | |
| 1592 | 1678 | // If you're modifying a reply, I say it better be logged... |
| 1593 | 1679 | $moderationAction = true; |
| 1594 | - } |
|
| 1595 | - else |
|
| 1680 | + } else |
|
| 1596 | 1681 | { |
| 1597 | 1682 | isAllowedTo('modify_any'); |
| 1598 | 1683 | |
| 1599 | 1684 | // Log it, assuming you're not modifying your own post. |
| 1600 | - if ($row['id_member'] != $user_info['id']) |
|
| 1601 | - $moderationAction = true; |
|
| 1685 | + if ($row['id_member'] != $user_info['id']) { |
|
| 1686 | + $moderationAction = true; |
|
| 1687 | + } |
|
| 1602 | 1688 | } |
| 1603 | 1689 | |
| 1604 | 1690 | // If drafts are enabled, then lets send this off to save |
@@ -1635,20 +1721,24 @@ discard block |
||
| 1635 | 1721 | $_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']); |
| 1636 | 1722 | $_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']); |
| 1637 | 1723 | |
| 1638 | - if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') |
|
| 1639 | - $post_errors[] = 'no_name'; |
|
| 1640 | - if ($smcFunc['strlen']($_POST['guestname']) > 25) |
|
| 1641 | - $post_errors[] = 'long_name'; |
|
| 1724 | + if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') { |
|
| 1725 | + $post_errors[] = 'no_name'; |
|
| 1726 | + } |
|
| 1727 | + if ($smcFunc['strlen']($_POST['guestname']) > 25) { |
|
| 1728 | + $post_errors[] = 'long_name'; |
|
| 1729 | + } |
|
| 1642 | 1730 | |
| 1643 | 1731 | if (empty($modSettings['guest_post_no_email'])) |
| 1644 | 1732 | { |
| 1645 | 1733 | // Only check if they changed it! |
| 1646 | 1734 | if (!isset($row) || $row['poster_email'] != $_POST['email']) |
| 1647 | 1735 | { |
| 1648 | - if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) |
|
| 1649 | - $post_errors[] = 'no_email'; |
|
| 1650 | - if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) |
|
| 1651 | - $post_errors[] = 'bad_email'; |
|
| 1736 | + if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) { |
|
| 1737 | + $post_errors[] = 'no_email'; |
|
| 1738 | + } |
|
| 1739 | + if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { |
|
| 1740 | + $post_errors[] = 'bad_email'; |
|
| 1741 | + } |
|
| 1652 | 1742 | } |
| 1653 | 1743 | |
| 1654 | 1744 | // Now make sure this email address is not banned from posting. |
@@ -1664,75 +1754,89 @@ discard block |
||
| 1664 | 1754 | } |
| 1665 | 1755 | |
| 1666 | 1756 | // Coming from the quickReply? |
| 1667 | - if(isset($_POST['quickReply'])) |
|
| 1668 | - $_POST['message'] = $_POST['quickReply']; |
|
| 1757 | + if(isset($_POST['quickReply'])) { |
|
| 1758 | + $_POST['message'] = $_POST['quickReply']; |
|
| 1759 | + } |
|
| 1669 | 1760 | |
| 1670 | 1761 | // Check the subject and message. |
| 1671 | - if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') |
|
| 1672 | - $post_errors[] = 'no_subject'; |
|
| 1673 | - if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') |
|
| 1674 | - $post_errors[] = 'no_message'; |
|
| 1675 | - elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) |
|
| 1676 | - $post_errors[] = array('long_message', array($modSettings['max_messageLength'])); |
|
| 1677 | - else |
|
| 1762 | + if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') { |
|
| 1763 | + $post_errors[] = 'no_subject'; |
|
| 1764 | + } |
|
| 1765 | + if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') { |
|
| 1766 | + $post_errors[] = 'no_message'; |
|
| 1767 | + } elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) { |
|
| 1768 | + $post_errors[] = array('long_message', array($modSettings['max_messageLength'])); |
|
| 1769 | + } else |
|
| 1678 | 1770 | { |
| 1679 | 1771 | // Prepare the message a bit for some additional testing. |
| 1680 | 1772 | $_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES); |
| 1681 | 1773 | |
| 1682 | 1774 | // Preparse code. (Zef) |
| 1683 | - if ($user_info['is_guest']) |
|
| 1684 | - $user_info['name'] = $_POST['guestname']; |
|
| 1775 | + if ($user_info['is_guest']) { |
|
| 1776 | + $user_info['name'] = $_POST['guestname']; |
|
| 1777 | + } |
|
| 1685 | 1778 | preparsecode($_POST['message']); |
| 1686 | 1779 | |
| 1687 | 1780 | // Let's see if there's still some content left without the tags. |
| 1688 | - if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) |
|
| 1689 | - $post_errors[] = 'no_message'; |
|
| 1781 | + if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) { |
|
| 1782 | + $post_errors[] = 'no_message'; |
|
| 1783 | + } |
|
| 1784 | + } |
|
| 1785 | + if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') { |
|
| 1786 | + $post_errors[] = 'no_event'; |
|
| 1690 | 1787 | } |
| 1691 | - if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') |
|
| 1692 | - $post_errors[] = 'no_event'; |
|
| 1693 | 1788 | // You are not! |
| 1694 | - if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) |
|
| 1695 | - fatal_error('Knave! Masquerader! Charlatan!', false); |
|
| 1789 | + if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) { |
|
| 1790 | + fatal_error('Knave! Masquerader! Charlatan!', false); |
|
| 1791 | + } |
|
| 1696 | 1792 | |
| 1697 | 1793 | // Validate the poll... |
| 1698 | 1794 | if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1') |
| 1699 | 1795 | { |
| 1700 | - if (!empty($topic) && !isset($_REQUEST['msg'])) |
|
| 1701 | - fatal_lang_error('no_access', false); |
|
| 1796 | + if (!empty($topic) && !isset($_REQUEST['msg'])) { |
|
| 1797 | + fatal_lang_error('no_access', false); |
|
| 1798 | + } |
|
| 1702 | 1799 | |
| 1703 | 1800 | // This is a new topic... so it's a new poll. |
| 1704 | - if (empty($topic)) |
|
| 1705 | - isAllowedTo('poll_post'); |
|
| 1801 | + if (empty($topic)) { |
|
| 1802 | + isAllowedTo('poll_post'); |
|
| 1803 | + } |
|
| 1706 | 1804 | // Can you add to your own topics? |
| 1707 | - elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) |
|
| 1708 | - isAllowedTo('poll_add_own'); |
|
| 1805 | + elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) { |
|
| 1806 | + isAllowedTo('poll_add_own'); |
|
| 1807 | + } |
|
| 1709 | 1808 | // Can you add polls to any topic, then? |
| 1710 | - else |
|
| 1711 | - isAllowedTo('poll_add_any'); |
|
| 1809 | + else { |
|
| 1810 | + isAllowedTo('poll_add_any'); |
|
| 1811 | + } |
|
| 1712 | 1812 | |
| 1713 | - if (!isset($_POST['question']) || trim($_POST['question']) == '') |
|
| 1714 | - $post_errors[] = 'no_question'; |
|
| 1813 | + if (!isset($_POST['question']) || trim($_POST['question']) == '') { |
|
| 1814 | + $post_errors[] = 'no_question'; |
|
| 1815 | + } |
|
| 1715 | 1816 | |
| 1716 | 1817 | $_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']); |
| 1717 | 1818 | |
| 1718 | 1819 | // Get rid of empty ones. |
| 1719 | - foreach ($_POST['options'] as $k => $option) |
|
| 1720 | - if ($option == '') |
|
| 1820 | + foreach ($_POST['options'] as $k => $option) { |
|
| 1821 | + if ($option == '') |
|
| 1721 | 1822 | unset($_POST['options'][$k], $_POST['options'][$k]); |
| 1823 | + } |
|
| 1722 | 1824 | |
| 1723 | 1825 | // What are you going to vote between with one choice?!? |
| 1724 | - if (count($_POST['options']) < 2) |
|
| 1725 | - $post_errors[] = 'poll_few'; |
|
| 1726 | - elseif (count($_POST['options']) > 256) |
|
| 1727 | - $post_errors[] = 'poll_many'; |
|
| 1826 | + if (count($_POST['options']) < 2) { |
|
| 1827 | + $post_errors[] = 'poll_few'; |
|
| 1828 | + } elseif (count($_POST['options']) > 256) { |
|
| 1829 | + $post_errors[] = 'poll_many'; |
|
| 1830 | + } |
|
| 1728 | 1831 | } |
| 1729 | 1832 | |
| 1730 | 1833 | if ($posterIsGuest) |
| 1731 | 1834 | { |
| 1732 | 1835 | // If user is a guest, make sure the chosen name isn't taken. |
| 1733 | 1836 | require_once($sourcedir . '/Subs-Members.php'); |
| 1734 | - if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) |
|
| 1735 | - $post_errors[] = 'bad_name'; |
|
| 1837 | + if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) { |
|
| 1838 | + $post_errors[] = 'bad_name'; |
|
| 1839 | + } |
|
| 1736 | 1840 | } |
| 1737 | 1841 | // If the user isn't a guest, get his or her name and email. |
| 1738 | 1842 | elseif (!isset($_REQUEST['msg'])) |
@@ -1763,8 +1867,9 @@ discard block |
||
| 1763 | 1867 | } |
| 1764 | 1868 | |
| 1765 | 1869 | // Make sure the user isn't spamming the board. |
| 1766 | - if (!isset($_REQUEST['msg'])) |
|
| 1767 | - spamProtection('post'); |
|
| 1870 | + if (!isset($_REQUEST['msg'])) { |
|
| 1871 | + spamProtection('post'); |
|
| 1872 | + } |
|
| 1768 | 1873 | |
| 1769 | 1874 | // At about this point, we're posting and that's that. |
| 1770 | 1875 | ignore_user_abort(true); |
@@ -1777,32 +1882,36 @@ discard block |
||
| 1777 | 1882 | $_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => '')); |
| 1778 | 1883 | |
| 1779 | 1884 | // At this point, we want to make sure the subject isn't too long. |
| 1780 | - if ($smcFunc['strlen']($_POST['subject']) > 100) |
|
| 1781 | - $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
| 1885 | + if ($smcFunc['strlen']($_POST['subject']) > 100) { |
|
| 1886 | + $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
| 1887 | + } |
|
| 1782 | 1888 | |
| 1783 | 1889 | // Same with the "why did you edit this" text. |
| 1784 | - if ($smcFunc['strlen']($_POST['modify_reason']) > 100) |
|
| 1785 | - $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
| 1890 | + if ($smcFunc['strlen']($_POST['modify_reason']) > 100) { |
|
| 1891 | + $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
| 1892 | + } |
|
| 1786 | 1893 | |
| 1787 | 1894 | // Make the poll... |
| 1788 | 1895 | if (isset($_REQUEST['poll'])) |
| 1789 | 1896 | { |
| 1790 | 1897 | // Make sure that the user has not entered a ridiculous number of options.. |
| 1791 | - if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) |
|
| 1792 | - $_POST['poll_max_votes'] = 1; |
|
| 1793 | - elseif ($_POST['poll_max_votes'] > count($_POST['options'])) |
|
| 1794 | - $_POST['poll_max_votes'] = count($_POST['options']); |
|
| 1795 | - else |
|
| 1796 | - $_POST['poll_max_votes'] = (int) $_POST['poll_max_votes']; |
|
| 1898 | + if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) { |
|
| 1899 | + $_POST['poll_max_votes'] = 1; |
|
| 1900 | + } elseif ($_POST['poll_max_votes'] > count($_POST['options'])) { |
|
| 1901 | + $_POST['poll_max_votes'] = count($_POST['options']); |
|
| 1902 | + } else { |
|
| 1903 | + $_POST['poll_max_votes'] = (int) $_POST['poll_max_votes']; |
|
| 1904 | + } |
|
| 1797 | 1905 | |
| 1798 | 1906 | $_POST['poll_expire'] = (int) $_POST['poll_expire']; |
| 1799 | 1907 | $_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']); |
| 1800 | 1908 | |
| 1801 | 1909 | // Just set it to zero if it's not there.. |
| 1802 | - if (!isset($_POST['poll_hide'])) |
|
| 1803 | - $_POST['poll_hide'] = 0; |
|
| 1804 | - else |
|
| 1805 | - $_POST['poll_hide'] = (int) $_POST['poll_hide']; |
|
| 1910 | + if (!isset($_POST['poll_hide'])) { |
|
| 1911 | + $_POST['poll_hide'] = 0; |
|
| 1912 | + } else { |
|
| 1913 | + $_POST['poll_hide'] = (int) $_POST['poll_hide']; |
|
| 1914 | + } |
|
| 1806 | 1915 | $_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0; |
| 1807 | 1916 | |
| 1808 | 1917 | $_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0; |
@@ -1811,16 +1920,19 @@ discard block |
||
| 1811 | 1920 | { |
| 1812 | 1921 | require_once($sourcedir . '/Subs-Members.php'); |
| 1813 | 1922 | $allowedVoteGroups = groupsAllowedTo('poll_vote', $board); |
| 1814 | - if (!in_array(-1, $allowedVoteGroups['allowed'])) |
|
| 1815 | - $_POST['poll_guest_vote'] = 0; |
|
| 1923 | + if (!in_array(-1, $allowedVoteGroups['allowed'])) { |
|
| 1924 | + $_POST['poll_guest_vote'] = 0; |
|
| 1925 | + } |
|
| 1816 | 1926 | } |
| 1817 | 1927 | |
| 1818 | 1928 | // If the user tries to set the poll too far in advance, don't let them. |
| 1819 | - if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) |
|
| 1820 | - fatal_lang_error('poll_range_error', false); |
|
| 1929 | + if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) { |
|
| 1930 | + fatal_lang_error('poll_range_error', false); |
|
| 1931 | + } |
|
| 1821 | 1932 | // Don't allow them to select option 2 for hidden results if it's not time limited. |
| 1822 | - elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) |
|
| 1823 | - $_POST['poll_hide'] = 1; |
|
| 1933 | + elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) { |
|
| 1934 | + $_POST['poll_hide'] = 1; |
|
| 1935 | + } |
|
| 1824 | 1936 | |
| 1825 | 1937 | // Clean up the question and answers. |
| 1826 | 1938 | $_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']); |
@@ -1834,13 +1946,15 @@ discard block |
||
| 1834 | 1946 | { |
| 1835 | 1947 | $attachIDs = array(); |
| 1836 | 1948 | $attach_errors = array(); |
| 1837 | - if (!empty($context['we_are_history'])) |
|
| 1838 | - $attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>'; |
|
| 1949 | + if (!empty($context['we_are_history'])) { |
|
| 1950 | + $attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>'; |
|
| 1951 | + } |
|
| 1839 | 1952 | |
| 1840 | 1953 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
| 1841 | 1954 | { |
| 1842 | - if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
|
| 1843 | - continue; |
|
| 1955 | + if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { |
|
| 1956 | + continue; |
|
| 1957 | + } |
|
| 1844 | 1958 | |
| 1845 | 1959 | // If there was an initial error just show that message. |
| 1846 | 1960 | if ($attachID == 'initial_error') |
@@ -1869,12 +1983,13 @@ discard block |
||
| 1869 | 1983 | if (createAttachment($attachmentOptions)) |
| 1870 | 1984 | { |
| 1871 | 1985 | $attachIDs[] = $attachmentOptions['id']; |
| 1872 | - if (!empty($attachmentOptions['thumb'])) |
|
| 1873 | - $attachIDs[] = $attachmentOptions['thumb']; |
|
| 1986 | + if (!empty($attachmentOptions['thumb'])) { |
|
| 1987 | + $attachIDs[] = $attachmentOptions['thumb']; |
|
| 1988 | + } |
|
| 1874 | 1989 | } |
| 1990 | + } else { |
|
| 1991 | + $attach_errors[] = '<dt> </dt>'; |
|
| 1875 | 1992 | } |
| 1876 | - else |
|
| 1877 | - $attach_errors[] = '<dt> </dt>'; |
|
| 1878 | 1993 | |
| 1879 | 1994 | if (!empty($attachmentOptions['errors'])) |
| 1880 | 1995 | { |
@@ -1886,14 +2001,16 @@ discard block |
||
| 1886 | 2001 | if (!is_array($error)) |
| 1887 | 2002 | { |
| 1888 | 2003 | $attach_errors[] = '<dd>' . $txt[$error] . '</dd>'; |
| 1889 | - if (in_array($error, $log_these)) |
|
| 1890 | - log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
| 2004 | + if (in_array($error, $log_these)) { |
|
| 2005 | + log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
| 2006 | + } |
|
| 2007 | + } else { |
|
| 2008 | + $attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>'; |
|
| 1891 | 2009 | } |
| 1892 | - else |
|
| 1893 | - $attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>'; |
|
| 1894 | 2010 | } |
| 1895 | - if (file_exists($attachment['tmp_name'])) |
|
| 1896 | - unlink($attachment['tmp_name']); |
|
| 2011 | + if (file_exists($attachment['tmp_name'])) { |
|
| 2012 | + unlink($attachment['tmp_name']); |
|
| 2013 | + } |
|
| 1897 | 2014 | } |
| 1898 | 2015 | } |
| 1899 | 2016 | unset($_SESSION['temp_attachments']); |
@@ -1934,24 +2051,24 @@ discard block |
||
| 1934 | 2051 | ); |
| 1935 | 2052 | |
| 1936 | 2053 | call_integration_hook('integrate_poll_add_edit', array($id_poll, false)); |
| 2054 | + } else { |
|
| 2055 | + $id_poll = 0; |
|
| 1937 | 2056 | } |
| 1938 | - else |
|
| 1939 | - $id_poll = 0; |
|
| 1940 | 2057 | |
| 1941 | 2058 | // Creating a new topic? |
| 1942 | 2059 | $newTopic = empty($_REQUEST['msg']) && empty($topic); |
| 1943 | 2060 | |
| 1944 | 2061 | // Check the icon. |
| 1945 | - if (!isset($_POST['icon'])) |
|
| 1946 | - $_POST['icon'] = 'xx'; |
|
| 1947 | - |
|
| 1948 | - else |
|
| 2062 | + if (!isset($_POST['icon'])) { |
|
| 2063 | + $_POST['icon'] = 'xx'; |
|
| 2064 | + } else |
|
| 1949 | 2065 | { |
| 1950 | 2066 | $_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']); |
| 1951 | 2067 | |
| 1952 | 2068 | // Need to figure it out if this is a valid icon name. |
| 1953 | - if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) |
|
| 1954 | - $_POST['icon'] = 'xx'; |
|
| 2069 | + if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) { |
|
| 2070 | + $_POST['icon'] = 'xx'; |
|
| 2071 | + } |
|
| 1955 | 2072 | } |
| 1956 | 2073 | |
| 1957 | 2074 | // Collect all parameters for the creation or modification of a post. |
@@ -1992,8 +2109,9 @@ discard block |
||
| 1992 | 2109 | } |
| 1993 | 2110 | |
| 1994 | 2111 | // This will save some time... |
| 1995 | - if (empty($approve_has_changed)) |
|
| 1996 | - unset($msgOptions['approved']); |
|
| 2112 | + if (empty($approve_has_changed)) { |
|
| 2113 | + unset($msgOptions['approved']); |
|
| 2114 | + } |
|
| 1997 | 2115 | |
| 1998 | 2116 | modifyPost($msgOptions, $topicOptions, $posterOptions); |
| 1999 | 2117 | } |
@@ -2002,8 +2120,9 @@ discard block |
||
| 2002 | 2120 | { |
| 2003 | 2121 | createPost($msgOptions, $topicOptions, $posterOptions); |
| 2004 | 2122 | |
| 2005 | - if (isset($topicOptions['id'])) |
|
| 2006 | - $topic = $topicOptions['id']; |
|
| 2123 | + if (isset($topicOptions['id'])) { |
|
| 2124 | + $topic = $topicOptions['id']; |
|
| 2125 | + } |
|
| 2007 | 2126 | } |
| 2008 | 2127 | |
| 2009 | 2128 | // Assign the previously uploaded attachments to the brand new message. |
@@ -2015,8 +2134,9 @@ discard block |
||
| 2015 | 2134 | } |
| 2016 | 2135 | |
| 2017 | 2136 | // If we had a draft for this, its time to remove it since it was just posted |
| 2018 | - if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) |
|
| 2019 | - DeleteDraft($_POST['id_draft']); |
|
| 2137 | + if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) { |
|
| 2138 | + DeleteDraft($_POST['id_draft']); |
|
| 2139 | + } |
|
| 2020 | 2140 | |
| 2021 | 2141 | // Editing or posting an event? |
| 2022 | 2142 | if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1)) |
@@ -2036,8 +2156,7 @@ discard block |
||
| 2036 | 2156 | 'span' => isset($_POST['span']) && $_POST['span'] > 0 ? min((int) $modSettings['cal_maxspan'], (int) $_POST['span'] - 1) : 0, |
| 2037 | 2157 | ); |
| 2038 | 2158 | insertEvent($eventOptions); |
| 2039 | - } |
|
| 2040 | - elseif (isset($_POST['calendar'])) |
|
| 2159 | + } elseif (isset($_POST['calendar'])) |
|
| 2041 | 2160 | { |
| 2042 | 2161 | $_REQUEST['eventid'] = (int) $_REQUEST['eventid']; |
| 2043 | 2162 | |
@@ -2065,14 +2184,15 @@ discard block |
||
| 2065 | 2184 | } |
| 2066 | 2185 | |
| 2067 | 2186 | // Delete it? |
| 2068 | - if (isset($_REQUEST['deleteevent'])) |
|
| 2069 | - $smcFunc['db_query']('', ' |
|
| 2187 | + if (isset($_REQUEST['deleteevent'])) { |
|
| 2188 | + $smcFunc['db_query']('', ' |
|
| 2070 | 2189 | DELETE FROM {db_prefix}calendar |
| 2071 | 2190 | WHERE id_event = {int:id_event}', |
| 2072 | 2191 | array( |
| 2073 | 2192 | 'id_event' => $_REQUEST['eventid'], |
| 2074 | 2193 | ) |
| 2075 | 2194 | ); |
| 2195 | + } |
|
| 2076 | 2196 | // ... or just update it? |
| 2077 | 2197 | else |
| 2078 | 2198 | { |
@@ -2116,9 +2236,8 @@ discard block |
||
| 2116 | 2236 | array($user_info['id'], $topic, 0), |
| 2117 | 2237 | array('id_member', 'id_topic', 'id_board') |
| 2118 | 2238 | ); |
| 2119 | - } |
|
| 2120 | - elseif (!$newTopic) |
|
| 2121 | - $smcFunc['db_query']('', ' |
|
| 2239 | + } elseif (!$newTopic) { |
|
| 2240 | + $smcFunc['db_query']('', ' |
|
| 2122 | 2241 | DELETE FROM {db_prefix}log_notify |
| 2123 | 2242 | WHERE id_member = {int:current_member} |
| 2124 | 2243 | AND id_topic = {int:current_topic}', |
@@ -2127,16 +2246,20 @@ discard block |
||
| 2127 | 2246 | 'current_topic' => $topic, |
| 2128 | 2247 | ) |
| 2129 | 2248 | ); |
| 2249 | + } |
|
| 2130 | 2250 | |
| 2131 | 2251 | // Log an act of moderation - modifying. |
| 2132 | - if (!empty($moderationAction)) |
|
| 2133 | - logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
| 2252 | + if (!empty($moderationAction)) { |
|
| 2253 | + logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
| 2254 | + } |
|
| 2134 | 2255 | |
| 2135 | - if (isset($_POST['lock']) && $_POST['lock'] != 2) |
|
| 2136 | - logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
| 2256 | + if (isset($_POST['lock']) && $_POST['lock'] != 2) { |
|
| 2257 | + logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
| 2258 | + } |
|
| 2137 | 2259 | |
| 2138 | - if (isset($_POST['sticky'])) |
|
| 2139 | - logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
| 2260 | + if (isset($_POST['sticky'])) { |
|
| 2261 | + logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
| 2262 | + } |
|
| 2140 | 2263 | |
| 2141 | 2264 | // Returning to the topic? |
| 2142 | 2265 | if (!empty($_REQUEST['goback'])) |
@@ -2155,26 +2278,31 @@ discard block |
||
| 2155 | 2278 | ); |
| 2156 | 2279 | } |
| 2157 | 2280 | |
| 2158 | - if ($board_info['num_topics'] == 0) |
|
| 2159 | - cache_put_data('board-' . $board, null, 120); |
|
| 2281 | + if ($board_info['num_topics'] == 0) { |
|
| 2282 | + cache_put_data('board-' . $board, null, 120); |
|
| 2283 | + } |
|
| 2160 | 2284 | |
| 2161 | 2285 | call_integration_hook('integrate_post2_end'); |
| 2162 | 2286 | |
| 2163 | - if (!empty($_POST['announce_topic'])) |
|
| 2164 | - redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2287 | + if (!empty($_POST['announce_topic'])) { |
|
| 2288 | + redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2289 | + } |
|
| 2165 | 2290 | |
| 2166 | - if (!empty($_POST['move']) && allowedTo('move_any')) |
|
| 2167 | - redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2291 | + if (!empty($_POST['move']) && allowedTo('move_any')) { |
|
| 2292 | + redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2293 | + } |
|
| 2168 | 2294 | |
| 2169 | 2295 | // Return to post if the mod is on. |
| 2170 | - if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) |
|
| 2171 | - redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie')); |
|
| 2172 | - elseif (!empty($_REQUEST['goback'])) |
|
| 2173 | - redirectexit('topic=' . $topic . '.new#new', isBrowser('ie')); |
|
| 2296 | + if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) { |
|
| 2297 | + redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie')); |
|
| 2298 | + } elseif (!empty($_REQUEST['goback'])) { |
|
| 2299 | + redirectexit('topic=' . $topic . '.new#new', isBrowser('ie')); |
|
| 2300 | + } |
|
| 2174 | 2301 | // Dut-dut-duh-duh-DUH-duh-dut-duh-duh! *dances to the Final Fantasy Fanfare...* |
| 2175 | - else |
|
| 2176 | - redirectexit('board=' . $board . '.0'); |
|
| 2177 | -} |
|
| 2302 | + else { |
|
| 2303 | + redirectexit('board=' . $board . '.0'); |
|
| 2304 | + } |
|
| 2305 | + } |
|
| 2178 | 2306 | |
| 2179 | 2307 | /** |
| 2180 | 2308 | * Handle the announce topic function (action=announce). |
@@ -2192,8 +2320,9 @@ discard block |
||
| 2192 | 2320 | |
| 2193 | 2321 | validateSession(); |
| 2194 | 2322 | |
| 2195 | - if (empty($topic)) |
|
| 2196 | - fatal_lang_error('topic_gone', false); |
|
| 2323 | + if (empty($topic)) { |
|
| 2324 | + fatal_lang_error('topic_gone', false); |
|
| 2325 | + } |
|
| 2197 | 2326 | |
| 2198 | 2327 | loadLanguage('Post'); |
| 2199 | 2328 | loadTemplate('Post'); |
@@ -2220,8 +2349,9 @@ discard block |
||
| 2220 | 2349 | global $txt, $context, $topic, $board, $board_info, $smcFunc; |
| 2221 | 2350 | |
| 2222 | 2351 | $groups = array_merge($board_info['groups'], array(1)); |
| 2223 | - foreach ($groups as $id => $group) |
|
| 2224 | - $groups[$id] = (int) $group; |
|
| 2352 | + foreach ($groups as $id => $group) { |
|
| 2353 | + $groups[$id] = (int) $group; |
|
| 2354 | + } |
|
| 2225 | 2355 | |
| 2226 | 2356 | $context['groups'] = array(); |
| 2227 | 2357 | if (in_array(0, $groups)) |
@@ -2264,8 +2394,9 @@ discard block |
||
| 2264 | 2394 | 'group_list' => $groups, |
| 2265 | 2395 | ) |
| 2266 | 2396 | ); |
| 2267 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2268 | - $context['groups'][$row['id_group']]['name'] = $row['group_name']; |
|
| 2397 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2398 | + $context['groups'][$row['id_group']]['name'] = $row['group_name']; |
|
| 2399 | + } |
|
| 2269 | 2400 | $smcFunc['db_free_result']($request); |
| 2270 | 2401 | |
| 2271 | 2402 | // Get the subject of the topic we're about to announce. |
@@ -2307,16 +2438,19 @@ discard block |
||
| 2307 | 2438 | $context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start']; |
| 2308 | 2439 | $groups = array_merge($board_info['groups'], array(1)); |
| 2309 | 2440 | |
| 2310 | - if (isset($_POST['membergroups'])) |
|
| 2311 | - $_POST['who'] = explode(',', $_POST['membergroups']); |
|
| 2441 | + if (isset($_POST['membergroups'])) { |
|
| 2442 | + $_POST['who'] = explode(',', $_POST['membergroups']); |
|
| 2443 | + } |
|
| 2312 | 2444 | |
| 2313 | 2445 | // Check whether at least one membergroup was selected. |
| 2314 | - if (empty($_POST['who'])) |
|
| 2315 | - fatal_lang_error('no_membergroup_selected'); |
|
| 2446 | + if (empty($_POST['who'])) { |
|
| 2447 | + fatal_lang_error('no_membergroup_selected'); |
|
| 2448 | + } |
|
| 2316 | 2449 | |
| 2317 | 2450 | // Make sure all membergroups are integers and can access the board of the announcement. |
| 2318 | - foreach ($_POST['who'] as $id => $mg) |
|
| 2319 | - $_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0; |
|
| 2451 | + foreach ($_POST['who'] as $id => $mg) { |
|
| 2452 | + $_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0; |
|
| 2453 | + } |
|
| 2320 | 2454 | |
| 2321 | 2455 | // Get the topic subject and censor it. |
| 2322 | 2456 | $request = $smcFunc['db_query']('', ' |
@@ -2362,12 +2496,13 @@ discard block |
||
| 2362 | 2496 | if ($smcFunc['db_num_rows']($request) == 0) |
| 2363 | 2497 | { |
| 2364 | 2498 | logAction('announce_topic', array('topic' => $topic), 'user'); |
| 2365 | - if (!empty($_REQUEST['move']) && allowedTo('move_any')) |
|
| 2366 | - redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2367 | - elseif (!empty($_REQUEST['goback'])) |
|
| 2368 | - redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie')); |
|
| 2369 | - else |
|
| 2370 | - redirectexit('board=' . $board . '.0'); |
|
| 2499 | + if (!empty($_REQUEST['move']) && allowedTo('move_any')) { |
|
| 2500 | + redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2501 | + } elseif (!empty($_REQUEST['goback'])) { |
|
| 2502 | + redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie')); |
|
| 2503 | + } else { |
|
| 2504 | + redirectexit('board=' . $board . '.0'); |
|
| 2505 | + } |
|
| 2371 | 2506 | } |
| 2372 | 2507 | |
| 2373 | 2508 | $announcements = array(); |
@@ -2386,8 +2521,9 @@ discard block |
||
| 2386 | 2521 | foreach ($rows as $row) |
| 2387 | 2522 | { |
| 2388 | 2523 | // Force them to have it? |
| 2389 | - if (empty($prefs[$row['id_member']]['announcements'])) |
|
| 2390 | - continue; |
|
| 2524 | + if (empty($prefs[$row['id_member']]['announcements'])) { |
|
| 2525 | + continue; |
|
| 2526 | + } |
|
| 2391 | 2527 | |
| 2392 | 2528 | $cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']; |
| 2393 | 2529 | |
@@ -2415,8 +2551,9 @@ discard block |
||
| 2415 | 2551 | } |
| 2416 | 2552 | |
| 2417 | 2553 | // For each language send a different mail - low priority... |
| 2418 | - foreach ($announcements as $lang => $mail) |
|
| 2419 | - sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5); |
|
| 2554 | + foreach ($announcements as $lang => $mail) { |
|
| 2555 | + sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5); |
|
| 2556 | + } |
|
| 2420 | 2557 | |
| 2421 | 2558 | $context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1); |
| 2422 | 2559 | |
@@ -2426,9 +2563,10 @@ discard block |
||
| 2426 | 2563 | $context['sub_template'] = 'announcement_send'; |
| 2427 | 2564 | |
| 2428 | 2565 | // Go back to the correct language for the user ;). |
| 2429 | - if (!empty($modSettings['userLanguage'])) |
|
| 2430 | - loadLanguage('Post'); |
|
| 2431 | -} |
|
| 2566 | + if (!empty($modSettings['userLanguage'])) { |
|
| 2567 | + loadLanguage('Post'); |
|
| 2568 | + } |
|
| 2569 | + } |
|
| 2432 | 2570 | |
| 2433 | 2571 | /** |
| 2434 | 2572 | * Get the topic for display purposes. |
@@ -2441,12 +2579,13 @@ discard block |
||
| 2441 | 2579 | { |
| 2442 | 2580 | global $topic, $modSettings, $context, $smcFunc, $counter, $options; |
| 2443 | 2581 | |
| 2444 | - if (isset($_REQUEST['xml'])) |
|
| 2445 | - $limit = ' |
|
| 2582 | + if (isset($_REQUEST['xml'])) { |
|
| 2583 | + $limit = ' |
|
| 2446 | 2584 | LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']); |
| 2447 | - else |
|
| 2448 | - $limit = empty($modSettings['topicSummaryPosts']) ? '' : ' |
|
| 2585 | + } else { |
|
| 2586 | + $limit = empty($modSettings['topicSummaryPosts']) ? '' : ' |
|
| 2449 | 2587 | LIMIT ' . (int) $modSettings['topicSummaryPosts']; |
| 2588 | + } |
|
| 2450 | 2589 | |
| 2451 | 2590 | // If you're modifying, get only those posts before the current one. (otherwise get all.) |
| 2452 | 2591 | $request = $smcFunc['db_query']('', ' |
@@ -2484,8 +2623,9 @@ discard block |
||
| 2484 | 2623 | 'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']), |
| 2485 | 2624 | ); |
| 2486 | 2625 | |
| 2487 | - if (!empty($context['new_replies'])) |
|
| 2488 | - $context['new_replies']--; |
|
| 2626 | + if (!empty($context['new_replies'])) { |
|
| 2627 | + $context['new_replies']--; |
|
| 2628 | + } |
|
| 2489 | 2629 | } |
| 2490 | 2630 | $smcFunc['db_free_result']($request); |
| 2491 | 2631 | } |
@@ -2502,8 +2642,9 @@ discard block |
||
| 2502 | 2642 | global $sourcedir, $smcFunc; |
| 2503 | 2643 | |
| 2504 | 2644 | loadLanguage('Post'); |
| 2505 | - if (!isset($_REQUEST['xml'])) |
|
| 2506 | - loadTemplate('Post'); |
|
| 2645 | + if (!isset($_REQUEST['xml'])) { |
|
| 2646 | + loadTemplate('Post'); |
|
| 2647 | + } |
|
| 2507 | 2648 | |
| 2508 | 2649 | include_once($sourcedir . '/Subs-Post.php'); |
| 2509 | 2650 | |
@@ -2534,8 +2675,9 @@ discard block |
||
| 2534 | 2675 | $smcFunc['db_free_result']($request); |
| 2535 | 2676 | |
| 2536 | 2677 | $context['sub_template'] = 'quotefast'; |
| 2537 | - if (!empty($row)) |
|
| 2538 | - $can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']); |
|
| 2678 | + if (!empty($row)) { |
|
| 2679 | + $can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']); |
|
| 2680 | + } |
|
| 2539 | 2681 | |
| 2540 | 2682 | if (!empty($can_view_post)) |
| 2541 | 2683 | { |
@@ -2568,8 +2710,9 @@ discard block |
||
| 2568 | 2710 | } |
| 2569 | 2711 | |
| 2570 | 2712 | // Remove any nested quotes. |
| 2571 | - if (!empty($modSettings['removeNestedQuotes'])) |
|
| 2572 | - $row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']); |
|
| 2713 | + if (!empty($modSettings['removeNestedQuotes'])) { |
|
| 2714 | + $row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']); |
|
| 2715 | + } |
|
| 2573 | 2716 | |
| 2574 | 2717 | $lb = "\n"; |
| 2575 | 2718 | |
@@ -2595,14 +2738,14 @@ discard block |
||
| 2595 | 2738 | 'time' => '', |
| 2596 | 2739 | ), |
| 2597 | 2740 | ); |
| 2598 | - } |
|
| 2599 | - else |
|
| 2600 | - $context['quote'] = array( |
|
| 2741 | + } else { |
|
| 2742 | + $context['quote'] = array( |
|
| 2601 | 2743 | 'xml' => '', |
| 2602 | 2744 | 'mozilla' => '', |
| 2603 | 2745 | 'text' => '', |
| 2604 | 2746 | ); |
| 2605 | -} |
|
| 2747 | + } |
|
| 2748 | + } |
|
| 2606 | 2749 | |
| 2607 | 2750 | /** |
| 2608 | 2751 | * Used to edit the body or subject of a message inline |
@@ -2614,8 +2757,9 @@ discard block |
||
| 2614 | 2757 | global $user_info, $context, $smcFunc, $language, $board_info; |
| 2615 | 2758 | |
| 2616 | 2759 | // We have to have a topic! |
| 2617 | - if (empty($topic)) |
|
| 2618 | - obExit(false); |
|
| 2760 | + if (empty($topic)) { |
|
| 2761 | + obExit(false); |
|
| 2762 | + } |
|
| 2619 | 2763 | |
| 2620 | 2764 | checkSession('get'); |
| 2621 | 2765 | require_once($sourcedir . '/Subs-Post.php'); |
@@ -2641,31 +2785,35 @@ discard block |
||
| 2641 | 2785 | 'guest_id' => 0, |
| 2642 | 2786 | ) |
| 2643 | 2787 | ); |
| 2644 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 2645 | - fatal_lang_error('no_board', false); |
|
| 2788 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 2789 | + fatal_lang_error('no_board', false); |
|
| 2790 | + } |
|
| 2646 | 2791 | $row = $smcFunc['db_fetch_assoc']($request); |
| 2647 | 2792 | $smcFunc['db_free_result']($request); |
| 2648 | 2793 | |
| 2649 | 2794 | // Change either body or subject requires permissions to modify messages. |
| 2650 | 2795 | if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon'])) |
| 2651 | 2796 | { |
| 2652 | - if (!empty($row['locked'])) |
|
| 2653 | - isAllowedTo('moderate_board'); |
|
| 2797 | + if (!empty($row['locked'])) { |
|
| 2798 | + isAllowedTo('moderate_board'); |
|
| 2799 | + } |
|
| 2654 | 2800 | |
| 2655 | 2801 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
| 2656 | 2802 | { |
| 2657 | - if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
| 2658 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 2659 | - elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) |
|
| 2660 | - isAllowedTo('modify_replies'); |
|
| 2661 | - else |
|
| 2662 | - isAllowedTo('modify_own'); |
|
| 2803 | + if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
| 2804 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 2805 | + } elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
| 2806 | + isAllowedTo('modify_replies'); |
|
| 2807 | + } else { |
|
| 2808 | + isAllowedTo('modify_own'); |
|
| 2809 | + } |
|
| 2663 | 2810 | } |
| 2664 | 2811 | // Otherwise, they're locked out; someone who can modify the replies is needed. |
| 2665 | - elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 2666 | - isAllowedTo('modify_replies'); |
|
| 2667 | - else |
|
| 2668 | - isAllowedTo('modify_any'); |
|
| 2812 | + elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) { |
|
| 2813 | + isAllowedTo('modify_replies'); |
|
| 2814 | + } else { |
|
| 2815 | + isAllowedTo('modify_any'); |
|
| 2816 | + } |
|
| 2669 | 2817 | |
| 2670 | 2818 | // Only log this action if it wasn't your message. |
| 2671 | 2819 | $moderationAction = $row['id_member'] != $user_info['id']; |
@@ -2677,10 +2825,10 @@ discard block |
||
| 2677 | 2825 | $_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => '')); |
| 2678 | 2826 | |
| 2679 | 2827 | // Maximum number of characters. |
| 2680 | - if ($smcFunc['strlen']($_POST['subject']) > 100) |
|
| 2681 | - $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
| 2682 | - } |
|
| 2683 | - elseif (isset($_POST['subject'])) |
|
| 2828 | + if ($smcFunc['strlen']($_POST['subject']) > 100) { |
|
| 2829 | + $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
| 2830 | + } |
|
| 2831 | + } elseif (isset($_POST['subject'])) |
|
| 2684 | 2832 | { |
| 2685 | 2833 | $post_errors[] = 'no_subject'; |
| 2686 | 2834 | unset($_POST['subject']); |
@@ -2692,13 +2840,11 @@ discard block |
||
| 2692 | 2840 | { |
| 2693 | 2841 | $post_errors[] = 'no_message'; |
| 2694 | 2842 | unset($_POST['message']); |
| 2695 | - } |
|
| 2696 | - elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) |
|
| 2843 | + } elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) |
|
| 2697 | 2844 | { |
| 2698 | 2845 | $post_errors[] = 'long_message'; |
| 2699 | 2846 | unset($_POST['message']); |
| 2700 | - } |
|
| 2701 | - else |
|
| 2847 | + } else |
|
| 2702 | 2848 | { |
| 2703 | 2849 | $_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES); |
| 2704 | 2850 | |
@@ -2714,31 +2860,34 @@ discard block |
||
| 2714 | 2860 | |
| 2715 | 2861 | if (isset($_POST['lock'])) |
| 2716 | 2862 | { |
| 2717 | - if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) |
|
| 2718 | - unset($_POST['lock']); |
|
| 2719 | - elseif (!allowedTo('lock_any')) |
|
| 2863 | + if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) { |
|
| 2864 | + unset($_POST['lock']); |
|
| 2865 | + } elseif (!allowedTo('lock_any')) |
|
| 2720 | 2866 | { |
| 2721 | - if ($row['locked'] == 1) |
|
| 2722 | - unset($_POST['lock']); |
|
| 2723 | - else |
|
| 2724 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 2867 | + if ($row['locked'] == 1) { |
|
| 2868 | + unset($_POST['lock']); |
|
| 2869 | + } else { |
|
| 2870 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 2871 | + } |
|
| 2872 | + } elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) { |
|
| 2873 | + unset($_POST['lock']); |
|
| 2874 | + } else { |
|
| 2875 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
|
| 2725 | 2876 | } |
| 2726 | - elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) |
|
| 2727 | - unset($_POST['lock']); |
|
| 2728 | - else |
|
| 2729 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
|
| 2730 | 2877 | } |
| 2731 | 2878 | |
| 2732 | - if (isset($_POST['sticky']) && !allowedTo('make_sticky')) |
|
| 2733 | - unset($_POST['sticky']); |
|
| 2879 | + if (isset($_POST['sticky']) && !allowedTo('make_sticky')) { |
|
| 2880 | + unset($_POST['sticky']); |
|
| 2881 | + } |
|
| 2734 | 2882 | |
| 2735 | 2883 | if (isset($_POST['modify_reason'])) |
| 2736 | 2884 | { |
| 2737 | 2885 | $_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => '')); |
| 2738 | 2886 | |
| 2739 | 2887 | // Maximum number of characters. |
| 2740 | - if ($smcFunc['strlen']($_POST['modify_reason']) > 100) |
|
| 2741 | - $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
| 2888 | + if ($smcFunc['strlen']($_POST['modify_reason']) > 100) { |
|
| 2889 | + $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
| 2890 | + } |
|
| 2742 | 2891 | } |
| 2743 | 2892 | |
| 2744 | 2893 | if (empty($post_errors)) |
@@ -2775,8 +2924,9 @@ discard block |
||
| 2775 | 2924 | } |
| 2776 | 2925 | } |
| 2777 | 2926 | // If nothing was changed there's no need to add an entry to the moderation log. |
| 2778 | - else |
|
| 2779 | - $moderationAction = false; |
|
| 2927 | + else { |
|
| 2928 | + $moderationAction = false; |
|
| 2929 | + } |
|
| 2780 | 2930 | |
| 2781 | 2931 | modifyPost($msgOptions, $topicOptions, $posterOptions); |
| 2782 | 2932 | |
@@ -2794,9 +2944,9 @@ discard block |
||
| 2794 | 2944 | // Get the proper (default language) response prefix first. |
| 2795 | 2945 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
| 2796 | 2946 | { |
| 2797 | - if ($language === $user_info['language']) |
|
| 2798 | - $context['response_prefix'] = $txt['response_prefix']; |
|
| 2799 | - else |
|
| 2947 | + if ($language === $user_info['language']) { |
|
| 2948 | + $context['response_prefix'] = $txt['response_prefix']; |
|
| 2949 | + } else |
|
| 2800 | 2950 | { |
| 2801 | 2951 | loadLanguage('index', $language, false); |
| 2802 | 2952 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -2818,8 +2968,9 @@ discard block |
||
| 2818 | 2968 | ); |
| 2819 | 2969 | } |
| 2820 | 2970 | |
| 2821 | - if (!empty($moderationAction)) |
|
| 2822 | - logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
| 2971 | + if (!empty($moderationAction)) { |
|
| 2972 | + logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
| 2973 | + } |
|
| 2823 | 2974 | } |
| 2824 | 2975 | |
| 2825 | 2976 | if (isset($_REQUEST['xml'])) |
@@ -2860,8 +3011,7 @@ discard block |
||
| 2860 | 3011 | ); |
| 2861 | 3012 | |
| 2862 | 3013 | censorText($context['message']['subject']); |
| 2863 | - } |
|
| 2864 | - else |
|
| 3014 | + } else |
|
| 2865 | 3015 | { |
| 2866 | 3016 | $context['message'] = array( |
| 2867 | 3017 | 'id' => $row['id_msg'], |
@@ -2873,15 +3023,16 @@ discard block |
||
| 2873 | 3023 | loadLanguage('Errors'); |
| 2874 | 3024 | foreach ($post_errors as $post_error) |
| 2875 | 3025 | { |
| 2876 | - if ($post_error == 'long_message') |
|
| 2877 | - $context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']); |
|
| 2878 | - else |
|
| 2879 | - $context['message']['errors'][] = $txt['error_' . $post_error]; |
|
| 3026 | + if ($post_error == 'long_message') { |
|
| 3027 | + $context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']); |
|
| 3028 | + } else { |
|
| 3029 | + $context['message']['errors'][] = $txt['error_' . $post_error]; |
|
| 3030 | + } |
|
| 2880 | 3031 | } |
| 2881 | 3032 | } |
| 3033 | + } else { |
|
| 3034 | + obExit(false); |
|
| 3035 | + } |
|
| 2882 | 3036 | } |
| 2883 | - else |
|
| 2884 | - obExit(false); |
|
| 2885 | -} |
|
| 2886 | 3037 | |
| 2887 | 3038 | ?> |
| 2888 | 3039 | \ No newline at end of file |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 3 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * Shows a listing of registered members. |
@@ -110,8 +111,9 @@ discard block |
||
| 110 | 111 | |
| 111 | 112 | $context['custom_profile_fields'] = getCustFieldsMList(); |
| 112 | 113 | |
| 113 | - if (!empty($context['custom_profile_fields']['columns'])) |
|
| 114 | - $context['columns'] += $context['custom_profile_fields']['columns']; |
|
| 114 | + if (!empty($context['custom_profile_fields']['columns'])) { |
|
| 115 | + $context['columns'] += $context['custom_profile_fields']['columns']; |
|
| 116 | + } |
|
| 115 | 117 | |
| 116 | 118 | $context['colspan'] = 0; |
| 117 | 119 | $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array(); |
@@ -147,12 +149,12 @@ discard block |
||
| 147 | 149 | call_integration_hook('integrate_memberlist_buttons'); |
| 148 | 150 | |
| 149 | 151 | // Jump to the sub action. |
| 150 | - if (isset($subActions[$context['listing_by']])) |
|
| 151 | - call_helper($subActions[$context['listing_by']][1]); |
|
| 152 | - |
|
| 153 | - else |
|
| 154 | - call_helper($subActions['all'][1]); |
|
| 155 | -} |
|
| 152 | + if (isset($subActions[$context['listing_by']])) { |
|
| 153 | + call_helper($subActions[$context['listing_by']][1]); |
|
| 154 | + } else { |
|
| 155 | + call_helper($subActions['all'][1]); |
|
| 156 | + } |
|
| 157 | + } |
|
| 156 | 158 | |
| 157 | 159 | /** |
| 158 | 160 | * List all members, page by page, with sorting. |
@@ -177,8 +179,9 @@ discard block |
||
| 177 | 179 | if ($use_cache) |
| 178 | 180 | { |
| 179 | 181 | // Maybe there's something cached already. |
| 180 | - if (!empty($modSettings['memberlist_cache'])) |
|
| 181 | - $memberlist_cache = smf_json_decode($modSettings['memberlist_cache'], true); |
|
| 182 | + if (!empty($modSettings['memberlist_cache'])) { |
|
| 183 | + $memberlist_cache = smf_json_decode($modSettings['memberlist_cache'], true); |
|
| 184 | + } |
|
| 182 | 185 | |
| 183 | 186 | // The chunk size for the cached index. |
| 184 | 187 | $cache_step_size = 500; |
@@ -234,13 +237,15 @@ discard block |
||
| 234 | 237 | } |
| 235 | 238 | |
| 236 | 239 | // Set defaults for sort (real_name) and start. (0) |
| 237 | - if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) |
|
| 238 | - $_REQUEST['sort'] = 'real_name'; |
|
| 240 | + if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) { |
|
| 241 | + $_REQUEST['sort'] = 'real_name'; |
|
| 242 | + } |
|
| 239 | 243 | |
| 240 | 244 | if (!is_numeric($_REQUEST['start'])) |
| 241 | 245 | { |
| 242 | - if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0) |
|
| 243 | - fatal_error('Hacker?', false); |
|
| 246 | + if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0) { |
|
| 247 | + fatal_error('Hacker?', false); |
|
| 248 | + } |
|
| 244 | 249 | |
| 245 | 250 | $_REQUEST['start'] = $match[0]; |
| 246 | 251 | |
@@ -259,16 +264,18 @@ discard block |
||
| 259 | 264 | } |
| 260 | 265 | |
| 261 | 266 | $context['letter_links'] = ''; |
| 262 | - for ($i = 97; $i < 123; $i++) |
|
| 263 | - $context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> '; |
|
| 267 | + for ($i = 97; $i < 123; $i++) { |
|
| 268 | + $context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> '; |
|
| 269 | + } |
|
| 264 | 270 | |
| 265 | 271 | // Sort out the column information. |
| 266 | 272 | foreach ($context['columns'] as $col => $column_details) |
| 267 | 273 | { |
| 268 | 274 | $context['columns'][$col]['href'] = $scripturl . '?action=mlist;sort=' . $col . ';start=0'; |
| 269 | 275 | |
| 270 | - if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) |
|
| 271 | - $context['columns'][$col]['href'] .= ';desc'; |
|
| 276 | + if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) { |
|
| 277 | + $context['columns'][$col]['href'] .= ';desc'; |
|
| 278 | + } |
|
| 272 | 279 | |
| 273 | 280 | $context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>'; |
| 274 | 281 | $context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col; |
@@ -317,8 +324,9 @@ discard block |
||
| 317 | 324 | elseif ($use_cache && $_REQUEST['sort'] === 'real_name') |
| 318 | 325 | { |
| 319 | 326 | $first_offset = floor(($memberlist_cache['num_members'] - $modSettings['defaultMaxMembers'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size; |
| 320 | - if ($first_offset < 0) |
|
| 321 | - $first_offset = 0; |
|
| 327 | + if ($first_offset < 0) { |
|
| 328 | + $first_offset = 0; |
|
| 329 | + } |
|
| 322 | 330 | $second_offset = ceil(($memberlist_cache['num_members'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size; |
| 323 | 331 | |
| 324 | 332 | $where = 'mem.real_name BETWEEN {string:real_name_low} AND {string:real_name_high}'; |
@@ -395,12 +403,13 @@ discard block |
||
| 395 | 403 | ) |
| 396 | 404 | ); |
| 397 | 405 | $context['custom_search_fields'] = array(); |
| 398 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 399 | - $context['custom_search_fields'][$row['col_name']] = array( |
|
| 406 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 407 | + $context['custom_search_fields'][$row['col_name']] = array( |
|
| 400 | 408 | 'colname' => $row['col_name'], |
| 401 | 409 | 'name' => $row['field_name'], |
| 402 | 410 | 'desc' => $row['field_desc'], |
| 403 | 411 | ); |
| 412 | + } |
|
| 404 | 413 | $smcFunc['db_free_result']($request); |
| 405 | 414 | |
| 406 | 415 | // They're searching.. |
@@ -413,23 +422,27 @@ discard block |
||
| 413 | 422 | $context['old_search_value'] = urlencode($_REQUEST['search']); |
| 414 | 423 | |
| 415 | 424 | // No fields? Use default... |
| 416 | - if (empty($_POST['fields'])) |
|
| 417 | - $_POST['fields'] = array('name'); |
|
| 425 | + if (empty($_POST['fields'])) { |
|
| 426 | + $_POST['fields'] = array('name'); |
|
| 427 | + } |
|
| 418 | 428 | |
| 419 | 429 | // Set defaults for how the results are sorted |
| 420 | - if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) |
|
| 421 | - $_REQUEST['sort'] = 'real_name'; |
|
| 430 | + if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) { |
|
| 431 | + $_REQUEST['sort'] = 'real_name'; |
|
| 432 | + } |
|
| 422 | 433 | |
| 423 | 434 | // Build the column link / sort information. |
| 424 | 435 | foreach ($context['columns'] as $col => $column_details) |
| 425 | 436 | { |
| 426 | 437 | $context['columns'][$col]['href'] = $scripturl . '?action=mlist;sa=search;start=0;sort=' . $col; |
| 427 | 438 | |
| 428 | - if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) |
|
| 429 | - $context['columns'][$col]['href'] .= ';desc'; |
|
| 439 | + if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) { |
|
| 440 | + $context['columns'][$col]['href'] .= ';desc'; |
|
| 441 | + } |
|
| 430 | 442 | |
| 431 | - if (isset($_POST['search']) && isset($_POST['fields'])) |
|
| 432 | - $context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']); |
|
| 443 | + if (isset($_POST['search']) && isset($_POST['fields'])) { |
|
| 444 | + $context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']); |
|
| 445 | + } |
|
| 433 | 446 | |
| 434 | 447 | $context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>'; |
| 435 | 448 | $context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col; |
@@ -452,8 +465,7 @@ discard block |
||
| 452 | 465 | { |
| 453 | 466 | $fields = allowedTo('moderate_forum') ? array('member_name', 'real_name') : array('real_name'); |
| 454 | 467 | $search_fields[] = 'name'; |
| 455 | - } |
|
| 456 | - else |
|
| 468 | + } else |
|
| 457 | 469 | { |
| 458 | 470 | $fields = array(); |
| 459 | 471 | $search_fields = array(); |
@@ -478,9 +490,10 @@ discard block |
||
| 478 | 490 | $search_fields[] = 'email'; |
| 479 | 491 | } |
| 480 | 492 | |
| 481 | - if ($smcFunc['db_case_sensitive']) |
|
| 482 | - foreach ($fields as $key => $field) |
|
| 493 | + if ($smcFunc['db_case_sensitive']) { |
|
| 494 | + foreach ($fields as $key => $field) |
|
| 483 | 495 | $fields[$key] = 'LOWER(' . $field . ')'; |
| 496 | + } |
|
| 484 | 497 | |
| 485 | 498 | $customJoin = array(); |
| 486 | 499 | $customCount = 10; |
@@ -499,8 +512,9 @@ discard block |
||
| 499 | 512 | } |
| 500 | 513 | |
| 501 | 514 | // No search fields? That means you're trying to hack things |
| 502 | - if (empty($search_fields)) |
|
| 503 | - fatal_lang_error('invalid_search_string', false); |
|
| 515 | + if (empty($search_fields)) { |
|
| 516 | + fatal_lang_error('invalid_search_string', false); |
|
| 517 | + } |
|
| 504 | 518 | |
| 505 | 519 | $query = $_POST['search'] == '' ? '= {string:blank_string}' : ($smcFunc['db_case_sensitive'] ? 'LIKE LOWER({string:search})' : 'LIKE {string:search}'); |
| 506 | 520 | |
@@ -538,8 +552,7 @@ discard block |
||
| 538 | 552 | ); |
| 539 | 553 | printMemberListRows($request); |
| 540 | 554 | $smcFunc['db_free_result']($request); |
| 541 | - } |
|
| 542 | - else |
|
| 555 | + } else |
|
| 543 | 556 | { |
| 544 | 557 | // These are all the possible fields. |
| 545 | 558 | $context['search_fields'] = array( |
@@ -554,14 +567,14 @@ discard block |
||
| 554 | 567 | { |
| 555 | 568 | unset($context['search_fields']['email']); |
| 556 | 569 | $context['search_defaults'] = array('name'); |
| 557 | - } |
|
| 558 | - else |
|
| 570 | + } else |
|
| 559 | 571 | { |
| 560 | 572 | $context['search_defaults'] = array('name', 'email'); |
| 561 | 573 | } |
| 562 | 574 | |
| 563 | - foreach ($context['custom_search_fields'] as $field) |
|
| 564 | - $context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']); |
|
| 575 | + foreach ($context['custom_search_fields'] as $field) { |
|
| 576 | + $context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']); |
|
| 577 | + } |
|
| 565 | 578 | |
| 566 | 579 | $context['sub_template'] = 'search'; |
| 567 | 580 | $context['old_search'] = isset($_GET['search']) ? $_GET['search'] : (isset($_POST['search']) ? $smcFunc['htmlspecialchars']($_POST['search']) : ''); |
@@ -603,12 +616,14 @@ discard block |
||
| 603 | 616 | $smcFunc['db_free_result']($result); |
| 604 | 617 | |
| 605 | 618 | // Avoid division by zero... |
| 606 | - if ($most_posts == 0) |
|
| 607 | - $most_posts = 1; |
|
| 619 | + if ($most_posts == 0) { |
|
| 620 | + $most_posts = 1; |
|
| 621 | + } |
|
| 608 | 622 | |
| 609 | 623 | $members = array(); |
| 610 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 611 | - $members[] = $row['id_member']; |
|
| 624 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 625 | + $members[] = $row['id_member']; |
|
| 626 | + } |
|
| 612 | 627 | |
| 613 | 628 | // Load all the members for display. |
| 614 | 629 | loadMemberData($members); |
@@ -616,8 +631,9 @@ discard block |
||
| 616 | 631 | $context['members'] = array(); |
| 617 | 632 | foreach ($members as $member) |
| 618 | 633 | { |
| 619 | - if (!loadMemberContext($member)) |
|
| 620 | - continue; |
|
| 634 | + if (!loadMemberContext($member)) { |
|
| 635 | + continue; |
|
| 636 | + } |
|
| 621 | 637 | |
| 622 | 638 | $context['members'][$member] = $memberContext[$member]; |
| 623 | 639 | $context['members'][$member]['post_percent'] = round(($context['members'][$member]['real_posts'] * 100) / $most_posts); |
@@ -634,20 +650,21 @@ discard block |
||
| 634 | 650 | continue; |
| 635 | 651 | } |
| 636 | 652 | |
| 637 | - if ($column['bbc'] && !empty($context['members'][$member]['options'][$key])) |
|
| 638 | - $context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key])); |
|
| 639 | - |
|
| 640 | - elseif ($column['type'] == 'check') |
|
| 641 | - $context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes']; |
|
| 653 | + if ($column['bbc'] && !empty($context['members'][$member]['options'][$key])) { |
|
| 654 | + $context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key])); |
|
| 655 | + } elseif ($column['type'] == 'check') { |
|
| 656 | + $context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes']; |
|
| 657 | + } |
|
| 642 | 658 | |
| 643 | 659 | // Enclosing the user input within some other text? |
| 644 | - if (!empty($column['enclose'])) |
|
| 645 | - $context['members'][$member]['options'][$key] = strtr($column['enclose'], array( |
|
| 660 | + if (!empty($column['enclose'])) { |
|
| 661 | + $context['members'][$member]['options'][$key] = strtr($column['enclose'], array( |
|
| 646 | 662 | '{SCRIPTURL}' => $scripturl, |
| 647 | 663 | '{IMAGES_URL}' => $settings['images_url'], |
| 648 | 664 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
| 649 | 665 | '{INPUT}' => $context['members'][$member]['options'][$key], |
| 650 | 666 | )); |
| 667 | + } |
|
| 651 | 668 | } |
| 652 | 669 | } |
| 653 | 670 | } |
@@ -688,17 +705,17 @@ discard block |
||
| 688 | 705 | ); |
| 689 | 706 | |
| 690 | 707 | // Get the right sort method depending on the cust field type. |
| 691 | - if ($row['field_type'] != 'check') |
|
| 692 | - $cpf['columns'][$row['col_name']]['sort'] = array( |
|
| 708 | + if ($row['field_type'] != 'check') { |
|
| 709 | + $cpf['columns'][$row['col_name']]['sort'] = array( |
|
| 693 | 710 | 'down' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 ASC, COALESCE(t' . $row['col_name'] . '.value, "") DESC', |
| 694 | 711 | 'up' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 DESC, COALESCE(t' . $row['col_name'] . '.value, "") ASC' |
| 695 | 712 | ); |
| 696 | - |
|
| 697 | - else |
|
| 698 | - $cpf['columns'][$row['col_name']]['sort'] = array( |
|
| 713 | + } else { |
|
| 714 | + $cpf['columns'][$row['col_name']]['sort'] = array( |
|
| 699 | 715 | 'down' => 't' . $row['col_name'] . '.value DESC', |
| 700 | 716 | 'up' => 't' . $row['col_name'] . '.value ASC' |
| 701 | 717 | ); |
| 718 | + } |
|
| 702 | 719 | |
| 703 | 720 | $cpf['join'][$row['col_name']] = 'LEFT JOIN {db_prefix}themes AS t' . $row['col_name'] . ' ON (t' . $row['col_name'] . '.variable = {literal:' . $row['col_name'] . '} AND t' . $row['col_name'] . '.id_theme = 1 AND t' . $row['col_name'] . '.id_member = mem.id_member)'; |
| 704 | 721 | } |