@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | private $dir; |
4 | 4 | |
5 | 5 | public function __construct($dir) { |
6 | - $this->dir = CACHE_DIR . "/" . clean_filename($dir); |
|
6 | + $this->dir = CACHE_DIR."/".clean_filename($dir); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | public function getDir() { |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | public function getFullPath($filename) { |
42 | 42 | $filename = clean_filename($filename); |
43 | 43 | |
44 | - return $this->dir . "/" . $filename; |
|
44 | + return $this->dir."/".$filename; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | public function put($filename, $data) { |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | } |
74 | 74 | |
75 | 75 | public function getUrl($filename) { |
76 | - return get_self_url_prefix() . "/public.php?op=cached_url&file=" . basename($this->dir) . "/" . $filename; |
|
76 | + return get_self_url_prefix()."/public.php?op=cached_url&file=".basename($this->dir)."/".$filename; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | // check for locally cached (media) URLs and rewrite to local versions |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | if (!$res) return ''; |
86 | 86 | |
87 | 87 | $doc = new DOMDocument(); |
88 | - if ($doc->loadHTML('<?xml encoding="UTF-8">' . $res)) { |
|
88 | + if ($doc->loadHTML('<?xml encoding="UTF-8">'.$res)) { |
|
89 | 89 | $xpath = new DOMXPath($doc); |
90 | 90 | $cache = new DiskCache("images"); |
91 | 91 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | } |
127 | 127 | |
128 | 128 | public static function expire() { |
129 | - $dirs = array_filter(glob(CACHE_DIR . "/*"), "is_dir"); |
|
129 | + $dirs = array_filter(glob(CACHE_DIR."/*"), "is_dir"); |
|
130 | 130 | |
131 | 131 | foreach ($dirs as $cache_dir) { |
132 | 132 | $num_deleted = 0; |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | |
137 | 137 | if ($files) { |
138 | 138 | foreach ($files as $file) { |
139 | - if (time() - filemtime($file) > 86400*CACHE_MAX_DAYS) { |
|
139 | + if (time() - filemtime($file) > 86400 * CACHE_MAX_DAYS) { |
|
140 | 140 | unlink($file); |
141 | 141 | |
142 | 142 | ++$num_deleted; |
@@ -18,10 +18,11 @@ discard block |
||
18 | 18 | |
19 | 19 | public function isWritable($filename = "") { |
20 | 20 | if ($filename) { |
21 | - if (file_exists($this->getFullPath($filename))) |
|
22 | - return is_writable($this->getFullPath($filename)); |
|
23 | - else |
|
24 | - return is_writable($this->dir); |
|
21 | + if (file_exists($this->getFullPath($filename))) { |
|
22 | + return is_writable($this->getFullPath($filename)); |
|
23 | + } else { |
|
24 | + return is_writable($this->dir); |
|
25 | + } |
|
25 | 26 | } else { |
26 | 27 | return is_writable($this->dir); |
27 | 28 | } |
@@ -32,10 +33,11 @@ discard block |
||
32 | 33 | } |
33 | 34 | |
34 | 35 | public function getSize($filename) { |
35 | - if ($this->exists($filename)) |
|
36 | - return filesize($this->getFullPath($filename)); |
|
37 | - else |
|
38 | - return -1; |
|
36 | + if ($this->exists($filename)) { |
|
37 | + return filesize($this->getFullPath($filename)); |
|
38 | + } else { |
|
39 | + return -1; |
|
40 | + } |
|
39 | 41 | } |
40 | 42 | |
41 | 43 | public function getFullPath($filename) { |
@@ -53,17 +55,19 @@ discard block |
||
53 | 55 | } |
54 | 56 | |
55 | 57 | public function get($filename) { |
56 | - if ($this->exists($filename)) |
|
57 | - return file_get_contents($this->getFullPath($filename)); |
|
58 | - else |
|
59 | - return null; |
|
58 | + if ($this->exists($filename)) { |
|
59 | + return file_get_contents($this->getFullPath($filename)); |
|
60 | + } else { |
|
61 | + return null; |
|
62 | + } |
|
60 | 63 | } |
61 | 64 | |
62 | 65 | public function getMimeType($filename) { |
63 | - if ($this->exists($filename)) |
|
64 | - return mime_content_type($this->getFullPath($filename)); |
|
65 | - else |
|
66 | - return null; |
|
66 | + if ($this->exists($filename)) { |
|
67 | + return mime_content_type($this->getFullPath($filename)); |
|
68 | + } else { |
|
69 | + return null; |
|
70 | + } |
|
67 | 71 | } |
68 | 72 | |
69 | 73 | public function send($filename) { |
@@ -82,7 +86,9 @@ discard block |
||
82 | 86 | static public function rewriteUrls($str) |
83 | 87 | { |
84 | 88 | $res = trim($str); |
85 | - if (!$res) return ''; |
|
89 | + if (!$res) { |
|
90 | + return ''; |
|
91 | + } |
|
86 | 92 | |
87 | 93 | $doc = new DOMDocument(); |
88 | 94 | if ($doc->loadHTML('<?xml encoding="UTF-8">' . $res)) { |
@@ -105,9 +111,9 @@ discard block |
||
105 | 111 | |
106 | 112 | $src = $cache->getUrl(sha1($src)); |
107 | 113 | |
108 | - if ($entry->hasAttribute('poster')) |
|
109 | - $entry->setAttribute('poster', $src); |
|
110 | - else { |
|
114 | + if ($entry->hasAttribute('poster')) { |
|
115 | + $entry->setAttribute('poster', $src); |
|
116 | + } else { |
|
111 | 117 | $entry->setAttribute('src', $src); |
112 | 118 | $entry->removeAttribute("srcset"); |
113 | 119 | } |
@@ -1,151 +1,151 @@ |
||
1 | 1 | <?php |
2 | 2 | class DiskCache { |
3 | - private $dir; |
|
4 | - |
|
5 | - public function __construct($dir) { |
|
6 | - $this->dir = CACHE_DIR . "/" . clean_filename($dir); |
|
7 | - } |
|
8 | - |
|
9 | - public function getDir() { |
|
10 | - return $this->dir; |
|
11 | - } |
|
12 | - |
|
13 | - public function makeDir() { |
|
14 | - if (!is_dir($this->dir)) { |
|
15 | - return mkdir($this->dir); |
|
16 | - } |
|
17 | - } |
|
18 | - |
|
19 | - public function isWritable($filename = "") { |
|
20 | - if ($filename) { |
|
21 | - if (file_exists($this->getFullPath($filename))) |
|
22 | - return is_writable($this->getFullPath($filename)); |
|
23 | - else |
|
24 | - return is_writable($this->dir); |
|
25 | - } else { |
|
26 | - return is_writable($this->dir); |
|
27 | - } |
|
28 | - } |
|
29 | - |
|
30 | - public function exists($filename) { |
|
31 | - return file_exists($this->getFullPath($filename)); |
|
32 | - } |
|
33 | - |
|
34 | - public function getSize($filename) { |
|
35 | - if ($this->exists($filename)) |
|
36 | - return filesize($this->getFullPath($filename)); |
|
37 | - else |
|
38 | - return -1; |
|
39 | - } |
|
40 | - |
|
41 | - public function getFullPath($filename) { |
|
42 | - $filename = clean_filename($filename); |
|
43 | - |
|
44 | - return $this->dir . "/" . $filename; |
|
45 | - } |
|
46 | - |
|
47 | - public function put($filename, $data) { |
|
48 | - return file_put_contents($this->getFullPath($filename), $data); |
|
49 | - } |
|
50 | - |
|
51 | - public function touch($filename) { |
|
52 | - return touch($this->getFullPath($filename)); |
|
53 | - } |
|
54 | - |
|
55 | - public function get($filename) { |
|
56 | - if ($this->exists($filename)) |
|
57 | - return file_get_contents($this->getFullPath($filename)); |
|
58 | - else |
|
59 | - return null; |
|
60 | - } |
|
61 | - |
|
62 | - public function getMimeType($filename) { |
|
63 | - if ($this->exists($filename)) |
|
64 | - return mime_content_type($this->getFullPath($filename)); |
|
65 | - else |
|
66 | - return null; |
|
67 | - } |
|
68 | - |
|
69 | - public function send($filename) { |
|
70 | - header("Content-Disposition: inline; filename=\"$filename\""); |
|
71 | - |
|
72 | - return send_local_file($this->getFullPath($filename)); |
|
73 | - } |
|
74 | - |
|
75 | - public function getUrl($filename) { |
|
76 | - return get_self_url_prefix() . "/public.php?op=cached_url&file=" . basename($this->dir) . "/" . $filename; |
|
77 | - } |
|
78 | - |
|
79 | - // check for locally cached (media) URLs and rewrite to local versions |
|
80 | - // this is called separately after sanitize() and plugin render article hooks to allow |
|
81 | - // plugins work on original source URLs used before caching |
|
82 | - static public function rewriteUrls($str) |
|
83 | - { |
|
84 | - $res = trim($str); |
|
85 | - if (!$res) return ''; |
|
86 | - |
|
87 | - $doc = new DOMDocument(); |
|
88 | - if ($doc->loadHTML('<?xml encoding="UTF-8">' . $res)) { |
|
89 | - $xpath = new DOMXPath($doc); |
|
90 | - $cache = new DiskCache("images"); |
|
91 | - |
|
92 | - $entries = $xpath->query('(//img[@src]|//picture/source[@src]|//video[@poster]|//video/source[@src]|//audio/source[@src])'); |
|
93 | - |
|
94 | - $need_saving = false; |
|
95 | - |
|
96 | - foreach ($entries as $entry) { |
|
97 | - |
|
98 | - if ($entry->hasAttribute('src') || $entry->hasAttribute('poster')) { |
|
99 | - |
|
100 | - // should be already absolutized because this is called after sanitize() |
|
101 | - $src = $entry->hasAttribute('poster') ? $entry->getAttribute('poster') : $entry->getAttribute('src'); |
|
102 | - $cached_filename = sha1($src); |
|
103 | - |
|
104 | - if ($cache->exists($cached_filename)) { |
|
105 | - |
|
106 | - $src = $cache->getUrl(sha1($src)); |
|
107 | - |
|
108 | - if ($entry->hasAttribute('poster')) |
|
109 | - $entry->setAttribute('poster', $src); |
|
110 | - else { |
|
111 | - $entry->setAttribute('src', $src); |
|
112 | - $entry->removeAttribute("srcset"); |
|
113 | - } |
|
114 | - |
|
115 | - $need_saving = true; |
|
116 | - } |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - if ($need_saving) { |
|
121 | - $doc->removeChild($doc->firstChild); //remove doctype |
|
122 | - $res = $doc->saveHTML(); |
|
123 | - } |
|
124 | - } |
|
125 | - return $res; |
|
126 | - } |
|
127 | - |
|
128 | - public static function expire() { |
|
129 | - $dirs = array_filter(glob(CACHE_DIR . "/*"), "is_dir"); |
|
130 | - |
|
131 | - foreach ($dirs as $cache_dir) { |
|
132 | - $num_deleted = 0; |
|
133 | - |
|
134 | - if (is_writable($cache_dir) && !file_exists("$cache_dir/.no-auto-expiry")) { |
|
135 | - $files = glob("$cache_dir/*"); |
|
136 | - |
|
137 | - if ($files) { |
|
138 | - foreach ($files as $file) { |
|
139 | - if (time() - filemtime($file) > 86400*CACHE_MAX_DAYS) { |
|
140 | - unlink($file); |
|
141 | - |
|
142 | - ++$num_deleted; |
|
143 | - } |
|
144 | - } |
|
145 | - } |
|
146 | - |
|
147 | - Debug::log("expired $cache_dir: removed $num_deleted files."); |
|
148 | - } |
|
149 | - } |
|
150 | - } |
|
3 | + private $dir; |
|
4 | + |
|
5 | + public function __construct($dir) { |
|
6 | + $this->dir = CACHE_DIR . "/" . clean_filename($dir); |
|
7 | + } |
|
8 | + |
|
9 | + public function getDir() { |
|
10 | + return $this->dir; |
|
11 | + } |
|
12 | + |
|
13 | + public function makeDir() { |
|
14 | + if (!is_dir($this->dir)) { |
|
15 | + return mkdir($this->dir); |
|
16 | + } |
|
17 | + } |
|
18 | + |
|
19 | + public function isWritable($filename = "") { |
|
20 | + if ($filename) { |
|
21 | + if (file_exists($this->getFullPath($filename))) |
|
22 | + return is_writable($this->getFullPath($filename)); |
|
23 | + else |
|
24 | + return is_writable($this->dir); |
|
25 | + } else { |
|
26 | + return is_writable($this->dir); |
|
27 | + } |
|
28 | + } |
|
29 | + |
|
30 | + public function exists($filename) { |
|
31 | + return file_exists($this->getFullPath($filename)); |
|
32 | + } |
|
33 | + |
|
34 | + public function getSize($filename) { |
|
35 | + if ($this->exists($filename)) |
|
36 | + return filesize($this->getFullPath($filename)); |
|
37 | + else |
|
38 | + return -1; |
|
39 | + } |
|
40 | + |
|
41 | + public function getFullPath($filename) { |
|
42 | + $filename = clean_filename($filename); |
|
43 | + |
|
44 | + return $this->dir . "/" . $filename; |
|
45 | + } |
|
46 | + |
|
47 | + public function put($filename, $data) { |
|
48 | + return file_put_contents($this->getFullPath($filename), $data); |
|
49 | + } |
|
50 | + |
|
51 | + public function touch($filename) { |
|
52 | + return touch($this->getFullPath($filename)); |
|
53 | + } |
|
54 | + |
|
55 | + public function get($filename) { |
|
56 | + if ($this->exists($filename)) |
|
57 | + return file_get_contents($this->getFullPath($filename)); |
|
58 | + else |
|
59 | + return null; |
|
60 | + } |
|
61 | + |
|
62 | + public function getMimeType($filename) { |
|
63 | + if ($this->exists($filename)) |
|
64 | + return mime_content_type($this->getFullPath($filename)); |
|
65 | + else |
|
66 | + return null; |
|
67 | + } |
|
68 | + |
|
69 | + public function send($filename) { |
|
70 | + header("Content-Disposition: inline; filename=\"$filename\""); |
|
71 | + |
|
72 | + return send_local_file($this->getFullPath($filename)); |
|
73 | + } |
|
74 | + |
|
75 | + public function getUrl($filename) { |
|
76 | + return get_self_url_prefix() . "/public.php?op=cached_url&file=" . basename($this->dir) . "/" . $filename; |
|
77 | + } |
|
78 | + |
|
79 | + // check for locally cached (media) URLs and rewrite to local versions |
|
80 | + // this is called separately after sanitize() and plugin render article hooks to allow |
|
81 | + // plugins work on original source URLs used before caching |
|
82 | + static public function rewriteUrls($str) |
|
83 | + { |
|
84 | + $res = trim($str); |
|
85 | + if (!$res) return ''; |
|
86 | + |
|
87 | + $doc = new DOMDocument(); |
|
88 | + if ($doc->loadHTML('<?xml encoding="UTF-8">' . $res)) { |
|
89 | + $xpath = new DOMXPath($doc); |
|
90 | + $cache = new DiskCache("images"); |
|
91 | + |
|
92 | + $entries = $xpath->query('(//img[@src]|//picture/source[@src]|//video[@poster]|//video/source[@src]|//audio/source[@src])'); |
|
93 | + |
|
94 | + $need_saving = false; |
|
95 | + |
|
96 | + foreach ($entries as $entry) { |
|
97 | + |
|
98 | + if ($entry->hasAttribute('src') || $entry->hasAttribute('poster')) { |
|
99 | + |
|
100 | + // should be already absolutized because this is called after sanitize() |
|
101 | + $src = $entry->hasAttribute('poster') ? $entry->getAttribute('poster') : $entry->getAttribute('src'); |
|
102 | + $cached_filename = sha1($src); |
|
103 | + |
|
104 | + if ($cache->exists($cached_filename)) { |
|
105 | + |
|
106 | + $src = $cache->getUrl(sha1($src)); |
|
107 | + |
|
108 | + if ($entry->hasAttribute('poster')) |
|
109 | + $entry->setAttribute('poster', $src); |
|
110 | + else { |
|
111 | + $entry->setAttribute('src', $src); |
|
112 | + $entry->removeAttribute("srcset"); |
|
113 | + } |
|
114 | + |
|
115 | + $need_saving = true; |
|
116 | + } |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + if ($need_saving) { |
|
121 | + $doc->removeChild($doc->firstChild); //remove doctype |
|
122 | + $res = $doc->saveHTML(); |
|
123 | + } |
|
124 | + } |
|
125 | + return $res; |
|
126 | + } |
|
127 | + |
|
128 | + public static function expire() { |
|
129 | + $dirs = array_filter(glob(CACHE_DIR . "/*"), "is_dir"); |
|
130 | + |
|
131 | + foreach ($dirs as $cache_dir) { |
|
132 | + $num_deleted = 0; |
|
133 | + |
|
134 | + if (is_writable($cache_dir) && !file_exists("$cache_dir/.no-auto-expiry")) { |
|
135 | + $files = glob("$cache_dir/*"); |
|
136 | + |
|
137 | + if ($files) { |
|
138 | + foreach ($files as $file) { |
|
139 | + if (time() - filemtime($file) > 86400*CACHE_MAX_DAYS) { |
|
140 | + unlink($file); |
|
141 | + |
|
142 | + ++$num_deleted; |
|
143 | + } |
|
144 | + } |
|
145 | + } |
|
146 | + |
|
147 | + Debug::log("expired $cache_dir: removed $num_deleted files."); |
|
148 | + } |
|
149 | + } |
|
150 | + } |
|
151 | 151 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $cat_title = htmlspecialchars($row['title']); |
71 | 71 | |
72 | 72 | if ($include_settings) { |
73 | - $order_id = (int)$row["order_id"]; |
|
73 | + $order_id = (int) $row["order_id"]; |
|
74 | 74 | $ttrss_specific_qpart = "ttrssSortOrder=\"$order_id\""; |
75 | 75 | } |
76 | 76 | } else { |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | $site_url = htmlspecialchars($fline["site_url"]); |
104 | 104 | |
105 | 105 | if ($include_settings) { |
106 | - $update_interval = (int)$fline["update_interval"]; |
|
107 | - $order_id = (int)$fline["order_id"]; |
|
106 | + $update_interval = (int) $fline["update_interval"]; |
|
107 | + $order_id = (int) $fline["order_id"]; |
|
108 | 108 | |
109 | 109 | $ttrss_specific_qpart = "ttrssSortOrder=\"$order_id\" ttrssUpdateInterval=\"$update_interval\""; |
110 | 110 | } else { |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | |
131 | 131 | if (!isset($_REQUEST["debug"])) { |
132 | 132 | header("Content-type: application/xml+opml"); |
133 | - header("Content-Disposition: attachment; filename=" . $name ); |
|
133 | + header("Content-Disposition: attachment; filename=".$name); |
|
134 | 134 | } else { |
135 | 135 | header("Content-type: text/xml"); |
136 | 136 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | |
140 | 140 | $out .= "<opml version=\"1.0\">"; |
141 | 141 | $out .= "<head> |
142 | - <dateCreated>" . date("r", time()) . "</dateCreated> |
|
142 | + <dateCreated>" . date("r", time())."</dateCreated> |
|
143 | 143 | <title>Tiny Tiny RSS Feed Export</title> |
144 | 144 | </head>"; |
145 | 145 | $out .= "<body>"; |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | foreach (json_decode($tmp_line["match_on"], true) as $feed_id) { |
215 | 215 | |
216 | 216 | if (strpos($feed_id, "CAT:") === 0) { |
217 | - $feed_id = (int)substr($feed_id, 4); |
|
217 | + $feed_id = (int) substr($feed_id, 4); |
|
218 | 218 | if ($feed_id) { |
219 | 219 | array_push($match, [Feeds::getCategoryTitle($feed_id), true, false]); |
220 | 220 | } else { |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | } |
223 | 223 | } else { |
224 | 224 | if ($feed_id) { |
225 | - array_push($match, [Feeds::getFeedTitle((int)$feed_id), false, false]); |
|
225 | + array_push($match, [Feeds::getFeedTitle((int) $feed_id), false, false]); |
|
226 | 226 | } else { |
227 | 227 | array_push($match, [0, false, true]); |
228 | 228 | } |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | list ($name, $is_cat, $is_id) = $match; |
410 | 410 | |
411 | 411 | if ($is_id) { |
412 | - array_push($match_on, ($is_cat ? "CAT:" : "") . $name); |
|
412 | + array_push($match_on, ($is_cat ? "CAT:" : "").$name); |
|
413 | 413 | } else { |
414 | 414 | |
415 | 415 | if (!$is_cat) { |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | } |
439 | 439 | |
440 | 440 | $reg_exp = $rule["reg_exp"]; |
441 | - $filter_type = (int)$rule["filter_type"]; |
|
441 | + $filter_type = (int) $rule["filter_type"]; |
|
442 | 442 | $inverse = bool_to_sql_bool($rule["inverse"]); |
443 | 443 | $match_on = json_encode($match_on); |
444 | 444 | |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | |
473 | 473 | $cat_filter = bool_to_sql_bool($rule["cat_filter"]); |
474 | 474 | $reg_exp = $rule["reg_exp"]; |
475 | - $filter_type = (int)$rule["filter_type"]; |
|
475 | + $filter_type = (int) $rule["filter_type"]; |
|
476 | 476 | $inverse = bool_to_sql_bool($rule["inverse"]); |
477 | 477 | |
478 | 478 | $usth = $this->pdo->prepare("INSERT INTO ttrss_filters2_rules |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | |
486 | 486 | foreach ($filter["actions"] as $action) { |
487 | 487 | |
488 | - $action_id = (int)$action["action_id"]; |
|
488 | + $action_id = (int) $action["action_id"]; |
|
489 | 489 | $action_param = $action["action_param"]; |
490 | 490 | |
491 | 491 | $usth = $this->pdo->prepare("INSERT INTO ttrss_filters2_actions |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | } |
586 | 586 | |
587 | 587 | if (is_uploaded_file($_FILES['opml_file']['tmp_name'])) { |
588 | - $tmp_file = tempnam(CACHE_DIR . '/upload', 'opml'); |
|
588 | + $tmp_file = tempnam(CACHE_DIR.'/upload', 'opml'); |
|
589 | 589 | |
590 | 590 | $result = move_uploaded_file($_FILES['opml_file']['tmp_name'], |
591 | 591 | $tmp_file); |
@@ -623,10 +623,10 @@ discard block |
||
623 | 623 | print "$msg<br/>"; |
624 | 624 | } |
625 | 625 | |
626 | - public static function opml_publish_url(){ |
|
626 | + public static function opml_publish_url() { |
|
627 | 627 | |
628 | 628 | $url_path = get_self_url_prefix(); |
629 | - $url_path .= "/opml.php?op=publish&key=" . |
|
629 | + $url_path .= "/opml.php?op=publish&key=". |
|
630 | 630 | Feeds::get_feed_access_key('OPML:Publish', false, $_SESSION["uid"]); |
631 | 631 | |
632 | 632 | return $url_path; |
@@ -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 | } |
@@ -52,10 +52,11 @@ discard block |
||
52 | 52 | |
53 | 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 | |
60 | 61 | $out = ""; |
61 | 62 | |
@@ -77,7 +78,9 @@ discard block |
||
77 | 78 | $cat_title = ""; |
78 | 79 | } |
79 | 80 | |
80 | - if ($cat_title) $out .= "<outline text=\"$cat_title\" $ttrss_specific_qpart>\n"; |
|
81 | + if ($cat_title) { |
|
82 | + $out .= "<outline text=\"$cat_title\" $ttrss_specific_qpart>\n"; |
|
83 | + } |
|
81 | 84 | |
82 | 85 | $sth = $this->pdo->prepare("SELECT id,title |
83 | 86 | FROM ttrss_feed_categories WHERE |
@@ -120,13 +123,17 @@ discard block |
||
120 | 123 | $out .= "<outline type=\"rss\" text=\"$title\" xmlUrl=\"$url\" $ttrss_specific_qpart $html_url_qpart/>\n"; |
121 | 124 | } |
122 | 125 | |
123 | - if ($cat_title) $out .= "</outline>\n"; |
|
126 | + if ($cat_title) { |
|
127 | + $out .= "</outline>\n"; |
|
128 | + } |
|
124 | 129 | |
125 | 130 | return $out; |
126 | 131 | } |
127 | 132 | |
128 | 133 | public function opml_export($name, $owner_uid, $hide_private_feeds = false, $include_settings = true) { |
129 | - if (!$owner_uid) return; |
|
134 | + if (!$owner_uid) { |
|
135 | + return; |
|
136 | + } |
|
130 | 137 | |
131 | 138 | if (!isset($_REQUEST["debug"])) { |
132 | 139 | header("Content-type: application/xml+opml"); |
@@ -275,8 +282,9 @@ discard block |
||
275 | 282 | |
276 | 283 | // cleanup empty categories |
277 | 284 | foreach ($outlines as $node) { |
278 | - if ($node->getElementsByTagName('outline')->length == 0) |
|
279 | - $node->parentNode->removeChild($node); |
|
285 | + if ($node->getElementsByTagName('outline')->length == 0) { |
|
286 | + $node->parentNode->removeChild($node); |
|
287 | + } |
|
280 | 288 | } |
281 | 289 | |
282 | 290 | $res = $doc->saveXML(); |
@@ -297,10 +305,14 @@ discard block |
||
297 | 305 | $attrs = $node->attributes; |
298 | 306 | |
299 | 307 | $feed_title = mb_substr($attrs->getNamedItem('text')->nodeValue, 0, 250); |
300 | - if (!$feed_title) $feed_title = mb_substr($attrs->getNamedItem('title')->nodeValue, 0, 250); |
|
308 | + if (!$feed_title) { |
|
309 | + $feed_title = mb_substr($attrs->getNamedItem('title')->nodeValue, 0, 250); |
|
310 | + } |
|
301 | 311 | |
302 | 312 | $feed_url = $attrs->getNamedItem('xmlUrl')->nodeValue; |
303 | - if (!$feed_url) $feed_url = $attrs->getNamedItem('xmlURL')->nodeValue; |
|
313 | + if (!$feed_url) { |
|
314 | + $feed_url = $attrs->getNamedItem('xmlURL')->nodeValue; |
|
315 | + } |
|
304 | 316 | |
305 | 317 | $site_url = mb_substr($attrs->getNamedItem('htmlUrl')->nodeValue, 0, 250); |
306 | 318 | |
@@ -309,19 +321,27 @@ discard block |
||
309 | 321 | feed_url = ? AND owner_uid = ?"); |
310 | 322 | $sth->execute([$feed_url, $owner_uid]); |
311 | 323 | |
312 | - if (!$feed_title) $feed_title = '[Unknown]'; |
|
324 | + if (!$feed_title) { |
|
325 | + $feed_title = '[Unknown]'; |
|
326 | + } |
|
313 | 327 | |
314 | 328 | if (!$sth->fetch()) { |
315 | 329 | #$this->opml_notice("[FEED] [$feed_title/$feed_url] dst_CAT=$cat_id"); |
316 | 330 | $this->opml_notice(T_sprintf("Adding feed: %s", $feed_title == '[Unknown]' ? $feed_url : $feed_title)); |
317 | 331 | |
318 | - if (!$cat_id) $cat_id = null; |
|
332 | + if (!$cat_id) { |
|
333 | + $cat_id = null; |
|
334 | + } |
|
319 | 335 | |
320 | 336 | $update_interval = (int) $attrs->getNamedItem('ttrssUpdateInterval')->nodeValue; |
321 | - if (!$update_interval) $update_interval = 0; |
|
337 | + if (!$update_interval) { |
|
338 | + $update_interval = 0; |
|
339 | + } |
|
322 | 340 | |
323 | 341 | $order_id = (int) $attrs->getNamedItem('ttrssSortOrder')->nodeValue; |
324 | - if (!$order_id) $order_id = 0; |
|
342 | + if (!$order_id) { |
|
343 | + $order_id = 0; |
|
344 | + } |
|
325 | 345 | |
326 | 346 | $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
327 | 347 | (title, feed_url, owner_uid, cat_id, site_url, order_id, update_interval) VALUES |
@@ -505,15 +525,18 @@ discard block |
||
505 | 525 | if ($root_node) { |
506 | 526 | $cat_title = mb_substr($root_node->attributes->getNamedItem('text')->nodeValue, 0, 250); |
507 | 527 | |
508 | - if (!$cat_title) |
|
509 | - $cat_title = mb_substr($root_node->attributes->getNamedItem('title')->nodeValue, 0, 250); |
|
528 | + if (!$cat_title) { |
|
529 | + $cat_title = mb_substr($root_node->attributes->getNamedItem('title')->nodeValue, 0, 250); |
|
530 | + } |
|
510 | 531 | |
511 | 532 | if (!in_array($cat_title, array("tt-rss-filters", "tt-rss-labels", "tt-rss-prefs"))) { |
512 | 533 | $cat_id = $this->get_feed_category($cat_title, $parent_id); |
513 | 534 | |
514 | 535 | if ($cat_id === false) { |
515 | 536 | $order_id = (int) $root_node->attributes->getNamedItem('ttrssSortOrder')->nodeValue; |
516 | - if (!$order_id) $order_id = 0; |
|
537 | + if (!$order_id) { |
|
538 | + $order_id = 0; |
|
539 | + } |
|
517 | 540 | |
518 | 541 | Feeds::add_feed_category($cat_title, $parent_id, $order_id); |
519 | 542 | $cat_id = $this->get_feed_category($cat_title, $parent_id); |
@@ -540,8 +563,9 @@ discard block |
||
540 | 563 | $attrs = $node->attributes; |
541 | 564 | $node_cat_title = $attrs->getNamedItem('text')->nodeValue; |
542 | 565 | |
543 | - if (!$node_cat_title) |
|
544 | - $node_cat_title = $attrs->getNamedItem('title')->nodeValue; |
|
566 | + if (!$node_cat_title) { |
|
567 | + $node_cat_title = $attrs->getNamedItem('title')->nodeValue; |
|
568 | + } |
|
545 | 569 | |
546 | 570 | $node_feed_url = $attrs->getNamedItem('xmlUrl')->nodeValue; |
547 | 571 | |
@@ -574,7 +598,9 @@ discard block |
||
574 | 598 | } |
575 | 599 | |
576 | 600 | public function opml_import($owner_uid) { |
577 | - if (!$owner_uid) return; |
|
601 | + if (!$owner_uid) { |
|
602 | + return; |
|
603 | + } |
|
578 | 604 | |
579 | 605 | $doc = false; |
580 | 606 |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | ### HSL >> RGB |
184 | 184 | function _color_hsl2rgb($hsl) { |
185 | 185 | $h = $hsl[0]; $s = $hsl[1]; $l = $hsl[2]; |
186 | - $m2 = ($l <= 0.5) ? $l * ($s + 1) : $l + $s - $l*$s; |
|
186 | + $m2 = ($l <= 0.5) ? $l * ($s + 1) : $l + $s - $l * $s; |
|
187 | 187 | $m1 = $l * 2 - $m2; |
188 | 188 | return array(_color_hue2rgb($m1, $m2, $h + 0.33333), |
189 | 189 | _color_hue2rgb($m1, $m2, $h), |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | $hex = substr($hex, 1); |
209 | 209 | |
210 | 210 | if (strlen($hex) == 4) { |
211 | - $hex = $hex[1] . $hex[1] . $hex[2] . $hex[2] . $hex[3] . $hex[3]; |
|
211 | + $hex = $hex[1].$hex[1].$hex[2].$hex[2].$hex[3].$hex[3]; |
|
212 | 212 | } |
213 | 213 | $c = hexdec($hex); |
214 | 214 | for ($i = 16; $i >= 0; $i -= 8) { |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | function _color_pack($rgb, $normalize = false) { |
221 | 221 | foreach ($rgb as $k => $v) { |
222 | 222 | $out |= (($v * ($normalize ? 255 : 1)) << (16 - $k * 8)); |
223 | - }return '#'. str_pad(dechex($out), 6, 0, STR_PAD_LEFT); |
|
223 | + }return '#'.str_pad(dechex($out), 6, 0, STR_PAD_LEFT); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | function rgb2hsl($arr) { |
@@ -244,13 +244,13 @@ discard block |
||
244 | 244 | } else { |
245 | 245 | $s = $del_Max / $var_Max; |
246 | 246 | |
247 | - $del_R = ((($var_Max - $var_R ) / 6 ) + ($del_Max / 2 ) ) / $del_Max; |
|
248 | - $del_G = ((($var_Max - $var_G ) / 6 ) + ($del_Max / 2 ) ) / $del_Max; |
|
249 | - $del_B = ((($var_Max - $var_B ) / 6 ) + ($del_Max / 2 ) ) / $del_Max; |
|
247 | + $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
248 | + $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
249 | + $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
250 | 250 | |
251 | - if ($var_R == $var_Max) $h = $del_B - $del_G; |
|
252 | - else if ($var_G == $var_Max) $h = (1 / 3 ) + $del_R - $del_B; |
|
253 | - else if ($var_B == $var_Max) $h = (2 / 3 ) + $del_G - $del_R; |
|
251 | + if ($var_R == $var_Max) $h = $del_B - $del_G; |
|
252 | + else if ($var_G == $var_Max) $h = (1 / 3) + $del_R - $del_B; |
|
253 | + else if ($var_B == $var_Max) $h = (2 / 3) + $del_G - $del_R; |
|
254 | 254 | |
255 | 255 | if ($h < 0) $h++; |
256 | 256 | if ($h > 1) $h--; |
@@ -264,21 +264,21 @@ discard block |
||
264 | 264 | $s = $arr[1]; |
265 | 265 | $v = $arr[2]; |
266 | 266 | |
267 | - if($s == 0) { |
|
267 | + if ($s == 0) { |
|
268 | 268 | $r = $g = $B = $v * 255; |
269 | 269 | } else { |
270 | 270 | $var_H = $h * 6; |
271 | - $var_i = floor($var_H ); |
|
272 | - $var_1 = $v * (1 - $s ); |
|
273 | - $var_2 = $v * (1 - $s * ($var_H - $var_i ) ); |
|
274 | - $var_3 = $v * (1 - $s * (1 - ($var_H - $var_i ) ) ); |
|
275 | - |
|
276 | - if ($var_i == 0) { $var_R = $v ; $var_G = $var_3 ; $var_B = $var_1 ; } |
|
277 | - else if ($var_i == 1) { $var_R = $var_2 ; $var_G = $v ; $var_B = $var_1 ; } |
|
278 | - else if ($var_i == 2) { $var_R = $var_1 ; $var_G = $v ; $var_B = $var_3 ; } |
|
279 | - else if ($var_i == 3) { $var_R = $var_1 ; $var_G = $var_2 ; $var_B = $v ; } |
|
280 | - else if ($var_i == 4) { $var_R = $var_3 ; $var_G = $var_1 ; $var_B = $v ; } |
|
281 | - else { $var_R = $v ; $var_G = $var_1 ; $var_B = $var_2 ; } |
|
271 | + $var_i = floor($var_H); |
|
272 | + $var_1 = $v * (1 - $s); |
|
273 | + $var_2 = $v * (1 - $s * ($var_H - $var_i)); |
|
274 | + $var_3 = $v * (1 - $s * (1 - ($var_H - $var_i))); |
|
275 | + |
|
276 | + if ($var_i == 0) { $var_R = $v; $var_G = $var_3; $var_B = $var_1; } |
|
277 | + else if ($var_i == 1) { $var_R = $var_2; $var_G = $v; $var_B = $var_1; } |
|
278 | + else if ($var_i == 2) { $var_R = $var_1; $var_G = $v; $var_B = $var_3; } |
|
279 | + else if ($var_i == 3) { $var_R = $var_1; $var_G = $var_2; $var_B = $v; } |
|
280 | + else if ($var_i == 4) { $var_R = $var_3; $var_G = $var_1; $var_B = $v; } |
|
281 | + else { $var_R = $v; $var_G = $var_1; $var_B = $var_2; } |
|
282 | 282 | |
283 | 283 | $r = $var_R * 255; |
284 | 284 | $g = $var_G * 255; |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | } |
289 | 289 | |
290 | 290 | function colorPalette($imageFile, $numColors, $granularity = 5) { |
291 | - $granularity = max(1, abs((int)$granularity)); |
|
291 | + $granularity = max(1, abs((int) $granularity)); |
|
292 | 292 | $colors = array(); |
293 | 293 | |
294 | 294 | $size = @getimagesize($imageFile); |
@@ -301,10 +301,10 @@ discard block |
||
301 | 301 | $ico = new floIcon(); |
302 | 302 | @$ico->readICO($imageFile); |
303 | 303 | |
304 | - if(count($ico->images)==0) |
|
304 | + if (count($ico->images) == 0) |
|
305 | 305 | return false; |
306 | 306 | else |
307 | - $img = @$ico->images[count($ico->images)-1]->getImageResource(); |
|
307 | + $img = @$ico->images[count($ico->images) - 1]->getImageResource(); |
|
308 | 308 | |
309 | 309 | } else { |
310 | 310 | return false; |
@@ -316,17 +316,17 @@ discard block |
||
316 | 316 | |
317 | 317 | if (!$img) return false; |
318 | 318 | |
319 | - for($x = 0; $x < $size[0]; $x += $granularity) { |
|
320 | - for($y = 0; $y < $size[1]; $y += $granularity) { |
|
319 | + for ($x = 0; $x < $size[0]; $x += $granularity) { |
|
320 | + for ($y = 0; $y < $size[1]; $y += $granularity) { |
|
321 | 321 | $thisColor = imagecolorat($img, $x, $y); |
322 | 322 | $rgb = imagecolorsforindex($img, $thisColor); |
323 | 323 | $red = round(round(($rgb['red'] / 0x33)) * 0x33); |
324 | 324 | $green = round(round(($rgb['green'] / 0x33)) * 0x33); |
325 | 325 | $blue = round(round(($rgb['blue'] / 0x33)) * 0x33); |
326 | 326 | $thisRGB = sprintf('%02X%02X%02X', $red, $green, $blue); |
327 | - if(array_key_exists($thisRGB, $colors)) { |
|
327 | + if (array_key_exists($thisRGB, $colors)) { |
|
328 | 328 | $colors[$thisRGB]++; |
329 | - } else{ |
|
329 | + } else { |
|
330 | 330 | $colors[$thisRGB] = 1; |
331 | 331 | } |
332 | 332 | } |
@@ -157,11 +157,12 @@ discard block |
||
157 | 157 | |
158 | 158 | $color = strtolower($color); |
159 | 159 | |
160 | - if (isset($htmlcolors[$color])) |
|
161 | - return $htmlcolors[$color]; |
|
162 | - else |
|
163 | - return $color; |
|
164 | -} |
|
160 | + if (isset($htmlcolors[$color])) { |
|
161 | + return $htmlcolors[$color]; |
|
162 | + } else { |
|
163 | + return $color; |
|
164 | + } |
|
165 | + } |
|
165 | 166 | |
166 | 167 | ### RGB >> HSL |
167 | 168 | function _color_rgb2hsl($rgb) { |
@@ -173,9 +174,15 @@ discard block |
||
173 | 174 | } |
174 | 175 | $h = 0; |
175 | 176 | if ($delta > 0) { |
176 | - if ($max == $r && $max != $g) $h += ($g - $b) / $delta; |
|
177 | - if ($max == $g && $max != $b) $h += (2 + ($b - $r) / $delta); |
|
178 | - if ($max == $b && $max != $r) $h += (4 + ($r - $g) / $delta); |
|
177 | + if ($max == $r && $max != $g) { |
|
178 | + $h += ($g - $b) / $delta; |
|
179 | + } |
|
180 | + if ($max == $g && $max != $b) { |
|
181 | + $h += (2 + ($b - $r) / $delta); |
|
182 | + } |
|
183 | + if ($max == $b && $max != $r) { |
|
184 | + $h += (4 + ($r - $g) / $delta); |
|
185 | + } |
|
179 | 186 | $h /= 6; |
180 | 187 | } return array($h, $s, $l); |
181 | 188 | } |
@@ -193,19 +200,26 @@ discard block |
||
193 | 200 | ### Helper function for _color_hsl2rgb(). |
194 | 201 | function _color_hue2rgb($m1, $m2, $h) { |
195 | 202 | $h = ($h < 0) ? $h + 1 : (($h > 1) ? $h - 1 : $h); |
196 | - if ($h * 6 < 1) return $m1 + ($m2 - $m1) * $h * 6; |
|
197 | - if ($h * 2 < 1) return $m2; |
|
198 | - if ($h * 3 < 2) return $m1 + ($m2 - $m1) * (0.66666 - $h) * 6; |
|
203 | + if ($h * 6 < 1) { |
|
204 | + return $m1 + ($m2 - $m1) * $h * 6; |
|
205 | + } |
|
206 | + if ($h * 2 < 1) { |
|
207 | + return $m2; |
|
208 | + } |
|
209 | + if ($h * 3 < 2) { |
|
210 | + return $m1 + ($m2 - $m1) * (0.66666 - $h) * 6; |
|
211 | + } |
|
199 | 212 | return $m1; |
200 | 213 | } |
201 | 214 | |
202 | 215 | ### Convert a hex color into an RGB triplet. |
203 | 216 | function _color_unpack($hex, $normalize = false) { |
204 | 217 | |
205 | - if (strpos($hex, '#') !== 0) |
|
206 | - $hex = _resolve_htmlcolor($hex); |
|
207 | - else |
|
208 | - $hex = substr($hex, 1); |
|
218 | + if (strpos($hex, '#') !== 0) { |
|
219 | + $hex = _resolve_htmlcolor($hex); |
|
220 | + } else { |
|
221 | + $hex = substr($hex, 1); |
|
222 | + } |
|
209 | 223 | |
210 | 224 | if (strlen($hex) == 4) { |
211 | 225 | $hex = $hex[1] . $hex[1] . $hex[2] . $hex[2] . $hex[3] . $hex[3]; |
@@ -248,12 +262,20 @@ discard block |
||
248 | 262 | $del_G = ((($var_Max - $var_G ) / 6 ) + ($del_Max / 2 ) ) / $del_Max; |
249 | 263 | $del_B = ((($var_Max - $var_B ) / 6 ) + ($del_Max / 2 ) ) / $del_Max; |
250 | 264 | |
251 | - if ($var_R == $var_Max) $h = $del_B - $del_G; |
|
252 | - else if ($var_G == $var_Max) $h = (1 / 3 ) + $del_R - $del_B; |
|
253 | - else if ($var_B == $var_Max) $h = (2 / 3 ) + $del_G - $del_R; |
|
265 | + if ($var_R == $var_Max) { |
|
266 | + $h = $del_B - $del_G; |
|
267 | + } else if ($var_G == $var_Max) { |
|
268 | + $h = (1 / 3 ) + $del_R - $del_B; |
|
269 | + } else if ($var_B == $var_Max) { |
|
270 | + $h = (2 / 3 ) + $del_G - $del_R; |
|
271 | + } |
|
254 | 272 | |
255 | - if ($h < 0) $h++; |
|
256 | - if ($h > 1) $h--; |
|
273 | + if ($h < 0) { |
|
274 | + $h++; |
|
275 | + } |
|
276 | + if ($h > 1) { |
|
277 | + $h--; |
|
278 | + } |
|
257 | 279 | } |
258 | 280 | |
259 | 281 | return array($h, $s, $v); |
@@ -273,12 +295,7 @@ discard block |
||
273 | 295 | $var_2 = $v * (1 - $s * ($var_H - $var_i ) ); |
274 | 296 | $var_3 = $v * (1 - $s * (1 - ($var_H - $var_i ) ) ); |
275 | 297 | |
276 | - if ($var_i == 0) { $var_R = $v ; $var_G = $var_3 ; $var_B = $var_1 ; } |
|
277 | - else if ($var_i == 1) { $var_R = $var_2 ; $var_G = $v ; $var_B = $var_1 ; } |
|
278 | - else if ($var_i == 2) { $var_R = $var_1 ; $var_G = $v ; $var_B = $var_3 ; } |
|
279 | - else if ($var_i == 3) { $var_R = $var_1 ; $var_G = $var_2 ; $var_B = $v ; } |
|
280 | - else if ($var_i == 4) { $var_R = $var_3 ; $var_G = $var_1 ; $var_B = $v ; } |
|
281 | - else { $var_R = $v ; $var_G = $var_1 ; $var_B = $var_2 ; } |
|
298 | + if ($var_i == 0) { $var_R = $v ; $var_G = $var_3 ; $var_B = $var_1 ; } else if ($var_i == 1) { $var_R = $var_2 ; $var_G = $v ; $var_B = $var_1 ; } else if ($var_i == 2) { $var_R = $var_1 ; $var_G = $v ; $var_B = $var_3 ; } else if ($var_i == 3) { $var_R = $var_1 ; $var_G = $var_2 ; $var_B = $v ; } else if ($var_i == 4) { $var_R = $var_3 ; $var_G = $var_1 ; $var_B = $v ; } else { $var_R = $v ; $var_G = $var_1 ; $var_B = $var_2 ; } |
|
282 | 299 | |
283 | 300 | $r = $var_R * 255; |
284 | 301 | $g = $var_G * 255; |
@@ -301,10 +318,11 @@ discard block |
||
301 | 318 | $ico = new floIcon(); |
302 | 319 | @$ico->readICO($imageFile); |
303 | 320 | |
304 | - if(count($ico->images)==0) |
|
305 | - return false; |
|
306 | - else |
|
307 | - $img = @$ico->images[count($ico->images)-1]->getImageResource(); |
|
321 | + if(count($ico->images)==0) { |
|
322 | + return false; |
|
323 | + } else { |
|
324 | + $img = @$ico->images[count($ico->images)-1]->getImageResource(); |
|
325 | + } |
|
308 | 326 | |
309 | 327 | } else { |
310 | 328 | return false; |
@@ -314,7 +332,9 @@ discard block |
||
314 | 332 | $img = @imagecreatefromstring(file_get_contents($imageFile)); |
315 | 333 | } |
316 | 334 | |
317 | - if (!$img) return false; |
|
335 | + if (!$img) { |
|
336 | + return false; |
|
337 | + } |
|
318 | 338 | |
319 | 339 | for($x = 0; $x < $size[0]; $x += $granularity) { |
320 | 340 | for($y = 0; $y < $size[1]; $y += $granularity) { |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | return true; |
79 | 79 | } |
80 | 80 | |
81 | -function ttrss_open () { |
|
81 | +function ttrss_open() { |
|
82 | 82 | return true; |
83 | 83 | } |
84 | 84 | |
85 | -function ttrss_read ($id){ |
|
85 | +function ttrss_read($id) { |
|
86 | 86 | global $session_expire; |
87 | 87 | |
88 | 88 | $sth = Db::pdo()->prepare("SELECT data FROM ttrss_sessions WHERE id=?"); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
104 | -function ttrss_write ($id, $data) { |
|
104 | +function ttrss_write($id, $data) { |
|
105 | 105 | global $session_expire; |
106 | 106 | |
107 | 107 | $data = base64_encode($data); |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | return true; |
122 | 122 | } |
123 | 123 | |
124 | -function ttrss_close () { |
|
124 | +function ttrss_close() { |
|
125 | 125 | return true; |
126 | 126 | } |
127 | 127 | |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | return true; |
133 | 133 | } |
134 | 134 | |
135 | -function ttrss_gc () { |
|
136 | - Db::pdo()->query("DELETE FROM ttrss_sessions WHERE expire < " . time()); |
|
135 | +function ttrss_gc() { |
|
136 | + Db::pdo()->query("DELETE FROM ttrss_sessions WHERE expire < ".time()); |
|
137 | 137 | |
138 | 138 | return true; |
139 | 139 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | __("Session failed to validate (schema version changed)"); |
43 | 43 | return false; |
44 | 44 | } |
45 | - $pdo = Db::pdo(); |
|
45 | + $pdo = Db::pdo(); |
|
46 | 46 | |
47 | 47 | if ($_SESSION["uid"]) { |
48 | 48 | |
@@ -56,21 +56,21 @@ discard block |
||
56 | 56 | |
57 | 57 | // user not found |
58 | 58 | if ($row = $sth->fetch()) { |
59 | - $pwd_hash = $row["pwd_hash"]; |
|
59 | + $pwd_hash = $row["pwd_hash"]; |
|
60 | 60 | |
61 | - if ($pwd_hash != $_SESSION["pwd_hash"]) { |
|
61 | + if ($pwd_hash != $_SESSION["pwd_hash"]) { |
|
62 | 62 | |
63 | - $_SESSION["login_error_msg"] = |
|
63 | + $_SESSION["login_error_msg"] = |
|
64 | 64 | __("Session failed to validate (password changed)"); |
65 | 65 | |
66 | - return false; |
|
67 | - } |
|
66 | + return false; |
|
67 | + } |
|
68 | 68 | } else { |
69 | 69 | |
70 | - $_SESSION["login_error_msg"] = |
|
71 | - __("Session failed to validate (user not found)"); |
|
70 | + $_SESSION["login_error_msg"] = |
|
71 | + __("Session failed to validate (user not found)"); |
|
72 | 72 | |
73 | - return false; |
|
73 | + return false; |
|
74 | 74 | |
75 | 75 | } |
76 | 76 | } |
@@ -35,7 +35,9 @@ |
||
35 | 35 | } |
36 | 36 | |
37 | 37 | function validate_session() { |
38 | - if (SINGLE_USER_MODE) return true; |
|
38 | + if (SINGLE_USER_MODE) { |
|
39 | + return true; |
|
40 | + } |
|
39 | 41 | |
40 | 42 | if (isset($_SESSION["ref_schema_version"]) && $_SESSION["ref_schema_version"] != session_get_schema_version()) { |
41 | 43 | $_SESSION["login_error_msg"] = |
@@ -19,7 +19,7 @@ |
||
19 | 19 | } |
20 | 20 | |
21 | 21 | public function get_js() { |
22 | - return file_get_contents(dirname(__FILE__) . "/init.js"); |
|
22 | + return file_get_contents(dirname(__FILE__)."/init.js"); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | public function hook_render_article($article) { |
@@ -1,64 +1,64 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class NSFW extends Plugin { |
3 | - private $host; |
|
3 | + private $host; |
|
4 | 4 | |
5 | - public function about() { |
|
6 | - return array(1.0, |
|
7 | - "Hide article content based on tags", |
|
8 | - "fox", |
|
9 | - false); |
|
10 | - } |
|
5 | + public function about() { |
|
6 | + return array(1.0, |
|
7 | + "Hide article content based on tags", |
|
8 | + "fox", |
|
9 | + false); |
|
10 | + } |
|
11 | 11 | |
12 | - public function init($host) { |
|
13 | - $this->host = $host; |
|
12 | + public function init($host) { |
|
13 | + $this->host = $host; |
|
14 | 14 | |
15 | - $host->add_hook($host::HOOK_RENDER_ARTICLE, $this); |
|
16 | - $host->add_hook($host::HOOK_RENDER_ARTICLE_CDM, $this); |
|
17 | - $host->add_hook($host::HOOK_PREFS_TAB, $this); |
|
15 | + $host->add_hook($host::HOOK_RENDER_ARTICLE, $this); |
|
16 | + $host->add_hook($host::HOOK_RENDER_ARTICLE_CDM, $this); |
|
17 | + $host->add_hook($host::HOOK_PREFS_TAB, $this); |
|
18 | 18 | |
19 | - } |
|
19 | + } |
|
20 | 20 | |
21 | - public function get_js() { |
|
22 | - return file_get_contents(dirname(__FILE__) . "/init.js"); |
|
23 | - } |
|
21 | + public function get_js() { |
|
22 | + return file_get_contents(dirname(__FILE__) . "/init.js"); |
|
23 | + } |
|
24 | 24 | |
25 | - public function hook_render_article($article) { |
|
26 | - $tags = array_map("trim", explode(",", $this->host->get($this, "tags"))); |
|
27 | - $a_tags = array_map("trim", explode(",", $article["tag_cache"])); |
|
25 | + public function hook_render_article($article) { |
|
26 | + $tags = array_map("trim", explode(",", $this->host->get($this, "tags"))); |
|
27 | + $a_tags = array_map("trim", explode(",", $article["tag_cache"])); |
|
28 | 28 | |
29 | - if (count(array_intersect($tags, $a_tags)) > 0) { |
|
30 | - $article["content"] = "<div class='nswf wrapper'><button onclick=\"nsfwShow(this)\">".__("Not work safe (click to toggle)")."</button> |
|
29 | + if (count(array_intersect($tags, $a_tags)) > 0) { |
|
30 | + $article["content"] = "<div class='nswf wrapper'><button onclick=\"nsfwShow(this)\">".__("Not work safe (click to toggle)")."</button> |
|
31 | 31 | <div class='nswf content' style='display : none'>".$article["content"]."</div></div>"; |
32 | - } |
|
32 | + } |
|
33 | 33 | |
34 | - return $article; |
|
35 | - } |
|
34 | + return $article; |
|
35 | + } |
|
36 | 36 | |
37 | - public function hook_render_article_cdm($article) { |
|
38 | - $tags = array_map("trim", explode(",", $this->host->get($this, "tags"))); |
|
39 | - $a_tags = array_map("trim", explode(",", $article["tag_cache"])); |
|
37 | + public function hook_render_article_cdm($article) { |
|
38 | + $tags = array_map("trim", explode(",", $this->host->get($this, "tags"))); |
|
39 | + $a_tags = array_map("trim", explode(",", $article["tag_cache"])); |
|
40 | 40 | |
41 | - if (count(array_intersect($tags, $a_tags)) > 0) { |
|
42 | - $article["content"] = "<div class='nswf wrapper'><button onclick=\"nsfwShow(this)\">".__("Not work safe (click to toggle)")."</button> |
|
41 | + if (count(array_intersect($tags, $a_tags)) > 0) { |
|
42 | + $article["content"] = "<div class='nswf wrapper'><button onclick=\"nsfwShow(this)\">".__("Not work safe (click to toggle)")."</button> |
|
43 | 43 | <div class='nswf content' style='display : none'>".$article["content"]."</div></div>"; |
44 | - } |
|
44 | + } |
|
45 | 45 | |
46 | - return $article; |
|
47 | - } |
|
46 | + return $article; |
|
47 | + } |
|
48 | 48 | |
49 | - public function hook_prefs_tab($args) { |
|
50 | - if ($args != "prefPrefs") return; |
|
49 | + public function hook_prefs_tab($args) { |
|
50 | + if ($args != "prefPrefs") return; |
|
51 | 51 | |
52 | - print "<div dojoType=\"dijit.layout.AccordionPane\" |
|
52 | + print "<div dojoType=\"dijit.layout.AccordionPane\" |
|
53 | 53 | title=\"<i class='material-icons'>extension</i> ".__("NSFW Plugin")."\">"; |
54 | 54 | |
55 | - print "<br/>"; |
|
55 | + print "<br/>"; |
|
56 | 56 | |
57 | - $tags = $this->host->get($this, "tags"); |
|
57 | + $tags = $this->host->get($this, "tags"); |
|
58 | 58 | |
59 | - print "<form dojoType=\"dijit.form.Form\">"; |
|
59 | + print "<form dojoType=\"dijit.form.Form\">"; |
|
60 | 60 | |
61 | - print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> |
|
61 | + print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> |
|
62 | 62 | evt.preventDefault(); |
63 | 63 | if (this.validate()) { |
64 | 64 | new Ajax.Request('backend.php', { |
@@ -71,38 +71,38 @@ discard block |
||
71 | 71 | } |
72 | 72 | </script>"; |
73 | 73 | |
74 | - print_hidden("op", "pluginhandler"); |
|
75 | - print_hidden("method", "save"); |
|
76 | - print_hidden("plugin", "nsfw"); |
|
74 | + print_hidden("op", "pluginhandler"); |
|
75 | + print_hidden("method", "save"); |
|
76 | + print_hidden("plugin", "nsfw"); |
|
77 | 77 | |
78 | - print "<table width=\"100%\" class=\"prefPrefsList\">"; |
|
78 | + print "<table width=\"100%\" class=\"prefPrefsList\">"; |
|
79 | 79 | |
80 | - print "<tr><td width=\"40%\">".__("Tags to consider NSFW (comma-separated)")."</td>"; |
|
81 | - print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"tags\" value=\"$tags\"></td></tr>"; |
|
80 | + print "<tr><td width=\"40%\">".__("Tags to consider NSFW (comma-separated)")."</td>"; |
|
81 | + print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"tags\" value=\"$tags\"></td></tr>"; |
|
82 | 82 | |
83 | - print "</table>"; |
|
83 | + print "</table>"; |
|
84 | 84 | |
85 | - print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". |
|
86 | - __("Save")."</button>"; |
|
85 | + print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". |
|
86 | + __("Save")."</button>"; |
|
87 | 87 | |
88 | - print "</form>"; |
|
88 | + print "</form>"; |
|
89 | 89 | |
90 | - print "</div>"; #pane |
|
91 | - } |
|
90 | + print "</div>"; #pane |
|
91 | + } |
|
92 | 92 | |
93 | - public function save() { |
|
94 | - $tags = explode(",", $_POST["tags"]); |
|
95 | - $tags = array_map("trim", $tags); |
|
96 | - $tags = array_map("mb_strtolower", $tags); |
|
97 | - $tags = join(", ", $tags); |
|
93 | + public function save() { |
|
94 | + $tags = explode(",", $_POST["tags"]); |
|
95 | + $tags = array_map("trim", $tags); |
|
96 | + $tags = array_map("mb_strtolower", $tags); |
|
97 | + $tags = join(", ", $tags); |
|
98 | 98 | |
99 | - $this->host->set($this, "tags", $tags); |
|
99 | + $this->host->set($this, "tags", $tags); |
|
100 | 100 | |
101 | - echo __("Configuration saved."); |
|
102 | - } |
|
101 | + echo __("Configuration saved."); |
|
102 | + } |
|
103 | 103 | |
104 | - public function api_version() { |
|
105 | - return 2; |
|
106 | - } |
|
104 | + public function api_version() { |
|
105 | + return 2; |
|
106 | + } |
|
107 | 107 | |
108 | 108 | } |
@@ -47,7 +47,9 @@ |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | public function hook_prefs_tab($args) { |
50 | - if ($args != "prefPrefs") return; |
|
50 | + if ($args != "prefPrefs") { |
|
51 | + return; |
|
52 | + } |
|
51 | 53 | |
52 | 54 | print "<div dojoType=\"dijit.layout.AccordionPane\" |
53 | 55 | title=\"<i class='material-icons'>extension</i> ".__("NSFW Plugin")."\">"; |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | } |
14 | 14 | |
15 | 15 | /* @var PluginHost $host */ |
16 | - public function init($host ) { |
|
16 | + public function init($host) { |
|
17 | 17 | $this->host = $host; |
18 | 18 | $this->base = new Auth_Base(); |
19 | 19 | |
@@ -59,16 +59,16 @@ discard block |
||
59 | 59 | $_SESSION["hide_logout"] = true; |
60 | 60 | |
61 | 61 | // LemonLDAP can send user informations via HTTP HEADER |
62 | - if (defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE){ |
|
62 | + if (defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE) { |
|
63 | 63 | // update user name |
64 | 64 | $fullname = $_SERVER['HTTP_USER_NAME'] ? $_SERVER['HTTP_USER_NAME'] : $_SERVER['AUTHENTICATE_CN']; |
65 | - if ($fullname){ |
|
65 | + if ($fullname) { |
|
66 | 66 | $sth = $this->pdo->prepare("UPDATE ttrss_users SET full_name = ? WHERE id = ?"); |
67 | 67 | $sth->execute([$fullname, $user_id]); |
68 | 68 | } |
69 | 69 | // update user mail |
70 | 70 | $email = $_SERVER['HTTP_USER_MAIL'] ? $_SERVER['HTTP_USER_MAIL'] : $_SERVER['AUTHENTICATE_MAIL']; |
71 | - if ($email){ |
|
71 | + if ($email) { |
|
72 | 72 | $sth = $this->pdo->prepare("UPDATE ttrss_users SET email = ? WHERE id = ?"); |
73 | 73 | $sth->execute([$email, $user_id]); |
74 | 74 | } |
@@ -1,88 +1,88 @@ |
||
1 | 1 | <?php |
2 | 2 | class Auth_Remote extends Plugin implements IAuthModule { |
3 | 3 | |
4 | - private $host; |
|
5 | - /* @var Auth_Base $base */ |
|
6 | - private $base; |
|
7 | - |
|
8 | - public function about() { |
|
9 | - return array(1.0, |
|
10 | - "Authenticates against remote password (e.g. supplied by Apache)", |
|
11 | - "fox", |
|
12 | - true); |
|
13 | - } |
|
14 | - |
|
15 | - /* @var PluginHost $host */ |
|
16 | - public function init($host ) { |
|
17 | - $this->host = $host; |
|
18 | - $this->base = new Auth_Base(); |
|
19 | - |
|
20 | - $host->add_hook($host::HOOK_AUTH_USER, $this); |
|
21 | - } |
|
22 | - |
|
23 | - public function get_login_by_ssl_certificate() { |
|
24 | - $cert_serial = get_ssl_certificate_id(); |
|
25 | - |
|
26 | - if ($cert_serial) { |
|
27 | - $sth = $this->pdo->prepare("SELECT login FROM ttrss_user_prefs, ttrss_users |
|
4 | + private $host; |
|
5 | + /* @var Auth_Base $base */ |
|
6 | + private $base; |
|
7 | + |
|
8 | + public function about() { |
|
9 | + return array(1.0, |
|
10 | + "Authenticates against remote password (e.g. supplied by Apache)", |
|
11 | + "fox", |
|
12 | + true); |
|
13 | + } |
|
14 | + |
|
15 | + /* @var PluginHost $host */ |
|
16 | + public function init($host ) { |
|
17 | + $this->host = $host; |
|
18 | + $this->base = new Auth_Base(); |
|
19 | + |
|
20 | + $host->add_hook($host::HOOK_AUTH_USER, $this); |
|
21 | + } |
|
22 | + |
|
23 | + public function get_login_by_ssl_certificate() { |
|
24 | + $cert_serial = get_ssl_certificate_id(); |
|
25 | + |
|
26 | + if ($cert_serial) { |
|
27 | + $sth = $this->pdo->prepare("SELECT login FROM ttrss_user_prefs, ttrss_users |
|
28 | 28 | WHERE pref_name = 'SSL_CERT_SERIAL' AND value = ? AND |
29 | 29 | owner_uid = ttrss_users.id"); |
30 | - $sth->execute([$cert_serial]); |
|
31 | - |
|
32 | - if ($row = $sth->fetch()) { |
|
33 | - return $row['login']; |
|
34 | - } |
|
35 | - } |
|
36 | - |
|
37 | - return ""; |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
42 | - */ |
|
43 | - public function authenticate($login, $password) { |
|
44 | - $try_login = $_SERVER["REMOTE_USER"]; |
|
45 | - |
|
46 | - // php-cgi |
|
47 | - if (!$try_login) $try_login = $_SERVER["REDIRECT_REMOTE_USER"]; |
|
48 | - if (!$try_login) $try_login = $_SERVER["PHP_AUTH_USER"]; |
|
49 | - |
|
50 | - if (!$try_login) $try_login = $this->get_login_by_ssl_certificate(); |
|
51 | - |
|
52 | - if ($try_login) { |
|
53 | - $user_id = $this->base->auto_create_user($try_login, $password); |
|
54 | - |
|
55 | - if ($user_id) { |
|
56 | - $_SESSION["fake_login"] = $try_login; |
|
57 | - $_SESSION["fake_password"] = "******"; |
|
58 | - $_SESSION["hide_hello"] = true; |
|
59 | - $_SESSION["hide_logout"] = true; |
|
60 | - |
|
61 | - // LemonLDAP can send user informations via HTTP HEADER |
|
62 | - if (defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE){ |
|
63 | - // update user name |
|
64 | - $fullname = $_SERVER['HTTP_USER_NAME'] ? $_SERVER['HTTP_USER_NAME'] : $_SERVER['AUTHENTICATE_CN']; |
|
65 | - if ($fullname){ |
|
66 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET full_name = ? WHERE id = ?"); |
|
67 | - $sth->execute([$fullname, $user_id]); |
|
68 | - } |
|
69 | - // update user mail |
|
70 | - $email = $_SERVER['HTTP_USER_MAIL'] ? $_SERVER['HTTP_USER_MAIL'] : $_SERVER['AUTHENTICATE_MAIL']; |
|
71 | - if ($email){ |
|
72 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET email = ? WHERE id = ?"); |
|
73 | - $sth->execute([$email, $user_id]); |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - return $user_id; |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - return false; |
|
82 | - } |
|
83 | - |
|
84 | - public function api_version() { |
|
85 | - return 2; |
|
86 | - } |
|
30 | + $sth->execute([$cert_serial]); |
|
31 | + |
|
32 | + if ($row = $sth->fetch()) { |
|
33 | + return $row['login']; |
|
34 | + } |
|
35 | + } |
|
36 | + |
|
37 | + return ""; |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
42 | + */ |
|
43 | + public function authenticate($login, $password) { |
|
44 | + $try_login = $_SERVER["REMOTE_USER"]; |
|
45 | + |
|
46 | + // php-cgi |
|
47 | + if (!$try_login) $try_login = $_SERVER["REDIRECT_REMOTE_USER"]; |
|
48 | + if (!$try_login) $try_login = $_SERVER["PHP_AUTH_USER"]; |
|
49 | + |
|
50 | + if (!$try_login) $try_login = $this->get_login_by_ssl_certificate(); |
|
51 | + |
|
52 | + if ($try_login) { |
|
53 | + $user_id = $this->base->auto_create_user($try_login, $password); |
|
54 | + |
|
55 | + if ($user_id) { |
|
56 | + $_SESSION["fake_login"] = $try_login; |
|
57 | + $_SESSION["fake_password"] = "******"; |
|
58 | + $_SESSION["hide_hello"] = true; |
|
59 | + $_SESSION["hide_logout"] = true; |
|
60 | + |
|
61 | + // LemonLDAP can send user informations via HTTP HEADER |
|
62 | + if (defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE){ |
|
63 | + // update user name |
|
64 | + $fullname = $_SERVER['HTTP_USER_NAME'] ? $_SERVER['HTTP_USER_NAME'] : $_SERVER['AUTHENTICATE_CN']; |
|
65 | + if ($fullname){ |
|
66 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET full_name = ? WHERE id = ?"); |
|
67 | + $sth->execute([$fullname, $user_id]); |
|
68 | + } |
|
69 | + // update user mail |
|
70 | + $email = $_SERVER['HTTP_USER_MAIL'] ? $_SERVER['HTTP_USER_MAIL'] : $_SERVER['AUTHENTICATE_MAIL']; |
|
71 | + if ($email){ |
|
72 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET email = ? WHERE id = ?"); |
|
73 | + $sth->execute([$email, $user_id]); |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + return $user_id; |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + return false; |
|
82 | + } |
|
83 | + |
|
84 | + public function api_version() { |
|
85 | + return 2; |
|
86 | + } |
|
87 | 87 | |
88 | 88 | } |
@@ -44,10 +44,16 @@ |
||
44 | 44 | $try_login = $_SERVER["REMOTE_USER"]; |
45 | 45 | |
46 | 46 | // php-cgi |
47 | - if (!$try_login) $try_login = $_SERVER["REDIRECT_REMOTE_USER"]; |
|
48 | - if (!$try_login) $try_login = $_SERVER["PHP_AUTH_USER"]; |
|
47 | + if (!$try_login) { |
|
48 | + $try_login = $_SERVER["REDIRECT_REMOTE_USER"]; |
|
49 | + } |
|
50 | + if (!$try_login) { |
|
51 | + $try_login = $_SERVER["PHP_AUTH_USER"]; |
|
52 | + } |
|
49 | 53 | |
50 | - if (!$try_login) $try_login = $this->get_login_by_ssl_certificate(); |
|
54 | + if (!$try_login) { |
|
55 | + $try_login = $this->get_login_by_ssl_certificate(); |
|
56 | + } |
|
51 | 57 | |
52 | 58 | if ($try_login) { |
53 | 59 | $user_id = $this->base->auto_create_user($try_login, $password); |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | print "<div dojoType=\"dijit.layout.AccordionPane\" |
23 | 23 | title=\"<i class='material-icons'>bookmark</i> ".__('Bookmarklets')."\">"; |
24 | 24 | |
25 | - print "<h3>" . __("Drag the link below to your browser toolbar, open the feed you're interested in in your browser and click on the link to subscribe to it.") . "</h3>"; |
|
25 | + print "<h3>".__("Drag the link below to your browser toolbar, open the feed you're interested in in your browser and click on the link to subscribe to it.")."</h3>"; |
|
26 | 26 | |
27 | 27 | $bm_subscribe_url = str_replace('%s', '', Pref_Feeds::subscribe_to_feed_url()); |
28 | 28 | |
@@ -31,14 +31,14 @@ discard block |
||
31 | 31 | $bm_url = htmlspecialchars("javascript:{if(confirm('$confirm_str'.replace('%s',window.location.href)))window.location.href='$bm_subscribe_url'+window.location.href}"); |
32 | 32 | |
33 | 33 | print "<p><label class='dijitButton'>"; |
34 | - print "<a href=\"$bm_url\">" . __('Subscribe in Tiny Tiny RSS'). "</a>"; |
|
34 | + print "<a href=\"$bm_url\">".__('Subscribe in Tiny Tiny RSS')."</a>"; |
|
35 | 35 | print "</label></p>"; |
36 | 36 | |
37 | - print "<h3>" . __("Use this bookmarklet to publish arbitrary pages using Tiny Tiny RSS") . "</h3>"; |
|
37 | + print "<h3>".__("Use this bookmarklet to publish arbitrary pages using Tiny Tiny RSS")."</h3>"; |
|
38 | 38 | |
39 | 39 | print "<label class='dijitButton'>"; |
40 | 40 | $bm_url = htmlspecialchars("javascript:(function(){var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='".get_self_url_prefix()."/public.php?op=sharepopup',l=d.location,e=encodeURIComponent,g=f+'&title='+((e(s))?e(s):e(document.title))+'&url='+e(l.href);function a(){if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=500,height=250')){l.href=g;}}a();})()"); |
41 | - print "<a href=\"$bm_url\">" . __('Share with Tiny Tiny RSS'). "</a>"; |
|
41 | + print "<a href=\"$bm_url\">".__('Share with Tiny Tiny RSS')."</a>"; |
|
42 | 42 | print "</label>"; |
43 | 43 | |
44 | 44 | print "<button dojoType='dijit.form.Button' class='alt-info' onclick='window.open(\"https://tt-rss.org/wiki/ShareAnything\")'> |
@@ -1,56 +1,56 @@ |
||
1 | 1 | <?php |
2 | 2 | class Bookmarklets extends Plugin { |
3 | - private $host; |
|
3 | + private $host; |
|
4 | 4 | |
5 | - function about() { |
|
5 | + function about() { |
|
6 | 6 | return array(1.0, |
7 | - "Easy feed subscription and web page sharing using bookmarklets", |
|
8 | - "fox", |
|
9 | - false, |
|
10 | - "https://git.tt-rss.org/fox/tt-rss/wiki/ShareAnything"); |
|
11 | - } |
|
7 | + "Easy feed subscription and web page sharing using bookmarklets", |
|
8 | + "fox", |
|
9 | + false, |
|
10 | + "https://git.tt-rss.org/fox/tt-rss/wiki/ShareAnything"); |
|
11 | + } |
|
12 | 12 | |
13 | - function init($host) { |
|
13 | + function init($host) { |
|
14 | 14 | $this->host = $host; |
15 | 15 | |
16 | 16 | $host->add_hook($host::HOOK_PREFS_TAB, $this); |
17 | - } |
|
17 | + } |
|
18 | 18 | |
19 | - function hook_prefs_tab($args) { |
|
19 | + function hook_prefs_tab($args) { |
|
20 | 20 | if ($args == "prefFeeds") { |
21 | 21 | |
22 | - print "<div dojoType=\"dijit.layout.AccordionPane\" |
|
22 | + print "<div dojoType=\"dijit.layout.AccordionPane\" |
|
23 | 23 | title=\"<i class='material-icons'>bookmark</i> ".__('Bookmarklets')."\">"; |
24 | 24 | |
25 | - print "<h3>" . __("Drag the link below to your browser toolbar, open the feed you're interested in in your browser and click on the link to subscribe to it.") . "</h3>"; |
|
25 | + print "<h3>" . __("Drag the link below to your browser toolbar, open the feed you're interested in in your browser and click on the link to subscribe to it.") . "</h3>"; |
|
26 | 26 | |
27 | - $bm_subscribe_url = str_replace('%s', '', Pref_Feeds::subscribe_to_feed_url()); |
|
27 | + $bm_subscribe_url = str_replace('%s', '', Pref_Feeds::subscribe_to_feed_url()); |
|
28 | 28 | |
29 | - $confirm_str = str_replace("'", "\'", __('Subscribe to %s in Tiny Tiny RSS?')); |
|
29 | + $confirm_str = str_replace("'", "\'", __('Subscribe to %s in Tiny Tiny RSS?')); |
|
30 | 30 | |
31 | - $bm_url = htmlspecialchars("javascript:{if(confirm('$confirm_str'.replace('%s',window.location.href)))window.location.href='$bm_subscribe_url'+window.location.href}"); |
|
31 | + $bm_url = htmlspecialchars("javascript:{if(confirm('$confirm_str'.replace('%s',window.location.href)))window.location.href='$bm_subscribe_url'+window.location.href}"); |
|
32 | 32 | |
33 | - print "<p><label class='dijitButton'>"; |
|
34 | - print "<a href=\"$bm_url\">" . __('Subscribe in Tiny Tiny RSS'). "</a>"; |
|
35 | - print "</label></p>"; |
|
33 | + print "<p><label class='dijitButton'>"; |
|
34 | + print "<a href=\"$bm_url\">" . __('Subscribe in Tiny Tiny RSS'). "</a>"; |
|
35 | + print "</label></p>"; |
|
36 | 36 | |
37 | - print "<h3>" . __("Use this bookmarklet to publish arbitrary pages using Tiny Tiny RSS") . "</h3>"; |
|
37 | + print "<h3>" . __("Use this bookmarklet to publish arbitrary pages using Tiny Tiny RSS") . "</h3>"; |
|
38 | 38 | |
39 | - print "<label class='dijitButton'>"; |
|
40 | - $bm_url = htmlspecialchars("javascript:(function(){var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='".get_self_url_prefix()."/public.php?op=sharepopup',l=d.location,e=encodeURIComponent,g=f+'&title='+((e(s))?e(s):e(document.title))+'&url='+e(l.href);function a(){if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=500,height=250')){l.href=g;}}a();})()"); |
|
41 | - print "<a href=\"$bm_url\">" . __('Share with Tiny Tiny RSS'). "</a>"; |
|
42 | - print "</label>"; |
|
39 | + print "<label class='dijitButton'>"; |
|
40 | + $bm_url = htmlspecialchars("javascript:(function(){var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='".get_self_url_prefix()."/public.php?op=sharepopup',l=d.location,e=encodeURIComponent,g=f+'&title='+((e(s))?e(s):e(document.title))+'&url='+e(l.href);function a(){if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=500,height=250')){l.href=g;}}a();})()"); |
|
41 | + print "<a href=\"$bm_url\">" . __('Share with Tiny Tiny RSS'). "</a>"; |
|
42 | + print "</label>"; |
|
43 | 43 | |
44 | - print "<button dojoType='dijit.form.Button' class='alt-info' onclick='window.open(\"https://tt-rss.org/wiki/ShareAnything\")'> |
|
44 | + print "<button dojoType='dijit.form.Button' class='alt-info' onclick='window.open(\"https://tt-rss.org/wiki/ShareAnything\")'> |
|
45 | 45 | <i class='material-icons'>help</i> ".__("More info...")."</button>"; |
46 | 46 | |
47 | - print "</div>"; #pane |
|
47 | + print "</div>"; #pane |
|
48 | 48 | |
49 | - } |
|
50 | - } |
|
49 | + } |
|
50 | + } |
|
51 | 51 | |
52 | - public function api_version() { |
|
53 | - return 2; |
|
54 | - } |
|
52 | + public function api_version() { |
|
53 | + return 2; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | } |
18 | 18 | |
19 | 19 | public function get_js() { |
20 | - return file_get_contents(dirname(__FILE__) . "/note.js"); |
|
20 | + return file_get_contents(dirname(__FILE__)."/note.js"); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 |
@@ -1,78 +1,78 @@ |
||
1 | 1 | <?php |
2 | 2 | class Note extends Plugin { |
3 | 3 | |
4 | - /* @var PluginHost $host */ |
|
5 | - private $host; |
|
4 | + /* @var PluginHost $host */ |
|
5 | + private $host; |
|
6 | 6 | |
7 | - public function about() { |
|
8 | - return array(1.0, |
|
9 | - "Adds support for setting article notes", |
|
10 | - "fox"); |
|
11 | - } |
|
7 | + public function about() { |
|
8 | + return array(1.0, |
|
9 | + "Adds support for setting article notes", |
|
10 | + "fox"); |
|
11 | + } |
|
12 | 12 | |
13 | - public function init($host) { |
|
14 | - $this->host = $host; |
|
13 | + public function init($host) { |
|
14 | + $this->host = $host; |
|
15 | 15 | |
16 | - $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this); |
|
17 | - } |
|
16 | + $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this); |
|
17 | + } |
|
18 | 18 | |
19 | - public function get_js() { |
|
20 | - return file_get_contents(dirname(__FILE__) . "/note.js"); |
|
21 | - } |
|
19 | + public function get_js() { |
|
20 | + return file_get_contents(dirname(__FILE__) . "/note.js"); |
|
21 | + } |
|
22 | 22 | |
23 | 23 | |
24 | - public function hook_article_button($line) { |
|
25 | - return "<i class='material-icons' onclick=\"Plugins.Note.edit(".$line["id"].")\" |
|
24 | + public function hook_article_button($line) { |
|
25 | + return "<i class='material-icons' onclick=\"Plugins.Note.edit(".$line["id"].")\" |
|
26 | 26 | style='cursor : pointer' title='".__('Edit article note')."'>note</i>"; |
27 | - } |
|
27 | + } |
|
28 | 28 | |
29 | - public function edit() { |
|
30 | - $param = $_REQUEST['param']; |
|
29 | + public function edit() { |
|
30 | + $param = $_REQUEST['param']; |
|
31 | 31 | |
32 | - $sth = $this->pdo->prepare("SELECT note FROM ttrss_user_entries WHERE |
|
32 | + $sth = $this->pdo->prepare("SELECT note FROM ttrss_user_entries WHERE |
|
33 | 33 | ref_id = ? AND owner_uid = ?"); |
34 | - $sth->execute([$param, $_SESSION['uid']]); |
|
34 | + $sth->execute([$param, $_SESSION['uid']]); |
|
35 | 35 | |
36 | - if ($row = $sth->fetch()) { |
|
36 | + if ($row = $sth->fetch()) { |
|
37 | 37 | |
38 | - $note = $row['note']; |
|
38 | + $note = $row['note']; |
|
39 | 39 | |
40 | - print_hidden("id", "$param"); |
|
41 | - print_hidden("op", "pluginhandler"); |
|
42 | - print_hidden("method", "setNote"); |
|
43 | - print_hidden("plugin", "note"); |
|
40 | + print_hidden("id", "$param"); |
|
41 | + print_hidden("op", "pluginhandler"); |
|
42 | + print_hidden("method", "setNote"); |
|
43 | + print_hidden("plugin", "note"); |
|
44 | 44 | |
45 | - print "<textarea dojoType='dijit.form.SimpleTextarea' |
|
45 | + print "<textarea dojoType='dijit.form.SimpleTextarea' |
|
46 | 46 | style='font-size : 12px; width : 98%; height: 100px;' |
47 | 47 | name='note'>$note</textarea>"; |
48 | 48 | |
49 | - } |
|
49 | + } |
|
50 | 50 | |
51 | - print "<footer class='text-center'>"; |
|
52 | - print "<button dojoType=\"dijit.form.Button\" |
|
51 | + print "<footer class='text-center'>"; |
|
52 | + print "<button dojoType=\"dijit.form.Button\" |
|
53 | 53 | onclick=\"dijit.byId('editNoteDlg').execute()\">".__('Save')."</button> "; |
54 | - print "<button dojoType=\"dijit.form.Button\" |
|
54 | + print "<button dojoType=\"dijit.form.Button\" |
|
55 | 55 | onclick=\"dijit.byId('editNoteDlg').hide()\">".__('Cancel')."</button>"; |
56 | - print "</footer>"; |
|
56 | + print "</footer>"; |
|
57 | 57 | |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | - public function setNote() { |
|
61 | - $id = $_REQUEST["id"]; |
|
62 | - $note = trim(strip_tags($_REQUEST["note"])); |
|
60 | + public function setNote() { |
|
61 | + $id = $_REQUEST["id"]; |
|
62 | + $note = trim(strip_tags($_REQUEST["note"])); |
|
63 | 63 | |
64 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET note = ? |
|
64 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET note = ? |
|
65 | 65 | WHERE ref_id = ? AND owner_uid = ?"); |
66 | - $sth->execute([$note, $id, $_SESSION['uid']]); |
|
66 | + $sth->execute([$note, $id, $_SESSION['uid']]); |
|
67 | 67 | |
68 | - $formatted_note = Article::format_article_note($id, $note); |
|
68 | + $formatted_note = Article::format_article_note($id, $note); |
|
69 | 69 | |
70 | - print json_encode(array("note" => $formatted_note, |
|
71 | - "raw_length" => mb_strlen($note))); |
|
72 | - } |
|
70 | + print json_encode(array("note" => $formatted_note, |
|
71 | + "raw_length" => mb_strlen($note))); |
|
72 | + } |
|
73 | 73 | |
74 | - public function api_version() { |
|
75 | - return 2; |
|
76 | - } |
|
74 | + public function api_version() { |
|
75 | + return 2; |
|
76 | + } |
|
77 | 77 | |
78 | 78 | } |
@@ -14,7 +14,7 @@ |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | public function get_js() { |
17 | - return file_get_contents(__DIR__ . "/init.js"); |
|
17 | + return file_get_contents(__DIR__."/init.js"); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | public function api_version() { |
@@ -1,24 +1,24 @@ |
||
1 | 1 | <?php |
2 | 2 | class No_Title_Counters extends Plugin { |
3 | - private $host; |
|
3 | + private $host; |
|
4 | 4 | |
5 | - public function about() { |
|
6 | - return array(1.0, |
|
7 | - "Remove counters from window title (prevents tab flashing on new articles)", |
|
8 | - "fox"); |
|
9 | - } |
|
5 | + public function about() { |
|
6 | + return array(1.0, |
|
7 | + "Remove counters from window title (prevents tab flashing on new articles)", |
|
8 | + "fox"); |
|
9 | + } |
|
10 | 10 | |
11 | - public function init($host) { |
|
12 | - $this->host = $host; |
|
11 | + public function init($host) { |
|
12 | + $this->host = $host; |
|
13 | 13 | |
14 | - } |
|
14 | + } |
|
15 | 15 | |
16 | - public function get_js() { |
|
17 | - return file_get_contents(__DIR__ . "/init.js"); |
|
18 | - } |
|
16 | + public function get_js() { |
|
17 | + return file_get_contents(__DIR__ . "/init.js"); |
|
18 | + } |
|
19 | 19 | |
20 | - public function api_version() { |
|
21 | - return 2; |
|
22 | - } |
|
20 | + public function api_version() { |
|
21 | + return 2; |
|
22 | + } |
|
23 | 23 | |
24 | 24 | } |