@@ -1,196 +1,196 @@ |
||
1 | 1 | <?php |
2 | 2 | abstract class FeedItem_Common extends FeedItem { |
3 | - protected $elem; |
|
4 | - protected $xpath; |
|
5 | - protected $doc; |
|
3 | + protected $elem; |
|
4 | + protected $xpath; |
|
5 | + protected $doc; |
|
6 | 6 | |
7 | - public function __construct($elem, $doc, $xpath) { |
|
8 | - $this->elem = $elem; |
|
9 | - $this->xpath = $xpath; |
|
10 | - $this->doc = $doc; |
|
7 | + public function __construct($elem, $doc, $xpath) { |
|
8 | + $this->elem = $elem; |
|
9 | + $this->xpath = $xpath; |
|
10 | + $this->doc = $doc; |
|
11 | 11 | |
12 | - try { |
|
12 | + try { |
|
13 | 13 | |
14 | - $source = $elem->getElementsByTagName("source")->item(0); |
|
14 | + $source = $elem->getElementsByTagName("source")->item(0); |
|
15 | 15 | |
16 | - // we don't need <source> element |
|
17 | - if ($source) |
|
18 | - $elem->removeChild($source); |
|
19 | - } catch (DOMException $e) { |
|
20 | - // |
|
21 | - } |
|
22 | - } |
|
16 | + // we don't need <source> element |
|
17 | + if ($source) |
|
18 | + $elem->removeChild($source); |
|
19 | + } catch (DOMException $e) { |
|
20 | + // |
|
21 | + } |
|
22 | + } |
|
23 | 23 | |
24 | - public function get_element() { |
|
25 | - return $this->elem; |
|
26 | - } |
|
24 | + public function get_element() { |
|
25 | + return $this->elem; |
|
26 | + } |
|
27 | 27 | |
28 | - public function get_author() { |
|
29 | - $author = $this->elem->getElementsByTagName("author")->item(0); |
|
28 | + public function get_author() { |
|
29 | + $author = $this->elem->getElementsByTagName("author")->item(0); |
|
30 | 30 | |
31 | - if ($author) { |
|
32 | - $name = $author->getElementsByTagName("name")->item(0); |
|
31 | + if ($author) { |
|
32 | + $name = $author->getElementsByTagName("name")->item(0); |
|
33 | 33 | |
34 | - if ($name) return clean($name->nodeValue); |
|
34 | + if ($name) return clean($name->nodeValue); |
|
35 | 35 | |
36 | - $email = $author->getElementsByTagName("email")->item(0); |
|
36 | + $email = $author->getElementsByTagName("email")->item(0); |
|
37 | 37 | |
38 | - if ($email) return clean($email->nodeValue); |
|
38 | + if ($email) return clean($email->nodeValue); |
|
39 | 39 | |
40 | - if ($author->nodeValue) |
|
41 | - return clean($author->nodeValue); |
|
42 | - } |
|
40 | + if ($author->nodeValue) |
|
41 | + return clean($author->nodeValue); |
|
42 | + } |
|
43 | 43 | |
44 | - $author_elems = $this->xpath->query("dc:creator", $this->elem); |
|
45 | - $authors = []; |
|
44 | + $author_elems = $this->xpath->query("dc:creator", $this->elem); |
|
45 | + $authors = []; |
|
46 | 46 | |
47 | - foreach ($author_elems as $author) { |
|
48 | - array_push($authors, clean($author->nodeValue)); |
|
49 | - } |
|
47 | + foreach ($author_elems as $author) { |
|
48 | + array_push($authors, clean($author->nodeValue)); |
|
49 | + } |
|
50 | 50 | |
51 | - return implode(", ", $authors); |
|
52 | - } |
|
51 | + return implode(", ", $authors); |
|
52 | + } |
|
53 | 53 | |
54 | - public function get_comments_url() { |
|
55 | - //RSS only. Use a query here to avoid namespace clashes (e.g. with slash). |
|
56 | - //might give a wrong result if a default namespace was declared (possible with XPath 2.0) |
|
57 | - $com_url = $this->xpath->query("comments", $this->elem)->item(0); |
|
54 | + public function get_comments_url() { |
|
55 | + //RSS only. Use a query here to avoid namespace clashes (e.g. with slash). |
|
56 | + //might give a wrong result if a default namespace was declared (possible with XPath 2.0) |
|
57 | + $com_url = $this->xpath->query("comments", $this->elem)->item(0); |
|
58 | 58 | |
59 | - if ($com_url) |
|
60 | - return clean($com_url->nodeValue); |
|
59 | + if ($com_url) |
|
60 | + return clean($com_url->nodeValue); |
|
61 | 61 | |
62 | - //Atom Threading Extension (RFC 4685) stuff. Could be used in RSS feeds, so it's in common. |
|
63 | - //'text/html' for type is too restrictive? |
|
64 | - $com_url = $this->xpath->query("atom:link[@rel='replies' and contains(@type,'text/html')]/@href", $this->elem)->item(0); |
|
62 | + //Atom Threading Extension (RFC 4685) stuff. Could be used in RSS feeds, so it's in common. |
|
63 | + //'text/html' for type is too restrictive? |
|
64 | + $com_url = $this->xpath->query("atom:link[@rel='replies' and contains(@type,'text/html')]/@href", $this->elem)->item(0); |
|
65 | 65 | |
66 | - if ($com_url) |
|
67 | - return clean($com_url->nodeValue); |
|
68 | - } |
|
66 | + if ($com_url) |
|
67 | + return clean($com_url->nodeValue); |
|
68 | + } |
|
69 | 69 | |
70 | - public function get_comments_count() { |
|
71 | - //also query for ATE stuff here |
|
72 | - $query = "slash:comments|thread:total|atom:link[@rel='replies']/@thread:count"; |
|
73 | - $comments = $this->xpath->query($query, $this->elem)->item(0); |
|
70 | + public function get_comments_count() { |
|
71 | + //also query for ATE stuff here |
|
72 | + $query = "slash:comments|thread:total|atom:link[@rel='replies']/@thread:count"; |
|
73 | + $comments = $this->xpath->query($query, $this->elem)->item(0); |
|
74 | 74 | |
75 | - if ($comments) { |
|
76 | - return clean($comments->nodeValue); |
|
77 | - } |
|
78 | - } |
|
75 | + if ($comments) { |
|
76 | + return clean($comments->nodeValue); |
|
77 | + } |
|
78 | + } |
|
79 | 79 | |
80 | - // this is common for both Atom and RSS types and deals with various media: elements |
|
81 | - public function get_enclosures() { |
|
82 | - $encs = []; |
|
80 | + // this is common for both Atom and RSS types and deals with various media: elements |
|
81 | + public function get_enclosures() { |
|
82 | + $encs = []; |
|
83 | 83 | |
84 | - $enclosures = $this->xpath->query("media:content", $this->elem); |
|
84 | + $enclosures = $this->xpath->query("media:content", $this->elem); |
|
85 | 85 | |
86 | - foreach ($enclosures as $enclosure) { |
|
87 | - $enc = new FeedEnclosure(); |
|
86 | + foreach ($enclosures as $enclosure) { |
|
87 | + $enc = new FeedEnclosure(); |
|
88 | 88 | |
89 | - $enc->type = clean($enclosure->getAttribute("type")); |
|
90 | - $enc->link = clean($enclosure->getAttribute("url")); |
|
91 | - $enc->length = clean($enclosure->getAttribute("length")); |
|
92 | - $enc->height = clean($enclosure->getAttribute("height")); |
|
93 | - $enc->width = clean($enclosure->getAttribute("width")); |
|
89 | + $enc->type = clean($enclosure->getAttribute("type")); |
|
90 | + $enc->link = clean($enclosure->getAttribute("url")); |
|
91 | + $enc->length = clean($enclosure->getAttribute("length")); |
|
92 | + $enc->height = clean($enclosure->getAttribute("height")); |
|
93 | + $enc->width = clean($enclosure->getAttribute("width")); |
|
94 | 94 | |
95 | - $medium = clean($enclosure->getAttribute("medium")); |
|
96 | - if (!$enc->type && $medium) { |
|
97 | - $enc->type = strtolower("$medium/generic"); |
|
98 | - } |
|
95 | + $medium = clean($enclosure->getAttribute("medium")); |
|
96 | + if (!$enc->type && $medium) { |
|
97 | + $enc->type = strtolower("$medium/generic"); |
|
98 | + } |
|
99 | 99 | |
100 | - $desc = $this->xpath->query("media:description", $enclosure)->item(0); |
|
101 | - if ($desc) $enc->title = clean($desc->nodeValue); |
|
100 | + $desc = $this->xpath->query("media:description", $enclosure)->item(0); |
|
101 | + if ($desc) $enc->title = clean($desc->nodeValue); |
|
102 | 102 | |
103 | - array_push($encs, $enc); |
|
104 | - } |
|
103 | + array_push($encs, $enc); |
|
104 | + } |
|
105 | 105 | |
106 | - $enclosures = $this->xpath->query("media:group", $this->elem); |
|
106 | + $enclosures = $this->xpath->query("media:group", $this->elem); |
|
107 | 107 | |
108 | - foreach ($enclosures as $enclosure) { |
|
109 | - $enc = new FeedEnclosure(); |
|
108 | + foreach ($enclosures as $enclosure) { |
|
109 | + $enc = new FeedEnclosure(); |
|
110 | 110 | |
111 | - $content = $this->xpath->query("media:content", $enclosure)->item(0); |
|
111 | + $content = $this->xpath->query("media:content", $enclosure)->item(0); |
|
112 | 112 | |
113 | - if ($content) { |
|
114 | - $enc->type = clean($content->getAttribute("type")); |
|
115 | - $enc->link = clean($content->getAttribute("url")); |
|
116 | - $enc->length = clean($content->getAttribute("length")); |
|
117 | - $enc->height = clean($content->getAttribute("height")); |
|
118 | - $enc->width = clean($content->getAttribute("width")); |
|
113 | + if ($content) { |
|
114 | + $enc->type = clean($content->getAttribute("type")); |
|
115 | + $enc->link = clean($content->getAttribute("url")); |
|
116 | + $enc->length = clean($content->getAttribute("length")); |
|
117 | + $enc->height = clean($content->getAttribute("height")); |
|
118 | + $enc->width = clean($content->getAttribute("width")); |
|
119 | 119 | |
120 | - $medium = clean($content->getAttribute("medium")); |
|
121 | - if (!$enc->type && $medium) { |
|
122 | - $enc->type = strtolower("$medium/generic"); |
|
123 | - } |
|
120 | + $medium = clean($content->getAttribute("medium")); |
|
121 | + if (!$enc->type && $medium) { |
|
122 | + $enc->type = strtolower("$medium/generic"); |
|
123 | + } |
|
124 | 124 | |
125 | - $desc = $this->xpath->query("media:description", $content)->item(0); |
|
126 | - if ($desc) { |
|
127 | - $enc->title = clean($desc->nodeValue); |
|
128 | - } else { |
|
129 | - $desc = $this->xpath->query("media:description", $enclosure)->item(0); |
|
130 | - if ($desc) $enc->title = clean($desc->nodeValue); |
|
131 | - } |
|
125 | + $desc = $this->xpath->query("media:description", $content)->item(0); |
|
126 | + if ($desc) { |
|
127 | + $enc->title = clean($desc->nodeValue); |
|
128 | + } else { |
|
129 | + $desc = $this->xpath->query("media:description", $enclosure)->item(0); |
|
130 | + if ($desc) $enc->title = clean($desc->nodeValue); |
|
131 | + } |
|
132 | 132 | |
133 | - array_push($encs, $enc); |
|
134 | - } |
|
135 | - } |
|
133 | + array_push($encs, $enc); |
|
134 | + } |
|
135 | + } |
|
136 | 136 | |
137 | - $enclosures = $this->xpath->query("media:thumbnail", $this->elem); |
|
137 | + $enclosures = $this->xpath->query("media:thumbnail", $this->elem); |
|
138 | 138 | |
139 | - foreach ($enclosures as $enclosure) { |
|
140 | - $enc = new FeedEnclosure(); |
|
139 | + foreach ($enclosures as $enclosure) { |
|
140 | + $enc = new FeedEnclosure(); |
|
141 | 141 | |
142 | - $enc->type = "image/generic"; |
|
143 | - $enc->link = clean($enclosure->getAttribute("url")); |
|
144 | - $enc->height = clean($enclosure->getAttribute("height")); |
|
145 | - $enc->width = clean($enclosure->getAttribute("width")); |
|
142 | + $enc->type = "image/generic"; |
|
143 | + $enc->link = clean($enclosure->getAttribute("url")); |
|
144 | + $enc->height = clean($enclosure->getAttribute("height")); |
|
145 | + $enc->width = clean($enclosure->getAttribute("width")); |
|
146 | 146 | |
147 | - array_push($encs, $enc); |
|
148 | - } |
|
147 | + array_push($encs, $enc); |
|
148 | + } |
|
149 | 149 | |
150 | - return $encs; |
|
151 | - } |
|
150 | + return $encs; |
|
151 | + } |
|
152 | 152 | |
153 | - public function count_children($node) { |
|
154 | - return $node->getElementsByTagName("*")->length; |
|
155 | - } |
|
153 | + public function count_children($node) { |
|
154 | + return $node->getElementsByTagName("*")->length; |
|
155 | + } |
|
156 | 156 | |
157 | - public function subtree_or_text($node) { |
|
158 | - if ($this->count_children($node) == 0) { |
|
159 | - return $node->nodeValue; |
|
160 | - } else { |
|
161 | - return $node->c14n(); |
|
162 | - } |
|
163 | - } |
|
157 | + public function subtree_or_text($node) { |
|
158 | + if ($this->count_children($node) == 0) { |
|
159 | + return $node->nodeValue; |
|
160 | + } else { |
|
161 | + return $node->c14n(); |
|
162 | + } |
|
163 | + } |
|
164 | 164 | |
165 | - public static function normalize_categories($cats) { |
|
165 | + public static function normalize_categories($cats) { |
|
166 | 166 | |
167 | - $tmp = []; |
|
167 | + $tmp = []; |
|
168 | 168 | |
169 | - foreach ($cats as $rawcat) { |
|
170 | - $tmp = array_merge($tmp, explode(",", $rawcat)); |
|
171 | - } |
|
169 | + foreach ($cats as $rawcat) { |
|
170 | + $tmp = array_merge($tmp, explode(",", $rawcat)); |
|
171 | + } |
|
172 | 172 | |
173 | - $tmp = array_map(function($srccat) { |
|
174 | - $cat = clean(trim(mb_strtolower($srccat))); |
|
173 | + $tmp = array_map(function($srccat) { |
|
174 | + $cat = clean(trim(mb_strtolower($srccat))); |
|
175 | 175 | |
176 | - // we don't support numeric tags |
|
177 | - if (is_numeric($cat)) |
|
178 | - $cat = 't:' . $cat; |
|
176 | + // we don't support numeric tags |
|
177 | + if (is_numeric($cat)) |
|
178 | + $cat = 't:' . $cat; |
|
179 | 179 | |
180 | - $cat = preg_replace('/[,\'\"]/', "", $cat); |
|
180 | + $cat = preg_replace('/[,\'\"]/', "", $cat); |
|
181 | 181 | |
182 | - if (DB_TYPE == "mysql") { |
|
183 | - $cat = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $cat); |
|
184 | - } |
|
182 | + if (DB_TYPE == "mysql") { |
|
183 | + $cat = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $cat); |
|
184 | + } |
|
185 | 185 | |
186 | - if (mb_strlen($cat) > 250) |
|
187 | - $cat = mb_substr($cat, 0, 250); |
|
186 | + if (mb_strlen($cat) > 250) |
|
187 | + $cat = mb_substr($cat, 0, 250); |
|
188 | 188 | |
189 | - return $cat; |
|
190 | - }, $tmp); |
|
189 | + return $cat; |
|
190 | + }, $tmp); |
|
191 | 191 | |
192 | - asort($tmp); |
|
192 | + asort($tmp); |
|
193 | 193 | |
194 | - return array_unique($tmp); |
|
195 | - } |
|
194 | + return array_unique($tmp); |
|
195 | + } |
|
196 | 196 | } |
@@ -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 | } |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | interface IDb { |
3 | - public function connect($host, $user, $pass, $db, $port); |
|
4 | - public function escape_string($s, $strip_tags = true); |
|
5 | - public function query($query, $die_on_error = true); |
|
6 | - public function fetch_assoc($result); |
|
7 | - public function num_rows($result); |
|
8 | - public function fetch_result($result, $row, $param); |
|
9 | - public function close(); |
|
10 | - public function affected_rows($result); |
|
11 | - public function last_error(); |
|
12 | - public function last_query_error(); |
|
3 | + public function connect($host, $user, $pass, $db, $port); |
|
4 | + public function escape_string($s, $strip_tags = true); |
|
5 | + public function query($query, $die_on_error = true); |
|
6 | + public function fetch_assoc($result); |
|
7 | + public function num_rows($result); |
|
8 | + public function fetch_result($result, $row, $param); |
|
9 | + public function close(); |
|
10 | + public function affected_rows($result); |
|
11 | + public function last_error(); |
|
12 | + public function last_query_error(); |
|
13 | 13 | } |
@@ -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 | } |
@@ -1,23 +1,23 @@ |
||
1 | 1 | <?php |
2 | 2 | class Handler implements IHandler { |
3 | - protected $pdo; |
|
4 | - protected $args; |
|
3 | + protected $pdo; |
|
4 | + protected $args; |
|
5 | 5 | |
6 | - public function __construct($args) { |
|
7 | - $this->pdo = Db::pdo(); |
|
8 | - $this->args = $args; |
|
9 | - } |
|
6 | + public function __construct($args) { |
|
7 | + $this->pdo = Db::pdo(); |
|
8 | + $this->args = $args; |
|
9 | + } |
|
10 | 10 | |
11 | - public function csrf_ignore($method) { |
|
12 | - return true; |
|
13 | - } |
|
11 | + public function csrf_ignore($method) { |
|
12 | + return true; |
|
13 | + } |
|
14 | 14 | |
15 | - public function before($method) { |
|
16 | - return true; |
|
17 | - } |
|
15 | + public function before($method) { |
|
16 | + return true; |
|
17 | + } |
|
18 | 18 | |
19 | - public function after() { |
|
20 | - return true; |
|
21 | - } |
|
19 | + public function after() { |
|
20 | + return true; |
|
21 | + } |
|
22 | 22 | |
23 | 23 | } |
@@ -1,28 +1,28 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class Opml extends Handler_Protected { |
3 | 3 | |
4 | - public function csrf_ignore($method) { |
|
5 | - $csrf_ignored = array("export", "import"); |
|
4 | + public function csrf_ignore($method) { |
|
5 | + $csrf_ignored = array("export", "import"); |
|
6 | 6 | |
7 | - return array_search($method, $csrf_ignored) !== false; |
|
8 | - } |
|
7 | + return array_search($method, $csrf_ignored) !== false; |
|
8 | + } |
|
9 | 9 | |
10 | - public function export() { |
|
11 | - $output_name = "tt-rss_".date("Y-m-d").".opml"; |
|
12 | - $include_settings = $_REQUEST["include_settings"] == "1"; |
|
13 | - $owner_uid = $_SESSION["uid"]; |
|
10 | + public function export() { |
|
11 | + $output_name = "tt-rss_".date("Y-m-d").".opml"; |
|
12 | + $include_settings = $_REQUEST["include_settings"] == "1"; |
|
13 | + $owner_uid = $_SESSION["uid"]; |
|
14 | 14 | |
15 | - $rc = $this->opml_export($output_name, $owner_uid, false, $include_settings); |
|
15 | + $rc = $this->opml_export($output_name, $owner_uid, false, $include_settings); |
|
16 | 16 | |
17 | - return $rc; |
|
18 | - } |
|
17 | + return $rc; |
|
18 | + } |
|
19 | 19 | |
20 | - public function import() { |
|
21 | - $owner_uid = $_SESSION["uid"]; |
|
20 | + public function import() { |
|
21 | + $owner_uid = $_SESSION["uid"]; |
|
22 | 22 | |
23 | - header('Content-Type: text/html; charset=utf-8'); |
|
23 | + header('Content-Type: text/html; charset=utf-8'); |
|
24 | 24 | |
25 | - print "<html> |
|
25 | + print "<html> |
|
26 | 26 | <head> |
27 | 27 | ".stylesheet_tag("css/default.css")." |
28 | 28 | <title>".__("OPML Utility")."</title> |
@@ -31,177 +31,177 @@ discard block |
||
31 | 31 | <body class='claro ttrss_utility'> |
32 | 32 | <h1>".__('OPML Utility')."</h1><div class='content'>"; |
33 | 33 | |
34 | - Feeds::add_feed_category("Imported feeds"); |
|
34 | + Feeds::add_feed_category("Imported feeds"); |
|
35 | 35 | |
36 | - $this->opml_notice(__("Importing OPML...")); |
|
36 | + $this->opml_notice(__("Importing OPML...")); |
|
37 | 37 | |
38 | - $this->opml_import($owner_uid); |
|
38 | + $this->opml_import($owner_uid); |
|
39 | 39 | |
40 | - print "<br><form method=\"GET\" action=\"prefs.php\"> |
|
40 | + print "<br><form method=\"GET\" action=\"prefs.php\"> |
|
41 | 41 | <input type=\"submit\" value=\"".__("Return to preferences")."\"> |
42 | 42 | </form>"; |
43 | 43 | |
44 | - print "</div></body></html>"; |
|
44 | + print "</div></body></html>"; |
|
45 | 45 | |
46 | 46 | |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | - // Export |
|
49 | + // Export |
|
50 | 50 | |
51 | - private function opml_export_category($owner_uid, $cat_id, $hide_private_feeds = false, $include_settings = true) { |
|
51 | + private function opml_export_category($owner_uid, $cat_id, $hide_private_feeds = false, $include_settings = true) { |
|
52 | 52 | |
53 | - $cat_id = (int) $cat_id; |
|
53 | + $cat_id = (int) $cat_id; |
|
54 | 54 | |
55 | - if ($hide_private_feeds) |
|
56 | - $hide_qpart = "(private IS false AND auth_login = '' AND auth_pass = '')"; |
|
57 | - else |
|
58 | - $hide_qpart = "true"; |
|
55 | + if ($hide_private_feeds) |
|
56 | + $hide_qpart = "(private IS false AND auth_login = '' AND auth_pass = '')"; |
|
57 | + else |
|
58 | + $hide_qpart = "true"; |
|
59 | 59 | |
60 | - $out = ""; |
|
60 | + $out = ""; |
|
61 | 61 | |
62 | - $ttrss_specific_qpart = ""; |
|
62 | + $ttrss_specific_qpart = ""; |
|
63 | 63 | |
64 | - if ($cat_id) { |
|
65 | - $sth = $this->pdo->prepare("SELECT title,order_id |
|
64 | + if ($cat_id) { |
|
65 | + $sth = $this->pdo->prepare("SELECT title,order_id |
|
66 | 66 | FROM ttrss_feed_categories WHERE id = ? |
67 | 67 | AND owner_uid = ?"); |
68 | - $sth->execute([$cat_id, $owner_uid]); |
|
69 | - $row = $sth->fetch(); |
|
70 | - $cat_title = htmlspecialchars($row['title']); |
|
68 | + $sth->execute([$cat_id, $owner_uid]); |
|
69 | + $row = $sth->fetch(); |
|
70 | + $cat_title = htmlspecialchars($row['title']); |
|
71 | 71 | |
72 | - if ($include_settings) { |
|
73 | - $order_id = (int)$row["order_id"]; |
|
74 | - $ttrss_specific_qpart = "ttrssSortOrder=\"$order_id\""; |
|
75 | - } |
|
76 | - } else { |
|
77 | - $cat_title = ""; |
|
78 | - } |
|
72 | + if ($include_settings) { |
|
73 | + $order_id = (int)$row["order_id"]; |
|
74 | + $ttrss_specific_qpart = "ttrssSortOrder=\"$order_id\""; |
|
75 | + } |
|
76 | + } else { |
|
77 | + $cat_title = ""; |
|
78 | + } |
|
79 | 79 | |
80 | - if ($cat_title) $out .= "<outline text=\"$cat_title\" $ttrss_specific_qpart>\n"; |
|
80 | + if ($cat_title) $out .= "<outline text=\"$cat_title\" $ttrss_specific_qpart>\n"; |
|
81 | 81 | |
82 | - $sth = $this->pdo->prepare("SELECT id,title |
|
82 | + $sth = $this->pdo->prepare("SELECT id,title |
|
83 | 83 | FROM ttrss_feed_categories WHERE |
84 | 84 | (parent_cat = :cat OR (:cat = 0 AND parent_cat IS NULL)) AND |
85 | 85 | owner_uid = :uid ORDER BY order_id, title"); |
86 | 86 | |
87 | - $sth->execute([':cat' => $cat_id, ':uid' => $owner_uid]); |
|
87 | + $sth->execute([':cat' => $cat_id, ':uid' => $owner_uid]); |
|
88 | 88 | |
89 | - while ($line = $sth->fetch()) { |
|
90 | - $out .= $this->opml_export_category($owner_uid, $line["id"], $hide_private_feeds, $include_settings); |
|
91 | - } |
|
89 | + while ($line = $sth->fetch()) { |
|
90 | + $out .= $this->opml_export_category($owner_uid, $line["id"], $hide_private_feeds, $include_settings); |
|
91 | + } |
|
92 | 92 | |
93 | - $fsth = $this->pdo->prepare("select title, feed_url, site_url, update_interval, order_id |
|
93 | + $fsth = $this->pdo->prepare("select title, feed_url, site_url, update_interval, order_id |
|
94 | 94 | FROM ttrss_feeds WHERE |
95 | 95 | (cat_id = :cat OR (:cat = 0 AND cat_id IS NULL)) AND owner_uid = :uid AND $hide_qpart |
96 | 96 | ORDER BY order_id, title"); |
97 | 97 | |
98 | - $fsth->execute([':cat' => $cat_id, ':uid' => $owner_uid]); |
|
98 | + $fsth->execute([':cat' => $cat_id, ':uid' => $owner_uid]); |
|
99 | 99 | |
100 | - while ($fline = $fsth->fetch()) { |
|
101 | - $title = htmlspecialchars($fline["title"]); |
|
102 | - $url = htmlspecialchars($fline["feed_url"]); |
|
103 | - $site_url = htmlspecialchars($fline["site_url"]); |
|
100 | + while ($fline = $fsth->fetch()) { |
|
101 | + $title = htmlspecialchars($fline["title"]); |
|
102 | + $url = htmlspecialchars($fline["feed_url"]); |
|
103 | + $site_url = htmlspecialchars($fline["site_url"]); |
|
104 | 104 | |
105 | - if ($include_settings) { |
|
106 | - $update_interval = (int)$fline["update_interval"]; |
|
107 | - $order_id = (int)$fline["order_id"]; |
|
105 | + if ($include_settings) { |
|
106 | + $update_interval = (int)$fline["update_interval"]; |
|
107 | + $order_id = (int)$fline["order_id"]; |
|
108 | 108 | |
109 | - $ttrss_specific_qpart = "ttrssSortOrder=\"$order_id\" ttrssUpdateInterval=\"$update_interval\""; |
|
110 | - } else { |
|
111 | - $ttrss_specific_qpart = ""; |
|
112 | - } |
|
109 | + $ttrss_specific_qpart = "ttrssSortOrder=\"$order_id\" ttrssUpdateInterval=\"$update_interval\""; |
|
110 | + } else { |
|
111 | + $ttrss_specific_qpart = ""; |
|
112 | + } |
|
113 | 113 | |
114 | - if ($site_url) { |
|
115 | - $html_url_qpart = "htmlUrl=\"$site_url\""; |
|
116 | - } else { |
|
117 | - $html_url_qpart = ""; |
|
118 | - } |
|
114 | + if ($site_url) { |
|
115 | + $html_url_qpart = "htmlUrl=\"$site_url\""; |
|
116 | + } else { |
|
117 | + $html_url_qpart = ""; |
|
118 | + } |
|
119 | 119 | |
120 | - $out .= "<outline type=\"rss\" text=\"$title\" xmlUrl=\"$url\" $ttrss_specific_qpart $html_url_qpart/>\n"; |
|
121 | - } |
|
120 | + $out .= "<outline type=\"rss\" text=\"$title\" xmlUrl=\"$url\" $ttrss_specific_qpart $html_url_qpart/>\n"; |
|
121 | + } |
|
122 | 122 | |
123 | - if ($cat_title) $out .= "</outline>\n"; |
|
123 | + if ($cat_title) $out .= "</outline>\n"; |
|
124 | 124 | |
125 | - return $out; |
|
126 | - } |
|
125 | + return $out; |
|
126 | + } |
|
127 | 127 | |
128 | - public function opml_export($name, $owner_uid, $hide_private_feeds = false, $include_settings = true) { |
|
129 | - if (!$owner_uid) return; |
|
128 | + public function opml_export($name, $owner_uid, $hide_private_feeds = false, $include_settings = true) { |
|
129 | + if (!$owner_uid) return; |
|
130 | 130 | |
131 | - if (!isset($_REQUEST["debug"])) { |
|
132 | - header("Content-type: application/xml+opml"); |
|
133 | - header("Content-Disposition: attachment; filename=" . $name ); |
|
134 | - } else { |
|
135 | - header("Content-type: text/xml"); |
|
136 | - } |
|
131 | + if (!isset($_REQUEST["debug"])) { |
|
132 | + header("Content-type: application/xml+opml"); |
|
133 | + header("Content-Disposition: attachment; filename=" . $name ); |
|
134 | + } else { |
|
135 | + header("Content-type: text/xml"); |
|
136 | + } |
|
137 | 137 | |
138 | - $out = "<?xml version=\"1.0\" encoding=\"utf-8\"?".">"; |
|
138 | + $out = "<?xml version=\"1.0\" encoding=\"utf-8\"?".">"; |
|
139 | 139 | |
140 | - $out .= "<opml version=\"1.0\">"; |
|
141 | - $out .= "<head> |
|
140 | + $out .= "<opml version=\"1.0\">"; |
|
141 | + $out .= "<head> |
|
142 | 142 | <dateCreated>" . date("r", time()) . "</dateCreated> |
143 | 143 | <title>Tiny Tiny RSS Feed Export</title> |
144 | 144 | </head>"; |
145 | - $out .= "<body>"; |
|
145 | + $out .= "<body>"; |
|
146 | 146 | |
147 | - $out .= $this->opml_export_category($owner_uid, 0, $hide_private_feeds, $include_settings); |
|
147 | + $out .= $this->opml_export_category($owner_uid, 0, $hide_private_feeds, $include_settings); |
|
148 | 148 | |
149 | - # export tt-rss settings |
|
149 | + # export tt-rss settings |
|
150 | 150 | |
151 | - if ($include_settings) { |
|
152 | - $out .= "<outline text=\"tt-rss-prefs\" schema-version=\"".SCHEMA_VERSION."\">"; |
|
151 | + if ($include_settings) { |
|
152 | + $out .= "<outline text=\"tt-rss-prefs\" schema-version=\"".SCHEMA_VERSION."\">"; |
|
153 | 153 | |
154 | - $sth = $this->pdo->prepare("SELECT pref_name, value FROM ttrss_user_prefs WHERE |
|
154 | + $sth = $this->pdo->prepare("SELECT pref_name, value FROM ttrss_user_prefs WHERE |
|
155 | 155 | profile IS NULL AND owner_uid = ? ORDER BY pref_name"); |
156 | - $sth->execute([$owner_uid]); |
|
156 | + $sth->execute([$owner_uid]); |
|
157 | 157 | |
158 | - while ($line = $sth->fetch()) { |
|
159 | - $name = $line["pref_name"]; |
|
160 | - $value = htmlspecialchars($line["value"]); |
|
158 | + while ($line = $sth->fetch()) { |
|
159 | + $name = $line["pref_name"]; |
|
160 | + $value = htmlspecialchars($line["value"]); |
|
161 | 161 | |
162 | - $out .= "<outline pref-name=\"$name\" value=\"$value\"/>"; |
|
163 | - } |
|
162 | + $out .= "<outline pref-name=\"$name\" value=\"$value\"/>"; |
|
163 | + } |
|
164 | 164 | |
165 | - $out .= "</outline>"; |
|
165 | + $out .= "</outline>"; |
|
166 | 166 | |
167 | - $out .= "<outline text=\"tt-rss-labels\" schema-version=\"".SCHEMA_VERSION."\">"; |
|
167 | + $out .= "<outline text=\"tt-rss-labels\" schema-version=\"".SCHEMA_VERSION."\">"; |
|
168 | 168 | |
169 | - $sth = $this->pdo->prepare("SELECT * FROM ttrss_labels2 WHERE |
|
169 | + $sth = $this->pdo->prepare("SELECT * FROM ttrss_labels2 WHERE |
|
170 | 170 | owner_uid = ?"); |
171 | - $sth->execute([$owner_uid]); |
|
171 | + $sth->execute([$owner_uid]); |
|
172 | 172 | |
173 | - while ($line = $sth->fetch()) { |
|
174 | - $name = htmlspecialchars($line['caption']); |
|
175 | - $fg_color = htmlspecialchars($line['fg_color']); |
|
176 | - $bg_color = htmlspecialchars($line['bg_color']); |
|
173 | + while ($line = $sth->fetch()) { |
|
174 | + $name = htmlspecialchars($line['caption']); |
|
175 | + $fg_color = htmlspecialchars($line['fg_color']); |
|
176 | + $bg_color = htmlspecialchars($line['bg_color']); |
|
177 | 177 | |
178 | - $out .= "<outline label-name=\"$name\" label-fg-color=\"$fg_color\" label-bg-color=\"$bg_color\"/>"; |
|
178 | + $out .= "<outline label-name=\"$name\" label-fg-color=\"$fg_color\" label-bg-color=\"$bg_color\"/>"; |
|
179 | 179 | |
180 | - } |
|
180 | + } |
|
181 | 181 | |
182 | - $out .= "</outline>"; |
|
182 | + $out .= "</outline>"; |
|
183 | 183 | |
184 | - $out .= "<outline text=\"tt-rss-filters\" schema-version=\"".SCHEMA_VERSION."\">"; |
|
184 | + $out .= "<outline text=\"tt-rss-filters\" schema-version=\"".SCHEMA_VERSION."\">"; |
|
185 | 185 | |
186 | - $sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2 |
|
186 | + $sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2 |
|
187 | 187 | WHERE owner_uid = ? ORDER BY id"); |
188 | - $sth->execute([$owner_uid]); |
|
188 | + $sth->execute([$owner_uid]); |
|
189 | 189 | |
190 | - while ($line = $sth->fetch()) { |
|
191 | - $line["rules"] = array(); |
|
192 | - $line["actions"] = array(); |
|
190 | + while ($line = $sth->fetch()) { |
|
191 | + $line["rules"] = array(); |
|
192 | + $line["actions"] = array(); |
|
193 | 193 | |
194 | - $tmph = $this->pdo->prepare("SELECT * FROM ttrss_filters2_rules |
|
194 | + $tmph = $this->pdo->prepare("SELECT * FROM ttrss_filters2_rules |
|
195 | 195 | WHERE filter_id = ?"); |
196 | - $tmph->execute([$line['id']]); |
|
196 | + $tmph->execute([$line['id']]); |
|
197 | 197 | |
198 | - while ($tmp_line = $tmph->fetch(PDO::FETCH_ASSOC)) { |
|
199 | - unset($tmp_line["id"]); |
|
200 | - unset($tmp_line["filter_id"]); |
|
198 | + while ($tmp_line = $tmph->fetch(PDO::FETCH_ASSOC)) { |
|
199 | + unset($tmp_line["id"]); |
|
200 | + unset($tmp_line["filter_id"]); |
|
201 | 201 | |
202 | - $cat_filter = $tmp_line["cat_filter"]; |
|
202 | + $cat_filter = $tmp_line["cat_filter"]; |
|
203 | 203 | |
204 | - if (!$tmp_line["match_on"]) { |
|
204 | + if (!$tmp_line["match_on"]) { |
|
205 | 205 | if ($cat_filter && $tmp_line["cat_id"] || $tmp_line["feed_id"]) { |
206 | 206 | $tmp_line["feed"] = Feeds::getFeedTitle( |
207 | 207 | $cat_filter ? $tmp_line["cat_id"] : $tmp_line["feed_id"], |
@@ -210,8 +210,8 @@ discard block |
||
210 | 210 | $tmp_line["feed"] = ""; |
211 | 211 | } |
212 | 212 | } else { |
213 | - $match = []; |
|
214 | - foreach (json_decode($tmp_line["match_on"], true) as $feed_id) { |
|
213 | + $match = []; |
|
214 | + foreach (json_decode($tmp_line["match_on"], true) as $feed_id) { |
|
215 | 215 | |
216 | 216 | if (strpos($feed_id, "CAT:") === 0) { |
217 | 217 | $feed_id = (int)substr($feed_id, 4); |
@@ -230,56 +230,56 @@ discard block |
||
230 | 230 | } |
231 | 231 | |
232 | 232 | $tmp_line["match"] = $match; |
233 | - unset($tmp_line["match_on"]); |
|
233 | + unset($tmp_line["match_on"]); |
|
234 | 234 | } |
235 | 235 | |
236 | - unset($tmp_line["feed_id"]); |
|
237 | - unset($tmp_line["cat_id"]); |
|
236 | + unset($tmp_line["feed_id"]); |
|
237 | + unset($tmp_line["cat_id"]); |
|
238 | 238 | |
239 | - array_push($line["rules"], $tmp_line); |
|
240 | - } |
|
239 | + array_push($line["rules"], $tmp_line); |
|
240 | + } |
|
241 | 241 | |
242 | - $tmph = $this->pdo->prepare("SELECT * FROM ttrss_filters2_actions |
|
242 | + $tmph = $this->pdo->prepare("SELECT * FROM ttrss_filters2_actions |
|
243 | 243 | WHERE filter_id = ?"); |
244 | - $tmph->execute([$line['id']]); |
|
244 | + $tmph->execute([$line['id']]); |
|
245 | 245 | |
246 | - while ($tmp_line = $tmph->fetch(PDO::FETCH_ASSOC)) { |
|
247 | - unset($tmp_line["id"]); |
|
248 | - unset($tmp_line["filter_id"]); |
|
246 | + while ($tmp_line = $tmph->fetch(PDO::FETCH_ASSOC)) { |
|
247 | + unset($tmp_line["id"]); |
|
248 | + unset($tmp_line["filter_id"]); |
|
249 | 249 | |
250 | - array_push($line["actions"], $tmp_line); |
|
251 | - } |
|
250 | + array_push($line["actions"], $tmp_line); |
|
251 | + } |
|
252 | 252 | |
253 | - unset($line["id"]); |
|
254 | - unset($line["owner_uid"]); |
|
255 | - $filter = json_encode($line); |
|
253 | + unset($line["id"]); |
|
254 | + unset($line["owner_uid"]); |
|
255 | + $filter = json_encode($line); |
|
256 | 256 | |
257 | - $out .= "<outline filter-type=\"2\"><![CDATA[$filter]]></outline>"; |
|
257 | + $out .= "<outline filter-type=\"2\"><![CDATA[$filter]]></outline>"; |
|
258 | 258 | |
259 | - } |
|
259 | + } |
|
260 | 260 | |
261 | 261 | |
262 | - $out .= "</outline>"; |
|
263 | - } |
|
262 | + $out .= "</outline>"; |
|
263 | + } |
|
264 | 264 | |
265 | - $out .= "</body></opml>"; |
|
265 | + $out .= "</body></opml>"; |
|
266 | 266 | |
267 | - // Format output. |
|
268 | - $doc = new DOMDocument(); |
|
269 | - $doc->formatOutput = true; |
|
270 | - $doc->preserveWhiteSpace = false; |
|
271 | - $doc->loadXML($out); |
|
267 | + // Format output. |
|
268 | + $doc = new DOMDocument(); |
|
269 | + $doc->formatOutput = true; |
|
270 | + $doc->preserveWhiteSpace = false; |
|
271 | + $doc->loadXML($out); |
|
272 | 272 | |
273 | - $xpath = new DOMXpath($doc); |
|
274 | - $outlines = $xpath->query("//outline[@title]"); |
|
273 | + $xpath = new DOMXpath($doc); |
|
274 | + $outlines = $xpath->query("//outline[@title]"); |
|
275 | 275 | |
276 | - // cleanup empty categories |
|
277 | - foreach ($outlines as $node) { |
|
278 | - if ($node->getElementsByTagName('outline')->length == 0) |
|
279 | - $node->parentNode->removeChild($node); |
|
280 | - } |
|
276 | + // cleanup empty categories |
|
277 | + foreach ($outlines as $node) { |
|
278 | + if ($node->getElementsByTagName('outline')->length == 0) |
|
279 | + $node->parentNode->removeChild($node); |
|
280 | + } |
|
281 | 281 | |
282 | - $res = $doc->saveXML(); |
|
282 | + $res = $doc->saveXML(); |
|
283 | 283 | |
284 | 284 | /* // saveXML uses a two-space indent. Change to tabs. |
285 | 285 | $res = preg_replace_callback('/^(?: )+/mu', |
@@ -288,128 +288,128 @@ discard block |
||
288 | 288 | 'return str_repeat("\t", intval(strlen($matches[0])/2));'), |
289 | 289 | $res); */ |
290 | 290 | |
291 | - print $res; |
|
292 | - } |
|
291 | + print $res; |
|
292 | + } |
|
293 | 293 | |
294 | - // Import |
|
294 | + // Import |
|
295 | 295 | |
296 | - private function opml_import_feed($node, $cat_id, $owner_uid) { |
|
297 | - $attrs = $node->attributes; |
|
296 | + private function opml_import_feed($node, $cat_id, $owner_uid) { |
|
297 | + $attrs = $node->attributes; |
|
298 | 298 | |
299 | - $feed_title = mb_substr($attrs->getNamedItem('text')->nodeValue, 0, 250); |
|
300 | - if (!$feed_title) $feed_title = mb_substr($attrs->getNamedItem('title')->nodeValue, 0, 250); |
|
299 | + $feed_title = mb_substr($attrs->getNamedItem('text')->nodeValue, 0, 250); |
|
300 | + if (!$feed_title) $feed_title = mb_substr($attrs->getNamedItem('title')->nodeValue, 0, 250); |
|
301 | 301 | |
302 | - $feed_url = $attrs->getNamedItem('xmlUrl')->nodeValue; |
|
303 | - if (!$feed_url) $feed_url = $attrs->getNamedItem('xmlURL')->nodeValue; |
|
302 | + $feed_url = $attrs->getNamedItem('xmlUrl')->nodeValue; |
|
303 | + if (!$feed_url) $feed_url = $attrs->getNamedItem('xmlURL')->nodeValue; |
|
304 | 304 | |
305 | - $site_url = mb_substr($attrs->getNamedItem('htmlUrl')->nodeValue, 0, 250); |
|
305 | + $site_url = mb_substr($attrs->getNamedItem('htmlUrl')->nodeValue, 0, 250); |
|
306 | 306 | |
307 | - if ($feed_url) { |
|
308 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
307 | + if ($feed_url) { |
|
308 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
309 | 309 | feed_url = ? AND owner_uid = ?"); |
310 | - $sth->execute([$feed_url, $owner_uid]); |
|
310 | + $sth->execute([$feed_url, $owner_uid]); |
|
311 | 311 | |
312 | - if (!$feed_title) $feed_title = '[Unknown]'; |
|
312 | + if (!$feed_title) $feed_title = '[Unknown]'; |
|
313 | 313 | |
314 | - if (!$sth->fetch()) { |
|
315 | - #$this->opml_notice("[FEED] [$feed_title/$feed_url] dst_CAT=$cat_id"); |
|
316 | - $this->opml_notice(T_sprintf("Adding feed: %s", $feed_title == '[Unknown]' ? $feed_url : $feed_title)); |
|
314 | + if (!$sth->fetch()) { |
|
315 | + #$this->opml_notice("[FEED] [$feed_title/$feed_url] dst_CAT=$cat_id"); |
|
316 | + $this->opml_notice(T_sprintf("Adding feed: %s", $feed_title == '[Unknown]' ? $feed_url : $feed_title)); |
|
317 | 317 | |
318 | - if (!$cat_id) $cat_id = null; |
|
318 | + if (!$cat_id) $cat_id = null; |
|
319 | 319 | |
320 | - $update_interval = (int) $attrs->getNamedItem('ttrssUpdateInterval')->nodeValue; |
|
321 | - if (!$update_interval) $update_interval = 0; |
|
320 | + $update_interval = (int) $attrs->getNamedItem('ttrssUpdateInterval')->nodeValue; |
|
321 | + if (!$update_interval) $update_interval = 0; |
|
322 | 322 | |
323 | - $order_id = (int) $attrs->getNamedItem('ttrssSortOrder')->nodeValue; |
|
324 | - if (!$order_id) $order_id = 0; |
|
323 | + $order_id = (int) $attrs->getNamedItem('ttrssSortOrder')->nodeValue; |
|
324 | + if (!$order_id) $order_id = 0; |
|
325 | 325 | |
326 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
326 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
327 | 327 | (title, feed_url, owner_uid, cat_id, site_url, order_id, update_interval) VALUES |
328 | 328 | (?, ?, ?, ?, ?, ?, ?)"); |
329 | 329 | |
330 | - $sth->execute([$feed_title, $feed_url, $owner_uid, $cat_id, $site_url, $order_id, $update_interval]); |
|
330 | + $sth->execute([$feed_title, $feed_url, $owner_uid, $cat_id, $site_url, $order_id, $update_interval]); |
|
331 | 331 | |
332 | - } else { |
|
333 | - $this->opml_notice(T_sprintf("Duplicate feed: %s", $feed_title == '[Unknown]' ? $feed_url : $feed_title)); |
|
334 | - } |
|
335 | - } |
|
336 | - } |
|
332 | + } else { |
|
333 | + $this->opml_notice(T_sprintf("Duplicate feed: %s", $feed_title == '[Unknown]' ? $feed_url : $feed_title)); |
|
334 | + } |
|
335 | + } |
|
336 | + } |
|
337 | 337 | |
338 | - private function opml_import_label($node, $owner_uid) { |
|
339 | - $attrs = $node->attributes; |
|
340 | - $label_name = $attrs->getNamedItem('label-name')->nodeValue; |
|
338 | + private function opml_import_label($node, $owner_uid) { |
|
339 | + $attrs = $node->attributes; |
|
340 | + $label_name = $attrs->getNamedItem('label-name')->nodeValue; |
|
341 | 341 | |
342 | - if ($label_name) { |
|
343 | - $fg_color = $attrs->getNamedItem('label-fg-color')->nodeValue; |
|
344 | - $bg_color = $attrs->getNamedItem('label-bg-color')->nodeValue; |
|
342 | + if ($label_name) { |
|
343 | + $fg_color = $attrs->getNamedItem('label-fg-color')->nodeValue; |
|
344 | + $bg_color = $attrs->getNamedItem('label-bg-color')->nodeValue; |
|
345 | 345 | |
346 | - if (!Labels::find_id($label_name, $_SESSION['uid'])) { |
|
347 | - $this->opml_notice(T_sprintf("Adding label %s", htmlspecialchars($label_name))); |
|
348 | - Labels::create($label_name, $fg_color, $bg_color, $owner_uid); |
|
349 | - } else { |
|
350 | - $this->opml_notice(T_sprintf("Duplicate label: %s", htmlspecialchars($label_name))); |
|
351 | - } |
|
352 | - } |
|
353 | - } |
|
346 | + if (!Labels::find_id($label_name, $_SESSION['uid'])) { |
|
347 | + $this->opml_notice(T_sprintf("Adding label %s", htmlspecialchars($label_name))); |
|
348 | + Labels::create($label_name, $fg_color, $bg_color, $owner_uid); |
|
349 | + } else { |
|
350 | + $this->opml_notice(T_sprintf("Duplicate label: %s", htmlspecialchars($label_name))); |
|
351 | + } |
|
352 | + } |
|
353 | + } |
|
354 | 354 | |
355 | - private function opml_import_preference($node) { |
|
356 | - $attrs = $node->attributes; |
|
357 | - $pref_name = $attrs->getNamedItem('pref-name')->nodeValue; |
|
355 | + private function opml_import_preference($node) { |
|
356 | + $attrs = $node->attributes; |
|
357 | + $pref_name = $attrs->getNamedItem('pref-name')->nodeValue; |
|
358 | 358 | |
359 | - if ($pref_name) { |
|
360 | - $pref_value = $attrs->getNamedItem('value')->nodeValue; |
|
359 | + if ($pref_name) { |
|
360 | + $pref_value = $attrs->getNamedItem('value')->nodeValue; |
|
361 | 361 | |
362 | - $this->opml_notice(T_sprintf("Setting preference key %s to %s", |
|
363 | - $pref_name, $pref_value)); |
|
362 | + $this->opml_notice(T_sprintf("Setting preference key %s to %s", |
|
363 | + $pref_name, $pref_value)); |
|
364 | 364 | |
365 | - set_pref($pref_name, $pref_value); |
|
366 | - } |
|
367 | - } |
|
365 | + set_pref($pref_name, $pref_value); |
|
366 | + } |
|
367 | + } |
|
368 | 368 | |
369 | - private function opml_import_filter($node) { |
|
370 | - $attrs = $node->attributes; |
|
369 | + private function opml_import_filter($node) { |
|
370 | + $attrs = $node->attributes; |
|
371 | 371 | |
372 | - $filter_type = $attrs->getNamedItem('filter-type')->nodeValue; |
|
372 | + $filter_type = $attrs->getNamedItem('filter-type')->nodeValue; |
|
373 | 373 | |
374 | - if ($filter_type == '2') { |
|
375 | - $filter = json_decode($node->nodeValue, true); |
|
374 | + if ($filter_type == '2') { |
|
375 | + $filter = json_decode($node->nodeValue, true); |
|
376 | 376 | |
377 | - if ($filter) { |
|
378 | - $match_any_rule = bool_to_sql_bool($filter["match_any_rule"]); |
|
379 | - $enabled = bool_to_sql_bool($filter["enabled"]); |
|
380 | - $inverse = bool_to_sql_bool($filter["inverse"]); |
|
381 | - $title = $filter["title"]; |
|
377 | + if ($filter) { |
|
378 | + $match_any_rule = bool_to_sql_bool($filter["match_any_rule"]); |
|
379 | + $enabled = bool_to_sql_bool($filter["enabled"]); |
|
380 | + $inverse = bool_to_sql_bool($filter["inverse"]); |
|
381 | + $title = $filter["title"]; |
|
382 | 382 | |
383 | - //print "F: $title, $inverse, $enabled, $match_any_rule"; |
|
383 | + //print "F: $title, $inverse, $enabled, $match_any_rule"; |
|
384 | 384 | |
385 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_filters2 (match_any_rule,enabled,inverse,title,owner_uid) |
|
385 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_filters2 (match_any_rule,enabled,inverse,title,owner_uid) |
|
386 | 386 | VALUES (?, ?, ?, ?, ?)"); |
387 | 387 | |
388 | - $sth->execute([$match_any_rule, $enabled, $inverse, $title, $_SESSION['uid']]); |
|
388 | + $sth->execute([$match_any_rule, $enabled, $inverse, $title, $_SESSION['uid']]); |
|
389 | 389 | |
390 | - $sth = $this->pdo->prepare("SELECT MAX(id) AS id FROM ttrss_filters2 WHERE |
|
390 | + $sth = $this->pdo->prepare("SELECT MAX(id) AS id FROM ttrss_filters2 WHERE |
|
391 | 391 | owner_uid = ?"); |
392 | - $sth->execute([$_SESSION['uid']]); |
|
392 | + $sth->execute([$_SESSION['uid']]); |
|
393 | 393 | |
394 | - $row = $sth->fetch(); |
|
395 | - $filter_id = $row['id']; |
|
394 | + $row = $sth->fetch(); |
|
395 | + $filter_id = $row['id']; |
|
396 | 396 | |
397 | - if ($filter_id) { |
|
398 | - $this->opml_notice(T_sprintf("Adding filter %s...", $title)); |
|
397 | + if ($filter_id) { |
|
398 | + $this->opml_notice(T_sprintf("Adding filter %s...", $title)); |
|
399 | 399 | |
400 | - foreach ($filter["rules"] as $rule) { |
|
401 | - $feed_id = null; |
|
402 | - $cat_id = null; |
|
400 | + foreach ($filter["rules"] as $rule) { |
|
401 | + $feed_id = null; |
|
402 | + $cat_id = null; |
|
403 | 403 | |
404 | - if ($rule["match"]) { |
|
404 | + if ($rule["match"]) { |
|
405 | 405 | |
406 | 406 | $match_on = []; |
407 | 407 | |
408 | - foreach ($rule["match"] as $match) { |
|
409 | - list ($name, $is_cat, $is_id) = $match; |
|
408 | + foreach ($rule["match"] as $match) { |
|
409 | + list ($name, $is_cat, $is_id) = $match; |
|
410 | 410 | |
411 | - if ($is_id) { |
|
412 | - array_push($match_on, ($is_cat ? "CAT:" : "") . $name); |
|
411 | + if ($is_id) { |
|
412 | + array_push($match_on, ($is_cat ? "CAT:" : "") . $name); |
|
413 | 413 | } else { |
414 | 414 | |
415 | 415 | if (!$is_cat) { |
@@ -421,18 +421,18 @@ discard block |
||
421 | 421 | if ($row = $tsth->fetch()) { |
422 | 422 | $match_id = $row['id']; |
423 | 423 | |
424 | - array_push($match_on, $match_id); |
|
424 | + array_push($match_on, $match_id); |
|
425 | 425 | } |
426 | 426 | } else { |
427 | 427 | $tsth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories |
428 | 428 | WHERE title = ? AND owner_uid = ?"); |
429 | - $tsth->execute([$name, $_SESSION['uid']]); |
|
429 | + $tsth->execute([$name, $_SESSION['uid']]); |
|
430 | 430 | |
431 | - if ($row = $tsth->fetch()) { |
|
432 | - $match_id = $row['id']; |
|
431 | + if ($row = $tsth->fetch()) { |
|
432 | + $match_id = $row['id']; |
|
433 | 433 | |
434 | - array_push($match_on, "CAT:$match_id"); |
|
435 | - } |
|
434 | + array_push($match_on, "CAT:$match_id"); |
|
435 | + } |
|
436 | 436 | } |
437 | 437 | } |
438 | 438 | } |
@@ -460,14 +460,14 @@ discard block |
||
460 | 460 | $feed_id = $row['id']; |
461 | 461 | } |
462 | 462 | } else { |
463 | - $tsth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories |
|
463 | + $tsth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories |
|
464 | 464 | WHERE title = ? AND owner_uid = ?"); |
465 | 465 | |
466 | - $tsth->execute([$rule['feed'], $_SESSION['uid']]); |
|
466 | + $tsth->execute([$rule['feed'], $_SESSION['uid']]); |
|
467 | 467 | |
468 | - if ($row = $tsth->fetch()) { |
|
469 | - $feed_id = $row['id']; |
|
470 | - } |
|
468 | + if ($row = $tsth->fetch()) { |
|
469 | + $feed_id = $row['id']; |
|
470 | + } |
|
471 | 471 | } |
472 | 472 | |
473 | 473 | $cat_filter = bool_to_sql_bool($rule["cat_filter"]); |
@@ -481,174 +481,174 @@ discard block |
||
481 | 481 | (?, ?, ?, ?, ?, ?, ?)"); |
482 | 482 | $usth->execute([$feed_id, $cat_id, $filter_id, $filter_type, $reg_exp, $cat_filter, $inverse]); |
483 | 483 | } |
484 | - } |
|
484 | + } |
|
485 | 485 | |
486 | - foreach ($filter["actions"] as $action) { |
|
486 | + foreach ($filter["actions"] as $action) { |
|
487 | 487 | |
488 | - $action_id = (int)$action["action_id"]; |
|
489 | - $action_param = $action["action_param"]; |
|
488 | + $action_id = (int)$action["action_id"]; |
|
489 | + $action_param = $action["action_param"]; |
|
490 | 490 | |
491 | - $usth = $this->pdo->prepare("INSERT INTO ttrss_filters2_actions |
|
491 | + $usth = $this->pdo->prepare("INSERT INTO ttrss_filters2_actions |
|
492 | 492 | (filter_id,action_id,action_param) |
493 | 493 | VALUES |
494 | 494 | (?, ?, ?)"); |
495 | - $usth->execute([$filter_id, $action_id, $action_param]); |
|
496 | - } |
|
497 | - } |
|
498 | - } |
|
499 | - } |
|
500 | - } |
|
501 | - |
|
502 | - private function opml_import_category($doc, $root_node, $owner_uid, $parent_id) { |
|
503 | - $default_cat_id = (int) $this->get_feed_category('Imported feeds', false); |
|
504 | - |
|
505 | - if ($root_node) { |
|
506 | - $cat_title = mb_substr($root_node->attributes->getNamedItem('text')->nodeValue, 0, 250); |
|
507 | - |
|
508 | - if (!$cat_title) |
|
509 | - $cat_title = mb_substr($root_node->attributes->getNamedItem('title')->nodeValue, 0, 250); |
|
510 | - |
|
511 | - if (!in_array($cat_title, array("tt-rss-filters", "tt-rss-labels", "tt-rss-prefs"))) { |
|
512 | - $cat_id = $this->get_feed_category($cat_title, $parent_id); |
|
513 | - |
|
514 | - if ($cat_id === false) { |
|
515 | - $order_id = (int) $root_node->attributes->getNamedItem('ttrssSortOrder')->nodeValue; |
|
516 | - if (!$order_id) $order_id = 0; |
|
517 | - |
|
518 | - Feeds::add_feed_category($cat_title, $parent_id, $order_id); |
|
519 | - $cat_id = $this->get_feed_category($cat_title, $parent_id); |
|
520 | - } |
|
521 | - |
|
522 | - } else { |
|
523 | - $cat_id = 0; |
|
524 | - } |
|
525 | - |
|
526 | - $outlines = $root_node->childNodes; |
|
527 | - |
|
528 | - } else { |
|
529 | - $xpath = new DOMXpath($doc); |
|
530 | - $outlines = $xpath->query("//opml/body/outline"); |
|
531 | - |
|
532 | - $cat_id = 0; |
|
533 | - } |
|
534 | - |
|
535 | - #$this->opml_notice("[CAT] $cat_title id: $cat_id P_id: $parent_id"); |
|
536 | - $this->opml_notice(T_sprintf("Processing category: %s", $cat_title ? $cat_title : __("Uncategorized"))); |
|
537 | - |
|
538 | - foreach ($outlines as $node) { |
|
539 | - if ($node->hasAttributes() && strtolower($node->tagName) == "outline") { |
|
540 | - $attrs = $node->attributes; |
|
541 | - $node_cat_title = $attrs->getNamedItem('text')->nodeValue; |
|
542 | - |
|
543 | - if (!$node_cat_title) |
|
544 | - $node_cat_title = $attrs->getNamedItem('title')->nodeValue; |
|
545 | - |
|
546 | - $node_feed_url = $attrs->getNamedItem('xmlUrl')->nodeValue; |
|
547 | - |
|
548 | - if ($node_cat_title && !$node_feed_url) { |
|
549 | - $this->opml_import_category($doc, $node, $owner_uid, $cat_id); |
|
550 | - } else { |
|
551 | - |
|
552 | - if (!$cat_id) { |
|
553 | - $dst_cat_id = $default_cat_id; |
|
554 | - } else { |
|
555 | - $dst_cat_id = $cat_id; |
|
556 | - } |
|
557 | - |
|
558 | - switch ($cat_title) { |
|
559 | - case "tt-rss-prefs": |
|
560 | - $this->opml_import_preference($node); |
|
561 | - break; |
|
562 | - case "tt-rss-labels": |
|
563 | - $this->opml_import_label($node, $owner_uid); |
|
564 | - break; |
|
565 | - case "tt-rss-filters": |
|
566 | - $this->opml_import_filter($node); |
|
567 | - break; |
|
568 | - default: |
|
569 | - $this->opml_import_feed($node, $dst_cat_id, $owner_uid); |
|
570 | - } |
|
571 | - } |
|
572 | - } |
|
573 | - } |
|
574 | - } |
|
575 | - |
|
576 | - public function opml_import($owner_uid) { |
|
577 | - if (!$owner_uid) return; |
|
578 | - |
|
579 | - $doc = false; |
|
580 | - |
|
581 | - if ($_FILES['opml_file']['error'] != 0) { |
|
582 | - print_error(T_sprintf("Upload failed with error code %d", |
|
583 | - $_FILES['opml_file']['error'])); |
|
584 | - return; |
|
585 | - } |
|
586 | - |
|
587 | - if (is_uploaded_file($_FILES['opml_file']['tmp_name'])) { |
|
588 | - $tmp_file = tempnam(CACHE_DIR . '/upload', 'opml'); |
|
589 | - |
|
590 | - $result = move_uploaded_file($_FILES['opml_file']['tmp_name'], |
|
591 | - $tmp_file); |
|
592 | - |
|
593 | - if (!$result) { |
|
594 | - print_error(__("Unable to move uploaded file.")); |
|
595 | - return; |
|
596 | - } |
|
597 | - } else { |
|
598 | - print_error(__('Error: please upload OPML file.')); |
|
599 | - return; |
|
600 | - } |
|
601 | - |
|
602 | - if (is_file($tmp_file)) { |
|
603 | - $doc = new DOMDocument(); |
|
604 | - libxml_disable_entity_loader(false); |
|
605 | - $doc->load($tmp_file); |
|
606 | - libxml_disable_entity_loader(true); |
|
607 | - unlink($tmp_file); |
|
608 | - } else if (!$doc) { |
|
609 | - print_error(__('Error: unable to find moved OPML file.')); |
|
610 | - return; |
|
611 | - } |
|
612 | - |
|
613 | - if ($doc) { |
|
614 | - $this->pdo->beginTransaction(); |
|
615 | - $this->opml_import_category($doc, false, $owner_uid, false); |
|
616 | - $this->pdo->commit(); |
|
617 | - } else { |
|
618 | - print_error(__('Error while parsing document.')); |
|
619 | - } |
|
620 | - } |
|
621 | - |
|
622 | - private function opml_notice($msg) { |
|
623 | - print "$msg<br/>"; |
|
624 | - } |
|
625 | - |
|
626 | - public static function opml_publish_url(){ |
|
627 | - |
|
628 | - $url_path = get_self_url_prefix(); |
|
629 | - $url_path .= "/opml.php?op=publish&key=" . |
|
630 | - Feeds::get_feed_access_key('OPML:Publish', false, $_SESSION["uid"]); |
|
631 | - |
|
632 | - return $url_path; |
|
633 | - } |
|
634 | - |
|
635 | - public function get_feed_category($feed_cat, $parent_cat_id = false) { |
|
636 | - |
|
637 | - $parent_cat_id = (int) $parent_cat_id; |
|
638 | - |
|
639 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories |
|
495 | + $usth->execute([$filter_id, $action_id, $action_param]); |
|
496 | + } |
|
497 | + } |
|
498 | + } |
|
499 | + } |
|
500 | + } |
|
501 | + |
|
502 | + private function opml_import_category($doc, $root_node, $owner_uid, $parent_id) { |
|
503 | + $default_cat_id = (int) $this->get_feed_category('Imported feeds', false); |
|
504 | + |
|
505 | + if ($root_node) { |
|
506 | + $cat_title = mb_substr($root_node->attributes->getNamedItem('text')->nodeValue, 0, 250); |
|
507 | + |
|
508 | + if (!$cat_title) |
|
509 | + $cat_title = mb_substr($root_node->attributes->getNamedItem('title')->nodeValue, 0, 250); |
|
510 | + |
|
511 | + if (!in_array($cat_title, array("tt-rss-filters", "tt-rss-labels", "tt-rss-prefs"))) { |
|
512 | + $cat_id = $this->get_feed_category($cat_title, $parent_id); |
|
513 | + |
|
514 | + if ($cat_id === false) { |
|
515 | + $order_id = (int) $root_node->attributes->getNamedItem('ttrssSortOrder')->nodeValue; |
|
516 | + if (!$order_id) $order_id = 0; |
|
517 | + |
|
518 | + Feeds::add_feed_category($cat_title, $parent_id, $order_id); |
|
519 | + $cat_id = $this->get_feed_category($cat_title, $parent_id); |
|
520 | + } |
|
521 | + |
|
522 | + } else { |
|
523 | + $cat_id = 0; |
|
524 | + } |
|
525 | + |
|
526 | + $outlines = $root_node->childNodes; |
|
527 | + |
|
528 | + } else { |
|
529 | + $xpath = new DOMXpath($doc); |
|
530 | + $outlines = $xpath->query("//opml/body/outline"); |
|
531 | + |
|
532 | + $cat_id = 0; |
|
533 | + } |
|
534 | + |
|
535 | + #$this->opml_notice("[CAT] $cat_title id: $cat_id P_id: $parent_id"); |
|
536 | + $this->opml_notice(T_sprintf("Processing category: %s", $cat_title ? $cat_title : __("Uncategorized"))); |
|
537 | + |
|
538 | + foreach ($outlines as $node) { |
|
539 | + if ($node->hasAttributes() && strtolower($node->tagName) == "outline") { |
|
540 | + $attrs = $node->attributes; |
|
541 | + $node_cat_title = $attrs->getNamedItem('text')->nodeValue; |
|
542 | + |
|
543 | + if (!$node_cat_title) |
|
544 | + $node_cat_title = $attrs->getNamedItem('title')->nodeValue; |
|
545 | + |
|
546 | + $node_feed_url = $attrs->getNamedItem('xmlUrl')->nodeValue; |
|
547 | + |
|
548 | + if ($node_cat_title && !$node_feed_url) { |
|
549 | + $this->opml_import_category($doc, $node, $owner_uid, $cat_id); |
|
550 | + } else { |
|
551 | + |
|
552 | + if (!$cat_id) { |
|
553 | + $dst_cat_id = $default_cat_id; |
|
554 | + } else { |
|
555 | + $dst_cat_id = $cat_id; |
|
556 | + } |
|
557 | + |
|
558 | + switch ($cat_title) { |
|
559 | + case "tt-rss-prefs": |
|
560 | + $this->opml_import_preference($node); |
|
561 | + break; |
|
562 | + case "tt-rss-labels": |
|
563 | + $this->opml_import_label($node, $owner_uid); |
|
564 | + break; |
|
565 | + case "tt-rss-filters": |
|
566 | + $this->opml_import_filter($node); |
|
567 | + break; |
|
568 | + default: |
|
569 | + $this->opml_import_feed($node, $dst_cat_id, $owner_uid); |
|
570 | + } |
|
571 | + } |
|
572 | + } |
|
573 | + } |
|
574 | + } |
|
575 | + |
|
576 | + public function opml_import($owner_uid) { |
|
577 | + if (!$owner_uid) return; |
|
578 | + |
|
579 | + $doc = false; |
|
580 | + |
|
581 | + if ($_FILES['opml_file']['error'] != 0) { |
|
582 | + print_error(T_sprintf("Upload failed with error code %d", |
|
583 | + $_FILES['opml_file']['error'])); |
|
584 | + return; |
|
585 | + } |
|
586 | + |
|
587 | + if (is_uploaded_file($_FILES['opml_file']['tmp_name'])) { |
|
588 | + $tmp_file = tempnam(CACHE_DIR . '/upload', 'opml'); |
|
589 | + |
|
590 | + $result = move_uploaded_file($_FILES['opml_file']['tmp_name'], |
|
591 | + $tmp_file); |
|
592 | + |
|
593 | + if (!$result) { |
|
594 | + print_error(__("Unable to move uploaded file.")); |
|
595 | + return; |
|
596 | + } |
|
597 | + } else { |
|
598 | + print_error(__('Error: please upload OPML file.')); |
|
599 | + return; |
|
600 | + } |
|
601 | + |
|
602 | + if (is_file($tmp_file)) { |
|
603 | + $doc = new DOMDocument(); |
|
604 | + libxml_disable_entity_loader(false); |
|
605 | + $doc->load($tmp_file); |
|
606 | + libxml_disable_entity_loader(true); |
|
607 | + unlink($tmp_file); |
|
608 | + } else if (!$doc) { |
|
609 | + print_error(__('Error: unable to find moved OPML file.')); |
|
610 | + return; |
|
611 | + } |
|
612 | + |
|
613 | + if ($doc) { |
|
614 | + $this->pdo->beginTransaction(); |
|
615 | + $this->opml_import_category($doc, false, $owner_uid, false); |
|
616 | + $this->pdo->commit(); |
|
617 | + } else { |
|
618 | + print_error(__('Error while parsing document.')); |
|
619 | + } |
|
620 | + } |
|
621 | + |
|
622 | + private function opml_notice($msg) { |
|
623 | + print "$msg<br/>"; |
|
624 | + } |
|
625 | + |
|
626 | + public static function opml_publish_url(){ |
|
627 | + |
|
628 | + $url_path = get_self_url_prefix(); |
|
629 | + $url_path .= "/opml.php?op=publish&key=" . |
|
630 | + Feeds::get_feed_access_key('OPML:Publish', false, $_SESSION["uid"]); |
|
631 | + |
|
632 | + return $url_path; |
|
633 | + } |
|
634 | + |
|
635 | + public function get_feed_category($feed_cat, $parent_cat_id = false) { |
|
636 | + |
|
637 | + $parent_cat_id = (int) $parent_cat_id; |
|
638 | + |
|
639 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories |
|
640 | 640 | WHERE title = :title |
641 | 641 | AND (parent_cat = :parent OR (:parent = 0 AND parent_cat IS NULL)) |
642 | 642 | AND owner_uid = :uid"); |
643 | 643 | |
644 | - $sth->execute([':title' => $feed_cat, ':parent' => $parent_cat_id, ':uid' => $_SESSION['uid']]); |
|
644 | + $sth->execute([':title' => $feed_cat, ':parent' => $parent_cat_id, ':uid' => $_SESSION['uid']]); |
|
645 | 645 | |
646 | - if ($row = $sth->fetch()) { |
|
647 | - return $row['id']; |
|
648 | - } else { |
|
649 | - return false; |
|
650 | - } |
|
651 | - } |
|
646 | + if ($row = $sth->fetch()) { |
|
647 | + return $row['id']; |
|
648 | + } else { |
|
649 | + return false; |
|
650 | + } |
|
651 | + } |
|
652 | 652 | |
653 | 653 | |
654 | 654 | } |
@@ -1,130 +1,130 @@ |
||
1 | 1 | <?php |
2 | - set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR . |
|
3 | - get_include_path()); |
|
4 | - |
|
5 | - $op = $_REQUEST["op"]; |
|
6 | - @$method = $_REQUEST['subop'] ? $_REQUEST['subop'] : $_REQUEST["method"]; |
|
7 | - |
|
8 | - if (!$method) |
|
9 | - $method = 'index'; |
|
10 | - else |
|
11 | - $method = strtolower($method); |
|
12 | - |
|
13 | - /* Public calls compatibility shim */ |
|
14 | - |
|
15 | - $public_calls = array("globalUpdateFeeds", "rss", "getUnread", "getProfiles", "share", |
|
16 | - "fbexport", "logout", "pubsub"); |
|
17 | - |
|
18 | - if (array_search($op, $public_calls) !== false) { |
|
19 | - header("Location: public.php?" . $_SERVER['QUERY_STRING']); |
|
20 | - return; |
|
21 | - } |
|
22 | - |
|
23 | - @$csrf_token = $_REQUEST['csrf_token']; |
|
24 | - |
|
25 | - require_once "autoload.php"; |
|
26 | - require_once "sessions.php"; |
|
27 | - require_once "functions.php"; |
|
28 | - require_once "config.php"; |
|
29 | - require_once "db.php"; |
|
30 | - require_once "db-prefs.php"; |
|
31 | - |
|
32 | - startup_gettext(); |
|
33 | - |
|
34 | - $script_started = microtime(true); |
|
35 | - |
|
36 | - if (!init_plugins()) return; |
|
37 | - |
|
38 | - header("Content-Type: text/json; charset=utf-8"); |
|
39 | - |
|
40 | - if (ENABLE_GZIP_OUTPUT && function_exists("ob_gzhandler")) { |
|
41 | - ob_start("ob_gzhandler"); |
|
42 | - } |
|
43 | - |
|
44 | - if (SINGLE_USER_MODE) { |
|
45 | - authenticate_user( "admin", null); |
|
46 | - } |
|
47 | - |
|
48 | - if ($_SESSION["uid"]) { |
|
49 | - if (!validate_session()) { |
|
50 | - header("Content-Type: text/json"); |
|
51 | - print error_json(6); |
|
52 | - return; |
|
53 | - } |
|
54 | - load_user_plugins( $_SESSION["uid"]); |
|
55 | - } |
|
56 | - |
|
57 | - $purge_intervals = array( |
|
58 | - 0 => __("Use default"), |
|
59 | - -1 => __("Never purge"), |
|
60 | - 5 => __("1 week old"), |
|
61 | - 14 => __("2 weeks old"), |
|
62 | - 31 => __("1 month old"), |
|
63 | - 60 => __("2 months old"), |
|
64 | - 90 => __("3 months old")); |
|
65 | - |
|
66 | - $update_intervals = array( |
|
67 | - 0 => __("Default interval"), |
|
68 | - -1 => __("Disable updates"), |
|
69 | - 15 => __("15 minutes"), |
|
70 | - 30 => __("30 minutes"), |
|
71 | - 60 => __("Hourly"), |
|
72 | - 240 => __("4 hours"), |
|
73 | - 720 => __("12 hours"), |
|
74 | - 1440 => __("Daily"), |
|
75 | - 10080 => __("Weekly")); |
|
76 | - |
|
77 | - $update_intervals_nodefault = array( |
|
78 | - -1 => __("Disable updates"), |
|
79 | - 15 => __("15 minutes"), |
|
80 | - 30 => __("30 minutes"), |
|
81 | - 60 => __("Hourly"), |
|
82 | - 240 => __("4 hours"), |
|
83 | - 720 => __("12 hours"), |
|
84 | - 1440 => __("Daily"), |
|
85 | - 10080 => __("Weekly")); |
|
86 | - |
|
87 | - $access_level_names = array( |
|
88 | - 0 => __("User"), |
|
89 | - 5 => __("Power User"), |
|
90 | - 10 => __("Administrator")); |
|
91 | - |
|
92 | - $op = str_replace("-", "_", $op); |
|
93 | - |
|
94 | - $override = PluginHost::getInstance()->lookup_handler($op, $method); |
|
95 | - |
|
96 | - if (class_exists($op) || $override) { |
|
97 | - |
|
98 | - if ($override) { |
|
99 | - $handler = $override; |
|
100 | - } else { |
|
101 | - $handler = new $op($_REQUEST); |
|
102 | - } |
|
103 | - |
|
104 | - if ($handler && implements_interface($handler, 'IHandler')) { |
|
105 | - if (validate_csrf($csrf_token) || $handler->csrf_ignore($method)) { |
|
106 | - if ($handler->before($method)) { |
|
107 | - if ($method && method_exists($handler, $method)) { |
|
108 | - $handler->$method(); |
|
109 | - } else { |
|
110 | - if (method_exists($handler, "catchall")) { |
|
111 | - $handler->catchall($method); |
|
112 | - } |
|
113 | - } |
|
114 | - $handler->after(); |
|
115 | - return; |
|
116 | - } else { |
|
117 | - header("Content-Type: text/json"); |
|
118 | - print error_json(6); |
|
119 | - return; |
|
120 | - } |
|
121 | - } else { |
|
122 | - header("Content-Type: text/json"); |
|
123 | - print error_json(6); |
|
124 | - return; |
|
125 | - } |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - header("Content-Type: text/json"); |
|
130 | - print error_json(13); |
|
2 | + set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR . |
|
3 | + get_include_path()); |
|
4 | + |
|
5 | + $op = $_REQUEST["op"]; |
|
6 | + @$method = $_REQUEST['subop'] ? $_REQUEST['subop'] : $_REQUEST["method"]; |
|
7 | + |
|
8 | + if (!$method) |
|
9 | + $method = 'index'; |
|
10 | + else |
|
11 | + $method = strtolower($method); |
|
12 | + |
|
13 | + /* Public calls compatibility shim */ |
|
14 | + |
|
15 | + $public_calls = array("globalUpdateFeeds", "rss", "getUnread", "getProfiles", "share", |
|
16 | + "fbexport", "logout", "pubsub"); |
|
17 | + |
|
18 | + if (array_search($op, $public_calls) !== false) { |
|
19 | + header("Location: public.php?" . $_SERVER['QUERY_STRING']); |
|
20 | + return; |
|
21 | + } |
|
22 | + |
|
23 | + @$csrf_token = $_REQUEST['csrf_token']; |
|
24 | + |
|
25 | + require_once "autoload.php"; |
|
26 | + require_once "sessions.php"; |
|
27 | + require_once "functions.php"; |
|
28 | + require_once "config.php"; |
|
29 | + require_once "db.php"; |
|
30 | + require_once "db-prefs.php"; |
|
31 | + |
|
32 | + startup_gettext(); |
|
33 | + |
|
34 | + $script_started = microtime(true); |
|
35 | + |
|
36 | + if (!init_plugins()) return; |
|
37 | + |
|
38 | + header("Content-Type: text/json; charset=utf-8"); |
|
39 | + |
|
40 | + if (ENABLE_GZIP_OUTPUT && function_exists("ob_gzhandler")) { |
|
41 | + ob_start("ob_gzhandler"); |
|
42 | + } |
|
43 | + |
|
44 | + if (SINGLE_USER_MODE) { |
|
45 | + authenticate_user( "admin", null); |
|
46 | + } |
|
47 | + |
|
48 | + if ($_SESSION["uid"]) { |
|
49 | + if (!validate_session()) { |
|
50 | + header("Content-Type: text/json"); |
|
51 | + print error_json(6); |
|
52 | + return; |
|
53 | + } |
|
54 | + load_user_plugins( $_SESSION["uid"]); |
|
55 | + } |
|
56 | + |
|
57 | + $purge_intervals = array( |
|
58 | + 0 => __("Use default"), |
|
59 | + -1 => __("Never purge"), |
|
60 | + 5 => __("1 week old"), |
|
61 | + 14 => __("2 weeks old"), |
|
62 | + 31 => __("1 month old"), |
|
63 | + 60 => __("2 months old"), |
|
64 | + 90 => __("3 months old")); |
|
65 | + |
|
66 | + $update_intervals = array( |
|
67 | + 0 => __("Default interval"), |
|
68 | + -1 => __("Disable updates"), |
|
69 | + 15 => __("15 minutes"), |
|
70 | + 30 => __("30 minutes"), |
|
71 | + 60 => __("Hourly"), |
|
72 | + 240 => __("4 hours"), |
|
73 | + 720 => __("12 hours"), |
|
74 | + 1440 => __("Daily"), |
|
75 | + 10080 => __("Weekly")); |
|
76 | + |
|
77 | + $update_intervals_nodefault = array( |
|
78 | + -1 => __("Disable updates"), |
|
79 | + 15 => __("15 minutes"), |
|
80 | + 30 => __("30 minutes"), |
|
81 | + 60 => __("Hourly"), |
|
82 | + 240 => __("4 hours"), |
|
83 | + 720 => __("12 hours"), |
|
84 | + 1440 => __("Daily"), |
|
85 | + 10080 => __("Weekly")); |
|
86 | + |
|
87 | + $access_level_names = array( |
|
88 | + 0 => __("User"), |
|
89 | + 5 => __("Power User"), |
|
90 | + 10 => __("Administrator")); |
|
91 | + |
|
92 | + $op = str_replace("-", "_", $op); |
|
93 | + |
|
94 | + $override = PluginHost::getInstance()->lookup_handler($op, $method); |
|
95 | + |
|
96 | + if (class_exists($op) || $override) { |
|
97 | + |
|
98 | + if ($override) { |
|
99 | + $handler = $override; |
|
100 | + } else { |
|
101 | + $handler = new $op($_REQUEST); |
|
102 | + } |
|
103 | + |
|
104 | + if ($handler && implements_interface($handler, 'IHandler')) { |
|
105 | + if (validate_csrf($csrf_token) || $handler->csrf_ignore($method)) { |
|
106 | + if ($handler->before($method)) { |
|
107 | + if ($method && method_exists($handler, $method)) { |
|
108 | + $handler->$method(); |
|
109 | + } else { |
|
110 | + if (method_exists($handler, "catchall")) { |
|
111 | + $handler->catchall($method); |
|
112 | + } |
|
113 | + } |
|
114 | + $handler->after(); |
|
115 | + return; |
|
116 | + } else { |
|
117 | + header("Content-Type: text/json"); |
|
118 | + print error_json(6); |
|
119 | + return; |
|
120 | + } |
|
121 | + } else { |
|
122 | + header("Content-Type: text/json"); |
|
123 | + print error_json(6); |
|
124 | + return; |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + header("Content-Type: text/json"); |
|
130 | + print error_json(13); |
@@ -1,38 +1,38 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | function db_escape_string($s, $strip_tags = true) { |
4 | - return Db::get()->escape_string($s, $strip_tags); |
|
4 | + return Db::get()->escape_string($s, $strip_tags); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | function db_query($query, $die_on_error = true) { |
8 | - return Db::get()->query($query, $die_on_error); |
|
8 | + return Db::get()->query($query, $die_on_error); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | function db_fetch_assoc($result) { |
12 | - return Db::get()->fetch_assoc($result); |
|
12 | + return Db::get()->fetch_assoc($result); |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | |
16 | 16 | function db_num_rows($result) { |
17 | - return Db::get()->num_rows($result); |
|
17 | + return Db::get()->num_rows($result); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | function db_fetch_result($result, $row, $param) { |
21 | - return Db::get()->fetch_result($result, $row, $param); |
|
21 | + return Db::get()->fetch_result($result, $row, $param); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | function db_affected_rows($result) { |
25 | - return Db::get()->affected_rows($result); |
|
25 | + return Db::get()->affected_rows($result); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | function db_last_error() { |
29 | - return Db::get()->last_error(); |
|
29 | + return Db::get()->last_error(); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | function db_last_query_error() { |
33 | - return Db::get()->last_query_error(); |
|
33 | + return Db::get()->last_query_error(); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | function db_quote($str){ |
37 | - return Db::get()->quote($str); |
|
37 | + return Db::get()->quote($str); |
|
38 | 38 | } |
@@ -7,15 +7,15 @@ |
||
7 | 7 | <link rel="shortcut icon" type="image/png" href="images/favicon.png"> |
8 | 8 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
9 | 9 | <?php |
10 | - foreach (array("lib/prototype.js", |
|
11 | - "lib/dojo/dojo.js", |
|
12 | - "lib/dojo/tt-rss-layer.js", |
|
13 | - "js/common.js", |
|
14 | - "errors.php?mode=js") as $jsfile) { |
|
10 | + foreach (array("lib/prototype.js", |
|
11 | + "lib/dojo/dojo.js", |
|
12 | + "lib/dojo/tt-rss-layer.js", |
|
13 | + "js/common.js", |
|
14 | + "errors.php?mode=js") as $jsfile) { |
|
15 | 15 | |
16 | - echo javascript_tag($jsfile); |
|
16 | + echo javascript_tag($jsfile); |
|
17 | 17 | |
18 | - } ?> |
|
18 | + } ?> |
|
19 | 19 | |
20 | 20 | <script type="text/javascript"> |
21 | 21 | require({cache:{}}); |