]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/apisearchjson.php
Merge branch 'master' into social-master
[quix0rs-gnu-social.git] / actions / apisearchjson.php
index 7ee353440f849423e6482701912a62589bded025..424773f12bf6bb41e7aea20b4ca780f447e764d8 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * @category  Search
- * @package   StatusNet
+ * @package   GNUsocial
  * @author    Zach Copley <zach@status.net>
  * @copyright 2008-2010 StatusNet, Inc.
+ * @copyright 2013 Free Software Foundation, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link      http://status.net/
+ * @link      http://www.gnu.org/software/social/
  */
 
-if (!defined('STATUSNET') && !defined('LACONICA')) {
-    exit(1);
-}
-
-require_once INSTALLDIR.'/lib/apiprivateauth.php';
-require_once INSTALLDIR.'/lib/jsonsearchresultslist.php';
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Action handler for Twitter-compatible API search
@@ -61,7 +57,7 @@ class ApiSearchJSONAction extends ApiPrivateAuthAction
      *
      * @return boolean true if nothing goes wrong
      */
-    function prepare($args)
+    function prepare(array $args=array())
     {
         parent::prepare($args);
 
@@ -89,12 +85,6 @@ class ApiSearchJSONAction extends ApiPrivateAuthAction
         $this->since_id = $this->trimmed('since_id');
         $this->geocode  = $this->trimmed('geocode');
 
-        if (!empty($this->auth_user)) {
-            $this->auth_profile = $this->auth_user->getProfile();
-        } else {
-            $this->auth_profile = null;
-        }
-
         return true;
     }
 
@@ -105,7 +95,7 @@ class ApiSearchJSONAction extends ApiPrivateAuthAction
      *
      * @return void
      */
-    function handle($args)
+    function handle(array $args=array())
     {
         parent::handle($args);
         $this->showResults();
@@ -118,21 +108,20 @@ class ApiSearchJSONAction extends ApiPrivateAuthAction
      */
     function showResults()
     {
-        $q = strtolower($this->query);
-
         // TODO: Support search operators like from: and to:, boolean, etc.
 
-        $stream = new SearchNoticeStream($q, $this->auth_profile);
-
-        $notice = $stream->getNotices(($this->page - 1) * $this->rpp, $this->rpp + 1);
+        $notice = new Notice();
 
-        // TODO: max_id, lang, geocode
-
-        $results = new JSONSearchResultsList($notice, $q, $this->rpp, $this->page, $this->since_id);
+        $this->notices = array();
+        $search_engine = $notice->getSearchEngine('notice');
+        $search_engine->set_sort_mode('chron');
+        $search_engine->limit(($this->page - 1) * $this->rpp, $this->rpp + 1);
+        if ($search_engine->query($this->query)) {
+            $cnt = $notice->find();
+            $this->notices = $notice->fetchAll();
+        }
 
-        $this->initDocument('json');
-        $results->show();
-        $this->endDocument('json');
+       $this->showJsonTimeline($this->notices);
     }
 
     /**
@@ -140,7 +129,7 @@ class ApiSearchJSONAction extends ApiPrivateAuthAction
      *
      * @return boolean true
      */
-    function isReadOnly($args)
+    function isReadOnly(array $args=array())
     {
         return true;
     }