]>
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 | 73 | function print_feed_multi_select($id, $default_ids = [], |
7f4a4045 AD |
74 | $attributes = "", $include_all_feeds = true, |
75 | $root_id = null, $nest_level = 0) { | |
d068111a | 76 | |
7f4a4045 | 77 | $pdo = DB::pdo(); |
02f3992a | 78 | |
7f4a4045 | 79 | print_r(in_array("CAT:6",$default_ids)); |
02f3992a | 80 | |
7f4a4045 AD |
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 | } | |
02f3992a | 88 | |
7f4a4045 | 89 | if (get_pref('ENABLE_FEED_CATS')) { |
02f3992a | 90 | |
7f4a4045 | 91 | if (!$root_id) $root_id = null; |
02f3992a | 92 | |
7f4a4045 | 93 | $sth = $pdo->prepare("SELECT id,title, |
02f3992a AD |
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 | |
df47100a | 97 | WHERE owner_uid = :uid AND |
cc9450c3 | 98 | (parent_cat = :root_id OR (:root_id IS NULL AND parent_cat IS NULL)) ORDER BY title"); |
d068111a | 99 | |
7f4a4045 | 100 | $sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]); |
02f3992a | 101 | |
7f4a4045 | 102 | while ($line = $sth->fetch()) { |
02f3992a | 103 | |
7f4a4045 AD |
104 | for ($i = 0; $i < $nest_level; $i++) |
105 | $line["title"] = " - " . $line["title"]; | |
02f3992a | 106 | |
7f4a4045 | 107 | $is_selected = in_array("CAT:".$line["id"], $default_ids) ? "selected=\"1\"" : ""; |
02f3992a | 108 | |
7f4a4045 AD |
109 | printf("<option $is_selected value='CAT:%d'>%s</option>", |
110 | $line["id"], htmlspecialchars($line["title"])); | |
02f3992a | 111 | |
7f4a4045 AD |
112 | if ($line["num_children"] > 0) |
113 | print_feed_multi_select($id, $default_ids, $attributes, | |
114 | $include_all_feeds, $line["id"], $nest_level+1); | |
02f3992a | 115 | |
7f4a4045 | 116 | $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds |
d068111a | 117 | WHERE cat_id = ? AND owner_uid = ? ORDER BY title"); |
02f3992a | 118 | |
7f4a4045 | 119 | $f_sth->execute([$line['id'], $_SESSION['uid']]); |
d068111a | 120 | |
7f4a4045 AD |
121 | while ($fline = $f_sth->fetch()) { |
122 | $is_selected = (in_array($fline["id"], $default_ids)) ? "selected=\"1\"" : ""; | |
02f3992a | 123 | |
7f4a4045 | 124 | $fline["title"] = " + " . $fline["title"]; |
02f3992a | 125 | |
7f4a4045 AD |
126 | for ($i = 0; $i < $nest_level; $i++) |
127 | $fline["title"] = " - " . $fline["title"]; | |
02f3992a | 128 | |
7f4a4045 AD |
129 | printf("<option $is_selected value='%d'>%s</option>", |
130 | $fline["id"], htmlspecialchars($fline["title"])); | |
131 | } | |
132 | } | |
02f3992a | 133 | |
7f4a4045 AD |
134 | if (!$root_id) { |
135 | $is_selected = in_array("CAT:0", $default_ids) ? "selected=\"1\"" : ""; | |
02f3992a | 136 | |
7f4a4045 AD |
137 | printf("<option $is_selected value='CAT:0'>%s</option>", |
138 | __("Uncategorized")); | |
02f3992a | 139 | |
7f4a4045 | 140 | $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds |
d068111a | 141 | WHERE cat_id IS NULL AND owner_uid = ? ORDER BY title"); |
7f4a4045 | 142 | $f_sth->execute([$_SESSION['uid']]); |
02f3992a | 143 | |
7f4a4045 AD |
144 | while ($fline = $f_sth->fetch()) { |
145 | $is_selected = in_array($fline["id"], $default_ids) ? "selected=\"1\"" : ""; | |
02f3992a | 146 | |
7f4a4045 | 147 | $fline["title"] = " + " . $fline["title"]; |
02f3992a | 148 | |
7f4a4045 AD |
149 | for ($i = 0; $i < $nest_level; $i++) |
150 | $fline["title"] = " - " . $fline["title"]; | |
02f3992a | 151 | |
7f4a4045 AD |
152 | printf("<option $is_selected value='%d'>%s</option>", |
153 | $fline["id"], htmlspecialchars($fline["title"])); | |
154 | } | |
155 | } | |
02f3992a | 156 | |
7f4a4045 AD |
157 | } else { |
158 | $sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds | |
d068111a | 159 | WHERE owner_uid = ? ORDER BY title"); |
7f4a4045 | 160 | $sth->execute([$_SESSION['uid']]); |
02f3992a | 161 | |
7f4a4045 | 162 | while ($line = $sth->fetch()) { |
02f3992a | 163 | |
7f4a4045 | 164 | $is_selected = (in_array($line["id"], $default_ids)) ? "selected=\"1\"" : ""; |
02f3992a | 165 | |
7f4a4045 AD |
166 | printf("<option $is_selected value='%d'>%s</option>", |
167 | $line["id"], htmlspecialchars($line["title"])); | |
168 | } | |
169 | } | |
02f3992a | 170 | |
7f4a4045 AD |
171 | if (!$root_id) { |
172 | print "</select>"; | |
173 | } | |
02f3992a AD |
174 | } |
175 | ||
bbd9e504 AD |
176 | function print_feed_cat_select($id, $default_id, |
177 | $attributes, $include_all_cats = true, $root_id = null, $nest_level = 0) { | |
9549e33c AD |
178 | |
179 | if (!$root_id) { | |
bbd9e504 | 180 | print "<select id=\"$id\" name=\"$id\" default=\"$default_id\" $attributes>"; |
9549e33c AD |
181 | } |
182 | ||
bbd9e504 | 183 | $pdo = DB::pdo(); |
9549e33c | 184 | |
bbd9e504 | 185 | if (!$root_id) $root_id = null; |
9549e33c | 186 | |
bbd9e504 | 187 | $sth = $pdo->prepare("SELECT id,title, |
9549e33c AD |
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 | |
df47100a | 191 | WHERE owner_uid = :uid AND |
cc9450c3 | 192 | (parent_cat = :root_id OR (:root_id IS NULL AND parent_cat IS NULL)) ORDER BY title"); |
bbd9e504 | 193 | $sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]); |
9549e33c | 194 | |
bbd9e504 | 195 | $found = 0; |
9549e33c | 196 | |
bbd9e504 | 197 | while ($line = $sth->fetch()) { |
7f4a4045 | 198 | ++$found; |
9549e33c | 199 | |
9549e33c AD |
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) { | |
bbd9e504 | 220 | if ($found > 0) { |
9549e33c AD |
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 | ||
9549e33c AD |
296 | } |
297 | ||
298 | if ($entry) $entry .= " <a target=\"_blank\" rel=\"noopener noreferrer\" | |
299 | href=\"$url\">" . basename($url) . "</a>"; | |
300 | ||
301 | return $entry; | |
302 | ||
303 | } | |
304 | ||
305 | return ""; | |
306 | } | |
4122da02 AD |
307 | |
308 | function print_label_select($name, $value, $attributes = "") { | |
309 | ||
7f4a4045 | 310 | $pdo = Db::pdo(); |
d068111a AD |
311 | |
312 | $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2 | |
313 | WHERE owner_uid = ? ORDER BY caption"); | |
314 | $sth->execute([$_SESSION['uid']]); | |
4122da02 AD |
315 | |
316 | print "<select default=\"$value\" name=\"" . htmlspecialchars($name) . | |
317 | "\" $attributes>"; | |
318 | ||
d068111a | 319 | while ($line = $sth->fetch()) { |
4122da02 AD |
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 | ||
7f4a4045 | 333 | } |