]>
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() { |
d9c85e0f | 11 | $label_id = $this->dbh->escape_string($_REQUEST['id']); |
cbe50c80 | 12 | |
d9c85e0f | 13 | $result = $this->dbh->query("SELECT * FROM ttrss_labels2 WHERE |
cbe50c80 AD |
14 | id = '$label_id' AND owner_uid = " . $_SESSION["uid"]); |
15 | ||
d9c85e0f | 16 | $line = $this->dbh->fetch_assoc($result); |
cbe50c80 | 17 | |
328118d1 AD |
18 | print_hidden("id", "$label_id"); |
19 | print_hidden("op", "pref-labels"); | |
20 | print_hidden("method", "save"); | |
cbe50c80 AD |
21 | |
22 | print "<div class=\"dlgSec\">".__("Caption")."</div>"; | |
23 | ||
24 | print "<div class=\"dlgSecCont\">"; | |
25 | ||
26 | $fg_color = $line['fg_color']; | |
27 | $bg_color = $line['bg_color']; | |
28 | ||
29 | print "<span class=\"labelColorIndicator\" id=\"label-editor-indicator\" style='color : $fg_color; background-color : $bg_color; margin-bottom : 4px; margin-right : 4px'>α</span>"; | |
30 | ||
31 | print "<input style=\"font-size : 16px\" name=\"caption\" | |
32 | dojoType=\"dijit.form.ValidationTextBox\" | |
33 | required=\"true\" | |
34 | value=\"".htmlspecialchars($line['caption'])."\">"; | |
35 | ||
36 | print "</div>"; | |
37 | print "<div class=\"dlgSec\">" . __("Colors") . "</div>"; | |
38 | print "<div class=\"dlgSecCont\">"; | |
39 | ||
40 | print "<table cellspacing=\"0\">"; | |
41 | ||
42 | print "<tr><td>".__("Foreground:")."</td><td>".__("Background:"). | |
43 | "</td></tr>"; | |
44 | ||
45 | print "<tr><td style='padding-right : 10px'>"; | |
46 | ||
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\">"; | |
53 | ||
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}); | |
58 | </script> | |
59 | </div>"; | |
60 | print "</div>"; | |
61 | ||
62 | print "</td><td>"; | |
63 | ||
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}); | |
68 | </script> | |
69 | </div>"; | |
70 | print "</div>"; | |
71 | ||
72 | print "</td></tr></table>"; | |
73 | print "</div>"; | |
74 | ||
75 | # print "</form>"; | |
76 | ||
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>"; | |
82 | print "</div>"; | |
83 | ||
84 | return; | |
85 | } | |
86 | ||
87 | function getlabeltree() { | |
88 | $root = array(); | |
89 | $root['id'] = 'root'; | |
90 | $root['name'] = __('Labels'); | |
91 | $root['items'] = array(); | |
92 | ||
d9c85e0f | 93 | $result = $this->dbh->query("SELECT * |
cbe50c80 AD |
94 | FROM ttrss_labels2 |
95 | WHERE owner_uid = ".$_SESSION["uid"]." | |
96 | ORDER BY caption"); | |
97 | ||
d9c85e0f | 98 | while ($line = $this->dbh->fetch_assoc($result)) { |
cbe50c80 AD |
99 | $label = array(); |
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; | |
107 | ||
108 | array_push($root['items'], $label); | |
109 | } | |
110 | ||
111 | $fl = array(); | |
112 | $fl['identifier'] = 'id'; | |
113 | $fl['label'] = 'name'; | |
114 | $fl['items'] = array($root); | |
115 | ||
116 | print json_encode($fl); | |
117 | return; | |
118 | } | |
119 | ||
120 | function colorset() { | |
d9c85e0f AD |
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"]); | |
cbe50c80 AD |
126 | |
127 | foreach ($ids as $id) { | |
128 | ||
129 | if ($kind == "fg" || $kind == "bg") { | |
d9c85e0f | 130 | $this->dbh->query("UPDATE ttrss_labels2 SET |
cbe50c80 AD |
131 | ${kind}_color = '$color' WHERE id = '$id' |
132 | AND owner_uid = " . $_SESSION["uid"]); | |
133 | } else { | |
d9c85e0f | 134 | $this->dbh->query("UPDATE ttrss_labels2 SET |
cbe50c80 AD |
135 | fg_color = '$fg', bg_color = '$bg' WHERE id = '$id' |
136 | AND owner_uid = " . $_SESSION["uid"]); | |
137 | } | |
138 | ||
d9c85e0f | 139 | $caption = $this->dbh->escape_string(label_find_caption($id, $_SESSION["uid"])); |
cbe50c80 AD |
140 | |
141 | /* Remove cached data */ | |
142 | ||
d9c85e0f | 143 | $this->dbh->query("UPDATE ttrss_user_entries SET label_cache = '' |
cbe50c80 AD |
144 | WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]); |
145 | ||
146 | } | |
147 | ||
148 | return; | |
149 | } | |
150 | ||
151 | function colorreset() { | |
d9c85e0f | 152 | $ids = explode(',', $this->dbh->escape_string($_REQUEST["ids"])); |
cbe50c80 AD |
153 | |
154 | foreach ($ids as $id) { | |
d9c85e0f | 155 | $this->dbh->query("UPDATE ttrss_labels2 SET |
cbe50c80 AD |
156 | fg_color = '', bg_color = '' WHERE id = '$id' |
157 | AND owner_uid = " . $_SESSION["uid"]); | |
158 | ||
d9c85e0f | 159 | $caption = $this->dbh->escape_string(label_find_caption($id, $_SESSION["uid"])); |
cbe50c80 AD |
160 | |
161 | /* Remove cached data */ | |
162 | ||
d9c85e0f | 163 | $this->dbh->query("UPDATE ttrss_user_entries SET label_cache = '' |
cbe50c80 AD |
164 | WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]); |
165 | } | |
166 | ||
167 | } | |
168 | ||
169 | function save() { | |
170 | ||
d9c85e0f AD |
171 | $id = $this->dbh->escape_string($_REQUEST["id"]); |
172 | $caption = $this->dbh->escape_string(trim($_REQUEST["caption"])); | |
cbe50c80 | 173 | |
d9c85e0f | 174 | $this->dbh->query("BEGIN"); |
cbe50c80 | 175 | |
d9c85e0f | 176 | $result = $this->dbh->query("SELECT caption FROM ttrss_labels2 |
cbe50c80 AD |
177 | WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]); |
178 | ||
d9c85e0f AD |
179 | if ($this->dbh->num_rows($result) != 0) { |
180 | $old_caption = $this->dbh->fetch_result($result, 0, "caption"); | |
cbe50c80 | 181 | |
d9c85e0f | 182 | $result = $this->dbh->query("SELECT id FROM ttrss_labels2 |
cbe50c80 AD |
183 | WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]); |
184 | ||
d9c85e0f | 185 | if ($this->dbh->num_rows($result) == 0) { |
cbe50c80 | 186 | if ($caption) { |
d9c85e0f | 187 | $result = $this->dbh->query("UPDATE ttrss_labels2 SET |
cbe50c80 AD |
188 | caption = '$caption' WHERE id = '$id' AND |
189 | owner_uid = " . $_SESSION["uid"]); | |
190 | ||
191 | /* Update filters that reference label being renamed */ | |
192 | ||
d9c85e0f | 193 | $old_caption = $this->dbh->escape_string($old_caption); |
cbe50c80 | 194 | |
d9c85e0f | 195 | $this->dbh->query("UPDATE ttrss_filters2_actions SET |
cbe50c80 AD |
196 | action_param = '$caption' WHERE action_param = '$old_caption' |
197 | AND action_id = 7 | |
6aff7845 | 198 | AND filter_id IN (SELECT id FROM ttrss_filters2 WHERE owner_uid = ".$_SESSION["uid"].")"); |
cbe50c80 AD |
199 | |
200 | print $_REQUEST["value"]; | |
201 | } else { | |
202 | print $old_caption; | |
203 | } | |
204 | } else { | |
205 | print $old_caption; | |
206 | } | |
207 | } | |
208 | ||
d9c85e0f | 209 | $this->dbh->query("COMMIT"); |
cbe50c80 AD |
210 | |
211 | return; | |
212 | } | |
213 | ||
214 | function remove() { | |
215 | ||
d9c85e0f | 216 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); |
cbe50c80 AD |
217 | |
218 | foreach ($ids as $id) { | |
a42c55f0 | 219 | label_remove($id, $_SESSION["uid"]); |
cbe50c80 AD |
220 | } |
221 | ||
222 | } | |
223 | ||
224 | function add() { | |
d9c85e0f AD |
225 | $caption = $this->dbh->escape_string($_REQUEST["caption"]); |
226 | $output = $this->dbh->escape_string($_REQUEST["output"]); | |
cbe50c80 AD |
227 | |
228 | if ($caption) { | |
229 | ||
a42c55f0 | 230 | if (label_create($caption)) { |
cbe50c80 AD |
231 | if (!$output) { |
232 | print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption)); | |
233 | } | |
234 | } | |
235 | ||
236 | if ($output == "select") { | |
237 | header("Content-Type: text/xml"); | |
238 | ||
239 | print "<rpc-reply><payload>"; | |
240 | ||
a42c55f0 | 241 | print_label_select("select_label", |
cbe50c80 AD |
242 | $caption, ""); |
243 | ||
244 | print "</payload></rpc-reply>"; | |
245 | } | |
246 | } | |
247 | ||
248 | return; | |
249 | } | |
250 | ||
251 | function index() { | |
252 | ||
cbe50c80 AD |
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\">"; | |
256 | ||
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>"; | |
265 | ||
266 | print"<button dojoType=\"dijit.form.Button\" onclick=\"return addLabel()\">". | |
267 | __('Create label')."</button dojoType=\"dijit.form.Button\"> "; | |
268 | ||
269 | print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedLabels()\">". | |
270 | __('Remove')."</button dojoType=\"dijit.form.Button\"> "; | |
271 | ||
272 | print "<button dojoType=\"dijit.form.Button\" onclick=\"labelColorReset()\">". | |
273 | __('Clear colors')."</button dojoType=\"dijit.form.Button\">"; | |
274 | ||
275 | ||
276 | print "</div>"; #toolbar | |
277 | print "</div>"; #pane | |
278 | print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">"; | |
279 | ||
280 | print "<div id=\"labellistLoading\"> | |
281 | <img src='images/indicator_tiny.gif'>". | |
282 | __("Loading, please wait...")."</div>"; | |
283 | ||
284 | print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"labelStore\" | |
285 | url=\"backend.php?op=pref-labels&method=getlabeltree\"> | |
286 | </div> | |
287 | <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"labelModel\" store=\"labelStore\" | |
288 | query=\"{id:'root'}\" rootId=\"root\" | |
289 | childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\"> | |
290 | </div> | |
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\"); | |
295 | </script> | |
296 | <script type=\"dojo/method\" event=\"onClick\" args=\"item\"> | |
297 | var id = String(item.id); | |
298 | var bare_id = id.substr(id.indexOf(':')+1); | |
299 | ||
300 | if (id.match('LABEL:')) { | |
301 | editLabel(bare_id); | |
302 | } | |
303 | </script> | |
304 | </div>"; | |
305 | ||
306 | print "</div>"; #pane | |
6065f3ad | 307 | |
1ffe3391 | 308 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
6065f3ad AD |
309 | "hook_prefs_tab", "prefLabels"); |
310 | ||
cbe50c80 AD |
311 | print "</div>"; #container |
312 | ||
313 | } | |
314 | } | |
315 | ||
316 | ?> |