]>
Commit | Line | Data |
---|---|---|
9549e33c AD |
1 | <?php |
2 | ||
3 | function print_select($id, $default, $values, $attributes = "", $name = "") { | |
4 | if (!$name) $name = $id; | |
5 | ||
6 | print "<select name=\"$name\" id=\"$id\" $attributes>"; | |
7 | foreach ($values as $v) { | |
8 | if ($v == $default) | |
9 | $sel = "selected=\"1\""; | |
10 | else | |
11 | $sel = ""; | |
12 | ||
13 | $v = trim($v); | |
14 | ||
15 | print "<option value=\"$v\" $sel>$v</option>"; | |
16 | } | |
17 | print "</select>"; | |
18 | } | |
19 | ||
20 | function print_select_hash($id, $default, $values, $attributes = "", $name = "") { | |
21 | if (!$name) $name = $id; | |
22 | ||
23 | print "<select name=\"$name\" id='$id' $attributes>"; | |
24 | foreach (array_keys($values) as $v) { | |
25 | if ($v == $default) | |
26 | $sel = 'selected="selected"'; | |
27 | else | |
28 | $sel = ""; | |
29 | ||
30 | $v = trim($v); | |
31 | ||
32 | print "<option $sel value=\"$v\">".$values[$v]."</option>"; | |
33 | } | |
34 | ||
35 | print "</select>"; | |
36 | } | |
37 | ||
38 | function print_hidden($name, $value) { | |
39 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"$name\" value=\"$value\">"; | |
40 | } | |
41 | ||
42 | function print_checkbox($id, $checked, $value = "", $attributes = "") { | |
43 | $checked_str = $checked ? "checked" : ""; | |
44 | $value_str = $value ? "value=\"$value\"" : ""; | |
45 | ||
46 | print "<input dojoType=\"dijit.form.CheckBox\" id=\"$id\" $value_str $checked_str $attributes name=\"$id\">"; | |
47 | } | |
48 | ||
49 | function print_button($type, $value, $attributes = "") { | |
50 | print "<p><button dojoType=\"dijit.form.Button\" $attributes type=\"$type\">$value</button>"; | |
51 | } | |
52 | ||
53 | function print_radio($id, $default, $true_is, $values, $attributes = "") { | |
54 | foreach ($values as $v) { | |
55 | ||
56 | if ($v == $default) | |
57 | $sel = "checked"; | |
58 | else | |
59 | $sel = ""; | |
60 | ||
61 | if ($v == $true_is) { | |
62 | $sel .= " value=\"1\""; | |
63 | } else { | |
64 | $sel .= " value=\"0\""; | |
65 | } | |
66 | ||
67 | print "<input class=\"noborder\" dojoType=\"dijit.form.RadioButton\" | |
68 | type=\"radio\" $sel $attributes name=\"$id\"> $v "; | |
69 | ||
70 | } | |
71 | } | |
72 | ||
02f3992a AD |
73 | function print_feed_multi_select($id, $default_ids = [], |
74 | $attributes = "", $include_all_feeds = true, | |
75 | $root_id = false, $nest_level = 0) { | |
76 | ||
77 | print_r(in_array("CAT:6",$default_ids)); | |
78 | ||
79 | if (!$root_id) { | |
80 | print "<select multiple=\true\" id=\"$id\" name=\"$id\" $attributes>"; | |
81 | if ($include_all_feeds) { | |
82 | $is_selected = (in_array("0", $default_ids)) ? "selected=\"1\"" : ""; | |
83 | print "<option $is_selected value=\"0\">".__('All feeds')."</option>"; | |
84 | } | |
85 | } | |
86 | ||
87 | if (get_pref('ENABLE_FEED_CATS')) { | |
88 | ||
89 | if ($root_id) | |
90 | $parent_qpart = "parent_cat = '$root_id'"; | |
91 | else | |
92 | $parent_qpart = "parent_cat IS NULL"; | |
93 | ||
94 | $result = db_query("SELECT id,title, | |
95 | (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE | |
96 | c2.parent_cat = ttrss_feed_categories.id) AS num_children | |
97 | FROM ttrss_feed_categories | |
98 | WHERE owner_uid = ".$_SESSION["uid"]." AND $parent_qpart ORDER BY title"); | |
99 | ||
100 | while ($line = db_fetch_assoc($result)) { | |
101 | ||
102 | for ($i = 0; $i < $nest_level; $i++) | |
103 | $line["title"] = " - " . $line["title"]; | |
104 | ||
105 | $is_selected = in_array("CAT:".$line["id"], $default_ids) ? "selected=\"1\"" : ""; | |
106 | ||
107 | printf("<option $is_selected value='CAT:%d'>%s</option>", | |
108 | $line["id"], htmlspecialchars($line["title"])); | |
109 | ||
110 | if ($line["num_children"] > 0) | |
111 | print_feed_multi_select($id, $default_ids, $attributes, | |
112 | $include_all_feeds, $line["id"], $nest_level+1); | |
113 | ||
114 | $feed_result = db_query("SELECT id,title FROM ttrss_feeds | |
115 | WHERE cat_id = '".$line["id"]."' AND owner_uid = ".$_SESSION["uid"] . " ORDER BY title"); | |
116 | ||
117 | while ($fline = db_fetch_assoc($feed_result)) { | |
118 | $is_selected = (in_array($fline["id"], $default_ids)) ? "selected=\"1\"" : ""; | |
119 | ||
120 | $fline["title"] = " + " . $fline["title"]; | |
121 | ||
122 | for ($i = 0; $i < $nest_level; $i++) | |
123 | $fline["title"] = " - " . $fline["title"]; | |
124 | ||
125 | printf("<option $is_selected value='%d'>%s</option>", | |
126 | $fline["id"], htmlspecialchars($fline["title"])); | |
127 | } | |
128 | } | |
129 | ||
130 | if (!$root_id) { | |
131 | $is_selected = in_array("CAT:0", $default_ids) ? "selected=\"1\"" : ""; | |
132 | ||
133 | printf("<option $is_selected value='CAT:0'>%s</option>", | |
134 | __("Uncategorized")); | |
135 | ||
136 | $feed_result = db_query("SELECT id,title FROM ttrss_feeds | |
137 | WHERE cat_id IS NULL AND owner_uid = ".$_SESSION["uid"] . " ORDER BY title"); | |
138 | ||
139 | while ($fline = db_fetch_assoc($feed_result)) { | |
140 | $is_selected = in_array($fline["id"], $default_ids) ? "selected=\"1\"" : ""; | |
141 | ||
142 | $fline["title"] = " + " . $fline["title"]; | |
143 | ||
144 | for ($i = 0; $i < $nest_level; $i++) | |
145 | $fline["title"] = " - " . $fline["title"]; | |
146 | ||
147 | printf("<option $is_selected value='%d'>%s</option>", | |
148 | $fline["id"], htmlspecialchars($fline["title"])); | |
149 | } | |
150 | } | |
151 | ||
152 | } else { | |
153 | $result = db_query("SELECT id,title FROM ttrss_feeds | |
154 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
155 | ||
156 | while ($line = db_fetch_assoc($result)) { | |
157 | ||
158 | $is_selected = (in_array($line["id"], $default_ids)) ? "selected=\"1\"" : ""; | |
159 | ||
160 | printf("<option $is_selected value='%d'>%s</option>", | |
161 | $line["id"], htmlspecialchars($line["title"])); | |
162 | } | |
163 | } | |
164 | ||
165 | if (!$root_id) { | |
166 | print "</select>"; | |
167 | } | |
168 | } | |
169 | ||
170 | ||
d76d5e86 | 171 | /*function print_feed_select($id, $default_id = "", |
9549e33c AD |
172 | $attributes = "", $include_all_feeds = true, |
173 | $root_id = false, $nest_level = 0) { | |
174 | ||
175 | if (!$root_id) { | |
176 | print "<select id=\"$id\" name=\"$id\" $attributes>"; | |
177 | if ($include_all_feeds) { | |
178 | $is_selected = ("0" == $default_id) ? "selected=\"1\"" : ""; | |
179 | print "<option $is_selected value=\"0\">".__('All feeds')."</option>"; | |
180 | } | |
181 | } | |
182 | ||
183 | if (get_pref('ENABLE_FEED_CATS')) { | |
184 | ||
185 | if ($root_id) | |
186 | $parent_qpart = "parent_cat = '$root_id'"; | |
187 | else | |
188 | $parent_qpart = "parent_cat IS NULL"; | |
189 | ||
190 | $result = db_query("SELECT id,title, | |
191 | (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE | |
192 | c2.parent_cat = ttrss_feed_categories.id) AS num_children | |
193 | FROM ttrss_feed_categories | |
194 | WHERE owner_uid = ".$_SESSION["uid"]." AND $parent_qpart ORDER BY title"); | |
195 | ||
196 | while ($line = db_fetch_assoc($result)) { | |
197 | ||
198 | for ($i = 0; $i < $nest_level; $i++) | |
199 | $line["title"] = " - " . $line["title"]; | |
200 | ||
201 | $is_selected = ("CAT:".$line["id"] == $default_id) ? "selected=\"1\"" : ""; | |
202 | ||
203 | printf("<option $is_selected value='CAT:%d'>%s</option>", | |
204 | $line["id"], htmlspecialchars($line["title"])); | |
205 | ||
206 | if ($line["num_children"] > 0) | |
207 | print_feed_select($id, $default_id, $attributes, | |
208 | $include_all_feeds, $line["id"], $nest_level+1); | |
209 | ||
210 | $feed_result = db_query("SELECT id,title FROM ttrss_feeds | |
211 | WHERE cat_id = '".$line["id"]."' AND owner_uid = ".$_SESSION["uid"] . " ORDER BY title"); | |
212 | ||
213 | while ($fline = db_fetch_assoc($feed_result)) { | |
214 | $is_selected = ($fline["id"] == $default_id) ? "selected=\"1\"" : ""; | |
215 | ||
216 | $fline["title"] = " + " . $fline["title"]; | |
217 | ||
218 | for ($i = 0; $i < $nest_level; $i++) | |
219 | $fline["title"] = " - " . $fline["title"]; | |
220 | ||
221 | printf("<option $is_selected value='%d'>%s</option>", | |
222 | $fline["id"], htmlspecialchars($fline["title"])); | |
223 | } | |
224 | } | |
225 | ||
226 | if (!$root_id) { | |
227 | $default_is_cat = ($default_id == "CAT:0"); | |
228 | $is_selected = $default_is_cat ? "selected=\"1\"" : ""; | |
229 | ||
230 | printf("<option $is_selected value='CAT:0'>%s</option>", | |
231 | __("Uncategorized")); | |
232 | ||
233 | $feed_result = db_query("SELECT id,title FROM ttrss_feeds | |
234 | WHERE cat_id IS NULL AND owner_uid = ".$_SESSION["uid"] . " ORDER BY title"); | |
235 | ||
236 | while ($fline = db_fetch_assoc($feed_result)) { | |
237 | $is_selected = ($fline["id"] == $default_id && !$default_is_cat) ? "selected=\"1\"" : ""; | |
238 | ||
239 | $fline["title"] = " + " . $fline["title"]; | |
240 | ||
241 | for ($i = 0; $i < $nest_level; $i++) | |
242 | $fline["title"] = " - " . $fline["title"]; | |
243 | ||
244 | printf("<option $is_selected value='%d'>%s</option>", | |
245 | $fline["id"], htmlspecialchars($fline["title"])); | |
246 | } | |
247 | } | |
248 | ||
249 | } else { | |
250 | $result = db_query("SELECT id,title FROM ttrss_feeds | |
251 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
252 | ||
253 | while ($line = db_fetch_assoc($result)) { | |
254 | ||
255 | $is_selected = ($line["id"] == $default_id) ? "selected=\"1\"" : ""; | |
256 | ||
257 | printf("<option $is_selected value='%d'>%s</option>", | |
258 | $line["id"], htmlspecialchars($line["title"])); | |
259 | } | |
260 | } | |
261 | ||
262 | if (!$root_id) { | |
263 | print "</select>"; | |
264 | } | |
d76d5e86 | 265 | }*/ |
9549e33c AD |
266 | |
267 | function print_feed_cat_select($id, $default_id, | |
268 | $attributes, $include_all_cats = true, $root_id = false, $nest_level = 0) { | |
269 | ||
270 | if (!$root_id) { | |
271 | print "<select id=\"$id\" name=\"$id\" default=\"$default_id\" $attributes>"; | |
272 | } | |
273 | ||
274 | if ($root_id) | |
275 | $parent_qpart = "parent_cat = '$root_id'"; | |
276 | else | |
277 | $parent_qpart = "parent_cat IS NULL"; | |
278 | ||
279 | $result = db_query("SELECT id,title, | |
280 | (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE | |
281 | c2.parent_cat = ttrss_feed_categories.id) AS num_children | |
282 | FROM ttrss_feed_categories | |
283 | WHERE owner_uid = ".$_SESSION["uid"]." AND $parent_qpart ORDER BY title"); | |
284 | ||
285 | while ($line = db_fetch_assoc($result)) { | |
286 | if ($line["id"] == $default_id) { | |
287 | $is_selected = "selected=\"1\""; | |
288 | } else { | |
289 | $is_selected = ""; | |
290 | } | |
291 | ||
292 | for ($i = 0; $i < $nest_level; $i++) | |
293 | $line["title"] = " - " . $line["title"]; | |
294 | ||
295 | if ($line["title"]) | |
296 | printf("<option $is_selected value='%d'>%s</option>", | |
297 | $line["id"], htmlspecialchars($line["title"])); | |
298 | ||
299 | if ($line["num_children"] > 0) | |
300 | print_feed_cat_select($id, $default_id, $attributes, | |
301 | $include_all_cats, $line["id"], $nest_level+1); | |
302 | } | |
303 | ||
304 | if (!$root_id) { | |
305 | if ($include_all_cats) { | |
306 | if (db_num_rows($result) > 0) { | |
307 | print "<option disabled=\"1\">--------</option>"; | |
308 | } | |
309 | ||
310 | if ($default_id == 0) { | |
311 | $is_selected = "selected=\"1\""; | |
312 | } else { | |
313 | $is_selected = ""; | |
314 | } | |
315 | ||
316 | print "<option $is_selected value=\"0\">".__('Uncategorized')."</option>"; | |
317 | } | |
318 | print "</select>"; | |
319 | } | |
320 | } | |
321 | ||
322 | function stylesheet_tag($filename) { | |
323 | $timestamp = filemtime($filename); | |
324 | ||
325 | return "<link rel=\"stylesheet\" type=\"text/css\" href=\"$filename?$timestamp\"/>\n"; | |
326 | } | |
327 | ||
328 | function javascript_tag($filename) { | |
329 | $query = ""; | |
330 | ||
331 | if (!(strpos($filename, "?") === FALSE)) { | |
332 | $query = substr($filename, strpos($filename, "?")+1); | |
333 | $filename = substr($filename, 0, strpos($filename, "?")); | |
334 | } | |
335 | ||
336 | $timestamp = filemtime($filename); | |
337 | ||
338 | if ($query) $timestamp .= "&$query"; | |
339 | ||
340 | return "<script type=\"text/javascript\" charset=\"utf-8\" src=\"$filename?$timestamp\"></script>\n"; | |
341 | } | |
342 | ||
343 | function format_warning($msg, $id = "") { | |
344 | return "<div class=\"alert\" id=\"$id\">$msg</div>"; | |
345 | } | |
346 | ||
347 | function format_notice($msg, $id = "") { | |
348 | return "<div class=\"alert alert-info\" id=\"$id\">$msg</div>"; | |
349 | } | |
350 | ||
351 | function format_error($msg, $id = "") { | |
352 | return "<div class=\"alert alert-danger\" id=\"$id\">$msg</div>"; | |
353 | } | |
354 | ||
355 | function print_notice($msg) { | |
356 | return print format_notice($msg); | |
357 | } | |
358 | ||
359 | function print_warning($msg) { | |
360 | return print format_warning($msg); | |
361 | } | |
362 | ||
363 | function print_error($msg) { | |
364 | return print format_error($msg); | |
365 | } | |
366 | ||
367 | function format_inline_player($url, $ctype) { | |
368 | ||
369 | $entry = ""; | |
370 | ||
371 | $url = htmlspecialchars($url); | |
372 | ||
373 | if (strpos($ctype, "audio/") === 0) { | |
374 | ||
375 | if ($_SESSION["hasAudio"] && (strpos($ctype, "ogg") !== false || | |
376 | $_SESSION["hasMp3"])) { | |
377 | ||
378 | $entry .= "<audio preload=\"none\" controls> | |
379 | <source type=\"$ctype\" src=\"$url\"/> | |
380 | </audio>"; | |
381 | ||
382 | } else { | |
383 | ||
384 | $entry .= "<object type=\"application/x-shockwave-flash\" | |
385 | data=\"lib/button/musicplayer.swf?song_url=$url\" | |
386 | width=\"17\" height=\"17\" style='float : left; margin-right : 5px;'> | |
387 | <param name=\"movie\" | |
388 | value=\"lib/button/musicplayer.swf?song_url=$url\" /> | |
389 | </object>"; | |
390 | } | |
391 | ||
392 | if ($entry) $entry .= " <a target=\"_blank\" rel=\"noopener noreferrer\" | |
393 | href=\"$url\">" . basename($url) . "</a>"; | |
394 | ||
395 | return $entry; | |
396 | ||
397 | } | |
398 | ||
399 | return ""; | |
400 | } | |
4122da02 AD |
401 | |
402 | function print_label_select($name, $value, $attributes = "") { | |
403 | ||
404 | $result = db_query("SELECT caption FROM ttrss_labels2 | |
405 | WHERE owner_uid = '".$_SESSION["uid"]."' ORDER BY caption"); | |
406 | ||
407 | print "<select default=\"$value\" name=\"" . htmlspecialchars($name) . | |
408 | "\" $attributes>"; | |
409 | ||
410 | while ($line = db_fetch_assoc($result)) { | |
411 | ||
412 | $issel = ($line["caption"] == $value) ? "selected=\"1\"" : ""; | |
413 | ||
414 | print "<option value=\"".htmlspecialchars($line["caption"])."\" | |
415 | $issel>" . htmlspecialchars($line["caption"]) . "</option>"; | |
416 | ||
417 | } | |
418 | ||
419 | # print "<option value=\"ADD_LABEL\">" .__("Add label...") . "</option>"; | |
420 | ||
421 | print "</select>"; | |
422 | ||
423 | ||
424 | } | |
425 |