]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/apigrouplistall.php
Merge branch 'send-twitter-replies-to-twitter' into 'master'
[quix0rs-gnu-social.git] / actions / apigrouplistall.php
index 89469f36f4a180cfa08f525f85ddd7de0a1bc9e0..2fb3714257f7677258a07390539d807771633888 100644 (file)
@@ -26,6 +26,7 @@
  * @author    Jeffery To <jeffery.to@gmail.com>
  * @author    Zach Copley <zach@status.net>
  * @copyright 2009 StatusNet, Inc.
+ * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link      http://status.net/
  */
@@ -34,8 +35,6 @@ if (!defined('STATUSNET')) {
     exit(1);
 }
 
-require_once INSTALLDIR . '/lib/api.php';
-
 /**
  * Returns of the lastest 20 groups for the site
  *
@@ -48,8 +47,7 @@ require_once INSTALLDIR . '/lib/api.php';
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link     http://status.net/
  */
-
-class ApiGroupListAllAction extends ApiAction
+class ApiGroupListAllAction extends ApiPrivateAuthAction
 {
     var $groups   = null;
 
@@ -59,14 +57,12 @@ class ApiGroupListAllAction extends ApiAction
      * @param array $args $_REQUEST args
      *
      * @return boolean success flag
-     *
      */
-
     function prepare($args)
     {
         parent::prepare($args);
 
-        $this->user   = $this->getTargetUser($id);
+        $this->user   = $this->getTargetUser(null);
         $this->groups = $this->getGroups();
 
         return true;
@@ -81,16 +77,17 @@ class ApiGroupListAllAction extends ApiAction
      *
      * @return void
      */
-
     function handle($args)
     {
         parent::handle($args);
 
         $sitename   = common_config('site', 'name');
+        // TRANS: Message is used as a title when listing the lastest 20 groups. %s is a site name.
         $title      = sprintf(_("%s groups"), $sitename);
-        $taguribase = common_config('integration', 'taguri');
+        $taguribase = TagURI::base();
         $id         = "tag:$taguribase:Groups";
         $link       = common_local_url('groups');
+        // TRANS: Message is used as a subtitle when listing the latest 20 groups. %s is a site name.
         $subtitle   = sprintf(_("groups on %s"), $sitename);
 
         switch($this->format) {
@@ -117,13 +114,13 @@ class ApiGroupListAllAction extends ApiAction
             break;
         default:
             $this->clientError(
-                _('API method not found!'),
+                // TRANS: Client error displayed when coming across a non-supported API method.
+                _('API method not found.'),
                 404,
                 $this->format
             );
             break;
         }
-
     }
 
     /**
@@ -131,17 +128,23 @@ class ApiGroupListAllAction extends ApiAction
      *
      * @return array groups
      */
-
     function getGroups()
     {
-        $groups = array();
-
-        // XXX: Use the $page, $count, $max_id, $since_id, and $since parameters
-
+        $qry = 'SELECT user_group.* '.
+          'from user_group join local_group on user_group.id = local_group.group_id '.
+          'order by created desc ';
+        $offset = intval($this->page - 1) * intval($this->count);
+        $limit = intval($this->count);
+        if (common_config('db', 'type') == 'pgsql') {
+            $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
+        } else {
+            $qry .= ' LIMIT ' . $offset . ', ' . $limit;
+        }
         $group = new User_group();
-        $group->orderBy('created DESC');
-        $group->find();
 
+        $group->query($qry);
+
+        $groups = array();
         while ($group->fetch()) {
             $groups[] = clone($group);
         }
@@ -156,7 +159,6 @@ class ApiGroupListAllAction extends ApiAction
      *
      * @return boolean true
      */
-
     function isReadOnly($args)
     {
         return true;
@@ -167,7 +169,6 @@ class ApiGroupListAllAction extends ApiAction
      *
      * @return string datestamp of the site's latest group
      */
-
     function lastModified()
     {
         if (!empty($this->groups) && (count($this->groups) > 0)) {
@@ -185,7 +186,6 @@ class ApiGroupListAllAction extends ApiAction
      *
      * @return string etag
      */
-
     function etag()
     {
         if (!empty($this->groups) && (count($this->groups) > 0)) {
@@ -195,6 +195,7 @@ class ApiGroupListAllAction extends ApiAction
             return '"' . implode(
                 ':',
                 array($this->arg('action'),
+                      common_user_cache_hash($this->auth_user),
                       common_language(),
                       strtotime($this->groups[0]->created),
                       strtotime($this->groups[$last]->created))
@@ -204,5 +205,4 @@ class ApiGroupListAllAction extends ApiAction
 
         return null;
     }
-
 }