]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/twitapisearchatom.php
Remove more contractions
[quix0rs-gnu-social.git] / actions / twitapisearchatom.php
index c5f724c12f2b8aac0477b4bb1f3a83699ab0f6d8..511d7cdc66ac3efb6d614c28bed9840325d52029 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Laconica, the distributed open-source microblogging tool
+ * StatusNet, the distributed open-source microblogging tool
  *
  * Action for showing Twitter-like Atom search results
  *
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * @category  Search
- * @package   Laconica
- * @author    Zach Copley <zach@controlyourself.ca>
- * @copyright 2008-2009 Control Yourself, Inc.
+ * @package   StatusNet
+ * @author    Zach Copley <zach@status.net>
+ * @copyright 2008-2009 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link      http://laconi.ca/
+ * @link      http://status.net/
  */
 
-if (!defined('LACONICA')) {
+if (!defined('STATUSNET') && !defined('LACONICA')) {
     exit(1);
 }
 
-require_once INSTALLDIR.'/lib/twitterapi.php';
+require_once INSTALLDIR.'/lib/api.php';
 
 /**
  * Action for outputting search results in Twitter compatible Atom
@@ -41,15 +41,15 @@ require_once INSTALLDIR.'/lib/twitterapi.php';
  * RSS10Action.
  *
  * @category Search
- * @package  Laconica
- * @author   Zach Copley <zach@controlyourself.ca>
+ * @package  StatusNet
+ * @author   Zach Copley <zach@status.net>
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link     http://laconi.ca/
+ * @link     http://status.net/
  *
- * @see      TwitterapiAction
+ * @see      ApiAction
  */
 
-class TwitapisearchatomAction extends TwitterapiAction
+class TwitapisearchatomAction extends ApiAction
 {
 
     var $cnt;
@@ -165,24 +165,30 @@ class TwitapisearchatomAction extends TwitterapiAction
         $search_engine->set_sort_mode('chron');
         $search_engine->limit(($this->page - 1) * $this->rpp,
             $this->rpp + 1, true);
-        $search_engine->query($q);
-        $this->cnt = $notice->find();
+        if (false === $search_engine->query($q)) {
+            $this->cnt = 0;
+        } else {
+            $this->cnt = $notice->find();
+        }
 
         $cnt = 0;
+        $this->max_id = 0;
 
-        while ($notice->fetch()) {
+        if ($this->cnt > 0) {
+            while ($notice->fetch()) {
 
-            ++$cnt;
+                ++$cnt;
 
-            if (!$this->max_id) {
-                $this->max_id = $notice->id;
-            }
+                if (!$this->max_id) {
+                    $this->max_id = $notice->id;
+                }
 
-            if ($cnt > $this->rpp) {
-                break;
-            }
+                if ($cnt > $this->rpp) {
+                    break;
+                }
 
-            $notices[] = clone($notice);
+                $notices[] = clone($notice);
+            }
         }
 
         return $notices;
@@ -218,11 +224,10 @@ class TwitapisearchatomAction extends TwitterapiAction
     {
         // TODO: A9 OpenSearch stuff like search.twitter.com?
 
-        $lang     = common_config('site', 'language');
         $server   = common_config('site', 'server');
         $sitename = common_config('site', 'name');
 
-        // XXX: Use xmlns:laconica instead?
+        // XXX: Use xmlns:statusnet instead?
 
         $this->elementStart('feed',
             array('xmlns' => 'http://www.w3.org/2005/Atom',
@@ -231,7 +236,7 @@ class TwitapisearchatomAction extends TwitterapiAction
                              // It's used for the source attr on notices
 
                              'xmlns:twitter' => 'http://api.twitter.com/',
-                             'xml:lang' => $lang));
+                             'xml:lang' => 'en-US')); // XXX Other locales ?
 
         $taguribase = common_config('integration', 'taguri');
         $this->element('id', null, "tag:$taguribase:search/$server");
@@ -245,7 +250,7 @@ class TwitapisearchatomAction extends TwitterapiAction
         }
 
         // FIXME: this alternate link is not quite right because our
-        // web-based notice search doesn't support a rpp (responses per
+        // web-based notice search does not support a rpp (responses per
         // page) param yet
 
         $this->element('link', array('type' => 'text/html',
@@ -265,6 +270,9 @@ class TwitapisearchatomAction extends TwitterapiAction
         $this->element('title', null, "$this->query - $sitename Search");
         $this->element('updated', null, common_date_iso8601('now'));
 
+        // XXX: The below "rel" links are not valid Atom, but it's what
+        // Twitter does...
+
         // refresh link
 
         $refresh_uri = $search_uri . "&since_id=" . $this->max_id;
@@ -332,7 +340,7 @@ class TwitapisearchatomAction extends TwitterapiAction
         // TODO: Here is where we'd put in a link to an atom feed for threads
 
         $this->element("twitter:source", null,
-            htmlentities($this->source_link($notice->source)));
+            htmlentities($this->sourceLink($notice->source)));
 
         $this->elementStart('author');