]> git.wh0rd.org - tt-rss.git/blob - include/controls.php
pngcrush.sh
[tt-rss.git] / include / controls.php
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\">&nbsp;$v&nbsp;";
69
70 }
71 }
72
73 function print_feed_multi_select($id, $default_ids = [],
74 $attributes = "", $include_all_feeds = true,
75 $root_id = null, $nest_level = 0) {
76
77 $pdo = DB::pdo();
78
79 print_r(in_array("CAT:6",$default_ids));
80
81 if (!$root_id) {
82 print "<select multiple=\true\" id=\"$id\" name=\"$id\" $attributes>";
83 if ($include_all_feeds) {
84 $is_selected = (in_array("0", $default_ids)) ? "selected=\"1\"" : "";
85 print "<option $is_selected value=\"0\">".__('All feeds')."</option>";
86 }
87 }
88
89 if (get_pref('ENABLE_FEED_CATS')) {
90
91 if (!$root_id) $root_id = null;
92
93 $sth = $pdo->prepare("SELECT id,title,
94 (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE
95 c2.parent_cat = ttrss_feed_categories.id) AS num_children
96 FROM ttrss_feed_categories
97 WHERE owner_uid = :uid AND
98 (parent_cat = :root_id OR (:root_id IS NULL AND parent_cat IS NULL)) ORDER BY title");
99
100 $sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]);
101
102 while ($line = $sth->fetch()) {
103
104 for ($i = 0; $i < $nest_level; $i++)
105 $line["title"] = " - " . $line["title"];
106
107 $is_selected = in_array("CAT:".$line["id"], $default_ids) ? "selected=\"1\"" : "";
108
109 printf("<option $is_selected value='CAT:%d'>%s</option>",
110 $line["id"], htmlspecialchars($line["title"]));
111
112 if ($line["num_children"] > 0)
113 print_feed_multi_select($id, $default_ids, $attributes,
114 $include_all_feeds, $line["id"], $nest_level+1);
115
116 $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds
117 WHERE cat_id = ? AND owner_uid = ? ORDER BY title");
118
119 $f_sth->execute([$line['id'], $_SESSION['uid']]);
120
121 while ($fline = $f_sth->fetch()) {
122 $is_selected = (in_array($fline["id"], $default_ids)) ? "selected=\"1\"" : "";
123
124 $fline["title"] = " + " . $fline["title"];
125
126 for ($i = 0; $i < $nest_level; $i++)
127 $fline["title"] = " - " . $fline["title"];
128
129 printf("<option $is_selected value='%d'>%s</option>",
130 $fline["id"], htmlspecialchars($fline["title"]));
131 }
132 }
133
134 if (!$root_id) {
135 $is_selected = in_array("CAT:0", $default_ids) ? "selected=\"1\"" : "";
136
137 printf("<option $is_selected value='CAT:0'>%s</option>",
138 __("Uncategorized"));
139
140 $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds
141 WHERE cat_id IS NULL AND owner_uid = ? ORDER BY title");
142 $f_sth->execute([$_SESSION['uid']]);
143
144 while ($fline = $f_sth->fetch()) {
145 $is_selected = in_array($fline["id"], $default_ids) ? "selected=\"1\"" : "";
146
147 $fline["title"] = " + " . $fline["title"];
148
149 for ($i = 0; $i < $nest_level; $i++)
150 $fline["title"] = " - " . $fline["title"];
151
152 printf("<option $is_selected value='%d'>%s</option>",
153 $fline["id"], htmlspecialchars($fline["title"]));
154 }
155 }
156
157 } else {
158 $sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds
159 WHERE owner_uid = ? ORDER BY title");
160 $sth->execute([$_SESSION['uid']]);
161
162 while ($line = $sth->fetch()) {
163
164 $is_selected = (in_array($line["id"], $default_ids)) ? "selected=\"1\"" : "";
165
166 printf("<option $is_selected value='%d'>%s</option>",
167 $line["id"], htmlspecialchars($line["title"]));
168 }
169 }
170
171 if (!$root_id) {
172 print "</select>";
173 }
174 }
175
176 function print_feed_cat_select($id, $default_id,
177 $attributes, $include_all_cats = true, $root_id = null, $nest_level = 0) {
178
179 if (!$root_id) {
180 print "<select id=\"$id\" name=\"$id\" default=\"$default_id\" $attributes>";
181 }
182
183 $pdo = DB::pdo();
184
185 if (!$root_id) $root_id = null;
186
187 $sth = $pdo->prepare("SELECT id,title,
188 (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE
189 c2.parent_cat = ttrss_feed_categories.id) AS num_children
190 FROM ttrss_feed_categories
191 WHERE owner_uid = :uid AND
192 (parent_cat = :root_id OR (:root_id IS NULL AND parent_cat IS NULL)) ORDER BY title");
193 $sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]);
194
195 $found = 0;
196
197 while ($line = $sth->fetch()) {
198 ++$found;
199
200 if ($line["id"] == $default_id) {
201 $is_selected = "selected=\"1\"";
202 } else {
203 $is_selected = "";
204 }
205
206 for ($i = 0; $i < $nest_level; $i++)
207 $line["title"] = " - " . $line["title"];
208
209 if ($line["title"])
210 printf("<option $is_selected value='%d'>%s</option>",
211 $line["id"], htmlspecialchars($line["title"]));
212
213 if ($line["num_children"] > 0)
214 print_feed_cat_select($id, $default_id, $attributes,
215 $include_all_cats, $line["id"], $nest_level+1);
216 }
217
218 if (!$root_id) {
219 if ($include_all_cats) {
220 if ($found > 0) {
221 print "<option disabled=\"1\">--------</option>";
222 }
223
224 if ($default_id == 0) {
225 $is_selected = "selected=\"1\"";
226 } else {
227 $is_selected = "";
228 }
229
230 print "<option $is_selected value=\"0\">".__('Uncategorized')."</option>";
231 }
232 print "</select>";
233 }
234 }
235
236 function stylesheet_tag($filename) {
237 $timestamp = filemtime($filename);
238
239 return "<link rel=\"stylesheet\" type=\"text/css\" href=\"$filename?$timestamp\"/>\n";
240 }
241
242 function javascript_tag($filename) {
243 $query = "";
244
245 if (!(strpos($filename, "?") === FALSE)) {
246 $query = substr($filename, strpos($filename, "?")+1);
247 $filename = substr($filename, 0, strpos($filename, "?"));
248 }
249
250 $timestamp = filemtime($filename);
251
252 if ($query) $timestamp .= "&$query";
253
254 return "<script type=\"text/javascript\" charset=\"utf-8\" src=\"$filename?$timestamp\"></script>\n";
255 }
256
257 function format_warning($msg, $id = "") {
258 return "<div class=\"alert\" id=\"$id\">$msg</div>";
259 }
260
261 function format_notice($msg, $id = "") {
262 return "<div class=\"alert alert-info\" id=\"$id\">$msg</div>";
263 }
264
265 function format_error($msg, $id = "") {
266 return "<div class=\"alert alert-danger\" id=\"$id\">$msg</div>";
267 }
268
269 function print_notice($msg) {
270 return print format_notice($msg);
271 }
272
273 function print_warning($msg) {
274 return print format_warning($msg);
275 }
276
277 function print_error($msg) {
278 return print format_error($msg);
279 }
280
281 function format_inline_player($url, $ctype) {
282
283 $entry = "";
284
285 $url = htmlspecialchars($url);
286
287 if (strpos($ctype, "audio/") === 0) {
288
289 if ($_SESSION["hasAudio"] && (strpos($ctype, "ogg") !== false ||
290 $_SESSION["hasMp3"])) {
291
292 $entry .= "<audio preload=\"none\" controls>
293 <source type=\"$ctype\" src=\"$url\"/>
294 </audio>";
295
296 }
297
298 if ($entry) $entry .= "&nbsp; <a target=\"_blank\" rel=\"noopener noreferrer\"
299 href=\"$url\">" . basename($url) . "</a>";
300
301 return $entry;
302
303 }
304
305 return "";
306 }
307
308 function print_label_select($name, $value, $attributes = "") {
309
310 $pdo = Db::pdo();
311
312 $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2
313 WHERE owner_uid = ? ORDER BY caption");
314 $sth->execute([$_SESSION['uid']]);
315
316 print "<select default=\"$value\" name=\"" . htmlspecialchars($name) .
317 "\" $attributes>";
318
319 while ($line = $sth->fetch()) {
320
321 $issel = ($line["caption"] == $value) ? "selected=\"1\"" : "";
322
323 print "<option value=\"".htmlspecialchars($line["caption"])."\"
324 $issel>" . htmlspecialchars($line["caption"]) . "</option>";
325
326 }
327
328 # print "<option value=\"ADD_LABEL\">" .__("Add label...") . "</option>";
329
330 print "</select>";
331
332
333 }