apistatusesretweets.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Show up to 100 repeats of a notice
  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 Evan Prodromou <evan@status.net>
  25. * @copyright 2009 StatusNet, Inc.
  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. /**
  33. * Show up to 100 repeats of a notice
  34. *
  35. * @category API
  36. * @package StatusNet
  37. * @author Evan Prodromou <evan@status.net>
  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. */
  41. class ApiStatusesRetweetsAction extends ApiAuthAction
  42. {
  43. const MAXCOUNT = 100;
  44. var $original = null;
  45. var $cnt = self::MAXCOUNT;
  46. /**
  47. * Take arguments for running
  48. *
  49. * @param array $args $_REQUEST args
  50. *
  51. * @return boolean success flag
  52. */
  53. function prepare($args)
  54. {
  55. parent::prepare($args);
  56. $id = $this->trimmed('id');
  57. $this->original = Notice::getKV('id', $id);
  58. if (empty($this->original)) {
  59. // TRANS: Client error displayed trying to display redents of a non-exiting notice.
  60. $this->clientError(_('No such notice.'),
  61. 400, $this->format);
  62. return false;
  63. }
  64. $cnt = $this->trimmed('count');
  65. if (empty($cnt) || !is_integer($cnt)) {
  66. $cnt = 100;
  67. } else {
  68. $this->cnt = min((int)$cnt, self::MAXCOUNT);
  69. }
  70. return true;
  71. }
  72. /**
  73. * Handle the request
  74. *
  75. * Make a new notice for the update, save it, and show it
  76. *
  77. * @param array $args $_REQUEST data (unused)
  78. *
  79. * @return void
  80. */
  81. function handle($args)
  82. {
  83. parent::handle($args);
  84. $strm = $this->original->repeatStream($this->cnt);
  85. switch ($this->format) {
  86. case 'xml':
  87. $this->showXmlTimeline($strm);
  88. break;
  89. case 'json':
  90. $this->showJsonTimeline($strm);
  91. break;
  92. default:
  93. // TRANS: Client error displayed when coming across a non-supported API method.
  94. $this->clientError(_('API method not found.'), $code = 404);
  95. break;
  96. }
  97. }
  98. /**
  99. * Return true if read only.
  100. *
  101. * MAY override
  102. *
  103. * @param array $args other arguments
  104. *
  105. * @return boolean is read only action?
  106. */
  107. function isReadOnly($args)
  108. {
  109. return true;
  110. }
  111. }