mirror of
https://git.tt-rss.org/fox/tt-rss.git
synced 2025-10-16 05:21:12 +02:00
search keyword highlighting (combined mode only)
This commit is contained in:
parent
07eb36583c
commit
dd90eb2c7a
@ -255,6 +255,7 @@ class Feeds extends Handler_Protected {
|
|||||||
$last_error = $qfh_ret[3];
|
$last_error = $qfh_ret[3];
|
||||||
$last_updated = strpos($qfh_ret[4], '1970-') === FALSE ?
|
$last_updated = strpos($qfh_ret[4], '1970-') === FALSE ?
|
||||||
make_local_datetime($qfh_ret[4], false) : __("Never");
|
make_local_datetime($qfh_ret[4], false) : __("Never");
|
||||||
|
$highlight_words = $qfh_ret[5];
|
||||||
|
|
||||||
$vgroup_last_feed = $vgr_last_feed;
|
$vgroup_last_feed = $vgr_last_feed;
|
||||||
|
|
||||||
@ -509,7 +510,7 @@ class Feeds extends Handler_Protected {
|
|||||||
$tags = false;
|
$tags = false;
|
||||||
|
|
||||||
$line["content"] = sanitize($line["content"],
|
$line["content"] = sanitize($line["content"],
|
||||||
sql_bool_to_bool($line['hide_images']), false, $entry_site_url);
|
sql_bool_to_bool($line['hide_images']), false, $entry_site_url, $highlight_words);
|
||||||
|
|
||||||
foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_CDM) as $p) {
|
foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_CDM) as $p) {
|
||||||
$line = $p->hook_render_article_cdm($line);
|
$line = $p->hook_render_article_cdm($line);
|
||||||
|
@ -1168,3 +1168,8 @@ body#ttrssPrefs hr {
|
|||||||
position : relative;
|
position : relative;
|
||||||
top : -2px;
|
top : -2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
span.highlight {
|
||||||
|
background-color : #ffff00;
|
||||||
|
color : #cc90cc;
|
||||||
|
}
|
||||||
|
@ -2204,6 +2204,7 @@
|
|||||||
|
|
||||||
$keywords = explode(" ", $search);
|
$keywords = explode(" ", $search);
|
||||||
$query_keywords = array();
|
$query_keywords = array();
|
||||||
|
$search_words = array();
|
||||||
|
|
||||||
foreach ($keywords as $k) {
|
foreach ($keywords as $k) {
|
||||||
if (strpos($k, "-") === 0) {
|
if (strpos($k, "-") === 0) {
|
||||||
@ -2223,6 +2224,7 @@
|
|||||||
} else {
|
} else {
|
||||||
array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
|
array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
|
||||||
OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
|
OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
|
||||||
|
array_push($search_words, $k);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "author":
|
case "author":
|
||||||
@ -2232,6 +2234,7 @@
|
|||||||
} else {
|
} else {
|
||||||
array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
|
array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
|
||||||
OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
|
OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
|
||||||
|
array_push($search_words, $k);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "note":
|
case "note":
|
||||||
@ -2246,6 +2249,7 @@
|
|||||||
} else {
|
} else {
|
||||||
array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
|
array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
|
||||||
OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
|
OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
|
||||||
|
if (!$not) array_push($search_words, $k);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "star":
|
case "star":
|
||||||
@ -2258,6 +2262,7 @@
|
|||||||
} else {
|
} else {
|
||||||
array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
|
array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
|
||||||
OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
|
OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
|
||||||
|
if (!$not) array_push($search_words, $k);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "pub":
|
case "pub":
|
||||||
@ -2270,6 +2275,7 @@
|
|||||||
} else {
|
} else {
|
||||||
array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
|
array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
|
||||||
OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
|
OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
|
||||||
|
if (!$not) array_push($search_words, $k);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -2285,13 +2291,15 @@
|
|||||||
} else {
|
} else {
|
||||||
array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
|
array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
|
||||||
OR UPPER(ttrss_entries.content) $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);
|
$search_query_part = implode("AND", $query_keywords);
|
||||||
|
|
||||||
return $search_query_part;
|
return array($search_query_part, $search_words);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getParentCategories($cat, $owner_uid) {
|
function getParentCategories($cat, $owner_uid) {
|
||||||
@ -2327,6 +2335,7 @@
|
|||||||
if (!$owner_uid) $owner_uid = $_SESSION["uid"];
|
if (!$owner_uid) $owner_uid = $_SESSION["uid"];
|
||||||
|
|
||||||
$ext_tables_part = "";
|
$ext_tables_part = "";
|
||||||
|
$search_words = array();
|
||||||
|
|
||||||
if ($search) {
|
if ($search) {
|
||||||
|
|
||||||
@ -2339,7 +2348,7 @@
|
|||||||
$search_query_part = "ref_id = -1 AND ";
|
$search_query_part = "ref_id = -1 AND ";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$search_query_part = search_to_sql($search);
|
list($search_query_part, $search_words) = search_to_sql($search);
|
||||||
$search_query_part .= " AND ";
|
$search_query_part .= " AND ";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2747,11 +2756,11 @@
|
|||||||
$result = db_query($select_qpart . $from_qpart . $where_qpart);
|
$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) {
|
||||||
if (!$owner) $owner = $_SESSION["uid"];
|
if (!$owner) $owner = $_SESSION["uid"];
|
||||||
|
|
||||||
$res = trim($str); if (!$res) return '';
|
$res = trim($str); if (!$res) return '';
|
||||||
@ -2852,7 +2861,41 @@
|
|||||||
|
|
||||||
$doc->removeChild($doc->firstChild); //remove doctype
|
$doc->removeChild($doc->firstChild); //remove doctype
|
||||||
$doc = strip_harmful_tags($doc, $allowed_elements, $disallowed_attributes);
|
$doc = strip_harmful_tags($doc, $allowed_elements, $disallowed_attributes);
|
||||||
|
|
||||||
|
if ($highlight_words) {
|
||||||
|
foreach ($highlight_words as $word) {
|
||||||
|
|
||||||
|
$elements = $xpath->query('//*[contains(.,"'.$word.'")]');
|
||||||
|
|
||||||
|
foreach ($elements as $element) {
|
||||||
|
foreach ($element->childNodes as $child) {
|
||||||
|
|
||||||
|
if (!$child instanceof DomText) continue;
|
||||||
|
|
||||||
|
$fragment = $doc->createDocumentFragment();
|
||||||
|
$text = $child->textContent;
|
||||||
|
$stubs = array();
|
||||||
|
|
||||||
|
while (($pos = stripos($text, $word)) !== false) {
|
||||||
|
$fragment->appendChild(new DomText(substr($text, 0, $pos)));
|
||||||
|
$word = substr($text, $pos, strlen($word));
|
||||||
|
$highlight = $doc->createElement('span');
|
||||||
|
$highlight->appendChild(new DomText($word));
|
||||||
|
$highlight->setAttribute('class', 'highlight');
|
||||||
|
$fragment->appendChild($highlight);
|
||||||
|
$text = substr($text, $pos + strlen($word));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($text)) $fragment->appendChild(new DomText($text));
|
||||||
|
|
||||||
|
$element->replaceChild($fragment, $child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$res = $doc->saveHTML();
|
$res = $doc->saveHTML();
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user