apilistsubscriber.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Check if a user is subscribed 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. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  25. * @link http://status.net/
  26. */
  27. if (!defined('STATUSNET')) {
  28. exit(1);
  29. }
  30. class ApiListSubscriberAction extends ApiBareAuthAction
  31. {
  32. var $list = null;
  33. function prepare($args)
  34. {
  35. parent::prepare($args);
  36. $this->target = $this->getTargetProfile($this->arg('id'));
  37. $this->list = $this->getTargetList($this->arg('user'), $this->arg('list_id'));
  38. if (empty($this->list)) {
  39. // TRANS: Client error displayed trying to perform an action related to a non-existing list.
  40. $this->clientError(_('List not found.'), 404);
  41. }
  42. if (!($this->target instanceof Profile)) {
  43. // TRANS: Client error displayed trying to perform an action related to a non-existing user.
  44. $this->clientError(_('No such user.'), 404);
  45. }
  46. return true;
  47. }
  48. function handle($args)
  49. {
  50. parent::handle($args);
  51. $arr = array('profile_tag_id' => $this->list->id,
  52. 'profile_id' => $this->target->id);
  53. $sub = Profile_tag_subscription::pkeyGet($arr);
  54. if(empty($sub)) {
  55. // TRANS: Client error displayed when a membership check for a user is nagative.
  56. $this->clientError(_('The specified user is not a subscriber of this list.'));
  57. }
  58. $user = $this->twitterUserArray($this->target, true);
  59. switch($this->format) {
  60. case 'xml':
  61. $this->showTwitterXmlUser($user, 'user', true);
  62. break;
  63. case 'json':
  64. $this->showSingleJsonUser($user);
  65. break;
  66. default:
  67. $this->clientError(
  68. // TRANS: Client error displayed when coming across a non-supported API method.
  69. _('API method not found.'),
  70. 404,
  71. $this->format
  72. );
  73. break;
  74. }
  75. }
  76. }