]>
git.wh0rd.org - tt-rss.git/blob - classes/pref/labels.php
5720a1f4b8303ebfd5a9fec940303356e0e1f787
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_hidden("id", "$label_id");
19 print_hidden("op", "pref-labels");
20 print_hidden("method", "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(Labels
::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(Labels
::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 Labels
::remove($id, $_SESSION["uid"]);
225 $caption = $this->dbh
->escape_string($_REQUEST["caption"]);
226 $output = $this->dbh
->escape_string($_REQUEST["output"]);
230 if (Labels
::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 print "<div id=\"pref-label-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
254 print "<div id=\"pref-label-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
255 print "<div id=\"pref-label-toolbar\" dojoType=\"dijit.Toolbar\">";
257 print "<div dojoType=\"dijit.form.DropDownButton\">".
258 "<span>" . __('Select')."</span>";
259 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
260 print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(true)\"
261 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
262 print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(false)\"
263 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
264 print "</div></div>";
266 print"<button dojoType=\"dijit.form.Button\" onclick=\"return addLabel()\">".
267 __('Create label')."</button dojoType=\"dijit.form.Button\"> ";
269 print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedLabels()\">".
270 __('Remove')."</button dojoType=\"dijit.form.Button\"> ";
272 print "<button dojoType=\"dijit.form.Button\" onclick=\"labelColorReset()\">".
273 __('Clear colors')."</button dojoType=\"dijit.form.Button\">";
276 print "</div>"; #toolbar
277 print "</div>"; #pane
278 print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
280 print "<div id=\"labellistLoading\">
281 <img src='images/indicator_tiny.gif'>".
282 __("Loading, please wait...")."</div>";
284 print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"labelStore\"
285 url=\"backend.php?op=pref-labels&method=getlabeltree\">
287 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"labelModel\" store=\"labelStore\"
288 query=\"{id:'root'}\" rootId=\"root\"
289 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
291 <div dojoType=\"fox.PrefLabelTree\" id=\"labelTree\"
292 model=\"labelModel\" openOnClick=\"true\">
293 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
294 Element.hide(\"labellistLoading\");
296 <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
297 var id = String(item.id);
298 var bare_id = id.substr(id.indexOf(':')+1);
300 if (id.match('LABEL:')) {
306 print "</div>"; #pane
308 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_PREFS_TAB
,
309 "hook_prefs_tab", "prefLabels");
311 print "</div>"; #container