apilistmemberships.php 3.5 KB

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