@@ -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()) |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | // Just send a generic message. |
| 77 | 77 | else |
| 78 | 78 | $this->setResponse(array( |
| 79 | - 'text' => $this->_sa == 'add' ? 'attach_error_title' : 'attached_file_deleted_error', |
|
| 79 | + 'text' => $this->_sa == 'add' ? 'attach_error_title' : 'attached_file_deleted_error', |
|
| 80 | 80 | 'type' => 'error', |
| 81 | 81 | 'data' => false, |
| 82 | 82 | )); |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | // Gotta urlencode the filename. |
| 407 | 407 | if ($this->_attachResults) |
| 408 | 408 | foreach ($this->_attachResults as $k => $v) |
| 409 | - $this->_attachResults[$k]['name'] = urlencode($this->_attachResults[$k]['name']); |
|
| 409 | + $this->_attachResults[$k]['name'] = urlencode($this->_attachResults[$k]['name']); |
|
| 410 | 410 | |
| 411 | 411 | $this->_response = array( |
| 412 | 412 | 'files' => $this->_attachResults ? $this->_attachResults : false, |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | ob_start(); |
| 434 | 434 | |
| 435 | 435 | // Set the header. |
| 436 | - header('Content-Type: application/json; charset='. $context['character_set'] .''); |
|
| 436 | + header('Content-Type: application/json; charset=' . $context['character_set'] . ''); |
|
| 437 | 437 | |
| 438 | 438 | echo $smcFunc['json_encode']($this->_response ? $this->_response : array()); |
| 439 | 439 | |
@@ -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 | class Attachments |
| 20 | 21 | { |
@@ -70,16 +71,18 @@ discard block |
||
| 70 | 71 | |
| 71 | 72 | $this->_sa = !empty($_REQUEST['sa']) ? $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_REQUEST['sa'])) : false; |
| 72 | 73 | |
| 73 | - if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) |
|
| 74 | - $this->{$this->_sa}(); |
|
| 74 | + if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) { |
|
| 75 | + $this->{$this->_sa}(); |
|
| 76 | + } |
|
| 75 | 77 | |
| 76 | 78 | // Just send a generic message. |
| 77 | - else |
|
| 78 | - $this->setResponse(array( |
|
| 79 | + else { |
|
| 80 | + $this->setResponse(array( |
|
| 79 | 81 | 'text' => $this->_sa == 'add' ? 'attach_error_title' : 'attached_file_deleted_error', |
| 80 | 82 | 'type' => 'error', |
| 81 | 83 | 'data' => false, |
| 82 | 84 | )); |
| 85 | + } |
|
| 83 | 86 | |
| 84 | 87 | // Back to the future, oh, to the browser! |
| 85 | 88 | $this->sendResponse(); |
@@ -95,12 +98,13 @@ discard block |
||
| 95 | 98 | $attachID = !empty($_REQUEST['attach']) && is_numeric($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : 0; |
| 96 | 99 | |
| 97 | 100 | // Need something to work with. |
| 98 | - if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) |
|
| 99 | - return $this->setResponse(array( |
|
| 101 | + if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) { |
|
| 102 | + return $this->setResponse(array( |
|
| 100 | 103 | 'text' => 'attached_file_deleted_error', |
| 101 | 104 | 'type' => 'error', |
| 102 | 105 | 'data' => false, |
| 103 | 106 | )); |
| 107 | + } |
|
| 104 | 108 | |
| 105 | 109 | // Lets pass some params and see what happens :P |
| 106 | 110 | $affectedMessage = removeAttachments(array('id_attach' => $attachID), '', true, true); |
@@ -119,19 +123,21 @@ discard block |
||
| 119 | 123 | public function add() |
| 120 | 124 | { |
| 121 | 125 | // You gotta be able to post attachments. |
| 122 | - if (!$this->_canPostAttachment) |
|
| 123 | - return $this->setResponse(array( |
|
| 126 | + if (!$this->_canPostAttachment) { |
|
| 127 | + return $this->setResponse(array( |
|
| 124 | 128 | 'text' => 'attached_file_cannot', |
| 125 | 129 | 'type' => 'error', |
| 126 | 130 | 'data' => false, |
| 127 | 131 | )); |
| 132 | + } |
|
| 128 | 133 | |
| 129 | 134 | // Process them at once! |
| 130 | 135 | $this->processAttachments(); |
| 131 | 136 | |
| 132 | 137 | // The attachments was created and moved the the right folder, time to update the DB. |
| 133 | - if (!empty($_SESSION['temp_attachments'])) |
|
| 134 | - $this->createAtttach(); |
|
| 138 | + if (!empty($_SESSION['temp_attachments'])) { |
|
| 139 | + $this->createAtttach(); |
|
| 140 | + } |
|
| 135 | 141 | |
| 136 | 142 | // Set the response. |
| 137 | 143 | $this->setResponse(); |
@@ -144,8 +150,9 @@ discard block |
||
| 144 | 150 | { |
| 145 | 151 | global $context, $modSettings, $smcFunc, $user_info, $txt; |
| 146 | 152 | |
| 147 | - if (!isset($_FILES['attachment']['name'])) |
|
| 148 | - $_FILES['attachment']['tmp_name'] = array(); |
|
| 153 | + if (!isset($_FILES['attachment']['name'])) { |
|
| 154 | + $_FILES['attachment']['tmp_name'] = array(); |
|
| 155 | + } |
|
| 149 | 156 | |
| 150 | 157 | // If there are attachments, calculate the total size and how many. |
| 151 | 158 | $context['attachments']['total_size'] = 0; |
@@ -155,25 +162,30 @@ discard block |
||
| 155 | 162 | if (isset($_REQUEST['msg'])) |
| 156 | 163 | { |
| 157 | 164 | $context['attachments']['quantity'] = count($context['current_attachments']); |
| 158 | - foreach ($context['current_attachments'] as $attachment) |
|
| 159 | - $context['attachments']['total_size'] += $attachment['size']; |
|
| 165 | + foreach ($context['current_attachments'] as $attachment) { |
|
| 166 | + $context['attachments']['total_size'] += $attachment['size']; |
|
| 167 | + } |
|
| 160 | 168 | } |
| 161 | 169 | |
| 162 | 170 | // A bit of house keeping first. |
| 163 | - if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) |
|
| 164 | - unset($_SESSION['temp_attachments']); |
|
| 171 | + if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) { |
|
| 172 | + unset($_SESSION['temp_attachments']); |
|
| 173 | + } |
|
| 165 | 174 | |
| 166 | 175 | // Our infamous SESSION var, we are gonna have soo much fun with it! |
| 167 | - if (!isset($_SESSION['temp_attachments'])) |
|
| 168 | - $_SESSION['temp_attachments'] = array(); |
|
| 176 | + if (!isset($_SESSION['temp_attachments'])) { |
|
| 177 | + $_SESSION['temp_attachments'] = array(); |
|
| 178 | + } |
|
| 169 | 179 | |
| 170 | 180 | // Make sure we're uploading to the right place. |
| 171 | - if (!empty($modSettings['automanage_attachments'])) |
|
| 172 | - automanage_attachments_check_directory(); |
|
| 181 | + if (!empty($modSettings['automanage_attachments'])) { |
|
| 182 | + automanage_attachments_check_directory(); |
|
| 183 | + } |
|
| 173 | 184 | |
| 174 | 185 | // Is the attachments folder actually there? |
| 175 | - if (!empty($context['dir_creation_error'])) |
|
| 176 | - $this->_generalErrors[] = $context['dir_creation_error']; |
|
| 186 | + if (!empty($context['dir_creation_error'])) { |
|
| 187 | + $this->_generalErrors[] = $context['dir_creation_error']; |
|
| 188 | + } |
|
| 177 | 189 | |
| 178 | 190 | // The current attach folder ha some issues... |
| 179 | 191 | elseif (!is_dir($this->_attchDir)) |
@@ -198,13 +210,12 @@ discard block |
||
| 198 | 210 | ); |
| 199 | 211 | list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request); |
| 200 | 212 | $smcFunc['db_free_result']($request); |
| 201 | - } |
|
| 202 | - |
|
| 203 | - else |
|
| 204 | - $context['attachments'] = array( |
|
| 213 | + } else { |
|
| 214 | + $context['attachments'] = array( |
|
| 205 | 215 | 'quantity' => 0, |
| 206 | 216 | 'total_size' => 0, |
| 207 | 217 | ); |
| 218 | + } |
|
| 208 | 219 | |
| 209 | 220 | // Check for other general errors here. |
| 210 | 221 | |
@@ -212,9 +223,10 @@ discard block |
||
| 212 | 223 | if (!empty($this->_generalErrors)) |
| 213 | 224 | { |
| 214 | 225 | // And delete the files 'cos they ain't going nowhere. |
| 215 | - foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
|
| 216 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 226 | + foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) { |
|
| 227 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 217 | 228 | unlink($_FILES['attachment']['tmp_name'][$n]); |
| 229 | + } |
|
| 218 | 230 | |
| 219 | 231 | $_FILES['attachment']['tmp_name'] = array(); |
| 220 | 232 | |
@@ -225,26 +237,29 @@ discard block |
||
| 225 | 237 | // Loop through $_FILES['attachment'] array and move each file to the current attachments folder. |
| 226 | 238 | foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
| 227 | 239 | { |
| 228 | - if ($_FILES['attachment']['name'][$n] == '') |
|
| 229 | - continue; |
|
| 240 | + if ($_FILES['attachment']['name'][$n] == '') { |
|
| 241 | + continue; |
|
| 242 | + } |
|
| 230 | 243 | |
| 231 | 244 | // First, let's first check for PHP upload errors. |
| 232 | 245 | $errors = array(); |
| 233 | 246 | if (!empty($_FILES['attachment']['error'][$n])) |
| 234 | 247 | { |
| 235 | - if ($_FILES['attachment']['error'][$n] == 2) |
|
| 236 | - $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
| 237 | - |
|
| 238 | - else |
|
| 239 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
| 248 | + if ($_FILES['attachment']['error'][$n] == 2) { |
|
| 249 | + $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
| 250 | + } else { |
|
| 251 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
| 252 | + } |
|
| 240 | 253 | |
| 241 | 254 | // Log this one, because... |
| 242 | - if ($_FILES['attachment']['error'][$n] == 6) |
|
| 243 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
| 255 | + if ($_FILES['attachment']['error'][$n] == 6) { |
|
| 256 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
| 257 | + } |
|
| 244 | 258 | |
| 245 | 259 | // Weird, no errors were cached, still fill out a generic one. |
| 246 | - if (empty($errors)) |
|
| 247 | - $errors[] = 'attach_php_error'; |
|
| 260 | + if (empty($errors)) { |
|
| 261 | + $errors[] = 'attach_php_error'; |
|
| 262 | + } |
|
| 248 | 263 | } |
| 249 | 264 | |
| 250 | 265 | // Try to move and rename the file before doing any more checks on it. |
@@ -256,8 +271,9 @@ discard block |
||
| 256 | 271 | { |
| 257 | 272 | // The reported MIME type of the attachment might not be reliable. |
| 258 | 273 | // Fortunately, PHP 5.3+ lets us easily verify the real MIME type. |
| 259 | - if (function_exists('mime_content_type')) |
|
| 260 | - $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
| 274 | + if (function_exists('mime_content_type')) { |
|
| 275 | + $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
| 276 | + } |
|
| 261 | 277 | |
| 262 | 278 | $_SESSION['temp_attachments'][$attachID] = array( |
| 263 | 279 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -269,16 +285,18 @@ discard block |
||
| 269 | 285 | ); |
| 270 | 286 | |
| 271 | 287 | // Move the file to the attachments folder with a temp name for now. |
| 272 | - if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) |
|
| 273 | - smf_chmod($destName, 0644); |
|
| 288 | + if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) { |
|
| 289 | + smf_chmod($destName, 0644); |
|
| 290 | + } |
|
| 274 | 291 | |
| 275 | 292 | // This is madness!! |
| 276 | 293 | else |
| 277 | 294 | { |
| 278 | 295 | // File couldn't be moved. |
| 279 | 296 | $_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout'; |
| 280 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 281 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 297 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
| 298 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 299 | + } |
|
| 282 | 300 | } |
| 283 | 301 | } |
| 284 | 302 | |
@@ -291,13 +309,15 @@ discard block |
||
| 291 | 309 | 'errors' => $errors, |
| 292 | 310 | ); |
| 293 | 311 | |
| 294 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 295 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 312 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
| 313 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 314 | + } |
|
| 296 | 315 | } |
| 297 | 316 | |
| 298 | 317 | // If there's no errors to this point. We still do need to apply some additional checks before we are finished. |
| 299 | - if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
|
| 300 | - attachmentChecks($attachID); |
|
| 318 | + if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) { |
|
| 319 | + attachmentChecks($attachID); |
|
| 320 | + } |
|
| 301 | 321 | } |
| 302 | 322 | |
| 303 | 323 | // Mod authors, finally a hook to hang an alternate attachment upload system upon |
@@ -344,14 +364,15 @@ discard block |
||
| 344 | 364 | |
| 345 | 365 | $_SESSION['already_attached'][$attachmentOptions['attachID']] = $attachmentOptions['attachID']; |
| 346 | 366 | |
| 347 | - if (!empty($attachmentOptions['thumb'])) |
|
| 348 | - $_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb']; |
|
| 367 | + if (!empty($attachmentOptions['thumb'])) { |
|
| 368 | + $_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb']; |
|
| 369 | + } |
|
| 349 | 370 | |
| 350 | - if ($this->_msg) |
|
| 351 | - assignAttachments($_SESSION['already_attached'], $this->_msg); |
|
| 371 | + if ($this->_msg) { |
|
| 372 | + assignAttachments($_SESSION['already_attached'], $this->_msg); |
|
| 373 | + } |
|
| 352 | 374 | } |
| 353 | - } |
|
| 354 | - else |
|
| 375 | + } else |
|
| 355 | 376 | { |
| 356 | 377 | // Sort out the errors for display and delete any associated files. |
| 357 | 378 | $log_these = array('attachments_no_create', 'attachments_no_write', 'attach_timeout', 'ran_out_of_space', 'cant_access_upload_path', 'attach_0_byte_file'); |
@@ -363,14 +384,16 @@ discard block |
||
| 363 | 384 | if (!is_array($error)) |
| 364 | 385 | { |
| 365 | 386 | $attachmentOptions['errors'][] = $txt[$error]; |
| 366 | - if (in_array($error, $log_these)) |
|
| 367 | - log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
| 387 | + if (in_array($error, $log_these)) { |
|
| 388 | + log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
| 389 | + } |
|
| 390 | + } else { |
|
| 391 | + $attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]); |
|
| 368 | 392 | } |
| 369 | - else |
|
| 370 | - $attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]); |
|
| 371 | 393 | } |
| 372 | - if (file_exists($attachment['tmp_name'])) |
|
| 373 | - unlink($attachment['tmp_name']); |
|
| 394 | + if (file_exists($attachment['tmp_name'])) { |
|
| 395 | + unlink($attachment['tmp_name']); |
|
| 396 | + } |
|
| 374 | 397 | } |
| 375 | 398 | |
| 376 | 399 | // You don't need to know. |
@@ -382,8 +405,9 @@ discard block |
||
| 382 | 405 | } |
| 383 | 406 | |
| 384 | 407 | // Temp save this on the db. |
| 385 | - if (!empty($_SESSION['already_attached'])) |
|
| 386 | - $this->_attachSuccess = $_SESSION['already_attached']; |
|
| 408 | + if (!empty($_SESSION['already_attached'])) { |
|
| 409 | + $this->_attachSuccess = $_SESSION['already_attached']; |
|
| 410 | + } |
|
| 387 | 411 | |
| 388 | 412 | unset($_SESSION['temp_attachments']); |
| 389 | 413 | } |
@@ -403,14 +427,16 @@ discard block |
||
| 403 | 427 | if ($this->_sa == 'add') |
| 404 | 428 | { |
| 405 | 429 | // Is there any generic errors? made some sense out of them! |
| 406 | - if ($this->_generalErrors) |
|
| 407 | - foreach ($this->_generalErrors as $k => $v) |
|
| 430 | + if ($this->_generalErrors) { |
|
| 431 | + foreach ($this->_generalErrors as $k => $v) |
|
| 408 | 432 | $this->_generalErrors[$k] = (is_array($v) ? vsprintf($txt[$v[0]], $v[1]) : $txt[$v]); |
| 433 | + } |
|
| 409 | 434 | |
| 410 | 435 | // Gotta urlencode the filename. |
| 411 | - if ($this->_attachResults) |
|
| 412 | - foreach ($this->_attachResults as $k => $v) |
|
| 436 | + if ($this->_attachResults) { |
|
| 437 | + foreach ($this->_attachResults as $k => $v) |
|
| 413 | 438 | $this->_attachResults[$k]['name'] = urlencode($this->_attachResults[$k]['name']); |
| 439 | + } |
|
| 414 | 440 | |
| 415 | 441 | $this->_response = array( |
| 416 | 442 | 'files' => $this->_attachResults ? $this->_attachResults : false, |
@@ -419,9 +445,10 @@ discard block |
||
| 419 | 445 | } |
| 420 | 446 | |
| 421 | 447 | // Rest of us mere mortals gets no special treatment... |
| 422 | - elseif (!empty($data)) |
|
| 423 | - if (!empty($data['text']) && !empty($txt[$data['text']])) |
|
| 448 | + elseif (!empty($data)) { |
|
| 449 | + if (!empty($data['text']) && !empty($txt[$data['text']])) |
|
| 424 | 450 | $this->_response['text'] = $txt[$data['text']]; |
| 451 | + } |
|
| 425 | 452 | } |
| 426 | 453 | |
| 427 | 454 | protected function sendResponse() |
@@ -430,11 +457,11 @@ discard block |
||
| 430 | 457 | |
| 431 | 458 | ob_end_clean(); |
| 432 | 459 | |
| 433 | - if (!empty($modSettings['CompressedOutput'])) |
|
| 434 | - @ob_start('ob_gzhandler'); |
|
| 435 | - |
|
| 436 | - else |
|
| 437 | - ob_start(); |
|
| 460 | + if (!empty($modSettings['CompressedOutput'])) { |
|
| 461 | + @ob_start('ob_gzhandler'); |
|
| 462 | + } else { |
|
| 463 | + ob_start(); |
|
| 464 | + } |
|
| 438 | 465 | |
| 439 | 466 | // Set the header. |
| 440 | 467 | header('Content-Type: application/json; charset='. $context['character_set'] .''); |
@@ -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']; |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | * |
| 174 | 174 | * @param string $post_errors A string of info about errors encountered trying to save this draft |
| 175 | 175 | * @param array $recipientList An array of data about who this PM is being sent to |
| 176 | - * @return boolean false if you can't save the draft, true if we're doing this via XML more than 5 seconds after the last save, nothing otherwise |
|
| 176 | + * @return boolean|null false if you can't save the draft, true if we're doing this via XML more than 5 seconds after the last save, nothing otherwise |
|
| 177 | 177 | */ |
| 178 | 178 | function SavePMDraft(&$post_errors, $recipientList) |
| 179 | 179 | { |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | * |
| 389 | 389 | * @param int $id_draft The ID of the draft to delete |
| 390 | 390 | * @param boolean $check Whether or not to check that the draft belongs to the current user |
| 391 | - * @return boolean False if it couldn't be deleted (doesn't return anything otherwise) |
|
| 391 | + * @return false|null False if it couldn't be deleted (doesn't return anything otherwise) |
|
| 392 | 392 | */ |
| 393 | 393 | function DeleteDraft($id_draft, $check = true) |
| 394 | 394 | { |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | * @param int $member_id ID of the member to show drafts for |
| 423 | 423 | * @param boolean|integer $topic If $type is 1, this can be set to only load drafts for posts in the specific topic |
| 424 | 424 | * @param int $draft_type The type of drafts to show - 0 for post drafts, 1 for PM drafts |
| 425 | - * @return boolean False if the drafts couldn't be loaded, nothing otherwise |
|
| 425 | + * @return false|null False if the drafts couldn't be loaded, nothing otherwise |
|
| 426 | 426 | */ |
| 427 | 427 | function ShowDrafts($member_id, $topic = false, $draft_type = 0) |
| 428 | 428 | { |
@@ -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. |
@@ -86,7 +86,7 @@ |
||
| 86 | 86 | foreach ($board['children'] as $child) |
| 87 | 87 | { |
| 88 | 88 | if (!$child['is_redirect']) |
| 89 | - $child['link'] = ''. ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')"><span class="new_posts">' . $txt['new'] . '</span></a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>'; |
|
| 89 | + $child['link'] = '' . ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')"><span class="new_posts">' . $txt['new'] . '</span></a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>'; |
|
| 90 | 90 | else |
| 91 | 91 | $child['link'] = '<a href="' . $child['href'] . '" title="' . comma_format($child['posts']) . ' ' . $txt['redirects'] . '">' . $child['name'] . '</a>'; |
| 92 | 92 | |
@@ -18,11 +18,12 @@ discard block |
||
| 18 | 18 | global $context, $settings, $options, $scripturl, $modSettings, $txt; |
| 19 | 19 | |
| 20 | 20 | // Let them know why their message became unapproved. |
| 21 | - if ($context['becomesUnapproved']) |
|
| 22 | - echo ' |
|
| 21 | + if ($context['becomesUnapproved']) { |
|
| 22 | + echo ' |
|
| 23 | 23 | <div class="noticebox"> |
| 24 | 24 | ', $txt['post_becomesUnapproved'], ' |
| 25 | 25 | </div>'; |
| 26 | + } |
|
| 26 | 27 | |
| 27 | 28 | if (!empty($context['boards']) && (!empty($options['show_children']) || $context['start'] == 0)) |
| 28 | 29 | { |
@@ -46,17 +47,19 @@ discard block |
||
| 46 | 47 | </a>'; |
| 47 | 48 | |
| 48 | 49 | // Has it outstanding posts for approval? |
| 49 | - if ($board['can_approve_posts'] && ($board['unapproved_posts'] || $board['unapproved_topics'])) |
|
| 50 | - echo ' |
|
| 50 | + if ($board['can_approve_posts'] && ($board['unapproved_posts'] || $board['unapproved_topics'])) { |
|
| 51 | + echo ' |
|
| 51 | 52 | <a href="', $scripturl, '?action=moderate;area=postmod;sa=', ($board['unapproved_topics'] > 0 ? 'topics' : 'posts'), ';brd=', $board['id'], ';', $context['session_var'], '=', $context['session_id'], '" title="', sprintf($txt['unapproved_posts'], $board['unapproved_topics'], $board['unapproved_posts']), '" class="moderation_link">(!)</a>'; |
| 53 | + } |
|
| 52 | 54 | |
| 53 | 55 | echo ' |
| 54 | 56 | <p class="board_description">', $board['description'], '</p>'; |
| 55 | 57 | |
| 56 | 58 | // Show the "Moderators: ". Each has name, href, link, and id. (but we're gonna use link_moderators.) |
| 57 | - if (!empty($board['moderators']) || !empty($board['moderator_groups'])) |
|
| 58 | - echo ' |
|
| 59 | + if (!empty($board['moderators']) || !empty($board['moderator_groups'])) { |
|
| 60 | + echo ' |
|
| 59 | 61 | <p class="moderators">', count($board['link_moderators']) === 1 ? $txt['moderator'] : $txt['moderators'], ': ', implode(', ', $board['link_moderators']), '</p>'; |
| 62 | + } |
|
| 60 | 63 | |
| 61 | 64 | // Show some basic information about the number of posts, etc. |
| 62 | 65 | echo ' |
@@ -68,9 +71,10 @@ discard block |
||
| 68 | 71 | </div> |
| 69 | 72 | <div class="lastpost lpr_border">'; |
| 70 | 73 | |
| 71 | - if (!empty($board['last_post']['id'])) |
|
| 72 | - echo ' |
|
| 74 | + if (!empty($board['last_post']['id'])) { |
|
| 75 | + echo ' |
|
| 73 | 76 | <p>', $board['last_post']['last_post_message'], '</p>'; |
| 77 | + } |
|
| 74 | 78 | |
| 75 | 79 | echo ' |
| 76 | 80 | </div>'; |
@@ -84,14 +88,16 @@ discard block |
||
| 84 | 88 | id, name, description, new (is it new?), topics (#), posts (#), href, link, and last_post. */ |
| 85 | 89 | foreach ($board['children'] as $child) |
| 86 | 90 | { |
| 87 | - if (!$child['is_redirect']) |
|
| 88 | - $child['link'] = ''. ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')"><span class="new_posts">' . $txt['new'] . '</span></a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>'; |
|
| 89 | - else |
|
| 90 | - $child['link'] = '<a href="' . $child['href'] . '" title="' . comma_format($child['posts']) . ' ' . $txt['redirects'] . '">' . $child['name'] . '</a>'; |
|
| 91 | + if (!$child['is_redirect']) { |
|
| 92 | + $child['link'] = ''. ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')"><span class="new_posts">' . $txt['new'] . '</span></a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>'; |
|
| 93 | + } else { |
|
| 94 | + $child['link'] = '<a href="' . $child['href'] . '" title="' . comma_format($child['posts']) . ' ' . $txt['redirects'] . '">' . $child['name'] . '</a>'; |
|
| 95 | + } |
|
| 91 | 96 | |
| 92 | 97 | // Has it posts awaiting approval? |
| 93 | - if ($child['can_approve_posts'] && ($child['unapproved_posts'] | $child['unapproved_topics'])) |
|
| 94 | - $child['link'] .= ' <a href="' . $scripturl . '?action=moderate;area=postmod;sa=' . ($child['unapproved_topics'] > 0 ? 'topics' : 'posts') . ';brd=' . $child['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" title="' . sprintf($txt['unapproved_posts'], $child['unapproved_topics'], $child['unapproved_posts']) . '" class="moderation_link">(!)</a>'; |
|
| 98 | + if ($child['can_approve_posts'] && ($child['unapproved_posts'] | $child['unapproved_topics'])) { |
|
| 99 | + $child['link'] .= ' <a href="' . $scripturl . '?action=moderate;area=postmod;sa=' . ($child['unapproved_topics'] > 0 ? 'topics' : 'posts') . ';brd=' . $child['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" title="' . sprintf($txt['unapproved_posts'], $child['unapproved_topics'], $child['unapproved_posts']) . '" class="moderation_link">(!)</a>'; |
|
| 100 | + } |
|
| 95 | 101 | |
| 96 | 102 | $children[] = $child['new'] ? '<span class="strong">' . $child['link'] . '</span>' : '<span>' . $child['link'] . '</span>'; |
| 97 | 103 | } |
@@ -111,8 +117,9 @@ discard block |
||
| 111 | 117 | } |
| 112 | 118 | |
| 113 | 119 | // They can only mark read if they are logged in and it's enabled! |
| 114 | - if (!$context['user']['is_logged']) |
|
| 115 | - unset($context['normal_buttons']['markread']); |
|
| 120 | + if (!$context['user']['is_logged']) { |
|
| 121 | + unset($context['normal_buttons']['markread']); |
|
| 122 | + } |
|
| 116 | 123 | |
| 117 | 124 | if (!$context['no_topic_listing']) |
| 118 | 125 | { |
@@ -139,13 +146,15 @@ discard block |
||
| 139 | 146 | <h3>', $context['name'], '</h3> |
| 140 | 147 | <p>'; |
| 141 | 148 | |
| 142 | - if ($context['description'] != '') |
|
| 143 | - echo ' |
|
| 149 | + if ($context['description'] != '') { |
|
| 150 | + echo ' |
|
| 144 | 151 | ', $context['description']; |
| 152 | + } |
|
| 145 | 153 | |
| 146 | - if (!empty($context['moderators'])) |
|
| 147 | - echo ' |
|
| 154 | + if (!empty($context['moderators'])) { |
|
| 155 | + echo ' |
|
| 148 | 156 | ', count($context['moderators']) === 1 ? $txt['moderator'] : $txt['moderators'], ': ', implode(', ', $context['link_moderators']), '.'; |
| 157 | + } |
|
| 149 | 158 | |
| 150 | 159 | echo ' |
| 151 | 160 | </p> |
@@ -153,9 +162,10 @@ discard block |
||
| 153 | 162 | } |
| 154 | 163 | |
| 155 | 164 | // If Quick Moderation is enabled start the form. |
| 156 | - if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics'])) |
|
| 157 | - echo ' |
|
| 165 | + if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics'])) { |
|
| 166 | + echo ' |
|
| 158 | 167 | <form action="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], '" method="post" accept-charset="', $context['character_set'], '" class="clear" name="quickModForm" id="quickModForm">'; |
| 168 | + } |
|
| 159 | 169 | |
| 160 | 170 | echo ' |
| 161 | 171 | <div id="messageindex">'; |
@@ -165,11 +175,11 @@ discard block |
||
| 165 | 175 | echo ' |
| 166 | 176 | <div class="information">'; |
| 167 | 177 | |
| 168 | - if ($settings['display_who_viewing'] == 1) |
|
| 169 | - echo count($context['view_members']), ' ', count($context['view_members']) === 1 ? $txt['who_member'] : $txt['members']; |
|
| 170 | - |
|
| 171 | - else |
|
| 172 | - echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . (empty($context['view_num_hidden']) || $context['can_moderate_forum'] ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')'); |
|
| 178 | + if ($settings['display_who_viewing'] == 1) { |
|
| 179 | + echo count($context['view_members']), ' ', count($context['view_members']) === 1 ? $txt['who_member'] : $txt['members']; |
|
| 180 | + } else { |
|
| 181 | + echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . (empty($context['view_num_hidden']) || $context['can_moderate_forum'] ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')'); |
|
| 182 | + } |
|
| 173 | 183 | echo $txt['who_and'], $context['view_num_guests'], ' ', $context['view_num_guests'] == 1 ? $txt['guest'] : $txt['guests'], $txt['who_viewing_board']; |
| 174 | 184 | |
| 175 | 185 | echo ' |
@@ -189,32 +199,36 @@ discard block |
||
| 189 | 199 | <div class="lastpost">', $context['topics_headers']['last_post'], '</div>'; |
| 190 | 200 | |
| 191 | 201 | // Show a "select all" box for quick moderation? |
| 192 | - if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1) |
|
| 193 | - echo ' |
|
| 202 | + if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1) { |
|
| 203 | + echo ' |
|
| 194 | 204 | <div class="moderation"> |
| 195 | 205 | <input type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');"> |
| 196 | 206 | </div>'; |
| 207 | + } |
|
| 197 | 208 | |
| 198 | 209 | // If it's on in "image" mode, don't show anything but the column. |
| 199 | - elseif (!empty($context['can_quick_mod'])) |
|
| 200 | - echo ' |
|
| 210 | + elseif (!empty($context['can_quick_mod'])) { |
|
| 211 | + echo ' |
|
| 201 | 212 | <div class="moderation"></div>'; |
| 213 | + } |
|
| 202 | 214 | } |
| 203 | 215 | |
| 204 | 216 | // No topics... just say, "sorry bub". |
| 205 | - else |
|
| 206 | - echo ' |
|
| 217 | + else { |
|
| 218 | + echo ' |
|
| 207 | 219 | <h3 class="titlebg">', $txt['topic_alert_none'], '</h3>'; |
| 220 | + } |
|
| 208 | 221 | |
| 209 | 222 | echo ' |
| 210 | 223 | </div><!-- #topic_header -->'; |
| 211 | 224 | |
| 212 | 225 | // If this person can approve items and we have some awaiting approval tell them. |
| 213 | - if (!empty($context['unapproved_posts_message'])) |
|
| 214 | - echo ' |
|
| 226 | + if (!empty($context['unapproved_posts_message'])) { |
|
| 227 | + echo ' |
|
| 215 | 228 | <div class="information"> |
| 216 | 229 | <span class="alert">!</span> ', $context['unapproved_posts_message'], ' |
| 217 | 230 | </div>'; |
| 231 | + } |
|
| 218 | 232 | |
| 219 | 233 | // Contain the topic list |
| 220 | 234 | echo ' |
@@ -235,25 +249,30 @@ discard block |
||
| 235 | 249 | echo ' |
| 236 | 250 | <div class="icons floatright">'; |
| 237 | 251 | |
| 238 | - if ($topic['is_watched']) |
|
| 239 | - echo ' |
|
| 252 | + if ($topic['is_watched']) { |
|
| 253 | + echo ' |
|
| 240 | 254 | <span class="generic_icons watch" title="', $txt['watching_this_topic'], '"></span>'; |
| 255 | + } |
|
| 241 | 256 | |
| 242 | - if ($topic['is_locked']) |
|
| 243 | - echo ' |
|
| 257 | + if ($topic['is_locked']) { |
|
| 258 | + echo ' |
|
| 244 | 259 | <span class="generic_icons lock"></span>'; |
| 260 | + } |
|
| 245 | 261 | |
| 246 | - if ($topic['is_sticky']) |
|
| 247 | - echo ' |
|
| 262 | + if ($topic['is_sticky']) { |
|
| 263 | + echo ' |
|
| 248 | 264 | <span class="generic_icons sticky"></span>'; |
| 265 | + } |
|
| 249 | 266 | |
| 250 | - if ($topic['is_redirect']) |
|
| 251 | - echo ' |
|
| 267 | + if ($topic['is_redirect']) { |
|
| 268 | + echo ' |
|
| 252 | 269 | <span class="generic_icons move"></span>'; |
| 270 | + } |
|
| 253 | 271 | |
| 254 | - if ($topic['is_poll']) |
|
| 255 | - echo ' |
|
| 272 | + if ($topic['is_poll']) { |
|
| 273 | + echo ' |
|
| 256 | 274 | <span class="generic_icons poll"></span>'; |
| 275 | + } |
|
| 257 | 276 | |
| 258 | 277 | echo ' |
| 259 | 278 | </div>'; |
@@ -285,26 +304,31 @@ discard block |
||
| 285 | 304 | echo ' |
| 286 | 305 | <div class="moderation">'; |
| 287 | 306 | |
| 288 | - if ($options['display_quick_mod'] == 1) |
|
| 289 | - echo ' |
|
| 307 | + if ($options['display_quick_mod'] == 1) { |
|
| 308 | + echo ' |
|
| 290 | 309 | <input type="checkbox" name="topics[]" value="', $topic['id'], '">'; |
| 291 | - else |
|
| 310 | + } else |
|
| 292 | 311 | { |
| 293 | 312 | // Check permissions on each and show only the ones they are allowed to use. |
| 294 | - if ($topic['quick_mod']['remove']) |
|
| 295 | - echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=remove;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons delete" title="', $txt['remove_topic'], '"></span></a>'; |
|
| 313 | + if ($topic['quick_mod']['remove']) { |
|
| 314 | + echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=remove;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons delete" title="', $txt['remove_topic'], '"></span></a>'; |
|
| 315 | + } |
|
| 296 | 316 | |
| 297 | - if ($topic['quick_mod']['lock']) |
|
| 298 | - echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=lock;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons lock" title="', $topic['is_locked'] ? $txt['set_unlock'] : $txt['set_lock'], '"></span></a>'; |
|
| 317 | + if ($topic['quick_mod']['lock']) { |
|
| 318 | + echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=lock;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons lock" title="', $topic['is_locked'] ? $txt['set_unlock'] : $txt['set_lock'], '"></span></a>'; |
|
| 319 | + } |
|
| 299 | 320 | |
| 300 | - if ($topic['quick_mod']['lock'] || $topic['quick_mod']['remove']) |
|
| 301 | - echo '<br>'; |
|
| 321 | + if ($topic['quick_mod']['lock'] || $topic['quick_mod']['remove']) { |
|
| 322 | + echo '<br>'; |
|
| 323 | + } |
|
| 302 | 324 | |
| 303 | - if ($topic['quick_mod']['sticky']) |
|
| 304 | - echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=sticky;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons sticky" title="', $topic['is_sticky'] ? $txt['set_nonsticky'] : $txt['set_sticky'], '"></span></a>'; |
|
| 325 | + if ($topic['quick_mod']['sticky']) { |
|
| 326 | + echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=sticky;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons sticky" title="', $topic['is_sticky'] ? $txt['set_nonsticky'] : $txt['set_sticky'], '"></span></a>'; |
|
| 327 | + } |
|
| 305 | 328 | |
| 306 | - if ($topic['quick_mod']['move']) |
|
| 307 | - echo '<a href="', $scripturl, '?action=movetopic;current_board=', $context['current_board'], ';board=', $context['current_board'], '.', $context['start'], ';topic=', $topic['id'], '.0"><span class="generic_icons move" title="', $txt['move_topic'], '"></span></a>'; |
|
| 329 | + if ($topic['quick_mod']['move']) { |
|
| 330 | + echo '<a href="', $scripturl, '?action=movetopic;current_board=', $context['current_board'], ';board=', $context['current_board'], '.', $context['start'], ';topic=', $topic['id'], '.0"><span class="generic_icons move" title="', $txt['move_topic'], '"></span></a>'; |
|
| 331 | + } |
|
| 308 | 332 | } |
| 309 | 333 | echo ' |
| 310 | 334 | </div><!-- .moderation -->'; |
@@ -322,18 +346,20 @@ discard block |
||
| 322 | 346 | <select class="qaction" name="qaction"', $context['can_move'] ? ' onchange="this.form.move_to.disabled = (this.options[this.selectedIndex].value != \'move\');"' : '', '> |
| 323 | 347 | <option value="">--------</option>'; |
| 324 | 348 | |
| 325 | - foreach ($context['qmod_actions'] as $qmod_action) |
|
| 326 | - if ($context['can_' . $qmod_action]) |
|
| 349 | + foreach ($context['qmod_actions'] as $qmod_action) { |
|
| 350 | + if ($context['can_' . $qmod_action]) |
|
| 327 | 351 | echo ' |
| 328 | 352 | <option value="' . $qmod_action . '">' . $txt['quick_mod_' . $qmod_action] . '</option>'; |
| 353 | + } |
|
| 329 | 354 | |
| 330 | 355 | echo ' |
| 331 | 356 | </select>'; |
| 332 | 357 | |
| 333 | 358 | // Show a list of boards they can move the topic to. |
| 334 | - if ($context['can_move']) |
|
| 335 | - echo ' |
|
| 359 | + if ($context['can_move']) { |
|
| 360 | + echo ' |
|
| 336 | 361 | <span id="quick_mod_jump_to"></span>'; |
| 362 | + } |
|
| 337 | 363 | |
| 338 | 364 | echo ' |
| 339 | 365 | <input type="submit" value="', $txt['quick_mod_go'], '" onclick="return document.forms.quickModForm.qaction.value != \'\' && confirm(\'', $txt['quickmod_confirm'], '\');" class="button qaction"> |
@@ -344,10 +370,11 @@ discard block |
||
| 344 | 370 | </div><!-- #messageindex -->'; |
| 345 | 371 | |
| 346 | 372 | // Finish off the form - again. |
| 347 | - if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics'])) |
|
| 348 | - echo ' |
|
| 373 | + if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics'])) { |
|
| 374 | + echo ' |
|
| 349 | 375 | <input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '"> |
| 350 | 376 | </form>'; |
| 377 | + } |
|
| 351 | 378 | |
| 352 | 379 | // Mobile action buttons (bottom) |
| 353 | 380 | echo ' |
@@ -369,8 +396,8 @@ discard block |
||
| 369 | 396 | // Show breadcrumbs at the bottom too. |
| 370 | 397 | theme_linktree(); |
| 371 | 398 | |
| 372 | - if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']) && $context['can_move']) |
|
| 373 | - echo ' |
|
| 399 | + if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']) && $context['can_move']) { |
|
| 400 | + echo ' |
|
| 374 | 401 | <script> |
| 375 | 402 | if (typeof(window.XMLHttpRequest) != "undefined") |
| 376 | 403 | aJumpTo[aJumpTo.length] = new JumpTo({ |
@@ -389,6 +416,7 @@ discard block |
||
| 389 | 416 | sCustomName: "move_to" |
| 390 | 417 | }); |
| 391 | 418 | </script>'; |
| 419 | + } |
|
| 392 | 420 | |
| 393 | 421 | // Javascript for inline editing. |
| 394 | 422 | echo ' |
@@ -425,8 +453,8 @@ discard block |
||
| 425 | 453 | <div class="information"> |
| 426 | 454 | <p class="floatright" id="message_index_jump_to"></p>'; |
| 427 | 455 | |
| 428 | - if (empty($context['no_topic_listing'])) |
|
| 429 | - echo ' |
|
| 456 | + if (empty($context['no_topic_listing'])) { |
|
| 457 | + echo ' |
|
| 430 | 458 | <p class="floatleft">', !empty($modSettings['enableParticipation']) && $context['user']['is_logged'] ? ' |
| 431 | 459 | <img src="' . $settings['images_url'] . '/icons/profile_sm.png" alt="" class="centericon"> ' . $txt['participation_caption'] . '<br>' : '', ' |
| 432 | 460 | '. ($modSettings['pollMode'] == '1' ? '<span class="generic_icons poll centericon"></span> ' . $txt['poll'] : '') . '<br> |
@@ -436,9 +464,10 @@ discard block |
||
| 436 | 464 | <span class="generic_icons lock centericon"></span> ' . $txt['locked_topic'] . '<br> |
| 437 | 465 | <span class="generic_icons sticky centericon"></span> ' . $txt['sticky_topic'] . '<br> |
| 438 | 466 | </p>'; |
| 467 | + } |
|
| 439 | 468 | |
| 440 | - if (!empty($context['jump_to'])) |
|
| 441 | - echo ' |
|
| 469 | + if (!empty($context['jump_to'])) { |
|
| 470 | + echo ' |
|
| 442 | 471 | <script> |
| 443 | 472 | if (typeof(window.XMLHttpRequest) != "undefined") |
| 444 | 473 | aJumpTo[aJumpTo.length] = new JumpTo({ |
@@ -454,6 +483,7 @@ discard block |
||
| 454 | 483 | sGoButtonLabel: "', $txt['quick_mod_go'], '" |
| 455 | 484 | }); |
| 456 | 485 | </script>'; |
| 486 | + } |
|
| 457 | 487 | |
| 458 | 488 | echo ' |
| 459 | 489 | <br class="clear"> |
@@ -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 | * The main dispatcher; doesn't do anything, just delegates. |
@@ -92,18 +93,19 @@ discard block |
||
| 92 | 93 | checkSession('get'); |
| 93 | 94 | validateToken('admin-bm-' . (int) $_REQUEST['src_board'], 'request'); |
| 94 | 95 | |
| 95 | - if ($_REQUEST['move_to'] === 'top') |
|
| 96 | - $boardOptions = array( |
|
| 96 | + if ($_REQUEST['move_to'] === 'top') { |
|
| 97 | + $boardOptions = array( |
|
| 97 | 98 | 'move_to' => $_REQUEST['move_to'], |
| 98 | 99 | 'target_category' => (int) $_REQUEST['target_cat'], |
| 99 | 100 | 'move_first_child' => true, |
| 100 | 101 | ); |
| 101 | - else |
|
| 102 | - $boardOptions = array( |
|
| 102 | + } else { |
|
| 103 | + $boardOptions = array( |
|
| 103 | 104 | 'move_to' => $_REQUEST['move_to'], |
| 104 | 105 | 'target_board' => (int) $_REQUEST['target_board'], |
| 105 | 106 | 'move_first_child' => true, |
| 106 | 107 | ); |
| 108 | + } |
|
| 107 | 109 | modifyBoard((int) $_REQUEST['src_board'], $boardOptions); |
| 108 | 110 | } |
| 109 | 111 | |
@@ -148,15 +150,16 @@ discard block |
||
| 148 | 150 | $security = $context['session_var'] . '=' . $context['session_id'] . ';' . $context['admin-bm-' . $context['move_board'] . '_token_var'] . '=' . $context['admin-bm-' . $context['move_board'] . '_token']; |
| 149 | 151 | foreach ($boardList[$catid] as $boardid) |
| 150 | 152 | { |
| 151 | - if (!isset($context['categories'][$catid]['move_link'])) |
|
| 152 | - $context['categories'][$catid]['move_link'] = array( |
|
| 153 | + if (!isset($context['categories'][$catid]['move_link'])) { |
|
| 154 | + $context['categories'][$catid]['move_link'] = array( |
|
| 153 | 155 | 'child_level' => 0, |
| 154 | 156 | 'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'', |
| 155 | 157 | 'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_board=' . $boardid . ';move_to=before;' . $security, |
| 156 | 158 | ); |
| 159 | + } |
|
| 157 | 160 | |
| 158 | - if (!$context['categories'][$catid]['boards'][$boardid]['move']) |
|
| 159 | - $context['categories'][$catid]['boards'][$boardid]['move_links'] = array( |
|
| 161 | + if (!$context['categories'][$catid]['boards'][$boardid]['move']) { |
|
| 162 | + $context['categories'][$catid]['boards'][$boardid]['move_links'] = array( |
|
| 160 | 163 | array( |
| 161 | 164 | 'child_level' => $boards[$boardid]['level'], |
| 162 | 165 | 'label' => $txt['mboards_order_after'] . '\'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'', |
@@ -170,34 +173,39 @@ discard block |
||
| 170 | 173 | 'class' => 'here', |
| 171 | 174 | ), |
| 172 | 175 | ); |
| 176 | + } |
|
| 173 | 177 | |
| 174 | 178 | $difference = $boards[$boardid]['level'] - $prev_child_level; |
| 175 | - if ($difference == 1) |
|
| 176 | - array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null); |
|
| 177 | - elseif ($difference < 0) |
|
| 179 | + if ($difference == 1) { |
|
| 180 | + array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null); |
|
| 181 | + } elseif ($difference < 0) |
|
| 178 | 182 | { |
| 179 | - if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) |
|
| 180 | - $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array(); |
|
| 181 | - for ($i = 0; $i < -$difference; $i++) |
|
| 182 | - if (($temp = array_pop($stack)) != null) |
|
| 183 | + if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) { |
|
| 184 | + $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array(); |
|
| 185 | + } |
|
| 186 | + for ($i = 0; $i < -$difference; $i++) { |
|
| 187 | + if (($temp = array_pop($stack)) != null) |
|
| 183 | 188 | array_unshift($context['categories'][$catid]['boards'][$prev_board]['move_links'], $temp); |
| 189 | + } |
|
| 184 | 190 | } |
| 185 | 191 | |
| 186 | 192 | $prev_board = $boardid; |
| 187 | 193 | $prev_child_level = $boards[$boardid]['level']; |
| 188 | 194 | |
| 189 | 195 | } |
| 190 | - if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) |
|
| 191 | - $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']); |
|
| 192 | - elseif (!empty($stack)) |
|
| 193 | - $context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack; |
|
| 196 | + if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) { |
|
| 197 | + $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']); |
|
| 198 | + } elseif (!empty($stack)) { |
|
| 199 | + $context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack; |
|
| 200 | + } |
|
| 194 | 201 | |
| 195 | - if (empty($boardList[$catid])) |
|
| 196 | - $context['categories'][$catid]['move_link'] = array( |
|
| 202 | + if (empty($boardList[$catid])) { |
|
| 203 | + $context['categories'][$catid]['move_link'] = array( |
|
| 197 | 204 | 'child_level' => 0, |
| 198 | 205 | 'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($tree['node']['name']) . '\'', |
| 199 | 206 | 'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_cat=' . $catid . ';move_to=top;' . $security, |
| 200 | 207 | ); |
| 208 | + } |
|
| 201 | 209 | } |
| 202 | 210 | } |
| 203 | 211 | |
@@ -253,9 +261,9 @@ discard block |
||
| 253 | 261 | ); |
| 254 | 262 | } |
| 255 | 263 | // Category doesn't exist, man... sorry. |
| 256 | - elseif (!isset($cat_tree[$_REQUEST['cat']])) |
|
| 257 | - redirectexit('action=admin;area=manageboards'); |
|
| 258 | - else |
|
| 264 | + elseif (!isset($cat_tree[$_REQUEST['cat']])) { |
|
| 265 | + redirectexit('action=admin;area=manageboards'); |
|
| 266 | + } else |
|
| 259 | 267 | { |
| 260 | 268 | $context['category'] = array( |
| 261 | 269 | 'id' => $_REQUEST['cat'], |
@@ -267,30 +275,31 @@ discard block |
||
| 267 | 275 | 'is_empty' => empty($cat_tree[$_REQUEST['cat']]['children']) |
| 268 | 276 | ); |
| 269 | 277 | |
| 270 | - foreach ($boardList[$_REQUEST['cat']] as $child_board) |
|
| 271 | - $context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name']; |
|
| 278 | + foreach ($boardList[$_REQUEST['cat']] as $child_board) { |
|
| 279 | + $context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name']; |
|
| 280 | + } |
|
| 272 | 281 | } |
| 273 | 282 | |
| 274 | 283 | $prevCat = 0; |
| 275 | 284 | foreach ($cat_tree as $catid => $tree) |
| 276 | 285 | { |
| 277 | - if ($catid == $_REQUEST['cat'] && $prevCat > 0) |
|
| 278 | - $context['category_order'][$prevCat]['selected'] = true; |
|
| 279 | - elseif ($catid != $_REQUEST['cat']) |
|
| 280 | - $context['category_order'][$catid] = array( |
|
| 286 | + if ($catid == $_REQUEST['cat'] && $prevCat > 0) { |
|
| 287 | + $context['category_order'][$prevCat]['selected'] = true; |
|
| 288 | + } elseif ($catid != $_REQUEST['cat']) { |
|
| 289 | + $context['category_order'][$catid] = array( |
|
| 281 | 290 | 'id' => $catid, |
| 282 | 291 | 'name' => $txt['mboards_order_after'] . $tree['node']['name'], |
| 283 | 292 | 'selected' => false, |
| 284 | 293 | 'true_name' => $tree['node']['name'] |
| 285 | 294 | ); |
| 295 | + } |
|
| 286 | 296 | $prevCat = $catid; |
| 287 | 297 | } |
| 288 | 298 | if (!isset($_REQUEST['delete'])) |
| 289 | 299 | { |
| 290 | 300 | $context['sub_template'] = 'modify_category'; |
| 291 | 301 | $context['page_title'] = $_REQUEST['sa'] == 'newcat' ? $txt['mboards_new_cat_name'] : $txt['catEdit']; |
| 292 | - } |
|
| 293 | - else |
|
| 302 | + } else |
|
| 294 | 303 | { |
| 295 | 304 | $context['sub_template'] = 'confirm_category_delete'; |
| 296 | 305 | $context['page_title'] = $txt['mboards_delete_cat']; |
@@ -327,8 +336,9 @@ discard block |
||
| 327 | 336 | { |
| 328 | 337 | $catOptions = array(); |
| 329 | 338 | |
| 330 | - if (isset($_POST['cat_order'])) |
|
| 331 | - $catOptions['move_after'] = (int) $_POST['cat_order']; |
|
| 339 | + if (isset($_POST['cat_order'])) { |
|
| 340 | + $catOptions['move_after'] = (int) $_POST['cat_order']; |
|
| 341 | + } |
|
| 332 | 342 | |
| 333 | 343 | // Change "This & That" to "This & That" but don't change "¢" to "&cent;"... |
| 334 | 344 | $catOptions['cat_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['cat_name']), false, '', $context['description_allowed_tags']); |
@@ -336,10 +346,11 @@ discard block |
||
| 336 | 346 | |
| 337 | 347 | $catOptions['is_collapsible'] = isset($_POST['collapse']); |
| 338 | 348 | |
| 339 | - if (isset($_POST['add'])) |
|
| 340 | - createCategory($catOptions); |
|
| 341 | - else |
|
| 342 | - modifyCategory($_POST['cat'], $catOptions); |
|
| 349 | + if (isset($_POST['add'])) { |
|
| 350 | + createCategory($catOptions); |
|
| 351 | + } else { |
|
| 352 | + modifyCategory($_POST['cat'], $catOptions); |
|
| 353 | + } |
|
| 343 | 354 | } |
| 344 | 355 | // If they want to delete - first give them confirmation. |
| 345 | 356 | elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['empty'])) |
@@ -353,13 +364,14 @@ discard block |
||
| 353 | 364 | // First off - check if we are moving all the current boards first - before we start deleting! |
| 354 | 365 | if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1) |
| 355 | 366 | { |
| 356 | - if (empty($_POST['cat_to'])) |
|
| 357 | - fatal_lang_error('mboards_delete_error'); |
|
| 367 | + if (empty($_POST['cat_to'])) { |
|
| 368 | + fatal_lang_error('mboards_delete_error'); |
|
| 369 | + } |
|
| 358 | 370 | |
| 359 | 371 | deleteCategories(array($_POST['cat']), (int) $_POST['cat_to']); |
| 372 | + } else { |
|
| 373 | + deleteCategories(array($_POST['cat'])); |
|
| 360 | 374 | } |
| 361 | - else |
|
| 362 | - deleteCategories(array($_POST['cat'])); |
|
| 363 | 375 | } |
| 364 | 376 | |
| 365 | 377 | redirectexit('action=admin;area=manageboards'); |
@@ -404,8 +416,9 @@ discard block |
||
| 404 | 416 | if ($_REQUEST['sa'] == 'newboard') |
| 405 | 417 | { |
| 406 | 418 | // Category doesn't exist, man... sorry. |
| 407 | - if (empty($_REQUEST['cat'])) |
|
| 408 | - redirectexit('action=admin;area=manageboards'); |
|
| 419 | + if (empty($_REQUEST['cat'])) { |
|
| 420 | + redirectexit('action=admin;area=manageboards'); |
|
| 421 | + } |
|
| 409 | 422 | |
| 410 | 423 | // Some things that need to be setup for a new board. |
| 411 | 424 | $curBoard = array( |
@@ -429,8 +442,7 @@ discard block |
||
| 429 | 442 | 'category' => (int) $_REQUEST['cat'], |
| 430 | 443 | 'no_children' => true, |
| 431 | 444 | ); |
| 432 | - } |
|
| 433 | - else |
|
| 445 | + } else |
|
| 434 | 446 | { |
| 435 | 447 | // Just some easy shortcuts. |
| 436 | 448 | $curBoard = &$boards[$_REQUEST['boardid']]; |
@@ -478,8 +490,9 @@ discard block |
||
| 478 | 490 | ); |
| 479 | 491 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 480 | 492 | { |
| 481 | - if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1) |
|
| 482 | - $curBoard['member_groups'][] = $row['id_group']; |
|
| 493 | + if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1) { |
|
| 494 | + $curBoard['member_groups'][] = $row['id_group']; |
|
| 495 | + } |
|
| 483 | 496 | |
| 484 | 497 | $context['groups'][(int) $row['id_group']] = array( |
| 485 | 498 | 'id' => $row['id_group'], |
@@ -492,8 +505,9 @@ discard block |
||
| 492 | 505 | $smcFunc['db_free_result']($request); |
| 493 | 506 | |
| 494 | 507 | // Category doesn't exist, man... sorry. |
| 495 | - if (!isset($boardList[$curBoard['category']])) |
|
| 496 | - redirectexit('action=admin;area=manageboards'); |
|
| 508 | + if (!isset($boardList[$curBoard['category']])) { |
|
| 509 | + redirectexit('action=admin;area=manageboards'); |
|
| 510 | + } |
|
| 497 | 511 | |
| 498 | 512 | foreach ($boardList[$curBoard['category']] as $boardid) |
| 499 | 513 | { |
@@ -507,8 +521,7 @@ discard block |
||
| 507 | 521 | 'is_child' => false, |
| 508 | 522 | 'selected' => true |
| 509 | 523 | ); |
| 510 | - } |
|
| 511 | - else |
|
| 524 | + } else |
|
| 512 | 525 | { |
| 513 | 526 | $context['board_order'][] = array( |
| 514 | 527 | 'id' => $boardid, |
@@ -525,19 +538,21 @@ discard block |
||
| 525 | 538 | $context['can_move_children'] = false; |
| 526 | 539 | $context['children'] = $boards[$_REQUEST['boardid']]['tree']['children']; |
| 527 | 540 | |
| 528 | - foreach ($context['board_order'] as $lBoard) |
|
| 529 | - if ($lBoard['is_child'] == false && $lBoard['selected'] == false) |
|
| 541 | + foreach ($context['board_order'] as $lBoard) { |
|
| 542 | + if ($lBoard['is_child'] == false && $lBoard['selected'] == false) |
|
| 530 | 543 | $context['can_move_children'] = true; |
| 544 | + } |
|
| 531 | 545 | } |
| 532 | 546 | |
| 533 | 547 | // Get other available categories. |
| 534 | 548 | $context['categories'] = array(); |
| 535 | - foreach ($cat_tree as $catID => $tree) |
|
| 536 | - $context['categories'][] = array( |
|
| 549 | + foreach ($cat_tree as $catID => $tree) { |
|
| 550 | + $context['categories'][] = array( |
|
| 537 | 551 | 'id' => $catID == $curBoard['category'] ? 0 : $catID, |
| 538 | 552 | 'name' => $tree['node']['name'], |
| 539 | 553 | 'selected' => $catID == $curBoard['category'] |
| 540 | 554 | ); |
| 555 | + } |
|
| 541 | 556 | |
| 542 | 557 | $request = $smcFunc['db_query']('', ' |
| 543 | 558 | SELECT mem.id_member, mem.real_name |
@@ -549,14 +564,16 @@ discard block |
||
| 549 | 564 | ) |
| 550 | 565 | ); |
| 551 | 566 | $context['board']['moderators'] = array(); |
| 552 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 553 | - $context['board']['moderators'][$row['id_member']] = $row['real_name']; |
|
| 567 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 568 | + $context['board']['moderators'][$row['id_member']] = $row['real_name']; |
|
| 569 | + } |
|
| 554 | 570 | $smcFunc['db_free_result']($request); |
| 555 | 571 | |
| 556 | 572 | $context['board']['moderator_list'] = empty($context['board']['moderators']) ? '' : '"' . implode('", "', $context['board']['moderators']) . '"'; |
| 557 | 573 | |
| 558 | - if (!empty($context['board']['moderators'])) |
|
| 559 | - list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1); |
|
| 574 | + if (!empty($context['board']['moderators'])) { |
|
| 575 | + list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1); |
|
| 576 | + } |
|
| 560 | 577 | |
| 561 | 578 | // Get all the groups assigned as moderators |
| 562 | 579 | $request = $smcFunc['db_query']('', ' |
@@ -568,14 +585,16 @@ discard block |
||
| 568 | 585 | ) |
| 569 | 586 | ); |
| 570 | 587 | $context['board']['moderator_groups'] = array(); |
| 571 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 572 | - $context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name']; |
|
| 588 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 589 | + $context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name']; |
|
| 590 | + } |
|
| 573 | 591 | $smcFunc['db_free_result']($request); |
| 574 | 592 | |
| 575 | 593 | $context['board']['moderator_groups_list'] = empty($context['board']['moderator_groups']) ? '' : '"' . implode('", &qout;', $context['board']['moderator_groups']) . '"'; |
| 576 | 594 | |
| 577 | - if (!empty($context['board']['moderator_groups'])) |
|
| 578 | - list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1); |
|
| 595 | + if (!empty($context['board']['moderator_groups'])) { |
|
| 596 | + list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1); |
|
| 597 | + } |
|
| 579 | 598 | |
| 580 | 599 | // Get all the themes... |
| 581 | 600 | $request = $smcFunc['db_query']('', ' |
@@ -587,8 +606,9 @@ discard block |
||
| 587 | 606 | ) |
| 588 | 607 | ); |
| 589 | 608 | $context['themes'] = array(); |
| 590 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 591 | - $context['themes'][] = $row; |
|
| 609 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 610 | + $context['themes'][] = $row; |
|
| 611 | + } |
|
| 592 | 612 | $smcFunc['db_free_result']($request); |
| 593 | 613 | |
| 594 | 614 | if (!isset($_REQUEST['delete'])) |
@@ -596,8 +616,7 @@ discard block |
||
| 596 | 616 | $context['sub_template'] = 'modify_board'; |
| 597 | 617 | $context['page_title'] = $txt['boardsEdit']; |
| 598 | 618 | loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
| 599 | - } |
|
| 600 | - else |
|
| 619 | + } else |
|
| 601 | 620 | { |
| 602 | 621 | $context['sub_template'] = 'confirm_board_delete'; |
| 603 | 622 | $context['page_title'] = $txt['mboards_delete_board']; |
@@ -641,8 +660,9 @@ discard block |
||
| 641 | 660 | // Change the boardorder of this board? |
| 642 | 661 | elseif (!empty($_POST['placement']) && !empty($_POST['board_order'])) |
| 643 | 662 | { |
| 644 | - if (!in_array($_POST['placement'], array('before', 'after', 'child'))) |
|
| 645 | - fatal_lang_error('mangled_post', false); |
|
| 663 | + if (!in_array($_POST['placement'], array('before', 'after', 'child'))) { |
|
| 664 | + fatal_lang_error('mangled_post', false); |
|
| 665 | + } |
|
| 646 | 666 | |
| 647 | 667 | $boardOptions['move_to'] = $_POST['placement']; |
| 648 | 668 | $boardOptions['target_board'] = (int) $_POST['board_order']; |
@@ -655,13 +675,14 @@ discard block |
||
| 655 | 675 | $boardOptions['access_groups'] = array(); |
| 656 | 676 | $boardOptions['deny_groups'] = array(); |
| 657 | 677 | |
| 658 | - if (!empty($_POST['groups'])) |
|
| 659 | - foreach ($_POST['groups'] as $group => $action) |
|
| 678 | + if (!empty($_POST['groups'])) { |
|
| 679 | + foreach ($_POST['groups'] as $group => $action) |
|
| 660 | 680 | { |
| 661 | 681 | if ($action == 'allow') |
| 662 | 682 | $boardOptions['access_groups'][] = (int) $group; |
| 663 | - elseif ($action == 'deny') |
|
| 664 | - $boardOptions['deny_groups'][] = (int) $group; |
|
| 683 | + } elseif ($action == 'deny') { |
|
| 684 | + $boardOptions['deny_groups'][] = (int) $group; |
|
| 685 | + } |
|
| 665 | 686 | } |
| 666 | 687 | |
| 667 | 688 | // People with manage-boards are special. |
@@ -673,8 +694,9 @@ discard block |
||
| 673 | 694 | // Secondly, make sure those with super cow powers (like apt-get, or in this case manage boards) are upgraded. |
| 674 | 695 | $boardOptions['access_groups'] = array_unique(array_merge($boardOptions['access_groups'], $board_managers)); |
| 675 | 696 | |
| 676 | - if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255) |
|
| 677 | - fatal_lang_error('too_many_groups', false); |
|
| 697 | + if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255) { |
|
| 698 | + fatal_lang_error('too_many_groups', false); |
|
| 699 | + } |
|
| 678 | 700 | |
| 679 | 701 | // Do not allow HTML tags. Parse the string. |
| 680 | 702 | $boardOptions['board_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['board_name']), false, '', $context['description_allowed_tags']); |
@@ -685,8 +707,9 @@ discard block |
||
| 685 | 707 | if (isset($_POST['moderator_list']) && is_array($_POST['moderator_list'])) |
| 686 | 708 | { |
| 687 | 709 | $moderators = array(); |
| 688 | - foreach ($_POST['moderator_list'] as $moderator) |
|
| 689 | - $moderators[(int) $moderator] = (int) $moderator; |
|
| 710 | + foreach ($_POST['moderator_list'] as $moderator) { |
|
| 711 | + $moderators[(int) $moderator] = (int) $moderator; |
|
| 712 | + } |
|
| 690 | 713 | $boardOptions['moderators'] = $moderators; |
| 691 | 714 | } |
| 692 | 715 | |
@@ -695,8 +718,9 @@ discard block |
||
| 695 | 718 | if (isset($_POST['moderator_group_list']) && is_array($_POST['moderator_group_list'])) |
| 696 | 719 | { |
| 697 | 720 | $moderator_groups = array(); |
| 698 | - foreach ($_POST['moderator_group_list'] as $moderator_group) |
|
| 699 | - $moderator_groups[(int) $moderator_group] = (int) $moderator_group; |
|
| 721 | + foreach ($_POST['moderator_group_list'] as $moderator_group) { |
|
| 722 | + $moderator_groups[(int) $moderator_group] = (int) $moderator_group; |
|
| 723 | + } |
|
| 700 | 724 | $boardOptions['moderator_groups'] = $moderator_groups; |
| 701 | 725 | } |
| 702 | 726 | |
@@ -722,56 +746,62 @@ discard block |
||
| 722 | 746 | $smcFunc['db_free_result']($request); |
| 723 | 747 | |
| 724 | 748 | // If we're turning redirection on check the board doesn't have posts in it - if it does don't make it a redirection board. |
| 725 | - if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts) |
|
| 726 | - unset($boardOptions['redirect']); |
|
| 749 | + if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts) { |
|
| 750 | + unset($boardOptions['redirect']); |
|
| 751 | + } |
|
| 727 | 752 | // Reset the redirection count when switching on/off. |
| 728 | - elseif (empty($boardOptions['redirect']) != empty($oldRedirect)) |
|
| 729 | - $boardOptions['num_posts'] = 0; |
|
| 753 | + elseif (empty($boardOptions['redirect']) != empty($oldRedirect)) { |
|
| 754 | + $boardOptions['num_posts'] = 0; |
|
| 755 | + } |
|
| 730 | 756 | // Resetting the count? |
| 731 | - elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect'])) |
|
| 732 | - $boardOptions['num_posts'] = 0; |
|
| 757 | + elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect'])) { |
|
| 758 | + $boardOptions['num_posts'] = 0; |
|
| 759 | + } |
|
| 733 | 760 | } |
| 734 | 761 | |
| 735 | 762 | // Create a new board... |
| 736 | 763 | if (isset($_POST['add'])) |
| 737 | 764 | { |
| 738 | 765 | // New boards by default go to the bottom of the category. |
| 739 | - if (empty($_POST['new_cat'])) |
|
| 740 | - $boardOptions['target_category'] = (int) $_POST['cur_cat']; |
|
| 741 | - if (!isset($boardOptions['move_to'])) |
|
| 742 | - $boardOptions['move_to'] = 'bottom'; |
|
| 766 | + if (empty($_POST['new_cat'])) { |
|
| 767 | + $boardOptions['target_category'] = (int) $_POST['cur_cat']; |
|
| 768 | + } |
|
| 769 | + if (!isset($boardOptions['move_to'])) { |
|
| 770 | + $boardOptions['move_to'] = 'bottom'; |
|
| 771 | + } |
|
| 743 | 772 | |
| 744 | 773 | createBoard($boardOptions); |
| 745 | 774 | } |
| 746 | 775 | |
| 747 | 776 | // ...or update an existing board. |
| 748 | - else |
|
| 749 | - modifyBoard($_POST['boardid'], $boardOptions); |
|
| 750 | - } |
|
| 751 | - elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children'])) |
|
| 777 | + else { |
|
| 778 | + modifyBoard($_POST['boardid'], $boardOptions); |
|
| 779 | + } |
|
| 780 | + } elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children'])) |
|
| 752 | 781 | { |
| 753 | 782 | EditBoard(); |
| 754 | 783 | return; |
| 755 | - } |
|
| 756 | - elseif (isset($_POST['delete'])) |
|
| 784 | + } elseif (isset($_POST['delete'])) |
|
| 757 | 785 | { |
| 758 | 786 | // First off - check if we are moving all the current child boards first - before we start deleting! |
| 759 | 787 | if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1) |
| 760 | 788 | { |
| 761 | - if (empty($_POST['board_to'])) |
|
| 762 | - fatal_lang_error('mboards_delete_board_error'); |
|
| 789 | + if (empty($_POST['board_to'])) { |
|
| 790 | + fatal_lang_error('mboards_delete_board_error'); |
|
| 791 | + } |
|
| 763 | 792 | |
| 764 | 793 | deleteBoards(array($_POST['boardid']), (int) $_POST['board_to']); |
| 794 | + } else { |
|
| 795 | + deleteBoards(array($_POST['boardid']), 0); |
|
| 765 | 796 | } |
| 766 | - else |
|
| 767 | - deleteBoards(array($_POST['boardid']), 0); |
|
| 768 | 797 | } |
| 769 | 798 | |
| 770 | - if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions') |
|
| 771 | - redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']); |
|
| 772 | - else |
|
| 773 | - redirectexit('action=admin;area=manageboards'); |
|
| 774 | -} |
|
| 799 | + if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions') { |
|
| 800 | + redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']); |
|
| 801 | + } else { |
|
| 802 | + redirectexit('action=admin;area=manageboards'); |
|
| 803 | + } |
|
| 804 | + } |
|
| 775 | 805 | |
| 776 | 806 | /** |
| 777 | 807 | * Used to retrieve data for modifying a board category |
@@ -808,8 +838,9 @@ discard block |
||
| 808 | 838 | $smcFunc['db_free_result']($request); |
| 809 | 839 | |
| 810 | 840 | // This would probably never happen, but just to be sure. |
| 811 | - if ($cat .= $allowed_sa[1]) |
|
| 812 | - die(str_replace(',', ' to', $cat)); |
|
| 841 | + if ($cat .= $allowed_sa[1]) { |
|
| 842 | + die(str_replace(',', ' to', $cat)); |
|
| 843 | + } |
|
| 813 | 844 | |
| 814 | 845 | redirectexit(); |
| 815 | 846 | } |
@@ -835,8 +866,9 @@ discard block |
||
| 835 | 866 | 'empty_string' => '', |
| 836 | 867 | ) |
| 837 | 868 | ); |
| 838 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 839 | - $recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name']; |
|
| 869 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 870 | + $recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name']; |
|
| 871 | + } |
|
| 840 | 872 | $smcFunc['db_free_result']($request); |
| 841 | 873 | |
| 842 | 874 | if (!empty($recycle_boards)) |
@@ -844,9 +876,9 @@ discard block |
||
| 844 | 876 | require_once($sourcedir . '/Subs-Boards.php'); |
| 845 | 877 | sortBoards($recycle_boards); |
| 846 | 878 | $recycle_boards = array('') + $recycle_boards; |
| 879 | + } else { |
|
| 880 | + $recycle_boards = array(''); |
|
| 847 | 881 | } |
| 848 | - else |
|
| 849 | - $recycle_boards = array(''); |
|
| 850 | 882 | |
| 851 | 883 | // Here and the board settings... |
| 852 | 884 | $config_vars = array( |
@@ -864,8 +896,9 @@ discard block |
||
| 864 | 896 | |
| 865 | 897 | call_integration_hook('integrate_modify_board_settings', array(&$config_vars)); |
| 866 | 898 | |
| 867 | - if ($return_config) |
|
| 868 | - return $config_vars; |
|
| 899 | + if ($return_config) { |
|
| 900 | + return $config_vars; |
|
| 901 | + } |
|
| 869 | 902 | |
| 870 | 903 | // Needed for the settings template. |
| 871 | 904 | require_once($sourcedir . '/ManageServer.php'); |
@@ -2259,9 +2259,9 @@ discard block |
||
| 2259 | 2259 | * |
| 2260 | 2260 | * @uses the template_include() function to include the file. |
| 2261 | 2261 | * @param string $template_name The name of the template to load |
| 2262 | - * @param array|string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load |
|
| 2262 | + * @param string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load |
|
| 2263 | 2263 | * @param bool $fatal If true, dies with an error message if the template cannot be found |
| 2264 | - * @return boolean Whether or not the template was loaded |
|
| 2264 | + * @return boolean|null Whether or not the template was loaded |
|
| 2265 | 2265 | */ |
| 2266 | 2266 | function loadTemplate($template_name, $style_sheets = array(), $fatal = true) |
| 2267 | 2267 | { |
@@ -2444,7 +2444,7 @@ discard block |
||
| 2444 | 2444 | * - all code added with this function is added to the same <style> tag so do make sure your css is valid! |
| 2445 | 2445 | * |
| 2446 | 2446 | * @param string $css Some css code |
| 2447 | - * @return void|bool Adds the CSS to the $context['css_header'] array or returns if no CSS is specified |
|
| 2447 | + * @return false|null Adds the CSS to the $context['css_header'] array or returns if no CSS is specified |
|
| 2448 | 2448 | */ |
| 2449 | 2449 | function addInlineCss($css) |
| 2450 | 2450 | { |
@@ -2558,7 +2558,7 @@ discard block |
||
| 2558 | 2558 | * |
| 2559 | 2559 | * @param string $javascript Some JS code |
| 2560 | 2560 | * @param bool $defer Whether the script should load in <head> or before the closing <html> tag |
| 2561 | - * @return void|bool Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified |
|
| 2561 | + * @return false|null Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified |
|
| 2562 | 2562 | */ |
| 2563 | 2563 | function addInlineJavaScript($javascript, $defer = false) |
| 2564 | 2564 | { |
@@ -2791,7 +2791,7 @@ discard block |
||
| 2791 | 2791 | * It will try to choose only utf8 or non-utf8 languages. |
| 2792 | 2792 | * |
| 2793 | 2793 | * @param bool $use_cache Whether or not to use the cache |
| 2794 | - * @return array An array of information about available languages |
|
| 2794 | + * @return string An array of information about available languages |
|
| 2795 | 2795 | */ |
| 2796 | 2796 | function getLanguages($use_cache = true) |
| 2797 | 2797 | { |
@@ -1719,7 +1719,7 @@ |
||
| 1719 | 1719 | $id_theme = $modSettings['theme_guests']; |
| 1720 | 1720 | |
| 1721 | 1721 | // We already load the basic stuff? |
| 1722 | - if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme ) |
|
| 1722 | + if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme) |
|
| 1723 | 1723 | { |
| 1724 | 1724 | // Verify the id_theme... no foul play. |
| 1725 | 1725 | // Always allow the board specific theme, if they are overriding. |
@@ -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 | * Load the $modSettings array. |
@@ -25,13 +26,14 @@ discard block |
||
| 25 | 26 | global $cache_enable, $sourcedir, $context; |
| 26 | 27 | |
| 27 | 28 | // Most database systems have not set UTF-8 as their default input charset. |
| 28 | - if (!empty($db_character_set)) |
|
| 29 | - $smcFunc['db_query']('', ' |
|
| 29 | + if (!empty($db_character_set)) { |
|
| 30 | + $smcFunc['db_query']('', ' |
|
| 30 | 31 | SET NAMES {string:db_character_set}', |
| 31 | 32 | array( |
| 32 | 33 | 'db_character_set' => $db_character_set, |
| 33 | 34 | ) |
| 34 | 35 | ); |
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | // We need some caching support, maybe. |
| 37 | 39 | loadCacheAccelerator(); |
@@ -46,28 +48,36 @@ discard block |
||
| 46 | 48 | ) |
| 47 | 49 | ); |
| 48 | 50 | $modSettings = array(); |
| 49 | - if (!$request) |
|
| 50 | - display_db_error(); |
|
| 51 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 52 | - $modSettings[$row[0]] = $row[1]; |
|
| 51 | + if (!$request) { |
|
| 52 | + display_db_error(); |
|
| 53 | + } |
|
| 54 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 55 | + $modSettings[$row[0]] = $row[1]; |
|
| 56 | + } |
|
| 53 | 57 | $smcFunc['db_free_result']($request); |
| 54 | 58 | |
| 55 | 59 | // Do a few things to protect against missing settings or settings with invalid values... |
| 56 | - if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) |
|
| 57 | - $modSettings['defaultMaxTopics'] = 20; |
|
| 58 | - if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) |
|
| 59 | - $modSettings['defaultMaxMessages'] = 15; |
|
| 60 | - if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) |
|
| 61 | - $modSettings['defaultMaxMembers'] = 30; |
|
| 62 | - if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) |
|
| 63 | - $modSettings['defaultMaxListItems'] = 15; |
|
| 60 | + if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) { |
|
| 61 | + $modSettings['defaultMaxTopics'] = 20; |
|
| 62 | + } |
|
| 63 | + if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) { |
|
| 64 | + $modSettings['defaultMaxMessages'] = 15; |
|
| 65 | + } |
|
| 66 | + if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) { |
|
| 67 | + $modSettings['defaultMaxMembers'] = 30; |
|
| 68 | + } |
|
| 69 | + if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) { |
|
| 70 | + $modSettings['defaultMaxListItems'] = 15; |
|
| 71 | + } |
|
| 64 | 72 | |
| 65 | 73 | // We excpiclity do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded. |
| 66 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
| 67 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 74 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
| 75 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 76 | + } |
|
| 68 | 77 | |
| 69 | - if (!empty($cache_enable)) |
|
| 70 | - cache_put_data('modSettings', $modSettings, 90); |
|
| 78 | + if (!empty($cache_enable)) { |
|
| 79 | + cache_put_data('modSettings', $modSettings, 90); |
|
| 80 | + } |
|
| 71 | 81 | } |
| 72 | 82 | |
| 73 | 83 | $modSettings['cache_enable'] = $cache_enable; |
@@ -87,8 +97,9 @@ discard block |
||
| 87 | 97 | }; |
| 88 | 98 | $fix_utf8mb4 = function($string) use ($utf8, $smcFunc) |
| 89 | 99 | { |
| 90 | - if (!$utf8 || $smcFunc['db_mb4']) |
|
| 91 | - return $string; |
|
| 100 | + if (!$utf8 || $smcFunc['db_mb4']) { |
|
| 101 | + return $string; |
|
| 102 | + } |
|
| 92 | 103 | |
| 93 | 104 | $i = 0; |
| 94 | 105 | $len = strlen($string); |
@@ -100,18 +111,15 @@ discard block |
||
| 100 | 111 | { |
| 101 | 112 | $new_string .= $string[$i]; |
| 102 | 113 | $i++; |
| 103 | - } |
|
| 104 | - elseif ($ord < 224) |
|
| 114 | + } elseif ($ord < 224) |
|
| 105 | 115 | { |
| 106 | 116 | $new_string .= $string[$i] . $string[$i + 1]; |
| 107 | 117 | $i += 2; |
| 108 | - } |
|
| 109 | - elseif ($ord < 240) |
|
| 118 | + } elseif ($ord < 240) |
|
| 110 | 119 | { |
| 111 | 120 | $new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2]; |
| 112 | 121 | $i += 3; |
| 113 | - } |
|
| 114 | - elseif ($ord < 248) |
|
| 122 | + } elseif ($ord < 248) |
|
| 115 | 123 | { |
| 116 | 124 | // Magic happens. |
| 117 | 125 | $val = (ord($string[$i]) & 0x07) << 18; |
@@ -155,8 +163,7 @@ discard block |
||
| 155 | 163 | { |
| 156 | 164 | $result = array_search($needle, array_slice($haystack_arr, $offset)); |
| 157 | 165 | return is_int($result) ? $result + $offset : false; |
| 158 | - } |
|
| 159 | - else |
|
| 166 | + } else |
|
| 160 | 167 | { |
| 161 | 168 | $needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|"|&|<|>| |.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
| 162 | 169 | $needle_size = count($needle_arr); |
@@ -165,8 +172,9 @@ discard block |
||
| 165 | 172 | while ((int) $result === $result) |
| 166 | 173 | { |
| 167 | 174 | $offset += $result; |
| 168 | - if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) |
|
| 169 | - return $offset; |
|
| 175 | + if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) { |
|
| 176 | + return $offset; |
|
| 177 | + } |
|
| 170 | 178 | $result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset)); |
| 171 | 179 | } |
| 172 | 180 | return false; |
@@ -204,8 +212,9 @@ discard block |
||
| 204 | 212 | $string = $ent_check($string); |
| 205 | 213 | preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches); |
| 206 | 214 | $string = $matches[0]; |
| 207 | - while (strlen($string) > $length) |
|
| 208 | - $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
| 215 | + while (strlen($string) > $length) { |
|
| 216 | + $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
| 217 | + } |
|
| 209 | 218 | return $string; |
| 210 | 219 | }, |
| 211 | 220 | 'ucfirst' => $utf8 ? function($string) use (&$smcFunc) |
@@ -215,8 +224,9 @@ discard block |
||
| 215 | 224 | 'ucwords' => $utf8 ? function($string) use (&$smcFunc) |
| 216 | 225 | { |
| 217 | 226 | $words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE); |
| 218 | - for ($i = 0, $n = count($words); $i < $n; $i += 2) |
|
| 219 | - $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
| 227 | + for ($i = 0, $n = count($words); $i < $n; $i += 2) { |
|
| 228 | + $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
| 229 | + } |
|
| 220 | 230 | return implode('', $words); |
| 221 | 231 | } : 'ucwords', |
| 222 | 232 | 'json_decode' => 'smf_json_decode', |
@@ -224,16 +234,17 @@ discard block |
||
| 224 | 234 | ); |
| 225 | 235 | |
| 226 | 236 | // Setting the timezone is a requirement for some functions. |
| 227 | - if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
|
| 228 | - date_default_timezone_set($modSettings['default_timezone']); |
|
| 229 | - else |
|
| 237 | + if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) { |
|
| 238 | + date_default_timezone_set($modSettings['default_timezone']); |
|
| 239 | + } else |
|
| 230 | 240 | { |
| 231 | 241 | // Get PHP's default timezone, if set |
| 232 | 242 | $ini_tz = ini_get('date.timezone'); |
| 233 | - if (!empty($ini_tz)) |
|
| 234 | - $modSettings['default_timezone'] = $ini_tz; |
|
| 235 | - else |
|
| 236 | - $modSettings['default_timezone'] = ''; |
|
| 243 | + if (!empty($ini_tz)) { |
|
| 244 | + $modSettings['default_timezone'] = $ini_tz; |
|
| 245 | + } else { |
|
| 246 | + $modSettings['default_timezone'] = ''; |
|
| 247 | + } |
|
| 237 | 248 | |
| 238 | 249 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
| 239 | 250 | if (!in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
@@ -251,22 +262,26 @@ discard block |
||
| 251 | 262 | if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null) |
| 252 | 263 | { |
| 253 | 264 | $modSettings['load_average'] = @file_get_contents('/proc/loadavg'); |
| 254 | - if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) |
|
| 255 | - $modSettings['load_average'] = (float) $matches[1]; |
|
| 256 | - elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) |
|
| 257 | - $modSettings['load_average'] = (float) $matches[1]; |
|
| 258 | - else |
|
| 259 | - unset($modSettings['load_average']); |
|
| 265 | + if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) { |
|
| 266 | + $modSettings['load_average'] = (float) $matches[1]; |
|
| 267 | + } elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) { |
|
| 268 | + $modSettings['load_average'] = (float) $matches[1]; |
|
| 269 | + } else { |
|
| 270 | + unset($modSettings['load_average']); |
|
| 271 | + } |
|
| 260 | 272 | |
| 261 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
| 262 | - cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
| 273 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
| 274 | + cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
| 275 | + } |
|
| 263 | 276 | } |
| 264 | 277 | |
| 265 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
| 266 | - call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
| 278 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
| 279 | + call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
| 280 | + } |
|
| 267 | 281 | |
| 268 | - if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) |
|
| 269 | - display_loadavg_error(); |
|
| 282 | + if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) { |
|
| 283 | + display_loadavg_error(); |
|
| 284 | + } |
|
| 270 | 285 | } |
| 271 | 286 | |
| 272 | 287 | // Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is. |
@@ -287,8 +302,9 @@ discard block |
||
| 287 | 302 | if (defined('SMF_INTEGRATION_SETTINGS')) |
| 288 | 303 | { |
| 289 | 304 | $integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true); |
| 290 | - foreach ($integration_settings as $hook => $function) |
|
| 291 | - add_integration_function($hook, $function, '', false); |
|
| 305 | + foreach ($integration_settings as $hook => $function) { |
|
| 306 | + add_integration_function($hook, $function, '', false); |
|
| 307 | + } |
|
| 292 | 308 | } |
| 293 | 309 | |
| 294 | 310 | // Any files to pre include? |
@@ -298,8 +314,9 @@ discard block |
||
| 298 | 314 | foreach ($pre_includes as $include) |
| 299 | 315 | { |
| 300 | 316 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
| 301 | - if (file_exists($include)) |
|
| 302 | - require_once($include); |
|
| 317 | + if (file_exists($include)) { |
|
| 318 | + require_once($include); |
|
| 319 | + } |
|
| 303 | 320 | } |
| 304 | 321 | } |
| 305 | 322 | |
@@ -405,27 +422,28 @@ discard block |
||
| 405 | 422 | break; |
| 406 | 423 | } |
| 407 | 424 | } |
| 425 | + } else { |
|
| 426 | + $id_member = 0; |
|
| 408 | 427 | } |
| 409 | - else |
|
| 410 | - $id_member = 0; |
|
| 411 | 428 | |
| 412 | 429 | if (empty($id_member) && isset($_COOKIE[$cookiename])) |
| 413 | 430 | { |
| 414 | 431 | $cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false); |
| 415 | 432 | |
| 416 | - if (empty($cookie_data)) |
|
| 417 | - $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
| 433 | + if (empty($cookie_data)) { |
|
| 434 | + $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
| 435 | + } |
|
| 418 | 436 | |
| 419 | 437 | list ($id_member, $password) = $cookie_data; |
| 420 | 438 | $id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0; |
| 421 | - } |
|
| 422 | - elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
| 439 | + } elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
| 423 | 440 | { |
| 424 | 441 | // @todo Perhaps we can do some more checking on this, such as on the first octet of the IP? |
| 425 | 442 | $cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]); |
| 426 | 443 | |
| 427 | - if (empty($cookie_data)) |
|
| 428 | - $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 444 | + if (empty($cookie_data)) { |
|
| 445 | + $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 446 | + } |
|
| 429 | 447 | |
| 430 | 448 | list ($id_member, $password, $login_span) = $cookie_data; |
| 431 | 449 | $id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0; |
@@ -450,30 +468,34 @@ discard block |
||
| 450 | 468 | $user_settings = $smcFunc['db_fetch_assoc']($request); |
| 451 | 469 | $smcFunc['db_free_result']($request); |
| 452 | 470 | |
| 453 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) |
|
| 454 | - $user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret); |
|
| 471 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) { |
|
| 472 | + $user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret); |
|
| 473 | + } |
|
| 455 | 474 | |
| 456 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 457 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 475 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 476 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 477 | + } |
|
| 458 | 478 | } |
| 459 | 479 | |
| 460 | 480 | // Did we find 'im? If not, junk it. |
| 461 | 481 | if (!empty($user_settings)) |
| 462 | 482 | { |
| 463 | 483 | // As much as the password should be right, we can assume the integration set things up. |
| 464 | - if (!empty($already_verified) && $already_verified === true) |
|
| 465 | - $check = true; |
|
| 484 | + if (!empty($already_verified) && $already_verified === true) { |
|
| 485 | + $check = true; |
|
| 486 | + } |
|
| 466 | 487 | // SHA-512 hash should be 128 characters long. |
| 467 | - elseif (strlen($password) == 128) |
|
| 468 | - $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
| 469 | - else |
|
| 470 | - $check = false; |
|
| 488 | + elseif (strlen($password) == 128) { |
|
| 489 | + $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
| 490 | + } else { |
|
| 491 | + $check = false; |
|
| 492 | + } |
|
| 471 | 493 | |
| 472 | 494 | // Wrong password or not activated - either way, you're going nowhere. |
| 473 | 495 | $id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0; |
| 496 | + } else { |
|
| 497 | + $id_member = 0; |
|
| 474 | 498 | } |
| 475 | - else |
|
| 476 | - $id_member = 0; |
|
| 477 | 499 | |
| 478 | 500 | // If we no longer have the member maybe they're being all hackey, stop brute force! |
| 479 | 501 | if (!$id_member) |
@@ -502,8 +524,9 @@ discard block |
||
| 502 | 524 | |
| 503 | 525 | list ($tfamember, $tfasecret) = $tfa_data; |
| 504 | 526 | |
| 505 | - if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) |
|
| 506 | - $tfasecret = null; |
|
| 527 | + if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) { |
|
| 528 | + $tfasecret = null; |
|
| 529 | + } |
|
| 507 | 530 | } |
| 508 | 531 | |
| 509 | 532 | if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret) |
@@ -523,10 +546,12 @@ discard block |
||
| 523 | 546 | // Are we forcing 2FA? Need to check if the user groups actually require 2FA |
| 524 | 547 | elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret'])) |
| 525 | 548 | { |
| 526 | - if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups |
|
| 549 | + if ($modSettings['tfa_mode'] == 2) { |
|
| 550 | + //only do this if we are just forcing SOME membergroups |
|
| 527 | 551 | { |
| 528 | 552 | //Build an array of ALL user membergroups. |
| 529 | 553 | $full_groups = array($user_settings['id_group']); |
| 554 | + } |
|
| 530 | 555 | if (!empty($user_settings['additional_groups'])) |
| 531 | 556 | { |
| 532 | 557 | $full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups'])); |
@@ -546,15 +571,17 @@ discard block |
||
| 546 | 571 | ); |
| 547 | 572 | $row = $smcFunc['db_fetch_assoc']($request); |
| 548 | 573 | $smcFunc['db_free_result']($request); |
| 574 | + } else { |
|
| 575 | + $row['total'] = 1; |
|
| 549 | 576 | } |
| 550 | - else |
|
| 551 | - $row['total'] = 1; //simplifies logics in the next "if" |
|
| 577 | + //simplifies logics in the next "if" |
|
| 552 | 578 | |
| 553 | 579 | $area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : ''; |
| 554 | 580 | $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : ''; |
| 555 | 581 | |
| 556 | - if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) |
|
| 557 | - redirectexit('action=profile;area=tfasetup;forced'); |
|
| 582 | + if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) { |
|
| 583 | + redirectexit('action=profile;area=tfasetup;forced'); |
|
| 584 | + } |
|
| 558 | 585 | } |
| 559 | 586 | } |
| 560 | 587 | |
@@ -591,33 +618,37 @@ discard block |
||
| 591 | 618 | updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'])); |
| 592 | 619 | $user_settings['last_login'] = time(); |
| 593 | 620 | |
| 594 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 595 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 621 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 622 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 623 | + } |
|
| 596 | 624 | |
| 597 | - if (!empty($modSettings['cache_enable'])) |
|
| 598 | - cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
| 625 | + if (!empty($modSettings['cache_enable'])) { |
|
| 626 | + cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
| 627 | + } |
|
| 599 | 628 | } |
| 629 | + } elseif (empty($_SESSION['id_msg_last_visit'])) { |
|
| 630 | + $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
| 600 | 631 | } |
| 601 | - elseif (empty($_SESSION['id_msg_last_visit'])) |
|
| 602 | - $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
| 603 | 632 | |
| 604 | 633 | $username = $user_settings['member_name']; |
| 605 | 634 | |
| 606 | - if (empty($user_settings['additional_groups'])) |
|
| 607 | - $user_info = array( |
|
| 635 | + if (empty($user_settings['additional_groups'])) { |
|
| 636 | + $user_info = array( |
|
| 608 | 637 | 'groups' => array($user_settings['id_group'], $user_settings['id_post_group']) |
| 609 | 638 | ); |
| 610 | - else |
|
| 611 | - $user_info = array( |
|
| 639 | + } else { |
|
| 640 | + $user_info = array( |
|
| 612 | 641 | 'groups' => array_merge( |
| 613 | 642 | array($user_settings['id_group'], $user_settings['id_post_group']), |
| 614 | 643 | explode(',', $user_settings['additional_groups']) |
| 615 | 644 | ) |
| 616 | 645 | ); |
| 646 | + } |
|
| 617 | 647 | |
| 618 | 648 | // Because history has proven that it is possible for groups to go bad - clean up in case. |
| 619 | - foreach ($user_info['groups'] as $k => $v) |
|
| 620 | - $user_info['groups'][$k] = (int) $v; |
|
| 649 | + foreach ($user_info['groups'] as $k => $v) { |
|
| 650 | + $user_info['groups'][$k] = (int) $v; |
|
| 651 | + } |
|
| 621 | 652 | |
| 622 | 653 | // This is a logged in user, so definitely not a spider. |
| 623 | 654 | $user_info['possibly_robot'] = false; |
@@ -631,8 +662,7 @@ discard block |
||
| 631 | 662 | $time_system = new DateTime('now', $tz_system); |
| 632 | 663 | $time_user = new DateTime('now', $tz_user); |
| 633 | 664 | $user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600; |
| 634 | - } |
|
| 635 | - else |
|
| 665 | + } else |
|
| 636 | 666 | { |
| 637 | 667 | // !!! Compatibility. |
| 638 | 668 | $user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset']; |
@@ -646,8 +676,9 @@ discard block |
||
| 646 | 676 | $user_info = array('groups' => array(-1)); |
| 647 | 677 | $user_settings = array(); |
| 648 | 678 | |
| 649 | - if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) |
|
| 650 | - $_COOKIE[$cookiename] = ''; |
|
| 679 | + if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) { |
|
| 680 | + $_COOKIE[$cookiename] = ''; |
|
| 681 | + } |
|
| 651 | 682 | |
| 652 | 683 | // Expire the 2FA cookie |
| 653 | 684 | if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member'])) |
@@ -664,19 +695,20 @@ discard block |
||
| 664 | 695 | } |
| 665 | 696 | |
| 666 | 697 | // Create a login token if it doesn't exist yet. |
| 667 | - if (!isset($_SESSION['token']['post-login'])) |
|
| 668 | - createToken('login'); |
|
| 669 | - else |
|
| 670 | - list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
| 698 | + if (!isset($_SESSION['token']['post-login'])) { |
|
| 699 | + createToken('login'); |
|
| 700 | + } else { |
|
| 701 | + list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
| 702 | + } |
|
| 671 | 703 | |
| 672 | 704 | // Do we perhaps think this is a search robot? Check every five minutes just in case... |
| 673 | 705 | if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300)) |
| 674 | 706 | { |
| 675 | 707 | require_once($sourcedir . '/ManageSearchEngines.php'); |
| 676 | 708 | $user_info['possibly_robot'] = SpiderCheck(); |
| 709 | + } elseif (!empty($modSettings['spider_mode'])) { |
|
| 710 | + $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
| 677 | 711 | } |
| 678 | - elseif (!empty($modSettings['spider_mode'])) |
|
| 679 | - $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
| 680 | 712 | // If we haven't turned on proper spider hunts then have a guess! |
| 681 | 713 | else |
| 682 | 714 | { |
@@ -724,8 +756,9 @@ discard block |
||
| 724 | 756 | $user_info['groups'] = array_unique($user_info['groups']); |
| 725 | 757 | |
| 726 | 758 | // Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems. |
| 727 | - if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) |
|
| 728 | - unset($user_info['ignoreboards'][$tmp]); |
|
| 759 | + if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) { |
|
| 760 | + unset($user_info['ignoreboards'][$tmp]); |
|
| 761 | + } |
|
| 729 | 762 | |
| 730 | 763 | // Allow the user to change their language. |
| 731 | 764 | if (!empty($modSettings['userLanguage'])) |
@@ -738,13 +771,14 @@ discard block |
||
| 738 | 771 | $user_info['language'] = strtr($_GET['language'], './\\:', '____'); |
| 739 | 772 | |
| 740 | 773 | // Make it permanent for members. |
| 741 | - if (!empty($user_info['id'])) |
|
| 742 | - updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
| 743 | - else |
|
| 744 | - $_SESSION['language'] = $user_info['language']; |
|
| 774 | + if (!empty($user_info['id'])) { |
|
| 775 | + updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
| 776 | + } else { |
|
| 777 | + $_SESSION['language'] = $user_info['language']; |
|
| 778 | + } |
|
| 779 | + } elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) { |
|
| 780 | + $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
| 745 | 781 | } |
| 746 | - elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) |
|
| 747 | - $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
| 748 | 782 | } |
| 749 | 783 | |
| 750 | 784 | $temp = build_query_board($user_info['id']); |
@@ -807,9 +841,9 @@ discard block |
||
| 807 | 841 | } |
| 808 | 842 | |
| 809 | 843 | // Remember redirection is the key to avoiding fallout from your bosses. |
| 810 | - if (!empty($topic)) |
|
| 811 | - redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
| 812 | - else |
|
| 844 | + if (!empty($topic)) { |
|
| 845 | + redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
| 846 | + } else |
|
| 813 | 847 | { |
| 814 | 848 | loadPermissions(); |
| 815 | 849 | loadTheme(); |
@@ -827,10 +861,11 @@ discard block |
||
| 827 | 861 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
| 828 | 862 | { |
| 829 | 863 | // @todo SLOW? |
| 830 | - if (!empty($topic)) |
|
| 831 | - $temp = cache_get_data('topic_board-' . $topic, 120); |
|
| 832 | - else |
|
| 833 | - $temp = cache_get_data('board-' . $board, 120); |
|
| 864 | + if (!empty($topic)) { |
|
| 865 | + $temp = cache_get_data('topic_board-' . $topic, 120); |
|
| 866 | + } else { |
|
| 867 | + $temp = cache_get_data('board-' . $board, 120); |
|
| 868 | + } |
|
| 834 | 869 | |
| 835 | 870 | if (!empty($temp)) |
| 836 | 871 | { |
@@ -868,8 +903,9 @@ discard block |
||
| 868 | 903 | $row = $smcFunc['db_fetch_assoc']($request); |
| 869 | 904 | |
| 870 | 905 | // Set the current board. |
| 871 | - if (!empty($row['id_board'])) |
|
| 872 | - $board = $row['id_board']; |
|
| 906 | + if (!empty($row['id_board'])) { |
|
| 907 | + $board = $row['id_board']; |
|
| 908 | + } |
|
| 873 | 909 | |
| 874 | 910 | // Basic operating information. (globals... :/) |
| 875 | 911 | $board_info = array( |
@@ -905,21 +941,23 @@ discard block |
||
| 905 | 941 | |
| 906 | 942 | do |
| 907 | 943 | { |
| 908 | - if (!empty($row['id_moderator'])) |
|
| 909 | - $board_info['moderators'][$row['id_moderator']] = array( |
|
| 944 | + if (!empty($row['id_moderator'])) { |
|
| 945 | + $board_info['moderators'][$row['id_moderator']] = array( |
|
| 910 | 946 | 'id' => $row['id_moderator'], |
| 911 | 947 | 'name' => $row['real_name'], |
| 912 | 948 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
| 913 | 949 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
| 914 | 950 | ); |
| 951 | + } |
|
| 915 | 952 | |
| 916 | - if (!empty($row['id_moderator_group'])) |
|
| 917 | - $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
| 953 | + if (!empty($row['id_moderator_group'])) { |
|
| 954 | + $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
| 918 | 955 | 'id' => $row['id_moderator_group'], |
| 919 | 956 | 'name' => $row['group_name'], |
| 920 | 957 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
| 921 | 958 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
| 922 | 959 | ); |
| 960 | + } |
|
| 923 | 961 | } |
| 924 | 962 | while ($row = $smcFunc['db_fetch_assoc']($request)); |
| 925 | 963 | |
@@ -951,12 +989,12 @@ discard block |
||
| 951 | 989 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
| 952 | 990 | { |
| 953 | 991 | // @todo SLOW? |
| 954 | - if (!empty($topic)) |
|
| 955 | - cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
| 992 | + if (!empty($topic)) { |
|
| 993 | + cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
| 994 | + } |
|
| 956 | 995 | cache_put_data('board-' . $board, $board_info, 120); |
| 957 | 996 | } |
| 958 | - } |
|
| 959 | - else |
|
| 997 | + } else |
|
| 960 | 998 | { |
| 961 | 999 | // Otherwise the topic is invalid, there are no moderators, etc. |
| 962 | 1000 | $board_info = array( |
@@ -970,8 +1008,9 @@ discard block |
||
| 970 | 1008 | $smcFunc['db_free_result']($request); |
| 971 | 1009 | } |
| 972 | 1010 | |
| 973 | - if (!empty($topic)) |
|
| 974 | - $_GET['board'] = (int) $board; |
|
| 1011 | + if (!empty($topic)) { |
|
| 1012 | + $_GET['board'] = (int) $board; |
|
| 1013 | + } |
|
| 975 | 1014 | |
| 976 | 1015 | if (!empty($board)) |
| 977 | 1016 | { |
@@ -981,10 +1020,12 @@ discard block |
||
| 981 | 1020 | // Now check if the user is a moderator. |
| 982 | 1021 | $user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0; |
| 983 | 1022 | |
| 984 | - if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) |
|
| 985 | - $board_info['error'] = 'access'; |
|
| 986 | - if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) |
|
| 987 | - $board_info['error'] = 'access'; |
|
| 1023 | + if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) { |
|
| 1024 | + $board_info['error'] = 'access'; |
|
| 1025 | + } |
|
| 1026 | + if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) { |
|
| 1027 | + $board_info['error'] = 'access'; |
|
| 1028 | + } |
|
| 988 | 1029 | |
| 989 | 1030 | // Build up the linktree. |
| 990 | 1031 | $context['linktree'] = array_merge( |
@@ -1007,8 +1048,9 @@ discard block |
||
| 1007 | 1048 | $context['current_board'] = $board; |
| 1008 | 1049 | |
| 1009 | 1050 | // No posting in redirection boards! |
| 1010 | - if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) |
|
| 1011 | - $board_info['error'] == 'post_in_redirect'; |
|
| 1051 | + if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) { |
|
| 1052 | + $board_info['error'] == 'post_in_redirect'; |
|
| 1053 | + } |
|
| 1012 | 1054 | |
| 1013 | 1055 | // Hacker... you can't see this topic, I'll tell you that. (but moderators can!) |
| 1014 | 1056 | if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod'])) |
@@ -1034,24 +1076,23 @@ discard block |
||
| 1034 | 1076 | ob_end_clean(); |
| 1035 | 1077 | header('HTTP/1.1 403 Forbidden'); |
| 1036 | 1078 | die; |
| 1037 | - } |
|
| 1038 | - elseif ($board_info['error'] == 'post_in_redirect') |
|
| 1079 | + } elseif ($board_info['error'] == 'post_in_redirect') |
|
| 1039 | 1080 | { |
| 1040 | 1081 | // Slightly different error message here... |
| 1041 | 1082 | fatal_lang_error('cannot_post_redirect', false); |
| 1042 | - } |
|
| 1043 | - elseif ($user_info['is_guest']) |
|
| 1083 | + } elseif ($user_info['is_guest']) |
|
| 1044 | 1084 | { |
| 1045 | 1085 | loadLanguage('Errors'); |
| 1046 | 1086 | is_not_guest($txt['topic_gone']); |
| 1087 | + } else { |
|
| 1088 | + fatal_lang_error('topic_gone', false); |
|
| 1047 | 1089 | } |
| 1048 | - else |
|
| 1049 | - fatal_lang_error('topic_gone', false); |
|
| 1050 | 1090 | } |
| 1051 | 1091 | |
| 1052 | - if ($user_info['is_mod']) |
|
| 1053 | - $user_info['groups'][] = 3; |
|
| 1054 | -} |
|
| 1092 | + if ($user_info['is_mod']) { |
|
| 1093 | + $user_info['groups'][] = 3; |
|
| 1094 | + } |
|
| 1095 | + } |
|
| 1055 | 1096 | |
| 1056 | 1097 | /** |
| 1057 | 1098 | * Load this user's permissions. |
@@ -1072,8 +1113,9 @@ discard block |
||
| 1072 | 1113 | asort($cache_groups); |
| 1073 | 1114 | $cache_groups = implode(',', $cache_groups); |
| 1074 | 1115 | // If it's a spider then cache it different. |
| 1075 | - if ($user_info['possibly_robot']) |
|
| 1076 | - $cache_groups .= '-spider'; |
|
| 1116 | + if ($user_info['possibly_robot']) { |
|
| 1117 | + $cache_groups .= '-spider'; |
|
| 1118 | + } |
|
| 1077 | 1119 | |
| 1078 | 1120 | if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
| 1079 | 1121 | { |
@@ -1081,9 +1123,9 @@ discard block |
||
| 1081 | 1123 | banPermissions(); |
| 1082 | 1124 | |
| 1083 | 1125 | return; |
| 1126 | + } elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) { |
|
| 1127 | + list ($user_info['permissions'], $removals) = $temp; |
|
| 1084 | 1128 | } |
| 1085 | - elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
|
| 1086 | - list ($user_info['permissions'], $removals) = $temp; |
|
| 1087 | 1129 | } |
| 1088 | 1130 | |
| 1089 | 1131 | // If it is detected as a robot, and we are restricting permissions as a special group - then implement this. |
@@ -1105,23 +1147,26 @@ discard block |
||
| 1105 | 1147 | $removals = array(); |
| 1106 | 1148 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1107 | 1149 | { |
| 1108 | - if (empty($row['add_deny'])) |
|
| 1109 | - $removals[] = $row['permission']; |
|
| 1110 | - else |
|
| 1111 | - $user_info['permissions'][] = $row['permission']; |
|
| 1150 | + if (empty($row['add_deny'])) { |
|
| 1151 | + $removals[] = $row['permission']; |
|
| 1152 | + } else { |
|
| 1153 | + $user_info['permissions'][] = $row['permission']; |
|
| 1154 | + } |
|
| 1112 | 1155 | } |
| 1113 | 1156 | $smcFunc['db_free_result']($request); |
| 1114 | 1157 | |
| 1115 | - if (isset($cache_groups)) |
|
| 1116 | - cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
| 1158 | + if (isset($cache_groups)) { |
|
| 1159 | + cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
| 1160 | + } |
|
| 1117 | 1161 | } |
| 1118 | 1162 | |
| 1119 | 1163 | // Get the board permissions. |
| 1120 | 1164 | if (!empty($board)) |
| 1121 | 1165 | { |
| 1122 | 1166 | // Make sure the board (if any) has been loaded by loadBoard(). |
| 1123 | - if (!isset($board_info['profile'])) |
|
| 1124 | - fatal_lang_error('no_board'); |
|
| 1167 | + if (!isset($board_info['profile'])) { |
|
| 1168 | + fatal_lang_error('no_board'); |
|
| 1169 | + } |
|
| 1125 | 1170 | |
| 1126 | 1171 | $request = $smcFunc['db_query']('', ' |
| 1127 | 1172 | SELECT permission, add_deny |
@@ -1137,20 +1182,23 @@ discard block |
||
| 1137 | 1182 | ); |
| 1138 | 1183 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1139 | 1184 | { |
| 1140 | - if (empty($row['add_deny'])) |
|
| 1141 | - $removals[] = $row['permission']; |
|
| 1142 | - else |
|
| 1143 | - $user_info['permissions'][] = $row['permission']; |
|
| 1185 | + if (empty($row['add_deny'])) { |
|
| 1186 | + $removals[] = $row['permission']; |
|
| 1187 | + } else { |
|
| 1188 | + $user_info['permissions'][] = $row['permission']; |
|
| 1189 | + } |
|
| 1144 | 1190 | } |
| 1145 | 1191 | $smcFunc['db_free_result']($request); |
| 1146 | 1192 | } |
| 1147 | 1193 | |
| 1148 | 1194 | // Remove all the permissions they shouldn't have ;). |
| 1149 | - if (!empty($modSettings['permission_enable_deny'])) |
|
| 1150 | - $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
| 1195 | + if (!empty($modSettings['permission_enable_deny'])) { |
|
| 1196 | + $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
| 1197 | + } |
|
| 1151 | 1198 | |
| 1152 | - if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) |
|
| 1153 | - cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
| 1199 | + if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) { |
|
| 1200 | + cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
| 1201 | + } |
|
| 1154 | 1202 | |
| 1155 | 1203 | // Banned? Watch, don't touch.. |
| 1156 | 1204 | banPermissions(); |
@@ -1162,17 +1210,18 @@ discard block |
||
| 1162 | 1210 | { |
| 1163 | 1211 | require_once($sourcedir . '/Subs-Auth.php'); |
| 1164 | 1212 | rebuildModCache(); |
| 1213 | + } else { |
|
| 1214 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
| 1165 | 1215 | } |
| 1166 | - else |
|
| 1167 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
| 1168 | 1216 | |
| 1169 | 1217 | // This is a useful phantom permission added to the current user, and only the current user while they are logged in. |
| 1170 | 1218 | // For example this drastically simplifies certain changes to the profile area. |
| 1171 | 1219 | $user_info['permissions'][] = 'is_not_guest'; |
| 1172 | 1220 | // And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions. |
| 1173 | 1221 | $user_info['permissions'][] = 'profile_view_own'; |
| 1174 | - if (in_array('profile_view', $user_info['permissions'])) |
|
| 1175 | - $user_info['permissions'][] = 'profile_view_any'; |
|
| 1222 | + if (in_array('profile_view', $user_info['permissions'])) { |
|
| 1223 | + $user_info['permissions'][] = 'profile_view_any'; |
|
| 1224 | + } |
|
| 1176 | 1225 | } |
| 1177 | 1226 | } |
| 1178 | 1227 | |
@@ -1190,8 +1239,9 @@ discard block |
||
| 1190 | 1239 | global $image_proxy_enabled, $image_proxy_secret, $boardurl; |
| 1191 | 1240 | |
| 1192 | 1241 | // Can't just look for no users :P. |
| 1193 | - if (empty($users)) |
|
| 1194 | - return array(); |
|
| 1242 | + if (empty($users)) { |
|
| 1243 | + return array(); |
|
| 1244 | + } |
|
| 1195 | 1245 | |
| 1196 | 1246 | // Pass the set value |
| 1197 | 1247 | $context['loadMemberContext_set'] = $set; |
@@ -1206,8 +1256,9 @@ discard block |
||
| 1206 | 1256 | for ($i = 0, $n = count($users); $i < $n; $i++) |
| 1207 | 1257 | { |
| 1208 | 1258 | $data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240); |
| 1209 | - if ($data == null) |
|
| 1210 | - continue; |
|
| 1259 | + if ($data == null) { |
|
| 1260 | + continue; |
|
| 1261 | + } |
|
| 1211 | 1262 | |
| 1212 | 1263 | $loaded_ids[] = $data['id_member']; |
| 1213 | 1264 | $user_profile[$data['id_member']] = $data; |
@@ -1274,16 +1325,19 @@ discard block |
||
| 1274 | 1325 | $row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : ''; |
| 1275 | 1326 | |
| 1276 | 1327 | // Take care of proxying avatar if required, do this here for maximum reach |
| 1277 | - if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) |
|
| 1278 | - $row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret); |
|
| 1328 | + if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) { |
|
| 1329 | + $row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret); |
|
| 1330 | + } |
|
| 1279 | 1331 | |
| 1280 | 1332 | // Keep track of the member's normal member group |
| 1281 | 1333 | $row['primary_group'] = $row['member_group']; |
| 1282 | 1334 | |
| 1283 | - if (isset($row['member_ip'])) |
|
| 1284 | - $row['member_ip'] = inet_dtop($row['member_ip']); |
|
| 1285 | - if (isset($row['member_ip2'])) |
|
| 1286 | - $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
| 1335 | + if (isset($row['member_ip'])) { |
|
| 1336 | + $row['member_ip'] = inet_dtop($row['member_ip']); |
|
| 1337 | + } |
|
| 1338 | + if (isset($row['member_ip2'])) { |
|
| 1339 | + $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
| 1340 | + } |
|
| 1287 | 1341 | $new_loaded_ids[] = $row['id_member']; |
| 1288 | 1342 | $loaded_ids[] = $row['id_member']; |
| 1289 | 1343 | $row['options'] = array(); |
@@ -1302,8 +1356,9 @@ discard block |
||
| 1302 | 1356 | 'loaded_ids' => $new_loaded_ids, |
| 1303 | 1357 | ) |
| 1304 | 1358 | ); |
| 1305 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1306 | - $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
| 1359 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1360 | + $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
| 1361 | + } |
|
| 1307 | 1362 | $smcFunc['db_free_result']($request); |
| 1308 | 1363 | } |
| 1309 | 1364 | |
@@ -1314,10 +1369,11 @@ discard block |
||
| 1314 | 1369 | { |
| 1315 | 1370 | foreach ($loaded_ids as $a_member) |
| 1316 | 1371 | { |
| 1317 | - if (!empty($user_profile[$a_member]['additional_groups'])) |
|
| 1318 | - $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
| 1319 | - else |
|
| 1320 | - $groups = array($user_profile[$a_member]['id_group']); |
|
| 1372 | + if (!empty($user_profile[$a_member]['additional_groups'])) { |
|
| 1373 | + $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
| 1374 | + } else { |
|
| 1375 | + $groups = array($user_profile[$a_member]['id_group']); |
|
| 1376 | + } |
|
| 1321 | 1377 | |
| 1322 | 1378 | $temp = array_intersect($groups, array_keys($board_info['moderator_groups'])); |
| 1323 | 1379 | |
@@ -1330,8 +1386,9 @@ discard block |
||
| 1330 | 1386 | |
| 1331 | 1387 | if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) |
| 1332 | 1388 | { |
| 1333 | - for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) |
|
| 1334 | - cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
| 1389 | + for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) { |
|
| 1390 | + cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
| 1391 | + } |
|
| 1335 | 1392 | } |
| 1336 | 1393 | |
| 1337 | 1394 | // Are we loading any moderators? If so, fix their group data... |
@@ -1357,14 +1414,17 @@ discard block |
||
| 1357 | 1414 | foreach ($temp_mods as $id) |
| 1358 | 1415 | { |
| 1359 | 1416 | // By popular demand, don't show admins or global moderators as moderators. |
| 1360 | - if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) |
|
| 1361 | - $user_profile[$id]['member_group'] = $row['member_group']; |
|
| 1417 | + if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) { |
|
| 1418 | + $user_profile[$id]['member_group'] = $row['member_group']; |
|
| 1419 | + } |
|
| 1362 | 1420 | |
| 1363 | 1421 | // If the Moderator group has no color or icons, but their group does... don't overwrite. |
| 1364 | - if (!empty($row['icons'])) |
|
| 1365 | - $user_profile[$id]['icons'] = $row['icons']; |
|
| 1366 | - if (!empty($row['member_group_color'])) |
|
| 1367 | - $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
| 1422 | + if (!empty($row['icons'])) { |
|
| 1423 | + $user_profile[$id]['icons'] = $row['icons']; |
|
| 1424 | + } |
|
| 1425 | + if (!empty($row['member_group_color'])) { |
|
| 1426 | + $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
| 1427 | + } |
|
| 1368 | 1428 | } |
| 1369 | 1429 | } |
| 1370 | 1430 | |
@@ -1386,12 +1446,14 @@ discard block |
||
| 1386 | 1446 | static $loadedLanguages = array(); |
| 1387 | 1447 | |
| 1388 | 1448 | // If this person's data is already loaded, skip it. |
| 1389 | - if (isset($dataLoaded[$user])) |
|
| 1390 | - return true; |
|
| 1449 | + if (isset($dataLoaded[$user])) { |
|
| 1450 | + return true; |
|
| 1451 | + } |
|
| 1391 | 1452 | |
| 1392 | 1453 | // We can't load guests or members not loaded by loadMemberData()! |
| 1393 | - if ($user == 0) |
|
| 1394 | - return false; |
|
| 1454 | + if ($user == 0) { |
|
| 1455 | + return false; |
|
| 1456 | + } |
|
| 1395 | 1457 | if (!isset($user_profile[$user])) |
| 1396 | 1458 | { |
| 1397 | 1459 | trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING); |
@@ -1417,12 +1479,16 @@ discard block |
||
| 1417 | 1479 | $buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array(); |
| 1418 | 1480 | |
| 1419 | 1481 | //We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme |
| 1420 | - if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists |
|
| 1482 | + if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) { |
|
| 1483 | + //icon is set and exists |
|
| 1421 | 1484 | $group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1]; |
| 1422 | - elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default |
|
| 1485 | + } elseif (isset($profile['icons'][1])) { |
|
| 1486 | + //icon is set and doesn't exist, fallback to default |
|
| 1423 | 1487 | $group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1]; |
| 1424 | - else //not set, bye bye |
|
| 1488 | + } else { |
|
| 1489 | + //not set, bye bye |
|
| 1425 | 1490 | $group_icon_url = ''; |
| 1491 | + } |
|
| 1426 | 1492 | |
| 1427 | 1493 | // These minimal values are always loaded |
| 1428 | 1494 | $memberContext[$user] = array( |
@@ -1441,8 +1507,9 @@ discard block |
||
| 1441 | 1507 | if ($context['loadMemberContext_set'] != 'minimal') |
| 1442 | 1508 | { |
| 1443 | 1509 | // Go the extra mile and load the user's native language name. |
| 1444 | - if (empty($loadedLanguages)) |
|
| 1445 | - $loadedLanguages = getLanguages(); |
|
| 1510 | + if (empty($loadedLanguages)) { |
|
| 1511 | + $loadedLanguages = getLanguages(); |
|
| 1512 | + } |
|
| 1446 | 1513 | |
| 1447 | 1514 | $memberContext[$user] += array( |
| 1448 | 1515 | 'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>', |
@@ -1497,31 +1564,33 @@ discard block |
||
| 1497 | 1564 | { |
| 1498 | 1565 | if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://'))) |
| 1499 | 1566 | { |
| 1500 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) |
|
| 1501 | - $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
| 1502 | - else |
|
| 1503 | - $image = get_gravatar_url($profile['email_address']); |
|
| 1504 | - } |
|
| 1505 | - else |
|
| 1567 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) { |
|
| 1568 | + $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
| 1569 | + } else { |
|
| 1570 | + $image = get_gravatar_url($profile['email_address']); |
|
| 1571 | + } |
|
| 1572 | + } else |
|
| 1506 | 1573 | { |
| 1507 | 1574 | // So it's stored in the member table? |
| 1508 | 1575 | if (!empty($profile['avatar'])) |
| 1509 | 1576 | { |
| 1510 | 1577 | $image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']; |
| 1578 | + } elseif (!empty($profile['filename'])) { |
|
| 1579 | + $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
| 1511 | 1580 | } |
| 1512 | - elseif (!empty($profile['filename'])) |
|
| 1513 | - $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
| 1514 | 1581 | // Right... no avatar...use the default one |
| 1515 | - else |
|
| 1516 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 1582 | + else { |
|
| 1583 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 1584 | + } |
|
| 1517 | 1585 | } |
| 1518 | - if (!empty($image)) |
|
| 1519 | - $memberContext[$user]['avatar'] = array( |
|
| 1586 | + if (!empty($image)) { |
|
| 1587 | + $memberContext[$user]['avatar'] = array( |
|
| 1520 | 1588 | 'name' => $profile['avatar'], |
| 1521 | 1589 | 'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">', |
| 1522 | 1590 | 'href' => $image, |
| 1523 | 1591 | 'url' => $image, |
| 1524 | 1592 | ); |
| 1593 | + } |
|
| 1525 | 1594 | } |
| 1526 | 1595 | |
| 1527 | 1596 | // Are we also loading the members custom fields into context? |
@@ -1529,13 +1598,15 @@ discard block |
||
| 1529 | 1598 | { |
| 1530 | 1599 | $memberContext[$user]['custom_fields'] = array(); |
| 1531 | 1600 | |
| 1532 | - if (!isset($context['display_fields'])) |
|
| 1533 | - $context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true); |
|
| 1601 | + if (!isset($context['display_fields'])) { |
|
| 1602 | + $context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true); |
|
| 1603 | + } |
|
| 1534 | 1604 | |
| 1535 | 1605 | foreach ($context['display_fields'] as $custom) |
| 1536 | 1606 | { |
| 1537 | - if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) |
|
| 1538 | - continue; |
|
| 1607 | + if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) { |
|
| 1608 | + continue; |
|
| 1609 | + } |
|
| 1539 | 1610 | |
| 1540 | 1611 | $value = $profile['options'][$custom['col_name']]; |
| 1541 | 1612 | |
@@ -1543,31 +1614,36 @@ discard block |
||
| 1543 | 1614 | $currentKey = 0; |
| 1544 | 1615 | |
| 1545 | 1616 | // Create a key => value array for multiple options fields |
| 1546 | - if (!empty($custom['options'])) |
|
| 1547 | - foreach ($custom['options'] as $k => $v) |
|
| 1617 | + if (!empty($custom['options'])) { |
|
| 1618 | + foreach ($custom['options'] as $k => $v) |
|
| 1548 | 1619 | { |
| 1549 | 1620 | $fieldOptions[] = $v; |
| 1550 | - if (empty($currentKey)) |
|
| 1551 | - $currentKey = $v == $value ? $k : 0; |
|
| 1621 | + } |
|
| 1622 | + if (empty($currentKey)) { |
|
| 1623 | + $currentKey = $v == $value ? $k : 0; |
|
| 1624 | + } |
|
| 1552 | 1625 | } |
| 1553 | 1626 | |
| 1554 | 1627 | // BBC? |
| 1555 | - if ($custom['bbc']) |
|
| 1556 | - $value = parse_bbc($value); |
|
| 1628 | + if ($custom['bbc']) { |
|
| 1629 | + $value = parse_bbc($value); |
|
| 1630 | + } |
|
| 1557 | 1631 | |
| 1558 | 1632 | // ... or checkbox? |
| 1559 | - elseif (isset($custom['type']) && $custom['type'] == 'check') |
|
| 1560 | - $value = $value ? $txt['yes'] : $txt['no']; |
|
| 1633 | + elseif (isset($custom['type']) && $custom['type'] == 'check') { |
|
| 1634 | + $value = $value ? $txt['yes'] : $txt['no']; |
|
| 1635 | + } |
|
| 1561 | 1636 | |
| 1562 | 1637 | // Enclosing the user input within some other text? |
| 1563 | - if (!empty($custom['enclose'])) |
|
| 1564 | - $value = strtr($custom['enclose'], array( |
|
| 1638 | + if (!empty($custom['enclose'])) { |
|
| 1639 | + $value = strtr($custom['enclose'], array( |
|
| 1565 | 1640 | '{SCRIPTURL}' => $scripturl, |
| 1566 | 1641 | '{IMAGES_URL}' => $settings['images_url'], |
| 1567 | 1642 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
| 1568 | 1643 | '{INPUT}' => $value, |
| 1569 | 1644 | '{KEY}' => $currentKey, |
| 1570 | 1645 | )); |
| 1646 | + } |
|
| 1571 | 1647 | |
| 1572 | 1648 | $memberContext[$user]['custom_fields'][] = array( |
| 1573 | 1649 | 'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'], |
@@ -1594,8 +1670,9 @@ discard block |
||
| 1594 | 1670 | global $smcFunc, $txt, $scripturl, $settings; |
| 1595 | 1671 | |
| 1596 | 1672 | // Do not waste my time... |
| 1597 | - if (empty($users) || empty($params)) |
|
| 1598 | - return false; |
|
| 1673 | + if (empty($users) || empty($params)) { |
|
| 1674 | + return false; |
|
| 1675 | + } |
|
| 1599 | 1676 | |
| 1600 | 1677 | // Make sure it's an array. |
| 1601 | 1678 | $users = !is_array($users) ? array($users) : array_unique($users); |
@@ -1622,41 +1699,48 @@ discard block |
||
| 1622 | 1699 | $currentKey = 0; |
| 1623 | 1700 | |
| 1624 | 1701 | // Create a key => value array for multiple options fields |
| 1625 | - if (!empty($row['field_options'])) |
|
| 1626 | - foreach (explode(',', $row['field_options']) as $k => $v) |
|
| 1702 | + if (!empty($row['field_options'])) { |
|
| 1703 | + foreach (explode(',', $row['field_options']) as $k => $v) |
|
| 1627 | 1704 | { |
| 1628 | 1705 | $fieldOptions[] = $v; |
| 1629 | - if (empty($currentKey)) |
|
| 1630 | - $currentKey = $v == $row['value'] ? $k : 0; |
|
| 1706 | + } |
|
| 1707 | + if (empty($currentKey)) { |
|
| 1708 | + $currentKey = $v == $row['value'] ? $k : 0; |
|
| 1709 | + } |
|
| 1631 | 1710 | } |
| 1632 | 1711 | |
| 1633 | 1712 | // BBC? |
| 1634 | - if (!empty($row['bbc'])) |
|
| 1635 | - $row['value'] = parse_bbc($row['value']); |
|
| 1713 | + if (!empty($row['bbc'])) { |
|
| 1714 | + $row['value'] = parse_bbc($row['value']); |
|
| 1715 | + } |
|
| 1636 | 1716 | |
| 1637 | 1717 | // ... or checkbox? |
| 1638 | - elseif (isset($row['type']) && $row['type'] == 'check') |
|
| 1639 | - $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
| 1718 | + elseif (isset($row['type']) && $row['type'] == 'check') { |
|
| 1719 | + $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
| 1720 | + } |
|
| 1640 | 1721 | |
| 1641 | 1722 | // Enclosing the user input within some other text? |
| 1642 | - if (!empty($row['enclose'])) |
|
| 1643 | - $row['value'] = strtr($row['enclose'], array( |
|
| 1723 | + if (!empty($row['enclose'])) { |
|
| 1724 | + $row['value'] = strtr($row['enclose'], array( |
|
| 1644 | 1725 | '{SCRIPTURL}' => $scripturl, |
| 1645 | 1726 | '{IMAGES_URL}' => $settings['images_url'], |
| 1646 | 1727 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
| 1647 | 1728 | '{INPUT}' => un_htmlspecialchars($row['value']), |
| 1648 | 1729 | '{KEY}' => $currentKey, |
| 1649 | 1730 | )); |
| 1731 | + } |
|
| 1650 | 1732 | |
| 1651 | 1733 | // Send a simple array if there is just 1 param |
| 1652 | - if (count($params) == 1) |
|
| 1653 | - $return[$row['id_member']] = $row; |
|
| 1734 | + if (count($params) == 1) { |
|
| 1735 | + $return[$row['id_member']] = $row; |
|
| 1736 | + } |
|
| 1654 | 1737 | |
| 1655 | 1738 | // More than 1? knock yourself out... |
| 1656 | 1739 | else |
| 1657 | 1740 | { |
| 1658 | - if (!isset($return[$row['id_member']])) |
|
| 1659 | - $return[$row['id_member']] = array(); |
|
| 1741 | + if (!isset($return[$row['id_member']])) { |
|
| 1742 | + $return[$row['id_member']] = array(); |
|
| 1743 | + } |
|
| 1660 | 1744 | |
| 1661 | 1745 | $return[$row['id_member']][$row['variable']] = $row; |
| 1662 | 1746 | } |
@@ -1690,8 +1774,9 @@ discard block |
||
| 1690 | 1774 | global $context; |
| 1691 | 1775 | |
| 1692 | 1776 | // Don't know any browser! |
| 1693 | - if (empty($context['browser'])) |
|
| 1694 | - detectBrowser(); |
|
| 1777 | + if (empty($context['browser'])) { |
|
| 1778 | + detectBrowser(); |
|
| 1779 | + } |
|
| 1695 | 1780 | |
| 1696 | 1781 | return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false; |
| 1697 | 1782 | } |
@@ -1709,8 +1794,9 @@ discard block |
||
| 1709 | 1794 | global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled; |
| 1710 | 1795 | |
| 1711 | 1796 | // The theme was specified by parameter. |
| 1712 | - if (!empty($id_theme)) |
|
| 1713 | - $id_theme = (int) $id_theme; |
|
| 1797 | + if (!empty($id_theme)) { |
|
| 1798 | + $id_theme = (int) $id_theme; |
|
| 1799 | + } |
|
| 1714 | 1800 | // The theme was specified by REQUEST. |
| 1715 | 1801 | elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
| 1716 | 1802 | { |
@@ -1718,54 +1804,61 @@ discard block |
||
| 1718 | 1804 | $_SESSION['id_theme'] = $id_theme; |
| 1719 | 1805 | } |
| 1720 | 1806 | // The theme was specified by REQUEST... previously. |
| 1721 | - elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
|
| 1722 | - $id_theme = (int) $_SESSION['id_theme']; |
|
| 1807 | + elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) { |
|
| 1808 | + $id_theme = (int) $_SESSION['id_theme']; |
|
| 1809 | + } |
|
| 1723 | 1810 | // The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.) |
| 1724 | - elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) |
|
| 1725 | - $id_theme = $user_info['theme']; |
|
| 1811 | + elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) { |
|
| 1812 | + $id_theme = $user_info['theme']; |
|
| 1813 | + } |
|
| 1726 | 1814 | // The theme was specified by the board. |
| 1727 | - elseif (!empty($board_info['theme'])) |
|
| 1728 | - $id_theme = $board_info['theme']; |
|
| 1815 | + elseif (!empty($board_info['theme'])) { |
|
| 1816 | + $id_theme = $board_info['theme']; |
|
| 1817 | + } |
|
| 1729 | 1818 | // The theme is the forum's default. |
| 1730 | - else |
|
| 1731 | - $id_theme = $modSettings['theme_guests']; |
|
| 1819 | + else { |
|
| 1820 | + $id_theme = $modSettings['theme_guests']; |
|
| 1821 | + } |
|
| 1732 | 1822 | |
| 1733 | 1823 | // We already load the basic stuff? |
| 1734 | 1824 | if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme ) |
| 1735 | 1825 | { |
| 1736 | 1826 | // Verify the id_theme... no foul play. |
| 1737 | 1827 | // Always allow the board specific theme, if they are overriding. |
| 1738 | - if (!empty($board_info['theme']) && $board_info['override_theme']) |
|
| 1739 | - $id_theme = $board_info['theme']; |
|
| 1828 | + if (!empty($board_info['theme']) && $board_info['override_theme']) { |
|
| 1829 | + $id_theme = $board_info['theme']; |
|
| 1830 | + } |
|
| 1740 | 1831 | // If they have specified a particular theme to use with SSI allow it to be used. |
| 1741 | - elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) |
|
| 1742 | - $id_theme = (int) $id_theme; |
|
| 1743 | - elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
| 1832 | + elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) { |
|
| 1833 | + $id_theme = (int) $id_theme; |
|
| 1834 | + } elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
| 1744 | 1835 | { |
| 1745 | 1836 | $themes = explode(',', $modSettings['enableThemes']); |
| 1746 | - if (!in_array($id_theme, $themes)) |
|
| 1747 | - $id_theme = $modSettings['theme_guests']; |
|
| 1748 | - else |
|
| 1749 | - $id_theme = (int) $id_theme; |
|
| 1837 | + if (!in_array($id_theme, $themes)) { |
|
| 1838 | + $id_theme = $modSettings['theme_guests']; |
|
| 1839 | + } else { |
|
| 1840 | + $id_theme = (int) $id_theme; |
|
| 1841 | + } |
|
| 1842 | + } else { |
|
| 1843 | + $id_theme = (int) $id_theme; |
|
| 1750 | 1844 | } |
| 1751 | - else |
|
| 1752 | - $id_theme = (int) $id_theme; |
|
| 1753 | 1845 | |
| 1754 | 1846 | $member = empty($user_info['id']) ? -1 : $user_info['id']; |
| 1755 | 1847 | |
| 1756 | 1848 | // Disable image proxy if we don't have SSL enabled |
| 1757 | - if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) |
|
| 1758 | - $image_proxy_enabled = false; |
|
| 1849 | + if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) { |
|
| 1850 | + $image_proxy_enabled = false; |
|
| 1851 | + } |
|
| 1759 | 1852 | |
| 1760 | 1853 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated']) |
| 1761 | 1854 | { |
| 1762 | 1855 | $themeData = $temp; |
| 1763 | 1856 | $flag = true; |
| 1857 | + } elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) { |
|
| 1858 | + $themeData = $temp + array($member => array()); |
|
| 1859 | + } else { |
|
| 1860 | + $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
| 1764 | 1861 | } |
| 1765 | - elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) |
|
| 1766 | - $themeData = $temp + array($member => array()); |
|
| 1767 | - else |
|
| 1768 | - $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
| 1769 | 1862 | |
| 1770 | 1863 | if (empty($flag)) |
| 1771 | 1864 | { |
@@ -1784,31 +1877,37 @@ discard block |
||
| 1784 | 1877 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 1785 | 1878 | { |
| 1786 | 1879 | // There are just things we shouldn't be able to change as members. |
| 1787 | - if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) |
|
| 1788 | - continue; |
|
| 1880 | + if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) { |
|
| 1881 | + continue; |
|
| 1882 | + } |
|
| 1789 | 1883 | |
| 1790 | 1884 | // If this is the theme_dir of the default theme, store it. |
| 1791 | - if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) |
|
| 1792 | - $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
| 1885 | + if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) { |
|
| 1886 | + $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
| 1887 | + } |
|
| 1793 | 1888 | |
| 1794 | 1889 | // If this isn't set yet, is a theme option, or is not the default theme.. |
| 1795 | - if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') |
|
| 1796 | - $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
| 1890 | + if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') { |
|
| 1891 | + $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
| 1892 | + } |
|
| 1797 | 1893 | } |
| 1798 | 1894 | $smcFunc['db_free_result']($result); |
| 1799 | 1895 | |
| 1800 | - if (!empty($themeData[-1])) |
|
| 1801 | - foreach ($themeData[-1] as $k => $v) |
|
| 1896 | + if (!empty($themeData[-1])) { |
|
| 1897 | + foreach ($themeData[-1] as $k => $v) |
|
| 1802 | 1898 | { |
| 1803 | 1899 | if (!isset($themeData[$member][$k])) |
| 1804 | 1900 | $themeData[$member][$k] = $v; |
| 1901 | + } |
|
| 1805 | 1902 | } |
| 1806 | 1903 | |
| 1807 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 1808 | - cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
| 1904 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 1905 | + cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
| 1906 | + } |
|
| 1809 | 1907 | // Only if we didn't already load that part of the cache... |
| 1810 | - elseif (!isset($temp)) |
|
| 1811 | - cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
| 1908 | + elseif (!isset($temp)) { |
|
| 1909 | + cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
| 1910 | + } |
|
| 1812 | 1911 | } |
| 1813 | 1912 | |
| 1814 | 1913 | $settings = $themeData[0]; |
@@ -1825,17 +1924,20 @@ discard block |
||
| 1825 | 1924 | $settings['template_dirs'][] = $settings['theme_dir']; |
| 1826 | 1925 | |
| 1827 | 1926 | // Based on theme (if there is one). |
| 1828 | - if (!empty($settings['base_theme_dir'])) |
|
| 1829 | - $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
| 1927 | + if (!empty($settings['base_theme_dir'])) { |
|
| 1928 | + $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
| 1929 | + } |
|
| 1830 | 1930 | |
| 1831 | 1931 | // Lastly the default theme. |
| 1832 | - if ($settings['theme_dir'] != $settings['default_theme_dir']) |
|
| 1833 | - $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
| 1932 | + if ($settings['theme_dir'] != $settings['default_theme_dir']) { |
|
| 1933 | + $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
| 1934 | + } |
|
| 1834 | 1935 | } |
| 1835 | 1936 | |
| 1836 | 1937 | |
| 1837 | - if (!$initialize) |
|
| 1838 | - return; |
|
| 1938 | + if (!$initialize) { |
|
| 1939 | + return; |
|
| 1940 | + } |
|
| 1839 | 1941 | |
| 1840 | 1942 | // Check to see if we're forcing SSL |
| 1841 | 1943 | if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) && |
@@ -1856,8 +1958,9 @@ discard block |
||
| 1856 | 1958 | $detected_url = httpsOn() ? 'https://' : 'http://'; |
| 1857 | 1959 | $detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']; |
| 1858 | 1960 | $temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')); |
| 1859 | - if ($temp != '/') |
|
| 1860 | - $detected_url .= $temp; |
|
| 1961 | + if ($temp != '/') { |
|
| 1962 | + $detected_url .= $temp; |
|
| 1963 | + } |
|
| 1861 | 1964 | } |
| 1862 | 1965 | if (isset($detected_url) && $detected_url != $boardurl) |
| 1863 | 1966 | { |
@@ -1869,8 +1972,9 @@ discard block |
||
| 1869 | 1972 | foreach ($aliases as $alias) |
| 1870 | 1973 | { |
| 1871 | 1974 | // Rip off all the boring parts, spaces, etc. |
| 1872 | - if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) |
|
| 1873 | - $do_fix = true; |
|
| 1975 | + if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) { |
|
| 1976 | + $do_fix = true; |
|
| 1977 | + } |
|
| 1874 | 1978 | } |
| 1875 | 1979 | } |
| 1876 | 1980 | |
@@ -1878,21 +1982,23 @@ discard block |
||
| 1878 | 1982 | if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI') |
| 1879 | 1983 | { |
| 1880 | 1984 | // Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;). |
| 1881 | - if (empty($_GET)) |
|
| 1882 | - redirectexit('wwwRedirect'); |
|
| 1883 | - else |
|
| 1985 | + if (empty($_GET)) { |
|
| 1986 | + redirectexit('wwwRedirect'); |
|
| 1987 | + } else |
|
| 1884 | 1988 | { |
| 1885 | 1989 | $k = key($_GET); |
| 1886 | 1990 | $v = current($_GET); |
| 1887 | 1991 | |
| 1888 | - if ($k != 'wwwRedirect') |
|
| 1889 | - redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
| 1992 | + if ($k != 'wwwRedirect') { |
|
| 1993 | + redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
| 1994 | + } |
|
| 1890 | 1995 | } |
| 1891 | 1996 | } |
| 1892 | 1997 | |
| 1893 | 1998 | // #3 is just a check for SSL... |
| 1894 | - if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) |
|
| 1895 | - $do_fix = true; |
|
| 1999 | + if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) { |
|
| 2000 | + $do_fix = true; |
|
| 2001 | + } |
|
| 1896 | 2002 | |
| 1897 | 2003 | // Okay, #4 - perhaps it's an IP address? We're gonna want to use that one, then. (assuming it's the IP or something...) |
| 1898 | 2004 | if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1) |
@@ -1927,8 +2033,9 @@ discard block |
||
| 1927 | 2033 | $board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl)); |
| 1928 | 2034 | } |
| 1929 | 2035 | } |
| 1930 | - foreach ($context['linktree'] as $k => $dummy) |
|
| 1931 | - $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
| 2036 | + foreach ($context['linktree'] as $k => $dummy) { |
|
| 2037 | + $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
| 2038 | + } |
|
| 1932 | 2039 | } |
| 1933 | 2040 | } |
| 1934 | 2041 | // Set up the contextual user array. |
@@ -1947,16 +2054,16 @@ discard block |
||
| 1947 | 2054 | 'email' => $user_info['email'], |
| 1948 | 2055 | 'ignoreusers' => $user_info['ignoreusers'], |
| 1949 | 2056 | ); |
| 1950 | - if (!$context['user']['is_guest']) |
|
| 1951 | - $context['user']['name'] = $user_info['name']; |
|
| 1952 | - elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) |
|
| 1953 | - $context['user']['name'] = $txt['guest_title']; |
|
| 2057 | + if (!$context['user']['is_guest']) { |
|
| 2058 | + $context['user']['name'] = $user_info['name']; |
|
| 2059 | + } elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) { |
|
| 2060 | + $context['user']['name'] = $txt['guest_title']; |
|
| 2061 | + } |
|
| 1954 | 2062 | |
| 1955 | 2063 | // Determine the current smiley set. |
| 1956 | 2064 | $user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set']; |
| 1957 | 2065 | $context['user']['smiley_set'] = $user_info['smiley_set']; |
| 1958 | - } |
|
| 1959 | - else |
|
| 2066 | + } else |
|
| 1960 | 2067 | { |
| 1961 | 2068 | // What to do when there is no $user_info (e.g., an error very early in the login process) |
| 1962 | 2069 | $context['user'] = array( |
@@ -1990,18 +2097,24 @@ discard block |
||
| 1990 | 2097 | } |
| 1991 | 2098 | |
| 1992 | 2099 | // Some basic information... |
| 1993 | - if (!isset($context['html_headers'])) |
|
| 1994 | - $context['html_headers'] = ''; |
|
| 1995 | - if (!isset($context['javascript_files'])) |
|
| 1996 | - $context['javascript_files'] = array(); |
|
| 1997 | - if (!isset($context['css_files'])) |
|
| 1998 | - $context['css_files'] = array(); |
|
| 1999 | - if (!isset($context['css_header'])) |
|
| 2000 | - $context['css_header'] = array(); |
|
| 2001 | - if (!isset($context['javascript_inline'])) |
|
| 2002 | - $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
| 2003 | - if (!isset($context['javascript_vars'])) |
|
| 2004 | - $context['javascript_vars'] = array(); |
|
| 2100 | + if (!isset($context['html_headers'])) { |
|
| 2101 | + $context['html_headers'] = ''; |
|
| 2102 | + } |
|
| 2103 | + if (!isset($context['javascript_files'])) { |
|
| 2104 | + $context['javascript_files'] = array(); |
|
| 2105 | + } |
|
| 2106 | + if (!isset($context['css_files'])) { |
|
| 2107 | + $context['css_files'] = array(); |
|
| 2108 | + } |
|
| 2109 | + if (!isset($context['css_header'])) { |
|
| 2110 | + $context['css_header'] = array(); |
|
| 2111 | + } |
|
| 2112 | + if (!isset($context['javascript_inline'])) { |
|
| 2113 | + $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
| 2114 | + } |
|
| 2115 | + if (!isset($context['javascript_vars'])) { |
|
| 2116 | + $context['javascript_vars'] = array(); |
|
| 2117 | + } |
|
| 2005 | 2118 | |
| 2006 | 2119 | $context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2'; |
| 2007 | 2120 | $context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | '; |
@@ -2013,16 +2126,18 @@ discard block |
||
| 2013 | 2126 | $context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null; |
| 2014 | 2127 | $context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null; |
| 2015 | 2128 | $context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3; |
| 2016 | - if (isset($modSettings['load_average'])) |
|
| 2017 | - $context['load_average'] = $modSettings['load_average']; |
|
| 2129 | + if (isset($modSettings['load_average'])) { |
|
| 2130 | + $context['load_average'] = $modSettings['load_average']; |
|
| 2131 | + } |
|
| 2018 | 2132 | |
| 2019 | 2133 | // Detect the browser. This is separated out because it's also used in attachment downloads |
| 2020 | 2134 | detectBrowser(); |
| 2021 | 2135 | |
| 2022 | 2136 | // Set the top level linktree up. |
| 2023 | 2137 | // Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet... |
| 2024 | - if (empty($context['linktree'])) |
|
| 2025 | - $context['linktree'] = array(); |
|
| 2138 | + if (empty($context['linktree'])) { |
|
| 2139 | + $context['linktree'] = array(); |
|
| 2140 | + } |
|
| 2026 | 2141 | array_unshift($context['linktree'], array( |
| 2027 | 2142 | 'url' => $scripturl, |
| 2028 | 2143 | 'name' => $context['forum_name_html_safe'] |
@@ -2031,8 +2146,9 @@ discard block |
||
| 2031 | 2146 | // This allows sticking some HTML on the page output - useful for controls. |
| 2032 | 2147 | $context['insert_after_template'] = ''; |
| 2033 | 2148 | |
| 2034 | - if (!isset($txt)) |
|
| 2035 | - $txt = array(); |
|
| 2149 | + if (!isset($txt)) { |
|
| 2150 | + $txt = array(); |
|
| 2151 | + } |
|
| 2036 | 2152 | |
| 2037 | 2153 | $simpleActions = array( |
| 2038 | 2154 | 'findmember', |
@@ -2078,9 +2194,10 @@ discard block |
||
| 2078 | 2194 | |
| 2079 | 2195 | // See if theres any extra param to check. |
| 2080 | 2196 | $requiresXML = false; |
| 2081 | - foreach ($extraParams as $key => $extra) |
|
| 2082 | - if (isset($_REQUEST[$extra])) |
|
| 2197 | + foreach ($extraParams as $key => $extra) { |
|
| 2198 | + if (isset($_REQUEST[$extra])) |
|
| 2083 | 2199 | $requiresXML = true; |
| 2200 | + } |
|
| 2084 | 2201 | |
| 2085 | 2202 | // Output is fully XML, so no need for the index template. |
| 2086 | 2203 | if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML)) |
@@ -2095,37 +2212,39 @@ discard block |
||
| 2095 | 2212 | { |
| 2096 | 2213 | loadLanguage('index+Modifications'); |
| 2097 | 2214 | $context['template_layers'] = array(); |
| 2098 | - } |
|
| 2099 | - |
|
| 2100 | - else |
|
| 2215 | + } else |
|
| 2101 | 2216 | { |
| 2102 | 2217 | // Custom templates to load, or just default? |
| 2103 | - if (isset($settings['theme_templates'])) |
|
| 2104 | - $templates = explode(',', $settings['theme_templates']); |
|
| 2105 | - else |
|
| 2106 | - $templates = array('index'); |
|
| 2218 | + if (isset($settings['theme_templates'])) { |
|
| 2219 | + $templates = explode(',', $settings['theme_templates']); |
|
| 2220 | + } else { |
|
| 2221 | + $templates = array('index'); |
|
| 2222 | + } |
|
| 2107 | 2223 | |
| 2108 | 2224 | // Load each template... |
| 2109 | - foreach ($templates as $template) |
|
| 2110 | - loadTemplate($template); |
|
| 2225 | + foreach ($templates as $template) { |
|
| 2226 | + loadTemplate($template); |
|
| 2227 | + } |
|
| 2111 | 2228 | |
| 2112 | 2229 | // ...and attempt to load their associated language files. |
| 2113 | 2230 | $required_files = implode('+', array_merge($templates, array('Modifications'))); |
| 2114 | 2231 | loadLanguage($required_files, '', false); |
| 2115 | 2232 | |
| 2116 | 2233 | // Custom template layers? |
| 2117 | - if (isset($settings['theme_layers'])) |
|
| 2118 | - $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
| 2119 | - else |
|
| 2120 | - $context['template_layers'] = array('html', 'body'); |
|
| 2234 | + if (isset($settings['theme_layers'])) { |
|
| 2235 | + $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
| 2236 | + } else { |
|
| 2237 | + $context['template_layers'] = array('html', 'body'); |
|
| 2238 | + } |
|
| 2121 | 2239 | } |
| 2122 | 2240 | |
| 2123 | 2241 | // Initialize the theme. |
| 2124 | 2242 | loadSubTemplate('init', 'ignore'); |
| 2125 | 2243 | |
| 2126 | 2244 | // Allow overriding the board wide time/number formats. |
| 2127 | - if (empty($user_settings['time_format']) && !empty($txt['time_format'])) |
|
| 2128 | - $user_info['time_format'] = $txt['time_format']; |
|
| 2245 | + if (empty($user_settings['time_format']) && !empty($txt['time_format'])) { |
|
| 2246 | + $user_info['time_format'] = $txt['time_format']; |
|
| 2247 | + } |
|
| 2129 | 2248 | |
| 2130 | 2249 | // Set the character set from the template. |
| 2131 | 2250 | $context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']; |
@@ -2133,12 +2252,14 @@ discard block |
||
| 2133 | 2252 | $context['right_to_left'] = !empty($txt['lang_rtl']); |
| 2134 | 2253 | |
| 2135 | 2254 | // Guests may still need a name. |
| 2136 | - if ($context['user']['is_guest'] && empty($context['user']['name'])) |
|
| 2137 | - $context['user']['name'] = $txt['guest_title']; |
|
| 2255 | + if ($context['user']['is_guest'] && empty($context['user']['name'])) { |
|
| 2256 | + $context['user']['name'] = $txt['guest_title']; |
|
| 2257 | + } |
|
| 2138 | 2258 | |
| 2139 | 2259 | // Any theme-related strings that need to be loaded? |
| 2140 | - if (!empty($settings['require_theme_strings'])) |
|
| 2141 | - loadLanguage('ThemeStrings', '', false); |
|
| 2260 | + if (!empty($settings['require_theme_strings'])) { |
|
| 2261 | + loadLanguage('ThemeStrings', '', false); |
|
| 2262 | + } |
|
| 2142 | 2263 | |
| 2143 | 2264 | // Make a special URL for the language. |
| 2144 | 2265 | $settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']); |
@@ -2149,8 +2270,9 @@ discard block |
||
| 2149 | 2270 | // Here is my luvly Responsive CSS |
| 2150 | 2271 | loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive'); |
| 2151 | 2272 | |
| 2152 | - if ($context['right_to_left']) |
|
| 2153 | - loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
| 2273 | + if ($context['right_to_left']) { |
|
| 2274 | + loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
| 2275 | + } |
|
| 2154 | 2276 | |
| 2155 | 2277 | // We allow theme variants, because we're cool. |
| 2156 | 2278 | $context['theme_variant'] = ''; |
@@ -2158,14 +2280,17 @@ discard block |
||
| 2158 | 2280 | if (!empty($settings['theme_variants'])) |
| 2159 | 2281 | { |
| 2160 | 2282 | // Overriding - for previews and that ilk. |
| 2161 | - if (!empty($_REQUEST['variant'])) |
|
| 2162 | - $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
| 2283 | + if (!empty($_REQUEST['variant'])) { |
|
| 2284 | + $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
| 2285 | + } |
|
| 2163 | 2286 | // User selection? |
| 2164 | - if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) |
|
| 2165 | - $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
| 2287 | + if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) { |
|
| 2288 | + $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
| 2289 | + } |
|
| 2166 | 2290 | // If not a user variant, select the default. |
| 2167 | - if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) |
|
| 2168 | - $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
| 2291 | + if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) { |
|
| 2292 | + $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
| 2293 | + } |
|
| 2169 | 2294 | |
| 2170 | 2295 | // Do this to keep things easier in the templates. |
| 2171 | 2296 | $context['theme_variant'] = '_' . $context['theme_variant']; |
@@ -2174,20 +2299,23 @@ discard block |
||
| 2174 | 2299 | if (!empty($context['theme_variant'])) |
| 2175 | 2300 | { |
| 2176 | 2301 | loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']); |
| 2177 | - if ($context['right_to_left']) |
|
| 2178 | - loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
| 2302 | + if ($context['right_to_left']) { |
|
| 2303 | + loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
| 2304 | + } |
|
| 2179 | 2305 | } |
| 2180 | 2306 | } |
| 2181 | 2307 | |
| 2182 | 2308 | // Let's be compatible with old themes! |
| 2183 | - if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) |
|
| 2184 | - $context['template_layers'] = array('main'); |
|
| 2309 | + if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) { |
|
| 2310 | + $context['template_layers'] = array('main'); |
|
| 2311 | + } |
|
| 2185 | 2312 | |
| 2186 | 2313 | $context['tabindex'] = 1; |
| 2187 | 2314 | |
| 2188 | 2315 | // Compatibility. |
| 2189 | - if (!isset($settings['theme_version'])) |
|
| 2190 | - $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
| 2316 | + if (!isset($settings['theme_version'])) { |
|
| 2317 | + $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
| 2318 | + } |
|
| 2191 | 2319 | |
| 2192 | 2320 | // Default JS variables for use in every theme |
| 2193 | 2321 | $context['javascript_vars'] = array( |
@@ -2206,18 +2334,18 @@ discard block |
||
| 2206 | 2334 | ); |
| 2207 | 2335 | |
| 2208 | 2336 | // Add the JQuery library to the list of files to load. |
| 2209 | - if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') |
|
| 2210 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2211 | - |
|
| 2212 | - elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') |
|
| 2213 | - loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery'); |
|
| 2214 | - |
|
| 2215 | - elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') |
|
| 2216 | - loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
| 2337 | + if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') { |
|
| 2338 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2339 | + } elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') { |
|
| 2340 | + loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery'); |
|
| 2341 | + } elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') { |
|
| 2342 | + loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
| 2343 | + } |
|
| 2217 | 2344 | |
| 2218 | 2345 | // Auto loading? template_javascript() will take care of the local half of this. |
| 2219 | - else |
|
| 2220 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2346 | + else { |
|
| 2347 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2348 | + } |
|
| 2221 | 2349 | |
| 2222 | 2350 | // Queue our JQuery plugins! |
| 2223 | 2351 | loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins'); |
@@ -2240,12 +2368,12 @@ discard block |
||
| 2240 | 2368 | require_once($sourcedir . '/ScheduledTasks.php'); |
| 2241 | 2369 | |
| 2242 | 2370 | // What to do, what to do?! |
| 2243 | - if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) |
|
| 2244 | - AutoTask(); |
|
| 2245 | - else |
|
| 2246 | - ReduceMailQueue(); |
|
| 2247 | - } |
|
| 2248 | - else |
|
| 2371 | + if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) { |
|
| 2372 | + AutoTask(); |
|
| 2373 | + } else { |
|
| 2374 | + ReduceMailQueue(); |
|
| 2375 | + } |
|
| 2376 | + } else |
|
| 2249 | 2377 | { |
| 2250 | 2378 | $type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq'; |
| 2251 | 2379 | $ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time']; |
@@ -2296,8 +2424,9 @@ discard block |
||
| 2296 | 2424 | foreach ($theme_includes as $include) |
| 2297 | 2425 | { |
| 2298 | 2426 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
| 2299 | - if (file_exists($include)) |
|
| 2300 | - require_once($include); |
|
| 2427 | + if (file_exists($include)) { |
|
| 2428 | + require_once($include); |
|
| 2429 | + } |
|
| 2301 | 2430 | } |
| 2302 | 2431 | } |
| 2303 | 2432 | |
@@ -2327,16 +2456,19 @@ discard block |
||
| 2327 | 2456 | // Do any style sheets first, cause we're easy with those. |
| 2328 | 2457 | if (!empty($style_sheets)) |
| 2329 | 2458 | { |
| 2330 | - if (!is_array($style_sheets)) |
|
| 2331 | - $style_sheets = array($style_sheets); |
|
| 2459 | + if (!is_array($style_sheets)) { |
|
| 2460 | + $style_sheets = array($style_sheets); |
|
| 2461 | + } |
|
| 2332 | 2462 | |
| 2333 | - foreach ($style_sheets as $sheet) |
|
| 2334 | - loadCSSFile($sheet . '.css', array(), $sheet); |
|
| 2463 | + foreach ($style_sheets as $sheet) { |
|
| 2464 | + loadCSSFile($sheet . '.css', array(), $sheet); |
|
| 2465 | + } |
|
| 2335 | 2466 | } |
| 2336 | 2467 | |
| 2337 | 2468 | // No template to load? |
| 2338 | - if ($template_name === false) |
|
| 2339 | - return true; |
|
| 2469 | + if ($template_name === false) { |
|
| 2470 | + return true; |
|
| 2471 | + } |
|
| 2340 | 2472 | |
| 2341 | 2473 | $loaded = false; |
| 2342 | 2474 | foreach ($settings['template_dirs'] as $template_dir) |
@@ -2351,12 +2483,14 @@ discard block |
||
| 2351 | 2483 | |
| 2352 | 2484 | if ($loaded) |
| 2353 | 2485 | { |
| 2354 | - if ($db_show_debug === true) |
|
| 2355 | - $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
| 2486 | + if ($db_show_debug === true) { |
|
| 2487 | + $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
| 2488 | + } |
|
| 2356 | 2489 | |
| 2357 | 2490 | // If they have specified an initialization function for this template, go ahead and call it now. |
| 2358 | - if (function_exists('template_' . $template_name . '_init')) |
|
| 2359 | - call_user_func('template_' . $template_name . '_init'); |
|
| 2491 | + if (function_exists('template_' . $template_name . '_init')) { |
|
| 2492 | + call_user_func('template_' . $template_name . '_init'); |
|
| 2493 | + } |
|
| 2360 | 2494 | } |
| 2361 | 2495 | // Hmmm... doesn't exist?! I don't suppose the directory is wrong, is it? |
| 2362 | 2496 | elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default')) |
@@ -2376,13 +2510,14 @@ discard block |
||
| 2376 | 2510 | loadTemplate($template_name); |
| 2377 | 2511 | } |
| 2378 | 2512 | // Cause an error otherwise. |
| 2379 | - elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) |
|
| 2380 | - fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
| 2381 | - elseif ($fatal) |
|
| 2382 | - die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template')); |
|
| 2383 | - else |
|
| 2384 | - return false; |
|
| 2385 | -} |
|
| 2513 | + elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) { |
|
| 2514 | + fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
| 2515 | + } elseif ($fatal) { |
|
| 2516 | + die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template')); |
|
| 2517 | + } else { |
|
| 2518 | + return false; |
|
| 2519 | + } |
|
| 2520 | + } |
|
| 2386 | 2521 | |
| 2387 | 2522 | /** |
| 2388 | 2523 | * Load a sub-template. |
@@ -2400,17 +2535,19 @@ discard block |
||
| 2400 | 2535 | { |
| 2401 | 2536 | global $context, $txt, $db_show_debug; |
| 2402 | 2537 | |
| 2403 | - if ($db_show_debug === true) |
|
| 2404 | - $context['debug']['sub_templates'][] = $sub_template_name; |
|
| 2538 | + if ($db_show_debug === true) { |
|
| 2539 | + $context['debug']['sub_templates'][] = $sub_template_name; |
|
| 2540 | + } |
|
| 2405 | 2541 | |
| 2406 | 2542 | // Figure out what the template function is named. |
| 2407 | 2543 | $theme_function = 'template_' . $sub_template_name; |
| 2408 | - if (function_exists($theme_function)) |
|
| 2409 | - $theme_function(); |
|
| 2410 | - elseif ($fatal === false) |
|
| 2411 | - fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
| 2412 | - elseif ($fatal !== 'ignore') |
|
| 2413 | - die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template')); |
|
| 2544 | + if (function_exists($theme_function)) { |
|
| 2545 | + $theme_function(); |
|
| 2546 | + } elseif ($fatal === false) { |
|
| 2547 | + fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
| 2548 | + } elseif ($fatal !== 'ignore') { |
|
| 2549 | + die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template')); |
|
| 2550 | + } |
|
| 2414 | 2551 | |
| 2415 | 2552 | // Are we showing debugging for templates? Just make sure not to do it before the doctype... |
| 2416 | 2553 | if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml'])) |
@@ -2447,8 +2584,9 @@ discard block |
||
| 2447 | 2584 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
| 2448 | 2585 | |
| 2449 | 2586 | // If this is an external file, automatically set this to false. |
| 2450 | - if (!empty($params['external'])) |
|
| 2451 | - $params['minimize'] = false; |
|
| 2587 | + if (!empty($params['external'])) { |
|
| 2588 | + $params['minimize'] = false; |
|
| 2589 | + } |
|
| 2452 | 2590 | |
| 2453 | 2591 | // Account for shorthand like admin.css?alp21 filenames |
| 2454 | 2592 | $has_seed = strpos($fileName, '.css?'); |
@@ -2465,13 +2603,10 @@ discard block |
||
| 2465 | 2603 | { |
| 2466 | 2604 | $fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2467 | 2605 | $filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2606 | + } else { |
|
| 2607 | + $fileUrl = false; |
|
| 2468 | 2608 | } |
| 2469 | - |
|
| 2470 | - else |
|
| 2471 | - $fileUrl = false; |
|
| 2472 | - } |
|
| 2473 | - |
|
| 2474 | - else |
|
| 2609 | + } else |
|
| 2475 | 2610 | { |
| 2476 | 2611 | $fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2477 | 2612 | $filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2486,12 +2621,14 @@ discard block |
||
| 2486 | 2621 | } |
| 2487 | 2622 | |
| 2488 | 2623 | // Add it to the array for use in the template |
| 2489 | - if (!empty($fileName)) |
|
| 2490 | - $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2624 | + if (!empty($fileName)) { |
|
| 2625 | + $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2626 | + } |
|
| 2491 | 2627 | |
| 2492 | - if (!empty($context['right_to_left']) && !empty($params['rtl'])) |
|
| 2493 | - loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
| 2494 | -} |
|
| 2628 | + if (!empty($context['right_to_left']) && !empty($params['rtl'])) { |
|
| 2629 | + loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
| 2630 | + } |
|
| 2631 | + } |
|
| 2495 | 2632 | |
| 2496 | 2633 | /** |
| 2497 | 2634 | * Add a block of inline css code to be executed later |
@@ -2508,8 +2645,9 @@ discard block |
||
| 2508 | 2645 | global $context; |
| 2509 | 2646 | |
| 2510 | 2647 | // Gotta add something... |
| 2511 | - if (empty($css)) |
|
| 2512 | - return false; |
|
| 2648 | + if (empty($css)) { |
|
| 2649 | + return false; |
|
| 2650 | + } |
|
| 2513 | 2651 | |
| 2514 | 2652 | $context['css_header'][] = $css; |
| 2515 | 2653 | } |
@@ -2544,8 +2682,9 @@ discard block |
||
| 2544 | 2682 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
| 2545 | 2683 | |
| 2546 | 2684 | // If this is an external file, automatically set this to false. |
| 2547 | - if (!empty($params['external'])) |
|
| 2548 | - $params['minimize'] = false; |
|
| 2685 | + if (!empty($params['external'])) { |
|
| 2686 | + $params['minimize'] = false; |
|
| 2687 | + } |
|
| 2549 | 2688 | |
| 2550 | 2689 | // Account for shorthand like admin.js?alp21 filenames |
| 2551 | 2690 | $has_seed = strpos($fileName, '.js?'); |
@@ -2562,16 +2701,12 @@ discard block |
||
| 2562 | 2701 | { |
| 2563 | 2702 | $fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2564 | 2703 | $filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2565 | - } |
|
| 2566 | - |
|
| 2567 | - else |
|
| 2704 | + } else |
|
| 2568 | 2705 | { |
| 2569 | 2706 | $fileUrl = false; |
| 2570 | 2707 | $filePath = false; |
| 2571 | 2708 | } |
| 2572 | - } |
|
| 2573 | - |
|
| 2574 | - else |
|
| 2709 | + } else |
|
| 2575 | 2710 | { |
| 2576 | 2711 | $fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2577 | 2712 | $filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2586,9 +2721,10 @@ discard block |
||
| 2586 | 2721 | } |
| 2587 | 2722 | |
| 2588 | 2723 | // Add it to the array for use in the template |
| 2589 | - if (!empty($fileName)) |
|
| 2590 | - $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2591 | -} |
|
| 2724 | + if (!empty($fileName)) { |
|
| 2725 | + $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2726 | + } |
|
| 2727 | + } |
|
| 2592 | 2728 | |
| 2593 | 2729 | /** |
| 2594 | 2730 | * Add a Javascript variable for output later (for feeding text strings and similar to JS) |
@@ -2602,9 +2738,10 @@ discard block |
||
| 2602 | 2738 | { |
| 2603 | 2739 | global $context; |
| 2604 | 2740 | |
| 2605 | - if (!empty($key) && (!empty($value) || $value === '0')) |
|
| 2606 | - $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
| 2607 | -} |
|
| 2741 | + if (!empty($key) && (!empty($value) || $value === '0')) { |
|
| 2742 | + $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
| 2743 | + } |
|
| 2744 | + } |
|
| 2608 | 2745 | |
| 2609 | 2746 | /** |
| 2610 | 2747 | * Add a block of inline Javascript code to be executed later |
@@ -2621,8 +2758,9 @@ discard block |
||
| 2621 | 2758 | { |
| 2622 | 2759 | global $context; |
| 2623 | 2760 | |
| 2624 | - if (empty($javascript)) |
|
| 2625 | - return false; |
|
| 2761 | + if (empty($javascript)) { |
|
| 2762 | + return false; |
|
| 2763 | + } |
|
| 2626 | 2764 | |
| 2627 | 2765 | $context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript; |
| 2628 | 2766 | } |
@@ -2643,15 +2781,18 @@ discard block |
||
| 2643 | 2781 | static $already_loaded = array(); |
| 2644 | 2782 | |
| 2645 | 2783 | // Default to the user's language. |
| 2646 | - if ($lang == '') |
|
| 2647 | - $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
| 2784 | + if ($lang == '') { |
|
| 2785 | + $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
| 2786 | + } |
|
| 2648 | 2787 | |
| 2649 | 2788 | // Do we want the English version of language file as fallback? |
| 2650 | - if (empty($modSettings['disable_language_fallback']) && $lang != 'english') |
|
| 2651 | - loadLanguage($template_name, 'english', false); |
|
| 2789 | + if (empty($modSettings['disable_language_fallback']) && $lang != 'english') { |
|
| 2790 | + loadLanguage($template_name, 'english', false); |
|
| 2791 | + } |
|
| 2652 | 2792 | |
| 2653 | - if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) |
|
| 2654 | - return $lang; |
|
| 2793 | + if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) { |
|
| 2794 | + return $lang; |
|
| 2795 | + } |
|
| 2655 | 2796 | |
| 2656 | 2797 | // Make sure we have $settings - if not we're in trouble and need to find it! |
| 2657 | 2798 | if (empty($settings['default_theme_dir'])) |
@@ -2662,8 +2803,9 @@ discard block |
||
| 2662 | 2803 | |
| 2663 | 2804 | // What theme are we in? |
| 2664 | 2805 | $theme_name = basename($settings['theme_url']); |
| 2665 | - if (empty($theme_name)) |
|
| 2666 | - $theme_name = 'unknown'; |
|
| 2806 | + if (empty($theme_name)) { |
|
| 2807 | + $theme_name = 'unknown'; |
|
| 2808 | + } |
|
| 2667 | 2809 | |
| 2668 | 2810 | // For each file open it up and write it out! |
| 2669 | 2811 | foreach (explode('+', $template_name) as $template) |
@@ -2705,8 +2847,9 @@ discard block |
||
| 2705 | 2847 | $found = true; |
| 2706 | 2848 | |
| 2707 | 2849 | // setlocale is required for basename() & pathinfo() to work properly on the selected language |
| 2708 | - if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) |
|
| 2709 | - setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
| 2850 | + if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) { |
|
| 2851 | + setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
| 2852 | + } |
|
| 2710 | 2853 | |
| 2711 | 2854 | break; |
| 2712 | 2855 | } |
@@ -2746,8 +2889,9 @@ discard block |
||
| 2746 | 2889 | } |
| 2747 | 2890 | |
| 2748 | 2891 | // Keep track of what we're up to soldier. |
| 2749 | - if ($db_show_debug === true) |
|
| 2750 | - $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
| 2892 | + if ($db_show_debug === true) { |
|
| 2893 | + $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
| 2894 | + } |
|
| 2751 | 2895 | |
| 2752 | 2896 | // Remember what we have loaded, and in which language. |
| 2753 | 2897 | $already_loaded[$template_name] = $lang; |
@@ -2793,8 +2937,9 @@ discard block |
||
| 2793 | 2937 | ) |
| 2794 | 2938 | ); |
| 2795 | 2939 | // In the EXTREMELY unlikely event this happens, give an error message. |
| 2796 | - if ($smcFunc['db_num_rows']($result) == 0) |
|
| 2797 | - fatal_lang_error('parent_not_found', 'critical'); |
|
| 2940 | + if ($smcFunc['db_num_rows']($result) == 0) { |
|
| 2941 | + fatal_lang_error('parent_not_found', 'critical'); |
|
| 2942 | + } |
|
| 2798 | 2943 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 2799 | 2944 | { |
| 2800 | 2945 | if (!isset($boards[$row['id_board']])) |
@@ -2811,8 +2956,8 @@ discard block |
||
| 2811 | 2956 | ); |
| 2812 | 2957 | } |
| 2813 | 2958 | // If a moderator exists for this board, add that moderator for all children too. |
| 2814 | - if (!empty($row['id_moderator'])) |
|
| 2815 | - foreach ($boards as $id => $dummy) |
|
| 2959 | + if (!empty($row['id_moderator'])) { |
|
| 2960 | + foreach ($boards as $id => $dummy) |
|
| 2816 | 2961 | { |
| 2817 | 2962 | $boards[$id]['moderators'][$row['id_moderator']] = array( |
| 2818 | 2963 | 'id' => $row['id_moderator'], |
@@ -2820,11 +2965,12 @@ discard block |
||
| 2820 | 2965 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
| 2821 | 2966 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
| 2822 | 2967 | ); |
| 2968 | + } |
|
| 2823 | 2969 | } |
| 2824 | 2970 | |
| 2825 | 2971 | // If a moderator group exists for this board, add that moderator group for all children too |
| 2826 | - if (!empty($row['id_moderator_group'])) |
|
| 2827 | - foreach ($boards as $id => $dummy) |
|
| 2972 | + if (!empty($row['id_moderator_group'])) { |
|
| 2973 | + foreach ($boards as $id => $dummy) |
|
| 2828 | 2974 | { |
| 2829 | 2975 | $boards[$id]['moderator_groups'][$row['id_moderator_group']] = array( |
| 2830 | 2976 | 'id' => $row['id_moderator_group'], |
@@ -2832,6 +2978,7 @@ discard block |
||
| 2832 | 2978 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
| 2833 | 2979 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
| 2834 | 2980 | ); |
| 2981 | + } |
|
| 2835 | 2982 | } |
| 2836 | 2983 | } |
| 2837 | 2984 | $smcFunc['db_free_result']($result); |
@@ -2858,23 +3005,27 @@ discard block |
||
| 2858 | 3005 | if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null) |
| 2859 | 3006 | { |
| 2860 | 3007 | // If we don't have our ucwords function defined yet, let's load the settings data. |
| 2861 | - if (empty($smcFunc['ucwords'])) |
|
| 2862 | - reloadSettings(); |
|
| 3008 | + if (empty($smcFunc['ucwords'])) { |
|
| 3009 | + reloadSettings(); |
|
| 3010 | + } |
|
| 2863 | 3011 | |
| 2864 | 3012 | // If we don't have our theme information yet, let's get it. |
| 2865 | - if (empty($settings['default_theme_dir'])) |
|
| 2866 | - loadTheme(0, false); |
|
| 3013 | + if (empty($settings['default_theme_dir'])) { |
|
| 3014 | + loadTheme(0, false); |
|
| 3015 | + } |
|
| 2867 | 3016 | |
| 2868 | 3017 | // Default language directories to try. |
| 2869 | 3018 | $language_directories = array( |
| 2870 | 3019 | $settings['default_theme_dir'] . '/languages', |
| 2871 | 3020 | ); |
| 2872 | - if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) |
|
| 2873 | - $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
| 3021 | + if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) { |
|
| 3022 | + $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
| 3023 | + } |
|
| 2874 | 3024 | |
| 2875 | 3025 | // We possibly have a base theme directory. |
| 2876 | - if (!empty($settings['base_theme_dir'])) |
|
| 2877 | - $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
| 3026 | + if (!empty($settings['base_theme_dir'])) { |
|
| 3027 | + $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
| 3028 | + } |
|
| 2878 | 3029 | |
| 2879 | 3030 | // Remove any duplicates. |
| 2880 | 3031 | $language_directories = array_unique($language_directories); |
@@ -2888,20 +3039,21 @@ discard block |
||
| 2888 | 3039 | foreach ($language_directories as $language_dir) |
| 2889 | 3040 | { |
| 2890 | 3041 | // Can't look in here... doesn't exist! |
| 2891 | - if (!file_exists($language_dir)) |
|
| 2892 | - continue; |
|
| 3042 | + if (!file_exists($language_dir)) { |
|
| 3043 | + continue; |
|
| 3044 | + } |
|
| 2893 | 3045 | |
| 2894 | 3046 | $dir = dir($language_dir); |
| 2895 | 3047 | while ($entry = $dir->read()) |
| 2896 | 3048 | { |
| 2897 | 3049 | // Look for the index language file... For good measure skip any "index.language-utf8.php" files |
| 2898 | - if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) |
|
| 2899 | - continue; |
|
| 2900 | - |
|
| 2901 | - if (!empty($langList) && !empty($langList[$matches[1]])) |
|
| 2902 | - $langName = $langList[$matches[1]]; |
|
| 3050 | + if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) { |
|
| 3051 | + continue; |
|
| 3052 | + } |
|
| 2903 | 3053 | |
| 2904 | - else |
|
| 3054 | + if (!empty($langList) && !empty($langList[$matches[1]])) { |
|
| 3055 | + $langName = $langList[$matches[1]]; |
|
| 3056 | + } else |
|
| 2905 | 3057 | { |
| 2906 | 3058 | $langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' '))); |
| 2907 | 3059 | |
@@ -2942,12 +3094,14 @@ discard block |
||
| 2942 | 3094 | } |
| 2943 | 3095 | |
| 2944 | 3096 | // Do we need to store the lang list? |
| 2945 | - if (empty($langList)) |
|
| 2946 | - updateSettings(array('langList' => $smcFunc['json_encode']($catchLang))); |
|
| 3097 | + if (empty($langList)) { |
|
| 3098 | + updateSettings(array('langList' => $smcFunc['json_encode']($catchLang))); |
|
| 3099 | + } |
|
| 2947 | 3100 | |
| 2948 | 3101 | // Let's cash in on this deal. |
| 2949 | - if (!empty($modSettings['cache_enable'])) |
|
| 2950 | - cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
| 3102 | + if (!empty($modSettings['cache_enable'])) { |
|
| 3103 | + cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
| 3104 | + } |
|
| 2951 | 3105 | } |
| 2952 | 3106 | |
| 2953 | 3107 | return $context['languages']; |
@@ -2970,8 +3124,9 @@ discard block |
||
| 2970 | 3124 | global $modSettings, $options, $txt; |
| 2971 | 3125 | static $censor_vulgar = null, $censor_proper; |
| 2972 | 3126 | |
| 2973 | - if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') |
|
| 2974 | - return $text; |
|
| 3127 | + if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') { |
|
| 3128 | + return $text; |
|
| 3129 | + } |
|
| 2975 | 3130 | |
| 2976 | 3131 | // If they haven't yet been loaded, load them. |
| 2977 | 3132 | if ($censor_vulgar == null) |
@@ -2999,9 +3154,9 @@ discard block |
||
| 2999 | 3154 | { |
| 3000 | 3155 | $func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace'; |
| 3001 | 3156 | $text = $func($censor_vulgar, $censor_proper, $text); |
| 3157 | + } else { |
|
| 3158 | + $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
| 3002 | 3159 | } |
| 3003 | - else |
|
| 3004 | - $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
| 3005 | 3160 | |
| 3006 | 3161 | return $text; |
| 3007 | 3162 | } |
@@ -3027,38 +3182,42 @@ discard block |
||
| 3027 | 3182 | @ini_set('track_errors', '1'); |
| 3028 | 3183 | |
| 3029 | 3184 | // Don't include the file more than once, if $once is true. |
| 3030 | - if ($once && in_array($filename, $templates)) |
|
| 3031 | - return; |
|
| 3185 | + if ($once && in_array($filename, $templates)) { |
|
| 3186 | + return; |
|
| 3187 | + } |
|
| 3032 | 3188 | // Add this file to the include list, whether $once is true or not. |
| 3033 | - else |
|
| 3034 | - $templates[] = $filename; |
|
| 3189 | + else { |
|
| 3190 | + $templates[] = $filename; |
|
| 3191 | + } |
|
| 3035 | 3192 | |
| 3036 | 3193 | // Are we going to use eval? |
| 3037 | 3194 | if (empty($modSettings['disableTemplateEval'])) |
| 3038 | 3195 | { |
| 3039 | 3196 | $file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false; |
| 3040 | 3197 | $settings['current_include_filename'] = $filename; |
| 3041 | - } |
|
| 3042 | - else |
|
| 3198 | + } else |
|
| 3043 | 3199 | { |
| 3044 | 3200 | $file_found = file_exists($filename); |
| 3045 | 3201 | |
| 3046 | - if ($once && $file_found) |
|
| 3047 | - require_once($filename); |
|
| 3048 | - elseif ($file_found) |
|
| 3049 | - require($filename); |
|
| 3202 | + if ($once && $file_found) { |
|
| 3203 | + require_once($filename); |
|
| 3204 | + } elseif ($file_found) { |
|
| 3205 | + require($filename); |
|
| 3206 | + } |
|
| 3050 | 3207 | } |
| 3051 | 3208 | |
| 3052 | 3209 | if ($file_found !== true) |
| 3053 | 3210 | { |
| 3054 | 3211 | ob_end_clean(); |
| 3055 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
| 3056 | - @ob_start('ob_gzhandler'); |
|
| 3057 | - else |
|
| 3058 | - ob_start(); |
|
| 3212 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
| 3213 | + @ob_start('ob_gzhandler'); |
|
| 3214 | + } else { |
|
| 3215 | + ob_start(); |
|
| 3216 | + } |
|
| 3059 | 3217 | |
| 3060 | - if (isset($_GET['debug'])) |
|
| 3061 | - header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3218 | + if (isset($_GET['debug'])) { |
|
| 3219 | + header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3220 | + } |
|
| 3062 | 3221 | |
| 3063 | 3222 | // Don't cache error pages!! |
| 3064 | 3223 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -3077,12 +3236,13 @@ discard block |
||
| 3077 | 3236 | echo '<!DOCTYPE html> |
| 3078 | 3237 | <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '> |
| 3079 | 3238 | <head>'; |
| 3080 | - if (isset($context['character_set'])) |
|
| 3081 | - echo ' |
|
| 3239 | + if (isset($context['character_set'])) { |
|
| 3240 | + echo ' |
|
| 3082 | 3241 | <meta charset="', $context['character_set'], '">'; |
| 3242 | + } |
|
| 3083 | 3243 | |
| 3084 | - if (!empty($maintenance) && !allowedTo('admin_forum')) |
|
| 3085 | - echo ' |
|
| 3244 | + if (!empty($maintenance) && !allowedTo('admin_forum')) { |
|
| 3245 | + echo ' |
|
| 3086 | 3246 | <title>', $mtitle, '</title> |
| 3087 | 3247 | </head> |
| 3088 | 3248 | <body> |
@@ -3090,8 +3250,8 @@ discard block |
||
| 3090 | 3250 | ', $mmessage, ' |
| 3091 | 3251 | </body> |
| 3092 | 3252 | </html>'; |
| 3093 | - elseif (!allowedTo('admin_forum')) |
|
| 3094 | - echo ' |
|
| 3253 | + } elseif (!allowedTo('admin_forum')) { |
|
| 3254 | + echo ' |
|
| 3095 | 3255 | <title>', $txt['template_parse_error'], '</title> |
| 3096 | 3256 | </head> |
| 3097 | 3257 | <body> |
@@ -3099,16 +3259,18 @@ discard block |
||
| 3099 | 3259 | ', $txt['template_parse_error_message'], ' |
| 3100 | 3260 | </body> |
| 3101 | 3261 | </html>'; |
| 3102 | - else |
|
| 3262 | + } else |
|
| 3103 | 3263 | { |
| 3104 | 3264 | require_once($sourcedir . '/Subs-Package.php'); |
| 3105 | 3265 | |
| 3106 | 3266 | $error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
| 3107 | 3267 | $error_array = error_get_last(); |
| 3108 | - if (empty($error) && ini_get('track_errors') && !empty($error_array)) |
|
| 3109 | - $error = $error_array['message']; |
|
| 3110 | - if (empty($error)) |
|
| 3111 | - $error = $txt['template_parse_errmsg']; |
|
| 3268 | + if (empty($error) && ini_get('track_errors') && !empty($error_array)) { |
|
| 3269 | + $error = $error_array['message']; |
|
| 3270 | + } |
|
| 3271 | + if (empty($error)) { |
|
| 3272 | + $error = $txt['template_parse_errmsg']; |
|
| 3273 | + } |
|
| 3112 | 3274 | |
| 3113 | 3275 | $error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>')); |
| 3114 | 3276 | |
@@ -3119,11 +3281,12 @@ discard block |
||
| 3119 | 3281 | <h3>', $txt['template_parse_error'], '</h3> |
| 3120 | 3282 | ', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
| 3121 | 3283 | |
| 3122 | - if (!empty($error)) |
|
| 3123 | - echo ' |
|
| 3284 | + if (!empty($error)) { |
|
| 3285 | + echo ' |
|
| 3124 | 3286 | <hr> |
| 3125 | 3287 | |
| 3126 | 3288 | <div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>'; |
| 3289 | + } |
|
| 3127 | 3290 | |
| 3128 | 3291 | // I know, I know... this is VERY COMPLICATED. Still, it's good. |
| 3129 | 3292 | if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0) |
@@ -3133,10 +3296,11 @@ discard block |
||
| 3133 | 3296 | $data2 = preg_split('~\<br( /)?\>~', $data2); |
| 3134 | 3297 | |
| 3135 | 3298 | // Fix the PHP code stuff... |
| 3136 | - if (!isBrowser('gecko')) |
|
| 3137 | - $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
| 3138 | - else |
|
| 3139 | - $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
| 3299 | + if (!isBrowser('gecko')) { |
|
| 3300 | + $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
| 3301 | + } else { |
|
| 3302 | + $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
| 3303 | + } |
|
| 3140 | 3304 | |
| 3141 | 3305 | // Now we get to work around a bug in PHP where it doesn't escape <br>s! |
| 3142 | 3306 | $j = -1; |
@@ -3144,8 +3308,9 @@ discard block |
||
| 3144 | 3308 | { |
| 3145 | 3309 | $j++; |
| 3146 | 3310 | |
| 3147 | - if (substr_count($line, '<br>') == 0) |
|
| 3148 | - continue; |
|
| 3311 | + if (substr_count($line, '<br>') == 0) { |
|
| 3312 | + continue; |
|
| 3313 | + } |
|
| 3149 | 3314 | |
| 3150 | 3315 | $n = substr_count($line, '<br>'); |
| 3151 | 3316 | for ($i = 0; $i < $n; $i++) |
@@ -3164,38 +3329,42 @@ discard block |
||
| 3164 | 3329 | // Figure out what the color coding was before... |
| 3165 | 3330 | $line = max($match[1] - 9, 1); |
| 3166 | 3331 | $last_line = ''; |
| 3167 | - for ($line2 = $line - 1; $line2 > 1; $line2--) |
|
| 3168 | - if (strpos($data2[$line2], '<') !== false) |
|
| 3332 | + for ($line2 = $line - 1; $line2 > 1; $line2--) { |
|
| 3333 | + if (strpos($data2[$line2], '<') !== false) |
|
| 3169 | 3334 | { |
| 3170 | 3335 | if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0) |
| 3171 | 3336 | $last_line = $color_match[1]; |
| 3337 | + } |
|
| 3172 | 3338 | break; |
| 3173 | 3339 | } |
| 3174 | 3340 | |
| 3175 | 3341 | // Show the relevant lines... |
| 3176 | 3342 | for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++) |
| 3177 | 3343 | { |
| 3178 | - if ($line == $match[1]) |
|
| 3179 | - echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
| 3344 | + if ($line == $match[1]) { |
|
| 3345 | + echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
| 3346 | + } |
|
| 3180 | 3347 | |
| 3181 | 3348 | echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> '; |
| 3182 | - if (isset($data2[$line]) && $data2[$line] != '') |
|
| 3183 | - echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
| 3349 | + if (isset($data2[$line]) && $data2[$line] != '') { |
|
| 3350 | + echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
| 3351 | + } |
|
| 3184 | 3352 | |
| 3185 | 3353 | if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0) |
| 3186 | 3354 | { |
| 3187 | 3355 | $last_line = $color_match[1]; |
| 3188 | 3356 | echo '</', substr($last_line, 1, 4), '>'; |
| 3357 | + } elseif ($last_line != '' && strpos($data2[$line], '<') !== false) { |
|
| 3358 | + $last_line = ''; |
|
| 3359 | + } elseif ($last_line != '' && $data2[$line] != '') { |
|
| 3360 | + echo '</', substr($last_line, 1, 4), '>'; |
|
| 3189 | 3361 | } |
| 3190 | - elseif ($last_line != '' && strpos($data2[$line], '<') !== false) |
|
| 3191 | - $last_line = ''; |
|
| 3192 | - elseif ($last_line != '' && $data2[$line] != '') |
|
| 3193 | - echo '</', substr($last_line, 1, 4), '>'; |
|
| 3194 | 3362 | |
| 3195 | - if ($line == $match[1]) |
|
| 3196 | - echo '</pre></div><pre style="margin: 0;">'; |
|
| 3197 | - else |
|
| 3198 | - echo "\n"; |
|
| 3363 | + if ($line == $match[1]) { |
|
| 3364 | + echo '</pre></div><pre style="margin: 0;">'; |
|
| 3365 | + } else { |
|
| 3366 | + echo "\n"; |
|
| 3367 | + } |
|
| 3199 | 3368 | } |
| 3200 | 3369 | |
| 3201 | 3370 | echo '</pre></div>'; |
@@ -3219,8 +3388,9 @@ discard block |
||
| 3219 | 3388 | global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port; |
| 3220 | 3389 | |
| 3221 | 3390 | // Figure out what type of database we are using. |
| 3222 | - if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
|
| 3223 | - $db_type = 'mysql'; |
|
| 3391 | + if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) { |
|
| 3392 | + $db_type = 'mysql'; |
|
| 3393 | + } |
|
| 3224 | 3394 | |
| 3225 | 3395 | // Load the file for the database. |
| 3226 | 3396 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
@@ -3228,8 +3398,9 @@ discard block |
||
| 3228 | 3398 | $db_options = array(); |
| 3229 | 3399 | |
| 3230 | 3400 | // Add in the port if needed |
| 3231 | - if (!empty($db_port)) |
|
| 3232 | - $db_options['port'] = $db_port; |
|
| 3401 | + if (!empty($db_port)) { |
|
| 3402 | + $db_options['port'] = $db_port; |
|
| 3403 | + } |
|
| 3233 | 3404 | |
| 3234 | 3405 | // If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use. |
| 3235 | 3406 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
@@ -3248,13 +3419,15 @@ discard block |
||
| 3248 | 3419 | } |
| 3249 | 3420 | |
| 3250 | 3421 | // Safe guard here, if there isn't a valid connection lets put a stop to it. |
| 3251 | - if (!$db_connection) |
|
| 3252 | - display_db_error(); |
|
| 3422 | + if (!$db_connection) { |
|
| 3423 | + display_db_error(); |
|
| 3424 | + } |
|
| 3253 | 3425 | |
| 3254 | 3426 | // If in SSI mode fix up the prefix. |
| 3255 | - if (SMF == 'SSI') |
|
| 3256 | - db_fix_prefix($db_prefix, $db_name); |
|
| 3257 | -} |
|
| 3427 | + if (SMF == 'SSI') { |
|
| 3428 | + db_fix_prefix($db_prefix, $db_name); |
|
| 3429 | + } |
|
| 3430 | + } |
|
| 3258 | 3431 | |
| 3259 | 3432 | /** |
| 3260 | 3433 | * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it. |
@@ -3268,10 +3441,11 @@ discard block |
||
| 3268 | 3441 | global $sourcedir, $cacheAPI, $cache_accelerator; |
| 3269 | 3442 | |
| 3270 | 3443 | // Not overriding this and we have a cacheAPI, send it back. |
| 3271 | - if (empty($overrideCache) && is_object($cacheAPI)) |
|
| 3272 | - return $cacheAPI; |
|
| 3273 | - elseif (is_null($cacheAPI)) |
|
| 3274 | - $cacheAPI = false; |
|
| 3444 | + if (empty($overrideCache) && is_object($cacheAPI)) { |
|
| 3445 | + return $cacheAPI; |
|
| 3446 | + } elseif (is_null($cacheAPI)) { |
|
| 3447 | + $cacheAPI = false; |
|
| 3448 | + } |
|
| 3275 | 3449 | |
| 3276 | 3450 | // Make sure our class is in session. |
| 3277 | 3451 | require_once($sourcedir . '/Class-CacheAPI.php'); |
@@ -3292,8 +3466,9 @@ discard block |
||
| 3292 | 3466 | if (!$testAPI->isSupported()) |
| 3293 | 3467 | { |
| 3294 | 3468 | // Can we save ourselves? |
| 3295 | - if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') |
|
| 3296 | - return loadCacheAccelerator(null, false); |
|
| 3469 | + if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') { |
|
| 3470 | + return loadCacheAccelerator(null, false); |
|
| 3471 | + } |
|
| 3297 | 3472 | return false; |
| 3298 | 3473 | } |
| 3299 | 3474 | |
@@ -3305,9 +3480,9 @@ discard block |
||
| 3305 | 3480 | { |
| 3306 | 3481 | $cacheAPI = $testAPI; |
| 3307 | 3482 | return $cacheAPI; |
| 3483 | + } else { |
|
| 3484 | + return $testAPI; |
|
| 3308 | 3485 | } |
| 3309 | - else |
|
| 3310 | - return $testAPI; |
|
| 3311 | 3486 | } |
| 3312 | 3487 | } |
| 3313 | 3488 | |
@@ -3327,8 +3502,9 @@ discard block |
||
| 3327 | 3502 | |
| 3328 | 3503 | // @todo Why are we doing this if caching is disabled? |
| 3329 | 3504 | |
| 3330 | - if (function_exists('call_integration_hook')) |
|
| 3331 | - call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
| 3505 | + if (function_exists('call_integration_hook')) { |
|
| 3506 | + call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
| 3507 | + } |
|
| 3332 | 3508 | |
| 3333 | 3509 | /* Refresh the cache if either: |
| 3334 | 3510 | 1. Caching is disabled. |
@@ -3342,16 +3518,19 @@ discard block |
||
| 3342 | 3518 | require_once($sourcedir . '/' . $file); |
| 3343 | 3519 | $cache_block = call_user_func_array($function, $params); |
| 3344 | 3520 | |
| 3345 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) |
|
| 3346 | - cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
| 3521 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) { |
|
| 3522 | + cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
| 3523 | + } |
|
| 3347 | 3524 | } |
| 3348 | 3525 | |
| 3349 | 3526 | // Some cached data may need a freshening up after retrieval. |
| 3350 | - if (!empty($cache_block['post_retri_eval'])) |
|
| 3351 | - eval($cache_block['post_retri_eval']); |
|
| 3527 | + if (!empty($cache_block['post_retri_eval'])) { |
|
| 3528 | + eval($cache_block['post_retri_eval']); |
|
| 3529 | + } |
|
| 3352 | 3530 | |
| 3353 | - if (function_exists('call_integration_hook')) |
|
| 3354 | - call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
| 3531 | + if (function_exists('call_integration_hook')) { |
|
| 3532 | + call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
| 3533 | + } |
|
| 3355 | 3534 | |
| 3356 | 3535 | return $cache_block['data']; |
| 3357 | 3536 | } |
@@ -3378,8 +3557,9 @@ discard block |
||
| 3378 | 3557 | global $smcFunc, $cache_enable, $cacheAPI; |
| 3379 | 3558 | global $cache_hits, $cache_count, $db_show_debug; |
| 3380 | 3559 | |
| 3381 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
| 3382 | - return; |
|
| 3560 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
| 3561 | + return; |
|
| 3562 | + } |
|
| 3383 | 3563 | |
| 3384 | 3564 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
| 3385 | 3565 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3392,12 +3572,14 @@ discard block |
||
| 3392 | 3572 | $value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value)); |
| 3393 | 3573 | $cacheAPI->putData($key, $value, $ttl); |
| 3394 | 3574 | |
| 3395 | - if (function_exists('call_integration_hook')) |
|
| 3396 | - call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
| 3575 | + if (function_exists('call_integration_hook')) { |
|
| 3576 | + call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
| 3577 | + } |
|
| 3397 | 3578 | |
| 3398 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 3399 | - $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 3400 | -} |
|
| 3579 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 3580 | + $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 3581 | + } |
|
| 3582 | + } |
|
| 3401 | 3583 | |
| 3402 | 3584 | /** |
| 3403 | 3585 | * Gets the value from the cache specified by key, so long as it is not older than ttl seconds. |
@@ -3413,8 +3595,9 @@ discard block |
||
| 3413 | 3595 | global $smcFunc, $cache_enable, $cacheAPI; |
| 3414 | 3596 | global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug; |
| 3415 | 3597 | |
| 3416 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
| 3417 | - return; |
|
| 3598 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
| 3599 | + return; |
|
| 3600 | + } |
|
| 3418 | 3601 | |
| 3419 | 3602 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
| 3420 | 3603 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3434,16 +3617,18 @@ discard block |
||
| 3434 | 3617 | |
| 3435 | 3618 | if (empty($value)) |
| 3436 | 3619 | { |
| 3437 | - if (!is_array($cache_misses)) |
|
| 3438 | - $cache_misses = array(); |
|
| 3620 | + if (!is_array($cache_misses)) { |
|
| 3621 | + $cache_misses = array(); |
|
| 3622 | + } |
|
| 3439 | 3623 | |
| 3440 | 3624 | $cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1; |
| 3441 | 3625 | $cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get'); |
| 3442 | 3626 | } |
| 3443 | 3627 | } |
| 3444 | 3628 | |
| 3445 | - if (function_exists('call_integration_hook') && isset($value)) |
|
| 3446 | - call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
| 3629 | + if (function_exists('call_integration_hook') && isset($value)) { |
|
| 3630 | + call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
| 3631 | + } |
|
| 3447 | 3632 | |
| 3448 | 3633 | return empty($value) ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true)); |
| 3449 | 3634 | } |
@@ -3465,8 +3650,9 @@ discard block |
||
| 3465 | 3650 | global $cacheAPI; |
| 3466 | 3651 | |
| 3467 | 3652 | // If we can't get to the API, can't do this. |
| 3468 | - if (empty($cacheAPI)) |
|
| 3469 | - return; |
|
| 3653 | + if (empty($cacheAPI)) { |
|
| 3654 | + return; |
|
| 3655 | + } |
|
| 3470 | 3656 | |
| 3471 | 3657 | // Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure. |
| 3472 | 3658 | $cacheAPI->cleanCache($type); |
@@ -3491,8 +3677,9 @@ discard block |
||
| 3491 | 3677 | global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret; |
| 3492 | 3678 | |
| 3493 | 3679 | // Come on! |
| 3494 | - if (empty($data)) |
|
| 3495 | - return array(); |
|
| 3680 | + if (empty($data)) { |
|
| 3681 | + return array(); |
|
| 3682 | + } |
|
| 3496 | 3683 | |
| 3497 | 3684 | // Set a nice default var. |
| 3498 | 3685 | $image = ''; |
@@ -3500,11 +3687,11 @@ discard block |
||
| 3500 | 3687 | // Gravatar has been set as mandatory! |
| 3501 | 3688 | if (!empty($modSettings['gravatarOverride'])) |
| 3502 | 3689 | { |
| 3503 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) |
|
| 3504 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3505 | - |
|
| 3506 | - else if (!empty($data['email'])) |
|
| 3507 | - $image = get_gravatar_url($data['email']); |
|
| 3690 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) { |
|
| 3691 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3692 | + } else if (!empty($data['email'])) { |
|
| 3693 | + $image = get_gravatar_url($data['email']); |
|
| 3694 | + } |
|
| 3508 | 3695 | } |
| 3509 | 3696 | |
| 3510 | 3697 | // Look if the user has a gravatar field or has set an external url as avatar. |
@@ -3516,54 +3703,60 @@ discard block |
||
| 3516 | 3703 | // Gravatar. |
| 3517 | 3704 | if (stristr($data['avatar'], 'gravatar://')) |
| 3518 | 3705 | { |
| 3519 | - if ($data['avatar'] == 'gravatar://') |
|
| 3520 | - $image = get_gravatar_url($data['email']); |
|
| 3521 | - |
|
| 3522 | - elseif (!empty($modSettings['gravatarAllowExtraEmail'])) |
|
| 3523 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3706 | + if ($data['avatar'] == 'gravatar://') { |
|
| 3707 | + $image = get_gravatar_url($data['email']); |
|
| 3708 | + } elseif (!empty($modSettings['gravatarAllowExtraEmail'])) { |
|
| 3709 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3710 | + } |
|
| 3524 | 3711 | } |
| 3525 | 3712 | |
| 3526 | 3713 | // External url. |
| 3527 | 3714 | else |
| 3528 | 3715 | { |
| 3529 | 3716 | // Using ssl? |
| 3530 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) |
|
| 3531 | - $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
| 3717 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) { |
|
| 3718 | + $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
| 3719 | + } |
|
| 3532 | 3720 | |
| 3533 | 3721 | // Just a plain external url. |
| 3534 | - else |
|
| 3535 | - $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
| 3722 | + else { |
|
| 3723 | + $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
| 3724 | + } |
|
| 3536 | 3725 | } |
| 3537 | 3726 | } |
| 3538 | 3727 | |
| 3539 | 3728 | // Perhaps this user has an attachment as avatar... |
| 3540 | - else if (!empty($data['filename'])) |
|
| 3541 | - $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
| 3729 | + else if (!empty($data['filename'])) { |
|
| 3730 | + $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
| 3731 | + } |
|
| 3542 | 3732 | |
| 3543 | 3733 | // Right... no avatar... use our default image. |
| 3544 | - else |
|
| 3545 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 3734 | + else { |
|
| 3735 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 3736 | + } |
|
| 3546 | 3737 | } |
| 3547 | 3738 | |
| 3548 | 3739 | call_integration_hook('integrate_set_avatar_data', array(&$image, &$data)); |
| 3549 | 3740 | |
| 3550 | 3741 | // At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed. |
| 3551 | - if (!empty($image)) |
|
| 3552 | - return array( |
|
| 3742 | + if (!empty($image)) { |
|
| 3743 | + return array( |
|
| 3553 | 3744 | 'name' => !empty($data['avatar']) ? $data['avatar'] : '', |
| 3554 | 3745 | 'image' => '<img class="avatar" src="' . $image . '" />', |
| 3555 | 3746 | 'href' => $image, |
| 3556 | 3747 | 'url' => $image, |
| 3557 | 3748 | ); |
| 3749 | + } |
|
| 3558 | 3750 | |
| 3559 | 3751 | // Fallback to make life easier for everyone... |
| 3560 | - else |
|
| 3561 | - return array( |
|
| 3752 | + else { |
|
| 3753 | + return array( |
|
| 3562 | 3754 | 'name' => '', |
| 3563 | 3755 | 'image' => '', |
| 3564 | 3756 | 'href' => '', |
| 3565 | 3757 | 'url' => '', |
| 3566 | 3758 | ); |
| 3567 | -} |
|
| 3759 | + } |
|
| 3760 | + } |
|
| 3568 | 3761 | |
| 3569 | 3762 | ?> |
| 3570 | 3763 | \ No newline at end of file |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | /** |
| 501 | 501 | * Returns the amount of affected rows for a query. |
| 502 | 502 | * |
| 503 | - * @param mixed $result |
|
| 503 | + * @param resource|null $result |
|
| 504 | 504 | * |
| 505 | 505 | * @return int |
| 506 | 506 | * |
@@ -869,7 +869,7 @@ discard block |
||
| 869 | 869 | * |
| 870 | 870 | * @param string $db_name The database name |
| 871 | 871 | * @param resource $db_connection The database connection |
| 872 | - * @return true Always returns true |
|
| 872 | + * @return boolean Always returns true |
|
| 873 | 873 | */ |
| 874 | 874 | function smf_db_select_db($db_name, $db_connection) |
| 875 | 875 | { |
@@ -199,22 +199,22 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | case 'date': |
| 201 | 201 | if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
| 202 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
| 202 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]) . '::date'; |
|
| 203 | 203 | else |
| 204 | 204 | smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
| 205 | 205 | break; |
| 206 | 206 | |
| 207 | 207 | case 'time': |
| 208 | 208 | if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
| 209 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
| 209 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]) . '::time'; |
|
| 210 | 210 | else |
| 211 | 211 | smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
| 212 | 212 | break; |
| 213 | 213 | |
| 214 | 214 | case 'datetime': |
| 215 | 215 | 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) |
| 216 | - return 'to_timestamp('. |
|
| 217 | - 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 | + return 'to_timestamp(' . |
|
| 217 | + 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]) . |
|
| 218 | 218 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
| 219 | 219 | else |
| 220 | 220 | smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | $old_pos = 0; |
| 425 | 425 | $pos = -1; |
| 426 | 426 | // Remove the string escape for better runtime |
| 427 | - $db_string_1 = str_replace('\'\'','',$db_string); |
|
| 427 | + $db_string_1 = str_replace('\'\'', '', $db_string); |
|
| 428 | 428 | while (true) |
| 429 | 429 | { |
| 430 | 430 | $pos = strpos($db_string_1, '\'', $pos + 1); |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | if (!empty($keys) && (count($keys) > 0) && $returnmode > 0) |
| 803 | 803 | { |
| 804 | 804 | // we only take the first key |
| 805 | - $returning = ' RETURNING '.$keys[0]; |
|
| 805 | + $returning = ' RETURNING ' . $keys[0]; |
|
| 806 | 806 | $with_returning = true; |
| 807 | 807 | } |
| 808 | 808 | |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '") |
| 834 | 834 | VALUES |
| 835 | 835 | ' . implode(', |
| 836 | - ', $insertRows).$replace.$returning, |
|
| 836 | + ', $insertRows) . $replace . $returning, |
|
| 837 | 837 | array( |
| 838 | 838 | 'security_override' => true, |
| 839 | 839 | 'db_error_skip' => $method == 'ignore' || $table === $db_prefix . 'log_errors', |
@@ -846,7 +846,7 @@ discard block |
||
| 846 | 846 | if ($returnmode === 2) |
| 847 | 847 | $return_var = array(); |
| 848 | 848 | |
| 849 | - while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
|
| 849 | + while (($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
|
| 850 | 850 | { |
| 851 | 851 | if (is_numeric($row[0])) // try to emulate mysql limitation |
| 852 | 852 | { |
@@ -1009,7 +1009,7 @@ discard block |
||
| 1009 | 1009 | */ |
| 1010 | 1010 | function smf_db_custom_order($field, $array_values, $desc = false) |
| 1011 | 1011 | { |
| 1012 | - $return = 'CASE '. $field . ' '; |
|
| 1012 | + $return = 'CASE ' . $field . ' '; |
|
| 1013 | 1013 | $count = count($array_values); |
| 1014 | 1014 | $then = ($desc ? ' THEN -' : ' THEN '); |
| 1015 | 1015 | |
@@ -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', |
@@ -64,11 +65,13 @@ discard block |
||
| 64 | 65 | 'db_error_insert' => 'smf_db_error_insert', |
| 65 | 66 | 'db_custom_order' => 'smf_db_custom_order', |
| 66 | 67 | ); |
| 68 | + } |
|
| 67 | 69 | |
| 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'] . '\'')); |
|
| 70 | + if (!empty($db_options['persist'])) { |
|
| 71 | + $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 72 | + } else { |
|
| 73 | + $connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 74 | + } |
|
| 72 | 75 | |
| 73 | 76 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 74 | 77 | if (!$connection) |
@@ -76,8 +79,7 @@ discard block |
||
| 76 | 79 | if (!empty($db_options['non_fatal'])) |
| 77 | 80 | { |
| 78 | 81 | return null; |
| 79 | - } |
|
| 80 | - else |
|
| 82 | + } else |
|
| 81 | 83 | { |
| 82 | 84 | display_db_error(); |
| 83 | 85 | } |
@@ -128,31 +130,38 @@ discard block |
||
| 128 | 130 | |
| 129 | 131 | list ($values, $connection) = $db_callback; |
| 130 | 132 | |
| 131 | - if ($matches[1] === 'db_prefix') |
|
| 132 | - return $db_prefix; |
|
| 133 | + if ($matches[1] === 'db_prefix') { |
|
| 134 | + return $db_prefix; |
|
| 135 | + } |
|
| 133 | 136 | |
| 134 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
| 135 | - return $user_info[$matches[1]]; |
|
| 137 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
| 138 | + return $user_info[$matches[1]]; |
|
| 139 | + } |
|
| 136 | 140 | |
| 137 | - if ($matches[1] === 'empty') |
|
| 138 | - return '\'\''; |
|
| 141 | + if ($matches[1] === 'empty') { |
|
| 142 | + return '\'\''; |
|
| 143 | + } |
|
| 139 | 144 | |
| 140 | - if (!isset($matches[2])) |
|
| 141 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 145 | + if (!isset($matches[2])) { |
|
| 146 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 147 | + } |
|
| 142 | 148 | |
| 143 | - if ($matches[1] === 'literal') |
|
| 144 | - return '\'' . pg_escape_string($matches[2]) . '\''; |
|
| 149 | + if ($matches[1] === 'literal') { |
|
| 150 | + return '\'' . pg_escape_string($matches[2]) . '\''; |
|
| 151 | + } |
|
| 145 | 152 | |
| 146 | - if (!isset($values[$matches[2]])) |
|
| 147 | - 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 | + if (!isset($values[$matches[2]])) { |
|
| 154 | + 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__); |
|
| 155 | + } |
|
| 148 | 156 | |
| 149 | 157 | $replacement = $values[$matches[2]]; |
| 150 | 158 | |
| 151 | 159 | switch ($matches[1]) |
| 152 | 160 | { |
| 153 | 161 | case 'int': |
| 154 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 155 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 162 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
| 163 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 164 | + } |
|
| 156 | 165 | return (string) (int) $replacement; |
| 157 | 166 | break; |
| 158 | 167 | |
@@ -164,65 +173,73 @@ discard block |
||
| 164 | 173 | case 'array_int': |
| 165 | 174 | if (is_array($replacement)) |
| 166 | 175 | { |
| 167 | - if (empty($replacement)) |
|
| 168 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 176 | + if (empty($replacement)) { |
|
| 177 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 178 | + } |
|
| 169 | 179 | |
| 170 | 180 | foreach ($replacement as $key => $value) |
| 171 | 181 | { |
| 172 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 173 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 182 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 183 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 184 | + } |
|
| 174 | 185 | |
| 175 | 186 | $replacement[$key] = (string) (int) $value; |
| 176 | 187 | } |
| 177 | 188 | |
| 178 | 189 | return implode(', ', $replacement); |
| 190 | + } else { |
|
| 191 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 179 | 192 | } |
| 180 | - else |
|
| 181 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 182 | 193 | |
| 183 | 194 | break; |
| 184 | 195 | |
| 185 | 196 | case 'array_string': |
| 186 | 197 | if (is_array($replacement)) |
| 187 | 198 | { |
| 188 | - if (empty($replacement)) |
|
| 189 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 199 | + if (empty($replacement)) { |
|
| 200 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 201 | + } |
|
| 190 | 202 | |
| 191 | - foreach ($replacement as $key => $value) |
|
| 192 | - $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 203 | + foreach ($replacement as $key => $value) { |
|
| 204 | + $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 205 | + } |
|
| 193 | 206 | |
| 194 | 207 | return implode(', ', $replacement); |
| 208 | + } else { |
|
| 209 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 195 | 210 | } |
| 196 | - else |
|
| 197 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 198 | 211 | break; |
| 199 | 212 | |
| 200 | 213 | case 'date': |
| 201 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
| 202 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
| 203 | - else |
|
| 204 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 214 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 215 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
| 216 | + } else { |
|
| 217 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 218 | + } |
|
| 205 | 219 | break; |
| 206 | 220 | |
| 207 | 221 | case 'time': |
| 208 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
| 209 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
| 210 | - else |
|
| 211 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 222 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
| 223 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
| 224 | + } else { |
|
| 225 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 226 | + } |
|
| 212 | 227 | break; |
| 213 | 228 | |
| 214 | 229 | case 'datetime': |
| 215 | - 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) |
|
| 216 | - return 'to_timestamp('. |
|
| 230 | + 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) { |
|
| 231 | + return 'to_timestamp('. |
|
| 217 | 232 | 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]). |
| 218 | 233 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
| 219 | - else |
|
| 220 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 234 | + } else { |
|
| 235 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 236 | + } |
|
| 221 | 237 | break; |
| 222 | 238 | |
| 223 | 239 | case 'float': |
| 224 | - if (!is_numeric($replacement)) |
|
| 225 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 240 | + if (!is_numeric($replacement)) { |
|
| 241 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 242 | + } |
|
| 226 | 243 | return (string) (float) $replacement; |
| 227 | 244 | break; |
| 228 | 245 | |
@@ -235,31 +252,36 @@ discard block |
||
| 235 | 252 | break; |
| 236 | 253 | |
| 237 | 254 | case 'inet': |
| 238 | - if ($replacement == 'null' || $replacement == '') |
|
| 239 | - return 'null'; |
|
| 240 | - if (inet_pton($replacement) === false) |
|
| 241 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 255 | + if ($replacement == 'null' || $replacement == '') { |
|
| 256 | + return 'null'; |
|
| 257 | + } |
|
| 258 | + if (inet_pton($replacement) === false) { |
|
| 259 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 260 | + } |
|
| 242 | 261 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
| 243 | 262 | |
| 244 | 263 | case 'array_inet': |
| 245 | 264 | if (is_array($replacement)) |
| 246 | 265 | { |
| 247 | - if (empty($replacement)) |
|
| 248 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 266 | + if (empty($replacement)) { |
|
| 267 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 268 | + } |
|
| 249 | 269 | |
| 250 | 270 | foreach ($replacement as $key => $value) |
| 251 | 271 | { |
| 252 | - if ($replacement == 'null' || $replacement == '') |
|
| 253 | - $replacement[$key] = 'null'; |
|
| 254 | - if (!isValidIP($value)) |
|
| 255 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 272 | + if ($replacement == 'null' || $replacement == '') { |
|
| 273 | + $replacement[$key] = 'null'; |
|
| 274 | + } |
|
| 275 | + if (!isValidIP($value)) { |
|
| 276 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 277 | + } |
|
| 256 | 278 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
| 257 | 279 | } |
| 258 | 280 | |
| 259 | 281 | return implode(', ', $replacement); |
| 282 | + } else { |
|
| 283 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 260 | 284 | } |
| 261 | - else |
|
| 262 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 263 | 285 | break; |
| 264 | 286 | |
| 265 | 287 | default: |
@@ -350,14 +372,16 @@ discard block |
||
| 350 | 372 | ), |
| 351 | 373 | ); |
| 352 | 374 | |
| 353 | - if (isset($replacements[$identifier])) |
|
| 354 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 375 | + if (isset($replacements[$identifier])) { |
|
| 376 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 377 | + } |
|
| 355 | 378 | |
| 356 | 379 | // Limits need to be a little different. |
| 357 | 380 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
| 358 | 381 | |
| 359 | - if (trim($db_string) == '') |
|
| 360 | - return false; |
|
| 382 | + if (trim($db_string) == '') { |
|
| 383 | + return false; |
|
| 384 | + } |
|
| 361 | 385 | |
| 362 | 386 | // Comments that are allowed in a query are preg_removed. |
| 363 | 387 | static $allowed_comments_from = array( |
@@ -377,8 +401,9 @@ discard block |
||
| 377 | 401 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 378 | 402 | $db_replace_result = 0; |
| 379 | 403 | |
| 380 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 381 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 404 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 405 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 406 | + } |
|
| 382 | 407 | |
| 383 | 408 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
| 384 | 409 | { |
@@ -399,8 +424,9 @@ discard block |
||
| 399 | 424 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 400 | 425 | |
| 401 | 426 | // Initialize $db_cache if not already initialized. |
| 402 | - if (!isset($db_cache)) |
|
| 403 | - $db_cache = array(); |
|
| 427 | + if (!isset($db_cache)) { |
|
| 428 | + $db_cache = array(); |
|
| 429 | + } |
|
| 404 | 430 | |
| 405 | 431 | if (!empty($_SESSION['debug_redirect'])) |
| 406 | 432 | { |
@@ -428,17 +454,18 @@ discard block |
||
| 428 | 454 | while (true) |
| 429 | 455 | { |
| 430 | 456 | $pos = strpos($db_string_1, '\'', $pos + 1); |
| 431 | - if ($pos === false) |
|
| 432 | - break; |
|
| 457 | + if ($pos === false) { |
|
| 458 | + break; |
|
| 459 | + } |
|
| 433 | 460 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
| 434 | 461 | |
| 435 | 462 | while (true) |
| 436 | 463 | { |
| 437 | 464 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
| 438 | 465 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
| 439 | - if ($pos1 === false) |
|
| 440 | - break; |
|
| 441 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
| 466 | + if ($pos1 === false) { |
|
| 467 | + break; |
|
| 468 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
| 442 | 469 | { |
| 443 | 470 | $pos = $pos1; |
| 444 | 471 | break; |
@@ -454,16 +481,19 @@ discard block |
||
| 454 | 481 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 455 | 482 | |
| 456 | 483 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 457 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 458 | - $fail = true; |
|
| 484 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 485 | + $fail = true; |
|
| 486 | + } |
|
| 459 | 487 | // Trying to change passwords, slow us down, or something? |
| 460 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 461 | - $fail = true; |
|
| 462 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 463 | - $fail = true; |
|
| 488 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 489 | + $fail = true; |
|
| 490 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 491 | + $fail = true; |
|
| 492 | + } |
|
| 464 | 493 | |
| 465 | - if (!empty($fail) && function_exists('log_error')) |
|
| 466 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 494 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 495 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 496 | + } |
|
| 467 | 497 | } |
| 468 | 498 | |
| 469 | 499 | // Set optimize stuff |
@@ -482,18 +512,21 @@ discard block |
||
| 482 | 512 | |
| 483 | 513 | $db_string = $query_hints_set . $db_string; |
| 484 | 514 | |
| 485 | - if (isset($db_show_debug) && $db_show_debug === true && $db_cache[$db_count]['q'] != '...') |
|
| 486 | - $db_cache[$db_count]['q'] = "\t\t" . $db_string; |
|
| 515 | + if (isset($db_show_debug) && $db_show_debug === true && $db_cache[$db_count]['q'] != '...') { |
|
| 516 | + $db_cache[$db_count]['q'] = "\t\t" . $db_string; |
|
| 517 | + } |
|
| 487 | 518 | } |
| 488 | 519 | |
| 489 | 520 | $db_last_result = @pg_query($connection, $db_string); |
| 490 | 521 | |
| 491 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
| 492 | - $db_last_result = smf_db_error($db_string, $connection); |
|
| 522 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
| 523 | + $db_last_result = smf_db_error($db_string, $connection); |
|
| 524 | + } |
|
| 493 | 525 | |
| 494 | 526 | // Debugging. |
| 495 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 496 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 527 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 528 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 529 | + } |
|
| 497 | 530 | |
| 498 | 531 | return $db_last_result; |
| 499 | 532 | } |
@@ -510,10 +543,11 @@ discard block |
||
| 510 | 543 | { |
| 511 | 544 | global $db_last_result, $db_replace_result; |
| 512 | 545 | |
| 513 | - if ($db_replace_result) |
|
| 514 | - return $db_replace_result; |
|
| 515 | - elseif ($result === null && !$db_last_result) |
|
| 516 | - return 0; |
|
| 546 | + if ($db_replace_result) { |
|
| 547 | + return $db_replace_result; |
|
| 548 | + } elseif ($result === null && !$db_last_result) { |
|
| 549 | + return 0; |
|
| 550 | + } |
|
| 517 | 551 | |
| 518 | 552 | return pg_affected_rows($result === null ? $db_last_result : $result); |
| 519 | 553 | } |
@@ -537,8 +571,9 @@ discard block |
||
| 537 | 571 | array( |
| 538 | 572 | ) |
| 539 | 573 | ); |
| 540 | - if (!$request) |
|
| 541 | - return false; |
|
| 574 | + if (!$request) { |
|
| 575 | + return false; |
|
| 576 | + } |
|
| 542 | 577 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
| 543 | 578 | $smcFunc['db_free_result']($request); |
| 544 | 579 | |
@@ -559,12 +594,13 @@ discard block |
||
| 559 | 594 | // Decide which connection to use |
| 560 | 595 | $connection = $connection === null ? $db_connection : $connection; |
| 561 | 596 | |
| 562 | - if ($type == 'begin') |
|
| 563 | - return @pg_query($connection, 'BEGIN'); |
|
| 564 | - elseif ($type == 'rollback') |
|
| 565 | - return @pg_query($connection, 'ROLLBACK'); |
|
| 566 | - elseif ($type == 'commit') |
|
| 567 | - return @pg_query($connection, 'COMMIT'); |
|
| 597 | + if ($type == 'begin') { |
|
| 598 | + return @pg_query($connection, 'BEGIN'); |
|
| 599 | + } elseif ($type == 'rollback') { |
|
| 600 | + return @pg_query($connection, 'ROLLBACK'); |
|
| 601 | + } elseif ($type == 'commit') { |
|
| 602 | + return @pg_query($connection, 'COMMIT'); |
|
| 603 | + } |
|
| 568 | 604 | |
| 569 | 605 | return false; |
| 570 | 606 | } |
@@ -592,19 +628,22 @@ discard block |
||
| 592 | 628 | $query_error = @pg_last_error($connection); |
| 593 | 629 | |
| 594 | 630 | // Log the error. |
| 595 | - if (function_exists('log_error')) |
|
| 596 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
| 631 | + if (function_exists('log_error')) { |
|
| 632 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
| 633 | + } |
|
| 597 | 634 | |
| 598 | 635 | // Nothing's defined yet... just die with it. |
| 599 | - if (empty($context) || empty($txt)) |
|
| 600 | - die($query_error); |
|
| 636 | + if (empty($context) || empty($txt)) { |
|
| 637 | + die($query_error); |
|
| 638 | + } |
|
| 601 | 639 | |
| 602 | 640 | // Show an error message, if possible. |
| 603 | 641 | $context['error_title'] = $txt['database_error']; |
| 604 | - if (allowedTo('admin_forum')) |
|
| 605 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 606 | - else |
|
| 607 | - $context['error_message'] = $txt['try_again']; |
|
| 642 | + if (allowedTo('admin_forum')) { |
|
| 643 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 644 | + } else { |
|
| 645 | + $context['error_message'] = $txt['try_again']; |
|
| 646 | + } |
|
| 608 | 647 | |
| 609 | 648 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 610 | 649 | { |
@@ -626,12 +665,14 @@ discard block |
||
| 626 | 665 | { |
| 627 | 666 | global $db_row_count; |
| 628 | 667 | |
| 629 | - if ($counter !== false) |
|
| 630 | - return pg_fetch_row($request, $counter); |
|
| 668 | + if ($counter !== false) { |
|
| 669 | + return pg_fetch_row($request, $counter); |
|
| 670 | + } |
|
| 631 | 671 | |
| 632 | 672 | // Reset the row counter... |
| 633 | - if (!isset($db_row_count[(int) $request])) |
|
| 634 | - $db_row_count[(int) $request] = 0; |
|
| 673 | + if (!isset($db_row_count[(int) $request])) { |
|
| 674 | + $db_row_count[(int) $request] = 0; |
|
| 675 | + } |
|
| 635 | 676 | |
| 636 | 677 | // Return the right row. |
| 637 | 678 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -648,12 +689,14 @@ discard block |
||
| 648 | 689 | { |
| 649 | 690 | global $db_row_count; |
| 650 | 691 | |
| 651 | - if ($counter !== false) |
|
| 652 | - return pg_fetch_assoc($request, $counter); |
|
| 692 | + if ($counter !== false) { |
|
| 693 | + return pg_fetch_assoc($request, $counter); |
|
| 694 | + } |
|
| 653 | 695 | |
| 654 | 696 | // Reset the row counter... |
| 655 | - if (!isset($db_row_count[(int) $request])) |
|
| 656 | - $db_row_count[(int) $request] = 0; |
|
| 697 | + if (!isset($db_row_count[(int) $request])) { |
|
| 698 | + $db_row_count[(int) $request] = 0; |
|
| 699 | + } |
|
| 657 | 700 | |
| 658 | 701 | // Return the right row. |
| 659 | 702 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -706,11 +749,13 @@ discard block |
||
| 706 | 749 | |
| 707 | 750 | $replace = ''; |
| 708 | 751 | |
| 709 | - if (empty($data)) |
|
| 710 | - return; |
|
| 752 | + if (empty($data)) { |
|
| 753 | + return; |
|
| 754 | + } |
|
| 711 | 755 | |
| 712 | - if (!is_array($data[array_rand($data)])) |
|
| 713 | - $data = array($data); |
|
| 756 | + if (!is_array($data[array_rand($data)])) { |
|
| 757 | + $data = array($data); |
|
| 758 | + } |
|
| 714 | 759 | |
| 715 | 760 | // Replace the prefix holder with the actual prefix. |
| 716 | 761 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -729,11 +774,13 @@ discard block |
||
| 729 | 774 | //pg 9.5 got replace support |
| 730 | 775 | $pg_version = $smcFunc['db_get_version'](); |
| 731 | 776 | // if we got a Beta Version |
| 732 | - if (stripos($pg_version, 'beta') !== false) |
|
| 733 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
| 777 | + if (stripos($pg_version, 'beta') !== false) { |
|
| 778 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
| 779 | + } |
|
| 734 | 780 | // or RC |
| 735 | - if (stripos($pg_version, 'rc') !== false) |
|
| 736 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
| 781 | + if (stripos($pg_version, 'rc') !== false) { |
|
| 782 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
| 783 | + } |
|
| 737 | 784 | |
| 738 | 785 | $replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false); |
| 739 | 786 | } |
@@ -752,32 +799,35 @@ discard block |
||
| 752 | 799 | $key_str .= ($count_pk > 0 ? ',' : ''); |
| 753 | 800 | $key_str .= $columnName; |
| 754 | 801 | $count_pk++; |
| 755 | - } |
|
| 756 | - else if ($method == 'replace') //normal field |
|
| 802 | + } else if ($method == 'replace') { |
|
| 803 | + //normal field |
|
| 757 | 804 | { |
| 758 | 805 | $col_str .= ($count > 0 ? ',' : ''); |
| 806 | + } |
|
| 759 | 807 | $col_str .= $columnName . ' = EXCLUDED.' . $columnName; |
| 760 | 808 | $count++; |
| 761 | 809 | } |
| 762 | 810 | } |
| 763 | - if ($method == 'replace') |
|
| 764 | - $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
| 765 | - else |
|
| 766 | - $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
| 767 | - } |
|
| 768 | - else if ($method == 'replace') |
|
| 811 | + if ($method == 'replace') { |
|
| 812 | + $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
| 813 | + } else { |
|
| 814 | + $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
| 815 | + } |
|
| 816 | + } else if ($method == 'replace') |
|
| 769 | 817 | { |
| 770 | 818 | foreach ($columns as $columnName => $type) |
| 771 | 819 | { |
| 772 | 820 | // Are we restricting the length? |
| 773 | - if (strpos($type, 'string-') !== false) |
|
| 774 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 775 | - else |
|
| 776 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 821 | + if (strpos($type, 'string-') !== false) { |
|
| 822 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 823 | + } else { |
|
| 824 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 825 | + } |
|
| 777 | 826 | |
| 778 | 827 | // A key? That's what we were looking for. |
| 779 | - if (in_array($columnName, $keys)) |
|
| 780 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 828 | + if (in_array($columnName, $keys)) { |
|
| 829 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 830 | + } |
|
| 781 | 831 | $count++; |
| 782 | 832 | } |
| 783 | 833 | |
@@ -813,10 +863,11 @@ discard block |
||
| 813 | 863 | foreach ($columns as $columnName => $type) |
| 814 | 864 | { |
| 815 | 865 | // Are we restricting the length? |
| 816 | - if (strpos($type, 'string-') !== false) |
|
| 817 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 818 | - else |
|
| 819 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 866 | + if (strpos($type, 'string-') !== false) { |
|
| 867 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 868 | + } else { |
|
| 869 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 870 | + } |
|
| 820 | 871 | } |
| 821 | 872 | $insertData = substr($insertData, 0, -2) . ')'; |
| 822 | 873 | |
@@ -825,8 +876,9 @@ discard block |
||
| 825 | 876 | |
| 826 | 877 | // Here's where the variables are injected to the query. |
| 827 | 878 | $insertRows = array(); |
| 828 | - foreach ($data as $dataRow) |
|
| 829 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 879 | + foreach ($data as $dataRow) { |
|
| 880 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 881 | + } |
|
| 830 | 882 | |
| 831 | 883 | // Do the insert. |
| 832 | 884 | $request = $smcFunc['db_query']('', ' |
@@ -843,19 +895,21 @@ discard block |
||
| 843 | 895 | |
| 844 | 896 | if ($with_returning && $request !== false) |
| 845 | 897 | { |
| 846 | - if ($returnmode === 2) |
|
| 847 | - $return_var = array(); |
|
| 898 | + if ($returnmode === 2) { |
|
| 899 | + $return_var = array(); |
|
| 900 | + } |
|
| 848 | 901 | |
| 849 | 902 | while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
| 850 | 903 | { |
| 851 | - if (is_numeric($row[0])) // try to emulate mysql limitation |
|
| 904 | + if (is_numeric($row[0])) { |
|
| 905 | + // try to emulate mysql limitation |
|
| 852 | 906 | { |
| 853 | 907 | if ($returnmode === 1) |
| 854 | 908 | $return_var = $row[0]; |
| 855 | - elseif ($returnmode === 2) |
|
| 856 | - $return_var[] = $row[0]; |
|
| 857 | - } |
|
| 858 | - else |
|
| 909 | + } elseif ($returnmode === 2) { |
|
| 910 | + $return_var[] = $row[0]; |
|
| 911 | + } |
|
| 912 | + } else |
|
| 859 | 913 | { |
| 860 | 914 | $with_returning = false; |
| 861 | 915 | trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR); |
@@ -864,9 +918,10 @@ discard block |
||
| 864 | 918 | } |
| 865 | 919 | } |
| 866 | 920 | |
| 867 | - if ($with_returning && !empty($return_var)) |
|
| 868 | - return $return_var; |
|
| 869 | -} |
|
| 921 | + if ($with_returning && !empty($return_var)) { |
|
| 922 | + return $return_var; |
|
| 923 | + } |
|
| 924 | + } |
|
| 870 | 925 | |
| 871 | 926 | /** |
| 872 | 927 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -903,8 +958,9 @@ discard block |
||
| 903 | 958 | */ |
| 904 | 959 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 905 | 960 | { |
| 906 | - if (empty($log_message)) |
|
| 907 | - $log_message = $error_message; |
|
| 961 | + if (empty($log_message)) { |
|
| 962 | + $log_message = $error_message; |
|
| 963 | + } |
|
| 908 | 964 | |
| 909 | 965 | foreach (debug_backtrace() as $step) |
| 910 | 966 | { |
@@ -923,12 +979,14 @@ discard block |
||
| 923 | 979 | } |
| 924 | 980 | |
| 925 | 981 | // A special case - we want the file and line numbers for debugging. |
| 926 | - if ($error_type == 'return') |
|
| 927 | - return array($file, $line); |
|
| 982 | + if ($error_type == 'return') { |
|
| 983 | + return array($file, $line); |
|
| 984 | + } |
|
| 928 | 985 | |
| 929 | 986 | // Is always a critical error. |
| 930 | - if (function_exists('log_error')) |
|
| 931 | - log_error($log_message, 'critical', $file, $line); |
|
| 987 | + if (function_exists('log_error')) { |
|
| 988 | + log_error($log_message, 'critical', $file, $line); |
|
| 989 | + } |
|
| 932 | 990 | |
| 933 | 991 | if (function_exists('fatal_error')) |
| 934 | 992 | { |
@@ -936,12 +994,12 @@ discard block |
||
| 936 | 994 | |
| 937 | 995 | // Cannot continue... |
| 938 | 996 | exit; |
| 997 | + } elseif ($error_type) { |
|
| 998 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 999 | + } else { |
|
| 1000 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 1001 | + } |
|
| 939 | 1002 | } |
| 940 | - elseif ($error_type) |
|
| 941 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 942 | - else |
|
| 943 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 944 | -} |
|
| 945 | 1003 | |
| 946 | 1004 | /** |
| 947 | 1005 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -958,10 +1016,11 @@ discard block |
||
| 958 | 1016 | '\\' => '\\\\', |
| 959 | 1017 | ); |
| 960 | 1018 | |
| 961 | - if ($translate_human_wildcards) |
|
| 962 | - $replacements += array( |
|
| 1019 | + if ($translate_human_wildcards) { |
|
| 1020 | + $replacements += array( |
|
| 963 | 1021 | '*' => '%', |
| 964 | 1022 | ); |
| 1023 | + } |
|
| 965 | 1024 | |
| 966 | 1025 | return strtr($string, $replacements); |
| 967 | 1026 | } |
@@ -989,11 +1048,12 @@ discard block |
||
| 989 | 1048 | global $db_prefix, $db_connection; |
| 990 | 1049 | static $pg_error_data_prep; |
| 991 | 1050 | |
| 992 | - if (empty($pg_error_data_prep)) |
|
| 993 | - $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
| 1051 | + if (empty($pg_error_data_prep)) { |
|
| 1052 | + $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
| 994 | 1053 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line) |
| 995 | 1054 | VALUES( $1, $2, $3, $4, $5, $6, $7, $8, $9)' |
| 996 | 1055 | ); |
| 1056 | + } |
|
| 997 | 1057 | |
| 998 | 1058 | pg_execute($db_connection, 'smf_log_errors', $error_array); |
| 999 | 1059 | } |
@@ -1013,8 +1073,9 @@ discard block |
||
| 1013 | 1073 | $count = count($array_values); |
| 1014 | 1074 | $then = ($desc ? ' THEN -' : ' THEN '); |
| 1015 | 1075 | |
| 1016 | - for ($i = 0; $i < $count; $i++) |
|
| 1017 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
| 1076 | + for ($i = 0; $i < $count; $i++) { |
|
| 1077 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
| 1078 | + } |
|
| 1018 | 1079 | |
| 1019 | 1080 | $return .= 'END'; |
| 1020 | 1081 | return $return; |