peopletagswidget.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Tags for a profile
  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 Action
  23. * @package StatusNet
  24. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  25. * @link http://status.net/
  26. */
  27. if (!defined('GNUSOCIAL')) { exit(1); }
  28. /*
  29. * Show a bunch of peopletags
  30. * provide ajax editing if the current user owns the tags
  31. *
  32. * @category Action
  33. * @pacage StatusNet
  34. * @author Shashi Gowda <connect2shashi@gmail.com>
  35. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  36. */
  37. class PeopletagsWidget extends Widget
  38. {
  39. /*
  40. * the query, current peopletag.
  41. * or an array of strings (tags)
  42. */
  43. var $tag=null;
  44. var $user=null;
  45. var $tagger=null;
  46. var $tagged=null;
  47. function __construct($out, $tagger, $tagged)
  48. {
  49. parent::__construct($out);
  50. $this->user = common_current_user();
  51. $this->tag = Profile_tag::getTags($tagger->id, $tagged->id, $this->user);
  52. $this->tagger = $tagger;
  53. $this->tagged = $tagged;
  54. }
  55. function show()
  56. {
  57. if (Event::handle('StartShowPeopletags', array($this, $this->tagger, $this->tagged))) {
  58. if ($this->tag->N > 0) {
  59. $this->showTags();
  60. }
  61. else {
  62. $this->showEmptyList();
  63. }
  64. Event::handle('EndShowPeopletags', array($this, $this->tagger, $this->tagged));
  65. }
  66. }
  67. function url()
  68. {
  69. return $this->tag->homeUrl();
  70. }
  71. function label()
  72. {
  73. // TRANS: Label in lists widget.
  74. return _m('LABEL','Your lists');
  75. }
  76. function showTags()
  77. {
  78. $this->out->elementStart('dl', 'entity_tags user_profile_tags');
  79. $this->out->element('dt', null, $this->label());
  80. $this->out->elementStart('dd');
  81. $class = 'tags xoxo';
  82. if ($this->isEditable()) {
  83. $class .= ' editable';
  84. }
  85. $tags = array();
  86. $this->out->elementStart('ul', $class);
  87. while ($this->tag->fetch()) {
  88. $mode = $this->tag->private ? 'private' : 'public';
  89. $tags[] = $this->tag->tag;
  90. $this->out->elementStart('li', 'hashptag mode-' . $mode);
  91. // Avoid space by using raw output.
  92. $pt = '<span class="mark_hash">#</span><a rel="tag" href="' .
  93. htmlspecialchars($this->url()) .
  94. '">' . htmlspecialchars($this->tag->tag) . '</a>';
  95. $this->out->raw($pt);
  96. $this->out->elementEnd('li');
  97. }
  98. $this->out->elementEnd('ul');
  99. if ($this->isEditable()) {
  100. $this->showEditTagForm($tags);
  101. }
  102. $this->out->elementEnd('dd');
  103. $this->out->elementEnd('dl');
  104. }
  105. function showEditTagForm($tags=null)
  106. {
  107. $this->out->elementStart('div', 'form_tag_user_wrap');
  108. $this->out->elementStart('form', array('method' => 'post',
  109. 'class' => 'form_tag_user',
  110. 'name' => 'tagprofile',
  111. 'action' => common_local_url('tagprofile', array('id' => $this->tagged->id))));
  112. $this->out->elementStart('fieldset');
  113. // TRANS: Fieldset legend in lists widget.
  114. $this->out->element('legend', null, _m('LEGEND','Edit lists'));
  115. $this->out->hidden('token', common_session_token());
  116. $this->out->hidden('id', $this->tagged->id);
  117. if (!$tags) {
  118. $tags = array();
  119. }
  120. $this->out->input('tags', $this->label(),
  121. ($this->out->arg('tags')) ? $this->out->arg('tags') : implode(' ', $tags));
  122. // TRANS: Button text to save tags for a profile.
  123. $this->out->submit('save', _m('BUTTON','Save'));
  124. $this->out->elementEnd('fieldset');
  125. $this->out->elementEnd('form');
  126. $this->out->elementEnd('div');
  127. }
  128. function showEmptyList()
  129. {
  130. $this->out->elementStart('dl', 'entity_tags user_profile_tags');
  131. $this->out->element('dt', null, $this->label());
  132. $this->out->elementStart('dd');
  133. $class = 'tags';
  134. if ($this->isEditable()) {
  135. $class .= ' editable';
  136. }
  137. $this->out->elementStart('ul', $class);
  138. // TRANS: Empty list message for tags.
  139. $this->out->element('li', null, _('(None)'));
  140. $this->out->elementEnd('ul');
  141. if ($this->isEditable()) {
  142. $this->showEditTagForm();
  143. }
  144. $this->out->elementEnd('dd');
  145. $this->out->elementEnd('dl');
  146. }
  147. function isEditable()
  148. {
  149. return !empty($this->user) && $this->tagger->id == $this->user->id;
  150. }
  151. }