peopletags.php 5.7 KB

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