@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | /** |
34 | 34 | * @var array Which databases support this method? |
35 | 35 | */ |
36 | - protected $supported_databases = array('mysql','postgresql'); |
|
36 | + protected $supported_databases = array('mysql', 'postgresql'); |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * The constructor function |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | $query_where = array(); |
177 | 177 | $query_params = $search_data['params']; |
178 | 178 | |
179 | - if( $smcFunc['db_title'] == "PostgreSQL") |
|
179 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
180 | 180 | $modSettings['search_simple_fulltext'] = true; |
181 | 181 | |
182 | 182 | if ($query_params['id_search']) |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | // if we have bool terms to search, add them in |
257 | 257 | if ($query_params['boolean_match']) |
258 | 258 | { |
259 | - if($smcFunc['db_title'] == "PostgreSQL") |
|
259 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
260 | 260 | { |
261 | 261 | $language_ftx = $smcFunc['db_search_language'](); |
262 | 262 | |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | } |
269 | 269 | } |
270 | 270 | |
271 | - $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? ( ' |
|
271 | + $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? (' |
|
272 | 272 | INSERT IGNORE INTO {db_prefix}' . $search_data['insert_into'] . ' |
273 | 273 | (' . implode(', ', array_keys($query_select)) . ')') : '') . ' |
274 | 274 | SELECT ' . implode(', ', $query_select) . ' |
@@ -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 | * 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 | * 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'), |
@@ -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 |
@@ -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 | * View the forum's error log. |
@@ -30,12 +31,14 @@ discard block |
||
30 | 31 | global $scripturl, $txt, $context, $modSettings, $user_profile, $filter, $smcFunc; |
31 | 32 | |
32 | 33 | // Viewing contents of a file? |
33 | - if (isset($_GET['file'])) |
|
34 | - return ViewFile(); |
|
34 | + if (isset($_GET['file'])) { |
|
35 | + return ViewFile(); |
|
36 | + } |
|
35 | 37 | |
36 | 38 | // Viewing contents of a backtrace? |
37 | - if (isset($_GET['backtrace'])) |
|
38 | - return ViewBacktrace(); |
|
39 | + if (isset($_GET['backtrace'])) { |
|
40 | + return ViewBacktrace(); |
|
41 | + } |
|
39 | 42 | |
40 | 43 | // Check for the administrative permission to do this. |
41 | 44 | isAllowedTo('admin_forum'); |
@@ -89,8 +92,8 @@ discard block |
||
89 | 92 | ); |
90 | 93 | |
91 | 94 | // Set up the filtering... |
92 | - if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']])) |
|
93 | - $filter = array( |
|
95 | + if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']])) { |
|
96 | + $filter = array( |
|
94 | 97 | 'variable' => $_GET['filter'], |
95 | 98 | 'value' => array( |
96 | 99 | 'sql' => in_array($_GET['filter'], array('message', 'url', 'file')) ? base64_decode(strtr($_GET['value'], array(' ' => '+'))) : $smcFunc['db_escape_wildcard_string']($_GET['value']), |
@@ -98,10 +101,12 @@ discard block |
||
98 | 101 | 'href' => ';filter=' . $_GET['filter'] . ';value=' . $_GET['value'], |
99 | 102 | 'entity' => $filters[$_GET['filter']]['txt'] |
100 | 103 | ); |
104 | + } |
|
101 | 105 | |
102 | 106 | // Deleting, are we? |
103 | - if (isset($_POST['delall']) || isset($_POST['delete'])) |
|
104 | - deleteErrors(); |
|
107 | + if (isset($_POST['delall']) || isset($_POST['delete'])) { |
|
108 | + deleteErrors(); |
|
109 | + } |
|
105 | 110 | |
106 | 111 | // Just how many errors are there? |
107 | 112 | $result = $smcFunc['db_query']('', ' |
@@ -116,12 +121,14 @@ discard block |
||
116 | 121 | $smcFunc['db_free_result']($result); |
117 | 122 | |
118 | 123 | // If this filter is empty... |
119 | - if ($num_errors == 0 && isset($filter)) |
|
120 | - redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : '')); |
|
124 | + if ($num_errors == 0 && isset($filter)) { |
|
125 | + redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : '')); |
|
126 | + } |
|
121 | 127 | |
122 | 128 | // Clean up start. |
123 | - if (!isset($_GET['start']) || $_GET['start'] < 0) |
|
124 | - $_GET['start'] = 0; |
|
129 | + if (!isset($_GET['start']) || $_GET['start'] < 0) { |
|
130 | + $_GET['start'] = 0; |
|
131 | + } |
|
125 | 132 | |
126 | 133 | // Do we want to reverse error listing? |
127 | 134 | $context['sort_direction'] = isset($_REQUEST['desc']) ? 'down' : 'up'; |
@@ -131,9 +138,9 @@ discard block |
||
131 | 138 | $context['start'] = $_GET['start']; |
132 | 139 | |
133 | 140 | // Update the error count |
134 | - if (!isset($filter)) |
|
135 | - $context['num_errors'] = $num_errors; |
|
136 | - else |
|
141 | + if (!isset($filter)) { |
|
142 | + $context['num_errors'] = $num_errors; |
|
143 | + } else |
|
137 | 144 | { |
138 | 145 | // We want all errors, not just the number of filtered messages... |
139 | 146 | $query = $smcFunc['db_query']('', ' |
@@ -165,8 +172,9 @@ discard block |
||
165 | 172 | for ($i = 0; $row = $smcFunc['db_fetch_assoc']($request); $i++) |
166 | 173 | { |
167 | 174 | $search_message = preg_replace('~<span class="remove">(.+?)</span>~', '%', $smcFunc['db_escape_wildcard_string']($row['message'])); |
168 | - if ($search_message == $filter['value']['sql']) |
|
169 | - $search_message = $smcFunc['db_escape_wildcard_string']($row['message']); |
|
175 | + if ($search_message == $filter['value']['sql']) { |
|
176 | + $search_message = $smcFunc['db_escape_wildcard_string']($row['message']); |
|
177 | + } |
|
170 | 178 | $show_message = strtr(strtr(preg_replace('~<span class="remove">(.+?)</span>~', '$1', $row['message']), array("\r" => '', '<br>' => "\n", '<' => '<', '>' => '>', '"' => '"')), array("\n" => '<br>')); |
171 | 179 | |
172 | 180 | $context['errors'][$row['id_error']] = array( |
@@ -225,8 +233,9 @@ discard block |
||
225 | 233 | 'members' => count($members), |
226 | 234 | ) |
227 | 235 | ); |
228 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
229 | - $members[$row['id_member']] = $row; |
|
236 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
237 | + $members[$row['id_member']] = $row; |
|
238 | + } |
|
230 | 239 | $smcFunc['db_free_result']($request); |
231 | 240 | |
232 | 241 | // This is a guest... |
@@ -258,20 +267,18 @@ discard block |
||
258 | 267 | $id = $filter['value']['sql']; |
259 | 268 | loadMemberData($id, false, 'minimal'); |
260 | 269 | $context['filter']['value']['html'] = '<a href="' . $scripturl . '?action=profile;u=' . $id . '">' . $user_profile[$id]['real_name'] . '</a>'; |
261 | - } |
|
262 | - elseif ($filter['variable'] == 'url') |
|
263 | - $context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\''; |
|
264 | - elseif ($filter['variable'] == 'message') |
|
270 | + } elseif ($filter['variable'] == 'url') { |
|
271 | + $context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\''; |
|
272 | + } elseif ($filter['variable'] == 'message') |
|
265 | 273 | { |
266 | 274 | $context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']($filter['value']['sql']), array("\n" => '<br>', '<br />' => '<br>', "\t" => ' ', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\''; |
267 | 275 | $context['filter']['value']['html'] = preg_replace('~&lt;span class=&quot;remove&quot;&gt;(.+?)&lt;/span&gt;~', '$1', $context['filter']['value']['html']); |
268 | - } |
|
269 | - elseif ($filter['variable'] == 'error_type') |
|
276 | + } elseif ($filter['variable'] == 'error_type') |
|
270 | 277 | { |
271 | 278 | $context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']($filter['value']['sql']), array("\n" => '<br>', '<br />' => '<br>', "\t" => ' ', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\''; |
279 | + } else { |
|
280 | + $context['filter']['value']['html'] = &$filter['value']['sql']; |
|
272 | 281 | } |
273 | - else |
|
274 | - $context['filter']['value']['html'] = &$filter['value']['sql']; |
|
275 | 282 | } |
276 | 283 | |
277 | 284 | $context['error_types'] = array(); |
@@ -312,10 +319,11 @@ discard block |
||
312 | 319 | $context['error_types']['all']['label'] .= ' (' . $sum . ')'; |
313 | 320 | |
314 | 321 | // Finally, work out what is the last tab! |
315 | - if (isset($context['error_types'][$sum])) |
|
316 | - $context['error_types'][$sum]['is_last'] = true; |
|
317 | - else |
|
318 | - $context['error_types']['all']['is_last'] = true; |
|
322 | + if (isset($context['error_types'][$sum])) { |
|
323 | + $context['error_types'][$sum]['is_last'] = true; |
|
324 | + } else { |
|
325 | + $context['error_types']['all']['is_last'] = true; |
|
326 | + } |
|
319 | 327 | |
320 | 328 | // And this is pretty basic ;). |
321 | 329 | $context['page_title'] = $txt['errlog']; |
@@ -341,21 +349,23 @@ discard block |
||
341 | 349 | validateToken('admin-el'); |
342 | 350 | |
343 | 351 | // Delete all or just some? |
344 | - if (isset($_POST['delall']) && !isset($filter)) |
|
345 | - $smcFunc['db_query']('truncate_table', ' |
|
352 | + if (isset($_POST['delall']) && !isset($filter)) { |
|
353 | + $smcFunc['db_query']('truncate_table', ' |
|
346 | 354 | TRUNCATE {db_prefix}log_errors', |
347 | 355 | array( |
348 | 356 | ) |
349 | 357 | ); |
358 | + } |
|
350 | 359 | // Deleting all with a filter? |
351 | - elseif (isset($_POST['delall']) && isset($filter)) |
|
352 | - $smcFunc['db_query']('', ' |
|
360 | + elseif (isset($_POST['delall']) && isset($filter)) { |
|
361 | + $smcFunc['db_query']('', ' |
|
353 | 362 | DELETE FROM {db_prefix}log_errors |
354 | 363 | WHERE ' . $filter['variable'] . ' LIKE {string:filter}', |
355 | 364 | array( |
356 | 365 | 'filter' => $filter['value']['sql'], |
357 | 366 | ) |
358 | 367 | ); |
368 | + } |
|
359 | 369 | // Just specific errors? |
360 | 370 | elseif (!empty($_POST['delete'])) |
361 | 371 | { |
@@ -401,15 +411,17 @@ discard block |
||
401 | 411 | $line = isset($_REQUEST['line']) ? (int) $_REQUEST['line'] : 0; |
402 | 412 | |
403 | 413 | // Make sure the file we are looking for is one they are allowed to look at |
404 | - if ($ext != '.php' || (strpos($file, $real_board) === false && strpos($file, $real_source) === false) || ($basename == 'settings.php' || $basename == 'settings_bak.php') || strpos($file, $real_cache) !== false || !is_readable($file)) |
|
405 | - fatal_lang_error('error_bad_file', true, array($smcFunc['htmlspecialchars']($file))); |
|
414 | + if ($ext != '.php' || (strpos($file, $real_board) === false && strpos($file, $real_source) === false) || ($basename == 'settings.php' || $basename == 'settings_bak.php') || strpos($file, $real_cache) !== false || !is_readable($file)) { |
|
415 | + fatal_lang_error('error_bad_file', true, array($smcFunc['htmlspecialchars']($file))); |
|
416 | + } |
|
406 | 417 | |
407 | 418 | // get the min and max lines |
408 | 419 | $min = $line - 20 <= 0 ? 1 : $line - 20; |
409 | 420 | $max = $line + 21; // One additional line to make everything work out correctly |
410 | 421 | |
411 | - if ($max <= 0 || $min >= $max) |
|
412 | - fatal_lang_error('error_bad_line'); |
|
422 | + if ($max <= 0 || $min >= $max) { |
|
423 | + fatal_lang_error('error_bad_line'); |
|
424 | + } |
|
413 | 425 | |
414 | 426 | $file_data = explode('<br />', highlight_php_code($smcFunc['htmlspecialchars'](implode('', file($file))))); |
415 | 427 |
@@ -254,8 +254,8 @@ discard block |
||
254 | 254 | |
255 | 255 | case 'datetime': |
256 | 256 | if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
257 | - return 'str_to_date('. |
|
258 | - sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
|
257 | + return 'str_to_date(' . |
|
258 | + sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5], $datetime_matches[6]) . |
|
259 | 259 | ',\'%Y-%m-%d %h:%i:%s\')'; |
260 | 260 | else |
261 | 261 | smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | $old_pos = 0; |
407 | 407 | $pos = -1; |
408 | 408 | // Remove the string escape for better runtime |
409 | - $db_string_1 = str_replace('\\\'','',$db_string); |
|
409 | + $db_string_1 = str_replace('\\\'', '', $db_string); |
|
410 | 410 | while (true) |
411 | 411 | { |
412 | 412 | $pos = strpos($db_string_1, '\'', $pos + 1); |
@@ -787,7 +787,7 @@ discard block |
||
787 | 787 | { |
788 | 788 | $count = count($insertRows); |
789 | 789 | $ai = 0; |
790 | - for($i = 0; $i < $count; $i++) |
|
790 | + for ($i = 0; $i < $count; $i++) |
|
791 | 791 | { |
792 | 792 | $old_id = $smcFunc['db_insert_id'](); |
793 | 793 | |
@@ -813,13 +813,13 @@ discard block |
||
813 | 813 | $count2 = count($indexed_columns); |
814 | 814 | for ($x = 0; $x < $count2; $x++) |
815 | 815 | { |
816 | - $where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x]; |
|
816 | + $where_string += key($indexed_columns[$x]) . ' = ' . $insertRows[$i][$x]; |
|
817 | 817 | if (($x + 1) < $count2) |
818 | 818 | $where_string += ' AND '; |
819 | 819 | } |
820 | 820 | |
821 | - $request = $smcFunc['db_query']('',' |
|
822 | - SELECT `'. $keys[0] . '` FROM ' . $table .' |
|
821 | + $request = $smcFunc['db_query']('', ' |
|
822 | + SELECT `'. $keys[0] . '` FROM ' . $table . ' |
|
823 | 823 | WHERE ' . $where_string . ' LIMIT 1', |
824 | 824 | array() |
825 | 825 | ); |
@@ -848,7 +848,7 @@ discard block |
||
848 | 848 | $return_var = array(); |
849 | 849 | $count = count($insertRows); |
850 | 850 | $start = smf_db_insert_id($table, $keys[0]); |
851 | - for ($i = 0; $i < $count; $i++ ) |
|
851 | + for ($i = 0; $i < $count; $i++) |
|
852 | 852 | $return_var[] = $start + $i; |
853 | 853 | } |
854 | 854 | return $return_var; |
@@ -985,7 +985,7 @@ discard block |
||
985 | 985 | mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssis', |
986 | 986 | $error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6], |
987 | 987 | $error_array[7], $error_array[8], $error_array[9]); |
988 | - mysqli_stmt_execute ($mysql_error_data_prep); |
|
988 | + mysqli_stmt_execute($mysql_error_data_prep); |
|
989 | 989 | } |
990 | 990 | |
991 | 991 | /** |
@@ -999,7 +999,7 @@ discard block |
||
999 | 999 | */ |
1000 | 1000 | function smf_db_custom_order($field, $array_values, $desc = false) |
1001 | 1001 | { |
1002 | - $return = 'CASE '. $field . ' '; |
|
1002 | + $return = 'CASE ' . $field . ' '; |
|
1003 | 1003 | $count = count($array_values); |
1004 | 1004 | $then = ($desc ? ' THEN -' : ' THEN '); |
1005 | 1005 |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -33,8 +34,8 @@ discard block |
||
33 | 34 | global $smcFunc; |
34 | 35 | |
35 | 36 | // Map some database specific functions, only do this once. |
36 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
37 | - $smcFunc += array( |
|
37 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
38 | + $smcFunc += array( |
|
38 | 39 | 'db_query' => 'smf_db_query', |
39 | 40 | 'db_quote' => 'smf_db_quote', |
40 | 41 | 'db_fetch_assoc' => 'mysqli_fetch_assoc', |
@@ -65,13 +66,16 @@ discard block |
||
65 | 66 | 'db_native_replace' => 'smf_db_native_replace', |
66 | 67 | 'db_cte_support' => 'smf_db_cte_support', |
67 | 68 | ); |
69 | + } |
|
68 | 70 | |
69 | - if (!empty($db_options['persist'])) |
|
70 | - $db_server = 'p:' . $db_server; |
|
71 | + if (!empty($db_options['persist'])) { |
|
72 | + $db_server = 'p:' . $db_server; |
|
73 | + } |
|
71 | 74 | |
72 | 75 | // We are not going to make it very far without these. |
73 | - if (!function_exists('mysqli_init') || !function_exists('mysqli_real_connect')) |
|
74 | - display_db_error(); |
|
76 | + if (!function_exists('mysqli_init') || !function_exists('mysqli_real_connect')) { |
|
77 | + display_db_error(); |
|
78 | + } |
|
75 | 79 | |
76 | 80 | $connection = mysqli_init(); |
77 | 81 | |
@@ -81,29 +85,33 @@ discard block |
||
81 | 85 | |
82 | 86 | if ($connection) |
83 | 87 | { |
84 | - if (!empty($db_options['port'])) |
|
85 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags); |
|
86 | - else |
|
87 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags); |
|
88 | + if (!empty($db_options['port'])) { |
|
89 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags); |
|
90 | + } else { |
|
91 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags); |
|
92 | + } |
|
88 | 93 | } |
89 | 94 | |
90 | 95 | // Something's wrong, show an error if its fatal (which we assume it is) |
91 | 96 | if ($success === false) |
92 | 97 | { |
93 | - if (!empty($db_options['non_fatal'])) |
|
94 | - return null; |
|
95 | - else |
|
96 | - display_db_error(); |
|
98 | + if (!empty($db_options['non_fatal'])) { |
|
99 | + return null; |
|
100 | + } else { |
|
101 | + display_db_error(); |
|
102 | + } |
|
97 | 103 | } |
98 | 104 | |
99 | 105 | // Select the database, unless told not to |
100 | - if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) |
|
101 | - display_db_error(); |
|
106 | + if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) { |
|
107 | + display_db_error(); |
|
108 | + } |
|
102 | 109 | |
103 | 110 | mysqli_query($connection, 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\''); |
104 | 111 | |
105 | - if (!empty($db_options['db_mb4'])) |
|
106 | - $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
112 | + if (!empty($db_options['db_mb4'])) { |
|
113 | + $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
114 | + } |
|
107 | 115 | |
108 | 116 | return $connection; |
109 | 117 | } |
@@ -174,34 +182,42 @@ discard block |
||
174 | 182 | global $db_callback, $user_info, $db_prefix, $smcFunc; |
175 | 183 | |
176 | 184 | list ($values, $connection) = $db_callback; |
177 | - if (!is_object($connection)) |
|
178 | - display_db_error(); |
|
185 | + if (!is_object($connection)) { |
|
186 | + display_db_error(); |
|
187 | + } |
|
179 | 188 | |
180 | - if ($matches[1] === 'db_prefix') |
|
181 | - return $db_prefix; |
|
189 | + if ($matches[1] === 'db_prefix') { |
|
190 | + return $db_prefix; |
|
191 | + } |
|
182 | 192 | |
183 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
184 | - return $user_info[$matches[1]]; |
|
193 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
194 | + return $user_info[$matches[1]]; |
|
195 | + } |
|
185 | 196 | |
186 | - if ($matches[1] === 'empty') |
|
187 | - return '\'\''; |
|
197 | + if ($matches[1] === 'empty') { |
|
198 | + return '\'\''; |
|
199 | + } |
|
188 | 200 | |
189 | - if (!isset($matches[2])) |
|
190 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
201 | + if (!isset($matches[2])) { |
|
202 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
203 | + } |
|
191 | 204 | |
192 | - if ($matches[1] === 'literal') |
|
193 | - return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
205 | + if ($matches[1] === 'literal') { |
|
206 | + return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
207 | + } |
|
194 | 208 | |
195 | - if (!isset($values[$matches[2]])) |
|
196 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
209 | + if (!isset($values[$matches[2]])) { |
|
210 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
211 | + } |
|
197 | 212 | |
198 | 213 | $replacement = $values[$matches[2]]; |
199 | 214 | |
200 | 215 | switch ($matches[1]) |
201 | 216 | { |
202 | 217 | case 'int': |
203 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
204 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
218 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
219 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
220 | + } |
|
205 | 221 | return (string) (int) $replacement; |
206 | 222 | break; |
207 | 223 | |
@@ -213,65 +229,73 @@ discard block |
||
213 | 229 | case 'array_int': |
214 | 230 | if (is_array($replacement)) |
215 | 231 | { |
216 | - if (empty($replacement)) |
|
217 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
232 | + if (empty($replacement)) { |
|
233 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
234 | + } |
|
218 | 235 | |
219 | 236 | foreach ($replacement as $key => $value) |
220 | 237 | { |
221 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
222 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
238 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
239 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
240 | + } |
|
223 | 241 | |
224 | 242 | $replacement[$key] = (string) (int) $value; |
225 | 243 | } |
226 | 244 | |
227 | 245 | return implode(', ', $replacement); |
246 | + } else { |
|
247 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
228 | 248 | } |
229 | - else |
|
230 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
231 | 249 | |
232 | 250 | break; |
233 | 251 | |
234 | 252 | case 'array_string': |
235 | 253 | if (is_array($replacement)) |
236 | 254 | { |
237 | - if (empty($replacement)) |
|
238 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
255 | + if (empty($replacement)) { |
|
256 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
257 | + } |
|
239 | 258 | |
240 | - foreach ($replacement as $key => $value) |
|
241 | - $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
259 | + foreach ($replacement as $key => $value) { |
|
260 | + $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
261 | + } |
|
242 | 262 | |
243 | 263 | return implode(', ', $replacement); |
264 | + } else { |
|
265 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
244 | 266 | } |
245 | - else |
|
246 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
247 | 267 | break; |
248 | 268 | |
249 | 269 | case 'date': |
250 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
251 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
252 | - else |
|
253 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
270 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
271 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
272 | + } else { |
|
273 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
274 | + } |
|
254 | 275 | break; |
255 | 276 | |
256 | 277 | case 'time': |
257 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
258 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
259 | - else |
|
260 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
278 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
279 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
280 | + } else { |
|
281 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
282 | + } |
|
261 | 283 | break; |
262 | 284 | |
263 | 285 | case 'datetime': |
264 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
265 | - return 'str_to_date('. |
|
286 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
287 | + return 'str_to_date('. |
|
266 | 288 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
267 | 289 | ',\'%Y-%m-%d %h:%i:%s\')'; |
268 | - else |
|
269 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
290 | + } else { |
|
291 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
292 | + } |
|
270 | 293 | break; |
271 | 294 | |
272 | 295 | case 'float': |
273 | - if (!is_numeric($replacement)) |
|
274 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
296 | + if (!is_numeric($replacement)) { |
|
297 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
298 | + } |
|
275 | 299 | return (string) (float) $replacement; |
276 | 300 | break; |
277 | 301 | |
@@ -285,32 +309,37 @@ discard block |
||
285 | 309 | break; |
286 | 310 | |
287 | 311 | case 'inet': |
288 | - if ($replacement == 'null' || $replacement == '') |
|
289 | - return 'null'; |
|
290 | - if (!isValidIP($replacement)) |
|
291 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
312 | + if ($replacement == 'null' || $replacement == '') { |
|
313 | + return 'null'; |
|
314 | + } |
|
315 | + if (!isValidIP($replacement)) { |
|
316 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
317 | + } |
|
292 | 318 | //we don't use the native support of mysql > 5.6.2 |
293 | 319 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
294 | 320 | |
295 | 321 | case 'array_inet': |
296 | 322 | if (is_array($replacement)) |
297 | 323 | { |
298 | - if (empty($replacement)) |
|
299 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
324 | + if (empty($replacement)) { |
|
325 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
326 | + } |
|
300 | 327 | |
301 | 328 | foreach ($replacement as $key => $value) |
302 | 329 | { |
303 | - if ($replacement == 'null' || $replacement == '') |
|
304 | - $replacement[$key] = 'null'; |
|
305 | - if (!isValidIP($value)) |
|
306 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
330 | + if ($replacement == 'null' || $replacement == '') { |
|
331 | + $replacement[$key] = 'null'; |
|
332 | + } |
|
333 | + if (!isValidIP($value)) { |
|
334 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
335 | + } |
|
307 | 336 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
308 | 337 | } |
309 | 338 | |
310 | 339 | return implode(', ', $replacement); |
340 | + } else { |
|
341 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
311 | 342 | } |
312 | - else |
|
313 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
314 | 343 | break; |
315 | 344 | |
316 | 345 | default: |
@@ -381,18 +410,20 @@ discard block |
||
381 | 410 | // One more query.... |
382 | 411 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
383 | 412 | |
384 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
385 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
413 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
414 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
415 | + } |
|
386 | 416 | |
387 | 417 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
388 | 418 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
389 | 419 | { |
390 | 420 | // Add before LIMIT |
391 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
392 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
393 | - else |
|
394 | - // Append it. |
|
421 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
422 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
423 | + } else { |
|
424 | + // Append it. |
|
395 | 425 | $db_string .= "\n\t\t\tORDER BY null"; |
426 | + } |
|
396 | 427 | } |
397 | 428 | |
398 | 429 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -418,17 +449,18 @@ discard block |
||
418 | 449 | while (true) |
419 | 450 | { |
420 | 451 | $pos = strpos($db_string_1, '\'', $pos + 1); |
421 | - if ($pos === false) |
|
422 | - break; |
|
452 | + if ($pos === false) { |
|
453 | + break; |
|
454 | + } |
|
423 | 455 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
424 | 456 | |
425 | 457 | while (true) |
426 | 458 | { |
427 | 459 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
428 | 460 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
429 | - if ($pos1 === false) |
|
430 | - break; |
|
431 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
461 | + if ($pos1 === false) { |
|
462 | + break; |
|
463 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
432 | 464 | { |
433 | 465 | $pos = $pos1; |
434 | 466 | break; |
@@ -444,16 +476,19 @@ discard block |
||
444 | 476 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
445 | 477 | |
446 | 478 | // Comments? We don't use comments in our queries, we leave 'em outside! |
447 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
448 | - $fail = true; |
|
479 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
480 | + $fail = true; |
|
481 | + } |
|
449 | 482 | // Trying to change passwords, slow us down, or something? |
450 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
451 | - $fail = true; |
|
452 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
453 | - $fail = true; |
|
483 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
484 | + $fail = true; |
|
485 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
486 | + $fail = true; |
|
487 | + } |
|
454 | 488 | |
455 | - if (!empty($fail) && function_exists('log_error')) |
|
456 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
489 | + if (!empty($fail) && function_exists('log_error')) { |
|
490 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
491 | + } |
|
457 | 492 | } |
458 | 493 | |
459 | 494 | // Debugging. |
@@ -463,8 +498,9 @@ discard block |
||
463 | 498 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
464 | 499 | |
465 | 500 | // Initialize $db_cache if not already initialized. |
466 | - if (!isset($db_cache)) |
|
467 | - $db_cache = array(); |
|
501 | + if (!isset($db_cache)) { |
|
502 | + $db_cache = array(); |
|
503 | + } |
|
468 | 504 | |
469 | 505 | if (!empty($_SESSION['debug_redirect'])) |
470 | 506 | { |
@@ -480,17 +516,20 @@ discard block |
||
480 | 516 | $db_cache[$db_count]['s'] = ($st = microtime(true)) - $time_start; |
481 | 517 | } |
482 | 518 | |
483 | - if (empty($db_unbuffered)) |
|
484 | - $ret = @mysqli_query($connection, $db_string); |
|
485 | - else |
|
486 | - $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
519 | + if (empty($db_unbuffered)) { |
|
520 | + $ret = @mysqli_query($connection, $db_string); |
|
521 | + } else { |
|
522 | + $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
523 | + } |
|
487 | 524 | |
488 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
489 | - $ret = smf_db_error($db_string, $connection); |
|
525 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
526 | + $ret = smf_db_error($db_string, $connection); |
|
527 | + } |
|
490 | 528 | |
491 | 529 | // Debugging. |
492 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
493 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
530 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
531 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
532 | + } |
|
494 | 533 | |
495 | 534 | return $ret; |
496 | 535 | } |
@@ -537,12 +576,13 @@ discard block |
||
537 | 576 | // Decide which connection to use |
538 | 577 | $connection = $connection === null ? $db_connection : $connection; |
539 | 578 | |
540 | - if ($type == 'begin') |
|
541 | - return @mysqli_query($connection, 'BEGIN'); |
|
542 | - elseif ($type == 'rollback') |
|
543 | - return @mysqli_query($connection, 'ROLLBACK'); |
|
544 | - elseif ($type == 'commit') |
|
545 | - return @mysqli_query($connection, 'COMMIT'); |
|
579 | + if ($type == 'begin') { |
|
580 | + return @mysqli_query($connection, 'BEGIN'); |
|
581 | + } elseif ($type == 'rollback') { |
|
582 | + return @mysqli_query($connection, 'ROLLBACK'); |
|
583 | + } elseif ($type == 'commit') { |
|
584 | + return @mysqli_query($connection, 'COMMIT'); |
|
585 | + } |
|
546 | 586 | |
547 | 587 | return false; |
548 | 588 | } |
@@ -580,8 +620,9 @@ discard block |
||
580 | 620 | // 1213: Deadlock found. |
581 | 621 | |
582 | 622 | // Log the error. |
583 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
584 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
623 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
624 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
625 | + } |
|
585 | 626 | |
586 | 627 | // Database error auto fixing ;). |
587 | 628 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -590,8 +631,9 @@ discard block |
||
590 | 631 | $old_cache = @$modSettings['cache_enable']; |
591 | 632 | $modSettings['cache_enable'] = '1'; |
592 | 633 | |
593 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
594 | - $db_last_error = max(@$db_last_error, $temp); |
|
634 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
635 | + $db_last_error = max(@$db_last_error, $temp); |
|
636 | + } |
|
595 | 637 | |
596 | 638 | if (@$db_last_error < time() - 3600 * 24 * 3) |
597 | 639 | { |
@@ -607,8 +649,9 @@ discard block |
||
607 | 649 | foreach ($tables as $table) |
608 | 650 | { |
609 | 651 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
610 | - if (trim($table) != '') |
|
611 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
652 | + if (trim($table) != '') { |
|
653 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
654 | + } |
|
612 | 655 | } |
613 | 656 | } |
614 | 657 | |
@@ -617,8 +660,9 @@ discard block |
||
617 | 660 | // Table crashed. Let's try to fix it. |
618 | 661 | elseif ($query_errno == 1016) |
619 | 662 | { |
620 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
621 | - $fix_tables = array('`' . $match[1] . '`'); |
|
663 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
664 | + $fix_tables = array('`' . $match[1] . '`'); |
|
665 | + } |
|
622 | 666 | } |
623 | 667 | // Indexes crashed. Should be easy to fix! |
624 | 668 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -637,13 +681,15 @@ discard block |
||
637 | 681 | |
638 | 682 | // Make a note of the REPAIR... |
639 | 683 | cache_put_data('db_last_error', time(), 600); |
640 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
641 | - updateSettingsFile(array('db_last_error' => time())); |
|
684 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
685 | + updateSettingsFile(array('db_last_error' => time())); |
|
686 | + } |
|
642 | 687 | |
643 | 688 | // Attempt to find and repair the broken table. |
644 | - foreach ($fix_tables as $table) |
|
645 | - $smcFunc['db_query']('', " |
|
689 | + foreach ($fix_tables as $table) { |
|
690 | + $smcFunc['db_query']('', " |
|
646 | 691 | REPAIR TABLE $table", false, false); |
692 | + } |
|
647 | 693 | |
648 | 694 | // And send off an email! |
649 | 695 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -652,11 +698,12 @@ discard block |
||
652 | 698 | |
653 | 699 | // Try the query again...? |
654 | 700 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
655 | - if ($ret !== false) |
|
656 | - return $ret; |
|
701 | + if ($ret !== false) { |
|
702 | + return $ret; |
|
703 | + } |
|
704 | + } else { |
|
705 | + $modSettings['cache_enable'] = $old_cache; |
|
657 | 706 | } |
658 | - else |
|
659 | - $modSettings['cache_enable'] = $old_cache; |
|
660 | 707 | |
661 | 708 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
662 | 709 | if (in_array($query_errno, array(1205, 1213))) |
@@ -669,24 +716,27 @@ discard block |
||
669 | 716 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
670 | 717 | |
671 | 718 | $new_errno = mysqli_errno($db_connection); |
672 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
673 | - break; |
|
719 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
720 | + break; |
|
721 | + } |
|
674 | 722 | } |
675 | 723 | |
676 | 724 | // If it failed again, shucks to be you... we're not trying it over and over. |
677 | - if ($ret !== false) |
|
678 | - return $ret; |
|
725 | + if ($ret !== false) { |
|
726 | + return $ret; |
|
727 | + } |
|
679 | 728 | } |
680 | 729 | } |
681 | 730 | // Are they out of space, perhaps? |
682 | 731 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
683 | 732 | { |
684 | - if (!isset($txt)) |
|
685 | - $query_error .= ' - check database storage space.'; |
|
686 | - else |
|
733 | + if (!isset($txt)) { |
|
734 | + $query_error .= ' - check database storage space.'; |
|
735 | + } else |
|
687 | 736 | { |
688 | - if (!isset($txt['mysql_error_space'])) |
|
689 | - loadLanguage('Errors'); |
|
737 | + if (!isset($txt['mysql_error_space'])) { |
|
738 | + loadLanguage('Errors'); |
|
739 | + } |
|
690 | 740 | |
691 | 741 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
692 | 742 | } |
@@ -694,15 +744,17 @@ discard block |
||
694 | 744 | } |
695 | 745 | |
696 | 746 | // Nothing's defined yet... just die with it. |
697 | - if (empty($context) || empty($txt)) |
|
698 | - die($query_error); |
|
747 | + if (empty($context) || empty($txt)) { |
|
748 | + die($query_error); |
|
749 | + } |
|
699 | 750 | |
700 | 751 | // Show an error message, if possible. |
701 | 752 | $context['error_title'] = $txt['database_error']; |
702 | - if (allowedTo('admin_forum')) |
|
703 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
704 | - else |
|
705 | - $context['error_message'] = $txt['try_again']; |
|
753 | + if (allowedTo('admin_forum')) { |
|
754 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
755 | + } else { |
|
756 | + $context['error_message'] = $txt['try_again']; |
|
757 | + } |
|
706 | 758 | |
707 | 759 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
708 | 760 | { |
@@ -734,8 +786,9 @@ discard block |
||
734 | 786 | $return_var = null; |
735 | 787 | |
736 | 788 | // With nothing to insert, simply return. |
737 | - if (empty($data)) |
|
738 | - return; |
|
789 | + if (empty($data)) { |
|
790 | + return; |
|
791 | + } |
|
739 | 792 | |
740 | 793 | // Replace the prefix holder with the actual prefix. |
741 | 794 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -745,23 +798,26 @@ discard block |
||
745 | 798 | if (!empty($keys) && (count($keys) > 0) && $returnmode > 0) |
746 | 799 | { |
747 | 800 | $with_returning = true; |
748 | - if ($returnmode == 2) |
|
749 | - $return_var = array(); |
|
801 | + if ($returnmode == 2) { |
|
802 | + $return_var = array(); |
|
803 | + } |
|
750 | 804 | } |
751 | 805 | |
752 | 806 | // Inserting data as a single row can be done as a single array. |
753 | - if (!is_array($data[array_rand($data)])) |
|
754 | - $data = array($data); |
|
807 | + if (!is_array($data[array_rand($data)])) { |
|
808 | + $data = array($data); |
|
809 | + } |
|
755 | 810 | |
756 | 811 | // Create the mold for a single row insert. |
757 | 812 | $insertData = '('; |
758 | 813 | foreach ($columns as $columnName => $type) |
759 | 814 | { |
760 | 815 | // Are we restricting the length? |
761 | - if (strpos($type, 'string-') !== false) |
|
762 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
763 | - else |
|
764 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
816 | + if (strpos($type, 'string-') !== false) { |
|
817 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
818 | + } else { |
|
819 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
820 | + } |
|
765 | 821 | } |
766 | 822 | $insertData = substr($insertData, 0, -2) . ')'; |
767 | 823 | |
@@ -770,16 +826,18 @@ discard block |
||
770 | 826 | |
771 | 827 | // Here's where the variables are injected to the query. |
772 | 828 | $insertRows = array(); |
773 | - foreach ($data as $dataRow) |
|
774 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
829 | + foreach ($data as $dataRow) { |
|
830 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
831 | + } |
|
775 | 832 | |
776 | 833 | // Determine the method of insertion. |
777 | 834 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
778 | 835 | |
779 | 836 | // Sanity check for replace is key part of the columns array |
780 | - if ($method == 'replace' && count(array_intersect_key($columns, array_flip($keys))) !== count($keys)) |
|
781 | - smf_db_error_backtrace('Primary Key field missing in insert call', |
|
837 | + if ($method == 'replace' && count(array_intersect_key($columns, array_flip($keys))) !== count($keys)) { |
|
838 | + smf_db_error_backtrace('Primary Key field missing in insert call', |
|
782 | 839 | 'Change the method of db insert to insert or add the pk field to the columns array', E_USER_ERROR, __FILE__, __LINE__); |
840 | + } |
|
783 | 841 | |
784 | 842 | if (!$with_returning || $method != 'ingore') |
785 | 843 | { |
@@ -795,8 +853,7 @@ discard block |
||
795 | 853 | ), |
796 | 854 | $connection |
797 | 855 | ); |
798 | - } |
|
799 | - else //special way for ignore method with returning |
|
856 | + } else //special way for ignore method with returning |
|
800 | 857 | { |
801 | 858 | $count = count($insertRows); |
802 | 859 | $ai = 0; |
@@ -816,19 +873,21 @@ discard block |
||
816 | 873 | ); |
817 | 874 | $new_id = $smcFunc['db_insert_id'](); |
818 | 875 | |
819 | - if ($last_id != $new_id) //the inserted value was new |
|
876 | + if ($last_id != $new_id) { |
|
877 | + //the inserted value was new |
|
820 | 878 | { |
821 | 879 | $ai = $new_id; |
822 | 880 | } |
823 | - else // the inserted value already exists we need to find the pk |
|
881 | + } else // the inserted value already exists we need to find the pk |
|
824 | 882 | { |
825 | 883 | $where_string = ''; |
826 | 884 | $count2 = count($indexed_columns); |
827 | 885 | for ($x = 0; $x < $count2; $x++) |
828 | 886 | { |
829 | 887 | $where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x]; |
830 | - if (($x + 1) < $count2) |
|
831 | - $where_string += ' AND '; |
|
888 | + if (($x + 1) < $count2) { |
|
889 | + $where_string += ' AND '; |
|
890 | + } |
|
832 | 891 | } |
833 | 892 | |
834 | 893 | $request = $smcFunc['db_query']('',' |
@@ -844,25 +903,27 @@ discard block |
||
844 | 903 | } |
845 | 904 | } |
846 | 905 | |
847 | - if ($returnmode == 1) |
|
848 | - $return_var = $ai; |
|
849 | - else if ($returnmode == 2) |
|
850 | - $return_var[] = $ai; |
|
906 | + if ($returnmode == 1) { |
|
907 | + $return_var = $ai; |
|
908 | + } else if ($returnmode == 2) { |
|
909 | + $return_var[] = $ai; |
|
910 | + } |
|
851 | 911 | } |
852 | 912 | } |
853 | 913 | |
854 | 914 | |
855 | 915 | if ($with_returning) |
856 | 916 | { |
857 | - if ($returnmode == 1 && empty($return_var)) |
|
858 | - $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
859 | - else if ($returnmode == 2 && empty($return_var)) |
|
917 | + if ($returnmode == 1 && empty($return_var)) { |
|
918 | + $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
919 | + } else if ($returnmode == 2 && empty($return_var)) |
|
860 | 920 | { |
861 | 921 | $return_var = array(); |
862 | 922 | $count = count($insertRows); |
863 | 923 | $start = smf_db_insert_id($table, $keys[0]); |
864 | - for ($i = 0; $i < $count; $i++ ) |
|
865 | - $return_var[] = $start + $i; |
|
924 | + for ($i = 0; $i < $count; $i++ ) { |
|
925 | + $return_var[] = $start + $i; |
|
926 | + } |
|
866 | 927 | } |
867 | 928 | return $return_var; |
868 | 929 | } |
@@ -880,8 +941,9 @@ discard block |
||
880 | 941 | */ |
881 | 942 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
882 | 943 | { |
883 | - if (empty($log_message)) |
|
884 | - $log_message = $error_message; |
|
944 | + if (empty($log_message)) { |
|
945 | + $log_message = $error_message; |
|
946 | + } |
|
885 | 947 | |
886 | 948 | foreach (debug_backtrace() as $step) |
887 | 949 | { |
@@ -900,12 +962,14 @@ discard block |
||
900 | 962 | } |
901 | 963 | |
902 | 964 | // A special case - we want the file and line numbers for debugging. |
903 | - if ($error_type == 'return') |
|
904 | - return array($file, $line); |
|
965 | + if ($error_type == 'return') { |
|
966 | + return array($file, $line); |
|
967 | + } |
|
905 | 968 | |
906 | 969 | // Is always a critical error. |
907 | - if (function_exists('log_error')) |
|
908 | - log_error($log_message, 'critical', $file, $line); |
|
970 | + if (function_exists('log_error')) { |
|
971 | + log_error($log_message, 'critical', $file, $line); |
|
972 | + } |
|
909 | 973 | |
910 | 974 | if (function_exists('fatal_error')) |
911 | 975 | { |
@@ -913,12 +977,12 @@ discard block |
||
913 | 977 | |
914 | 978 | // Cannot continue... |
915 | 979 | exit; |
980 | + } elseif ($error_type) { |
|
981 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
982 | + } else { |
|
983 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
984 | + } |
|
916 | 985 | } |
917 | - elseif ($error_type) |
|
918 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
919 | - else |
|
920 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
921 | -} |
|
922 | 986 | |
923 | 987 | /** |
924 | 988 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -935,10 +999,11 @@ discard block |
||
935 | 999 | '\\' => '\\\\', |
936 | 1000 | ); |
937 | 1001 | |
938 | - if ($translate_human_wildcards) |
|
939 | - $replacements += array( |
|
1002 | + if ($translate_human_wildcards) { |
|
1003 | + $replacements += array( |
|
940 | 1004 | '*' => '%', |
941 | 1005 | ); |
1006 | + } |
|
942 | 1007 | |
943 | 1008 | return strtr($string, $replacements); |
944 | 1009 | } |
@@ -952,8 +1017,9 @@ discard block |
||
952 | 1017 | */ |
953 | 1018 | function smf_is_resource($result) |
954 | 1019 | { |
955 | - if ($result instanceof mysqli_result) |
|
956 | - return true; |
|
1020 | + if ($result instanceof mysqli_result) { |
|
1021 | + return true; |
|
1022 | + } |
|
957 | 1023 | |
958 | 1024 | return false; |
959 | 1025 | } |
@@ -982,19 +1048,22 @@ discard block |
||
982 | 1048 | static $mysql_error_data_prep; |
983 | 1049 | |
984 | 1050 | // without database we can't do anything |
985 | - if (empty($db_connection)) |
|
986 | - return; |
|
1051 | + if (empty($db_connection)) { |
|
1052 | + return; |
|
1053 | + } |
|
987 | 1054 | |
988 | - if (empty($mysql_error_data_prep)) |
|
989 | - $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
1055 | + if (empty($mysql_error_data_prep)) { |
|
1056 | + $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
990 | 1057 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line, backtrace) |
991 | 1058 | VALUES( ?, ?, unhex(?), ?, ?, ?, ?, ?, ?, ?)' |
992 | 1059 | ); |
1060 | + } |
|
993 | 1061 | |
994 | - if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) |
|
995 | - $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
996 | - else |
|
997 | - $error_array[2] = null; |
|
1062 | + if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) { |
|
1063 | + $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
1064 | + } else { |
|
1065 | + $error_array[2] = null; |
|
1066 | + } |
|
998 | 1067 | mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssis', |
999 | 1068 | $error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6], |
1000 | 1069 | $error_array[7], $error_array[8], $error_array[9]); |
@@ -1016,8 +1085,9 @@ discard block |
||
1016 | 1085 | $count = count($array_values); |
1017 | 1086 | $then = ($desc ? ' THEN -' : ' THEN '); |
1018 | 1087 | |
1019 | - for ($i = 0; $i < $count; $i++) |
|
1020 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1088 | + for ($i = 0; $i < $count; $i++) { |
|
1089 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1090 | + } |
|
1021 | 1091 | |
1022 | 1092 | $return .= 'END'; |
1023 | 1093 | return $return; |
@@ -1043,17 +1113,20 @@ discard block |
||
1043 | 1113 | global $smcFunc; |
1044 | 1114 | static $return; |
1045 | 1115 | |
1046 | - if (isset($return)) |
|
1047 | - return $return; |
|
1116 | + if (isset($return)) { |
|
1117 | + return $return; |
|
1118 | + } |
|
1048 | 1119 | |
1049 | 1120 | db_extend('extra'); |
1050 | 1121 | |
1051 | 1122 | $version = $smcFunc['db_get_version'](); |
1052 | 1123 | |
1053 | - if (strpos(strtolower($version), 'mariadb') !== false) |
|
1054 | - $return = version_compare($version, '10.2.2', '>='); |
|
1055 | - else //mysql |
|
1124 | + if (strpos(strtolower($version), 'mariadb') !== false) { |
|
1125 | + $return = version_compare($version, '10.2.2', '>='); |
|
1126 | + } else { |
|
1127 | + //mysql |
|
1056 | 1128 | $return = version_compare($version, '8.0.1', '>='); |
1129 | + } |
|
1057 | 1130 | |
1058 | 1131 | return $return; |
1059 | 1132 | } |
@@ -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 | /** |
@@ -44,8 +45,9 @@ discard block |
||
44 | 45 | $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('manage_membergroups') ? 'index' : 'settings'); |
45 | 46 | |
46 | 47 | // Is it elsewhere? |
47 | - if (isset($subActions[$_REQUEST['sa']][2])) |
|
48 | - require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]); |
|
48 | + if (isset($subActions[$_REQUEST['sa']][2])) { |
|
49 | + require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]); |
|
50 | + } |
|
49 | 51 | |
50 | 52 | // Do the permission check, you might not be allowed her. |
51 | 53 | isAllowedTo($subActions[$_REQUEST['sa']][1]); |
@@ -104,19 +106,20 @@ discard block |
||
104 | 106 | 'function' => function($rowData) use ($scripturl) |
105 | 107 | { |
106 | 108 | // Since the moderator group has no explicit members, no link is needed. |
107 | - if ($rowData['id_group'] == 3) |
|
108 | - $group_name = $rowData['group_name']; |
|
109 | - else |
|
109 | + if ($rowData['id_group'] == 3) { |
|
110 | + $group_name = $rowData['group_name']; |
|
111 | + } else |
|
110 | 112 | { |
111 | 113 | $color_style = empty($rowData['online_color']) ? '' : sprintf(' style="color: %1$s;"', $rowData['online_color']); |
112 | 114 | $group_name = sprintf('<a href="%1$s?action=admin;area=membergroups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']); |
113 | 115 | } |
114 | 116 | |
115 | 117 | // Add a help option for moderator and administrator. |
116 | - if ($rowData['id_group'] == 1) |
|
117 | - $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
118 | - elseif ($rowData['id_group'] == 3) |
|
119 | - $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
118 | + if ($rowData['id_group'] == 1) { |
|
119 | + $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
120 | + } elseif ($rowData['id_group'] == 3) { |
|
121 | + $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
122 | + } |
|
120 | 123 | |
121 | 124 | return $group_name; |
122 | 125 | }, |
@@ -329,12 +332,14 @@ discard block |
||
329 | 332 | call_integration_hook('integrate_add_membergroup', array($id_group, $postCountBasedGroup)); |
330 | 333 | |
331 | 334 | // Update the post groups now, if this is a post group! |
332 | - if (isset($_POST['min_posts'])) |
|
333 | - updateStats('postgroups'); |
|
335 | + if (isset($_POST['min_posts'])) { |
|
336 | + updateStats('postgroups'); |
|
337 | + } |
|
334 | 338 | |
335 | 339 | // You cannot set permissions for post groups if they are disabled. |
336 | - if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups'])) |
|
337 | - $_POST['perm_type'] = ''; |
|
340 | + if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups'])) { |
|
341 | + $_POST['perm_type'] = ''; |
|
342 | + } |
|
338 | 343 | |
339 | 344 | if ($_POST['perm_type'] == 'predefined') |
340 | 345 | { |
@@ -364,8 +369,9 @@ discard block |
||
364 | 369 | $smcFunc['db_free_result']($request); |
365 | 370 | |
366 | 371 | // Protected groups are... well, protected! |
367 | - if ($copy_type == 1) |
|
368 | - fatal_lang_error('membergroup_does_not_exist'); |
|
372 | + if ($copy_type == 1) { |
|
373 | + fatal_lang_error('membergroup_does_not_exist'); |
|
374 | + } |
|
369 | 375 | } |
370 | 376 | |
371 | 377 | // Don't allow copying of a real priviledged person! |
@@ -383,18 +389,20 @@ discard block |
||
383 | 389 | $inserts = array(); |
384 | 390 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
385 | 391 | { |
386 | - if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions'])) |
|
387 | - $inserts[] = array($id_group, $row['permission'], $row['add_deny']); |
|
392 | + if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions'])) { |
|
393 | + $inserts[] = array($id_group, $row['permission'], $row['add_deny']); |
|
394 | + } |
|
388 | 395 | } |
389 | 396 | $smcFunc['db_free_result']($request); |
390 | 397 | |
391 | - if (!empty($inserts)) |
|
392 | - $smcFunc['db_insert']('insert', |
|
398 | + if (!empty($inserts)) { |
|
399 | + $smcFunc['db_insert']('insert', |
|
393 | 400 | '{db_prefix}permissions', |
394 | 401 | array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'), |
395 | 402 | $inserts, |
396 | 403 | array('id_group', 'permission') |
397 | 404 | ); |
405 | + } |
|
398 | 406 | |
399 | 407 | $request = $smcFunc['db_query']('', ' |
400 | 408 | SELECT id_profile, permission, add_deny |
@@ -405,17 +413,19 @@ discard block |
||
405 | 413 | ) |
406 | 414 | ); |
407 | 415 | $inserts = array(); |
408 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
409 | - $inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']); |
|
416 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
417 | + $inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']); |
|
418 | + } |
|
410 | 419 | $smcFunc['db_free_result']($request); |
411 | 420 | |
412 | - if (!empty($inserts)) |
|
413 | - $smcFunc['db_insert']('insert', |
|
421 | + if (!empty($inserts)) { |
|
422 | + $smcFunc['db_insert']('insert', |
|
414 | 423 | '{db_prefix}board_permissions', |
415 | 424 | array('id_group' => 'int', 'id_profile' => 'int', 'permission' => 'string', 'add_deny' => 'int'), |
416 | 425 | $inserts, |
417 | 426 | array('id_group', 'id_profile', 'permission') |
418 | 427 | ); |
428 | + } |
|
419 | 429 | |
420 | 430 | // Also get some membergroup information if we're copying and not copying from guests... |
421 | 431 | if ($copy_id > 0 && $_POST['perm_type'] == 'copy') |
@@ -468,14 +478,15 @@ discard block |
||
468 | 478 | $changed_boards['allow'] = array(); |
469 | 479 | $changed_boards['deny'] = array(); |
470 | 480 | $changed_boards['ignore'] = array(); |
471 | - foreach ($accesses as $group_id => $action) |
|
472 | - $changed_boards[$action][] = (int) $group_id; |
|
481 | + foreach ($accesses as $group_id => $action) { |
|
482 | + $changed_boards[$action][] = (int) $group_id; |
|
483 | + } |
|
473 | 484 | |
474 | 485 | foreach (array('allow', 'deny') as $board_action) |
475 | 486 | { |
476 | 487 | // Only do this if they have special access requirements. |
477 | - if (!empty($changed_boards[$board_action])) |
|
478 | - $smcFunc['db_query']('', ' |
|
488 | + if (!empty($changed_boards[$board_action])) { |
|
489 | + $smcFunc['db_query']('', ' |
|
479 | 490 | UPDATE {db_prefix}boards |
480 | 491 | SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END |
481 | 492 | WHERE id_board IN ({array_int:board_list})', |
@@ -487,11 +498,13 @@ discard block |
||
487 | 498 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
488 | 499 | ) |
489 | 500 | ); |
501 | + } |
|
490 | 502 | } |
491 | 503 | |
492 | 504 | // If this is joinable then set it to show group membership in people's profiles. |
493 | - if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1) |
|
494 | - updateSettings(array('show_group_membership' => 1)); |
|
505 | + if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1) { |
|
506 | + updateSettings(array('show_group_membership' => 1)); |
|
507 | + } |
|
495 | 508 | |
496 | 509 | // Rebuild the group cache. |
497 | 510 | updateSettings(array( |
@@ -512,8 +525,9 @@ discard block |
||
512 | 525 | $context['undefined_group'] = !isset($_REQUEST['postgroup']) && !isset($_REQUEST['generalgroup']); |
513 | 526 | $context['allow_protected'] = allowedTo('admin_forum'); |
514 | 527 | |
515 | - if (!empty($modSettings['deny_boards_access'])) |
|
516 | - loadLanguage('ManagePermissions'); |
|
528 | + if (!empty($modSettings['deny_boards_access'])) { |
|
529 | + loadLanguage('ManagePermissions'); |
|
530 | + } |
|
517 | 531 | |
518 | 532 | $result = $smcFunc['db_query']('', ' |
519 | 533 | SELECT id_group, group_name |
@@ -530,11 +544,12 @@ discard block |
||
530 | 544 | ) |
531 | 545 | ); |
532 | 546 | $context['groups'] = array(); |
533 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
534 | - $context['groups'][] = array( |
|
547 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
548 | + $context['groups'][] = array( |
|
535 | 549 | 'id' => $row['id_group'], |
536 | 550 | 'name' => $row['group_name'] |
537 | 551 | ); |
552 | + } |
|
538 | 553 | $smcFunc['db_free_result']($result); |
539 | 554 | |
540 | 555 | $request = $smcFunc['db_query']('', ' |
@@ -551,12 +566,13 @@ discard block |
||
551 | 566 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
552 | 567 | { |
553 | 568 | // This category hasn't been set up yet.. |
554 | - if (!isset($context['categories'][$row['id_cat']])) |
|
555 | - $context['categories'][$row['id_cat']] = array( |
|
569 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
570 | + $context['categories'][$row['id_cat']] = array( |
|
556 | 571 | 'id' => $row['id_cat'], |
557 | 572 | 'name' => $row['cat_name'], |
558 | 573 | 'boards' => array() |
559 | 574 | ); |
575 | + } |
|
560 | 576 | |
561 | 577 | // Set this board up, and let the template know when it's a child. (indent them..) |
562 | 578 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
@@ -603,8 +619,9 @@ discard block |
||
603 | 619 | require_once($sourcedir . '/Subs-Membergroups.php'); |
604 | 620 | $result = deleteMembergroups((int) $_REQUEST['group']); |
605 | 621 | // Need to throw a warning if it went wrong, but this is the only one we have a message for... |
606 | - if ($result === 'group_cannot_delete_sub') |
|
607 | - fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
622 | + if ($result === 'group_cannot_delete_sub') { |
|
623 | + fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
624 | + } |
|
608 | 625 | |
609 | 626 | // Go back to the membergroup index. |
610 | 627 | redirectexit('action=admin;area=membergroups;'); |
@@ -626,8 +643,9 @@ discard block |
||
626 | 643 | |
627 | 644 | $_REQUEST['group'] = isset($_REQUEST['group']) && $_REQUEST['group'] > 0 ? (int) $_REQUEST['group'] : 0; |
628 | 645 | |
629 | - if (!empty($modSettings['deny_boards_access'])) |
|
630 | - loadLanguage('ManagePermissions'); |
|
646 | + if (!empty($modSettings['deny_boards_access'])) { |
|
647 | + loadLanguage('ManagePermissions'); |
|
648 | + } |
|
631 | 649 | |
632 | 650 | // Make sure this group is editable. |
633 | 651 | if (!empty($_REQUEST['group'])) |
@@ -649,8 +667,9 @@ discard block |
||
649 | 667 | } |
650 | 668 | |
651 | 669 | // Now, do we have a valid id? |
652 | - if (empty($_REQUEST['group'])) |
|
653 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
670 | + if (empty($_REQUEST['group'])) { |
|
671 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
672 | + } |
|
654 | 673 | |
655 | 674 | // People who can manage boards are a bit special. |
656 | 675 | require_once($sourcedir . '/Subs-Members.php'); |
@@ -681,8 +700,9 @@ discard block |
||
681 | 700 | require_once($sourcedir . '/Subs-Membergroups.php'); |
682 | 701 | $result = deleteMembergroups($_REQUEST['group']); |
683 | 702 | // Need to throw a warning if it went wrong, but this is the only one we have a message for... |
684 | - if ($result === 'group_cannot_delete_sub') |
|
685 | - fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
703 | + if ($result === 'group_cannot_delete_sub') { |
|
704 | + fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
705 | + } |
|
686 | 706 | |
687 | 707 | redirectexit('action=admin;area=membergroups;'); |
688 | 708 | } |
@@ -759,16 +779,18 @@ discard block |
||
759 | 779 | $request = $smcFunc['db_query']('', ' |
760 | 780 | SELECT id_board |
761 | 781 | FROM {db_prefix}boards'); |
762 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
763 | - $accesses[(int) $row['id_board']] = 'allow'; |
|
782 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
783 | + $accesses[(int) $row['id_board']] = 'allow'; |
|
784 | + } |
|
764 | 785 | $smcFunc['db_free_result']($request); |
765 | 786 | } |
766 | 787 | |
767 | 788 | $changed_boards['allow'] = array(); |
768 | 789 | $changed_boards['deny'] = array(); |
769 | 790 | $changed_boards['ignore'] = array(); |
770 | - foreach ($accesses as $group_id => $action) |
|
771 | - $changed_boards[$action][] = (int) $group_id; |
|
791 | + foreach ($accesses as $group_id => $action) { |
|
792 | + $changed_boards[$action][] = (int) $group_id; |
|
793 | + } |
|
772 | 794 | |
773 | 795 | foreach (array('allow', 'deny') as $board_action) |
774 | 796 | { |
@@ -784,8 +806,8 @@ discard block |
||
784 | 806 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
785 | 807 | ) |
786 | 808 | ); |
787 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
788 | - $smcFunc['db_query']('', ' |
|
809 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
810 | + $smcFunc['db_query']('', ' |
|
789 | 811 | UPDATE {db_prefix}boards |
790 | 812 | SET {raw:column} = {string:member_group_access} |
791 | 813 | WHERE id_board = {int:current_board}', |
@@ -795,11 +817,12 @@ discard block |
||
795 | 817 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
796 | 818 | ) |
797 | 819 | ); |
820 | + } |
|
798 | 821 | $smcFunc['db_free_result']($request); |
799 | 822 | |
800 | 823 | // Add the membergroup to all boards that hadn't been set yet. |
801 | - if (!empty($changed_boards[$board_action])) |
|
802 | - $smcFunc['db_query']('', ' |
|
824 | + if (!empty($changed_boards[$board_action])) { |
|
825 | + $smcFunc['db_query']('', ' |
|
803 | 826 | UPDATE {db_prefix}boards |
804 | 827 | SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END |
805 | 828 | WHERE id_board IN ({array_int:board_list}) |
@@ -813,6 +836,7 @@ discard block |
||
813 | 836 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
814 | 837 | ) |
815 | 838 | ); |
839 | + } |
|
816 | 840 | } |
817 | 841 | } |
818 | 842 | |
@@ -838,12 +862,14 @@ discard block |
||
838 | 862 | ) |
839 | 863 | ); |
840 | 864 | $updates = array(); |
841 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
842 | - $updates[$row['additional_groups']][] = $row['id_member']; |
|
865 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
866 | + $updates[$row['additional_groups']][] = $row['id_member']; |
|
867 | + } |
|
843 | 868 | $smcFunc['db_free_result']($request); |
844 | 869 | |
845 | - foreach ($updates as $additional_groups => $memberArray) |
|
846 | - updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group']))))); |
|
870 | + foreach ($updates as $additional_groups => $memberArray) { |
|
871 | + updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group']))))); |
|
872 | + } |
|
847 | 873 | |
848 | 874 | // Sorry, but post groups can't moderate boards |
849 | 875 | $smcFunc['db_query']('', ' |
@@ -853,8 +879,7 @@ discard block |
||
853 | 879 | 'current_group' => (int) $_REQUEST['group'], |
854 | 880 | ) |
855 | 881 | ); |
856 | - } |
|
857 | - elseif ($_REQUEST['group'] != 3) |
|
882 | + } elseif ($_REQUEST['group'] != 3) |
|
858 | 883 | { |
859 | 884 | // Making it a hidden group? If so remove everyone with it as primary group (Actually, just make them additional). |
860 | 885 | if ($_POST['group_hidden'] == 2) |
@@ -869,8 +894,9 @@ discard block |
||
869 | 894 | ) |
870 | 895 | ); |
871 | 896 | $updates = array(); |
872 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
873 | - $updates[$row['additional_groups']][] = $row['id_member']; |
|
897 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
898 | + $updates[$row['additional_groups']][] = $row['id_member']; |
|
899 | + } |
|
874 | 900 | $smcFunc['db_free_result']($request); |
875 | 901 | |
876 | 902 | foreach ($updates as $additional_groups => $memberArray) |
@@ -912,8 +938,9 @@ discard block |
||
912 | 938 | $smcFunc['db_free_result']($request); |
913 | 939 | |
914 | 940 | // Do we need to update the setting? |
915 | - if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable)) |
|
916 | - updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0)); |
|
941 | + if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable)) { |
|
942 | + updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0)); |
|
943 | + } |
|
917 | 944 | } |
918 | 945 | |
919 | 946 | // Do we need to set inherited permissions? |
@@ -946,8 +973,9 @@ discard block |
||
946 | 973 | { |
947 | 974 | $moderators[$k] = trim($moderators[$k]); |
948 | 975 | |
949 | - if (strlen($moderators[$k]) == 0) |
|
950 | - unset($moderators[$k]); |
|
976 | + if (strlen($moderators[$k]) == 0) { |
|
977 | + unset($moderators[$k]); |
|
978 | + } |
|
951 | 979 | } |
952 | 980 | |
953 | 981 | // Find all the id_member's for the member_name's in the list. |
@@ -963,8 +991,9 @@ discard block |
||
963 | 991 | 'count' => count($moderators), |
964 | 992 | ) |
965 | 993 | ); |
966 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
967 | - $group_moderators[] = $row['id_member']; |
|
994 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
995 | + $group_moderators[] = $row['id_member']; |
|
996 | + } |
|
968 | 997 | $smcFunc['db_free_result']($request); |
969 | 998 | } |
970 | 999 | } |
@@ -972,8 +1001,9 @@ discard block |
||
972 | 1001 | if (!empty($_POST['moderator_list'])) |
973 | 1002 | { |
974 | 1003 | $moderators = array(); |
975 | - foreach ($_POST['moderator_list'] as $moderator) |
|
976 | - $moderators[] = (int) $moderator; |
|
1004 | + foreach ($_POST['moderator_list'] as $moderator) { |
|
1005 | + $moderators[] = (int) $moderator; |
|
1006 | + } |
|
977 | 1007 | |
978 | 1008 | if (!empty($moderators)) |
979 | 1009 | { |
@@ -987,8 +1017,9 @@ discard block |
||
987 | 1017 | 'num_moderators' => count($moderators), |
988 | 1018 | ) |
989 | 1019 | ); |
990 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
991 | - $group_moderators[] = $row['id_member']; |
|
1020 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1021 | + $group_moderators[] = $row['id_member']; |
|
1022 | + } |
|
992 | 1023 | $smcFunc['db_free_result']($request); |
993 | 1024 | } |
994 | 1025 | } |
@@ -1000,8 +1031,9 @@ discard block |
||
1000 | 1031 | if (!empty($group_moderators)) |
1001 | 1032 | { |
1002 | 1033 | $mod_insert = array(); |
1003 | - foreach ($group_moderators as $moderator) |
|
1004 | - $mod_insert[] = array($_REQUEST['group'], $moderator); |
|
1034 | + foreach ($group_moderators as $moderator) { |
|
1035 | + $mod_insert[] = array($_REQUEST['group'], $moderator); |
|
1036 | + } |
|
1005 | 1037 | |
1006 | 1038 | $smcFunc['db_insert']('insert', |
1007 | 1039 | '{db_prefix}group_moderators', |
@@ -1035,8 +1067,9 @@ discard block |
||
1035 | 1067 | 'current_group' => (int) $_REQUEST['group'], |
1036 | 1068 | ) |
1037 | 1069 | ); |
1038 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
1039 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
1070 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
1071 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
1072 | + } |
|
1040 | 1073 | $row = $smcFunc['db_fetch_assoc']($request); |
1041 | 1074 | $smcFunc['db_free_result']($request); |
1042 | 1075 | |
@@ -1073,14 +1106,16 @@ discard block |
||
1073 | 1106 | ) |
1074 | 1107 | ); |
1075 | 1108 | $context['group']['moderators'] = array(); |
1076 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1077 | - $context['group']['moderators'][$row['id_member']] = $row['real_name']; |
|
1109 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1110 | + $context['group']['moderators'][$row['id_member']] = $row['real_name']; |
|
1111 | + } |
|
1078 | 1112 | $smcFunc['db_free_result']($request); |
1079 | 1113 | |
1080 | 1114 | $context['group']['moderator_list'] = empty($context['group']['moderators']) ? '' : '"' . implode('", "', $context['group']['moderators']) . '"'; |
1081 | 1115 | |
1082 | - if (!empty($context['group']['moderators'])) |
|
1083 | - list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1); |
|
1116 | + if (!empty($context['group']['moderators'])) { |
|
1117 | + list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1); |
|
1118 | + } |
|
1084 | 1119 | |
1085 | 1120 | // Get a list of boards this membergroup is allowed to see. |
1086 | 1121 | $context['boards'] = array(); |
@@ -1100,12 +1135,13 @@ discard block |
||
1100 | 1135 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1101 | 1136 | { |
1102 | 1137 | // This category hasn't been set up yet.. |
1103 | - if (!isset($context['categories'][$row['id_cat']])) |
|
1104 | - $context['categories'][$row['id_cat']] = array( |
|
1138 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
1139 | + $context['categories'][$row['id_cat']] = array( |
|
1105 | 1140 | 'id' => $row['id_cat'], |
1106 | 1141 | 'name' => $row['cat_name'], |
1107 | 1142 | 'boards' => array() |
1108 | 1143 | ); |
1144 | + } |
|
1109 | 1145 | |
1110 | 1146 | // Set this board up, and let the template know when it's a child. (indent them..) |
1111 | 1147 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
@@ -1147,14 +1183,16 @@ discard block |
||
1147 | 1183 | $ext = pathinfo($settings['default_theme_dir'] . '/images/membericons/' . $value, PATHINFO_EXTENSION); |
1148 | 1184 | |
1149 | 1185 | // If the extension is not empty, and it is valid |
1150 | - if (!empty($ext) && in_array($ext, $imageExts)) |
|
1151 | - $context['possible_icons'][] = $value; |
|
1186 | + if (!empty($ext) && in_array($ext, $imageExts)) { |
|
1187 | + $context['possible_icons'][] = $value; |
|
1188 | + } |
|
1152 | 1189 | } |
1153 | 1190 | } |
1154 | 1191 | |
1155 | 1192 | // Insert our JS, if we have possible icons. |
1156 | - if (!empty($context['possible_icons'])) |
|
1157 | - loadJavaScriptFile('icondropdown.js', array('validate' => true, 'minimize' => true), 'smf_icondropdown'); |
|
1193 | + if (!empty($context['possible_icons'])) { |
|
1194 | + loadJavaScriptFile('icondropdown.js', array('validate' => true, 'minimize' => true), 'smf_icondropdown'); |
|
1195 | + } |
|
1158 | 1196 | |
1159 | 1197 | loadJavaScriptFile('suggest.js', array('defer' => false, 'minimize' => true), 'smf_suggest'); |
1160 | 1198 | |
@@ -1176,8 +1214,9 @@ discard block |
||
1176 | 1214 | ) |
1177 | 1215 | ); |
1178 | 1216 | $context['inheritable_groups'] = array(); |
1179 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1180 | - $context['inheritable_groups'][$row['id_group']] = $row['group_name']; |
|
1217 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1218 | + $context['inheritable_groups'][$row['id_group']] = $row['group_name']; |
|
1219 | + } |
|
1181 | 1220 | $smcFunc['db_free_result']($request); |
1182 | 1221 | |
1183 | 1222 | call_integration_hook('integrate_view_membergroup'); |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * The main dispatcher; doesn't do anything, just delegates. |
@@ -92,18 +93,19 @@ discard block |
||
92 | 93 | checkSession('get'); |
93 | 94 | validateToken('admin-bm-' . (int) $_REQUEST['src_board'], 'request'); |
94 | 95 | |
95 | - if ($_REQUEST['move_to'] === 'top') |
|
96 | - $boardOptions = array( |
|
96 | + if ($_REQUEST['move_to'] === 'top') { |
|
97 | + $boardOptions = array( |
|
97 | 98 | 'move_to' => $_REQUEST['move_to'], |
98 | 99 | 'target_category' => (int) $_REQUEST['target_cat'], |
99 | 100 | 'move_first_child' => true, |
100 | 101 | ); |
101 | - else |
|
102 | - $boardOptions = array( |
|
102 | + } else { |
|
103 | + $boardOptions = array( |
|
103 | 104 | 'move_to' => $_REQUEST['move_to'], |
104 | 105 | 'target_board' => (int) $_REQUEST['target_board'], |
105 | 106 | 'move_first_child' => true, |
106 | 107 | ); |
108 | + } |
|
107 | 109 | modifyBoard((int) $_REQUEST['src_board'], $boardOptions); |
108 | 110 | } |
109 | 111 | |
@@ -148,15 +150,16 @@ discard block |
||
148 | 150 | $security = $context['session_var'] . '=' . $context['session_id'] . ';' . $context['admin-bm-' . $context['move_board'] . '_token_var'] . '=' . $context['admin-bm-' . $context['move_board'] . '_token']; |
149 | 151 | foreach ($boardList[$catid] as $boardid) |
150 | 152 | { |
151 | - if (!isset($context['categories'][$catid]['move_link'])) |
|
152 | - $context['categories'][$catid]['move_link'] = array( |
|
153 | + if (!isset($context['categories'][$catid]['move_link'])) { |
|
154 | + $context['categories'][$catid]['move_link'] = array( |
|
153 | 155 | 'child_level' => 0, |
154 | 156 | 'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'', |
155 | 157 | 'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_board=' . $boardid . ';move_to=before;' . $security, |
156 | 158 | ); |
159 | + } |
|
157 | 160 | |
158 | - if (!$context['categories'][$catid]['boards'][$boardid]['move']) |
|
159 | - $context['categories'][$catid]['boards'][$boardid]['move_links'] = array( |
|
161 | + if (!$context['categories'][$catid]['boards'][$boardid]['move']) { |
|
162 | + $context['categories'][$catid]['boards'][$boardid]['move_links'] = array( |
|
160 | 163 | array( |
161 | 164 | 'child_level' => $boards[$boardid]['level'], |
162 | 165 | 'label' => $txt['mboards_order_after'] . '\'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'', |
@@ -170,33 +173,38 @@ discard block |
||
170 | 173 | 'class' => 'here', |
171 | 174 | ), |
172 | 175 | ); |
176 | + } |
|
173 | 177 | |
174 | 178 | $difference = $boards[$boardid]['level'] - $prev_child_level; |
175 | - if ($difference == 1) |
|
176 | - array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null); |
|
177 | - elseif ($difference < 0) |
|
179 | + if ($difference == 1) { |
|
180 | + array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null); |
|
181 | + } elseif ($difference < 0) |
|
178 | 182 | { |
179 | - if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) |
|
180 | - $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array(); |
|
181 | - for ($i = 0; $i < -$difference; $i++) |
|
182 | - if (($temp = array_pop($stack)) != null) |
|
183 | + if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) { |
|
184 | + $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array(); |
|
185 | + } |
|
186 | + for ($i = 0; $i < -$difference; $i++) { |
|
187 | + if (($temp = array_pop($stack)) != null) |
|
183 | 188 | array_unshift($context['categories'][$catid]['boards'][$prev_board]['move_links'], $temp); |
189 | + } |
|
184 | 190 | } |
185 | 191 | |
186 | 192 | $prev_board = $boardid; |
187 | 193 | $prev_child_level = $boards[$boardid]['level']; |
188 | 194 | } |
189 | - if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) |
|
190 | - $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']); |
|
191 | - elseif (!empty($stack)) |
|
192 | - $context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack; |
|
195 | + if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) { |
|
196 | + $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']); |
|
197 | + } elseif (!empty($stack)) { |
|
198 | + $context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack; |
|
199 | + } |
|
193 | 200 | |
194 | - if (empty($boardList[$catid])) |
|
195 | - $context['categories'][$catid]['move_link'] = array( |
|
201 | + if (empty($boardList[$catid])) { |
|
202 | + $context['categories'][$catid]['move_link'] = array( |
|
196 | 203 | 'child_level' => 0, |
197 | 204 | 'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($tree['node']['name']) . '\'', |
198 | 205 | 'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_cat=' . $catid . ';move_to=top;' . $security, |
199 | 206 | ); |
207 | + } |
|
200 | 208 | } |
201 | 209 | } |
202 | 210 | |
@@ -252,9 +260,9 @@ discard block |
||
252 | 260 | ); |
253 | 261 | } |
254 | 262 | // Category doesn't exist, man... sorry. |
255 | - elseif (!isset($cat_tree[$_REQUEST['cat']])) |
|
256 | - redirectexit('action=admin;area=manageboards'); |
|
257 | - else |
|
263 | + elseif (!isset($cat_tree[$_REQUEST['cat']])) { |
|
264 | + redirectexit('action=admin;area=manageboards'); |
|
265 | + } else |
|
258 | 266 | { |
259 | 267 | $context['category'] = array( |
260 | 268 | 'id' => $_REQUEST['cat'], |
@@ -266,30 +274,31 @@ discard block |
||
266 | 274 | 'is_empty' => empty($cat_tree[$_REQUEST['cat']]['children']) |
267 | 275 | ); |
268 | 276 | |
269 | - foreach ($boardList[$_REQUEST['cat']] as $child_board) |
|
270 | - $context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name']; |
|
277 | + foreach ($boardList[$_REQUEST['cat']] as $child_board) { |
|
278 | + $context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name']; |
|
279 | + } |
|
271 | 280 | } |
272 | 281 | |
273 | 282 | $prevCat = 0; |
274 | 283 | foreach ($cat_tree as $catid => $tree) |
275 | 284 | { |
276 | - if ($catid == $_REQUEST['cat'] && $prevCat > 0) |
|
277 | - $context['category_order'][$prevCat]['selected'] = true; |
|
278 | - elseif ($catid != $_REQUEST['cat']) |
|
279 | - $context['category_order'][$catid] = array( |
|
285 | + if ($catid == $_REQUEST['cat'] && $prevCat > 0) { |
|
286 | + $context['category_order'][$prevCat]['selected'] = true; |
|
287 | + } elseif ($catid != $_REQUEST['cat']) { |
|
288 | + $context['category_order'][$catid] = array( |
|
280 | 289 | 'id' => $catid, |
281 | 290 | 'name' => $txt['mboards_order_after'] . $tree['node']['name'], |
282 | 291 | 'selected' => false, |
283 | 292 | 'true_name' => $tree['node']['name'] |
284 | 293 | ); |
294 | + } |
|
285 | 295 | $prevCat = $catid; |
286 | 296 | } |
287 | 297 | if (!isset($_REQUEST['delete'])) |
288 | 298 | { |
289 | 299 | $context['sub_template'] = 'modify_category'; |
290 | 300 | $context['page_title'] = $_REQUEST['sa'] == 'newcat' ? $txt['mboards_new_cat_name'] : $txt['catEdit']; |
291 | - } |
|
292 | - else |
|
301 | + } else |
|
293 | 302 | { |
294 | 303 | $context['sub_template'] = 'confirm_category_delete'; |
295 | 304 | $context['page_title'] = $txt['mboards_delete_cat']; |
@@ -326,8 +335,9 @@ discard block |
||
326 | 335 | { |
327 | 336 | $catOptions = array(); |
328 | 337 | |
329 | - if (isset($_POST['cat_order'])) |
|
330 | - $catOptions['move_after'] = (int) $_POST['cat_order']; |
|
338 | + if (isset($_POST['cat_order'])) { |
|
339 | + $catOptions['move_after'] = (int) $_POST['cat_order']; |
|
340 | + } |
|
331 | 341 | |
332 | 342 | // Change "This & That" to "This & That" but don't change "¢" to "&cent;"... |
333 | 343 | $catOptions['cat_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['cat_name']), false, '', $context['description_allowed_tags']); |
@@ -335,10 +345,11 @@ discard block |
||
335 | 345 | |
336 | 346 | $catOptions['is_collapsible'] = isset($_POST['collapse']); |
337 | 347 | |
338 | - if (isset($_POST['add'])) |
|
339 | - createCategory($catOptions); |
|
340 | - else |
|
341 | - modifyCategory($_POST['cat'], $catOptions); |
|
348 | + if (isset($_POST['add'])) { |
|
349 | + createCategory($catOptions); |
|
350 | + } else { |
|
351 | + modifyCategory($_POST['cat'], $catOptions); |
|
352 | + } |
|
342 | 353 | } |
343 | 354 | // If they want to delete - first give them confirmation. |
344 | 355 | elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['empty'])) |
@@ -352,13 +363,14 @@ discard block |
||
352 | 363 | // First off - check if we are moving all the current boards first - before we start deleting! |
353 | 364 | if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1) |
354 | 365 | { |
355 | - if (empty($_POST['cat_to'])) |
|
356 | - fatal_lang_error('mboards_delete_error'); |
|
366 | + if (empty($_POST['cat_to'])) { |
|
367 | + fatal_lang_error('mboards_delete_error'); |
|
368 | + } |
|
357 | 369 | |
358 | 370 | deleteCategories(array($_POST['cat']), (int) $_POST['cat_to']); |
371 | + } else { |
|
372 | + deleteCategories(array($_POST['cat'])); |
|
359 | 373 | } |
360 | - else |
|
361 | - deleteCategories(array($_POST['cat'])); |
|
362 | 374 | } |
363 | 375 | |
364 | 376 | redirectexit('action=admin;area=manageboards'); |
@@ -403,8 +415,9 @@ discard block |
||
403 | 415 | if ($_REQUEST['sa'] == 'newboard') |
404 | 416 | { |
405 | 417 | // Category doesn't exist, man... sorry. |
406 | - if (empty($_REQUEST['cat'])) |
|
407 | - redirectexit('action=admin;area=manageboards'); |
|
418 | + if (empty($_REQUEST['cat'])) { |
|
419 | + redirectexit('action=admin;area=manageboards'); |
|
420 | + } |
|
408 | 421 | |
409 | 422 | // Some things that need to be setup for a new board. |
410 | 423 | $curBoard = array( |
@@ -428,8 +441,7 @@ discard block |
||
428 | 441 | 'category' => (int) $_REQUEST['cat'], |
429 | 442 | 'no_children' => true, |
430 | 443 | ); |
431 | - } |
|
432 | - else |
|
444 | + } else |
|
433 | 445 | { |
434 | 446 | // Just some easy shortcuts. |
435 | 447 | $curBoard = &$boards[$_REQUEST['boardid']]; |
@@ -477,8 +489,9 @@ discard block |
||
477 | 489 | ); |
478 | 490 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
479 | 491 | { |
480 | - if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1) |
|
481 | - $curBoard['member_groups'][] = $row['id_group']; |
|
492 | + if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1) { |
|
493 | + $curBoard['member_groups'][] = $row['id_group']; |
|
494 | + } |
|
482 | 495 | |
483 | 496 | $context['groups'][(int) $row['id_group']] = array( |
484 | 497 | 'id' => $row['id_group'], |
@@ -491,8 +504,9 @@ discard block |
||
491 | 504 | $smcFunc['db_free_result']($request); |
492 | 505 | |
493 | 506 | // Category doesn't exist, man... sorry. |
494 | - if (!isset($boardList[$curBoard['category']])) |
|
495 | - redirectexit('action=admin;area=manageboards'); |
|
507 | + if (!isset($boardList[$curBoard['category']])) { |
|
508 | + redirectexit('action=admin;area=manageboards'); |
|
509 | + } |
|
496 | 510 | |
497 | 511 | foreach ($boardList[$curBoard['category']] as $boardid) |
498 | 512 | { |
@@ -506,8 +520,7 @@ discard block |
||
506 | 520 | 'is_child' => false, |
507 | 521 | 'selected' => true |
508 | 522 | ); |
509 | - } |
|
510 | - else |
|
523 | + } else |
|
511 | 524 | { |
512 | 525 | $context['board_order'][] = array( |
513 | 526 | 'id' => $boardid, |
@@ -524,19 +537,21 @@ discard block |
||
524 | 537 | $context['can_move_children'] = false; |
525 | 538 | $context['children'] = $boards[$_REQUEST['boardid']]['tree']['children']; |
526 | 539 | |
527 | - foreach ($context['board_order'] as $lBoard) |
|
528 | - if ($lBoard['is_child'] == false && $lBoard['selected'] == false) |
|
540 | + foreach ($context['board_order'] as $lBoard) { |
|
541 | + if ($lBoard['is_child'] == false && $lBoard['selected'] == false) |
|
529 | 542 | $context['can_move_children'] = true; |
543 | + } |
|
530 | 544 | } |
531 | 545 | |
532 | 546 | // Get other available categories. |
533 | 547 | $context['categories'] = array(); |
534 | - foreach ($cat_tree as $catID => $tree) |
|
535 | - $context['categories'][] = array( |
|
548 | + foreach ($cat_tree as $catID => $tree) { |
|
549 | + $context['categories'][] = array( |
|
536 | 550 | 'id' => $catID == $curBoard['category'] ? 0 : $catID, |
537 | 551 | 'name' => $tree['node']['name'], |
538 | 552 | 'selected' => $catID == $curBoard['category'] |
539 | 553 | ); |
554 | + } |
|
540 | 555 | |
541 | 556 | $request = $smcFunc['db_query']('', ' |
542 | 557 | SELECT mem.id_member, mem.real_name |
@@ -548,14 +563,16 @@ discard block |
||
548 | 563 | ) |
549 | 564 | ); |
550 | 565 | $context['board']['moderators'] = array(); |
551 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
552 | - $context['board']['moderators'][$row['id_member']] = $row['real_name']; |
|
566 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
567 | + $context['board']['moderators'][$row['id_member']] = $row['real_name']; |
|
568 | + } |
|
553 | 569 | $smcFunc['db_free_result']($request); |
554 | 570 | |
555 | 571 | $context['board']['moderator_list'] = empty($context['board']['moderators']) ? '' : '"' . implode('", "', $context['board']['moderators']) . '"'; |
556 | 572 | |
557 | - if (!empty($context['board']['moderators'])) |
|
558 | - list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1); |
|
573 | + if (!empty($context['board']['moderators'])) { |
|
574 | + list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1); |
|
575 | + } |
|
559 | 576 | |
560 | 577 | // Get all the groups assigned as moderators |
561 | 578 | $request = $smcFunc['db_query']('', ' |
@@ -567,14 +584,16 @@ discard block |
||
567 | 584 | ) |
568 | 585 | ); |
569 | 586 | $context['board']['moderator_groups'] = array(); |
570 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
571 | - $context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name']; |
|
587 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
588 | + $context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name']; |
|
589 | + } |
|
572 | 590 | $smcFunc['db_free_result']($request); |
573 | 591 | |
574 | 592 | $context['board']['moderator_groups_list'] = empty($context['board']['moderator_groups']) ? '' : '"' . implode('", &qout;', $context['board']['moderator_groups']) . '"'; |
575 | 593 | |
576 | - if (!empty($context['board']['moderator_groups'])) |
|
577 | - list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1); |
|
594 | + if (!empty($context['board']['moderator_groups'])) { |
|
595 | + list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1); |
|
596 | + } |
|
578 | 597 | |
579 | 598 | // Get all the themes... |
580 | 599 | $request = $smcFunc['db_query']('', ' |
@@ -586,8 +605,9 @@ discard block |
||
586 | 605 | ) |
587 | 606 | ); |
588 | 607 | $context['themes'] = array(); |
589 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
590 | - $context['themes'][] = $row; |
|
608 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
609 | + $context['themes'][] = $row; |
|
610 | + } |
|
591 | 611 | $smcFunc['db_free_result']($request); |
592 | 612 | |
593 | 613 | if (!isset($_REQUEST['delete'])) |
@@ -595,8 +615,7 @@ discard block |
||
595 | 615 | $context['sub_template'] = 'modify_board'; |
596 | 616 | $context['page_title'] = $txt['boardsEdit']; |
597 | 617 | loadJavaScriptFile('suggest.js', array('defer' => false, 'minimize' => true), 'smf_suggest'); |
598 | - } |
|
599 | - else |
|
618 | + } else |
|
600 | 619 | { |
601 | 620 | $context['sub_template'] = 'confirm_board_delete'; |
602 | 621 | $context['page_title'] = $txt['mboards_delete_board']; |
@@ -640,8 +659,9 @@ discard block |
||
640 | 659 | // Change the boardorder of this board? |
641 | 660 | elseif (!empty($_POST['placement']) && !empty($_POST['board_order'])) |
642 | 661 | { |
643 | - if (!in_array($_POST['placement'], array('before', 'after', 'child'))) |
|
644 | - fatal_lang_error('mangled_post', false); |
|
662 | + if (!in_array($_POST['placement'], array('before', 'after', 'child'))) { |
|
663 | + fatal_lang_error('mangled_post', false); |
|
664 | + } |
|
645 | 665 | |
646 | 666 | $boardOptions['move_to'] = $_POST['placement']; |
647 | 667 | $boardOptions['target_board'] = (int) $_POST['board_order']; |
@@ -654,13 +674,14 @@ discard block |
||
654 | 674 | $boardOptions['access_groups'] = array(); |
655 | 675 | $boardOptions['deny_groups'] = array(); |
656 | 676 | |
657 | - if (!empty($_POST['groups'])) |
|
658 | - foreach ($_POST['groups'] as $group => $action) |
|
677 | + if (!empty($_POST['groups'])) { |
|
678 | + foreach ($_POST['groups'] as $group => $action) |
|
659 | 679 | { |
660 | 680 | if ($action == 'allow') |
661 | 681 | $boardOptions['access_groups'][] = (int) $group; |
662 | - elseif ($action == 'deny') |
|
663 | - $boardOptions['deny_groups'][] = (int) $group; |
|
682 | + } elseif ($action == 'deny') { |
|
683 | + $boardOptions['deny_groups'][] = (int) $group; |
|
684 | + } |
|
664 | 685 | } |
665 | 686 | |
666 | 687 | // People with manage-boards are special. |
@@ -672,8 +693,9 @@ discard block |
||
672 | 693 | // Secondly, make sure those with super cow powers (like apt-get, or in this case manage boards) are upgraded. |
673 | 694 | $boardOptions['access_groups'] = array_unique(array_merge($boardOptions['access_groups'], $board_managers)); |
674 | 695 | |
675 | - if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255) |
|
676 | - fatal_lang_error('too_many_groups', false); |
|
696 | + if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255) { |
|
697 | + fatal_lang_error('too_many_groups', false); |
|
698 | + } |
|
677 | 699 | |
678 | 700 | // Do not allow HTML tags. Parse the string. |
679 | 701 | $boardOptions['board_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['board_name']), false, '', $context['description_allowed_tags']); |
@@ -684,8 +706,9 @@ discard block |
||
684 | 706 | if (isset($_POST['moderator_list']) && is_array($_POST['moderator_list'])) |
685 | 707 | { |
686 | 708 | $moderators = array(); |
687 | - foreach ($_POST['moderator_list'] as $moderator) |
|
688 | - $moderators[(int) $moderator] = (int) $moderator; |
|
709 | + foreach ($_POST['moderator_list'] as $moderator) { |
|
710 | + $moderators[(int) $moderator] = (int) $moderator; |
|
711 | + } |
|
689 | 712 | $boardOptions['moderators'] = $moderators; |
690 | 713 | } |
691 | 714 | |
@@ -694,8 +717,9 @@ discard block |
||
694 | 717 | if (isset($_POST['moderator_group_list']) && is_array($_POST['moderator_group_list'])) |
695 | 718 | { |
696 | 719 | $moderator_groups = array(); |
697 | - foreach ($_POST['moderator_group_list'] as $moderator_group) |
|
698 | - $moderator_groups[(int) $moderator_group] = (int) $moderator_group; |
|
720 | + foreach ($_POST['moderator_group_list'] as $moderator_group) { |
|
721 | + $moderator_groups[(int) $moderator_group] = (int) $moderator_group; |
|
722 | + } |
|
699 | 723 | $boardOptions['moderator_groups'] = $moderator_groups; |
700 | 724 | } |
701 | 725 | |
@@ -721,56 +745,62 @@ discard block |
||
721 | 745 | $smcFunc['db_free_result']($request); |
722 | 746 | |
723 | 747 | // If we're turning redirection on check the board doesn't have posts in it - if it does don't make it a redirection board. |
724 | - if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts) |
|
725 | - unset($boardOptions['redirect']); |
|
748 | + if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts) { |
|
749 | + unset($boardOptions['redirect']); |
|
750 | + } |
|
726 | 751 | // Reset the redirection count when switching on/off. |
727 | - elseif (empty($boardOptions['redirect']) != empty($oldRedirect)) |
|
728 | - $boardOptions['num_posts'] = 0; |
|
752 | + elseif (empty($boardOptions['redirect']) != empty($oldRedirect)) { |
|
753 | + $boardOptions['num_posts'] = 0; |
|
754 | + } |
|
729 | 755 | // Resetting the count? |
730 | - elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect'])) |
|
731 | - $boardOptions['num_posts'] = 0; |
|
756 | + elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect'])) { |
|
757 | + $boardOptions['num_posts'] = 0; |
|
758 | + } |
|
732 | 759 | } |
733 | 760 | |
734 | 761 | // Create a new board... |
735 | 762 | if (isset($_POST['add'])) |
736 | 763 | { |
737 | 764 | // New boards by default go to the bottom of the category. |
738 | - if (empty($_POST['new_cat'])) |
|
739 | - $boardOptions['target_category'] = (int) $_POST['cur_cat']; |
|
740 | - if (!isset($boardOptions['move_to'])) |
|
741 | - $boardOptions['move_to'] = 'bottom'; |
|
765 | + if (empty($_POST['new_cat'])) { |
|
766 | + $boardOptions['target_category'] = (int) $_POST['cur_cat']; |
|
767 | + } |
|
768 | + if (!isset($boardOptions['move_to'])) { |
|
769 | + $boardOptions['move_to'] = 'bottom'; |
|
770 | + } |
|
742 | 771 | |
743 | 772 | createBoard($boardOptions); |
744 | 773 | } |
745 | 774 | |
746 | 775 | // ...or update an existing board. |
747 | - else |
|
748 | - modifyBoard($_POST['boardid'], $boardOptions); |
|
749 | - } |
|
750 | - elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children'])) |
|
776 | + else { |
|
777 | + modifyBoard($_POST['boardid'], $boardOptions); |
|
778 | + } |
|
779 | + } elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children'])) |
|
751 | 780 | { |
752 | 781 | EditBoard(); |
753 | 782 | return; |
754 | - } |
|
755 | - elseif (isset($_POST['delete'])) |
|
783 | + } elseif (isset($_POST['delete'])) |
|
756 | 784 | { |
757 | 785 | // First off - check if we are moving all the current child boards first - before we start deleting! |
758 | 786 | if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1) |
759 | 787 | { |
760 | - if (empty($_POST['board_to'])) |
|
761 | - fatal_lang_error('mboards_delete_board_error'); |
|
788 | + if (empty($_POST['board_to'])) { |
|
789 | + fatal_lang_error('mboards_delete_board_error'); |
|
790 | + } |
|
762 | 791 | |
763 | 792 | deleteBoards(array($_POST['boardid']), (int) $_POST['board_to']); |
793 | + } else { |
|
794 | + deleteBoards(array($_POST['boardid']), 0); |
|
764 | 795 | } |
765 | - else |
|
766 | - deleteBoards(array($_POST['boardid']), 0); |
|
767 | 796 | } |
768 | 797 | |
769 | - if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions') |
|
770 | - redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']); |
|
771 | - else |
|
772 | - redirectexit('action=admin;area=manageboards'); |
|
773 | -} |
|
798 | + if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions') { |
|
799 | + redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']); |
|
800 | + } else { |
|
801 | + redirectexit('action=admin;area=manageboards'); |
|
802 | + } |
|
803 | + } |
|
774 | 804 | |
775 | 805 | /** |
776 | 806 | * Used to retrieve data for modifying a board category |
@@ -807,8 +837,9 @@ discard block |
||
807 | 837 | $smcFunc['db_free_result']($request); |
808 | 838 | |
809 | 839 | // This would probably never happen, but just to be sure. |
810 | - if ($cat .= $allowed_sa[1]) |
|
811 | - die(str_replace(',', ' to', $cat)); |
|
840 | + if ($cat .= $allowed_sa[1]) { |
|
841 | + die(str_replace(',', ' to', $cat)); |
|
842 | + } |
|
812 | 843 | |
813 | 844 | redirectexit(); |
814 | 845 | } |
@@ -834,8 +865,9 @@ discard block |
||
834 | 865 | 'empty_string' => '', |
835 | 866 | ) |
836 | 867 | ); |
837 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
838 | - $recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name']; |
|
868 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
869 | + $recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name']; |
|
870 | + } |
|
839 | 871 | $smcFunc['db_free_result']($request); |
840 | 872 | |
841 | 873 | if (!empty($recycle_boards)) |
@@ -843,13 +875,14 @@ discard block |
||
843 | 875 | require_once($sourcedir . '/Subs-Boards.php'); |
844 | 876 | sortBoards($recycle_boards); |
845 | 877 | $recycle_boards = array('') + $recycle_boards; |
878 | + } else { |
|
879 | + $recycle_boards = array(''); |
|
846 | 880 | } |
847 | - else |
|
848 | - $recycle_boards = array(''); |
|
849 | 881 | |
850 | 882 | // If this setting is missing, set it to 1 |
851 | - if (empty($modSettings['boardindex_max_depth'])) |
|
852 | - $modSettings['boardindex_max_depth'] = 1; |
|
883 | + if (empty($modSettings['boardindex_max_depth'])) { |
|
884 | + $modSettings['boardindex_max_depth'] = 1; |
|
885 | + } |
|
853 | 886 | |
854 | 887 | // Here and the board settings... |
855 | 888 | $config_vars = array( |
@@ -868,8 +901,9 @@ discard block |
||
868 | 901 | |
869 | 902 | call_integration_hook('integrate_modify_board_settings', array(&$config_vars)); |
870 | 903 | |
871 | - if ($return_config) |
|
872 | - return $config_vars; |
|
904 | + if ($return_config) { |
|
905 | + return $config_vars; |
|
906 | + } |
|
873 | 907 | |
874 | 908 | // Needed for the settings template. |
875 | 909 | require_once($sourcedir . '/ManageServer.php'); |
@@ -17,8 +17,9 @@ discard block |
||
17 | 17 | * @version 2.1 Beta 4 |
18 | 18 | */ |
19 | 19 | |
20 | -if (!defined('SMF')) |
|
20 | +if (!defined('SMF')) { |
|
21 | 21 | die('No direct access...'); |
22 | +} |
|
22 | 23 | |
23 | 24 | /** |
24 | 25 | * Attempt to start the session, unless it already has been. |
@@ -38,8 +39,9 @@ discard block |
||
38 | 39 | { |
39 | 40 | $parsed_url = parse_url($boardurl); |
40 | 41 | |
41 | - if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
42 | - @ini_set('session.cookie_domain', '.' . $parts[1]); |
|
42 | + if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
43 | + @ini_set('session.cookie_domain', '.' . $parts[1]); |
|
44 | + } |
|
43 | 45 | } |
44 | 46 | // @todo Set the session cookie path? |
45 | 47 | |
@@ -47,8 +49,9 @@ discard block |
||
47 | 49 | if ((ini_get('session.auto_start') == 1 && !empty($modSettings['databaseSession_enable'])) || session_id() == '') |
48 | 50 | { |
49 | 51 | // Attempt to end the already-started session. |
50 | - if (ini_get('session.auto_start') == 1) |
|
51 | - session_write_close(); |
|
52 | + if (ini_get('session.auto_start') == 1) { |
|
53 | + session_write_close(); |
|
54 | + } |
|
52 | 55 | |
53 | 56 | // This is here to stop people from using bad junky PHPSESSIDs. |
54 | 57 | if (isset($_REQUEST[session_name()]) && preg_match('~^[A-Za-z0-9,-]{16,64}$~', $_REQUEST[session_name()]) == 0 && !isset($_COOKIE[session_name()])) |
@@ -63,23 +66,26 @@ discard block |
||
63 | 66 | if (!empty($modSettings['databaseSession_enable'])) |
64 | 67 | { |
65 | 68 | @ini_set('session.serialize_handler', 'php_serialize'); |
66 | - if (ini_get('session.serialize_handler') != 'php_serialize') |
|
67 | - @ini_set('session.serialize_handler', 'php'); |
|
69 | + if (ini_get('session.serialize_handler') != 'php_serialize') { |
|
70 | + @ini_set('session.serialize_handler', 'php'); |
|
71 | + } |
|
68 | 72 | session_set_save_handler('sessionOpen', 'sessionClose', 'sessionRead', 'sessionWrite', 'sessionDestroy', 'sessionGC'); |
69 | 73 | @ini_set('session.gc_probability', '1'); |
74 | + } elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) { |
|
75 | + @ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60)); |
|
70 | 76 | } |
71 | - elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) |
|
72 | - @ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60)); |
|
73 | 77 | |
74 | 78 | // Use cache setting sessions? |
75 | - if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') |
|
76 | - call_integration_hook('integrate_session_handlers'); |
|
79 | + if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') { |
|
80 | + call_integration_hook('integrate_session_handlers'); |
|
81 | + } |
|
77 | 82 | |
78 | 83 | session_start(); |
79 | 84 | |
80 | 85 | // Change it so the cache settings are a little looser than default. |
81 | - if (!empty($modSettings['databaseSession_loose'])) |
|
82 | - header('cache-control: private'); |
|
86 | + if (!empty($modSettings['databaseSession_loose'])) { |
|
87 | + header('cache-control: private'); |
|
88 | + } |
|
83 | 89 | } |
84 | 90 | |
85 | 91 | // Set the randomly generated code. |
@@ -125,8 +131,9 @@ discard block |
||
125 | 131 | { |
126 | 132 | global $smcFunc; |
127 | 133 | |
128 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
129 | - return ''; |
|
134 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
135 | + return ''; |
|
136 | + } |
|
130 | 137 | |
131 | 138 | // Look for it in the database. |
132 | 139 | $result = $smcFunc['db_query']('', ' |
@@ -156,8 +163,9 @@ discard block |
||
156 | 163 | global $smcFunc, $db_connection, $db_server, $db_name, $db_user, $db_passwd; |
157 | 164 | global $db_prefix, $db_persist, $db_port, $db_mb4; |
158 | 165 | |
159 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
160 | - return false; |
|
166 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
167 | + return false; |
|
168 | + } |
|
161 | 169 | |
162 | 170 | // php < 7.0 need this |
163 | 171 | if (empty($db_connection)) |
@@ -165,11 +173,13 @@ discard block |
||
165 | 173 | $db_options = array(); |
166 | 174 | |
167 | 175 | // Add in the port if needed |
168 | - if (!empty($db_port)) |
|
169 | - $db_options['port'] = $db_port; |
|
176 | + if (!empty($db_port)) { |
|
177 | + $db_options['port'] = $db_port; |
|
178 | + } |
|
170 | 179 | |
171 | - if (!empty($db_mb4)) |
|
172 | - $db_options['db_mb4'] = $db_mb4; |
|
180 | + if (!empty($db_mb4)) { |
|
181 | + $db_options['db_mb4'] = $db_mb4; |
|
182 | + } |
|
173 | 183 | |
174 | 184 | $options = array_merge($db_options, array('persist' => $db_persist, 'dont_select_db' => SMF == 'SSI')); |
175 | 185 | |
@@ -189,13 +199,14 @@ discard block |
||
189 | 199 | ); |
190 | 200 | |
191 | 201 | // If that didn't work, try inserting a new one. |
192 | - if ($smcFunc['db_affected_rows']() == 0) |
|
193 | - $smcFunc['db_insert']('ignore', |
|
202 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
203 | + $smcFunc['db_insert']('ignore', |
|
194 | 204 | '{db_prefix}sessions', |
195 | 205 | array('session_id' => 'string', 'data' => 'string', 'last_update' => 'int'), |
196 | 206 | array($session_id, $data, time()), |
197 | 207 | array('session_id') |
198 | 208 | ); |
209 | + } |
|
199 | 210 | |
200 | 211 | return ($smcFunc['db_affected_rows']() == 0 ? false : true); |
201 | 212 | } |
@@ -210,8 +221,9 @@ discard block |
||
210 | 221 | { |
211 | 222 | global $smcFunc; |
212 | 223 | |
213 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
214 | - return false; |
|
224 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
225 | + return false; |
|
226 | + } |
|
215 | 227 | |
216 | 228 | // Just delete the row... |
217 | 229 | $smcFunc['db_query']('', ' |
@@ -237,8 +249,9 @@ discard block |
||
237 | 249 | global $modSettings, $smcFunc; |
238 | 250 | |
239 | 251 | // Just set to the default or lower? Ignore it for a higher value. (hopefully) |
240 | - if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) |
|
241 | - $max_lifetime = max($modSettings['databaseSession_lifetime'], 60); |
|
252 | + if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) { |
|
253 | + $max_lifetime = max($modSettings['databaseSession_lifetime'], 60); |
|
254 | + } |
|
242 | 255 | |
243 | 256 | // Clean up after yerself ;). |
244 | 257 | $smcFunc['db_query']('', ' |