atomgroupnoticefeed.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Class for building an in-memory Atom feed for a particular group's
  6. * timeline.
  7. *
  8. * PHP version 5
  9. *
  10. * LICENCE: This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * @category Feed
  24. * @package StatusNet
  25. * @author Zach Copley <zach@status.net>
  26. * @copyright 2010 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('STATUSNET'))
  31. {
  32. exit(1);
  33. }
  34. /**
  35. * Class for group notice feeds. May contains a reference to the group.
  36. *
  37. * @category Feed
  38. * @package StatusNet
  39. * @author Zach Copley <zach@status.net>
  40. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  41. * @link http://status.net/
  42. */
  43. class AtomGroupNoticeFeed extends AtomNoticeFeed
  44. {
  45. private $group;
  46. /**
  47. * Constructor
  48. *
  49. * @param Group $group the group for the feed
  50. * @param User $cur the current authenticated user, if any
  51. * @param boolean $indent flag to turn indenting on or off
  52. *
  53. * @return void
  54. */
  55. function __construct($group, $cur = null, $indent = true) {
  56. parent::__construct($cur, $indent);
  57. $this->group = $group;
  58. // TRANS: Title in atom group notice feed. %s is a group name.
  59. $title = sprintf(_("%s timeline"), $group->nickname);
  60. $this->setTitle($title);
  61. $sitename = common_config('site', 'name');
  62. $subtitle = sprintf(
  63. // TRANS: Message is used as a subtitle in atom group notice feed.
  64. // TRANS: %1$s is a group name, %2$s is a site name.
  65. _('Updates from %1$s on %2$s!'),
  66. $group->nickname,
  67. $sitename
  68. );
  69. $this->setSubtitle($subtitle);
  70. $avatar = $group->homepage_logo;
  71. $logo = ($avatar) ? $avatar : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
  72. $this->setLogo($logo);
  73. $this->setUpdated('now');
  74. $self = common_local_url('ApiTimelineGroup',
  75. array('id' => $group->id,
  76. 'format' => 'atom'));
  77. $this->setId($self);
  78. $this->setSelfLink($self);
  79. $ao = ActivityObject::fromGroup($group);
  80. $this->addAuthorRaw($ao->asString('author'));
  81. $this->addLink($group->homeUrl());
  82. }
  83. function getGroup()
  84. {
  85. return $this->group;
  86. }
  87. function initFeed()
  88. {
  89. parent::initFeed();
  90. $attrs = array();
  91. if (!empty($this->cur)) {
  92. $attrs['member'] = $this->cur->isMember($this->group)
  93. ? 'true' : 'false';
  94. $attrs['blocked'] = Group_block::isBlocked(
  95. $this->group,
  96. $this->cur->getProfile()
  97. ) ? 'true' : 'false';
  98. }
  99. $attrs['member_count'] = $this->group->getMemberCount();
  100. $this->element('statusnet:group_info', $attrs);
  101. }
  102. }