grouplist.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Widget to show a list of groups
  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 Public
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @copyright 2008-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') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. require_once INSTALLDIR . '/lib/ui/widget.php';
  33. /**
  34. * Widget to show a list of groups
  35. *
  36. * @category Public
  37. * @package StatusNet
  38. * @author Evan Prodromou <evan@status.net>
  39. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  40. * @link http://status.net/
  41. */
  42. class GroupList extends Widget
  43. {
  44. public $widgetOpts;
  45. public $scoped;
  46. /** Current group, group query. */
  47. var $group = null;
  48. /** Owner of this list */
  49. var $owner = null;
  50. /** Action object using us. */
  51. var $action = null;
  52. function __construct($group, $owner=null, $action=null)
  53. {
  54. parent::__construct($action);
  55. $this->group = $group;
  56. $this->owner = $owner;
  57. $this->action = $action;
  58. }
  59. function show()
  60. {
  61. $this->out->elementStart('ul', 'profiles groups xoxo');
  62. $cnt = 0;
  63. while ($this->group->fetch()) {
  64. $cnt++;
  65. if($cnt > GROUPS_PER_PAGE) {
  66. break;
  67. }
  68. $this->showgroup();
  69. }
  70. $this->out->elementEnd('ul');
  71. return $cnt;
  72. }
  73. function showGroup()
  74. {
  75. $this->out->elementStart('li', array('class' => 'profile h-card',
  76. 'id' => 'group-' . $this->group->id));
  77. $user = common_current_user();
  78. $this->out->elementStart('div', 'entity_profile');
  79. $logo = $this->group->stream_logo ?: User_group::defaultLogo(AVATAR_STREAM_SIZE);
  80. $this->out->elementStart('a', array('href' => $this->group->homeUrl(),
  81. 'class' => 'u-url p-nickname',
  82. 'rel' => 'contact group'));
  83. $this->out->element('img', array('src' => $logo,
  84. 'class' => 'avatar u-photo',
  85. 'width' => AVATAR_STREAM_SIZE,
  86. 'height' => AVATAR_STREAM_SIZE,
  87. 'alt' => $this->group->getBestName()));
  88. $this->out->text($this->group->getNickname());
  89. $this->out->elementEnd('a');
  90. if ($this->group->fullname) {
  91. $this->out->text(' ');
  92. $this->out->elementStart('span', 'p-name');
  93. $this->out->raw($this->highlight($this->group->fullname));
  94. $this->out->elementEnd('span');
  95. }
  96. if ($this->group->location) {
  97. $this->out->text(' ');
  98. $this->out->elementStart('span', 'label');
  99. $this->out->raw($this->highlight($this->group->location));
  100. $this->out->elementEnd('span');
  101. }
  102. if ($this->group->homepage) {
  103. $this->out->text(' ');
  104. $this->out->elementStart('a', array('href' => $this->group->homepage,
  105. 'class' => 'u-url'));
  106. $this->out->raw($this->highlight($this->group->homepage));
  107. $this->out->elementEnd('a');
  108. }
  109. if ($this->group->description) {
  110. $this->out->elementStart('p', 'note');
  111. $this->out->raw($this->highlight($this->group->description));
  112. $this->out->elementEnd('p');
  113. }
  114. // If we're on a list with an owner (subscriptions or subscribers)...
  115. if (!empty($user) && !empty($this->owner) && $user->id == $this->owner->id) {
  116. $this->showOwnerControls();
  117. }
  118. $this->out->elementEnd('div');
  119. if ($user) {
  120. $this->out->elementStart('div', 'entity_actions');
  121. $this->out->elementStart('ul');
  122. $this->out->elementStart('li', 'entity_subscribe');
  123. // XXX: special-case for user looking at own
  124. // subscriptions page
  125. if ($user->isMember($this->group)) {
  126. $lf = new LeaveForm($this->out, $this->group);
  127. $lf->show();
  128. } else if (!Group_block::isBlocked($this->group, $user->getProfile())) {
  129. $jf = new JoinForm($this->out, $this->group);
  130. $jf->show();
  131. }
  132. $this->out->elementEnd('li');
  133. $this->out->elementEnd('ul');
  134. $this->out->elementEnd('div');
  135. }
  136. $this->out->elementEnd('li');
  137. }
  138. /* Override this in subclasses. */
  139. function showOwnerControls()
  140. {
  141. return;
  142. }
  143. function highlight($text)
  144. {
  145. return htmlspecialchars($text);
  146. }
  147. }