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