X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=include%2Ffunctions.php;h=8ede14a0bfa7a188b036d8ac704aff70dd7c22a9;hb=a33558a61efc244ad8c809748e6ee64413e3a217;hp=69be5cf3f0d392fc99b64291f3c8408cda144560;hpb=7e9f591d1f172f2f064daaf0c9a73123338887f4;p=tt-rss.git diff --git a/include/functions.php b/include/functions.php index 69be5cf3..8ede14a0 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,6 +1,6 @@ = 0x0090808f) && (OPENSSL_VERSION_NUMBER < 0x10000000)) { + curl_setopt($ch, CURLOPT_SSLVERSION, 3); + } + if ($login && $pass) curl_setopt($ch, CURLOPT_USERPWD, "$login:$pass"); @@ -1058,7 +1087,7 @@ $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 WEEK) "; } break; - case "2weeks": + case "2week": if (DB_TYPE == "pgsql") { $date_qpart = "date_entered < NOW() - INTERVAL '2 week' "; } else { @@ -1501,7 +1530,11 @@ foreach ($feeds as $feed) { $cv = array("id" => PluginHost::pfeed_to_feed_id($feed['id']), "counter" => $feed['sender']->get_unread($feed['id'])); - array_push($ret_arr, $cv); + + if (method_exists($feed['sender'], 'get_total')) + $cv["auxcounter"] = $feed['sender']->get_total($feed['id']); + + array_push($ret_arr, $cv); } } @@ -1875,19 +1908,19 @@ return "images/archive.png"; break; case -1: - return "images/mark_set.svg"; + return "images/star.png"; break; case -2: - return "images/pub_set.svg"; + return "images/feed.png"; break; case -3: return "images/fresh.png"; break; case -4: - return "images/tag.png"; + return "images/folder.png"; break; case -6: - return "images/recently_read.png"; + return "images/time.png"; break; default: if ($id < LABEL_BASE_INDEX) { @@ -2195,6 +2228,7 @@ $keywords = explode(" ", $search); $query_keywords = array(); + $search_words = array(); foreach ($keywords as $k) { if (strpos($k, "-") === 0) { @@ -2214,6 +2248,7 @@ } else { array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))"); + array_push($search_words, $k); } break; case "author": @@ -2223,6 +2258,7 @@ } else { array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))"); + array_push($search_words, $k); } break; case "note": @@ -2237,6 +2273,7 @@ } 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 "star": @@ -2249,6 +2286,7 @@ } 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 "pub": @@ -2261,6 +2299,7 @@ } 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; default: @@ -2276,13 +2315,15 @@ } 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); } } } $search_query_part = implode("AND", $query_keywords); - return $search_query_part; + return array($search_query_part, $search_words); } function getParentCategories($cat, $owner_uid) { @@ -2313,11 +2354,12 @@ return $rv; } - function queryFeedHeadlines($feed, $limit, $view_mode, $cat_view, $search, $search_mode, $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false, $ignore_vfeed_group = false) { + function queryFeedHeadlines($feed, $limit, $view_mode, $cat_view, $search, $search_mode, $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false, $ignore_vfeed_group = false, $override_strategy = false, $override_vfeed = false) { if (!$owner_uid) $owner_uid = $_SESSION["uid"]; $ext_tables_part = ""; + $search_words = array(); if ($search) { @@ -2330,7 +2372,7 @@ $search_query_part = "ref_id = -1 AND "; } else { - $search_query_part = search_to_sql($search); + list($search_query_part, $search_words) = search_to_sql($search); $search_query_part .= " AND "; } @@ -2515,6 +2557,11 @@ $allow_archived = true; if (!$override_order) $override_order = "last_read DESC"; + +/* } else if ($feed == -7) { // shared + $query_strategy_part = "uuid != ''"; + $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; + $allow_archived = true; */ } else if ($feed == -3) { // fresh virtual feed $query_strategy_part = "unread = true AND score >= 0"; @@ -2556,6 +2603,14 @@ $order_by = $override_order; } + if ($override_strategy) { + $query_strategy_part = $override_strategy; + } + + if ($override_vfeed) { + $vfeed_query_part = $override_vfeed; + } + $feed_title = ""; if ($search) { @@ -2578,7 +2633,9 @@ } } - $content_query_part = "content as content_preview, cached_content, "; + + $content_query_part = "content, content AS content_preview, "; + if (is_numeric($feed)) { @@ -2626,6 +2683,8 @@ num_comments, comments, int_id, + uuid, + lang, hide_images, unread,feed_id,marked,published,link,last_read,orig_feed_id, last_marked, last_published, @@ -2668,6 +2727,8 @@ "tag_cache," . "label_cache," . "link," . + "lang," . + "uuid," . "last_read," . "(SELECT hide_images FROM ttrss_feeds WHERE id = feed_id) AS hide_images," . "last_marked, last_published, " . @@ -2719,18 +2780,15 @@ $result = db_query($select_qpart . $from_qpart . $where_qpart); } - return array($result, $feed_title, $feed_site_url, $last_error, $last_updated); + return array($result, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words); } - function sanitize($str, $force_remove_images = false, $owner = false, $site_url = false) { + function sanitize($str, $force_remove_images = false, $owner = false, $site_url = false, $highlight_words = false, $article_id = false) { if (!$owner) $owner = $_SESSION["uid"]; $res = trim($str); if (!$res) return ''; - if (strpos($res, "href=") === false) - $res = rewrite_urls($res); - $charset_hack = ' '; @@ -2812,7 +2870,7 @@ $disallowed_attributes = array('id', 'style', 'class'); foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SANITIZE) as $plugin) { - $retval = $plugin->hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes); + $retval = $plugin->hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes, $article_id); if (is_array($retval)) { $doc = $retval[0]; $allowed_elements = $retval[1]; @@ -2824,7 +2882,39 @@ $doc->removeChild($doc->firstChild); //remove doctype $doc = strip_harmful_tags($doc, $allowed_elements, $disallowed_attributes); + + if ($highlight_words) { + foreach ($highlight_words as $word) { + + // http://stackoverflow.com/questions/4081372/highlight-keywords-in-a-paragraph + + $elements = $xpath->query("//*/text()"); + + foreach ($elements as $child) { + + $fragment = $doc->createDocumentFragment(); + $text = $child->textContent; + $stubs = array(); + + while (($pos = mb_stripos($text, $word)) !== false) { + $fragment->appendChild(new DomText(mb_substr($text, 0, $pos))); + $word = mb_substr($text, $pos, mb_strlen($word)); + $highlight = $doc->createElement('span'); + $highlight->appendChild(new DomText($word)); + $highlight->setAttribute('class', 'highlight'); + $fragment->appendChild($highlight); + $text = mb_substr($text, $pos + mb_strlen($word)); + } + + if (!empty($text)) $fragment->appendChild(new DomText($text)); + + $child->parentNode->replaceChild($fragment, $child); + } + } + } + $res = $doc->saveHTML(); + return $res; } @@ -2973,10 +3063,6 @@ if (preg_match("/^[0-9]*$/", $tag)) return false; if (mb_strlen($tag) > 250) return false; - if (function_exists('iconv')) { - $tag = iconv("utf-8", "utf-8", $tag); - } - if (!$tag) return false; return true; @@ -2992,19 +3078,19 @@ function format_warning($msg, $id = "") { global $link; return "
- $msg
"; + $msg"; } function format_notice($msg, $id = "") { global $link; return "
- $msg
"; + $msg"; } function format_error($msg, $id = "") { global $link; return "
- $msg
"; + $msg"; } function print_notice($msg) { @@ -3093,7 +3179,7 @@ ccache_update($feed_id, $owner_uid); } - $result = db_query("SELECT id,title,link,content,feed_id,comments,int_id, + $result = db_query("SELECT id,title,link,content,feed_id,comments,int_id,lang, ".SUBSTRING_FOR_DATE."(updated,1,16) as updated, (SELECT site_url FROM ttrss_feeds WHERE id = feed_id) as site_url, (SELECT hide_images FROM ttrss_feeds WHERE id = feed_id) as hide_images, @@ -3102,8 +3188,7 @@ tag_cache, author, orig_feed_id, - note, - cached_content + note FROM ttrss_entries,ttrss_user_entries WHERE id = '$id' AND ref_id = id AND owner_uid = $owner_uid"); @@ -3118,7 +3203,7 @@ $line["content"] = sanitize($line["content"], sql_bool_to_bool($line['hide_images']), - $owner_uid, $line["site_url"]); + $owner_uid, $line["site_url"], false, $line["id"]); foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE) as $p) { $line = $p->hook_render_article($line); @@ -3146,6 +3231,21 @@ Tiny Tiny RSS - ".$line["title"]." + "; } @@ -3162,7 +3262,8 @@ $parsed_updated = make_local_datetime($line["updated"], true, $owner_uid, true); - $rv['content'] .= "
$parsed_updated
"; + if (!$zoom_mode) + $rv['content'] .= "
$parsed_updated
"; if ($line["link"]) { $rv['content'] .= "
"; } + if ($zoom_mode) + $rv['content'] .= "
$parsed_updated
"; + $tags_str = format_tags_string($line["tags"], $id); $tags_str_full = join(", ", $line["tags"]); @@ -3247,7 +3351,9 @@ } $rv['content'] .= "
"; - $rv['content'] .= "
"; + if (!$line['lang']) $line['lang'] = 'en'; + + $rv['content'] .= "
"; $rv['content'] .= $line["content"]; $rv['content'] .= format_article_enclosures($id, @@ -3329,6 +3435,11 @@ $cat_id = (int)getFeedCategory($feed_id); + if ($cat_id == 0) + $null_cat_qpart = "cat_id IS NULL OR"; + else + $null_cat_qpart = ""; + $result = db_query("SELECT * FROM ttrss_filters2 WHERE owner_uid = $owner_uid AND enabled = true ORDER BY order_id, title"); @@ -3344,7 +3455,7 @@ FROM ttrss_filters2_rules AS r, ttrss_filter_types AS t WHERE - (cat_id IS NULL OR cat_id IN ($check_cats)) AND + ($null_cat_qpart (cat_id IS NULL AND cat_filter = false) OR cat_id IN ($check_cats)) AND (feed_id IS NULL OR feed_id = '$feed_id') AND filter_type = t.id AND filter_id = '$filter_id'"); @@ -3690,6 +3801,7 @@ $url = $line["content_url"]; $ctype = $line["content_type"]; + $title = $line["title"]; if (!$ctype) $ctype = __("unknown type"); @@ -3712,6 +3824,7 @@ $entry["type"] = $ctype; $entry["filename"] = $filename; $entry["url"] = $url; + $entry["title"] = $title; array_push($entries, $entry); } @@ -3733,7 +3846,10 @@ $rv .= "

