@@ -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 | } |
@@ -1,91 +1,91 @@ |
||
1 | 1 | <?php |
2 | 2 | class Af_Tumblr_1280 extends Plugin { |
3 | - private $host; |
|
3 | + private $host; |
|
4 | 4 | |
5 | - public function about() { |
|
6 | - return array(1.0, |
|
7 | - "Replace Tumblr pictures and videos with largest size if available (requires CURL)", |
|
8 | - "fox"); |
|
9 | - } |
|
5 | + public function about() { |
|
6 | + return array(1.0, |
|
7 | + "Replace Tumblr pictures and videos with largest size if available (requires CURL)", |
|
8 | + "fox"); |
|
9 | + } |
|
10 | 10 | |
11 | - public function flags() { |
|
12 | - return array("needs_curl" => true); |
|
13 | - } |
|
11 | + public function flags() { |
|
12 | + return array("needs_curl" => true); |
|
13 | + } |
|
14 | 14 | |
15 | - public function init($host) { |
|
16 | - $this->host = $host; |
|
15 | + public function init($host) { |
|
16 | + $this->host = $host; |
|
17 | 17 | |
18 | - if (function_exists("curl_init")) { |
|
19 | - $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); |
|
20 | - } |
|
21 | - } |
|
18 | + if (function_exists("curl_init")) { |
|
19 | + $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); |
|
20 | + } |
|
21 | + } |
|
22 | 22 | |
23 | - public function hook_article_filter($article) { |
|
23 | + public function hook_article_filter($article) { |
|
24 | 24 | |
25 | - if (!function_exists("curl_init") || ini_get("open_basedir")) |
|
26 | - return $article; |
|
25 | + if (!function_exists("curl_init") || ini_get("open_basedir")) |
|
26 | + return $article; |
|
27 | 27 | |
28 | - $doc = new DOMDocument(); |
|
29 | - $doc->loadHTML('<?xml encoding="UTF-8">' . $article["content"]); |
|
28 | + $doc = new DOMDocument(); |
|
29 | + $doc->loadHTML('<?xml encoding="UTF-8">' . $article["content"]); |
|
30 | 30 | |
31 | - $found = false; |
|
31 | + $found = false; |
|
32 | 32 | |
33 | - if ($doc) { |
|
34 | - $xpath = new DOMXpath($doc); |
|
33 | + if ($doc) { |
|
34 | + $xpath = new DOMXpath($doc); |
|
35 | 35 | |
36 | - $images = $xpath->query('(//img[contains(@src, \'media.tumblr.com\')])'); |
|
36 | + $images = $xpath->query('(//img[contains(@src, \'media.tumblr.com\')])'); |
|
37 | 37 | |
38 | - foreach ($images as $img) { |
|
39 | - $src = $img->getAttribute("src"); |
|
38 | + foreach ($images as $img) { |
|
39 | + $src = $img->getAttribute("src"); |
|
40 | 40 | |
41 | - $test_src = preg_replace("/_\d{3}.(jpg|gif|png)/", "_1280.$1", $src); |
|
41 | + $test_src = preg_replace("/_\d{3}.(jpg|gif|png)/", "_1280.$1", $src); |
|
42 | 42 | |
43 | - if ($src != $test_src) { |
|
43 | + if ($src != $test_src) { |
|
44 | 44 | |
45 | - $ch = curl_init($test_src); |
|
46 | - curl_setopt($ch, CURLOPT_TIMEOUT, 5); |
|
47 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
48 | - curl_setopt($ch, CURLOPT_HEADER, true); |
|
49 | - curl_setopt($ch, CURLOPT_NOBODY, true); |
|
50 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|
51 | - curl_setopt($ch, CURLOPT_USERAGENT, SELF_USER_AGENT); |
|
45 | + $ch = curl_init($test_src); |
|
46 | + curl_setopt($ch, CURLOPT_TIMEOUT, 5); |
|
47 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
48 | + curl_setopt($ch, CURLOPT_HEADER, true); |
|
49 | + curl_setopt($ch, CURLOPT_NOBODY, true); |
|
50 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|
51 | + curl_setopt($ch, CURLOPT_USERAGENT, SELF_USER_AGENT); |
|
52 | 52 | |
53 | - @$result = curl_exec($ch); |
|
54 | - $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
53 | + @$result = curl_exec($ch); |
|
54 | + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
55 | 55 | |
56 | - if ($result && $http_code == 200) { |
|
57 | - $img->setAttribute("src", $test_src); |
|
58 | - $found = true; |
|
59 | - } |
|
60 | - } |
|
61 | - } |
|
56 | + if ($result && $http_code == 200) { |
|
57 | + $img->setAttribute("src", $test_src); |
|
58 | + $found = true; |
|
59 | + } |
|
60 | + } |
|
61 | + } |
|
62 | 62 | |
63 | - $video_sources = $xpath->query('//video/source[contains(@src, \'.tumblr.com/video_file\')]'); |
|
63 | + $video_sources = $xpath->query('//video/source[contains(@src, \'.tumblr.com/video_file\')]'); |
|
64 | 64 | |
65 | - foreach ($video_sources as $source) { |
|
66 | - $src = $source->getAttribute("src"); |
|
65 | + foreach ($video_sources as $source) { |
|
66 | + $src = $source->getAttribute("src"); |
|
67 | 67 | |
68 | - $new_src = preg_replace("/\/\d{3}$/", "", $src); |
|
68 | + $new_src = preg_replace("/\/\d{3}$/", "", $src); |
|
69 | 69 | |
70 | - if ($src != $new_src) { |
|
71 | - $source->setAttribute("src", $new_src); |
|
72 | - $found = true; |
|
73 | - } |
|
74 | - } |
|
70 | + if ($src != $new_src) { |
|
71 | + $source->setAttribute("src", $new_src); |
|
72 | + $found = true; |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | - if ($found) { |
|
77 | - $doc->removeChild($doc->firstChild); //remove doctype |
|
78 | - $article["content"] = $doc->saveHTML(); |
|
79 | - } |
|
80 | - } |
|
76 | + if ($found) { |
|
77 | + $doc->removeChild($doc->firstChild); //remove doctype |
|
78 | + $article["content"] = $doc->saveHTML(); |
|
79 | + } |
|
80 | + } |
|
81 | 81 | |
82 | - return $article; |
|
82 | + return $article; |
|
83 | 83 | |
84 | - } |
|
84 | + } |
|
85 | 85 | |
86 | 86 | |
87 | - public function api_version() { |
|
88 | - return 2; |
|
89 | - } |
|
87 | + public function api_version() { |
|
88 | + return 2; |
|
89 | + } |
|
90 | 90 | |
91 | 91 | } |
@@ -1,38 +1,38 @@ |
||
1 | 1 | <?php |
2 | 2 | class Close_Button extends Plugin { |
3 | - private $host; |
|
4 | - |
|
5 | - public function init($host) { |
|
6 | - $this->host = $host; |
|
7 | - |
|
8 | - $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this); |
|
9 | - } |
|
10 | - |
|
11 | - public function about() { |
|
12 | - return array(1.0, |
|
13 | - "Adds a button to close article panel", |
|
14 | - "fox"); |
|
15 | - } |
|
16 | - |
|
17 | - public function get_css() { |
|
18 | - return "i.icon-close-article { color : red; }"; |
|
19 | - } |
|
20 | - |
|
21 | - /** |
|
22 | - * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
23 | - */ |
|
24 | - public function hook_article_button($line) { |
|
25 | - if (!get_pref("COMBINED_DISPLAY_MODE")) { |
|
26 | - $rv = "<i class='material-icons icon-close-article' |
|
3 | + private $host; |
|
4 | + |
|
5 | + public function init($host) { |
|
6 | + $this->host = $host; |
|
7 | + |
|
8 | + $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this); |
|
9 | + } |
|
10 | + |
|
11 | + public function about() { |
|
12 | + return array(1.0, |
|
13 | + "Adds a button to close article panel", |
|
14 | + "fox"); |
|
15 | + } |
|
16 | + |
|
17 | + public function get_css() { |
|
18 | + return "i.icon-close-article { color : red; }"; |
|
19 | + } |
|
20 | + |
|
21 | + /** |
|
22 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
23 | + */ |
|
24 | + public function hook_article_button($line) { |
|
25 | + if (!get_pref("COMBINED_DISPLAY_MODE")) { |
|
26 | + $rv = "<i class='material-icons icon-close-article' |
|
27 | 27 | style='cursor : pointer' onclick='Article.close()' |
28 | 28 | title='".__('Close article')."'>close</i>"; |
29 | - } |
|
29 | + } |
|
30 | 30 | |
31 | - return $rv; |
|
32 | - } |
|
31 | + return $rv; |
|
32 | + } |
|
33 | 33 | |
34 | - public function api_version() { |
|
35 | - return 2; |
|
36 | - } |
|
34 | + public function api_version() { |
|
35 | + return 2; |
|
36 | + } |
|
37 | 37 | |
38 | 38 | } |
@@ -1,57 +1,57 @@ |
||
1 | 1 | <?php |
2 | 2 | class Auto_Assign_Labels 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 | - "Assign labels automatically based on article title, content, and tags", |
|
10 | - "fox"); |
|
11 | - } |
|
7 | + public function about() { |
|
8 | + return array(1.0, |
|
9 | + "Assign labels automatically based on article title, content, and tags", |
|
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_FILTER, $this); |
|
17 | - } |
|
16 | + $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); |
|
17 | + } |
|
18 | 18 | |
19 | - public function get_all_labels_filter_format($owner_uid) { |
|
20 | - $rv = array(); |
|
19 | + public function get_all_labels_filter_format($owner_uid) { |
|
20 | + $rv = array(); |
|
21 | 21 | |
22 | - $sth = $this->pdo->prepare("SELECT id, fg_color, bg_color, caption FROM ttrss_labels2 WHERE owner_uid = ?"); |
|
23 | - $sth->execute([$owner_uid]); |
|
22 | + $sth = $this->pdo->prepare("SELECT id, fg_color, bg_color, caption FROM ttrss_labels2 WHERE owner_uid = ?"); |
|
23 | + $sth->execute([$owner_uid]); |
|
24 | 24 | |
25 | - while ($line = $sth->fetch()) { |
|
26 | - array_push($rv, array(Labels::label_to_feed_id($line["id"]), |
|
27 | - $line["caption"], $line["fg_color"], $line["bg_color"])); |
|
28 | - } |
|
25 | + while ($line = $sth->fetch()) { |
|
26 | + array_push($rv, array(Labels::label_to_feed_id($line["id"]), |
|
27 | + $line["caption"], $line["fg_color"], $line["bg_color"])); |
|
28 | + } |
|
29 | 29 | |
30 | - return $rv; |
|
31 | - } |
|
30 | + return $rv; |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - public function hook_article_filter($article) { |
|
34 | + public function hook_article_filter($article) { |
|
35 | 35 | |
36 | - $owner_uid = $article["owner_uid"]; |
|
37 | - $labels = $this->get_all_labels_filter_format($owner_uid); |
|
38 | - $tags_str = join(",", $article["tags"]); |
|
36 | + $owner_uid = $article["owner_uid"]; |
|
37 | + $labels = $this->get_all_labels_filter_format($owner_uid); |
|
38 | + $tags_str = join(",", $article["tags"]); |
|
39 | 39 | |
40 | - foreach ($labels as $label) { |
|
41 | - $caption = preg_quote($label[1], "/"); |
|
40 | + foreach ($labels as $label) { |
|
41 | + $caption = preg_quote($label[1], "/"); |
|
42 | 42 | |
43 | - if ($caption && preg_match("/\b$caption\b/i", "$tags_str " . strip_tags($article["content"]) . " " . $article["title"])) { |
|
43 | + if ($caption && preg_match("/\b$caption\b/i", "$tags_str " . strip_tags($article["content"]) . " " . $article["title"])) { |
|
44 | 44 | |
45 | - if (!RSSUtils::labels_contains_caption($article["labels"], $caption)) { |
|
46 | - array_push($article["labels"], $label); |
|
47 | - } |
|
48 | - } |
|
49 | - } |
|
45 | + if (!RSSUtils::labels_contains_caption($article["labels"], $caption)) { |
|
46 | + array_push($article["labels"], $label); |
|
47 | + } |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | - return $article; |
|
52 | - } |
|
51 | + return $article; |
|
52 | + } |
|
53 | 53 | |
54 | - public function api_version() { |
|
55 | - return 2; |
|
56 | - } |
|
54 | + public function api_version() { |
|
55 | + return 2; |
|
56 | + } |
|
57 | 57 | } |
@@ -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 | } |
@@ -1,63 +1,63 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class Auth_Internal extends Plugin implements IAuthModule { |
3 | 3 | |
4 | - private $host; |
|
4 | + private $host; |
|
5 | 5 | |
6 | - public function about() { |
|
7 | - return array(1.0, |
|
8 | - "Authenticates against internal tt-rss database", |
|
9 | - "fox", |
|
10 | - true); |
|
11 | - } |
|
6 | + public function about() { |
|
7 | + return array(1.0, |
|
8 | + "Authenticates against internal tt-rss database", |
|
9 | + "fox", |
|
10 | + true); |
|
11 | + } |
|
12 | 12 | |
13 | - /* @var PluginHost $host */ |
|
14 | - public function init($host) { |
|
15 | - $this->host = $host; |
|
16 | - $this->pdo = Db::pdo(); |
|
13 | + /* @var PluginHost $host */ |
|
14 | + public function init($host) { |
|
15 | + $this->host = $host; |
|
16 | + $this->pdo = Db::pdo(); |
|
17 | 17 | |
18 | - $host->add_hook($host::HOOK_AUTH_USER, $this); |
|
19 | - } |
|
18 | + $host->add_hook($host::HOOK_AUTH_USER, $this); |
|
19 | + } |
|
20 | 20 | |
21 | - public function authenticate($login, $password, $service = '') { |
|
21 | + public function authenticate($login, $password, $service = '') { |
|
22 | 22 | |
23 | - $pwd_hash1 = encrypt_password($password); |
|
24 | - $pwd_hash2 = encrypt_password($password, $login); |
|
25 | - $otp = $_REQUEST["otp"]; |
|
23 | + $pwd_hash1 = encrypt_password($password); |
|
24 | + $pwd_hash2 = encrypt_password($password, $login); |
|
25 | + $otp = $_REQUEST["otp"]; |
|
26 | 26 | |
27 | - if (get_schema_version() > 96) { |
|
27 | + if (get_schema_version() > 96) { |
|
28 | 28 | |
29 | - $sth = $this->pdo->prepare("SELECT otp_enabled,salt FROM ttrss_users WHERE |
|
29 | + $sth = $this->pdo->prepare("SELECT otp_enabled,salt FROM ttrss_users WHERE |
|
30 | 30 | login = ?"); |
31 | - $sth->execute([$login]); |
|
31 | + $sth->execute([$login]); |
|
32 | 32 | |
33 | - if ($row = $sth->fetch()) { |
|
34 | - $otp_enabled = $row['otp_enabled']; |
|
33 | + if ($row = $sth->fetch()) { |
|
34 | + $otp_enabled = $row['otp_enabled']; |
|
35 | 35 | |
36 | - if ($otp_enabled) { |
|
36 | + if ($otp_enabled) { |
|
37 | 37 | |
38 | - // only allow app password checking if OTP is enabled |
|
39 | - if ($service && get_schema_version() > 138) { |
|
40 | - return $this->check_app_password($login, $password, $service); |
|
41 | - } |
|
38 | + // only allow app password checking if OTP is enabled |
|
39 | + if ($service && get_schema_version() > 138) { |
|
40 | + return $this->check_app_password($login, $password, $service); |
|
41 | + } |
|
42 | 42 | |
43 | - if ($otp) { |
|
44 | - $base32 = new \OTPHP\Base32(); |
|
43 | + if ($otp) { |
|
44 | + $base32 = new \OTPHP\Base32(); |
|
45 | 45 | |
46 | - $secret = $base32->encode(mb_substr(sha1($row["salt"]), 0, 12), false); |
|
47 | - $secret_legacy = $base32->encode(sha1($row["salt"])); |
|
46 | + $secret = $base32->encode(mb_substr(sha1($row["salt"]), 0, 12), false); |
|
47 | + $secret_legacy = $base32->encode(sha1($row["salt"])); |
|
48 | 48 | |
49 | - $totp = new \OTPHP\TOTP($secret); |
|
50 | - $otp_check = $totp->now(); |
|
49 | + $totp = new \OTPHP\TOTP($secret); |
|
50 | + $otp_check = $totp->now(); |
|
51 | 51 | |
52 | - $totp_legacy = new \OTPHP\TOTP($secret_legacy); |
|
53 | - $otp_check_legacy = $totp_legacy->now(); |
|
52 | + $totp_legacy = new \OTPHP\TOTP($secret_legacy); |
|
53 | + $otp_check_legacy = $totp_legacy->now(); |
|
54 | 54 | |
55 | - if ($otp != $otp_check && $otp != $otp_check_legacy) { |
|
56 | - return false; |
|
57 | - } |
|
58 | - } else { |
|
59 | - $return = urlencode($_REQUEST["return"]); |
|
60 | - ?> |
|
55 | + if ($otp != $otp_check && $otp != $otp_check_legacy) { |
|
56 | + return false; |
|
57 | + } |
|
58 | + } else { |
|
59 | + $return = urlencode($_REQUEST["return"]); |
|
60 | + ?> |
|
61 | 61 | <!DOCTYPE html> |
62 | 62 | <html> |
63 | 63 | <head> |
@@ -87,208 +87,208 @@ discard block |
||
87 | 87 | document.forms[0].otp.focus(); |
88 | 88 | </script> |
89 | 89 | <?php |
90 | - exit; |
|
91 | - } |
|
92 | - } |
|
93 | - } |
|
94 | - } |
|
90 | + exit; |
|
91 | + } |
|
92 | + } |
|
93 | + } |
|
94 | + } |
|
95 | 95 | |
96 | - // check app passwords first but allow regular password as a fallback for the time being |
|
97 | - // if OTP is not enabled |
|
96 | + // check app passwords first but allow regular password as a fallback for the time being |
|
97 | + // if OTP is not enabled |
|
98 | 98 | |
99 | - if ($service && get_schema_version() > 138) { |
|
100 | - $user_id = $this->check_app_password($login, $password, $service); |
|
99 | + if ($service && get_schema_version() > 138) { |
|
100 | + $user_id = $this->check_app_password($login, $password, $service); |
|
101 | 101 | |
102 | - if ($user_id) |
|
103 | - return $user_id; |
|
104 | - } |
|
102 | + if ($user_id) |
|
103 | + return $user_id; |
|
104 | + } |
|
105 | 105 | |
106 | - if (get_schema_version() > 87) { |
|
106 | + if (get_schema_version() > 87) { |
|
107 | 107 | |
108 | - $sth = $this->pdo->prepare("SELECT salt FROM ttrss_users WHERE login = ?"); |
|
109 | - $sth->execute([$login]); |
|
108 | + $sth = $this->pdo->prepare("SELECT salt FROM ttrss_users WHERE login = ?"); |
|
109 | + $sth->execute([$login]); |
|
110 | 110 | |
111 | - if ($row = $sth->fetch()) { |
|
112 | - $salt = $row['salt']; |
|
111 | + if ($row = $sth->fetch()) { |
|
112 | + $salt = $row['salt']; |
|
113 | 113 | |
114 | - if ($salt == "") { |
|
114 | + if ($salt == "") { |
|
115 | 115 | |
116 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE |
|
116 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE |
|
117 | 117 | login = ? AND (pwd_hash = ? OR pwd_hash = ?)"); |
118 | 118 | |
119 | - $sth->execute([$login, $pwd_hash1, $pwd_hash2]); |
|
119 | + $sth->execute([$login, $pwd_hash1, $pwd_hash2]); |
|
120 | 120 | |
121 | - // verify and upgrade password to new salt base |
|
121 | + // verify and upgrade password to new salt base |
|
122 | 122 | |
123 | - if ($row = $sth->fetch()) { |
|
124 | - // upgrade password to MODE2 |
|
123 | + if ($row = $sth->fetch()) { |
|
124 | + // upgrade password to MODE2 |
|
125 | 125 | |
126 | - $user_id = $row['id']; |
|
126 | + $user_id = $row['id']; |
|
127 | 127 | |
128 | - $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
129 | - $pwd_hash = encrypt_password($password, $salt, true); |
|
128 | + $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
129 | + $pwd_hash = encrypt_password($password, $salt, true); |
|
130 | 130 | |
131 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET |
|
131 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET |
|
132 | 132 | pwd_hash = ?, salt = ? WHERE login = ?"); |
133 | 133 | |
134 | - $sth->execute([$pwd_hash, $salt, $login]); |
|
134 | + $sth->execute([$pwd_hash, $salt, $login]); |
|
135 | 135 | |
136 | - return $user_id; |
|
136 | + return $user_id; |
|
137 | 137 | |
138 | - } else { |
|
139 | - return false; |
|
140 | - } |
|
138 | + } else { |
|
139 | + return false; |
|
140 | + } |
|
141 | 141 | |
142 | - } else { |
|
143 | - $pwd_hash = encrypt_password($password, $salt, true); |
|
142 | + } else { |
|
143 | + $pwd_hash = encrypt_password($password, $salt, true); |
|
144 | 144 | |
145 | - $sth = $this->pdo->prepare("SELECT id |
|
145 | + $sth = $this->pdo->prepare("SELECT id |
|
146 | 146 | FROM ttrss_users WHERE |
147 | 147 | login = ? AND pwd_hash = ?"); |
148 | - $sth->execute([$login, $pwd_hash]); |
|
148 | + $sth->execute([$login, $pwd_hash]); |
|
149 | 149 | |
150 | - if ($row = $sth->fetch()) { |
|
151 | - return $row['id']; |
|
152 | - } |
|
153 | - } |
|
150 | + if ($row = $sth->fetch()) { |
|
151 | + return $row['id']; |
|
152 | + } |
|
153 | + } |
|
154 | 154 | |
155 | - } else { |
|
156 | - $sth = $this->pdo->prepare("SELECT id |
|
155 | + } else { |
|
156 | + $sth = $this->pdo->prepare("SELECT id |
|
157 | 157 | FROM ttrss_users WHERE |
158 | 158 | login = ? AND (pwd_hash = ? OR pwd_hash = ?)"); |
159 | 159 | |
160 | - $sth->execute([$login, $pwd_hash1, $pwd_hash2]); |
|
160 | + $sth->execute([$login, $pwd_hash1, $pwd_hash2]); |
|
161 | 161 | |
162 | - if ($row = $sth->fetch()) { |
|
163 | - return $row['id']; |
|
164 | - } |
|
165 | - } |
|
166 | - } else { |
|
167 | - $sth = $this->pdo->prepare("SELECT id |
|
162 | + if ($row = $sth->fetch()) { |
|
163 | + return $row['id']; |
|
164 | + } |
|
165 | + } |
|
166 | + } else { |
|
167 | + $sth = $this->pdo->prepare("SELECT id |
|
168 | 168 | FROM ttrss_users WHERE |
169 | 169 | login = ? AND (pwd_hash = ? OR pwd_hash = ?)"); |
170 | 170 | |
171 | - $sth->execute([$login, $pwd_hash1, $pwd_hash2]); |
|
171 | + $sth->execute([$login, $pwd_hash1, $pwd_hash2]); |
|
172 | 172 | |
173 | - if ($row = $sth->fetch()) { |
|
174 | - return $row['id']; |
|
175 | - } |
|
176 | - } |
|
173 | + if ($row = $sth->fetch()) { |
|
174 | + return $row['id']; |
|
175 | + } |
|
176 | + } |
|
177 | 177 | |
178 | - return false; |
|
179 | - } |
|
178 | + return false; |
|
179 | + } |
|
180 | 180 | |
181 | - public function check_password($owner_uid, $password) { |
|
181 | + public function check_password($owner_uid, $password) { |
|
182 | 182 | |
183 | - $sth = $this->pdo->prepare("SELECT salt,login,otp_enabled FROM ttrss_users WHERE |
|
183 | + $sth = $this->pdo->prepare("SELECT salt,login,otp_enabled FROM ttrss_users WHERE |
|
184 | 184 | id = ?"); |
185 | - $sth->execute([$owner_uid]); |
|
185 | + $sth->execute([$owner_uid]); |
|
186 | 186 | |
187 | - if ($row = $sth->fetch()) { |
|
187 | + if ($row = $sth->fetch()) { |
|
188 | 188 | |
189 | - $salt = $row['salt']; |
|
190 | - $login = $row['login']; |
|
189 | + $salt = $row['salt']; |
|
190 | + $login = $row['login']; |
|
191 | 191 | |
192 | - if (!$salt) { |
|
193 | - $password_hash1 = encrypt_password($password); |
|
194 | - $password_hash2 = encrypt_password($password, $login); |
|
192 | + if (!$salt) { |
|
193 | + $password_hash1 = encrypt_password($password); |
|
194 | + $password_hash2 = encrypt_password($password, $login); |
|
195 | 195 | |
196 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE |
|
196 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE |
|
197 | 197 | id = ? AND (pwd_hash = ? OR pwd_hash = ?)"); |
198 | 198 | |
199 | - $sth->execute([$owner_uid, $password_hash1, $password_hash2]); |
|
199 | + $sth->execute([$owner_uid, $password_hash1, $password_hash2]); |
|
200 | 200 | |
201 | - return $sth->fetch(); |
|
201 | + return $sth->fetch(); |
|
202 | 202 | |
203 | - } else { |
|
204 | - $password_hash = encrypt_password($password, $salt, true); |
|
203 | + } else { |
|
204 | + $password_hash = encrypt_password($password, $salt, true); |
|
205 | 205 | |
206 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE |
|
206 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE |
|
207 | 207 | id = ? AND pwd_hash = ?"); |
208 | 208 | |
209 | - $sth->execute([$owner_uid, $password_hash]); |
|
209 | + $sth->execute([$owner_uid, $password_hash]); |
|
210 | 210 | |
211 | - return $sth->fetch(); |
|
212 | - } |
|
213 | - } |
|
211 | + return $sth->fetch(); |
|
212 | + } |
|
213 | + } |
|
214 | 214 | |
215 | - return false; |
|
216 | - } |
|
215 | + return false; |
|
216 | + } |
|
217 | 217 | |
218 | - public function change_password($owner_uid, $old_password, $new_password) { |
|
218 | + public function change_password($owner_uid, $old_password, $new_password) { |
|
219 | 219 | |
220 | - if ($this->check_password($owner_uid, $old_password)) { |
|
220 | + if ($this->check_password($owner_uid, $old_password)) { |
|
221 | 221 | |
222 | - $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
223 | - $new_password_hash = encrypt_password($new_password, $new_salt, true); |
|
222 | + $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
223 | + $new_password_hash = encrypt_password($new_password, $new_salt, true); |
|
224 | 224 | |
225 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET |
|
225 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET |
|
226 | 226 | pwd_hash = ?, salt = ?, otp_enabled = false |
227 | 227 | WHERE id = ?"); |
228 | - $sth->execute([$new_password_hash, $new_salt, $owner_uid]); |
|
228 | + $sth->execute([$new_password_hash, $new_salt, $owner_uid]); |
|
229 | 229 | |
230 | - $_SESSION["pwd_hash"] = $new_password_hash; |
|
230 | + $_SESSION["pwd_hash"] = $new_password_hash; |
|
231 | 231 | |
232 | - $sth = $this->pdo->prepare("SELECT email, login FROM ttrss_users WHERE id = ?"); |
|
233 | - $sth->execute([$owner_uid]); |
|
232 | + $sth = $this->pdo->prepare("SELECT email, login FROM ttrss_users WHERE id = ?"); |
|
233 | + $sth->execute([$owner_uid]); |
|
234 | 234 | |
235 | - if ($row = $sth->fetch()) { |
|
236 | - $mailer = new Mailer(); |
|
235 | + if ($row = $sth->fetch()) { |
|
236 | + $mailer = new Mailer(); |
|
237 | 237 | |
238 | - require_once "lib/MiniTemplator.class.php"; |
|
238 | + require_once "lib/MiniTemplator.class.php"; |
|
239 | 239 | |
240 | - $tpl = new MiniTemplator; |
|
240 | + $tpl = new MiniTemplator; |
|
241 | 241 | |
242 | - $tpl->readTemplateFromFile("templates/password_change_template.txt"); |
|
242 | + $tpl->readTemplateFromFile("templates/password_change_template.txt"); |
|
243 | 243 | |
244 | - $tpl->setVariable('LOGIN', $row["login"]); |
|
245 | - $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
244 | + $tpl->setVariable('LOGIN', $row["login"]); |
|
245 | + $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
246 | 246 | |
247 | - $tpl->addBlock('message'); |
|
247 | + $tpl->addBlock('message'); |
|
248 | 248 | |
249 | - $tpl->generateOutputToString($message); |
|
249 | + $tpl->generateOutputToString($message); |
|
250 | 250 | |
251 | - $mailer->mail(["to_name" => $row["login"], |
|
252 | - "to_address" => $row["email"], |
|
253 | - "subject" => "[tt-rss] Password change notification", |
|
254 | - "message" => $message]); |
|
251 | + $mailer->mail(["to_name" => $row["login"], |
|
252 | + "to_address" => $row["email"], |
|
253 | + "subject" => "[tt-rss] Password change notification", |
|
254 | + "message" => $message]); |
|
255 | 255 | |
256 | - } |
|
256 | + } |
|
257 | 257 | |
258 | - return __("Password has been changed."); |
|
259 | - } else { |
|
260 | - return "ERROR: ".__('Old password is incorrect.'); |
|
261 | - } |
|
262 | - } |
|
258 | + return __("Password has been changed."); |
|
259 | + } else { |
|
260 | + return "ERROR: ".__('Old password is incorrect.'); |
|
261 | + } |
|
262 | + } |
|
263 | 263 | |
264 | - private function check_app_password($login, $password, $service) { |
|
265 | - $sth = $this->pdo->prepare("SELECT p.id, p.pwd_hash, u.id AS uid |
|
264 | + private function check_app_password($login, $password, $service) { |
|
265 | + $sth = $this->pdo->prepare("SELECT p.id, p.pwd_hash, u.id AS uid |
|
266 | 266 | FROM ttrss_app_passwords p, ttrss_users u |
267 | 267 | WHERE p.owner_uid = u.id AND u.login = ? AND service = ?"); |
268 | - $sth->execute([$login, $service]); |
|
268 | + $sth->execute([$login, $service]); |
|
269 | 269 | |
270 | - while ($row = $sth->fetch()) { |
|
271 | - list ($algo, $hash, $salt) = explode(":", $row["pwd_hash"]); |
|
270 | + while ($row = $sth->fetch()) { |
|
271 | + list ($algo, $hash, $salt) = explode(":", $row["pwd_hash"]); |
|
272 | 272 | |
273 | - if ($algo == "SSHA-512") { |
|
274 | - $test_hash = hash('sha512', $salt . $password); |
|
273 | + if ($algo == "SSHA-512") { |
|
274 | + $test_hash = hash('sha512', $salt . $password); |
|
275 | 275 | |
276 | - if ($test_hash == $hash) { |
|
277 | - $usth = $this->pdo->prepare("UPDATE ttrss_app_passwords SET last_used = NOW() WHERE id = ?"); |
|
278 | - $usth->execute([$row['id']]); |
|
276 | + if ($test_hash == $hash) { |
|
277 | + $usth = $this->pdo->prepare("UPDATE ttrss_app_passwords SET last_used = NOW() WHERE id = ?"); |
|
278 | + $usth->execute([$row['id']]); |
|
279 | 279 | |
280 | - return $row['uid']; |
|
281 | - } |
|
282 | - } else { |
|
283 | - user_error("Got unknown algo of app password for user $login: $algo"); |
|
284 | - } |
|
285 | - } |
|
280 | + return $row['uid']; |
|
281 | + } |
|
282 | + } else { |
|
283 | + user_error("Got unknown algo of app password for user $login: $algo"); |
|
284 | + } |
|
285 | + } |
|
286 | 286 | |
287 | - return false; |
|
288 | - } |
|
287 | + return false; |
|
288 | + } |
|
289 | 289 | |
290 | - public function api_version() { |
|
291 | - return 2; |
|
292 | - } |
|
290 | + public function api_version() { |
|
291 | + return 2; |
|
292 | + } |
|
293 | 293 | |
294 | 294 | } |
@@ -1,43 +1,43 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class Cache_Starred_Images extends Plugin { |
3 | 3 | |
4 | - /* @var PluginHost $host */ |
|
5 | - private $host; |
|
6 | - /* @var DiskCache $cache */ |
|
7 | - private $cache; |
|
4 | + /* @var PluginHost $host */ |
|
5 | + private $host; |
|
6 | + /* @var DiskCache $cache */ |
|
7 | + private $cache; |
|
8 | 8 | private $max_cache_attempts = 5; // per-article |
9 | 9 | |
10 | - public function about() { |
|
11 | - return array(1.0, |
|
12 | - "Automatically cache media files in Starred articles", |
|
13 | - "fox"); |
|
14 | - } |
|
10 | + public function about() { |
|
11 | + return array(1.0, |
|
12 | + "Automatically cache media files in Starred articles", |
|
13 | + "fox"); |
|
14 | + } |
|
15 | 15 | |
16 | - public function init($host) { |
|
17 | - $this->host = $host; |
|
18 | - $this->cache = new DiskCache("starred-images"); |
|
16 | + public function init($host) { |
|
17 | + $this->host = $host; |
|
18 | + $this->cache = new DiskCache("starred-images"); |
|
19 | 19 | |
20 | - if ($this->cache->makeDir()) |
|
21 | - chmod($this->cache->getDir(), 0777); |
|
20 | + if ($this->cache->makeDir()) |
|
21 | + chmod($this->cache->getDir(), 0777); |
|
22 | 22 | |
23 | - if (!$this->cache->exists(".no-auto-expiry")) |
|
24 | - $this->cache->touch(".no-auto-expiry"); |
|
23 | + if (!$this->cache->exists(".no-auto-expiry")) |
|
24 | + $this->cache->touch(".no-auto-expiry"); |
|
25 | 25 | |
26 | - if ($this->cache->isWritable()) { |
|
27 | - $host->add_hook($host::HOOK_HOUSE_KEEPING, $this); |
|
28 | - $host->add_hook($host::HOOK_ENCLOSURE_ENTRY, $this); |
|
29 | - $host->add_hook($host::HOOK_SANITIZE, $this); |
|
30 | - } else { |
|
31 | - user_error("Starred cache directory ".$this->cache->getDir()." is not writable.", E_USER_WARNING); |
|
32 | - } |
|
33 | - } |
|
26 | + if ($this->cache->isWritable()) { |
|
27 | + $host->add_hook($host::HOOK_HOUSE_KEEPING, $this); |
|
28 | + $host->add_hook($host::HOOK_ENCLOSURE_ENTRY, $this); |
|
29 | + $host->add_hook($host::HOOK_SANITIZE, $this); |
|
30 | + } else { |
|
31 | + user_error("Starred cache directory ".$this->cache->getDir()." is not writable.", E_USER_WARNING); |
|
32 | + } |
|
33 | + } |
|
34 | 34 | |
35 | - public function hook_house_keeping() { |
|
36 | - /* since HOOK_UPDATE_TASK is not available to user plugins, this hook is a next best thing */ |
|
35 | + public function hook_house_keeping() { |
|
36 | + /* since HOOK_UPDATE_TASK is not available to user plugins, this hook is a next best thing */ |
|
37 | 37 | |
38 | - Debug::log("caching media of starred articles for user " . $this->host->get_owner_uid() . "..."); |
|
38 | + Debug::log("caching media of starred articles for user " . $this->host->get_owner_uid() . "..."); |
|
39 | 39 | |
40 | - $sth = $this->pdo->prepare("SELECT content, ttrss_entries.title, |
|
40 | + $sth = $this->pdo->prepare("SELECT content, ttrss_entries.title, |
|
41 | 41 | ttrss_user_entries.owner_uid, link, site_url, ttrss_entries.id, plugin_data |
42 | 42 | FROM ttrss_entries, ttrss_user_entries LEFT JOIN ttrss_feeds ON |
43 | 43 | (ttrss_user_entries.feed_id = ttrss_feeds.id) |
@@ -48,115 +48,115 @@ discard block |
||
48 | 48 | plugin_data NOT LIKE '%starred_cache_images%' |
49 | 49 | ORDER BY ".sql_random_function()." LIMIT 100"); |
50 | 50 | |
51 | - if ($sth->execute([$this->host->get_owner_uid()])) { |
|
51 | + if ($sth->execute([$this->host->get_owner_uid()])) { |
|
52 | 52 | |
53 | - $usth = $this->pdo->prepare("UPDATE ttrss_entries SET plugin_data = ? WHERE id = ?"); |
|
53 | + $usth = $this->pdo->prepare("UPDATE ttrss_entries SET plugin_data = ? WHERE id = ?"); |
|
54 | 54 | |
55 | - while ($line = $sth->fetch()) { |
|
56 | - Debug::log("processing article " . $line["title"], Debug::$LOG_VERBOSE); |
|
55 | + while ($line = $sth->fetch()) { |
|
56 | + Debug::log("processing article " . $line["title"], Debug::$LOG_VERBOSE); |
|
57 | 57 | |
58 | - if ($line["site_url"]) { |
|
59 | - $success = $this->cache_article_images($line["content"], $line["site_url"], $line["owner_uid"], $line["id"]); |
|
58 | + if ($line["site_url"]) { |
|
59 | + $success = $this->cache_article_images($line["content"], $line["site_url"], $line["owner_uid"], $line["id"]); |
|
60 | 60 | |
61 | - if ($success) { |
|
62 | - $plugin_data = "starred_cache_images,${line['owner_uid']}:" . $line["plugin_data"]; |
|
61 | + if ($success) { |
|
62 | + $plugin_data = "starred_cache_images,${line['owner_uid']}:" . $line["plugin_data"]; |
|
63 | 63 | |
64 | - $usth->execute([$plugin_data, $line['id']]); |
|
65 | - } |
|
66 | - } |
|
67 | - } |
|
68 | - } |
|
64 | + $usth->execute([$plugin_data, $line['id']]); |
|
65 | + } |
|
66 | + } |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - /* actual housekeeping */ |
|
70 | + /* actual housekeeping */ |
|
71 | 71 | |
72 | - Debug::log("expiring " . $this->cache->getDir() . "..."); |
|
72 | + Debug::log("expiring " . $this->cache->getDir() . "..."); |
|
73 | 73 | |
74 | - $files = glob($this->cache->getDir() . "/*.{png,mp4,status}", GLOB_BRACE); |
|
74 | + $files = glob($this->cache->getDir() . "/*.{png,mp4,status}", GLOB_BRACE); |
|
75 | 75 | |
76 | - $last_article_id = 0; |
|
77 | - $article_exists = 1; |
|
76 | + $last_article_id = 0; |
|
77 | + $article_exists = 1; |
|
78 | 78 | |
79 | - foreach ($files as $file) { |
|
80 | - list ($article_id, $hash) = explode("-", basename($file)); |
|
79 | + foreach ($files as $file) { |
|
80 | + list ($article_id, $hash) = explode("-", basename($file)); |
|
81 | 81 | |
82 | - if ($article_id != $last_article_id) { |
|
83 | - $last_article_id = $article_id; |
|
82 | + if ($article_id != $last_article_id) { |
|
83 | + $last_article_id = $article_id; |
|
84 | 84 | |
85 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_entries WHERE id = ?"); |
|
86 | - $sth->execute([$article_id]); |
|
85 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_entries WHERE id = ?"); |
|
86 | + $sth->execute([$article_id]); |
|
87 | 87 | |
88 | - $article_exists = $sth->fetch(); |
|
89 | - } |
|
88 | + $article_exists = $sth->fetch(); |
|
89 | + } |
|
90 | 90 | |
91 | - if (!$article_exists) { |
|
92 | - unlink($file); |
|
93 | - } |
|
94 | - } |
|
95 | - } |
|
91 | + if (!$article_exists) { |
|
92 | + unlink($file); |
|
93 | + } |
|
94 | + } |
|
95 | + } |
|
96 | 96 | |
97 | - public function hook_enclosure_entry($enc, $article_id) { |
|
98 | - $local_filename = $article_id . "-" . sha1($enc["content_url"]); |
|
97 | + public function hook_enclosure_entry($enc, $article_id) { |
|
98 | + $local_filename = $article_id . "-" . sha1($enc["content_url"]); |
|
99 | 99 | |
100 | - if ($this->cache->exists($local_filename)) { |
|
101 | - $enc["content_url"] = $this->cache->getUrl($local_filename); |
|
102 | - } |
|
100 | + if ($this->cache->exists($local_filename)) { |
|
101 | + $enc["content_url"] = $this->cache->getUrl($local_filename); |
|
102 | + } |
|
103 | 103 | |
104 | - return $enc; |
|
105 | - } |
|
104 | + return $enc; |
|
105 | + } |
|
106 | 106 | |
107 | - public function hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes, $article_id) { |
|
108 | - $xpath = new DOMXpath($doc); |
|
107 | + public function hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes, $article_id) { |
|
108 | + $xpath = new DOMXpath($doc); |
|
109 | 109 | |
110 | - if ($article_id) { |
|
111 | - $entries = $xpath->query('(//img[@src])|(//video/source[@src])'); |
|
110 | + if ($article_id) { |
|
111 | + $entries = $xpath->query('(//img[@src])|(//video/source[@src])'); |
|
112 | 112 | |
113 | - foreach ($entries as $entry) { |
|
114 | - if ($entry->hasAttribute('src')) { |
|
115 | - $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); |
|
113 | + foreach ($entries as $entry) { |
|
114 | + if ($entry->hasAttribute('src')) { |
|
115 | + $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); |
|
116 | 116 | |
117 | - $local_filename = $article_id . "-" . sha1($src); |
|
117 | + $local_filename = $article_id . "-" . sha1($src); |
|
118 | 118 | |
119 | - if ($this->cache->exists($local_filename)) { |
|
120 | - $entry->setAttribute("src", $this->cache->getUrl($local_filename)); |
|
121 | - $entry->removeAttribute("srcset"); |
|
122 | - } |
|
123 | - } |
|
124 | - } |
|
125 | - } |
|
119 | + if ($this->cache->exists($local_filename)) { |
|
120 | + $entry->setAttribute("src", $this->cache->getUrl($local_filename)); |
|
121 | + $entry->removeAttribute("srcset"); |
|
122 | + } |
|
123 | + } |
|
124 | + } |
|
125 | + } |
|
126 | 126 | |
127 | - return $doc; |
|
128 | - } |
|
127 | + return $doc; |
|
128 | + } |
|
129 | 129 | |
130 | - private function cache_url($article_id, $url) { |
|
131 | - $local_filename = $article_id . "-" . sha1($url); |
|
130 | + private function cache_url($article_id, $url) { |
|
131 | + $local_filename = $article_id . "-" . sha1($url); |
|
132 | 132 | |
133 | - if (!$this->cache->exists($local_filename)) { |
|
134 | - Debug::log("cache_images: downloading: $url to $local_filename", Debug::$LOG_VERBOSE); |
|
133 | + if (!$this->cache->exists($local_filename)) { |
|
134 | + Debug::log("cache_images: downloading: $url to $local_filename", Debug::$LOG_VERBOSE); |
|
135 | 135 | |
136 | - $data = fetch_file_contents(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]); |
|
136 | + $data = fetch_file_contents(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]); |
|
137 | 137 | |
138 | - if ($data) |
|
139 | - return $this->cache->put($local_filename, $data);; |
|
138 | + if ($data) |
|
139 | + return $this->cache->put($local_filename, $data);; |
|
140 | 140 | |
141 | - } else { |
|
142 | - //Debug::log("cache_images: local file exists for $url", Debug::$LOG_VERBOSE); |
|
141 | + } else { |
|
142 | + //Debug::log("cache_images: local file exists for $url", Debug::$LOG_VERBOSE); |
|
143 | 143 | |
144 | - return true; |
|
145 | - } |
|
144 | + return true; |
|
145 | + } |
|
146 | 146 | |
147 | - return false; |
|
148 | - } |
|
147 | + return false; |
|
148 | + } |
|
149 | 149 | |
150 | - private function cache_article_images($content, $site_url, $owner_uid, $article_id) { |
|
151 | - $status_filename = $article_id . "-" . sha1($site_url) . ".status"; |
|
150 | + private function cache_article_images($content, $site_url, $owner_uid, $article_id) { |
|
151 | + $status_filename = $article_id . "-" . sha1($site_url) . ".status"; |
|
152 | 152 | |
153 | - /* housekeeping might run as a separate user, in this case status/media might not be writable */ |
|
154 | - if (!$this->cache->isWritable($status_filename)) { |
|
155 | - Debug::log("status not writable: $status_filename", Debug::$LOG_VERBOSE); |
|
156 | - return false; |
|
157 | - } |
|
153 | + /* housekeeping might run as a separate user, in this case status/media might not be writable */ |
|
154 | + if (!$this->cache->isWritable($status_filename)) { |
|
155 | + Debug::log("status not writable: $status_filename", Debug::$LOG_VERBOSE); |
|
156 | + return false; |
|
157 | + } |
|
158 | 158 | |
159 | - Debug::log("status: $status_filename", Debug::$LOG_VERBOSE); |
|
159 | + Debug::log("status: $status_filename", Debug::$LOG_VERBOSE); |
|
160 | 160 | |
161 | 161 | if ($this->cache->exists($status_filename)) |
162 | 162 | $status = json_decode($this->cache->get($status_filename), true); |
@@ -176,49 +176,49 @@ discard block |
||
176 | 176 | return false; |
177 | 177 | } |
178 | 178 | |
179 | - $doc = new DOMDocument(); |
|
179 | + $doc = new DOMDocument(); |
|
180 | 180 | |
181 | - $has_images = false; |
|
182 | - $success = false; |
|
181 | + $has_images = false; |
|
182 | + $success = false; |
|
183 | 183 | |
184 | 184 | if ($doc->loadHTML('<?xml encoding="UTF-8">' . $content)) { |
185 | - $xpath = new DOMXPath($doc); |
|
186 | - $entries = $xpath->query('(//img[@src])|(//video/source[@src])'); |
|
185 | + $xpath = new DOMXPath($doc); |
|
186 | + $entries = $xpath->query('(//img[@src])|(//video/source[@src])'); |
|
187 | 187 | |
188 | - foreach ($entries as $entry) { |
|
188 | + foreach ($entries as $entry) { |
|
189 | 189 | |
190 | - if ($entry->hasAttribute('src') && strpos($entry->getAttribute('src'), "data:") !== 0) { |
|
190 | + if ($entry->hasAttribute('src') && strpos($entry->getAttribute('src'), "data:") !== 0) { |
|
191 | 191 | |
192 | - $has_images = true; |
|
192 | + $has_images = true; |
|
193 | 193 | |
194 | - $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); |
|
194 | + $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); |
|
195 | 195 | |
196 | - if ($this->cache_url($article_id, $src)) { |
|
197 | - $success = true; |
|
198 | - } |
|
199 | - } |
|
200 | - } |
|
201 | - } |
|
196 | + if ($this->cache_url($article_id, $src)) { |
|
197 | + $success = true; |
|
198 | + } |
|
199 | + } |
|
200 | + } |
|
201 | + } |
|
202 | 202 | |
203 | - $esth = $this->pdo->prepare("SELECT content_url FROM ttrss_enclosures WHERE post_id = ? AND |
|
203 | + $esth = $this->pdo->prepare("SELECT content_url FROM ttrss_enclosures WHERE post_id = ? AND |
|
204 | 204 | (content_type LIKE '%image%' OR content_type LIKE '%video%')"); |
205 | 205 | |
206 | 206 | if ($esth->execute([$article_id])) { |
207 | - while ($enc = $esth->fetch()) { |
|
207 | + while ($enc = $esth->fetch()) { |
|
208 | 208 | |
209 | - $has_images = true; |
|
210 | - $url = rewrite_relative_url($site_url, $enc["content_url"]); |
|
209 | + $has_images = true; |
|
210 | + $url = rewrite_relative_url($site_url, $enc["content_url"]); |
|
211 | 211 | |
212 | - if ($this->cache_url($article_id, $url)) { |
|
213 | - $success = true; |
|
214 | - } |
|
215 | - } |
|
216 | - } |
|
212 | + if ($this->cache_url($article_id, $url)) { |
|
213 | + $success = true; |
|
214 | + } |
|
215 | + } |
|
216 | + } |
|
217 | 217 | |
218 | - return $success || !$has_images; |
|
219 | - } |
|
218 | + return $success || !$has_images; |
|
219 | + } |
|
220 | 220 | |
221 | - public function api_version() { |
|
222 | - return 2; |
|
223 | - } |
|
221 | + public function api_version() { |
|
222 | + return 2; |
|
223 | + } |
|
224 | 224 | } |
@@ -1,78 +1,78 @@ |
||
1 | 1 | <?php |
2 | 2 | class VF_Shared 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 | - "Feed for all articles actively shared by URL", |
|
10 | - "fox", |
|
11 | - false); |
|
12 | - } |
|
7 | + public function about() { |
|
8 | + return array(1.0, |
|
9 | + "Feed for all articles actively shared by URL", |
|
10 | + "fox", |
|
11 | + false); |
|
12 | + } |
|
13 | 13 | |
14 | - public function init($host) { |
|
15 | - $this->host = $host; |
|
14 | + public function init($host) { |
|
15 | + $this->host = $host; |
|
16 | 16 | |
17 | - $host->add_feed(-1, __("Shared articles"), 'link', $this); |
|
18 | - } |
|
17 | + $host->add_feed(-1, __("Shared articles"), 'link', $this); |
|
18 | + } |
|
19 | 19 | |
20 | - public function api_version() { |
|
21 | - return 2; |
|
22 | - } |
|
20 | + public function api_version() { |
|
21 | + return 2; |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
26 | - */ |
|
27 | - public function get_unread($feed_id) { |
|
28 | - $sth = $this->pdo->prepare("select count(int_id) AS count |
|
24 | + /** |
|
25 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
26 | + */ |
|
27 | + public function get_unread($feed_id) { |
|
28 | + $sth = $this->pdo->prepare("select count(int_id) AS count |
|
29 | 29 | from ttrss_user_entries where owner_uid = ? and unread = true and uuid != ''"); |
30 | - $sth->execute([$_SESSION['uid']]); |
|
30 | + $sth->execute([$_SESSION['uid']]); |
|
31 | 31 | |
32 | - if ($row = $sth->fetch()) { |
|
33 | - return $row['count']; |
|
34 | - } |
|
32 | + if ($row = $sth->fetch()) { |
|
33 | + return $row['count']; |
|
34 | + } |
|
35 | 35 | |
36 | - return 0; |
|
37 | - } |
|
36 | + return 0; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
41 | - */ |
|
42 | - public function get_total($feed_id) { |
|
43 | - $sth = $this->pdo->prepare("select count(int_id) AS count |
|
39 | + /** |
|
40 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
41 | + */ |
|
42 | + public function get_total($feed_id) { |
|
43 | + $sth = $this->pdo->prepare("select count(int_id) AS count |
|
44 | 44 | from ttrss_user_entries where owner_uid = ? and uuid != ''"); |
45 | - $sth->execute([$_SESSION['uid']]); |
|
45 | + $sth->execute([$_SESSION['uid']]); |
|
46 | 46 | |
47 | - if ($row = $sth->fetch()) { |
|
48 | - return $row['count']; |
|
49 | - } |
|
47 | + if ($row = $sth->fetch()) { |
|
48 | + return $row['count']; |
|
49 | + } |
|
50 | 50 | |
51 | - return 0; |
|
52 | - } |
|
51 | + return 0; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
56 | - */ |
|
57 | - public function get_headlines($feed_id, $options) { |
|
58 | - $params = array( |
|
59 | - "feed" => -4, |
|
60 | - "limit" => $options["limit"], |
|
61 | - "view_mode" => $this->get_unread(-1) > 0 ? "adaptive" : "all_articles", |
|
62 | - "search" => $options['search'], |
|
63 | - "override_order" => $options['override_order'], |
|
64 | - "offset" => $options["offset"], |
|
65 | - "filter" => $options["filter"], |
|
66 | - "since_id" => $options["since_id"], |
|
67 | - "include_children" => $options["include_children"], |
|
68 | - "override_strategy" => "uuid != ''", |
|
69 | - "override_vfeed" => "ttrss_feeds.title AS feed_title," |
|
70 | - ); |
|
54 | + /** |
|
55 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
56 | + */ |
|
57 | + public function get_headlines($feed_id, $options) { |
|
58 | + $params = array( |
|
59 | + "feed" => -4, |
|
60 | + "limit" => $options["limit"], |
|
61 | + "view_mode" => $this->get_unread(-1) > 0 ? "adaptive" : "all_articles", |
|
62 | + "search" => $options['search'], |
|
63 | + "override_order" => $options['override_order'], |
|
64 | + "offset" => $options["offset"], |
|
65 | + "filter" => $options["filter"], |
|
66 | + "since_id" => $options["since_id"], |
|
67 | + "include_children" => $options["include_children"], |
|
68 | + "override_strategy" => "uuid != ''", |
|
69 | + "override_vfeed" => "ttrss_feeds.title AS feed_title," |
|
70 | + ); |
|
71 | 71 | |
72 | - $qfh_ret = Feeds::queryFeedHeadlines($params); |
|
73 | - $qfh_ret[1] = __("Shared articles"); |
|
72 | + $qfh_ret = Feeds::queryFeedHeadlines($params); |
|
73 | + $qfh_ret[1] = __("Shared articles"); |
|
74 | 74 | |
75 | - return $qfh_ret; |
|
76 | - } |
|
75 | + return $qfh_ret; |
|
76 | + } |
|
77 | 77 | |
78 | 78 | } |
@@ -1,37 +1,37 @@ |
||
1 | 1 | <?php |
2 | 2 | class No_Iframes extends Plugin { |
3 | - private $host; |
|
3 | + private $host; |
|
4 | 4 | |
5 | - public function about() { |
|
6 | - return array(1.0, |
|
7 | - "Remove embedded iframes (unless whitelisted)", |
|
8 | - "fox"); |
|
9 | - } |
|
5 | + public function about() { |
|
6 | + return array(1.0, |
|
7 | + "Remove embedded iframes (unless whitelisted)", |
|
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 | - $host->add_hook($host::HOOK_SANITIZE, $this); |
|
15 | - } |
|
14 | + $host->add_hook($host::HOOK_SANITIZE, $this); |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
19 | - */ |
|
20 | - public function hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes) { |
|
17 | + /** |
|
18 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
19 | + */ |
|
20 | + public function hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes) { |
|
21 | 21 | |
22 | - $xpath = new DOMXpath($doc); |
|
23 | - $entries = $xpath->query('//iframe'); |
|
22 | + $xpath = new DOMXpath($doc); |
|
23 | + $entries = $xpath->query('//iframe'); |
|
24 | 24 | |
25 | - foreach ($entries as $entry) { |
|
26 | - if (!iframe_whitelisted($entry)) |
|
27 | - $entry->parentNode->removeChild($entry); |
|
28 | - } |
|
25 | + foreach ($entries as $entry) { |
|
26 | + if (!iframe_whitelisted($entry)) |
|
27 | + $entry->parentNode->removeChild($entry); |
|
28 | + } |
|
29 | 29 | |
30 | - return array($doc, $allowed_elements, $disallowed_attributes); |
|
31 | - } |
|
30 | + return array($doc, $allowed_elements, $disallowed_attributes); |
|
31 | + } |
|
32 | 32 | |
33 | - public function api_version() { |
|
34 | - return 2; |
|
35 | - } |
|
33 | + public function api_version() { |
|
34 | + return 2; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | } |