selftag.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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->_join .= "\n" . <<<'END'
  84. INNER JOIN profile_list ON profile.id = profile_list.tagger
  85. LEFT JOIN profile_role ON profile.id = profile_role.profile_id
  86. END;
  87. $profile->whereAdd(sprintf(
  88. "profile_list.tag = '%s'",
  89. $profile->escape($this->tag)
  90. ));
  91. $profile->whereAdd("COALESCE(profile_role.role, '') <> 'silenced'");
  92. $user = common_current_user();
  93. if (!empty($user)) {
  94. $profile->whereAdd(sprintf(
  95. 'profile_list.tagger = %d OR profile_list.private IS NOT TRUE',
  96. $user->getID()
  97. ));
  98. } else {
  99. $profile->whereAdd('profile_list.private IS NOT TRUE');
  100. }
  101. $profile->orderBy('profile_list.modified DESC');
  102. $offset = ($this->page - 1) * PROFILES_PER_PAGE;
  103. $limit = PROFILES_PER_PAGE + 1;
  104. $profile->limit($offset, $limit);
  105. $profile->find();
  106. $ptl = new SelfTagProfileList($profile, $this); // pass the ammunition
  107. $cnt = $ptl->show();
  108. $this->pagination(
  109. $this->page > 1,
  110. $cnt > PROFILES_PER_PAGE,
  111. $this->page,
  112. 'selftag',
  113. ['tag' => $this->tag]
  114. );
  115. }
  116. /**
  117. * Returns the page title
  118. *
  119. * @return string page title
  120. */
  121. public function title()
  122. {
  123. // TRANS: Page title for page showing self tags.
  124. // TRANS: %1$s is a tag, %2$d is a page number.
  125. return sprintf(
  126. _('Users self-tagged with %1$s, page %2$d'),
  127. $this->tag,
  128. $this->page
  129. );
  130. }
  131. }
  132. class SelfTagProfileList extends ProfileList
  133. {
  134. public function newListItem(Profile $target)
  135. {
  136. return new SelfTagProfileListItem($target, $this->action);
  137. }
  138. }
  139. class SelfTagProfileListItem extends ProfileListItem
  140. {
  141. public function linkAttributes()
  142. {
  143. $aAttrs = parent::linkAttributes();
  144. if (common_config('nofollow', 'selftag')) {
  145. $aAttrs['rel'] .= ' nofollow';
  146. }
  147. return $aAttrs;
  148. }
  149. public function homepageAttributes()
  150. {
  151. $aAttrs = parent::linkAttributes();
  152. if (common_config('nofollow', 'selftag')) {
  153. $aAttrs['rel'] = 'nofollow';
  154. }
  155. return $aAttrs;
  156. }
  157. public function showTags()
  158. {
  159. $selftags = new SelfTagsWidget($this->out, $this->profile, $this->profile);
  160. $selftags->show();
  161. $user = common_current_user();
  162. if (!empty($user) && $user->id != $this->profile->getID() &&
  163. $user->getProfile()->canTag($this->profile)) {
  164. $yourtags = new PeopleTagsWidget($this->out, $user, $this->profile);
  165. $yourtags->show();
  166. }
  167. }
  168. }