apiqvitterlistmembers.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * List a list's members
  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 ApiQvitterListMembersAction extends ApiPrivateAuthAction
  51. {
  52. var $list = 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->format = 'json';
  65. $this->list = $this->getTargetList($this->arg('nickname'), $this->arg('id'));
  66. if (!$this->list instanceof Profile_list) {
  67. // TRANS: Client error displayed trying to show list membership on a non-existing list.
  68. $this->clientError(_('List not found.'), 404);
  69. }
  70. $this->profiles = $this->getProfiles();
  71. return true;
  72. }
  73. /**
  74. * Handle the request
  75. *
  76. * Show the admin of the group
  77. *
  78. * @param array $args $_REQUEST data (unused)
  79. *
  80. * @return void
  81. */
  82. protected function handle()
  83. {
  84. parent::handle();
  85. $this->showJsonUsers($this->profiles);
  86. }
  87. /**
  88. * Fetch the admins of a group
  89. *
  90. * @return array $profiles list of profiles
  91. */
  92. function getProfiles()
  93. {
  94. $profiles = array();
  95. $profile = $this->list->getTagged(
  96. ($this->page - 1) * $this->count,
  97. $this->count,
  98. $this->since_id,
  99. $this->max_id
  100. );
  101. while ($profile->fetch()) {
  102. $profiles[] = clone($profile);
  103. }
  104. return $profiles;
  105. }
  106. /**
  107. * Is this action read only?
  108. *
  109. * @param array $args other arguments
  110. *
  111. * @return boolean true
  112. */
  113. function isReadOnly($args)
  114. {
  115. return true;
  116. }
  117. /**
  118. * When was this list of profiles last modified?
  119. *
  120. * @return string datestamp of the lastest profile in the group
  121. */
  122. function lastModified()
  123. {
  124. if (!empty($this->profiles) && (count($this->profiles) > 0)) {
  125. return strtotime($this->profiles[0]->created);
  126. }
  127. return null;
  128. }
  129. /**
  130. * An entity tag for this list of groups
  131. *
  132. * Returns an Etag based on the action name, language
  133. * the group id, and timestamps of the first and last
  134. * user who has joined the group
  135. *
  136. * @return string etag
  137. */
  138. function etag()
  139. {
  140. if (!empty($this->profiles) && (count($this->profiles) > 0)) {
  141. $last = count($this->profiles) - 1;
  142. return '"' . implode(
  143. ':',
  144. array($this->arg('action'),
  145. common_user_cache_hash($this->auth_user),
  146. common_language(),
  147. $this->group->id,
  148. strtotime($this->profiles[0]->created),
  149. strtotime($this->profiles[$last]->created))
  150. )
  151. . '"';
  152. }
  153. return null;
  154. }
  155. }