]>
git.wh0rd.org - tt-rss.git/blob - include/controls.php
3 function print_select($id, $default, $values, $attributes = "", $name = "") {
4 if (!$name) $name = $id;
6 print "<select name=\"$name\" id=\"$id\" $attributes>";
7 foreach ($values as $v) {
9 $sel = "selected=\"1\"";
15 print "<option value=\"$v\" $sel>$v</option>";
20 function print_select_hash($id, $default, $values, $attributes = "", $name = "") {
21 if (!$name) $name = $id;
23 print "<select name=\"$name\" id='$id' $attributes>";
24 foreach (array_keys($values) as $v) {
26 $sel = 'selected="selected"';
32 print "<option $sel value=\"$v\">".$values[$v]."</option>";
38 function print_hidden($name, $value) {
39 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"$name\" value=\"$value\">";
42 function print_checkbox($id, $checked, $value = "", $attributes = "") {
43 $checked_str = $checked ?
"checked" : "";
44 $value_str = $value ?
"value=\"$value\"" : "";
46 print "<input dojoType=\"dijit.form.CheckBox\" id=\"$id\" $value_str $checked_str $attributes name=\"$id\">";
49 function print_button($type, $value, $attributes = "") {
50 print "<p><button dojoType=\"dijit.form.Button\" $attributes type=\"$type\">$value</button>";
53 function print_radio($id, $default, $true_is, $values, $attributes = "") {
54 foreach ($values as $v) {
62 $sel .= " value=\"1\"";
64 $sel .= " value=\"0\"";
67 print "<input class=\"noborder\" dojoType=\"dijit.form.RadioButton\"
68 type=\"radio\" $sel $attributes name=\"$id\"> $v ";
73 function print_feed_select($id, $default_id = "",
74 $attributes = "", $include_all_feeds = true,
75 $root_id = false, $nest_level = 0) {
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>";
85 if (get_pref('ENABLE_FEED_CATS')) {
88 $parent_qpart = "parent_cat = '$root_id'";
90 $parent_qpart = "parent_cat IS NULL";
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");
98 while ($line = db_fetch_assoc($result)) {
100 for ($i = 0; $i < $nest_level; $i++
)
101 $line["title"] = " - " . $line["title"];
103 $is_selected = ("CAT:".$line["id"] == $default_id) ?
"selected=\"1\"" : "";
105 printf("<option $is_selected value='CAT:%d'>%s</option>",
106 $line["id"], htmlspecialchars($line["title"]));
108 if ($line["num_children"] > 0)
109 print_feed_select($id, $default_id, $attributes,
110 $include_all_feeds, $line["id"], $nest_level+
1);
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");
115 while ($fline = db_fetch_assoc($feed_result)) {
116 $is_selected = ($fline["id"] == $default_id) ?
"selected=\"1\"" : "";
118 $fline["title"] = " + " . $fline["title"];
120 for ($i = 0; $i < $nest_level; $i++
)
121 $fline["title"] = " - " . $fline["title"];
123 printf("<option $is_selected value='%d'>%s</option>",
124 $fline["id"], htmlspecialchars($fline["title"]));
129 $default_is_cat = ($default_id == "CAT:0");
130 $is_selected = $default_is_cat ?
"selected=\"1\"" : "";
132 printf("<option $is_selected value='CAT:0'>%s</option>",
133 __("Uncategorized"));
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");
138 while ($fline = db_fetch_assoc($feed_result)) {
139 $is_selected = ($fline["id"] == $default_id && !$default_is_cat) ?
"selected=\"1\"" : "";
141 $fline["title"] = " + " . $fline["title"];
143 for ($i = 0; $i < $nest_level; $i++
)
144 $fline["title"] = " - " . $fline["title"];
146 printf("<option $is_selected value='%d'>%s</option>",
147 $fline["id"], htmlspecialchars($fline["title"]));
152 $result = db_query("SELECT id,title FROM ttrss_feeds
153 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
155 while ($line = db_fetch_assoc($result)) {
157 $is_selected = ($line["id"] == $default_id) ?
"selected=\"1\"" : "";
159 printf("<option $is_selected value='%d'>%s</option>",
160 $line["id"], htmlspecialchars($line["title"]));
169 function print_feed_cat_select($id, $default_id,
170 $attributes, $include_all_cats = true, $root_id = false, $nest_level = 0) {
173 print "<select id=\"$id\" name=\"$id\" default=\"$default_id\" $attributes>";
177 $parent_qpart = "parent_cat = '$root_id'";
179 $parent_qpart = "parent_cat IS NULL";
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");
187 while ($line = db_fetch_assoc($result)) {
188 if ($line["id"] == $default_id) {
189 $is_selected = "selected=\"1\"";
194 for ($i = 0; $i < $nest_level; $i++
)
195 $line["title"] = " - " . $line["title"];
198 printf("<option $is_selected value='%d'>%s</option>",
199 $line["id"], htmlspecialchars($line["title"]));
201 if ($line["num_children"] > 0)
202 print_feed_cat_select($id, $default_id, $attributes,
203 $include_all_cats, $line["id"], $nest_level+
1);
207 if ($include_all_cats) {
208 if (db_num_rows($result) > 0) {
209 print "<option disabled=\"1\">--------</option>";
212 if ($default_id == 0) {
213 $is_selected = "selected=\"1\"";
218 print "<option $is_selected value=\"0\">".__('Uncategorized')."</option>";
224 function stylesheet_tag($filename) {
225 $timestamp = filemtime($filename);
227 return "<link rel=\"stylesheet\" type=\"text/css\" href=\"$filename?$timestamp\"/>\n";
230 function javascript_tag($filename) {
233 if (!(strpos($filename, "?") === FALSE)) {
234 $query = substr($filename, strpos($filename, "?")+
1);
235 $filename = substr($filename, 0, strpos($filename, "?"));
238 $timestamp = filemtime($filename);
240 if ($query) $timestamp .= "&$query";
242 return "<script type=\"text/javascript\" charset=\"utf-8\" src=\"$filename?$timestamp\"></script>\n";
245 function format_warning($msg, $id = "") {
246 return "<div class=\"alert\" id=\"$id\">$msg</div>";
249 function format_notice($msg, $id = "") {
250 return "<div class=\"alert alert-info\" id=\"$id\">$msg</div>";
253 function format_error($msg, $id = "") {
254 return "<div class=\"alert alert-danger\" id=\"$id\">$msg</div>";
257 function print_notice($msg) {
258 return print format_notice($msg);
261 function print_warning($msg) {
262 return print format_warning($msg);
265 function print_error($msg) {
266 return print format_error($msg);
269 function format_inline_player($url, $ctype) {
273 $url = htmlspecialchars($url);
275 if (strpos($ctype, "audio/") === 0) {
277 if ($_SESSION["hasAudio"] && (strpos($ctype, "ogg") !== false ||
278 $_SESSION["hasMp3"])) {
280 $entry .= "<audio preload=\"none\" controls>
281 <source type=\"$ctype\" src=\"$url\"/>
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\" />
294 if ($entry) $entry .= " <a target=\"_blank\" rel=\"noopener noreferrer\"
295 href=\"$url\">" . basename($url) . "</a>";