]>
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 = $this->dbh
->escape_string($_REQUEST['id']);
13 $result = $this->dbh
->query("SELECT * FROM ttrss_labels2 WHERE
14 id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
16 $line = $this->dbh
->fetch_assoc($result);
18 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$label_id\">";
19 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-labels\">";
20 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"save\">";
22 print "<div class=\"dlgSec\">".__("Caption")."</div>";
24 print "<div class=\"dlgSecCont\">";
26 $fg_color = $line['fg_color'];
27 $bg_color = $line['bg_color'];
29 print "<span class=\"labelColorIndicator\" id=\"label-editor-indicator\" style='color : $fg_color; background-color : $bg_color; margin-bottom : 4px; margin-right : 4px'>α</span>";
31 print "<input style=\"font-size : 16px\" name=\"caption\"
32 dojoType=\"dijit.form.ValidationTextBox\"
34 value=\"".htmlspecialchars($line['caption'])."\">";
37 print "<div class=\"dlgSec\">" . __("Colors") . "</div>";
38 print "<div class=\"dlgSecCont\">";
40 print "<table cellspacing=\"0\">";
42 print "<tr><td>".__("Foreground:")."</td><td>".__("Background:").
45 print "<tr><td style='padding-right : 10px'>";
47 print "<input dojoType=\"dijit.form.TextBox\"
48 style=\"display : none\" id=\"labelEdit_fgColor\"
49 name=\"fg_color\" value=\"$fg_color\">";
50 print "<input dojoType=\"dijit.form.TextBox\"
51 style=\"display : none\" id=\"labelEdit_bgColor\"
52 name=\"bg_color\" value=\"$bg_color\">";
54 print "<div dojoType=\"dijit.ColorPalette\">
55 <script type=\"dojo/method\" event=\"onChange\" args=\"fg_color\">
56 dijit.byId(\"labelEdit_fgColor\").attr('value', fg_color);
57 $('label-editor-indicator').setStyle({color: fg_color});
64 print "<div dojoType=\"dijit.ColorPalette\">
65 <script type=\"dojo/method\" event=\"onChange\" args=\"bg_color\">
66 dijit.byId(\"labelEdit_bgColor\").attr('value', bg_color);
67 $('label-editor-indicator').setStyle({backgroundColor: bg_color});
72 print "</td></tr></table>";
77 print "<div class=\"dlgButtons\">";
78 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelEditDlg').execute()\">".
79 __('Save')."</button>";
80 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelEditDlg').hide()\">".
81 __('Cancel')."</button>";
87 function getlabeltree() {
90 $root['name'] = __('Labels');
91 $root['items'] = array();
93 $result = $this->dbh
->query("SELECT *
95 WHERE owner_uid = ".$_SESSION["uid"]."
98 while ($line = $this->dbh
->fetch_assoc($result)) {
100 $label['id'] = 'LABEL:' . $line['id'];
101 $label['bare_id'] = $line['id'];
102 $label['name'] = $line['caption'];
103 $label['fg_color'] = $line['fg_color'];
104 $label['bg_color'] = $line['bg_color'];
105 $label['type'] = 'label';
106 $label['checkbox'] = false;
108 array_push($root['items'], $label);
112 $fl['identifier'] = 'id';
113 $fl['label'] = 'name';
114 $fl['items'] = array($root);
116 print json_encode($fl);
120 function colorset() {
121 $kind = $this->dbh
->escape_string($_REQUEST["kind"]);
122 $ids = explode(',', $this->dbh
->escape_string($_REQUEST["ids"]));
123 $color = $this->dbh
->escape_string($_REQUEST["color"]);
124 $fg = $this->dbh
->escape_string($_REQUEST["fg"]);
125 $bg = $this->dbh
->escape_string($_REQUEST["bg"]);
127 foreach ($ids as $id) {
129 if ($kind == "fg" ||
$kind == "bg") {
130 $this->dbh
->query("UPDATE ttrss_labels2 SET
131 ${kind}_color = '$color' WHERE id = '$id'
132 AND owner_uid = " . $_SESSION["uid"]);
134 $this->dbh
->query("UPDATE ttrss_labels2 SET
135 fg_color = '$fg', bg_color = '$bg' WHERE id = '$id'
136 AND owner_uid = " . $_SESSION["uid"]);
139 $caption = $this->dbh
->escape_string(label_find_caption($id, $_SESSION["uid"]));
141 /* Remove cached data */
143 $this->dbh
->query("UPDATE ttrss_user_entries SET label_cache = ''
144 WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
151 function colorreset() {
152 $ids = explode(',', $this->dbh
->escape_string($_REQUEST["ids"]));
154 foreach ($ids as $id) {
155 $this->dbh
->query("UPDATE ttrss_labels2 SET
156 fg_color = '', bg_color = '' WHERE id = '$id'
157 AND owner_uid = " . $_SESSION["uid"]);
159 $caption = $this->dbh
->escape_string(label_find_caption($id, $_SESSION["uid"]));
161 /* Remove cached data */
163 $this->dbh
->query("UPDATE ttrss_user_entries SET label_cache = ''
164 WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
171 $id = $this->dbh
->escape_string($_REQUEST["id"]);
172 $caption = $this->dbh
->escape_string(trim($_REQUEST["caption"]));
174 $this->dbh
->query("BEGIN");
176 $result = $this->dbh
->query("SELECT caption FROM ttrss_labels2
177 WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
179 if ($this->dbh
->num_rows($result) != 0) {
180 $old_caption = $this->dbh
->fetch_result($result, 0, "caption");
182 $result = $this->dbh
->query("SELECT id FROM ttrss_labels2
183 WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]);
185 if ($this->dbh
->num_rows($result) == 0) {
187 $result = $this->dbh
->query("UPDATE ttrss_labels2 SET
188 caption = '$caption' WHERE id = '$id' AND
189 owner_uid = " . $_SESSION["uid"]);
191 /* Update filters that reference label being renamed */
193 $old_caption = $this->dbh
->escape_string($old_caption);
195 $this->dbh
->query("UPDATE ttrss_filters2_actions SET
196 action_param = '$caption' WHERE action_param = '$old_caption'
198 AND filter_id IN (SELECT id FROM ttrss_filters2 WHERE owner_uid = ".$_SESSION["uid"].")");
200 print $_REQUEST["value"];
209 $this->dbh
->query("COMMIT");
216 $ids = explode(",", $this->dbh
->escape_string($_REQUEST["ids"]));
218 foreach ($ids as $id) {
219 label_remove($id, $_SESSION["uid"]);
225 $caption = $this->dbh
->escape_string($_REQUEST["caption"]);
226 $output = $this->dbh
->escape_string($_REQUEST["output"]);
230 if (label_create($caption)) {
232 print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
236 if ($output == "select") {
237 header("Content-Type: text/xml");
239 print "<rpc-reply><payload>";
241 print_label_select("select_label",
244 print "</payload></rpc-reply>";
253 $sort = $this->dbh
->escape_string($_REQUEST["sort"]);
255 if (!$sort ||
$sort == "undefined") {
259 $label_search = $this->dbh
->escape_string($_REQUEST["search"]);
261 if (array_key_exists("search", $_REQUEST)) {
262 $_SESSION["prefs_label_search"] = $label_search;
264 $label_search = $_SESSION["prefs_label_search"];
267 print "<div id=\"pref-label-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
268 print "<div id=\"pref-label-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
269 print "<div id=\"pref-label-toolbar\" dojoType=\"dijit.Toolbar\">";
271 print "<div dojoType=\"dijit.form.DropDownButton\">".
272 "<span>" . __('Select')."</span>";
273 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
274 print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(true)\"
275 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
276 print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(false)\"
277 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
278 print "</div></div>";
280 print"<button dojoType=\"dijit.form.Button\" onclick=\"return addLabel()\">".
281 __('Create label')."</button dojoType=\"dijit.form.Button\"> ";
283 print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedLabels()\">".
284 __('Remove')."</button dojoType=\"dijit.form.Button\"> ";
286 print "<button dojoType=\"dijit.form.Button\" onclick=\"labelColorReset()\">".
287 __('Clear colors')."</button dojoType=\"dijit.form.Button\">";
290 print "</div>"; #toolbar
291 print "</div>"; #pane
292 print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
294 print "<div id=\"labellistLoading\">
295 <img src='images/indicator_tiny.gif'>".
296 __("Loading, please wait...")."</div>";
298 print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"labelStore\"
299 url=\"backend.php?op=pref-labels&method=getlabeltree\">
301 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"labelModel\" store=\"labelStore\"
302 query=\"{id:'root'}\" rootId=\"root\"
303 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
305 <div dojoType=\"fox.PrefLabelTree\" id=\"labelTree\"
306 model=\"labelModel\" openOnClick=\"true\">
307 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
308 Element.hide(\"labellistLoading\");
310 <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
311 var id = String(item.id);
312 var bare_id = id.substr(id.indexOf(':')+1);
314 if (id.match('LABEL:')) {
320 print "</div>"; #pane
322 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_PREFS_TAB
,
323 "hook_prefs_tab", "prefLabels");
325 print "</div>"; #container