sortablegrouplist.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Widget to show a sortable list of profiles
  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 Zach Copley <zach@status.net>
  25. * @copyright 2011 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('GNUSOCIAL')) { exit(1); }
  30. /**
  31. * Widget to show a sortable list of subscriptions
  32. *
  33. * @category Public
  34. * @package StatusNet
  35. * @author Zach Copley <zach@status.net>
  36. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  37. * @link http://status.net/
  38. */
  39. class SortableGroupList extends SortableSubscriptionList
  40. {
  41. function startList()
  42. {
  43. $this->out->elementStart('table', array('class' => 'profile_list xoxo'));
  44. $this->out->elementStart('thead');
  45. $this->out->elementStart('tr');
  46. $tableHeaders = array(
  47. // TRANS: Column header in table for user nickname.
  48. 'nickname' => _m('Nickname'),
  49. // TRANS: Column header in table for timestamp when user was created.
  50. 'created' => _m('Created')
  51. );
  52. foreach ($tableHeaders as $id => $label) {
  53. $attrs = array('id' => $id);
  54. $current = (!empty($this->action->sort) && $this->action->sort == $id);
  55. if ($current || empty($this->action->sort) && $id == 'nickname') {
  56. $attrs['class'] = 'current';
  57. }
  58. if ($current && $this->action->reverse) {
  59. $attrs['class'] .= ' reverse';
  60. $attrs['class'] = trim($attrs['class']);
  61. }
  62. $this->out->elementStart('th', $attrs);
  63. $linkAttrs = array();
  64. $params = array('sort' => $id);
  65. if (!empty($this->action->q)) {
  66. $params['q'] = $this->action->q;
  67. }
  68. if ($current && !$this->action->reverse) {
  69. $params['reverse'] = 'true';
  70. }
  71. $args = array();
  72. $filter = $this->action->arg('filter');
  73. if (!empty($filter)) {
  74. $args['filter'] = $filter;
  75. }
  76. $linkAttrs['href'] = common_local_url(
  77. $this->action->arg('action'), $args, $params
  78. );
  79. $this->out->element('a', $linkAttrs, $label);
  80. $this->out->elementEnd('th');
  81. }
  82. // TRANS: Column header in table for members of a group.
  83. $this->out->element('th', array('id' => 'Members'), _m('Members'));
  84. $this->out->element('th', array('id' => 'controls'), null);
  85. $this->out->elementEnd('tr');
  86. $this->out->elementEnd('thead');
  87. $this->out->elementStart('tbody');
  88. }
  89. function newListItem(Profile $profile)
  90. {
  91. return new SortableGroupListItem($profile, $this->owner, $this->action);
  92. }
  93. }
  94. class SortableGroupListItem extends SortableSubscriptionListItem
  95. {
  96. function showHomepage()
  97. {
  98. if ($this->profile->getHomepage()) {
  99. $this->out->text(' ');
  100. $aAttrs = $this->homepageAttributes();
  101. $this->out->elementStart('a', $aAttrs);
  102. $this->out->text($this->profile->getHomepage());
  103. $this->out->elementEnd('a');
  104. }
  105. }
  106. function showDescription()
  107. {
  108. if ($this->profile->getDescription()) {
  109. $this->out->elementStart('p', 'note');
  110. $this->out->text($this->profile->getDescription());
  111. $this->out->elementEnd('p');
  112. }
  113. }
  114. // TODO: Make sure we can do ->getAvatar() for group profiles too!
  115. function showAvatar(Profile $profile, $size=null)
  116. {
  117. $logo = $profile->getGroup()->stream_logo ?: User_group::defaultLogo($size ?: $this->avatarSize());
  118. $this->out->element('img', array('src' => $logo,
  119. 'class' => 'avatar u-photo',
  120. 'width' => AVATAR_STREAM_SIZE,
  121. 'height' => AVATAR_STREAM_SIZE,
  122. 'alt' => $profile->getBestName()));
  123. }
  124. function show()
  125. {
  126. if (Event::handle('StartProfileListItem', array($this))) {
  127. $this->startItem();
  128. if (Event::handle('StartProfileListItemProfile', array($this))) {
  129. $this->showProfile();
  130. Event::handle('EndProfileListItemProfile', array($this));
  131. }
  132. // XXX Add events?
  133. $this->showCreatedDate();
  134. $this->showMemberCount();
  135. if (Event::handle('StartProfileListItemActions', array($this))) {
  136. $this->showActions();
  137. Event::handle('EndProfileListItemActions', array($this));
  138. }
  139. $this->endItem();
  140. Event::handle('EndProfileListItem', array($this));
  141. }
  142. }
  143. function showProfile()
  144. {
  145. $this->startProfile();
  146. $this->showAvatar($this->profile);
  147. $this->out->element('a', array('href' => $this->profile->getUrl(),
  148. 'class' => 'p-org p-nickname',
  149. 'rel' => 'contact group'),
  150. $this->profile->getNickname());
  151. $this->showFullName();
  152. $this->showLocation();
  153. $this->showHomepage();
  154. $this->showDescription(); // groups have this instead of bios
  155. // Relevant portion!
  156. $this->showTags();
  157. $this->endProfile();
  158. }
  159. function endActions()
  160. {
  161. // delete button
  162. $cur = common_current_user();
  163. list($action, $r2args) = $this->out->returnToArgs();
  164. $r2args['action'] = $action;
  165. if ($cur instanceof User && $cur->hasRight(Right::DELETEGROUP)) {
  166. $this->out->elementStart('li', 'entity_delete');
  167. $df = new DeleteGroupForm($this->out, $this->profile->getGroup(), $r2args);
  168. $df->show();
  169. $this->out->elementEnd('li');
  170. }
  171. $this->out->elementEnd('ul');
  172. $this->out->elementEnd('td');
  173. }
  174. function showActions()
  175. {
  176. $this->startActions();
  177. if (Event::handle('StartProfileListItemActionElements', array($this))) {
  178. $this->showJoinButton();
  179. Event::handle('EndProfileListItemActionElements', array($this));
  180. }
  181. $this->endActions();
  182. }
  183. function showJoinButton()
  184. {
  185. $user = $this->owner;
  186. if ($user) {
  187. $this->out->elementStart('li', 'entity_subscribe');
  188. // XXX: special-case for user looking at own
  189. // subscriptions page
  190. if ($user->isMember($this->profile->getGroup())) {
  191. $lf = new LeaveForm($this->out, $this->profile->getGroup());
  192. $lf->show();
  193. } else if (!Group_block::isBlocked($this->profile->getGroup(), $user->getProfile())) {
  194. $jf = new JoinForm($this->out, $this->profile->getGroup());
  195. $jf->show();
  196. }
  197. $this->out->elementEnd('li');
  198. }
  199. }
  200. function showMemberCount()
  201. {
  202. $this->out->elementStart('td', 'entry_member_count');
  203. $this->out->text($this->profile->getGroup()->getMemberCount());
  204. $this->out->elementEnd('td');
  205. }
  206. function showCreatedDate()
  207. {
  208. $this->out->elementStart('td', 'entry_created');
  209. // @todo FIXME: Should we provide i18n for timestamps in core?
  210. $this->out->text(date('j M Y', strtotime($this->profile->created)));
  211. $this->out->elementEnd('td');
  212. }
  213. function showAdmins()
  214. {
  215. $this->out->elementStart('td', 'entry_admins');
  216. // @todo
  217. $this->out->text('gargargar');
  218. $this->out->elementEnd('td');
  219. }
  220. /**
  221. * Only show the tags if we're logged in
  222. */
  223. function showTags()
  224. {
  225. if (common_logged_in()) {
  226. parent::showTags();
  227. }
  228. }
  229. }