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