peopletaglist.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. require_once INSTALLDIR.'/lib/widget.php';
  33. define('PEOPLETAGS_PER_PAGE', 20);
  34. /**
  35. * Widget to show a list of peopletags
  36. *
  37. * @category Public
  38. * @package StatusNet
  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 PeopletagList extends Widget
  43. {
  44. /** Current peopletag, peopletag query. */
  45. var $peopletag = null;
  46. /** current user **/
  47. var $user = null;
  48. function __construct($peopletag, $action=null)
  49. {
  50. parent::__construct($action);
  51. $this->peopletag = $peopletag;
  52. if (!empty($owner)) {
  53. $this->user = $owner;
  54. } else {
  55. $this->user = common_current_user();
  56. }
  57. }
  58. function show()
  59. {
  60. $this->out->elementStart('ul', 'peopletags xoxo hfeed');
  61. $cnt = 0;
  62. while ($this->peopletag->fetch()) {
  63. $cnt++;
  64. if($cnt > PEOPLETAGS_PER_PAGE) {
  65. break;
  66. }
  67. $this->showPeopletag();
  68. }
  69. $this->out->elementEnd('ul');
  70. return $cnt;
  71. }
  72. function showPeopletag()
  73. {
  74. $ptag = new PeopletagListItem($this->peopletag, $this->user, $this->out);
  75. $ptag->show();
  76. }
  77. }
  78. class PeopletagListItem extends Widget
  79. {
  80. var $peopletag = null;
  81. var $current = null;
  82. var $profile = null;
  83. /**
  84. * constructor
  85. *
  86. * Also initializes the owner attribute.
  87. *
  88. * @param Notice $notice The notice we'll display
  89. */
  90. function __construct($peopletag, $current, $out=null)
  91. {
  92. parent::__construct($out);
  93. $this->peopletag = $peopletag;
  94. $this->current = $current;
  95. $this->profile = Profile::getKV('id', $this->peopletag->tagger);
  96. }
  97. /**
  98. * recipe function for displaying a single peopletag.
  99. *
  100. * This uses all the other methods to correctly display a notice. Override
  101. * it or one of the others to fine-tune the output.
  102. *
  103. * @return void
  104. */
  105. function url()
  106. {
  107. return $this->peopletag->homeUrl();
  108. }
  109. function show()
  110. {
  111. if (empty($this->peopletag)) {
  112. common_log(LOG_WARNING, "Trying to show missing peopletag; skipping.");
  113. return;
  114. }
  115. if (Event::handle('StartShowPeopletagItem', array($this))) {
  116. $this->showStart();
  117. $this->showPeopletag();
  118. $this->showStats();
  119. $this->showEnd();
  120. Event::handle('EndShowPeopletagItem', array($this));
  121. }
  122. }
  123. function showStart()
  124. {
  125. $mode = ($this->peopletag->private) ? 'private' : 'public';
  126. $this->out->elementStart('li', array('class' => 'h-entry peopletag mode-' . $mode,
  127. 'id' => 'peopletag-' . $this->peopletag->id));
  128. }
  129. function showEnd()
  130. {
  131. $this->out->elementEnd('li');
  132. }
  133. function showPeopletag()
  134. {
  135. $this->showCreator();
  136. $this->showTag();
  137. $this->showPrivacy();
  138. $this->showUpdated();
  139. $this->showActions();
  140. $this->showDescription();
  141. }
  142. function showStats()
  143. {
  144. $this->out->elementStart('div', 'entry-summary entity_statistics');
  145. $this->out->elementStart('span', 'tagged-count');
  146. $this->out->element('a',
  147. array('href' => common_local_url('peopletagged',
  148. array('tagger' => $this->profile->nickname,
  149. 'tag' => $this->peopletag->tag))),
  150. // TRANS: Link description for link to list of users tagged with a tag (so part of a list).
  151. _('Listed'));
  152. $this->out->raw($this->peopletag->taggedCount());
  153. $this->out->elementEnd('span');
  154. $this->out->elementStart('span', 'subscriber-count');
  155. $this->out->element('a',
  156. array('href' => common_local_url('peopletagsubscribers',
  157. array('tagger' => $this->profile->nickname,
  158. 'tag' => $this->peopletag->tag))),
  159. // TRANS: Link description for link to list of users subscribed to a tag.
  160. _('Subscribers'));
  161. $this->out->raw($this->peopletag->subscriberCount());
  162. $this->out->elementEnd('span');
  163. $this->out->elementEnd('div');
  164. }
  165. function showOwnerOptions()
  166. {
  167. $this->out->elementStart('li', 'entity_edit');
  168. $this->out->element('a', array('href' =>
  169. common_local_url('editpeopletag', array('tagger' => $this->profile->nickname,
  170. 'tag' => $this->peopletag->tag)),
  171. // TRANS: Title for link to edit list settings.
  172. 'title' => _('Edit list settings.')),
  173. // TRANS: Text for link to edit list settings.
  174. _('Edit'));
  175. $this->out->elementEnd('li');
  176. }
  177. function showSubscribeForm()
  178. {
  179. $this->out->elementStart('li');
  180. if (Event::handle('StartSubscribePeopletagForm', array($this->out, $this->peopletag))) {
  181. if ($this->current) {
  182. if ($this->peopletag->hasSubscriber($this->current->id)) {
  183. $form = new UnsubscribePeopletagForm($this->out, $this->peopletag);
  184. $form->show();
  185. } else {
  186. $form = new SubscribePeopletagForm($this->out, $this->peopletag);
  187. $form->show();
  188. }
  189. }
  190. Event::handle('EndSubscribePeopletagForm', array($this->out, $this->peopletag));
  191. }
  192. $this->out->elementEnd('li');
  193. }
  194. function showCreator()
  195. {
  196. $attrs = array();
  197. $attrs['href'] = $this->profile->profileurl;
  198. $attrs['class'] = 'h-card p-author nickname p-name';
  199. $attrs['rel'] = 'contact';
  200. $attrs['title'] = $this->profile->getFancyName();
  201. $this->out->elementStart('a', $attrs);
  202. $this->showAvatar($this->profile);
  203. $this->out->text($this->profile->getNickname());
  204. $this->out->elementEnd('a');
  205. }
  206. function showUpdated()
  207. {
  208. if (!empty($this->peopletag->modified)) {
  209. $this->out->element('abbr',
  210. array('title' => common_date_w3dtf($this->peopletag->modified),
  211. 'class' => 'updated'),
  212. common_date_string($this->peopletag->modified));
  213. }
  214. }
  215. function showPrivacy()
  216. {
  217. if ($this->peopletag->private) {
  218. $this->out->elementStart('a',
  219. array('href' => common_local_url('peopletagsbyuser',
  220. array('nickname' => $this->profile->nickname, 'private' => 1))));
  221. // TRANS: Privacy mode text in list list item for private list.
  222. $this->out->element('span', 'privacy_mode', _m('MODE','Private'));
  223. $this->out->elementEnd('a');
  224. }
  225. }
  226. function showTag()
  227. {
  228. $this->out->elementStart('span', 'entry-title tag');
  229. $this->out->element('a',
  230. array('rel' => 'bookmark',
  231. 'href' => $this->url()),
  232. htmlspecialchars($this->peopletag->tag));
  233. $this->out->elementEnd('span');
  234. }
  235. function showActions()
  236. {
  237. $this->out->elementStart('div', 'entity_actions');
  238. $this->out->elementStart('ul');
  239. if (!$this->peopletag->private) {
  240. $this->showSubscribeForm();
  241. }
  242. if (!empty($this->current) && $this->profile->id == $this->current->id) {
  243. $this->showOwnerOptions();
  244. }
  245. $this->out->elementEnd('ul');
  246. $this->out->elementEnd('div');
  247. }
  248. function showDescription()
  249. {
  250. $this->out->element('div', 'e-content description', $this->peopletag->description);
  251. }
  252. }