groupprofileblock.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2011, StatusNet, Inc.
  5. *
  6. * Profile block to show for a group
  7. *
  8. * PHP version 5
  9. *
  10. * 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 Widget
  24. * @package StatusNet
  25. * @author Evan Prodromou <evan@status.net>
  26. * @copyright 2011 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('STATUSNET')) {
  31. // This check helps protect against security problems;
  32. // your code file can't be executed directly from the web.
  33. exit(1);
  34. }
  35. /**
  36. * Profile block to show for a group
  37. *
  38. * @category Widget
  39. * @package StatusNet
  40. * @author Evan Prodromou <evan@status.net>
  41. * @copyright 2011 StatusNet, Inc.
  42. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  43. * @link http://status.net/
  44. */
  45. class GroupProfileBlock extends ProfileBlock
  46. {
  47. public $widgetOpts;
  48. public $scoped;
  49. public $profile;
  50. protected $group = null;
  51. function __construct($out, $group)
  52. {
  53. parent::__construct($out);
  54. $this->group = $group;
  55. $this->profile = $this->group->getProfile();
  56. }
  57. protected function showAvatar(Profile $profile, $size=null)
  58. {
  59. $avatar_url = $profile->getGroup()->homepage_logo ?: User_group::defaultLogo($size ?: $this->avatarSize());
  60. $this->out->element('img', array('src' => $avatar_url,
  61. 'class' => 'avatar u-photo',
  62. 'width' => $this->avatarSize(),
  63. 'height' => $this->avatarSize(),
  64. 'alt' => $profile->getBestName()));
  65. }
  66. function name()
  67. {
  68. return $this->group->getBestName();
  69. }
  70. function url()
  71. {
  72. return $this->group->homeUrl();
  73. }
  74. function location()
  75. {
  76. return $this->group->location;
  77. }
  78. function homepage()
  79. {
  80. return $this->group->homepage;
  81. }
  82. function description()
  83. {
  84. return $this->group->description;
  85. }
  86. function otherProfiles()
  87. {
  88. return array();
  89. }
  90. function showActions()
  91. {
  92. $cur = common_current_user();
  93. $this->out->elementStart('div', 'entity_actions');
  94. // TRANS: Group actions header (h2). Text hidden by default.
  95. $this->out->element('h2', null, _('Group actions'));
  96. $this->out->elementStart('ul');
  97. if (Event::handle('StartGroupActionsList', array($this, $this->group))) {
  98. $this->out->elementStart('li', 'entity_subscribe');
  99. if (Event::handle('StartGroupSubscribe', array($this, $this->group))) {
  100. if ($cur) {
  101. $profile = $cur->getProfile();
  102. if ($profile->isMember($this->group)) {
  103. $lf = new LeaveForm($this->out, $this->group);
  104. $lf->show();
  105. } else if ($profile->isPendingMember($this->group)) {
  106. $cf = new CancelGroupForm($this->out, $this->group);
  107. $cf->show();
  108. } else if (!Group_block::isBlocked($this->group, $profile)) {
  109. $jf = new JoinForm($this->out, $this->group);
  110. $jf->show();
  111. }
  112. }
  113. Event::handle('EndGroupSubscribe', array($this, $this->group));
  114. }
  115. $this->out->elementEnd('li');
  116. if ($cur && $cur->isAdmin($this->group)) {
  117. $this->out->elementStart('li', 'entity_edit');
  118. $this->out->element('a', array('href' => common_local_url('editgroup',
  119. array('nickname' => $this->group->nickname)),
  120. // TRANS: Tooltip for menu item in the group navigation page. Only shown for group administrators.
  121. // TRANS: %s is the nickname of the group.
  122. 'title' => sprintf(_m('TOOLTIP','Edit %s group properties'), $this->group->nickname)),
  123. // TRANS: Link text for link on user profile.
  124. _m('BUTTON','Edit'));
  125. $this->out->elementEnd('li');
  126. $this->out->elementStart('li', 'entity_edit');
  127. $this->out->element('a', array('href' => common_local_url('grouplogo',
  128. array('nickname' => $this->group->nickname)),
  129. // TRANS: Tooltip for menu item in the group navigation page. Only shown for group administrators.
  130. // TRANS: %s is the nickname of the group.
  131. 'title' => sprintf(_m('TOOLTIP','Add or edit %s logo'), $this->group->nickname)),
  132. // TRANS: Link text for link on user profile.
  133. _m('MENU','Logo'));
  134. $this->out->elementEnd('li');
  135. }
  136. if ($cur && $cur->hasRight(Right::DELETEGROUP)) {
  137. $this->out->elementStart('li', 'entity_delete');
  138. $df = new DeleteGroupForm($this->out, $this->group);
  139. $df->show();
  140. $this->out->elementEnd('li');
  141. }
  142. Event::handle('EndGroupActionsList', array($this, $this->group));
  143. }
  144. $this->out->elementEnd('ul');
  145. $this->out->elementEnd('div');
  146. }
  147. function show()
  148. {
  149. $this->out->elementStart('div', 'profile_block group_profile_block section');
  150. if (Event::handle('StartShowGroupProfileBlock', array($this->out, $this->group))) {
  151. parent::show();
  152. Event::handle('EndShowGroupProfileBlock', array($this->out, $this->group));
  153. }
  154. $this->out->elementEnd('div');
  155. }
  156. function showName()
  157. {
  158. parent::showName();
  159. $this->showAliases();
  160. }
  161. function showAliases()
  162. {
  163. $aliases = $this->group->getAliases();
  164. if (!empty($aliases)) {
  165. $this->out->elementStart('ul', 'group_aliases');
  166. foreach ($aliases as $alias) {
  167. $this->out->element('li', 'group_alias', $alias);
  168. }
  169. $this->out->elementEnd('ul');
  170. }
  171. }
  172. }