apilistmember.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * API method to check if a user belongs to a list.
  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 Shashi Gowda <connect2shashi@gmail.com>
  25. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  26. * @link http://status.net/
  27. */
  28. if (!defined('STATUSNET')) {
  29. exit(1);
  30. }
  31. /**
  32. * Action handler for Twitter list_memeber methods
  33. *
  34. * @category API
  35. * @package StatusNet
  36. * @author Shashi Gowda <connect2shashi@gmail.com>
  37. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  38. * @link http://status.net/
  39. * @see ApiBareAuthAction
  40. */
  41. class ApiListMemberAction extends ApiBareAuthAction
  42. {
  43. /**
  44. * Set the flags for handling the request. Show the profile if this
  45. * is a GET request AND the profile is a member of the list, add a member
  46. * if it is a POST, remove the profile from the list if method is DELETE
  47. * or if method is POST and an argument _method is set to DELETE. Act
  48. * like we don't know if the current user has no access to the list.
  49. *
  50. * Takes parameters:
  51. * - user: the user id or nickname
  52. * - list_id: the id of the tag or the tag itself
  53. * - id: the id of the member being looked for/added/removed
  54. *
  55. * @return boolean success flag
  56. */
  57. protected function prepare(array $args=array())
  58. {
  59. parent::prepare($args);
  60. $this->target = $this->getTargetProfile($this->arg('id'));
  61. $this->list = $this->getTargetList($this->arg('user'), $this->arg('list_id'));
  62. if (empty($this->list)) {
  63. // TRANS: Client error displayed when referring to a non-existing list.
  64. $this->clientError(_('List not found.'), 404);
  65. }
  66. if (!($this->target instanceof Profile)) {
  67. // TRANS: Client error displayed when referring to a non-existing user.
  68. $this->clientError(_('No such user.'), 404);
  69. }
  70. return true;
  71. }
  72. /**
  73. * Handle the request
  74. *
  75. * @return boolean success flag
  76. */
  77. protected function handle()
  78. {
  79. parent::handle();
  80. $arr = array('tagger' => $this->list->tagger,
  81. 'tag' => $this->list->tag,
  82. 'tagged' => $this->target->id);
  83. $ptag = Profile_tag::pkeyGet($arr);
  84. if(empty($ptag)) {
  85. // TRANS: Client error displayed when referring to a non-list member.
  86. $this->clientError(_('The specified user is not a member of this list.'));
  87. }
  88. $user = $this->twitterUserArray($this->target, true);
  89. switch($this->format) {
  90. case 'xml':
  91. $this->showTwitterXmlUser($user, 'user', true);
  92. break;
  93. case 'json':
  94. $this->showSingleJsonUser($user);
  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. return true;
  101. }
  102. }