]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/noticesearch.php
fix calls to show_rss_timeline
[quix0rs-gnu-social.git] / actions / noticesearch.php
index ab383fab436152cdb42f3f37a40275f9b0ede2d3..e6de21ae068be9c818a10c6ff1e7d037fa4c37db 100644 (file)
 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() {
@@ -41,7 +40,12 @@ class NoticesearchAction extends SearchAction {
 
                # lcase it for comparison
                $q = strtolower($q);
-               $notice->whereAdd('MATCH(content) against (\''.addslashes($q).'\')');
+
+               if(common_config('db','type')=='mysql') {
+                       $notice->whereAdd('MATCH(content) against (\''.addslashes($q).'\')');
+               } else {
+                       $notice->whereAdd('to_tsvector(\'english\', content) @@ plainto_tsquery(\''.addslashes($q).'\')');
+               }
 
                # Ask for an extra to see if there's more.
 
@@ -86,6 +90,11 @@ class NoticesearchAction extends SearchAction {
 
        function show_notice($notice, $terms) {
                $profile = $notice->getProfile();
+               if (!$profile) {
+                       common_log_db_error($notice, 'SELECT', __FILE__);
+                       $this->server_error(_('Notice without matching profile'));
+                       return;
+               }
                # XXX: RDFa
                common_element_start('li', array('class' => 'notice_single',
                                                                                  'id' => 'notice-' . $notice->id));
@@ -140,8 +149,15 @@ class NoticesearchAction extends SearchAction {
        }
 
        function highlight($text, $terms) {
+               /* Highligh serach terms */
                $pattern = '/('.implode('|',array_map('htmlspecialchars', $terms)).')/i';
                $result = preg_replace($pattern, '<strong>\\1</strong>', $text);
+
+               /* Remove highlighting from inside links, loop incase multiple highlights in links */
+               $pattern = '/(href="[^"]*)<strong>('.implode('|',array_map('htmlspecialchars', $terms)).')<\/strong>([^"]*")/iU';
+               do {
+                       $result = preg_replace($pattern, '\\1\\2\\3', $result, -1, $count);
+               } while ($count);
                return $result;
        }
 }