2 class Pref_Labels extends Handler_Protected {
4 function csrf_ignore($method) {
5 $csrf_ignored = array("index", "getlabeltree", "edit");
7 return array_search($method, $csrf_ignored) !== false;
11 $label_id = clean($_REQUEST['id']);
13 $sth = $this->pdo->prepare("SELECT * FROM ttrss_labels2 WHERE
14 id = ? AND owner_uid = ?");
15 $sth->execute([$label_id, $_SESSION['uid']]);
17 if ($line = $sth->fetch()) {
19 print_hidden("id", "$label_id");
20 print_hidden("op", "pref-labels");
21 print_hidden("method", "save");
23 print "<form onsubmit='return false;'>";
25 print "<div class=\"dlgSec\">".__("Caption")."</div>";
27 print "<div class=\"dlgSecCont\">";
29 $fg_color = $line['fg_color'];
30 $bg_color = $line['bg_color'];
32 print "<span class=\"labelColorIndicator\" id=\"label-editor-indicator\" style='color : $fg_color; background-color : $bg_color; margin-bottom : 4px; margin-right : 4px'>α</span>";
34 print "<input style=\"font-size : 16px\" name=\"caption\"
35 dojoType=\"dijit.form.ValidationTextBox\"
37 value=\"".htmlspecialchars($line['caption'])."\">";
40 print "<div class=\"dlgSec\">" . __("Colors") . "</div>";
41 print "<div class=\"dlgSecCont\">";
43 print "<table cellspacing=\"0\">";
45 print "<tr><td>".__("Foreground:")."</td><td>".__("Background:").
48 print "<tr><td style='padding-right : 10px'>";
50 print "<input dojoType=\"dijit.form.TextBox\"
51 style=\"display : none\" id=\"labelEdit_fgColor\"
52 name=\"fg_color\" value=\"$fg_color\">";
53 print "<input dojoType=\"dijit.form.TextBox\"
54 style=\"display : none\" id=\"labelEdit_bgColor\"
55 name=\"bg_color\" value=\"$bg_color\">";
57 print "<div dojoType=\"dijit.ColorPalette\">
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});
67 print "<div dojoType=\"dijit.ColorPalette\">
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});
75 print "</td></tr></table>";
80 print "<div class=\"dlgButtons\">";
81 print "<button dojoType=\"dijit.form.Button\" type=\"submit\" class=\"btn-primary\" onclick=\"dijit.byId('labelEditDlg').execute()\">".
82 __('Save')."</button>";
83 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelEditDlg').hide()\">".
84 __('Cancel')."</button>";
91 function getlabeltree() {
94 $root['name'] = __('Labels');
95 $root['items'] = array();
97 $sth = $this->pdo->prepare("SELECT *
101 $sth->execute([$_SESSION['uid']]);
103 while ($line = $sth->fetch()) {
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;
113 array_push($root['items'], $label);
117 $fl['identifier'] = 'id';
118 $fl['label'] = 'name';
119 $fl['items'] = array($root);
121 print json_encode($fl);
125 function colorset() {
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"]);
132 foreach ($ids as $id) {
134 if ($kind == "fg" || $kind == "bg") {
135 $sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET
136 ${kind}_color = ? WHERE id = ?
139 $sth->execute([$color, $id, $_SESSION['uid']]);
143 $sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET
144 fg_color = ?, bg_color = ? WHERE id = ?
147 $sth->execute([$fg, $bg, $id, $_SESSION['uid']]);
150 $caption = Labels::find_caption($id, $_SESSION["uid"]);
152 /* Remove cached data */
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']]);
160 function colorreset() {
161 $ids = explode(',', clean($_REQUEST["ids"]));
163 foreach ($ids as $id) {
164 $sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET
165 fg_color = '', bg_color = '' WHERE id = ?
167 $sth->execute([$id, $_SESSION['uid']]);
169 $caption = Labels::find_caption($id, $_SESSION["uid"]);
171 /* Remove cached data */
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']]);
181 $id = clean($_REQUEST["id"]);
182 $caption = trim(clean($_REQUEST["caption"]));
184 $this->pdo->beginTransaction();
186 $sth = $this->pdo->prepare("SELECT caption FROM ttrss_labels2
187 WHERE id = ? AND owner_uid = ?");
188 $sth->execute([$id, $_SESSION['uid']]);
190 if ($row = $sth->fetch()) {
191 $old_caption = $row["caption"];
193 $sth = $this->pdo->prepare("SELECT id FROM ttrss_labels2
194 WHERE caption = ? AND owner_uid = ?");
195 $sth->execute([$caption, $_SESSION['uid']]);
197 if (!$sth->fetch()) {
199 $sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET
200 caption = ? WHERE id = ? AND
202 $sth->execute([$caption, $id, $_SESSION['uid']]);
204 /* Update filters that reference label being renamed */
206 $sth = $this->pdo->prepare("UPDATE ttrss_filters2_actions SET
207 action_param = ? WHERE action_param = ?
209 AND filter_id IN (SELECT id FROM ttrss_filters2 WHERE owner_uid = ?)");
211 $sth->execute([$caption, $old_caption, $_SESSION['uid']]);
213 print clean($_REQUEST["value"]);
222 $this->pdo->commit();
228 $ids = explode(",", clean($_REQUEST["ids"]));
230 foreach ($ids as $id) {
231 Labels::remove($id, $_SESSION["uid"]);
237 $caption = clean($_REQUEST["caption"]);
238 $output = clean($_REQUEST["output"]);
242 if (Labels::create($caption)) {
244 print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
248 if ($output == "select") {
249 header("Content-Type: text/xml");
251 print "<rpc-reply><payload>";
253 print_label_select("select_label",
256 print "</payload></rpc-reply>";
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\">";
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>";
278 print"<button dojoType=\"dijit.form.Button\" onclick=\"return addLabel()\">".
279 __('Create label')."</button dojoType=\"dijit.form.Button\"> ";
281 print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedLabels()\">".
282 __('Remove')."</button dojoType=\"dijit.form.Button\"> ";
284 print "<button dojoType=\"dijit.form.Button\" onclick=\"labelColorReset()\">".
285 __('Clear colors')."</button dojoType=\"dijit.form.Button\">";
288 print "</div>"; #toolbar
289 print "</div>"; #pane
290 print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
292 print "<div id=\"labellistLoading\">
293 <img src='images/indicator_tiny.gif'>".
294 __("Loading, please wait...")."</div>";
296 print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"labelStore\"
297 url=\"backend.php?op=pref-labels&method=getlabeltree\">
299 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"labelModel\" store=\"labelStore\"
300 query=\"{id:'root'}\" rootId=\"root\"
301 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
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\");
308 <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
309 var id = String(item.id);
310 var bare_id = id.substr(id.indexOf(':')+1);
312 if (id.match('LABEL:')) {
318 print "</div>"; #pane
320 PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
321 "hook_prefs_tab", "prefLabels");
323 print "</div>"; #container