sortablesubscriptionlist.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 SortableSubscriptionList extends SubscriptionList
  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 for number of subscriptions.
  83. $this->out->element('th', array('id' => 'subscriptions'), _m('Subscriptions'));
  84. // TRANS: Column header for number of notices.
  85. $this->out->element('th', array('id' => 'notices'), _m('Notices'));
  86. $this->out->element('th', array('id' => 'controls'), null);
  87. $this->out->elementEnd('tr');
  88. $this->out->elementEnd('thead');
  89. $this->out->elementStart('tbody');
  90. }
  91. function endList()
  92. {
  93. $this->out->elementEnd('tbody');
  94. $this->out->elementEnd('table');
  95. }
  96. function newListItem(Profile $profile)
  97. {
  98. return new SortableSubscriptionListItem($profile, $this->owner, $this->action);
  99. }
  100. }
  101. class SortableSubscriptionListItem extends SubscriptionListItem
  102. {
  103. function startItem()
  104. {
  105. $attr = array(
  106. 'class' => 'profile',
  107. 'id' => 'profile-' . $this->profile->id
  108. );
  109. $this->out->elementStart('tr', $attr);
  110. }
  111. function endItem()
  112. {
  113. $this->out->elementEnd('tr');
  114. }
  115. function startProfile()
  116. {
  117. $this->out->elementStart('td', 'entity_profile h-card');
  118. }
  119. function endProfile()
  120. {
  121. $this->out->elementEnd('td');
  122. }
  123. function startActions()
  124. {
  125. $this->out->elementStart('td', 'entity_actions');
  126. $this->out->elementStart('ul');
  127. }
  128. function endActions()
  129. {
  130. // delete button
  131. $cur = common_current_user();
  132. list($action, $r2args) = $this->out->returnToArgs();
  133. $r2args['action'] = $action;
  134. if ($cur instanceof User && $cur->hasRight(Right::DELETEUSER)) {
  135. $this->out->elementStart('li', 'entity_delete');
  136. $df = new DeleteUserForm($this->out, $this->profile, $r2args);
  137. $df->show();
  138. $this->out->elementEnd('li');
  139. }
  140. $this->out->elementEnd('ul');
  141. $this->out->elementEnd('td');
  142. }
  143. function show()
  144. {
  145. if (Event::handle('StartProfileListItem', array($this))) {
  146. $this->startItem();
  147. if (Event::handle('StartProfileListItemProfile', array($this))) {
  148. $this->showProfile();
  149. Event::handle('EndProfileListItemProfile', array($this));
  150. }
  151. // XXX Add events?
  152. $this->showCreatedDate();
  153. $this->showSubscriberCount();
  154. $this->showNoticeCount();
  155. if (Event::handle('StartProfileListItemActions', array($this))) {
  156. $this->showActions();
  157. Event::handle('EndProfileListItemActions', array($this));
  158. }
  159. $this->endItem();
  160. Event::handle('EndProfileListItem', array($this));
  161. }
  162. }
  163. function showSubscriberCount()
  164. {
  165. $this->out->elementStart('td', 'entry_subscriber_count');
  166. $this->out->text($this->profile->subscriberCount());
  167. $this->out->elementEnd('td');
  168. }
  169. function showCreatedDate()
  170. {
  171. $this->out->elementStart('td', 'entry_created');
  172. $this->out->text(date('j M Y', strtotime($this->profile->created)));
  173. $this->out->elementEnd('td');
  174. }
  175. function showNoticeCount()
  176. {
  177. $this->out->elementStart('td', 'entry_notice_count');
  178. $this->out->text($this->profile->noticeCount());
  179. $this->out->elementEnd('td');
  180. }
  181. function showBio()
  182. {
  183. if ($this->profile->getDescription()) {
  184. $this->out->elementStart('p', 'note');
  185. $this->out->text($this->profile->getDescription());
  186. $this->out->elementEnd('p');
  187. }
  188. }
  189. /**
  190. * Only show the tags if we're logged in
  191. */
  192. function showTags()
  193. {
  194. if (common_logged_in()) {
  195. parent::showTags();
  196. }
  197. }
  198. }