X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=include%2Ffunctions2.php;h=deeaaf2109f5c93479e2d61f4042a60c451189d5;hb=ae962a96fdba3fcc14b60d48f0db48bb7f3b243e;hp=2cf4af22e22a71ce4ee23ec0e5392961b4db746b;hpb=3e8a79be6d49d06c3a11be832123f94e0f212a3e;p=tt-rss.git diff --git a/include/functions2.php b/include/functions2.php index 2cf4af22..deeaaf21 100644 --- a/include/functions2.php +++ b/include/functions2.php @@ -18,6 +18,7 @@ $params["bw_limit"] = (int) $_SESSION["bw_limit"]; $params["label_base_index"] = (int) LABEL_BASE_INDEX; $params["theme"] = get_pref("USER_CSS_THEME", false, false); + $params["plugins"] = implode(", ", PluginHost::getInstance()->get_plugin_names()); $params["php_platform"] = PHP_OS; $params["php_version"] = PHP_VERSION; @@ -396,20 +397,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 = ""; } @@ -429,8 +426,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) { @@ -1748,7 +1747,7 @@ return $rv; } - function save_email_address($email) { + /* function save_email_address($email) { // FIXME: implement persistent storage of emails if (!$_SESSION['stored_emails']) @@ -1756,7 +1755,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) { @@ -1849,8 +1848,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(); @@ -1860,6 +1868,8 @@ $url = $line["content_url"]; $ctype = $line["content_type"]; $title = $line["title"]; + $width = $line["width"]; + $height = $line["height"]; if (!$ctype) $ctype = __("unknown type"); @@ -1883,6 +1893,8 @@ $entry["filename"] = $filename; $entry["url"] = $url; $entry["title"] = $title; + $entry["width"] = $width; + $entry["height"] = $height; array_push($entries, $entry); } @@ -1897,9 +1909,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") { @@ -2224,7 +2209,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; @@ -2245,6 +2230,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); @@ -2266,6 +2252,13 @@ $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); @@ -2301,19 +2294,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 } }