diff options
Diffstat (limited to 'include/functions.php')
-rw-r--r-- | include/functions.php | 161 |
1 files changed, 36 insertions, 125 deletions
diff --git a/include/functions.php b/include/functions.php index e0580a076..73d963803 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,15 +1,9 @@ <?php - define('SCHEMA_VERSION', 141); - define('LABEL_BASE_INDEX', -1024); define('PLUGIN_FEED_BASE_INDEX', -128); - $fetch_last_error = false; - $fetch_last_error_code = false; - $fetch_last_content_type = false; - $fetch_last_error_content = false; // curl only for the time being - $fetch_effective_url = false; - $fetch_curl_used = false; + /** constant is @deprecated, use Config::SCHEMA_VERSION instead */ + define('SCHEMA_VERSION', Config::SCHEMA_VERSION); if (version_compare(PHP_VERSION, '8.0.0', '<')) { libxml_disable_entity_loader(true); @@ -163,73 +157,74 @@ require_once 'controls.php'; require_once 'controls_compat.php'; - define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . get_version() . ' (http://tt-rss.org/)'); + define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . Config::get_version() . ' (http://tt-rss.org/)'); ini_set('user_agent', SELF_USER_AGENT); /* compat shims */ + /** function is @deprecated */ + function get_version() { + return Config::get_version(); + } + + /** function is @deprecated */ + function get_schema_version() { + return Config::get_schema_version(); + } + + /** function is @deprecated */ function _debug($msg) { Debug::log($msg); } - // @deprecated + /** function is @deprecated */ function getFeedUnread($feed, $is_cat = false) { return Feeds::_get_counters($feed, $is_cat, true, $_SESSION["uid"]); } - // @deprecated + /** function is @deprecated */ function sanitize($str, $force_remove_images = false, $owner = false, $site_url = false, $highlight_words = false, $article_id = false) { return Sanitizer::sanitize($str, $force_remove_images, $owner, $site_url, $highlight_words, $article_id); } - // @deprecated + /** function is @deprecated */ function fetch_file_contents($params) { return UrlHelper::fetch($params); } - // @deprecated + /** function is @deprecated */ function rewrite_relative_url($url, $rel_url) { return UrlHelper::rewrite_relative($url, $rel_url); } - // @deprecated + /** function is @deprecated */ function validate_url($url) { return UrlHelper::validate($url); } - // @deprecated + /** function is @deprecated */ function authenticate_user($login, $password, $check_only = false, $service = false) { return UserHelper::authenticate($login, $password, $check_only, $service); } - // @deprecated + /** function is @deprecated */ function smart_date_time($timestamp, $tz_offset = 0, $owner_uid = false, $eta_min = false) { return TimeHelper::smart_date_time($timestamp, $tz_offset, $owner_uid, $eta_min); } - // @deprecated + /** function is @deprecated */ function make_local_datetime($timestamp, $long, $owner_uid = false, $no_smart_dt = false, $eta_min = false) { return TimeHelper::make_local_datetime($timestamp, $long, $owner_uid, $no_smart_dt, $eta_min); } - /* end compat shims */ - - function get_ssl_certificate_id() { - if ($_SERVER["REDIRECT_SSL_CLIENT_M_SERIAL"] ?? false) { - return sha1($_SERVER["REDIRECT_SSL_CLIENT_M_SERIAL"] . - $_SERVER["REDIRECT_SSL_CLIENT_V_START"] . - $_SERVER["REDIRECT_SSL_CLIENT_V_END"] . - $_SERVER["REDIRECT_SSL_CLIENT_S_DN"]); - } - if ($_SERVER["SSL_CLIENT_M_SERIAL"] ?? false) { - return sha1($_SERVER["SSL_CLIENT_M_SERIAL"] . - $_SERVER["SSL_CLIENT_V_START"] . - $_SERVER["SSL_CLIENT_V_END"] . - $_SERVER["SSL_CLIENT_S_DN"]); - } - return ""; + // this returns Config::SELF_URL_PATH sans ending slash + /** function is @deprecated by Config::get_self_url() */ + function get_self_url_prefix() { + return Config::get_self_url(); } + /* end compat shims */ + // this is used for user http parameters unless HTML code is actually needed function clean($param) { if (is_array($param)) { @@ -241,6 +236,14 @@ } } + function with_trailing_slash(string $str) : string { + if (substr($str, -1) === "/") { + return $str; + } else { + return "$str/"; + } + } + function make_password($length = 12) { $password = ""; $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ*%+^"; @@ -303,10 +306,6 @@ return $s ? 1 : 0; } - function get_schema_version() { - return Config::get_schema_version(); - } - function file_is_locked($filename) { if (file_exists(Config::get(Config::LOCK_DIRECTORY) . "/$filename")) { if (function_exists('flock')) { @@ -371,34 +370,6 @@ return vsprintf(_ngettext(array_shift($args), array_shift($args), array_shift($args)), $args); } - function is_server_https() { - return (!empty($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] != 'off')) || - (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'); - } - - function is_prefix_https() { - return parse_url(Config::get(Config::SELF_URL_PATH), PHP_URL_SCHEME) == 'https'; - } - - // this returns Config::get(Config::SELF_URL_PATH) sans ending slash - function get_self_url_prefix() { - if (strrpos(Config::get(Config::SELF_URL_PATH), "/") === strlen(Config::get(Config::SELF_URL_PATH))-1) { - return substr(Config::get(Config::SELF_URL_PATH), 0, strlen(Config::get(Config::SELF_URL_PATH))-1); - } else { - return Config::get(Config::SELF_URL_PATH); - } - } - - function encrypt_password($pass, $salt = '', $mode2 = false) { - if ($salt && $mode2) { - return "MODE2:" . hash('sha256', $salt . $pass); - } else if ($salt) { - return "SHA1X:" . sha1("$salt:$pass"); - } else { - return "SHA1:" . sha1($pass); - } - } // function encrypt_password - function init_plugins() { PluginHost::getInstance()->load(Config::get(Config::PLUGINS), PluginHost::KIND_ALL); @@ -471,63 +442,3 @@ return $ts; } - /* for package maintainers who don't use git: if version_static.txt exists in tt-rss root - directory, its contents are displayed instead of git commit-based version, this could be generated - based on source git tree commit used when creating the package */ - - function get_version(&$git_commit = false, &$git_timestamp = false, &$last_error = false) { - global $ttrss_version; - - if (is_array($ttrss_version) && isset($ttrss_version['version'])) { - $git_commit = $ttrss_version['commit']; - $git_timestamp = $ttrss_version['timestamp']; - $last_error = $ttrss_version['last_error'] ?? ""; - - return $ttrss_version['version']; - } else { - $ttrss_version = []; - } - - $ttrss_version['version'] = "UNKNOWN (Unsupported)"; - - date_default_timezone_set('UTC'); - $root_dir = dirname(__DIR__); - - if (PHP_OS === "Darwin") { - $ttrss_version['version'] = "UNKNOWN (Unsupported, Darwin)"; - } else if (file_exists("$root_dir/version_static.txt")) { - $ttrss_version['version'] = trim(file_get_contents("$root_dir/version_static.txt")) . " (Unsupported)"; - } else if (is_dir("$root_dir/.git")) { - $rc = 0; - $output = []; - - $cwd = getcwd(); - - chdir($root_dir); - exec('git --no-pager log --pretty="version: %ct %h" -n1 HEAD 2>&1', $output, $rc); - chdir($cwd); - - if (is_array($output) && count($output) > 0) { - list ($test, $timestamp, $commit) = explode(" ", $output[0], 3); - - if ($test == "version:") { - $git_commit = $commit; - $git_timestamp = $timestamp; - - $ttrss_version['version'] = strftime("%y.%m", (int)$timestamp) . "-$commit"; - $ttrss_version['commit'] = $commit; - $ttrss_version['timestamp'] = $timestamp; - } - } - - if (!isset($ttrss_version['commit'])) { - $last_error = "Unable to determine version (using $root_dir): RC=$rc; OUTPUT=" . implode("\n", $output); - - $ttrss_version["last_error"] = $last_error; - - user_error($last_error, E_USER_WARNING); - } - } - - return $ttrss_version['version']; - } |