controls.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <?php
  2. function print_select($id, $default, $values, $attributes = "", $name = "") {
  3. if (!$name) $name = $id;
  4. print "<select name=\"$name\" id=\"$id\" $attributes>";
  5. foreach ($values as $v) {
  6. if ($v == $default)
  7. $sel = "selected=\"1\"";
  8. else
  9. $sel = "";
  10. $v = trim($v);
  11. print "<option value=\"$v\" $sel>$v</option>";
  12. }
  13. print "</select>";
  14. }
  15. function print_select_hash($id, $default, $values, $attributes = "", $name = "") {
  16. if (!$name) $name = $id;
  17. print "<select name=\"$name\" id='$id' $attributes>";
  18. foreach (array_keys($values) as $v) {
  19. if ($v == $default)
  20. $sel = 'selected="selected"';
  21. else
  22. $sel = "";
  23. $v = trim($v);
  24. print "<option $sel value=\"$v\">".$values[$v]."</option>";
  25. }
  26. print "</select>";
  27. }
  28. function print_hidden($name, $value) {
  29. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"$name\" value=\"$value\">";
  30. }
  31. function print_checkbox($id, $checked, $value = "", $attributes = "") {
  32. $checked_str = $checked ? "checked" : "";
  33. $value_str = $value ? "value=\"$value\"" : "";
  34. print "<input dojoType=\"dijit.form.CheckBox\" id=\"$id\" $value_str $checked_str $attributes name=\"$id\">";
  35. }
  36. function print_button($type, $value, $attributes = "") {
  37. print "<p><button dojoType=\"dijit.form.Button\" $attributes type=\"$type\">$value</button>";
  38. }
  39. function print_radio($id, $default, $true_is, $values, $attributes = "") {
  40. foreach ($values as $v) {
  41. if ($v == $default)
  42. $sel = "checked";
  43. else
  44. $sel = "";
  45. if ($v == $true_is) {
  46. $sel .= " value=\"1\"";
  47. } else {
  48. $sel .= " value=\"0\"";
  49. }
  50. print "<input class=\"noborder\" dojoType=\"dijit.form.RadioButton\"
  51. type=\"radio\" $sel $attributes name=\"$id\">&nbsp;$v&nbsp;";
  52. }
  53. }
  54. function print_feed_select($id, $default_id = "",
  55. $attributes = "", $include_all_feeds = true,
  56. $root_id = false, $nest_level = 0) {
  57. if (!$root_id) {
  58. print "<select id=\"$id\" name=\"$id\" $attributes>";
  59. if ($include_all_feeds) {
  60. $is_selected = ("0" == $default_id) ? "selected=\"1\"" : "";
  61. print "<option $is_selected value=\"0\">".__('All feeds')."</option>";
  62. }
  63. }
  64. if (get_pref('ENABLE_FEED_CATS')) {
  65. if ($root_id)
  66. $parent_qpart = "parent_cat = '$root_id'";
  67. else
  68. $parent_qpart = "parent_cat IS NULL";
  69. $result = db_query("SELECT id,title,
  70. (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE
  71. c2.parent_cat = ttrss_feed_categories.id) AS num_children
  72. FROM ttrss_feed_categories
  73. WHERE owner_uid = ".$_SESSION["uid"]." AND $parent_qpart ORDER BY title");
  74. while ($line = db_fetch_assoc($result)) {
  75. for ($i = 0; $i < $nest_level; $i++)
  76. $line["title"] = " - " . $line["title"];
  77. $is_selected = ("CAT:".$line["id"] == $default_id) ? "selected=\"1\"" : "";
  78. printf("<option $is_selected value='CAT:%d'>%s</option>",
  79. $line["id"], htmlspecialchars($line["title"]));
  80. if ($line["num_children"] > 0)
  81. print_feed_select($id, $default_id, $attributes,
  82. $include_all_feeds, $line["id"], $nest_level+1);
  83. $feed_result = db_query("SELECT id,title FROM ttrss_feeds
  84. WHERE cat_id = '".$line["id"]."' AND owner_uid = ".$_SESSION["uid"] . " ORDER BY title");
  85. while ($fline = db_fetch_assoc($feed_result)) {
  86. $is_selected = ($fline["id"] == $default_id) ? "selected=\"1\"" : "";
  87. $fline["title"] = " + " . $fline["title"];
  88. for ($i = 0; $i < $nest_level; $i++)
  89. $fline["title"] = " - " . $fline["title"];
  90. printf("<option $is_selected value='%d'>%s</option>",
  91. $fline["id"], htmlspecialchars($fline["title"]));
  92. }
  93. }
  94. if (!$root_id) {
  95. $default_is_cat = ($default_id == "CAT:0");
  96. $is_selected = $default_is_cat ? "selected=\"1\"" : "";
  97. printf("<option $is_selected value='CAT:0'>%s</option>",
  98. __("Uncategorized"));
  99. $feed_result = db_query("SELECT id,title FROM ttrss_feeds
  100. WHERE cat_id IS NULL AND owner_uid = ".$_SESSION["uid"] . " ORDER BY title");
  101. while ($fline = db_fetch_assoc($feed_result)) {
  102. $is_selected = ($fline["id"] == $default_id && !$default_is_cat) ? "selected=\"1\"" : "";
  103. $fline["title"] = " + " . $fline["title"];
  104. for ($i = 0; $i < $nest_level; $i++)
  105. $fline["title"] = " - " . $fline["title"];
  106. printf("<option $is_selected value='%d'>%s</option>",
  107. $fline["id"], htmlspecialchars($fline["title"]));
  108. }
  109. }
  110. } else {
  111. $result = db_query("SELECT id,title FROM ttrss_feeds
  112. WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
  113. while ($line = db_fetch_assoc($result)) {
  114. $is_selected = ($line["id"] == $default_id) ? "selected=\"1\"" : "";
  115. printf("<option $is_selected value='%d'>%s</option>",
  116. $line["id"], htmlspecialchars($line["title"]));
  117. }
  118. }
  119. if (!$root_id) {
  120. print "</select>";
  121. }
  122. }
  123. function print_feed_cat_select($id, $default_id,
  124. $attributes, $include_all_cats = true, $root_id = false, $nest_level = 0) {
  125. if (!$root_id) {
  126. print "<select id=\"$id\" name=\"$id\" default=\"$default_id\" $attributes>";
  127. }
  128. if ($root_id)
  129. $parent_qpart = "parent_cat = '$root_id'";
  130. else
  131. $parent_qpart = "parent_cat IS NULL";
  132. $result = db_query("SELECT id,title,
  133. (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE
  134. c2.parent_cat = ttrss_feed_categories.id) AS num_children
  135. FROM ttrss_feed_categories
  136. WHERE owner_uid = ".$_SESSION["uid"]." AND $parent_qpart ORDER BY title");
  137. while ($line = db_fetch_assoc($result)) {
  138. if ($line["id"] == $default_id) {
  139. $is_selected = "selected=\"1\"";
  140. } else {
  141. $is_selected = "";
  142. }
  143. for ($i = 0; $i < $nest_level; $i++)
  144. $line["title"] = " - " . $line["title"];
  145. if ($line["title"])
  146. printf("<option $is_selected value='%d'>%s</option>",
  147. $line["id"], htmlspecialchars($line["title"]));
  148. if ($line["num_children"] > 0)
  149. print_feed_cat_select($id, $default_id, $attributes,
  150. $include_all_cats, $line["id"], $nest_level+1);
  151. }
  152. if (!$root_id) {
  153. if ($include_all_cats) {
  154. if (db_num_rows($result) > 0) {
  155. print "<option disabled=\"1\">--------</option>";
  156. }
  157. if ($default_id == 0) {
  158. $is_selected = "selected=\"1\"";
  159. } else {
  160. $is_selected = "";
  161. }
  162. print "<option $is_selected value=\"0\">".__('Uncategorized')."</option>";
  163. }
  164. print "</select>";
  165. }
  166. }
  167. function stylesheet_tag($filename) {
  168. $timestamp = filemtime($filename);
  169. return "<link rel=\"stylesheet\" type=\"text/css\" href=\"$filename?$timestamp\"/>\n";
  170. }
  171. function javascript_tag($filename) {
  172. $query = "";
  173. if (!(strpos($filename, "?") === FALSE)) {
  174. $query = substr($filename, strpos($filename, "?")+1);
  175. $filename = substr($filename, 0, strpos($filename, "?"));
  176. }
  177. $timestamp = filemtime($filename);
  178. if ($query) $timestamp .= "&$query";
  179. return "<script type=\"text/javascript\" charset=\"utf-8\" src=\"$filename?$timestamp\"></script>\n";
  180. }
  181. function format_warning($msg, $id = "") {
  182. return "<div class=\"alert\" id=\"$id\">$msg</div>";
  183. }
  184. function format_notice($msg, $id = "") {
  185. return "<div class=\"alert alert-info\" id=\"$id\">$msg</div>";
  186. }
  187. function format_error($msg, $id = "") {
  188. return "<div class=\"alert alert-danger\" id=\"$id\">$msg</div>";
  189. }
  190. function print_notice($msg) {
  191. return print format_notice($msg);
  192. }
  193. function print_warning($msg) {
  194. return print format_warning($msg);
  195. }
  196. function print_error($msg) {
  197. return print format_error($msg);
  198. }
  199. function format_inline_player($url, $ctype) {
  200. $entry = "";
  201. $url = htmlspecialchars($url);
  202. if (strpos($ctype, "audio/") === 0) {
  203. if ($_SESSION["hasAudio"] && (strpos($ctype, "ogg") !== false ||
  204. $_SESSION["hasMp3"])) {
  205. $entry .= "<audio preload=\"none\" controls>
  206. <source type=\"$ctype\" src=\"$url\"/>
  207. </audio>";
  208. } else {
  209. $entry .= "<object type=\"application/x-shockwave-flash\"
  210. data=\"lib/button/musicplayer.swf?song_url=$url\"
  211. width=\"17\" height=\"17\" style='float : left; margin-right : 5px;'>
  212. <param name=\"movie\"
  213. value=\"lib/button/musicplayer.swf?song_url=$url\" />
  214. </object>";
  215. }
  216. if ($entry) $entry .= "&nbsp; <a target=\"_blank\" rel=\"noopener noreferrer\"
  217. href=\"$url\">" . basename($url) . "</a>";
  218. return $entry;
  219. }
  220. return "";
  221. }
  222. function print_label_select($name, $value, $attributes = "") {
  223. $result = db_query("SELECT caption FROM ttrss_labels2
  224. WHERE owner_uid = '".$_SESSION["uid"]."' ORDER BY caption");
  225. print "<select default=\"$value\" name=\"" . htmlspecialchars($name) .
  226. "\" $attributes>";
  227. while ($line = db_fetch_assoc($result)) {
  228. $issel = ($line["caption"] == $value) ? "selected=\"1\"" : "";
  229. print "<option value=\"".htmlspecialchars($line["caption"])."\"
  230. $issel>" . htmlspecialchars($line["caption"]) . "</option>";
  231. }
  232. # print "<option value=\"ADD_LABEL\">" .__("Add label...") . "</option>";
  233. print "</select>";
  234. }