grouplist.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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/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. /** Current group, group query. */
  45. var $group = null;
  46. /** Owner of this list */
  47. var $owner = null;
  48. /** Action object using us. */
  49. var $action = null;
  50. function __construct($group, $owner=null, $action=null)
  51. {
  52. parent::__construct($action);
  53. $this->group = $group;
  54. $this->owner = $owner;
  55. $this->action = $action;
  56. }
  57. function show()
  58. {
  59. $this->out->elementStart('ul', 'profiles groups xoxo');
  60. $cnt = 0;
  61. while ($this->group->fetch()) {
  62. $cnt++;
  63. if($cnt > GROUPS_PER_PAGE) {
  64. break;
  65. }
  66. $this->showgroup();
  67. }
  68. $this->out->elementEnd('ul');
  69. return $cnt;
  70. }
  71. function showGroup()
  72. {
  73. $this->out->elementStart('li', array('class' => 'profile h-card',
  74. 'id' => 'group-' . $this->group->id));
  75. $user = common_current_user();
  76. $this->out->elementStart('div', 'entity_profile');
  77. $logo = $this->group->stream_logo ?: User_group::defaultLogo(AVATAR_STREAM_SIZE);
  78. $this->out->elementStart('a', array('href' => $this->group->homeUrl(),
  79. 'class' => 'u-url p-nickname',
  80. 'rel' => 'contact group'));
  81. $this->out->element('img', array('src' => $logo,
  82. 'class' => 'avatar u-photo',
  83. 'width' => AVATAR_STREAM_SIZE,
  84. 'height' => AVATAR_STREAM_SIZE,
  85. 'alt' => $this->group->getBestName()));
  86. $this->out->text($this->group->getNickname());
  87. $this->out->elementEnd('a');
  88. if ($this->group->fullname) {
  89. $this->out->text(' ');
  90. $this->out->elementStart('span', 'p-name');
  91. $this->out->raw($this->highlight($this->group->fullname));
  92. $this->out->elementEnd('span');
  93. }
  94. if ($this->group->location) {
  95. $this->out->text(' ');
  96. $this->out->elementStart('span', 'label');
  97. $this->out->raw($this->highlight($this->group->location));
  98. $this->out->elementEnd('span');
  99. }
  100. if ($this->group->homepage) {
  101. $this->out->text(' ');
  102. $this->out->elementStart('a', array('href' => $this->group->homepage,
  103. 'class' => 'u-url'));
  104. $this->out->raw($this->highlight($this->group->homepage));
  105. $this->out->elementEnd('a');
  106. }
  107. if ($this->group->description) {
  108. $this->out->elementStart('p', 'note');
  109. $this->out->raw($this->highlight($this->group->description));
  110. $this->out->elementEnd('p');
  111. }
  112. // If we're on a list with an owner (subscriptions or subscribers)...
  113. if (!empty($user) && !empty($this->owner) && $user->id == $this->owner->id) {
  114. $this->showOwnerControls();
  115. }
  116. $this->out->elementEnd('div');
  117. if ($user) {
  118. $this->out->elementStart('div', 'entity_actions');
  119. $this->out->elementStart('ul');
  120. $this->out->elementStart('li', 'entity_subscribe');
  121. // XXX: special-case for user looking at own
  122. // subscriptions page
  123. if ($user->isMember($this->group)) {
  124. $lf = new LeaveForm($this->out, $this->group);
  125. $lf->show();
  126. } else if (!Group_block::isBlocked($this->group, $user->getProfile())) {
  127. $jf = new JoinForm($this->out, $this->group);
  128. $jf->show();
  129. }
  130. $this->out->elementEnd('li');
  131. $this->out->elementEnd('ul');
  132. $this->out->elementEnd('div');
  133. }
  134. $this->out->elementEnd('li');
  135. }
  136. /* Override this in subclasses. */
  137. function showOwnerControls()
  138. {
  139. return;
  140. }
  141. function highlight($text)
  142. {
  143. return htmlspecialchars($text);
  144. }
  145. }