controls.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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_multi_select($id, $default_ids = [],
  55. $attributes = "", $include_all_feeds = true,
  56. $root_id = null, $nest_level = 0) {
  57. $pdo = DB::pdo();
  58. print_r(in_array("CAT:6",$default_ids));
  59. if (!$root_id) {
  60. print "<select multiple=\true\" id=\"$id\" name=\"$id\" $attributes>";
  61. if ($include_all_feeds) {
  62. $is_selected = (in_array("0", $default_ids)) ? "selected=\"1\"" : "";
  63. print "<option $is_selected value=\"0\">".__('All feeds')."</option>";
  64. }
  65. }
  66. if (get_pref('ENABLE_FEED_CATS')) {
  67. if (!$root_id) $root_id = null;
  68. $sth = $pdo->prepare("SELECT id,title,
  69. (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE
  70. c2.parent_cat = ttrss_feed_categories.id) AS num_children
  71. FROM ttrss_feed_categories
  72. WHERE owner_uid = :uid AND
  73. (parent_cat = :root_id OR (:root_id IS NULL AND parent_cat IS NULL)) ORDER BY title");
  74. $sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]);
  75. while ($line = $sth->fetch()) {
  76. for ($i = 0; $i < $nest_level; $i++)
  77. $line["title"] = " - " . $line["title"];
  78. $is_selected = in_array("CAT:".$line["id"], $default_ids) ? "selected=\"1\"" : "";
  79. printf("<option $is_selected value='CAT:%d'>%s</option>",
  80. $line["id"], htmlspecialchars($line["title"]));
  81. if ($line["num_children"] > 0)
  82. print_feed_multi_select($id, $default_ids, $attributes,
  83. $include_all_feeds, $line["id"], $nest_level+1);
  84. $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds
  85. WHERE cat_id = ? AND owner_uid = ? ORDER BY title");
  86. $f_sth->execute([$line['id'], $_SESSION['uid']]);
  87. while ($fline = $f_sth->fetch()) {
  88. $is_selected = (in_array($fline["id"], $default_ids)) ? "selected=\"1\"" : "";
  89. $fline["title"] = " + " . $fline["title"];
  90. for ($i = 0; $i < $nest_level; $i++)
  91. $fline["title"] = " - " . $fline["title"];
  92. printf("<option $is_selected value='%d'>%s</option>",
  93. $fline["id"], htmlspecialchars($fline["title"]));
  94. }
  95. }
  96. if (!$root_id) {
  97. $is_selected = in_array("CAT:0", $default_ids) ? "selected=\"1\"" : "";
  98. printf("<option $is_selected value='CAT:0'>%s</option>",
  99. __("Uncategorized"));
  100. $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds
  101. WHERE cat_id IS NULL AND owner_uid = ? ORDER BY title");
  102. $f_sth->execute([$_SESSION['uid']]);
  103. while ($fline = $f_sth->fetch()) {
  104. $is_selected = in_array($fline["id"], $default_ids) ? "selected=\"1\"" : "";
  105. $fline["title"] = " + " . $fline["title"];
  106. for ($i = 0; $i < $nest_level; $i++)
  107. $fline["title"] = " - " . $fline["title"];
  108. printf("<option $is_selected value='%d'>%s</option>",
  109. $fline["id"], htmlspecialchars($fline["title"]));
  110. }
  111. }
  112. } else {
  113. $sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds
  114. WHERE owner_uid = ? ORDER BY title");
  115. $sth->execute([$_SESSION['uid']]);
  116. while ($line = $sth->fetch()) {
  117. $is_selected = (in_array($line["id"], $default_ids)) ? "selected=\"1\"" : "";
  118. printf("<option $is_selected value='%d'>%s</option>",
  119. $line["id"], htmlspecialchars($line["title"]));
  120. }
  121. }
  122. if (!$root_id) {
  123. print "</select>";
  124. }
  125. }
  126. function print_feed_cat_select($id, $default_id,
  127. $attributes, $include_all_cats = true, $root_id = null, $nest_level = 0) {
  128. if (!$root_id) {
  129. print "<select id=\"$id\" name=\"$id\" default=\"$default_id\" $attributes>";
  130. }
  131. $pdo = DB::pdo();
  132. if (!$root_id) $root_id = null;
  133. $sth = $pdo->prepare("SELECT id,title,
  134. (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE
  135. c2.parent_cat = ttrss_feed_categories.id) AS num_children
  136. FROM ttrss_feed_categories
  137. WHERE owner_uid = :uid AND
  138. (parent_cat = :root_id OR (:root_id IS NULL AND parent_cat IS NULL)) ORDER BY title");
  139. $sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]);
  140. $found = 0;
  141. while ($line = $sth->fetch()) {
  142. ++$found;
  143. if ($line["id"] == $default_id) {
  144. $is_selected = "selected=\"1\"";
  145. } else {
  146. $is_selected = "";
  147. }
  148. for ($i = 0; $i < $nest_level; $i++)
  149. $line["title"] = " - " . $line["title"];
  150. if ($line["title"])
  151. printf("<option $is_selected value='%d'>%s</option>",
  152. $line["id"], htmlspecialchars($line["title"]));
  153. if ($line["num_children"] > 0)
  154. print_feed_cat_select($id, $default_id, $attributes,
  155. $include_all_cats, $line["id"], $nest_level+1);
  156. }
  157. if (!$root_id) {
  158. if ($include_all_cats) {
  159. if ($found > 0) {
  160. print "<option disabled=\"1\">--------</option>";
  161. }
  162. if ($default_id == 0) {
  163. $is_selected = "selected=\"1\"";
  164. } else {
  165. $is_selected = "";
  166. }
  167. print "<option $is_selected value=\"0\">".__('Uncategorized')."</option>";
  168. }
  169. print "</select>";
  170. }
  171. }
  172. function stylesheet_tag($filename) {
  173. $timestamp = filemtime($filename);
  174. return "<link rel=\"stylesheet\" type=\"text/css\" href=\"$filename?$timestamp\"/>\n";
  175. }
  176. function javascript_tag($filename) {
  177. $query = "";
  178. if (!(strpos($filename, "?") === FALSE)) {
  179. $query = substr($filename, strpos($filename, "?")+1);
  180. $filename = substr($filename, 0, strpos($filename, "?"));
  181. }
  182. $timestamp = filemtime($filename);
  183. if ($query) $timestamp .= "&$query";
  184. return "<script type=\"text/javascript\" charset=\"utf-8\" src=\"$filename?$timestamp\"></script>\n";
  185. }
  186. function format_warning($msg, $id = "") {
  187. return "<div class=\"alert\" id=\"$id\">$msg</div>";
  188. }
  189. function format_notice($msg, $id = "") {
  190. return "<div class=\"alert alert-info\" id=\"$id\">$msg</div>";
  191. }
  192. function format_error($msg, $id = "") {
  193. return "<div class=\"alert alert-danger\" id=\"$id\">$msg</div>";
  194. }
  195. function print_notice($msg) {
  196. return print format_notice($msg);
  197. }
  198. function print_warning($msg) {
  199. return print format_warning($msg);
  200. }
  201. function print_error($msg) {
  202. return print format_error($msg);
  203. }
  204. function format_inline_player($url, $ctype) {
  205. $entry = "";
  206. $url = htmlspecialchars($url);
  207. if (strpos($ctype, "audio/") === 0) {
  208. if ($_SESSION["hasAudio"] && (strpos($ctype, "ogg") !== false ||
  209. $_SESSION["hasMp3"])) {
  210. $entry .= "<audio preload=\"none\" controls>
  211. <source type=\"$ctype\" src=\"$url\"/>
  212. </audio>";
  213. }
  214. if ($entry) $entry .= "&nbsp; <a target=\"_blank\" rel=\"noopener noreferrer\"
  215. href=\"$url\">" . basename($url) . "</a>";
  216. return $entry;
  217. }
  218. return "";
  219. }
  220. function print_label_select($name, $value, $attributes = "") {
  221. $pdo = Db::pdo();
  222. $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2
  223. WHERE owner_uid = ? ORDER BY caption");
  224. $sth->execute([$_SESSION['uid']]);
  225. print "<select default=\"$value\" name=\"" . htmlspecialchars($name) .
  226. "\" $attributes>";
  227. while ($line = $sth->fetch()) {
  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. }