]>
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 | ||
bbd9e504 AD |
170 | function print_feed_cat_select($id, $default_id, |
171 | $attributes, $include_all_cats = true, $root_id = null, $nest_level = 0) { | |
9549e33c AD |
172 | |
173 | if (!$root_id) { | |
bbd9e504 | 174 | print "<select id=\"$id\" name=\"$id\" default=\"$default_id\" $attributes>"; |
9549e33c AD |
175 | } |
176 | ||
bbd9e504 | 177 | $pdo = DB::pdo(); |
9549e33c | 178 | |
bbd9e504 | 179 | if (!$root_id) $root_id = null; |
9549e33c | 180 | |
bbd9e504 | 181 | $sth = $pdo->prepare("SELECT id,title, |
9549e33c AD |
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 | |
bbd9e504 AD |
185 | WHERE owner_uid = :uid AND |
186 | (parent_cat = :root_id OR :root_id IS NULL AND parent_cat IS NULL) ORDER BY title"); | |
187 | $sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]); | |
9549e33c | 188 | |
bbd9e504 | 189 | $found = 0; |
9549e33c | 190 | |
bbd9e504 AD |
191 | while ($line = $sth->fetch()) { |
192 | ++$found; | |
9549e33c | 193 | |
9549e33c AD |
194 | if ($line["id"] == $default_id) { |
195 | $is_selected = "selected=\"1\""; | |
196 | } else { | |
197 | $is_selected = ""; | |
198 | } | |
199 | ||
200 | for ($i = 0; $i < $nest_level; $i++) | |
201 | $line["title"] = " - " . $line["title"]; | |
202 | ||
203 | if ($line["title"]) | |
204 | printf("<option $is_selected value='%d'>%s</option>", | |
205 | $line["id"], htmlspecialchars($line["title"])); | |
206 | ||
207 | if ($line["num_children"] > 0) | |
208 | print_feed_cat_select($id, $default_id, $attributes, | |
209 | $include_all_cats, $line["id"], $nest_level+1); | |
210 | } | |
211 | ||
212 | if (!$root_id) { | |
213 | if ($include_all_cats) { | |
bbd9e504 | 214 | if ($found > 0) { |
9549e33c AD |
215 | print "<option disabled=\"1\">--------</option>"; |
216 | } | |
217 | ||
218 | if ($default_id == 0) { | |
219 | $is_selected = "selected=\"1\""; | |
220 | } else { | |
221 | $is_selected = ""; | |
222 | } | |
223 | ||
224 | print "<option $is_selected value=\"0\">".__('Uncategorized')."</option>"; | |
225 | } | |
226 | print "</select>"; | |
227 | } | |
228 | } | |
229 | ||
230 | function stylesheet_tag($filename) { | |
231 | $timestamp = filemtime($filename); | |
232 | ||
233 | return "<link rel=\"stylesheet\" type=\"text/css\" href=\"$filename?$timestamp\"/>\n"; | |
234 | } | |
235 | ||
236 | function javascript_tag($filename) { | |
237 | $query = ""; | |
238 | ||
239 | if (!(strpos($filename, "?") === FALSE)) { | |
240 | $query = substr($filename, strpos($filename, "?")+1); | |
241 | $filename = substr($filename, 0, strpos($filename, "?")); | |
242 | } | |
243 | ||
244 | $timestamp = filemtime($filename); | |
245 | ||
246 | if ($query) $timestamp .= "&$query"; | |
247 | ||
248 | return "<script type=\"text/javascript\" charset=\"utf-8\" src=\"$filename?$timestamp\"></script>\n"; | |
249 | } | |
250 | ||
251 | function format_warning($msg, $id = "") { | |
252 | return "<div class=\"alert\" id=\"$id\">$msg</div>"; | |
253 | } | |
254 | ||
255 | function format_notice($msg, $id = "") { | |
256 | return "<div class=\"alert alert-info\" id=\"$id\">$msg</div>"; | |
257 | } | |
258 | ||
259 | function format_error($msg, $id = "") { | |
260 | return "<div class=\"alert alert-danger\" id=\"$id\">$msg</div>"; | |
261 | } | |
262 | ||
263 | function print_notice($msg) { | |
264 | return print format_notice($msg); | |
265 | } | |
266 | ||
267 | function print_warning($msg) { | |
268 | return print format_warning($msg); | |
269 | } | |
270 | ||
271 | function print_error($msg) { | |
272 | return print format_error($msg); | |
273 | } | |
274 | ||
275 | function format_inline_player($url, $ctype) { | |
276 | ||
277 | $entry = ""; | |
278 | ||
279 | $url = htmlspecialchars($url); | |
280 | ||
281 | if (strpos($ctype, "audio/") === 0) { | |
282 | ||
283 | if ($_SESSION["hasAudio"] && (strpos($ctype, "ogg") !== false || | |
284 | $_SESSION["hasMp3"])) { | |
285 | ||
286 | $entry .= "<audio preload=\"none\" controls> | |
287 | <source type=\"$ctype\" src=\"$url\"/> | |
288 | </audio>"; | |
289 | ||
290 | } else { | |
291 | ||
292 | $entry .= "<object type=\"application/x-shockwave-flash\" | |
293 | data=\"lib/button/musicplayer.swf?song_url=$url\" | |
294 | width=\"17\" height=\"17\" style='float : left; margin-right : 5px;'> | |
295 | <param name=\"movie\" | |
296 | value=\"lib/button/musicplayer.swf?song_url=$url\" /> | |
297 | </object>"; | |
298 | } | |
299 | ||
300 | if ($entry) $entry .= " <a target=\"_blank\" rel=\"noopener noreferrer\" | |
301 | href=\"$url\">" . basename($url) . "</a>"; | |
302 | ||
303 | return $entry; | |
304 | ||
305 | } | |
306 | ||
307 | return ""; | |
308 | } | |
4122da02 AD |
309 | |
310 | function print_label_select($name, $value, $attributes = "") { | |
311 | ||
312 | $result = db_query("SELECT caption FROM ttrss_labels2 | |
313 | WHERE owner_uid = '".$_SESSION["uid"]."' ORDER BY caption"); | |
314 | ||
315 | print "<select default=\"$value\" name=\"" . htmlspecialchars($name) . | |
316 | "\" $attributes>"; | |
317 | ||
318 | while ($line = db_fetch_assoc($result)) { | |
319 | ||
320 | $issel = ($line["caption"] == $value) ? "selected=\"1\"" : ""; | |
321 | ||
322 | print "<option value=\"".htmlspecialchars($line["caption"])."\" | |
323 | $issel>" . htmlspecialchars($line["caption"]) . "</option>"; | |
324 | ||
325 | } | |
326 | ||
327 | # print "<option value=\"ADD_LABEL\">" .__("Add label...") . "</option>"; | |
328 | ||
329 | print "</select>"; | |
330 | ||
331 | ||
332 | } | |
333 |