@@ -1,55 +1,55 @@ |
||
1 | 1 | <?php |
2 | 2 | class Mailer { |
3 | - // TODO: support HTML mail (i.e. MIME messages) |
|
3 | + // TODO: support HTML mail (i.e. MIME messages) |
|
4 | 4 | |
5 | - private $last_error = "Unable to send mail: check local configuration."; |
|
5 | + private $last_error = "Unable to send mail: check local configuration."; |
|
6 | 6 | |
7 | - public function mail($params) { |
|
7 | + public function mail($params) { |
|
8 | 8 | |
9 | - $to_name = $params["to_name"]; |
|
10 | - $to_address = $params["to_address"]; |
|
11 | - $subject = $params["subject"]; |
|
12 | - $message = $params["message"]; |
|
13 | - $from_name = $params["from_name"] ? $params["from_name"] : SMTP_FROM_NAME; |
|
14 | - $from_address = $params["from_address"] ? $params["from_address"] : SMTP_FROM_ADDRESS; |
|
9 | + $to_name = $params["to_name"]; |
|
10 | + $to_address = $params["to_address"]; |
|
11 | + $subject = $params["subject"]; |
|
12 | + $message = $params["message"]; |
|
13 | + $from_name = $params["from_name"] ? $params["from_name"] : SMTP_FROM_NAME; |
|
14 | + $from_address = $params["from_address"] ? $params["from_address"] : SMTP_FROM_ADDRESS; |
|
15 | 15 | |
16 | - $additional_headers = $params["headers"] ? $params["headers"] : []; |
|
16 | + $additional_headers = $params["headers"] ? $params["headers"] : []; |
|
17 | 17 | |
18 | - $from_combined = $from_name ? "$from_name <$from_address>" : $from_address; |
|
19 | - $to_combined = $to_name ? "$to_name <$to_address>" : $to_address; |
|
18 | + $from_combined = $from_name ? "$from_name <$from_address>" : $from_address; |
|
19 | + $to_combined = $to_name ? "$to_name <$to_address>" : $to_address; |
|
20 | 20 | |
21 | - if (defined('_LOG_SENT_MAIL') && _LOG_SENT_MAIL) { |
|
22 | - Logger::get()->log("Sending mail from $from_combined to $to_combined [$subject]: $message"); |
|
23 | - } |
|
21 | + if (defined('_LOG_SENT_MAIL') && _LOG_SENT_MAIL) { |
|
22 | + Logger::get()->log("Sending mail from $from_combined to $to_combined [$subject]: $message"); |
|
23 | + } |
|
24 | 24 | |
25 | - // HOOK_SEND_MAIL plugin instructions: |
|
26 | - // 1. return 1 or true if mail is handled |
|
27 | - // 2. return -1 if there's been a fatal error and no further action is allowed |
|
28 | - // 3. any other return value will allow cycling to the next handler and, eventually, to default mail() function |
|
29 | - // 4. set error message if needed via passed Mailer instance function set_error() |
|
25 | + // HOOK_SEND_MAIL plugin instructions: |
|
26 | + // 1. return 1 or true if mail is handled |
|
27 | + // 2. return -1 if there's been a fatal error and no further action is allowed |
|
28 | + // 3. any other return value will allow cycling to the next handler and, eventually, to default mail() function |
|
29 | + // 4. set error message if needed via passed Mailer instance function set_error() |
|
30 | 30 | |
31 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEND_MAIL) as $p) { |
|
32 | - $rc = $p->hook_send_mail($this, $params); |
|
31 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEND_MAIL) as $p) { |
|
32 | + $rc = $p->hook_send_mail($this, $params); |
|
33 | 33 | |
34 | - if ($rc == 1) { |
|
35 | - return $rc; |
|
36 | - } |
|
34 | + if ($rc == 1) { |
|
35 | + return $rc; |
|
36 | + } |
|
37 | 37 | |
38 | - if ($rc == -1) { |
|
39 | - return 0; |
|
40 | - } |
|
41 | - } |
|
38 | + if ($rc == -1) { |
|
39 | + return 0; |
|
40 | + } |
|
41 | + } |
|
42 | 42 | |
43 | - $headers = ["From: $from_combined", "Content-Type: text/plain; charset=UTF-8"]; |
|
43 | + $headers = ["From: $from_combined", "Content-Type: text/plain; charset=UTF-8"]; |
|
44 | 44 | |
45 | - return mail($to_combined, $subject, $message, implode("\r\n", array_merge($headers, $additional_headers))); |
|
46 | - } |
|
45 | + return mail($to_combined, $subject, $message, implode("\r\n", array_merge($headers, $additional_headers))); |
|
46 | + } |
|
47 | 47 | |
48 | - public function set_error($message) { |
|
49 | - $this->last_error = $message; |
|
50 | - } |
|
48 | + public function set_error($message) { |
|
49 | + $this->last_error = $message; |
|
50 | + } |
|
51 | 51 | |
52 | - public function error() { |
|
53 | - return $this->last_error; |
|
54 | - } |
|
52 | + public function error() { |
|
53 | + return $this->last_error; |
|
54 | + } |
|
55 | 55 | } |
@@ -1,206 +1,206 @@ |
||
1 | 1 | <?php |
2 | 2 | class Dlg extends Handler_Protected { |
3 | - private $param; |
|
3 | + private $param; |
|
4 | 4 | private $params; |
5 | 5 | |
6 | 6 | function before($method) { |
7 | - if (parent::before($method)) { |
|
8 | - header("Content-Type: text/html"); # required for iframe |
|
7 | + if (parent::before($method)) { |
|
8 | + header("Content-Type: text/html"); # required for iframe |
|
9 | 9 | |
10 | - $this->param = $_REQUEST["param"]; |
|
11 | - return true; |
|
12 | - } |
|
13 | - return false; |
|
14 | - } |
|
10 | + $this->param = $_REQUEST["param"]; |
|
11 | + return true; |
|
12 | + } |
|
13 | + return false; |
|
14 | + } |
|
15 | 15 | |
16 | - public function importOpml() { |
|
17 | - print_notice("If you have imported labels and/or filters, you might need to reload preferences to see your new data."); |
|
16 | + public function importOpml() { |
|
17 | + print_notice("If you have imported labels and/or filters, you might need to reload preferences to see your new data."); |
|
18 | 18 | |
19 | - print "<div class='panel panel-scrollable'>"; |
|
19 | + print "<div class='panel panel-scrollable'>"; |
|
20 | 20 | |
21 | - $opml = new Opml($_REQUEST); |
|
21 | + $opml = new Opml($_REQUEST); |
|
22 | 22 | |
23 | - $opml->opml_import($_SESSION["uid"]); |
|
23 | + $opml->opml_import($_SESSION["uid"]); |
|
24 | 24 | |
25 | - print "</div>"; |
|
25 | + print "</div>"; |
|
26 | 26 | |
27 | - print "<footer class='text-center'>"; |
|
28 | - print "<button dojoType='dijit.form.Button' |
|
27 | + print "<footer class='text-center'>"; |
|
28 | + print "<button dojoType='dijit.form.Button' |
|
29 | 29 | onclick=\"dijit.byId('opmlImportDlg').execute()\">". |
30 | - __('Close this window')."</button>"; |
|
31 | - print "</footer>"; |
|
30 | + __('Close this window')."</button>"; |
|
31 | + print "</footer>"; |
|
32 | 32 | |
33 | - print "</div>"; |
|
33 | + print "</div>"; |
|
34 | 34 | |
35 | - //return; |
|
36 | - } |
|
35 | + //return; |
|
36 | + } |
|
37 | 37 | |
38 | - public function pubOPMLUrl() { |
|
39 | - $url_path = Opml::opml_publish_url(); |
|
38 | + public function pubOPMLUrl() { |
|
39 | + $url_path = Opml::opml_publish_url(); |
|
40 | 40 | |
41 | - print "<header>".__("Your Public OPML URL is:")."</header>"; |
|
41 | + print "<header>".__("Your Public OPML URL is:")."</header>"; |
|
42 | 42 | |
43 | - print "<section>"; |
|
43 | + print "<section>"; |
|
44 | 44 | |
45 | - print "<div class='panel text-center'>"; |
|
46 | - print "<a id='pub_opml_url' href='$url_path' target='_blank'>$url_path</a>"; |
|
47 | - print "</div>"; |
|
45 | + print "<div class='panel text-center'>"; |
|
46 | + print "<a id='pub_opml_url' href='$url_path' target='_blank'>$url_path</a>"; |
|
47 | + print "</div>"; |
|
48 | 48 | |
49 | - print "</section>"; |
|
49 | + print "</section>"; |
|
50 | 50 | |
51 | - print "<footer class='text-center'>"; |
|
51 | + print "<footer class='text-center'>"; |
|
52 | 52 | |
53 | - print "<button dojoType='dijit.form.Button' onclick=\"return Helpers.OPML.changeKey()\">". |
|
54 | - __('Generate new URL')."</button> "; |
|
53 | + print "<button dojoType='dijit.form.Button' onclick=\"return Helpers.OPML.changeKey()\">". |
|
54 | + __('Generate new URL')."</button> "; |
|
55 | 55 | |
56 | - print "<button dojoType='dijit.form.Button' onclick=\"return CommonDialogs.closeInfoBox()\">". |
|
57 | - __('Close this window')."</button>"; |
|
56 | + print "<button dojoType='dijit.form.Button' onclick=\"return CommonDialogs.closeInfoBox()\">". |
|
57 | + __('Close this window')."</button>"; |
|
58 | 58 | |
59 | - print "</footer>"; |
|
59 | + print "</footer>"; |
|
60 | 60 | |
61 | - //return; |
|
62 | - } |
|
61 | + //return; |
|
62 | + } |
|
63 | 63 | |
64 | - public function explainError() { |
|
65 | - print "<div class=\"errorExplained\">"; |
|
64 | + public function explainError() { |
|
65 | + print "<div class=\"errorExplained\">"; |
|
66 | 66 | |
67 | - if ($this->param == 1) { |
|
68 | - print __("Update daemon is enabled in configuration, but daemon process is not running, which prevents all feeds from updating. Please start the daemon process or contact instance owner."); |
|
67 | + if ($this->param == 1) { |
|
68 | + print __("Update daemon is enabled in configuration, but daemon process is not running, which prevents all feeds from updating. Please start the daemon process or contact instance owner."); |
|
69 | 69 | |
70 | - $stamp = (int) file_get_contents(LOCK_DIRECTORY."/update_daemon.stamp"); |
|
70 | + $stamp = (int) file_get_contents(LOCK_DIRECTORY."/update_daemon.stamp"); |
|
71 | 71 | |
72 | - print "<p>".__("Last update:")." ".date("Y.m.d, G:i", $stamp); |
|
72 | + print "<p>".__("Last update:")." ".date("Y.m.d, G:i", $stamp); |
|
73 | 73 | |
74 | - } |
|
74 | + } |
|
75 | 75 | |
76 | - if ($this->param == 3) { |
|
77 | - print __("Update daemon is taking too long to perform a feed update. This could indicate a problem like crash or a hang. Please check the daemon process or contact instance owner."); |
|
76 | + if ($this->param == 3) { |
|
77 | + print __("Update daemon is taking too long to perform a feed update. This could indicate a problem like crash or a hang. Please check the daemon process or contact instance owner."); |
|
78 | 78 | |
79 | - $stamp = (int) file_get_contents(LOCK_DIRECTORY."/update_daemon.stamp"); |
|
79 | + $stamp = (int) file_get_contents(LOCK_DIRECTORY."/update_daemon.stamp"); |
|
80 | 80 | |
81 | - print "<p>".__("Last update:")." ".date("Y.m.d, G:i", $stamp); |
|
81 | + print "<p>".__("Last update:")." ".date("Y.m.d, G:i", $stamp); |
|
82 | 82 | |
83 | - } |
|
83 | + } |
|
84 | 84 | |
85 | - print "</div>"; |
|
85 | + print "</div>"; |
|
86 | 86 | |
87 | - print "<footer class='text-center'>"; |
|
88 | - print "<button onclick=\"return CommonDialogs.closeInfoBox()\">". |
|
89 | - __('Close this window')."</button>"; |
|
90 | - print "</footer>"; |
|
87 | + print "<footer class='text-center'>"; |
|
88 | + print "<button onclick=\"return CommonDialogs.closeInfoBox()\">". |
|
89 | + __('Close this window')."</button>"; |
|
90 | + print "</footer>"; |
|
91 | 91 | |
92 | - //return; |
|
93 | - } |
|
92 | + //return; |
|
93 | + } |
|
94 | 94 | |
95 | - public function printTagCloud() { |
|
96 | - print "<div class='panel text-center'>"; |
|
95 | + public function printTagCloud() { |
|
96 | + print "<div class='panel text-center'>"; |
|
97 | 97 | |
98 | - // from here: http://www.roscripts.com/Create_tag_cloud-71.html |
|
98 | + // from here: http://www.roscripts.com/Create_tag_cloud-71.html |
|
99 | 99 | |
100 | - $sth = $this->pdo->prepare("SELECT tag_name, COUNT(post_int_id) AS count |
|
100 | + $sth = $this->pdo->prepare("SELECT tag_name, COUNT(post_int_id) AS count |
|
101 | 101 | FROM ttrss_tags WHERE owner_uid = ? |
102 | 102 | GROUP BY tag_name ORDER BY count DESC LIMIT 50"); |
103 | - $sth->execute([$_SESSION['uid']]); |
|
103 | + $sth->execute([$_SESSION['uid']]); |
|
104 | 104 | |
105 | - $tags = array(); |
|
105 | + $tags = array(); |
|
106 | 106 | |
107 | - while ($line = $sth->fetch()) { |
|
108 | - $tags[$line["tag_name"]] = $line["count"]; |
|
109 | - } |
|
107 | + while ($line = $sth->fetch()) { |
|
108 | + $tags[$line["tag_name"]] = $line["count"]; |
|
109 | + } |
|
110 | 110 | |
111 | 111 | if (count($tags) == 0) { return; } |
112 | 112 | |
113 | - ksort($tags); |
|
113 | + ksort($tags); |
|
114 | 114 | |
115 | - $max_size = 32; // max font size in pixels |
|
116 | - $min_size = 11; // min font size in pixels |
|
115 | + $max_size = 32; // max font size in pixels |
|
116 | + $min_size = 11; // min font size in pixels |
|
117 | 117 | |
118 | - // largest and smallest array values |
|
119 | - $max_qty = max(array_values($tags)); |
|
120 | - $min_qty = min(array_values($tags)); |
|
118 | + // largest and smallest array values |
|
119 | + $max_qty = max(array_values($tags)); |
|
120 | + $min_qty = min(array_values($tags)); |
|
121 | 121 | |
122 | - // find the range of values |
|
123 | - $spread = $max_qty - $min_qty; |
|
124 | - if ($spread == 0) { // we don't want to divide by zero |
|
125 | - $spread = 1; |
|
126 | - } |
|
122 | + // find the range of values |
|
123 | + $spread = $max_qty - $min_qty; |
|
124 | + if ($spread == 0) { // we don't want to divide by zero |
|
125 | + $spread = 1; |
|
126 | + } |
|
127 | 127 | |
128 | - // set the font-size increment |
|
129 | - $step = ($max_size - $min_size) / ($spread); |
|
128 | + // set the font-size increment |
|
129 | + $step = ($max_size - $min_size) / ($spread); |
|
130 | 130 | |
131 | - // loop through the tag array |
|
132 | - foreach ($tags as $key => $value) { |
|
133 | - // calculate font-size |
|
134 | - // find the $value in excess of $min_qty |
|
135 | - // multiply by the font-size increment ($size) |
|
136 | - // and add the $min_size set above |
|
137 | - $size = round($min_size + (($value - $min_qty) * $step)); |
|
131 | + // loop through the tag array |
|
132 | + foreach ($tags as $key => $value) { |
|
133 | + // calculate font-size |
|
134 | + // find the $value in excess of $min_qty |
|
135 | + // multiply by the font-size increment ($size) |
|
136 | + // and add the $min_size set above |
|
137 | + $size = round($min_size + (($value - $min_qty) * $step)); |
|
138 | 138 | |
139 | - $key_escaped = str_replace("'", "\\'", $key); |
|
139 | + $key_escaped = str_replace("'", "\\'", $key); |
|
140 | 140 | |
141 | - echo "<a href=\"#\" onclick=\"Feeds.open({feed:'$key_escaped'}) \" style=\"font-size: ". |
|
142 | - $size."px\" title=\"$value articles tagged with ". |
|
143 | - $key.'">'.$key.'</a> '; |
|
144 | - } |
|
141 | + echo "<a href=\"#\" onclick=\"Feeds.open({feed:'$key_escaped'}) \" style=\"font-size: ". |
|
142 | + $size."px\" title=\"$value articles tagged with ". |
|
143 | + $key.'">'.$key.'</a> '; |
|
144 | + } |
|
145 | 145 | |
146 | 146 | |
147 | 147 | |
148 | - print "</div>"; |
|
148 | + print "</div>"; |
|
149 | 149 | |
150 | - print "<footer class='text-center'>"; |
|
151 | - print "<button dojoType='dijit.form.Button' |
|
150 | + print "<footer class='text-center'>"; |
|
151 | + print "<button dojoType='dijit.form.Button' |
|
152 | 152 | onclick=\"return CommonDialogs.closeInfoBox()\">". |
153 | - __('Close this window')."</button>"; |
|
154 | - print "</footer>"; |
|
153 | + __('Close this window')."</button>"; |
|
154 | + print "</footer>"; |
|
155 | 155 | |
156 | - } |
|
156 | + } |
|
157 | 157 | |
158 | - public function generatedFeed() { |
|
158 | + public function generatedFeed() { |
|
159 | 159 | |
160 | - $this->params = explode(":", $this->param, 3); |
|
161 | - $feed_id = $this->params[0]; |
|
162 | - $is_cat = (bool) $this->params[1]; |
|
160 | + $this->params = explode(":", $this->param, 3); |
|
161 | + $feed_id = $this->params[0]; |
|
162 | + $is_cat = (bool) $this->params[1]; |
|
163 | 163 | |
164 | - $key = Feeds::get_feed_access_key($feed_id, $is_cat); |
|
164 | + $key = Feeds::get_feed_access_key($feed_id, $is_cat); |
|
165 | 165 | |
166 | - $url_path = htmlspecialchars($this->params[2])."&key=".$key; |
|
166 | + $url_path = htmlspecialchars($this->params[2])."&key=".$key; |
|
167 | 167 | |
168 | - $feed_title = Feeds::getFeedTitle($feed_id, $is_cat); |
|
168 | + $feed_title = Feeds::getFeedTitle($feed_id, $is_cat); |
|
169 | 169 | |
170 | - print "<header>".T_sprintf("%s can be accessed via the following secret URL:", $feed_title)."</header>"; |
|
170 | + print "<header>".T_sprintf("%s can be accessed via the following secret URL:", $feed_title)."</header>"; |
|
171 | 171 | |
172 | - print "<section>"; |
|
173 | - print "<div class='panel text-center'>"; |
|
174 | - print "<a id='gen_feed_url' href='$url_path' target='_blank'>$url_path</a>"; |
|
175 | - print "</div>"; |
|
176 | - print "</section>"; |
|
172 | + print "<section>"; |
|
173 | + print "<div class='panel text-center'>"; |
|
174 | + print "<a id='gen_feed_url' href='$url_path' target='_blank'>$url_path</a>"; |
|
175 | + print "</div>"; |
|
176 | + print "</section>"; |
|
177 | 177 | |
178 | - print "<footer>"; |
|
178 | + print "<footer>"; |
|
179 | 179 | |
180 | - print "<button dojoType='dijit.form.Button' style='float : left' class='alt-info' onclick='window.open(\"https://tt-rss.org/wiki/GeneratedFeeds\")'> |
|
180 | + print "<button dojoType='dijit.form.Button' style='float : left' class='alt-info' onclick='window.open(\"https://tt-rss.org/wiki/GeneratedFeeds\")'> |
|
181 | 181 | <i class='material-icons'>help</i> ".__("More info...")."</button>"; |
182 | 182 | |
183 | - print "<button dojoType='dijit.form.Button' onclick=\"return CommonDialogs.genUrlChangeKey('$feed_id', '$is_cat')\">". |
|
184 | - __('Generate new URL')."</button> "; |
|
183 | + print "<button dojoType='dijit.form.Button' onclick=\"return CommonDialogs.genUrlChangeKey('$feed_id', '$is_cat')\">". |
|
184 | + __('Generate new URL')."</button> "; |
|
185 | 185 | |
186 | - print "<button dojoType='dijit.form.Button' onclick=\"return CommonDialogs.closeInfoBox()\">". |
|
187 | - __('Close this window')."</button>"; |
|
186 | + print "<button dojoType='dijit.form.Button' onclick=\"return CommonDialogs.closeInfoBox()\">". |
|
187 | + __('Close this window')."</button>"; |
|
188 | 188 | |
189 | - print "</footer>"; |
|
189 | + print "</footer>"; |
|
190 | 190 | |
191 | - //return; |
|
192 | - } |
|
191 | + //return; |
|
192 | + } |
|
193 | 193 | |
194 | - public function defaultPasswordWarning() { |
|
194 | + public function defaultPasswordWarning() { |
|
195 | 195 | |
196 | - print_warning(__("You are using default tt-rss password. Please change it in the Preferences (Personal data / Authentication).")); |
|
196 | + print_warning(__("You are using default tt-rss password. Please change it in the Preferences (Personal data / Authentication).")); |
|
197 | 197 | |
198 | - print "<footer class='text-center'>"; |
|
199 | - print "<button dojoType='dijit.form.Button' onclick=\"document.location.href = 'prefs.php'\">". |
|
200 | - __('Open Preferences')."</button> "; |
|
201 | - print "<button dojoType='dijit.form.Button' |
|
198 | + print "<footer class='text-center'>"; |
|
199 | + print "<button dojoType='dijit.form.Button' onclick=\"document.location.href = 'prefs.php'\">". |
|
200 | + __('Open Preferences')."</button> "; |
|
201 | + print "<button dojoType='dijit.form.Button' |
|
202 | 202 | onclick=\"return CommonDialogs.closeInfoBox()\">". |
203 | - __('Close this window')."</button>"; |
|
204 | - print "</footeer>"; |
|
205 | - } |
|
203 | + __('Close this window')."</button>"; |
|
204 | + print "</footeer>"; |
|
205 | + } |
|
206 | 206 | } |
@@ -1,641 +1,641 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class Article extends Handler_Protected { |
3 | 3 | |
4 | - public function csrf_ignore($method) { |
|
5 | - $csrf_ignored = array("redirect", "editarticletags"); |
|
4 | + public function csrf_ignore($method) { |
|
5 | + $csrf_ignored = array("redirect", "editarticletags"); |
|
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 redirect() { |
|
11 | - $id = clean($_REQUEST['id']); |
|
10 | + public function redirect() { |
|
11 | + $id = clean($_REQUEST['id']); |
|
12 | 12 | |
13 | - $sth = $this->pdo->prepare("SELECT link FROM ttrss_entries, ttrss_user_entries |
|
13 | + $sth = $this->pdo->prepare("SELECT link FROM ttrss_entries, ttrss_user_entries |
|
14 | 14 | WHERE id = ? AND id = ref_id AND owner_uid = ? |
15 | 15 | LIMIT 1"); |
16 | 16 | $sth->execute([$id, $_SESSION['uid']]); |
17 | 17 | |
18 | - if ($row = $sth->fetch()) { |
|
19 | - $article_url = $row['link']; |
|
20 | - $article_url = str_replace("\n", "", $article_url); |
|
18 | + if ($row = $sth->fetch()) { |
|
19 | + $article_url = $row['link']; |
|
20 | + $article_url = str_replace("\n", "", $article_url); |
|
21 | 21 | |
22 | - header("Location: $article_url"); |
|
23 | - return; |
|
22 | + header("Location: $article_url"); |
|
23 | + return; |
|
24 | 24 | |
25 | - } else { |
|
26 | - print_error(__("Article not found.")); |
|
27 | - } |
|
28 | - } |
|
25 | + } else { |
|
26 | + print_error(__("Article not found.")); |
|
27 | + } |
|
28 | + } |
|
29 | 29 | |
30 | - public static function create_published_article($title, $url, $content, $labels_str, |
|
31 | - $owner_uid) { |
|
30 | + public static function create_published_article($title, $url, $content, $labels_str, |
|
31 | + $owner_uid) { |
|
32 | 32 | |
33 | - $guid = 'SHA1:'.sha1("ttshared:".$url.$owner_uid); // include owner_uid to prevent global GUID clash |
|
33 | + $guid = 'SHA1:'.sha1("ttshared:".$url.$owner_uid); // include owner_uid to prevent global GUID clash |
|
34 | 34 | |
35 | - if (!$content) { |
|
36 | - $pluginhost = new PluginHost(); |
|
37 | - $pluginhost->load_all(PluginHost::KIND_ALL, $owner_uid); |
|
38 | - $pluginhost->load_data(); |
|
35 | + if (!$content) { |
|
36 | + $pluginhost = new PluginHost(); |
|
37 | + $pluginhost->load_all(PluginHost::KIND_ALL, $owner_uid); |
|
38 | + $pluginhost->load_data(); |
|
39 | 39 | |
40 | - foreach ($pluginhost->get_hooks(PluginHost::HOOK_GET_FULL_TEXT) as $p) { |
|
41 | - $extracted_content = $p->hook_get_full_text($url); |
|
40 | + foreach ($pluginhost->get_hooks(PluginHost::HOOK_GET_FULL_TEXT) as $p) { |
|
41 | + $extracted_content = $p->hook_get_full_text($url); |
|
42 | 42 | |
43 | - if ($extracted_content) { |
|
44 | - $content = $extracted_content; |
|
45 | - break; |
|
46 | - } |
|
47 | - } |
|
48 | - } |
|
43 | + if ($extracted_content) { |
|
44 | + $content = $extracted_content; |
|
45 | + break; |
|
46 | + } |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | - $content_hash = sha1($content); |
|
50 | + $content_hash = sha1($content); |
|
51 | 51 | |
52 | - if ($labels_str != "") { |
|
53 | - $labels = explode(",", $labels_str); |
|
54 | - } else { |
|
55 | - $labels = array(); |
|
56 | - } |
|
52 | + if ($labels_str != "") { |
|
53 | + $labels = explode(",", $labels_str); |
|
54 | + } else { |
|
55 | + $labels = array(); |
|
56 | + } |
|
57 | 57 | |
58 | - $rc = false; |
|
58 | + $rc = false; |
|
59 | 59 | |
60 | - if (!$title) { |
|
61 | - $title = $url; |
|
62 | - } |
|
63 | - if (!$title && !$url) { |
|
64 | - return false; |
|
65 | - } |
|
60 | + if (!$title) { |
|
61 | + $title = $url; |
|
62 | + } |
|
63 | + if (!$title && !$url) { |
|
64 | + return false; |
|
65 | + } |
|
66 | 66 | |
67 | - if (filter_var($url, FILTER_VALIDATE_URL) === false) { |
|
68 | - return false; |
|
69 | - } |
|
67 | + if (filter_var($url, FILTER_VALIDATE_URL) === false) { |
|
68 | + return false; |
|
69 | + } |
|
70 | 70 | |
71 | - $pdo = Db::pdo(); |
|
71 | + $pdo = Db::pdo(); |
|
72 | 72 | |
73 | - $pdo->beginTransaction(); |
|
73 | + $pdo->beginTransaction(); |
|
74 | 74 | |
75 | - // only check for our user data here, others might have shared this with different content etc |
|
76 | - $sth = $pdo->prepare("SELECT id FROM ttrss_entries, ttrss_user_entries WHERE |
|
75 | + // only check for our user data here, others might have shared this with different content etc |
|
76 | + $sth = $pdo->prepare("SELECT id FROM ttrss_entries, ttrss_user_entries WHERE |
|
77 | 77 | guid = ? AND ref_id = id AND owner_uid = ? LIMIT 1"); |
78 | - $sth->execute([$guid, $owner_uid]); |
|
78 | + $sth->execute([$guid, $owner_uid]); |
|
79 | 79 | |
80 | - if ($row = $sth->fetch()) { |
|
81 | - $ref_id = $row['id']; |
|
80 | + if ($row = $sth->fetch()) { |
|
81 | + $ref_id = $row['id']; |
|
82 | 82 | |
83 | - $sth = $pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE |
|
83 | + $sth = $pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE |
|
84 | 84 | ref_id = ? AND owner_uid = ? LIMIT 1"); |
85 | 85 | $sth->execute([$ref_id, $owner_uid]); |
86 | 86 | |
87 | - if ($row = $sth->fetch()) { |
|
88 | - $int_id = $row['int_id']; |
|
87 | + if ($row = $sth->fetch()) { |
|
88 | + $int_id = $row['int_id']; |
|
89 | 89 | |
90 | - $sth = $pdo->prepare("UPDATE ttrss_entries SET |
|
90 | + $sth = $pdo->prepare("UPDATE ttrss_entries SET |
|
91 | 91 | content = ?, content_hash = ? WHERE id = ?"); |
92 | - $sth->execute([$content, $content_hash, $ref_id]); |
|
92 | + $sth->execute([$content, $content_hash, $ref_id]); |
|
93 | 93 | |
94 | - if (DB_TYPE == "pgsql") { |
|
95 | - $sth = $pdo->prepare("UPDATE ttrss_entries |
|
94 | + if (DB_TYPE == "pgsql") { |
|
95 | + $sth = $pdo->prepare("UPDATE ttrss_entries |
|
96 | 96 | SET tsvector_combined = to_tsvector( :ts_content) |
97 | 97 | WHERE id = :id"); |
98 | - $params = [ |
|
99 | - ":ts_content" => mb_substr(strip_tags($content), 0, 900000), |
|
100 | - ":id" => $ref_id]; |
|
101 | - $sth->execute($params); |
|
102 | - } |
|
98 | + $params = [ |
|
99 | + ":ts_content" => mb_substr(strip_tags($content), 0, 900000), |
|
100 | + ":id" => $ref_id]; |
|
101 | + $sth->execute($params); |
|
102 | + } |
|
103 | 103 | |
104 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries SET published = true, |
|
104 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries SET published = true, |
|
105 | 105 | last_published = NOW() WHERE |
106 | 106 | int_id = ? AND owner_uid = ?"); |
107 | - $sth->execute([$int_id, $owner_uid]); |
|
107 | + $sth->execute([$int_id, $owner_uid]); |
|
108 | 108 | |
109 | - } else { |
|
109 | + } else { |
|
110 | 110 | |
111 | - $sth = $pdo->prepare("INSERT INTO ttrss_user_entries |
|
111 | + $sth = $pdo->prepare("INSERT INTO ttrss_user_entries |
|
112 | 112 | (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, |
113 | 113 | last_read, note, unread, last_published) |
114 | 114 | VALUES |
115 | 115 | (?, '', NULL, NULL, ?, true, '', '', NOW(), '', false, NOW())"); |
116 | - $sth->execute([$ref_id, $owner_uid]); |
|
117 | - } |
|
116 | + $sth->execute([$ref_id, $owner_uid]); |
|
117 | + } |
|
118 | 118 | |
119 | - if (count($labels) != 0) { |
|
120 | - foreach ($labels as $label) { |
|
121 | - Labels::add_article($ref_id, trim($label), $owner_uid); |
|
122 | - } |
|
123 | - } |
|
119 | + if (count($labels) != 0) { |
|
120 | + foreach ($labels as $label) { |
|
121 | + Labels::add_article($ref_id, trim($label), $owner_uid); |
|
122 | + } |
|
123 | + } |
|
124 | 124 | |
125 | - $rc = true; |
|
125 | + $rc = true; |
|
126 | 126 | |
127 | - } else { |
|
128 | - $sth = $pdo->prepare("INSERT INTO ttrss_entries |
|
127 | + } else { |
|
128 | + $sth = $pdo->prepare("INSERT INTO ttrss_entries |
|
129 | 129 | (title, guid, link, updated, content, content_hash, date_entered, date_updated) |
130 | 130 | VALUES |
131 | 131 | (?, ?, ?, NOW(), ?, ?, NOW(), NOW())"); |
132 | - $sth->execute([$title, $guid, $url, $content, $content_hash]); |
|
132 | + $sth->execute([$title, $guid, $url, $content, $content_hash]); |
|
133 | 133 | |
134 | - $sth = $pdo->prepare("SELECT id FROM ttrss_entries WHERE guid = ?"); |
|
135 | - $sth->execute([$guid]); |
|
134 | + $sth = $pdo->prepare("SELECT id FROM ttrss_entries WHERE guid = ?"); |
|
135 | + $sth->execute([$guid]); |
|
136 | 136 | |
137 | - if ($row = $sth->fetch()) { |
|
138 | - $ref_id = $row["id"]; |
|
139 | - if (DB_TYPE == "pgsql") { |
|
140 | - $sth = $pdo->prepare("UPDATE ttrss_entries |
|
137 | + if ($row = $sth->fetch()) { |
|
138 | + $ref_id = $row["id"]; |
|
139 | + if (DB_TYPE == "pgsql") { |
|
140 | + $sth = $pdo->prepare("UPDATE ttrss_entries |
|
141 | 141 | SET tsvector_combined = to_tsvector( :ts_content) |
142 | 142 | WHERE id = :id"); |
143 | - $params = [ |
|
144 | - ":ts_content" => mb_substr(strip_tags($content), 0, 900000), |
|
145 | - ":id" => $ref_id]; |
|
146 | - $sth->execute($params); |
|
147 | - } |
|
148 | - $sth = $pdo->prepare("INSERT INTO ttrss_user_entries |
|
143 | + $params = [ |
|
144 | + ":ts_content" => mb_substr(strip_tags($content), 0, 900000), |
|
145 | + ":id" => $ref_id]; |
|
146 | + $sth->execute($params); |
|
147 | + } |
|
148 | + $sth = $pdo->prepare("INSERT INTO ttrss_user_entries |
|
149 | 149 | (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, |
150 | 150 | last_read, note, unread, last_published) |
151 | 151 | VALUES |
152 | 152 | (?, '', NULL, NULL, ?, true, '', '', NOW(), '', false, NOW())"); |
153 | - $sth->execute([$ref_id, $owner_uid]); |
|
153 | + $sth->execute([$ref_id, $owner_uid]); |
|
154 | 154 | |
155 | - if (count($labels) != 0) { |
|
156 | - foreach ($labels as $label) { |
|
157 | - Labels::add_article($ref_id, trim($label), $owner_uid); |
|
158 | - } |
|
159 | - } |
|
155 | + if (count($labels) != 0) { |
|
156 | + foreach ($labels as $label) { |
|
157 | + Labels::add_article($ref_id, trim($label), $owner_uid); |
|
158 | + } |
|
159 | + } |
|
160 | 160 | |
161 | - $rc = true; |
|
162 | - } |
|
163 | - } |
|
161 | + $rc = true; |
|
162 | + } |
|
163 | + } |
|
164 | 164 | |
165 | - $pdo->commit(); |
|
165 | + $pdo->commit(); |
|
166 | 166 | |
167 | - return $rc; |
|
168 | - } |
|
167 | + return $rc; |
|
168 | + } |
|
169 | 169 | |
170 | - public function editArticleTags() { |
|
170 | + public function editArticleTags() { |
|
171 | 171 | |
172 | - $param = clean($_REQUEST['param']); |
|
172 | + $param = clean($_REQUEST['param']); |
|
173 | 173 | |
174 | - $tags = Article::get_article_tags($param); |
|
174 | + $tags = Article::get_article_tags($param); |
|
175 | 175 | |
176 | - $tags_str = join(", ", $tags); |
|
176 | + $tags_str = join(", ", $tags); |
|
177 | 177 | |
178 | - print_hidden("id", "$param"); |
|
179 | - print_hidden("op", "article"); |
|
180 | - print_hidden("method", "setArticleTags"); |
|
178 | + print_hidden("id", "$param"); |
|
179 | + print_hidden("op", "article"); |
|
180 | + print_hidden("method", "setArticleTags"); |
|
181 | 181 | |
182 | - print "<header class='horizontal'>".__("Tags for this article (separated by commas):")."</header>"; |
|
182 | + print "<header class='horizontal'>".__("Tags for this article (separated by commas):")."</header>"; |
|
183 | 183 | |
184 | - print "<section>"; |
|
185 | - print "<textarea dojoType='dijit.form.SimpleTextarea' rows='4' |
|
184 | + print "<section>"; |
|
185 | + print "<textarea dojoType='dijit.form.SimpleTextarea' rows='4' |
|
186 | 186 | style='height : 100px; font-size : 12px; width : 98%' id='tags_str' |
187 | 187 | name='tags_str'>$tags_str</textarea> |
188 | 188 | <div class='autocomplete' id='tags_choices' |
189 | 189 | style='display:none'></div>"; |
190 | - print "</section>"; |
|
190 | + print "</section>"; |
|
191 | 191 | |
192 | - print "<footer>"; |
|
193 | - print "<button dojoType='dijit.form.Button' |
|
192 | + print "<footer>"; |
|
193 | + print "<button dojoType='dijit.form.Button' |
|
194 | 194 | type='submit' class='alt-primary' onclick=\"dijit.byId('editTagsDlg').execute()\">".__('Save')."</button> "; |
195 | - print "<button dojoType='dijit.form.Button' |
|
195 | + print "<button dojoType='dijit.form.Button' |
|
196 | 196 | onclick=\"dijit.byId('editTagsDlg').hide()\">".__('Cancel')."</button>"; |
197 | - print "</footer>"; |
|
197 | + print "</footer>"; |
|
198 | 198 | |
199 | - } |
|
199 | + } |
|
200 | 200 | |
201 | - public function setScore() { |
|
202 | - $ids = explode(",", clean($_REQUEST['id'])); |
|
203 | - $score = (int) clean($_REQUEST['score']); |
|
201 | + public function setScore() { |
|
202 | + $ids = explode(",", clean($_REQUEST['id'])); |
|
203 | + $score = (int) clean($_REQUEST['score']); |
|
204 | 204 | |
205 | - $ids_qmarks = arr_qmarks($ids); |
|
205 | + $ids_qmarks = arr_qmarks($ids); |
|
206 | 206 | |
207 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
207 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
208 | 208 | score = ? WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
209 | 209 | |
210 | - $sth->execute(array_merge([$score], $ids, [$_SESSION['uid']])); |
|
210 | + $sth->execute(array_merge([$score], $ids, [$_SESSION['uid']])); |
|
211 | 211 | |
212 | - print json_encode(["id" => $ids, "score" => (int) $score]); |
|
213 | - } |
|
212 | + print json_encode(["id" => $ids, "score" => (int) $score]); |
|
213 | + } |
|
214 | 214 | |
215 | - public function getScore() { |
|
216 | - $id = clean($_REQUEST['id']); |
|
215 | + public function getScore() { |
|
216 | + $id = clean($_REQUEST['id']); |
|
217 | 217 | |
218 | - $sth = $this->pdo->prepare("SELECT score FROM ttrss_user_entries WHERE ref_id = ? AND owner_uid = ?"); |
|
219 | - $sth->execute([$id, $_SESSION['uid']]); |
|
220 | - $row = $sth->fetch(); |
|
218 | + $sth = $this->pdo->prepare("SELECT score FROM ttrss_user_entries WHERE ref_id = ? AND owner_uid = ?"); |
|
219 | + $sth->execute([$id, $_SESSION['uid']]); |
|
220 | + $row = $sth->fetch(); |
|
221 | 221 | |
222 | - $score = $row['score']; |
|
222 | + $score = $row['score']; |
|
223 | 223 | |
224 | - print json_encode(["id" => $id, "score" => (int) $score]); |
|
225 | - } |
|
224 | + print json_encode(["id" => $id, "score" => (int) $score]); |
|
225 | + } |
|
226 | 226 | |
227 | 227 | |
228 | - public function setArticleTags() { |
|
228 | + public function setArticleTags() { |
|
229 | 229 | |
230 | - $id = clean($_REQUEST["id"]); |
|
230 | + $id = clean($_REQUEST["id"]); |
|
231 | 231 | |
232 | - $tags_str = clean($_REQUEST["tags_str"]); |
|
233 | - $tags = array_unique(trim_array(explode(",", $tags_str))); |
|
232 | + $tags_str = clean($_REQUEST["tags_str"]); |
|
233 | + $tags = array_unique(trim_array(explode(",", $tags_str))); |
|
234 | 234 | |
235 | - $this->pdo->beginTransaction(); |
|
235 | + $this->pdo->beginTransaction(); |
|
236 | 236 | |
237 | - $sth = $this->pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE |
|
237 | + $sth = $this->pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE |
|
238 | 238 | ref_id = ? AND owner_uid = ? LIMIT 1"); |
239 | - $sth->execute([$id, $_SESSION['uid']]); |
|
239 | + $sth->execute([$id, $_SESSION['uid']]); |
|
240 | 240 | |
241 | - if ($row = $sth->fetch()) { |
|
241 | + if ($row = $sth->fetch()) { |
|
242 | 242 | |
243 | - $tags_to_cache = array(); |
|
243 | + $tags_to_cache = array(); |
|
244 | 244 | |
245 | - $int_id = $row['int_id']; |
|
245 | + $int_id = $row['int_id']; |
|
246 | 246 | |
247 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_tags WHERE |
|
247 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_tags WHERE |
|
248 | 248 | post_int_id = ? AND owner_uid = ?"); |
249 | - $sth->execute([$int_id, $_SESSION['uid']]); |
|
249 | + $sth->execute([$int_id, $_SESSION['uid']]); |
|
250 | 250 | |
251 | - $tags = FeedItem_Common::normalize_categories($tags); |
|
251 | + $tags = FeedItem_Common::normalize_categories($tags); |
|
252 | 252 | |
253 | - foreach ($tags as $tag) { |
|
254 | - if ($tag != '') { |
|
255 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_tags |
|
253 | + foreach ($tags as $tag) { |
|
254 | + if ($tag != '') { |
|
255 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_tags |
|
256 | 256 | (post_int_id, owner_uid, tag_name) |
257 | 257 | VALUES (?, ?, ?)"); |
258 | 258 | |
259 | - $sth->execute([$int_id, $_SESSION['uid'], $tag]); |
|
260 | - } |
|
259 | + $sth->execute([$int_id, $_SESSION['uid'], $tag]); |
|
260 | + } |
|
261 | 261 | |
262 | - array_push($tags_to_cache, $tag); |
|
263 | - } |
|
262 | + array_push($tags_to_cache, $tag); |
|
263 | + } |
|
264 | 264 | |
265 | - /* update tag cache */ |
|
265 | + /* update tag cache */ |
|
266 | 266 | |
267 | - $tags_str = join(",", $tags_to_cache); |
|
267 | + $tags_str = join(",", $tags_to_cache); |
|
268 | 268 | |
269 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries |
|
269 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries |
|
270 | 270 | SET tag_cache = ? WHERE ref_id = ? AND owner_uid = ?"); |
271 | - $sth->execute([$tags_str, $id, $_SESSION['uid']]); |
|
272 | - } |
|
271 | + $sth->execute([$tags_str, $id, $_SESSION['uid']]); |
|
272 | + } |
|
273 | 273 | |
274 | - $this->pdo->commit(); |
|
274 | + $this->pdo->commit(); |
|
275 | 275 | |
276 | - $tags = Article::get_article_tags($id); |
|
277 | - $tags_str = $this->format_tags_string($tags); |
|
278 | - $tags_str_full = join(", ", $tags); |
|
276 | + $tags = Article::get_article_tags($id); |
|
277 | + $tags_str = $this->format_tags_string($tags); |
|
278 | + $tags_str_full = join(", ", $tags); |
|
279 | 279 | |
280 | - if (!$tags_str_full) { |
|
281 | - $tags_str_full = __("no tags"); |
|
282 | - } |
|
280 | + if (!$tags_str_full) { |
|
281 | + $tags_str_full = __("no tags"); |
|
282 | + } |
|
283 | 283 | |
284 | - print json_encode([ |
|
285 | - "id" => (int) $id, |
|
286 | - "content" => $tags_str, |
|
287 | - "content_full" => $tags_str_full |
|
288 | - ]); |
|
289 | - } |
|
284 | + print json_encode([ |
|
285 | + "id" => (int) $id, |
|
286 | + "content" => $tags_str, |
|
287 | + "content_full" => $tags_str_full |
|
288 | + ]); |
|
289 | + } |
|
290 | 290 | |
291 | 291 | |
292 | - public function completeTags() { |
|
293 | - $search = clean($_REQUEST["search"]); |
|
292 | + public function completeTags() { |
|
293 | + $search = clean($_REQUEST["search"]); |
|
294 | 294 | |
295 | - $sth = $this->pdo->prepare("SELECT DISTINCT tag_name FROM ttrss_tags |
|
295 | + $sth = $this->pdo->prepare("SELECT DISTINCT tag_name FROM ttrss_tags |
|
296 | 296 | WHERE owner_uid = ? AND |
297 | 297 | tag_name LIKE ? ORDER BY tag_name |
298 | 298 | LIMIT 10"); |
299 | 299 | |
300 | - $sth->execute([$_SESSION['uid'], "$search%"]); |
|
300 | + $sth->execute([$_SESSION['uid'], "$search%"]); |
|
301 | 301 | |
302 | - print "<ul>"; |
|
303 | - while ($line = $sth->fetch()) { |
|
304 | - print "<li>".$line["tag_name"]."</li>"; |
|
305 | - } |
|
306 | - print "</ul>"; |
|
307 | - } |
|
302 | + print "<ul>"; |
|
303 | + while ($line = $sth->fetch()) { |
|
304 | + print "<li>".$line["tag_name"]."</li>"; |
|
305 | + } |
|
306 | + print "</ul>"; |
|
307 | + } |
|
308 | 308 | |
309 | - public function assigntolabel() { |
|
310 | - return $this->labelops(true); |
|
311 | - } |
|
309 | + public function assigntolabel() { |
|
310 | + return $this->labelops(true); |
|
311 | + } |
|
312 | 312 | |
313 | - public function removefromlabel() { |
|
314 | - return $this->labelops(false); |
|
315 | - } |
|
313 | + public function removefromlabel() { |
|
314 | + return $this->labelops(false); |
|
315 | + } |
|
316 | 316 | |
317 | - private function labelops($assign) { |
|
318 | - $reply = array(); |
|
317 | + private function labelops($assign) { |
|
318 | + $reply = array(); |
|
319 | 319 | |
320 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
321 | - $label_id = clean($_REQUEST["lid"]); |
|
320 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
321 | + $label_id = clean($_REQUEST["lid"]); |
|
322 | 322 | |
323 | - $label = Labels::find_caption($label_id, $_SESSION["uid"]); |
|
323 | + $label = Labels::find_caption($label_id, $_SESSION["uid"]); |
|
324 | 324 | |
325 | - $reply["info-for-headlines"] = array(); |
|
325 | + $reply["info-for-headlines"] = array(); |
|
326 | 326 | |
327 | - if ($label) { |
|
327 | + if ($label) { |
|
328 | 328 | |
329 | - foreach ($ids as $id) { |
|
329 | + foreach ($ids as $id) { |
|
330 | 330 | |
331 | - if ($assign) { |
|
332 | - Labels::add_article($id, $label, $_SESSION["uid"]); |
|
333 | - } else { |
|
334 | - Labels::remove_article($id, $label, $_SESSION["uid"]); |
|
335 | - } |
|
331 | + if ($assign) { |
|
332 | + Labels::add_article($id, $label, $_SESSION["uid"]); |
|
333 | + } else { |
|
334 | + Labels::remove_article($id, $label, $_SESSION["uid"]); |
|
335 | + } |
|
336 | 336 | |
337 | - $labels = $this->get_article_labels($id, $_SESSION["uid"]); |
|
337 | + $labels = $this->get_article_labels($id, $_SESSION["uid"]); |
|
338 | 338 | |
339 | - array_push($reply["info-for-headlines"], |
|
340 | - array("id" => $id, "labels" => $this->format_article_labels($labels))); |
|
339 | + array_push($reply["info-for-headlines"], |
|
340 | + array("id" => $id, "labels" => $this->format_article_labels($labels))); |
|
341 | 341 | |
342 | - } |
|
343 | - } |
|
342 | + } |
|
343 | + } |
|
344 | 344 | |
345 | - $reply["message"] = "UPDATE_COUNTERS"; |
|
345 | + $reply["message"] = "UPDATE_COUNTERS"; |
|
346 | 346 | |
347 | - print json_encode($reply); |
|
348 | - } |
|
347 | + print json_encode($reply); |
|
348 | + } |
|
349 | 349 | |
350 | - public function getArticleFeed($id) { |
|
351 | - $sth = $this->pdo->prepare("SELECT feed_id FROM ttrss_user_entries |
|
350 | + public function getArticleFeed($id) { |
|
351 | + $sth = $this->pdo->prepare("SELECT feed_id FROM ttrss_user_entries |
|
352 | 352 | WHERE ref_id = ? AND owner_uid = ?"); |
353 | - $sth->execute([$id, $_SESSION['uid']]); |
|
354 | - |
|
355 | - if ($row = $sth->fetch()) { |
|
356 | - return $row["feed_id"]; |
|
357 | - } else { |
|
358 | - return 0; |
|
359 | - } |
|
360 | - } |
|
361 | - |
|
362 | - public static function format_article_enclosures($id, $always_display_enclosures, |
|
363 | - $article_content, $hide_images = false) { |
|
364 | - |
|
365 | - $result = Article::get_article_enclosures($id); |
|
366 | - $rv = ''; |
|
367 | - |
|
368 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ENCLOSURES) as $plugin) { |
|
369 | - $retval = $plugin->hook_format_enclosures($rv, $result, $id, $always_display_enclosures, $article_content, $hide_images); |
|
370 | - if (is_array($retval)) { |
|
371 | - $rv = $retval[0]; |
|
372 | - $result = $retval[1]; |
|
373 | - } else { |
|
374 | - $rv = $retval; |
|
375 | - } |
|
376 | - } |
|
377 | - unset($retval); // Unset to prevent breaking render if there are no HOOK_RENDER_ENCLOSURE hooks below. |
|
378 | - |
|
379 | - if ($rv === '' && !empty($result)) { |
|
380 | - $entries_html = array(); |
|
381 | - $entries = array(); |
|
382 | - $entries_inline = array(); |
|
383 | - |
|
384 | - foreach ($result as $line) { |
|
385 | - |
|
386 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ENCLOSURE_ENTRY) as $plugin) { |
|
387 | - $line = $plugin->hook_enclosure_entry($line, $id); |
|
388 | - } |
|
389 | - |
|
390 | - $url = $line["content_url"]; |
|
391 | - $ctype = $line["content_type"]; |
|
392 | - $title = $line["title"]; |
|
393 | - $width = $line["width"]; |
|
394 | - $height = $line["height"]; |
|
395 | - |
|
396 | - if (!$ctype) { |
|
397 | - $ctype = __("unknown type"); |
|
398 | - } |
|
399 | - |
|
400 | - //$filename = substr($url, strrpos($url, "/")+1); |
|
401 | - $filename = basename($url); |
|
402 | - |
|
403 | - $player = format_inline_player($url, $ctype); |
|
404 | - |
|
405 | - if ($player) { |
|
406 | - array_push($entries_inline, $player); |
|
407 | - } |
|
353 | + $sth->execute([$id, $_SESSION['uid']]); |
|
354 | + |
|
355 | + if ($row = $sth->fetch()) { |
|
356 | + return $row["feed_id"]; |
|
357 | + } else { |
|
358 | + return 0; |
|
359 | + } |
|
360 | + } |
|
361 | + |
|
362 | + public static function format_article_enclosures($id, $always_display_enclosures, |
|
363 | + $article_content, $hide_images = false) { |
|
364 | + |
|
365 | + $result = Article::get_article_enclosures($id); |
|
366 | + $rv = ''; |
|
367 | + |
|
368 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ENCLOSURES) as $plugin) { |
|
369 | + $retval = $plugin->hook_format_enclosures($rv, $result, $id, $always_display_enclosures, $article_content, $hide_images); |
|
370 | + if (is_array($retval)) { |
|
371 | + $rv = $retval[0]; |
|
372 | + $result = $retval[1]; |
|
373 | + } else { |
|
374 | + $rv = $retval; |
|
375 | + } |
|
376 | + } |
|
377 | + unset($retval); // Unset to prevent breaking render if there are no HOOK_RENDER_ENCLOSURE hooks below. |
|
378 | + |
|
379 | + if ($rv === '' && !empty($result)) { |
|
380 | + $entries_html = array(); |
|
381 | + $entries = array(); |
|
382 | + $entries_inline = array(); |
|
383 | + |
|
384 | + foreach ($result as $line) { |
|
385 | + |
|
386 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ENCLOSURE_ENTRY) as $plugin) { |
|
387 | + $line = $plugin->hook_enclosure_entry($line, $id); |
|
388 | + } |
|
389 | + |
|
390 | + $url = $line["content_url"]; |
|
391 | + $ctype = $line["content_type"]; |
|
392 | + $title = $line["title"]; |
|
393 | + $width = $line["width"]; |
|
394 | + $height = $line["height"]; |
|
395 | + |
|
396 | + if (!$ctype) { |
|
397 | + $ctype = __("unknown type"); |
|
398 | + } |
|
399 | + |
|
400 | + //$filename = substr($url, strrpos($url, "/")+1); |
|
401 | + $filename = basename($url); |
|
402 | + |
|
403 | + $player = format_inline_player($url, $ctype); |
|
404 | + |
|
405 | + if ($player) { |
|
406 | + array_push($entries_inline, $player); |
|
407 | + } |
|
408 | 408 | |
409 | 409 | # $entry .= " <a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\" rel=\"noopener noreferrer\">" . |
410 | 410 | # $filename . " (" . $ctype . ")" . "</a>"; |
411 | 411 | |
412 | - $entry = "<div onclick=\"popupOpenUrl('".htmlspecialchars($url)."')\" |
|
412 | + $entry = "<div onclick=\"popupOpenUrl('".htmlspecialchars($url)."')\" |
|
413 | 413 | dojoType=\"dijit.MenuItem\">$filename ($ctype)</div>"; |
414 | 414 | |
415 | - array_push($entries_html, $entry); |
|
415 | + array_push($entries_html, $entry); |
|
416 | 416 | |
417 | - $entry = array(); |
|
417 | + $entry = array(); |
|
418 | 418 | |
419 | - $entry["type"] = $ctype; |
|
420 | - $entry["filename"] = $filename; |
|
421 | - $entry["url"] = $url; |
|
422 | - $entry["title"] = $title; |
|
423 | - $entry["width"] = $width; |
|
424 | - $entry["height"] = $height; |
|
419 | + $entry["type"] = $ctype; |
|
420 | + $entry["filename"] = $filename; |
|
421 | + $entry["url"] = $url; |
|
422 | + $entry["title"] = $title; |
|
423 | + $entry["width"] = $width; |
|
424 | + $entry["height"] = $height; |
|
425 | 425 | |
426 | - array_push($entries, $entry); |
|
427 | - } |
|
426 | + array_push($entries, $entry); |
|
427 | + } |
|
428 | 428 | |
429 | - if ($_SESSION['uid'] && !get_pref("STRIP_IMAGES") && !$_SESSION["bw_limit"]) { |
|
430 | - if ($always_display_enclosures || |
|
431 | - !preg_match("/<img/i", $article_content)) { |
|
429 | + if ($_SESSION['uid'] && !get_pref("STRIP_IMAGES") && !$_SESSION["bw_limit"]) { |
|
430 | + if ($always_display_enclosures || |
|
431 | + !preg_match("/<img/i", $article_content)) { |
|
432 | 432 | |
433 | - foreach ($entries as $entry) { |
|
433 | + foreach ($entries as $entry) { |
|
434 | 434 | |
435 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ENCLOSURE) as $plugin) { |
|
436 | - $retval = $plugin->hook_render_enclosure($entry, $hide_images); |
|
437 | - } |
|
435 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ENCLOSURE) as $plugin) { |
|
436 | + $retval = $plugin->hook_render_enclosure($entry, $hide_images); |
|
437 | + } |
|
438 | 438 | |
439 | 439 | |
440 | - if ($retval) { |
|
441 | - $rv .= $retval; |
|
442 | - } else { |
|
440 | + if ($retval) { |
|
441 | + $rv .= $retval; |
|
442 | + } else { |
|
443 | 443 | |
444 | - if (preg_match("/image/", $entry["type"])) { |
|
444 | + if (preg_match("/image/", $entry["type"])) { |
|
445 | 445 | |
446 | - if (!$hide_images) { |
|
447 | - $encsize = ''; |
|
448 | - if ($entry['height'] > 0) |
|
449 | - $encsize .= ' height="'.intval($entry['height']).'"'; |
|
450 | - if ($entry['width'] > 0) |
|
451 | - $encsize .= ' width="'.intval($entry['width']).'"'; |
|
452 | - $rv .= "<p><img |
|
446 | + if (!$hide_images) { |
|
447 | + $encsize = ''; |
|
448 | + if ($entry['height'] > 0) |
|
449 | + $encsize .= ' height="'.intval($entry['height']).'"'; |
|
450 | + if ($entry['width'] > 0) |
|
451 | + $encsize .= ' width="'.intval($entry['width']).'"'; |
|
452 | + $rv .= "<p><img |
|
453 | 453 | alt=\"".htmlspecialchars($entry["filename"])."\" |
454 | 454 | src=\"" .htmlspecialchars($entry["url"])."\" |
455 | 455 | " . $encsize." /></p>"; |
456 | - } else { |
|
457 | - $rv .= "<p><a target=\"_blank\" rel=\"noopener noreferrer\" |
|
456 | + } else { |
|
457 | + $rv .= "<p><a target=\"_blank\" rel=\"noopener noreferrer\" |
|
458 | 458 | href=\"".htmlspecialchars($entry["url"])."\" |
459 | 459 | >" .htmlspecialchars($entry["url"])."</a></p>"; |
460 | - } |
|
461 | - |
|
462 | - if ($entry['title']) { |
|
463 | - $rv .= "<div class=\"enclosure_title\">${entry['title']}</div>"; |
|
464 | - } |
|
465 | - } |
|
466 | - } |
|
467 | - } |
|
468 | - } |
|
469 | - } |
|
470 | - |
|
471 | - if (count($entries_inline) > 0) { |
|
472 | - //$rv .= "<hr clear='both'/>"; |
|
473 | - foreach ($entries_inline as $entry) { $rv .= $entry; }; |
|
474 | - $rv .= "<br clear='both'/>"; |
|
475 | - } |
|
476 | - |
|
477 | - $rv .= "<div class=\"attachments\" dojoType=\"fox.form.DropDownButton\">". |
|
478 | - "<span>".__('Attachments')."</span>"; |
|
479 | - |
|
480 | - $rv .= "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
481 | - |
|
482 | - foreach ($entries as $entry) { |
|
483 | - if ($entry["title"]) |
|
484 | - $title = " — ".truncate_string($entry["title"], 30); |
|
485 | - else |
|
486 | - $title = ""; |
|
487 | - |
|
488 | - if ($entry["filename"]) |
|
489 | - $filename = truncate_middle(htmlspecialchars($entry["filename"]), 60); |
|
490 | - else |
|
491 | - $filename = ""; |
|
492 | - |
|
493 | - $rv .= "<div onclick='popupOpenUrl(\"".htmlspecialchars($entry["url"])."\")' |
|
460 | + } |
|
461 | + |
|
462 | + if ($entry['title']) { |
|
463 | + $rv .= "<div class=\"enclosure_title\">${entry['title']}</div>"; |
|
464 | + } |
|
465 | + } |
|
466 | + } |
|
467 | + } |
|
468 | + } |
|
469 | + } |
|
470 | + |
|
471 | + if (count($entries_inline) > 0) { |
|
472 | + //$rv .= "<hr clear='both'/>"; |
|
473 | + foreach ($entries_inline as $entry) { $rv .= $entry; }; |
|
474 | + $rv .= "<br clear='both'/>"; |
|
475 | + } |
|
476 | + |
|
477 | + $rv .= "<div class=\"attachments\" dojoType=\"fox.form.DropDownButton\">". |
|
478 | + "<span>".__('Attachments')."</span>"; |
|
479 | + |
|
480 | + $rv .= "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
481 | + |
|
482 | + foreach ($entries as $entry) { |
|
483 | + if ($entry["title"]) |
|
484 | + $title = " — ".truncate_string($entry["title"], 30); |
|
485 | + else |
|
486 | + $title = ""; |
|
487 | + |
|
488 | + if ($entry["filename"]) |
|
489 | + $filename = truncate_middle(htmlspecialchars($entry["filename"]), 60); |
|
490 | + else |
|
491 | + $filename = ""; |
|
492 | + |
|
493 | + $rv .= "<div onclick='popupOpenUrl(\"".htmlspecialchars($entry["url"])."\")' |
|
494 | 494 | dojoType=\"dijit.MenuItem\">".$filename.$title."</div>"; |
495 | 495 | |
496 | - }; |
|
496 | + }; |
|
497 | 497 | |
498 | - $rv .= "</div>"; |
|
499 | - $rv .= "</div>"; |
|
500 | - } |
|
498 | + $rv .= "</div>"; |
|
499 | + $rv .= "</div>"; |
|
500 | + } |
|
501 | 501 | |
502 | - return $rv; |
|
503 | - } |
|
502 | + return $rv; |
|
503 | + } |
|
504 | 504 | |
505 | - public static function get_article_tags($id, $owner_uid = 0, $tag_cache = false) { |
|
505 | + public static function get_article_tags($id, $owner_uid = 0, $tag_cache = false) { |
|
506 | 506 | |
507 | - $a_id = $id; |
|
507 | + $a_id = $id; |
|
508 | 508 | |
509 | - if (!$owner_uid) { |
|
510 | - $owner_uid = $_SESSION["uid"]; |
|
511 | - } |
|
509 | + if (!$owner_uid) { |
|
510 | + $owner_uid = $_SESSION["uid"]; |
|
511 | + } |
|
512 | 512 | |
513 | - $pdo = Db::pdo(); |
|
513 | + $pdo = Db::pdo(); |
|
514 | 514 | |
515 | - $sth = $pdo->prepare("SELECT DISTINCT tag_name, |
|
515 | + $sth = $pdo->prepare("SELECT DISTINCT tag_name, |
|
516 | 516 | owner_uid as owner FROM ttrss_tags |
517 | 517 | WHERE post_int_id = (SELECT int_id FROM ttrss_user_entries WHERE |
518 | 518 | ref_id = ? AND owner_uid = ? LIMIT 1) ORDER BY tag_name"); |
519 | 519 | |
520 | - $tags = array(); |
|
520 | + $tags = array(); |
|
521 | 521 | |
522 | - /* check cache first */ |
|
522 | + /* check cache first */ |
|
523 | 523 | |
524 | - if ($tag_cache === false) { |
|
525 | - $csth = $pdo->prepare("SELECT tag_cache FROM ttrss_user_entries |
|
524 | + if ($tag_cache === false) { |
|
525 | + $csth = $pdo->prepare("SELECT tag_cache FROM ttrss_user_entries |
|
526 | 526 | WHERE ref_id = ? AND owner_uid = ?"); |
527 | - $csth->execute([$id, $owner_uid]); |
|
527 | + $csth->execute([$id, $owner_uid]); |
|
528 | 528 | |
529 | - if ($row = $csth->fetch()) { |
|
530 | - $tag_cache = $row["tag_cache"]; |
|
531 | - } |
|
532 | - } |
|
529 | + if ($row = $csth->fetch()) { |
|
530 | + $tag_cache = $row["tag_cache"]; |
|
531 | + } |
|
532 | + } |
|
533 | 533 | |
534 | - if ($tag_cache) { |
|
535 | - $tags = explode(",", $tag_cache); |
|
536 | - } else { |
|
534 | + if ($tag_cache) { |
|
535 | + $tags = explode(",", $tag_cache); |
|
536 | + } else { |
|
537 | 537 | |
538 | - /* do it the hard way */ |
|
538 | + /* do it the hard way */ |
|
539 | 539 | |
540 | - $sth->execute([$a_id, $owner_uid]); |
|
540 | + $sth->execute([$a_id, $owner_uid]); |
|
541 | 541 | |
542 | - while ($tmp_line = $sth->fetch()) { |
|
543 | - array_push($tags, $tmp_line["tag_name"]); |
|
544 | - } |
|
542 | + while ($tmp_line = $sth->fetch()) { |
|
543 | + array_push($tags, $tmp_line["tag_name"]); |
|
544 | + } |
|
545 | 545 | |
546 | - /* update the cache */ |
|
546 | + /* update the cache */ |
|
547 | 547 | |
548 | - $tags_str = join(",", $tags); |
|
548 | + $tags_str = join(",", $tags); |
|
549 | 549 | |
550 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
550 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
551 | 551 | SET tag_cache = ? WHERE ref_id = ? |
552 | 552 | AND owner_uid = ?"); |
553 | - $sth->execute([$tags_str, $id, $owner_uid]); |
|
554 | - } |
|
553 | + $sth->execute([$tags_str, $id, $owner_uid]); |
|
554 | + } |
|
555 | 555 | |
556 | - return $tags; |
|
557 | - } |
|
556 | + return $tags; |
|
557 | + } |
|
558 | 558 | |
559 | - public static function format_tags_string($tags) { |
|
560 | - if (!is_array($tags) || count($tags) == 0) { |
|
561 | - return __("no tags"); |
|
562 | - } else { |
|
563 | - $maxtags = min(5, count($tags)); |
|
564 | - $tags_str = ""; |
|
559 | + public static function format_tags_string($tags) { |
|
560 | + if (!is_array($tags) || count($tags) == 0) { |
|
561 | + return __("no tags"); |
|
562 | + } else { |
|
563 | + $maxtags = min(5, count($tags)); |
|
564 | + $tags_str = ""; |
|
565 | 565 | |
566 | - for ($i = 0; $i < $maxtags; $i++) { |
|
567 | - $tags_str .= "<a class=\"tag\" href=\"#\" onclick=\"Feeds.open({feed:'".$tags[$i]."'})\">".$tags[$i]."</a>, "; |
|
568 | - } |
|
566 | + for ($i = 0; $i < $maxtags; $i++) { |
|
567 | + $tags_str .= "<a class=\"tag\" href=\"#\" onclick=\"Feeds.open({feed:'".$tags[$i]."'})\">".$tags[$i]."</a>, "; |
|
568 | + } |
|
569 | 569 | |
570 | - $tags_str = mb_substr($tags_str, 0, mb_strlen($tags_str) - 2); |
|
570 | + $tags_str = mb_substr($tags_str, 0, mb_strlen($tags_str) - 2); |
|
571 | 571 | |
572 | - if (count($tags) > $maxtags) { |
|
573 | - $tags_str .= ", …"; |
|
574 | - } |
|
572 | + if (count($tags) > $maxtags) { |
|
573 | + $tags_str .= ", …"; |
|
574 | + } |
|
575 | 575 | |
576 | - return $tags_str; |
|
577 | - } |
|
578 | - } |
|
576 | + return $tags_str; |
|
577 | + } |
|
578 | + } |
|
579 | 579 | |
580 | - public static function format_article_labels($labels) { |
|
580 | + public static function format_article_labels($labels) { |
|
581 | 581 | |
582 | - if (!is_array($labels)) { |
|
583 | - return ''; |
|
584 | - } |
|
582 | + if (!is_array($labels)) { |
|
583 | + return ''; |
|
584 | + } |
|
585 | 585 | |
586 | - $labels_str = ""; |
|
586 | + $labels_str = ""; |
|
587 | 587 | |
588 | - foreach ($labels as $l) { |
|
589 | - $labels_str .= sprintf("<div class='label' |
|
588 | + foreach ($labels as $l) { |
|
589 | + $labels_str .= sprintf("<div class='label' |
|
590 | 590 | style='color : %s; background-color : %s'>%s</div>", |
591 | - $l[2], $l[3], $l[1]); |
|
592 | - } |
|
591 | + $l[2], $l[3], $l[1]); |
|
592 | + } |
|
593 | 593 | |
594 | - return $labels_str; |
|
594 | + return $labels_str; |
|
595 | 595 | |
596 | - } |
|
596 | + } |
|
597 | 597 | |
598 | - public static function format_article_note($id, $note, $allow_edit = true) { |
|
598 | + public static function format_article_note($id, $note, $allow_edit = true) { |
|
599 | 599 | |
600 | - if ($allow_edit) { |
|
601 | - $onclick = "onclick='Plugins.Note.edit($id)'"; |
|
602 | - $note_class = 'editable'; |
|
603 | - } else { |
|
604 | - $onclick = ''; |
|
605 | - $note_class = ''; |
|
606 | - } |
|
600 | + if ($allow_edit) { |
|
601 | + $onclick = "onclick='Plugins.Note.edit($id)'"; |
|
602 | + $note_class = 'editable'; |
|
603 | + } else { |
|
604 | + $onclick = ''; |
|
605 | + $note_class = ''; |
|
606 | + } |
|
607 | 607 | |
608 | - return "<div class='article-note $note_class'> |
|
608 | + return "<div class='article-note $note_class'> |
|
609 | 609 | <i class='material-icons'>note</i> |
610 | 610 | <div $onclick class='body'>$note</div> |
611 | 611 | </div>"; |
612 | - } |
|
612 | + } |
|
613 | 613 | |
614 | - public static function get_article_enclosures($id) { |
|
614 | + public static function get_article_enclosures($id) { |
|
615 | 615 | |
616 | - $pdo = Db::pdo(); |
|
616 | + $pdo = Db::pdo(); |
|
617 | 617 | |
618 | - $sth = $pdo->prepare("SELECT * FROM ttrss_enclosures |
|
618 | + $sth = $pdo->prepare("SELECT * FROM ttrss_enclosures |
|
619 | 619 | WHERE post_id = ? AND content_url != ''"); |
620 | - $sth->execute([$id]); |
|
620 | + $sth->execute([$id]); |
|
621 | 621 | |
622 | - $rv = array(); |
|
622 | + $rv = array(); |
|
623 | 623 | |
624 | - $cache = new DiskCache("images"); |
|
624 | + $cache = new DiskCache("images"); |
|
625 | 625 | |
626 | - while ($line = $sth->fetch()) { |
|
626 | + while ($line = $sth->fetch()) { |
|
627 | 627 | |
628 | - if ($cache->exists(sha1($line["content_url"]))) { |
|
629 | - $line["content_url"] = $cache->getUrl(sha1($line["content_url"])); |
|
630 | - } |
|
628 | + if ($cache->exists(sha1($line["content_url"]))) { |
|
629 | + $line["content_url"] = $cache->getUrl(sha1($line["content_url"])); |
|
630 | + } |
|
631 | 631 | |
632 | - array_push($rv, $line); |
|
633 | - } |
|
632 | + array_push($rv, $line); |
|
633 | + } |
|
634 | 634 | |
635 | - return $rv; |
|
636 | - } |
|
635 | + return $rv; |
|
636 | + } |
|
637 | 637 | |
638 | - public static function purge_orphans() { |
|
638 | + public static function purge_orphans() { |
|
639 | 639 | |
640 | 640 | // purge orphaned posts in main content table |
641 | 641 | |
@@ -655,180 +655,180 @@ discard block |
||
655 | 655 | } |
656 | 656 | } |
657 | 657 | |
658 | - public static function catchupArticlesById($ids, $cmode, $owner_uid = false) { |
|
658 | + public static function catchupArticlesById($ids, $cmode, $owner_uid = false) { |
|
659 | 659 | |
660 | - if (!$owner_uid) { |
|
661 | - $owner_uid = $_SESSION["uid"]; |
|
662 | - } |
|
660 | + if (!$owner_uid) { |
|
661 | + $owner_uid = $_SESSION["uid"]; |
|
662 | + } |
|
663 | 663 | |
664 | - $pdo = Db::pdo(); |
|
664 | + $pdo = Db::pdo(); |
|
665 | 665 | |
666 | - $ids_qmarks = arr_qmarks($ids); |
|
666 | + $ids_qmarks = arr_qmarks($ids); |
|
667 | 667 | |
668 | - if ($cmode == 1) { |
|
669 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
668 | + if ($cmode == 1) { |
|
669 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
670 | 670 | unread = true |
671 | 671 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
672 | - } else if ($cmode == 2) { |
|
673 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
672 | + } else if ($cmode == 2) { |
|
673 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
674 | 674 | unread = NOT unread,last_read = NOW() |
675 | 675 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
676 | - } else { |
|
677 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
676 | + } else { |
|
677 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
678 | 678 | unread = false,last_read = NOW() |
679 | 679 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
680 | - } |
|
680 | + } |
|
681 | 681 | |
682 | - $sth->execute(array_merge($ids, [$owner_uid])); |
|
682 | + $sth->execute(array_merge($ids, [$owner_uid])); |
|
683 | 683 | |
684 | - /* update ccache */ |
|
684 | + /* update ccache */ |
|
685 | 685 | |
686 | - $sth = $pdo->prepare("SELECT DISTINCT feed_id FROM ttrss_user_entries |
|
686 | + $sth = $pdo->prepare("SELECT DISTINCT feed_id FROM ttrss_user_entries |
|
687 | 687 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
688 | - $sth->execute(array_merge($ids, [$owner_uid])); |
|
688 | + $sth->execute(array_merge($ids, [$owner_uid])); |
|
689 | 689 | |
690 | - while ($line = $sth->fetch()) { |
|
691 | - CCache::update($line["feed_id"], $owner_uid); |
|
692 | - } |
|
693 | - } |
|
690 | + while ($line = $sth->fetch()) { |
|
691 | + CCache::update($line["feed_id"], $owner_uid); |
|
692 | + } |
|
693 | + } |
|
694 | 694 | |
695 | - public static function getLastArticleId() { |
|
696 | - $pdo = DB::pdo(); |
|
695 | + public static function getLastArticleId() { |
|
696 | + $pdo = DB::pdo(); |
|
697 | 697 | |
698 | - $sth = $pdo->prepare("SELECT ref_id AS id FROM ttrss_user_entries |
|
698 | + $sth = $pdo->prepare("SELECT ref_id AS id FROM ttrss_user_entries |
|
699 | 699 | WHERE owner_uid = ? ORDER BY ref_id DESC LIMIT 1"); |
700 | - $sth->execute([$_SESSION['uid']]); |
|
700 | + $sth->execute([$_SESSION['uid']]); |
|
701 | 701 | |
702 | - if ($row = $sth->fetch()) { |
|
703 | - return $row['id']; |
|
704 | - } else { |
|
705 | - return -1; |
|
706 | - } |
|
707 | - } |
|
702 | + if ($row = $sth->fetch()) { |
|
703 | + return $row['id']; |
|
704 | + } else { |
|
705 | + return -1; |
|
706 | + } |
|
707 | + } |
|
708 | 708 | |
709 | - public static function get_article_labels($id, $owner_uid = false) { |
|
710 | - $rv = array(); |
|
709 | + public static function get_article_labels($id, $owner_uid = false) { |
|
710 | + $rv = array(); |
|
711 | 711 | |
712 | - if (!$owner_uid) { |
|
713 | - $owner_uid = $_SESSION["uid"]; |
|
714 | - } |
|
712 | + if (!$owner_uid) { |
|
713 | + $owner_uid = $_SESSION["uid"]; |
|
714 | + } |
|
715 | 715 | |
716 | - $pdo = Db::pdo(); |
|
716 | + $pdo = Db::pdo(); |
|
717 | 717 | |
718 | - $sth = $pdo->prepare("SELECT label_cache FROM |
|
718 | + $sth = $pdo->prepare("SELECT label_cache FROM |
|
719 | 719 | ttrss_user_entries WHERE ref_id = ? AND owner_uid = ?"); |
720 | - $sth->execute([$id, $owner_uid]); |
|
720 | + $sth->execute([$id, $owner_uid]); |
|
721 | 721 | |
722 | - if ($row = $sth->fetch()) { |
|
723 | - $label_cache = $row["label_cache"]; |
|
722 | + if ($row = $sth->fetch()) { |
|
723 | + $label_cache = $row["label_cache"]; |
|
724 | 724 | |
725 | - if ($label_cache) { |
|
726 | - $tmp = json_decode($label_cache, true); |
|
725 | + if ($label_cache) { |
|
726 | + $tmp = json_decode($label_cache, true); |
|
727 | 727 | |
728 | - if (!$tmp || $tmp["no-labels"] == 1) { |
|
729 | - return $rv; |
|
730 | - } else { |
|
731 | - return $tmp; |
|
732 | - } |
|
733 | - } |
|
734 | - } |
|
728 | + if (!$tmp || $tmp["no-labels"] == 1) { |
|
729 | + return $rv; |
|
730 | + } else { |
|
731 | + return $tmp; |
|
732 | + } |
|
733 | + } |
|
734 | + } |
|
735 | 735 | |
736 | - $sth = $pdo->prepare("SELECT DISTINCT label_id,caption,fg_color,bg_color |
|
736 | + $sth = $pdo->prepare("SELECT DISTINCT label_id,caption,fg_color,bg_color |
|
737 | 737 | FROM ttrss_labels2, ttrss_user_labels2 |
738 | 738 | WHERE id = label_id |
739 | 739 | AND article_id = ? |
740 | 740 | AND owner_uid = ? |
741 | 741 | ORDER BY caption"); |
742 | - $sth->execute([$id, $owner_uid]); |
|
743 | - |
|
744 | - while ($line = $sth->fetch()) { |
|
745 | - $rk = array(Labels::label_to_feed_id($line["label_id"]), |
|
746 | - $line["caption"], $line["fg_color"], |
|
747 | - $line["bg_color"]); |
|
748 | - array_push($rv, $rk); |
|
749 | - } |
|
750 | - |
|
751 | - if (count($rv) > 0) { |
|
752 | - Labels::update_cache($owner_uid, $id, $rv); |
|
753 | - } else { |
|
754 | - Labels::update_cache($owner_uid, $id, array("no-labels" => 1)); |
|
755 | - } |
|
756 | - |
|
757 | - return $rv; |
|
758 | - } |
|
759 | - |
|
760 | - public static function get_article_image($enclosures, $content, $site_url) { |
|
761 | - |
|
762 | - $article_image = ""; |
|
763 | - $article_stream = ""; |
|
764 | - |
|
765 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_IMAGE) as $p) { |
|
766 | - list ($article_image, $article_stream, $content) = $p->hook_article_image($enclosures, $content, $site_url); |
|
767 | - } |
|
768 | - |
|
769 | - if (!$article_image && !$article_stream) { |
|
770 | - $tmpdoc = new DOMDocument(); |
|
771 | - |
|
772 | - if (@$tmpdoc->loadHTML('<?xml encoding="UTF-8">'.mb_substr($content, 0, 131070))) { |
|
773 | - $tmpxpath = new DOMXPath($tmpdoc); |
|
774 | - $elems = $tmpxpath->query('(//img[@src]|//video[@poster]|//iframe[contains(@src , "youtube.com/embed/")])'); |
|
775 | - |
|
776 | - foreach ($elems as $e) { |
|
777 | - if ($e->nodeName == "iframe") { |
|
778 | - $matches = []; |
|
779 | - if (preg_match("/\/embed\/([\w-]+)/", $e->getAttribute("src"), $matches)) { |
|
780 | - $article_image = "https://img.youtube.com/vi/".$matches[1]."/hqdefault.jpg"; |
|
781 | - $article_stream = "https://youtu.be/".$matches[1]; |
|
782 | - break; |
|
783 | - } |
|
784 | - } else if ($e->nodeName == "video") { |
|
785 | - $article_image = $e->getAttribute("poster"); |
|
786 | - |
|
787 | - $src = $tmpxpath->query("//source[@src]", $e)->item(0); |
|
788 | - |
|
789 | - if ($src) { |
|
790 | - $article_stream = $src->getAttribute("src"); |
|
791 | - } |
|
792 | - |
|
793 | - break; |
|
794 | - } else if ($e->nodeName == 'img') { |
|
795 | - if (mb_strpos($e->getAttribute("src"), "data:") !== 0) { |
|
796 | - $article_image = $e->getAttribute("src"); |
|
797 | - } |
|
798 | - break; |
|
799 | - } |
|
800 | - } |
|
801 | - } |
|
802 | - |
|
803 | - if (!$article_image) { |
|
804 | - foreach ($enclosures as $enc) { |
|
805 | - if (strpos($enc["content_type"], "image/") !== false) { |
|
806 | - $article_image = $enc["content_url"]; |
|
807 | - } |
|
808 | - break; |
|
809 | - } |
|
810 | - } |
|
811 | - |
|
812 | - if ($article_image) { |
|
813 | - $article_image = rewrite_relative_url($site_url, $article_image); |
|
814 | - } |
|
815 | - |
|
816 | - if ($article_stream) { |
|
817 | - $article_stream = rewrite_relative_url($site_url, $article_stream); |
|
818 | - } |
|
819 | - } |
|
820 | - |
|
821 | - $cache = new DiskCache("images"); |
|
822 | - |
|
823 | - if ($article_image && $cache->exists(sha1($article_image))) { |
|
824 | - $article_image = $cache->getUrl(sha1($article_image)); |
|
825 | - } |
|
826 | - |
|
827 | - if ($article_stream && $cache->exists(sha1($article_stream))) { |
|
828 | - $article_stream = $cache->getUrl(sha1($article_stream)); |
|
829 | - } |
|
830 | - |
|
831 | - return [$article_image, $article_stream]; |
|
832 | - } |
|
742 | + $sth->execute([$id, $owner_uid]); |
|
743 | + |
|
744 | + while ($line = $sth->fetch()) { |
|
745 | + $rk = array(Labels::label_to_feed_id($line["label_id"]), |
|
746 | + $line["caption"], $line["fg_color"], |
|
747 | + $line["bg_color"]); |
|
748 | + array_push($rv, $rk); |
|
749 | + } |
|
750 | + |
|
751 | + if (count($rv) > 0) { |
|
752 | + Labels::update_cache($owner_uid, $id, $rv); |
|
753 | + } else { |
|
754 | + Labels::update_cache($owner_uid, $id, array("no-labels" => 1)); |
|
755 | + } |
|
756 | + |
|
757 | + return $rv; |
|
758 | + } |
|
759 | + |
|
760 | + public static function get_article_image($enclosures, $content, $site_url) { |
|
761 | + |
|
762 | + $article_image = ""; |
|
763 | + $article_stream = ""; |
|
764 | + |
|
765 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_IMAGE) as $p) { |
|
766 | + list ($article_image, $article_stream, $content) = $p->hook_article_image($enclosures, $content, $site_url); |
|
767 | + } |
|
768 | + |
|
769 | + if (!$article_image && !$article_stream) { |
|
770 | + $tmpdoc = new DOMDocument(); |
|
771 | + |
|
772 | + if (@$tmpdoc->loadHTML('<?xml encoding="UTF-8">'.mb_substr($content, 0, 131070))) { |
|
773 | + $tmpxpath = new DOMXPath($tmpdoc); |
|
774 | + $elems = $tmpxpath->query('(//img[@src]|//video[@poster]|//iframe[contains(@src , "youtube.com/embed/")])'); |
|
775 | + |
|
776 | + foreach ($elems as $e) { |
|
777 | + if ($e->nodeName == "iframe") { |
|
778 | + $matches = []; |
|
779 | + if (preg_match("/\/embed\/([\w-]+)/", $e->getAttribute("src"), $matches)) { |
|
780 | + $article_image = "https://img.youtube.com/vi/".$matches[1]."/hqdefault.jpg"; |
|
781 | + $article_stream = "https://youtu.be/".$matches[1]; |
|
782 | + break; |
|
783 | + } |
|
784 | + } else if ($e->nodeName == "video") { |
|
785 | + $article_image = $e->getAttribute("poster"); |
|
786 | + |
|
787 | + $src = $tmpxpath->query("//source[@src]", $e)->item(0); |
|
788 | + |
|
789 | + if ($src) { |
|
790 | + $article_stream = $src->getAttribute("src"); |
|
791 | + } |
|
792 | + |
|
793 | + break; |
|
794 | + } else if ($e->nodeName == 'img') { |
|
795 | + if (mb_strpos($e->getAttribute("src"), "data:") !== 0) { |
|
796 | + $article_image = $e->getAttribute("src"); |
|
797 | + } |
|
798 | + break; |
|
799 | + } |
|
800 | + } |
|
801 | + } |
|
802 | + |
|
803 | + if (!$article_image) { |
|
804 | + foreach ($enclosures as $enc) { |
|
805 | + if (strpos($enc["content_type"], "image/") !== false) { |
|
806 | + $article_image = $enc["content_url"]; |
|
807 | + } |
|
808 | + break; |
|
809 | + } |
|
810 | + } |
|
811 | + |
|
812 | + if ($article_image) { |
|
813 | + $article_image = rewrite_relative_url($site_url, $article_image); |
|
814 | + } |
|
815 | + |
|
816 | + if ($article_stream) { |
|
817 | + $article_stream = rewrite_relative_url($site_url, $article_stream); |
|
818 | + } |
|
819 | + } |
|
820 | + |
|
821 | + $cache = new DiskCache("images"); |
|
822 | + |
|
823 | + if ($article_image && $cache->exists(sha1($article_image))) { |
|
824 | + $article_image = $cache->getUrl(sha1($article_image)); |
|
825 | + } |
|
826 | + |
|
827 | + if ($article_stream && $cache->exists(sha1($article_stream))) { |
|
828 | + $article_stream = $cache->getUrl(sha1($article_stream)); |
|
829 | + } |
|
830 | + |
|
831 | + return [$article_image, $article_stream]; |
|
832 | + } |
|
833 | 833 | |
834 | 834 | } |
@@ -445,10 +445,12 @@ discard block |
||
445 | 445 | |
446 | 446 | if (!$hide_images) { |
447 | 447 | $encsize = ''; |
448 | - if ($entry['height'] > 0) |
|
449 | - $encsize .= ' height="'.intval($entry['height']).'"'; |
|
450 | - if ($entry['width'] > 0) |
|
451 | - $encsize .= ' width="'.intval($entry['width']).'"'; |
|
448 | + if ($entry['height'] > 0) { |
|
449 | + $encsize .= ' height="'.intval($entry['height']).'"'; |
|
450 | + } |
|
451 | + if ($entry['width'] > 0) { |
|
452 | + $encsize .= ' width="'.intval($entry['width']).'"'; |
|
453 | + } |
|
452 | 454 | $rv .= "<p><img |
453 | 455 | alt=\"".htmlspecialchars($entry["filename"])."\" |
454 | 456 | src=\"" .htmlspecialchars($entry["url"])."\" |
@@ -480,15 +482,17 @@ discard block |
||
480 | 482 | $rv .= "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
481 | 483 | |
482 | 484 | foreach ($entries as $entry) { |
483 | - if ($entry["title"]) |
|
484 | - $title = " — ".truncate_string($entry["title"], 30); |
|
485 | - else |
|
486 | - $title = ""; |
|
487 | - |
|
488 | - if ($entry["filename"]) |
|
489 | - $filename = truncate_middle(htmlspecialchars($entry["filename"]), 60); |
|
490 | - else |
|
491 | - $filename = ""; |
|
485 | + if ($entry["title"]) { |
|
486 | + $title = " — ".truncate_string($entry["title"], 30); |
|
487 | + } else { |
|
488 | + $title = ""; |
|
489 | + } |
|
490 | + |
|
491 | + if ($entry["filename"]) { |
|
492 | + $filename = truncate_middle(htmlspecialchars($entry["filename"]), 60); |
|
493 | + } else { |
|
494 | + $filename = ""; |
|
495 | + } |
|
492 | 496 | |
493 | 497 | $rv .= "<div onclick='popupOpenUrl(\"".htmlspecialchars($entry["url"])."\")' |
494 | 498 | dojoType=\"dijit.MenuItem\">".$filename.$title."</div>"; |
@@ -1,50 +1,50 @@ |
||
1 | 1 | <?php |
2 | 2 | class Auth_Base { |
3 | - private $pdo; |
|
3 | + private $pdo; |
|
4 | 4 | |
5 | - const AUTH_SERVICE_API = '_api'; |
|
5 | + const AUTH_SERVICE_API = '_api'; |
|
6 | 6 | |
7 | - public function __construct() { |
|
8 | - $this->pdo = Db::pdo(); |
|
9 | - } |
|
7 | + public function __construct() { |
|
8 | + $this->pdo = Db::pdo(); |
|
9 | + } |
|
10 | 10 | |
11 | - // Auto-creates specified user if allowed by system configuration |
|
12 | - // Can be used instead of find_user_by_login() by external auth modules |
|
13 | - public function auto_create_user($login, $password = false) { |
|
14 | - if ($login && defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE) { |
|
15 | - $user_id = $this->find_user_by_login($login); |
|
11 | + // Auto-creates specified user if allowed by system configuration |
|
12 | + // Can be used instead of find_user_by_login() by external auth modules |
|
13 | + public function auto_create_user($login, $password = false) { |
|
14 | + if ($login && defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE) { |
|
15 | + $user_id = $this->find_user_by_login($login); |
|
16 | 16 | |
17 | - if (!$password) { |
|
18 | - $password = make_password(); |
|
19 | - } |
|
17 | + if (!$password) { |
|
18 | + $password = make_password(); |
|
19 | + } |
|
20 | 20 | |
21 | - if (!$user_id) { |
|
22 | - $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
23 | - $pwd_hash = encrypt_password($password, $salt, true); |
|
21 | + if (!$user_id) { |
|
22 | + $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
23 | + $pwd_hash = encrypt_password($password, $salt, true); |
|
24 | 24 | |
25 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_users |
|
25 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_users |
|
26 | 26 | (login,access_level,last_login,created,pwd_hash,salt) |
27 | 27 | VALUES (?, 0, null, NOW(), ?,?)"); |
28 | - $sth->execute([$login, $pwd_hash, $salt]); |
|
28 | + $sth->execute([$login, $pwd_hash, $salt]); |
|
29 | 29 | |
30 | - return $this->find_user_by_login($login); |
|
30 | + return $this->find_user_by_login($login); |
|
31 | 31 | |
32 | - } else { |
|
33 | - return $user_id; |
|
34 | - } |
|
35 | - } |
|
32 | + } else { |
|
33 | + return $user_id; |
|
34 | + } |
|
35 | + } |
|
36 | 36 | |
37 | - return $this->find_user_by_login($login); |
|
38 | - } |
|
37 | + return $this->find_user_by_login($login); |
|
38 | + } |
|
39 | 39 | |
40 | - public function find_user_by_login($login) { |
|
41 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?"); |
|
42 | - $sth->execute([$login]); |
|
40 | + public function find_user_by_login($login) { |
|
41 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?"); |
|
42 | + $sth->execute([$login]); |
|
43 | 43 | |
44 | - if ($row = $sth->fetch()) { |
|
45 | - return $row["id"]; |
|
46 | - } else { |
|
47 | - return false; |
|
48 | - } |
|
49 | - } |
|
44 | + if ($row = $sth->fetch()) { |
|
45 | + return $row["id"]; |
|
46 | + } else { |
|
47 | + return false; |
|
48 | + } |
|
49 | + } |
|
50 | 50 | } |
@@ -1,157 +1,157 @@ |
||
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 | - } |
|
26 | - } else { |
|
27 | - return is_writable($this->dir); |
|
28 | - } |
|
29 | - } |
|
30 | - |
|
31 | - public function exists($filename) { |
|
32 | - return file_exists($this->getFullPath($filename)); |
|
33 | - } |
|
34 | - |
|
35 | - public function getSize($filename) { |
|
36 | - if ($this->exists($filename)) { |
|
37 | - return filesize($this->getFullPath($filename)); |
|
38 | - } else { |
|
39 | - return -1; |
|
40 | - } |
|
41 | - } |
|
42 | - |
|
43 | - public function getFullPath($filename) { |
|
44 | - $filename = clean_filename($filename); |
|
45 | - |
|
46 | - return $this->dir."/".$filename; |
|
47 | - } |
|
48 | - |
|
49 | - public function put($filename, $data) { |
|
50 | - return file_put_contents($this->getFullPath($filename), $data); |
|
51 | - } |
|
52 | - |
|
53 | - public function touch($filename) { |
|
54 | - return touch($this->getFullPath($filename)); |
|
55 | - } |
|
56 | - |
|
57 | - public function get($filename) { |
|
58 | - if ($this->exists($filename)) { |
|
59 | - return file_get_contents($this->getFullPath($filename)); |
|
60 | - } else { |
|
61 | - return null; |
|
62 | - } |
|
63 | - } |
|
64 | - |
|
65 | - public function getMimeType($filename) { |
|
66 | - if ($this->exists($filename)) { |
|
67 | - return mime_content_type($this->getFullPath($filename)); |
|
68 | - } else { |
|
69 | - return null; |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - public function send($filename) { |
|
74 | - header("Content-Disposition: inline; filename=\"$filename\""); |
|
75 | - |
|
76 | - return send_local_file($this->getFullPath($filename)); |
|
77 | - } |
|
78 | - |
|
79 | - public function getUrl($filename) { |
|
80 | - return get_self_url_prefix()."/public.php?op=cached_url&file=".basename($this->dir)."/".$filename; |
|
81 | - } |
|
82 | - |
|
83 | - // check for locally cached (media) URLs and rewrite to local versions |
|
84 | - // this is called separately after sanitize() and plugin render article hooks to allow |
|
85 | - // plugins work on original source URLs used before caching |
|
86 | - static public function rewriteUrls($str) |
|
87 | - { |
|
88 | - $res = trim($str); |
|
89 | - if (!$res) { |
|
90 | - return ''; |
|
91 | - } |
|
92 | - |
|
93 | - $doc = new DOMDocument(); |
|
94 | - if ($doc->loadHTML('<?xml encoding="UTF-8">'.$res)) { |
|
95 | - $xpath = new DOMXPath($doc); |
|
96 | - $cache = new DiskCache("images"); |
|
97 | - |
|
98 | - $entries = $xpath->query('(//img[@src]|//picture/source[@src]|//video[@poster]|//video/source[@src]|//audio/source[@src])'); |
|
99 | - |
|
100 | - $need_saving = false; |
|
101 | - |
|
102 | - foreach ($entries as $entry) { |
|
103 | - |
|
104 | - if ($entry->hasAttribute('src') || $entry->hasAttribute('poster')) { |
|
105 | - |
|
106 | - // should be already absolutized because this is called after sanitize() |
|
107 | - $src = $entry->hasAttribute('poster') ? $entry->getAttribute('poster') : $entry->getAttribute('src'); |
|
108 | - $cached_filename = sha1($src); |
|
109 | - |
|
110 | - if ($cache->exists($cached_filename)) { |
|
111 | - |
|
112 | - $src = $cache->getUrl(sha1($src)); |
|
113 | - |
|
114 | - if ($entry->hasAttribute('poster')) { |
|
115 | - $entry->setAttribute('poster', $src); |
|
116 | - } else { |
|
117 | - $entry->setAttribute('src', $src); |
|
118 | - $entry->removeAttribute("srcset"); |
|
119 | - } |
|
120 | - |
|
121 | - $need_saving = true; |
|
122 | - } |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - if ($need_saving) { |
|
127 | - $doc->removeChild($doc->firstChild); //remove doctype |
|
128 | - $res = $doc->saveHTML(); |
|
129 | - } |
|
130 | - } |
|
131 | - return $res; |
|
132 | - } |
|
133 | - |
|
134 | - public static function expire() { |
|
135 | - $dirs = array_filter(glob(CACHE_DIR."/*"), "is_dir"); |
|
136 | - |
|
137 | - foreach ($dirs as $cache_dir) { |
|
138 | - $num_deleted = 0; |
|
139 | - |
|
140 | - if (is_writable($cache_dir) && !file_exists("$cache_dir/.no-auto-expiry")) { |
|
141 | - $files = glob("$cache_dir/*"); |
|
142 | - |
|
143 | - if ($files) { |
|
144 | - foreach ($files as $file) { |
|
145 | - if (time() - filemtime($file) > 86400 * CACHE_MAX_DAYS) { |
|
146 | - unlink($file); |
|
147 | - |
|
148 | - ++$num_deleted; |
|
149 | - } |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - Debug::log("expired $cache_dir: removed $num_deleted files."); |
|
154 | - } |
|
155 | - } |
|
156 | - } |
|
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 | + } |
|
26 | + } else { |
|
27 | + return is_writable($this->dir); |
|
28 | + } |
|
29 | + } |
|
30 | + |
|
31 | + public function exists($filename) { |
|
32 | + return file_exists($this->getFullPath($filename)); |
|
33 | + } |
|
34 | + |
|
35 | + public function getSize($filename) { |
|
36 | + if ($this->exists($filename)) { |
|
37 | + return filesize($this->getFullPath($filename)); |
|
38 | + } else { |
|
39 | + return -1; |
|
40 | + } |
|
41 | + } |
|
42 | + |
|
43 | + public function getFullPath($filename) { |
|
44 | + $filename = clean_filename($filename); |
|
45 | + |
|
46 | + return $this->dir."/".$filename; |
|
47 | + } |
|
48 | + |
|
49 | + public function put($filename, $data) { |
|
50 | + return file_put_contents($this->getFullPath($filename), $data); |
|
51 | + } |
|
52 | + |
|
53 | + public function touch($filename) { |
|
54 | + return touch($this->getFullPath($filename)); |
|
55 | + } |
|
56 | + |
|
57 | + public function get($filename) { |
|
58 | + if ($this->exists($filename)) { |
|
59 | + return file_get_contents($this->getFullPath($filename)); |
|
60 | + } else { |
|
61 | + return null; |
|
62 | + } |
|
63 | + } |
|
64 | + |
|
65 | + public function getMimeType($filename) { |
|
66 | + if ($this->exists($filename)) { |
|
67 | + return mime_content_type($this->getFullPath($filename)); |
|
68 | + } else { |
|
69 | + return null; |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + public function send($filename) { |
|
74 | + header("Content-Disposition: inline; filename=\"$filename\""); |
|
75 | + |
|
76 | + return send_local_file($this->getFullPath($filename)); |
|
77 | + } |
|
78 | + |
|
79 | + public function getUrl($filename) { |
|
80 | + return get_self_url_prefix()."/public.php?op=cached_url&file=".basename($this->dir)."/".$filename; |
|
81 | + } |
|
82 | + |
|
83 | + // check for locally cached (media) URLs and rewrite to local versions |
|
84 | + // this is called separately after sanitize() and plugin render article hooks to allow |
|
85 | + // plugins work on original source URLs used before caching |
|
86 | + static public function rewriteUrls($str) |
|
87 | + { |
|
88 | + $res = trim($str); |
|
89 | + if (!$res) { |
|
90 | + return ''; |
|
91 | + } |
|
92 | + |
|
93 | + $doc = new DOMDocument(); |
|
94 | + if ($doc->loadHTML('<?xml encoding="UTF-8">'.$res)) { |
|
95 | + $xpath = new DOMXPath($doc); |
|
96 | + $cache = new DiskCache("images"); |
|
97 | + |
|
98 | + $entries = $xpath->query('(//img[@src]|//picture/source[@src]|//video[@poster]|//video/source[@src]|//audio/source[@src])'); |
|
99 | + |
|
100 | + $need_saving = false; |
|
101 | + |
|
102 | + foreach ($entries as $entry) { |
|
103 | + |
|
104 | + if ($entry->hasAttribute('src') || $entry->hasAttribute('poster')) { |
|
105 | + |
|
106 | + // should be already absolutized because this is called after sanitize() |
|
107 | + $src = $entry->hasAttribute('poster') ? $entry->getAttribute('poster') : $entry->getAttribute('src'); |
|
108 | + $cached_filename = sha1($src); |
|
109 | + |
|
110 | + if ($cache->exists($cached_filename)) { |
|
111 | + |
|
112 | + $src = $cache->getUrl(sha1($src)); |
|
113 | + |
|
114 | + if ($entry->hasAttribute('poster')) { |
|
115 | + $entry->setAttribute('poster', $src); |
|
116 | + } else { |
|
117 | + $entry->setAttribute('src', $src); |
|
118 | + $entry->removeAttribute("srcset"); |
|
119 | + } |
|
120 | + |
|
121 | + $need_saving = true; |
|
122 | + } |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + if ($need_saving) { |
|
127 | + $doc->removeChild($doc->firstChild); //remove doctype |
|
128 | + $res = $doc->saveHTML(); |
|
129 | + } |
|
130 | + } |
|
131 | + return $res; |
|
132 | + } |
|
133 | + |
|
134 | + public static function expire() { |
|
135 | + $dirs = array_filter(glob(CACHE_DIR."/*"), "is_dir"); |
|
136 | + |
|
137 | + foreach ($dirs as $cache_dir) { |
|
138 | + $num_deleted = 0; |
|
139 | + |
|
140 | + if (is_writable($cache_dir) && !file_exists("$cache_dir/.no-auto-expiry")) { |
|
141 | + $files = glob("$cache_dir/*"); |
|
142 | + |
|
143 | + if ($files) { |
|
144 | + foreach ($files as $file) { |
|
145 | + if (time() - filemtime($file) > 86400 * CACHE_MAX_DAYS) { |
|
146 | + unlink($file); |
|
147 | + |
|
148 | + ++$num_deleted; |
|
149 | + } |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + Debug::log("expired $cache_dir: removed $num_deleted files."); |
|
154 | + } |
|
155 | + } |
|
156 | + } |
|
157 | 157 | } |
@@ -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,184 +31,184 @@ 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"; |
|
59 | - } |
|
55 | + if ($hide_private_feeds) { |
|
56 | + $hide_qpart = "(private IS false AND auth_login = '' AND auth_pass = '')"; |
|
57 | + } else { |
|
58 | + $hide_qpart = "true"; |
|
59 | + } |
|
60 | 60 | |
61 | - $out = ""; |
|
61 | + $out = ""; |
|
62 | 62 | |
63 | - $ttrss_specific_qpart = ""; |
|
63 | + $ttrss_specific_qpart = ""; |
|
64 | 64 | |
65 | - if ($cat_id) { |
|
66 | - $sth = $this->pdo->prepare("SELECT title,order_id |
|
65 | + if ($cat_id) { |
|
66 | + $sth = $this->pdo->prepare("SELECT title,order_id |
|
67 | 67 | FROM ttrss_feed_categories WHERE id = ? |
68 | 68 | AND owner_uid = ?"); |
69 | - $sth->execute([$cat_id, $owner_uid]); |
|
70 | - $row = $sth->fetch(); |
|
71 | - $cat_title = htmlspecialchars($row['title']); |
|
72 | - |
|
73 | - if ($include_settings) { |
|
74 | - $order_id = (int) $row["order_id"]; |
|
75 | - $ttrss_specific_qpart = "ttrssSortOrder=\"$order_id\""; |
|
76 | - } |
|
77 | - } else { |
|
78 | - $cat_title = ""; |
|
79 | - } |
|
80 | - |
|
81 | - if ($cat_title) { |
|
82 | - $out .= "<outline text=\"$cat_title\" $ttrss_specific_qpart>\n"; |
|
83 | - } |
|
84 | - |
|
85 | - $sth = $this->pdo->prepare("SELECT id,title |
|
69 | + $sth->execute([$cat_id, $owner_uid]); |
|
70 | + $row = $sth->fetch(); |
|
71 | + $cat_title = htmlspecialchars($row['title']); |
|
72 | + |
|
73 | + if ($include_settings) { |
|
74 | + $order_id = (int) $row["order_id"]; |
|
75 | + $ttrss_specific_qpart = "ttrssSortOrder=\"$order_id\""; |
|
76 | + } |
|
77 | + } else { |
|
78 | + $cat_title = ""; |
|
79 | + } |
|
80 | + |
|
81 | + if ($cat_title) { |
|
82 | + $out .= "<outline text=\"$cat_title\" $ttrss_specific_qpart>\n"; |
|
83 | + } |
|
84 | + |
|
85 | + $sth = $this->pdo->prepare("SELECT id,title |
|
86 | 86 | FROM ttrss_feed_categories WHERE |
87 | 87 | (parent_cat = :cat OR (:cat = 0 AND parent_cat IS NULL)) AND |
88 | 88 | owner_uid = :uid ORDER BY order_id, title"); |
89 | 89 | |
90 | - $sth->execute([':cat' => $cat_id, ':uid' => $owner_uid]); |
|
90 | + $sth->execute([':cat' => $cat_id, ':uid' => $owner_uid]); |
|
91 | 91 | |
92 | - while ($line = $sth->fetch()) { |
|
93 | - $out .= $this->opml_export_category($owner_uid, $line["id"], $hide_private_feeds, $include_settings); |
|
94 | - } |
|
92 | + while ($line = $sth->fetch()) { |
|
93 | + $out .= $this->opml_export_category($owner_uid, $line["id"], $hide_private_feeds, $include_settings); |
|
94 | + } |
|
95 | 95 | |
96 | - $fsth = $this->pdo->prepare("select title, feed_url, site_url, update_interval, order_id |
|
96 | + $fsth = $this->pdo->prepare("select title, feed_url, site_url, update_interval, order_id |
|
97 | 97 | FROM ttrss_feeds WHERE |
98 | 98 | (cat_id = :cat OR (:cat = 0 AND cat_id IS NULL)) AND owner_uid = :uid AND $hide_qpart |
99 | 99 | ORDER BY order_id, title"); |
100 | 100 | |
101 | - $fsth->execute([':cat' => $cat_id, ':uid' => $owner_uid]); |
|
101 | + $fsth->execute([':cat' => $cat_id, ':uid' => $owner_uid]); |
|
102 | 102 | |
103 | - while ($fline = $fsth->fetch()) { |
|
104 | - $title = htmlspecialchars($fline["title"]); |
|
105 | - $url = htmlspecialchars($fline["feed_url"]); |
|
106 | - $site_url = htmlspecialchars($fline["site_url"]); |
|
103 | + while ($fline = $fsth->fetch()) { |
|
104 | + $title = htmlspecialchars($fline["title"]); |
|
105 | + $url = htmlspecialchars($fline["feed_url"]); |
|
106 | + $site_url = htmlspecialchars($fline["site_url"]); |
|
107 | 107 | |
108 | - if ($include_settings) { |
|
109 | - $update_interval = (int) $fline["update_interval"]; |
|
110 | - $order_id = (int) $fline["order_id"]; |
|
108 | + if ($include_settings) { |
|
109 | + $update_interval = (int) $fline["update_interval"]; |
|
110 | + $order_id = (int) $fline["order_id"]; |
|
111 | 111 | |
112 | - $ttrss_specific_qpart = "ttrssSortOrder=\"$order_id\" ttrssUpdateInterval=\"$update_interval\""; |
|
113 | - } else { |
|
114 | - $ttrss_specific_qpart = ""; |
|
115 | - } |
|
112 | + $ttrss_specific_qpart = "ttrssSortOrder=\"$order_id\" ttrssUpdateInterval=\"$update_interval\""; |
|
113 | + } else { |
|
114 | + $ttrss_specific_qpart = ""; |
|
115 | + } |
|
116 | 116 | |
117 | - if ($site_url) { |
|
118 | - $html_url_qpart = "htmlUrl=\"$site_url\""; |
|
119 | - } else { |
|
120 | - $html_url_qpart = ""; |
|
121 | - } |
|
117 | + if ($site_url) { |
|
118 | + $html_url_qpart = "htmlUrl=\"$site_url\""; |
|
119 | + } else { |
|
120 | + $html_url_qpart = ""; |
|
121 | + } |
|
122 | 122 | |
123 | - $out .= "<outline type=\"rss\" text=\"$title\" xmlUrl=\"$url\" $ttrss_specific_qpart $html_url_qpart/>\n"; |
|
124 | - } |
|
123 | + $out .= "<outline type=\"rss\" text=\"$title\" xmlUrl=\"$url\" $ttrss_specific_qpart $html_url_qpart/>\n"; |
|
124 | + } |
|
125 | 125 | |
126 | - if ($cat_title) { |
|
127 | - $out .= "</outline>\n"; |
|
128 | - } |
|
126 | + if ($cat_title) { |
|
127 | + $out .= "</outline>\n"; |
|
128 | + } |
|
129 | 129 | |
130 | - return $out; |
|
131 | - } |
|
130 | + return $out; |
|
131 | + } |
|
132 | 132 | |
133 | - public function opml_export($name, $owner_uid, $hide_private_feeds = false, $include_settings = true) { |
|
134 | - if (!$owner_uid) { |
|
135 | - return; |
|
136 | - } |
|
133 | + public function opml_export($name, $owner_uid, $hide_private_feeds = false, $include_settings = true) { |
|
134 | + if (!$owner_uid) { |
|
135 | + return; |
|
136 | + } |
|
137 | 137 | |
138 | - if (!isset($_REQUEST["debug"])) { |
|
139 | - header("Content-type: application/xml+opml"); |
|
140 | - header("Content-Disposition: attachment; filename=".$name); |
|
141 | - } else { |
|
142 | - header("Content-type: text/xml"); |
|
143 | - } |
|
138 | + if (!isset($_REQUEST["debug"])) { |
|
139 | + header("Content-type: application/xml+opml"); |
|
140 | + header("Content-Disposition: attachment; filename=".$name); |
|
141 | + } else { |
|
142 | + header("Content-type: text/xml"); |
|
143 | + } |
|
144 | 144 | |
145 | - $out = "<?xml version=\"1.0\" encoding=\"utf-8\"?".">"; |
|
145 | + $out = "<?xml version=\"1.0\" encoding=\"utf-8\"?".">"; |
|
146 | 146 | |
147 | - $out .= "<opml version=\"1.0\">"; |
|
148 | - $out .= "<head> |
|
147 | + $out .= "<opml version=\"1.0\">"; |
|
148 | + $out .= "<head> |
|
149 | 149 | <dateCreated>" . date("r", time())."</dateCreated> |
150 | 150 | <title>Tiny Tiny RSS Feed Export</title> |
151 | 151 | </head>"; |
152 | - $out .= "<body>"; |
|
152 | + $out .= "<body>"; |
|
153 | 153 | |
154 | - $out .= $this->opml_export_category($owner_uid, 0, $hide_private_feeds, $include_settings); |
|
154 | + $out .= $this->opml_export_category($owner_uid, 0, $hide_private_feeds, $include_settings); |
|
155 | 155 | |
156 | - # export tt-rss settings |
|
156 | + # export tt-rss settings |
|
157 | 157 | |
158 | - if ($include_settings) { |
|
159 | - $out .= "<outline text=\"tt-rss-prefs\" schema-version=\"".SCHEMA_VERSION."\">"; |
|
158 | + if ($include_settings) { |
|
159 | + $out .= "<outline text=\"tt-rss-prefs\" schema-version=\"".SCHEMA_VERSION."\">"; |
|
160 | 160 | |
161 | - $sth = $this->pdo->prepare("SELECT pref_name, value FROM ttrss_user_prefs WHERE |
|
161 | + $sth = $this->pdo->prepare("SELECT pref_name, value FROM ttrss_user_prefs WHERE |
|
162 | 162 | profile IS NULL AND owner_uid = ? ORDER BY pref_name"); |
163 | - $sth->execute([$owner_uid]); |
|
163 | + $sth->execute([$owner_uid]); |
|
164 | 164 | |
165 | - while ($line = $sth->fetch()) { |
|
166 | - $name = $line["pref_name"]; |
|
167 | - $value = htmlspecialchars($line["value"]); |
|
165 | + while ($line = $sth->fetch()) { |
|
166 | + $name = $line["pref_name"]; |
|
167 | + $value = htmlspecialchars($line["value"]); |
|
168 | 168 | |
169 | - $out .= "<outline pref-name=\"$name\" value=\"$value\"/>"; |
|
170 | - } |
|
169 | + $out .= "<outline pref-name=\"$name\" value=\"$value\"/>"; |
|
170 | + } |
|
171 | 171 | |
172 | - $out .= "</outline>"; |
|
172 | + $out .= "</outline>"; |
|
173 | 173 | |
174 | - $out .= "<outline text=\"tt-rss-labels\" schema-version=\"".SCHEMA_VERSION."\">"; |
|
174 | + $out .= "<outline text=\"tt-rss-labels\" schema-version=\"".SCHEMA_VERSION."\">"; |
|
175 | 175 | |
176 | - $sth = $this->pdo->prepare("SELECT * FROM ttrss_labels2 WHERE |
|
176 | + $sth = $this->pdo->prepare("SELECT * FROM ttrss_labels2 WHERE |
|
177 | 177 | owner_uid = ?"); |
178 | - $sth->execute([$owner_uid]); |
|
178 | + $sth->execute([$owner_uid]); |
|
179 | 179 | |
180 | - while ($line = $sth->fetch()) { |
|
181 | - $name = htmlspecialchars($line['caption']); |
|
182 | - $fg_color = htmlspecialchars($line['fg_color']); |
|
183 | - $bg_color = htmlspecialchars($line['bg_color']); |
|
180 | + while ($line = $sth->fetch()) { |
|
181 | + $name = htmlspecialchars($line['caption']); |
|
182 | + $fg_color = htmlspecialchars($line['fg_color']); |
|
183 | + $bg_color = htmlspecialchars($line['bg_color']); |
|
184 | 184 | |
185 | - $out .= "<outline label-name=\"$name\" label-fg-color=\"$fg_color\" label-bg-color=\"$bg_color\"/>"; |
|
185 | + $out .= "<outline label-name=\"$name\" label-fg-color=\"$fg_color\" label-bg-color=\"$bg_color\"/>"; |
|
186 | 186 | |
187 | - } |
|
187 | + } |
|
188 | 188 | |
189 | - $out .= "</outline>"; |
|
189 | + $out .= "</outline>"; |
|
190 | 190 | |
191 | - $out .= "<outline text=\"tt-rss-filters\" schema-version=\"".SCHEMA_VERSION."\">"; |
|
191 | + $out .= "<outline text=\"tt-rss-filters\" schema-version=\"".SCHEMA_VERSION."\">"; |
|
192 | 192 | |
193 | - $sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2 |
|
193 | + $sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2 |
|
194 | 194 | WHERE owner_uid = ? ORDER BY id"); |
195 | - $sth->execute([$owner_uid]); |
|
195 | + $sth->execute([$owner_uid]); |
|
196 | 196 | |
197 | - while ($line = $sth->fetch()) { |
|
198 | - $line["rules"] = array(); |
|
199 | - $line["actions"] = array(); |
|
197 | + while ($line = $sth->fetch()) { |
|
198 | + $line["rules"] = array(); |
|
199 | + $line["actions"] = array(); |
|
200 | 200 | |
201 | - $tmph = $this->pdo->prepare("SELECT * FROM ttrss_filters2_rules |
|
201 | + $tmph = $this->pdo->prepare("SELECT * FROM ttrss_filters2_rules |
|
202 | 202 | WHERE filter_id = ?"); |
203 | - $tmph->execute([$line['id']]); |
|
203 | + $tmph->execute([$line['id']]); |
|
204 | 204 | |
205 | - while ($tmp_line = $tmph->fetch(PDO::FETCH_ASSOC)) { |
|
206 | - unset($tmp_line["id"]); |
|
207 | - unset($tmp_line["filter_id"]); |
|
205 | + while ($tmp_line = $tmph->fetch(PDO::FETCH_ASSOC)) { |
|
206 | + unset($tmp_line["id"]); |
|
207 | + unset($tmp_line["filter_id"]); |
|
208 | 208 | |
209 | - $cat_filter = $tmp_line["cat_filter"]; |
|
209 | + $cat_filter = $tmp_line["cat_filter"]; |
|
210 | 210 | |
211 | - if (!$tmp_line["match_on"]) { |
|
211 | + if (!$tmp_line["match_on"]) { |
|
212 | 212 | if ($cat_filter && $tmp_line["cat_id"] || $tmp_line["feed_id"]) { |
213 | 213 | $tmp_line["feed"] = Feeds::getFeedTitle( |
214 | 214 | $cat_filter ? $tmp_line["cat_id"] : $tmp_line["feed_id"], |
@@ -217,8 +217,8 @@ discard block |
||
217 | 217 | $tmp_line["feed"] = ""; |
218 | 218 | } |
219 | 219 | } else { |
220 | - $match = []; |
|
221 | - foreach (json_decode($tmp_line["match_on"], true) as $feed_id) { |
|
220 | + $match = []; |
|
221 | + foreach (json_decode($tmp_line["match_on"], true) as $feed_id) { |
|
222 | 222 | |
223 | 223 | if (strpos($feed_id, "CAT:") === 0) { |
224 | 224 | $feed_id = (int) substr($feed_id, 4); |
@@ -237,57 +237,57 @@ discard block |
||
237 | 237 | } |
238 | 238 | |
239 | 239 | $tmp_line["match"] = $match; |
240 | - unset($tmp_line["match_on"]); |
|
240 | + unset($tmp_line["match_on"]); |
|
241 | 241 | } |
242 | 242 | |
243 | - unset($tmp_line["feed_id"]); |
|
244 | - unset($tmp_line["cat_id"]); |
|
243 | + unset($tmp_line["feed_id"]); |
|
244 | + unset($tmp_line["cat_id"]); |
|
245 | 245 | |
246 | - array_push($line["rules"], $tmp_line); |
|
247 | - } |
|
246 | + array_push($line["rules"], $tmp_line); |
|
247 | + } |
|
248 | 248 | |
249 | - $tmph = $this->pdo->prepare("SELECT * FROM ttrss_filters2_actions |
|
249 | + $tmph = $this->pdo->prepare("SELECT * FROM ttrss_filters2_actions |
|
250 | 250 | WHERE filter_id = ?"); |
251 | - $tmph->execute([$line['id']]); |
|
251 | + $tmph->execute([$line['id']]); |
|
252 | 252 | |
253 | - while ($tmp_line = $tmph->fetch(PDO::FETCH_ASSOC)) { |
|
254 | - unset($tmp_line["id"]); |
|
255 | - unset($tmp_line["filter_id"]); |
|
253 | + while ($tmp_line = $tmph->fetch(PDO::FETCH_ASSOC)) { |
|
254 | + unset($tmp_line["id"]); |
|
255 | + unset($tmp_line["filter_id"]); |
|
256 | 256 | |
257 | - array_push($line["actions"], $tmp_line); |
|
258 | - } |
|
257 | + array_push($line["actions"], $tmp_line); |
|
258 | + } |
|
259 | 259 | |
260 | - unset($line["id"]); |
|
261 | - unset($line["owner_uid"]); |
|
262 | - $filter = json_encode($line); |
|
260 | + unset($line["id"]); |
|
261 | + unset($line["owner_uid"]); |
|
262 | + $filter = json_encode($line); |
|
263 | 263 | |
264 | - $out .= "<outline filter-type=\"2\"><![CDATA[$filter]]></outline>"; |
|
264 | + $out .= "<outline filter-type=\"2\"><![CDATA[$filter]]></outline>"; |
|
265 | 265 | |
266 | - } |
|
266 | + } |
|
267 | 267 | |
268 | 268 | |
269 | - $out .= "</outline>"; |
|
270 | - } |
|
269 | + $out .= "</outline>"; |
|
270 | + } |
|
271 | 271 | |
272 | - $out .= "</body></opml>"; |
|
272 | + $out .= "</body></opml>"; |
|
273 | 273 | |
274 | - // Format output. |
|
275 | - $doc = new DOMDocument(); |
|
276 | - $doc->formatOutput = true; |
|
277 | - $doc->preserveWhiteSpace = false; |
|
278 | - $doc->loadXML($out); |
|
274 | + // Format output. |
|
275 | + $doc = new DOMDocument(); |
|
276 | + $doc->formatOutput = true; |
|
277 | + $doc->preserveWhiteSpace = false; |
|
278 | + $doc->loadXML($out); |
|
279 | 279 | |
280 | - $xpath = new DOMXpath($doc); |
|
281 | - $outlines = $xpath->query("//outline[@title]"); |
|
280 | + $xpath = new DOMXpath($doc); |
|
281 | + $outlines = $xpath->query("//outline[@title]"); |
|
282 | 282 | |
283 | - // cleanup empty categories |
|
284 | - foreach ($outlines as $node) { |
|
285 | - if ($node->getElementsByTagName('outline')->length == 0) { |
|
286 | - $node->parentNode->removeChild($node); |
|
287 | - } |
|
288 | - } |
|
283 | + // cleanup empty categories |
|
284 | + foreach ($outlines as $node) { |
|
285 | + if ($node->getElementsByTagName('outline')->length == 0) { |
|
286 | + $node->parentNode->removeChild($node); |
|
287 | + } |
|
288 | + } |
|
289 | 289 | |
290 | - $res = $doc->saveXML(); |
|
290 | + $res = $doc->saveXML(); |
|
291 | 291 | |
292 | 292 | /* // saveXML uses a two-space indent. Change to tabs. |
293 | 293 | $res = preg_replace_callback('/^(?: )+/mu', |
@@ -296,140 +296,140 @@ discard block |
||
296 | 296 | 'return str_repeat("\t", intval(strlen($matches[0])/2));'), |
297 | 297 | $res); */ |
298 | 298 | |
299 | - print $res; |
|
300 | - } |
|
299 | + print $res; |
|
300 | + } |
|
301 | 301 | |
302 | - // Import |
|
302 | + // Import |
|
303 | 303 | |
304 | - private function opml_import_feed($node, $cat_id, $owner_uid) { |
|
305 | - $attrs = $node->attributes; |
|
304 | + private function opml_import_feed($node, $cat_id, $owner_uid) { |
|
305 | + $attrs = $node->attributes; |
|
306 | 306 | |
307 | - $feed_title = mb_substr($attrs->getNamedItem('text')->nodeValue, 0, 250); |
|
308 | - if (!$feed_title) { |
|
309 | - $feed_title = mb_substr($attrs->getNamedItem('title')->nodeValue, 0, 250); |
|
310 | - } |
|
307 | + $feed_title = mb_substr($attrs->getNamedItem('text')->nodeValue, 0, 250); |
|
308 | + if (!$feed_title) { |
|
309 | + $feed_title = mb_substr($attrs->getNamedItem('title')->nodeValue, 0, 250); |
|
310 | + } |
|
311 | 311 | |
312 | - $feed_url = $attrs->getNamedItem('xmlUrl')->nodeValue; |
|
313 | - if (!$feed_url) { |
|
314 | - $feed_url = $attrs->getNamedItem('xmlURL')->nodeValue; |
|
315 | - } |
|
312 | + $feed_url = $attrs->getNamedItem('xmlUrl')->nodeValue; |
|
313 | + if (!$feed_url) { |
|
314 | + $feed_url = $attrs->getNamedItem('xmlURL')->nodeValue; |
|
315 | + } |
|
316 | 316 | |
317 | - $site_url = mb_substr($attrs->getNamedItem('htmlUrl')->nodeValue, 0, 250); |
|
317 | + $site_url = mb_substr($attrs->getNamedItem('htmlUrl')->nodeValue, 0, 250); |
|
318 | 318 | |
319 | - if ($feed_url) { |
|
320 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
319 | + if ($feed_url) { |
|
320 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
321 | 321 | feed_url = ? AND owner_uid = ?"); |
322 | - $sth->execute([$feed_url, $owner_uid]); |
|
322 | + $sth->execute([$feed_url, $owner_uid]); |
|
323 | 323 | |
324 | - if (!$feed_title) { |
|
325 | - $feed_title = '[Unknown]'; |
|
326 | - } |
|
324 | + if (!$feed_title) { |
|
325 | + $feed_title = '[Unknown]'; |
|
326 | + } |
|
327 | 327 | |
328 | - if (!$sth->fetch()) { |
|
329 | - #$this->opml_notice("[FEED] [$feed_title/$feed_url] dst_CAT=$cat_id"); |
|
330 | - $this->opml_notice(T_sprintf("Adding feed: %s", $feed_title == '[Unknown]' ? $feed_url : $feed_title)); |
|
328 | + if (!$sth->fetch()) { |
|
329 | + #$this->opml_notice("[FEED] [$feed_title/$feed_url] dst_CAT=$cat_id"); |
|
330 | + $this->opml_notice(T_sprintf("Adding feed: %s", $feed_title == '[Unknown]' ? $feed_url : $feed_title)); |
|
331 | 331 | |
332 | - if (!$cat_id) { |
|
333 | - $cat_id = null; |
|
334 | - } |
|
332 | + if (!$cat_id) { |
|
333 | + $cat_id = null; |
|
334 | + } |
|
335 | 335 | |
336 | - $update_interval = (int) $attrs->getNamedItem('ttrssUpdateInterval')->nodeValue; |
|
337 | - if (!$update_interval) { |
|
338 | - $update_interval = 0; |
|
339 | - } |
|
336 | + $update_interval = (int) $attrs->getNamedItem('ttrssUpdateInterval')->nodeValue; |
|
337 | + if (!$update_interval) { |
|
338 | + $update_interval = 0; |
|
339 | + } |
|
340 | 340 | |
341 | - $order_id = (int) $attrs->getNamedItem('ttrssSortOrder')->nodeValue; |
|
342 | - if (!$order_id) { |
|
343 | - $order_id = 0; |
|
344 | - } |
|
341 | + $order_id = (int) $attrs->getNamedItem('ttrssSortOrder')->nodeValue; |
|
342 | + if (!$order_id) { |
|
343 | + $order_id = 0; |
|
344 | + } |
|
345 | 345 | |
346 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
346 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
347 | 347 | (title, feed_url, owner_uid, cat_id, site_url, order_id, update_interval) VALUES |
348 | 348 | (?, ?, ?, ?, ?, ?, ?)"); |
349 | 349 | |
350 | - $sth->execute([$feed_title, $feed_url, $owner_uid, $cat_id, $site_url, $order_id, $update_interval]); |
|
350 | + $sth->execute([$feed_title, $feed_url, $owner_uid, $cat_id, $site_url, $order_id, $update_interval]); |
|
351 | 351 | |
352 | - } else { |
|
353 | - $this->opml_notice(T_sprintf("Duplicate feed: %s", $feed_title == '[Unknown]' ? $feed_url : $feed_title)); |
|
354 | - } |
|
355 | - } |
|
356 | - } |
|
352 | + } else { |
|
353 | + $this->opml_notice(T_sprintf("Duplicate feed: %s", $feed_title == '[Unknown]' ? $feed_url : $feed_title)); |
|
354 | + } |
|
355 | + } |
|
356 | + } |
|
357 | 357 | |
358 | - private function opml_import_label($node, $owner_uid) { |
|
359 | - $attrs = $node->attributes; |
|
360 | - $label_name = $attrs->getNamedItem('label-name')->nodeValue; |
|
358 | + private function opml_import_label($node, $owner_uid) { |
|
359 | + $attrs = $node->attributes; |
|
360 | + $label_name = $attrs->getNamedItem('label-name')->nodeValue; |
|
361 | 361 | |
362 | - if ($label_name) { |
|
363 | - $fg_color = $attrs->getNamedItem('label-fg-color')->nodeValue; |
|
364 | - $bg_color = $attrs->getNamedItem('label-bg-color')->nodeValue; |
|
362 | + if ($label_name) { |
|
363 | + $fg_color = $attrs->getNamedItem('label-fg-color')->nodeValue; |
|
364 | + $bg_color = $attrs->getNamedItem('label-bg-color')->nodeValue; |
|
365 | 365 | |
366 | - if (!Labels::find_id($label_name, $_SESSION['uid'])) { |
|
367 | - $this->opml_notice(T_sprintf("Adding label %s", htmlspecialchars($label_name))); |
|
368 | - Labels::create($label_name, $fg_color, $bg_color, $owner_uid); |
|
369 | - } else { |
|
370 | - $this->opml_notice(T_sprintf("Duplicate label: %s", htmlspecialchars($label_name))); |
|
371 | - } |
|
372 | - } |
|
373 | - } |
|
366 | + if (!Labels::find_id($label_name, $_SESSION['uid'])) { |
|
367 | + $this->opml_notice(T_sprintf("Adding label %s", htmlspecialchars($label_name))); |
|
368 | + Labels::create($label_name, $fg_color, $bg_color, $owner_uid); |
|
369 | + } else { |
|
370 | + $this->opml_notice(T_sprintf("Duplicate label: %s", htmlspecialchars($label_name))); |
|
371 | + } |
|
372 | + } |
|
373 | + } |
|
374 | 374 | |
375 | - private function opml_import_preference($node) { |
|
376 | - $attrs = $node->attributes; |
|
377 | - $pref_name = $attrs->getNamedItem('pref-name')->nodeValue; |
|
375 | + private function opml_import_preference($node) { |
|
376 | + $attrs = $node->attributes; |
|
377 | + $pref_name = $attrs->getNamedItem('pref-name')->nodeValue; |
|
378 | 378 | |
379 | - if ($pref_name) { |
|
380 | - $pref_value = $attrs->getNamedItem('value')->nodeValue; |
|
379 | + if ($pref_name) { |
|
380 | + $pref_value = $attrs->getNamedItem('value')->nodeValue; |
|
381 | 381 | |
382 | - $this->opml_notice(T_sprintf("Setting preference key %s to %s", |
|
383 | - $pref_name, $pref_value)); |
|
382 | + $this->opml_notice(T_sprintf("Setting preference key %s to %s", |
|
383 | + $pref_name, $pref_value)); |
|
384 | 384 | |
385 | - set_pref($pref_name, $pref_value); |
|
386 | - } |
|
387 | - } |
|
385 | + set_pref($pref_name, $pref_value); |
|
386 | + } |
|
387 | + } |
|
388 | 388 | |
389 | - private function opml_import_filter($node) { |
|
390 | - $attrs = $node->attributes; |
|
389 | + private function opml_import_filter($node) { |
|
390 | + $attrs = $node->attributes; |
|
391 | 391 | |
392 | - $filter_type = $attrs->getNamedItem('filter-type')->nodeValue; |
|
392 | + $filter_type = $attrs->getNamedItem('filter-type')->nodeValue; |
|
393 | 393 | |
394 | - if ($filter_type == '2') { |
|
395 | - $filter = json_decode($node->nodeValue, true); |
|
394 | + if ($filter_type == '2') { |
|
395 | + $filter = json_decode($node->nodeValue, true); |
|
396 | 396 | |
397 | - if ($filter) { |
|
398 | - $match_any_rule = bool_to_sql_bool($filter["match_any_rule"]); |
|
399 | - $enabled = bool_to_sql_bool($filter["enabled"]); |
|
400 | - $inverse = bool_to_sql_bool($filter["inverse"]); |
|
401 | - $title = $filter["title"]; |
|
397 | + if ($filter) { |
|
398 | + $match_any_rule = bool_to_sql_bool($filter["match_any_rule"]); |
|
399 | + $enabled = bool_to_sql_bool($filter["enabled"]); |
|
400 | + $inverse = bool_to_sql_bool($filter["inverse"]); |
|
401 | + $title = $filter["title"]; |
|
402 | 402 | |
403 | - //print "F: $title, $inverse, $enabled, $match_any_rule"; |
|
403 | + //print "F: $title, $inverse, $enabled, $match_any_rule"; |
|
404 | 404 | |
405 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_filters2 (match_any_rule,enabled,inverse,title,owner_uid) |
|
405 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_filters2 (match_any_rule,enabled,inverse,title,owner_uid) |
|
406 | 406 | VALUES (?, ?, ?, ?, ?)"); |
407 | 407 | |
408 | - $sth->execute([$match_any_rule, $enabled, $inverse, $title, $_SESSION['uid']]); |
|
408 | + $sth->execute([$match_any_rule, $enabled, $inverse, $title, $_SESSION['uid']]); |
|
409 | 409 | |
410 | - $sth = $this->pdo->prepare("SELECT MAX(id) AS id FROM ttrss_filters2 WHERE |
|
410 | + $sth = $this->pdo->prepare("SELECT MAX(id) AS id FROM ttrss_filters2 WHERE |
|
411 | 411 | owner_uid = ?"); |
412 | - $sth->execute([$_SESSION['uid']]); |
|
412 | + $sth->execute([$_SESSION['uid']]); |
|
413 | 413 | |
414 | - $row = $sth->fetch(); |
|
415 | - $filter_id = $row['id']; |
|
414 | + $row = $sth->fetch(); |
|
415 | + $filter_id = $row['id']; |
|
416 | 416 | |
417 | - if ($filter_id) { |
|
418 | - $this->opml_notice(T_sprintf("Adding filter %s...", $title)); |
|
417 | + if ($filter_id) { |
|
418 | + $this->opml_notice(T_sprintf("Adding filter %s...", $title)); |
|
419 | 419 | |
420 | - foreach ($filter["rules"] as $rule) { |
|
421 | - $feed_id = null; |
|
422 | - $cat_id = null; |
|
420 | + foreach ($filter["rules"] as $rule) { |
|
421 | + $feed_id = null; |
|
422 | + $cat_id = null; |
|
423 | 423 | |
424 | - if ($rule["match"]) { |
|
424 | + if ($rule["match"]) { |
|
425 | 425 | |
426 | 426 | $match_on = []; |
427 | 427 | |
428 | - foreach ($rule["match"] as $match) { |
|
429 | - list ($name, $is_cat, $is_id) = $match; |
|
428 | + foreach ($rule["match"] as $match) { |
|
429 | + list ($name, $is_cat, $is_id) = $match; |
|
430 | 430 | |
431 | - if ($is_id) { |
|
432 | - array_push($match_on, ($is_cat ? "CAT:" : "").$name); |
|
431 | + if ($is_id) { |
|
432 | + array_push($match_on, ($is_cat ? "CAT:" : "").$name); |
|
433 | 433 | } else { |
434 | 434 | |
435 | 435 | if (!$is_cat) { |
@@ -441,18 +441,18 @@ discard block |
||
441 | 441 | if ($row = $tsth->fetch()) { |
442 | 442 | $match_id = $row['id']; |
443 | 443 | |
444 | - array_push($match_on, $match_id); |
|
444 | + array_push($match_on, $match_id); |
|
445 | 445 | } |
446 | 446 | } else { |
447 | 447 | $tsth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories |
448 | 448 | WHERE title = ? AND owner_uid = ?"); |
449 | - $tsth->execute([$name, $_SESSION['uid']]); |
|
449 | + $tsth->execute([$name, $_SESSION['uid']]); |
|
450 | 450 | |
451 | - if ($row = $tsth->fetch()) { |
|
452 | - $match_id = $row['id']; |
|
451 | + if ($row = $tsth->fetch()) { |
|
452 | + $match_id = $row['id']; |
|
453 | 453 | |
454 | - array_push($match_on, "CAT:$match_id"); |
|
455 | - } |
|
454 | + array_push($match_on, "CAT:$match_id"); |
|
455 | + } |
|
456 | 456 | } |
457 | 457 | } |
458 | 458 | } |
@@ -480,14 +480,14 @@ discard block |
||
480 | 480 | $feed_id = $row['id']; |
481 | 481 | } |
482 | 482 | } else { |
483 | - $tsth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories |
|
483 | + $tsth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories |
|
484 | 484 | WHERE title = ? AND owner_uid = ?"); |
485 | 485 | |
486 | - $tsth->execute([$rule['feed'], $_SESSION['uid']]); |
|
486 | + $tsth->execute([$rule['feed'], $_SESSION['uid']]); |
|
487 | 487 | |
488 | - if ($row = $tsth->fetch()) { |
|
489 | - $feed_id = $row['id']; |
|
490 | - } |
|
488 | + if ($row = $tsth->fetch()) { |
|
489 | + $feed_id = $row['id']; |
|
490 | + } |
|
491 | 491 | } |
492 | 492 | |
493 | 493 | $cat_filter = bool_to_sql_bool($rule["cat_filter"]); |
@@ -501,180 +501,180 @@ discard block |
||
501 | 501 | (?, ?, ?, ?, ?, ?, ?)"); |
502 | 502 | $usth->execute([$feed_id, $cat_id, $filter_id, $filter_type, $reg_exp, $cat_filter, $inverse]); |
503 | 503 | } |
504 | - } |
|
504 | + } |
|
505 | 505 | |
506 | - foreach ($filter["actions"] as $action) { |
|
506 | + foreach ($filter["actions"] as $action) { |
|
507 | 507 | |
508 | - $action_id = (int) $action["action_id"]; |
|
509 | - $action_param = $action["action_param"]; |
|
508 | + $action_id = (int) $action["action_id"]; |
|
509 | + $action_param = $action["action_param"]; |
|
510 | 510 | |
511 | - $usth = $this->pdo->prepare("INSERT INTO ttrss_filters2_actions |
|
511 | + $usth = $this->pdo->prepare("INSERT INTO ttrss_filters2_actions |
|
512 | 512 | (filter_id,action_id,action_param) |
513 | 513 | VALUES |
514 | 514 | (?, ?, ?)"); |
515 | - $usth->execute([$filter_id, $action_id, $action_param]); |
|
516 | - } |
|
517 | - } |
|
518 | - } |
|
519 | - } |
|
520 | - } |
|
521 | - |
|
522 | - private function opml_import_category($doc, $root_node, $owner_uid, $parent_id) { |
|
523 | - $default_cat_id = (int) $this->get_feed_category('Imported feeds', false); |
|
524 | - |
|
525 | - if ($root_node) { |
|
526 | - $cat_title = mb_substr($root_node->attributes->getNamedItem('text')->nodeValue, 0, 250); |
|
527 | - |
|
528 | - if (!$cat_title) { |
|
529 | - $cat_title = mb_substr($root_node->attributes->getNamedItem('title')->nodeValue, 0, 250); |
|
530 | - } |
|
531 | - |
|
532 | - if (!in_array($cat_title, array("tt-rss-filters", "tt-rss-labels", "tt-rss-prefs"))) { |
|
533 | - $cat_id = $this->get_feed_category($cat_title, $parent_id); |
|
534 | - |
|
535 | - if ($cat_id === false) { |
|
536 | - $order_id = (int) $root_node->attributes->getNamedItem('ttrssSortOrder')->nodeValue; |
|
537 | - if (!$order_id) { |
|
538 | - $order_id = 0; |
|
539 | - } |
|
540 | - |
|
541 | - Feeds::add_feed_category($cat_title, $parent_id, $order_id); |
|
542 | - $cat_id = $this->get_feed_category($cat_title, $parent_id); |
|
543 | - } |
|
544 | - |
|
545 | - } else { |
|
546 | - $cat_id = 0; |
|
547 | - } |
|
548 | - |
|
549 | - $outlines = $root_node->childNodes; |
|
550 | - |
|
551 | - } else { |
|
552 | - $xpath = new DOMXpath($doc); |
|
553 | - $outlines = $xpath->query("//opml/body/outline"); |
|
554 | - |
|
555 | - $cat_id = 0; |
|
556 | - } |
|
557 | - |
|
558 | - #$this->opml_notice("[CAT] $cat_title id: $cat_id P_id: $parent_id"); |
|
559 | - $this->opml_notice(T_sprintf("Processing category: %s", $cat_title ? $cat_title : __("Uncategorized"))); |
|
560 | - |
|
561 | - foreach ($outlines as $node) { |
|
562 | - if ($node->hasAttributes() && strtolower($node->tagName) == "outline") { |
|
563 | - $attrs = $node->attributes; |
|
564 | - $node_cat_title = $attrs->getNamedItem('text')->nodeValue; |
|
565 | - |
|
566 | - if (!$node_cat_title) { |
|
567 | - $node_cat_title = $attrs->getNamedItem('title')->nodeValue; |
|
568 | - } |
|
569 | - |
|
570 | - $node_feed_url = $attrs->getNamedItem('xmlUrl')->nodeValue; |
|
571 | - |
|
572 | - if ($node_cat_title && !$node_feed_url) { |
|
573 | - $this->opml_import_category($doc, $node, $owner_uid, $cat_id); |
|
574 | - } else { |
|
575 | - |
|
576 | - if (!$cat_id) { |
|
577 | - $dst_cat_id = $default_cat_id; |
|
578 | - } else { |
|
579 | - $dst_cat_id = $cat_id; |
|
580 | - } |
|
581 | - |
|
582 | - switch ($cat_title) { |
|
583 | - case "tt-rss-prefs": |
|
584 | - $this->opml_import_preference($node); |
|
585 | - break; |
|
586 | - case "tt-rss-labels": |
|
587 | - $this->opml_import_label($node, $owner_uid); |
|
588 | - break; |
|
589 | - case "tt-rss-filters": |
|
590 | - $this->opml_import_filter($node); |
|
591 | - break; |
|
592 | - default: |
|
593 | - $this->opml_import_feed($node, $dst_cat_id, $owner_uid); |
|
594 | - } |
|
595 | - } |
|
596 | - } |
|
597 | - } |
|
598 | - } |
|
599 | - |
|
600 | - public function opml_import($owner_uid) { |
|
601 | - if (!$owner_uid) { |
|
602 | - return; |
|
603 | - } |
|
604 | - |
|
605 | - $doc = false; |
|
606 | - |
|
607 | - if ($_FILES['opml_file']['error'] != 0) { |
|
608 | - print_error(T_sprintf("Upload failed with error code %d", |
|
609 | - $_FILES['opml_file']['error'])); |
|
610 | - return; |
|
611 | - } |
|
612 | - |
|
613 | - if (is_uploaded_file($_FILES['opml_file']['tmp_name'])) { |
|
614 | - $tmp_file = tempnam(CACHE_DIR.'/upload', 'opml'); |
|
615 | - |
|
616 | - $result = move_uploaded_file($_FILES['opml_file']['tmp_name'], |
|
617 | - $tmp_file); |
|
618 | - |
|
619 | - if (!$result) { |
|
620 | - print_error(__("Unable to move uploaded file.")); |
|
621 | - return; |
|
622 | - } |
|
623 | - } else { |
|
624 | - print_error(__('Error: please upload OPML file.')); |
|
625 | - return; |
|
626 | - } |
|
627 | - |
|
628 | - if (is_file($tmp_file)) { |
|
629 | - $doc = new DOMDocument(); |
|
630 | - libxml_disable_entity_loader(false); |
|
631 | - $doc->load($tmp_file); |
|
632 | - libxml_disable_entity_loader(true); |
|
633 | - unlink($tmp_file); |
|
634 | - } else if (!$doc) { |
|
635 | - print_error(__('Error: unable to find moved OPML file.')); |
|
636 | - return; |
|
637 | - } |
|
638 | - |
|
639 | - if ($doc) { |
|
640 | - $this->pdo->beginTransaction(); |
|
641 | - $this->opml_import_category($doc, false, $owner_uid, false); |
|
642 | - $this->pdo->commit(); |
|
643 | - } else { |
|
644 | - print_error(__('Error while parsing document.')); |
|
645 | - } |
|
646 | - } |
|
647 | - |
|
648 | - private function opml_notice($msg) { |
|
649 | - print "$msg<br/>"; |
|
650 | - } |
|
651 | - |
|
652 | - public static function opml_publish_url() { |
|
653 | - |
|
654 | - $url_path = get_self_url_prefix(); |
|
655 | - $url_path .= "/opml.php?op=publish&key=". |
|
656 | - Feeds::get_feed_access_key('OPML:Publish', false, $_SESSION["uid"]); |
|
657 | - |
|
658 | - return $url_path; |
|
659 | - } |
|
660 | - |
|
661 | - public function get_feed_category($feed_cat, $parent_cat_id = false) { |
|
662 | - |
|
663 | - $parent_cat_id = (int) $parent_cat_id; |
|
664 | - |
|
665 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories |
|
515 | + $usth->execute([$filter_id, $action_id, $action_param]); |
|
516 | + } |
|
517 | + } |
|
518 | + } |
|
519 | + } |
|
520 | + } |
|
521 | + |
|
522 | + private function opml_import_category($doc, $root_node, $owner_uid, $parent_id) { |
|
523 | + $default_cat_id = (int) $this->get_feed_category('Imported feeds', false); |
|
524 | + |
|
525 | + if ($root_node) { |
|
526 | + $cat_title = mb_substr($root_node->attributes->getNamedItem('text')->nodeValue, 0, 250); |
|
527 | + |
|
528 | + if (!$cat_title) { |
|
529 | + $cat_title = mb_substr($root_node->attributes->getNamedItem('title')->nodeValue, 0, 250); |
|
530 | + } |
|
531 | + |
|
532 | + if (!in_array($cat_title, array("tt-rss-filters", "tt-rss-labels", "tt-rss-prefs"))) { |
|
533 | + $cat_id = $this->get_feed_category($cat_title, $parent_id); |
|
534 | + |
|
535 | + if ($cat_id === false) { |
|
536 | + $order_id = (int) $root_node->attributes->getNamedItem('ttrssSortOrder')->nodeValue; |
|
537 | + if (!$order_id) { |
|
538 | + $order_id = 0; |
|
539 | + } |
|
540 | + |
|
541 | + Feeds::add_feed_category($cat_title, $parent_id, $order_id); |
|
542 | + $cat_id = $this->get_feed_category($cat_title, $parent_id); |
|
543 | + } |
|
544 | + |
|
545 | + } else { |
|
546 | + $cat_id = 0; |
|
547 | + } |
|
548 | + |
|
549 | + $outlines = $root_node->childNodes; |
|
550 | + |
|
551 | + } else { |
|
552 | + $xpath = new DOMXpath($doc); |
|
553 | + $outlines = $xpath->query("//opml/body/outline"); |
|
554 | + |
|
555 | + $cat_id = 0; |
|
556 | + } |
|
557 | + |
|
558 | + #$this->opml_notice("[CAT] $cat_title id: $cat_id P_id: $parent_id"); |
|
559 | + $this->opml_notice(T_sprintf("Processing category: %s", $cat_title ? $cat_title : __("Uncategorized"))); |
|
560 | + |
|
561 | + foreach ($outlines as $node) { |
|
562 | + if ($node->hasAttributes() && strtolower($node->tagName) == "outline") { |
|
563 | + $attrs = $node->attributes; |
|
564 | + $node_cat_title = $attrs->getNamedItem('text')->nodeValue; |
|
565 | + |
|
566 | + if (!$node_cat_title) { |
|
567 | + $node_cat_title = $attrs->getNamedItem('title')->nodeValue; |
|
568 | + } |
|
569 | + |
|
570 | + $node_feed_url = $attrs->getNamedItem('xmlUrl')->nodeValue; |
|
571 | + |
|
572 | + if ($node_cat_title && !$node_feed_url) { |
|
573 | + $this->opml_import_category($doc, $node, $owner_uid, $cat_id); |
|
574 | + } else { |
|
575 | + |
|
576 | + if (!$cat_id) { |
|
577 | + $dst_cat_id = $default_cat_id; |
|
578 | + } else { |
|
579 | + $dst_cat_id = $cat_id; |
|
580 | + } |
|
581 | + |
|
582 | + switch ($cat_title) { |
|
583 | + case "tt-rss-prefs": |
|
584 | + $this->opml_import_preference($node); |
|
585 | + break; |
|
586 | + case "tt-rss-labels": |
|
587 | + $this->opml_import_label($node, $owner_uid); |
|
588 | + break; |
|
589 | + case "tt-rss-filters": |
|
590 | + $this->opml_import_filter($node); |
|
591 | + break; |
|
592 | + default: |
|
593 | + $this->opml_import_feed($node, $dst_cat_id, $owner_uid); |
|
594 | + } |
|
595 | + } |
|
596 | + } |
|
597 | + } |
|
598 | + } |
|
599 | + |
|
600 | + public function opml_import($owner_uid) { |
|
601 | + if (!$owner_uid) { |
|
602 | + return; |
|
603 | + } |
|
604 | + |
|
605 | + $doc = false; |
|
606 | + |
|
607 | + if ($_FILES['opml_file']['error'] != 0) { |
|
608 | + print_error(T_sprintf("Upload failed with error code %d", |
|
609 | + $_FILES['opml_file']['error'])); |
|
610 | + return; |
|
611 | + } |
|
612 | + |
|
613 | + if (is_uploaded_file($_FILES['opml_file']['tmp_name'])) { |
|
614 | + $tmp_file = tempnam(CACHE_DIR.'/upload', 'opml'); |
|
615 | + |
|
616 | + $result = move_uploaded_file($_FILES['opml_file']['tmp_name'], |
|
617 | + $tmp_file); |
|
618 | + |
|
619 | + if (!$result) { |
|
620 | + print_error(__("Unable to move uploaded file.")); |
|
621 | + return; |
|
622 | + } |
|
623 | + } else { |
|
624 | + print_error(__('Error: please upload OPML file.')); |
|
625 | + return; |
|
626 | + } |
|
627 | + |
|
628 | + if (is_file($tmp_file)) { |
|
629 | + $doc = new DOMDocument(); |
|
630 | + libxml_disable_entity_loader(false); |
|
631 | + $doc->load($tmp_file); |
|
632 | + libxml_disable_entity_loader(true); |
|
633 | + unlink($tmp_file); |
|
634 | + } else if (!$doc) { |
|
635 | + print_error(__('Error: unable to find moved OPML file.')); |
|
636 | + return; |
|
637 | + } |
|
638 | + |
|
639 | + if ($doc) { |
|
640 | + $this->pdo->beginTransaction(); |
|
641 | + $this->opml_import_category($doc, false, $owner_uid, false); |
|
642 | + $this->pdo->commit(); |
|
643 | + } else { |
|
644 | + print_error(__('Error while parsing document.')); |
|
645 | + } |
|
646 | + } |
|
647 | + |
|
648 | + private function opml_notice($msg) { |
|
649 | + print "$msg<br/>"; |
|
650 | + } |
|
651 | + |
|
652 | + public static function opml_publish_url() { |
|
653 | + |
|
654 | + $url_path = get_self_url_prefix(); |
|
655 | + $url_path .= "/opml.php?op=publish&key=". |
|
656 | + Feeds::get_feed_access_key('OPML:Publish', false, $_SESSION["uid"]); |
|
657 | + |
|
658 | + return $url_path; |
|
659 | + } |
|
660 | + |
|
661 | + public function get_feed_category($feed_cat, $parent_cat_id = false) { |
|
662 | + |
|
663 | + $parent_cat_id = (int) $parent_cat_id; |
|
664 | + |
|
665 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories |
|
666 | 666 | WHERE title = :title |
667 | 667 | AND (parent_cat = :parent OR (:parent = 0 AND parent_cat IS NULL)) |
668 | 668 | AND owner_uid = :uid"); |
669 | 669 | |
670 | - $sth->execute([':title' => $feed_cat, ':parent' => $parent_cat_id, ':uid' => $_SESSION['uid']]); |
|
670 | + $sth->execute([':title' => $feed_cat, ':parent' => $parent_cat_id, ':uid' => $_SESSION['uid']]); |
|
671 | 671 | |
672 | - if ($row = $sth->fetch()) { |
|
673 | - return $row['id']; |
|
674 | - } else { |
|
675 | - return false; |
|
676 | - } |
|
677 | - } |
|
672 | + if ($row = $sth->fetch()) { |
|
673 | + return $row['id']; |
|
674 | + } else { |
|
675 | + return false; |
|
676 | + } |
|
677 | + } |
|
678 | 678 | |
679 | 679 | |
680 | 680 | } |
@@ -1,243 +1,243 @@ |
||
1 | 1 | <?php |
2 | 2 | class FeedParser { |
3 | - private $doc; |
|
4 | - private $error; |
|
5 | - private $libxml_errors = array(); |
|
6 | - private $items; |
|
7 | - private $link; |
|
8 | - private $title; |
|
9 | - private $type; |
|
10 | - private $xpath; |
|
11 | - |
|
12 | - const FEED_RDF = 0; |
|
13 | - const FEED_RSS = 1; |
|
14 | - const FEED_ATOM = 2; |
|
15 | - |
|
16 | - public function __construct($data) { |
|
17 | - libxml_use_internal_errors(true); |
|
18 | - libxml_clear_errors(); |
|
19 | - $this->doc = new DOMDocument(); |
|
20 | - $this->doc->loadXML($data); |
|
21 | - |
|
22 | - mb_substitute_character("none"); |
|
23 | - |
|
24 | - $error = libxml_get_last_error(); |
|
25 | - |
|
26 | - if ($error) { |
|
27 | - foreach (libxml_get_errors() as $error) { |
|
28 | - if ($error->level == LIBXML_ERR_FATAL) { |
|
29 | - if (!isset($this->error)) //currently only the first error is reported |
|
30 | - $this->error = $this->format_error($error); |
|
31 | - $this->libxml_errors [] = $this->format_error($error); |
|
32 | - } |
|
33 | - } |
|
34 | - } |
|
35 | - libxml_clear_errors(); |
|
36 | - |
|
37 | - $this->items = array(); |
|
38 | - } |
|
39 | - |
|
40 | - public function init() { |
|
41 | - $xpath = new DOMXPath($this->doc); |
|
42 | - $xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom'); |
|
43 | - $xpath->registerNamespace('atom03', 'http://purl.org/atom/ns#'); |
|
44 | - $xpath->registerNamespace('media', 'http://search.yahoo.com/mrss/'); |
|
45 | - $xpath->registerNamespace('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'); |
|
46 | - $xpath->registerNamespace('slash', 'http://purl.org/rss/1.0/modules/slash/'); |
|
47 | - $xpath->registerNamespace('dc', 'http://purl.org/dc/elements/1.1/'); |
|
48 | - $xpath->registerNamespace('content', 'http://purl.org/rss/1.0/modules/content/'); |
|
49 | - $xpath->registerNamespace('thread', 'http://purl.org/syndication/thread/1.0'); |
|
50 | - |
|
51 | - $this->xpath = $xpath; |
|
52 | - |
|
53 | - $root = $xpath->query("(//atom03:feed|//atom:feed|//channel|//rdf:rdf|//rdf:RDF)"); |
|
54 | - |
|
55 | - if ($root && $root->length > 0) { |
|
56 | - $root = $root->item(0); |
|
57 | - |
|
58 | - if ($root) { |
|
59 | - switch (mb_strtolower($root->tagName)) { |
|
60 | - case "rdf:rdf": |
|
61 | - $this->type = $this::FEED_RDF; |
|
62 | - break; |
|
63 | - case "channel": |
|
64 | - $this->type = $this::FEED_RSS; |
|
65 | - break; |
|
66 | - case "feed": |
|
67 | - case "atom:feed": |
|
68 | - $this->type = $this::FEED_ATOM; |
|
69 | - break; |
|
70 | - default: |
|
71 | - if (!isset($this->error)) { |
|
72 | - $this->error = "Unknown/unsupported feed type"; |
|
73 | - } |
|
74 | - return; |
|
75 | - } |
|
76 | - } |
|
77 | - |
|
78 | - switch ($this->type) { |
|
79 | - case $this::FEED_ATOM: |
|
80 | - |
|
81 | - $title = $xpath->query("//atom:feed/atom:title")->item(0); |
|
82 | - |
|
83 | - if (!$title) { |
|
84 | - $title = $xpath->query("//atom03:feed/atom03:title")->item(0); |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - if ($title) { |
|
89 | - $this->title = $title->nodeValue; |
|
90 | - } |
|
91 | - |
|
92 | - $link = $xpath->query("//atom:feed/atom:link[not(@rel)]")->item(0); |
|
93 | - |
|
94 | - if (!$link) { |
|
95 | - $link = $xpath->query("//atom:feed/atom:link[@rel='alternate']")->item(0); |
|
96 | - } |
|
97 | - |
|
98 | - if (!$link) { |
|
99 | - $link = $xpath->query("//atom03:feed/atom03:link[not(@rel)]")->item(0); |
|
100 | - } |
|
101 | - |
|
102 | - if (!$link) { |
|
103 | - $link = $xpath->query("//atom03:feed/atom03:link[@rel='alternate']")->item(0); |
|
104 | - } |
|
105 | - |
|
106 | - if ($link && $link->hasAttributes()) { |
|
107 | - $this->link = $link->getAttribute("href"); |
|
108 | - } |
|
109 | - |
|
110 | - $articles = $xpath->query("//atom:entry"); |
|
111 | - |
|
112 | - if (!$articles || $articles->length == 0) { |
|
113 | - $articles = $xpath->query("//atom03:entry"); |
|
114 | - } |
|
115 | - |
|
116 | - foreach ($articles as $article) { |
|
117 | - array_push($this->items, new FeedItem_Atom($article, $this->doc, $this->xpath)); |
|
118 | - } |
|
119 | - |
|
120 | - break; |
|
121 | - case $this::FEED_RSS: |
|
122 | - $title = $xpath->query("//channel/title")->item(0); |
|
123 | - |
|
124 | - if ($title) { |
|
125 | - $this->title = $title->nodeValue; |
|
126 | - } |
|
127 | - |
|
128 | - $link = $xpath->query("//channel/link")->item(0); |
|
129 | - |
|
130 | - if ($link) { |
|
131 | - if ($link->getAttribute("href")) { |
|
132 | - $this->link = $link->getAttribute("href"); |
|
133 | - } else if ($link->nodeValue) { |
|
134 | - $this->link = $link->nodeValue; |
|
135 | - } |
|
136 | - } |
|
137 | - |
|
138 | - $articles = $xpath->query("//channel/item"); |
|
139 | - |
|
140 | - foreach ($articles as $article) { |
|
141 | - array_push($this->items, new FeedItem_RSS($article, $this->doc, $this->xpath)); |
|
142 | - } |
|
143 | - |
|
144 | - break; |
|
145 | - case $this::FEED_RDF: |
|
146 | - $xpath->registerNamespace('rssfake', 'http://purl.org/rss/1.0/'); |
|
147 | - |
|
148 | - $title = $xpath->query("//rssfake:channel/rssfake:title")->item(0); |
|
149 | - |
|
150 | - if ($title) { |
|
151 | - $this->title = $title->nodeValue; |
|
152 | - } |
|
153 | - |
|
154 | - $link = $xpath->query("//rssfake:channel/rssfake:link")->item(0); |
|
155 | - |
|
156 | - if ($link) { |
|
157 | - $this->link = $link->nodeValue; |
|
158 | - } |
|
159 | - |
|
160 | - $articles = $xpath->query("//rssfake:item"); |
|
161 | - |
|
162 | - foreach ($articles as $article) { |
|
163 | - array_push($this->items, new FeedItem_RSS($article, $this->doc, $this->xpath)); |
|
164 | - } |
|
165 | - |
|
166 | - break; |
|
167 | - |
|
168 | - } |
|
169 | - |
|
170 | - if ($this->title) { |
|
171 | - $this->title = trim($this->title); |
|
172 | - } |
|
173 | - if ($this->link) { |
|
174 | - $this->link = trim($this->link); |
|
175 | - } |
|
3 | + private $doc; |
|
4 | + private $error; |
|
5 | + private $libxml_errors = array(); |
|
6 | + private $items; |
|
7 | + private $link; |
|
8 | + private $title; |
|
9 | + private $type; |
|
10 | + private $xpath; |
|
11 | + |
|
12 | + const FEED_RDF = 0; |
|
13 | + const FEED_RSS = 1; |
|
14 | + const FEED_ATOM = 2; |
|
15 | + |
|
16 | + public function __construct($data) { |
|
17 | + libxml_use_internal_errors(true); |
|
18 | + libxml_clear_errors(); |
|
19 | + $this->doc = new DOMDocument(); |
|
20 | + $this->doc->loadXML($data); |
|
21 | + |
|
22 | + mb_substitute_character("none"); |
|
23 | + |
|
24 | + $error = libxml_get_last_error(); |
|
25 | + |
|
26 | + if ($error) { |
|
27 | + foreach (libxml_get_errors() as $error) { |
|
28 | + if ($error->level == LIBXML_ERR_FATAL) { |
|
29 | + if (!isset($this->error)) //currently only the first error is reported |
|
30 | + $this->error = $this->format_error($error); |
|
31 | + $this->libxml_errors [] = $this->format_error($error); |
|
32 | + } |
|
33 | + } |
|
34 | + } |
|
35 | + libxml_clear_errors(); |
|
36 | + |
|
37 | + $this->items = array(); |
|
38 | + } |
|
39 | + |
|
40 | + public function init() { |
|
41 | + $xpath = new DOMXPath($this->doc); |
|
42 | + $xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom'); |
|
43 | + $xpath->registerNamespace('atom03', 'http://purl.org/atom/ns#'); |
|
44 | + $xpath->registerNamespace('media', 'http://search.yahoo.com/mrss/'); |
|
45 | + $xpath->registerNamespace('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'); |
|
46 | + $xpath->registerNamespace('slash', 'http://purl.org/rss/1.0/modules/slash/'); |
|
47 | + $xpath->registerNamespace('dc', 'http://purl.org/dc/elements/1.1/'); |
|
48 | + $xpath->registerNamespace('content', 'http://purl.org/rss/1.0/modules/content/'); |
|
49 | + $xpath->registerNamespace('thread', 'http://purl.org/syndication/thread/1.0'); |
|
50 | + |
|
51 | + $this->xpath = $xpath; |
|
52 | + |
|
53 | + $root = $xpath->query("(//atom03:feed|//atom:feed|//channel|//rdf:rdf|//rdf:RDF)"); |
|
54 | + |
|
55 | + if ($root && $root->length > 0) { |
|
56 | + $root = $root->item(0); |
|
57 | + |
|
58 | + if ($root) { |
|
59 | + switch (mb_strtolower($root->tagName)) { |
|
60 | + case "rdf:rdf": |
|
61 | + $this->type = $this::FEED_RDF; |
|
62 | + break; |
|
63 | + case "channel": |
|
64 | + $this->type = $this::FEED_RSS; |
|
65 | + break; |
|
66 | + case "feed": |
|
67 | + case "atom:feed": |
|
68 | + $this->type = $this::FEED_ATOM; |
|
69 | + break; |
|
70 | + default: |
|
71 | + if (!isset($this->error)) { |
|
72 | + $this->error = "Unknown/unsupported feed type"; |
|
73 | + } |
|
74 | + return; |
|
75 | + } |
|
76 | + } |
|
77 | + |
|
78 | + switch ($this->type) { |
|
79 | + case $this::FEED_ATOM: |
|
80 | + |
|
81 | + $title = $xpath->query("//atom:feed/atom:title")->item(0); |
|
82 | + |
|
83 | + if (!$title) { |
|
84 | + $title = $xpath->query("//atom03:feed/atom03:title")->item(0); |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + if ($title) { |
|
89 | + $this->title = $title->nodeValue; |
|
90 | + } |
|
91 | + |
|
92 | + $link = $xpath->query("//atom:feed/atom:link[not(@rel)]")->item(0); |
|
93 | + |
|
94 | + if (!$link) { |
|
95 | + $link = $xpath->query("//atom:feed/atom:link[@rel='alternate']")->item(0); |
|
96 | + } |
|
97 | + |
|
98 | + if (!$link) { |
|
99 | + $link = $xpath->query("//atom03:feed/atom03:link[not(@rel)]")->item(0); |
|
100 | + } |
|
101 | + |
|
102 | + if (!$link) { |
|
103 | + $link = $xpath->query("//atom03:feed/atom03:link[@rel='alternate']")->item(0); |
|
104 | + } |
|
105 | + |
|
106 | + if ($link && $link->hasAttributes()) { |
|
107 | + $this->link = $link->getAttribute("href"); |
|
108 | + } |
|
109 | + |
|
110 | + $articles = $xpath->query("//atom:entry"); |
|
111 | + |
|
112 | + if (!$articles || $articles->length == 0) { |
|
113 | + $articles = $xpath->query("//atom03:entry"); |
|
114 | + } |
|
115 | + |
|
116 | + foreach ($articles as $article) { |
|
117 | + array_push($this->items, new FeedItem_Atom($article, $this->doc, $this->xpath)); |
|
118 | + } |
|
119 | + |
|
120 | + break; |
|
121 | + case $this::FEED_RSS: |
|
122 | + $title = $xpath->query("//channel/title")->item(0); |
|
123 | + |
|
124 | + if ($title) { |
|
125 | + $this->title = $title->nodeValue; |
|
126 | + } |
|
127 | + |
|
128 | + $link = $xpath->query("//channel/link")->item(0); |
|
129 | + |
|
130 | + if ($link) { |
|
131 | + if ($link->getAttribute("href")) { |
|
132 | + $this->link = $link->getAttribute("href"); |
|
133 | + } else if ($link->nodeValue) { |
|
134 | + $this->link = $link->nodeValue; |
|
135 | + } |
|
136 | + } |
|
137 | + |
|
138 | + $articles = $xpath->query("//channel/item"); |
|
139 | + |
|
140 | + foreach ($articles as $article) { |
|
141 | + array_push($this->items, new FeedItem_RSS($article, $this->doc, $this->xpath)); |
|
142 | + } |
|
143 | + |
|
144 | + break; |
|
145 | + case $this::FEED_RDF: |
|
146 | + $xpath->registerNamespace('rssfake', 'http://purl.org/rss/1.0/'); |
|
147 | + |
|
148 | + $title = $xpath->query("//rssfake:channel/rssfake:title")->item(0); |
|
149 | + |
|
150 | + if ($title) { |
|
151 | + $this->title = $title->nodeValue; |
|
152 | + } |
|
153 | + |
|
154 | + $link = $xpath->query("//rssfake:channel/rssfake:link")->item(0); |
|
155 | + |
|
156 | + if ($link) { |
|
157 | + $this->link = $link->nodeValue; |
|
158 | + } |
|
159 | + |
|
160 | + $articles = $xpath->query("//rssfake:item"); |
|
161 | + |
|
162 | + foreach ($articles as $article) { |
|
163 | + array_push($this->items, new FeedItem_RSS($article, $this->doc, $this->xpath)); |
|
164 | + } |
|
165 | + |
|
166 | + break; |
|
167 | + |
|
168 | + } |
|
169 | + |
|
170 | + if ($this->title) { |
|
171 | + $this->title = trim($this->title); |
|
172 | + } |
|
173 | + if ($this->link) { |
|
174 | + $this->link = trim($this->link); |
|
175 | + } |
|
176 | 176 | |
177 | - } else { |
|
178 | - if (!isset($this->error)) { |
|
179 | - $this->error = "Unknown/unsupported feed type"; |
|
180 | - } |
|
181 | - return; |
|
182 | - } |
|
183 | - } |
|
184 | - |
|
185 | - public function format_error($error) { |
|
186 | - if ($error) { |
|
187 | - return sprintf("LibXML error %s at line %d (column %d): %s", |
|
188 | - $error->code, $error->line, $error->column, |
|
189 | - $error->message); |
|
190 | - } else { |
|
191 | - return ""; |
|
192 | - } |
|
193 | - } |
|
194 | - |
|
195 | - // libxml may have invalid unicode data in error messages |
|
196 | - public function error() { |
|
197 | - return UConverter::transcode($this->error, 'UTF-8', 'UTF-8'); |
|
198 | - } |
|
199 | - |
|
200 | - // WARNING: may return invalid unicode data |
|
201 | - public function errors() { |
|
202 | - return $this->libxml_errors; |
|
203 | - } |
|
204 | - |
|
205 | - public function get_link() { |
|
206 | - return clean($this->link); |
|
207 | - } |
|
208 | - |
|
209 | - public function get_title() { |
|
210 | - return clean($this->title); |
|
211 | - } |
|
212 | - |
|
213 | - public function get_items() { |
|
214 | - return $this->items; |
|
215 | - } |
|
216 | - |
|
217 | - public function get_links($rel) { |
|
218 | - $rv = array(); |
|
219 | - |
|
220 | - switch ($this->type) { |
|
221 | - case $this::FEED_ATOM: |
|
222 | - $links = $this->xpath->query("//atom:feed/atom:link"); |
|
223 | - |
|
224 | - foreach ($links as $link) { |
|
225 | - if (!$rel || $link->hasAttribute('rel') && $link->getAttribute('rel') == $rel) { |
|
226 | - array_push($rv, clean(trim($link->getAttribute('href')))); |
|
227 | - } |
|
228 | - } |
|
229 | - break; |
|
230 | - case $this::FEED_RSS: |
|
231 | - $links = $this->xpath->query("//atom:link"); |
|
232 | - |
|
233 | - foreach ($links as $link) { |
|
234 | - if (!$rel || $link->hasAttribute('rel') && $link->getAttribute('rel') == $rel) { |
|
235 | - array_push($rv, clean(trim($link->getAttribute('href')))); |
|
236 | - } |
|
237 | - } |
|
238 | - break; |
|
239 | - } |
|
240 | - |
|
241 | - return $rv; |
|
242 | - } |
|
177 | + } else { |
|
178 | + if (!isset($this->error)) { |
|
179 | + $this->error = "Unknown/unsupported feed type"; |
|
180 | + } |
|
181 | + return; |
|
182 | + } |
|
183 | + } |
|
184 | + |
|
185 | + public function format_error($error) { |
|
186 | + if ($error) { |
|
187 | + return sprintf("LibXML error %s at line %d (column %d): %s", |
|
188 | + $error->code, $error->line, $error->column, |
|
189 | + $error->message); |
|
190 | + } else { |
|
191 | + return ""; |
|
192 | + } |
|
193 | + } |
|
194 | + |
|
195 | + // libxml may have invalid unicode data in error messages |
|
196 | + public function error() { |
|
197 | + return UConverter::transcode($this->error, 'UTF-8', 'UTF-8'); |
|
198 | + } |
|
199 | + |
|
200 | + // WARNING: may return invalid unicode data |
|
201 | + public function errors() { |
|
202 | + return $this->libxml_errors; |
|
203 | + } |
|
204 | + |
|
205 | + public function get_link() { |
|
206 | + return clean($this->link); |
|
207 | + } |
|
208 | + |
|
209 | + public function get_title() { |
|
210 | + return clean($this->title); |
|
211 | + } |
|
212 | + |
|
213 | + public function get_items() { |
|
214 | + return $this->items; |
|
215 | + } |
|
216 | + |
|
217 | + public function get_links($rel) { |
|
218 | + $rv = array(); |
|
219 | + |
|
220 | + switch ($this->type) { |
|
221 | + case $this::FEED_ATOM: |
|
222 | + $links = $this->xpath->query("//atom:feed/atom:link"); |
|
223 | + |
|
224 | + foreach ($links as $link) { |
|
225 | + if (!$rel || $link->hasAttribute('rel') && $link->getAttribute('rel') == $rel) { |
|
226 | + array_push($rv, clean(trim($link->getAttribute('href')))); |
|
227 | + } |
|
228 | + } |
|
229 | + break; |
|
230 | + case $this::FEED_RSS: |
|
231 | + $links = $this->xpath->query("//atom:link"); |
|
232 | + |
|
233 | + foreach ($links as $link) { |
|
234 | + if (!$rel || $link->hasAttribute('rel') && $link->getAttribute('rel') == $rel) { |
|
235 | + array_push($rv, clean(trim($link->getAttribute('href')))); |
|
236 | + } |
|
237 | + } |
|
238 | + break; |
|
239 | + } |
|
240 | + |
|
241 | + return $rv; |
|
242 | + } |
|
243 | 243 | } |
@@ -26,8 +26,10 @@ |
||
26 | 26 | if ($error) { |
27 | 27 | foreach (libxml_get_errors() as $error) { |
28 | 28 | if ($error->level == LIBXML_ERR_FATAL) { |
29 | - if (!isset($this->error)) //currently only the first error is reported |
|
29 | + if (!isset($this->error)) { |
|
30 | + //currently only the first error is reported |
|
30 | 31 | $this->error = $this->format_error($error); |
32 | + } |
|
31 | 33 | $this->libxml_errors [] = $this->format_error($error); |
32 | 34 | } |
33 | 35 | } |
@@ -1,89 +1,89 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class Pref_Feeds extends Handler_Protected { |
3 | - public function csrf_ignore($method) { |
|
4 | - $csrf_ignored = array("index", "getfeedtree", "add", "editcats", "editfeed", |
|
5 | - "savefeedorder", "uploadicon", "feedswitherrors", "inactivefeeds", |
|
6 | - "batchsubscribe"); |
|
3 | + public function csrf_ignore($method) { |
|
4 | + $csrf_ignored = array("index", "getfeedtree", "add", "editcats", "editfeed", |
|
5 | + "savefeedorder", "uploadicon", "feedswitherrors", "inactivefeeds", |
|
6 | + "batchsubscribe"); |
|
7 | 7 | |
8 | - return array_search($method, $csrf_ignored) !== false; |
|
9 | - } |
|
8 | + return array_search($method, $csrf_ignored) !== false; |
|
9 | + } |
|
10 | 10 | |
11 | - public static function get_ts_languages() { |
|
12 | - $rv = []; |
|
11 | + public static function get_ts_languages() { |
|
12 | + $rv = []; |
|
13 | 13 | |
14 | - if (DB_TYPE == "pgsql") { |
|
15 | - $dbh = Db::pdo(); |
|
14 | + if (DB_TYPE == "pgsql") { |
|
15 | + $dbh = Db::pdo(); |
|
16 | 16 | |
17 | - $res = $dbh->query("SELECT cfgname FROM pg_ts_config"); |
|
17 | + $res = $dbh->query("SELECT cfgname FROM pg_ts_config"); |
|
18 | 18 | |
19 | - while ($row = $res->fetch()) { |
|
20 | - array_push($rv, ucfirst($row['cfgname'])); |
|
21 | - } |
|
22 | - } |
|
19 | + while ($row = $res->fetch()) { |
|
20 | + array_push($rv, ucfirst($row['cfgname'])); |
|
21 | + } |
|
22 | + } |
|
23 | 23 | |
24 | - return $rv; |
|
25 | - } |
|
24 | + return $rv; |
|
25 | + } |
|
26 | 26 | |
27 | - public function batch_edit_cbox($elem, $label = false) { |
|
28 | - print "<input type=\"checkbox\" title=\"".__("Check to enable field")."\" |
|
27 | + public function batch_edit_cbox($elem, $label = false) { |
|
28 | + print "<input type=\"checkbox\" title=\"".__("Check to enable field")."\" |
|
29 | 29 | onchange=\"dijit.byId('feedEditDlg').toggleField(this, '$elem', '$label')\">"; |
30 | - } |
|
30 | + } |
|
31 | 31 | |
32 | - public function renamecat() { |
|
33 | - $title = clean($_REQUEST['title']); |
|
34 | - $id = clean($_REQUEST['id']); |
|
32 | + public function renamecat() { |
|
33 | + $title = clean($_REQUEST['title']); |
|
34 | + $id = clean($_REQUEST['id']); |
|
35 | 35 | |
36 | - if ($title) { |
|
37 | - $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories SET |
|
36 | + if ($title) { |
|
37 | + $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories SET |
|
38 | 38 | title = ? WHERE id = ? AND owner_uid = ?"); |
39 | - $sth->execute([$title, $id, $_SESSION['uid']]); |
|
40 | - } |
|
41 | - } |
|
39 | + $sth->execute([$title, $id, $_SESSION['uid']]); |
|
40 | + } |
|
41 | + } |
|
42 | 42 | |
43 | - private function get_category_items($cat_id) { |
|
43 | + private function get_category_items($cat_id) { |
|
44 | 44 | |
45 | - if (clean($_REQUEST['mode']) != 2) { |
|
46 | - $search = $_SESSION["prefs_feed_search"]; |
|
47 | - } else { |
|
48 | - $search = ""; |
|
49 | - } |
|
45 | + if (clean($_REQUEST['mode']) != 2) { |
|
46 | + $search = $_SESSION["prefs_feed_search"]; |
|
47 | + } else { |
|
48 | + $search = ""; |
|
49 | + } |
|
50 | 50 | |
51 | - // first one is set by API |
|
52 | - $show_empty_cats = clean($_REQUEST['force_show_empty']) || |
|
53 | - (clean($_REQUEST['mode']) != 2 && !$search); |
|
51 | + // first one is set by API |
|
52 | + $show_empty_cats = clean($_REQUEST['force_show_empty']) || |
|
53 | + (clean($_REQUEST['mode']) != 2 && !$search); |
|
54 | 54 | |
55 | - $items = array(); |
|
55 | + $items = array(); |
|
56 | 56 | |
57 | - $sth = $this->pdo->prepare("SELECT id, title FROM ttrss_feed_categories |
|
57 | + $sth = $this->pdo->prepare("SELECT id, title FROM ttrss_feed_categories |
|
58 | 58 | WHERE owner_uid = ? AND parent_cat = ? ORDER BY order_id, title"); |
59 | - $sth->execute([$_SESSION['uid'], $cat_id]); |
|
59 | + $sth->execute([$_SESSION['uid'], $cat_id]); |
|
60 | 60 | |
61 | - while ($line = $sth->fetch()) { |
|
61 | + while ($line = $sth->fetch()) { |
|
62 | 62 | |
63 | - $cat = array(); |
|
64 | - $cat['id'] = 'CAT:'.$line['id']; |
|
65 | - $cat['bare_id'] = (int) $line['id']; |
|
66 | - $cat['name'] = $line['title']; |
|
67 | - $cat['items'] = array(); |
|
68 | - $cat['checkbox'] = false; |
|
69 | - $cat['type'] = 'category'; |
|
70 | - $cat['unread'] = -1; |
|
71 | - $cat['child_unread'] = -1; |
|
72 | - $cat['auxcounter'] = -1; |
|
73 | - $cat['parent_id'] = $cat_id; |
|
63 | + $cat = array(); |
|
64 | + $cat['id'] = 'CAT:'.$line['id']; |
|
65 | + $cat['bare_id'] = (int) $line['id']; |
|
66 | + $cat['name'] = $line['title']; |
|
67 | + $cat['items'] = array(); |
|
68 | + $cat['checkbox'] = false; |
|
69 | + $cat['type'] = 'category'; |
|
70 | + $cat['unread'] = -1; |
|
71 | + $cat['child_unread'] = -1; |
|
72 | + $cat['auxcounter'] = -1; |
|
73 | + $cat['parent_id'] = $cat_id; |
|
74 | 74 | |
75 | - $cat['items'] = $this->get_category_items($line['id']); |
|
75 | + $cat['items'] = $this->get_category_items($line['id']); |
|
76 | 76 | |
77 | - $num_children = $this->calculate_children_count($cat); |
|
78 | - $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); |
|
77 | + $num_children = $this->calculate_children_count($cat); |
|
78 | + $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); |
|
79 | 79 | |
80 | - if ($num_children > 0 || $show_empty_cats) { |
|
81 | - array_push($items, $cat); |
|
82 | - } |
|
80 | + if ($num_children > 0 || $show_empty_cats) { |
|
81 | + array_push($items, $cat); |
|
82 | + } |
|
83 | 83 | |
84 | - } |
|
84 | + } |
|
85 | 85 | |
86 | - $fsth = $this->pdo->prepare("SELECT id, title, last_error, |
|
86 | + $fsth = $this->pdo->prepare("SELECT id, title, last_error, |
|
87 | 87 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated, update_interval |
88 | 88 | FROM ttrss_feeds |
89 | 89 | WHERE cat_id = :cat AND |
@@ -91,687 +91,687 @@ discard block |
||
91 | 91 | (:search = '' OR (LOWER(title) LIKE :search OR LOWER(feed_url) LIKE :search)) |
92 | 92 | ORDER BY order_id, title"); |
93 | 93 | |
94 | - $fsth->execute([":cat" => $cat_id, ":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]); |
|
95 | - |
|
96 | - while ($feed_line = $fsth->fetch()) { |
|
97 | - $feed = array(); |
|
98 | - $feed['id'] = 'FEED:'.$feed_line['id']; |
|
99 | - $feed['bare_id'] = (int) $feed_line['id']; |
|
100 | - $feed['auxcounter'] = -1; |
|
101 | - $feed['name'] = $feed_line['title']; |
|
102 | - $feed['checkbox'] = false; |
|
103 | - $feed['unread'] = -1; |
|
104 | - $feed['error'] = $feed_line['last_error']; |
|
105 | - $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); |
|
106 | - $feed['param'] = make_local_datetime( |
|
107 | - $feed_line['last_updated'], true); |
|
108 | - $feed['updates_disabled'] = (int) ($feed_line['update_interval'] < 0); |
|
109 | - |
|
110 | - array_push($items, $feed); |
|
111 | - } |
|
112 | - |
|
113 | - return $items; |
|
114 | - } |
|
115 | - |
|
116 | - public function getfeedtree() { |
|
117 | - print json_encode($this->makefeedtree()); |
|
118 | - } |
|
119 | - |
|
120 | - public function makefeedtree() { |
|
121 | - |
|
122 | - if (clean($_REQUEST['mode']) != 2) { |
|
123 | - $search = $_SESSION["prefs_feed_search"]; |
|
124 | - } else { |
|
125 | - $search = ""; |
|
126 | - } |
|
127 | - |
|
128 | - $root = array(); |
|
129 | - $root['id'] = 'root'; |
|
130 | - $root['name'] = __('Feeds'); |
|
131 | - $root['items'] = array(); |
|
132 | - $root['type'] = 'category'; |
|
133 | - |
|
134 | - $enable_cats = get_pref('ENABLE_FEED_CATS'); |
|
135 | - |
|
136 | - if (clean($_REQUEST['mode']) == 2) { |
|
137 | - |
|
138 | - if ($enable_cats) { |
|
139 | - $cat = $this->feedlist_init_cat(-1); |
|
140 | - } else { |
|
141 | - $cat['items'] = array(); |
|
142 | - } |
|
143 | - |
|
144 | - foreach (array(-4, -3, -1, -2, 0, -6) as $i) { |
|
145 | - array_push($cat['items'], $this->feedlist_init_feed($i)); |
|
146 | - } |
|
147 | - |
|
148 | - /* Plugin feeds for -1 */ |
|
149 | - |
|
150 | - $feeds = PluginHost::getInstance()->get_feeds(-1); |
|
151 | - |
|
152 | - if ($feeds) { |
|
153 | - foreach ($feeds as $feed) { |
|
154 | - $feed_id = PluginHost::pfeed_to_feed_id($feed['id']); |
|
155 | - |
|
156 | - $item = array(); |
|
157 | - $item['id'] = 'FEED:'.$feed_id; |
|
158 | - $item['bare_id'] = (int) $feed_id; |
|
159 | - $item['auxcounter'] = -1; |
|
160 | - $item['name'] = $feed['title']; |
|
161 | - $item['checkbox'] = false; |
|
162 | - $item['error'] = ''; |
|
163 | - $item['icon'] = $feed['icon']; |
|
164 | - |
|
165 | - $item['param'] = ''; |
|
166 | - $item['unread'] = -1; |
|
167 | - $item['type'] = 'feed'; |
|
168 | - |
|
169 | - array_push($cat['items'], $item); |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - if ($enable_cats) { |
|
174 | - array_push($root['items'], $cat); |
|
175 | - } else { |
|
176 | - $root['items'] = array_merge($root['items'], $cat['items']); |
|
177 | - } |
|
178 | - |
|
179 | - $sth = $this->pdo->prepare("SELECT * FROM |
|
94 | + $fsth->execute([":cat" => $cat_id, ":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]); |
|
95 | + |
|
96 | + while ($feed_line = $fsth->fetch()) { |
|
97 | + $feed = array(); |
|
98 | + $feed['id'] = 'FEED:'.$feed_line['id']; |
|
99 | + $feed['bare_id'] = (int) $feed_line['id']; |
|
100 | + $feed['auxcounter'] = -1; |
|
101 | + $feed['name'] = $feed_line['title']; |
|
102 | + $feed['checkbox'] = false; |
|
103 | + $feed['unread'] = -1; |
|
104 | + $feed['error'] = $feed_line['last_error']; |
|
105 | + $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); |
|
106 | + $feed['param'] = make_local_datetime( |
|
107 | + $feed_line['last_updated'], true); |
|
108 | + $feed['updates_disabled'] = (int) ($feed_line['update_interval'] < 0); |
|
109 | + |
|
110 | + array_push($items, $feed); |
|
111 | + } |
|
112 | + |
|
113 | + return $items; |
|
114 | + } |
|
115 | + |
|
116 | + public function getfeedtree() { |
|
117 | + print json_encode($this->makefeedtree()); |
|
118 | + } |
|
119 | + |
|
120 | + public function makefeedtree() { |
|
121 | + |
|
122 | + if (clean($_REQUEST['mode']) != 2) { |
|
123 | + $search = $_SESSION["prefs_feed_search"]; |
|
124 | + } else { |
|
125 | + $search = ""; |
|
126 | + } |
|
127 | + |
|
128 | + $root = array(); |
|
129 | + $root['id'] = 'root'; |
|
130 | + $root['name'] = __('Feeds'); |
|
131 | + $root['items'] = array(); |
|
132 | + $root['type'] = 'category'; |
|
133 | + |
|
134 | + $enable_cats = get_pref('ENABLE_FEED_CATS'); |
|
135 | + |
|
136 | + if (clean($_REQUEST['mode']) == 2) { |
|
137 | + |
|
138 | + if ($enable_cats) { |
|
139 | + $cat = $this->feedlist_init_cat(-1); |
|
140 | + } else { |
|
141 | + $cat['items'] = array(); |
|
142 | + } |
|
143 | + |
|
144 | + foreach (array(-4, -3, -1, -2, 0, -6) as $i) { |
|
145 | + array_push($cat['items'], $this->feedlist_init_feed($i)); |
|
146 | + } |
|
147 | + |
|
148 | + /* Plugin feeds for -1 */ |
|
149 | + |
|
150 | + $feeds = PluginHost::getInstance()->get_feeds(-1); |
|
151 | + |
|
152 | + if ($feeds) { |
|
153 | + foreach ($feeds as $feed) { |
|
154 | + $feed_id = PluginHost::pfeed_to_feed_id($feed['id']); |
|
155 | + |
|
156 | + $item = array(); |
|
157 | + $item['id'] = 'FEED:'.$feed_id; |
|
158 | + $item['bare_id'] = (int) $feed_id; |
|
159 | + $item['auxcounter'] = -1; |
|
160 | + $item['name'] = $feed['title']; |
|
161 | + $item['checkbox'] = false; |
|
162 | + $item['error'] = ''; |
|
163 | + $item['icon'] = $feed['icon']; |
|
164 | + |
|
165 | + $item['param'] = ''; |
|
166 | + $item['unread'] = -1; |
|
167 | + $item['type'] = 'feed'; |
|
168 | + |
|
169 | + array_push($cat['items'], $item); |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + if ($enable_cats) { |
|
174 | + array_push($root['items'], $cat); |
|
175 | + } else { |
|
176 | + $root['items'] = array_merge($root['items'], $cat['items']); |
|
177 | + } |
|
178 | + |
|
179 | + $sth = $this->pdo->prepare("SELECT * FROM |
|
180 | 180 | ttrss_labels2 WHERE owner_uid = ? ORDER by caption"); |
181 | - $sth->execute([$_SESSION['uid']]); |
|
181 | + $sth->execute([$_SESSION['uid']]); |
|
182 | 182 | |
183 | - if (get_pref('ENABLE_FEED_CATS')) { |
|
184 | - $cat = $this->feedlist_init_cat(-2); |
|
185 | - } else { |
|
186 | - $cat['items'] = array(); |
|
187 | - } |
|
183 | + if (get_pref('ENABLE_FEED_CATS')) { |
|
184 | + $cat = $this->feedlist_init_cat(-2); |
|
185 | + } else { |
|
186 | + $cat['items'] = array(); |
|
187 | + } |
|
188 | 188 | |
189 | - $num_labels = 0; |
|
190 | - while ($line = $sth->fetch()) { |
|
191 | - ++$num_labels; |
|
189 | + $num_labels = 0; |
|
190 | + while ($line = $sth->fetch()) { |
|
191 | + ++$num_labels; |
|
192 | 192 | |
193 | - $label_id = Labels::label_to_feed_id($line['id']); |
|
193 | + $label_id = Labels::label_to_feed_id($line['id']); |
|
194 | 194 | |
195 | - $feed = $this->feedlist_init_feed($label_id, false, 0); |
|
195 | + $feed = $this->feedlist_init_feed($label_id, false, 0); |
|
196 | 196 | |
197 | - $feed['fg_color'] = $line['fg_color']; |
|
198 | - $feed['bg_color'] = $line['bg_color']; |
|
197 | + $feed['fg_color'] = $line['fg_color']; |
|
198 | + $feed['bg_color'] = $line['bg_color']; |
|
199 | 199 | |
200 | - array_push($cat['items'], $feed); |
|
201 | - } |
|
200 | + array_push($cat['items'], $feed); |
|
201 | + } |
|
202 | 202 | |
203 | - if ($num_labels) { |
|
204 | - if ($enable_cats) { |
|
205 | - array_push($root['items'], $cat); |
|
206 | - } else { |
|
207 | - $root['items'] = array_merge($root['items'], $cat['items']); |
|
208 | - } |
|
209 | - } |
|
210 | - } |
|
203 | + if ($num_labels) { |
|
204 | + if ($enable_cats) { |
|
205 | + array_push($root['items'], $cat); |
|
206 | + } else { |
|
207 | + $root['items'] = array_merge($root['items'], $cat['items']); |
|
208 | + } |
|
209 | + } |
|
210 | + } |
|
211 | 211 | |
212 | - if ($enable_cats) { |
|
213 | - $show_empty_cats = clean($_REQUEST['force_show_empty']) || |
|
214 | - (clean($_REQUEST['mode']) != 2 && !$search); |
|
212 | + if ($enable_cats) { |
|
213 | + $show_empty_cats = clean($_REQUEST['force_show_empty']) || |
|
214 | + (clean($_REQUEST['mode']) != 2 && !$search); |
|
215 | 215 | |
216 | - $sth = $this->pdo->prepare("SELECT id, title FROM ttrss_feed_categories |
|
216 | + $sth = $this->pdo->prepare("SELECT id, title FROM ttrss_feed_categories |
|
217 | 217 | WHERE owner_uid = ? AND parent_cat IS NULL ORDER BY order_id, title"); |
218 | - $sth->execute([$_SESSION['uid']]); |
|
219 | - |
|
220 | - while ($line = $sth->fetch()) { |
|
221 | - $cat = array(); |
|
222 | - $cat['id'] = 'CAT:'.$line['id']; |
|
223 | - $cat['bare_id'] = (int) $line['id']; |
|
224 | - $cat['auxcounter'] = -1; |
|
225 | - $cat['name'] = $line['title']; |
|
226 | - $cat['items'] = array(); |
|
227 | - $cat['checkbox'] = false; |
|
228 | - $cat['type'] = 'category'; |
|
229 | - $cat['unread'] = -1; |
|
230 | - $cat['child_unread'] = -1; |
|
231 | - |
|
232 | - $cat['items'] = $this->get_category_items($line['id']); |
|
233 | - |
|
234 | - $num_children = $this->calculate_children_count($cat); |
|
235 | - $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); |
|
236 | - |
|
237 | - if ($num_children > 0 || $show_empty_cats) { |
|
238 | - array_push($root['items'], $cat); |
|
239 | - } |
|
240 | - |
|
241 | - $root['param'] += count($cat['items']); |
|
242 | - } |
|
243 | - |
|
244 | - /* Uncategorized is a special case */ |
|
245 | - |
|
246 | - $cat = array(); |
|
247 | - $cat['id'] = 'CAT:0'; |
|
248 | - $cat['bare_id'] = 0; |
|
249 | - $cat['auxcounter'] = -1; |
|
250 | - $cat['name'] = __("Uncategorized"); |
|
251 | - $cat['items'] = array(); |
|
252 | - $cat['type'] = 'category'; |
|
253 | - $cat['checkbox'] = false; |
|
254 | - $cat['unread'] = -1; |
|
255 | - $cat['child_unread'] = -1; |
|
256 | - |
|
257 | - $fsth = $this->pdo->prepare("SELECT id, title,last_error, |
|
218 | + $sth->execute([$_SESSION['uid']]); |
|
219 | + |
|
220 | + while ($line = $sth->fetch()) { |
|
221 | + $cat = array(); |
|
222 | + $cat['id'] = 'CAT:'.$line['id']; |
|
223 | + $cat['bare_id'] = (int) $line['id']; |
|
224 | + $cat['auxcounter'] = -1; |
|
225 | + $cat['name'] = $line['title']; |
|
226 | + $cat['items'] = array(); |
|
227 | + $cat['checkbox'] = false; |
|
228 | + $cat['type'] = 'category'; |
|
229 | + $cat['unread'] = -1; |
|
230 | + $cat['child_unread'] = -1; |
|
231 | + |
|
232 | + $cat['items'] = $this->get_category_items($line['id']); |
|
233 | + |
|
234 | + $num_children = $this->calculate_children_count($cat); |
|
235 | + $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); |
|
236 | + |
|
237 | + if ($num_children > 0 || $show_empty_cats) { |
|
238 | + array_push($root['items'], $cat); |
|
239 | + } |
|
240 | + |
|
241 | + $root['param'] += count($cat['items']); |
|
242 | + } |
|
243 | + |
|
244 | + /* Uncategorized is a special case */ |
|
245 | + |
|
246 | + $cat = array(); |
|
247 | + $cat['id'] = 'CAT:0'; |
|
248 | + $cat['bare_id'] = 0; |
|
249 | + $cat['auxcounter'] = -1; |
|
250 | + $cat['name'] = __("Uncategorized"); |
|
251 | + $cat['items'] = array(); |
|
252 | + $cat['type'] = 'category'; |
|
253 | + $cat['checkbox'] = false; |
|
254 | + $cat['unread'] = -1; |
|
255 | + $cat['child_unread'] = -1; |
|
256 | + |
|
257 | + $fsth = $this->pdo->prepare("SELECT id, title,last_error, |
|
258 | 258 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated, update_interval |
259 | 259 | FROM ttrss_feeds |
260 | 260 | WHERE cat_id IS NULL AND |
261 | 261 | owner_uid = :uid AND |
262 | 262 | (:search = '' OR (LOWER(title) LIKE :search OR LOWER(feed_url) LIKE :search)) |
263 | 263 | ORDER BY order_id, title"); |
264 | - $fsth->execute([":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]); |
|
265 | - |
|
266 | - while ($feed_line = $fsth->fetch()) { |
|
267 | - $feed = array(); |
|
268 | - $feed['id'] = 'FEED:'.$feed_line['id']; |
|
269 | - $feed['bare_id'] = (int) $feed_line['id']; |
|
270 | - $feed['auxcounter'] = -1; |
|
271 | - $feed['name'] = $feed_line['title']; |
|
272 | - $feed['checkbox'] = false; |
|
273 | - $feed['error'] = $feed_line['last_error']; |
|
274 | - $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); |
|
275 | - $feed['param'] = make_local_datetime( |
|
276 | - $feed_line['last_updated'], true); |
|
277 | - $feed['unread'] = -1; |
|
278 | - $feed['type'] = 'feed'; |
|
279 | - $feed['updates_disabled'] = (int) ($feed_line['update_interval'] < 0); |
|
280 | - |
|
281 | - array_push($cat['items'], $feed); |
|
282 | - } |
|
283 | - |
|
284 | - $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); |
|
285 | - |
|
286 | - if (count($cat['items']) > 0 || $show_empty_cats) { |
|
287 | - array_push($root['items'], $cat); |
|
288 | - } |
|
289 | - |
|
290 | - $num_children = $this->calculate_children_count($root); |
|
291 | - $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); |
|
292 | - |
|
293 | - } else { |
|
294 | - $fsth = $this->pdo->prepare("SELECT id, title, last_error, |
|
264 | + $fsth->execute([":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]); |
|
265 | + |
|
266 | + while ($feed_line = $fsth->fetch()) { |
|
267 | + $feed = array(); |
|
268 | + $feed['id'] = 'FEED:'.$feed_line['id']; |
|
269 | + $feed['bare_id'] = (int) $feed_line['id']; |
|
270 | + $feed['auxcounter'] = -1; |
|
271 | + $feed['name'] = $feed_line['title']; |
|
272 | + $feed['checkbox'] = false; |
|
273 | + $feed['error'] = $feed_line['last_error']; |
|
274 | + $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); |
|
275 | + $feed['param'] = make_local_datetime( |
|
276 | + $feed_line['last_updated'], true); |
|
277 | + $feed['unread'] = -1; |
|
278 | + $feed['type'] = 'feed'; |
|
279 | + $feed['updates_disabled'] = (int) ($feed_line['update_interval'] < 0); |
|
280 | + |
|
281 | + array_push($cat['items'], $feed); |
|
282 | + } |
|
283 | + |
|
284 | + $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); |
|
285 | + |
|
286 | + if (count($cat['items']) > 0 || $show_empty_cats) { |
|
287 | + array_push($root['items'], $cat); |
|
288 | + } |
|
289 | + |
|
290 | + $num_children = $this->calculate_children_count($root); |
|
291 | + $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); |
|
292 | + |
|
293 | + } else { |
|
294 | + $fsth = $this->pdo->prepare("SELECT id, title, last_error, |
|
295 | 295 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated, update_interval |
296 | 296 | FROM ttrss_feeds |
297 | 297 | WHERE owner_uid = :uid AND |
298 | 298 | (:search = '' OR (LOWER(title) LIKE :search OR LOWER(feed_url) LIKE :search)) |
299 | 299 | ORDER BY order_id, title"); |
300 | - $fsth->execute([":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]); |
|
301 | - |
|
302 | - while ($feed_line = $fsth->fetch()) { |
|
303 | - $feed = array(); |
|
304 | - $feed['id'] = 'FEED:'.$feed_line['id']; |
|
305 | - $feed['bare_id'] = (int) $feed_line['id']; |
|
306 | - $feed['auxcounter'] = -1; |
|
307 | - $feed['name'] = $feed_line['title']; |
|
308 | - $feed['checkbox'] = false; |
|
309 | - $feed['error'] = $feed_line['last_error']; |
|
310 | - $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); |
|
311 | - $feed['param'] = make_local_datetime( |
|
312 | - $feed_line['last_updated'], true); |
|
313 | - $feed['unread'] = -1; |
|
314 | - $feed['type'] = 'feed'; |
|
315 | - $feed['updates_disabled'] = (int) ($feed_line['update_interval'] < 0); |
|
316 | - |
|
317 | - array_push($root['items'], $feed); |
|
318 | - } |
|
319 | - |
|
320 | - $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($root['items'])), count($root['items'])); |
|
321 | - } |
|
322 | - |
|
323 | - $fl = array(); |
|
324 | - $fl['identifier'] = 'id'; |
|
325 | - $fl['label'] = 'name'; |
|
326 | - |
|
327 | - if (clean($_REQUEST['mode']) != 2) { |
|
328 | - $fl['items'] = array($root); |
|
329 | - } else { |
|
330 | - $fl['items'] = $root['items']; |
|
331 | - } |
|
332 | - |
|
333 | - return $fl; |
|
334 | - } |
|
335 | - |
|
336 | - public function catsortreset() { |
|
337 | - $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories |
|
300 | + $fsth->execute([":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]); |
|
301 | + |
|
302 | + while ($feed_line = $fsth->fetch()) { |
|
303 | + $feed = array(); |
|
304 | + $feed['id'] = 'FEED:'.$feed_line['id']; |
|
305 | + $feed['bare_id'] = (int) $feed_line['id']; |
|
306 | + $feed['auxcounter'] = -1; |
|
307 | + $feed['name'] = $feed_line['title']; |
|
308 | + $feed['checkbox'] = false; |
|
309 | + $feed['error'] = $feed_line['last_error']; |
|
310 | + $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); |
|
311 | + $feed['param'] = make_local_datetime( |
|
312 | + $feed_line['last_updated'], true); |
|
313 | + $feed['unread'] = -1; |
|
314 | + $feed['type'] = 'feed'; |
|
315 | + $feed['updates_disabled'] = (int) ($feed_line['update_interval'] < 0); |
|
316 | + |
|
317 | + array_push($root['items'], $feed); |
|
318 | + } |
|
319 | + |
|
320 | + $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($root['items'])), count($root['items'])); |
|
321 | + } |
|
322 | + |
|
323 | + $fl = array(); |
|
324 | + $fl['identifier'] = 'id'; |
|
325 | + $fl['label'] = 'name'; |
|
326 | + |
|
327 | + if (clean($_REQUEST['mode']) != 2) { |
|
328 | + $fl['items'] = array($root); |
|
329 | + } else { |
|
330 | + $fl['items'] = $root['items']; |
|
331 | + } |
|
332 | + |
|
333 | + return $fl; |
|
334 | + } |
|
335 | + |
|
336 | + public function catsortreset() { |
|
337 | + $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories |
|
338 | 338 | SET order_id = 0 WHERE owner_uid = ?"); |
339 | - $sth->execute([$_SESSION['uid']]); |
|
340 | - } |
|
339 | + $sth->execute([$_SESSION['uid']]); |
|
340 | + } |
|
341 | 341 | |
342 | - public function feedsortreset() { |
|
343 | - $sth = $this->pdo->prepare("UPDATE ttrss_feeds |
|
342 | + public function feedsortreset() { |
|
343 | + $sth = $this->pdo->prepare("UPDATE ttrss_feeds |
|
344 | 344 | SET order_id = 0 WHERE owner_uid = ?"); |
345 | - $sth->execute([$_SESSION['uid']]); |
|
346 | - } |
|
345 | + $sth->execute([$_SESSION['uid']]); |
|
346 | + } |
|
347 | 347 | |
348 | - private function process_category_order(&$data_map, $item_id, $parent_id = false, $nest_level = 0) { |
|
348 | + private function process_category_order(&$data_map, $item_id, $parent_id = false, $nest_level = 0) { |
|
349 | 349 | |
350 | - $prefix = ""; |
|
351 | - for ($i = 0; $i < $nest_level; $i++) { |
|
352 | - $prefix .= " "; |
|
353 | - } |
|
350 | + $prefix = ""; |
|
351 | + for ($i = 0; $i < $nest_level; $i++) { |
|
352 | + $prefix .= " "; |
|
353 | + } |
|
354 | 354 | |
355 | - Debug::log("$prefix C: $item_id P: $parent_id"); |
|
355 | + Debug::log("$prefix C: $item_id P: $parent_id"); |
|
356 | 356 | |
357 | - $bare_item_id = substr($item_id, strpos($item_id, ':') + 1); |
|
357 | + $bare_item_id = substr($item_id, strpos($item_id, ':') + 1); |
|
358 | 358 | |
359 | - if ($item_id != 'root') { |
|
360 | - if ($parent_id && $parent_id != 'root') { |
|
361 | - $parent_bare_id = substr($parent_id, strpos($parent_id, ':') + 1); |
|
362 | - $parent_qpart = $parent_bare_id; |
|
363 | - } else { |
|
364 | - $parent_qpart = null; |
|
365 | - } |
|
359 | + if ($item_id != 'root') { |
|
360 | + if ($parent_id && $parent_id != 'root') { |
|
361 | + $parent_bare_id = substr($parent_id, strpos($parent_id, ':') + 1); |
|
362 | + $parent_qpart = $parent_bare_id; |
|
363 | + } else { |
|
364 | + $parent_qpart = null; |
|
365 | + } |
|
366 | 366 | |
367 | - $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories |
|
367 | + $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories |
|
368 | 368 | SET parent_cat = ? WHERE id = ? AND |
369 | 369 | owner_uid = ?"); |
370 | - $sth->execute([$parent_qpart, $bare_item_id, $_SESSION['uid']]); |
|
371 | - } |
|
370 | + $sth->execute([$parent_qpart, $bare_item_id, $_SESSION['uid']]); |
|
371 | + } |
|
372 | 372 | |
373 | - $order_id = 1; |
|
373 | + $order_id = 1; |
|
374 | 374 | |
375 | - $cat = $data_map[$item_id]; |
|
375 | + $cat = $data_map[$item_id]; |
|
376 | 376 | |
377 | - if ($cat && is_array($cat)) { |
|
378 | - foreach ($cat as $item) { |
|
379 | - $id = $item['_reference']; |
|
380 | - $bare_id = substr($id, strpos($id, ':') + 1); |
|
377 | + if ($cat && is_array($cat)) { |
|
378 | + foreach ($cat as $item) { |
|
379 | + $id = $item['_reference']; |
|
380 | + $bare_id = substr($id, strpos($id, ':') + 1); |
|
381 | 381 | |
382 | - Debug::log("$prefix [$order_id] $id/$bare_id"); |
|
382 | + Debug::log("$prefix [$order_id] $id/$bare_id"); |
|
383 | 383 | |
384 | - if ($item['_reference']) { |
|
384 | + if ($item['_reference']) { |
|
385 | 385 | |
386 | - if (strpos($id, "FEED") === 0) { |
|
386 | + if (strpos($id, "FEED") === 0) { |
|
387 | 387 | |
388 | - $cat_id = ($item_id != "root") ? $bare_item_id : null; |
|
388 | + $cat_id = ($item_id != "root") ? $bare_item_id : null; |
|
389 | 389 | |
390 | - $sth = $this->pdo->prepare("UPDATE ttrss_feeds |
|
390 | + $sth = $this->pdo->prepare("UPDATE ttrss_feeds |
|
391 | 391 | SET order_id = ?, cat_id = ? |
392 | 392 | WHERE id = ? AND owner_uid = ?"); |
393 | 393 | |
394 | - $sth->execute([$order_id, $cat_id ? $cat_id : null, $bare_id, $_SESSION['uid']]); |
|
394 | + $sth->execute([$order_id, $cat_id ? $cat_id : null, $bare_id, $_SESSION['uid']]); |
|
395 | 395 | |
396 | - } else if (strpos($id, "CAT:") === 0) { |
|
397 | - $this->process_category_order($data_map, $item['_reference'], $item_id, |
|
398 | - $nest_level + 1); |
|
396 | + } else if (strpos($id, "CAT:") === 0) { |
|
397 | + $this->process_category_order($data_map, $item['_reference'], $item_id, |
|
398 | + $nest_level + 1); |
|
399 | 399 | |
400 | - $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories |
|
400 | + $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories |
|
401 | 401 | SET order_id = ? WHERE id = ? AND |
402 | 402 | owner_uid = ?"); |
403 | - $sth->execute([$order_id, $bare_id, $_SESSION['uid']]); |
|
404 | - } |
|
405 | - } |
|
403 | + $sth->execute([$order_id, $bare_id, $_SESSION['uid']]); |
|
404 | + } |
|
405 | + } |
|
406 | 406 | |
407 | - ++$order_id; |
|
408 | - } |
|
409 | - } |
|
410 | - } |
|
407 | + ++$order_id; |
|
408 | + } |
|
409 | + } |
|
410 | + } |
|
411 | 411 | |
412 | - public function savefeedorder() { |
|
413 | - $data = json_decode($_POST['payload'], true); |
|
412 | + public function savefeedorder() { |
|
413 | + $data = json_decode($_POST['payload'], true); |
|
414 | 414 | |
415 | - #file_put_contents("/tmp/saveorder.json", clean($_POST['payload'])); |
|
416 | - #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true); |
|
415 | + #file_put_contents("/tmp/saveorder.json", clean($_POST['payload'])); |
|
416 | + #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true); |
|
417 | 417 | |
418 | - if (!is_array($data['items'])) { |
|
419 | - $data['items'] = json_decode($data['items'], true); |
|
420 | - } |
|
418 | + if (!is_array($data['items'])) { |
|
419 | + $data['items'] = json_decode($data['items'], true); |
|
420 | + } |
|
421 | 421 | |
422 | 422 | # print_r($data['items']); |
423 | 423 | |
424 | - if (is_array($data) && is_array($data['items'])) { |
|
424 | + if (is_array($data) && is_array($data['items'])) { |
|
425 | 425 | # $cat_order_id = 0; |
426 | 426 | |
427 | - $data_map = array(); |
|
428 | - $root_item = false; |
|
427 | + $data_map = array(); |
|
428 | + $root_item = false; |
|
429 | 429 | |
430 | - foreach ($data['items'] as $item) { |
|
430 | + foreach ($data['items'] as $item) { |
|
431 | 431 | |
432 | 432 | # if ($item['id'] != 'root') { |
433 | - if (is_array($item['items'])) { |
|
434 | - if (isset($item['items']['_reference'])) { |
|
435 | - $data_map[$item['id']] = array($item['items']); |
|
436 | - } else { |
|
437 | - $data_map[$item['id']] = $item['items']; |
|
438 | - } |
|
439 | - } |
|
440 | - if ($item['id'] == 'root') { |
|
441 | - $root_item = $item['id']; |
|
442 | - } |
|
443 | - } |
|
444 | - |
|
445 | - $this->process_category_order($data_map, $root_item); |
|
446 | - } |
|
447 | - } |
|
448 | - |
|
449 | - public function removeicon() { |
|
450 | - $feed_id = clean($_REQUEST["feed_id"]); |
|
451 | - |
|
452 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE id = ? AND owner_uid = ?"); |
|
453 | - $sth->execute([$feed_id, $_SESSION['uid']]); |
|
454 | - |
|
455 | - if ($sth->fetch()) { |
|
456 | - @unlink(ICONS_DIR."/$feed_id.ico"); |
|
457 | - |
|
458 | - $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = NULL where id = ?"); |
|
459 | - $sth->execute([$feed_id]); |
|
460 | - } |
|
461 | - } |
|
462 | - |
|
463 | - public function uploadicon() { |
|
464 | - header("Content-type: text/html"); |
|
465 | - |
|
466 | - if (is_uploaded_file($_FILES['icon_file']['tmp_name'])) { |
|
467 | - $tmp_file = tempnam(CACHE_DIR.'/upload', 'icon'); |
|
468 | - |
|
469 | - $result = move_uploaded_file($_FILES['icon_file']['tmp_name'], |
|
470 | - $tmp_file); |
|
471 | - |
|
472 | - if (!$result) { |
|
473 | - return; |
|
474 | - } |
|
475 | - } else { |
|
476 | - return; |
|
477 | - } |
|
433 | + if (is_array($item['items'])) { |
|
434 | + if (isset($item['items']['_reference'])) { |
|
435 | + $data_map[$item['id']] = array($item['items']); |
|
436 | + } else { |
|
437 | + $data_map[$item['id']] = $item['items']; |
|
438 | + } |
|
439 | + } |
|
440 | + if ($item['id'] == 'root') { |
|
441 | + $root_item = $item['id']; |
|
442 | + } |
|
443 | + } |
|
444 | + |
|
445 | + $this->process_category_order($data_map, $root_item); |
|
446 | + } |
|
447 | + } |
|
448 | + |
|
449 | + public function removeicon() { |
|
450 | + $feed_id = clean($_REQUEST["feed_id"]); |
|
451 | + |
|
452 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE id = ? AND owner_uid = ?"); |
|
453 | + $sth->execute([$feed_id, $_SESSION['uid']]); |
|
454 | + |
|
455 | + if ($sth->fetch()) { |
|
456 | + @unlink(ICONS_DIR."/$feed_id.ico"); |
|
457 | + |
|
458 | + $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = NULL where id = ?"); |
|
459 | + $sth->execute([$feed_id]); |
|
460 | + } |
|
461 | + } |
|
462 | + |
|
463 | + public function uploadicon() { |
|
464 | + header("Content-type: text/html"); |
|
465 | + |
|
466 | + if (is_uploaded_file($_FILES['icon_file']['tmp_name'])) { |
|
467 | + $tmp_file = tempnam(CACHE_DIR.'/upload', 'icon'); |
|
468 | + |
|
469 | + $result = move_uploaded_file($_FILES['icon_file']['tmp_name'], |
|
470 | + $tmp_file); |
|
471 | + |
|
472 | + if (!$result) { |
|
473 | + return; |
|
474 | + } |
|
475 | + } else { |
|
476 | + return; |
|
477 | + } |
|
478 | 478 | |
479 | - $icon_file = $tmp_file; |
|
480 | - $feed_id = clean($_REQUEST["feed_id"]); |
|
481 | - $rc = 2; // failed |
|
479 | + $icon_file = $tmp_file; |
|
480 | + $feed_id = clean($_REQUEST["feed_id"]); |
|
481 | + $rc = 2; // failed |
|
482 | 482 | |
483 | - if (is_file($icon_file) && $feed_id) { |
|
484 | - if (filesize($icon_file) < 65535) { |
|
483 | + if (is_file($icon_file) && $feed_id) { |
|
484 | + if (filesize($icon_file) < 65535) { |
|
485 | 485 | |
486 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE id = ? AND owner_uid = ?"); |
|
487 | - $sth->execute([$feed_id, $_SESSION['uid']]); |
|
486 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE id = ? AND owner_uid = ?"); |
|
487 | + $sth->execute([$feed_id, $_SESSION['uid']]); |
|
488 | 488 | |
489 | - if ($sth->fetch()) { |
|
490 | - @unlink(ICONS_DIR."/$feed_id.ico"); |
|
491 | - if (rename($icon_file, ICONS_DIR."/$feed_id.ico")) { |
|
489 | + if ($sth->fetch()) { |
|
490 | + @unlink(ICONS_DIR."/$feed_id.ico"); |
|
491 | + if (rename($icon_file, ICONS_DIR."/$feed_id.ico")) { |
|
492 | 492 | |
493 | - $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = '' WHERE id = ?"); |
|
494 | - $sth->execute([$feed_id]); |
|
493 | + $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = '' WHERE id = ?"); |
|
494 | + $sth->execute([$feed_id]); |
|
495 | 495 | |
496 | - $rc = 0; |
|
497 | - } |
|
498 | - } |
|
499 | - } else { |
|
500 | - $rc = 1; |
|
501 | - } |
|
502 | - } |
|
496 | + $rc = 0; |
|
497 | + } |
|
498 | + } |
|
499 | + } else { |
|
500 | + $rc = 1; |
|
501 | + } |
|
502 | + } |
|
503 | 503 | |
504 | - if (is_file($icon_file)) { |
|
505 | - @unlink($icon_file); |
|
506 | - } |
|
504 | + if (is_file($icon_file)) { |
|
505 | + @unlink($icon_file); |
|
506 | + } |
|
507 | 507 | |
508 | - print $rc; |
|
509 | - return; |
|
510 | - } |
|
508 | + print $rc; |
|
509 | + return; |
|
510 | + } |
|
511 | 511 | |
512 | - public function editfeed() { |
|
513 | - global $purge_intervals; |
|
514 | - global $update_intervals; |
|
512 | + public function editfeed() { |
|
513 | + global $purge_intervals; |
|
514 | + global $update_intervals; |
|
515 | 515 | |
516 | 516 | |
517 | - $feed_id = clean($_REQUEST["id"]); |
|
517 | + $feed_id = clean($_REQUEST["id"]); |
|
518 | 518 | |
519 | - $sth = $this->pdo->prepare("SELECT * FROM ttrss_feeds WHERE id = ? AND |
|
519 | + $sth = $this->pdo->prepare("SELECT * FROM ttrss_feeds WHERE id = ? AND |
|
520 | 520 | owner_uid = ?"); |
521 | - $sth->execute([$feed_id, $_SESSION['uid']]); |
|
521 | + $sth->execute([$feed_id, $_SESSION['uid']]); |
|
522 | 522 | |
523 | - if ($row = $sth->fetch()) { |
|
524 | - print '<div dojoType="dijit.layout.TabContainer" style="height : 450px"> |
|
523 | + if ($row = $sth->fetch()) { |
|
524 | + print '<div dojoType="dijit.layout.TabContainer" style="height : 450px"> |
|
525 | 525 | <div dojoType="dijit.layout.ContentPane" title="'.__('General').'">'; |
526 | 526 | |
527 | - $title = htmlspecialchars($row["title"]); |
|
527 | + $title = htmlspecialchars($row["title"]); |
|
528 | 528 | |
529 | - print_hidden("id", "$feed_id"); |
|
530 | - print_hidden("op", "pref-feeds"); |
|
531 | - print_hidden("method", "editSave"); |
|
529 | + print_hidden("id", "$feed_id"); |
|
530 | + print_hidden("op", "pref-feeds"); |
|
531 | + print_hidden("method", "editSave"); |
|
532 | 532 | |
533 | - print "<header>".__("Feed")."</header>"; |
|
534 | - print "<section>"; |
|
533 | + print "<header>".__("Feed")."</header>"; |
|
534 | + print "<section>"; |
|
535 | 535 | |
536 | - /* Title */ |
|
536 | + /* Title */ |
|
537 | 537 | |
538 | - print "<fieldset>"; |
|
538 | + print "<fieldset>"; |
|
539 | 539 | |
540 | - print "<input dojoType='dijit.form.ValidationTextBox' required='1' |
|
540 | + print "<input dojoType='dijit.form.ValidationTextBox' required='1' |
|
541 | 541 | placeHolder=\"".__("Feed Title")."\" |
542 | 542 | style='font-size : 16px; width: 500px' name='title' value=\"$title\">"; |
543 | 543 | |
544 | - print "</fieldset>"; |
|
544 | + print "</fieldset>"; |
|
545 | 545 | |
546 | - /* Feed URL */ |
|
546 | + /* Feed URL */ |
|
547 | 547 | |
548 | - $feed_url = htmlspecialchars($row["feed_url"]); |
|
548 | + $feed_url = htmlspecialchars($row["feed_url"]); |
|
549 | 549 | |
550 | - print "<fieldset>"; |
|
550 | + print "<fieldset>"; |
|
551 | 551 | |
552 | - print "<label>".__('URL:')."</label> "; |
|
553 | - print "<input dojoType='dijit.form.ValidationTextBox' required='1' |
|
552 | + print "<label>".__('URL:')."</label> "; |
|
553 | + print "<input dojoType='dijit.form.ValidationTextBox' required='1' |
|
554 | 554 | placeHolder=\"".__("Feed URL")."\" |
555 | 555 | regExp='^(http|https)://.*' style='width : 300px' |
556 | 556 | name='feed_url' value=\"$feed_url\">"; |
557 | 557 | |
558 | - $last_error = $row["last_error"]; |
|
558 | + $last_error = $row["last_error"]; |
|
559 | 559 | |
560 | - if ($last_error) { |
|
561 | - print " <i class=\"material-icons\" |
|
560 | + if ($last_error) { |
|
561 | + print " <i class=\"material-icons\" |
|
562 | 562 | title=\"".htmlspecialchars($last_error)."\">error</i>"; |
563 | - } |
|
563 | + } |
|
564 | 564 | |
565 | - print "</fieldset>"; |
|
565 | + print "</fieldset>"; |
|
566 | 566 | |
567 | - /* Category */ |
|
567 | + /* Category */ |
|
568 | 568 | |
569 | - if (get_pref('ENABLE_FEED_CATS')) { |
|
569 | + if (get_pref('ENABLE_FEED_CATS')) { |
|
570 | 570 | |
571 | - $cat_id = $row["cat_id"]; |
|
571 | + $cat_id = $row["cat_id"]; |
|
572 | 572 | |
573 | - print "<fieldset>"; |
|
573 | + print "<fieldset>"; |
|
574 | 574 | |
575 | - print "<label>".__('Place in category:')."</label> "; |
|
575 | + print "<label>".__('Place in category:')."</label> "; |
|
576 | 576 | |
577 | - print_feed_cat_select("cat_id", $cat_id, |
|
578 | - 'dojoType="fox.form.Select"'); |
|
577 | + print_feed_cat_select("cat_id", $cat_id, |
|
578 | + 'dojoType="fox.form.Select"'); |
|
579 | 579 | |
580 | - print "</fieldset>"; |
|
581 | - } |
|
580 | + print "</fieldset>"; |
|
581 | + } |
|
582 | 582 | |
583 | - /* Site URL */ |
|
583 | + /* Site URL */ |
|
584 | 584 | |
585 | - $site_url = htmlspecialchars($row["site_url"]); |
|
585 | + $site_url = htmlspecialchars($row["site_url"]); |
|
586 | 586 | |
587 | - print "<fieldset>"; |
|
587 | + print "<fieldset>"; |
|
588 | 588 | |
589 | - print "<label>".__('Site URL:')."</label> "; |
|
590 | - print "<input dojoType='dijit.form.ValidationTextBox' required='1' |
|
589 | + print "<label>".__('Site URL:')."</label> "; |
|
590 | + print "<input dojoType='dijit.form.ValidationTextBox' required='1' |
|
591 | 591 | placeHolder=\"".__("Site URL")."\" |
592 | 592 | regExp='^(http|https)://.*' style='width : 300px' |
593 | 593 | name='site_url' value=\"$site_url\">"; |
594 | 594 | |
595 | - print "</fieldset>"; |
|
595 | + print "</fieldset>"; |
|
596 | 596 | |
597 | - /* FTS Stemming Language */ |
|
597 | + /* FTS Stemming Language */ |
|
598 | 598 | |
599 | - if (DB_TYPE == "pgsql") { |
|
600 | - $feed_language = $row["feed_language"]; |
|
599 | + if (DB_TYPE == "pgsql") { |
|
600 | + $feed_language = $row["feed_language"]; |
|
601 | 601 | |
602 | - if (!$feed_language) { |
|
603 | - $feed_language = get_pref('DEFAULT_SEARCH_LANGUAGE'); |
|
604 | - } |
|
602 | + if (!$feed_language) { |
|
603 | + $feed_language = get_pref('DEFAULT_SEARCH_LANGUAGE'); |
|
604 | + } |
|
605 | 605 | |
606 | - print "<fieldset>"; |
|
606 | + print "<fieldset>"; |
|
607 | 607 | |
608 | - print "<label>".__('Language:')."</label> "; |
|
609 | - print_select("feed_language", $feed_language, $this::get_ts_languages(), |
|
610 | - 'dojoType="fox.form.Select"'); |
|
608 | + print "<label>".__('Language:')."</label> "; |
|
609 | + print_select("feed_language", $feed_language, $this::get_ts_languages(), |
|
610 | + 'dojoType="fox.form.Select"'); |
|
611 | 611 | |
612 | - print "</fieldset>"; |
|
613 | - } |
|
612 | + print "</fieldset>"; |
|
613 | + } |
|
614 | 614 | |
615 | - print "</section>"; |
|
615 | + print "</section>"; |
|
616 | 616 | |
617 | - print "<header>".__("Update")."</header>"; |
|
618 | - print "<section>"; |
|
617 | + print "<header>".__("Update")."</header>"; |
|
618 | + print "<section>"; |
|
619 | 619 | |
620 | - /* Update Interval */ |
|
620 | + /* Update Interval */ |
|
621 | 621 | |
622 | - $update_interval = $row["update_interval"]; |
|
622 | + $update_interval = $row["update_interval"]; |
|
623 | 623 | |
624 | - print "<fieldset>"; |
|
624 | + print "<fieldset>"; |
|
625 | 625 | |
626 | - print "<label>".__("Interval:")."</label> "; |
|
626 | + print "<label>".__("Interval:")."</label> "; |
|
627 | 627 | |
628 | - print_select_hash("update_interval", $update_interval, $update_intervals, |
|
629 | - 'dojoType="fox.form.Select"'); |
|
628 | + print_select_hash("update_interval", $update_interval, $update_intervals, |
|
629 | + 'dojoType="fox.form.Select"'); |
|
630 | 630 | |
631 | - print "</fieldset>"; |
|
631 | + print "</fieldset>"; |
|
632 | 632 | |
633 | - /* Purge intl */ |
|
633 | + /* Purge intl */ |
|
634 | 634 | |
635 | - $purge_interval = $row["purge_interval"]; |
|
635 | + $purge_interval = $row["purge_interval"]; |
|
636 | 636 | |
637 | - print "<fieldset>"; |
|
637 | + print "<fieldset>"; |
|
638 | 638 | |
639 | - print "<label>".__('Article purging:')."</label> "; |
|
639 | + print "<label>".__('Article purging:')."</label> "; |
|
640 | 640 | |
641 | - print_select_hash("purge_interval", $purge_interval, $purge_intervals, |
|
642 | - 'dojoType="fox.form.Select" '. |
|
643 | - ((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"')); |
|
641 | + print_select_hash("purge_interval", $purge_interval, $purge_intervals, |
|
642 | + 'dojoType="fox.form.Select" '. |
|
643 | + ((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"')); |
|
644 | 644 | |
645 | - print "</fieldset>"; |
|
645 | + print "</fieldset>"; |
|
646 | 646 | |
647 | - print "</section>"; |
|
647 | + print "</section>"; |
|
648 | 648 | |
649 | - $auth_login = htmlspecialchars($row["auth_login"]); |
|
650 | - $auth_pass = htmlspecialchars($row["auth_pass"]); |
|
649 | + $auth_login = htmlspecialchars($row["auth_login"]); |
|
650 | + $auth_pass = htmlspecialchars($row["auth_pass"]); |
|
651 | 651 | |
652 | - $auth_enabled = $auth_login !== '' || $auth_pass !== ''; |
|
652 | + $auth_enabled = $auth_login !== '' || $auth_pass !== ''; |
|
653 | 653 | |
654 | - $auth_style = $auth_enabled ? '' : 'display: none'; |
|
655 | - print "<div id='feedEditDlg_loginContainer' style='$auth_style'>"; |
|
656 | - print "<header>".__("Authentication")."</header>"; |
|
657 | - print "<section>"; |
|
654 | + $auth_style = $auth_enabled ? '' : 'display: none'; |
|
655 | + print "<div id='feedEditDlg_loginContainer' style='$auth_style'>"; |
|
656 | + print "<header>".__("Authentication")."</header>"; |
|
657 | + print "<section>"; |
|
658 | 658 | |
659 | - print "<fieldset>"; |
|
659 | + print "<fieldset>"; |
|
660 | 660 | |
661 | - print "<input dojoType='dijit.form.TextBox' id='feedEditDlg_login' |
|
661 | + print "<input dojoType='dijit.form.TextBox' id='feedEditDlg_login' |
|
662 | 662 | placeHolder='".__("Login")."' |
663 | 663 | autocomplete='new-password' |
664 | 664 | name='auth_login' value=\"$auth_login\">"; |
665 | 665 | |
666 | - print "</fieldset><fieldset>"; |
|
666 | + print "</fieldset><fieldset>"; |
|
667 | 667 | |
668 | - print "<input dojoType='dijit.form.TextBox' type='password' name='auth_pass' |
|
668 | + print "<input dojoType='dijit.form.TextBox' type='password' name='auth_pass' |
|
669 | 669 | autocomplete='new-password' |
670 | 670 | placeHolder='".__("Password")."' |
671 | 671 | value=\"$auth_pass\">"; |
672 | 672 | |
673 | - print "<div dojoType='dijit.Tooltip' connectId='feedEditDlg_login' position='below'> |
|
673 | + print "<div dojoType='dijit.Tooltip' connectId='feedEditDlg_login' position='below'> |
|
674 | 674 | ".__('<b>Hint:</b> you need to fill in your login information if your feed requires authentication, except for Twitter feeds.')." |
675 | 675 | </div>"; |
676 | 676 | |
677 | - print "</fieldset>"; |
|
677 | + print "</fieldset>"; |
|
678 | 678 | |
679 | - print "</section></div>"; |
|
679 | + print "</section></div>"; |
|
680 | 680 | |
681 | - $auth_checked = $auth_enabled ? 'checked' : ''; |
|
682 | - print "<label class='checkbox'> |
|
681 | + $auth_checked = $auth_enabled ? 'checked' : ''; |
|
682 | + print "<label class='checkbox'> |
|
683 | 683 | <input type='checkbox' $auth_checked name='need_auth' dojoType='dijit.form.CheckBox' id='feedEditDlg_loginCheck' |
684 | 684 | onclick='displayIfChecked(this, \"feedEditDlg_loginContainer\")'> |
685 | 685 | ".__('This feed requires authentication.')."</label>"; |
686 | 686 | |
687 | - print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Options').'">'; |
|
687 | + print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Options').'">'; |
|
688 | 688 | |
689 | - print "<section class='narrow'>"; |
|
689 | + print "<section class='narrow'>"; |
|
690 | 690 | |
691 | - $include_in_digest = $row["include_in_digest"]; |
|
691 | + $include_in_digest = $row["include_in_digest"]; |
|
692 | 692 | |
693 | - if ($include_in_digest) { |
|
694 | - $checked = "checked=\"1\""; |
|
695 | - } else { |
|
696 | - $checked = ""; |
|
697 | - } |
|
693 | + if ($include_in_digest) { |
|
694 | + $checked = "checked=\"1\""; |
|
695 | + } else { |
|
696 | + $checked = ""; |
|
697 | + } |
|
698 | 698 | |
699 | - print "<fieldset class='narrow'>"; |
|
699 | + print "<fieldset class='narrow'>"; |
|
700 | 700 | |
701 | - print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"include_in_digest\" |
|
701 | + print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"include_in_digest\" |
|
702 | 702 | name=\"include_in_digest\" |
703 | 703 | $checked> ".__('Include in e-mail digest')."</label>"; |
704 | 704 | |
705 | - print "</fieldset>"; |
|
705 | + print "</fieldset>"; |
|
706 | 706 | |
707 | - $always_display_enclosures = $row["always_display_enclosures"]; |
|
707 | + $always_display_enclosures = $row["always_display_enclosures"]; |
|
708 | 708 | |
709 | - if ($always_display_enclosures) { |
|
710 | - $checked = "checked"; |
|
711 | - } else { |
|
712 | - $checked = ""; |
|
713 | - } |
|
709 | + if ($always_display_enclosures) { |
|
710 | + $checked = "checked"; |
|
711 | + } else { |
|
712 | + $checked = ""; |
|
713 | + } |
|
714 | 714 | |
715 | - print "<fieldset class='narrow'>"; |
|
715 | + print "<fieldset class='narrow'>"; |
|
716 | 716 | |
717 | - print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"always_display_enclosures\" |
|
717 | + print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"always_display_enclosures\" |
|
718 | 718 | name=\"always_display_enclosures\" |
719 | 719 | $checked> ".__('Always display image attachments')."</label>"; |
720 | 720 | |
721 | - print "</fieldset>"; |
|
721 | + print "</fieldset>"; |
|
722 | 722 | |
723 | - $hide_images = $row["hide_images"]; |
|
723 | + $hide_images = $row["hide_images"]; |
|
724 | 724 | |
725 | - if ($hide_images) { |
|
726 | - $checked = "checked=\"1\""; |
|
727 | - } else { |
|
728 | - $checked = ""; |
|
729 | - } |
|
725 | + if ($hide_images) { |
|
726 | + $checked = "checked=\"1\""; |
|
727 | + } else { |
|
728 | + $checked = ""; |
|
729 | + } |
|
730 | 730 | |
731 | - print "<fieldset class='narrow'>"; |
|
731 | + print "<fieldset class='narrow'>"; |
|
732 | 732 | |
733 | - print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' id='hide_images' |
|
733 | + print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' id='hide_images' |
|
734 | 734 | name='hide_images' $checked> ".__('Do not embed media')."</label>"; |
735 | 735 | |
736 | - print "</fieldset>"; |
|
736 | + print "</fieldset>"; |
|
737 | 737 | |
738 | - $cache_images = $row["cache_images"]; |
|
738 | + $cache_images = $row["cache_images"]; |
|
739 | 739 | |
740 | - if ($cache_images) { |
|
741 | - $checked = "checked=\"1\""; |
|
742 | - } else { |
|
743 | - $checked = ""; |
|
744 | - } |
|
740 | + if ($cache_images) { |
|
741 | + $checked = "checked=\"1\""; |
|
742 | + } else { |
|
743 | + $checked = ""; |
|
744 | + } |
|
745 | 745 | |
746 | - print "<fieldset class='narrow'>"; |
|
746 | + print "<fieldset class='narrow'>"; |
|
747 | 747 | |
748 | - print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' id='cache_images' |
|
748 | + print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' id='cache_images' |
|
749 | 749 | name='cache_images' $checked> ".__('Cache media')."</label>"; |
750 | 750 | |
751 | - print "</fieldset>"; |
|
751 | + print "</fieldset>"; |
|
752 | 752 | |
753 | - $mark_unread_on_update = $row["mark_unread_on_update"]; |
|
753 | + $mark_unread_on_update = $row["mark_unread_on_update"]; |
|
754 | 754 | |
755 | - if ($mark_unread_on_update) { |
|
756 | - $checked = "checked"; |
|
757 | - } else { |
|
758 | - $checked = ""; |
|
759 | - } |
|
755 | + if ($mark_unread_on_update) { |
|
756 | + $checked = "checked"; |
|
757 | + } else { |
|
758 | + $checked = ""; |
|
759 | + } |
|
760 | 760 | |
761 | - print "<fieldset class='narrow'>"; |
|
761 | + print "<fieldset class='narrow'>"; |
|
762 | 762 | |
763 | - print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' id='mark_unread_on_update' |
|
763 | + print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' id='mark_unread_on_update' |
|
764 | 764 | name='mark_unread_on_update' $checked> ".__('Mark updated articles as unread')."</label>"; |
765 | 765 | |
766 | - print "</fieldset>"; |
|
766 | + print "</fieldset>"; |
|
767 | 767 | |
768 | - print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Icon').'">'; |
|
768 | + print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Icon').'">'; |
|
769 | 769 | |
770 | - /* Icon */ |
|
770 | + /* Icon */ |
|
771 | 771 | |
772 | - print "<img class='feedIcon feed-editor-icon' src=\"".Feeds::getFeedIcon($feed_id)."\">"; |
|
772 | + print "<img class='feedIcon feed-editor-icon' src=\"".Feeds::getFeedIcon($feed_id)."\">"; |
|
773 | 773 | |
774 | - print "<form onsubmit='return false;' id='feed_icon_upload_form' |
|
774 | + print "<form onsubmit='return false;' id='feed_icon_upload_form' |
|
775 | 775 | enctype='multipart/form-data' method='POST'> |
776 | 776 | <label class='dijitButton'>".__("Choose file...")." |
777 | 777 | <input style='display: none' id='icon_file' size='10' name='icon_file' type='file'> |
@@ -785,231 +785,231 @@ discard block |
||
785 | 785 | type='submit'>".__('Remove')."</button> |
786 | 786 | </form>"; |
787 | 787 | |
788 | - print "</section>"; |
|
788 | + print "</section>"; |
|
789 | 789 | |
790 | - print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Plugins').'">'; |
|
790 | + print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Plugins').'">'; |
|
791 | 791 | |
792 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED, |
|
793 | - "hook_prefs_edit_feed", $feed_id); |
|
792 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED, |
|
793 | + "hook_prefs_edit_feed", $feed_id); |
|
794 | 794 | |
795 | - print "</div></div>"; |
|
795 | + print "</div></div>"; |
|
796 | 796 | |
797 | - $title = htmlspecialchars($title, ENT_QUOTES); |
|
797 | + $title = htmlspecialchars($title, ENT_QUOTES); |
|
798 | 798 | |
799 | - print "<footer> |
|
799 | + print "<footer> |
|
800 | 800 | <button style='float : left' class='alt-danger' dojoType='dijit.form.Button' onclick='return CommonDialogs.unsubscribeFeed($feed_id, \"$title\")'>". |
801 | - __('Unsubscribe')."</button> |
|
801 | + __('Unsubscribe')."</button> |
|
802 | 802 | <button dojoType='dijit.form.Button' class='alt-primary' onclick=\"return dijit.byId('feedEditDlg').execute()\">".__('Save')."</button> |
803 | 803 | <button dojoType='dijit.form.Button' onclick=\"return dijit.byId('feedEditDlg').hide()\">".__('Cancel')."</button> |
804 | 804 | </footer>"; |
805 | - } |
|
806 | - } |
|
805 | + } |
|
806 | + } |
|
807 | 807 | |
808 | - public function editfeeds() { |
|
809 | - global $purge_intervals; |
|
810 | - global $update_intervals; |
|
808 | + public function editfeeds() { |
|
809 | + global $purge_intervals; |
|
810 | + global $update_intervals; |
|
811 | 811 | |
812 | - $feed_ids = clean($_REQUEST["ids"]); |
|
812 | + $feed_ids = clean($_REQUEST["ids"]); |
|
813 | 813 | |
814 | - print_notice("Enable the options you wish to apply using checkboxes on the right:"); |
|
814 | + print_notice("Enable the options you wish to apply using checkboxes on the right:"); |
|
815 | 815 | |
816 | - print "<p>"; |
|
816 | + print "<p>"; |
|
817 | 817 | |
818 | - print_hidden("ids", "$feed_ids"); |
|
819 | - print_hidden("op", "pref-feeds"); |
|
820 | - print_hidden("method", "batchEditSave"); |
|
818 | + print_hidden("ids", "$feed_ids"); |
|
819 | + print_hidden("op", "pref-feeds"); |
|
820 | + print_hidden("method", "batchEditSave"); |
|
821 | 821 | |
822 | - print "<header>".__("Feed")."</header>"; |
|
823 | - print "<section>"; |
|
822 | + print "<header>".__("Feed")."</header>"; |
|
823 | + print "<section>"; |
|
824 | 824 | |
825 | - /* Category */ |
|
825 | + /* Category */ |
|
826 | 826 | |
827 | - if (get_pref('ENABLE_FEED_CATS')) { |
|
827 | + if (get_pref('ENABLE_FEED_CATS')) { |
|
828 | 828 | |
829 | - print "<fieldset>"; |
|
829 | + print "<fieldset>"; |
|
830 | 830 | |
831 | - print "<label>".__('Place in category:')."</label> "; |
|
831 | + print "<label>".__('Place in category:')."</label> "; |
|
832 | 832 | |
833 | - print_feed_cat_select("cat_id", false, |
|
834 | - 'disabled="1" dojoType="fox.form.Select"'); |
|
833 | + print_feed_cat_select("cat_id", false, |
|
834 | + 'disabled="1" dojoType="fox.form.Select"'); |
|
835 | 835 | |
836 | - $this->batch_edit_cbox("cat_id"); |
|
836 | + $this->batch_edit_cbox("cat_id"); |
|
837 | 837 | |
838 | - print "</fieldset>"; |
|
839 | - } |
|
838 | + print "</fieldset>"; |
|
839 | + } |
|
840 | 840 | |
841 | - /* FTS Stemming Language */ |
|
841 | + /* FTS Stemming Language */ |
|
842 | 842 | |
843 | - if (DB_TYPE == "pgsql") { |
|
844 | - print "<fieldset>"; |
|
843 | + if (DB_TYPE == "pgsql") { |
|
844 | + print "<fieldset>"; |
|
845 | 845 | |
846 | - print "<label>".__('Language:')."</label> "; |
|
847 | - print_select("feed_language", "", $this::get_ts_languages(), |
|
848 | - 'disabled="1" dojoType="fox.form.Select"'); |
|
846 | + print "<label>".__('Language:')."</label> "; |
|
847 | + print_select("feed_language", "", $this::get_ts_languages(), |
|
848 | + 'disabled="1" dojoType="fox.form.Select"'); |
|
849 | 849 | |
850 | - $this->batch_edit_cbox("feed_language"); |
|
850 | + $this->batch_edit_cbox("feed_language"); |
|
851 | 851 | |
852 | - print "</fieldset>"; |
|
853 | - } |
|
852 | + print "</fieldset>"; |
|
853 | + } |
|
854 | 854 | |
855 | - print "</section>"; |
|
855 | + print "</section>"; |
|
856 | 856 | |
857 | - print "<header>".__("Update")."</header>"; |
|
858 | - print "<section>"; |
|
857 | + print "<header>".__("Update")."</header>"; |
|
858 | + print "<section>"; |
|
859 | 859 | |
860 | - /* Update Interval */ |
|
860 | + /* Update Interval */ |
|
861 | 861 | |
862 | - print "<fieldset>"; |
|
862 | + print "<fieldset>"; |
|
863 | 863 | |
864 | - print "<label>".__("Interval:")."</label> "; |
|
864 | + print "<label>".__("Interval:")."</label> "; |
|
865 | 865 | |
866 | - print_select_hash("update_interval", "", $update_intervals, |
|
867 | - 'disabled="1" dojoType="fox.form.Select"'); |
|
866 | + print_select_hash("update_interval", "", $update_intervals, |
|
867 | + 'disabled="1" dojoType="fox.form.Select"'); |
|
868 | 868 | |
869 | - $this->batch_edit_cbox("update_interval"); |
|
869 | + $this->batch_edit_cbox("update_interval"); |
|
870 | 870 | |
871 | - print "</fieldset>"; |
|
871 | + print "</fieldset>"; |
|
872 | 872 | |
873 | - /* Purge intl */ |
|
873 | + /* Purge intl */ |
|
874 | 874 | |
875 | - if (FORCE_ARTICLE_PURGE == 0) { |
|
875 | + if (FORCE_ARTICLE_PURGE == 0) { |
|
876 | 876 | |
877 | - print "<fieldset>"; |
|
877 | + print "<fieldset>"; |
|
878 | 878 | |
879 | - print "<label>".__('Article purging:')."</label> "; |
|
879 | + print "<label>".__('Article purging:')."</label> "; |
|
880 | 880 | |
881 | - print_select_hash("purge_interval", "", $purge_intervals, |
|
882 | - 'disabled="1" dojoType="fox.form.Select"'); |
|
881 | + print_select_hash("purge_interval", "", $purge_intervals, |
|
882 | + 'disabled="1" dojoType="fox.form.Select"'); |
|
883 | 883 | |
884 | - $this->batch_edit_cbox("purge_interval"); |
|
884 | + $this->batch_edit_cbox("purge_interval"); |
|
885 | 885 | |
886 | - print "</fieldset>"; |
|
887 | - } |
|
886 | + print "</fieldset>"; |
|
887 | + } |
|
888 | 888 | |
889 | - print "</section>"; |
|
890 | - print "<header>".__("Authentication")."</header>"; |
|
891 | - print "<section>"; |
|
889 | + print "</section>"; |
|
890 | + print "<header>".__("Authentication")."</header>"; |
|
891 | + print "<section>"; |
|
892 | 892 | |
893 | - print "<fieldset>"; |
|
893 | + print "<fieldset>"; |
|
894 | 894 | |
895 | - print "<input dojoType='dijit.form.TextBox' |
|
895 | + print "<input dojoType='dijit.form.TextBox' |
|
896 | 896 | placeHolder=\"".__("Login")."\" disabled='1' |
897 | 897 | autocomplete='new-password' |
898 | 898 | name='auth_login' value=''>"; |
899 | 899 | |
900 | - $this->batch_edit_cbox("auth_login"); |
|
900 | + $this->batch_edit_cbox("auth_login"); |
|
901 | 901 | |
902 | - print "<input dojoType='dijit.form.TextBox' type='password' name='auth_pass' |
|
902 | + print "<input dojoType='dijit.form.TextBox' type='password' name='auth_pass' |
|
903 | 903 | autocomplete='new-password' |
904 | 904 | placeHolder=\"".__("Password")."\" disabled='1' |
905 | 905 | value=''>"; |
906 | 906 | |
907 | - $this->batch_edit_cbox("auth_pass"); |
|
907 | + $this->batch_edit_cbox("auth_pass"); |
|
908 | 908 | |
909 | - print "</fieldset>"; |
|
909 | + print "</fieldset>"; |
|
910 | 910 | |
911 | - print "</section>"; |
|
912 | - print "<header>".__("Options")."</header>"; |
|
913 | - print "<section>"; |
|
911 | + print "</section>"; |
|
912 | + print "<header>".__("Options")."</header>"; |
|
913 | + print "<section>"; |
|
914 | 914 | |
915 | - print "<fieldset class='narrow'>"; |
|
916 | - print "<label class='checkbox'><input disabled='1' type='checkbox' id='include_in_digest' |
|
915 | + print "<fieldset class='narrow'>"; |
|
916 | + print "<label class='checkbox'><input disabled='1' type='checkbox' id='include_in_digest' |
|
917 | 917 | name='include_in_digest' dojoType='dijit.form.CheckBox'> ".__('Include in e-mail digest')."</label>"; |
918 | 918 | |
919 | - print " "; $this->batch_edit_cbox("include_in_digest", "include_in_digest_l"); |
|
919 | + print " "; $this->batch_edit_cbox("include_in_digest", "include_in_digest_l"); |
|
920 | 920 | |
921 | - print "</fieldset><fieldset class='narrow'>"; |
|
921 | + print "</fieldset><fieldset class='narrow'>"; |
|
922 | 922 | |
923 | - print "<label class='checkbox'><input disabled='1' type='checkbox' id='always_display_enclosures' |
|
923 | + print "<label class='checkbox'><input disabled='1' type='checkbox' id='always_display_enclosures' |
|
924 | 924 | name='always_display_enclosures' dojoType='dijit.form.CheckBox'> ".__('Always display image attachments')."</label>"; |
925 | 925 | |
926 | - print " "; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l"); |
|
926 | + print " "; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l"); |
|
927 | 927 | |
928 | - print "</fieldset><fieldset class='narrow'>"; |
|
928 | + print "</fieldset><fieldset class='narrow'>"; |
|
929 | 929 | |
930 | - print "<label class='checkbox'><input disabled='1' type='checkbox' id='hide_images' |
|
930 | + print "<label class='checkbox'><input disabled='1' type='checkbox' id='hide_images' |
|
931 | 931 | name='hide_images' dojoType='dijit.form.CheckBox'> ". __('Do not embed media')."</label>"; |
932 | 932 | |
933 | - print " "; $this->batch_edit_cbox("hide_images", "hide_images_l"); |
|
933 | + print " "; $this->batch_edit_cbox("hide_images", "hide_images_l"); |
|
934 | 934 | |
935 | - print "</fieldset><fieldset class='narrow'>"; |
|
935 | + print "</fieldset><fieldset class='narrow'>"; |
|
936 | 936 | |
937 | - print "<label class='checkbox'><input disabled='1' type='checkbox' id='cache_images' |
|
937 | + print "<label class='checkbox'><input disabled='1' type='checkbox' id='cache_images' |
|
938 | 938 | name='cache_images' dojoType='dijit.form.CheckBox'> ".__('Cache media')."</label>"; |
939 | 939 | |
940 | - print " "; $this->batch_edit_cbox("cache_images", "cache_images_l"); |
|
940 | + print " "; $this->batch_edit_cbox("cache_images", "cache_images_l"); |
|
941 | 941 | |
942 | - print "</fieldset><fieldset class='narrow'>"; |
|
942 | + print "</fieldset><fieldset class='narrow'>"; |
|
943 | 943 | |
944 | - print "<label class='checkbox'><input disabled='1' type='checkbox' id='mark_unread_on_update' |
|
944 | + print "<label class='checkbox'><input disabled='1' type='checkbox' id='mark_unread_on_update' |
|
945 | 945 | name='mark_unread_on_update' dojoType='dijit.form.CheckBox'> ".__('Mark updated articles as unread')."</label>"; |
946 | 946 | |
947 | - print " "; $this->batch_edit_cbox("mark_unread_on_update", "mark_unread_on_update_l"); |
|
947 | + print " "; $this->batch_edit_cbox("mark_unread_on_update", "mark_unread_on_update_l"); |
|
948 | 948 | |
949 | - print "</fieldset>"; |
|
949 | + print "</fieldset>"; |
|
950 | 950 | |
951 | - print "</section>"; |
|
951 | + print "</section>"; |
|
952 | 952 | |
953 | - print "<footer> |
|
953 | + print "<footer> |
|
954 | 954 | <button dojoType='dijit.form.Button' type='submit' class='alt-primary' |
955 | 955 | onclick=\"return dijit.byId('feedEditDlg').execute()\">". |
956 | - __('Save')."</button> |
|
956 | + __('Save')."</button> |
|
957 | 957 | <button dojoType='dijit.form.Button' |
958 | 958 | onclick=\"return dijit.byId('feedEditDlg').hide()\">". |
959 | - __('Cancel')."</button> |
|
959 | + __('Cancel')."</button> |
|
960 | 960 | </footer>"; |
961 | 961 | |
962 | - return; |
|
963 | - } |
|
964 | - |
|
965 | - public function batchEditSave() { |
|
966 | - return $this->editsaveops(true); |
|
967 | - } |
|
968 | - |
|
969 | - public function editSave() { |
|
970 | - return $this->editsaveops(false); |
|
971 | - } |
|
972 | - |
|
973 | - public function editsaveops($batch) { |
|
974 | - |
|
975 | - $feed_title = trim(clean($_POST["title"])); |
|
976 | - $feed_url = trim(clean($_POST["feed_url"])); |
|
977 | - $site_url = trim(clean($_POST["site_url"])); |
|
978 | - $upd_intl = (int) clean($_POST["update_interval"]); |
|
979 | - $purge_intl = (int) clean($_POST["purge_interval"]); |
|
980 | - $feed_id = (int) clean($_POST["id"]); /* editSave */ |
|
981 | - $feed_ids = explode(",", clean($_POST["ids"])); /* batchEditSave */ |
|
982 | - $cat_id = (int) clean($_POST["cat_id"]); |
|
983 | - $auth_login = trim(clean($_POST["auth_login"])); |
|
984 | - $auth_pass = trim(clean($_POST["auth_pass"])); |
|
985 | - $private = checkbox_to_sql_bool(clean($_POST["private"])); |
|
986 | - $include_in_digest = checkbox_to_sql_bool( |
|
987 | - clean($_POST["include_in_digest"])); |
|
988 | - $cache_images = checkbox_to_sql_bool( |
|
989 | - clean($_POST["cache_images"])); |
|
990 | - $hide_images = checkbox_to_sql_bool( |
|
991 | - clean($_POST["hide_images"])); |
|
992 | - $always_display_enclosures = checkbox_to_sql_bool( |
|
993 | - clean($_POST["always_display_enclosures"])); |
|
994 | - |
|
995 | - $mark_unread_on_update = checkbox_to_sql_bool( |
|
996 | - clean($_POST["mark_unread_on_update"])); |
|
997 | - |
|
998 | - $feed_language = trim(clean($_POST["feed_language"])); |
|
999 | - |
|
1000 | - if (!$batch) { |
|
1001 | - if (clean($_POST["need_auth"]) !== 'on') { |
|
1002 | - $auth_login = ''; |
|
1003 | - $auth_pass = ''; |
|
1004 | - } |
|
1005 | - |
|
1006 | - /* $sth = $this->pdo->prepare("SELECT feed_url FROM ttrss_feeds WHERE id = ?"); |
|
962 | + return; |
|
963 | + } |
|
964 | + |
|
965 | + public function batchEditSave() { |
|
966 | + return $this->editsaveops(true); |
|
967 | + } |
|
968 | + |
|
969 | + public function editSave() { |
|
970 | + return $this->editsaveops(false); |
|
971 | + } |
|
972 | + |
|
973 | + public function editsaveops($batch) { |
|
974 | + |
|
975 | + $feed_title = trim(clean($_POST["title"])); |
|
976 | + $feed_url = trim(clean($_POST["feed_url"])); |
|
977 | + $site_url = trim(clean($_POST["site_url"])); |
|
978 | + $upd_intl = (int) clean($_POST["update_interval"]); |
|
979 | + $purge_intl = (int) clean($_POST["purge_interval"]); |
|
980 | + $feed_id = (int) clean($_POST["id"]); /* editSave */ |
|
981 | + $feed_ids = explode(",", clean($_POST["ids"])); /* batchEditSave */ |
|
982 | + $cat_id = (int) clean($_POST["cat_id"]); |
|
983 | + $auth_login = trim(clean($_POST["auth_login"])); |
|
984 | + $auth_pass = trim(clean($_POST["auth_pass"])); |
|
985 | + $private = checkbox_to_sql_bool(clean($_POST["private"])); |
|
986 | + $include_in_digest = checkbox_to_sql_bool( |
|
987 | + clean($_POST["include_in_digest"])); |
|
988 | + $cache_images = checkbox_to_sql_bool( |
|
989 | + clean($_POST["cache_images"])); |
|
990 | + $hide_images = checkbox_to_sql_bool( |
|
991 | + clean($_POST["hide_images"])); |
|
992 | + $always_display_enclosures = checkbox_to_sql_bool( |
|
993 | + clean($_POST["always_display_enclosures"])); |
|
994 | + |
|
995 | + $mark_unread_on_update = checkbox_to_sql_bool( |
|
996 | + clean($_POST["mark_unread_on_update"])); |
|
997 | + |
|
998 | + $feed_language = trim(clean($_POST["feed_language"])); |
|
999 | + |
|
1000 | + if (!$batch) { |
|
1001 | + if (clean($_POST["need_auth"]) !== 'on') { |
|
1002 | + $auth_login = ''; |
|
1003 | + $auth_pass = ''; |
|
1004 | + } |
|
1005 | + |
|
1006 | + /* $sth = $this->pdo->prepare("SELECT feed_url FROM ttrss_feeds WHERE id = ?"); |
|
1007 | 1007 | $sth->execute([$feed_id]); |
1008 | 1008 | $row = $sth->fetch();$orig_feed_url = $row["feed_url"]; |
1009 | 1009 | |
1010 | 1010 | $reset_basic_info = $orig_feed_url != $feed_url; */ |
1011 | 1011 | |
1012 | - $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET |
|
1012 | + $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET |
|
1013 | 1013 | cat_id = :cat_id, |
1014 | 1014 | title = :title, |
1015 | 1015 | feed_url = :feed_url, |
@@ -1028,253 +1028,253 @@ discard block |
||
1028 | 1028 | feed_language = :feed_language |
1029 | 1029 | WHERE id = :id AND owner_uid = :uid"); |
1030 | 1030 | |
1031 | - $sth->execute([":title" => $feed_title, |
|
1032 | - ":cat_id" => $cat_id ? $cat_id : null, |
|
1033 | - ":feed_url" => $feed_url, |
|
1034 | - ":site_url" => $site_url, |
|
1035 | - ":upd_intl" => $upd_intl, |
|
1036 | - ":purge_intl" => $purge_intl, |
|
1037 | - ":auth_login" => $auth_login, |
|
1038 | - ":auth_pass" => $auth_pass, |
|
1039 | - ":private" => (int) $private, |
|
1040 | - ":cache_images" => (int) $cache_images, |
|
1041 | - ":hide_images" => (int) $hide_images, |
|
1042 | - ":include_in_digest" => (int) $include_in_digest, |
|
1043 | - ":always_display_enclosures" => (int) $always_display_enclosures, |
|
1044 | - ":mark_unread_on_update" => (int) $mark_unread_on_update, |
|
1045 | - ":feed_language" => $feed_language, |
|
1046 | - ":id" => $feed_id, |
|
1047 | - ":uid" => $_SESSION['uid']]); |
|
1031 | + $sth->execute([":title" => $feed_title, |
|
1032 | + ":cat_id" => $cat_id ? $cat_id : null, |
|
1033 | + ":feed_url" => $feed_url, |
|
1034 | + ":site_url" => $site_url, |
|
1035 | + ":upd_intl" => $upd_intl, |
|
1036 | + ":purge_intl" => $purge_intl, |
|
1037 | + ":auth_login" => $auth_login, |
|
1038 | + ":auth_pass" => $auth_pass, |
|
1039 | + ":private" => (int) $private, |
|
1040 | + ":cache_images" => (int) $cache_images, |
|
1041 | + ":hide_images" => (int) $hide_images, |
|
1042 | + ":include_in_digest" => (int) $include_in_digest, |
|
1043 | + ":always_display_enclosures" => (int) $always_display_enclosures, |
|
1044 | + ":mark_unread_on_update" => (int) $mark_unread_on_update, |
|
1045 | + ":feed_language" => $feed_language, |
|
1046 | + ":id" => $feed_id, |
|
1047 | + ":uid" => $_SESSION['uid']]); |
|
1048 | 1048 | |
1049 | 1049 | /* if ($reset_basic_info) { |
1050 | 1050 | RSSUtils::set_basic_feed_info($feed_id); |
1051 | 1051 | } */ |
1052 | 1052 | |
1053 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_SAVE_FEED, |
|
1054 | - "hook_prefs_save_feed", $feed_id); |
|
1053 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_SAVE_FEED, |
|
1054 | + "hook_prefs_save_feed", $feed_id); |
|
1055 | 1055 | |
1056 | - } else { |
|
1057 | - $feed_data = array(); |
|
1056 | + } else { |
|
1057 | + $feed_data = array(); |
|
1058 | 1058 | |
1059 | - foreach (array_keys($_POST) as $k) { |
|
1060 | - if ($k != "op" && $k != "method" && $k != "ids") { |
|
1061 | - $feed_data[$k] = clean($_POST[$k]); |
|
1062 | - } |
|
1063 | - } |
|
1059 | + foreach (array_keys($_POST) as $k) { |
|
1060 | + if ($k != "op" && $k != "method" && $k != "ids") { |
|
1061 | + $feed_data[$k] = clean($_POST[$k]); |
|
1062 | + } |
|
1063 | + } |
|
1064 | 1064 | |
1065 | - $this->pdo->beginTransaction(); |
|
1065 | + $this->pdo->beginTransaction(); |
|
1066 | 1066 | |
1067 | - $feed_ids_qmarks = arr_qmarks($feed_ids); |
|
1067 | + $feed_ids_qmarks = arr_qmarks($feed_ids); |
|
1068 | 1068 | |
1069 | - foreach (array_keys($feed_data) as $k) { |
|
1069 | + foreach (array_keys($feed_data) as $k) { |
|
1070 | 1070 | |
1071 | - $qpart = ""; |
|
1071 | + $qpart = ""; |
|
1072 | 1072 | |
1073 | - switch ($k) { |
|
1074 | - case "title": |
|
1075 | - $qpart = "title = ".$this->pdo->quote($feed_title); |
|
1076 | - break; |
|
1073 | + switch ($k) { |
|
1074 | + case "title": |
|
1075 | + $qpart = "title = ".$this->pdo->quote($feed_title); |
|
1076 | + break; |
|
1077 | 1077 | |
1078 | - case "feed_url": |
|
1079 | - $qpart = "feed_url = ".$this->pdo->quote($feed_url); |
|
1080 | - break; |
|
1078 | + case "feed_url": |
|
1079 | + $qpart = "feed_url = ".$this->pdo->quote($feed_url); |
|
1080 | + break; |
|
1081 | 1081 | |
1082 | - case "update_interval": |
|
1083 | - $qpart = "update_interval = ".$this->pdo->quote($upd_intl); |
|
1084 | - break; |
|
1082 | + case "update_interval": |
|
1083 | + $qpart = "update_interval = ".$this->pdo->quote($upd_intl); |
|
1084 | + break; |
|
1085 | 1085 | |
1086 | - case "purge_interval": |
|
1087 | - $qpart = "purge_interval =".$this->pdo->quote($purge_intl); |
|
1088 | - break; |
|
1086 | + case "purge_interval": |
|
1087 | + $qpart = "purge_interval =".$this->pdo->quote($purge_intl); |
|
1088 | + break; |
|
1089 | 1089 | |
1090 | - case "auth_login": |
|
1091 | - $qpart = "auth_login = ".$this->pdo->quote($auth_login); |
|
1092 | - break; |
|
1090 | + case "auth_login": |
|
1091 | + $qpart = "auth_login = ".$this->pdo->quote($auth_login); |
|
1092 | + break; |
|
1093 | 1093 | |
1094 | - case "auth_pass": |
|
1095 | - $qpart = "auth_pass =".$this->pdo->quote($auth_pass).", auth_pass_encrypted = false"; |
|
1096 | - break; |
|
1094 | + case "auth_pass": |
|
1095 | + $qpart = "auth_pass =".$this->pdo->quote($auth_pass).", auth_pass_encrypted = false"; |
|
1096 | + break; |
|
1097 | 1097 | |
1098 | - case "private": |
|
1099 | - $qpart = "private = ".$this->pdo->quote($private); |
|
1100 | - break; |
|
1098 | + case "private": |
|
1099 | + $qpart = "private = ".$this->pdo->quote($private); |
|
1100 | + break; |
|
1101 | 1101 | |
1102 | - case "include_in_digest": |
|
1103 | - $qpart = "include_in_digest = ".$this->pdo->quote($include_in_digest); |
|
1104 | - break; |
|
1102 | + case "include_in_digest": |
|
1103 | + $qpart = "include_in_digest = ".$this->pdo->quote($include_in_digest); |
|
1104 | + break; |
|
1105 | 1105 | |
1106 | - case "always_display_enclosures": |
|
1107 | - $qpart = "always_display_enclosures = ".$this->pdo->quote($always_display_enclosures); |
|
1108 | - break; |
|
1106 | + case "always_display_enclosures": |
|
1107 | + $qpart = "always_display_enclosures = ".$this->pdo->quote($always_display_enclosures); |
|
1108 | + break; |
|
1109 | 1109 | |
1110 | - case "mark_unread_on_update": |
|
1111 | - $qpart = "mark_unread_on_update = ".$this->pdo->quote($mark_unread_on_update); |
|
1112 | - break; |
|
1110 | + case "mark_unread_on_update": |
|
1111 | + $qpart = "mark_unread_on_update = ".$this->pdo->quote($mark_unread_on_update); |
|
1112 | + break; |
|
1113 | 1113 | |
1114 | - case "cache_images": |
|
1115 | - $qpart = "cache_images = ".$this->pdo->quote($cache_images); |
|
1116 | - break; |
|
1114 | + case "cache_images": |
|
1115 | + $qpart = "cache_images = ".$this->pdo->quote($cache_images); |
|
1116 | + break; |
|
1117 | 1117 | |
1118 | - case "hide_images": |
|
1119 | - $qpart = "hide_images = ".$this->pdo->quote($hide_images); |
|
1120 | - break; |
|
1118 | + case "hide_images": |
|
1119 | + $qpart = "hide_images = ".$this->pdo->quote($hide_images); |
|
1120 | + break; |
|
1121 | 1121 | |
1122 | - case "cat_id": |
|
1123 | - if (get_pref('ENABLE_FEED_CATS')) { |
|
1124 | - if ($cat_id) { |
|
1125 | - $qpart = "cat_id = ".$this->pdo->quote($cat_id); |
|
1126 | - } else { |
|
1127 | - $qpart = 'cat_id = NULL'; |
|
1128 | - } |
|
1129 | - } else { |
|
1130 | - $qpart = ""; |
|
1131 | - } |
|
1122 | + case "cat_id": |
|
1123 | + if (get_pref('ENABLE_FEED_CATS')) { |
|
1124 | + if ($cat_id) { |
|
1125 | + $qpart = "cat_id = ".$this->pdo->quote($cat_id); |
|
1126 | + } else { |
|
1127 | + $qpart = 'cat_id = NULL'; |
|
1128 | + } |
|
1129 | + } else { |
|
1130 | + $qpart = ""; |
|
1131 | + } |
|
1132 | 1132 | |
1133 | - break; |
|
1133 | + break; |
|
1134 | 1134 | |
1135 | - case "feed_language": |
|
1136 | - $qpart = "feed_language = ".$this->pdo->quote($feed_language); |
|
1137 | - break; |
|
1135 | + case "feed_language": |
|
1136 | + $qpart = "feed_language = ".$this->pdo->quote($feed_language); |
|
1137 | + break; |
|
1138 | 1138 | |
1139 | - } |
|
1139 | + } |
|
1140 | 1140 | |
1141 | - if ($qpart) { |
|
1142 | - $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids_qmarks) |
|
1141 | + if ($qpart) { |
|
1142 | + $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids_qmarks) |
|
1143 | 1143 | AND owner_uid = ?"); |
1144 | - $sth->execute(array_merge($feed_ids, [$_SESSION['uid']])); |
|
1145 | - } |
|
1146 | - } |
|
1144 | + $sth->execute(array_merge($feed_ids, [$_SESSION['uid']])); |
|
1145 | + } |
|
1146 | + } |
|
1147 | 1147 | |
1148 | - $this->pdo->commit(); |
|
1149 | - } |
|
1150 | - return; |
|
1151 | - } |
|
1148 | + $this->pdo->commit(); |
|
1149 | + } |
|
1150 | + return; |
|
1151 | + } |
|
1152 | 1152 | |
1153 | - public function remove() { |
|
1153 | + public function remove() { |
|
1154 | 1154 | |
1155 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
1155 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
1156 | 1156 | |
1157 | - foreach ($ids as $id) { |
|
1158 | - Pref_Feeds::remove_feed($id, $_SESSION["uid"]); |
|
1159 | - } |
|
1157 | + foreach ($ids as $id) { |
|
1158 | + Pref_Feeds::remove_feed($id, $_SESSION["uid"]); |
|
1159 | + } |
|
1160 | 1160 | |
1161 | - return; |
|
1162 | - } |
|
1161 | + return; |
|
1162 | + } |
|
1163 | 1163 | |
1164 | - public function removeCat() { |
|
1165 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
1166 | - foreach ($ids as $id) { |
|
1167 | - $this->remove_feed_category($id, $_SESSION["uid"]); |
|
1168 | - } |
|
1169 | - } |
|
1164 | + public function removeCat() { |
|
1165 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
1166 | + foreach ($ids as $id) { |
|
1167 | + $this->remove_feed_category($id, $_SESSION["uid"]); |
|
1168 | + } |
|
1169 | + } |
|
1170 | 1170 | |
1171 | - public function addCat() { |
|
1172 | - $feed_cat = trim(clean($_REQUEST["cat"])); |
|
1171 | + public function addCat() { |
|
1172 | + $feed_cat = trim(clean($_REQUEST["cat"])); |
|
1173 | 1173 | |
1174 | - Feeds::add_feed_category($feed_cat); |
|
1175 | - } |
|
1174 | + Feeds::add_feed_category($feed_cat); |
|
1175 | + } |
|
1176 | 1176 | |
1177 | - public function index() { |
|
1177 | + public function index() { |
|
1178 | 1178 | |
1179 | - print "<div dojoType='dijit.layout.AccordionContainer' region='center'>"; |
|
1180 | - print "<div style='padding : 0px' dojoType='dijit.layout.AccordionPane' |
|
1179 | + print "<div dojoType='dijit.layout.AccordionContainer' region='center'>"; |
|
1180 | + print "<div style='padding : 0px' dojoType='dijit.layout.AccordionPane' |
|
1181 | 1181 | title=\"<i class='material-icons'>rss_feed</i> ".__('Feeds')."\">"; |
1182 | 1182 | |
1183 | - $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_errors |
|
1183 | + $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_errors |
|
1184 | 1184 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?"); |
1185 | - $sth->execute([$_SESSION['uid']]); |
|
1185 | + $sth->execute([$_SESSION['uid']]); |
|
1186 | 1186 | |
1187 | - if ($row = $sth->fetch()) { |
|
1188 | - $num_errors = $row["num_errors"]; |
|
1189 | - } else { |
|
1190 | - $num_errors = 0; |
|
1191 | - } |
|
1187 | + if ($row = $sth->fetch()) { |
|
1188 | + $num_errors = $row["num_errors"]; |
|
1189 | + } else { |
|
1190 | + $num_errors = 0; |
|
1191 | + } |
|
1192 | 1192 | |
1193 | - if ($num_errors > 0) { |
|
1193 | + if ($num_errors > 0) { |
|
1194 | 1194 | |
1195 | - $error_button = "<button dojoType=\"dijit.form.Button\" |
|
1195 | + $error_button = "<button dojoType=\"dijit.form.Button\" |
|
1196 | 1196 | onclick=\"CommonDialogs.showFeedsWithErrors()\" id=\"errorButton\">" . |
1197 | - __("Feeds with errors")."</button>"; |
|
1198 | - } |
|
1197 | + __("Feeds with errors")."</button>"; |
|
1198 | + } |
|
1199 | 1199 | |
1200 | - $inactive_button = "<button dojoType=\"dijit.form.Button\" |
|
1200 | + $inactive_button = "<button dojoType=\"dijit.form.Button\" |
|
1201 | 1201 | id=\"pref_feeds_inactive_btn\" |
1202 | 1202 | style=\"display : none\" |
1203 | 1203 | onclick=\"dijit.byId('feedTree').showInactiveFeeds()\">" . |
1204 | - __("Inactive feeds")."</button>"; |
|
1204 | + __("Inactive feeds")."</button>"; |
|
1205 | 1205 | |
1206 | - $feed_search = clean($_REQUEST["search"]); |
|
1206 | + $feed_search = clean($_REQUEST["search"]); |
|
1207 | 1207 | |
1208 | - if (array_key_exists("search", $_REQUEST)) { |
|
1209 | - $_SESSION["prefs_feed_search"] = $feed_search; |
|
1210 | - } else { |
|
1211 | - $feed_search = $_SESSION["prefs_feed_search"]; |
|
1212 | - } |
|
1208 | + if (array_key_exists("search", $_REQUEST)) { |
|
1209 | + $_SESSION["prefs_feed_search"] = $feed_search; |
|
1210 | + } else { |
|
1211 | + $feed_search = $_SESSION["prefs_feed_search"]; |
|
1212 | + } |
|
1213 | 1213 | |
1214 | - print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; |
|
1214 | + print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; |
|
1215 | 1215 | |
1216 | - print "<div region='top' dojoType=\"fox.Toolbar\">"; #toolbar |
|
1216 | + print "<div region='top' dojoType=\"fox.Toolbar\">"; #toolbar |
|
1217 | 1217 | |
1218 | - print "<div style='float : right; padding-right : 4px;'> |
|
1218 | + print "<div style='float : right; padding-right : 4px;'> |
|
1219 | 1219 | <input dojoType=\"dijit.form.TextBox\" id=\"feed_search\" size=\"20\" type=\"search\" |
1220 | 1220 | value=\"$feed_search\"> |
1221 | 1221 | <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedTree').reload()\">". |
1222 | - __('Search')."</button> |
|
1222 | + __('Search')."</button> |
|
1223 | 1223 | </div>"; |
1224 | 1224 | |
1225 | - print "<div dojoType=\"fox.form.DropDownButton\">". |
|
1226 | - "<span>".__('Select')."</span>"; |
|
1227 | - print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
1228 | - print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(true)\" |
|
1225 | + print "<div dojoType=\"fox.form.DropDownButton\">". |
|
1226 | + "<span>".__('Select')."</span>"; |
|
1227 | + print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
1228 | + print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(true)\" |
|
1229 | 1229 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; |
1230 | - print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(false)\" |
|
1230 | + print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(false)\" |
|
1231 | 1231 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; |
1232 | - print "</div></div>"; |
|
1232 | + print "</div></div>"; |
|
1233 | 1233 | |
1234 | - print "<div dojoType=\"fox.form.DropDownButton\">". |
|
1235 | - "<span>".__('Feeds')."</span>"; |
|
1236 | - print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
1237 | - print "<div onclick=\"CommonDialogs.quickAddFeed()\" |
|
1234 | + print "<div dojoType=\"fox.form.DropDownButton\">". |
|
1235 | + "<span>".__('Feeds')."</span>"; |
|
1236 | + print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
1237 | + print "<div onclick=\"CommonDialogs.quickAddFeed()\" |
|
1238 | 1238 | dojoType=\"dijit.MenuItem\">".__('Subscribe to feed')."</div>"; |
1239 | - print "<div onclick=\"dijit.byId('feedTree').editSelectedFeed()\" |
|
1239 | + print "<div onclick=\"dijit.byId('feedTree').editSelectedFeed()\" |
|
1240 | 1240 | dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>"; |
1241 | - print "<div onclick=\"dijit.byId('feedTree').resetFeedOrder()\" |
|
1241 | + print "<div onclick=\"dijit.byId('feedTree').resetFeedOrder()\" |
|
1242 | 1242 | dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>"; |
1243 | - print "<div onclick=\"dijit.byId('feedTree').batchSubscribe()\" |
|
1243 | + print "<div onclick=\"dijit.byId('feedTree').batchSubscribe()\" |
|
1244 | 1244 | dojoType=\"dijit.MenuItem\">".__('Batch subscribe')."</div>"; |
1245 | - print "<div dojoType=\"dijit.MenuItem\" onclick=\"dijit.byId('feedTree').removeSelectedFeeds()\">" |
|
1246 | - .__('Unsubscribe')."</div> "; |
|
1247 | - print "</div></div>"; |
|
1248 | - |
|
1249 | - if (get_pref('ENABLE_FEED_CATS')) { |
|
1250 | - print "<div dojoType=\"fox.form.DropDownButton\">". |
|
1251 | - "<span>".__('Categories')."</span>"; |
|
1252 | - print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
1253 | - print "<div onclick=\"dijit.byId('feedTree').createCategory()\" |
|
1245 | + print "<div dojoType=\"dijit.MenuItem\" onclick=\"dijit.byId('feedTree').removeSelectedFeeds()\">" |
|
1246 | + .__('Unsubscribe')."</div> "; |
|
1247 | + print "</div></div>"; |
|
1248 | + |
|
1249 | + if (get_pref('ENABLE_FEED_CATS')) { |
|
1250 | + print "<div dojoType=\"fox.form.DropDownButton\">". |
|
1251 | + "<span>".__('Categories')."</span>"; |
|
1252 | + print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
1253 | + print "<div onclick=\"dijit.byId('feedTree').createCategory()\" |
|
1254 | 1254 | dojoType=\"dijit.MenuItem\">".__('Add category')."</div>"; |
1255 | - print "<div onclick=\"dijit.byId('feedTree').resetCatOrder()\" |
|
1255 | + print "<div onclick=\"dijit.byId('feedTree').resetCatOrder()\" |
|
1256 | 1256 | dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>"; |
1257 | - print "<div onclick=\"dijit.byId('feedTree').removeSelectedCategories()\" |
|
1257 | + print "<div onclick=\"dijit.byId('feedTree').removeSelectedCategories()\" |
|
1258 | 1258 | dojoType=\"dijit.MenuItem\">".__('Remove selected')."</div>"; |
1259 | - print "</div></div>"; |
|
1259 | + print "</div></div>"; |
|
1260 | 1260 | |
1261 | - } |
|
1261 | + } |
|
1262 | 1262 | |
1263 | - print $error_button; |
|
1264 | - print $inactive_button; |
|
1263 | + print $error_button; |
|
1264 | + print $inactive_button; |
|
1265 | 1265 | |
1266 | - print "</div>"; # toolbar |
|
1266 | + print "</div>"; # toolbar |
|
1267 | 1267 | |
1268 | - //print '</div>'; |
|
1269 | - print '<div style="padding : 0px" dojoType="dijit.layout.ContentPane" region="center">'; |
|
1268 | + //print '</div>'; |
|
1269 | + print '<div style="padding : 0px" dojoType="dijit.layout.ContentPane" region="center">'; |
|
1270 | 1270 | |
1271 | - print "<div id=\"feedlistLoading\"> |
|
1271 | + print "<div id=\"feedlistLoading\"> |
|
1272 | 1272 | <img src='images/indicator_tiny.gif'>". |
1273 | - __("Loading, please wait...")."</div>"; |
|
1273 | + __("Loading, please wait...")."</div>"; |
|
1274 | 1274 | |
1275 | - $auto_expand = $feed_search != "" ? "true" : "false"; |
|
1275 | + $auto_expand = $feed_search != "" ? "true" : "false"; |
|
1276 | 1276 | |
1277 | - print "<div dojoType=\"fox.PrefFeedStore\" jsId=\"feedStore\" |
|
1277 | + print "<div dojoType=\"fox.PrefFeedStore\" jsId=\"feedStore\" |
|
1278 | 1278 | url=\"backend.php?op=pref-feeds&method=getfeedtree\"> |
1279 | 1279 | </div> |
1280 | 1280 | <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"feedModel\" store=\"feedStore\" |
@@ -1307,23 +1307,23 @@ discard block |
||
1307 | 1307 | # ".__('<b>Hint:</b> you can drag feeds and categories around.')." |
1308 | 1308 | # </div>"; |
1309 | 1309 | |
1310 | - print '</div>'; |
|
1311 | - print '</div>'; |
|
1310 | + print '</div>'; |
|
1311 | + print '</div>'; |
|
1312 | 1312 | |
1313 | - print "</div>"; # feeds pane |
|
1313 | + print "</div>"; # feeds pane |
|
1314 | 1314 | |
1315 | - print "<div dojoType='dijit.layout.AccordionPane' |
|
1315 | + print "<div dojoType='dijit.layout.AccordionPane' |
|
1316 | 1316 | title='<i class=\"material-icons\">import_export</i> ".__('OPML')."'>"; |
1317 | 1317 | |
1318 | - print "<h3>".__("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.")."</h3>"; |
|
1318 | + print "<h3>".__("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.")."</h3>"; |
|
1319 | 1319 | |
1320 | - print_notice("Only main settings profile can be migrated using OPML."); |
|
1320 | + print_notice("Only main settings profile can be migrated using OPML."); |
|
1321 | 1321 | |
1322 | - print "<iframe id=\"upload_iframe\" |
|
1322 | + print "<iframe id=\"upload_iframe\" |
|
1323 | 1323 | name=\"upload_iframe\" onload=\"Helpers.OPML.onImportComplete(this)\" |
1324 | 1324 | style=\"width: 400px; height: 100px; display: none;\"></iframe>"; |
1325 | 1325 | |
1326 | - print "<form name='opml_form' style='display : inline-block' target='upload_iframe' |
|
1326 | + print "<form name='opml_form' style='display : inline-block' target='upload_iframe' |
|
1327 | 1327 | enctype='multipart/form-data' method='POST' |
1328 | 1328 | action='backend.php'> |
1329 | 1329 | <label class='dijitButton'>".__("Choose file...")." |
@@ -1332,118 +1332,118 @@ discard block |
||
1332 | 1332 | <input type='hidden' name='op' value='dlg'> |
1333 | 1333 | <input type='hidden' name='method' value='importOpml'> |
1334 | 1334 | <button dojoType='dijit.form.Button' class='alt-primary' onclick=\"return Helpers.OPML.import();\" type=\"submit\">" . |
1335 | - __('Import OPML')."</button>"; |
|
1335 | + __('Import OPML')."</button>"; |
|
1336 | 1336 | |
1337 | - print "</form>"; |
|
1337 | + print "</form>"; |
|
1338 | 1338 | |
1339 | - print "<form dojoType='dijit.form.Form' id='opmlExportForm' style='display : inline-block'>"; |
|
1339 | + print "<form dojoType='dijit.form.Form' id='opmlExportForm' style='display : inline-block'>"; |
|
1340 | 1340 | |
1341 | - print "<button dojoType='dijit.form.Button' |
|
1341 | + print "<button dojoType='dijit.form.Button' |
|
1342 | 1342 | onclick='Helpers.OPML.export()' >" . |
1343 | - __('Export OPML')."</button>"; |
|
1343 | + __('Export OPML')."</button>"; |
|
1344 | 1344 | |
1345 | - print " <label class='checkbox'>"; |
|
1346 | - print_checkbox("include_settings", true, "1", ""); |
|
1347 | - print " ".__("Include settings"); |
|
1348 | - print "</label>"; |
|
1345 | + print " <label class='checkbox'>"; |
|
1346 | + print_checkbox("include_settings", true, "1", ""); |
|
1347 | + print " ".__("Include settings"); |
|
1348 | + print "</label>"; |
|
1349 | 1349 | |
1350 | - print "</form>"; |
|
1350 | + print "</form>"; |
|
1351 | 1351 | |
1352 | - print "<p/>"; |
|
1352 | + print "<p/>"; |
|
1353 | 1353 | |
1354 | - print "<h2>".__("Published OPML")."</h2>"; |
|
1354 | + print "<h2>".__("Published OPML")."</h2>"; |
|
1355 | 1355 | |
1356 | - print "<p>".__('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.'). |
|
1357 | - " ". |
|
1358 | - __("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.")."</p>"; |
|
1356 | + print "<p>".__('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.'). |
|
1357 | + " ". |
|
1358 | + __("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.")."</p>"; |
|
1359 | 1359 | |
1360 | - print "<button dojoType='dijit.form.Button' class='alt-primary' onclick=\"return App.displayDlg('".__("Public OPML URL")."','pubOPMLUrl')\">". |
|
1361 | - __('Display published OPML URL')."</button> "; |
|
1360 | + print "<button dojoType='dijit.form.Button' class='alt-primary' onclick=\"return App.displayDlg('".__("Public OPML URL")."','pubOPMLUrl')\">". |
|
1361 | + __('Display published OPML URL')."</button> "; |
|
1362 | 1362 | |
1363 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
1364 | - "hook_prefs_tab_section", "prefFeedsOPML"); |
|
1363 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
1364 | + "hook_prefs_tab_section", "prefFeedsOPML"); |
|
1365 | 1365 | |
1366 | - print "</div>"; # pane |
|
1366 | + print "</div>"; # pane |
|
1367 | 1367 | |
1368 | - print "<div dojoType=\"dijit.layout.AccordionPane\" |
|
1368 | + print "<div dojoType=\"dijit.layout.AccordionPane\" |
|
1369 | 1369 | title=\"<i class='material-icons'>share</i> ".__('Published & shared articles / Generated feeds')."\">"; |
1370 | 1370 | |
1371 | - print "<h3>".__('Published articles can be subscribed by anyone who knows the following URL:')."</h3>"; |
|
1371 | + print "<h3>".__('Published articles can be subscribed by anyone who knows the following URL:')."</h3>"; |
|
1372 | 1372 | |
1373 | - $rss_url = '-2::'.htmlspecialchars(get_self_url_prefix(). |
|
1374 | - "/public.php?op=rss&id=-2&view-mode=all_articles"); ; |
|
1373 | + $rss_url = '-2::'.htmlspecialchars(get_self_url_prefix(). |
|
1374 | + "/public.php?op=rss&id=-2&view-mode=all_articles"); ; |
|
1375 | 1375 | |
1376 | - print "<button dojoType='dijit.form.Button' class='alt-primary' onclick=\"return App.displayDlg('".__("Show as feed")."','generatedFeed', '$rss_url')\">". |
|
1377 | - __('Display URL')."</button> "; |
|
1376 | + print "<button dojoType='dijit.form.Button' class='alt-primary' onclick=\"return App.displayDlg('".__("Show as feed")."','generatedFeed', '$rss_url')\">". |
|
1377 | + __('Display URL')."</button> "; |
|
1378 | 1378 | |
1379 | - print "<button class=\"alt-danger\" dojoType=\"dijit.form.Button\" onclick=\"return Helpers.clearFeedAccessKeys()\">". |
|
1380 | - __('Clear all generated URLs')."</button> "; |
|
1379 | + print "<button class=\"alt-danger\" dojoType=\"dijit.form.Button\" onclick=\"return Helpers.clearFeedAccessKeys()\">". |
|
1380 | + __('Clear all generated URLs')."</button> "; |
|
1381 | 1381 | |
1382 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
1383 | - "hook_prefs_tab_section", "prefFeedsPublishedGenerated"); |
|
1382 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
1383 | + "hook_prefs_tab_section", "prefFeedsPublishedGenerated"); |
|
1384 | 1384 | |
1385 | - print "</div>"; #pane |
|
1385 | + print "</div>"; #pane |
|
1386 | 1386 | |
1387 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
|
1388 | - "hook_prefs_tab", "prefFeeds"); |
|
1387 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
|
1388 | + "hook_prefs_tab", "prefFeeds"); |
|
1389 | 1389 | |
1390 | - print "</div>"; #container |
|
1391 | - } |
|
1390 | + print "</div>"; #container |
|
1391 | + } |
|
1392 | 1392 | |
1393 | - private function feedlist_init_cat($cat_id) { |
|
1394 | - $obj = array(); |
|
1395 | - $cat_id = (int) $cat_id; |
|
1393 | + private function feedlist_init_cat($cat_id) { |
|
1394 | + $obj = array(); |
|
1395 | + $cat_id = (int) $cat_id; |
|
1396 | 1396 | |
1397 | - if ($cat_id > 0) { |
|
1398 | - $cat_unread = CCache::find($cat_id, $_SESSION["uid"], true); |
|
1399 | - } else if ($cat_id == 0 || $cat_id == -2) { |
|
1400 | - $cat_unread = Feeds::getCategoryUnread($cat_id); |
|
1401 | - } |
|
1397 | + if ($cat_id > 0) { |
|
1398 | + $cat_unread = CCache::find($cat_id, $_SESSION["uid"], true); |
|
1399 | + } else if ($cat_id == 0 || $cat_id == -2) { |
|
1400 | + $cat_unread = Feeds::getCategoryUnread($cat_id); |
|
1401 | + } |
|
1402 | 1402 | |
1403 | - $obj['id'] = 'CAT:'.$cat_id; |
|
1404 | - $obj['items'] = array(); |
|
1405 | - $obj['name'] = Feeds::getCategoryTitle($cat_id); |
|
1406 | - $obj['type'] = 'category'; |
|
1407 | - $obj['unread'] = (int) $cat_unread; |
|
1408 | - $obj['bare_id'] = $cat_id; |
|
1403 | + $obj['id'] = 'CAT:'.$cat_id; |
|
1404 | + $obj['items'] = array(); |
|
1405 | + $obj['name'] = Feeds::getCategoryTitle($cat_id); |
|
1406 | + $obj['type'] = 'category'; |
|
1407 | + $obj['unread'] = (int) $cat_unread; |
|
1408 | + $obj['bare_id'] = $cat_id; |
|
1409 | 1409 | |
1410 | - return $obj; |
|
1411 | - } |
|
1410 | + return $obj; |
|
1411 | + } |
|
1412 | 1412 | |
1413 | - private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') { |
|
1414 | - $obj = array(); |
|
1415 | - $feed_id = (int) $feed_id; |
|
1413 | + private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') { |
|
1414 | + $obj = array(); |
|
1415 | + $feed_id = (int) $feed_id; |
|
1416 | 1416 | |
1417 | - if (!$title) { |
|
1418 | - $title = Feeds::getFeedTitle($feed_id, false); |
|
1419 | - } |
|
1417 | + if (!$title) { |
|
1418 | + $title = Feeds::getFeedTitle($feed_id, false); |
|
1419 | + } |
|
1420 | 1420 | |
1421 | - if ($unread === false) { |
|
1422 | - $unread = getFeedUnread($feed_id, false); |
|
1423 | - } |
|
1421 | + if ($unread === false) { |
|
1422 | + $unread = getFeedUnread($feed_id, false); |
|
1423 | + } |
|
1424 | 1424 | |
1425 | - $obj['id'] = 'FEED:'.$feed_id; |
|
1426 | - $obj['name'] = $title; |
|
1427 | - $obj['unread'] = (int) $unread; |
|
1428 | - $obj['type'] = 'feed'; |
|
1429 | - $obj['error'] = $error; |
|
1430 | - $obj['updated'] = $updated; |
|
1431 | - $obj['icon'] = Feeds::getFeedIcon($feed_id); |
|
1432 | - $obj['bare_id'] = $feed_id; |
|
1433 | - $obj['auxcounter'] = 0; |
|
1425 | + $obj['id'] = 'FEED:'.$feed_id; |
|
1426 | + $obj['name'] = $title; |
|
1427 | + $obj['unread'] = (int) $unread; |
|
1428 | + $obj['type'] = 'feed'; |
|
1429 | + $obj['error'] = $error; |
|
1430 | + $obj['updated'] = $updated; |
|
1431 | + $obj['icon'] = Feeds::getFeedIcon($feed_id); |
|
1432 | + $obj['bare_id'] = $feed_id; |
|
1433 | + $obj['auxcounter'] = 0; |
|
1434 | 1434 | |
1435 | - return $obj; |
|
1436 | - } |
|
1435 | + return $obj; |
|
1436 | + } |
|
1437 | 1437 | |
1438 | - public function inactiveFeeds() { |
|
1438 | + public function inactiveFeeds() { |
|
1439 | 1439 | |
1440 | - if (DB_TYPE == "pgsql") { |
|
1441 | - $interval_qpart = "NOW() - INTERVAL '3 months'"; |
|
1442 | - } else { |
|
1443 | - $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; |
|
1444 | - } |
|
1440 | + if (DB_TYPE == "pgsql") { |
|
1441 | + $interval_qpart = "NOW() - INTERVAL '3 months'"; |
|
1442 | + } else { |
|
1443 | + $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; |
|
1444 | + } |
|
1445 | 1445 | |
1446 | - $sth = $this->pdo->prepare("SELECT ttrss_feeds.title, ttrss_feeds.site_url, |
|
1446 | + $sth = $this->pdo->prepare("SELECT ttrss_feeds.title, ttrss_feeds.site_url, |
|
1447 | 1447 | ttrss_feeds.feed_url, ttrss_feeds.id, MAX(updated) AS last_article |
1448 | 1448 | FROM ttrss_feeds, ttrss_entries, ttrss_user_entries WHERE |
1449 | 1449 | (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE |
@@ -1454,358 +1454,358 @@ discard block |
||
1454 | 1454 | ttrss_entries.id = ref_id |
1455 | 1455 | GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url |
1456 | 1456 | ORDER BY last_article"); |
1457 | - $sth->execute([$_SESSION['uid']]); |
|
1457 | + $sth->execute([$_SESSION['uid']]); |
|
1458 | 1458 | |
1459 | - print "<div dojoType='fox.Toolbar'>"; |
|
1460 | - print "<div dojoType='fox.form.DropDownButton'>". |
|
1461 | - "<span>".__('Select')."</span>"; |
|
1462 | - print "<div dojoType='dijit.Menu' style='display: none'>"; |
|
1463 | - print "<div onclick=\"Tables.select('inactive-feeds-list', true)\" |
|
1459 | + print "<div dojoType='fox.Toolbar'>"; |
|
1460 | + print "<div dojoType='fox.form.DropDownButton'>". |
|
1461 | + "<span>".__('Select')."</span>"; |
|
1462 | + print "<div dojoType='dijit.Menu' style='display: none'>"; |
|
1463 | + print "<div onclick=\"Tables.select('inactive-feeds-list', true)\" |
|
1464 | 1464 | dojoType='dijit.MenuItem'>".__('All')."</div>"; |
1465 | - print "<div onclick=\"Tables.select('inactive-feeds-list', false)\" |
|
1465 | + print "<div onclick=\"Tables.select('inactive-feeds-list', false)\" |
|
1466 | 1466 | dojoType='dijit.MenuItem'>".__('None')."</div>"; |
1467 | - print "</div></div>"; |
|
1468 | - print "</div>"; #toolbar |
|
1467 | + print "</div></div>"; |
|
1468 | + print "</div>"; #toolbar |
|
1469 | 1469 | |
1470 | - print "<div class='panel panel-scrollable'>"; |
|
1471 | - print "<table width='100%' id='inactive-feeds-list'>"; |
|
1470 | + print "<div class='panel panel-scrollable'>"; |
|
1471 | + print "<table width='100%' id='inactive-feeds-list'>"; |
|
1472 | 1472 | |
1473 | - $lnum = 1; |
|
1473 | + $lnum = 1; |
|
1474 | 1474 | |
1475 | - while ($line = $sth->fetch()) { |
|
1475 | + while ($line = $sth->fetch()) { |
|
1476 | 1476 | |
1477 | - $feed_id = $line["id"]; |
|
1477 | + $feed_id = $line["id"]; |
|
1478 | 1478 | |
1479 | - print "<tr data-row-id='$feed_id'>"; |
|
1479 | + print "<tr data-row-id='$feed_id'>"; |
|
1480 | 1480 | |
1481 | - print "<td width='5%' align='center'><input |
|
1481 | + print "<td width='5%' align='center'><input |
|
1482 | 1482 | onclick='Tables.onRowChecked(this);' dojoType='dijit.form.CheckBox' |
1483 | 1483 | type='checkbox'></td>"; |
1484 | - print "<td>"; |
|
1484 | + print "<td>"; |
|
1485 | 1485 | |
1486 | - print "<a href='#' ". |
|
1487 | - "title=\"".__("Click to edit feed")."\" ". |
|
1488 | - "onclick=\"CommonDialogs.editFeed(".$line["id"].")\">". |
|
1489 | - htmlspecialchars($line["title"])."</a>"; |
|
1486 | + print "<a href='#' ". |
|
1487 | + "title=\"".__("Click to edit feed")."\" ". |
|
1488 | + "onclick=\"CommonDialogs.editFeed(".$line["id"].")\">". |
|
1489 | + htmlspecialchars($line["title"])."</a>"; |
|
1490 | 1490 | |
1491 | - print "</td><td class='text-muted' align='right'>"; |
|
1492 | - print make_local_datetime($line['last_article'], false); |
|
1493 | - print "</td>"; |
|
1494 | - print "</tr>"; |
|
1491 | + print "</td><td class='text-muted' align='right'>"; |
|
1492 | + print make_local_datetime($line['last_article'], false); |
|
1493 | + print "</td>"; |
|
1494 | + print "</tr>"; |
|
1495 | 1495 | |
1496 | - ++$lnum; |
|
1497 | - } |
|
1496 | + ++$lnum; |
|
1497 | + } |
|
1498 | 1498 | |
1499 | - print "</table>"; |
|
1500 | - print "</div>"; |
|
1499 | + print "</table>"; |
|
1500 | + print "</div>"; |
|
1501 | 1501 | |
1502 | - print "<footer> |
|
1502 | + print "<footer> |
|
1503 | 1503 | <button style='float : left' class=\"alt-danger\" dojoType='dijit.form.Button' onclick=\"dijit.byId('inactiveFeedsDlg').removeSelected()\">" |
1504 | - .__('Unsubscribe from selected feeds')."</button> |
|
1504 | + .__('Unsubscribe from selected feeds')."</button> |
|
1505 | 1505 | <button dojoType='dijit.form.Button' onclick=\"dijit.byId('inactiveFeedsDlg').hide()\">" |
1506 | - .__('Close this window')."</button> |
|
1506 | + .__('Close this window')."</button> |
|
1507 | 1507 | </footer>"; |
1508 | 1508 | |
1509 | - } |
|
1509 | + } |
|
1510 | 1510 | |
1511 | - public function feedsWithErrors() { |
|
1512 | - $sth = $this->pdo->prepare("SELECT id,title,feed_url,last_error,site_url |
|
1511 | + public function feedsWithErrors() { |
|
1512 | + $sth = $this->pdo->prepare("SELECT id,title,feed_url,last_error,site_url |
|
1513 | 1513 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?"); |
1514 | - $sth->execute([$_SESSION['uid']]); |
|
1514 | + $sth->execute([$_SESSION['uid']]); |
|
1515 | 1515 | |
1516 | - print "<div dojoType=\"fox.Toolbar\">"; |
|
1517 | - print "<div dojoType=\"fox.form.DropDownButton\">". |
|
1518 | - "<span>".__('Select')."</span>"; |
|
1519 | - print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
1520 | - print "<div onclick=\"Tables.select('error-feeds-list', true)\" |
|
1516 | + print "<div dojoType=\"fox.Toolbar\">"; |
|
1517 | + print "<div dojoType=\"fox.form.DropDownButton\">". |
|
1518 | + "<span>".__('Select')."</span>"; |
|
1519 | + print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
1520 | + print "<div onclick=\"Tables.select('error-feeds-list', true)\" |
|
1521 | 1521 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; |
1522 | - print "<div onclick=\"Tables.select('error-feeds-list', false)\" |
|
1522 | + print "<div onclick=\"Tables.select('error-feeds-list', false)\" |
|
1523 | 1523 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; |
1524 | - print "</div></div>"; |
|
1525 | - print "</div>"; #toolbar |
|
1524 | + print "</div></div>"; |
|
1525 | + print "</div>"; #toolbar |
|
1526 | 1526 | |
1527 | - print "<div class='panel panel-scrollable'>"; |
|
1528 | - print "<table width='100%' id='error-feeds-list'>"; |
|
1527 | + print "<div class='panel panel-scrollable'>"; |
|
1528 | + print "<table width='100%' id='error-feeds-list'>"; |
|
1529 | 1529 | |
1530 | - $lnum = 1; |
|
1530 | + $lnum = 1; |
|
1531 | 1531 | |
1532 | - while ($line = $sth->fetch()) { |
|
1532 | + while ($line = $sth->fetch()) { |
|
1533 | 1533 | |
1534 | - $feed_id = $line["id"]; |
|
1534 | + $feed_id = $line["id"]; |
|
1535 | 1535 | |
1536 | - print "<tr data-row-id='$feed_id'>"; |
|
1536 | + print "<tr data-row-id='$feed_id'>"; |
|
1537 | 1537 | |
1538 | - print "<td width='5%' align='center'><input |
|
1538 | + print "<td width='5%' align='center'><input |
|
1539 | 1539 | onclick='Tables.onRowChecked(this);' dojoType=\"dijit.form.CheckBox\" |
1540 | 1540 | type=\"checkbox\"></td>"; |
1541 | - print "<td>"; |
|
1541 | + print "<td>"; |
|
1542 | 1542 | |
1543 | - print "<a class=\"visibleLink\" href=\"#\" ". |
|
1544 | - "title=\"".__("Click to edit feed")."\" ". |
|
1545 | - "onclick=\"CommonDialogs.editFeed(".$line["id"].")\">". |
|
1546 | - htmlspecialchars($line["title"])."</a>: "; |
|
1543 | + print "<a class=\"visibleLink\" href=\"#\" ". |
|
1544 | + "title=\"".__("Click to edit feed")."\" ". |
|
1545 | + "onclick=\"CommonDialogs.editFeed(".$line["id"].")\">". |
|
1546 | + htmlspecialchars($line["title"])."</a>: "; |
|
1547 | 1547 | |
1548 | - print "<span class=\"text-muted\">"; |
|
1549 | - print htmlspecialchars($line["last_error"]); |
|
1550 | - print "</span>"; |
|
1548 | + print "<span class=\"text-muted\">"; |
|
1549 | + print htmlspecialchars($line["last_error"]); |
|
1550 | + print "</span>"; |
|
1551 | 1551 | |
1552 | - print "</td>"; |
|
1553 | - print "</tr>"; |
|
1552 | + print "</td>"; |
|
1553 | + print "</tr>"; |
|
1554 | 1554 | |
1555 | - ++$lnum; |
|
1556 | - } |
|
1555 | + ++$lnum; |
|
1556 | + } |
|
1557 | 1557 | |
1558 | - print "</table>"; |
|
1559 | - print "</div>"; |
|
1558 | + print "</table>"; |
|
1559 | + print "</div>"; |
|
1560 | 1560 | |
1561 | - print "<footer>"; |
|
1562 | - print "<button style='float : left' class=\"alt-danger\" dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').removeSelected()\">" |
|
1563 | - .__('Unsubscribe from selected feeds')."</button> "; |
|
1561 | + print "<footer>"; |
|
1562 | + print "<button style='float : left' class=\"alt-danger\" dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').removeSelected()\">" |
|
1563 | + .__('Unsubscribe from selected feeds')."</button> "; |
|
1564 | 1564 | |
1565 | - print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').hide()\">". |
|
1566 | - __('Close this window')."</button>"; |
|
1565 | + print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').hide()\">". |
|
1566 | + __('Close this window')."</button>"; |
|
1567 | 1567 | |
1568 | - print "</footer>"; |
|
1569 | - } |
|
1568 | + print "</footer>"; |
|
1569 | + } |
|
1570 | 1570 | |
1571 | - private function remove_feed_category($id, $owner_uid) { |
|
1571 | + private function remove_feed_category($id, $owner_uid) { |
|
1572 | 1572 | |
1573 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_feed_categories |
|
1573 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_feed_categories |
|
1574 | 1574 | WHERE id = ? AND owner_uid = ?"); |
1575 | - $sth->execute([$id, $owner_uid]); |
|
1575 | + $sth->execute([$id, $owner_uid]); |
|
1576 | 1576 | |
1577 | - CCache::remove($id, $owner_uid, true); |
|
1578 | - } |
|
1577 | + CCache::remove($id, $owner_uid, true); |
|
1578 | + } |
|
1579 | 1579 | |
1580 | - public static function remove_feed($id, $owner_uid) { |
|
1581 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_UNSUBSCRIBE_FEED) as $p) { |
|
1582 | - if (!$p->hook_unsubscribe_feed($id, $owner_uid)) { |
|
1580 | + public static function remove_feed($id, $owner_uid) { |
|
1581 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_UNSUBSCRIBE_FEED) as $p) { |
|
1582 | + if (!$p->hook_unsubscribe_feed($id, $owner_uid)) { |
|
1583 | 1583 | user_error("feed $id (owner: $owner_uid) not removed due to plugin error (HOOK_UNSUBSCRIBE_FEED).", E_USER_WARNING); |
1584 | 1584 | return; |
1585 | - } |
|
1586 | - } |
|
1585 | + } |
|
1586 | + } |
|
1587 | 1587 | |
1588 | - $pdo = Db::pdo(); |
|
1588 | + $pdo = Db::pdo(); |
|
1589 | 1589 | |
1590 | - if ($id > 0) { |
|
1591 | - $pdo->beginTransaction(); |
|
1590 | + if ($id > 0) { |
|
1591 | + $pdo->beginTransaction(); |
|
1592 | 1592 | |
1593 | - /* save starred articles in Archived feed */ |
|
1593 | + /* save starred articles in Archived feed */ |
|
1594 | 1594 | |
1595 | - /* prepare feed if necessary */ |
|
1595 | + /* prepare feed if necessary */ |
|
1596 | 1596 | |
1597 | - $sth = $pdo->prepare("SELECT feed_url FROM ttrss_feeds WHERE id = ? |
|
1597 | + $sth = $pdo->prepare("SELECT feed_url FROM ttrss_feeds WHERE id = ? |
|
1598 | 1598 | AND owner_uid = ?"); |
1599 | - $sth->execute([$id, $owner_uid]); |
|
1599 | + $sth->execute([$id, $owner_uid]); |
|
1600 | 1600 | |
1601 | - if ($row = $sth->fetch()) { |
|
1602 | - $feed_url = $row["feed_url"]; |
|
1601 | + if ($row = $sth->fetch()) { |
|
1602 | + $feed_url = $row["feed_url"]; |
|
1603 | 1603 | |
1604 | - $sth = $pdo->prepare("SELECT id FROM ttrss_archived_feeds |
|
1604 | + $sth = $pdo->prepare("SELECT id FROM ttrss_archived_feeds |
|
1605 | 1605 | WHERE feed_url = ? AND owner_uid = ?"); |
1606 | - $sth->execute([$feed_url, $owner_uid]); |
|
1606 | + $sth->execute([$feed_url, $owner_uid]); |
|
1607 | 1607 | |
1608 | - if ($row = $sth->fetch()) { |
|
1609 | - $archive_id = $row["id"]; |
|
1610 | - } else { |
|
1611 | - $res = $pdo->query("SELECT MAX(id) AS id FROM ttrss_archived_feeds"); |
|
1612 | - $row = $res->fetch(); |
|
1608 | + if ($row = $sth->fetch()) { |
|
1609 | + $archive_id = $row["id"]; |
|
1610 | + } else { |
|
1611 | + $res = $pdo->query("SELECT MAX(id) AS id FROM ttrss_archived_feeds"); |
|
1612 | + $row = $res->fetch(); |
|
1613 | 1613 | |
1614 | - $new_feed_id = (int) $row['id'] + 1; |
|
1614 | + $new_feed_id = (int) $row['id'] + 1; |
|
1615 | 1615 | |
1616 | - $sth = $pdo->prepare("INSERT INTO ttrss_archived_feeds |
|
1616 | + $sth = $pdo->prepare("INSERT INTO ttrss_archived_feeds |
|
1617 | 1617 | (id, owner_uid, title, feed_url, site_url, created) |
1618 | 1618 | SELECT ?, owner_uid, title, feed_url, site_url, NOW() from ttrss_feeds |
1619 | 1619 | WHERE id = ?"); |
1620 | - $sth->execute([$new_feed_id, $id]); |
|
1620 | + $sth->execute([$new_feed_id, $id]); |
|
1621 | 1621 | |
1622 | - $archive_id = $new_feed_id; |
|
1623 | - } |
|
1622 | + $archive_id = $new_feed_id; |
|
1623 | + } |
|
1624 | 1624 | |
1625 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries SET feed_id = NULL, |
|
1625 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries SET feed_id = NULL, |
|
1626 | 1626 | orig_feed_id = ? WHERE feed_id = ? AND |
1627 | 1627 | marked = true AND owner_uid = ?"); |
1628 | 1628 | |
1629 | - $sth->execute([$archive_id, $id, $owner_uid]); |
|
1629 | + $sth->execute([$archive_id, $id, $owner_uid]); |
|
1630 | 1630 | |
1631 | - /* Remove access key for the feed */ |
|
1631 | + /* Remove access key for the feed */ |
|
1632 | 1632 | |
1633 | - $sth = $pdo->prepare("DELETE FROM ttrss_access_keys WHERE |
|
1633 | + $sth = $pdo->prepare("DELETE FROM ttrss_access_keys WHERE |
|
1634 | 1634 | feed_id = ? AND owner_uid = ?"); |
1635 | - $sth->execute([$id, $owner_uid]); |
|
1635 | + $sth->execute([$id, $owner_uid]); |
|
1636 | 1636 | |
1637 | - /* remove the feed */ |
|
1637 | + /* remove the feed */ |
|
1638 | 1638 | |
1639 | - $sth = $pdo->prepare("DELETE FROM ttrss_feeds |
|
1639 | + $sth = $pdo->prepare("DELETE FROM ttrss_feeds |
|
1640 | 1640 | WHERE id = ? AND owner_uid = ?"); |
1641 | - $sth->execute([$id, $owner_uid]); |
|
1642 | - } |
|
1641 | + $sth->execute([$id, $owner_uid]); |
|
1642 | + } |
|
1643 | 1643 | |
1644 | - $pdo->commit(); |
|
1644 | + $pdo->commit(); |
|
1645 | 1645 | |
1646 | - if (file_exists(ICONS_DIR."/$id.ico")) { |
|
1647 | - unlink(ICONS_DIR."/$id.ico"); |
|
1648 | - } |
|
1646 | + if (file_exists(ICONS_DIR."/$id.ico")) { |
|
1647 | + unlink(ICONS_DIR."/$id.ico"); |
|
1648 | + } |
|
1649 | 1649 | |
1650 | - CCache::remove($id, $owner_uid); |
|
1650 | + CCache::remove($id, $owner_uid); |
|
1651 | 1651 | |
1652 | - } else { |
|
1653 | - Labels::remove(Labels::feed_to_label_id($id), $owner_uid); |
|
1654 | - //CCache::remove($id, $owner_uid); don't think labels are cached |
|
1655 | - } |
|
1656 | - } |
|
1652 | + } else { |
|
1653 | + Labels::remove(Labels::feed_to_label_id($id), $owner_uid); |
|
1654 | + //CCache::remove($id, $owner_uid); don't think labels are cached |
|
1655 | + } |
|
1656 | + } |
|
1657 | 1657 | |
1658 | - public function batchSubscribe() { |
|
1659 | - print_hidden("op", "pref-feeds"); |
|
1660 | - print_hidden("method", "batchaddfeeds"); |
|
1658 | + public function batchSubscribe() { |
|
1659 | + print_hidden("op", "pref-feeds"); |
|
1660 | + print_hidden("method", "batchaddfeeds"); |
|
1661 | 1661 | |
1662 | - print "<header class='horizontal'>".__("One valid feed per line (no detection is done)")."</header>"; |
|
1663 | - print "<section>"; |
|
1662 | + print "<header class='horizontal'>".__("One valid feed per line (no detection is done)")."</header>"; |
|
1663 | + print "<section>"; |
|
1664 | 1664 | |
1665 | - print "<textarea |
|
1665 | + print "<textarea |
|
1666 | 1666 | style='font-size : 12px; width : 98%; height: 200px;' |
1667 | 1667 | dojoType='dijit.form.SimpleTextarea' name='feeds'></textarea>"; |
1668 | 1668 | |
1669 | - if (get_pref('ENABLE_FEED_CATS')) { |
|
1670 | - print "<fieldset>"; |
|
1671 | - print "<label>".__('Place in category:')."</label> "; |
|
1672 | - print_feed_cat_select("cat", false, 'dojoType="fox.form.Select"'); |
|
1673 | - print "</fieldset>"; |
|
1674 | - } |
|
1669 | + if (get_pref('ENABLE_FEED_CATS')) { |
|
1670 | + print "<fieldset>"; |
|
1671 | + print "<label>".__('Place in category:')."</label> "; |
|
1672 | + print_feed_cat_select("cat", false, 'dojoType="fox.form.Select"'); |
|
1673 | + print "</fieldset>"; |
|
1674 | + } |
|
1675 | 1675 | |
1676 | - print "</section>"; |
|
1676 | + print "</section>"; |
|
1677 | 1677 | |
1678 | - print "<div id='feedDlg_loginContainer' style='display : none'>"; |
|
1678 | + print "<div id='feedDlg_loginContainer' style='display : none'>"; |
|
1679 | 1679 | |
1680 | - print "<header>".__("Authentication")."</header>"; |
|
1681 | - print "<section>"; |
|
1680 | + print "<header>".__("Authentication")."</header>"; |
|
1681 | + print "<section>"; |
|
1682 | 1682 | |
1683 | - print "<input dojoType='dijit.form.TextBox' name='login' placeHolder=\"".__("Login")."\"> |
|
1683 | + print "<input dojoType='dijit.form.TextBox' name='login' placeHolder=\"".__("Login")."\"> |
|
1684 | 1684 | <input placeHolder=\"".__("Password")."\" dojoType=\"dijit.form.TextBox\" type='password' |
1685 | 1685 | autocomplete='new-password' name='pass''></div>"; |
1686 | 1686 | |
1687 | - print "</section>"; |
|
1688 | - print "</div>"; |
|
1687 | + print "</section>"; |
|
1688 | + print "</div>"; |
|
1689 | 1689 | |
1690 | - print "<fieldset class='narrow'> |
|
1690 | + print "<fieldset class='narrow'> |
|
1691 | 1691 | <label class='checkbox'><input type='checkbox' name='need_auth' dojoType='dijit.form.CheckBox' |
1692 | 1692 | onclick='displayIfChecked(this, \"feedDlg_loginContainer\")'> ". |
1693 | - __('Feeds require authentication.')."</label></div>"; |
|
1694 | - print "</fieldset>"; |
|
1693 | + __('Feeds require authentication.')."</label></div>"; |
|
1694 | + print "</fieldset>"; |
|
1695 | 1695 | |
1696 | - print "<footer> |
|
1696 | + print "<footer> |
|
1697 | 1697 | <button dojoType='dijit.form.Button' type='submit' class='alt-primary'>".__('Subscribe')."</button> |
1698 | 1698 | <button dojoType='dijit.form.Button' onclick=\"return dijit.byId('batchSubDlg').hide()\">".__('Cancel')."</button> |
1699 | 1699 | </footer>"; |
1700 | - } |
|
1700 | + } |
|
1701 | 1701 | |
1702 | - public function batchAddFeeds() { |
|
1703 | - $cat_id = clean($_REQUEST['cat']); |
|
1704 | - $feeds = explode("\n", clean($_REQUEST['feeds'])); |
|
1705 | - $login = clean($_REQUEST['login']); |
|
1706 | - $pass = trim(clean($_REQUEST['pass'])); |
|
1702 | + public function batchAddFeeds() { |
|
1703 | + $cat_id = clean($_REQUEST['cat']); |
|
1704 | + $feeds = explode("\n", clean($_REQUEST['feeds'])); |
|
1705 | + $login = clean($_REQUEST['login']); |
|
1706 | + $pass = trim(clean($_REQUEST['pass'])); |
|
1707 | 1707 | |
1708 | - $csth = $this->pdo->prepare("SELECT id FROM ttrss_feeds |
|
1708 | + $csth = $this->pdo->prepare("SELECT id FROM ttrss_feeds |
|
1709 | 1709 | WHERE feed_url = ? AND owner_uid = ?"); |
1710 | 1710 | |
1711 | - $isth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
1711 | + $isth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
1712 | 1712 | (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method,auth_pass_encrypted) |
1713 | 1713 | VALUES (?, ?, '[Unknown]', ?, ?, ?, 0, false)"); |
1714 | 1714 | |
1715 | - foreach ($feeds as $feed) { |
|
1716 | - $feed = trim($feed); |
|
1715 | + foreach ($feeds as $feed) { |
|
1716 | + $feed = trim($feed); |
|
1717 | 1717 | |
1718 | - if (Feeds::validate_feed_url($feed)) { |
|
1718 | + if (Feeds::validate_feed_url($feed)) { |
|
1719 | 1719 | |
1720 | - $this->pdo->beginTransaction(); |
|
1720 | + $this->pdo->beginTransaction(); |
|
1721 | 1721 | |
1722 | - $csth->execute([$feed, $_SESSION['uid']]); |
|
1722 | + $csth->execute([$feed, $_SESSION['uid']]); |
|
1723 | 1723 | |
1724 | - if (!$csth->fetch()) { |
|
1725 | - $isth->execute([$_SESSION['uid'], $feed, $cat_id ? $cat_id : null, $login, $pass]); |
|
1726 | - } |
|
1724 | + if (!$csth->fetch()) { |
|
1725 | + $isth->execute([$_SESSION['uid'], $feed, $cat_id ? $cat_id : null, $login, $pass]); |
|
1726 | + } |
|
1727 | 1727 | |
1728 | - $this->pdo->commit(); |
|
1729 | - } |
|
1730 | - } |
|
1731 | - } |
|
1728 | + $this->pdo->commit(); |
|
1729 | + } |
|
1730 | + } |
|
1731 | + } |
|
1732 | 1732 | |
1733 | - public function regenOPMLKey() { |
|
1734 | - $this->update_feed_access_key('OPML:Publish', |
|
1735 | - false, $_SESSION["uid"]); |
|
1733 | + public function regenOPMLKey() { |
|
1734 | + $this->update_feed_access_key('OPML:Publish', |
|
1735 | + false, $_SESSION["uid"]); |
|
1736 | 1736 | |
1737 | - $new_link = Opml::opml_publish_url(); |
|
1737 | + $new_link = Opml::opml_publish_url(); |
|
1738 | 1738 | |
1739 | - print json_encode(array("link" => $new_link)); |
|
1740 | - } |
|
1739 | + print json_encode(array("link" => $new_link)); |
|
1740 | + } |
|
1741 | 1741 | |
1742 | - public function regenFeedKey() { |
|
1743 | - $feed_id = clean($_REQUEST['id']); |
|
1744 | - $is_cat = clean($_REQUEST['is_cat']); |
|
1742 | + public function regenFeedKey() { |
|
1743 | + $feed_id = clean($_REQUEST['id']); |
|
1744 | + $is_cat = clean($_REQUEST['is_cat']); |
|
1745 | 1745 | |
1746 | - $new_key = $this->update_feed_access_key($feed_id, $is_cat); |
|
1746 | + $new_key = $this->update_feed_access_key($feed_id, $is_cat); |
|
1747 | 1747 | |
1748 | - print json_encode(["link" => $new_key]); |
|
1749 | - } |
|
1748 | + print json_encode(["link" => $new_key]); |
|
1749 | + } |
|
1750 | 1750 | |
1751 | 1751 | |
1752 | - private function update_feed_access_key($feed_id, $is_cat, $owner_uid = false) { |
|
1753 | - if (!$owner_uid) { |
|
1754 | - $owner_uid = $_SESSION["uid"]; |
|
1755 | - } |
|
1752 | + private function update_feed_access_key($feed_id, $is_cat, $owner_uid = false) { |
|
1753 | + if (!$owner_uid) { |
|
1754 | + $owner_uid = $_SESSION["uid"]; |
|
1755 | + } |
|
1756 | 1756 | |
1757 | - // clear old value and generate new one |
|
1758 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_access_keys |
|
1757 | + // clear old value and generate new one |
|
1758 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_access_keys |
|
1759 | 1759 | WHERE feed_id = ? AND is_cat = ? AND owner_uid = ?"); |
1760 | - $sth->execute([$feed_id, bool_to_sql_bool($is_cat), $owner_uid]); |
|
1760 | + $sth->execute([$feed_id, bool_to_sql_bool($is_cat), $owner_uid]); |
|
1761 | 1761 | |
1762 | - return Feeds::get_feed_access_key($feed_id, $is_cat, $owner_uid); |
|
1763 | - } |
|
1762 | + return Feeds::get_feed_access_key($feed_id, $is_cat, $owner_uid); |
|
1763 | + } |
|
1764 | 1764 | |
1765 | - // Silent |
|
1766 | - public function clearKeys() { |
|
1767 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_access_keys WHERE |
|
1765 | + // Silent |
|
1766 | + public function clearKeys() { |
|
1767 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_access_keys WHERE |
|
1768 | 1768 | owner_uid = ?"); |
1769 | - $sth->execute([$_SESSION['uid']]); |
|
1770 | - } |
|
1771 | - |
|
1772 | - private function calculate_children_count($cat) { |
|
1773 | - $c = 0; |
|
1774 | - |
|
1775 | - foreach ($cat['items'] as $child) { |
|
1776 | - if ($child['type'] == 'category') { |
|
1777 | - $c += $this->calculate_children_count($child); |
|
1778 | - } else { |
|
1779 | - $c += 1; |
|
1780 | - } |
|
1781 | - } |
|
1782 | - |
|
1783 | - return $c; |
|
1784 | - } |
|
1785 | - |
|
1786 | - public function getinactivefeeds() { |
|
1787 | - if (DB_TYPE == "pgsql") { |
|
1788 | - $interval_qpart = "NOW() - INTERVAL '3 months'"; |
|
1789 | - } else { |
|
1790 | - $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; |
|
1791 | - } |
|
1792 | - |
|
1793 | - $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_inactive FROM ttrss_feeds WHERE |
|
1769 | + $sth->execute([$_SESSION['uid']]); |
|
1770 | + } |
|
1771 | + |
|
1772 | + private function calculate_children_count($cat) { |
|
1773 | + $c = 0; |
|
1774 | + |
|
1775 | + foreach ($cat['items'] as $child) { |
|
1776 | + if ($child['type'] == 'category') { |
|
1777 | + $c += $this->calculate_children_count($child); |
|
1778 | + } else { |
|
1779 | + $c += 1; |
|
1780 | + } |
|
1781 | + } |
|
1782 | + |
|
1783 | + return $c; |
|
1784 | + } |
|
1785 | + |
|
1786 | + public function getinactivefeeds() { |
|
1787 | + if (DB_TYPE == "pgsql") { |
|
1788 | + $interval_qpart = "NOW() - INTERVAL '3 months'"; |
|
1789 | + } else { |
|
1790 | + $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; |
|
1791 | + } |
|
1792 | + |
|
1793 | + $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_inactive FROM ttrss_feeds WHERE |
|
1794 | 1794 | (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE |
1795 | 1795 | ttrss_entries.id = ref_id AND |
1796 | 1796 | ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart AND |
1797 | 1797 | ttrss_feeds.owner_uid = ?"); |
1798 | - $sth->execute([$_SESSION['uid']]); |
|
1799 | - |
|
1800 | - if ($row = $sth->fetch()) { |
|
1801 | - print (int) $row["num_inactive"]; |
|
1802 | - } |
|
1803 | - } |
|
1804 | - |
|
1805 | - public static function subscribe_to_feed_url() { |
|
1806 | - $url_path = get_self_url_prefix(). |
|
1807 | - "/public.php?op=subscribe&feed_url=%s"; |
|
1808 | - return $url_path; |
|
1809 | - } |
|
1798 | + $sth->execute([$_SESSION['uid']]); |
|
1799 | + |
|
1800 | + if ($row = $sth->fetch()) { |
|
1801 | + print (int) $row["num_inactive"]; |
|
1802 | + } |
|
1803 | + } |
|
1804 | + |
|
1805 | + public static function subscribe_to_feed_url() { |
|
1806 | + $url_path = get_self_url_prefix(). |
|
1807 | + "/public.php?op=subscribe&feed_url=%s"; |
|
1808 | + return $url_path; |
|
1809 | + } |
|
1810 | 1810 | |
1811 | 1811 | } |
@@ -1071,70 +1071,70 @@ |
||
1071 | 1071 | $qpart = ""; |
1072 | 1072 | |
1073 | 1073 | switch ($k) { |
1074 | - case "title": |
|
1075 | - $qpart = "title = ".$this->pdo->quote($feed_title); |
|
1076 | - break; |
|
1077 | - |
|
1078 | - case "feed_url": |
|
1079 | - $qpart = "feed_url = ".$this->pdo->quote($feed_url); |
|
1080 | - break; |
|
1081 | - |
|
1082 | - case "update_interval": |
|
1083 | - $qpart = "update_interval = ".$this->pdo->quote($upd_intl); |
|
1084 | - break; |
|
1085 | - |
|
1086 | - case "purge_interval": |
|
1087 | - $qpart = "purge_interval =".$this->pdo->quote($purge_intl); |
|
1088 | - break; |
|
1089 | - |
|
1090 | - case "auth_login": |
|
1091 | - $qpart = "auth_login = ".$this->pdo->quote($auth_login); |
|
1092 | - break; |
|
1093 | - |
|
1094 | - case "auth_pass": |
|
1095 | - $qpart = "auth_pass =".$this->pdo->quote($auth_pass).", auth_pass_encrypted = false"; |
|
1096 | - break; |
|
1097 | - |
|
1098 | - case "private": |
|
1099 | - $qpart = "private = ".$this->pdo->quote($private); |
|
1100 | - break; |
|
1101 | - |
|
1102 | - case "include_in_digest": |
|
1103 | - $qpart = "include_in_digest = ".$this->pdo->quote($include_in_digest); |
|
1104 | - break; |
|
1105 | - |
|
1106 | - case "always_display_enclosures": |
|
1107 | - $qpart = "always_display_enclosures = ".$this->pdo->quote($always_display_enclosures); |
|
1108 | - break; |
|
1109 | - |
|
1110 | - case "mark_unread_on_update": |
|
1111 | - $qpart = "mark_unread_on_update = ".$this->pdo->quote($mark_unread_on_update); |
|
1112 | - break; |
|
1113 | - |
|
1114 | - case "cache_images": |
|
1115 | - $qpart = "cache_images = ".$this->pdo->quote($cache_images); |
|
1116 | - break; |
|
1117 | - |
|
1118 | - case "hide_images": |
|
1119 | - $qpart = "hide_images = ".$this->pdo->quote($hide_images); |
|
1120 | - break; |
|
1121 | - |
|
1122 | - case "cat_id": |
|
1123 | - if (get_pref('ENABLE_FEED_CATS')) { |
|
1124 | - if ($cat_id) { |
|
1125 | - $qpart = "cat_id = ".$this->pdo->quote($cat_id); |
|
1126 | - } else { |
|
1127 | - $qpart = 'cat_id = NULL'; |
|
1128 | - } |
|
1074 | + case "title": |
|
1075 | + $qpart = "title = ".$this->pdo->quote($feed_title); |
|
1076 | + break; |
|
1077 | + |
|
1078 | + case "feed_url": |
|
1079 | + $qpart = "feed_url = ".$this->pdo->quote($feed_url); |
|
1080 | + break; |
|
1081 | + |
|
1082 | + case "update_interval": |
|
1083 | + $qpart = "update_interval = ".$this->pdo->quote($upd_intl); |
|
1084 | + break; |
|
1085 | + |
|
1086 | + case "purge_interval": |
|
1087 | + $qpart = "purge_interval =".$this->pdo->quote($purge_intl); |
|
1088 | + break; |
|
1089 | + |
|
1090 | + case "auth_login": |
|
1091 | + $qpart = "auth_login = ".$this->pdo->quote($auth_login); |
|
1092 | + break; |
|
1093 | + |
|
1094 | + case "auth_pass": |
|
1095 | + $qpart = "auth_pass =".$this->pdo->quote($auth_pass).", auth_pass_encrypted = false"; |
|
1096 | + break; |
|
1097 | + |
|
1098 | + case "private": |
|
1099 | + $qpart = "private = ".$this->pdo->quote($private); |
|
1100 | + break; |
|
1101 | + |
|
1102 | + case "include_in_digest": |
|
1103 | + $qpart = "include_in_digest = ".$this->pdo->quote($include_in_digest); |
|
1104 | + break; |
|
1105 | + |
|
1106 | + case "always_display_enclosures": |
|
1107 | + $qpart = "always_display_enclosures = ".$this->pdo->quote($always_display_enclosures); |
|
1108 | + break; |
|
1109 | + |
|
1110 | + case "mark_unread_on_update": |
|
1111 | + $qpart = "mark_unread_on_update = ".$this->pdo->quote($mark_unread_on_update); |
|
1112 | + break; |
|
1113 | + |
|
1114 | + case "cache_images": |
|
1115 | + $qpart = "cache_images = ".$this->pdo->quote($cache_images); |
|
1116 | + break; |
|
1117 | + |
|
1118 | + case "hide_images": |
|
1119 | + $qpart = "hide_images = ".$this->pdo->quote($hide_images); |
|
1120 | + break; |
|
1121 | + |
|
1122 | + case "cat_id": |
|
1123 | + if (get_pref('ENABLE_FEED_CATS')) { |
|
1124 | + if ($cat_id) { |
|
1125 | + $qpart = "cat_id = ".$this->pdo->quote($cat_id); |
|
1129 | 1126 | } else { |
1130 | - $qpart = ""; |
|
1127 | + $qpart = 'cat_id = NULL'; |
|
1131 | 1128 | } |
1129 | + } else { |
|
1130 | + $qpart = ""; |
|
1131 | + } |
|
1132 | 1132 | |
1133 | - break; |
|
1133 | + break; |
|
1134 | 1134 | |
1135 | - case "feed_language": |
|
1136 | - $qpart = "feed_language = ".$this->pdo->quote($feed_language); |
|
1137 | - break; |
|
1135 | + case "feed_language": |
|
1136 | + $qpart = "feed_language = ".$this->pdo->quote($feed_language); |
|
1137 | + break; |
|
1138 | 1138 | |
1139 | 1139 | } |
1140 | 1140 |
@@ -1,130 +1,130 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class Pref_Users extends Handler_Protected { |
3 | - public function before($method) { |
|
4 | - if (parent::before($method)) { |
|
5 | - if ($_SESSION["access_level"] < 10) { |
|
6 | - print __("Your access level is insufficient to open this tab."); |
|
7 | - return false; |
|
8 | - } |
|
9 | - return true; |
|
10 | - } |
|
11 | - return false; |
|
12 | - } |
|
3 | + public function before($method) { |
|
4 | + if (parent::before($method)) { |
|
5 | + if ($_SESSION["access_level"] < 10) { |
|
6 | + print __("Your access level is insufficient to open this tab."); |
|
7 | + return false; |
|
8 | + } |
|
9 | + return true; |
|
10 | + } |
|
11 | + return false; |
|
12 | + } |
|
13 | 13 | |
14 | - public function csrf_ignore($method) { |
|
15 | - $csrf_ignored = array("index", "edit", "userdetails"); |
|
14 | + public function csrf_ignore($method) { |
|
15 | + $csrf_ignored = array("index", "edit", "userdetails"); |
|
16 | 16 | |
17 | - return array_search($method, $csrf_ignored) !== false; |
|
18 | - } |
|
17 | + return array_search($method, $csrf_ignored) !== false; |
|
18 | + } |
|
19 | 19 | |
20 | - public function edit() { |
|
21 | - global $access_level_names; |
|
20 | + public function edit() { |
|
21 | + global $access_level_names; |
|
22 | 22 | |
23 | - print "<form id='user_edit_form' onsubmit='return false' dojoType='dijit.form.Form'>"; |
|
23 | + print "<form id='user_edit_form' onsubmit='return false' dojoType='dijit.form.Form'>"; |
|
24 | 24 | |
25 | - print '<div dojoType="dijit.layout.TabContainer" style="height : 400px"> |
|
25 | + print '<div dojoType="dijit.layout.TabContainer" style="height : 400px"> |
|
26 | 26 | <div dojoType="dijit.layout.ContentPane" title="'.__('Edit user').'">'; |
27 | 27 | |
28 | - //print "<form id=\"user_edit_form\" onsubmit='return false' dojoType=\"dijit.form.Form\">"; |
|
28 | + //print "<form id=\"user_edit_form\" onsubmit='return false' dojoType=\"dijit.form.Form\">"; |
|
29 | 29 | |
30 | - $id = (int) clean($_REQUEST["id"]); |
|
30 | + $id = (int) clean($_REQUEST["id"]); |
|
31 | 31 | |
32 | - print_hidden("id", "$id"); |
|
33 | - print_hidden("op", "pref-users"); |
|
34 | - print_hidden("method", "editSave"); |
|
32 | + print_hidden("id", "$id"); |
|
33 | + print_hidden("op", "pref-users"); |
|
34 | + print_hidden("method", "editSave"); |
|
35 | 35 | |
36 | - $sth = $this->pdo->prepare("SELECT * FROM ttrss_users WHERE id = ?"); |
|
37 | - $sth->execute([$id]); |
|
36 | + $sth = $this->pdo->prepare("SELECT * FROM ttrss_users WHERE id = ?"); |
|
37 | + $sth->execute([$id]); |
|
38 | 38 | |
39 | - if ($row = $sth->fetch()) { |
|
39 | + if ($row = $sth->fetch()) { |
|
40 | 40 | |
41 | - $login = $row["login"]; |
|
42 | - $access_level = $row["access_level"]; |
|
43 | - $email = $row["email"]; |
|
41 | + $login = $row["login"]; |
|
42 | + $access_level = $row["access_level"]; |
|
43 | + $email = $row["email"]; |
|
44 | 44 | |
45 | - $sel_disabled = ($id == $_SESSION["uid"] || $login == "admin") ? "disabled" : ""; |
|
45 | + $sel_disabled = ($id == $_SESSION["uid"] || $login == "admin") ? "disabled" : ""; |
|
46 | 46 | |
47 | - print "<header>".__("User")."</header>"; |
|
48 | - print "<section>"; |
|
47 | + print "<header>".__("User")."</header>"; |
|
48 | + print "<section>"; |
|
49 | 49 | |
50 | - if ($sel_disabled) { |
|
51 | - print_hidden("login", "$login"); |
|
52 | - } |
|
50 | + if ($sel_disabled) { |
|
51 | + print_hidden("login", "$login"); |
|
52 | + } |
|
53 | 53 | |
54 | - print "<fieldset>"; |
|
55 | - print "<label>".__("Login:")."</label>"; |
|
56 | - print "<input style='font-size : 16px' |
|
54 | + print "<fieldset>"; |
|
55 | + print "<label>".__("Login:")."</label>"; |
|
56 | + print "<input style='font-size : 16px' |
|
57 | 57 | dojoType='dijit.form.ValidationTextBox' required='1' |
58 | 58 | $sel_disabled name='login' value=\"$login\">"; |
59 | - print "</fieldset>"; |
|
59 | + print "</fieldset>"; |
|
60 | 60 | |
61 | - print "</section>"; |
|
61 | + print "</section>"; |
|
62 | 62 | |
63 | - print "<header>".__("Authentication")."</header>"; |
|
64 | - print "<section>"; |
|
63 | + print "<header>".__("Authentication")."</header>"; |
|
64 | + print "<section>"; |
|
65 | 65 | |
66 | - print "<fieldset>"; |
|
66 | + print "<fieldset>"; |
|
67 | 67 | |
68 | - print "<label>".__('Access level: ')."</label> "; |
|
68 | + print "<label>".__('Access level: ')."</label> "; |
|
69 | 69 | |
70 | - if (!$sel_disabled) { |
|
71 | - print_select_hash("access_level", $access_level, $access_level_names, |
|
72 | - "dojoType=\"fox.form.Select\" $sel_disabled"); |
|
73 | - } else { |
|
74 | - print_select_hash("", $access_level, $access_level_names, |
|
75 | - "dojoType=\"fox.form.Select\" $sel_disabled"); |
|
76 | - print_hidden("access_level", "$access_level"); |
|
77 | - } |
|
70 | + if (!$sel_disabled) { |
|
71 | + print_select_hash("access_level", $access_level, $access_level_names, |
|
72 | + "dojoType=\"fox.form.Select\" $sel_disabled"); |
|
73 | + } else { |
|
74 | + print_select_hash("", $access_level, $access_level_names, |
|
75 | + "dojoType=\"fox.form.Select\" $sel_disabled"); |
|
76 | + print_hidden("access_level", "$access_level"); |
|
77 | + } |
|
78 | 78 | |
79 | - print "</fieldset>"; |
|
80 | - print "<fieldset>"; |
|
79 | + print "</fieldset>"; |
|
80 | + print "<fieldset>"; |
|
81 | 81 | |
82 | - print "<label>".__("New password:")."</label> "; |
|
83 | - print "<input dojoType='dijit.form.TextBox' type='password' size='20' placeholder='Change password' |
|
82 | + print "<label>".__("New password:")."</label> "; |
|
83 | + print "<input dojoType='dijit.form.TextBox' type='password' size='20' placeholder='Change password' |
|
84 | 84 | name='password'>"; |
85 | 85 | |
86 | - print "</fieldset>"; |
|
86 | + print "</fieldset>"; |
|
87 | 87 | |
88 | - print "</section>"; |
|
88 | + print "</section>"; |
|
89 | 89 | |
90 | - print "<header>".__("Options")."</header>"; |
|
91 | - print "<section>"; |
|
90 | + print "<header>".__("Options")."</header>"; |
|
91 | + print "<section>"; |
|
92 | 92 | |
93 | - print "<fieldset>"; |
|
94 | - print "<label>".__("E-mail:")."</label> "; |
|
95 | - print "<input dojoType='dijit.form.TextBox' size='30' name='email' |
|
93 | + print "<fieldset>"; |
|
94 | + print "<label>".__("E-mail:")."</label> "; |
|
95 | + print "<input dojoType='dijit.form.TextBox' size='30' name='email' |
|
96 | 96 | value=\"$email\">"; |
97 | - print "</fieldset>"; |
|
97 | + print "</fieldset>"; |
|
98 | 98 | |
99 | - print "</section>"; |
|
99 | + print "</section>"; |
|
100 | 100 | |
101 | - print "</table>"; |
|
101 | + print "</table>"; |
|
102 | 102 | |
103 | - } |
|
103 | + } |
|
104 | 104 | |
105 | - print '</div>'; #tab |
|
106 | - print "<div href=\"backend.php?op=pref-users&method=userdetails&id=$id\" |
|
105 | + print '</div>'; #tab |
|
106 | + print "<div href=\"backend.php?op=pref-users&method=userdetails&id=$id\" |
|
107 | 107 | dojoType=\"dijit.layout.ContentPane\" title=\"".__('User details')."\">"; |
108 | 108 | |
109 | - print '</div>'; |
|
110 | - print '</div>'; |
|
109 | + print '</div>'; |
|
110 | + print '</div>'; |
|
111 | 111 | |
112 | - print "<footer> |
|
112 | + print "<footer> |
|
113 | 113 | <button dojoType='dijit.form.Button' class='alt-primary' type='submit' onclick=\"dijit.byId('userEditDlg').execute()\">". |
114 | - __('Save')."</button> |
|
114 | + __('Save')."</button> |
|
115 | 115 | <button dojoType='dijit.form.Button' onclick=\"dijit.byId('userEditDlg').hide()\">". |
116 | - __('Cancel')."</button> |
|
116 | + __('Cancel')."</button> |
|
117 | 117 | </footer>"; |
118 | 118 | |
119 | - print "</form>"; |
|
119 | + print "</form>"; |
|
120 | 120 | |
121 | - return; |
|
122 | - } |
|
121 | + return; |
|
122 | + } |
|
123 | 123 | |
124 | - public function userdetails() { |
|
125 | - $id = (int) clean($_REQUEST["id"]); |
|
124 | + public function userdetails() { |
|
125 | + $id = (int) clean($_REQUEST["id"]); |
|
126 | 126 | |
127 | - $sth = $this->pdo->prepare("SELECT login, |
|
127 | + $sth = $this->pdo->prepare("SELECT login, |
|
128 | 128 | ".SUBSTRING_FOR_DATE."(last_login,1,16) AS last_login, |
129 | 129 | access_level, |
130 | 130 | (SELECT COUNT(int_id) FROM ttrss_user_entries |
@@ -132,248 +132,248 @@ discard block |
||
132 | 132 | ".SUBSTRING_FOR_DATE."(created,1,16) AS created |
133 | 133 | FROM ttrss_users |
134 | 134 | WHERE id = ?"); |
135 | - $sth->execute([$id]); |
|
135 | + $sth->execute([$id]); |
|
136 | 136 | |
137 | - if ($row = $sth->fetch()) { |
|
138 | - print "<table width='100%'>"; |
|
137 | + if ($row = $sth->fetch()) { |
|
138 | + print "<table width='100%'>"; |
|
139 | 139 | |
140 | - $last_login = make_local_datetime( |
|
141 | - $row["last_login"], true); |
|
140 | + $last_login = make_local_datetime( |
|
141 | + $row["last_login"], true); |
|
142 | 142 | |
143 | - $created = make_local_datetime( |
|
144 | - $row["created"], true); |
|
143 | + $created = make_local_datetime( |
|
144 | + $row["created"], true); |
|
145 | 145 | |
146 | - $stored_articles = $row["stored_articles"]; |
|
146 | + $stored_articles = $row["stored_articles"]; |
|
147 | 147 | |
148 | - print "<tr><td>".__('Registered')."</td><td>$created</td></tr>"; |
|
149 | - print "<tr><td>".__('Last logged in')."</td><td>$last_login</td></tr>"; |
|
148 | + print "<tr><td>".__('Registered')."</td><td>$created</td></tr>"; |
|
149 | + print "<tr><td>".__('Last logged in')."</td><td>$last_login</td></tr>"; |
|
150 | 150 | |
151 | - $sth = $this->pdo->prepare("SELECT COUNT(id) as num_feeds FROM ttrss_feeds |
|
151 | + $sth = $this->pdo->prepare("SELECT COUNT(id) as num_feeds FROM ttrss_feeds |
|
152 | 152 | WHERE owner_uid = ?"); |
153 | - $sth->execute([$id]); |
|
154 | - $row = $sth->fetch(); |
|
155 | - $num_feeds = $row["num_feeds"]; |
|
153 | + $sth->execute([$id]); |
|
154 | + $row = $sth->fetch(); |
|
155 | + $num_feeds = $row["num_feeds"]; |
|
156 | 156 | |
157 | - print "<tr><td>".__('Subscribed feeds count')."</td><td>$num_feeds</td></tr>"; |
|
158 | - print "<tr><td>".__('Stored articles')."</td><td>$stored_articles</td></tr>"; |
|
157 | + print "<tr><td>".__('Subscribed feeds count')."</td><td>$num_feeds</td></tr>"; |
|
158 | + print "<tr><td>".__('Stored articles')."</td><td>$stored_articles</td></tr>"; |
|
159 | 159 | |
160 | - print "</table>"; |
|
160 | + print "</table>"; |
|
161 | 161 | |
162 | - print "<h1>".__('Subscribed feeds')."</h1>"; |
|
162 | + print "<h1>".__('Subscribed feeds')."</h1>"; |
|
163 | 163 | |
164 | - $sth = $this->pdo->prepare("SELECT id,title,site_url FROM ttrss_feeds |
|
164 | + $sth = $this->pdo->prepare("SELECT id,title,site_url FROM ttrss_feeds |
|
165 | 165 | WHERE owner_uid = ? ORDER BY title"); |
166 | - $sth->execute([$id]); |
|
166 | + $sth->execute([$id]); |
|
167 | 167 | |
168 | - print "<ul class=\"panel panel-scrollable list list-unstyled\">"; |
|
168 | + print "<ul class=\"panel panel-scrollable list list-unstyled\">"; |
|
169 | 169 | |
170 | - while ($line = $sth->fetch()) { |
|
170 | + while ($line = $sth->fetch()) { |
|
171 | 171 | |
172 | - $icon_file = ICONS_URL."/".$line["id"].".ico"; |
|
172 | + $icon_file = ICONS_URL."/".$line["id"].".ico"; |
|
173 | 173 | |
174 | - if (file_exists($icon_file) && filesize($icon_file) > 0) { |
|
175 | - $feed_icon = "<img class=\"icon\" src=\"$icon_file\">"; |
|
176 | - } else { |
|
177 | - $feed_icon = "<img class=\"icon\" src=\"images/blank_icon.gif\">"; |
|
178 | - } |
|
174 | + if (file_exists($icon_file) && filesize($icon_file) > 0) { |
|
175 | + $feed_icon = "<img class=\"icon\" src=\"$icon_file\">"; |
|
176 | + } else { |
|
177 | + $feed_icon = "<img class=\"icon\" src=\"images/blank_icon.gif\">"; |
|
178 | + } |
|
179 | 179 | |
180 | - print "<li>$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>"; |
|
180 | + print "<li>$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>"; |
|
181 | 181 | |
182 | - } |
|
182 | + } |
|
183 | 183 | |
184 | - print "</ul>"; |
|
184 | + print "</ul>"; |
|
185 | 185 | |
186 | 186 | |
187 | - } else { |
|
188 | - print "<h1>".__('User not found')."</h1>"; |
|
189 | - } |
|
187 | + } else { |
|
188 | + print "<h1>".__('User not found')."</h1>"; |
|
189 | + } |
|
190 | 190 | |
191 | - } |
|
191 | + } |
|
192 | 192 | |
193 | - public function editSave() { |
|
194 | - $login = trim(clean($_REQUEST["login"])); |
|
195 | - $uid = clean($_REQUEST["id"]); |
|
196 | - $access_level = (int) clean($_REQUEST["access_level"]); |
|
197 | - $email = trim(clean($_REQUEST["email"])); |
|
198 | - $password = clean($_REQUEST["password"]); |
|
193 | + public function editSave() { |
|
194 | + $login = trim(clean($_REQUEST["login"])); |
|
195 | + $uid = clean($_REQUEST["id"]); |
|
196 | + $access_level = (int) clean($_REQUEST["access_level"]); |
|
197 | + $email = trim(clean($_REQUEST["email"])); |
|
198 | + $password = clean($_REQUEST["password"]); |
|
199 | 199 | |
200 | - if ($password) { |
|
201 | - $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
202 | - $pwd_hash = encrypt_password($password, $salt, true); |
|
203 | - $pass_query_part = "pwd_hash = ".$this->pdo->quote($pwd_hash).", |
|
200 | + if ($password) { |
|
201 | + $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
202 | + $pwd_hash = encrypt_password($password, $salt, true); |
|
203 | + $pass_query_part = "pwd_hash = ".$this->pdo->quote($pwd_hash).", |
|
204 | 204 | salt = ".$this->pdo->quote($salt).","; |
205 | - } else { |
|
206 | - $pass_query_part = ""; |
|
207 | - } |
|
205 | + } else { |
|
206 | + $pass_query_part = ""; |
|
207 | + } |
|
208 | 208 | |
209 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET $pass_query_part login = ?, |
|
209 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET $pass_query_part login = ?, |
|
210 | 210 | access_level = ?, email = ?, otp_enabled = false WHERE id = ?"); |
211 | - $sth->execute([$login, $access_level, $email, $uid]); |
|
211 | + $sth->execute([$login, $access_level, $email, $uid]); |
|
212 | 212 | |
213 | - } |
|
213 | + } |
|
214 | 214 | |
215 | - public function remove() { |
|
216 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
215 | + public function remove() { |
|
216 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
217 | 217 | |
218 | - foreach ($ids as $id) { |
|
219 | - if ($id != $_SESSION["uid"] && $id != 1) { |
|
220 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_tags WHERE owner_uid = ?"); |
|
221 | - $sth->execute([$id]); |
|
218 | + foreach ($ids as $id) { |
|
219 | + if ($id != $_SESSION["uid"] && $id != 1) { |
|
220 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_tags WHERE owner_uid = ?"); |
|
221 | + $sth->execute([$id]); |
|
222 | 222 | |
223 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_feeds WHERE owner_uid = ?"); |
|
224 | - $sth->execute([$id]); |
|
223 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_feeds WHERE owner_uid = ?"); |
|
224 | + $sth->execute([$id]); |
|
225 | 225 | |
226 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_users WHERE id = ?"); |
|
227 | - $sth->execute([$id]); |
|
228 | - } |
|
229 | - } |
|
230 | - } |
|
226 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_users WHERE id = ?"); |
|
227 | + $sth->execute([$id]); |
|
228 | + } |
|
229 | + } |
|
230 | + } |
|
231 | 231 | |
232 | - public function add() { |
|
233 | - $login = trim(clean($_REQUEST["login"])); |
|
234 | - $tmp_user_pwd = make_password(); |
|
235 | - $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
236 | - $pwd_hash = encrypt_password($tmp_user_pwd, $salt, true); |
|
232 | + public function add() { |
|
233 | + $login = trim(clean($_REQUEST["login"])); |
|
234 | + $tmp_user_pwd = make_password(); |
|
235 | + $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
236 | + $pwd_hash = encrypt_password($tmp_user_pwd, $salt, true); |
|
237 | 237 | |
238 | - if (!$login) { |
|
239 | - return; |
|
240 | - } |
|
241 | - // no blank usernames |
|
238 | + if (!$login) { |
|
239 | + return; |
|
240 | + } |
|
241 | + // no blank usernames |
|
242 | 242 | |
243 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE |
|
243 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE |
|
244 | 244 | login = ?"); |
245 | - $sth->execute([$login]); |
|
245 | + $sth->execute([$login]); |
|
246 | 246 | |
247 | - if (!$sth->fetch()) { |
|
247 | + if (!$sth->fetch()) { |
|
248 | 248 | |
249 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_users |
|
249 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_users |
|
250 | 250 | (login,pwd_hash,access_level,last_login,created, salt) |
251 | 251 | VALUES (?, ?, 0, null, NOW(), ?)"); |
252 | - $sth->execute([$login, $pwd_hash, $salt]); |
|
252 | + $sth->execute([$login, $pwd_hash, $salt]); |
|
253 | 253 | |
254 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE |
|
254 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE |
|
255 | 255 | login = ? AND pwd_hash = ?"); |
256 | - $sth->execute([$login, $pwd_hash]); |
|
256 | + $sth->execute([$login, $pwd_hash]); |
|
257 | 257 | |
258 | - if ($row = $sth->fetch()) { |
|
258 | + if ($row = $sth->fetch()) { |
|
259 | 259 | |
260 | - $new_uid = $row['id']; |
|
260 | + $new_uid = $row['id']; |
|
261 | 261 | |
262 | - print T_sprintf("Added user %s with password %s", |
|
263 | - $login, $tmp_user_pwd); |
|
262 | + print T_sprintf("Added user %s with password %s", |
|
263 | + $login, $tmp_user_pwd); |
|
264 | 264 | |
265 | - initialize_user($new_uid); |
|
265 | + initialize_user($new_uid); |
|
266 | 266 | |
267 | - } else { |
|
267 | + } else { |
|
268 | 268 | |
269 | - print T_sprintf("Could not create user %s", $login); |
|
269 | + print T_sprintf("Could not create user %s", $login); |
|
270 | 270 | |
271 | - } |
|
272 | - } else { |
|
273 | - print T_sprintf("User %s already exists.", $login); |
|
274 | - } |
|
275 | - } |
|
271 | + } |
|
272 | + } else { |
|
273 | + print T_sprintf("User %s already exists.", $login); |
|
274 | + } |
|
275 | + } |
|
276 | 276 | |
277 | - public static function resetUserPassword($uid, $format_output = false) { |
|
277 | + public static function resetUserPassword($uid, $format_output = false) { |
|
278 | 278 | |
279 | - $pdo = Db::pdo(); |
|
279 | + $pdo = Db::pdo(); |
|
280 | 280 | |
281 | - $sth = $pdo->prepare("SELECT login FROM ttrss_users WHERE id = ?"); |
|
282 | - $sth->execute([$uid]); |
|
281 | + $sth = $pdo->prepare("SELECT login FROM ttrss_users WHERE id = ?"); |
|
282 | + $sth->execute([$uid]); |
|
283 | 283 | |
284 | - if ($row = $sth->fetch()) { |
|
284 | + if ($row = $sth->fetch()) { |
|
285 | 285 | |
286 | - $login = $row["login"]; |
|
286 | + $login = $row["login"]; |
|
287 | 287 | |
288 | - $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
289 | - $tmp_user_pwd = make_password(); |
|
288 | + $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
289 | + $tmp_user_pwd = make_password(); |
|
290 | 290 | |
291 | - $pwd_hash = encrypt_password($tmp_user_pwd, $new_salt, true); |
|
291 | + $pwd_hash = encrypt_password($tmp_user_pwd, $new_salt, true); |
|
292 | 292 | |
293 | - $sth = $pdo->prepare("UPDATE ttrss_users |
|
293 | + $sth = $pdo->prepare("UPDATE ttrss_users |
|
294 | 294 | SET pwd_hash = ?, salt = ?, otp_enabled = false |
295 | 295 | WHERE id = ?"); |
296 | - $sth->execute([$pwd_hash, $new_salt, $uid]); |
|
296 | + $sth->execute([$pwd_hash, $new_salt, $uid]); |
|
297 | 297 | |
298 | - $message = T_sprintf("Changed password of user %s to %s", "<strong>$login</strong>", "<strong>$tmp_user_pwd</strong>"); |
|
298 | + $message = T_sprintf("Changed password of user %s to %s", "<strong>$login</strong>", "<strong>$tmp_user_pwd</strong>"); |
|
299 | 299 | |
300 | - if ($format_output) { |
|
301 | - print_notice($message); |
|
302 | - } else { |
|
303 | - print $message; |
|
304 | - } |
|
300 | + if ($format_output) { |
|
301 | + print_notice($message); |
|
302 | + } else { |
|
303 | + print $message; |
|
304 | + } |
|
305 | 305 | |
306 | - } |
|
307 | - } |
|
306 | + } |
|
307 | + } |
|
308 | 308 | |
309 | - public function resetPass() { |
|
310 | - $uid = clean($_REQUEST["id"]); |
|
311 | - Pref_Users::resetUserPassword($uid); |
|
312 | - } |
|
309 | + public function resetPass() { |
|
310 | + $uid = clean($_REQUEST["id"]); |
|
311 | + Pref_Users::resetUserPassword($uid); |
|
312 | + } |
|
313 | 313 | |
314 | - public function index() { |
|
314 | + public function index() { |
|
315 | 315 | |
316 | - global $access_level_names; |
|
316 | + global $access_level_names; |
|
317 | 317 | |
318 | - print "<div dojoType='dijit.layout.BorderContainer' gutters='false'>"; |
|
319 | - print "<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='top'>"; |
|
320 | - print "<div dojoType='fox.Toolbar'>"; |
|
318 | + print "<div dojoType='dijit.layout.BorderContainer' gutters='false'>"; |
|
319 | + print "<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='top'>"; |
|
320 | + print "<div dojoType='fox.Toolbar'>"; |
|
321 | 321 | |
322 | - $user_search = trim(clean($_REQUEST["search"])); |
|
322 | + $user_search = trim(clean($_REQUEST["search"])); |
|
323 | 323 | |
324 | - if (array_key_exists("search", $_REQUEST)) { |
|
325 | - $_SESSION["prefs_user_search"] = $user_search; |
|
326 | - } else { |
|
327 | - $user_search = $_SESSION["prefs_user_search"]; |
|
328 | - } |
|
324 | + if (array_key_exists("search", $_REQUEST)) { |
|
325 | + $_SESSION["prefs_user_search"] = $user_search; |
|
326 | + } else { |
|
327 | + $user_search = $_SESSION["prefs_user_search"]; |
|
328 | + } |
|
329 | 329 | |
330 | - print "<div style='float : right; padding-right : 4px;'> |
|
330 | + print "<div style='float : right; padding-right : 4px;'> |
|
331 | 331 | <input dojoType='dijit.form.TextBox' id='user_search' size='20' type='search' |
332 | 332 | value=\"$user_search\"> |
333 | 333 | <button dojoType='dijit.form.Button' onclick='Users.reload()'>". |
334 | - __('Search')."</button> |
|
334 | + __('Search')."</button> |
|
335 | 335 | </div>"; |
336 | 336 | |
337 | - $sort = clean($_REQUEST["sort"]); |
|
337 | + $sort = clean($_REQUEST["sort"]); |
|
338 | 338 | |
339 | - if (!$sort || $sort == "undefined") { |
|
340 | - $sort = "login"; |
|
341 | - } |
|
339 | + if (!$sort || $sort == "undefined") { |
|
340 | + $sort = "login"; |
|
341 | + } |
|
342 | 342 | |
343 | - print "<div dojoType='fox.form.DropDownButton'>". |
|
344 | - "<span>".__('Select')."</span>"; |
|
345 | - print "<div dojoType='dijit.Menu' style='display: none'>"; |
|
346 | - print "<div onclick=\"Tables.select('prefUserList', true)\" |
|
343 | + print "<div dojoType='fox.form.DropDownButton'>". |
|
344 | + "<span>".__('Select')."</span>"; |
|
345 | + print "<div dojoType='dijit.Menu' style='display: none'>"; |
|
346 | + print "<div onclick=\"Tables.select('prefUserList', true)\" |
|
347 | 347 | dojoType='dijit.MenuItem'>".__('All')."</div>"; |
348 | - print "<div onclick=\"Tables.select('prefUserList', false)\" |
|
348 | + print "<div onclick=\"Tables.select('prefUserList', false)\" |
|
349 | 349 | dojoType='dijit.MenuItem'>".__('None')."</div>"; |
350 | - print "</div></div>"; |
|
350 | + print "</div></div>"; |
|
351 | 351 | |
352 | - print "<button dojoType='dijit.form.Button' onclick='Users.add()'>".__('Create user')."</button>"; |
|
352 | + print "<button dojoType='dijit.form.Button' onclick='Users.add()'>".__('Create user')."</button>"; |
|
353 | 353 | |
354 | - print " |
|
354 | + print " |
|
355 | 355 | <button dojoType='dijit.form.Button' onclick='Users.editSelected()'>". |
356 | - __('Edit')."</button dojoType=\"dijit.form.Button\"> |
|
356 | + __('Edit')."</button dojoType=\"dijit.form.Button\"> |
|
357 | 357 | <button dojoType='dijit.form.Button' onclick='Users.removeSelected()'>". |
358 | - __('Remove')."</button dojoType=\"dijit.form.Button\"> |
|
358 | + __('Remove')."</button dojoType=\"dijit.form.Button\"> |
|
359 | 359 | <button dojoType='dijit.form.Button' onclick='Users.resetSelected()'>". |
360 | - __('Reset password')."</button dojoType=\"dijit.form.Button\">"; |
|
360 | + __('Reset password')."</button dojoType=\"dijit.form.Button\">"; |
|
361 | 361 | |
362 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
363 | - "hook_prefs_tab_section", "prefUsersToolbar"); |
|
362 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
363 | + "hook_prefs_tab_section", "prefUsersToolbar"); |
|
364 | 364 | |
365 | - print "</div>"; #toolbar |
|
366 | - print "</div>"; #pane |
|
367 | - print "<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='center'>"; |
|
365 | + print "</div>"; #toolbar |
|
366 | + print "</div>"; #pane |
|
367 | + print "<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='center'>"; |
|
368 | 368 | |
369 | - $sort = $this->validate_field($sort, |
|
370 | - ["login", "access_level", "created", "num_feeds", "created", "last_login"], "login"); |
|
369 | + $sort = $this->validate_field($sort, |
|
370 | + ["login", "access_level", "created", "num_feeds", "created", "last_login"], "login"); |
|
371 | 371 | |
372 | - if ($sort != "login") { |
|
373 | - $sort = "$sort DESC"; |
|
374 | - } |
|
372 | + if ($sort != "login") { |
|
373 | + $sort = "$sort DESC"; |
|
374 | + } |
|
375 | 375 | |
376 | - $sth = $this->pdo->prepare("SELECT |
|
376 | + $sth = $this->pdo->prepare("SELECT |
|
377 | 377 | tu.id, |
378 | 378 | login,access_level,email, |
379 | 379 | ".SUBSTRING_FOR_DATE."(last_login,1,16) as last_login, |
@@ -384,11 +384,11 @@ discard block |
||
384 | 384 | WHERE |
385 | 385 | (:search = '' OR login LIKE :search) AND tu.id > 0 |
386 | 386 | ORDER BY $sort"); |
387 | - $sth->execute([":search" => $user_search ? "%$user_search%" : ""]); |
|
387 | + $sth->execute([":search" => $user_search ? "%$user_search%" : ""]); |
|
388 | 388 | |
389 | - print "<p><table width='100%' cellspacing='0' class='prefUserList' id='prefUserList'>"; |
|
389 | + print "<p><table width='100%' cellspacing='0' class='prefUserList' id='prefUserList'>"; |
|
390 | 390 | |
391 | - print "<tr class='title'> |
|
391 | + print "<tr class='title'> |
|
392 | 392 | <td align='center' width='5%'> </td> |
393 | 393 | <td width='20%'><a href='#' onclick=\"Users.reload('login')\">".__('Login')."</a></td> |
394 | 394 | <td width='20%'><a href='#' onclick=\"Users.reload('access_level')\">".__('Access Level')."</a></td> |
@@ -396,58 +396,58 @@ discard block |
||
396 | 396 | <td width='20%'><a href='#' onclick=\"Users.reload('created')\">".__('Registered')."</a></td> |
397 | 397 | <td width='20%'><a href='#' onclick=\"Users.reload('last_login')\">".__('Last login')."</a></td></tr>"; |
398 | 398 | |
399 | - $lnum = 0; |
|
399 | + $lnum = 0; |
|
400 | 400 | |
401 | - while ($line = $sth->fetch()) { |
|
401 | + while ($line = $sth->fetch()) { |
|
402 | 402 | |
403 | - $uid = $line["id"]; |
|
403 | + $uid = $line["id"]; |
|
404 | 404 | |
405 | - print "<tr data-row-id='$uid' onclick='Users.edit($uid)'>"; |
|
405 | + print "<tr data-row-id='$uid' onclick='Users.edit($uid)'>"; |
|
406 | 406 | |
407 | - $line["login"] = htmlspecialchars($line["login"]); |
|
408 | - $line["created"] = make_local_datetime($line["created"], false); |
|
409 | - $line["last_login"] = make_local_datetime($line["last_login"], false); |
|
407 | + $line["login"] = htmlspecialchars($line["login"]); |
|
408 | + $line["created"] = make_local_datetime($line["created"], false); |
|
409 | + $line["last_login"] = make_local_datetime($line["last_login"], false); |
|
410 | 410 | |
411 | - print "<td align='center'><input onclick='Tables.onRowChecked(this); event.stopPropagation();' |
|
411 | + print "<td align='center'><input onclick='Tables.onRowChecked(this); event.stopPropagation();' |
|
412 | 412 | dojoType='dijit.form.CheckBox' type='checkbox'></td>"; |
413 | 413 | |
414 | - print "<td title='".__('Click to edit')."'><i class='material-icons'>person</i> ".$line["login"]."</td>"; |
|
414 | + print "<td title='".__('Click to edit')."'><i class='material-icons'>person</i> ".$line["login"]."</td>"; |
|
415 | 415 | |
416 | - print "<td>".$access_level_names[$line["access_level"]]."</td>"; |
|
417 | - print "<td>".$line["num_feeds"]."</td>"; |
|
418 | - print "<td>".$line["created"]."</td>"; |
|
419 | - print "<td>".$line["last_login"]."</td>"; |
|
416 | + print "<td>".$access_level_names[$line["access_level"]]."</td>"; |
|
417 | + print "<td>".$line["num_feeds"]."</td>"; |
|
418 | + print "<td>".$line["created"]."</td>"; |
|
419 | + print "<td>".$line["last_login"]."</td>"; |
|
420 | 420 | |
421 | - print "</tr>"; |
|
421 | + print "</tr>"; |
|
422 | 422 | |
423 | - ++$lnum; |
|
424 | - } |
|
423 | + ++$lnum; |
|
424 | + } |
|
425 | 425 | |
426 | - print "</table>"; |
|
426 | + print "</table>"; |
|
427 | 427 | |
428 | - if ($lnum == 0) { |
|
429 | - if (!$user_search) { |
|
430 | - print_warning(__('No users defined.')); |
|
431 | - } else { |
|
432 | - print_warning(__('No matching users found.')); |
|
433 | - } |
|
434 | - } |
|
428 | + if ($lnum == 0) { |
|
429 | + if (!$user_search) { |
|
430 | + print_warning(__('No users defined.')); |
|
431 | + } else { |
|
432 | + print_warning(__('No matching users found.')); |
|
433 | + } |
|
434 | + } |
|
435 | 435 | |
436 | - print "</div>"; #pane |
|
436 | + print "</div>"; #pane |
|
437 | 437 | |
438 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
|
439 | - "hook_prefs_tab", "prefUsers"); |
|
438 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
|
439 | + "hook_prefs_tab", "prefUsers"); |
|
440 | 440 | |
441 | - print "</div>"; #container |
|
441 | + print "</div>"; #container |
|
442 | 442 | |
443 | - } |
|
443 | + } |
|
444 | 444 | |
445 | - public function validate_field($string, $allowed, $default = "") { |
|
446 | - if (in_array($string, $allowed)) { |
|
447 | - return $string; |
|
448 | - } else { |
|
449 | - return $default; |
|
450 | - } |
|
451 | - } |
|
445 | + public function validate_field($string, $allowed, $default = "") { |
|
446 | + if (in_array($string, $allowed)) { |
|
447 | + return $string; |
|
448 | + } else { |
|
449 | + return $default; |
|
450 | + } |
|
451 | + } |
|
452 | 452 | |
453 | 453 | } |