selftag.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Action for showing profiles self-tagged with a given tag
  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. * @author Evan Prodromou <evan@status.net>
  25. * @author Zach Copley <zach@status.net>
  26. * @copyright 2009 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('STATUSNET') && !defined('LACONICA')) {
  31. exit(1);
  32. }
  33. /**
  34. * This class outputs a paginated list of profiles self-tagged with a given tag
  35. *
  36. * @category Output
  37. * @package StatusNet
  38. * @author Evan Prodromou <evan@status.net>
  39. * @author Zach Copley <zach@status.net>
  40. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  41. * @link http://status.net/
  42. *
  43. * @see Action
  44. */
  45. class SelftagAction extends Action
  46. {
  47. var $tag = null;
  48. var $page = null;
  49. /**
  50. * For initializing members of the class.
  51. *
  52. * @param array $args misc. arguments
  53. *
  54. * @return boolean true
  55. * @throws ClientException
  56. */
  57. function prepare(array $args = [])
  58. {
  59. parent::prepare($args);
  60. $this->tag = $this->trimmed('tag');
  61. if (!common_valid_profile_tag($this->tag)) {
  62. // TRANS: Client error displayed when trying to list a profile with an invalid list.
  63. // TRANS: %s is the invalid list name.
  64. $this->clientError(sprintf(_('Not a valid list: %s.'),
  65. $this->tag));
  66. return null;
  67. }
  68. $this->page = ($this->arg('page')) ? $this->arg('page') : 1;
  69. common_set_returnto($this->selfUrl());
  70. return true;
  71. }
  72. /**
  73. * Handler method
  74. *
  75. * @return void is read only action?
  76. */
  77. function handle()
  78. {
  79. parent::handle();
  80. $this->showPage();
  81. }
  82. /**
  83. * Whips up a query to get a list of profiles based on the provided
  84. * people tag and page, initalizes a ProfileList widget, and displays
  85. * it to the user.
  86. */
  87. function showContent()
  88. {
  89. $profile = new Profile();
  90. $offset = ($this->page - 1) * PROFILES_PER_PAGE;
  91. $limit = PROFILES_PER_PAGE + 1;
  92. if (common_config('db', 'type') == 'pgsql') {
  93. $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset;
  94. } else {
  95. $lim = ' LIMIT ' . $offset . ', ' . $limit;
  96. }
  97. // XXX: memcached this
  98. $qry = 'SELECT profile.* ' .
  99. 'FROM profile JOIN ( profile_tag, profile_list ) ' .
  100. 'ON profile.id = profile_tag.tagger ' .
  101. 'AND profile_tag.tagger = profile_list.tagger ' .
  102. 'AND profile_list.tag = profile_tag.tag ' .
  103. 'WHERE profile_tag.tagger = profile_tag.tagged ' .
  104. "AND profile_tag.tag = '%s' ";
  105. $user = common_current_user();
  106. if (empty($user)) {
  107. $qry .= 'AND profile_list.private = false ';
  108. } else {
  109. $qry .= 'AND (profile_list.tagger = ' . $user->id .
  110. ' OR profile_list.private = false) ';
  111. }
  112. $qry .= 'ORDER BY profile_tag.modified DESC%s';
  113. $profile->query(sprintf($qry, $this->tag, $lim));
  114. $ptl = new SelfTagProfileList($profile, $this); // pass the ammunition
  115. $cnt = $ptl->show();
  116. $this->pagination($this->page > 1,
  117. $cnt > PROFILES_PER_PAGE,
  118. $this->page,
  119. 'selftag',
  120. array('tag' => $this->tag));
  121. }
  122. /**
  123. * Returns the page title
  124. *
  125. * @return string page title
  126. */
  127. function title()
  128. {
  129. // TRANS: Page title for page showing self tags.
  130. // TRANS: %1$s is a tag, %2$d is a page number.
  131. return sprintf(_('Users self-tagged with %1$s, page %2$d'),
  132. $this->tag, $this->page);
  133. }
  134. }
  135. class SelfTagProfileList extends ProfileList
  136. {
  137. function newListItem(Profile $target)
  138. {
  139. return new SelfTagProfileListItem($target, $this->action);
  140. }
  141. }
  142. class SelfTagProfileListItem extends ProfileListItem
  143. {
  144. function linkAttributes()
  145. {
  146. $aAttrs = parent::linkAttributes();
  147. if (common_config('nofollow', 'selftag')) {
  148. $aAttrs['rel'] .= ' nofollow';
  149. }
  150. return $aAttrs;
  151. }
  152. function homepageAttributes()
  153. {
  154. $aAttrs = parent::linkAttributes();
  155. if (common_config('nofollow', 'selftag')) {
  156. $aAttrs['rel'] = 'nofollow';
  157. }
  158. return $aAttrs;
  159. }
  160. function showTags()
  161. {
  162. $selftags = new SelfTagsWidget($this->out, $this->profile, $this->profile);
  163. $selftags->show();
  164. $user = common_current_user();
  165. if (!empty($user) && $user->id != $this->profile->getID() &&
  166. $user->getProfile()->canTag($this->profile)) {
  167. $yourtags = new PeopleTagsWidget($this->out, $user, $this->profile);
  168. $yourtags->show();
  169. }
  170. }
  171. }