]>
Commit | Line | Data |
---|---|---|
cbe50c80 | 1 | <?php |
369dbc19 | 2 | class Pref_Labels extends Handler_Protected { |
cbe50c80 | 3 | |
8484ce22 AD |
4 | function csrf_ignore($method) { |
5 | $csrf_ignored = array("index", "getlabeltree", "edit"); | |
6 | ||
7 | return array_search($method, $csrf_ignored) !== false; | |
8 | } | |
9 | ||
cbe50c80 | 10 | function edit() { |
e6532439 | 11 | $label_id = clean($_REQUEST['id']); |
cbe50c80 | 12 | |
21295a52 AD |
13 | $sth = $this->pdo->prepare("SELECT * FROM ttrss_labels2 WHERE |
14 | id = ? AND owner_uid = ?"); | |
15 | $sth->execute([$label_id, $_SESSION['uid']]); | |
cbe50c80 | 16 | |
21295a52 | 17 | if ($line = $sth->fetch()) { |
cbe50c80 | 18 | |
21295a52 AD |
19 | print_hidden("id", "$label_id"); |
20 | print_hidden("op", "pref-labels"); | |
21 | print_hidden("method", "save"); | |
cbe50c80 | 22 | |
5f7be995 AD |
23 | print "<form onsubmit='return false;'>"; |
24 | ||
21295a52 | 25 | print "<div class=\"dlgSec\">".__("Caption")."</div>"; |
cbe50c80 | 26 | |
21295a52 | 27 | print "<div class=\"dlgSecCont\">"; |
cbe50c80 | 28 | |
21295a52 AD |
29 | $fg_color = $line['fg_color']; |
30 | $bg_color = $line['bg_color']; | |
cbe50c80 | 31 | |
21295a52 | 32 | print "<span class=\"labelColorIndicator\" id=\"label-editor-indicator\" style='color : $fg_color; background-color : $bg_color; margin-bottom : 4px; margin-right : 4px'>α</span>"; |
cbe50c80 | 33 | |
21295a52 | 34 | print "<input style=\"font-size : 16px\" name=\"caption\" |
cbe50c80 AD |
35 | dojoType=\"dijit.form.ValidationTextBox\" |
36 | required=\"true\" | |
37 | value=\"".htmlspecialchars($line['caption'])."\">"; | |
38 | ||
21295a52 AD |
39 | print "</div>"; |
40 | print "<div class=\"dlgSec\">" . __("Colors") . "</div>"; | |
41 | print "<div class=\"dlgSecCont\">"; | |
cbe50c80 | 42 | |
21295a52 | 43 | print "<table cellspacing=\"0\">"; |
cbe50c80 | 44 | |
21295a52 AD |
45 | print "<tr><td>".__("Foreground:")."</td><td>".__("Background:"). |
46 | "</td></tr>"; | |
cbe50c80 | 47 | |
21295a52 | 48 | print "<tr><td style='padding-right : 10px'>"; |
cbe50c80 | 49 | |
21295a52 | 50 | print "<input dojoType=\"dijit.form.TextBox\" |
cbe50c80 AD |
51 | style=\"display : none\" id=\"labelEdit_fgColor\" |
52 | name=\"fg_color\" value=\"$fg_color\">"; | |
21295a52 | 53 | print "<input dojoType=\"dijit.form.TextBox\" |
cbe50c80 AD |
54 | style=\"display : none\" id=\"labelEdit_bgColor\" |
55 | name=\"bg_color\" value=\"$bg_color\">"; | |
56 | ||
21295a52 | 57 | print "<div dojoType=\"dijit.ColorPalette\"> |
cbe50c80 AD |
58 | <script type=\"dojo/method\" event=\"onChange\" args=\"fg_color\"> |
59 | dijit.byId(\"labelEdit_fgColor\").attr('value', fg_color); | |
60 | $('label-editor-indicator').setStyle({color: fg_color}); | |
61 | </script> | |
21295a52 AD |
62 | </div>"; |
63 | print "</div>"; | |
cbe50c80 | 64 | |
21295a52 | 65 | print "</td><td>"; |
cbe50c80 | 66 | |
21295a52 | 67 | print "<div dojoType=\"dijit.ColorPalette\"> |
cbe50c80 AD |
68 | <script type=\"dojo/method\" event=\"onChange\" args=\"bg_color\"> |
69 | dijit.byId(\"labelEdit_bgColor\").attr('value', bg_color); | |
70 | $('label-editor-indicator').setStyle({backgroundColor: bg_color}); | |
71 | </script> | |
21295a52 AD |
72 | </div>"; |
73 | print "</div>"; | |
cbe50c80 | 74 | |
21295a52 AD |
75 | print "</td></tr></table>"; |
76 | print "</div>"; | |
cbe50c80 AD |
77 | |
78 | # print "</form>"; | |
79 | ||
21295a52 | 80 | print "<div class=\"dlgButtons\">"; |
6fb5ce5e | 81 | print "<button dojoType=\"dijit.form.Button\" type=\"submit\" class=\"btn-primary\" onclick=\"dijit.byId('labelEditDlg').execute()\">". |
21295a52 AD |
82 | __('Save')."</button>"; |
83 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelEditDlg').hide()\">". | |
84 | __('Cancel')."</button>"; | |
85 | print "</div>"; | |
5f7be995 AD |
86 | |
87 | print "</form>"; | |
21295a52 | 88 | } |
cbe50c80 AD |
89 | } |
90 | ||
91 | function getlabeltree() { | |
92 | $root = array(); | |
93 | $root['id'] = 'root'; | |
94 | $root['name'] = __('Labels'); | |
95 | $root['items'] = array(); | |
96 | ||
21295a52 | 97 | $sth = $this->pdo->prepare("SELECT * |
cbe50c80 | 98 | FROM ttrss_labels2 |
21295a52 | 99 | WHERE owner_uid = ? |
cbe50c80 | 100 | ORDER BY caption"); |
21295a52 | 101 | $sth->execute([$_SESSION['uid']]); |
cbe50c80 | 102 | |
21295a52 | 103 | while ($line = $sth->fetch()) { |
cbe50c80 AD |
104 | $label = array(); |
105 | $label['id'] = 'LABEL:' . $line['id']; | |
106 | $label['bare_id'] = $line['id']; | |
107 | $label['name'] = $line['caption']; | |
108 | $label['fg_color'] = $line['fg_color']; | |
109 | $label['bg_color'] = $line['bg_color']; | |
110 | $label['type'] = 'label'; | |
111 | $label['checkbox'] = false; | |
112 | ||
113 | array_push($root['items'], $label); | |
114 | } | |
115 | ||
116 | $fl = array(); | |
117 | $fl['identifier'] = 'id'; | |
118 | $fl['label'] = 'name'; | |
119 | $fl['items'] = array($root); | |
120 | ||
121 | print json_encode($fl); | |
122 | return; | |
123 | } | |
124 | ||
125 | function colorset() { | |
e6532439 AD |
126 | $kind = clean($_REQUEST["kind"]); |
127 | $ids = explode(',', clean($_REQUEST["ids"])); | |
128 | $color = clean($_REQUEST["color"]); | |
129 | $fg = clean($_REQUEST["fg"]); | |
130 | $bg = clean($_REQUEST["bg"]); | |
cbe50c80 AD |
131 | |
132 | foreach ($ids as $id) { | |
133 | ||
134 | if ($kind == "fg" || $kind == "bg") { | |
21295a52 AD |
135 | $sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET |
136 | ${kind}_color = ? WHERE id = ? | |
137 | AND owner_uid = ?"); | |
138 | ||
139 | $sth->execute([$color, $id, $_SESSION['uid']]); | |
140 | ||
cbe50c80 | 141 | } else { |
21295a52 AD |
142 | |
143 | $sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET | |
144 | fg_color = ?, bg_color = ? WHERE id = ? | |
145 | AND owner_uid = ?"); | |
146 | ||
147 | $sth->execute([$fg, $bg, $id, $_SESSION['uid']]); | |
cbe50c80 AD |
148 | } |
149 | ||
21295a52 | 150 | $caption = Labels::find_caption($id, $_SESSION["uid"]); |
cbe50c80 AD |
151 | |
152 | /* Remove cached data */ | |
153 | ||
21295a52 AD |
154 | $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET label_cache = '' |
155 | WHERE label_cache LIKE ? AND owner_uid = ?"); | |
156 | $sth->execute(["%$caption%", $_SESSION['uid']]); | |
cbe50c80 | 157 | } |
cbe50c80 AD |
158 | } |
159 | ||
160 | function colorreset() { | |
e6532439 | 161 | $ids = explode(',', clean($_REQUEST["ids"])); |
cbe50c80 AD |
162 | |
163 | foreach ($ids as $id) { | |
21295a52 AD |
164 | $sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET |
165 | fg_color = '', bg_color = '' WHERE id = ? | |
166 | AND owner_uid = ?"); | |
167 | $sth->execute([$id, $_SESSION['uid']]); | |
cbe50c80 | 168 | |
21295a52 | 169 | $caption = Labels::find_caption($id, $_SESSION["uid"]); |
cbe50c80 AD |
170 | |
171 | /* Remove cached data */ | |
172 | ||
21295a52 AD |
173 | $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET label_cache = '' |
174 | WHERE label_cache LIKE ? AND owner_uid = ?"); | |
175 | $sth->execute(["%$caption%", $_SESSION['uid']]); | |
cbe50c80 | 176 | } |
cbe50c80 AD |
177 | } |
178 | ||
179 | function save() { | |
180 | ||
e6532439 AD |
181 | $id = clean($_REQUEST["id"]); |
182 | $caption = trim(clean($_REQUEST["caption"])); | |
cbe50c80 | 183 | |
21295a52 | 184 | $this->pdo->beginTransaction(); |
cbe50c80 | 185 | |
21295a52 AD |
186 | $sth = $this->pdo->prepare("SELECT caption FROM ttrss_labels2 |
187 | WHERE id = ? AND owner_uid = ?"); | |
188 | $sth->execute([$id, $_SESSION['uid']]); | |
cbe50c80 | 189 | |
21295a52 AD |
190 | if ($row = $sth->fetch()) { |
191 | $old_caption = $row["caption"]; | |
cbe50c80 | 192 | |
21295a52 AD |
193 | $sth = $this->pdo->prepare("SELECT id FROM ttrss_labels2 |
194 | WHERE caption = ? AND owner_uid = ?"); | |
195 | $sth->execute([$caption, $_SESSION['uid']]); | |
cbe50c80 | 196 | |
21295a52 | 197 | if (!$sth->fetch()) { |
cbe50c80 | 198 | if ($caption) { |
21295a52 AD |
199 | $sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET |
200 | caption = ? WHERE id = ? AND | |
201 | owner_uid = ?"); | |
202 | $sth->execute([$caption, $id, $_SESSION['uid']]); | |
cbe50c80 AD |
203 | |
204 | /* Update filters that reference label being renamed */ | |
205 | ||
21295a52 AD |
206 | $sth = $this->pdo->prepare("UPDATE ttrss_filters2_actions SET |
207 | action_param = ? WHERE action_param = ? | |
cbe50c80 | 208 | AND action_id = 7 |
21295a52 AD |
209 | AND filter_id IN (SELECT id FROM ttrss_filters2 WHERE owner_uid = ?)"); |
210 | ||
211 | $sth->execute([$caption, $old_caption, $_SESSION['uid']]); | |
cbe50c80 | 212 | |
e6532439 | 213 | print clean($_REQUEST["value"]); |
cbe50c80 AD |
214 | } else { |
215 | print $old_caption; | |
216 | } | |
217 | } else { | |
218 | print $old_caption; | |
219 | } | |
220 | } | |
221 | ||
21295a52 | 222 | $this->pdo->commit(); |
cbe50c80 | 223 | |
cbe50c80 AD |
224 | } |
225 | ||
226 | function remove() { | |
227 | ||
e6532439 | 228 | $ids = explode(",", clean($_REQUEST["ids"])); |
cbe50c80 AD |
229 | |
230 | foreach ($ids as $id) { | |
7c9b5a3f | 231 | Labels::remove($id, $_SESSION["uid"]); |
cbe50c80 AD |
232 | } |
233 | ||
234 | } | |
235 | ||
236 | function add() { | |
e6532439 AD |
237 | $caption = clean($_REQUEST["caption"]); |
238 | $output = clean($_REQUEST["output"]); | |
cbe50c80 AD |
239 | |
240 | if ($caption) { | |
241 | ||
7c9b5a3f | 242 | if (Labels::create($caption)) { |
cbe50c80 AD |
243 | if (!$output) { |
244 | print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption)); | |
245 | } | |
246 | } | |
247 | ||
248 | if ($output == "select") { | |
249 | header("Content-Type: text/xml"); | |
250 | ||
251 | print "<rpc-reply><payload>"; | |
252 | ||
a42c55f0 | 253 | print_label_select("select_label", |
cbe50c80 AD |
254 | $caption, ""); |
255 | ||
256 | print "</payload></rpc-reply>"; | |
257 | } | |
258 | } | |
259 | ||
260 | return; | |
261 | } | |
262 | ||
263 | function index() { | |
264 | ||
cbe50c80 AD |
265 | print "<div id=\"pref-label-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">"; |
266 | print "<div id=\"pref-label-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">"; | |
267 | print "<div id=\"pref-label-toolbar\" dojoType=\"dijit.Toolbar\">"; | |
268 | ||
269 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
270 | "<span>" . __('Select')."</span>"; | |
271 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
272 | print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(true)\" | |
273 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
274 | print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(false)\" | |
275 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
276 | print "</div></div>"; | |
277 | ||
278 | print"<button dojoType=\"dijit.form.Button\" onclick=\"return addLabel()\">". | |
279 | __('Create label')."</button dojoType=\"dijit.form.Button\"> "; | |
280 | ||
281 | print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedLabels()\">". | |
282 | __('Remove')."</button dojoType=\"dijit.form.Button\"> "; | |
283 | ||
284 | print "<button dojoType=\"dijit.form.Button\" onclick=\"labelColorReset()\">". | |
285 | __('Clear colors')."</button dojoType=\"dijit.form.Button\">"; | |
286 | ||
287 | ||
288 | print "</div>"; #toolbar | |
289 | print "</div>"; #pane | |
290 | print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">"; | |
291 | ||
292 | print "<div id=\"labellistLoading\"> | |
293 | <img src='images/indicator_tiny.gif'>". | |
294 | __("Loading, please wait...")."</div>"; | |
295 | ||
296 | print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"labelStore\" | |
297 | url=\"backend.php?op=pref-labels&method=getlabeltree\"> | |
298 | </div> | |
299 | <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"labelModel\" store=\"labelStore\" | |
300 | query=\"{id:'root'}\" rootId=\"root\" | |
301 | childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\"> | |
302 | </div> | |
303 | <div dojoType=\"fox.PrefLabelTree\" id=\"labelTree\" | |
304 | model=\"labelModel\" openOnClick=\"true\"> | |
305 | <script type=\"dojo/method\" event=\"onLoad\" args=\"item\"> | |
306 | Element.hide(\"labellistLoading\"); | |
307 | </script> | |
308 | <script type=\"dojo/method\" event=\"onClick\" args=\"item\"> | |
309 | var id = String(item.id); | |
310 | var bare_id = id.substr(id.indexOf(':')+1); | |
311 | ||
312 | if (id.match('LABEL:')) { | |
313 | editLabel(bare_id); | |
314 | } | |
315 | </script> | |
316 | </div>"; | |
317 | ||
318 | print "</div>"; #pane | |
6065f3ad | 319 | |
1ffe3391 | 320 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
6065f3ad AD |
321 | "hook_prefs_tab", "prefLabels"); |
322 | ||
cbe50c80 AD |
323 | print "</div>"; #container |
324 | ||
325 | } | |
ea79a0e0 | 326 | } |