apigroupshow.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Show information about a group
  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 StatusNet
  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. * @copyright 2009 StatusNet, Inc.
  29. * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
  30. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  31. * @link http://status.net/
  32. */
  33. if (!defined('STATUSNET')) {
  34. exit(1);
  35. }
  36. /**
  37. * Outputs detailed information about the group specified by ID
  38. *
  39. * @category API
  40. * @package StatusNet
  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 Michele <macno@macno.org>
  46. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  47. * @link http://status.net/
  48. */
  49. class ApiGroupShowAction extends ApiPrivateAuthAction
  50. {
  51. var $group = 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->group = $this->getTargetGroup($this->arg('id'));
  63. if (empty($this->group)) {
  64. $alias = Group_alias::getKV(
  65. 'alias',
  66. common_canonical_nickname($this->arg('id'))
  67. );
  68. if (!empty($alias)) {
  69. $args = array('id' => $alias->group_id, 'format' => $this->format);
  70. common_redirect(common_local_url('ApiGroupShow', $args), 301);
  71. } else {
  72. // TRANS: Client error displayed when trying to show a group that could not be found.
  73. $this->clientError(_('Group not found.'), 404);
  74. }
  75. return;
  76. }
  77. return true;
  78. }
  79. /**
  80. * Handle the request
  81. *
  82. * Check the format and show the user info
  83. *
  84. * @return void
  85. */
  86. protected function handle()
  87. {
  88. parent::handle();
  89. switch($this->format) {
  90. case 'xml':
  91. $this->showSingleXmlGroup($this->group);
  92. break;
  93. case 'json':
  94. $this->showSingleJsonGroup($this->group);
  95. break;
  96. default:
  97. // TRANS: Client error displayed when coming across a non-supported API method.
  98. $this->clientError(_('API method not found.'), 404);
  99. }
  100. }
  101. /**
  102. * When was this group last modified?
  103. *
  104. * @return string datestamp of the latest notice in the stream
  105. */
  106. function lastModified()
  107. {
  108. if (!empty($this->group)) {
  109. return strtotime($this->group->modified);
  110. }
  111. return null;
  112. }
  113. /**
  114. * An entity tag for this group
  115. *
  116. * Returns an Etag based on the action name, language, and
  117. * timestamps of the notice
  118. *
  119. * @return string etag
  120. */
  121. function etag()
  122. {
  123. if (!empty($this->group)) {
  124. return '"' . implode(
  125. ':',
  126. array($this->arg('action'),
  127. common_user_cache_hash($this->auth_user),
  128. common_language(),
  129. $this->group->id,
  130. strtotime($this->group->modified))
  131. )
  132. . '"';
  133. }
  134. return null;
  135. }
  136. /**
  137. * Return true if read only.
  138. *
  139. * MAY override
  140. *
  141. * @param array $args other arguments
  142. *
  143. * @return boolean is read only action?
  144. */
  145. function isReadOnly($args)
  146. {
  147. return true;
  148. }
  149. }