selftag.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Action for showing profiles self-tagged with a given tag
  18. *
  19. * @category Action
  20. * @package GNUsocial
  21. * @author Evan Prodromou <evan@status.net>
  22. * @author Zach Copley <zach@status.net>
  23. * @copyright 2009 StatusNet, Inc.
  24. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  25. */
  26. defined('GNUSOCIAL') || die();
  27. /**
  28. * This class outputs a paginated list of profiles self-tagged with a given tag
  29. *
  30. * @category Output
  31. * @copyright 2009 StatusNet, Inc.
  32. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  33. *
  34. * @see Action
  35. */
  36. class SelftagAction extends Action
  37. {
  38. public $tag = null;
  39. public $page = null;
  40. /**
  41. * For initializing members of the class.
  42. *
  43. * @param array $args misc. arguments
  44. *
  45. * @return boolean true
  46. * @throws ClientException
  47. */
  48. public function prepare(array $args = [])
  49. {
  50. parent::prepare($args);
  51. $this->tag = $this->trimmed('tag');
  52. if (!common_valid_profile_tag($this->tag)) {
  53. // TRANS: Client error displayed when trying to list a profile with an invalid list.
  54. // TRANS: %s is the invalid list name.
  55. $this->clientError(sprintf(
  56. _('Not a valid list: %s.'),
  57. $this->tag
  58. ));
  59. return null;
  60. }
  61. $this->page = ($this->arg('page')) ? $this->arg('page') : 1;
  62. common_set_returnto($this->selfUrl());
  63. return true;
  64. }
  65. /**
  66. * Handler method
  67. *
  68. * @return void is read only action?
  69. */
  70. public function handle()
  71. {
  72. parent::handle();
  73. $this->showPage();
  74. }
  75. /**
  76. * Whips up a query to get a list of profiles based on the provided
  77. * people tag and page, initalizes a ProfileList widget, and displays
  78. * it to the user.
  79. */
  80. public function showContent()
  81. {
  82. $profile = new Profile();
  83. $profile->joinAdd(['id', 'profile_list:tagger']);
  84. $profile->joinAdd(['id', 'profile_role:profile_id'], 'LEFT');
  85. $profile->whereAdd(sprintf(
  86. "profile_list.tag = '%s'",
  87. $profile->escape($this->tag)
  88. ));
  89. $profile->whereAdd("COALESCE(profile_role.role, '') <> 'silenced'");
  90. $user = common_current_user();
  91. if (!empty($user)) {
  92. $profile->whereAdd(sprintf(
  93. 'profile_list.tagger = %d OR profile_list.private IS NOT TRUE',
  94. $user->getID()
  95. ));
  96. } else {
  97. $profile->whereAdd('profile_list.private IS NOT TRUE');
  98. }
  99. $profile->orderBy('profile_list.modified DESC, profile_list.id DESC');
  100. $offset = ($this->page - 1) * PROFILES_PER_PAGE;
  101. $limit = PROFILES_PER_PAGE + 1;
  102. $profile->limit($offset, $limit);
  103. $profile->find();
  104. $ptl = new SelfTagProfileList($profile, $this); // pass the ammunition
  105. $cnt = $ptl->show();
  106. $this->pagination(
  107. $this->page > 1,
  108. $cnt > PROFILES_PER_PAGE,
  109. $this->page,
  110. 'selftag',
  111. ['tag' => $this->tag]
  112. );
  113. }
  114. /**
  115. * Returns the page title
  116. *
  117. * @return string page title
  118. */
  119. public function title()
  120. {
  121. // TRANS: Page title for page showing self tags.
  122. // TRANS: %1$s is a tag, %2$d is a page number.
  123. return sprintf(
  124. _('Users self-tagged with %1$s, page %2$d'),
  125. $this->tag,
  126. $this->page
  127. );
  128. }
  129. }
  130. class SelfTagProfileList extends ProfileList
  131. {
  132. public function newListItem(Profile $target)
  133. {
  134. return new SelfTagProfileListItem($target, $this->action);
  135. }
  136. }
  137. class SelfTagProfileListItem extends ProfileListItem
  138. {
  139. public function linkAttributes()
  140. {
  141. $aAttrs = parent::linkAttributes();
  142. if (common_config('nofollow', 'selftag')) {
  143. $aAttrs['rel'] .= ' nofollow';
  144. }
  145. return $aAttrs;
  146. }
  147. public function homepageAttributes()
  148. {
  149. $aAttrs = parent::linkAttributes();
  150. if (common_config('nofollow', 'selftag')) {
  151. $aAttrs['rel'] = 'nofollow';
  152. }
  153. return $aAttrs;
  154. }
  155. public function showTags()
  156. {
  157. $selftags = new SelfTagsWidget($this->out, $this->profile, $this->profile);
  158. $selftags->show();
  159. $user = common_current_user();
  160. if (!empty($user) && $user->id != $this->profile->getID() &&
  161. $user->getProfile()->canTag($this->profile)) {
  162. $yourtags = new PeopleTagsWidget($this->out, $user, $this->profile);
  163. $yourtags->show();
  164. }
  165. }
  166. }