" .htmlspecialchars($entry["url"]) . "

"; + } + if ($entry['title']) { + $rv.= "
${entry['title']}
"; } } } @@ -3750,7 +3866,12 @@ ""; foreach ($entries as $entry) { - $rv .= ""; + if ($entry["title"]) + $title = "— " . truncate_string($entry["title"], 30); + else + $title = ""; + + $rv .= ""; }; @@ -3784,7 +3905,7 @@ * @return string Absolute URL */ function rewrite_relative_url($url, $rel_url) { - if (strpos($rel_url, "magnet:") === 0) { + if (strpos($rel_url, ":") !== false) { return $rel_url; } else if (strpos($rel_url, "://") !== false) { return $rel_url; @@ -3899,52 +4020,6 @@ } - function rewrite_urls($html) { - libxml_use_internal_errors(true); - - $charset_hack = ' - - '; - - $doc = new DOMDocument(); - $doc->loadHTML($charset_hack . $html); - $xpath = new DOMXPath($doc); - - $entries = $xpath->query('//*/text()'); - - foreach ($entries as $entry) { - if (strstr($entry->wholeText, "://") !== false) { - $text = preg_replace("/((?\\1", $entry->wholeText); - - if ($text != $entry->wholeText) { - $cdoc = new DOMDocument(); - $cdoc->loadHTML($charset_hack . $text); - - - foreach ($cdoc->childNodes as $cnode) { - $cnode = $doc->importNode($cnode, true); - - if ($cnode) { - $entry->parentNode->insertBefore($cnode); - } - } - - $entry->parentNode->removeChild($entry); - - } - } - } - - $node = $doc->getElementsByTagName('body')->item(0); - - // http://tt-rss.org/forum/viewtopic.php?f=1&t=970 - if ($node) - return $doc->saveXML($node); - else - return $html; - } - function filter_to_sql($filter, $owner_uid) { $query = array(); @@ -3954,6 +4029,7 @@ $reg_qpart = "REGEXP"; foreach ($filter["rules"] AS $rule) { + $rule['reg_exp'] = str_replace('/', '\/', $rule["reg_exp"]); $regexp_valid = preg_match('/' . $rule['reg_exp'] . '/', $rule['reg_exp']) !== FALSE; @@ -4011,6 +4087,8 @@ $qpart .= " AND $cat_qpart"; } + $qpart .= " AND feed_id IS NOT NULL"; + array_push($query, "($qpart)"); } @@ -4088,7 +4166,9 @@ return in_array($interface, class_implements($class)); } - function geturl($url){ + function geturl($url, $depth = 0){ + + if ($depth == 20) return $url; if (!function_exists('curl_init')) return user_error('CURL Must be installed for geturl function to work. Ask your host to enable it or uncomment extension=php_curl.dll in php.ini', E_USER_ERROR); @@ -4115,6 +4195,10 @@ curl_setopt($curl, CURLOPT_TIMEOUT, 60); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + if ((OPENSSL_VERSION_NUMBER >= 0x0090808f) && (OPENSSL_VERSION_NUMBER < 0x10000000)) { + curl_setopt($curl, CURLOPT_SSLVERSION, 3); + } + $html = curl_exec($curl); $status = curl_getinfo($curl); @@ -4127,7 +4211,7 @@ preg_match("/(Location:|URI:)[^(\n)]*/", $header, $matches); $url = trim(str_replace($matches[1],"",$matches[0])); $url_parsed = parse_url($url); - return (isset($url_parsed))? geturl($url):''; + return (isset($url_parsed))? geturl($url, $depth + 1):''; } global $fetch_last_error; @@ -4232,16 +4316,21 @@ } function ngettext(msg1, msg2, n) { - return (parseInt(n) > 1) ? msg2 : msg1; + return __((parseInt(n) > 1) ? msg2 : msg1); }'; $l10n = _get_reader(); for ($i = 0; $i < $l10n->total; $i++) { $orig = $l10n->get_original_string($i); - $translation = __($orig); - - print T_js_decl($orig, $translation); + if(strpos($orig, "\000") !== FALSE) { // Plural forms + $key = explode(chr(0), $orig); + print T_js_decl($key[0], _ngettext($key[0], $key[1], 1)); // Singular + print T_js_decl($key[1], _ngettext($key[0], $key[1], 2)); // Plural + } else { + $translation = __($orig); + print T_js_decl($orig, $translation); + } } }