@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | /** |
| 501 | 501 | * Returns the amount of affected rows for a query. |
| 502 | 502 | * |
| 503 | - * @param mixed $result |
|
| 503 | + * @param resource|null $result |
|
| 504 | 504 | * |
| 505 | 505 | * @return int |
| 506 | 506 | * |
@@ -869,7 +869,7 @@ discard block |
||
| 869 | 869 | * |
| 870 | 870 | * @param string $db_name The database name |
| 871 | 871 | * @param resource $db_connection The database connection |
| 872 | - * @return true Always returns true |
|
| 872 | + * @return boolean Always returns true |
|
| 873 | 873 | */ |
| 874 | 874 | function smf_db_select_db($db_name, $db_connection) |
| 875 | 875 | { |
@@ -199,22 +199,22 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | case 'date': |
| 201 | 201 | if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
| 202 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
| 202 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]) . '::date'; |
|
| 203 | 203 | else |
| 204 | 204 | smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
| 205 | 205 | break; |
| 206 | 206 | |
| 207 | 207 | case 'time': |
| 208 | 208 | if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
| 209 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
| 209 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]) . '::time'; |
|
| 210 | 210 | else |
| 211 | 211 | smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
| 212 | 212 | break; |
| 213 | 213 | |
| 214 | 214 | case 'datetime': |
| 215 | 215 | if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
| 216 | - return 'to_timestamp('. |
|
| 217 | - sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
|
| 216 | + return 'to_timestamp(' . |
|
| 217 | + sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5], $datetime_matches[6]) . |
|
| 218 | 218 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
| 219 | 219 | else |
| 220 | 220 | smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | $old_pos = 0; |
| 425 | 425 | $pos = -1; |
| 426 | 426 | // Remove the string escape for better runtime |
| 427 | - $db_string_1 = str_replace('\'\'','',$db_string); |
|
| 427 | + $db_string_1 = str_replace('\'\'', '', $db_string); |
|
| 428 | 428 | while (true) |
| 429 | 429 | { |
| 430 | 430 | $pos = strpos($db_string_1, '\'', $pos + 1); |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | if (!empty($keys) && (count($keys) > 0) && $returnmode > 0) |
| 803 | 803 | { |
| 804 | 804 | // we only take the first key |
| 805 | - $returning = ' RETURNING '.$keys[0]; |
|
| 805 | + $returning = ' RETURNING ' . $keys[0]; |
|
| 806 | 806 | $with_returning = true; |
| 807 | 807 | } |
| 808 | 808 | |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '") |
| 834 | 834 | VALUES |
| 835 | 835 | ' . implode(', |
| 836 | - ', $insertRows).$replace.$returning, |
|
| 836 | + ', $insertRows) . $replace . $returning, |
|
| 837 | 837 | array( |
| 838 | 838 | 'security_override' => true, |
| 839 | 839 | 'db_error_skip' => $method == 'ignore' || $table === $db_prefix . 'log_errors', |
@@ -846,7 +846,7 @@ discard block |
||
| 846 | 846 | if ($returnmode === 2) |
| 847 | 847 | $return_var = array(); |
| 848 | 848 | |
| 849 | - while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
|
| 849 | + while (($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
|
| 850 | 850 | { |
| 851 | 851 | if (is_numeric($row[0])) // try to emulate mysql limitation |
| 852 | 852 | { |
@@ -1009,7 +1009,7 @@ discard block |
||
| 1009 | 1009 | */ |
| 1010 | 1010 | function smf_db_custom_order($field, $array_values, $desc = false) |
| 1011 | 1011 | { |
| 1012 | - $return = 'CASE '. $field . ' '; |
|
| 1012 | + $return = 'CASE ' . $field . ' '; |
|
| 1013 | 1013 | $count = count($array_values); |
| 1014 | 1014 | $then = ($desc ? ' THEN -' : ' THEN '); |
| 1015 | 1015 | |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -34,8 +35,8 @@ discard block |
||
| 34 | 35 | global $smcFunc; |
| 35 | 36 | |
| 36 | 37 | // Map some database specific functions, only do this once. |
| 37 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
| 38 | - $smcFunc += array( |
|
| 38 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
| 39 | + $smcFunc += array( |
|
| 39 | 40 | 'db_query' => 'smf_db_query', |
| 40 | 41 | 'db_quote' => 'smf_db_quote', |
| 41 | 42 | 'db_insert' => 'smf_db_insert', |
@@ -64,11 +65,13 @@ discard block |
||
| 64 | 65 | 'db_error_insert' => 'smf_db_error_insert', |
| 65 | 66 | 'db_custom_order' => 'smf_db_custom_order', |
| 66 | 67 | ); |
| 68 | + } |
|
| 67 | 69 | |
| 68 | - if (!empty($db_options['persist'])) |
|
| 69 | - $connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 70 | - else |
|
| 71 | - $connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 70 | + if (!empty($db_options['persist'])) { |
|
| 71 | + $connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 72 | + } else { |
|
| 73 | + $connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 74 | + } |
|
| 72 | 75 | |
| 73 | 76 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 74 | 77 | if (!$connection) |
@@ -76,8 +79,7 @@ discard block |
||
| 76 | 79 | if (!empty($db_options['non_fatal'])) |
| 77 | 80 | { |
| 78 | 81 | return null; |
| 79 | - } |
|
| 80 | - else |
|
| 82 | + } else |
|
| 81 | 83 | { |
| 82 | 84 | display_db_error(); |
| 83 | 85 | } |
@@ -128,31 +130,38 @@ discard block |
||
| 128 | 130 | |
| 129 | 131 | list ($values, $connection) = $db_callback; |
| 130 | 132 | |
| 131 | - if ($matches[1] === 'db_prefix') |
|
| 132 | - return $db_prefix; |
|
| 133 | + if ($matches[1] === 'db_prefix') { |
|
| 134 | + return $db_prefix; |
|
| 135 | + } |
|
| 133 | 136 | |
| 134 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
| 135 | - return $user_info[$matches[1]]; |
|
| 137 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
| 138 | + return $user_info[$matches[1]]; |
|
| 139 | + } |
|
| 136 | 140 | |
| 137 | - if ($matches[1] === 'empty') |
|
| 138 | - return '\'\''; |
|
| 141 | + if ($matches[1] === 'empty') { |
|
| 142 | + return '\'\''; |
|
| 143 | + } |
|
| 139 | 144 | |
| 140 | - if (!isset($matches[2])) |
|
| 141 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 145 | + if (!isset($matches[2])) { |
|
| 146 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 147 | + } |
|
| 142 | 148 | |
| 143 | - if ($matches[1] === 'literal') |
|
| 144 | - return '\'' . pg_escape_string($matches[2]) . '\''; |
|
| 149 | + if ($matches[1] === 'literal') { |
|
| 150 | + return '\'' . pg_escape_string($matches[2]) . '\''; |
|
| 151 | + } |
|
| 145 | 152 | |
| 146 | - if (!isset($values[$matches[2]])) |
|
| 147 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 153 | + if (!isset($values[$matches[2]])) { |
|
| 154 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 155 | + } |
|
| 148 | 156 | |
| 149 | 157 | $replacement = $values[$matches[2]]; |
| 150 | 158 | |
| 151 | 159 | switch ($matches[1]) |
| 152 | 160 | { |
| 153 | 161 | case 'int': |
| 154 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 155 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 162 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
| 163 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 164 | + } |
|
| 156 | 165 | return (string) (int) $replacement; |
| 157 | 166 | break; |
| 158 | 167 | |
@@ -164,65 +173,73 @@ discard block |
||
| 164 | 173 | case 'array_int': |
| 165 | 174 | if (is_array($replacement)) |
| 166 | 175 | { |
| 167 | - if (empty($replacement)) |
|
| 168 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 176 | + if (empty($replacement)) { |
|
| 177 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 178 | + } |
|
| 169 | 179 | |
| 170 | 180 | foreach ($replacement as $key => $value) |
| 171 | 181 | { |
| 172 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 173 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 182 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 183 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 184 | + } |
|
| 174 | 185 | |
| 175 | 186 | $replacement[$key] = (string) (int) $value; |
| 176 | 187 | } |
| 177 | 188 | |
| 178 | 189 | return implode(', ', $replacement); |
| 190 | + } else { |
|
| 191 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 179 | 192 | } |
| 180 | - else |
|
| 181 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 182 | 193 | |
| 183 | 194 | break; |
| 184 | 195 | |
| 185 | 196 | case 'array_string': |
| 186 | 197 | if (is_array($replacement)) |
| 187 | 198 | { |
| 188 | - if (empty($replacement)) |
|
| 189 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 199 | + if (empty($replacement)) { |
|
| 200 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 201 | + } |
|
| 190 | 202 | |
| 191 | - foreach ($replacement as $key => $value) |
|
| 192 | - $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 203 | + foreach ($replacement as $key => $value) { |
|
| 204 | + $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 205 | + } |
|
| 193 | 206 | |
| 194 | 207 | return implode(', ', $replacement); |
| 208 | + } else { |
|
| 209 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 195 | 210 | } |
| 196 | - else |
|
| 197 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 198 | 211 | break; |
| 199 | 212 | |
| 200 | 213 | case 'date': |
| 201 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
| 202 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
| 203 | - else |
|
| 204 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 214 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 215 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
| 216 | + } else { |
|
| 217 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 218 | + } |
|
| 205 | 219 | break; |
| 206 | 220 | |
| 207 | 221 | case 'time': |
| 208 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
| 209 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
| 210 | - else |
|
| 211 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 222 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
| 223 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
| 224 | + } else { |
|
| 225 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 226 | + } |
|
| 212 | 227 | break; |
| 213 | 228 | |
| 214 | 229 | case 'datetime': |
| 215 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
| 216 | - return 'to_timestamp('. |
|
| 230 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
| 231 | + return 'to_timestamp('. |
|
| 217 | 232 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
| 218 | 233 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
| 219 | - else |
|
| 220 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 234 | + } else { |
|
| 235 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 236 | + } |
|
| 221 | 237 | break; |
| 222 | 238 | |
| 223 | 239 | case 'float': |
| 224 | - if (!is_numeric($replacement)) |
|
| 225 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 240 | + if (!is_numeric($replacement)) { |
|
| 241 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 242 | + } |
|
| 226 | 243 | return (string) (float) $replacement; |
| 227 | 244 | break; |
| 228 | 245 | |
@@ -235,31 +252,36 @@ discard block |
||
| 235 | 252 | break; |
| 236 | 253 | |
| 237 | 254 | case 'inet': |
| 238 | - if ($replacement == 'null' || $replacement == '') |
|
| 239 | - return 'null'; |
|
| 240 | - if (inet_pton($replacement) === false) |
|
| 241 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 255 | + if ($replacement == 'null' || $replacement == '') { |
|
| 256 | + return 'null'; |
|
| 257 | + } |
|
| 258 | + if (inet_pton($replacement) === false) { |
|
| 259 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 260 | + } |
|
| 242 | 261 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
| 243 | 262 | |
| 244 | 263 | case 'array_inet': |
| 245 | 264 | if (is_array($replacement)) |
| 246 | 265 | { |
| 247 | - if (empty($replacement)) |
|
| 248 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 266 | + if (empty($replacement)) { |
|
| 267 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 268 | + } |
|
| 249 | 269 | |
| 250 | 270 | foreach ($replacement as $key => $value) |
| 251 | 271 | { |
| 252 | - if ($replacement == 'null' || $replacement == '') |
|
| 253 | - $replacement[$key] = 'null'; |
|
| 254 | - if (!isValidIP($value)) |
|
| 255 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 272 | + if ($replacement == 'null' || $replacement == '') { |
|
| 273 | + $replacement[$key] = 'null'; |
|
| 274 | + } |
|
| 275 | + if (!isValidIP($value)) { |
|
| 276 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 277 | + } |
|
| 256 | 278 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
| 257 | 279 | } |
| 258 | 280 | |
| 259 | 281 | return implode(', ', $replacement); |
| 282 | + } else { |
|
| 283 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 260 | 284 | } |
| 261 | - else |
|
| 262 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 263 | 285 | break; |
| 264 | 286 | |
| 265 | 287 | default: |
@@ -350,14 +372,16 @@ discard block |
||
| 350 | 372 | ), |
| 351 | 373 | ); |
| 352 | 374 | |
| 353 | - if (isset($replacements[$identifier])) |
|
| 354 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 375 | + if (isset($replacements[$identifier])) { |
|
| 376 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 377 | + } |
|
| 355 | 378 | |
| 356 | 379 | // Limits need to be a little different. |
| 357 | 380 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
| 358 | 381 | |
| 359 | - if (trim($db_string) == '') |
|
| 360 | - return false; |
|
| 382 | + if (trim($db_string) == '') { |
|
| 383 | + return false; |
|
| 384 | + } |
|
| 361 | 385 | |
| 362 | 386 | // Comments that are allowed in a query are preg_removed. |
| 363 | 387 | static $allowed_comments_from = array( |
@@ -377,8 +401,9 @@ discard block |
||
| 377 | 401 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 378 | 402 | $db_replace_result = 0; |
| 379 | 403 | |
| 380 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 381 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 404 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 405 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 406 | + } |
|
| 382 | 407 | |
| 383 | 408 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
| 384 | 409 | { |
@@ -403,17 +428,18 @@ discard block |
||
| 403 | 428 | while (true) |
| 404 | 429 | { |
| 405 | 430 | $pos = strpos($db_string_1, '\'', $pos + 1); |
| 406 | - if ($pos === false) |
|
| 407 | - break; |
|
| 431 | + if ($pos === false) { |
|
| 432 | + break; |
|
| 433 | + } |
|
| 408 | 434 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
| 409 | 435 | |
| 410 | 436 | while (true) |
| 411 | 437 | { |
| 412 | 438 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
| 413 | 439 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
| 414 | - if ($pos1 === false) |
|
| 415 | - break; |
|
| 416 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
| 440 | + if ($pos1 === false) { |
|
| 441 | + break; |
|
| 442 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
| 417 | 443 | { |
| 418 | 444 | $pos = $pos1; |
| 419 | 445 | break; |
@@ -429,16 +455,19 @@ discard block |
||
| 429 | 455 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 430 | 456 | |
| 431 | 457 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 432 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 433 | - $fail = true; |
|
| 458 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 459 | + $fail = true; |
|
| 460 | + } |
|
| 434 | 461 | // Trying to change passwords, slow us down, or something? |
| 435 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 436 | - $fail = true; |
|
| 437 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 438 | - $fail = true; |
|
| 462 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 463 | + $fail = true; |
|
| 464 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 465 | + $fail = true; |
|
| 466 | + } |
|
| 439 | 467 | |
| 440 | - if (!empty($fail) && function_exists('log_error')) |
|
| 441 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 468 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 469 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 470 | + } |
|
| 442 | 471 | } |
| 443 | 472 | |
| 444 | 473 | // Set optimize stuff |
@@ -465,8 +494,9 @@ discard block |
||
| 465 | 494 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 466 | 495 | |
| 467 | 496 | // Initialize $db_cache if not already initialized. |
| 468 | - if (!isset($db_cache)) |
|
| 469 | - $db_cache = array(); |
|
| 497 | + if (!isset($db_cache)) { |
|
| 498 | + $db_cache = array(); |
|
| 499 | + } |
|
| 470 | 500 | |
| 471 | 501 | if (!empty($_SESSION['debug_redirect'])) |
| 472 | 502 | { |
@@ -484,12 +514,14 @@ discard block |
||
| 484 | 514 | |
| 485 | 515 | $db_last_result = @pg_query($connection, $db_string); |
| 486 | 516 | |
| 487 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
| 488 | - $db_last_result = smf_db_error($db_string, $connection); |
|
| 517 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
| 518 | + $db_last_result = smf_db_error($db_string, $connection); |
|
| 519 | + } |
|
| 489 | 520 | |
| 490 | 521 | // Debugging. |
| 491 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 492 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 522 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 523 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 524 | + } |
|
| 493 | 525 | |
| 494 | 526 | return $db_last_result; |
| 495 | 527 | } |
@@ -506,10 +538,11 @@ discard block |
||
| 506 | 538 | { |
| 507 | 539 | global $db_last_result, $db_replace_result; |
| 508 | 540 | |
| 509 | - if ($db_replace_result) |
|
| 510 | - return $db_replace_result; |
|
| 511 | - elseif ($result === null && !$db_last_result) |
|
| 512 | - return 0; |
|
| 541 | + if ($db_replace_result) { |
|
| 542 | + return $db_replace_result; |
|
| 543 | + } elseif ($result === null && !$db_last_result) { |
|
| 544 | + return 0; |
|
| 545 | + } |
|
| 513 | 546 | |
| 514 | 547 | return pg_affected_rows($result === null ? $db_last_result : $result); |
| 515 | 548 | } |
@@ -533,8 +566,9 @@ discard block |
||
| 533 | 566 | array( |
| 534 | 567 | ) |
| 535 | 568 | ); |
| 536 | - if (!$request) |
|
| 537 | - return false; |
|
| 569 | + if (!$request) { |
|
| 570 | + return false; |
|
| 571 | + } |
|
| 538 | 572 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
| 539 | 573 | $smcFunc['db_free_result']($request); |
| 540 | 574 | |
@@ -555,12 +589,13 @@ discard block |
||
| 555 | 589 | // Decide which connection to use |
| 556 | 590 | $connection = $connection === null ? $db_connection : $connection; |
| 557 | 591 | |
| 558 | - if ($type == 'begin') |
|
| 559 | - return @pg_query($connection, 'BEGIN'); |
|
| 560 | - elseif ($type == 'rollback') |
|
| 561 | - return @pg_query($connection, 'ROLLBACK'); |
|
| 562 | - elseif ($type == 'commit') |
|
| 563 | - return @pg_query($connection, 'COMMIT'); |
|
| 592 | + if ($type == 'begin') { |
|
| 593 | + return @pg_query($connection, 'BEGIN'); |
|
| 594 | + } elseif ($type == 'rollback') { |
|
| 595 | + return @pg_query($connection, 'ROLLBACK'); |
|
| 596 | + } elseif ($type == 'commit') { |
|
| 597 | + return @pg_query($connection, 'COMMIT'); |
|
| 598 | + } |
|
| 564 | 599 | |
| 565 | 600 | return false; |
| 566 | 601 | } |
@@ -588,19 +623,22 @@ discard block |
||
| 588 | 623 | $query_error = @pg_last_error($connection); |
| 589 | 624 | |
| 590 | 625 | // Log the error. |
| 591 | - if (function_exists('log_error')) |
|
| 592 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
| 626 | + if (function_exists('log_error')) { |
|
| 627 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
| 628 | + } |
|
| 593 | 629 | |
| 594 | 630 | // Nothing's defined yet... just die with it. |
| 595 | - if (empty($context) || empty($txt)) |
|
| 596 | - die($query_error); |
|
| 631 | + if (empty($context) || empty($txt)) { |
|
| 632 | + die($query_error); |
|
| 633 | + } |
|
| 597 | 634 | |
| 598 | 635 | // Show an error message, if possible. |
| 599 | 636 | $context['error_title'] = $txt['database_error']; |
| 600 | - if (allowedTo('admin_forum')) |
|
| 601 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 602 | - else |
|
| 603 | - $context['error_message'] = $txt['try_again']; |
|
| 637 | + if (allowedTo('admin_forum')) { |
|
| 638 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 639 | + } else { |
|
| 640 | + $context['error_message'] = $txt['try_again']; |
|
| 641 | + } |
|
| 604 | 642 | |
| 605 | 643 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 606 | 644 | { |
@@ -622,12 +660,14 @@ discard block |
||
| 622 | 660 | { |
| 623 | 661 | global $db_row_count; |
| 624 | 662 | |
| 625 | - if ($counter !== false) |
|
| 626 | - return pg_fetch_row($request, $counter); |
|
| 663 | + if ($counter !== false) { |
|
| 664 | + return pg_fetch_row($request, $counter); |
|
| 665 | + } |
|
| 627 | 666 | |
| 628 | 667 | // Reset the row counter... |
| 629 | - if (!isset($db_row_count[(int) $request])) |
|
| 630 | - $db_row_count[(int) $request] = 0; |
|
| 668 | + if (!isset($db_row_count[(int) $request])) { |
|
| 669 | + $db_row_count[(int) $request] = 0; |
|
| 670 | + } |
|
| 631 | 671 | |
| 632 | 672 | // Return the right row. |
| 633 | 673 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -644,12 +684,14 @@ discard block |
||
| 644 | 684 | { |
| 645 | 685 | global $db_row_count; |
| 646 | 686 | |
| 647 | - if ($counter !== false) |
|
| 648 | - return pg_fetch_assoc($request, $counter); |
|
| 687 | + if ($counter !== false) { |
|
| 688 | + return pg_fetch_assoc($request, $counter); |
|
| 689 | + } |
|
| 649 | 690 | |
| 650 | 691 | // Reset the row counter... |
| 651 | - if (!isset($db_row_count[(int) $request])) |
|
| 652 | - $db_row_count[(int) $request] = 0; |
|
| 692 | + if (!isset($db_row_count[(int) $request])) { |
|
| 693 | + $db_row_count[(int) $request] = 0; |
|
| 694 | + } |
|
| 653 | 695 | |
| 654 | 696 | // Return the right row. |
| 655 | 697 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -702,11 +744,13 @@ discard block |
||
| 702 | 744 | |
| 703 | 745 | $replace = ''; |
| 704 | 746 | |
| 705 | - if (empty($data)) |
|
| 706 | - return; |
|
| 747 | + if (empty($data)) { |
|
| 748 | + return; |
|
| 749 | + } |
|
| 707 | 750 | |
| 708 | - if (!is_array($data[array_rand($data)])) |
|
| 709 | - $data = array($data); |
|
| 751 | + if (!is_array($data[array_rand($data)])) { |
|
| 752 | + $data = array($data); |
|
| 753 | + } |
|
| 710 | 754 | |
| 711 | 755 | // Replace the prefix holder with the actual prefix. |
| 712 | 756 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -725,11 +769,13 @@ discard block |
||
| 725 | 769 | //pg 9.5 got replace support |
| 726 | 770 | $pg_version = $smcFunc['db_get_version'](); |
| 727 | 771 | // if we got a Beta Version |
| 728 | - if (stripos($pg_version, 'beta') !== false) |
|
| 729 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
| 772 | + if (stripos($pg_version, 'beta') !== false) { |
|
| 773 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
| 774 | + } |
|
| 730 | 775 | // or RC |
| 731 | - if (stripos($pg_version, 'rc') !== false) |
|
| 732 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
| 776 | + if (stripos($pg_version, 'rc') !== false) { |
|
| 777 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
| 778 | + } |
|
| 733 | 779 | |
| 734 | 780 | $replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false); |
| 735 | 781 | } |
@@ -748,32 +794,35 @@ discard block |
||
| 748 | 794 | $key_str .= ($count_pk > 0 ? ',' : ''); |
| 749 | 795 | $key_str .= $columnName; |
| 750 | 796 | $count_pk++; |
| 751 | - } |
|
| 752 | - else if ($method == 'replace') //normal field |
|
| 797 | + } else if ($method == 'replace') { |
|
| 798 | + //normal field |
|
| 753 | 799 | { |
| 754 | 800 | $col_str .= ($count > 0 ? ',' : ''); |
| 801 | + } |
|
| 755 | 802 | $col_str .= $columnName . ' = EXCLUDED.' . $columnName; |
| 756 | 803 | $count++; |
| 757 | 804 | } |
| 758 | 805 | } |
| 759 | - if ($method == 'replace') |
|
| 760 | - $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
| 761 | - else |
|
| 762 | - $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
| 763 | - } |
|
| 764 | - else if ($method == 'replace') |
|
| 806 | + if ($method == 'replace') { |
|
| 807 | + $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
| 808 | + } else { |
|
| 809 | + $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
| 810 | + } |
|
| 811 | + } else if ($method == 'replace') |
|
| 765 | 812 | { |
| 766 | 813 | foreach ($columns as $columnName => $type) |
| 767 | 814 | { |
| 768 | 815 | // Are we restricting the length? |
| 769 | - if (strpos($type, 'string-') !== false) |
|
| 770 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 771 | - else |
|
| 772 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 816 | + if (strpos($type, 'string-') !== false) { |
|
| 817 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 818 | + } else { |
|
| 819 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 820 | + } |
|
| 773 | 821 | |
| 774 | 822 | // A key? That's what we were looking for. |
| 775 | - if (in_array($columnName, $keys)) |
|
| 776 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 823 | + if (in_array($columnName, $keys)) { |
|
| 824 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 825 | + } |
|
| 777 | 826 | $count++; |
| 778 | 827 | } |
| 779 | 828 | |
@@ -809,10 +858,11 @@ discard block |
||
| 809 | 858 | foreach ($columns as $columnName => $type) |
| 810 | 859 | { |
| 811 | 860 | // Are we restricting the length? |
| 812 | - if (strpos($type, 'string-') !== false) |
|
| 813 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 814 | - else |
|
| 815 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 861 | + if (strpos($type, 'string-') !== false) { |
|
| 862 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 863 | + } else { |
|
| 864 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 865 | + } |
|
| 816 | 866 | } |
| 817 | 867 | $insertData = substr($insertData, 0, -2) . ')'; |
| 818 | 868 | |
@@ -821,8 +871,9 @@ discard block |
||
| 821 | 871 | |
| 822 | 872 | // Here's where the variables are injected to the query. |
| 823 | 873 | $insertRows = array(); |
| 824 | - foreach ($data as $dataRow) |
|
| 825 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 874 | + foreach ($data as $dataRow) { |
|
| 875 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 876 | + } |
|
| 826 | 877 | |
| 827 | 878 | // Do the insert. |
| 828 | 879 | $request = $smcFunc['db_query']('', ' |
@@ -839,19 +890,21 @@ discard block |
||
| 839 | 890 | |
| 840 | 891 | if ($with_returning && $request !== false) |
| 841 | 892 | { |
| 842 | - if ($returnmode === 2) |
|
| 843 | - $return_var = array(); |
|
| 893 | + if ($returnmode === 2) { |
|
| 894 | + $return_var = array(); |
|
| 895 | + } |
|
| 844 | 896 | |
| 845 | 897 | while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
| 846 | 898 | { |
| 847 | - if (is_numeric($row[0])) // try to emulate mysql limitation |
|
| 899 | + if (is_numeric($row[0])) { |
|
| 900 | + // try to emulate mysql limitation |
|
| 848 | 901 | { |
| 849 | 902 | if ($returnmode === 1) |
| 850 | 903 | $return_var = $row[0]; |
| 851 | - elseif ($returnmode === 2) |
|
| 852 | - $return_var[] = $row[0]; |
|
| 853 | - } |
|
| 854 | - else |
|
| 904 | + } elseif ($returnmode === 2) { |
|
| 905 | + $return_var[] = $row[0]; |
|
| 906 | + } |
|
| 907 | + } else |
|
| 855 | 908 | { |
| 856 | 909 | $with_returning = false; |
| 857 | 910 | trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR); |
@@ -860,9 +913,10 @@ discard block |
||
| 860 | 913 | } |
| 861 | 914 | } |
| 862 | 915 | |
| 863 | - if ($with_returning && !empty($return_var)) |
|
| 864 | - return $return_var; |
|
| 865 | -} |
|
| 916 | + if ($with_returning && !empty($return_var)) { |
|
| 917 | + return $return_var; |
|
| 918 | + } |
|
| 919 | + } |
|
| 866 | 920 | |
| 867 | 921 | /** |
| 868 | 922 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -899,8 +953,9 @@ discard block |
||
| 899 | 953 | */ |
| 900 | 954 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 901 | 955 | { |
| 902 | - if (empty($log_message)) |
|
| 903 | - $log_message = $error_message; |
|
| 956 | + if (empty($log_message)) { |
|
| 957 | + $log_message = $error_message; |
|
| 958 | + } |
|
| 904 | 959 | |
| 905 | 960 | foreach (debug_backtrace() as $step) |
| 906 | 961 | { |
@@ -919,12 +974,14 @@ discard block |
||
| 919 | 974 | } |
| 920 | 975 | |
| 921 | 976 | // A special case - we want the file and line numbers for debugging. |
| 922 | - if ($error_type == 'return') |
|
| 923 | - return array($file, $line); |
|
| 977 | + if ($error_type == 'return') { |
|
| 978 | + return array($file, $line); |
|
| 979 | + } |
|
| 924 | 980 | |
| 925 | 981 | // Is always a critical error. |
| 926 | - if (function_exists('log_error')) |
|
| 927 | - log_error($log_message, 'critical', $file, $line); |
|
| 982 | + if (function_exists('log_error')) { |
|
| 983 | + log_error($log_message, 'critical', $file, $line); |
|
| 984 | + } |
|
| 928 | 985 | |
| 929 | 986 | if (function_exists('fatal_error')) |
| 930 | 987 | { |
@@ -932,12 +989,12 @@ discard block |
||
| 932 | 989 | |
| 933 | 990 | // Cannot continue... |
| 934 | 991 | exit; |
| 992 | + } elseif ($error_type) { |
|
| 993 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 994 | + } else { |
|
| 995 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 996 | + } |
|
| 935 | 997 | } |
| 936 | - elseif ($error_type) |
|
| 937 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 938 | - else |
|
| 939 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 940 | -} |
|
| 941 | 998 | |
| 942 | 999 | /** |
| 943 | 1000 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -954,10 +1011,11 @@ discard block |
||
| 954 | 1011 | '\\' => '\\\\', |
| 955 | 1012 | ); |
| 956 | 1013 | |
| 957 | - if ($translate_human_wildcards) |
|
| 958 | - $replacements += array( |
|
| 1014 | + if ($translate_human_wildcards) { |
|
| 1015 | + $replacements += array( |
|
| 959 | 1016 | '*' => '%', |
| 960 | 1017 | ); |
| 1018 | + } |
|
| 961 | 1019 | |
| 962 | 1020 | return strtr($string, $replacements); |
| 963 | 1021 | } |
@@ -986,14 +1044,16 @@ discard block |
||
| 986 | 1044 | static $pg_error_data_prep; |
| 987 | 1045 | |
| 988 | 1046 | // without database we can't do anything |
| 989 | - if (empty($db_connection)) |
|
| 990 | - return; |
|
| 1047 | + if (empty($db_connection)) { |
|
| 1048 | + return; |
|
| 1049 | + } |
|
| 991 | 1050 | |
| 992 | - if (empty($pg_error_data_prep)) |
|
| 993 | - $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
| 1051 | + if (empty($pg_error_data_prep)) { |
|
| 1052 | + $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
| 994 | 1053 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line) |
| 995 | 1054 | VALUES( $1, $2, $3, $4, $5, $6, $7, $8, $9)' |
| 996 | 1055 | ); |
| 1056 | + } |
|
| 997 | 1057 | |
| 998 | 1058 | pg_execute($db_connection, 'smf_log_errors', $error_array); |
| 999 | 1059 | } |
@@ -1013,8 +1073,9 @@ discard block |
||
| 1013 | 1073 | $count = count($array_values); |
| 1014 | 1074 | $then = ($desc ? ' THEN -' : ' THEN '); |
| 1015 | 1075 | |
| 1016 | - for ($i = 0; $i < $count; $i++) |
|
| 1017 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
| 1076 | + for ($i = 0; $i < $count; $i++) { |
|
| 1077 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
| 1078 | + } |
|
| 1018 | 1079 | |
| 1019 | 1080 | $return .= 'END'; |
| 1020 | 1081 | return $return; |
@@ -1334,7 +1334,7 @@ discard block |
||
| 1334 | 1334 | 'class' => 'centercol', |
| 1335 | 1335 | ), |
| 1336 | 1336 | 'data' => array( |
| 1337 | - 'function' => function ($rowData) |
|
| 1337 | + 'function' => function($rowData) |
|
| 1338 | 1338 | { |
| 1339 | 1339 | $isChecked = $rowData['disabled'] ? '' : ' checked'; |
| 1340 | 1340 | $onClickHandler = $rowData['can_show_register'] ? sprintf(' onclick="document.getElementById(\'reg_%1$s\').disabled = !this.checked;"', $rowData['id']) : ''; |
@@ -1350,7 +1350,7 @@ discard block |
||
| 1350 | 1350 | 'class' => 'centercol', |
| 1351 | 1351 | ), |
| 1352 | 1352 | 'data' => array( |
| 1353 | - 'function' => function ($rowData) |
|
| 1353 | + 'function' => function($rowData) |
|
| 1354 | 1354 | { |
| 1355 | 1355 | $isChecked = $rowData['on_register'] && !$rowData['disabled'] ? ' checked' : ''; |
| 1356 | 1356 | $isDisabled = $rowData['can_show_register'] ? '' : ' disabled'; |
@@ -1397,15 +1397,15 @@ discard block |
||
| 1397 | 1397 | 'value' => $txt['custom_profile_fieldorder'], |
| 1398 | 1398 | ), |
| 1399 | 1399 | 'data' => array( |
| 1400 | - 'function' => function ($rowData) use ($context, $txt, $scripturl) |
|
| 1400 | + 'function' => function($rowData) use ($context, $txt, $scripturl) |
|
| 1401 | 1401 | { |
| 1402 | - $return = '<p class="centertext bold_text">'. $rowData['field_order'] .'<br>'; |
|
| 1402 | + $return = '<p class="centertext bold_text">' . $rowData['field_order'] . '<br>'; |
|
| 1403 | 1403 | |
| 1404 | 1404 | if ($rowData['field_order'] > 1) |
| 1405 | - $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>'; |
|
| 1405 | + $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="' . $txt['custom_edit_order_move'] . ' ' . $txt['custom_edit_order_up'] . '"></span></a>'; |
|
| 1406 | 1406 | |
| 1407 | 1407 | if ($rowData['field_order'] < $context['custFieldsMaxOrder']) |
| 1408 | - $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>'; |
|
| 1408 | + $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="' . $txt['custom_edit_order_move'] . ' ' . $txt['custom_edit_order_down'] . '"></span></a>'; |
|
| 1409 | 1409 | |
| 1410 | 1410 | $return .= '</p>'; |
| 1411 | 1411 | |
@@ -1423,7 +1423,7 @@ discard block |
||
| 1423 | 1423 | 'value' => $txt['custom_profile_fieldname'], |
| 1424 | 1424 | ), |
| 1425 | 1425 | 'data' => array( |
| 1426 | - 'function' => function ($rowData) use ($scripturl) |
|
| 1426 | + 'function' => function($rowData) use ($scripturl) |
|
| 1427 | 1427 | { |
| 1428 | 1428 | return sprintf('<a href="%1$s?action=admin;area=featuresettings;sa=profileedit;fid=%2$d">%3$s</a><div class="smalltext">%4$s</div>', $scripturl, $rowData['id_field'], $rowData['field_name'], $rowData['field_desc']); |
| 1429 | 1429 | }, |
@@ -1439,7 +1439,7 @@ discard block |
||
| 1439 | 1439 | 'value' => $txt['custom_profile_fieldtype'], |
| 1440 | 1440 | ), |
| 1441 | 1441 | 'data' => array( |
| 1442 | - 'function' => function ($rowData) use ($txt) |
|
| 1442 | + 'function' => function($rowData) use ($txt) |
|
| 1443 | 1443 | { |
| 1444 | 1444 | $textKey = sprintf('custom_profile_type_%1$s', $rowData['field_type']); |
| 1445 | 1445 | return isset($txt[$textKey]) ? $txt[$textKey] : $textKey; |
@@ -1457,7 +1457,7 @@ discard block |
||
| 1457 | 1457 | 'value' => $txt['custom_profile_active'], |
| 1458 | 1458 | ), |
| 1459 | 1459 | 'data' => array( |
| 1460 | - 'function' => function ($rowData) use ($txt) |
|
| 1460 | + 'function' => function($rowData) use ($txt) |
|
| 1461 | 1461 | { |
| 1462 | 1462 | return $rowData['active'] ? $txt['yes'] : $txt['no']; |
| 1463 | 1463 | }, |
@@ -1474,7 +1474,7 @@ discard block |
||
| 1474 | 1474 | 'value' => $txt['custom_profile_placement'], |
| 1475 | 1475 | ), |
| 1476 | 1476 | 'data' => array( |
| 1477 | - 'function' => function ($rowData) |
|
| 1477 | + 'function' => function($rowData) |
|
| 1478 | 1478 | { |
| 1479 | 1479 | global $txt, $context; |
| 1480 | 1480 | |
@@ -1709,7 +1709,7 @@ discard block |
||
| 1709 | 1709 | redirectexit('action=admin;area=featuresettings;sa=profile'); // @todo implement an error handler |
| 1710 | 1710 | |
| 1711 | 1711 | // All good, proceed. |
| 1712 | - $smcFunc['db_query']('',' |
|
| 1712 | + $smcFunc['db_query']('', ' |
|
| 1713 | 1713 | UPDATE {db_prefix}custom_fields |
| 1714 | 1714 | SET field_order = {int:old_order} |
| 1715 | 1715 | WHERE field_order = {int:new_order}', |
@@ -1718,7 +1718,7 @@ discard block |
||
| 1718 | 1718 | 'old_order' => $context['field']['order'], |
| 1719 | 1719 | ) |
| 1720 | 1720 | ); |
| 1721 | - $smcFunc['db_query']('',' |
|
| 1721 | + $smcFunc['db_query']('', ' |
|
| 1722 | 1722 | UPDATE {db_prefix}custom_fields |
| 1723 | 1723 | SET field_order = {int:new_order} |
| 1724 | 1724 | WHERE id_field = {int:id_field}', |
@@ -1820,7 +1820,7 @@ discard block |
||
| 1820 | 1820 | $smcFunc['db_free_result']($request); |
| 1821 | 1821 | |
| 1822 | 1822 | $unique = false; |
| 1823 | - for ($i = 0; !$unique && $i < 9; $i ++) |
|
| 1823 | + for ($i = 0; !$unique && $i < 9; $i++) |
|
| 1824 | 1824 | { |
| 1825 | 1825 | if (!in_array($col_name, $current_fields)) |
| 1826 | 1826 | $unique = true; |
@@ -1993,7 +1993,7 @@ discard block |
||
| 1993 | 1993 | ); |
| 1994 | 1994 | |
| 1995 | 1995 | // Re-arrange the order. |
| 1996 | - $smcFunc['db_query']('',' |
|
| 1996 | + $smcFunc['db_query']('', ' |
|
| 1997 | 1997 | UPDATE {db_prefix}custom_fields |
| 1998 | 1998 | SET field_order = field_order - 1 |
| 1999 | 1999 | WHERE field_order > {int:current_order}', |
@@ -2257,7 +2257,7 @@ discard block |
||
| 2257 | 2257 | $context['token_check'] = 'noti-admin'; |
| 2258 | 2258 | |
| 2259 | 2259 | // Specify our action since we'll want to post back here instead of the profile |
| 2260 | - $context['action'] = 'action=admin;area=featuresettings;sa=alerts;'. $context['session_var'] .'='. $context['session_id']; |
|
| 2260 | + $context['action'] = 'action=admin;area=featuresettings;sa=alerts;' . $context['session_var'] . '=' . $context['session_id']; |
|
| 2261 | 2261 | |
| 2262 | 2262 | loadTemplate('Profile'); |
| 2263 | 2263 | loadLanguage('Profile'); |
@@ -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 makes sure the requested subaction does exists, if it doesn't, it sets a default action or. |
@@ -206,16 +207,18 @@ discard block |
||
| 206 | 207 | { |
| 207 | 208 | $all_zones = timezone_identifiers_list(); |
| 208 | 209 | // Make sure we set the value to the same as the printed value. |
| 209 | - foreach ($all_zones as $zone) |
|
| 210 | - $config_vars['default_timezone'][2][$zone] = $zone; |
|
| 210 | + foreach ($all_zones as $zone) { |
|
| 211 | + $config_vars['default_timezone'][2][$zone] = $zone; |
|
| 212 | + } |
|
| 213 | + } else { |
|
| 214 | + unset($config_vars['default_timezone']); |
|
| 211 | 215 | } |
| 212 | - else |
|
| 213 | - unset($config_vars['default_timezone']); |
|
| 214 | 216 | |
| 215 | 217 | call_integration_hook('integrate_modify_basic_settings', array(&$config_vars)); |
| 216 | 218 | |
| 217 | - if ($return_config) |
|
| 218 | - return $config_vars; |
|
| 219 | + if ($return_config) { |
|
| 220 | + return $config_vars; |
|
| 221 | + } |
|
| 219 | 222 | |
| 220 | 223 | // Saving? |
| 221 | 224 | if (isset($_GET['save'])) |
@@ -223,8 +226,9 @@ discard block |
||
| 223 | 226 | checkSession(); |
| 224 | 227 | |
| 225 | 228 | // Prevent absurd boundaries here - make it a day tops. |
| 226 | - if (isset($_POST['lastActive'])) |
|
| 227 | - $_POST['lastActive'] = min((int) $_POST['lastActive'], 1440); |
|
| 229 | + if (isset($_POST['lastActive'])) { |
|
| 230 | + $_POST['lastActive'] = min((int) $_POST['lastActive'], 1440); |
|
| 231 | + } |
|
| 228 | 232 | |
| 229 | 233 | call_integration_hook('integrate_save_basic_settings'); |
| 230 | 234 | |
@@ -269,8 +273,9 @@ discard block |
||
| 269 | 273 | |
| 270 | 274 | call_integration_hook('integrate_modify_bbc_settings', array(&$config_vars)); |
| 271 | 275 | |
| 272 | - if ($return_config) |
|
| 273 | - return $config_vars; |
|
| 276 | + if ($return_config) { |
|
| 277 | + return $config_vars; |
|
| 278 | + } |
|
| 274 | 279 | |
| 275 | 280 | // Setup the template. |
| 276 | 281 | require_once($sourcedir . '/ManageServer.php'); |
@@ -287,13 +292,15 @@ discard block |
||
| 287 | 292 | |
| 288 | 293 | // Clean up the tags. |
| 289 | 294 | $bbcTags = array(); |
| 290 | - foreach (parse_bbc(false) as $tag) |
|
| 291 | - $bbcTags[] = $tag['tag']; |
|
| 295 | + foreach (parse_bbc(false) as $tag) { |
|
| 296 | + $bbcTags[] = $tag['tag']; |
|
| 297 | + } |
|
| 292 | 298 | |
| 293 | - if (!isset($_POST['disabledBBC_enabledTags'])) |
|
| 294 | - $_POST['disabledBBC_enabledTags'] = array(); |
|
| 295 | - elseif (!is_array($_POST['disabledBBC_enabledTags'])) |
|
| 296 | - $_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']); |
|
| 299 | + if (!isset($_POST['disabledBBC_enabledTags'])) { |
|
| 300 | + $_POST['disabledBBC_enabledTags'] = array(); |
|
| 301 | + } elseif (!is_array($_POST['disabledBBC_enabledTags'])) { |
|
| 302 | + $_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']); |
|
| 303 | + } |
|
| 297 | 304 | // Work out what is actually disabled! |
| 298 | 305 | $_POST['disabledBBC'] = implode(',', array_diff($bbcTags, $_POST['disabledBBC_enabledTags'])); |
| 299 | 306 | |
@@ -337,8 +344,9 @@ discard block |
||
| 337 | 344 | |
| 338 | 345 | call_integration_hook('integrate_layout_settings', array(&$config_vars)); |
| 339 | 346 | |
| 340 | - if ($return_config) |
|
| 341 | - return $config_vars; |
|
| 347 | + if ($return_config) { |
|
| 348 | + return $config_vars; |
|
| 349 | + } |
|
| 342 | 350 | |
| 343 | 351 | // Saving? |
| 344 | 352 | if (isset($_GET['save'])) |
@@ -379,8 +387,9 @@ discard block |
||
| 379 | 387 | |
| 380 | 388 | call_integration_hook('integrate_likes_settings', array(&$config_vars)); |
| 381 | 389 | |
| 382 | - if ($return_config) |
|
| 383 | - return $config_vars; |
|
| 390 | + if ($return_config) { |
|
| 391 | + return $config_vars; |
|
| 392 | + } |
|
| 384 | 393 | |
| 385 | 394 | // Saving? |
| 386 | 395 | if (isset($_GET['save'])) |
@@ -418,8 +427,9 @@ discard block |
||
| 418 | 427 | |
| 419 | 428 | call_integration_hook('integrate_mentions_settings', array(&$config_vars)); |
| 420 | 429 | |
| 421 | - if ($return_config) |
|
| 422 | - return $config_vars; |
|
| 430 | + if ($return_config) { |
|
| 431 | + return $config_vars; |
|
| 432 | + } |
|
| 423 | 433 | |
| 424 | 434 | // Saving? |
| 425 | 435 | if (isset($_GET['save'])) |
@@ -463,8 +473,8 @@ discard block |
||
| 463 | 473 | 'enable' => array('check', 'warning_enable'), |
| 464 | 474 | ); |
| 465 | 475 | |
| 466 | - if (!empty($modSettings['warning_settings']) && $currently_enabled) |
|
| 467 | - $config_vars += array( |
|
| 476 | + if (!empty($modSettings['warning_settings']) && $currently_enabled) { |
|
| 477 | + $config_vars += array( |
|
| 468 | 478 | '', |
| 469 | 479 | array('int', 'warning_watch', 'subtext' => $txt['setting_warning_watch_note'] . ' ' . $txt['zero_to_disable']), |
| 470 | 480 | 'moderate' => array('int', 'warning_moderate', 'subtext' => $txt['setting_warning_moderate_note'] . ' ' . $txt['zero_to_disable']), |
@@ -473,15 +483,18 @@ discard block |
||
| 473 | 483 | 'rem2' => array('int', 'warning_decrement', 'subtext' => $txt['setting_warning_decrement_note'] . ' ' . $txt['zero_to_disable']), |
| 474 | 484 | array('permissions', 'view_warning'), |
| 475 | 485 | ); |
| 486 | + } |
|
| 476 | 487 | |
| 477 | 488 | call_integration_hook('integrate_warning_settings', array(&$config_vars)); |
| 478 | 489 | |
| 479 | - if ($return_config) |
|
| 480 | - return $config_vars; |
|
| 490 | + if ($return_config) { |
|
| 491 | + return $config_vars; |
|
| 492 | + } |
|
| 481 | 493 | |
| 482 | 494 | // Cannot use moderation if post moderation is not enabled. |
| 483 | - if (!$modSettings['postmod_active']) |
|
| 484 | - unset($config_vars['moderate']); |
|
| 495 | + if (!$modSettings['postmod_active']) { |
|
| 496 | + unset($config_vars['moderate']); |
|
| 497 | + } |
|
| 485 | 498 | |
| 486 | 499 | // Will need the utility functions from here. |
| 487 | 500 | require_once($sourcedir . '/ManageServer.php'); |
@@ -506,16 +519,16 @@ discard block |
||
| 506 | 519 | 'warning_watch' => 10, |
| 507 | 520 | 'warning_mute' => 60, |
| 508 | 521 | ); |
| 509 | - if ($modSettings['postmod_active']) |
|
| 510 | - $vars['warning_moderate'] = 35; |
|
| 522 | + if ($modSettings['postmod_active']) { |
|
| 523 | + $vars['warning_moderate'] = 35; |
|
| 524 | + } |
|
| 511 | 525 | |
| 512 | 526 | foreach ($vars as $var => $value) |
| 513 | 527 | { |
| 514 | 528 | $config_vars[] = array('int', $var); |
| 515 | 529 | $_POST[$var] = $value; |
| 516 | 530 | } |
| 517 | - } |
|
| 518 | - else |
|
| 531 | + } else |
|
| 519 | 532 | { |
| 520 | 533 | $_POST['warning_watch'] = min($_POST['warning_watch'], 100); |
| 521 | 534 | $_POST['warning_moderate'] = $modSettings['postmod_active'] ? min($_POST['warning_moderate'], 100) : 0; |
@@ -603,8 +616,9 @@ discard block |
||
| 603 | 616 | |
| 604 | 617 | call_integration_hook('integrate_spam_settings', array(&$config_vars)); |
| 605 | 618 | |
| 606 | - if ($return_config) |
|
| 607 | - return $config_vars; |
|
| 619 | + if ($return_config) { |
|
| 620 | + return $config_vars; |
|
| 621 | + } |
|
| 608 | 622 | |
| 609 | 623 | // You need to be an admin to edit settings! |
| 610 | 624 | isAllowedTo('admin_forum'); |
@@ -638,8 +652,9 @@ discard block |
||
| 638 | 652 | |
| 639 | 653 | if (empty($context['qa_by_lang'][strtr($language, array('-utf8' => ''))]) && !empty($context['question_answers'])) |
| 640 | 654 | { |
| 641 | - if (empty($context['settings_insert_above'])) |
|
| 642 | - $context['settings_insert_above'] = ''; |
|
| 655 | + if (empty($context['settings_insert_above'])) { |
|
| 656 | + $context['settings_insert_above'] = ''; |
|
| 657 | + } |
|
| 643 | 658 | |
| 644 | 659 | $context['settings_insert_above'] .= '<div class="noticebox">' . sprintf($txt['question_not_defined'], $context['languages'][$language]['name']) . '</div>'; |
| 645 | 660 | } |
@@ -682,8 +697,9 @@ discard block |
||
| 682 | 697 | $_POST['pm_spam_settings'] = (int) $_POST['max_pm_recipients'] . ',' . (int) $_POST['pm_posts_verification'] . ',' . (int) $_POST['pm_posts_per_hour']; |
| 683 | 698 | |
| 684 | 699 | // Hack in guest requiring verification! |
| 685 | - if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha'])) |
|
| 686 | - $_POST['posts_require_captcha'] = -1; |
|
| 700 | + if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha'])) { |
|
| 701 | + $_POST['posts_require_captcha'] = -1; |
|
| 702 | + } |
|
| 687 | 703 | |
| 688 | 704 | $save_vars = $config_vars; |
| 689 | 705 | unset($save_vars['pm1'], $save_vars['pm2'], $save_vars['pm3'], $save_vars['guest_verify']); |
@@ -700,14 +716,16 @@ discard block |
||
| 700 | 716 | foreach ($context['qa_languages'] as $lang_id => $dummy) |
| 701 | 717 | { |
| 702 | 718 | // If we had some questions for this language before, but don't now, delete everything from that language. |
| 703 | - if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id])) |
|
| 704 | - $changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]); |
|
| 719 | + if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id])) { |
|
| 720 | + $changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]); |
|
| 721 | + } |
|
| 705 | 722 | |
| 706 | 723 | // Now step through and see if any existing questions no longer exist. |
| 707 | - if (!empty($context['qa_by_lang'][$lang_id])) |
|
| 708 | - foreach ($context['qa_by_lang'][$lang_id] as $q_id) |
|
| 724 | + if (!empty($context['qa_by_lang'][$lang_id])) { |
|
| 725 | + foreach ($context['qa_by_lang'][$lang_id] as $q_id) |
|
| 709 | 726 | if (empty($_POST['question'][$lang_id][$q_id])) |
| 710 | 727 | $changes['delete'][] = $q_id; |
| 728 | + } |
|
| 711 | 729 | |
| 712 | 730 | // Now let's see if there are new questions or ones that need updating. |
| 713 | 731 | if (isset($_POST['question'][$lang_id])) |
@@ -716,14 +734,16 @@ discard block |
||
| 716 | 734 | { |
| 717 | 735 | // Ignore junky ids. |
| 718 | 736 | $q_id = (int) $q_id; |
| 719 | - if ($q_id <= 0) |
|
| 720 | - continue; |
|
| 737 | + if ($q_id <= 0) { |
|
| 738 | + continue; |
|
| 739 | + } |
|
| 721 | 740 | |
| 722 | 741 | // Check the question isn't empty (because they want to delete it?) |
| 723 | 742 | if (empty($question) || trim($question) == '') |
| 724 | 743 | { |
| 725 | - if (isset($context['question_answers'][$q_id])) |
|
| 726 | - $changes['delete'][] = $q_id; |
|
| 744 | + if (isset($context['question_answers'][$q_id])) { |
|
| 745 | + $changes['delete'][] = $q_id; |
|
| 746 | + } |
|
| 727 | 747 | continue; |
| 728 | 748 | } |
| 729 | 749 | $question = $smcFunc['htmlspecialchars'](trim($question)); |
@@ -731,19 +751,22 @@ discard block |
||
| 731 | 751 | // Get the answers. Firstly check there actually might be some. |
| 732 | 752 | if (!isset($_POST['answer'][$lang_id][$q_id]) || !is_array($_POST['answer'][$lang_id][$q_id])) |
| 733 | 753 | { |
| 734 | - if (isset($context['question_answers'][$q_id])) |
|
| 735 | - $changes['delete'][] = $q_id; |
|
| 754 | + if (isset($context['question_answers'][$q_id])) { |
|
| 755 | + $changes['delete'][] = $q_id; |
|
| 756 | + } |
|
| 736 | 757 | continue; |
| 737 | 758 | } |
| 738 | 759 | // Now get them and check that they might be viable. |
| 739 | 760 | $answers = array(); |
| 740 | - foreach ($_POST['answer'][$lang_id][$q_id] as $answer) |
|
| 741 | - if (!empty($answer) && trim($answer) !== '') |
|
| 761 | + foreach ($_POST['answer'][$lang_id][$q_id] as $answer) { |
|
| 762 | + if (!empty($answer) && trim($answer) !== '') |
|
| 742 | 763 | $answers[] = $smcFunc['htmlspecialchars'](trim($answer)); |
| 764 | + } |
|
| 743 | 765 | if (empty($answers)) |
| 744 | 766 | { |
| 745 | - if (isset($context['question_answers'][$q_id])) |
|
| 746 | - $changes['delete'][] = $q_id; |
|
| 767 | + if (isset($context['question_answers'][$q_id])) { |
|
| 768 | + $changes['delete'][] = $q_id; |
|
| 769 | + } |
|
| 747 | 770 | continue; |
| 748 | 771 | } |
| 749 | 772 | $answers = $smcFunc['json_encode']($answers); |
@@ -753,16 +776,17 @@ discard block |
||
| 753 | 776 | { |
| 754 | 777 | // New question. Now, we don't want to randomly consume ids, so we'll set those, rather than trusting the browser's supplied ids. |
| 755 | 778 | $changes['insert'][] = array($lang_id, $question, $answers); |
| 756 | - } |
|
| 757 | - else |
|
| 779 | + } else |
|
| 758 | 780 | { |
| 759 | 781 | // It's an existing question. Let's see what's changed, if anything. |
| 760 | - if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers']) |
|
| 761 | - $changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers); |
|
| 782 | + if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers']) { |
|
| 783 | + $changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers); |
|
| 784 | + } |
|
| 762 | 785 | } |
| 763 | 786 | |
| 764 | - if (!isset($qs_per_lang[$lang_id])) |
|
| 765 | - $qs_per_lang[$lang_id] = 0; |
|
| 787 | + if (!isset($qs_per_lang[$lang_id])) { |
|
| 788 | + $qs_per_lang[$lang_id] = 0; |
|
| 789 | + } |
|
| 766 | 790 | $qs_per_lang[$lang_id]++; |
| 767 | 791 | } |
| 768 | 792 | } |
@@ -812,8 +836,9 @@ discard block |
||
| 812 | 836 | |
| 813 | 837 | // Lastly, the count of messages needs to be no more than the lowest number of questions for any one language. |
| 814 | 838 | $count_questions = empty($qs_per_lang) ? 0 : min($qs_per_lang); |
| 815 | - if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions) |
|
| 816 | - $_POST['qa_verification_number'] = $count_questions; |
|
| 839 | + if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions) { |
|
| 840 | + $_POST['qa_verification_number'] = $count_questions; |
|
| 841 | + } |
|
| 817 | 842 | |
| 818 | 843 | call_integration_hook('integrate_save_spam_settings', array(&$save_vars)); |
| 819 | 844 | |
@@ -828,24 +853,27 @@ discard block |
||
| 828 | 853 | |
| 829 | 854 | $character_range = array_merge(range('A', 'H'), array('K', 'M', 'N', 'P', 'R'), range('T', 'Y')); |
| 830 | 855 | $_SESSION['visual_verification_code'] = ''; |
| 831 | - for ($i = 0; $i < 6; $i++) |
|
| 832 | - $_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)]; |
|
| 856 | + for ($i = 0; $i < 6; $i++) { |
|
| 857 | + $_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)]; |
|
| 858 | + } |
|
| 833 | 859 | |
| 834 | 860 | // Some javascript for CAPTCHA. |
| 835 | 861 | $context['settings_post_javascript'] = ''; |
| 836 | - if ($context['use_graphic_library']) |
|
| 837 | - $context['settings_post_javascript'] .= ' |
|
| 862 | + if ($context['use_graphic_library']) { |
|
| 863 | + $context['settings_post_javascript'] .= ' |
|
| 838 | 864 | function refreshImages() |
| 839 | 865 | { |
| 840 | 866 | var imageType = document.getElementById(\'visual_verification_type\').value; |
| 841 | 867 | document.getElementById(\'verification_image\').src = \'' . $context['verification_image_href'] . ';type=\' + imageType; |
| 842 | 868 | }'; |
| 869 | + } |
|
| 843 | 870 | |
| 844 | 871 | // Show the image itself, or text saying we can't. |
| 845 | - if ($context['use_graphic_library']) |
|
| 846 | - $config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>'; |
|
| 847 | - else |
|
| 848 | - $config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>'; |
|
| 872 | + if ($context['use_graphic_library']) { |
|
| 873 | + $config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>'; |
|
| 874 | + } else { |
|
| 875 | + $config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>'; |
|
| 876 | + } |
|
| 849 | 877 | |
| 850 | 878 | // Hack for PM spam settings. |
| 851 | 879 | list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']); |
@@ -855,9 +883,10 @@ discard block |
||
| 855 | 883 | $modSettings['posts_require_captcha'] = !isset($modSettings['posts_require_captcha']) || $modSettings['posts_require_captcha'] == -1 ? 0 : $modSettings['posts_require_captcha']; |
| 856 | 884 | |
| 857 | 885 | // Some minor javascript for the guest post setting. |
| 858 | - if ($modSettings['posts_require_captcha']) |
|
| 859 | - $context['settings_post_javascript'] .= ' |
|
| 886 | + if ($modSettings['posts_require_captcha']) { |
|
| 887 | + $context['settings_post_javascript'] .= ' |
|
| 860 | 888 | document.getElementById(\'guests_require_captcha\').disabled = true;'; |
| 889 | + } |
|
| 861 | 890 | |
| 862 | 891 | // And everything else. |
| 863 | 892 | $context['post_url'] = $scripturl . '?action=admin;area=antispam;save'; |
@@ -904,8 +933,9 @@ discard block |
||
| 904 | 933 | |
| 905 | 934 | call_integration_hook('integrate_signature_settings', array(&$config_vars)); |
| 906 | 935 | |
| 907 | - if ($return_config) |
|
| 908 | - return $config_vars; |
|
| 936 | + if ($return_config) { |
|
| 937 | + return $config_vars; |
|
| 938 | + } |
|
| 909 | 939 | |
| 910 | 940 | // Setup the template. |
| 911 | 941 | $context['page_title'] = $txt['signature_settings']; |
@@ -960,8 +990,9 @@ discard block |
||
| 960 | 990 | $sig = strtr($row['signature'], array('<br>' => "\n")); |
| 961 | 991 | |
| 962 | 992 | // Max characters... |
| 963 | - if (!empty($sig_limits[1])) |
|
| 964 | - $sig = $smcFunc['substr']($sig, 0, $sig_limits[1]); |
|
| 993 | + if (!empty($sig_limits[1])) { |
|
| 994 | + $sig = $smcFunc['substr']($sig, 0, $sig_limits[1]); |
|
| 995 | + } |
|
| 965 | 996 | // Max lines... |
| 966 | 997 | if (!empty($sig_limits[2])) |
| 967 | 998 | { |
@@ -971,8 +1002,9 @@ discard block |
||
| 971 | 1002 | if ($sig[$i] == "\n") |
| 972 | 1003 | { |
| 973 | 1004 | $count++; |
| 974 | - if ($count >= $sig_limits[2]) |
|
| 975 | - $sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' ')); |
|
| 1005 | + if ($count >= $sig_limits[2]) { |
|
| 1006 | + $sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' ')); |
|
| 1007 | + } |
|
| 976 | 1008 | } |
| 977 | 1009 | } |
| 978 | 1010 | } |
@@ -983,17 +1015,19 @@ discard block |
||
| 983 | 1015 | { |
| 984 | 1016 | $limit_broke = 0; |
| 985 | 1017 | // Attempt to allow all sizes of abuse, so to speak. |
| 986 | - if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) |
|
| 987 | - $limit_broke = $sig_limits[7] . 'px'; |
|
| 988 | - elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) |
|
| 989 | - $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt'; |
|
| 990 | - elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) |
|
| 991 | - $limit_broke = ((float) $sig_limits[7] / 16) . 'em'; |
|
| 992 | - elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) |
|
| 993 | - $limit_broke = 'large'; |
|
| 994 | - |
|
| 995 | - if ($limit_broke) |
|
| 996 | - $sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig); |
|
| 1018 | + if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) { |
|
| 1019 | + $limit_broke = $sig_limits[7] . 'px'; |
|
| 1020 | + } elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) { |
|
| 1021 | + $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt'; |
|
| 1022 | + } elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) { |
|
| 1023 | + $limit_broke = ((float) $sig_limits[7] / 16) . 'em'; |
|
| 1024 | + } elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) { |
|
| 1025 | + $limit_broke = 'large'; |
|
| 1026 | + } |
|
| 1027 | + |
|
| 1028 | + if ($limit_broke) { |
|
| 1029 | + $sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig); |
|
| 1030 | + } |
|
| 997 | 1031 | } |
| 998 | 1032 | } |
| 999 | 1033 | |
@@ -1049,32 +1083,34 @@ discard block |
||
| 1049 | 1083 | $img_offset = false; |
| 1050 | 1084 | } |
| 1051 | 1085 | } |
| 1086 | + } else { |
|
| 1087 | + $replaces[$image] = ''; |
|
| 1052 | 1088 | } |
| 1053 | - else |
|
| 1054 | - $replaces[$image] = ''; |
|
| 1055 | 1089 | |
| 1056 | 1090 | continue; |
| 1057 | 1091 | } |
| 1058 | 1092 | |
| 1059 | 1093 | // Does it have predefined restraints? Width first. |
| 1060 | - if ($matches[6][$key]) |
|
| 1061 | - $matches[2][$key] = $matches[6][$key]; |
|
| 1094 | + if ($matches[6][$key]) { |
|
| 1095 | + $matches[2][$key] = $matches[6][$key]; |
|
| 1096 | + } |
|
| 1062 | 1097 | if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5]) |
| 1063 | 1098 | { |
| 1064 | 1099 | $width = $sig_limits[5]; |
| 1065 | 1100 | $matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]); |
| 1101 | + } elseif ($matches[2][$key]) { |
|
| 1102 | + $width = $matches[2][$key]; |
|
| 1066 | 1103 | } |
| 1067 | - elseif ($matches[2][$key]) |
|
| 1068 | - $width = $matches[2][$key]; |
|
| 1069 | 1104 | // ... and height. |
| 1070 | 1105 | if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6]) |
| 1071 | 1106 | { |
| 1072 | 1107 | $height = $sig_limits[6]; |
| 1073 | - if ($width != -1) |
|
| 1074 | - $width = $width * ($height / $matches[4][$key]); |
|
| 1108 | + if ($width != -1) { |
|
| 1109 | + $width = $width * ($height / $matches[4][$key]); |
|
| 1110 | + } |
|
| 1111 | + } elseif ($matches[4][$key]) { |
|
| 1112 | + $height = $matches[4][$key]; |
|
| 1075 | 1113 | } |
| 1076 | - elseif ($matches[4][$key]) |
|
| 1077 | - $height = $matches[4][$key]; |
|
| 1078 | 1114 | |
| 1079 | 1115 | // If the dimensions are still not fixed - we need to check the actual image. |
| 1080 | 1116 | if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6])) |
@@ -1092,12 +1128,13 @@ discard block |
||
| 1092 | 1128 | if ($sizes[1] > $sig_limits[6] && $sig_limits[6]) |
| 1093 | 1129 | { |
| 1094 | 1130 | $height = $sig_limits[6]; |
| 1095 | - if ($width == -1) |
|
| 1096 | - $width = $sizes[0]; |
|
| 1131 | + if ($width == -1) { |
|
| 1132 | + $width = $sizes[0]; |
|
| 1133 | + } |
|
| 1097 | 1134 | $width = $width * ($height / $sizes[1]); |
| 1135 | + } elseif ($width != -1) { |
|
| 1136 | + $height = $sizes[1]; |
|
| 1098 | 1137 | } |
| 1099 | - elseif ($width != -1) |
|
| 1100 | - $height = $sizes[1]; |
|
| 1101 | 1138 | } |
| 1102 | 1139 | } |
| 1103 | 1140 | |
@@ -1110,8 +1147,9 @@ discard block |
||
| 1110 | 1147 | // Record that we got one. |
| 1111 | 1148 | $image_count_holder[$image] = isset($image_count_holder[$image]) ? $image_count_holder[$image] + 1 : 1; |
| 1112 | 1149 | } |
| 1113 | - if (!empty($replaces)) |
|
| 1114 | - $sig = str_replace(array_keys($replaces), array_values($replaces), $sig); |
|
| 1150 | + if (!empty($replaces)) { |
|
| 1151 | + $sig = str_replace(array_keys($replaces), array_values($replaces), $sig); |
|
| 1152 | + } |
|
| 1115 | 1153 | } |
| 1116 | 1154 | } |
| 1117 | 1155 | // Try to fix disabled tags. |
@@ -1123,18 +1161,20 @@ discard block |
||
| 1123 | 1161 | |
| 1124 | 1162 | $sig = strtr($sig, array("\n" => '<br>')); |
| 1125 | 1163 | call_integration_hook('integrate_apply_signature_settings', array(&$sig, $sig_limits, $disabledTags)); |
| 1126 | - if ($sig != $row['signature']) |
|
| 1127 | - $changes[$row['id_member']] = $sig; |
|
| 1164 | + if ($sig != $row['signature']) { |
|
| 1165 | + $changes[$row['id_member']] = $sig; |
|
| 1166 | + } |
|
| 1167 | + } |
|
| 1168 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1169 | + $done = true; |
|
| 1128 | 1170 | } |
| 1129 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1130 | - $done = true; |
|
| 1131 | 1171 | $smcFunc['db_free_result']($request); |
| 1132 | 1172 | |
| 1133 | 1173 | // Do we need to delete what we have? |
| 1134 | 1174 | if (!empty($changes)) |
| 1135 | 1175 | { |
| 1136 | - foreach ($changes as $id => $sig) |
|
| 1137 | - $smcFunc['db_query']('', ' |
|
| 1176 | + foreach ($changes as $id => $sig) { |
|
| 1177 | + $smcFunc['db_query']('', ' |
|
| 1138 | 1178 | UPDATE {db_prefix}members |
| 1139 | 1179 | SET signature = {string:signature} |
| 1140 | 1180 | WHERE id_member = {int:id_member}', |
@@ -1143,11 +1183,13 @@ discard block |
||
| 1143 | 1183 | 'signature' => $sig, |
| 1144 | 1184 | ) |
| 1145 | 1185 | ); |
| 1186 | + } |
|
| 1146 | 1187 | } |
| 1147 | 1188 | |
| 1148 | 1189 | $_GET['step'] += 50; |
| 1149 | - if (!$done) |
|
| 1150 | - pauseSignatureApplySettings(); |
|
| 1190 | + if (!$done) { |
|
| 1191 | + pauseSignatureApplySettings(); |
|
| 1192 | + } |
|
| 1151 | 1193 | } |
| 1152 | 1194 | $settings_applied = true; |
| 1153 | 1195 | } |
@@ -1165,8 +1207,9 @@ discard block |
||
| 1165 | 1207 | ); |
| 1166 | 1208 | |
| 1167 | 1209 | // Temporarily make each setting a modSetting! |
| 1168 | - foreach ($context['signature_settings'] as $key => $value) |
|
| 1169 | - $modSettings['signature_' . $key] = $value; |
|
| 1210 | + foreach ($context['signature_settings'] as $key => $value) { |
|
| 1211 | + $modSettings['signature_' . $key] = $value; |
|
| 1212 | + } |
|
| 1170 | 1213 | |
| 1171 | 1214 | // Make sure we check the right tags! |
| 1172 | 1215 | $modSettings['bbc_disabled_signature_bbc'] = $disabledTags; |
@@ -1178,23 +1221,26 @@ discard block |
||
| 1178 | 1221 | |
| 1179 | 1222 | // Clean up the tag stuff! |
| 1180 | 1223 | $bbcTags = array(); |
| 1181 | - foreach (parse_bbc(false) as $tag) |
|
| 1182 | - $bbcTags[] = $tag['tag']; |
|
| 1224 | + foreach (parse_bbc(false) as $tag) { |
|
| 1225 | + $bbcTags[] = $tag['tag']; |
|
| 1226 | + } |
|
| 1183 | 1227 | |
| 1184 | - if (!isset($_POST['signature_bbc_enabledTags'])) |
|
| 1185 | - $_POST['signature_bbc_enabledTags'] = array(); |
|
| 1186 | - elseif (!is_array($_POST['signature_bbc_enabledTags'])) |
|
| 1187 | - $_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']); |
|
| 1228 | + if (!isset($_POST['signature_bbc_enabledTags'])) { |
|
| 1229 | + $_POST['signature_bbc_enabledTags'] = array(); |
|
| 1230 | + } elseif (!is_array($_POST['signature_bbc_enabledTags'])) { |
|
| 1231 | + $_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']); |
|
| 1232 | + } |
|
| 1188 | 1233 | |
| 1189 | 1234 | $sig_limits = array(); |
| 1190 | 1235 | foreach ($context['signature_settings'] as $key => $value) |
| 1191 | 1236 | { |
| 1192 | - if ($key == 'allow_smileys') |
|
| 1193 | - continue; |
|
| 1194 | - elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys'])) |
|
| 1195 | - $sig_limits[] = -1; |
|
| 1196 | - else |
|
| 1197 | - $sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0; |
|
| 1237 | + if ($key == 'allow_smileys') { |
|
| 1238 | + continue; |
|
| 1239 | + } elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys'])) { |
|
| 1240 | + $sig_limits[] = -1; |
|
| 1241 | + } else { |
|
| 1242 | + $sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0; |
|
| 1243 | + } |
|
| 1198 | 1244 | } |
| 1199 | 1245 | |
| 1200 | 1246 | call_integration_hook('integrate_save_signature_settings', array(&$sig_limits, &$bbcTags)); |
@@ -1227,12 +1273,14 @@ discard block |
||
| 1227 | 1273 | |
| 1228 | 1274 | // Try get more time... |
| 1229 | 1275 | @set_time_limit(600); |
| 1230 | - if (function_exists('apache_reset_timeout')) |
|
| 1231 | - @apache_reset_timeout(); |
|
| 1276 | + if (function_exists('apache_reset_timeout')) { |
|
| 1277 | + @apache_reset_timeout(); |
|
| 1278 | + } |
|
| 1232 | 1279 | |
| 1233 | 1280 | // Have we exhausted all the time we allowed? |
| 1234 | - if (time() - array_sum(explode(' ', $sig_start)) < 3) |
|
| 1235 | - return; |
|
| 1281 | + if (time() - array_sum(explode(' ', $sig_start)) < 3) { |
|
| 1282 | + return; |
|
| 1283 | + } |
|
| 1236 | 1284 | |
| 1237 | 1285 | $context['continue_get_data'] = '?action=admin;area=featuresettings;sa=sig;apply;step=' . $_GET['step'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
| 1238 | 1286 | $context['page_title'] = $txt['not_done_title']; |
@@ -1278,9 +1326,10 @@ discard block |
||
| 1278 | 1326 | $disable_fields = array_flip($standard_fields); |
| 1279 | 1327 | if (!empty($_POST['active'])) |
| 1280 | 1328 | { |
| 1281 | - foreach ($_POST['active'] as $value) |
|
| 1282 | - if (isset($disable_fields[$value])) |
|
| 1329 | + foreach ($_POST['active'] as $value) { |
|
| 1330 | + if (isset($disable_fields[$value])) |
|
| 1283 | 1331 | unset($disable_fields[$value]); |
| 1332 | + } |
|
| 1284 | 1333 | } |
| 1285 | 1334 | // What we have left! |
| 1286 | 1335 | $changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields)); |
@@ -1289,16 +1338,18 @@ discard block |
||
| 1289 | 1338 | $reg_fields = array(); |
| 1290 | 1339 | if (!empty($_POST['reg'])) |
| 1291 | 1340 | { |
| 1292 | - foreach ($_POST['reg'] as $value) |
|
| 1293 | - if (in_array($value, $standard_fields) && !isset($disable_fields[$value])) |
|
| 1341 | + foreach ($_POST['reg'] as $value) { |
|
| 1342 | + if (in_array($value, $standard_fields) && !isset($disable_fields[$value])) |
|
| 1294 | 1343 | $reg_fields[] = $value; |
| 1344 | + } |
|
| 1295 | 1345 | } |
| 1296 | 1346 | // What we have left! |
| 1297 | 1347 | $changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields); |
| 1298 | 1348 | |
| 1299 | 1349 | $_SESSION['adm-save'] = true; |
| 1300 | - if (!empty($changes)) |
|
| 1301 | - updateSettings($changes); |
|
| 1350 | + if (!empty($changes)) { |
|
| 1351 | + updateSettings($changes); |
|
| 1352 | + } |
|
| 1302 | 1353 | } |
| 1303 | 1354 | |
| 1304 | 1355 | createToken('admin-scp'); |
@@ -1401,11 +1452,13 @@ discard block |
||
| 1401 | 1452 | { |
| 1402 | 1453 | $return = '<p class="centertext bold_text">'. $rowData['field_order'] .'<br>'; |
| 1403 | 1454 | |
| 1404 | - if ($rowData['field_order'] > 1) |
|
| 1405 | - $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>'; |
|
| 1455 | + if ($rowData['field_order'] > 1) { |
|
| 1456 | + $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>'; |
|
| 1457 | + } |
|
| 1406 | 1458 | |
| 1407 | - if ($rowData['field_order'] < $context['custFieldsMaxOrder']) |
|
| 1408 | - $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>'; |
|
| 1459 | + if ($rowData['field_order'] < $context['custFieldsMaxOrder']) { |
|
| 1460 | + $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>'; |
|
| 1461 | + } |
|
| 1409 | 1462 | |
| 1410 | 1463 | $return .= '</p>'; |
| 1411 | 1464 | |
@@ -1543,16 +1596,16 @@ discard block |
||
| 1543 | 1596 | $disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array(); |
| 1544 | 1597 | $registration_fields = isset($modSettings['registration_fields']) ? explode(',', $modSettings['registration_fields']) : array(); |
| 1545 | 1598 | |
| 1546 | - foreach ($standard_fields as $field) |
|
| 1547 | - $list[] = array( |
|
| 1599 | + foreach ($standard_fields as $field) { |
|
| 1600 | + $list[] = array( |
|
| 1548 | 1601 | 'id' => $field, |
| 1549 | 1602 | 'label' => isset($txt['standard_profile_field_' . $field]) ? $txt['standard_profile_field_' . $field] : (isset($txt[$field]) ? $txt[$field] : $field), |
| 1550 | 1603 | 'disabled' => in_array($field, $disabled_fields), |
| 1551 | 1604 | 'on_register' => in_array($field, $registration_fields) && !in_array($field, $fields_no_registration), |
| 1552 | 1605 | 'can_show_register' => !in_array($field, $fields_no_registration), |
| 1553 | 1606 | ); |
| 1554 | - } |
|
| 1555 | - else |
|
| 1607 | + } |
|
| 1608 | + } else |
|
| 1556 | 1609 | { |
| 1557 | 1610 | // Load all the fields. |
| 1558 | 1611 | $request = $smcFunc['db_query']('', ' |
@@ -1566,8 +1619,9 @@ discard block |
||
| 1566 | 1619 | 'items_per_page' => $items_per_page, |
| 1567 | 1620 | ) |
| 1568 | 1621 | ); |
| 1569 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1570 | - $list[] = $row; |
|
| 1622 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1623 | + $list[] = $row; |
|
| 1624 | + } |
|
| 1571 | 1625 | $smcFunc['db_free_result']($request); |
| 1572 | 1626 | } |
| 1573 | 1627 | |
@@ -1633,9 +1687,9 @@ discard block |
||
| 1633 | 1687 | $context['field'] = array(); |
| 1634 | 1688 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1635 | 1689 | { |
| 1636 | - if ($row['field_type'] == 'textarea') |
|
| 1637 | - @list ($rows, $cols) = @explode(',', $row['default_value']); |
|
| 1638 | - else |
|
| 1690 | + if ($row['field_type'] == 'textarea') { |
|
| 1691 | + @list ($rows, $cols) = @explode(',', $row['default_value']); |
|
| 1692 | + } else |
|
| 1639 | 1693 | { |
| 1640 | 1694 | $rows = 3; |
| 1641 | 1695 | $cols = 30; |
@@ -1671,8 +1725,8 @@ discard block |
||
| 1671 | 1725 | } |
| 1672 | 1726 | |
| 1673 | 1727 | // Setup the default values as needed. |
| 1674 | - if (empty($context['field'])) |
|
| 1675 | - $context['field'] = array( |
|
| 1728 | + if (empty($context['field'])) { |
|
| 1729 | + $context['field'] = array( |
|
| 1676 | 1730 | 'name' => '', |
| 1677 | 1731 | 'col_name' => '???', |
| 1678 | 1732 | 'desc' => '', |
@@ -1697,6 +1751,7 @@ discard block |
||
| 1697 | 1751 | 'enclose' => '', |
| 1698 | 1752 | 'placement' => 0, |
| 1699 | 1753 | ); |
| 1754 | + } |
|
| 1700 | 1755 | |
| 1701 | 1756 | // Are we moving it? |
| 1702 | 1757 | if (isset($_GET['move']) && in_array($smcFunc['htmlspecialchars']($_GET['move']), $move_to)) |
@@ -1705,8 +1760,10 @@ discard block |
||
| 1705 | 1760 | $new_order = ($_GET['move'] == 'up' ? ($context['field']['order'] - 1) : ($context['field']['order'] + 1)); |
| 1706 | 1761 | |
| 1707 | 1762 | // Is this a valid position? |
| 1708 | - if ($new_order <= 0 || $new_order > $order_count) |
|
| 1709 | - redirectexit('action=admin;area=featuresettings;sa=profile'); // @todo implement an error handler |
|
| 1763 | + if ($new_order <= 0 || $new_order > $order_count) { |
|
| 1764 | + redirectexit('action=admin;area=featuresettings;sa=profile'); |
|
| 1765 | + } |
|
| 1766 | + // @todo implement an error handler |
|
| 1710 | 1767 | |
| 1711 | 1768 | // All good, proceed. |
| 1712 | 1769 | $smcFunc['db_query']('',' |
@@ -1737,12 +1794,14 @@ discard block |
||
| 1737 | 1794 | validateToken('admin-ecp'); |
| 1738 | 1795 | |
| 1739 | 1796 | // Everyone needs a name - even the (bracket) unknown... |
| 1740 | - if (trim($_POST['field_name']) == '') |
|
| 1741 | - redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name'); |
|
| 1797 | + if (trim($_POST['field_name']) == '') { |
|
| 1798 | + redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name'); |
|
| 1799 | + } |
|
| 1742 | 1800 | |
| 1743 | 1801 | // Regex you say? Do a very basic test to see if the pattern is valid |
| 1744 | - if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false) |
|
| 1745 | - redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error'); |
|
| 1802 | + if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false) { |
|
| 1803 | + redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error'); |
|
| 1804 | + } |
|
| 1746 | 1805 | |
| 1747 | 1806 | $_POST['field_name'] = $smcFunc['htmlspecialchars']($_POST['field_name']); |
| 1748 | 1807 | $_POST['field_desc'] = $smcFunc['htmlspecialchars']($_POST['field_desc']); |
@@ -1759,8 +1818,9 @@ discard block |
||
| 1759 | 1818 | |
| 1760 | 1819 | // Some masking stuff... |
| 1761 | 1820 | $mask = isset($_POST['mask']) ? $_POST['mask'] : ''; |
| 1762 | - if ($mask == 'regex' && isset($_POST['regex'])) |
|
| 1763 | - $mask .= $_POST['regex']; |
|
| 1821 | + if ($mask == 'regex' && isset($_POST['regex'])) { |
|
| 1822 | + $mask .= $_POST['regex']; |
|
| 1823 | + } |
|
| 1764 | 1824 | |
| 1765 | 1825 | $field_length = isset($_POST['max_length']) ? (int) $_POST['max_length'] : 255; |
| 1766 | 1826 | $enclose = isset($_POST['enclose']) ? $_POST['enclose'] : ''; |
@@ -1779,8 +1839,9 @@ discard block |
||
| 1779 | 1839 | $v = strtr($v, array(',' => '')); |
| 1780 | 1840 | |
| 1781 | 1841 | // Nada, zip, etc... |
| 1782 | - if (trim($v) == '') |
|
| 1783 | - continue; |
|
| 1842 | + if (trim($v) == '') { |
|
| 1843 | + continue; |
|
| 1844 | + } |
|
| 1784 | 1845 | |
| 1785 | 1846 | // Otherwise, save it boy. |
| 1786 | 1847 | $field_options .= $v . ','; |
@@ -1788,15 +1849,17 @@ discard block |
||
| 1788 | 1849 | $newOptions[$k] = $v; |
| 1789 | 1850 | |
| 1790 | 1851 | // Is it default? |
| 1791 | - if (isset($_POST['default_select']) && $_POST['default_select'] == $k) |
|
| 1792 | - $default = $v; |
|
| 1852 | + if (isset($_POST['default_select']) && $_POST['default_select'] == $k) { |
|
| 1853 | + $default = $v; |
|
| 1854 | + } |
|
| 1793 | 1855 | } |
| 1794 | 1856 | $field_options = substr($field_options, 0, -1); |
| 1795 | 1857 | } |
| 1796 | 1858 | |
| 1797 | 1859 | // Text area has default has dimensions |
| 1798 | - if ($_POST['field_type'] == 'textarea') |
|
| 1799 | - $default = (int) $_POST['rows'] . ',' . (int) $_POST['cols']; |
|
| 1860 | + if ($_POST['field_type'] == 'textarea') { |
|
| 1861 | + $default = (int) $_POST['rows'] . ',' . (int) $_POST['cols']; |
|
| 1862 | + } |
|
| 1800 | 1863 | |
| 1801 | 1864 | // Come up with the unique name? |
| 1802 | 1865 | if (empty($context['fid'])) |
@@ -1805,32 +1868,36 @@ discard block |
||
| 1805 | 1868 | preg_match('~([\w\d_-]+)~', $col_name, $matches); |
| 1806 | 1869 | |
| 1807 | 1870 | // If there is nothing to the name, then let's start out own - for foreign languages etc. |
| 1808 | - if (isset($matches[1])) |
|
| 1809 | - $col_name = $initial_col_name = 'cust_' . strtolower($matches[1]); |
|
| 1810 | - else |
|
| 1811 | - $col_name = $initial_col_name = 'cust_' . mt_rand(1, 9999); |
|
| 1871 | + if (isset($matches[1])) { |
|
| 1872 | + $col_name = $initial_col_name = 'cust_' . strtolower($matches[1]); |
|
| 1873 | + } else { |
|
| 1874 | + $col_name = $initial_col_name = 'cust_' . mt_rand(1, 9999); |
|
| 1875 | + } |
|
| 1812 | 1876 | |
| 1813 | 1877 | // Make sure this is unique. |
| 1814 | 1878 | $current_fields = array(); |
| 1815 | 1879 | $request = $smcFunc['db_query']('', ' |
| 1816 | 1880 | SELECT id_field, col_name |
| 1817 | 1881 | FROM {db_prefix}custom_fields'); |
| 1818 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1819 | - $current_fields[$row['id_field']] = $row['col_name']; |
|
| 1882 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1883 | + $current_fields[$row['id_field']] = $row['col_name']; |
|
| 1884 | + } |
|
| 1820 | 1885 | $smcFunc['db_free_result']($request); |
| 1821 | 1886 | |
| 1822 | 1887 | $unique = false; |
| 1823 | 1888 | for ($i = 0; !$unique && $i < 9; $i ++) |
| 1824 | 1889 | { |
| 1825 | - if (!in_array($col_name, $current_fields)) |
|
| 1826 | - $unique = true; |
|
| 1827 | - else |
|
| 1828 | - $col_name = $initial_col_name . $i; |
|
| 1890 | + if (!in_array($col_name, $current_fields)) { |
|
| 1891 | + $unique = true; |
|
| 1892 | + } else { |
|
| 1893 | + $col_name = $initial_col_name . $i; |
|
| 1894 | + } |
|
| 1829 | 1895 | } |
| 1830 | 1896 | |
| 1831 | 1897 | // Still not a unique column name? Leave it up to the user, then. |
| 1832 | - if (!$unique) |
|
| 1833 | - fatal_lang_error('custom_option_not_unique'); |
|
| 1898 | + if (!$unique) { |
|
| 1899 | + fatal_lang_error('custom_option_not_unique'); |
|
| 1900 | + } |
|
| 1834 | 1901 | } |
| 1835 | 1902 | // Work out what to do with the user data otherwise... |
| 1836 | 1903 | else |
@@ -1858,8 +1925,9 @@ discard block |
||
| 1858 | 1925 | // Work out what's changed! |
| 1859 | 1926 | foreach ($context['field']['options'] as $k => $option) |
| 1860 | 1927 | { |
| 1861 | - if (trim($option) == '') |
|
| 1862 | - continue; |
|
| 1928 | + if (trim($option) == '') { |
|
| 1929 | + continue; |
|
| 1930 | + } |
|
| 1863 | 1931 | |
| 1864 | 1932 | // Still exists? |
| 1865 | 1933 | if (in_array($option, $newOptions)) |
@@ -1873,8 +1941,8 @@ discard block |
||
| 1873 | 1941 | foreach ($optionChanges as $k => $option) |
| 1874 | 1942 | { |
| 1875 | 1943 | // Just been renamed? |
| 1876 | - if (!in_array($k, $takenKeys) && !empty($newOptions[$k])) |
|
| 1877 | - $smcFunc['db_query']('', ' |
|
| 1944 | + if (!in_array($k, $takenKeys) && !empty($newOptions[$k])) { |
|
| 1945 | + $smcFunc['db_query']('', ' |
|
| 1878 | 1946 | UPDATE {db_prefix}themes |
| 1879 | 1947 | SET value = {string:new_value} |
| 1880 | 1948 | WHERE variable = {string:current_column} |
@@ -1887,6 +1955,7 @@ discard block |
||
| 1887 | 1955 | 'old_value' => $option, |
| 1888 | 1956 | ) |
| 1889 | 1957 | ); |
| 1958 | + } |
|
| 1890 | 1959 | } |
| 1891 | 1960 | } |
| 1892 | 1961 | // @todo Maybe we should adjust based on new text length limits? |
@@ -1929,8 +1998,8 @@ discard block |
||
| 1929 | 1998 | ); |
| 1930 | 1999 | |
| 1931 | 2000 | // Just clean up any old selects - these are a pain! |
| 1932 | - if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions)) |
|
| 1933 | - $smcFunc['db_query']('', ' |
|
| 2001 | + if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions)) { |
|
| 2002 | + $smcFunc['db_query']('', ' |
|
| 1934 | 2003 | DELETE FROM {db_prefix}themes |
| 1935 | 2004 | WHERE variable = {string:current_column} |
| 1936 | 2005 | AND value NOT IN ({array_string:new_option_values}) |
@@ -1941,8 +2010,8 @@ discard block |
||
| 1941 | 2010 | 'current_column' => $context['field']['col_name'], |
| 1942 | 2011 | ) |
| 1943 | 2012 | ); |
| 1944 | - } |
|
| 1945 | - else |
|
| 2013 | + } |
|
| 2014 | + } else |
|
| 1946 | 2015 | { |
| 1947 | 2016 | // Gotta figure it out the order. |
| 1948 | 2017 | $new_order = $order_count > 1 ? ($order_count + 1) : 1; |
@@ -2116,11 +2185,13 @@ discard block |
||
| 2116 | 2185 | call_integration_hook('integrate_prune_settings', array(&$config_vars, &$prune_toggle, false)); |
| 2117 | 2186 | |
| 2118 | 2187 | $prune_toggle_dt = array(); |
| 2119 | - foreach ($prune_toggle as $item) |
|
| 2120 | - $prune_toggle_dt[] = 'setting_' . $item; |
|
| 2188 | + foreach ($prune_toggle as $item) { |
|
| 2189 | + $prune_toggle_dt[] = 'setting_' . $item; |
|
| 2190 | + } |
|
| 2121 | 2191 | |
| 2122 | - if ($return_config) |
|
| 2123 | - return $config_vars; |
|
| 2192 | + if ($return_config) { |
|
| 2193 | + return $config_vars; |
|
| 2194 | + } |
|
| 2124 | 2195 | |
| 2125 | 2196 | addInlineJavaScript(' |
| 2126 | 2197 | function togglePruned() |
@@ -2158,15 +2229,16 @@ discard block |
||
| 2158 | 2229 | $vals = array(); |
| 2159 | 2230 | foreach ($config_vars as $index => $dummy) |
| 2160 | 2231 | { |
| 2161 | - if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle)) |
|
| 2162 | - continue; |
|
| 2232 | + if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle)) { |
|
| 2233 | + continue; |
|
| 2234 | + } |
|
| 2163 | 2235 | |
| 2164 | 2236 | $vals[] = empty($_POST[$dummy[1]]) || $_POST[$dummy[1]] < 0 ? 0 : (int) $_POST[$dummy[1]]; |
| 2165 | 2237 | } |
| 2166 | 2238 | $_POST['pruningOptions'] = implode(',', $vals); |
| 2239 | + } else { |
|
| 2240 | + $_POST['pruningOptions'] = ''; |
|
| 2167 | 2241 | } |
| 2168 | - else |
|
| 2169 | - $_POST['pruningOptions'] = ''; |
|
| 2170 | 2242 | |
| 2171 | 2243 | saveDBSettings($savevar); |
| 2172 | 2244 | $_SESSION['adm-save'] = true; |
@@ -2178,10 +2250,11 @@ discard block |
||
| 2178 | 2250 | $context['sub_template'] = 'show_settings'; |
| 2179 | 2251 | |
| 2180 | 2252 | // Get the actual values |
| 2181 | - if (!empty($modSettings['pruningOptions'])) |
|
| 2182 | - @list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']); |
|
| 2183 | - else |
|
| 2184 | - $modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0; |
|
| 2253 | + if (!empty($modSettings['pruningOptions'])) { |
|
| 2254 | + @list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']); |
|
| 2255 | + } else { |
|
| 2256 | + $modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0; |
|
| 2257 | + } |
|
| 2185 | 2258 | |
| 2186 | 2259 | prepareDBSettingContext($config_vars); |
| 2187 | 2260 | } |
@@ -2203,8 +2276,9 @@ discard block |
||
| 2203 | 2276 | // Make it even easier to add new settings. |
| 2204 | 2277 | call_integration_hook('integrate_general_mod_settings', array(&$config_vars)); |
| 2205 | 2278 | |
| 2206 | - if ($return_config) |
|
| 2207 | - return $config_vars; |
|
| 2279 | + if ($return_config) { |
|
| 2280 | + return $config_vars; |
|
| 2281 | + } |
|
| 2208 | 2282 | |
| 2209 | 2283 | $context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=general'; |
| 2210 | 2284 | $context['settings_title'] = $txt['mods_cat_modifications_misc']; |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | $query_where = array(); |
| 167 | 167 | $query_params = $search_data['params']; |
| 168 | 168 | |
| 169 | - if( $smcFunc['db_title'] == "PostgreSQL") |
|
| 169 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
| 170 | 170 | $modSettings['search_simple_fulltext'] = true; |
| 171 | 171 | |
| 172 | 172 | if ($query_params['id_search']) |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | |
| 210 | 210 | if (!empty($modSettings['search_simple_fulltext'])) |
| 211 | 211 | { |
| 212 | - if($smcFunc['db_title'] == "PostgreSQL") |
|
| 212 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
| 213 | 213 | { |
| 214 | 214 | $language_ftx = $smcFunc['db_search_language'](); |
| 215 | 215 | |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | // remove any indexed words that are used in the complex body search terms |
| 228 | 228 | $words['indexed_words'] = array_diff($words['indexed_words'], $words['complex_words']); |
| 229 | 229 | |
| 230 | - if($smcFunc['db_title'] == "PostgreSQL"){ |
|
| 230 | + if ($smcFunc['db_title'] == "PostgreSQL") { |
|
| 231 | 231 | $row = 0; |
| 232 | 232 | foreach ($words['indexed_words'] as $fulltextWord) { |
| 233 | 233 | $query_params['boolean_match'] .= ($row <> 0 ? '&' : ''); |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | |
| 244 | 244 | // if we have bool terms to search, add them in |
| 245 | 245 | if ($query_params['boolean_match']) { |
| 246 | - if($smcFunc['db_title'] == "PostgreSQL") |
|
| 246 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
| 247 | 247 | { |
| 248 | 248 | $language_ftx = $smcFunc['db_search_language'](); |
| 249 | 249 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? ( ' |
|
| 259 | + $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? (' |
|
| 260 | 260 | INSERT IGNORE INTO {db_prefix}' . $search_data['insert_into'] . ' |
| 261 | 261 | (' . implode(', ', array_keys($query_select)) . ')') : '') . ' |
| 262 | 262 | 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 |
@@ -98,8 +99,9 @@ discard block |
||
| 98 | 99 | $smcFunc['db_free_result']($request); |
| 99 | 100 | } |
| 100 | 101 | // 4 is the MySQL default... |
| 101 | - else |
|
| 102 | - $min_word_length = 4; |
|
| 102 | + else { |
|
| 103 | + $min_word_length = 4; |
|
| 104 | + } |
|
| 103 | 105 | |
| 104 | 106 | return $min_word_length; |
| 105 | 107 | } |
@@ -138,8 +140,7 @@ discard block |
||
| 138 | 140 | $wordsSearch['words'][] = trim($word, "/*- "); |
| 139 | 141 | $wordsSearch['complex_words'][] = count($subwords) === 1 ? $word : '"' . $word . '"'; |
| 140 | 142 | } |
| 141 | - } |
|
| 142 | - elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
| 143 | + } elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
| 143 | 144 | { |
| 144 | 145 | // short words have feelings too |
| 145 | 146 | $wordsSearch['words'][] = trim($word, "/*- "); |
@@ -149,8 +150,9 @@ discard block |
||
| 149 | 150 | |
| 150 | 151 | $fulltextWord = count($subwords) === 1 ? $word : '"' . $word . '"'; |
| 151 | 152 | $wordsSearch['indexed_words'][] = $fulltextWord; |
| 152 | - if ($isExcluded) |
|
| 153 | - $wordsExclude[] = $fulltextWord; |
|
| 153 | + if ($isExcluded) { |
|
| 154 | + $wordsExclude[] = $fulltextWord; |
|
| 155 | + } |
|
| 154 | 156 | } |
| 155 | 157 | |
| 156 | 158 | /** |
@@ -166,44 +168,54 @@ discard block |
||
| 166 | 168 | $query_where = array(); |
| 167 | 169 | $query_params = $search_data['params']; |
| 168 | 170 | |
| 169 | - if( $smcFunc['db_title'] == "PostgreSQL") |
|
| 170 | - $modSettings['search_simple_fulltext'] = true; |
|
| 171 | + if( $smcFunc['db_title'] == "PostgreSQL") { |
|
| 172 | + $modSettings['search_simple_fulltext'] = true; |
|
| 173 | + } |
|
| 171 | 174 | |
| 172 | - if ($query_params['id_search']) |
|
| 173 | - $query_select['id_search'] = '{int:id_search}'; |
|
| 175 | + if ($query_params['id_search']) { |
|
| 176 | + $query_select['id_search'] = '{int:id_search}'; |
|
| 177 | + } |
|
| 174 | 178 | |
| 175 | 179 | $count = 0; |
| 176 | - if (empty($modSettings['search_simple_fulltext'])) |
|
| 177 | - foreach ($words['words'] as $regularWord) |
|
| 180 | + if (empty($modSettings['search_simple_fulltext'])) { |
|
| 181 | + foreach ($words['words'] as $regularWord) |
|
| 178 | 182 | { |
| 179 | 183 | $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 . '}'; |
| 184 | + } |
|
| 180 | 185 | $query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
| 181 | 186 | } |
| 182 | 187 | |
| 183 | - if ($query_params['user_query']) |
|
| 184 | - $query_where[] = '{raw:user_query}'; |
|
| 185 | - if ($query_params['board_query']) |
|
| 186 | - $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 188 | + if ($query_params['user_query']) { |
|
| 189 | + $query_where[] = '{raw:user_query}'; |
|
| 190 | + } |
|
| 191 | + if ($query_params['board_query']) { |
|
| 192 | + $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 193 | + } |
|
| 187 | 194 | |
| 188 | - if ($query_params['topic']) |
|
| 189 | - $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 190 | - if ($query_params['min_msg_id']) |
|
| 191 | - $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 192 | - if ($query_params['max_msg_id']) |
|
| 193 | - $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 195 | + if ($query_params['topic']) { |
|
| 196 | + $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 197 | + } |
|
| 198 | + if ($query_params['min_msg_id']) { |
|
| 199 | + $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 200 | + } |
|
| 201 | + if ($query_params['max_msg_id']) { |
|
| 202 | + $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 203 | + } |
|
| 194 | 204 | |
| 195 | 205 | $count = 0; |
| 196 | - if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) |
|
| 197 | - foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 206 | + if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) { |
|
| 207 | + foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 198 | 208 | { |
| 199 | 209 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_phrase_' . $count . '}'; |
| 210 | + } |
|
| 200 | 211 | $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), '\\\'') . '[[:>:]]'; |
| 201 | 212 | } |
| 202 | 213 | $count = 0; |
| 203 | - if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) |
|
| 204 | - foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 214 | + if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) { |
|
| 215 | + foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 205 | 216 | { |
| 206 | 217 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_words_' . $count . '}'; |
| 218 | + } |
|
| 207 | 219 | $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), '\\\'') . '[[:>:]]'; |
| 208 | 220 | } |
| 209 | 221 | |
@@ -215,12 +227,11 @@ discard block |
||
| 215 | 227 | |
| 216 | 228 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ plainto_tsquery({string:language_ftx},{string:body_match})'; |
| 217 | 229 | $query_params['language_ftx'] = $language_ftx; |
| 230 | + } else { |
|
| 231 | + $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
| 218 | 232 | } |
| 219 | - else |
|
| 220 | - $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
| 221 | 233 | $query_params['body_match'] = implode(' ', array_diff($words['indexed_words'], $query_params['excluded_index_words'])); |
| 222 | - } |
|
| 223 | - else |
|
| 234 | + } else |
|
| 224 | 235 | { |
| 225 | 236 | $query_params['boolean_match'] = ''; |
| 226 | 237 | |
@@ -234,10 +245,10 @@ discard block |
||
| 234 | 245 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' '; |
| 235 | 246 | $row++; |
| 236 | 247 | } |
| 237 | - } |
|
| 238 | - else |
|
| 239 | - foreach ($words['indexed_words'] as $fulltextWord) |
|
| 248 | + } else { |
|
| 249 | + foreach ($words['indexed_words'] as $fulltextWord) |
|
| 240 | 250 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' '; |
| 251 | + } |
|
| 241 | 252 | |
| 242 | 253 | $query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1); |
| 243 | 254 | |
@@ -249,9 +260,9 @@ discard block |
||
| 249 | 260 | |
| 250 | 261 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ plainto_tsquery({string:language_ftx},{string:boolean_match})'; |
| 251 | 262 | $query_params['language_ftx'] = $language_ftx; |
| 263 | + } else { |
|
| 264 | + $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
| 252 | 265 | } |
| 253 | - else |
|
| 254 | - $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
| 255 | 266 | } |
| 256 | 267 | |
| 257 | 268 | } |
@@ -256,8 +256,8 @@ discard block |
||
| 256 | 256 | $time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
| 257 | 257 | |
| 258 | 258 | $js_time_string = str_replace( |
| 259 | - array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r', '%R', '%S', '%T', '%X'), |
|
| 260 | - array('H', 'G', 'h', 'g', 'i', 'A', 'a', 'h:i:s A', 'H:i', 's', 'H:i:s', 'H:i:s'), |
|
| 259 | + array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r', '%R', '%S', '%T', '%X'), |
|
| 260 | + array('H', 'G', 'h', 'g', 'i', 'A', 'a', 'h:i:s A', 'H:i', 's', 'H:i:s', 'H:i:s'), |
|
| 261 | 261 | $time_string |
| 262 | 262 | ); |
| 263 | 263 | |
@@ -1305,14 +1305,14 @@ discard block |
||
| 1305 | 1305 | if (isset($context['name']) && isset($context['email'])) |
| 1306 | 1306 | { |
| 1307 | 1307 | $context['posting_fields']['guestname'] = array( |
| 1308 | - 'dt' => '<span id="caption_guestname"' . (isset($context['post_error']['long_name']) || isset($context['post_error']['no_name']) || isset($context['post_error']['bad_name']) ? ' class="error"' : '') . '>' . $txt['name'] . '</span>', |
|
| 1308 | + 'dt' => '<span id="caption_guestname"' . (isset($context['post_error']['long_name']) || isset($context['post_error']['no_name']) || isset($context['post_error']['bad_name']) ? ' class="error"' : '') . '>' . $txt['name'] . '</span>', |
|
| 1309 | 1309 | 'dd' => '<input type="text" name="guestname" size="25" value="' . $context['name'] . '" required>', |
| 1310 | 1310 | ); |
| 1311 | 1311 | |
| 1312 | 1312 | if (empty($modSettings['guest_post_no_email'])) |
| 1313 | 1313 | { |
| 1314 | 1314 | $context['posting_fields']['email'] = array( |
| 1315 | - 'dt' => '<span id="caption_email"' . (isset($context['post_error']['no_email']) || isset($context['post_error']['bad_email']) ? ' class="error"' : '') . '>' . $txt['email'] . '</span>', |
|
| 1315 | + 'dt' => '<span id="caption_email"' . (isset($context['post_error']['no_email']) || isset($context['post_error']['bad_email']) ? ' class="error"' : '') . '>' . $txt['email'] . '</span>', |
|
| 1316 | 1316 | 'dd' => '<input type="email" name="email" size="25" value="' . $context['email'] . '" required>', |
| 1317 | 1317 | ); |
| 1318 | 1318 | } |
@@ -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 | * Handles showing the post screen, loading the post to be modified, and loading any post quoted. |
@@ -35,12 +36,14 @@ discard block |
||
| 35 | 36 | global $sourcedir, $smcFunc, $language; |
| 36 | 37 | |
| 37 | 38 | loadLanguage('Post'); |
| 38 | - if (!empty($modSettings['drafts_post_enabled'])) |
|
| 39 | - loadLanguage('Drafts'); |
|
| 39 | + if (!empty($modSettings['drafts_post_enabled'])) { |
|
| 40 | + loadLanguage('Drafts'); |
|
| 41 | + } |
|
| 40 | 42 | |
| 41 | 43 | // You can't reply with a poll... hacker. |
| 42 | - if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) |
|
| 43 | - unset($_REQUEST['poll']); |
|
| 44 | + if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) { |
|
| 45 | + unset($_REQUEST['poll']); |
|
| 46 | + } |
|
| 44 | 47 | |
| 45 | 48 | // Posting an event? |
| 46 | 49 | $context['make_event'] = isset($_REQUEST['calendar']); |
@@ -58,12 +61,14 @@ discard block |
||
| 58 | 61 | { |
| 59 | 62 | // Get ids of all the boards they can post in. |
| 60 | 63 | $post_permissions = array('post_new'); |
| 61 | - if ($modSettings['postmod_active']) |
|
| 62 | - $post_permissions[] = 'post_unapproved_topics'; |
|
| 64 | + if ($modSettings['postmod_active']) { |
|
| 65 | + $post_permissions[] = 'post_unapproved_topics'; |
|
| 66 | + } |
|
| 63 | 67 | |
| 64 | 68 | $boards = boardsAllowedTo($post_permissions); |
| 65 | - if (empty($boards)) |
|
| 66 | - fatal_lang_error('cannot_post_new', false); |
|
| 69 | + if (empty($boards)) { |
|
| 70 | + fatal_lang_error('cannot_post_new', false); |
|
| 71 | + } |
|
| 67 | 72 | |
| 68 | 73 | // Get a list of boards for the select menu |
| 69 | 74 | require_once($sourcedir . '/Subs-MessageIndex.php'); |
@@ -76,8 +81,9 @@ discard block |
||
| 76 | 81 | $board_list = getBoardList($boardListOptions); |
| 77 | 82 | } |
| 78 | 83 | // Let's keep things simple for ourselves below |
| 79 | - else |
|
| 80 | - $boards = array($board); |
|
| 84 | + else { |
|
| 85 | + $boards = array($board); |
|
| 86 | + } |
|
| 81 | 87 | |
| 82 | 88 | require_once($sourcedir . '/Subs-Post.php'); |
| 83 | 89 | |
@@ -100,10 +106,11 @@ discard block |
||
| 100 | 106 | array( |
| 101 | 107 | 'msg' => (int) $_REQUEST['msg'], |
| 102 | 108 | )); |
| 103 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
| 104 | - unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']); |
|
| 105 | - else |
|
| 106 | - list ($topic) = $smcFunc['db_fetch_row']($request); |
|
| 109 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
| 110 | + unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']); |
|
| 111 | + } else { |
|
| 112 | + list ($topic) = $smcFunc['db_fetch_row']($request); |
|
| 113 | + } |
|
| 107 | 114 | $smcFunc['db_free_result']($request); |
| 108 | 115 | } |
| 109 | 116 | |
@@ -130,33 +137,36 @@ discard block |
||
| 130 | 137 | $smcFunc['db_free_result']($request); |
| 131 | 138 | |
| 132 | 139 | // If this topic already has a poll, they sure can't add another. |
| 133 | - if (isset($_REQUEST['poll']) && $pollID > 0) |
|
| 134 | - unset($_REQUEST['poll']); |
|
| 140 | + if (isset($_REQUEST['poll']) && $pollID > 0) { |
|
| 141 | + unset($_REQUEST['poll']); |
|
| 142 | + } |
|
| 135 | 143 | |
| 136 | 144 | if (empty($_REQUEST['msg'])) |
| 137 | 145 | { |
| 138 | - if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) |
|
| 139 | - is_not_guest(); |
|
| 146 | + if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) { |
|
| 147 | + is_not_guest(); |
|
| 148 | + } |
|
| 140 | 149 | |
| 141 | 150 | // By default the reply will be approved... |
| 142 | 151 | $context['becomes_approved'] = true; |
| 143 | 152 | if ($id_member_poster != $user_info['id'] || $user_info['is_guest']) |
| 144 | 153 | { |
| 145 | - if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) |
|
| 146 | - $context['becomes_approved'] = false; |
|
| 147 | - else |
|
| 148 | - isAllowedTo('post_reply_any'); |
|
| 149 | - } |
|
| 150 | - elseif (!allowedTo('post_reply_any')) |
|
| 154 | + if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) { |
|
| 155 | + $context['becomes_approved'] = false; |
|
| 156 | + } else { |
|
| 157 | + isAllowedTo('post_reply_any'); |
|
| 158 | + } |
|
| 159 | + } elseif (!allowedTo('post_reply_any')) |
|
| 151 | 160 | { |
| 152 | - if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) |
|
| 153 | - $context['becomes_approved'] = false; |
|
| 154 | - else |
|
| 155 | - isAllowedTo('post_reply_own'); |
|
| 161 | + if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) { |
|
| 162 | + $context['becomes_approved'] = false; |
|
| 163 | + } else { |
|
| 164 | + isAllowedTo('post_reply_own'); |
|
| 165 | + } |
|
| 156 | 166 | } |
| 167 | + } else { |
|
| 168 | + $context['becomes_approved'] = true; |
|
| 157 | 169 | } |
| 158 | - else |
|
| 159 | - $context['becomes_approved'] = true; |
|
| 160 | 170 | |
| 161 | 171 | $context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own')); |
| 162 | 172 | $context['can_sticky'] = allowedTo('make_sticky'); |
@@ -171,17 +181,18 @@ discard block |
||
| 171 | 181 | $context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky; |
| 172 | 182 | |
| 173 | 183 | // Check whether this is a really old post being bumped... |
| 174 | - if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) |
|
| 175 | - $post_errors[] = array('old_topic', array($modSettings['oldTopicDays'])); |
|
| 176 | - } |
|
| 177 | - else |
|
| 184 | + if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) { |
|
| 185 | + $post_errors[] = array('old_topic', array($modSettings['oldTopicDays'])); |
|
| 186 | + } |
|
| 187 | + } else |
|
| 178 | 188 | { |
| 179 | 189 | // @todo Should use JavaScript to hide and show the warning based on the selection in the board select menu |
| 180 | 190 | $context['becomes_approved'] = true; |
| 181 | - if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true)) |
|
| 182 | - $context['becomes_approved'] = false; |
|
| 183 | - else |
|
| 184 | - isAllowedTo('post_new', $boards, true); |
|
| 191 | + if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true)) { |
|
| 192 | + $context['becomes_approved'] = false; |
|
| 193 | + } else { |
|
| 194 | + isAllowedTo('post_new', $boards, true); |
|
| 195 | + } |
|
| 185 | 196 | |
| 186 | 197 | $locked = 0; |
| 187 | 198 | $context['already_locked'] = 0; |
@@ -211,27 +222,32 @@ discard block |
||
| 211 | 222 | if (empty($_REQUEST['message']) && empty($_REQUEST['preview']) && !empty($_SESSION['already_attached'])) |
| 212 | 223 | { |
| 213 | 224 | require_once($sourcedir . '/ManageAttachments.php'); |
| 214 | - foreach ($_SESSION['already_attached'] as $attachID => $attachment) |
|
| 215 | - removeAttachments(array('id_attach' => $attachID)); |
|
| 225 | + foreach ($_SESSION['already_attached'] as $attachID => $attachment) { |
|
| 226 | + removeAttachments(array('id_attach' => $attachID)); |
|
| 227 | + } |
|
| 216 | 228 | |
| 217 | 229 | unset($_SESSION['already_attached']); |
| 218 | 230 | } |
| 219 | 231 | |
| 220 | 232 | // Don't allow a post if it's locked and you aren't all powerful. |
| 221 | - if ($locked && !allowedTo('moderate_board')) |
|
| 222 | - fatal_lang_error('topic_locked', false); |
|
| 233 | + if ($locked && !allowedTo('moderate_board')) { |
|
| 234 | + fatal_lang_error('topic_locked', false); |
|
| 235 | + } |
|
| 223 | 236 | // Check the users permissions - is the user allowed to add or post a poll? |
| 224 | 237 | if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1') |
| 225 | 238 | { |
| 226 | 239 | // New topic, new poll. |
| 227 | - if (empty($topic)) |
|
| 228 | - isAllowedTo('poll_post'); |
|
| 240 | + if (empty($topic)) { |
|
| 241 | + isAllowedTo('poll_post'); |
|
| 242 | + } |
|
| 229 | 243 | // This is an old topic - but it is yours! Can you add to it? |
| 230 | - elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) |
|
| 231 | - isAllowedTo('poll_add_own'); |
|
| 244 | + elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) { |
|
| 245 | + isAllowedTo('poll_add_own'); |
|
| 246 | + } |
|
| 232 | 247 | // If you're not the owner, can you add to any poll? |
| 233 | - else |
|
| 234 | - isAllowedTo('poll_add_any'); |
|
| 248 | + else { |
|
| 249 | + isAllowedTo('poll_add_any'); |
|
| 250 | + } |
|
| 235 | 251 | |
| 236 | 252 | if (!empty($board)) |
| 237 | 253 | { |
@@ -240,8 +256,9 @@ discard block |
||
| 240 | 256 | $guest_vote_enabled = in_array(-1, $allowedVoteGroups['allowed']); |
| 241 | 257 | } |
| 242 | 258 | // No board, so we'll have to check this again in Post2 |
| 243 | - else |
|
| 244 | - $guest_vote_enabled = true; |
|
| 259 | + else { |
|
| 260 | + $guest_vote_enabled = true; |
|
| 261 | + } |
|
| 245 | 262 | |
| 246 | 263 | // Set up the poll options. |
| 247 | 264 | $context['poll_options'] = array( |
@@ -267,8 +284,9 @@ discard block |
||
| 267 | 284 | if ($context['make_event']) |
| 268 | 285 | { |
| 269 | 286 | // They might want to pick a board. |
| 270 | - if (!isset($context['current_board'])) |
|
| 271 | - $context['current_board'] = 0; |
|
| 287 | + if (!isset($context['current_board'])) { |
|
| 288 | + $context['current_board'] = 0; |
|
| 289 | + } |
|
| 272 | 290 | |
| 273 | 291 | // Start loading up the event info. |
| 274 | 292 | $context['event'] = array(); |
@@ -282,10 +300,11 @@ discard block |
||
| 282 | 300 | isAllowedTo('calendar_post'); |
| 283 | 301 | |
| 284 | 302 | // We want a fairly compact version of the time, but as close as possible to the user's settings. |
| 285 | - if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
| 286 | - $time_string = '%k:%M'; |
|
| 287 | - else |
|
| 288 | - $time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
| 303 | + if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
| 304 | + $time_string = '%k:%M'; |
|
| 305 | + } else { |
|
| 306 | + $time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
| 307 | + } |
|
| 289 | 308 | |
| 290 | 309 | $js_time_string = str_replace( |
| 291 | 310 | array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r', '%R', '%S', '%T', '%X'), |
@@ -307,8 +326,7 @@ discard block |
||
| 307 | 326 | require_once($sourcedir . '/Subs-Calendar.php'); |
| 308 | 327 | $eventProperties = getEventProperties($context['event']['id']); |
| 309 | 328 | $context['event'] = array_merge($context['event'], $eventProperties); |
| 310 | - } |
|
| 311 | - else |
|
| 329 | + } else |
|
| 312 | 330 | { |
| 313 | 331 | // Get the current event information. |
| 314 | 332 | require_once($sourcedir . '/Subs-Calendar.php'); |
@@ -316,10 +334,12 @@ discard block |
||
| 316 | 334 | $context['event'] = array_merge($context['event'], $eventProperties); |
| 317 | 335 | |
| 318 | 336 | // Make sure the year and month are in the valid range. |
| 319 | - if ($context['event']['month'] < 1 || $context['event']['month'] > 12) |
|
| 320 | - fatal_lang_error('invalid_month', false); |
|
| 321 | - if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) |
|
| 322 | - fatal_lang_error('invalid_year', false); |
|
| 337 | + if ($context['event']['month'] < 1 || $context['event']['month'] > 12) { |
|
| 338 | + fatal_lang_error('invalid_month', false); |
|
| 339 | + } |
|
| 340 | + if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) { |
|
| 341 | + fatal_lang_error('invalid_year', false); |
|
| 342 | + } |
|
| 323 | 343 | |
| 324 | 344 | $context['event']['categories'] = $board_list; |
| 325 | 345 | } |
@@ -430,10 +450,11 @@ discard block |
||
| 430 | 450 | |
| 431 | 451 | if (!empty($context['new_replies'])) |
| 432 | 452 | { |
| 433 | - if ($context['new_replies'] == 1) |
|
| 434 | - $txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply']; |
|
| 435 | - else |
|
| 436 | - $txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']); |
|
| 453 | + if ($context['new_replies'] == 1) { |
|
| 454 | + $txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply']; |
|
| 455 | + } else { |
|
| 456 | + $txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']); |
|
| 457 | + } |
|
| 437 | 458 | |
| 438 | 459 | $post_errors[] = 'new_replies'; |
| 439 | 460 | |
@@ -445,9 +466,9 @@ discard block |
||
| 445 | 466 | // Get a response prefix (like 'Re:') in the default forum language. |
| 446 | 467 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
| 447 | 468 | { |
| 448 | - if ($language === $user_info['language']) |
|
| 449 | - $context['response_prefix'] = $txt['response_prefix']; |
|
| 450 | - else |
|
| 469 | + if ($language === $user_info['language']) { |
|
| 470 | + $context['response_prefix'] = $txt['response_prefix']; |
|
| 471 | + } else |
|
| 451 | 472 | { |
| 452 | 473 | loadLanguage('index', $language, false); |
| 453 | 474 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -460,23 +481,26 @@ discard block |
||
| 460 | 481 | // Do we have a body, but an error happened. |
| 461 | 482 | if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error'])) |
| 462 | 483 | { |
| 463 | - if (isset($_REQUEST['quickReply'])) |
|
| 464 | - $_REQUEST['message'] = $_REQUEST['quickReply']; |
|
| 484 | + if (isset($_REQUEST['quickReply'])) { |
|
| 485 | + $_REQUEST['message'] = $_REQUEST['quickReply']; |
|
| 486 | + } |
|
| 465 | 487 | |
| 466 | 488 | // Validate inputs. |
| 467 | 489 | if (empty($context['post_error'])) |
| 468 | 490 | { |
| 469 | 491 | // This means they didn't click Post and get an error. |
| 470 | 492 | $really_previewing = true; |
| 471 | - } |
|
| 472 | - else |
|
| 493 | + } else |
|
| 473 | 494 | { |
| 474 | - if (!isset($_REQUEST['subject'])) |
|
| 475 | - $_REQUEST['subject'] = ''; |
|
| 476 | - if (!isset($_REQUEST['message'])) |
|
| 477 | - $_REQUEST['message'] = ''; |
|
| 478 | - if (!isset($_REQUEST['icon'])) |
|
| 479 | - $_REQUEST['icon'] = 'xx'; |
|
| 495 | + if (!isset($_REQUEST['subject'])) { |
|
| 496 | + $_REQUEST['subject'] = ''; |
|
| 497 | + } |
|
| 498 | + if (!isset($_REQUEST['message'])) { |
|
| 499 | + $_REQUEST['message'] = ''; |
|
| 500 | + } |
|
| 501 | + if (!isset($_REQUEST['icon'])) { |
|
| 502 | + $_REQUEST['icon'] = 'xx'; |
|
| 503 | + } |
|
| 480 | 504 | |
| 481 | 505 | // They are previewing if they asked to preview (i.e. came from quick reply). |
| 482 | 506 | $really_previewing = !empty($_POST['preview']); |
@@ -492,8 +516,9 @@ discard block |
||
| 492 | 516 | $form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES); |
| 493 | 517 | |
| 494 | 518 | // Make sure the subject isn't too long - taking into account special characters. |
| 495 | - if ($smcFunc['strlen']($form_subject) > 100) |
|
| 496 | - $form_subject = $smcFunc['substr']($form_subject, 0, 100); |
|
| 519 | + if ($smcFunc['strlen']($form_subject) > 100) { |
|
| 520 | + $form_subject = $smcFunc['substr']($form_subject, 0, 100); |
|
| 521 | + } |
|
| 497 | 522 | |
| 498 | 523 | if (isset($_REQUEST['poll'])) |
| 499 | 524 | { |
@@ -505,8 +530,9 @@ discard block |
||
| 505 | 530 | $_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']); |
| 506 | 531 | foreach ($_POST['options'] as $option) |
| 507 | 532 | { |
| 508 | - if (trim($option) == '') |
|
| 509 | - continue; |
|
| 533 | + if (trim($option) == '') { |
|
| 534 | + continue; |
|
| 535 | + } |
|
| 510 | 536 | |
| 511 | 537 | $context['choices'][] = array( |
| 512 | 538 | 'id' => $choice_id++, |
@@ -568,13 +594,14 @@ discard block |
||
| 568 | 594 | $context['preview_subject'] = $form_subject; |
| 569 | 595 | |
| 570 | 596 | censorText($context['preview_subject']); |
| 597 | + } else { |
|
| 598 | + $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>'; |
|
| 571 | 599 | } |
| 572 | - else |
|
| 573 | - $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>'; |
|
| 574 | 600 | |
| 575 | 601 | // Protect any CDATA blocks. |
| 576 | - if (isset($_REQUEST['xml'])) |
|
| 577 | - $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>')); |
|
| 602 | + if (isset($_REQUEST['xml'])) { |
|
| 603 | + $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]>< == 0) |
|
| 617 | - fatal_lang_error('no_board', false); |
|
| 643 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 644 | + fatal_lang_error('no_board', false); |
|
| 645 | + } |
|
| 618 | 646 | $row = $smcFunc['db_fetch_assoc']($request); |
| 619 | 647 | |
| 620 | 648 | $attachment_stuff = array($row); |
| 621 | - while ($row2 = $smcFunc['db_fetch_assoc']($request)) |
|
| 622 | - $attachment_stuff[] = $row2; |
|
| 649 | + while ($row2 = $smcFunc['db_fetch_assoc']($request)) { |
|
| 650 | + $attachment_stuff[] = $row2; |
|
| 651 | + } |
|
| 623 | 652 | $smcFunc['db_free_result']($request); |
| 624 | 653 | |
| 625 | 654 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
| 626 | 655 | { |
| 627 | 656 | // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public. |
| 628 | - if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
| 629 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 630 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) |
|
| 631 | - isAllowedTo('modify_replies'); |
|
| 632 | - else |
|
| 633 | - isAllowedTo('modify_own'); |
|
| 657 | + if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
| 658 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 659 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
| 660 | + isAllowedTo('modify_replies'); |
|
| 661 | + } else { |
|
| 662 | + isAllowedTo('modify_own'); |
|
| 663 | + } |
|
| 664 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) { |
|
| 665 | + isAllowedTo('modify_replies'); |
|
| 666 | + } else { |
|
| 667 | + isAllowedTo('modify_any'); |
|
| 634 | 668 | } |
| 635 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 636 | - isAllowedTo('modify_replies'); |
|
| 637 | - else |
|
| 638 | - isAllowedTo('modify_any'); |
|
| 639 | 669 | |
| 640 | 670 | if ($context['can_announce'] && !empty($row['id_action'])) |
| 641 | 671 | { |
@@ -659,8 +689,9 @@ discard block |
||
| 659 | 689 | |
| 660 | 690 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 661 | 691 | { |
| 662 | - if ($row['filesize'] <= 0) |
|
| 663 | - continue; |
|
| 692 | + if ($row['filesize'] <= 0) { |
|
| 693 | + continue; |
|
| 694 | + } |
|
| 664 | 695 | $context['current_attachments'][$row['id_attach']] = array( |
| 665 | 696 | 'name' => $smcFunc['htmlspecialchars']($row['filename']), |
| 666 | 697 | 'size' => $row['filesize'], |
@@ -730,29 +761,32 @@ discard block |
||
| 730 | 761 | ) |
| 731 | 762 | ); |
| 732 | 763 | // The message they were trying to edit was most likely deleted. |
| 733 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 734 | - fatal_lang_error('no_message', false); |
|
| 764 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 765 | + fatal_lang_error('no_message', false); |
|
| 766 | + } |
|
| 735 | 767 | $row = $smcFunc['db_fetch_assoc']($request); |
| 736 | 768 | |
| 737 | 769 | $attachment_stuff = array($row); |
| 738 | - while ($row2 = $smcFunc['db_fetch_assoc']($request)) |
|
| 739 | - $attachment_stuff[] = $row2; |
|
| 770 | + while ($row2 = $smcFunc['db_fetch_assoc']($request)) { |
|
| 771 | + $attachment_stuff[] = $row2; |
|
| 772 | + } |
|
| 740 | 773 | $smcFunc['db_free_result']($request); |
| 741 | 774 | |
| 742 | 775 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
| 743 | 776 | { |
| 744 | 777 | // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public. |
| 745 | - if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
| 746 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 747 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) |
|
| 748 | - isAllowedTo('modify_replies'); |
|
| 749 | - else |
|
| 750 | - isAllowedTo('modify_own'); |
|
| 778 | + if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
| 779 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 780 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
| 781 | + isAllowedTo('modify_replies'); |
|
| 782 | + } else { |
|
| 783 | + isAllowedTo('modify_own'); |
|
| 784 | + } |
|
| 785 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) { |
|
| 786 | + isAllowedTo('modify_replies'); |
|
| 787 | + } else { |
|
| 788 | + isAllowedTo('modify_any'); |
|
| 751 | 789 | } |
| 752 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 753 | - isAllowedTo('modify_replies'); |
|
| 754 | - else |
|
| 755 | - isAllowedTo('modify_any'); |
|
| 756 | 790 | |
| 757 | 791 | if ($context['can_announce'] && !empty($row['id_action'])) |
| 758 | 792 | { |
@@ -779,15 +813,17 @@ discard block |
||
| 779 | 813 | $context['icon'] = $row['icon']; |
| 780 | 814 | |
| 781 | 815 | // Show an "approve" box if the user can approve it, and the message isn't approved. |
| 782 | - if (!$row['approved'] && !$context['show_approval']) |
|
| 783 | - $context['show_approval'] = allowedTo('approve_posts'); |
|
| 816 | + if (!$row['approved'] && !$context['show_approval']) { |
|
| 817 | + $context['show_approval'] = allowedTo('approve_posts'); |
|
| 818 | + } |
|
| 784 | 819 | |
| 785 | 820 | // Sort the attachments so they are in the order saved |
| 786 | 821 | $temp = array(); |
| 787 | 822 | foreach ($attachment_stuff as $attachment) |
| 788 | 823 | { |
| 789 | - if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) |
|
| 790 | - $temp[$attachment['id_attach']] = $attachment; |
|
| 824 | + if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) { |
|
| 825 | + $temp[$attachment['id_attach']] = $attachment; |
|
| 826 | + } |
|
| 791 | 827 | |
| 792 | 828 | } |
| 793 | 829 | ksort($temp); |
@@ -849,14 +885,16 @@ discard block |
||
| 849 | 885 | 'is_approved' => 1, |
| 850 | 886 | ) |
| 851 | 887 | ); |
| 852 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 853 | - fatal_lang_error('quoted_post_deleted', false); |
|
| 888 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 889 | + fatal_lang_error('quoted_post_deleted', false); |
|
| 890 | + } |
|
| 854 | 891 | list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request); |
| 855 | 892 | $smcFunc['db_free_result']($request); |
| 856 | 893 | |
| 857 | 894 | // Add 'Re: ' to the front of the quoted subject. |
| 858 | - if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
|
| 859 | - $form_subject = $context['response_prefix'] . $form_subject; |
|
| 895 | + if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) { |
|
| 896 | + $form_subject = $context['response_prefix'] . $form_subject; |
|
| 897 | + } |
|
| 860 | 898 | |
| 861 | 899 | // Censor the message and subject. |
| 862 | 900 | censorText($form_message); |
@@ -869,10 +907,11 @@ discard block |
||
| 869 | 907 | for ($i = 0, $n = count($parts); $i < $n; $i++) |
| 870 | 908 | { |
| 871 | 909 | // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat. |
| 872 | - if ($i % 4 == 0) |
|
| 873 | - $parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) |
|
| 910 | + if ($i % 4 == 0) { |
|
| 911 | + $parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) |
|
| 874 | 912 | { |
| 875 | 913 | return '[html]' . preg_replace('~<br\s?/?' . '>~i', '<br /><br>', "$m[1]") . '[/html]'; |
| 914 | + } |
|
| 876 | 915 | }, $parts[$i]); |
| 877 | 916 | } |
| 878 | 917 | $form_message = implode('', $parts); |
@@ -881,8 +920,9 @@ discard block |
||
| 881 | 920 | $form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message); |
| 882 | 921 | |
| 883 | 922 | // Remove any nested quotes, if necessary. |
| 884 | - if (!empty($modSettings['removeNestedQuotes'])) |
|
| 885 | - $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
| 923 | + if (!empty($modSettings['removeNestedQuotes'])) { |
|
| 924 | + $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
| 925 | + } |
|
| 886 | 926 | |
| 887 | 927 | // Add a quote string on the front and end. |
| 888 | 928 | $form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]'; |
@@ -894,15 +934,15 @@ discard block |
||
| 894 | 934 | $form_subject = $first_subject; |
| 895 | 935 | |
| 896 | 936 | // Add 'Re: ' to the front of the subject. |
| 897 | - if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
|
| 898 | - $form_subject = $context['response_prefix'] . $form_subject; |
|
| 937 | + if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) { |
|
| 938 | + $form_subject = $context['response_prefix'] . $form_subject; |
|
| 939 | + } |
|
| 899 | 940 | |
| 900 | 941 | // Censor the subject. |
| 901 | 942 | censorText($form_subject); |
| 902 | 943 | |
| 903 | 944 | $form_message = ''; |
| 904 | - } |
|
| 905 | - else |
|
| 945 | + } else |
|
| 906 | 946 | { |
| 907 | 947 | $form_subject = isset($_GET['subject']) ? $_GET['subject'] : ''; |
| 908 | 948 | $form_message = ''; |
@@ -921,13 +961,15 @@ discard block |
||
| 921 | 961 | if (isset($_REQUEST['msg'])) |
| 922 | 962 | { |
| 923 | 963 | $context['attachments']['quantity'] = count($context['current_attachments']); |
| 924 | - foreach ($context['current_attachments'] as $attachment) |
|
| 925 | - $context['attachments']['total_size'] += $attachment['size']; |
|
| 964 | + foreach ($context['current_attachments'] as $attachment) { |
|
| 965 | + $context['attachments']['total_size'] += $attachment['size']; |
|
| 966 | + } |
|
| 926 | 967 | } |
| 927 | 968 | |
| 928 | 969 | // A bit of house keeping first. |
| 929 | - if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) |
|
| 930 | - unset($_SESSION['temp_attachments']); |
|
| 970 | + if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) { |
|
| 971 | + unset($_SESSION['temp_attachments']); |
|
| 972 | + } |
|
| 931 | 973 | |
| 932 | 974 | if (!empty($_SESSION['temp_attachments'])) |
| 933 | 975 | { |
@@ -936,9 +978,10 @@ discard block |
||
| 936 | 978 | { |
| 937 | 979 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
| 938 | 980 | { |
| 939 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
| 940 | - if (file_exists($attachment['tmp_name'])) |
|
| 981 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) { |
|
| 982 | + if (file_exists($attachment['tmp_name'])) |
|
| 941 | 983 | unlink($attachment['tmp_name']); |
| 984 | + } |
|
| 942 | 985 | } |
| 943 | 986 | $post_errors[] = 'temp_attachments_gone'; |
| 944 | 987 | $_SESSION['temp_attachments'] = array(); |
@@ -952,8 +995,9 @@ discard block |
||
| 952 | 995 | // See if any files still exist before showing the warning message and the files attached. |
| 953 | 996 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
| 954 | 997 | { |
| 955 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
|
| 956 | - continue; |
|
| 998 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { |
|
| 999 | + continue; |
|
| 1000 | + } |
|
| 957 | 1001 | |
| 958 | 1002 | if (file_exists($attachment['tmp_name'])) |
| 959 | 1003 | { |
@@ -963,20 +1007,21 @@ discard block |
||
| 963 | 1007 | break; |
| 964 | 1008 | } |
| 965 | 1009 | } |
| 966 | - } |
|
| 967 | - else |
|
| 1010 | + } else |
|
| 968 | 1011 | { |
| 969 | 1012 | // Since, they don't belong here. Let's inform the user that they exist.. |
| 970 | - if (!empty($topic)) |
|
| 971 | - $delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp'; |
|
| 972 | - else |
|
| 973 | - $delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp'; |
|
| 1013 | + if (!empty($topic)) { |
|
| 1014 | + $delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp'; |
|
| 1015 | + } else { |
|
| 1016 | + $delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp'; |
|
| 1017 | + } |
|
| 974 | 1018 | |
| 975 | 1019 | // Compile a list of the files to show the user. |
| 976 | 1020 | $file_list = array(); |
| 977 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
| 978 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
| 1021 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) { |
|
| 1022 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
| 979 | 1023 | $file_list[] = $attachment['name']; |
| 1024 | + } |
|
| 980 | 1025 | |
| 981 | 1026 | $_SESSION['temp_attachments']['post']['files'] = $file_list; |
| 982 | 1027 | $file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>'; |
@@ -988,8 +1033,7 @@ discard block |
||
| 988 | 1033 | |
| 989 | 1034 | $post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list)); |
| 990 | 1035 | $context['ignore_temp_attachments'] = true; |
| 991 | - } |
|
| 992 | - else |
|
| 1036 | + } else |
|
| 993 | 1037 | { |
| 994 | 1038 | $post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list)); |
| 995 | 1039 | $context['ignore_temp_attachments'] = true; |
@@ -997,16 +1041,19 @@ discard block |
||
| 997 | 1041 | } |
| 998 | 1042 | } |
| 999 | 1043 | |
| 1000 | - if (!empty($context['we_are_history'])) |
|
| 1001 | - $post_errors[] = $context['we_are_history']; |
|
| 1044 | + if (!empty($context['we_are_history'])) { |
|
| 1045 | + $post_errors[] = $context['we_are_history']; |
|
| 1046 | + } |
|
| 1002 | 1047 | |
| 1003 | 1048 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
| 1004 | 1049 | { |
| 1005 | - if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) |
|
| 1006 | - break; |
|
| 1050 | + if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) { |
|
| 1051 | + break; |
|
| 1052 | + } |
|
| 1007 | 1053 | |
| 1008 | - if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
|
| 1009 | - continue; |
|
| 1054 | + if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { |
|
| 1055 | + continue; |
|
| 1056 | + } |
|
| 1010 | 1057 | |
| 1011 | 1058 | if ($attachID == 'initial_error') |
| 1012 | 1059 | { |
@@ -1021,15 +1068,17 @@ discard block |
||
| 1021 | 1068 | { |
| 1022 | 1069 | $txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : ''; |
| 1023 | 1070 | $txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">'; |
| 1024 | - foreach ($attachment['errors'] as $error) |
|
| 1025 | - $txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >'; |
|
| 1071 | + foreach ($attachment['errors'] as $error) { |
|
| 1072 | + $txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >'; |
|
| 1073 | + } |
|
| 1026 | 1074 | $txt['error_attach_errors'] .= '</div>'; |
| 1027 | 1075 | $post_errors[] = 'attach_errors'; |
| 1028 | 1076 | |
| 1029 | 1077 | // Take out the trash. |
| 1030 | 1078 | unset($_SESSION['temp_attachments'][$attachID]); |
| 1031 | - if (file_exists($attachment['tmp_name'])) |
|
| 1032 | - unlink($attachment['tmp_name']); |
|
| 1079 | + if (file_exists($attachment['tmp_name'])) { |
|
| 1080 | + unlink($attachment['tmp_name']); |
|
| 1081 | + } |
|
| 1033 | 1082 | continue; |
| 1034 | 1083 | } |
| 1035 | 1084 | |
@@ -1042,8 +1091,9 @@ discard block |
||
| 1042 | 1091 | |
| 1043 | 1092 | $context['attachments']['quantity']++; |
| 1044 | 1093 | $context['attachments']['total_size'] += $attachment['size']; |
| 1045 | - if (!isset($context['files_in_session_warning'])) |
|
| 1046 | - $context['files_in_session_warning'] = $txt['attached_files_in_session']; |
|
| 1094 | + if (!isset($context['files_in_session_warning'])) { |
|
| 1095 | + $context['files_in_session_warning'] = $txt['attached_files_in_session']; |
|
| 1096 | + } |
|
| 1047 | 1097 | |
| 1048 | 1098 | $context['current_attachments'][$attachID] = array( |
| 1049 | 1099 | 'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>', |
@@ -1071,8 +1121,9 @@ discard block |
||
| 1071 | 1121 | } |
| 1072 | 1122 | |
| 1073 | 1123 | // If they came from quick reply, and have to enter verification details, give them some notice. |
| 1074 | - if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) |
|
| 1075 | - $post_errors[] = 'need_qr_verification'; |
|
| 1124 | + if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) { |
|
| 1125 | + $post_errors[] = 'need_qr_verification'; |
|
| 1126 | + } |
|
| 1076 | 1127 | |
| 1077 | 1128 | /* |
| 1078 | 1129 | * There are two error types: serious and minor. Serious errors |
@@ -1089,52 +1140,56 @@ discard block |
||
| 1089 | 1140 | { |
| 1090 | 1141 | loadLanguage('Errors'); |
| 1091 | 1142 | $context['error_type'] = 'minor'; |
| 1092 | - foreach ($post_errors as $post_error) |
|
| 1093 | - if (is_array($post_error)) |
|
| 1143 | + foreach ($post_errors as $post_error) { |
|
| 1144 | + if (is_array($post_error)) |
|
| 1094 | 1145 | { |
| 1095 | 1146 | $post_error_id = $post_error[0]; |
| 1147 | + } |
|
| 1096 | 1148 | $context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]); |
| 1097 | 1149 | |
| 1098 | 1150 | // If it's not a minor error flag it as such. |
| 1099 | - if (!in_array($post_error_id, $minor_errors)) |
|
| 1100 | - $context['error_type'] = 'serious'; |
|
| 1101 | - } |
|
| 1102 | - else |
|
| 1151 | + if (!in_array($post_error_id, $minor_errors)) { |
|
| 1152 | + $context['error_type'] = 'serious'; |
|
| 1153 | + } |
|
| 1154 | + } else |
|
| 1103 | 1155 | { |
| 1104 | 1156 | $context['post_error'][$post_error] = $txt['error_' . $post_error]; |
| 1105 | 1157 | |
| 1106 | 1158 | // If it's not a minor error flag it as such. |
| 1107 | - if (!in_array($post_error, $minor_errors)) |
|
| 1108 | - $context['error_type'] = 'serious'; |
|
| 1159 | + if (!in_array($post_error, $minor_errors)) { |
|
| 1160 | + $context['error_type'] = 'serious'; |
|
| 1161 | + } |
|
| 1109 | 1162 | } |
| 1110 | 1163 | } |
| 1111 | 1164 | |
| 1112 | 1165 | // What are you doing? Posting a poll, modifying, previewing, new post, or reply... |
| 1113 | - if (isset($_REQUEST['poll'])) |
|
| 1114 | - $context['page_title'] = $txt['new_poll']; |
|
| 1115 | - elseif ($context['make_event']) |
|
| 1116 | - $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit']; |
|
| 1117 | - elseif (isset($_REQUEST['msg'])) |
|
| 1118 | - $context['page_title'] = $txt['modify_msg']; |
|
| 1119 | - elseif (isset($_REQUEST['subject'], $context['preview_subject'])) |
|
| 1120 | - $context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']); |
|
| 1121 | - elseif (empty($topic)) |
|
| 1122 | - $context['page_title'] = $txt['start_new_topic']; |
|
| 1123 | - else |
|
| 1124 | - $context['page_title'] = $txt['post_reply']; |
|
| 1166 | + if (isset($_REQUEST['poll'])) { |
|
| 1167 | + $context['page_title'] = $txt['new_poll']; |
|
| 1168 | + } elseif ($context['make_event']) { |
|
| 1169 | + $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit']; |
|
| 1170 | + } elseif (isset($_REQUEST['msg'])) { |
|
| 1171 | + $context['page_title'] = $txt['modify_msg']; |
|
| 1172 | + } elseif (isset($_REQUEST['subject'], $context['preview_subject'])) { |
|
| 1173 | + $context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']); |
|
| 1174 | + } elseif (empty($topic)) { |
|
| 1175 | + $context['page_title'] = $txt['start_new_topic']; |
|
| 1176 | + } else { |
|
| 1177 | + $context['page_title'] = $txt['post_reply']; |
|
| 1178 | + } |
|
| 1125 | 1179 | |
| 1126 | 1180 | // Build the link tree. |
| 1127 | - if (empty($topic)) |
|
| 1128 | - $context['linktree'][] = array( |
|
| 1181 | + if (empty($topic)) { |
|
| 1182 | + $context['linktree'][] = array( |
|
| 1129 | 1183 | 'name' => '<em>' . $txt['start_new_topic'] . '</em>' |
| 1130 | 1184 | ); |
| 1131 | - else |
|
| 1132 | - $context['linktree'][] = array( |
|
| 1185 | + } else { |
|
| 1186 | + $context['linktree'][] = array( |
|
| 1133 | 1187 | 'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'], |
| 1134 | 1188 | 'name' => $form_subject, |
| 1135 | 1189 | 'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>', |
| 1136 | 1190 | 'extra_after' => '<span><strong class="nav">)</strong></span>' |
| 1137 | 1191 | ); |
| 1192 | + } |
|
| 1138 | 1193 | |
| 1139 | 1194 | $context['subject'] = addcslashes($form_subject, '"'); |
| 1140 | 1195 | $context['message'] = str_replace(array('"', '<', '>', ' '), array('"', '<', '>', ' '), $form_message); |
@@ -1178,8 +1233,9 @@ discard block |
||
| 1178 | 1233 | // Message icons - customized icons are off? |
| 1179 | 1234 | $context['icons'] = getMessageIcons(!empty($board) ? $board : 0); |
| 1180 | 1235 | |
| 1181 | - if (!empty($context['icons'])) |
|
| 1182 | - $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
| 1236 | + if (!empty($context['icons'])) { |
|
| 1237 | + $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
| 1238 | + } |
|
| 1183 | 1239 | |
| 1184 | 1240 | // Are we starting a poll? if set the poll icon as selected if its available |
| 1185 | 1241 | if (isset($_REQUEST['poll'])) |
@@ -1199,8 +1255,9 @@ discard block |
||
| 1199 | 1255 | for ($i = 0, $n = count($context['icons']); $i < $n; $i++) |
| 1200 | 1256 | { |
| 1201 | 1257 | $context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value']; |
| 1202 | - if ($context['icons'][$i]['selected']) |
|
| 1203 | - $context['icon_url'] = $context['icons'][$i]['url']; |
|
| 1258 | + if ($context['icons'][$i]['selected']) { |
|
| 1259 | + $context['icon_url'] = $context['icons'][$i]['url']; |
|
| 1260 | + } |
|
| 1204 | 1261 | } |
| 1205 | 1262 | if (empty($context['icon_url'])) |
| 1206 | 1263 | { |
@@ -1214,8 +1271,9 @@ discard block |
||
| 1214 | 1271 | )); |
| 1215 | 1272 | } |
| 1216 | 1273 | |
| 1217 | - if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) |
|
| 1218 | - getTopic(); |
|
| 1274 | + if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) { |
|
| 1275 | + getTopic(); |
|
| 1276 | + } |
|
| 1219 | 1277 | |
| 1220 | 1278 | // If the user can post attachments prepare the warning labels. |
| 1221 | 1279 | if ($context['can_post_attachment']) |
@@ -1226,12 +1284,13 @@ discard block |
||
| 1226 | 1284 | $context['attachment_restrictions'] = array(); |
| 1227 | 1285 | $context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', ')); |
| 1228 | 1286 | $attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit'); |
| 1229 | - foreach ($attachmentRestrictionTypes as $type) |
|
| 1230 | - if (!empty($modSettings[$type])) |
|
| 1287 | + foreach ($attachmentRestrictionTypes as $type) { |
|
| 1288 | + if (!empty($modSettings[$type])) |
|
| 1231 | 1289 | { |
| 1232 | 1290 | // Show the max number of attachments if not 0. |
| 1233 | 1291 | if ($type == 'attachmentNumPerPostLimit') |
| 1234 | 1292 | $context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']); |
| 1293 | + } |
|
| 1235 | 1294 | } |
| 1236 | 1295 | } |
| 1237 | 1296 | |
@@ -1265,8 +1324,8 @@ discard block |
||
| 1265 | 1324 | |
| 1266 | 1325 | if (!empty($context['current_attachments'])) |
| 1267 | 1326 | { |
| 1268 | - foreach ($context['current_attachments'] as $key => $mock) |
|
| 1269 | - addInlineJavaScript(' |
|
| 1327 | + foreach ($context['current_attachments'] as $key => $mock) { |
|
| 1328 | + addInlineJavaScript(' |
|
| 1270 | 1329 | current_attachments.push({ |
| 1271 | 1330 | name: '. JavaScriptEscape($mock['name']) . ', |
| 1272 | 1331 | size: '. $mock['size'] . ', |
@@ -1275,6 +1334,7 @@ discard block |
||
| 1275 | 1334 | type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') . ', |
| 1276 | 1335 | thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) . ' |
| 1277 | 1336 | });', true); |
| 1337 | + } |
|
| 1278 | 1338 | } |
| 1279 | 1339 | |
| 1280 | 1340 | // File Upload. |
@@ -1349,9 +1409,10 @@ discard block |
||
| 1349 | 1409 | $context['posting_fields']['board']['dd'] .= ' |
| 1350 | 1410 | <optgroup label="' . $category['name'] . '">'; |
| 1351 | 1411 | |
| 1352 | - foreach ($category['boards'] as $brd) |
|
| 1353 | - $context['posting_fields']['board']['dd'] .= ' |
|
| 1412 | + foreach ($category['boards'] as $brd) { |
|
| 1413 | + $context['posting_fields']['board']['dd'] .= ' |
|
| 1354 | 1414 | <option value="' . $brd['id'] . '"' . ($brd['selected'] ? ' selected' : '') . '>' . ($brd['child_level'] > 0 ? str_repeat('==', $brd['child_level'] - 1) . '=>' : '') . ' ' . $brd['name'] . '</option>'; |
| 1415 | + } |
|
| 1355 | 1416 | |
| 1356 | 1417 | $context['posting_fields']['board']['dd'] .= ' |
| 1357 | 1418 | </optgroup>'; |
@@ -1382,8 +1443,9 @@ discard block |
||
| 1382 | 1443 | |
| 1383 | 1444 | |
| 1384 | 1445 | // Finally, load the template. |
| 1385 | - if (!isset($_REQUEST['xml'])) |
|
| 1386 | - loadTemplate('Post'); |
|
| 1446 | + if (!isset($_REQUEST['xml'])) { |
|
| 1447 | + loadTemplate('Post'); |
|
| 1448 | + } |
|
| 1387 | 1449 | |
| 1388 | 1450 | call_integration_hook('integrate_post_end'); |
| 1389 | 1451 | } |
@@ -1404,13 +1466,14 @@ discard block |
||
| 1404 | 1466 | // Sneaking off, are we? |
| 1405 | 1467 | if (empty($_POST) && empty($topic)) |
| 1406 | 1468 | { |
| 1407 | - if (empty($_SERVER['CONTENT_LENGTH'])) |
|
| 1408 | - redirectexit('action=post;board=' . $board . '.0'); |
|
| 1409 | - else |
|
| 1410 | - fatal_lang_error('post_upload_error', false); |
|
| 1469 | + if (empty($_SERVER['CONTENT_LENGTH'])) { |
|
| 1470 | + redirectexit('action=post;board=' . $board . '.0'); |
|
| 1471 | + } else { |
|
| 1472 | + fatal_lang_error('post_upload_error', false); |
|
| 1473 | + } |
|
| 1474 | + } elseif (empty($_POST) && !empty($topic)) { |
|
| 1475 | + redirectexit('action=post;topic=' . $topic . '.0'); |
|
| 1411 | 1476 | } |
| 1412 | - elseif (empty($_POST) && !empty($topic)) |
|
| 1413 | - redirectexit('action=post;topic=' . $topic . '.0'); |
|
| 1414 | 1477 | |
| 1415 | 1478 | // No need! |
| 1416 | 1479 | $context['robot_no_index'] = true; |
@@ -1422,8 +1485,9 @@ discard block |
||
| 1422 | 1485 | $post_errors = array(); |
| 1423 | 1486 | |
| 1424 | 1487 | // If the session has timed out, let the user re-submit their form. |
| 1425 | - if (checkSession('post', '', false) != '') |
|
| 1426 | - $post_errors[] = 'session_timeout'; |
|
| 1488 | + if (checkSession('post', '', false) != '') { |
|
| 1489 | + $post_errors[] = 'session_timeout'; |
|
| 1490 | + } |
|
| 1427 | 1491 | |
| 1428 | 1492 | // Wrong verification code? |
| 1429 | 1493 | if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1))) |
@@ -1433,33 +1497,38 @@ discard block |
||
| 1433 | 1497 | 'id' => 'post', |
| 1434 | 1498 | ); |
| 1435 | 1499 | $context['require_verification'] = create_control_verification($verificationOptions, true); |
| 1436 | - if (is_array($context['require_verification'])) |
|
| 1437 | - $post_errors = array_merge($post_errors, $context['require_verification']); |
|
| 1500 | + if (is_array($context['require_verification'])) { |
|
| 1501 | + $post_errors = array_merge($post_errors, $context['require_verification']); |
|
| 1502 | + } |
|
| 1438 | 1503 | } |
| 1439 | 1504 | |
| 1440 | 1505 | require_once($sourcedir . '/Subs-Post.php'); |
| 1441 | 1506 | loadLanguage('Post'); |
| 1442 | 1507 | |
| 1443 | 1508 | // Drafts enabled and needed? |
| 1444 | - if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) |
|
| 1445 | - require_once($sourcedir . '/Drafts.php'); |
|
| 1509 | + if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) { |
|
| 1510 | + require_once($sourcedir . '/Drafts.php'); |
|
| 1511 | + } |
|
| 1446 | 1512 | |
| 1447 | 1513 | // First check to see if they are trying to delete any current attachments. |
| 1448 | 1514 | if (isset($_POST['attach_del'])) |
| 1449 | 1515 | { |
| 1450 | 1516 | $keep_temp = array(); |
| 1451 | 1517 | $keep_ids = array(); |
| 1452 | - foreach ($_POST['attach_del'] as $dummy) |
|
| 1453 | - if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false) |
|
| 1518 | + foreach ($_POST['attach_del'] as $dummy) { |
|
| 1519 | + if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false) |
|
| 1454 | 1520 | $keep_temp[] = $dummy; |
| 1455 | - else |
|
| 1456 | - $keep_ids[] = (int) $dummy; |
|
| 1521 | + } |
|
| 1522 | + else { |
|
| 1523 | + $keep_ids[] = (int) $dummy; |
|
| 1524 | + } |
|
| 1457 | 1525 | |
| 1458 | - if (isset($_SESSION['temp_attachments'])) |
|
| 1459 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
| 1526 | + if (isset($_SESSION['temp_attachments'])) { |
|
| 1527 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
| 1460 | 1528 | { |
| 1461 | 1529 | if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
| 1462 | 1530 | continue; |
| 1531 | + } |
|
| 1463 | 1532 | |
| 1464 | 1533 | unset($_SESSION['temp_attachments'][$attachID]); |
| 1465 | 1534 | unlink($attachment['tmp_name']); |
@@ -1491,8 +1560,9 @@ discard block |
||
| 1491 | 1560 | { |
| 1492 | 1561 | require_once($sourcedir . '/ManageAttachments.php'); |
| 1493 | 1562 | |
| 1494 | - foreach ($_SESSION['already_attached'] as $attachID => $attachment) |
|
| 1495 | - removeAttachments(array('id_attach' => $attachID)); |
|
| 1563 | + foreach ($_SESSION['already_attached'] as $attachID => $attachment) { |
|
| 1564 | + removeAttachments(array('id_attach' => $attachID)); |
|
| 1565 | + } |
|
| 1496 | 1566 | |
| 1497 | 1567 | unset($_SESSION['already_attached']); |
| 1498 | 1568 | |
@@ -1515,12 +1585,14 @@ discard block |
||
| 1515 | 1585 | $smcFunc['db_free_result']($request); |
| 1516 | 1586 | |
| 1517 | 1587 | // Though the topic should be there, it might have vanished. |
| 1518 | - if (!is_array($topic_info)) |
|
| 1519 | - fatal_lang_error('topic_doesnt_exist', 404); |
|
| 1588 | + if (!is_array($topic_info)) { |
|
| 1589 | + fatal_lang_error('topic_doesnt_exist', 404); |
|
| 1590 | + } |
|
| 1520 | 1591 | |
| 1521 | 1592 | // Did this topic suddenly move? Just checking... |
| 1522 | - if ($topic_info['id_board'] != $board) |
|
| 1523 | - fatal_lang_error('not_a_topic'); |
|
| 1593 | + if ($topic_info['id_board'] != $board) { |
|
| 1594 | + fatal_lang_error('not_a_topic'); |
|
| 1595 | + } |
|
| 1524 | 1596 | |
| 1525 | 1597 | // Do the permissions and approval stuff... |
| 1526 | 1598 | $becomesApproved = true; |
@@ -1543,49 +1615,50 @@ discard block |
||
| 1543 | 1615 | if (!empty($topic) && !isset($_REQUEST['msg'])) |
| 1544 | 1616 | { |
| 1545 | 1617 | // Don't allow a post if it's locked. |
| 1546 | - if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) |
|
| 1547 | - fatal_lang_error('topic_locked', false); |
|
| 1618 | + if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) { |
|
| 1619 | + fatal_lang_error('topic_locked', false); |
|
| 1620 | + } |
|
| 1548 | 1621 | |
| 1549 | 1622 | // Sorry, multiple polls aren't allowed... yet. You should stop giving me ideas :P. |
| 1550 | - if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) |
|
| 1551 | - unset($_REQUEST['poll']); |
|
| 1552 | - |
|
| 1553 | - elseif ($topic_info['id_member_started'] != $user_info['id']) |
|
| 1554 | - { |
|
| 1555 | - if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) |
|
| 1556 | - $becomesApproved = false; |
|
| 1557 | - |
|
| 1558 | - else |
|
| 1559 | - isAllowedTo('post_reply_any'); |
|
| 1560 | - } |
|
| 1561 | - elseif (!allowedTo('post_reply_any')) |
|
| 1623 | + if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) { |
|
| 1624 | + unset($_REQUEST['poll']); |
|
| 1625 | + } elseif ($topic_info['id_member_started'] != $user_info['id']) |
|
| 1626 | + { |
|
| 1627 | + if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) { |
|
| 1628 | + $becomesApproved = false; |
|
| 1629 | + } else { |
|
| 1630 | + isAllowedTo('post_reply_any'); |
|
| 1631 | + } |
|
| 1632 | + } elseif (!allowedTo('post_reply_any')) |
|
| 1562 | 1633 | { |
| 1563 | - if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) |
|
| 1564 | - $becomesApproved = false; |
|
| 1565 | - |
|
| 1566 | - else |
|
| 1567 | - isAllowedTo('post_reply_own'); |
|
| 1634 | + if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) { |
|
| 1635 | + $becomesApproved = false; |
|
| 1636 | + } else { |
|
| 1637 | + isAllowedTo('post_reply_own'); |
|
| 1638 | + } |
|
| 1568 | 1639 | } |
| 1569 | 1640 | |
| 1570 | 1641 | if (isset($_POST['lock'])) |
| 1571 | 1642 | { |
| 1572 | 1643 | // Nothing is changed to the lock. |
| 1573 | - if (empty($topic_info['locked']) == empty($_POST['lock'])) |
|
| 1574 | - unset($_POST['lock']); |
|
| 1644 | + if (empty($topic_info['locked']) == empty($_POST['lock'])) { |
|
| 1645 | + unset($_POST['lock']); |
|
| 1646 | + } |
|
| 1575 | 1647 | |
| 1576 | 1648 | // You're have no permission to lock this topic. |
| 1577 | - elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) |
|
| 1578 | - unset($_POST['lock']); |
|
| 1649 | + elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) { |
|
| 1650 | + unset($_POST['lock']); |
|
| 1651 | + } |
|
| 1579 | 1652 | |
| 1580 | 1653 | // You are allowed to (un)lock your own topic only. |
| 1581 | 1654 | elseif (!allowedTo('lock_any')) |
| 1582 | 1655 | { |
| 1583 | 1656 | // You cannot override a moderator lock. |
| 1584 | - if ($topic_info['locked'] == 1) |
|
| 1585 | - unset($_POST['lock']); |
|
| 1586 | - |
|
| 1587 | - else |
|
| 1588 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 1657 | + if ($topic_info['locked'] == 1) { |
|
| 1658 | + unset($_POST['lock']); |
|
| 1659 | + } else { |
|
| 1660 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 1661 | + } |
|
| 1589 | 1662 | } |
| 1590 | 1663 | // Hail mighty moderator, (un)lock this topic immediately. |
| 1591 | 1664 | else |
@@ -1593,19 +1666,21 @@ discard block |
||
| 1593 | 1666 | $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
| 1594 | 1667 | |
| 1595 | 1668 | // Did someone (un)lock this while you were posting? |
| 1596 | - if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) |
|
| 1597 | - $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
| 1669 | + if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) { |
|
| 1670 | + $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
| 1671 | + } |
|
| 1598 | 1672 | } |
| 1599 | 1673 | } |
| 1600 | 1674 | |
| 1601 | 1675 | // So you wanna (un)sticky this...let's see. |
| 1602 | - if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) |
|
| 1603 | - unset($_POST['sticky']); |
|
| 1604 | - elseif (isset($_POST['sticky'])) |
|
| 1676 | + if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) { |
|
| 1677 | + unset($_POST['sticky']); |
|
| 1678 | + } elseif (isset($_POST['sticky'])) |
|
| 1605 | 1679 | { |
| 1606 | 1680 | // Did someone (un)sticky this while you were posting? |
| 1607 | - if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) |
|
| 1608 | - $post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky'; |
|
| 1681 | + if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) { |
|
| 1682 | + $post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky'; |
|
| 1683 | + } |
|
| 1609 | 1684 | } |
| 1610 | 1685 | |
| 1611 | 1686 | // If drafts are enabled, then pass this off |
@@ -1632,26 +1707,31 @@ discard block |
||
| 1632 | 1707 | |
| 1633 | 1708 | // Do like, the permissions, for safety and stuff... |
| 1634 | 1709 | $becomesApproved = true; |
| 1635 | - if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) |
|
| 1636 | - $becomesApproved = false; |
|
| 1637 | - else |
|
| 1638 | - isAllowedTo('post_new'); |
|
| 1710 | + if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) { |
|
| 1711 | + $becomesApproved = false; |
|
| 1712 | + } else { |
|
| 1713 | + isAllowedTo('post_new'); |
|
| 1714 | + } |
|
| 1639 | 1715 | |
| 1640 | 1716 | if (isset($_POST['lock'])) |
| 1641 | 1717 | { |
| 1642 | 1718 | // New topics are by default not locked. |
| 1643 | - if (empty($_POST['lock'])) |
|
| 1644 | - unset($_POST['lock']); |
|
| 1719 | + if (empty($_POST['lock'])) { |
|
| 1720 | + unset($_POST['lock']); |
|
| 1721 | + } |
|
| 1645 | 1722 | // Besides, you need permission. |
| 1646 | - elseif (!allowedTo(array('lock_any', 'lock_own'))) |
|
| 1647 | - unset($_POST['lock']); |
|
| 1723 | + elseif (!allowedTo(array('lock_any', 'lock_own'))) { |
|
| 1724 | + unset($_POST['lock']); |
|
| 1725 | + } |
|
| 1648 | 1726 | // A moderator-lock (1) can override a user-lock (2). |
| 1649 | - else |
|
| 1650 | - $_POST['lock'] = allowedTo('lock_any') ? 1 : 2; |
|
| 1727 | + else { |
|
| 1728 | + $_POST['lock'] = allowedTo('lock_any') ? 1 : 2; |
|
| 1729 | + } |
|
| 1651 | 1730 | } |
| 1652 | 1731 | |
| 1653 | - if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) |
|
| 1654 | - unset($_POST['sticky']); |
|
| 1732 | + if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) { |
|
| 1733 | + unset($_POST['sticky']); |
|
| 1734 | + } |
|
| 1655 | 1735 | |
| 1656 | 1736 | // Saving your new topic as a draft first? |
| 1657 | 1737 | if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft'])) |
@@ -1676,31 +1756,37 @@ discard block |
||
| 1676 | 1756 | 'id_msg' => $_REQUEST['msg'], |
| 1677 | 1757 | ) |
| 1678 | 1758 | ); |
| 1679 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1680 | - fatal_lang_error('cant_find_messages', false); |
|
| 1759 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1760 | + fatal_lang_error('cant_find_messages', false); |
|
| 1761 | + } |
|
| 1681 | 1762 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1682 | 1763 | $smcFunc['db_free_result']($request); |
| 1683 | 1764 | |
| 1684 | - if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) |
|
| 1685 | - fatal_lang_error('topic_locked', false); |
|
| 1765 | + if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) { |
|
| 1766 | + fatal_lang_error('topic_locked', false); |
|
| 1767 | + } |
|
| 1686 | 1768 | |
| 1687 | 1769 | if (isset($_POST['lock'])) |
| 1688 | 1770 | { |
| 1689 | 1771 | // Nothing changes to the lock status. |
| 1690 | - if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) |
|
| 1691 | - unset($_POST['lock']); |
|
| 1772 | + if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) { |
|
| 1773 | + unset($_POST['lock']); |
|
| 1774 | + } |
|
| 1692 | 1775 | // You're simply not allowed to (un)lock this. |
| 1693 | - elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) |
|
| 1694 | - unset($_POST['lock']); |
|
| 1776 | + elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) { |
|
| 1777 | + unset($_POST['lock']); |
|
| 1778 | + } |
|
| 1695 | 1779 | // You're only allowed to lock your own topics. |
| 1696 | 1780 | elseif (!allowedTo('lock_any')) |
| 1697 | 1781 | { |
| 1698 | 1782 | // You're not allowed to break a moderator's lock. |
| 1699 | - if ($topic_info['locked'] == 1) |
|
| 1700 | - unset($_POST['lock']); |
|
| 1783 | + if ($topic_info['locked'] == 1) { |
|
| 1784 | + unset($_POST['lock']); |
|
| 1785 | + } |
|
| 1701 | 1786 | // Lock it with a soft lock or unlock it. |
| 1702 | - else |
|
| 1703 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 1787 | + else { |
|
| 1788 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 1789 | + } |
|
| 1704 | 1790 | } |
| 1705 | 1791 | // You must be the moderator. |
| 1706 | 1792 | else |
@@ -1708,44 +1794,46 @@ discard block |
||
| 1708 | 1794 | $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
| 1709 | 1795 | |
| 1710 | 1796 | // Did someone (un)lock this while you were posting? |
| 1711 | - if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) |
|
| 1712 | - $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
| 1797 | + if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) { |
|
| 1798 | + $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
| 1799 | + } |
|
| 1713 | 1800 | } |
| 1714 | 1801 | } |
| 1715 | 1802 | |
| 1716 | 1803 | // Change the sticky status of this topic? |
| 1717 | - if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) |
|
| 1718 | - unset($_POST['sticky']); |
|
| 1719 | - elseif (isset($_POST['sticky'])) |
|
| 1804 | + if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) { |
|
| 1805 | + unset($_POST['sticky']); |
|
| 1806 | + } elseif (isset($_POST['sticky'])) |
|
| 1720 | 1807 | { |
| 1721 | 1808 | // Did someone (un)sticky this while you were posting? |
| 1722 | - if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) |
|
| 1723 | - $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied'; |
|
| 1809 | + if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) { |
|
| 1810 | + $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied'; |
|
| 1811 | + } |
|
| 1724 | 1812 | } |
| 1725 | 1813 | |
| 1726 | 1814 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
| 1727 | 1815 | { |
| 1728 | - if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
| 1729 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 1730 | - elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) |
|
| 1731 | - isAllowedTo('modify_replies'); |
|
| 1732 | - else |
|
| 1733 | - isAllowedTo('modify_own'); |
|
| 1734 | - } |
|
| 1735 | - elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 1816 | + if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
| 1817 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 1818 | + } elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
| 1819 | + isAllowedTo('modify_replies'); |
|
| 1820 | + } else { |
|
| 1821 | + isAllowedTo('modify_own'); |
|
| 1822 | + } |
|
| 1823 | + } elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 1736 | 1824 | { |
| 1737 | 1825 | isAllowedTo('modify_replies'); |
| 1738 | 1826 | |
| 1739 | 1827 | // If you're modifying a reply, I say it better be logged... |
| 1740 | 1828 | $moderationAction = true; |
| 1741 | - } |
|
| 1742 | - else |
|
| 1829 | + } else |
|
| 1743 | 1830 | { |
| 1744 | 1831 | isAllowedTo('modify_any'); |
| 1745 | 1832 | |
| 1746 | 1833 | // Log it, assuming you're not modifying your own post. |
| 1747 | - if ($row['id_member'] != $user_info['id']) |
|
| 1748 | - $moderationAction = true; |
|
| 1834 | + if ($row['id_member'] != $user_info['id']) { |
|
| 1835 | + $moderationAction = true; |
|
| 1836 | + } |
|
| 1749 | 1837 | } |
| 1750 | 1838 | |
| 1751 | 1839 | // If drafts are enabled, then lets send this off to save |
@@ -1784,20 +1872,24 @@ discard block |
||
| 1784 | 1872 | $_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']); |
| 1785 | 1873 | $_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']); |
| 1786 | 1874 | |
| 1787 | - if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') |
|
| 1788 | - $post_errors[] = 'no_name'; |
|
| 1789 | - if ($smcFunc['strlen']($_POST['guestname']) > 25) |
|
| 1790 | - $post_errors[] = 'long_name'; |
|
| 1875 | + if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') { |
|
| 1876 | + $post_errors[] = 'no_name'; |
|
| 1877 | + } |
|
| 1878 | + if ($smcFunc['strlen']($_POST['guestname']) > 25) { |
|
| 1879 | + $post_errors[] = 'long_name'; |
|
| 1880 | + } |
|
| 1791 | 1881 | |
| 1792 | 1882 | if (empty($modSettings['guest_post_no_email'])) |
| 1793 | 1883 | { |
| 1794 | 1884 | // Only check if they changed it! |
| 1795 | 1885 | if (!isset($row) || $row['poster_email'] != $_POST['email']) |
| 1796 | 1886 | { |
| 1797 | - if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) |
|
| 1798 | - $post_errors[] = 'no_email'; |
|
| 1799 | - if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) |
|
| 1800 | - $post_errors[] = 'bad_email'; |
|
| 1887 | + if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) { |
|
| 1888 | + $post_errors[] = 'no_email'; |
|
| 1889 | + } |
|
| 1890 | + if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { |
|
| 1891 | + $post_errors[] = 'bad_email'; |
|
| 1892 | + } |
|
| 1801 | 1893 | } |
| 1802 | 1894 | |
| 1803 | 1895 | // Now make sure this email address is not banned from posting. |
@@ -1813,75 +1905,89 @@ discard block |
||
| 1813 | 1905 | } |
| 1814 | 1906 | |
| 1815 | 1907 | // Coming from the quickReply? |
| 1816 | - if (isset($_POST['quickReply'])) |
|
| 1817 | - $_POST['message'] = $_POST['quickReply']; |
|
| 1908 | + if (isset($_POST['quickReply'])) { |
|
| 1909 | + $_POST['message'] = $_POST['quickReply']; |
|
| 1910 | + } |
|
| 1818 | 1911 | |
| 1819 | 1912 | // Check the subject and message. |
| 1820 | - if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') |
|
| 1821 | - $post_errors[] = 'no_subject'; |
|
| 1822 | - if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') |
|
| 1823 | - $post_errors[] = 'no_message'; |
|
| 1824 | - elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) |
|
| 1825 | - $post_errors[] = array('long_message', array($modSettings['max_messageLength'])); |
|
| 1826 | - else |
|
| 1913 | + if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') { |
|
| 1914 | + $post_errors[] = 'no_subject'; |
|
| 1915 | + } |
|
| 1916 | + if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') { |
|
| 1917 | + $post_errors[] = 'no_message'; |
|
| 1918 | + } elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) { |
|
| 1919 | + $post_errors[] = array('long_message', array($modSettings['max_messageLength'])); |
|
| 1920 | + } else |
|
| 1827 | 1921 | { |
| 1828 | 1922 | // Prepare the message a bit for some additional testing. |
| 1829 | 1923 | $_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES); |
| 1830 | 1924 | |
| 1831 | 1925 | // Preparse code. (Zef) |
| 1832 | - if ($user_info['is_guest']) |
|
| 1833 | - $user_info['name'] = $_POST['guestname']; |
|
| 1926 | + if ($user_info['is_guest']) { |
|
| 1927 | + $user_info['name'] = $_POST['guestname']; |
|
| 1928 | + } |
|
| 1834 | 1929 | preparsecode($_POST['message']); |
| 1835 | 1930 | |
| 1836 | 1931 | // Let's see if there's still some content left without the tags. |
| 1837 | - if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) |
|
| 1838 | - $post_errors[] = 'no_message'; |
|
| 1932 | + if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) { |
|
| 1933 | + $post_errors[] = 'no_message'; |
|
| 1934 | + } |
|
| 1935 | + } |
|
| 1936 | + if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') { |
|
| 1937 | + $post_errors[] = 'no_event'; |
|
| 1839 | 1938 | } |
| 1840 | - if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') |
|
| 1841 | - $post_errors[] = 'no_event'; |
|
| 1842 | 1939 | // You are not! |
| 1843 | - if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) |
|
| 1844 | - fatal_error('Knave! Masquerader! Charlatan!', false); |
|
| 1940 | + if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) { |
|
| 1941 | + fatal_error('Knave! Masquerader! Charlatan!', false); |
|
| 1942 | + } |
|
| 1845 | 1943 | |
| 1846 | 1944 | // Validate the poll... |
| 1847 | 1945 | if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1') |
| 1848 | 1946 | { |
| 1849 | - if (!empty($topic) && !isset($_REQUEST['msg'])) |
|
| 1850 | - fatal_lang_error('no_access', false); |
|
| 1947 | + if (!empty($topic) && !isset($_REQUEST['msg'])) { |
|
| 1948 | + fatal_lang_error('no_access', false); |
|
| 1949 | + } |
|
| 1851 | 1950 | |
| 1852 | 1951 | // This is a new topic... so it's a new poll. |
| 1853 | - if (empty($topic)) |
|
| 1854 | - isAllowedTo('poll_post'); |
|
| 1952 | + if (empty($topic)) { |
|
| 1953 | + isAllowedTo('poll_post'); |
|
| 1954 | + } |
|
| 1855 | 1955 | // Can you add to your own topics? |
| 1856 | - elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) |
|
| 1857 | - isAllowedTo('poll_add_own'); |
|
| 1956 | + elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) { |
|
| 1957 | + isAllowedTo('poll_add_own'); |
|
| 1958 | + } |
|
| 1858 | 1959 | // Can you add polls to any topic, then? |
| 1859 | - else |
|
| 1860 | - isAllowedTo('poll_add_any'); |
|
| 1960 | + else { |
|
| 1961 | + isAllowedTo('poll_add_any'); |
|
| 1962 | + } |
|
| 1861 | 1963 | |
| 1862 | - if (!isset($_POST['question']) || trim($_POST['question']) == '') |
|
| 1863 | - $post_errors[] = 'no_question'; |
|
| 1964 | + if (!isset($_POST['question']) || trim($_POST['question']) == '') { |
|
| 1965 | + $post_errors[] = 'no_question'; |
|
| 1966 | + } |
|
| 1864 | 1967 | |
| 1865 | 1968 | $_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']); |
| 1866 | 1969 | |
| 1867 | 1970 | // Get rid of empty ones. |
| 1868 | - foreach ($_POST['options'] as $k => $option) |
|
| 1869 | - if ($option == '') |
|
| 1971 | + foreach ($_POST['options'] as $k => $option) { |
|
| 1972 | + if ($option == '') |
|
| 1870 | 1973 | unset($_POST['options'][$k], $_POST['options'][$k]); |
| 1974 | + } |
|
| 1871 | 1975 | |
| 1872 | 1976 | // What are you going to vote between with one choice?!? |
| 1873 | - if (count($_POST['options']) < 2) |
|
| 1874 | - $post_errors[] = 'poll_few'; |
|
| 1875 | - elseif (count($_POST['options']) > 256) |
|
| 1876 | - $post_errors[] = 'poll_many'; |
|
| 1977 | + if (count($_POST['options']) < 2) { |
|
| 1978 | + $post_errors[] = 'poll_few'; |
|
| 1979 | + } elseif (count($_POST['options']) > 256) { |
|
| 1980 | + $post_errors[] = 'poll_many'; |
|
| 1981 | + } |
|
| 1877 | 1982 | } |
| 1878 | 1983 | |
| 1879 | 1984 | if ($posterIsGuest) |
| 1880 | 1985 | { |
| 1881 | 1986 | // If user is a guest, make sure the chosen name isn't taken. |
| 1882 | 1987 | require_once($sourcedir . '/Subs-Members.php'); |
| 1883 | - if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) |
|
| 1884 | - $post_errors[] = 'bad_name'; |
|
| 1988 | + if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) { |
|
| 1989 | + $post_errors[] = 'bad_name'; |
|
| 1990 | + } |
|
| 1885 | 1991 | } |
| 1886 | 1992 | // If the user isn't a guest, get his or her name and email. |
| 1887 | 1993 | elseif (!isset($_REQUEST['msg'])) |
@@ -1912,8 +2018,9 @@ discard block |
||
| 1912 | 2018 | } |
| 1913 | 2019 | |
| 1914 | 2020 | // Make sure the user isn't spamming the board. |
| 1915 | - if (!isset($_REQUEST['msg'])) |
|
| 1916 | - spamProtection('post'); |
|
| 2021 | + if (!isset($_REQUEST['msg'])) { |
|
| 2022 | + spamProtection('post'); |
|
| 2023 | + } |
|
| 1917 | 2024 | |
| 1918 | 2025 | // At about this point, we're posting and that's that. |
| 1919 | 2026 | ignore_user_abort(true); |
@@ -1926,32 +2033,36 @@ discard block |
||
| 1926 | 2033 | $_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => '')); |
| 1927 | 2034 | |
| 1928 | 2035 | // At this point, we want to make sure the subject isn't too long. |
| 1929 | - if ($smcFunc['strlen']($_POST['subject']) > 100) |
|
| 1930 | - $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
| 2036 | + if ($smcFunc['strlen']($_POST['subject']) > 100) { |
|
| 2037 | + $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
| 2038 | + } |
|
| 1931 | 2039 | |
| 1932 | 2040 | // Same with the "why did you edit this" text. |
| 1933 | - if ($smcFunc['strlen']($_POST['modify_reason']) > 100) |
|
| 1934 | - $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
| 2041 | + if ($smcFunc['strlen']($_POST['modify_reason']) > 100) { |
|
| 2042 | + $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
| 2043 | + } |
|
| 1935 | 2044 | |
| 1936 | 2045 | // Make the poll... |
| 1937 | 2046 | if (isset($_REQUEST['poll'])) |
| 1938 | 2047 | { |
| 1939 | 2048 | // Make sure that the user has not entered a ridiculous number of options.. |
| 1940 | - if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) |
|
| 1941 | - $_POST['poll_max_votes'] = 1; |
|
| 1942 | - elseif ($_POST['poll_max_votes'] > count($_POST['options'])) |
|
| 1943 | - $_POST['poll_max_votes'] = count($_POST['options']); |
|
| 1944 | - else |
|
| 1945 | - $_POST['poll_max_votes'] = (int) $_POST['poll_max_votes']; |
|
| 2049 | + if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) { |
|
| 2050 | + $_POST['poll_max_votes'] = 1; |
|
| 2051 | + } elseif ($_POST['poll_max_votes'] > count($_POST['options'])) { |
|
| 2052 | + $_POST['poll_max_votes'] = count($_POST['options']); |
|
| 2053 | + } else { |
|
| 2054 | + $_POST['poll_max_votes'] = (int) $_POST['poll_max_votes']; |
|
| 2055 | + } |
|
| 1946 | 2056 | |
| 1947 | 2057 | $_POST['poll_expire'] = (int) $_POST['poll_expire']; |
| 1948 | 2058 | $_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']); |
| 1949 | 2059 | |
| 1950 | 2060 | // Just set it to zero if it's not there.. |
| 1951 | - if (!isset($_POST['poll_hide'])) |
|
| 1952 | - $_POST['poll_hide'] = 0; |
|
| 1953 | - else |
|
| 1954 | - $_POST['poll_hide'] = (int) $_POST['poll_hide']; |
|
| 2061 | + if (!isset($_POST['poll_hide'])) { |
|
| 2062 | + $_POST['poll_hide'] = 0; |
|
| 2063 | + } else { |
|
| 2064 | + $_POST['poll_hide'] = (int) $_POST['poll_hide']; |
|
| 2065 | + } |
|
| 1955 | 2066 | $_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0; |
| 1956 | 2067 | |
| 1957 | 2068 | $_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0; |
@@ -1960,16 +2071,19 @@ discard block |
||
| 1960 | 2071 | { |
| 1961 | 2072 | require_once($sourcedir . '/Subs-Members.php'); |
| 1962 | 2073 | $allowedVoteGroups = groupsAllowedTo('poll_vote', $board); |
| 1963 | - if (!in_array(-1, $allowedVoteGroups['allowed'])) |
|
| 1964 | - $_POST['poll_guest_vote'] = 0; |
|
| 2074 | + if (!in_array(-1, $allowedVoteGroups['allowed'])) { |
|
| 2075 | + $_POST['poll_guest_vote'] = 0; |
|
| 2076 | + } |
|
| 1965 | 2077 | } |
| 1966 | 2078 | |
| 1967 | 2079 | // If the user tries to set the poll too far in advance, don't let them. |
| 1968 | - if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) |
|
| 1969 | - fatal_lang_error('poll_range_error', false); |
|
| 2080 | + if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) { |
|
| 2081 | + fatal_lang_error('poll_range_error', false); |
|
| 2082 | + } |
|
| 1970 | 2083 | // Don't allow them to select option 2 for hidden results if it's not time limited. |
| 1971 | - elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) |
|
| 1972 | - $_POST['poll_hide'] = 1; |
|
| 2084 | + elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) { |
|
| 2085 | + $_POST['poll_hide'] = 1; |
|
| 2086 | + } |
|
| 1973 | 2087 | |
| 1974 | 2088 | // Clean up the question and answers. |
| 1975 | 2089 | $_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']); |
@@ -1983,13 +2097,15 @@ discard block |
||
| 1983 | 2097 | { |
| 1984 | 2098 | $attachIDs = array(); |
| 1985 | 2099 | $attach_errors = array(); |
| 1986 | - if (!empty($context['we_are_history'])) |
|
| 1987 | - $attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>'; |
|
| 2100 | + if (!empty($context['we_are_history'])) { |
|
| 2101 | + $attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>'; |
|
| 2102 | + } |
|
| 1988 | 2103 | |
| 1989 | 2104 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
| 1990 | 2105 | { |
| 1991 | - if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
|
| 1992 | - continue; |
|
| 2106 | + if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { |
|
| 2107 | + continue; |
|
| 2108 | + } |
|
| 1993 | 2109 | |
| 1994 | 2110 | // If there was an initial error just show that message. |
| 1995 | 2111 | if ($attachID == 'initial_error') |
@@ -2018,12 +2134,13 @@ discard block |
||
| 2018 | 2134 | if (createAttachment($attachmentOptions)) |
| 2019 | 2135 | { |
| 2020 | 2136 | $attachIDs[] = $attachmentOptions['id']; |
| 2021 | - if (!empty($attachmentOptions['thumb'])) |
|
| 2022 | - $attachIDs[] = $attachmentOptions['thumb']; |
|
| 2137 | + if (!empty($attachmentOptions['thumb'])) { |
|
| 2138 | + $attachIDs[] = $attachmentOptions['thumb']; |
|
| 2139 | + } |
|
| 2023 | 2140 | } |
| 2141 | + } else { |
|
| 2142 | + $attach_errors[] = '<dt> </dt>'; |
|
| 2024 | 2143 | } |
| 2025 | - else |
|
| 2026 | - $attach_errors[] = '<dt> </dt>'; |
|
| 2027 | 2144 | |
| 2028 | 2145 | if (!empty($attachmentOptions['errors'])) |
| 2029 | 2146 | { |
@@ -2035,14 +2152,16 @@ discard block |
||
| 2035 | 2152 | if (!is_array($error)) |
| 2036 | 2153 | { |
| 2037 | 2154 | $attach_errors[] = '<dd>' . $txt[$error] . '</dd>'; |
| 2038 | - if (in_array($error, $log_these)) |
|
| 2039 | - log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
| 2155 | + if (in_array($error, $log_these)) { |
|
| 2156 | + log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
| 2157 | + } |
|
| 2158 | + } else { |
|
| 2159 | + $attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>'; |
|
| 2040 | 2160 | } |
| 2041 | - else |
|
| 2042 | - $attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>'; |
|
| 2043 | 2161 | } |
| 2044 | - if (file_exists($attachment['tmp_name'])) |
|
| 2045 | - unlink($attachment['tmp_name']); |
|
| 2162 | + if (file_exists($attachment['tmp_name'])) { |
|
| 2163 | + unlink($attachment['tmp_name']); |
|
| 2164 | + } |
|
| 2046 | 2165 | } |
| 2047 | 2166 | } |
| 2048 | 2167 | unset($_SESSION['temp_attachments']); |
@@ -2083,24 +2202,24 @@ discard block |
||
| 2083 | 2202 | ); |
| 2084 | 2203 | |
| 2085 | 2204 | call_integration_hook('integrate_poll_add_edit', array($id_poll, false)); |
| 2205 | + } else { |
|
| 2206 | + $id_poll = 0; |
|
| 2086 | 2207 | } |
| 2087 | - else |
|
| 2088 | - $id_poll = 0; |
|
| 2089 | 2208 | |
| 2090 | 2209 | // Creating a new topic? |
| 2091 | 2210 | $newTopic = empty($_REQUEST['msg']) && empty($topic); |
| 2092 | 2211 | |
| 2093 | 2212 | // Check the icon. |
| 2094 | - if (!isset($_POST['icon'])) |
|
| 2095 | - $_POST['icon'] = 'xx'; |
|
| 2096 | - |
|
| 2097 | - else |
|
| 2213 | + if (!isset($_POST['icon'])) { |
|
| 2214 | + $_POST['icon'] = 'xx'; |
|
| 2215 | + } else |
|
| 2098 | 2216 | { |
| 2099 | 2217 | $_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']); |
| 2100 | 2218 | |
| 2101 | 2219 | // Need to figure it out if this is a valid icon name. |
| 2102 | - if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) |
|
| 2103 | - $_POST['icon'] = 'xx'; |
|
| 2220 | + if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) { |
|
| 2221 | + $_POST['icon'] = 'xx'; |
|
| 2222 | + } |
|
| 2104 | 2223 | } |
| 2105 | 2224 | |
| 2106 | 2225 | // Collect all parameters for the creation or modification of a post. |
@@ -2141,8 +2260,9 @@ discard block |
||
| 2141 | 2260 | } |
| 2142 | 2261 | |
| 2143 | 2262 | // This will save some time... |
| 2144 | - if (empty($approve_has_changed)) |
|
| 2145 | - unset($msgOptions['approved']); |
|
| 2263 | + if (empty($approve_has_changed)) { |
|
| 2264 | + unset($msgOptions['approved']); |
|
| 2265 | + } |
|
| 2146 | 2266 | |
| 2147 | 2267 | modifyPost($msgOptions, $topicOptions, $posterOptions); |
| 2148 | 2268 | } |
@@ -2151,8 +2271,9 @@ discard block |
||
| 2151 | 2271 | { |
| 2152 | 2272 | createPost($msgOptions, $topicOptions, $posterOptions); |
| 2153 | 2273 | |
| 2154 | - if (isset($topicOptions['id'])) |
|
| 2155 | - $topic = $topicOptions['id']; |
|
| 2274 | + if (isset($topicOptions['id'])) { |
|
| 2275 | + $topic = $topicOptions['id']; |
|
| 2276 | + } |
|
| 2156 | 2277 | } |
| 2157 | 2278 | |
| 2158 | 2279 | // Are there attachments already uploaded and waiting to be assigned? |
@@ -2164,8 +2285,9 @@ discard block |
||
| 2164 | 2285 | } |
| 2165 | 2286 | |
| 2166 | 2287 | // If we had a draft for this, its time to remove it since it was just posted |
| 2167 | - if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) |
|
| 2168 | - DeleteDraft($_POST['id_draft']); |
|
| 2288 | + if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) { |
|
| 2289 | + DeleteDraft($_POST['id_draft']); |
|
| 2290 | + } |
|
| 2169 | 2291 | |
| 2170 | 2292 | // Editing or posting an event? |
| 2171 | 2293 | if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1)) |
@@ -2184,8 +2306,7 @@ discard block |
||
| 2184 | 2306 | 'member' => $user_info['id'], |
| 2185 | 2307 | ); |
| 2186 | 2308 | insertEvent($eventOptions); |
| 2187 | - } |
|
| 2188 | - elseif (isset($_POST['calendar'])) |
|
| 2309 | + } elseif (isset($_POST['calendar'])) |
|
| 2189 | 2310 | { |
| 2190 | 2311 | $_REQUEST['eventid'] = (int) $_REQUEST['eventid']; |
| 2191 | 2312 | |
@@ -2213,14 +2334,15 @@ discard block |
||
| 2213 | 2334 | } |
| 2214 | 2335 | |
| 2215 | 2336 | // Delete it? |
| 2216 | - if (isset($_REQUEST['deleteevent'])) |
|
| 2217 | - $smcFunc['db_query']('', ' |
|
| 2337 | + if (isset($_REQUEST['deleteevent'])) { |
|
| 2338 | + $smcFunc['db_query']('', ' |
|
| 2218 | 2339 | DELETE FROM {db_prefix}calendar |
| 2219 | 2340 | WHERE id_event = {int:id_event}', |
| 2220 | 2341 | array( |
| 2221 | 2342 | 'id_event' => $_REQUEST['eventid'], |
| 2222 | 2343 | ) |
| 2223 | 2344 | ); |
| 2345 | + } |
|
| 2224 | 2346 | // ... or just update it? |
| 2225 | 2347 | else |
| 2226 | 2348 | { |
@@ -2262,9 +2384,8 @@ discard block |
||
| 2262 | 2384 | array($user_info['id'], $topic, 0), |
| 2263 | 2385 | array('id_member', 'id_topic', 'id_board') |
| 2264 | 2386 | ); |
| 2265 | - } |
|
| 2266 | - elseif (!$newTopic) |
|
| 2267 | - $smcFunc['db_query']('', ' |
|
| 2387 | + } elseif (!$newTopic) { |
|
| 2388 | + $smcFunc['db_query']('', ' |
|
| 2268 | 2389 | DELETE FROM {db_prefix}log_notify |
| 2269 | 2390 | WHERE id_member = {int:current_member} |
| 2270 | 2391 | AND id_topic = {int:current_topic}', |
@@ -2273,16 +2394,20 @@ discard block |
||
| 2273 | 2394 | 'current_topic' => $topic, |
| 2274 | 2395 | ) |
| 2275 | 2396 | ); |
| 2397 | + } |
|
| 2276 | 2398 | |
| 2277 | 2399 | // Log an act of moderation - modifying. |
| 2278 | - if (!empty($moderationAction)) |
|
| 2279 | - logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
| 2400 | + if (!empty($moderationAction)) { |
|
| 2401 | + logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
| 2402 | + } |
|
| 2280 | 2403 | |
| 2281 | - if (isset($_POST['lock']) && $_POST['lock'] != 2) |
|
| 2282 | - logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
| 2404 | + if (isset($_POST['lock']) && $_POST['lock'] != 2) { |
|
| 2405 | + logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
| 2406 | + } |
|
| 2283 | 2407 | |
| 2284 | - if (isset($_POST['sticky'])) |
|
| 2285 | - logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
| 2408 | + if (isset($_POST['sticky'])) { |
|
| 2409 | + logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
| 2410 | + } |
|
| 2286 | 2411 | |
| 2287 | 2412 | // Returning to the topic? |
| 2288 | 2413 | if (!empty($_REQUEST['goback'])) |
@@ -2301,26 +2426,31 @@ discard block |
||
| 2301 | 2426 | ); |
| 2302 | 2427 | } |
| 2303 | 2428 | |
| 2304 | - if ($board_info['num_topics'] == 0) |
|
| 2305 | - cache_put_data('board-' . $board, null, 120); |
|
| 2429 | + if ($board_info['num_topics'] == 0) { |
|
| 2430 | + cache_put_data('board-' . $board, null, 120); |
|
| 2431 | + } |
|
| 2306 | 2432 | |
| 2307 | 2433 | call_integration_hook('integrate_post2_end'); |
| 2308 | 2434 | |
| 2309 | - if (!empty($_POST['announce_topic']) && allowedTo('announce_topic')) |
|
| 2310 | - redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2435 | + if (!empty($_POST['announce_topic']) && allowedTo('announce_topic')) { |
|
| 2436 | + redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2437 | + } |
|
| 2311 | 2438 | |
| 2312 | - if (!empty($_POST['move']) && allowedTo('move_any')) |
|
| 2313 | - redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2439 | + if (!empty($_POST['move']) && allowedTo('move_any')) { |
|
| 2440 | + redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2441 | + } |
|
| 2314 | 2442 | |
| 2315 | 2443 | // Return to post if the mod is on. |
| 2316 | - if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) |
|
| 2317 | - redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie')); |
|
| 2318 | - elseif (!empty($_REQUEST['goback'])) |
|
| 2319 | - redirectexit('topic=' . $topic . '.new#new', isBrowser('ie')); |
|
| 2444 | + if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) { |
|
| 2445 | + redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie')); |
|
| 2446 | + } elseif (!empty($_REQUEST['goback'])) { |
|
| 2447 | + redirectexit('topic=' . $topic . '.new#new', isBrowser('ie')); |
|
| 2448 | + } |
|
| 2320 | 2449 | // Dut-dut-duh-duh-DUH-duh-dut-duh-duh! *dances to the Final Fantasy Fanfare...* |
| 2321 | - else |
|
| 2322 | - redirectexit('board=' . $board . '.0'); |
|
| 2323 | -} |
|
| 2450 | + else { |
|
| 2451 | + redirectexit('board=' . $board . '.0'); |
|
| 2452 | + } |
|
| 2453 | + } |
|
| 2324 | 2454 | |
| 2325 | 2455 | /** |
| 2326 | 2456 | * Handle the announce topic function (action=announce). |
@@ -2338,8 +2468,9 @@ discard block |
||
| 2338 | 2468 | |
| 2339 | 2469 | validateSession(); |
| 2340 | 2470 | |
| 2341 | - if (empty($topic)) |
|
| 2342 | - fatal_lang_error('topic_gone', false); |
|
| 2471 | + if (empty($topic)) { |
|
| 2472 | + fatal_lang_error('topic_gone', false); |
|
| 2473 | + } |
|
| 2343 | 2474 | |
| 2344 | 2475 | loadLanguage('Post'); |
| 2345 | 2476 | loadTemplate('Post'); |
@@ -2366,8 +2497,9 @@ discard block |
||
| 2366 | 2497 | global $txt, $context, $topic, $board_info, $smcFunc; |
| 2367 | 2498 | |
| 2368 | 2499 | $groups = array_merge($board_info['groups'], array(1)); |
| 2369 | - foreach ($groups as $id => $group) |
|
| 2370 | - $groups[$id] = (int) $group; |
|
| 2500 | + foreach ($groups as $id => $group) { |
|
| 2501 | + $groups[$id] = (int) $group; |
|
| 2502 | + } |
|
| 2371 | 2503 | |
| 2372 | 2504 | $context['groups'] = array(); |
| 2373 | 2505 | if (in_array(0, $groups)) |
@@ -2410,8 +2542,9 @@ discard block |
||
| 2410 | 2542 | 'group_list' => $groups, |
| 2411 | 2543 | ) |
| 2412 | 2544 | ); |
| 2413 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2414 | - $context['groups'][$row['id_group']]['name'] = $row['group_name']; |
|
| 2545 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2546 | + $context['groups'][$row['id_group']]['name'] = $row['group_name']; |
|
| 2547 | + } |
|
| 2415 | 2548 | $smcFunc['db_free_result']($request); |
| 2416 | 2549 | |
| 2417 | 2550 | // Get the subject of the topic we're about to announce. |
@@ -2453,16 +2586,19 @@ discard block |
||
| 2453 | 2586 | $context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start']; |
| 2454 | 2587 | $groups = array_merge($board_info['groups'], array(1)); |
| 2455 | 2588 | |
| 2456 | - if (isset($_POST['membergroups'])) |
|
| 2457 | - $_POST['who'] = explode(',', $_POST['membergroups']); |
|
| 2589 | + if (isset($_POST['membergroups'])) { |
|
| 2590 | + $_POST['who'] = explode(',', $_POST['membergroups']); |
|
| 2591 | + } |
|
| 2458 | 2592 | |
| 2459 | 2593 | // Check whether at least one membergroup was selected. |
| 2460 | - if (empty($_POST['who'])) |
|
| 2461 | - fatal_lang_error('no_membergroup_selected'); |
|
| 2594 | + if (empty($_POST['who'])) { |
|
| 2595 | + fatal_lang_error('no_membergroup_selected'); |
|
| 2596 | + } |
|
| 2462 | 2597 | |
| 2463 | 2598 | // Make sure all membergroups are integers and can access the board of the announcement. |
| 2464 | - foreach ($_POST['who'] as $id => $mg) |
|
| 2465 | - $_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0; |
|
| 2599 | + foreach ($_POST['who'] as $id => $mg) { |
|
| 2600 | + $_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0; |
|
| 2601 | + } |
|
| 2466 | 2602 | |
| 2467 | 2603 | // Get the topic subject and censor it. |
| 2468 | 2604 | $request = $smcFunc['db_query']('', ' |
@@ -2508,12 +2644,13 @@ discard block |
||
| 2508 | 2644 | if ($smcFunc['db_num_rows']($request) == 0) |
| 2509 | 2645 | { |
| 2510 | 2646 | logAction('announce_topic', array('topic' => $topic), 'user'); |
| 2511 | - if (!empty($_REQUEST['move']) && allowedTo('move_any')) |
|
| 2512 | - redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2513 | - elseif (!empty($_REQUEST['goback'])) |
|
| 2514 | - redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie')); |
|
| 2515 | - else |
|
| 2516 | - redirectexit('board=' . $board . '.0'); |
|
| 2647 | + if (!empty($_REQUEST['move']) && allowedTo('move_any')) { |
|
| 2648 | + redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2649 | + } elseif (!empty($_REQUEST['goback'])) { |
|
| 2650 | + redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie')); |
|
| 2651 | + } else { |
|
| 2652 | + redirectexit('board=' . $board . '.0'); |
|
| 2653 | + } |
|
| 2517 | 2654 | } |
| 2518 | 2655 | |
| 2519 | 2656 | $announcements = array(); |
@@ -2532,8 +2669,9 @@ discard block |
||
| 2532 | 2669 | foreach ($rows as $row) |
| 2533 | 2670 | { |
| 2534 | 2671 | // Force them to have it? |
| 2535 | - if (empty($prefs[$row['id_member']]['announcements'])) |
|
| 2536 | - continue; |
|
| 2672 | + if (empty($prefs[$row['id_member']]['announcements'])) { |
|
| 2673 | + continue; |
|
| 2674 | + } |
|
| 2537 | 2675 | |
| 2538 | 2676 | $cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']; |
| 2539 | 2677 | |
@@ -2561,8 +2699,9 @@ discard block |
||
| 2561 | 2699 | } |
| 2562 | 2700 | |
| 2563 | 2701 | // For each language send a different mail - low priority... |
| 2564 | - foreach ($announcements as $lang => $mail) |
|
| 2565 | - sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5); |
|
| 2702 | + foreach ($announcements as $lang => $mail) { |
|
| 2703 | + sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5); |
|
| 2704 | + } |
|
| 2566 | 2705 | |
| 2567 | 2706 | $context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1); |
| 2568 | 2707 | |
@@ -2572,9 +2711,10 @@ discard block |
||
| 2572 | 2711 | $context['sub_template'] = 'announcement_send'; |
| 2573 | 2712 | |
| 2574 | 2713 | // Go back to the correct language for the user ;). |
| 2575 | - if (!empty($modSettings['userLanguage'])) |
|
| 2576 | - loadLanguage('Post'); |
|
| 2577 | -} |
|
| 2714 | + if (!empty($modSettings['userLanguage'])) { |
|
| 2715 | + loadLanguage('Post'); |
|
| 2716 | + } |
|
| 2717 | + } |
|
| 2578 | 2718 | |
| 2579 | 2719 | /** |
| 2580 | 2720 | * Get the topic for display purposes. |
@@ -2587,12 +2727,13 @@ discard block |
||
| 2587 | 2727 | { |
| 2588 | 2728 | global $topic, $modSettings, $context, $smcFunc, $counter, $options; |
| 2589 | 2729 | |
| 2590 | - if (isset($_REQUEST['xml'])) |
|
| 2591 | - $limit = ' |
|
| 2730 | + if (isset($_REQUEST['xml'])) { |
|
| 2731 | + $limit = ' |
|
| 2592 | 2732 | LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']); |
| 2593 | - else |
|
| 2594 | - $limit = empty($modSettings['topicSummaryPosts']) ? '' : ' |
|
| 2733 | + } else { |
|
| 2734 | + $limit = empty($modSettings['topicSummaryPosts']) ? '' : ' |
|
| 2595 | 2735 | LIMIT ' . (int) $modSettings['topicSummaryPosts']; |
| 2736 | + } |
|
| 2596 | 2737 | |
| 2597 | 2738 | // If you're modifying, get only those posts before the current one. (otherwise get all.) |
| 2598 | 2739 | $request = $smcFunc['db_query']('', ' |
@@ -2630,8 +2771,9 @@ discard block |
||
| 2630 | 2771 | 'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']), |
| 2631 | 2772 | ); |
| 2632 | 2773 | |
| 2633 | - if (!empty($context['new_replies'])) |
|
| 2634 | - $context['new_replies']--; |
|
| 2774 | + if (!empty($context['new_replies'])) { |
|
| 2775 | + $context['new_replies']--; |
|
| 2776 | + } |
|
| 2635 | 2777 | } |
| 2636 | 2778 | $smcFunc['db_free_result']($request); |
| 2637 | 2779 | } |
@@ -2648,8 +2790,9 @@ discard block |
||
| 2648 | 2790 | global $sourcedir, $smcFunc; |
| 2649 | 2791 | |
| 2650 | 2792 | loadLanguage('Post'); |
| 2651 | - if (!isset($_REQUEST['xml'])) |
|
| 2652 | - loadTemplate('Post'); |
|
| 2793 | + if (!isset($_REQUEST['xml'])) { |
|
| 2794 | + loadTemplate('Post'); |
|
| 2795 | + } |
|
| 2653 | 2796 | |
| 2654 | 2797 | include_once($sourcedir . '/Subs-Post.php'); |
| 2655 | 2798 | |
@@ -2680,8 +2823,9 @@ discard block |
||
| 2680 | 2823 | $smcFunc['db_free_result']($request); |
| 2681 | 2824 | |
| 2682 | 2825 | $context['sub_template'] = 'quotefast'; |
| 2683 | - if (!empty($row)) |
|
| 2684 | - $can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']); |
|
| 2826 | + if (!empty($row)) { |
|
| 2827 | + $can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']); |
|
| 2828 | + } |
|
| 2685 | 2829 | |
| 2686 | 2830 | if (!empty($can_view_post)) |
| 2687 | 2831 | { |
@@ -2714,8 +2858,9 @@ discard block |
||
| 2714 | 2858 | } |
| 2715 | 2859 | |
| 2716 | 2860 | // Remove any nested quotes. |
| 2717 | - if (!empty($modSettings['removeNestedQuotes'])) |
|
| 2718 | - $row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']); |
|
| 2861 | + if (!empty($modSettings['removeNestedQuotes'])) { |
|
| 2862 | + $row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']); |
|
| 2863 | + } |
|
| 2719 | 2864 | |
| 2720 | 2865 | $lb = "\n"; |
| 2721 | 2866 | |
@@ -2741,14 +2886,14 @@ discard block |
||
| 2741 | 2886 | 'time' => '', |
| 2742 | 2887 | ), |
| 2743 | 2888 | ); |
| 2744 | - } |
|
| 2745 | - else |
|
| 2746 | - $context['quote'] = array( |
|
| 2889 | + } else { |
|
| 2890 | + $context['quote'] = array( |
|
| 2747 | 2891 | 'xml' => '', |
| 2748 | 2892 | 'mozilla' => '', |
| 2749 | 2893 | 'text' => '', |
| 2750 | 2894 | ); |
| 2751 | -} |
|
| 2895 | + } |
|
| 2896 | + } |
|
| 2752 | 2897 | |
| 2753 | 2898 | /** |
| 2754 | 2899 | * Used to edit the body or subject of a message inline |
@@ -2760,8 +2905,9 @@ discard block |
||
| 2760 | 2905 | global $user_info, $context, $smcFunc, $language, $board_info; |
| 2761 | 2906 | |
| 2762 | 2907 | // We have to have a topic! |
| 2763 | - if (empty($topic)) |
|
| 2764 | - obExit(false); |
|
| 2908 | + if (empty($topic)) { |
|
| 2909 | + obExit(false); |
|
| 2910 | + } |
|
| 2765 | 2911 | |
| 2766 | 2912 | checkSession('get'); |
| 2767 | 2913 | require_once($sourcedir . '/Subs-Post.php'); |
@@ -2787,31 +2933,35 @@ discard block |
||
| 2787 | 2933 | 'guest_id' => 0, |
| 2788 | 2934 | ) |
| 2789 | 2935 | ); |
| 2790 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 2791 | - fatal_lang_error('no_board', false); |
|
| 2936 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 2937 | + fatal_lang_error('no_board', false); |
|
| 2938 | + } |
|
| 2792 | 2939 | $row = $smcFunc['db_fetch_assoc']($request); |
| 2793 | 2940 | $smcFunc['db_free_result']($request); |
| 2794 | 2941 | |
| 2795 | 2942 | // Change either body or subject requires permissions to modify messages. |
| 2796 | 2943 | if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon'])) |
| 2797 | 2944 | { |
| 2798 | - if (!empty($row['locked'])) |
|
| 2799 | - isAllowedTo('moderate_board'); |
|
| 2945 | + if (!empty($row['locked'])) { |
|
| 2946 | + isAllowedTo('moderate_board'); |
|
| 2947 | + } |
|
| 2800 | 2948 | |
| 2801 | 2949 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
| 2802 | 2950 | { |
| 2803 | - if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
| 2804 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 2805 | - elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) |
|
| 2806 | - isAllowedTo('modify_replies'); |
|
| 2807 | - else |
|
| 2808 | - isAllowedTo('modify_own'); |
|
| 2951 | + if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
| 2952 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 2953 | + } elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
| 2954 | + isAllowedTo('modify_replies'); |
|
| 2955 | + } else { |
|
| 2956 | + isAllowedTo('modify_own'); |
|
| 2957 | + } |
|
| 2809 | 2958 | } |
| 2810 | 2959 | // Otherwise, they're locked out; someone who can modify the replies is needed. |
| 2811 | - elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 2812 | - isAllowedTo('modify_replies'); |
|
| 2813 | - else |
|
| 2814 | - isAllowedTo('modify_any'); |
|
| 2960 | + elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) { |
|
| 2961 | + isAllowedTo('modify_replies'); |
|
| 2962 | + } else { |
|
| 2963 | + isAllowedTo('modify_any'); |
|
| 2964 | + } |
|
| 2815 | 2965 | |
| 2816 | 2966 | // Only log this action if it wasn't your message. |
| 2817 | 2967 | $moderationAction = $row['id_member'] != $user_info['id']; |
@@ -2823,10 +2973,10 @@ discard block |
||
| 2823 | 2973 | $_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => '')); |
| 2824 | 2974 | |
| 2825 | 2975 | // Maximum number of characters. |
| 2826 | - if ($smcFunc['strlen']($_POST['subject']) > 100) |
|
| 2827 | - $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
| 2828 | - } |
|
| 2829 | - elseif (isset($_POST['subject'])) |
|
| 2976 | + if ($smcFunc['strlen']($_POST['subject']) > 100) { |
|
| 2977 | + $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
| 2978 | + } |
|
| 2979 | + } elseif (isset($_POST['subject'])) |
|
| 2830 | 2980 | { |
| 2831 | 2981 | $post_errors[] = 'no_subject'; |
| 2832 | 2982 | unset($_POST['subject']); |
@@ -2838,13 +2988,11 @@ discard block |
||
| 2838 | 2988 | { |
| 2839 | 2989 | $post_errors[] = 'no_message'; |
| 2840 | 2990 | unset($_POST['message']); |
| 2841 | - } |
|
| 2842 | - elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) |
|
| 2991 | + } elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) |
|
| 2843 | 2992 | { |
| 2844 | 2993 | $post_errors[] = 'long_message'; |
| 2845 | 2994 | unset($_POST['message']); |
| 2846 | - } |
|
| 2847 | - else |
|
| 2995 | + } else |
|
| 2848 | 2996 | { |
| 2849 | 2997 | $_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES); |
| 2850 | 2998 | |
@@ -2860,31 +3008,34 @@ discard block |
||
| 2860 | 3008 | |
| 2861 | 3009 | if (isset($_POST['lock'])) |
| 2862 | 3010 | { |
| 2863 | - if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) |
|
| 2864 | - unset($_POST['lock']); |
|
| 2865 | - elseif (!allowedTo('lock_any')) |
|
| 3011 | + if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) { |
|
| 3012 | + unset($_POST['lock']); |
|
| 3013 | + } elseif (!allowedTo('lock_any')) |
|
| 2866 | 3014 | { |
| 2867 | - if ($row['locked'] == 1) |
|
| 2868 | - unset($_POST['lock']); |
|
| 2869 | - else |
|
| 2870 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 3015 | + if ($row['locked'] == 1) { |
|
| 3016 | + unset($_POST['lock']); |
|
| 3017 | + } else { |
|
| 3018 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 3019 | + } |
|
| 3020 | + } elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) { |
|
| 3021 | + unset($_POST['lock']); |
|
| 3022 | + } else { |
|
| 3023 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
|
| 2871 | 3024 | } |
| 2872 | - elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) |
|
| 2873 | - unset($_POST['lock']); |
|
| 2874 | - else |
|
| 2875 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
|
| 2876 | 3025 | } |
| 2877 | 3026 | |
| 2878 | - if (isset($_POST['sticky']) && !allowedTo('make_sticky')) |
|
| 2879 | - unset($_POST['sticky']); |
|
| 3027 | + if (isset($_POST['sticky']) && !allowedTo('make_sticky')) { |
|
| 3028 | + unset($_POST['sticky']); |
|
| 3029 | + } |
|
| 2880 | 3030 | |
| 2881 | 3031 | if (isset($_POST['modify_reason'])) |
| 2882 | 3032 | { |
| 2883 | 3033 | $_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => '')); |
| 2884 | 3034 | |
| 2885 | 3035 | // Maximum number of characters. |
| 2886 | - if ($smcFunc['strlen']($_POST['modify_reason']) > 100) |
|
| 2887 | - $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
| 3036 | + if ($smcFunc['strlen']($_POST['modify_reason']) > 100) { |
|
| 3037 | + $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
| 3038 | + } |
|
| 2888 | 3039 | } |
| 2889 | 3040 | |
| 2890 | 3041 | if (empty($post_errors)) |
@@ -2921,8 +3072,9 @@ discard block |
||
| 2921 | 3072 | } |
| 2922 | 3073 | } |
| 2923 | 3074 | // If nothing was changed there's no need to add an entry to the moderation log. |
| 2924 | - else |
|
| 2925 | - $moderationAction = false; |
|
| 3075 | + else { |
|
| 3076 | + $moderationAction = false; |
|
| 3077 | + } |
|
| 2926 | 3078 | |
| 2927 | 3079 | modifyPost($msgOptions, $topicOptions, $posterOptions); |
| 2928 | 3080 | |
@@ -2940,9 +3092,9 @@ discard block |
||
| 2940 | 3092 | // Get the proper (default language) response prefix first. |
| 2941 | 3093 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
| 2942 | 3094 | { |
| 2943 | - if ($language === $user_info['language']) |
|
| 2944 | - $context['response_prefix'] = $txt['response_prefix']; |
|
| 2945 | - else |
|
| 3095 | + if ($language === $user_info['language']) { |
|
| 3096 | + $context['response_prefix'] = $txt['response_prefix']; |
|
| 3097 | + } else |
|
| 2946 | 3098 | { |
| 2947 | 3099 | loadLanguage('index', $language, false); |
| 2948 | 3100 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -2964,8 +3116,9 @@ discard block |
||
| 2964 | 3116 | ); |
| 2965 | 3117 | } |
| 2966 | 3118 | |
| 2967 | - if (!empty($moderationAction)) |
|
| 2968 | - logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
| 3119 | + if (!empty($moderationAction)) { |
|
| 3120 | + logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
| 3121 | + } |
|
| 2969 | 3122 | } |
| 2970 | 3123 | |
| 2971 | 3124 | if (isset($_REQUEST['xml'])) |
@@ -3006,8 +3159,7 @@ discard block |
||
| 3006 | 3159 | ); |
| 3007 | 3160 | |
| 3008 | 3161 | censorText($context['message']['subject']); |
| 3009 | - } |
|
| 3010 | - else |
|
| 3162 | + } else |
|
| 3011 | 3163 | { |
| 3012 | 3164 | $context['message'] = array( |
| 3013 | 3165 | 'id' => $row['id_msg'], |
@@ -3019,15 +3171,16 @@ discard block |
||
| 3019 | 3171 | loadLanguage('Errors'); |
| 3020 | 3172 | foreach ($post_errors as $post_error) |
| 3021 | 3173 | { |
| 3022 | - if ($post_error == 'long_message') |
|
| 3023 | - $context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']); |
|
| 3024 | - else |
|
| 3025 | - $context['message']['errors'][] = $txt['error_' . $post_error]; |
|
| 3174 | + if ($post_error == 'long_message') { |
|
| 3175 | + $context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']); |
|
| 3176 | + } else { |
|
| 3177 | + $context['message']['errors'][] = $txt['error_' . $post_error]; |
|
| 3178 | + } |
|
| 3026 | 3179 | } |
| 3027 | 3180 | } |
| 3181 | + } else { |
|
| 3182 | + obExit(false); |
|
| 3183 | + } |
|
| 3028 | 3184 | } |
| 3029 | - else |
|
| 3030 | - obExit(false); |
|
| 3031 | -} |
|
| 3032 | 3185 | |
| 3033 | 3186 | ?> |
| 3034 | 3187 | \ No newline at end of file |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | 'class' => 'centercol', |
| 257 | 257 | ), |
| 258 | 258 | 'data' => array( |
| 259 | - 'function' => function ($entry) |
|
| 259 | + 'function' => function($entry) |
|
| 260 | 260 | { |
| 261 | 261 | return '<input type="checkbox" name="delete[]" value="' . $entry['id'] . '"' . ($entry['editable'] ? '' : ' disabled') . '>'; |
| 262 | 262 | }, |
@@ -638,7 +638,7 @@ discard block |
||
| 638 | 638 | if (empty($entries[$k]['action_text'])) |
| 639 | 639 | $entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action']; |
| 640 | 640 | $entries[$k]['action_text'] = preg_replace_callback('~\{([A-Za-z\d_]+)\}~i', |
| 641 | - function ($matches) use ($entries, $k) |
|
| 641 | + function($matches) use ($entries, $k) |
|
| 642 | 642 | { |
| 643 | 643 | return isset($entries[$k]['extra'][$matches[1]]) ? $entries[$k]['extra'][$matches[1]] : ''; |
| 644 | 644 | }, $entries[$k]['action_text']); |
@@ -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 | * Prepares the information from the moderation log for viewing. |
@@ -32,14 +33,16 @@ discard block |
||
| 32 | 33 | |
| 33 | 34 | // Are we looking at the moderation log or the administration log. |
| 34 | 35 | $context['log_type'] = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'adminlog' ? 3 : 1; |
| 35 | - if ($context['log_type'] == 3) |
|
| 36 | - isAllowedTo('admin_forum'); |
|
| 36 | + if ($context['log_type'] == 3) { |
|
| 37 | + isAllowedTo('admin_forum'); |
|
| 38 | + } |
|
| 37 | 39 | |
| 38 | 40 | // These change dependant on whether we are viewing the moderation or admin log. |
| 39 | - if ($context['log_type'] == 3 || $_REQUEST['action'] == 'admin') |
|
| 40 | - $context['url_start'] = '?action=admin;area=logs;sa=' . ($context['log_type'] == 3 ? 'adminlog' : 'modlog') . ';type=' . $context['log_type']; |
|
| 41 | - else |
|
| 42 | - $context['url_start'] = '?action=moderate;area=modlog;type=' . $context['log_type']; |
|
| 41 | + if ($context['log_type'] == 3 || $_REQUEST['action'] == 'admin') { |
|
| 42 | + $context['url_start'] = '?action=admin;area=logs;sa=' . ($context['log_type'] == 3 ? 'adminlog' : 'modlog') . ';type=' . $context['log_type']; |
|
| 43 | + } else { |
|
| 44 | + $context['url_start'] = '?action=moderate;area=modlog;type=' . $context['log_type']; |
|
| 45 | + } |
|
| 43 | 46 | |
| 44 | 47 | $context['can_delete'] = allowedTo('admin_forum'); |
| 45 | 48 | |
@@ -67,8 +70,7 @@ discard block |
||
| 67 | 70 | $log_type = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'adminlog' ? 'admin' : 'moderate'; |
| 68 | 71 | logAction('clearlog_' . $log_type, array(), $log_type); |
| 69 | 72 | |
| 70 | - } |
|
| 71 | - elseif (!empty($_POST['remove']) && isset($_POST['delete']) && $context['can_delete']) |
|
| 73 | + } elseif (!empty($_POST['remove']) && isset($_POST['delete']) && $context['can_delete']) |
|
| 72 | 74 | { |
| 73 | 75 | checkSession(); |
| 74 | 76 | validateToken('mod-ml'); |
@@ -114,15 +116,17 @@ discard block |
||
| 114 | 116 | 'ip' => array('sql' => 'lm.ip', 'label' => $txt['modlog_ip']) |
| 115 | 117 | ); |
| 116 | 118 | |
| 117 | - if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search'])) |
|
| 118 | - $search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search']; |
|
| 119 | - else |
|
| 120 | - $search_params_string = $search_params['string']; |
|
| 119 | + if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search'])) { |
|
| 120 | + $search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search']; |
|
| 121 | + } else { |
|
| 122 | + $search_params_string = $search_params['string']; |
|
| 123 | + } |
|
| 121 | 124 | |
| 122 | - if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']])) |
|
| 123 | - $search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member'); |
|
| 124 | - else |
|
| 125 | - $search_params_type = $search_params['type']; |
|
| 125 | + if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']])) { |
|
| 126 | + $search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member'); |
|
| 127 | + } else { |
|
| 128 | + $search_params_type = $search_params['type']; |
|
| 129 | + } |
|
| 126 | 130 | |
| 127 | 131 | $search_params_column = $searchTypes[$search_params_type]['sql']; |
| 128 | 132 | $search_params = array( |
@@ -301,15 +305,16 @@ discard block |
||
| 301 | 305 | $context['default_list'] = 'moderation_log_list'; |
| 302 | 306 | |
| 303 | 307 | // If a hook has changed this, respect it. |
| 304 | - if (!empty($moderation_menu_name)) |
|
| 305 | - $context[$context['moderation_menu_name']]['tab_data'] = $moderation_menu_name; |
|
| 306 | - elseif (isset($context['moderation_menu_name'])) |
|
| 307 | - $context[$context['moderation_menu_name']]['tab_data'] = array( |
|
| 308 | + if (!empty($moderation_menu_name)) { |
|
| 309 | + $context[$context['moderation_menu_name']]['tab_data'] = $moderation_menu_name; |
|
| 310 | + } elseif (isset($context['moderation_menu_name'])) { |
|
| 311 | + $context[$context['moderation_menu_name']]['tab_data'] = array( |
|
| 308 | 312 | 'title' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log'], |
| 309 | 313 | 'help' => $context['log_type'] == 3 ? 'adminlog' : 'modlog', |
| 310 | 314 | 'description' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log_desc'] |
| 311 | 315 | ); |
| 312 | -} |
|
| 316 | + } |
|
| 317 | + } |
|
| 313 | 318 | |
| 314 | 319 | /** |
| 315 | 320 | * Get the number of mod log entries. |
@@ -413,30 +418,35 @@ discard block |
||
| 413 | 418 | // Add on some of the column stuff info |
| 414 | 419 | if (!empty($row['id_board'])) |
| 415 | 420 | { |
| 416 | - if ($row['action'] == 'move') |
|
| 417 | - $row['extra']['board_to'] = $row['id_board']; |
|
| 418 | - else |
|
| 419 | - $row['extra']['board'] = $row['id_board']; |
|
| 421 | + if ($row['action'] == 'move') { |
|
| 422 | + $row['extra']['board_to'] = $row['id_board']; |
|
| 423 | + } else { |
|
| 424 | + $row['extra']['board'] = $row['id_board']; |
|
| 425 | + } |
|
| 420 | 426 | } |
| 421 | 427 | |
| 422 | - if (!empty($row['id_topic'])) |
|
| 423 | - $row['extra']['topic'] = $row['id_topic']; |
|
| 424 | - if (!empty($row['id_msg'])) |
|
| 425 | - $row['extra']['message'] = $row['id_msg']; |
|
| 428 | + if (!empty($row['id_topic'])) { |
|
| 429 | + $row['extra']['topic'] = $row['id_topic']; |
|
| 430 | + } |
|
| 431 | + if (!empty($row['id_msg'])) { |
|
| 432 | + $row['extra']['message'] = $row['id_msg']; |
|
| 433 | + } |
|
| 426 | 434 | |
| 427 | 435 | // Is this associated with a topic? |
| 428 | - if (isset($row['extra']['topic'])) |
|
| 429 | - $topics[(int) $row['extra']['topic']][] = $row['id_action']; |
|
| 430 | - if (isset($row['extra']['new_topic'])) |
|
| 431 | - $topics[(int) $row['extra']['new_topic']][] = $row['id_action']; |
|
| 436 | + if (isset($row['extra']['topic'])) { |
|
| 437 | + $topics[(int) $row['extra']['topic']][] = $row['id_action']; |
|
| 438 | + } |
|
| 439 | + if (isset($row['extra']['new_topic'])) { |
|
| 440 | + $topics[(int) $row['extra']['new_topic']][] = $row['id_action']; |
|
| 441 | + } |
|
| 432 | 442 | |
| 433 | 443 | // How about a member? |
| 434 | 444 | if (isset($row['extra']['member'])) |
| 435 | 445 | { |
| 436 | 446 | // Guests don't have names! |
| 437 | - if (empty($row['extra']['member'])) |
|
| 438 | - $row['extra']['member'] = $txt['modlog_parameter_guest']; |
|
| 439 | - else |
|
| 447 | + if (empty($row['extra']['member'])) { |
|
| 448 | + $row['extra']['member'] = $txt['modlog_parameter_guest']; |
|
| 449 | + } else |
|
| 440 | 450 | { |
| 441 | 451 | // Try to find it... |
| 442 | 452 | $members[(int) $row['extra']['member']][] = $row['id_action']; |
@@ -444,35 +454,42 @@ discard block |
||
| 444 | 454 | } |
| 445 | 455 | |
| 446 | 456 | // Associated with a board? |
| 447 | - if (isset($row['extra']['board_to'])) |
|
| 448 | - $boards[(int) $row['extra']['board_to']][] = $row['id_action']; |
|
| 449 | - if (isset($row['extra']['board_from'])) |
|
| 450 | - $boards[(int) $row['extra']['board_from']][] = $row['id_action']; |
|
| 451 | - if (isset($row['extra']['board'])) |
|
| 452 | - $boards[(int) $row['extra']['board']][] = $row['id_action']; |
|
| 457 | + if (isset($row['extra']['board_to'])) { |
|
| 458 | + $boards[(int) $row['extra']['board_to']][] = $row['id_action']; |
|
| 459 | + } |
|
| 460 | + if (isset($row['extra']['board_from'])) { |
|
| 461 | + $boards[(int) $row['extra']['board_from']][] = $row['id_action']; |
|
| 462 | + } |
|
| 463 | + if (isset($row['extra']['board'])) { |
|
| 464 | + $boards[(int) $row['extra']['board']][] = $row['id_action']; |
|
| 465 | + } |
|
| 453 | 466 | |
| 454 | 467 | // A message? |
| 455 | - if (isset($row['extra']['message'])) |
|
| 456 | - $messages[(int) $row['extra']['message']][] = $row['id_action']; |
|
| 468 | + if (isset($row['extra']['message'])) { |
|
| 469 | + $messages[(int) $row['extra']['message']][] = $row['id_action']; |
|
| 470 | + } |
|
| 457 | 471 | |
| 458 | 472 | // IP Info? |
| 459 | - if (isset($row['extra']['ip_range'])) |
|
| 460 | - if ($seeIP) |
|
| 473 | + if (isset($row['extra']['ip_range'])) { |
|
| 474 | + if ($seeIP) |
|
| 461 | 475 | $row['extra']['ip_range'] = '<a href="' . $scripturl . '?action=trackip;searchip=' . $row['extra']['ip_range'] . '">' . $row['extra']['ip_range'] . '</a>'; |
| 462 | - else |
|
| 463 | - $row['extra']['ip_range'] = $txt['logged']; |
|
| 476 | + } else { |
|
| 477 | + $row['extra']['ip_range'] = $txt['logged']; |
|
| 478 | + } |
|
| 464 | 479 | |
| 465 | 480 | // Email? |
| 466 | - if (isset($row['extra']['email'])) |
|
| 467 | - $row['extra']['email'] = '<a href="mailto:' . $row['extra']['email'] . '">' . $row['extra']['email'] . '</a>'; |
|
| 481 | + if (isset($row['extra']['email'])) { |
|
| 482 | + $row['extra']['email'] = '<a href="mailto:' . $row['extra']['email'] . '">' . $row['extra']['email'] . '</a>'; |
|
| 483 | + } |
|
| 468 | 484 | |
| 469 | 485 | // Bans are complex. |
| 470 | 486 | if ($row['action'] == 'ban' || $row['action'] == 'banremove') |
| 471 | 487 | { |
| 472 | 488 | $row['action_text'] = $txt['modlog_ac_ban' . ($row['action'] == 'banremove' ? '_remove' : '')]; |
| 473 | - foreach (array('member', 'email', 'ip_range', 'hostname') as $type) |
|
| 474 | - if (isset($row['extra'][$type])) |
|
| 489 | + foreach (array('member', 'email', 'ip_range', 'hostname') as $type) { |
|
| 490 | + if (isset($row['extra'][$type])) |
|
| 475 | 491 | $row['action_text'] .= $txt['modlog_ac_ban_trigger_' . $type]; |
| 492 | + } |
|
| 476 | 493 | } |
| 477 | 494 | |
| 478 | 495 | // The array to go to the template. Note here that action is set to a "default" value of the action doesn't match anything in the descriptions. Allows easy adding of logging events with basic details. |
@@ -508,12 +525,13 @@ discard block |
||
| 508 | 525 | foreach ($boards[$row['id_board']] as $action) |
| 509 | 526 | { |
| 510 | 527 | // Make the board number into a link - dealing with moving too. |
| 511 | - if (isset($entries[$action]['extra']['board_to']) && $entries[$action]['extra']['board_to'] == $row['id_board']) |
|
| 512 | - $entries[$action]['extra']['board_to'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
| 513 | - elseif (isset($entries[$action]['extra']['board_from']) && $entries[$action]['extra']['board_from'] == $row['id_board']) |
|
| 514 | - $entries[$action]['extra']['board_from'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
| 515 | - elseif (isset($entries[$action]['extra']['board']) && $entries[$action]['extra']['board'] == $row['id_board']) |
|
| 516 | - $entries[$action]['extra']['board'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
| 528 | + if (isset($entries[$action]['extra']['board_to']) && $entries[$action]['extra']['board_to'] == $row['id_board']) { |
|
| 529 | + $entries[$action]['extra']['board_to'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
| 530 | + } elseif (isset($entries[$action]['extra']['board_from']) && $entries[$action]['extra']['board_from'] == $row['id_board']) { |
|
| 531 | + $entries[$action]['extra']['board_from'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
| 532 | + } elseif (isset($entries[$action]['extra']['board']) && $entries[$action]['extra']['board'] == $row['id_board']) { |
|
| 533 | + $entries[$action]['extra']['board'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
| 534 | + } |
|
| 517 | 535 | } |
| 518 | 536 | } |
| 519 | 537 | $smcFunc['db_free_result']($request); |
@@ -547,10 +565,11 @@ discard block |
||
| 547 | 565 | ); |
| 548 | 566 | |
| 549 | 567 | // Make the topic number into a link - dealing with splitting too. |
| 550 | - if (isset($this_action['extra']['topic']) && $this_action['extra']['topic'] == $row['id_topic']) |
|
| 551 | - $this_action['extra']['topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>'; |
|
| 552 | - elseif (isset($this_action['extra']['new_topic']) && $this_action['extra']['new_topic'] == $row['id_topic']) |
|
| 553 | - $this_action['extra']['new_topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>'; |
|
| 568 | + if (isset($this_action['extra']['topic']) && $this_action['extra']['topic'] == $row['id_topic']) { |
|
| 569 | + $this_action['extra']['topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>'; |
|
| 570 | + } elseif (isset($this_action['extra']['new_topic']) && $this_action['extra']['new_topic'] == $row['id_topic']) { |
|
| 571 | + $this_action['extra']['new_topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>'; |
|
| 572 | + } |
|
| 554 | 573 | } |
| 555 | 574 | } |
| 556 | 575 | $smcFunc['db_free_result']($request); |
@@ -583,8 +602,9 @@ discard block |
||
| 583 | 602 | ); |
| 584 | 603 | |
| 585 | 604 | // Make the message number into a link. |
| 586 | - if (isset($this_action['extra']['message']) && $this_action['extra']['message'] == $row['id_msg']) |
|
| 587 | - $this_action['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>'; |
|
| 605 | + if (isset($this_action['extra']['message']) && $this_action['extra']['message'] == $row['id_msg']) { |
|
| 606 | + $this_action['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>'; |
|
| 607 | + } |
|
| 588 | 608 | } |
| 589 | 609 | } |
| 590 | 610 | $smcFunc['db_free_result']($request); |
@@ -624,25 +644,29 @@ discard block |
||
| 624 | 644 | foreach ($entries as $k => $entry) |
| 625 | 645 | { |
| 626 | 646 | // Make any message info links so its easier to go find that message. |
| 627 | - if (isset($entry['extra']['message']) && (empty($entry['message']) || empty($entry['message']['id']))) |
|
| 628 | - $entries[$k]['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $entry['extra']['message'] . '">' . $entry['extra']['message'] . '</a>'; |
|
| 647 | + if (isset($entry['extra']['message']) && (empty($entry['message']) || empty($entry['message']['id']))) { |
|
| 648 | + $entries[$k]['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $entry['extra']['message'] . '">' . $entry['extra']['message'] . '</a>'; |
|
| 649 | + } |
|
| 629 | 650 | |
| 630 | 651 | // Mark up any deleted members, topics and boards. |
| 631 | - foreach (array('board', 'board_from', 'board_to', 'member', 'topic', 'new_topic') as $type) |
|
| 632 | - if (!empty($entry['extra'][$type]) && is_numeric($entry['extra'][$type])) |
|
| 652 | + foreach (array('board', 'board_from', 'board_to', 'member', 'topic', 'new_topic') as $type) { |
|
| 653 | + if (!empty($entry['extra'][$type]) && is_numeric($entry['extra'][$type])) |
|
| 633 | 654 | $entries[$k]['extra'][$type] = sprintf($txt['modlog_id'], $entry['extra'][$type]); |
| 655 | + } |
|
| 634 | 656 | |
| 635 | 657 | if (isset($entry['extra']['report'])) |
| 636 | 658 | { |
| 637 | 659 | // Member profile reports go in a different area |
| 638 | - if (stristr($entry['action'], 'user_report')) |
|
| 639 | - $entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedmembers;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>'; |
|
| 640 | - else |
|
| 641 | - $entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedposts;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>'; |
|
| 660 | + if (stristr($entry['action'], 'user_report')) { |
|
| 661 | + $entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedmembers;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>'; |
|
| 662 | + } else { |
|
| 663 | + $entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedposts;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>'; |
|
| 664 | + } |
|
| 642 | 665 | } |
| 643 | 666 | |
| 644 | - if (empty($entries[$k]['action_text'])) |
|
| 645 | - $entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action']; |
|
| 667 | + if (empty($entries[$k]['action_text'])) { |
|
| 668 | + $entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action']; |
|
| 669 | + } |
|
| 646 | 670 | $entries[$k]['action_text'] = preg_replace_callback('~\{([A-Za-z\d_]+)\}~i', |
| 647 | 671 | function ($matches) use ($entries, $k) |
| 648 | 672 | { |
@@ -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 | * Class Likes |
@@ -106,8 +107,9 @@ discard block |
||
| 106 | 107 | $this->_extra = isset($_GET['extra']) ? $_GET['extra'] : false; |
| 107 | 108 | |
| 108 | 109 | // We do not want to output debug information here. |
| 109 | - if ($this->_js) |
|
| 110 | - $db_show_debug = false; |
|
| 110 | + if ($this->_js) { |
|
| 111 | + $db_show_debug = false; |
|
| 112 | + } |
|
| 111 | 113 | } |
| 112 | 114 | |
| 113 | 115 | /** |
@@ -141,8 +143,9 @@ discard block |
||
| 141 | 143 | $call = $this->_sa; |
| 142 | 144 | |
| 143 | 145 | // Guest can only view likes. |
| 144 | - if ($call != 'view') |
|
| 145 | - is_not_guest(); |
|
| 146 | + if ($call != 'view') { |
|
| 147 | + is_not_guest(); |
|
| 148 | + } |
|
| 146 | 149 | |
| 147 | 150 | checkSession('get'); |
| 148 | 151 | |
@@ -180,15 +183,17 @@ discard block |
||
| 180 | 183 | global $smcFunc, $modSettings; |
| 181 | 184 | |
| 182 | 185 | // This feature is currently disable. |
| 183 | - if (empty($modSettings['enable_likes'])) |
|
| 184 | - return $this->_error = 'like_disable'; |
|
| 186 | + if (empty($modSettings['enable_likes'])) { |
|
| 187 | + return $this->_error = 'like_disable'; |
|
| 188 | + } |
|
| 185 | 189 | |
| 186 | 190 | // Zerothly, they did indicate some kind of content to like, right? |
| 187 | 191 | preg_match('~^([a-z0-9\-\_]{1,6})~i', $this->_type, $matches); |
| 188 | 192 | $this->_type = isset($matches[1]) ? $matches[1] : ''; |
| 189 | 193 | |
| 190 | - if ($this->_type == '' || $this->_content <= 0) |
|
| 191 | - return $this->_error = 'cannot_'; |
|
| 194 | + if ($this->_type == '' || $this->_content <= 0) { |
|
| 195 | + return $this->_error = 'cannot_'; |
|
| 196 | + } |
|
| 192 | 197 | |
| 193 | 198 | // First we need to verify if the user can see the type of content or not. This is set up to be extensible, |
| 194 | 199 | // so we'll check for the one type we do know about, and if it's not that, we'll defer to any hooks. |
@@ -207,12 +212,14 @@ discard block |
||
| 207 | 212 | 'msg' => $this->_content, |
| 208 | 213 | ) |
| 209 | 214 | ); |
| 210 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
| 211 | - list ($this->_idTopic, $topicOwner) = $smcFunc['db_fetch_row']($request); |
|
| 215 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
| 216 | + list ($this->_idTopic, $topicOwner) = $smcFunc['db_fetch_row']($request); |
|
| 217 | + } |
|
| 212 | 218 | |
| 213 | 219 | $smcFunc['db_free_result']($request); |
| 214 | - if (empty($this->_idTopic)) |
|
| 215 | - return $this->_error = 'cannot_'; |
|
| 220 | + if (empty($this->_idTopic)) { |
|
| 221 | + return $this->_error = 'cannot_'; |
|
| 222 | + } |
|
| 216 | 223 | |
| 217 | 224 | // So we know what topic it's in and more importantly we know the user can see it. |
| 218 | 225 | // If we're not viewing, we need some info set up. |
@@ -221,9 +228,7 @@ discard block |
||
| 221 | 228 | $this->_validLikes['redirect'] = 'topic=' . $this->_idTopic . '.msg' . $this->_content . '#msg' . $this->_content; |
| 222 | 229 | |
| 223 | 230 | $this->_validLikes['can_like'] = ($this->_user['id'] == $topicOwner ? 'cannot_like_content' : (allowedTo('likes_like') ? true : 'cannot_like_content')); |
| 224 | - } |
|
| 225 | - |
|
| 226 | - else |
|
| 231 | + } else |
|
| 227 | 232 | { |
| 228 | 233 | // Modders: This will give you whatever the user offers up in terms of liking, e.g. $this->_type=msg, $this->_content=1 |
| 229 | 234 | // When you hook this, check $this->_type first. If it is not something your mod worries about, return false. |
@@ -241,8 +246,9 @@ discard block |
||
| 241 | 246 | if ($result !== false) |
| 242 | 247 | { |
| 243 | 248 | // Match the type with what we already have. |
| 244 | - if (!isset($result['type']) || $result['type'] != $this->_type) |
|
| 245 | - return $this->_error = 'not_valid_like_type'; |
|
| 249 | + if (!isset($result['type']) || $result['type'] != $this->_type) { |
|
| 250 | + return $this->_error = 'not_valid_like_type'; |
|
| 251 | + } |
|
| 246 | 252 | |
| 247 | 253 | // Fill out the rest. |
| 248 | 254 | $this->_type = $result['type']; |
@@ -253,13 +259,15 @@ discard block |
||
| 253 | 259 | } |
| 254 | 260 | } |
| 255 | 261 | |
| 256 | - if (!$found) |
|
| 257 | - return $this->_error = 'cannot_'; |
|
| 262 | + if (!$found) { |
|
| 263 | + return $this->_error = 'cannot_'; |
|
| 264 | + } |
|
| 258 | 265 | } |
| 259 | 266 | |
| 260 | 267 | // Does the user can like this? Viewing a list of likes doesn't require this permission. |
| 261 | - if ($this->_sa != 'view' && isset($this->_validLikes['can_like']) && is_string($this->_validLikes['can_like'])) |
|
| 262 | - return $this->_error = $this->_validLikes['can_like']; |
|
| 268 | + if ($this->_sa != 'view' && isset($this->_validLikes['can_like']) && is_string($this->_validLikes['can_like'])) { |
|
| 269 | + return $this->_error = $this->_validLikes['can_like']; |
|
| 270 | + } |
|
| 263 | 271 | } |
| 264 | 272 | |
| 265 | 273 | /** |
@@ -284,8 +292,9 @@ discard block |
||
| 284 | 292 | ); |
| 285 | 293 | |
| 286 | 294 | // Are we calling this directly? if so, set a proper data for the response. Do note that __METHOD__ returns both the class name and the function name. |
| 287 | - if ($this->_sa == __FUNCTION__) |
|
| 288 | - $this->_data = __FUNCTION__; |
|
| 295 | + if ($this->_sa == __FUNCTION__) { |
|
| 296 | + $this->_data = __FUNCTION__; |
|
| 297 | + } |
|
| 289 | 298 | } |
| 290 | 299 | |
| 291 | 300 | /** |
@@ -315,8 +324,8 @@ discard block |
||
| 315 | 324 | |
| 316 | 325 | // Add a background task to process sending alerts. |
| 317 | 326 | // Mod author, you can add your own background task for your own custom like event using the "integrate_issue_like" hook or your callback, both are immediately called after this. |
| 318 | - if ($this->_type == 'msg') |
|
| 319 | - $smcFunc['db_insert']('insert', |
|
| 327 | + if ($this->_type == 'msg') { |
|
| 328 | + $smcFunc['db_insert']('insert', |
|
| 320 | 329 | '{db_prefix}background_tasks', |
| 321 | 330 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 322 | 331 | array('$sourcedir/tasks/Likes-Notify.php', 'Likes_Notify_Background', $smcFunc['json_encode'](array( |
@@ -328,10 +337,12 @@ discard block |
||
| 328 | 337 | )), 0), |
| 329 | 338 | array('id_task') |
| 330 | 339 | ); |
| 340 | + } |
|
| 331 | 341 | |
| 332 | 342 | // Are we calling this directly? if so, set a proper data for the response. Do note that __METHOD__ returns both the class name and the function name. |
| 333 | - if ($this->_sa == __FUNCTION__) |
|
| 334 | - $this->_data = __FUNCTION__; |
|
| 343 | + if ($this->_sa == __FUNCTION__) { |
|
| 344 | + $this->_data = __FUNCTION__; |
|
| 345 | + } |
|
| 335 | 346 | } |
| 336 | 347 | |
| 337 | 348 | /** |
@@ -357,8 +368,9 @@ discard block |
||
| 357 | 368 | $smcFunc['db_free_result']($request); |
| 358 | 369 | |
| 359 | 370 | // If you want to call this directly, fill out _data property too. |
| 360 | - if ($this->_sa == __FUNCTION__) |
|
| 361 | - $this->_data = $this->_numLikes; |
|
| 371 | + if ($this->_sa == __FUNCTION__) { |
|
| 372 | + $this->_data = $this->_numLikes; |
|
| 373 | + } |
|
| 362 | 374 | } |
| 363 | 375 | |
| 364 | 376 | /** |
@@ -371,8 +383,9 @@ discard block |
||
| 371 | 383 | global $smcFunc; |
| 372 | 384 | |
| 373 | 385 | // Safety first! |
| 374 | - if (empty($this->_type) || empty($this->_content)) |
|
| 375 | - return $this->_error = 'cannot_'; |
|
| 386 | + if (empty($this->_type) || empty($this->_content)) { |
|
| 387 | + return $this->_error = 'cannot_'; |
|
| 388 | + } |
|
| 376 | 389 | |
| 377 | 390 | // Do we already like this? |
| 378 | 391 | $request = $smcFunc['db_query']('', ' |
@@ -390,26 +403,28 @@ discard block |
||
| 390 | 403 | $this->_alreadyLiked = (bool) $smcFunc['db_num_rows']($request) != 0; |
| 391 | 404 | $smcFunc['db_free_result']($request); |
| 392 | 405 | |
| 393 | - if ($this->_alreadyLiked) |
|
| 394 | - $this->delete(); |
|
| 395 | - |
|
| 396 | - else |
|
| 397 | - $this->insert(); |
|
| 406 | + if ($this->_alreadyLiked) { |
|
| 407 | + $this->delete(); |
|
| 408 | + } else { |
|
| 409 | + $this->insert(); |
|
| 410 | + } |
|
| 398 | 411 | |
| 399 | 412 | // Now, how many people like this content now? We *could* just +1 / -1 the relevant container but that has proven to become unstable. |
| 400 | 413 | $this->_count(); |
| 401 | 414 | |
| 402 | 415 | // Update the likes count for messages. |
| 403 | - if ($this->_type == 'msg') |
|
| 404 | - $this->msgIssueLike(); |
|
| 416 | + if ($this->_type == 'msg') { |
|
| 417 | + $this->msgIssueLike(); |
|
| 418 | + } |
|
| 405 | 419 | |
| 406 | 420 | // Any callbacks? |
| 407 | 421 | elseif (!empty($this->_validLikes['callback'])) |
| 408 | 422 | { |
| 409 | 423 | $call = call_helper($this->_validLikes['callback'], true); |
| 410 | 424 | |
| 411 | - if (!empty($call)) |
|
| 412 | - call_user_func_array($call, array($this)); |
|
| 425 | + if (!empty($call)) { |
|
| 426 | + call_user_func_array($call, array($this)); |
|
| 427 | + } |
|
| 413 | 428 | } |
| 414 | 429 | |
| 415 | 430 | // Sometimes there might be other things that need updating after we do this like. |
@@ -418,8 +433,9 @@ discard block |
||
| 418 | 433 | // Now some clean up. This is provided here for any like handlers that want to do any cache flushing. |
| 419 | 434 | // This way a like handler doesn't need to explicitly declare anything in integrate_issue_like, but do so |
| 420 | 435 | // in integrate_valid_likes where it absolutely has to exist. |
| 421 | - if (!empty($this->_validLikes['flush_cache'])) |
|
| 422 | - cache_put_data($this->_validLikes['flush_cache'], null); |
|
| 436 | + if (!empty($this->_validLikes['flush_cache'])) { |
|
| 437 | + cache_put_data($this->_validLikes['flush_cache'], null); |
|
| 438 | + } |
|
| 423 | 439 | |
| 424 | 440 | // All done, start building the data to pass as response. |
| 425 | 441 | $this->_data = array( |
@@ -442,8 +458,9 @@ discard block |
||
| 442 | 458 | { |
| 443 | 459 | global $smcFunc; |
| 444 | 460 | |
| 445 | - if ($this->_type !== 'msg') |
|
| 446 | - return; |
|
| 461 | + if ($this->_type !== 'msg') { |
|
| 462 | + return; |
|
| 463 | + } |
|
| 447 | 464 | |
| 448 | 465 | $smcFunc['db_query']('', ' |
| 449 | 466 | UPDATE {db_prefix}messages |
@@ -484,8 +501,9 @@ discard block |
||
| 484 | 501 | 'like_type' => $this->_type, |
| 485 | 502 | ) |
| 486 | 503 | ); |
| 487 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 488 | - $context['likers'][$row['id_member']] = array('timestamp' => $row['like_time']); |
|
| 504 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 505 | + $context['likers'][$row['id_member']] = array('timestamp' => $row['like_time']); |
|
| 506 | + } |
|
| 489 | 507 | |
| 490 | 508 | // Now to get member data, including avatars and so on. |
| 491 | 509 | $members = array_keys($context['likers']); |
@@ -493,8 +511,9 @@ discard block |
||
| 493 | 511 | if (count($loaded) != count($members)) |
| 494 | 512 | { |
| 495 | 513 | $members = array_diff($members, $loaded); |
| 496 | - foreach ($members as $not_loaded) |
|
| 497 | - unset ($context['likers'][$not_loaded]); |
|
| 514 | + foreach ($members as $not_loaded) { |
|
| 515 | + unset ($context['likers'][$not_loaded]); |
|
| 516 | + } |
|
| 498 | 517 | } |
| 499 | 518 | |
| 500 | 519 | foreach ($context['likers'] as $liker => $dummy) |
@@ -536,12 +555,14 @@ discard block |
||
| 536 | 555 | global $context, $txt; |
| 537 | 556 | |
| 538 | 557 | // Don't do anything if someone else has already take care of the response. |
| 539 | - if (!$this->_setResponse) |
|
| 540 | - return; |
|
| 558 | + if (!$this->_setResponse) { |
|
| 559 | + return; |
|
| 560 | + } |
|
| 541 | 561 | |
| 542 | 562 | // Want a json response huh? |
| 543 | - if ($this->_validLikes['json']) |
|
| 544 | - return $this->jsonResponse(); |
|
| 563 | + if ($this->_validLikes['json']) { |
|
| 564 | + return $this->jsonResponse(); |
|
| 565 | + } |
|
| 545 | 566 | |
| 546 | 567 | // Set everything up for display. |
| 547 | 568 | loadTemplate('Likes'); |
@@ -551,8 +572,9 @@ discard block |
||
| 551 | 572 | if ($this->_error) |
| 552 | 573 | { |
| 553 | 574 | // If this is a generic error, set it up good. |
| 554 | - if ($this->_error == 'cannot_') |
|
| 555 | - $this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content'; |
|
| 575 | + if ($this->_error == 'cannot_') { |
|
| 576 | + $this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content'; |
|
| 577 | + } |
|
| 556 | 578 | |
| 557 | 579 | // Is this request coming from an ajax call? |
| 558 | 580 | if ($this->_js) |
@@ -562,8 +584,9 @@ discard block |
||
| 562 | 584 | } |
| 563 | 585 | |
| 564 | 586 | // Nope? then just do a redirect to whatever URL was provided. |
| 565 | - else |
|
| 566 | - redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] . ';error=' . $this->_error : ''); |
|
| 587 | + else { |
|
| 588 | + redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] . ';error=' . $this->_error : ''); |
|
| 589 | + } |
|
| 567 | 590 | |
| 568 | 591 | return; |
| 569 | 592 | } |
@@ -572,8 +595,9 @@ discard block |
||
| 572 | 595 | else |
| 573 | 596 | { |
| 574 | 597 | // Not an ajax request so send the user back to the previous location or the main page. |
| 575 | - if (!$this->_js) |
|
| 576 | - redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] : ''); |
|
| 598 | + if (!$this->_js) { |
|
| 599 | + redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] : ''); |
|
| 600 | + } |
|
| 577 | 601 | |
| 578 | 602 | // These fine gentlemen all share the same template. |
| 579 | 603 | $generic = array('delete', 'insert', '_count'); |
@@ -606,8 +630,9 @@ discard block |
||
| 606 | 630 | // If there is an error, send it. |
| 607 | 631 | if ($this->_error) |
| 608 | 632 | { |
| 609 | - if ($this->_error == 'cannot_') |
|
| 610 | - $this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content'; |
|
| 633 | + if ($this->_error == 'cannot_') { |
|
| 634 | + $this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content'; |
|
| 635 | + } |
|
| 611 | 636 | |
| 612 | 637 | $print['error'] = $this->_error; |
| 613 | 638 | } |
@@ -643,33 +668,36 @@ discard block |
||
| 643 | 668 | <body style="background-color: #444455; color: white; font-style: italic; font-family: serif;"> |
| 644 | 669 | <div style="margin-top: 12%; font-size: 1.1em; line-height: 1.4; text-align: center;">'; |
| 645 | 670 | |
| 646 | - if (!isset($_GET['verse']) || ($_GET['verse'] != '2:18' && $_GET['verse'] != '22:1-2')) |
|
| 647 | - $_GET['verse'] = '4:16'; |
|
| 671 | + if (!isset($_GET['verse']) || ($_GET['verse'] != '2:18' && $_GET['verse'] != '22:1-2')) { |
|
| 672 | + $_GET['verse'] = '4:16'; |
|
| 673 | + } |
|
| 648 | 674 | |
| 649 | - if ($_GET['verse'] == '2:18') |
|
| 650 | - echo ' |
|
| 675 | + if ($_GET['verse'] == '2:18') { |
|
| 676 | + echo ' |
|
| 651 | 677 | Woe, it was that his name wasn\'t <em>known</em>, that he came in mystery, and was recognized by none. And it became to be in those days <em>something</em>. Something not yet <em id="unknown" name="[Unknown]">unknown</em> to mankind. And thus what was to be known the <em>secret project</em> began into its existence. Henceforth the opposition was only <em>weary</em> and <em>fearful</em>, for now their match was at arms against them.'; |
| 652 | - elseif ($_GET['verse'] == '4:16') |
|
| 653 | - echo ' |
|
| 678 | + } elseif ($_GET['verse'] == '4:16') { |
|
| 679 | + echo ' |
|
| 654 | 680 | And it came to pass that the <em>unbelievers</em> dwindled in number and saw rise of many <em>proselytizers</em>, and the opposition found fear in the face of the <em>x</em> and the <em>j</em> while those who stood with the <em>something</em> grew stronger and came together. Still, this was only the <em>beginning</em>, and what lay in the future was <em id="unknown" name="[Unknown]">unknown</em> to all, even those on the right side.'; |
| 655 | - elseif ($_GET['verse'] == '22:1-2') |
|
| 656 | - echo ' |
|
| 681 | + } elseif ($_GET['verse'] == '22:1-2') { |
|
| 682 | + echo ' |
|
| 657 | 683 | <p>Now <em>behold</em>, that which was once the secret project was <em id="unknown" name="[Unknown]">unknown</em> no longer. Alas, it needed more than <em>only one</em>, but yet even thought otherwise. It became that the opposition <em>rumored</em> and lied, but still to no avail. Their match, though not <em>perfect</em>, had them outdone.</p> |
| 658 | 684 | <p style="margin: 2ex 1ex 0 1ex; font-size: 1.05em; line-height: 1.5; text-align: center;">Let it continue. <em>The end</em>.</p>'; |
| 685 | + } |
|
| 659 | 686 | |
| 660 | 687 | echo ' |
| 661 | 688 | </div> |
| 662 | 689 | <div style="margin-top: 2ex; font-size: 2em; text-align: right;">'; |
| 663 | 690 | |
| 664 | - if ($_GET['verse'] == '2:18') |
|
| 665 | - echo ' |
|
| 691 | + if ($_GET['verse'] == '2:18') { |
|
| 692 | + echo ' |
|
| 666 | 693 | from <span style="font-family: Georgia, serif;"><strong><a href="', $scripturl, '?action=about:unknown;verse=4:16" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 2:18</span>'; |
| 667 | - elseif ($_GET['verse'] == '4:16') |
|
| 668 | - echo ' |
|
| 694 | + } elseif ($_GET['verse'] == '4:16') { |
|
| 695 | + echo ' |
|
| 669 | 696 | from <span style="font-family: Georgia, serif;"><strong><a href="', $scripturl, '?action=about:unknown;verse=22:1-2" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 4:16</span>'; |
| 670 | - elseif ($_GET['verse'] == '22:1-2') |
|
| 671 | - echo ' |
|
| 697 | + } elseif ($_GET['verse'] == '22:1-2') { |
|
| 698 | + echo ' |
|
| 672 | 699 | from <span style="font-family: Georgia, serif;"><strong>The Book of Unknown</strong>, 22:1-2</span>'; |
| 700 | + } |
|
| 673 | 701 | |
| 674 | 702 | echo ' |
| 675 | 703 | </div> |
@@ -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 | * Get all birthdays within the given time range. |
@@ -60,8 +61,7 @@ discard block |
||
| 60 | 61 | 'max_year' => $year_high, |
| 61 | 62 | ) |
| 62 | 63 | ); |
| 63 | - } |
|
| 64 | - else |
|
| 64 | + } else |
|
| 65 | 65 | { |
| 66 | 66 | $result = $smcFunc['db_query']('birthday_array', ' |
| 67 | 67 | SELECT id_member, real_name, YEAR(birthdate) AS birth_year, birthdate |
@@ -91,10 +91,11 @@ discard block |
||
| 91 | 91 | $bday = array(); |
| 92 | 92 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 93 | 93 | { |
| 94 | - if ($year_low != $year_high) |
|
| 95 | - $age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low; |
|
| 96 | - else |
|
| 97 | - $age_year = $year_low; |
|
| 94 | + if ($year_low != $year_high) { |
|
| 95 | + $age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low; |
|
| 96 | + } else { |
|
| 97 | + $age_year = $year_low; |
|
| 98 | + } |
|
| 98 | 99 | |
| 99 | 100 | $bday[$age_year . substr($row['birthdate'], 4)][] = array( |
| 100 | 101 | 'id' => $row['id_member'], |
@@ -108,8 +109,9 @@ discard block |
||
| 108 | 109 | ksort($bday); |
| 109 | 110 | |
| 110 | 111 | // Set is_last, so the themes know when to stop placing separators. |
| 111 | - foreach ($bday as $mday => $array) |
|
| 112 | - $bday[$mday][count($array) - 1]['is_last'] = true; |
|
| 112 | + foreach ($bday as $mday => $array) { |
|
| 113 | + $bday[$mday][count($array) - 1]['is_last'] = true; |
|
| 114 | + } |
|
| 113 | 115 | |
| 114 | 116 | return $bday; |
| 115 | 117 | } |
@@ -133,8 +135,9 @@ discard block |
||
| 133 | 135 | static $timezone_array = array(); |
| 134 | 136 | require_once($sourcedir . '/Subs.php'); |
| 135 | 137 | |
| 136 | - if (empty($timezone_array['default'])) |
|
| 137 | - $timezone_array['default'] = timezone_open(date_default_timezone_get()); |
|
| 138 | + if (empty($timezone_array['default'])) { |
|
| 139 | + $timezone_array['default'] = timezone_open(date_default_timezone_get()); |
|
| 140 | + } |
|
| 138 | 141 | |
| 139 | 142 | $low_object = date_create($low_date); |
| 140 | 143 | $high_object = date_create($high_date); |
@@ -161,8 +164,9 @@ discard block |
||
| 161 | 164 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 162 | 165 | { |
| 163 | 166 | // If the attached topic is not approved then for the moment pretend it doesn't exist |
| 164 | - if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) |
|
| 165 | - continue; |
|
| 167 | + if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) { |
|
| 168 | + continue; |
|
| 169 | + } |
|
| 166 | 170 | |
| 167 | 171 | // Force a censor of the title - as often these are used by others. |
| 168 | 172 | censorText($row['title'], $use_permissions ? false : true); |
@@ -170,12 +174,14 @@ discard block |
||
| 170 | 174 | // Get the various time and date properties for this event |
| 171 | 175 | list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row); |
| 172 | 176 | |
| 173 | - if (empty($timezone_array[$tz])) |
|
| 174 | - $timezone_array[$tz] = timezone_open($tz); |
|
| 177 | + if (empty($timezone_array[$tz])) { |
|
| 178 | + $timezone_array[$tz] = timezone_open($tz); |
|
| 179 | + } |
|
| 175 | 180 | |
| 176 | 181 | // Sanity check |
| 177 | - if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) |
|
| 178 | - continue; |
|
| 182 | + if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) { |
|
| 183 | + continue; |
|
| 184 | + } |
|
| 179 | 185 | |
| 180 | 186 | // Get set up for the loop |
| 181 | 187 | $start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), $timezone_array[$tz]); |
@@ -239,8 +245,8 @@ discard block |
||
| 239 | 245 | ); |
| 240 | 246 | |
| 241 | 247 | // If we're using permissions (calendar pages?) then just ouput normal contextual style information. |
| 242 | - if ($use_permissions) |
|
| 243 | - $events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array( |
|
| 248 | + if ($use_permissions) { |
|
| 249 | + $events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array( |
|
| 244 | 250 | 'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0', |
| 245 | 251 | 'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>', |
| 246 | 252 | 'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')), |
@@ -248,9 +254,10 @@ discard block |
||
| 248 | 254 | 'can_export' => !empty($modSettings['cal_export']) ? true : false, |
| 249 | 255 | 'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'], |
| 250 | 256 | )); |
| 257 | + } |
|
| 251 | 258 | // Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info. |
| 252 | - else |
|
| 253 | - $events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array( |
|
| 259 | + else { |
|
| 260 | + $events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array( |
|
| 254 | 261 | 'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0', |
| 255 | 262 | 'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>', |
| 256 | 263 | 'can_edit' => false, |
@@ -260,6 +267,7 @@ discard block |
||
| 260 | 267 | 'poster' => $row['id_member'], |
| 261 | 268 | 'allowed_groups' => explode(',', $row['member_groups']), |
| 262 | 269 | )); |
| 270 | + } |
|
| 263 | 271 | |
| 264 | 272 | date_add($cal_date, date_interval_create_from_date_string('1 day')); |
| 265 | 273 | } |
@@ -269,8 +277,9 @@ discard block |
||
| 269 | 277 | // If we're doing normal contextual data, go through and make things clear to the templates ;). |
| 270 | 278 | if ($use_permissions) |
| 271 | 279 | { |
| 272 | - foreach ($events as $mday => $array) |
|
| 273 | - $events[$mday][count($array) - 1]['is_last'] = true; |
|
| 280 | + foreach ($events as $mday => $array) { |
|
| 281 | + $events[$mday][count($array) - 1]['is_last'] = true; |
|
| 282 | + } |
|
| 274 | 283 | } |
| 275 | 284 | |
| 276 | 285 | ksort($events); |
@@ -290,11 +299,12 @@ discard block |
||
| 290 | 299 | global $smcFunc; |
| 291 | 300 | |
| 292 | 301 | // Get the lowest and highest dates for "all years". |
| 293 | - if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) |
|
| 294 | - $allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec} |
|
| 302 | + if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) { |
|
| 303 | + $allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec} |
|
| 295 | 304 | OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}'; |
| 296 | - else |
|
| 297 | - $allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}'; |
|
| 305 | + } else { |
|
| 306 | + $allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}'; |
|
| 307 | + } |
|
| 298 | 308 | |
| 299 | 309 | // Find some holidays... ;). |
| 300 | 310 | $result = $smcFunc['db_query']('', ' |
@@ -314,10 +324,11 @@ discard block |
||
| 314 | 324 | $holidays = array(); |
| 315 | 325 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 316 | 326 | { |
| 317 | - if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) |
|
| 318 | - $event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4); |
|
| 319 | - else |
|
| 320 | - $event_year = substr($low_date, 0, 4); |
|
| 327 | + if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) { |
|
| 328 | + $event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4); |
|
| 329 | + } else { |
|
| 330 | + $event_year = substr($low_date, 0, 4); |
|
| 331 | + } |
|
| 321 | 332 | |
| 322 | 333 | $holidays[$event_year . substr($row['event_date'], 4)][] = $row['title']; |
| 323 | 334 | } |
@@ -343,10 +354,12 @@ discard block |
||
| 343 | 354 | isAllowedTo('calendar_post'); |
| 344 | 355 | |
| 345 | 356 | // No board? No topic?!? |
| 346 | - if (empty($board)) |
|
| 347 | - fatal_lang_error('missing_board_id', false); |
|
| 348 | - if (empty($topic)) |
|
| 349 | - fatal_lang_error('missing_topic_id', false); |
|
| 357 | + if (empty($board)) { |
|
| 358 | + fatal_lang_error('missing_board_id', false); |
|
| 359 | + } |
|
| 360 | + if (empty($topic)) { |
|
| 361 | + fatal_lang_error('missing_topic_id', false); |
|
| 362 | + } |
|
| 350 | 363 | |
| 351 | 364 | // Administrator, Moderator, or owner. Period. |
| 352 | 365 | if (!allowedTo('admin_forum') && !allowedTo('moderate_board')) |
@@ -364,12 +377,14 @@ discard block |
||
| 364 | 377 | if ($row = $smcFunc['db_fetch_assoc']($result)) |
| 365 | 378 | { |
| 366 | 379 | // Not the owner of the topic. |
| 367 | - if ($row['id_member_started'] != $user_info['id']) |
|
| 368 | - fatal_lang_error('not_your_topic', 'user'); |
|
| 380 | + if ($row['id_member_started'] != $user_info['id']) { |
|
| 381 | + fatal_lang_error('not_your_topic', 'user'); |
|
| 382 | + } |
|
| 369 | 383 | } |
| 370 | 384 | // Topic/Board doesn't exist..... |
| 371 | - else |
|
| 372 | - fatal_lang_error('calendar_no_topic', 'general'); |
|
| 385 | + else { |
|
| 386 | + fatal_lang_error('calendar_no_topic', 'general'); |
|
| 387 | + } |
|
| 373 | 388 | $smcFunc['db_free_result']($result); |
| 374 | 389 | } |
| 375 | 390 | } |
@@ -457,14 +472,16 @@ discard block |
||
| 457 | 472 | if (!empty($calendarOptions['start_day'])) |
| 458 | 473 | { |
| 459 | 474 | $nShift -= $calendarOptions['start_day']; |
| 460 | - if ($nShift < 0) |
|
| 461 | - $nShift = 7 + $nShift; |
|
| 475 | + if ($nShift < 0) { |
|
| 476 | + $nShift = 7 + $nShift; |
|
| 477 | + } |
|
| 462 | 478 | } |
| 463 | 479 | |
| 464 | 480 | // Number of rows required to fit the month. |
| 465 | 481 | $nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7); |
| 466 | - if (($month_info['last_day']['day_of_month'] + $nShift) % 7) |
|
| 467 | - $nRows++; |
|
| 482 | + if (($month_info['last_day']['day_of_month'] + $nShift) % 7) { |
|
| 483 | + $nRows++; |
|
| 484 | + } |
|
| 468 | 485 | |
| 469 | 486 | // Fetch the arrays for birthdays, posted events, and holidays. |
| 470 | 487 | $bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array(); |
@@ -477,8 +494,9 @@ discard block |
||
| 477 | 494 | { |
| 478 | 495 | $calendarGrid['week_days'][] = $count; |
| 479 | 496 | $count++; |
| 480 | - if ($count == 7) |
|
| 481 | - $count = 0; |
|
| 497 | + if ($count == 7) { |
|
| 498 | + $count = 0; |
|
| 499 | + } |
|
| 482 | 500 | } |
| 483 | 501 | |
| 484 | 502 | // Iterate through each week. |
@@ -495,8 +513,9 @@ discard block |
||
| 495 | 513 | { |
| 496 | 514 | $nDay = ($nRow * 7) + $nCol - $nShift + 1; |
| 497 | 515 | |
| 498 | - if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) |
|
| 499 | - $nDay = 0; |
|
| 516 | + if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) { |
|
| 517 | + $nDay = 0; |
|
| 518 | + } |
|
| 500 | 519 | |
| 501 | 520 | $date = sprintf('%04d-%02d-%02d', $year, $month, $nDay); |
| 502 | 521 | |
@@ -514,8 +533,9 @@ discard block |
||
| 514 | 533 | } |
| 515 | 534 | |
| 516 | 535 | // What is the last day of the month? |
| 517 | - if ($is_previous === true) |
|
| 518 | - $calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month']; |
|
| 536 | + if ($is_previous === true) { |
|
| 537 | + $calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month']; |
|
| 538 | + } |
|
| 519 | 539 | |
| 520 | 540 | // We'll use the shift in the template. |
| 521 | 541 | $calendarGrid['shift'] = $nShift; |
@@ -549,8 +569,9 @@ discard block |
||
| 549 | 569 | { |
| 550 | 570 | // Here we offset accordingly to get things to the real start of a week. |
| 551 | 571 | $date_diff = $day_of_week - $calendarOptions['start_day']; |
| 552 | - if ($date_diff < 0) |
|
| 553 | - $date_diff += 7; |
|
| 572 | + if ($date_diff < 0) { |
|
| 573 | + $date_diff += 7; |
|
| 574 | + } |
|
| 554 | 575 | $new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400; |
| 555 | 576 | $day = (int) strftime('%d', $new_timestamp); |
| 556 | 577 | $month = (int) strftime('%m', $new_timestamp); |
@@ -680,18 +701,20 @@ discard block |
||
| 680 | 701 | { |
| 681 | 702 | foreach ($date_events as $event_key => $event_val) |
| 682 | 703 | { |
| 683 | - if (in_array($event_val['id'], $temp)) |
|
| 684 | - unset($calendarGrid['events'][$date][$event_key]); |
|
| 685 | - else |
|
| 686 | - $temp[] = $event_val['id']; |
|
| 704 | + if (in_array($event_val['id'], $temp)) { |
|
| 705 | + unset($calendarGrid['events'][$date][$event_key]); |
|
| 706 | + } else { |
|
| 707 | + $temp[] = $event_val['id']; |
|
| 708 | + } |
|
| 687 | 709 | } |
| 688 | 710 | } |
| 689 | 711 | |
| 690 | 712 | // Give birthdays and holidays a friendly format, without the year |
| 691 | - if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
| 692 | - $date_format = '%b %d'; |
|
| 693 | - else |
|
| 694 | - $date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]); |
|
| 713 | + if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
| 714 | + $date_format = '%b %d'; |
|
| 715 | + } else { |
|
| 716 | + $date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]); |
|
| 717 | + } |
|
| 695 | 718 | |
| 696 | 719 | foreach (array('birthdays', 'holidays') as $type) |
| 697 | 720 | { |
@@ -790,8 +813,9 @@ discard block |
||
| 790 | 813 | // Holidays between now and now + days. |
| 791 | 814 | for ($i = $now; $i < $now + $days_for_index; $i += 86400) |
| 792 | 815 | { |
| 793 | - if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) |
|
| 794 | - $return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]); |
|
| 816 | + if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) { |
|
| 817 | + $return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]); |
|
| 818 | + } |
|
| 795 | 819 | } |
| 796 | 820 | } |
| 797 | 821 | |
@@ -803,8 +827,9 @@ discard block |
||
| 803 | 827 | $loop_date = strftime('%Y-%m-%d', $i); |
| 804 | 828 | if (isset($cached_data['birthdays'][$loop_date])) |
| 805 | 829 | { |
| 806 | - foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) |
|
| 807 | - $cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date']; |
|
| 830 | + foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) { |
|
| 831 | + $cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date']; |
|
| 832 | + } |
|
| 808 | 833 | $return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]); |
| 809 | 834 | } |
| 810 | 835 | } |
@@ -819,8 +844,9 @@ discard block |
||
| 819 | 844 | $loop_date = strftime('%Y-%m-%d', $i); |
| 820 | 845 | |
| 821 | 846 | // No events today? Check the next day. |
| 822 | - if (empty($cached_data['events'][$loop_date])) |
|
| 823 | - continue; |
|
| 847 | + if (empty($cached_data['events'][$loop_date])) { |
|
| 848 | + continue; |
|
| 849 | + } |
|
| 824 | 850 | |
| 825 | 851 | // Loop through all events to add a few last-minute values. |
| 826 | 852 | foreach ($cached_data['events'][$loop_date] as $ev => $event) |
@@ -833,9 +859,9 @@ discard block |
||
| 833 | 859 | { |
| 834 | 860 | unset($cached_data['events'][$loop_date][$ev]); |
| 835 | 861 | continue; |
| 862 | + } else { |
|
| 863 | + $duplicates[$this_event['topic'] . $this_event['title']] = true; |
|
| 836 | 864 | } |
| 837 | - else |
|
| 838 | - $duplicates[$this_event['topic'] . $this_event['title']] = true; |
|
| 839 | 865 | |
| 840 | 866 | // Might be set to true afterwards, depending on the permissions. |
| 841 | 867 | $this_event['can_edit'] = false; |
@@ -843,16 +869,19 @@ discard block |
||
| 843 | 869 | $this_event['date'] = $loop_date; |
| 844 | 870 | } |
| 845 | 871 | |
| 846 | - if (!empty($cached_data['events'][$loop_date])) |
|
| 847 | - $return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]); |
|
| 872 | + if (!empty($cached_data['events'][$loop_date])) { |
|
| 873 | + $return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]); |
|
| 874 | + } |
|
| 848 | 875 | } |
| 849 | 876 | } |
| 850 | 877 | |
| 851 | 878 | // Mark the last item so that a list separator can be used in the template. |
| 852 | - for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) |
|
| 853 | - $return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]); |
|
| 854 | - for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) |
|
| 855 | - $return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]); |
|
| 879 | + for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) { |
|
| 880 | + $return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]); |
|
| 881 | + } |
|
| 882 | + for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) { |
|
| 883 | + $return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]); |
|
| 884 | + } |
|
| 856 | 885 | |
| 857 | 886 | return array( |
| 858 | 887 | 'data' => $return_data, |
@@ -900,37 +929,46 @@ discard block |
||
| 900 | 929 | if (isset($_POST['start_date'])) |
| 901 | 930 | { |
| 902 | 931 | $d = date_parse($_POST['start_date']); |
| 903 | - if (!empty($d['error_count']) || !empty($d['warning_count'])) |
|
| 904 | - fatal_lang_error('invalid_date', false); |
|
| 905 | - if (empty($d['year'])) |
|
| 906 | - fatal_lang_error('event_year_missing', false); |
|
| 907 | - if (empty($d['month'])) |
|
| 908 | - fatal_lang_error('event_month_missing', false); |
|
| 909 | - } |
|
| 910 | - elseif (isset($_POST['start_datetime'])) |
|
| 932 | + if (!empty($d['error_count']) || !empty($d['warning_count'])) { |
|
| 933 | + fatal_lang_error('invalid_date', false); |
|
| 934 | + } |
|
| 935 | + if (empty($d['year'])) { |
|
| 936 | + fatal_lang_error('event_year_missing', false); |
|
| 937 | + } |
|
| 938 | + if (empty($d['month'])) { |
|
| 939 | + fatal_lang_error('event_month_missing', false); |
|
| 940 | + } |
|
| 941 | + } elseif (isset($_POST['start_datetime'])) |
|
| 911 | 942 | { |
| 912 | 943 | $d = date_parse($_POST['start_datetime']); |
| 913 | - if (!empty($d['error_count']) || !empty($d['warning_count'])) |
|
| 914 | - fatal_lang_error('invalid_date', false); |
|
| 915 | - if (empty($d['year'])) |
|
| 916 | - fatal_lang_error('event_year_missing', false); |
|
| 917 | - if (empty($d['month'])) |
|
| 918 | - fatal_lang_error('event_month_missing', false); |
|
| 944 | + if (!empty($d['error_count']) || !empty($d['warning_count'])) { |
|
| 945 | + fatal_lang_error('invalid_date', false); |
|
| 946 | + } |
|
| 947 | + if (empty($d['year'])) { |
|
| 948 | + fatal_lang_error('event_year_missing', false); |
|
| 949 | + } |
|
| 950 | + if (empty($d['month'])) { |
|
| 951 | + fatal_lang_error('event_month_missing', false); |
|
| 952 | + } |
|
| 919 | 953 | } |
| 920 | 954 | // The 2.0 way |
| 921 | 955 | else |
| 922 | 956 | { |
| 923 | 957 | // No month? No year? |
| 924 | - if (!isset($_POST['month'])) |
|
| 925 | - fatal_lang_error('event_month_missing', false); |
|
| 926 | - if (!isset($_POST['year'])) |
|
| 927 | - fatal_lang_error('event_year_missing', false); |
|
| 958 | + if (!isset($_POST['month'])) { |
|
| 959 | + fatal_lang_error('event_month_missing', false); |
|
| 960 | + } |
|
| 961 | + if (!isset($_POST['year'])) { |
|
| 962 | + fatal_lang_error('event_year_missing', false); |
|
| 963 | + } |
|
| 928 | 964 | |
| 929 | 965 | // Check the month and year... |
| 930 | - if ($_POST['month'] < 1 || $_POST['month'] > 12) |
|
| 931 | - fatal_lang_error('invalid_month', false); |
|
| 932 | - if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) |
|
| 933 | - fatal_lang_error('invalid_year', false); |
|
| 966 | + if ($_POST['month'] < 1 || $_POST['month'] > 12) { |
|
| 967 | + fatal_lang_error('invalid_month', false); |
|
| 968 | + } |
|
| 969 | + if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) { |
|
| 970 | + fatal_lang_error('invalid_year', false); |
|
| 971 | + } |
|
| 934 | 972 | } |
| 935 | 973 | } |
| 936 | 974 | |
@@ -940,8 +978,9 @@ discard block |
||
| 940 | 978 | // If they want to us to calculate an end date, make sure it will fit in an acceptable range. |
| 941 | 979 | if (isset($_POST['span'])) |
| 942 | 980 | { |
| 943 | - if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) |
|
| 944 | - fatal_lang_error('invalid_days_numb', false); |
|
| 981 | + if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) { |
|
| 982 | + fatal_lang_error('invalid_days_numb', false); |
|
| 983 | + } |
|
| 945 | 984 | } |
| 946 | 985 | |
| 947 | 986 | // There is no need to validate the following values if we are just deleting the event. |
@@ -951,24 +990,29 @@ discard block |
||
| 951 | 990 | if (empty($_POST['start_date']) && empty($_POST['start_datetime'])) |
| 952 | 991 | { |
| 953 | 992 | // No day? |
| 954 | - if (!isset($_POST['day'])) |
|
| 955 | - fatal_lang_error('event_day_missing', false); |
|
| 993 | + if (!isset($_POST['day'])) { |
|
| 994 | + fatal_lang_error('event_day_missing', false); |
|
| 995 | + } |
|
| 956 | 996 | |
| 957 | 997 | // Bad day? |
| 958 | - if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) |
|
| 959 | - fatal_lang_error('invalid_date', false); |
|
| 998 | + if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) { |
|
| 999 | + fatal_lang_error('invalid_date', false); |
|
| 1000 | + } |
|
| 960 | 1001 | } |
| 961 | 1002 | |
| 962 | - if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) |
|
| 963 | - fatal_lang_error('event_title_missing', false); |
|
| 964 | - elseif (!isset($_POST['evtitle'])) |
|
| 965 | - $_POST['evtitle'] = $_POST['subject']; |
|
| 1003 | + if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) { |
|
| 1004 | + fatal_lang_error('event_title_missing', false); |
|
| 1005 | + } elseif (!isset($_POST['evtitle'])) { |
|
| 1006 | + $_POST['evtitle'] = $_POST['subject']; |
|
| 1007 | + } |
|
| 966 | 1008 | |
| 967 | 1009 | // No title? |
| 968 | - if ($smcFunc['htmltrim']($_POST['evtitle']) === '') |
|
| 969 | - fatal_lang_error('no_event_title', false); |
|
| 970 | - if ($smcFunc['strlen']($_POST['evtitle']) > 100) |
|
| 971 | - $_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100); |
|
| 1010 | + if ($smcFunc['htmltrim']($_POST['evtitle']) === '') { |
|
| 1011 | + fatal_lang_error('no_event_title', false); |
|
| 1012 | + } |
|
| 1013 | + if ($smcFunc['strlen']($_POST['evtitle']) > 100) { |
|
| 1014 | + $_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100); |
|
| 1015 | + } |
|
| 972 | 1016 | $_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']); |
| 973 | 1017 | } |
| 974 | 1018 | } |
@@ -995,8 +1039,9 @@ discard block |
||
| 995 | 1039 | ); |
| 996 | 1040 | |
| 997 | 1041 | // No results, return false. |
| 998 | - if ($smcFunc['db_num_rows'] === 0) |
|
| 999 | - return false; |
|
| 1042 | + if ($smcFunc['db_num_rows'] === 0) { |
|
| 1043 | + return false; |
|
| 1044 | + } |
|
| 1000 | 1045 | |
| 1001 | 1046 | // Grab the results and return. |
| 1002 | 1047 | list ($poster) = $smcFunc['db_fetch_row']($request); |
@@ -1130,8 +1175,9 @@ discard block |
||
| 1130 | 1175 | call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters)); |
| 1131 | 1176 | |
| 1132 | 1177 | $column_clauses = array(); |
| 1133 | - foreach ($event_columns as $col => $crit) |
|
| 1134 | - $column_clauses[] = $col . ' = ' . $crit; |
|
| 1178 | + foreach ($event_columns as $col => $crit) { |
|
| 1179 | + $column_clauses[] = $col . ' = ' . $crit; |
|
| 1180 | + } |
|
| 1135 | 1181 | |
| 1136 | 1182 | $smcFunc['db_query']('', ' |
| 1137 | 1183 | UPDATE {db_prefix}calendar |
@@ -1216,8 +1262,9 @@ discard block |
||
| 1216 | 1262 | ); |
| 1217 | 1263 | |
| 1218 | 1264 | // If nothing returned, we are in poo, poo. |
| 1219 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 1220 | - return false; |
|
| 1265 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 1266 | + return false; |
|
| 1267 | + } |
|
| 1221 | 1268 | |
| 1222 | 1269 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1223 | 1270 | $smcFunc['db_free_result']($request); |
@@ -1225,8 +1272,9 @@ discard block |
||
| 1225 | 1272 | list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row); |
| 1226 | 1273 | |
| 1227 | 1274 | // Sanity check |
| 1228 | - if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) |
|
| 1229 | - return false; |
|
| 1275 | + if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) { |
|
| 1276 | + return false; |
|
| 1277 | + } |
|
| 1230 | 1278 | |
| 1231 | 1279 | $return_value = array( |
| 1232 | 1280 | 'boards' => array(), |
@@ -1363,24 +1411,27 @@ discard block |
||
| 1363 | 1411 | |
| 1364 | 1412 | // Set $span, in case we need it |
| 1365 | 1413 | $span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0); |
| 1366 | - if ($span > 0) |
|
| 1367 | - $span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1; |
|
| 1414 | + if ($span > 0) { |
|
| 1415 | + $span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1; |
|
| 1416 | + } |
|
| 1368 | 1417 | |
| 1369 | 1418 | // Define the timezone for this event, falling back to the default if not provided |
| 1370 | - if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
| 1371 | - $tz = $eventOptions['tz']; |
|
| 1372 | - elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
| 1373 | - $tz = $_POST['tz']; |
|
| 1374 | - else |
|
| 1375 | - $tz = getUserTimezone(); |
|
| 1419 | + if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) { |
|
| 1420 | + $tz = $eventOptions['tz']; |
|
| 1421 | + } elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) { |
|
| 1422 | + $tz = $_POST['tz']; |
|
| 1423 | + } else { |
|
| 1424 | + $tz = getUserTimezone(); |
|
| 1425 | + } |
|
| 1376 | 1426 | |
| 1377 | 1427 | // Is this supposed to be an all day event, or should it have specific start and end times? |
| 1378 | - if (isset($eventOptions['allday'])) |
|
| 1379 | - $allday = $eventOptions['allday']; |
|
| 1380 | - elseif (empty($_POST['allday'])) |
|
| 1381 | - $allday = false; |
|
| 1382 | - else |
|
| 1383 | - $allday = true; |
|
| 1428 | + if (isset($eventOptions['allday'])) { |
|
| 1429 | + $allday = $eventOptions['allday']; |
|
| 1430 | + } elseif (empty($_POST['allday'])) { |
|
| 1431 | + $allday = false; |
|
| 1432 | + } else { |
|
| 1433 | + $allday = true; |
|
| 1434 | + } |
|
| 1384 | 1435 | |
| 1385 | 1436 | // Input might come as individual parameters... |
| 1386 | 1437 | $start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null); |
@@ -1407,10 +1458,12 @@ discard block |
||
| 1407 | 1458 | $end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null); |
| 1408 | 1459 | |
| 1409 | 1460 | // If the date and time were given in separate strings, combine them |
| 1410 | - if (empty($start_string) && isset($start_date_string)) |
|
| 1411 | - $start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : ''); |
|
| 1412 | - if (empty($end_string) && isset($end_date_string)) |
|
| 1413 | - $end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : ''); |
|
| 1461 | + if (empty($start_string) && isset($start_date_string)) { |
|
| 1462 | + $start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : ''); |
|
| 1463 | + } |
|
| 1464 | + if (empty($end_string) && isset($end_date_string)) { |
|
| 1465 | + $end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : ''); |
|
| 1466 | + } |
|
| 1414 | 1467 | |
| 1415 | 1468 | // If some form of string input was given, override individually defined options with it |
| 1416 | 1469 | if (isset($start_string)) |
@@ -1501,10 +1554,11 @@ discard block |
||
| 1501 | 1554 | if ($start_object >= $end_object) |
| 1502 | 1555 | { |
| 1503 | 1556 | $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz); |
| 1504 | - if ($span > 0) |
|
| 1505 | - date_add($end_object, date_interval_create_from_date_string($span . ' days')); |
|
| 1506 | - else |
|
| 1507 | - date_add($end_object, date_interval_create_from_date_string('1 hour')); |
|
| 1557 | + if ($span > 0) { |
|
| 1558 | + date_add($end_object, date_interval_create_from_date_string($span . ' days')); |
|
| 1559 | + } else { |
|
| 1560 | + date_add($end_object, date_interval_create_from_date_string('1 hour')); |
|
| 1561 | + } |
|
| 1508 | 1562 | } |
| 1509 | 1563 | |
| 1510 | 1564 | // Is $end_object too late? |
@@ -1517,9 +1571,9 @@ discard block |
||
| 1517 | 1571 | { |
| 1518 | 1572 | $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz); |
| 1519 | 1573 | date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days')); |
| 1574 | + } else { |
|
| 1575 | + $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz); |
|
| 1520 | 1576 | } |
| 1521 | - else |
|
| 1522 | - $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz); |
|
| 1523 | 1577 | } |
| 1524 | 1578 | } |
| 1525 | 1579 | |
@@ -1532,8 +1586,7 @@ discard block |
||
| 1532 | 1586 | $start_time = null; |
| 1533 | 1587 | $end_time = null; |
| 1534 | 1588 | $tz = null; |
| 1535 | - } |
|
| 1536 | - else |
|
| 1589 | + } else |
|
| 1537 | 1590 | { |
| 1538 | 1591 | $start_time = date_format($start_object, 'H:i:s'); |
| 1539 | 1592 | $end_time = date_format($end_object, 'H:i:s'); |
@@ -1559,19 +1612,21 @@ discard block |
||
| 1559 | 1612 | // First, try to create a better date format, ignoring the "time" elements. |
| 1560 | 1613 | if (empty($date_format)) |
| 1561 | 1614 | { |
| 1562 | - if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
| 1563 | - $date_format = '%F'; |
|
| 1564 | - else |
|
| 1565 | - $date_format = $matches[0]; |
|
| 1615 | + if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
| 1616 | + $date_format = '%F'; |
|
| 1617 | + } else { |
|
| 1618 | + $date_format = $matches[0]; |
|
| 1619 | + } |
|
| 1566 | 1620 | } |
| 1567 | 1621 | |
| 1568 | 1622 | // We want a fairly compact version of the time, but as close as possible to the user's settings. |
| 1569 | 1623 | if (empty($time_format)) |
| 1570 | 1624 | { |
| 1571 | - if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
| 1572 | - $time_format = '%k:%M'; |
|
| 1573 | - else |
|
| 1574 | - $time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
| 1625 | + if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
| 1626 | + $time_format = '%k:%M'; |
|
| 1627 | + } else { |
|
| 1628 | + $time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
| 1629 | + } |
|
| 1575 | 1630 | } |
| 1576 | 1631 | |
| 1577 | 1632 | // Should this be an all day event? |
@@ -1581,11 +1636,13 @@ discard block |
||
| 1581 | 1636 | $span = 1 + date_interval_format(date_diff(date_create($row['start_date']), date_create($row['end_date'])), '%d'); |
| 1582 | 1637 | |
| 1583 | 1638 | // We need to have a defined timezone in the steps below |
| 1584 | - if (empty($row['timezone'])) |
|
| 1585 | - $row['timezone'] = getUserTimezone(); |
|
| 1639 | + if (empty($row['timezone'])) { |
|
| 1640 | + $row['timezone'] = getUserTimezone(); |
|
| 1641 | + } |
|
| 1586 | 1642 | |
| 1587 | - if (empty($timezone_array[$row['timezone']])) |
|
| 1588 | - $timezone_array[$row['timezone']] = timezone_open($row['timezone']); |
|
| 1643 | + if (empty($timezone_array[$row['timezone']])) { |
|
| 1644 | + $timezone_array[$row['timezone']] = timezone_open($row['timezone']); |
|
| 1645 | + } |
|
| 1589 | 1646 | |
| 1590 | 1647 | // Get most of the standard date information for the start and end datetimes |
| 1591 | 1648 | $start = date_parse($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : '')); |
@@ -1633,8 +1690,9 @@ discard block |
||
| 1633 | 1690 | global $smcFunc, $context, $user_info, $modSettings, $user_settings; |
| 1634 | 1691 | static $member_cache = array(); |
| 1635 | 1692 | |
| 1636 | - if (is_null($id_member) && $user_info['is_guest'] == false) |
|
| 1637 | - $id_member = $context['user']['id']; |
|
| 1693 | + if (is_null($id_member) && $user_info['is_guest'] == false) { |
|
| 1694 | + $id_member = $context['user']['id']; |
|
| 1695 | + } |
|
| 1638 | 1696 | |
| 1639 | 1697 | //check if the cache got the data |
| 1640 | 1698 | if (isset($id_member) && isset($member_cache[$id_member])) |
@@ -1663,11 +1721,13 @@ discard block |
||
| 1663 | 1721 | $smcFunc['db_free_result']($request); |
| 1664 | 1722 | } |
| 1665 | 1723 | |
| 1666 | - if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
| 1667 | - $timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get(); |
|
| 1724 | + if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) { |
|
| 1725 | + $timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get(); |
|
| 1726 | + } |
|
| 1668 | 1727 | |
| 1669 | - if (isset($id_member)) |
|
| 1670 | - $member_cache[$id_member] = $timezone; |
|
| 1728 | + if (isset($id_member)) { |
|
| 1729 | + $member_cache[$id_member] = $timezone; |
|
| 1730 | + } |
|
| 1671 | 1731 | |
| 1672 | 1732 | return $timezone; |
| 1673 | 1733 | } |
@@ -1696,8 +1756,9 @@ discard block |
||
| 1696 | 1756 | ) |
| 1697 | 1757 | ); |
| 1698 | 1758 | $holidays = array(); |
| 1699 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1700 | - $holidays[] = $row; |
|
| 1759 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1760 | + $holidays[] = $row; |
|
| 1761 | + } |
|
| 1701 | 1762 | $smcFunc['db_free_result']($request); |
| 1702 | 1763 | |
| 1703 | 1764 | return $holidays; |
@@ -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('Hacking attempt...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Interface cache_api_interface |
@@ -182,8 +183,9 @@ discard block |
||
| 182 | 183 | { |
| 183 | 184 | global $cache_enable; |
| 184 | 185 | |
| 185 | - if ($test) |
|
| 186 | - return true; |
|
| 186 | + if ($test) { |
|
| 187 | + return true; |
|
| 188 | + } |
|
| 187 | 189 | return !empty($cache_enable); |
| 188 | 190 | } |
| 189 | 191 | |
@@ -202,18 +204,20 @@ discard block |
||
| 202 | 204 | global $boardurl, $cachedir; |
| 203 | 205 | |
| 204 | 206 | // Find a valid good file to do mtime checks on. |
| 205 | - if (file_exists($cachedir . '/' . 'index.php')) |
|
| 206 | - $filemtime = $cachedir . '/' . 'index.php'; |
|
| 207 | - elseif (is_dir($cachedir . '/')) |
|
| 208 | - $filemtime = $cachedir . '/'; |
|
| 209 | - else |
|
| 210 | - $filemtime = $boardurl . '/index.php'; |
|
| 207 | + if (file_exists($cachedir . '/' . 'index.php')) { |
|
| 208 | + $filemtime = $cachedir . '/' . 'index.php'; |
|
| 209 | + } elseif (is_dir($cachedir . '/')) { |
|
| 210 | + $filemtime = $cachedir . '/'; |
|
| 211 | + } else { |
|
| 212 | + $filemtime = $boardurl . '/index.php'; |
|
| 213 | + } |
|
| 211 | 214 | |
| 212 | 215 | // Set the default if no prefix was specified. |
| 213 | - if (empty($prefix)) |
|
| 214 | - $this->prefix = md5($boardurl . filemtime($filemtime)) . '-SMF-'; |
|
| 215 | - else |
|
| 216 | - $this->prefix = $prefix; |
|
| 216 | + if (empty($prefix)) { |
|
| 217 | + $this->prefix = md5($boardurl . filemtime($filemtime)) . '-SMF-'; |
|
| 218 | + } else { |
|
| 219 | + $this->prefix = $prefix; |
|
| 220 | + } |
|
| 217 | 221 | |
| 218 | 222 | return true; |
| 219 | 223 | } |
@@ -276,8 +280,9 @@ discard block |
||
| 276 | 280 | |
| 277 | 281 | // Invalidate cache, to be sure! |
| 278 | 282 | // ... as long as index.php can be modified, anyway. |
| 279 | - if (is_writable($cachedir . '/' . 'index.php')) |
|
| 280 | - @touch($cachedir . '/' . 'index.php'); |
|
| 283 | + if (is_writable($cachedir . '/' . 'index.php')) { |
|
| 284 | + @touch($cachedir . '/' . 'index.php'); |
|
| 285 | + } |
|
| 281 | 286 | |
| 282 | 287 | return true; |
| 283 | 288 | } |
@@ -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 | * Retrieve a list and several other statistics of the users currently online. |
@@ -45,8 +46,9 @@ discard block |
||
| 45 | 46 | } |
| 46 | 47 | |
| 47 | 48 | // Not allowed sort method? Bang! Error! |
| 48 | - elseif (!in_array($membersOnlineOptions['sort'], $allowed_sort_options)) |
|
| 49 | - trigger_error('Sort method for getMembersOnlineStats() function is not allowed', E_USER_NOTICE); |
|
| 49 | + elseif (!in_array($membersOnlineOptions['sort'], $allowed_sort_options)) { |
|
| 50 | + trigger_error('Sort method for getMembersOnlineStats() function is not allowed', E_USER_NOTICE); |
|
| 51 | + } |
|
| 50 | 52 | |
| 51 | 53 | // Initialize the array that'll be returned later on. |
| 52 | 54 | $membersOnlineStats = array( |
@@ -63,8 +65,9 @@ discard block |
||
| 63 | 65 | // Get any spiders if enabled. |
| 64 | 66 | $spiders = array(); |
| 65 | 67 | $spider_finds = array(); |
| 66 | - if (!empty($modSettings['show_spider_online']) && ($modSettings['show_spider_online'] < 3 || allowedTo('admin_forum')) && !empty($modSettings['spider_name_cache'])) |
|
| 67 | - $spiders = $smcFunc['json_decode']($modSettings['spider_name_cache'], true); |
|
| 68 | + if (!empty($modSettings['show_spider_online']) && ($modSettings['show_spider_online'] < 3 || allowedTo('admin_forum')) && !empty($modSettings['spider_name_cache'])) { |
|
| 69 | + $spiders = $smcFunc['json_decode']($modSettings['spider_name_cache'], true); |
|
| 70 | + } |
|
| 68 | 71 | |
| 69 | 72 | // Load the users online right now. |
| 70 | 73 | $request = $smcFunc['db_query']('', ' |
@@ -92,9 +95,7 @@ discard block |
||
| 92 | 95 | $membersOnlineStats['num_guests']++; |
| 93 | 96 | |
| 94 | 97 | continue; |
| 95 | - } |
|
| 96 | - |
|
| 97 | - elseif (empty($row['show_online']) && empty($membersOnlineOptions['show_hidden'])) |
|
| 98 | + } elseif (empty($row['show_online']) && empty($membersOnlineOptions['show_hidden'])) |
|
| 98 | 99 | { |
| 99 | 100 | // Just increase the stats and don't add this hidden user to any list. |
| 100 | 101 | $membersOnlineStats['num_users_hidden']++; |
@@ -102,10 +103,11 @@ discard block |
||
| 102 | 103 | } |
| 103 | 104 | |
| 104 | 105 | // Some basic color coding... |
| 105 | - if (!empty($row['online_color'])) |
|
| 106 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
| 107 | - else |
|
| 108 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 106 | + if (!empty($row['online_color'])) { |
|
| 107 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
| 108 | + } else { |
|
| 109 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 110 | + } |
|
| 109 | 111 | |
| 110 | 112 | // Buddies get counted and highlighted. |
| 111 | 113 | $is_buddy = in_array($row['id_member'], $user_info['buddies']); |
@@ -132,8 +134,8 @@ discard block |
||
| 132 | 134 | $membersOnlineStats['list_users_online'][$row[$membersOnlineOptions['sort']] . '_' . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
| 133 | 135 | |
| 134 | 136 | // Store all distinct (primary) membergroups that are shown. |
| 135 | - if (!isset($membersOnlineStats['online_groups'][$row['id_group']])) |
|
| 136 | - $membersOnlineStats['online_groups'][$row['id_group']] = array( |
|
| 137 | + if (!isset($membersOnlineStats['online_groups'][$row['id_group']])) { |
|
| 138 | + $membersOnlineStats['online_groups'][$row['id_group']] = array( |
|
| 137 | 139 | 'id' => $row['id_group'], |
| 138 | 140 | 'name' => $row['group_name'], |
| 139 | 141 | 'color' => $row['online_color'], |
@@ -141,6 +143,7 @@ discard block |
||
| 141 | 143 | 'type' => $row['group_type'], |
| 142 | 144 | 'parent' => $row['id_parent'], |
| 143 | 145 | ); |
| 146 | + } |
|
| 144 | 147 | } |
| 145 | 148 | $smcFunc['db_free_result']($request); |
| 146 | 149 | |
@@ -201,11 +204,12 @@ discard block |
||
| 201 | 204 | $settingsToUpdate = array(); |
| 202 | 205 | |
| 203 | 206 | // More members on now than ever were? Update it! |
| 204 | - if (!isset($modSettings['mostOnline']) || $total_users_online >= $modSettings['mostOnline']) |
|
| 205 | - $settingsToUpdate = array( |
|
| 207 | + if (!isset($modSettings['mostOnline']) || $total_users_online >= $modSettings['mostOnline']) { |
|
| 208 | + $settingsToUpdate = array( |
|
| 206 | 209 | 'mostOnline' => $total_users_online, |
| 207 | 210 | 'mostDate' => time() |
| 208 | 211 | ); |
| 212 | + } |
|
| 209 | 213 | |
| 210 | 214 | $date = strftime('%Y-%m-%d', forum_time(false)); |
| 211 | 215 | |
@@ -237,8 +241,9 @@ discard block |
||
| 237 | 241 | { |
| 238 | 242 | list ($modSettings['mostOnlineToday']) = $smcFunc['db_fetch_row']($request); |
| 239 | 243 | |
| 240 | - if ($total_users_online > $modSettings['mostOnlineToday']) |
|
| 241 | - trackStats(array('most_on' => $total_users_online)); |
|
| 244 | + if ($total_users_online > $modSettings['mostOnlineToday']) { |
|
| 245 | + trackStats(array('most_on' => $total_users_online)); |
|
| 246 | + } |
|
| 242 | 247 | |
| 243 | 248 | $total_users_online = max($total_users_online, $modSettings['mostOnlineToday']); |
| 244 | 249 | } |
@@ -255,8 +260,9 @@ discard block |
||
| 255 | 260 | $settingsToUpdate['mostOnlineToday'] = $total_users_online; |
| 256 | 261 | } |
| 257 | 262 | |
| 258 | - if (!empty($settingsToUpdate)) |
|
| 259 | - updateSettings($settingsToUpdate); |
|
| 260 | -} |
|
| 263 | + if (!empty($settingsToUpdate)) { |
|
| 264 | + updateSettings($settingsToUpdate); |
|
| 265 | + } |
|
| 266 | + } |
|
| 261 | 267 | |
| 262 | 268 | ?> |
| 263 | 269 | \ No newline at end of file |