1
|
|
|
<?php |
2
|
|
|
class Pref_Labels extends Handler_Protected { |
3
|
|
|
|
4
|
|
|
public function csrf_ignore($method) { |
5
|
|
|
$csrf_ignored = array("index", "getlabeltree", "edit"); |
6
|
|
|
|
7
|
|
|
return array_search($method, $csrf_ignored) !== false; |
8
|
|
|
} |
9
|
|
|
|
10
|
|
|
public function edit() { |
11
|
|
|
$label_id = clean($_REQUEST['id']); |
12
|
|
|
|
13
|
|
|
$sth = $this->pdo->prepare("SELECT * FROM ttrss_labels2 WHERE |
14
|
|
|
id = ? AND owner_uid = ?"); |
15
|
|
|
$sth->execute([$label_id, $_SESSION['uid']]); |
16
|
|
|
|
17
|
|
|
if ($line = $sth->fetch()) { |
18
|
|
|
|
19
|
|
|
print_hidden("id", "$label_id"); |
20
|
|
|
print_hidden("op", "pref-labels"); |
21
|
|
|
print_hidden("method", "save"); |
22
|
|
|
|
23
|
|
|
print "<form onsubmit='return false;'>"; |
24
|
|
|
|
25
|
|
|
print "<header>".__("Caption")."</header>"; |
26
|
|
|
|
27
|
|
|
print "<section>"; |
28
|
|
|
|
29
|
|
|
$fg_color = $line['fg_color']; |
30
|
|
|
$bg_color = $line['bg_color'] ? $line['bg_color'] : '#fff7d5'; |
31
|
|
|
|
32
|
|
|
print "<input style='font-size : 16px; color : $fg_color; background : $bg_color; transition : background 0.1s linear' |
33
|
|
|
id='labelEdit_caption' name='caption' dojoType='dijit.form.ValidationTextBox' |
34
|
|
|
required='true' value=\"".htmlspecialchars($line['caption'])."\">"; |
35
|
|
|
|
36
|
|
|
print "</section>"; |
37
|
|
|
|
38
|
|
|
print "<header>".__("Colors")."</header>"; |
39
|
|
|
print "<section>"; |
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'>"; |
44
|
|
|
|
45
|
|
|
print "<input dojoType='dijit.form.TextBox' |
46
|
|
|
style='display : none' id='labelEdit_fgColor' |
47
|
|
|
name='fg_color' value='$fg_color'>"; |
48
|
|
|
print "<input dojoType='dijit.form.TextBox' |
49
|
|
|
style='display : none' id='labelEdit_bgColor' |
50
|
|
|
name='bg_color' value='$bg_color'>"; |
51
|
|
|
|
52
|
|
|
print "<div dojoType='dijit.ColorPalette'> |
53
|
|
|
<script type='dojo/method' event='onChange' args='fg_color'> |
54
|
|
|
dijit.byId('labelEdit_fgColor').attr('value', fg_color); |
55
|
|
|
dijit.byId('labelEdit_caption').domNode.setStyle({color: fg_color}); |
56
|
|
|
</script> |
57
|
|
|
</div>"; |
58
|
|
|
|
59
|
|
|
print "</td><td>"; |
60
|
|
|
|
61
|
|
|
print "<div dojoType='dijit.ColorPalette'> |
62
|
|
|
<script type='dojo/method' event='onChange' args='bg_color'> |
63
|
|
|
dijit.byId('labelEdit_bgColor').attr('value', bg_color); |
64
|
|
|
dijit.byId('labelEdit_caption').domNode.setStyle({backgroundColor: bg_color}); |
65
|
|
|
</script> |
66
|
|
|
</div>"; |
67
|
|
|
|
68
|
|
|
print "</td></tr></table>"; |
69
|
|
|
print "</section>"; |
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>"; |
77
|
|
|
|
78
|
|
|
print "</form>"; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getlabeltree() { |
83
|
|
|
$root = array(); |
84
|
|
|
$root['id'] = 'root'; |
85
|
|
|
$root['name'] = __('Labels'); |
86
|
|
|
$root['items'] = array(); |
87
|
|
|
|
88
|
|
|
$sth = $this->pdo->prepare("SELECT * |
89
|
|
|
FROM ttrss_labels2 |
90
|
|
|
WHERE owner_uid = ? |
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 |
127
|
|
|
${kind}_color = ? WHERE id = ? |
128
|
|
|
AND owner_uid = ?"); |
129
|
|
|
|
130
|
|
|
$sth->execute([$color, $id, $_SESSION['uid']]); |
131
|
|
|
|
132
|
|
|
} else { |
133
|
|
|
|
134
|
|
|
$sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET |
135
|
|
|
fg_color = ?, bg_color = ? WHERE id = ? |
136
|
|
|
AND owner_uid = ?"); |
137
|
|
|
|
138
|
|
|
$sth->execute([$fg, $bg, $id, $_SESSION['uid']]); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/* Remove cached data */ |
142
|
|
|
|
143
|
|
|
$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET label_cache = '' |
144
|
|
|
WHERE owner_uid = ?"); |
145
|
|
|
$sth->execute([$_SESSION['uid']]); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function colorreset() { |
150
|
|
|
$ids = explode(',', clean($_REQUEST["ids"])); |
|
|
|
|
151
|
|
|
|
152
|
|
|
foreach ($ids as $id) { |
153
|
|
|
$sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET |
154
|
|
|
fg_color = '', bg_color = '' WHERE id = ? |
155
|
|
|
AND owner_uid = ?"); |
156
|
|
|
$sth->execute([$id, $_SESSION['uid']]); |
157
|
|
|
|
158
|
|
|
/* Remove cached data */ |
159
|
|
|
|
160
|
|
|
$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET label_cache = '' |
161
|
|
|
WHERE owner_uid = ?"); |
162
|
|
|
$sth->execute([$_SESSION['uid']]); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function save() { |
167
|
|
|
|
168
|
|
|
$id = clean($_REQUEST["id"]); |
169
|
|
|
$caption = trim(clean($_REQUEST["caption"])); |
|
|
|
|
170
|
|
|
|
171
|
|
|
$this->pdo->beginTransaction(); |
172
|
|
|
|
173
|
|
|
$sth = $this->pdo->prepare("SELECT caption FROM ttrss_labels2 |
174
|
|
|
WHERE id = ? AND owner_uid = ?"); |
175
|
|
|
$sth->execute([$id, $_SESSION['uid']]); |
176
|
|
|
|
177
|
|
|
if ($row = $sth->fetch()) { |
178
|
|
|
$old_caption = $row["caption"]; |
179
|
|
|
|
180
|
|
|
$sth = $this->pdo->prepare("SELECT id FROM ttrss_labels2 |
181
|
|
|
WHERE caption = ? AND owner_uid = ?"); |
182
|
|
|
$sth->execute([$caption, $_SESSION['uid']]); |
183
|
|
|
|
184
|
|
|
if (!$sth->fetch()) { |
185
|
|
|
if ($caption) { |
186
|
|
|
$sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET |
187
|
|
|
caption = ? WHERE id = ? AND |
188
|
|
|
owner_uid = ?"); |
189
|
|
|
$sth->execute([$caption, $id, $_SESSION['uid']]); |
190
|
|
|
|
191
|
|
|
/* Update filters that reference label being renamed */ |
192
|
|
|
|
193
|
|
|
$sth = $this->pdo->prepare("UPDATE ttrss_filters2_actions SET |
194
|
|
|
action_param = ? WHERE action_param = ? |
195
|
|
|
AND action_id = 7 |
196
|
|
|
AND filter_id IN (SELECT id FROM ttrss_filters2 WHERE owner_uid = ?)"); |
197
|
|
|
|
198
|
|
|
$sth->execute([$caption, $old_caption, $_SESSION['uid']]); |
199
|
|
|
|
200
|
|
|
print clean($_REQUEST["value"]); |
|
|
|
|
201
|
|
|
} else { |
202
|
|
|
print $old_caption; |
203
|
|
|
} |
204
|
|
|
} else { |
205
|
|
|
print $old_caption; |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
$this->pdo->commit(); |
210
|
|
|
|
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
public function remove() { |
214
|
|
|
|
215
|
|
|
$ids = explode(",", clean($_REQUEST["ids"])); |
|
|
|
|
216
|
|
|
|
217
|
|
|
foreach ($ids as $id) { |
218
|
|
|
Labels::remove($id, $_SESSION["uid"]); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
public function add() { |
224
|
|
|
$caption = clean($_REQUEST["caption"]); |
225
|
|
|
$output = clean($_REQUEST["output"]); |
226
|
|
|
|
227
|
|
|
if ($caption) { |
228
|
|
|
|
229
|
|
|
if (Labels::create($caption)) { |
230
|
|
|
if (!$output) { |
231
|
|
|
print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption)); |
|
|
|
|
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
if ($output == "select") { |
236
|
|
|
header("Content-Type: text/xml"); |
237
|
|
|
|
238
|
|
|
print "<rpc-reply><payload>"; |
239
|
|
|
|
240
|
|
|
print_label_select("select_label", |
241
|
|
|
$caption, ""); |
242
|
|
|
|
243
|
|
|
print "</payload></rpc-reply>"; |
244
|
|
|
} |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
return; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
public function index() { |
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'>"; |
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)\" |
260
|
|
|
dojoType=\"dijit.MenuItem\">".__('All')."</div>"; |
261
|
|
|
print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(false)\" |
262
|
|
|
dojoType=\"dijit.MenuItem\">".__('None')."</div>"; |
263
|
|
|
print "</div></div>"; |
264
|
|
|
|
265
|
|
|
print"<button dojoType=\"dijit.form.Button\" onclick=\"CommonDialogs.addLabel()\">". |
266
|
|
|
__('Create label')."</button dojoType=\"dijit.form.Button\"> "; |
267
|
|
|
|
268
|
|
|
print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelTree').removeSelected()\">". |
269
|
|
|
__('Remove')."</button dojoType=\"dijit.form.Button\"> "; |
270
|
|
|
|
271
|
|
|
print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelTree').resetColors()\">". |
272
|
|
|
__('Clear colors')."</button dojoType=\"dijit.form.Button\">"; |
273
|
|
|
|
274
|
|
|
|
275
|
|
|
print "</div>"; #toolbar |
276
|
|
|
print "</div>"; #pane |
277
|
|
|
print "<div style='padding : 0px' dojoType=\"dijit.layout.ContentPane\" region=\"center\">"; |
278
|
|
|
|
279
|
|
|
print "<div id=\"labellistLoading\"> |
280
|
|
|
<img src='images/indicator_tiny.gif'>". |
281
|
|
|
__("Loading, please wait...")."</div>"; |
282
|
|
|
|
283
|
|
|
print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"labelStore\" |
284
|
|
|
url=\"backend.php?op=pref-labels&method=getlabeltree\"> |
285
|
|
|
</div> |
286
|
|
|
<div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"labelModel\" store=\"labelStore\" |
287
|
|
|
query=\"{id:'root'}\" rootId=\"root\" |
288
|
|
|
childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\"> |
289
|
|
|
</div> |
290
|
|
|
<div dojoType=\"fox.PrefLabelTree\" id=\"labelTree\" |
291
|
|
|
model=\"labelModel\" openOnClick=\"true\"> |
292
|
|
|
<script type=\"dojo/method\" event=\"onLoad\" args=\"item\"> |
293
|
|
|
Element.hide(\"labellistLoading\"); |
294
|
|
|
</script> |
295
|
|
|
<script type=\"dojo/method\" event=\"onClick\" args=\"item\"> |
296
|
|
|
var id = String(item.id); |
297
|
|
|
var bare_id = id.substr(id.indexOf(':')+1); |
298
|
|
|
|
299
|
|
|
if (id.match('LABEL:')) { |
300
|
|
|
dijit.byId('labelTree').editLabel(bare_id); |
301
|
|
|
} |
302
|
|
|
</script> |
303
|
|
|
</div>"; |
304
|
|
|
|
305
|
|
|
print "</div>"; #pane |
306
|
|
|
|
307
|
|
|
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
308
|
|
|
"hook_prefs_tab", "prefLabels"); |
309
|
|
|
|
310
|
|
|
print "</div>"; #container |
311
|
|
|
|
312
|
|
|
} |
313
|
|
|
} |
314
|
|
|
|