selftag.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 $argarray misc. arguments
  53. *
  54. * @return boolean true
  55. */
  56. function prepare($argarray)
  57. {
  58. parent::prepare($argarray);
  59. $this->tag = $this->trimmed('tag');
  60. if (!common_valid_profile_tag($this->tag)) {
  61. // TRANS: Client error displayed when trying to list a profile with an invalid list.
  62. // TRANS: %s is the invalid list name.
  63. $this->clientError(sprintf(_('Not a valid list: %s.'),
  64. $this->tag));
  65. return;
  66. }
  67. $this->page = ($this->arg('page')) ? $this->arg('page') : 1;
  68. common_set_returnto($this->selfUrl());
  69. return true;
  70. }
  71. /**
  72. * Handler method
  73. *
  74. * @param array $argarray is ignored since it's now passed in in prepare()
  75. *
  76. * @return boolean is read only action?
  77. */
  78. function handle($argarray)
  79. {
  80. parent::handle($argarray);
  81. $this->showPage();
  82. }
  83. /**
  84. * Whips up a query to get a list of profiles based on the provided
  85. * people tag and page, initalizes a ProfileList widget, and displays
  86. * it to the user.
  87. *
  88. * @return nothing
  89. */
  90. function showContent()
  91. {
  92. $profile = new Profile();
  93. $offset = ($this->page - 1) * PROFILES_PER_PAGE;
  94. $limit = PROFILES_PER_PAGE + 1;
  95. if (common_config('db', 'type') == 'pgsql') {
  96. $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset;
  97. } else {
  98. $lim = ' LIMIT ' . $offset . ', ' . $limit;
  99. }
  100. // XXX: memcached this
  101. $qry = 'SELECT profile.* ' .
  102. 'FROM profile JOIN ( profile_tag, profile_list ) ' .
  103. 'ON profile.id = profile_tag.tagger ' .
  104. 'AND profile_tag.tagger = profile_list.tagger ' .
  105. 'AND profile_list.tag = profile_tag.tag ' .
  106. 'WHERE profile_tag.tagger = profile_tag.tagged ' .
  107. "AND profile_tag.tag = '%s' ";
  108. $user = common_current_user();
  109. if (empty($user)) {
  110. $qry .= 'AND profile_list.private = false ';
  111. } else {
  112. $qry .= 'AND (profile_list.tagger = ' . $user->id .
  113. ' OR profile_list.private = false) ';
  114. }
  115. $qry .= 'ORDER BY profile_tag.modified DESC%s';
  116. $profile->query(sprintf($qry, $this->tag, $lim));
  117. $ptl = new SelfTagProfileList($profile, $this); // pass the ammunition
  118. $cnt = $ptl->show();
  119. $this->pagination($this->page > 1,
  120. $cnt > PROFILES_PER_PAGE,
  121. $this->page,
  122. 'selftag',
  123. array('tag' => $this->tag));
  124. }
  125. /**
  126. * Returns the page title
  127. *
  128. * @return string page title
  129. */
  130. function title()
  131. {
  132. // TRANS: Page title for page showing self tags.
  133. // TRANS: %1$s is a tag, %2$d is a page number.
  134. return sprintf(_('Users self-tagged with %1$s, page %2$d'),
  135. $this->tag, $this->page);
  136. }
  137. }
  138. class SelfTagProfileList extends ProfileList
  139. {
  140. function newListItem($profile)
  141. {
  142. return new SelfTagProfileListItem($profile, $this->action);
  143. }
  144. }
  145. class SelfTagProfileListItem extends ProfileListItem
  146. {
  147. function linkAttributes()
  148. {
  149. $aAttrs = parent::linkAttributes();
  150. if (common_config('nofollow', 'selftag')) {
  151. $aAttrs['rel'] .= ' nofollow';
  152. }
  153. return $aAttrs;
  154. }
  155. function homepageAttributes()
  156. {
  157. $aAttrs = parent::linkAttributes();
  158. if (common_config('nofollow', 'selftag')) {
  159. $aAttrs['rel'] = 'nofollow';
  160. }
  161. return $aAttrs;
  162. }
  163. function showTags()
  164. {
  165. $selftags = new SelfTagsWidget($this->out, $this->profile, $this->profile);
  166. $selftags->show();
  167. $user = common_current_user();
  168. if (!empty($user) && $user->id != $this->profile->id &&
  169. $user->getProfile()->canTag($this->profile)) {
  170. $yourtags = new PeopleTagsWidget($this->out, $user, $this->profile);
  171. $yourtags->show();
  172. }
  173. }
  174. }