@@ -16,8 +16,9 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | // Start things rolling by getting SMF alive... |
| 18 | 18 | $ssi_guest_access = true; |
| 19 | -if (!file_exists(dirname(__FILE__) . '/SSI.php')) |
|
| 19 | +if (!file_exists(dirname(__FILE__) . '/SSI.php')) { |
|
| 20 | 20 | die('Cannot find SSI.php'); |
| 21 | +} |
|
| 21 | 22 | |
| 22 | 23 | require_once(dirname(__FILE__) . '/SSI.php'); |
| 23 | 24 | require_once($sourcedir . '/ManagePaid.php'); |
@@ -35,20 +36,22 @@ discard block |
||
| 35 | 36 | } |
| 36 | 37 | |
| 37 | 38 | // I assume we're even active? |
| 38 | -if (empty($modSettings['paid_enabled'])) |
|
| 39 | +if (empty($modSettings['paid_enabled'])) { |
|
| 39 | 40 | exit; |
| 41 | +} |
|
| 40 | 42 | |
| 41 | 43 | // If we have some custom people who find out about problems load them here. |
| 42 | 44 | $notify_users = array(); |
| 43 | 45 | if (!empty($modSettings['paid_email_to'])) |
| 44 | 46 | { |
| 45 | - foreach (explode(',', $modSettings['paid_email_to']) as $email) |
|
| 46 | - $notify_users[] = array( |
|
| 47 | + foreach (explode(',', $modSettings['paid_email_to']) as $email) { |
|
| 48 | + $notify_users[] = array( |
|
| 47 | 49 | 'email' => $email, |
| 48 | 50 | 'name' => $txt['who_member'], |
| 49 | 51 | 'id' => 0, |
| 50 | 52 | ); |
| 51 | -} |
|
| 53 | + } |
|
| 54 | + } |
|
| 52 | 55 | |
| 53 | 56 | // We need to see whether we can find the correct payment gateway, |
| 54 | 57 | // we'll going to go through all our gateway scripts and find out |
@@ -65,8 +68,9 @@ discard block |
||
| 65 | 68 | } |
| 66 | 69 | } |
| 67 | 70 | |
| 68 | -if (empty($txnType)) |
|
| 71 | +if (empty($txnType)) { |
|
| 69 | 72 | generateSubscriptionError($txt['paid_unknown_transaction_type']); |
| 73 | +} |
|
| 70 | 74 | |
| 71 | 75 | // Get the subscription and member ID amoungst others... |
| 72 | 76 | @list($subscription_id, $member_id) = $gatewayClass->precheck(); |
@@ -76,8 +80,9 @@ discard block |
||
| 76 | 80 | $member_id = (int) $member_id; |
| 77 | 81 | |
| 78 | 82 | // This would be bad... |
| 79 | -if (empty($member_id)) |
|
| 83 | +if (empty($member_id)) { |
|
| 80 | 84 | generateSubscriptionError($txt['paid_empty_member']); |
| 85 | +} |
|
| 81 | 86 | |
| 82 | 87 | // Verify the member. |
| 83 | 88 | $request = $smcFunc['db_query']('', ' |
@@ -89,8 +94,9 @@ discard block |
||
| 89 | 94 | ) |
| 90 | 95 | ); |
| 91 | 96 | // Didn't find them? |
| 92 | -if ($smcFunc['db_num_rows']($request) === 0) |
|
| 97 | +if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 93 | 98 | generateSubscriptionError(sprintf($txt['paid_could_not_find_member'], $member_id)); |
| 99 | +} |
|
| 94 | 100 | $member_info = $smcFunc['db_fetch_assoc']($request); |
| 95 | 101 | $smcFunc['db_free_result']($request); |
| 96 | 102 | |
@@ -105,8 +111,9 @@ discard block |
||
| 105 | 111 | ); |
| 106 | 112 | |
| 107 | 113 | // Didn't find it? |
| 108 | -if ($smcFunc['db_num_rows']($request) === 0) |
|
| 114 | +if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 109 | 115 | generateSubscriptionError(sprintf($txt['paid_count_not_find_subscription'], $member_id, $subscription_id)); |
| 116 | +} |
|
| 110 | 117 | |
| 111 | 118 | $subscription_info = $smcFunc['db_fetch_assoc']($request); |
| 112 | 119 | $smcFunc['db_free_result']($request); |
@@ -123,8 +130,9 @@ discard block |
||
| 123 | 130 | 'current_member' => $member_id, |
| 124 | 131 | ) |
| 125 | 132 | ); |
| 126 | -if ($smcFunc['db_num_rows']($request) === 0) |
|
| 133 | +if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 127 | 134 | generateSubscriptionError(sprintf($txt['paid_count_not_find_subscription_log'], $member_id, $subscription_id)); |
| 135 | +} |
|
| 128 | 136 | $subscription_info += $smcFunc['db_fetch_assoc']($request); |
| 129 | 137 | $smcFunc['db_free_result']($request); |
| 130 | 138 | |
@@ -139,8 +147,7 @@ discard block |
||
| 139 | 147 | removeSubscription($subscription_id, $member_id); |
| 140 | 148 | $subscription_act = time(); |
| 141 | 149 | $status = 0; |
| 142 | - } |
|
| 143 | - else |
|
| 150 | + } else |
|
| 144 | 151 | { |
| 145 | 152 | loadSubscriptions(); |
| 146 | 153 | $subscription_act = $subscription_info['end_time'] - $context['subscriptions'][$subscription_id]['num_length']; |
@@ -188,16 +195,18 @@ discard block |
||
| 188 | 195 | if (!$gatewayClass->isSubscription()) |
| 189 | 196 | { |
| 190 | 197 | $real_details = json_decode($subscription_info['pending_details'], true); |
| 191 | - if (empty($real_details)) |
|
| 192 | - generateSubscriptionError(sprintf($txt['paid_count_not_find_outstanding_payment'], $member_id, $subscription_id)); |
|
| 198 | + if (empty($real_details)) { |
|
| 199 | + generateSubscriptionError(sprintf($txt['paid_count_not_find_outstanding_payment'], $member_id, $subscription_id)); |
|
| 200 | + } |
|
| 193 | 201 | |
| 194 | 202 | // Now we just try to find anything pending. |
| 195 | 203 | // We don't really care which it is as security happens later. |
| 196 | 204 | foreach ($real_details as $id => $detail) |
| 197 | 205 | { |
| 198 | 206 | unset($real_details[$id]); |
| 199 | - if ($detail[3] == 'payback' && $subscription_info['payments_pending']) |
|
| 200 | - $subscription_info['payments_pending']--; |
|
| 207 | + if ($detail[3] == 'payback' && $subscription_info['payments_pending']) { |
|
| 208 | + $subscription_info['payments_pending']--; |
|
| 209 | + } |
|
| 201 | 210 | break; |
| 202 | 211 | } |
| 203 | 212 | |
@@ -223,10 +232,11 @@ discard block |
||
| 223 | 232 | // This is a little harder, can we find the right duration? |
| 224 | 233 | foreach ($cost as $duration => $value) |
| 225 | 234 | { |
| 226 | - if ($duration == 'fixed') |
|
| 227 | - continue; |
|
| 228 | - elseif ((float) $value == (float) $total_cost) |
|
| 229 | - $found_duration = strtoupper(substr($duration, 0, 1)); |
|
| 235 | + if ($duration == 'fixed') { |
|
| 236 | + continue; |
|
| 237 | + } elseif ((float) $value == (float) $total_cost) { |
|
| 238 | + $found_duration = strtoupper(substr($duration, 0, 1)); |
|
| 239 | + } |
|
| 230 | 240 | } |
| 231 | 241 | |
| 232 | 242 | // If we have the duration then we're done. |
@@ -235,8 +245,7 @@ discard block |
||
| 235 | 245 | $notify = true; |
| 236 | 246 | addSubscription($subscription_id, $member_id, $found_duration); |
| 237 | 247 | } |
| 238 | - } |
|
| 239 | - else |
|
| 248 | + } else |
|
| 240 | 249 | { |
| 241 | 250 | $actual_cost = $cost['fixed']; |
| 242 | 251 | |
@@ -268,10 +277,10 @@ discard block |
||
| 268 | 277 | // Maybe they're cancelling. Some subscriptions may require actively doing something, but PayPal doesn't, for example. |
| 269 | 278 | elseif ($gatewayClass->isCancellation()) |
| 270 | 279 | { |
| 271 | - if (method_exists($gatewayClass, 'performCancel')) |
|
| 272 | - $gatewayClass->performCancel($subscription_id, $member_id, $subscription_info); |
|
| 273 | -} |
|
| 274 | -else |
|
| 280 | + if (method_exists($gatewayClass, 'performCancel')) { |
|
| 281 | + $gatewayClass->performCancel($subscription_id, $member_id, $subscription_info); |
|
| 282 | + } |
|
| 283 | + } else |
|
| 275 | 284 | { |
| 276 | 285 | // Some other "valid" transaction such as: |
| 277 | 286 | // |
@@ -308,8 +317,9 @@ discard block |
||
| 308 | 317 | // Maybe we can try to give them the post data? |
| 309 | 318 | if (!empty($_POST)) |
| 310 | 319 | { |
| 311 | - foreach ($_POST as $key => $val) |
|
| 312 | - $text .= '<br>' . $smcFunc['htmlspecialchars']($key) . ': ' . $smcFunc['htmlspecialchars']($val); |
|
| 320 | + foreach ($_POST as $key => $val) { |
|
| 321 | + $text .= '<br>' . $smcFunc['htmlspecialchars']($key) . ': ' . $smcFunc['htmlspecialchars']($val); |
|
| 322 | + } |
|
| 313 | 323 | } |
| 314 | 324 | |
| 315 | 325 | // Then just log and die. |
@@ -10,7 +10,8 @@ |
||
| 10 | 10 | header('Location: ' . $boardurl); |
| 11 | 11 | } |
| 12 | 12 | // Can't find it... just forget it. |
| 13 | -else |
|
| 13 | +else { |
|
| 14 | 14 | exit; |
| 15 | +} |
|
| 15 | 16 | |
| 16 | 17 | ?> |
| 17 | 18 | \ No newline at end of file |
@@ -1,9 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // Try to handle it with the upper level index.php. (it should know what to do.) |
| 4 | -if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) |
|
| 4 | +if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) { |
|
| 5 | 5 | include (dirname(dirname(__FILE__)) . '/index.php'); |
| 6 | -else |
|
| 6 | +} else { |
|
| 7 | 7 | exit; |
| 8 | +} |
|
| 8 | 9 | |
| 9 | 10 | ?> |
| 10 | 11 | \ No newline at end of file |
@@ -12,7 +12,8 @@ |
||
| 12 | 12 | header('Location: ' . $boardurl); |
| 13 | 13 | } |
| 14 | 14 | // Can't find it... just forget it. |
| 15 | -else |
|
| 15 | +else { |
|
| 16 | 16 | exit; |
| 17 | +} |
|
| 17 | 18 | |
| 18 | 19 | ?> |
| 19 | 20 | \ No newline at end of file |
@@ -1,9 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // Try to handle it with the upper level index.php. (it should know what to do.) |
| 4 | -if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) |
|
| 4 | +if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) { |
|
| 5 | 5 | include (dirname(dirname(__FILE__)) . '/index.php'); |
| 6 | -else |
|
| 6 | +} else { |
|
| 7 | 7 | exit; |
| 8 | +} |
|
| 8 | 9 | |
| 9 | 10 | ?> |
| 10 | 11 | \ No newline at end of file |
@@ -1,9 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // Try to handle it with the upper level index.php. (it should know what to do.) |
| 4 | -if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) |
|
| 4 | +if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) { |
|
| 5 | 5 | include (dirname(dirname(__FILE__)) . '/index.php'); |
| 6 | -else |
|
| 6 | +} else { |
|
| 7 | 7 | exit; |
| 8 | +} |
|
| 8 | 9 | |
| 9 | 10 | ?> |
| 10 | 11 | \ No newline at end of file |
@@ -1,9 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // Try to handle it with the upper level index.php. (it should know what to do.) |
| 4 | -if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) |
|
| 4 | +if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) { |
|
| 5 | 5 | include (dirname(dirname(__FILE__)) . '/index.php'); |
| 6 | -else |
|
| 6 | +} else { |
|
| 7 | 7 | exit; |
| 8 | +} |
|
| 8 | 9 | |
| 9 | 10 | ?> |
| 10 | 11 | \ No newline at end of file |
@@ -71,11 +71,11 @@ discard block |
||
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // Use cache when possible. |
| 74 | - if (($cache = cache_get_data('attachment_lookup_id-'. $attachId)) != null) |
|
| 74 | + if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null) |
|
| 75 | 75 | list($file, $thumbFile) = $cache; |
| 76 | 76 | |
| 77 | 77 | // Get the info from the DB. |
| 78 | - if(empty($file) || empty($thumbFile) && !empty($file['id_thumb'])) |
|
| 78 | + if (empty($file) || empty($thumbFile) && !empty($file['id_thumb'])) |
|
| 79 | 79 | { |
| 80 | 80 | // Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request. |
| 81 | 81 | $attachRequest = null; |
@@ -144,8 +144,8 @@ discard block |
||
| 144 | 144 | $file['filePath'] = getAttachmentFilename($file['filename'], $attachId, $file['id_folder'], false, $file['file_hash']); |
| 145 | 145 | // ensure variant attachment compatibility |
| 146 | 146 | $filePath = pathinfo($file['filePath']); |
| 147 | - $file['filePath'] = !file_exists($file['filePath']) ? substr($file['filePath'], 0, -(strlen($filePath['extension'])+1)) : $file['filePath']; |
|
| 148 | - $file['etag'] = '"'. md5_file($file['filePath']) .'"'; |
|
| 147 | + $file['filePath'] = !file_exists($file['filePath']) ? substr($file['filePath'], 0, -(strlen($filePath['extension']) + 1)) : $file['filePath']; |
|
| 148 | + $file['etag'] = '"' . md5_file($file['filePath']) . '"'; |
|
| 149 | 149 | |
| 150 | 150 | // now get the thumbfile! |
| 151 | 151 | $thumbFile = array(); |
@@ -171,13 +171,13 @@ discard block |
||
| 171 | 171 | |
| 172 | 172 | // set filePath and ETag time |
| 173 | 173 | $thumbFile['filePath'] = getAttachmentFilename($thumbFile['filename'], $attachId, $thumbFile['id_folder'], false, $thumbFile['file_hash']); |
| 174 | - $thumbFile['etag'] = '"'. md5_file($thumbFile['filePath']) .'"'; |
|
| 174 | + $thumbFile['etag'] = '"' . md5_file($thumbFile['filePath']) . '"'; |
|
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | // 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)); |
|
| 179 | + if (!empty($file) || !empty($thumbFile)) |
|
| 180 | + cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900)); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | // Update the download counter (unless it's a thumbnail). |
@@ -289,17 +289,17 @@ discard block |
||
| 289 | 289 | if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file['fileext'], array('txt', 'css', 'htm', 'html', 'php', 'xml'))) |
| 290 | 290 | { |
| 291 | 291 | if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) |
| 292 | - $callback = function ($buffer) |
|
| 292 | + $callback = function($buffer) |
|
| 293 | 293 | { |
| 294 | 294 | return preg_replace('~[\r]?\n~', "\r\n", $buffer); |
| 295 | 295 | }; |
| 296 | 296 | elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) |
| 297 | - $callback = function ($buffer) |
|
| 297 | + $callback = function($buffer) |
|
| 298 | 298 | { |
| 299 | 299 | return preg_replace('~[\r]?\n~', "\r", $buffer); |
| 300 | 300 | }; |
| 301 | 301 | else |
| 302 | - $callback = function ($buffer) |
|
| 302 | + $callback = function($buffer) |
|
| 303 | 303 | { |
| 304 | 304 | return preg_replace('~[\r]?\n~', "\n", $buffer); |
| 305 | 305 | }; |
@@ -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 | } |
@@ -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 | * Edit the position and properties of a category. |
@@ -42,8 +43,9 @@ discard block |
||
| 42 | 43 | $cat_order = array(); |
| 43 | 44 | |
| 44 | 45 | // Setting 'move_after' to '0' moves the category to the top. |
| 45 | - if ($catOptions['move_after'] == 0) |
|
| 46 | - $cats[] = $category_id; |
|
| 46 | + if ($catOptions['move_after'] == 0) { |
|
| 47 | + $cats[] = $category_id; |
|
| 48 | + } |
|
| 47 | 49 | |
| 48 | 50 | // Grab the categories sorted by cat_order. |
| 49 | 51 | $request = $smcFunc['db_query']('', ' |
@@ -55,17 +57,19 @@ discard block |
||
| 55 | 57 | ); |
| 56 | 58 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 57 | 59 | { |
| 58 | - if ($row['id_cat'] != $category_id) |
|
| 59 | - $cats[] = $row['id_cat']; |
|
| 60 | - if ($row['id_cat'] == $catOptions['move_after']) |
|
| 61 | - $cats[] = $category_id; |
|
| 60 | + if ($row['id_cat'] != $category_id) { |
|
| 61 | + $cats[] = $row['id_cat']; |
|
| 62 | + } |
|
| 63 | + if ($row['id_cat'] == $catOptions['move_after']) { |
|
| 64 | + $cats[] = $category_id; |
|
| 65 | + } |
|
| 62 | 66 | $cat_order[$row['id_cat']] = $row['cat_order']; |
| 63 | 67 | } |
| 64 | 68 | $smcFunc['db_free_result']($request); |
| 65 | 69 | |
| 66 | 70 | // Set the new order for the categories. |
| 67 | - foreach ($cats as $index => $cat) |
|
| 68 | - if ($index != $cat_order[$cat]) |
|
| 71 | + foreach ($cats as $index => $cat) { |
|
| 72 | + if ($index != $cat_order[$cat]) |
|
| 69 | 73 | $smcFunc['db_query']('', ' |
| 70 | 74 | UPDATE {db_prefix}categories |
| 71 | 75 | SET cat_order = {int:new_order} |
@@ -75,6 +79,7 @@ discard block |
||
| 75 | 79 | 'current_category' => $cat, |
| 76 | 80 | ) |
| 77 | 81 | ); |
| 82 | + } |
|
| 78 | 83 | |
| 79 | 84 | // If the category order changed, so did the board order. |
| 80 | 85 | require_once($sourcedir . '/Subs-Boards.php'); |
@@ -117,8 +122,9 @@ discard block |
||
| 117 | 122 | )) |
| 118 | 123 | ); |
| 119 | 124 | |
| 120 | - if (empty($catOptions['dont_log'])) |
|
| 121 | - logAction('edit_cat', array('catname' => isset($catOptions['cat_name']) ? $catOptions['cat_name'] : $category_id), 'admin'); |
|
| 125 | + if (empty($catOptions['dont_log'])) { |
|
| 126 | + logAction('edit_cat', array('catname' => isset($catOptions['cat_name']) ? $catOptions['cat_name'] : $category_id), 'admin'); |
|
| 127 | + } |
|
| 122 | 128 | } |
| 123 | 129 | } |
| 124 | 130 | |
@@ -135,16 +141,20 @@ discard block |
||
| 135 | 141 | global $smcFunc; |
| 136 | 142 | |
| 137 | 143 | // Check required values. |
| 138 | - if (!isset($catOptions['cat_name']) || trim($catOptions['cat_name']) == '') |
|
| 139 | - trigger_error('createCategory(): A category name is required', E_USER_ERROR); |
|
| 144 | + if (!isset($catOptions['cat_name']) || trim($catOptions['cat_name']) == '') { |
|
| 145 | + trigger_error('createCategory(): A category name is required', E_USER_ERROR); |
|
| 146 | + } |
|
| 140 | 147 | |
| 141 | 148 | // Set default values. |
| 142 | - if (!isset($catOptions['cat_desc'])) |
|
| 143 | - $catOptions['cat_desc'] = ''; |
|
| 144 | - if (!isset($catOptions['move_after'])) |
|
| 145 | - $catOptions['move_after'] = 0; |
|
| 146 | - if (!isset($catOptions['is_collapsible'])) |
|
| 147 | - $catOptions['is_collapsible'] = true; |
|
| 149 | + if (!isset($catOptions['cat_desc'])) { |
|
| 150 | + $catOptions['cat_desc'] = ''; |
|
| 151 | + } |
|
| 152 | + if (!isset($catOptions['move_after'])) { |
|
| 153 | + $catOptions['move_after'] = 0; |
|
| 154 | + } |
|
| 155 | + if (!isset($catOptions['is_collapsible'])) { |
|
| 156 | + $catOptions['is_collapsible'] = true; |
|
| 157 | + } |
|
| 148 | 158 | // Don't log an edit right after. |
| 149 | 159 | $catOptions['dont_log'] = true; |
| 150 | 160 | |
@@ -212,21 +222,24 @@ discard block |
||
| 212 | 222 | ) |
| 213 | 223 | ); |
| 214 | 224 | $boards_inside = array(); |
| 215 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 216 | - $boards_inside[] = $row['id_board']; |
|
| 225 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 226 | + $boards_inside[] = $row['id_board']; |
|
| 227 | + } |
|
| 217 | 228 | $smcFunc['db_free_result']($request); |
| 218 | 229 | |
| 219 | - if (!empty($boards_inside)) |
|
| 220 | - deleteBoards($boards_inside, null); |
|
| 230 | + if (!empty($boards_inside)) { |
|
| 231 | + deleteBoards($boards_inside, null); |
|
| 232 | + } |
|
| 221 | 233 | } |
| 222 | 234 | |
| 223 | 235 | // Make sure the safe category is really safe. |
| 224 | - elseif (in_array($moveBoardsTo, $categories)) |
|
| 225 | - trigger_error('deleteCategories(): You cannot move the boards to a category that\'s being deleted', E_USER_ERROR); |
|
| 236 | + elseif (in_array($moveBoardsTo, $categories)) { |
|
| 237 | + trigger_error('deleteCategories(): You cannot move the boards to a category that\'s being deleted', E_USER_ERROR); |
|
| 238 | + } |
|
| 226 | 239 | |
| 227 | 240 | // Move the boards inside the categories to a safe category. |
| 228 | - else |
|
| 229 | - $smcFunc['db_query']('', ' |
|
| 241 | + else { |
|
| 242 | + $smcFunc['db_query']('', ' |
|
| 230 | 243 | UPDATE {db_prefix}boards |
| 231 | 244 | SET id_cat = {int:new_parent_cat} |
| 232 | 245 | WHERE id_cat IN ({array_int:category_list})', |
@@ -235,6 +248,7 @@ discard block |
||
| 235 | 248 | 'new_parent_cat' => $moveBoardsTo, |
| 236 | 249 | ) |
| 237 | 250 | ); |
| 251 | + } |
|
| 238 | 252 | |
| 239 | 253 | // Do the deletion of the category itself |
| 240 | 254 | $smcFunc['db_query']('', ' |
@@ -246,8 +260,9 @@ discard block |
||
| 246 | 260 | ); |
| 247 | 261 | |
| 248 | 262 | // Log what we've done. |
| 249 | - foreach ($categories as $category) |
|
| 250 | - logAction('delete_cat', array('catname' => $cat_tree[$category]['node']['name']), 'admin'); |
|
| 263 | + foreach ($categories as $category) { |
|
| 264 | + logAction('delete_cat', array('catname' => $cat_tree[$category]['node']['name']), 'admin'); |
|
| 265 | + } |
|
| 251 | 266 | |
| 252 | 267 | // Get all boards back into the right order. |
| 253 | 268 | reorderBoards(); |