userrss.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2008, 2009, StatusNet, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
  20. require_once(INSTALLDIR.'/lib/rssaction.php');
  21. // Formatting of RSS handled by Rss10Action
  22. class UserrssAction extends Rss10Action
  23. {
  24. var $tag = null;
  25. function prepare($args)
  26. {
  27. parent::prepare($args);
  28. $nickname = $this->trimmed('nickname');
  29. $this->user = User::getKV('nickname', $nickname);
  30. $this->tag = $this->trimmed('tag');
  31. if (!$this->user) {
  32. // TRANS: Client error displayed when user not found for an action.
  33. $this->clientError(_('No such user.'));
  34. }
  35. if (!empty($this->tag)) {
  36. $this->notices = $this->getTaggedNotices();
  37. } else {
  38. $this->notices = $this->getNotices();
  39. }
  40. return true;
  41. }
  42. function getTaggedNotices()
  43. {
  44. $notice = $this->user->getTaggedNotices(
  45. $this->tag,
  46. 0,
  47. ($this->limit == 0) ? NOTICES_PER_PAGE : $this->limit,
  48. 0,
  49. 0
  50. );
  51. $notices = array();
  52. while ($notice->fetch()) {
  53. $notices[] = clone($notice);
  54. }
  55. return $notices;
  56. }
  57. function getNotices()
  58. {
  59. $notice = $this->user->getNotices(
  60. 0,
  61. ($this->limit == 0) ? NOTICES_PER_PAGE : $this->limit
  62. );
  63. $notices = array();
  64. while ($notice->fetch()) {
  65. $notices[] = clone($notice);
  66. }
  67. return $notices;
  68. }
  69. function getChannel()
  70. {
  71. $user = $this->user;
  72. $profile = $user->getProfile();
  73. $c = array('url' => common_local_url('userrss',
  74. array('nickname' =>
  75. $user->nickname)),
  76. // TRANS: Message is used as link title. %s is a user nickname.
  77. 'title' => sprintf(_('%s timeline'), $user->nickname),
  78. 'link' => $profile->profileurl,
  79. // TRANS: Message is used as link description. %1$s is a username, %2$s is a site name.
  80. 'description' => sprintf(_('Updates from %1$s on %2$s!'),
  81. $user->nickname, common_config('site', 'name')));
  82. return $c;
  83. }
  84. function getImage()
  85. {
  86. $profile = $this->user->getProfile();
  87. return $profile->avatarUrl(AVATAR_PROFILE_SIZE);
  88. }
  89. // override parent to add X-SUP-ID URL
  90. function initRss($limit=0)
  91. {
  92. $url = common_local_url('sup', null, null, $this->user->id);
  93. header('X-SUP-ID: '.$url);
  94. parent::initRss($limit);
  95. }
  96. function isReadOnly($args)
  97. {
  98. return true;
  99. }
  100. }