apigroupadmins.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * List a group's admins
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category API
  23. * @package GNUsocial
  24. * @author Craig Andrews <candrews@integralblue.com>
  25. * @author Evan Prodromou <evan@status.net>
  26. * @author Jeffery To <jeffery.to@gmail.com>
  27. * @author Zach Copley <zach@status.net>
  28. * @author Hannes Mannerheim <h@nnesmannerhe.im>
  29. * @copyright 2009 StatusNet, Inc.
  30. * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
  31. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  32. * @link http://www.gnu.org/software/social/
  33. */
  34. if (!defined('GNUSOCIAL')) {
  35. exit(1);
  36. }
  37. /**
  38. * List 20 newest admins of the group specified by name or ID.
  39. *
  40. * @category API
  41. * @package GNUsocial
  42. * @author Craig Andrews <candrews@integralblue.com>
  43. * @author Evan Prodromou <evan@status.net>
  44. * @author Jeffery To <jeffery.to@gmail.com>
  45. * @author Zach Copley <zach@status.net>
  46. * @author Hannes Mannerheim <h@nnesmannerhe.im>
  47. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  48. * @link http://www.gnu.org/software/social/
  49. */
  50. class ApiGroupAdminsAction extends ApiPrivateAuthAction
  51. {
  52. var $group = null;
  53. var $profiles = null;
  54. /**
  55. * Take arguments for running
  56. *
  57. * @param array $args $_REQUEST args
  58. *
  59. * @return boolean success flag
  60. */
  61. protected function prepare(array $args=array())
  62. {
  63. parent::prepare($args);
  64. $this->group = $this->getTargetGroup($this->arg('id'));
  65. if (empty($this->group)) {
  66. // TRANS: Client error displayed trying to show group membership on a non-existing group.
  67. $this->clientError(_('Group not found.'), 404);
  68. }
  69. $this->profiles = $this->getProfiles();
  70. return true;
  71. }
  72. /**
  73. * Handle the request
  74. *
  75. * Show the admin of the group
  76. *
  77. * @param array $args $_REQUEST data (unused)
  78. *
  79. * @return void
  80. */
  81. protected function handle()
  82. {
  83. parent::handle();
  84. // XXX: RSS and Atom
  85. switch($this->format) {
  86. case 'xml':
  87. $this->showTwitterXmlUsers($this->profiles);
  88. break;
  89. case 'json':
  90. $this->showJsonUsers($this->profiles);
  91. break;
  92. default:
  93. $this->clientError(
  94. // TRANS: Client error displayed when coming across a non-supported API method.
  95. _('API method not found.'),
  96. 404,
  97. $this->format
  98. );
  99. break;
  100. }
  101. }
  102. /**
  103. * Fetch the admins of a group
  104. *
  105. * @return array $profiles list of profiles
  106. */
  107. function getProfiles()
  108. {
  109. $profiles = array();
  110. $profile = $this->group->getAdmins(
  111. ($this->page - 1) * $this->count,
  112. $this->count,
  113. $this->since_id,
  114. $this->max_id
  115. );
  116. while ($profile->fetch()) {
  117. $profiles[] = clone($profile);
  118. }
  119. return $profiles;
  120. }
  121. /**
  122. * Is this action read only?
  123. *
  124. * @param array $args other arguments
  125. *
  126. * @return boolean true
  127. */
  128. function isReadOnly($args)
  129. {
  130. return true;
  131. }
  132. /**
  133. * When was this list of profiles last modified?
  134. *
  135. * @return string datestamp of the lastest profile in the group
  136. */
  137. function lastModified()
  138. {
  139. if (!empty($this->profiles) && (count($this->profiles) > 0)) {
  140. return strtotime($this->profiles[0]->created);
  141. }
  142. return null;
  143. }
  144. /**
  145. * An entity tag for this list of groups
  146. *
  147. * Returns an Etag based on the action name, language
  148. * the group id, and timestamps of the first and last
  149. * user who has joined the group
  150. *
  151. * @return string etag
  152. */
  153. function etag()
  154. {
  155. if (!empty($this->profiles) && (count($this->profiles) > 0)) {
  156. $last = count($this->profiles) - 1;
  157. return '"' . implode(
  158. ':',
  159. array($this->arg('action'),
  160. common_user_cache_hash($this->auth_user),
  161. common_language(),
  162. $this->group->id,
  163. strtotime($this->profiles[0]->created),
  164. strtotime($this->profiles[$last]->created))
  165. )
  166. . '"';
  167. }
  168. return null;
  169. }
  170. }