X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=include%2Ffunctions.php;h=3ac413667d61a299837a7b8d0cd89715a3dd0739;hb=924a89ebf33b5ce82a76aa4f9b4726cb60282528;hp=238c017c5a6eff33095f7781edc1a0f2673af854;hpb=893960b039284fcd240fb3113fdfa86cc1331223;p=tt-rss.git diff --git a/include/functions.php b/include/functions.php index 238c017c..3ac41366 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,6 +1,6 @@ NOW() - INTERVAL '$intl hour' "; + $match_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' "; } else { - $match_part .= " AND updated > DATE_SUB(NOW(), INTERVAL $intl HOUR) "; + $match_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) "; } $need_entries = true; @@ -1522,13 +1561,10 @@ $owner_uid = $_SESSION["uid"]; - $result = db_query("SELECT id,caption,COUNT(u1.unread) AS unread,COUNT(u2.unread) AS total + $result = db_query("SELECT id,caption,SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS unread, COUNT(u1.unread) AS total FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON (ttrss_labels2.id = label_id) - LEFT JOIN ttrss_user_entries AS u1 ON (u1.ref_id = article_id AND u1.unread = true - AND u1.owner_uid = $owner_uid) - LEFT JOIN ttrss_user_entries AS u2 ON (u2.ref_id = article_id AND u2.unread = false - AND u2.owner_uid = $owner_uid) + LEFT JOIN ttrss_user_entries AS u1 ON u1.ref_id = article_id WHERE ttrss_labels2.owner_uid = $owner_uid GROUP BY ttrss_labels2.id, ttrss_labels2.caption"); @@ -2203,6 +2239,7 @@ $keywords = explode(" ", $search); $query_keywords = array(); + $search_words = array(); foreach ($keywords as $k) { if (strpos($k, "-") === 0) { @@ -2222,6 +2259,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": @@ -2231,6 +2269,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": @@ -2245,6 +2284,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": @@ -2257,6 +2297,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": @@ -2269,6 +2310,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: @@ -2284,13 +2326,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) { @@ -2326,6 +2370,7 @@ if (!$owner_uid) $owner_uid = $_SESSION["uid"]; $ext_tables_part = ""; + $search_words = array(); if ($search) { @@ -2338,7 +2383,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 "; } @@ -2650,6 +2695,7 @@ comments, int_id, uuid, + lang, hide_images, unread,feed_id,marked,published,link,last_read,orig_feed_id, last_marked, last_published, @@ -2692,6 +2738,7 @@ "tag_cache," . "label_cache," . "link," . + "lang," . "uuid," . "last_read," . "(SELECT hide_images FROM ttrss_feeds WHERE id = feed_id) AS hide_images," . @@ -2744,18 +2791,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 = ' '; @@ -2837,7 +2881,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]; @@ -2847,9 +2891,53 @@ } } - $doc->removeChild($doc->firstChild); //remove doctype + $doc->removeChild($doc->doctype); //remove doctype $doc = strip_harmful_tags($doc, $allowed_elements, $disallowed_attributes); - $res = $doc->saveHTML(); + + 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); + } + } + } + + $body = $doc->getElementsByTagName("body")->item(0); + + if ($body) { + $div = $doc->createElement("div"); + + foreach ($body->childNodes as $child) { + $div->appendChild($child); + } + + $res = $doc->saveXML($div); + } else { + $res = $doc->saveHTML(); + } + return $res; } @@ -2998,10 +3086,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,9 +3202,10 @@ 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 title FROM ttrss_feeds WHERE id = feed_id) as feed_title, (SELECT hide_images FROM ttrss_feeds WHERE id = feed_id) as hide_images, (SELECT always_display_enclosures FROM ttrss_feeds WHERE id = feed_id) as always_display_enclosures, num_comments, @@ -3142,7 +3227,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); @@ -3157,10 +3242,13 @@ } else { $comments_url = htmlspecialchars($line["link"]); } - $entry_comments = "$num_comments comments"; + $entry_comments = "$num_comments ". + _ngettext("comment", "comments", $num_comments).""; + } else { if ($line["comments"] && $line["link"] != $line["comments"]) { - $entry_comments = "comments"; + $entry_comments = "".__("comments").""; } } @@ -3170,6 +3258,9 @@ Tiny Tiny RSS - ".$line["title"]." + + +