]>
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() { |
3972bf59 | 11 | $label_id = db_escape_string($this->link, $_REQUEST['id']); |
cbe50c80 AD |
12 | |
13 | $result = db_query($this->link, "SELECT * FROM ttrss_labels2 WHERE | |
14 | id = '$label_id' AND owner_uid = " . $_SESSION["uid"]); | |
15 | ||
16 | $line = db_fetch_assoc($result); | |
17 | ||
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\">"; | |
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 | ||
93 | $result = db_query($this->link, "SELECT * | |
94 | FROM ttrss_labels2 | |
95 | WHERE owner_uid = ".$_SESSION["uid"]." | |
96 | ORDER BY caption"); | |
97 | ||
98 | while ($line = db_fetch_assoc($result)) { | |
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() { | |
3972bf59 AD |
121 | $kind = db_escape_string($this->link, $_REQUEST["kind"]); |
122 | $ids = split(',', db_escape_string($this->link, $_REQUEST["ids"])); | |
123 | $color = db_escape_string($this->link, $_REQUEST["color"]); | |
124 | $fg = db_escape_string($this->link, $_REQUEST["fg"]); | |
125 | $bg = db_escape_string($this->link, $_REQUEST["bg"]); | |
cbe50c80 AD |
126 | |
127 | foreach ($ids as $id) { | |
128 | ||
129 | if ($kind == "fg" || $kind == "bg") { | |
130 | db_query($this->link, "UPDATE ttrss_labels2 SET | |
131 | ${kind}_color = '$color' WHERE id = '$id' | |
132 | AND owner_uid = " . $_SESSION["uid"]); | |
133 | } else { | |
134 | db_query($this->link, "UPDATE ttrss_labels2 SET | |
135 | fg_color = '$fg', bg_color = '$bg' WHERE id = '$id' | |
136 | AND owner_uid = " . $_SESSION["uid"]); | |
137 | } | |
138 | ||
3972bf59 | 139 | $caption = db_escape_string($this->link, label_find_caption($this->link, $id, $_SESSION["uid"])); |
cbe50c80 AD |
140 | |
141 | /* Remove cached data */ | |
142 | ||
143 | db_query($this->link, "UPDATE ttrss_user_entries SET label_cache = '' | |
144 | WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]); | |
145 | ||
146 | } | |
147 | ||
148 | return; | |
149 | } | |
150 | ||
151 | function colorreset() { | |
3972bf59 | 152 | $ids = split(',', db_escape_string($this->link, $_REQUEST["ids"])); |
cbe50c80 AD |
153 | |
154 | foreach ($ids as $id) { | |
155 | db_query($this->link, "UPDATE ttrss_labels2 SET | |
156 | fg_color = '', bg_color = '' WHERE id = '$id' | |
157 | AND owner_uid = " . $_SESSION["uid"]); | |
158 | ||
3972bf59 | 159 | $caption = db_escape_string($this->link, label_find_caption($this->link, $id, $_SESSION["uid"])); |
cbe50c80 AD |
160 | |
161 | /* Remove cached data */ | |
162 | ||
163 | db_query($this->link, "UPDATE ttrss_user_entries SET label_cache = '' | |
164 | WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]); | |
165 | } | |
166 | ||
167 | } | |
168 | ||
169 | function save() { | |
170 | ||
3972bf59 AD |
171 | $id = db_escape_string($this->link, $_REQUEST["id"]); |
172 | $caption = db_escape_string($this->link, trim($_REQUEST["caption"])); | |
cbe50c80 AD |
173 | |
174 | db_query($this->link, "BEGIN"); | |
175 | ||
176 | $result = db_query($this->link, "SELECT caption FROM ttrss_labels2 | |
177 | WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]); | |
178 | ||
179 | if (db_num_rows($result) != 0) { | |
180 | $old_caption = db_fetch_result($result, 0, "caption"); | |
181 | ||
182 | $result = db_query($this->link, "SELECT id FROM ttrss_labels2 | |
183 | WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]); | |
184 | ||
185 | if (db_num_rows($result) == 0) { | |
186 | if ($caption) { | |
187 | $result = db_query($this->link, "UPDATE ttrss_labels2 SET | |
188 | caption = '$caption' WHERE id = '$id' AND | |
189 | owner_uid = " . $_SESSION["uid"]); | |
190 | ||
191 | /* Update filters that reference label being renamed */ | |
192 | ||
3972bf59 | 193 | $old_caption = db_escape_string($this->link, $old_caption); |
cbe50c80 | 194 | |
6aff7845 | 195 | db_query($this->link, "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 | ||
209 | db_query($this->link, "COMMIT"); | |
210 | ||
211 | return; | |
212 | } | |
213 | ||
214 | function remove() { | |
215 | ||
3972bf59 | 216 | $ids = split(",", db_escape_string($this->link, $_REQUEST["ids"])); |
cbe50c80 AD |
217 | |
218 | foreach ($ids as $id) { | |
219 | label_remove($this->link, $id, $_SESSION["uid"]); | |
220 | } | |
221 | ||
222 | } | |
223 | ||
224 | function add() { | |
3972bf59 AD |
225 | $caption = db_escape_string($this->link, $_REQUEST["caption"]); |
226 | $output = db_escape_string($this->link, $_REQUEST["output"]); | |
cbe50c80 AD |
227 | |
228 | if ($caption) { | |
229 | ||
230 | if (label_create($this->link, $caption)) { | |
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 | ||
241 | print_label_select($this->link, "select_label", | |
242 | $caption, ""); | |
243 | ||
244 | print "</payload></rpc-reply>"; | |
245 | } | |
246 | } | |
247 | ||
248 | return; | |
249 | } | |
250 | ||
251 | function index() { | |
252 | ||
3972bf59 | 253 | $sort = db_escape_string($this->link, $_REQUEST["sort"]); |
cbe50c80 AD |
254 | |
255 | if (!$sort || $sort == "undefined") { | |
256 | $sort = "caption"; | |
257 | } | |
258 | ||
3972bf59 | 259 | $label_search = db_escape_string($this->link, $_REQUEST["search"]); |
cbe50c80 AD |
260 | |
261 | if (array_key_exists("search", $_REQUEST)) { | |
262 | $_SESSION["prefs_label_search"] = $label_search; | |
263 | } else { | |
264 | $label_search = $_SESSION["prefs_label_search"]; | |
265 | } | |
266 | ||
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\">"; | |
270 | ||
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>"; | |
279 | ||
280 | print"<button dojoType=\"dijit.form.Button\" onclick=\"return addLabel()\">". | |
281 | __('Create label')."</button dojoType=\"dijit.form.Button\"> "; | |
282 | ||
283 | print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedLabels()\">". | |
284 | __('Remove')."</button dojoType=\"dijit.form.Button\"> "; | |
285 | ||
286 | print "<button dojoType=\"dijit.form.Button\" onclick=\"labelColorReset()\">". | |
287 | __('Clear colors')."</button dojoType=\"dijit.form.Button\">"; | |
288 | ||
289 | ||
290 | print "</div>"; #toolbar | |
291 | print "</div>"; #pane | |
292 | print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">"; | |
293 | ||
294 | print "<div id=\"labellistLoading\"> | |
295 | <img src='images/indicator_tiny.gif'>". | |
296 | __("Loading, please wait...")."</div>"; | |
297 | ||
298 | print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"labelStore\" | |
299 | url=\"backend.php?op=pref-labels&method=getlabeltree\"> | |
300 | </div> | |
301 | <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"labelModel\" store=\"labelStore\" | |
302 | query=\"{id:'root'}\" rootId=\"root\" | |
303 | childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\"> | |
304 | </div> | |
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\"); | |
309 | </script> | |
310 | <script type=\"dojo/method\" event=\"onClick\" args=\"item\"> | |
311 | var id = String(item.id); | |
312 | var bare_id = id.substr(id.indexOf(':')+1); | |
313 | ||
314 | if (id.match('LABEL:')) { | |
315 | editLabel(bare_id); | |
316 | } | |
317 | </script> | |
318 | </div>"; | |
319 | ||
320 | print "</div>"; #pane | |
6065f3ad AD |
321 | |
322 | global $pluginhost; | |
323 | $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB, | |
324 | "hook_prefs_tab", "prefLabels"); | |
325 | ||
cbe50c80 AD |
326 | print "</div>"; #container |
327 | ||
328 | } | |
329 | } | |
330 | ||
331 | ?> |