apiqvittersandboxed.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * List all sandboxed users on the instance
  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. *
  39. * @category API
  40. * @package GNUsocial
  41. * @author Craig Andrews <candrews@integralblue.com>
  42. * @author Evan Prodromou <evan@status.net>
  43. * @author Jeffery To <jeffery.to@gmail.com>
  44. * @author Zach Copley <zach@status.net>
  45. * @author Hannes Mannerheim <h@nnesmannerhe.im>
  46. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  47. * @link http://www.gnu.org/software/social/
  48. */
  49. class ApiQvitterSandboxedAction extends ApiPrivateAuthAction
  50. {
  51. var $profiles = null;
  52. /**
  53. * Take arguments for running
  54. *
  55. * @param array $args $_REQUEST args
  56. *
  57. * @return boolean success flag
  58. */
  59. protected function prepare(array $args=array())
  60. {
  61. parent::prepare($args);
  62. $this->profiles = $this->getProfiles();
  63. return true;
  64. }
  65. /**
  66. * Handle the request
  67. *
  68. * @param array $args $_REQUEST data (unused)
  69. *
  70. * @return void
  71. */
  72. protected function handle()
  73. {
  74. parent::handle();
  75. // XXX: RSS and Atom
  76. switch($this->format) {
  77. case 'xml':
  78. $this->showTwitterXmlUsers($this->profiles);
  79. break;
  80. case 'json':
  81. $this->showJsonUsers($this->profiles);
  82. break;
  83. default:
  84. $this->clientError(
  85. // TRANS: Client error displayed when coming across a non-supported API method.
  86. _('API method not found.'),
  87. 404,
  88. $this->format
  89. );
  90. break;
  91. }
  92. }
  93. /**
  94. * Fetch the sandboxed profiles
  95. *
  96. * @return array $profiles list of profiles
  97. */
  98. function getProfiles()
  99. {
  100. $profiles = array();
  101. $profile = $this->getSandboxed(
  102. ($this->page - 1) * $this->count,
  103. $this->count);
  104. while ($profile->fetch()) {
  105. $profiles[] = clone($profile);
  106. }
  107. return $profiles;
  108. }
  109. /**
  110. * Fetch the sandboxed profiles from DB
  111. *
  112. * @return array $profiles list of profiles
  113. */
  114. function getSandboxed($offset=null, $limit=null) // offset is null because DataObject wants it, 0 would mean no results
  115. {
  116. $profiles = new Profile();
  117. $profiles->joinAdd(array('id', 'profile_role:profile_id'));
  118. $profiles->whereAdd(sprintf('profile_role.role = \'%s\'', Profile_role::SANDBOXED));
  119. $profiles->orderBy('profile_role.created DESC');
  120. $profiles->limit($offset, $limit);
  121. $profiles->find();
  122. return $profiles;
  123. }
  124. /**
  125. * Is this action read only?
  126. *
  127. * @param array $args other arguments
  128. *
  129. * @return boolean true
  130. */
  131. function isReadOnly($args)
  132. {
  133. return true;
  134. }
  135. /**
  136. * When was this list of profiles last modified?
  137. *
  138. * @return string datestamp of the lastest profile
  139. */
  140. function lastModified()
  141. {
  142. if (!empty($this->profiles) && (count($this->profiles) > 0)) {
  143. return strtotime($this->profiles[0]->created);
  144. }
  145. return null;
  146. }
  147. /**
  148. * An entity tag for this list
  149. *
  150. * Returns an Etag based on the action name, language
  151. * and timestamps of the first and last profile
  152. *
  153. * @return string etag
  154. */
  155. function etag()
  156. {
  157. if (!empty($this->profiles) && (count($this->profiles) > 0)) {
  158. $last = count($this->profiles) - 1;
  159. return '"' . implode(
  160. ':',
  161. array($this->arg('action'),
  162. common_user_cache_hash($this->auth_user),
  163. common_language(),
  164. strtotime($this->profiles[0]->created),
  165. strtotime($this->profiles[$last]->created))
  166. )
  167. . '"';
  168. }
  169. return null;
  170. }
  171. }