apilistsubscriptions.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Get a list of lists a user is subscribed to.
  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. * @copyright 2009 StatusNet, Inc.
  25. * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET')) {
  30. exit(1);
  31. }
  32. class ApiListSubscriptionsAction extends ApiBareAuthAction
  33. {
  34. var $lists = array();
  35. var $cursor = -1;
  36. var $next_cursor = 0;
  37. var $prev_cursor = 0;
  38. /**
  39. * Take arguments for running
  40. *
  41. * @param array $args $_REQUEST args
  42. *
  43. * @return boolean success flag
  44. *
  45. */
  46. protected function prepare(array $args=array())
  47. {
  48. parent::prepare($args);
  49. $this->cursor = (int) $this->arg('cursor', -1);
  50. $user = $this->getTargetUser($this->arg('user'));
  51. if (!($user instanceof User)) {
  52. // TRANS: Client error displayed trying to perform an action related to a non-existing user.
  53. $this->clientError(_('No such user.'), 404);
  54. }
  55. $this->target = $user->getProfile();
  56. $this->getLists();
  57. return true;
  58. }
  59. /**
  60. * Handle the request
  61. *
  62. * Show the lists
  63. *
  64. * @return void
  65. */
  66. protected function handle()
  67. {
  68. parent::handle();
  69. switch($this->format) {
  70. case 'xml':
  71. $this->showXmlLists($this->lists, $this->next_cursor, $this->prev_cursor);
  72. break;
  73. case 'json':
  74. $this->showJsonLists($this->lists, $this->next_cursor, $this->prev_cursor);
  75. break;
  76. default:
  77. // TRANS: Client error displayed when coming across a non-supported API method.
  78. $this->clientError(_('API method not found.'));
  79. }
  80. }
  81. /**
  82. * Return true if read only.
  83. *
  84. * MAY override
  85. *
  86. * @param array $args other arguments
  87. *
  88. * @return boolean is read only action?
  89. */
  90. function isReadOnly($args)
  91. {
  92. return true;
  93. }
  94. function getLists()
  95. {
  96. $fn = array($this->target, 'getTagSubscriptions');
  97. # 20 lists
  98. list($this->lists, $this->next_cursor, $this->prev_cursor) =
  99. Profile_list::getAtCursor($fn, array(), $this->cursor, 20);
  100. }
  101. }