@@ -5,8 +5,9 @@ discard block |
||
5 | 5 | $namespace = ''; |
6 | 6 | $class_name = $class; |
7 | 7 | |
8 | - if (strpos($class, '\\') !== FALSE) |
|
9 | - list ($namespace, $class_name) = explode('\\', $class, 2); |
|
8 | + if (strpos($class, '\\') !== FALSE) { |
|
9 | + list ($namespace, $class_name) = explode('\\', $class, 2); |
|
10 | + } |
|
10 | 11 | |
11 | 12 | $root_dir = dirname(__DIR__); // we're in tt-rss/include |
12 | 13 | |
@@ -20,7 +21,8 @@ discard block |
||
20 | 21 | $class_file = "$root_dir/classes/" . str_replace("_", "/", strtolower($class)) . ".php"; |
21 | 22 | } |
22 | 23 | |
23 | - if (file_exists($class_file)) |
|
24 | - include $class_file; |
|
24 | + if (file_exists($class_file)) { |
|
25 | + include $class_file; |
|
26 | + } |
|
25 | 27 | |
26 | 28 | }); |
@@ -1,26 +1,26 @@ |
||
1 | 1 | <?php |
2 | - require_once "functions.php"; |
|
2 | + require_once "functions.php"; |
|
3 | 3 | |
4 | - spl_autoload_register(function($class) { |
|
5 | - $namespace = ''; |
|
6 | - $class_name = $class; |
|
4 | + spl_autoload_register(function($class) { |
|
5 | + $namespace = ''; |
|
6 | + $class_name = $class; |
|
7 | 7 | |
8 | - if (strpos($class, '\\') !== FALSE) |
|
9 | - list ($namespace, $class_name) = explode('\\', $class, 2); |
|
8 | + if (strpos($class, '\\') !== FALSE) |
|
9 | + list ($namespace, $class_name) = explode('\\', $class, 2); |
|
10 | 10 | |
11 | - $root_dir = dirname(__DIR__); // we're in tt-rss/include |
|
11 | + $root_dir = dirname(__DIR__); // we're in tt-rss/include |
|
12 | 12 | |
13 | - // 1. third party libraries with namespaces are loaded from vendor/ |
|
14 | - // 2. internal tt-rss classes are loaded from classes/ and use special naming logic instead of namespaces |
|
15 | - // 3. plugin classes are loaded by PluginHandler from plugins.local/ and plugins/ (TODO: use generic autoloader?) |
|
13 | + // 1. third party libraries with namespaces are loaded from vendor/ |
|
14 | + // 2. internal tt-rss classes are loaded from classes/ and use special naming logic instead of namespaces |
|
15 | + // 3. plugin classes are loaded by PluginHandler from plugins.local/ and plugins/ (TODO: use generic autoloader?) |
|
16 | 16 | |
17 | - if ($namespace && $class_name) { |
|
18 | - $class_file = "$root_dir/vendor/$namespace/" . str_replace('\\', '/', $class_name) . ".php"; |
|
19 | - } else { |
|
20 | - $class_file = "$root_dir/classes/" . str_replace("_", "/", strtolower($class)) . ".php"; |
|
21 | - } |
|
17 | + if ($namespace && $class_name) { |
|
18 | + $class_file = "$root_dir/vendor/$namespace/" . str_replace('\\', '/', $class_name) . ".php"; |
|
19 | + } else { |
|
20 | + $class_file = "$root_dir/classes/" . str_replace("_", "/", strtolower($class)) . ".php"; |
|
21 | + } |
|
22 | 22 | |
23 | - if (file_exists($class_file)) |
|
24 | - include $class_file; |
|
23 | + if (file_exists($class_file)) |
|
24 | + include $class_file; |
|
25 | 25 | |
26 | - }); |
|
26 | + }); |
@@ -86,15 +86,17 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | public static function instance() { |
89 | - if (self::$instance == null) |
|
90 | - self::$instance = new self(); |
|
89 | + if (self::$instance == null) { |
|
90 | + self::$instance = new self(); |
|
91 | + } |
|
91 | 92 | |
92 | 93 | return self::$instance; |
93 | 94 | } |
94 | 95 | |
95 | 96 | public static function get() { |
96 | - if (self::$instance == null) |
|
97 | - self::$instance = new self(); |
|
97 | + if (self::$instance == null) { |
|
98 | + self::$instance = new self(); |
|
99 | + } |
|
98 | 100 | |
99 | 101 | if (!self::$instance->adapter) { |
100 | 102 | self::$instance->legacy_connect(); |
@@ -104,8 +106,9 @@ discard block |
||
104 | 106 | } |
105 | 107 | |
106 | 108 | public static function pdo() { |
107 | - if (self::$instance == null) |
|
108 | - self::$instance = new self(); |
|
109 | + if (self::$instance == null) { |
|
110 | + self::$instance = new self(); |
|
111 | + } |
|
109 | 112 | |
110 | 113 | if (!self::$instance->pdo) { |
111 | 114 | self::$instance->pdo = self::$instance->pdo_connect(); |
@@ -2,115 +2,115 @@ |
||
2 | 2 | class Db |
3 | 3 | { |
4 | 4 | |
5 | - /* @var Db $instance */ |
|
6 | - private static $instance; |
|
5 | + /* @var Db $instance */ |
|
6 | + private static $instance; |
|
7 | 7 | |
8 | - /* @var IDb $adapter */ |
|
9 | - private $adapter; |
|
8 | + /* @var IDb $adapter */ |
|
9 | + private $adapter; |
|
10 | 10 | |
11 | - private $link; |
|
11 | + private $link; |
|
12 | 12 | |
13 | - /* @var PDO $pdo */ |
|
14 | - private $pdo; |
|
13 | + /* @var PDO $pdo */ |
|
14 | + private $pdo; |
|
15 | 15 | |
16 | - private function __clone() { |
|
17 | - // |
|
18 | - } |
|
16 | + private function __clone() { |
|
17 | + // |
|
18 | + } |
|
19 | 19 | |
20 | - private function legacy_connect() { |
|
20 | + private function legacy_connect() { |
|
21 | 21 | |
22 | - user_error("Legacy connect requested to " . DB_TYPE, E_USER_NOTICE); |
|
22 | + user_error("Legacy connect requested to " . DB_TYPE, E_USER_NOTICE); |
|
23 | 23 | |
24 | - $er = error_reporting(E_ALL); |
|
24 | + $er = error_reporting(E_ALL); |
|
25 | 25 | |
26 | - switch (DB_TYPE) { |
|
27 | - case "mysql": |
|
28 | - $this->adapter = new Db_Mysqli(); |
|
29 | - break; |
|
30 | - case "pgsql": |
|
31 | - $this->adapter = new Db_Pgsql(); |
|
32 | - break; |
|
33 | - default: |
|
34 | - die("Unknown DB_TYPE: " . DB_TYPE); |
|
35 | - } |
|
26 | + switch (DB_TYPE) { |
|
27 | + case "mysql": |
|
28 | + $this->adapter = new Db_Mysqli(); |
|
29 | + break; |
|
30 | + case "pgsql": |
|
31 | + $this->adapter = new Db_Pgsql(); |
|
32 | + break; |
|
33 | + default: |
|
34 | + die("Unknown DB_TYPE: " . DB_TYPE); |
|
35 | + } |
|
36 | 36 | |
37 | - if (!$this->adapter) { |
|
38 | - print("Error initializing database adapter for " . DB_TYPE); |
|
39 | - exit(100); |
|
40 | - } |
|
37 | + if (!$this->adapter) { |
|
38 | + print("Error initializing database adapter for " . DB_TYPE); |
|
39 | + exit(100); |
|
40 | + } |
|
41 | 41 | |
42 | - $this->link = $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, defined('DB_PORT') ? DB_PORT : ""); |
|
42 | + $this->link = $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, defined('DB_PORT') ? DB_PORT : ""); |
|
43 | 43 | |
44 | - if (!$this->link) { |
|
45 | - print("Error connecting through adapter: " . $this->adapter->last_error()); |
|
46 | - exit(101); |
|
47 | - } |
|
44 | + if (!$this->link) { |
|
45 | + print("Error connecting through adapter: " . $this->adapter->last_error()); |
|
46 | + exit(101); |
|
47 | + } |
|
48 | 48 | |
49 | - error_reporting($er); |
|
50 | - } |
|
49 | + error_reporting($er); |
|
50 | + } |
|
51 | 51 | |
52 | - // this really shouldn't be used unless a separate PDO connection is needed |
|
53 | - // normal usage is Db::pdo()->prepare(...) etc |
|
54 | - public function pdo_connect() { |
|
52 | + // this really shouldn't be used unless a separate PDO connection is needed |
|
53 | + // normal usage is Db::pdo()->prepare(...) etc |
|
54 | + public function pdo_connect() { |
|
55 | 55 | |
56 | - $db_port = defined('DB_PORT') && DB_PORT ? ';port=' . DB_PORT : ''; |
|
57 | - $db_host = defined('DB_HOST') && DB_HOST ? ';host=' . DB_HOST : ''; |
|
56 | + $db_port = defined('DB_PORT') && DB_PORT ? ';port=' . DB_PORT : ''; |
|
57 | + $db_host = defined('DB_HOST') && DB_HOST ? ';host=' . DB_HOST : ''; |
|
58 | 58 | |
59 | - try { |
|
60 | - $pdo = new PDO(DB_TYPE . ':dbname=' . DB_NAME . $db_host . $db_port, |
|
61 | - DB_USER, |
|
62 | - DB_PASS); |
|
63 | - } catch (Exception $e) { |
|
64 | - print "<pre>Exception while creating PDO object:" . $e->getMessage() . "</pre>"; |
|
65 | - exit(101); |
|
66 | - } |
|
59 | + try { |
|
60 | + $pdo = new PDO(DB_TYPE . ':dbname=' . DB_NAME . $db_host . $db_port, |
|
61 | + DB_USER, |
|
62 | + DB_PASS); |
|
63 | + } catch (Exception $e) { |
|
64 | + print "<pre>Exception while creating PDO object:" . $e->getMessage() . "</pre>"; |
|
65 | + exit(101); |
|
66 | + } |
|
67 | 67 | |
68 | - $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
68 | + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
69 | 69 | |
70 | - if (DB_TYPE == "pgsql") { |
|
70 | + if (DB_TYPE == "pgsql") { |
|
71 | 71 | |
72 | - $pdo->query("set client_encoding = 'UTF-8'"); |
|
73 | - $pdo->query("set datestyle = 'ISO, european'"); |
|
74 | - $pdo->query("set TIME ZONE 0"); |
|
75 | - $pdo->query("set cpu_tuple_cost = 0.5"); |
|
72 | + $pdo->query("set client_encoding = 'UTF-8'"); |
|
73 | + $pdo->query("set datestyle = 'ISO, european'"); |
|
74 | + $pdo->query("set TIME ZONE 0"); |
|
75 | + $pdo->query("set cpu_tuple_cost = 0.5"); |
|
76 | 76 | |
77 | - } else if (DB_TYPE == "mysql") { |
|
78 | - $pdo->query("SET time_zone = '+0:0'"); |
|
77 | + } else if (DB_TYPE == "mysql") { |
|
78 | + $pdo->query("SET time_zone = '+0:0'"); |
|
79 | 79 | |
80 | - if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { |
|
81 | - $pdo->query("SET NAMES " . MYSQL_CHARSET); |
|
82 | - } |
|
83 | - } |
|
80 | + if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { |
|
81 | + $pdo->query("SET NAMES " . MYSQL_CHARSET); |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - return $pdo; |
|
86 | - } |
|
85 | + return $pdo; |
|
86 | + } |
|
87 | 87 | |
88 | - public static function instance() { |
|
89 | - if (self::$instance == null) |
|
90 | - self::$instance = new self(); |
|
88 | + public static function instance() { |
|
89 | + if (self::$instance == null) |
|
90 | + self::$instance = new self(); |
|
91 | 91 | |
92 | - return self::$instance; |
|
93 | - } |
|
92 | + return self::$instance; |
|
93 | + } |
|
94 | 94 | |
95 | - public static function get() { |
|
96 | - if (self::$instance == null) |
|
97 | - self::$instance = new self(); |
|
95 | + public static function get() { |
|
96 | + if (self::$instance == null) |
|
97 | + self::$instance = new self(); |
|
98 | 98 | |
99 | - if (!self::$instance->adapter) { |
|
100 | - self::$instance->legacy_connect(); |
|
101 | - } |
|
99 | + if (!self::$instance->adapter) { |
|
100 | + self::$instance->legacy_connect(); |
|
101 | + } |
|
102 | 102 | |
103 | - return self::$instance->adapter; |
|
104 | - } |
|
103 | + return self::$instance->adapter; |
|
104 | + } |
|
105 | 105 | |
106 | - public static function pdo() { |
|
107 | - if (self::$instance == null) |
|
108 | - self::$instance = new self(); |
|
106 | + public static function pdo() { |
|
107 | + if (self::$instance == null) |
|
108 | + self::$instance = new self(); |
|
109 | 109 | |
110 | - if (!self::$instance->pdo) { |
|
111 | - self::$instance->pdo = self::$instance->pdo_connect(); |
|
112 | - } |
|
110 | + if (!self::$instance->pdo) { |
|
111 | + self::$instance->pdo = self::$instance->pdo_connect(); |
|
112 | + } |
|
113 | 113 | |
114 | - return self::$instance->pdo; |
|
115 | - } |
|
114 | + return self::$instance->pdo; |
|
115 | + } |
|
116 | 116 | } |
@@ -19,8 +19,9 @@ discard block |
||
19 | 19 | $from_combined = $from_name ? "$from_name <$from_address>" : $from_address; |
20 | 20 | $to_combined = $to_name ? "$to_name <$to_address>" : $to_address; |
21 | 21 | |
22 | - if (defined('_LOG_SENT_MAIL') && _LOG_SENT_MAIL) |
|
23 | - Logger::get()->log("Sending mail from $from_combined to $to_combined [$subject]: $message"); |
|
22 | + if (defined('_LOG_SENT_MAIL') && _LOG_SENT_MAIL) { |
|
23 | + Logger::get()->log("Sending mail from $from_combined to $to_combined [$subject]: $message"); |
|
24 | + } |
|
24 | 25 | |
25 | 26 | // HOOK_SEND_MAIL plugin instructions: |
26 | 27 | // 1. return 1 or true if mail is handled |
@@ -31,11 +32,13 @@ discard block |
||
31 | 32 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEND_MAIL) as $p) { |
32 | 33 | $rc = $p->hook_send_mail($this, $params); |
33 | 34 | |
34 | - if ($rc == 1) |
|
35 | - return $rc; |
|
35 | + if ($rc == 1) { |
|
36 | + return $rc; |
|
37 | + } |
|
36 | 38 | |
37 | - if ($rc == -1) |
|
38 | - return 0; |
|
39 | + if ($rc == -1) { |
|
40 | + return 0; |
|
41 | + } |
|
39 | 42 | } |
40 | 43 | |
41 | 44 | $headers = [ "From: $from_combined", "Content-Type: text/plain; charset=UTF-8" ]; |
@@ -1,52 +1,52 @@ |
||
1 | 1 | <?php |
2 | 2 | class Mailer { |
3 | - // TODO: support HTML mail (i.e. MIME messages) |
|
3 | + // TODO: support HTML mail (i.e. MIME messages) |
|
4 | 4 | |
5 | - private $last_error = "Unable to send mail: check local configuration."; |
|
5 | + private $last_error = "Unable to send mail: check local configuration."; |
|
6 | 6 | |
7 | - public function mail($params) { |
|
7 | + public function mail($params) { |
|
8 | 8 | |
9 | - $to_name = $params["to_name"]; |
|
10 | - $to_address = $params["to_address"]; |
|
11 | - $subject = $params["subject"]; |
|
12 | - $message = $params["message"]; |
|
13 | - $from_name = $params["from_name"] ? $params["from_name"] : SMTP_FROM_NAME; |
|
14 | - $from_address = $params["from_address"] ? $params["from_address"] : SMTP_FROM_ADDRESS; |
|
9 | + $to_name = $params["to_name"]; |
|
10 | + $to_address = $params["to_address"]; |
|
11 | + $subject = $params["subject"]; |
|
12 | + $message = $params["message"]; |
|
13 | + $from_name = $params["from_name"] ? $params["from_name"] : SMTP_FROM_NAME; |
|
14 | + $from_address = $params["from_address"] ? $params["from_address"] : SMTP_FROM_ADDRESS; |
|
15 | 15 | |
16 | - $additional_headers = $params["headers"] ? $params["headers"] : []; |
|
16 | + $additional_headers = $params["headers"] ? $params["headers"] : []; |
|
17 | 17 | |
18 | - $from_combined = $from_name ? "$from_name <$from_address>" : $from_address; |
|
19 | - $to_combined = $to_name ? "$to_name <$to_address>" : $to_address; |
|
18 | + $from_combined = $from_name ? "$from_name <$from_address>" : $from_address; |
|
19 | + $to_combined = $to_name ? "$to_name <$to_address>" : $to_address; |
|
20 | 20 | |
21 | - if (defined('_LOG_SENT_MAIL') && _LOG_SENT_MAIL) |
|
22 | - Logger::get()->log("Sending mail from $from_combined to $to_combined [$subject]: $message"); |
|
21 | + if (defined('_LOG_SENT_MAIL') && _LOG_SENT_MAIL) |
|
22 | + Logger::get()->log("Sending mail from $from_combined to $to_combined [$subject]: $message"); |
|
23 | 23 | |
24 | - // HOOK_SEND_MAIL plugin instructions: |
|
25 | - // 1. return 1 or true if mail is handled |
|
26 | - // 2. return -1 if there's been a fatal error and no further action is allowed |
|
27 | - // 3. any other return value will allow cycling to the next handler and, eventually, to default mail() function |
|
28 | - // 4. set error message if needed via passed Mailer instance function set_error() |
|
24 | + // HOOK_SEND_MAIL plugin instructions: |
|
25 | + // 1. return 1 or true if mail is handled |
|
26 | + // 2. return -1 if there's been a fatal error and no further action is allowed |
|
27 | + // 3. any other return value will allow cycling to the next handler and, eventually, to default mail() function |
|
28 | + // 4. set error message if needed via passed Mailer instance function set_error() |
|
29 | 29 | |
30 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEND_MAIL) as $p) { |
|
31 | - $rc = $p->hook_send_mail($this, $params); |
|
30 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEND_MAIL) as $p) { |
|
31 | + $rc = $p->hook_send_mail($this, $params); |
|
32 | 32 | |
33 | - if ($rc == 1) |
|
34 | - return $rc; |
|
33 | + if ($rc == 1) |
|
34 | + return $rc; |
|
35 | 35 | |
36 | - if ($rc == -1) |
|
37 | - return 0; |
|
38 | - } |
|
36 | + if ($rc == -1) |
|
37 | + return 0; |
|
38 | + } |
|
39 | 39 | |
40 | - $headers = [ "From: $from_combined", "Content-Type: text/plain; charset=UTF-8" ]; |
|
40 | + $headers = [ "From: $from_combined", "Content-Type: text/plain; charset=UTF-8" ]; |
|
41 | 41 | |
42 | - return mail($to_combined, $subject, $message, implode("\r\n", array_merge($headers, $additional_headers))); |
|
43 | - } |
|
42 | + return mail($to_combined, $subject, $message, implode("\r\n", array_merge($headers, $additional_headers))); |
|
43 | + } |
|
44 | 44 | |
45 | - public function set_error($message) { |
|
46 | - $this->last_error = $message; |
|
47 | - } |
|
45 | + public function set_error($message) { |
|
46 | + $this->last_error = $message; |
|
47 | + } |
|
48 | 48 | |
49 | - public function error() { |
|
50 | - return $this->last_error; |
|
51 | - } |
|
49 | + public function error() { |
|
50 | + return $this->last_error; |
|
51 | + } |
|
52 | 52 | } |
@@ -43,10 +43,11 @@ discard block |
||
43 | 43 | || $link->getAttribute("rel") == "standout")) { |
44 | 44 | $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link); |
45 | 45 | |
46 | - if ($base) |
|
47 | - return rewrite_relative_url($base, clean(trim($link->getAttribute("href")))); |
|
48 | - else |
|
49 | - return clean(trim($link->getAttribute("href"))); |
|
46 | + if ($base) { |
|
47 | + return rewrite_relative_url($base, clean(trim($link->getAttribute("href")))); |
|
48 | + } else { |
|
49 | + return clean(trim($link->getAttribute("href"))); |
|
50 | + } |
|
50 | 51 | |
51 | 52 | } |
52 | 53 | } |
@@ -106,8 +107,9 @@ discard block |
||
106 | 107 | $cats = []; |
107 | 108 | |
108 | 109 | foreach ($categories as $cat) { |
109 | - if ($cat->hasAttribute("term")) |
|
110 | - array_push($cats, $cat->getAttribute("term")); |
|
110 | + if ($cat->hasAttribute("term")) { |
|
111 | + array_push($cats, $cat->getAttribute("term")); |
|
112 | + } |
|
111 | 113 | } |
112 | 114 | |
113 | 115 | $categories = $this->xpath->query("dc:subject", $this->elem); |
@@ -1,160 +1,160 @@ |
||
1 | 1 | <?php |
2 | 2 | class FeedItem_Atom extends FeedItem_Common { |
3 | - const NS_XML = "http://www.w3.org/XML/1998/namespace"; |
|
3 | + const NS_XML = "http://www.w3.org/XML/1998/namespace"; |
|
4 | 4 | |
5 | - public function get_id() { |
|
6 | - $id = $this->elem->getElementsByTagName("id")->item(0); |
|
5 | + public function get_id() { |
|
6 | + $id = $this->elem->getElementsByTagName("id")->item(0); |
|
7 | 7 | |
8 | - if ($id) { |
|
9 | - return $id->nodeValue; |
|
10 | - } else { |
|
11 | - return clean($this->get_link()); |
|
12 | - } |
|
13 | - } |
|
8 | + if ($id) { |
|
9 | + return $id->nodeValue; |
|
10 | + } else { |
|
11 | + return clean($this->get_link()); |
|
12 | + } |
|
13 | + } |
|
14 | 14 | |
15 | - public function get_date() { |
|
16 | - $updated = $this->elem->getElementsByTagName("updated")->item(0); |
|
15 | + public function get_date() { |
|
16 | + $updated = $this->elem->getElementsByTagName("updated")->item(0); |
|
17 | 17 | |
18 | - if ($updated) { |
|
19 | - return strtotime($updated->nodeValue); |
|
20 | - } |
|
18 | + if ($updated) { |
|
19 | + return strtotime($updated->nodeValue); |
|
20 | + } |
|
21 | 21 | |
22 | - $published = $this->elem->getElementsByTagName("published")->item(0); |
|
22 | + $published = $this->elem->getElementsByTagName("published")->item(0); |
|
23 | 23 | |
24 | - if ($published) { |
|
25 | - return strtotime($published->nodeValue); |
|
26 | - } |
|
24 | + if ($published) { |
|
25 | + return strtotime($published->nodeValue); |
|
26 | + } |
|
27 | 27 | |
28 | - $date = $this->xpath->query("dc:date", $this->elem)->item(0); |
|
28 | + $date = $this->xpath->query("dc:date", $this->elem)->item(0); |
|
29 | 29 | |
30 | - if ($date) { |
|
31 | - return strtotime($date->nodeValue); |
|
32 | - } |
|
33 | - } |
|
30 | + if ($date) { |
|
31 | + return strtotime($date->nodeValue); |
|
32 | + } |
|
33 | + } |
|
34 | 34 | |
35 | 35 | |
36 | - public function get_link() { |
|
37 | - $links = $this->elem->getElementsByTagName("link"); |
|
36 | + public function get_link() { |
|
37 | + $links = $this->elem->getElementsByTagName("link"); |
|
38 | 38 | |
39 | - foreach ($links as $link) { |
|
40 | - if ($link && $link->hasAttribute("href") && |
|
41 | - (!$link->hasAttribute("rel") |
|
42 | - || $link->getAttribute("rel") == "alternate" |
|
43 | - || $link->getAttribute("rel") == "standout")) { |
|
44 | - $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link); |
|
39 | + foreach ($links as $link) { |
|
40 | + if ($link && $link->hasAttribute("href") && |
|
41 | + (!$link->hasAttribute("rel") |
|
42 | + || $link->getAttribute("rel") == "alternate" |
|
43 | + || $link->getAttribute("rel") == "standout")) { |
|
44 | + $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link); |
|
45 | 45 | |
46 | - if ($base) |
|
47 | - return rewrite_relative_url($base, clean(trim($link->getAttribute("href")))); |
|
48 | - else |
|
49 | - return clean(trim($link->getAttribute("href"))); |
|
46 | + if ($base) |
|
47 | + return rewrite_relative_url($base, clean(trim($link->getAttribute("href")))); |
|
48 | + else |
|
49 | + return clean(trim($link->getAttribute("href"))); |
|
50 | 50 | |
51 | - } |
|
52 | - } |
|
53 | - } |
|
51 | + } |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | - public function get_title() { |
|
56 | - $title = $this->elem->getElementsByTagName("title")->item(0); |
|
55 | + public function get_title() { |
|
56 | + $title = $this->elem->getElementsByTagName("title")->item(0); |
|
57 | 57 | |
58 | - if ($title) { |
|
59 | - return clean(trim($title->nodeValue)); |
|
60 | - } |
|
61 | - } |
|
62 | - |
|
63 | - public function get_content() { |
|
64 | - $content = $this->elem->getElementsByTagName("content")->item(0); |
|
65 | - |
|
66 | - if ($content) { |
|
67 | - if ($content->hasAttribute('type')) { |
|
68 | - if ($content->getAttribute('type') == 'xhtml') { |
|
69 | - for ($i = 0; $i < $content->childNodes->length; $i++) { |
|
70 | - $child = $content->childNodes->item($i); |
|
71 | - |
|
72 | - if ($child->hasChildNodes()) { |
|
73 | - return $this->doc->saveHTML($child); |
|
74 | - } |
|
75 | - } |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - return $this->subtree_or_text($content); |
|
80 | - } |
|
81 | - } |
|
82 | - |
|
83 | - public function get_description() { |
|
84 | - $content = $this->elem->getElementsByTagName("summary")->item(0); |
|
85 | - |
|
86 | - if ($content) { |
|
87 | - if ($content->hasAttribute('type')) { |
|
88 | - if ($content->getAttribute('type') == 'xhtml') { |
|
89 | - for ($i = 0; $i < $content->childNodes->length; $i++) { |
|
90 | - $child = $content->childNodes->item($i); |
|
91 | - |
|
92 | - if ($child->hasChildNodes()) { |
|
93 | - return $this->doc->saveHTML($child); |
|
94 | - } |
|
95 | - } |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - return $this->subtree_or_text($content); |
|
100 | - } |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - public function get_categories() { |
|
105 | - $categories = $this->elem->getElementsByTagName("category"); |
|
106 | - $cats = []; |
|
107 | - |
|
108 | - foreach ($categories as $cat) { |
|
109 | - if ($cat->hasAttribute("term")) |
|
110 | - array_push($cats, $cat->getAttribute("term")); |
|
111 | - } |
|
112 | - |
|
113 | - $categories = $this->xpath->query("dc:subject", $this->elem); |
|
58 | + if ($title) { |
|
59 | + return clean(trim($title->nodeValue)); |
|
60 | + } |
|
61 | + } |
|
62 | + |
|
63 | + public function get_content() { |
|
64 | + $content = $this->elem->getElementsByTagName("content")->item(0); |
|
65 | + |
|
66 | + if ($content) { |
|
67 | + if ($content->hasAttribute('type')) { |
|
68 | + if ($content->getAttribute('type') == 'xhtml') { |
|
69 | + for ($i = 0; $i < $content->childNodes->length; $i++) { |
|
70 | + $child = $content->childNodes->item($i); |
|
71 | + |
|
72 | + if ($child->hasChildNodes()) { |
|
73 | + return $this->doc->saveHTML($child); |
|
74 | + } |
|
75 | + } |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + return $this->subtree_or_text($content); |
|
80 | + } |
|
81 | + } |
|
82 | + |
|
83 | + public function get_description() { |
|
84 | + $content = $this->elem->getElementsByTagName("summary")->item(0); |
|
85 | + |
|
86 | + if ($content) { |
|
87 | + if ($content->hasAttribute('type')) { |
|
88 | + if ($content->getAttribute('type') == 'xhtml') { |
|
89 | + for ($i = 0; $i < $content->childNodes->length; $i++) { |
|
90 | + $child = $content->childNodes->item($i); |
|
91 | + |
|
92 | + if ($child->hasChildNodes()) { |
|
93 | + return $this->doc->saveHTML($child); |
|
94 | + } |
|
95 | + } |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + return $this->subtree_or_text($content); |
|
100 | + } |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + public function get_categories() { |
|
105 | + $categories = $this->elem->getElementsByTagName("category"); |
|
106 | + $cats = []; |
|
107 | + |
|
108 | + foreach ($categories as $cat) { |
|
109 | + if ($cat->hasAttribute("term")) |
|
110 | + array_push($cats, $cat->getAttribute("term")); |
|
111 | + } |
|
112 | + |
|
113 | + $categories = $this->xpath->query("dc:subject", $this->elem); |
|
114 | 114 | |
115 | - foreach ($categories as $cat) { |
|
116 | - array_push($cats, $cat->nodeValue); |
|
117 | - } |
|
118 | - |
|
119 | - return $this->normalize_categories($cats); |
|
120 | - } |
|
115 | + foreach ($categories as $cat) { |
|
116 | + array_push($cats, $cat->nodeValue); |
|
117 | + } |
|
118 | + |
|
119 | + return $this->normalize_categories($cats); |
|
120 | + } |
|
121 | 121 | |
122 | - public function get_enclosures() { |
|
123 | - $links = $this->elem->getElementsByTagName("link"); |
|
124 | - |
|
125 | - $encs = array(); |
|
126 | - |
|
127 | - foreach ($links as $link) { |
|
128 | - if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) { |
|
129 | - if ($link->getAttribute("rel") == "enclosure") { |
|
130 | - $enc = new FeedEnclosure(); |
|
131 | - |
|
132 | - $enc->type = clean($link->getAttribute("type")); |
|
133 | - $enc->link = clean($link->getAttribute("href")); |
|
134 | - $enc->length = clean($link->getAttribute("length")); |
|
135 | - |
|
136 | - array_push($encs, $enc); |
|
137 | - } |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - $encs = array_merge($encs, parent::get_enclosures()); |
|
142 | - |
|
143 | - return $encs; |
|
144 | - } |
|
145 | - |
|
146 | - public function get_language() { |
|
147 | - $lang = $this->elem->getAttributeNS(self::NS_XML, "lang"); |
|
148 | - |
|
149 | - if (!empty($lang)) { |
|
150 | - return clean($lang); |
|
151 | - } else { |
|
152 | - // Fall back to the language declared on the feed, if any. |
|
153 | - foreach ($this->doc->childNodes as $child) { |
|
154 | - if (method_exists($child, "getAttributeNS")) { |
|
155 | - return clean($child->getAttributeNS(self::NS_XML, "lang")); |
|
156 | - } |
|
157 | - } |
|
158 | - } |
|
159 | - } |
|
122 | + public function get_enclosures() { |
|
123 | + $links = $this->elem->getElementsByTagName("link"); |
|
124 | + |
|
125 | + $encs = array(); |
|
126 | + |
|
127 | + foreach ($links as $link) { |
|
128 | + if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) { |
|
129 | + if ($link->getAttribute("rel") == "enclosure") { |
|
130 | + $enc = new FeedEnclosure(); |
|
131 | + |
|
132 | + $enc->type = clean($link->getAttribute("type")); |
|
133 | + $enc->link = clean($link->getAttribute("href")); |
|
134 | + $enc->length = clean($link->getAttribute("length")); |
|
135 | + |
|
136 | + array_push($encs, $enc); |
|
137 | + } |
|
138 | + } |
|
139 | + } |
|
140 | + |
|
141 | + $encs = array_merge($encs, parent::get_enclosures()); |
|
142 | + |
|
143 | + return $encs; |
|
144 | + } |
|
145 | + |
|
146 | + public function get_language() { |
|
147 | + $lang = $this->elem->getAttributeNS(self::NS_XML, "lang"); |
|
148 | + |
|
149 | + if (!empty($lang)) { |
|
150 | + return clean($lang); |
|
151 | + } else { |
|
152 | + // Fall back to the language declared on the feed, if any. |
|
153 | + foreach ($this->doc->childNodes as $child) { |
|
154 | + if (method_exists($child, "getAttributeNS")) { |
|
155 | + return clean($child->getAttributeNS(self::NS_XML, "lang")); |
|
156 | + } |
|
157 | + } |
|
158 | + } |
|
159 | + } |
|
160 | 160 | } |
@@ -95,10 +95,11 @@ discard block |
||
95 | 95 | |
96 | 96 | $count = getFeedUnread($i); |
97 | 97 | |
98 | - if ($i == 0 || $i == -1 || $i == -2) |
|
99 | - $auxctr = Feeds::getFeedArticles($i, false); |
|
100 | - else |
|
101 | - $auxctr = 0; |
|
98 | + if ($i == 0 || $i == -1 || $i == -2) { |
|
99 | + $auxctr = Feeds::getFeedArticles($i, false); |
|
100 | + } else { |
|
101 | + $auxctr = 0; |
|
102 | + } |
|
102 | 103 | |
103 | 104 | $cv = array("id" => $i, |
104 | 105 | "counter" => (int) $count, |
@@ -117,8 +118,9 @@ discard block |
||
117 | 118 | $cv = array("id" => PluginHost::pfeed_to_feed_id($feed['id']), |
118 | 119 | "counter" => $feed['sender']->get_unread($feed['id'])); |
119 | 120 | |
120 | - if (method_exists($feed['sender'], 'get_total')) |
|
121 | - $cv["auxcounter"] = $feed['sender']->get_total($feed['id']); |
|
121 | + if (method_exists($feed['sender'], 'get_total')) { |
|
122 | + $cv["auxcounter"] = $feed['sender']->get_total($feed['id']); |
|
123 | + } |
|
122 | 124 | |
123 | 125 | array_push($ret_arr, $cv); |
124 | 126 | } |
@@ -150,8 +152,9 @@ discard block |
||
150 | 152 | "counter" => (int) $line["unread"], |
151 | 153 | "auxcounter" => (int) $line["total"]); |
152 | 154 | |
153 | - if ($descriptions) |
|
154 | - $cv["description"] = $line["caption"]; |
|
155 | + if ($descriptions) { |
|
156 | + $cv["description"] = $line["caption"]; |
|
157 | + } |
|
155 | 158 | |
156 | 159 | array_push($ret_arr, $cv); |
157 | 160 | } |
@@ -189,22 +192,25 @@ discard block |
||
189 | 192 | $has_img = false; |
190 | 193 | } |
191 | 194 | |
192 | - if (date('Y') - date('Y', strtotime($line['last_updated'])) > 2) |
|
193 | - $last_updated = ''; |
|
195 | + if (date('Y') - date('Y', strtotime($line['last_updated'])) > 2) { |
|
196 | + $last_updated = ''; |
|
197 | + } |
|
194 | 198 | |
195 | 199 | $cv = array("id" => $id, |
196 | 200 | "updated" => $last_updated, |
197 | 201 | "counter" => (int) $count, |
198 | 202 | "has_img" => (int) $has_img); |
199 | 203 | |
200 | - if ($last_error) |
|
201 | - $cv["error"] = $last_error; |
|
204 | + if ($last_error) { |
|
205 | + $cv["error"] = $last_error; |
|
206 | + } |
|
202 | 207 | |
203 | 208 | // if (get_pref('EXTENDED_FEEDLIST')) |
204 | 209 | // $cv["xmsg"] = getFeedArticles($id)." ".__("total"); |
205 | 210 | |
206 | - if ($active_feed && $id == $active_feed) |
|
207 | - $cv["title"] = truncate_string($line["title"], 30); |
|
211 | + if ($active_feed && $id == $active_feed) { |
|
212 | + $cv["title"] = truncate_string($line["title"], 30); |
|
213 | + } |
|
208 | 214 | |
209 | 215 | array_push($ret_arr, $cv); |
210 | 216 |
@@ -1,171 +1,171 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class Counters { |
3 | 3 | |
4 | - public static function getAllCounters() { |
|
5 | - $data = Counters::getGlobalCounters(); |
|
4 | + public static function getAllCounters() { |
|
5 | + $data = Counters::getGlobalCounters(); |
|
6 | 6 | |
7 | - $data = array_merge($data, Counters::getVirtCounters()); |
|
8 | - $data = array_merge($data, Counters::getLabelCounters()); |
|
9 | - $data = array_merge($data, Counters::getFeedCounters()); |
|
10 | - $data = array_merge($data, Counters::getCategoryCounters()); |
|
7 | + $data = array_merge($data, Counters::getVirtCounters()); |
|
8 | + $data = array_merge($data, Counters::getLabelCounters()); |
|
9 | + $data = array_merge($data, Counters::getFeedCounters()); |
|
10 | + $data = array_merge($data, Counters::getCategoryCounters()); |
|
11 | 11 | |
12 | - return $data; |
|
13 | - } |
|
12 | + return $data; |
|
13 | + } |
|
14 | 14 | |
15 | - public static function getCategoryCounters() { |
|
16 | - $ret_arr = array(); |
|
15 | + public static function getCategoryCounters() { |
|
16 | + $ret_arr = array(); |
|
17 | 17 | |
18 | - /* Labels category */ |
|
18 | + /* Labels category */ |
|
19 | 19 | |
20 | - $cv = array("id" => -2, "kind" => "cat", |
|
21 | - "counter" => Feeds::getCategoryUnread(-2)); |
|
20 | + $cv = array("id" => -2, "kind" => "cat", |
|
21 | + "counter" => Feeds::getCategoryUnread(-2)); |
|
22 | 22 | |
23 | - array_push($ret_arr, $cv); |
|
23 | + array_push($ret_arr, $cv); |
|
24 | 24 | |
25 | - $pdo = DB::pdo(); |
|
25 | + $pdo = DB::pdo(); |
|
26 | 26 | |
27 | - $sth = $pdo->prepare("SELECT ttrss_feed_categories.id AS cat_id, value AS unread, |
|
27 | + $sth = $pdo->prepare("SELECT ttrss_feed_categories.id AS cat_id, value AS unread, |
|
28 | 28 | (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 |
29 | 29 | WHERE c2.parent_cat = ttrss_feed_categories.id) AS num_children |
30 | 30 | FROM ttrss_feed_categories, ttrss_cat_counters_cache |
31 | 31 | WHERE ttrss_cat_counters_cache.feed_id = ttrss_feed_categories.id AND |
32 | 32 | ttrss_cat_counters_cache.owner_uid = ttrss_feed_categories.owner_uid AND |
33 | 33 | ttrss_feed_categories.owner_uid = ?"); |
34 | - $sth->execute([$_SESSION['uid']]); |
|
34 | + $sth->execute([$_SESSION['uid']]); |
|
35 | 35 | |
36 | - while ($line = $sth->fetch()) { |
|
37 | - $line["cat_id"] = (int) $line["cat_id"]; |
|
36 | + while ($line = $sth->fetch()) { |
|
37 | + $line["cat_id"] = (int) $line["cat_id"]; |
|
38 | 38 | |
39 | - if ($line["num_children"] > 0) { |
|
40 | - $child_counter = Feeds::getCategoryChildrenUnread($line["cat_id"], $_SESSION["uid"]); |
|
41 | - } else { |
|
42 | - $child_counter = 0; |
|
43 | - } |
|
39 | + if ($line["num_children"] > 0) { |
|
40 | + $child_counter = Feeds::getCategoryChildrenUnread($line["cat_id"], $_SESSION["uid"]); |
|
41 | + } else { |
|
42 | + $child_counter = 0; |
|
43 | + } |
|
44 | 44 | |
45 | - $cv = array("id" => $line["cat_id"], "kind" => "cat", |
|
46 | - "counter" => $line["unread"] + $child_counter); |
|
45 | + $cv = array("id" => $line["cat_id"], "kind" => "cat", |
|
46 | + "counter" => $line["unread"] + $child_counter); |
|
47 | 47 | |
48 | - array_push($ret_arr, $cv); |
|
49 | - } |
|
48 | + array_push($ret_arr, $cv); |
|
49 | + } |
|
50 | 50 | |
51 | - /* Special case: NULL category doesn't actually exist in the DB */ |
|
51 | + /* Special case: NULL category doesn't actually exist in the DB */ |
|
52 | 52 | |
53 | - $cv = array("id" => 0, "kind" => "cat", |
|
54 | - "counter" => (int) CCache::find(0, $_SESSION["uid"], true)); |
|
53 | + $cv = array("id" => 0, "kind" => "cat", |
|
54 | + "counter" => (int) CCache::find(0, $_SESSION["uid"], true)); |
|
55 | 55 | |
56 | - array_push($ret_arr, $cv); |
|
56 | + array_push($ret_arr, $cv); |
|
57 | 57 | |
58 | - return $ret_arr; |
|
59 | - } |
|
58 | + return $ret_arr; |
|
59 | + } |
|
60 | 60 | |
61 | - public static function getGlobalCounters($global_unread = -1) { |
|
62 | - $ret_arr = array(); |
|
61 | + public static function getGlobalCounters($global_unread = -1) { |
|
62 | + $ret_arr = array(); |
|
63 | 63 | |
64 | - if ($global_unread == -1) { |
|
65 | - $global_unread = Feeds::getGlobalUnread(); |
|
66 | - } |
|
64 | + if ($global_unread == -1) { |
|
65 | + $global_unread = Feeds::getGlobalUnread(); |
|
66 | + } |
|
67 | 67 | |
68 | - $cv = array("id" => "global-unread", |
|
69 | - "counter" => (int) $global_unread); |
|
68 | + $cv = array("id" => "global-unread", |
|
69 | + "counter" => (int) $global_unread); |
|
70 | 70 | |
71 | - array_push($ret_arr, $cv); |
|
71 | + array_push($ret_arr, $cv); |
|
72 | 72 | |
73 | - $pdo = Db::pdo(); |
|
73 | + $pdo = Db::pdo(); |
|
74 | 74 | |
75 | - $sth = $pdo->prepare("SELECT COUNT(id) AS fn FROM |
|
75 | + $sth = $pdo->prepare("SELECT COUNT(id) AS fn FROM |
|
76 | 76 | ttrss_feeds WHERE owner_uid = ?"); |
77 | - $sth->execute([$_SESSION['uid']]); |
|
78 | - $row = $sth->fetch(); |
|
77 | + $sth->execute([$_SESSION['uid']]); |
|
78 | + $row = $sth->fetch(); |
|
79 | 79 | |
80 | - $subscribed_feeds = $row["fn"]; |
|
80 | + $subscribed_feeds = $row["fn"]; |
|
81 | 81 | |
82 | - $cv = array("id" => "subscribed-feeds", |
|
83 | - "counter" => (int) $subscribed_feeds); |
|
82 | + $cv = array("id" => "subscribed-feeds", |
|
83 | + "counter" => (int) $subscribed_feeds); |
|
84 | 84 | |
85 | - array_push($ret_arr, $cv); |
|
85 | + array_push($ret_arr, $cv); |
|
86 | 86 | |
87 | - return $ret_arr; |
|
88 | - } |
|
87 | + return $ret_arr; |
|
88 | + } |
|
89 | 89 | |
90 | - public static function getVirtCounters() { |
|
90 | + public static function getVirtCounters() { |
|
91 | 91 | |
92 | - $ret_arr = array(); |
|
92 | + $ret_arr = array(); |
|
93 | 93 | |
94 | - for ($i = 0; $i >= -4; $i--) { |
|
94 | + for ($i = 0; $i >= -4; $i--) { |
|
95 | 95 | |
96 | - $count = getFeedUnread($i); |
|
96 | + $count = getFeedUnread($i); |
|
97 | 97 | |
98 | - if ($i == 0 || $i == -1 || $i == -2) |
|
99 | - $auxctr = Feeds::getFeedArticles($i, false); |
|
100 | - else |
|
101 | - $auxctr = 0; |
|
98 | + if ($i == 0 || $i == -1 || $i == -2) |
|
99 | + $auxctr = Feeds::getFeedArticles($i, false); |
|
100 | + else |
|
101 | + $auxctr = 0; |
|
102 | 102 | |
103 | - $cv = array("id" => $i, |
|
104 | - "counter" => (int) $count, |
|
105 | - "auxcounter" => (int) $auxctr); |
|
103 | + $cv = array("id" => $i, |
|
104 | + "counter" => (int) $count, |
|
105 | + "auxcounter" => (int) $auxctr); |
|
106 | 106 | |
107 | 107 | // if (get_pref('EXTENDED_FEEDLIST')) |
108 | 108 | // $cv["xmsg"] = getFeedArticles($i)." ".__("total"); |
109 | 109 | |
110 | - array_push($ret_arr, $cv); |
|
111 | - } |
|
110 | + array_push($ret_arr, $cv); |
|
111 | + } |
|
112 | 112 | |
113 | - $feeds = PluginHost::getInstance()->get_feeds(-1); |
|
113 | + $feeds = PluginHost::getInstance()->get_feeds(-1); |
|
114 | 114 | |
115 | - if (is_array($feeds)) { |
|
116 | - foreach ($feeds as $feed) { |
|
117 | - $cv = array("id" => PluginHost::pfeed_to_feed_id($feed['id']), |
|
118 | - "counter" => $feed['sender']->get_unread($feed['id'])); |
|
115 | + if (is_array($feeds)) { |
|
116 | + foreach ($feeds as $feed) { |
|
117 | + $cv = array("id" => PluginHost::pfeed_to_feed_id($feed['id']), |
|
118 | + "counter" => $feed['sender']->get_unread($feed['id'])); |
|
119 | 119 | |
120 | - if (method_exists($feed['sender'], 'get_total')) |
|
121 | - $cv["auxcounter"] = $feed['sender']->get_total($feed['id']); |
|
120 | + if (method_exists($feed['sender'], 'get_total')) |
|
121 | + $cv["auxcounter"] = $feed['sender']->get_total($feed['id']); |
|
122 | 122 | |
123 | - array_push($ret_arr, $cv); |
|
124 | - } |
|
125 | - } |
|
123 | + array_push($ret_arr, $cv); |
|
124 | + } |
|
125 | + } |
|
126 | 126 | |
127 | - return $ret_arr; |
|
128 | - } |
|
127 | + return $ret_arr; |
|
128 | + } |
|
129 | 129 | |
130 | - public static function getLabelCounters($descriptions = false) { |
|
130 | + public static function getLabelCounters($descriptions = false) { |
|
131 | 131 | |
132 | - $ret_arr = array(); |
|
132 | + $ret_arr = array(); |
|
133 | 133 | |
134 | - $pdo = Db::pdo(); |
|
134 | + $pdo = Db::pdo(); |
|
135 | 135 | |
136 | - $sth = $pdo->prepare("SELECT id,caption,SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS unread, COUNT(u1.unread) AS total |
|
136 | + $sth = $pdo->prepare("SELECT id,caption,SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS unread, COUNT(u1.unread) AS total |
|
137 | 137 | FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON |
138 | 138 | (ttrss_labels2.id = label_id) |
139 | 139 | LEFT JOIN ttrss_user_entries AS u1 ON u1.ref_id = article_id |
140 | 140 | WHERE ttrss_labels2.owner_uid = :uid AND u1.owner_uid = :uid |
141 | 141 | GROUP BY ttrss_labels2.id, |
142 | 142 | ttrss_labels2.caption"); |
143 | - $sth->execute([":uid" => $_SESSION['uid']]); |
|
143 | + $sth->execute([":uid" => $_SESSION['uid']]); |
|
144 | 144 | |
145 | - while ($line = $sth->fetch()) { |
|
145 | + while ($line = $sth->fetch()) { |
|
146 | 146 | |
147 | - $id = Labels::label_to_feed_id($line["id"]); |
|
147 | + $id = Labels::label_to_feed_id($line["id"]); |
|
148 | 148 | |
149 | - $cv = array("id" => $id, |
|
150 | - "counter" => (int) $line["unread"], |
|
151 | - "auxcounter" => (int) $line["total"]); |
|
149 | + $cv = array("id" => $id, |
|
150 | + "counter" => (int) $line["unread"], |
|
151 | + "auxcounter" => (int) $line["total"]); |
|
152 | 152 | |
153 | - if ($descriptions) |
|
154 | - $cv["description"] = $line["caption"]; |
|
153 | + if ($descriptions) |
|
154 | + $cv["description"] = $line["caption"]; |
|
155 | 155 | |
156 | - array_push($ret_arr, $cv); |
|
157 | - } |
|
156 | + array_push($ret_arr, $cv); |
|
157 | + } |
|
158 | 158 | |
159 | - return $ret_arr; |
|
160 | - } |
|
159 | + return $ret_arr; |
|
160 | + } |
|
161 | 161 | |
162 | - public static function getFeedCounters($active_feed = false) { |
|
162 | + public static function getFeedCounters($active_feed = false) { |
|
163 | 163 | |
164 | - $ret_arr = array(); |
|
164 | + $ret_arr = array(); |
|
165 | 165 | |
166 | - $pdo = Db::pdo(); |
|
166 | + $pdo = Db::pdo(); |
|
167 | 167 | |
168 | - $sth = $pdo->prepare("SELECT ttrss_feeds.id, |
|
168 | + $sth = $pdo->prepare("SELECT ttrss_feeds.id, |
|
169 | 169 | ttrss_feeds.title, |
170 | 170 | ".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated, |
171 | 171 | last_error, value AS count |
@@ -173,44 +173,44 @@ discard block |
||
173 | 173 | WHERE ttrss_feeds.owner_uid = ? |
174 | 174 | AND ttrss_counters_cache.owner_uid = ttrss_feeds.owner_uid |
175 | 175 | AND ttrss_counters_cache.feed_id = ttrss_feeds.id"); |
176 | - $sth->execute([$_SESSION['uid']]); |
|
176 | + $sth->execute([$_SESSION['uid']]); |
|
177 | 177 | |
178 | - while ($line = $sth->fetch()) { |
|
178 | + while ($line = $sth->fetch()) { |
|
179 | 179 | |
180 | - $id = $line["id"]; |
|
181 | - $count = $line["count"]; |
|
182 | - $last_error = htmlspecialchars($line["last_error"]); |
|
180 | + $id = $line["id"]; |
|
181 | + $count = $line["count"]; |
|
182 | + $last_error = htmlspecialchars($line["last_error"]); |
|
183 | 183 | |
184 | - $last_updated = make_local_datetime($line['last_updated'], false); |
|
184 | + $last_updated = make_local_datetime($line['last_updated'], false); |
|
185 | 185 | |
186 | - if (Feeds::feedHasIcon($id)) { |
|
187 | - $has_img = filemtime(Feeds::getIconFile($id)); |
|
188 | - } else { |
|
189 | - $has_img = false; |
|
190 | - } |
|
186 | + if (Feeds::feedHasIcon($id)) { |
|
187 | + $has_img = filemtime(Feeds::getIconFile($id)); |
|
188 | + } else { |
|
189 | + $has_img = false; |
|
190 | + } |
|
191 | 191 | |
192 | - if (date('Y') - date('Y', strtotime($line['last_updated'])) > 2) |
|
193 | - $last_updated = ''; |
|
192 | + if (date('Y') - date('Y', strtotime($line['last_updated'])) > 2) |
|
193 | + $last_updated = ''; |
|
194 | 194 | |
195 | - $cv = array("id" => $id, |
|
196 | - "updated" => $last_updated, |
|
197 | - "counter" => (int) $count, |
|
198 | - "has_img" => (int) $has_img); |
|
195 | + $cv = array("id" => $id, |
|
196 | + "updated" => $last_updated, |
|
197 | + "counter" => (int) $count, |
|
198 | + "has_img" => (int) $has_img); |
|
199 | 199 | |
200 | - if ($last_error) |
|
201 | - $cv["error"] = $last_error; |
|
200 | + if ($last_error) |
|
201 | + $cv["error"] = $last_error; |
|
202 | 202 | |
203 | 203 | // if (get_pref('EXTENDED_FEEDLIST')) |
204 | 204 | // $cv["xmsg"] = getFeedArticles($id)." ".__("total"); |
205 | 205 | |
206 | - if ($active_feed && $id == $active_feed) |
|
207 | - $cv["title"] = truncate_string($line["title"], 30); |
|
206 | + if ($active_feed && $id == $active_feed) |
|
207 | + $cv["title"] = truncate_string($line["title"], 30); |
|
208 | 208 | |
209 | - array_push($ret_arr, $cv); |
|
209 | + array_push($ret_arr, $cv); |
|
210 | 210 | |
211 | - } |
|
211 | + } |
|
212 | 212 | |
213 | - return $ret_arr; |
|
214 | - } |
|
213 | + return $ret_arr; |
|
214 | + } |
|
215 | 215 | |
216 | 216 | } |
@@ -43,10 +43,11 @@ |
||
43 | 43 | foreach ($lines as $line) { |
44 | 44 | if (strpos($line, "--") !== 0 && $line) { |
45 | 45 | |
46 | - if ($html_output) |
|
47 | - print "<pre>$line</pre>"; |
|
48 | - else |
|
49 | - Debug::log("> $line"); |
|
46 | + if ($html_output) { |
|
47 | + print "<pre>$line</pre>"; |
|
48 | + } else { |
|
49 | + Debug::log("> $line"); |
|
50 | + } |
|
50 | 51 | |
51 | 52 | try { |
52 | 53 | $this->pdo->query($line); // PDO returns errors as exceptions now |
@@ -2,83 +2,83 @@ |
||
2 | 2 | |
3 | 3 | class DbUpdater { |
4 | 4 | |
5 | - private $pdo; |
|
6 | - private $db_type; |
|
7 | - private $need_version; |
|
8 | - |
|
9 | - public function __construct($db_type, $need_version) { |
|
10 | - $this->pdo = Db::pdo(); |
|
11 | - $this->db_type = $db_type; |
|
12 | - $this->need_version = (int) $need_version; |
|
13 | - } |
|
14 | - |
|
15 | - public function getSchemaVersion() { |
|
16 | - $row = $this->pdo->query("SELECT schema_version FROM ttrss_version")->fetch(); |
|
17 | - return (int) $row['schema_version']; |
|
18 | - } |
|
19 | - |
|
20 | - public function isUpdateRequired() { |
|
21 | - return $this->getSchemaVersion() < $this->need_version; |
|
22 | - } |
|
23 | - |
|
24 | - public function getSchemaLines($version) { |
|
25 | - $filename = "schema/versions/".$this->db_type."/$version.sql"; |
|
26 | - |
|
27 | - if (file_exists($filename)) { |
|
28 | - return explode(";", preg_replace("/[\r\n]/", "", file_get_contents($filename))); |
|
29 | - } else { |
|
30 | - user_error("DB Updater: schema file for version $version is not found."); |
|
31 | - return false; |
|
32 | - } |
|
33 | - } |
|
34 | - |
|
35 | - public function performUpdateTo($version, $html_output = true) { |
|
36 | - if ($this->getSchemaVersion() == $version - 1) { |
|
37 | - |
|
38 | - $lines = $this->getSchemaLines($version); |
|
39 | - |
|
40 | - if (is_array($lines)) { |
|
41 | - |
|
42 | - $this->pdo->beginTransaction(); |
|
43 | - |
|
44 | - foreach ($lines as $line) { |
|
45 | - if (strpos($line, "--") !== 0 && $line) { |
|
46 | - |
|
47 | - if ($html_output) |
|
48 | - print "<pre>$line</pre>"; |
|
49 | - else |
|
50 | - Debug::log("> $line"); |
|
51 | - |
|
52 | - try { |
|
53 | - $this->pdo->query($line); // PDO returns errors as exceptions now |
|
54 | - } catch (PDOException $e) { |
|
55 | - if ($html_output) { |
|
56 | - print "<div class='text-error'>Error: " . $e->getMessage() . "</div>"; |
|
57 | - } else { |
|
58 | - Debug::log("Error: " . $e->getMessage()); |
|
59 | - } |
|
60 | - |
|
61 | - $this->pdo->rollBack(); |
|
62 | - return false; |
|
63 | - } |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - $db_version = $this->getSchemaVersion(); |
|
68 | - |
|
69 | - if ($db_version == $version) { |
|
70 | - $this->pdo->commit(); |
|
71 | - return true; |
|
72 | - } else { |
|
73 | - $this->pdo->rollBack(); |
|
74 | - return false; |
|
75 | - } |
|
76 | - } else { |
|
77 | - return false; |
|
78 | - } |
|
79 | - } else { |
|
80 | - return false; |
|
81 | - } |
|
82 | - } |
|
5 | + private $pdo; |
|
6 | + private $db_type; |
|
7 | + private $need_version; |
|
8 | + |
|
9 | + public function __construct($db_type, $need_version) { |
|
10 | + $this->pdo = Db::pdo(); |
|
11 | + $this->db_type = $db_type; |
|
12 | + $this->need_version = (int) $need_version; |
|
13 | + } |
|
14 | + |
|
15 | + public function getSchemaVersion() { |
|
16 | + $row = $this->pdo->query("SELECT schema_version FROM ttrss_version")->fetch(); |
|
17 | + return (int) $row['schema_version']; |
|
18 | + } |
|
19 | + |
|
20 | + public function isUpdateRequired() { |
|
21 | + return $this->getSchemaVersion() < $this->need_version; |
|
22 | + } |
|
23 | + |
|
24 | + public function getSchemaLines($version) { |
|
25 | + $filename = "schema/versions/".$this->db_type."/$version.sql"; |
|
26 | + |
|
27 | + if (file_exists($filename)) { |
|
28 | + return explode(";", preg_replace("/[\r\n]/", "", file_get_contents($filename))); |
|
29 | + } else { |
|
30 | + user_error("DB Updater: schema file for version $version is not found."); |
|
31 | + return false; |
|
32 | + } |
|
33 | + } |
|
34 | + |
|
35 | + public function performUpdateTo($version, $html_output = true) { |
|
36 | + if ($this->getSchemaVersion() == $version - 1) { |
|
37 | + |
|
38 | + $lines = $this->getSchemaLines($version); |
|
39 | + |
|
40 | + if (is_array($lines)) { |
|
41 | + |
|
42 | + $this->pdo->beginTransaction(); |
|
43 | + |
|
44 | + foreach ($lines as $line) { |
|
45 | + if (strpos($line, "--") !== 0 && $line) { |
|
46 | + |
|
47 | + if ($html_output) |
|
48 | + print "<pre>$line</pre>"; |
|
49 | + else |
|
50 | + Debug::log("> $line"); |
|
51 | + |
|
52 | + try { |
|
53 | + $this->pdo->query($line); // PDO returns errors as exceptions now |
|
54 | + } catch (PDOException $e) { |
|
55 | + if ($html_output) { |
|
56 | + print "<div class='text-error'>Error: " . $e->getMessage() . "</div>"; |
|
57 | + } else { |
|
58 | + Debug::log("Error: " . $e->getMessage()); |
|
59 | + } |
|
60 | + |
|
61 | + $this->pdo->rollBack(); |
|
62 | + return false; |
|
63 | + } |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + $db_version = $this->getSchemaVersion(); |
|
68 | + |
|
69 | + if ($db_version == $version) { |
|
70 | + $this->pdo->commit(); |
|
71 | + return true; |
|
72 | + } else { |
|
73 | + $this->pdo->rollBack(); |
|
74 | + return false; |
|
75 | + } |
|
76 | + } else { |
|
77 | + return false; |
|
78 | + } |
|
79 | + } else { |
|
80 | + return false; |
|
81 | + } |
|
82 | + } |
|
83 | 83 | |
84 | 84 | } |
@@ -24,13 +24,15 @@ discard block |
||
24 | 24 | $r = ord($str[2]); |
25 | 25 | if (strlen($str) > 3) { |
26 | 26 | $a = 127 - (ord($str[3]) / 2); |
27 | - if ($a != 0 && $a != 127) |
|
28 | - $this->had_alpha = 1; |
|
27 | + if ($a != 0 && $a != 127) { |
|
28 | + $this->had_alpha = 1; |
|
29 | + } |
|
29 | 30 | } else { |
30 | 31 | $a = 0; |
31 | 32 | } |
32 | - if ($a != 127) |
|
33 | - $this->all_transaprent = 0; |
|
33 | + if ($a != 127) { |
|
34 | + $this->all_transaprent = 0; |
|
35 | + } |
|
34 | 36 | return imagecolorallocatealpha($img, $r, $g, $b, $a); |
35 | 37 | } |
36 | 38 | |
@@ -65,8 +67,9 @@ discard block |
||
65 | 67 | $most_pixels = 0; |
66 | 68 | for ($i = 0; $i < $h["num"]; $i++) { |
67 | 69 | $entry = substr($ico, 6 + 16 * $i, 16); |
68 | - if (!$entry || strlen($entry) < 16) |
|
69 | - continue; |
|
70 | + if (!$entry || strlen($entry) < 16) { |
|
71 | + continue; |
|
72 | + } |
|
70 | 73 | $e = unpack("Cwidth/" . |
71 | 74 | "Cheight/" . |
72 | 75 | "Ccolors/" . |
@@ -76,10 +79,12 @@ discard block |
||
76 | 79 | "Vsize/" . |
77 | 80 | "Voffset/", |
78 | 81 | $entry); |
79 | - if ($e["width"] == 0) |
|
80 | - $e["width"] = 256; |
|
81 | - if ($e["height"] == 0) |
|
82 | - $e["height"] = 256; |
|
82 | + if ($e["width"] == 0) { |
|
83 | + $e["width"] = 256; |
|
84 | + } |
|
85 | + if ($e["height"] == 0) { |
|
86 | + $e["height"] = 256; |
|
87 | + } |
|
83 | 88 | if ($e["zero"] != 0) { |
84 | 89 | $this->error = "nonzero reserved field"; |
85 | 90 | return false; |
@@ -226,8 +231,9 @@ discard block |
||
226 | 231 | } |
227 | 232 | } |
228 | 233 | // End of row padding |
229 | - while ($offset & 3) |
|
230 | - $offset++; |
|
234 | + while ($offset & 3) { |
|
235 | + $offset++; |
|
236 | + } |
|
231 | 237 | } |
232 | 238 | |
233 | 239 | // Now the "AND" image, which is 1 bit per pixel. Ignore |
@@ -261,8 +267,9 @@ discard block |
||
261 | 267 | } |
262 | 268 | |
263 | 269 | // End of row padding |
264 | - while ($offset & 3) |
|
265 | - $offset++; |
|
270 | + while ($offset & 3) { |
|
271 | + $offset++; |
|
272 | + } |
|
266 | 273 | } |
267 | 274 | return $img; |
268 | 275 | } |
@@ -123,16 +123,16 @@ discard block |
||
123 | 123 | $bitmapinfo = unpack("Vsize", $data); |
124 | 124 | if ($bitmapinfo["size"] == 40) { |
125 | 125 | $info = unpack("Vsize/" . |
126 | - "Vwidth/" . |
|
127 | - "Vheight/" . |
|
128 | - "vplanes/" . |
|
129 | - "vbpp/" . |
|
130 | - "Vcompress/" . |
|
131 | - "Vsize/" . |
|
132 | - "Vxres/" . |
|
133 | - "Vyres/" . |
|
134 | - "Vpalcolors/" . |
|
135 | - "Vimpcolors/", $data); |
|
126 | + "Vwidth/" . |
|
127 | + "Vheight/" . |
|
128 | + "vplanes/" . |
|
129 | + "vbpp/" . |
|
130 | + "Vcompress/" . |
|
131 | + "Vsize/" . |
|
132 | + "Vxres/" . |
|
133 | + "Vyres/" . |
|
134 | + "Vpalcolors/" . |
|
135 | + "Vimpcolors/", $data); |
|
136 | 136 | if ($e["bpp"] == 0) { |
137 | 137 | $e["bpp"] = $info["bpp"]; |
138 | 138 | } |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | for ($y = 0; $y < $height; $y++) { |
240 | 240 | for ($x = 0; $x < $width; $x++) { |
241 | 241 | imagesetpixel($img, $x, $y, |
242 | - $XOR[$y][$x]); |
|
242 | + $XOR[$y][$x]); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | return $img; |
@@ -250,10 +250,10 @@ discard block |
||
250 | 250 | $x = 0; |
251 | 251 | while ($x < $width) { |
252 | 252 | for ($b = 0x80; |
253 | - $b > 0 && $x < $width; $b >>= 1) { |
|
253 | + $b > 0 && $x < $width; $b >>= 1) { |
|
254 | 254 | if (!(ord($data[$offset]) & $b)) { |
255 | 255 | imagesetpixel($img, $x, $y, |
256 | - $XOR[$y][$x]); |
|
256 | + $XOR[$y][$x]); |
|
257 | 257 | } |
258 | 258 | $x++; |
259 | 259 | } |
@@ -108,13 +108,15 @@ discard block |
||
108 | 108 | //---------------------------------------------------------------------- |
109 | 109 | public function appendNum($bits, $num) |
110 | 110 | { |
111 | - if ($bits == 0) |
|
112 | - return 0; |
|
111 | + if ($bits == 0) { |
|
112 | + return 0; |
|
113 | + } |
|
113 | 114 | |
114 | 115 | $b = QRbitstream::newFromNum($bits, $num); |
115 | 116 | |
116 | - if(is_null($b)) |
|
117 | - return -1; |
|
117 | + if(is_null($b)) { |
|
118 | + return -1; |
|
119 | + } |
|
118 | 120 | |
119 | 121 | $ret = $this->append($b); |
120 | 122 | unset($b); |
@@ -125,13 +127,15 @@ discard block |
||
125 | 127 | //---------------------------------------------------------------------- |
126 | 128 | public function appendBytes($size, $data) |
127 | 129 | { |
128 | - if ($size == 0) |
|
129 | - return 0; |
|
130 | + if ($size == 0) { |
|
131 | + return 0; |
|
132 | + } |
|
130 | 133 | |
131 | 134 | $b = QRbitstream::newFromBytes($size, $data); |
132 | 135 | |
133 | - if(is_null($b)) |
|
134 | - return -1; |
|
136 | + if(is_null($b)) { |
|
137 | + return -1; |
|
138 | + } |
|
135 | 139 | |
136 | 140 | $ret = $this->append($b); |
137 | 141 | unset($b); |
@@ -115,8 +115,9 @@ discard block |
||
115 | 115 | |
116 | 116 | for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) { |
117 | 117 | $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level]; |
118 | - if($words >= $size) |
|
119 | - return $i; |
|
118 | + if($words >= $size) { |
|
119 | + return $i; |
|
120 | + } |
|
120 | 121 | } |
121 | 122 | |
122 | 123 | return -1; |
@@ -134,8 +135,9 @@ discard block |
||
134 | 135 | //---------------------------------------------------------------------- |
135 | 136 | public static function lengthIndicator($mode, $version) |
136 | 137 | { |
137 | - if ($mode == QR_MODE_STRUCTURE) |
|
138 | - return 0; |
|
138 | + if ($mode == QR_MODE_STRUCTURE) { |
|
139 | + return 0; |
|
140 | + } |
|
139 | 141 | |
140 | 142 | if ($version <= 9) { |
141 | 143 | $l = 0; |
@@ -151,8 +153,9 @@ discard block |
||
151 | 153 | //---------------------------------------------------------------------- |
152 | 154 | public static function maximumWords($mode, $version) |
153 | 155 | { |
154 | - if($mode == QR_MODE_STRUCTURE) |
|
155 | - return 3; |
|
156 | + if($mode == QR_MODE_STRUCTURE) { |
|
157 | + return 3; |
|
158 | + } |
|
156 | 159 | |
157 | 160 | if($version <= 9) { |
158 | 161 | $l = 0; |
@@ -298,8 +301,9 @@ discard block |
||
298 | 301 | //---------------------------------------------------------------------- |
299 | 302 | public static function putAlignmentPattern($version, &$frame, $width) |
300 | 303 | { |
301 | - if($version < 2) |
|
302 | - return; |
|
304 | + if($version < 2) { |
|
305 | + return; |
|
306 | + } |
|
303 | 307 | |
304 | 308 | $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0]; |
305 | 309 | if($d < 0) { |
@@ -351,8 +355,9 @@ discard block |
||
351 | 355 | //---------------------------------------------------------------------- |
352 | 356 | public static function getVersionPattern($version) |
353 | 357 | { |
354 | - if($version < 7 || $version > QRSPEC_VERSION_MAX) |
|
355 | - return 0; |
|
358 | + if($version < 7 || $version > QRSPEC_VERSION_MAX) { |
|
359 | + return 0; |
|
360 | + } |
|
356 | 361 | |
357 | 362 | return self::$versionPattern[$version -7]; |
358 | 363 | } |
@@ -369,11 +374,13 @@ discard block |
||
369 | 374 | |
370 | 375 | public static function getFormatInfo($mask, $level) |
371 | 376 | { |
372 | - if($mask < 0 || $mask > 7) |
|
373 | - return 0; |
|
377 | + if($mask < 0 || $mask > 7) { |
|
378 | + return 0; |
|
379 | + } |
|
374 | 380 | |
375 | - if($level < 0 || $level > 3) |
|
376 | - return 0; |
|
381 | + if($level < 0 || $level > 3) { |
|
382 | + return 0; |
|
383 | + } |
|
377 | 384 | |
378 | 385 | return self::$formatInfo[$level][$mask]; |
379 | 386 | } |
@@ -553,8 +560,9 @@ discard block |
||
553 | 560 | //---------------------------------------------------------------------- |
554 | 561 | public static function newFrame($version) |
555 | 562 | { |
556 | - if($version < 1 || $version > QRSPEC_VERSION_MAX) |
|
557 | - return null; |
|
563 | + if($version < 1 || $version > QRSPEC_VERSION_MAX) { |
|
564 | + return null; |
|
565 | + } |
|
558 | 566 | |
559 | 567 | if(!isset(self::$frames[$version])) { |
560 | 568 | |
@@ -572,8 +580,9 @@ discard block |
||
572 | 580 | } |
573 | 581 | } |
574 | 582 | |
575 | - if(is_null(self::$frames[$version])) |
|
576 | - return null; |
|
583 | + if(is_null(self::$frames[$version])) { |
|
584 | + return null; |
|
585 | + } |
|
577 | 586 | |
578 | 587 | return self::$frames[$version]; |
579 | 588 | } |
@@ -335,10 +335,10 @@ |
||
335 | 335 | |
336 | 336 | // Version information pattern ----------------------------------------- |
337 | 337 | |
338 | - // Version information pattern (BCH coded). |
|
338 | + // Version information pattern (BCH coded). |
|
339 | 339 | // See Table 1 in Appendix D (pp.68) of JIS X0510:2004. |
340 | 340 | |
341 | - // size: [QRSPEC_VERSION_MAX - 6] |
|
341 | + // size: [QRSPEC_VERSION_MAX - 6] |
|
342 | 342 | |
343 | 343 | public static $versionPattern = array( |
344 | 344 | 0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d, |