@@ -233,11 +233,13 @@ |
||
| 233 | 233 | ); |
| 234 | 234 | |
| 235 | 235 | $id_searchs = array(); |
| 236 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
| 237 | - $id_searchs[] = $row['id_search']; |
|
| 236 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
| 237 | + $id_searchs[] = $row['id_search']; |
|
| 238 | + } |
|
| 238 | 239 | |
| 239 | - if (count($id_searchs) < 1) |
|
| 240 | - return; |
|
| 240 | + if (count($id_searchs) < 1) { |
|
| 241 | + return; |
|
| 242 | + } |
|
| 241 | 243 | |
| 242 | 244 | $smcFunc['db_query']('',' |
| 243 | 245 | DELETE FROM {db_prefix}log_search_results |
@@ -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 | * Standard non full index, non custom index search |
@@ -27,8 +28,9 @@ discard block |
||
| 27 | 28 | $return = false; |
| 28 | 29 | |
| 29 | 30 | // Maybe parent got support |
| 30 | - if (!$return) |
|
| 31 | - $return = parent::supportsMethod($methodName, $query_params); |
|
| 31 | + if (!$return) { |
|
| 32 | + $return = parent::supportsMethod($methodName, $query_params); |
|
| 33 | + } |
|
| 32 | 34 | |
| 33 | 35 | return $return; |
| 34 | 36 | } |
@@ -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 | * Class fulltext_search |
@@ -75,8 +76,9 @@ discard block |
||
| 75 | 76 | } |
| 76 | 77 | |
| 77 | 78 | // Maybe parent got support |
| 78 | - if (!$return) |
|
| 79 | - $return = parent::supportsMethod($methodName, $query_params); |
|
| 79 | + if (!$return) { |
|
| 80 | + $return = parent::supportsMethod($methodName, $query_params); |
|
| 81 | + } |
|
| 80 | 82 | |
| 81 | 83 | return $return; |
| 82 | 84 | } |
@@ -92,8 +94,9 @@ discard block |
||
| 92 | 94 | { |
| 93 | 95 | global $smcFunc, $db_type; |
| 94 | 96 | |
| 95 | - if ($db_type == 'postgresql') |
|
| 96 | - return 0; |
|
| 97 | + if ($db_type == 'postgresql') { |
|
| 98 | + return 0; |
|
| 99 | + } |
|
| 97 | 100 | // Try to determine the minimum number of letters for a fulltext search. |
| 98 | 101 | $request = $smcFunc['db_search_query']('max_fulltext_length', ' |
| 99 | 102 | SHOW VARIABLES |
@@ -108,8 +111,9 @@ discard block |
||
| 108 | 111 | $smcFunc['db_free_result']($request); |
| 109 | 112 | } |
| 110 | 113 | // 4 is the MySQL default... |
| 111 | - else |
|
| 112 | - $min_word_length = 4; |
|
| 114 | + else { |
|
| 115 | + $min_word_length = 4; |
|
| 116 | + } |
|
| 113 | 117 | |
| 114 | 118 | return $min_word_length; |
| 115 | 119 | } |
@@ -148,8 +152,7 @@ discard block |
||
| 148 | 152 | $wordsSearch['words'][] = trim($word, "/*- "); |
| 149 | 153 | $wordsSearch['complex_words'][] = count($subwords) === 1 ? $word : '"' . $word . '"'; |
| 150 | 154 | } |
| 151 | - } |
|
| 152 | - elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
| 155 | + } elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
| 153 | 156 | { |
| 154 | 157 | // short words have feelings too |
| 155 | 158 | $wordsSearch['words'][] = trim($word, "/*- "); |
@@ -159,8 +162,9 @@ discard block |
||
| 159 | 162 | |
| 160 | 163 | $fulltextWord = count($subwords) === 1 ? $word : '"' . $word . '"'; |
| 161 | 164 | $wordsSearch['indexed_words'][] = $fulltextWord; |
| 162 | - if ($isExcluded) |
|
| 163 | - $wordsExclude[] = $fulltextWord; |
|
| 165 | + if ($isExcluded) { |
|
| 166 | + $wordsExclude[] = $fulltextWord; |
|
| 167 | + } |
|
| 164 | 168 | } |
| 165 | 169 | |
| 166 | 170 | /** |
@@ -176,44 +180,54 @@ discard block |
||
| 176 | 180 | $query_where = array(); |
| 177 | 181 | $query_params = $search_data['params']; |
| 178 | 182 | |
| 179 | - if( $smcFunc['db_title'] == "PostgreSQL") |
|
| 180 | - $modSettings['search_simple_fulltext'] = true; |
|
| 183 | + if( $smcFunc['db_title'] == "PostgreSQL") { |
|
| 184 | + $modSettings['search_simple_fulltext'] = true; |
|
| 185 | + } |
|
| 181 | 186 | |
| 182 | - if ($query_params['id_search']) |
|
| 183 | - $query_select['id_search'] = '{int:id_search}'; |
|
| 187 | + if ($query_params['id_search']) { |
|
| 188 | + $query_select['id_search'] = '{int:id_search}'; |
|
| 189 | + } |
|
| 184 | 190 | |
| 185 | 191 | $count = 0; |
| 186 | - if (empty($modSettings['search_simple_fulltext'])) |
|
| 187 | - foreach ($words['words'] as $regularWord) |
|
| 192 | + if (empty($modSettings['search_simple_fulltext'])) { |
|
| 193 | + foreach ($words['words'] as $regularWord) |
|
| 188 | 194 | { |
| 189 | 195 | $query_where[] = 'm.body' . (in_array($regularWord, $query_params['excluded_words']) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:complex_body_' . $count . '}'; |
| 196 | + } |
|
| 190 | 197 | $query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
| 191 | 198 | } |
| 192 | 199 | |
| 193 | - if ($query_params['user_query']) |
|
| 194 | - $query_where[] = '{raw:user_query}'; |
|
| 195 | - if ($query_params['board_query']) |
|
| 196 | - $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 200 | + if ($query_params['user_query']) { |
|
| 201 | + $query_where[] = '{raw:user_query}'; |
|
| 202 | + } |
|
| 203 | + if ($query_params['board_query']) { |
|
| 204 | + $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 205 | + } |
|
| 197 | 206 | |
| 198 | - if ($query_params['topic']) |
|
| 199 | - $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 200 | - if ($query_params['min_msg_id']) |
|
| 201 | - $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 202 | - if ($query_params['max_msg_id']) |
|
| 203 | - $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 207 | + if ($query_params['topic']) { |
|
| 208 | + $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 209 | + } |
|
| 210 | + if ($query_params['min_msg_id']) { |
|
| 211 | + $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 212 | + } |
|
| 213 | + if ($query_params['max_msg_id']) { |
|
| 214 | + $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 215 | + } |
|
| 204 | 216 | |
| 205 | 217 | $count = 0; |
| 206 | - if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) |
|
| 207 | - foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 218 | + if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) { |
|
| 219 | + foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 208 | 220 | { |
| 209 | 221 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_phrase_' . $count . '}'; |
| 222 | + } |
|
| 210 | 223 | $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), '\\\'') . '[[:>:]]'; |
| 211 | 224 | } |
| 212 | 225 | $count = 0; |
| 213 | - if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) |
|
| 214 | - foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 226 | + if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) { |
|
| 227 | + foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 215 | 228 | { |
| 216 | 229 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_words_' . $count . '}'; |
| 230 | + } |
|
| 217 | 231 | $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), '\\\'') . '[[:>:]]'; |
| 218 | 232 | } |
| 219 | 233 | |
@@ -225,12 +239,11 @@ discard block |
||
| 225 | 239 | |
| 226 | 240 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ plainto_tsquery({string:language_ftx},{string:body_match})'; |
| 227 | 241 | $query_params['language_ftx'] = $language_ftx; |
| 242 | + } else { |
|
| 243 | + $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
| 228 | 244 | } |
| 229 | - else |
|
| 230 | - $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
| 231 | 245 | $query_params['body_match'] = implode(' ', array_diff($words['indexed_words'], $query_params['excluded_index_words'])); |
| 232 | - } |
|
| 233 | - else |
|
| 246 | + } else |
|
| 234 | 247 | { |
| 235 | 248 | $query_params['boolean_match'] = ''; |
| 236 | 249 | |
@@ -246,10 +259,10 @@ discard block |
||
| 246 | 259 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' '; |
| 247 | 260 | $row++; |
| 248 | 261 | } |
| 249 | - } |
|
| 250 | - else |
|
| 251 | - foreach ($words['indexed_words'] as $fulltextWord) |
|
| 262 | + } else { |
|
| 263 | + foreach ($words['indexed_words'] as $fulltextWord) |
|
| 252 | 264 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' '; |
| 265 | + } |
|
| 253 | 266 | |
| 254 | 267 | $query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1); |
| 255 | 268 | |
@@ -262,9 +275,9 @@ discard block |
||
| 262 | 275 | |
| 263 | 276 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ plainto_tsquery({string:language_ftx},{string:boolean_match})'; |
| 264 | 277 | $query_params['language_ftx'] = $language_ftx; |
| 278 | + } else { |
|
| 279 | + $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
| 265 | 280 | } |
| 266 | - else |
|
| 267 | - $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
| 268 | 281 | } |
| 269 | 282 | } |
| 270 | 283 | |
@@ -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 | |
@@ -86,8 +88,9 @@ discard block |
||
| 86 | 88 | } |
| 87 | 89 | |
| 88 | 90 | // Maybe parent got support |
| 89 | - if (!$return) |
|
| 90 | - $return = parent::supportsMethod($methodName, $query_params); |
|
| 91 | + if (!$return) { |
|
| 92 | + $return = parent::supportsMethod($methodName, $query_params); |
|
| 93 | + } |
|
| 91 | 94 | |
| 92 | 95 | return $return; |
| 93 | 96 | } |
@@ -124,21 +127,23 @@ discard block |
||
| 124 | 127 | |
| 125 | 128 | $subwords = text2words($word, $this->min_word_length, true); |
| 126 | 129 | |
| 127 | - if (empty($modSettings['search_force_index'])) |
|
| 128 | - $wordsSearch['words'][] = $word; |
|
| 130 | + if (empty($modSettings['search_force_index'])) { |
|
| 131 | + $wordsSearch['words'][] = $word; |
|
| 132 | + } |
|
| 129 | 133 | |
| 130 | 134 | // Excluded phrases don't benefit from being split into subwords. |
| 131 | - if (count($subwords) > 1 && $isExcluded) |
|
| 132 | - return; |
|
| 133 | - else |
|
| 135 | + if (count($subwords) > 1 && $isExcluded) { |
|
| 136 | + return; |
|
| 137 | + } else |
|
| 134 | 138 | { |
| 135 | 139 | foreach ($subwords as $subword) |
| 136 | 140 | { |
| 137 | 141 | if ($smcFunc['strlen']($subword) >= $this->min_word_length && !in_array($subword, $this->bannedWords)) |
| 138 | 142 | { |
| 139 | 143 | $wordsSearch['indexed_words'][] = $subword; |
| 140 | - if ($isExcluded) |
|
| 141 | - $wordsExclude[] = $subword; |
|
| 144 | + if ($isExcluded) { |
|
| 145 | + $wordsExclude[] = $subword; |
|
| 146 | + } |
|
| 142 | 147 | } |
| 143 | 148 | } |
| 144 | 149 | } |
@@ -159,8 +164,9 @@ discard block |
||
| 159 | 164 | $query_where = array(); |
| 160 | 165 | $query_params = $search_data['params']; |
| 161 | 166 | |
| 162 | - if ($query_params['id_search']) |
|
| 163 | - $query_select['id_search'] = '{int:id_search}'; |
|
| 167 | + if ($query_params['id_search']) { |
|
| 168 | + $query_select['id_search'] = '{int:id_search}'; |
|
| 169 | + } |
|
| 164 | 170 | |
| 165 | 171 | $count = 0; |
| 166 | 172 | foreach ($words['words'] as $regularWord) |
@@ -169,30 +175,37 @@ discard block |
||
| 169 | 175 | $query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
| 170 | 176 | } |
| 171 | 177 | |
| 172 | - if ($query_params['user_query']) |
|
| 173 | - $query_where[] = '{raw:user_query}'; |
|
| 174 | - if ($query_params['board_query']) |
|
| 175 | - $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 178 | + if ($query_params['user_query']) { |
|
| 179 | + $query_where[] = '{raw:user_query}'; |
|
| 180 | + } |
|
| 181 | + if ($query_params['board_query']) { |
|
| 182 | + $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 183 | + } |
|
| 176 | 184 | |
| 177 | - if ($query_params['topic']) |
|
| 178 | - $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 179 | - if ($query_params['min_msg_id']) |
|
| 180 | - $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 181 | - if ($query_params['max_msg_id']) |
|
| 182 | - $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 185 | + if ($query_params['topic']) { |
|
| 186 | + $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 187 | + } |
|
| 188 | + if ($query_params['min_msg_id']) { |
|
| 189 | + $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 190 | + } |
|
| 191 | + if ($query_params['max_msg_id']) { |
|
| 192 | + $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 193 | + } |
|
| 183 | 194 | |
| 184 | 195 | $count = 0; |
| 185 | - if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) |
|
| 186 | - foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 196 | + if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) { |
|
| 197 | + foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 187 | 198 | { |
| 188 | 199 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_phrase_' . $count . '}'; |
| 200 | + } |
|
| 189 | 201 | $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), '\\\'') . '[[:>:]]'; |
| 190 | 202 | } |
| 191 | 203 | $count = 0; |
| 192 | - if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) |
|
| 193 | - foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 204 | + if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) { |
|
| 205 | + foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 194 | 206 | { |
| 195 | 207 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_words_' . $count . '}'; |
| 208 | + } |
|
| 196 | 209 | $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), '\\\'') . '[[:>:]]'; |
| 197 | 210 | } |
| 198 | 211 | |
@@ -205,8 +218,7 @@ discard block |
||
| 205 | 218 | { |
| 206 | 219 | $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)'; |
| 207 | 220 | $query_where[] = '(lsw' . $numTables . '.id_word IS NULL)'; |
| 208 | - } |
|
| 209 | - else |
|
| 221 | + } else |
|
| 210 | 222 | { |
| 211 | 223 | $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)'; |
| 212 | 224 | $query_where[] = 'lsw' . $numTables . '.id_word = ' . $indexedWord; |
@@ -242,16 +254,18 @@ discard block |
||
| 242 | 254 | $customIndexSettings = $smcFunc['json_decode']($modSettings['search_custom_index_config'], true); |
| 243 | 255 | |
| 244 | 256 | $inserts = array(); |
| 245 | - foreach (text2words($msgOptions['body'], $customIndexSettings['bytes_per_word'], true) as $word) |
|
| 246 | - $inserts[] = array($word, $msgOptions['id']); |
|
| 257 | + foreach (text2words($msgOptions['body'], $customIndexSettings['bytes_per_word'], true) as $word) { |
|
| 258 | + $inserts[] = array($word, $msgOptions['id']); |
|
| 259 | + } |
|
| 247 | 260 | |
| 248 | - if (!empty($inserts)) |
|
| 249 | - $smcFunc['db_insert']('ignore', |
|
| 261 | + if (!empty($inserts)) { |
|
| 262 | + $smcFunc['db_insert']('ignore', |
|
| 250 | 263 | '{db_prefix}log_search_words', |
| 251 | 264 | array('id_word' => 'int', 'id_msg' => 'int'), |
| 252 | 265 | $inserts, |
| 253 | 266 | array('id_word', 'id_msg') |
| 254 | 267 | ); |
| 268 | + } |
|
| 255 | 269 | } |
| 256 | 270 | |
| 257 | 271 | /** |
@@ -294,8 +308,9 @@ discard block |
||
| 294 | 308 | if (!empty($inserted_words)) |
| 295 | 309 | { |
| 296 | 310 | $inserts = array(); |
| 297 | - foreach ($inserted_words as $word) |
|
| 298 | - $inserts[] = array($word, $msgOptions['id']); |
|
| 311 | + foreach ($inserted_words as $word) { |
|
| 312 | + $inserts[] = array($word, $msgOptions['id']); |
|
| 313 | + } |
|
| 299 | 314 | $smcFunc['db_insert']('insert', |
| 300 | 315 | '{db_prefix}log_search_words', |
| 301 | 316 | array('id_word' => 'string', 'id_msg' => 'int'), |
@@ -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 | * Delete one of more membergroups. |
@@ -31,15 +32,16 @@ discard block |
||
| 31 | 32 | global $smcFunc, $modSettings, $txt; |
| 32 | 33 | |
| 33 | 34 | // Make sure it's an array. |
| 34 | - if (!is_array($groups)) |
|
| 35 | - $groups = array((int) $groups); |
|
| 36 | - else |
|
| 35 | + if (!is_array($groups)) { |
|
| 36 | + $groups = array((int) $groups); |
|
| 37 | + } else |
|
| 37 | 38 | { |
| 38 | 39 | $groups = array_unique($groups); |
| 39 | 40 | |
| 40 | 41 | // Make sure all groups are integer. |
| 41 | - foreach ($groups as $key => $value) |
|
| 42 | - $groups[$key] = (int) $value; |
|
| 42 | + foreach ($groups as $key => $value) { |
|
| 43 | + $groups[$key] = (int) $value; |
|
| 44 | + } |
|
| 43 | 45 | } |
| 44 | 46 | |
| 45 | 47 | // Some groups are protected (guests, administrators, moderators, newbies). |
@@ -56,15 +58,17 @@ discard block |
||
| 56 | 58 | 'is_protected' => 1, |
| 57 | 59 | ) |
| 58 | 60 | ); |
| 59 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 60 | - $protected_groups[] = $row['id_group']; |
|
| 61 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 62 | + $protected_groups[] = $row['id_group']; |
|
| 63 | + } |
|
| 61 | 64 | $smcFunc['db_free_result']($request); |
| 62 | 65 | } |
| 63 | 66 | |
| 64 | 67 | // Make sure they don't delete protected groups! |
| 65 | 68 | $groups = array_diff($groups, array_unique($protected_groups)); |
| 66 | - if (empty($groups)) |
|
| 67 | - return 'no_group_found'; |
|
| 69 | + if (empty($groups)) { |
|
| 70 | + return 'no_group_found'; |
|
| 71 | + } |
|
| 68 | 72 | |
| 69 | 73 | // Make sure they don't try to delete a group attached to a paid subscription. |
| 70 | 74 | $subscriptions = array(); |
@@ -74,13 +78,14 @@ discard block |
||
| 74 | 78 | ORDER BY name'); |
| 75 | 79 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 76 | 80 | { |
| 77 | - if (in_array($row['id_group'], $groups)) |
|
| 78 | - $subscriptions[] = $row['name']; |
|
| 79 | - else |
|
| 81 | + if (in_array($row['id_group'], $groups)) { |
|
| 82 | + $subscriptions[] = $row['name']; |
|
| 83 | + } else |
|
| 80 | 84 | { |
| 81 | 85 | $add_groups = explode(',', $row['add_groups']); |
| 82 | - if (count(array_intersect($add_groups, $groups)) != 0) |
|
| 83 | - $subscriptions[] = $row['name']; |
|
| 86 | + if (count(array_intersect($add_groups, $groups)) != 0) { |
|
| 87 | + $subscriptions[] = $row['name']; |
|
| 88 | + } |
|
| 84 | 89 | } |
| 85 | 90 | } |
| 86 | 91 | $smcFunc['db_free_result']($request); |
@@ -101,8 +106,9 @@ discard block |
||
| 101 | 106 | 'group_list' => $groups, |
| 102 | 107 | ) |
| 103 | 108 | ); |
| 104 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 105 | - logAction('delete_group', array('group' => $row['group_name']), 'admin'); |
|
| 109 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 110 | + logAction('delete_group', array('group' => $row['group_name']), 'admin'); |
|
| 111 | + } |
|
| 106 | 112 | $smcFunc['db_free_result']($request); |
| 107 | 113 | |
| 108 | 114 | call_integration_hook('integrate_delete_membergroups', array($groups)); |
@@ -187,12 +193,14 @@ discard block |
||
| 187 | 193 | ) |
| 188 | 194 | ); |
| 189 | 195 | $updates = array(); |
| 190 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 191 | - $updates[$row['additional_groups']][] = $row['id_member']; |
|
| 196 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 197 | + $updates[$row['additional_groups']][] = $row['id_member']; |
|
| 198 | + } |
|
| 192 | 199 | $smcFunc['db_free_result']($request); |
| 193 | 200 | |
| 194 | - foreach ($updates as $additional_groups => $memberArray) |
|
| 195 | - updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups)))); |
|
| 201 | + foreach ($updates as $additional_groups => $memberArray) { |
|
| 202 | + updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups)))); |
|
| 203 | + } |
|
| 196 | 204 | |
| 197 | 205 | // No boards can provide access to these membergroups anymore. |
| 198 | 206 | $request = $smcFunc['db_query']('', ' |
@@ -204,12 +212,13 @@ discard block |
||
| 204 | 212 | ) |
| 205 | 213 | ); |
| 206 | 214 | $updates = array(); |
| 207 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 208 | - $updates[$row['member_groups']][] = $row['id_board']; |
|
| 215 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 216 | + $updates[$row['member_groups']][] = $row['id_board']; |
|
| 217 | + } |
|
| 209 | 218 | $smcFunc['db_free_result']($request); |
| 210 | 219 | |
| 211 | - foreach ($updates as $member_groups => $boardArray) |
|
| 212 | - $smcFunc['db_query']('', ' |
|
| 220 | + foreach ($updates as $member_groups => $boardArray) { |
|
| 221 | + $smcFunc['db_query']('', ' |
|
| 213 | 222 | UPDATE {db_prefix}boards |
| 214 | 223 | SET member_groups = {string:member_groups} |
| 215 | 224 | WHERE id_board IN ({array_int:board_lists})', |
@@ -218,6 +227,7 @@ discard block |
||
| 218 | 227 | 'member_groups' => implode(',', array_diff(explode(',', $member_groups), $groups)), |
| 219 | 228 | ) |
| 220 | 229 | ); |
| 230 | + } |
|
| 221 | 231 | |
| 222 | 232 | // Recalculate the post groups, as they likely changed. |
| 223 | 233 | updateStats('postgroups'); |
@@ -225,8 +235,9 @@ discard block |
||
| 225 | 235 | // Make a note of the fact that the cache may be wrong. |
| 226 | 236 | $settings_update = array('settings_updated' => time()); |
| 227 | 237 | // Have we deleted the spider group? |
| 228 | - if (isset($modSettings['spider_group']) && in_array($modSettings['spider_group'], $groups)) |
|
| 229 | - $settings_update['spider_group'] = 0; |
|
| 238 | + if (isset($modSettings['spider_group']) && in_array($modSettings['spider_group'], $groups)) { |
|
| 239 | + $settings_update['spider_group'] = 0; |
|
| 240 | + } |
|
| 230 | 241 | |
| 231 | 242 | updateSettings($settings_update); |
| 232 | 243 | |
@@ -250,22 +261,24 @@ discard block |
||
| 250 | 261 | global $smcFunc, $modSettings, $sourcedir; |
| 251 | 262 | |
| 252 | 263 | // You're getting nowhere without this permission, unless of course you are the group's moderator. |
| 253 | - if (!$permissionCheckDone) |
|
| 254 | - isAllowedTo('manage_membergroups'); |
|
| 264 | + if (!$permissionCheckDone) { |
|
| 265 | + isAllowedTo('manage_membergroups'); |
|
| 266 | + } |
|
| 255 | 267 | |
| 256 | 268 | // Assume something will happen. |
| 257 | 269 | updateSettings(array('settings_updated' => time())); |
| 258 | 270 | |
| 259 | 271 | // Cleaning the input. |
| 260 | - if (!is_array($members)) |
|
| 261 | - $members = array((int) $members); |
|
| 262 | - else |
|
| 272 | + if (!is_array($members)) { |
|
| 273 | + $members = array((int) $members); |
|
| 274 | + } else |
|
| 263 | 275 | { |
| 264 | 276 | $members = array_unique($members); |
| 265 | 277 | |
| 266 | 278 | // Cast the members to integer. |
| 267 | - foreach ($members as $key => $value) |
|
| 268 | - $members[$key] = (int) $value; |
|
| 279 | + foreach ($members as $key => $value) { |
|
| 280 | + $members[$key] = (int) $value; |
|
| 281 | + } |
|
| 269 | 282 | } |
| 270 | 283 | |
| 271 | 284 | // Before we get started, let's check we won't leave the admin group empty! |
@@ -277,14 +290,15 @@ discard block |
||
| 277 | 290 | // Remove any admins if there are too many. |
| 278 | 291 | $non_changing_admins = array_diff(array_keys($admins), $members); |
| 279 | 292 | |
| 280 | - if (empty($non_changing_admins)) |
|
| 281 | - $members = array_diff($members, array_keys($admins)); |
|
| 293 | + if (empty($non_changing_admins)) { |
|
| 294 | + $members = array_diff($members, array_keys($admins)); |
|
| 295 | + } |
|
| 282 | 296 | } |
| 283 | 297 | |
| 284 | 298 | // Just in case. |
| 285 | - if (empty($members)) |
|
| 286 | - return false; |
|
| 287 | - elseif ($groups === null) |
|
| 299 | + if (empty($members)) { |
|
| 300 | + return false; |
|
| 301 | + } elseif ($groups === null) |
|
| 288 | 302 | { |
| 289 | 303 | // Wanna remove all groups from these members? That's easy. |
| 290 | 304 | $smcFunc['db_query']('', ' |
@@ -306,20 +320,21 @@ discard block |
||
| 306 | 320 | updateStats('postgroups', $members); |
| 307 | 321 | |
| 308 | 322 | // Log what just happened. |
| 309 | - foreach ($members as $member) |
|
| 310 | - logAction('removed_all_groups', array('member' => $member), 'admin'); |
|
| 323 | + foreach ($members as $member) { |
|
| 324 | + logAction('removed_all_groups', array('member' => $member), 'admin'); |
|
| 325 | + } |
|
| 311 | 326 | |
| 312 | 327 | return true; |
| 313 | - } |
|
| 314 | - elseif (!is_array($groups)) |
|
| 315 | - $groups = array((int) $groups); |
|
| 316 | - else |
|
| 328 | + } elseif (!is_array($groups)) { |
|
| 329 | + $groups = array((int) $groups); |
|
| 330 | + } else |
|
| 317 | 331 | { |
| 318 | 332 | $groups = array_unique($groups); |
| 319 | 333 | |
| 320 | 334 | // Make sure all groups are integer. |
| 321 | - foreach ($groups as $key => $value) |
|
| 322 | - $groups[$key] = (int) $value; |
|
| 335 | + foreach ($groups as $key => $value) { |
|
| 336 | + $groups[$key] = (int) $value; |
|
| 337 | + } |
|
| 323 | 338 | } |
| 324 | 339 | |
| 325 | 340 | // Fetch a list of groups members cannot be assigned to explicitly, and the group names of the ones we want. |
@@ -335,10 +350,11 @@ discard block |
||
| 335 | 350 | $group_names = array(); |
| 336 | 351 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 337 | 352 | { |
| 338 | - if ($row['min_posts'] != -1) |
|
| 339 | - $implicitGroups[] = $row['id_group']; |
|
| 340 | - else |
|
| 341 | - $group_names[$row['id_group']] = $row['group_name']; |
|
| 353 | + if ($row['min_posts'] != -1) { |
|
| 354 | + $implicitGroups[] = $row['id_group']; |
|
| 355 | + } else { |
|
| 356 | + $group_names[$row['id_group']] = $row['group_name']; |
|
| 357 | + } |
|
| 342 | 358 | } |
| 343 | 359 | $smcFunc['db_free_result']($request); |
| 344 | 360 | |
@@ -357,8 +373,9 @@ discard block |
||
| 357 | 373 | ) |
| 358 | 374 | ); |
| 359 | 375 | $protected_groups = array(1); |
| 360 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 361 | - $protected_groups[] = $row['id_group']; |
|
| 376 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 377 | + $protected_groups[] = $row['id_group']; |
|
| 378 | + } |
|
| 362 | 379 | $smcFunc['db_free_result']($request); |
| 363 | 380 | |
| 364 | 381 | // If you're not an admin yourself, you can't touch protected groups! |
@@ -366,8 +383,9 @@ discard block |
||
| 366 | 383 | } |
| 367 | 384 | |
| 368 | 385 | // Only continue if there are still groups and members left. |
| 369 | - if (empty($groups) || empty($members)) |
|
| 370 | - return false; |
|
| 386 | + if (empty($groups) || empty($members)) { |
|
| 387 | + return false; |
|
| 388 | + } |
|
| 371 | 389 | |
| 372 | 390 | // First, reset those who have this as their primary group - this is the easy one. |
| 373 | 391 | $log_inserts = array(); |
@@ -381,8 +399,9 @@ discard block |
||
| 381 | 399 | 'member_list' => $members, |
| 382 | 400 | ) |
| 383 | 401 | ); |
| 384 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 385 | - $log_inserts[] = array('group' => $group_names[$row['id_group']], 'member' => $row['id_member']); |
|
| 402 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 403 | + $log_inserts[] = array('group' => $group_names[$row['id_group']], 'member' => $row['id_member']); |
|
| 404 | + } |
|
| 386 | 405 | $smcFunc['db_free_result']($request); |
| 387 | 406 | |
| 388 | 407 | $smcFunc['db_query']('', ' |
@@ -414,16 +433,17 @@ discard block |
||
| 414 | 433 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 415 | 434 | { |
| 416 | 435 | // What log entries must we make for this one, eh? |
| 417 | - foreach (explode(',', $row['additional_groups']) as $group) |
|
| 418 | - if (in_array($group, $groups)) |
|
| 436 | + foreach (explode(',', $row['additional_groups']) as $group) { |
|
| 437 | + if (in_array($group, $groups)) |
|
| 419 | 438 | $log_inserts[] = array('group' => $group_names[$group], 'member' => $row['id_member']); |
| 439 | + } |
|
| 420 | 440 | |
| 421 | 441 | $updates[$row['additional_groups']][] = $row['id_member']; |
| 422 | 442 | } |
| 423 | 443 | $smcFunc['db_free_result']($request); |
| 424 | 444 | |
| 425 | - foreach ($updates as $additional_groups => $memberArray) |
|
| 426 | - $smcFunc['db_query']('', ' |
|
| 445 | + foreach ($updates as $additional_groups => $memberArray) { |
|
| 446 | + $smcFunc['db_query']('', ' |
|
| 427 | 447 | UPDATE {db_prefix}members |
| 428 | 448 | SET additional_groups = {string:additional_groups} |
| 429 | 449 | WHERE id_member IN ({array_int:member_list})', |
@@ -432,6 +452,7 @@ discard block |
||
| 432 | 452 | 'additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups)), |
| 433 | 453 | ) |
| 434 | 454 | ); |
| 455 | + } |
|
| 435 | 456 | |
| 436 | 457 | // Their post groups may have changed now... |
| 437 | 458 | updateStats('postgroups', $members); |
@@ -440,8 +461,9 @@ discard block |
||
| 440 | 461 | if (!empty($log_inserts) && !empty($modSettings['modlog_enabled'])) |
| 441 | 462 | { |
| 442 | 463 | require_once($sourcedir . '/Logging.php'); |
| 443 | - foreach ($log_inserts as $extra) |
|
| 444 | - logAction('removed_from_group', $extra, 'admin'); |
|
| 464 | + foreach ($log_inserts as $extra) { |
|
| 465 | + logAction('removed_from_group', $extra, 'admin'); |
|
| 466 | + } |
|
| 445 | 467 | } |
| 446 | 468 | |
| 447 | 469 | // Mission successful. |
@@ -477,21 +499,23 @@ discard block |
||
| 477 | 499 | global $smcFunc, $sourcedir; |
| 478 | 500 | |
| 479 | 501 | // Show your licence, but only if it hasn't been done yet. |
| 480 | - if (!$permissionCheckDone) |
|
| 481 | - isAllowedTo('manage_membergroups'); |
|
| 502 | + if (!$permissionCheckDone) { |
|
| 503 | + isAllowedTo('manage_membergroups'); |
|
| 504 | + } |
|
| 482 | 505 | |
| 483 | 506 | // Make sure we don't keep old stuff cached. |
| 484 | 507 | updateSettings(array('settings_updated' => time())); |
| 485 | 508 | |
| 486 | - if (!is_array($members)) |
|
| 487 | - $members = array((int) $members); |
|
| 488 | - else |
|
| 509 | + if (!is_array($members)) { |
|
| 510 | + $members = array((int) $members); |
|
| 511 | + } else |
|
| 489 | 512 | { |
| 490 | 513 | $members = array_unique($members); |
| 491 | 514 | |
| 492 | 515 | // Make sure all members are integer. |
| 493 | - foreach ($members as $key => $value) |
|
| 494 | - $members[$key] = (int) $value; |
|
| 516 | + foreach ($members as $key => $value) { |
|
| 517 | + $members[$key] = (int) $value; |
|
| 518 | + } |
|
| 495 | 519 | } |
| 496 | 520 | $group = (int) $group; |
| 497 | 521 | |
@@ -508,20 +532,23 @@ discard block |
||
| 508 | 532 | $group_names = array(); |
| 509 | 533 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 510 | 534 | { |
| 511 | - if ($row['min_posts'] != -1) |
|
| 512 | - $implicitGroups[] = $row['id_group']; |
|
| 513 | - else |
|
| 514 | - $group_names[$row['id_group']] = $row['group_name']; |
|
| 535 | + if ($row['min_posts'] != -1) { |
|
| 536 | + $implicitGroups[] = $row['id_group']; |
|
| 537 | + } else { |
|
| 538 | + $group_names[$row['id_group']] = $row['group_name']; |
|
| 539 | + } |
|
| 515 | 540 | } |
| 516 | 541 | $smcFunc['db_free_result']($request); |
| 517 | 542 | |
| 518 | 543 | // Sorry, you can't join an implicit group. |
| 519 | - if (in_array($group, $implicitGroups) || empty($members)) |
|
| 520 | - return false; |
|
| 544 | + if (in_array($group, $implicitGroups) || empty($members)) { |
|
| 545 | + return false; |
|
| 546 | + } |
|
| 521 | 547 | |
| 522 | 548 | // Only admins can add admins... |
| 523 | - if (!allowedTo('admin_forum') && $group == 1) |
|
| 524 | - return false; |
|
| 549 | + if (!allowedTo('admin_forum') && $group == 1) { |
|
| 550 | + return false; |
|
| 551 | + } |
|
| 525 | 552 | // ... and assign protected groups! |
| 526 | 553 | elseif (!allowedTo('admin_forum') && !$ignoreProtected) |
| 527 | 554 | { |
@@ -539,13 +566,14 @@ discard block |
||
| 539 | 566 | $smcFunc['db_free_result']($request); |
| 540 | 567 | |
| 541 | 568 | // Is it protected? |
| 542 | - if ($is_protected == 1) |
|
| 543 | - return false; |
|
| 569 | + if ($is_protected == 1) { |
|
| 570 | + return false; |
|
| 571 | + } |
|
| 544 | 572 | } |
| 545 | 573 | |
| 546 | 574 | // Do the actual updates. |
| 547 | - if ($type == 'only_additional') |
|
| 548 | - $smcFunc['db_query']('', ' |
|
| 575 | + if ($type == 'only_additional') { |
|
| 576 | + $smcFunc['db_query']('', ' |
|
| 549 | 577 | UPDATE {db_prefix}members |
| 550 | 578 | SET additional_groups = CASE WHEN additional_groups = {string:blank_string} THEN {string:id_group_string} ELSE CONCAT(additional_groups, {string:id_group_string_extend}) END |
| 551 | 579 | WHERE id_member IN ({array_int:member_list}) |
@@ -559,8 +587,8 @@ discard block |
||
| 559 | 587 | 'blank_string' => '', |
| 560 | 588 | ) |
| 561 | 589 | ); |
| 562 | - elseif ($type == 'only_primary' || $type == 'force_primary') |
|
| 563 | - $smcFunc['db_query']('', ' |
|
| 590 | + } elseif ($type == 'only_primary' || $type == 'force_primary') { |
|
| 591 | + $smcFunc['db_query']('', ' |
|
| 564 | 592 | UPDATE {db_prefix}members |
| 565 | 593 | SET id_group = {int:id_group} |
| 566 | 594 | WHERE id_member IN ({array_int:member_list})' . ($type == 'force_primary' ? '' : ' |
@@ -572,8 +600,8 @@ discard block |
||
| 572 | 600 | 'regular_group' => 0, |
| 573 | 601 | ) |
| 574 | 602 | ); |
| 575 | - elseif ($type == 'auto') |
|
| 576 | - $smcFunc['db_query']('', ' |
|
| 603 | + } elseif ($type == 'auto') { |
|
| 604 | + $smcFunc['db_query']('', ' |
|
| 577 | 605 | UPDATE {db_prefix}members |
| 578 | 606 | SET |
| 579 | 607 | id_group = CASE WHEN id_group = {int:regular_group} THEN {int:id_group} ELSE id_group END, |
@@ -592,9 +620,11 @@ discard block |
||
| 592 | 620 | 'id_group_string_extend' => ',' . $group, |
| 593 | 621 | ) |
| 594 | 622 | ); |
| 623 | + } |
|
| 595 | 624 | // Ack!!? What happened? |
| 596 | - else |
|
| 597 | - trigger_error('addMembersToGroup(): Unknown type \'' . $type . '\'', E_USER_WARNING); |
|
| 625 | + else { |
|
| 626 | + trigger_error('addMembersToGroup(): Unknown type \'' . $type . '\'', E_USER_WARNING); |
|
| 627 | + } |
|
| 598 | 628 | |
| 599 | 629 | call_integration_hook('integrate_add_members_to_group', array($members, $group, &$group_names)); |
| 600 | 630 | |
@@ -603,8 +633,9 @@ discard block |
||
| 603 | 633 | |
| 604 | 634 | // Log the data. |
| 605 | 635 | require_once($sourcedir . '/Logging.php'); |
| 606 | - foreach ($members as $member) |
|
| 607 | - logAction('added_to_group', array('group' => $group_names[$group], 'member_affected' => $member), 'admin'); |
|
| 636 | + foreach ($members as $member) { |
|
| 637 | + logAction('added_to_group', array('group' => $group_names[$group], 'member_affected' => $member), 'admin'); |
|
| 638 | + } |
|
| 608 | 639 | |
| 609 | 640 | return true; |
| 610 | 641 | } |
@@ -632,8 +663,9 @@ discard block |
||
| 632 | 663 | ) |
| 633 | 664 | ); |
| 634 | 665 | $members = array(); |
| 635 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 636 | - $members[$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 666 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 667 | + $members[$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 668 | + } |
|
| 637 | 669 | $smcFunc['db_free_result']($request); |
| 638 | 670 | |
| 639 | 671 | // If there are more than $limit members, add a 'more' link. |
@@ -641,10 +673,10 @@ discard block |
||
| 641 | 673 | { |
| 642 | 674 | array_pop($members); |
| 643 | 675 | return true; |
| 676 | + } else { |
|
| 677 | + return false; |
|
| 678 | + } |
|
| 644 | 679 | } |
| 645 | - else |
|
| 646 | - return false; |
|
| 647 | -} |
|
| 648 | 680 | |
| 649 | 681 | /** |
| 650 | 682 | * Retrieve a list of (visible) membergroups used by the cache. |
@@ -669,8 +701,9 @@ discard block |
||
| 669 | 701 | ) |
| 670 | 702 | ); |
| 671 | 703 | $groupCache = array(); |
| 672 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 673 | - $groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>'; |
|
| 704 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 705 | + $groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>'; |
|
| 706 | + } |
|
| 674 | 707 | $smcFunc['db_free_result']($request); |
| 675 | 708 | |
| 676 | 709 | return array( |
@@ -716,8 +749,9 @@ discard block |
||
| 716 | 749 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 717 | 750 | { |
| 718 | 751 | // We only list the groups they can see. |
| 719 | - if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) |
|
| 720 | - continue; |
|
| 752 | + if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) { |
|
| 753 | + continue; |
|
| 754 | + } |
|
| 721 | 755 | |
| 722 | 756 | $row['icons'] = explode('#', $row['icons']); |
| 723 | 757 | |
@@ -752,12 +786,11 @@ discard block |
||
| 752 | 786 | 'group_list' => $group_ids, |
| 753 | 787 | ) |
| 754 | 788 | ); |
| 755 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
| 756 | - $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
| 789 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
| 790 | + $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
| 791 | + } |
|
| 757 | 792 | $smcFunc['db_free_result']($query); |
| 758 | - } |
|
| 759 | - |
|
| 760 | - else |
|
| 793 | + } else |
|
| 761 | 794 | { |
| 762 | 795 | $query = $smcFunc['db_query']('', ' |
| 763 | 796 | SELECT id_group, COUNT(*) AS num_members |
@@ -768,8 +801,9 @@ discard block |
||
| 768 | 801 | 'group_list' => $group_ids, |
| 769 | 802 | ) |
| 770 | 803 | ); |
| 771 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
| 772 | - $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
| 804 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
| 805 | + $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
| 806 | + } |
|
| 773 | 807 | $smcFunc['db_free_result']($query); |
| 774 | 808 | |
| 775 | 809 | // Only do additional groups if we can moderate... |
@@ -788,8 +822,9 @@ discard block |
||
| 788 | 822 | 'blank_string' => '', |
| 789 | 823 | ) |
| 790 | 824 | ); |
| 791 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
| 792 | - $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
| 825 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
| 826 | + $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
| 827 | + } |
|
| 793 | 828 | $smcFunc['db_free_result']($query); |
| 794 | 829 | } |
| 795 | 830 | } |
@@ -803,8 +838,9 @@ discard block |
||
| 803 | 838 | 'group_list' => $group_ids, |
| 804 | 839 | ) |
| 805 | 840 | ); |
| 806 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
| 807 | - $groups[$row['id_group']]['moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 841 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
| 842 | + $groups[$row['id_group']]['moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 843 | + } |
|
| 808 | 844 | $smcFunc['db_free_result']($query); |
| 809 | 845 | } |
| 810 | 846 | |
@@ -813,8 +849,9 @@ discard block |
||
| 813 | 849 | { |
| 814 | 850 | $sort_ascending = strpos($sort, 'DESC') === false; |
| 815 | 851 | |
| 816 | - foreach ($groups as $group) |
|
| 817 | - $sort_array[] = $group['id_group'] != 3 ? (int) $group['num_members'] : -1; |
|
| 852 | + foreach ($groups as $group) { |
|
| 853 | + $sort_array[] = $group['id_group'] != 3 ? (int) $group['num_members'] : -1; |
|
| 854 | + } |
|
| 818 | 855 | |
| 819 | 856 | array_multisort($sort_array, $sort_ascending ? SORT_ASC : SORT_DESC, SORT_REGULAR, $groups); |
| 820 | 857 | } |
@@ -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 | * Truncate the GET array to a specified length |
@@ -26,24 +27,28 @@ discard block |
||
| 26 | 27 | function truncateArray($arr, $max_length=1900) |
| 27 | 28 | { |
| 28 | 29 | $curr_length = 0; |
| 29 | - foreach ($arr as $key => $value) |
|
| 30 | - if (is_array($value)) |
|
| 30 | + foreach ($arr as $key => $value) { |
|
| 31 | + if (is_array($value)) |
|
| 31 | 32 | foreach ($value as $key2 => $value2) |
| 32 | 33 | $curr_length += strlen ($value2); |
| 33 | - else |
|
| 34 | - $curr_length += strlen ($value); |
|
| 35 | - if ($curr_length <= $max_length) |
|
| 36 | - return $arr; |
|
| 37 | - else |
|
| 34 | + } |
|
| 35 | + else { |
|
| 36 | + $curr_length += strlen ($value); |
|
| 37 | + } |
|
| 38 | + if ($curr_length <= $max_length) { |
|
| 39 | + return $arr; |
|
| 40 | + } else |
|
| 38 | 41 | { |
| 39 | 42 | // Truncate each element's value to a reasonable length |
| 40 | 43 | $param_max = floor($max_length/count($arr)); |
| 41 | - foreach ($arr as $key => &$value) |
|
| 42 | - if (is_array($value)) |
|
| 44 | + foreach ($arr as $key => &$value) { |
|
| 45 | + if (is_array($value)) |
|
| 43 | 46 | foreach ($value as $key2 => &$value2) |
| 44 | 47 | $value2 = substr($value2, 0, $param_max - strlen($key) - 5); |
| 45 | - else |
|
| 46 | - $value = substr($value, 0, $param_max - strlen($key) - 5); |
|
| 48 | + } |
|
| 49 | + else { |
|
| 50 | + $value = substr($value, 0, $param_max - strlen($key) - 5); |
|
| 51 | + } |
|
| 47 | 52 | return $arr; |
| 48 | 53 | } |
| 49 | 54 | } |
@@ -65,8 +70,9 @@ discard block |
||
| 65 | 70 | // Don't update for every page - this isn't wholly accurate but who cares. |
| 66 | 71 | if ($topic) |
| 67 | 72 | { |
| 68 | - if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) |
|
| 69 | - $force = false; |
|
| 73 | + if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) { |
|
| 74 | + $force = false; |
|
| 75 | + } |
|
| 70 | 76 | $_SESSION['last_topic_id'] = $topic; |
| 71 | 77 | } |
| 72 | 78 | } |
@@ -79,22 +85,24 @@ discard block |
||
| 79 | 85 | } |
| 80 | 86 | |
| 81 | 87 | // Don't mark them as online more than every so often. |
| 82 | - if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) |
|
| 83 | - return; |
|
| 88 | + if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) { |
|
| 89 | + return; |
|
| 90 | + } |
|
| 84 | 91 | |
| 85 | 92 | if (!empty($modSettings['who_enabled'])) |
| 86 | 93 | { |
| 87 | 94 | $encoded_get = truncateArray($_GET) + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']); |
| 88 | 95 | |
| 89 | 96 | // In the case of a dlattach action, session_var may not be set. |
| 90 | - if (!isset($context['session_var'])) |
|
| 91 | - $context['session_var'] = $_SESSION['session_var']; |
|
| 97 | + if (!isset($context['session_var'])) { |
|
| 98 | + $context['session_var'] = $_SESSION['session_var']; |
|
| 99 | + } |
|
| 92 | 100 | |
| 93 | 101 | unset($encoded_get['sesc'], $encoded_get[$context['session_var']]); |
| 94 | 102 | $encoded_get = $smcFunc['json_encode']($encoded_get); |
| 103 | + } else { |
|
| 104 | + $encoded_get = ''; |
|
| 95 | 105 | } |
| 96 | - else |
|
| 97 | - $encoded_get = ''; |
|
| 98 | 106 | |
| 99 | 107 | // Guests use 0, members use their session ID. |
| 100 | 108 | $session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id(); |
@@ -134,17 +142,18 @@ discard block |
||
| 134 | 142 | ); |
| 135 | 143 | |
| 136 | 144 | // Guess it got deleted. |
| 137 | - if ($smcFunc['db_affected_rows']() == 0) |
|
| 145 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
| 146 | + $_SESSION['log_time'] = 0; |
|
| 147 | + } |
|
| 148 | + } else { |
|
| 138 | 149 | $_SESSION['log_time'] = 0; |
| 139 | 150 | } |
| 140 | - else |
|
| 141 | - $_SESSION['log_time'] = 0; |
|
| 142 | 151 | |
| 143 | 152 | // Otherwise, we have to delete and insert. |
| 144 | 153 | if (empty($_SESSION['log_time'])) |
| 145 | 154 | { |
| 146 | - if ($do_delete || !empty($user_info['id'])) |
|
| 147 | - $smcFunc['db_query']('', ' |
|
| 155 | + if ($do_delete || !empty($user_info['id'])) { |
|
| 156 | + $smcFunc['db_query']('', ' |
|
| 148 | 157 | DELETE FROM {db_prefix}log_online |
| 149 | 158 | WHERE ' . ($do_delete ? 'log_time < {int:log_time}' : '') . ($do_delete && !empty($user_info['id']) ? ' OR ' : '') . (empty($user_info['id']) ? '' : 'id_member = {int:current_member}'), |
| 150 | 159 | array( |
@@ -152,6 +161,7 @@ discard block |
||
| 152 | 161 | 'log_time' => time() - $modSettings['lastActive'] * 60, |
| 153 | 162 | ) |
| 154 | 163 | ); |
| 164 | + } |
|
| 155 | 165 | |
| 156 | 166 | $smcFunc['db_insert']($do_delete ? 'ignore' : 'replace', |
| 157 | 167 | '{db_prefix}log_online', |
@@ -165,21 +175,24 @@ discard block |
||
| 165 | 175 | $_SESSION['log_time'] = time(); |
| 166 | 176 | |
| 167 | 177 | // Well, they are online now. |
| 168 | - if (empty($_SESSION['timeOnlineUpdated'])) |
|
| 169 | - $_SESSION['timeOnlineUpdated'] = time(); |
|
| 178 | + if (empty($_SESSION['timeOnlineUpdated'])) { |
|
| 179 | + $_SESSION['timeOnlineUpdated'] = time(); |
|
| 180 | + } |
|
| 170 | 181 | |
| 171 | 182 | // Set their login time, if not already done within the last minute. |
| 172 | 183 | if (SMF != 'SSI' && !empty($user_info['last_login']) && $user_info['last_login'] < time() - 60 && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('.xml', 'login2', 'logintfa')))) |
| 173 | 184 | { |
| 174 | 185 | // Don't count longer than 15 minutes. |
| 175 | - if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) |
|
| 176 | - $_SESSION['timeOnlineUpdated'] = time(); |
|
| 186 | + if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) { |
|
| 187 | + $_SESSION['timeOnlineUpdated'] = time(); |
|
| 188 | + } |
|
| 177 | 189 | |
| 178 | 190 | $user_settings['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated']; |
| 179 | 191 | updateMemberData($user_info['id'], array('last_login' => time(), 'member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'], 'total_time_logged_in' => $user_settings['total_time_logged_in'])); |
| 180 | 192 | |
| 181 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 182 | - cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60); |
|
| 193 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 194 | + cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60); |
|
| 195 | + } |
|
| 183 | 196 | |
| 184 | 197 | $user_info['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated']; |
| 185 | 198 | $_SESSION['timeOnlineUpdated'] = time(); |
@@ -216,8 +229,7 @@ discard block |
||
| 216 | 229 | // Oops. maybe we have no more disk space left, or some other troubles, troubles... |
| 217 | 230 | // Copy the file back and run for your life! |
| 218 | 231 | @copy($cachedir . '/db_last_error_bak.php', $cachedir . '/db_last_error.php'); |
| 219 | - } |
|
| 220 | - else |
|
| 232 | + } else |
|
| 221 | 233 | { |
| 222 | 234 | @touch($boarddir . '/' . 'Settings.php'); |
| 223 | 235 | return true; |
@@ -237,22 +249,27 @@ discard block |
||
| 237 | 249 | global $db_cache, $db_count, $cache_misses, $cache_count_misses, $db_show_debug, $cache_count, $cache_hits, $smcFunc, $txt; |
| 238 | 250 | |
| 239 | 251 | // Add to Settings.php if you want to show the debugging information. |
| 240 | - if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) |
|
| 241 | - return; |
|
| 252 | + if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) { |
|
| 253 | + return; |
|
| 254 | + } |
|
| 242 | 255 | |
| 243 | - if (empty($_SESSION['view_queries'])) |
|
| 244 | - $_SESSION['view_queries'] = 0; |
|
| 245 | - if (empty($context['debug']['language_files'])) |
|
| 246 | - $context['debug']['language_files'] = array(); |
|
| 247 | - if (empty($context['debug']['sheets'])) |
|
| 248 | - $context['debug']['sheets'] = array(); |
|
| 256 | + if (empty($_SESSION['view_queries'])) { |
|
| 257 | + $_SESSION['view_queries'] = 0; |
|
| 258 | + } |
|
| 259 | + if (empty($context['debug']['language_files'])) { |
|
| 260 | + $context['debug']['language_files'] = array(); |
|
| 261 | + } |
|
| 262 | + if (empty($context['debug']['sheets'])) { |
|
| 263 | + $context['debug']['sheets'] = array(); |
|
| 264 | + } |
|
| 249 | 265 | |
| 250 | 266 | $files = get_included_files(); |
| 251 | 267 | $total_size = 0; |
| 252 | 268 | for ($i = 0, $n = count($files); $i < $n; $i++) |
| 253 | 269 | { |
| 254 | - if (file_exists($files[$i])) |
|
| 255 | - $total_size += filesize($files[$i]); |
|
| 270 | + if (file_exists($files[$i])) { |
|
| 271 | + $total_size += filesize($files[$i]); |
|
| 272 | + } |
|
| 256 | 273 | $files[$i] = strtr($files[$i], array($boarddir => '.', $sourcedir => '(Sources)', $cachedir => '(Cache)', $settings['actual_theme_dir'] => '(Current Theme)')); |
| 257 | 274 | } |
| 258 | 275 | |
@@ -261,8 +278,9 @@ discard block |
||
| 261 | 278 | { |
| 262 | 279 | foreach ($db_cache as $q => $query_data) |
| 263 | 280 | { |
| 264 | - if (!empty($query_data['w'])) |
|
| 265 | - $warnings += count($query_data['w']); |
|
| 281 | + if (!empty($query_data['w'])) { |
|
| 282 | + $warnings += count($query_data['w']); |
|
| 283 | + } |
|
| 266 | 284 | } |
| 267 | 285 | |
| 268 | 286 | $_SESSION['debug'] = &$db_cache; |
@@ -283,12 +301,14 @@ discard block |
||
| 283 | 301 | ',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">'. $txt['debug_show'] .'</a><span id="debug_instances" style="display: none;"><em>'. implode('</em>, <em>', array_keys($context['debug']['instances'])) .'</em></span>)'. '<br>') : ''),' |
| 284 | 302 | ', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br>'; |
| 285 | 303 | |
| 286 | - if (function_exists('memory_get_peak_usage')) |
|
| 287 | - echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>'; |
|
| 304 | + if (function_exists('memory_get_peak_usage')) { |
|
| 305 | + echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>'; |
|
| 306 | + } |
|
| 288 | 307 | |
| 289 | 308 | // What tokens are active? |
| 290 | - if (isset($_SESSION['token'])) |
|
| 291 | - echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>'; |
|
| 309 | + if (isset($_SESSION['token'])) { |
|
| 310 | + echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>'; |
|
| 311 | + } |
|
| 292 | 312 | |
| 293 | 313 | if (!empty($modSettings['cache_enable']) && !empty($cache_hits)) |
| 294 | 314 | { |
@@ -302,10 +322,12 @@ discard block |
||
| 302 | 322 | $total_t += $cache_hit['t']; |
| 303 | 323 | $total_s += $cache_hit['s']; |
| 304 | 324 | } |
| 305 | - if (!isset($cache_misses)) |
|
| 306 | - $cache_misses = array(); |
|
| 307 | - foreach ($cache_misses as $missed) |
|
| 308 | - $missed_entries[] = $missed['d'] . ' ' . $missed['k']; |
|
| 325 | + if (!isset($cache_misses)) { |
|
| 326 | + $cache_misses = array(); |
|
| 327 | + } |
|
| 328 | + foreach ($cache_misses as $missed) { |
|
| 329 | + $missed_entries[] = $missed['d'] . ' ' . $missed['k']; |
|
| 330 | + } |
|
| 309 | 331 | |
| 310 | 332 | echo ' |
| 311 | 333 | ', $txt['debug_cache_hits'], $cache_count, ': ', sprintf($txt['debug_cache_seconds_bytes_total'], comma_format($total_t, 5), comma_format($total_s)), ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_cache_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_cache_info" style="display: none;"><em>', implode('</em>, <em>', $entries), '</em></span>)<br> |
@@ -316,38 +338,44 @@ discard block |
||
| 316 | 338 | <a href="', $scripturl, '?action=viewquery" target="_blank" rel="noopener">', $warnings == 0 ? sprintf($txt['debug_queries_used'], (int) $db_count) : sprintf($txt['debug_queries_used_and_warnings'], (int) $db_count, $warnings), '</a><br> |
| 317 | 339 | <br>'; |
| 318 | 340 | |
| 319 | - if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) |
|
| 320 | - foreach ($db_cache as $q => $query_data) |
|
| 341 | + if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) { |
|
| 342 | + foreach ($db_cache as $q => $query_data) |
|
| 321 | 343 | { |
| 322 | 344 | $is_select = strpos(trim($query_data['q']), 'SELECT') === 0 || preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+SELECT .+$~s', trim($query_data['q'])) != 0; |
| 345 | + } |
|
| 323 | 346 | // Temporary tables created in earlier queries are not explainable. |
| 324 | 347 | if ($is_select) |
| 325 | 348 | { |
| 326 | - foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) |
|
| 327 | - if (strpos(trim($query_data['q']), $tmp) !== false) |
|
| 349 | + foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) { |
|
| 350 | + if (strpos(trim($query_data['q']), $tmp) !== false) |
|
| 328 | 351 | { |
| 329 | 352 | $is_select = false; |
| 353 | + } |
|
| 330 | 354 | break; |
| 331 | 355 | } |
| 332 | 356 | } |
| 333 | 357 | // But actual creation of the temporary tables are. |
| 334 | - elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($query_data['q'])) != 0) |
|
| 335 | - $is_select = true; |
|
| 358 | + elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($query_data['q'])) != 0) { |
|
| 359 | + $is_select = true; |
|
| 360 | + } |
|
| 336 | 361 | |
| 337 | 362 | // Make the filenames look a bit better. |
| 338 | - if (isset($query_data['f'])) |
|
| 339 | - $query_data['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $query_data['f']); |
|
| 363 | + if (isset($query_data['f'])) { |
|
| 364 | + $query_data['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $query_data['f']); |
|
| 365 | + } |
|
| 340 | 366 | |
| 341 | 367 | echo ' |
| 342 | 368 | <strong>', $is_select ? '<a href="' . $scripturl . '?action=viewquery;qq=' . ($q + 1) . '#qq' . $q . '" target="_blank" rel="noopener" style="text-decoration: none;">' : '', nl2br(str_replace("\t", ' ', $smcFunc['htmlspecialchars'](ltrim($query_data['q'], "\n\r")))) . ($is_select ? '</a></strong>' : '</strong>') . '<br> |
| 343 | 369 | '; |
| 344 | - if (!empty($query_data['f']) && !empty($query_data['l'])) |
|
| 345 | - echo sprintf($txt['debug_query_in_line'], $query_data['f'], $query_data['l']); |
|
| 370 | + if (!empty($query_data['f']) && !empty($query_data['l'])) { |
|
| 371 | + echo sprintf($txt['debug_query_in_line'], $query_data['f'], $query_data['l']); |
|
| 372 | + } |
|
| 346 | 373 | |
| 347 | - if (isset($query_data['s'], $query_data['t']) && isset($txt['debug_query_which_took_at'])) |
|
| 348 | - echo sprintf($txt['debug_query_which_took_at'], round($query_data['t'], 8), round($query_data['s'], 8)) . '<br>'; |
|
| 349 | - elseif (isset($query_data['t'])) |
|
| 350 | - echo sprintf($txt['debug_query_which_took'], round($query_data['t'], 8)) . '<br>'; |
|
| 374 | + if (isset($query_data['s'], $query_data['t']) && isset($txt['debug_query_which_took_at'])) { |
|
| 375 | + echo sprintf($txt['debug_query_which_took_at'], round($query_data['t'], 8), round($query_data['s'], 8)) . '<br>'; |
|
| 376 | + } elseif (isset($query_data['t'])) { |
|
| 377 | + echo sprintf($txt['debug_query_which_took'], round($query_data['t'], 8)) . '<br>'; |
|
| 378 | + } |
|
| 351 | 379 | echo ' |
| 352 | 380 | <br>'; |
| 353 | 381 | } |
@@ -372,12 +400,14 @@ discard block |
||
| 372 | 400 | global $modSettings, $smcFunc; |
| 373 | 401 | static $cache_stats = array(); |
| 374 | 402 | |
| 375 | - if (empty($modSettings['trackStats'])) |
|
| 376 | - return false; |
|
| 377 | - if (!empty($stats)) |
|
| 378 | - return $cache_stats = array_merge($cache_stats, $stats); |
|
| 379 | - elseif (empty($cache_stats)) |
|
| 380 | - return false; |
|
| 403 | + if (empty($modSettings['trackStats'])) { |
|
| 404 | + return false; |
|
| 405 | + } |
|
| 406 | + if (!empty($stats)) { |
|
| 407 | + return $cache_stats = array_merge($cache_stats, $stats); |
|
| 408 | + } elseif (empty($cache_stats)) { |
|
| 409 | + return false; |
|
| 410 | + } |
|
| 381 | 411 | |
| 382 | 412 | $setStringUpdate = ''; |
| 383 | 413 | $insert_keys = array(); |
@@ -390,10 +420,11 @@ discard block |
||
| 390 | 420 | $setStringUpdate .= ' |
| 391 | 421 | ' . $field . ' = ' . ($change === '+' ? $field . ' + 1' : '{int:' . $field . '}') . ','; |
| 392 | 422 | |
| 393 | - if ($change === '+') |
|
| 394 | - $cache_stats[$field] = 1; |
|
| 395 | - else |
|
| 396 | - $update_parameters[$field] = $change; |
|
| 423 | + if ($change === '+') { |
|
| 424 | + $cache_stats[$field] = 1; |
|
| 425 | + } else { |
|
| 426 | + $update_parameters[$field] = $change; |
|
| 427 | + } |
|
| 397 | 428 | $insert_keys[$field] = 'int'; |
| 398 | 429 | } |
| 399 | 430 | |
@@ -457,43 +488,50 @@ discard block |
||
| 457 | 488 | ); |
| 458 | 489 | |
| 459 | 490 | // Make sure this particular log is enabled first... |
| 460 | - if (empty($modSettings['modlog_enabled'])) |
|
| 461 | - unset ($log_types['moderate']); |
|
| 462 | - if (empty($modSettings['userlog_enabled'])) |
|
| 463 | - unset ($log_types['user']); |
|
| 464 | - if (empty($modSettings['adminlog_enabled'])) |
|
| 465 | - unset ($log_types['admin']); |
|
| 491 | + if (empty($modSettings['modlog_enabled'])) { |
|
| 492 | + unset ($log_types['moderate']); |
|
| 493 | + } |
|
| 494 | + if (empty($modSettings['userlog_enabled'])) { |
|
| 495 | + unset ($log_types['user']); |
|
| 496 | + } |
|
| 497 | + if (empty($modSettings['adminlog_enabled'])) { |
|
| 498 | + unset ($log_types['admin']); |
|
| 499 | + } |
|
| 466 | 500 | |
| 467 | 501 | call_integration_hook('integrate_log_types', array(&$log_types)); |
| 468 | 502 | |
| 469 | 503 | foreach ($logs as $log) |
| 470 | 504 | { |
| 471 | - if (!isset($log_types[$log['log_type']])) |
|
| 472 | - return false; |
|
| 505 | + if (!isset($log_types[$log['log_type']])) { |
|
| 506 | + return false; |
|
| 507 | + } |
|
| 473 | 508 | |
| 474 | - if (!is_array($log['extra'])) |
|
| 475 | - trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE); |
|
| 509 | + if (!is_array($log['extra'])) { |
|
| 510 | + trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE); |
|
| 511 | + } |
|
| 476 | 512 | |
| 477 | 513 | // Pull out the parts we want to store separately, but also make sure that the data is proper |
| 478 | 514 | if (isset($log['extra']['topic'])) |
| 479 | 515 | { |
| 480 | - if (!is_numeric($log['extra']['topic'])) |
|
| 481 | - trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE); |
|
| 516 | + if (!is_numeric($log['extra']['topic'])) { |
|
| 517 | + trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE); |
|
| 518 | + } |
|
| 482 | 519 | $topic_id = empty($log['extra']['topic']) ? 0 : (int) $log['extra']['topic']; |
| 483 | 520 | unset($log['extra']['topic']); |
| 521 | + } else { |
|
| 522 | + $topic_id = 0; |
|
| 484 | 523 | } |
| 485 | - else |
|
| 486 | - $topic_id = 0; |
|
| 487 | 524 | |
| 488 | 525 | if (isset($log['extra']['message'])) |
| 489 | 526 | { |
| 490 | - if (!is_numeric($log['extra']['message'])) |
|
| 491 | - trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE); |
|
| 527 | + if (!is_numeric($log['extra']['message'])) { |
|
| 528 | + trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE); |
|
| 529 | + } |
|
| 492 | 530 | $msg_id = empty($log['extra']['message']) ? 0 : (int) $log['extra']['message']; |
| 493 | 531 | unset($log['extra']['message']); |
| 532 | + } else { |
|
| 533 | + $msg_id = 0; |
|
| 494 | 534 | } |
| 495 | - else |
|
| 496 | - $msg_id = 0; |
|
| 497 | 535 | |
| 498 | 536 | // @todo cache this? |
| 499 | 537 | // Is there an associated report on this? |
@@ -520,23 +558,26 @@ discard block |
||
| 520 | 558 | $smcFunc['db_free_result']($request); |
| 521 | 559 | } |
| 522 | 560 | |
| 523 | - if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) |
|
| 524 | - trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE); |
|
| 561 | + if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) { |
|
| 562 | + trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE); |
|
| 563 | + } |
|
| 525 | 564 | |
| 526 | 565 | if (isset($log['extra']['board'])) |
| 527 | 566 | { |
| 528 | - if (!is_numeric($log['extra']['board'])) |
|
| 529 | - trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE); |
|
| 567 | + if (!is_numeric($log['extra']['board'])) { |
|
| 568 | + trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE); |
|
| 569 | + } |
|
| 530 | 570 | $board_id = empty($log['extra']['board']) ? 0 : (int) $log['extra']['board']; |
| 531 | 571 | unset($log['extra']['board']); |
| 572 | + } else { |
|
| 573 | + $board_id = 0; |
|
| 532 | 574 | } |
| 533 | - else |
|
| 534 | - $board_id = 0; |
|
| 535 | 575 | |
| 536 | 576 | if (isset($log['extra']['board_to'])) |
| 537 | 577 | { |
| 538 | - if (!is_numeric($log['extra']['board_to'])) |
|
| 539 | - trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE); |
|
| 578 | + if (!is_numeric($log['extra']['board_to'])) { |
|
| 579 | + trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE); |
|
| 580 | + } |
|
| 540 | 581 | if (empty($board_id)) |
| 541 | 582 | { |
| 542 | 583 | $board_id = empty($log['extra']['board_to']) ? 0 : (int) $log['extra']['board_to']; |
@@ -544,15 +585,17 @@ discard block |
||
| 544 | 585 | } |
| 545 | 586 | } |
| 546 | 587 | |
| 547 | - if (isset($log['extra']['member_affected'])) |
|
| 548 | - $memID = $log['extra']['member_affected']; |
|
| 549 | - else |
|
| 550 | - $memID = $user_info['id']; |
|
| 588 | + if (isset($log['extra']['member_affected'])) { |
|
| 589 | + $memID = $log['extra']['member_affected']; |
|
| 590 | + } else { |
|
| 591 | + $memID = $user_info['id']; |
|
| 592 | + } |
|
| 551 | 593 | |
| 552 | - if (isset($user_info['ip'])) |
|
| 553 | - $memIP = $user_info['ip']; |
|
| 554 | - else |
|
| 555 | - $memIP = 'null'; |
|
| 594 | + if (isset($user_info['ip'])) { |
|
| 595 | + $memIP = $user_info['ip']; |
|
| 596 | + } else { |
|
| 597 | + $memIP = 'null'; |
|
| 598 | + } |
|
| 556 | 599 | |
| 557 | 600 | $inserts[] = array( |
| 558 | 601 | time(), $log_types[$log['log_type']], $memID, $memIP, $log['action'], |
@@ -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 | * This is the main function for the languages area. |
@@ -150,11 +151,11 @@ discard block |
||
| 150 | 151 | $language_list = new xmlArray(fetch_web_data($url), true); |
| 151 | 152 | |
| 152 | 153 | // Check that the site responded and that the language exists. |
| 153 | - if (!$language_list->exists('languages')) |
|
| 154 | - $context['smf_error'] = 'no_response'; |
|
| 155 | - elseif (!$language_list->exists('languages/language')) |
|
| 156 | - $context['smf_error'] = 'no_files'; |
|
| 157 | - else |
|
| 154 | + if (!$language_list->exists('languages')) { |
|
| 155 | + $context['smf_error'] = 'no_response'; |
|
| 156 | + } elseif (!$language_list->exists('languages/language')) { |
|
| 157 | + $context['smf_error'] = 'no_files'; |
|
| 158 | + } else |
|
| 158 | 159 | { |
| 159 | 160 | $language_list = $language_list->path('languages[0]'); |
| 160 | 161 | $lang_files = $language_list->set('language'); |
@@ -162,8 +163,9 @@ discard block |
||
| 162 | 163 | foreach ($lang_files as $file) |
| 163 | 164 | { |
| 164 | 165 | // Were we searching? |
| 165 | - if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false) |
|
| 166 | - continue; |
|
| 166 | + if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false) { |
|
| 167 | + continue; |
|
| 168 | + } |
|
| 167 | 169 | |
| 168 | 170 | $smf_languages[] = array( |
| 169 | 171 | 'id' => $file->fetch('id'), |
@@ -174,10 +176,11 @@ discard block |
||
| 174 | 176 | 'install_link' => '<a href="' . $scripturl . '?action=admin;area=languages;sa=downloadlang;did=' . $file->fetch('id') . ';' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['add_language_smf_install'] . '</a>', |
| 175 | 177 | ); |
| 176 | 178 | } |
| 177 | - if (empty($smf_languages)) |
|
| 178 | - $context['smf_error'] = 'no_files'; |
|
| 179 | - else |
|
| 180 | - return $smf_languages; |
|
| 179 | + if (empty($smf_languages)) { |
|
| 180 | + $context['smf_error'] = 'no_files'; |
|
| 181 | + } else { |
|
| 182 | + return $smf_languages; |
|
| 183 | + } |
|
| 181 | 184 | } |
| 182 | 185 | } |
| 183 | 186 | |
@@ -199,8 +202,9 @@ discard block |
||
| 199 | 202 | require_once($sourcedir . '/Subs-Package.php'); |
| 200 | 203 | |
| 201 | 204 | // Clearly we need to know what to request. |
| 202 | - if (!isset($_GET['did'])) |
|
| 203 | - fatal_lang_error('no_access', false); |
|
| 205 | + if (!isset($_GET['did'])) { |
|
| 206 | + fatal_lang_error('no_access', false); |
|
| 207 | + } |
|
| 204 | 208 | |
| 205 | 209 | // Some lovely context. |
| 206 | 210 | $context['download_id'] = $_GET['did']; |
@@ -220,8 +224,9 @@ discard block |
||
| 220 | 224 | foreach ($_POST['copy_file'] as $file) |
| 221 | 225 | { |
| 222 | 226 | // Check it's not very bad. |
| 223 | - if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file))) |
|
| 224 | - fatal_error($txt['languages_download_illegal_paths']); |
|
| 227 | + if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file))) { |
|
| 228 | + fatal_error($txt['languages_download_illegal_paths']); |
|
| 229 | + } |
|
| 225 | 230 | |
| 226 | 231 | $chmod_files[] = $boarddir . '/' . $file; |
| 227 | 232 | $install_files[] = $file; |
@@ -232,8 +237,9 @@ discard block |
||
| 232 | 237 | $files_left = $file_status['files']['notwritable']; |
| 233 | 238 | |
| 234 | 239 | // Something not writable? |
| 235 | - if (!empty($files_left)) |
|
| 236 | - $context['error_message'] = $txt['languages_download_not_chmod']; |
|
| 240 | + if (!empty($files_left)) { |
|
| 241 | + $context['error_message'] = $txt['languages_download_not_chmod']; |
|
| 242 | + } |
|
| 237 | 243 | // Otherwise, go go go! |
| 238 | 244 | elseif (!empty($install_files)) |
| 239 | 245 | { |
@@ -248,11 +254,13 @@ discard block |
||
| 248 | 254 | } |
| 249 | 255 | |
| 250 | 256 | // Open up the old china. |
| 251 | - if (!isset($archive_content)) |
|
| 252 | - $archive_content = read_tgz_file('https://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null); |
|
| 257 | + if (!isset($archive_content)) { |
|
| 258 | + $archive_content = read_tgz_file('https://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null); |
|
| 259 | + } |
|
| 253 | 260 | |
| 254 | - if (empty($archive_content)) |
|
| 255 | - fatal_error($txt['add_language_error_no_response']); |
|
| 261 | + if (empty($archive_content)) { |
|
| 262 | + fatal_error($txt['add_language_error_no_response']); |
|
| 263 | + } |
|
| 256 | 264 | |
| 257 | 265 | // Now for each of the files, let's do some *stuff* |
| 258 | 266 | $context['files'] = array( |
@@ -267,8 +275,9 @@ discard block |
||
| 267 | 275 | $extension = substr($filename, strrpos($filename, '.') + 1); |
| 268 | 276 | |
| 269 | 277 | // Don't do anything with files we don't understand. |
| 270 | - if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt'))) |
|
| 271 | - continue; |
|
| 278 | + if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt'))) { |
|
| 279 | + continue; |
|
| 280 | + } |
|
| 272 | 281 | |
| 273 | 282 | // Basic data. |
| 274 | 283 | $context_data = array( |
@@ -287,8 +296,9 @@ discard block |
||
| 287 | 296 | // Does the file exist, is it different and can we overwrite? |
| 288 | 297 | if (file_exists($boarddir . '/' . $file['filename'])) |
| 289 | 298 | { |
| 290 | - if (is_writable($boarddir . '/' . $file['filename'])) |
|
| 291 | - $context_data['writable'] = true; |
|
| 299 | + if (is_writable($boarddir . '/' . $file['filename'])) { |
|
| 300 | + $context_data['writable'] = true; |
|
| 301 | + } |
|
| 292 | 302 | |
| 293 | 303 | // Finally, do we actually think the content has changed? |
| 294 | 304 | if ($file['size'] == filesize($boarddir . '/' . $file['filename']) && $file['md5'] == md5_file($boarddir . '/' . $file['filename'])) |
@@ -301,16 +311,17 @@ discard block |
||
| 301 | 311 | { |
| 302 | 312 | $context_data['exists'] = 'same'; |
| 303 | 313 | $context_data['default_copy'] = false; |
| 314 | + } else { |
|
| 315 | + $context_data['exists'] = 'different'; |
|
| 304 | 316 | } |
| 305 | - else |
|
| 306 | - $context_data['exists'] = 'different'; |
|
| 307 | 317 | } |
| 308 | 318 | // No overwrite? |
| 309 | 319 | else |
| 310 | 320 | { |
| 311 | 321 | // Can we at least stick it in the directory... |
| 312 | - if (is_writable($boarddir . '/' . $dirname)) |
|
| 313 | - $context_data['writable'] = true; |
|
| 322 | + if (is_writable($boarddir . '/' . $dirname)) { |
|
| 323 | + $context_data['writable'] = true; |
|
| 324 | + } |
|
| 314 | 325 | } |
| 315 | 326 | |
| 316 | 327 | // I love PHP files, that's why I'm a developer and not an artistic type spending my time drinking absinth and living a life of sin... |
@@ -325,8 +336,9 @@ discard block |
||
| 325 | 336 | list ($name, $language) = explode('.', $filename); |
| 326 | 337 | |
| 327 | 338 | // Let's get the new version, I like versions, they tell me that I'm up to date. |
| 328 | - if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1) |
|
| 329 | - $context_data['version'] = $match[1]; |
|
| 339 | + if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1) { |
|
| 340 | + $context_data['version'] = $match[1]; |
|
| 341 | + } |
|
| 330 | 342 | |
| 331 | 343 | // Now does the old file exist - if so what is it's version? |
| 332 | 344 | if (file_exists($boarddir . '/' . $file['filename'])) |
@@ -342,34 +354,35 @@ discard block |
||
| 342 | 354 | $context_data['cur_version'] = $match[1]; |
| 343 | 355 | |
| 344 | 356 | // How does this compare? |
| 345 | - if ($context_data['cur_version'] == $context_data['version']) |
|
| 346 | - $context_data['version_compare'] = 'same'; |
|
| 347 | - elseif ($context_data['cur_version'] > $context_data['version']) |
|
| 348 | - $context_data['version_compare'] = 'older'; |
|
| 357 | + if ($context_data['cur_version'] == $context_data['version']) { |
|
| 358 | + $context_data['version_compare'] = 'same'; |
|
| 359 | + } elseif ($context_data['cur_version'] > $context_data['version']) { |
|
| 360 | + $context_data['version_compare'] = 'older'; |
|
| 361 | + } |
|
| 349 | 362 | |
| 350 | 363 | // Don't recommend copying if the version is the same. |
| 351 | - if ($context_data['version_compare'] != 'newer') |
|
| 352 | - $context_data['default_copy'] = false; |
|
| 364 | + if ($context_data['version_compare'] != 'newer') { |
|
| 365 | + $context_data['default_copy'] = false; |
|
| 366 | + } |
|
| 353 | 367 | } |
| 354 | 368 | } |
| 355 | 369 | |
| 356 | 370 | // Add the context data to the main set. |
| 357 | 371 | $context['files']['lang'][] = $context_data; |
| 358 | - } |
|
| 359 | - elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false) |
|
| 372 | + } elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false) |
|
| 360 | 373 | { |
| 361 | 374 | // Registration agreement is a primary file |
| 362 | 375 | $context['files']['lang'][] = $context_data; |
| 363 | - } |
|
| 364 | - else |
|
| 376 | + } else |
|
| 365 | 377 | { |
| 366 | 378 | // There shouldn't be anything else, but load this into "other" in case we decide to handle it in the future |
| 367 | 379 | $context['files']['other'][] = $context_data; |
| 368 | 380 | } |
| 369 | 381 | |
| 370 | 382 | // Collect together all non-writable areas. |
| 371 | - if (!$context_data['writable']) |
|
| 372 | - $context['make_writable'][] = $context_data['destination']; |
|
| 383 | + if (!$context_data['writable']) { |
|
| 384 | + $context['make_writable'][] = $context_data['destination']; |
|
| 385 | + } |
|
| 373 | 386 | } |
| 374 | 387 | |
| 375 | 388 | // Before we go to far can we make anything writable, eh, eh? |
@@ -384,22 +397,24 @@ discard block |
||
| 384 | 397 | { |
| 385 | 398 | if ($type == 'lang') |
| 386 | 399 | { |
| 387 | - foreach ($data as $k => $file) |
|
| 388 | - if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable'])) |
|
| 400 | + foreach ($data as $k => $file) { |
|
| 401 | + if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable'])) |
|
| 389 | 402 | $context['files'][$type][$k]['writable'] = true; |
| 390 | - } |
|
| 391 | - else |
|
| 403 | + } |
|
| 404 | + } else |
|
| 392 | 405 | { |
| 393 | - foreach ($data as $theme => $files) |
|
| 394 | - foreach ($files as $k => $file) |
|
| 406 | + foreach ($data as $theme => $files) { |
|
| 407 | + foreach ($files as $k => $file) |
|
| 395 | 408 | if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable'])) |
| 396 | 409 | $context['files'][$type][$theme][$k]['writable'] = true; |
| 410 | + } |
|
| 397 | 411 | } |
| 398 | 412 | } |
| 399 | 413 | |
| 400 | 414 | // Are we going to need more language stuff? |
| 401 | - if (!empty($context['still_not_writable'])) |
|
| 402 | - loadLanguage('Packages'); |
|
| 415 | + if (!empty($context['still_not_writable'])) { |
|
| 416 | + loadLanguage('Packages'); |
|
| 417 | + } |
|
| 403 | 418 | } |
| 404 | 419 | |
| 405 | 420 | // This is the list for the main files. |
@@ -612,12 +627,13 @@ discard block |
||
| 612 | 627 | highlightSelected("list_language_list_' . ($language == '' ? 'english' : $language) . '");', true); |
| 613 | 628 | |
| 614 | 629 | // Display a warning if we cannot edit the default setting. |
| 615 | - if (!is_writable($boarddir . '/Settings.php')) |
|
| 616 | - $listOptions['additional_rows'][] = array( |
|
| 630 | + if (!is_writable($boarddir . '/Settings.php')) { |
|
| 631 | + $listOptions['additional_rows'][] = array( |
|
| 617 | 632 | 'position' => 'after_title', |
| 618 | 633 | 'value' => $txt['language_settings_writable'], |
| 619 | 634 | 'class' => 'smalltext alert', |
| 620 | 635 | ); |
| 636 | + } |
|
| 621 | 637 | |
| 622 | 638 | require_once($sourcedir . '/Subs-List.php'); |
| 623 | 639 | createList($listOptions); |
@@ -659,10 +675,11 @@ discard block |
||
| 659 | 675 | |
| 660 | 676 | // Put them back. |
| 661 | 677 | $settings['actual_theme_dir'] = $backup_actual_theme_dir; |
| 662 | - if (!empty($backup_base_theme_dir)) |
|
| 663 | - $settings['base_theme_dir'] = $backup_base_theme_dir; |
|
| 664 | - else |
|
| 665 | - unset($settings['base_theme_dir']); |
|
| 678 | + if (!empty($backup_base_theme_dir)) { |
|
| 679 | + $settings['base_theme_dir'] = $backup_base_theme_dir; |
|
| 680 | + } else { |
|
| 681 | + unset($settings['base_theme_dir']); |
|
| 682 | + } |
|
| 666 | 683 | |
| 667 | 684 | // Get the language files and data... |
| 668 | 685 | foreach ($context['languages'] as $lang) |
@@ -691,13 +708,15 @@ discard block |
||
| 691 | 708 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 692 | 709 | { |
| 693 | 710 | // Default? |
| 694 | - if (empty($row['lngfile']) || !isset($languages[$row['lngfile']])) |
|
| 695 | - $row['lngfile'] = $language; |
|
| 711 | + if (empty($row['lngfile']) || !isset($languages[$row['lngfile']])) { |
|
| 712 | + $row['lngfile'] = $language; |
|
| 713 | + } |
|
| 696 | 714 | |
| 697 | - if (!isset($languages[$row['lngfile']]) && isset($languages['english'])) |
|
| 698 | - $languages['english']['count'] += $row['num_users']; |
|
| 699 | - elseif (isset($languages[$row['lngfile']])) |
|
| 700 | - $languages[$row['lngfile']]['count'] += $row['num_users']; |
|
| 715 | + if (!isset($languages[$row['lngfile']]) && isset($languages['english'])) { |
|
| 716 | + $languages['english']['count'] += $row['num_users']; |
|
| 717 | + } elseif (isset($languages[$row['lngfile']])) { |
|
| 718 | + $languages[$row['lngfile']]['count'] += $row['num_users']; |
|
| 719 | + } |
|
| 701 | 720 | } |
| 702 | 721 | $smcFunc['db_free_result']($request); |
| 703 | 722 | |
@@ -737,13 +756,15 @@ discard block |
||
| 737 | 756 | |
| 738 | 757 | call_integration_hook('integrate_language_settings', array(&$config_vars)); |
| 739 | 758 | |
| 740 | - if ($return_config) |
|
| 741 | - return $config_vars; |
|
| 759 | + if ($return_config) { |
|
| 760 | + return $config_vars; |
|
| 761 | + } |
|
| 742 | 762 | |
| 743 | 763 | // Get our languages. No cache |
| 744 | 764 | getLanguages(false); |
| 745 | - foreach ($context['languages'] as $lang) |
|
| 746 | - $config_vars['language'][4][$lang['filename']] = array($lang['filename'], $lang['name']); |
|
| 765 | + foreach ($context['languages'] as $lang) { |
|
| 766 | + $config_vars['language'][4][$lang['filename']] = array($lang['filename'], $lang['name']); |
|
| 767 | + } |
|
| 747 | 768 | |
| 748 | 769 | // Saving settings? |
| 749 | 770 | if (isset($_REQUEST['save'])) |
@@ -753,8 +774,9 @@ discard block |
||
| 753 | 774 | call_integration_hook('integrate_save_language_settings', array(&$config_vars)); |
| 754 | 775 | |
| 755 | 776 | saveSettings($config_vars); |
| 756 | - if (!$settings_not_writable && !$settings_backup_fail) |
|
| 757 | - $_SESSION['adm-save'] = true; |
|
| 777 | + if (!$settings_not_writable && !$settings_backup_fail) { |
|
| 778 | + $_SESSION['adm-save'] = true; |
|
| 779 | + } |
|
| 758 | 780 | redirectexit('action=admin;area=languages;sa=settings'); |
| 759 | 781 | } |
| 760 | 782 | |
@@ -763,10 +785,11 @@ discard block |
||
| 763 | 785 | $context['settings_title'] = $txt['language_settings']; |
| 764 | 786 | $context['save_disabled'] = $settings_not_writable; |
| 765 | 787 | |
| 766 | - if ($settings_not_writable) |
|
| 767 | - $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>'; |
|
| 768 | - elseif ($settings_backup_fail) |
|
| 769 | - $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>'; |
|
| 788 | + if ($settings_not_writable) { |
|
| 789 | + $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>'; |
|
| 790 | + } elseif ($settings_backup_fail) { |
|
| 791 | + $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>'; |
|
| 792 | + } |
|
| 770 | 793 | |
| 771 | 794 | // Fill the config array. |
| 772 | 795 | prepareServerSettingsContext($config_vars); |
@@ -813,8 +836,9 @@ discard block |
||
| 813 | 836 | 'theme_dir' => $settings['default_theme_dir'], |
| 814 | 837 | ), |
| 815 | 838 | ); |
| 816 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 817 | - $themes[$row['id_theme']][$row['variable']] = $row['value']; |
|
| 839 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 840 | + $themes[$row['id_theme']][$row['variable']] = $row['value']; |
|
| 841 | + } |
|
| 818 | 842 | $smcFunc['db_free_result']($request); |
| 819 | 843 | |
| 820 | 844 | // This will be where we look |
@@ -841,14 +865,16 @@ discard block |
||
| 841 | 865 | // Check we have themes with a path and a name - just in case - and add the path. |
| 842 | 866 | foreach ($themes as $id => $data) |
| 843 | 867 | { |
| 844 | - if (count($data) != 2) |
|
| 845 | - unset($themes[$id]); |
|
| 846 | - elseif (is_dir($data['theme_dir'] . '/languages')) |
|
| 847 | - $lang_dirs[$id] = $data['theme_dir'] . '/languages'; |
|
| 868 | + if (count($data) != 2) { |
|
| 869 | + unset($themes[$id]); |
|
| 870 | + } elseif (is_dir($data['theme_dir'] . '/languages')) { |
|
| 871 | + $lang_dirs[$id] = $data['theme_dir'] . '/languages'; |
|
| 872 | + } |
|
| 848 | 873 | |
| 849 | 874 | // How about image directories? |
| 850 | - if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id'])) |
|
| 851 | - $images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id']; |
|
| 875 | + if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id'])) { |
|
| 876 | + $images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id']; |
|
| 877 | + } |
|
| 852 | 878 | } |
| 853 | 879 | |
| 854 | 880 | $current_file = $file_id ? $lang_dirs[$theme_id] . '/' . $file_id . '.' . $context['lang_id'] . '.php' : ''; |
@@ -862,15 +888,17 @@ discard block |
||
| 862 | 888 | while ($entry = $dir->read()) |
| 863 | 889 | { |
| 864 | 890 | // We're only after the files for this language. |
| 865 | - if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0) |
|
| 866 | - continue; |
|
| 891 | + if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0) { |
|
| 892 | + continue; |
|
| 893 | + } |
|
| 867 | 894 | |
| 868 | - if (!isset($context['possible_files'][$theme])) |
|
| 869 | - $context['possible_files'][$theme] = array( |
|
| 895 | + if (!isset($context['possible_files'][$theme])) { |
|
| 896 | + $context['possible_files'][$theme] = array( |
|
| 870 | 897 | 'id' => $theme, |
| 871 | 898 | 'name' => $themes[$theme]['name'], |
| 872 | 899 | 'files' => array(), |
| 873 | 900 | ); |
| 901 | + } |
|
| 874 | 902 | |
| 875 | 903 | $context['possible_files'][$theme]['files'][] = array( |
| 876 | 904 | 'id' => $matches[1], |
@@ -899,31 +927,36 @@ discard block |
||
| 899 | 927 | { |
| 900 | 928 | $_SESSION['last_backup_for'] = $context['lang_id'] . '$$$'; |
| 901 | 929 | $result = package_create_backup('backup_lang_' . $context['lang_id']); |
| 902 | - if (!$result) |
|
| 903 | - fatal_lang_error('could_not_language_backup', false); |
|
| 930 | + if (!$result) { |
|
| 931 | + fatal_lang_error('could_not_language_backup', false); |
|
| 932 | + } |
|
| 904 | 933 | } |
| 905 | 934 | |
| 906 | 935 | // Second, loop through the array to remove the files. |
| 907 | 936 | foreach ($lang_dirs as $curPath) |
| 908 | 937 | { |
| 909 | - foreach ($context['possible_files'][1]['files'] as $lang) |
|
| 910 | - if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php')) |
|
| 938 | + foreach ($context['possible_files'][1]['files'] as $lang) { |
|
| 939 | + if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php')) |
|
| 911 | 940 | unlink($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'); |
| 941 | + } |
|
| 912 | 942 | |
| 913 | 943 | // Check for the email template. |
| 914 | - if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php')) |
|
| 915 | - unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php'); |
|
| 944 | + if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php')) { |
|
| 945 | + unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php'); |
|
| 946 | + } |
|
| 916 | 947 | } |
| 917 | 948 | |
| 918 | 949 | // Third, the agreement file. |
| 919 | - if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt')) |
|
| 920 | - unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt'); |
|
| 950 | + if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt')) { |
|
| 951 | + unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt'); |
|
| 952 | + } |
|
| 921 | 953 | |
| 922 | 954 | // Fourth, a related images folder, if it exists... |
| 923 | - if (!empty($images_dirs)) |
|
| 924 | - foreach ($images_dirs as $curPath) |
|
| 955 | + if (!empty($images_dirs)) { |
|
| 956 | + foreach ($images_dirs as $curPath) |
|
| 925 | 957 | if (is_dir($curPath)) |
| 926 | 958 | deltree($curPath); |
| 959 | + } |
|
| 927 | 960 | |
| 928 | 961 | // Members can no longer use this language. |
| 929 | 962 | $smcFunc['db_query']('', ' |
@@ -1010,13 +1043,14 @@ discard block |
||
| 1010 | 1043 | foreach ($_POST['edit'] as $k => $v) |
| 1011 | 1044 | { |
| 1012 | 1045 | // Only try to save if 'edit' was specified and if the string has changed |
| 1013 | - if ($v == 'edit' && isset($_POST['entry'][$k]) && isset($_POST['comp'][$k]) && $_POST['entry'][$k] != $_POST['comp'][$k]) |
|
| 1014 | - $save_strings[$k] = cleanLangString($_POST['entry'][$k], false); |
|
| 1046 | + if ($v == 'edit' && isset($_POST['entry'][$k]) && isset($_POST['comp'][$k]) && $_POST['entry'][$k] != $_POST['comp'][$k]) { |
|
| 1047 | + $save_strings[$k] = cleanLangString($_POST['entry'][$k], false); |
|
| 1048 | + } |
|
| 1015 | 1049 | |
| 1016 | 1050 | // Record any add or remove requests. We'll decide on them later. |
| 1017 | - elseif ($v == 'remove') |
|
| 1018 | - $remove_strings[] = $k; |
|
| 1019 | - elseif ($v == 'add' && isset($_POST['entry'][$k])) |
|
| 1051 | + elseif ($v == 'remove') { |
|
| 1052 | + $remove_strings[] = $k; |
|
| 1053 | + } elseif ($v == 'add' && isset($_POST['entry'][$k])) |
|
| 1020 | 1054 | { |
| 1021 | 1055 | $add_strings[$k] = array( |
| 1022 | 1056 | 'group' => isset($_POST['grp'][$k]) ? $_POST['grp'][$k] : 'txt', |
@@ -1056,8 +1090,9 @@ discard block |
||
| 1056 | 1090 | { |
| 1057 | 1091 | $group = !empty($special_groups[$file_id][$matches[1]]) ? $special_groups[$file_id][$matches[1]] : $matches[1]; |
| 1058 | 1092 | |
| 1059 | - if (isset($allows_add_remove[$file_id]['add']) && in_array($matches[1], $allows_add_remove[$file_id]['add'])) |
|
| 1060 | - $context['can_add_lang_entry'][$group] = true; |
|
| 1093 | + if (isset($allows_add_remove[$file_id]['add']) && in_array($matches[1], $allows_add_remove[$file_id]['add'])) { |
|
| 1094 | + $context['can_add_lang_entry'][$group] = true; |
|
| 1095 | + } |
|
| 1061 | 1096 | |
| 1062 | 1097 | $entries[$matches[2]] = array( |
| 1063 | 1098 | 'type' => $matches[1], |
@@ -1079,8 +1114,9 @@ discard block |
||
| 1079 | 1114 | { |
| 1080 | 1115 | $group = !empty($special_groups[$file_id][$matches[1]]) ? $special_groups[$file_id][$matches[1]] : $matches[1]; |
| 1081 | 1116 | |
| 1082 | - if (isset($allows_add_remove[$file_id]['add']) && in_array($matches[1], $allows_add_remove[$file_id]['add'])) |
|
| 1083 | - $context['can_add_lang_entry'][$group] = true; |
|
| 1117 | + if (isset($allows_add_remove[$file_id]['add']) && in_array($matches[1], $allows_add_remove[$file_id]['add'])) { |
|
| 1118 | + $context['can_add_lang_entry'][$group] = true; |
|
| 1119 | + } |
|
| 1084 | 1120 | |
| 1085 | 1121 | $entries[$matches[2]] = array( |
| 1086 | 1122 | 'type' => $matches[1], |
@@ -1100,8 +1136,9 @@ discard block |
||
| 1100 | 1136 | { |
| 1101 | 1137 | // Ignore some things we set separately. |
| 1102 | 1138 | $ignore_files = array('lang_character_set', 'lang_locale', 'lang_dictionary', 'lang_spelling', 'lang_rtl'); |
| 1103 | - if (in_array($entryKey, $ignore_files)) |
|
| 1104 | - continue; |
|
| 1139 | + if (in_array($entryKey, $ignore_files)) { |
|
| 1140 | + continue; |
|
| 1141 | + } |
|
| 1105 | 1142 | |
| 1106 | 1143 | // These are arrays that need breaking out. |
| 1107 | 1144 | $arrays = array('days', 'days_short', 'months', 'months_titles', 'months_short'); |
@@ -1134,9 +1171,9 @@ discard block |
||
| 1134 | 1171 | { |
| 1135 | 1172 | $save_cache['entries'][$cur_index] = strtr($save_strings[$entryKey . '-+- ' . $cur_index], array('\'' => '')); |
| 1136 | 1173 | $save_cache['enabled'] = true; |
| 1174 | + } else { |
|
| 1175 | + $save_cache['entries'][$cur_index] = $subValue; |
|
| 1137 | 1176 | } |
| 1138 | - else |
|
| 1139 | - $save_cache['entries'][$cur_index] = $subValue; |
|
| 1140 | 1177 | |
| 1141 | 1178 | $context['file_entries'][$entryValue['group']][] = array( |
| 1142 | 1179 | 'key' => $entryKey . '-+- ' . $cur_index, |
@@ -1159,9 +1196,9 @@ discard block |
||
| 1159 | 1196 | { |
| 1160 | 1197 | $items[] = $k2 . ' => \'' . $v2 . '\''; |
| 1161 | 1198 | $cur_index = $k2; |
| 1199 | + } else { |
|
| 1200 | + $items[] = '\'' . $v2 . '\''; |
|
| 1162 | 1201 | } |
| 1163 | - else |
|
| 1164 | - $items[] = '\'' . $v2 . '\''; |
|
| 1165 | 1202 | |
| 1166 | 1203 | $cur_index++; |
| 1167 | 1204 | } |
@@ -1171,15 +1208,15 @@ discard block |
||
| 1171 | 1208 | 'replace' => '$' . $entryValue['type'] . '[\'' . $entryKey . '\'] = array(' . implode(', ', $items) . ');', |
| 1172 | 1209 | ); |
| 1173 | 1210 | } |
| 1174 | - } |
|
| 1175 | - else |
|
| 1211 | + } else |
|
| 1176 | 1212 | { |
| 1177 | 1213 | // Saving? |
| 1178 | 1214 | if (isset($save_strings[$entryKey]) && $save_strings[$entryKey] != $entryValue['entry']) |
| 1179 | 1215 | { |
| 1180 | 1216 | // @todo Fix this properly. |
| 1181 | - if ($save_strings[$entryKey] == '') |
|
| 1182 | - $save_strings[$entryKey] = '\'\''; |
|
| 1217 | + if ($save_strings[$entryKey] == '') { |
|
| 1218 | + $save_strings[$entryKey] = '\'\''; |
|
| 1219 | + } |
|
| 1183 | 1220 | |
| 1184 | 1221 | // Set the new value. |
| 1185 | 1222 | $entryValue['entry'] = $save_strings[$entryKey]; |
@@ -1218,8 +1255,9 @@ discard block |
||
| 1218 | 1255 | { |
| 1219 | 1256 | $type = isset($special_types[$string_val['group']]) ? $special_types[$string_val['group']] : $string_val['group']; |
| 1220 | 1257 | |
| 1221 | - if (!in_array($type, $allows_add_remove[$file_id]['add'])) |
|
| 1222 | - continue; |
|
| 1258 | + if (!in_array($type, $allows_add_remove[$file_id]['add'])) { |
|
| 1259 | + continue; |
|
| 1260 | + } |
|
| 1223 | 1261 | |
| 1224 | 1262 | $final_saves[$string_key] = array( |
| 1225 | 1263 | 'find' => "\n\n?".'>', |
@@ -1234,8 +1272,9 @@ discard block |
||
| 1234 | 1272 | checkSession(); |
| 1235 | 1273 | |
| 1236 | 1274 | $file_contents = implode('', file($current_file)); |
| 1237 | - foreach ($final_saves as $save) |
|
| 1238 | - $file_contents = strtr($file_contents, array($save['find'] => $save['replace'])); |
|
| 1275 | + foreach ($final_saves as $save) { |
|
| 1276 | + $file_contents = strtr($file_contents, array($save['find'] => $save['replace'])); |
|
| 1277 | + } |
|
| 1239 | 1278 | |
| 1240 | 1279 | // Save the actual changes. |
| 1241 | 1280 | $fp = fopen($current_file, 'w+'); |
@@ -1293,8 +1332,9 @@ discard block |
||
| 1293 | 1332 | } |
| 1294 | 1333 | |
| 1295 | 1334 | // If we saved, redirect. |
| 1296 | - if ($madeSave) |
|
| 1297 | - redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id']); |
|
| 1335 | + if ($madeSave) { |
|
| 1336 | + redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id']); |
|
| 1337 | + } |
|
| 1298 | 1338 | |
| 1299 | 1339 | createToken('admin-mlang'); |
| 1300 | 1340 | } |
@@ -1326,8 +1366,9 @@ discard block |
||
| 1326 | 1366 | // Toggle the escape. |
| 1327 | 1367 | $is_escape = !$is_escape; |
| 1328 | 1368 | // If we're now escaped don't add this string. |
| 1329 | - if ($is_escape) |
|
| 1330 | - continue; |
|
| 1369 | + if ($is_escape) { |
|
| 1370 | + continue; |
|
| 1371 | + } |
|
| 1331 | 1372 | } |
| 1332 | 1373 | // Special case - parsed string with line break etc? |
| 1333 | 1374 | elseif (($string{$i} == 'n' || $string{$i} == 't') && $in_string == 2 && $is_escape) |
@@ -1344,11 +1385,13 @@ discard block |
||
| 1344 | 1385 | if ($in_string != 2 && ($in_string != 1 || !$is_escape)) |
| 1345 | 1386 | { |
| 1346 | 1387 | // Is it the end of a single quote string? |
| 1347 | - if ($in_string == 1) |
|
| 1348 | - $in_string = 0; |
|
| 1388 | + if ($in_string == 1) { |
|
| 1389 | + $in_string = 0; |
|
| 1390 | + } |
|
| 1349 | 1391 | // Otherwise it's the start! |
| 1350 | - else |
|
| 1351 | - $in_string = 1; |
|
| 1392 | + else { |
|
| 1393 | + $in_string = 1; |
|
| 1394 | + } |
|
| 1352 | 1395 | |
| 1353 | 1396 | // Don't actually include this character! |
| 1354 | 1397 | continue; |
@@ -1361,19 +1404,22 @@ discard block |
||
| 1361 | 1404 | if ($in_string != 1 && ($in_string != 2 || !$is_escape)) |
| 1362 | 1405 | { |
| 1363 | 1406 | // Is it the end of a double quote string? |
| 1364 | - if ($in_string == 2) |
|
| 1365 | - $in_string = 0; |
|
| 1407 | + if ($in_string == 2) { |
|
| 1408 | + $in_string = 0; |
|
| 1409 | + } |
|
| 1366 | 1410 | // Otherwise it's the start! |
| 1367 | - else |
|
| 1368 | - $in_string = 2; |
|
| 1411 | + else { |
|
| 1412 | + $in_string = 2; |
|
| 1413 | + } |
|
| 1369 | 1414 | |
| 1370 | 1415 | // Don't actually include this character! |
| 1371 | 1416 | continue; |
| 1372 | 1417 | } |
| 1373 | 1418 | } |
| 1374 | 1419 | // A join/space outside of a string is simply removed. |
| 1375 | - elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.')) |
|
| 1376 | - continue; |
|
| 1420 | + elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.')) { |
|
| 1421 | + continue; |
|
| 1422 | + } |
|
| 1377 | 1423 | // Start of a variable? |
| 1378 | 1424 | elseif ($in_string == 0 && $string{$i} == '$') |
| 1379 | 1425 | { |
@@ -1407,8 +1453,7 @@ discard block |
||
| 1407 | 1453 | |
| 1408 | 1454 | // Unhtml then rehtml the whole thing! |
| 1409 | 1455 | $new_string = $smcFunc['htmlspecialchars'](un_htmlspecialchars($new_string)); |
| 1410 | - } |
|
| 1411 | - else |
|
| 1456 | + } else |
|
| 1412 | 1457 | { |
| 1413 | 1458 | // Keep track of what we're doing... |
| 1414 | 1459 | $in_string = 0; |
@@ -1437,10 +1482,11 @@ discard block |
||
| 1437 | 1482 | preg_match('~\{%([\$A-Za-z0-9\'\[\]_-]+)%\}~', substr($string, $i), $matches); |
| 1438 | 1483 | if (!empty($matches[1])) |
| 1439 | 1484 | { |
| 1440 | - if ($in_string == 1) |
|
| 1441 | - $new_string .= '\' . '; |
|
| 1442 | - elseif ($new_string) |
|
| 1443 | - $new_string .= ' . '; |
|
| 1485 | + if ($in_string == 1) { |
|
| 1486 | + $new_string .= '\' . '; |
|
| 1487 | + } elseif ($new_string) { |
|
| 1488 | + $new_string .= ' . '; |
|
| 1489 | + } |
|
| 1444 | 1490 | |
| 1445 | 1491 | $new_string .= $matches[1]; |
| 1446 | 1492 | $i += strlen($matches[1]) + 3; |
@@ -1453,8 +1499,9 @@ discard block |
||
| 1453 | 1499 | elseif ($string{$i} == '<') |
| 1454 | 1500 | { |
| 1455 | 1501 | // Probably HTML? |
| 1456 | - if ($string{$i + 1} != ' ') |
|
| 1457 | - $in_html = true; |
|
| 1502 | + if ($string{$i + 1} != ' ') { |
|
| 1503 | + $in_html = true; |
|
| 1504 | + } |
|
| 1458 | 1505 | // Assume we need an entity... |
| 1459 | 1506 | else |
| 1460 | 1507 | { |
@@ -1466,8 +1513,9 @@ discard block |
||
| 1466 | 1513 | elseif ($string{$i} == '>') |
| 1467 | 1514 | { |
| 1468 | 1515 | // Will it be HTML? |
| 1469 | - if ($in_html) |
|
| 1470 | - $in_html = false; |
|
| 1516 | + if ($in_html) { |
|
| 1517 | + $in_html = false; |
|
| 1518 | + } |
|
| 1471 | 1519 | // Otherwise we need an entity... |
| 1472 | 1520 | else |
| 1473 | 1521 | { |
@@ -1476,8 +1524,9 @@ discard block |
||
| 1476 | 1524 | } |
| 1477 | 1525 | } |
| 1478 | 1526 | // Is it a slash? If so escape it... |
| 1479 | - if ($string{$i} == '\\') |
|
| 1480 | - $new_string .= '\\'; |
|
| 1527 | + if ($string{$i} == '\\') { |
|
| 1528 | + $new_string .= '\\'; |
|
| 1529 | + } |
|
| 1481 | 1530 | // The infamous double quote? |
| 1482 | 1531 | elseif ($string{$i} == '"') |
| 1483 | 1532 | { |
@@ -1500,10 +1549,11 @@ discard block |
||
| 1500 | 1549 | } |
| 1501 | 1550 | |
| 1502 | 1551 | // If we ended as a string then close it off. |
| 1503 | - if ($in_string == 1) |
|
| 1504 | - $new_string .= '\''; |
|
| 1505 | - elseif ($in_string == 2) |
|
| 1506 | - $new_string .= '"'; |
|
| 1552 | + if ($in_string == 1) { |
|
| 1553 | + $new_string .= '\''; |
|
| 1554 | + } elseif ($in_string == 2) { |
|
| 1555 | + $new_string .= '"'; |
|
| 1556 | + } |
|
| 1507 | 1557 | } |
| 1508 | 1558 | |
| 1509 | 1559 | return $new_string; |
@@ -36,11 +36,12 @@ discard block |
||
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // An error? |
| 39 | - if (!empty($context['error_message'])) |
|
| 40 | - echo ' |
|
| 39 | + if (!empty($context['error_message'])) { |
|
| 40 | + echo ' |
|
| 41 | 41 | <div class="errorbox"> |
| 42 | 42 | ', $context['error_message'], ' |
| 43 | 43 | </div>'; |
| 44 | + } |
|
| 44 | 45 | |
| 45 | 46 | // Provide something of an introduction... |
| 46 | 47 | echo ' |
@@ -67,11 +68,12 @@ discard block |
||
| 67 | 68 | // If the files are not writable, we might! |
| 68 | 69 | if (!empty($context['still_not_writable'])) |
| 69 | 70 | { |
| 70 | - if (!empty($context['package_ftp']['error'])) |
|
| 71 | - echo ' |
|
| 71 | + if (!empty($context['package_ftp']['error'])) { |
|
| 72 | + echo ' |
|
| 72 | 73 | <div class="errorbox"> |
| 73 | 74 | ', $context['package_ftp']['error'], ' |
| 74 | 75 | </div>'; |
| 76 | + } |
|
| 75 | 77 | |
| 76 | 78 | echo ' |
| 77 | 79 | <div class="cat_bar"> |
@@ -150,11 +152,12 @@ discard block |
||
| 150 | 152 | </div>'; |
| 151 | 153 | |
| 152 | 154 | // Not writable? Oops, show an error for ya. |
| 153 | - if (!empty($context['lang_file_not_writable_message'])) |
|
| 154 | - echo ' |
|
| 155 | + if (!empty($context['lang_file_not_writable_message'])) { |
|
| 156 | + echo ' |
|
| 155 | 157 | <div class="errorbox"> |
| 156 | 158 | ', $context['lang_file_not_writable_message'], ' |
| 157 | 159 | </div>'; |
| 160 | + } |
|
| 158 | 161 | |
| 159 | 162 | // Show the language entries |
| 160 | 163 | echo ' |
@@ -199,9 +202,10 @@ discard block |
||
| 199 | 202 | <input type="submit" name="save_main" value="', $txt['save'], '"', $context['lang_file_not_writable_message'] || !empty($context['file_entries']) ? ' disabled' : '', ' class="button">'; |
| 200 | 203 | |
| 201 | 204 | // Allow deleting entries. English can't be deleted though. |
| 202 | - if ($context['lang_id'] != 'english') |
|
| 203 | - echo ' |
|
| 205 | + if ($context['lang_id'] != 'english') { |
|
| 206 | + echo ' |
|
| 204 | 207 | <input type="submit" name="delete_main" value="', $txt['delete'], '"', $context['lang_file_not_writable_message'] || !empty($context['file_entries']) ? ' disabled' : '', ' onclick="confirm(\'', $txt['languages_delete_confirm'], '\');" class="button">'; |
| 208 | + } |
|
| 205 | 209 | |
| 206 | 210 | echo ' |
| 207 | 211 | </div><!-- .windowbg --> |
@@ -224,9 +228,10 @@ discard block |
||
| 224 | 228 | echo ' |
| 225 | 229 | <optgroup label="', $theme['name'], '">'; |
| 226 | 230 | |
| 227 | - foreach ($theme['files'] as $file) |
|
| 228 | - echo ' |
|
| 231 | + foreach ($theme['files'] as $file) { |
|
| 232 | + echo ' |
|
| 229 | 233 | <option value="', $id_theme, '+', $file['id'], '"', $file['selected'] ? ' selected' : '', '>', $file['name'], '</option>'; |
| 234 | + } |
|
| 230 | 235 | |
| 231 | 236 | echo ' |
| 232 | 237 | </optgroup>'; |
@@ -241,11 +246,12 @@ discard block |
||
| 241 | 246 | </div><!-- .information -->'; |
| 242 | 247 | |
| 243 | 248 | // Is it not writable? Show an error. |
| 244 | - if (!empty($context['entries_not_writable_message'])) |
|
| 245 | - echo ' |
|
| 249 | + if (!empty($context['entries_not_writable_message'])) { |
|
| 250 | + echo ' |
|
| 246 | 251 | <div class="errorbox"> |
| 247 | 252 | ', $context['entries_not_writable_message'], ' |
| 248 | 253 | </div>'; |
| 254 | + } |
|
| 249 | 255 | |
| 250 | 256 | // Already have some file entries? |
| 251 | 257 | if (!empty($context['file_entries'])) |
@@ -274,8 +280,8 @@ discard block |
||
| 274 | 280 | </dt> |
| 275 | 281 | <dd id="entry_', $entry_num, '">'; |
| 276 | 282 | |
| 277 | - if ($entry['can_remove']) |
|
| 278 | - echo ' |
|
| 283 | + if ($entry['can_remove']) { |
|
| 284 | + echo ' |
|
| 279 | 285 | <span style="margin-right: 1ch; white-space: nowrap"> |
| 280 | 286 | <input id="entry_', $entry_num, '_none" class="entry_toggle" type="radio" name="edit[', $entry['key'], ']" value="" data-target="#entry_', $entry_num, '" checked> |
| 281 | 287 | <label for="entry_', $entry_num, '_none">', $txt['no_change'], '</label> |
@@ -288,10 +294,11 @@ discard block |
||
| 288 | 294 | <input id="entry_', $entry_num, '_remove" class="entry_toggle" type="radio" name="edit[', $entry['key'], ']" value="remove" data-target="#entry_', $entry_num, '"> |
| 289 | 295 | <label for="entry_', $entry_num, '_remove">', $txt['remove'], '</label> |
| 290 | 296 | </span>'; |
| 291 | - else |
|
| 292 | - echo ' |
|
| 297 | + } else { |
|
| 298 | + echo ' |
|
| 293 | 299 | <input id="entry_', $entry_num, '_edit" class="entry_toggle" type="checkbox" name="edit[', $entry['key'], ']" value="edit" data-target="#entry_', $entry_num, '"> |
| 294 | 300 | <label for="entry_', $entry_num, '_edit">', $txt['edit'], '</label>'; |
| 301 | + } |
|
| 295 | 302 | |
| 296 | 303 | echo ' |
| 297 | 304 | </span> |
@@ -351,12 +358,13 @@ discard block |
||
| 351 | 358 | <input type="text" name="smf_add" size="40" value="', !empty($context['smf_search_term']) ? $context['smf_search_term'] : '', '">'; |
| 352 | 359 | |
| 353 | 360 | // Do we have some errors? Too bad. Display a little error box. |
| 354 | - if (!empty($context['smf_error'])) |
|
| 355 | - echo ' |
|
| 361 | + if (!empty($context['smf_error'])) { |
|
| 362 | + echo ' |
|
| 356 | 363 | <div> |
| 357 | 364 | <br> |
| 358 | 365 | <p class="errorbox">', $txt['add_language_error_' . $context['smf_error']], '</p> |
| 359 | 366 | </div>'; |
| 367 | + } |
|
| 360 | 368 | |
| 361 | 369 | echo ' |
| 362 | 370 | </fieldset> |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 4 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * This function allows to move a topic, making sure to ask the moderator |
@@ -32,8 +33,9 @@ discard block |
||
| 32 | 33 | { |
| 33 | 34 | global $txt, $board, $topic, $user_info, $context, $language, $scripturl, $smcFunc, $modSettings, $sourcedir; |
| 34 | 35 | |
| 35 | - if (empty($topic)) |
|
| 36 | - fatal_lang_error('no_access', false); |
|
| 36 | + if (empty($topic)) { |
|
| 37 | + fatal_lang_error('no_access', false); |
|
| 38 | + } |
|
| 37 | 39 | |
| 38 | 40 | $request = $smcFunc['db_query']('', ' |
| 39 | 41 | SELECT t.id_member_started, ms.subject, t.approved |
@@ -49,8 +51,9 @@ discard block |
||
| 49 | 51 | $smcFunc['db_free_result']($request); |
| 50 | 52 | |
| 51 | 53 | // Can they see it - if not approved? |
| 52 | - if ($modSettings['postmod_active'] && !$context['is_approved']) |
|
| 53 | - isAllowedTo('approve_posts'); |
|
| 54 | + if ($modSettings['postmod_active'] && !$context['is_approved']) { |
|
| 55 | + isAllowedTo('approve_posts'); |
|
| 56 | + } |
|
| 54 | 57 | |
| 55 | 58 | // Permission check! |
| 56 | 59 | // @todo |
@@ -59,9 +62,9 @@ discard block |
||
| 59 | 62 | if ($id_member_started == $user_info['id']) |
| 60 | 63 | { |
| 61 | 64 | isAllowedTo('move_own'); |
| 65 | + } else { |
|
| 66 | + isAllowedTo('move_any'); |
|
| 62 | 67 | } |
| 63 | - else |
|
| 64 | - isAllowedTo('move_any'); |
|
| 65 | 68 | } |
| 66 | 69 | |
| 67 | 70 | $context['move_any'] = $user_info['is_admin'] || $modSettings['topic_move_any']; |
@@ -83,11 +86,13 @@ discard block |
||
| 83 | 86 | 'not_redirection' => true, |
| 84 | 87 | ); |
| 85 | 88 | |
| 86 | - if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board) |
|
| 87 | - $options['selected_board'] = $_SESSION['move_to_topic']; |
|
| 89 | + if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board) { |
|
| 90 | + $options['selected_board'] = $_SESSION['move_to_topic']; |
|
| 91 | + } |
|
| 88 | 92 | |
| 89 | - if (!$context['move_any']) |
|
| 90 | - $options['included_boards'] = $boards; |
|
| 93 | + if (!$context['move_any']) { |
|
| 94 | + $options['included_boards'] = $boards; |
|
| 95 | + } |
|
| 91 | 96 | |
| 92 | 97 | require_once($sourcedir . '/Subs-MessageIndex.php'); |
| 93 | 98 | $context['categories'] = getBoardList($options); |
@@ -138,12 +143,14 @@ discard block |
||
| 138 | 143 | global $txt, $topic, $scripturl, $sourcedir, $context; |
| 139 | 144 | global $board, $language, $user_info, $smcFunc; |
| 140 | 145 | |
| 141 | - if (empty($topic)) |
|
| 142 | - fatal_lang_error('no_access', false); |
|
| 146 | + if (empty($topic)) { |
|
| 147 | + fatal_lang_error('no_access', false); |
|
| 148 | + } |
|
| 143 | 149 | |
| 144 | 150 | // You can't choose to have a redirection topic and use an empty reason. |
| 145 | - if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == '')) |
|
| 146 | - fatal_lang_error('movetopic_no_reason', false); |
|
| 151 | + if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == '')) { |
|
| 152 | + fatal_lang_error('movetopic_no_reason', false); |
|
| 153 | + } |
|
| 147 | 154 | |
| 148 | 155 | moveTopicConcurrence(); |
| 149 | 156 | |
@@ -163,16 +170,18 @@ discard block |
||
| 163 | 170 | $smcFunc['db_free_result']($request); |
| 164 | 171 | |
| 165 | 172 | // Can they see it? |
| 166 | - if (!$context['is_approved']) |
|
| 167 | - isAllowedTo('approve_posts'); |
|
| 173 | + if (!$context['is_approved']) { |
|
| 174 | + isAllowedTo('approve_posts'); |
|
| 175 | + } |
|
| 168 | 176 | |
| 169 | 177 | // Can they move topics on this board? |
| 170 | 178 | if (!allowedTo('move_any')) |
| 171 | 179 | { |
| 172 | - if ($id_member_started == $user_info['id']) |
|
| 173 | - isAllowedTo('move_own'); |
|
| 174 | - else |
|
| 175 | - isAllowedTo('move_any'); |
|
| 180 | + if ($id_member_started == $user_info['id']) { |
|
| 181 | + isAllowedTo('move_own'); |
|
| 182 | + } else { |
|
| 183 | + isAllowedTo('move_any'); |
|
| 184 | + } |
|
| 176 | 185 | } |
| 177 | 186 | |
| 178 | 187 | checkSession(); |
@@ -197,8 +206,9 @@ discard block |
||
| 197 | 206 | 'blank_redirect' => '', |
| 198 | 207 | ) |
| 199 | 208 | ); |
| 200 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 201 | - fatal_lang_error('no_board'); |
|
| 209 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 210 | + fatal_lang_error('no_board'); |
|
| 211 | + } |
|
| 202 | 212 | list ($pcounter, $board_name, $subject) = $smcFunc['db_fetch_row']($request); |
| 203 | 213 | $smcFunc['db_free_result']($request); |
| 204 | 214 | |
@@ -210,8 +220,9 @@ discard block |
||
| 210 | 220 | { |
| 211 | 221 | $_POST['custom_subject'] = strtr($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['custom_subject'])), array("\r" => '', "\n" => '', "\t" => '')); |
| 212 | 222 | // Keep checking the length. |
| 213 | - if ($smcFunc['strlen']($_POST['custom_subject']) > 100) |
|
| 214 | - $_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100); |
|
| 223 | + if ($smcFunc['strlen']($_POST['custom_subject']) > 100) { |
|
| 224 | + $_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100); |
|
| 225 | + } |
|
| 215 | 226 | |
| 216 | 227 | // If it's still valid move onwards and upwards. |
| 217 | 228 | if ($_POST['custom_subject'] != '') |
@@ -221,9 +232,9 @@ discard block |
||
| 221 | 232 | // Get a response prefix, but in the forum's default language. |
| 222 | 233 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
| 223 | 234 | { |
| 224 | - if ($language === $user_info['language']) |
|
| 225 | - $context['response_prefix'] = $txt['response_prefix']; |
|
| 226 | - else |
|
| 235 | + if ($language === $user_info['language']) { |
|
| 236 | + $context['response_prefix'] = $txt['response_prefix']; |
|
| 237 | + } else |
|
| 227 | 238 | { |
| 228 | 239 | loadLanguage('index', $language, false); |
| 229 | 240 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -263,8 +274,9 @@ discard block |
||
| 263 | 274 | if (isset($_POST['postRedirect'])) |
| 264 | 275 | { |
| 265 | 276 | // Should be in the boardwide language. |
| 266 | - if ($user_info['language'] != $language) |
|
| 267 | - loadLanguage('index', $language); |
|
| 277 | + if ($user_info['language'] != $language) { |
|
| 278 | + loadLanguage('index', $language); |
|
| 279 | + } |
|
| 268 | 280 | |
| 269 | 281 | $_POST['reason'] = $smcFunc['htmlspecialchars']($_POST['reason'], ENT_QUOTES); |
| 270 | 282 | preparsecode($_POST['reason']); |
@@ -328,8 +340,9 @@ discard block |
||
| 328 | 340 | $posters = array(); |
| 329 | 341 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 330 | 342 | { |
| 331 | - if (!isset($posters[$row['id_member']])) |
|
| 332 | - $posters[$row['id_member']] = 0; |
|
| 343 | + if (!isset($posters[$row['id_member']])) { |
|
| 344 | + $posters[$row['id_member']] = 0; |
|
| 345 | + } |
|
| 333 | 346 | |
| 334 | 347 | $posters[$row['id_member']]++; |
| 335 | 348 | } |
@@ -338,11 +351,13 @@ discard block |
||
| 338 | 351 | foreach ($posters as $id_member => $posts) |
| 339 | 352 | { |
| 340 | 353 | // The board we're moving from counted posts, but not to. |
| 341 | - if (empty($pcounter_from)) |
|
| 342 | - updateMemberData($id_member, array('posts' => 'posts - ' . $posts)); |
|
| 354 | + if (empty($pcounter_from)) { |
|
| 355 | + updateMemberData($id_member, array('posts' => 'posts - ' . $posts)); |
|
| 356 | + } |
|
| 343 | 357 | // The reverse: from didn't, to did. |
| 344 | - else |
|
| 345 | - updateMemberData($id_member, array('posts' => 'posts + ' . $posts)); |
|
| 358 | + else { |
|
| 359 | + updateMemberData($id_member, array('posts' => 'posts + ' . $posts)); |
|
| 360 | + } |
|
| 346 | 361 | } |
| 347 | 362 | } |
| 348 | 363 | |
@@ -350,19 +365,21 @@ discard block |
||
| 350 | 365 | moveTopics($topic, $_POST['toboard']); |
| 351 | 366 | |
| 352 | 367 | // Log that they moved this topic. |
| 353 | - if (!allowedTo('move_own') || $id_member_started != $user_info['id']) |
|
| 354 | - logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard'])); |
|
| 368 | + if (!allowedTo('move_own') || $id_member_started != $user_info['id']) { |
|
| 369 | + logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard'])); |
|
| 370 | + } |
|
| 355 | 371 | // Notify people that this topic has been moved? |
| 356 | 372 | sendNotifications($topic, 'move'); |
| 357 | 373 | |
| 358 | 374 | call_integration_hook('integrate_movetopic2_end'); |
| 359 | 375 | |
| 360 | 376 | // Why not go back to the original board in case they want to keep moving? |
| 361 | - if (!isset($_REQUEST['goback'])) |
|
| 362 | - redirectexit('board=' . $board . '.0'); |
|
| 363 | - else |
|
| 364 | - redirectexit('topic=' . $topic . '.0'); |
|
| 365 | -} |
|
| 377 | + if (!isset($_REQUEST['goback'])) { |
|
| 378 | + redirectexit('board=' . $board . '.0'); |
|
| 379 | + } else { |
|
| 380 | + redirectexit('topic=' . $topic . '.0'); |
|
| 381 | + } |
|
| 382 | + } |
|
| 366 | 383 | |
| 367 | 384 | /** |
| 368 | 385 | * Moves one or more topics to a specific board. (doesn't check permissions.) |
@@ -378,18 +395,21 @@ discard block |
||
| 378 | 395 | global $sourcedir, $user_info, $modSettings, $smcFunc; |
| 379 | 396 | |
| 380 | 397 | // Empty array? |
| 381 | - if (empty($topics)) |
|
| 382 | - return; |
|
| 398 | + if (empty($topics)) { |
|
| 399 | + return; |
|
| 400 | + } |
|
| 383 | 401 | |
| 384 | 402 | // Only a single topic. |
| 385 | - if (is_numeric($topics)) |
|
| 386 | - $topics = array($topics); |
|
| 403 | + if (is_numeric($topics)) { |
|
| 404 | + $topics = array($topics); |
|
| 405 | + } |
|
| 387 | 406 | |
| 388 | 407 | $fromBoards = array(); |
| 389 | 408 | |
| 390 | 409 | // Destination board empty or equal to 0? |
| 391 | - if (empty($toBoard)) |
|
| 392 | - return; |
|
| 410 | + if (empty($toBoard)) { |
|
| 411 | + return; |
|
| 412 | + } |
|
| 393 | 413 | |
| 394 | 414 | // Are we moving to the recycle board? |
| 395 | 415 | $isRecycleDest = !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $toBoard; |
@@ -397,8 +417,9 @@ discard block |
||
| 397 | 417 | // Callback for search APIs to do their thing |
| 398 | 418 | require_once($sourcedir . '/Search.php'); |
| 399 | 419 | $searchAPI = findSearchAPI(); |
| 400 | - if ($searchAPI->supportsMethod('topicsMoved')) |
|
| 401 | - $searchAPI->topicsMoved($topics, $toBoard); |
|
| 420 | + if ($searchAPI->supportsMethod('topicsMoved')) { |
|
| 421 | + $searchAPI->topicsMoved($topics, $toBoard); |
|
| 422 | + } |
|
| 402 | 423 | |
| 403 | 424 | // Determine the source boards... |
| 404 | 425 | $request = $smcFunc['db_query']('', ' |
@@ -412,8 +433,9 @@ discard block |
||
| 412 | 433 | ) |
| 413 | 434 | ); |
| 414 | 435 | // Num of rows = 0 -> no topics found. Num of rows > 1 -> topics are on multiple boards. |
| 415 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 416 | - return; |
|
| 436 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 437 | + return; |
|
| 438 | + } |
|
| 417 | 439 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 418 | 440 | { |
| 419 | 441 | if (!isset($fromBoards[$row['id_board']]['num_posts'])) |
@@ -431,10 +453,11 @@ discard block |
||
| 431 | 453 | $fromBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts']; |
| 432 | 454 | |
| 433 | 455 | // Add the topics to the right type. |
| 434 | - if ($row['approved']) |
|
| 435 | - $fromBoards[$row['id_board']]['num_topics'] += $row['num_topics']; |
|
| 436 | - else |
|
| 437 | - $fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics']; |
|
| 456 | + if ($row['approved']) { |
|
| 457 | + $fromBoards[$row['id_board']]['num_topics'] += $row['num_topics']; |
|
| 458 | + } else { |
|
| 459 | + $fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics']; |
|
| 460 | + } |
|
| 438 | 461 | } |
| 439 | 462 | $smcFunc['db_free_result']($request); |
| 440 | 463 | |
@@ -560,13 +583,14 @@ discard block |
||
| 560 | 583 | ) |
| 561 | 584 | ); |
| 562 | 585 | $approval_msgs = array(); |
| 563 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 564 | - $approval_msgs[] = $row['id_msg']; |
|
| 586 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 587 | + $approval_msgs[] = $row['id_msg']; |
|
| 588 | + } |
|
| 565 | 589 | $smcFunc['db_free_result']($request); |
| 566 | 590 | |
| 567 | 591 | // Empty the approval queue for these, as we're going to approve them next. |
| 568 | - if (!empty($approval_msgs)) |
|
| 569 | - $smcFunc['db_query']('', ' |
|
| 592 | + if (!empty($approval_msgs)) { |
|
| 593 | + $smcFunc['db_query']('', ' |
|
| 570 | 594 | DELETE FROM {db_prefix}approval_queue |
| 571 | 595 | WHERE id_msg IN ({array_int:message_list}) |
| 572 | 596 | AND id_attach = {int:id_attach}', |
@@ -575,6 +599,7 @@ discard block |
||
| 575 | 599 | 'id_attach' => 0, |
| 576 | 600 | ) |
| 577 | 601 | ); |
| 602 | + } |
|
| 578 | 603 | |
| 579 | 604 | // Get all the current max and mins. |
| 580 | 605 | $request = $smcFunc['db_query']('', ' |
@@ -608,8 +633,8 @@ discard block |
||
| 608 | 633 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 609 | 634 | { |
| 610 | 635 | // If not, update. |
| 611 | - if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max']) |
|
| 612 | - $smcFunc['db_query']('', ' |
|
| 636 | + if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max']) { |
|
| 637 | + $smcFunc['db_query']('', ' |
|
| 613 | 638 | UPDATE {db_prefix}topics |
| 614 | 639 | SET id_first_msg = {int:first_msg}, id_last_msg = {int:last_msg} |
| 615 | 640 | WHERE id_topic = {int:selected_topic}', |
@@ -619,6 +644,7 @@ discard block |
||
| 619 | 644 | 'selected_topic' => $row['id_topic'], |
| 620 | 645 | ) |
| 621 | 646 | ); |
| 647 | + } |
|
| 622 | 648 | } |
| 623 | 649 | $smcFunc['db_free_result']($request); |
| 624 | 650 | } |
@@ -677,9 +703,10 @@ discard block |
||
| 677 | 703 | } |
| 678 | 704 | |
| 679 | 705 | // Update the cache? |
| 680 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) |
|
| 681 | - foreach ($topics as $topic_id) |
|
| 706 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) { |
|
| 707 | + foreach ($topics as $topic_id) |
|
| 682 | 708 | cache_put_data('topic_board-' . $topic_id, null, 120); |
| 709 | + } |
|
| 683 | 710 | |
| 684 | 711 | require_once($sourcedir . '/Subs-Post.php'); |
| 685 | 712 | |
@@ -703,15 +730,17 @@ discard block |
||
| 703 | 730 | { |
| 704 | 731 | global $board, $topic, $smcFunc, $scripturl; |
| 705 | 732 | |
| 706 | - if (isset($_GET['current_board'])) |
|
| 707 | - $move_from = (int) $_GET['current_board']; |
|
| 733 | + if (isset($_GET['current_board'])) { |
|
| 734 | + $move_from = (int) $_GET['current_board']; |
|
| 735 | + } |
|
| 708 | 736 | |
| 709 | - if (empty($move_from) || empty($board) || empty($topic)) |
|
| 710 | - return true; |
|
| 737 | + if (empty($move_from) || empty($board) || empty($topic)) { |
|
| 738 | + return true; |
|
| 739 | + } |
|
| 711 | 740 | |
| 712 | - if ($move_from == $board) |
|
| 713 | - return true; |
|
| 714 | - else |
|
| 741 | + if ($move_from == $board) { |
|
| 742 | + return true; |
|
| 743 | + } else |
|
| 715 | 744 | { |
| 716 | 745 | $request = $smcFunc['db_query']('', ' |
| 717 | 746 | SELECT m.subject, b.name |