]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
add notice search rss ("tracking")
authorEvan Prodromou <evan@prodromou.name>
Wed, 9 Jul 2008 23:42:28 +0000 (19:42 -0400)
committerEvan Prodromou <evan@prodromou.name>
Wed, 9 Jul 2008 23:42:28 +0000 (19:42 -0400)
darcs-hash:20080709234228-84dde-f24d277947ab49031a1b6d74184568fe2f50a685.gz

actions/noticesearch.php
actions/noticesearchrss.php [new file with mode: 0644]
htaccess.sample
lib/searchaction.php
lib/util.php

index 8b2082e8c26e72b82a0fc296fc6ad04ce2bf8f84..0a9f4c37fe9ae423ca13a99e57a336124fec6f82 100644 (file)
@@ -69,6 +69,19 @@ class NoticesearchAction extends SearchAction {
                                                  $page, 'noticesearch', array('q' => $q));
        }
 
+       function show_header($arr) {
+               if ($arr) {
+                       $q = $arr[0];
+               }
+               if ($q) {
+                       common_element('link', array('rel' => 'alternate',
+                                                                                'href' => common_local_url('noticesearchrss',
+                                                                                                                                       array('q' => $q)),
+                                                                                'type' => 'application/rss+xml',
+                                                                                'title' => _t('Search Stream Feed')));
+               }
+       }
+       
        # XXX: refactor and combine with StreamAction::show_notice()
        
        function show_notice($notice, $terms) {
diff --git a/actions/noticesearchrss.php b/actions/noticesearchrss.php
new file mode 100644 (file)
index 0000000..f5834c4
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+if (!defined('LACONICA')) { exit(1); }
+
+require_once(INSTALLDIR.'/lib/rssaction.php');
+
+// Formatting of RSS handled by Rss10Action
+
+class NoticesearchrssAction extends Rss10Action {
+
+       function init() {
+               return true;
+       }
+       
+       function get_notices($limit=0) {
+
+               $q = $this->trimmed('q');
+               $notices = array();
+               
+               $notice = new Notice();
+
+               # lcase it for comparison
+               $q = strtolower($q);
+               
+               $notice->whereAdd('MATCH(content) against (\''.addslashes($q).'\')');
+
+               # Ask for an extra to see if there's more.
+               
+               if ($limit != 0) {
+                       $notice->limit(0, $limit);
+               }
+
+               $notice->find();
+               
+               while ($notice->fetch()) {
+                       $notices[] = clone($notice);
+               }
+               
+               return $notices;
+       }
+       
+       function get_channel() {
+               global $config;
+               $q = $this->trimmed('q');
+               $c = array('url' => common_local_url('noticesearchrss', array('q' => $q)),
+                                  'title' => $config['site']['name'] . _t(' Search Stream for "' . $q . '"'),
+                                  'link' => common_local_url('noticesearch', array('q' => $q)),
+                                  'description' => _t('All updates matching search term "') . $q . '"');
+               return $c;
+       }
+       
+       function get_image() {
+               return NULL;
+       }
+}
\ No newline at end of file
index 48ee74bfacfdaaacbb3eec1c20834eb03fa81faf..8c9e16c47010010990bbd8e93add93631aa00271 100644 (file)
@@ -35,6 +35,7 @@ RewriteRule ^settings/im$ index.php?action=imsettings [L,QSA]
 
 RewriteRule ^search/people$ index.php?action=peoplesearch [L,QSA]
 RewriteRule ^search/notice$ index.php?action=noticesearch [L,QSA]
+RewriteRule ^search/notice/rss$ index.php?action=noticesearchrss [L,QSA]
 
 RewriteRule ^notice/new$ index.php?action=newnotice [L,QSA]
 RewriteRule ^notice/(\d+)$ index.php?action=shownotice&notice=$1 [L,QSA]
index bf598ea93d2f0a7fb6ae9fba94b69fb43e8ee5ac..a9fb77fd3c2f933cc212c299c85272301b4fdbbb 100644 (file)
@@ -26,7 +26,10 @@ class SearchAction extends Action {
                $this->show_form();
        }
 
-       function show_top($error=NULL) {
+       function show_top($arr=NULL) {
+               if ($arr) {
+                       $error = $arr[1];
+               }
                if ($error) {
                        common_element('p', 'error', $error);
                } else {
@@ -42,12 +45,17 @@ class SearchAction extends Action {
        function get_title() {
                return NULL;
        }
+
+       function show_header($arr) {
+               return;
+       }
        
        function show_form($error=NULL) {
                $q = $this->trimmed('q');
                $page = $this->trimmed('page', 1);
                
-               common_show_header($this->get_title(), NULL, $error, array($this, 'show_top'));
+               common_show_header($this->get_title(), array($this, 'show_header'), array($q, $error),
+                                                  array($this, 'show_top'));
                common_element_start('form', array('method' => 'post',
                                                                                   'id' => 'login',
                                                                                   'action' => common_local_url($this->trimmed('action'))));
index d86cc5e4c0330a70ba8090750569dfa933acbb47..7627cafdcd74e634ba61c039763b704f4476c244 100644 (file)
@@ -778,6 +778,8 @@ function common_fancy_url($action, $args=NULL) {
                return common_path('search/people' . (($args) ? ('?' . http_build_query($args)) : ''));
         case 'noticesearch':
                return common_path('search/notice' . (($args) ? ('?' . http_build_query($args)) : ''));
+        case 'noticesearchrss':
+               return common_path('search/notice/rss' . (($args) ? ('?' . http_build_query($args)) : ''));
         default:
                return common_simple_url($action, $args);
        }