peopletaglistitem.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Widget to show a list of peopletags
  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 Shashi Gowda <connect2shashi@gmail.com>
  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('GNUSOCIAL')) { exit(1); }
  30. class PeopletagListItem extends Widget
  31. {
  32. var $peopletag = null;
  33. var $current = null;
  34. var $profile = null;
  35. /**
  36. * constructor
  37. *
  38. * Also initializes the owner attribute.
  39. *
  40. * @param Notice $notice The notice we'll display
  41. */
  42. function __construct($peopletag, $current, $out=null)
  43. {
  44. parent::__construct($out);
  45. $this->peopletag = $peopletag;
  46. $this->current = $current;
  47. $this->profile = Profile::getKV('id', $this->peopletag->tagger);
  48. }
  49. /**
  50. * recipe function for displaying a single peopletag.
  51. *
  52. * This uses all the other methods to correctly display a notice. Override
  53. * it or one of the others to fine-tune the output.
  54. *
  55. * @return void
  56. */
  57. function url()
  58. {
  59. return $this->peopletag->homeUrl();
  60. }
  61. function show()
  62. {
  63. if (empty($this->peopletag)) {
  64. common_log(LOG_WARNING, "Trying to show missing peopletag; skipping.");
  65. return;
  66. }
  67. if (Event::handle('StartShowPeopletagItem', array($this))) {
  68. $this->showStart();
  69. $this->showPeopletag();
  70. $this->showStats();
  71. $this->showEnd();
  72. Event::handle('EndShowPeopletagItem', array($this));
  73. }
  74. }
  75. function showStart()
  76. {
  77. $mode = ($this->peopletag->private) ? 'private' : 'public';
  78. $this->out->elementStart('li', array('class' => 'h-entry peopletag mode-' . $mode,
  79. 'id' => 'peopletag-' . $this->peopletag->id));
  80. }
  81. function showEnd()
  82. {
  83. $this->out->elementEnd('li');
  84. }
  85. function showPeopletag()
  86. {
  87. $this->showCreator();
  88. $this->showTag();
  89. $this->showPrivacy();
  90. $this->showUpdated();
  91. $this->showActions();
  92. $this->showDescription();
  93. }
  94. function showStats()
  95. {
  96. $this->out->elementStart('div', 'entry-summary entity_statistics');
  97. $this->out->elementStart('span', 'tagged-count');
  98. $this->out->element('a',
  99. array('href' => common_local_url('peopletagged',
  100. array('tagger' => $this->profile->nickname,
  101. 'tag' => $this->peopletag->tag))),
  102. // TRANS: Link description for link to list of users tagged with a tag (so part of a list).
  103. _('Listed'));
  104. $this->out->raw($this->peopletag->taggedCount());
  105. $this->out->elementEnd('span');
  106. $this->out->elementStart('span', 'subscriber-count');
  107. $this->out->element('a',
  108. array('href' => common_local_url('peopletagsubscribers',
  109. array('tagger' => $this->profile->nickname,
  110. 'tag' => $this->peopletag->tag))),
  111. // TRANS: Link description for link to list of users subscribed to a tag.
  112. _('Subscribers'));
  113. $this->out->raw($this->peopletag->subscriberCount());
  114. $this->out->elementEnd('span');
  115. $this->out->elementEnd('div');
  116. }
  117. function showOwnerOptions()
  118. {
  119. $this->out->elementStart('li', 'entity_edit');
  120. $this->out->element('a', array('href' =>
  121. common_local_url('editpeopletag', array('tagger' => $this->profile->nickname,
  122. 'tag' => $this->peopletag->tag)),
  123. // TRANS: Title for link to edit list settings.
  124. 'title' => _('Edit list settings.')),
  125. // TRANS: Text for link to edit list settings.
  126. _('Edit'));
  127. $this->out->elementEnd('li');
  128. }
  129. function showSubscribeForm()
  130. {
  131. $this->out->elementStart('li');
  132. if (Event::handle('StartSubscribePeopletagForm', array($this->out, $this->peopletag))) {
  133. if ($this->current) {
  134. if ($this->peopletag->hasSubscriber($this->current->id)) {
  135. $form = new UnsubscribePeopletagForm($this->out, $this->peopletag);
  136. $form->show();
  137. } else {
  138. $form = new SubscribePeopletagForm($this->out, $this->peopletag);
  139. $form->show();
  140. }
  141. }
  142. Event::handle('EndSubscribePeopletagForm', array($this->out, $this->peopletag));
  143. }
  144. $this->out->elementEnd('li');
  145. }
  146. function showCreator()
  147. {
  148. $attrs = array();
  149. $attrs['href'] = $this->profile->profileurl;
  150. $attrs['class'] = 'h-card p-author nickname p-name';
  151. $attrs['rel'] = 'contact';
  152. $attrs['title'] = $this->profile->getFancyName();
  153. $this->out->elementStart('a', $attrs);
  154. $this->showAvatar($this->profile);
  155. $this->out->text($this->profile->getNickname());
  156. $this->out->elementEnd('a');
  157. }
  158. function showUpdated()
  159. {
  160. if (!empty($this->peopletag->modified)) {
  161. $this->out->element('abbr',
  162. array('title' => common_date_w3dtf($this->peopletag->modified),
  163. 'class' => 'updated'),
  164. common_date_string($this->peopletag->modified));
  165. }
  166. }
  167. function showPrivacy()
  168. {
  169. if ($this->peopletag->private) {
  170. $this->out->elementStart('a',
  171. array('href' => common_local_url('peopletagsbyuser',
  172. array('nickname' => $this->profile->nickname, 'private' => 1))));
  173. // TRANS: Privacy mode text in list list item for private list.
  174. $this->out->element('span', 'privacy_mode', _m('MODE','Private'));
  175. $this->out->elementEnd('a');
  176. }
  177. }
  178. function showTag()
  179. {
  180. $this->out->elementStart('span', 'entry-title tag');
  181. $this->out->element('a',
  182. array('rel' => 'bookmark',
  183. 'href' => $this->url()),
  184. htmlspecialchars($this->peopletag->tag));
  185. $this->out->elementEnd('span');
  186. }
  187. function showActions()
  188. {
  189. $this->out->elementStart('div', 'entity_actions');
  190. $this->out->elementStart('ul');
  191. if (!$this->peopletag->private) {
  192. $this->showSubscribeForm();
  193. }
  194. if (!empty($this->current) && $this->profile->id == $this->current->id) {
  195. $this->showOwnerOptions();
  196. }
  197. $this->out->elementEnd('ul');
  198. $this->out->elementEnd('div');
  199. }
  200. function showDescription()
  201. {
  202. $this->out->element('div', 'e-content description', $this->peopletag->description);
  203. }
  204. }