X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fapigrouplistall.php;h=d05baa0992d928fdc35e5cb3b58d205d90a408da;hb=ad12384d8c021c31f91060ccbc4f91eda9d33f02;hp=b1964d8005227147682d4f5cda1e2284271a0150;hpb=08de0f1ebdabdce561ce863bdec219a913e61d26;p=quix0rs-gnu-social.git diff --git a/actions/apigrouplistall.php b/actions/apigrouplistall.php index b1964d8005..d05baa0992 100644 --- a/actions/apigrouplistall.php +++ b/actions/apigrouplistall.php @@ -21,8 +21,12 @@ * * @category API * @package StatusNet + * @author Craig Andrews + * @author Evan Prodromou + * @author Jeffery To * @author Zach Copley * @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/ */ @@ -31,26 +35,22 @@ if (!defined('STATUSNET')) { exit(1); } -require_once INSTALLDIR . '/lib/twitterapi.php'; +require_once INSTALLDIR . '/lib/apiprivateauth.php'; /** * Returns of the lastest 20 groups for the site * * @category API * @package StatusNet + * @author Craig Andrews + * @author Evan Prodromou + * @author Jeffery To * @author Zach Copley * @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 TwitterApiAction +class ApiGroupListAllAction extends ApiPrivateAuthAction { - var $format = null; - var $page = null; - var $count = null; - var $max_id = null; - var $since_id = null; - var $since = null; var $groups = null; /** @@ -59,21 +59,12 @@ class ApiGroupListAllAction extends TwitterApiAction * @param array $args $_REQUEST args * * @return boolean success flag - * */ - function prepare($args) { parent::prepare($args); - $this->page = (int)$this->arg('page', 1); - $this->count = (int)$this->arg('count', 20); - $this->max_id = (int)$this->arg('max_id', 0); - $this->since_id = (int)$this->arg('since_id', 0); - $this->since = $this->arg('since'); - - $this->user = $this->getTargetUser($id); - $this->format = $this->arg('format'); + $this->user = $this->getTargetUser(null); $this->groups = $this->getGroups(); return true; @@ -88,29 +79,30 @@ class ApiGroupListAllAction extends TwitterApiAction * * @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 lastest 20 groups. %s is a site name. $subtitle = sprintf(_("groups on %s"), $sitename); switch($this->format) { case 'xml': - $this->show_xml_groups($this->groups); + $this->showXmlGroups($this->groups); break; case 'rss': - $this->show_rss_groups($this->groups, $title, $link, $subtitle); + $this->showRssGroups($this->groups, $title, $link, $subtitle); break; case 'atom': $selfuri = common_root_url() . 'api/statusnet/groups/list_all.atom'; - $this->show_atom_groups( + $this->showAtomGroups( $this->groups, $title, $id, @@ -120,17 +112,17 @@ class ApiGroupListAllAction extends TwitterApiAction ); break; case 'json': - $this->show_json_groups($this->groups); + $this->showJsonGroups($this->groups); break; default: $this->clientError( - _('API method not found!'), + // TRANS: Client error displayed trying to execute an unknown API method listing the latest 20 groups. + _('API method not found.'), 404, $this->format ); break; } - } /** @@ -138,17 +130,23 @@ class ApiGroupListAllAction extends TwitterApiAction * * @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); } @@ -163,7 +161,6 @@ class ApiGroupListAllAction extends TwitterApiAction * * @return boolean true */ - function isReadOnly($args) { return true; @@ -174,7 +171,6 @@ class ApiGroupListAllAction extends TwitterApiAction * * @return string datestamp of the site's latest group */ - function lastModified() { if (!empty($this->groups) && (count($this->groups) > 0)) { @@ -192,7 +188,6 @@ class ApiGroupListAllAction extends TwitterApiAction * * @return string etag */ - function etag() { if (!empty($this->groups) && (count($this->groups) > 0)) { @@ -202,6 +197,7 @@ class ApiGroupListAllAction extends TwitterApiAction 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)) @@ -211,5 +207,4 @@ class ApiGroupListAllAction extends TwitterApiAction return null; } - }