@@ -101,9 +101,9 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | - * Determine if the browser is Opera or not |
|
| 105 | - * @return boolean Whether or not this is Opera |
|
| 106 | - */ |
|
| 104 | + * Determine if the browser is Opera or not |
|
| 105 | + * @return boolean Whether or not this is Opera |
|
| 106 | + */ |
|
| 107 | 107 | function isOpera() |
| 108 | 108 | { |
| 109 | 109 | if (!isset($this->_browsers['is_opera'])) |
@@ -112,9 +112,9 @@ discard block |
||
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
| 115 | - * Determine if the browser is IE or not |
|
| 116 | - * @return boolean true Whether or not the browser is IE |
|
| 117 | - */ |
|
| 115 | + * Determine if the browser is IE or not |
|
| 116 | + * @return boolean true Whether or not the browser is IE |
|
| 117 | + */ |
|
| 118 | 118 | function isIe() |
| 119 | 119 | { |
| 120 | 120 | // I'm IE, Yes I'm the real IE; All you other IEs are just imitating. |
@@ -124,9 +124,9 @@ discard block |
||
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
| 127 | - * Determine if the browser is IE11 or not |
|
| 128 | - * @return boolean Whether or not the browser is IE11 |
|
| 129 | - */ |
|
| 127 | + * Determine if the browser is IE11 or not |
|
| 128 | + * @return boolean Whether or not the browser is IE11 |
|
| 129 | + */ |
|
| 130 | 130 | function isIe11() |
| 131 | 131 | { |
| 132 | 132 | // IE11 is a bit different than earlier versions |
@@ -137,9 +137,9 @@ discard block |
||
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
| 140 | - * Determine if the browser is Edge or not |
|
| 141 | - * @return boolean Whether or not the browser is Edge |
|
| 142 | - */ |
|
| 140 | + * Determine if the browser is Edge or not |
|
| 141 | + * @return boolean Whether or not the browser is Edge |
|
| 142 | + */ |
|
| 143 | 143 | function isEdge() |
| 144 | 144 | { |
| 145 | 145 | if (!isset($this->_browsers['is_edge'])) |
@@ -148,9 +148,9 @@ discard block |
||
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | - * Determine if the browser is a Webkit based one or not |
|
| 152 | - * @return boolean Whether or not this is a Webkit-based browser |
|
| 153 | - */ |
|
| 151 | + * Determine if the browser is a Webkit based one or not |
|
| 152 | + * @return boolean Whether or not this is a Webkit-based browser |
|
| 153 | + */ |
|
| 154 | 154 | function isWebkit() |
| 155 | 155 | { |
| 156 | 156 | if (!isset($this->_browsers['is_webkit'])) |
@@ -159,9 +159,9 @@ discard block |
||
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
| 162 | - * Determine if the browser is Firefox or one of its variants |
|
| 163 | - * @return boolean Whether or not this is Firefox (or one of its variants) |
|
| 164 | - */ |
|
| 162 | + * Determine if the browser is Firefox or one of its variants |
|
| 163 | + * @return boolean Whether or not this is Firefox (or one of its variants) |
|
| 164 | + */ |
|
| 165 | 165 | function isFirefox() |
| 166 | 166 | { |
| 167 | 167 | if (!isset($this->_browsers['is_firefox'])) |
@@ -170,9 +170,9 @@ discard block |
||
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
| 173 | - * Determine if the browser is WebTv or not |
|
| 174 | - * @return boolean Whether or not this is WebTV |
|
| 175 | - */ |
|
| 173 | + * Determine if the browser is WebTv or not |
|
| 174 | + * @return boolean Whether or not this is WebTV |
|
| 175 | + */ |
|
| 176 | 176 | function isWebTv() |
| 177 | 177 | { |
| 178 | 178 | if (!isset($this->_browsers['is_web_tv'])) |
@@ -181,9 +181,9 @@ discard block |
||
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
| 184 | - * Determine if the browser is konqueror or not |
|
| 185 | - * @return boolean Whether or not this is Konqueror |
|
| 186 | - */ |
|
| 184 | + * Determine if the browser is konqueror or not |
|
| 185 | + * @return boolean Whether or not this is Konqueror |
|
| 186 | + */ |
|
| 187 | 187 | function isKonqueror() |
| 188 | 188 | { |
| 189 | 189 | if (!isset($this->_browsers['is_konqueror'])) |
@@ -192,9 +192,9 @@ discard block |
||
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
| 195 | - * Determine if the browser is Gecko or not |
|
| 196 | - * @return boolean Whether or not this is a Gecko-based browser |
|
| 197 | - */ |
|
| 195 | + * Determine if the browser is Gecko or not |
|
| 196 | + * @return boolean Whether or not this is a Gecko-based browser |
|
| 197 | + */ |
|
| 198 | 198 | function isGecko() |
| 199 | 199 | { |
| 200 | 200 | if (!isset($this->_browsers['is_gecko'])) |
@@ -203,9 +203,9 @@ discard block |
||
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
| 206 | - * Determine if the browser is Opera Mini or not |
|
| 207 | - * @return boolean Whether or not this is Opera Mini |
|
| 208 | - */ |
|
| 206 | + * Determine if the browser is Opera Mini or not |
|
| 207 | + * @return boolean Whether or not this is Opera Mini |
|
| 208 | + */ |
|
| 209 | 209 | function isOperaMini() |
| 210 | 210 | { |
| 211 | 211 | if (!isset($this->_browsers['is_opera_mini'])) |
@@ -216,9 +216,9 @@ discard block |
||
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
| 219 | - * Determine if the browser is Opera Mobile or not |
|
| 220 | - * @return boolean Whether or not this is Opera Mobile |
|
| 221 | - */ |
|
| 219 | + * Determine if the browser is Opera Mobile or not |
|
| 220 | + * @return boolean Whether or not this is Opera Mobile |
|
| 221 | + */ |
|
| 222 | 222 | function isOperaMobi() |
| 223 | 223 | { |
| 224 | 224 | if (!isset($this->_browsers['is_opera_mobi'])) |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 3 |
| 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 browser_detector |
@@ -55,20 +56,25 @@ discard block |
||
| 55 | 56 | $this->_browsers['needs_size_fix'] = false; |
| 56 | 57 | |
| 57 | 58 | // One at a time, one at a time, and in this order too |
| 58 | - if ($this->isOpera()) |
|
| 59 | - $this->setupOpera(); |
|
| 59 | + if ($this->isOpera()) { |
|
| 60 | + $this->setupOpera(); |
|
| 61 | + } |
|
| 60 | 62 | // Meh... |
| 61 | - elseif ($this->isEdge()) |
|
| 62 | - $this->setupEdge(); |
|
| 63 | + elseif ($this->isEdge()) { |
|
| 64 | + $this->setupEdge(); |
|
| 65 | + } |
|
| 63 | 66 | // Them webkits need to be set up too |
| 64 | - elseif ($this->isWebkit()) |
|
| 65 | - $this->setupWebkit(); |
|
| 67 | + elseif ($this->isWebkit()) { |
|
| 68 | + $this->setupWebkit(); |
|
| 69 | + } |
|
| 66 | 70 | // We may have work to do on Firefox... |
| 67 | - elseif ($this->isFirefox()) |
|
| 68 | - $this->setupFirefox(); |
|
| 71 | + elseif ($this->isFirefox()) { |
|
| 72 | + $this->setupFirefox(); |
|
| 73 | + } |
|
| 69 | 74 | // Old friend, old frenemy |
| 70 | - elseif ($this->isIe()) |
|
| 71 | - $this->setupIe(); |
|
| 75 | + elseif ($this->isIe()) { |
|
| 76 | + $this->setupIe(); |
|
| 77 | + } |
|
| 72 | 78 | |
| 73 | 79 | // Just a few mobile checks |
| 74 | 80 | $this->isOperaMini(); |
@@ -84,11 +90,12 @@ discard block |
||
| 84 | 90 | $this->_browsers['possibly_robot'] = !empty($user_info['possibly_robot']); |
| 85 | 91 | |
| 86 | 92 | // Robots shouldn't be logging in or registering. So, they aren't a bot. Better to be wrong than sorry (or people won't be able to log in!), anyway. |
| 87 | - if ((isset($_REQUEST['action']) && in_array($_REQUEST['action'], array('login', 'login2', 'register', 'signup'))) || !$user_info['is_guest']) |
|
| 88 | - $this->_browsers['possibly_robot'] = false; |
|
| 93 | + if ((isset($_REQUEST['action']) && in_array($_REQUEST['action'], array('login', 'login2', 'register', 'signup'))) || !$user_info['is_guest']) { |
|
| 94 | + $this->_browsers['possibly_robot'] = false; |
|
| 95 | + } |
|
| 96 | + } else { |
|
| 97 | + $this->_browsers['possibly_robot'] = false; |
|
| 89 | 98 | } |
| 90 | - else |
|
| 91 | - $this->_browsers['possibly_robot'] = false; |
|
| 92 | 99 | |
| 93 | 100 | // Fill out the historical array as needed to support old mods that don't use isBrowser |
| 94 | 101 | $this->fillInformation(); |
@@ -106,8 +113,9 @@ discard block |
||
| 106 | 113 | */ |
| 107 | 114 | function isOpera() |
| 108 | 115 | { |
| 109 | - if (!isset($this->_browsers['is_opera'])) |
|
| 110 | - $this->_browsers['is_opera'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false; |
|
| 116 | + if (!isset($this->_browsers['is_opera'])) { |
|
| 117 | + $this->_browsers['is_opera'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false; |
|
| 118 | + } |
|
| 111 | 119 | return $this->_browsers['is_opera']; |
| 112 | 120 | } |
| 113 | 121 | |
@@ -118,8 +126,9 @@ discard block |
||
| 118 | 126 | function isIe() |
| 119 | 127 | { |
| 120 | 128 | // I'm IE, Yes I'm the real IE; All you other IEs are just imitating. |
| 121 | - if (!isset($this->_browsers['is_ie'])) |
|
| 122 | - $this->_browsers['is_ie'] = !$this->isOpera() && !$this->isGecko() && !$this->isWebTv() && preg_match('~MSIE \d+~', $_SERVER['HTTP_USER_AGENT']) === 1; |
|
| 129 | + if (!isset($this->_browsers['is_ie'])) { |
|
| 130 | + $this->_browsers['is_ie'] = !$this->isOpera() && !$this->isGecko() && !$this->isWebTv() && preg_match('~MSIE \d+~', $_SERVER['HTTP_USER_AGENT']) === 1; |
|
| 131 | + } |
|
| 123 | 132 | return $this->_browsers['is_ie']; |
| 124 | 133 | } |
| 125 | 134 | |
@@ -131,8 +140,9 @@ discard block |
||
| 131 | 140 | { |
| 132 | 141 | // IE11 is a bit different than earlier versions |
| 133 | 142 | // The isGecko() part is to ensure we get this right... |
| 134 | - if (!isset($this->_browsers['is_ie11'])) |
|
| 135 | - $this->_browsers['is_ie11'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== false && $this->isGecko(); |
|
| 143 | + if (!isset($this->_browsers['is_ie11'])) { |
|
| 144 | + $this->_browsers['is_ie11'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== false && $this->isGecko(); |
|
| 145 | + } |
|
| 136 | 146 | return $this->_browsers['is_ie11']; |
| 137 | 147 | } |
| 138 | 148 | |
@@ -142,8 +152,9 @@ discard block |
||
| 142 | 152 | */ |
| 143 | 153 | function isEdge() |
| 144 | 154 | { |
| 145 | - if (!isset($this->_browsers['is_edge'])) |
|
| 146 | - $this->_browsers['is_edge'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Edge') !== false; |
|
| 155 | + if (!isset($this->_browsers['is_edge'])) { |
|
| 156 | + $this->_browsers['is_edge'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Edge') !== false; |
|
| 157 | + } |
|
| 147 | 158 | return $this->_browsers['is_edge']; |
| 148 | 159 | } |
| 149 | 160 | |
@@ -153,8 +164,9 @@ discard block |
||
| 153 | 164 | */ |
| 154 | 165 | function isWebkit() |
| 155 | 166 | { |
| 156 | - if (!isset($this->_browsers['is_webkit'])) |
|
| 157 | - $this->_browsers['is_webkit'] = strpos($_SERVER['HTTP_USER_AGENT'], 'AppleWebKit') !== false; |
|
| 167 | + if (!isset($this->_browsers['is_webkit'])) { |
|
| 168 | + $this->_browsers['is_webkit'] = strpos($_SERVER['HTTP_USER_AGENT'], 'AppleWebKit') !== false; |
|
| 169 | + } |
|
| 158 | 170 | return $this->_browsers['is_webkit']; |
| 159 | 171 | } |
| 160 | 172 | |
@@ -164,8 +176,9 @@ discard block |
||
| 164 | 176 | */ |
| 165 | 177 | function isFirefox() |
| 166 | 178 | { |
| 167 | - if (!isset($this->_browsers['is_firefox'])) |
|
| 168 | - $this->_browsers['is_firefox'] = preg_match('~(?:Firefox|Ice[wW]easel|IceCat|Shiretoko|Minefield)/~', $_SERVER['HTTP_USER_AGENT']) === 1 && $this->isGecko(); |
|
| 179 | + if (!isset($this->_browsers['is_firefox'])) { |
|
| 180 | + $this->_browsers['is_firefox'] = preg_match('~(?:Firefox|Ice[wW]easel|IceCat|Shiretoko|Minefield)/~', $_SERVER['HTTP_USER_AGENT']) === 1 && $this->isGecko(); |
|
| 181 | + } |
|
| 169 | 182 | return $this->_browsers['is_firefox']; |
| 170 | 183 | } |
| 171 | 184 | |
@@ -175,8 +188,9 @@ discard block |
||
| 175 | 188 | */ |
| 176 | 189 | function isWebTv() |
| 177 | 190 | { |
| 178 | - if (!isset($this->_browsers['is_web_tv'])) |
|
| 179 | - $this->_browsers['is_web_tv'] = strpos($_SERVER['HTTP_USER_AGENT'], 'WebTV') !== false; |
|
| 191 | + if (!isset($this->_browsers['is_web_tv'])) { |
|
| 192 | + $this->_browsers['is_web_tv'] = strpos($_SERVER['HTTP_USER_AGENT'], 'WebTV') !== false; |
|
| 193 | + } |
|
| 180 | 194 | return $this->_browsers['is_web_tv']; |
| 181 | 195 | } |
| 182 | 196 | |
@@ -186,8 +200,9 @@ discard block |
||
| 186 | 200 | */ |
| 187 | 201 | function isKonqueror() |
| 188 | 202 | { |
| 189 | - if (!isset($this->_browsers['is_konqueror'])) |
|
| 190 | - $this->_browsers['is_konqueror'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Konqueror') !== false; |
|
| 203 | + if (!isset($this->_browsers['is_konqueror'])) { |
|
| 204 | + $this->_browsers['is_konqueror'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Konqueror') !== false; |
|
| 205 | + } |
|
| 191 | 206 | return $this->_browsers['is_konqueror']; |
| 192 | 207 | } |
| 193 | 208 | |
@@ -197,8 +212,9 @@ discard block |
||
| 197 | 212 | */ |
| 198 | 213 | function isGecko() |
| 199 | 214 | { |
| 200 | - if (!isset($this->_browsers['is_gecko'])) |
|
| 201 | - $this->_browsers['is_gecko'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false && !$this->isWebkit() && !$this->isKonqueror(); |
|
| 215 | + if (!isset($this->_browsers['is_gecko'])) { |
|
| 216 | + $this->_browsers['is_gecko'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false && !$this->isWebkit() && !$this->isKonqueror(); |
|
| 217 | + } |
|
| 202 | 218 | return $this->_browsers['is_gecko']; |
| 203 | 219 | } |
| 204 | 220 | |
@@ -208,10 +224,12 @@ discard block |
||
| 208 | 224 | */ |
| 209 | 225 | function isOperaMini() |
| 210 | 226 | { |
| 211 | - if (!isset($this->_browsers['is_opera_mini'])) |
|
| 212 | - $this->_browsers['is_opera_mini'] = (isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']) || stripos($_SERVER['HTTP_USER_AGENT'], 'opera mini') !== false); |
|
| 213 | - if ($this->_browsers['is_opera_mini']) |
|
| 214 | - $this->_is_mobile = true; |
|
| 227 | + if (!isset($this->_browsers['is_opera_mini'])) { |
|
| 228 | + $this->_browsers['is_opera_mini'] = (isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']) || stripos($_SERVER['HTTP_USER_AGENT'], 'opera mini') !== false); |
|
| 229 | + } |
|
| 230 | + if ($this->_browsers['is_opera_mini']) { |
|
| 231 | + $this->_is_mobile = true; |
|
| 232 | + } |
|
| 215 | 233 | return $this->_browsers['is_opera_mini']; |
| 216 | 234 | } |
| 217 | 235 | |
@@ -221,10 +239,12 @@ discard block |
||
| 221 | 239 | */ |
| 222 | 240 | function isOperaMobi() |
| 223 | 241 | { |
| 224 | - if (!isset($this->_browsers['is_opera_mobi'])) |
|
| 225 | - $this->_browsers['is_opera_mobi'] = stripos($_SERVER['HTTP_USER_AGENT'], 'opera mobi') !== false; |
|
| 226 | - if ($this->_browsers['is_opera_mobi']) |
|
| 227 | - $this->_is_mobile = true; |
|
| 242 | + if (!isset($this->_browsers['is_opera_mobi'])) { |
|
| 243 | + $this->_browsers['is_opera_mobi'] = stripos($_SERVER['HTTP_USER_AGENT'], 'opera mobi') !== false; |
|
| 244 | + } |
|
| 245 | + if ($this->_browsers['is_opera_mobi']) { |
|
| 246 | + $this->_is_mobile = true; |
|
| 247 | + } |
|
| 228 | 248 | return $this->_browsers['is_opera_mini']; |
| 229 | 249 | } |
| 230 | 250 | |
@@ -244,8 +264,9 @@ discard block |
||
| 244 | 264 | ); |
| 245 | 265 | |
| 246 | 266 | // blackberry, playbook, iphone, nokia, android and ipods set a mobile flag |
| 247 | - if ($this->_browsers['is_iphone'] || $this->_browsers['is_blackberry'] || $this->_browsers['is_android'] || $this->_browsers['is_nokia']) |
|
| 248 | - $this->_is_mobile = true; |
|
| 267 | + if ($this->_browsers['is_iphone'] || $this->_browsers['is_blackberry'] || $this->_browsers['is_android'] || $this->_browsers['is_nokia']) { |
|
| 268 | + $this->_is_mobile = true; |
|
| 269 | + } |
|
| 249 | 270 | |
| 250 | 271 | // @todo what to do with the blaPad? ... for now leave it detected as Safari ... |
| 251 | 272 | $this->_browsers['is_safari'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== false && !$this->_browsers['is_chrome'] && !$this->_browsers['is_iphone']; |
@@ -254,15 +275,17 @@ discard block |
||
| 254 | 275 | // if Chrome, get the major version |
| 255 | 276 | if ($this->_browsers['is_chrome']) |
| 256 | 277 | { |
| 257 | - if (preg_match('~chrome[/]([0-9][0-9]?[.])~i', $_SERVER['HTTP_USER_AGENT'], $match) === 1) |
|
| 258 | - $this->_browsers['is_chrome' . (int) $match[1]] = true; |
|
| 278 | + if (preg_match('~chrome[/]([0-9][0-9]?[.])~i', $_SERVER['HTTP_USER_AGENT'], $match) === 1) { |
|
| 279 | + $this->_browsers['is_chrome' . (int) $match[1]] = true; |
|
| 280 | + } |
|
| 259 | 281 | } |
| 260 | 282 | |
| 261 | 283 | // or if Safari get its major version |
| 262 | 284 | if ($this->_browsers['is_safari']) |
| 263 | 285 | { |
| 264 | - if (preg_match('~version/?(.*)safari.*~i', $_SERVER['HTTP_USER_AGENT'], $match) === 1) |
|
| 265 | - $this->_browsers['is_safari' . (int) trim($match[1])] = true; |
|
| 286 | + if (preg_match('~version/?(.*)safari.*~i', $_SERVER['HTTP_USER_AGENT'], $match) === 1) { |
|
| 287 | + $this->_browsers['is_safari' . (int) trim($match[1])] = true; |
|
| 288 | + } |
|
| 266 | 289 | } |
| 267 | 290 | } |
| 268 | 291 | |
@@ -291,8 +314,9 @@ discard block |
||
| 291 | 314 | $this->_browsers['is_ie' . ((int) $trident_match[1] + 4)] = true; |
| 292 | 315 | |
| 293 | 316 | // If trident is set, see the (if any) msie tag in the user agent matches ... if not its in some compatibility view |
| 294 | - if (isset($msie_match[1]) && ($msie_match[1] < $trident_match[1] + 4)) |
|
| 295 | - $this->_browsers['is_ie_compat_view'] = true; |
|
| 317 | + if (isset($msie_match[1]) && ($msie_match[1] < $trident_match[1] + 4)) { |
|
| 318 | + $this->_browsers['is_ie_compat_view'] = true; |
|
| 319 | + } |
|
| 296 | 320 | } |
| 297 | 321 | |
| 298 | 322 | // Detect true IE6 and IE7 and not IE in compat mode. |
@@ -326,8 +350,9 @@ discard block |
||
| 326 | 350 | */ |
| 327 | 351 | private function setupFirefox() |
| 328 | 352 | { |
| 329 | - if (preg_match('~(?:Firefox|Ice[wW]easel|IceCat|Shiretoko|Minefield)[\/ \(]([^ ;\)]+)~', $_SERVER['HTTP_USER_AGENT'], $match) === 1) |
|
| 330 | - $this->_browsers['is_firefox' . (int) $match[1]] = true; |
|
| 353 | + if (preg_match('~(?:Firefox|Ice[wW]easel|IceCat|Shiretoko|Minefield)[\/ \(]([^ ;\)]+)~', $_SERVER['HTTP_USER_AGENT'], $match) === 1) { |
|
| 354 | + $this->_browsers['is_firefox' . (int) $match[1]] = true; |
|
| 355 | + } |
|
| 331 | 356 | } |
| 332 | 357 | |
| 333 | 358 | /** |
@@ -338,11 +363,13 @@ discard block |
||
| 338 | 363 | private function setupOpera() |
| 339 | 364 | { |
| 340 | 365 | // Opera 10+ uses the version tag at the end of the string |
| 341 | - if (preg_match('~\sVersion/([0-9]+)\.[0-9]+(?:\s*|$)~', $_SERVER['HTTP_USER_AGENT'], $match)) |
|
| 342 | - $this->_browsers['is_opera' . (int) $match[1]] = true; |
|
| 366 | + if (preg_match('~\sVersion/([0-9]+)\.[0-9]+(?:\s*|$)~', $_SERVER['HTTP_USER_AGENT'], $match)) { |
|
| 367 | + $this->_browsers['is_opera' . (int) $match[1]] = true; |
|
| 368 | + } |
|
| 343 | 369 | // Opera pre 10 is supposed to uses the Opera tag alone, as do some spoofers |
| 344 | - elseif (preg_match('~Opera[ /]([0-9]+)(?!\\.[89])~', $_SERVER['HTTP_USER_AGENT'], $match)) |
|
| 345 | - $this->_browsers['is_opera' . (int) $match[1]] = true; |
|
| 370 | + elseif (preg_match('~Opera[ /]([0-9]+)(?!\\.[89])~', $_SERVER['HTTP_USER_AGENT'], $match)) { |
|
| 371 | + $this->_browsers['is_opera' . (int) $match[1]] = true; |
|
| 372 | + } |
|
| 346 | 373 | |
| 347 | 374 | // Needs size fix? |
| 348 | 375 | $this->_browsers['needs_size_fix'] = !empty($this->_browsers['is_opera6']); |
@@ -353,8 +380,9 @@ discard block |
||
| 353 | 380 | */ |
| 354 | 381 | private function setupEdge() |
| 355 | 382 | { |
| 356 | - if (preg_match('~Edge[\/]([0-9][0-9]?[\.][0-9][0-9])~i', $_SERVER['HTTP_USER_AGENT'], $match) === 1) |
|
| 357 | - $this->_browsers['is_edge' . (int) $match[1]] = true; |
|
| 383 | + if (preg_match('~Edge[\/]([0-9][0-9]?[\.][0-9][0-9])~i', $_SERVER['HTTP_USER_AGENT'], $match) === 1) { |
|
| 384 | + $this->_browsers['is_edge' . (int) $match[1]] = true; |
|
| 385 | + } |
|
| 358 | 386 | } |
| 359 | 387 | |
| 360 | 388 | /** |
@@ -367,9 +395,9 @@ discard block |
||
| 367 | 395 | { |
| 368 | 396 | global $context; |
| 369 | 397 | |
| 370 | - if ($this->_is_mobile) |
|
| 371 | - $context['browser_body_id'] = 'mobile'; |
|
| 372 | - else |
|
| 398 | + if ($this->_is_mobile) { |
|
| 399 | + $context['browser_body_id'] = 'mobile'; |
|
| 400 | + } else |
|
| 373 | 401 | { |
| 374 | 402 | // add in any specific detection conversions here if you want a special body id e.g. 'is_opera9' => 'opera9' |
| 375 | 403 | $browser_priority = array( |
@@ -99,19 +99,19 @@ |
||
| 99 | 99 | { |
| 100 | 100 | if (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d{1,7};i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d{1,14};(i:3;i:\d;)?\}$~', $_COOKIE[$cookiename]) === 1) |
| 101 | 101 | { |
| 102 | - list (, , $timeout) = smf_json_decode($_COOKIE[$cookiename], true); |
|
| 102 | + list (,, $timeout) = smf_json_decode($_COOKIE[$cookiename], true); |
|
| 103 | 103 | |
| 104 | 104 | // That didn't work... Maybe it's using serialize? |
| 105 | 105 | if (is_null($timeout)) |
| 106 | - list (, , $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
| 106 | + list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
| 107 | 107 | } |
| 108 | 108 | elseif (isset($_SESSION['login_' . $cookiename])) |
| 109 | 109 | { |
| 110 | - list (, , $timeout) = smf_json_decode($_SESSION['login_' . $cookiename]); |
|
| 110 | + list (,, $timeout) = smf_json_decode($_SESSION['login_' . $cookiename]); |
|
| 111 | 111 | |
| 112 | 112 | // Try for old format |
| 113 | 113 | if (is_null($timeout)) |
| 114 | - list (, , $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 114 | + list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 115 | 115 | } |
| 116 | 116 | else |
| 117 | 117 | trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR); |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 3 |
| 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 | * Ask them for their login information. (shows a page for the user to type |
@@ -29,8 +30,9 @@ discard block |
||
| 29 | 30 | global $txt, $context, $scripturl, $user_info; |
| 30 | 31 | |
| 31 | 32 | // You are already logged in, go take a tour of the boards |
| 32 | - if (!empty($user_info['id'])) |
|
| 33 | - redirectexit(); |
|
| 33 | + if (!empty($user_info['id'])) { |
|
| 34 | + redirectexit(); |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | // We need to load the Login template/language file. |
| 36 | 38 | loadLanguage('Login'); |
@@ -57,10 +59,11 @@ discard block |
||
| 57 | 59 | ); |
| 58 | 60 | |
| 59 | 61 | // Set the login URL - will be used when the login process is done (but careful not to send us to an attachment). |
| 60 | - if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) |
|
| 61 | - $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 62 | - elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) |
|
| 63 | - unset($_SESSION['login_url']); |
|
| 62 | + if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) { |
|
| 63 | + $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 64 | + } elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) { |
|
| 65 | + unset($_SESSION['login_url']); |
|
| 66 | + } |
|
| 64 | 67 | |
| 65 | 68 | // Create a one time token. |
| 66 | 69 | createToken('login'); |
@@ -83,8 +86,9 @@ discard block |
||
| 83 | 86 | global $cookiename, $modSettings, $context, $sourcedir, $maintenance; |
| 84 | 87 | |
| 85 | 88 | // Check to ensure we're forcing SSL for authentication |
| 86 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
| 87 | - fatal_lang_error('login_ssl_required'); |
|
| 89 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
| 90 | + fatal_lang_error('login_ssl_required'); |
|
| 91 | + } |
|
| 88 | 92 | |
| 89 | 93 | // Load cookie authentication stuff. |
| 90 | 94 | require_once($sourcedir . '/Subs-Auth.php'); |
@@ -102,19 +106,20 @@ discard block |
||
| 102 | 106 | list (, , $timeout) = smf_json_decode($_COOKIE[$cookiename], true); |
| 103 | 107 | |
| 104 | 108 | // That didn't work... Maybe it's using serialize? |
| 105 | - if (is_null($timeout)) |
|
| 106 | - list (, , $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
| 107 | - } |
|
| 108 | - elseif (isset($_SESSION['login_' . $cookiename])) |
|
| 109 | + if (is_null($timeout)) { |
|
| 110 | + list (, , $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
| 111 | + } |
|
| 112 | + } elseif (isset($_SESSION['login_' . $cookiename])) |
|
| 109 | 113 | { |
| 110 | 114 | list (, , $timeout) = smf_json_decode($_SESSION['login_' . $cookiename]); |
| 111 | 115 | |
| 112 | 116 | // Try for old format |
| 113 | - if (is_null($timeout)) |
|
| 114 | - list (, , $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 117 | + if (is_null($timeout)) { |
|
| 118 | + list (, , $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 119 | + } |
|
| 120 | + } else { |
|
| 121 | + trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR); |
|
| 115 | 122 | } |
| 116 | - else |
|
| 117 | - trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR); |
|
| 118 | 123 | |
| 119 | 124 | $user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4); |
| 120 | 125 | updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt'])); |
@@ -125,16 +130,18 @@ discard block |
||
| 125 | 130 | $tfadata = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true); |
| 126 | 131 | |
| 127 | 132 | // If that didn't work, try unserialize instead... |
| 128 | - if (is_null($tfadata)) |
|
| 129 | - $tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']); |
|
| 133 | + if (is_null($tfadata)) { |
|
| 134 | + $tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']); |
|
| 135 | + } |
|
| 130 | 136 | |
| 131 | 137 | list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata; |
| 132 | 138 | |
| 133 | 139 | // If we're preserving the cookie, reset it with updated salt |
| 134 | - if ($preserve && time() < $exp) |
|
| 135 | - setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true); |
|
| 136 | - else |
|
| 137 | - setTFACookie(-3600, 0, ''); |
|
| 140 | + if ($preserve && time() < $exp) { |
|
| 141 | + setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true); |
|
| 142 | + } else { |
|
| 143 | + setTFACookie(-3600, 0, ''); |
|
| 144 | + } |
|
| 138 | 145 | } |
| 139 | 146 | |
| 140 | 147 | setLoginCookie($timeout - time(), $user_info['id'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
@@ -145,20 +152,20 @@ discard block |
||
| 145 | 152 | elseif (isset($_GET['sa']) && $_GET['sa'] == 'check') |
| 146 | 153 | { |
| 147 | 154 | // Strike! You're outta there! |
| 148 | - if ($_GET['member'] != $user_info['id']) |
|
| 149 | - fatal_lang_error('login_cookie_error', false); |
|
| 155 | + if ($_GET['member'] != $user_info['id']) { |
|
| 156 | + fatal_lang_error('login_cookie_error', false); |
|
| 157 | + } |
|
| 150 | 158 | |
| 151 | 159 | $user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap'])))); |
| 152 | 160 | |
| 153 | 161 | // Some whitelisting for login_url... |
| 154 | - if (empty($_SESSION['login_url'])) |
|
| 155 | - redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
|
| 156 | - elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false)) |
|
| 162 | + if (empty($_SESSION['login_url'])) { |
|
| 163 | + redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
|
| 164 | + } elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false)) |
|
| 157 | 165 | { |
| 158 | 166 | unset ($_SESSION['login_url']); |
| 159 | 167 | redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
| 160 | - } |
|
| 161 | - else |
|
| 168 | + } else |
|
| 162 | 169 | { |
| 163 | 170 | // Best not to clutter the session data too much... |
| 164 | 171 | $temp = $_SESSION['login_url']; |
@@ -169,8 +176,9 @@ discard block |
||
| 169 | 176 | } |
| 170 | 177 | |
| 171 | 178 | // Beyond this point you are assumed to be a guest trying to login. |
| 172 | - if (!$user_info['is_guest']) |
|
| 173 | - redirectexit(); |
|
| 179 | + if (!$user_info['is_guest']) { |
|
| 180 | + redirectexit(); |
|
| 181 | + } |
|
| 174 | 182 | |
| 175 | 183 | // Are you guessing with a script? |
| 176 | 184 | checkSession(); |
@@ -178,18 +186,21 @@ discard block |
||
| 178 | 186 | spamProtection('login'); |
| 179 | 187 | |
| 180 | 188 | // Set the login_url if it's not already set (but careful not to send us to an attachment). |
| 181 | - if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) |
|
| 182 | - $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 189 | + if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) { |
|
| 190 | + $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 191 | + } |
|
| 183 | 192 | |
| 184 | 193 | // Been guessing a lot, haven't we? |
| 185 | - if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) |
|
| 186 | - fatal_lang_error('login_threshold_fail', 'critical'); |
|
| 194 | + if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) { |
|
| 195 | + fatal_lang_error('login_threshold_fail', 'critical'); |
|
| 196 | + } |
|
| 187 | 197 | |
| 188 | 198 | // Set up the cookie length. (if it's invalid, just fall through and use the default.) |
| 189 | - if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) |
|
| 190 | - $modSettings['cookieTime'] = 3153600; |
|
| 191 | - elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) |
|
| 192 | - $modSettings['cookieTime'] = (int) $_POST['cookielength']; |
|
| 199 | + if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) { |
|
| 200 | + $modSettings['cookieTime'] = 3153600; |
|
| 201 | + } elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) { |
|
| 202 | + $modSettings['cookieTime'] = (int) $_POST['cookielength']; |
|
| 203 | + } |
|
| 193 | 204 | |
| 194 | 205 | loadLanguage('Login'); |
| 195 | 206 | // Load the template stuff. |
@@ -301,8 +312,9 @@ discard block |
||
| 301 | 312 | $other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd'])); |
| 302 | 313 | |
| 303 | 314 | // Snitz style - SHA-256. Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway. |
| 304 | - if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) |
|
| 305 | - $other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd'])); |
|
| 315 | + if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) { |
|
| 316 | + $other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd'])); |
|
| 317 | + } |
|
| 306 | 318 | |
| 307 | 319 | // phpBB3 users new hashing. We now support it as well ;). |
| 308 | 320 | $other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']); |
@@ -322,27 +334,29 @@ discard block |
||
| 322 | 334 | // Some common md5 ones. |
| 323 | 335 | $other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']); |
| 324 | 336 | $other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']); |
| 325 | - } |
|
| 326 | - elseif (strlen($user_settings['passwd']) == 40) |
|
| 337 | + } elseif (strlen($user_settings['passwd']) == 40) |
|
| 327 | 338 | { |
| 328 | 339 | // Maybe they are using a hash from before the password fix. |
| 329 | 340 | // This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1 |
| 330 | 341 | $other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd'])); |
| 331 | 342 | |
| 332 | 343 | // BurningBoard3 style of hashing. |
| 333 | - if (!empty($modSettings['enable_password_conversion'])) |
|
| 334 | - $other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd']))); |
|
| 344 | + if (!empty($modSettings['enable_password_conversion'])) { |
|
| 345 | + $other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd']))); |
|
| 346 | + } |
|
| 335 | 347 | |
| 336 | 348 | // Perhaps we converted to UTF-8 and have a valid password being hashed differently. |
| 337 | 349 | if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8') |
| 338 | 350 | { |
| 339 | 351 | // Try iconv first, for no particular reason. |
| 340 | - if (function_exists('iconv')) |
|
| 341 | - $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd']))); |
|
| 352 | + if (function_exists('iconv')) { |
|
| 353 | + $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd']))); |
|
| 354 | + } |
|
| 342 | 355 | |
| 343 | 356 | // Say it aint so, iconv failed! |
| 344 | - if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) |
|
| 345 | - $other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet']))); |
|
| 357 | + if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) { |
|
| 358 | + $other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet']))); |
|
| 359 | + } |
|
| 346 | 360 | } |
| 347 | 361 | } |
| 348 | 362 | |
@@ -372,8 +386,9 @@ discard block |
||
| 372 | 386 | $_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1; |
| 373 | 387 | |
| 374 | 388 | // Hmm... don't remember it, do you? Here, try the password reminder ;). |
| 375 | - if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) |
|
| 376 | - redirectexit('action=reminder'); |
|
| 389 | + if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) { |
|
| 390 | + redirectexit('action=reminder'); |
|
| 391 | + } |
|
| 377 | 392 | // We'll give you another chance... |
| 378 | 393 | else |
| 379 | 394 | { |
@@ -384,8 +399,7 @@ discard block |
||
| 384 | 399 | return; |
| 385 | 400 | } |
| 386 | 401 | } |
| 387 | - } |
|
| 388 | - elseif (!empty($user_settings['passwd_flood'])) |
|
| 402 | + } elseif (!empty($user_settings['passwd_flood'])) |
|
| 389 | 403 | { |
| 390 | 404 | // Let's be sure they weren't a little hacker. |
| 391 | 405 | validatePasswordFlood($user_settings['id_member'], $user_settings['passwd_flood'], true); |
@@ -402,8 +416,9 @@ discard block |
||
| 402 | 416 | } |
| 403 | 417 | |
| 404 | 418 | // Check their activation status. |
| 405 | - if (!checkActivation()) |
|
| 406 | - return; |
|
| 419 | + if (!checkActivation()) { |
|
| 420 | + return; |
|
| 421 | + } |
|
| 407 | 422 | |
| 408 | 423 | DoLogin(); |
| 409 | 424 | } |
@@ -415,8 +430,9 @@ discard block |
||
| 415 | 430 | { |
| 416 | 431 | global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl; |
| 417 | 432 | |
| 418 | - if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) |
|
| 419 | - fatal_lang_error('no_access', false); |
|
| 433 | + if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) { |
|
| 434 | + fatal_lang_error('no_access', false); |
|
| 435 | + } |
|
| 420 | 436 | |
| 421 | 437 | loadLanguage('Profile'); |
| 422 | 438 | require_once($sourcedir . '/Class-TOTP.php'); |
@@ -424,8 +440,9 @@ discard block |
||
| 424 | 440 | $member = $context['tfa_member']; |
| 425 | 441 | |
| 426 | 442 | // Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA |
| 427 | - if (time() - $member['last_login'] < 120) |
|
| 428 | - fatal_lang_error('tfa_wait', false); |
|
| 443 | + if (time() - $member['last_login'] < 120) { |
|
| 444 | + fatal_lang_error('tfa_wait', false); |
|
| 445 | + } |
|
| 429 | 446 | |
| 430 | 447 | $totp = new \TOTP\Auth($member['tfa_secret']); |
| 431 | 448 | $totp->setRange(1); |
@@ -439,8 +456,9 @@ discard block |
||
| 439 | 456 | if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup'])) |
| 440 | 457 | { |
| 441 | 458 | // Check to ensure we're forcing SSL for authentication |
| 442 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
| 443 | - fatal_lang_error('login_ssl_required'); |
|
| 459 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
| 460 | + fatal_lang_error('login_ssl_required'); |
|
| 461 | + } |
|
| 444 | 462 | |
| 445 | 463 | $code = $_POST['tfa_code']; |
| 446 | 464 | |
@@ -450,20 +468,19 @@ discard block |
||
| 450 | 468 | |
| 451 | 469 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']), !empty($_POST['tfa_preserve'])); |
| 452 | 470 | redirectexit(); |
| 453 | - } |
|
| 454 | - else |
|
| 471 | + } else |
|
| 455 | 472 | { |
| 456 | 473 | validatePasswordFlood($member['id_member'], $member['passwd_flood'], false, true); |
| 457 | 474 | |
| 458 | 475 | $context['tfa_error'] = true; |
| 459 | 476 | $context['tfa_value'] = $_POST['tfa_code']; |
| 460 | 477 | } |
| 461 | - } |
|
| 462 | - elseif (!empty($_POST['tfa_backup'])) |
|
| 478 | + } elseif (!empty($_POST['tfa_backup'])) |
|
| 463 | 479 | { |
| 464 | 480 | // Check to ensure we're forcing SSL for authentication |
| 465 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
| 466 | - fatal_lang_error('login_ssl_required'); |
|
| 481 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
| 482 | + fatal_lang_error('login_ssl_required'); |
|
| 483 | + } |
|
| 467 | 484 | |
| 468 | 485 | $backup = $_POST['tfa_backup']; |
| 469 | 486 | |
@@ -477,8 +494,7 @@ discard block |
||
| 477 | 494 | )); |
| 478 | 495 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt'])); |
| 479 | 496 | redirectexit('action=profile;area=tfasetup;backup'); |
| 480 | - } |
|
| 481 | - else |
|
| 497 | + } else |
|
| 482 | 498 | { |
| 483 | 499 | validatePasswordFlood($member['id_member'], $member['passwd_flood'], false, true); |
| 484 | 500 | |
@@ -501,8 +517,9 @@ discard block |
||
| 501 | 517 | { |
| 502 | 518 | global $context, $txt, $scripturl, $user_settings, $modSettings; |
| 503 | 519 | |
| 504 | - if (!isset($context['login_errors'])) |
|
| 505 | - $context['login_errors'] = array(); |
|
| 520 | + if (!isset($context['login_errors'])) { |
|
| 521 | + $context['login_errors'] = array(); |
|
| 522 | + } |
|
| 506 | 523 | |
| 507 | 524 | // What is the true activation status of this account? |
| 508 | 525 | $activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated']; |
@@ -514,8 +531,9 @@ discard block |
||
| 514 | 531 | return false; |
| 515 | 532 | } |
| 516 | 533 | // Awaiting approval still? |
| 517 | - elseif ($activation_status == 3) |
|
| 518 | - fatal_lang_error('still_awaiting_approval', 'user'); |
|
| 534 | + elseif ($activation_status == 3) { |
|
| 535 | + fatal_lang_error('still_awaiting_approval', 'user'); |
|
| 536 | + } |
|
| 519 | 537 | // Awaiting deletion, changed their mind? |
| 520 | 538 | elseif ($activation_status == 4) |
| 521 | 539 | { |
@@ -523,8 +541,7 @@ discard block |
||
| 523 | 541 | { |
| 524 | 542 | updateMemberData($user_settings['id_member'], array('is_activated' => 1)); |
| 525 | 543 | updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0))); |
| 526 | - } |
|
| 527 | - else |
|
| 544 | + } else |
|
| 528 | 545 | { |
| 529 | 546 | $context['disable_login_hashing'] = true; |
| 530 | 547 | $context['login_errors'][] = $txt['awaiting_delete_account']; |
@@ -565,8 +582,9 @@ discard block |
||
| 565 | 582 | setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
| 566 | 583 | |
| 567 | 584 | // Reset the login threshold. |
| 568 | - if (isset($_SESSION['failed_login'])) |
|
| 569 | - unset($_SESSION['failed_login']); |
|
| 585 | + if (isset($_SESSION['failed_login'])) { |
|
| 586 | + unset($_SESSION['failed_login']); |
|
| 587 | + } |
|
| 570 | 588 | |
| 571 | 589 | $user_info['is_guest'] = false; |
| 572 | 590 | $user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']); |
@@ -588,16 +606,18 @@ discard block |
||
| 588 | 606 | 'id_member' => $user_info['id'], |
| 589 | 607 | ) |
| 590 | 608 | ); |
| 591 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
| 592 | - $_SESSION['first_login'] = true; |
|
| 593 | - else |
|
| 594 | - unset($_SESSION['first_login']); |
|
| 609 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
| 610 | + $_SESSION['first_login'] = true; |
|
| 611 | + } else { |
|
| 612 | + unset($_SESSION['first_login']); |
|
| 613 | + } |
|
| 595 | 614 | $smcFunc['db_free_result']($request); |
| 596 | 615 | |
| 597 | 616 | // You've logged in, haven't you? |
| 598 | 617 | $update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']); |
| 599 | - if (empty($user_settings['tfa_secret'])) |
|
| 600 | - $update['last_login'] = time(); |
|
| 618 | + if (empty($user_settings['tfa_secret'])) { |
|
| 619 | + $update['last_login'] = time(); |
|
| 620 | + } |
|
| 601 | 621 | updateMemberData($user_info['id'], $update); |
| 602 | 622 | |
| 603 | 623 | // Get rid of the online entry for that old guest.... |
@@ -611,8 +631,8 @@ discard block |
||
| 611 | 631 | $_SESSION['log_time'] = 0; |
| 612 | 632 | |
| 613 | 633 | // Log this entry, only if we have it enabled. |
| 614 | - if (!empty($modSettings['loginHistoryDays'])) |
|
| 615 | - $smcFunc['db_insert']('insert', |
|
| 634 | + if (!empty($modSettings['loginHistoryDays'])) { |
|
| 635 | + $smcFunc['db_insert']('insert', |
|
| 616 | 636 | '{db_prefix}member_logins', |
| 617 | 637 | array( |
| 618 | 638 | 'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet', |
@@ -624,13 +644,15 @@ discard block |
||
| 624 | 644 | 'id_member', 'time' |
| 625 | 645 | ) |
| 626 | 646 | ); |
| 647 | + } |
|
| 627 | 648 | |
| 628 | 649 | // Just log you back out if it's in maintenance mode and you AREN'T an admin. |
| 629 | - if (empty($maintenance) || allowedTo('admin_forum')) |
|
| 630 | - redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']); |
|
| 631 | - else |
|
| 632 | - redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']); |
|
| 633 | -} |
|
| 650 | + if (empty($maintenance) || allowedTo('admin_forum')) { |
|
| 651 | + redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']); |
|
| 652 | + } else { |
|
| 653 | + redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']); |
|
| 654 | + } |
|
| 655 | + } |
|
| 634 | 656 | |
| 635 | 657 | /** |
| 636 | 658 | * Logs the current user out of their account. |
@@ -646,13 +668,15 @@ discard block |
||
| 646 | 668 | global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings; |
| 647 | 669 | |
| 648 | 670 | // Make sure they aren't being auto-logged out. |
| 649 | - if (!$internal) |
|
| 650 | - checkSession('get'); |
|
| 671 | + if (!$internal) { |
|
| 672 | + checkSession('get'); |
|
| 673 | + } |
|
| 651 | 674 | |
| 652 | 675 | require_once($sourcedir . '/Subs-Auth.php'); |
| 653 | 676 | |
| 654 | - if (isset($_SESSION['pack_ftp'])) |
|
| 655 | - $_SESSION['pack_ftp'] = null; |
|
| 677 | + if (isset($_SESSION['pack_ftp'])) { |
|
| 678 | + $_SESSION['pack_ftp'] = null; |
|
| 679 | + } |
|
| 656 | 680 | |
| 657 | 681 | // It won't be first login anymore. |
| 658 | 682 | unset($_SESSION['first_login']); |
@@ -680,24 +704,27 @@ discard block |
||
| 680 | 704 | |
| 681 | 705 | // And some other housekeeping while we're at it. |
| 682 | 706 | $salt = substr(md5(mt_rand()), 0, 4); |
| 683 | - if (!empty($user_info['id'])) |
|
| 684 | - updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
| 707 | + if (!empty($user_info['id'])) { |
|
| 708 | + updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
| 709 | + } |
|
| 685 | 710 | |
| 686 | 711 | if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa'])) |
| 687 | 712 | { |
| 688 | 713 | $tfadata = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true); |
| 689 | 714 | |
| 690 | 715 | // If that failed, try the old method |
| 691 | - if (is_null($tfadata)) |
|
| 692 | - $tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']); |
|
| 716 | + if (is_null($tfadata)) { |
|
| 717 | + $tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']); |
|
| 718 | + } |
|
| 693 | 719 | |
| 694 | 720 | list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata; |
| 695 | 721 | |
| 696 | 722 | // If we're preserving the cookie, reset it with updated salt |
| 697 | - if ($preserve && time() < $exp) |
|
| 698 | - setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true); |
|
| 699 | - else |
|
| 700 | - setTFACookie(-3600, 0, ''); |
|
| 723 | + if ($preserve && time() < $exp) { |
|
| 724 | + setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true); |
|
| 725 | + } else { |
|
| 726 | + setTFACookie(-3600, 0, ''); |
|
| 727 | + } |
|
| 701 | 728 | } |
| 702 | 729 | |
| 703 | 730 | session_destroy(); |
@@ -705,14 +732,13 @@ discard block |
||
| 705 | 732 | // Off to the merry board index we go! |
| 706 | 733 | if ($redirect) |
| 707 | 734 | { |
| 708 | - if (empty($_SESSION['logout_url'])) |
|
| 709 | - redirectexit('', $context['server']['needs_login_fix']); |
|
| 710 | - elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false)) |
|
| 735 | + if (empty($_SESSION['logout_url'])) { |
|
| 736 | + redirectexit('', $context['server']['needs_login_fix']); |
|
| 737 | + } elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false)) |
|
| 711 | 738 | { |
| 712 | 739 | unset ($_SESSION['logout_url']); |
| 713 | 740 | redirectexit(); |
| 714 | - } |
|
| 715 | - else |
|
| 741 | + } else |
|
| 716 | 742 | { |
| 717 | 743 | $temp = $_SESSION['logout_url']; |
| 718 | 744 | unset($_SESSION['logout_url']); |
@@ -745,8 +771,9 @@ discard block |
||
| 745 | 771 | function phpBB3_password_check($passwd, $passwd_hash) |
| 746 | 772 | { |
| 747 | 773 | // Too long or too short? |
| 748 | - if (strlen($passwd_hash) != 34) |
|
| 749 | - return; |
|
| 774 | + if (strlen($passwd_hash) != 34) { |
|
| 775 | + return; |
|
| 776 | + } |
|
| 750 | 777 | |
| 751 | 778 | // Range of characters allowed. |
| 752 | 779 | $range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
@@ -758,8 +785,9 @@ discard block |
||
| 758 | 785 | $salt = substr($passwd_hash, 4, 8); |
| 759 | 786 | |
| 760 | 787 | $hash = md5($salt . $passwd, true); |
| 761 | - for (; $count != 0; --$count) |
|
| 762 | - $hash = md5($hash . $passwd, true); |
|
| 788 | + for (; $count != 0; --$count) { |
|
| 789 | + $hash = md5($hash . $passwd, true); |
|
| 790 | + } |
|
| 763 | 791 | |
| 764 | 792 | $output = substr($passwd_hash, 0, 12); |
| 765 | 793 | $i = 0; |
@@ -768,21 +796,25 @@ discard block |
||
| 768 | 796 | $value = ord($hash[$i++]); |
| 769 | 797 | $output .= $range[$value & 0x3f]; |
| 770 | 798 | |
| 771 | - if ($i < 16) |
|
| 772 | - $value |= ord($hash[$i]) << 8; |
|
| 799 | + if ($i < 16) { |
|
| 800 | + $value |= ord($hash[$i]) << 8; |
|
| 801 | + } |
|
| 773 | 802 | |
| 774 | 803 | $output .= $range[($value >> 6) & 0x3f]; |
| 775 | 804 | |
| 776 | - if ($i++ >= 16) |
|
| 777 | - break; |
|
| 805 | + if ($i++ >= 16) { |
|
| 806 | + break; |
|
| 807 | + } |
|
| 778 | 808 | |
| 779 | - if ($i < 16) |
|
| 780 | - $value |= ord($hash[$i]) << 16; |
|
| 809 | + if ($i < 16) { |
|
| 810 | + $value |= ord($hash[$i]) << 16; |
|
| 811 | + } |
|
| 781 | 812 | |
| 782 | 813 | $output .= $range[($value >> 12) & 0x3f]; |
| 783 | 814 | |
| 784 | - if ($i++ >= 16) |
|
| 785 | - break; |
|
| 815 | + if ($i++ >= 16) { |
|
| 816 | + break; |
|
| 817 | + } |
|
| 786 | 818 | |
| 787 | 819 | $output .= $range[($value >> 18) & 0x3f]; |
| 788 | 820 | } |
@@ -813,8 +845,9 @@ discard block |
||
| 813 | 845 | require_once($sourcedir . '/Subs-Auth.php'); |
| 814 | 846 | setLoginCookie(-3600, 0); |
| 815 | 847 | |
| 816 | - if (isset($_SESSION['login_' . $cookiename])) |
|
| 817 | - unset($_SESSION['login_' . $cookiename]); |
|
| 848 | + if (isset($_SESSION['login_' . $cookiename])) { |
|
| 849 | + unset($_SESSION['login_' . $cookiename]); |
|
| 850 | + } |
|
| 818 | 851 | } |
| 819 | 852 | |
| 820 | 853 | // We need a member! |
@@ -828,8 +861,9 @@ discard block |
||
| 828 | 861 | } |
| 829 | 862 | |
| 830 | 863 | // Right, have we got a flood value? |
| 831 | - if ($password_flood_value !== false) |
|
| 832 | - @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
| 864 | + if ($password_flood_value !== false) { |
|
| 865 | + @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
| 866 | + } |
|
| 833 | 867 | |
| 834 | 868 | // Timestamp or number of tries invalid? |
| 835 | 869 | if (empty($number_tries) || empty($time_stamp)) |
@@ -845,15 +879,17 @@ discard block |
||
| 845 | 879 | $number_tries = $time_stamp < time() - 20 ? 2 : $number_tries; |
| 846 | 880 | |
| 847 | 881 | // They are trying too fast, make them wait longer |
| 848 | - if ($time_stamp < time() - 10) |
|
| 849 | - $time_stamp = time(); |
|
| 882 | + if ($time_stamp < time() - 10) { |
|
| 883 | + $time_stamp = time(); |
|
| 884 | + } |
|
| 850 | 885 | } |
| 851 | 886 | |
| 852 | 887 | $number_tries++; |
| 853 | 888 | |
| 854 | 889 | // Broken the law? |
| 855 | - if ($number_tries > 5) |
|
| 856 | - fatal_lang_error('login_threshold_brute_fail', 'critical'); |
|
| 890 | + if ($number_tries > 5) { |
|
| 891 | + fatal_lang_error('login_threshold_brute_fail', 'critical'); |
|
| 892 | + } |
|
| 857 | 893 | |
| 858 | 894 | // Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it! |
| 859 | 895 | updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries)); |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | ) |
| 232 | 232 | ); |
| 233 | 233 | |
| 234 | - $request = $smcFunc['db_query']('',' |
|
| 234 | + $request = $smcFunc['db_query']('', ' |
|
| 235 | 235 | SHOW default_text_search_config', |
| 236 | 236 | array() |
| 237 | 237 | ); |
@@ -426,8 +426,8 @@ discard block |
||
| 426 | 426 | WHERE t.schemaname= {string:schema} and ( |
| 427 | 427 | indexname = {string:messages_ftx} OR indexname = {string:log_search_words} )', |
| 428 | 428 | array( |
| 429 | - 'messages_ftx' => $db_prefix. 'messages_ftx', |
|
| 430 | - 'log_search_words' => $db_prefix. 'log_search_words', |
|
| 429 | + 'messages_ftx' => $db_prefix . 'messages_ftx', |
|
| 430 | + 'log_search_words' => $db_prefix . 'log_search_words', |
|
| 431 | 431 | 'schema' => 'public', |
| 432 | 432 | ) |
| 433 | 433 | ); |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | $context['table_info']['index_length'] = (int) $row['index_size']; |
| 443 | 443 | $context['table_info']['fulltext_length'] = (int) $row['index_size']; |
| 444 | 444 | } |
| 445 | - elseif ($row['indexname'] == $db_prefix. 'log_search_words') |
|
| 445 | + elseif ($row['indexname'] == $db_prefix . 'log_search_words') |
|
| 446 | 446 | { |
| 447 | 447 | $context['table_info']['index_length'] = (int) $row['index_size']; |
| 448 | 448 | $context['table_info']['custom_index_length'] = (int) $row['index_size']; |
@@ -799,7 +799,7 @@ discard block |
||
| 799 | 799 | // We need this for db_get_version |
| 800 | 800 | db_extend(); |
| 801 | 801 | |
| 802 | - if ($smcFunc['db_title'] == 'PostgreSQL'){ |
|
| 802 | + if ($smcFunc['db_title'] == 'PostgreSQL') { |
|
| 803 | 803 | $request = $smcFunc['db_query']('', ' |
| 804 | 804 | SELECT |
| 805 | 805 | indexname |
@@ -814,7 +814,7 @@ discard block |
||
| 814 | 814 | WHERE t.schemaname= {string:schema} and indexname = {string:messages_ftx}', |
| 815 | 815 | array( |
| 816 | 816 | 'schema' => 'public', |
| 817 | - 'messages_ftx' => $db_prefix.'messages_ftx', |
|
| 817 | + 'messages_ftx' => $db_prefix . 'messages_ftx', |
|
| 818 | 818 | ) |
| 819 | 819 | ); |
| 820 | 820 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 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 | * Main entry point for the admin search settings screen. |
@@ -107,11 +108,13 @@ discard block |
||
| 107 | 108 | // Perhaps the search method wants to add some settings? |
| 108 | 109 | require_once($sourcedir . '/Search.php'); |
| 109 | 110 | $searchAPI = findSearchAPI(); |
| 110 | - if (is_callable(array($searchAPI, 'searchSettings'))) |
|
| 111 | - call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars)); |
|
| 111 | + if (is_callable(array($searchAPI, 'searchSettings'))) { |
|
| 112 | + call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars)); |
|
| 113 | + } |
|
| 112 | 114 | |
| 113 | - if ($return_config) |
|
| 114 | - return $config_vars; |
|
| 115 | + if ($return_config) { |
|
| 116 | + return $config_vars; |
|
| 117 | + } |
|
| 115 | 118 | |
| 116 | 119 | $context['page_title'] = $txt['search_settings_title']; |
| 117 | 120 | $context['sub_template'] = 'show_settings'; |
@@ -126,8 +129,9 @@ discard block |
||
| 126 | 129 | |
| 127 | 130 | call_integration_hook('integrate_save_search_settings'); |
| 128 | 131 | |
| 129 | - if (empty($_POST['search_results_per_page'])) |
|
| 130 | - $_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages']; |
|
| 132 | + if (empty($_POST['search_results_per_page'])) { |
|
| 133 | + $_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages']; |
|
| 134 | + } |
|
| 131 | 135 | saveDBSettings($config_vars); |
| 132 | 136 | $_SESSION['adm-save'] = true; |
| 133 | 137 | redirectexit('action=admin;area=managesearch;sa=settings;' . $context['session_var'] . '=' . $context['session_id']); |
@@ -177,17 +181,20 @@ discard block |
||
| 177 | 181 | call_integration_hook('integrate_save_search_weights'); |
| 178 | 182 | |
| 179 | 183 | $changes = array(); |
| 180 | - foreach ($factors as $factor) |
|
| 181 | - $changes[$factor] = (int) $_POST[$factor]; |
|
| 184 | + foreach ($factors as $factor) { |
|
| 185 | + $changes[$factor] = (int) $_POST[$factor]; |
|
| 186 | + } |
|
| 182 | 187 | updateSettings($changes); |
| 183 | 188 | } |
| 184 | 189 | |
| 185 | 190 | $context['relative_weights'] = array('total' => 0); |
| 186 | - foreach ($factors as $factor) |
|
| 187 | - $context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0; |
|
| 191 | + foreach ($factors as $factor) { |
|
| 192 | + $context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0; |
|
| 193 | + } |
|
| 188 | 194 | |
| 189 | - foreach ($factors as $factor) |
|
| 190 | - $context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1); |
|
| 195 | + foreach ($factors as $factor) { |
|
| 196 | + $context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1); |
|
| 197 | + } |
|
| 191 | 198 | |
| 192 | 199 | createToken('admin-msw'); |
| 193 | 200 | } |
@@ -215,8 +222,9 @@ discard block |
||
| 215 | 222 | $context['search_apis'] = loadSearchAPIs(); |
| 216 | 223 | |
| 217 | 224 | // Detect whether a fulltext index is set. |
| 218 | - if ($context['supports_fulltext']) |
|
| 219 | - detectFulltextIndex(); |
|
| 225 | + if ($context['supports_fulltext']) { |
|
| 226 | + detectFulltextIndex(); |
|
| 227 | + } |
|
| 220 | 228 | |
| 221 | 229 | if (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'createfulltext') |
| 222 | 230 | { |
@@ -250,8 +258,7 @@ discard block |
||
| 250 | 258 | 'language' => $language_ftx |
| 251 | 259 | ) |
| 252 | 260 | ); |
| 253 | - } |
|
| 254 | - else |
|
| 261 | + } else |
|
| 255 | 262 | { |
| 256 | 263 | // Make sure it's gone before creating it. |
| 257 | 264 | $smcFunc['db_query']('', ' |
@@ -271,8 +278,7 @@ discard block |
||
| 271 | 278 | } |
| 272 | 279 | |
| 273 | 280 | $context['fulltext_index'] = 'body'; |
| 274 | - } |
|
| 275 | - elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index'])) |
|
| 281 | + } elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index'])) |
|
| 276 | 282 | { |
| 277 | 283 | checkSession('get'); |
| 278 | 284 | validateToken('admin-msm', 'get'); |
@@ -289,12 +295,12 @@ discard block |
||
| 289 | 295 | $context['fulltext_index'] = ''; |
| 290 | 296 | |
| 291 | 297 | // Go back to the default search method. |
| 292 | - if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext') |
|
| 293 | - updateSettings(array( |
|
| 298 | + if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext') { |
|
| 299 | + updateSettings(array( |
|
| 294 | 300 | 'search_index' => '', |
| 295 | 301 | )); |
| 296 | - } |
|
| 297 | - elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom') |
|
| 302 | + } |
|
| 303 | + } elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom') |
|
| 298 | 304 | { |
| 299 | 305 | checkSession('get'); |
| 300 | 306 | validateToken('admin-msm', 'get'); |
@@ -316,12 +322,12 @@ discard block |
||
| 316 | 322 | )); |
| 317 | 323 | |
| 318 | 324 | // Go back to the default search method. |
| 319 | - if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') |
|
| 320 | - updateSettings(array( |
|
| 325 | + if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') { |
|
| 326 | + updateSettings(array( |
|
| 321 | 327 | 'search_index' => '', |
| 322 | 328 | )); |
| 323 | - } |
|
| 324 | - elseif (isset($_POST['save'])) |
|
| 329 | + } |
|
| 330 | + } elseif (isset($_POST['save'])) |
|
| 325 | 331 | { |
| 326 | 332 | checkSession(); |
| 327 | 333 | validateToken('admin-msmpost'); |
@@ -343,8 +349,8 @@ discard block |
||
| 343 | 349 | // Get some info about the messages table, to show its size and index size. |
| 344 | 350 | if ($db_type == 'mysql' || $db_type == 'mysqli') |
| 345 | 351 | { |
| 346 | - if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) |
|
| 347 | - $request = $smcFunc['db_query']('', ' |
|
| 352 | + if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) { |
|
| 353 | + $request = $smcFunc['db_query']('', ' |
|
| 348 | 354 | SHOW TABLE STATUS |
| 349 | 355 | FROM {string:database_name} |
| 350 | 356 | LIKE {string:table_name}', |
@@ -353,14 +359,15 @@ discard block |
||
| 353 | 359 | 'table_name' => str_replace('_', '\_', $match[2]) . 'messages', |
| 354 | 360 | ) |
| 355 | 361 | ); |
| 356 | - else |
|
| 357 | - $request = $smcFunc['db_query']('', ' |
|
| 362 | + } else { |
|
| 363 | + $request = $smcFunc['db_query']('', ' |
|
| 358 | 364 | SHOW TABLE STATUS |
| 359 | 365 | LIKE {string:table_name}', |
| 360 | 366 | array( |
| 361 | 367 | 'table_name' => str_replace('_', '\_', $db_prefix) . 'messages', |
| 362 | 368 | ) |
| 363 | 369 | ); |
| 370 | + } |
|
| 364 | 371 | if ($request !== false && $smcFunc['db_num_rows']($request) == 1) |
| 365 | 372 | { |
| 366 | 373 | // Only do this if the user has permission to execute this query. |
@@ -372,8 +379,8 @@ discard block |
||
| 372 | 379 | } |
| 373 | 380 | |
| 374 | 381 | // Now check the custom index table, if it exists at all. |
| 375 | - if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) |
|
| 376 | - $request = $smcFunc['db_query']('', ' |
|
| 382 | + if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) { |
|
| 383 | + $request = $smcFunc['db_query']('', ' |
|
| 377 | 384 | SHOW TABLE STATUS |
| 378 | 385 | FROM {string:database_name} |
| 379 | 386 | LIKE {string:table_name}', |
@@ -382,14 +389,15 @@ discard block |
||
| 382 | 389 | 'table_name' => str_replace('_', '\_', $match[2]) . 'log_search_words', |
| 383 | 390 | ) |
| 384 | 391 | ); |
| 385 | - else |
|
| 386 | - $request = $smcFunc['db_query']('', ' |
|
| 392 | + } else { |
|
| 393 | + $request = $smcFunc['db_query']('', ' |
|
| 387 | 394 | SHOW TABLE STATUS |
| 388 | 395 | LIKE {string:table_name}', |
| 389 | 396 | array( |
| 390 | 397 | 'table_name' => str_replace('_', '\_', $db_prefix) . 'log_search_words', |
| 391 | 398 | ) |
| 392 | 399 | ); |
| 400 | + } |
|
| 393 | 401 | if ($request !== false && $smcFunc['db_num_rows']($request) == 1) |
| 394 | 402 | { |
| 395 | 403 | // Only do this if the user has permission to execute this query. |
@@ -398,8 +406,7 @@ discard block |
||
| 398 | 406 | $context['table_info']['custom_index_length'] = $row['Data_length'] + $row['Index_length']; |
| 399 | 407 | $smcFunc['db_free_result']($request); |
| 400 | 408 | } |
| 401 | - } |
|
| 402 | - elseif ($db_type == 'postgresql') |
|
| 409 | + } elseif ($db_type == 'postgresql') |
|
| 403 | 410 | { |
| 404 | 411 | // In order to report the sizes correctly we need to perform vacuum (optimize) on the tables we will be using. |
| 405 | 412 | //db_extend(); |
@@ -441,38 +448,38 @@ discard block |
||
| 441 | 448 | $context['table_info']['data_length'] = (int) $row['table_size']; |
| 442 | 449 | $context['table_info']['index_length'] = (int) $row['index_size']; |
| 443 | 450 | $context['table_info']['fulltext_length'] = (int) $row['index_size']; |
| 444 | - } |
|
| 445 | - elseif ($row['indexname'] == $db_prefix. 'log_search_words') |
|
| 451 | + } elseif ($row['indexname'] == $db_prefix. 'log_search_words') |
|
| 446 | 452 | { |
| 447 | 453 | $context['table_info']['index_length'] = (int) $row['index_size']; |
| 448 | 454 | $context['table_info']['custom_index_length'] = (int) $row['index_size']; |
| 449 | 455 | } |
| 450 | 456 | } |
| 451 | 457 | $smcFunc['db_free_result']($request); |
| 452 | - } |
|
| 453 | - else |
|
| 454 | - // Didn't work for some reason... |
|
| 458 | + } else { |
|
| 459 | + // Didn't work for some reason... |
|
| 455 | 460 | $context['table_info'] = array( |
| 456 | 461 | 'data_length' => $txt['not_applicable'], |
| 457 | 462 | 'index_length' => $txt['not_applicable'], |
| 458 | 463 | 'fulltext_length' => $txt['not_applicable'], |
| 459 | 464 | 'custom_index_length' => $txt['not_applicable'], |
| 460 | 465 | ); |
| 461 | - } |
|
| 462 | - else |
|
| 463 | - $context['table_info'] = array( |
|
| 466 | + } |
|
| 467 | + } else { |
|
| 468 | + $context['table_info'] = array( |
|
| 464 | 469 | 'data_length' => $txt['not_applicable'], |
| 465 | 470 | 'index_length' => $txt['not_applicable'], |
| 466 | 471 | 'fulltext_length' => $txt['not_applicable'], |
| 467 | 472 | 'custom_index_length' => $txt['not_applicable'], |
| 468 | 473 | ); |
| 474 | + } |
|
| 469 | 475 | |
| 470 | 476 | // Format the data and index length in kilobytes. |
| 471 | 477 | foreach ($context['table_info'] as $type => $size) |
| 472 | 478 | { |
| 473 | 479 | // If it's not numeric then just break. This database engine doesn't support size. |
| 474 | - if (!is_numeric($size)) |
|
| 475 | - break; |
|
| 480 | + if (!is_numeric($size)) { |
|
| 481 | + break; |
|
| 482 | + } |
|
| 476 | 483 | |
| 477 | 484 | $context['table_info'][$type] = comma_format($context['table_info'][$type] / 1024) . ' ' . $txt['search_method_kilobytes']; |
| 478 | 485 | } |
@@ -501,8 +508,9 @@ discard block |
||
| 501 | 508 | |
| 502 | 509 | // Scotty, we need more time... |
| 503 | 510 | @set_time_limit(600); |
| 504 | - if (function_exists('apache_reset_timeout')) |
|
| 505 | - @apache_reset_timeout(); |
|
| 511 | + if (function_exists('apache_reset_timeout')) { |
|
| 512 | + @apache_reset_timeout(); |
|
| 513 | + } |
|
| 506 | 514 | |
| 507 | 515 | $context[$context['admin_menu_name']]['current_subsection'] = 'method'; |
| 508 | 516 | $context['page_title'] = $txt['search_index_custom']; |
@@ -532,8 +540,7 @@ discard block |
||
| 532 | 540 | $context['start'] = (int) $context['index_settings']['resume_at']; |
| 533 | 541 | unset($context['index_settings']['resume_at']); |
| 534 | 542 | $context['step'] = 1; |
| 535 | - } |
|
| 536 | - else |
|
| 543 | + } else |
|
| 537 | 544 | { |
| 538 | 545 | $context['index_settings'] = array( |
| 539 | 546 | 'bytes_per_word' => isset($_REQUEST['bytes_per_word']) && isset($index_properties[$_REQUEST['bytes_per_word']]) ? (int) $_REQUEST['bytes_per_word'] : 2, |
@@ -542,12 +549,14 @@ discard block |
||
| 542 | 549 | $context['step'] = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0; |
| 543 | 550 | |
| 544 | 551 | // admin timeouts are painful when building these long indexes - but only if we actually have such things enabled |
| 545 | - if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1) |
|
| 546 | - $_SESSION['admin_time'] = time(); |
|
| 552 | + if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1) { |
|
| 553 | + $_SESSION['admin_time'] = time(); |
|
| 554 | + } |
|
| 547 | 555 | } |
| 548 | 556 | |
| 549 | - if ($context['step'] !== 0) |
|
| 550 | - checkSession('request'); |
|
| 557 | + if ($context['step'] !== 0) { |
|
| 558 | + checkSession('request'); |
|
| 559 | + } |
|
| 551 | 560 | |
| 552 | 561 | // Step 0: let the user determine how they like their index. |
| 553 | 562 | if ($context['step'] === 0) |
@@ -576,12 +585,14 @@ discard block |
||
| 576 | 585 | $smcFunc['db_create_word_search']($index_properties[$context['index_settings']['bytes_per_word']]['column_definition']); |
| 577 | 586 | |
| 578 | 587 | // Temporarily switch back to not using a search index. |
| 579 | - if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') |
|
| 580 | - updateSettings(array('search_index' => '')); |
|
| 588 | + if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') { |
|
| 589 | + updateSettings(array('search_index' => '')); |
|
| 590 | + } |
|
| 581 | 591 | |
| 582 | 592 | // Don't let simultanious processes be updating the search index. |
| 583 | - if (!empty($modSettings['search_custom_index_config'])) |
|
| 584 | - updateSettings(array('search_custom_index_config' => '')); |
|
| 593 | + if (!empty($modSettings['search_custom_index_config'])) { |
|
| 594 | + updateSettings(array('search_custom_index_config' => '')); |
|
| 595 | + } |
|
| 585 | 596 | } |
| 586 | 597 | |
| 587 | 598 | $num_messages = array( |
@@ -597,16 +608,16 @@ discard block |
||
| 597 | 608 | 'starting_id' => $context['start'], |
| 598 | 609 | ) |
| 599 | 610 | ); |
| 600 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 601 | - $num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages']; |
|
| 611 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 612 | + $num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages']; |
|
| 613 | + } |
|
| 602 | 614 | |
| 603 | 615 | if (empty($num_messages['todo'])) |
| 604 | 616 | { |
| 605 | 617 | $context['step'] = 2; |
| 606 | 618 | $context['percentage'] = 80; |
| 607 | 619 | $context['start'] = 0; |
| 608 | - } |
|
| 609 | - else |
|
| 620 | + } else |
|
| 610 | 621 | { |
| 611 | 622 | // Number of seconds before the next step. |
| 612 | 623 | $stop = time() + 3; |
@@ -647,21 +658,22 @@ discard block |
||
| 647 | 658 | |
| 648 | 659 | $context['start'] += $forced_break ? $number_processed : $messages_per_batch; |
| 649 | 660 | |
| 650 | - if (!empty($inserts)) |
|
| 651 | - $smcFunc['db_insert']('ignore', |
|
| 661 | + if (!empty($inserts)) { |
|
| 662 | + $smcFunc['db_insert']('ignore', |
|
| 652 | 663 | '{db_prefix}log_search_words', |
| 653 | 664 | array('id_word' => 'int', 'id_msg' => 'int'), |
| 654 | 665 | $inserts, |
| 655 | 666 | array('id_word', 'id_msg') |
| 656 | 667 | ); |
| 668 | + } |
|
| 657 | 669 | if ($num_messages['todo'] === 0) |
| 658 | 670 | { |
| 659 | 671 | $context['step'] = 2; |
| 660 | 672 | $context['start'] = 0; |
| 661 | 673 | break; |
| 674 | + } else { |
|
| 675 | + updateSettings(array('search_custom_index_resume' => json_encode(array_merge($context['index_settings'], array('resume_at' => $context['start']))))); |
|
| 662 | 676 | } |
| 663 | - else |
|
| 664 | - updateSettings(array('search_custom_index_resume' => json_encode(array_merge($context['index_settings'], array('resume_at' => $context['start']))))); |
|
| 665 | 677 | } |
| 666 | 678 | |
| 667 | 679 | // Since there are still two steps to go, 80% is the maximum here. |
@@ -672,9 +684,9 @@ discard block |
||
| 672 | 684 | // Step 2: removing the words that occur too often and are of no use. |
| 673 | 685 | elseif ($context['step'] === 2) |
| 674 | 686 | { |
| 675 | - if ($context['index_settings']['bytes_per_word'] < 4) |
|
| 676 | - $context['step'] = 3; |
|
| 677 | - else |
|
| 687 | + if ($context['index_settings']['bytes_per_word'] < 4) { |
|
| 688 | + $context['step'] = 3; |
|
| 689 | + } else |
|
| 678 | 690 | { |
| 679 | 691 | $stop_words = $context['start'] === 0 || empty($modSettings['search_stopwords']) ? array() : explode(',', $modSettings['search_stopwords']); |
| 680 | 692 | $stop = time() + 3; |
@@ -695,20 +707,22 @@ discard block |
||
| 695 | 707 | 'minimum_messages' => $max_messages, |
| 696 | 708 | ) |
| 697 | 709 | ); |
| 698 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 699 | - $stop_words[] = $row['id_word']; |
|
| 710 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 711 | + $stop_words[] = $row['id_word']; |
|
| 712 | + } |
|
| 700 | 713 | $smcFunc['db_free_result']($request); |
| 701 | 714 | |
| 702 | 715 | updateSettings(array('search_stopwords' => implode(',', $stop_words))); |
| 703 | 716 | |
| 704 | - if (!empty($stop_words)) |
|
| 705 | - $smcFunc['db_query']('', ' |
|
| 717 | + if (!empty($stop_words)) { |
|
| 718 | + $smcFunc['db_query']('', ' |
|
| 706 | 719 | DELETE FROM {db_prefix}log_search_words |
| 707 | 720 | WHERE id_word in ({array_int:stop_words})', |
| 708 | 721 | array( |
| 709 | 722 | 'stop_words' => $stop_words, |
| 710 | 723 | ) |
| 711 | 724 | ); |
| 725 | + } |
|
| 712 | 726 | |
| 713 | 727 | $context['start'] += $index_properties[$context['index_settings']['bytes_per_word']]['step_size']; |
| 714 | 728 | if ($context['start'] > $index_properties[$context['index_settings']['bytes_per_word']]['max_size']) |
@@ -769,8 +783,9 @@ discard block |
||
| 769 | 783 | $searchAPI = new $search_class_name(); |
| 770 | 784 | |
| 771 | 785 | // No Support? NEXT! |
| 772 | - if (!$searchAPI->is_supported) |
|
| 773 | - continue; |
|
| 786 | + if (!$searchAPI->is_supported) { |
|
| 787 | + continue; |
|
| 788 | + } |
|
| 774 | 789 | |
| 775 | 790 | $apis[$index_name] = array( |
| 776 | 791 | 'filename' => $file, |
@@ -817,10 +832,10 @@ discard block |
||
| 817 | 832 | 'messages_ftx' => $db_prefix.'messages_ftx', |
| 818 | 833 | ) |
| 819 | 834 | ); |
| 820 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 821 | - $context['fulltext_index'][] = $row['indexname']; |
|
| 822 | - } |
|
| 823 | - else |
|
| 835 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 836 | + $context['fulltext_index'][] = $row['indexname']; |
|
| 837 | + } |
|
| 838 | + } else |
|
| 824 | 839 | { |
| 825 | 840 | $request = $smcFunc['db_query']('', ' |
| 826 | 841 | SHOW INDEX |
@@ -831,17 +846,19 @@ discard block |
||
| 831 | 846 | $context['fulltext_index'] = ''; |
| 832 | 847 | if ($request !== false || $smcFunc['db_num_rows']($request) != 0) |
| 833 | 848 | { |
| 834 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 835 | - if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
| 849 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 850 | + if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
| 836 | 851 | $context['fulltext_index'][] = $row['Key_name']; |
| 852 | + } |
|
| 837 | 853 | $smcFunc['db_free_result']($request); |
| 838 | 854 | |
| 839 | - if (is_array($context['fulltext_index'])) |
|
| 840 | - $context['fulltext_index'] = array_unique($context['fulltext_index']); |
|
| 855 | + if (is_array($context['fulltext_index'])) { |
|
| 856 | + $context['fulltext_index'] = array_unique($context['fulltext_index']); |
|
| 857 | + } |
|
| 841 | 858 | } |
| 842 | 859 | |
| 843 | - if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) |
|
| 844 | - $request = $smcFunc['db_query']('', ' |
|
| 860 | + if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) { |
|
| 861 | + $request = $smcFunc['db_query']('', ' |
|
| 845 | 862 | SHOW TABLE STATUS |
| 846 | 863 | FROM {string:database_name} |
| 847 | 864 | LIKE {string:table_name}', |
@@ -850,20 +867,22 @@ discard block |
||
| 850 | 867 | 'table_name' => str_replace('_', '\_', $match[2]) . 'messages', |
| 851 | 868 | ) |
| 852 | 869 | ); |
| 853 | - else |
|
| 854 | - $request = $smcFunc['db_query']('', ' |
|
| 870 | + } else { |
|
| 871 | + $request = $smcFunc['db_query']('', ' |
|
| 855 | 872 | SHOW TABLE STATUS |
| 856 | 873 | LIKE {string:table_name}', |
| 857 | 874 | array( |
| 858 | 875 | 'table_name' => str_replace('_', '\_', $db_prefix) . 'messages', |
| 859 | 876 | ) |
| 860 | 877 | ); |
| 878 | + } |
|
| 861 | 879 | |
| 862 | 880 | if ($request !== false) |
| 863 | 881 | { |
| 864 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 865 | - if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'], '5.6.4', '>='))) |
|
| 882 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 883 | + if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'], '5.6.4', '>='))) |
|
| 866 | 884 | $context['cannot_create_fulltext'] = true; |
| 885 | + } |
|
| 867 | 886 | $smcFunc['db_free_result']($request); |
| 868 | 887 | } |
| 869 | 888 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | if (!empty($db_options['persist'])) |
| 64 | 64 | $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
| 65 | 65 | else |
| 66 | - $connection = @pg_connect( 'host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 66 | + $connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 67 | 67 | |
| 68 | 68 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 69 | 69 | if (!$connection) |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * |
| 88 | 88 | * @param string $type Indicates which additional file to load. ('extra', 'packages') |
| 89 | 89 | */ |
| 90 | -function db_extend ($type = 'extra') |
|
| 90 | +function db_extend($type = 'extra') |
|
| 91 | 91 | { |
| 92 | 92 | global $sourcedir, $db_type; |
| 93 | 93 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * @param string $db_prefix The database prefix |
| 104 | 104 | * @param string $db_name The database name |
| 105 | 105 | */ |
| 106 | -function db_fix_prefix (&$db_prefix, $db_name) |
|
| 106 | +function db_fix_prefix(&$db_prefix, $db_name) |
|
| 107 | 107 | { |
| 108 | 108 | return; |
| 109 | 109 | } |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | $replacement[$key] = 'null'; |
| 237 | 237 | if (!isValidIP($value)) |
| 238 | 238 | smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
| 239 | - $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
|
| 239 | + $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | return implode(', ', $replacement); |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | |
| 553 | 553 | // Log the error. |
| 554 | 554 | if (function_exists('log_error')) |
| 555 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" .$db_string : ''), 'database', $file, $line); |
|
| 555 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
| 556 | 556 | |
| 557 | 557 | // Nothing's defined yet... just die with it. |
| 558 | 558 | if (empty($context) || empty($txt)) |
@@ -688,31 +688,31 @@ discard block |
||
| 688 | 688 | static $pg_version; |
| 689 | 689 | static $replace_support; |
| 690 | 690 | |
| 691 | - if(empty($pg_version)) |
|
| 691 | + if (empty($pg_version)) |
|
| 692 | 692 | { |
| 693 | 693 | db_extend(); |
| 694 | 694 | //pg 9.5 got replace support |
| 695 | 695 | $pg_version = $smcFunc['db_get_version'](); |
| 696 | 696 | // if we got a Beta Version |
| 697 | 697 | if (stripos($pg_version, 'beta') !== false) |
| 698 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')).'.0'; |
|
| 698 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
| 699 | 699 | // or RC |
| 700 | 700 | if (stripos($pg_version, 'rc') !== false) |
| 701 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')).'.0'; |
|
| 701 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
| 702 | 702 | |
| 703 | - $replace_support = (version_compare($pg_version,'9.5.0','>=') ? true : false); |
|
| 703 | + $replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false); |
|
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | $count = 0; |
| 707 | 707 | $where = ''; |
| 708 | 708 | $count_pk = 0; |
| 709 | 709 | |
| 710 | - If($replace_support) |
|
| 710 | + If ($replace_support) |
|
| 711 | 711 | { |
| 712 | 712 | foreach ($columns as $columnName => $type) |
| 713 | 713 | { |
| 714 | 714 | //check pk fiel |
| 715 | - IF(in_array($columnName, $keys)) |
|
| 715 | + IF (in_array($columnName, $keys)) |
|
| 716 | 716 | { |
| 717 | 717 | $key_str .= ($count_pk > 0 ? ',' : ''); |
| 718 | 718 | $key_str .= $columnName; |
@@ -721,11 +721,11 @@ discard block |
||
| 721 | 721 | else //normal field |
| 722 | 722 | { |
| 723 | 723 | $col_str .= ($count > 0 ? ',' : ''); |
| 724 | - $col_str .= $columnName.' = EXCLUDED.'.$columnName; |
|
| 724 | + $col_str .= $columnName . ' = EXCLUDED.' . $columnName; |
|
| 725 | 725 | $count++; |
| 726 | 726 | } |
| 727 | 727 | } |
| 728 | - $replace = ' ON CONFLICT ('.$key_str.') DO UPDATE SET '.$col_str; |
|
| 728 | + $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
| 729 | 729 | } |
| 730 | 730 | else |
| 731 | 731 | { |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | $smcFunc['db_query']('', ' |
| 786 | 786 | INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '") |
| 787 | 787 | VALUES |
| 788 | - ' . $entry.$replace, |
|
| 788 | + ' . $entry . $replace, |
|
| 789 | 789 | array( |
| 790 | 790 | 'security_override' => true, |
| 791 | 791 | 'db_error_skip' => $method == 'ignore' || $table === $db_prefix . 'log_errors', |
@@ -880,7 +880,7 @@ discard block |
||
| 880 | 880 | * @param bool $translate_human_wildcards If true, turns human readable wildcards into SQL wildcards. |
| 881 | 881 | * @return string The escaped string |
| 882 | 882 | */ |
| 883 | -function smf_db_escape_wildcard_string($string, $translate_human_wildcards=false) |
|
| 883 | +function smf_db_escape_wildcard_string($string, $translate_human_wildcards = false) |
|
| 884 | 884 | { |
| 885 | 885 | $replacements = array( |
| 886 | 886 | '%' => '\%', |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 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']) || $smcFunc['db_fetch_assoc'] != 'postg_fetch_assoc') |
|
| 38 | - $smcFunc += array( |
|
| 38 | + if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'postg_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', |
@@ -59,11 +60,13 @@ discard block |
||
| 59 | 60 | 'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string', |
| 60 | 61 | 'db_is_resource' => 'is_resource', |
| 61 | 62 | ); |
| 63 | + } |
|
| 62 | 64 | |
| 63 | - if (!empty($db_options['persist'])) |
|
| 64 | - $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 65 | - else |
|
| 66 | - $connection = @pg_connect( 'host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 65 | + if (!empty($db_options['persist'])) { |
|
| 66 | + $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 67 | + } else { |
|
| 68 | + $connection = @pg_connect( 'host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 69 | + } |
|
| 67 | 70 | |
| 68 | 71 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 69 | 72 | if (!$connection) |
@@ -71,8 +74,7 @@ discard block |
||
| 71 | 74 | if (!empty($db_options['non_fatal'])) |
| 72 | 75 | { |
| 73 | 76 | return null; |
| 74 | - } |
|
| 75 | - else |
|
| 77 | + } else |
|
| 76 | 78 | { |
| 77 | 79 | display_db_error(); |
| 78 | 80 | } |
@@ -123,34 +125,42 @@ discard block |
||
| 123 | 125 | |
| 124 | 126 | list ($values, $connection) = $db_callback; |
| 125 | 127 | |
| 126 | - if ($matches[1] === 'db_prefix') |
|
| 127 | - return $db_prefix; |
|
| 128 | + if ($matches[1] === 'db_prefix') { |
|
| 129 | + return $db_prefix; |
|
| 130 | + } |
|
| 128 | 131 | |
| 129 | - if ($matches[1] === 'query_see_board') |
|
| 130 | - return $user_info['query_see_board']; |
|
| 132 | + if ($matches[1] === 'query_see_board') { |
|
| 133 | + return $user_info['query_see_board']; |
|
| 134 | + } |
|
| 131 | 135 | |
| 132 | - if ($matches[1] === 'query_wanna_see_board') |
|
| 133 | - return $user_info['query_wanna_see_board']; |
|
| 136 | + if ($matches[1] === 'query_wanna_see_board') { |
|
| 137 | + return $user_info['query_wanna_see_board']; |
|
| 138 | + } |
|
| 134 | 139 | |
| 135 | - if ($matches[1] === 'empty') |
|
| 136 | - return '\'\''; |
|
| 140 | + if ($matches[1] === 'empty') { |
|
| 141 | + return '\'\''; |
|
| 142 | + } |
|
| 137 | 143 | |
| 138 | - if (!isset($matches[2])) |
|
| 139 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 144 | + if (!isset($matches[2])) { |
|
| 145 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 146 | + } |
|
| 140 | 147 | |
| 141 | - if ($matches[1] === 'literal') |
|
| 142 | - return '\'' . pg_escape_string($matches[2]) . '\''; |
|
| 148 | + if ($matches[1] === 'literal') { |
|
| 149 | + return '\'' . pg_escape_string($matches[2]) . '\''; |
|
| 150 | + } |
|
| 143 | 151 | |
| 144 | - if (!isset($values[$matches[2]])) |
|
| 145 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 152 | + if (!isset($values[$matches[2]])) { |
|
| 153 | + 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__); |
|
| 154 | + } |
|
| 146 | 155 | |
| 147 | 156 | $replacement = $values[$matches[2]]; |
| 148 | 157 | |
| 149 | 158 | switch ($matches[1]) |
| 150 | 159 | { |
| 151 | 160 | case 'int': |
| 152 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 153 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 161 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
| 162 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 163 | + } |
|
| 154 | 164 | return (string) (int) $replacement; |
| 155 | 165 | break; |
| 156 | 166 | |
@@ -162,49 +172,55 @@ discard block |
||
| 162 | 172 | case 'array_int': |
| 163 | 173 | if (is_array($replacement)) |
| 164 | 174 | { |
| 165 | - if (empty($replacement)) |
|
| 166 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 175 | + if (empty($replacement)) { |
|
| 176 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 177 | + } |
|
| 167 | 178 | |
| 168 | 179 | foreach ($replacement as $key => $value) |
| 169 | 180 | { |
| 170 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 171 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 181 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 182 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 183 | + } |
|
| 172 | 184 | |
| 173 | 185 | $replacement[$key] = (string) (int) $value; |
| 174 | 186 | } |
| 175 | 187 | |
| 176 | 188 | return implode(', ', $replacement); |
| 189 | + } else { |
|
| 190 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 177 | 191 | } |
| 178 | - else |
|
| 179 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 180 | 192 | |
| 181 | 193 | break; |
| 182 | 194 | |
| 183 | 195 | case 'array_string': |
| 184 | 196 | if (is_array($replacement)) |
| 185 | 197 | { |
| 186 | - if (empty($replacement)) |
|
| 187 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 198 | + if (empty($replacement)) { |
|
| 199 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 200 | + } |
|
| 188 | 201 | |
| 189 | - foreach ($replacement as $key => $value) |
|
| 190 | - $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 202 | + foreach ($replacement as $key => $value) { |
|
| 203 | + $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 204 | + } |
|
| 191 | 205 | |
| 192 | 206 | return implode(', ', $replacement); |
| 207 | + } else { |
|
| 208 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 193 | 209 | } |
| 194 | - else |
|
| 195 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 196 | 210 | break; |
| 197 | 211 | |
| 198 | 212 | case 'date': |
| 199 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
| 200 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 201 | - else |
|
| 202 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 213 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 214 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 215 | + } else { |
|
| 216 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 217 | + } |
|
| 203 | 218 | break; |
| 204 | 219 | |
| 205 | 220 | case 'float': |
| 206 | - if (!is_numeric($replacement)) |
|
| 207 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 221 | + if (!is_numeric($replacement)) { |
|
| 222 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 223 | + } |
|
| 208 | 224 | return (string) (float) $replacement; |
| 209 | 225 | break; |
| 210 | 226 | |
@@ -217,32 +233,37 @@ discard block |
||
| 217 | 233 | break; |
| 218 | 234 | |
| 219 | 235 | case 'inet': |
| 220 | - if ($replacement == 'null' || $replacement == '') |
|
| 221 | - return 'null'; |
|
| 222 | - if (inet_pton($replacement) === false) |
|
| 223 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 236 | + if ($replacement == 'null' || $replacement == '') { |
|
| 237 | + return 'null'; |
|
| 238 | + } |
|
| 239 | + if (inet_pton($replacement) === false) { |
|
| 240 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 241 | + } |
|
| 224 | 242 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
| 225 | 243 | break; |
| 226 | 244 | |
| 227 | 245 | case 'array_inet': |
| 228 | 246 | if (is_array($replacement)) |
| 229 | 247 | { |
| 230 | - if (empty($replacement)) |
|
| 231 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 248 | + if (empty($replacement)) { |
|
| 249 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 250 | + } |
|
| 232 | 251 | |
| 233 | 252 | foreach ($replacement as $key => $value) |
| 234 | 253 | { |
| 235 | - if ($replacement == 'null' || $replacement == '') |
|
| 236 | - $replacement[$key] = 'null'; |
|
| 237 | - if (!isValidIP($value)) |
|
| 238 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 254 | + if ($replacement == 'null' || $replacement == '') { |
|
| 255 | + $replacement[$key] = 'null'; |
|
| 256 | + } |
|
| 257 | + if (!isValidIP($value)) { |
|
| 258 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 259 | + } |
|
| 239 | 260 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
| 240 | 261 | } |
| 241 | 262 | |
| 242 | 263 | return implode(', ', $replacement); |
| 264 | + } else { |
|
| 265 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 243 | 266 | } |
| 244 | - else |
|
| 245 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 246 | 267 | break; |
| 247 | 268 | |
| 248 | 269 | default: |
@@ -332,14 +353,16 @@ discard block |
||
| 332 | 353 | ), |
| 333 | 354 | ); |
| 334 | 355 | |
| 335 | - if (isset($replacements[$identifier])) |
|
| 336 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 356 | + if (isset($replacements[$identifier])) { |
|
| 357 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 358 | + } |
|
| 337 | 359 | |
| 338 | 360 | // Limits need to be a little different. |
| 339 | 361 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
| 340 | 362 | |
| 341 | - if (trim($db_string) == '') |
|
| 342 | - return false; |
|
| 363 | + if (trim($db_string) == '') { |
|
| 364 | + return false; |
|
| 365 | + } |
|
| 343 | 366 | |
| 344 | 367 | // Comments that are allowed in a query are preg_removed. |
| 345 | 368 | static $allowed_comments_from = array( |
@@ -359,8 +382,9 @@ discard block |
||
| 359 | 382 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 360 | 383 | $db_replace_result = 0; |
| 361 | 384 | |
| 362 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 363 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 385 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 386 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 387 | + } |
|
| 364 | 388 | |
| 365 | 389 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
| 366 | 390 | { |
@@ -381,8 +405,9 @@ discard block |
||
| 381 | 405 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 382 | 406 | |
| 383 | 407 | // Initialize $db_cache if not already initialized. |
| 384 | - if (!isset($db_cache)) |
|
| 385 | - $db_cache = array(); |
|
| 408 | + if (!isset($db_cache)) { |
|
| 409 | + $db_cache = array(); |
|
| 410 | + } |
|
| 386 | 411 | |
| 387 | 412 | if (!empty($_SESSION['debug_redirect'])) |
| 388 | 413 | { |
@@ -408,17 +433,18 @@ discard block |
||
| 408 | 433 | while (true) |
| 409 | 434 | { |
| 410 | 435 | $pos = strpos($db_string, '\'', $pos + 1); |
| 411 | - if ($pos === false) |
|
| 412 | - break; |
|
| 436 | + if ($pos === false) { |
|
| 437 | + break; |
|
| 438 | + } |
|
| 413 | 439 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
| 414 | 440 | |
| 415 | 441 | while (true) |
| 416 | 442 | { |
| 417 | 443 | $pos1 = strpos($db_string, '\'', $pos + 1); |
| 418 | 444 | $pos2 = strpos($db_string, '\\', $pos + 1); |
| 419 | - if ($pos1 === false) |
|
| 420 | - break; |
|
| 421 | - elseif ($pos2 == false || $pos2 > $pos1) |
|
| 445 | + if ($pos1 === false) { |
|
| 446 | + break; |
|
| 447 | + } elseif ($pos2 == false || $pos2 > $pos1) |
|
| 422 | 448 | { |
| 423 | 449 | $pos = $pos1; |
| 424 | 450 | break; |
@@ -434,26 +460,31 @@ discard block |
||
| 434 | 460 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 435 | 461 | |
| 436 | 462 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 437 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 438 | - $fail = true; |
|
| 463 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 464 | + $fail = true; |
|
| 465 | + } |
|
| 439 | 466 | // Trying to change passwords, slow us down, or something? |
| 440 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 441 | - $fail = true; |
|
| 442 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 443 | - $fail = true; |
|
| 467 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 468 | + $fail = true; |
|
| 469 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 470 | + $fail = true; |
|
| 471 | + } |
|
| 444 | 472 | |
| 445 | - if (!empty($fail) && function_exists('log_error')) |
|
| 446 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 473 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 474 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 475 | + } |
|
| 447 | 476 | } |
| 448 | 477 | |
| 449 | 478 | $db_last_result = @pg_query($connection, $db_string); |
| 450 | 479 | |
| 451 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
| 452 | - $db_last_result = smf_db_error($db_string, $connection); |
|
| 480 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
| 481 | + $db_last_result = smf_db_error($db_string, $connection); |
|
| 482 | + } |
|
| 453 | 483 | |
| 454 | 484 | // Debugging. |
| 455 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 456 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 485 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 486 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 487 | + } |
|
| 457 | 488 | |
| 458 | 489 | return $db_last_result; |
| 459 | 490 | } |
@@ -466,10 +497,11 @@ discard block |
||
| 466 | 497 | { |
| 467 | 498 | global $db_last_result, $db_replace_result; |
| 468 | 499 | |
| 469 | - if ($db_replace_result) |
|
| 470 | - return $db_replace_result; |
|
| 471 | - elseif ($result === null && !$db_last_result) |
|
| 472 | - return 0; |
|
| 500 | + if ($db_replace_result) { |
|
| 501 | + return $db_replace_result; |
|
| 502 | + } elseif ($result === null && !$db_last_result) { |
|
| 503 | + return 0; |
|
| 504 | + } |
|
| 473 | 505 | |
| 474 | 506 | return pg_affected_rows($result === null ? $db_last_result : $result); |
| 475 | 507 | } |
@@ -488,16 +520,18 @@ discard block |
||
| 488 | 520 | |
| 489 | 521 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
| 490 | 522 | |
| 491 | - if ($connection === false) |
|
| 492 | - $connection = $db_connection; |
|
| 523 | + if ($connection === false) { |
|
| 524 | + $connection = $db_connection; |
|
| 525 | + } |
|
| 493 | 526 | |
| 494 | 527 | // Try get the last ID for the auto increment field. |
| 495 | 528 | $request = $smcFunc['db_query']('', 'SELECT CURRVAL(\'' . $table . '_seq\') AS insertID', |
| 496 | 529 | array( |
| 497 | 530 | ) |
| 498 | 531 | ); |
| 499 | - if (!$request) |
|
| 500 | - return false; |
|
| 532 | + if (!$request) { |
|
| 533 | + return false; |
|
| 534 | + } |
|
| 501 | 535 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
| 502 | 536 | $smcFunc['db_free_result']($request); |
| 503 | 537 | |
@@ -518,12 +552,13 @@ discard block |
||
| 518 | 552 | // Decide which connection to use |
| 519 | 553 | $connection = $connection === null ? $db_connection : $connection; |
| 520 | 554 | |
| 521 | - if ($type == 'begin') |
|
| 522 | - return @pg_query($connection, 'BEGIN'); |
|
| 523 | - elseif ($type == 'rollback') |
|
| 524 | - return @pg_query($connection, 'ROLLBACK'); |
|
| 525 | - elseif ($type == 'commit') |
|
| 526 | - return @pg_query($connection, 'COMMIT'); |
|
| 555 | + if ($type == 'begin') { |
|
| 556 | + return @pg_query($connection, 'BEGIN'); |
|
| 557 | + } elseif ($type == 'rollback') { |
|
| 558 | + return @pg_query($connection, 'ROLLBACK'); |
|
| 559 | + } elseif ($type == 'commit') { |
|
| 560 | + return @pg_query($connection, 'COMMIT'); |
|
| 561 | + } |
|
| 527 | 562 | |
| 528 | 563 | return false; |
| 529 | 564 | } |
@@ -551,19 +586,22 @@ discard block |
||
| 551 | 586 | $query_error = @pg_last_error($connection); |
| 552 | 587 | |
| 553 | 588 | // Log the error. |
| 554 | - if (function_exists('log_error')) |
|
| 555 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" .$db_string : ''), 'database', $file, $line); |
|
| 589 | + if (function_exists('log_error')) { |
|
| 590 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" .$db_string : ''), 'database', $file, $line); |
|
| 591 | + } |
|
| 556 | 592 | |
| 557 | 593 | // Nothing's defined yet... just die with it. |
| 558 | - if (empty($context) || empty($txt)) |
|
| 559 | - die($query_error); |
|
| 594 | + if (empty($context) || empty($txt)) { |
|
| 595 | + die($query_error); |
|
| 596 | + } |
|
| 560 | 597 | |
| 561 | 598 | // Show an error message, if possible. |
| 562 | 599 | $context['error_title'] = $txt['database_error']; |
| 563 | - if (allowedTo('admin_forum')) |
|
| 564 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 565 | - else |
|
| 566 | - $context['error_message'] = $txt['try_again']; |
|
| 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']; |
|
| 604 | + } |
|
| 567 | 605 | |
| 568 | 606 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 569 | 607 | { |
@@ -585,12 +623,14 @@ discard block |
||
| 585 | 623 | { |
| 586 | 624 | global $db_row_count; |
| 587 | 625 | |
| 588 | - if ($counter !== false) |
|
| 589 | - return pg_fetch_row($request, $counter); |
|
| 626 | + if ($counter !== false) { |
|
| 627 | + return pg_fetch_row($request, $counter); |
|
| 628 | + } |
|
| 590 | 629 | |
| 591 | 630 | // Reset the row counter... |
| 592 | - if (!isset($db_row_count[(int) $request])) |
|
| 593 | - $db_row_count[(int) $request] = 0; |
|
| 631 | + if (!isset($db_row_count[(int) $request])) { |
|
| 632 | + $db_row_count[(int) $request] = 0; |
|
| 633 | + } |
|
| 594 | 634 | |
| 595 | 635 | // Return the right row. |
| 596 | 636 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -607,12 +647,14 @@ discard block |
||
| 607 | 647 | { |
| 608 | 648 | global $db_row_count; |
| 609 | 649 | |
| 610 | - if ($counter !== false) |
|
| 611 | - return pg_fetch_assoc($request, $counter); |
|
| 650 | + if ($counter !== false) { |
|
| 651 | + return pg_fetch_assoc($request, $counter); |
|
| 652 | + } |
|
| 612 | 653 | |
| 613 | 654 | // Reset the row counter... |
| 614 | - if (!isset($db_row_count[(int) $request])) |
|
| 615 | - $db_row_count[(int) $request] = 0; |
|
| 655 | + if (!isset($db_row_count[(int) $request])) { |
|
| 656 | + $db_row_count[(int) $request] = 0; |
|
| 657 | + } |
|
| 616 | 658 | |
| 617 | 659 | // Return the right row. |
| 618 | 660 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -664,11 +706,13 @@ discard block |
||
| 664 | 706 | |
| 665 | 707 | $replace = ''; |
| 666 | 708 | |
| 667 | - if (empty($data)) |
|
| 668 | - return; |
|
| 709 | + if (empty($data)) { |
|
| 710 | + return; |
|
| 711 | + } |
|
| 669 | 712 | |
| 670 | - if (!is_array($data[array_rand($data)])) |
|
| 671 | - $data = array($data); |
|
| 713 | + if (!is_array($data[array_rand($data)])) { |
|
| 714 | + $data = array($data); |
|
| 715 | + } |
|
| 672 | 716 | |
| 673 | 717 | // Replace the prefix holder with the actual prefix. |
| 674 | 718 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -694,11 +738,13 @@ discard block |
||
| 694 | 738 | //pg 9.5 got replace support |
| 695 | 739 | $pg_version = $smcFunc['db_get_version'](); |
| 696 | 740 | // if we got a Beta Version |
| 697 | - if (stripos($pg_version, 'beta') !== false) |
|
| 698 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')).'.0'; |
|
| 741 | + if (stripos($pg_version, 'beta') !== false) { |
|
| 742 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')).'.0'; |
|
| 743 | + } |
|
| 699 | 744 | // or RC |
| 700 | - if (stripos($pg_version, 'rc') !== false) |
|
| 701 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')).'.0'; |
|
| 745 | + if (stripos($pg_version, 'rc') !== false) { |
|
| 746 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')).'.0'; |
|
| 747 | + } |
|
| 702 | 748 | |
| 703 | 749 | $replace_support = (version_compare($pg_version,'9.5.0','>=') ? true : false); |
| 704 | 750 | } |
@@ -717,8 +763,7 @@ discard block |
||
| 717 | 763 | $key_str .= ($count_pk > 0 ? ',' : ''); |
| 718 | 764 | $key_str .= $columnName; |
| 719 | 765 | $count_pk++; |
| 720 | - } |
|
| 721 | - else //normal field |
|
| 766 | + } else //normal field |
|
| 722 | 767 | { |
| 723 | 768 | $col_str .= ($count > 0 ? ',' : ''); |
| 724 | 769 | $col_str .= $columnName.' = EXCLUDED.'.$columnName; |
@@ -726,20 +771,21 @@ discard block |
||
| 726 | 771 | } |
| 727 | 772 | } |
| 728 | 773 | $replace = ' ON CONFLICT ('.$key_str.') DO UPDATE SET '.$col_str; |
| 729 | - } |
|
| 730 | - else |
|
| 774 | + } else |
|
| 731 | 775 | { |
| 732 | 776 | foreach ($columns as $columnName => $type) |
| 733 | 777 | { |
| 734 | 778 | // Are we restricting the length? |
| 735 | - if (strpos($type, 'string-') !== false) |
|
| 736 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 737 | - else |
|
| 738 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 779 | + if (strpos($type, 'string-') !== false) { |
|
| 780 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 781 | + } else { |
|
| 782 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 783 | + } |
|
| 739 | 784 | |
| 740 | 785 | // A key? That's what we were looking for. |
| 741 | - if (in_array($columnName, $keys)) |
|
| 742 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 786 | + if (in_array($columnName, $keys)) { |
|
| 787 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 788 | + } |
|
| 743 | 789 | $count++; |
| 744 | 790 | } |
| 745 | 791 | |
@@ -765,10 +811,11 @@ discard block |
||
| 765 | 811 | foreach ($columns as $columnName => $type) |
| 766 | 812 | { |
| 767 | 813 | // Are we restricting the length? |
| 768 | - if (strpos($type, 'string-') !== false) |
|
| 769 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 770 | - else |
|
| 771 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 814 | + if (strpos($type, 'string-') !== false) { |
|
| 815 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 816 | + } else { |
|
| 817 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 818 | + } |
|
| 772 | 819 | } |
| 773 | 820 | $insertData = substr($insertData, 0, -2) . ')'; |
| 774 | 821 | |
@@ -777,11 +824,12 @@ discard block |
||
| 777 | 824 | |
| 778 | 825 | // Here's where the variables are injected to the query. |
| 779 | 826 | $insertRows = array(); |
| 780 | - foreach ($data as $dataRow) |
|
| 781 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 827 | + foreach ($data as $dataRow) { |
|
| 828 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 829 | + } |
|
| 782 | 830 | |
| 783 | - foreach ($insertRows as $entry) |
|
| 784 | - // Do the insert. |
|
| 831 | + foreach ($insertRows as $entry) { |
|
| 832 | + // Do the insert. |
|
| 785 | 833 | $smcFunc['db_query']('', ' |
| 786 | 834 | INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '") |
| 787 | 835 | VALUES |
@@ -792,11 +840,13 @@ discard block |
||
| 792 | 840 | ), |
| 793 | 841 | $connection |
| 794 | 842 | ); |
| 843 | + } |
|
| 795 | 844 | } |
| 796 | 845 | |
| 797 | - if ($priv_trans) |
|
| 798 | - $smcFunc['db_transaction']('commit', $connection); |
|
| 799 | -} |
|
| 846 | + if ($priv_trans) { |
|
| 847 | + $smcFunc['db_transaction']('commit', $connection); |
|
| 848 | + } |
|
| 849 | + } |
|
| 800 | 850 | |
| 801 | 851 | /** |
| 802 | 852 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -833,8 +883,9 @@ discard block |
||
| 833 | 883 | */ |
| 834 | 884 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 835 | 885 | { |
| 836 | - if (empty($log_message)) |
|
| 837 | - $log_message = $error_message; |
|
| 886 | + if (empty($log_message)) { |
|
| 887 | + $log_message = $error_message; |
|
| 888 | + } |
|
| 838 | 889 | |
| 839 | 890 | foreach (debug_backtrace() as $step) |
| 840 | 891 | { |
@@ -853,12 +904,14 @@ discard block |
||
| 853 | 904 | } |
| 854 | 905 | |
| 855 | 906 | // A special case - we want the file and line numbers for debugging. |
| 856 | - if ($error_type == 'return') |
|
| 857 | - return array($file, $line); |
|
| 907 | + if ($error_type == 'return') { |
|
| 908 | + return array($file, $line); |
|
| 909 | + } |
|
| 858 | 910 | |
| 859 | 911 | // Is always a critical error. |
| 860 | - if (function_exists('log_error')) |
|
| 861 | - log_error($log_message, 'critical', $file, $line); |
|
| 912 | + if (function_exists('log_error')) { |
|
| 913 | + log_error($log_message, 'critical', $file, $line); |
|
| 914 | + } |
|
| 862 | 915 | |
| 863 | 916 | if (function_exists('fatal_error')) |
| 864 | 917 | { |
@@ -866,12 +919,12 @@ discard block |
||
| 866 | 919 | |
| 867 | 920 | // Cannot continue... |
| 868 | 921 | exit; |
| 922 | + } elseif ($error_type) { |
|
| 923 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 924 | + } else { |
|
| 925 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 926 | + } |
|
| 869 | 927 | } |
| 870 | - elseif ($error_type) |
|
| 871 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 872 | - else |
|
| 873 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 874 | -} |
|
| 875 | 928 | |
| 876 | 929 | /** |
| 877 | 930 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -888,10 +941,11 @@ discard block |
||
| 888 | 941 | '\\' => '\\\\', |
| 889 | 942 | ); |
| 890 | 943 | |
| 891 | - if ($translate_human_wildcards) |
|
| 892 | - $replacements += array( |
|
| 944 | + if ($translate_human_wildcards) { |
|
| 945 | + $replacements += array( |
|
| 893 | 946 | '*' => '%', |
| 894 | 947 | ); |
| 948 | + } |
|
| 895 | 949 | |
| 896 | 950 | return strtr($string, $replacements); |
| 897 | 951 | } |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 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 | * Sets the SMF-style login cookie and session based on the id_member and password passed. |
@@ -43,8 +44,9 @@ discard block |
||
| 43 | 44 | $array = smf_json_decode($_COOKIE[$cookiename], true); |
| 44 | 45 | |
| 45 | 46 | // Legacy format |
| 46 | - if (is_null($array)) |
|
| 47 | - $array = safe_unserialize($_COOKIE[$cookiename]); |
|
| 47 | + if (is_null($array)) { |
|
| 48 | + $array = safe_unserialize($_COOKIE[$cookiename]); |
|
| 49 | + } |
|
| 48 | 50 | |
| 49 | 51 | // Out with the old, in with the new! |
| 50 | 52 | if (isset($array[3]) && $array[3] != $cookie_state) |
@@ -62,8 +64,9 @@ discard block |
||
| 62 | 64 | smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]); |
| 63 | 65 | |
| 64 | 66 | // If subdomain-independent cookies are on, unset the subdomain-dependent cookie too. |
| 65 | - if (empty($id) && !empty($modSettings['globalCookies'])) |
|
| 66 | - smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], ''); |
|
| 67 | + if (empty($id) && !empty($modSettings['globalCookies'])) { |
|
| 68 | + smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], ''); |
|
| 69 | + } |
|
| 67 | 70 | |
| 68 | 71 | // Any alias URLs? This is mainly for use with frames, etc. |
| 69 | 72 | if (!empty($modSettings['forum_alias_urls'])) |
@@ -79,8 +82,9 @@ discard block |
||
| 79 | 82 | |
| 80 | 83 | $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])); |
| 81 | 84 | |
| 82 | - if ($cookie_url[0] == '') |
|
| 83 | - $cookie_url[0] = strtok($alias, '/'); |
|
| 85 | + if ($cookie_url[0] == '') { |
|
| 86 | + $cookie_url[0] = strtok($alias, '/'); |
|
| 87 | + } |
|
| 84 | 88 | |
| 85 | 89 | smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]); |
| 86 | 90 | } |
@@ -126,8 +130,9 @@ discard block |
||
| 126 | 130 | $identifier = $cookiename . '_tfa'; |
| 127 | 131 | $cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2); |
| 128 | 132 | |
| 129 | - if ($preserve) |
|
| 130 | - $cookie_length = 81600 * 30; |
|
| 133 | + if ($preserve) { |
|
| 134 | + $cookie_length = 81600 * 30; |
|
| 135 | + } |
|
| 131 | 136 | |
| 132 | 137 | // Get the data and path to set it on. |
| 133 | 138 | $data = json_encode(empty($id) ? array(0, '', 0, $cookie_state, false) : array($id, $secret, time() + $cookie_length, $cookie_state, $preserve)); |
@@ -137,8 +142,9 @@ discard block |
||
| 137 | 142 | smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]); |
| 138 | 143 | |
| 139 | 144 | // If subdomain-independent cookies are on, unset the subdomain-dependent cookie too. |
| 140 | - if (empty($id) && !empty($modSettings['globalCookies'])) |
|
| 141 | - smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], ''); |
|
| 145 | + if (empty($id) && !empty($modSettings['globalCookies'])) { |
|
| 146 | + smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], ''); |
|
| 147 | + } |
|
| 142 | 148 | |
| 143 | 149 | $_COOKIE[$identifier] = $data; |
| 144 | 150 | } |
@@ -160,23 +166,28 @@ discard block |
||
| 160 | 166 | $parsed_url = parse_url($boardurl); |
| 161 | 167 | |
| 162 | 168 | // Is local cookies off? |
| 163 | - if (empty($parsed_url['path']) || !$local) |
|
| 164 | - $parsed_url['path'] = ''; |
|
| 169 | + if (empty($parsed_url['path']) || !$local) { |
|
| 170 | + $parsed_url['path'] = ''; |
|
| 171 | + } |
|
| 165 | 172 | |
| 166 | - if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) |
|
| 167 | - $parsed_url['host'] = $modSettings['globalCookiesDomain']; |
|
| 173 | + if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) { |
|
| 174 | + $parsed_url['host'] = $modSettings['globalCookiesDomain']; |
|
| 175 | + } |
|
| 168 | 176 | |
| 169 | 177 | // Globalize cookies across domains (filter out IP-addresses)? |
| 170 | - elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
| 171 | - $parsed_url['host'] = '.' . $parts[1]; |
|
| 178 | + elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
| 179 | + $parsed_url['host'] = '.' . $parts[1]; |
|
| 180 | + } |
|
| 172 | 181 | |
| 173 | 182 | // We shouldn't use a host at all if both options are off. |
| 174 | - elseif (!$local && !$global) |
|
| 175 | - $parsed_url['host'] = ''; |
|
| 183 | + elseif (!$local && !$global) { |
|
| 184 | + $parsed_url['host'] = ''; |
|
| 185 | + } |
|
| 176 | 186 | |
| 177 | 187 | // The host also shouldn't be set if there aren't any dots in it. |
| 178 | - elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) |
|
| 179 | - $parsed_url['host'] = ''; |
|
| 188 | + elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) { |
|
| 189 | + $parsed_url['host'] = ''; |
|
| 190 | + } |
|
| 180 | 191 | |
| 181 | 192 | return array($parsed_url['host'], $parsed_url['path'] . '/'); |
| 182 | 193 | } |
@@ -195,8 +206,9 @@ discard block |
||
| 195 | 206 | createToken('login'); |
| 196 | 207 | |
| 197 | 208 | // Never redirect to an attachment |
| 198 | - if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) |
|
| 199 | - $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
| 209 | + if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) { |
|
| 210 | + $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
| 211 | + } |
|
| 200 | 212 | |
| 201 | 213 | $context['sub_template'] = 'kick_guest'; |
| 202 | 214 | $context['page_title'] = $txt['login']; |
@@ -251,10 +263,12 @@ discard block |
||
| 251 | 263 | $txt['security_wrong'] = sprintf($txt['security_wrong'], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $txt['unknown'], $_SERVER['HTTP_USER_AGENT'], $user_info['ip']); |
| 252 | 264 | log_error($txt['security_wrong'], 'critical'); |
| 253 | 265 | |
| 254 | - if (isset($_POST[$type . '_hash_pass'])) |
|
| 255 | - unset($_POST[$type . '_hash_pass']); |
|
| 256 | - if (isset($_POST[$type . '_pass'])) |
|
| 257 | - unset($_POST[$type . '_pass']); |
|
| 266 | + if (isset($_POST[$type . '_hash_pass'])) { |
|
| 267 | + unset($_POST[$type . '_hash_pass']); |
|
| 268 | + } |
|
| 269 | + if (isset($_POST[$type . '_pass'])) { |
|
| 270 | + unset($_POST[$type . '_pass']); |
|
| 271 | + } |
|
| 258 | 272 | |
| 259 | 273 | $context['incorrect_password'] = true; |
| 260 | 274 | } |
@@ -267,15 +281,17 @@ discard block |
||
| 267 | 281 | |
| 268 | 282 | // Now go through $_POST. Make sure the session hash is sent. |
| 269 | 283 | $_POST[$context['session_var']] = $context['session_id']; |
| 270 | - foreach ($_POST as $k => $v) |
|
| 271 | - $context['post_data'] .= adminLogin_outputPostVars($k, $v); |
|
| 284 | + foreach ($_POST as $k => $v) { |
|
| 285 | + $context['post_data'] .= adminLogin_outputPostVars($k, $v); |
|
| 286 | + } |
|
| 272 | 287 | |
| 273 | 288 | // Now we'll use the admin_login sub template of the Login template. |
| 274 | 289 | $context['sub_template'] = 'admin_login'; |
| 275 | 290 | |
| 276 | 291 | // And title the page something like "Login". |
| 277 | - if (!isset($context['page_title'])) |
|
| 278 | - $context['page_title'] = $txt['login']; |
|
| 292 | + if (!isset($context['page_title'])) { |
|
| 293 | + $context['page_title'] = $txt['login']; |
|
| 294 | + } |
|
| 279 | 295 | |
| 280 | 296 | // The type of action. |
| 281 | 297 | $context['sessionCheckType'] = $type; |
@@ -298,14 +314,15 @@ discard block |
||
| 298 | 314 | { |
| 299 | 315 | global $smcFunc; |
| 300 | 316 | |
| 301 | - if (!is_array($v)) |
|
| 302 | - return ' |
|
| 317 | + if (!is_array($v)) { |
|
| 318 | + return ' |
|
| 303 | 319 | <input type="hidden" name="' . $smcFunc['htmlspecialchars']($k) . '" value="' . strtr($v, array('"' => '"', '<' => '<', '>' => '>')) . '">'; |
| 304 | - else |
|
| 320 | + } else |
|
| 305 | 321 | { |
| 306 | 322 | $ret = ''; |
| 307 | - foreach ($v as $k2 => $v2) |
|
| 308 | - $ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2); |
|
| 323 | + foreach ($v as $k2 => $v2) { |
|
| 324 | + $ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2); |
|
| 325 | + } |
|
| 309 | 326 | |
| 310 | 327 | return $ret; |
| 311 | 328 | } |
@@ -332,18 +349,20 @@ discard block |
||
| 332 | 349 | foreach ($get as $k => $v) |
| 333 | 350 | { |
| 334 | 351 | // Only if it's not already in the $scripturl! |
| 335 | - if (!isset($temp[$k])) |
|
| 336 | - $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
| 352 | + if (!isset($temp[$k])) { |
|
| 353 | + $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
| 354 | + } |
|
| 337 | 355 | // If it changed, put it out there, but with an ampersand. |
| 338 | - elseif ($temp[$k] != $get[$k]) |
|
| 339 | - $query_string .= urlencode($k) . '=' . urlencode($v) . '&'; |
|
| 356 | + elseif ($temp[$k] != $get[$k]) { |
|
| 357 | + $query_string .= urlencode($k) . '=' . urlencode($v) . '&'; |
|
| 358 | + } |
|
| 340 | 359 | } |
| 341 | - } |
|
| 342 | - else |
|
| 360 | + } else |
|
| 343 | 361 | { |
| 344 | 362 | // Add up all the data from $_GET into get_data. |
| 345 | - foreach ($get as $k => $v) |
|
| 346 | - $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
| 363 | + foreach ($get as $k => $v) { |
|
| 364 | + $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
| 365 | + } |
|
| 347 | 366 | } |
| 348 | 367 | |
| 349 | 368 | $query_string = substr($query_string, 0, -1); |
@@ -366,8 +385,9 @@ discard block |
||
| 366 | 385 | global $scripturl, $user_info, $smcFunc; |
| 367 | 386 | |
| 368 | 387 | // If it's not already an array, make it one. |
| 369 | - if (!is_array($names)) |
|
| 370 | - $names = explode(',', $names); |
|
| 388 | + if (!is_array($names)) { |
|
| 389 | + $names = explode(',', $names); |
|
| 390 | + } |
|
| 371 | 391 | |
| 372 | 392 | $maybe_email = false; |
| 373 | 393 | foreach ($names as $i => $name) |
@@ -378,10 +398,11 @@ discard block |
||
| 378 | 398 | $maybe_email |= strpos($name, '@') !== false; |
| 379 | 399 | |
| 380 | 400 | // Make it so standard wildcards will work. (* and ?) |
| 381 | - if ($use_wildcards) |
|
| 382 | - $names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => ''')); |
|
| 383 | - else |
|
| 384 | - $names[$i] = strtr($names[$i], array('\'' => ''')); |
|
| 401 | + if ($use_wildcards) { |
|
| 402 | + $names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => ''')); |
|
| 403 | + } else { |
|
| 404 | + $names[$i] = strtr($names[$i], array('\'' => ''')); |
|
| 405 | + } |
|
| 385 | 406 | } |
| 386 | 407 | |
| 387 | 408 | // What are we using to compare? |
@@ -391,11 +412,12 @@ discard block |
||
| 391 | 412 | $results = array(); |
| 392 | 413 | |
| 393 | 414 | // This ensures you can't search someones email address if you can't see it. |
| 394 | - if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) |
|
| 395 | - $email_condition = ' |
|
| 415 | + if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) { |
|
| 416 | + $email_condition = ' |
|
| 396 | 417 | OR (email_address ' . $comparison . ' \'' . implode( '\') OR (email_address ' . $comparison . ' \'', $names) . '\')'; |
| 397 | - else |
|
| 398 | - $email_condition = ''; |
|
| 418 | + } else { |
|
| 419 | + $email_condition = ''; |
|
| 420 | + } |
|
| 399 | 421 | |
| 400 | 422 | // Get the case of the columns right - but only if we need to as things like MySQL will go slow needlessly otherwise. |
| 401 | 423 | $member_name = $smcFunc['db_case_sensitive'] ? 'LOWER(member_name)' : 'member_name'; |
@@ -453,10 +475,11 @@ discard block |
||
| 453 | 475 | $context['template_layers'] = array(); |
| 454 | 476 | $context['sub_template'] = 'find_members'; |
| 455 | 477 | |
| 456 | - if (isset($_REQUEST['search'])) |
|
| 457 | - $context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES); |
|
| 458 | - else |
|
| 459 | - $_REQUEST['start'] = 0; |
|
| 478 | + if (isset($_REQUEST['search'])) { |
|
| 479 | + $context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES); |
|
| 480 | + } else { |
|
| 481 | + $_REQUEST['start'] = 0; |
|
| 482 | + } |
|
| 460 | 483 | |
| 461 | 484 | // Allow the user to pass the input to be added to to the box. |
| 462 | 485 | $context['input_box_name'] = isset($_REQUEST['input']) && preg_match('~^[\w-]+$~', $_REQUEST['input']) === 1 ? $_REQUEST['input'] : 'to'; |
@@ -497,10 +520,10 @@ discard block |
||
| 497 | 520 | ); |
| 498 | 521 | |
| 499 | 522 | $context['results'] = array_slice($context['results'], $_REQUEST['start'], 7); |
| 523 | + } else { |
|
| 524 | + $context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']); |
|
| 525 | + } |
|
| 500 | 526 | } |
| 501 | - else |
|
| 502 | - $context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']); |
|
| 503 | -} |
|
| 504 | 527 | |
| 505 | 528 | /** |
| 506 | 529 | * Outputs each member name on its own line. |
@@ -516,8 +539,9 @@ discard block |
||
| 516 | 539 | $_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search'])); |
| 517 | 540 | $_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&' => '&')); |
| 518 | 541 | |
| 519 | - if (function_exists('iconv')) |
|
| 520 | - header('Content-Type: text/plain; charset=UTF-8'); |
|
| 542 | + if (function_exists('iconv')) { |
|
| 543 | + header('Content-Type: text/plain; charset=UTF-8'); |
|
| 544 | + } |
|
| 521 | 545 | |
| 522 | 546 | $request = $smcFunc['db_query']('', ' |
| 523 | 547 | SELECT real_name |
@@ -537,14 +561,16 @@ discard block |
||
| 537 | 561 | if (function_exists('iconv')) |
| 538 | 562 | { |
| 539 | 563 | $utf8 = iconv($txt['lang_character_set'], 'UTF-8', $row['real_name']); |
| 540 | - if ($utf8) |
|
| 541 | - $row['real_name'] = $utf8; |
|
| 564 | + if ($utf8) { |
|
| 565 | + $row['real_name'] = $utf8; |
|
| 566 | + } |
|
| 542 | 567 | } |
| 543 | 568 | |
| 544 | 569 | $row['real_name'] = strtr($row['real_name'], array('&' => '&', '<' => '<', '>' => '>', '"' => '"')); |
| 545 | 570 | |
| 546 | - if (preg_match('~&#\d+;~', $row['real_name']) != 0) |
|
| 547 | - $row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']); |
|
| 571 | + if (preg_match('~&#\d+;~', $row['real_name']) != 0) { |
|
| 572 | + $row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']); |
|
| 573 | + } |
|
| 548 | 574 | |
| 549 | 575 | echo $row['real_name'], "\n"; |
| 550 | 576 | } |
@@ -601,9 +627,9 @@ discard block |
||
| 601 | 627 | |
| 602 | 628 | // Update the database... |
| 603 | 629 | updateMemberData($memID, array('member_name' => $user, 'passwd' => $newPassword_sha1)); |
| 630 | + } else { |
|
| 631 | + updateMemberData($memID, array('passwd' => $newPassword_sha1)); |
|
| 604 | 632 | } |
| 605 | - else |
|
| 606 | - updateMemberData($memID, array('passwd' => $newPassword_sha1)); |
|
| 607 | 633 | |
| 608 | 634 | call_integration_hook('integrate_reset_pass', array($old_user, $user, $newPassword)); |
| 609 | 635 | |
@@ -634,31 +660,37 @@ discard block |
||
| 634 | 660 | $errors = array(); |
| 635 | 661 | |
| 636 | 662 | // Don't use too long a name. |
| 637 | - if ($smcFunc['strlen']($username) > 25) |
|
| 638 | - $errors[] = array('lang', 'error_long_name'); |
|
| 663 | + if ($smcFunc['strlen']($username) > 25) { |
|
| 664 | + $errors[] = array('lang', 'error_long_name'); |
|
| 665 | + } |
|
| 639 | 666 | |
| 640 | 667 | // No name?! How can you register with no name? |
| 641 | - if ($username == '') |
|
| 642 | - $errors[] = array('lang', 'need_username'); |
|
| 668 | + if ($username == '') { |
|
| 669 | + $errors[] = array('lang', 'need_username'); |
|
| 670 | + } |
|
| 643 | 671 | |
| 644 | 672 | // Only these characters are permitted. |
| 645 | - if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) |
|
| 646 | - $errors[] = array('lang', 'error_invalid_characters_username'); |
|
| 673 | + if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) { |
|
| 674 | + $errors[] = array('lang', 'error_invalid_characters_username'); |
|
| 675 | + } |
|
| 647 | 676 | |
| 648 | - if (stristr($username, $txt['guest_title']) !== false) |
|
| 649 | - $errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title'])); |
|
| 677 | + if (stristr($username, $txt['guest_title']) !== false) { |
|
| 678 | + $errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title'])); |
|
| 679 | + } |
|
| 650 | 680 | |
| 651 | 681 | if ($check_reserved_name) |
| 652 | 682 | { |
| 653 | 683 | require_once($sourcedir . '/Subs-Members.php'); |
| 654 | - if (isReservedName($username, $memID, false)) |
|
| 655 | - $errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']); |
|
| 684 | + if (isReservedName($username, $memID, false)) { |
|
| 685 | + $errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']); |
|
| 686 | + } |
|
| 656 | 687 | } |
| 657 | 688 | |
| 658 | - if ($return_error) |
|
| 659 | - return $errors; |
|
| 660 | - elseif (empty($errors)) |
|
| 661 | - return null; |
|
| 689 | + if ($return_error) { |
|
| 690 | + return $errors; |
|
| 691 | + } elseif (empty($errors)) { |
|
| 692 | + return null; |
|
| 693 | + } |
|
| 662 | 694 | |
| 663 | 695 | loadLanguage('Errors'); |
| 664 | 696 | $error = $errors[0]; |
@@ -684,22 +716,26 @@ discard block |
||
| 684 | 716 | global $modSettings, $smcFunc; |
| 685 | 717 | |
| 686 | 718 | // Perform basic requirements first. |
| 687 | - if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) |
|
| 688 | - return 'short'; |
|
| 719 | + if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) { |
|
| 720 | + return 'short'; |
|
| 721 | + } |
|
| 689 | 722 | |
| 690 | 723 | // Is this enough? |
| 691 | - if (empty($modSettings['password_strength'])) |
|
| 692 | - return null; |
|
| 724 | + if (empty($modSettings['password_strength'])) { |
|
| 725 | + return null; |
|
| 726 | + } |
|
| 693 | 727 | |
| 694 | 728 | // Otherwise, perform the medium strength test - checking if password appears in the restricted string. |
| 695 | - if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) |
|
| 696 | - return 'restricted_words'; |
|
| 697 | - elseif ($smcFunc['strpos']($password, $username) !== false) |
|
| 698 | - return 'restricted_words'; |
|
| 729 | + if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) { |
|
| 730 | + return 'restricted_words'; |
|
| 731 | + } elseif ($smcFunc['strpos']($password, $username) !== false) { |
|
| 732 | + return 'restricted_words'; |
|
| 733 | + } |
|
| 699 | 734 | |
| 700 | 735 | // If just medium, we're done. |
| 701 | - if ($modSettings['password_strength'] == 1) |
|
| 702 | - return null; |
|
| 736 | + if ($modSettings['password_strength'] == 1) { |
|
| 737 | + return null; |
|
| 738 | + } |
|
| 703 | 739 | |
| 704 | 740 | // Otherwise, hard test next, check for numbers and letters, uppercase too. |
| 705 | 741 | $good = preg_match('~(\D\d|\d\D)~', $password) != 0; |
@@ -731,14 +767,16 @@ discard block |
||
| 731 | 767 | ) |
| 732 | 768 | ); |
| 733 | 769 | $groups = array(); |
| 734 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 735 | - $groups[] = $row['id_group']; |
|
| 770 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 771 | + $groups[] = $row['id_group']; |
|
| 772 | + } |
|
| 736 | 773 | $smcFunc['db_free_result']($request); |
| 737 | 774 | |
| 738 | - if (empty($groups)) |
|
| 739 | - $group_query = '0=1'; |
|
| 740 | - else |
|
| 741 | - $group_query = 'id_group IN (' . implode(',', $groups) . ')'; |
|
| 775 | + if (empty($groups)) { |
|
| 776 | + $group_query = '0=1'; |
|
| 777 | + } else { |
|
| 778 | + $group_query = 'id_group IN (' . implode(',', $groups) . ')'; |
|
| 779 | + } |
|
| 742 | 780 | } |
| 743 | 781 | |
| 744 | 782 | // Then, same again, just the boards this time! |
@@ -748,10 +786,11 @@ discard block |
||
| 748 | 786 | { |
| 749 | 787 | $boards = boardsAllowedTo('moderate_board', true); |
| 750 | 788 | |
| 751 | - if (empty($boards)) |
|
| 752 | - $board_query = '0=1'; |
|
| 753 | - else |
|
| 754 | - $board_query = 'id_board IN (' . implode(',', $boards) . ')'; |
|
| 789 | + if (empty($boards)) { |
|
| 790 | + $board_query = '0=1'; |
|
| 791 | + } else { |
|
| 792 | + $board_query = 'id_board IN (' . implode(',', $boards) . ')'; |
|
| 793 | + } |
|
| 755 | 794 | } |
| 756 | 795 | |
| 757 | 796 | // What boards are they the moderator of? |
@@ -766,8 +805,9 @@ discard block |
||
| 766 | 805 | 'current_member' => $user_info['id'], |
| 767 | 806 | ) |
| 768 | 807 | ); |
| 769 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 770 | - $boards_mod[] = $row['id_board']; |
|
| 808 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 809 | + $boards_mod[] = $row['id_board']; |
|
| 810 | + } |
|
| 771 | 811 | $smcFunc['db_free_result']($request); |
| 772 | 812 | |
| 773 | 813 | // Can any of the groups they're in moderate any of the boards? |
@@ -779,8 +819,9 @@ discard block |
||
| 779 | 819 | 'groups' => $user_info['groups'], |
| 780 | 820 | ) |
| 781 | 821 | ); |
| 782 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 783 | - $boards_mod[] = $row['id_board']; |
|
| 822 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 823 | + $boards_mod[] = $row['id_board']; |
|
| 824 | + } |
|
| 784 | 825 | $smcFunc['db_free_result']($request); |
| 785 | 826 | |
| 786 | 827 | // Just in case we've got duplicates here... |
@@ -825,10 +866,12 @@ discard block |
||
| 825 | 866 | global $modSettings; |
| 826 | 867 | |
| 827 | 868 | // In case a customization wants to override the default settings |
| 828 | - if ($httponly === null) |
|
| 829 | - $httponly = !empty($modSettings['httponlyCookies']); |
|
| 830 | - if ($secure === null) |
|
| 831 | - $secure = !empty($modSettings['secureCookies']); |
|
| 869 | + if ($httponly === null) { |
|
| 870 | + $httponly = !empty($modSettings['httponlyCookies']); |
|
| 871 | + } |
|
| 872 | + if ($secure === null) { |
|
| 873 | + $secure = !empty($modSettings['secureCookies']); |
|
| 874 | + } |
|
| 832 | 875 | |
| 833 | 876 | // Intercept cookie? |
| 834 | 877 | call_integration_hook('integrate_cookie', array($name, $value, $expire, $path, $domain, $secure, $httponly)); |
@@ -848,8 +891,9 @@ discard block |
||
| 848 | 891 | function hash_password($username, $password, $cost = null) |
| 849 | 892 | { |
| 850 | 893 | global $sourcedir, $smcFunc, $modSettings; |
| 851 | - if (!function_exists('password_hash')) |
|
| 852 | - require_once($sourcedir . '/Subs-Password.php'); |
|
| 894 | + if (!function_exists('password_hash')) { |
|
| 895 | + require_once($sourcedir . '/Subs-Password.php'); |
|
| 896 | + } |
|
| 853 | 897 | |
| 854 | 898 | $cost = empty($cost) ? (empty($modSettings['bcrypt_hash_cost']) ? 10 : $modSettings['bcrypt_hash_cost']) : $cost; |
| 855 | 899 | |
@@ -881,8 +925,9 @@ discard block |
||
| 881 | 925 | function hash_verify_password($username, $password, $hash) |
| 882 | 926 | { |
| 883 | 927 | global $sourcedir, $smcFunc; |
| 884 | - if (!function_exists('password_verify')) |
|
| 885 | - require_once($sourcedir . '/Subs-Password.php'); |
|
| 928 | + if (!function_exists('password_verify')) { |
|
| 929 | + require_once($sourcedir . '/Subs-Password.php'); |
|
| 930 | + } |
|
| 886 | 931 | |
| 887 | 932 | return password_verify($smcFunc['strtolower']($username) . $password, $hash); |
| 888 | 933 | } |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * @version 2.1 Beta 3 |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -if (!defined('SMF')) |
|
| 18 | +if (!defined('SMF')) { |
|
| 19 | 19 | die('No direct access...'); |
| 20 | +} |
|
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * This helps organize things... |
@@ -37,13 +38,14 @@ discard block |
||
| 37 | 38 | |
| 38 | 39 | loadLanguage('PersonalMessage+Drafts'); |
| 39 | 40 | |
| 40 | - if (!isset($_REQUEST['xml'])) |
|
| 41 | - loadTemplate('PersonalMessage'); |
|
| 41 | + if (!isset($_REQUEST['xml'])) { |
|
| 42 | + loadTemplate('PersonalMessage'); |
|
| 43 | + } |
|
| 42 | 44 | |
| 43 | 45 | // Load up the members maximum message capacity. |
| 44 | - if ($user_info['is_admin']) |
|
| 45 | - $context['message_limit'] = 0; |
|
| 46 | - elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null) |
|
| 46 | + if ($user_info['is_admin']) { |
|
| 47 | + $context['message_limit'] = 0; |
|
| 48 | + } elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null) |
|
| 47 | 49 | { |
| 48 | 50 | // @todo Why do we do this? It seems like if they have any limit we should use it. |
| 49 | 51 | $request = $smcFunc['db_query']('', ' |
@@ -78,8 +80,9 @@ discard block |
||
| 78 | 80 | } |
| 79 | 81 | |
| 80 | 82 | // a previous message was sent successfully? show a small indication. |
| 81 | - if (isset($_GET['done']) && ($_GET['done'] == 'sent')) |
|
| 82 | - $context['pm_sent'] = true; |
|
| 83 | + if (isset($_GET['done']) && ($_GET['done'] == 'sent')) { |
|
| 84 | + $context['pm_sent'] = true; |
|
| 85 | + } |
|
| 83 | 86 | |
| 84 | 87 | $context['labels'] = array(); |
| 85 | 88 | |
@@ -210,11 +213,11 @@ discard block |
||
| 210 | 213 | { |
| 211 | 214 | $_REQUEST['sa'] = ''; |
| 212 | 215 | MessageFolder(); |
| 213 | - } |
|
| 214 | - else |
|
| 216 | + } else |
|
| 215 | 217 | { |
| 216 | - if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup') |
|
| 217 | - messageIndexBar($_REQUEST['sa']); |
|
| 218 | + if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup') { |
|
| 219 | + messageIndexBar($_REQUEST['sa']); |
|
| 220 | + } |
|
| 218 | 221 | |
| 219 | 222 | call_helper($subActions[$_REQUEST['sa']]); |
| 220 | 223 | } |
@@ -291,16 +294,17 @@ discard block |
||
| 291 | 294 | ); |
| 292 | 295 | |
| 293 | 296 | // Handle labels. |
| 294 | - if (empty($context['currently_using_labels'])) |
|
| 295 | - unset($pm_areas['labels']); |
|
| 296 | - else |
|
| 297 | + if (empty($context['currently_using_labels'])) { |
|
| 298 | + unset($pm_areas['labels']); |
|
| 299 | + } else |
|
| 297 | 300 | { |
| 298 | 301 | // Note we send labels by id as it will have less problems in the querystring. |
| 299 | 302 | $unread_in_labels = 0; |
| 300 | 303 | foreach ($context['labels'] as $label) |
| 301 | 304 | { |
| 302 | - if ($label['id'] == -1) |
|
| 303 | - continue; |
|
| 305 | + if ($label['id'] == -1) { |
|
| 306 | + continue; |
|
| 307 | + } |
|
| 304 | 308 | |
| 305 | 309 | // Count the amount of unread items in labels. |
| 306 | 310 | $unread_in_labels += $label['unread_messages']; |
@@ -314,8 +318,9 @@ discard block |
||
| 314 | 318 | ); |
| 315 | 319 | } |
| 316 | 320 | |
| 317 | - if (!empty($unread_in_labels)) |
|
| 318 | - $pm_areas['labels']['title'] .= ' <span class="amt">' . $unread_in_labels . '</span>'; |
|
| 321 | + if (!empty($unread_in_labels)) { |
|
| 322 | + $pm_areas['labels']['title'] .= ' <span class="amt">' . $unread_in_labels . '</span>'; |
|
| 323 | + } |
|
| 319 | 324 | } |
| 320 | 325 | |
| 321 | 326 | $pm_areas['folders']['areas']['inbox']['unread_messages'] = &$context['labels'][-1]['unread_messages']; |
@@ -356,8 +361,9 @@ discard block |
||
| 356 | 361 | unset($pm_areas); |
| 357 | 362 | |
| 358 | 363 | // No menu means no access. |
| 359 | - if (!$pm_include_data && (!$user_info['is_guest'] || validateSession())) |
|
| 360 | - fatal_lang_error('no_access', false); |
|
| 364 | + if (!$pm_include_data && (!$user_info['is_guest'] || validateSession())) { |
|
| 365 | + fatal_lang_error('no_access', false); |
|
| 366 | + } |
|
| 361 | 367 | |
| 362 | 368 | // Make a note of the Unique ID for this menu. |
| 363 | 369 | $context['pm_menu_id'] = $context['max_menu_id']; |
@@ -368,9 +374,10 @@ discard block |
||
| 368 | 374 | $context['menu_item_selected'] = $current_area; |
| 369 | 375 | |
| 370 | 376 | // Set the template for this area and add the profile layer. |
| 371 | - if (!isset($_REQUEST['xml'])) |
|
| 372 | - $context['template_layers'][] = 'pm'; |
|
| 373 | -} |
|
| 377 | + if (!isset($_REQUEST['xml'])) { |
|
| 378 | + $context['template_layers'][] = 'pm'; |
|
| 379 | + } |
|
| 380 | + } |
|
| 374 | 381 | |
| 375 | 382 | /** |
| 376 | 383 | * The popup for when we ask for the popup from the user. |
@@ -402,8 +409,9 @@ discard block |
||
| 402 | 409 | ) |
| 403 | 410 | ); |
| 404 | 411 | $pms = array(); |
| 405 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 406 | - $pms[] = $row[0]; |
|
| 412 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 413 | + $pms[] = $row[0]; |
|
| 414 | + } |
|
| 407 | 415 | $smcFunc['db_free_result']($request); |
| 408 | 416 | |
| 409 | 417 | if (!empty($pms)) |
@@ -431,8 +439,9 @@ discard block |
||
| 431 | 439 | ); |
| 432 | 440 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 433 | 441 | { |
| 434 | - if (!empty($row['id_member_from'])) |
|
| 435 | - $senders[] = $row['id_member_from']; |
|
| 442 | + if (!empty($row['id_member_from'])) { |
|
| 443 | + $senders[] = $row['id_member_from']; |
|
| 444 | + } |
|
| 436 | 445 | |
| 437 | 446 | $row['replied_to_you'] = $row['id_pm'] != $row['id_pm_head']; |
| 438 | 447 | $row['time'] = timeformat($row['timestamp']); |
@@ -442,13 +451,15 @@ discard block |
||
| 442 | 451 | $smcFunc['db_free_result']($request); |
| 443 | 452 | |
| 444 | 453 | $senders = loadMemberData($senders); |
| 445 | - foreach ($senders as $member) |
|
| 446 | - loadMemberContext($member); |
|
| 454 | + foreach ($senders as $member) { |
|
| 455 | + loadMemberContext($member); |
|
| 456 | + } |
|
| 447 | 457 | |
| 448 | 458 | // Having loaded everyone, attach them to the PMs. |
| 449 | - foreach ($context['unread_pms'] as $id_pm => $details) |
|
| 450 | - if (!empty($memberContext[$details['id_member_from']])) |
|
| 459 | + foreach ($context['unread_pms'] as $id_pm => $details) { |
|
| 460 | + if (!empty($memberContext[$details['id_member_from']])) |
|
| 451 | 461 | $context['unread_pms'][$id_pm]['member'] = &$memberContext[$details['id_member_from']]; |
| 462 | + } |
|
| 452 | 463 | } |
| 453 | 464 | } |
| 454 | 465 | |
@@ -468,12 +479,13 @@ discard block |
||
| 468 | 479 | } |
| 469 | 480 | |
| 470 | 481 | // Make sure the starting location is valid. |
| 471 | - if (isset($_GET['start']) && $_GET['start'] != 'new') |
|
| 472 | - $_GET['start'] = (int) $_GET['start']; |
|
| 473 | - elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first'])) |
|
| 474 | - $_GET['start'] = 0; |
|
| 475 | - else |
|
| 476 | - $_GET['start'] = 'new'; |
|
| 482 | + if (isset($_GET['start']) && $_GET['start'] != 'new') { |
|
| 483 | + $_GET['start'] = (int) $_GET['start']; |
|
| 484 | + } elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first'])) { |
|
| 485 | + $_GET['start'] = 0; |
|
| 486 | + } else { |
|
| 487 | + $_GET['start'] = 'new'; |
|
| 488 | + } |
|
| 477 | 489 | |
| 478 | 490 | // Set up some basic theme stuff. |
| 479 | 491 | $context['from_or_to'] = $context['folder'] != 'sent' ? 'from' : 'to'; |
@@ -490,8 +502,7 @@ discard block |
||
| 490 | 502 | { |
| 491 | 503 | $labelQuery = ' |
| 492 | 504 | AND pmr.in_inbox = 1'; |
| 493 | - } |
|
| 494 | - elseif ($context['folder'] != 'sent') |
|
| 505 | + } elseif ($context['folder'] != 'sent') |
|
| 495 | 506 | { |
| 496 | 507 | $labelJoin = ' |
| 497 | 508 | INNER JOIN {db_prefix}pm_labeled_messages AS pl ON (pl.id_pm = pmr.id_pm)'; |
@@ -533,22 +544,24 @@ discard block |
||
| 533 | 544 | $txt['delete_all'] = str_replace('PMBOX', $pmbox, $txt['delete_all']); |
| 534 | 545 | |
| 535 | 546 | // Now, build the link tree! |
| 536 | - if ($context['current_label_id'] == -1) |
|
| 537 | - $context['linktree'][] = array( |
|
| 547 | + if ($context['current_label_id'] == -1) { |
|
| 548 | + $context['linktree'][] = array( |
|
| 538 | 549 | 'url' => $scripturl . '?action=pm;f=' . $context['folder'], |
| 539 | 550 | 'name' => $pmbox |
| 540 | 551 | ); |
| 552 | + } |
|
| 541 | 553 | |
| 542 | 554 | // Build it further for a label. |
| 543 | - if ($context['current_label_id'] != -1) |
|
| 544 | - $context['linktree'][] = array( |
|
| 555 | + if ($context['current_label_id'] != -1) { |
|
| 556 | + $context['linktree'][] = array( |
|
| 545 | 557 | 'url' => $scripturl . '?action=pm;f=' . $context['folder'] . ';l=' . $context['current_label_id'], |
| 546 | 558 | 'name' => $txt['pm_current_label'] . ': ' . $context['current_label'] |
| 547 | 559 | ); |
| 560 | + } |
|
| 548 | 561 | |
| 549 | 562 | // Figure out how many messages there are. |
| 550 | - if ($context['folder'] == 'sent') |
|
| 551 | - $request = $smcFunc['db_query']('', ' |
|
| 563 | + if ($context['folder'] == 'sent') { |
|
| 564 | + $request = $smcFunc['db_query']('', ' |
|
| 552 | 565 | SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') |
| 553 | 566 | FROM {db_prefix}personal_messages AS pm |
| 554 | 567 | WHERE pm.id_member_from = {int:current_member} |
@@ -558,8 +571,8 @@ discard block |
||
| 558 | 571 | 'not_deleted' => 0, |
| 559 | 572 | ) |
| 560 | 573 | ); |
| 561 | - else |
|
| 562 | - $request = $smcFunc['db_query']('', ' |
|
| 574 | + } else { |
|
| 575 | + $request = $smcFunc['db_query']('', ' |
|
| 563 | 576 | SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') |
| 564 | 577 | FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? ' |
| 565 | 578 | INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . ' |
@@ -570,6 +583,7 @@ discard block |
||
| 570 | 583 | 'not_deleted' => 0, |
| 571 | 584 | ) |
| 572 | 585 | ); |
| 586 | + } |
|
| 573 | 587 | list ($max_messages) = $smcFunc['db_fetch_row']($request); |
| 574 | 588 | $smcFunc['db_free_result']($request); |
| 575 | 589 | |
@@ -578,10 +592,11 @@ discard block |
||
| 578 | 592 | $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
| 579 | 593 | |
| 580 | 594 | // Start on the last page. |
| 581 | - if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages) |
|
| 582 | - $_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage); |
|
| 583 | - elseif ($_GET['start'] < 0) |
|
| 584 | - $_GET['start'] = 0; |
|
| 595 | + if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages) { |
|
| 596 | + $_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage); |
|
| 597 | + } elseif ($_GET['start'] < 0) { |
|
| 598 | + $_GET['start'] = 0; |
|
| 599 | + } |
|
| 585 | 600 | |
| 586 | 601 | // ... but wait - what if we want to start from a specific message? |
| 587 | 602 | if (isset($_GET['pmid'])) |
@@ -589,19 +604,21 @@ discard block |
||
| 589 | 604 | $pmID = (int) $_GET['pmid']; |
| 590 | 605 | |
| 591 | 606 | // Make sure you have access to this PM. |
| 592 | - if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) |
|
| 593 | - fatal_lang_error('no_access', false); |
|
| 607 | + if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) { |
|
| 608 | + fatal_lang_error('no_access', false); |
|
| 609 | + } |
|
| 594 | 610 | |
| 595 | 611 | $context['current_pm'] = $pmID; |
| 596 | 612 | |
| 597 | 613 | // With only one page of PM's we're gonna want page 1. |
| 598 | - if ($max_messages <= $maxPerPage) |
|
| 599 | - $_GET['start'] = 0; |
|
| 614 | + if ($max_messages <= $maxPerPage) { |
|
| 615 | + $_GET['start'] = 0; |
|
| 616 | + } |
|
| 600 | 617 | // If we pass kstart we assume we're in the right place. |
| 601 | 618 | elseif (!isset($_GET['kstart'])) |
| 602 | 619 | { |
| 603 | - if ($context['folder'] == 'sent') |
|
| 604 | - $request = $smcFunc['db_query']('', ' |
|
| 620 | + if ($context['folder'] == 'sent') { |
|
| 621 | + $request = $smcFunc['db_query']('', ' |
|
| 605 | 622 | SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') |
| 606 | 623 | FROM {db_prefix}personal_messages |
| 607 | 624 | WHERE id_member_from = {int:current_member} |
@@ -613,8 +630,8 @@ discard block |
||
| 613 | 630 | 'id_pm' => $pmID, |
| 614 | 631 | ) |
| 615 | 632 | ); |
| 616 | - else |
|
| 617 | - $request = $smcFunc['db_query']('', ' |
|
| 633 | + } else { |
|
| 634 | + $request = $smcFunc['db_query']('', ' |
|
| 618 | 635 | SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') |
| 619 | 636 | FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? ' |
| 620 | 637 | INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . ' |
@@ -627,6 +644,7 @@ discard block |
||
| 627 | 644 | 'id_pm' => $pmID, |
| 628 | 645 | ) |
| 629 | 646 | ); |
| 647 | + } |
|
| 630 | 648 | |
| 631 | 649 | list ($_GET['start']) = $smcFunc['db_fetch_row']($request); |
| 632 | 650 | $smcFunc['db_free_result']($request); |
@@ -641,8 +659,9 @@ discard block |
||
| 641 | 659 | { |
| 642 | 660 | $pmsg = (int) $_GET['pmsg']; |
| 643 | 661 | |
| 644 | - if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) |
|
| 645 | - fatal_lang_error('no_access', false); |
|
| 662 | + if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) { |
|
| 663 | + fatal_lang_error('no_access', false); |
|
| 664 | + } |
|
| 646 | 665 | } |
| 647 | 666 | |
| 648 | 667 | // Set up the page index. |
@@ -737,8 +756,9 @@ discard block |
||
| 737 | 756 | { |
| 738 | 757 | if (!isset($recipients[$row['id_pm']])) |
| 739 | 758 | { |
| 740 | - if (isset($row['id_member_from'])) |
|
| 741 | - $posters[$row['id_pm']] = $row['id_member_from']; |
|
| 759 | + if (isset($row['id_member_from'])) { |
|
| 760 | + $posters[$row['id_pm']] = $row['id_member_from']; |
|
| 761 | + } |
|
| 742 | 762 | $pms[$row['id_pm']] = $row['id_pm']; |
| 743 | 763 | $recipients[$row['id_pm']] = array( |
| 744 | 764 | 'to' => array(), |
@@ -747,29 +767,33 @@ discard block |
||
| 747 | 767 | } |
| 748 | 768 | |
| 749 | 769 | // Keep track of the last message so we know what the head is without another query! |
| 750 | - if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm'])) |
|
| 751 | - $lastData = array( |
|
| 770 | + if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm'])) { |
|
| 771 | + $lastData = array( |
|
| 752 | 772 | 'id' => $row['id_pm'], |
| 753 | 773 | 'head' => $row['id_pm_head'], |
| 754 | 774 | ); |
| 775 | + } |
|
| 755 | 776 | } |
| 756 | 777 | $smcFunc['db_free_result']($request); |
| 757 | 778 | |
| 758 | 779 | // Make sure that we have been given a correct head pm id! |
| 759 | - if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id']) |
|
| 760 | - fatal_lang_error('no_access', false); |
|
| 780 | + if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id']) { |
|
| 781 | + fatal_lang_error('no_access', false); |
|
| 782 | + } |
|
| 761 | 783 | |
| 762 | 784 | if (!empty($pms)) |
| 763 | 785 | { |
| 764 | 786 | // Select the correct current message. |
| 765 | - if (empty($pmID)) |
|
| 766 | - $context['current_pm'] = $lastData['id']; |
|
| 787 | + if (empty($pmID)) { |
|
| 788 | + $context['current_pm'] = $lastData['id']; |
|
| 789 | + } |
|
| 767 | 790 | |
| 768 | 791 | // This is a list of the pm's that are used for "full" display. |
| 769 | - if ($context['display_mode'] == 0) |
|
| 770 | - $display_pms = $pms; |
|
| 771 | - else |
|
| 772 | - $display_pms = array($context['current_pm']); |
|
| 792 | + if ($context['display_mode'] == 0) { |
|
| 793 | + $display_pms = $pms; |
|
| 794 | + } else { |
|
| 795 | + $display_pms = array($context['current_pm']); |
|
| 796 | + } |
|
| 773 | 797 | |
| 774 | 798 | // At this point we know the main id_pm's. But - if we are looking at conversations we need the others! |
| 775 | 799 | if ($context['display_mode'] == 2) |
@@ -791,16 +815,18 @@ discard block |
||
| 791 | 815 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 792 | 816 | { |
| 793 | 817 | // This is, frankly, a joke. We will put in a workaround for people sending to themselves - yawn! |
| 794 | - if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1) |
|
| 795 | - continue; |
|
| 796 | - elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1) |
|
| 797 | - continue; |
|
| 818 | + if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1) { |
|
| 819 | + continue; |
|
| 820 | + } elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1) { |
|
| 821 | + continue; |
|
| 822 | + } |
|
| 798 | 823 | |
| 799 | - if (!isset($recipients[$row['id_pm']])) |
|
| 800 | - $recipients[$row['id_pm']] = array( |
|
| 824 | + if (!isset($recipients[$row['id_pm']])) { |
|
| 825 | + $recipients[$row['id_pm']] = array( |
|
| 801 | 826 | 'to' => array(), |
| 802 | 827 | 'bcc' => array() |
| 803 | 828 | ); |
| 829 | + } |
|
| 804 | 830 | $display_pms[] = $row['id_pm']; |
| 805 | 831 | $posters[$row['id_pm']] = $row['id_member_from']; |
| 806 | 832 | } |
@@ -851,8 +877,9 @@ discard block |
||
| 851 | 877 | while($row2 = $smcFunc['db_fetch_assoc']($request2)) |
| 852 | 878 | { |
| 853 | 879 | $l_id = $row2['id_label']; |
| 854 | - if (isset($context['labels'][$l_id])) |
|
| 855 | - $context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); |
|
| 880 | + if (isset($context['labels'][$l_id])) { |
|
| 881 | + $context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); |
|
| 882 | + } |
|
| 856 | 883 | } |
| 857 | 884 | |
| 858 | 885 | $smcFunc['db_free_result']($request2); |
@@ -869,9 +896,10 @@ discard block |
||
| 869 | 896 | // Make sure we don't load unnecessary data. |
| 870 | 897 | if ($context['display_mode'] == 1) |
| 871 | 898 | { |
| 872 | - foreach ($posters as $k => $v) |
|
| 873 | - if (!in_array($k, $display_pms)) |
|
| 899 | + foreach ($posters as $k => $v) { |
|
| 900 | + if (!in_array($k, $display_pms)) |
|
| 874 | 901 | unset($posters[$k]); |
| 902 | + } |
|
| 875 | 903 | } |
| 876 | 904 | |
| 877 | 905 | // Load any users.... |
@@ -882,8 +910,9 @@ discard block |
||
| 882 | 910 | { |
| 883 | 911 | // Get the order right. |
| 884 | 912 | $orderBy = array(); |
| 885 | - foreach (array_reverse($pms) as $pm) |
|
| 886 | - $orderBy[] = 'pm.id_pm = ' . $pm; |
|
| 913 | + foreach (array_reverse($pms) as $pm) { |
|
| 914 | + $orderBy[] = 'pm.id_pm = ' . $pm; |
|
| 915 | + } |
|
| 887 | 916 | |
| 888 | 917 | // Seperate query for these bits! |
| 889 | 918 | $subjects_request = $smcFunc['db_query']('', ' |
@@ -929,9 +958,9 @@ discard block |
||
| 929 | 958 | // Allow mods to add additional buttons here |
| 930 | 959 | call_integration_hook('integrate_conversation_buttons'); |
| 931 | 960 | } |
| 961 | + } else { |
|
| 962 | + $messages_request = false; |
|
| 932 | 963 | } |
| 933 | - else |
|
| 934 | - $messages_request = false; |
|
| 935 | 964 | |
| 936 | 965 | $context['can_send_pm'] = allowedTo('pm_send'); |
| 937 | 966 | $context['can_send_email'] = allowedTo('moderate_forum'); |
@@ -942,11 +971,13 @@ discard block |
||
| 942 | 971 | if ($context['folder'] != 'sent' && !empty($context['labels'][(int) $context['current_label_id']]['unread_messages'])) |
| 943 | 972 | { |
| 944 | 973 | // If the display mode is "old sk00l" do them all... |
| 945 | - if ($context['display_mode'] == 0) |
|
| 946 | - markMessages(null, $context['current_label_id']); |
|
| 974 | + if ($context['display_mode'] == 0) { |
|
| 975 | + markMessages(null, $context['current_label_id']); |
|
| 976 | + } |
|
| 947 | 977 | // Otherwise do just the current one! |
| 948 | - elseif (!empty($context['current_pm'])) |
|
| 949 | - markMessages($display_pms, $context['current_label_id']); |
|
| 978 | + elseif (!empty($context['current_pm'])) { |
|
| 979 | + markMessages($display_pms, $context['current_label_id']); |
|
| 980 | + } |
|
| 950 | 981 | } |
| 951 | 982 | } |
| 952 | 983 | |
@@ -964,8 +995,9 @@ discard block |
||
| 964 | 995 | |
| 965 | 996 | // Count the current message number.... |
| 966 | 997 | static $counter = null; |
| 967 | - if ($counter === null || $reset) |
|
| 968 | - $counter = $context['start']; |
|
| 998 | + if ($counter === null || $reset) { |
|
| 999 | + $counter = $context['start']; |
|
| 1000 | + } |
|
| 969 | 1001 | |
| 970 | 1002 | static $temp_pm_selected = null; |
| 971 | 1003 | if ($temp_pm_selected === null) |
@@ -1010,19 +1042,22 @@ discard block |
||
| 1010 | 1042 | } |
| 1011 | 1043 | |
| 1012 | 1044 | // Bail if it's false, ie. no messages. |
| 1013 | - if ($messages_request == false) |
|
| 1014 | - return false; |
|
| 1045 | + if ($messages_request == false) { |
|
| 1046 | + return false; |
|
| 1047 | + } |
|
| 1015 | 1048 | |
| 1016 | 1049 | // Reset the data? |
| 1017 | - if ($reset == true) |
|
| 1018 | - return @$smcFunc['db_data_seek']($messages_request, 0); |
|
| 1050 | + if ($reset == true) { |
|
| 1051 | + return @$smcFunc['db_data_seek']($messages_request, 0); |
|
| 1052 | + } |
|
| 1019 | 1053 | |
| 1020 | 1054 | // Get the next one... bail if anything goes wrong. |
| 1021 | 1055 | $message = $smcFunc['db_fetch_assoc']($messages_request); |
| 1022 | 1056 | if (!$message) |
| 1023 | 1057 | { |
| 1024 | - if ($type != 'subject') |
|
| 1025 | - $smcFunc['db_free_result']($messages_request); |
|
| 1058 | + if ($type != 'subject') { |
|
| 1059 | + $smcFunc['db_free_result']($messages_request); |
|
| 1060 | + } |
|
| 1026 | 1061 | |
| 1027 | 1062 | return false; |
| 1028 | 1063 | } |
@@ -1042,8 +1077,7 @@ discard block |
||
| 1042 | 1077 | $memberContext[$message['id_member_from']]['email'] = ''; |
| 1043 | 1078 | $memberContext[$message['id_member_from']]['show_email'] = false; |
| 1044 | 1079 | $memberContext[$message['id_member_from']]['is_guest'] = true; |
| 1045 | - } |
|
| 1046 | - else |
|
| 1080 | + } else |
|
| 1047 | 1081 | { |
| 1048 | 1082 | $memberContext[$message['id_member_from']]['can_view_profile'] = allowedTo('profile_view') || ($message['id_member_from'] == $user_info['id'] && !$user_info['is_guest']); |
| 1049 | 1083 | $memberContext[$message['id_member_from']]['can_see_warning'] = !isset($context['disabled_fields']['warning_status']) && $memberContext[$message['id_member_from']]['warning_status'] && ($context['user']['can_mod'] || (!empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $message['id_member_from'] == $user_info['id']))); |
@@ -1084,12 +1118,13 @@ discard block |
||
| 1084 | 1118 | $counter++; |
| 1085 | 1119 | |
| 1086 | 1120 | // Any custom profile fields? |
| 1087 | - if (!empty($memberContext[$message['id_member_from']]['custom_fields'])) |
|
| 1088 | - foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom) |
|
| 1121 | + if (!empty($memberContext[$message['id_member_from']]['custom_fields'])) { |
|
| 1122 | + foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom) |
|
| 1089 | 1123 | switch ($custom['placement']) |
| 1090 | 1124 | { |
| 1091 | 1125 | case 1: |
| 1092 | 1126 | $output['custom_fields']['icons'][] = $custom; |
| 1127 | + } |
|
| 1093 | 1128 | break; |
| 1094 | 1129 | case 2: |
| 1095 | 1130 | $output['custom_fields']['above_signature'][] = $custom; |
@@ -1132,22 +1167,28 @@ discard block |
||
| 1132 | 1167 | $context['search_params'][$k] = $v; |
| 1133 | 1168 | } |
| 1134 | 1169 | } |
| 1135 | - if (isset($_REQUEST['search'])) |
|
| 1136 | - $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']); |
|
| 1170 | + if (isset($_REQUEST['search'])) { |
|
| 1171 | + $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']); |
|
| 1172 | + } |
|
| 1137 | 1173 | |
| 1138 | - if (isset($context['search_params']['search'])) |
|
| 1139 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
| 1140 | - if (isset($context['search_params']['userspec'])) |
|
| 1141 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
| 1174 | + if (isset($context['search_params']['search'])) { |
|
| 1175 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
| 1176 | + } |
|
| 1177 | + if (isset($context['search_params']['userspec'])) { |
|
| 1178 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
| 1179 | + } |
|
| 1142 | 1180 | |
| 1143 | - if (!empty($context['search_params']['searchtype'])) |
|
| 1144 | - $context['search_params']['searchtype'] = 2; |
|
| 1181 | + if (!empty($context['search_params']['searchtype'])) { |
|
| 1182 | + $context['search_params']['searchtype'] = 2; |
|
| 1183 | + } |
|
| 1145 | 1184 | |
| 1146 | - if (!empty($context['search_params']['minage'])) |
|
| 1147 | - $context['search_params']['minage'] = (int) $context['search_params']['minage']; |
|
| 1185 | + if (!empty($context['search_params']['minage'])) { |
|
| 1186 | + $context['search_params']['minage'] = (int) $context['search_params']['minage']; |
|
| 1187 | + } |
|
| 1148 | 1188 | |
| 1149 | - if (!empty($context['search_params']['maxage'])) |
|
| 1150 | - $context['search_params']['maxage'] = (int) $context['search_params']['maxage']; |
|
| 1189 | + if (!empty($context['search_params']['maxage'])) { |
|
| 1190 | + $context['search_params']['maxage'] = (int) $context['search_params']['maxage']; |
|
| 1191 | + } |
|
| 1151 | 1192 | |
| 1152 | 1193 | $context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']); |
| 1153 | 1194 | $context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']); |
@@ -1174,8 +1215,9 @@ discard block |
||
| 1174 | 1215 | $context['search_errors']['messages'] = array(); |
| 1175 | 1216 | foreach ($context['search_errors'] as $search_error => $dummy) |
| 1176 | 1217 | { |
| 1177 | - if ($search_error == 'messages') |
|
| 1178 | - continue; |
|
| 1218 | + if ($search_error == 'messages') { |
|
| 1219 | + continue; |
|
| 1220 | + } |
|
| 1179 | 1221 | |
| 1180 | 1222 | $context['search_errors']['messages'][] = $txt['error_' . $search_error]; |
| 1181 | 1223 | } |
@@ -1197,8 +1239,9 @@ discard block |
||
| 1197 | 1239 | global $scripturl, $modSettings, $user_info, $context, $txt; |
| 1198 | 1240 | global $memberContext, $smcFunc; |
| 1199 | 1241 | |
| 1200 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) |
|
| 1201 | - fatal_lang_error('loadavg_search_disabled', false); |
|
| 1242 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) { |
|
| 1243 | + fatal_lang_error('loadavg_search_disabled', false); |
|
| 1244 | + } |
|
| 1202 | 1245 | |
| 1203 | 1246 | /** |
| 1204 | 1247 | * @todo For the moment force the folder to the inbox. |
@@ -1227,35 +1270,40 @@ discard block |
||
| 1227 | 1270 | $context['start'] = isset($_GET['start']) ? (int) $_GET['start'] : 0; |
| 1228 | 1271 | |
| 1229 | 1272 | // Store whether simple search was used (needed if the user wants to do another query). |
| 1230 | - if (!isset($search_params['advanced'])) |
|
| 1231 | - $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1; |
|
| 1273 | + if (!isset($search_params['advanced'])) { |
|
| 1274 | + $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1; |
|
| 1275 | + } |
|
| 1232 | 1276 | |
| 1233 | 1277 | // 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'. |
| 1234 | - if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) |
|
| 1235 | - $search_params['searchtype'] = 2; |
|
| 1278 | + if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) { |
|
| 1279 | + $search_params['searchtype'] = 2; |
|
| 1280 | + } |
|
| 1236 | 1281 | |
| 1237 | 1282 | // Minimum age of messages. Default to zero (don't set param in that case). |
| 1238 | - if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) |
|
| 1239 | - $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage']; |
|
| 1283 | + if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) { |
|
| 1284 | + $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage']; |
|
| 1285 | + } |
|
| 1240 | 1286 | |
| 1241 | 1287 | // Maximum age of messages. Default to infinite (9999 days: param not set). |
| 1242 | - if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999)) |
|
| 1243 | - $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage']; |
|
| 1288 | + if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999)) { |
|
| 1289 | + $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage']; |
|
| 1290 | + } |
|
| 1244 | 1291 | |
| 1245 | 1292 | $search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']); |
| 1246 | 1293 | $search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']); |
| 1247 | 1294 | |
| 1248 | 1295 | // Default the user name to a wildcard matching every user (*). |
| 1249 | - if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) |
|
| 1250 | - $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec']; |
|
| 1296 | + if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) { |
|
| 1297 | + $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec']; |
|
| 1298 | + } |
|
| 1251 | 1299 | |
| 1252 | 1300 | // This will be full of all kinds of parameters! |
| 1253 | 1301 | $searchq_parameters = array(); |
| 1254 | 1302 | |
| 1255 | 1303 | // If there's no specific user, then don't mention it in the main query. |
| 1256 | - if (empty($search_params['userspec'])) |
|
| 1257 | - $userQuery = ''; |
|
| 1258 | - else |
|
| 1304 | + if (empty($search_params['userspec'])) { |
|
| 1305 | + $userQuery = ''; |
|
| 1306 | + } else |
|
| 1259 | 1307 | { |
| 1260 | 1308 | $userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('"' => '"')); |
| 1261 | 1309 | $userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')); |
@@ -1267,8 +1315,9 @@ discard block |
||
| 1267 | 1315 | { |
| 1268 | 1316 | $possible_users[$k] = trim($possible_users[$k]); |
| 1269 | 1317 | |
| 1270 | - if (strlen($possible_users[$k]) == 0) |
|
| 1271 | - unset($possible_users[$k]); |
|
| 1318 | + if (strlen($possible_users[$k]) == 0) { |
|
| 1319 | + unset($possible_users[$k]); |
|
| 1320 | + } |
|
| 1272 | 1321 | } |
| 1273 | 1322 | |
| 1274 | 1323 | if (!empty($possible_users)) |
@@ -1280,8 +1329,9 @@ discard block |
||
| 1280 | 1329 | { |
| 1281 | 1330 | $where_params['name_' . $k] = $v; |
| 1282 | 1331 | $where_clause[] = '{raw:real_name} LIKE {string:name_' . $k . '}'; |
| 1283 | - if (!isset($where_params['real_name'])) |
|
| 1284 | - $where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name'; |
|
| 1332 | + if (!isset($where_params['real_name'])) { |
|
| 1333 | + $where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name'; |
|
| 1334 | + } |
|
| 1285 | 1335 | } |
| 1286 | 1336 | |
| 1287 | 1337 | // Who matches those criteria? |
@@ -1294,28 +1344,28 @@ discard block |
||
| 1294 | 1344 | ); |
| 1295 | 1345 | |
| 1296 | 1346 | // Simply do nothing if there're too many members matching the criteria. |
| 1297 | - if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) |
|
| 1298 | - $userQuery = ''; |
|
| 1299 | - elseif ($smcFunc['db_num_rows']($request) == 0) |
|
| 1347 | + if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) { |
|
| 1348 | + $userQuery = ''; |
|
| 1349 | + } elseif ($smcFunc['db_num_rows']($request) == 0) |
|
| 1300 | 1350 | { |
| 1301 | 1351 | $userQuery = 'AND pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})'; |
| 1302 | 1352 | $searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\''; |
| 1303 | 1353 | $searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name'; |
| 1304 | - } |
|
| 1305 | - else |
|
| 1354 | + } else |
|
| 1306 | 1355 | { |
| 1307 | 1356 | $memberlist = array(); |
| 1308 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1309 | - $memberlist[] = $row['id_member']; |
|
| 1357 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1358 | + $memberlist[] = $row['id_member']; |
|
| 1359 | + } |
|
| 1310 | 1360 | $userQuery = 'AND (pm.id_member_from IN ({array_int:member_list}) OR (pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})))'; |
| 1311 | 1361 | $searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\''; |
| 1312 | 1362 | $searchq_parameters['member_list'] = $memberlist; |
| 1313 | 1363 | $searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name'; |
| 1314 | 1364 | } |
| 1315 | 1365 | $smcFunc['db_free_result']($request); |
| 1366 | + } else { |
|
| 1367 | + $userQuery = ''; |
|
| 1316 | 1368 | } |
| 1317 | - else |
|
| 1318 | - $userQuery = ''; |
|
| 1319 | 1369 | } |
| 1320 | 1370 | |
| 1321 | 1371 | // Setup the sorting variables... |
@@ -1323,8 +1373,9 @@ discard block |
||
| 1323 | 1373 | $sort_columns = array( |
| 1324 | 1374 | 'pm.id_pm', |
| 1325 | 1375 | ); |
| 1326 | - if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) |
|
| 1327 | - list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); |
|
| 1376 | + if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) { |
|
| 1377 | + list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); |
|
| 1378 | + } |
|
| 1328 | 1379 | $search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'pm.id_pm'; |
| 1329 | 1380 | $search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc'; |
| 1330 | 1381 | |
@@ -1334,24 +1385,27 @@ discard block |
||
| 1334 | 1385 | if ($context['folder'] == 'inbox' && !empty($search_params['advanced']) && $context['currently_using_labels']) |
| 1335 | 1386 | { |
| 1336 | 1387 | // Came here from pagination? Put them back into $_REQUEST for sanitization. |
| 1337 | - if (isset($search_params['labels'])) |
|
| 1338 | - $_REQUEST['searchlabel'] = explode(',', $search_params['labels']); |
|
| 1388 | + if (isset($search_params['labels'])) { |
|
| 1389 | + $_REQUEST['searchlabel'] = explode(',', $search_params['labels']); |
|
| 1390 | + } |
|
| 1339 | 1391 | |
| 1340 | 1392 | // Assuming we have some labels - make them all integers. |
| 1341 | 1393 | if (!empty($_REQUEST['searchlabel']) && is_array($_REQUEST['searchlabel'])) |
| 1342 | 1394 | { |
| 1343 | - foreach ($_REQUEST['searchlabel'] as $key => $id) |
|
| 1344 | - $_REQUEST['searchlabel'][$key] = (int) $id; |
|
| 1395 | + foreach ($_REQUEST['searchlabel'] as $key => $id) { |
|
| 1396 | + $_REQUEST['searchlabel'][$key] = (int) $id; |
|
| 1397 | + } |
|
| 1398 | + } else { |
|
| 1399 | + $_REQUEST['searchlabel'] = array(); |
|
| 1345 | 1400 | } |
| 1346 | - else |
|
| 1347 | - $_REQUEST['searchlabel'] = array(); |
|
| 1348 | 1401 | |
| 1349 | 1402 | // Now that everything is cleaned up a bit, make the labels a param. |
| 1350 | 1403 | $search_params['labels'] = implode(',', $_REQUEST['searchlabel']); |
| 1351 | 1404 | |
| 1352 | 1405 | // No labels selected? That must be an error! |
| 1353 | - if (empty($_REQUEST['searchlabel'])) |
|
| 1354 | - $context['search_errors']['no_labels_selected'] = true; |
|
| 1406 | + if (empty($_REQUEST['searchlabel'])) { |
|
| 1407 | + $context['search_errors']['no_labels_selected'] = true; |
|
| 1408 | + } |
|
| 1355 | 1409 | // Otherwise prepare the query! |
| 1356 | 1410 | elseif (count($_REQUEST['searchlabel']) != count($context['labels'])) |
| 1357 | 1411 | { |
@@ -1374,8 +1428,7 @@ discard block |
||
| 1374 | 1428 | // Not searching the inbox - PM must be labeled |
| 1375 | 1429 | $labelQuery = ' AND pml.id_label IN ({array_int:labels})'; |
| 1376 | 1430 | $labelJoin = ' INNER JOIN {db_prefix}pm_labeled_messages AS pml ON (pml.id_pm = pmr.id_pm)'; |
| 1377 | - } |
|
| 1378 | - else |
|
| 1431 | + } else |
|
| 1379 | 1432 | { |
| 1380 | 1433 | // Searching the inbox - PM doesn't have to be labeled |
| 1381 | 1434 | $labelQuery = ' AND (' . substr($labelQuery, 5) . ' OR pml.id_label IN ({array_int:labels}))'; |
@@ -1390,8 +1443,9 @@ discard block |
||
| 1390 | 1443 | // What are we actually searching for? |
| 1391 | 1444 | $search_params['search'] = !empty($search_params['search']) ? $search_params['search'] : (isset($_REQUEST['search']) ? $_REQUEST['search'] : ''); |
| 1392 | 1445 | // If we ain't got nothing - we should error! |
| 1393 | - if (!isset($search_params['search']) || $search_params['search'] == '') |
|
| 1394 | - $context['search_errors']['invalid_search_string'] = true; |
|
| 1446 | + if (!isset($search_params['search']) || $search_params['search'] == '') { |
|
| 1447 | + $context['search_errors']['invalid_search_string'] = true; |
|
| 1448 | + } |
|
| 1395 | 1449 | |
| 1396 | 1450 | // Extract phrase parts first (e.g. some words "this is a phrase" some more words.) |
| 1397 | 1451 | preg_match_all('~(?:^|\s)([-]?)"([^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), $search_params['search'], $matches, PREG_PATTERN_ORDER); |
@@ -1404,12 +1458,14 @@ discard block |
||
| 1404 | 1458 | $excludedWords = array(); |
| 1405 | 1459 | |
| 1406 | 1460 | // .. first, we check for things like -"some words", but not "-some words". |
| 1407 | - foreach ($matches[1] as $index => $word) |
|
| 1408 | - if ($word == '-') |
|
| 1461 | + foreach ($matches[1] as $index => $word) { |
|
| 1462 | + if ($word == '-') |
|
| 1409 | 1463 | { |
| 1410 | 1464 | $word = $smcFunc['strtolower'](trim($searchArray[$index])); |
| 1411 | - if (strlen($word) > 0) |
|
| 1412 | - $excludedWords[] = $word; |
|
| 1465 | + } |
|
| 1466 | + if (strlen($word) > 0) { |
|
| 1467 | + $excludedWords[] = $word; |
|
| 1468 | + } |
|
| 1413 | 1469 | unset($searchArray[$index]); |
| 1414 | 1470 | } |
| 1415 | 1471 | |
@@ -1419,8 +1475,9 @@ discard block |
||
| 1419 | 1475 | if (strpos(trim($word), '-') === 0) |
| 1420 | 1476 | { |
| 1421 | 1477 | $word = substr($smcFunc['strtolower']($word), 1); |
| 1422 | - if (strlen($word) > 0) |
|
| 1423 | - $excludedWords[] = $word; |
|
| 1478 | + if (strlen($word) > 0) { |
|
| 1479 | + $excludedWords[] = $word; |
|
| 1480 | + } |
|
| 1424 | 1481 | unset($tempSearch[$index]); |
| 1425 | 1482 | } |
| 1426 | 1483 | } |
@@ -1431,9 +1488,9 @@ discard block |
||
| 1431 | 1488 | foreach ($searchArray as $index => $value) |
| 1432 | 1489 | { |
| 1433 | 1490 | $searchArray[$index] = $smcFunc['strtolower'](trim($value)); |
| 1434 | - if ($searchArray[$index] == '') |
|
| 1435 | - unset($searchArray[$index]); |
|
| 1436 | - else |
|
| 1491 | + if ($searchArray[$index] == '') { |
|
| 1492 | + unset($searchArray[$index]); |
|
| 1493 | + } else |
|
| 1437 | 1494 | { |
| 1438 | 1495 | // Sort out entities first. |
| 1439 | 1496 | $searchArray[$index] = $smcFunc['htmlspecialchars']($searchArray[$index]); |
@@ -1443,27 +1500,32 @@ discard block |
||
| 1443 | 1500 | |
| 1444 | 1501 | // Create an array of replacements for highlighting. |
| 1445 | 1502 | $context['mark'] = array(); |
| 1446 | - foreach ($searchArray as $word) |
|
| 1447 | - $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>'; |
|
| 1503 | + foreach ($searchArray as $word) { |
|
| 1504 | + $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>'; |
|
| 1505 | + } |
|
| 1448 | 1506 | |
| 1449 | 1507 | // This contains *everything* |
| 1450 | 1508 | $searchWords = array_merge($searchArray, $excludedWords); |
| 1451 | 1509 | |
| 1452 | 1510 | // Make sure at least one word is being searched for. |
| 1453 | - if (empty($searchArray)) |
|
| 1454 | - $context['search_errors']['invalid_search_string'] = true; |
|
| 1511 | + if (empty($searchArray)) { |
|
| 1512 | + $context['search_errors']['invalid_search_string'] = true; |
|
| 1513 | + } |
|
| 1455 | 1514 | |
| 1456 | 1515 | // Sort out the search query so the user can edit it - if they want. |
| 1457 | 1516 | $context['search_params'] = $search_params; |
| 1458 | - if (isset($context['search_params']['search'])) |
|
| 1459 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
| 1460 | - if (isset($context['search_params']['userspec'])) |
|
| 1461 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
| 1517 | + if (isset($context['search_params']['search'])) { |
|
| 1518 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
| 1519 | + } |
|
| 1520 | + if (isset($context['search_params']['userspec'])) { |
|
| 1521 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
| 1522 | + } |
|
| 1462 | 1523 | |
| 1463 | 1524 | // Now we have all the parameters, combine them together for pagination and the like... |
| 1464 | 1525 | $context['params'] = array(); |
| 1465 | - foreach ($search_params as $k => $v) |
|
| 1466 | - $context['params'][] = $k . '|\'|' . $v; |
|
| 1526 | + foreach ($search_params as $k => $v) { |
|
| 1527 | + $context['params'][] = $k . '|\'|' . $v; |
|
| 1528 | + } |
|
| 1467 | 1529 | $context['params'] = base64_encode(implode('|"|', $context['params'])); |
| 1468 | 1530 | |
| 1469 | 1531 | // Compile the subject query part. |
@@ -1471,26 +1533,31 @@ discard block |
||
| 1471 | 1533 | |
| 1472 | 1534 | foreach ($searchWords as $index => $word) |
| 1473 | 1535 | { |
| 1474 | - if ($word == '') |
|
| 1475 | - continue; |
|
| 1536 | + if ($word == '') { |
|
| 1537 | + continue; |
|
| 1538 | + } |
|
| 1476 | 1539 | |
| 1477 | - if ($search_params['subject_only']) |
|
| 1478 | - $andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}'; |
|
| 1479 | - else |
|
| 1480 | - $andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})'; |
|
| 1540 | + if ($search_params['subject_only']) { |
|
| 1541 | + $andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}'; |
|
| 1542 | + } else { |
|
| 1543 | + $andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})'; |
|
| 1544 | + } |
|
| 1481 | 1545 | $searchq_parameters['search_' . $index] = '%' . strtr($word, array('_' => '\\_', '%' => '\\%')) . '%'; |
| 1482 | 1546 | } |
| 1483 | 1547 | |
| 1484 | 1548 | $searchQuery = ' 1=1'; |
| 1485 | - if (!empty($andQueryParts)) |
|
| 1486 | - $searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts); |
|
| 1549 | + if (!empty($andQueryParts)) { |
|
| 1550 | + $searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts); |
|
| 1551 | + } |
|
| 1487 | 1552 | |
| 1488 | 1553 | // Age limits? |
| 1489 | 1554 | $timeQuery = ''; |
| 1490 | - if (!empty($search_params['minage'])) |
|
| 1491 | - $timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400); |
|
| 1492 | - if (!empty($search_params['maxage'])) |
|
| 1493 | - $timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400); |
|
| 1555 | + if (!empty($search_params['minage'])) { |
|
| 1556 | + $timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400); |
|
| 1557 | + } |
|
| 1558 | + if (!empty($search_params['maxage'])) { |
|
| 1559 | + $timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400); |
|
| 1560 | + } |
|
| 1494 | 1561 | |
| 1495 | 1562 | // If we have errors - return back to the first screen... |
| 1496 | 1563 | if (!empty($context['search_errors'])) |
@@ -1576,8 +1643,9 @@ discard block |
||
| 1576 | 1643 | ) |
| 1577 | 1644 | ); |
| 1578 | 1645 | $real_pm_ids = array(); |
| 1579 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1580 | - $real_pm_ids[$row['id_pm_head']] = $row['id_pm']; |
|
| 1646 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1647 | + $real_pm_ids[$row['id_pm_head']] = $row['id_pm']; |
|
| 1648 | + } |
|
| 1581 | 1649 | $smcFunc['db_free_result']($request); |
| 1582 | 1650 | } |
| 1583 | 1651 | |
@@ -1607,8 +1675,9 @@ discard block |
||
| 1607 | 1675 | ); |
| 1608 | 1676 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1609 | 1677 | { |
| 1610 | - if ($context['folder'] == 'sent' || empty($row['bcc'])) |
|
| 1611 | - $recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>'; |
|
| 1678 | + if ($context['folder'] == 'sent' || empty($row['bcc'])) { |
|
| 1679 | + $recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>'; |
|
| 1680 | + } |
|
| 1612 | 1681 | |
| 1613 | 1682 | if ($row['id_member_to'] == $user_info['id'] && $context['folder'] != 'sent') |
| 1614 | 1683 | { |
@@ -1629,12 +1698,14 @@ discard block |
||
| 1629 | 1698 | while($row2 = $smcFunc['db_fetch_assoc']($request2)) |
| 1630 | 1699 | { |
| 1631 | 1700 | $l_id = $row2['id_label']; |
| 1632 | - if (isset($context['labels'][$l_id])) |
|
| 1633 | - $context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); |
|
| 1701 | + if (isset($context['labels'][$l_id])) { |
|
| 1702 | + $context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); |
|
| 1703 | + } |
|
| 1634 | 1704 | |
| 1635 | 1705 | // Here we find the first label on a message - for linking to posts in results |
| 1636 | - if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1) |
|
| 1637 | - $context['first_label'][$row['id_pm']] = $l_id; |
|
| 1706 | + if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1) { |
|
| 1707 | + $context['first_label'][$row['id_pm']] = $l_id; |
|
| 1708 | + } |
|
| 1638 | 1709 | } |
| 1639 | 1710 | |
| 1640 | 1711 | $smcFunc['db_free_result']($request2); |
@@ -1761,8 +1832,9 @@ discard block |
||
| 1761 | 1832 | list ($postCount) = $smcFunc['db_fetch_row']($request); |
| 1762 | 1833 | $smcFunc['db_free_result']($request); |
| 1763 | 1834 | |
| 1764 | - if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) |
|
| 1765 | - fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); |
|
| 1835 | + if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) { |
|
| 1836 | + fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); |
|
| 1837 | + } |
|
| 1766 | 1838 | } |
| 1767 | 1839 | |
| 1768 | 1840 | // Quoting/Replying to a message? |
@@ -1771,8 +1843,9 @@ discard block |
||
| 1771 | 1843 | $pmsg = (int) $_REQUEST['pmsg']; |
| 1772 | 1844 | |
| 1773 | 1845 | // Make sure this is yours. |
| 1774 | - if (!isAccessiblePM($pmsg)) |
|
| 1775 | - fatal_lang_error('no_access', false); |
|
| 1846 | + if (!isAccessiblePM($pmsg)) { |
|
| 1847 | + fatal_lang_error('no_access', false); |
|
| 1848 | + } |
|
| 1776 | 1849 | |
| 1777 | 1850 | // Work out whether this is one you've received? |
| 1778 | 1851 | $request = $smcFunc['db_query']('', ' |
@@ -1809,8 +1882,9 @@ discard block |
||
| 1809 | 1882 | 'id_pm' => $pmsg, |
| 1810 | 1883 | ) |
| 1811 | 1884 | ); |
| 1812 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1813 | - fatal_lang_error('pm_not_yours', false); |
|
| 1885 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1886 | + fatal_lang_error('pm_not_yours', false); |
|
| 1887 | + } |
|
| 1814 | 1888 | $row_quoted = $smcFunc['db_fetch_assoc']($request); |
| 1815 | 1889 | $smcFunc['db_free_result']($request); |
| 1816 | 1890 | |
@@ -1821,9 +1895,9 @@ discard block |
||
| 1821 | 1895 | // Add 'Re: ' to it.... |
| 1822 | 1896 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
| 1823 | 1897 | { |
| 1824 | - if ($language === $user_info['language']) |
|
| 1825 | - $context['response_prefix'] = $txt['response_prefix']; |
|
| 1826 | - else |
|
| 1898 | + if ($language === $user_info['language']) { |
|
| 1899 | + $context['response_prefix'] = $txt['response_prefix']; |
|
| 1900 | + } else |
|
| 1827 | 1901 | { |
| 1828 | 1902 | loadLanguage('index', $language, false); |
| 1829 | 1903 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -1832,22 +1906,25 @@ discard block |
||
| 1832 | 1906 | cache_put_data('response_prefix', $context['response_prefix'], 600); |
| 1833 | 1907 | } |
| 1834 | 1908 | $form_subject = $row_quoted['subject']; |
| 1835 | - if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
|
| 1836 | - $form_subject = $context['response_prefix'] . $form_subject; |
|
| 1909 | + if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) { |
|
| 1910 | + $form_subject = $context['response_prefix'] . $form_subject; |
|
| 1911 | + } |
|
| 1837 | 1912 | |
| 1838 | 1913 | if (isset($_REQUEST['quote'])) |
| 1839 | 1914 | { |
| 1840 | 1915 | // Remove any nested quotes and <br>... |
| 1841 | 1916 | $form_message = preg_replace('~<br ?/?' . '>~i', "\n", $row_quoted['body']); |
| 1842 | - if (!empty($modSettings['removeNestedQuotes'])) |
|
| 1843 | - $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
| 1844 | - if (empty($row_quoted['id_member'])) |
|
| 1845 | - $form_message = '[quote author="' . $row_quoted['real_name'] . '"]' . "\n" . $form_message . "\n" . '[/quote]'; |
|
| 1846 | - else |
|
| 1847 | - $form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]'; |
|
| 1917 | + if (!empty($modSettings['removeNestedQuotes'])) { |
|
| 1918 | + $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
| 1919 | + } |
|
| 1920 | + if (empty($row_quoted['id_member'])) { |
|
| 1921 | + $form_message = '[quote author="' . $row_quoted['real_name'] . '"]' . "\n" . $form_message . "\n" . '[/quote]'; |
|
| 1922 | + } else { |
|
| 1923 | + $form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]'; |
|
| 1924 | + } |
|
| 1925 | + } else { |
|
| 1926 | + $form_message = ''; |
|
| 1848 | 1927 | } |
| 1849 | - else |
|
| 1850 | - $form_message = ''; |
|
| 1851 | 1928 | |
| 1852 | 1929 | // Do the BBC thang on the message. |
| 1853 | 1930 | $row_quoted['body'] = parse_bbc($row_quoted['body'], true, 'pm' . $row_quoted['id_pm']); |
@@ -1868,8 +1945,7 @@ discard block |
||
| 1868 | 1945 | 'timestamp' => forum_time(true, $row_quoted['msgtime']), |
| 1869 | 1946 | 'body' => $row_quoted['body'] |
| 1870 | 1947 | ); |
| 1871 | - } |
|
| 1872 | - else |
|
| 1948 | + } else |
|
| 1873 | 1949 | { |
| 1874 | 1950 | $context['quoted_message'] = false; |
| 1875 | 1951 | $form_subject = ''; |
@@ -1888,11 +1964,12 @@ discard block |
||
| 1888 | 1964 | if ($_REQUEST['u'] == 'all' && isset($row_quoted)) |
| 1889 | 1965 | { |
| 1890 | 1966 | // Firstly, to reply to all we clearly already have $row_quoted - so have the original member from. |
| 1891 | - if ($row_quoted['id_member'] != $user_info['id']) |
|
| 1892 | - $context['recipients']['to'][] = array( |
|
| 1967 | + if ($row_quoted['id_member'] != $user_info['id']) { |
|
| 1968 | + $context['recipients']['to'][] = array( |
|
| 1893 | 1969 | 'id' => $row_quoted['id_member'], |
| 1894 | 1970 | 'name' => $smcFunc['htmlspecialchars']($row_quoted['real_name']), |
| 1895 | 1971 | ); |
| 1972 | + } |
|
| 1896 | 1973 | |
| 1897 | 1974 | // Now to get the others. |
| 1898 | 1975 | $request = $smcFunc['db_query']('', ' |
@@ -1908,18 +1985,19 @@ discard block |
||
| 1908 | 1985 | 'not_bcc' => 0, |
| 1909 | 1986 | ) |
| 1910 | 1987 | ); |
| 1911 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1912 | - $context['recipients']['to'][] = array( |
|
| 1988 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1989 | + $context['recipients']['to'][] = array( |
|
| 1913 | 1990 | 'id' => $row['id_member'], |
| 1914 | 1991 | 'name' => $row['real_name'], |
| 1915 | 1992 | ); |
| 1993 | + } |
|
| 1916 | 1994 | $smcFunc['db_free_result']($request); |
| 1917 | - } |
|
| 1918 | - else |
|
| 1995 | + } else |
|
| 1919 | 1996 | { |
| 1920 | 1997 | $_REQUEST['u'] = explode(',', $_REQUEST['u']); |
| 1921 | - foreach ($_REQUEST['u'] as $key => $uID) |
|
| 1922 | - $_REQUEST['u'][$key] = (int) $uID; |
|
| 1998 | + foreach ($_REQUEST['u'] as $key => $uID) { |
|
| 1999 | + $_REQUEST['u'][$key] = (int) $uID; |
|
| 2000 | + } |
|
| 1923 | 2001 | |
| 1924 | 2002 | $_REQUEST['u'] = array_unique($_REQUEST['u']); |
| 1925 | 2003 | |
@@ -1933,22 +2011,24 @@ discard block |
||
| 1933 | 2011 | 'limit' => count($_REQUEST['u']), |
| 1934 | 2012 | ) |
| 1935 | 2013 | ); |
| 1936 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1937 | - $context['recipients']['to'][] = array( |
|
| 2014 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2015 | + $context['recipients']['to'][] = array( |
|
| 1938 | 2016 | 'id' => $row['id_member'], |
| 1939 | 2017 | 'name' => $row['real_name'], |
| 1940 | 2018 | ); |
| 2019 | + } |
|
| 1941 | 2020 | $smcFunc['db_free_result']($request); |
| 1942 | 2021 | } |
| 1943 | 2022 | |
| 1944 | 2023 | // Get a literal name list in case the user has JavaScript disabled. |
| 1945 | 2024 | $names = array(); |
| 1946 | - foreach ($context['recipients']['to'] as $to) |
|
| 1947 | - $names[] = $to['name']; |
|
| 2025 | + foreach ($context['recipients']['to'] as $to) { |
|
| 2026 | + $names[] = $to['name']; |
|
| 2027 | + } |
|
| 1948 | 2028 | $context['to_value'] = empty($names) ? '' : '"' . implode('", "', $names) . '"'; |
| 2029 | + } else { |
|
| 2030 | + $context['to_value'] = ''; |
|
| 1949 | 2031 | } |
| 1950 | - else |
|
| 1951 | - $context['to_value'] = ''; |
|
| 1952 | 2032 | |
| 1953 | 2033 | // Set the defaults... |
| 1954 | 2034 | $context['subject'] = $form_subject; |
@@ -2018,8 +2098,9 @@ discard block |
||
| 2018 | 2098 | |
| 2019 | 2099 | // validate with loadMemberData() |
| 2020 | 2100 | $memberResult = loadMemberData($user_info['id'], false); |
| 2021 | - if (!$memberResult) |
|
| 2022 | - fatal_lang_error('not_a_user', false); |
|
| 2101 | + if (!$memberResult) { |
|
| 2102 | + fatal_lang_error('not_a_user', false); |
|
| 2103 | + } |
|
| 2023 | 2104 | list ($memID) = $memberResult; |
| 2024 | 2105 | |
| 2025 | 2106 | // drafts is where the functions reside |
@@ -2044,9 +2125,9 @@ discard block |
||
| 2044 | 2125 | $context['menu_data_' . $context['pm_menu_id']]['current_area'] = 'send'; $context['sub_template'] = 'send'; |
| 2045 | 2126 | loadJavaScriptFile('PersonalMessage.js', array('defer' => false), 'smf_pms'); |
| 2046 | 2127 | loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
| 2128 | + } else { |
|
| 2129 | + $context['sub_template'] = 'pm'; |
|
| 2047 | 2130 | } |
| 2048 | - else |
|
| 2049 | - $context['sub_template'] = 'pm'; |
|
| 2050 | 2131 | |
| 2051 | 2132 | $context['page_title'] = $txt['send_message']; |
| 2052 | 2133 | |
@@ -2107,10 +2188,11 @@ discard block |
||
| 2107 | 2188 | ); |
| 2108 | 2189 | if ($smcFunc['db_num_rows']($request) == 0) |
| 2109 | 2190 | { |
| 2110 | - if (!isset($_REQUEST['xml'])) |
|
| 2111 | - fatal_lang_error('pm_not_yours', false); |
|
| 2112 | - else |
|
| 2113 | - $error_types[] = 'pm_not_yours'; |
|
| 2191 | + if (!isset($_REQUEST['xml'])) { |
|
| 2192 | + fatal_lang_error('pm_not_yours', false); |
|
| 2193 | + } else { |
|
| 2194 | + $error_types[] = 'pm_not_yours'; |
|
| 2195 | + } |
|
| 2114 | 2196 | } |
| 2115 | 2197 | $row_quoted = $smcFunc['db_fetch_assoc']($request); |
| 2116 | 2198 | $smcFunc['db_free_result']($request); |
@@ -2157,14 +2239,16 @@ discard block |
||
| 2157 | 2239 | $context['post_error'][$error_type] = true; |
| 2158 | 2240 | if (isset($txt['error_' . $error_type])) |
| 2159 | 2241 | { |
| 2160 | - if ($error_type == 'long_message') |
|
| 2161 | - $txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']); |
|
| 2242 | + if ($error_type == 'long_message') { |
|
| 2243 | + $txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']); |
|
| 2244 | + } |
|
| 2162 | 2245 | $context['post_error']['messages'][] = $txt['error_' . $error_type]; |
| 2163 | 2246 | } |
| 2164 | 2247 | |
| 2165 | 2248 | // If it's not a minor error flag it as such. |
| 2166 | - if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'))) |
|
| 2167 | - $context['error_type'] = 'serious'; |
|
| 2249 | + if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'))) { |
|
| 2250 | + $context['error_type'] = 'serious'; |
|
| 2251 | + } |
|
| 2168 | 2252 | } |
| 2169 | 2253 | |
| 2170 | 2254 | // We need to load the editor once more. |
@@ -2222,8 +2306,9 @@ discard block |
||
| 2222 | 2306 | require_once($sourcedir . '/Subs-Auth.php'); |
| 2223 | 2307 | |
| 2224 | 2308 | // PM Drafts enabled and needed? |
| 2225 | - if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft']))) |
|
| 2226 | - require_once($sourcedir . '/Drafts.php'); |
|
| 2309 | + if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft']))) { |
|
| 2310 | + require_once($sourcedir . '/Drafts.php'); |
|
| 2311 | + } |
|
| 2227 | 2312 | |
| 2228 | 2313 | loadLanguage('PersonalMessage', '', false); |
| 2229 | 2314 | |
@@ -2253,24 +2338,27 @@ discard block |
||
| 2253 | 2338 | |
| 2254 | 2339 | if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) |
| 2255 | 2340 | { |
| 2256 | - if (!isset($_REQUEST['xml'])) |
|
| 2257 | - fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); |
|
| 2258 | - else |
|
| 2259 | - $post_errors[] = 'pm_too_many_per_hour'; |
|
| 2341 | + if (!isset($_REQUEST['xml'])) { |
|
| 2342 | + fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); |
|
| 2343 | + } else { |
|
| 2344 | + $post_errors[] = 'pm_too_many_per_hour'; |
|
| 2345 | + } |
|
| 2260 | 2346 | } |
| 2261 | 2347 | } |
| 2262 | 2348 | |
| 2263 | 2349 | // If your session timed out, show an error, but do allow to re-submit. |
| 2264 | - if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '') |
|
| 2265 | - $post_errors[] = 'session_timeout'; |
|
| 2350 | + if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '') { |
|
| 2351 | + $post_errors[] = 'session_timeout'; |
|
| 2352 | + } |
|
| 2266 | 2353 | |
| 2267 | 2354 | $_REQUEST['subject'] = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : ''; |
| 2268 | 2355 | $_REQUEST['to'] = empty($_POST['to']) ? (empty($_GET['to']) ? '' : $_GET['to']) : $_POST['to']; |
| 2269 | 2356 | $_REQUEST['bcc'] = empty($_POST['bcc']) ? (empty($_GET['bcc']) ? '' : $_GET['bcc']) : $_POST['bcc']; |
| 2270 | 2357 | |
| 2271 | 2358 | // Route the input from the 'u' parameter to the 'to'-list. |
| 2272 | - if (!empty($_POST['u'])) |
|
| 2273 | - $_POST['recipient_to'] = explode(',', $_POST['u']); |
|
| 2359 | + if (!empty($_POST['u'])) { |
|
| 2360 | + $_POST['recipient_to'] = explode(',', $_POST['u']); |
|
| 2361 | + } |
|
| 2274 | 2362 | |
| 2275 | 2363 | // Construct the list of recipients. |
| 2276 | 2364 | $recipientList = array(); |
@@ -2282,8 +2370,9 @@ discard block |
||
| 2282 | 2370 | $recipientList[$recipientType] = array(); |
| 2283 | 2371 | if (!empty($_POST['recipient_' . $recipientType]) && is_array($_POST['recipient_' . $recipientType])) |
| 2284 | 2372 | { |
| 2285 | - foreach ($_POST['recipient_' . $recipientType] as $recipient) |
|
| 2286 | - $recipientList[$recipientType][] = (int) $recipient; |
|
| 2373 | + foreach ($_POST['recipient_' . $recipientType] as $recipient) { |
|
| 2374 | + $recipientList[$recipientType][] = (int) $recipient; |
|
| 2375 | + } |
|
| 2287 | 2376 | } |
| 2288 | 2377 | |
| 2289 | 2378 | // Are there also literal names set? |
@@ -2297,10 +2386,11 @@ discard block |
||
| 2297 | 2386 | |
| 2298 | 2387 | foreach ($namedRecipientList[$recipientType] as $index => $recipient) |
| 2299 | 2388 | { |
| 2300 | - if (strlen(trim($recipient)) > 0) |
|
| 2301 | - $namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient))); |
|
| 2302 | - else |
|
| 2303 | - unset($namedRecipientList[$recipientType][$index]); |
|
| 2389 | + if (strlen(trim($recipient)) > 0) { |
|
| 2390 | + $namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient))); |
|
| 2391 | + } else { |
|
| 2392 | + unset($namedRecipientList[$recipientType][$index]); |
|
| 2393 | + } |
|
| 2304 | 2394 | } |
| 2305 | 2395 | |
| 2306 | 2396 | if (!empty($namedRecipientList[$recipientType])) |
@@ -2330,8 +2420,9 @@ discard block |
||
| 2330 | 2420 | } |
| 2331 | 2421 | |
| 2332 | 2422 | // Selected a recipient to be deleted? Remove them now. |
| 2333 | - if (!empty($_POST['delete_recipient'])) |
|
| 2334 | - $recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient'])); |
|
| 2423 | + if (!empty($_POST['delete_recipient'])) { |
|
| 2424 | + $recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient'])); |
|
| 2425 | + } |
|
| 2335 | 2426 | |
| 2336 | 2427 | // Make sure we don't include the same name twice |
| 2337 | 2428 | $recipientList[$recipientType] = array_unique($recipientList[$recipientType]); |
@@ -2341,8 +2432,9 @@ discard block |
||
| 2341 | 2432 | $is_recipient_change = !empty($_POST['delete_recipient']) || !empty($_POST['to_submit']) || !empty($_POST['bcc_submit']); |
| 2342 | 2433 | |
| 2343 | 2434 | // Check if there's at least one recipient. |
| 2344 | - if (empty($recipientList['to']) && empty($recipientList['bcc'])) |
|
| 2345 | - $post_errors[] = 'no_to'; |
|
| 2435 | + if (empty($recipientList['to']) && empty($recipientList['bcc'])) { |
|
| 2436 | + $post_errors[] = 'no_to'; |
|
| 2437 | + } |
|
| 2346 | 2438 | |
| 2347 | 2439 | // Make sure that we remove the members who did get it from the screen. |
| 2348 | 2440 | if (!$is_recipient_change) |
@@ -2356,28 +2448,31 @@ discard block |
||
| 2356 | 2448 | // Since we already have a post error, remove the previous one. |
| 2357 | 2449 | $post_errors = array_diff($post_errors, array('no_to')); |
| 2358 | 2450 | |
| 2359 | - foreach ($namesNotFound[$recipientType] as $name) |
|
| 2360 | - $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name); |
|
| 2451 | + foreach ($namesNotFound[$recipientType] as $name) { |
|
| 2452 | + $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name); |
|
| 2453 | + } |
|
| 2361 | 2454 | } |
| 2362 | 2455 | } |
| 2363 | 2456 | } |
| 2364 | 2457 | |
| 2365 | 2458 | // Did they make any mistakes? |
| 2366 | - if ($_REQUEST['subject'] == '') |
|
| 2367 | - $post_errors[] = 'no_subject'; |
|
| 2368 | - if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') |
|
| 2369 | - $post_errors[] = 'no_message'; |
|
| 2370 | - elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength']) |
|
| 2371 | - $post_errors[] = 'long_message'; |
|
| 2372 | - else |
|
| 2459 | + if ($_REQUEST['subject'] == '') { |
|
| 2460 | + $post_errors[] = 'no_subject'; |
|
| 2461 | + } |
|
| 2462 | + if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') { |
|
| 2463 | + $post_errors[] = 'no_message'; |
|
| 2464 | + } elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength']) { |
|
| 2465 | + $post_errors[] = 'long_message'; |
|
| 2466 | + } else |
|
| 2373 | 2467 | { |
| 2374 | 2468 | // Preparse the message. |
| 2375 | 2469 | $message = $_REQUEST['message']; |
| 2376 | 2470 | preparsecode($message); |
| 2377 | 2471 | |
| 2378 | 2472 | // Make sure there's still some content left without the tags. |
| 2379 | - if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false)) |
|
| 2380 | - $post_errors[] = 'no_message'; |
|
| 2473 | + if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false)) { |
|
| 2474 | + $post_errors[] = 'no_message'; |
|
| 2475 | + } |
|
| 2381 | 2476 | } |
| 2382 | 2477 | |
| 2383 | 2478 | // Wrong verification code? |
@@ -2389,13 +2484,15 @@ discard block |
||
| 2389 | 2484 | ); |
| 2390 | 2485 | $context['require_verification'] = create_control_verification($verificationOptions, true); |
| 2391 | 2486 | |
| 2392 | - if (is_array($context['require_verification'])) |
|
| 2393 | - $post_errors = array_merge($post_errors, $context['require_verification']); |
|
| 2487 | + if (is_array($context['require_verification'])) { |
|
| 2488 | + $post_errors = array_merge($post_errors, $context['require_verification']); |
|
| 2489 | + } |
|
| 2394 | 2490 | } |
| 2395 | 2491 | |
| 2396 | 2492 | // If they did, give a chance to make ammends. |
| 2397 | - if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml'])) |
|
| 2398 | - return messagePostError($post_errors, $namedRecipientList, $recipientList); |
|
| 2493 | + if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml'])) { |
|
| 2494 | + return messagePostError($post_errors, $namedRecipientList, $recipientList); |
|
| 2495 | + } |
|
| 2399 | 2496 | |
| 2400 | 2497 | // Want to take a second glance before you send? |
| 2401 | 2498 | if (isset($_REQUEST['preview'])) |
@@ -2426,8 +2523,9 @@ discard block |
||
| 2426 | 2523 | foreach ($namesNotFound as $recipientType => $names) |
| 2427 | 2524 | { |
| 2428 | 2525 | $post_errors[] = 'bad_' . $recipientType; |
| 2429 | - foreach ($names as $name) |
|
| 2430 | - $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name); |
|
| 2526 | + foreach ($names as $name) { |
|
| 2527 | + $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name); |
|
| 2528 | + } |
|
| 2431 | 2529 | } |
| 2432 | 2530 | |
| 2433 | 2531 | return messagePostError(array(), $namedRecipientList, $recipientList); |
@@ -2457,13 +2555,14 @@ discard block |
||
| 2457 | 2555 | checkSubmitOnce('check'); |
| 2458 | 2556 | |
| 2459 | 2557 | // Do the actual sending of the PM. |
| 2460 | - if (!empty($recipientList['to']) || !empty($recipientList['bcc'])) |
|
| 2461 | - $context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0); |
|
| 2462 | - else |
|
| 2463 | - $context['send_log'] = array( |
|
| 2558 | + if (!empty($recipientList['to']) || !empty($recipientList['bcc'])) { |
|
| 2559 | + $context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0); |
|
| 2560 | + } else { |
|
| 2561 | + $context['send_log'] = array( |
|
| 2464 | 2562 | 'sent' => array(), |
| 2465 | 2563 | 'failed' => array() |
| 2466 | 2564 | ); |
| 2565 | + } |
|
| 2467 | 2566 | |
| 2468 | 2567 | // Mark the message as "replied to". |
| 2469 | 2568 | if (!empty($context['send_log']['sent']) && !empty($_REQUEST['replied_to']) && isset($_REQUEST['f']) && $_REQUEST['f'] == 'inbox') |
@@ -2481,11 +2580,12 @@ discard block |
||
| 2481 | 2580 | } |
| 2482 | 2581 | |
| 2483 | 2582 | // If one or more of the recipient were invalid, go back to the post screen with the failed usernames. |
| 2484 | - if (!empty($context['send_log']['failed'])) |
|
| 2485 | - return messagePostError($post_errors, $namesNotFound, array( |
|
| 2583 | + if (!empty($context['send_log']['failed'])) { |
|
| 2584 | + return messagePostError($post_errors, $namesNotFound, array( |
|
| 2486 | 2585 | 'to' => array_intersect($recipientList['to'], $context['send_log']['failed']), |
| 2487 | 2586 | 'bcc' => array_intersect($recipientList['bcc'], $context['send_log']['failed']) |
| 2488 | 2587 | )); |
| 2588 | + } |
|
| 2489 | 2589 | |
| 2490 | 2590 | // Message sent successfully? |
| 2491 | 2591 | if (!empty($context['send_log']) && empty($context['send_log']['failed'])) |
@@ -2493,8 +2593,9 @@ discard block |
||
| 2493 | 2593 | $context['current_label_redirect'] = $context['current_label_redirect'] . ';done=sent'; |
| 2494 | 2594 | |
| 2495 | 2595 | // If we had a PM draft for this one, then its time to remove it since it was just sent |
| 2496 | - if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft'])) |
|
| 2497 | - DeleteDraft($_POST['id_pm_draft']); |
|
| 2596 | + if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft'])) { |
|
| 2597 | + DeleteDraft($_POST['id_pm_draft']); |
|
| 2598 | + } |
|
| 2498 | 2599 | } |
| 2499 | 2600 | |
| 2500 | 2601 | // Go back to the where they sent from, if possible... |
@@ -2509,24 +2610,28 @@ discard block |
||
| 2509 | 2610 | |
| 2510 | 2611 | checkSession('request'); |
| 2511 | 2612 | |
| 2512 | - if (isset($_REQUEST['del_selected'])) |
|
| 2513 | - $_REQUEST['pm_action'] = 'delete'; |
|
| 2613 | + if (isset($_REQUEST['del_selected'])) { |
|
| 2614 | + $_REQUEST['pm_action'] = 'delete'; |
|
| 2615 | + } |
|
| 2514 | 2616 | |
| 2515 | 2617 | if (isset($_REQUEST['pm_action']) && $_REQUEST['pm_action'] != '' && !empty($_REQUEST['pms']) && is_array($_REQUEST['pms'])) |
| 2516 | 2618 | { |
| 2517 | - foreach ($_REQUEST['pms'] as $pm) |
|
| 2518 | - $_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action']; |
|
| 2619 | + foreach ($_REQUEST['pms'] as $pm) { |
|
| 2620 | + $_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action']; |
|
| 2621 | + } |
|
| 2519 | 2622 | } |
| 2520 | 2623 | |
| 2521 | - if (empty($_REQUEST['pm_actions'])) |
|
| 2522 | - redirectexit($context['current_label_redirect']); |
|
| 2624 | + if (empty($_REQUEST['pm_actions'])) { |
|
| 2625 | + redirectexit($context['current_label_redirect']); |
|
| 2626 | + } |
|
| 2523 | 2627 | |
| 2524 | 2628 | // If we are in conversation, we may need to apply this to every message in the conversation. |
| 2525 | 2629 | if ($context['display_mode'] == 2 && isset($_REQUEST['conversation'])) |
| 2526 | 2630 | { |
| 2527 | 2631 | $id_pms = array(); |
| 2528 | - foreach ($_REQUEST['pm_actions'] as $pm => $dummy) |
|
| 2529 | - $id_pms[] = (int) $pm; |
|
| 2632 | + foreach ($_REQUEST['pm_actions'] as $pm => $dummy) { |
|
| 2633 | + $id_pms[] = (int) $pm; |
|
| 2634 | + } |
|
| 2530 | 2635 | |
| 2531 | 2636 | $request = $smcFunc['db_query']('', ' |
| 2532 | 2637 | SELECT id_pm_head, id_pm |
@@ -2537,8 +2642,9 @@ discard block |
||
| 2537 | 2642 | ) |
| 2538 | 2643 | ); |
| 2539 | 2644 | $pm_heads = array(); |
| 2540 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2541 | - $pm_heads[$row['id_pm_head']] = $row['id_pm']; |
|
| 2645 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2646 | + $pm_heads[$row['id_pm_head']] = $row['id_pm']; |
|
| 2647 | + } |
|
| 2542 | 2648 | $smcFunc['db_free_result']($request); |
| 2543 | 2649 | |
| 2544 | 2650 | $request = $smcFunc['db_query']('', ' |
@@ -2552,8 +2658,9 @@ discard block |
||
| 2552 | 2658 | // Copy the action from the single to PM to the others. |
| 2553 | 2659 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2554 | 2660 | { |
| 2555 | - if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]])) |
|
| 2556 | - $_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]]; |
|
| 2661 | + if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]])) { |
|
| 2662 | + $_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]]; |
|
| 2663 | + } |
|
| 2557 | 2664 | } |
| 2558 | 2665 | $smcFunc['db_free_result']($request); |
| 2559 | 2666 | } |
@@ -2565,22 +2672,21 @@ discard block |
||
| 2565 | 2672 | $labels = array(); |
| 2566 | 2673 | foreach ($_REQUEST['pm_actions'] as $pm => $action) |
| 2567 | 2674 | { |
| 2568 | - if ($action === 'delete') |
|
| 2569 | - $to_delete[] = (int) $pm; |
|
| 2570 | - else |
|
| 2675 | + if ($action === 'delete') { |
|
| 2676 | + $to_delete[] = (int) $pm; |
|
| 2677 | + } else |
|
| 2571 | 2678 | { |
| 2572 | 2679 | if (substr($action, 0, 4) == 'add_') |
| 2573 | 2680 | { |
| 2574 | 2681 | $type = 'add'; |
| 2575 | 2682 | $action = substr($action, 4); |
| 2576 | - } |
|
| 2577 | - elseif (substr($action, 0, 4) == 'rem_') |
|
| 2683 | + } elseif (substr($action, 0, 4) == 'rem_') |
|
| 2578 | 2684 | { |
| 2579 | 2685 | $type = 'rem'; |
| 2580 | 2686 | $action = substr($action, 4); |
| 2687 | + } else { |
|
| 2688 | + $type = 'unk'; |
|
| 2581 | 2689 | } |
| 2582 | - else |
|
| 2583 | - $type = 'unk'; |
|
| 2584 | 2690 | |
| 2585 | 2691 | if ($action == '-1' || (int) $action > 0) |
| 2586 | 2692 | { |
@@ -2591,8 +2697,9 @@ discard block |
||
| 2591 | 2697 | } |
| 2592 | 2698 | |
| 2593 | 2699 | // Deleting, it looks like? |
| 2594 | - if (!empty($to_delete)) |
|
| 2595 | - deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']); |
|
| 2700 | + if (!empty($to_delete)) { |
|
| 2701 | + deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']); |
|
| 2702 | + } |
|
| 2596 | 2703 | |
| 2597 | 2704 | // Are we labeling anything? |
| 2598 | 2705 | if (!empty($to_label) && $context['folder'] == 'inbox') |
@@ -2660,8 +2767,7 @@ discard block |
||
| 2660 | 2767 | } |
| 2661 | 2768 | |
| 2662 | 2769 | $smcFunc['db_free_result']($request2); |
| 2663 | - } |
|
| 2664 | - elseif ($type == 'rem') |
|
| 2770 | + } elseif ($type == 'rem') |
|
| 2665 | 2771 | { |
| 2666 | 2772 | // If we're removing from the inbox, see if we have at least one other label. |
| 2667 | 2773 | // This query is faster than the one above |
@@ -2693,21 +2799,25 @@ discard block |
||
| 2693 | 2799 | if ($to_label[$row['id_pm']] != '-1') |
| 2694 | 2800 | { |
| 2695 | 2801 | // If this label is in the list and we're not adding it, remove it |
| 2696 | - if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add') |
|
| 2697 | - unset($labels[$to_label[$row['id_pm']]]); |
|
| 2698 | - else if ($type !== 'rem') |
|
| 2699 | - $labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']]; |
|
| 2802 | + if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add') { |
|
| 2803 | + unset($labels[$to_label[$row['id_pm']]]); |
|
| 2804 | + } else if ($type !== 'rem') { |
|
| 2805 | + $labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']]; |
|
| 2806 | + } |
|
| 2700 | 2807 | } |
| 2701 | 2808 | |
| 2702 | 2809 | // Removing all labels or just removing the inbox label |
| 2703 | - if ($type == 'rem' && empty($labels)) |
|
| 2704 | - $in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0); |
|
| 2810 | + if ($type == 'rem' && empty($labels)) { |
|
| 2811 | + $in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0); |
|
| 2812 | + } |
|
| 2705 | 2813 | // Adding new labels, but removing inbox and applying new ones |
| 2706 | - elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels)) |
|
| 2707 | - $in_inbox = 0; |
|
| 2814 | + elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels)) { |
|
| 2815 | + $in_inbox = 0; |
|
| 2816 | + } |
|
| 2708 | 2817 | // Just adding it to the inbox |
| 2709 | - else |
|
| 2710 | - $in_inbox = 1; |
|
| 2818 | + else { |
|
| 2819 | + $in_inbox = 1; |
|
| 2820 | + } |
|
| 2711 | 2821 | |
| 2712 | 2822 | // Are we adding it to or removing it from the inbox? |
| 2713 | 2823 | if ($in_inbox != $row['in_inbox']) |
@@ -2749,8 +2859,9 @@ discard block |
||
| 2749 | 2859 | if (!empty($labels_to_apply)) |
| 2750 | 2860 | { |
| 2751 | 2861 | $inserts = array(); |
| 2752 | - foreach ($labels_to_apply as $label) |
|
| 2753 | - $inserts[] = array($row['id_pm'], $label); |
|
| 2862 | + foreach ($labels_to_apply as $label) { |
|
| 2863 | + $inserts[] = array($row['id_pm'], $label); |
|
| 2864 | + } |
|
| 2754 | 2865 | |
| 2755 | 2866 | $smcFunc['db_insert']('', |
| 2756 | 2867 | '{db_prefix}pm_labeled_messages', |
@@ -2794,11 +2905,13 @@ discard block |
||
| 2794 | 2905 | checkSession('get'); |
| 2795 | 2906 | |
| 2796 | 2907 | // If all then delete all messages the user has. |
| 2797 | - if ($_REQUEST['f'] == 'all') |
|
| 2798 | - deleteMessages(null, null); |
|
| 2908 | + if ($_REQUEST['f'] == 'all') { |
|
| 2909 | + deleteMessages(null, null); |
|
| 2910 | + } |
|
| 2799 | 2911 | // Otherwise just the selected folder. |
| 2800 | - else |
|
| 2801 | - deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent'); |
|
| 2912 | + else { |
|
| 2913 | + deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent'); |
|
| 2914 | + } |
|
| 2802 | 2915 | |
| 2803 | 2916 | // Done... all gone. |
| 2804 | 2917 | redirectexit($context['current_label_redirect']); |
@@ -2835,8 +2948,9 @@ discard block |
||
| 2835 | 2948 | 'msgtime' => $deleteTime, |
| 2836 | 2949 | ) |
| 2837 | 2950 | ); |
| 2838 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 2839 | - $toDelete[] = $row[0]; |
|
| 2951 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 2952 | + $toDelete[] = $row[0]; |
|
| 2953 | + } |
|
| 2840 | 2954 | $smcFunc['db_free_result']($request); |
| 2841 | 2955 | |
| 2842 | 2956 | // Select all messages in their inbox older than $deleteTime. |
@@ -2853,8 +2967,9 @@ discard block |
||
| 2853 | 2967 | 'msgtime' => $deleteTime, |
| 2854 | 2968 | ) |
| 2855 | 2969 | ); |
| 2856 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2857 | - $toDelete[] = $row['id_pm']; |
|
| 2970 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2971 | + $toDelete[] = $row['id_pm']; |
|
| 2972 | + } |
|
| 2858 | 2973 | $smcFunc['db_free_result']($request); |
| 2859 | 2974 | |
| 2860 | 2975 | // Delete the actual messages. |
@@ -2885,26 +3000,29 @@ discard block |
||
| 2885 | 3000 | { |
| 2886 | 3001 | global $user_info, $smcFunc; |
| 2887 | 3002 | |
| 2888 | - if ($owner === null) |
|
| 2889 | - $owner = array($user_info['id']); |
|
| 2890 | - elseif (empty($owner)) |
|
| 2891 | - return; |
|
| 2892 | - elseif (!is_array($owner)) |
|
| 2893 | - $owner = array($owner); |
|
| 3003 | + if ($owner === null) { |
|
| 3004 | + $owner = array($user_info['id']); |
|
| 3005 | + } elseif (empty($owner)) { |
|
| 3006 | + return; |
|
| 3007 | + } elseif (!is_array($owner)) { |
|
| 3008 | + $owner = array($owner); |
|
| 3009 | + } |
|
| 2894 | 3010 | |
| 2895 | 3011 | if ($personal_messages !== null) |
| 2896 | 3012 | { |
| 2897 | - if (empty($personal_messages) || !is_array($personal_messages)) |
|
| 2898 | - return; |
|
| 3013 | + if (empty($personal_messages) || !is_array($personal_messages)) { |
|
| 3014 | + return; |
|
| 3015 | + } |
|
| 2899 | 3016 | |
| 2900 | - foreach ($personal_messages as $index => $delete_id) |
|
| 2901 | - $personal_messages[$index] = (int) $delete_id; |
|
| 3017 | + foreach ($personal_messages as $index => $delete_id) { |
|
| 3018 | + $personal_messages[$index] = (int) $delete_id; |
|
| 3019 | + } |
|
| 2902 | 3020 | |
| 2903 | 3021 | $where = ' |
| 2904 | 3022 | AND id_pm IN ({array_int:pm_list})'; |
| 3023 | + } else { |
|
| 3024 | + $where = ''; |
|
| 2905 | 3025 | } |
| 2906 | - else |
|
| 2907 | - $where = ''; |
|
| 2908 | 3026 | |
| 2909 | 3027 | if ($folder == 'sent' || $folder === null) |
| 2910 | 3028 | { |
@@ -2939,17 +3057,19 @@ discard block |
||
| 2939 | 3057 | // ...And update the statistics accordingly - now including unread messages!. |
| 2940 | 3058 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2941 | 3059 | { |
| 2942 | - if ($row['is_read']) |
|
| 2943 | - updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'])); |
|
| 2944 | - else |
|
| 2945 | - updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages'])); |
|
| 3060 | + if ($row['is_read']) { |
|
| 3061 | + updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'])); |
|
| 3062 | + } else { |
|
| 3063 | + updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages'])); |
|
| 3064 | + } |
|
| 2946 | 3065 | |
| 2947 | 3066 | // If this is the current member we need to make their message count correct. |
| 2948 | 3067 | if ($user_info['id'] == $row['id_member']) |
| 2949 | 3068 | { |
| 2950 | 3069 | $user_info['messages'] -= $row['num_deleted_messages']; |
| 2951 | - if (!($row['is_read'])) |
|
| 2952 | - $user_info['unread_messages'] -= $row['num_deleted_messages']; |
|
| 3070 | + if (!($row['is_read'])) { |
|
| 3071 | + $user_info['unread_messages'] -= $row['num_deleted_messages']; |
|
| 3072 | + } |
|
| 2953 | 3073 | } |
| 2954 | 3074 | } |
| 2955 | 3075 | $smcFunc['db_free_result']($request); |
@@ -3017,8 +3137,9 @@ discard block |
||
| 3017 | 3137 | ) |
| 3018 | 3138 | ); |
| 3019 | 3139 | $remove_pms = array(); |
| 3020 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 3021 | - $remove_pms[] = $row['sender']; |
|
| 3140 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 3141 | + $remove_pms[] = $row['sender']; |
|
| 3142 | + } |
|
| 3022 | 3143 | $smcFunc['db_free_result']($request); |
| 3023 | 3144 | |
| 3024 | 3145 | if (!empty($remove_pms)) |
@@ -3063,8 +3184,9 @@ discard block |
||
| 3063 | 3184 | { |
| 3064 | 3185 | global $user_info, $context, $smcFunc; |
| 3065 | 3186 | |
| 3066 | - if ($owner === null) |
|
| 3067 | - $owner = $user_info['id']; |
|
| 3187 | + if ($owner === null) { |
|
| 3188 | + $owner = $user_info['id']; |
|
| 3189 | + } |
|
| 3068 | 3190 | |
| 3069 | 3191 | $in_inbox = ''; |
| 3070 | 3192 | |
@@ -3088,8 +3210,7 @@ discard block |
||
| 3088 | 3210 | } |
| 3089 | 3211 | |
| 3090 | 3212 | $smcFunc['db_free_result']($get_messages); |
| 3091 | - } |
|
| 3092 | - elseif ($label = '-1') |
|
| 3213 | + } elseif ($label = '-1') |
|
| 3093 | 3214 | { |
| 3094 | 3215 | // Marking all PMs in your inbox read |
| 3095 | 3216 | $in_inbox = ' |
@@ -3114,8 +3235,9 @@ discard block |
||
| 3114 | 3235 | { |
| 3115 | 3236 | if ($owner == $user_info['id']) |
| 3116 | 3237 | { |
| 3117 | - foreach ($context['labels'] as $label) |
|
| 3118 | - $context['labels'][(int) $label['id']]['unread_messages'] = 0; |
|
| 3238 | + foreach ($context['labels'] as $label) { |
|
| 3239 | + $context['labels'][(int) $label['id']]['unread_messages'] = 0; |
|
| 3240 | + } |
|
| 3119 | 3241 | } |
| 3120 | 3242 | |
| 3121 | 3243 | $result = $smcFunc['db_query']('', ' |
@@ -3135,8 +3257,9 @@ discard block |
||
| 3135 | 3257 | { |
| 3136 | 3258 | $total_unread += $row['num']; |
| 3137 | 3259 | |
| 3138 | - if ($owner != $user_info['id'] || empty($row['id_pm'])) |
|
| 3139 | - continue; |
|
| 3260 | + if ($owner != $user_info['id'] || empty($row['id_pm'])) { |
|
| 3261 | + continue; |
|
| 3262 | + } |
|
| 3140 | 3263 | |
| 3141 | 3264 | $this_labels = array(); |
| 3142 | 3265 | |
@@ -3160,11 +3283,13 @@ discard block |
||
| 3160 | 3283 | |
| 3161 | 3284 | $smcFunc['db_free_result']($result2); |
| 3162 | 3285 | |
| 3163 | - foreach ($this_labels as $this_label) |
|
| 3164 | - $context['labels'][$this_label]['unread_messages'] += $row['num']; |
|
| 3286 | + foreach ($this_labels as $this_label) { |
|
| 3287 | + $context['labels'][$this_label]['unread_messages'] += $row['num']; |
|
| 3288 | + } |
|
| 3165 | 3289 | |
| 3166 | - if ($row['in_inbox'] == 1) |
|
| 3167 | - $context['labels'][-1]['unread_messages'] += $row['num']; |
|
| 3290 | + if ($row['in_inbox'] == 1) { |
|
| 3291 | + $context['labels'][-1]['unread_messages'] += $row['num']; |
|
| 3292 | + } |
|
| 3168 | 3293 | } |
| 3169 | 3294 | $smcFunc['db_free_result']($result); |
| 3170 | 3295 | |
@@ -3173,8 +3298,9 @@ discard block |
||
| 3173 | 3298 | updateMemberData($owner, array('unread_messages' => $total_unread)); |
| 3174 | 3299 | |
| 3175 | 3300 | // If it was for the current member, reflect this in the $user_info array too. |
| 3176 | - if ($owner == $user_info['id']) |
|
| 3177 | - $user_info['unread_messages'] = $total_unread; |
|
| 3301 | + if ($owner == $user_info['id']) { |
|
| 3302 | + $user_info['unread_messages'] = $total_unread; |
|
| 3303 | + } |
|
| 3178 | 3304 | } |
| 3179 | 3305 | } |
| 3180 | 3306 | |
@@ -3202,8 +3328,9 @@ discard block |
||
| 3202 | 3328 | // Add all existing labels to the array to save, slashing them as necessary... |
| 3203 | 3329 | foreach ($context['labels'] as $label) |
| 3204 | 3330 | { |
| 3205 | - if ($label['id'] != -1) |
|
| 3206 | - $the_labels[$label['id']] = $label['name']; |
|
| 3331 | + if ($label['id'] != -1) { |
|
| 3332 | + $the_labels[$label['id']] = $label['name']; |
|
| 3333 | + } |
|
| 3207 | 3334 | } |
| 3208 | 3335 | |
| 3209 | 3336 | if (isset($_POST[$context['session_var']])) |
@@ -3222,8 +3349,9 @@ discard block |
||
| 3222 | 3349 | { |
| 3223 | 3350 | $_POST['label'] = strtr($smcFunc['htmlspecialchars'](trim($_POST['label'])), array(',' => ',')); |
| 3224 | 3351 | |
| 3225 | - if ($smcFunc['strlen']($_POST['label']) > 30) |
|
| 3226 | - $_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30); |
|
| 3352 | + if ($smcFunc['strlen']($_POST['label']) > 30) { |
|
| 3353 | + $_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30); |
|
| 3354 | + } |
|
| 3227 | 3355 | if ($_POST['label'] != '') |
| 3228 | 3356 | { |
| 3229 | 3357 | $the_labels[] = $_POST['label']; |
@@ -3244,24 +3372,25 @@ discard block |
||
| 3244 | 3372 | { |
| 3245 | 3373 | foreach ($the_labels as $id => $name) |
| 3246 | 3374 | { |
| 3247 | - if ($id == -1) |
|
| 3248 | - continue; |
|
| 3249 | - elseif (isset($_POST['label_name'][$id])) |
|
| 3375 | + if ($id == -1) { |
|
| 3376 | + continue; |
|
| 3377 | + } elseif (isset($_POST['label_name'][$id])) |
|
| 3250 | 3378 | { |
| 3251 | 3379 | $_POST['label_name'][$id] = trim(strtr($smcFunc['htmlspecialchars']($_POST['label_name'][$id]), array(',' => ','))); |
| 3252 | 3380 | |
| 3253 | - if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30) |
|
| 3254 | - $_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30); |
|
| 3381 | + if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30) { |
|
| 3382 | + $_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30); |
|
| 3383 | + } |
|
| 3255 | 3384 | if ($_POST['label_name'][$id] != '') |
| 3256 | 3385 | { |
| 3257 | 3386 | // Changing the name of this label? |
| 3258 | - if ($the_labels[$id] != $_POST['label_name'][$id]) |
|
| 3259 | - $label_updates[$id] = $_POST['label_name'][$id]; |
|
| 3387 | + if ($the_labels[$id] != $_POST['label_name'][$id]) { |
|
| 3388 | + $label_updates[$id] = $_POST['label_name'][$id]; |
|
| 3389 | + } |
|
| 3260 | 3390 | |
| 3261 | 3391 | $the_labels[(int) $id] = $_POST['label_name'][$id]; |
| 3262 | 3392 | |
| 3263 | - } |
|
| 3264 | - else |
|
| 3393 | + } else |
|
| 3265 | 3394 | { |
| 3266 | 3395 | unset($the_labels[(int) $id]); |
| 3267 | 3396 | $labels_to_remove[] = $id; |
@@ -3275,8 +3404,9 @@ discard block |
||
| 3275 | 3404 | if (!empty($labels_to_add)) |
| 3276 | 3405 | { |
| 3277 | 3406 | $inserts = array(); |
| 3278 | - foreach ($labels_to_add AS $label) |
|
| 3279 | - $inserts[] = array($user_info['id'], $label); |
|
| 3407 | + foreach ($labels_to_add AS $label) { |
|
| 3408 | + $inserts[] = array($user_info['id'], $label); |
|
| 3409 | + } |
|
| 3280 | 3410 | |
| 3281 | 3411 | $smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array()); |
| 3282 | 3412 | } |
@@ -3366,8 +3496,9 @@ discard block |
||
| 3366 | 3496 | // Each action... |
| 3367 | 3497 | foreach ($rule['actions'] as $k2 => $action) |
| 3368 | 3498 | { |
| 3369 | - if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove)) |
|
| 3370 | - continue; |
|
| 3499 | + if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove)) { |
|
| 3500 | + continue; |
|
| 3501 | + } |
|
| 3371 | 3502 | |
| 3372 | 3503 | $rule_changes[] = $rule['id']; |
| 3373 | 3504 | |
@@ -3382,8 +3513,8 @@ discard block |
||
| 3382 | 3513 | { |
| 3383 | 3514 | $rule_changes = array_unique($rule_changes); |
| 3384 | 3515 | // Update/delete as appropriate. |
| 3385 | - foreach ($rule_changes as $k => $id) |
|
| 3386 | - if (!empty($context['rules'][$id]['actions'])) |
|
| 3516 | + foreach ($rule_changes as $k => $id) { |
|
| 3517 | + if (!empty($context['rules'][$id]['actions'])) |
|
| 3387 | 3518 | { |
| 3388 | 3519 | $smcFunc['db_query']('', ' |
| 3389 | 3520 | UPDATE {db_prefix}pm_rules |
@@ -3396,12 +3527,13 @@ discard block |
||
| 3396 | 3527 | 'actions' => json_encode($context['rules'][$id]['actions']), |
| 3397 | 3528 | ) |
| 3398 | 3529 | ); |
| 3530 | + } |
|
| 3399 | 3531 | unset($rule_changes[$k]); |
| 3400 | 3532 | } |
| 3401 | 3533 | |
| 3402 | 3534 | // Anything left here means it's lost all actions... |
| 3403 | - if (!empty($rule_changes)) |
|
| 3404 | - $smcFunc['db_query']('', ' |
|
| 3535 | + if (!empty($rule_changes)) { |
|
| 3536 | + $smcFunc['db_query']('', ' |
|
| 3405 | 3537 | DELETE FROM {db_prefix}pm_rules |
| 3406 | 3538 | WHERE id_rule IN ({array_int:rule_list}) |
| 3407 | 3539 | AND id_member = {int:current_member}', |
@@ -3410,6 +3542,7 @@ discard block |
||
| 3410 | 3542 | 'rule_list' => $rule_changes, |
| 3411 | 3543 | ) |
| 3412 | 3544 | ); |
| 3545 | + } |
|
| 3413 | 3546 | } |
| 3414 | 3547 | |
| 3415 | 3548 | // Make sure we're not caching this! |
@@ -3479,8 +3612,9 @@ discard block |
||
| 3479 | 3612 | // Save the fields. |
| 3480 | 3613 | saveProfileFields(); |
| 3481 | 3614 | |
| 3482 | - if (!empty($profile_vars)) |
|
| 3483 | - updateMemberData($user_info['id'], $profile_vars); |
|
| 3615 | + if (!empty($profile_vars)) { |
|
| 3616 | + updateMemberData($user_info['id'], $profile_vars); |
|
| 3617 | + } |
|
| 3484 | 3618 | } |
| 3485 | 3619 | |
| 3486 | 3620 | setupProfileContext( |
@@ -3505,13 +3639,15 @@ discard block |
||
| 3505 | 3639 | global $user_info, $language, $modSettings, $smcFunc; |
| 3506 | 3640 | |
| 3507 | 3641 | // Check that this feature is even enabled! |
| 3508 | - if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg'])) |
|
| 3509 | - fatal_lang_error('no_access', false); |
|
| 3642 | + if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg'])) { |
|
| 3643 | + fatal_lang_error('no_access', false); |
|
| 3644 | + } |
|
| 3510 | 3645 | |
| 3511 | 3646 | $pmsg = (int) $_REQUEST['pmsg']; |
| 3512 | 3647 | |
| 3513 | - if (!isAccessiblePM($pmsg, 'inbox')) |
|
| 3514 | - fatal_lang_error('no_access', false); |
|
| 3648 | + if (!isAccessiblePM($pmsg, 'inbox')) { |
|
| 3649 | + fatal_lang_error('no_access', false); |
|
| 3650 | + } |
|
| 3515 | 3651 | |
| 3516 | 3652 | $context['pm_id'] = $pmsg; |
| 3517 | 3653 | $context['page_title'] = $txt['pm_report_title']; |
@@ -3533,8 +3669,9 @@ discard block |
||
| 3533 | 3669 | ) |
| 3534 | 3670 | ); |
| 3535 | 3671 | $context['admins'] = array(); |
| 3536 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 3537 | - $context['admins'][$row['id_member']] = $row['real_name']; |
|
| 3672 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 3673 | + $context['admins'][$row['id_member']] = $row['real_name']; |
|
| 3674 | + } |
|
| 3538 | 3675 | $smcFunc['db_free_result']($request); |
| 3539 | 3676 | |
| 3540 | 3677 | // How many admins in total? |
@@ -3563,8 +3700,9 @@ discard block |
||
| 3563 | 3700 | ) |
| 3564 | 3701 | ); |
| 3565 | 3702 | // Can only be a hacker here! |
| 3566 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 3567 | - fatal_lang_error('no_access', false); |
|
| 3703 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 3704 | + fatal_lang_error('no_access', false); |
|
| 3705 | + } |
|
| 3568 | 3706 | list ($subject, $body, $time, $memberFromID, $memberFromName) = $smcFunc['db_fetch_row']($request); |
| 3569 | 3707 | $smcFunc['db_free_result']($request); |
| 3570 | 3708 | |
@@ -3588,15 +3726,17 @@ discard block |
||
| 3588 | 3726 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 3589 | 3727 | { |
| 3590 | 3728 | // If it's hidden still don't reveal their names - privacy after all ;) |
| 3591 | - if ($row['bcc']) |
|
| 3592 | - $hidden_recipients++; |
|
| 3593 | - else |
|
| 3594 | - $recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]'; |
|
| 3729 | + if ($row['bcc']) { |
|
| 3730 | + $hidden_recipients++; |
|
| 3731 | + } else { |
|
| 3732 | + $recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]'; |
|
| 3733 | + } |
|
| 3595 | 3734 | } |
| 3596 | 3735 | $smcFunc['db_free_result']($request); |
| 3597 | 3736 | |
| 3598 | - if ($hidden_recipients) |
|
| 3599 | - $recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients); |
|
| 3737 | + if ($hidden_recipients) { |
|
| 3738 | + $recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients); |
|
| 3739 | + } |
|
| 3600 | 3740 | |
| 3601 | 3741 | // Now let's get out and loop through the admins. |
| 3602 | 3742 | $request = $smcFunc['db_query']('', ' |
@@ -3612,8 +3752,9 @@ discard block |
||
| 3612 | 3752 | ); |
| 3613 | 3753 | |
| 3614 | 3754 | // Maybe we shouldn't advertise this? |
| 3615 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 3616 | - fatal_lang_error('no_access', false); |
|
| 3755 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 3756 | + fatal_lang_error('no_access', false); |
|
| 3757 | + } |
|
| 3617 | 3758 | |
| 3618 | 3759 | $memberFromName = un_htmlspecialchars($memberFromName); |
| 3619 | 3760 | |
@@ -3632,8 +3773,9 @@ discard block |
||
| 3632 | 3773 | // Make the body. |
| 3633 | 3774 | $report_body = str_replace(array('{REPORTER}', '{SENDER}'), array(un_htmlspecialchars($user_info['name']), $memberFromName), $txt['pm_report_pm_user_sent']); |
| 3634 | 3775 | $report_body .= "\n" . '[b]' . $_POST['reason'] . '[/b]' . "\n\n"; |
| 3635 | - if (!empty($recipients)) |
|
| 3636 | - $report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n"; |
|
| 3776 | + if (!empty($recipients)) { |
|
| 3777 | + $report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n"; |
|
| 3778 | + } |
|
| 3637 | 3779 | $report_body .= $txt['pm_report_pm_unedited_below'] . "\n" . '[quote author=' . (empty($memberFromID) ? '"' . $memberFromName . '"' : $memberFromName . ' link=action=profile;u=' . $memberFromID . ' date=' . $time) . ']' . "\n" . un_htmlspecialchars($body) . '[/quote]'; |
| 3638 | 3780 | |
| 3639 | 3781 | // Plonk it in the array ;) |
@@ -3653,12 +3795,14 @@ discard block |
||
| 3653 | 3795 | $smcFunc['db_free_result']($request); |
| 3654 | 3796 | |
| 3655 | 3797 | // Send a different email for each language. |
| 3656 | - foreach ($messagesToSend as $lang => $message) |
|
| 3657 | - sendpm($message['recipients'], $message['subject'], $message['body']); |
|
| 3798 | + foreach ($messagesToSend as $lang => $message) { |
|
| 3799 | + sendpm($message['recipients'], $message['subject'], $message['body']); |
|
| 3800 | + } |
|
| 3658 | 3801 | |
| 3659 | 3802 | // Give the user their own language back! |
| 3660 | - if (!empty($modSettings['userLanguage'])) |
|
| 3661 | - loadLanguage('PersonalMessage', '', false); |
|
| 3803 | + if (!empty($modSettings['userLanguage'])) { |
|
| 3804 | + loadLanguage('PersonalMessage', '', false); |
|
| 3805 | + } |
|
| 3662 | 3806 | |
| 3663 | 3807 | // Leave them with a template. |
| 3664 | 3808 | $context['sub_template'] = 'report_message_complete'; |
@@ -3704,8 +3848,9 @@ discard block |
||
| 3704 | 3848 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 3705 | 3849 | { |
| 3706 | 3850 | // Hide hidden groups! |
| 3707 | - if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) |
|
| 3708 | - continue; |
|
| 3851 | + if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) { |
|
| 3852 | + continue; |
|
| 3853 | + } |
|
| 3709 | 3854 | |
| 3710 | 3855 | $context['groups'][$row['id_group']] = $row['group_name']; |
| 3711 | 3856 | } |
@@ -3731,9 +3876,10 @@ discard block |
||
| 3731 | 3876 | $context['rule'] = $context['rules'][$context['rid']]; |
| 3732 | 3877 | $members = array(); |
| 3733 | 3878 | // Need to get member names! |
| 3734 | - foreach ($context['rule']['criteria'] as $k => $criteria) |
|
| 3735 | - if ($criteria['t'] == 'mid' && !empty($criteria['v'])) |
|
| 3879 | + foreach ($context['rule']['criteria'] as $k => $criteria) { |
|
| 3880 | + if ($criteria['t'] == 'mid' && !empty($criteria['v'])) |
|
| 3736 | 3881 | $members[(int) $criteria['v']] = $k; |
| 3882 | + } |
|
| 3737 | 3883 | |
| 3738 | 3884 | if (!empty($members)) |
| 3739 | 3885 | { |
@@ -3745,19 +3891,20 @@ discard block |
||
| 3745 | 3891 | 'member_list' => array_keys($members), |
| 3746 | 3892 | ) |
| 3747 | 3893 | ); |
| 3748 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 3749 | - $context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name']; |
|
| 3894 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 3895 | + $context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name']; |
|
| 3896 | + } |
|
| 3750 | 3897 | $smcFunc['db_free_result']($request); |
| 3751 | 3898 | } |
| 3752 | - } |
|
| 3753 | - else |
|
| 3754 | - $context['rule'] = array( |
|
| 3899 | + } else { |
|
| 3900 | + $context['rule'] = array( |
|
| 3755 | 3901 | 'id' => '', |
| 3756 | 3902 | 'name' => '', |
| 3757 | 3903 | 'criteria' => array(), |
| 3758 | 3904 | 'actions' => array(), |
| 3759 | 3905 | 'logic' => 'and', |
| 3760 | 3906 | ); |
| 3907 | + } |
|
| 3761 | 3908 | } |
| 3762 | 3909 | // Saving? |
| 3763 | 3910 | elseif (isset($_GET['save'])) |
@@ -3767,22 +3914,25 @@ discard block |
||
| 3767 | 3914 | |
| 3768 | 3915 | // Name is easy! |
| 3769 | 3916 | $ruleName = $smcFunc['htmlspecialchars'](trim($_POST['rule_name'])); |
| 3770 | - if (empty($ruleName)) |
|
| 3771 | - fatal_lang_error('pm_rule_no_name', false); |
|
| 3917 | + if (empty($ruleName)) { |
|
| 3918 | + fatal_lang_error('pm_rule_no_name', false); |
|
| 3919 | + } |
|
| 3772 | 3920 | |
| 3773 | 3921 | // Sanity check... |
| 3774 | - if (empty($_POST['ruletype']) || empty($_POST['acttype'])) |
|
| 3775 | - fatal_lang_error('pm_rule_no_criteria', false); |
|
| 3922 | + if (empty($_POST['ruletype']) || empty($_POST['acttype'])) { |
|
| 3923 | + fatal_lang_error('pm_rule_no_criteria', false); |
|
| 3924 | + } |
|
| 3776 | 3925 | |
| 3777 | 3926 | // Let's do the criteria first - it's also hardest! |
| 3778 | 3927 | $criteria = array(); |
| 3779 | 3928 | foreach ($_POST['ruletype'] as $ind => $type) |
| 3780 | 3929 | { |
| 3781 | 3930 | // Check everything is here... |
| 3782 | - if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]]))) |
|
| 3783 | - continue; |
|
| 3784 | - elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind])) |
|
| 3785 | - continue; |
|
| 3931 | + if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]]))) { |
|
| 3932 | + continue; |
|
| 3933 | + } elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind])) { |
|
| 3934 | + continue; |
|
| 3935 | + } |
|
| 3786 | 3936 | |
| 3787 | 3937 | // Members need to be found. |
| 3788 | 3938 | if ($type == 'mid') |
@@ -3806,13 +3956,13 @@ discard block |
||
| 3806 | 3956 | $smcFunc['db_free_result']($request); |
| 3807 | 3957 | |
| 3808 | 3958 | $criteria[] = array('t' => 'mid', 'v' => $memID); |
| 3959 | + } elseif ($type == 'bud') { |
|
| 3960 | + $criteria[] = array('t' => 'bud', 'v' => 1); |
|
| 3961 | + } elseif ($type == 'gid') { |
|
| 3962 | + $criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]); |
|
| 3963 | + } elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') { |
|
| 3964 | + $criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind]))); |
|
| 3809 | 3965 | } |
| 3810 | - elseif ($type == 'bud') |
|
| 3811 | - $criteria[] = array('t' => 'bud', 'v' => 1); |
|
| 3812 | - elseif ($type == 'gid') |
|
| 3813 | - $criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]); |
|
| 3814 | - elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') |
|
| 3815 | - $criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind]))); |
|
| 3816 | 3966 | } |
| 3817 | 3967 | |
| 3818 | 3968 | // Also do the actions! |
@@ -3822,26 +3972,29 @@ discard block |
||
| 3822 | 3972 | foreach ($_POST['acttype'] as $ind => $type) |
| 3823 | 3973 | { |
| 3824 | 3974 | // Picking a valid label? |
| 3825 | - if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]]))) |
|
| 3826 | - continue; |
|
| 3975 | + if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]]))) { |
|
| 3976 | + continue; |
|
| 3977 | + } |
|
| 3827 | 3978 | |
| 3828 | 3979 | // Record what we're doing. |
| 3829 | - if ($type == 'del') |
|
| 3830 | - $doDelete = 1; |
|
| 3831 | - elseif ($type == 'lab') |
|
| 3832 | - $actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]); |
|
| 3980 | + if ($type == 'del') { |
|
| 3981 | + $doDelete = 1; |
|
| 3982 | + } elseif ($type == 'lab') { |
|
| 3983 | + $actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]); |
|
| 3984 | + } |
|
| 3833 | 3985 | } |
| 3834 | 3986 | |
| 3835 | - if (empty($criteria) || (empty($actions) && !$doDelete)) |
|
| 3836 | - fatal_lang_error('pm_rule_no_criteria', false); |
|
| 3987 | + if (empty($criteria) || (empty($actions) && !$doDelete)) { |
|
| 3988 | + fatal_lang_error('pm_rule_no_criteria', false); |
|
| 3989 | + } |
|
| 3837 | 3990 | |
| 3838 | 3991 | // What are we storing? |
| 3839 | 3992 | $criteria = json_encode($criteria); |
| 3840 | 3993 | $actions = json_encode($actions); |
| 3841 | 3994 | |
| 3842 | 3995 | // Create the rule? |
| 3843 | - if (empty($context['rid'])) |
|
| 3844 | - $smcFunc['db_insert']('', |
|
| 3996 | + if (empty($context['rid'])) { |
|
| 3997 | + $smcFunc['db_insert']('', |
|
| 3845 | 3998 | '{db_prefix}pm_rules', |
| 3846 | 3999 | array( |
| 3847 | 4000 | 'id_member' => 'int', 'rule_name' => 'string', 'criteria' => 'string', 'actions' => 'string', |
@@ -3852,8 +4005,8 @@ discard block |
||
| 3852 | 4005 | ), |
| 3853 | 4006 | array('id_rule') |
| 3854 | 4007 | ); |
| 3855 | - else |
|
| 3856 | - $smcFunc['db_query']('', ' |
|
| 4008 | + } else { |
|
| 4009 | + $smcFunc['db_query']('', ' |
|
| 3857 | 4010 | UPDATE {db_prefix}pm_rules |
| 3858 | 4011 | SET rule_name = {string:rule_name}, criteria = {string:criteria}, actions = {string:actions}, |
| 3859 | 4012 | delete_pm = {int:delete_pm}, is_or = {int:is_or} |
@@ -3869,6 +4022,7 @@ discard block |
||
| 3869 | 4022 | 'actions' => $actions, |
| 3870 | 4023 | ) |
| 3871 | 4024 | ); |
| 4025 | + } |
|
| 3872 | 4026 | |
| 3873 | 4027 | redirectexit('action=pm;sa=manrules'); |
| 3874 | 4028 | } |
@@ -3877,11 +4031,12 @@ discard block |
||
| 3877 | 4031 | { |
| 3878 | 4032 | checkSession(); |
| 3879 | 4033 | $toDelete = array(); |
| 3880 | - foreach ($_POST['delrule'] as $k => $v) |
|
| 3881 | - $toDelete[] = (int) $k; |
|
| 4034 | + foreach ($_POST['delrule'] as $k => $v) { |
|
| 4035 | + $toDelete[] = (int) $k; |
|
| 4036 | + } |
|
| 3882 | 4037 | |
| 3883 | - if (!empty($toDelete)) |
|
| 3884 | - $smcFunc['db_query']('', ' |
|
| 4038 | + if (!empty($toDelete)) { |
|
| 4039 | + $smcFunc['db_query']('', ' |
|
| 3885 | 4040 | DELETE FROM {db_prefix}pm_rules |
| 3886 | 4041 | WHERE id_rule IN ({array_int:delete_list}) |
| 3887 | 4042 | AND id_member = {int:current_member}', |
@@ -3890,6 +4045,7 @@ discard block |
||
| 3890 | 4045 | 'delete_list' => $toDelete, |
| 3891 | 4046 | ) |
| 3892 | 4047 | ); |
| 4048 | + } |
|
| 3893 | 4049 | |
| 3894 | 4050 | redirectexit('action=pm;sa=manrules'); |
| 3895 | 4051 | } |
@@ -3908,8 +4064,9 @@ discard block |
||
| 3908 | 4064 | loadRules(); |
| 3909 | 4065 | |
| 3910 | 4066 | // No rules? |
| 3911 | - if (empty($context['rules'])) |
|
| 3912 | - return; |
|
| 4067 | + if (empty($context['rules'])) { |
|
| 4068 | + return; |
|
| 4069 | + } |
|
| 3913 | 4070 | |
| 3914 | 4071 | // Just unread ones? |
| 3915 | 4072 | $ruleQuery = $all_messages ? '' : ' AND pmr.is_new = 1'; |
@@ -3939,8 +4096,9 @@ discard block |
||
| 3939 | 4096 | // Loop through all the criteria hoping to make a match. |
| 3940 | 4097 | foreach ($rule['criteria'] as $criterium) |
| 3941 | 4098 | { |
| 3942 | - if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false)) |
|
| 3943 | - $match = true; |
|
| 4099 | + if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false)) { |
|
| 4100 | + $match = true; |
|
| 4101 | + } |
|
| 3944 | 4102 | // If we're adding and one criteria don't match then we stop! |
| 3945 | 4103 | elseif ($rule['logic'] == 'and') |
| 3946 | 4104 | { |
@@ -3952,17 +4110,18 @@ discard block |
||
| 3952 | 4110 | // If we have a match the rule must be true - act! |
| 3953 | 4111 | if ($match) |
| 3954 | 4112 | { |
| 3955 | - if ($rule['delete']) |
|
| 3956 | - $actions['deletes'][] = $row['id_pm']; |
|
| 3957 | - else |
|
| 4113 | + if ($rule['delete']) { |
|
| 4114 | + $actions['deletes'][] = $row['id_pm']; |
|
| 4115 | + } else |
|
| 3958 | 4116 | { |
| 3959 | 4117 | foreach ($rule['actions'] as $ruleAction) |
| 3960 | 4118 | { |
| 3961 | 4119 | if ($ruleAction['t'] == 'lab') |
| 3962 | 4120 | { |
| 3963 | 4121 | // Get a basic pot started! |
| 3964 | - if (!isset($actions['labels'][$row['id_pm']])) |
|
| 3965 | - $actions['labels'][$row['id_pm']] = array(); |
|
| 4122 | + if (!isset($actions['labels'][$row['id_pm']])) { |
|
| 4123 | + $actions['labels'][$row['id_pm']] = array(); |
|
| 4124 | + } |
|
| 3966 | 4125 | $actions['labels'][$row['id_pm']][] = $ruleAction['v']; |
| 3967 | 4126 | } |
| 3968 | 4127 | } |
@@ -3973,8 +4132,9 @@ discard block |
||
| 3973 | 4132 | $smcFunc['db_free_result']($request); |
| 3974 | 4133 | |
| 3975 | 4134 | // Deletes are easy! |
| 3976 | - if (!empty($actions['deletes'])) |
|
| 3977 | - deleteMessages($actions['deletes']); |
|
| 4135 | + if (!empty($actions['deletes'])) { |
|
| 4136 | + deleteMessages($actions['deletes']); |
|
| 4137 | + } |
|
| 3978 | 4138 | |
| 3979 | 4139 | // Relabel? |
| 3980 | 4140 | if (!empty($actions['labels'])) |
@@ -4001,8 +4161,7 @@ discard block |
||
| 4001 | 4161 | 'current_member' => $user_info['id'], |
| 4002 | 4162 | ) |
| 4003 | 4163 | ); |
| 4004 | - } |
|
| 4005 | - else |
|
| 4164 | + } else |
|
| 4006 | 4165 | { |
| 4007 | 4166 | $realLabels[] = $label['id']; |
| 4008 | 4167 | } |
@@ -4011,8 +4170,9 @@ discard block |
||
| 4011 | 4170 | |
| 4012 | 4171 | $inserts = array(); |
| 4013 | 4172 | // Now we insert the label info |
| 4014 | - foreach ($realLabels as $a_label) |
|
| 4015 | - $inserts[] = array($pm, $a_label); |
|
| 4173 | + foreach ($realLabels as $a_label) { |
|
| 4174 | + $inserts[] = array($pm, $a_label); |
|
| 4175 | + } |
|
| 4016 | 4176 | |
| 4017 | 4177 | $smcFunc['db_insert']('ignore', |
| 4018 | 4178 | '{db_prefix}pm_labeled_messages', |
@@ -4033,8 +4193,9 @@ discard block |
||
| 4033 | 4193 | { |
| 4034 | 4194 | global $user_info, $context, $smcFunc; |
| 4035 | 4195 | |
| 4036 | - if (isset($context['rules']) && !$reload) |
|
| 4037 | - return; |
|
| 4196 | + if (isset($context['rules']) && !$reload) { |
|
| 4197 | + return; |
|
| 4198 | + } |
|
| 4038 | 4199 | |
| 4039 | 4200 | $request = $smcFunc['db_query']('', ' |
| 4040 | 4201 | SELECT |
@@ -4058,8 +4219,9 @@ discard block |
||
| 4058 | 4219 | 'logic' => $row['is_or'] ? 'or' : 'and', |
| 4059 | 4220 | ); |
| 4060 | 4221 | |
| 4061 | - if ($row['delete_pm']) |
|
| 4062 | - $context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1); |
|
| 4222 | + if ($row['delete_pm']) { |
|
| 4223 | + $context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1); |
|
| 4224 | + } |
|
| 4063 | 4225 | } |
| 4064 | 4226 | $smcFunc['db_free_result']($request); |
| 4065 | 4227 | } |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | else |
| 238 | 238 | { |
| 239 | 239 | $query_this_board = '{query_wanna_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' |
| 240 | - AND b.id_board != {int:recycle_board}' : ''). ' |
|
| 240 | + AND b.id_board != {int:recycle_board}' : '') . ' |
|
| 241 | 241 | AND m.id_msg >= {int:max_id_msg}'; |
| 242 | 242 | $query_parameters['max_id_msg'] = max(0, $modSettings['maxMsgID'] - 100 - $_REQUEST['start'] * 6); |
| 243 | 243 | $query_parameters['recycle_board'] = $modSettings['recycle_board']; |
@@ -1124,7 +1124,7 @@ discard block |
||
| 1124 | 1124 | ); |
| 1125 | 1125 | else |
| 1126 | 1126 | $request = $smcFunc['db_query']('', ' |
| 1127 | - SELECT DISTINCT t.id_topic,'.$_REQUEST['sort'].' |
|
| 1127 | + SELECT DISTINCT t.id_topic,'.$_REQUEST['sort'] . ' |
|
| 1128 | 1128 | FROM {db_prefix}topics AS t |
| 1129 | 1129 | INNER JOIN {db_prefix}messages AS m ON (m.id_topic = t.id_topic AND m.id_member = {int:current_member})' . (strpos($_REQUEST['sort'], 'ms.') === false ? '' : ' |
| 1130 | 1130 | INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)') . (strpos($_REQUEST['sort'], 'mems.') === false ? '' : ' |
@@ -1391,7 +1391,7 @@ discard block |
||
| 1391 | 1391 | if ($is_topics) |
| 1392 | 1392 | { |
| 1393 | 1393 | $context['recent_buttons'] = array( |
| 1394 | - 'markread' => array('text' => !empty($context['no_board_limits']) ? 'mark_as_read' : 'mark_read_short', 'image' => 'markread.png', 'custom' => 'data-confirm="'. $txt['are_sure_mark_read'] .'"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=' . (!empty($context['no_board_limits']) ? 'all' : 'board' . $context['querystring_board_limits']) . ';' . $context['session_var'] . '=' . $context['session_id']), |
|
| 1394 | + 'markread' => array('text' => !empty($context['no_board_limits']) ? 'mark_as_read' : 'mark_read_short', 'image' => 'markread.png', 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=' . (!empty($context['no_board_limits']) ? 'all' : 'board' . $context['querystring_board_limits']) . ';' . $context['session_var'] . '=' . $context['session_id']), |
|
| 1395 | 1395 | ); |
| 1396 | 1396 | |
| 1397 | 1397 | if ($context['showCheckboxes']) |
@@ -1407,7 +1407,7 @@ discard block |
||
| 1407 | 1407 | elseif (!$is_topics && isset($context['topics_to_mark'])) |
| 1408 | 1408 | { |
| 1409 | 1409 | $context['recent_buttons'] = array( |
| 1410 | - 'markread' => array('text' => 'mark_as_read', 'image' => 'markread.png', 'custom' => 'data-confirm="'. $txt['are_sure_mark_read'] .'"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=unreadreplies;topics=' . $context['topics_to_mark'] . ';' . $context['session_var'] . '=' . $context['session_id']), |
|
| 1410 | + 'markread' => array('text' => 'mark_as_read', 'image' => 'markread.png', 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=unreadreplies;topics=' . $context['topics_to_mark'] . ';' . $context['session_var'] . '=' . $context['session_id']), |
|
| 1411 | 1411 | ); |
| 1412 | 1412 | |
| 1413 | 1413 | if ($context['showCheckboxes']) |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 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 the latest post made on the system |
@@ -44,8 +45,9 @@ discard block |
||
| 44 | 45 | 'is_approved' => 1, |
| 45 | 46 | ) |
| 46 | 47 | ); |
| 47 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 48 | - return array(); |
|
| 48 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 49 | + return array(); |
|
| 50 | + } |
|
| 49 | 51 | $row = $smcFunc['db_fetch_assoc']($request); |
| 50 | 52 | $smcFunc['db_free_result']($request); |
| 51 | 53 | |
@@ -54,8 +56,9 @@ discard block |
||
| 54 | 56 | censorText($row['body']); |
| 55 | 57 | |
| 56 | 58 | $row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled']), array('<br>' => ' '))); |
| 57 | - if ($smcFunc['strlen']($row['body']) > 128) |
|
| 58 | - $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...'; |
|
| 59 | + if ($smcFunc['strlen']($row['body']) > 128) { |
|
| 60 | + $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...'; |
|
| 61 | + } |
|
| 59 | 62 | |
| 60 | 63 | // Send the data. |
| 61 | 64 | return array( |
@@ -83,15 +86,17 @@ discard block |
||
| 83 | 86 | |
| 84 | 87 | $context['is_redirect'] = false; |
| 85 | 88 | |
| 86 | - if (isset($_REQUEST['start']) && $_REQUEST['start'] > 95) |
|
| 87 | - $_REQUEST['start'] = 95; |
|
| 89 | + if (isset($_REQUEST['start']) && $_REQUEST['start'] > 95) { |
|
| 90 | + $_REQUEST['start'] = 95; |
|
| 91 | + } |
|
| 88 | 92 | |
| 89 | 93 | $query_parameters = array(); |
| 90 | 94 | if (!empty($_REQUEST['c']) && empty($board)) |
| 91 | 95 | { |
| 92 | 96 | $_REQUEST['c'] = explode(',', $_REQUEST['c']); |
| 93 | - foreach ($_REQUEST['c'] as $i => $c) |
|
| 94 | - $_REQUEST['c'][$i] = (int) $c; |
|
| 97 | + foreach ($_REQUEST['c'] as $i => $c) { |
|
| 98 | + $_REQUEST['c'][$i] = (int) $c; |
|
| 99 | + } |
|
| 95 | 100 | |
| 96 | 101 | if (count($_REQUEST['c']) == 1) |
| 97 | 102 | { |
@@ -107,8 +112,9 @@ discard block |
||
| 107 | 112 | list ($name) = $smcFunc['db_fetch_row']($request); |
| 108 | 113 | $smcFunc['db_free_result']($request); |
| 109 | 114 | |
| 110 | - if (empty($name)) |
|
| 111 | - fatal_lang_error('no_access', false); |
|
| 115 | + if (empty($name)) { |
|
| 116 | + fatal_lang_error('no_access', false); |
|
| 117 | + } |
|
| 112 | 118 | |
| 113 | 119 | $context['linktree'][] = array( |
| 114 | 120 | 'url' => $scripturl . '#c' . (int) $_REQUEST['c'], |
@@ -140,8 +146,9 @@ discard block |
||
| 140 | 146 | } |
| 141 | 147 | $smcFunc['db_free_result']($request); |
| 142 | 148 | |
| 143 | - if (empty($boards)) |
|
| 144 | - fatal_lang_error('error_no_boards_selected'); |
|
| 149 | + if (empty($boards)) { |
|
| 150 | + fatal_lang_error('error_no_boards_selected'); |
|
| 151 | + } |
|
| 145 | 152 | |
| 146 | 153 | $query_this_board = 'b.id_board IN ({array_int:boards})'; |
| 147 | 154 | $query_parameters['boards'] = $boards; |
@@ -155,12 +162,12 @@ discard block |
||
| 155 | 162 | } |
| 156 | 163 | |
| 157 | 164 | $context['page_index'] = constructPageIndex($scripturl . '?action=recent;c=' . implode(',', $_REQUEST['c']), $_REQUEST['start'], min(100, $total_cat_posts), 10, false); |
| 158 | - } |
|
| 159 | - elseif (!empty($_REQUEST['boards'])) |
|
| 165 | + } elseif (!empty($_REQUEST['boards'])) |
|
| 160 | 166 | { |
| 161 | 167 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
| 162 | - foreach ($_REQUEST['boards'] as $i => $b) |
|
| 163 | - $_REQUEST['boards'][$i] = (int) $b; |
|
| 168 | + foreach ($_REQUEST['boards'] as $i => $b) { |
|
| 169 | + $_REQUEST['boards'][$i] = (int) $b; |
|
| 170 | + } |
|
| 164 | 171 | |
| 165 | 172 | $request = $smcFunc['db_query']('', ' |
| 166 | 173 | SELECT b.id_board, b.num_posts |
@@ -184,8 +191,9 @@ discard block |
||
| 184 | 191 | } |
| 185 | 192 | $smcFunc['db_free_result']($request); |
| 186 | 193 | |
| 187 | - if (empty($boards)) |
|
| 188 | - fatal_lang_error('error_no_boards_selected'); |
|
| 194 | + if (empty($boards)) { |
|
| 195 | + fatal_lang_error('error_no_boards_selected'); |
|
| 196 | + } |
|
| 189 | 197 | |
| 190 | 198 | $query_this_board = 'b.id_board IN ({array_int:boards})'; |
| 191 | 199 | $query_parameters['boards'] = $boards; |
@@ -199,8 +207,7 @@ discard block |
||
| 199 | 207 | } |
| 200 | 208 | |
| 201 | 209 | $context['page_index'] = constructPageIndex($scripturl . '?action=recent;boards=' . implode(',', $_REQUEST['boards']), $_REQUEST['start'], min(100, $total_posts), 10, false); |
| 202 | - } |
|
| 203 | - elseif (!empty($board)) |
|
| 210 | + } elseif (!empty($board)) |
|
| 204 | 211 | { |
| 205 | 212 | $request = $smcFunc['db_query']('', ' |
| 206 | 213 | SELECT num_posts, redirect |
@@ -233,8 +240,7 @@ discard block |
||
| 233 | 240 | } |
| 234 | 241 | |
| 235 | 242 | $context['page_index'] = constructPageIndex($scripturl . '?action=recent;board=' . $board . '.%1$d', $_REQUEST['start'], min(100, $total_posts), 10, true); |
| 236 | - } |
|
| 237 | - else |
|
| 243 | + } else |
|
| 238 | 244 | { |
| 239 | 245 | $query_this_board = '{query_wanna_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' |
| 240 | 246 | AND b.id_board != {int:recycle_board}' : ''). ' |
@@ -269,8 +275,9 @@ discard block |
||
| 269 | 275 | ); |
| 270 | 276 | |
| 271 | 277 | // If you selected a redirection board, don't try getting posts for it... |
| 272 | - if ($context['is_redirect']) |
|
| 273 | - $messages = 0; |
|
| 278 | + if ($context['is_redirect']) { |
|
| 279 | + $messages = 0; |
|
| 280 | + } |
|
| 274 | 281 | |
| 275 | 282 | $key = 'recent-' . $user_info['id'] . '-' . md5(json_encode(array_diff_key($query_parameters, array('max_id_msg' => 0)))) . '-' . (int) $_REQUEST['start']; |
| 276 | 283 | if (!$context['is_redirect'] && (empty($modSettings['cache_enable']) || ($messages = cache_get_data($key, 120)) == null)) |
@@ -301,16 +308,18 @@ discard block |
||
| 301 | 308 | $query_this_board = str_replace('AND m.id_msg >= {int:max_id_msg}', '', $query_this_board); |
| 302 | 309 | $cache_results = true; |
| 303 | 310 | unset($query_parameters['max_id_msg']); |
| 311 | + } else { |
|
| 312 | + $done = true; |
|
| 304 | 313 | } |
| 305 | - else |
|
| 306 | - $done = true; |
|
| 307 | 314 | } |
| 308 | 315 | $messages = array(); |
| 309 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 310 | - $messages[] = $row['id_msg']; |
|
| 316 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 317 | + $messages[] = $row['id_msg']; |
|
| 318 | + } |
|
| 311 | 319 | $smcFunc['db_free_result']($request); |
| 312 | - if (!empty($cache_results)) |
|
| 313 | - cache_put_data($key, $messages, 120); |
|
| 320 | + if (!empty($cache_results)) { |
|
| 321 | + cache_put_data($key, $messages, 120); |
|
| 322 | + } |
|
| 314 | 323 | } |
| 315 | 324 | |
| 316 | 325 | // Nothing here... Or at least, nothing you can see... |
@@ -397,8 +406,9 @@ discard block |
||
| 397 | 406 | 'css_class' => 'windowbg', |
| 398 | 407 | ); |
| 399 | 408 | |
| 400 | - if ($user_info['id'] == $row['id_first_member']) |
|
| 401 | - $board_ids['own'][$row['id_board']][] = $row['id_msg']; |
|
| 409 | + if ($user_info['id'] == $row['id_first_member']) { |
|
| 410 | + $board_ids['own'][$row['id_board']][] = $row['id_msg']; |
|
| 411 | + } |
|
| 402 | 412 | $board_ids['any'][$row['id_board']][] = $row['id_msg']; |
| 403 | 413 | } |
| 404 | 414 | $smcFunc['db_free_result']($request); |
@@ -424,20 +434,23 @@ discard block |
||
| 424 | 434 | $boards = boardsAllowedTo($permission); |
| 425 | 435 | |
| 426 | 436 | // If 0 is the only thing in the array, they can do it everywhere! |
| 427 | - if (!empty($boards) && $boards[0] == 0) |
|
| 428 | - $boards = array_keys($board_ids[$type]); |
|
| 437 | + if (!empty($boards) && $boards[0] == 0) { |
|
| 438 | + $boards = array_keys($board_ids[$type]); |
|
| 439 | + } |
|
| 429 | 440 | |
| 430 | 441 | // Go through the boards, and look for posts they can do this on. |
| 431 | 442 | foreach ($boards as $board_id) |
| 432 | 443 | { |
| 433 | 444 | // Hmm, they have permission, but there are no topics from that board on this page. |
| 434 | - if (!isset($board_ids[$type][$board_id])) |
|
| 435 | - continue; |
|
| 445 | + if (!isset($board_ids[$type][$board_id])) { |
|
| 446 | + continue; |
|
| 447 | + } |
|
| 436 | 448 | |
| 437 | 449 | // Okay, looks like they can do it for these posts. |
| 438 | - foreach ($board_ids[$type][$board_id] as $counter) |
|
| 439 | - if ($type == 'any' || $context['posts'][$counter]['poster']['id'] == $user_info['id']) |
|
| 450 | + foreach ($board_ids[$type][$board_id] as $counter) { |
|
| 451 | + if ($type == 'any' || $context['posts'][$counter]['poster']['id'] == $user_info['id']) |
|
| 440 | 452 | $context['posts'][$counter][$allowed] = true; |
| 453 | + } |
|
| 441 | 454 | } |
| 442 | 455 | } |
| 443 | 456 | } |
@@ -480,17 +493,19 @@ discard block |
||
| 480 | 493 | $context['showing_all_topics'] = isset($_GET['all']); |
| 481 | 494 | $context['start'] = (int) $_REQUEST['start']; |
| 482 | 495 | $context['topics_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics']; |
| 483 | - if ($_REQUEST['action'] == 'unread') |
|
| 484 | - $context['page_title'] = $context['showing_all_topics'] ? $txt['unread_topics_all'] : $txt['unread_topics_visit']; |
|
| 485 | - else |
|
| 486 | - $context['page_title'] = $txt['unread_replies']; |
|
| 496 | + if ($_REQUEST['action'] == 'unread') { |
|
| 497 | + $context['page_title'] = $context['showing_all_topics'] ? $txt['unread_topics_all'] : $txt['unread_topics_visit']; |
|
| 498 | + } else { |
|
| 499 | + $context['page_title'] = $txt['unread_replies']; |
|
| 500 | + } |
|
| 487 | 501 | |
| 488 | - if ($context['showing_all_topics'] && !empty($context['load_average']) && !empty($modSettings['loadavg_allunread']) && $context['load_average'] >= $modSettings['loadavg_allunread']) |
|
| 489 | - fatal_lang_error('loadavg_allunread_disabled', false); |
|
| 490 | - elseif ($_REQUEST['action'] != 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unreadreplies']) && $context['load_average'] >= $modSettings['loadavg_unreadreplies']) |
|
| 491 | - fatal_lang_error('loadavg_unreadreplies_disabled', false); |
|
| 492 | - elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unread']) && $context['load_average'] >= $modSettings['loadavg_unread']) |
|
| 493 | - fatal_lang_error('loadavg_unread_disabled', false); |
|
| 502 | + if ($context['showing_all_topics'] && !empty($context['load_average']) && !empty($modSettings['loadavg_allunread']) && $context['load_average'] >= $modSettings['loadavg_allunread']) { |
|
| 503 | + fatal_lang_error('loadavg_allunread_disabled', false); |
|
| 504 | + } elseif ($_REQUEST['action'] != 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unreadreplies']) && $context['load_average'] >= $modSettings['loadavg_unreadreplies']) { |
|
| 505 | + fatal_lang_error('loadavg_unreadreplies_disabled', false); |
|
| 506 | + } elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unread']) && $context['load_average'] >= $modSettings['loadavg_unread']) { |
|
| 507 | + fatal_lang_error('loadavg_unread_disabled', false); |
|
| 508 | + } |
|
| 494 | 509 | |
| 495 | 510 | // Parameters for the main query. |
| 496 | 511 | $query_parameters = array(); |
@@ -503,12 +518,14 @@ discard block |
||
| 503 | 518 | if (!empty($_REQUEST['boards'])) |
| 504 | 519 | { |
| 505 | 520 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
| 506 | - foreach ($_REQUEST['boards'] as $b) |
|
| 507 | - $boards[] = (int) $b; |
|
| 521 | + foreach ($_REQUEST['boards'] as $b) { |
|
| 522 | + $boards[] = (int) $b; |
|
| 523 | + } |
|
| 508 | 524 | } |
| 509 | 525 | |
| 510 | - if (!empty($board)) |
|
| 511 | - $boards[] = (int) $board; |
|
| 526 | + if (!empty($board)) { |
|
| 527 | + $boards[] = (int) $board; |
|
| 528 | + } |
|
| 512 | 529 | |
| 513 | 530 | // The easiest thing is to just get all the boards they can see, but since we've specified the top of tree we ignore some of them |
| 514 | 531 | $request = $smcFunc['db_query']('', ' |
@@ -525,30 +542,31 @@ discard block |
||
| 525 | 542 | ) |
| 526 | 543 | ); |
| 527 | 544 | |
| 528 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 529 | - if (in_array($row['id_parent'], $boards)) |
|
| 545 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 546 | + if (in_array($row['id_parent'], $boards)) |
|
| 530 | 547 | $boards[] = $row['id_board']; |
| 548 | + } |
|
| 531 | 549 | |
| 532 | 550 | $smcFunc['db_free_result']($request); |
| 533 | 551 | |
| 534 | - if (empty($boards)) |
|
| 535 | - fatal_lang_error('error_no_boards_selected'); |
|
| 552 | + if (empty($boards)) { |
|
| 553 | + fatal_lang_error('error_no_boards_selected'); |
|
| 554 | + } |
|
| 536 | 555 | |
| 537 | 556 | $query_this_board = 'id_board IN ({array_int:boards})'; |
| 538 | 557 | $query_parameters['boards'] = $boards; |
| 539 | 558 | $context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%d'; |
| 540 | - } |
|
| 541 | - elseif (!empty($board)) |
|
| 559 | + } elseif (!empty($board)) |
|
| 542 | 560 | { |
| 543 | 561 | $query_this_board = 'id_board = {int:board}'; |
| 544 | 562 | $query_parameters['board'] = $board; |
| 545 | 563 | $context['querystring_board_limits'] = ';board=' . $board . '.%1$d'; |
| 546 | - } |
|
| 547 | - elseif (!empty($_REQUEST['boards'])) |
|
| 564 | + } elseif (!empty($_REQUEST['boards'])) |
|
| 548 | 565 | { |
| 549 | 566 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
| 550 | - foreach ($_REQUEST['boards'] as $i => $b) |
|
| 551 | - $_REQUEST['boards'][$i] = (int) $b; |
|
| 567 | + foreach ($_REQUEST['boards'] as $i => $b) { |
|
| 568 | + $_REQUEST['boards'][$i] = (int) $b; |
|
| 569 | + } |
|
| 552 | 570 | |
| 553 | 571 | $request = $smcFunc['db_query']('', ' |
| 554 | 572 | SELECT b.id_board |
@@ -560,22 +578,24 @@ discard block |
||
| 560 | 578 | ) |
| 561 | 579 | ); |
| 562 | 580 | $boards = array(); |
| 563 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 564 | - $boards[] = $row['id_board']; |
|
| 581 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 582 | + $boards[] = $row['id_board']; |
|
| 583 | + } |
|
| 565 | 584 | $smcFunc['db_free_result']($request); |
| 566 | 585 | |
| 567 | - if (empty($boards)) |
|
| 568 | - fatal_lang_error('error_no_boards_selected'); |
|
| 586 | + if (empty($boards)) { |
|
| 587 | + fatal_lang_error('error_no_boards_selected'); |
|
| 588 | + } |
|
| 569 | 589 | |
| 570 | 590 | $query_this_board = 'id_board IN ({array_int:boards})'; |
| 571 | 591 | $query_parameters['boards'] = $boards; |
| 572 | 592 | $context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%1$d'; |
| 573 | - } |
|
| 574 | - elseif (!empty($_REQUEST['c'])) |
|
| 593 | + } elseif (!empty($_REQUEST['c'])) |
|
| 575 | 594 | { |
| 576 | 595 | $_REQUEST['c'] = explode(',', $_REQUEST['c']); |
| 577 | - foreach ($_REQUEST['c'] as $i => $c) |
|
| 578 | - $_REQUEST['c'][$i] = (int) $c; |
|
| 596 | + foreach ($_REQUEST['c'] as $i => $c) { |
|
| 597 | + $_REQUEST['c'][$i] = (int) $c; |
|
| 598 | + } |
|
| 579 | 599 | |
| 580 | 600 | $see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board'; |
| 581 | 601 | $request = $smcFunc['db_query']('', ' |
@@ -588,18 +608,19 @@ discard block |
||
| 588 | 608 | ) |
| 589 | 609 | ); |
| 590 | 610 | $boards = array(); |
| 591 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 592 | - $boards[] = $row['id_board']; |
|
| 611 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 612 | + $boards[] = $row['id_board']; |
|
| 613 | + } |
|
| 593 | 614 | $smcFunc['db_free_result']($request); |
| 594 | 615 | |
| 595 | - if (empty($boards)) |
|
| 596 | - fatal_lang_error('error_no_boards_selected'); |
|
| 616 | + if (empty($boards)) { |
|
| 617 | + fatal_lang_error('error_no_boards_selected'); |
|
| 618 | + } |
|
| 597 | 619 | |
| 598 | 620 | $query_this_board = 'id_board IN ({array_int:boards})'; |
| 599 | 621 | $query_parameters['boards'] = $boards; |
| 600 | 622 | $context['querystring_board_limits'] = ';c=' . implode(',', $_REQUEST['c']) . ';start=%1$d'; |
| 601 | - } |
|
| 602 | - else |
|
| 623 | + } else |
|
| 603 | 624 | { |
| 604 | 625 | $see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board'; |
| 605 | 626 | // Don't bother to show deleted posts! |
@@ -613,12 +634,14 @@ discard block |
||
| 613 | 634 | ) |
| 614 | 635 | ); |
| 615 | 636 | $boards = array(); |
| 616 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 617 | - $boards[] = $row['id_board']; |
|
| 637 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 638 | + $boards[] = $row['id_board']; |
|
| 639 | + } |
|
| 618 | 640 | $smcFunc['db_free_result']($request); |
| 619 | 641 | |
| 620 | - if (empty($boards)) |
|
| 621 | - fatal_lang_error('error_no_boards_available', false); |
|
| 642 | + if (empty($boards)) { |
|
| 643 | + fatal_lang_error('error_no_boards_available', false); |
|
| 644 | + } |
|
| 622 | 645 | |
| 623 | 646 | $query_this_board = 'id_board IN ({array_int:boards})'; |
| 624 | 647 | $query_parameters['boards'] = $boards; |
@@ -680,13 +703,14 @@ discard block |
||
| 680 | 703 | 'name' => $_REQUEST['action'] == 'unread' ? $txt['unread_topics_visit'] : $txt['unread_replies'] |
| 681 | 704 | ); |
| 682 | 705 | |
| 683 | - if ($context['showing_all_topics']) |
|
| 684 | - $context['linktree'][] = array( |
|
| 706 | + if ($context['showing_all_topics']) { |
|
| 707 | + $context['linktree'][] = array( |
|
| 685 | 708 | 'url' => $scripturl . '?action=' . $_REQUEST['action'] . ';all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'], |
| 686 | 709 | 'name' => $txt['unread_topics_all'] |
| 687 | 710 | ); |
| 688 | - else |
|
| 689 | - $txt['unread_topics_visit_none'] = strtr($txt['unread_topics_visit_none'], array('?action=unread;all' => '?action=unread;all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'])); |
|
| 711 | + } else { |
|
| 712 | + $txt['unread_topics_visit_none'] = strtr($txt['unread_topics_visit_none'], array('?action=unread;all' => '?action=unread;all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'])); |
|
| 713 | + } |
|
| 690 | 714 | |
| 691 | 715 | loadTemplate('Recent'); |
| 692 | 716 | loadTemplate('MessageIndex'); |
@@ -694,8 +718,9 @@ discard block |
||
| 694 | 718 | |
| 695 | 719 | // Setup the default topic icons... for checking they exist and the like ;) |
| 696 | 720 | $context['icon_sources'] = array(); |
| 697 | - foreach ($context['stable_icons'] as $icon) |
|
| 698 | - $context['icon_sources'][$icon] = 'images_url'; |
|
| 721 | + foreach ($context['stable_icons'] as $icon) { |
|
| 722 | + $context['icon_sources'][$icon] = 'images_url'; |
|
| 723 | + } |
|
| 699 | 724 | |
| 700 | 725 | $is_topics = $_REQUEST['action'] == 'unread'; |
| 701 | 726 | |
@@ -725,8 +750,7 @@ discard block |
||
| 725 | 750 | ); |
| 726 | 751 | list ($earliest_msg) = $smcFunc['db_fetch_row']($request); |
| 727 | 752 | $smcFunc['db_free_result']($request); |
| 728 | - } |
|
| 729 | - else |
|
| 753 | + } else |
|
| 730 | 754 | { |
| 731 | 755 | $request = $smcFunc['db_query']('', ' |
| 732 | 756 | SELECT MIN(lmr.id_msg) |
@@ -742,14 +766,14 @@ discard block |
||
| 742 | 766 | } |
| 743 | 767 | |
| 744 | 768 | // This is needed in case of topics marked unread. |
| 745 | - if (empty($earliest_msg)) |
|
| 746 | - $earliest_msg = 0; |
|
| 747 | - else |
|
| 769 | + if (empty($earliest_msg)) { |
|
| 770 | + $earliest_msg = 0; |
|
| 771 | + } else |
|
| 748 | 772 | { |
| 749 | 773 | // Using caching, when possible, to ignore the below slow query. |
| 750 | - if (isset($_SESSION['cached_log_time']) && $_SESSION['cached_log_time'][0] + 45 > time()) |
|
| 751 | - $earliest_msg2 = $_SESSION['cached_log_time'][1]; |
|
| 752 | - else |
|
| 774 | + if (isset($_SESSION['cached_log_time']) && $_SESSION['cached_log_time'][0] + 45 > time()) { |
|
| 775 | + $earliest_msg2 = $_SESSION['cached_log_time'][1]; |
|
| 776 | + } else |
|
| 753 | 777 | { |
| 754 | 778 | // This query is pretty slow, but it's needed to ensure nothing crucial is ignored. |
| 755 | 779 | $request = $smcFunc['db_query']('', ' |
@@ -764,8 +788,9 @@ discard block |
||
| 764 | 788 | $smcFunc['db_free_result']($request); |
| 765 | 789 | |
| 766 | 790 | // In theory this could be zero, if the first ever post is unread, so fudge it ;) |
| 767 | - if ($earliest_msg2 == 0) |
|
| 768 | - $earliest_msg2 = -1; |
|
| 791 | + if ($earliest_msg2 == 0) { |
|
| 792 | + $earliest_msg2 = -1; |
|
| 793 | + } |
|
| 769 | 794 | |
| 770 | 795 | $_SESSION['cached_log_time'] = array(time(), $earliest_msg2); |
| 771 | 796 | } |
@@ -803,9 +828,9 @@ discard block |
||
| 803 | 828 | 'db_error_skip' => true, |
| 804 | 829 | )) |
| 805 | 830 | ) !== false; |
| 831 | + } else { |
|
| 832 | + $have_temp_table = false; |
|
| 806 | 833 | } |
| 807 | - else |
|
| 808 | - $have_temp_table = false; |
|
| 809 | 834 | |
| 810 | 835 | if ($context['showing_all_topics'] && $have_temp_table) |
| 811 | 836 | { |
@@ -851,14 +876,15 @@ discard block |
||
| 851 | 876 | |
| 852 | 877 | $context['topics'] = array(); |
| 853 | 878 | $context['no_topic_listing'] = true; |
| 854 | - if ($context['querystring_board_limits'] == ';start=%1$d') |
|
| 855 | - $context['querystring_board_limits'] = ''; |
|
| 856 | - else |
|
| 857 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 879 | + if ($context['querystring_board_limits'] == ';start=%1$d') { |
|
| 880 | + $context['querystring_board_limits'] = ''; |
|
| 881 | + } else { |
|
| 882 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 883 | + } |
|
| 858 | 884 | return; |
| 885 | + } else { |
|
| 886 | + $min_message = (int) $min_message; |
|
| 859 | 887 | } |
| 860 | - else |
|
| 861 | - $min_message = (int) $min_message; |
|
| 862 | 888 | |
| 863 | 889 | $request = $smcFunc['db_query']('substring', ' |
| 864 | 890 | SELECT ' . $select_clause . ' |
@@ -887,8 +913,7 @@ discard block |
||
| 887 | 913 | 'limit' => $context['topics_per_page'], |
| 888 | 914 | )) |
| 889 | 915 | ); |
| 890 | - } |
|
| 891 | - elseif ($is_topics) |
|
| 916 | + } elseif ($is_topics) |
|
| 892 | 917 | { |
| 893 | 918 | $request = $smcFunc['db_query']('', ' |
| 894 | 919 | SELECT COUNT(*), MIN(t.id_last_msg) |
@@ -939,14 +964,15 @@ discard block |
||
| 939 | 964 | |
| 940 | 965 | $context['topics'] = array(); |
| 941 | 966 | $context['no_topic_listing'] = true; |
| 942 | - if ($context['querystring_board_limits'] == ';start=%d') |
|
| 943 | - $context['querystring_board_limits'] = ''; |
|
| 944 | - else |
|
| 945 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 967 | + if ($context['querystring_board_limits'] == ';start=%d') { |
|
| 968 | + $context['querystring_board_limits'] = ''; |
|
| 969 | + } else { |
|
| 970 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 971 | + } |
|
| 946 | 972 | return; |
| 973 | + } else { |
|
| 974 | + $min_message = (int) $min_message; |
|
| 947 | 975 | } |
| 948 | - else |
|
| 949 | - $min_message = (int) $min_message; |
|
| 950 | 976 | |
| 951 | 977 | $request = $smcFunc['db_query']('substring', ' |
| 952 | 978 | SELECT ' . $select_clause . ' |
@@ -976,8 +1002,7 @@ discard block |
||
| 976 | 1002 | 'limit' => $context['topics_per_page'], |
| 977 | 1003 | )) |
| 978 | 1004 | ); |
| 979 | - } |
|
| 980 | - else |
|
| 1005 | + } else |
|
| 981 | 1006 | { |
| 982 | 1007 | if ($modSettings['totalMessages'] > 100000) |
| 983 | 1008 | { |
@@ -1029,8 +1054,8 @@ discard block |
||
| 1029 | 1054 | ) !== false; |
| 1030 | 1055 | |
| 1031 | 1056 | // If that worked, create a sample of the log_topics table too. |
| 1032 | - if ($have_temp_table) |
|
| 1033 | - $have_temp_table = $smcFunc['db_query']('', ' |
|
| 1057 | + if ($have_temp_table) { |
|
| 1058 | + $have_temp_table = $smcFunc['db_query']('', ' |
|
| 1034 | 1059 | CREATE TEMPORARY TABLE {db_prefix}log_topics_posted_in ( |
| 1035 | 1060 | PRIMARY KEY (id_topic) |
| 1036 | 1061 | ) |
@@ -1043,6 +1068,7 @@ discard block |
||
| 1043 | 1068 | 'db_error_skip' => true, |
| 1044 | 1069 | ) |
| 1045 | 1070 | ) !== false; |
| 1071 | + } |
|
| 1046 | 1072 | } |
| 1047 | 1073 | |
| 1048 | 1074 | if (!empty($have_temp_table)) |
@@ -1058,8 +1084,7 @@ discard block |
||
| 1058 | 1084 | ); |
| 1059 | 1085 | list ($num_topics) = $smcFunc['db_fetch_row']($request); |
| 1060 | 1086 | $smcFunc['db_free_result']($request); |
| 1061 | - } |
|
| 1062 | - else |
|
| 1087 | + } else |
|
| 1063 | 1088 | { |
| 1064 | 1089 | $request = $smcFunc['db_query']('unread_fetch_topic_count', ' |
| 1065 | 1090 | SELECT COUNT(DISTINCT t.id_topic), MIN(t.id_last_msg) |
@@ -1100,15 +1125,16 @@ discard block |
||
| 1100 | 1125 | { |
| 1101 | 1126 | $context['topics'] = array(); |
| 1102 | 1127 | $context['no_topic_listing'] = true; |
| 1103 | - if ($context['querystring_board_limits'] == ';start=%d') |
|
| 1104 | - $context['querystring_board_limits'] = ''; |
|
| 1105 | - else |
|
| 1106 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 1128 | + if ($context['querystring_board_limits'] == ';start=%d') { |
|
| 1129 | + $context['querystring_board_limits'] = ''; |
|
| 1130 | + } else { |
|
| 1131 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 1132 | + } |
|
| 1107 | 1133 | return; |
| 1108 | 1134 | } |
| 1109 | 1135 | |
| 1110 | - if (!empty($have_temp_table)) |
|
| 1111 | - $request = $smcFunc['db_query']('', ' |
|
| 1136 | + if (!empty($have_temp_table)) { |
|
| 1137 | + $request = $smcFunc['db_query']('', ' |
|
| 1112 | 1138 | SELECT t.id_topic |
| 1113 | 1139 | FROM {db_prefix}topics_posted_in AS t |
| 1114 | 1140 | LEFT JOIN {db_prefix}log_topics_posted_in AS lt ON (lt.id_topic = t.id_topic) |
@@ -1122,8 +1148,8 @@ discard block |
||
| 1122 | 1148 | 'limit' => $context['topics_per_page'], |
| 1123 | 1149 | )) |
| 1124 | 1150 | ); |
| 1125 | - else |
|
| 1126 | - $request = $smcFunc['db_query']('', ' |
|
| 1151 | + } else { |
|
| 1152 | + $request = $smcFunc['db_query']('', ' |
|
| 1127 | 1153 | SELECT DISTINCT t.id_topic,'.$_REQUEST['sort'].' |
| 1128 | 1154 | FROM {db_prefix}topics AS t |
| 1129 | 1155 | INNER JOIN {db_prefix}messages AS m ON (m.id_topic = t.id_topic AND m.id_member = {int:current_member})' . (strpos($_REQUEST['sort'], 'ms.') === false ? '' : ' |
@@ -1147,10 +1173,12 @@ discard block |
||
| 1147 | 1173 | 'sort' => $_REQUEST['sort'], |
| 1148 | 1174 | )) |
| 1149 | 1175 | ); |
| 1176 | + } |
|
| 1150 | 1177 | |
| 1151 | 1178 | $topics = array(); |
| 1152 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1153 | - $topics[] = $row['id_topic']; |
|
| 1179 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1180 | + $topics[] = $row['id_topic']; |
|
| 1181 | + } |
|
| 1154 | 1182 | $smcFunc['db_free_result']($request); |
| 1155 | 1183 | |
| 1156 | 1184 | // Sanity... where have you gone? |
@@ -1158,10 +1186,11 @@ discard block |
||
| 1158 | 1186 | { |
| 1159 | 1187 | $context['topics'] = array(); |
| 1160 | 1188 | $context['no_topic_listing'] = true; |
| 1161 | - if ($context['querystring_board_limits'] == ';start=%d') |
|
| 1162 | - $context['querystring_board_limits'] = ''; |
|
| 1163 | - else |
|
| 1164 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 1189 | + if ($context['querystring_board_limits'] == ';start=%d') { |
|
| 1190 | + $context['querystring_board_limits'] = ''; |
|
| 1191 | + } else { |
|
| 1192 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
| 1193 | + } |
|
| 1165 | 1194 | return; |
| 1166 | 1195 | } |
| 1167 | 1196 | |
@@ -1195,8 +1224,9 @@ discard block |
||
| 1195 | 1224 | |
| 1196 | 1225 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1197 | 1226 | { |
| 1198 | - if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') |
|
| 1199 | - continue; |
|
| 1227 | + if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') { |
|
| 1228 | + continue; |
|
| 1229 | + } |
|
| 1200 | 1230 | |
| 1201 | 1231 | $topic_ids[] = $row['id_topic']; |
| 1202 | 1232 | |
@@ -1204,11 +1234,13 @@ discard block |
||
| 1204 | 1234 | { |
| 1205 | 1235 | // Limit them to 128 characters - do this FIRST because it's a lot of wasted censoring otherwise. |
| 1206 | 1236 | $row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => ' '))); |
| 1207 | - if ($smcFunc['strlen']($row['first_body']) > 128) |
|
| 1208 | - $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...'; |
|
| 1237 | + if ($smcFunc['strlen']($row['first_body']) > 128) { |
|
| 1238 | + $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...'; |
|
| 1239 | + } |
|
| 1209 | 1240 | $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => ' '))); |
| 1210 | - if ($smcFunc['strlen']($row['last_body']) > 128) |
|
| 1211 | - $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...'; |
|
| 1241 | + if ($smcFunc['strlen']($row['last_body']) > 128) { |
|
| 1242 | + $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...'; |
|
| 1243 | + } |
|
| 1212 | 1244 | |
| 1213 | 1245 | // Censor the subject and message preview. |
| 1214 | 1246 | censorText($row['first_subject']); |
@@ -1219,23 +1251,22 @@ discard block |
||
| 1219 | 1251 | { |
| 1220 | 1252 | $row['last_subject'] = $row['first_subject']; |
| 1221 | 1253 | $row['last_body'] = $row['first_body']; |
| 1222 | - } |
|
| 1223 | - else |
|
| 1254 | + } else |
|
| 1224 | 1255 | { |
| 1225 | 1256 | censorText($row['last_subject']); |
| 1226 | 1257 | censorText($row['last_body']); |
| 1227 | 1258 | } |
| 1228 | - } |
|
| 1229 | - else |
|
| 1259 | + } else |
|
| 1230 | 1260 | { |
| 1231 | 1261 | $row['first_body'] = ''; |
| 1232 | 1262 | $row['last_body'] = ''; |
| 1233 | 1263 | censorText($row['first_subject']); |
| 1234 | 1264 | |
| 1235 | - if ($row['id_first_msg'] == $row['id_last_msg']) |
|
| 1236 | - $row['last_subject'] = $row['first_subject']; |
|
| 1237 | - else |
|
| 1238 | - censorText($row['last_subject']); |
|
| 1265 | + if ($row['id_first_msg'] == $row['id_last_msg']) { |
|
| 1266 | + $row['last_subject'] = $row['first_subject']; |
|
| 1267 | + } else { |
|
| 1268 | + censorText($row['last_subject']); |
|
| 1269 | + } |
|
| 1239 | 1270 | } |
| 1240 | 1271 | |
| 1241 | 1272 | // Decide how many pages the topic should have. |
@@ -1247,22 +1278,24 @@ discard block |
||
| 1247 | 1278 | $pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $topic_length, $messages_per_page, true, false); |
| 1248 | 1279 | |
| 1249 | 1280 | // If we can use all, show all. |
| 1250 | - if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages']) |
|
| 1251 | - $pages .= ' <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>'; |
|
| 1281 | + if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages']) { |
|
| 1282 | + $pages .= ' <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>'; |
|
| 1283 | + } |
|
| 1284 | + } else { |
|
| 1285 | + $pages = ''; |
|
| 1252 | 1286 | } |
| 1253 | 1287 | |
| 1254 | - else |
|
| 1255 | - $pages = ''; |
|
| 1256 | - |
|
| 1257 | 1288 | // We need to check the topic icons exist... you can never be too sure! |
| 1258 | 1289 | if (!empty($modSettings['messageIconChecks_enable'])) |
| 1259 | 1290 | { |
| 1260 | 1291 | // First icon first... as you'd expect. |
| 1261 | - if (!isset($context['icon_sources'][$row['first_icon']])) |
|
| 1262 | - $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1292 | + if (!isset($context['icon_sources'][$row['first_icon']])) { |
|
| 1293 | + $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1294 | + } |
|
| 1263 | 1295 | // Last icon... last... duh. |
| 1264 | - if (!isset($context['icon_sources'][$row['last_icon']])) |
|
| 1265 | - $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1296 | + if (!isset($context['icon_sources'][$row['last_icon']])) { |
|
| 1297 | + $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1298 | + } |
|
| 1266 | 1299 | } |
| 1267 | 1300 | |
| 1268 | 1301 | // Force the recycling icon if appropriate |
@@ -1276,12 +1309,14 @@ discard block |
||
| 1276 | 1309 | $colorClass = 'windowbg'; |
| 1277 | 1310 | |
| 1278 | 1311 | // Sticky topics should get a different color, too. |
| 1279 | - if ($row['is_sticky']) |
|
| 1280 | - $colorClass .= ' sticky'; |
|
| 1312 | + if ($row['is_sticky']) { |
|
| 1313 | + $colorClass .= ' sticky'; |
|
| 1314 | + } |
|
| 1281 | 1315 | |
| 1282 | 1316 | // Locked topics get special treatment as well. |
| 1283 | - if ($row['locked']) |
|
| 1284 | - $colorClass .= ' locked'; |
|
| 1317 | + if ($row['locked']) { |
|
| 1318 | + $colorClass .= ' locked'; |
|
| 1319 | + } |
|
| 1285 | 1320 | |
| 1286 | 1321 | // And build the array. |
| 1287 | 1322 | $context['topics'][$row['id_topic']] = array( |
@@ -1378,8 +1413,9 @@ discard block |
||
| 1378 | 1413 | ); |
| 1379 | 1414 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 1380 | 1415 | { |
| 1381 | - if (empty($context['topics'][$row['id_topic']]['is_posted_in'])) |
|
| 1382 | - $context['topics'][$row['id_topic']]['is_posted_in'] = true; |
|
| 1416 | + if (empty($context['topics'][$row['id_topic']]['is_posted_in'])) { |
|
| 1417 | + $context['topics'][$row['id_topic']]['is_posted_in'] = true; |
|
| 1418 | + } |
|
| 1383 | 1419 | } |
| 1384 | 1420 | $smcFunc['db_free_result']($result); |
| 1385 | 1421 | } |
@@ -1394,28 +1430,30 @@ discard block |
||
| 1394 | 1430 | 'markread' => array('text' => !empty($context['no_board_limits']) ? 'mark_as_read' : 'mark_read_short', 'image' => 'markread.png', 'custom' => 'data-confirm="'. $txt['are_sure_mark_read'] .'"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=' . (!empty($context['no_board_limits']) ? 'all' : 'board' . $context['querystring_board_limits']) . ';' . $context['session_var'] . '=' . $context['session_id']), |
| 1395 | 1431 | ); |
| 1396 | 1432 | |
| 1397 | - if ($context['showCheckboxes']) |
|
| 1398 | - $context['recent_buttons']['markselectread'] = array( |
|
| 1433 | + if ($context['showCheckboxes']) { |
|
| 1434 | + $context['recent_buttons']['markselectread'] = array( |
|
| 1399 | 1435 | 'text' => 'quick_mod_markread', |
| 1400 | 1436 | 'image' => 'markselectedread.png', |
| 1401 | 1437 | 'url' => 'javascript:document.quickModForm.submit();', |
| 1402 | 1438 | ); |
| 1439 | + } |
|
| 1403 | 1440 | |
| 1404 | - if (!empty($context['topics']) && !$context['showing_all_topics']) |
|
| 1405 | - $context['recent_buttons']['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.png', 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true); |
|
| 1406 | - } |
|
| 1407 | - elseif (!$is_topics && isset($context['topics_to_mark'])) |
|
| 1441 | + if (!empty($context['topics']) && !$context['showing_all_topics']) { |
|
| 1442 | + $context['recent_buttons']['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.png', 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true); |
|
| 1443 | + } |
|
| 1444 | + } elseif (!$is_topics && isset($context['topics_to_mark'])) |
|
| 1408 | 1445 | { |
| 1409 | 1446 | $context['recent_buttons'] = array( |
| 1410 | 1447 | 'markread' => array('text' => 'mark_as_read', 'image' => 'markread.png', 'custom' => 'data-confirm="'. $txt['are_sure_mark_read'] .'"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=unreadreplies;topics=' . $context['topics_to_mark'] . ';' . $context['session_var'] . '=' . $context['session_id']), |
| 1411 | 1448 | ); |
| 1412 | 1449 | |
| 1413 | - if ($context['showCheckboxes']) |
|
| 1414 | - $context['recent_buttons']['markselectread'] = array( |
|
| 1450 | + if ($context['showCheckboxes']) { |
|
| 1451 | + $context['recent_buttons']['markselectread'] = array( |
|
| 1415 | 1452 | 'text' => 'quick_mod_markread', |
| 1416 | 1453 | 'image' => 'markselectedread.png', |
| 1417 | 1454 | 'url' => 'javascript:document.quickModForm.submit();', |
| 1418 | 1455 | ); |
| 1456 | + } |
|
| 1419 | 1457 | } |
| 1420 | 1458 | |
| 1421 | 1459 | // Allow mods to add additional buttons here |
@@ -206,12 +206,12 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | if (!empty($modSettings['search_simple_fulltext'])) |
| 208 | 208 | { |
| 209 | - if($smcFunc['db_title'] == "PostgreSQL") |
|
| 209 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
| 210 | 210 | { |
| 211 | 211 | //we use the default language "default_text_search_config", otherwise we had to assgine the language here |
| 212 | 212 | //to_tsvector(body) -> to_tsvector($language,body) to_tsquery(...) -> to_tsquery($language,...) |
| 213 | 213 | $language_ftx = 'english'; |
| 214 | - $request = $smcFunc['db_query']('',' |
|
| 214 | + $request = $smcFunc['db_query']('', ' |
|
| 215 | 215 | SHOW default_text_search_config', |
| 216 | 216 | array() |
| 217 | 217 | ); |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | // remove any indexed words that are used in the complex body search terms |
| 236 | 236 | $words['indexed_words'] = array_diff($words['indexed_words'], $words['complex_words']); |
| 237 | 237 | |
| 238 | - if($smcFunc['db_title'] == "PostgreSQL"){ |
|
| 238 | + if ($smcFunc['db_title'] == "PostgreSQL") { |
|
| 239 | 239 | $row = 0; |
| 240 | 240 | foreach ($words['indexed_words'] as $fulltextWord) { |
| 241 | 241 | $query_params['boolean_match'] .= ($row <> 0 ? '&' : ''); |
@@ -251,12 +251,12 @@ discard block |
||
| 251 | 251 | |
| 252 | 252 | // if we have bool terms to search, add them in |
| 253 | 253 | if ($query_params['boolean_match']) { |
| 254 | - if($smcFunc['db_title'] == "PostgreSQL") |
|
| 254 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
| 255 | 255 | { |
| 256 | 256 | //we use the default language "default_text_search_config", otherwise we had to assgine the language here |
| 257 | 257 | //to_tsvector(body) -> to_tsvector($language,body) to_tsquery(...) -> to_tsquery($language,...) |
| 258 | 258 | $language_ftx = 'english'; |
| 259 | - $request = $smcFunc['db_query']('',' |
|
| 259 | + $request = $smcFunc['db_query']('', ' |
|
| 260 | 260 | SHOW default_text_search_config', |
| 261 | 261 | array() |
| 262 | 262 | ); |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? ( ' |
|
| 278 | + $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? (' |
|
| 279 | 279 | INSERT IGNORE INTO {db_prefix}' . $search_data['insert_into'] . ' |
| 280 | 280 | (' . implode(', ', array_keys($query_select)) . ')') : '') . ' |
| 281 | 281 | SELECT ' . implode(', ', $query_select) . ' |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 3 |
| 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,41 +168,50 @@ discard block |
||
| 166 | 168 | $query_where = array(); |
| 167 | 169 | $query_params = $search_data['params']; |
| 168 | 170 | |
| 169 | - if ($query_params['id_search']) |
|
| 170 | - $query_select['id_search'] = '{int:id_search}'; |
|
| 171 | + if ($query_params['id_search']) { |
|
| 172 | + $query_select['id_search'] = '{int:id_search}'; |
|
| 173 | + } |
|
| 171 | 174 | |
| 172 | 175 | $count = 0; |
| 173 | - if (empty($modSettings['search_simple_fulltext'])) |
|
| 174 | - foreach ($words['words'] as $regularWord) |
|
| 176 | + if (empty($modSettings['search_simple_fulltext'])) { |
|
| 177 | + foreach ($words['words'] as $regularWord) |
|
| 175 | 178 | { |
| 176 | 179 | $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 . '}'; |
| 180 | + } |
|
| 177 | 181 | $query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
| 178 | 182 | } |
| 179 | 183 | |
| 180 | - if ($query_params['user_query']) |
|
| 181 | - $query_where[] = '{raw:user_query}'; |
|
| 182 | - if ($query_params['board_query']) |
|
| 183 | - $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 184 | + if ($query_params['user_query']) { |
|
| 185 | + $query_where[] = '{raw:user_query}'; |
|
| 186 | + } |
|
| 187 | + if ($query_params['board_query']) { |
|
| 188 | + $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 189 | + } |
|
| 184 | 190 | |
| 185 | - if ($query_params['topic']) |
|
| 186 | - $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 187 | - if ($query_params['min_msg_id']) |
|
| 188 | - $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 189 | - if ($query_params['max_msg_id']) |
|
| 190 | - $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 191 | + if ($query_params['topic']) { |
|
| 192 | + $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 193 | + } |
|
| 194 | + if ($query_params['min_msg_id']) { |
|
| 195 | + $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 196 | + } |
|
| 197 | + if ($query_params['max_msg_id']) { |
|
| 198 | + $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 199 | + } |
|
| 191 | 200 | |
| 192 | 201 | $count = 0; |
| 193 | - if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) |
|
| 194 | - foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 202 | + if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) { |
|
| 203 | + foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 195 | 204 | { |
| 196 | 205 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_phrase_' . $count . '}'; |
| 206 | + } |
|
| 197 | 207 | $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), '\\\'') . '[[:>:]]'; |
| 198 | 208 | } |
| 199 | 209 | $count = 0; |
| 200 | - if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) |
|
| 201 | - foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 210 | + if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) { |
|
| 211 | + foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 202 | 212 | { |
| 203 | 213 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_words_' . $count . '}'; |
| 214 | + } |
|
| 204 | 215 | $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), '\\\'') . '[[:>:]]'; |
| 205 | 216 | } |
| 206 | 217 | |
@@ -223,12 +234,11 @@ discard block |
||
| 223 | 234 | } |
| 224 | 235 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:body_match})'; |
| 225 | 236 | $query_params['language_ftx'] = $language_ftx; |
| 237 | + } else { |
|
| 238 | + $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
| 226 | 239 | } |
| 227 | - else |
|
| 228 | - $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
| 229 | 240 | $query_params['body_match'] = implode(' ', array_diff($words['indexed_words'], $query_params['excluded_index_words'])); |
| 230 | - } |
|
| 231 | - else |
|
| 241 | + } else |
|
| 232 | 242 | { |
| 233 | 243 | $query_params['boolean_match'] = ''; |
| 234 | 244 | |
@@ -242,10 +252,10 @@ discard block |
||
| 242 | 252 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' '; |
| 243 | 253 | $row++; |
| 244 | 254 | } |
| 245 | - } |
|
| 246 | - else |
|
| 247 | - foreach ($words['indexed_words'] as $fulltextWord) |
|
| 255 | + } else { |
|
| 256 | + foreach ($words['indexed_words'] as $fulltextWord) |
|
| 248 | 257 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' '; |
| 258 | + } |
|
| 249 | 259 | |
| 250 | 260 | $query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1); |
| 251 | 261 | |
@@ -268,9 +278,9 @@ discard block |
||
| 268 | 278 | } |
| 269 | 279 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:boolean_match})'; |
| 270 | 280 | $query_params['language_ftx'] = $language_ftx; |
| 281 | + } else { |
|
| 282 | + $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
| 271 | 283 | } |
| 272 | - else |
|
| 273 | - $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
| 274 | 284 | } |
| 275 | 285 | |
| 276 | 286 | } |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 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 | * Add the file functions to the $smcFunc array. |
@@ -52,8 +53,9 @@ discard block |
||
| 52 | 53 | 'messages', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages', |
| 53 | 54 | 'pm_recipients', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys', |
| 54 | 55 | 'themes', 'topics'); |
| 55 | - foreach ($reservedTables as $k => $table_name) |
|
| 56 | - $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
| 56 | + foreach ($reservedTables as $k => $table_name) { |
|
| 57 | + $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
| 58 | + } |
|
| 57 | 59 | |
| 58 | 60 | // We in turn may need the extra stuff. |
| 59 | 61 | db_extend('extra'); |
@@ -102,8 +104,9 @@ discard block |
||
| 102 | 104 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 103 | 105 | |
| 104 | 106 | // First - no way do we touch SMF tables. |
| 105 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
| 106 | - return false; |
|
| 107 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
| 108 | + return false; |
|
| 109 | + } |
|
| 107 | 110 | |
| 108 | 111 | // Log that we'll want to remove this on uninstall. |
| 109 | 112 | $db_package_log[] = array('remove_table', $table_name); |
@@ -113,10 +116,11 @@ discard block |
||
| 113 | 116 | if (in_array($full_table_name, $tables)) |
| 114 | 117 | { |
| 115 | 118 | // This is a sad day... drop the table? If not, return false (error) by default. |
| 116 | - if ($if_exists == 'overwrite') |
|
| 117 | - $smcFunc['db_drop_table']($table_name); |
|
| 118 | - else |
|
| 119 | - return $if_exists == 'ignore'; |
|
| 119 | + if ($if_exists == 'overwrite') { |
|
| 120 | + $smcFunc['db_drop_table']($table_name); |
|
| 121 | + } else { |
|
| 122 | + return $if_exists == 'ignore'; |
|
| 123 | + } |
|
| 120 | 124 | } |
| 121 | 125 | |
| 122 | 126 | // If we've got this far - good news - no table exists. We can build our own! |
@@ -134,17 +138,18 @@ discard block |
||
| 134 | 138 | ) |
| 135 | 139 | ); |
| 136 | 140 | $default = 'default nextval(\'' . $table_name . '_seq\')'; |
| 141 | + } elseif (isset($column['default']) && $column['default'] !== null) { |
|
| 142 | + $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
| 143 | + } else { |
|
| 144 | + $default = ''; |
|
| 137 | 145 | } |
| 138 | - elseif (isset($column['default']) && $column['default'] !== null) |
|
| 139 | - $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
| 140 | - else |
|
| 141 | - $default = ''; |
|
| 142 | 146 | |
| 143 | 147 | // Sort out the size... |
| 144 | 148 | $column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null; |
| 145 | 149 | list ($type, $size) = $smcFunc['db_calculate_type']($column['type'], $column['size']); |
| 146 | - if ($size !== null) |
|
| 147 | - $type = $type . '(' . $size . ')'; |
|
| 150 | + if ($size !== null) { |
|
| 151 | + $type = $type . '(' . $size . ')'; |
|
| 152 | + } |
|
| 148 | 153 | |
| 149 | 154 | // Now just put it together! |
| 150 | 155 | $table_query .= "\n\t\"" . $column['name'] . '" ' . $type . ' ' . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default . ','; |
@@ -157,19 +162,21 @@ discard block |
||
| 157 | 162 | $columns = implode(',', $index['columns']); |
| 158 | 163 | |
| 159 | 164 | // Primary goes in the table... |
| 160 | - if (isset($index['type']) && $index['type'] == 'primary') |
|
| 161 | - $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
| 162 | - else |
|
| 165 | + if (isset($index['type']) && $index['type'] == 'primary') { |
|
| 166 | + $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
| 167 | + } else |
|
| 163 | 168 | { |
| 164 | - if (empty($index['name'])) |
|
| 165 | - $index['name'] = implode('_', $index['columns']); |
|
| 169 | + if (empty($index['name'])) { |
|
| 170 | + $index['name'] = implode('_', $index['columns']); |
|
| 171 | + } |
|
| 166 | 172 | $index_queries[] = 'CREATE ' . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $table_name . '_' . $index['name'] . ' ON ' . $table_name . ' (' . $columns . ')'; |
| 167 | 173 | } |
| 168 | 174 | } |
| 169 | 175 | |
| 170 | 176 | // No trailing commas! |
| 171 | - if (substr($table_query, -1) == ',') |
|
| 172 | - $table_query = substr($table_query, 0, -1); |
|
| 177 | + if (substr($table_query, -1) == ',') { |
|
| 178 | + $table_query = substr($table_query, 0, -1); |
|
| 179 | + } |
|
| 173 | 180 | |
| 174 | 181 | $table_query .= ')'; |
| 175 | 182 | |
@@ -180,12 +187,13 @@ discard block |
||
| 180 | 187 | ) |
| 181 | 188 | ); |
| 182 | 189 | // And the indexes... |
| 183 | - foreach ($index_queries as $query) |
|
| 184 | - $smcFunc['db_query']('', $query, |
|
| 190 | + foreach ($index_queries as $query) { |
|
| 191 | + $smcFunc['db_query']('', $query, |
|
| 185 | 192 | array( |
| 186 | 193 | 'security_override' => true, |
| 187 | 194 | ) |
| 188 | 195 | ); |
| 196 | + } |
|
| 189 | 197 | |
| 190 | 198 | // Go, go power rangers! |
| 191 | 199 | $smcFunc['db_transaction']('commit'); |
@@ -213,8 +221,9 @@ discard block |
||
| 213 | 221 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 214 | 222 | |
| 215 | 223 | // God no - dropping one of these = bad. |
| 216 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
| 217 | - return false; |
|
| 224 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
| 225 | + return false; |
|
| 226 | + } |
|
| 218 | 227 | |
| 219 | 228 | // Does it exist? |
| 220 | 229 | if (in_array($full_table_name, $smcFunc['db_list_tables']())) |
@@ -272,21 +281,24 @@ discard block |
||
| 272 | 281 | |
| 273 | 282 | // Does it exist - if so don't add it again! |
| 274 | 283 | $columns = $smcFunc['db_list_columns']($table_name, false); |
| 275 | - foreach ($columns as $column) |
|
| 276 | - if ($column == $column_info['name']) |
|
| 284 | + foreach ($columns as $column) { |
|
| 285 | + if ($column == $column_info['name']) |
|
| 277 | 286 | { |
| 278 | 287 | // If we're going to overwrite then use change column. |
| 279 | 288 | if ($if_exists == 'update') |
| 280 | 289 | return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
| 281 | - else |
|
| 282 | - return false; |
|
| 290 | + } |
|
| 291 | + else { |
|
| 292 | + return false; |
|
| 293 | + } |
|
| 283 | 294 | } |
| 284 | 295 | |
| 285 | 296 | // Get the specifics... |
| 286 | 297 | $column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null; |
| 287 | 298 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']); |
| 288 | - if ($size !== null) |
|
| 289 | - $type = $type . '(' . $size . ')'; |
|
| 299 | + if ($size !== null) { |
|
| 300 | + $type = $type . '(' . $size . ')'; |
|
| 301 | + } |
|
| 290 | 302 | |
| 291 | 303 | // Now add the thing! |
| 292 | 304 | $query = ' |
@@ -301,11 +313,12 @@ discard block |
||
| 301 | 313 | // If there's more attributes they need to be done via a change on PostgreSQL. |
| 302 | 314 | unset($column_info['type'], $column_info['size']); |
| 303 | 315 | |
| 304 | - if (count($column_info) != 1) |
|
| 305 | - return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
|
| 306 | - else |
|
| 307 | - return true; |
|
| 308 | -} |
|
| 316 | + if (count($column_info) != 1) { |
|
| 317 | + return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
|
| 318 | + } else { |
|
| 319 | + return true; |
|
| 320 | + } |
|
| 321 | + } |
|
| 309 | 322 | |
| 310 | 323 | /** |
| 311 | 324 | * Removes a column. |
@@ -324,8 +337,8 @@ discard block |
||
| 324 | 337 | |
| 325 | 338 | // Does it exist? |
| 326 | 339 | $columns = $smcFunc['db_list_columns']($table_name, true); |
| 327 | - foreach ($columns as $column) |
|
| 328 | - if ($column['name'] == $column_name) |
|
| 340 | + foreach ($columns as $column) { |
|
| 341 | + if ($column['name'] == $column_name) |
|
| 329 | 342 | { |
| 330 | 343 | // If there is an auto we need remove it! |
| 331 | 344 | if ($column['auto']) |
@@ -335,6 +348,7 @@ discard block |
||
| 335 | 348 | 'security_override' => true, |
| 336 | 349 | ) |
| 337 | 350 | ); |
| 351 | + } |
|
| 338 | 352 | |
| 339 | 353 | $smcFunc['db_query']('', ' |
| 340 | 354 | ALTER TABLE ' . $table_name . ' |
@@ -369,13 +383,15 @@ discard block |
||
| 369 | 383 | // Check it does exist! |
| 370 | 384 | $columns = $smcFunc['db_list_columns']($table_name, true); |
| 371 | 385 | $old_info = null; |
| 372 | - foreach ($columns as $column) |
|
| 373 | - if ($column['name'] == $old_column) |
|
| 386 | + foreach ($columns as $column) { |
|
| 387 | + if ($column['name'] == $old_column) |
|
| 374 | 388 | $old_info = $column; |
| 389 | + } |
|
| 375 | 390 | |
| 376 | 391 | // Nothing? |
| 377 | - if ($old_info == null) |
|
| 378 | - return false; |
|
| 392 | + if ($old_info == null) { |
|
| 393 | + return false; |
|
| 394 | + } |
|
| 379 | 395 | |
| 380 | 396 | // Now we check each bit individually and ALTER as required. |
| 381 | 397 | if (isset($column_info['name']) && $column_info['name'] != $old_column) |
@@ -432,8 +448,9 @@ discard block |
||
| 432 | 448 | { |
| 433 | 449 | $column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null; |
| 434 | 450 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']); |
| 435 | - if ($size !== null) |
|
| 436 | - $type = $type . '(' . $size . ')'; |
|
| 451 | + if ($size !== null) { |
|
| 452 | + $type = $type . '(' . $size . ')'; |
|
| 453 | + } |
|
| 437 | 454 | |
| 438 | 455 | // The alter is a pain. |
| 439 | 456 | $smcFunc['db_transaction']('begin'); |
@@ -527,21 +544,23 @@ discard block |
||
| 527 | 544 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 528 | 545 | |
| 529 | 546 | // No columns = no index. |
| 530 | - if (empty($index_info['columns'])) |
|
| 531 | - return false; |
|
| 547 | + if (empty($index_info['columns'])) { |
|
| 548 | + return false; |
|
| 549 | + } |
|
| 532 | 550 | $columns = implode(',', $index_info['columns']); |
| 533 | 551 | |
| 534 | 552 | // No name - make it up! |
| 535 | 553 | if (empty($index_info['name'])) |
| 536 | 554 | { |
| 537 | 555 | // No need for primary. |
| 538 | - if (isset($index_info['type']) && $index_info['type'] == 'primary') |
|
| 539 | - $index_info['name'] = ''; |
|
| 540 | - else |
|
| 541 | - $index_info['name'] = $table_name . implode('_', $index_info['columns']); |
|
| 556 | + if (isset($index_info['type']) && $index_info['type'] == 'primary') { |
|
| 557 | + $index_info['name'] = ''; |
|
| 558 | + } else { |
|
| 559 | + $index_info['name'] = $table_name . implode('_', $index_info['columns']); |
|
| 560 | + } |
|
| 561 | + } else { |
|
| 562 | + $index_info['name'] = $table_name . $index_info['name']; |
|
| 542 | 563 | } |
| 543 | - else |
|
| 544 | - $index_info['name'] = $table_name . $index_info['name']; |
|
| 545 | 564 | |
| 546 | 565 | // Log that we are going to want to remove this! |
| 547 | 566 | $db_package_log[] = array('remove_index', $table_name, $index_info['name']); |
@@ -554,10 +573,11 @@ discard block |
||
| 554 | 573 | if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary')) |
| 555 | 574 | { |
| 556 | 575 | // If we want to overwrite simply remove the current one then continue. |
| 557 | - if ($if_exists != 'update' || $index['type'] == 'primary') |
|
| 558 | - return false; |
|
| 559 | - else |
|
| 560 | - $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
| 576 | + if ($if_exists != 'update' || $index['type'] == 'primary') { |
|
| 577 | + return false; |
|
| 578 | + } else { |
|
| 579 | + $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
| 580 | + } |
|
| 561 | 581 | } |
| 562 | 582 | } |
| 563 | 583 | |
@@ -571,8 +591,7 @@ discard block |
||
| 571 | 591 | 'security_override' => true, |
| 572 | 592 | ) |
| 573 | 593 | ); |
| 574 | - } |
|
| 575 | - else |
|
| 594 | + } else |
|
| 576 | 595 | { |
| 577 | 596 | $smcFunc['db_query']('', ' |
| 578 | 597 | CREATE ' . (isset($index_info['type']) && $index_info['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $index_info['name'] . ' ON ' . $table_name . ' (' . $columns . ')', |
@@ -600,8 +619,9 @@ discard block |
||
| 600 | 619 | |
| 601 | 620 | // Better exist! |
| 602 | 621 | $indexes = $smcFunc['db_list_indexes']($table_name, true); |
| 603 | - if ($index_name != 'primary') |
|
| 604 | - $index_name = $table_name . '_' . $index_name; |
|
| 622 | + if ($index_name != 'primary') { |
|
| 623 | + $index_name = $table_name . '_' . $index_name; |
|
| 624 | + } |
|
| 605 | 625 | |
| 606 | 626 | foreach ($indexes as $index) |
| 607 | 627 | { |
@@ -665,8 +685,7 @@ discard block |
||
| 665 | 685 | 'datetime' => 'timestamp without time zone', |
| 666 | 686 | 'timestamp' => 'timestamp without time zone', |
| 667 | 687 | ); |
| 668 | - } |
|
| 669 | - else |
|
| 688 | + } else |
|
| 670 | 689 | { |
| 671 | 690 | $types = array( |
| 672 | 691 | 'character varying' => 'varchar', |
@@ -682,14 +701,16 @@ discard block |
||
| 682 | 701 | // Got it? Change it! |
| 683 | 702 | if (isset($types[$type_name])) |
| 684 | 703 | { |
| 685 | - if ($type_name == 'tinytext') |
|
| 686 | - $type_size = 255; |
|
| 704 | + if ($type_name == 'tinytext') { |
|
| 705 | + $type_size = 255; |
|
| 706 | + } |
|
| 687 | 707 | $type_name = $types[$type_name]; |
| 688 | 708 | } |
| 689 | 709 | |
| 690 | 710 | // Only char fields got size |
| 691 | - if (strpos($type_name, 'char') === false) |
|
| 692 | - $type_size = null; |
|
| 711 | + if (strpos($type_name, 'char') === false) { |
|
| 712 | + $type_size = null; |
|
| 713 | + } |
|
| 693 | 714 | |
| 694 | 715 | |
| 695 | 716 | return array($type_name, $type_size); |
@@ -744,8 +765,7 @@ discard block |
||
| 744 | 765 | if (!$detail) |
| 745 | 766 | { |
| 746 | 767 | $columns[] = $row['column_name']; |
| 747 | - } |
|
| 748 | - else |
|
| 768 | + } else |
|
| 749 | 769 | { |
| 750 | 770 | $auto = false; |
| 751 | 771 | // What is the default? |
@@ -753,11 +773,11 @@ discard block |
||
| 753 | 773 | { |
| 754 | 774 | $default = null; |
| 755 | 775 | $auto = true; |
| 776 | + } elseif (trim($row['column_default']) != '') { |
|
| 777 | + $default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::')); |
|
| 778 | + } else { |
|
| 779 | + $default = null; |
|
| 756 | 780 | } |
| 757 | - elseif (trim($row['column_default']) != '') |
|
| 758 | - $default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::')); |
|
| 759 | - else |
|
| 760 | - $default = null; |
|
| 761 | 781 | |
| 762 | 782 | // Make the type generic. |
| 763 | 783 | list ($type, $size) = $smcFunc['db_calculate_type']($row['data_type'], $row['character_maximum_length'], true); |
@@ -808,26 +828,30 @@ discard block |
||
| 808 | 828 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 809 | 829 | { |
| 810 | 830 | // Try get the columns that make it up. |
| 811 | - if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) |
|
| 812 | - continue; |
|
| 831 | + if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) { |
|
| 832 | + continue; |
|
| 833 | + } |
|
| 813 | 834 | |
| 814 | 835 | $columns = explode(',', $matches[1]); |
| 815 | 836 | |
| 816 | - if (empty($columns)) |
|
| 817 | - continue; |
|
| 837 | + if (empty($columns)) { |
|
| 838 | + continue; |
|
| 839 | + } |
|
| 818 | 840 | |
| 819 | - foreach ($columns as $k => $v) |
|
| 820 | - $columns[$k] = trim($v); |
|
| 841 | + foreach ($columns as $k => $v) { |
|
| 842 | + $columns[$k] = trim($v); |
|
| 843 | + } |
|
| 821 | 844 | |
| 822 | 845 | // Fix up the name to be consistent cross databases |
| 823 | - if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1) |
|
| 824 | - $row['name'] = 'PRIMARY'; |
|
| 825 | - else |
|
| 826 | - $row['name'] = str_replace($table_name . '_', '', $row['name']); |
|
| 846 | + if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1) { |
|
| 847 | + $row['name'] = 'PRIMARY'; |
|
| 848 | + } else { |
|
| 849 | + $row['name'] = str_replace($table_name . '_', '', $row['name']); |
|
| 850 | + } |
|
| 827 | 851 | |
| 828 | - if (!$detail) |
|
| 829 | - $indexes[] = $row['name']; |
|
| 830 | - else |
|
| 852 | + if (!$detail) { |
|
| 853 | + $indexes[] = $row['name']; |
|
| 854 | + } else |
|
| 831 | 855 | { |
| 832 | 856 | $indexes[$row['name']] = array( |
| 833 | 857 | 'name' => $row['name'], |