sortablesubscriptionlist.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. $this->out->elementStart('td');
  47. $this->out->checkbox('', '', false);
  48. $this->out->elementEnd('td');
  49. $tableHeaders = array(
  50. // TRANS: Column header in table for user nickname.
  51. 'nickname' => _m('Nickname'),
  52. // TRANS: Column header in table for timestamp when user was created.
  53. 'created' => _m('Created')
  54. );
  55. foreach ($tableHeaders as $id => $label) {
  56. $attrs = array('id' => $id);
  57. $current = (!empty($this->action->sort) && $this->action->sort == $id);
  58. if ($current || empty($this->action->sort) && $id == 'nickname') {
  59. $attrs['class'] = 'current';
  60. }
  61. if ($current && $this->action->reverse) {
  62. $attrs['class'] .= ' reverse';
  63. $attrs['class'] = trim($attrs['class']);
  64. }
  65. $this->out->elementStart('th', $attrs);
  66. $linkAttrs = array();
  67. $params = array('sort' => $id);
  68. if (!empty($this->action->q)) {
  69. $params['q'] = $this->action->q;
  70. }
  71. if ($current && !$this->action->reverse) {
  72. $params['reverse'] = 'true';
  73. }
  74. $args = array();
  75. $filter = $this->action->arg('filter');
  76. if (!empty($filter)) {
  77. $args['filter'] = $filter;
  78. }
  79. $linkAttrs['href'] = common_local_url(
  80. $this->action->arg('action'), $args, $params
  81. );
  82. $this->out->element('a', $linkAttrs, $label);
  83. $this->out->elementEnd('th');
  84. }
  85. // TRANS: Column header for number of subscriptions.
  86. $this->out->element('th', array('id' => 'subscriptions'), _m('Subscriptions'));
  87. // TRANS: Column header for number of notices.
  88. $this->out->element('th', array('id' => 'notices'), _m('Notices'));
  89. $this->out->element('th', array('id' => 'controls'));
  90. $this->out->elementEnd('tr');
  91. $this->out->elementEnd('thead');
  92. $this->out->elementStart('tbody');
  93. }
  94. function endList()
  95. {
  96. $this->out->elementEnd('tbody');
  97. $this->out->elementEnd('table');
  98. }
  99. function newListItem(Profile $profile)
  100. {
  101. return new SortableSubscriptionListItem($profile, $this->owner, $this->action);
  102. }
  103. }
  104. class SortableSubscriptionListItem extends SubscriptionListItem
  105. {
  106. function startItem()
  107. {
  108. $attr = array(
  109. 'class' => 'profile',
  110. 'id' => 'profile-' . $this->profile->id
  111. );
  112. $this->out->elementStart('tr', $attr);
  113. }
  114. function endItem()
  115. {
  116. $this->out->elementEnd('tr');
  117. }
  118. function startProfile()
  119. {
  120. $this->out->elementStart('td', 'entity_profile h-card');
  121. }
  122. function endProfile()
  123. {
  124. $this->out->elementEnd('td');
  125. }
  126. function startActions()
  127. {
  128. $this->out->elementStart('td', 'entity_actions');
  129. $this->out->elementStart('ul');
  130. }
  131. function endActions()
  132. {
  133. // delete button
  134. $cur = common_current_user();
  135. list($action, $r2args) = $this->out->returnToArgs();
  136. $r2args['action'] = $action;
  137. if ($cur instanceof User && $cur->hasRight(Right::DELETEUSER)) {
  138. $this->out->elementStart('li', 'entity_delete');
  139. $df = new DeleteUserForm($this->out, $this->profile, $r2args);
  140. $df->show();
  141. $this->out->elementEnd('li');
  142. }
  143. $this->out->elementEnd('ul');
  144. $this->out->elementEnd('td');
  145. }
  146. function show()
  147. {
  148. if (Event::handle('StartProfileListItem', array($this))) {
  149. $this->startItem();
  150. $this->out->elementStart('td');
  151. // $this->out->checkbox('', '', false, '', $this->profile->id, false, 'ids[]');
  152. $this->out->input('', '', $this->profile->id, '', 'ids[]', false, [
  153. 'type' => 'checkbox', 'form' => 'form_bulk']);
  154. $this->out->elementEnd('td');
  155. if (Event::handle('StartProfileListItemProfile', array($this))) {
  156. $this->showProfile();
  157. Event::handle('EndProfileListItemProfile', array($this));
  158. }
  159. // XXX Add events?
  160. $this->showCreatedDate();
  161. $this->showSubscriberCount();
  162. $this->showNoticeCount();
  163. if (Event::handle('StartProfileListItemActions', array($this))) {
  164. $this->showActions();
  165. Event::handle('EndProfileListItemActions', array($this));
  166. }
  167. $this->endItem();
  168. Event::handle('EndProfileListItem', array($this));
  169. }
  170. }
  171. function showSubscriberCount()
  172. {
  173. $this->out->elementStart('td', 'entry_subscriber_count');
  174. $this->out->text($this->profile->subscriberCount());
  175. $this->out->elementEnd('td');
  176. }
  177. function showCreatedDate()
  178. {
  179. $this->out->elementStart('td', 'entry_created');
  180. $this->out->text(date('Y-m-d', strtotime($this->profile->created)));
  181. $this->out->elementEnd('td');
  182. }
  183. function showNoticeCount()
  184. {
  185. $this->out->elementStart('td', 'entry_notice_count');
  186. $this->out->text($this->profile->noticeCount());
  187. $this->out->elementEnd('td');
  188. }
  189. function showBio()
  190. {
  191. if ($this->profile->getDescription()) {
  192. $this->out->elementStart('p', 'note');
  193. $this->out->text($this->profile->getDescription());
  194. $this->out->elementEnd('p');
  195. }
  196. }
  197. /**
  198. * Only show the tags if we're logged in
  199. */
  200. function showTags()
  201. {
  202. if (common_logged_in()) {
  203. parent::showTags();
  204. }
  205. }
  206. }