]>
git.wh0rd.org - tt-rss.git/blob - classes/pref/labels.php
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 = $_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 "<div class=\"dlgSec\">".__("Caption")."</div>";
25 print "<div class=\"dlgSecCont\">";
27 $fg_color = $line['fg_color'];
28 $bg_color = $line['bg_color'];
30 print "<span class=\"labelColorIndicator\" id=\"label-editor-indicator\" style='color : $fg_color; background-color : $bg_color; margin-bottom : 4px; margin-right : 4px'>α</span>";
32 print "<input style=\"font-size : 16px\" name=\"caption\"
33 dojoType=\"dijit.form.ValidationTextBox\"
35 value=\"".htmlspecialchars($line['caption'])."\">";
38 print "<div class=\"dlgSec\">" . __("Colors") . "</div>";
39 print "<div class=\"dlgSecCont\">";
41 print "<table cellspacing=\"0\">";
43 print "<tr><td>".__("Foreground:")."</td><td>".__("Background:").
46 print "<tr><td style='padding-right : 10px'>";
48 print "<input dojoType=\"dijit.form.TextBox\"
49 style=\"display : none\" id=\"labelEdit_fgColor\"
50 name=\"fg_color\" value=\"$fg_color\">";
51 print "<input dojoType=\"dijit.form.TextBox\"
52 style=\"display : none\" id=\"labelEdit_bgColor\"
53 name=\"bg_color\" value=\"$bg_color\">";
55 print "<div dojoType=\"dijit.ColorPalette\">
56 <script type=\"dojo/method\" event=\"onChange\" args=\"fg_color\">
57 dijit.byId(\"labelEdit_fgColor\").attr('value', fg_color);
58 $('label-editor-indicator').setStyle({color: fg_color});
65 print "<div dojoType=\"dijit.ColorPalette\">
66 <script type=\"dojo/method\" event=\"onChange\" args=\"bg_color\">
67 dijit.byId(\"labelEdit_bgColor\").attr('value', bg_color);
68 $('label-editor-indicator').setStyle({backgroundColor: bg_color});
73 print "</td></tr></table>";
78 print "<div class=\"dlgButtons\">";
79 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelEditDlg').execute()\">".
80 __('Save')."</button>";
81 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelEditDlg').hide()\">".
82 __('Cancel')."</button>";
87 function getlabeltree() {
90 $root['name'] = __('Labels');
91 $root['items'] = array();
93 $sth = $this->pdo
->prepare("SELECT *
97 $sth->execute([$_SESSION['uid']]);
99 while ($line = $sth->fetch()) {
101 $label['id'] = 'LABEL:' . $line['id'];
102 $label['bare_id'] = $line['id'];
103 $label['name'] = $line['caption'];
104 $label['fg_color'] = $line['fg_color'];
105 $label['bg_color'] = $line['bg_color'];
106 $label['type'] = 'label';
107 $label['checkbox'] = false;
109 array_push($root['items'], $label);
113 $fl['identifier'] = 'id';
114 $fl['label'] = 'name';
115 $fl['items'] = array($root);
117 print json_encode($fl);
121 function colorset() {
122 $kind = $_REQUEST["kind"];
123 $ids = explode(',', $_REQUEST["ids"]);
124 $color = $_REQUEST["color"];
125 $fg = $_REQUEST["fg"];
126 $bg = $_REQUEST["bg"];
128 foreach ($ids as $id) {
130 if ($kind == "fg" ||
$kind == "bg") {
131 $sth = $this->pdo
->prepare("UPDATE ttrss_labels2 SET
132 ${kind}_color = ? WHERE id = ?
135 $sth->execute([$color, $id, $_SESSION['uid']]);
139 $sth = $this->pdo
->prepare("UPDATE ttrss_labels2 SET
140 fg_color = ?, bg_color = ? WHERE id = ?
143 $sth->execute([$fg, $bg, $id, $_SESSION['uid']]);
146 $caption = Labels
::find_caption($id, $_SESSION["uid"]);
148 /* Remove cached data */
150 $sth = $this->pdo
->prepare("UPDATE ttrss_user_entries SET label_cache = ''
151 WHERE label_cache LIKE ? AND owner_uid = ?");
152 $sth->execute(["%$caption%", $_SESSION['uid']]);
156 function colorreset() {
157 $ids = explode(',', $_REQUEST["ids"]);
159 foreach ($ids as $id) {
160 $sth = $this->pdo
->prepare("UPDATE ttrss_labels2 SET
161 fg_color = '', bg_color = '' WHERE id = ?
163 $sth->execute([$id, $_SESSION['uid']]);
165 $caption = Labels
::find_caption($id, $_SESSION["uid"]);
167 /* Remove cached data */
169 $sth = $this->pdo
->prepare("UPDATE ttrss_user_entries SET label_cache = ''
170 WHERE label_cache LIKE ? AND owner_uid = ?");
171 $sth->execute(["%$caption%", $_SESSION['uid']]);
177 $id = $_REQUEST["id"];
178 $caption = trim($_REQUEST["caption"]);
180 $this->pdo
->beginTransaction();
182 $sth = $this->pdo
->prepare("SELECT caption FROM ttrss_labels2
183 WHERE id = ? AND owner_uid = ?");
184 $sth->execute([$id, $_SESSION['uid']]);
186 if ($row = $sth->fetch()) {
187 $old_caption = $row["caption"];
189 $sth = $this->pdo
->prepare("SELECT id FROM ttrss_labels2
190 WHERE caption = ? AND owner_uid = ?");
191 $sth->execute([$caption, $_SESSION['uid']]);
193 if (!$sth->fetch()) {
195 $sth = $this->pdo
->prepare("UPDATE ttrss_labels2 SET
196 caption = ? WHERE id = ? AND
198 $sth->execute([$caption, $id, $_SESSION['uid']]);
200 /* Update filters that reference label being renamed */
202 $sth = $this->pdo
->prepare("UPDATE ttrss_filters2_actions SET
203 action_param = ? WHERE action_param = ?
205 AND filter_id IN (SELECT id FROM ttrss_filters2 WHERE owner_uid = ?)");
207 $sth->execute([$caption, $old_caption, $_SESSION['uid']]);
209 print $_REQUEST["value"];
218 $this->pdo
->commit();
224 $ids = explode(",", $_REQUEST["ids"]);
226 foreach ($ids as $id) {
227 Labels
::remove($id, $_SESSION["uid"]);
233 $caption = $_REQUEST["caption"];
234 $output = $_REQUEST["output"];
238 if (Labels
::create($caption)) {
240 print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
244 if ($output == "select") {
245 header("Content-Type: text/xml");
247 print "<rpc-reply><payload>";
249 print_label_select("select_label",
252 print "</payload></rpc-reply>";
261 print "<div id=\"pref-label-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
262 print "<div id=\"pref-label-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
263 print "<div id=\"pref-label-toolbar\" dojoType=\"dijit.Toolbar\">";
265 print "<div dojoType=\"dijit.form.DropDownButton\">".
266 "<span>" . __('Select')."</span>";
267 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
268 print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(true)\"
269 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
270 print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(false)\"
271 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
272 print "</div></div>";
274 print"<button dojoType=\"dijit.form.Button\" onclick=\"return addLabel()\">".
275 __('Create label')."</button dojoType=\"dijit.form.Button\"> ";
277 print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedLabels()\">".
278 __('Remove')."</button dojoType=\"dijit.form.Button\"> ";
280 print "<button dojoType=\"dijit.form.Button\" onclick=\"labelColorReset()\">".
281 __('Clear colors')."</button dojoType=\"dijit.form.Button\">";
284 print "</div>"; #toolbar
285 print "</div>"; #pane
286 print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
288 print "<div id=\"labellistLoading\">
289 <img src='images/indicator_tiny.gif'>".
290 __("Loading, please wait...")."</div>";
292 print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"labelStore\"
293 url=\"backend.php?op=pref-labels&method=getlabeltree\">
295 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"labelModel\" store=\"labelStore\"
296 query=\"{id:'root'}\" rootId=\"root\"
297 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
299 <div dojoType=\"fox.PrefLabelTree\" id=\"labelTree\"
300 model=\"labelModel\" openOnClick=\"true\">
301 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
302 Element.hide(\"labellistLoading\");
304 <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
305 var id = String(item.id);
306 var bare_id = id.substr(id.indexOf(':')+1);
308 if (id.match('LABEL:')) {
314 print "</div>"; #pane
316 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_PREFS_TAB
,
317 "hook_prefs_tab", "prefLabels");
319 print "</div>"; #container