apilistsubscribers.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Show/add/remove list subscribers.
  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. require_once INSTALLDIR . '/lib/api/apilistusers.php';
  31. class ApiListSubscribersAction extends ApiListUsersAction
  32. {
  33. /**
  34. * Subscribe to list
  35. *
  36. * @return boolean success
  37. */
  38. function handlePost()
  39. {
  40. $result = Profile_tag_subscription::add($this->list,
  41. $this->auth_user);
  42. if(empty($result)) {
  43. // TRANS: Client error displayed when an unknown error occurs in the list subscribers action.
  44. $this->clientError(_('An error occured.'), 500);
  45. }
  46. switch($this->format) {
  47. case 'xml':
  48. $this->showSingleXmlList($this->list);
  49. break;
  50. case 'json':
  51. $this->showSingleJsonList($this->list);
  52. break;
  53. default:
  54. // TRANS: Client error displayed when coming across a non-supported API method.
  55. $this->clientError(_('API method not found.'), 404);
  56. }
  57. }
  58. function handleDelete()
  59. {
  60. $args = array('profile_tag_id' => $this->list->id,
  61. 'profile_id' => $this->auth_user->id);
  62. $ptag = Profile_tag_subscription::pkeyGet($args);
  63. if(empty($ptag)) {
  64. // TRANS: Client error displayed when trying to unsubscribe from a non-subscribed list.
  65. $this->clientError(_('You are not subscribed to this list.'));
  66. }
  67. $result = Profile_tag_subscription::remove($this->list, $this->auth_user);
  68. if (empty($result)) {
  69. // TRANS: Client error displayed when an unknown error occurs unsubscribing from a list.
  70. $this->clientError(_('An error occured.'), 500);
  71. }
  72. switch($this->format) {
  73. case 'xml':
  74. $this->showSingleXmlList($this->list);
  75. break;
  76. case 'json':
  77. $this->showSingleJsonList($this->list);
  78. break;
  79. default:
  80. // TRANS: Client error displayed when coming across a non-supported API method.
  81. $this->clientError(_('API method not found.'), 404);
  82. }
  83. return true;
  84. }
  85. function getUsers()
  86. {
  87. $fn = array($this->list, 'getSubscribers');
  88. list($this->users, $this->next_cursor, $this->prev_cursor) =
  89. Profile_list::getAtCursor($fn, array(), $this->cursor, 20);
  90. }
  91. }