X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fnoticesearch.php;h=29527c56725c721486b2d234bf2b4c108fac2826;hb=912e9b3f4ff3e43838e44e9ab804765e9573206f;hp=d4de61a904653ee0b842f2875781c2c9163862d1;hpb=ce2b174c4a083128cd14154d0f6c61e19d5cb229;p=quix0rs-gnu-social.git diff --git a/actions/noticesearch.php b/actions/noticesearch.php index d4de61a904..29527c5672 100644 --- a/actions/noticesearch.php +++ b/actions/noticesearch.php @@ -20,23 +20,22 @@ if (!defined('LACONICA')) { exit(1); } require_once(INSTALLDIR.'/lib/searchaction.php'); -define(NOTICES_PER_PAGE, 20); +define('NOTICES_PER_PAGE', 20); # XXX common parent for people and content search? class NoticesearchAction extends SearchAction { - + function get_instructions() { - return _('Search for notices on %%site.name%% by their contents. ' . - 'Separate search terms by spaces; they must be 3 characters or more.'); + return _('Search for notices on %%site.name%% by their contents. Separate search terms by spaces; they must be 3 characters or more.'); } - + function get_title() { return _('Text search'); } - + function show_results($q, $page) { - + $notice = new Notice(); # lcase it for comparison @@ -44,7 +43,7 @@ class NoticesearchAction extends SearchAction { $notice->whereAdd('MATCH(content) against (\''.addslashes($q).'\')'); # Ask for an extra to see if there's more. - + $notice->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1); $cnt = $notice->find(); @@ -64,7 +63,7 @@ class NoticesearchAction extends SearchAction { } else { common_element('p', 'error', _('No results')); } - + common_pagination($page > 1, $cnt > NOTICES_PER_PAGE, $page, 'noticesearch', array('q' => $q)); } @@ -81,9 +80,9 @@ class NoticesearchAction extends SearchAction { 'title' => _('Search Stream Feed'))); } } - + # XXX: refactor and combine with StreamAction::show_notice() - + function show_notice($notice, $terms) { $profile = $notice->getProfile(); # XXX: RDFa @@ -127,7 +126,7 @@ class NoticesearchAction extends SearchAction { _('in reply to...')); common_text(')'); } - common_element_start('a', + common_element_start('a', array('href' => common_local_url('newnotice', array('replyto' => $profile->nickname)), 'onclick' => 'doreply("'.$profile->nickname.'"); return false', @@ -140,8 +139,15 @@ class NoticesearchAction extends SearchAction { } function highlight($text, $terms) { + /* Highligh serach terms */ $pattern = '/('.implode('|',array_map('htmlspecialchars', $terms)).')/i'; $result = preg_replace($pattern, '\\1', $text); + + /* Remove highlighting from inside links, loop incase multiple highlights in links */ + $pattern = '/(href="[^"]*)('.implode('|',array_map('htmlspecialchars', $terms)).')<\/strong>([^"]*")/iU'; + do { + $result = preg_replace($pattern, '\\1\\2\\3', $result, -1, $count); + } while ($count); return $result; } }