groupprofileblock.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. protected $group = null;
  48. function __construct($out, $group)
  49. {
  50. parent::__construct($out);
  51. $this->group = $group;
  52. $this->profile = $this->group->getProfile();
  53. }
  54. protected function showAvatar(Profile $profile, $size=null)
  55. {
  56. $avatar_url = $profile->getGroup()->homepage_logo ?: User_group::defaultLogo($size ?: $this->avatarSize());
  57. $this->out->element('img', array('src' => $avatar_url,
  58. 'class' => 'avatar u-photo',
  59. 'width' => $this->avatarSize(),
  60. 'height' => $this->avatarSize(),
  61. 'alt' => $profile->getBestName()));
  62. }
  63. function name()
  64. {
  65. return $this->group->getBestName();
  66. }
  67. function url()
  68. {
  69. return $this->group->homeUrl();
  70. }
  71. function location()
  72. {
  73. return $this->group->location;
  74. }
  75. function homepage()
  76. {
  77. return $this->group->homepage;
  78. }
  79. function description()
  80. {
  81. return $this->group->description;
  82. }
  83. function otherProfiles()
  84. {
  85. return array();
  86. }
  87. function showActions()
  88. {
  89. $cur = common_current_user();
  90. $this->out->elementStart('div', 'entity_actions');
  91. // TRANS: Group actions header (h2). Text hidden by default.
  92. $this->out->element('h2', null, _('Group actions'));
  93. $this->out->elementStart('ul');
  94. if (Event::handle('StartGroupActionsList', array($this, $this->group))) {
  95. $this->out->elementStart('li', 'entity_subscribe');
  96. if (Event::handle('StartGroupSubscribe', array($this, $this->group))) {
  97. if ($cur) {
  98. $profile = $cur->getProfile();
  99. if ($profile->isMember($this->group)) {
  100. $lf = new LeaveForm($this->out, $this->group);
  101. $lf->show();
  102. } else if ($profile->isPendingMember($this->group)) {
  103. $cf = new CancelGroupForm($this->out, $this->group);
  104. $cf->show();
  105. } else if (!Group_block::isBlocked($this->group, $profile)) {
  106. $jf = new JoinForm($this->out, $this->group);
  107. $jf->show();
  108. }
  109. }
  110. Event::handle('EndGroupSubscribe', array($this, $this->group));
  111. }
  112. $this->out->elementEnd('li');
  113. if ($cur && $cur->isAdmin($this->group)) {
  114. $this->out->elementStart('li', 'entity_edit');
  115. $this->out->element('a', array('href' => common_local_url('editgroup',
  116. array('nickname' => $this->group->nickname)),
  117. // TRANS: Tooltip for menu item in the group navigation page. Only shown for group administrators.
  118. // TRANS: %s is the nickname of the group.
  119. 'title' => sprintf(_m('TOOLTIP','Edit %s group properties'), $this->group->nickname)),
  120. // TRANS: Link text for link on user profile.
  121. _m('BUTTON','Edit'));
  122. $this->out->elementEnd('li');
  123. $this->out->elementStart('li', 'entity_edit');
  124. $this->out->element('a', array('href' => common_local_url('grouplogo',
  125. array('nickname' => $this->group->nickname)),
  126. // TRANS: Tooltip for menu item in the group navigation page. Only shown for group administrators.
  127. // TRANS: %s is the nickname of the group.
  128. 'title' => sprintf(_m('TOOLTIP','Add or edit %s logo'), $this->group->nickname)),
  129. // TRANS: Link text for link on user profile.
  130. _m('MENU','Logo'));
  131. $this->out->elementEnd('li');
  132. }
  133. if ($cur && $cur->hasRight(Right::DELETEGROUP)) {
  134. $this->out->elementStart('li', 'entity_delete');
  135. $df = new DeleteGroupForm($this->out, $this->group);
  136. $df->show();
  137. $this->out->elementEnd('li');
  138. }
  139. Event::handle('EndGroupActionsList', array($this, $this->group));
  140. }
  141. $this->out->elementEnd('ul');
  142. $this->out->elementEnd('div');
  143. }
  144. function show()
  145. {
  146. $this->out->elementStart('div', 'profile_block group_profile_block section');
  147. if (Event::handle('StartShowGroupProfileBlock', array($this->out, $this->group))) {
  148. parent::show();
  149. Event::handle('EndShowGroupProfileBlock', array($this->out, $this->group));
  150. }
  151. $this->out->elementEnd('div');
  152. }
  153. function showName()
  154. {
  155. parent::showName();
  156. $this->showAliases();
  157. }
  158. function showAliases()
  159. {
  160. $aliases = $this->group->getAliases();
  161. if (!empty($aliases)) {
  162. $this->out->elementStart('ul', 'group_aliases');
  163. foreach ($aliases as $alias) {
  164. $this->out->element('li', 'group_alias', $alias);
  165. }
  166. $this->out->elementEnd('ul');
  167. }
  168. }
  169. }