X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=include%2Ffunctions.php;h=8ede14a0bfa7a188b036d8ac704aff70dd7c22a9;hb=a33558a61efc244ad8c809748e6ee64413e3a217;hp=ef5905fe2e118442e2427857ff8cd7da6853df18;hpb=8d476359199e063a4e9ca29608f9d0dcb99d96f9;p=tt-rss.git diff --git a/include/functions.php b/include/functions.php index ef5905fe..8ede14a0 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,6 +1,6 @@ '; @@ -2837,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]; @@ -2849,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; } @@ -2998,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; @@ -3118,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, @@ -3142,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); @@ -3201,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"]); @@ -3286,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, @@ -3368,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"); @@ -3383,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'"); @@ -3729,6 +3801,7 @@ $url = $line["content_url"]; $ctype = $line["content_type"]; + $title = $line["title"]; if (!$ctype) $ctype = __("unknown type"); @@ -3751,6 +3824,7 @@ $entry["type"] = $ctype; $entry["filename"] = $filename; $entry["url"] = $url; + $entry["title"] = $title; array_push($entries, $entry); } @@ -3772,7 +3846,10 @@ $rv .= "

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

"; + } + if ($entry['title']) { + $rv.= "
${entry['title']}
"; } } } @@ -3789,7 +3866,12 @@ ""; foreach ($entries as $entry) { - $rv .= ""; + if ($entry["title"]) + $title = "— " . truncate_string($entry["title"], 30); + else + $title = ""; + + $rv .= ""; }; @@ -3938,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(); @@ -4051,6 +4087,8 @@ $qpart .= " AND $cat_qpart"; } + $qpart .= " AND feed_id IS NOT NULL"; + array_push($query, "($qpart)"); }