X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=include%2Ffunctions2.php;h=a73f9a7a786342f0563e77680937fdbaffefbee0;hb=27f7b59353a076120407d8873ea86f5eea7d1dcf;hp=57475183aae0b08031a98521a60f3826d8f321a7;hpb=31460f84fe350a04fd796763c4a444dcd10c7338;p=tt-rss.git diff --git a/include/functions2.php b/include/functions2.php index 57475183..a73f9a7a 100644 --- a/include/functions2.php +++ b/include/functions2.php @@ -18,6 +18,11 @@ $params["bw_limit"] = (int) $_SESSION["bw_limit"]; $params["label_base_index"] = (int) LABEL_BASE_INDEX; + $theme = get_pref( "USER_CSS_THEME", false, false); + $params["theme"] = theme_valid("$theme") ? $theme : ""; + + $params["plugins"] = implode(", ", PluginHost::getInstance()->get_plugin_names()); + $params["php_platform"] = PHP_OS; $params["php_version"] = PHP_VERSION; @@ -198,6 +203,26 @@ return array($prefixes, $hotkeys); } + function check_for_update() { + if (defined("GIT_VERSION_TIMESTAMP")) { + $content = @fetch_file_contents("http://tt-rss.org/version.json"); + + if ($content) { + $content = json_decode($content, true); + + if ($content && isset($content["changeset"])) { + if ((int)GIT_VERSION_TIMESTAMP < (int)$content["changeset"]["timestamp"] && + GIT_VERSION_HEAD != $content["changeset"]["id"]) { + + return $content["changeset"]["id"]; + } + } + } + } + + return ""; + } + function make_runtime_info() { $data = array(); @@ -216,6 +241,15 @@ $data['dep_ts'] = calculate_dep_timestamp(); $data['reload_on_ts_change'] = !defined('_NO_RELOAD_ON_TS_CHANGE'); + + if (CHECK_FOR_UPDATES && $_SESSION["last_version_check"] + 86400 + rand(-1000, 1000) < time()) { + $update_result = @check_for_update(); + + $data["update_result"] = $update_result; + + $_SESSION["last_version_check"] = time(); + } + if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) { $data['daemon_is_running'] = (int) file_is_locked("update_daemon.lock"); @@ -243,15 +277,6 @@ } } - if ($_SESSION["last_version_check"] + 86400 + rand(-1000, 1000) < time()) { - $new_version_details = @check_for_update(); - - $data['new_version_available'] = (int) ($new_version_details != false); - - $_SESSION["last_version_check"] = time(); - $_SESSION["version_data"] = $new_version_details; - } - return $data; } @@ -329,6 +354,19 @@ else array_push($query_keywords, "($not (published = false))"); + } else { + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') + OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))"); + if (!$not) array_push($search_words, $k); + } + break; + case "unread": + if ($commandpair[1]) { + if ($commandpair[1] == "true") + array_push($query_keywords, "($not (unread = true))"); + else + array_push($query_keywords, "($not (unread = false))"); + } else { array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))"); @@ -395,20 +433,16 @@ $search_words = array(); if ($search) { + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH) as $plugin) { + list($search_query_part, $search_words) = $plugin->hook_search($search); + break; + } - if (SPHINX_ENABLED) { - $ids = join(",", @sphinx_search($search, 0, 500)); - - if ($ids) - $search_query_part = "ref_id IN ($ids) AND "; - else - $search_query_part = "ref_id = -1 AND "; - - } else { + // fall back in case of no plugins + if (!$search_query_part) { list($search_query_part, $search_words) = search_to_sql($search); - $search_query_part .= " AND "; } - + $search_query_part .= " AND "; } else { $search_query_part = ""; } @@ -428,8 +462,10 @@ // Try to check if SQL regexp implementation chokes on a valid regexp - $result = db_query("SELECT true AS true_val FROM ttrss_entries, - ttrss_user_entries, ttrss_feeds + $result = db_query("SELECT true AS true_val + FROM ttrss_entries + JOIN ttrss_user_entries ON ttrss_entries.id = ttrss_user_entries.ref_id + JOIN ttrss_feeds ON ttrss_feeds.id = ttrss_user_entries.feed_id WHERE $filter_query_part LIMIT 1", false); if ($result) { @@ -629,10 +665,6 @@ $order_by = "score DESC, date_entered DESC, updated DESC"; - if ($view_mode == "unread_first") { - $order_by = "unread DESC, $order_by"; - } - if ($override_order) { $order_by = $override_order; } @@ -826,6 +858,21 @@ } + function iframe_whitelisted($entry) { + $whitelist = array("youtube.com", "youtu.be", "vimeo.com"); + + @$src = parse_url($entry->getAttribute("src"), PHP_URL_HOST); + + if ($src) { + foreach ($whitelist as $w) { + if ($src == $w || $src == "www.$w") + return true; + } + } + + return false; + } + function sanitize($str, $force_remove_images = false, $owner = false, $site_url = false, $highlight_words = false, $article_id = false) { if (!$owner) $owner = $_SESSION["uid"]; @@ -862,7 +909,7 @@ $cached_filename = CACHE_DIR . '/images/' . sha1($src) . '.png'; if (file_exists($cached_filename)) { - $src = SELF_URL_PATH . '/image.php?hash=' . sha1($src); + $src = SELF_URL_PATH . '/public.php?op=cached_image&hash=' . sha1($src); } $entry->setAttribute('src', $src); @@ -894,8 +941,15 @@ $entries = $xpath->query('//iframe'); foreach ($entries as $entry) { - $entry->setAttribute('sandbox', 'allow-scripts'); - + if (!iframe_whitelisted($entry)) { + $entry->setAttribute('sandbox', 'allow-scripts'); + } else { + if ($_SERVER['HTTPS'] == "on") { + $entry->setAttribute("src", + str_replace("http://", "https://", + $entry->getAttribute("src"))); + } + } } $allowed_elements = array('a', 'address', 'audio', 'article', 'aside', @@ -994,25 +1048,6 @@ return $doc; } - function check_for_update() { - if (CHECK_FOR_NEW_VERSION && $_SESSION['access_level'] >= 10) { - $version_url = "http://tt-rss.org/version.php?ver=" . VERSION . - "&iid=" . sha1(SELF_URL_PATH); - - $version_data = @fetch_file_contents($version_url); - - if ($version_data) { - $version_data = json_decode($version_data, true); - if ($version_data && $version_data['version']) { - if (version_compare(VERSION_STATIC, $version_data['version']) == -1) { - return $version_data; - } - } - } - } - return false; - } - function catchupArticlesById($ids, $cmode, $owner_uid = false) { if (!$owner_uid) $owner_uid = $_SESSION["uid"]; @@ -1747,7 +1782,7 @@ return $rv; } - function save_email_address($email) { + /* function save_email_address($email) { // FIXME: implement persistent storage of emails if (!$_SESSION['stored_emails']) @@ -1755,7 +1790,7 @@ if (!in_array($email, $_SESSION['stored_emails'])) array_push($_SESSION['stored_emails'], $email); - } + } */ function get_feed_access_key($feed_id, $is_cat, $owner_uid = false) { @@ -1848,8 +1883,17 @@ $result = get_article_enclosures($id); $rv = ''; - if (count($result) > 0) { + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ENCLOSURES) as $plugin) { + $retval = $plugin->hook_format_enclosures($rv, $result, $id, $always_display_enclosures, $article_content, $hide_images); + if (is_array($retval)) { + $rv = $retval[0]; + $result = $retval[1]; + } else { + $rv = $retval; + } + } + if ($rv === '' && !empty($result)) { $entries_html = array(); $entries = array(); $entries_inline = array(); @@ -1859,6 +1903,8 @@ $url = $line["content_url"]; $ctype = $line["content_type"]; $title = $line["title"]; + $width = $line["width"]; + $height = $line["height"]; if (!$ctype) $ctype = __("unknown type"); @@ -1882,6 +1928,8 @@ $entry["filename"] = $filename; $entry["url"] = $url; $entry["title"] = $title; + $entry["width"] = $width; + $entry["height"] = $height; array_push($entries, $entry); } @@ -1896,9 +1944,15 @@ preg_match("/\.(jpg|png|gif|bmp)/i", $entry["filename"])) { if (!$hide_images) { + $encsize = ''; + if ($entry['height'] > 0) + $encsize .= ' height="' . intval($entry['width']) . '"'; + if ($entry['width'] > 0) + $encsize .= ' width="' . intval($entry['height']) . '"'; $rv .= "

\"".htmlspecialchars($entry["filename"])."\"

"; + src=\"" .htmlspecialchars($entry["url"]) . "\" + " . $encsize . " />

"; } else { $rv .= "

SetServer($sphinxpair[0], (int)$sphinxpair[1]); - $sphinxClient->SetConnectTimeout(1); - - $sphinxClient->SetFieldWeights(array('title' => 70, 'content' => 30, - 'feed_title' => 20)); - - $sphinxClient->SetMatchMode(SPH_MATCH_EXTENDED2); - $sphinxClient->SetRankingMode(SPH_RANK_PROXIMITY_BM25); - $sphinxClient->SetLimits($offset, $limit, 1000); - $sphinxClient->SetArrayResult(false); - $sphinxClient->SetFilter('owner_uid', array($_SESSION['uid'])); - - $result = $sphinxClient->Query($query, SPHINX_INDEX); - - $ids = array(); - - if (is_array($result['matches'])) { - foreach (array_keys($result['matches']) as $int_id) { - $ref_id = $result['matches'][$int_id]['attrs']['ref_id']; - array_push($ids, $ref_id); - } - } - - return $ids; - } - function cleanup_tags($days = 14, $limit = 1000) { if (DB_TYPE == "pgsql") { @@ -2223,7 +2244,7 @@ return in_array($interface, class_implements($class)); } - function geturl($url, $depth = 0){ + function geturl($url, $depth = 0, $nobody = true){ if ($depth == 20) return $url; @@ -2244,6 +2265,7 @@ curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0 Firefox/5.0'); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt($curl, CURLOPT_HEADER, true); + curl_setopt($curl, CURLOPT_NOBODY, $nobody); curl_setopt($curl, CURLOPT_REFERER, $url); curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($curl, CURLOPT_AUTOREFERER, true); @@ -2256,15 +2278,18 @@ curl_setopt($curl, CURLOPT_PROXY, _CURL_HTTP_PROXY); } - if ((OPENSSL_VERSION_NUMBER >= 0x0090808f) && (OPENSSL_VERSION_NUMBER < 0x10000000)) { - curl_setopt($curl, CURLOPT_SSLVERSION, 3); - } - $html = curl_exec($curl); $status = curl_getinfo($curl); if($status['http_code']!=200){ + + // idiot site not allowing http head + if($status['http_code'] == 405) { + curl_close($curl); + return geturl($url, $depth +1, false); + } + if($status['http_code'] == 301 || $status['http_code'] == 302) { curl_close($curl); list($header) = explode("\r\n\r\n", $html, 2); @@ -2300,19 +2325,26 @@ if (!isset($_GET['debug'])) { $cached_file = CACHE_DIR . "/js/".basename($js).".js"; - if (file_exists($cached_file) && - is_readable($cached_file) && - filemtime($cached_file) >= filemtime("js/$js.js")) { + if (file_exists($cached_file) && is_readable($cached_file) && filemtime($cached_file) >= filemtime("js/$js.js")) { - $rv .= file_get_contents($cached_file); + list($header, $contents) = explode("\n", file_get_contents($cached_file), 2); - } else { - $minified = JShrink\Minifier::minify(file_get_contents("js/$js.js")); - file_put_contents($cached_file, $minified); - $rv .= $minified; + if ($header && $contents) { + list($htag, $hversion) = explode(":", $header); + + if ($htag == "tt-rss" && $hversion == VERSION) { + $rv .= $contents; + continue; + } + } } + + $minified = JShrink\Minifier::minify(file_get_contents("js/$js.js")); + file_put_contents($cached_file, "tt-rss:" . VERSION . "\n" . $minified); + $rv .= $minified; + } else { - $rv .= file_get_contents("js/$js.js"); + $rv .= file_get_contents("js/$js.js"); // no cache in debug mode } } @@ -2403,9 +2435,31 @@ return LABEL_BASE_INDEX - 1 + abs($feed); } - function format_libxml_error($error) { - return T_sprintf("LibXML error %s at line %d (column %d): %s", - $error->code, $error->line, $error->column, - $error->message); + function theme_valid($file) { + if ($file == "default.css" || $file == "night.css") return true; // needed for array_filter + $file = "themes/" . basename($file); + + if (file_exists($file) && is_readable($file)) { + $fh = fopen($file, "r"); + + if ($fh) { + $header = fgets($fh); + fclose($fh); + + return strpos($header, "supports-version:" . VERSION_STATIC) !== FALSE; + } + } + + return false; + } + + function error_json($code) { + require_once "errors.php"; + + @$message = $ERRORS[$code]; + + return json_encode(array("error" => + array("code" => $code, "message" => $message))); + } ?>