@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | $ts = strftime("%H:%M:%S", time()); |
42 | 42 | if (function_exists('posix_getpid')) { |
43 | - $ts = "$ts/" . posix_getpid(); |
|
43 | + $ts = "$ts/".posix_getpid(); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | if (Debug::$logfile) { |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | |
61 | 61 | if (!$locked) { |
62 | 62 | fclose($fp); |
63 | - user_error("Unable to lock debugging log file: " . Debug::$logfile, E_USER_WARNING); |
|
63 | + user_error("Unable to lock debugging log file: ".Debug::$logfile, E_USER_WARNING); |
|
64 | 64 | return; |
65 | 65 | } |
66 | 66 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | return; |
78 | 78 | |
79 | 79 | } else { |
80 | - user_error("Unable to open debugging log file: " . Debug::$logfile, E_USER_WARNING); |
|
80 | + user_error("Unable to open debugging log file: ".Debug::$logfile, E_USER_WARNING); |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | foreach (json_decode($tmp_line["match_on"], true) as $feed_id) { |
222 | 222 | |
223 | 223 | if (strpos($feed_id, "CAT:") === 0) { |
224 | - $feed_id = (int)substr($feed_id, 4); |
|
224 | + $feed_id = (int) substr($feed_id, 4); |
|
225 | 225 | if ($feed_id) { |
226 | 226 | array_push($match, [Feeds::getCategoryTitle($feed_id), true, false]); |
227 | 227 | } else { |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | } |
230 | 230 | } else { |
231 | 231 | if ($feed_id) { |
232 | - array_push($match, [Feeds::getFeedTitle((int)$feed_id), false, false]); |
|
232 | + array_push($match, [Feeds::getFeedTitle((int) $feed_id), false, false]); |
|
233 | 233 | } else { |
234 | 234 | array_push($match, [0, false, true]); |
235 | 235 | } |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | list ($name, $is_cat, $is_id) = $match; |
430 | 430 | |
431 | 431 | if ($is_id) { |
432 | - array_push($match_on, ($is_cat ? "CAT:" : "") . $name); |
|
432 | + array_push($match_on, ($is_cat ? "CAT:" : "").$name); |
|
433 | 433 | } else { |
434 | 434 | |
435 | 435 | if (!$is_cat) { |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | } |
459 | 459 | |
460 | 460 | $reg_exp = $rule["reg_exp"]; |
461 | - $filter_type = (int)$rule["filter_type"]; |
|
461 | + $filter_type = (int) $rule["filter_type"]; |
|
462 | 462 | $inverse = bool_to_sql_bool($rule["inverse"]); |
463 | 463 | $match_on = json_encode($match_on); |
464 | 464 | |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | |
493 | 493 | $cat_filter = bool_to_sql_bool($rule["cat_filter"]); |
494 | 494 | $reg_exp = $rule["reg_exp"]; |
495 | - $filter_type = (int)$rule["filter_type"]; |
|
495 | + $filter_type = (int) $rule["filter_type"]; |
|
496 | 496 | $inverse = bool_to_sql_bool($rule["inverse"]); |
497 | 497 | |
498 | 498 | $usth = $this->pdo->prepare("INSERT INTO ttrss_filters2_rules |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | ### HSL >> RGB |
184 | 184 | function _color_hsl2rgb($hsl) { |
185 | 185 | $h = $hsl[0]; $s = $hsl[1]; $l = $hsl[2]; |
186 | - $m2 = ($l <= 0.5) ? $l * ($s + 1) : $l + $s - $l*$s; |
|
186 | + $m2 = ($l <= 0.5) ? $l * ($s + 1) : $l + $s - $l * $s; |
|
187 | 187 | $m1 = $l * 2 - $m2; |
188 | 188 | return array(_color_hue2rgb($m1, $m2, $h + 0.33333), |
189 | 189 | _color_hue2rgb($m1, $m2, $h), |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | $hex = substr($hex, 1); |
209 | 209 | |
210 | 210 | if (strlen($hex) == 4) { |
211 | - $hex = $hex[1] . $hex[1] . $hex[2] . $hex[2] . $hex[3] . $hex[3]; |
|
211 | + $hex = $hex[1].$hex[1].$hex[2].$hex[2].$hex[3].$hex[3]; |
|
212 | 212 | } |
213 | 213 | $c = hexdec($hex); |
214 | 214 | for ($i = 16; $i >= 0; $i -= 8) { |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | function _color_pack($rgb, $normalize = false) { |
221 | 221 | foreach ($rgb as $k => $v) { |
222 | 222 | $out |= (($v * ($normalize ? 255 : 1)) << (16 - $k * 8)); |
223 | - }return '#'. str_pad(dechex($out), 6, 0, STR_PAD_LEFT); |
|
223 | + }return '#'.str_pad(dechex($out), 6, 0, STR_PAD_LEFT); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | function rgb2hsl($arr) { |
@@ -244,13 +244,13 @@ discard block |
||
244 | 244 | } else { |
245 | 245 | $s = $del_Max / $var_Max; |
246 | 246 | |
247 | - $del_R = ((($var_Max - $var_R ) / 6 ) + ($del_Max / 2 ) ) / $del_Max; |
|
248 | - $del_G = ((($var_Max - $var_G ) / 6 ) + ($del_Max / 2 ) ) / $del_Max; |
|
249 | - $del_B = ((($var_Max - $var_B ) / 6 ) + ($del_Max / 2 ) ) / $del_Max; |
|
247 | + $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
248 | + $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
249 | + $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
250 | 250 | |
251 | - if ($var_R == $var_Max) $h = $del_B - $del_G; |
|
252 | - else if ($var_G == $var_Max) $h = (1 / 3 ) + $del_R - $del_B; |
|
253 | - else if ($var_B == $var_Max) $h = (2 / 3 ) + $del_G - $del_R; |
|
251 | + if ($var_R == $var_Max) $h = $del_B - $del_G; |
|
252 | + else if ($var_G == $var_Max) $h = (1 / 3) + $del_R - $del_B; |
|
253 | + else if ($var_B == $var_Max) $h = (2 / 3) + $del_G - $del_R; |
|
254 | 254 | |
255 | 255 | if ($h < 0) $h++; |
256 | 256 | if ($h > 1) $h--; |
@@ -264,21 +264,21 @@ discard block |
||
264 | 264 | $s = $arr[1]; |
265 | 265 | $v = $arr[2]; |
266 | 266 | |
267 | - if($s == 0) { |
|
267 | + if ($s == 0) { |
|
268 | 268 | $r = $g = $B = $v * 255; |
269 | 269 | } else { |
270 | 270 | $var_H = $h * 6; |
271 | - $var_i = floor($var_H ); |
|
272 | - $var_1 = $v * (1 - $s ); |
|
273 | - $var_2 = $v * (1 - $s * ($var_H - $var_i ) ); |
|
274 | - $var_3 = $v * (1 - $s * (1 - ($var_H - $var_i ) ) ); |
|
275 | - |
|
276 | - if ($var_i == 0) { $var_R = $v ; $var_G = $var_3 ; $var_B = $var_1 ; } |
|
277 | - else if ($var_i == 1) { $var_R = $var_2 ; $var_G = $v ; $var_B = $var_1 ; } |
|
278 | - else if ($var_i == 2) { $var_R = $var_1 ; $var_G = $v ; $var_B = $var_3 ; } |
|
279 | - else if ($var_i == 3) { $var_R = $var_1 ; $var_G = $var_2 ; $var_B = $v ; } |
|
280 | - else if ($var_i == 4) { $var_R = $var_3 ; $var_G = $var_1 ; $var_B = $v ; } |
|
281 | - else { $var_R = $v ; $var_G = $var_1 ; $var_B = $var_2 ; } |
|
271 | + $var_i = floor($var_H); |
|
272 | + $var_1 = $v * (1 - $s); |
|
273 | + $var_2 = $v * (1 - $s * ($var_H - $var_i)); |
|
274 | + $var_3 = $v * (1 - $s * (1 - ($var_H - $var_i))); |
|
275 | + |
|
276 | + if ($var_i == 0) { $var_R = $v; $var_G = $var_3; $var_B = $var_1; } |
|
277 | + else if ($var_i == 1) { $var_R = $var_2; $var_G = $v; $var_B = $var_1; } |
|
278 | + else if ($var_i == 2) { $var_R = $var_1; $var_G = $v; $var_B = $var_3; } |
|
279 | + else if ($var_i == 3) { $var_R = $var_1; $var_G = $var_2; $var_B = $v; } |
|
280 | + else if ($var_i == 4) { $var_R = $var_3; $var_G = $var_1; $var_B = $v; } |
|
281 | + else { $var_R = $v; $var_G = $var_1; $var_B = $var_2; } |
|
282 | 282 | |
283 | 283 | $r = $var_R * 255; |
284 | 284 | $g = $var_G * 255; |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | } |
289 | 289 | |
290 | 290 | function colorPalette($imageFile, $numColors, $granularity = 5) { |
291 | - $granularity = max(1, abs((int)$granularity)); |
|
291 | + $granularity = max(1, abs((int) $granularity)); |
|
292 | 292 | $colors = array(); |
293 | 293 | |
294 | 294 | $size = @getimagesize($imageFile); |
@@ -301,10 +301,10 @@ discard block |
||
301 | 301 | $ico = new floIcon(); |
302 | 302 | @$ico->readICO($imageFile); |
303 | 303 | |
304 | - if(count($ico->images)==0) |
|
304 | + if (count($ico->images) == 0) |
|
305 | 305 | return false; |
306 | 306 | else |
307 | - $img = @$ico->images[count($ico->images)-1]->getImageResource(); |
|
307 | + $img = @$ico->images[count($ico->images) - 1]->getImageResource(); |
|
308 | 308 | |
309 | 309 | } else { |
310 | 310 | return false; |
@@ -316,17 +316,17 @@ discard block |
||
316 | 316 | |
317 | 317 | if (!$img) return false; |
318 | 318 | |
319 | - for($x = 0; $x < $size[0]; $x += $granularity) { |
|
320 | - for($y = 0; $y < $size[1]; $y += $granularity) { |
|
319 | + for ($x = 0; $x < $size[0]; $x += $granularity) { |
|
320 | + for ($y = 0; $y < $size[1]; $y += $granularity) { |
|
321 | 321 | $thisColor = imagecolorat($img, $x, $y); |
322 | 322 | $rgb = imagecolorsforindex($img, $thisColor); |
323 | 323 | $red = round(round(($rgb['red'] / 0x33)) * 0x33); |
324 | 324 | $green = round(round(($rgb['green'] / 0x33)) * 0x33); |
325 | 325 | $blue = round(round(($rgb['blue'] / 0x33)) * 0x33); |
326 | 326 | $thisRGB = sprintf('%02X%02X%02X', $red, $green, $blue); |
327 | - if(array_key_exists($thisRGB, $colors)) { |
|
327 | + if (array_key_exists($thisRGB, $colors)) { |
|
328 | 328 | $colors[$thisRGB]++; |
329 | - } else{ |
|
329 | + } else { |
|
330 | 330 | $colors[$thisRGB] = 1; |
331 | 331 | } |
332 | 332 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | if (!is_array($options)) { |
204 | 204 | |
205 | 205 | // falling back on compatibility shim |
206 | - $option_names = [ "url", "type", "login", "pass", "post_query", "timeout", "last_modified", "useragent" ]; |
|
206 | + $option_names = ["url", "type", "login", "pass", "post_query", "timeout", "last_modified", "useragent"]; |
|
207 | 207 | $tmp = []; |
208 | 208 | |
209 | 209 | for ($i = 0; $i < func_num_args(); $i++) { |
@@ -230,13 +230,13 @@ discard block |
||
230 | 230 | $url = str_replace(' ', '%20', $url); |
231 | 231 | |
232 | 232 | if (strpos($url, "//") === 0) |
233 | - $url = 'http:' . $url; |
|
233 | + $url = 'http:'.$url; |
|
234 | 234 | |
235 | 235 | $url_host = parse_url($url, PHP_URL_HOST); |
236 | 236 | $fetch_domain_hits[$url_host] += 1; |
237 | 237 | |
238 | 238 | if ($fetch_domain_hits[$url_host] > MAX_FETCH_REQUESTS_PER_HOST) { |
239 | - user_error("Exceeded fetch request quota for $url_host: " . $fetch_domain_hits[$url_host], E_USER_WARNING); |
|
239 | + user_error("Exceeded fetch request quota for $url_host: ".$fetch_domain_hits[$url_host], E_USER_WARNING); |
|
240 | 240 | #return false; |
241 | 241 | } |
242 | 242 | |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | array_push($curl_http_headers, "If-Modified-Since: $last_modified"); |
253 | 253 | |
254 | 254 | if ($http_accept) |
255 | - array_push($curl_http_headers, "Accept: " . $http_accept); |
|
255 | + array_push($curl_http_headers, "Accept: ".$http_accept); |
|
256 | 256 | |
257 | 257 | if (count($curl_http_headers) > 0) |
258 | 258 | curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_http_headers); |
@@ -265,11 +265,10 @@ discard block |
||
265 | 265 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
266 | 266 | curl_setopt($ch, CURLOPT_HEADER, true); |
267 | 267 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); |
268 | - curl_setopt($ch, CURLOPT_USERAGENT, $useragent ? $useragent : |
|
269 | - SELF_USER_AGENT); |
|
268 | + curl_setopt($ch, CURLOPT_USERAGENT, $useragent ? $useragent : SELF_USER_AGENT); |
|
270 | 269 | curl_setopt($ch, CURLOPT_ENCODING, ""); |
271 | 270 | |
272 | - if ($http_referrer) |
|
271 | + if ($http_referrer) |
|
273 | 272 | curl_setopt($ch, CURLOPT_REFERER, $http_referrer); |
274 | 273 | |
275 | 274 | if ($max_size) { |
@@ -278,7 +277,7 @@ discard block |
||
278 | 277 | |
279 | 278 | // holy shit closures in php |
280 | 279 | // download & upload are *expected* sizes respectively, could be zero |
281 | - curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function($curl_handle, $download_size, $downloaded, $upload_size, $uploaded) use( &$max_size) { |
|
280 | + curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function($curl_handle, $download_size, $downloaded, $upload_size, $uploaded) use(&$max_size) { |
|
282 | 281 | Debug::log("[curl progressfunction] $downloaded $max_size", Debug::$LOG_EXTENDED); |
283 | 282 | |
284 | 283 | return ($downloaded > $max_size) ? 1 : 0; // if max size is set, abort when exceeding it |
@@ -338,7 +337,7 @@ discard block |
||
338 | 337 | if ($http_code != 200 || $type && strpos($fetch_last_content_type, "$type") === false) { |
339 | 338 | |
340 | 339 | if (curl_errno($ch) != 0) { |
341 | - $fetch_last_error .= "; " . curl_errno($ch) . " " . curl_error($ch); |
|
340 | + $fetch_last_error .= "; ".curl_errno($ch)." ".curl_error($ch); |
|
342 | 341 | } |
343 | 342 | |
344 | 343 | $fetch_last_error_content = $contents; |
@@ -347,7 +346,7 @@ discard block |
||
347 | 346 | } |
348 | 347 | |
349 | 348 | if (!$contents) { |
350 | - $fetch_last_error = curl_errno($ch) . " " . curl_error($ch); |
|
349 | + $fetch_last_error = curl_errno($ch)." ".curl_error($ch); |
|
351 | 350 | curl_close($ch); |
352 | 351 | return false; |
353 | 352 | } |
@@ -367,7 +366,7 @@ discard block |
||
367 | 366 | |
368 | 367 | $fetch_curl_used = false; |
369 | 368 | |
370 | - if ($login && $pass){ |
|
369 | + if ($login && $pass) { |
|
371 | 370 | $url_parts = array(); |
372 | 371 | |
373 | 372 | preg_match("/(^[^:]*):\/\/(.*)/", $url, $url_parts); |
@@ -375,7 +374,7 @@ discard block |
||
375 | 374 | $pass = urlencode($pass); |
376 | 375 | |
377 | 376 | if ($url_parts[1] && $url_parts[2]) { |
378 | - $url = $url_parts[1] . "://$login:$pass@" . $url_parts[2]; |
|
377 | + $url = $url_parts[1]."://$login:$pass@".$url_parts[2]; |
|
379 | 378 | } |
380 | 379 | } |
381 | 380 | |
@@ -443,7 +442,7 @@ discard block |
||
443 | 442 | $error = error_get_last(); |
444 | 443 | |
445 | 444 | if ($error['message'] != $old_error['message']) { |
446 | - $fetch_last_error .= "; " . $error["message"]; |
|
445 | + $fetch_last_error .= "; ".$error["message"]; |
|
447 | 446 | } |
448 | 447 | |
449 | 448 | $fetch_last_error_content = $data; |
@@ -518,15 +517,15 @@ discard block |
||
518 | 517 | |
519 | 518 | function get_ssl_certificate_id() { |
520 | 519 | if ($_SERVER["REDIRECT_SSL_CLIENT_M_SERIAL"]) { |
521 | - return sha1($_SERVER["REDIRECT_SSL_CLIENT_M_SERIAL"] . |
|
522 | - $_SERVER["REDIRECT_SSL_CLIENT_V_START"] . |
|
523 | - $_SERVER["REDIRECT_SSL_CLIENT_V_END"] . |
|
520 | + return sha1($_SERVER["REDIRECT_SSL_CLIENT_M_SERIAL"]. |
|
521 | + $_SERVER["REDIRECT_SSL_CLIENT_V_START"]. |
|
522 | + $_SERVER["REDIRECT_SSL_CLIENT_V_END"]. |
|
524 | 523 | $_SERVER["REDIRECT_SSL_CLIENT_S_DN"]); |
525 | 524 | } |
526 | 525 | if ($_SERVER["SSL_CLIENT_M_SERIAL"]) { |
527 | - return sha1($_SERVER["SSL_CLIENT_M_SERIAL"] . |
|
528 | - $_SERVER["SSL_CLIENT_V_START"] . |
|
529 | - $_SERVER["SSL_CLIENT_V_END"] . |
|
526 | + return sha1($_SERVER["SSL_CLIENT_M_SERIAL"]. |
|
527 | + $_SERVER["SSL_CLIENT_V_START"]. |
|
528 | + $_SERVER["SSL_CLIENT_V_END"]. |
|
530 | 529 | $_SERVER["SSL_CLIENT_S_DN"]); |
531 | 530 | } |
532 | 531 | return ""; |
@@ -661,7 +660,7 @@ discard block |
||
661 | 660 | function logout_user() { |
662 | 661 | @session_destroy(); |
663 | 662 | if (isset($_COOKIE[session_name()])) { |
664 | - setcookie(session_name(), '', time()-42000, '/'); |
|
663 | + setcookie(session_name(), '', time() - 42000, '/'); |
|
665 | 664 | } |
666 | 665 | session_commit(); |
667 | 666 | } |
@@ -745,7 +744,7 @@ discard block |
||
745 | 744 | |
746 | 745 | function truncate_string($str, $max_len, $suffix = '…') { |
747 | 746 | if (mb_strlen($str, "utf-8") > $max_len) { |
748 | - return mb_substr($str, 0, $max_len, "utf-8") . $suffix; |
|
747 | + return mb_substr($str, 0, $max_len, "utf-8").$suffix; |
|
749 | 748 | } else { |
750 | 749 | return $str; |
751 | 750 | } |
@@ -755,7 +754,7 @@ discard block |
||
755 | 754 | $startString = mb_substr($original, 0, $position, "UTF-8"); |
756 | 755 | $endString = mb_substr($original, $position + $length, mb_strlen($original), "UTF-8"); |
757 | 756 | |
758 | - $out = $startString . $replacement . $endString; |
|
757 | + $out = $startString.$replacement.$endString; |
|
759 | 758 | |
760 | 759 | return $out; |
761 | 760 | } |
@@ -893,9 +892,9 @@ discard block |
||
893 | 892 | } |
894 | 893 | |
895 | 894 | function file_is_locked($filename) { |
896 | - if (file_exists(LOCK_DIRECTORY . "/$filename")) { |
|
895 | + if (file_exists(LOCK_DIRECTORY."/$filename")) { |
|
897 | 896 | if (function_exists('flock')) { |
898 | - $fp = @fopen(LOCK_DIRECTORY . "/$filename", "r"); |
|
897 | + $fp = @fopen(LOCK_DIRECTORY."/$filename", "r"); |
|
899 | 898 | if ($fp) { |
900 | 899 | if (flock($fp, LOCK_EX | LOCK_NB)) { |
901 | 900 | flock($fp, LOCK_UN); |
@@ -916,11 +915,11 @@ discard block |
||
916 | 915 | |
917 | 916 | |
918 | 917 | function make_lockfile($filename) { |
919 | - $fp = fopen(LOCK_DIRECTORY . "/$filename", "w"); |
|
918 | + $fp = fopen(LOCK_DIRECTORY."/$filename", "w"); |
|
920 | 919 | |
921 | 920 | if ($fp && flock($fp, LOCK_EX | LOCK_NB)) { |
922 | 921 | $stat_h = fstat($fp); |
923 | - $stat_f = stat(LOCK_DIRECTORY . "/$filename"); |
|
922 | + $stat_f = stat(LOCK_DIRECTORY."/$filename"); |
|
924 | 923 | |
925 | 924 | if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { |
926 | 925 | if ($stat_h["ino"] != $stat_f["ino"] || |
@@ -931,7 +930,7 @@ discard block |
||
931 | 930 | } |
932 | 931 | |
933 | 932 | if (function_exists('posix_getpid')) { |
934 | - fwrite($fp, posix_getpid() . "\n"); |
|
933 | + fwrite($fp, posix_getpid()."\n"); |
|
935 | 934 | } |
936 | 935 | return $fp; |
937 | 936 | } else { |
@@ -940,10 +939,10 @@ discard block |
||
940 | 939 | } |
941 | 940 | |
942 | 941 | function make_stampfile($filename) { |
943 | - $fp = fopen(LOCK_DIRECTORY . "/$filename", "w"); |
|
942 | + $fp = fopen(LOCK_DIRECTORY."/$filename", "w"); |
|
944 | 943 | |
945 | 944 | if (flock($fp, LOCK_EX | LOCK_NB)) { |
946 | - fwrite($fp, time() . "\n"); |
|
945 | + fwrite($fp, time()."\n"); |
|
947 | 946 | flock($fp, LOCK_UN); |
948 | 947 | fclose($fp); |
949 | 948 | return true; |
@@ -993,7 +992,7 @@ discard block |
||
993 | 992 | $params["is_default_pw"] = Pref_Prefs::isdefaultpassword(); |
994 | 993 | $params["label_base_index"] = (int) LABEL_BASE_INDEX; |
995 | 994 | |
996 | - $theme = get_pref( "USER_CSS_THEME", false, false); |
|
995 | + $theme = get_pref("USER_CSS_THEME", false, false); |
|
997 | 996 | $params["theme"] = theme_exists($theme) ? $theme : ""; |
998 | 997 | |
999 | 998 | $params["plugins"] = implode(", ", PluginHost::getInstance()->get_plugin_names()); |
@@ -1217,13 +1216,13 @@ discard block |
||
1217 | 1216 | } |
1218 | 1217 | } |
1219 | 1218 | |
1220 | - if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) { |
|
1219 | + if (file_exists(LOCK_DIRECTORY."/update_daemon.lock")) { |
|
1221 | 1220 | |
1222 | 1221 | $data['daemon_is_running'] = (int) file_is_locked("update_daemon.lock"); |
1223 | 1222 | |
1224 | 1223 | if (time() - $_SESSION["daemon_stamp_check"] > 30) { |
1225 | 1224 | |
1226 | - $stamp = (int) @file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp"); |
|
1225 | + $stamp = (int) @file_get_contents(LOCK_DIRECTORY."/update_daemon.stamp"); |
|
1227 | 1226 | |
1228 | 1227 | if ($stamp) { |
1229 | 1228 | $stamp_delta = time() - $stamp; |
@@ -1266,7 +1265,7 @@ discard block |
||
1266 | 1265 | $res = trim($str); if (!$res) return ''; |
1267 | 1266 | |
1268 | 1267 | $doc = new DOMDocument(); |
1269 | - $doc->loadHTML('<?xml encoding="UTF-8">' . $res); |
|
1268 | + $doc->loadHTML('<?xml encoding="UTF-8">'.$res); |
|
1270 | 1269 | $xpath = new DOMXPath($doc); |
1271 | 1270 | |
1272 | 1271 | $rewrite_base_url = $site_url ? $site_url : get_self_url_prefix(); |
@@ -1365,7 +1364,7 @@ discard block |
||
1365 | 1364 | 'ol', 'p', 'picture', 'pre', 'q', 'ruby', 'rp', 'rt', 's', 'samp', 'section', |
1366 | 1365 | 'small', 'source', 'span', 'strike', 'strong', 'sub', 'summary', |
1367 | 1366 | 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'time', |
1368 | - 'tr', 'track', 'tt', 'u', 'ul', 'var', 'wbr', 'video', 'xml:namespace' ); |
|
1367 | + 'tr', 'track', 'tt', 'u', 'ul', 'var', 'wbr', 'video', 'xml:namespace'); |
|
1369 | 1368 | |
1370 | 1369 | if ($_SESSION['hasSandbox']) $allowed_elements[] = 'iframe'; |
1371 | 1370 | |
@@ -1500,8 +1499,8 @@ discard block |
||
1500 | 1499 | |
1501 | 1500 | // this returns SELF_URL_PATH sans ending slash |
1502 | 1501 | function get_self_url_prefix() { |
1503 | - if (strrpos(SELF_URL_PATH, "/") === strlen(SELF_URL_PATH)-1) { |
|
1504 | - return substr(SELF_URL_PATH, 0, strlen(SELF_URL_PATH)-1); |
|
1502 | + if (strrpos(SELF_URL_PATH, "/") === strlen(SELF_URL_PATH) - 1) { |
|
1503 | + return substr(SELF_URL_PATH, 0, strlen(SELF_URL_PATH) - 1); |
|
1505 | 1504 | } else { |
1506 | 1505 | return SELF_URL_PATH; |
1507 | 1506 | } |
@@ -1510,11 +1509,11 @@ discard block |
||
1510 | 1509 | /* TODO: This needs to use bcrypt */ |
1511 | 1510 | function encrypt_password($pass, $salt = '', $mode2 = false) { |
1512 | 1511 | if ($salt && $mode2) { |
1513 | - return "MODE2:" . hash('sha256', $salt . $pass); |
|
1512 | + return "MODE2:".hash('sha256', $salt.$pass); |
|
1514 | 1513 | } else if ($salt) { |
1515 | - return "SHA1X:" . sha1("$salt:$pass"); |
|
1514 | + return "SHA1X:".sha1("$salt:$pass"); |
|
1516 | 1515 | } else { |
1517 | - return "SHA1:" . sha1($pass); |
|
1516 | + return "SHA1:".sha1($pass); |
|
1518 | 1517 | } |
1519 | 1518 | } |
1520 | 1519 | |
@@ -1525,7 +1524,7 @@ discard block |
||
1525 | 1524 | } |
1526 | 1525 | |
1527 | 1526 | function build_url($parts) { |
1528 | - return $parts['scheme'] . "://" . $parts['host'] . $parts['path']; |
|
1527 | + return $parts['scheme']."://".$parts['host'].$parts['path']; |
|
1529 | 1528 | } |
1530 | 1529 | |
1531 | 1530 | function cleanup_url_path($path) { |
@@ -1569,7 +1568,7 @@ discard block |
||
1569 | 1568 | $dir = dirname($parts['path']); |
1570 | 1569 | $dir !== '/' && $dir .= '/'; |
1571 | 1570 | } |
1572 | - $parts['path'] = $dir . $rel_url; |
|
1571 | + $parts['path'] = $dir.$rel_url; |
|
1573 | 1572 | $parts['path'] = cleanup_url_path($parts['path']); |
1574 | 1573 | |
1575 | 1574 | return build_url($parts); |
@@ -1656,12 +1655,12 @@ discard block |
||
1656 | 1655 | |
1657 | 1656 | for ($i = 0; $i < $l10n->total; $i++) { |
1658 | 1657 | $orig = $l10n->get_original_string($i); |
1659 | - if(strpos($orig, "\000") !== FALSE) { // Plural forms |
|
1658 | + if (strpos($orig, "\000") !== FALSE) { // Plural forms |
|
1660 | 1659 | $key = explode(chr(0), $orig); |
1661 | 1660 | print T_js_decl($key[0], _ngettext($key[0], $key[1], 1)); // Singular |
1662 | 1661 | print T_js_decl($key[1], _ngettext($key[0], $key[1], 2)); // Plural |
1663 | 1662 | } else { |
1664 | - $translation = _dgettext($domain,$orig); |
|
1663 | + $translation = _dgettext($domain, $orig); |
|
1665 | 1664 | print T_js_decl($orig, $translation); |
1666 | 1665 | } |
1667 | 1666 | } |
@@ -1717,7 +1716,7 @@ discard block |
||
1717 | 1716 | if (file_exists($filename)) { |
1718 | 1717 | $ext = pathinfo($filename, PATHINFO_EXTENSION); |
1719 | 1718 | |
1720 | - return "data:image/$ext;base64," . base64_encode(file_get_contents($filename)); |
|
1719 | + return "data:image/$ext;base64,".base64_encode(file_get_contents($filename)); |
|
1721 | 1720 | } else { |
1722 | 1721 | return ""; |
1723 | 1722 | } |
@@ -1754,7 +1753,7 @@ discard block |
||
1754 | 1753 | |
1755 | 1754 | header("Content-type: $mimetype"); |
1756 | 1755 | |
1757 | - $stamp = gmdate("D, d M Y H:i:s", filemtime($filename)) . " GMT"; |
|
1756 | + $stamp = gmdate("D, d M Y H:i:s", filemtime($filename))." GMT"; |
|
1758 | 1757 | header("Last-Modified: $stamp", true); |
1759 | 1758 | |
1760 | 1759 | return readfile($filename); |
@@ -1764,7 +1763,7 @@ discard block |
||
1764 | 1763 | } |
1765 | 1764 | |
1766 | 1765 | function arr_qmarks($arr) { |
1767 | - return str_repeat('?,', count($arr) - 1) . '?'; |
|
1766 | + return str_repeat('?,', count($arr) - 1).'?'; |
|
1768 | 1767 | } |
1769 | 1768 | |
1770 | 1769 | function get_scripts_timestamp() { |
@@ -1799,7 +1798,7 @@ discard block |
||
1799 | 1798 | } else if (PHP_OS === "Darwin") { |
1800 | 1799 | $ttrss_version = "UNKNOWN (Unsupported, Darwin)"; |
1801 | 1800 | } else if (file_exists("$root_dir/version_static.txt")) { |
1802 | - $ttrss_version = trim(file_get_contents("$root_dir/version_static.txt")) . " (Unsupported)"; |
|
1801 | + $ttrss_version = trim(file_get_contents("$root_dir/version_static.txt"))." (Unsupported)"; |
|
1803 | 1802 | } else if (is_dir("$root_dir/.git")) { |
1804 | 1803 | $rc = 0; |
1805 | 1804 | $output = []; |
@@ -1817,10 +1816,10 @@ discard block |
||
1817 | 1816 | $git_commit = $commit; |
1818 | 1817 | $git_timestamp = $timestamp; |
1819 | 1818 | |
1820 | - $ttrss_version = strftime("%y.%m", $timestamp) . "-$commit"; |
|
1819 | + $ttrss_version = strftime("%y.%m", $timestamp)."-$commit"; |
|
1821 | 1820 | } |
1822 | 1821 | } else { |
1823 | - user_error("Unable to determine version (using $root_dir): " . implode("\n", $output), E_USER_WARNING); |
|
1822 | + user_error("Unable to determine version (using $root_dir): ".implode("\n", $output), E_USER_WARNING); |
|
1824 | 1823 | } |
1825 | 1824 | } |
1826 | 1825 |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | return true; |
79 | 79 | } |
80 | 80 | |
81 | -function ttrss_open () { |
|
81 | +function ttrss_open() { |
|
82 | 82 | return true; |
83 | 83 | } |
84 | 84 | |
85 | -function ttrss_read ($id){ |
|
85 | +function ttrss_read($id) { |
|
86 | 86 | global $session_expire; |
87 | 87 | |
88 | 88 | $sth = Db::pdo()->prepare("SELECT data FROM ttrss_sessions WHERE id=?"); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
104 | -function ttrss_write ($id, $data) { |
|
104 | +function ttrss_write($id, $data) { |
|
105 | 105 | global $session_expire; |
106 | 106 | |
107 | 107 | $data = base64_encode($data); |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | return true; |
122 | 122 | } |
123 | 123 | |
124 | -function ttrss_close () { |
|
124 | +function ttrss_close() { |
|
125 | 125 | return true; |
126 | 126 | } |
127 | 127 | |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | return true; |
133 | 133 | } |
134 | 134 | |
135 | -function ttrss_gc () { |
|
136 | - Db::pdo()->query("DELETE FROM ttrss_sessions WHERE expire < " . time()); |
|
135 | +function ttrss_gc() { |
|
136 | + Db::pdo()->query("DELETE FROM ttrss_sessions WHERE expire < ".time()); |
|
137 | 137 | |
138 | 138 | return true; |
139 | 139 | } |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | $ret = iterator_to_array($this->childNodes); |
329 | 329 | if ($filterEmptyDOMText) { |
330 | 330 | // Array values is used to discard the key order. Needs to be 0 to whatever without skipping any number |
331 | - $ret = array_values(array_filter($ret, function ($node) { |
|
331 | + $ret = array_values(array_filter($ret, function($node) { |
|
332 | 332 | return $node->nodeName !== '#text' || mb_strlen(trim($node->nodeValue)); |
333 | 333 | })); |
334 | 334 | } |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | } |
428 | 428 | |
429 | 429 | // And there should be no text nodes with real content |
430 | - return array_reduce(iterator_to_array($children), function ($carry, $child) { |
|
430 | + return array_reduce(iterator_to_array($children), function($carry, $child) { |
|
431 | 431 | if (!$carry === false) { |
432 | 432 | return false; |
433 | 433 | } |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | * are dealing with (And at this point we know they are empty or are just whitespace, because of the |
481 | 481 | * mb_strlen in this chain of checks). |
482 | 482 | */ |
483 | - + count(array_filter(iterator_to_array($this->childNodes), function ($child) { |
|
483 | + + count(array_filter(iterator_to_array($this->childNodes), function($child) { |
|
484 | 484 | return $child instanceof DOMText; |
485 | 485 | })) |
486 | 486 | |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | return $this->nodeType === XML_TEXT_NODE || in_array($this->nodeName, $this->phrasing_elems) !== false || |
499 | 499 | (!is_null($this->childNodes) && |
500 | 500 | ($this->nodeName === 'a' || $this->nodeName === 'del' || $this->nodeName === 'ins') && |
501 | - array_reduce(iterator_to_array($this->childNodes), function ($carry, $node) { |
|
501 | + array_reduce(iterator_to_array($this->childNodes), function($carry, $node) { |
|
502 | 502 | return $node->isPhrasingContent() && $carry; |
503 | 503 | }, true) |
504 | 504 | ); |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | $this->attempts[] = ['articleContent' => $result, 'textLength' => $length]; |
195 | 195 | |
196 | 196 | // No luck after removing flags, just return the longest text we found during the different loops |
197 | - usort($this->attempts, function ($a, $b) { |
|
197 | + usort($this->attempts, function($a, $b) { |
|
198 | 198 | return $a['textLength'] < $b['textLength']; |
199 | 199 | }); |
200 | 200 | |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | } |
274 | 274 | |
275 | 275 | // Prepend the XML tag to avoid having issues with special characters. Should be harmless. |
276 | - $dom->loadHTML('<?xml encoding="UTF-8">' . $html); |
|
276 | + $dom->loadHTML('<?xml encoding="UTF-8">'.$html); |
|
277 | 277 | $dom->encoding = 'UTF-8'; |
278 | 278 | |
279 | 279 | $this->removeScripts($dom); |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | * I can assure you it works properly if you let the code run. |
492 | 492 | */ |
493 | 493 | if (preg_match('/ [\|\-\\\\\/>»] /i', $curTitle)) { |
494 | - $titleHadHierarchicalSeparators = (bool)preg_match('/ [\\\\\/>»] /', $curTitle); |
|
494 | + $titleHadHierarchicalSeparators = (bool) preg_match('/ [\\\\\/>»] /', $curTitle); |
|
495 | 495 | $curTitle = preg_replace('/(.*)[\|\-\\\\\/>»] .*/i', '$1', $originalTitle); |
496 | 496 | |
497 | 497 | $this->logger->info(sprintf('[Metadata] Found hierarchical separators in title, new title is: \'%s\'', $curTitle)); |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | // could assume it's the full title. |
508 | 508 | $match = false; |
509 | 509 | for ($i = 1; $i <= 2; $i++) { |
510 | - foreach ($this->dom->getElementsByTagName('h' . $i) as $hTag) { |
|
510 | + foreach ($this->dom->getElementsByTagName('h'.$i) as $hTag) { |
|
511 | 511 | // Trim texts to avoid having false negatives when the title is surrounded by spaces or tabs |
512 | 512 | if (trim($hTag->nodeValue) === trim($curTitle)) { |
513 | 513 | $match = true; |
@@ -579,17 +579,17 @@ discard block |
||
579 | 579 | |
580 | 580 | // Scheme-rooted relative URI. |
581 | 581 | if (substr($uri, 0, 2) === '//') { |
582 | - return $scheme . '://' . substr($uri, 2); |
|
582 | + return $scheme.'://'.substr($uri, 2); |
|
583 | 583 | } |
584 | 584 | |
585 | 585 | // Prepath-rooted relative URI. |
586 | 586 | if (substr($uri, 0, 1) === '/') { |
587 | - return $prePath . $uri; |
|
587 | + return $prePath.$uri; |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | // Dotslash relative URI. |
591 | 591 | if (strpos($uri, './') === 0) { |
592 | - return $pathBase . substr($uri, 2); |
|
592 | + return $pathBase.substr($uri, 2); |
|
593 | 593 | } |
594 | 594 | // Ignore hash URIs: |
595 | 595 | if (substr($uri, 0, 1) === '#') { |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | |
599 | 599 | // Standard relative URI; add entire path. pathBase already includes a |
600 | 600 | // trailing "/". |
601 | - return $pathBase . $uri; |
|
601 | + return $pathBase.$uri; |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | /** |
@@ -614,17 +614,17 @@ discard block |
||
614 | 614 | if ($this->dom->baseURI !== null) { |
615 | 615 | if (substr($this->dom->baseURI, 0, 1) === '/') { |
616 | 616 | // URLs starting with '/' override completely the URL defined in the link |
617 | - $pathBase = parse_url($url, PHP_URL_SCHEME) . '://' . parse_url($url, PHP_URL_HOST) . $this->dom->baseURI; |
|
617 | + $pathBase = parse_url($url, PHP_URL_SCHEME).'://'.parse_url($url, PHP_URL_HOST).$this->dom->baseURI; |
|
618 | 618 | } else { |
619 | 619 | // Otherwise just prepend the base to the actual path |
620 | - $pathBase = parse_url($url, PHP_URL_SCHEME) . '://' . parse_url($url, PHP_URL_HOST) . dirname(parse_url($url, PHP_URL_PATH)) . '/' . rtrim($this->dom->baseURI, '/') . '/'; |
|
620 | + $pathBase = parse_url($url, PHP_URL_SCHEME).'://'.parse_url($url, PHP_URL_HOST).dirname(parse_url($url, PHP_URL_PATH)).'/'.rtrim($this->dom->baseURI, '/').'/'; |
|
621 | 621 | } |
622 | 622 | } else { |
623 | - $pathBase = parse_url($url, PHP_URL_SCHEME) . '://' . parse_url($url, PHP_URL_HOST) . dirname(parse_url($url, PHP_URL_PATH)) . '/'; |
|
623 | + $pathBase = parse_url($url, PHP_URL_SCHEME).'://'.parse_url($url, PHP_URL_HOST).dirname(parse_url($url, PHP_URL_PATH)).'/'; |
|
624 | 624 | } |
625 | 625 | |
626 | 626 | $scheme = parse_url($pathBase, PHP_URL_SCHEME); |
627 | - $prePath = $scheme . '://' . parse_url($pathBase, PHP_URL_HOST); |
|
627 | + $prePath = $scheme.'://'.parse_url($pathBase, PHP_URL_HOST); |
|
628 | 628 | |
629 | 629 | return [$pathBase, $scheme, $prePath]; |
630 | 630 | } |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | continue; |
659 | 659 | } |
660 | 660 | |
661 | - $matchString = $node->getAttribute('class') . ' ' . $node->getAttribute('id'); |
|
661 | + $matchString = $node->getAttribute('class').' '.$node->getAttribute('id'); |
|
662 | 662 | |
663 | 663 | if (!$node->isProbablyVisible()) { |
664 | 664 | $this->logger->debug(sprintf('[Get Nodes] Removing hidden node... Match string was: \'%s\'', $matchString)); |
@@ -1049,7 +1049,7 @@ discard block |
||
1049 | 1049 | while ($parentOfTopCandidate->nodeName !== 'body' && $parentOfTopCandidate->nodeType === XML_ELEMENT_NODE) { |
1050 | 1050 | $listsContainingThisAncestor = 0; |
1051 | 1051 | for ($ancestorIndex = 0; $ancestorIndex < count($alternativeCandidateAncestors) && $listsContainingThisAncestor < $MINIMUM_TOPCANDIDATES; $ancestorIndex++) { |
1052 | - $listsContainingThisAncestor += (int)in_array($parentOfTopCandidate, $alternativeCandidateAncestors[$ancestorIndex]); |
|
1052 | + $listsContainingThisAncestor += (int) in_array($parentOfTopCandidate, $alternativeCandidateAncestors[$ancestorIndex]); |
|
1053 | 1053 | } |
1054 | 1054 | if ($listsContainingThisAncestor >= $MINIMUM_TOPCANDIDATES) { |
1055 | 1055 | $topCandidate = $parentOfTopCandidate; |
@@ -1285,7 +1285,7 @@ discard block |
||
1285 | 1285 | $row = $tbody->getFirstElementChild(); |
1286 | 1286 | if ($row->hasSingleTagInsideElement('td')) { |
1287 | 1287 | $cell = $row->getFirstElementChild(); |
1288 | - $cell = NodeUtility::setNodeTag($cell, (array_reduce(iterator_to_array($cell->childNodes), function ($carry, $node) { |
|
1288 | + $cell = NodeUtility::setNodeTag($cell, (array_reduce(iterator_to_array($cell->childNodes), function($carry, $node) { |
|
1289 | 1289 | return $node->isPhrasingContent() && $carry; |
1290 | 1290 | }, true)) ? 'p' : 'div'); |
1291 | 1291 | $table->parentNode->replaceChild($cell, $table); |
@@ -1465,7 +1465,7 @@ discard block |
||
1465 | 1465 | $node = $DOMNodeList->item($length - 1 - $i); |
1466 | 1466 | |
1467 | 1467 | // First check if we're in a data table, in which case don't remove us. |
1468 | - if ($node->hasAncestorTag('table', -1, function ($node) { |
|
1468 | + if ($node->hasAncestorTag('table', -1, function($node) { |
|
1469 | 1469 | return $node->isReadabilityDataTable(); |
1470 | 1470 | })) { |
1471 | 1471 | continue; |
@@ -1577,7 +1577,7 @@ discard block |
||
1577 | 1577 | public function _cleanHeaders(DOMDocument $article) |
1578 | 1578 | { |
1579 | 1579 | for ($headerIndex = 1; $headerIndex < 3; $headerIndex++) { |
1580 | - $headers = $article->getElementsByTagName('h' . $headerIndex); |
|
1580 | + $headers = $article->getElementsByTagName('h'.$headerIndex); |
|
1581 | 1581 | /** @var $header DOMElement */ |
1582 | 1582 | foreach ($headers as $header) { |
1583 | 1583 | $weight = 0; |
@@ -54,7 +54,7 @@ |
||
54 | 54 | while ($line = $sth->fetch()) { |
55 | 55 | |
56 | 56 | if (!$subject) { |
57 | - $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]); |
|
57 | + $subject = __("[Forwarded]")." ".htmlspecialchars($line["title"]); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"])); |
@@ -536,32 +536,32 @@ discard block |
||
536 | 536 | ///////////////////////////////////////////////////////////////////////////// |
537 | 537 | |
538 | 538 | /// enter mbstring workaround mode |
539 | - public function _MBPush () |
|
539 | + public function _MBPush() |
|
540 | 540 | { |
541 | 541 | $this->_mbenc = ""; |
542 | - if ( ini_get ( "mbstring.func_overload" ) & 2 ) |
|
542 | + if (ini_get("mbstring.func_overload") & 2) |
|
543 | 543 | { |
544 | 544 | $this->_mbenc = mb_internal_encoding(); |
545 | - mb_internal_encoding ( "latin1" ); |
|
545 | + mb_internal_encoding("latin1"); |
|
546 | 546 | } |
547 | 547 | } |
548 | 548 | |
549 | 549 | /// leave mbstring workaround mode |
550 | - public function _MBPop () |
|
550 | + public function _MBPop() |
|
551 | 551 | { |
552 | - if ( $this->_mbenc ) { |
|
553 | - mb_internal_encoding ( $this->_mbenc ); |
|
552 | + if ($this->_mbenc) { |
|
553 | + mb_internal_encoding($this->_mbenc); |
|
554 | 554 | } |
555 | 555 | } |
556 | 556 | |
557 | 557 | /// connect to searchd server |
558 | - public function _Connect () |
|
558 | + public function _Connect() |
|
559 | 559 | { |
560 | - if ( $this->_socket!==false ) |
|
560 | + if ($this->_socket !== false) |
|
561 | 561 | { |
562 | 562 | // we are in persistent connection mode, so we have a socket |
563 | 563 | // however, need to check whether it's still alive |
564 | - if ( !@feof ( $this->_socket ) ) { |
|
564 | + if (!@feof($this->_socket)) { |
|
565 | 565 | return $this->_socket; |
566 | 566 | } |
567 | 567 | |
@@ -878,92 +878,92 @@ discard block |
||
878 | 878 | } |
879 | 879 | |
880 | 880 | /// set count-distinct attribute for group-by queries |
881 | - public function SetGroupDistinct ( $attribute ) |
|
881 | + public function SetGroupDistinct($attribute) |
|
882 | 882 | { |
883 | - assert ( is_string($attribute) ); |
|
883 | + assert(is_string($attribute)); |
|
884 | 884 | $this->_groupdistinct = $attribute; |
885 | 885 | } |
886 | 886 | |
887 | 887 | /// set distributed retries count and delay |
888 | - public function SetRetries ( $count, $delay=0 ) |
|
888 | + public function SetRetries($count, $delay = 0) |
|
889 | 889 | { |
890 | - assert ( is_int($count) && $count>=0 ); |
|
891 | - assert ( is_int($delay) && $delay>=0 ); |
|
890 | + assert(is_int($count) && $count >= 0); |
|
891 | + assert(is_int($delay) && $delay >= 0); |
|
892 | 892 | $this->_retrycount = $count; |
893 | 893 | $this->_retrydelay = $delay; |
894 | 894 | } |
895 | 895 | |
896 | 896 | /// set result set format (hash or array; hash by default) |
897 | 897 | /// PHP specific; needed for group-by-MVA result sets that may contain duplicate IDs |
898 | - public function SetArrayResult ( $arrayresult ) |
|
898 | + public function SetArrayResult($arrayresult) |
|
899 | 899 | { |
900 | - assert ( is_bool($arrayresult) ); |
|
900 | + assert(is_bool($arrayresult)); |
|
901 | 901 | $this->_arrayresult = $arrayresult; |
902 | 902 | } |
903 | 903 | |
904 | 904 | /// set attribute values override |
905 | 905 | /// there can be only one override per attribute |
906 | 906 | /// $values must be a hash that maps document IDs to attribute values |
907 | - public function SetOverride ( $attrname, $attrtype, $values ) |
|
907 | + public function SetOverride($attrname, $attrtype, $values) |
|
908 | 908 | { |
909 | - assert ( is_string ( $attrname ) ); |
|
910 | - assert ( in_array ( $attrtype, array ( SPH_ATTR_INTEGER, SPH_ATTR_TIMESTAMP, SPH_ATTR_BOOL, SPH_ATTR_FLOAT, SPH_ATTR_BIGINT ) ) ); |
|
911 | - assert ( is_array ( $values ) ); |
|
909 | + assert(is_string($attrname)); |
|
910 | + assert(in_array($attrtype, array(SPH_ATTR_INTEGER, SPH_ATTR_TIMESTAMP, SPH_ATTR_BOOL, SPH_ATTR_FLOAT, SPH_ATTR_BIGINT))); |
|
911 | + assert(is_array($values)); |
|
912 | 912 | |
913 | - $this->_overrides[$attrname] = array ( "attr"=>$attrname, "type"=>$attrtype, "values"=>$values ); |
|
913 | + $this->_overrides[$attrname] = array("attr"=>$attrname, "type"=>$attrtype, "values"=>$values); |
|
914 | 914 | } |
915 | 915 | |
916 | 916 | /// set select-list (attributes or expressions), SQL-like syntax |
917 | - public function SetSelect ( $select ) |
|
917 | + public function SetSelect($select) |
|
918 | 918 | { |
919 | - assert ( is_string ( $select ) ); |
|
919 | + assert(is_string($select)); |
|
920 | 920 | $this->_select = $select; |
921 | 921 | } |
922 | 922 | |
923 | 923 | ////////////////////////////////////////////////////////////////////////////// |
924 | 924 | |
925 | 925 | /// clear all filters (for multi-queries) |
926 | - public function ResetFilters () |
|
926 | + public function ResetFilters() |
|
927 | 927 | { |
928 | 928 | $this->_filters = array(); |
929 | 929 | $this->_anchor = array(); |
930 | 930 | } |
931 | 931 | |
932 | 932 | /// clear groupby settings (for multi-queries) |
933 | - public function ResetGroupBy () |
|
933 | + public function ResetGroupBy() |
|
934 | 934 | { |
935 | - $this->_groupby = ""; |
|
935 | + $this->_groupby = ""; |
|
936 | 936 | $this->_groupfunc = SPH_GROUPBY_DAY; |
937 | 937 | $this->_groupsort = "@group desc"; |
938 | - $this->_groupdistinct= ""; |
|
938 | + $this->_groupdistinct = ""; |
|
939 | 939 | } |
940 | 940 | |
941 | 941 | /// clear all attribute value overrides (for multi-queries) |
942 | - public function ResetOverrides () |
|
942 | + public function ResetOverrides() |
|
943 | 943 | { |
944 | - $this->_overrides = array (); |
|
944 | + $this->_overrides = array(); |
|
945 | 945 | } |
946 | 946 | |
947 | 947 | ////////////////////////////////////////////////////////////////////////////// |
948 | 948 | |
949 | 949 | /// connect to searchd server, run given search query through given indexes, |
950 | 950 | /// and return the search results |
951 | - public function Query ( $query, $index="*", $comment="" ) |
|
951 | + public function Query($query, $index = "*", $comment = "") |
|
952 | 952 | { |
953 | - assert ( empty($this->_reqs) ); |
|
953 | + assert(empty($this->_reqs)); |
|
954 | 954 | |
955 | - $this->AddQuery ( $query, $index, $comment ); |
|
956 | - $results = $this->RunQueries (); |
|
957 | - $this->_reqs = array (); // just in case it failed too early |
|
955 | + $this->AddQuery($query, $index, $comment); |
|
956 | + $results = $this->RunQueries(); |
|
957 | + $this->_reqs = array(); // just in case it failed too early |
|
958 | 958 | |
959 | - if ( !is_array($results) ) { |
|
959 | + if (!is_array($results)) { |
|
960 | 960 | return false; |
961 | 961 | } |
962 | 962 | // probably network error; error message should be already filled |
963 | 963 | |
964 | 964 | $this->_error = $results[0]["error"]; |
965 | 965 | $this->_warning = $results[0]["warning"]; |
966 | - if ( $results[0]["status"]==SEARCHD_ERROR ) { |
|
966 | + if ($results[0]["status"] == SEARCHD_ERROR) { |
|
967 | 967 | return false; |
968 | 968 | } else { |
969 | 969 | return $results[0]; |
@@ -971,11 +971,11 @@ discard block |
||
971 | 971 | } |
972 | 972 | |
973 | 973 | /// helper to pack floats in network byte order |
974 | - public function _PackFloat ( $f ) |
|
974 | + public function _PackFloat($f) |
|
975 | 975 | { |
976 | - $t1 = pack ( "f", $f ); // machine order |
|
977 | - list(,$t2) = unpack ( "L*", $t1 ); // int in machine order |
|
978 | - return pack ( "N", $t2 ); |
|
976 | + $t1 = pack("f", $f); // machine order |
|
977 | + list(,$t2) = unpack("L*", $t1); // int in machine order |
|
978 | + return pack("N", $t2); |
|
979 | 979 | } |
980 | 980 | |
981 | 981 | /** |
@@ -984,183 +984,183 @@ discard block |
||
984 | 984 | |
985 | 985 | /// add query to multi-query batch |
986 | 986 | /// returns index into results array from RunQueries() call |
987 | - public function AddQuery ( $query, $index="*", $comment="" ) |
|
987 | + public function AddQuery($query, $index = "*", $comment = "") |
|
988 | 988 | { |
989 | 989 | // mbstring workaround |
990 | - $this->_MBPush (); |
|
990 | + $this->_MBPush(); |
|
991 | 991 | |
992 | 992 | // build request |
993 | - $req = pack ( "NNNNN", $this->_offset, $this->_limit, $this->_mode, $this->_ranker, $this->_sort ); // mode and limits |
|
994 | - $req .= pack ( "N", strlen($this->_sortby) ) . $this->_sortby; |
|
995 | - $req .= pack ( "N", strlen($query) ) . $query; // query itself |
|
996 | - $req .= pack ( "N", count($this->_weights) ); // weights |
|
997 | - foreach ( $this->_weights as $weight ) { |
|
998 | - $req .= pack ( "N", (int)$weight ); |
|
993 | + $req = pack("NNNNN", $this->_offset, $this->_limit, $this->_mode, $this->_ranker, $this->_sort); // mode and limits |
|
994 | + $req .= pack("N", strlen($this->_sortby)).$this->_sortby; |
|
995 | + $req .= pack("N", strlen($query)).$query; // query itself |
|
996 | + $req .= pack("N", count($this->_weights)); // weights |
|
997 | + foreach ($this->_weights as $weight) { |
|
998 | + $req .= pack("N", (int) $weight); |
|
999 | 999 | } |
1000 | - $req .= pack ( "N", strlen($index) ) . $index; // indexes |
|
1001 | - $req .= pack ( "N", 1 ); // id64 range marker |
|
1002 | - $req .= sphPackU64 ( $this->_min_id ) . sphPackU64 ( $this->_max_id ); // id64 range |
|
1000 | + $req .= pack("N", strlen($index)).$index; // indexes |
|
1001 | + $req .= pack("N", 1); // id64 range marker |
|
1002 | + $req .= sphPackU64($this->_min_id).sphPackU64($this->_max_id); // id64 range |
|
1003 | 1003 | |
1004 | 1004 | // filters |
1005 | - $req .= pack ( "N", count($this->_filters) ); |
|
1006 | - foreach ( $this->_filters as $filter ) |
|
1005 | + $req .= pack("N", count($this->_filters)); |
|
1006 | + foreach ($this->_filters as $filter) |
|
1007 | 1007 | { |
1008 | - $req .= pack ( "N", strlen($filter["attr"]) ) . $filter["attr"]; |
|
1009 | - $req .= pack ( "N", $filter["type"] ); |
|
1010 | - switch ( $filter["type"] ) |
|
1008 | + $req .= pack("N", strlen($filter["attr"])).$filter["attr"]; |
|
1009 | + $req .= pack("N", $filter["type"]); |
|
1010 | + switch ($filter["type"]) |
|
1011 | 1011 | { |
1012 | 1012 | case SPH_FILTER_VALUES: |
1013 | - $req .= pack ( "N", count($filter["values"]) ); |
|
1014 | - foreach ( $filter["values"] as $value ) |
|
1015 | - $req .= sphPackI64 ( $value ); |
|
1013 | + $req .= pack("N", count($filter["values"])); |
|
1014 | + foreach ($filter["values"] as $value) |
|
1015 | + $req .= sphPackI64($value); |
|
1016 | 1016 | break; |
1017 | 1017 | |
1018 | 1018 | case SPH_FILTER_RANGE: |
1019 | - $req .= sphPackI64 ( $filter["min"] ) . sphPackI64 ( $filter["max"] ); |
|
1019 | + $req .= sphPackI64($filter["min"]).sphPackI64($filter["max"]); |
|
1020 | 1020 | break; |
1021 | 1021 | |
1022 | 1022 | case SPH_FILTER_FLOATRANGE: |
1023 | - $req .= $this->_PackFloat ( $filter["min"] ) . $this->_PackFloat ( $filter["max"] ); |
|
1023 | + $req .= $this->_PackFloat($filter["min"]).$this->_PackFloat($filter["max"]); |
|
1024 | 1024 | break; |
1025 | 1025 | |
1026 | 1026 | default: |
1027 | - assert ( 0 && "internal error: unhandled filter type" ); |
|
1027 | + assert(0 && "internal error: unhandled filter type"); |
|
1028 | 1028 | } |
1029 | - $req .= pack ( "N", $filter["exclude"] ); |
|
1029 | + $req .= pack("N", $filter["exclude"]); |
|
1030 | 1030 | } |
1031 | 1031 | |
1032 | 1032 | // group-by clause, max-matches count, group-sort clause, cutoff count |
1033 | - $req .= pack ( "NN", $this->_groupfunc, strlen($this->_groupby) ) . $this->_groupby; |
|
1034 | - $req .= pack ( "N", $this->_maxmatches ); |
|
1035 | - $req .= pack ( "N", strlen($this->_groupsort) ) . $this->_groupsort; |
|
1036 | - $req .= pack ( "NNN", $this->_cutoff, $this->_retrycount, $this->_retrydelay ); |
|
1037 | - $req .= pack ( "N", strlen($this->_groupdistinct) ) . $this->_groupdistinct; |
|
1033 | + $req .= pack("NN", $this->_groupfunc, strlen($this->_groupby)).$this->_groupby; |
|
1034 | + $req .= pack("N", $this->_maxmatches); |
|
1035 | + $req .= pack("N", strlen($this->_groupsort)).$this->_groupsort; |
|
1036 | + $req .= pack("NNN", $this->_cutoff, $this->_retrycount, $this->_retrydelay); |
|
1037 | + $req .= pack("N", strlen($this->_groupdistinct)).$this->_groupdistinct; |
|
1038 | 1038 | |
1039 | 1039 | // anchor point |
1040 | - if ( empty($this->_anchor) ) |
|
1040 | + if (empty($this->_anchor)) |
|
1041 | 1041 | { |
1042 | - $req .= pack ( "N", 0 ); |
|
1042 | + $req .= pack("N", 0); |
|
1043 | 1043 | } else |
1044 | 1044 | { |
1045 | - $a =& $this->_anchor; |
|
1046 | - $req .= pack ( "N", 1 ); |
|
1047 | - $req .= pack ( "N", strlen($a["attrlat"]) ) . $a["attrlat"]; |
|
1048 | - $req .= pack ( "N", strlen($a["attrlong"]) ) . $a["attrlong"]; |
|
1049 | - $req .= $this->_PackFloat ( $a["lat"] ) . $this->_PackFloat ( $a["long"] ); |
|
1045 | + $a = & $this->_anchor; |
|
1046 | + $req .= pack("N", 1); |
|
1047 | + $req .= pack("N", strlen($a["attrlat"])).$a["attrlat"]; |
|
1048 | + $req .= pack("N", strlen($a["attrlong"])).$a["attrlong"]; |
|
1049 | + $req .= $this->_PackFloat($a["lat"]).$this->_PackFloat($a["long"]); |
|
1050 | 1050 | } |
1051 | 1051 | |
1052 | 1052 | // per-index weights |
1053 | - $req .= pack ( "N", count($this->_indexweights) ); |
|
1054 | - foreach ( $this->_indexweights as $idx=>$weight ) { |
|
1055 | - $req .= pack ( "N", strlen($idx) ) . $idx . pack ( "N", $weight ); |
|
1053 | + $req .= pack("N", count($this->_indexweights)); |
|
1054 | + foreach ($this->_indexweights as $idx=>$weight) { |
|
1055 | + $req .= pack("N", strlen($idx)).$idx.pack("N", $weight); |
|
1056 | 1056 | } |
1057 | 1057 | |
1058 | 1058 | // max query time |
1059 | - $req .= pack ( "N", $this->_maxquerytime ); |
|
1059 | + $req .= pack("N", $this->_maxquerytime); |
|
1060 | 1060 | |
1061 | 1061 | // per-field weights |
1062 | - $req .= pack ( "N", count($this->_fieldweights) ); |
|
1063 | - foreach ( $this->_fieldweights as $field=>$weight ) { |
|
1064 | - $req .= pack ( "N", strlen($field) ) . $field . pack ( "N", $weight ); |
|
1062 | + $req .= pack("N", count($this->_fieldweights)); |
|
1063 | + foreach ($this->_fieldweights as $field=>$weight) { |
|
1064 | + $req .= pack("N", strlen($field)).$field.pack("N", $weight); |
|
1065 | 1065 | } |
1066 | 1066 | |
1067 | 1067 | // comment |
1068 | - $req .= pack ( "N", strlen($comment) ) . $comment; |
|
1068 | + $req .= pack("N", strlen($comment)).$comment; |
|
1069 | 1069 | |
1070 | 1070 | // attribute overrides |
1071 | - $req .= pack ( "N", count($this->_overrides) ); |
|
1072 | - foreach ( $this->_overrides as $key => $entry ) |
|
1071 | + $req .= pack("N", count($this->_overrides)); |
|
1072 | + foreach ($this->_overrides as $key => $entry) |
|
1073 | 1073 | { |
1074 | - $req .= pack ( "N", strlen($entry["attr"]) ) . $entry["attr"]; |
|
1075 | - $req .= pack ( "NN", $entry["type"], count($entry["values"]) ); |
|
1076 | - foreach ( $entry["values"] as $id=>$val ) |
|
1074 | + $req .= pack("N", strlen($entry["attr"])).$entry["attr"]; |
|
1075 | + $req .= pack("NN", $entry["type"], count($entry["values"])); |
|
1076 | + foreach ($entry["values"] as $id=>$val) |
|
1077 | 1077 | { |
1078 | - assert ( is_numeric($id) ); |
|
1079 | - assert ( is_numeric($val) ); |
|
1078 | + assert(is_numeric($id)); |
|
1079 | + assert(is_numeric($val)); |
|
1080 | 1080 | |
1081 | - $req .= sphPackU64 ( $id ); |
|
1082 | - switch ( $entry["type"] ) |
|
1081 | + $req .= sphPackU64($id); |
|
1082 | + switch ($entry["type"]) |
|
1083 | 1083 | { |
1084 | - case SPH_ATTR_FLOAT: $req .= $this->_PackFloat ( $val ); break; |
|
1085 | - case SPH_ATTR_BIGINT: $req .= sphPackI64 ( $val ); break; |
|
1086 | - default: $req .= pack ( "N", $val ); break; |
|
1084 | + case SPH_ATTR_FLOAT: $req .= $this->_PackFloat($val); break; |
|
1085 | + case SPH_ATTR_BIGINT: $req .= sphPackI64($val); break; |
|
1086 | + default: $req .= pack("N", $val); break; |
|
1087 | 1087 | } |
1088 | 1088 | } |
1089 | 1089 | } |
1090 | 1090 | |
1091 | 1091 | // select-list |
1092 | - $req .= pack ( "N", strlen($this->_select) ) . $this->_select; |
|
1092 | + $req .= pack("N", strlen($this->_select)).$this->_select; |
|
1093 | 1093 | |
1094 | 1094 | // mbstring workaround |
1095 | - $this->_MBPop (); |
|
1095 | + $this->_MBPop(); |
|
1096 | 1096 | |
1097 | 1097 | // store request to requests array |
1098 | 1098 | $this->_reqs[] = $req; |
1099 | - return count($this->_reqs)-1; |
|
1099 | + return count($this->_reqs) - 1; |
|
1100 | 1100 | } |
1101 | 1101 | |
1102 | 1102 | /// connect to searchd, run queries batch, and return an array of result sets |
1103 | - public function RunQueries () |
|
1103 | + public function RunQueries() |
|
1104 | 1104 | { |
1105 | - if ( empty($this->_reqs) ) |
|
1105 | + if (empty($this->_reqs)) |
|
1106 | 1106 | { |
1107 | 1107 | $this->_error = "no queries defined, issue AddQuery() first"; |
1108 | 1108 | return false; |
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | // mbstring workaround |
1112 | - $this->_MBPush (); |
|
1112 | + $this->_MBPush(); |
|
1113 | 1113 | |
1114 | - if (!( $fp = $this->_Connect() )) |
|
1114 | + if (!($fp = $this->_Connect())) |
|
1115 | 1115 | { |
1116 | - $this->_MBPop (); |
|
1116 | + $this->_MBPop(); |
|
1117 | 1117 | return false; |
1118 | 1118 | } |
1119 | 1119 | |
1120 | 1120 | // send query, get response |
1121 | 1121 | $nreqs = count($this->_reqs); |
1122 | - $req = join ( "", $this->_reqs ); |
|
1123 | - $len = 8+strlen($req); |
|
1124 | - $req = pack ( "nnNNN", SEARCHD_COMMAND_SEARCH, VER_COMMAND_SEARCH, $len, 0, $nreqs ) . $req; // add header |
|
1122 | + $req = join("", $this->_reqs); |
|
1123 | + $len = 8 + strlen($req); |
|
1124 | + $req = pack("nnNNN", SEARCHD_COMMAND_SEARCH, VER_COMMAND_SEARCH, $len, 0, $nreqs).$req; // add header |
|
1125 | 1125 | |
1126 | - if ( !( $this->_Send ( $fp, $req, $len+8 ) ) || |
|
1127 | - !( $response = $this->_GetResponse ( $fp, VER_COMMAND_SEARCH ) ) ) |
|
1126 | + if (!($this->_Send($fp, $req, $len + 8)) || |
|
1127 | + !($response = $this->_GetResponse($fp, VER_COMMAND_SEARCH))) |
|
1128 | 1128 | { |
1129 | - $this->_MBPop (); |
|
1129 | + $this->_MBPop(); |
|
1130 | 1130 | return false; |
1131 | 1131 | } |
1132 | 1132 | |
1133 | 1133 | // query sent ok; we can reset reqs now |
1134 | - $this->_reqs = array (); |
|
1134 | + $this->_reqs = array(); |
|
1135 | 1135 | |
1136 | 1136 | // parse and return response |
1137 | - return $this->_ParseSearchResponse ( $response, $nreqs ); |
|
1137 | + return $this->_ParseSearchResponse($response, $nreqs); |
|
1138 | 1138 | } |
1139 | 1139 | |
1140 | 1140 | /// parse and return search query (or queries) response |
1141 | - public function _ParseSearchResponse ( $response, $nreqs ) |
|
1141 | + public function _ParseSearchResponse($response, $nreqs) |
|
1142 | 1142 | { |
1143 | 1143 | $p = 0; // current position |
1144 | 1144 | $max = strlen($response); // max position for checks, to protect against broken responses |
1145 | 1145 | |
1146 | - $results = array (); |
|
1147 | - for ( $ires=0; $ires<$nreqs && $p<$max; $ires++ ) |
|
1146 | + $results = array(); |
|
1147 | + for ($ires = 0; $ires < $nreqs && $p < $max; $ires++) |
|
1148 | 1148 | { |
1149 | 1149 | $results[] = array(); |
1150 | - $result =& $results[$ires]; |
|
1150 | + $result = & $results[$ires]; |
|
1151 | 1151 | |
1152 | 1152 | $result["error"] = ""; |
1153 | 1153 | $result["warning"] = ""; |
1154 | 1154 | |
1155 | 1155 | // extract status |
1156 | - list(,$status) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
1156 | + list(,$status) = unpack("N*", substr($response, $p, 4)); $p += 4; |
|
1157 | 1157 | $result["status"] = $status; |
1158 | - if ( $status!=SEARCHD_OK ) |
|
1158 | + if ($status != SEARCHD_OK) |
|
1159 | 1159 | { |
1160 | - list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; |
|
1161 | - $message = substr ( $response, $p, $len ); $p += $len; |
|
1160 | + list(,$len) = unpack("N*", substr($response, $p, 4)); $p += 4; |
|
1161 | + $message = substr($response, $p, $len); $p += $len; |
|
1162 | 1162 | |
1163 | - if ( $status==SEARCHD_WARNING ) |
|
1163 | + if ($status == SEARCHD_WARNING) |
|
1164 | 1164 | { |
1165 | 1165 | $result["warning"] = $message; |
1166 | 1166 | } else |