@@ -1,83 +1,83 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class Pref_Filters extends Handler_Protected { |
3 | 3 | |
4 | - public function csrf_ignore($method) { |
|
5 | - $csrf_ignored = array("index", "getfiltertree", "edit", "newfilter", "newrule", |
|
6 | - "newaction", "savefilterorder"); |
|
4 | + public function csrf_ignore($method) { |
|
5 | + $csrf_ignored = array("index", "getfiltertree", "edit", "newfilter", "newrule", |
|
6 | + "newaction", "savefilterorder"); |
|
7 | 7 | |
8 | - return array_search($method, $csrf_ignored) !== false; |
|
9 | - } |
|
8 | + return array_search($method, $csrf_ignored) !== false; |
|
9 | + } |
|
10 | 10 | |
11 | - public function filtersortreset() { |
|
12 | - $sth = $this->pdo->prepare("UPDATE ttrss_filters2 |
|
11 | + public function filtersortreset() { |
|
12 | + $sth = $this->pdo->prepare("UPDATE ttrss_filters2 |
|
13 | 13 | SET order_id = 0 WHERE owner_uid = ?"); |
14 | - $sth->execute([$_SESSION['uid']]); |
|
15 | - return; |
|
16 | - } |
|
14 | + $sth->execute([$_SESSION['uid']]); |
|
15 | + return; |
|
16 | + } |
|
17 | 17 | |
18 | - public function savefilterorder() { |
|
19 | - $data = json_decode($_POST['payload'], true); |
|
18 | + public function savefilterorder() { |
|
19 | + $data = json_decode($_POST['payload'], true); |
|
20 | 20 | |
21 | - #file_put_contents("/tmp/saveorder.json", clean($_POST['payload'])); |
|
22 | - #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true); |
|
21 | + #file_put_contents("/tmp/saveorder.json", clean($_POST['payload'])); |
|
22 | + #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true); |
|
23 | 23 | |
24 | - if (!is_array($data['items'])) { |
|
25 | - $data['items'] = json_decode($data['items'], true); |
|
26 | - } |
|
24 | + if (!is_array($data['items'])) { |
|
25 | + $data['items'] = json_decode($data['items'], true); |
|
26 | + } |
|
27 | 27 | |
28 | - $index = 0; |
|
28 | + $index = 0; |
|
29 | 29 | |
30 | - if (is_array($data) && is_array($data['items'])) { |
|
30 | + if (is_array($data) && is_array($data['items'])) { |
|
31 | 31 | |
32 | - $sth = $this->pdo->prepare("UPDATE ttrss_filters2 SET |
|
32 | + $sth = $this->pdo->prepare("UPDATE ttrss_filters2 SET |
|
33 | 33 | order_id = ? WHERE id = ? AND |
34 | 34 | owner_uid = ?"); |
35 | 35 | |
36 | - foreach ($data['items'][0]['items'] as $item) { |
|
37 | - $filter_id = (int) str_replace("FILTER:", "", $item['_reference']); |
|
36 | + foreach ($data['items'][0]['items'] as $item) { |
|
37 | + $filter_id = (int) str_replace("FILTER:", "", $item['_reference']); |
|
38 | 38 | |
39 | - if ($filter_id > 0) { |
|
40 | - $sth->execute([$index, $filter_id, $_SESSION['uid']]); |
|
41 | - ++$index; |
|
42 | - } |
|
43 | - } |
|
44 | - } |
|
39 | + if ($filter_id > 0) { |
|
40 | + $sth->execute([$index, $filter_id, $_SESSION['uid']]); |
|
41 | + ++$index; |
|
42 | + } |
|
43 | + } |
|
44 | + } |
|
45 | 45 | |
46 | - return; |
|
47 | - } |
|
46 | + return; |
|
47 | + } |
|
48 | 48 | |
49 | - public function testFilterDo() { |
|
50 | - $offset = (int) clean($_REQUEST["offset"]); |
|
51 | - $limit = (int) clean($_REQUEST["limit"]); |
|
49 | + public function testFilterDo() { |
|
50 | + $offset = (int) clean($_REQUEST["offset"]); |
|
51 | + $limit = (int) clean($_REQUEST["limit"]); |
|
52 | 52 | |
53 | - $filter = array(); |
|
53 | + $filter = array(); |
|
54 | 54 | |
55 | - $filter["enabled"] = true; |
|
56 | - $filter["match_any_rule"] = checkbox_to_sql_bool(clean($_REQUEST["match_any_rule"])); |
|
57 | - $filter["inverse"] = checkbox_to_sql_bool(clean($_REQUEST["inverse"])); |
|
55 | + $filter["enabled"] = true; |
|
56 | + $filter["match_any_rule"] = checkbox_to_sql_bool(clean($_REQUEST["match_any_rule"])); |
|
57 | + $filter["inverse"] = checkbox_to_sql_bool(clean($_REQUEST["inverse"])); |
|
58 | 58 | |
59 | - $filter["rules"] = array(); |
|
60 | - $filter["actions"] = array("dummy-action"); |
|
59 | + $filter["rules"] = array(); |
|
60 | + $filter["actions"] = array("dummy-action"); |
|
61 | 61 | |
62 | - $res = $this->pdo->query("SELECT id,name FROM ttrss_filter_types"); |
|
62 | + $res = $this->pdo->query("SELECT id,name FROM ttrss_filter_types"); |
|
63 | 63 | |
64 | - $filter_types = array(); |
|
65 | - while ($line = $res->fetch()) { |
|
66 | - $filter_types[$line["id"]] = $line["name"]; |
|
67 | - } |
|
64 | + $filter_types = array(); |
|
65 | + while ($line = $res->fetch()) { |
|
66 | + $filter_types[$line["id"]] = $line["name"]; |
|
67 | + } |
|
68 | 68 | |
69 | - $scope_qparts = array(); |
|
69 | + $scope_qparts = array(); |
|
70 | 70 | |
71 | - $rctr = 0; |
|
72 | - foreach (clean($_REQUEST["rule"]) as $r) { |
|
73 | - $rule = json_decode($r, true); |
|
71 | + $rctr = 0; |
|
72 | + foreach (clean($_REQUEST["rule"]) as $r) { |
|
73 | + $rule = json_decode($r, true); |
|
74 | 74 | |
75 | - if ($rule && $rctr < 5) { |
|
76 | - $rule["type"] = $filter_types[$rule["filter_type"]]; |
|
77 | - unset($rule["filter_type"]); |
|
75 | + if ($rule && $rctr < 5) { |
|
76 | + $rule["type"] = $filter_types[$rule["filter_type"]]; |
|
77 | + unset($rule["filter_type"]); |
|
78 | 78 | |
79 | - $scope_inner_qparts = []; |
|
80 | - foreach ($rule["feed_id"] as $feed_id) { |
|
79 | + $scope_inner_qparts = []; |
|
80 | + foreach ($rule["feed_id"] as $feed_id) { |
|
81 | 81 | |
82 | 82 | if (strpos($feed_id, "CAT:") === 0) { |
83 | 83 | $cat_id = (int) substr($feed_id, 4); |
@@ -88,29 +88,29 @@ discard block |
||
88 | 88 | } |
89 | 89 | |
90 | 90 | if (count($scope_inner_qparts) > 0) { |
91 | - array_push($scope_qparts, "(".implode(" OR ", $scope_inner_qparts).")"); |
|
91 | + array_push($scope_qparts, "(".implode(" OR ", $scope_inner_qparts).")"); |
|
92 | 92 | } |
93 | 93 | |
94 | - array_push($filter["rules"], $rule); |
|
94 | + array_push($filter["rules"], $rule); |
|
95 | 95 | |
96 | - ++$rctr; |
|
97 | - } else { |
|
98 | - break; |
|
99 | - } |
|
100 | - } |
|
96 | + ++$rctr; |
|
97 | + } else { |
|
98 | + break; |
|
99 | + } |
|
100 | + } |
|
101 | 101 | |
102 | - if (count($scope_qparts) == 0) $scope_qparts = ["true"]; |
|
102 | + if (count($scope_qparts) == 0) $scope_qparts = ["true"]; |
|
103 | 103 | |
104 | - $glue = $filter['match_any_rule'] ? " OR " : " AND "; |
|
105 | - $scope_qpart = join($glue, $scope_qparts); |
|
104 | + $glue = $filter['match_any_rule'] ? " OR " : " AND "; |
|
105 | + $scope_qpart = join($glue, $scope_qparts); |
|
106 | 106 | |
107 | - if (!$scope_qpart) $scope_qpart = "true"; |
|
107 | + if (!$scope_qpart) $scope_qpart = "true"; |
|
108 | 108 | |
109 | - $rv = array(); |
|
109 | + $rv = array(); |
|
110 | 110 | |
111 | - //while ($found < $limit && $offset < $limit * 1000 && time() - $started < ini_get("max_execution_time") * 0.7) { |
|
111 | + //while ($found < $limit && $offset < $limit * 1000 && time() - $started < ini_get("max_execution_time") * 0.7) { |
|
112 | 112 | |
113 | - $sth = $this->pdo->prepare("SELECT ttrss_entries.id, |
|
113 | + $sth = $this->pdo->prepare("SELECT ttrss_entries.id, |
|
114 | 114 | ttrss_entries.title, |
115 | 115 | ttrss_feeds.id AS feed_id, |
116 | 116 | ttrss_feeds.title AS feed_title, |
@@ -130,58 +130,58 @@ discard block |
||
130 | 130 | ttrss_user_entries.owner_uid = ? |
131 | 131 | ORDER BY date_entered DESC LIMIT $limit OFFSET $offset"); |
132 | 132 | |
133 | - $sth->execute([$_SESSION['uid']]); |
|
133 | + $sth->execute([$_SESSION['uid']]); |
|
134 | 134 | |
135 | - while ($line = $sth->fetch()) { |
|
135 | + while ($line = $sth->fetch()) { |
|
136 | 136 | |
137 | - $rc = RSSUtils::get_article_filters(array($filter), $line['title'], $line['content'], $line['link'], |
|
138 | - $line['author'], explode(",", $line['tag_cache'])); |
|
137 | + $rc = RSSUtils::get_article_filters(array($filter), $line['title'], $line['content'], $line['link'], |
|
138 | + $line['author'], explode(",", $line['tag_cache'])); |
|
139 | 139 | |
140 | - if (count($rc) > 0) { |
|
140 | + if (count($rc) > 0) { |
|
141 | 141 | |
142 | - $line["content_preview"] = truncate_string(strip_tags($line["content"]), 200, '…'); |
|
142 | + $line["content_preview"] = truncate_string(strip_tags($line["content"]), 200, '…'); |
|
143 | 143 | |
144 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
|
145 | - $line = $p->hook_query_headlines($line, 100); |
|
146 | - } |
|
144 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
|
145 | + $line = $p->hook_query_headlines($line, 100); |
|
146 | + } |
|
147 | 147 | |
148 | - $content_preview = $line["content_preview"]; |
|
148 | + $content_preview = $line["content_preview"]; |
|
149 | 149 | |
150 | - $tmp = "<li><span class='title'>".$line["title"]."</span><br/>". |
|
151 | - "<span class='feed'>".$line['feed_title']."</span>, <span class='date'>".mb_substr($line["date_entered"], 0, 16)."</span>". |
|
152 | - "<div class='preview text-muted'>".$content_preview."</div>". |
|
153 | - "</li>"; |
|
150 | + $tmp = "<li><span class='title'>".$line["title"]."</span><br/>". |
|
151 | + "<span class='feed'>".$line['feed_title']."</span>, <span class='date'>".mb_substr($line["date_entered"], 0, 16)."</span>". |
|
152 | + "<div class='preview text-muted'>".$content_preview."</div>". |
|
153 | + "</li>"; |
|
154 | 154 | |
155 | - array_push($rv, $tmp); |
|
155 | + array_push($rv, $tmp); |
|
156 | 156 | |
157 | - } |
|
158 | - } |
|
157 | + } |
|
158 | + } |
|
159 | 159 | |
160 | - print json_encode($rv); |
|
161 | - } |
|
160 | + print json_encode($rv); |
|
161 | + } |
|
162 | 162 | |
163 | - public function testFilter() { |
|
163 | + public function testFilter() { |
|
164 | 164 | |
165 | - if (isset($_REQUEST["offset"])) { |
|
166 | - return $this->testFilterDo(); |
|
167 | - } |
|
165 | + if (isset($_REQUEST["offset"])) { |
|
166 | + return $this->testFilterDo(); |
|
167 | + } |
|
168 | 168 | |
169 | - //print __("Articles matching this filter:"); |
|
169 | + //print __("Articles matching this filter:"); |
|
170 | 170 | |
171 | - print "<div><img id='prefFilterLoadingIndicator' src='images/indicator_tiny.gif'> <span id='prefFilterProgressMsg'>Looking for articles...</span></div>"; |
|
171 | + print "<div><img id='prefFilterLoadingIndicator' src='images/indicator_tiny.gif'> <span id='prefFilterProgressMsg'>Looking for articles...</span></div>"; |
|
172 | 172 | |
173 | - print "<ul class='panel panel-scrollable list list-unstyled' id='prefFilterTestResultList'>"; |
|
174 | - print "</ul>"; |
|
173 | + print "<ul class='panel panel-scrollable list list-unstyled' id='prefFilterTestResultList'>"; |
|
174 | + print "</ul>"; |
|
175 | 175 | |
176 | - print "<footer class='text-center'>"; |
|
177 | - print "<button dojoType='dijit.form.Button' onclick=\"dijit.byId('filterTestDlg').hide()\">". |
|
178 | - __('Close this window')."</button>"; |
|
179 | - print "</footer>"; |
|
176 | + print "<footer class='text-center'>"; |
|
177 | + print "<button dojoType='dijit.form.Button' onclick=\"dijit.byId('filterTestDlg').hide()\">". |
|
178 | + __('Close this window')."</button>"; |
|
179 | + print "</footer>"; |
|
180 | 180 | |
181 | - } |
|
181 | + } |
|
182 | 182 | |
183 | - private function getfilterrules_list($filter_id) { |
|
184 | - $sth = $this->pdo->prepare("SELECT reg_exp, |
|
183 | + private function getfilterrules_list($filter_id) { |
|
184 | + $sth = $this->pdo->prepare("SELECT reg_exp, |
|
185 | 185 | inverse, |
186 | 186 | match_on, |
187 | 187 | feed_id, |
@@ -193,15 +193,15 @@ discard block |
||
193 | 193 | WHERE |
194 | 194 | filter_id = ? AND filter_type = ttrss_filter_types.id |
195 | 195 | ORDER BY reg_exp"); |
196 | - $sth->execute([$filter_id]); |
|
196 | + $sth->execute([$filter_id]); |
|
197 | 197 | |
198 | - $rv = ""; |
|
198 | + $rv = ""; |
|
199 | 199 | |
200 | - while ($line = $sth->fetch()) { |
|
200 | + while ($line = $sth->fetch()) { |
|
201 | 201 | |
202 | - if ($line["match_on"]) { |
|
203 | - $feeds = json_decode($line["match_on"], true); |
|
204 | - $feeds_fmt = []; |
|
202 | + if ($line["match_on"]) { |
|
203 | + $feeds = json_decode($line["match_on"], true); |
|
204 | + $feeds_fmt = []; |
|
205 | 205 | |
206 | 206 | foreach ($feeds as $feed_id) { |
207 | 207 | |
@@ -227,27 +227,27 @@ discard block |
||
227 | 227 | |
228 | 228 | # $where = $line["cat_id"] . "/" . $line["feed_id"]; |
229 | 229 | |
230 | - $inverse = $line["inverse"] ? "inverse" : ""; |
|
230 | + $inverse = $line["inverse"] ? "inverse" : ""; |
|
231 | 231 | |
232 | - $rv .= "<li class='$inverse'>".T_sprintf("%s on %s in %s %s", |
|
233 | - htmlspecialchars($line["reg_exp"]), |
|
234 | - $line["field"], |
|
235 | - $where, |
|
236 | - $line["inverse"] ? __("(inverse)") : "")."</li>"; |
|
237 | - } |
|
232 | + $rv .= "<li class='$inverse'>".T_sprintf("%s on %s in %s %s", |
|
233 | + htmlspecialchars($line["reg_exp"]), |
|
234 | + $line["field"], |
|
235 | + $where, |
|
236 | + $line["inverse"] ? __("(inverse)") : "")."</li>"; |
|
237 | + } |
|
238 | 238 | |
239 | - return $rv; |
|
240 | - } |
|
239 | + return $rv; |
|
240 | + } |
|
241 | 241 | |
242 | - public function getfiltertree() { |
|
243 | - $root = array(); |
|
244 | - $root['id'] = 'root'; |
|
245 | - $root['name'] = __('Filters'); |
|
246 | - $root['items'] = array(); |
|
242 | + public function getfiltertree() { |
|
243 | + $root = array(); |
|
244 | + $root['id'] = 'root'; |
|
245 | + $root['name'] = __('Filters'); |
|
246 | + $root['items'] = array(); |
|
247 | 247 | |
248 | - $filter_search = $_SESSION["prefs_filter_search"]; |
|
248 | + $filter_search = $_SESSION["prefs_filter_search"]; |
|
249 | 249 | |
250 | - $sth = $this->pdo->prepare("SELECT *, |
|
250 | + $sth = $this->pdo->prepare("SELECT *, |
|
251 | 251 | (SELECT action_param FROM ttrss_filters2_actions |
252 | 252 | WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_param, |
253 | 253 | (SELECT action_id FROM ttrss_filters2_actions |
@@ -259,281 +259,281 @@ discard block |
||
259 | 259 | WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS reg_exp |
260 | 260 | FROM ttrss_filters2 WHERE |
261 | 261 | owner_uid = ? ORDER BY order_id, title"); |
262 | - $sth->execute([$_SESSION['uid']]); |
|
262 | + $sth->execute([$_SESSION['uid']]); |
|
263 | 263 | |
264 | - $folder = array(); |
|
265 | - $folder['items'] = array(); |
|
264 | + $folder = array(); |
|
265 | + $folder['items'] = array(); |
|
266 | 266 | |
267 | - while ($line = $sth->fetch()) { |
|
267 | + while ($line = $sth->fetch()) { |
|
268 | 268 | |
269 | - $name = $this->getFilterName($line["id"]); |
|
269 | + $name = $this->getFilterName($line["id"]); |
|
270 | 270 | |
271 | - $match_ok = false; |
|
272 | - if ($filter_search) { |
|
273 | - if (mb_strpos($line['title'], $filter_search) !== false) { |
|
274 | - $match_ok = true; |
|
275 | - } |
|
271 | + $match_ok = false; |
|
272 | + if ($filter_search) { |
|
273 | + if (mb_strpos($line['title'], $filter_search) !== false) { |
|
274 | + $match_ok = true; |
|
275 | + } |
|
276 | 276 | |
277 | - $rules_sth = $this->pdo->prepare("SELECT reg_exp |
|
277 | + $rules_sth = $this->pdo->prepare("SELECT reg_exp |
|
278 | 278 | FROM ttrss_filters2_rules WHERE filter_id = ?"); |
279 | - $rules_sth->execute([$line['id']]); |
|
280 | - |
|
281 | - while ($rule_line = $rules_sth->fetch()) { |
|
282 | - if (mb_strpos($rule_line['reg_exp'], $filter_search) !== false) { |
|
283 | - $match_ok = true; |
|
284 | - break; |
|
285 | - } |
|
286 | - } |
|
287 | - } |
|
279 | + $rules_sth->execute([$line['id']]); |
|
288 | 280 | |
289 | - if ($line['action_id'] == 7) { |
|
290 | - $label_sth = $this->pdo->prepare("SELECT fg_color, bg_color |
|
281 | + while ($rule_line = $rules_sth->fetch()) { |
|
282 | + if (mb_strpos($rule_line['reg_exp'], $filter_search) !== false) { |
|
283 | + $match_ok = true; |
|
284 | + break; |
|
285 | + } |
|
286 | + } |
|
287 | + } |
|
288 | + |
|
289 | + if ($line['action_id'] == 7) { |
|
290 | + $label_sth = $this->pdo->prepare("SELECT fg_color, bg_color |
|
291 | 291 | FROM ttrss_labels2 WHERE caption = ? AND |
292 | 292 | owner_uid = ?"); |
293 | - $label_sth->execute([$line['action_param'], $_SESSION['uid']]); |
|
293 | + $label_sth->execute([$line['action_param'], $_SESSION['uid']]); |
|
294 | 294 | |
295 | - if ($label_row = $label_sth->fetch()) { |
|
296 | - //$fg_color = $label_row["fg_color"]; |
|
297 | - $bg_color = $label_row["bg_color"]; |
|
295 | + if ($label_row = $label_sth->fetch()) { |
|
296 | + //$fg_color = $label_row["fg_color"]; |
|
297 | + $bg_color = $label_row["bg_color"]; |
|
298 | 298 | |
299 | - $name[1] = "<i class=\"material-icons\" style='color : $bg_color; margin-right : 4px'>label</i>".$name[1]; |
|
300 | - } |
|
301 | - } |
|
299 | + $name[1] = "<i class=\"material-icons\" style='color : $bg_color; margin-right : 4px'>label</i>".$name[1]; |
|
300 | + } |
|
301 | + } |
|
302 | 302 | |
303 | - $filter = array(); |
|
304 | - $filter['id'] = 'FILTER:'.$line['id']; |
|
305 | - $filter['bare_id'] = $line['id']; |
|
306 | - $filter['name'] = $name[0]; |
|
307 | - $filter['param'] = $name[1]; |
|
308 | - $filter['checkbox'] = false; |
|
309 | - $filter['last_triggered'] = $line["last_triggered"] ? make_local_datetime($line["last_triggered"], false) : null; |
|
310 | - $filter['enabled'] = $line["enabled"]; |
|
311 | - $filter['rules'] = $this->getfilterrules_list($line['id']); |
|
312 | - |
|
313 | - if (!$filter_search || $match_ok) { |
|
314 | - array_push($folder['items'], $filter); |
|
315 | - } |
|
316 | - } |
|
303 | + $filter = array(); |
|
304 | + $filter['id'] = 'FILTER:'.$line['id']; |
|
305 | + $filter['bare_id'] = $line['id']; |
|
306 | + $filter['name'] = $name[0]; |
|
307 | + $filter['param'] = $name[1]; |
|
308 | + $filter['checkbox'] = false; |
|
309 | + $filter['last_triggered'] = $line["last_triggered"] ? make_local_datetime($line["last_triggered"], false) : null; |
|
310 | + $filter['enabled'] = $line["enabled"]; |
|
311 | + $filter['rules'] = $this->getfilterrules_list($line['id']); |
|
312 | + |
|
313 | + if (!$filter_search || $match_ok) { |
|
314 | + array_push($folder['items'], $filter); |
|
315 | + } |
|
316 | + } |
|
317 | 317 | |
318 | - $root['items'] = $folder['items']; |
|
318 | + $root['items'] = $folder['items']; |
|
319 | 319 | |
320 | - $fl = array(); |
|
321 | - $fl['identifier'] = 'id'; |
|
322 | - $fl['label'] = 'name'; |
|
323 | - $fl['items'] = array($root); |
|
320 | + $fl = array(); |
|
321 | + $fl['identifier'] = 'id'; |
|
322 | + $fl['label'] = 'name'; |
|
323 | + $fl['items'] = array($root); |
|
324 | 324 | |
325 | - print json_encode($fl); |
|
326 | - return; |
|
327 | - } |
|
325 | + print json_encode($fl); |
|
326 | + return; |
|
327 | + } |
|
328 | 328 | |
329 | - public function edit() { |
|
329 | + public function edit() { |
|
330 | 330 | |
331 | - $filter_id = clean($_REQUEST["id"]); |
|
331 | + $filter_id = clean($_REQUEST["id"]); |
|
332 | 332 | |
333 | - $sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2 |
|
333 | + $sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2 |
|
334 | 334 | WHERE id = ? AND owner_uid = ?"); |
335 | - $sth->execute([$filter_id, $_SESSION['uid']]); |
|
335 | + $sth->execute([$filter_id, $_SESSION['uid']]); |
|
336 | 336 | |
337 | - if ($row = $sth->fetch()) { |
|
337 | + if ($row = $sth->fetch()) { |
|
338 | 338 | |
339 | - $enabled = $row["enabled"]; |
|
340 | - $match_any_rule = $row["match_any_rule"]; |
|
341 | - $inverse = $row["inverse"]; |
|
342 | - $title = htmlspecialchars($row["title"]); |
|
339 | + $enabled = $row["enabled"]; |
|
340 | + $match_any_rule = $row["match_any_rule"]; |
|
341 | + $inverse = $row["inverse"]; |
|
342 | + $title = htmlspecialchars($row["title"]); |
|
343 | 343 | |
344 | - print "<form id='filter_edit_form' onsubmit='return false'>"; |
|
344 | + print "<form id='filter_edit_form' onsubmit='return false'>"; |
|
345 | 345 | |
346 | - print_hidden("op", "pref-filters"); |
|
347 | - print_hidden("id", "$filter_id"); |
|
348 | - print_hidden("method", "editSave"); |
|
349 | - print_hidden("csrf_token", $_SESSION['csrf_token']); |
|
346 | + print_hidden("op", "pref-filters"); |
|
347 | + print_hidden("id", "$filter_id"); |
|
348 | + print_hidden("method", "editSave"); |
|
349 | + print_hidden("csrf_token", $_SESSION['csrf_token']); |
|
350 | 350 | |
351 | - print "<header>".__("Caption")."</header>"; |
|
352 | - print "<section>"; |
|
353 | - print "<input required=\"true\" dojoType=\"dijit.form.ValidationTextBox\" style=\"width : 20em;\" name=\"title\" value=\"$title\">"; |
|
354 | - print "</section>"; |
|
351 | + print "<header>".__("Caption")."</header>"; |
|
352 | + print "<section>"; |
|
353 | + print "<input required=\"true\" dojoType=\"dijit.form.ValidationTextBox\" style=\"width : 20em;\" name=\"title\" value=\"$title\">"; |
|
354 | + print "</section>"; |
|
355 | 355 | |
356 | - print "<header class='horizontal'>".__("Match")."</header>"; |
|
357 | - print "<section>"; |
|
356 | + print "<header class='horizontal'>".__("Match")."</header>"; |
|
357 | + print "<section>"; |
|
358 | 358 | |
359 | - print "<div dojoType=\"fox.Toolbar\">"; |
|
359 | + print "<div dojoType=\"fox.Toolbar\">"; |
|
360 | 360 | |
361 | - print "<div dojoType=\"fox.form.DropDownButton\">". |
|
362 | - "<span>".__('Select')."</span>"; |
|
363 | - print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
364 | - print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\" |
|
361 | + print "<div dojoType=\"fox.form.DropDownButton\">". |
|
362 | + "<span>".__('Select')."</span>"; |
|
363 | + print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
364 | + print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\" |
|
365 | 365 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; |
366 | - print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\" |
|
366 | + print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\" |
|
367 | 367 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; |
368 | - print "</div></div>"; |
|
368 | + print "</div></div>"; |
|
369 | 369 | |
370 | - print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">". |
|
371 | - __('Add')."</button> "; |
|
370 | + print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">". |
|
371 | + __('Add')."</button> "; |
|
372 | 372 | |
373 | - print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">". |
|
374 | - __('Delete')."</button> "; |
|
373 | + print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">". |
|
374 | + __('Delete')."</button> "; |
|
375 | 375 | |
376 | - print "</div>"; |
|
376 | + print "</div>"; |
|
377 | 377 | |
378 | - print "<ul id='filterDlg_Matches'>"; |
|
378 | + print "<ul id='filterDlg_Matches'>"; |
|
379 | 379 | |
380 | - $rules_sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_rules |
|
380 | + $rules_sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_rules |
|
381 | 381 | WHERE filter_id = ? ORDER BY reg_exp, id"); |
382 | - $rules_sth->execute([$filter_id]); |
|
383 | - |
|
384 | - while ($line = $rules_sth->fetch()) { |
|
385 | - if ($line["match_on"]) { |
|
386 | - $line["feed_id"] = json_decode($line["match_on"], true); |
|
387 | - } else { |
|
388 | - if ($line["cat_filter"]) { |
|
389 | - $feed_id = "CAT:".(int) $line["cat_id"]; |
|
390 | - } else { |
|
391 | - $feed_id = (int) $line["feed_id"]; |
|
392 | - } |
|
393 | - |
|
394 | - $line["feed_id"] = ["".$feed_id]; // set item type to string for in_array() |
|
395 | - } |
|
396 | - |
|
397 | - unset($line["cat_filter"]); |
|
398 | - unset($line["cat_id"]); |
|
399 | - unset($line["filter_id"]); |
|
400 | - unset($line["id"]); |
|
401 | - if (!$line["inverse"]) { |
|
402 | - unset($line["inverse"]); |
|
403 | - } |
|
404 | - unset($line["match_on"]); |
|
405 | - |
|
406 | - $data = htmlspecialchars(json_encode($line)); |
|
407 | - |
|
408 | - print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='Lists.onRowChecked(this)'>". |
|
409 | - "<span onclick=\"dijit.byId('filterEditDlg').editRule(this)\">".$this->getRuleName($line)."</span>". |
|
410 | - "<input type='hidden' name='rule[]' value=\"$data\"/></li>"; |
|
411 | - } |
|
382 | + $rules_sth->execute([$filter_id]); |
|
383 | + |
|
384 | + while ($line = $rules_sth->fetch()) { |
|
385 | + if ($line["match_on"]) { |
|
386 | + $line["feed_id"] = json_decode($line["match_on"], true); |
|
387 | + } else { |
|
388 | + if ($line["cat_filter"]) { |
|
389 | + $feed_id = "CAT:".(int) $line["cat_id"]; |
|
390 | + } else { |
|
391 | + $feed_id = (int) $line["feed_id"]; |
|
392 | + } |
|
412 | 393 | |
413 | - print "</ul>"; |
|
394 | + $line["feed_id"] = ["".$feed_id]; // set item type to string for in_array() |
|
395 | + } |
|
414 | 396 | |
415 | - print "</section>"; |
|
397 | + unset($line["cat_filter"]); |
|
398 | + unset($line["cat_id"]); |
|
399 | + unset($line["filter_id"]); |
|
400 | + unset($line["id"]); |
|
401 | + if (!$line["inverse"]) { |
|
402 | + unset($line["inverse"]); |
|
403 | + } |
|
404 | + unset($line["match_on"]); |
|
416 | 405 | |
417 | - print "<header class='horizontal'>".__("Apply actions")."</header>"; |
|
406 | + $data = htmlspecialchars(json_encode($line)); |
|
418 | 407 | |
419 | - print "<section>"; |
|
408 | + print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='Lists.onRowChecked(this)'>". |
|
409 | + "<span onclick=\"dijit.byId('filterEditDlg').editRule(this)\">".$this->getRuleName($line)."</span>". |
|
410 | + "<input type='hidden' name='rule[]' value=\"$data\"/></li>"; |
|
411 | + } |
|
412 | + |
|
413 | + print "</ul>"; |
|
414 | + |
|
415 | + print "</section>"; |
|
420 | 416 | |
421 | - print "<div dojoType=\"fox.Toolbar\">"; |
|
417 | + print "<header class='horizontal'>".__("Apply actions")."</header>"; |
|
422 | 418 | |
423 | - print "<div dojoType=\"fox.form.DropDownButton\">". |
|
424 | - "<span>".__('Select')."</span>"; |
|
425 | - print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
426 | - print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\" |
|
419 | + print "<section>"; |
|
420 | + |
|
421 | + print "<div dojoType=\"fox.Toolbar\">"; |
|
422 | + |
|
423 | + print "<div dojoType=\"fox.form.DropDownButton\">". |
|
424 | + "<span>".__('Select')."</span>"; |
|
425 | + print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
426 | + print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\" |
|
427 | 427 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; |
428 | - print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\" |
|
428 | + print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\" |
|
429 | 429 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; |
430 | - print "</div></div>"; |
|
430 | + print "</div></div>"; |
|
431 | 431 | |
432 | - print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">". |
|
433 | - __('Add')."</button> "; |
|
432 | + print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">". |
|
433 | + __('Add')."</button> "; |
|
434 | 434 | |
435 | - print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">". |
|
436 | - __('Delete')."</button> "; |
|
435 | + print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">". |
|
436 | + __('Delete')."</button> "; |
|
437 | 437 | |
438 | - print "</div>"; |
|
438 | + print "</div>"; |
|
439 | 439 | |
440 | - print "<ul id='filterDlg_Actions'>"; |
|
440 | + print "<ul id='filterDlg_Actions'>"; |
|
441 | 441 | |
442 | - $actions_sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_actions |
|
442 | + $actions_sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_actions |
|
443 | 443 | WHERE filter_id = ? ORDER BY id"); |
444 | - $actions_sth->execute([$filter_id]); |
|
444 | + $actions_sth->execute([$filter_id]); |
|
445 | 445 | |
446 | - while ($line = $actions_sth->fetch()) { |
|
447 | - $line["action_param_label"] = $line["action_param"]; |
|
446 | + while ($line = $actions_sth->fetch()) { |
|
447 | + $line["action_param_label"] = $line["action_param"]; |
|
448 | 448 | |
449 | - unset($line["filter_id"]); |
|
450 | - unset($line["id"]); |
|
449 | + unset($line["filter_id"]); |
|
450 | + unset($line["id"]); |
|
451 | 451 | |
452 | - $data = htmlspecialchars(json_encode($line)); |
|
452 | + $data = htmlspecialchars(json_encode($line)); |
|
453 | 453 | |
454 | - print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='Lists.onRowChecked(this)'>". |
|
455 | - "<span onclick=\"dijit.byId('filterEditDlg').editAction(this)\">".$this->getActionName($line)."</span>". |
|
456 | - "<input type='hidden' name='action[]' value=\"$data\"/></li>"; |
|
457 | - } |
|
454 | + print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='Lists.onRowChecked(this)'>". |
|
455 | + "<span onclick=\"dijit.byId('filterEditDlg').editAction(this)\">".$this->getActionName($line)."</span>". |
|
456 | + "<input type='hidden' name='action[]' value=\"$data\"/></li>"; |
|
457 | + } |
|
458 | 458 | |
459 | - print "</ul>"; |
|
459 | + print "</ul>"; |
|
460 | 460 | |
461 | - print "</section>"; |
|
461 | + print "</section>"; |
|
462 | 462 | |
463 | - print "<header>".__("Options")."</header>"; |
|
464 | - print "<section>"; |
|
463 | + print "<header>".__("Options")."</header>"; |
|
464 | + print "<section>"; |
|
465 | 465 | |
466 | - if ($enabled) { |
|
467 | - $checked = "checked=\"1\""; |
|
468 | - } else { |
|
469 | - $checked = ""; |
|
470 | - } |
|
466 | + if ($enabled) { |
|
467 | + $checked = "checked=\"1\""; |
|
468 | + } else { |
|
469 | + $checked = ""; |
|
470 | + } |
|
471 | 471 | |
472 | - print "<fieldset class='narrow'>"; |
|
473 | - print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked> |
|
472 | + print "<fieldset class='narrow'>"; |
|
473 | + print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked> |
|
474 | 474 | ".__('Enabled')."</label>"; |
475 | 475 | |
476 | - if ($match_any_rule) { |
|
477 | - $checked = "checked=\"1\""; |
|
478 | - } else { |
|
479 | - $checked = ""; |
|
480 | - } |
|
476 | + if ($match_any_rule) { |
|
477 | + $checked = "checked=\"1\""; |
|
478 | + } else { |
|
479 | + $checked = ""; |
|
480 | + } |
|
481 | 481 | |
482 | - print "</fieldset><fieldset class='narrow'>"; |
|
482 | + print "</fieldset><fieldset class='narrow'>"; |
|
483 | 483 | |
484 | - print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\" $checked> |
|
484 | + print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\" $checked> |
|
485 | 485 | ".__('Match any rule')."</label>"; |
486 | 486 | |
487 | - print "</fieldset><fieldset class='narrow'>"; |
|
487 | + print "</fieldset><fieldset class='narrow'>"; |
|
488 | 488 | |
489 | - if ($inverse) { |
|
490 | - $checked = "checked=\"1\""; |
|
491 | - } else { |
|
492 | - $checked = ""; |
|
493 | - } |
|
489 | + if ($inverse) { |
|
490 | + $checked = "checked=\"1\""; |
|
491 | + } else { |
|
492 | + $checked = ""; |
|
493 | + } |
|
494 | 494 | |
495 | - print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked> |
|
495 | + print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked> |
|
496 | 496 | ".__('Inverse matching')."</label>"; |
497 | 497 | |
498 | - print "</fieldset>"; |
|
498 | + print "</fieldset>"; |
|
499 | 499 | |
500 | - print "</section>"; |
|
500 | + print "</section>"; |
|
501 | 501 | |
502 | - print "<footer>"; |
|
502 | + print "<footer>"; |
|
503 | 503 | |
504 | - print "<div style=\"float : left\">"; |
|
505 | - print "<button dojoType=\"dijit.form.Button\" class=\"alt-danger\" onclick=\"return dijit.byId('filterEditDlg').removeFilter()\">". |
|
506 | - __('Remove')."</button>"; |
|
507 | - print "</div>"; |
|
504 | + print "<div style=\"float : left\">"; |
|
505 | + print "<button dojoType=\"dijit.form.Button\" class=\"alt-danger\" onclick=\"return dijit.byId('filterEditDlg').removeFilter()\">". |
|
506 | + __('Remove')."</button>"; |
|
507 | + print "</div>"; |
|
508 | 508 | |
509 | - print "<button dojoType=\"dijit.form.Button\" class=\"alt-info\" onclick=\"return dijit.byId('filterEditDlg').test()\">". |
|
510 | - __('Test')."</button> "; |
|
509 | + print "<button dojoType=\"dijit.form.Button\" class=\"alt-info\" onclick=\"return dijit.byId('filterEditDlg').test()\">". |
|
510 | + __('Test')."</button> "; |
|
511 | 511 | |
512 | - print "<button dojoType=\"dijit.form.Button\" type=\"submit\" class=\"alt-primary\" onclick=\"return dijit.byId('filterEditDlg').execute()\">". |
|
513 | - __('Save')."</button> "; |
|
512 | + print "<button dojoType=\"dijit.form.Button\" type=\"submit\" class=\"alt-primary\" onclick=\"return dijit.byId('filterEditDlg').execute()\">". |
|
513 | + __('Save')."</button> "; |
|
514 | 514 | |
515 | - print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">". |
|
516 | - __('Cancel')."</button>"; |
|
515 | + print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">". |
|
516 | + __('Cancel')."</button>"; |
|
517 | 517 | |
518 | - print "</footer>"; |
|
519 | - print "</form>"; |
|
518 | + print "</footer>"; |
|
519 | + print "</form>"; |
|
520 | 520 | |
521 | - } |
|
522 | - } |
|
521 | + } |
|
522 | + } |
|
523 | 523 | |
524 | - private function getRuleName($rule) { |
|
525 | - if (!$rule) { |
|
526 | - $rule = json_decode(clean($_REQUEST["rule"]), true); |
|
527 | - } |
|
524 | + private function getRuleName($rule) { |
|
525 | + if (!$rule) { |
|
526 | + $rule = json_decode(clean($_REQUEST["rule"]), true); |
|
527 | + } |
|
528 | 528 | |
529 | - $feeds = $rule["feed_id"]; |
|
530 | - $feeds_fmt = []; |
|
529 | + $feeds = $rule["feed_id"]; |
|
530 | + $feeds_fmt = []; |
|
531 | 531 | |
532 | - if (!is_array($feeds)) { |
|
533 | - $feeds = [$feeds]; |
|
534 | - } |
|
532 | + if (!is_array($feeds)) { |
|
533 | + $feeds = [$feeds]; |
|
534 | + } |
|
535 | 535 | |
536 | - foreach ($feeds as $feed_id) { |
|
536 | + foreach ($feeds as $feed_id) { |
|
537 | 537 | |
538 | 538 | if (strpos($feed_id, "CAT:") === 0) { |
539 | 539 | $feed_id = (int) substr($feed_id, 4); |
@@ -548,276 +548,276 @@ discard block |
||
548 | 548 | |
549 | 549 | $feed = implode(", ", $feeds_fmt); |
550 | 550 | |
551 | - $sth = $this->pdo->prepare("SELECT description FROM ttrss_filter_types |
|
551 | + $sth = $this->pdo->prepare("SELECT description FROM ttrss_filter_types |
|
552 | 552 | WHERE id = ?"); |
553 | - $sth->execute([(int) $rule["filter_type"]]); |
|
553 | + $sth->execute([(int) $rule["filter_type"]]); |
|
554 | 554 | |
555 | - if ($row = $sth->fetch()) { |
|
556 | - $filter_type = $row["description"]; |
|
557 | - } else { |
|
558 | - $filter_type = "?UNKNOWN?"; |
|
559 | - } |
|
555 | + if ($row = $sth->fetch()) { |
|
556 | + $filter_type = $row["description"]; |
|
557 | + } else { |
|
558 | + $filter_type = "?UNKNOWN?"; |
|
559 | + } |
|
560 | 560 | |
561 | - $inverse = isset($rule["inverse"]) ? "inverse" : ""; |
|
561 | + $inverse = isset($rule["inverse"]) ? "inverse" : ""; |
|
562 | 562 | |
563 | - return "<span class='filterRule $inverse'>". |
|
564 | - T_sprintf("%s on %s in %s %s", htmlspecialchars($rule["reg_exp"]), |
|
565 | - $filter_type, $feed, isset($rule["inverse"]) ? __("(inverse)") : "")."</span>"; |
|
566 | - } |
|
563 | + return "<span class='filterRule $inverse'>". |
|
564 | + T_sprintf("%s on %s in %s %s", htmlspecialchars($rule["reg_exp"]), |
|
565 | + $filter_type, $feed, isset($rule["inverse"]) ? __("(inverse)") : "")."</span>"; |
|
566 | + } |
|
567 | 567 | |
568 | - public function printRuleName() { |
|
569 | - print $this->getRuleName(json_decode(clean($_REQUEST["rule"]), true)); |
|
570 | - } |
|
568 | + public function printRuleName() { |
|
569 | + print $this->getRuleName(json_decode(clean($_REQUEST["rule"]), true)); |
|
570 | + } |
|
571 | 571 | |
572 | - private function getActionName($action) { |
|
573 | - $sth = $this->pdo->prepare("SELECT description FROM |
|
572 | + private function getActionName($action) { |
|
573 | + $sth = $this->pdo->prepare("SELECT description FROM |
|
574 | 574 | ttrss_filter_actions WHERE id = ?"); |
575 | - $sth->execute([(int) $action["action_id"]]); |
|
575 | + $sth->execute([(int) $action["action_id"]]); |
|
576 | 576 | |
577 | - $title = ""; |
|
577 | + $title = ""; |
|
578 | 578 | |
579 | - if ($row = $sth->fetch()) { |
|
579 | + if ($row = $sth->fetch()) { |
|
580 | 580 | |
581 | - $title = __($row["description"]); |
|
581 | + $title = __($row["description"]); |
|
582 | 582 | |
583 | - if ($action["action_id"] == 4 || $action["action_id"] == 6 || |
|
584 | - $action["action_id"] == 7) |
|
585 | - $title .= ": ".$action["action_param"]; |
|
583 | + if ($action["action_id"] == 4 || $action["action_id"] == 6 || |
|
584 | + $action["action_id"] == 7) |
|
585 | + $title .= ": ".$action["action_param"]; |
|
586 | 586 | |
587 | - if ($action["action_id"] == 9) { |
|
588 | - list ($pfclass, $pfaction) = explode(":", $action["action_param"]); |
|
587 | + if ($action["action_id"] == 9) { |
|
588 | + list ($pfclass, $pfaction) = explode(":", $action["action_param"]); |
|
589 | 589 | |
590 | - $filter_actions = PluginHost::getInstance()->get_filter_actions(); |
|
590 | + $filter_actions = PluginHost::getInstance()->get_filter_actions(); |
|
591 | 591 | |
592 | - foreach ($filter_actions as $fclass => $factions) { |
|
593 | - foreach ($factions as $faction) { |
|
594 | - if ($pfaction == $faction["action"] && $pfclass == $fclass) { |
|
595 | - $title .= ": ".$fclass.": ".$faction["description"]; |
|
596 | - break; |
|
597 | - } |
|
598 | - } |
|
599 | - } |
|
600 | - } |
|
601 | - } |
|
592 | + foreach ($filter_actions as $fclass => $factions) { |
|
593 | + foreach ($factions as $faction) { |
|
594 | + if ($pfaction == $faction["action"] && $pfclass == $fclass) { |
|
595 | + $title .= ": ".$fclass.": ".$faction["description"]; |
|
596 | + break; |
|
597 | + } |
|
598 | + } |
|
599 | + } |
|
600 | + } |
|
601 | + } |
|
602 | 602 | |
603 | - return $title; |
|
604 | - } |
|
603 | + return $title; |
|
604 | + } |
|
605 | 605 | |
606 | - public function printActionName() { |
|
607 | - print $this->getActionName(json_decode(clean($_REQUEST["action"]), true)); |
|
608 | - } |
|
606 | + public function printActionName() { |
|
607 | + print $this->getActionName(json_decode(clean($_REQUEST["action"]), true)); |
|
608 | + } |
|
609 | 609 | |
610 | - public function editSave() { |
|
611 | - if (clean($_REQUEST["savemode"] && $_REQUEST["savemode"]) == "test") { |
|
612 | - return $this->testFilter(); |
|
613 | - } |
|
610 | + public function editSave() { |
|
611 | + if (clean($_REQUEST["savemode"] && $_REQUEST["savemode"]) == "test") { |
|
612 | + return $this->testFilter(); |
|
613 | + } |
|
614 | 614 | |
615 | - $filter_id = clean($_REQUEST["id"]); |
|
616 | - $enabled = checkbox_to_sql_bool(clean($_REQUEST["enabled"])); |
|
617 | - $match_any_rule = checkbox_to_sql_bool(clean($_REQUEST["match_any_rule"])); |
|
618 | - $inverse = checkbox_to_sql_bool(clean($_REQUEST["inverse"])); |
|
619 | - $title = clean($_REQUEST["title"]); |
|
615 | + $filter_id = clean($_REQUEST["id"]); |
|
616 | + $enabled = checkbox_to_sql_bool(clean($_REQUEST["enabled"])); |
|
617 | + $match_any_rule = checkbox_to_sql_bool(clean($_REQUEST["match_any_rule"])); |
|
618 | + $inverse = checkbox_to_sql_bool(clean($_REQUEST["inverse"])); |
|
619 | + $title = clean($_REQUEST["title"]); |
|
620 | 620 | |
621 | - $this->pdo->beginTransaction(); |
|
621 | + $this->pdo->beginTransaction(); |
|
622 | 622 | |
623 | - $sth = $this->pdo->prepare("UPDATE ttrss_filters2 SET enabled = ?, |
|
623 | + $sth = $this->pdo->prepare("UPDATE ttrss_filters2 SET enabled = ?, |
|
624 | 624 | match_any_rule = ?, |
625 | 625 | inverse = ?, |
626 | 626 | title = ? |
627 | 627 | WHERE id = ? AND owner_uid = ?"); |
628 | 628 | |
629 | - $sth->execute([$enabled, $match_any_rule, $inverse, $title, $filter_id, $_SESSION['uid']]); |
|
629 | + $sth->execute([$enabled, $match_any_rule, $inverse, $title, $filter_id, $_SESSION['uid']]); |
|
630 | 630 | |
631 | - $this->saveRulesAndActions($filter_id); |
|
631 | + $this->saveRulesAndActions($filter_id); |
|
632 | 632 | |
633 | - $this->pdo->commit(); |
|
634 | - } |
|
633 | + $this->pdo->commit(); |
|
634 | + } |
|
635 | 635 | |
636 | - public function remove() { |
|
636 | + public function remove() { |
|
637 | 637 | |
638 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
639 | - $ids_qmarks = arr_qmarks($ids); |
|
638 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
639 | + $ids_qmarks = arr_qmarks($ids); |
|
640 | 640 | |
641 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_filters2 WHERE id IN ($ids_qmarks) |
|
641 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_filters2 WHERE id IN ($ids_qmarks) |
|
642 | 642 | AND owner_uid = ?"); |
643 | - $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
644 | - } |
|
643 | + $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
644 | + } |
|
645 | 645 | |
646 | - private function saveRulesAndActions($filter_id) |
|
647 | - { |
|
646 | + private function saveRulesAndActions($filter_id) |
|
647 | + { |
|
648 | 648 | |
649 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_filters2_rules WHERE filter_id = ?"); |
|
650 | - $sth->execute([$filter_id]); |
|
649 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_filters2_rules WHERE filter_id = ?"); |
|
650 | + $sth->execute([$filter_id]); |
|
651 | 651 | |
652 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_filters2_actions WHERE filter_id = ?"); |
|
653 | - $sth->execute([$filter_id]); |
|
652 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_filters2_actions WHERE filter_id = ?"); |
|
653 | + $sth->execute([$filter_id]); |
|
654 | 654 | |
655 | - if (!is_array(clean($_REQUEST["rule"]))) { |
|
656 | - $_REQUEST["rule"] = []; |
|
657 | - } |
|
658 | - if (!is_array(clean($_REQUEST["action"]))) { |
|
659 | - $_REQUEST["action"] = []; |
|
660 | - } |
|
655 | + if (!is_array(clean($_REQUEST["rule"]))) { |
|
656 | + $_REQUEST["rule"] = []; |
|
657 | + } |
|
658 | + if (!is_array(clean($_REQUEST["action"]))) { |
|
659 | + $_REQUEST["action"] = []; |
|
660 | + } |
|
661 | 661 | |
662 | - if ($filter_id) { |
|
663 | - /* create rules */ |
|
662 | + if ($filter_id) { |
|
663 | + /* create rules */ |
|
664 | 664 | |
665 | - $rules = array(); |
|
666 | - $actions = array(); |
|
665 | + $rules = array(); |
|
666 | + $actions = array(); |
|
667 | 667 | |
668 | - foreach (clean($_REQUEST["rule"]) as $rule) { |
|
669 | - $rule = json_decode($rule, true); |
|
670 | - unset($rule["id"]); |
|
668 | + foreach (clean($_REQUEST["rule"]) as $rule) { |
|
669 | + $rule = json_decode($rule, true); |
|
670 | + unset($rule["id"]); |
|
671 | 671 | |
672 | - if (array_search($rule, $rules) === false) { |
|
673 | - array_push($rules, $rule); |
|
674 | - } |
|
675 | - } |
|
672 | + if (array_search($rule, $rules) === false) { |
|
673 | + array_push($rules, $rule); |
|
674 | + } |
|
675 | + } |
|
676 | 676 | |
677 | - foreach (clean($_REQUEST["action"]) as $action) { |
|
678 | - $action = json_decode($action, true); |
|
679 | - unset($action["id"]); |
|
677 | + foreach (clean($_REQUEST["action"]) as $action) { |
|
678 | + $action = json_decode($action, true); |
|
679 | + unset($action["id"]); |
|
680 | 680 | |
681 | - if (array_search($action, $actions) === false) { |
|
682 | - array_push($actions, $action); |
|
683 | - } |
|
684 | - } |
|
681 | + if (array_search($action, $actions) === false) { |
|
682 | + array_push($actions, $action); |
|
683 | + } |
|
684 | + } |
|
685 | 685 | |
686 | - $rsth = $this->pdo->prepare("INSERT INTO ttrss_filters2_rules |
|
686 | + $rsth = $this->pdo->prepare("INSERT INTO ttrss_filters2_rules |
|
687 | 687 | (filter_id, reg_exp,filter_type,feed_id,cat_id,match_on,inverse) VALUES |
688 | 688 | (?, ?, ?, NULL, NULL, ?, ?)"); |
689 | 689 | |
690 | - foreach ($rules as $rule) { |
|
691 | - if ($rule) { |
|
690 | + foreach ($rules as $rule) { |
|
691 | + if ($rule) { |
|
692 | 692 | |
693 | - $reg_exp = trim($rule["reg_exp"]); |
|
694 | - $inverse = isset($rule["inverse"]) ? 1 : 0; |
|
693 | + $reg_exp = trim($rule["reg_exp"]); |
|
694 | + $inverse = isset($rule["inverse"]) ? 1 : 0; |
|
695 | 695 | |
696 | - $filter_type = (int) trim($rule["filter_type"]); |
|
697 | - $match_on = json_encode($rule["feed_id"]); |
|
696 | + $filter_type = (int) trim($rule["filter_type"]); |
|
697 | + $match_on = json_encode($rule["feed_id"]); |
|
698 | 698 | |
699 | - $rsth->execute([$filter_id, $reg_exp, $filter_type, $match_on, $inverse]); |
|
700 | - } |
|
701 | - } |
|
699 | + $rsth->execute([$filter_id, $reg_exp, $filter_type, $match_on, $inverse]); |
|
700 | + } |
|
701 | + } |
|
702 | 702 | |
703 | - $asth = $this->pdo->prepare("INSERT INTO ttrss_filters2_actions |
|
703 | + $asth = $this->pdo->prepare("INSERT INTO ttrss_filters2_actions |
|
704 | 704 | (filter_id, action_id, action_param) VALUES |
705 | 705 | (?, ?, ?)"); |
706 | 706 | |
707 | - foreach ($actions as $action) { |
|
708 | - if ($action) { |
|
707 | + foreach ($actions as $action) { |
|
708 | + if ($action) { |
|
709 | 709 | |
710 | - $action_id = (int) $action["action_id"]; |
|
711 | - $action_param = $action["action_param"]; |
|
712 | - $action_param_label = $action["action_param_label"]; |
|
710 | + $action_id = (int) $action["action_id"]; |
|
711 | + $action_param = $action["action_param"]; |
|
712 | + $action_param_label = $action["action_param_label"]; |
|
713 | 713 | |
714 | - if ($action_id == 7) { |
|
715 | - $action_param = $action_param_label; |
|
716 | - } |
|
714 | + if ($action_id == 7) { |
|
715 | + $action_param = $action_param_label; |
|
716 | + } |
|
717 | 717 | |
718 | - if ($action_id == 6) { |
|
719 | - $action_param = (int) str_replace("+", "", $action_param); |
|
720 | - } |
|
718 | + if ($action_id == 6) { |
|
719 | + $action_param = (int) str_replace("+", "", $action_param); |
|
720 | + } |
|
721 | 721 | |
722 | - $asth->execute([$filter_id, $action_id, $action_param]); |
|
723 | - } |
|
724 | - } |
|
725 | - } |
|
726 | - } |
|
722 | + $asth->execute([$filter_id, $action_id, $action_param]); |
|
723 | + } |
|
724 | + } |
|
725 | + } |
|
726 | + } |
|
727 | 727 | |
728 | - public function add() { |
|
729 | - if (clean($_REQUEST["savemode"] && $_REQUEST["savemode"]) == "test") { |
|
730 | - return $this->testFilter(); |
|
731 | - } |
|
728 | + public function add() { |
|
729 | + if (clean($_REQUEST["savemode"] && $_REQUEST["savemode"]) == "test") { |
|
730 | + return $this->testFilter(); |
|
731 | + } |
|
732 | 732 | |
733 | - $enabled = checkbox_to_sql_bool(clean($_REQUEST["enabled"])); |
|
734 | - $match_any_rule = checkbox_to_sql_bool(clean($_REQUEST["match_any_rule"])); |
|
735 | - $title = clean($_REQUEST["title"]); |
|
736 | - $inverse = checkbox_to_sql_bool(clean($_REQUEST["inverse"])); |
|
733 | + $enabled = checkbox_to_sql_bool(clean($_REQUEST["enabled"])); |
|
734 | + $match_any_rule = checkbox_to_sql_bool(clean($_REQUEST["match_any_rule"])); |
|
735 | + $title = clean($_REQUEST["title"]); |
|
736 | + $inverse = checkbox_to_sql_bool(clean($_REQUEST["inverse"])); |
|
737 | 737 | |
738 | - $this->pdo->beginTransaction(); |
|
738 | + $this->pdo->beginTransaction(); |
|
739 | 739 | |
740 | - /* create base filter */ |
|
740 | + /* create base filter */ |
|
741 | 741 | |
742 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_filters2 |
|
742 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_filters2 |
|
743 | 743 | (owner_uid, match_any_rule, enabled, title, inverse) VALUES |
744 | 744 | (?, ?, ?, ?, ?)"); |
745 | 745 | |
746 | - $sth->execute([$_SESSION['uid'], $match_any_rule, $enabled, $title, $inverse]); |
|
746 | + $sth->execute([$_SESSION['uid'], $match_any_rule, $enabled, $title, $inverse]); |
|
747 | 747 | |
748 | - $sth = $this->pdo->prepare("SELECT MAX(id) AS id FROM ttrss_filters2 |
|
748 | + $sth = $this->pdo->prepare("SELECT MAX(id) AS id FROM ttrss_filters2 |
|
749 | 749 | WHERE owner_uid = ?"); |
750 | - $sth->execute([$_SESSION['uid']]); |
|
750 | + $sth->execute([$_SESSION['uid']]); |
|
751 | 751 | |
752 | - if ($row = $sth->fetch()) { |
|
753 | - $filter_id = $row['id']; |
|
754 | - $this->saveRulesAndActions($filter_id); |
|
755 | - } |
|
752 | + if ($row = $sth->fetch()) { |
|
753 | + $filter_id = $row['id']; |
|
754 | + $this->saveRulesAndActions($filter_id); |
|
755 | + } |
|
756 | 756 | |
757 | - $this->pdo->commit(); |
|
758 | - } |
|
757 | + $this->pdo->commit(); |
|
758 | + } |
|
759 | 759 | |
760 | - public function index() { |
|
760 | + public function index() { |
|
761 | 761 | |
762 | - $filter_search = clean($_REQUEST["search"]); |
|
762 | + $filter_search = clean($_REQUEST["search"]); |
|
763 | 763 | |
764 | - if (array_key_exists("search", $_REQUEST)) { |
|
765 | - $_SESSION["prefs_filter_search"] = $filter_search; |
|
766 | - } else { |
|
767 | - $filter_search = $_SESSION["prefs_filter_search"]; |
|
768 | - } |
|
764 | + if (array_key_exists("search", $_REQUEST)) { |
|
765 | + $_SESSION["prefs_filter_search"] = $filter_search; |
|
766 | + } else { |
|
767 | + $filter_search = $_SESSION["prefs_filter_search"]; |
|
768 | + } |
|
769 | 769 | |
770 | - print "<div dojoType='dijit.layout.BorderContainer' gutters='false'>"; |
|
771 | - print "<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='top'>"; |
|
772 | - print "<div dojoType='fox.Toolbar'>"; |
|
770 | + print "<div dojoType='dijit.layout.BorderContainer' gutters='false'>"; |
|
771 | + print "<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='top'>"; |
|
772 | + print "<div dojoType='fox.Toolbar'>"; |
|
773 | 773 | |
774 | - if (array_key_exists("search", $_REQUEST)) { |
|
775 | - $_SESSION["prefs_filter_search"] = $filter_search; |
|
776 | - } else { |
|
777 | - $filter_search = $_SESSION["prefs_filter_search"]; |
|
778 | - } |
|
774 | + if (array_key_exists("search", $_REQUEST)) { |
|
775 | + $_SESSION["prefs_filter_search"] = $filter_search; |
|
776 | + } else { |
|
777 | + $filter_search = $_SESSION["prefs_filter_search"]; |
|
778 | + } |
|
779 | 779 | |
780 | - print "<div style='float : right; padding-right : 4px;'> |
|
780 | + print "<div style='float : right; padding-right : 4px;'> |
|
781 | 781 | <input dojoType=\"dijit.form.TextBox\" id=\"filter_search\" size=\"20\" type=\"search\" |
782 | 782 | value=\"$filter_search\"> |
783 | 783 | <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('filterTree').reload()\">". |
784 | - __('Search')."</button> |
|
784 | + __('Search')."</button> |
|
785 | 785 | </div>"; |
786 | 786 | |
787 | - print "<div dojoType=\"fox.form.DropDownButton\">". |
|
788 | - "<span>".__('Select')."</span>"; |
|
789 | - print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
790 | - print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(true)\" |
|
787 | + print "<div dojoType=\"fox.form.DropDownButton\">". |
|
788 | + "<span>".__('Select')."</span>"; |
|
789 | + print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
790 | + print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(true)\" |
|
791 | 791 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; |
792 | - print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(false)\" |
|
792 | + print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(false)\" |
|
793 | 793 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; |
794 | - print "</div></div>"; |
|
794 | + print "</div></div>"; |
|
795 | 795 | |
796 | - print "<button dojoType=\"dijit.form.Button\" onclick=\"return Filters.quickAddFilter()\">". |
|
797 | - __('Create filter')."</button> "; |
|
796 | + print "<button dojoType=\"dijit.form.Button\" onclick=\"return Filters.quickAddFilter()\">". |
|
797 | + __('Create filter')."</button> "; |
|
798 | 798 | |
799 | - print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterTree').joinSelectedFilters()\">". |
|
800 | - __('Combine')."</button> "; |
|
799 | + print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterTree').joinSelectedFilters()\">". |
|
800 | + __('Combine')."</button> "; |
|
801 | 801 | |
802 | - print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterTree').editSelectedFilter()\">". |
|
803 | - __('Edit')."</button> "; |
|
802 | + print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterTree').editSelectedFilter()\">". |
|
803 | + __('Edit')."</button> "; |
|
804 | 804 | |
805 | - print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterTree').resetFilterOrder()\">". |
|
806 | - __('Reset sort order')."</button> "; |
|
805 | + print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterTree').resetFilterOrder()\">". |
|
806 | + __('Reset sort order')."</button> "; |
|
807 | 807 | |
808 | 808 | |
809 | - print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterTree').removeSelectedFilters()\">". |
|
810 | - __('Remove')."</button> "; |
|
809 | + print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterTree').removeSelectedFilters()\">". |
|
810 | + __('Remove')."</button> "; |
|
811 | 811 | |
812 | - print "</div>"; # toolbar |
|
813 | - print "</div>"; # toolbar-frame |
|
814 | - print "<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='center'>"; |
|
812 | + print "</div>"; # toolbar |
|
813 | + print "</div>"; # toolbar-frame |
|
814 | + print "<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='center'>"; |
|
815 | 815 | |
816 | - print "<div id='filterlistLoading'> |
|
816 | + print "<div id='filterlistLoading'> |
|
817 | 817 | <img src='images/indicator_tiny.gif'>". |
818 | - __("Loading, please wait...")."</div>"; |
|
818 | + __("Loading, please wait...")."</div>"; |
|
819 | 819 | |
820 | - print "<div dojoType=\"fox.PrefFilterStore\" jsId=\"filterStore\" |
|
820 | + print "<div dojoType=\"fox.PrefFilterStore\" jsId=\"filterStore\" |
|
821 | 821 | url=\"backend.php?op=pref-filters&method=getfiltertree\"> |
822 | 822 | </div> |
823 | 823 | <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"filterModel\" store=\"filterStore\" |
@@ -842,152 +842,152 @@ discard block |
||
842 | 842 | |
843 | 843 | </div>"; |
844 | 844 | |
845 | - print "</div>"; #pane |
|
845 | + print "</div>"; #pane |
|
846 | 846 | |
847 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
|
848 | - "hook_prefs_tab", "prefFilters"); |
|
847 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
|
848 | + "hook_prefs_tab", "prefFilters"); |
|
849 | 849 | |
850 | - print "</div>"; #container |
|
850 | + print "</div>"; #container |
|
851 | 851 | |
852 | - } |
|
852 | + } |
|
853 | 853 | |
854 | - public function newfilter() { |
|
854 | + public function newfilter() { |
|
855 | 855 | |
856 | - print "<form name='filter_new_form' id='filter_new_form' onsubmit='return false'>"; |
|
856 | + print "<form name='filter_new_form' id='filter_new_form' onsubmit='return false'>"; |
|
857 | 857 | |
858 | - print_hidden("op", "pref-filters"); |
|
859 | - print_hidden("method", "add"); |
|
860 | - print_hidden("csrf_token", $_SESSION['csrf_token']); |
|
858 | + print_hidden("op", "pref-filters"); |
|
859 | + print_hidden("method", "add"); |
|
860 | + print_hidden("csrf_token", $_SESSION['csrf_token']); |
|
861 | 861 | |
862 | - print "<header>".__("Caption")."</header>"; |
|
862 | + print "<header>".__("Caption")."</header>"; |
|
863 | 863 | |
864 | - print "<section>"; |
|
865 | - print "<input required='true' dojoType='dijit.form.ValidationTextBox' style='width : 20em;' name='title' value=''>"; |
|
866 | - print "</section>"; |
|
864 | + print "<section>"; |
|
865 | + print "<input required='true' dojoType='dijit.form.ValidationTextBox' style='width : 20em;' name='title' value=''>"; |
|
866 | + print "</section>"; |
|
867 | 867 | |
868 | - print "<header class='horizontal'>".__("Match")."</header >"; |
|
869 | - print "<section>"; |
|
868 | + print "<header class='horizontal'>".__("Match")."</header >"; |
|
869 | + print "<section>"; |
|
870 | 870 | |
871 | - print "<div dojoType='fox.Toolbar'>"; |
|
871 | + print "<div dojoType='fox.Toolbar'>"; |
|
872 | 872 | |
873 | - print "<div dojoType='fox.form.DropDownButton'>". |
|
874 | - "<span>".__('Select')."</span>"; |
|
875 | - print "<div dojoType='dijit.Menu' style='display: none'>"; |
|
876 | - print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\" |
|
873 | + print "<div dojoType='fox.form.DropDownButton'>". |
|
874 | + "<span>".__('Select')."</span>"; |
|
875 | + print "<div dojoType='dijit.Menu' style='display: none'>"; |
|
876 | + print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\" |
|
877 | 877 | dojoType='dijit.MenuItem'>".__('All')."</div>"; |
878 | - print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\" |
|
878 | + print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\" |
|
879 | 879 | dojoType='dijit.MenuItem'>".__('None')."</div>"; |
880 | - print "</div></div>"; |
|
880 | + print "</div></div>"; |
|
881 | 881 | |
882 | - print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('filterEditDlg').addRule()\">". |
|
883 | - __('Add')."</button> "; |
|
882 | + print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('filterEditDlg').addRule()\">". |
|
883 | + __('Add')."</button> "; |
|
884 | 884 | |
885 | - print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">". |
|
886 | - __('Delete')."</button> "; |
|
885 | + print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">". |
|
886 | + __('Delete')."</button> "; |
|
887 | 887 | |
888 | - print "</div>"; |
|
888 | + print "</div>"; |
|
889 | 889 | |
890 | - print "<ul id='filterDlg_Matches'>"; |
|
890 | + print "<ul id='filterDlg_Matches'>"; |
|
891 | 891 | # print "<li>No rules</li>"; |
892 | - print "</ul>"; |
|
892 | + print "</ul>"; |
|
893 | 893 | |
894 | - print "</section>"; |
|
894 | + print "</section>"; |
|
895 | 895 | |
896 | - print "<header class='horizontal'>".__("Apply actions")."</header>"; |
|
896 | + print "<header class='horizontal'>".__("Apply actions")."</header>"; |
|
897 | 897 | |
898 | - print "<section>"; |
|
898 | + print "<section>"; |
|
899 | 899 | |
900 | - print "<div dojoType='fox.Toolbar'>"; |
|
900 | + print "<div dojoType='fox.Toolbar'>"; |
|
901 | 901 | |
902 | - print "<div dojoType='fox.form.DropDownButton'>". |
|
903 | - "<span>".__('Select')."</span>"; |
|
904 | - print "<div dojoType='dijit.Menu' style='display: none'>"; |
|
905 | - print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\" |
|
902 | + print "<div dojoType='fox.form.DropDownButton'>". |
|
903 | + "<span>".__('Select')."</span>"; |
|
904 | + print "<div dojoType='dijit.Menu' style='display: none'>"; |
|
905 | + print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\" |
|
906 | 906 | dojoType='dijit.MenuItem'>".__('All')."</div>"; |
907 | - print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\" |
|
907 | + print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\" |
|
908 | 908 | dojoType='dijit.MenuItem'>".__('None')."</div>"; |
909 | - print "</div></div>"; |
|
909 | + print "</div></div>"; |
|
910 | 910 | |
911 | - print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('filterEditDlg').addAction()\">". |
|
912 | - __('Add')."</button> "; |
|
911 | + print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('filterEditDlg').addAction()\">". |
|
912 | + __('Add')."</button> "; |
|
913 | 913 | |
914 | - print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">". |
|
915 | - __('Delete')."</button> "; |
|
914 | + print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">". |
|
915 | + __('Delete')."</button> "; |
|
916 | 916 | |
917 | - print "</div>"; |
|
917 | + print "</div>"; |
|
918 | 918 | |
919 | - print "<ul id='filterDlg_Actions'>"; |
|
919 | + print "<ul id='filterDlg_Actions'>"; |
|
920 | 920 | # print "<li>No actions</li>"; |
921 | - print "</ul>"; |
|
921 | + print "</ul>"; |
|
922 | 922 | |
923 | - print "</section>"; |
|
923 | + print "</section>"; |
|
924 | 924 | |
925 | - print "<header>".__("Options")."</header>"; |
|
925 | + print "<header>".__("Options")."</header>"; |
|
926 | 926 | |
927 | - print "<section>"; |
|
928 | - print "<fieldset class='narrow'>"; |
|
927 | + print "<section>"; |
|
928 | + print "<fieldset class='narrow'>"; |
|
929 | 929 | |
930 | - print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' name='enabled' id='enabled' checked='1'> |
|
930 | + print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' name='enabled' id='enabled' checked='1'> |
|
931 | 931 | ".__('Enabled')."</label>"; |
932 | 932 | |
933 | - print "</fieldset><fieldset class='narrow'>"; |
|
933 | + print "</fieldset><fieldset class='narrow'>"; |
|
934 | 934 | |
935 | - print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' name='match_any_rule' id='match_any_rule'> |
|
935 | + print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' name='match_any_rule' id='match_any_rule'> |
|
936 | 936 | ".__('Match any rule')."</label>"; |
937 | 937 | |
938 | - print "</fieldset><fieldset class='narrow'>"; |
|
938 | + print "</fieldset><fieldset class='narrow'>"; |
|
939 | 939 | |
940 | - print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' name='inverse' id='inverse'> |
|
940 | + print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' name='inverse' id='inverse'> |
|
941 | 941 | ".__('Inverse matching')."</label>"; |
942 | 942 | |
943 | - print "</fieldset>"; |
|
943 | + print "</fieldset>"; |
|
944 | 944 | |
945 | - print "</section>"; |
|
945 | + print "</section>"; |
|
946 | 946 | |
947 | - print "<footer>"; |
|
947 | + print "<footer>"; |
|
948 | 948 | |
949 | - print "<button dojoType='dijit.form.Button' class='alt-info' onclick=\"return dijit.byId('filterEditDlg').test()\">". |
|
950 | - __('Test')."</button> "; |
|
951 | - print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary' onclick=\"return dijit.byId('filterEditDlg').execute()\">". |
|
952 | - __('Create')."</button> "; |
|
953 | - print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('filterEditDlg').hide()\">". |
|
954 | - __('Cancel')."</button>"; |
|
949 | + print "<button dojoType='dijit.form.Button' class='alt-info' onclick=\"return dijit.byId('filterEditDlg').test()\">". |
|
950 | + __('Test')."</button> "; |
|
951 | + print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary' onclick=\"return dijit.byId('filterEditDlg').execute()\">". |
|
952 | + __('Create')."</button> "; |
|
953 | + print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('filterEditDlg').hide()\">". |
|
954 | + __('Cancel')."</button>"; |
|
955 | 955 | |
956 | - print "</footer>"; |
|
956 | + print "</footer>"; |
|
957 | 957 | |
958 | - } |
|
958 | + } |
|
959 | 959 | |
960 | - public function newrule() { |
|
961 | - $rule = json_decode(clean($_REQUEST["rule"]), true); |
|
960 | + public function newrule() { |
|
961 | + $rule = json_decode(clean($_REQUEST["rule"]), true); |
|
962 | 962 | |
963 | - if ($rule) { |
|
964 | - $reg_exp = htmlspecialchars($rule["reg_exp"]); |
|
965 | - $filter_type = $rule["filter_type"]; |
|
966 | - $feed_id = $rule["feed_id"]; |
|
967 | - $inverse_checked = isset($rule["inverse"]) ? "checked" : ""; |
|
968 | - } else { |
|
969 | - $reg_exp = ""; |
|
970 | - $filter_type = 1; |
|
971 | - $feed_id = ["0"]; |
|
972 | - $inverse_checked = ""; |
|
973 | - } |
|
963 | + if ($rule) { |
|
964 | + $reg_exp = htmlspecialchars($rule["reg_exp"]); |
|
965 | + $filter_type = $rule["filter_type"]; |
|
966 | + $feed_id = $rule["feed_id"]; |
|
967 | + $inverse_checked = isset($rule["inverse"]) ? "checked" : ""; |
|
968 | + } else { |
|
969 | + $reg_exp = ""; |
|
970 | + $filter_type = 1; |
|
971 | + $feed_id = ["0"]; |
|
972 | + $inverse_checked = ""; |
|
973 | + } |
|
974 | 974 | |
975 | - print "<form name='filter_new_rule_form' id='filter_new_rule_form' onsubmit='return false;'>"; |
|
975 | + print "<form name='filter_new_rule_form' id='filter_new_rule_form' onsubmit='return false;'>"; |
|
976 | 976 | |
977 | - $res = $this->pdo->query("SELECT id,description |
|
977 | + $res = $this->pdo->query("SELECT id,description |
|
978 | 978 | FROM ttrss_filter_types WHERE id != 5 ORDER BY description"); |
979 | 979 | |
980 | - $filter_types = array(); |
|
980 | + $filter_types = array(); |
|
981 | 981 | |
982 | - while ($line = $res->fetch()) { |
|
983 | - $filter_types[$line["id"]] = __($line["description"]); |
|
984 | - } |
|
982 | + while ($line = $res->fetch()) { |
|
983 | + $filter_types[$line["id"]] = __($line["description"]); |
|
984 | + } |
|
985 | 985 | |
986 | - print "<header>".__("Match")."</header>"; |
|
986 | + print "<header>".__("Match")."</header>"; |
|
987 | 987 | |
988 | - print "<section>"; |
|
988 | + print "<section>"; |
|
989 | 989 | |
990 | - print "<input dojoType=\"dijit.form.ValidationTextBox\" |
|
990 | + print "<input dojoType=\"dijit.form.ValidationTextBox\" |
|
991 | 991 | required=\"true\" id=\"filterDlg_regExp\" |
992 | 992 | onchange='Filters.filterDlgCheckRegExp(this)' |
993 | 993 | onblur='Filters.filterDlgCheckRegExp(this)' |
@@ -995,272 +995,272 @@ discard block |
||
995 | 995 | style=\"font-size : 16px; width : 500px\" |
996 | 996 | name=\"reg_exp\" value=\"$reg_exp\"/>"; |
997 | 997 | |
998 | - print "<div dojoType='dijit.Tooltip' id='filterDlg_regExp_tip' connectId='filterDlg_regExp' position='below'></div>"; |
|
998 | + print "<div dojoType='dijit.Tooltip' id='filterDlg_regExp_tip' connectId='filterDlg_regExp' position='below'></div>"; |
|
999 | 999 | |
1000 | - print "<fieldset>"; |
|
1001 | - print "<label class='checkbox'><input id=\"filterDlg_inverse\" dojoType=\"dijit.form.CheckBox\" |
|
1000 | + print "<fieldset>"; |
|
1001 | + print "<label class='checkbox'><input id=\"filterDlg_inverse\" dojoType=\"dijit.form.CheckBox\" |
|
1002 | 1002 | name=\"inverse\" $inverse_checked/> ". |
1003 | - __("Inverse regular expression matching")."</label>"; |
|
1004 | - print "</fieldset>"; |
|
1003 | + __("Inverse regular expression matching")."</label>"; |
|
1004 | + print "</fieldset>"; |
|
1005 | 1005 | |
1006 | - print "<fieldset>"; |
|
1007 | - print "<label style='display : inline'>".__("on field")."</label> "; |
|
1008 | - print_select_hash("filter_type", $filter_type, $filter_types, |
|
1009 | - 'dojoType="fox.form.Select"'); |
|
1010 | - print "<label style='padding-left : 10px; display : inline'>".__("in")."</label> "; |
|
1006 | + print "<fieldset>"; |
|
1007 | + print "<label style='display : inline'>".__("on field")."</label> "; |
|
1008 | + print_select_hash("filter_type", $filter_type, $filter_types, |
|
1009 | + 'dojoType="fox.form.Select"'); |
|
1010 | + print "<label style='padding-left : 10px; display : inline'>".__("in")."</label> "; |
|
1011 | 1011 | |
1012 | - print "</fieldset>"; |
|
1012 | + print "</fieldset>"; |
|
1013 | 1013 | |
1014 | - print "<fieldset>"; |
|
1015 | - print "<span id='filterDlg_feeds'>"; |
|
1016 | - print_feed_multi_select("feed_id", |
|
1017 | - $feed_id, |
|
1018 | - 'style="width : 500px; height : 300px" dojoType="dijit.form.MultiSelect"'); |
|
1019 | - print "</span>"; |
|
1014 | + print "<fieldset>"; |
|
1015 | + print "<span id='filterDlg_feeds'>"; |
|
1016 | + print_feed_multi_select("feed_id", |
|
1017 | + $feed_id, |
|
1018 | + 'style="width : 500px; height : 300px" dojoType="dijit.form.MultiSelect"'); |
|
1019 | + print "</span>"; |
|
1020 | 1020 | |
1021 | - print "</fieldset>"; |
|
1021 | + print "</fieldset>"; |
|
1022 | 1022 | |
1023 | - print "</section>"; |
|
1023 | + print "</section>"; |
|
1024 | 1024 | |
1025 | - print "<footer>"; |
|
1025 | + print "<footer>"; |
|
1026 | 1026 | |
1027 | - print "<button dojoType='dijit.form.Button' style='float : left' class='alt-info' onclick='window.open(\"https://tt-rss.org/wiki/ContentFilters\")'> |
|
1027 | + print "<button dojoType='dijit.form.Button' style='float : left' class='alt-info' onclick='window.open(\"https://tt-rss.org/wiki/ContentFilters\")'> |
|
1028 | 1028 | <i class='material-icons'>help</i> ".__("More info...")."</button>"; |
1029 | 1029 | |
1030 | - print "<button dojoType='dijit.form.Button' class='alt-primary' type='submit' onclick=\"return dijit.byId('filterNewRuleDlg').execute()\">". |
|
1031 | - ($rule ? __("Save rule") : __('Add rule'))."</button> "; |
|
1030 | + print "<button dojoType='dijit.form.Button' class='alt-primary' type='submit' onclick=\"return dijit.byId('filterNewRuleDlg').execute()\">". |
|
1031 | + ($rule ? __("Save rule") : __('Add rule'))."</button> "; |
|
1032 | 1032 | |
1033 | - print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('filterNewRuleDlg').hide()\">". |
|
1034 | - __('Cancel')."</button>"; |
|
1033 | + print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('filterNewRuleDlg').hide()\">". |
|
1034 | + __('Cancel')."</button>"; |
|
1035 | 1035 | |
1036 | - print "</footer>"; |
|
1036 | + print "</footer>"; |
|
1037 | 1037 | |
1038 | - print "</form>"; |
|
1039 | - } |
|
1038 | + print "</form>"; |
|
1039 | + } |
|
1040 | 1040 | |
1041 | - public function newaction() { |
|
1042 | - $action = json_decode(clean($_REQUEST["action"]), true); |
|
1041 | + public function newaction() { |
|
1042 | + $action = json_decode(clean($_REQUEST["action"]), true); |
|
1043 | 1043 | |
1044 | - if ($action) { |
|
1045 | - $action_param = $action["action_param"]; |
|
1046 | - $action_id = (int) $action["action_id"]; |
|
1047 | - } else { |
|
1048 | - $action_param = ""; |
|
1049 | - $action_id = 0; |
|
1050 | - } |
|
1044 | + if ($action) { |
|
1045 | + $action_param = $action["action_param"]; |
|
1046 | + $action_id = (int) $action["action_id"]; |
|
1047 | + } else { |
|
1048 | + $action_param = ""; |
|
1049 | + $action_id = 0; |
|
1050 | + } |
|
1051 | 1051 | |
1052 | - print "<form name='filter_new_action_form' id='filter_new_action_form' onsubmit='return false;'>"; |
|
1052 | + print "<form name='filter_new_action_form' id='filter_new_action_form' onsubmit='return false;'>"; |
|
1053 | 1053 | |
1054 | - print "<header>".__("Perform Action")."</header>"; |
|
1054 | + print "<header>".__("Perform Action")."</header>"; |
|
1055 | 1055 | |
1056 | - print "<section>"; |
|
1056 | + print "<section>"; |
|
1057 | 1057 | |
1058 | - print "<select name='action_id' dojoType='fox.form.Select' |
|
1058 | + print "<select name='action_id' dojoType='fox.form.Select' |
|
1059 | 1059 | onchange='Filters.filterDlgCheckAction(this)'>"; |
1060 | 1060 | |
1061 | - $res = $this->pdo->query("SELECT id,description FROM ttrss_filter_actions |
|
1061 | + $res = $this->pdo->query("SELECT id,description FROM ttrss_filter_actions |
|
1062 | 1062 | ORDER BY name"); |
1063 | 1063 | |
1064 | - while ($line = $res->fetch()) { |
|
1065 | - $is_selected = ($line["id"] == $action_id) ? "selected='1'" : ""; |
|
1066 | - printf("<option $is_selected value='%d'>%s</option>", $line["id"], __($line["description"])); |
|
1067 | - } |
|
1064 | + while ($line = $res->fetch()) { |
|
1065 | + $is_selected = ($line["id"] == $action_id) ? "selected='1'" : ""; |
|
1066 | + printf("<option $is_selected value='%d'>%s</option>", $line["id"], __($line["description"])); |
|
1067 | + } |
|
1068 | 1068 | |
1069 | - print "</select>"; |
|
1069 | + print "</select>"; |
|
1070 | 1070 | |
1071 | - $param_box_hidden = ($action_id == 7 || $action_id == 4 || $action_id == 6 || $action_id == 9) ? |
|
1072 | - "" : "display : none"; |
|
1071 | + $param_box_hidden = ($action_id == 7 || $action_id == 4 || $action_id == 6 || $action_id == 9) ? |
|
1072 | + "" : "display : none"; |
|
1073 | 1073 | |
1074 | - $param_hidden = ($action_id == 4 || $action_id == 6) ? |
|
1075 | - "" : "display : none"; |
|
1074 | + $param_hidden = ($action_id == 4 || $action_id == 6) ? |
|
1075 | + "" : "display : none"; |
|
1076 | 1076 | |
1077 | - $label_param_hidden = ($action_id == 7) ? "" : "display : none"; |
|
1078 | - $plugin_param_hidden = ($action_id == 9) ? "" : "display : none"; |
|
1077 | + $label_param_hidden = ($action_id == 7) ? "" : "display : none"; |
|
1078 | + $plugin_param_hidden = ($action_id == 9) ? "" : "display : none"; |
|
1079 | 1079 | |
1080 | - print "<span id='filterDlg_paramBox' style=\"$param_box_hidden\">"; |
|
1081 | - print " "; |
|
1082 | - //print " " . __("with parameters:") . " "; |
|
1083 | - print "<input dojoType='dijit.form.TextBox' |
|
1080 | + print "<span id='filterDlg_paramBox' style=\"$param_box_hidden\">"; |
|
1081 | + print " "; |
|
1082 | + //print " " . __("with parameters:") . " "; |
|
1083 | + print "<input dojoType='dijit.form.TextBox' |
|
1084 | 1084 | id='filterDlg_actionParam' style=\"$param_hidden\" |
1085 | 1085 | name='action_param' value=\"$action_param\">"; |
1086 | 1086 | |
1087 | - print_label_select("action_param_label", $action_param, |
|
1088 | - "id='filterDlg_actionParamLabel' style=\"$label_param_hidden\" |
|
1087 | + print_label_select("action_param_label", $action_param, |
|
1088 | + "id='filterDlg_actionParamLabel' style=\"$label_param_hidden\" |
|
1089 | 1089 | dojoType='fox.form.Select'"); |
1090 | 1090 | |
1091 | - $filter_actions = PluginHost::getInstance()->get_filter_actions(); |
|
1092 | - $filter_action_hash = array(); |
|
1091 | + $filter_actions = PluginHost::getInstance()->get_filter_actions(); |
|
1092 | + $filter_action_hash = array(); |
|
1093 | 1093 | |
1094 | - foreach ($filter_actions as $fclass => $factions) { |
|
1095 | - foreach ($factions as $faction) { |
|
1094 | + foreach ($filter_actions as $fclass => $factions) { |
|
1095 | + foreach ($factions as $faction) { |
|
1096 | 1096 | |
1097 | - $filter_action_hash[$fclass.":".$faction["action"]] = |
|
1098 | - $fclass.": ".$faction["description"]; |
|
1099 | - } |
|
1100 | - } |
|
1097 | + $filter_action_hash[$fclass.":".$faction["action"]] = |
|
1098 | + $fclass.": ".$faction["description"]; |
|
1099 | + } |
|
1100 | + } |
|
1101 | 1101 | |
1102 | - if (count($filter_action_hash) == 0) { |
|
1103 | - $filter_plugin_disabled = "disabled"; |
|
1102 | + if (count($filter_action_hash) == 0) { |
|
1103 | + $filter_plugin_disabled = "disabled"; |
|
1104 | 1104 | |
1105 | - $filter_action_hash["no-data"] = __("No actions available"); |
|
1105 | + $filter_action_hash["no-data"] = __("No actions available"); |
|
1106 | 1106 | |
1107 | - } else { |
|
1108 | - $filter_plugin_disabled = ""; |
|
1109 | - } |
|
1107 | + } else { |
|
1108 | + $filter_plugin_disabled = ""; |
|
1109 | + } |
|
1110 | 1110 | |
1111 | - print_select_hash("filterDlg_actionParamPlugin", $action_param, $filter_action_hash, |
|
1112 | - "style=\"$plugin_param_hidden\" dojoType='fox.form.Select' $filter_plugin_disabled", |
|
1113 | - "action_param_plugin"); |
|
1111 | + print_select_hash("filterDlg_actionParamPlugin", $action_param, $filter_action_hash, |
|
1112 | + "style=\"$plugin_param_hidden\" dojoType='fox.form.Select' $filter_plugin_disabled", |
|
1113 | + "action_param_plugin"); |
|
1114 | 1114 | |
1115 | - print "</span>"; |
|
1115 | + print "</span>"; |
|
1116 | 1116 | |
1117 | - print " "; // tiny layout hack |
|
1117 | + print " "; // tiny layout hack |
|
1118 | 1118 | |
1119 | - print "</section>"; |
|
1119 | + print "</section>"; |
|
1120 | 1120 | |
1121 | - print "<footer>"; |
|
1121 | + print "<footer>"; |
|
1122 | 1122 | |
1123 | - print "<button dojoType='dijit.form.Button' class='alt-primary' type='submit' onclick=\"return dijit.byId('filterNewActionDlg').execute()\">". |
|
1124 | - ($action ? __("Save action") : __('Add action'))."</button> "; |
|
1123 | + print "<button dojoType='dijit.form.Button' class='alt-primary' type='submit' onclick=\"return dijit.byId('filterNewActionDlg').execute()\">". |
|
1124 | + ($action ? __("Save action") : __('Add action'))."</button> "; |
|
1125 | 1125 | |
1126 | - print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('filterNewActionDlg').hide()\">". |
|
1127 | - __('Cancel')."</button>"; |
|
1126 | + print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('filterNewActionDlg').hide()\">". |
|
1127 | + __('Cancel')."</button>"; |
|
1128 | 1128 | |
1129 | - print "</footer>"; |
|
1129 | + print "</footer>"; |
|
1130 | 1130 | |
1131 | - print "</form>"; |
|
1132 | - } |
|
1131 | + print "</form>"; |
|
1132 | + } |
|
1133 | 1133 | |
1134 | - private function getFilterName($id) { |
|
1134 | + private function getFilterName($id) { |
|
1135 | 1135 | |
1136 | - $sth = $this->pdo->prepare( |
|
1137 | - "SELECT title,match_any_rule,f.inverse AS inverse,COUNT(DISTINCT r.id) AS num_rules,COUNT(DISTINCT a.id) AS num_actions |
|
1136 | + $sth = $this->pdo->prepare( |
|
1137 | + "SELECT title,match_any_rule,f.inverse AS inverse,COUNT(DISTINCT r.id) AS num_rules,COUNT(DISTINCT a.id) AS num_actions |
|
1138 | 1138 | FROM ttrss_filters2 AS f LEFT JOIN ttrss_filters2_rules AS r |
1139 | 1139 | ON (r.filter_id = f.id) |
1140 | 1140 | LEFT JOIN ttrss_filters2_actions AS a |
1141 | 1141 | ON (a.filter_id = f.id) WHERE f.id = ? GROUP BY f.title, f.match_any_rule, f.inverse"); |
1142 | - $sth->execute([$id]); |
|
1142 | + $sth->execute([$id]); |
|
1143 | 1143 | |
1144 | - if ($row = $sth->fetch()) { |
|
1144 | + if ($row = $sth->fetch()) { |
|
1145 | 1145 | |
1146 | - $title = $row["title"]; |
|
1147 | - $num_rules = $row["num_rules"]; |
|
1148 | - $num_actions = $row["num_actions"]; |
|
1149 | - $match_any_rule = $row["match_any_rule"]; |
|
1150 | - $inverse = $row["inverse"]; |
|
1146 | + $title = $row["title"]; |
|
1147 | + $num_rules = $row["num_rules"]; |
|
1148 | + $num_actions = $row["num_actions"]; |
|
1149 | + $match_any_rule = $row["match_any_rule"]; |
|
1150 | + $inverse = $row["inverse"]; |
|
1151 | 1151 | |
1152 | - if (!$title) { |
|
1153 | - $title = __("[No caption]"); |
|
1154 | - } |
|
1152 | + if (!$title) { |
|
1153 | + $title = __("[No caption]"); |
|
1154 | + } |
|
1155 | 1155 | |
1156 | - $title = sprintf(_ngettext("%s (%d rule)", "%s (%d rules)", (int) $num_rules), $title, $num_rules); |
|
1156 | + $title = sprintf(_ngettext("%s (%d rule)", "%s (%d rules)", (int) $num_rules), $title, $num_rules); |
|
1157 | 1157 | |
1158 | - $sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_actions |
|
1158 | + $sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_actions |
|
1159 | 1159 | WHERE filter_id = ? ORDER BY id LIMIT 1"); |
1160 | - $sth->execute([$id]); |
|
1160 | + $sth->execute([$id]); |
|
1161 | 1161 | |
1162 | - $actions = ""; |
|
1162 | + $actions = ""; |
|
1163 | 1163 | |
1164 | - if ($line = $sth->fetch()) { |
|
1165 | - $actions = $this->getActionName($line); |
|
1164 | + if ($line = $sth->fetch()) { |
|
1165 | + $actions = $this->getActionName($line); |
|
1166 | 1166 | |
1167 | - $num_actions -= 1; |
|
1168 | - } |
|
1167 | + $num_actions -= 1; |
|
1168 | + } |
|
1169 | 1169 | |
1170 | - if ($match_any_rule) $title .= " (".__("matches any rule").")"; |
|
1171 | - if ($inverse) $title .= " (".__("inverse").")"; |
|
1170 | + if ($match_any_rule) $title .= " (".__("matches any rule").")"; |
|
1171 | + if ($inverse) $title .= " (".__("inverse").")"; |
|
1172 | 1172 | |
1173 | - if ($num_actions > 0) |
|
1174 | - $actions = sprintf(_ngettext("%s (+%d action)", "%s (+%d actions)", (int) $num_actions), $actions, $num_actions); |
|
1173 | + if ($num_actions > 0) |
|
1174 | + $actions = sprintf(_ngettext("%s (+%d action)", "%s (+%d actions)", (int) $num_actions), $actions, $num_actions); |
|
1175 | 1175 | |
1176 | - return [$title, $actions]; |
|
1177 | - } |
|
1176 | + return [$title, $actions]; |
|
1177 | + } |
|
1178 | 1178 | |
1179 | - return []; |
|
1180 | - } |
|
1179 | + return []; |
|
1180 | + } |
|
1181 | 1181 | |
1182 | - public function join() { |
|
1183 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
1182 | + public function join() { |
|
1183 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
1184 | 1184 | |
1185 | - if (count($ids) > 1) { |
|
1186 | - $base_id = array_shift($ids); |
|
1187 | - $ids_qmarks = arr_qmarks($ids); |
|
1185 | + if (count($ids) > 1) { |
|
1186 | + $base_id = array_shift($ids); |
|
1187 | + $ids_qmarks = arr_qmarks($ids); |
|
1188 | 1188 | |
1189 | - $this->pdo->beginTransaction(); |
|
1189 | + $this->pdo->beginTransaction(); |
|
1190 | 1190 | |
1191 | - $sth = $this->pdo->prepare("UPDATE ttrss_filters2_rules |
|
1191 | + $sth = $this->pdo->prepare("UPDATE ttrss_filters2_rules |
|
1192 | 1192 | SET filter_id = ? WHERE filter_id IN ($ids_qmarks)"); |
1193 | - $sth->execute(array_merge([$base_id], $ids)); |
|
1193 | + $sth->execute(array_merge([$base_id], $ids)); |
|
1194 | 1194 | |
1195 | - $sth = $this->pdo->prepare("UPDATE ttrss_filters2_actions |
|
1195 | + $sth = $this->pdo->prepare("UPDATE ttrss_filters2_actions |
|
1196 | 1196 | SET filter_id = ? WHERE filter_id IN ($ids_qmarks)"); |
1197 | - $sth->execute(array_merge([$base_id], $ids)); |
|
1197 | + $sth->execute(array_merge([$base_id], $ids)); |
|
1198 | 1198 | |
1199 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_filters2 WHERE id IN ($ids_qmarks)"); |
|
1200 | - $sth->execute($ids); |
|
1199 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_filters2 WHERE id IN ($ids_qmarks)"); |
|
1200 | + $sth->execute($ids); |
|
1201 | 1201 | |
1202 | - $sth = $this->pdo->prepare("UPDATE ttrss_filters2 SET match_any_rule = true WHERE id = ?"); |
|
1203 | - $sth->execute([$base_id]); |
|
1202 | + $sth = $this->pdo->prepare("UPDATE ttrss_filters2 SET match_any_rule = true WHERE id = ?"); |
|
1203 | + $sth->execute([$base_id]); |
|
1204 | 1204 | |
1205 | - $this->pdo->commit(); |
|
1205 | + $this->pdo->commit(); |
|
1206 | 1206 | |
1207 | - $this->optimizeFilter($base_id); |
|
1207 | + $this->optimizeFilter($base_id); |
|
1208 | 1208 | |
1209 | - } |
|
1210 | - } |
|
1209 | + } |
|
1210 | + } |
|
1211 | 1211 | |
1212 | - private function optimizeFilter($id) { |
|
1212 | + private function optimizeFilter($id) { |
|
1213 | 1213 | |
1214 | - $this->pdo->beginTransaction(); |
|
1214 | + $this->pdo->beginTransaction(); |
|
1215 | 1215 | |
1216 | - $sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_actions |
|
1216 | + $sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_actions |
|
1217 | 1217 | WHERE filter_id = ?"); |
1218 | - $sth->execute([$id]); |
|
1218 | + $sth->execute([$id]); |
|
1219 | 1219 | |
1220 | - $tmp = array(); |
|
1221 | - $dupe_ids = array(); |
|
1220 | + $tmp = array(); |
|
1221 | + $dupe_ids = array(); |
|
1222 | 1222 | |
1223 | - while ($line = $sth->fetch()) { |
|
1224 | - $id = $line["id"]; |
|
1225 | - unset($line["id"]); |
|
1223 | + while ($line = $sth->fetch()) { |
|
1224 | + $id = $line["id"]; |
|
1225 | + unset($line["id"]); |
|
1226 | 1226 | |
1227 | - if (array_search($line, $tmp) === false) { |
|
1228 | - array_push($tmp, $line); |
|
1229 | - } else { |
|
1230 | - array_push($dupe_ids, $id); |
|
1231 | - } |
|
1232 | - } |
|
1227 | + if (array_search($line, $tmp) === false) { |
|
1228 | + array_push($tmp, $line); |
|
1229 | + } else { |
|
1230 | + array_push($dupe_ids, $id); |
|
1231 | + } |
|
1232 | + } |
|
1233 | 1233 | |
1234 | - if (count($dupe_ids) > 0) { |
|
1235 | - $ids_str = join(",", $dupe_ids); |
|
1234 | + if (count($dupe_ids) > 0) { |
|
1235 | + $ids_str = join(",", $dupe_ids); |
|
1236 | 1236 | |
1237 | - $this->pdo->query("DELETE FROM ttrss_filters2_actions WHERE id IN ($ids_str)"); |
|
1238 | - } |
|
1237 | + $this->pdo->query("DELETE FROM ttrss_filters2_actions WHERE id IN ($ids_str)"); |
|
1238 | + } |
|
1239 | 1239 | |
1240 | - $sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_rules |
|
1240 | + $sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_rules |
|
1241 | 1241 | WHERE filter_id = ?"); |
1242 | - $sth->execute([$id]); |
|
1242 | + $sth->execute([$id]); |
|
1243 | 1243 | |
1244 | - $tmp = array(); |
|
1245 | - $dupe_ids = array(); |
|
1244 | + $tmp = array(); |
|
1245 | + $dupe_ids = array(); |
|
1246 | 1246 | |
1247 | - while ($line = $sth->fetch()) { |
|
1248 | - $id = $line["id"]; |
|
1249 | - unset($line["id"]); |
|
1247 | + while ($line = $sth->fetch()) { |
|
1248 | + $id = $line["id"]; |
|
1249 | + unset($line["id"]); |
|
1250 | 1250 | |
1251 | - if (array_search($line, $tmp) === false) { |
|
1252 | - array_push($tmp, $line); |
|
1253 | - } else { |
|
1254 | - array_push($dupe_ids, $id); |
|
1255 | - } |
|
1256 | - } |
|
1251 | + if (array_search($line, $tmp) === false) { |
|
1252 | + array_push($tmp, $line); |
|
1253 | + } else { |
|
1254 | + array_push($dupe_ids, $id); |
|
1255 | + } |
|
1256 | + } |
|
1257 | 1257 | |
1258 | - if (count($dupe_ids) > 0) { |
|
1259 | - $ids_str = join(",", $dupe_ids); |
|
1258 | + if (count($dupe_ids) > 0) { |
|
1259 | + $ids_str = join(",", $dupe_ids); |
|
1260 | 1260 | |
1261 | - $this->pdo->query("DELETE FROM ttrss_filters2_rules WHERE id IN ($ids_str)"); |
|
1262 | - } |
|
1261 | + $this->pdo->query("DELETE FROM ttrss_filters2_rules WHERE id IN ($ids_str)"); |
|
1262 | + } |
|
1263 | 1263 | |
1264 | - $this->pdo->commit(); |
|
1265 | - } |
|
1264 | + $this->pdo->commit(); |
|
1265 | + } |
|
1266 | 1266 | } |
@@ -99,12 +99,16 @@ discard block |
||
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | - if (count($scope_qparts) == 0) $scope_qparts = ["true"]; |
|
102 | + if (count($scope_qparts) == 0) { |
|
103 | + $scope_qparts = ["true"]; |
|
104 | + } |
|
103 | 105 | |
104 | 106 | $glue = $filter['match_any_rule'] ? " OR " : " AND "; |
105 | 107 | $scope_qpart = join($glue, $scope_qparts); |
106 | 108 | |
107 | - if (!$scope_qpart) $scope_qpart = "true"; |
|
109 | + if (!$scope_qpart) { |
|
110 | + $scope_qpart = "true"; |
|
111 | + } |
|
108 | 112 | |
109 | 113 | $rv = array(); |
110 | 114 | |
@@ -209,10 +213,11 @@ discard block |
||
209 | 213 | $feed_id = (int) substr($feed_id, 4); |
210 | 214 | array_push($feeds_fmt, Feeds::getCategoryTitle($feed_id)); |
211 | 215 | } else { |
212 | - if ($feed_id) |
|
213 | - array_push($feeds_fmt, Feeds::getFeedTitle((int) $feed_id)); |
|
214 | - else |
|
215 | - array_push($feeds_fmt, __("All feeds")); |
|
216 | + if ($feed_id) { |
|
217 | + array_push($feeds_fmt, Feeds::getFeedTitle((int) $feed_id)); |
|
218 | + } else { |
|
219 | + array_push($feeds_fmt, __("All feeds")); |
|
220 | + } |
|
216 | 221 | } |
217 | 222 | } |
218 | 223 | |
@@ -539,10 +544,11 @@ discard block |
||
539 | 544 | $feed_id = (int) substr($feed_id, 4); |
540 | 545 | array_push($feeds_fmt, Feeds::getCategoryTitle($feed_id)); |
541 | 546 | } else { |
542 | - if ($feed_id) |
|
543 | - array_push($feeds_fmt, Feeds::getFeedTitle((int) $feed_id)); |
|
544 | - else |
|
545 | - array_push($feeds_fmt, __("All feeds")); |
|
547 | + if ($feed_id) { |
|
548 | + array_push($feeds_fmt, Feeds::getFeedTitle((int) $feed_id)); |
|
549 | + } else { |
|
550 | + array_push($feeds_fmt, __("All feeds")); |
|
551 | + } |
|
546 | 552 | } |
547 | 553 | } |
548 | 554 | |
@@ -581,8 +587,9 @@ discard block |
||
581 | 587 | $title = __($row["description"]); |
582 | 588 | |
583 | 589 | if ($action["action_id"] == 4 || $action["action_id"] == 6 || |
584 | - $action["action_id"] == 7) |
|
585 | - $title .= ": ".$action["action_param"]; |
|
590 | + $action["action_id"] == 7) { |
|
591 | + $title .= ": ".$action["action_param"]; |
|
592 | + } |
|
586 | 593 | |
587 | 594 | if ($action["action_id"] == 9) { |
588 | 595 | list ($pfclass, $pfaction) = explode(":", $action["action_param"]); |
@@ -1167,11 +1174,16 @@ discard block |
||
1167 | 1174 | $num_actions -= 1; |
1168 | 1175 | } |
1169 | 1176 | |
1170 | - if ($match_any_rule) $title .= " (".__("matches any rule").")"; |
|
1171 | - if ($inverse) $title .= " (".__("inverse").")"; |
|
1177 | + if ($match_any_rule) { |
|
1178 | + $title .= " (".__("matches any rule").")"; |
|
1179 | + } |
|
1180 | + if ($inverse) { |
|
1181 | + $title .= " (".__("inverse").")"; |
|
1182 | + } |
|
1172 | 1183 | |
1173 | - if ($num_actions > 0) |
|
1174 | - $actions = sprintf(_ngettext("%s (+%d action)", "%s (+%d actions)", (int) $num_actions), $actions, $num_actions); |
|
1184 | + if ($num_actions > 0) { |
|
1185 | + $actions = sprintf(_ngettext("%s (+%d action)", "%s (+%d actions)", (int) $num_actions), $actions, $num_actions); |
|
1186 | + } |
|
1175 | 1187 | |
1176 | 1188 | return [$title, $actions]; |
1177 | 1189 | } |
@@ -2,284 +2,284 @@ discard block |
||
2 | 2 | |
3 | 3 | class Pref_Prefs extends Handler_Protected { |
4 | 4 | |
5 | - private $pref_help = []; |
|
6 | - private $pref_item_map = []; |
|
7 | - private $pref_blacklist = []; |
|
8 | - private $profile_blacklist = []; |
|
9 | - |
|
10 | - public function csrf_ignore($method) { |
|
11 | - $csrf_ignored = array("index", "updateself", "customizecss", "editprefprofiles"); |
|
12 | - |
|
13 | - return array_search($method, $csrf_ignored) !== false; |
|
14 | - } |
|
15 | - |
|
16 | - public function __construct($args) { |
|
17 | - parent::__construct($args); |
|
18 | - |
|
19 | - $this->pref_item_map = [ |
|
20 | - __('General') => [ |
|
21 | - 'USER_LANGUAGE', |
|
22 | - 'USER_TIMEZONE', |
|
23 | - 'BLOCK_SEPARATOR', |
|
24 | - 'USER_CSS_THEME', |
|
25 | - 'BLOCK_SEPARATOR', |
|
26 | - 'ENABLE_API_ACCESS', |
|
27 | - ], |
|
28 | - __('Feeds') => [ |
|
29 | - 'DEFAULT_UPDATE_INTERVAL', |
|
30 | - 'FRESH_ARTICLE_MAX_AGE', |
|
31 | - 'DEFAULT_SEARCH_LANGUAGE', |
|
32 | - 'BLOCK_SEPARATOR', |
|
33 | - 'ENABLE_FEED_CATS', |
|
34 | - 'BLOCK_SEPARATOR', |
|
35 | - 'CONFIRM_FEED_CATCHUP', |
|
36 | - 'ON_CATCHUP_SHOW_NEXT_FEED', |
|
37 | - 'BLOCK_SEPARATOR', |
|
38 | - 'HIDE_READ_FEEDS', |
|
39 | - 'HIDE_READ_SHOWS_SPECIAL', |
|
40 | - ], |
|
41 | - __('Articles') => [ |
|
42 | - 'PURGE_OLD_DAYS', |
|
43 | - 'PURGE_UNREAD_ARTICLES', |
|
44 | - 'BLOCK_SEPARATOR', |
|
45 | - 'COMBINED_DISPLAY_MODE', |
|
46 | - 'CDM_EXPANDED', |
|
47 | - 'BLOCK_SEPARATOR', |
|
48 | - 'CDM_AUTO_CATCHUP', |
|
49 | - 'VFEED_GROUP_BY_FEED', |
|
50 | - 'BLOCK_SEPARATOR', |
|
51 | - 'SHOW_CONTENT_PREVIEW', |
|
52 | - 'STRIP_IMAGES', |
|
53 | - ], |
|
54 | - __('Digest') => [ |
|
55 | - 'DIGEST_ENABLE', |
|
56 | - 'DIGEST_CATCHUP', |
|
57 | - 'DIGEST_PREFERRED_TIME', |
|
58 | - ], |
|
59 | - __('Advanced') => [ |
|
60 | - 'BLACKLISTED_TAGS', |
|
61 | - 'BLOCK_SEPARATOR', |
|
62 | - 'LONG_DATE_FORMAT', |
|
63 | - 'SHORT_DATE_FORMAT', |
|
64 | - 'BLOCK_SEPARATOR', |
|
65 | - 'SSL_CERT_SERIAL', |
|
66 | - ] |
|
67 | - ]; |
|
68 | - |
|
69 | - $this->pref_help = [ |
|
70 | - "ALLOW_DUPLICATE_POSTS" => array(__("Allow duplicate articles"), ""), |
|
71 | - "BLACKLISTED_TAGS" => array(__("Blacklisted tags"), __("Never apply these tags automatically (comma-separated list).")), |
|
72 | - "DEFAULT_SEARCH_LANGUAGE" => array(__("Default language"), __("Used for full-text search")), |
|
73 | - "CDM_AUTO_CATCHUP" => array(__("Mark read on scroll"), __("Mark articles as read as you scroll past them")), |
|
74 | - "CDM_EXPANDED" => array(__("Always expand articles")), |
|
75 | - "COMBINED_DISPLAY_MODE" => array(__("Combined mode"), __("Show flat list of articles instead of separate panels")), |
|
76 | - "CONFIRM_FEED_CATCHUP" => array(__("Confirm marking feeds as read")), |
|
77 | - "DEFAULT_ARTICLE_LIMIT" => array(__("Amount of articles to display at once")), |
|
78 | - "DEFAULT_UPDATE_INTERVAL" => array(__("Default update interval")), |
|
79 | - "DIGEST_CATCHUP" => array(__("Mark sent articles as read")), |
|
80 | - "DIGEST_ENABLE" => array(__("Enable digest"), __("Send daily digest of new (and unread) headlines to your e-mail address")), |
|
81 | - "DIGEST_PREFERRED_TIME" => array(__("Try to send around this time"), __("Time in UTC")), |
|
82 | - "ENABLE_API_ACCESS" => array(__("Enable API"), __("Allows accessing this account through the API")), |
|
83 | - "ENABLE_FEED_CATS" => array(__("Enable categories")), |
|
84 | - "FEEDS_SORT_BY_UNREAD" => array(__("Sort feeds by unread articles count"), ""), |
|
85 | - "FRESH_ARTICLE_MAX_AGE" => array(__("Maximum age of fresh articles"), "<strong>".__("hours")."</strong>"), |
|
86 | - "HIDE_READ_FEEDS" => array(__("Hide read feeds")), |
|
87 | - "HIDE_READ_SHOWS_SPECIAL" => array(__("Always show special feeds"), __("While hiding read feeds")), |
|
88 | - "LONG_DATE_FORMAT" => array(__("Long date format"), __("Syntax is identical to PHP <a href='http://php.net/manual/function.date.php'>date()</a> function.")), |
|
89 | - "ON_CATCHUP_SHOW_NEXT_FEED" => array(__("Automatically show next feed"), __("After marking one as read")), |
|
90 | - "PURGE_OLD_DAYS" => array(__("Purge articles older than"), __("<strong>days</strong> (0 disables)")), |
|
91 | - "PURGE_UNREAD_ARTICLES" => array(__("Purge unread articles")), |
|
92 | - "REVERSE_HEADLINES" => array(__("Reverse headline order (oldest first)")), |
|
93 | - "SHORT_DATE_FORMAT" => array(__("Short date format")), |
|
94 | - "SHOW_CONTENT_PREVIEW" => array(__("Show content preview in headlines")), |
|
95 | - "SORT_HEADLINES_BY_FEED_DATE" => array(__("Sort headlines by feed date"), __("Use feed-specified date to sort headlines instead of local import date.")), |
|
96 | - "SSL_CERT_SERIAL" => array(__("SSL client certificate")), |
|
97 | - "STRIP_IMAGES" => array(__("Do not embed media")), |
|
98 | - "STRIP_UNSAFE_TAGS" => array(__("Strip unsafe tags from articles"), __("Strip all but most common HTML tags when reading articles.")), |
|
99 | - "USER_STYLESHEET" => array(__("Customize stylesheet")), |
|
100 | - "USER_TIMEZONE" => array(__("Time zone")), |
|
101 | - "VFEED_GROUP_BY_FEED" => array(__("Group by feed"), __("Group multiple-feed output by originating feed")), |
|
102 | - "USER_LANGUAGE" => array(__("Language")), |
|
103 | - "USER_CSS_THEME" => array(__("Theme")) |
|
104 | - ]; |
|
105 | - |
|
106 | - $this->pref_blacklist = ["ALLOW_DUPLICATE_POSTS", "STRIP_UNSAFE_TAGS", "REVERSE_HEADLINES", |
|
107 | - "SORT_HEADLINES_BY_FEED_DATE", "DEFAULT_ARTICLE_LIMIT", |
|
108 | - "FEEDS_SORT_BY_UNREAD", "USER_STYLESHEET"]; |
|
109 | - |
|
110 | - /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */ |
|
111 | - |
|
112 | - $this->profile_blacklist = ["ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS", |
|
113 | - "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP", |
|
114 | - "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE", |
|
115 | - "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE", |
|
116 | - "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME"]; |
|
117 | - } |
|
118 | - |
|
119 | - public function changepassword() { |
|
120 | - |
|
121 | - if (defined('_TTRSS_DEMO_INSTANCE')) { |
|
122 | - print "ERROR: ".format_error("Disabled in demo version."); |
|
123 | - return; |
|
124 | - } |
|
125 | - |
|
126 | - $old_pw = clean($_POST["old_password"]); |
|
127 | - $new_pw = clean($_POST["new_password"]); |
|
128 | - $con_pw = clean($_POST["confirm_password"]); |
|
129 | - |
|
130 | - if ($old_pw == $new_pw) { |
|
131 | - print "ERROR: ".format_error("New password must be different from the old one."); |
|
132 | - return; |
|
133 | - } |
|
134 | - |
|
135 | - if ($old_pw == "") { |
|
136 | - print "ERROR: ".format_error("Old password cannot be blank."); |
|
137 | - return; |
|
138 | - } |
|
139 | - |
|
140 | - if ($new_pw == "") { |
|
141 | - print "ERROR: ".format_error("New password cannot be blank."); |
|
142 | - return; |
|
143 | - } |
|
144 | - |
|
145 | - if ($new_pw != $con_pw) { |
|
146 | - print "ERROR: ".format_error("Entered passwords do not match."); |
|
147 | - return; |
|
148 | - } |
|
149 | - |
|
150 | - $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
151 | - |
|
152 | - if (method_exists($authenticator, "change_password")) { |
|
153 | - print format_notice($authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw)); |
|
154 | - } else { |
|
155 | - print "ERROR: ".format_error("Function not supported by authentication module."); |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - public function saveconfig() { |
|
160 | - $boolean_prefs = explode(",", clean($_POST["boolean_prefs"])); |
|
161 | - |
|
162 | - foreach ($boolean_prefs as $pref) { |
|
163 | - if (!isset($_POST[$pref])) { |
|
164 | - $_POST[$pref] = 'false'; |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - $need_reload = false; |
|
169 | - |
|
170 | - foreach (array_keys($_POST) as $pref_name) { |
|
171 | - |
|
172 | - $value = $_POST[$pref_name]; |
|
173 | - |
|
174 | - switch ($pref_name) { |
|
175 | - case 'DIGEST_PREFERRED_TIME': |
|
176 | - if (get_pref('DIGEST_PREFERRED_TIME') != $value) { |
|
177 | - |
|
178 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET |
|
5 | + private $pref_help = []; |
|
6 | + private $pref_item_map = []; |
|
7 | + private $pref_blacklist = []; |
|
8 | + private $profile_blacklist = []; |
|
9 | + |
|
10 | + public function csrf_ignore($method) { |
|
11 | + $csrf_ignored = array("index", "updateself", "customizecss", "editprefprofiles"); |
|
12 | + |
|
13 | + return array_search($method, $csrf_ignored) !== false; |
|
14 | + } |
|
15 | + |
|
16 | + public function __construct($args) { |
|
17 | + parent::__construct($args); |
|
18 | + |
|
19 | + $this->pref_item_map = [ |
|
20 | + __('General') => [ |
|
21 | + 'USER_LANGUAGE', |
|
22 | + 'USER_TIMEZONE', |
|
23 | + 'BLOCK_SEPARATOR', |
|
24 | + 'USER_CSS_THEME', |
|
25 | + 'BLOCK_SEPARATOR', |
|
26 | + 'ENABLE_API_ACCESS', |
|
27 | + ], |
|
28 | + __('Feeds') => [ |
|
29 | + 'DEFAULT_UPDATE_INTERVAL', |
|
30 | + 'FRESH_ARTICLE_MAX_AGE', |
|
31 | + 'DEFAULT_SEARCH_LANGUAGE', |
|
32 | + 'BLOCK_SEPARATOR', |
|
33 | + 'ENABLE_FEED_CATS', |
|
34 | + 'BLOCK_SEPARATOR', |
|
35 | + 'CONFIRM_FEED_CATCHUP', |
|
36 | + 'ON_CATCHUP_SHOW_NEXT_FEED', |
|
37 | + 'BLOCK_SEPARATOR', |
|
38 | + 'HIDE_READ_FEEDS', |
|
39 | + 'HIDE_READ_SHOWS_SPECIAL', |
|
40 | + ], |
|
41 | + __('Articles') => [ |
|
42 | + 'PURGE_OLD_DAYS', |
|
43 | + 'PURGE_UNREAD_ARTICLES', |
|
44 | + 'BLOCK_SEPARATOR', |
|
45 | + 'COMBINED_DISPLAY_MODE', |
|
46 | + 'CDM_EXPANDED', |
|
47 | + 'BLOCK_SEPARATOR', |
|
48 | + 'CDM_AUTO_CATCHUP', |
|
49 | + 'VFEED_GROUP_BY_FEED', |
|
50 | + 'BLOCK_SEPARATOR', |
|
51 | + 'SHOW_CONTENT_PREVIEW', |
|
52 | + 'STRIP_IMAGES', |
|
53 | + ], |
|
54 | + __('Digest') => [ |
|
55 | + 'DIGEST_ENABLE', |
|
56 | + 'DIGEST_CATCHUP', |
|
57 | + 'DIGEST_PREFERRED_TIME', |
|
58 | + ], |
|
59 | + __('Advanced') => [ |
|
60 | + 'BLACKLISTED_TAGS', |
|
61 | + 'BLOCK_SEPARATOR', |
|
62 | + 'LONG_DATE_FORMAT', |
|
63 | + 'SHORT_DATE_FORMAT', |
|
64 | + 'BLOCK_SEPARATOR', |
|
65 | + 'SSL_CERT_SERIAL', |
|
66 | + ] |
|
67 | + ]; |
|
68 | + |
|
69 | + $this->pref_help = [ |
|
70 | + "ALLOW_DUPLICATE_POSTS" => array(__("Allow duplicate articles"), ""), |
|
71 | + "BLACKLISTED_TAGS" => array(__("Blacklisted tags"), __("Never apply these tags automatically (comma-separated list).")), |
|
72 | + "DEFAULT_SEARCH_LANGUAGE" => array(__("Default language"), __("Used for full-text search")), |
|
73 | + "CDM_AUTO_CATCHUP" => array(__("Mark read on scroll"), __("Mark articles as read as you scroll past them")), |
|
74 | + "CDM_EXPANDED" => array(__("Always expand articles")), |
|
75 | + "COMBINED_DISPLAY_MODE" => array(__("Combined mode"), __("Show flat list of articles instead of separate panels")), |
|
76 | + "CONFIRM_FEED_CATCHUP" => array(__("Confirm marking feeds as read")), |
|
77 | + "DEFAULT_ARTICLE_LIMIT" => array(__("Amount of articles to display at once")), |
|
78 | + "DEFAULT_UPDATE_INTERVAL" => array(__("Default update interval")), |
|
79 | + "DIGEST_CATCHUP" => array(__("Mark sent articles as read")), |
|
80 | + "DIGEST_ENABLE" => array(__("Enable digest"), __("Send daily digest of new (and unread) headlines to your e-mail address")), |
|
81 | + "DIGEST_PREFERRED_TIME" => array(__("Try to send around this time"), __("Time in UTC")), |
|
82 | + "ENABLE_API_ACCESS" => array(__("Enable API"), __("Allows accessing this account through the API")), |
|
83 | + "ENABLE_FEED_CATS" => array(__("Enable categories")), |
|
84 | + "FEEDS_SORT_BY_UNREAD" => array(__("Sort feeds by unread articles count"), ""), |
|
85 | + "FRESH_ARTICLE_MAX_AGE" => array(__("Maximum age of fresh articles"), "<strong>".__("hours")."</strong>"), |
|
86 | + "HIDE_READ_FEEDS" => array(__("Hide read feeds")), |
|
87 | + "HIDE_READ_SHOWS_SPECIAL" => array(__("Always show special feeds"), __("While hiding read feeds")), |
|
88 | + "LONG_DATE_FORMAT" => array(__("Long date format"), __("Syntax is identical to PHP <a href='http://php.net/manual/function.date.php'>date()</a> function.")), |
|
89 | + "ON_CATCHUP_SHOW_NEXT_FEED" => array(__("Automatically show next feed"), __("After marking one as read")), |
|
90 | + "PURGE_OLD_DAYS" => array(__("Purge articles older than"), __("<strong>days</strong> (0 disables)")), |
|
91 | + "PURGE_UNREAD_ARTICLES" => array(__("Purge unread articles")), |
|
92 | + "REVERSE_HEADLINES" => array(__("Reverse headline order (oldest first)")), |
|
93 | + "SHORT_DATE_FORMAT" => array(__("Short date format")), |
|
94 | + "SHOW_CONTENT_PREVIEW" => array(__("Show content preview in headlines")), |
|
95 | + "SORT_HEADLINES_BY_FEED_DATE" => array(__("Sort headlines by feed date"), __("Use feed-specified date to sort headlines instead of local import date.")), |
|
96 | + "SSL_CERT_SERIAL" => array(__("SSL client certificate")), |
|
97 | + "STRIP_IMAGES" => array(__("Do not embed media")), |
|
98 | + "STRIP_UNSAFE_TAGS" => array(__("Strip unsafe tags from articles"), __("Strip all but most common HTML tags when reading articles.")), |
|
99 | + "USER_STYLESHEET" => array(__("Customize stylesheet")), |
|
100 | + "USER_TIMEZONE" => array(__("Time zone")), |
|
101 | + "VFEED_GROUP_BY_FEED" => array(__("Group by feed"), __("Group multiple-feed output by originating feed")), |
|
102 | + "USER_LANGUAGE" => array(__("Language")), |
|
103 | + "USER_CSS_THEME" => array(__("Theme")) |
|
104 | + ]; |
|
105 | + |
|
106 | + $this->pref_blacklist = ["ALLOW_DUPLICATE_POSTS", "STRIP_UNSAFE_TAGS", "REVERSE_HEADLINES", |
|
107 | + "SORT_HEADLINES_BY_FEED_DATE", "DEFAULT_ARTICLE_LIMIT", |
|
108 | + "FEEDS_SORT_BY_UNREAD", "USER_STYLESHEET"]; |
|
109 | + |
|
110 | + /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */ |
|
111 | + |
|
112 | + $this->profile_blacklist = ["ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS", |
|
113 | + "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP", |
|
114 | + "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE", |
|
115 | + "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE", |
|
116 | + "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME"]; |
|
117 | + } |
|
118 | + |
|
119 | + public function changepassword() { |
|
120 | + |
|
121 | + if (defined('_TTRSS_DEMO_INSTANCE')) { |
|
122 | + print "ERROR: ".format_error("Disabled in demo version."); |
|
123 | + return; |
|
124 | + } |
|
125 | + |
|
126 | + $old_pw = clean($_POST["old_password"]); |
|
127 | + $new_pw = clean($_POST["new_password"]); |
|
128 | + $con_pw = clean($_POST["confirm_password"]); |
|
129 | + |
|
130 | + if ($old_pw == $new_pw) { |
|
131 | + print "ERROR: ".format_error("New password must be different from the old one."); |
|
132 | + return; |
|
133 | + } |
|
134 | + |
|
135 | + if ($old_pw == "") { |
|
136 | + print "ERROR: ".format_error("Old password cannot be blank."); |
|
137 | + return; |
|
138 | + } |
|
139 | + |
|
140 | + if ($new_pw == "") { |
|
141 | + print "ERROR: ".format_error("New password cannot be blank."); |
|
142 | + return; |
|
143 | + } |
|
144 | + |
|
145 | + if ($new_pw != $con_pw) { |
|
146 | + print "ERROR: ".format_error("Entered passwords do not match."); |
|
147 | + return; |
|
148 | + } |
|
149 | + |
|
150 | + $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
151 | + |
|
152 | + if (method_exists($authenticator, "change_password")) { |
|
153 | + print format_notice($authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw)); |
|
154 | + } else { |
|
155 | + print "ERROR: ".format_error("Function not supported by authentication module."); |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + public function saveconfig() { |
|
160 | + $boolean_prefs = explode(",", clean($_POST["boolean_prefs"])); |
|
161 | + |
|
162 | + foreach ($boolean_prefs as $pref) { |
|
163 | + if (!isset($_POST[$pref])) { |
|
164 | + $_POST[$pref] = 'false'; |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + $need_reload = false; |
|
169 | + |
|
170 | + foreach (array_keys($_POST) as $pref_name) { |
|
171 | + |
|
172 | + $value = $_POST[$pref_name]; |
|
173 | + |
|
174 | + switch ($pref_name) { |
|
175 | + case 'DIGEST_PREFERRED_TIME': |
|
176 | + if (get_pref('DIGEST_PREFERRED_TIME') != $value) { |
|
177 | + |
|
178 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET |
|
179 | 179 | last_digest_sent = NULL WHERE id = ?"); |
180 | - $sth->execute([$_SESSION['uid']]); |
|
180 | + $sth->execute([$_SESSION['uid']]); |
|
181 | 181 | |
182 | - } |
|
183 | - break; |
|
184 | - case 'USER_LANGUAGE': |
|
185 | - if (!$need_reload) { |
|
186 | - $need_reload = $_SESSION["language"] != $value; |
|
187 | - } |
|
188 | - break; |
|
182 | + } |
|
183 | + break; |
|
184 | + case 'USER_LANGUAGE': |
|
185 | + if (!$need_reload) { |
|
186 | + $need_reload = $_SESSION["language"] != $value; |
|
187 | + } |
|
188 | + break; |
|
189 | 189 | |
190 | - case 'USER_CSS_THEME': |
|
191 | - if (!$need_reload) { |
|
192 | - $need_reload = get_pref($pref_name) != $value; |
|
193 | - } |
|
194 | - break; |
|
195 | - } |
|
190 | + case 'USER_CSS_THEME': |
|
191 | + if (!$need_reload) { |
|
192 | + $need_reload = get_pref($pref_name) != $value; |
|
193 | + } |
|
194 | + break; |
|
195 | + } |
|
196 | 196 | |
197 | - set_pref($pref_name, $value); |
|
198 | - } |
|
197 | + set_pref($pref_name, $value); |
|
198 | + } |
|
199 | 199 | |
200 | - if ($need_reload) { |
|
201 | - print "PREFS_NEED_RELOAD"; |
|
202 | - } else { |
|
203 | - print __("The configuration was saved."); |
|
204 | - } |
|
205 | - } |
|
200 | + if ($need_reload) { |
|
201 | + print "PREFS_NEED_RELOAD"; |
|
202 | + } else { |
|
203 | + print __("The configuration was saved."); |
|
204 | + } |
|
205 | + } |
|
206 | 206 | |
207 | - public function changeemail() { |
|
207 | + public function changeemail() { |
|
208 | 208 | |
209 | - $email = clean($_POST["email"]); |
|
210 | - $full_name = clean($_POST["full_name"]); |
|
211 | - $active_uid = $_SESSION["uid"]; |
|
209 | + $email = clean($_POST["email"]); |
|
210 | + $full_name = clean($_POST["full_name"]); |
|
211 | + $active_uid = $_SESSION["uid"]; |
|
212 | 212 | |
213 | - $sth = $this->pdo->prepare("SELECT email, login, full_name FROM ttrss_users WHERE id = ?"); |
|
214 | - $sth->execute([$active_uid]); |
|
213 | + $sth = $this->pdo->prepare("SELECT email, login, full_name FROM ttrss_users WHERE id = ?"); |
|
214 | + $sth->execute([$active_uid]); |
|
215 | 215 | |
216 | - if ($row = $sth->fetch()) { |
|
217 | - $old_email = $row["email"]; |
|
216 | + if ($row = $sth->fetch()) { |
|
217 | + $old_email = $row["email"]; |
|
218 | 218 | |
219 | - if ($old_email != $email) { |
|
220 | - $mailer = new Mailer(); |
|
219 | + if ($old_email != $email) { |
|
220 | + $mailer = new Mailer(); |
|
221 | 221 | |
222 | - require_once "lib/MiniTemplator.class.php"; |
|
222 | + require_once "lib/MiniTemplator.class.php"; |
|
223 | 223 | |
224 | - $tpl = new MiniTemplator; |
|
224 | + $tpl = new MiniTemplator; |
|
225 | 225 | |
226 | - $tpl->readTemplateFromFile("templates/mail_change_template.txt"); |
|
226 | + $tpl->readTemplateFromFile("templates/mail_change_template.txt"); |
|
227 | 227 | |
228 | - $tpl->setVariable('LOGIN', $row["login"]); |
|
229 | - $tpl->setVariable('NEWMAIL', $email); |
|
230 | - $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
228 | + $tpl->setVariable('LOGIN', $row["login"]); |
|
229 | + $tpl->setVariable('NEWMAIL', $email); |
|
230 | + $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
231 | 231 | |
232 | - $tpl->addBlock('message'); |
|
232 | + $tpl->addBlock('message'); |
|
233 | 233 | |
234 | - $tpl->generateOutputToString($message); |
|
234 | + $tpl->generateOutputToString($message); |
|
235 | 235 | |
236 | - $mailer->mail(["to_name" => $row["login"], |
|
237 | - "to_address" => $row["email"], |
|
238 | - "subject" => "[tt-rss] Mail address change notification", |
|
239 | - "message" => $message]); |
|
236 | + $mailer->mail(["to_name" => $row["login"], |
|
237 | + "to_address" => $row["email"], |
|
238 | + "subject" => "[tt-rss] Mail address change notification", |
|
239 | + "message" => $message]); |
|
240 | 240 | |
241 | - } |
|
242 | - } |
|
241 | + } |
|
242 | + } |
|
243 | 243 | |
244 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET email = ?, |
|
244 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET email = ?, |
|
245 | 245 | full_name = ? WHERE id = ?"); |
246 | - $sth->execute([$email, $full_name, $active_uid]); |
|
246 | + $sth->execute([$email, $full_name, $active_uid]); |
|
247 | 247 | |
248 | - print __("Your personal data has been saved."); |
|
248 | + print __("Your personal data has been saved."); |
|
249 | 249 | |
250 | - return; |
|
251 | - } |
|
250 | + return; |
|
251 | + } |
|
252 | 252 | |
253 | - public function resetconfig() { |
|
253 | + public function resetconfig() { |
|
254 | 254 | |
255 | - $_SESSION["prefs_op_result"] = "reset-to-defaults"; |
|
255 | + $_SESSION["prefs_op_result"] = "reset-to-defaults"; |
|
256 | 256 | |
257 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_user_prefs |
|
257 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_user_prefs |
|
258 | 258 | WHERE (profile = :profile OR (:profile IS NULL AND profile IS NULL)) |
259 | 259 | AND owner_uid = :uid"); |
260 | - $sth->execute([":profile" => $_SESSION['profile'], ":uid" => $_SESSION['uid']]); |
|
260 | + $sth->execute([":profile" => $_SESSION['profile'], ":uid" => $_SESSION['uid']]); |
|
261 | 261 | |
262 | - initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]); |
|
262 | + initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]); |
|
263 | 263 | |
264 | - echo __("Your preferences are now set to default values."); |
|
265 | - } |
|
264 | + echo __("Your preferences are now set to default values."); |
|
265 | + } |
|
266 | 266 | |
267 | - public function index() { |
|
267 | + public function index() { |
|
268 | 268 | |
269 | - global $access_level_names; |
|
269 | + global $access_level_names; |
|
270 | 270 | |
271 | - $_SESSION["prefs_op_result"] = ""; |
|
271 | + $_SESSION["prefs_op_result"] = ""; |
|
272 | 272 | |
273 | - print "<div dojoType='dijit.layout.AccordionContainer' region='center'>"; |
|
274 | - print "<div dojoType='dijit.layout.AccordionPane' |
|
273 | + print "<div dojoType='dijit.layout.AccordionContainer' region='center'>"; |
|
274 | + print "<div dojoType='dijit.layout.AccordionPane' |
|
275 | 275 | title=\"<i class='material-icons'>person</i> ".__('Personal data / Authentication')."\">"; |
276 | 276 | |
277 | - print "<div dojoType='dijit.layout.TabContainer'>"; |
|
278 | - print "<div dojoType='dijit.layout.ContentPane' title=\"".__('Personal data')."\">"; |
|
277 | + print "<div dojoType='dijit.layout.TabContainer'>"; |
|
278 | + print "<div dojoType='dijit.layout.ContentPane' title=\"".__('Personal data')."\">"; |
|
279 | 279 | |
280 | - print "<form dojoType='dijit.form.Form' id='changeUserdataForm'>"; |
|
280 | + print "<form dojoType='dijit.form.Form' id='changeUserdataForm'>"; |
|
281 | 281 | |
282 | - print "<script type='dojo/method' event='onSubmit' args='evt'> |
|
282 | + print "<script type='dojo/method' event='onSubmit' args='evt'> |
|
283 | 283 | evt.preventDefault(); |
284 | 284 | if (this.validate()) { |
285 | 285 | Notify.progress('Saving data...', true); |
@@ -293,61 +293,61 @@ discard block |
||
293 | 293 | } |
294 | 294 | </script>"; |
295 | 295 | |
296 | - $sth = $this->pdo->prepare("SELECT email,full_name,otp_enabled, |
|
296 | + $sth = $this->pdo->prepare("SELECT email,full_name,otp_enabled, |
|
297 | 297 | access_level FROM ttrss_users |
298 | 298 | WHERE id = ?"); |
299 | - $sth->execute([$_SESSION["uid"]]); |
|
300 | - $row = $sth->fetch(); |
|
301 | - |
|
302 | - $email = htmlspecialchars($row["email"]); |
|
303 | - $full_name = htmlspecialchars($row["full_name"]); |
|
304 | - $otp_enabled = sql_bool_to_bool($row["otp_enabled"]); |
|
305 | - |
|
306 | - print "<fieldset>"; |
|
307 | - print "<label>".__('Full name:')."</label>"; |
|
308 | - print "<input dojoType='dijit.form.ValidationTextBox' name='full_name' required='1' value='$full_name'>"; |
|
309 | - print "</fieldset>"; |
|
310 | - |
|
311 | - print "<fieldset>"; |
|
312 | - print "<label>".__('E-mail:')."</label>"; |
|
313 | - print "<input dojoType='dijit.form.ValidationTextBox' name='email' required='1' value='$email'>"; |
|
314 | - print "</fieldset>"; |
|
315 | - |
|
316 | - if (!SINGLE_USER_MODE && !$_SESSION["hide_hello"]) { |
|
317 | - |
|
318 | - $access_level = $row["access_level"]; |
|
319 | - print "<fieldset>"; |
|
320 | - print "<label>".__('Access level:')."</label>"; |
|
321 | - print $access_level_names[$access_level]; |
|
322 | - print "</fieldset>"; |
|
323 | - } |
|
299 | + $sth->execute([$_SESSION["uid"]]); |
|
300 | + $row = $sth->fetch(); |
|
324 | 301 | |
325 | - print_hidden("op", "pref-prefs"); |
|
326 | - print_hidden("method", "changeemail"); |
|
302 | + $email = htmlspecialchars($row["email"]); |
|
303 | + $full_name = htmlspecialchars($row["full_name"]); |
|
304 | + $otp_enabled = sql_bool_to_bool($row["otp_enabled"]); |
|
327 | 305 | |
328 | - print "<hr/>"; |
|
306 | + print "<fieldset>"; |
|
307 | + print "<label>".__('Full name:')."</label>"; |
|
308 | + print "<input dojoType='dijit.form.ValidationTextBox' name='full_name' required='1' value='$full_name'>"; |
|
309 | + print "</fieldset>"; |
|
329 | 310 | |
330 | - print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>". |
|
331 | - __("Save data")."</button>"; |
|
311 | + print "<fieldset>"; |
|
312 | + print "<label>".__('E-mail:')."</label>"; |
|
313 | + print "<input dojoType='dijit.form.ValidationTextBox' name='email' required='1' value='$email'>"; |
|
314 | + print "</fieldset>"; |
|
332 | 315 | |
333 | - print "</form>"; |
|
316 | + if (!SINGLE_USER_MODE && !$_SESSION["hide_hello"]) { |
|
334 | 317 | |
335 | - print "</div>"; # content pane |
|
336 | - print "<div dojoType='dijit.layout.ContentPane' title=\"".__('Password')."\">"; |
|
318 | + $access_level = $row["access_level"]; |
|
319 | + print "<fieldset>"; |
|
320 | + print "<label>".__('Access level:')."</label>"; |
|
321 | + print $access_level_names[$access_level]; |
|
322 | + print "</fieldset>"; |
|
323 | + } |
|
337 | 324 | |
338 | - if ($_SESSION["auth_module"]) { |
|
339 | - $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
340 | - } else { |
|
341 | - $authenticator = false; |
|
342 | - } |
|
325 | + print_hidden("op", "pref-prefs"); |
|
326 | + print_hidden("method", "changeemail"); |
|
327 | + |
|
328 | + print "<hr/>"; |
|
343 | 329 | |
344 | - if ($authenticator && method_exists($authenticator, "change_password")) { |
|
330 | + print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>". |
|
331 | + __("Save data")."</button>"; |
|
345 | 332 | |
346 | - print "<div style='display : none' id='pwd_change_infobox'></div>"; |
|
333 | + print "</form>"; |
|
347 | 334 | |
348 | - print "<form dojoType='dijit.form.Form'>"; |
|
335 | + print "</div>"; # content pane |
|
336 | + print "<div dojoType='dijit.layout.ContentPane' title=\"".__('Password')."\">"; |
|
349 | 337 | |
350 | - print "<script type='dojo/method' event='onSubmit' args='evt'> |
|
338 | + if ($_SESSION["auth_module"]) { |
|
339 | + $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
340 | + } else { |
|
341 | + $authenticator = false; |
|
342 | + } |
|
343 | + |
|
344 | + if ($authenticator && method_exists($authenticator, "change_password")) { |
|
345 | + |
|
346 | + print "<div style='display : none' id='pwd_change_infobox'></div>"; |
|
347 | + |
|
348 | + print "<form dojoType='dijit.form.Form'>"; |
|
349 | + |
|
350 | + print "<script type='dojo/method' event='onSubmit' args='evt'> |
|
351 | 351 | evt.preventDefault(); |
352 | 352 | if (this.validate()) { |
353 | 353 | Notify.progress('Changing password...', true); |
@@ -376,71 +376,71 @@ discard block |
||
376 | 376 | } |
377 | 377 | </script>"; |
378 | 378 | |
379 | - if ($otp_enabled) { |
|
380 | - print_notice(__("Changing your current password will disable OTP.")); |
|
381 | - } |
|
379 | + if ($otp_enabled) { |
|
380 | + print_notice(__("Changing your current password will disable OTP.")); |
|
381 | + } |
|
382 | 382 | |
383 | - print "<fieldset>"; |
|
384 | - print "<label>".__("Old password:")."</label>"; |
|
385 | - print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='old_password'>"; |
|
386 | - print "</fieldset>"; |
|
383 | + print "<fieldset>"; |
|
384 | + print "<label>".__("Old password:")."</label>"; |
|
385 | + print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='old_password'>"; |
|
386 | + print "</fieldset>"; |
|
387 | 387 | |
388 | - print "<fieldset>"; |
|
389 | - print "<label>".__("New password:")."</label>"; |
|
390 | - print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='new_password'>"; |
|
391 | - print "</fieldset>"; |
|
388 | + print "<fieldset>"; |
|
389 | + print "<label>".__("New password:")."</label>"; |
|
390 | + print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='new_password'>"; |
|
391 | + print "</fieldset>"; |
|
392 | 392 | |
393 | - print "<fieldset>"; |
|
394 | - print "<label>".__("Confirm password:")."</label>"; |
|
395 | - print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='confirm_password'>"; |
|
396 | - print "</fieldset>"; |
|
393 | + print "<fieldset>"; |
|
394 | + print "<label>".__("Confirm password:")."</label>"; |
|
395 | + print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='confirm_password'>"; |
|
396 | + print "</fieldset>"; |
|
397 | 397 | |
398 | - print_hidden("op", "pref-prefs"); |
|
399 | - print_hidden("method", "changepassword"); |
|
398 | + print_hidden("op", "pref-prefs"); |
|
399 | + print_hidden("method", "changepassword"); |
|
400 | 400 | |
401 | - print "<hr/>"; |
|
401 | + print "<hr/>"; |
|
402 | 402 | |
403 | - print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>". |
|
404 | - __("Change password")."</button>"; |
|
403 | + print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>". |
|
404 | + __("Change password")."</button>"; |
|
405 | 405 | |
406 | - print "</form>"; |
|
406 | + print "</form>"; |
|
407 | 407 | |
408 | - print "</div>"; # content pane |
|
408 | + print "</div>"; # content pane |
|
409 | 409 | |
410 | - if ($_SESSION["auth_module"] == "auth_internal") { |
|
410 | + if ($_SESSION["auth_module"] == "auth_internal") { |
|
411 | 411 | |
412 | - print "<div dojoType='dijit.layout.ContentPane' title=\"".__('App passwords')."\">"; |
|
412 | + print "<div dojoType='dijit.layout.ContentPane' title=\"".__('App passwords')."\">"; |
|
413 | 413 | |
414 | - print_notice("You can create separate passwords for API clients. Using one is required if you enable OTP."); |
|
414 | + print_notice("You can create separate passwords for API clients. Using one is required if you enable OTP."); |
|
415 | 415 | |
416 | - print "<div id='app_passwords_holder'>"; |
|
417 | - $this->appPasswordList(); |
|
418 | - print "</div>"; |
|
416 | + print "<div id='app_passwords_holder'>"; |
|
417 | + $this->appPasswordList(); |
|
418 | + print "</div>"; |
|
419 | 419 | |
420 | - print "<hr>"; |
|
420 | + print "<hr>"; |
|
421 | 421 | |
422 | - print "<button style='float : left' class='alt-primary' dojoType='dijit.form.Button' |
|
422 | + print "<button style='float : left' class='alt-primary' dojoType='dijit.form.Button' |
|
423 | 423 | onclick=\"Helpers.AppPasswords.generate()\">" . |
424 | - __('Generate new password')."</button> "; |
|
424 | + __('Generate new password')."</button> "; |
|
425 | 425 | |
426 | - print "<button style='float : left' class='alt-danger' dojoType='dijit.form.Button' |
|
426 | + print "<button style='float : left' class='alt-danger' dojoType='dijit.form.Button' |
|
427 | 427 | onclick=\"Helpers.AppPasswords.removeSelected()\">" . |
428 | - __('Remove selected passwords')."</button>"; |
|
428 | + __('Remove selected passwords')."</button>"; |
|
429 | 429 | |
430 | - print "</div>"; # content pane |
|
431 | - } |
|
430 | + print "</div>"; # content pane |
|
431 | + } |
|
432 | 432 | |
433 | - print "<div dojoType='dijit.layout.ContentPane' title=\"".__('One time passwords / Authenticator')."\">"; |
|
433 | + print "<div dojoType='dijit.layout.ContentPane' title=\"".__('One time passwords / Authenticator')."\">"; |
|
434 | 434 | |
435 | - if ($_SESSION["auth_module"] == "auth_internal") { |
|
435 | + if ($_SESSION["auth_module"] == "auth_internal") { |
|
436 | 436 | |
437 | - if ($otp_enabled) { |
|
437 | + if ($otp_enabled) { |
|
438 | 438 | |
439 | - print_warning("One time passwords are currently enabled. Enter your current password below to disable."); |
|
439 | + print_warning("One time passwords are currently enabled. Enter your current password below to disable."); |
|
440 | 440 | |
441 | - print "<form dojoType='dijit.form.Form'>"; |
|
441 | + print "<form dojoType='dijit.form.Form'>"; |
|
442 | 442 | |
443 | - print "<script type='dojo/method' event='onSubmit' args='evt'> |
|
443 | + print "<script type='dojo/method' event='onSubmit' args='evt'> |
|
444 | 444 | evt.preventDefault(); |
445 | 445 | if (this.validate()) { |
446 | 446 | Notify.progress('Disabling OTP', true); |
@@ -459,49 +459,49 @@ discard block |
||
459 | 459 | } |
460 | 460 | </script>"; |
461 | 461 | |
462 | - print "<fieldset>"; |
|
463 | - print "<label>".__("Your password:")."</label>"; |
|
464 | - print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='password'>"; |
|
465 | - print "</fieldset>"; |
|
462 | + print "<fieldset>"; |
|
463 | + print "<label>".__("Your password:")."</label>"; |
|
464 | + print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='password'>"; |
|
465 | + print "</fieldset>"; |
|
466 | 466 | |
467 | - print_hidden("op", "pref-prefs"); |
|
468 | - print_hidden("method", "otpdisable"); |
|
467 | + print_hidden("op", "pref-prefs"); |
|
468 | + print_hidden("method", "otpdisable"); |
|
469 | 469 | |
470 | - print "<hr/>"; |
|
470 | + print "<hr/>"; |
|
471 | 471 | |
472 | - print "<button dojoType='dijit.form.Button' type='submit'>". |
|
473 | - __("Disable OTP")."</button>"; |
|
472 | + print "<button dojoType='dijit.form.Button' type='submit'>". |
|
473 | + __("Disable OTP")."</button>"; |
|
474 | 474 | |
475 | - print "</form>"; |
|
475 | + print "</form>"; |
|
476 | 476 | |
477 | - } else { |
|
477 | + } else { |
|
478 | 478 | |
479 | - print_warning("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP."); |
|
480 | - print_notice("You will need to generate app passwords for the API clients if you enable OTP."); |
|
479 | + print_warning("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP."); |
|
480 | + print_notice("You will need to generate app passwords for the API clients if you enable OTP."); |
|
481 | 481 | |
482 | - if (function_exists("imagecreatefromstring")) { |
|
483 | - print "<h3>".__("Scan the following code by the Authenticator application or copy the key manually")."</h3>"; |
|
482 | + if (function_exists("imagecreatefromstring")) { |
|
483 | + print "<h3>".__("Scan the following code by the Authenticator application or copy the key manually")."</h3>"; |
|
484 | 484 | |
485 | - $csrf_token = $_SESSION["csrf_token"]; |
|
486 | - print "<img alt='otp qr-code' src='backend.php?op=pref-prefs&method=otpqrcode&csrf_token=$csrf_token'>"; |
|
487 | - } else { |
|
488 | - print_error("PHP GD functions are required to generate QR codes."); |
|
489 | - print "<h3>".__("Use the following OTP key with a compatible Authenticator application")."</h3>"; |
|
490 | - } |
|
485 | + $csrf_token = $_SESSION["csrf_token"]; |
|
486 | + print "<img alt='otp qr-code' src='backend.php?op=pref-prefs&method=otpqrcode&csrf_token=$csrf_token'>"; |
|
487 | + } else { |
|
488 | + print_error("PHP GD functions are required to generate QR codes."); |
|
489 | + print "<h3>".__("Use the following OTP key with a compatible Authenticator application")."</h3>"; |
|
490 | + } |
|
491 | 491 | |
492 | - print "<form dojoType='dijit.form.Form' id='changeOtpForm'>"; |
|
492 | + print "<form dojoType='dijit.form.Form' id='changeOtpForm'>"; |
|
493 | 493 | |
494 | - $otp_secret = $this->otpsecret(); |
|
494 | + $otp_secret = $this->otpsecret(); |
|
495 | 495 | |
496 | - print "<fieldset>"; |
|
497 | - print "<label>".__("OTP Key:")."</label>"; |
|
498 | - print "<input dojoType='dijit.form.ValidationTextBox' disabled='disabled' value='$otp_secret' size='32'>"; |
|
499 | - print "</fieldset>"; |
|
496 | + print "<fieldset>"; |
|
497 | + print "<label>".__("OTP Key:")."</label>"; |
|
498 | + print "<input dojoType='dijit.form.ValidationTextBox' disabled='disabled' value='$otp_secret' size='32'>"; |
|
499 | + print "</fieldset>"; |
|
500 | 500 | |
501 | - print_hidden("op", "pref-prefs"); |
|
502 | - print_hidden("method", "otpenable"); |
|
501 | + print_hidden("op", "pref-prefs"); |
|
502 | + print_hidden("method", "otpenable"); |
|
503 | 503 | |
504 | - print "<script type='dojo/method' event='onSubmit' args='evt'> |
|
504 | + print "<script type='dojo/method' event='onSubmit' args='evt'> |
|
505 | 505 | evt.preventDefault(); |
506 | 506 | if (this.validate()) { |
507 | 507 | Notify.progress('Saving data...', true); |
@@ -520,43 +520,43 @@ discard block |
||
520 | 520 | } |
521 | 521 | </script>"; |
522 | 522 | |
523 | - print "<fieldset>"; |
|
524 | - print "<label>".__("Your password:")."</label>"; |
|
525 | - print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' |
|
523 | + print "<fieldset>"; |
|
524 | + print "<label>".__("Your password:")."</label>"; |
|
525 | + print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' |
|
526 | 526 | name='password'>"; |
527 | - print "</fieldset>"; |
|
527 | + print "</fieldset>"; |
|
528 | 528 | |
529 | - print "<fieldset>"; |
|
530 | - print "<label>".__("One time password:")."</label>"; |
|
531 | - print "<input dojoType='dijit.form.ValidationTextBox' autocomplete='off' |
|
529 | + print "<fieldset>"; |
|
530 | + print "<label>".__("One time password:")."</label>"; |
|
531 | + print "<input dojoType='dijit.form.ValidationTextBox' autocomplete='off' |
|
532 | 532 | required='1' name='otp'>"; |
533 | - print "</fieldset>"; |
|
533 | + print "</fieldset>"; |
|
534 | 534 | |
535 | - print "<hr/>"; |
|
536 | - print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>". |
|
537 | - __("Enable OTP")."</button>"; |
|
535 | + print "<hr/>"; |
|
536 | + print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>". |
|
537 | + __("Enable OTP")."</button>"; |
|
538 | 538 | |
539 | - print "</form>"; |
|
539 | + print "</form>"; |
|
540 | 540 | |
541 | - } |
|
542 | - } |
|
541 | + } |
|
542 | + } |
|
543 | 543 | |
544 | - print "</div>"; # content pane |
|
545 | - print "</div>"; # tab container |
|
544 | + print "</div>"; # content pane |
|
545 | + print "</div>"; # tab container |
|
546 | 546 | |
547 | - } |
|
547 | + } |
|
548 | 548 | |
549 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
550 | - "hook_prefs_tab_section", "prefPrefsAuth"); |
|
549 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
550 | + "hook_prefs_tab_section", "prefPrefsAuth"); |
|
551 | 551 | |
552 | - print "</div>"; #pane |
|
552 | + print "</div>"; #pane |
|
553 | 553 | |
554 | - print "<div dojoType='dijit.layout.AccordionPane' selected='true' |
|
554 | + print "<div dojoType='dijit.layout.AccordionPane' selected='true' |
|
555 | 555 | title=\"<i class='material-icons'>settings</i> ".__('Preferences')."\">"; |
556 | 556 | |
557 | - print "<form dojoType='dijit.form.Form' id='changeSettingsForm'>"; |
|
557 | + print "<form dojoType='dijit.form.Form' id='changeSettingsForm'>"; |
|
558 | 558 | |
559 | - print "<script type='dojo/method' event='onSubmit' args='evt, quit'> |
|
559 | + print "<script type='dojo/method' event='onSubmit' args='evt, quit'> |
|
560 | 560 | if (evt) evt.preventDefault(); |
561 | 561 | if (this.validate()) { |
562 | 562 | console.log(dojo.objectToQuery(this.getValues())); |
@@ -578,23 +578,23 @@ discard block |
||
578 | 578 | } |
579 | 579 | </script>"; |
580 | 580 | |
581 | - print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; |
|
581 | + print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; |
|
582 | 582 | |
583 | - print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">'; |
|
583 | + print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">'; |
|
584 | 584 | |
585 | - $profile = $_SESSION["profile"]; |
|
585 | + $profile = $_SESSION["profile"]; |
|
586 | 586 | |
587 | - if ($profile) { |
|
588 | - print_notice(__("Some preferences are only available in default profile.")); |
|
587 | + if ($profile) { |
|
588 | + print_notice(__("Some preferences are only available in default profile.")); |
|
589 | 589 | |
590 | - initialize_user_prefs($_SESSION["uid"], $profile); |
|
591 | - } else { |
|
592 | - initialize_user_prefs($_SESSION["uid"]); |
|
593 | - } |
|
590 | + initialize_user_prefs($_SESSION["uid"], $profile); |
|
591 | + } else { |
|
592 | + initialize_user_prefs($_SESSION["uid"]); |
|
593 | + } |
|
594 | 594 | |
595 | - $prefs_available = []; |
|
595 | + $prefs_available = []; |
|
596 | 596 | |
597 | - $sth = $this->pdo->prepare("SELECT DISTINCT |
|
597 | + $sth = $this->pdo->prepare("SELECT DISTINCT |
|
598 | 598 | ttrss_user_prefs.pref_name,value,type_name, |
599 | 599 | ttrss_prefs_sections.order_id, |
600 | 600 | def_value,section_id |
@@ -605,235 +605,235 @@ discard block |
||
605 | 605 | ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND |
606 | 606 | owner_uid = :uid |
607 | 607 | ORDER BY ttrss_prefs_sections.order_id,pref_name"); |
608 | - $sth->execute([":uid" => $_SESSION['uid'], ":profile" => $profile]); |
|
608 | + $sth->execute([":uid" => $_SESSION['uid'], ":profile" => $profile]); |
|
609 | 609 | |
610 | - $listed_boolean_prefs = []; |
|
610 | + $listed_boolean_prefs = []; |
|
611 | 611 | |
612 | - while ($line = $sth->fetch()) { |
|
612 | + while ($line = $sth->fetch()) { |
|
613 | 613 | |
614 | - if (in_array($line["pref_name"], $this->pref_blacklist)) { |
|
615 | - continue; |
|
616 | - } |
|
614 | + if (in_array($line["pref_name"], $this->pref_blacklist)) { |
|
615 | + continue; |
|
616 | + } |
|
617 | 617 | |
618 | - if ($profile && in_array($line["pref_name"], $this->profile_blacklist)) { |
|
619 | - continue; |
|
620 | - } |
|
618 | + if ($profile && in_array($line["pref_name"], $this->profile_blacklist)) { |
|
619 | + continue; |
|
620 | + } |
|
621 | 621 | |
622 | - $pref_name = $line["pref_name"]; |
|
623 | - $short_desc = $this->getShortDesc($pref_name); |
|
622 | + $pref_name = $line["pref_name"]; |
|
623 | + $short_desc = $this->getShortDesc($pref_name); |
|
624 | 624 | |
625 | - if (!$short_desc) { |
|
626 | - continue; |
|
627 | - } |
|
625 | + if (!$short_desc) { |
|
626 | + continue; |
|
627 | + } |
|
628 | 628 | |
629 | - $prefs_available[$pref_name] = [ |
|
630 | - 'type_name' => $line["type_name"], |
|
631 | - 'value' => $line['value'], |
|
632 | - 'help_text' => $this->getHelpText($pref_name), |
|
633 | - 'short_desc' => $short_desc |
|
634 | - ]; |
|
635 | - } |
|
629 | + $prefs_available[$pref_name] = [ |
|
630 | + 'type_name' => $line["type_name"], |
|
631 | + 'value' => $line['value'], |
|
632 | + 'help_text' => $this->getHelpText($pref_name), |
|
633 | + 'short_desc' => $short_desc |
|
634 | + ]; |
|
635 | + } |
|
636 | 636 | |
637 | - foreach (array_keys($this->pref_item_map) as $section) { |
|
637 | + foreach (array_keys($this->pref_item_map) as $section) { |
|
638 | 638 | |
639 | - print "<h2>$section</h2>"; |
|
639 | + print "<h2>$section</h2>"; |
|
640 | 640 | |
641 | - foreach ($this->pref_item_map[$section] as $pref_name) { |
|
641 | + foreach ($this->pref_item_map[$section] as $pref_name) { |
|
642 | 642 | |
643 | - if ($pref_name == 'BLOCK_SEPARATOR' && !$profile) { |
|
644 | - print "<hr/>"; |
|
645 | - continue; |
|
646 | - } |
|
643 | + if ($pref_name == 'BLOCK_SEPARATOR' && !$profile) { |
|
644 | + print "<hr/>"; |
|
645 | + continue; |
|
646 | + } |
|
647 | 647 | |
648 | - if ($pref_name == "DEFAULT_SEARCH_LANGUAGE" && DB_TYPE != "pgsql") { |
|
649 | - continue; |
|
650 | - } |
|
648 | + if ($pref_name == "DEFAULT_SEARCH_LANGUAGE" && DB_TYPE != "pgsql") { |
|
649 | + continue; |
|
650 | + } |
|
651 | 651 | |
652 | - if ($item = $prefs_available[$pref_name]) { |
|
652 | + if ($item = $prefs_available[$pref_name]) { |
|
653 | 653 | |
654 | - print "<fieldset class='prefs'>"; |
|
654 | + print "<fieldset class='prefs'>"; |
|
655 | 655 | |
656 | - print "<label for='CB_$pref_name'>"; |
|
657 | - print $item['short_desc'].":"; |
|
658 | - print "</label>"; |
|
656 | + print "<label for='CB_$pref_name'>"; |
|
657 | + print $item['short_desc'].":"; |
|
658 | + print "</label>"; |
|
659 | 659 | |
660 | - $value = $item['value']; |
|
661 | - $type_name = $item['type_name']; |
|
660 | + $value = $item['value']; |
|
661 | + $type_name = $item['type_name']; |
|
662 | 662 | |
663 | - if ($pref_name == "USER_LANGUAGE") { |
|
664 | - print_select_hash($pref_name, $value, get_translations(), |
|
665 | - "style='width : 220px; margin : 0px' dojoType='fox.form.Select'"); |
|
663 | + if ($pref_name == "USER_LANGUAGE") { |
|
664 | + print_select_hash($pref_name, $value, get_translations(), |
|
665 | + "style='width : 220px; margin : 0px' dojoType='fox.form.Select'"); |
|
666 | 666 | |
667 | - } else if ($pref_name == "USER_TIMEZONE") { |
|
667 | + } else if ($pref_name == "USER_TIMEZONE") { |
|
668 | 668 | |
669 | - $timezones = explode("\n", file_get_contents("lib/timezones.txt")); |
|
669 | + $timezones = explode("\n", file_get_contents("lib/timezones.txt")); |
|
670 | 670 | |
671 | - print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"'); |
|
672 | - } else if ($pref_name == "USER_CSS_THEME") { |
|
671 | + print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"'); |
|
672 | + } else if ($pref_name == "USER_CSS_THEME") { |
|
673 | 673 | |
674 | - $themes = array_merge(glob("themes/*.php"), glob("themes/*.css"), glob("themes.local/*.css")); |
|
675 | - $themes = array_map("basename", $themes); |
|
676 | - $themes = array_filter($themes, "theme_exists"); |
|
677 | - asort($themes); |
|
674 | + $themes = array_merge(glob("themes/*.php"), glob("themes/*.css"), glob("themes.local/*.css")); |
|
675 | + $themes = array_map("basename", $themes); |
|
676 | + $themes = array_filter($themes, "theme_exists"); |
|
677 | + asort($themes); |
|
678 | 678 | |
679 | - if (!theme_exists($value)) { |
|
680 | - $value = "default.php"; |
|
681 | - } |
|
679 | + if (!theme_exists($value)) { |
|
680 | + $value = "default.php"; |
|
681 | + } |
|
682 | 682 | |
683 | - print "<select name='$pref_name' id='$pref_name' dojoType='fox.form.Select'>"; |
|
683 | + print "<select name='$pref_name' id='$pref_name' dojoType='fox.form.Select'>"; |
|
684 | 684 | |
685 | - $issel = $value == "default.php" ? "selected='selected'" : ""; |
|
686 | - print "<option $issel value='default.php'>".__("default")."</option>"; |
|
685 | + $issel = $value == "default.php" ? "selected='selected'" : ""; |
|
686 | + print "<option $issel value='default.php'>".__("default")."</option>"; |
|
687 | 687 | |
688 | - foreach ($themes as $theme) { |
|
689 | - $issel = $value == $theme ? "selected='selected'" : ""; |
|
690 | - print "<option $issel value='$theme'>$theme</option>"; |
|
691 | - } |
|
688 | + foreach ($themes as $theme) { |
|
689 | + $issel = $value == $theme ? "selected='selected'" : ""; |
|
690 | + print "<option $issel value='$theme'>$theme</option>"; |
|
691 | + } |
|
692 | 692 | |
693 | - print "</select>"; |
|
693 | + print "</select>"; |
|
694 | 694 | |
695 | - print " <button dojoType=\"dijit.form.Button\" class='alt-info' |
|
695 | + print " <button dojoType=\"dijit.form.Button\" class='alt-info' |
|
696 | 696 | onclick=\"Helpers.customizeCSS()\">" . __('Customize')."</button>"; |
697 | 697 | |
698 | - print " <button dojoType='dijit.form.Button' onclick='window.open(\"https://tt-rss.org/wiki/Themes\")'> |
|
698 | + print " <button dojoType='dijit.form.Button' onclick='window.open(\"https://tt-rss.org/wiki/Themes\")'> |
|
699 | 699 | <i class='material-icons'>open_in_new</i> ".__("More themes...")."</button>"; |
700 | 700 | |
701 | - } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") { |
|
701 | + } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") { |
|
702 | 702 | |
703 | - global $update_intervals_nodefault; |
|
703 | + global $update_intervals_nodefault; |
|
704 | 704 | |
705 | - print_select_hash($pref_name, $value, $update_intervals_nodefault, |
|
706 | - 'dojoType="fox.form.Select"'); |
|
707 | - } else if ($pref_name == "DEFAULT_SEARCH_LANGUAGE") { |
|
705 | + print_select_hash($pref_name, $value, $update_intervals_nodefault, |
|
706 | + 'dojoType="fox.form.Select"'); |
|
707 | + } else if ($pref_name == "DEFAULT_SEARCH_LANGUAGE") { |
|
708 | 708 | |
709 | - print_select($pref_name, $value, Pref_Feeds::get_ts_languages(), |
|
710 | - 'dojoType="fox.form.Select"'); |
|
709 | + print_select($pref_name, $value, Pref_Feeds::get_ts_languages(), |
|
710 | + 'dojoType="fox.form.Select"'); |
|
711 | 711 | |
712 | - } else if ($type_name == "bool") { |
|
712 | + } else if ($type_name == "bool") { |
|
713 | 713 | |
714 | - array_push($listed_boolean_prefs, $pref_name); |
|
714 | + array_push($listed_boolean_prefs, $pref_name); |
|
715 | 715 | |
716 | - $checked = ($value == "true") ? "checked=\"checked\"" : ""; |
|
716 | + $checked = ($value == "true") ? "checked=\"checked\"" : ""; |
|
717 | 717 | |
718 | - if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) { |
|
719 | - $disabled = "disabled=\"1\""; |
|
720 | - $checked = "checked=\"checked\""; |
|
721 | - } else { |
|
722 | - $disabled = ""; |
|
723 | - } |
|
718 | + if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) { |
|
719 | + $disabled = "disabled=\"1\""; |
|
720 | + $checked = "checked=\"checked\""; |
|
721 | + } else { |
|
722 | + $disabled = ""; |
|
723 | + } |
|
724 | 724 | |
725 | - print "<input type='checkbox' name='$pref_name' $checked $disabled |
|
725 | + print "<input type='checkbox' name='$pref_name' $checked $disabled |
|
726 | 726 | dojoType='dijit.form.CheckBox' id='CB_$pref_name' value='1'>"; |
727 | 727 | |
728 | - } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', |
|
729 | - 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) { |
|
728 | + } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', |
|
729 | + 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) { |
|
730 | 730 | |
731 | - $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; |
|
731 | + $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; |
|
732 | 732 | |
733 | - if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) { |
|
734 | - $disabled = "disabled='1'"; |
|
735 | - $value = FORCE_ARTICLE_PURGE; |
|
736 | - } else { |
|
737 | - $disabled = ""; |
|
738 | - } |
|
733 | + if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) { |
|
734 | + $disabled = "disabled='1'"; |
|
735 | + $value = FORCE_ARTICLE_PURGE; |
|
736 | + } else { |
|
737 | + $disabled = ""; |
|
738 | + } |
|
739 | 739 | |
740 | - if ($type_name == 'integer') { |
|
741 | - print "<input dojoType=\"dijit.form.NumberSpinner\" |
|
740 | + if ($type_name == 'integer') { |
|
741 | + print "<input dojoType=\"dijit.form.NumberSpinner\" |
|
742 | 742 | required='1' $disabled |
743 | 743 | name=\"$pref_name\" value=\"$value\">"; |
744 | - } else { |
|
745 | - print "<input dojoType=\"dijit.form.TextBox\" |
|
744 | + } else { |
|
745 | + print "<input dojoType=\"dijit.form.TextBox\" |
|
746 | 746 | required='1' $regexp $disabled |
747 | 747 | name=\"$pref_name\" value=\"$value\">"; |
748 | - } |
|
748 | + } |
|
749 | 749 | |
750 | - } else if ($pref_name == "SSL_CERT_SERIAL") { |
|
750 | + } else if ($pref_name == "SSL_CERT_SERIAL") { |
|
751 | 751 | |
752 | - print "<input dojoType='dijit.form.ValidationTextBox' |
|
752 | + print "<input dojoType='dijit.form.ValidationTextBox' |
|
753 | 753 | id='SSL_CERT_SERIAL' readonly='1' |
754 | 754 | name=\"$pref_name\" value=\"$value\">"; |
755 | 755 | |
756 | - $cert_serial = htmlspecialchars(get_ssl_certificate_id()); |
|
757 | - $has_serial = ($cert_serial) ? "false" : "true"; |
|
756 | + $cert_serial = htmlspecialchars(get_ssl_certificate_id()); |
|
757 | + $has_serial = ($cert_serial) ? "false" : "true"; |
|
758 | 758 | |
759 | - print "<button dojoType='dijit.form.Button' disabled='$has_serial' |
|
759 | + print "<button dojoType='dijit.form.Button' disabled='$has_serial' |
|
760 | 760 | onclick=\"dijit.byId('SSL_CERT_SERIAL').attr('value', '$cert_serial')\">". |
761 | - __('Register')."</button>"; |
|
761 | + __('Register')."</button>"; |
|
762 | 762 | |
763 | - print "<button dojoType='dijit.form.Button' class='alt-danger' |
|
763 | + print "<button dojoType='dijit.form.Button' class='alt-danger' |
|
764 | 764 | onclick=\"dijit.byId('SSL_CERT_SERIAL').attr('value', '')\">" . |
765 | - __('Clear')."</button>"; |
|
765 | + __('Clear')."</button>"; |
|
766 | 766 | |
767 | - print "<button dojoType='dijit.form.Button' class='alt-info' |
|
767 | + print "<button dojoType='dijit.form.Button' class='alt-info' |
|
768 | 768 | onclick='window.open(\"https://tt-rss.org/wiki/SSL%20Certificate%20Authentication\")'> |
769 | 769 | <i class='material-icons'>help</i> ".__("More info...")."</button>"; |
770 | 770 | |
771 | - } else if ($pref_name == 'DIGEST_PREFERRED_TIME') { |
|
772 | - print "<input dojoType=\"dijit.form.ValidationTextBox\" |
|
771 | + } else if ($pref_name == 'DIGEST_PREFERRED_TIME') { |
|
772 | + print "<input dojoType=\"dijit.form.ValidationTextBox\" |
|
773 | 773 | id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\" |
774 | 774 | name=\"$pref_name\" value=\"$value\">"; |
775 | 775 | |
776 | - $item['help_text'] .= ". ".T_sprintf("Current server time: %s", date("H:i")); |
|
777 | - } else { |
|
778 | - $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; |
|
776 | + $item['help_text'] .= ". ".T_sprintf("Current server time: %s", date("H:i")); |
|
777 | + } else { |
|
778 | + $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; |
|
779 | 779 | |
780 | - print "<input dojoType=\"dijit.form.ValidationTextBox\" $regexp name=\"$pref_name\" value=\"$value\">"; |
|
781 | - } |
|
780 | + print "<input dojoType=\"dijit.form.ValidationTextBox\" $regexp name=\"$pref_name\" value=\"$value\">"; |
|
781 | + } |
|
782 | 782 | |
783 | - if ($item['help_text']) { |
|
784 | - print "<div class='help-text text-muted'><label for='CB_$pref_name'>".$item['help_text']."</label></div>"; |
|
785 | - } |
|
783 | + if ($item['help_text']) { |
|
784 | + print "<div class='help-text text-muted'><label for='CB_$pref_name'>".$item['help_text']."</label></div>"; |
|
785 | + } |
|
786 | 786 | |
787 | - print "</fieldset>"; |
|
788 | - } |
|
789 | - } |
|
790 | - } |
|
787 | + print "</fieldset>"; |
|
788 | + } |
|
789 | + } |
|
790 | + } |
|
791 | 791 | |
792 | - $listed_boolean_prefs = htmlspecialchars(join(",", $listed_boolean_prefs)); |
|
792 | + $listed_boolean_prefs = htmlspecialchars(join(",", $listed_boolean_prefs)); |
|
793 | 793 | |
794 | - print_hidden("boolean_prefs", "$listed_boolean_prefs"); |
|
794 | + print_hidden("boolean_prefs", "$listed_boolean_prefs"); |
|
795 | 795 | |
796 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
797 | - "hook_prefs_tab_section", "prefPrefsPrefsInside"); |
|
796 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
797 | + "hook_prefs_tab_section", "prefPrefsPrefsInside"); |
|
798 | 798 | |
799 | - print '</div>'; # inside pane |
|
800 | - print '<div dojoType="dijit.layout.ContentPane" region="bottom">'; |
|
799 | + print '</div>'; # inside pane |
|
800 | + print '<div dojoType="dijit.layout.ContentPane" region="bottom">'; |
|
801 | 801 | |
802 | - print_hidden("op", "pref-prefs"); |
|
803 | - print_hidden("method", "saveconfig"); |
|
802 | + print_hidden("op", "pref-prefs"); |
|
803 | + print_hidden("method", "saveconfig"); |
|
804 | 804 | |
805 | - print "<div dojoType=\"fox.form.ComboButton\" type=\"submit\" class=\"alt-primary\"> |
|
805 | + print "<div dojoType=\"fox.form.ComboButton\" type=\"submit\" class=\"alt-primary\"> |
|
806 | 806 | <span>".__('Save configuration')."</span> |
807 | 807 | <div dojoType=\"dijit.DropDownMenu\"> |
808 | 808 | <div dojoType=\"dijit.MenuItem\" |
809 | 809 | onclick=\"dijit.byId('changeSettingsForm').onSubmit(null, true)\">". |
810 | - __("Save and exit preferences")."</div> |
|
810 | + __("Save and exit preferences")."</div> |
|
811 | 811 | </div> |
812 | 812 | </div>"; |
813 | 813 | |
814 | - print "<button dojoType=\"dijit.form.Button\" onclick=\"return Helpers.editProfiles()\">". |
|
815 | - __('Manage profiles')."</button> "; |
|
814 | + print "<button dojoType=\"dijit.form.Button\" onclick=\"return Helpers.editProfiles()\">". |
|
815 | + __('Manage profiles')."</button> "; |
|
816 | 816 | |
817 | - print "<button dojoType=\"dijit.form.Button\" class=\"alt-danger\" onclick=\"return Helpers.confirmReset()\">". |
|
818 | - __('Reset to defaults')."</button>"; |
|
817 | + print "<button dojoType=\"dijit.form.Button\" class=\"alt-danger\" onclick=\"return Helpers.confirmReset()\">". |
|
818 | + __('Reset to defaults')."</button>"; |
|
819 | 819 | |
820 | - print " "; |
|
820 | + print " "; |
|
821 | 821 | |
822 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
823 | - "hook_prefs_tab_section", "prefPrefsPrefsOutside"); |
|
822 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
|
823 | + "hook_prefs_tab_section", "prefPrefsPrefsOutside"); |
|
824 | 824 | |
825 | - print "</form>"; |
|
826 | - print '</div>'; # inner pane |
|
827 | - print '</div>'; # border container |
|
825 | + print "</form>"; |
|
826 | + print '</div>'; # inner pane |
|
827 | + print '</div>'; # border container |
|
828 | 828 | |
829 | - print "</div>"; #pane |
|
829 | + print "</div>"; #pane |
|
830 | 830 | |
831 | - print "<div dojoType=\"dijit.layout.AccordionPane\" |
|
831 | + print "<div dojoType=\"dijit.layout.AccordionPane\" |
|
832 | 832 | title=\"<i class='material-icons'>extension</i> ".__('Plugins')."\">"; |
833 | 833 | |
834 | - print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">"; |
|
834 | + print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">"; |
|
835 | 835 | |
836 | - print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> |
|
836 | + print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> |
|
837 | 837 | evt.preventDefault(); |
838 | 838 | if (this.validate()) { |
839 | 839 | Notify.progress('Saving data...', true); |
@@ -850,384 +850,384 @@ discard block |
||
850 | 850 | } |
851 | 851 | </script>"; |
852 | 852 | |
853 | - print_hidden("op", "pref-prefs"); |
|
854 | - print_hidden("method", "setplugins"); |
|
853 | + print_hidden("op", "pref-prefs"); |
|
854 | + print_hidden("method", "setplugins"); |
|
855 | 855 | |
856 | - print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; |
|
857 | - print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">'; |
|
856 | + print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; |
|
857 | + print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">'; |
|
858 | 858 | |
859 | - if (ini_get("open_basedir") && function_exists("curl_init") && !defined("NO_CURL")) { |
|
860 | - print_warning("Your PHP configuration has open_basedir restrictions enabled. Some plugins relying on CURL for functionality may not work correctly."); |
|
861 | - } |
|
859 | + if (ini_get("open_basedir") && function_exists("curl_init") && !defined("NO_CURL")) { |
|
860 | + print_warning("Your PHP configuration has open_basedir restrictions enabled. Some plugins relying on CURL for functionality may not work correctly."); |
|
861 | + } |
|
862 | 862 | |
863 | - $feed_handler_whitelist = ["Af_Comics"]; |
|
863 | + $feed_handler_whitelist = ["Af_Comics"]; |
|
864 | 864 | |
865 | - $feed_handlers = array_merge( |
|
866 | - PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_FETCHED), |
|
867 | - PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_PARSED), |
|
868 | - PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FETCH_FEED)); |
|
865 | + $feed_handlers = array_merge( |
|
866 | + PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_FETCHED), |
|
867 | + PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_PARSED), |
|
868 | + PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FETCH_FEED)); |
|
869 | 869 | |
870 | - $feed_handlers = array_filter($feed_handlers, function($plugin) use ($feed_handler_whitelist) { |
|
871 | - return in_array(get_class($plugin), $feed_handler_whitelist) === false; }); |
|
870 | + $feed_handlers = array_filter($feed_handlers, function($plugin) use ($feed_handler_whitelist) { |
|
871 | + return in_array(get_class($plugin), $feed_handler_whitelist) === false; }); |
|
872 | 872 | |
873 | - if (count($feed_handlers) > 0) { |
|
874 | - print_error( |
|
875 | - T_sprintf("The following plugins use per-feed content hooks. This may cause excessive data usage and origin server load resulting in a ban of your instance: <b>%s</b>", |
|
876 | - implode(", ", array_map(function($plugin) { return get_class($plugin); }, $feed_handlers)) |
|
877 | - )." (<a href='https://tt-rss.org/wiki/FeedHandlerPlugins' target='_blank'>".__("More info...")."</a>)" |
|
878 | - ); |
|
879 | - } |
|
873 | + if (count($feed_handlers) > 0) { |
|
874 | + print_error( |
|
875 | + T_sprintf("The following plugins use per-feed content hooks. This may cause excessive data usage and origin server load resulting in a ban of your instance: <b>%s</b>", |
|
876 | + implode(", ", array_map(function($plugin) { return get_class($plugin); }, $feed_handlers)) |
|
877 | + )." (<a href='https://tt-rss.org/wiki/FeedHandlerPlugins' target='_blank'>".__("More info...")."</a>)" |
|
878 | + ); |
|
879 | + } |
|
880 | 880 | |
881 | - print "<h2>".__("System plugins")."</h2>"; |
|
882 | - print_notice("System plugins are enabled in <strong>config.php</strong> for all users."); |
|
881 | + print "<h2>".__("System plugins")."</h2>"; |
|
882 | + print_notice("System plugins are enabled in <strong>config.php</strong> for all users."); |
|
883 | 883 | |
884 | - $system_enabled = array_map("trim", explode(",", PLUGINS)); |
|
885 | - $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS"))); |
|
884 | + $system_enabled = array_map("trim", explode(",", PLUGINS)); |
|
885 | + $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS"))); |
|
886 | 886 | |
887 | - $tmppluginhost = new PluginHost(); |
|
888 | - $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true); |
|
889 | - $tmppluginhost->load_data(); |
|
887 | + $tmppluginhost = new PluginHost(); |
|
888 | + $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true); |
|
889 | + $tmppluginhost->load_data(); |
|
890 | 890 | |
891 | - foreach ($tmppluginhost->get_plugins() as $name => $plugin) { |
|
892 | - $about = $plugin->about(); |
|
891 | + foreach ($tmppluginhost->get_plugins() as $name => $plugin) { |
|
892 | + $about = $plugin->about(); |
|
893 | 893 | |
894 | - if ($about[3]) { |
|
895 | - if (in_array($name, $system_enabled)) { |
|
896 | - $checked = "checked='1'"; |
|
897 | - } else { |
|
898 | - $checked = ""; |
|
899 | - } |
|
894 | + if ($about[3]) { |
|
895 | + if (in_array($name, $system_enabled)) { |
|
896 | + $checked = "checked='1'"; |
|
897 | + } else { |
|
898 | + $checked = ""; |
|
899 | + } |
|
900 | 900 | |
901 | - print "<fieldset class='prefs plugin'> |
|
901 | + print "<fieldset class='prefs plugin'> |
|
902 | 902 | <label>$name:</label> |
903 | 903 | <label class='checkbox description text-muted' id='PLABEL-$name'> |
904 | 904 | <input disabled='1' |
905 | 905 | dojoType='dijit.form.CheckBox' $checked type='checkbox'> |
906 | 906 | ".htmlspecialchars($about[1])."</label>"; |
907 | 907 | |
908 | - if (@$about[4]) { |
|
909 | - print "<button dojoType='dijit.form.Button' class='alt-info' |
|
908 | + if (@$about[4]) { |
|
909 | + print "<button dojoType='dijit.form.Button' class='alt-info' |
|
910 | 910 | onclick='window.open(\"".htmlspecialchars($about[4])."\")'> |
911 | 911 | <i class='material-icons'>open_in_new</i> ".__("More info...")."</button>"; |
912 | - } |
|
912 | + } |
|
913 | 913 | |
914 | - print "<div dojoType='dijit.Tooltip' connectId='PLABEL-$name' position='after'>". |
|
915 | - htmlspecialchars(T_sprintf("v%.2f, by %s", $about[0], $about[2])). |
|
916 | - "</div>"; |
|
914 | + print "<div dojoType='dijit.Tooltip' connectId='PLABEL-$name' position='after'>". |
|
915 | + htmlspecialchars(T_sprintf("v%.2f, by %s", $about[0], $about[2])). |
|
916 | + "</div>"; |
|
917 | 917 | |
918 | - print "</fieldset>"; |
|
918 | + print "</fieldset>"; |
|
919 | 919 | |
920 | - } |
|
921 | - } |
|
920 | + } |
|
921 | + } |
|
922 | 922 | |
923 | - print "<h2>".__("User plugins")."</h2>"; |
|
923 | + print "<h2>".__("User plugins")."</h2>"; |
|
924 | 924 | |
925 | - foreach ($tmppluginhost->get_plugins() as $name => $plugin) { |
|
926 | - $about = $plugin->about(); |
|
925 | + foreach ($tmppluginhost->get_plugins() as $name => $plugin) { |
|
926 | + $about = $plugin->about(); |
|
927 | 927 | |
928 | - if (!$about[3]) { |
|
928 | + if (!$about[3]) { |
|
929 | 929 | |
930 | - $checked = ""; |
|
931 | - $disabled = ""; |
|
930 | + $checked = ""; |
|
931 | + $disabled = ""; |
|
932 | 932 | |
933 | - if (in_array($name, $system_enabled)) { |
|
934 | - $checked = "checked='1'"; |
|
935 | - $disabled = "disabled='1'"; |
|
936 | - } else if (in_array($name, $user_enabled)) { |
|
937 | - $checked = "checked='1'"; |
|
938 | - } |
|
933 | + if (in_array($name, $system_enabled)) { |
|
934 | + $checked = "checked='1'"; |
|
935 | + $disabled = "disabled='1'"; |
|
936 | + } else if (in_array($name, $user_enabled)) { |
|
937 | + $checked = "checked='1'"; |
|
938 | + } |
|
939 | 939 | |
940 | - print "<fieldset class='prefs plugin'> |
|
940 | + print "<fieldset class='prefs plugin'> |
|
941 | 941 | <label>$name:</label> |
942 | 942 | <label class='checkbox description text-muted' id='PLABEL-$name'> |
943 | 943 | <input name='plugins[]' value='$name' dojoType='dijit.form.CheckBox' $checked $disabled type='checkbox'> |
944 | 944 | ".htmlspecialchars($about[1])."</label>"; |
945 | 945 | |
946 | - if (count($tmppluginhost->get_all($plugin)) > 0) { |
|
947 | - if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) { |
|
948 | - print " <button dojoType='dijit.form.Button' |
|
946 | + if (count($tmppluginhost->get_all($plugin)) > 0) { |
|
947 | + if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) { |
|
948 | + print " <button dojoType='dijit.form.Button' |
|
949 | 949 | onclick=\"Helpers.clearPluginData('$name')\"> |
950 | 950 | <i class='material-icons'>clear</i> ".__("Clear data")."</button>"; |
951 | - } |
|
952 | - } |
|
951 | + } |
|
952 | + } |
|
953 | 953 | |
954 | - if (@$about[4]) { |
|
955 | - print " <button dojoType='dijit.form.Button' class='alt-info' |
|
954 | + if (@$about[4]) { |
|
955 | + print " <button dojoType='dijit.form.Button' class='alt-info' |
|
956 | 956 | onclick='window.open(\"".htmlspecialchars($about[4])."\")'> |
957 | 957 | <i class='material-icons'>open_in_new</i> ".__("More info...")."</button>"; |
958 | - } |
|
958 | + } |
|
959 | 959 | |
960 | - print "<div dojoType='dijit.Tooltip' connectId='PLABEL-$name' position='after'>". |
|
961 | - htmlspecialchars(T_sprintf("v%.2f, by %s", $about[0], $about[2])). |
|
962 | - "</div>"; |
|
960 | + print "<div dojoType='dijit.Tooltip' connectId='PLABEL-$name' position='after'>". |
|
961 | + htmlspecialchars(T_sprintf("v%.2f, by %s", $about[0], $about[2])). |
|
962 | + "</div>"; |
|
963 | 963 | |
964 | - print "</fieldset>"; |
|
965 | - } |
|
966 | - } |
|
964 | + print "</fieldset>"; |
|
965 | + } |
|
966 | + } |
|
967 | 967 | |
968 | - print "</div>"; #content-pane |
|
969 | - print '<div dojoType="dijit.layout.ContentPane" region="bottom">'; |
|
968 | + print "</div>"; #content-pane |
|
969 | + print '<div dojoType="dijit.layout.ContentPane" region="bottom">'; |
|
970 | 970 | |
971 | - print "<button dojoType='dijit.form.Button' style='float : left' class='alt-info' onclick='window.open(\"https://tt-rss.org/wiki/Plugins\")'> |
|
971 | + print "<button dojoType='dijit.form.Button' style='float : left' class='alt-info' onclick='window.open(\"https://tt-rss.org/wiki/Plugins\")'> |
|
972 | 972 | <i class='material-icons'>help</i> ".__("More info...")."</button>"; |
973 | 973 | |
974 | - print "<button dojoType='dijit.form.Button' class='alt-primary' type='submit'>". |
|
975 | - __("Enable selected plugins")."</button>"; |
|
976 | - print "</div>"; #pane |
|
974 | + print "<button dojoType='dijit.form.Button' class='alt-primary' type='submit'>". |
|
975 | + __("Enable selected plugins")."</button>"; |
|
976 | + print "</div>"; #pane |
|
977 | 977 | |
978 | - print "</div>"; #pane |
|
979 | - print "</div>"; #border-container |
|
978 | + print "</div>"; #pane |
|
979 | + print "</div>"; #border-container |
|
980 | 980 | |
981 | - print "</form>"; |
|
981 | + print "</form>"; |
|
982 | 982 | |
983 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
|
984 | - "hook_prefs_tab", "prefPrefs"); |
|
983 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
|
984 | + "hook_prefs_tab", "prefPrefs"); |
|
985 | 985 | |
986 | - print "</div>"; #container |
|
986 | + print "</div>"; #container |
|
987 | 987 | |
988 | - } |
|
988 | + } |
|
989 | 989 | |
990 | - public function toggleAdvanced() { |
|
991 | - $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"]; |
|
992 | - } |
|
990 | + public function toggleAdvanced() { |
|
991 | + $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"]; |
|
992 | + } |
|
993 | 993 | |
994 | - public function otpsecret() { |
|
995 | - $sth = $this->pdo->prepare("SELECT salt, otp_enabled |
|
994 | + public function otpsecret() { |
|
995 | + $sth = $this->pdo->prepare("SELECT salt, otp_enabled |
|
996 | 996 | FROM ttrss_users |
997 | 997 | WHERE id = ?"); |
998 | - $sth->execute([$_SESSION['uid']]); |
|
998 | + $sth->execute([$_SESSION['uid']]); |
|
999 | 999 | |
1000 | - if ($row = $sth->fetch()) { |
|
1001 | - $otp_enabled = sql_bool_to_bool($row["otp_enabled"]); |
|
1000 | + if ($row = $sth->fetch()) { |
|
1001 | + $otp_enabled = sql_bool_to_bool($row["otp_enabled"]); |
|
1002 | 1002 | |
1003 | - if (!$otp_enabled) { |
|
1004 | - $base32 = new \OTPHP\Base32(); |
|
1005 | - $secret = $base32->encode(mb_substr(sha1($row["salt"]), 0, 12), false); |
|
1003 | + if (!$otp_enabled) { |
|
1004 | + $base32 = new \OTPHP\Base32(); |
|
1005 | + $secret = $base32->encode(mb_substr(sha1($row["salt"]), 0, 12), false); |
|
1006 | 1006 | |
1007 | - return $secret; |
|
1008 | - } |
|
1009 | - } |
|
1007 | + return $secret; |
|
1008 | + } |
|
1009 | + } |
|
1010 | 1010 | |
1011 | - return false; |
|
1012 | - } |
|
1011 | + return false; |
|
1012 | + } |
|
1013 | 1013 | |
1014 | - public function otpqrcode() { |
|
1015 | - require_once "lib/phpqrcode/phpqrcode.php"; |
|
1014 | + public function otpqrcode() { |
|
1015 | + require_once "lib/phpqrcode/phpqrcode.php"; |
|
1016 | 1016 | |
1017 | - $sth = $this->pdo->prepare("SELECT login |
|
1017 | + $sth = $this->pdo->prepare("SELECT login |
|
1018 | 1018 | FROM ttrss_users |
1019 | 1019 | WHERE id = ?"); |
1020 | - $sth->execute([$_SESSION['uid']]); |
|
1020 | + $sth->execute([$_SESSION['uid']]); |
|
1021 | 1021 | |
1022 | - if ($row = $sth->fetch()) { |
|
1023 | - $secret = $this->otpsecret(); |
|
1024 | - $login = $row['login']; |
|
1022 | + if ($row = $sth->fetch()) { |
|
1023 | + $secret = $this->otpsecret(); |
|
1024 | + $login = $row['login']; |
|
1025 | 1025 | |
1026 | - if ($secret) { |
|
1027 | - QRcode::png("otpauth://totp/".urlencode($login). |
|
1028 | - "?secret=$secret&issuer=".urlencode("Tiny Tiny RSS")); |
|
1029 | - } |
|
1030 | - } |
|
1031 | - } |
|
1026 | + if ($secret) { |
|
1027 | + QRcode::png("otpauth://totp/".urlencode($login). |
|
1028 | + "?secret=$secret&issuer=".urlencode("Tiny Tiny RSS")); |
|
1029 | + } |
|
1030 | + } |
|
1031 | + } |
|
1032 | 1032 | |
1033 | - public function otpenable() { |
|
1033 | + public function otpenable() { |
|
1034 | 1034 | |
1035 | - $password = clean($_REQUEST["password"]); |
|
1036 | - $otp = clean($_REQUEST["otp"]); |
|
1035 | + $password = clean($_REQUEST["password"]); |
|
1036 | + $otp = clean($_REQUEST["otp"]); |
|
1037 | 1037 | |
1038 | - $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
1038 | + $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
1039 | 1039 | |
1040 | - if ($authenticator->check_password($_SESSION["uid"], $password)) { |
|
1040 | + if ($authenticator->check_password($_SESSION["uid"], $password)) { |
|
1041 | 1041 | |
1042 | - $secret = $this->otpsecret(); |
|
1042 | + $secret = $this->otpsecret(); |
|
1043 | 1043 | |
1044 | - if ($secret) { |
|
1045 | - $topt = new \OTPHP\TOTP($secret); |
|
1046 | - $otp_check = $topt->now(); |
|
1044 | + if ($secret) { |
|
1045 | + $topt = new \OTPHP\TOTP($secret); |
|
1046 | + $otp_check = $topt->now(); |
|
1047 | 1047 | |
1048 | - if ($otp == $otp_check) { |
|
1049 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET otp_enabled = true WHERE id = ?"); |
|
1048 | + if ($otp == $otp_check) { |
|
1049 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET otp_enabled = true WHERE id = ?"); |
|
1050 | 1050 | |
1051 | - $sth->execute([$_SESSION['uid']]); |
|
1051 | + $sth->execute([$_SESSION['uid']]); |
|
1052 | 1052 | |
1053 | - print "OK"; |
|
1054 | - } else { |
|
1055 | - print "ERROR:".__("Incorrect one time password"); |
|
1056 | - } |
|
1057 | - } |
|
1053 | + print "OK"; |
|
1054 | + } else { |
|
1055 | + print "ERROR:".__("Incorrect one time password"); |
|
1056 | + } |
|
1057 | + } |
|
1058 | 1058 | |
1059 | - } else { |
|
1060 | - print "ERROR:".__("Incorrect password"); |
|
1061 | - } |
|
1059 | + } else { |
|
1060 | + print "ERROR:".__("Incorrect password"); |
|
1061 | + } |
|
1062 | 1062 | |
1063 | - } |
|
1063 | + } |
|
1064 | 1064 | |
1065 | - public static function isdefaultpassword() { |
|
1066 | - $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
1065 | + public static function isdefaultpassword() { |
|
1066 | + $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
1067 | 1067 | |
1068 | - if ($authenticator && |
|
1068 | + if ($authenticator && |
|
1069 | 1069 | method_exists($authenticator, "check_password") && |
1070 | 1070 | $authenticator->check_password($_SESSION["uid"], "password")) { |
1071 | 1071 | |
1072 | - return true; |
|
1073 | - } |
|
1072 | + return true; |
|
1073 | + } |
|
1074 | 1074 | |
1075 | - return false; |
|
1076 | - } |
|
1075 | + return false; |
|
1076 | + } |
|
1077 | 1077 | |
1078 | - public function otpdisable() { |
|
1079 | - $password = clean($_REQUEST["password"]); |
|
1078 | + public function otpdisable() { |
|
1079 | + $password = clean($_REQUEST["password"]); |
|
1080 | 1080 | |
1081 | - $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
1081 | + $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
|
1082 | 1082 | |
1083 | - if ($authenticator->check_password($_SESSION["uid"], $password)) { |
|
1083 | + if ($authenticator->check_password($_SESSION["uid"], $password)) { |
|
1084 | 1084 | |
1085 | - $sth = $this->pdo->prepare("SELECT email, login FROM ttrss_users WHERE id = ?"); |
|
1086 | - $sth->execute([$_SESSION['uid']]); |
|
1085 | + $sth = $this->pdo->prepare("SELECT email, login FROM ttrss_users WHERE id = ?"); |
|
1086 | + $sth->execute([$_SESSION['uid']]); |
|
1087 | 1087 | |
1088 | - if ($row = $sth->fetch()) { |
|
1089 | - $mailer = new Mailer(); |
|
1088 | + if ($row = $sth->fetch()) { |
|
1089 | + $mailer = new Mailer(); |
|
1090 | 1090 | |
1091 | - require_once "lib/MiniTemplator.class.php"; |
|
1091 | + require_once "lib/MiniTemplator.class.php"; |
|
1092 | 1092 | |
1093 | - $tpl = new MiniTemplator; |
|
1093 | + $tpl = new MiniTemplator; |
|
1094 | 1094 | |
1095 | - $tpl->readTemplateFromFile("templates/otp_disabled_template.txt"); |
|
1095 | + $tpl->readTemplateFromFile("templates/otp_disabled_template.txt"); |
|
1096 | 1096 | |
1097 | - $tpl->setVariable('LOGIN', $row["login"]); |
|
1098 | - $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
1097 | + $tpl->setVariable('LOGIN', $row["login"]); |
|
1098 | + $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
1099 | 1099 | |
1100 | - $tpl->addBlock('message'); |
|
1100 | + $tpl->addBlock('message'); |
|
1101 | 1101 | |
1102 | - $tpl->generateOutputToString($message); |
|
1102 | + $tpl->generateOutputToString($message); |
|
1103 | 1103 | |
1104 | - $mailer->mail(["to_name" => $row["login"], |
|
1105 | - "to_address" => $row["email"], |
|
1106 | - "subject" => "[tt-rss] OTP change notification", |
|
1107 | - "message" => $message]); |
|
1108 | - } |
|
1104 | + $mailer->mail(["to_name" => $row["login"], |
|
1105 | + "to_address" => $row["email"], |
|
1106 | + "subject" => "[tt-rss] OTP change notification", |
|
1107 | + "message" => $message]); |
|
1108 | + } |
|
1109 | 1109 | |
1110 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET otp_enabled = false WHERE |
|
1110 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET otp_enabled = false WHERE |
|
1111 | 1111 | id = ?"); |
1112 | - $sth->execute([$_SESSION['uid']]); |
|
1112 | + $sth->execute([$_SESSION['uid']]); |
|
1113 | 1113 | |
1114 | - print "OK"; |
|
1115 | - } else { |
|
1116 | - print "ERROR: ".__("Incorrect password"); |
|
1117 | - } |
|
1114 | + print "OK"; |
|
1115 | + } else { |
|
1116 | + print "ERROR: ".__("Incorrect password"); |
|
1117 | + } |
|
1118 | 1118 | |
1119 | - } |
|
1119 | + } |
|
1120 | 1120 | |
1121 | - public function setplugins() { |
|
1122 | - if (is_array(clean($_REQUEST["plugins"]))) { |
|
1123 | - $plugins = join(",", clean($_REQUEST["plugins"])); |
|
1124 | - } else { |
|
1125 | - $plugins = ""; |
|
1126 | - } |
|
1121 | + public function setplugins() { |
|
1122 | + if (is_array(clean($_REQUEST["plugins"]))) { |
|
1123 | + $plugins = join(",", clean($_REQUEST["plugins"])); |
|
1124 | + } else { |
|
1125 | + $plugins = ""; |
|
1126 | + } |
|
1127 | 1127 | |
1128 | - set_pref("_ENABLED_PLUGINS", $plugins); |
|
1129 | - } |
|
1128 | + set_pref("_ENABLED_PLUGINS", $plugins); |
|
1129 | + } |
|
1130 | 1130 | |
1131 | - public function clearplugindata() { |
|
1132 | - $name = clean($_REQUEST["name"]); |
|
1131 | + public function clearplugindata() { |
|
1132 | + $name = clean($_REQUEST["name"]); |
|
1133 | 1133 | |
1134 | - PluginHost::getInstance()->clear_data(PluginHost::getInstance()->get_plugin($name)); |
|
1135 | - } |
|
1134 | + PluginHost::getInstance()->clear_data(PluginHost::getInstance()->get_plugin($name)); |
|
1135 | + } |
|
1136 | 1136 | |
1137 | - public function customizeCSS() { |
|
1138 | - $value = get_pref("USER_STYLESHEET"); |
|
1139 | - $value = str_replace("<br/>", "\n", $value); |
|
1137 | + public function customizeCSS() { |
|
1138 | + $value = get_pref("USER_STYLESHEET"); |
|
1139 | + $value = str_replace("<br/>", "\n", $value); |
|
1140 | 1140 | |
1141 | - print_notice(__("You can override colors, fonts and layout of your currently selected theme with custom CSS declarations here.")); |
|
1141 | + print_notice(__("You can override colors, fonts and layout of your currently selected theme with custom CSS declarations here.")); |
|
1142 | 1142 | |
1143 | - print_hidden("op", "rpc"); |
|
1144 | - print_hidden("method", "setpref"); |
|
1145 | - print_hidden("key", "USER_STYLESHEET"); |
|
1143 | + print_hidden("op", "rpc"); |
|
1144 | + print_hidden("method", "setpref"); |
|
1145 | + print_hidden("key", "USER_STYLESHEET"); |
|
1146 | 1146 | |
1147 | - print "<div id='css_edit_apply_msg' style='display : none'>"; |
|
1148 | - print_warning(__("User CSS has been applied, you might need to reload the page to see all changes.")); |
|
1149 | - print "</div>"; |
|
1147 | + print "<div id='css_edit_apply_msg' style='display : none'>"; |
|
1148 | + print_warning(__("User CSS has been applied, you might need to reload the page to see all changes.")); |
|
1149 | + print "</div>"; |
|
1150 | 1150 | |
1151 | - print "<textarea class='panel user-css-editor' dojoType='dijit.form.SimpleTextarea' |
|
1151 | + print "<textarea class='panel user-css-editor' dojoType='dijit.form.SimpleTextarea' |
|
1152 | 1152 | style='font-size : 12px;' name='value'>$value</textarea>"; |
1153 | 1153 | |
1154 | - print "<footer>"; |
|
1155 | - print "<button dojoType='dijit.form.Button' class='alt-success' |
|
1154 | + print "<footer>"; |
|
1155 | + print "<button dojoType='dijit.form.Button' class='alt-success' |
|
1156 | 1156 | onclick=\"dijit.byId('cssEditDlg').apply()\">".__('Apply')."</button> "; |
1157 | - print "<button dojoType='dijit.form.Button' class='alt-primary' |
|
1157 | + print "<button dojoType='dijit.form.Button' class='alt-primary' |
|
1158 | 1158 | onclick=\"dijit.byId('cssEditDlg').execute()\">".__('Save and reload')."</button> "; |
1159 | - print "<button dojoType='dijit.form.Button' |
|
1159 | + print "<button dojoType='dijit.form.Button' |
|
1160 | 1160 | onclick=\"dijit.byId('cssEditDlg').hide()\">".__('Cancel')."</button>"; |
1161 | - print "</footer>"; |
|
1161 | + print "</footer>"; |
|
1162 | 1162 | |
1163 | - } |
|
1163 | + } |
|
1164 | 1164 | |
1165 | - public function editPrefProfiles() { |
|
1166 | - print "<div dojoType='fox.Toolbar'>"; |
|
1165 | + public function editPrefProfiles() { |
|
1166 | + print "<div dojoType='fox.Toolbar'>"; |
|
1167 | 1167 | |
1168 | - print "<div dojoType='fox.form.DropDownButton'>". |
|
1169 | - "<span>".__('Select')."</span>"; |
|
1170 | - print "<div dojoType='dijit.Menu' style='display: none'>"; |
|
1171 | - print "<div onclick=\"Tables.select('pref-profiles-list', true)\" |
|
1168 | + print "<div dojoType='fox.form.DropDownButton'>". |
|
1169 | + "<span>".__('Select')."</span>"; |
|
1170 | + print "<div dojoType='dijit.Menu' style='display: none'>"; |
|
1171 | + print "<div onclick=\"Tables.select('pref-profiles-list', true)\" |
|
1172 | 1172 | dojoType='dijit.MenuItem'>".__('All')."</div>"; |
1173 | - print "<div onclick=\"Tables.select('pref-profiles-list', false)\" |
|
1173 | + print "<div onclick=\"Tables.select('pref-profiles-list', false)\" |
|
1174 | 1174 | dojoType='dijit.MenuItem'>".__('None')."</div>"; |
1175 | - print "</div></div>"; |
|
1175 | + print "</div></div>"; |
|
1176 | 1176 | |
1177 | - print "<div style='float : right'>"; |
|
1177 | + print "<div style='float : right'>"; |
|
1178 | 1178 | |
1179 | - print "<input name='newprofile' dojoType='dijit.form.ValidationTextBox' |
|
1179 | + print "<input name='newprofile' dojoType='dijit.form.ValidationTextBox' |
|
1180 | 1180 | required='1'> |
1181 | 1181 | <button dojoType='dijit.form.Button' |
1182 | 1182 | onclick=\"dijit.byId('profileEditDlg').addProfile()\">". |
1183 | - __('Create profile')."</button></div>"; |
|
1183 | + __('Create profile')."</button></div>"; |
|
1184 | 1184 | |
1185 | - print "</div>"; |
|
1185 | + print "</div>"; |
|
1186 | 1186 | |
1187 | - $sth = $this->pdo->prepare("SELECT title,id FROM ttrss_settings_profiles |
|
1187 | + $sth = $this->pdo->prepare("SELECT title,id FROM ttrss_settings_profiles |
|
1188 | 1188 | WHERE owner_uid = ? ORDER BY title"); |
1189 | - $sth->execute([$_SESSION['uid']]); |
|
1189 | + $sth->execute([$_SESSION['uid']]); |
|
1190 | 1190 | |
1191 | - print "<div class='panel panel-scrollable'>"; |
|
1191 | + print "<div class='panel panel-scrollable'>"; |
|
1192 | 1192 | |
1193 | - print "<form id='profile_edit_form' onsubmit='return false'>"; |
|
1193 | + print "<form id='profile_edit_form' onsubmit='return false'>"; |
|
1194 | 1194 | |
1195 | - print "<table width='100%' id='pref-profiles-list'>"; |
|
1195 | + print "<table width='100%' id='pref-profiles-list'>"; |
|
1196 | 1196 | |
1197 | - print "<tr>"; # data-row-id='0' <-- no point, shouldn't be removed |
|
1197 | + print "<tr>"; # data-row-id='0' <-- no point, shouldn't be removed |
|
1198 | 1198 | |
1199 | - print "<td><input onclick='Tables.onRowChecked(this);' dojoType='dijit.form.CheckBox' type='checkbox'></td>"; |
|
1199 | + print "<td><input onclick='Tables.onRowChecked(this);' dojoType='dijit.form.CheckBox' type='checkbox'></td>"; |
|
1200 | 1200 | |
1201 | - if (!$_SESSION["profile"]) { |
|
1202 | - $is_active = __("(active)"); |
|
1203 | - } else { |
|
1204 | - $is_active = ""; |
|
1205 | - } |
|
1201 | + if (!$_SESSION["profile"]) { |
|
1202 | + $is_active = __("(active)"); |
|
1203 | + } else { |
|
1204 | + $is_active = ""; |
|
1205 | + } |
|
1206 | 1206 | |
1207 | - print "<td width='100%'><span>".__("Default profile")." $is_active</span></td>"; |
|
1207 | + print "<td width='100%'><span>".__("Default profile")." $is_active</span></td>"; |
|
1208 | 1208 | |
1209 | - print "</tr>"; |
|
1209 | + print "</tr>"; |
|
1210 | 1210 | |
1211 | - while ($line = $sth->fetch()) { |
|
1211 | + while ($line = $sth->fetch()) { |
|
1212 | 1212 | |
1213 | - $profile_id = $line["id"]; |
|
1213 | + $profile_id = $line["id"]; |
|
1214 | 1214 | |
1215 | - print "<tr data-row-id='$profile_id'>"; |
|
1215 | + print "<tr data-row-id='$profile_id'>"; |
|
1216 | 1216 | |
1217 | - $edit_title = htmlspecialchars($line["title"]); |
|
1217 | + $edit_title = htmlspecialchars($line["title"]); |
|
1218 | 1218 | |
1219 | - print "<td><input onclick='Tables.onRowChecked(this);' dojoType='dijit.form.CheckBox' type='checkbox'></td>"; |
|
1219 | + print "<td><input onclick='Tables.onRowChecked(this);' dojoType='dijit.form.CheckBox' type='checkbox'></td>"; |
|
1220 | 1220 | |
1221 | - if ($_SESSION["profile"] == $line["id"]) { |
|
1222 | - $is_active = __("(active)"); |
|
1223 | - } else { |
|
1224 | - $is_active = ""; |
|
1225 | - } |
|
1221 | + if ($_SESSION["profile"] == $line["id"]) { |
|
1222 | + $is_active = __("(active)"); |
|
1223 | + } else { |
|
1224 | + $is_active = ""; |
|
1225 | + } |
|
1226 | 1226 | |
1227 | - print "<td><span dojoType='dijit.InlineEditBox' |
|
1227 | + print "<td><span dojoType='dijit.InlineEditBox' |
|
1228 | 1228 | width='300px' autoSave='false' |
1229 | 1229 | profile-id='$profile_id'>".$edit_title. |
1230 | - "<script type='dojo/method' event='onChange' args='item'> |
|
1230 | + "<script type='dojo/method' event='onChange' args='item'> |
|
1231 | 1231 | var elem = this; |
1232 | 1232 | dojo.xhrPost({ |
1233 | 1233 | url: 'backend.php', |
@@ -1241,118 +1241,118 @@ discard block |
||
1241 | 1241 | </script> |
1242 | 1242 | </span> $is_active</td>"; |
1243 | 1243 | |
1244 | - print "</tr>"; |
|
1245 | - } |
|
1244 | + print "</tr>"; |
|
1245 | + } |
|
1246 | 1246 | |
1247 | - print "</table>"; |
|
1248 | - print "</form>"; |
|
1249 | - print "</div>"; |
|
1247 | + print "</table>"; |
|
1248 | + print "</form>"; |
|
1249 | + print "</div>"; |
|
1250 | 1250 | |
1251 | - print "<footer> |
|
1251 | + print "<footer> |
|
1252 | 1252 | <button style='float : left' class='alt-danger' dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').removeSelected()\">". |
1253 | - __('Remove selected profiles')."</button> |
|
1253 | + __('Remove selected profiles')."</button> |
|
1254 | 1254 | <button dojoType='dijit.form.Button' class='alt-primary' type='submit' onclick=\"dijit.byId('profileEditDlg').activateProfile()\">". |
1255 | - __('Activate profile')."</button> |
|
1255 | + __('Activate profile')."</button> |
|
1256 | 1256 | <button dojoType='dijit.form.Button' onclick=\"dijit.byId('profileEditDlg').hide()\">". |
1257 | - __('Cancel')."</button>"; |
|
1258 | - print "</footer>"; |
|
1259 | - |
|
1260 | - } |
|
1261 | - |
|
1262 | - private function getShortDesc($pref_name) { |
|
1263 | - if (isset($this->pref_help[$pref_name])) { |
|
1264 | - return $this->pref_help[$pref_name][0]; |
|
1265 | - } |
|
1266 | - return ""; |
|
1267 | - } |
|
1268 | - |
|
1269 | - private function getHelpText($pref_name) { |
|
1270 | - if (isset($this->pref_help[$pref_name])) { |
|
1271 | - return $this->pref_help[$pref_name][1]; |
|
1272 | - } |
|
1273 | - return ""; |
|
1274 | - } |
|
1275 | - |
|
1276 | - private function appPasswordList() { |
|
1277 | - print "<div dojoType='fox.Toolbar'>"; |
|
1278 | - print "<div dojoType='fox.form.DropDownButton'>". |
|
1279 | - "<span>".__('Select')."</span>"; |
|
1280 | - print "<div dojoType='dijit.Menu' style='display: none'>"; |
|
1281 | - print "<div onclick=\"Tables.select('app-password-list', true)\" |
|
1257 | + __('Cancel')."</button>"; |
|
1258 | + print "</footer>"; |
|
1259 | + |
|
1260 | + } |
|
1261 | + |
|
1262 | + private function getShortDesc($pref_name) { |
|
1263 | + if (isset($this->pref_help[$pref_name])) { |
|
1264 | + return $this->pref_help[$pref_name][0]; |
|
1265 | + } |
|
1266 | + return ""; |
|
1267 | + } |
|
1268 | + |
|
1269 | + private function getHelpText($pref_name) { |
|
1270 | + if (isset($this->pref_help[$pref_name])) { |
|
1271 | + return $this->pref_help[$pref_name][1]; |
|
1272 | + } |
|
1273 | + return ""; |
|
1274 | + } |
|
1275 | + |
|
1276 | + private function appPasswordList() { |
|
1277 | + print "<div dojoType='fox.Toolbar'>"; |
|
1278 | + print "<div dojoType='fox.form.DropDownButton'>". |
|
1279 | + "<span>".__('Select')."</span>"; |
|
1280 | + print "<div dojoType='dijit.Menu' style='display: none'>"; |
|
1281 | + print "<div onclick=\"Tables.select('app-password-list', true)\" |
|
1282 | 1282 | dojoType=\"dijit.MenuItem\">" . __('All')."</div>"; |
1283 | - print "<div onclick=\"Tables.select('app-password-list', false)\" |
|
1283 | + print "<div onclick=\"Tables.select('app-password-list', false)\" |
|
1284 | 1284 | dojoType=\"dijit.MenuItem\">" . __('None')."</div>"; |
1285 | - print "</div></div>"; |
|
1286 | - print "</div>"; #toolbar |
|
1287 | - |
|
1288 | - print "<div class='panel panel-scrollable'>"; |
|
1289 | - print "<table width='100%' id='app-password-list'>"; |
|
1290 | - print "<tr>"; |
|
1291 | - print "<th width='2%'></th>"; |
|
1292 | - print "<th align='left'>".__("Description")."</th>"; |
|
1293 | - print "<th align='right'>".__("Created")."</th>"; |
|
1294 | - print "<th align='right'>".__("Last used")."</th>"; |
|
1295 | - print "</tr>"; |
|
1296 | - |
|
1297 | - $sth = $this->pdo->prepare("SELECT id, title, created, last_used |
|
1285 | + print "</div></div>"; |
|
1286 | + print "</div>"; #toolbar |
|
1287 | + |
|
1288 | + print "<div class='panel panel-scrollable'>"; |
|
1289 | + print "<table width='100%' id='app-password-list'>"; |
|
1290 | + print "<tr>"; |
|
1291 | + print "<th width='2%'></th>"; |
|
1292 | + print "<th align='left'>".__("Description")."</th>"; |
|
1293 | + print "<th align='right'>".__("Created")."</th>"; |
|
1294 | + print "<th align='right'>".__("Last used")."</th>"; |
|
1295 | + print "</tr>"; |
|
1296 | + |
|
1297 | + $sth = $this->pdo->prepare("SELECT id, title, created, last_used |
|
1298 | 1298 | FROM ttrss_app_passwords WHERE owner_uid = ?"); |
1299 | - $sth->execute([$_SESSION['uid']]); |
|
1299 | + $sth->execute([$_SESSION['uid']]); |
|
1300 | 1300 | |
1301 | - while ($row = $sth->fetch()) { |
|
1301 | + while ($row = $sth->fetch()) { |
|
1302 | 1302 | |
1303 | - $row_id = $row["id"]; |
|
1303 | + $row_id = $row["id"]; |
|
1304 | 1304 | |
1305 | - print "<tr data-row-id='$row_id'>"; |
|
1305 | + print "<tr data-row-id='$row_id'>"; |
|
1306 | 1306 | |
1307 | - print "<td align='center'> |
|
1307 | + print "<td align='center'> |
|
1308 | 1308 | <input onclick='Tables.onRowChecked(this)' dojoType='dijit.form.CheckBox' type='checkbox'></td>"; |
1309 | - print "<td>".htmlspecialchars($row["title"])."</td>"; |
|
1309 | + print "<td>".htmlspecialchars($row["title"])."</td>"; |
|
1310 | 1310 | |
1311 | - print "<td align='right' class='text-muted'>"; |
|
1312 | - print make_local_datetime($row['created'], false); |
|
1313 | - print "</td>"; |
|
1311 | + print "<td align='right' class='text-muted'>"; |
|
1312 | + print make_local_datetime($row['created'], false); |
|
1313 | + print "</td>"; |
|
1314 | 1314 | |
1315 | - print "<td align='right' class='text-muted'>"; |
|
1316 | - print make_local_datetime($row['last_used'], false); |
|
1317 | - print "</td>"; |
|
1315 | + print "<td align='right' class='text-muted'>"; |
|
1316 | + print make_local_datetime($row['last_used'], false); |
|
1317 | + print "</td>"; |
|
1318 | 1318 | |
1319 | - print "</tr>"; |
|
1320 | - } |
|
1319 | + print "</tr>"; |
|
1320 | + } |
|
1321 | 1321 | |
1322 | - print "</table>"; |
|
1323 | - print "</div>"; |
|
1324 | - } |
|
1322 | + print "</table>"; |
|
1323 | + print "</div>"; |
|
1324 | + } |
|
1325 | 1325 | |
1326 | - private function encryptAppPassword($password) { |
|
1327 | - $salt = substr(bin2hex(get_random_bytes(24)), 0, 24); |
|
1326 | + private function encryptAppPassword($password) { |
|
1327 | + $salt = substr(bin2hex(get_random_bytes(24)), 0, 24); |
|
1328 | 1328 | |
1329 | - return "SSHA-512:".hash('sha512', $salt.$password).":$salt"; |
|
1330 | - } |
|
1329 | + return "SSHA-512:".hash('sha512', $salt.$password).":$salt"; |
|
1330 | + } |
|
1331 | 1331 | |
1332 | - public function deleteAppPassword() { |
|
1333 | - $ids = explode(",", clean($_REQUEST['ids'])); |
|
1334 | - $ids_qmarks = arr_qmarks($ids); |
|
1332 | + public function deleteAppPassword() { |
|
1333 | + $ids = explode(",", clean($_REQUEST['ids'])); |
|
1334 | + $ids_qmarks = arr_qmarks($ids); |
|
1335 | 1335 | |
1336 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_app_passwords WHERE id IN ($ids_qmarks) AND owner_uid = ?"); |
|
1337 | - $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
1336 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_app_passwords WHERE id IN ($ids_qmarks) AND owner_uid = ?"); |
|
1337 | + $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
1338 | 1338 | |
1339 | - $this->appPasswordList(); |
|
1340 | - } |
|
1339 | + $this->appPasswordList(); |
|
1340 | + } |
|
1341 | 1341 | |
1342 | - public function generateAppPassword() { |
|
1343 | - $title = clean($_REQUEST['title']); |
|
1344 | - $new_password = make_password(16); |
|
1345 | - $new_password_hash = $this->encryptAppPassword($new_password); |
|
1342 | + public function generateAppPassword() { |
|
1343 | + $title = clean($_REQUEST['title']); |
|
1344 | + $new_password = make_password(16); |
|
1345 | + $new_password_hash = $this->encryptAppPassword($new_password); |
|
1346 | 1346 | |
1347 | - print_warning(T_sprintf("Generated password <strong>%s</strong> for %s. Please remember it for future reference.", $new_password, $title)); |
|
1347 | + print_warning(T_sprintf("Generated password <strong>%s</strong> for %s. Please remember it for future reference.", $new_password, $title)); |
|
1348 | 1348 | |
1349 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_app_passwords |
|
1349 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_app_passwords |
|
1350 | 1350 | (title, pwd_hash, service, created, owner_uid) |
1351 | 1351 | VALUES |
1352 | 1352 | (?, ?, ?, NOW(), ?)"); |
1353 | 1353 | |
1354 | - $sth->execute([$title, $new_password_hash, Auth_Base::AUTH_SERVICE_API, $_SESSION['uid']]); |
|
1354 | + $sth->execute([$title, $new_password_hash, Auth_Base::AUTH_SERVICE_API, $_SESSION['uid']]); |
|
1355 | 1355 | |
1356 | - $this->appPasswordList(); |
|
1357 | - } |
|
1356 | + $this->appPasswordList(); |
|
1357 | + } |
|
1358 | 1358 | } |
@@ -172,26 +172,26 @@ |
||
172 | 172 | $value = $_POST[$pref_name]; |
173 | 173 | |
174 | 174 | switch ($pref_name) { |
175 | - case 'DIGEST_PREFERRED_TIME': |
|
176 | - if (get_pref('DIGEST_PREFERRED_TIME') != $value) { |
|
175 | + case 'DIGEST_PREFERRED_TIME': |
|
176 | + if (get_pref('DIGEST_PREFERRED_TIME') != $value) { |
|
177 | 177 | |
178 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET |
|
178 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET |
|
179 | 179 | last_digest_sent = NULL WHERE id = ?"); |
180 | - $sth->execute([$_SESSION['uid']]); |
|
180 | + $sth->execute([$_SESSION['uid']]); |
|
181 | 181 | |
182 | - } |
|
183 | - break; |
|
184 | - case 'USER_LANGUAGE': |
|
185 | - if (!$need_reload) { |
|
186 | - $need_reload = $_SESSION["language"] != $value; |
|
187 | - } |
|
188 | - break; |
|
182 | + } |
|
183 | + break; |
|
184 | + case 'USER_LANGUAGE': |
|
185 | + if (!$need_reload) { |
|
186 | + $need_reload = $_SESSION["language"] != $value; |
|
187 | + } |
|
188 | + break; |
|
189 | 189 | |
190 | - case 'USER_CSS_THEME': |
|
191 | - if (!$need_reload) { |
|
192 | - $need_reload = get_pref($pref_name) != $value; |
|
193 | - } |
|
194 | - break; |
|
190 | + case 'USER_CSS_THEME': |
|
191 | + if (!$need_reload) { |
|
192 | + $need_reload = get_pref($pref_name) != $value; |
|
193 | + } |
|
194 | + break; |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | set_pref($pref_name, $value); |
@@ -1,286 +1,286 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class Pref_Labels extends Handler_Protected { |
3 | 3 | |
4 | - public function csrf_ignore($method) { |
|
5 | - $csrf_ignored = array("index", "getlabeltree", "edit"); |
|
4 | + public function csrf_ignore($method) { |
|
5 | + $csrf_ignored = array("index", "getlabeltree", "edit"); |
|
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 edit() { |
|
11 | - $label_id = clean($_REQUEST['id']); |
|
10 | + public function edit() { |
|
11 | + $label_id = clean($_REQUEST['id']); |
|
12 | 12 | |
13 | - $sth = $this->pdo->prepare("SELECT * FROM ttrss_labels2 WHERE |
|
13 | + $sth = $this->pdo->prepare("SELECT * FROM ttrss_labels2 WHERE |
|
14 | 14 | id = ? AND owner_uid = ?"); |
15 | - $sth->execute([$label_id, $_SESSION['uid']]); |
|
15 | + $sth->execute([$label_id, $_SESSION['uid']]); |
|
16 | 16 | |
17 | - if ($line = $sth->fetch()) { |
|
17 | + if ($line = $sth->fetch()) { |
|
18 | 18 | |
19 | - print_hidden("id", "$label_id"); |
|
20 | - print_hidden("op", "pref-labels"); |
|
21 | - print_hidden("method", "save"); |
|
19 | + print_hidden("id", "$label_id"); |
|
20 | + print_hidden("op", "pref-labels"); |
|
21 | + print_hidden("method", "save"); |
|
22 | 22 | |
23 | - print "<form onsubmit='return false;'>"; |
|
23 | + print "<form onsubmit='return false;'>"; |
|
24 | 24 | |
25 | - print "<header>".__("Caption")."</header>"; |
|
25 | + print "<header>".__("Caption")."</header>"; |
|
26 | 26 | |
27 | - print "<section>"; |
|
27 | + print "<section>"; |
|
28 | 28 | |
29 | - $fg_color = $line['fg_color']; |
|
30 | - $bg_color = $line['bg_color'] ? $line['bg_color'] : '#fff7d5'; |
|
29 | + $fg_color = $line['fg_color']; |
|
30 | + $bg_color = $line['bg_color'] ? $line['bg_color'] : '#fff7d5'; |
|
31 | 31 | |
32 | - print "<input style='font-size : 16px; color : $fg_color; background : $bg_color; transition : background 0.1s linear' |
|
32 | + print "<input style='font-size : 16px; color : $fg_color; background : $bg_color; transition : background 0.1s linear' |
|
33 | 33 | id='labelEdit_caption' name='caption' dojoType='dijit.form.ValidationTextBox' |
34 | 34 | required='true' value=\"".htmlspecialchars($line['caption'])."\">"; |
35 | 35 | |
36 | - print "</section>"; |
|
36 | + print "</section>"; |
|
37 | 37 | |
38 | - print "<header>".__("Colors")."</header>"; |
|
39 | - print "<section>"; |
|
38 | + print "<header>".__("Colors")."</header>"; |
|
39 | + print "<section>"; |
|
40 | 40 | |
41 | - print "<table>"; |
|
42 | - print "<tr><th style='text-align : left'>".__("Foreground:")."</th><th style='text-align : left'>".__("Background:")."</th></tr>"; |
|
43 | - print "<tr><td style='padding-right : 10px'>"; |
|
41 | + print "<table>"; |
|
42 | + print "<tr><th style='text-align : left'>".__("Foreground:")."</th><th style='text-align : left'>".__("Background:")."</th></tr>"; |
|
43 | + print "<tr><td style='padding-right : 10px'>"; |
|
44 | 44 | |
45 | - print "<input dojoType='dijit.form.TextBox' |
|
45 | + print "<input dojoType='dijit.form.TextBox' |
|
46 | 46 | style='display : none' id='labelEdit_fgColor' |
47 | 47 | name='fg_color' value='$fg_color'>"; |
48 | - print "<input dojoType='dijit.form.TextBox' |
|
48 | + print "<input dojoType='dijit.form.TextBox' |
|
49 | 49 | style='display : none' id='labelEdit_bgColor' |
50 | 50 | name='bg_color' value='$bg_color'>"; |
51 | 51 | |
52 | - print "<div dojoType='dijit.ColorPalette'> |
|
52 | + print "<div dojoType='dijit.ColorPalette'> |
|
53 | 53 | <script type='dojo/method' event='onChange' args='fg_color'> |
54 | 54 | dijit.byId('labelEdit_fgColor').attr('value', fg_color); |
55 | 55 | dijit.byId('labelEdit_caption').domNode.setStyle({color: fg_color}); |
56 | 56 | </script> |
57 | 57 | </div>"; |
58 | 58 | |
59 | - print "</td><td>"; |
|
59 | + print "</td><td>"; |
|
60 | 60 | |
61 | - print "<div dojoType='dijit.ColorPalette'> |
|
61 | + print "<div dojoType='dijit.ColorPalette'> |
|
62 | 62 | <script type='dojo/method' event='onChange' args='bg_color'> |
63 | 63 | dijit.byId('labelEdit_bgColor').attr('value', bg_color); |
64 | 64 | dijit.byId('labelEdit_caption').domNode.setStyle({backgroundColor: bg_color}); |
65 | 65 | </script> |
66 | 66 | </div>"; |
67 | 67 | |
68 | - print "</td></tr></table>"; |
|
69 | - print "</section>"; |
|
68 | + print "</td></tr></table>"; |
|
69 | + print "</section>"; |
|
70 | 70 | |
71 | - print "<footer>"; |
|
72 | - print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary' onclick=\"dijit.byId('labelEditDlg').execute()\">". |
|
73 | - __('Save')."</button>"; |
|
74 | - print "<button dojoType='dijit.form.Button' onclick=\"dijit.byId('labelEditDlg').hide()\">". |
|
75 | - __('Cancel')."</button>"; |
|
76 | - print "</footer>"; |
|
71 | + print "<footer>"; |
|
72 | + print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary' onclick=\"dijit.byId('labelEditDlg').execute()\">". |
|
73 | + __('Save')."</button>"; |
|
74 | + print "<button dojoType='dijit.form.Button' onclick=\"dijit.byId('labelEditDlg').hide()\">". |
|
75 | + __('Cancel')."</button>"; |
|
76 | + print "</footer>"; |
|
77 | 77 | |
78 | - print "</form>"; |
|
79 | - } |
|
80 | - } |
|
78 | + print "</form>"; |
|
79 | + } |
|
80 | + } |
|
81 | 81 | |
82 | - public function getlabeltree() { |
|
83 | - $root = array(); |
|
84 | - $root['id'] = 'root'; |
|
85 | - $root['name'] = __('Labels'); |
|
86 | - $root['items'] = array(); |
|
82 | + public function getlabeltree() { |
|
83 | + $root = array(); |
|
84 | + $root['id'] = 'root'; |
|
85 | + $root['name'] = __('Labels'); |
|
86 | + $root['items'] = array(); |
|
87 | 87 | |
88 | - $sth = $this->pdo->prepare("SELECT * |
|
88 | + $sth = $this->pdo->prepare("SELECT * |
|
89 | 89 | FROM ttrss_labels2 |
90 | 90 | WHERE owner_uid = ? |
91 | 91 | ORDER BY caption"); |
92 | - $sth->execute([$_SESSION['uid']]); |
|
93 | - |
|
94 | - while ($line = $sth->fetch()) { |
|
95 | - $label = array(); |
|
96 | - $label['id'] = 'LABEL:'.$line['id']; |
|
97 | - $label['bare_id'] = $line['id']; |
|
98 | - $label['name'] = $line['caption']; |
|
99 | - $label['fg_color'] = $line['fg_color']; |
|
100 | - $label['bg_color'] = $line['bg_color']; |
|
101 | - $label['type'] = 'label'; |
|
102 | - $label['checkbox'] = false; |
|
103 | - |
|
104 | - array_push($root['items'], $label); |
|
105 | - } |
|
106 | - |
|
107 | - $fl = array(); |
|
108 | - $fl['identifier'] = 'id'; |
|
109 | - $fl['label'] = 'name'; |
|
110 | - $fl['items'] = array($root); |
|
111 | - |
|
112 | - print json_encode($fl); |
|
113 | - return; |
|
114 | - } |
|
115 | - |
|
116 | - public function colorset() { |
|
117 | - $kind = clean($_REQUEST["kind"]); |
|
118 | - $ids = explode(',', clean($_REQUEST["ids"])); |
|
119 | - $color = clean($_REQUEST["color"]); |
|
120 | - $fg = clean($_REQUEST["fg"]); |
|
121 | - $bg = clean($_REQUEST["bg"]); |
|
122 | - |
|
123 | - foreach ($ids as $id) { |
|
124 | - |
|
125 | - if ($kind == "fg" || $kind == "bg") { |
|
126 | - $sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET |
|
92 | + $sth->execute([$_SESSION['uid']]); |
|
93 | + |
|
94 | + while ($line = $sth->fetch()) { |
|
95 | + $label = array(); |
|
96 | + $label['id'] = 'LABEL:'.$line['id']; |
|
97 | + $label['bare_id'] = $line['id']; |
|
98 | + $label['name'] = $line['caption']; |
|
99 | + $label['fg_color'] = $line['fg_color']; |
|
100 | + $label['bg_color'] = $line['bg_color']; |
|
101 | + $label['type'] = 'label'; |
|
102 | + $label['checkbox'] = false; |
|
103 | + |
|
104 | + array_push($root['items'], $label); |
|
105 | + } |
|
106 | + |
|
107 | + $fl = array(); |
|
108 | + $fl['identifier'] = 'id'; |
|
109 | + $fl['label'] = 'name'; |
|
110 | + $fl['items'] = array($root); |
|
111 | + |
|
112 | + print json_encode($fl); |
|
113 | + return; |
|
114 | + } |
|
115 | + |
|
116 | + public function colorset() { |
|
117 | + $kind = clean($_REQUEST["kind"]); |
|
118 | + $ids = explode(',', clean($_REQUEST["ids"])); |
|
119 | + $color = clean($_REQUEST["color"]); |
|
120 | + $fg = clean($_REQUEST["fg"]); |
|
121 | + $bg = clean($_REQUEST["bg"]); |
|
122 | + |
|
123 | + foreach ($ids as $id) { |
|
124 | + |
|
125 | + if ($kind == "fg" || $kind == "bg") { |
|
126 | + $sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET |
|
127 | 127 | ${kind}_color = ? WHERE id = ? |
128 | 128 | AND owner_uid = ?"); |
129 | 129 | |
130 | - $sth->execute([$color, $id, $_SESSION['uid']]); |
|
130 | + $sth->execute([$color, $id, $_SESSION['uid']]); |
|
131 | 131 | |
132 | - } else { |
|
132 | + } else { |
|
133 | 133 | |
134 | - $sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET |
|
134 | + $sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET |
|
135 | 135 | fg_color = ?, bg_color = ? WHERE id = ? |
136 | 136 | AND owner_uid = ?"); |
137 | 137 | |
138 | - $sth->execute([$fg, $bg, $id, $_SESSION['uid']]); |
|
139 | - } |
|
138 | + $sth->execute([$fg, $bg, $id, $_SESSION['uid']]); |
|
139 | + } |
|
140 | 140 | |
141 | - /* Remove cached data */ |
|
141 | + /* Remove cached data */ |
|
142 | 142 | |
143 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET label_cache = '' |
|
143 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET label_cache = '' |
|
144 | 144 | WHERE owner_uid = ?"); |
145 | - $sth->execute([$_SESSION['uid']]); |
|
146 | - } |
|
147 | - } |
|
145 | + $sth->execute([$_SESSION['uid']]); |
|
146 | + } |
|
147 | + } |
|
148 | 148 | |
149 | - public function colorreset() { |
|
150 | - $ids = explode(',', clean($_REQUEST["ids"])); |
|
149 | + public function colorreset() { |
|
150 | + $ids = explode(',', clean($_REQUEST["ids"])); |
|
151 | 151 | |
152 | - foreach ($ids as $id) { |
|
153 | - $sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET |
|
152 | + foreach ($ids as $id) { |
|
153 | + $sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET |
|
154 | 154 | fg_color = '', bg_color = '' WHERE id = ? |
155 | 155 | AND owner_uid = ?"); |
156 | - $sth->execute([$id, $_SESSION['uid']]); |
|
156 | + $sth->execute([$id, $_SESSION['uid']]); |
|
157 | 157 | |
158 | - /* Remove cached data */ |
|
158 | + /* Remove cached data */ |
|
159 | 159 | |
160 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET label_cache = '' |
|
160 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET label_cache = '' |
|
161 | 161 | WHERE owner_uid = ?"); |
162 | - $sth->execute([$_SESSION['uid']]); |
|
163 | - } |
|
164 | - } |
|
162 | + $sth->execute([$_SESSION['uid']]); |
|
163 | + } |
|
164 | + } |
|
165 | 165 | |
166 | - public function save() { |
|
166 | + public function save() { |
|
167 | 167 | |
168 | - $id = clean($_REQUEST["id"]); |
|
169 | - $caption = trim(clean($_REQUEST["caption"])); |
|
168 | + $id = clean($_REQUEST["id"]); |
|
169 | + $caption = trim(clean($_REQUEST["caption"])); |
|
170 | 170 | |
171 | - $this->pdo->beginTransaction(); |
|
171 | + $this->pdo->beginTransaction(); |
|
172 | 172 | |
173 | - $sth = $this->pdo->prepare("SELECT caption FROM ttrss_labels2 |
|
173 | + $sth = $this->pdo->prepare("SELECT caption FROM ttrss_labels2 |
|
174 | 174 | WHERE id = ? AND owner_uid = ?"); |
175 | - $sth->execute([$id, $_SESSION['uid']]); |
|
175 | + $sth->execute([$id, $_SESSION['uid']]); |
|
176 | 176 | |
177 | - if ($row = $sth->fetch()) { |
|
178 | - $old_caption = $row["caption"]; |
|
177 | + if ($row = $sth->fetch()) { |
|
178 | + $old_caption = $row["caption"]; |
|
179 | 179 | |
180 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_labels2 |
|
180 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_labels2 |
|
181 | 181 | WHERE caption = ? AND owner_uid = ?"); |
182 | - $sth->execute([$caption, $_SESSION['uid']]); |
|
182 | + $sth->execute([$caption, $_SESSION['uid']]); |
|
183 | 183 | |
184 | - if (!$sth->fetch()) { |
|
185 | - if ($caption) { |
|
186 | - $sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET |
|
184 | + if (!$sth->fetch()) { |
|
185 | + if ($caption) { |
|
186 | + $sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET |
|
187 | 187 | caption = ? WHERE id = ? AND |
188 | 188 | owner_uid = ?"); |
189 | - $sth->execute([$caption, $id, $_SESSION['uid']]); |
|
189 | + $sth->execute([$caption, $id, $_SESSION['uid']]); |
|
190 | 190 | |
191 | - /* Update filters that reference label being renamed */ |
|
191 | + /* Update filters that reference label being renamed */ |
|
192 | 192 | |
193 | - $sth = $this->pdo->prepare("UPDATE ttrss_filters2_actions SET |
|
193 | + $sth = $this->pdo->prepare("UPDATE ttrss_filters2_actions SET |
|
194 | 194 | action_param = ? WHERE action_param = ? |
195 | 195 | AND action_id = 7 |
196 | 196 | AND filter_id IN (SELECT id FROM ttrss_filters2 WHERE owner_uid = ?)"); |
197 | 197 | |
198 | - $sth->execute([$caption, $old_caption, $_SESSION['uid']]); |
|
198 | + $sth->execute([$caption, $old_caption, $_SESSION['uid']]); |
|
199 | 199 | |
200 | - print clean($_REQUEST["value"]); |
|
201 | - } else { |
|
202 | - print $old_caption; |
|
203 | - } |
|
204 | - } else { |
|
205 | - print $old_caption; |
|
206 | - } |
|
207 | - } |
|
200 | + print clean($_REQUEST["value"]); |
|
201 | + } else { |
|
202 | + print $old_caption; |
|
203 | + } |
|
204 | + } else { |
|
205 | + print $old_caption; |
|
206 | + } |
|
207 | + } |
|
208 | 208 | |
209 | - $this->pdo->commit(); |
|
209 | + $this->pdo->commit(); |
|
210 | 210 | |
211 | - } |
|
211 | + } |
|
212 | 212 | |
213 | - public function remove() { |
|
213 | + public function remove() { |
|
214 | 214 | |
215 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
215 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
216 | 216 | |
217 | - foreach ($ids as $id) { |
|
218 | - Labels::remove($id, $_SESSION["uid"]); |
|
219 | - } |
|
217 | + foreach ($ids as $id) { |
|
218 | + Labels::remove($id, $_SESSION["uid"]); |
|
219 | + } |
|
220 | 220 | |
221 | - } |
|
221 | + } |
|
222 | 222 | |
223 | - public function add() { |
|
224 | - $caption = clean($_REQUEST["caption"]); |
|
225 | - $output = clean($_REQUEST["output"]); |
|
223 | + public function add() { |
|
224 | + $caption = clean($_REQUEST["caption"]); |
|
225 | + $output = clean($_REQUEST["output"]); |
|
226 | 226 | |
227 | - if ($caption) { |
|
227 | + if ($caption) { |
|
228 | 228 | |
229 | - if (Labels::create($caption)) { |
|
230 | - if (!$output) { |
|
231 | - print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption)); |
|
232 | - } |
|
233 | - } |
|
229 | + if (Labels::create($caption)) { |
|
230 | + if (!$output) { |
|
231 | + print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption)); |
|
232 | + } |
|
233 | + } |
|
234 | 234 | |
235 | - if ($output == "select") { |
|
236 | - header("Content-Type: text/xml"); |
|
235 | + if ($output == "select") { |
|
236 | + header("Content-Type: text/xml"); |
|
237 | 237 | |
238 | - print "<rpc-reply><payload>"; |
|
238 | + print "<rpc-reply><payload>"; |
|
239 | 239 | |
240 | - print_label_select("select_label", |
|
241 | - $caption, ""); |
|
240 | + print_label_select("select_label", |
|
241 | + $caption, ""); |
|
242 | 242 | |
243 | - print "</payload></rpc-reply>"; |
|
244 | - } |
|
245 | - } |
|
243 | + print "</payload></rpc-reply>"; |
|
244 | + } |
|
245 | + } |
|
246 | 246 | |
247 | - return; |
|
248 | - } |
|
247 | + return; |
|
248 | + } |
|
249 | 249 | |
250 | - public function index() { |
|
250 | + public function index() { |
|
251 | 251 | |
252 | - print "<div dojoType='dijit.layout.BorderContainer' gutters='false'>"; |
|
253 | - print "<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='top'>"; |
|
254 | - print "<div dojoType='fox.Toolbar'>"; |
|
252 | + print "<div dojoType='dijit.layout.BorderContainer' gutters='false'>"; |
|
253 | + print "<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='top'>"; |
|
254 | + print "<div dojoType='fox.Toolbar'>"; |
|
255 | 255 | |
256 | - print "<div dojoType='fox.form.DropDownButton'>". |
|
257 | - "<span>".__('Select')."</span>"; |
|
258 | - print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
259 | - print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(true)\" |
|
256 | + print "<div dojoType='fox.form.DropDownButton'>". |
|
257 | + "<span>".__('Select')."</span>"; |
|
258 | + print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
259 | + print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(true)\" |
|
260 | 260 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; |
261 | - print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(false)\" |
|
261 | + print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(false)\" |
|
262 | 262 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; |
263 | - print "</div></div>"; |
|
263 | + print "</div></div>"; |
|
264 | 264 | |
265 | - print"<button dojoType=\"dijit.form.Button\" onclick=\"CommonDialogs.addLabel()\">". |
|
266 | - __('Create label')."</button dojoType=\"dijit.form.Button\"> "; |
|
265 | + print"<button dojoType=\"dijit.form.Button\" onclick=\"CommonDialogs.addLabel()\">". |
|
266 | + __('Create label')."</button dojoType=\"dijit.form.Button\"> "; |
|
267 | 267 | |
268 | - print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelTree').removeSelected()\">". |
|
269 | - __('Remove')."</button dojoType=\"dijit.form.Button\"> "; |
|
268 | + print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelTree').removeSelected()\">". |
|
269 | + __('Remove')."</button dojoType=\"dijit.form.Button\"> "; |
|
270 | 270 | |
271 | - print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelTree').resetColors()\">". |
|
272 | - __('Clear colors')."</button dojoType=\"dijit.form.Button\">"; |
|
271 | + print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelTree').resetColors()\">". |
|
272 | + __('Clear colors')."</button dojoType=\"dijit.form.Button\">"; |
|
273 | 273 | |
274 | 274 | |
275 | - print "</div>"; #toolbar |
|
276 | - print "</div>"; #pane |
|
277 | - print "<div style='padding : 0px' dojoType=\"dijit.layout.ContentPane\" region=\"center\">"; |
|
275 | + print "</div>"; #toolbar |
|
276 | + print "</div>"; #pane |
|
277 | + print "<div style='padding : 0px' dojoType=\"dijit.layout.ContentPane\" region=\"center\">"; |
|
278 | 278 | |
279 | - print "<div id=\"labellistLoading\"> |
|
279 | + print "<div id=\"labellistLoading\"> |
|
280 | 280 | <img src='images/indicator_tiny.gif'>". |
281 | - __("Loading, please wait...")."</div>"; |
|
281 | + __("Loading, please wait...")."</div>"; |
|
282 | 282 | |
283 | - print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"labelStore\" |
|
283 | + print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"labelStore\" |
|
284 | 284 | url=\"backend.php?op=pref-labels&method=getlabeltree\"> |
285 | 285 | </div> |
286 | 286 | <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"labelModel\" store=\"labelStore\" |
@@ -302,12 +302,12 @@ discard block |
||
302 | 302 | </script> |
303 | 303 | </div>"; |
304 | 304 | |
305 | - print "</div>"; #pane |
|
305 | + print "</div>"; #pane |
|
306 | 306 | |
307 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
|
308 | - "hook_prefs_tab", "prefLabels"); |
|
307 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
|
308 | + "hook_prefs_tab", "prefLabels"); |
|
309 | 309 | |
310 | - print "</div>"; #container |
|
310 | + print "</div>"; #container |
|
311 | 311 | |
312 | - } |
|
312 | + } |
|
313 | 313 | } |
@@ -2,118 +2,118 @@ |
||
2 | 2 | class Db |
3 | 3 | { |
4 | 4 | |
5 | - /* @var Db $instance */ |
|
6 | - private static $instance; |
|
5 | + /* @var Db $instance */ |
|
6 | + private static $instance; |
|
7 | 7 | |
8 | - /* @var IDb $adapter */ |
|
9 | - private $adapter; |
|
8 | + /* @var IDb $adapter */ |
|
9 | + private $adapter; |
|
10 | 10 | |
11 | - private $link; |
|
11 | + private $link; |
|
12 | 12 | |
13 | - /* @var PDO $pdo */ |
|
14 | - private $pdo; |
|
13 | + /* @var PDO $pdo */ |
|
14 | + private $pdo; |
|
15 | 15 | |
16 | - private function __clone() { |
|
17 | - // |
|
18 | - } |
|
16 | + private function __clone() { |
|
17 | + // |
|
18 | + } |
|
19 | 19 | |
20 | - private function legacy_connect() { |
|
20 | + private function legacy_connect() { |
|
21 | 21 | |
22 | - user_error("Legacy connect requested to ".DB_TYPE, E_USER_NOTICE); |
|
22 | + user_error("Legacy connect requested to ".DB_TYPE, E_USER_NOTICE); |
|
23 | 23 | |
24 | - $er = error_reporting(E_ALL); |
|
24 | + $er = error_reporting(E_ALL); |
|
25 | 25 | |
26 | - switch (DB_TYPE) { |
|
27 | - case "mysql": |
|
28 | - $this->adapter = new Db_Mysqli(); |
|
29 | - break; |
|
30 | - case "pgsql": |
|
31 | - $this->adapter = new Db_Pgsql(); |
|
32 | - break; |
|
33 | - default: |
|
34 | - die("Unknown DB_TYPE: ".DB_TYPE); |
|
35 | - } |
|
26 | + switch (DB_TYPE) { |
|
27 | + case "mysql": |
|
28 | + $this->adapter = new Db_Mysqli(); |
|
29 | + break; |
|
30 | + case "pgsql": |
|
31 | + $this->adapter = new Db_Pgsql(); |
|
32 | + break; |
|
33 | + default: |
|
34 | + die("Unknown DB_TYPE: ".DB_TYPE); |
|
35 | + } |
|
36 | 36 | |
37 | - if (!$this->adapter) { |
|
38 | - print("Error initializing database adapter for ".DB_TYPE); |
|
39 | - exit(100); |
|
40 | - } |
|
37 | + if (!$this->adapter) { |
|
38 | + print("Error initializing database adapter for ".DB_TYPE); |
|
39 | + exit(100); |
|
40 | + } |
|
41 | 41 | |
42 | - $this->link = $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, defined('DB_PORT') ? DB_PORT : ""); |
|
42 | + $this->link = $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, defined('DB_PORT') ? DB_PORT : ""); |
|
43 | 43 | |
44 | - if (!$this->link) { |
|
45 | - print("Error connecting through adapter: ".$this->adapter->last_error()); |
|
46 | - exit(101); |
|
47 | - } |
|
44 | + if (!$this->link) { |
|
45 | + print("Error connecting through adapter: ".$this->adapter->last_error()); |
|
46 | + exit(101); |
|
47 | + } |
|
48 | 48 | |
49 | - error_reporting($er); |
|
50 | - } |
|
49 | + error_reporting($er); |
|
50 | + } |
|
51 | 51 | |
52 | - // this really shouldn't be used unless a separate PDO connection is needed |
|
53 | - // normal usage is Db::pdo()->prepare(...) etc |
|
54 | - public function pdo_connect() { |
|
52 | + // this really shouldn't be used unless a separate PDO connection is needed |
|
53 | + // normal usage is Db::pdo()->prepare(...) etc |
|
54 | + public function pdo_connect() { |
|
55 | 55 | |
56 | - $db_port = defined('DB_PORT') && DB_PORT ? ';port='.DB_PORT : ''; |
|
57 | - $db_host = defined('DB_HOST') && DB_HOST ? ';host='.DB_HOST : ''; |
|
56 | + $db_port = defined('DB_PORT') && DB_PORT ? ';port='.DB_PORT : ''; |
|
57 | + $db_host = defined('DB_HOST') && DB_HOST ? ';host='.DB_HOST : ''; |
|
58 | 58 | |
59 | - try { |
|
60 | - $pdo = new PDO(DB_TYPE.':dbname='.DB_NAME.$db_host.$db_port, |
|
61 | - DB_USER, |
|
62 | - DB_PASS); |
|
63 | - } catch (Exception $e) { |
|
64 | - print "<pre>Exception while creating PDO object:".$e->getMessage()."</pre>"; |
|
65 | - exit(101); |
|
66 | - } |
|
59 | + try { |
|
60 | + $pdo = new PDO(DB_TYPE.':dbname='.DB_NAME.$db_host.$db_port, |
|
61 | + DB_USER, |
|
62 | + DB_PASS); |
|
63 | + } catch (Exception $e) { |
|
64 | + print "<pre>Exception while creating PDO object:".$e->getMessage()."</pre>"; |
|
65 | + exit(101); |
|
66 | + } |
|
67 | 67 | |
68 | - $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
68 | + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
69 | 69 | |
70 | - if (DB_TYPE == "pgsql") { |
|
70 | + if (DB_TYPE == "pgsql") { |
|
71 | 71 | |
72 | - $pdo->query("set client_encoding = 'UTF-8'"); |
|
73 | - $pdo->query("set datestyle = 'ISO, european'"); |
|
74 | - $pdo->query("set TIME ZONE 0"); |
|
75 | - $pdo->query("set cpu_tuple_cost = 0.5"); |
|
72 | + $pdo->query("set client_encoding = 'UTF-8'"); |
|
73 | + $pdo->query("set datestyle = 'ISO, european'"); |
|
74 | + $pdo->query("set TIME ZONE 0"); |
|
75 | + $pdo->query("set cpu_tuple_cost = 0.5"); |
|
76 | 76 | |
77 | - } else if (DB_TYPE == "mysql") { |
|
78 | - $pdo->query("SET time_zone = '+0:0'"); |
|
77 | + } else if (DB_TYPE == "mysql") { |
|
78 | + $pdo->query("SET time_zone = '+0:0'"); |
|
79 | 79 | |
80 | - if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { |
|
81 | - $pdo->query("SET NAMES ".MYSQL_CHARSET); |
|
82 | - } |
|
83 | - } |
|
80 | + if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { |
|
81 | + $pdo->query("SET NAMES ".MYSQL_CHARSET); |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - return $pdo; |
|
86 | - } |
|
85 | + return $pdo; |
|
86 | + } |
|
87 | 87 | |
88 | - public static function instance() { |
|
89 | - if (self::$instance == null) { |
|
90 | - self::$instance = new self(); |
|
91 | - } |
|
88 | + public static function instance() { |
|
89 | + if (self::$instance == null) { |
|
90 | + self::$instance = new self(); |
|
91 | + } |
|
92 | 92 | |
93 | - return self::$instance; |
|
94 | - } |
|
93 | + return self::$instance; |
|
94 | + } |
|
95 | 95 | |
96 | - public static function get() { |
|
97 | - if (self::$instance == null) { |
|
98 | - self::$instance = new self(); |
|
99 | - } |
|
96 | + public static function get() { |
|
97 | + if (self::$instance == null) { |
|
98 | + self::$instance = new self(); |
|
99 | + } |
|
100 | 100 | |
101 | - if (!self::$instance->adapter) { |
|
102 | - self::$instance->legacy_connect(); |
|
103 | - } |
|
101 | + if (!self::$instance->adapter) { |
|
102 | + self::$instance->legacy_connect(); |
|
103 | + } |
|
104 | 104 | |
105 | - return self::$instance->adapter; |
|
106 | - } |
|
105 | + return self::$instance->adapter; |
|
106 | + } |
|
107 | 107 | |
108 | - public static function pdo() { |
|
109 | - if (self::$instance == null) { |
|
110 | - self::$instance = new self(); |
|
111 | - } |
|
108 | + public static function pdo() { |
|
109 | + if (self::$instance == null) { |
|
110 | + self::$instance = new self(); |
|
111 | + } |
|
112 | 112 | |
113 | - if (!self::$instance->pdo) { |
|
114 | - self::$instance->pdo = self::$instance->pdo_connect(); |
|
115 | - } |
|
113 | + if (!self::$instance->pdo) { |
|
114 | + self::$instance->pdo = self::$instance->pdo_connect(); |
|
115 | + } |
|
116 | 116 | |
117 | - return self::$instance->pdo; |
|
118 | - } |
|
117 | + return self::$instance->pdo; |
|
118 | + } |
|
119 | 119 | } |
@@ -24,14 +24,14 @@ |
||
24 | 24 | $er = error_reporting(E_ALL); |
25 | 25 | |
26 | 26 | switch (DB_TYPE) { |
27 | - case "mysql": |
|
28 | - $this->adapter = new Db_Mysqli(); |
|
29 | - break; |
|
30 | - case "pgsql": |
|
31 | - $this->adapter = new Db_Pgsql(); |
|
32 | - break; |
|
33 | - default: |
|
34 | - die("Unknown DB_TYPE: ".DB_TYPE); |
|
27 | + case "mysql": |
|
28 | + $this->adapter = new Db_Mysqli(); |
|
29 | + break; |
|
30 | + case "pgsql": |
|
31 | + $this->adapter = new Db_Pgsql(); |
|
32 | + break; |
|
33 | + default: |
|
34 | + die("Unknown DB_TYPE: ".DB_TYPE); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | if (!$this->adapter) { |
@@ -1,118 +1,118 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class Labels |
3 | 3 | { |
4 | - public static function label_to_feed_id($label) { |
|
5 | - return LABEL_BASE_INDEX - 1 - abs($label); |
|
6 | - } |
|
4 | + public static function label_to_feed_id($label) { |
|
5 | + return LABEL_BASE_INDEX - 1 - abs($label); |
|
6 | + } |
|
7 | 7 | |
8 | - public static function feed_to_label_id($feed) { |
|
9 | - return LABEL_BASE_INDEX - 1 + abs($feed); |
|
10 | - } |
|
8 | + public static function feed_to_label_id($feed) { |
|
9 | + return LABEL_BASE_INDEX - 1 + abs($feed); |
|
10 | + } |
|
11 | 11 | |
12 | - public static function find_id($label, $owner_uid) { |
|
13 | - $pdo = Db::pdo(); |
|
12 | + public static function find_id($label, $owner_uid) { |
|
13 | + $pdo = Db::pdo(); |
|
14 | 14 | |
15 | - $sth = $pdo->prepare("SELECT id FROM ttrss_labels2 WHERE caption = ? |
|
15 | + $sth = $pdo->prepare("SELECT id FROM ttrss_labels2 WHERE caption = ? |
|
16 | 16 | AND owner_uid = ? LIMIT 1"); |
17 | - $sth->execute([$label, $owner_uid]); |
|
17 | + $sth->execute([$label, $owner_uid]); |
|
18 | 18 | |
19 | - if ($row = $sth->fetch()) { |
|
20 | - return $row['id']; |
|
21 | - } else { |
|
22 | - return 0; |
|
23 | - } |
|
24 | - } |
|
19 | + if ($row = $sth->fetch()) { |
|
20 | + return $row['id']; |
|
21 | + } else { |
|
22 | + return 0; |
|
23 | + } |
|
24 | + } |
|
25 | 25 | |
26 | - public static function find_caption($label, $owner_uid) { |
|
27 | - $pdo = Db::pdo(); |
|
26 | + public static function find_caption($label, $owner_uid) { |
|
27 | + $pdo = Db::pdo(); |
|
28 | 28 | |
29 | - $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2 WHERE id = ? |
|
29 | + $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2 WHERE id = ? |
|
30 | 30 | AND owner_uid = ? LIMIT 1"); |
31 | - $sth->execute([$label, $owner_uid]); |
|
31 | + $sth->execute([$label, $owner_uid]); |
|
32 | 32 | |
33 | - if ($row = $sth->fetch()) { |
|
34 | - return $row['caption']; |
|
35 | - } else { |
|
36 | - return ""; |
|
37 | - } |
|
38 | - } |
|
33 | + if ($row = $sth->fetch()) { |
|
34 | + return $row['caption']; |
|
35 | + } else { |
|
36 | + return ""; |
|
37 | + } |
|
38 | + } |
|
39 | 39 | |
40 | - public static function get_all_labels($owner_uid) { |
|
41 | - $rv = array(); |
|
40 | + public static function get_all_labels($owner_uid) { |
|
41 | + $rv = array(); |
|
42 | 42 | |
43 | - $pdo = Db::pdo(); |
|
43 | + $pdo = Db::pdo(); |
|
44 | 44 | |
45 | - $sth = $pdo->prepare("SELECT id, fg_color, bg_color, caption FROM ttrss_labels2 |
|
45 | + $sth = $pdo->prepare("SELECT id, fg_color, bg_color, caption FROM ttrss_labels2 |
|
46 | 46 | WHERE owner_uid = ? ORDER BY caption"); |
47 | - $sth->execute([$owner_uid]); |
|
47 | + $sth->execute([$owner_uid]); |
|
48 | 48 | |
49 | - while ($line = $sth->fetch()) { |
|
50 | - array_push($rv, $line); |
|
51 | - } |
|
49 | + while ($line = $sth->fetch()) { |
|
50 | + array_push($rv, $line); |
|
51 | + } |
|
52 | 52 | |
53 | - return $rv; |
|
54 | - } |
|
53 | + return $rv; |
|
54 | + } |
|
55 | 55 | |
56 | - public static function update_cache($owner_uid, $id, $labels = false, $force = false) { |
|
57 | - $pdo = Db::pdo(); |
|
56 | + public static function update_cache($owner_uid, $id, $labels = false, $force = false) { |
|
57 | + $pdo = Db::pdo(); |
|
58 | 58 | |
59 | - if ($force) { |
|
60 | - Labels::clear_cache($id); |
|
61 | - } |
|
59 | + if ($force) { |
|
60 | + Labels::clear_cache($id); |
|
61 | + } |
|
62 | 62 | |
63 | - if (!$labels) { |
|
64 | - $labels = Article::get_article_labels($id); |
|
65 | - } |
|
63 | + if (!$labels) { |
|
64 | + $labels = Article::get_article_labels($id); |
|
65 | + } |
|
66 | 66 | |
67 | - $labels = json_encode($labels); |
|
67 | + $labels = json_encode($labels); |
|
68 | 68 | |
69 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
69 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
70 | 70 | label_cache = ? WHERE ref_id = ? AND owner_uid = ?"); |
71 | - $sth->execute([$labels, $id, $owner_uid]); |
|
71 | + $sth->execute([$labels, $id, $owner_uid]); |
|
72 | 72 | |
73 | - } |
|
73 | + } |
|
74 | 74 | |
75 | - public static function clear_cache($id) { |
|
75 | + public static function clear_cache($id) { |
|
76 | 76 | |
77 | - $pdo = Db::pdo(); |
|
77 | + $pdo = Db::pdo(); |
|
78 | 78 | |
79 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
79 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
80 | 80 | label_cache = '' WHERE ref_id = ?"); |
81 | - $sth->execute([$id]); |
|
81 | + $sth->execute([$id]); |
|
82 | 82 | |
83 | - } |
|
83 | + } |
|
84 | 84 | |
85 | - public static function remove_article($id, $label, $owner_uid) { |
|
85 | + public static function remove_article($id, $label, $owner_uid) { |
|
86 | 86 | |
87 | - $label_id = Labels::find_id($label, $owner_uid); |
|
87 | + $label_id = Labels::find_id($label, $owner_uid); |
|
88 | 88 | |
89 | - if (!$label_id) { |
|
90 | - return; |
|
91 | - } |
|
89 | + if (!$label_id) { |
|
90 | + return; |
|
91 | + } |
|
92 | 92 | |
93 | - $pdo = Db::pdo(); |
|
93 | + $pdo = Db::pdo(); |
|
94 | 94 | |
95 | - $sth = $pdo->prepare("DELETE FROM ttrss_user_labels2 |
|
95 | + $sth = $pdo->prepare("DELETE FROM ttrss_user_labels2 |
|
96 | 96 | WHERE |
97 | 97 | label_id = ? AND |
98 | 98 | article_id = ?"); |
99 | 99 | |
100 | - $sth->execute([$label_id, $id]); |
|
100 | + $sth->execute([$label_id, $id]); |
|
101 | 101 | |
102 | - Labels::clear_cache($id); |
|
103 | - } |
|
102 | + Labels::clear_cache($id); |
|
103 | + } |
|
104 | 104 | |
105 | - public static function add_article($id, $label, $owner_uid) { |
|
105 | + public static function add_article($id, $label, $owner_uid) { |
|
106 | 106 | |
107 | - $label_id = Labels::find_id($label, $owner_uid); |
|
107 | + $label_id = Labels::find_id($label, $owner_uid); |
|
108 | 108 | |
109 | - if (!$label_id) { |
|
110 | - return; |
|
111 | - } |
|
109 | + if (!$label_id) { |
|
110 | + return; |
|
111 | + } |
|
112 | 112 | |
113 | - $pdo = Db::pdo(); |
|
113 | + $pdo = Db::pdo(); |
|
114 | 114 | |
115 | - $sth = $pdo->prepare("SELECT |
|
115 | + $sth = $pdo->prepare("SELECT |
|
116 | 116 | article_id FROM ttrss_labels2, ttrss_user_labels2 |
117 | 117 | WHERE |
118 | 118 | label_id = id AND |
@@ -120,96 +120,96 @@ discard block |
||
120 | 120 | article_id = ? AND owner_uid = ? |
121 | 121 | LIMIT 1"); |
122 | 122 | |
123 | - $sth->execute([$label_id, $id, $owner_uid]); |
|
123 | + $sth->execute([$label_id, $id, $owner_uid]); |
|
124 | 124 | |
125 | - if (!$sth->fetch()) { |
|
126 | - $sth = $pdo->prepare("INSERT INTO ttrss_user_labels2 |
|
125 | + if (!$sth->fetch()) { |
|
126 | + $sth = $pdo->prepare("INSERT INTO ttrss_user_labels2 |
|
127 | 127 | (label_id, article_id) VALUES (?, ?)"); |
128 | 128 | |
129 | - $sth->execute([$label_id, $id]); |
|
130 | - } |
|
129 | + $sth->execute([$label_id, $id]); |
|
130 | + } |
|
131 | 131 | |
132 | - Labels::clear_cache($id); |
|
132 | + Labels::clear_cache($id); |
|
133 | 133 | |
134 | - } |
|
134 | + } |
|
135 | 135 | |
136 | - public static function remove($id, $owner_uid) { |
|
137 | - if (!$owner_uid) { |
|
138 | - $owner_uid = $_SESSION["uid"]; |
|
139 | - } |
|
136 | + public static function remove($id, $owner_uid) { |
|
137 | + if (!$owner_uid) { |
|
138 | + $owner_uid = $_SESSION["uid"]; |
|
139 | + } |
|
140 | 140 | |
141 | - $pdo = Db::pdo(); |
|
142 | - $tr_in_progress = false; |
|
141 | + $pdo = Db::pdo(); |
|
142 | + $tr_in_progress = false; |
|
143 | 143 | |
144 | - try { |
|
145 | - $pdo->beginTransaction(); |
|
146 | - } catch (Exception $e) { |
|
147 | - $tr_in_progress = true; |
|
148 | - } |
|
144 | + try { |
|
145 | + $pdo->beginTransaction(); |
|
146 | + } catch (Exception $e) { |
|
147 | + $tr_in_progress = true; |
|
148 | + } |
|
149 | 149 | |
150 | - $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2 |
|
150 | + $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2 |
|
151 | 151 | WHERE id = ?"); |
152 | - $sth->execute([$id]); |
|
152 | + $sth->execute([$id]); |
|
153 | 153 | |
154 | - $row = $sth->fetch(); |
|
155 | - $caption = $row['caption']; |
|
154 | + $row = $sth->fetch(); |
|
155 | + $caption = $row['caption']; |
|
156 | 156 | |
157 | - $sth = $pdo->prepare("DELETE FROM ttrss_labels2 WHERE id = ? |
|
157 | + $sth = $pdo->prepare("DELETE FROM ttrss_labels2 WHERE id = ? |
|
158 | 158 | AND owner_uid = ?"); |
159 | - $sth->execute([$id, $owner_uid]); |
|
159 | + $sth->execute([$id, $owner_uid]); |
|
160 | 160 | |
161 | - if ($sth->rowCount() != 0 && $caption) { |
|
161 | + if ($sth->rowCount() != 0 && $caption) { |
|
162 | 162 | |
163 | - /* Remove access key for the label */ |
|
163 | + /* Remove access key for the label */ |
|
164 | 164 | |
165 | - $ext_id = LABEL_BASE_INDEX - 1 - $id; |
|
165 | + $ext_id = LABEL_BASE_INDEX - 1 - $id; |
|
166 | 166 | |
167 | - $sth = $pdo->prepare("DELETE FROM ttrss_access_keys WHERE |
|
167 | + $sth = $pdo->prepare("DELETE FROM ttrss_access_keys WHERE |
|
168 | 168 | feed_id = ? AND owner_uid = ?"); |
169 | - $sth->execute([$ext_id, $owner_uid]); |
|
169 | + $sth->execute([$ext_id, $owner_uid]); |
|
170 | 170 | |
171 | - /* Remove cached data */ |
|
171 | + /* Remove cached data */ |
|
172 | 172 | |
173 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries SET label_cache = '' |
|
173 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries SET label_cache = '' |
|
174 | 174 | WHERE owner_uid = ?"); |
175 | - $sth->execute([$owner_uid]); |
|
175 | + $sth->execute([$owner_uid]); |
|
176 | 176 | |
177 | - } |
|
177 | + } |
|
178 | 178 | |
179 | - if (!$tr_in_progress) $pdo->commit(); |
|
180 | - } |
|
179 | + if (!$tr_in_progress) $pdo->commit(); |
|
180 | + } |
|
181 | 181 | |
182 | - public static function create($caption, $fg_color = '', $bg_color = '', $owner_uid = false) { |
|
182 | + public static function create($caption, $fg_color = '', $bg_color = '', $owner_uid = false) { |
|
183 | 183 | |
184 | - if (!$owner_uid) $owner_uid = $_SESSION['uid']; |
|
184 | + if (!$owner_uid) $owner_uid = $_SESSION['uid']; |
|
185 | 185 | |
186 | - $pdo = Db::pdo(); |
|
186 | + $pdo = Db::pdo(); |
|
187 | 187 | |
188 | - $tr_in_progress = false; |
|
188 | + $tr_in_progress = false; |
|
189 | 189 | |
190 | - try { |
|
191 | - $pdo->beginTransaction(); |
|
192 | - } catch (Exception $e) { |
|
193 | - $tr_in_progress = true; |
|
194 | - } |
|
190 | + try { |
|
191 | + $pdo->beginTransaction(); |
|
192 | + } catch (Exception $e) { |
|
193 | + $tr_in_progress = true; |
|
194 | + } |
|
195 | 195 | |
196 | - $sth = $pdo->prepare("SELECT id FROM ttrss_labels2 |
|
196 | + $sth = $pdo->prepare("SELECT id FROM ttrss_labels2 |
|
197 | 197 | WHERE caption = ? AND owner_uid = ?"); |
198 | - $sth->execute([$caption, $owner_uid]); |
|
198 | + $sth->execute([$caption, $owner_uid]); |
|
199 | 199 | |
200 | - if (!$sth->fetch()) { |
|
201 | - $sth = $pdo->prepare("INSERT INTO ttrss_labels2 |
|
200 | + if (!$sth->fetch()) { |
|
201 | + $sth = $pdo->prepare("INSERT INTO ttrss_labels2 |
|
202 | 202 | (caption,owner_uid,fg_color,bg_color) VALUES (?, ?, ?, ?)"); |
203 | 203 | |
204 | - $sth->execute([$caption, $owner_uid, $fg_color, $bg_color]); |
|
204 | + $sth->execute([$caption, $owner_uid, $fg_color, $bg_color]); |
|
205 | 205 | |
206 | - $result = $sth->rowCount(); |
|
207 | - } |
|
206 | + $result = $sth->rowCount(); |
|
207 | + } |
|
208 | 208 | |
209 | - if (!$tr_in_progress) { |
|
210 | - $pdo->commit(); |
|
211 | - } |
|
209 | + if (!$tr_in_progress) { |
|
210 | + $pdo->commit(); |
|
211 | + } |
|
212 | 212 | |
213 | - return $result; |
|
214 | - } |
|
213 | + return $result; |
|
214 | + } |
|
215 | 215 | } |
@@ -176,12 +176,16 @@ |
||
176 | 176 | |
177 | 177 | } |
178 | 178 | |
179 | - if (!$tr_in_progress) $pdo->commit(); |
|
179 | + if (!$tr_in_progress) { |
|
180 | + $pdo->commit(); |
|
181 | + } |
|
180 | 182 | } |
181 | 183 | |
182 | 184 | public static function create($caption, $fg_color = '', $bg_color = '', $owner_uid = false) { |
183 | 185 | |
184 | - if (!$owner_uid) $owner_uid = $_SESSION['uid']; |
|
186 | + if (!$owner_uid) { |
|
187 | + $owner_uid = $_SESSION['uid']; |
|
188 | + } |
|
185 | 189 | |
186 | 190 | $pdo = Db::pdo(); |
187 | 191 |
@@ -2,84 +2,84 @@ |
||
2 | 2 | |
3 | 3 | class DbUpdater { |
4 | 4 | |
5 | - private $pdo; |
|
6 | - private $db_type; |
|
7 | - private $need_version; |
|
8 | - |
|
9 | - public function __construct($db_type, $need_version) { |
|
10 | - $this->pdo = Db::pdo(); |
|
11 | - $this->db_type = $db_type; |
|
12 | - $this->need_version = (int) $need_version; |
|
13 | - } |
|
14 | - |
|
15 | - public function getSchemaVersion() { |
|
16 | - $row = $this->pdo->query("SELECT schema_version FROM ttrss_version")->fetch(); |
|
17 | - return (int) $row['schema_version']; |
|
18 | - } |
|
19 | - |
|
20 | - public function isUpdateRequired() { |
|
21 | - return $this->getSchemaVersion() < $this->need_version; |
|
22 | - } |
|
23 | - |
|
24 | - public function getSchemaLines($version) { |
|
25 | - $filename = "schema/versions/".$this->db_type."/$version.sql"; |
|
26 | - |
|
27 | - if (file_exists($filename)) { |
|
28 | - return explode(";", preg_replace("/[\r\n]/", "", file_get_contents($filename))); |
|
29 | - } else { |
|
30 | - user_error("DB Updater: schema file for version $version is not found."); |
|
31 | - return false; |
|
32 | - } |
|
33 | - } |
|
34 | - |
|
35 | - public function performUpdateTo($version, $html_output = true) { |
|
36 | - if ($this->getSchemaVersion() == $version - 1) { |
|
37 | - |
|
38 | - $lines = $this->getSchemaLines($version); |
|
39 | - |
|
40 | - if (is_array($lines)) { |
|
41 | - |
|
42 | - $this->pdo->beginTransaction(); |
|
43 | - |
|
44 | - foreach ($lines as $line) { |
|
45 | - if (strpos($line, "--") !== 0 && $line) { |
|
46 | - |
|
47 | - if ($html_output) { |
|
48 | - print "<pre>$line</pre>"; |
|
49 | - } else { |
|
50 | - Debug::log("> $line"); |
|
51 | - } |
|
52 | - |
|
53 | - try { |
|
54 | - $this->pdo->query($line); // PDO returns errors as exceptions now |
|
55 | - } catch (PDOException $e) { |
|
56 | - if ($html_output) { |
|
57 | - print "<div class='text-error'>Error: ".$e->getMessage()."</div>"; |
|
58 | - } else { |
|
59 | - Debug::log("Error: ".$e->getMessage()); |
|
60 | - } |
|
61 | - |
|
62 | - $this->pdo->rollBack(); |
|
63 | - return false; |
|
64 | - } |
|
65 | - } |
|
66 | - } |
|
67 | - |
|
68 | - $db_version = $this->getSchemaVersion(); |
|
69 | - |
|
70 | - if ($db_version == $version) { |
|
71 | - $this->pdo->commit(); |
|
72 | - return true; |
|
73 | - } else { |
|
74 | - $this->pdo->rollBack(); |
|
75 | - return false; |
|
76 | - } |
|
77 | - } else { |
|
78 | - return false; |
|
79 | - } |
|
80 | - } else { |
|
81 | - return false; |
|
82 | - } |
|
83 | - } |
|
5 | + private $pdo; |
|
6 | + private $db_type; |
|
7 | + private $need_version; |
|
8 | + |
|
9 | + public function __construct($db_type, $need_version) { |
|
10 | + $this->pdo = Db::pdo(); |
|
11 | + $this->db_type = $db_type; |
|
12 | + $this->need_version = (int) $need_version; |
|
13 | + } |
|
14 | + |
|
15 | + public function getSchemaVersion() { |
|
16 | + $row = $this->pdo->query("SELECT schema_version FROM ttrss_version")->fetch(); |
|
17 | + return (int) $row['schema_version']; |
|
18 | + } |
|
19 | + |
|
20 | + public function isUpdateRequired() { |
|
21 | + return $this->getSchemaVersion() < $this->need_version; |
|
22 | + } |
|
23 | + |
|
24 | + public function getSchemaLines($version) { |
|
25 | + $filename = "schema/versions/".$this->db_type."/$version.sql"; |
|
26 | + |
|
27 | + if (file_exists($filename)) { |
|
28 | + return explode(";", preg_replace("/[\r\n]/", "", file_get_contents($filename))); |
|
29 | + } else { |
|
30 | + user_error("DB Updater: schema file for version $version is not found."); |
|
31 | + return false; |
|
32 | + } |
|
33 | + } |
|
34 | + |
|
35 | + public function performUpdateTo($version, $html_output = true) { |
|
36 | + if ($this->getSchemaVersion() == $version - 1) { |
|
37 | + |
|
38 | + $lines = $this->getSchemaLines($version); |
|
39 | + |
|
40 | + if (is_array($lines)) { |
|
41 | + |
|
42 | + $this->pdo->beginTransaction(); |
|
43 | + |
|
44 | + foreach ($lines as $line) { |
|
45 | + if (strpos($line, "--") !== 0 && $line) { |
|
46 | + |
|
47 | + if ($html_output) { |
|
48 | + print "<pre>$line</pre>"; |
|
49 | + } else { |
|
50 | + Debug::log("> $line"); |
|
51 | + } |
|
52 | + |
|
53 | + try { |
|
54 | + $this->pdo->query($line); // PDO returns errors as exceptions now |
|
55 | + } catch (PDOException $e) { |
|
56 | + if ($html_output) { |
|
57 | + print "<div class='text-error'>Error: ".$e->getMessage()."</div>"; |
|
58 | + } else { |
|
59 | + Debug::log("Error: ".$e->getMessage()); |
|
60 | + } |
|
61 | + |
|
62 | + $this->pdo->rollBack(); |
|
63 | + return false; |
|
64 | + } |
|
65 | + } |
|
66 | + } |
|
67 | + |
|
68 | + $db_version = $this->getSchemaVersion(); |
|
69 | + |
|
70 | + if ($db_version == $version) { |
|
71 | + $this->pdo->commit(); |
|
72 | + return true; |
|
73 | + } else { |
|
74 | + $this->pdo->rollBack(); |
|
75 | + return false; |
|
76 | + } |
|
77 | + } else { |
|
78 | + return false; |
|
79 | + } |
|
80 | + } else { |
|
81 | + return false; |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | 85 | } |
@@ -2,126 +2,126 @@ discard block |
||
2 | 2 | class Digest |
3 | 3 | { |
4 | 4 | |
5 | - /** |
|
6 | - * Send by mail a digest of last articles. |
|
7 | - * |
|
8 | - * @param mixed $link The database connection. |
|
9 | - * @param integer $limit The maximum number of articles by digest. |
|
10 | - * @return boolean Return false if digests are not enabled. |
|
11 | - */ |
|
12 | - public static function send_headlines_digests() { |
|
5 | + /** |
|
6 | + * Send by mail a digest of last articles. |
|
7 | + * |
|
8 | + * @param mixed $link The database connection. |
|
9 | + * @param integer $limit The maximum number of articles by digest. |
|
10 | + * @return boolean Return false if digests are not enabled. |
|
11 | + */ |
|
12 | + public static function send_headlines_digests() { |
|
13 | 13 | |
14 | - $user_limit = 15; // amount of users to process (e.g. emails to send out) |
|
15 | - $limit = 1000; // maximum amount of headlines to include |
|
14 | + $user_limit = 15; // amount of users to process (e.g. emails to send out) |
|
15 | + $limit = 1000; // maximum amount of headlines to include |
|
16 | 16 | |
17 | - Debug::log("Sending digests, batch of max $user_limit users, headline limit = $limit"); |
|
17 | + Debug::log("Sending digests, batch of max $user_limit users, headline limit = $limit"); |
|
18 | 18 | |
19 | - if (DB_TYPE == "pgsql") { |
|
20 | - $interval_qpart = "last_digest_sent < NOW() - INTERVAL '1 days'"; |
|
21 | - } else if (DB_TYPE == "mysql") { |
|
22 | - $interval_qpart = "last_digest_sent < DATE_SUB(NOW(), INTERVAL 1 DAY)"; |
|
23 | - } |
|
19 | + if (DB_TYPE == "pgsql") { |
|
20 | + $interval_qpart = "last_digest_sent < NOW() - INTERVAL '1 days'"; |
|
21 | + } else if (DB_TYPE == "mysql") { |
|
22 | + $interval_qpart = "last_digest_sent < DATE_SUB(NOW(), INTERVAL 1 DAY)"; |
|
23 | + } |
|
24 | 24 | |
25 | - $pdo = Db::pdo(); |
|
25 | + $pdo = Db::pdo(); |
|
26 | 26 | |
27 | - $res = $pdo->query("SELECT id,email FROM ttrss_users |
|
27 | + $res = $pdo->query("SELECT id,email FROM ttrss_users |
|
28 | 28 | WHERE email != '' AND (last_digest_sent IS NULL OR $interval_qpart)"); |
29 | 29 | |
30 | - while ($line = $res->fetch()) { |
|
30 | + while ($line = $res->fetch()) { |
|
31 | 31 | |
32 | - if (@get_pref('DIGEST_ENABLE', $line['id'], false)) { |
|
33 | - $preferred_ts = strtotime(get_pref('DIGEST_PREFERRED_TIME', $line['id'], '00:00')); |
|
32 | + if (@get_pref('DIGEST_ENABLE', $line['id'], false)) { |
|
33 | + $preferred_ts = strtotime(get_pref('DIGEST_PREFERRED_TIME', $line['id'], '00:00')); |
|
34 | 34 | |
35 | - // try to send digests within 2 hours of preferred time |
|
36 | - if ($preferred_ts && time() >= $preferred_ts && |
|
37 | - time() - $preferred_ts <= 7200 |
|
38 | - ) { |
|
35 | + // try to send digests within 2 hours of preferred time |
|
36 | + if ($preferred_ts && time() >= $preferred_ts && |
|
37 | + time() - $preferred_ts <= 7200 |
|
38 | + ) { |
|
39 | 39 | |
40 | - Debug::log("Sending digest for UID:".$line['id']." - ".$line["email"]); |
|
40 | + Debug::log("Sending digest for UID:".$line['id']." - ".$line["email"]); |
|
41 | 41 | |
42 | - $do_catchup = get_pref('DIGEST_CATCHUP', $line['id'], false); |
|
42 | + $do_catchup = get_pref('DIGEST_CATCHUP', $line['id'], false); |
|
43 | 43 | |
44 | - global $tz_offset; |
|
44 | + global $tz_offset; |
|
45 | 45 | |
46 | - // reset tz_offset global to prevent tz cache clash between users |
|
47 | - $tz_offset = -1; |
|
46 | + // reset tz_offset global to prevent tz cache clash between users |
|
47 | + $tz_offset = -1; |
|
48 | 48 | |
49 | - $tuple = Digest::prepare_headlines_digest($line["id"], 1, $limit); |
|
50 | - $digest = $tuple[0]; |
|
51 | - $headlines_count = $tuple[1]; |
|
52 | - $affected_ids = $tuple[2]; |
|
53 | - $digest_text = $tuple[3]; |
|
49 | + $tuple = Digest::prepare_headlines_digest($line["id"], 1, $limit); |
|
50 | + $digest = $tuple[0]; |
|
51 | + $headlines_count = $tuple[1]; |
|
52 | + $affected_ids = $tuple[2]; |
|
53 | + $digest_text = $tuple[3]; |
|
54 | 54 | |
55 | - if ($headlines_count > 0) { |
|
55 | + if ($headlines_count > 0) { |
|
56 | 56 | |
57 | - $mailer = new Mailer(); |
|
57 | + $mailer = new Mailer(); |
|
58 | 58 | |
59 | - //$rc = $mail->quickMail($line["email"], $line["login"], DIGEST_SUBJECT, $digest, $digest_text); |
|
59 | + //$rc = $mail->quickMail($line["email"], $line["login"], DIGEST_SUBJECT, $digest, $digest_text); |
|
60 | 60 | |
61 | - $rc = $mailer->mail(["to_name" => $line["login"], |
|
62 | - "to_address" => $line["email"], |
|
63 | - "subject" => DIGEST_SUBJECT, |
|
64 | - "message" => $digest_text, |
|
65 | - "message_html" => $digest]); |
|
61 | + $rc = $mailer->mail(["to_name" => $line["login"], |
|
62 | + "to_address" => $line["email"], |
|
63 | + "subject" => DIGEST_SUBJECT, |
|
64 | + "message" => $digest_text, |
|
65 | + "message_html" => $digest]); |
|
66 | 66 | |
67 | - //if (!$rc && $debug) Debug::log("ERROR: " . $mailer->lastError()); |
|
67 | + //if (!$rc && $debug) Debug::log("ERROR: " . $mailer->lastError()); |
|
68 | 68 | |
69 | - Debug::log("RC=$rc"); |
|
69 | + Debug::log("RC=$rc"); |
|
70 | 70 | |
71 | - if ($rc && $do_catchup) { |
|
72 | - Debug::log("Marking affected articles as read..."); |
|
73 | - Article::catchupArticlesById($affected_ids, 0, $line["id"]); |
|
74 | - } |
|
75 | - } else { |
|
76 | - Debug::log("No headlines"); |
|
77 | - } |
|
71 | + if ($rc && $do_catchup) { |
|
72 | + Debug::log("Marking affected articles as read..."); |
|
73 | + Article::catchupArticlesById($affected_ids, 0, $line["id"]); |
|
74 | + } |
|
75 | + } else { |
|
76 | + Debug::log("No headlines"); |
|
77 | + } |
|
78 | 78 | |
79 | - $sth = $pdo->prepare("UPDATE ttrss_users SET last_digest_sent = NOW() |
|
79 | + $sth = $pdo->prepare("UPDATE ttrss_users SET last_digest_sent = NOW() |
|
80 | 80 | WHERE id = ?"); |
81 | - $sth->execute([$line["id"]]); |
|
81 | + $sth->execute([$line["id"]]); |
|
82 | 82 | |
83 | - } |
|
84 | - } |
|
85 | - } |
|
83 | + } |
|
84 | + } |
|
85 | + } |
|
86 | 86 | |
87 | - Debug::log("All done."); |
|
87 | + Debug::log("All done."); |
|
88 | 88 | |
89 | - } |
|
89 | + } |
|
90 | 90 | |
91 | - public static function prepare_headlines_digest($user_id, $days = 1, $limit = 1000) { |
|
91 | + public static function prepare_headlines_digest($user_id, $days = 1, $limit = 1000) { |
|
92 | 92 | |
93 | - require_once "lib/MiniTemplator.class.php"; |
|
93 | + require_once "lib/MiniTemplator.class.php"; |
|
94 | 94 | |
95 | - $tpl = new MiniTemplator; |
|
96 | - $tpl_t = new MiniTemplator; |
|
95 | + $tpl = new MiniTemplator; |
|
96 | + $tpl_t = new MiniTemplator; |
|
97 | 97 | |
98 | - $tpl->readTemplateFromFile("templates/digest_template_html.txt"); |
|
99 | - $tpl_t->readTemplateFromFile("templates/digest_template.txt"); |
|
98 | + $tpl->readTemplateFromFile("templates/digest_template_html.txt"); |
|
99 | + $tpl_t->readTemplateFromFile("templates/digest_template.txt"); |
|
100 | 100 | |
101 | - $user_tz_string = get_pref('USER_TIMEZONE', $user_id); |
|
102 | - $local_ts = convert_timestamp(time(), 'UTC', $user_tz_string); |
|
101 | + $user_tz_string = get_pref('USER_TIMEZONE', $user_id); |
|
102 | + $local_ts = convert_timestamp(time(), 'UTC', $user_tz_string); |
|
103 | 103 | |
104 | - $tpl->setVariable('CUR_DATE', date('Y/m/d', $local_ts)); |
|
105 | - $tpl->setVariable('CUR_TIME', date('G:i', $local_ts)); |
|
106 | - $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
104 | + $tpl->setVariable('CUR_DATE', date('Y/m/d', $local_ts)); |
|
105 | + $tpl->setVariable('CUR_TIME', date('G:i', $local_ts)); |
|
106 | + $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
107 | 107 | |
108 | - $tpl_t->setVariable('CUR_DATE', date('Y/m/d', $local_ts)); |
|
109 | - $tpl_t->setVariable('CUR_TIME', date('G:i', $local_ts)); |
|
110 | - $tpl_t->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
108 | + $tpl_t->setVariable('CUR_DATE', date('Y/m/d', $local_ts)); |
|
109 | + $tpl_t->setVariable('CUR_TIME', date('G:i', $local_ts)); |
|
110 | + $tpl_t->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
111 | 111 | |
112 | - $affected_ids = array(); |
|
112 | + $affected_ids = array(); |
|
113 | 113 | |
114 | - $days = (int) $days; |
|
114 | + $days = (int) $days; |
|
115 | 115 | |
116 | - if (DB_TYPE == "pgsql") { |
|
117 | - $interval_qpart = "ttrss_entries.date_updated > NOW() - INTERVAL '$days days'"; |
|
118 | - } else if (DB_TYPE == "mysql") { |
|
119 | - $interval_qpart = "ttrss_entries.date_updated > DATE_SUB(NOW(), INTERVAL $days DAY)"; |
|
120 | - } |
|
116 | + if (DB_TYPE == "pgsql") { |
|
117 | + $interval_qpart = "ttrss_entries.date_updated > NOW() - INTERVAL '$days days'"; |
|
118 | + } else if (DB_TYPE == "mysql") { |
|
119 | + $interval_qpart = "ttrss_entries.date_updated > DATE_SUB(NOW(), INTERVAL $days DAY)"; |
|
120 | + } |
|
121 | 121 | |
122 | - $pdo = Db::pdo(); |
|
122 | + $pdo = Db::pdo(); |
|
123 | 123 | |
124 | - $sth = $pdo->prepare("SELECT ttrss_entries.title, |
|
124 | + $sth = $pdo->prepare("SELECT ttrss_entries.title, |
|
125 | 125 | ttrss_feeds.title AS feed_title, |
126 | 126 | COALESCE(ttrss_feed_categories.title, '" . __('Uncategorized')."') AS cat_title, |
127 | 127 | date_updated, |
@@ -143,76 +143,76 @@ discard block |
||
143 | 143 | AND score >= 0 |
144 | 144 | ORDER BY ttrss_feed_categories.title, ttrss_feeds.title, score DESC, date_updated DESC |
145 | 145 | LIMIT :limit"); |
146 | - $sth->bindParam(':user_id', intval($user_id, 10), PDO::PARAM_INT); |
|
147 | - $sth->bindParam(':limit', intval($limit, 10), PDO::PARAM_INT); |
|
148 | - $sth->execute(); |
|
146 | + $sth->bindParam(':user_id', intval($user_id, 10), PDO::PARAM_INT); |
|
147 | + $sth->bindParam(':limit', intval($limit, 10), PDO::PARAM_INT); |
|
148 | + $sth->execute(); |
|
149 | 149 | |
150 | - $headlines_count = 0; |
|
151 | - $headlines = array(); |
|
150 | + $headlines_count = 0; |
|
151 | + $headlines = array(); |
|
152 | 152 | |
153 | - while ($line = $sth->fetch()) { |
|
154 | - array_push($headlines, $line); |
|
155 | - $headlines_count++; |
|
156 | - } |
|
153 | + while ($line = $sth->fetch()) { |
|
154 | + array_push($headlines, $line); |
|
155 | + $headlines_count++; |
|
156 | + } |
|
157 | 157 | |
158 | - for ($i = 0; $i < sizeof($headlines); $i++) { |
|
158 | + for ($i = 0; $i < sizeof($headlines); $i++) { |
|
159 | 159 | |
160 | - $line = $headlines[$i]; |
|
160 | + $line = $headlines[$i]; |
|
161 | 161 | |
162 | - array_push($affected_ids, $line["ref_id"]); |
|
162 | + array_push($affected_ids, $line["ref_id"]); |
|
163 | 163 | |
164 | - $updated = make_local_datetime($line['last_updated'], false, |
|
165 | - $user_id); |
|
164 | + $updated = make_local_datetime($line['last_updated'], false, |
|
165 | + $user_id); |
|
166 | 166 | |
167 | - if (get_pref('ENABLE_FEED_CATS', $user_id)) { |
|
168 | - $line['feed_title'] = $line['cat_title']." / ".$line['feed_title']; |
|
169 | - } |
|
167 | + if (get_pref('ENABLE_FEED_CATS', $user_id)) { |
|
168 | + $line['feed_title'] = $line['cat_title']." / ".$line['feed_title']; |
|
169 | + } |
|
170 | 170 | |
171 | - $article_labels = Article::get_article_labels($line["ref_id"], $user_id); |
|
172 | - $article_labels_formatted = ""; |
|
171 | + $article_labels = Article::get_article_labels($line["ref_id"], $user_id); |
|
172 | + $article_labels_formatted = ""; |
|
173 | 173 | |
174 | - if (is_array($article_labels) && count($article_labels) > 0) { |
|
175 | - $article_labels_formatted = implode(", ", array_map(function($a) { |
|
176 | - return $a[1]; |
|
177 | - }, $article_labels)); |
|
178 | - } |
|
174 | + if (is_array($article_labels) && count($article_labels) > 0) { |
|
175 | + $article_labels_formatted = implode(", ", array_map(function($a) { |
|
176 | + return $a[1]; |
|
177 | + }, $article_labels)); |
|
178 | + } |
|
179 | 179 | |
180 | - $tpl->setVariable('FEED_TITLE', $line["feed_title"]); |
|
181 | - $tpl->setVariable('ARTICLE_TITLE', $line["title"]); |
|
182 | - $tpl->setVariable('ARTICLE_LINK', $line["link"]); |
|
183 | - $tpl->setVariable('ARTICLE_UPDATED', $updated); |
|
184 | - $tpl->setVariable('ARTICLE_EXCERPT', |
|
185 | - truncate_string(strip_tags($line["content"]), 300)); |
|
180 | + $tpl->setVariable('FEED_TITLE', $line["feed_title"]); |
|
181 | + $tpl->setVariable('ARTICLE_TITLE', $line["title"]); |
|
182 | + $tpl->setVariable('ARTICLE_LINK', $line["link"]); |
|
183 | + $tpl->setVariable('ARTICLE_UPDATED', $updated); |
|
184 | + $tpl->setVariable('ARTICLE_EXCERPT', |
|
185 | + truncate_string(strip_tags($line["content"]), 300)); |
|
186 | 186 | // $tpl->setVariable('ARTICLE_CONTENT', |
187 | 187 | // strip_tags($article_content)); |
188 | - $tpl->setVariable('ARTICLE_LABELS', $article_labels_formatted, true); |
|
188 | + $tpl->setVariable('ARTICLE_LABELS', $article_labels_formatted, true); |
|
189 | 189 | |
190 | - $tpl->addBlock('article'); |
|
190 | + $tpl->addBlock('article'); |
|
191 | 191 | |
192 | - $tpl_t->setVariable('FEED_TITLE', $line["feed_title"]); |
|
193 | - $tpl_t->setVariable('ARTICLE_TITLE', $line["title"]); |
|
194 | - $tpl_t->setVariable('ARTICLE_LINK', $line["link"]); |
|
195 | - $tpl_t->setVariable('ARTICLE_UPDATED', $updated); |
|
196 | - $tpl_t->setVariable('ARTICLE_LABELS', $article_labels_formatted, true); |
|
197 | - $tpl_t->setVariable('ARTICLE_EXCERPT', |
|
198 | - truncate_string(strip_tags($line["content"]), 300, "..."), true); |
|
192 | + $tpl_t->setVariable('FEED_TITLE', $line["feed_title"]); |
|
193 | + $tpl_t->setVariable('ARTICLE_TITLE', $line["title"]); |
|
194 | + $tpl_t->setVariable('ARTICLE_LINK', $line["link"]); |
|
195 | + $tpl_t->setVariable('ARTICLE_UPDATED', $updated); |
|
196 | + $tpl_t->setVariable('ARTICLE_LABELS', $article_labels_formatted, true); |
|
197 | + $tpl_t->setVariable('ARTICLE_EXCERPT', |
|
198 | + truncate_string(strip_tags($line["content"]), 300, "..."), true); |
|
199 | 199 | |
200 | - $tpl_t->addBlock('article'); |
|
200 | + $tpl_t->addBlock('article'); |
|
201 | 201 | |
202 | - if ($headlines[$i]['feed_title'] != $headlines[$i + 1]['feed_title']) { |
|
203 | - $tpl->addBlock('feed'); |
|
204 | - $tpl_t->addBlock('feed'); |
|
205 | - } |
|
202 | + if ($headlines[$i]['feed_title'] != $headlines[$i + 1]['feed_title']) { |
|
203 | + $tpl->addBlock('feed'); |
|
204 | + $tpl_t->addBlock('feed'); |
|
205 | + } |
|
206 | 206 | |
207 | - } |
|
207 | + } |
|
208 | 208 | |
209 | - $tpl->addBlock('digest'); |
|
210 | - $tpl->generateOutputToString($tmp); |
|
209 | + $tpl->addBlock('digest'); |
|
210 | + $tpl->generateOutputToString($tmp); |
|
211 | 211 | |
212 | - $tpl_t->addBlock('digest'); |
|
213 | - $tpl_t->generateOutputToString($tmp_t); |
|
212 | + $tpl_t->addBlock('digest'); |
|
213 | + $tpl_t->generateOutputToString($tmp_t); |
|
214 | 214 | |
215 | - return array($tmp, $headlines_count, $affected_ids, $tmp_t); |
|
216 | - } |
|
215 | + return array($tmp, $headlines_count, $affected_ids, $tmp_t); |
|
216 | + } |
|
217 | 217 | |
218 | 218 | } |
@@ -1,88 +1,88 @@ |
||
1 | 1 | <?php |
2 | 2 | class Db_Mysqli implements IDb { |
3 | - private $link; |
|
4 | - private $last_error; |
|
5 | - |
|
6 | - public function connect($host, $user, $pass, $db, $port) { |
|
7 | - if ($port) { |
|
8 | - $this->link = mysqli_connect($host, $user, $pass, $db, $port); |
|
9 | - } else { |
|
10 | - $this->link = mysqli_connect($host, $user, $pass, $db); |
|
11 | - } |
|
12 | - |
|
13 | - if ($this->link) { |
|
14 | - $this->init(); |
|
15 | - |
|
16 | - return $this->link; |
|
17 | - } else { |
|
18 | - print("Unable to connect to database (as $user to $host, database $db): ".mysqli_connect_error()); |
|
19 | - exit(102); |
|
20 | - } |
|
21 | - } |
|
22 | - |
|
23 | - public function escape_string($s, $strip_tags = true) { |
|
24 | - if ($strip_tags) { |
|
25 | - $s = strip_tags($s); |
|
26 | - } |
|
27 | - |
|
28 | - return mysqli_real_escape_string($this->link, $s); |
|
29 | - } |
|
30 | - |
|
31 | - public function query($query, $die_on_error = true) { |
|
32 | - $result = @mysqli_query($this->link, $query); |
|
33 | - if (!$result) { |
|
34 | - $this->last_error = @mysqli_error($this->link); |
|
35 | - |
|
36 | - @mysqli_query($this->link, "ROLLBACK"); |
|
37 | - user_error("query $query failed: ".($this->link ? $this->last_error : "No connection"), |
|
38 | - $die_on_error ? E_USER_ERROR : E_USER_WARNING); |
|
39 | - } |
|
40 | - |
|
41 | - return $result; |
|
42 | - } |
|
43 | - |
|
44 | - public function fetch_assoc($result) { |
|
45 | - return mysqli_fetch_assoc($result); |
|
46 | - } |
|
47 | - |
|
48 | - |
|
49 | - public function num_rows($result) { |
|
50 | - return mysqli_num_rows($result); |
|
51 | - } |
|
52 | - |
|
53 | - public function fetch_result($result, $row, $param) { |
|
54 | - if (mysqli_data_seek($result, $row)) { |
|
55 | - $line = mysqli_fetch_assoc($result); |
|
56 | - return $line[$param]; |
|
57 | - } else { |
|
58 | - return false; |
|
59 | - } |
|
60 | - } |
|
61 | - |
|
62 | - public function close() { |
|
63 | - return mysqli_close($this->link); |
|
64 | - } |
|
65 | - |
|
66 | - public function affected_rows($result) { |
|
67 | - return mysqli_affected_rows($this->link); |
|
68 | - } |
|
69 | - |
|
70 | - public function last_error() { |
|
71 | - return mysqli_error($this->link); |
|
72 | - } |
|
73 | - |
|
74 | - public function last_query_error() { |
|
75 | - return $this->last_error; |
|
76 | - } |
|
77 | - |
|
78 | - public function init() { |
|
79 | - $this->query("SET time_zone = '+0:0'"); |
|
80 | - |
|
81 | - if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { |
|
82 | - mysqli_set_charset($this->link, MYSQL_CHARSET); |
|
83 | - } |
|
84 | - |
|
85 | - return true; |
|
86 | - } |
|
3 | + private $link; |
|
4 | + private $last_error; |
|
5 | + |
|
6 | + public function connect($host, $user, $pass, $db, $port) { |
|
7 | + if ($port) { |
|
8 | + $this->link = mysqli_connect($host, $user, $pass, $db, $port); |
|
9 | + } else { |
|
10 | + $this->link = mysqli_connect($host, $user, $pass, $db); |
|
11 | + } |
|
12 | + |
|
13 | + if ($this->link) { |
|
14 | + $this->init(); |
|
15 | + |
|
16 | + return $this->link; |
|
17 | + } else { |
|
18 | + print("Unable to connect to database (as $user to $host, database $db): ".mysqli_connect_error()); |
|
19 | + exit(102); |
|
20 | + } |
|
21 | + } |
|
22 | + |
|
23 | + public function escape_string($s, $strip_tags = true) { |
|
24 | + if ($strip_tags) { |
|
25 | + $s = strip_tags($s); |
|
26 | + } |
|
27 | + |
|
28 | + return mysqli_real_escape_string($this->link, $s); |
|
29 | + } |
|
30 | + |
|
31 | + public function query($query, $die_on_error = true) { |
|
32 | + $result = @mysqli_query($this->link, $query); |
|
33 | + if (!$result) { |
|
34 | + $this->last_error = @mysqli_error($this->link); |
|
35 | + |
|
36 | + @mysqli_query($this->link, "ROLLBACK"); |
|
37 | + user_error("query $query failed: ".($this->link ? $this->last_error : "No connection"), |
|
38 | + $die_on_error ? E_USER_ERROR : E_USER_WARNING); |
|
39 | + } |
|
40 | + |
|
41 | + return $result; |
|
42 | + } |
|
43 | + |
|
44 | + public function fetch_assoc($result) { |
|
45 | + return mysqli_fetch_assoc($result); |
|
46 | + } |
|
47 | + |
|
48 | + |
|
49 | + public function num_rows($result) { |
|
50 | + return mysqli_num_rows($result); |
|
51 | + } |
|
52 | + |
|
53 | + public function fetch_result($result, $row, $param) { |
|
54 | + if (mysqli_data_seek($result, $row)) { |
|
55 | + $line = mysqli_fetch_assoc($result); |
|
56 | + return $line[$param]; |
|
57 | + } else { |
|
58 | + return false; |
|
59 | + } |
|
60 | + } |
|
61 | + |
|
62 | + public function close() { |
|
63 | + return mysqli_close($this->link); |
|
64 | + } |
|
65 | + |
|
66 | + public function affected_rows($result) { |
|
67 | + return mysqli_affected_rows($this->link); |
|
68 | + } |
|
69 | + |
|
70 | + public function last_error() { |
|
71 | + return mysqli_error($this->link); |
|
72 | + } |
|
73 | + |
|
74 | + public function last_query_error() { |
|
75 | + return $this->last_error; |
|
76 | + } |
|
77 | + |
|
78 | + public function init() { |
|
79 | + $this->query("SET time_zone = '+0:0'"); |
|
80 | + |
|
81 | + if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { |
|
82 | + mysqli_set_charset($this->link, MYSQL_CHARSET); |
|
83 | + } |
|
84 | + |
|
85 | + return true; |
|
86 | + } |
|
87 | 87 | |
88 | 88 | } |
@@ -1,93 +1,93 @@ |
||
1 | 1 | <?php |
2 | 2 | class Db_Pgsql implements IDb { |
3 | - private $link; |
|
4 | - private $last_error; |
|
3 | + private $link; |
|
4 | + private $last_error; |
|
5 | 5 | |
6 | - public function connect($host, $user, $pass, $db, $port) { |
|
7 | - $string = "dbname=$db user=$user"; |
|
6 | + public function connect($host, $user, $pass, $db, $port) { |
|
7 | + $string = "dbname=$db user=$user"; |
|
8 | 8 | |
9 | - if ($pass) { |
|
10 | - $string .= " password=$pass"; |
|
11 | - } |
|
9 | + if ($pass) { |
|
10 | + $string .= " password=$pass"; |
|
11 | + } |
|
12 | 12 | |
13 | - if ($host) { |
|
14 | - $string .= " host=$host"; |
|
15 | - } |
|
13 | + if ($host) { |
|
14 | + $string .= " host=$host"; |
|
15 | + } |
|
16 | 16 | |
17 | - if (is_numeric($port) && $port > 0) { |
|
18 | - $string = "$string port=".$port; |
|
19 | - } |
|
17 | + if (is_numeric($port) && $port > 0) { |
|
18 | + $string = "$string port=".$port; |
|
19 | + } |
|
20 | 20 | |
21 | - $this->link = pg_connect($string); |
|
21 | + $this->link = pg_connect($string); |
|
22 | 22 | |
23 | - if (!$this->link) { |
|
24 | - print("Unable to connect to database (as $user to $host, database $db):".pg_last_error()); |
|
25 | - exit(102); |
|
26 | - } |
|
23 | + if (!$this->link) { |
|
24 | + print("Unable to connect to database (as $user to $host, database $db):".pg_last_error()); |
|
25 | + exit(102); |
|
26 | + } |
|
27 | 27 | |
28 | - $this->init(); |
|
28 | + $this->init(); |
|
29 | 29 | |
30 | - return $this->link; |
|
31 | - } |
|
30 | + return $this->link; |
|
31 | + } |
|
32 | 32 | |
33 | - public function escape_string($s, $strip_tags = true) { |
|
34 | - if ($strip_tags) { |
|
35 | - $s = strip_tags($s); |
|
36 | - } |
|
33 | + public function escape_string($s, $strip_tags = true) { |
|
34 | + if ($strip_tags) { |
|
35 | + $s = strip_tags($s); |
|
36 | + } |
|
37 | 37 | |
38 | - return pg_escape_string($s); |
|
39 | - } |
|
38 | + return pg_escape_string($s); |
|
39 | + } |
|
40 | 40 | |
41 | - public function query($query, $die_on_error = true) { |
|
42 | - $result = @pg_query($this->link, $query); |
|
41 | + public function query($query, $die_on_error = true) { |
|
42 | + $result = @pg_query($this->link, $query); |
|
43 | 43 | |
44 | - if (!$result) { |
|
45 | - $this->last_error = @pg_last_error($this->link); |
|
44 | + if (!$result) { |
|
45 | + $this->last_error = @pg_last_error($this->link); |
|
46 | 46 | |
47 | - @pg_query($this->link, "ROLLBACK"); |
|
48 | - $query = htmlspecialchars($query); // just in case |
|
49 | - user_error("query $query failed: ".($this->link ? $this->last_error : "No connection"), |
|
50 | - $die_on_error ? E_USER_ERROR : E_USER_WARNING); |
|
51 | - } |
|
52 | - return $result; |
|
53 | - } |
|
47 | + @pg_query($this->link, "ROLLBACK"); |
|
48 | + $query = htmlspecialchars($query); // just in case |
|
49 | + user_error("query $query failed: ".($this->link ? $this->last_error : "No connection"), |
|
50 | + $die_on_error ? E_USER_ERROR : E_USER_WARNING); |
|
51 | + } |
|
52 | + return $result; |
|
53 | + } |
|
54 | 54 | |
55 | - public function fetch_assoc($result) { |
|
56 | - return pg_fetch_assoc($result); |
|
57 | - } |
|
55 | + public function fetch_assoc($result) { |
|
56 | + return pg_fetch_assoc($result); |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - public function num_rows($result) { |
|
61 | - return pg_num_rows($result); |
|
62 | - } |
|
60 | + public function num_rows($result) { |
|
61 | + return pg_num_rows($result); |
|
62 | + } |
|
63 | 63 | |
64 | - public function fetch_result($result, $row, $param) { |
|
65 | - return pg_fetch_result($result, $row, $param); |
|
66 | - } |
|
64 | + public function fetch_result($result, $row, $param) { |
|
65 | + return pg_fetch_result($result, $row, $param); |
|
66 | + } |
|
67 | 67 | |
68 | - public function close() { |
|
69 | - return pg_close($this->link); |
|
70 | - } |
|
68 | + public function close() { |
|
69 | + return pg_close($this->link); |
|
70 | + } |
|
71 | 71 | |
72 | - public function affected_rows($result) { |
|
73 | - return pg_affected_rows($result); |
|
74 | - } |
|
72 | + public function affected_rows($result) { |
|
73 | + return pg_affected_rows($result); |
|
74 | + } |
|
75 | 75 | |
76 | - public function last_error() { |
|
77 | - return pg_last_error($this->link); |
|
78 | - } |
|
76 | + public function last_error() { |
|
77 | + return pg_last_error($this->link); |
|
78 | + } |
|
79 | 79 | |
80 | - public function last_query_error() { |
|
81 | - return $this->last_error; |
|
82 | - } |
|
80 | + public function last_query_error() { |
|
81 | + return $this->last_error; |
|
82 | + } |
|
83 | 83 | |
84 | - public function init() { |
|
85 | - $this->query("set client_encoding = 'UTF-8'"); |
|
86 | - pg_set_client_encoding("UNICODE"); |
|
87 | - $this->query("set datestyle = 'ISO, european'"); |
|
88 | - $this->query("set TIME ZONE 0"); |
|
89 | - $this->query("set cpu_tuple_cost = 0.5"); |
|
84 | + public function init() { |
|
85 | + $this->query("set client_encoding = 'UTF-8'"); |
|
86 | + pg_set_client_encoding("UNICODE"); |
|
87 | + $this->query("set datestyle = 'ISO, european'"); |
|
88 | + $this->query("set TIME ZONE 0"); |
|
89 | + $this->query("set cpu_tuple_cost = 0.5"); |
|
90 | 90 | |
91 | - return true; |
|
92 | - } |
|
91 | + return true; |
|
92 | + } |
|
93 | 93 | } |