@@ -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 | class Attachments |
20 | 21 | { |
@@ -70,16 +71,18 @@ discard block |
||
70 | 71 | |
71 | 72 | $this->_sa = !empty($_REQUEST['sa']) ? $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_REQUEST['sa'])) : false; |
72 | 73 | |
73 | - if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) |
|
74 | - $this->{$this->_sa}(); |
|
74 | + if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) { |
|
75 | + $this->{$this->_sa}(); |
|
76 | + } |
|
75 | 77 | |
76 | 78 | // Just send a generic message. |
77 | - else |
|
78 | - $this->setResponse(array( |
|
79 | + else { |
|
80 | + $this->setResponse(array( |
|
79 | 81 | 'text' => $this->_sa == 'add' ? 'attach_error_title' : 'attached_file_deleted_error', |
80 | 82 | 'type' => 'error', |
81 | 83 | 'data' => false, |
82 | 84 | )); |
85 | + } |
|
83 | 86 | |
84 | 87 | // Back to the future, oh, to the browser! |
85 | 88 | $this->sendResponse(); |
@@ -95,12 +98,13 @@ discard block |
||
95 | 98 | $attachID = !empty($_REQUEST['attach']) && is_numeric($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : 0; |
96 | 99 | |
97 | 100 | // Need something to work with. |
98 | - if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) |
|
99 | - return $this->setResponse(array( |
|
101 | + if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) { |
|
102 | + return $this->setResponse(array( |
|
100 | 103 | 'text' => 'attached_file_deleted_error', |
101 | 104 | 'type' => 'error', |
102 | 105 | 'data' => false, |
103 | 106 | )); |
107 | + } |
|
104 | 108 | |
105 | 109 | // Lets pass some params and see what happens :P |
106 | 110 | $affectedMessage = removeAttachments(array('id_attach' => $attachID), '', true, true); |
@@ -119,19 +123,21 @@ discard block |
||
119 | 123 | public function add() |
120 | 124 | { |
121 | 125 | // You gotta be able to post attachments. |
122 | - if (!$this->_canPostAttachment) |
|
123 | - return $this->setResponse(array( |
|
126 | + if (!$this->_canPostAttachment) { |
|
127 | + return $this->setResponse(array( |
|
124 | 128 | 'text' => 'attached_file_cannot', |
125 | 129 | 'type' => 'error', |
126 | 130 | 'data' => false, |
127 | 131 | )); |
132 | + } |
|
128 | 133 | |
129 | 134 | // Process them at once! |
130 | 135 | $this->processAttachments(); |
131 | 136 | |
132 | 137 | // The attachments was created and moved the the right folder, time to update the DB. |
133 | - if (!empty($_SESSION['temp_attachments'])) |
|
134 | - $this->createAtttach(); |
|
138 | + if (!empty($_SESSION['temp_attachments'])) { |
|
139 | + $this->createAtttach(); |
|
140 | + } |
|
135 | 141 | |
136 | 142 | // Set the response. |
137 | 143 | $this->setResponse(); |
@@ -144,8 +150,9 @@ discard block |
||
144 | 150 | { |
145 | 151 | global $context, $modSettings, $smcFunc, $user_info, $txt; |
146 | 152 | |
147 | - if (!isset($_FILES['attachment']['name'])) |
|
148 | - $_FILES['attachment']['tmp_name'] = array(); |
|
153 | + if (!isset($_FILES['attachment']['name'])) { |
|
154 | + $_FILES['attachment']['tmp_name'] = array(); |
|
155 | + } |
|
149 | 156 | |
150 | 157 | // If there are attachments, calculate the total size and how many. |
151 | 158 | $context['attachments']['total_size'] = 0; |
@@ -155,25 +162,30 @@ discard block |
||
155 | 162 | if (isset($_REQUEST['msg'])) |
156 | 163 | { |
157 | 164 | $context['attachments']['quantity'] = count($context['current_attachments']); |
158 | - foreach ($context['current_attachments'] as $attachment) |
|
159 | - $context['attachments']['total_size'] += $attachment['size']; |
|
165 | + foreach ($context['current_attachments'] as $attachment) { |
|
166 | + $context['attachments']['total_size'] += $attachment['size']; |
|
167 | + } |
|
160 | 168 | } |
161 | 169 | |
162 | 170 | // A bit of house keeping first. |
163 | - if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) |
|
164 | - unset($_SESSION['temp_attachments']); |
|
171 | + if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) { |
|
172 | + unset($_SESSION['temp_attachments']); |
|
173 | + } |
|
165 | 174 | |
166 | 175 | // Our infamous SESSION var, we are gonna have soo much fun with it! |
167 | - if (!isset($_SESSION['temp_attachments'])) |
|
168 | - $_SESSION['temp_attachments'] = array(); |
|
176 | + if (!isset($_SESSION['temp_attachments'])) { |
|
177 | + $_SESSION['temp_attachments'] = array(); |
|
178 | + } |
|
169 | 179 | |
170 | 180 | // Make sure we're uploading to the right place. |
171 | - if (!empty($modSettings['automanage_attachments'])) |
|
172 | - automanage_attachments_check_directory(); |
|
181 | + if (!empty($modSettings['automanage_attachments'])) { |
|
182 | + automanage_attachments_check_directory(); |
|
183 | + } |
|
173 | 184 | |
174 | 185 | // Is the attachments folder actually there? |
175 | - if (!empty($context['dir_creation_error'])) |
|
176 | - $this->_generalErrors[] = $context['dir_creation_error']; |
|
186 | + if (!empty($context['dir_creation_error'])) { |
|
187 | + $this->_generalErrors[] = $context['dir_creation_error']; |
|
188 | + } |
|
177 | 189 | |
178 | 190 | // The current attach folder ha some issues... |
179 | 191 | elseif (!is_dir($this->_attchDir)) |
@@ -198,13 +210,12 @@ discard block |
||
198 | 210 | ); |
199 | 211 | list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request); |
200 | 212 | $smcFunc['db_free_result']($request); |
201 | - } |
|
202 | - |
|
203 | - else |
|
204 | - $context['attachments'] = array( |
|
213 | + } else { |
|
214 | + $context['attachments'] = array( |
|
205 | 215 | 'quantity' => 0, |
206 | 216 | 'total_size' => 0, |
207 | 217 | ); |
218 | + } |
|
208 | 219 | |
209 | 220 | // Check for other general errors here. |
210 | 221 | |
@@ -212,9 +223,10 @@ discard block |
||
212 | 223 | if (!empty($this->_generalErrors)) |
213 | 224 | { |
214 | 225 | // And delete the files 'cos they ain't going nowhere. |
215 | - foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
|
216 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
226 | + foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) { |
|
227 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
217 | 228 | unlink($_FILES['attachment']['tmp_name'][$n]); |
229 | + } |
|
218 | 230 | |
219 | 231 | $_FILES['attachment']['tmp_name'] = array(); |
220 | 232 | |
@@ -225,26 +237,29 @@ discard block |
||
225 | 237 | // Loop through $_FILES['attachment'] array and move each file to the current attachments folder. |
226 | 238 | foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
227 | 239 | { |
228 | - if ($_FILES['attachment']['name'][$n] == '') |
|
229 | - continue; |
|
240 | + if ($_FILES['attachment']['name'][$n] == '') { |
|
241 | + continue; |
|
242 | + } |
|
230 | 243 | |
231 | 244 | // First, let's first check for PHP upload errors. |
232 | 245 | $errors = array(); |
233 | 246 | if (!empty($_FILES['attachment']['error'][$n])) |
234 | 247 | { |
235 | - if ($_FILES['attachment']['error'][$n] == 2) |
|
236 | - $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
237 | - |
|
238 | - else |
|
239 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
248 | + if ($_FILES['attachment']['error'][$n] == 2) { |
|
249 | + $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
250 | + } else { |
|
251 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
252 | + } |
|
240 | 253 | |
241 | 254 | // Log this one, because... |
242 | - if ($_FILES['attachment']['error'][$n] == 6) |
|
243 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
255 | + if ($_FILES['attachment']['error'][$n] == 6) { |
|
256 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
257 | + } |
|
244 | 258 | |
245 | 259 | // Weird, no errors were cached, still fill out a generic one. |
246 | - if (empty($errors)) |
|
247 | - $errors[] = 'attach_php_error'; |
|
260 | + if (empty($errors)) { |
|
261 | + $errors[] = 'attach_php_error'; |
|
262 | + } |
|
248 | 263 | } |
249 | 264 | |
250 | 265 | // Try to move and rename the file before doing any more checks on it. |
@@ -256,8 +271,9 @@ discard block |
||
256 | 271 | { |
257 | 272 | // The reported MIME type of the attachment might not be reliable. |
258 | 273 | // Fortunately, PHP 5.3+ lets us easily verify the real MIME type. |
259 | - if (function_exists('mime_content_type')) |
|
260 | - $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
274 | + if (function_exists('mime_content_type')) { |
|
275 | + $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
276 | + } |
|
261 | 277 | |
262 | 278 | $_SESSION['temp_attachments'][$attachID] = array( |
263 | 279 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -269,16 +285,18 @@ discard block |
||
269 | 285 | ); |
270 | 286 | |
271 | 287 | // Move the file to the attachments folder with a temp name for now. |
272 | - if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) |
|
273 | - smf_chmod($destName, 0644); |
|
288 | + if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) { |
|
289 | + smf_chmod($destName, 0644); |
|
290 | + } |
|
274 | 291 | |
275 | 292 | // This is madness!! |
276 | 293 | else |
277 | 294 | { |
278 | 295 | // File couldn't be moved. |
279 | 296 | $_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout'; |
280 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
281 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
297 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
298 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
299 | + } |
|
282 | 300 | } |
283 | 301 | } |
284 | 302 | |
@@ -291,13 +309,15 @@ discard block |
||
291 | 309 | 'errors' => $errors, |
292 | 310 | ); |
293 | 311 | |
294 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
295 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
312 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
313 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
314 | + } |
|
296 | 315 | } |
297 | 316 | |
298 | 317 | // If there's no errors to this point. We still do need to apply some additional checks before we are finished. |
299 | - if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
|
300 | - attachmentChecks($attachID); |
|
318 | + if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) { |
|
319 | + attachmentChecks($attachID); |
|
320 | + } |
|
301 | 321 | } |
302 | 322 | |
303 | 323 | // Mod authors, finally a hook to hang an alternate attachment upload system upon |
@@ -334,23 +354,24 @@ discard block |
||
334 | 354 | 'errors' => $attachment['errors'], |
335 | 355 | ); |
336 | 356 | |
337 | - if (empty($attachment['errors'])) |
|
338 | - if (createAttachment($attachmentOptions)) |
|
357 | + if (empty($attachment['errors'])) { |
|
358 | + if (createAttachment($attachmentOptions)) |
|
339 | 359 | { |
340 | 360 | // Avoid JS getting confused. |
341 | 361 | $attachmentOptions['attachID'] = $attachmentOptions['id']; |
362 | + } |
|
342 | 363 | unset($attachmentOptions['id']); |
343 | 364 | |
344 | 365 | $_SESSION['already_attached'][$attachmentOptions['attachID']] = $attachmentOptions['attachID']; |
345 | 366 | |
346 | - if (!empty($attachmentOptions['thumb'])) |
|
347 | - $_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb']; |
|
348 | - |
|
349 | - if ($this->_msg) |
|
350 | - assignAttachments($_SESSION['already_attached'], $this->_msg); |
|
351 | - } |
|
367 | + if (!empty($attachmentOptions['thumb'])) { |
|
368 | + $_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb']; |
|
369 | + } |
|
352 | 370 | |
353 | - elseif (!empty($attachmentOptions['errors'])) |
|
371 | + if ($this->_msg) { |
|
372 | + assignAttachments($_SESSION['already_attached'], $this->_msg); |
|
373 | + } |
|
374 | + } elseif (!empty($attachmentOptions['errors'])) |
|
354 | 375 | { |
355 | 376 | // Sort out the errors for display and delete any associated files. |
356 | 377 | $log_these = array('attachments_no_create', 'attachments_no_write', 'attach_timeout', 'ran_out_of_space', 'cant_access_upload_path', 'attach_0_byte_file'); |
@@ -362,14 +383,16 @@ discard block |
||
362 | 383 | if (!is_array($error)) |
363 | 384 | { |
364 | 385 | $attachmentOptions['errors'][] = $txt[$error]; |
365 | - if (in_array($error, $log_these)) |
|
366 | - log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
386 | + if (in_array($error, $log_these)) { |
|
387 | + log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
388 | + } |
|
389 | + } else { |
|
390 | + $attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]); |
|
367 | 391 | } |
368 | - else |
|
369 | - $attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]); |
|
370 | 392 | } |
371 | - if (file_exists($attachment['tmp_name'])) |
|
372 | - unlink($attachment['tmp_name']); |
|
393 | + if (file_exists($attachment['tmp_name'])) { |
|
394 | + unlink($attachment['tmp_name']); |
|
395 | + } |
|
373 | 396 | } |
374 | 397 | |
375 | 398 | // Regardless of errors, pass the results. |
@@ -377,8 +400,9 @@ discard block |
||
377 | 400 | } |
378 | 401 | |
379 | 402 | // Temp save this on the db. |
380 | - if (!empty($_SESSION['already_attached'])) |
|
381 | - $this->_attachSuccess = $_SESSION['already_attached']; |
|
403 | + if (!empty($_SESSION['already_attached'])) { |
|
404 | + $this->_attachSuccess = $_SESSION['already_attached']; |
|
405 | + } |
|
382 | 406 | |
383 | 407 | unset($_SESSION['temp_attachments']); |
384 | 408 | } |
@@ -398,14 +422,16 @@ discard block |
||
398 | 422 | if ($this->_sa == 'add') |
399 | 423 | { |
400 | 424 | // Is there any generic errors? made some sense out of them! |
401 | - if ($this->_generalErrors) |
|
402 | - foreach ($this->_generalErrors as $k => $v) |
|
425 | + if ($this->_generalErrors) { |
|
426 | + foreach ($this->_generalErrors as $k => $v) |
|
403 | 427 | $this->_generalErrors[$k] = (is_array($v) ? vsprintf($txt[$v[0]], $v[1]) : $txt[$v]); |
428 | + } |
|
404 | 429 | |
405 | 430 | // Gotta urlencode the filename. |
406 | - if ($this->_attachResults) |
|
407 | - foreach ($this->_attachResults as $k => $v) |
|
431 | + if ($this->_attachResults) { |
|
432 | + foreach ($this->_attachResults as $k => $v) |
|
408 | 433 | $this->_attachResults[$k]['name'] = urlencode($this->_attachResults[$k]['name']); |
434 | + } |
|
409 | 435 | |
410 | 436 | $this->_response = array( |
411 | 437 | 'files' => $this->_attachResults ? $this->_attachResults : false, |
@@ -414,9 +440,10 @@ discard block |
||
414 | 440 | } |
415 | 441 | |
416 | 442 | // Rest of us mere mortals gets no special treatment... |
417 | - elseif (!empty($data)) |
|
418 | - if (!empty($data['text']) && !empty($txt[$data['text']])) |
|
443 | + elseif (!empty($data)) { |
|
444 | + if (!empty($data['text']) && !empty($txt[$data['text']])) |
|
419 | 445 | $this->_response['text'] = $txt[$data['text']]; |
446 | + } |
|
420 | 447 | } |
421 | 448 | |
422 | 449 | protected function sendResponse() |
@@ -425,11 +452,11 @@ discard block |
||
425 | 452 | |
426 | 453 | ob_end_clean(); |
427 | 454 | |
428 | - if (!empty($modSettings['CompressedOutput'])) |
|
429 | - @ob_start('ob_gzhandler'); |
|
430 | - |
|
431 | - else |
|
432 | - ob_start(); |
|
455 | + if (!empty($modSettings['CompressedOutput'])) { |
|
456 | + @ob_start('ob_gzhandler'); |
|
457 | + } else { |
|
458 | + ob_start(); |
|
459 | + } |
|
433 | 460 | |
434 | 461 | // Set the header. |
435 | 462 | header('Content-Type: application/json; charset='. $context['character_set'] .''); |
@@ -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'); |
@@ -54,21 +57,25 @@ discard block |
||
54 | 57 | |
55 | 58 | if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments'])) |
56 | 59 | { |
57 | - if (!is_array($modSettings['attachment_basedirectories'])) |
|
58 | - $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
60 | + if (!is_array($modSettings['attachment_basedirectories'])) { |
|
61 | + $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
62 | + } |
|
59 | 63 | $base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']); |
64 | + } else { |
|
65 | + $base_dir = 0; |
|
60 | 66 | } |
61 | - else |
|
62 | - $base_dir = 0; |
|
63 | 67 | |
64 | 68 | if ($modSettings['automanage_attachments'] == 1) |
65 | 69 | { |
66 | - if (!isset($modSettings['last_attachments_directory'])) |
|
67 | - $modSettings['last_attachments_directory'] = array(); |
|
68 | - if (!is_array($modSettings['last_attachments_directory'])) |
|
69 | - $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
70 | - if (!isset($modSettings['last_attachments_directory'][$base_dir])) |
|
71 | - $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
70 | + if (!isset($modSettings['last_attachments_directory'])) { |
|
71 | + $modSettings['last_attachments_directory'] = array(); |
|
72 | + } |
|
73 | + if (!is_array($modSettings['last_attachments_directory'])) { |
|
74 | + $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
75 | + } |
|
76 | + if (!isset($modSettings['last_attachments_directory'][$base_dir])) { |
|
77 | + $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
78 | + } |
|
72 | 79 | } |
73 | 80 | |
74 | 81 | $basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
@@ -97,12 +104,14 @@ discard block |
||
97 | 104 | $updir = ''; |
98 | 105 | } |
99 | 106 | |
100 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
101 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
102 | - if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) |
|
103 | - $outputCreation = automanage_attachments_create_directory($updir); |
|
104 | - elseif (in_array($updir, $modSettings['attachmentUploadDir'])) |
|
105 | - $outputCreation = true; |
|
107 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
108 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
109 | + } |
|
110 | + if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) { |
|
111 | + $outputCreation = automanage_attachments_create_directory($updir); |
|
112 | + } elseif (in_array($updir, $modSettings['attachmentUploadDir'])) { |
|
113 | + $outputCreation = true; |
|
114 | + } |
|
106 | 115 | |
107 | 116 | if ($outputCreation) |
108 | 117 | { |
@@ -139,8 +148,9 @@ discard block |
||
139 | 148 | $count = count($tree); |
140 | 149 | |
141 | 150 | $directory = attachments_init_dir($tree, $count); |
142 | - if ($directory === false) |
|
143 | - return false; |
|
151 | + if ($directory === false) { |
|
152 | + return false; |
|
153 | + } |
|
144 | 154 | } |
145 | 155 | |
146 | 156 | $directory .= DIRECTORY_SEPARATOR . array_shift($tree); |
@@ -168,8 +178,9 @@ discard block |
||
168 | 178 | } |
169 | 179 | |
170 | 180 | // Everything seems fine...let's create the .htaccess |
171 | - if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) |
|
172 | - secureDirectory($updir, true); |
|
181 | + if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) { |
|
182 | + secureDirectory($updir, true); |
|
183 | + } |
|
173 | 184 | |
174 | 185 | $sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR; |
175 | 186 | $updir = rtrim($updir, $sep); |
@@ -201,8 +212,9 @@ discard block |
||
201 | 212 | { |
202 | 213 | global $modSettings, $boarddir; |
203 | 214 | |
204 | - if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) |
|
205 | - return; |
|
215 | + if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) { |
|
216 | + return; |
|
217 | + } |
|
206 | 218 | |
207 | 219 | $basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir; |
208 | 220 | // Just to be sure: I don't want directory separators at the end |
@@ -214,13 +226,14 @@ discard block |
||
214 | 226 | { |
215 | 227 | $base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']); |
216 | 228 | $base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0; |
229 | + } else { |
|
230 | + $base_dir = 0; |
|
217 | 231 | } |
218 | - else |
|
219 | - $base_dir = 0; |
|
220 | 232 | |
221 | 233 | // Get the last attachment directory for that base directory |
222 | - if (empty($modSettings['last_attachments_directory'][$base_dir])) |
|
223 | - $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
234 | + if (empty($modSettings['last_attachments_directory'][$base_dir])) { |
|
235 | + $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
236 | + } |
|
224 | 237 | // And increment it. |
225 | 238 | $modSettings['last_attachments_directory'][$base_dir]++; |
226 | 239 | |
@@ -235,10 +248,10 @@ discard block |
||
235 | 248 | $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
236 | 249 | |
237 | 250 | return true; |
251 | + } else { |
|
252 | + return false; |
|
253 | + } |
|
238 | 254 | } |
239 | - else |
|
240 | - return false; |
|
241 | -} |
|
242 | 255 | |
243 | 256 | /** |
244 | 257 | * Split a path into a list of all directories and subdirectories |
@@ -256,12 +269,13 @@ discard block |
||
256 | 269 | * in Windows we need to explode for both \ and / |
257 | 270 | * while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR) |
258 | 271 | */ |
259 | - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') |
|
260 | - $tree = preg_split('#[\\\/]#', $directory); |
|
261 | - else |
|
272 | + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
|
273 | + $tree = preg_split('#[\\\/]#', $directory); |
|
274 | + } else |
|
262 | 275 | { |
263 | - if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) |
|
264 | - return false; |
|
276 | + if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) { |
|
277 | + return false; |
|
278 | + } |
|
265 | 279 | |
266 | 280 | $tree = explode(DIRECTORY_SEPARATOR, trim($directory, DIRECTORY_SEPARATOR)); |
267 | 281 | } |
@@ -285,10 +299,11 @@ discard block |
||
285 | 299 | //Better be sure that the first part of the path is actually a drive letter... |
286 | 300 | //...even if, I should check this in the admin page...isn't it? |
287 | 301 | //...NHAAA Let's leave space for users' complains! :P |
288 | - if (preg_match('/^[a-z]:$/i', $tree[0])) |
|
289 | - $directory = array_shift($tree); |
|
290 | - else |
|
291 | - return false; |
|
302 | + if (preg_match('/^[a-z]:$/i', $tree[0])) { |
|
303 | + $directory = array_shift($tree); |
|
304 | + } else { |
|
305 | + return false; |
|
306 | + } |
|
292 | 307 | |
293 | 308 | $count--; |
294 | 309 | } |
@@ -303,18 +318,20 @@ discard block |
||
303 | 318 | global $context, $modSettings, $smcFunc, $txt, $user_info; |
304 | 319 | |
305 | 320 | // Make sure we're uploading to the right place. |
306 | - if (!empty($modSettings['automanage_attachments'])) |
|
307 | - automanage_attachments_check_directory(); |
|
321 | + if (!empty($modSettings['automanage_attachments'])) { |
|
322 | + automanage_attachments_check_directory(); |
|
323 | + } |
|
308 | 324 | |
309 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
310 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
325 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
326 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
327 | + } |
|
311 | 328 | |
312 | 329 | $context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
313 | 330 | |
314 | 331 | // Is the attachments folder actualy there? |
315 | - if (!empty($context['dir_creation_error'])) |
|
316 | - $initial_error = $context['dir_creation_error']; |
|
317 | - elseif (!is_dir($context['attach_dir'])) |
|
332 | + if (!empty($context['dir_creation_error'])) { |
|
333 | + $initial_error = $context['dir_creation_error']; |
|
334 | + } elseif (!is_dir($context['attach_dir'])) |
|
318 | 335 | { |
319 | 336 | $initial_error = 'attach_folder_warning'; |
320 | 337 | log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical'); |
@@ -337,12 +354,12 @@ discard block |
||
337 | 354 | ); |
338 | 355 | list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request); |
339 | 356 | $smcFunc['db_free_result']($request); |
340 | - } |
|
341 | - else |
|
342 | - $context['attachments'] = array( |
|
357 | + } else { |
|
358 | + $context['attachments'] = array( |
|
343 | 359 | 'quantity' => 0, |
344 | 360 | 'total_size' => 0, |
345 | 361 | ); |
362 | + } |
|
346 | 363 | } |
347 | 364 | |
348 | 365 | // Hmm. There are still files in session. |
@@ -352,39 +369,44 @@ discard block |
||
352 | 369 | // Let's try to keep them. But... |
353 | 370 | $ignore_temp = true; |
354 | 371 | // If new files are being added. We can't ignore those |
355 | - foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
356 | - if (!empty($dummy)) |
|
372 | + foreach ($_FILES['attachment']['tmp_name'] as $dummy) { |
|
373 | + if (!empty($dummy)) |
|
357 | 374 | { |
358 | 375 | $ignore_temp = false; |
376 | + } |
|
359 | 377 | break; |
360 | 378 | } |
361 | 379 | |
362 | 380 | // Need to make space for the new files. So, bye bye. |
363 | 381 | if (!$ignore_temp) |
364 | 382 | { |
365 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
366 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
383 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) { |
|
384 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
367 | 385 | unlink($attachment['tmp_name']); |
386 | + } |
|
368 | 387 | |
369 | 388 | $context['we_are_history'] = $txt['error_temp_attachments_flushed']; |
370 | 389 | $_SESSION['temp_attachments'] = array(); |
371 | 390 | } |
372 | 391 | } |
373 | 392 | |
374 | - if (!isset($_FILES['attachment']['name'])) |
|
375 | - $_FILES['attachment']['tmp_name'] = array(); |
|
393 | + if (!isset($_FILES['attachment']['name'])) { |
|
394 | + $_FILES['attachment']['tmp_name'] = array(); |
|
395 | + } |
|
376 | 396 | |
377 | - if (!isset($_SESSION['temp_attachments'])) |
|
378 | - $_SESSION['temp_attachments'] = array(); |
|
397 | + if (!isset($_SESSION['temp_attachments'])) { |
|
398 | + $_SESSION['temp_attachments'] = array(); |
|
399 | + } |
|
379 | 400 | |
380 | 401 | // Remember where we are at. If it's anywhere at all. |
381 | - if (!$ignore_temp) |
|
382 | - $_SESSION['temp_attachments']['post'] = array( |
|
402 | + if (!$ignore_temp) { |
|
403 | + $_SESSION['temp_attachments']['post'] = array( |
|
383 | 404 | 'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0, |
384 | 405 | 'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0, |
385 | 406 | 'topic' => !empty($topic) ? $topic : 0, |
386 | 407 | 'board' => !empty($board) ? $board : 0, |
387 | 408 | ); |
409 | + } |
|
388 | 410 | |
389 | 411 | // If we have an initial error, lets just display it. |
390 | 412 | if (!empty($initial_error)) |
@@ -392,9 +414,10 @@ discard block |
||
392 | 414 | $_SESSION['temp_attachments']['initial_error'] = $initial_error; |
393 | 415 | |
394 | 416 | // And delete the files 'cos they ain't going nowhere. |
395 | - foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
|
396 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
417 | + foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) { |
|
418 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
397 | 419 | unlink($_FILES['attachment']['tmp_name'][$n]); |
420 | + } |
|
398 | 421 | |
399 | 422 | $_FILES['attachment']['tmp_name'] = array(); |
400 | 423 | } |
@@ -402,21 +425,24 @@ discard block |
||
402 | 425 | // Loop through $_FILES['attachment'] array and move each file to the current attachments folder. |
403 | 426 | foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
404 | 427 | { |
405 | - if ($_FILES['attachment']['name'][$n] == '') |
|
406 | - continue; |
|
428 | + if ($_FILES['attachment']['name'][$n] == '') { |
|
429 | + continue; |
|
430 | + } |
|
407 | 431 | |
408 | 432 | // First, let's first check for PHP upload errors. |
409 | 433 | $errors = array(); |
410 | 434 | if (!empty($_FILES['attachment']['error'][$n])) |
411 | 435 | { |
412 | - if ($_FILES['attachment']['error'][$n] == 2) |
|
413 | - $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
414 | - elseif ($_FILES['attachment']['error'][$n] == 6) |
|
415 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
416 | - else |
|
417 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
418 | - if (empty($errors)) |
|
419 | - $errors[] = 'attach_php_error'; |
|
436 | + if ($_FILES['attachment']['error'][$n] == 2) { |
|
437 | + $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
438 | + } elseif ($_FILES['attachment']['error'][$n] == 6) { |
|
439 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
440 | + } else { |
|
441 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
442 | + } |
|
443 | + if (empty($errors)) { |
|
444 | + $errors[] = 'attach_php_error'; |
|
445 | + } |
|
420 | 446 | } |
421 | 447 | |
422 | 448 | // Try to move and rename the file before doing any more checks on it. |
@@ -426,8 +452,9 @@ discard block |
||
426 | 452 | { |
427 | 453 | // The reported MIME type of the attachment might not be reliable. |
428 | 454 | // Fortunately, PHP 5.3+ lets us easily verify the real MIME type. |
429 | - if (function_exists('mime_content_type')) |
|
430 | - $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
455 | + if (function_exists('mime_content_type')) { |
|
456 | + $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
457 | + } |
|
431 | 458 | |
432 | 459 | $_SESSION['temp_attachments'][$attachID] = array( |
433 | 460 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -439,16 +466,16 @@ discard block |
||
439 | 466 | ); |
440 | 467 | |
441 | 468 | // Move the file to the attachments folder with a temp name for now. |
442 | - if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) |
|
443 | - smf_chmod($destName, 0644); |
|
444 | - else |
|
469 | + if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) { |
|
470 | + smf_chmod($destName, 0644); |
|
471 | + } else |
|
445 | 472 | { |
446 | 473 | $_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout'; |
447 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
448 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
474 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
475 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
476 | + } |
|
449 | 477 | } |
450 | - } |
|
451 | - else |
|
478 | + } else |
|
452 | 479 | { |
453 | 480 | $_SESSION['temp_attachments'][$attachID] = array( |
454 | 481 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -456,12 +483,14 @@ discard block |
||
456 | 483 | 'errors' => $errors, |
457 | 484 | ); |
458 | 485 | |
459 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
460 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
486 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
487 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
488 | + } |
|
461 | 489 | } |
462 | 490 | // If there's no errors to this point. We still do need to apply some additional checks before we are finished. |
463 | - if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
|
464 | - attachmentChecks($attachID); |
|
491 | + if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) { |
|
492 | + attachmentChecks($attachID); |
|
493 | + } |
|
465 | 494 | } |
466 | 495 | // Mod authors, finally a hook to hang an alternate attachment upload system upon |
467 | 496 | // Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand()) |
@@ -488,21 +517,20 @@ discard block |
||
488 | 517 | global $modSettings, $context, $sourcedir, $smcFunc; |
489 | 518 | |
490 | 519 | // No data or missing data .... Not necessarily needed, but in case a mod author missed something. |
491 | - if (empty($_SESSION['temp_attachments'][$attachID])) |
|
492 | - $error = '$_SESSION[\'temp_attachments\'][$attachID]'; |
|
493 | - |
|
494 | - elseif (empty($attachID)) |
|
495 | - $error = '$attachID'; |
|
496 | - |
|
497 | - elseif (empty($context['attachments'])) |
|
498 | - $error = '$context[\'attachments\']'; |
|
499 | - |
|
500 | - elseif (empty($context['attach_dir'])) |
|
501 | - $error = '$context[\'attach_dir\']'; |
|
520 | + if (empty($_SESSION['temp_attachments'][$attachID])) { |
|
521 | + $error = '$_SESSION[\'temp_attachments\'][$attachID]'; |
|
522 | + } elseif (empty($attachID)) { |
|
523 | + $error = '$attachID'; |
|
524 | + } elseif (empty($context['attachments'])) { |
|
525 | + $error = '$context[\'attachments\']'; |
|
526 | + } elseif (empty($context['attach_dir'])) { |
|
527 | + $error = '$context[\'attach_dir\']'; |
|
528 | + } |
|
502 | 529 | |
503 | 530 | // Let's get their attention. |
504 | - if (!empty($error)) |
|
505 | - fatal_lang_error('attach_check_nag', 'debug', array($error)); |
|
531 | + if (!empty($error)) { |
|
532 | + fatal_lang_error('attach_check_nag', 'debug', array($error)); |
|
533 | + } |
|
506 | 534 | |
507 | 535 | // Just in case this slipped by the first checks, we stop it here and now |
508 | 536 | if ($_SESSION['temp_attachments'][$attachID]['size'] == 0) |
@@ -531,8 +559,9 @@ discard block |
||
531 | 559 | $size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']); |
532 | 560 | if (!(empty($size)) && ($size[2] != $old_format)) |
533 | 561 | { |
534 | - if (isset($context['validImageTypes'][$size[2]])) |
|
535 | - $_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
562 | + if (isset($context['validImageTypes'][$size[2]])) { |
|
563 | + $_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
564 | + } |
|
536 | 565 | } |
537 | 566 | } |
538 | 567 | } |
@@ -586,42 +615,48 @@ discard block |
||
586 | 615 | // Or, let the user know that it ain't gonna happen. |
587 | 616 | else |
588 | 617 | { |
589 | - if (isset($context['dir_creation_error'])) |
|
590 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error']; |
|
591 | - else |
|
592 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
618 | + if (isset($context['dir_creation_error'])) { |
|
619 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error']; |
|
620 | + } else { |
|
621 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
622 | + } |
|
593 | 623 | } |
624 | + } else { |
|
625 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
594 | 626 | } |
595 | - else |
|
596 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
597 | 627 | } |
598 | 628 | } |
599 | 629 | |
600 | 630 | // Is the file too big? |
601 | 631 | $context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size']; |
602 | - if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) |
|
603 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0))); |
|
632 | + if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) { |
|
633 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0))); |
|
634 | + } |
|
604 | 635 | |
605 | 636 | // Check the total upload size for this post... |
606 | - if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) |
|
607 | - $_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))); |
|
637 | + if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) { |
|
638 | + $_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))); |
|
639 | + } |
|
608 | 640 | |
609 | 641 | // Have we reached the maximum number of files we are allowed? |
610 | 642 | $context['attachments']['quantity']++; |
611 | 643 | |
612 | 644 | // Set a max limit if none exists |
613 | - if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) |
|
614 | - $modSettings['attachmentNumPerPostLimit'] = 50; |
|
645 | + if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) { |
|
646 | + $modSettings['attachmentNumPerPostLimit'] = 50; |
|
647 | + } |
|
615 | 648 | |
616 | - if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) |
|
617 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit'])); |
|
649 | + if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) { |
|
650 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit'])); |
|
651 | + } |
|
618 | 652 | |
619 | 653 | // File extension check |
620 | 654 | if (!empty($modSettings['attachmentCheckExtensions'])) |
621 | 655 | { |
622 | 656 | $allowed = explode(',', strtolower($modSettings['attachmentExtensions'])); |
623 | - foreach ($allowed as $k => $dummy) |
|
624 | - $allowed[$k] = trim($dummy); |
|
657 | + foreach ($allowed as $k => $dummy) { |
|
658 | + $allowed[$k] = trim($dummy); |
|
659 | + } |
|
625 | 660 | |
626 | 661 | if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed)) |
627 | 662 | { |
@@ -633,10 +668,12 @@ discard block |
||
633 | 668 | // Undo the math if there's an error |
634 | 669 | if (!empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
635 | 670 | { |
636 | - if (isset($context['dir_size'])) |
|
637 | - $context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
|
638 | - if (isset($context['dir_files'])) |
|
639 | - $context['dir_files']--; |
|
671 | + if (isset($context['dir_size'])) { |
|
672 | + $context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
|
673 | + } |
|
674 | + if (isset($context['dir_files'])) { |
|
675 | + $context['dir_files']--; |
|
676 | + } |
|
640 | 677 | $context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
641 | 678 | $context['attachments']['quantity']--; |
642 | 679 | return false; |
@@ -668,12 +705,14 @@ discard block |
||
668 | 705 | if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width']) |
669 | 706 | { |
670 | 707 | // Got a proper mime type? |
671 | - if (!empty($size['mime'])) |
|
672 | - $attachmentOptions['mime_type'] = $size['mime']; |
|
708 | + if (!empty($size['mime'])) { |
|
709 | + $attachmentOptions['mime_type'] = $size['mime']; |
|
710 | + } |
|
673 | 711 | |
674 | 712 | // Otherwise a valid one? |
675 | - elseif (isset($context['validImageTypes'][$size[2]])) |
|
676 | - $attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
713 | + elseif (isset($context['validImageTypes'][$size[2]])) { |
|
714 | + $attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
715 | + } |
|
677 | 716 | } |
678 | 717 | |
679 | 718 | // It is possible we might have a MIME type that isn't actually an image but still have a size. |
@@ -685,15 +724,17 @@ discard block |
||
685 | 724 | } |
686 | 725 | |
687 | 726 | // Get the hash if no hash has been given yet. |
688 | - if (empty($attachmentOptions['file_hash'])) |
|
689 | - $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true); |
|
727 | + if (empty($attachmentOptions['file_hash'])) { |
|
728 | + $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true); |
|
729 | + } |
|
690 | 730 | |
691 | 731 | // Assuming no-one set the extension let's take a look at it. |
692 | 732 | if (empty($attachmentOptions['fileext'])) |
693 | 733 | { |
694 | 734 | $attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : ''); |
695 | - if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) |
|
696 | - $attachmentOptions['fileext'] = ''; |
|
735 | + if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) { |
|
736 | + $attachmentOptions['fileext'] = ''; |
|
737 | + } |
|
697 | 738 | } |
698 | 739 | |
699 | 740 | // Last chance to change stuff! |
@@ -702,8 +743,9 @@ discard block |
||
702 | 743 | // Make sure the folder is valid... |
703 | 744 | $tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : smf_json_decode($modSettings['attachmentUploadDir'], true); |
704 | 745 | $folders = array_keys($tmp); |
705 | - if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) |
|
706 | - $attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir']; |
|
746 | + if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) { |
|
747 | + $attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir']; |
|
748 | + } |
|
707 | 749 | |
708 | 750 | $attachmentOptions['id'] = $smcFunc['db_insert']('', |
709 | 751 | '{db_prefix}attachments', |
@@ -734,8 +776,8 @@ discard block |
||
734 | 776 | rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']); |
735 | 777 | |
736 | 778 | // If it's not approved then add to the approval queue. |
737 | - if (!$attachmentOptions['approved']) |
|
738 | - $smcFunc['db_insert']('', |
|
779 | + if (!$attachmentOptions['approved']) { |
|
780 | + $smcFunc['db_insert']('', |
|
739 | 781 | '{db_prefix}approval_queue', |
740 | 782 | array( |
741 | 783 | 'id_attach' => 'int', 'id_msg' => 'int', |
@@ -745,9 +787,11 @@ discard block |
||
745 | 787 | ), |
746 | 788 | array() |
747 | 789 | ); |
790 | + } |
|
748 | 791 | |
749 | - if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) |
|
750 | - return true; |
|
792 | + if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) { |
|
793 | + return true; |
|
794 | + } |
|
751 | 795 | |
752 | 796 | // Like thumbnails, do we? |
753 | 797 | if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight'])) |
@@ -758,13 +802,15 @@ discard block |
||
758 | 802 | $size = @getimagesize($attachmentOptions['destination'] . '_thumb'); |
759 | 803 | list ($thumb_width, $thumb_height) = $size; |
760 | 804 | |
761 | - if (!empty($size['mime'])) |
|
762 | - $thumb_mime = $size['mime']; |
|
763 | - elseif (isset($context['validImageTypes'][$size[2]])) |
|
764 | - $thumb_mime = 'image/' . $context['validImageTypes'][$size[2]]; |
|
805 | + if (!empty($size['mime'])) { |
|
806 | + $thumb_mime = $size['mime']; |
|
807 | + } elseif (isset($context['validImageTypes'][$size[2]])) { |
|
808 | + $thumb_mime = 'image/' . $context['validImageTypes'][$size[2]]; |
|
809 | + } |
|
765 | 810 | // Lord only knows how this happened... |
766 | - else |
|
767 | - $thumb_mime = ''; |
|
811 | + else { |
|
812 | + $thumb_mime = ''; |
|
813 | + } |
|
768 | 814 | |
769 | 815 | $thumb_filename = $attachmentOptions['name'] . '_thumb'; |
770 | 816 | $thumb_size = filesize($attachmentOptions['destination'] . '_thumb'); |
@@ -844,15 +890,17 @@ discard block |
||
844 | 890 | global $smcFunc; |
845 | 891 | |
846 | 892 | // Oh, come on! |
847 | - if (empty($attachIDs) || empty($msgID)) |
|
848 | - return false; |
|
893 | + if (empty($attachIDs) || empty($msgID)) { |
|
894 | + return false; |
|
895 | + } |
|
849 | 896 | |
850 | 897 | // "I see what is right and approve, but I do what is wrong." |
851 | 898 | call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID)); |
852 | 899 | |
853 | 900 | // One last check |
854 | - if (empty($attachIDs)) |
|
855 | - return false; |
|
901 | + if (empty($attachIDs)) { |
|
902 | + return false; |
|
903 | + } |
|
856 | 904 | |
857 | 905 | // Perform. |
858 | 906 | $smcFunc['db_query']('', ' |
@@ -882,8 +930,9 @@ discard block |
||
882 | 930 | $externalParse = false; |
883 | 931 | |
884 | 932 | // Meh... |
885 | - if (empty($attachID)) |
|
886 | - return 'attachments_no_data_loaded'; |
|
933 | + if (empty($attachID)) { |
|
934 | + return 'attachments_no_data_loaded'; |
|
935 | + } |
|
887 | 936 | |
888 | 937 | // Make it easy. |
889 | 938 | $msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0; |
@@ -892,20 +941,23 @@ discard block |
||
892 | 941 | $externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID)); |
893 | 942 | |
894 | 943 | // "I am innocent of the blood of this just person: see ye to it." |
895 | - if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) |
|
896 | - return $externalParse; |
|
944 | + if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) { |
|
945 | + return $externalParse; |
|
946 | + } |
|
897 | 947 | |
898 | 948 | //Are attachments enable? |
899 | - if (empty($modSettings['attachmentEnable'])) |
|
900 | - return 'attachments_not_enable'; |
|
949 | + if (empty($modSettings['attachmentEnable'])) { |
|
950 | + return 'attachments_not_enable'; |
|
951 | + } |
|
901 | 952 | |
902 | 953 | // Previewing much? no msg ID has been set yet. |
903 | 954 | if (!empty($context['preview_message'])) |
904 | 955 | { |
905 | 956 | $allAttachments = getAttachsByMsg(0); |
906 | 957 | |
907 | - if (empty($allAttachments[0][$attachID])) |
|
908 | - return 'attachments_no_data_loaded'; |
|
958 | + if (empty($allAttachments[0][$attachID])) { |
|
959 | + return 'attachments_no_data_loaded'; |
|
960 | + } |
|
909 | 961 | |
910 | 962 | $attachLoaded = loadAttachmentContext(0, $allAttachments); |
911 | 963 | |
@@ -917,57 +969,66 @@ discard block |
||
917 | 969 | $attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview' . (empty($attachContext['is_image']) ? ';file' : '') . '">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>'; |
918 | 970 | |
919 | 971 | // Fix the thumbnail too, if the image has one. |
920 | - if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) |
|
921 | - $attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview'; |
|
972 | + if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) { |
|
973 | + $attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview'; |
|
974 | + } |
|
922 | 975 | |
923 | 976 | return $attachContext; |
924 | 977 | } |
925 | 978 | |
926 | 979 | // There is always the chance someone else has already done our dirty work... |
927 | 980 | // If so, all pertinent checks were already done. Hopefully... |
928 | - if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) |
|
929 | - return $context['current_attachments'][$attachID]; |
|
981 | + if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) { |
|
982 | + return $context['current_attachments'][$attachID]; |
|
983 | + } |
|
930 | 984 | |
931 | 985 | // If we are lucky enough to be in $board's scope then check it! |
932 | - if (!empty($board) && !allowedTo('view_attachments', $board)) |
|
933 | - return 'attachments_not_allowed_to_see'; |
|
986 | + if (!empty($board) && !allowedTo('view_attachments', $board)) { |
|
987 | + return 'attachments_not_allowed_to_see'; |
|
988 | + } |
|
934 | 989 | |
935 | 990 | // Get the message info associated with this particular attach ID. |
936 | 991 | $attachInfo = getAttachMsgInfo($attachID); |
937 | 992 | |
938 | 993 | // There is always the chance this attachment no longer exists or isn't associated to a message anymore... |
939 | - if (empty($attachInfo) || empty($attachInfo['msg'])) |
|
940 | - return 'attachments_no_msg_associated'; |
|
994 | + if (empty($attachInfo) || empty($attachInfo['msg'])) { |
|
995 | + return 'attachments_no_msg_associated'; |
|
996 | + } |
|
941 | 997 | |
942 | 998 | // Hold it! got the info now check if you can see this attachment. |
943 | - if (!allowedTo('view_attachments', $attachInfo['board'])) |
|
944 | - return 'attachments_not_allowed_to_see'; |
|
999 | + if (!allowedTo('view_attachments', $attachInfo['board'])) { |
|
1000 | + return 'attachments_not_allowed_to_see'; |
|
1001 | + } |
|
945 | 1002 | |
946 | 1003 | $allAttachments = getAttachsByMsg($attachInfo['msg']); |
947 | 1004 | $attachContext = $allAttachments[$attachInfo['msg']][$attachID]; |
948 | 1005 | |
949 | 1006 | // No point in keep going further. |
950 | - if (!allowedTo('view_attachments', $attachContext['board'])) |
|
951 | - return 'attachments_not_allowed_to_see'; |
|
1007 | + if (!allowedTo('view_attachments', $attachContext['board'])) { |
|
1008 | + return 'attachments_not_allowed_to_see'; |
|
1009 | + } |
|
952 | 1010 | |
953 | 1011 | // Load this particular attach's context. |
954 | - if (!empty($attachContext)) |
|
955 | - $attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments); |
|
1012 | + if (!empty($attachContext)) { |
|
1013 | + $attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments); |
|
1014 | + } |
|
956 | 1015 | |
957 | 1016 | // One last check, you know, gotta be paranoid... |
958 | - else |
|
959 | - return 'attachments_no_data_loaded'; |
|
1017 | + else { |
|
1018 | + return 'attachments_no_data_loaded'; |
|
1019 | + } |
|
960 | 1020 | |
961 | 1021 | // This is the last "if" I promise! |
962 | - if (empty($attachLoaded)) |
|
963 | - return 'attachments_no_data_loaded'; |
|
964 | - |
|
965 | - else |
|
966 | - $attachContext = $attachLoaded[$attachID]; |
|
1022 | + if (empty($attachLoaded)) { |
|
1023 | + return 'attachments_no_data_loaded'; |
|
1024 | + } else { |
|
1025 | + $attachContext = $attachLoaded[$attachID]; |
|
1026 | + } |
|
967 | 1027 | |
968 | 1028 | // You may or may not want to show this under the post. |
969 | - if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) |
|
970 | - $context['show_attach_under_post'][$attachID] = $attachID; |
|
1029 | + if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) { |
|
1030 | + $context['show_attach_under_post'][$attachID] = $attachID; |
|
1031 | + } |
|
971 | 1032 | |
972 | 1033 | // Last minute changes? |
973 | 1034 | call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext)); |
@@ -987,8 +1048,9 @@ discard block |
||
987 | 1048 | { |
988 | 1049 | global $smcFunc, $modSettings; |
989 | 1050 | |
990 | - if (empty($attachIDs)) |
|
991 | - return array(); |
|
1051 | + if (empty($attachIDs)) { |
|
1052 | + return array(); |
|
1053 | + } |
|
992 | 1054 | |
993 | 1055 | $return = array(); |
994 | 1056 | |
@@ -1004,11 +1066,12 @@ discard block |
||
1004 | 1066 | ) |
1005 | 1067 | ); |
1006 | 1068 | |
1007 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1008 | - return array(); |
|
1069 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1070 | + return array(); |
|
1071 | + } |
|
1009 | 1072 | |
1010 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1011 | - $return[$row['id_attach']] = array( |
|
1073 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1074 | + $return[$row['id_attach']] = array( |
|
1012 | 1075 | 'name' => $smcFunc['htmlspecialchars']($row['filename']), |
1013 | 1076 | 'size' => $row['size'], |
1014 | 1077 | 'attachID' => $row['id_attach'], |
@@ -1017,6 +1080,7 @@ discard block |
||
1017 | 1080 | 'mime_type' => $row['mime_type'], |
1018 | 1081 | 'thumb' => $row['id_thumb'], |
1019 | 1082 | ); |
1083 | + } |
|
1020 | 1084 | $smcFunc['db_free_result']($request); |
1021 | 1085 | |
1022 | 1086 | return $return; |
@@ -1033,8 +1097,9 @@ discard block |
||
1033 | 1097 | { |
1034 | 1098 | global $smcFunc; |
1035 | 1099 | |
1036 | - if (empty($attachID)) |
|
1037 | - return array(); |
|
1100 | + if (empty($attachID)) { |
|
1101 | + return array(); |
|
1102 | + } |
|
1038 | 1103 | |
1039 | 1104 | $request = $smcFunc['db_query']('', ' |
1040 | 1105 | SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board |
@@ -1047,8 +1112,9 @@ discard block |
||
1047 | 1112 | ) |
1048 | 1113 | ); |
1049 | 1114 | |
1050 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1051 | - return array(); |
|
1115 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1116 | + return array(); |
|
1117 | + } |
|
1052 | 1118 | |
1053 | 1119 | $row = $smcFunc['db_fetch_assoc']($request); |
1054 | 1120 | $smcFunc['db_free_result']($request); |
@@ -1089,8 +1155,9 @@ discard block |
||
1089 | 1155 | $temp = array(); |
1090 | 1156 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1091 | 1157 | { |
1092 | - if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) |
|
1093 | - continue; |
|
1158 | + if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) { |
|
1159 | + continue; |
|
1160 | + } |
|
1094 | 1161 | |
1095 | 1162 | $temp[$row['id_attach']] = $row; |
1096 | 1163 | } |
@@ -1119,8 +1186,9 @@ discard block |
||
1119 | 1186 | { |
1120 | 1187 | global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc; |
1121 | 1188 | |
1122 | - if (empty($attachments) || empty($attachments[$id_msg])) |
|
1123 | - return array(); |
|
1189 | + if (empty($attachments) || empty($attachments[$id_msg])) { |
|
1190 | + return array(); |
|
1191 | + } |
|
1124 | 1192 | |
1125 | 1193 | // Set up the attachment info - based on code by Meriadoc. |
1126 | 1194 | $attachmentData = array(); |
@@ -1144,11 +1212,13 @@ discard block |
||
1144 | 1212 | ); |
1145 | 1213 | |
1146 | 1214 | // If something is unapproved we'll note it so we can sort them. |
1147 | - if (!$attachment['approved']) |
|
1148 | - $have_unapproved = true; |
|
1215 | + if (!$attachment['approved']) { |
|
1216 | + $have_unapproved = true; |
|
1217 | + } |
|
1149 | 1218 | |
1150 | - if (!$attachmentData[$i]['is_image']) |
|
1151 | - continue; |
|
1219 | + if (!$attachmentData[$i]['is_image']) { |
|
1220 | + continue; |
|
1221 | + } |
|
1152 | 1222 | |
1153 | 1223 | $attachmentData[$i]['real_width'] = $attachment['width']; |
1154 | 1224 | $attachmentData[$i]['width'] = $attachment['width']; |
@@ -1169,12 +1239,12 @@ discard block |
||
1169 | 1239 | // So what folder are we putting this image in? |
1170 | 1240 | if (!empty($modSettings['currentAttachmentUploadDir'])) |
1171 | 1241 | { |
1172 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
1173 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
1242 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
1243 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
1244 | + } |
|
1174 | 1245 | $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
1175 | 1246 | $id_folder_thumb = $modSettings['currentAttachmentUploadDir']; |
1176 | - } |
|
1177 | - else |
|
1247 | + } else |
|
1178 | 1248 | { |
1179 | 1249 | $path = $modSettings['attachmentUploadDir']; |
1180 | 1250 | $id_folder_thumb = 1; |
@@ -1189,10 +1259,11 @@ discard block |
||
1189 | 1259 | $thumb_ext = isset($context['validImageTypes'][$size[2]]) ? $context['validImageTypes'][$size[2]] : ''; |
1190 | 1260 | |
1191 | 1261 | // Figure out the mime type. |
1192 | - if (!empty($size['mime'])) |
|
1193 | - $thumb_mime = $size['mime']; |
|
1194 | - else |
|
1195 | - $thumb_mime = 'image/' . $thumb_ext; |
|
1262 | + if (!empty($size['mime'])) { |
|
1263 | + $thumb_mime = $size['mime']; |
|
1264 | + } else { |
|
1265 | + $thumb_mime = 'image/' . $thumb_ext; |
|
1266 | + } |
|
1196 | 1267 | |
1197 | 1268 | $thumb_filename = $attachment['filename'] . '_thumb'; |
1198 | 1269 | $thumb_hash = getAttachmentFilename($thumb_filename, false, null, true); |
@@ -1239,11 +1310,12 @@ discard block |
||
1239 | 1310 | } |
1240 | 1311 | } |
1241 | 1312 | |
1242 | - if (!empty($attachment['id_thumb'])) |
|
1243 | - $attachmentData[$i]['thumbnail'] = array( |
|
1313 | + if (!empty($attachment['id_thumb'])) { |
|
1314 | + $attachmentData[$i]['thumbnail'] = array( |
|
1244 | 1315 | 'id' => $attachment['id_thumb'], |
1245 | 1316 | 'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image', |
1246 | 1317 | ); |
1318 | + } |
|
1247 | 1319 | $attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']); |
1248 | 1320 | |
1249 | 1321 | // If thumbnails are disabled, check the maximum size of the image. |
@@ -1253,30 +1325,31 @@ discard block |
||
1253 | 1325 | { |
1254 | 1326 | $attachmentData[$i]['width'] = $modSettings['max_image_width']; |
1255 | 1327 | $attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']); |
1256 | - } |
|
1257 | - elseif (!empty($modSettings['max_image_width'])) |
|
1328 | + } elseif (!empty($modSettings['max_image_width'])) |
|
1258 | 1329 | { |
1259 | 1330 | $attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']); |
1260 | 1331 | $attachmentData[$i]['height'] = $modSettings['max_image_height']; |
1261 | 1332 | } |
1262 | - } |
|
1263 | - elseif ($attachmentData[$i]['thumbnail']['has_thumb']) |
|
1333 | + } elseif ($attachmentData[$i]['thumbnail']['has_thumb']) |
|
1264 | 1334 | { |
1265 | 1335 | // If the image is too large to show inline, make it a popup. |
1266 | - 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']))) |
|
1267 | - $attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);'; |
|
1268 | - else |
|
1269 | - $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');'; |
|
1336 | + 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']))) { |
|
1337 | + $attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);'; |
|
1338 | + } else { |
|
1339 | + $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');'; |
|
1340 | + } |
|
1270 | 1341 | } |
1271 | 1342 | |
1272 | - if (!$attachmentData[$i]['thumbnail']['has_thumb']) |
|
1273 | - $attachmentData[$i]['downloads']++; |
|
1343 | + if (!$attachmentData[$i]['thumbnail']['has_thumb']) { |
|
1344 | + $attachmentData[$i]['downloads']++; |
|
1345 | + } |
|
1274 | 1346 | } |
1275 | 1347 | } |
1276 | 1348 | |
1277 | 1349 | // Do we need to instigate a sort? |
1278 | - if ($have_unapproved) |
|
1279 | - usort($attachmentData, 'approved_attach_sort'); |
|
1350 | + if ($have_unapproved) { |
|
1351 | + usort($attachmentData, 'approved_attach_sort'); |
|
1352 | + } |
|
1280 | 1353 | |
1281 | 1354 | return $attachmentData; |
1282 | 1355 | } |