@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 4 |
12 | 12 | */ |
13 | 13 | |
14 | -if (!defined('SMF')) |
|
14 | +if (!defined('SMF')) { |
|
15 | 15 | die('No direct access...'); |
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * Used for the "custom search index" option |
@@ -54,8 +55,9 @@ discard block |
||
54 | 55 | return; |
55 | 56 | } |
56 | 57 | |
57 | - if (empty($modSettings['search_custom_index_config'])) |
|
58 | - return; |
|
58 | + if (empty($modSettings['search_custom_index_config'])) { |
|
59 | + return; |
|
60 | + } |
|
59 | 61 | |
60 | 62 | $this->indexSettings = $smcFunc['json_decode']($modSettings['search_custom_index_config'], true); |
61 | 63 | |
@@ -117,21 +119,23 @@ discard block |
||
117 | 119 | |
118 | 120 | $subwords = text2words($word, $this->min_word_length, true); |
119 | 121 | |
120 | - if (empty($modSettings['search_force_index'])) |
|
121 | - $wordsSearch['words'][] = $word; |
|
122 | + if (empty($modSettings['search_force_index'])) { |
|
123 | + $wordsSearch['words'][] = $word; |
|
124 | + } |
|
122 | 125 | |
123 | 126 | // Excluded phrases don't benefit from being split into subwords. |
124 | - if (count($subwords) > 1 && $isExcluded) |
|
125 | - return; |
|
126 | - else |
|
127 | + if (count($subwords) > 1 && $isExcluded) { |
|
128 | + return; |
|
129 | + } else |
|
127 | 130 | { |
128 | 131 | foreach ($subwords as $subword) |
129 | 132 | { |
130 | 133 | if ($smcFunc['strlen']($subword) >= $this->min_word_length && !in_array($subword, $this->bannedWords)) |
131 | 134 | { |
132 | 135 | $wordsSearch['indexed_words'][] = $subword; |
133 | - if ($isExcluded) |
|
134 | - $wordsExclude[] = $subword; |
|
136 | + if ($isExcluded) { |
|
137 | + $wordsExclude[] = $subword; |
|
138 | + } |
|
135 | 139 | } |
136 | 140 | } |
137 | 141 | } |
@@ -152,8 +156,9 @@ discard block |
||
152 | 156 | $query_where = array(); |
153 | 157 | $query_params = $search_data['params']; |
154 | 158 | |
155 | - if ($query_params['id_search']) |
|
156 | - $query_select['id_search'] = '{int:id_search}'; |
|
159 | + if ($query_params['id_search']) { |
|
160 | + $query_select['id_search'] = '{int:id_search}'; |
|
161 | + } |
|
157 | 162 | |
158 | 163 | $count = 0; |
159 | 164 | foreach ($words['words'] as $regularWord) |
@@ -162,30 +167,37 @@ discard block |
||
162 | 167 | $query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
163 | 168 | } |
164 | 169 | |
165 | - if ($query_params['user_query']) |
|
166 | - $query_where[] = '{raw:user_query}'; |
|
167 | - if ($query_params['board_query']) |
|
168 | - $query_where[] = 'm.id_board {raw:board_query}'; |
|
170 | + if ($query_params['user_query']) { |
|
171 | + $query_where[] = '{raw:user_query}'; |
|
172 | + } |
|
173 | + if ($query_params['board_query']) { |
|
174 | + $query_where[] = 'm.id_board {raw:board_query}'; |
|
175 | + } |
|
169 | 176 | |
170 | - if ($query_params['topic']) |
|
171 | - $query_where[] = 'm.id_topic = {int:topic}'; |
|
172 | - if ($query_params['min_msg_id']) |
|
173 | - $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
174 | - if ($query_params['max_msg_id']) |
|
175 | - $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
177 | + if ($query_params['topic']) { |
|
178 | + $query_where[] = 'm.id_topic = {int:topic}'; |
|
179 | + } |
|
180 | + if ($query_params['min_msg_id']) { |
|
181 | + $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
182 | + } |
|
183 | + if ($query_params['max_msg_id']) { |
|
184 | + $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
185 | + } |
|
176 | 186 | |
177 | 187 | $count = 0; |
178 | - if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) |
|
179 | - foreach ($query_params['excluded_phrases'] as $phrase) |
|
188 | + if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) { |
|
189 | + foreach ($query_params['excluded_phrases'] as $phrase) |
|
180 | 190 | { |
181 | 191 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_phrase_' . $count . '}'; |
192 | + } |
|
182 | 193 | $query_params['exclude_subject_phrase_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($phrase, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $phrase), '\\\'') . '[[:>:]]'; |
183 | 194 | } |
184 | 195 | $count = 0; |
185 | - if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) |
|
186 | - foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
196 | + if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) { |
|
197 | + foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
187 | 198 | { |
188 | 199 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_words_' . $count . '}'; |
200 | + } |
|
189 | 201 | $query_params['exclude_subject_words_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($excludedWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $excludedWord), '\\\'') . '[[:>:]]'; |
190 | 202 | } |
191 | 203 | |
@@ -198,8 +210,7 @@ discard block |
||
198 | 210 | { |
199 | 211 | $query_left_join[] = '{db_prefix}log_search_words AS lsw' . $numTables . ' ON (lsw' . $numTables . '.id_word = ' . $indexedWord . ' AND lsw' . $numTables . '.id_msg = m.id_msg)'; |
200 | 212 | $query_where[] = '(lsw' . $numTables . '.id_word IS NULL)'; |
201 | - } |
|
202 | - else |
|
213 | + } else |
|
203 | 214 | { |
204 | 215 | $query_inner_join[] = '{db_prefix}log_search_words AS lsw' . $numTables . ' ON (lsw' . $numTables . '.id_msg = ' . ($prev_join === 0 ? 'm' : 'lsw' . $prev_join) . '.id_msg)'; |
205 | 216 | $query_where[] = 'lsw' . $numTables . '.id_word = ' . $indexedWord; |
@@ -235,16 +246,18 @@ discard block |
||
235 | 246 | $customIndexSettings = $smcFunc['json_decode']($modSettings['search_custom_index_config'], true); |
236 | 247 | |
237 | 248 | $inserts = array(); |
238 | - foreach (text2words($msgOptions['body'], $customIndexSettings['bytes_per_word'], true) as $word) |
|
239 | - $inserts[] = array($word, $msgOptions['id']); |
|
249 | + foreach (text2words($msgOptions['body'], $customIndexSettings['bytes_per_word'], true) as $word) { |
|
250 | + $inserts[] = array($word, $msgOptions['id']); |
|
251 | + } |
|
240 | 252 | |
241 | - if (!empty($inserts)) |
|
242 | - $smcFunc['db_insert']('ignore', |
|
253 | + if (!empty($inserts)) { |
|
254 | + $smcFunc['db_insert']('ignore', |
|
243 | 255 | '{db_prefix}log_search_words', |
244 | 256 | array('id_word' => 'int', 'id_msg' => 'int'), |
245 | 257 | $inserts, |
246 | 258 | array('id_word', 'id_msg') |
247 | 259 | ); |
260 | + } |
|
248 | 261 | } |
249 | 262 | |
250 | 263 | /** |
@@ -287,8 +300,9 @@ discard block |
||
287 | 300 | if (!empty($inserted_words)) |
288 | 301 | { |
289 | 302 | $inserts = array(); |
290 | - foreach ($inserted_words as $word) |
|
291 | - $inserts[] = array($word, $msgOptions['id']); |
|
303 | + foreach ($inserted_words as $word) { |
|
304 | + $inserts[] = array($word, $msgOptions['id']); |
|
305 | + } |
|
292 | 306 | $smcFunc['db_insert']('insert', |
293 | 307 | '{db_prefix}log_search_words', |
294 | 308 | array('id_word' => 'string', 'id_msg' => 'int'), |
@@ -30,8 +30,9 @@ discard block |
||
30 | 30 | * @version 2.1 Beta 4 |
31 | 31 | */ |
32 | 32 | |
33 | -if (!defined('SMF')) |
|
33 | +if (!defined('SMF')) { |
|
34 | 34 | die('No direct access...'); |
35 | +} |
|
35 | 36 | |
36 | 37 | /** |
37 | 38 | * Subaction handler - manages the action and delegates control to the proper |
@@ -103,12 +104,12 @@ discard block |
||
103 | 104 | cache_put_data('minimized_css', null); |
104 | 105 | |
105 | 106 | // Follow the sa or just go to administration. |
106 | - if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']])) |
|
107 | - call_helper($subActions[$_GET['sa']]); |
|
108 | - |
|
109 | - else |
|
110 | - call_helper($subActions['admin']); |
|
111 | -} |
|
107 | + if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']])) { |
|
108 | + call_helper($subActions[$_GET['sa']]); |
|
109 | + } else { |
|
110 | + call_helper($subActions['admin']); |
|
111 | + } |
|
112 | + } |
|
112 | 113 | |
113 | 114 | /** |
114 | 115 | * This function allows administration of themes and their settings, |
@@ -130,15 +131,16 @@ discard block |
||
130 | 131 | checkSession(); |
131 | 132 | validateToken('admin-tm'); |
132 | 133 | |
133 | - if (isset($_POST['options']['known_themes'])) |
|
134 | - foreach ($_POST['options']['known_themes'] as $key => $id) |
|
134 | + if (isset($_POST['options']['known_themes'])) { |
|
135 | + foreach ($_POST['options']['known_themes'] as $key => $id) |
|
135 | 136 | $_POST['options']['known_themes'][$key] = (int) $id; |
137 | + } else { |
|
138 | + fatal_lang_error('themes_none_selectable', false); |
|
139 | + } |
|
136 | 140 | |
137 | - else |
|
138 | - fatal_lang_error('themes_none_selectable', false); |
|
139 | - |
|
140 | - if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes'])) |
|
141 | - fatal_lang_error('themes_default_selectable', false); |
|
141 | + if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes'])) { |
|
142 | + fatal_lang_error('themes_default_selectable', false); |
|
143 | + } |
|
142 | 144 | |
143 | 145 | // Commit the new settings. |
144 | 146 | updateSettings(array( |
@@ -146,8 +148,9 @@ discard block |
||
146 | 148 | 'theme_guests' => $_POST['options']['theme_guests'], |
147 | 149 | 'knownThemes' => implode(',', $_POST['options']['known_themes']), |
148 | 150 | )); |
149 | - if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes'])) |
|
150 | - updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset'])); |
|
151 | + if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes'])) { |
|
152 | + updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset'])); |
|
153 | + } |
|
151 | 154 | |
152 | 155 | redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=admin'); |
153 | 156 | } |
@@ -166,8 +169,9 @@ discard block |
||
166 | 169 | // Look for a non existent theme directory. (ie theme87.) |
167 | 170 | $theme_dir = $boarddir . '/Themes/theme'; |
168 | 171 | $i = 1; |
169 | - while (file_exists($theme_dir . $i)) |
|
170 | - $i++; |
|
172 | + while (file_exists($theme_dir . $i)) { |
|
173 | + $i++; |
|
174 | + } |
|
171 | 175 | |
172 | 176 | $context['new_theme_name'] = 'theme' . $i; |
173 | 177 | |
@@ -189,8 +193,9 @@ discard block |
||
189 | 193 | loadLanguage('Admin'); |
190 | 194 | isAllowedTo('admin_forum'); |
191 | 195 | |
192 | - if (isset($_REQUEST['th'])) |
|
193 | - return SetThemeSettings(); |
|
196 | + if (isset($_REQUEST['th'])) { |
|
197 | + return SetThemeSettings(); |
|
198 | + } |
|
194 | 199 | |
195 | 200 | if (isset($_POST['save'])) |
196 | 201 | { |
@@ -274,12 +279,13 @@ discard block |
||
274 | 279 | $context['themes'] = array(); |
275 | 280 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
276 | 281 | { |
277 | - if (!isset($context['themes'][$row['id_theme']])) |
|
278 | - $context['themes'][$row['id_theme']] = array( |
|
282 | + if (!isset($context['themes'][$row['id_theme']])) { |
|
283 | + $context['themes'][$row['id_theme']] = array( |
|
279 | 284 | 'id' => $row['id_theme'], |
280 | 285 | 'num_default_options' => 0, |
281 | 286 | 'num_members' => 0, |
282 | 287 | ); |
288 | + } |
|
283 | 289 | $context['themes'][$row['id_theme']][$row['variable']] = $row['value']; |
284 | 290 | } |
285 | 291 | $smcFunc['db_free_result']($request); |
@@ -293,8 +299,9 @@ discard block |
||
293 | 299 | 'guest_member' => -1, |
294 | 300 | ) |
295 | 301 | ); |
296 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
297 | - $context['themes'][$row['id_theme']]['num_default_options'] = $row['value']; |
|
302 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
303 | + $context['themes'][$row['id_theme']]['num_default_options'] = $row['value']; |
|
304 | + } |
|
298 | 305 | $smcFunc['db_free_result']($request); |
299 | 306 | |
300 | 307 | // Need to make sure we don't do custom fields. |
@@ -305,8 +312,9 @@ discard block |
||
305 | 312 | ) |
306 | 313 | ); |
307 | 314 | $customFields = array(); |
308 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
309 | - $customFields[] = $row['col_name']; |
|
315 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
316 | + $customFields[] = $row['col_name']; |
|
317 | + } |
|
310 | 318 | $smcFunc['db_free_result']($request); |
311 | 319 | $customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})'); |
312 | 320 | |
@@ -321,14 +329,16 @@ discard block |
||
321 | 329 | 'custom_fields' => empty($customFields) ? array() : $customFields, |
322 | 330 | ) |
323 | 331 | ); |
324 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
325 | - $context['themes'][$row['id_theme']]['num_members'] = $row['value']; |
|
332 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
333 | + $context['themes'][$row['id_theme']]['num_members'] = $row['value']; |
|
334 | + } |
|
326 | 335 | $smcFunc['db_free_result']($request); |
327 | 336 | |
328 | 337 | // There has to be a Settings template! |
329 | - foreach ($context['themes'] as $k => $v) |
|
330 | - if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members']))) |
|
338 | + foreach ($context['themes'] as $k => $v) { |
|
339 | + if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members']))) |
|
331 | 340 | unset($context['themes'][$k]); |
341 | + } |
|
332 | 342 | |
333 | 343 | loadTemplate('Themes'); |
334 | 344 | $context['sub_template'] = 'reset_list'; |
@@ -343,16 +353,19 @@ discard block |
||
343 | 353 | checkSession(); |
344 | 354 | validateToken('admin-sto'); |
345 | 355 | |
346 | - if (empty($_POST['options'])) |
|
347 | - $_POST['options'] = array(); |
|
348 | - if (empty($_POST['default_options'])) |
|
349 | - $_POST['default_options'] = array(); |
|
356 | + if (empty($_POST['options'])) { |
|
357 | + $_POST['options'] = array(); |
|
358 | + } |
|
359 | + if (empty($_POST['default_options'])) { |
|
360 | + $_POST['default_options'] = array(); |
|
361 | + } |
|
350 | 362 | |
351 | 363 | // Set up the sql query. |
352 | 364 | $setValues = array(); |
353 | 365 | |
354 | - foreach ($_POST['options'] as $opt => $val) |
|
355 | - $setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val); |
|
366 | + foreach ($_POST['options'] as $opt => $val) { |
|
367 | + $setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val); |
|
368 | + } |
|
356 | 369 | |
357 | 370 | $old_settings = array(); |
358 | 371 | foreach ($_POST['default_options'] as $opt => $val) |
@@ -366,8 +379,8 @@ discard block |
||
366 | 379 | if (!empty($setValues)) |
367 | 380 | { |
368 | 381 | // Are there options in non-default themes set that should be cleared? |
369 | - if (!empty($old_settings)) |
|
370 | - $smcFunc['db_query']('', ' |
|
382 | + if (!empty($old_settings)) { |
|
383 | + $smcFunc['db_query']('', ' |
|
371 | 384 | DELETE FROM {db_prefix}themes |
372 | 385 | WHERE id_theme != {int:default_theme} |
373 | 386 | AND id_member = {int:guest_member} |
@@ -378,6 +391,7 @@ discard block |
||
378 | 391 | 'old_settings' => $old_settings, |
379 | 392 | ) |
380 | 393 | ); |
394 | + } |
|
381 | 395 | |
382 | 396 | $smcFunc['db_insert']('replace', |
383 | 397 | '{db_prefix}themes', |
@@ -391,8 +405,7 @@ discard block |
||
391 | 405 | cache_put_data('theme_settings-1', null, 90); |
392 | 406 | |
393 | 407 | redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset'); |
394 | - } |
|
395 | - elseif (isset($_POST['submit']) && $_POST['who'] == 1) |
|
408 | + } elseif (isset($_POST['submit']) && $_POST['who'] == 1) |
|
396 | 409 | { |
397 | 410 | checkSession(); |
398 | 411 | validateToken('admin-sto'); |
@@ -405,9 +418,9 @@ discard block |
||
405 | 418 | $old_settings = array(); |
406 | 419 | foreach ($_POST['default_options'] as $opt => $val) |
407 | 420 | { |
408 | - if ($_POST['default_options_master'][$opt] == 0) |
|
409 | - continue; |
|
410 | - elseif ($_POST['default_options_master'][$opt] == 1) |
|
421 | + if ($_POST['default_options_master'][$opt] == 0) { |
|
422 | + continue; |
|
423 | + } elseif ($_POST['default_options_master'][$opt] == 1) |
|
411 | 424 | { |
412 | 425 | // Delete then insert for ease of database compatibility! |
413 | 426 | $smcFunc['db_query']('substring', ' |
@@ -433,8 +446,7 @@ discard block |
||
433 | 446 | ); |
434 | 447 | |
435 | 448 | $old_settings[] = $opt; |
436 | - } |
|
437 | - elseif ($_POST['default_options_master'][$opt] == 2) |
|
449 | + } elseif ($_POST['default_options_master'][$opt] == 2) |
|
438 | 450 | { |
439 | 451 | $smcFunc['db_query']('', ' |
440 | 452 | DELETE FROM {db_prefix}themes |
@@ -449,8 +461,8 @@ discard block |
||
449 | 461 | } |
450 | 462 | |
451 | 463 | // Delete options from other themes. |
452 | - if (!empty($old_settings)) |
|
453 | - $smcFunc['db_query']('', ' |
|
464 | + if (!empty($old_settings)) { |
|
465 | + $smcFunc['db_query']('', ' |
|
454 | 466 | DELETE FROM {db_prefix}themes |
455 | 467 | WHERE id_theme != {int:default_theme} |
456 | 468 | AND id_member > {int:no_member} |
@@ -461,12 +473,13 @@ discard block |
||
461 | 473 | 'old_settings' => $old_settings, |
462 | 474 | ) |
463 | 475 | ); |
476 | + } |
|
464 | 477 | |
465 | 478 | foreach ($_POST['options'] as $opt => $val) |
466 | 479 | { |
467 | - if ($_POST['options_master'][$opt] == 0) |
|
468 | - continue; |
|
469 | - elseif ($_POST['options_master'][$opt] == 1) |
|
480 | + if ($_POST['options_master'][$opt] == 0) { |
|
481 | + continue; |
|
482 | + } elseif ($_POST['options_master'][$opt] == 1) |
|
470 | 483 | { |
471 | 484 | // Delete then insert for ease of database compatibility - again! |
472 | 485 | $smcFunc['db_query']('substring', ' |
@@ -491,8 +504,7 @@ discard block |
||
491 | 504 | 'value' => (is_array($val) ? implode(',', $val) : $val), |
492 | 505 | ) |
493 | 506 | ); |
494 | - } |
|
495 | - elseif ($_POST['options_master'][$opt] == 2) |
|
507 | + } elseif ($_POST['options_master'][$opt] == 2) |
|
496 | 508 | { |
497 | 509 | $smcFunc['db_query']('', ' |
498 | 510 | DELETE FROM {db_prefix}themes |
@@ -509,8 +521,7 @@ discard block |
||
509 | 521 | } |
510 | 522 | |
511 | 523 | redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset'); |
512 | - } |
|
513 | - elseif (!empty($_GET['who']) && $_GET['who'] == 2) |
|
524 | + } elseif (!empty($_GET['who']) && $_GET['who'] == 2) |
|
514 | 525 | { |
515 | 526 | checkSession('get'); |
516 | 527 | validateToken('admin-stor', 'request'); |
@@ -525,8 +536,9 @@ discard block |
||
525 | 536 | ) |
526 | 537 | ); |
527 | 538 | $customFields = array(); |
528 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
529 | - $customFields[] = $row['col_name']; |
|
539 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
540 | + $customFields[] = $row['col_name']; |
|
541 | + } |
|
530 | 542 | $smcFunc['db_free_result']($request); |
531 | 543 | } |
532 | 544 | $customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})'); |
@@ -578,13 +590,13 @@ discard block |
||
578 | 590 | ) |
579 | 591 | ); |
580 | 592 | $context['theme_options'] = array(); |
581 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
582 | - $context['theme_options'][$row['variable']] = $row['value']; |
|
593 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
594 | + $context['theme_options'][$row['variable']] = $row['value']; |
|
595 | + } |
|
583 | 596 | $smcFunc['db_free_result']($request); |
584 | 597 | |
585 | 598 | $context['theme_options_reset'] = false; |
586 | - } |
|
587 | - else |
|
599 | + } else |
|
588 | 600 | { |
589 | 601 | $context['theme_options'] = array(); |
590 | 602 | $context['theme_options_reset'] = true; |
@@ -593,30 +605,32 @@ discard block |
||
593 | 605 | foreach ($context['options'] as $i => $setting) |
594 | 606 | { |
595 | 607 | // Just skip separators |
596 | - if (!is_array($setting)) |
|
597 | - continue; |
|
608 | + if (!is_array($setting)) { |
|
609 | + continue; |
|
610 | + } |
|
598 | 611 | |
599 | 612 | // Is this disabled? |
600 | 613 | if ($setting['id'] == 'calendar_start_day' && empty($modSettings['cal_enabled'])) |
601 | 614 | { |
602 | 615 | unset($context['options'][$i]); |
603 | 616 | continue; |
604 | - } |
|
605 | - elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage'])) |
|
617 | + } elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage'])) |
|
606 | 618 | { |
607 | 619 | unset($context['options'][$i]); |
608 | 620 | continue; |
609 | 621 | } |
610 | 622 | |
611 | - if (!isset($setting['type']) || $setting['type'] == 'bool') |
|
612 | - $context['options'][$i]['type'] = 'checkbox'; |
|
613 | - elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') |
|
614 | - $context['options'][$i]['type'] = 'number'; |
|
615 | - elseif ($setting['type'] == 'string') |
|
616 | - $context['options'][$i]['type'] = 'text'; |
|
623 | + if (!isset($setting['type']) || $setting['type'] == 'bool') { |
|
624 | + $context['options'][$i]['type'] = 'checkbox'; |
|
625 | + } elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') { |
|
626 | + $context['options'][$i]['type'] = 'number'; |
|
627 | + } elseif ($setting['type'] == 'string') { |
|
628 | + $context['options'][$i]['type'] = 'text'; |
|
629 | + } |
|
617 | 630 | |
618 | - if (isset($setting['options'])) |
|
619 | - $context['options'][$i]['type'] = 'list'; |
|
631 | + if (isset($setting['options'])) { |
|
632 | + $context['options'][$i]['type'] = 'list'; |
|
633 | + } |
|
620 | 634 | |
621 | 635 | $context['options'][$i]['value'] = !isset($context['theme_options'][$setting['id']]) ? '' : $context['theme_options'][$setting['id']]; |
622 | 636 | } |
@@ -641,8 +655,9 @@ discard block |
||
641 | 655 | { |
642 | 656 | global $txt, $context, $settings, $modSettings, $smcFunc; |
643 | 657 | |
644 | - if (empty($_GET['th']) && empty($_GET['id'])) |
|
645 | - return ThemeAdmin(); |
|
658 | + if (empty($_GET['th']) && empty($_GET['id'])) { |
|
659 | + return ThemeAdmin(); |
|
660 | + } |
|
646 | 661 | |
647 | 662 | $_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id']; |
648 | 663 | |
@@ -653,8 +668,9 @@ discard block |
||
653 | 668 | isAllowedTo('admin_forum'); |
654 | 669 | |
655 | 670 | // Validate inputs/user. |
656 | - if (empty($_GET['th'])) |
|
657 | - fatal_lang_error('no_theme', false); |
|
671 | + if (empty($_GET['th'])) { |
|
672 | + fatal_lang_error('no_theme', false); |
|
673 | + } |
|
658 | 674 | |
659 | 675 | // Fetch the smiley sets... |
660 | 676 | $sets = explode(',', 'none,' . $modSettings['smiley_sets_known']); |
@@ -662,8 +678,9 @@ discard block |
||
662 | 678 | $context['smiley_sets'] = array( |
663 | 679 | '' => $txt['smileys_no_default'] |
664 | 680 | ); |
665 | - foreach ($sets as $i => $set) |
|
666 | - $context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]); |
|
681 | + foreach ($sets as $i => $set) { |
|
682 | + $context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]); |
|
683 | + } |
|
667 | 684 | |
668 | 685 | $old_id = $settings['theme_id']; |
669 | 686 | $old_settings = $settings; |
@@ -688,8 +705,9 @@ discard block |
||
688 | 705 | if (file_exists($settings['theme_dir'] . '/index.template.php')) |
689 | 706 | { |
690 | 707 | $file_contents = implode('', file($settings['theme_dir'] . '/index.template.php')); |
691 | - if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches)) |
|
692 | - eval('global $settings;' . $matches[0]); |
|
708 | + if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches)) { |
|
709 | + eval('global $settings;' . $matches[0]); |
|
710 | + } |
|
693 | 711 | } |
694 | 712 | |
695 | 713 | // Submitting! |
@@ -698,37 +716,45 @@ discard block |
||
698 | 716 | checkSession(); |
699 | 717 | validateToken('admin-sts'); |
700 | 718 | |
701 | - if (empty($_POST['options'])) |
|
702 | - $_POST['options'] = array(); |
|
703 | - if (empty($_POST['default_options'])) |
|
704 | - $_POST['default_options'] = array(); |
|
719 | + if (empty($_POST['options'])) { |
|
720 | + $_POST['options'] = array(); |
|
721 | + } |
|
722 | + if (empty($_POST['default_options'])) { |
|
723 | + $_POST['default_options'] = array(); |
|
724 | + } |
|
705 | 725 | |
706 | 726 | // Make sure items are cast correctly. |
707 | 727 | foreach ($context['theme_settings'] as $item) |
708 | 728 | { |
709 | 729 | // Disregard this item if this is just a separator. |
710 | - if (!is_array($item)) |
|
711 | - continue; |
|
730 | + if (!is_array($item)) { |
|
731 | + continue; |
|
732 | + } |
|
712 | 733 | |
713 | 734 | foreach (array('options', 'default_options') as $option) |
714 | 735 | { |
715 | - if (!isset($_POST[$option][$item['id']])) |
|
716 | - continue; |
|
736 | + if (!isset($_POST[$option][$item['id']])) { |
|
737 | + continue; |
|
738 | + } |
|
717 | 739 | // Checkbox. |
718 | - elseif (empty($item['type'])) |
|
719 | - $_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0; |
|
740 | + elseif (empty($item['type'])) { |
|
741 | + $_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0; |
|
742 | + } |
|
720 | 743 | // Number |
721 | - elseif ($item['type'] == 'number') |
|
722 | - $_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']]; |
|
744 | + elseif ($item['type'] == 'number') { |
|
745 | + $_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']]; |
|
746 | + } |
|
723 | 747 | } |
724 | 748 | } |
725 | 749 | |
726 | 750 | // Set up the sql query. |
727 | 751 | $inserts = array(); |
728 | - foreach ($_POST['options'] as $opt => $val) |
|
729 | - $inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val); |
|
730 | - foreach ($_POST['default_options'] as $opt => $val) |
|
731 | - $inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val); |
|
752 | + foreach ($_POST['options'] as $opt => $val) { |
|
753 | + $inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val); |
|
754 | + } |
|
755 | + foreach ($_POST['default_options'] as $opt => $val) { |
|
756 | + $inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val); |
|
757 | + } |
|
732 | 758 | // If we're actually inserting something.. |
733 | 759 | if (!empty($inserts)) |
734 | 760 | { |
@@ -754,8 +780,9 @@ discard block |
||
754 | 780 | |
755 | 781 | foreach ($settings as $setting => $dummy) |
756 | 782 | { |
757 | - if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs'))) |
|
758 | - $settings[$setting] = htmlspecialchars__recursive($settings[$setting]); |
|
783 | + if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs'))) { |
|
784 | + $settings[$setting] = htmlspecialchars__recursive($settings[$setting]); |
|
785 | + } |
|
759 | 786 | } |
760 | 787 | |
761 | 788 | $context['settings'] = $context['theme_settings']; |
@@ -764,18 +791,21 @@ discard block |
||
764 | 791 | foreach ($context['settings'] as $i => $setting) |
765 | 792 | { |
766 | 793 | // Separators are dummies, so leave them alone. |
767 | - if (!is_array($setting)) |
|
768 | - continue; |
|
794 | + if (!is_array($setting)) { |
|
795 | + continue; |
|
796 | + } |
|
769 | 797 | |
770 | - if (!isset($setting['type']) || $setting['type'] == 'bool') |
|
771 | - $context['settings'][$i]['type'] = 'checkbox'; |
|
772 | - elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') |
|
773 | - $context['settings'][$i]['type'] = 'number'; |
|
774 | - elseif ($setting['type'] == 'string') |
|
775 | - $context['settings'][$i]['type'] = 'text'; |
|
798 | + if (!isset($setting['type']) || $setting['type'] == 'bool') { |
|
799 | + $context['settings'][$i]['type'] = 'checkbox'; |
|
800 | + } elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') { |
|
801 | + $context['settings'][$i]['type'] = 'number'; |
|
802 | + } elseif ($setting['type'] == 'string') { |
|
803 | + $context['settings'][$i]['type'] = 'text'; |
|
804 | + } |
|
776 | 805 | |
777 | - if (isset($setting['options'])) |
|
778 | - $context['settings'][$i]['type'] = 'list'; |
|
806 | + if (isset($setting['options'])) { |
|
807 | + $context['settings'][$i]['type'] = 'list'; |
|
808 | + } |
|
779 | 809 | |
780 | 810 | $context['settings'][$i]['value'] = !isset($settings[$setting['id']]) ? '' : $settings[$setting['id']]; |
781 | 811 | } |
@@ -828,8 +858,9 @@ discard block |
||
828 | 858 | $themeID = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id']; |
829 | 859 | |
830 | 860 | // You can't delete the default theme! |
831 | - if ($themeID == 1) |
|
832 | - fatal_lang_error('no_access', false); |
|
861 | + if ($themeID == 1) { |
|
862 | + fatal_lang_error('no_access', false); |
|
863 | + } |
|
833 | 864 | |
834 | 865 | $theme_info = get_single_theme($themeID); |
835 | 866 | |
@@ -837,8 +868,9 @@ discard block |
||
837 | 868 | remove_theme($themeID); |
838 | 869 | |
839 | 870 | // And remove all its files and folders too. |
840 | - if (!empty($theme_info) && !empty($theme_info['theme_dir'])) |
|
841 | - remove_dir($theme_info['theme_dir']); |
|
871 | + if (!empty($theme_info) && !empty($theme_info['theme_dir'])) { |
|
872 | + remove_dir($theme_info['theme_dir']); |
|
873 | + } |
|
842 | 874 | |
843 | 875 | // Go back to the list page. |
844 | 876 | redirectexit('action=admin;area=theme;sa=list;' . $context['session_var'] . '=' . $context['session_id'] . ';done=removing'); |
@@ -863,12 +895,14 @@ discard block |
||
863 | 895 | $enableThemes = explode(',', $modSettings['enableThemes']); |
864 | 896 | |
865 | 897 | // Are we disabling it? |
866 | - if (isset($_GET['disabled'])) |
|
867 | - $enableThemes = array_diff($enableThemes, array($themeID)); |
|
898 | + if (isset($_GET['disabled'])) { |
|
899 | + $enableThemes = array_diff($enableThemes, array($themeID)); |
|
900 | + } |
|
868 | 901 | |
869 | 902 | // Nope? then enable it! |
870 | - else |
|
871 | - $enableThemes[] = (string) $themeID; |
|
903 | + else { |
|
904 | + $enableThemes[] = (string) $themeID; |
|
905 | + } |
|
872 | 906 | |
873 | 907 | // Update the setting. |
874 | 908 | $enableThemes = strtr(implode(',', $enableThemes), array(',,' => ',')); |
@@ -903,18 +937,21 @@ discard block |
||
903 | 937 | |
904 | 938 | $_SESSION['id_theme'] = 0; |
905 | 939 | |
906 | - if (isset($_GET['id'])) |
|
907 | - $_GET['th'] = $_GET['id']; |
|
940 | + if (isset($_GET['id'])) { |
|
941 | + $_GET['th'] = $_GET['id']; |
|
942 | + } |
|
908 | 943 | |
909 | 944 | // Saving a variant cause JS doesn't work - pretend it did ;) |
910 | 945 | if (isset($_POST['save'])) |
911 | 946 | { |
912 | 947 | // Which theme? |
913 | - foreach ($_POST['save'] as $k => $v) |
|
914 | - $_GET['th'] = (int) $k; |
|
948 | + foreach ($_POST['save'] as $k => $v) { |
|
949 | + $_GET['th'] = (int) $k; |
|
950 | + } |
|
915 | 951 | |
916 | - if (isset($_POST['vrt'][$k])) |
|
917 | - $_GET['vrt'] = $_POST['vrt'][$k]; |
|
952 | + if (isset($_POST['vrt'][$k])) { |
|
953 | + $_GET['vrt'] = $_POST['vrt'][$k]; |
|
954 | + } |
|
918 | 955 | } |
919 | 956 | |
920 | 957 | // Have we made a decision, or are we just browsing? |
@@ -992,8 +1029,9 @@ discard block |
||
992 | 1029 | else |
993 | 1030 | { |
994 | 1031 | // The forum's default theme is always 0 and we |
995 | - if (isset($_GET['th']) && $_GET['th'] == 0) |
|
996 | - $_GET['th'] = $modSettings['theme_guests']; |
|
1032 | + if (isset($_GET['th']) && $_GET['th'] == 0) { |
|
1033 | + $_GET['th'] = $modSettings['theme_guests']; |
|
1034 | + } |
|
997 | 1035 | |
998 | 1036 | updateMemberData((int) $_REQUEST['u'], array('id_theme' => (int) $_GET['th'])); |
999 | 1037 | |
@@ -1007,8 +1045,9 @@ discard block |
||
1007 | 1045 | ); |
1008 | 1046 | cache_put_data('theme_settings-' . $_GET['th'] . ':' . (int) $_REQUEST['u'], null, 90); |
1009 | 1047 | |
1010 | - if ($user_info['id'] == $_REQUEST['u']) |
|
1011 | - $_SESSION['id_variant'] = 0; |
|
1048 | + if ($user_info['id'] == $_REQUEST['u']) { |
|
1049 | + $_SESSION['id_variant'] = 0; |
|
1050 | + } |
|
1012 | 1051 | } |
1013 | 1052 | |
1014 | 1053 | redirectexit('action=profile;u=' . (int) $_REQUEST['u'] . ';area=theme'); |
@@ -1077,12 +1116,13 @@ discard block |
||
1077 | 1116 | ); |
1078 | 1117 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1079 | 1118 | { |
1080 | - if (!isset($context['available_themes'][$row['id_theme']])) |
|
1081 | - $context['available_themes'][$row['id_theme']] = array( |
|
1119 | + if (!isset($context['available_themes'][$row['id_theme']])) { |
|
1120 | + $context['available_themes'][$row['id_theme']] = array( |
|
1082 | 1121 | 'id' => $row['id_theme'], |
1083 | 1122 | 'selected' => $context['current_theme'] == $row['id_theme'], |
1084 | 1123 | 'num_users' => 0 |
1085 | 1124 | ); |
1125 | + } |
|
1086 | 1126 | $context['available_themes'][$row['id_theme']][$row['variable']] = $row['value']; |
1087 | 1127 | } |
1088 | 1128 | $smcFunc['db_free_result']($request); |
@@ -1095,9 +1135,9 @@ discard block |
||
1095 | 1135 | 'num_users' => 0 |
1096 | 1136 | ); |
1097 | 1137 | $guest_theme = 0; |
1138 | + } else { |
|
1139 | + $guest_theme = $modSettings['theme_guests']; |
|
1098 | 1140 | } |
1099 | - else |
|
1100 | - $guest_theme = $modSettings['theme_guests']; |
|
1101 | 1141 | |
1102 | 1142 | $request = $smcFunc['db_query']('', ' |
1103 | 1143 | SELECT id_theme, COUNT(*) AS the_count |
@@ -1110,15 +1150,17 @@ discard block |
||
1110 | 1150 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1111 | 1151 | { |
1112 | 1152 | // Figure out which theme it is they are REALLY using. |
1113 | - if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes']))) |
|
1114 | - $row['id_theme'] = $guest_theme; |
|
1115 | - elseif (empty($modSettings['theme_allow'])) |
|
1116 | - $row['id_theme'] = $guest_theme; |
|
1153 | + if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes']))) { |
|
1154 | + $row['id_theme'] = $guest_theme; |
|
1155 | + } elseif (empty($modSettings['theme_allow'])) { |
|
1156 | + $row['id_theme'] = $guest_theme; |
|
1157 | + } |
|
1117 | 1158 | |
1118 | - if (isset($context['available_themes'][$row['id_theme']])) |
|
1119 | - $context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count']; |
|
1120 | - else |
|
1121 | - $context['available_themes'][$guest_theme]['num_users'] += $row['the_count']; |
|
1159 | + if (isset($context['available_themes'][$row['id_theme']])) { |
|
1160 | + $context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count']; |
|
1161 | + } else { |
|
1162 | + $context['available_themes'][$guest_theme]['num_users'] += $row['the_count']; |
|
1163 | + } |
|
1122 | 1164 | } |
1123 | 1165 | $smcFunc['db_free_result']($request); |
1124 | 1166 | |
@@ -1137,8 +1179,9 @@ discard block |
||
1137 | 1179 | 'id_member' => isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? array(-1, $context['current_member']) : array(-1), |
1138 | 1180 | ) |
1139 | 1181 | ); |
1140 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1141 | - $variant_preferences[$row['id_theme']] = $row['value']; |
|
1182 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1183 | + $variant_preferences[$row['id_theme']] = $row['value']; |
|
1184 | + } |
|
1142 | 1185 | $smcFunc['db_free_result']($request); |
1143 | 1186 | } |
1144 | 1187 | |
@@ -1149,17 +1192,18 @@ discard block |
||
1149 | 1192 | foreach ($context['available_themes'] as $id_theme => $theme_data) |
1150 | 1193 | { |
1151 | 1194 | // Don't try to load the forum or board default theme's data... it doesn't have any! |
1152 | - if ($id_theme == 0) |
|
1153 | - continue; |
|
1195 | + if ($id_theme == 0) { |
|
1196 | + continue; |
|
1197 | + } |
|
1154 | 1198 | |
1155 | 1199 | // The thumbnail needs the correct path. |
1156 | 1200 | $settings['images_url'] = &$theme_data['images_url']; |
1157 | 1201 | |
1158 | - if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php')) |
|
1159 | - include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php'); |
|
1160 | - elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php')) |
|
1161 | - include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php'); |
|
1162 | - else |
|
1202 | + if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php')) { |
|
1203 | + include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php'); |
|
1204 | + } elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php')) { |
|
1205 | + include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php'); |
|
1206 | + } else |
|
1163 | 1207 | { |
1164 | 1208 | $txt['theme_thumbnail_href'] = $theme_data['images_url'] . '/thumbnail.png'; |
1165 | 1209 | $txt['theme_description'] = ''; |
@@ -1184,15 +1228,17 @@ discard block |
||
1184 | 1228 | loadLanguage('Settings'); |
1185 | 1229 | |
1186 | 1230 | $context['available_themes'][$id_theme]['variants'] = array(); |
1187 | - foreach ($settings['theme_variants'] as $variant) |
|
1188 | - $context['available_themes'][$id_theme]['variants'][$variant] = array( |
|
1231 | + foreach ($settings['theme_variants'] as $variant) { |
|
1232 | + $context['available_themes'][$id_theme]['variants'][$variant] = array( |
|
1189 | 1233 | 'label' => isset($txt['variant_' . $variant]) ? $txt['variant_' . $variant] : $variant, |
1190 | 1234 | 'thumbnail' => !file_exists($theme_data['theme_dir'] . '/images/thumbnail.png') || file_exists($theme_data['theme_dir'] . '/images/thumbnail_' . $variant . '.png') ? $theme_data['images_url'] . '/thumbnail_' . $variant . '.png' : ($theme_data['images_url'] . '/thumbnail.png'), |
1191 | 1235 | ); |
1236 | + } |
|
1192 | 1237 | |
1193 | 1238 | $context['available_themes'][$id_theme]['selected_variant'] = isset($_GET['vrt']) ? $_GET['vrt'] : (!empty($variant_preferences[$id_theme]) ? $variant_preferences[$id_theme] : (!empty($settings['default_variant']) ? $settings['default_variant'] : $settings['theme_variants'][0])); |
1194 | - if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'])) |
|
1195 | - $context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0]; |
|
1239 | + if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'])) { |
|
1240 | + $context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0]; |
|
1241 | + } |
|
1196 | 1242 | |
1197 | 1243 | $context['available_themes'][$id_theme]['thumbnail_href'] = $context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail']; |
1198 | 1244 | // Allow themes to override the text. |
@@ -1208,8 +1254,9 @@ discard block |
||
1208 | 1254 | // As long as we're not doing the default theme... |
1209 | 1255 | if (!isset($_REQUEST['u']) || $_REQUEST['u'] >= 0) |
1210 | 1256 | { |
1211 | - if ($guest_theme != 0) |
|
1212 | - $context['available_themes'][0] = $context['available_themes'][$guest_theme]; |
|
1257 | + if ($guest_theme != 0) { |
|
1258 | + $context['available_themes'][0] = $context['available_themes'][$guest_theme]; |
|
1259 | + } |
|
1213 | 1260 | |
1214 | 1261 | $context['available_themes'][0]['id'] = 0; |
1215 | 1262 | $context['available_themes'][0]['name'] = $txt['theme_forum_default']; |
@@ -1258,14 +1305,16 @@ discard block |
||
1258 | 1305 | $action = $smcFunc['htmlspecialchars'](trim($_GET['do'])); |
1259 | 1306 | |
1260 | 1307 | // Got any info from the specific form? |
1261 | - if (!isset($_POST['save_' . $action])) |
|
1262 | - fatal_lang_error('theme_install_no_action', false); |
|
1308 | + if (!isset($_POST['save_' . $action])) { |
|
1309 | + fatal_lang_error('theme_install_no_action', false); |
|
1310 | + } |
|
1263 | 1311 | |
1264 | 1312 | validateToken('admin-t-' . $action); |
1265 | 1313 | |
1266 | 1314 | // Hopefully the themes directory is writable, or we might have a problem. |
1267 | - if (!is_writable($themedir)) |
|
1268 | - fatal_lang_error('theme_install_write_error', 'critical'); |
|
1315 | + if (!is_writable($themedir)) { |
|
1316 | + fatal_lang_error('theme_install_write_error', 'critical'); |
|
1317 | + } |
|
1269 | 1318 | |
1270 | 1319 | // Call the function and handle the result. |
1271 | 1320 | $result = $subActions[$action](); |
@@ -1280,9 +1329,10 @@ discard block |
||
1280 | 1329 | } |
1281 | 1330 | |
1282 | 1331 | // Nope, show a nice error. |
1283 | - else |
|
1284 | - fatal_lang_error('theme_install_no_action', false); |
|
1285 | -} |
|
1332 | + else { |
|
1333 | + fatal_lang_error('theme_install_no_action', false); |
|
1334 | + } |
|
1335 | + } |
|
1286 | 1336 | |
1287 | 1337 | /** |
1288 | 1338 | * Installs a theme from a theme package. |
@@ -1298,8 +1348,9 @@ discard block |
||
1298 | 1348 | $dirtemp = $themedir . '/temp'; |
1299 | 1349 | |
1300 | 1350 | // Make sure the temp dir doesn't already exist |
1301 | - if (file_exists($dirtemp)) |
|
1302 | - remove_dir($dirtemp); |
|
1351 | + if (file_exists($dirtemp)) { |
|
1352 | + remove_dir($dirtemp); |
|
1353 | + } |
|
1303 | 1354 | |
1304 | 1355 | // Create the temp dir. |
1305 | 1356 | mkdir($dirtemp, 0777); |
@@ -1311,17 +1362,20 @@ discard block |
||
1311 | 1362 | smf_chmod($dirtemp, '0755'); |
1312 | 1363 | |
1313 | 1364 | // How about now? |
1314 | - if (!is_writable($dirtemp)) |
|
1315 | - fatal_lang_error('theme_install_write_error', 'critical'); |
|
1365 | + if (!is_writable($dirtemp)) { |
|
1366 | + fatal_lang_error('theme_install_write_error', 'critical'); |
|
1367 | + } |
|
1316 | 1368 | } |
1317 | 1369 | |
1318 | 1370 | // This happens when the admin session is gone and the user has to login again. |
1319 | - if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz'])) |
|
1320 | - redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']); |
|
1371 | + if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz'])) { |
|
1372 | + redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']); |
|
1373 | + } |
|
1321 | 1374 | |
1322 | 1375 | // Another error check layer, something went wrong with the upload. |
1323 | - if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0) |
|
1324 | - fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false); |
|
1376 | + if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0) { |
|
1377 | + fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false); |
|
1378 | + } |
|
1325 | 1379 | |
1326 | 1380 | // Get the theme's name. |
1327 | 1381 | $name = pathinfo($_FILES['theme_gz']['name'], PATHINFO_FILENAME); |
@@ -1352,11 +1406,10 @@ discard block |
||
1352 | 1406 | |
1353 | 1407 | // return all the info. |
1354 | 1408 | return $context['to_install']; |
1409 | + } else { |
|
1410 | + fatal_lang_error('theme_install_error_title', false); |
|
1411 | + } |
|
1355 | 1412 | } |
1356 | - |
|
1357 | - else |
|
1358 | - fatal_lang_error('theme_install_error_title', false); |
|
1359 | -} |
|
1360 | 1413 | |
1361 | 1414 | /** |
1362 | 1415 | * Makes a copy from the default theme, assigns a name for it and installs it. |
@@ -1370,15 +1423,17 @@ discard block |
||
1370 | 1423 | global $forum_version; |
1371 | 1424 | |
1372 | 1425 | // There's gotta be something to work with. |
1373 | - if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy'])) |
|
1374 | - fatal_lang_error('theme_install_error_title', false); |
|
1426 | + if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy'])) { |
|
1427 | + fatal_lang_error('theme_install_error_title', false); |
|
1428 | + } |
|
1375 | 1429 | |
1376 | 1430 | // Get a cleaner version. |
1377 | 1431 | $name = preg_replace('~[^A-Za-z0-9_\- ]~', '', $_REQUEST['copy']); |
1378 | 1432 | |
1379 | 1433 | // Is there a theme already named like this? |
1380 | - if (file_exists($themedir . '/' . $name)) |
|
1381 | - fatal_lang_error('theme_install_already_dir', false); |
|
1434 | + if (file_exists($themedir . '/' . $name)) { |
|
1435 | + fatal_lang_error('theme_install_already_dir', false); |
|
1436 | + } |
|
1382 | 1437 | |
1383 | 1438 | // This is a brand new theme so set all possible values. |
1384 | 1439 | $context['to_install'] = array( |
@@ -1398,8 +1453,9 @@ discard block |
||
1398 | 1453 | |
1399 | 1454 | // Buy some time. |
1400 | 1455 | @set_time_limit(600); |
1401 | - if (function_exists('apache_reset_timeout')) |
|
1402 | - @apache_reset_timeout(); |
|
1456 | + if (function_exists('apache_reset_timeout')) { |
|
1457 | + @apache_reset_timeout(); |
|
1458 | + } |
|
1403 | 1459 | |
1404 | 1460 | // Create subdirectories for css and javascript files. |
1405 | 1461 | mkdir($context['to_install']['theme_dir'] . '/css', 0777); |
@@ -1435,12 +1491,13 @@ discard block |
||
1435 | 1491 | |
1436 | 1492 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1437 | 1493 | { |
1438 | - if ($row['variable'] == 'theme_templates') |
|
1439 | - $theme_templates = $row['value']; |
|
1440 | - elseif ($row['variable'] == 'theme_layers') |
|
1441 | - $theme_layers = $row['value']; |
|
1442 | - else |
|
1443 | - continue; |
|
1494 | + if ($row['variable'] == 'theme_templates') { |
|
1495 | + $theme_templates = $row['value']; |
|
1496 | + } elseif ($row['variable'] == 'theme_layers') { |
|
1497 | + $theme_layers = $row['value']; |
|
1498 | + } else { |
|
1499 | + continue; |
|
1500 | + } |
|
1444 | 1501 | } |
1445 | 1502 | |
1446 | 1503 | $smcFunc['db_free_result']($request); |
@@ -1499,12 +1556,14 @@ discard block |
||
1499 | 1556 | global $themedir, $themeurl, $context; |
1500 | 1557 | |
1501 | 1558 | // Cannot use the theme dir as a theme dir. |
1502 | - if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir)) |
|
1503 | - fatal_lang_error('theme_install_invalid_dir', false); |
|
1559 | + if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir)) { |
|
1560 | + fatal_lang_error('theme_install_invalid_dir', false); |
|
1561 | + } |
|
1504 | 1562 | |
1505 | 1563 | // Check is there is "something" on the dir. |
1506 | - elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml')) |
|
1507 | - fatal_lang_error('theme_install_error', false); |
|
1564 | + elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml')) { |
|
1565 | + fatal_lang_error('theme_install_error', false); |
|
1566 | + } |
|
1508 | 1567 | |
1509 | 1568 | $name = basename($_REQUEST['theme_dir']); |
1510 | 1569 | $name = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $name); |
@@ -1548,24 +1607,27 @@ discard block |
||
1548 | 1607 | } |
1549 | 1608 | |
1550 | 1609 | // Any special layers? |
1551 | - if (isset($settings['catch_action']['layers'])) |
|
1552 | - $context['template_layers'] = $settings['catch_action']['layers']; |
|
1610 | + if (isset($settings['catch_action']['layers'])) { |
|
1611 | + $context['template_layers'] = $settings['catch_action']['layers']; |
|
1612 | + } |
|
1553 | 1613 | |
1554 | 1614 | // Any function to call? |
1555 | 1615 | if (isset($settings['catch_action']['function'])) |
1556 | 1616 | { |
1557 | 1617 | $hook = $settings['catch_action']['function']; |
1558 | 1618 | |
1559 | - if (!isset($settings['catch_action']['filename'])) |
|
1560 | - $settings['catch_action']['filename'] = ''; |
|
1619 | + if (!isset($settings['catch_action']['filename'])) { |
|
1620 | + $settings['catch_action']['filename'] = ''; |
|
1621 | + } |
|
1561 | 1622 | |
1562 | 1623 | add_integration_function('integrate_wrap_action', $hook, false, $settings['catch_action']['filename'], false); |
1563 | 1624 | call_integration_hook('integrate_wrap_action'); |
1564 | 1625 | } |
1565 | 1626 | // And finally, the main sub template ;). |
1566 | - if (isset($settings['catch_action']['sub_template'])) |
|
1567 | - $context['sub_template'] = $settings['catch_action']['sub_template']; |
|
1568 | -} |
|
1627 | + if (isset($settings['catch_action']['sub_template'])) { |
|
1628 | + $context['sub_template'] = $settings['catch_action']['sub_template']; |
|
1629 | + } |
|
1630 | + } |
|
1569 | 1631 | |
1570 | 1632 | /** |
1571 | 1633 | * Set an option via javascript. |
@@ -1584,12 +1646,14 @@ discard block |
||
1584 | 1646 | checkSession('get'); |
1585 | 1647 | |
1586 | 1648 | // This good-for-nothing pixel is being used to keep the session alive. |
1587 | - if (empty($_GET['var']) || !isset($_GET['val'])) |
|
1588 | - redirectexit($settings['images_url'] . '/blank.png'); |
|
1649 | + if (empty($_GET['var']) || !isset($_GET['val'])) { |
|
1650 | + redirectexit($settings['images_url'] . '/blank.png'); |
|
1651 | + } |
|
1589 | 1652 | |
1590 | 1653 | // Sorry, guests can't go any further than this. |
1591 | - if ($user_info['is_guest'] || $user_info['id'] == 0) |
|
1592 | - obExit(false); |
|
1654 | + if ($user_info['is_guest'] || $user_info['id'] == 0) { |
|
1655 | + obExit(false); |
|
1656 | + } |
|
1593 | 1657 | |
1594 | 1658 | $reservedVars = array( |
1595 | 1659 | 'actual_theme_url', |
@@ -1612,8 +1676,9 @@ discard block |
||
1612 | 1676 | ); |
1613 | 1677 | |
1614 | 1678 | // Can't change reserved vars. |
1615 | - if (in_array(strtolower($_GET['var']), $reservedVars)) |
|
1616 | - redirectexit($settings['images_url'] . '/blank.png'); |
|
1679 | + if (in_array(strtolower($_GET['var']), $reservedVars)) { |
|
1680 | + redirectexit($settings['images_url'] . '/blank.png'); |
|
1681 | + } |
|
1617 | 1682 | |
1618 | 1683 | // Use a specific theme? |
1619 | 1684 | if (isset($_GET['th']) || isset($_GET['id'])) |
@@ -1629,8 +1694,9 @@ discard block |
||
1629 | 1694 | { |
1630 | 1695 | $options['admin_preferences'] = !empty($options['admin_preferences']) ? $smcFunc['json_decode']($options['admin_preferences'], true) : array(); |
1631 | 1696 | // New thingy... |
1632 | - if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5) |
|
1633 | - $options['admin_preferences'][$_GET['admin_key']] = $_GET['val']; |
|
1697 | + if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5) { |
|
1698 | + $options['admin_preferences'][$_GET['admin_key']] = $_GET['val']; |
|
1699 | + } |
|
1634 | 1700 | |
1635 | 1701 | // Change the value to be something nice, |
1636 | 1702 | $_GET['val'] = $smcFunc['json_encode']($options['admin_preferences']); |
@@ -1660,8 +1726,9 @@ discard block |
||
1660 | 1726 | global $context, $scripturl, $boarddir, $smcFunc, $txt; |
1661 | 1727 | |
1662 | 1728 | // @todo Should this be removed? |
1663 | - if (isset($_REQUEST['preview'])) |
|
1664 | - die('die() with fire'); |
|
1729 | + if (isset($_REQUEST['preview'])) { |
|
1730 | + die('die() with fire'); |
|
1731 | + } |
|
1665 | 1732 | |
1666 | 1733 | isAllowedTo('admin_forum'); |
1667 | 1734 | loadTemplate('Themes'); |
@@ -1675,11 +1742,11 @@ discard block |
||
1675 | 1742 | foreach ($context['themes'] as $key => $theme) |
1676 | 1743 | { |
1677 | 1744 | // There has to be a Settings template! |
1678 | - if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css')) |
|
1679 | - unset($context['themes'][$key]); |
|
1680 | - |
|
1681 | - else |
|
1682 | - $context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css'); |
|
1745 | + if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css')) { |
|
1746 | + unset($context['themes'][$key]); |
|
1747 | + } else { |
|
1748 | + $context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css'); |
|
1749 | + } |
|
1683 | 1750 | } |
1684 | 1751 | |
1685 | 1752 | $context['sub_template'] = 'edit_list'; |
@@ -1694,22 +1761,24 @@ discard block |
||
1694 | 1761 | $context['theme_id'] = $currentTheme['id']; |
1695 | 1762 | $context['browse_title'] = sprintf($txt['themeadmin_browsing_theme'], $currentTheme['name']); |
1696 | 1763 | |
1697 | - if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css')) |
|
1698 | - fatal_lang_error('theme_edit_missing', false); |
|
1764 | + if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css')) { |
|
1765 | + fatal_lang_error('theme_edit_missing', false); |
|
1766 | + } |
|
1699 | 1767 | |
1700 | 1768 | if (!isset($_REQUEST['filename'])) |
1701 | 1769 | { |
1702 | 1770 | if (isset($_GET['directory'])) |
1703 | 1771 | { |
1704 | - if (substr($_GET['directory'], 0, 1) == '.') |
|
1705 | - $_GET['directory'] = ''; |
|
1706 | - else |
|
1772 | + if (substr($_GET['directory'], 0, 1) == '.') { |
|
1773 | + $_GET['directory'] = ''; |
|
1774 | + } else |
|
1707 | 1775 | { |
1708 | 1776 | $_GET['directory'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_GET['directory']); |
1709 | 1777 | |
1710 | 1778 | $temp = realpath($currentTheme['theme_dir'] . '/' . $_GET['directory']); |
1711 | - if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) |
|
1712 | - $_GET['directory'] = ''; |
|
1779 | + if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) { |
|
1780 | + $_GET['directory'] = ''; |
|
1781 | + } |
|
1713 | 1782 | } |
1714 | 1783 | } |
1715 | 1784 | |
@@ -1728,37 +1797,39 @@ discard block |
||
1728 | 1797 | 'href' => $scripturl . '?action=admin;area=theme;th=' . $_GET['th'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=edit;directory=' . $temp, |
1729 | 1798 | 'size' => '', |
1730 | 1799 | )); |
1800 | + } else { |
|
1801 | + $context['theme_files'] = get_file_listing($currentTheme['theme_dir'], ''); |
|
1731 | 1802 | } |
1732 | - else |
|
1733 | - $context['theme_files'] = get_file_listing($currentTheme['theme_dir'], ''); |
|
1734 | 1803 | |
1735 | 1804 | $context['sub_template'] = 'edit_browse'; |
1736 | 1805 | |
1737 | 1806 | return; |
1738 | - } |
|
1739 | - else |
|
1807 | + } else |
|
1740 | 1808 | { |
1741 | - if (substr($_REQUEST['filename'], 0, 1) == '.') |
|
1742 | - $_REQUEST['filename'] = ''; |
|
1743 | - else |
|
1809 | + if (substr($_REQUEST['filename'], 0, 1) == '.') { |
|
1810 | + $_REQUEST['filename'] = ''; |
|
1811 | + } else |
|
1744 | 1812 | { |
1745 | 1813 | $_REQUEST['filename'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_REQUEST['filename']); |
1746 | 1814 | |
1747 | 1815 | $temp = realpath($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']); |
1748 | - if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) |
|
1749 | - $_REQUEST['filename'] = ''; |
|
1816 | + if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) { |
|
1817 | + $_REQUEST['filename'] = ''; |
|
1818 | + } |
|
1750 | 1819 | } |
1751 | 1820 | |
1752 | - if (empty($_REQUEST['filename'])) |
|
1753 | - fatal_lang_error('theme_edit_missing', false); |
|
1821 | + if (empty($_REQUEST['filename'])) { |
|
1822 | + fatal_lang_error('theme_edit_missing', false); |
|
1823 | + } |
|
1754 | 1824 | } |
1755 | 1825 | |
1756 | 1826 | if (isset($_POST['save'])) |
1757 | 1827 | { |
1758 | 1828 | if (checkSession('post', '', false) == '' && validateToken('admin-te-' . md5($_GET['th'] . '-' . $_REQUEST['filename']), 'post', false) == true) |
1759 | 1829 | { |
1760 | - if (is_array($_POST['entire_file'])) |
|
1761 | - $_POST['entire_file'] = implode("\n", $_POST['entire_file']); |
|
1830 | + if (is_array($_POST['entire_file'])) { |
|
1831 | + $_POST['entire_file'] = implode("\n", $_POST['entire_file']); |
|
1832 | + } |
|
1762 | 1833 | |
1763 | 1834 | $_POST['entire_file'] = rtrim(strtr($_POST['entire_file'], array("\r" => '', ' ' => "\t"))); |
1764 | 1835 | |
@@ -1770,10 +1841,11 @@ discard block |
||
1770 | 1841 | fclose($fp); |
1771 | 1842 | |
1772 | 1843 | $error = @file_get_contents($currentTheme['theme_url'] . '/tmp_' . session_id() . '.php'); |
1773 | - if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0) |
|
1774 | - $error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php'; |
|
1775 | - else |
|
1776 | - unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php'); |
|
1844 | + if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0) { |
|
1845 | + $error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php'; |
|
1846 | + } else { |
|
1847 | + unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php'); |
|
1848 | + } |
|
1777 | 1849 | } |
1778 | 1850 | |
1779 | 1851 | if (!isset($error_file)) |
@@ -1794,10 +1866,11 @@ discard block |
||
1794 | 1866 | $context['sub_template'] = 'edit_file'; |
1795 | 1867 | |
1796 | 1868 | // Recycle the submitted data. |
1797 | - if (is_array($_POST['entire_file'])) |
|
1798 | - $context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file'])); |
|
1799 | - else |
|
1800 | - $context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']); |
|
1869 | + if (is_array($_POST['entire_file'])) { |
|
1870 | + $context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file'])); |
|
1871 | + } else { |
|
1872 | + $context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']); |
|
1873 | + } |
|
1801 | 1874 | |
1802 | 1875 | $context['edit_filename'] = $smcFunc['htmlspecialchars']($_POST['filename']); |
1803 | 1876 | |
@@ -1820,17 +1893,17 @@ discard block |
||
1820 | 1893 | $context['sub_template'] = 'edit_style'; |
1821 | 1894 | |
1822 | 1895 | $context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(file_get_contents($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']), array("\t" => ' '))); |
1823 | - } |
|
1824 | - elseif (substr($_REQUEST['filename'], -13) == '.template.php') |
|
1896 | + } elseif (substr($_REQUEST['filename'], -13) == '.template.php') |
|
1825 | 1897 | { |
1826 | 1898 | $context['sub_template'] = 'edit_template'; |
1827 | 1899 | |
1828 | - if (!isset($error_file)) |
|
1829 | - $file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']); |
|
1830 | - else |
|
1900 | + if (!isset($error_file)) { |
|
1901 | + $file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']); |
|
1902 | + } else |
|
1831 | 1903 | { |
1832 | - if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0) |
|
1833 | - $context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2]; |
|
1904 | + if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0) { |
|
1905 | + $context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2]; |
|
1906 | + } |
|
1834 | 1907 | $file_data = file($error_file); |
1835 | 1908 | unlink($error_file); |
1836 | 1909 | } |
@@ -1844,8 +1917,9 @@ discard block |
||
1844 | 1917 | // Try to format the functions a little nicer... |
1845 | 1918 | $context['file_parts'][$j]['data'] = trim($context['file_parts'][$j]['data']) . "\n"; |
1846 | 1919 | |
1847 | - if (empty($context['file_parts'][$j]['lines'])) |
|
1848 | - unset($context['file_parts'][$j]); |
|
1920 | + if (empty($context['file_parts'][$j]['lines'])) { |
|
1921 | + unset($context['file_parts'][$j]); |
|
1922 | + } |
|
1849 | 1923 | $context['file_parts'][++$j] = array('lines' => 0, 'line' => $i + 1, 'data' => ''); |
1850 | 1924 | } |
1851 | 1925 | |
@@ -1854,8 +1928,7 @@ discard block |
||
1854 | 1928 | } |
1855 | 1929 | |
1856 | 1930 | $context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(implode('', $file_data), array("\t" => ' '))); |
1857 | - } |
|
1858 | - else |
|
1931 | + } else |
|
1859 | 1932 | { |
1860 | 1933 | $context['sub_template'] = 'edit_file'; |
1861 | 1934 | |
@@ -1881,8 +1954,9 @@ discard block |
||
1881 | 1954 | |
1882 | 1955 | $_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id']; |
1883 | 1956 | |
1884 | - if (empty($_GET['th'])) |
|
1885 | - fatal_lang_error('theme_install_invalid_id'); |
|
1957 | + if (empty($_GET['th'])) { |
|
1958 | + fatal_lang_error('theme_install_invalid_id'); |
|
1959 | + } |
|
1886 | 1960 | |
1887 | 1961 | // Get the theme info. |
1888 | 1962 | $theme = get_single_theme($_GET['th']); |
@@ -1890,25 +1964,24 @@ discard block |
||
1890 | 1964 | |
1891 | 1965 | if (isset($_REQUEST['template']) && preg_match('~[\./\\\\:\0]~', $_REQUEST['template']) == 0) |
1892 | 1966 | { |
1893 | - if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php')) |
|
1894 | - $filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php'; |
|
1895 | - |
|
1896 | - else |
|
1897 | - fatal_lang_error('no_access', false); |
|
1967 | + if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php')) { |
|
1968 | + $filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php'; |
|
1969 | + } else { |
|
1970 | + fatal_lang_error('no_access', false); |
|
1971 | + } |
|
1898 | 1972 | |
1899 | 1973 | $fp = fopen($theme['theme_dir'] . '/' . $_REQUEST['template'] . '.template.php', 'w'); |
1900 | 1974 | fwrite($fp, file_get_contents($filename)); |
1901 | 1975 | fclose($fp); |
1902 | 1976 | |
1903 | 1977 | redirectexit('action=admin;area=theme;th=' . $context['theme_id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=copy'); |
1904 | - } |
|
1905 | - elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0) |
|
1978 | + } elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0) |
|
1906 | 1979 | { |
1907 | - if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php')) |
|
1908 | - $filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php'; |
|
1909 | - |
|
1910 | - else |
|
1911 | - fatal_lang_error('no_access', false); |
|
1980 | + if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php')) { |
|
1981 | + $filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php'; |
|
1982 | + } else { |
|
1983 | + fatal_lang_error('no_access', false); |
|
1984 | + } |
|
1912 | 1985 | |
1913 | 1986 | $fp = fopen($theme['theme_dir'] . '/languages/' . $_REQUEST['lang_file'] . '.php', 'w'); |
1914 | 1987 | fwrite($fp, file_get_contents($filename)); |
@@ -1923,16 +1996,18 @@ discard block |
||
1923 | 1996 | $dir = dir($settings['default_theme_dir']); |
1924 | 1997 | while ($entry = $dir->read()) |
1925 | 1998 | { |
1926 | - if (substr($entry, -13) == '.template.php') |
|
1927 | - $templates[] = substr($entry, 0, -13); |
|
1999 | + if (substr($entry, -13) == '.template.php') { |
|
2000 | + $templates[] = substr($entry, 0, -13); |
|
2001 | + } |
|
1928 | 2002 | } |
1929 | 2003 | $dir->close(); |
1930 | 2004 | |
1931 | 2005 | $dir = dir($settings['default_theme_dir'] . '/languages'); |
1932 | 2006 | while ($entry = $dir->read()) |
1933 | 2007 | { |
1934 | - if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches)) |
|
1935 | - $lang_files[] = $matches[1]; |
|
2008 | + if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches)) { |
|
2009 | + $lang_files[] = $matches[1]; |
|
2010 | + } |
|
1936 | 2011 | } |
1937 | 2012 | $dir->close(); |
1938 | 2013 | |
@@ -1940,21 +2015,23 @@ discard block |
||
1940 | 2015 | natcasesort($lang_files); |
1941 | 2016 | |
1942 | 2017 | $context['available_templates'] = array(); |
1943 | - foreach ($templates as $template) |
|
1944 | - $context['available_templates'][$template] = array( |
|
2018 | + foreach ($templates as $template) { |
|
2019 | + $context['available_templates'][$template] = array( |
|
1945 | 2020 | 'filename' => $template . '.template.php', |
1946 | 2021 | 'value' => $template, |
1947 | 2022 | 'already_exists' => false, |
1948 | 2023 | 'can_copy' => is_writable($theme['theme_dir']), |
1949 | 2024 | ); |
2025 | + } |
|
1950 | 2026 | $context['available_language_files'] = array(); |
1951 | - foreach ($lang_files as $file) |
|
1952 | - $context['available_language_files'][$file] = array( |
|
2027 | + foreach ($lang_files as $file) { |
|
2028 | + $context['available_language_files'][$file] = array( |
|
1953 | 2029 | 'filename' => $file . '.php', |
1954 | 2030 | 'value' => $file, |
1955 | 2031 | 'already_exists' => false, |
1956 | 2032 | 'can_copy' => file_exists($theme['theme_dir'] . '/languages') ? is_writable($theme['theme_dir'] . '/languages') : is_writable($theme['theme_dir']), |
1957 | 2033 | ); |
2034 | + } |
|
1958 | 2035 | |
1959 | 2036 | $dir = dir($theme['theme_dir']); |
1960 | 2037 | while ($entry = $dir->read()) |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 4 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | loadLanguage('Drafts'); |
21 | 22 | |
@@ -33,8 +34,9 @@ discard block |
||
33 | 34 | global $context, $user_info, $smcFunc, $modSettings, $board; |
34 | 35 | |
35 | 36 | // can you be, should you be ... here? |
36 | - if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft'])) |
|
37 | - return false; |
|
37 | + if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft'])) { |
|
38 | + return false; |
|
39 | + } |
|
38 | 40 | |
39 | 41 | // read in what they sent us, if anything |
40 | 42 | $id_draft = (int) $_POST['id_draft']; |
@@ -46,14 +48,16 @@ discard block |
||
46 | 48 | $context['draft_saved_on'] = $draft_info['poster_time']; |
47 | 49 | |
48 | 50 | // since we were called from the autosave function, send something back |
49 | - if (!empty($id_draft)) |
|
50 | - XmlDraft($id_draft); |
|
51 | + if (!empty($id_draft)) { |
|
52 | + XmlDraft($id_draft); |
|
53 | + } |
|
51 | 54 | |
52 | 55 | return true; |
53 | 56 | } |
54 | 57 | |
55 | - if (!isset($_POST['message'])) |
|
56 | - $_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : ''; |
|
58 | + if (!isset($_POST['message'])) { |
|
59 | + $_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : ''; |
|
60 | + } |
|
57 | 61 | |
58 | 62 | // prepare any data from the form |
59 | 63 | $topic_id = empty($_REQUEST['topic']) ? 0 : (int) $_REQUEST['topic']; |
@@ -66,8 +70,9 @@ discard block |
||
66 | 70 | |
67 | 71 | // message and subject still need a bit more work |
68 | 72 | preparsecode($draft['body']); |
69 | - if ($smcFunc['strlen']($draft['subject']) > 100) |
|
70 | - $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
73 | + if ($smcFunc['strlen']($draft['subject']) > 100) { |
|
74 | + $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
75 | + } |
|
71 | 76 | |
72 | 77 | // Modifying an existing draft, like hitting the save draft button or autosave enabled? |
73 | 78 | if (!empty($id_draft) && !empty($draft_info)) |
@@ -148,9 +153,9 @@ discard block |
||
148 | 153 | { |
149 | 154 | $context['draft_saved'] = true; |
150 | 155 | $context['id_draft'] = $id_draft; |
156 | + } else { |
|
157 | + $post_errors[] = 'draft_not_saved'; |
|
151 | 158 | } |
152 | - else |
|
153 | - $post_errors[] = 'draft_not_saved'; |
|
154 | 159 | |
155 | 160 | // cleanup |
156 | 161 | unset($_POST['save_draft']); |
@@ -180,8 +185,9 @@ discard block |
||
180 | 185 | global $context, $user_info, $smcFunc, $modSettings; |
181 | 186 | |
182 | 187 | // PM survey says ... can you stay or must you go |
183 | - if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) |
|
184 | - return false; |
|
188 | + if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) { |
|
189 | + return false; |
|
190 | + } |
|
185 | 191 | |
186 | 192 | // read in what you sent us |
187 | 193 | $id_pm_draft = (int) $_POST['id_pm_draft']; |
@@ -193,8 +199,9 @@ discard block |
||
193 | 199 | $context['draft_saved_on'] = $draft_info['poster_time']; |
194 | 200 | |
195 | 201 | // Send something back to the javascript caller |
196 | - if (!empty($id_draft)) |
|
197 | - XmlDraft($id_draft); |
|
202 | + if (!empty($id_draft)) { |
|
203 | + XmlDraft($id_draft); |
|
204 | + } |
|
198 | 205 | |
199 | 206 | return true; |
200 | 207 | } |
@@ -204,9 +211,9 @@ discard block |
||
204 | 211 | { |
205 | 212 | $recipientList['to'] = isset($_POST['recipient_to']) ? explode(',', $_POST['recipient_to']) : array(); |
206 | 213 | $recipientList['bcc'] = isset($_POST['recipient_bcc']) ? explode(',', $_POST['recipient_bcc']) : array(); |
214 | + } elseif (!empty($draft_info['to_list']) && empty($recipientList)) { |
|
215 | + $recipientList = $smcFunc['json_decode']($draft_info['to_list'], true); |
|
207 | 216 | } |
208 | - elseif (!empty($draft_info['to_list']) && empty($recipientList)) |
|
209 | - $recipientList = $smcFunc['json_decode']($draft_info['to_list'], true); |
|
210 | 217 | |
211 | 218 | // prepare the data we got from the form |
212 | 219 | $reply_id = empty($_POST['replied_to']) ? 0 : (int) $_POST['replied_to']; |
@@ -215,8 +222,9 @@ discard block |
||
215 | 222 | |
216 | 223 | // message and subject always need a bit more work |
217 | 224 | preparsecode($draft['body']); |
218 | - if ($smcFunc['strlen']($draft['subject']) > 100) |
|
219 | - $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
225 | + if ($smcFunc['strlen']($draft['subject']) > 100) { |
|
226 | + $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
227 | + } |
|
220 | 228 | |
221 | 229 | // Modifying an existing PM draft? |
222 | 230 | if (!empty($id_pm_draft) && !empty($draft_info)) |
@@ -280,9 +288,9 @@ discard block |
||
280 | 288 | { |
281 | 289 | $context['draft_saved'] = true; |
282 | 290 | $context['id_pm_draft'] = $id_pm_draft; |
291 | + } else { |
|
292 | + $post_errors[] = 'draft_not_saved'; |
|
283 | 293 | } |
284 | - else |
|
285 | - $post_errors[] = 'draft_not_saved'; |
|
286 | 294 | } |
287 | 295 | |
288 | 296 | // if we were called from the autosave function, send something back |
@@ -315,8 +323,9 @@ discard block |
||
315 | 323 | $type = (int) $type; |
316 | 324 | |
317 | 325 | // nothing to read, nothing to do |
318 | - if (empty($id_draft)) |
|
319 | - return false; |
|
326 | + if (empty($id_draft)) { |
|
327 | + return false; |
|
328 | + } |
|
320 | 329 | |
321 | 330 | // load in this draft from the DB |
322 | 331 | $request = $smcFunc['db_query']('', ' |
@@ -337,8 +346,9 @@ discard block |
||
337 | 346 | ); |
338 | 347 | |
339 | 348 | // no results? |
340 | - if (!$smcFunc['db_num_rows']($request)) |
|
341 | - return false; |
|
349 | + if (!$smcFunc['db_num_rows']($request)) { |
|
350 | + return false; |
|
351 | + } |
|
342 | 352 | |
343 | 353 | // load up the data |
344 | 354 | $draft_info = $smcFunc['db_fetch_assoc']($request); |
@@ -358,8 +368,7 @@ discard block |
||
358 | 368 | $context['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : ''; |
359 | 369 | $context['board'] = !empty($draft_info['id_board']) ? $draft_info['id_board'] : ''; |
360 | 370 | $context['id_draft'] = !empty($draft_info['id_draft']) ? $draft_info['id_draft'] : 0; |
361 | - } |
|
362 | - elseif ($type === 1) |
|
371 | + } elseif ($type === 1) |
|
363 | 372 | { |
364 | 373 | // one of those pm drafts? then set it up like we have an error |
365 | 374 | $_REQUEST['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : ''; |
@@ -395,12 +404,14 @@ discard block |
||
395 | 404 | global $user_info, $smcFunc; |
396 | 405 | |
397 | 406 | // Only a single draft. |
398 | - if (is_numeric($id_draft)) |
|
399 | - $id_draft = array($id_draft); |
|
407 | + if (is_numeric($id_draft)) { |
|
408 | + $id_draft = array($id_draft); |
|
409 | + } |
|
400 | 410 | |
401 | 411 | // can't delete nothing |
402 | - if (empty($id_draft) || ($check && empty($user_info['id']))) |
|
403 | - return false; |
|
412 | + if (empty($id_draft) || ($check && empty($user_info['id']))) { |
|
413 | + return false; |
|
414 | + } |
|
404 | 415 | |
405 | 416 | $smcFunc['db_query']('', ' |
406 | 417 | DELETE FROM {db_prefix}user_drafts |
@@ -429,14 +440,16 @@ discard block |
||
429 | 440 | global $smcFunc, $scripturl, $context, $txt, $modSettings; |
430 | 441 | |
431 | 442 | // Permissions |
432 | - if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) |
|
433 | - return false; |
|
443 | + if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) { |
|
444 | + return false; |
|
445 | + } |
|
434 | 446 | |
435 | 447 | $context['drafts'] = array(); |
436 | 448 | |
437 | 449 | // has a specific draft has been selected? Load it up if there is not a message already in the editor |
438 | - if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) |
|
439 | - ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true); |
|
450 | + if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) { |
|
451 | + ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true); |
|
452 | + } |
|
440 | 453 | |
441 | 454 | // load the drafts this user has available |
442 | 455 | $request = $smcFunc['db_query']('', ' |
@@ -459,8 +472,9 @@ discard block |
||
459 | 472 | // add them to the draft array for display |
460 | 473 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
461 | 474 | { |
462 | - if (empty($row['subject'])) |
|
463 | - $row['subject'] = $txt['no_subject']; |
|
475 | + if (empty($row['subject'])) { |
|
476 | + $row['subject'] = $txt['no_subject']; |
|
477 | + } |
|
464 | 478 | |
465 | 479 | // Post drafts |
466 | 480 | if ($draft_type === 0) |
@@ -545,8 +559,9 @@ discard block |
||
545 | 559 | } |
546 | 560 | |
547 | 561 | // Default to 10. |
548 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
549 | - $_REQUEST['viewscount'] = 10; |
|
562 | + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { |
|
563 | + $_REQUEST['viewscount'] = 10; |
|
564 | + } |
|
550 | 565 | |
551 | 566 | // Get the count of applicable drafts on the boards they can (still) see ... |
552 | 567 | // @todo .. should we just let them see their drafts even if they have lost board access ? |
@@ -611,12 +626,14 @@ discard block |
||
611 | 626 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
612 | 627 | { |
613 | 628 | // Censor.... |
614 | - if (empty($row['body'])) |
|
615 | - $row['body'] = ''; |
|
629 | + if (empty($row['body'])) { |
|
630 | + $row['body'] = ''; |
|
631 | + } |
|
616 | 632 | |
617 | 633 | $row['subject'] = $smcFunc['htmltrim']($row['subject']); |
618 | - if (empty($row['subject'])) |
|
619 | - $row['subject'] = $txt['no_subject']; |
|
634 | + if (empty($row['subject'])) { |
|
635 | + $row['subject'] = $txt['no_subject']; |
|
636 | + } |
|
620 | 637 | |
621 | 638 | censorText($row['body']); |
622 | 639 | censorText($row['subject']); |
@@ -648,8 +665,9 @@ discard block |
||
648 | 665 | $smcFunc['db_free_result']($request); |
649 | 666 | |
650 | 667 | // If the drafts were retrieved in reverse order, get them right again. |
651 | - if ($reverse) |
|
652 | - $context['drafts'] = array_reverse($context['drafts'], true); |
|
668 | + if ($reverse) { |
|
669 | + $context['drafts'] = array_reverse($context['drafts'], true); |
|
670 | + } |
|
653 | 671 | |
654 | 672 | // Menu tab |
655 | 673 | $context[$context['profile_menu_name']]['tab_data'] = array( |
@@ -707,8 +725,9 @@ discard block |
||
707 | 725 | } |
708 | 726 | |
709 | 727 | // Default to 10. |
710 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
711 | - $_REQUEST['viewscount'] = 10; |
|
728 | + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { |
|
729 | + $_REQUEST['viewscount'] = 10; |
|
730 | + } |
|
712 | 731 | |
713 | 732 | // Get the count of applicable drafts |
714 | 733 | $request = $smcFunc['db_query']('', ' |
@@ -767,12 +786,14 @@ discard block |
||
767 | 786 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
768 | 787 | { |
769 | 788 | // Censor.... |
770 | - if (empty($row['body'])) |
|
771 | - $row['body'] = ''; |
|
789 | + if (empty($row['body'])) { |
|
790 | + $row['body'] = ''; |
|
791 | + } |
|
772 | 792 | |
773 | 793 | $row['subject'] = $smcFunc['htmltrim']($row['subject']); |
774 | - if (empty($row['subject'])) |
|
775 | - $row['subject'] = $txt['no_subject']; |
|
794 | + if (empty($row['subject'])) { |
|
795 | + $row['subject'] = $txt['no_subject']; |
|
796 | + } |
|
776 | 797 | |
777 | 798 | censorText($row['body']); |
778 | 799 | censorText($row['subject']); |
@@ -827,8 +848,9 @@ discard block |
||
827 | 848 | $smcFunc['db_free_result']($request); |
828 | 849 | |
829 | 850 | // if the drafts were retrieved in reverse order, then put them in the right order again. |
830 | - if ($reverse) |
|
831 | - $context['drafts'] = array_reverse($context['drafts'], true); |
|
851 | + if ($reverse) { |
|
852 | + $context['drafts'] = array_reverse($context['drafts'], true); |
|
853 | + } |
|
832 | 854 | |
833 | 855 | // off to the template we go |
834 | 856 | $context['page_title'] = $txt['drafts']; |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 4 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * The main 'Attachments and Avatars' management function. |
@@ -63,10 +64,11 @@ discard block |
||
63 | 64 | call_integration_hook('integrate_manage_attachments', array(&$subActions)); |
64 | 65 | |
65 | 66 | // Pick the correct sub-action. |
66 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
67 | - $context['sub_action'] = $_REQUEST['sa']; |
|
68 | - else |
|
69 | - $context['sub_action'] = 'browse'; |
|
67 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
68 | + $context['sub_action'] = $_REQUEST['sa']; |
|
69 | + } else { |
|
70 | + $context['sub_action'] = 'browse'; |
|
71 | + } |
|
70 | 72 | |
71 | 73 | // Default page title is good. |
72 | 74 | $context['page_title'] = $txt['attachments_avatars']; |
@@ -94,20 +96,20 @@ discard block |
||
94 | 96 | $context['attachmentUploadDir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
95 | 97 | |
96 | 98 | // If not set, show a default path for the base directory |
97 | - if (!isset($_GET['save']) && empty($modSettings['basedirectory_for_attachments'])) |
|
98 | - if (is_dir($modSettings['attachmentUploadDir'][1])) |
|
99 | + if (!isset($_GET['save']) && empty($modSettings['basedirectory_for_attachments'])) { |
|
100 | + if (is_dir($modSettings['attachmentUploadDir'][1])) |
|
99 | 101 | $modSettings['basedirectory_for_attachments'] = $modSettings['attachmentUploadDir'][1]; |
100 | - |
|
101 | - else |
|
102 | - $modSettings['basedirectory_for_attachments'] = $context['attachmentUploadDir']; |
|
102 | + } else { |
|
103 | + $modSettings['basedirectory_for_attachments'] = $context['attachmentUploadDir']; |
|
104 | + } |
|
103 | 105 | |
104 | 106 | $context['valid_upload_dir'] = is_dir($context['attachmentUploadDir']) && is_writable($context['attachmentUploadDir']); |
105 | 107 | |
106 | - if (!empty($modSettings['automanage_attachments'])) |
|
107 | - $context['valid_basedirectory'] = !empty($modSettings['basedirectory_for_attachments']) && is_writable($modSettings['basedirectory_for_attachments']); |
|
108 | - |
|
109 | - else |
|
110 | - $context['valid_basedirectory'] = true; |
|
108 | + if (!empty($modSettings['automanage_attachments'])) { |
|
109 | + $context['valid_basedirectory'] = !empty($modSettings['basedirectory_for_attachments']) && is_writable($modSettings['basedirectory_for_attachments']); |
|
110 | + } else { |
|
111 | + $context['valid_basedirectory'] = true; |
|
112 | + } |
|
111 | 113 | |
112 | 114 | // A bit of razzle dazzle with the $txt strings. :) |
113 | 115 | $txt['attachment_path'] = $context['attachmentUploadDir']; |
@@ -185,8 +187,9 @@ discard block |
||
185 | 187 | |
186 | 188 | call_integration_hook('integrate_modify_attachment_settings', array(&$config_vars)); |
187 | 189 | |
188 | - if ($return_config) |
|
189 | - return $config_vars; |
|
190 | + if ($return_config) { |
|
191 | + return $config_vars; |
|
192 | + } |
|
190 | 193 | |
191 | 194 | // These are very likely to come in handy! (i.e. without them we're doomed!) |
192 | 195 | require_once($sourcedir . '/ManagePermissions.php'); |
@@ -197,21 +200,24 @@ discard block |
||
197 | 200 | { |
198 | 201 | checkSession(); |
199 | 202 | |
200 | - if (isset($_POST['attachmentUploadDir'])) |
|
201 | - unset($_POST['attachmentUploadDir']); |
|
203 | + if (isset($_POST['attachmentUploadDir'])) { |
|
204 | + unset($_POST['attachmentUploadDir']); |
|
205 | + } |
|
202 | 206 | |
203 | 207 | if (!empty($_POST['use_subdirectories_for_attachments'])) |
204 | 208 | { |
205 | - if (isset($_POST['use_subdirectories_for_attachments']) && empty($_POST['basedirectory_for_attachments'])) |
|
206 | - $_POST['basedirectory_for_attachments'] = (!empty($modSettings['basedirectory_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
|
209 | + if (isset($_POST['use_subdirectories_for_attachments']) && empty($_POST['basedirectory_for_attachments'])) { |
|
210 | + $_POST['basedirectory_for_attachments'] = (!empty($modSettings['basedirectory_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
|
211 | + } |
|
207 | 212 | |
208 | 213 | if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($modSettings['attachment_basedirectories'])) |
209 | 214 | { |
210 | - if (!is_array($modSettings['attachment_basedirectories'])) |
|
211 | - $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
215 | + if (!is_array($modSettings['attachment_basedirectories'])) { |
|
216 | + $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
217 | + } |
|
218 | + } else { |
|
219 | + $modSettings['attachment_basedirectories'] = array(); |
|
212 | 220 | } |
213 | - else |
|
214 | - $modSettings['attachment_basedirectories'] = array(); |
|
215 | 221 | |
216 | 222 | if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($_POST['basedirectory_for_attachments']) && !in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories'])) |
217 | 223 | { |
@@ -219,8 +225,9 @@ discard block |
||
219 | 225 | |
220 | 226 | if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachmentUploadDir'])) |
221 | 227 | { |
222 | - if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments'])) |
|
223 | - $_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments']; |
|
228 | + if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments'])) { |
|
229 | + $_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments']; |
|
230 | + } |
|
224 | 231 | } |
225 | 232 | |
226 | 233 | if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories'])) |
@@ -336,8 +343,9 @@ discard block |
||
336 | 343 | |
337 | 344 | call_integration_hook('integrate_modify_avatar_settings', array(&$config_vars)); |
338 | 345 | |
339 | - if ($return_config) |
|
340 | - return $config_vars; |
|
346 | + if ($return_config) { |
|
347 | + return $config_vars; |
|
348 | + } |
|
341 | 349 | |
342 | 350 | // We need this file for the settings template. |
343 | 351 | require_once($sourcedir . '/ManageServer.php'); |
@@ -348,17 +356,21 @@ discard block |
||
348 | 356 | checkSession(); |
349 | 357 | |
350 | 358 | // These settings cannot be left empty! |
351 | - if (empty($_POST['custom_avatar_dir'])) |
|
352 | - $_POST['custom_avatar_dir'] = $boarddir . '/custom_avatar'; |
|
359 | + if (empty($_POST['custom_avatar_dir'])) { |
|
360 | + $_POST['custom_avatar_dir'] = $boarddir . '/custom_avatar'; |
|
361 | + } |
|
353 | 362 | |
354 | - if (empty($_POST['custom_avatar_url'])) |
|
355 | - $_POST['custom_avatar_url'] = $boardurl . '/custom_avatar'; |
|
363 | + if (empty($_POST['custom_avatar_url'])) { |
|
364 | + $_POST['custom_avatar_url'] = $boardurl . '/custom_avatar'; |
|
365 | + } |
|
356 | 366 | |
357 | - if (empty($_POST['avatar_directory'])) |
|
358 | - $_POST['avatar_directory'] = $boarddir . '/avatars'; |
|
367 | + if (empty($_POST['avatar_directory'])) { |
|
368 | + $_POST['avatar_directory'] = $boarddir . '/avatars'; |
|
369 | + } |
|
359 | 370 | |
360 | - if (empty($_POST['avatar_url'])) |
|
361 | - $_POST['avatar_url'] = $boardurl . '/avatars'; |
|
371 | + if (empty($_POST['avatar_url'])) { |
|
372 | + $_POST['avatar_url'] = $boardurl . '/avatars'; |
|
373 | + } |
|
362 | 374 | |
363 | 375 | call_integration_hook('integrate_save_avatar_settings'); |
364 | 376 | |
@@ -406,11 +418,13 @@ discard block |
||
406 | 418 | $list_title = $txt['attachment_manager_browse_files'] . ': '; |
407 | 419 | foreach ($titles as $browse_type => $details) |
408 | 420 | { |
409 | - if ($browse_type != 'attachments') |
|
410 | - $list_title .= ' | '; |
|
421 | + if ($browse_type != 'attachments') { |
|
422 | + $list_title .= ' | '; |
|
423 | + } |
|
411 | 424 | |
412 | - if ($context['browse_type'] == $browse_type) |
|
413 | - $list_title .= '<img src="' . $settings['images_url'] . '/selected.png" alt=">"> '; |
|
425 | + if ($context['browse_type'] == $browse_type) { |
|
426 | + $list_title .= '<img src="' . $settings['images_url'] . '/selected.png" alt=">"> '; |
|
427 | + } |
|
414 | 428 | |
415 | 429 | $list_title .= '<a href="' . $scripturl . $details[0] . '">' . $details[1] . '</a>'; |
416 | 430 | } |
@@ -446,28 +460,33 @@ discard block |
||
446 | 460 | $link = '<a href="'; |
447 | 461 | |
448 | 462 | // In case of a custom avatar URL attachments have a fixed directory. |
449 | - if ($rowData['attachment_type'] == 1) |
|
450 | - $link .= sprintf('%1$s/%2$s', $modSettings['custom_avatar_url'], $rowData['filename']); |
|
463 | + if ($rowData['attachment_type'] == 1) { |
|
464 | + $link .= sprintf('%1$s/%2$s', $modSettings['custom_avatar_url'], $rowData['filename']); |
|
465 | + } |
|
451 | 466 | |
452 | 467 | // By default avatars are downloaded almost as attachments. |
453 | - elseif ($context['browse_type'] == 'avatars') |
|
454 | - $link .= sprintf('%1$s?action=dlattach;type=avatar;attach=%2$d', $scripturl, $rowData['id_attach']); |
|
468 | + elseif ($context['browse_type'] == 'avatars') { |
|
469 | + $link .= sprintf('%1$s?action=dlattach;type=avatar;attach=%2$d', $scripturl, $rowData['id_attach']); |
|
470 | + } |
|
455 | 471 | |
456 | 472 | // Normal attachments are always linked to a topic ID. |
457 | - else |
|
458 | - $link .= sprintf('%1$s?action=dlattach;topic=%2$d.0;attach=%3$d', $scripturl, $rowData['id_topic'], $rowData['id_attach']); |
|
473 | + else { |
|
474 | + $link .= sprintf('%1$s?action=dlattach;topic=%2$d.0;attach=%3$d', $scripturl, $rowData['id_topic'], $rowData['id_attach']); |
|
475 | + } |
|
459 | 476 | |
460 | 477 | $link .= '"'; |
461 | 478 | |
462 | 479 | // Show a popup on click if it's a picture and we know its dimensions. |
463 | - if (!empty($rowData['width']) && !empty($rowData['height'])) |
|
464 | - $link .= sprintf(' onclick="return reqWin(this.href' . ($rowData['attachment_type'] == 1 ? '' : ' + \';image\'') . ', %1$d, %2$d, true);"', $rowData['width'] + 20, $rowData['height'] + 20); |
|
480 | + if (!empty($rowData['width']) && !empty($rowData['height'])) { |
|
481 | + $link .= sprintf(' onclick="return reqWin(this.href' . ($rowData['attachment_type'] == 1 ? '' : ' + \';image\'') . ', %1$d, %2$d, true);"', $rowData['width'] + 20, $rowData['height'] + 20); |
|
482 | + } |
|
465 | 483 | |
466 | 484 | $link .= sprintf('>%1$s</a>', preg_replace('~&#(\\\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\\\1;', $smcFunc['htmlspecialchars']($rowData['filename']))); |
467 | 485 | |
468 | 486 | // Show the dimensions. |
469 | - if (!empty($rowData['width']) && !empty($rowData['height'])) |
|
470 | - $link .= sprintf(' <span class="smalltext">%1$dx%2$d</span>', $rowData['width'], $rowData['height']); |
|
487 | + if (!empty($rowData['width']) && !empty($rowData['height'])) { |
|
488 | + $link .= sprintf(' <span class="smalltext">%1$dx%2$d</span>', $rowData['width'], $rowData['height']); |
|
489 | + } |
|
471 | 490 | |
472 | 491 | return $link; |
473 | 492 | }, |
@@ -500,12 +519,14 @@ discard block |
||
500 | 519 | 'function' => function($rowData) use ($scripturl, $smcFunc) |
501 | 520 | { |
502 | 521 | // In case of an attachment, return the poster of the attachment. |
503 | - if (empty($rowData['id_member'])) |
|
504 | - return $smcFunc['htmlspecialchars']($rowData['poster_name']); |
|
522 | + if (empty($rowData['id_member'])) { |
|
523 | + return $smcFunc['htmlspecialchars']($rowData['poster_name']); |
|
524 | + } |
|
505 | 525 | |
506 | 526 | // Otherwise it must be an avatar, return the link to the owner of it. |
507 | - else |
|
508 | - return sprintf('<a href="%1$s?action=profile;u=%2$d">%3$s</a>', $scripturl, $rowData['id_member'], $rowData['poster_name']); |
|
527 | + else { |
|
528 | + return sprintf('<a href="%1$s?action=profile;u=%2$d">%3$s</a>', $scripturl, $rowData['id_member'], $rowData['poster_name']); |
|
529 | + } |
|
509 | 530 | }, |
510 | 531 | ), |
511 | 532 | 'sort' => array( |
@@ -524,8 +545,9 @@ discard block |
||
524 | 545 | $date = empty($rowData['poster_time']) ? $txt['never'] : timeformat($rowData['poster_time']); |
525 | 546 | |
526 | 547 | // Add a link to the topic in case of an attachment. |
527 | - if ($context['browse_type'] !== 'avatars') |
|
528 | - $date .= sprintf('<br>%1$s <a href="%2$s?topic=%3$d.msg%4$d#msg%4$d">%5$s</a>', $txt['in'], $scripturl, $rowData['id_topic'], $rowData['id_msg'], $rowData['subject']); |
|
548 | + if ($context['browse_type'] !== 'avatars') { |
|
549 | + $date .= sprintf('<br>%1$s <a href="%2$s?topic=%3$d.msg%4$d#msg%4$d">%5$s</a>', $txt['in'], $scripturl, $rowData['id_topic'], $rowData['id_msg'], $rowData['subject']); |
|
550 | + } |
|
529 | 551 | |
530 | 552 | return $date; |
531 | 553 | }, |
@@ -610,8 +632,8 @@ discard block |
||
610 | 632 | global $smcFunc, $txt; |
611 | 633 | |
612 | 634 | // Choose a query depending on what we are viewing. |
613 | - if ($browse_type === 'avatars') |
|
614 | - $request = $smcFunc['db_query']('', ' |
|
635 | + if ($browse_type === 'avatars') { |
|
636 | + $request = $smcFunc['db_query']('', ' |
|
615 | 637 | SELECT |
616 | 638 | {string:blank_text} AS id_msg, COALESCE(mem.real_name, {string:not_applicable_text}) AS poster_name, |
617 | 639 | mem.last_login AS poster_time, 0 AS id_topic, a.id_member, a.id_attach, a.filename, a.file_hash, a.attachment_type, |
@@ -630,8 +652,8 @@ discard block |
||
630 | 652 | 'per_page' => $items_per_page, |
631 | 653 | ) |
632 | 654 | ); |
633 | - else |
|
634 | - $request = $smcFunc['db_query']('', ' |
|
655 | + } else { |
|
656 | + $request = $smcFunc['db_query']('', ' |
|
635 | 657 | SELECT |
636 | 658 | m.id_msg, COALESCE(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_topic, m.id_member, |
637 | 659 | a.id_attach, a.filename, a.file_hash, a.attachment_type, a.size, a.width, a.height, a.downloads, mf.subject, t.id_board |
@@ -650,9 +672,11 @@ discard block |
||
650 | 672 | 'per_page' => $items_per_page, |
651 | 673 | ) |
652 | 674 | ); |
675 | + } |
|
653 | 676 | $files = array(); |
654 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
655 | - $files[] = $row; |
|
677 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
678 | + $files[] = $row; |
|
679 | + } |
|
656 | 680 | $smcFunc['db_free_result']($request); |
657 | 681 | |
658 | 682 | return $files; |
@@ -670,8 +694,8 @@ discard block |
||
670 | 694 | global $smcFunc; |
671 | 695 | |
672 | 696 | // Depending on the type of file, different queries are used. |
673 | - if ($browse_type === 'avatars') |
|
674 | - $request = $smcFunc['db_query']('', ' |
|
697 | + if ($browse_type === 'avatars') { |
|
698 | + $request = $smcFunc['db_query']('', ' |
|
675 | 699 | SELECT COUNT(*) |
676 | 700 | FROM {db_prefix}attachments |
677 | 701 | WHERE id_member != {int:guest_id_member}', |
@@ -679,8 +703,8 @@ discard block |
||
679 | 703 | 'guest_id_member' => 0, |
680 | 704 | ) |
681 | 705 | ); |
682 | - else |
|
683 | - $request = $smcFunc['db_query']('', ' |
|
706 | + } else { |
|
707 | + $request = $smcFunc['db_query']('', ' |
|
684 | 708 | SELECT COUNT(*) AS num_attach |
685 | 709 | FROM {db_prefix}attachments AS a |
686 | 710 | INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) |
@@ -693,6 +717,7 @@ discard block |
||
693 | 717 | 'guest_id_member' => 0, |
694 | 718 | ) |
695 | 719 | ); |
720 | + } |
|
696 | 721 | |
697 | 722 | list ($num_files) = $smcFunc['db_fetch_row']($request); |
698 | 723 | $smcFunc['db_free_result']($request); |
@@ -775,12 +800,14 @@ discard block |
||
775 | 800 | $current_dir_size /= 1024; |
776 | 801 | |
777 | 802 | // If they specified a limit only.... |
778 | - if (!empty($modSettings['attachmentDirSizeLimit'])) |
|
779 | - $context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2); |
|
803 | + if (!empty($modSettings['attachmentDirSizeLimit'])) { |
|
804 | + $context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2); |
|
805 | + } |
|
780 | 806 | $context['attachment_current_size'] = comma_format($current_dir_size, 2); |
781 | 807 | |
782 | - if (!empty($modSettings['attachmentDirFileLimit'])) |
|
783 | - $context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0); |
|
808 | + if (!empty($modSettings['attachmentDirFileLimit'])) { |
|
809 | + $context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0); |
|
810 | + } |
|
784 | 811 | $context['attachment_current_files'] = comma_format($current_dir_files, 0); |
785 | 812 | |
786 | 813 | $context['attach_multiple_dirs'] = count($attach_dirs) > 1 ? true : false; |
@@ -817,8 +844,8 @@ discard block |
||
817 | 844 | $messages = removeAttachments(array('attachment_type' => 0, 'poster_time' => (time() - 24 * 60 * 60 * $_POST['age'])), 'messages', true); |
818 | 845 | |
819 | 846 | // Update the messages to reflect the change. |
820 | - if (!empty($messages) && !empty($_POST['notice'])) |
|
821 | - $smcFunc['db_query']('', ' |
|
847 | + if (!empty($messages) && !empty($_POST['notice'])) { |
|
848 | + $smcFunc['db_query']('', ' |
|
822 | 849 | UPDATE {db_prefix}messages |
823 | 850 | SET body = CONCAT(body, {string:notice}) |
824 | 851 | WHERE id_msg IN ({array_int:messages})', |
@@ -827,8 +854,8 @@ discard block |
||
827 | 854 | 'notice' => '<br><br>' . $_POST['notice'], |
828 | 855 | ) |
829 | 856 | ); |
830 | - } |
|
831 | - else |
|
857 | + } |
|
858 | + } else |
|
832 | 859 | { |
833 | 860 | // Remove all the old avatars. |
834 | 861 | removeAttachments(array('not_id_member' => 0, 'last_login' => (time() - 24 * 60 * 60 * $_POST['age'])), 'members'); |
@@ -853,8 +880,8 @@ discard block |
||
853 | 880 | $messages = removeAttachments(array('attachment_type' => 0, 'size' => 1024 * $_POST['size']), 'messages', true); |
854 | 881 | |
855 | 882 | // And make a note on the post. |
856 | - if (!empty($messages) && !empty($_POST['notice'])) |
|
857 | - $smcFunc['db_query']('', ' |
|
883 | + if (!empty($messages) && !empty($_POST['notice'])) { |
|
884 | + $smcFunc['db_query']('', ' |
|
858 | 885 | UPDATE {db_prefix}messages |
859 | 886 | SET body = CONCAT(body, {string:notice}) |
860 | 887 | WHERE id_msg IN ({array_int:messages})', |
@@ -863,6 +890,7 @@ discard block |
||
863 | 890 | 'notice' => '<br><br>' . $_POST['notice'], |
864 | 891 | ) |
865 | 892 | ); |
893 | + } |
|
866 | 894 | |
867 | 895 | redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
868 | 896 | } |
@@ -882,16 +910,17 @@ discard block |
||
882 | 910 | { |
883 | 911 | $attachments = array(); |
884 | 912 | // There must be a quicker way to pass this safety test?? |
885 | - foreach ($_POST['remove'] as $removeID => $dummy) |
|
886 | - $attachments[] = (int) $removeID; |
|
913 | + foreach ($_POST['remove'] as $removeID => $dummy) { |
|
914 | + $attachments[] = (int) $removeID; |
|
915 | + } |
|
887 | 916 | |
888 | 917 | // If the attachments are from a 3rd party, let them remove it. Hooks should remove their ids from the array. |
889 | 918 | $filesRemoved = false; |
890 | 919 | call_integration_hook('integrate_attachment_remove', array(&$filesRemoved, $attachments)); |
891 | 920 | |
892 | - if ($_REQUEST['type'] == 'avatars' && !empty($attachments)) |
|
893 | - removeAttachments(array('id_attach' => $attachments)); |
|
894 | - else if (!empty($attachments)) |
|
921 | + if ($_REQUEST['type'] == 'avatars' && !empty($attachments)) { |
|
922 | + removeAttachments(array('id_attach' => $attachments)); |
|
923 | + } else if (!empty($attachments)) |
|
895 | 924 | { |
896 | 925 | $messages = removeAttachments(array('id_attach' => $attachments), 'messages', true); |
897 | 926 | |
@@ -930,12 +959,13 @@ discard block |
||
930 | 959 | |
931 | 960 | $messages = removeAttachments(array('attachment_type' => 0), '', true); |
932 | 961 | |
933 | - if (!isset($_POST['notice'])) |
|
934 | - $_POST['notice'] = $txt['attachment_delete_admin']; |
|
962 | + if (!isset($_POST['notice'])) { |
|
963 | + $_POST['notice'] = $txt['attachment_delete_admin']; |
|
964 | + } |
|
935 | 965 | |
936 | 966 | // Add the notice on the end of the changed messages. |
937 | - if (!empty($messages)) |
|
938 | - $smcFunc['db_query']('', ' |
|
967 | + if (!empty($messages)) { |
|
968 | + $smcFunc['db_query']('', ' |
|
939 | 969 | UPDATE {db_prefix}messages |
940 | 970 | SET body = CONCAT(body, {string:deleted_message}) |
941 | 971 | WHERE id_msg IN ({array_int:messages})', |
@@ -944,6 +974,7 @@ discard block |
||
944 | 974 | 'deleted_message' => '<br><br>' . $_POST['notice'], |
945 | 975 | ) |
946 | 976 | ); |
977 | + } |
|
947 | 978 | |
948 | 979 | redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
949 | 980 | } |
@@ -982,24 +1013,26 @@ discard block |
||
982 | 1013 | $is_not = substr($real_type, 0, 4) == 'not_'; |
983 | 1014 | $type = $is_not ? substr($real_type, 4) : $real_type; |
984 | 1015 | |
985 | - if (in_array($type, array('id_member', 'id_attach', 'id_msg'))) |
|
986 | - $new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
987 | - elseif ($type == 'attachment_type') |
|
988 | - $new_condition[] = 'a.attachment_type = {int:' . $real_type . '}'; |
|
989 | - elseif ($type == 'poster_time') |
|
990 | - $new_condition[] = 'm.poster_time < {int:' . $real_type . '}'; |
|
991 | - elseif ($type == 'last_login') |
|
992 | - $new_condition[] = 'mem.last_login < {int:' . $real_type . '}'; |
|
993 | - elseif ($type == 'size') |
|
994 | - $new_condition[] = 'a.size > {int:' . $real_type . '}'; |
|
995 | - elseif ($type == 'id_topic') |
|
996 | - $new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
1016 | + if (in_array($type, array('id_member', 'id_attach', 'id_msg'))) { |
|
1017 | + $new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
1018 | + } elseif ($type == 'attachment_type') { |
|
1019 | + $new_condition[] = 'a.attachment_type = {int:' . $real_type . '}'; |
|
1020 | + } elseif ($type == 'poster_time') { |
|
1021 | + $new_condition[] = 'm.poster_time < {int:' . $real_type . '}'; |
|
1022 | + } elseif ($type == 'last_login') { |
|
1023 | + $new_condition[] = 'mem.last_login < {int:' . $real_type . '}'; |
|
1024 | + } elseif ($type == 'size') { |
|
1025 | + $new_condition[] = 'a.size > {int:' . $real_type . '}'; |
|
1026 | + } elseif ($type == 'id_topic') { |
|
1027 | + $new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
1028 | + } |
|
997 | 1029 | |
998 | 1030 | // Add the parameter! |
999 | 1031 | $query_parameter[$real_type] = $restriction; |
1000 | 1032 | |
1001 | - if ($type == 'do_logging') |
|
1002 | - $do_logging = $condition['id_attach']; |
|
1033 | + if ($type == 'do_logging') { |
|
1034 | + $do_logging = $condition['id_attach']; |
|
1035 | + } |
|
1003 | 1036 | } |
1004 | 1037 | $condition = implode(' AND ', $new_condition); |
1005 | 1038 | } |
@@ -1031,15 +1064,15 @@ discard block |
||
1031 | 1064 | // wasn't it obvious? :P |
1032 | 1065 | // @todo look again at this. |
1033 | 1066 | @unlink($modSettings['custom_avatar_dir'] . '/' . $row['filename']); |
1034 | - } |
|
1035 | - else |
|
1067 | + } else |
|
1036 | 1068 | { |
1037 | 1069 | $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
1038 | 1070 | @unlink($filename); |
1039 | 1071 | |
1040 | 1072 | // If this was a thumb, the parent attachment should know about it. |
1041 | - if (!empty($row['id_parent'])) |
|
1042 | - $parents[] = $row['id_parent']; |
|
1073 | + if (!empty($row['id_parent'])) { |
|
1074 | + $parents[] = $row['id_parent']; |
|
1075 | + } |
|
1043 | 1076 | |
1044 | 1077 | // If this attachments has a thumb, remove it as well. |
1045 | 1078 | if (!empty($row['id_thumb']) && $autoThumbRemoval) |
@@ -1051,8 +1084,9 @@ discard block |
||
1051 | 1084 | } |
1052 | 1085 | |
1053 | 1086 | // Make a list. |
1054 | - if ($return_affected_messages && empty($row['attachment_type'])) |
|
1055 | - $msgs[] = $row['id_msg']; |
|
1087 | + if ($return_affected_messages && empty($row['attachment_type'])) { |
|
1088 | + $msgs[] = $row['id_msg']; |
|
1089 | + } |
|
1056 | 1090 | |
1057 | 1091 | $attach[] = $row['id_attach']; |
1058 | 1092 | } |
@@ -1060,8 +1094,8 @@ discard block |
||
1060 | 1094 | |
1061 | 1095 | // Removed attachments don't have to be updated anymore. |
1062 | 1096 | $parents = array_diff($parents, $attach); |
1063 | - if (!empty($parents)) |
|
1064 | - $smcFunc['db_query']('', ' |
|
1097 | + if (!empty($parents)) { |
|
1098 | + $smcFunc['db_query']('', ' |
|
1065 | 1099 | UPDATE {db_prefix}attachments |
1066 | 1100 | SET id_thumb = {int:no_thumb} |
1067 | 1101 | WHERE id_attach IN ({array_int:parent_attachments})', |
@@ -1070,6 +1104,7 @@ discard block |
||
1070 | 1104 | 'no_thumb' => 0, |
1071 | 1105 | ) |
1072 | 1106 | ); |
1107 | + } |
|
1073 | 1108 | |
1074 | 1109 | if (!empty($do_logging)) |
1075 | 1110 | { |
@@ -1086,31 +1121,34 @@ discard block |
||
1086 | 1121 | ) |
1087 | 1122 | ); |
1088 | 1123 | |
1089 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1090 | - logAction( |
|
1124 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1125 | + logAction( |
|
1091 | 1126 | 'remove_attach', |
1092 | 1127 | array( |
1093 | 1128 | 'message' => $row['id_msg'], |
1094 | 1129 | 'filename' => preg_replace('~&#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', $smcFunc['htmlspecialchars']($row['filename'])), |
1095 | 1130 | ) |
1096 | 1131 | ); |
1132 | + } |
|
1097 | 1133 | $smcFunc['db_free_result']($request); |
1098 | 1134 | } |
1099 | 1135 | |
1100 | - if (!empty($attach)) |
|
1101 | - $smcFunc['db_query']('', ' |
|
1136 | + if (!empty($attach)) { |
|
1137 | + $smcFunc['db_query']('', ' |
|
1102 | 1138 | DELETE FROM {db_prefix}attachments |
1103 | 1139 | WHERE id_attach IN ({array_int:attachment_list})', |
1104 | 1140 | array( |
1105 | 1141 | 'attachment_list' => $attach, |
1106 | 1142 | ) |
1107 | 1143 | ); |
1144 | + } |
|
1108 | 1145 | |
1109 | 1146 | call_integration_hook('integrate_remove_attachments', array($attach)); |
1110 | 1147 | |
1111 | - if ($return_affected_messages) |
|
1112 | - return array_unique($msgs); |
|
1113 | -} |
|
1148 | + if ($return_affected_messages) { |
|
1149 | + return array_unique($msgs); |
|
1150 | + } |
|
1151 | + } |
|
1114 | 1152 | |
1115 | 1153 | /** |
1116 | 1154 | * This function should find attachments in the database that no longer exist and clear them, and fix filesize issues. |
@@ -1122,8 +1160,9 @@ discard block |
||
1122 | 1160 | checkSession('get'); |
1123 | 1161 | |
1124 | 1162 | // If we choose cancel, redirect right back. |
1125 | - if (isset($_POST['cancel'])) |
|
1126 | - redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
1163 | + if (isset($_POST['cancel'])) { |
|
1164 | + redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
1165 | + } |
|
1127 | 1166 | |
1128 | 1167 | // Try give us a while to sort this out... |
1129 | 1168 | @set_time_limit(600); |
@@ -1140,13 +1179,15 @@ discard block |
||
1140 | 1179 | if (isset($_GET['fixErrors'])) |
1141 | 1180 | { |
1142 | 1181 | // Nothing? |
1143 | - if (empty($_POST['to_fix'])) |
|
1144 | - redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
1182 | + if (empty($_POST['to_fix'])) { |
|
1183 | + redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
1184 | + } |
|
1145 | 1185 | |
1146 | 1186 | $_SESSION['attachments_to_fix'] = array(); |
1147 | 1187 | // @todo No need to do this I think. |
1148 | - foreach ($_POST['to_fix'] as $value) |
|
1149 | - $_SESSION['attachments_to_fix'][] = $value; |
|
1188 | + foreach ($_POST['to_fix'] as $value) { |
|
1189 | + $_SESSION['attachments_to_fix'][] = $value; |
|
1190 | + } |
|
1150 | 1191 | } |
1151 | 1192 | } |
1152 | 1193 | |
@@ -1213,13 +1254,14 @@ discard block |
||
1213 | 1254 | } |
1214 | 1255 | } |
1215 | 1256 | } |
1216 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
1217 | - $to_fix[] = 'missing_thumbnail_parent'; |
|
1257 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
1258 | + $to_fix[] = 'missing_thumbnail_parent'; |
|
1259 | + } |
|
1218 | 1260 | $smcFunc['db_free_result']($result); |
1219 | 1261 | |
1220 | 1262 | // Do we need to delete what we have? |
1221 | - if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix)) |
|
1222 | - $smcFunc['db_query']('', ' |
|
1263 | + if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix)) { |
|
1264 | + $smcFunc['db_query']('', ' |
|
1223 | 1265 | DELETE FROM {db_prefix}attachments |
1224 | 1266 | WHERE id_attach IN ({array_int:to_remove}) |
1225 | 1267 | AND attachment_type = {int:attachment_type}', |
@@ -1228,6 +1270,7 @@ discard block |
||
1228 | 1270 | 'attachment_type' => 3, |
1229 | 1271 | ) |
1230 | 1272 | ); |
1273 | + } |
|
1231 | 1274 | |
1232 | 1275 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
1233 | 1276 | } |
@@ -1272,13 +1315,14 @@ discard block |
||
1272 | 1315 | $to_update[] = $row['id_attach']; |
1273 | 1316 | $context['repair_errors']['parent_missing_thumbnail']++; |
1274 | 1317 | } |
1275 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
1276 | - $to_fix[] = 'parent_missing_thumbnail'; |
|
1318 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
1319 | + $to_fix[] = 'parent_missing_thumbnail'; |
|
1320 | + } |
|
1277 | 1321 | $smcFunc['db_free_result']($result); |
1278 | 1322 | |
1279 | 1323 | // Do we need to delete what we have? |
1280 | - if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix)) |
|
1281 | - $smcFunc['db_query']('', ' |
|
1324 | + if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix)) { |
|
1325 | + $smcFunc['db_query']('', ' |
|
1282 | 1326 | UPDATE {db_prefix}attachments |
1283 | 1327 | SET id_thumb = {int:no_thumb} |
1284 | 1328 | WHERE id_attach IN ({array_int:to_update})', |
@@ -1287,6 +1331,7 @@ discard block |
||
1287 | 1331 | 'no_thumb' => 0, |
1288 | 1332 | ) |
1289 | 1333 | ); |
1334 | + } |
|
1290 | 1335 | |
1291 | 1336 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
1292 | 1337 | } |
@@ -1324,10 +1369,11 @@ discard block |
||
1324 | 1369 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
1325 | 1370 | { |
1326 | 1371 | // Get the filename. |
1327 | - if ($row['attachment_type'] == 1) |
|
1328 | - $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
1329 | - else |
|
1330 | - $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
1372 | + if ($row['attachment_type'] == 1) { |
|
1373 | + $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
1374 | + } else { |
|
1375 | + $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
1376 | + } |
|
1331 | 1377 | |
1332 | 1378 | // File doesn't exist? |
1333 | 1379 | if (!file_exists($filename)) |
@@ -1339,15 +1385,16 @@ discard block |
||
1339 | 1385 | $attachment_name = $row['id_attach'] . '_' . $row['file_hash'] . '.dat'; |
1340 | 1386 | |
1341 | 1387 | // Loop through the other folders. |
1342 | - foreach ($modSettings['attachmentUploadDir'] as $id => $dir) |
|
1343 | - if (file_exists($dir . '/' . $attachment_name)) |
|
1388 | + foreach ($modSettings['attachmentUploadDir'] as $id => $dir) { |
|
1389 | + if (file_exists($dir . '/' . $attachment_name)) |
|
1344 | 1390 | { |
1345 | 1391 | $context['repair_errors']['wrong_folder']++; |
1392 | + } |
|
1346 | 1393 | $errors_found[] = 'wrong_folder'; |
1347 | 1394 | |
1348 | 1395 | // Are we going to fix this now? |
1349 | - if ($fix_errors && in_array('wrong_folder', $to_fix)) |
|
1350 | - $smcFunc['db_query']('', ' |
|
1396 | + if ($fix_errors && in_array('wrong_folder', $to_fix)) { |
|
1397 | + $smcFunc['db_query']('', ' |
|
1351 | 1398 | UPDATE {db_prefix}attachments |
1352 | 1399 | SET id_folder = {int:new_folder} |
1353 | 1400 | WHERE id_attach = {int:id_attach}', |
@@ -1356,6 +1403,7 @@ discard block |
||
1356 | 1403 | 'id_attach' => $row['id_attach'], |
1357 | 1404 | ) |
1358 | 1405 | ); |
1406 | + } |
|
1359 | 1407 | |
1360 | 1408 | continue 2; |
1361 | 1409 | } |
@@ -1364,8 +1412,7 @@ discard block |
||
1364 | 1412 | $to_remove[] = $row['id_attach']; |
1365 | 1413 | $context['repair_errors']['file_missing_on_disk']++; |
1366 | 1414 | $errors_found[] = 'file_missing_on_disk'; |
1367 | - } |
|
1368 | - elseif (filesize($filename) == 0) |
|
1415 | + } elseif (filesize($filename) == 0) |
|
1369 | 1416 | { |
1370 | 1417 | $context['repair_errors']['file_size_of_zero']++; |
1371 | 1418 | $errors_found[] = 'file_size_of_zero'; |
@@ -1376,8 +1423,7 @@ discard block |
||
1376 | 1423 | $to_remove[] = $row['id_attach']; |
1377 | 1424 | @unlink($filename); |
1378 | 1425 | } |
1379 | - } |
|
1380 | - elseif (filesize($filename) != $row['size']) |
|
1426 | + } elseif (filesize($filename) != $row['size']) |
|
1381 | 1427 | { |
1382 | 1428 | $context['repair_errors']['file_wrong_size']++; |
1383 | 1429 | $errors_found[] = 'file_wrong_size'; |
@@ -1398,14 +1444,18 @@ discard block |
||
1398 | 1444 | } |
1399 | 1445 | } |
1400 | 1446 | |
1401 | - if (in_array('file_missing_on_disk', $errors_found)) |
|
1402 | - $to_fix[] = 'file_missing_on_disk'; |
|
1403 | - if (in_array('file_size_of_zero', $errors_found)) |
|
1404 | - $to_fix[] = 'file_size_of_zero'; |
|
1405 | - if (in_array('file_wrong_size', $errors_found)) |
|
1406 | - $to_fix[] = 'file_wrong_size'; |
|
1407 | - if (in_array('wrong_folder', $errors_found)) |
|
1408 | - $to_fix[] = 'wrong_folder'; |
|
1447 | + if (in_array('file_missing_on_disk', $errors_found)) { |
|
1448 | + $to_fix[] = 'file_missing_on_disk'; |
|
1449 | + } |
|
1450 | + if (in_array('file_size_of_zero', $errors_found)) { |
|
1451 | + $to_fix[] = 'file_size_of_zero'; |
|
1452 | + } |
|
1453 | + if (in_array('file_wrong_size', $errors_found)) { |
|
1454 | + $to_fix[] = 'file_wrong_size'; |
|
1455 | + } |
|
1456 | + if (in_array('wrong_folder', $errors_found)) { |
|
1457 | + $to_fix[] = 'wrong_folder'; |
|
1458 | + } |
|
1409 | 1459 | $smcFunc['db_free_result']($result); |
1410 | 1460 | |
1411 | 1461 | // Do we need to delete what we have? |
@@ -1475,20 +1525,22 @@ discard block |
||
1475 | 1525 | // If we are repairing remove the file from disk now. |
1476 | 1526 | if ($fix_errors && in_array('avatar_no_member', $to_fix)) |
1477 | 1527 | { |
1478 | - if ($row['attachment_type'] == 1) |
|
1479 | - $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
1480 | - else |
|
1481 | - $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
1528 | + if ($row['attachment_type'] == 1) { |
|
1529 | + $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
1530 | + } else { |
|
1531 | + $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
1532 | + } |
|
1482 | 1533 | @unlink($filename); |
1483 | 1534 | } |
1484 | 1535 | } |
1485 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
1486 | - $to_fix[] = 'avatar_no_member'; |
|
1536 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
1537 | + $to_fix[] = 'avatar_no_member'; |
|
1538 | + } |
|
1487 | 1539 | $smcFunc['db_free_result']($result); |
1488 | 1540 | |
1489 | 1541 | // Do we need to delete what we have? |
1490 | - if ($fix_errors && !empty($to_remove) && in_array('avatar_no_member', $to_fix)) |
|
1491 | - $smcFunc['db_query']('', ' |
|
1542 | + if ($fix_errors && !empty($to_remove) && in_array('avatar_no_member', $to_fix)) { |
|
1543 | + $smcFunc['db_query']('', ' |
|
1492 | 1544 | DELETE FROM {db_prefix}attachments |
1493 | 1545 | WHERE id_attach IN ({array_int:to_remove}) |
1494 | 1546 | AND id_member != {int:no_member} |
@@ -1499,6 +1551,7 @@ discard block |
||
1499 | 1551 | 'no_msg' => 0, |
1500 | 1552 | ) |
1501 | 1553 | ); |
1554 | + } |
|
1502 | 1555 | |
1503 | 1556 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
1504 | 1557 | } |
@@ -1558,13 +1611,14 @@ discard block |
||
1558 | 1611 | @unlink($filename); |
1559 | 1612 | } |
1560 | 1613 | } |
1561 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
1562 | - $to_fix[] = 'attachment_no_msg'; |
|
1614 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
1615 | + $to_fix[] = 'attachment_no_msg'; |
|
1616 | + } |
|
1563 | 1617 | $smcFunc['db_free_result']($result); |
1564 | 1618 | |
1565 | 1619 | // Do we need to delete what we have? |
1566 | - if ($fix_errors && !empty($to_remove) && in_array('attachment_no_msg', $to_fix)) |
|
1567 | - $smcFunc['db_query']('', ' |
|
1620 | + if ($fix_errors && !empty($to_remove) && in_array('attachment_no_msg', $to_fix)) { |
|
1621 | + $smcFunc['db_query']('', ' |
|
1568 | 1622 | DELETE FROM {db_prefix}attachments |
1569 | 1623 | WHERE id_attach IN ({array_int:to_remove}) |
1570 | 1624 | AND id_member = {int:no_member} |
@@ -1575,6 +1629,7 @@ discard block |
||
1575 | 1629 | 'attach_thumb' => array(0,3), |
1576 | 1630 | ) |
1577 | 1631 | ); |
1632 | + } |
|
1578 | 1633 | |
1579 | 1634 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
1580 | 1635 | } |
@@ -1598,8 +1653,9 @@ discard block |
||
1598 | 1653 | { |
1599 | 1654 | while ($file = readdir($dir)) |
1600 | 1655 | { |
1601 | - if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) |
|
1602 | - continue; |
|
1656 | + if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) { |
|
1657 | + continue; |
|
1658 | + } |
|
1603 | 1659 | |
1604 | 1660 | if ($files_checked <= $current_check) |
1605 | 1661 | { |
@@ -1607,8 +1663,9 @@ discard block |
||
1607 | 1663 | if (strpos($file, 'post_tmp_') !== false) |
1608 | 1664 | { |
1609 | 1665 | // Temp file is more than 5 hours old! |
1610 | - if (filemtime($attach_dir . '/' . $file) < time() - 18000) |
|
1611 | - @unlink($attach_dir . '/' . $file); |
|
1666 | + if (filemtime($attach_dir . '/' . $file) < time() - 18000) { |
|
1667 | + @unlink($attach_dir . '/' . $file); |
|
1668 | + } |
|
1612 | 1669 | } |
1613 | 1670 | // That should be an attachment, let's check if we have it in the database |
1614 | 1671 | elseif (strpos($file, '_') !== false) |
@@ -1630,8 +1687,7 @@ discard block |
||
1630 | 1687 | if ($fix_errors && in_array('files_without_attachment', $to_fix)) |
1631 | 1688 | { |
1632 | 1689 | @unlink($attach_dir . '/' . $file); |
1633 | - } |
|
1634 | - else |
|
1690 | + } else |
|
1635 | 1691 | { |
1636 | 1692 | $context['repair_errors']['files_without_attachment']++; |
1637 | 1693 | $to_fix[] = 'files_without_attachment'; |
@@ -1639,14 +1695,12 @@ discard block |
||
1639 | 1695 | } |
1640 | 1696 | $smcFunc['db_free_result']($request); |
1641 | 1697 | } |
1642 | - } |
|
1643 | - else |
|
1698 | + } else |
|
1644 | 1699 | { |
1645 | 1700 | if ($fix_errors && in_array('files_without_attachment', $to_fix)) |
1646 | 1701 | { |
1647 | 1702 | @unlink($attach_dir . '/' . $file); |
1648 | - } |
|
1649 | - else |
|
1703 | + } else |
|
1650 | 1704 | { |
1651 | 1705 | $context['repair_errors']['files_without_attachment']++; |
1652 | 1706 | $to_fix[] = 'files_without_attachment'; |
@@ -1655,8 +1709,9 @@ discard block |
||
1655 | 1709 | } |
1656 | 1710 | $current_check++; |
1657 | 1711 | $_GET['substep'] = $current_check; |
1658 | - if ($current_check - $files_checked >= $max_checks) |
|
1659 | - pauseAttachmentMaintenance($to_fix); |
|
1712 | + if ($current_check - $files_checked >= $max_checks) { |
|
1713 | + pauseAttachmentMaintenance($to_fix); |
|
1714 | + } |
|
1660 | 1715 | } |
1661 | 1716 | closedir($dir); |
1662 | 1717 | } |
@@ -1692,12 +1747,14 @@ discard block |
||
1692 | 1747 | |
1693 | 1748 | // Try get more time... |
1694 | 1749 | @set_time_limit(600); |
1695 | - if (function_exists('apache_reset_timeout')) |
|
1696 | - @apache_reset_timeout(); |
|
1750 | + if (function_exists('apache_reset_timeout')) { |
|
1751 | + @apache_reset_timeout(); |
|
1752 | + } |
|
1697 | 1753 | |
1698 | 1754 | // Have we already used our maximum time? |
1699 | - if (time() - array_sum(explode(' ', $time_start)) < 3 || $context['starting_substep'] == $_GET['substep']) |
|
1700 | - return; |
|
1755 | + if (time() - array_sum(explode(' ', $time_start)) < 3 || $context['starting_substep'] == $_GET['substep']) { |
|
1756 | + return; |
|
1757 | + } |
|
1701 | 1758 | |
1702 | 1759 | $context['continue_get_data'] = '?action=admin;area=manageattachments;sa=repair' . (isset($_GET['fixErrors']) ? ';fixErrors' : '') . ';step=' . $_GET['step'] . ';substep=' . $_GET['substep'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
1703 | 1760 | $context['page_title'] = $txt['not_done_title']; |
@@ -1709,10 +1766,11 @@ discard block |
||
1709 | 1766 | $context[$context['admin_menu_name']]['current_subsection'] = 'maintenance'; |
1710 | 1767 | |
1711 | 1768 | // Change these two if more steps are added! |
1712 | - if (empty($max_substep)) |
|
1713 | - $context['continue_percent'] = round(($_GET['step'] * 100) / 25); |
|
1714 | - else |
|
1715 | - $context['continue_percent'] = round(($_GET['step'] * 100 + ($_GET['substep'] * 100) / $max_substep) / 25); |
|
1769 | + if (empty($max_substep)) { |
|
1770 | + $context['continue_percent'] = round(($_GET['step'] * 100) / 25); |
|
1771 | + } else { |
|
1772 | + $context['continue_percent'] = round(($_GET['step'] * 100 + ($_GET['substep'] * 100) / $max_substep) / 25); |
|
1773 | + } |
|
1716 | 1774 | |
1717 | 1775 | // Never more than 100%! |
1718 | 1776 | $context['continue_percent'] = min($context['continue_percent'], 100); |
@@ -1754,15 +1812,17 @@ discard block |
||
1754 | 1812 | 'attachment_type' => 0, |
1755 | 1813 | ) |
1756 | 1814 | ); |
1757 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1758 | - $attachments[] = $row['id_attach']; |
|
1815 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1816 | + $attachments[] = $row['id_attach']; |
|
1817 | + } |
|
1759 | 1818 | $smcFunc['db_free_result']($request); |
1819 | + } elseif (!empty($_GET['aid'])) { |
|
1820 | + $attachments[] = (int) $_GET['aid']; |
|
1760 | 1821 | } |
1761 | - elseif (!empty($_GET['aid'])) |
|
1762 | - $attachments[] = (int) $_GET['aid']; |
|
1763 | 1822 | |
1764 | - if (empty($attachments)) |
|
1765 | - fatal_lang_error('no_access', false); |
|
1823 | + if (empty($attachments)) { |
|
1824 | + fatal_lang_error('no_access', false); |
|
1825 | + } |
|
1766 | 1826 | |
1767 | 1827 | // Now we have some ID's cleaned and ready to approve, but first - let's check we have permission! |
1768 | 1828 | $allowed_boards = boardsAllowedTo('approve_posts'); |
@@ -1795,17 +1855,18 @@ discard block |
||
1795 | 1855 | } |
1796 | 1856 | $smcFunc['db_free_result']($request); |
1797 | 1857 | |
1798 | - if (empty($attachments)) |
|
1799 | - fatal_lang_error('no_access', false); |
|
1858 | + if (empty($attachments)) { |
|
1859 | + fatal_lang_error('no_access', false); |
|
1860 | + } |
|
1800 | 1861 | |
1801 | 1862 | // Finally, we are there. Follow through! |
1802 | 1863 | if ($is_approve) |
1803 | 1864 | { |
1804 | 1865 | // Checked and deemed worthy. |
1805 | 1866 | ApproveAttachments($attachments); |
1867 | + } else { |
|
1868 | + removeAttachments(array('id_attach' => $attachments, 'do_logging' => true)); |
|
1806 | 1869 | } |
1807 | - else |
|
1808 | - removeAttachments(array('id_attach' => $attachments, 'do_logging' => true)); |
|
1809 | 1870 | |
1810 | 1871 | // Return to the topic.... |
1811 | 1872 | redirectexit($redirect); |
@@ -1821,8 +1882,9 @@ discard block |
||
1821 | 1882 | { |
1822 | 1883 | global $smcFunc; |
1823 | 1884 | |
1824 | - if (empty($attachments)) |
|
1825 | - return 0; |
|
1885 | + if (empty($attachments)) { |
|
1886 | + return 0; |
|
1887 | + } |
|
1826 | 1888 | |
1827 | 1889 | // For safety, check for thumbnails... |
1828 | 1890 | $request = $smcFunc['db_query']('', ' |
@@ -1841,15 +1903,17 @@ discard block |
||
1841 | 1903 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1842 | 1904 | { |
1843 | 1905 | // Update the thumbnail too... |
1844 | - if (!empty($row['id_thumb'])) |
|
1845 | - $attachments[] = $row['id_thumb']; |
|
1906 | + if (!empty($row['id_thumb'])) { |
|
1907 | + $attachments[] = $row['id_thumb']; |
|
1908 | + } |
|
1846 | 1909 | |
1847 | 1910 | $attachments[] = $row['id_attach']; |
1848 | 1911 | } |
1849 | 1912 | $smcFunc['db_free_result']($request); |
1850 | 1913 | |
1851 | - if (empty($attachments)) |
|
1852 | - return 0; |
|
1914 | + if (empty($attachments)) { |
|
1915 | + return 0; |
|
1916 | + } |
|
1853 | 1917 | |
1854 | 1918 | // Approving an attachment is not hard - it's easy. |
1855 | 1919 | $smcFunc['db_query']('', ' |
@@ -1875,14 +1939,15 @@ discard block |
||
1875 | 1939 | ) |
1876 | 1940 | ); |
1877 | 1941 | |
1878 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1879 | - logAction( |
|
1942 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1943 | + logAction( |
|
1880 | 1944 | 'approve_attach', |
1881 | 1945 | array( |
1882 | 1946 | 'message' => $row['id_msg'], |
1883 | 1947 | 'filename' => preg_replace('~&#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', $smcFunc['htmlspecialchars']($row['filename'])), |
1884 | 1948 | ) |
1885 | 1949 | ); |
1950 | + } |
|
1886 | 1951 | $smcFunc['db_free_result']($request); |
1887 | 1952 | |
1888 | 1953 | // Remove from the approval queue. |
@@ -1905,11 +1970,11 @@ discard block |
||
1905 | 1970 | global $modSettings, $scripturl, $context, $txt, $sourcedir, $boarddir, $smcFunc, $settings; |
1906 | 1971 | |
1907 | 1972 | // Since this needs to be done eventually. |
1908 | - if (!isset($modSettings['attachment_basedirectories'])) |
|
1909 | - $modSettings['attachment_basedirectories'] = array(); |
|
1910 | - |
|
1911 | - elseif (!is_array($modSettings['attachment_basedirectories'])) |
|
1912 | - $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
1973 | + if (!isset($modSettings['attachment_basedirectories'])) { |
|
1974 | + $modSettings['attachment_basedirectories'] = array(); |
|
1975 | + } elseif (!is_array($modSettings['attachment_basedirectories'])) { |
|
1976 | + $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
1977 | + } |
|
1913 | 1978 | |
1914 | 1979 | $errors = array(); |
1915 | 1980 | |
@@ -1924,8 +1989,9 @@ discard block |
||
1924 | 1989 | { |
1925 | 1990 | $error = ''; |
1926 | 1991 | $id = (int) $id; |
1927 | - if ($id < 1) |
|
1928 | - continue; |
|
1992 | + if ($id < 1) { |
|
1993 | + continue; |
|
1994 | + } |
|
1929 | 1995 | |
1930 | 1996 | // Sorry, these dirs are NOT valid |
1931 | 1997 | $invalid_dirs = array($boarddir, $settings['default_theme_dir'], $sourcedir); |
@@ -1944,8 +2010,7 @@ discard block |
||
1944 | 2010 | { |
1945 | 2011 | $errors[] = $path . ': ' . $txt['attach_dir_duplicate_msg']; |
1946 | 2012 | continue; |
1947 | - } |
|
1948 | - elseif (empty($path)) |
|
2013 | + } elseif (empty($path)) |
|
1949 | 2014 | { |
1950 | 2015 | // Ignore this and set $id to one less |
1951 | 2016 | continue; |
@@ -1953,10 +2018,11 @@ discard block |
||
1953 | 2018 | |
1954 | 2019 | // OK, so let's try to create it then. |
1955 | 2020 | require_once($sourcedir . '/Subs-Attachments.php'); |
1956 | - if (automanage_attachments_create_directory($path)) |
|
1957 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
1958 | - else |
|
1959 | - $errors[] = $path . ': ' . $txt[$context['dir_creation_error']]; |
|
2021 | + if (automanage_attachments_create_directory($path)) { |
|
2022 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
2023 | + } else { |
|
2024 | + $errors[] = $path . ': ' . $txt[$context['dir_creation_error']]; |
|
2025 | + } |
|
1960 | 2026 | } |
1961 | 2027 | |
1962 | 2028 | // Changing a directory name? |
@@ -1969,8 +2035,7 @@ discard block |
||
1969 | 2035 | $errors[] = $path . ': ' . $txt['attach_dir_no_rename']; |
1970 | 2036 | $path = $modSettings['attachmentUploadDir'][$id]; |
1971 | 2037 | } |
1972 | - } |
|
1973 | - else |
|
2038 | + } else |
|
1974 | 2039 | { |
1975 | 2040 | $errors[] = $path . ': ' . $txt['attach_dir_exists_msg']; |
1976 | 2041 | $path = $modSettings['attachmentUploadDir'][$id]; |
@@ -1995,12 +2060,13 @@ discard block |
||
1995 | 2060 | $path = $modSettings['attachmentUploadDir'][$id]; |
1996 | 2061 | |
1997 | 2062 | // It's not a good idea to delete the current directory. |
1998 | - if ($id == (!empty($_POST['current_dir']) ? $_POST['current_dir'] : $modSettings['currentAttachmentUploadDir'])) |
|
1999 | - $errors[] = $path . ': ' . $txt['attach_dir_is_current']; |
|
2063 | + if ($id == (!empty($_POST['current_dir']) ? $_POST['current_dir'] : $modSettings['currentAttachmentUploadDir'])) { |
|
2064 | + $errors[] = $path . ': ' . $txt['attach_dir_is_current']; |
|
2065 | + } |
|
2000 | 2066 | // Or the current base directory |
2001 | - elseif (!empty($modSettings['basedirectory_for_attachments']) && $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id]) |
|
2002 | - $errors[] = $path . ': ' . $txt['attach_dir_is_current_bd']; |
|
2003 | - else |
|
2067 | + elseif (!empty($modSettings['basedirectory_for_attachments']) && $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id]) { |
|
2068 | + $errors[] = $path . ': ' . $txt['attach_dir_is_current_bd']; |
|
2069 | + } else |
|
2004 | 2070 | { |
2005 | 2071 | // Let's not try to delete a path with files in it. |
2006 | 2072 | $request = $smcFunc['db_query']('', ' |
@@ -2019,17 +2085,18 @@ discard block |
||
2019 | 2085 | if (!empty($modSettings['attachment_basedirectories'])) |
2020 | 2086 | { |
2021 | 2087 | // Count any sub-folders. |
2022 | - foreach ($modSettings['attachmentUploadDir'] as $sub) |
|
2023 | - if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false) |
|
2088 | + foreach ($modSettings['attachmentUploadDir'] as $sub) { |
|
2089 | + if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false) |
|
2024 | 2090 | $num_attach++; |
2091 | + } |
|
2025 | 2092 | } |
2026 | 2093 | |
2027 | 2094 | // It's safe to delete. So try to delete the folder also |
2028 | 2095 | if ($num_attach == 0) |
2029 | 2096 | { |
2030 | - if (is_dir($path)) |
|
2031 | - $doit = true; |
|
2032 | - elseif (is_dir($boarddir . DIRECTORY_SEPARATOR . $path)) |
|
2097 | + if (is_dir($path)) { |
|
2098 | + $doit = true; |
|
2099 | + } elseif (is_dir($boarddir . DIRECTORY_SEPARATOR . $path)) |
|
2033 | 2100 | { |
2034 | 2101 | $doit = true; |
2035 | 2102 | $path = $boarddir . DIRECTORY_SEPARATOR . $path; |
@@ -2039,8 +2106,9 @@ discard block |
||
2039 | 2106 | { |
2040 | 2107 | unlink($path . '/.htaccess'); |
2041 | 2108 | unlink($path . '/index.php'); |
2042 | - if (!@rmdir($path)) |
|
2043 | - $error = $path . ': ' . $txt['attach_dir_no_delete']; |
|
2109 | + if (!@rmdir($path)) { |
|
2110 | + $error = $path . ': ' . $txt['attach_dir_no_delete']; |
|
2111 | + } |
|
2044 | 2112 | } |
2045 | 2113 | |
2046 | 2114 | // Remove it from the base directory list. |
@@ -2050,14 +2118,15 @@ discard block |
||
2050 | 2118 | updateSettings(array('attachment_basedirectories' => $smcFunc['json_encode']($modSettings['attachment_basedirectories']))); |
2051 | 2119 | $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
2052 | 2120 | } |
2121 | + } else { |
|
2122 | + $error = $path . ': ' . $txt['attach_dir_no_remove']; |
|
2053 | 2123 | } |
2054 | - else |
|
2055 | - $error = $path . ': ' . $txt['attach_dir_no_remove']; |
|
2056 | 2124 | |
2057 | - if (empty($error)) |
|
2058 | - continue; |
|
2059 | - else |
|
2060 | - $errors[] = $error; |
|
2125 | + if (empty($error)) { |
|
2126 | + continue; |
|
2127 | + } else { |
|
2128 | + $errors[] = $error; |
|
2129 | + } |
|
2061 | 2130 | } |
2062 | 2131 | } |
2063 | 2132 | |
@@ -2065,23 +2134,26 @@ discard block |
||
2065 | 2134 | } |
2066 | 2135 | |
2067 | 2136 | // We need to make sure the current directory is right. |
2068 | - if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir'])) |
|
2069 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
2137 | + if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir'])) { |
|
2138 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
2139 | + } |
|
2070 | 2140 | |
2071 | 2141 | // Find the current directory if there's no value carried, |
2072 | 2142 | if (empty($_POST['current_dir']) || empty($new_dirs[$_POST['current_dir']])) |
2073 | 2143 | { |
2074 | - if (array_key_exists($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir'])) |
|
2075 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
2076 | - else |
|
2077 | - $_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir'])); |
|
2144 | + if (array_key_exists($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir'])) { |
|
2145 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
2146 | + } else { |
|
2147 | + $_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir'])); |
|
2148 | + } |
|
2078 | 2149 | } |
2079 | 2150 | |
2080 | 2151 | // If the user wishes to go back, update the last_dir array |
2081 | 2152 | if ($_POST['current_dir'] != $modSettings['currentAttachmentUploadDir'] && !empty($modSettings['last_attachments_directory']) && (isset($modSettings['last_attachments_directory'][$_POST['current_dir']]) || isset($modSettings['last_attachments_directory'][0]))) |
2082 | 2153 | { |
2083 | - if (!is_array($modSettings['last_attachments_directory'])) |
|
2084 | - $modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true); |
|
2154 | + if (!is_array($modSettings['last_attachments_directory'])) { |
|
2155 | + $modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true); |
|
2156 | + } |
|
2085 | 2157 | $num = substr(strrchr($modSettings['attachmentUploadDir'][$_POST['current_dir']], '_'), 1); |
2086 | 2158 | |
2087 | 2159 | if (is_numeric($num)) |
@@ -2089,16 +2161,18 @@ discard block |
||
2089 | 2161 | // Need to find the base folder. |
2090 | 2162 | $bid = -1; |
2091 | 2163 | $use_subdirectories_for_attachments = 0; |
2092 | - if (!empty($modSettings['attachment_basedirectories'])) |
|
2093 | - foreach ($modSettings['attachment_basedirectories'] as $bid => $base) |
|
2164 | + if (!empty($modSettings['attachment_basedirectories'])) { |
|
2165 | + foreach ($modSettings['attachment_basedirectories'] as $bid => $base) |
|
2094 | 2166 | if (strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $base . DIRECTORY_SEPARATOR) !== false) |
2095 | 2167 | { |
2096 | 2168 | $use_subdirectories_for_attachments = 1; |
2169 | + } |
|
2097 | 2170 | break; |
2098 | 2171 | } |
2099 | 2172 | |
2100 | - if ($use_subdirectories_for_attachments == 0 && strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $boarddir . DIRECTORY_SEPARATOR) !== false) |
|
2101 | - $bid = 0; |
|
2173 | + if ($use_subdirectories_for_attachments == 0 && strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $boarddir . DIRECTORY_SEPARATOR) !== false) { |
|
2174 | + $bid = 0; |
|
2175 | + } |
|
2102 | 2176 | |
2103 | 2177 | $modSettings['last_attachments_directory'][$bid] = (int) $num; |
2104 | 2178 | $modSettings['basedirectory_for_attachments'] = !empty($modSettings['basedirectory_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : ''; |
@@ -2117,8 +2191,8 @@ discard block |
||
2117 | 2191 | // We might need to reset the paths. This loop will just loop through once. |
2118 | 2192 | foreach ($new_dirs as $id => $dir) |
2119 | 2193 | { |
2120 | - if ($id != 1) |
|
2121 | - $smcFunc['db_query']('', ' |
|
2194 | + if ($id != 1) { |
|
2195 | + $smcFunc['db_query']('', ' |
|
2122 | 2196 | UPDATE {db_prefix}attachments |
2123 | 2197 | SET id_folder = {int:default_folder} |
2124 | 2198 | WHERE id_folder = {int:current_folder}', |
@@ -2127,14 +2201,14 @@ discard block |
||
2127 | 2201 | 'current_folder' => $id, |
2128 | 2202 | ) |
2129 | 2203 | ); |
2204 | + } |
|
2130 | 2205 | |
2131 | 2206 | $update = array( |
2132 | 2207 | 'currentAttachmentUploadDir' => 1, |
2133 | 2208 | 'attachmentUploadDir' => $smcFunc['json_encode'](array(1 => $dir)), |
2134 | 2209 | ); |
2135 | 2210 | } |
2136 | - } |
|
2137 | - else |
|
2211 | + } else |
|
2138 | 2212 | { |
2139 | 2213 | // Save it to the database. |
2140 | 2214 | $update = array( |
@@ -2143,11 +2217,13 @@ discard block |
||
2143 | 2217 | ); |
2144 | 2218 | } |
2145 | 2219 | |
2146 | - if (!empty($update)) |
|
2147 | - updateSettings($update); |
|
2220 | + if (!empty($update)) { |
|
2221 | + updateSettings($update); |
|
2222 | + } |
|
2148 | 2223 | |
2149 | - if (!empty($errors)) |
|
2150 | - $_SESSION['errors']['dir'] = $errors; |
|
2224 | + if (!empty($errors)) { |
|
2225 | + $_SESSION['errors']['dir'] = $errors; |
|
2226 | + } |
|
2151 | 2227 | |
2152 | 2228 | redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']); |
2153 | 2229 | } |
@@ -2161,10 +2237,11 @@ discard block |
||
2161 | 2237 | $_POST['current_base_dir'] = isset($_POST['current_base_dir']) ? (int) $_POST['current_base_dir'] : 1; |
2162 | 2238 | if (empty($_POST['new_base_dir']) && !empty($_POST['current_base_dir'])) |
2163 | 2239 | { |
2164 | - if ($modSettings['basedirectory_for_attachments'] != $modSettings['attachmentUploadDir'][$_POST['current_base_dir']]) |
|
2165 | - $update = (array( |
|
2240 | + if ($modSettings['basedirectory_for_attachments'] != $modSettings['attachmentUploadDir'][$_POST['current_base_dir']]) { |
|
2241 | + $update = (array( |
|
2166 | 2242 | 'basedirectory_for_attachments' => $modSettings['attachmentUploadDir'][$_POST['current_base_dir']], |
2167 | 2243 | )); |
2244 | + } |
|
2168 | 2245 | } |
2169 | 2246 | |
2170 | 2247 | if (isset($_POST['base_dir'])) |
@@ -2212,13 +2289,15 @@ discard block |
||
2212 | 2289 | |
2213 | 2290 | if (!in_array($_POST['new_base_dir'], $modSettings['attachmentUploadDir'])) |
2214 | 2291 | { |
2215 | - if (!automanage_attachments_create_directory($_POST['new_base_dir'])) |
|
2216 | - $errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_no_create']; |
|
2292 | + if (!automanage_attachments_create_directory($_POST['new_base_dir'])) { |
|
2293 | + $errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_no_create']; |
|
2294 | + } |
|
2217 | 2295 | } |
2218 | 2296 | |
2219 | 2297 | $modSettings['currentAttachmentUploadDir'] = array_search($_POST['new_base_dir'], $modSettings['attachmentUploadDir']); |
2220 | - if (!in_array($_POST['new_base_dir'], $modSettings['attachment_basedirectories'])) |
|
2221 | - $modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir']; |
|
2298 | + if (!in_array($_POST['new_base_dir'], $modSettings['attachment_basedirectories'])) { |
|
2299 | + $modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir']; |
|
2300 | + } |
|
2222 | 2301 | ksort($modSettings['attachment_basedirectories']); |
2223 | 2302 | |
2224 | 2303 | $update = (array( |
@@ -2228,11 +2307,13 @@ discard block |
||
2228 | 2307 | )); |
2229 | 2308 | } |
2230 | 2309 | |
2231 | - if (!empty($errors)) |
|
2232 | - $_SESSION['errors']['base'] = $errors; |
|
2310 | + if (!empty($errors)) { |
|
2311 | + $_SESSION['errors']['base'] = $errors; |
|
2312 | + } |
|
2233 | 2313 | |
2234 | - if (!empty($update)) |
|
2235 | - updateSettings($update); |
|
2314 | + if (!empty($update)) { |
|
2315 | + updateSettings($update); |
|
2316 | + } |
|
2236 | 2317 | |
2237 | 2318 | redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']); |
2238 | 2319 | } |
@@ -2242,13 +2323,15 @@ discard block |
||
2242 | 2323 | if (is_array($_SESSION['errors'])) |
2243 | 2324 | { |
2244 | 2325 | $errors = array(); |
2245 | - if (!empty($_SESSION['errors']['dir'])) |
|
2246 | - foreach ($_SESSION['errors']['dir'] as $error) |
|
2326 | + if (!empty($_SESSION['errors']['dir'])) { |
|
2327 | + foreach ($_SESSION['errors']['dir'] as $error) |
|
2247 | 2328 | $errors['dir'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES); |
2329 | + } |
|
2248 | 2330 | |
2249 | - if (!empty($_SESSION['errors']['base'])) |
|
2250 | - foreach ($_SESSION['errors']['base'] as $error) |
|
2331 | + if (!empty($_SESSION['errors']['base'])) { |
|
2332 | + foreach ($_SESSION['errors']['base'] as $error) |
|
2251 | 2333 | $errors['base'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES); |
2334 | + } |
|
2252 | 2335 | } |
2253 | 2336 | unset($_SESSION['errors']); |
2254 | 2337 | } |
@@ -2458,8 +2541,9 @@ discard block |
||
2458 | 2541 | foreach ($modSettings['attachmentUploadDir'] as $id => $dir) |
2459 | 2542 | { |
2460 | 2543 | // If there aren't any attachments in this directory this won't exist. |
2461 | - if (!isset($expected_files[$id])) |
|
2462 | - $expected_files[$id] = 0; |
|
2544 | + if (!isset($expected_files[$id])) { |
|
2545 | + $expected_files[$id] = 0; |
|
2546 | + } |
|
2463 | 2547 | |
2464 | 2548 | // Check if the directory is doing okay. |
2465 | 2549 | list ($status, $error, $files) = attachDirStatus($dir, $expected_files[$id]); |
@@ -2472,10 +2556,11 @@ discard block |
||
2472 | 2556 | $is_base_dir = in_array($dir, $modSettings['attachment_basedirectories']); |
2473 | 2557 | |
2474 | 2558 | // Count any sub-folders. |
2475 | - foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) |
|
2476 | - if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
2559 | + foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) { |
|
2560 | + if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
2477 | 2561 | { |
2478 | 2562 | $expected_files[$id]++; |
2563 | + } |
|
2479 | 2564 | $sub_dirs++; |
2480 | 2565 | } |
2481 | 2566 | } |
@@ -2493,8 +2578,8 @@ discard block |
||
2493 | 2578 | } |
2494 | 2579 | |
2495 | 2580 | // Just stick a new directory on at the bottom. |
2496 | - if (isset($_REQUEST['new_path'])) |
|
2497 | - $attachdirs[] = array( |
|
2581 | + if (isset($_REQUEST['new_path'])) { |
|
2582 | + $attachdirs[] = array( |
|
2498 | 2583 | 'id' => max(array_merge(array_keys($expected_files), array_keys($modSettings['attachmentUploadDir']))) + 1, |
2499 | 2584 | 'current' => false, |
2500 | 2585 | 'path' => '', |
@@ -2502,6 +2587,7 @@ discard block |
||
2502 | 2587 | 'num_files' => '', |
2503 | 2588 | 'status' => '', |
2504 | 2589 | ); |
2590 | + } |
|
2505 | 2591 | |
2506 | 2592 | return $attachdirs; |
2507 | 2593 | } |
@@ -2514,8 +2600,9 @@ discard block |
||
2514 | 2600 | { |
2515 | 2601 | global $modSettings, $txt; |
2516 | 2602 | |
2517 | - if (empty($modSettings['attachment_basedirectories'])) |
|
2518 | - return; |
|
2603 | + if (empty($modSettings['attachment_basedirectories'])) { |
|
2604 | + return; |
|
2605 | + } |
|
2519 | 2606 | |
2520 | 2607 | $basedirs = array(); |
2521 | 2608 | // Get a list of the base directories. |
@@ -2523,16 +2610,18 @@ discard block |
||
2523 | 2610 | { |
2524 | 2611 | // Loop through the attach directory array to count any sub-directories |
2525 | 2612 | $expected_dirs = 0; |
2526 | - foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) |
|
2527 | - if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
2613 | + foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) { |
|
2614 | + if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
2528 | 2615 | $expected_dirs++; |
2616 | + } |
|
2529 | 2617 | |
2530 | - if (!is_dir($dir)) |
|
2531 | - $status = 'does_not_exist'; |
|
2532 | - elseif (!is_writeable($dir)) |
|
2533 | - $status = 'not_writable'; |
|
2534 | - else |
|
2535 | - $status = 'ok'; |
|
2618 | + if (!is_dir($dir)) { |
|
2619 | + $status = 'does_not_exist'; |
|
2620 | + } elseif (!is_writeable($dir)) { |
|
2621 | + $status = 'not_writable'; |
|
2622 | + } else { |
|
2623 | + $status = 'ok'; |
|
2624 | + } |
|
2536 | 2625 | |
2537 | 2626 | $basedirs[] = array( |
2538 | 2627 | 'id' => $id, |
@@ -2543,14 +2632,15 @@ discard block |
||
2543 | 2632 | ); |
2544 | 2633 | } |
2545 | 2634 | |
2546 | - if (isset($_REQUEST['new_base_path'])) |
|
2547 | - $basedirs[] = array( |
|
2635 | + if (isset($_REQUEST['new_base_path'])) { |
|
2636 | + $basedirs[] = array( |
|
2548 | 2637 | 'id' => '', |
2549 | 2638 | 'current' => false, |
2550 | 2639 | 'path' => '<input type="text" name="new_base_dir" value="" size="40">', |
2551 | 2640 | 'num_dirs' => '', |
2552 | 2641 | 'status' => '', |
2553 | 2642 | ); |
2643 | + } |
|
2554 | 2644 | |
2555 | 2645 | return $basedirs; |
2556 | 2646 | } |
@@ -2566,10 +2656,11 @@ discard block |
||
2566 | 2656 | */ |
2567 | 2657 | function attachDirStatus($dir, $expected_files) |
2568 | 2658 | { |
2569 | - if (!is_dir($dir)) |
|
2570 | - return array('does_not_exist', true, ''); |
|
2571 | - elseif (!is_writable($dir)) |
|
2572 | - return array('not_writable', true, ''); |
|
2659 | + if (!is_dir($dir)) { |
|
2660 | + return array('does_not_exist', true, ''); |
|
2661 | + } elseif (!is_writable($dir)) { |
|
2662 | + return array('not_writable', true, ''); |
|
2663 | + } |
|
2573 | 2664 | |
2574 | 2665 | // Everything is okay so far, start to scan through the directory. |
2575 | 2666 | $num_files = 0; |
@@ -2577,22 +2668,26 @@ discard block |
||
2577 | 2668 | while ($file = $dir_handle->read()) |
2578 | 2669 | { |
2579 | 2670 | // Now do we have a real file here? |
2580 | - if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) |
|
2581 | - continue; |
|
2671 | + if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) { |
|
2672 | + continue; |
|
2673 | + } |
|
2582 | 2674 | |
2583 | 2675 | $num_files++; |
2584 | 2676 | } |
2585 | 2677 | $dir_handle->close(); |
2586 | 2678 | |
2587 | - if ($num_files < $expected_files) |
|
2588 | - return array('files_missing', true, $num_files); |
|
2679 | + if ($num_files < $expected_files) { |
|
2680 | + return array('files_missing', true, $num_files); |
|
2681 | + } |
|
2589 | 2682 | // Empty? |
2590 | - elseif ($expected_files == 0) |
|
2591 | - return array('unused', false, $num_files); |
|
2683 | + elseif ($expected_files == 0) { |
|
2684 | + return array('unused', false, $num_files); |
|
2685 | + } |
|
2592 | 2686 | // All good! |
2593 | - else |
|
2594 | - return array('ok', false, $num_files); |
|
2595 | -} |
|
2687 | + else { |
|
2688 | + return array('ok', false, $num_files); |
|
2689 | + } |
|
2690 | + } |
|
2596 | 2691 | |
2597 | 2692 | /** |
2598 | 2693 | * Maintance function to move attachments from one directory to another |
@@ -2604,10 +2699,11 @@ discard block |
||
2604 | 2699 | checkSession(); |
2605 | 2700 | |
2606 | 2701 | $modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
2607 | - if (!empty($modSettings['attachment_basedirectories'])) |
|
2608 | - $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
2609 | - else |
|
2610 | - $modSettings['basedirectory_for_attachments'] = array(); |
|
2702 | + if (!empty($modSettings['attachment_basedirectories'])) { |
|
2703 | + $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
2704 | + } else { |
|
2705 | + $modSettings['basedirectory_for_attachments'] = array(); |
|
2706 | + } |
|
2611 | 2707 | |
2612 | 2708 | $_POST['from'] = (int) $_POST['from']; |
2613 | 2709 | $_POST['auto'] = !empty($_POST['auto']) ? (int) $_POST['auto'] : 0; |
@@ -2621,11 +2717,13 @@ discard block |
||
2621 | 2717 | $total_moved = 0; |
2622 | 2718 | $total_not_moved = 0; |
2623 | 2719 | |
2624 | - if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to']))) |
|
2625 | - $results[] = $txt['attachment_transfer_no_dir']; |
|
2720 | + if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to']))) { |
|
2721 | + $results[] = $txt['attachment_transfer_no_dir']; |
|
2722 | + } |
|
2626 | 2723 | |
2627 | - if ($_POST['from'] == $_POST['to']) |
|
2628 | - $results[] = $txt['attachment_transfer_same_dir']; |
|
2724 | + if ($_POST['from'] == $_POST['to']) { |
|
2725 | + $results[] = $txt['attachment_transfer_same_dir']; |
|
2726 | + } |
|
2629 | 2727 | |
2630 | 2728 | if (empty($results)) |
2631 | 2729 | { |
@@ -2644,8 +2742,9 @@ discard block |
||
2644 | 2742 | $smcFunc['db_free_result']($request); |
2645 | 2743 | $total_progress -= $start; |
2646 | 2744 | |
2647 | - if ($total_progress < 1) |
|
2648 | - $results[] = $txt['attachment_transfer_no_find']; |
|
2745 | + if ($total_progress < 1) { |
|
2746 | + $results[] = $txt['attachment_transfer_no_find']; |
|
2747 | + } |
|
2649 | 2748 | } |
2650 | 2749 | |
2651 | 2750 | if (empty($results)) |
@@ -2661,9 +2760,9 @@ discard block |
||
2661 | 2760 | |
2662 | 2761 | automanage_attachments_check_directory(); |
2663 | 2762 | $new_dir = $modSettings['currentAttachmentUploadDir']; |
2763 | + } else { |
|
2764 | + $new_dir = $_POST['to']; |
|
2664 | 2765 | } |
2665 | - else |
|
2666 | - $new_dir = $_POST['to']; |
|
2667 | 2766 | |
2668 | 2767 | $modSettings['currentAttachmentUploadDir'] = $new_dir; |
2669 | 2768 | |
@@ -2671,8 +2770,9 @@ discard block |
||
2671 | 2770 | while ($break == false) |
2672 | 2771 | { |
2673 | 2772 | @set_time_limit(300); |
2674 | - if (function_exists('apache_reset_timeout')) |
|
2675 | - @apache_reset_timeout(); |
|
2773 | + if (function_exists('apache_reset_timeout')) { |
|
2774 | + @apache_reset_timeout(); |
|
2775 | + } |
|
2676 | 2776 | |
2677 | 2777 | // If limits are set, get the file count and size for the destination folder |
2678 | 2778 | if ($dir_files <= 0 && (!empty($modSettings['attachmentDirSizeLimit']) || !empty($modSettings['attachmentDirFileLimit']))) |
@@ -2708,13 +2808,15 @@ discard block |
||
2708 | 2808 | |
2709 | 2809 | if ($smcFunc['db_num_rows']($request) === 0) |
2710 | 2810 | { |
2711 | - if (empty($current_progress)) |
|
2712 | - $results[] = $txt['attachment_transfer_no_find']; |
|
2811 | + if (empty($current_progress)) { |
|
2812 | + $results[] = $txt['attachment_transfer_no_find']; |
|
2813 | + } |
|
2713 | 2814 | break; |
2714 | 2815 | } |
2715 | 2816 | |
2716 | - if ($smcFunc['db_num_rows']($request) < $limit) |
|
2717 | - $break = true; |
|
2817 | + if ($smcFunc['db_num_rows']($request) < $limit) { |
|
2818 | + $break = true; |
|
2819 | + } |
|
2718 | 2820 | |
2719 | 2821 | // Move them |
2720 | 2822 | $moved = array(); |
@@ -2738,8 +2840,9 @@ discard block |
||
2738 | 2840 | automanage_attachments_by_space(); |
2739 | 2841 | |
2740 | 2842 | $results[] = sprintf($txt['attachments_transferred'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]); |
2741 | - if (!empty($total_not_moved)) |
|
2742 | - $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
2843 | + if (!empty($total_not_moved)) { |
|
2844 | + $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
2845 | + } |
|
2743 | 2846 | |
2744 | 2847 | $dir_files = 0; |
2745 | 2848 | $total_moved = 0; |
@@ -2747,8 +2850,7 @@ discard block |
||
2747 | 2850 | |
2748 | 2851 | $break = false; |
2749 | 2852 | break; |
2750 | - } |
|
2751 | - else |
|
2853 | + } else |
|
2752 | 2854 | { |
2753 | 2855 | // Hmm, not in auto. Time to bail out then... |
2754 | 2856 | $results[] = $txt['attachment_transfer_no_room']; |
@@ -2763,9 +2865,9 @@ discard block |
||
2763 | 2865 | $total_moved++; |
2764 | 2866 | $current_progress++; |
2765 | 2867 | $moved[] = $row['id_attach']; |
2868 | + } else { |
|
2869 | + $total_not_moved++; |
|
2766 | 2870 | } |
2767 | - else |
|
2768 | - $total_not_moved++; |
|
2769 | 2871 | } |
2770 | 2872 | $smcFunc['db_free_result']($request); |
2771 | 2873 | |
@@ -2803,13 +2905,15 @@ discard block |
||
2803 | 2905 | } |
2804 | 2906 | |
2805 | 2907 | $results[] = sprintf($txt['attachments_transferred'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]); |
2806 | - if (!empty($total_not_moved)) |
|
2807 | - $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
2908 | + if (!empty($total_not_moved)) { |
|
2909 | + $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
2910 | + } |
|
2808 | 2911 | } |
2809 | 2912 | |
2810 | 2913 | $_SESSION['results'] = $results; |
2811 | - if (file_exists($boarddir . '/progress.php')) |
|
2812 | - unlink($boarddir . '/progress.php'); |
|
2914 | + if (file_exists($boarddir . '/progress.php')) { |
|
2915 | + unlink($boarddir . '/progress.php'); |
|
2916 | + } |
|
2813 | 2917 | |
2814 | 2918 | redirectexit('action=admin;area=manageattachments;sa=maintenance#transfer'); |
2815 | 2919 | } |
@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | * @version 2.1 Beta 4 |
16 | 16 | */ |
17 | 17 | |
18 | -if (!defined('SMF')) |
|
18 | +if (!defined('SMF')) { |
|
19 | 19 | die('No direct access...'); |
20 | +} |
|
20 | 21 | |
21 | 22 | /** |
22 | 23 | * Log an error, if the error logging is enabled. |
@@ -36,8 +37,9 @@ discard block |
||
36 | 37 | static $tried_hook = false; |
37 | 38 | |
38 | 39 | // Check if error logging is actually on. |
39 | - if (empty($modSettings['enableErrorLogging'])) |
|
40 | - return $error_message; |
|
40 | + if (empty($modSettings['enableErrorLogging'])) { |
|
41 | + return $error_message; |
|
42 | + } |
|
41 | 43 | |
42 | 44 | // Basically, htmlspecialchars it minus &. (for entities!) |
43 | 45 | $error_message = strtr($error_message, array('<' => '<', '>' => '>', '"' => '"')); |
@@ -45,22 +47,26 @@ discard block |
||
45 | 47 | |
46 | 48 | // Add a file and line to the error message? |
47 | 49 | // Don't use the actual txt entries for file and line but instead use %1$s for file and %2$s for line |
48 | - if ($file == null) |
|
49 | - $file = ''; |
|
50 | - else |
|
51 | - // Window style slashes don't play well, lets convert them to the unix style. |
|
50 | + if ($file == null) { |
|
51 | + $file = ''; |
|
52 | + } else { |
|
53 | + // Window style slashes don't play well, lets convert them to the unix style. |
|
52 | 54 | $file = str_replace('\\', '/', $file); |
55 | + } |
|
53 | 56 | |
54 | - if ($line == null) |
|
55 | - $line = 0; |
|
56 | - else |
|
57 | - $line = (int) $line; |
|
57 | + if ($line == null) { |
|
58 | + $line = 0; |
|
59 | + } else { |
|
60 | + $line = (int) $line; |
|
61 | + } |
|
58 | 62 | |
59 | 63 | // Just in case there's no id_member or IP set yet. |
60 | - if (empty($user_info['id'])) |
|
61 | - $user_info['id'] = 0; |
|
62 | - if (empty($user_info['ip'])) |
|
63 | - $user_info['ip'] = ''; |
|
64 | + if (empty($user_info['id'])) { |
|
65 | + $user_info['id'] = 0; |
|
66 | + } |
|
67 | + if (empty($user_info['ip'])) { |
|
68 | + $user_info['ip'] = ''; |
|
69 | + } |
|
64 | 70 | |
65 | 71 | // Find the best query string we can... |
66 | 72 | $query_string = empty($_SERVER['QUERY_STRING']) ? (empty($_SERVER['REQUEST_URL']) ? '' : str_replace($scripturl, '', $_SERVER['REQUEST_URL'])) : $_SERVER['QUERY_STRING']; |
@@ -69,8 +75,9 @@ discard block |
||
69 | 75 | $query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string)); |
70 | 76 | |
71 | 77 | // Just so we know what board error messages are from. |
72 | - if (isset($_POST['board']) && !isset($_GET['board'])) |
|
73 | - $query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board']; |
|
78 | + if (isset($_POST['board']) && !isset($_GET['board'])) { |
|
79 | + $query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board']; |
|
80 | + } |
|
74 | 81 | |
75 | 82 | // What types of categories do we have? |
76 | 83 | $known_error_types = array( |
@@ -132,12 +139,14 @@ discard block |
||
132 | 139 | global $txt; |
133 | 140 | |
134 | 141 | // Send the appropriate HTTP status header - set this to 0 or false if you don't want to send one at all |
135 | - if (!empty($status)) |
|
136 | - send_http_status($status); |
|
142 | + if (!empty($status)) { |
|
143 | + send_http_status($status); |
|
144 | + } |
|
137 | 145 | |
138 | 146 | // We don't have $txt yet, but that's okay... |
139 | - if (empty($txt)) |
|
140 | - die($error); |
|
147 | + if (empty($txt)) { |
|
148 | + die($error); |
|
149 | + } |
|
141 | 150 | |
142 | 151 | log_error_online($error, false); |
143 | 152 | setup_fatal_error_context($log ? log_error($error, $log) : $error); |
@@ -164,8 +173,9 @@ discard block |
||
164 | 173 | static $fatal_error_called = false; |
165 | 174 | |
166 | 175 | // Send the status header - set this to 0 or false if you don't want to send one at all |
167 | - if (!empty($status)) |
|
168 | - send_http_status($status); |
|
176 | + if (!empty($status)) { |
|
177 | + send_http_status($status); |
|
178 | + } |
|
169 | 179 | |
170 | 180 | // Try to load a theme if we don't have one. |
171 | 181 | if (empty($context['theme_loaded']) && empty($fatal_error_called)) |
@@ -175,8 +185,9 @@ discard block |
||
175 | 185 | } |
176 | 186 | |
177 | 187 | // If we have no theme stuff we can't have the language file... |
178 | - if (empty($context['theme_loaded'])) |
|
179 | - die($error); |
|
188 | + if (empty($context['theme_loaded'])) { |
|
189 | + die($error); |
|
190 | + } |
|
180 | 191 | |
181 | 192 | $reload_lang_file = true; |
182 | 193 | // Log the error in the forum's language, but don't waste the time if we aren't logging |
@@ -212,8 +223,9 @@ discard block |
||
212 | 223 | global $settings, $modSettings, $db_show_debug; |
213 | 224 | |
214 | 225 | // Ignore errors if we're ignoring them or they are strict notices from PHP 5 (which cannot be solved without breaking PHP 4.) |
215 | - if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging']))) |
|
216 | - return; |
|
226 | + if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging']))) { |
|
227 | + return; |
|
228 | + } |
|
217 | 229 | |
218 | 230 | if (strpos($file, 'eval()') !== false && !empty($settings['current_include_filename'])) |
219 | 231 | { |
@@ -221,19 +233,22 @@ discard block |
||
221 | 233 | $count = count($array); |
222 | 234 | for ($i = 0; $i < $count; $i++) |
223 | 235 | { |
224 | - if ($array[$i]['function'] != 'loadSubTemplate') |
|
225 | - continue; |
|
236 | + if ($array[$i]['function'] != 'loadSubTemplate') { |
|
237 | + continue; |
|
238 | + } |
|
226 | 239 | |
227 | 240 | // This is a bug in PHP, with eval, it seems! |
228 | - if (empty($array[$i]['args'])) |
|
229 | - $i++; |
|
241 | + if (empty($array[$i]['args'])) { |
|
242 | + $i++; |
|
243 | + } |
|
230 | 244 | break; |
231 | 245 | } |
232 | 246 | |
233 | - if (isset($array[$i]) && !empty($array[$i]['args'])) |
|
234 | - $file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)'; |
|
235 | - else |
|
236 | - $file = realpath($settings['current_include_filename']) . ' (eval?)'; |
|
247 | + if (isset($array[$i]) && !empty($array[$i]['args'])) { |
|
248 | + $file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)'; |
|
249 | + } else { |
|
250 | + $file = realpath($settings['current_include_filename']) . ' (eval?)'; |
|
251 | + } |
|
237 | 252 | } |
238 | 253 | |
239 | 254 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -242,8 +257,9 @@ discard block |
||
242 | 257 | if ($error_level % 255 != E_ERROR) |
243 | 258 | { |
244 | 259 | $temporary = ob_get_contents(); |
245 | - if (substr($temporary, -2) == '="') |
|
246 | - echo '"'; |
|
260 | + if (substr($temporary, -2) == '="') { |
|
261 | + echo '"'; |
|
262 | + } |
|
247 | 263 | } |
248 | 264 | |
249 | 265 | // Debugging! This should look like a PHP error message. |
@@ -259,23 +275,27 @@ discard block |
||
259 | 275 | call_integration_hook('integrate_output_error', array($message, $error_type, $error_level, $file, $line)); |
260 | 276 | |
261 | 277 | // Dying on these errors only causes MORE problems (blank pages!) |
262 | - if ($file == 'Unknown') |
|
263 | - return; |
|
278 | + if ($file == 'Unknown') { |
|
279 | + return; |
|
280 | + } |
|
264 | 281 | |
265 | 282 | // If this is an E_ERROR or E_USER_ERROR.... die. Violently so. |
266 | - if ($error_level % 255 == E_ERROR) |
|
267 | - obExit(false); |
|
268 | - else |
|
269 | - return; |
|
283 | + if ($error_level % 255 == E_ERROR) { |
|
284 | + obExit(false); |
|
285 | + } else { |
|
286 | + return; |
|
287 | + } |
|
270 | 288 | |
271 | 289 | // If this is an E_ERROR, E_USER_ERROR, E_WARNING, or E_USER_WARNING.... die. Violently so. |
272 | - if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) |
|
273 | - fatal_error(allowedTo('admin_forum') ? $message : $error_string, false); |
|
290 | + if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) { |
|
291 | + fatal_error(allowedTo('admin_forum') ? $message : $error_string, false); |
|
292 | + } |
|
274 | 293 | |
275 | 294 | // We should NEVER get to this point. Any fatal error MUST quit, or very bad things can happen. |
276 | - if ($error_level % 255 == E_ERROR) |
|
277 | - die('No direct access...'); |
|
278 | -} |
|
295 | + if ($error_level % 255 == E_ERROR) { |
|
296 | + die('No direct access...'); |
|
297 | + } |
|
298 | + } |
|
279 | 299 | |
280 | 300 | /** |
281 | 301 | * It is called by {@link fatal_error()} and {@link fatal_lang_error()}. |
@@ -291,24 +311,28 @@ discard block |
||
291 | 311 | |
292 | 312 | // Attempt to prevent a recursive loop. |
293 | 313 | ++$level; |
294 | - if ($level > 1) |
|
295 | - return false; |
|
314 | + if ($level > 1) { |
|
315 | + return false; |
|
316 | + } |
|
296 | 317 | |
297 | 318 | // Maybe they came from dlattach or similar? |
298 | - if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) |
|
299 | - loadTheme(); |
|
319 | + if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) { |
|
320 | + loadTheme(); |
|
321 | + } |
|
300 | 322 | |
301 | 323 | // Don't bother indexing errors mate... |
302 | 324 | $context['robot_no_index'] = true; |
303 | 325 | |
304 | - if (!isset($context['error_title'])) |
|
305 | - $context['error_title'] = $txt['error_occured']; |
|
326 | + if (!isset($context['error_title'])) { |
|
327 | + $context['error_title'] = $txt['error_occured']; |
|
328 | + } |
|
306 | 329 | $context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message; |
307 | 330 | |
308 | 331 | $context['error_code'] = isset($error_code) ? 'id="' . $error_code . '" ' : ''; |
309 | 332 | |
310 | - if (empty($context['page_title'])) |
|
311 | - $context['page_title'] = $context['error_title']; |
|
333 | + if (empty($context['page_title'])) { |
|
334 | + $context['page_title'] = $context['error_title']; |
|
335 | + } |
|
312 | 336 | |
313 | 337 | loadTemplate('Errors'); |
314 | 338 | $context['sub_template'] = 'fatal_error'; |
@@ -316,23 +340,26 @@ discard block |
||
316 | 340 | // If this is SSI, what do they want us to do? |
317 | 341 | if (SMF == 'SSI') |
318 | 342 | { |
319 | - if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) |
|
320 | - $ssi_on_error_method(); |
|
321 | - elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) |
|
322 | - loadSubTemplate('fatal_error'); |
|
343 | + if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) { |
|
344 | + $ssi_on_error_method(); |
|
345 | + } elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) { |
|
346 | + loadSubTemplate('fatal_error'); |
|
347 | + } |
|
323 | 348 | |
324 | 349 | // No layers? |
325 | - if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) |
|
326 | - exit; |
|
350 | + if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) { |
|
351 | + exit; |
|
352 | + } |
|
327 | 353 | } |
328 | 354 | // Alternatively from the cron call? |
329 | 355 | elseif (SMF == 'BACKGROUND') |
330 | 356 | { |
331 | 357 | // We can't rely on even having language files available. |
332 | - if (defined('FROM_CLI') && FROM_CLI) |
|
333 | - echo 'cron error: ', $context['error_message']; |
|
334 | - else |
|
335 | - echo 'An error occurred. More information may be available in your logs.'; |
|
358 | + if (defined('FROM_CLI') && FROM_CLI) { |
|
359 | + echo 'cron error: ', $context['error_message']; |
|
360 | + } else { |
|
361 | + echo 'An error occurred. More information may be available in your logs.'; |
|
362 | + } |
|
336 | 363 | exit; |
337 | 364 | } |
338 | 365 | |
@@ -360,8 +387,8 @@ discard block |
||
360 | 387 | |
361 | 388 | set_fatal_error_headers(); |
362 | 389 | |
363 | - if (!empty($maintenance)) |
|
364 | - echo '<!DOCTYPE html> |
|
390 | + if (!empty($maintenance)) { |
|
391 | + echo '<!DOCTYPE html> |
|
365 | 392 | <html> |
366 | 393 | <head> |
367 | 394 | <meta name="robots" content="noindex"> |
@@ -372,6 +399,7 @@ discard block |
||
372 | 399 | ', $mmessage, ' |
373 | 400 | </body> |
374 | 401 | </html>'; |
402 | + } |
|
375 | 403 | |
376 | 404 | die(); |
377 | 405 | } |
@@ -393,15 +421,17 @@ discard block |
||
393 | 421 | // For our purposes, we're gonna want this on if at all possible. |
394 | 422 | $modSettings['cache_enable'] = '1'; |
395 | 423 | |
396 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
397 | - $db_last_error = max($db_last_error, $temp); |
|
424 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
425 | + $db_last_error = max($db_last_error, $temp); |
|
426 | + } |
|
398 | 427 | |
399 | 428 | if ($db_last_error < time() - 3600 * 24 * 3 && empty($maintenance) && !empty($db_error_send)) |
400 | 429 | { |
401 | 430 | // Avoid writing to the Settings.php file if at all possible; use shared memory instead. |
402 | 431 | cache_put_data('db_last_error', time(), 600); |
403 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
404 | - logLastDatabaseError(); |
|
432 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
433 | + logLastDatabaseError(); |
|
434 | + } |
|
405 | 435 | |
406 | 436 | // Language files aren't loaded yet :(. |
407 | 437 | $db_error = @$smcFunc['db_error']($db_connection); |
@@ -482,12 +512,14 @@ discard block |
||
482 | 512 | global $smcFunc, $user_info, $modSettings; |
483 | 513 | |
484 | 514 | // Don't bother if Who's Online is disabled. |
485 | - if (empty($modSettings['who_enabled'])) |
|
486 | - return; |
|
515 | + if (empty($modSettings['who_enabled'])) { |
|
516 | + return; |
|
517 | + } |
|
487 | 518 | |
488 | 519 | // Maybe they came from SSI or similar where sessions are not recorded? |
489 | - if (SMF == 'SSI' || SMF == 'BACKGROUND') |
|
490 | - return; |
|
520 | + if (SMF == 'SSI' || SMF == 'BACKGROUND') { |
|
521 | + return; |
|
522 | + } |
|
491 | 523 | |
492 | 524 | $session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id(); |
493 | 525 | |
@@ -513,8 +545,9 @@ discard block |
||
513 | 545 | $url = $smcFunc['json_decode']($url, true); |
514 | 546 | $url['error'] = $error; |
515 | 547 | |
516 | - if (!empty($sprintf)) |
|
517 | - $url['error_params'] = $sprintf; |
|
548 | + if (!empty($sprintf)) { |
|
549 | + $url['error_params'] = $sprintf; |
|
550 | + } |
|
518 | 551 | |
519 | 552 | $smcFunc['db_query']('', ' |
520 | 553 | UPDATE {db_prefix}log_online |
@@ -545,10 +578,11 @@ discard block |
||
545 | 578 | |
546 | 579 | $protocol = preg_match('~HTTP/1\.[01]~i', $_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'; |
547 | 580 | |
548 | - if (!isset($statuses[$code])) |
|
549 | - header($protocol . ' 500 Internal Server Error'); |
|
550 | - else |
|
551 | - header($protocol . ' ' . $code . ' ' . $statuses[$code]); |
|
552 | -} |
|
581 | + if (!isset($statuses[$code])) { |
|
582 | + header($protocol . ' 500 Internal Server Error'); |
|
583 | + } else { |
|
584 | + header($protocol . ' ' . $code . ' ' . $statuses[$code]); |
|
585 | + } |
|
586 | + } |
|
553 | 587 | |
554 | 588 | ?> |
555 | 589 | \ No newline at end of file |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 4 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * Show the calendar. |
@@ -47,12 +48,14 @@ discard block |
||
47 | 48 | 'post' => 'CalendarPost', |
48 | 49 | ); |
49 | 50 | |
50 | - if (isset($_GET['sa']) && isset($subActions[$_GET['sa']])) |
|
51 | - return call_helper($subActions[$_GET['sa']]); |
|
51 | + if (isset($_GET['sa']) && isset($subActions[$_GET['sa']])) { |
|
52 | + return call_helper($subActions[$_GET['sa']]); |
|
53 | + } |
|
52 | 54 | |
53 | 55 | // You can't do anything if the calendar is off. |
54 | - if (empty($modSettings['cal_enabled'])) |
|
55 | - fatal_lang_error('calendar_off', false); |
|
56 | + if (empty($modSettings['cal_enabled'])) { |
|
57 | + fatal_lang_error('calendar_off', false); |
|
58 | + } |
|
56 | 59 | |
57 | 60 | // This is gonna be needed... |
58 | 61 | loadTemplate('Calendar'); |
@@ -88,22 +91,25 @@ discard block |
||
88 | 91 | $context['page_title'] = $txt['calendar']; |
89 | 92 | |
90 | 93 | // Ensure a default view is defined |
91 | - if (empty($modSettings['calendar_default_view'])) |
|
92 | - $modSettings['calendar_default_view'] = 'viewlist'; |
|
94 | + if (empty($modSettings['calendar_default_view'])) { |
|
95 | + $modSettings['calendar_default_view'] = 'viewlist'; |
|
96 | + } |
|
93 | 97 | |
94 | 98 | // What view do we want? |
95 | - if (isset($_GET['viewweek'])) |
|
96 | - $context['calendar_view'] = 'viewweek'; |
|
97 | - elseif (isset($_GET['viewmonth'])) |
|
98 | - $context['calendar_view'] = 'viewmonth'; |
|
99 | - elseif (isset($_GET['viewlist'])) |
|
100 | - $context['calendar_view'] = 'viewlist'; |
|
101 | - else |
|
102 | - $context['calendar_view'] = $modSettings['calendar_default_view']; |
|
99 | + if (isset($_GET['viewweek'])) { |
|
100 | + $context['calendar_view'] = 'viewweek'; |
|
101 | + } elseif (isset($_GET['viewmonth'])) { |
|
102 | + $context['calendar_view'] = 'viewmonth'; |
|
103 | + } elseif (isset($_GET['viewlist'])) { |
|
104 | + $context['calendar_view'] = 'viewlist'; |
|
105 | + } else { |
|
106 | + $context['calendar_view'] = $modSettings['calendar_default_view']; |
|
107 | + } |
|
103 | 108 | |
104 | 109 | // Don't let search engines index the non-default calendar pages |
105 | - if ($context['calendar_view'] !== $modSettings['calendar_default_view']) |
|
106 | - $context['robot_no_index'] = true; |
|
110 | + if ($context['calendar_view'] !== $modSettings['calendar_default_view']) { |
|
111 | + $context['robot_no_index'] = true; |
|
112 | + } |
|
107 | 113 | |
108 | 114 | // Get the current day of month... |
109 | 115 | require_once($sourcedir . '/Subs-Calendar.php'); |
@@ -164,16 +170,19 @@ discard block |
||
164 | 170 | ); |
165 | 171 | |
166 | 172 | // Make sure the year and month are in valid ranges. |
167 | - if ($curPage['month'] < 1 || $curPage['month'] > 12) |
|
168 | - fatal_lang_error('invalid_month', false); |
|
169 | - if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear']) |
|
170 | - fatal_lang_error('invalid_year', false); |
|
173 | + if ($curPage['month'] < 1 || $curPage['month'] > 12) { |
|
174 | + fatal_lang_error('invalid_month', false); |
|
175 | + } |
|
176 | + if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear']) { |
|
177 | + fatal_lang_error('invalid_year', false); |
|
178 | + } |
|
171 | 179 | // If we have a day clean that too. |
172 | 180 | if ($context['calendar_view'] != 'viewmonth') |
173 | 181 | { |
174 | 182 | $isValid = checkdate($curPage['month'], $curPage['day'], $curPage['year']); |
175 | - if (!$isValid) |
|
176 | - fatal_lang_error('invalid_day', false); |
|
183 | + if (!$isValid) { |
|
184 | + fatal_lang_error('invalid_day', false); |
|
185 | + } |
|
177 | 186 | } |
178 | 187 | |
179 | 188 | // Load all the context information needed to show the calendar grid. |
@@ -195,23 +204,26 @@ discard block |
||
195 | 204 | ); |
196 | 205 | |
197 | 206 | // Load up the main view. |
198 | - if ($context['calendar_view'] == 'viewlist') |
|
199 | - $context['calendar_grid_main'] = getCalendarList($curPage['start_date'], $curPage['end_date'], $calendarOptions); |
|
200 | - elseif ($context['calendar_view'] == 'viewweek') |
|
201 | - $context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions); |
|
202 | - else |
|
203 | - $context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions); |
|
207 | + if ($context['calendar_view'] == 'viewlist') { |
|
208 | + $context['calendar_grid_main'] = getCalendarList($curPage['start_date'], $curPage['end_date'], $calendarOptions); |
|
209 | + } elseif ($context['calendar_view'] == 'viewweek') { |
|
210 | + $context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions); |
|
211 | + } else { |
|
212 | + $context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions); |
|
213 | + } |
|
204 | 214 | |
205 | 215 | // Load up the previous and next months. |
206 | 216 | $context['calendar_grid_current'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions); |
207 | 217 | |
208 | 218 | // Only show previous month if it isn't pre-January of the min-year |
209 | - if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1) |
|
210 | - $context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true); |
|
219 | + if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1) { |
|
220 | + $context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true); |
|
221 | + } |
|
211 | 222 | |
212 | 223 | // Only show next month if it isn't post-December of the max-year |
213 | - if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12) |
|
214 | - $context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions); |
|
224 | + if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12) { |
|
225 | + $context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions); |
|
226 | + } |
|
215 | 227 | |
216 | 228 | // Basic template stuff. |
217 | 229 | $context['allow_calendar_event'] = allowedTo('calendar_post'); |
@@ -231,8 +243,9 @@ discard block |
||
231 | 243 | $context['blocks_disabled'] = !empty($modSettings['cal_disable_prev_next']) ? 1 : 0; |
232 | 244 | |
233 | 245 | // Set the page title to mention the month or week, too |
234 | - if ($context['calendar_view'] != 'viewlist') |
|
235 | - $context['page_title'] .= ' - ' . ($context['calendar_view'] == 'viewweek' ? $context['calendar_grid_main']['week_title'] : $txt['months'][$context['current_month']] . ' ' . $context['current_year']); |
|
246 | + if ($context['calendar_view'] != 'viewlist') { |
|
247 | + $context['page_title'] .= ' - ' . ($context['calendar_view'] == 'viewweek' ? $context['calendar_grid_main']['week_title'] : $txt['months'][$context['current_month']] . ' ' . $context['current_year']); |
|
248 | + } |
|
236 | 249 | |
237 | 250 | // Load up the linktree! |
238 | 251 | $context['linktree'][] = array( |
@@ -245,17 +258,19 @@ discard block |
||
245 | 258 | 'name' => $txt['months'][$context['current_month']] . ' ' . $context['current_year'] |
246 | 259 | ); |
247 | 260 | // If applicable, add the current week to the linktree. |
248 | - if ($context['calendar_view'] == 'viewweek') |
|
249 | - $context['linktree'][] = array( |
|
261 | + if ($context['calendar_view'] == 'viewweek') { |
|
262 | + $context['linktree'][] = array( |
|
250 | 263 | 'url' => $scripturl . '?action=calendar;viewweek;year=' . $context['current_year'] . ';month=' . $context['current_month'] . ';day=' . $context['current_day'], |
251 | 264 | 'name' => $context['calendar_grid_main']['week_title'], |
252 | 265 | ); |
266 | + } |
|
253 | 267 | |
254 | 268 | // Build the calendar button array. |
255 | 269 | $context['calendar_buttons'] = array(); |
256 | 270 | |
257 | - if ($context['can_post']) |
|
258 | - $context['calendar_buttons']['post_event'] = array('text' => 'calendar_post_event', 'image' => 'calendarpe.png', 'url' => $scripturl . '?action=calendar;sa=post;month=' . $context['current_month'] . ';year=' . $context['current_year'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
271 | + if ($context['can_post']) { |
|
272 | + $context['calendar_buttons']['post_event'] = array('text' => 'calendar_post_event', 'image' => 'calendarpe.png', 'url' => $scripturl . '?action=calendar;sa=post;month=' . $context['current_month'] . ';year=' . $context['current_year'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
273 | + } |
|
259 | 274 | |
260 | 275 | // Allow mods to add additional buttons here |
261 | 276 | call_integration_hook('integrate_calendar_buttons'); |
@@ -284,14 +299,16 @@ discard block |
||
284 | 299 | require_once($sourcedir . '/Subs.php'); |
285 | 300 | |
286 | 301 | // Cast this for safety... |
287 | - if (isset($_REQUEST['eventid'])) |
|
288 | - $_REQUEST['eventid'] = (int) $_REQUEST['eventid']; |
|
302 | + if (isset($_REQUEST['eventid'])) { |
|
303 | + $_REQUEST['eventid'] = (int) $_REQUEST['eventid']; |
|
304 | + } |
|
289 | 305 | |
290 | 306 | // We want a fairly compact version of the time, but as close as possible to the user's settings. |
291 | - if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
292 | - $time_string = '%k:%M'; |
|
293 | - else |
|
294 | - $time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
307 | + if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
308 | + $time_string = '%k:%M'; |
|
309 | + } else { |
|
310 | + $time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
311 | + } |
|
295 | 312 | |
296 | 313 | $js_time_string = str_replace( |
297 | 314 | array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r', '%R', '%S', '%T', '%X'), |
@@ -305,12 +322,14 @@ discard block |
||
305 | 322 | checkSession(); |
306 | 323 | |
307 | 324 | // Validate the post... |
308 | - if (!isset($_POST['link_to_board'])) |
|
309 | - validateEventPost(); |
|
325 | + if (!isset($_POST['link_to_board'])) { |
|
326 | + validateEventPost(); |
|
327 | + } |
|
310 | 328 | |
311 | 329 | // If you're not allowed to edit any events, you have to be the poster. |
312 | - if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any')) |
|
313 | - isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any')); |
|
330 | + if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any')) { |
|
331 | + isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any')); |
|
332 | + } |
|
314 | 333 | |
315 | 334 | // New - and directing? |
316 | 335 | if (isset($_POST['link_to_board']) || empty($modSettings['cal_allow_unlinked'])) |
@@ -333,8 +352,9 @@ discard block |
||
333 | 352 | } |
334 | 353 | |
335 | 354 | // Deleting... |
336 | - elseif (isset($_REQUEST['deleteevent'])) |
|
337 | - removeEvent($_REQUEST['eventid']); |
|
355 | + elseif (isset($_REQUEST['deleteevent'])) { |
|
356 | + removeEvent($_REQUEST['eventid']); |
|
357 | + } |
|
338 | 358 | |
339 | 359 | // ... or just update it? |
340 | 360 | else |
@@ -357,15 +377,13 @@ discard block |
||
357 | 377 | $year = $d['year']; |
358 | 378 | $month = $d['month']; |
359 | 379 | $day = $d['day']; |
360 | - } |
|
361 | - elseif (isset($_POST['start_datetime'])) |
|
380 | + } elseif (isset($_POST['start_datetime'])) |
|
362 | 381 | { |
363 | 382 | $d = date_parse($_POST['start_datetime']); |
364 | 383 | $year = $d['year']; |
365 | 384 | $month = $d['month']; |
366 | 385 | $day = $d['day']; |
367 | - } |
|
368 | - else |
|
386 | + } else |
|
369 | 387 | { |
370 | 388 | $today = getdate(); |
371 | 389 | $year = isset($_POST['year']) ? $_POST['year'] : $today['year']; |
@@ -399,13 +417,13 @@ discard block |
||
399 | 417 | $context['event'] = array_merge($context['event'], $eventDatetimes); |
400 | 418 | |
401 | 419 | $context['event']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['event']['month'] == 12 ? 1 : $context['event']['month'] + 1, 0, $context['event']['month'] == 12 ? $context['event']['year'] + 1 : $context['event']['year'])); |
402 | - } |
|
403 | - else |
|
420 | + } else |
|
404 | 421 | { |
405 | 422 | $context['event'] = getEventProperties($_REQUEST['eventid']); |
406 | 423 | |
407 | - if ($context['event'] === false) |
|
408 | - fatal_lang_error('no_access', false); |
|
424 | + if ($context['event'] === false) { |
|
425 | + fatal_lang_error('no_access', false); |
|
426 | + } |
|
409 | 427 | |
410 | 428 | // If it has a board, then they should be editing it within the topic. |
411 | 429 | if (!empty($context['event']['topic']['id']) && !empty($context['event']['topic']['first_msg'])) |
@@ -416,10 +434,11 @@ discard block |
||
416 | 434 | } |
417 | 435 | |
418 | 436 | // Make sure the user is allowed to edit this event. |
419 | - if ($context['event']['member'] != $user_info['id']) |
|
420 | - isAllowedTo('calendar_edit_any'); |
|
421 | - elseif (!allowedTo('calendar_edit_any')) |
|
422 | - isAllowedTo('calendar_edit_own'); |
|
437 | + if ($context['event']['member'] != $user_info['id']) { |
|
438 | + isAllowedTo('calendar_edit_any'); |
|
439 | + } elseif (!allowedTo('calendar_edit_any')) { |
|
440 | + isAllowedTo('calendar_edit_own'); |
|
441 | + } |
|
423 | 442 | } |
424 | 443 | |
425 | 444 | // An all day event? Set up some nice defaults in case the user wants to change that |
@@ -453,8 +472,7 @@ discard block |
||
453 | 472 | { |
454 | 473 | // You can post new events but can't link them to anything... |
455 | 474 | $context['event']['categories'] = array(); |
456 | - } |
|
457 | - else |
|
475 | + } else |
|
458 | 476 | { |
459 | 477 | // Load the list of boards and categories in the context. |
460 | 478 | require_once($sourcedir . '/Subs-MessageIndex.php'); |
@@ -541,12 +559,14 @@ discard block |
||
541 | 559 | global $smcFunc, $sourcedir, $forum_version, $modSettings, $webmaster_email, $mbname; |
542 | 560 | |
543 | 561 | // You can't export if the calendar export feature is off. |
544 | - if (empty($modSettings['cal_export'])) |
|
545 | - fatal_lang_error('calendar_export_off', false); |
|
562 | + if (empty($modSettings['cal_export'])) { |
|
563 | + fatal_lang_error('calendar_export_off', false); |
|
564 | + } |
|
546 | 565 | |
547 | 566 | // Goes without saying that this is required. |
548 | - if (!isset($_REQUEST['eventid'])) |
|
549 | - fatal_lang_error('no_access', false); |
|
567 | + if (!isset($_REQUEST['eventid'])) { |
|
568 | + fatal_lang_error('no_access', false); |
|
569 | + } |
|
550 | 570 | |
551 | 571 | // This is kinda wanted. |
552 | 572 | require_once($sourcedir . '/Subs-Calendar.php'); |
@@ -554,15 +574,17 @@ discard block |
||
554 | 574 | // Load up the event in question and check it exists. |
555 | 575 | $event = getEventProperties($_REQUEST['eventid']); |
556 | 576 | |
557 | - if ($event === false) |
|
558 | - fatal_lang_error('no_access', false); |
|
577 | + if ($event === false) { |
|
578 | + fatal_lang_error('no_access', false); |
|
579 | + } |
|
559 | 580 | |
560 | 581 | // Check the title isn't too long - iCal requires some formatting if so. |
561 | 582 | $title = str_split($event['title'], 30); |
562 | 583 | foreach ($title as $id => $line) |
563 | 584 | { |
564 | - if ($id != 0) |
|
565 | - $title[$id] = ' ' . $title[$id]; |
|
585 | + if ($id != 0) { |
|
586 | + $title[$id] = ' ' . $title[$id]; |
|
587 | + } |
|
566 | 588 | $title[$id] .= "\n"; |
567 | 589 | } |
568 | 590 | |
@@ -575,8 +597,7 @@ discard block |
||
575 | 597 | { |
576 | 598 | $datestart = date_format($start_date, 'Ymd\THis'); |
577 | 599 | $dateend = date_format($end_date, 'Ymd\THis'); |
578 | - } |
|
579 | - else |
|
600 | + } else |
|
580 | 601 | { |
581 | 602 | $datestart = date_format($start_date, 'Ymd'); |
582 | 603 | |
@@ -597,15 +618,18 @@ discard block |
||
597 | 618 | $filecontents .= 'DTSTART' . (!empty($event['start_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $datestart . "\n"; |
598 | 619 | |
599 | 620 | // event has a duration |
600 | - if ($event['start_iso_gmdate'] != $event['end_iso_gmdate']) |
|
601 | - $filecontents .= 'DTEND' . (!empty($event['end_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $dateend . "\n"; |
|
621 | + if ($event['start_iso_gmdate'] != $event['end_iso_gmdate']) { |
|
622 | + $filecontents .= 'DTEND' . (!empty($event['end_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $dateend . "\n"; |
|
623 | + } |
|
602 | 624 | |
603 | 625 | // event has changed? advance the sequence for this UID |
604 | - if ($event['sequence'] > 0) |
|
605 | - $filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n"; |
|
626 | + if ($event['sequence'] > 0) { |
|
627 | + $filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n"; |
|
628 | + } |
|
606 | 629 | |
607 | - if (!empty($event['location'])) |
|
608 | - $filecontents .= 'LOCATION:' . str_replace(',', '\,', $event['location']) . "\n"; |
|
630 | + if (!empty($event['location'])) { |
|
631 | + $filecontents .= 'LOCATION:' . str_replace(',', '\,', $event['location']) . "\n"; |
|
632 | + } |
|
609 | 633 | |
610 | 634 | $filecontents .= 'SUMMARY:' . implode('', $title); |
611 | 635 | $filecontents .= 'UID:' . $event['eventid'] . '@' . str_replace(' ', '-', $mbname) . "\n"; |
@@ -614,23 +638,26 @@ discard block |
||
614 | 638 | |
615 | 639 | // Send some standard headers. |
616 | 640 | ob_end_clean(); |
617 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
618 | - @ob_start('ob_gzhandler'); |
|
619 | - else |
|
620 | - ob_start(); |
|
641 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
642 | + @ob_start('ob_gzhandler'); |
|
643 | + } else { |
|
644 | + ob_start(); |
|
645 | + } |
|
621 | 646 | |
622 | 647 | // Send the file headers |
623 | 648 | header('Pragma: '); |
624 | 649 | header('Cache-Control: no-cache'); |
625 | - if (!isBrowser('gecko')) |
|
626 | - header('Content-Transfer-Encoding: binary'); |
|
650 | + if (!isBrowser('gecko')) { |
|
651 | + header('Content-Transfer-Encoding: binary'); |
|
652 | + } |
|
627 | 653 | header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT'); |
628 | 654 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . 'GMT'); |
629 | 655 | header('Accept-Ranges: bytes'); |
630 | 656 | header('Connection: close'); |
631 | 657 | header('Content-Disposition: attachment; filename="' . $event['title'] . '.ics"'); |
632 | - if (empty($modSettings['enableCompressedOutput'])) |
|
633 | - header('Content-Length: ' . $smcFunc['strlen']($filecontents)); |
|
658 | + if (empty($modSettings['enableCompressedOutput'])) { |
|
659 | + header('Content-Length: ' . $smcFunc['strlen']($filecontents)); |
|
660 | + } |
|
634 | 661 | |
635 | 662 | // This is a calendar item! |
636 | 663 | header('Content-Type: text/calendar'); |
@@ -669,20 +696,17 @@ discard block |
||
669 | 696 | $context['sub_template'] = 'bcd'; |
670 | 697 | $context['linktree'][] = array('url' => $scripturl . '?action=clock;bcd', 'name' => 'BCD'); |
671 | 698 | $context['clockicons'] = $smcFunc['json_decode'](base64_decode('eyJoMSI6WzIsMV0sImgyIjpbOCw0LDIsMV0sIm0xIjpbNCwyLDFdLCJtMiI6WzgsNCwyLDFdLCJzMSI6WzQsMiwxXSwiczIiOls4LDQsMiwxXX0='), true); |
672 | - } |
|
673 | - elseif (!$omfg && !isset($_REQUEST['time'])) |
|
699 | + } elseif (!$omfg && !isset($_REQUEST['time'])) |
|
674 | 700 | { |
675 | 701 | $context['sub_template'] = 'hms'; |
676 | 702 | $context['linktree'][] = array('url' => $scripturl . '?action=clock', 'name' => 'Binary'); |
677 | 703 | $context['clockicons'] = $smcFunc['json_decode'](base64_decode('eyJoIjpbMTYsOCw0LDIsMV0sIm0iOlszMiwxNiw4LDQsMiwxXSwicyI6WzMyLDE2LDgsNCwyLDFdfQ'), true); |
678 | - } |
|
679 | - elseif ($omfg) |
|
704 | + } elseif ($omfg) |
|
680 | 705 | { |
681 | 706 | $context['sub_template'] = 'omfg'; |
682 | 707 | $context['linktree'][] = array('url' => $scripturl . '?action=clock;omfg', 'name' => 'OMFG'); |
683 | 708 | $context['clockicons'] = $smcFunc['json_decode'](base64_decode('eyJ5ZWFyIjpbNjQsMzIsMTYsOCw0LDIsMV0sIm1vbnRoIjpbOCw0LDIsMV0sImRheSI6WzE2LDgsNCwyLDFdLCJob3VyIjpbMTYsOCw0LDIsMV0sIm1pbiI6WzMyLDE2LDgsNCwyLDFdLCJzZWMiOlszMiwxNiw4LDQsMiwxXX0='), true); |
684 | - } |
|
685 | - elseif (isset($_REQUEST['time'])) |
|
709 | + } elseif (isset($_REQUEST['time'])) |
|
686 | 710 | { |
687 | 711 | $context['sub_template'] = 'thetime'; |
688 | 712 | $time = getdate($_REQUEST['time'] == 'now' ? time() : (int) $_REQUEST['time']); |
@@ -736,12 +760,13 @@ discard block |
||
736 | 760 | ), |
737 | 761 | ); |
738 | 762 | |
739 | - foreach ($context['clockicons'] as $t => $vs) |
|
740 | - foreach ($vs as $v => $dumb) |
|
763 | + foreach ($context['clockicons'] as $t => $vs) { |
|
764 | + foreach ($vs as $v => $dumb) |
|
741 | 765 | { |
742 | 766 | if ($$t >= $v) |
743 | 767 | { |
744 | 768 | $$t -= $v; |
769 | + } |
|
745 | 770 | $context['clockicons'][$t][$v] = true; |
746 | 771 | } |
747 | 772 | } |
@@ -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 = $smcFunc['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. |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -34,8 +35,8 @@ discard block |
||
34 | 35 | global $smcFunc; |
35 | 36 | |
36 | 37 | // Map some database specific functions, only do this once. |
37 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
38 | - $smcFunc += array( |
|
38 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
39 | + $smcFunc += array( |
|
39 | 40 | 'db_query' => 'smf_db_query', |
40 | 41 | 'db_quote' => 'smf_db_quote', |
41 | 42 | 'db_insert' => 'smf_db_insert', |
@@ -62,11 +63,13 @@ discard block |
||
62 | 63 | 'db_ping' => 'pg_ping', |
63 | 64 | 'db_fetch_all' => 'smf_db_fetch_all', |
64 | 65 | ); |
66 | + } |
|
65 | 67 | |
66 | - if (!empty($db_options['persist'])) |
|
67 | - $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
68 | - else |
|
69 | - $connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
68 | + if (!empty($db_options['persist'])) { |
|
69 | + $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
70 | + } else { |
|
71 | + $connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
72 | + } |
|
70 | 73 | |
71 | 74 | // Something's wrong, show an error if its fatal (which we assume it is) |
72 | 75 | if (!$connection) |
@@ -74,8 +77,7 @@ discard block |
||
74 | 77 | if (!empty($db_options['non_fatal'])) |
75 | 78 | { |
76 | 79 | return null; |
77 | - } |
|
78 | - else |
|
80 | + } else |
|
79 | 81 | { |
80 | 82 | display_db_error(); |
81 | 83 | } |
@@ -126,31 +128,38 @@ discard block |
||
126 | 128 | |
127 | 129 | list ($values, $connection) = $db_callback; |
128 | 130 | |
129 | - if ($matches[1] === 'db_prefix') |
|
130 | - return $db_prefix; |
|
131 | + if ($matches[1] === 'db_prefix') { |
|
132 | + return $db_prefix; |
|
133 | + } |
|
131 | 134 | |
132 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
133 | - return $user_info[$matches[1]]; |
|
135 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
136 | + return $user_info[$matches[1]]; |
|
137 | + } |
|
134 | 138 | |
135 | - if ($matches[1] === 'empty') |
|
136 | - return '\'\''; |
|
139 | + if ($matches[1] === 'empty') { |
|
140 | + return '\'\''; |
|
141 | + } |
|
137 | 142 | |
138 | - if (!isset($matches[2])) |
|
139 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
143 | + if (!isset($matches[2])) { |
|
144 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
145 | + } |
|
140 | 146 | |
141 | - if ($matches[1] === 'literal') |
|
142 | - return '\'' . pg_escape_string($matches[2]) . '\''; |
|
147 | + if ($matches[1] === 'literal') { |
|
148 | + return '\'' . pg_escape_string($matches[2]) . '\''; |
|
149 | + } |
|
143 | 150 | |
144 | - if (!isset($values[$matches[2]])) |
|
145 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
151 | + if (!isset($values[$matches[2]])) { |
|
152 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
153 | + } |
|
146 | 154 | |
147 | 155 | $replacement = $values[$matches[2]]; |
148 | 156 | |
149 | 157 | switch ($matches[1]) |
150 | 158 | { |
151 | 159 | case 'int': |
152 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
153 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
160 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
161 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
162 | + } |
|
154 | 163 | return (string) (int) $replacement; |
155 | 164 | break; |
156 | 165 | |
@@ -162,65 +171,73 @@ discard block |
||
162 | 171 | case 'array_int': |
163 | 172 | if (is_array($replacement)) |
164 | 173 | { |
165 | - if (empty($replacement)) |
|
166 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
174 | + if (empty($replacement)) { |
|
175 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
176 | + } |
|
167 | 177 | |
168 | 178 | foreach ($replacement as $key => $value) |
169 | 179 | { |
170 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
171 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
180 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
181 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
182 | + } |
|
172 | 183 | |
173 | 184 | $replacement[$key] = (string) (int) $value; |
174 | 185 | } |
175 | 186 | |
176 | 187 | return implode(', ', $replacement); |
188 | + } else { |
|
189 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
177 | 190 | } |
178 | - else |
|
179 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
180 | 191 | |
181 | 192 | break; |
182 | 193 | |
183 | 194 | case 'array_string': |
184 | 195 | if (is_array($replacement)) |
185 | 196 | { |
186 | - if (empty($replacement)) |
|
187 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
197 | + if (empty($replacement)) { |
|
198 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
199 | + } |
|
188 | 200 | |
189 | - foreach ($replacement as $key => $value) |
|
190 | - $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
201 | + foreach ($replacement as $key => $value) { |
|
202 | + $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
203 | + } |
|
191 | 204 | |
192 | 205 | return implode(', ', $replacement); |
206 | + } else { |
|
207 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
193 | 208 | } |
194 | - else |
|
195 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
196 | 209 | break; |
197 | 210 | |
198 | 211 | case 'date': |
199 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
200 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
201 | - else |
|
202 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
212 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
213 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
214 | + } else { |
|
215 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
216 | + } |
|
203 | 217 | break; |
204 | 218 | |
205 | 219 | case 'time': |
206 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
207 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
208 | - else |
|
209 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
220 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
221 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
222 | + } else { |
|
223 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
224 | + } |
|
210 | 225 | break; |
211 | 226 | |
212 | 227 | case 'datetime': |
213 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
214 | - return 'to_timestamp('. |
|
228 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
229 | + return 'to_timestamp('. |
|
215 | 230 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
216 | 231 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
217 | - else |
|
218 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
232 | + } else { |
|
233 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
234 | + } |
|
219 | 235 | break; |
220 | 236 | |
221 | 237 | case 'float': |
222 | - if (!is_numeric($replacement)) |
|
223 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
238 | + if (!is_numeric($replacement)) { |
|
239 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
240 | + } |
|
224 | 241 | return (string) (float) $replacement; |
225 | 242 | break; |
226 | 243 | |
@@ -233,31 +250,36 @@ discard block |
||
233 | 250 | break; |
234 | 251 | |
235 | 252 | case 'inet': |
236 | - if ($replacement == 'null' || $replacement == '') |
|
237 | - return 'null'; |
|
238 | - if (inet_pton($replacement) === false) |
|
239 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
253 | + if ($replacement == 'null' || $replacement == '') { |
|
254 | + return 'null'; |
|
255 | + } |
|
256 | + if (inet_pton($replacement) === false) { |
|
257 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
258 | + } |
|
240 | 259 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
241 | 260 | |
242 | 261 | case 'array_inet': |
243 | 262 | if (is_array($replacement)) |
244 | 263 | { |
245 | - if (empty($replacement)) |
|
246 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
264 | + if (empty($replacement)) { |
|
265 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
266 | + } |
|
247 | 267 | |
248 | 268 | foreach ($replacement as $key => $value) |
249 | 269 | { |
250 | - if ($replacement == 'null' || $replacement == '') |
|
251 | - $replacement[$key] = 'null'; |
|
252 | - if (!isValidIP($value)) |
|
253 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
270 | + if ($replacement == 'null' || $replacement == '') { |
|
271 | + $replacement[$key] = 'null'; |
|
272 | + } |
|
273 | + if (!isValidIP($value)) { |
|
274 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
275 | + } |
|
254 | 276 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
255 | 277 | } |
256 | 278 | |
257 | 279 | return implode(', ', $replacement); |
280 | + } else { |
|
281 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
258 | 282 | } |
259 | - else |
|
260 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
261 | 283 | break; |
262 | 284 | |
263 | 285 | default: |
@@ -351,14 +373,16 @@ discard block |
||
351 | 373 | ), |
352 | 374 | ); |
353 | 375 | |
354 | - if (isset($replacements[$identifier])) |
|
355 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
376 | + if (isset($replacements[$identifier])) { |
|
377 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
378 | + } |
|
356 | 379 | |
357 | 380 | // Limits need to be a little different. |
358 | 381 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
359 | 382 | |
360 | - if (trim($db_string) == '') |
|
361 | - return false; |
|
383 | + if (trim($db_string) == '') { |
|
384 | + return false; |
|
385 | + } |
|
362 | 386 | |
363 | 387 | // Comments that are allowed in a query are preg_removed. |
364 | 388 | static $allowed_comments_from = array( |
@@ -378,8 +402,9 @@ discard block |
||
378 | 402 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
379 | 403 | $db_replace_result = 0; |
380 | 404 | |
381 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
382 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
405 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
406 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
407 | + } |
|
383 | 408 | |
384 | 409 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
385 | 410 | { |
@@ -400,8 +425,9 @@ discard block |
||
400 | 425 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
401 | 426 | |
402 | 427 | // Initialize $db_cache if not already initialized. |
403 | - if (!isset($db_cache)) |
|
404 | - $db_cache = array(); |
|
428 | + if (!isset($db_cache)) { |
|
429 | + $db_cache = array(); |
|
430 | + } |
|
405 | 431 | |
406 | 432 | if (!empty($_SESSION['debug_redirect'])) |
407 | 433 | { |
@@ -427,17 +453,18 @@ discard block |
||
427 | 453 | while (true) |
428 | 454 | { |
429 | 455 | $pos = strpos($db_string, '\'', $pos + 1); |
430 | - if ($pos === false) |
|
431 | - break; |
|
456 | + if ($pos === false) { |
|
457 | + break; |
|
458 | + } |
|
432 | 459 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
433 | 460 | |
434 | 461 | while (true) |
435 | 462 | { |
436 | 463 | $pos1 = strpos($db_string, '\'', $pos + 1); |
437 | 464 | $pos2 = strpos($db_string, '\\', $pos + 1); |
438 | - if ($pos1 === false) |
|
439 | - break; |
|
440 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
465 | + if ($pos1 === false) { |
|
466 | + break; |
|
467 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
441 | 468 | { |
442 | 469 | $pos = $pos1; |
443 | 470 | break; |
@@ -453,16 +480,19 @@ discard block |
||
453 | 480 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
454 | 481 | |
455 | 482 | // Comments? We don't use comments in our queries, we leave 'em outside! |
456 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
457 | - $fail = true; |
|
483 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
484 | + $fail = true; |
|
485 | + } |
|
458 | 486 | // Trying to change passwords, slow us down, or something? |
459 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
460 | - $fail = true; |
|
461 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
462 | - $fail = true; |
|
487 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
488 | + $fail = true; |
|
489 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
490 | + $fail = true; |
|
491 | + } |
|
463 | 492 | |
464 | - if (!empty($fail) && function_exists('log_error')) |
|
465 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
493 | + if (!empty($fail) && function_exists('log_error')) { |
|
494 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
495 | + } |
|
466 | 496 | } |
467 | 497 | |
468 | 498 | // Set optimize stuff |
@@ -481,18 +511,21 @@ discard block |
||
481 | 511 | |
482 | 512 | $db_string = $query_hints_set . $db_string; |
483 | 513 | |
484 | - if (isset($db_show_debug) && $db_show_debug === true && $db_cache[$db_count]['q'] != '...') |
|
485 | - $db_cache[$db_count]['q'] = "\t\t" . $db_string; |
|
514 | + if (isset($db_show_debug) && $db_show_debug === true && $db_cache[$db_count]['q'] != '...') { |
|
515 | + $db_cache[$db_count]['q'] = "\t\t" . $db_string; |
|
516 | + } |
|
486 | 517 | } |
487 | 518 | |
488 | 519 | $db_last_result = @pg_query($connection, $db_string); |
489 | 520 | |
490 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
491 | - $db_last_result = smf_db_error($db_string, $connection); |
|
521 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
522 | + $db_last_result = smf_db_error($db_string, $connection); |
|
523 | + } |
|
492 | 524 | |
493 | 525 | // Debugging. |
494 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
495 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
526 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
527 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
528 | + } |
|
496 | 529 | |
497 | 530 | return $db_last_result; |
498 | 531 | } |
@@ -505,10 +538,11 @@ discard block |
||
505 | 538 | { |
506 | 539 | global $db_last_result, $db_replace_result; |
507 | 540 | |
508 | - if ($db_replace_result) |
|
509 | - return $db_replace_result; |
|
510 | - elseif ($result === null && !$db_last_result) |
|
511 | - return 0; |
|
541 | + if ($db_replace_result) { |
|
542 | + return $db_replace_result; |
|
543 | + } elseif ($result === null && !$db_last_result) { |
|
544 | + return 0; |
|
545 | + } |
|
512 | 546 | |
513 | 547 | return pg_affected_rows($result === null ? $db_last_result : $result); |
514 | 548 | } |
@@ -532,8 +566,9 @@ discard block |
||
532 | 566 | array( |
533 | 567 | ) |
534 | 568 | ); |
535 | - if (!$request) |
|
536 | - return false; |
|
569 | + if (!$request) { |
|
570 | + return false; |
|
571 | + } |
|
537 | 572 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
538 | 573 | $smcFunc['db_free_result']($request); |
539 | 574 | |
@@ -554,12 +589,13 @@ discard block |
||
554 | 589 | // Decide which connection to use |
555 | 590 | $connection = $connection === null ? $db_connection : $connection; |
556 | 591 | |
557 | - if ($type == 'begin') |
|
558 | - return @pg_query($connection, 'BEGIN'); |
|
559 | - elseif ($type == 'rollback') |
|
560 | - return @pg_query($connection, 'ROLLBACK'); |
|
561 | - elseif ($type == 'commit') |
|
562 | - return @pg_query($connection, 'COMMIT'); |
|
592 | + if ($type == 'begin') { |
|
593 | + return @pg_query($connection, 'BEGIN'); |
|
594 | + } elseif ($type == 'rollback') { |
|
595 | + return @pg_query($connection, 'ROLLBACK'); |
|
596 | + } elseif ($type == 'commit') { |
|
597 | + return @pg_query($connection, 'COMMIT'); |
|
598 | + } |
|
563 | 599 | |
564 | 600 | return false; |
565 | 601 | } |
@@ -587,19 +623,22 @@ discard block |
||
587 | 623 | $query_error = @pg_last_error($connection); |
588 | 624 | |
589 | 625 | // Log the error. |
590 | - if (function_exists('log_error')) |
|
591 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
626 | + if (function_exists('log_error')) { |
|
627 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
628 | + } |
|
592 | 629 | |
593 | 630 | // Nothing's defined yet... just die with it. |
594 | - if (empty($context) || empty($txt)) |
|
595 | - die($query_error); |
|
631 | + if (empty($context) || empty($txt)) { |
|
632 | + die($query_error); |
|
633 | + } |
|
596 | 634 | |
597 | 635 | // Show an error message, if possible. |
598 | 636 | $context['error_title'] = $txt['database_error']; |
599 | - if (allowedTo('admin_forum')) |
|
600 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
601 | - else |
|
602 | - $context['error_message'] = $txt['try_again']; |
|
637 | + if (allowedTo('admin_forum')) { |
|
638 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
639 | + } else { |
|
640 | + $context['error_message'] = $txt['try_again']; |
|
641 | + } |
|
603 | 642 | |
604 | 643 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
605 | 644 | { |
@@ -621,12 +660,14 @@ discard block |
||
621 | 660 | { |
622 | 661 | global $db_row_count; |
623 | 662 | |
624 | - if ($counter !== false) |
|
625 | - return pg_fetch_row($request, $counter); |
|
663 | + if ($counter !== false) { |
|
664 | + return pg_fetch_row($request, $counter); |
|
665 | + } |
|
626 | 666 | |
627 | 667 | // Reset the row counter... |
628 | - if (!isset($db_row_count[(int) $request])) |
|
629 | - $db_row_count[(int) $request] = 0; |
|
668 | + if (!isset($db_row_count[(int) $request])) { |
|
669 | + $db_row_count[(int) $request] = 0; |
|
670 | + } |
|
630 | 671 | |
631 | 672 | // Return the right row. |
632 | 673 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -643,12 +684,14 @@ discard block |
||
643 | 684 | { |
644 | 685 | global $db_row_count; |
645 | 686 | |
646 | - if ($counter !== false) |
|
647 | - return pg_fetch_assoc($request, $counter); |
|
687 | + if ($counter !== false) { |
|
688 | + return pg_fetch_assoc($request, $counter); |
|
689 | + } |
|
648 | 690 | |
649 | 691 | // Reset the row counter... |
650 | - if (!isset($db_row_count[(int) $request])) |
|
651 | - $db_row_count[(int) $request] = 0; |
|
692 | + if (!isset($db_row_count[(int) $request])) { |
|
693 | + $db_row_count[(int) $request] = 0; |
|
694 | + } |
|
652 | 695 | |
653 | 696 | // Return the right row. |
654 | 697 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -701,11 +744,13 @@ discard block |
||
701 | 744 | |
702 | 745 | $replace = ''; |
703 | 746 | |
704 | - if (empty($data)) |
|
705 | - return; |
|
747 | + if (empty($data)) { |
|
748 | + return; |
|
749 | + } |
|
706 | 750 | |
707 | - if (!is_array($data[array_rand($data)])) |
|
708 | - $data = array($data); |
|
751 | + if (!is_array($data[array_rand($data)])) { |
|
752 | + $data = array($data); |
|
753 | + } |
|
709 | 754 | |
710 | 755 | // Replace the prefix holder with the actual prefix. |
711 | 756 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -724,11 +769,13 @@ discard block |
||
724 | 769 | //pg 9.5 got replace support |
725 | 770 | $pg_version = $smcFunc['db_get_version'](); |
726 | 771 | // if we got a Beta Version |
727 | - if (stripos($pg_version, 'beta') !== false) |
|
728 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
772 | + if (stripos($pg_version, 'beta') !== false) { |
|
773 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
774 | + } |
|
729 | 775 | // or RC |
730 | - if (stripos($pg_version, 'rc') !== false) |
|
731 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
776 | + if (stripos($pg_version, 'rc') !== false) { |
|
777 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
778 | + } |
|
732 | 779 | |
733 | 780 | $replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false); |
734 | 781 | } |
@@ -747,8 +794,7 @@ discard block |
||
747 | 794 | $key_str .= ($count_pk > 0 ? ',' : ''); |
748 | 795 | $key_str .= $columnName; |
749 | 796 | $count_pk++; |
750 | - } |
|
751 | - else //normal field |
|
797 | + } else //normal field |
|
752 | 798 | { |
753 | 799 | $col_str .= ($count > 0 ? ',' : ''); |
754 | 800 | $col_str .= $columnName . ' = EXCLUDED.' . $columnName; |
@@ -756,20 +802,21 @@ discard block |
||
756 | 802 | } |
757 | 803 | } |
758 | 804 | $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
759 | - } |
|
760 | - else |
|
805 | + } else |
|
761 | 806 | { |
762 | 807 | foreach ($columns as $columnName => $type) |
763 | 808 | { |
764 | 809 | // Are we restricting the length? |
765 | - if (strpos($type, 'string-') !== false) |
|
766 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
767 | - else |
|
768 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
810 | + if (strpos($type, 'string-') !== false) { |
|
811 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
812 | + } else { |
|
813 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
814 | + } |
|
769 | 815 | |
770 | 816 | // A key? That's what we were looking for. |
771 | - if (in_array($columnName, $keys)) |
|
772 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
817 | + if (in_array($columnName, $keys)) { |
|
818 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
819 | + } |
|
773 | 820 | $count++; |
774 | 821 | } |
775 | 822 | |
@@ -805,10 +852,11 @@ discard block |
||
805 | 852 | foreach ($columns as $columnName => $type) |
806 | 853 | { |
807 | 854 | // Are we restricting the length? |
808 | - if (strpos($type, 'string-') !== false) |
|
809 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
810 | - else |
|
811 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
855 | + if (strpos($type, 'string-') !== false) { |
|
856 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
857 | + } else { |
|
858 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
859 | + } |
|
812 | 860 | } |
813 | 861 | $insertData = substr($insertData, 0, -2) . ')'; |
814 | 862 | |
@@ -817,8 +865,9 @@ discard block |
||
817 | 865 | |
818 | 866 | // Here's where the variables are injected to the query. |
819 | 867 | $insertRows = array(); |
820 | - foreach ($data as $dataRow) |
|
821 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
868 | + foreach ($data as $dataRow) { |
|
869 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
870 | + } |
|
822 | 871 | |
823 | 872 | // Do the insert. |
824 | 873 | $request = $smcFunc['db_query']('', ' |
@@ -835,19 +884,21 @@ discard block |
||
835 | 884 | |
836 | 885 | if ($with_returning && $request !== false) |
837 | 886 | { |
838 | - if ($returnmode === 2) |
|
839 | - $return_var = array(); |
|
887 | + if ($returnmode === 2) { |
|
888 | + $return_var = array(); |
|
889 | + } |
|
840 | 890 | |
841 | 891 | while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
842 | 892 | { |
843 | - if (is_numeric($row[0])) // try to emulate mysql limitation |
|
893 | + if (is_numeric($row[0])) { |
|
894 | + // try to emulate mysql limitation |
|
844 | 895 | { |
845 | 896 | if ($returnmode === 1) |
846 | 897 | $return_var = $row[0]; |
847 | - elseif ($returnmode === 2) |
|
848 | - $return_var[] = $row[0]; |
|
849 | - } |
|
850 | - else |
|
898 | + } elseif ($returnmode === 2) { |
|
899 | + $return_var[] = $row[0]; |
|
900 | + } |
|
901 | + } else |
|
851 | 902 | { |
852 | 903 | $with_returning = false; |
853 | 904 | trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR); |
@@ -856,9 +907,10 @@ discard block |
||
856 | 907 | } |
857 | 908 | } |
858 | 909 | |
859 | - if ($with_returning && !empty($return_var)) |
|
860 | - return $return_var; |
|
861 | -} |
|
910 | + if ($with_returning && !empty($return_var)) { |
|
911 | + return $return_var; |
|
912 | + } |
|
913 | + } |
|
862 | 914 | |
863 | 915 | /** |
864 | 916 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -895,8 +947,9 @@ discard block |
||
895 | 947 | */ |
896 | 948 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
897 | 949 | { |
898 | - if (empty($log_message)) |
|
899 | - $log_message = $error_message; |
|
950 | + if (empty($log_message)) { |
|
951 | + $log_message = $error_message; |
|
952 | + } |
|
900 | 953 | |
901 | 954 | foreach (debug_backtrace() as $step) |
902 | 955 | { |
@@ -915,12 +968,14 @@ discard block |
||
915 | 968 | } |
916 | 969 | |
917 | 970 | // A special case - we want the file and line numbers for debugging. |
918 | - if ($error_type == 'return') |
|
919 | - return array($file, $line); |
|
971 | + if ($error_type == 'return') { |
|
972 | + return array($file, $line); |
|
973 | + } |
|
920 | 974 | |
921 | 975 | // Is always a critical error. |
922 | - if (function_exists('log_error')) |
|
923 | - log_error($log_message, 'critical', $file, $line); |
|
976 | + if (function_exists('log_error')) { |
|
977 | + log_error($log_message, 'critical', $file, $line); |
|
978 | + } |
|
924 | 979 | |
925 | 980 | if (function_exists('fatal_error')) |
926 | 981 | { |
@@ -928,12 +983,12 @@ discard block |
||
928 | 983 | |
929 | 984 | // Cannot continue... |
930 | 985 | exit; |
986 | + } elseif ($error_type) { |
|
987 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
988 | + } else { |
|
989 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
990 | + } |
|
931 | 991 | } |
932 | - elseif ($error_type) |
|
933 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
934 | - else |
|
935 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
936 | -} |
|
937 | 992 | |
938 | 993 | /** |
939 | 994 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -950,10 +1005,11 @@ discard block |
||
950 | 1005 | '\\' => '\\\\', |
951 | 1006 | ); |
952 | 1007 | |
953 | - if ($translate_human_wildcards) |
|
954 | - $replacements += array( |
|
1008 | + if ($translate_human_wildcards) { |
|
1009 | + $replacements += array( |
|
955 | 1010 | '*' => '%', |
956 | 1011 | ); |
1012 | + } |
|
957 | 1013 | |
958 | 1014 | return strtr($string, $replacements); |
959 | 1015 | } |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * This file contains helper functions for upgrade.php |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF_VERSION')) |
|
16 | +if (!defined('SMF_VERSION')) { |
|
17 | 17 | die('No direct access!'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Clean the cache using the SMF 2.1 CacheAPI. |
@@ -45,8 +46,9 @@ discard block |
||
45 | 46 | global $smcFunc; |
46 | 47 | static $member_groups = array(); |
47 | 48 | |
48 | - if (!empty($member_groups)) |
|
49 | - return $member_groups; |
|
49 | + if (!empty($member_groups)) { |
|
50 | + return $member_groups; |
|
51 | + } |
|
50 | 52 | |
51 | 53 | $request = $smcFunc['db_query']('', ' |
52 | 54 | SELECT group_name, id_group |
@@ -71,8 +73,9 @@ discard block |
||
71 | 73 | ) |
72 | 74 | ); |
73 | 75 | } |
74 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
75 | - $member_groups[trim($row[0])] = $row[1]; |
|
76 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
77 | + $member_groups[trim($row[0])] = $row[1]; |
|
78 | + } |
|
76 | 79 | $smcFunc['db_free_result']($request); |
77 | 80 | |
78 | 81 | return $member_groups; |
@@ -88,8 +91,9 @@ discard block |
||
88 | 91 | { |
89 | 92 | global $upcontext, $boarddir, $sourcedir; |
90 | 93 | |
91 | - if (empty($files)) |
|
92 | - return true; |
|
94 | + if (empty($files)) { |
|
95 | + return true; |
|
96 | + } |
|
93 | 97 | |
94 | 98 | $failure = false; |
95 | 99 | // On linux, it's easy - just use is_writable! |
@@ -100,22 +104,25 @@ discard block |
||
100 | 104 | foreach ($files as $k => $file) |
101 | 105 | { |
102 | 106 | // Some files won't exist, try to address up front |
103 | - if (!file_exists($file)) |
|
104 | - @touch($file); |
|
107 | + if (!file_exists($file)) { |
|
108 | + @touch($file); |
|
109 | + } |
|
105 | 110 | // NOW do the writable check... |
106 | 111 | if (!is_writable($file)) |
107 | 112 | { |
108 | 113 | @chmod($file, 0755); |
109 | 114 | |
110 | 115 | // Well, 755 hopefully worked... if not, try 777. |
111 | - if (!is_writable($file) && !@chmod($file, 0777)) |
|
112 | - $failure = true; |
|
116 | + if (!is_writable($file) && !@chmod($file, 0777)) { |
|
117 | + $failure = true; |
|
118 | + } |
|
113 | 119 | // Otherwise remove it as it's good! |
114 | - else |
|
115 | - unset($files[$k]); |
|
120 | + else { |
|
121 | + unset($files[$k]); |
|
122 | + } |
|
123 | + } else { |
|
124 | + unset($files[$k]); |
|
116 | 125 | } |
117 | - else |
|
118 | - unset($files[$k]); |
|
119 | 126 | } |
120 | 127 | } |
121 | 128 | // Windows is trickier. Let's try opening for r+... |
@@ -126,30 +133,35 @@ discard block |
||
126 | 133 | foreach ($files as $k => $file) |
127 | 134 | { |
128 | 135 | // Folders can't be opened for write... but the index.php in them can ;). |
129 | - if (is_dir($file)) |
|
130 | - $file .= '/index.php'; |
|
136 | + if (is_dir($file)) { |
|
137 | + $file .= '/index.php'; |
|
138 | + } |
|
131 | 139 | |
132 | 140 | // Funny enough, chmod actually does do something on windows - it removes the read only attribute. |
133 | 141 | @chmod($file, 0777); |
134 | 142 | $fp = @fopen($file, 'r+'); |
135 | 143 | |
136 | 144 | // Hmm, okay, try just for write in that case... |
137 | - if (!$fp) |
|
138 | - $fp = @fopen($file, 'w'); |
|
145 | + if (!$fp) { |
|
146 | + $fp = @fopen($file, 'w'); |
|
147 | + } |
|
139 | 148 | |
140 | - if (!$fp) |
|
141 | - $failure = true; |
|
142 | - else |
|
143 | - unset($files[$k]); |
|
149 | + if (!$fp) { |
|
150 | + $failure = true; |
|
151 | + } else { |
|
152 | + unset($files[$k]); |
|
153 | + } |
|
144 | 154 | @fclose($fp); |
145 | 155 | } |
146 | 156 | } |
147 | 157 | |
148 | - if (empty($files)) |
|
149 | - return true; |
|
158 | + if (empty($files)) { |
|
159 | + return true; |
|
160 | + } |
|
150 | 161 | |
151 | - if (!isset($_SERVER)) |
|
152 | - return !$failure; |
|
162 | + if (!isset($_SERVER)) { |
|
163 | + return !$failure; |
|
164 | + } |
|
153 | 165 | |
154 | 166 | // What still needs to be done? |
155 | 167 | $upcontext['chmod']['files'] = $files; |
@@ -201,36 +213,40 @@ discard block |
||
201 | 213 | |
202 | 214 | if (!isset($ftp) || $ftp->error !== false) |
203 | 215 | { |
204 | - if (!isset($ftp)) |
|
205 | - $ftp = new ftp_connection(null); |
|
216 | + if (!isset($ftp)) { |
|
217 | + $ftp = new ftp_connection(null); |
|
218 | + } |
|
206 | 219 | // Save the error so we can mess with listing... |
207 | - elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) |
|
208 | - $upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message; |
|
220 | + elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) { |
|
221 | + $upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message; |
|
222 | + } |
|
209 | 223 | |
210 | 224 | list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__)); |
211 | 225 | |
212 | - if ($found_path || !isset($upcontext['chmod']['path'])) |
|
213 | - $upcontext['chmod']['path'] = $detect_path; |
|
226 | + if ($found_path || !isset($upcontext['chmod']['path'])) { |
|
227 | + $upcontext['chmod']['path'] = $detect_path; |
|
228 | + } |
|
214 | 229 | |
215 | - if (!isset($upcontext['chmod']['username'])) |
|
216 | - $upcontext['chmod']['username'] = $username; |
|
230 | + if (!isset($upcontext['chmod']['username'])) { |
|
231 | + $upcontext['chmod']['username'] = $username; |
|
232 | + } |
|
217 | 233 | |
218 | 234 | // Don't forget the login token. |
219 | 235 | $upcontext += createToken('login'); |
220 | 236 | |
221 | 237 | return false; |
222 | - } |
|
223 | - else |
|
238 | + } else |
|
224 | 239 | { |
225 | 240 | // We want to do a relative path for FTP. |
226 | 241 | if (!in_array($upcontext['chmod']['path'], array('', '/'))) |
227 | 242 | { |
228 | 243 | $ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => '')); |
229 | - if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) |
|
230 | - $ftp_root = substr($ftp_root, 0, -1); |
|
244 | + if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) { |
|
245 | + $ftp_root = substr($ftp_root, 0, -1); |
|
246 | + } |
|
247 | + } else { |
|
248 | + $ftp_root = $boarddir; |
|
231 | 249 | } |
232 | - else |
|
233 | - $ftp_root = $boarddir; |
|
234 | 250 | |
235 | 251 | // Save the info for next time! |
236 | 252 | $_SESSION['installer_temp_ftp'] = array( |
@@ -244,10 +260,12 @@ discard block |
||
244 | 260 | |
245 | 261 | foreach ($files as $k => $file) |
246 | 262 | { |
247 | - if (!is_writable($file)) |
|
248 | - $ftp->chmod($file, 0755); |
|
249 | - if (!is_writable($file)) |
|
250 | - $ftp->chmod($file, 0777); |
|
263 | + if (!is_writable($file)) { |
|
264 | + $ftp->chmod($file, 0755); |
|
265 | + } |
|
266 | + if (!is_writable($file)) { |
|
267 | + $ftp->chmod($file, 0777); |
|
268 | + } |
|
251 | 269 | |
252 | 270 | // Assuming that didn't work calculate the path without the boarddir. |
253 | 271 | if (!is_writable($file)) |
@@ -256,19 +274,23 @@ discard block |
||
256 | 274 | { |
257 | 275 | $ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => '')); |
258 | 276 | $ftp->chmod($ftp_file, 0755); |
259 | - if (!is_writable($file)) |
|
260 | - $ftp->chmod($ftp_file, 0777); |
|
277 | + if (!is_writable($file)) { |
|
278 | + $ftp->chmod($ftp_file, 0777); |
|
279 | + } |
|
261 | 280 | // Sometimes an extra slash can help... |
262 | 281 | $ftp_file = '/' . $ftp_file; |
263 | - if (!is_writable($file)) |
|
264 | - $ftp->chmod($ftp_file, 0755); |
|
265 | - if (!is_writable($file)) |
|
266 | - $ftp->chmod($ftp_file, 0777); |
|
282 | + if (!is_writable($file)) { |
|
283 | + $ftp->chmod($ftp_file, 0755); |
|
284 | + } |
|
285 | + if (!is_writable($file)) { |
|
286 | + $ftp->chmod($ftp_file, 0777); |
|
287 | + } |
|
267 | 288 | } |
268 | 289 | } |
269 | 290 | |
270 | - if (is_writable($file)) |
|
271 | - unset($files[$k]); |
|
291 | + if (is_writable($file)) { |
|
292 | + unset($files[$k]); |
|
293 | + } |
|
272 | 294 | } |
273 | 295 | |
274 | 296 | $ftp->close(); |
@@ -278,8 +300,9 @@ discard block |
||
278 | 300 | // What remains? |
279 | 301 | $upcontext['chmod']['files'] = $files; |
280 | 302 | |
281 | - if (empty($files)) |
|
282 | - return true; |
|
303 | + if (empty($files)) { |
|
304 | + return true; |
|
305 | + } |
|
283 | 306 | |
284 | 307 | return false; |
285 | 308 | } |
@@ -294,12 +317,14 @@ discard block |
||
294 | 317 | { |
295 | 318 | |
296 | 319 | // Some files won't exist, try to address up front |
297 | - if (!file_exists($file)) |
|
298 | - @touch($file); |
|
320 | + if (!file_exists($file)) { |
|
321 | + @touch($file); |
|
322 | + } |
|
299 | 323 | |
300 | 324 | // NOW do the writable check... |
301 | - if (is_writable($file)) |
|
302 | - return true; |
|
325 | + if (is_writable($file)) { |
|
326 | + return true; |
|
327 | + } |
|
303 | 328 | |
304 | 329 | @chmod($file, 0755); |
305 | 330 | |
@@ -309,10 +334,11 @@ discard block |
||
309 | 334 | foreach ($chmod_values as $val) |
310 | 335 | { |
311 | 336 | // If it's writable, break out of the loop |
312 | - if (is_writable($file)) |
|
313 | - break; |
|
314 | - else |
|
315 | - @chmod($file, $val); |
|
337 | + if (is_writable($file)) { |
|
338 | + break; |
|
339 | + } else { |
|
340 | + @chmod($file, $val); |
|
341 | + } |
|
316 | 342 | } |
317 | 343 | |
318 | 344 | return is_writable($file); |
@@ -339,14 +365,16 @@ discard block |
||
339 | 365 | { |
340 | 366 | static $fp = null; |
341 | 367 | |
342 | - if ($fp === null) |
|
343 | - $fp = fopen('php://stderr', 'wb'); |
|
368 | + if ($fp === null) { |
|
369 | + $fp = fopen('php://stderr', 'wb'); |
|
370 | + } |
|
344 | 371 | |
345 | 372 | fwrite($fp, $message . "\n"); |
346 | 373 | |
347 | - if ($fatal) |
|
348 | - exit; |
|
349 | -} |
|
374 | + if ($fatal) { |
|
375 | + exit; |
|
376 | + } |
|
377 | + } |
|
350 | 378 | |
351 | 379 | /** |
352 | 380 | * Throws a graphical error message. |