From 9549e33c2ce6a5d76c59bede2b098fa7457cceba Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 4 May 2017 14:22:23 +0300 Subject: [PATCH] move some common control-generating functions to controls.php --- include/controls.php | 302 +++++++++++++++++++++++++++++++++++++++++ include/functions.php | 222 +----------------------------- include/functions2.php | 100 -------------- 3 files changed, 303 insertions(+), 321 deletions(-) create mode 100644 include/controls.php diff --git a/include/controls.php b/include/controls.php new file mode 100644 index 000000000..0c5683082 --- /dev/null +++ b/include/controls.php @@ -0,0 +1,302 @@ +"; + foreach ($values as $v) { + if ($v == $default) + $sel = "selected=\"1\""; + else + $sel = ""; + + $v = trim($v); + + print ""; + } + print ""; +} + +function print_select_hash($id, $default, $values, $attributes = "", $name = "") { + if (!$name) $name = $id; + + print ""; +} + +function print_hidden($name, $value) { + print ""; +} + +function print_checkbox($id, $checked, $value = "", $attributes = "") { + $checked_str = $checked ? "checked" : ""; + $value_str = $value ? "value=\"$value\"" : ""; + + print ""; +} + +function print_button($type, $value, $attributes = "") { + print "

"; +} + +function print_radio($id, $default, $true_is, $values, $attributes = "") { + foreach ($values as $v) { + + if ($v == $default) + $sel = "checked"; + else + $sel = ""; + + if ($v == $true_is) { + $sel .= " value=\"1\""; + } else { + $sel .= " value=\"0\""; + } + + print " $v "; + + } +} + +function print_feed_select($id, $default_id = "", + $attributes = "", $include_all_feeds = true, + $root_id = false, $nest_level = 0) { + + if (!$root_id) { + print ""; + } +} + +function print_feed_cat_select($id, $default_id, + $attributes, $include_all_cats = true, $root_id = false, $nest_level = 0) { + + if (!$root_id) { + print ""; + } +} + +function stylesheet_tag($filename) { + $timestamp = filemtime($filename); + + return "\n"; +} + +function javascript_tag($filename) { + $query = ""; + + if (!(strpos($filename, "?") === FALSE)) { + $query = substr($filename, strpos($filename, "?")+1); + $filename = substr($filename, 0, strpos($filename, "?")); + } + + $timestamp = filemtime($filename); + + if ($query) $timestamp .= "&$query"; + + return "\n"; +} + +function format_warning($msg, $id = "") { + return "

$msg
"; +} + +function format_notice($msg, $id = "") { + return "
$msg
"; +} + +function format_error($msg, $id = "") { + return "
$msg
"; +} + +function print_notice($msg) { + return print format_notice($msg); +} + +function print_warning($msg) { + return print format_warning($msg); +} + +function print_error($msg) { + return print format_error($msg); +} + +function format_inline_player($url, $ctype) { + + $entry = ""; + + $url = htmlspecialchars($url); + + if (strpos($ctype, "audio/") === 0) { + + if ($_SESSION["hasAudio"] && (strpos($ctype, "ogg") !== false || + $_SESSION["hasMp3"])) { + + $entry .= ""; + + } else { + + $entry .= " + + "; + } + + if ($entry) $entry .= "  " . basename($url) . ""; + + return $entry; + + } + + return ""; +} diff --git a/include/functions.php b/include/functions.php index baeaa03ab..58fe1fe5d 100644 --- a/include/functions.php +++ b/include/functions.php @@ -136,6 +136,7 @@ require_once 'version.php'; require_once 'ccache.php'; require_once 'labels.php'; + require_once 'controls.php'; define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . VERSION . ' (http://tt-rss.org/)'); ini_set('user_agent', SELF_USER_AGENT); @@ -628,76 +629,6 @@ } } - function print_select($id, $default, $values, $attributes = "", $name = "") { - if (!$name) $name = $id; - - print ""; - } - - function print_select_hash($id, $default, $values, $attributes = "", $name = "") { - if (!$name) $name = $id; - - print ""; - } - - function print_hidden($name, $value) { - print ""; - } - - function print_checkbox($id, $checked, $value = "", $attributes = "") { - $checked_str = $checked ? "checked" : ""; - $value_str = $value ? "value=\"$value\"" : ""; - - print ""; - } - - function print_button($type, $value, $attributes = "") { - print "

"; - } - - function print_radio($id, $default, $true_is, $values, $attributes = "") { - foreach ($values as $v) { - - if ($v == $default) - $sel = "checked"; - else - $sel = ""; - - if ($v == $true_is) { - $sel .= " value=\"1\""; - } else { - $sel .= " value=\"0\""; - } - - print " $v "; - - } - } - function initialize_user_prefs($uid, $profile = false) { $uid = db_escape_string($uid); @@ -1815,157 +1746,6 @@ } } - function print_feed_select($id, $default_id = "", - $attributes = "", $include_all_feeds = true, - $root_id = false, $nest_level = 0) { - - if (!$root_id) { - print ""; - } - } - - function print_feed_cat_select($id, $default_id, - $attributes, $include_all_cats = true, $root_id = false, $nest_level = 0) { - - if (!$root_id) { - print ""; - } - } - function checkbox_to_sql_bool($val) { return ($val == "on") ? "true" : "false"; } diff --git a/include/functions2.php b/include/functions2.php index 97077e9da..71618b88b 100644 --- a/include/functions2.php +++ b/include/functions2.php @@ -1206,77 +1206,11 @@ exit; } - function format_warning($msg, $id = "") { - return "

$msg
"; - } - - function format_notice($msg, $id = "") { - return "
$msg
"; - } - - function format_error($msg, $id = "") { - return "
$msg
"; - } - - function print_notice($msg) { - return print format_notice($msg); - } - - function print_warning($msg) { - return print format_warning($msg); - } - - function print_error($msg) { - return print format_error($msg); - } - - function T_sprintf() { $args = func_get_args(); return vsprintf(__(array_shift($args)), $args); } - function format_inline_player($url, $ctype) { - - $entry = ""; - - $url = htmlspecialchars($url); - - if (strpos($ctype, "audio/") === 0) { - - if ($_SESSION["hasAudio"] && (strpos($ctype, "ogg") !== false || - $_SESSION["hasMp3"])) { - - $entry .= ""; - - } else { - - $entry .= " - - "; - } - - if ($entry) $entry .= "  " . basename($url) . ""; - - return $entry; - - } - - return ""; - -/* $filename = substr($url, strrpos($url, "/")+1); - - $entry .= " " . - $filename . " (" . $ctype . ")" . ""; */ - - } - function format_article($id, $mark_as_read = true, $zoom_mode = false, $owner_uid = false) { if (!$owner_uid) $owner_uid = $_SESSION["uid"]; @@ -2305,19 +2239,6 @@ return null; } - function tmpdirname($path, $prefix) { - // Use PHP's tmpfile function to create a temporary - // directory name. Delete the file and keep the name. - $tempname = tempnam($path,$prefix); - if (!$tempname) - return false; - - if (!unlink($tempname)) - return false; - - return $tempname; - } - function getFeedCategory($feed) { $result = db_query("SELECT cat_id FROM ttrss_feeds WHERE id = '$feed'"); @@ -2369,27 +2290,6 @@ return $rv; } - function stylesheet_tag($filename) { - $timestamp = filemtime($filename); - - return "\n"; - } - - function javascript_tag($filename) { - $query = ""; - - if (!(strpos($filename, "?") === FALSE)) { - $query = substr($filename, strpos($filename, "?")+1); - $filename = substr($filename, 0, strpos($filename, "?")); - } - - $timestamp = filemtime($filename); - - if ($query) $timestamp .= "&$query"; - - return "\n"; - } - function calculate_dep_timestamp() { $files = array_merge(glob("js/*.js"), glob("css/*.css"));