peopletagsbyuser.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Lists by a user
  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 Personal
  23. * @package StatusNet
  24. * @author Shashi Gowda <connect2shashi@gmail.com>
  25. * @copyright 2008-2011 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. require_once INSTALLDIR . '/lib/profile/peopletaglist.php';
  33. class PeopletagsbyuserAction extends Action
  34. {
  35. var $page = null;
  36. var $tagger = null;
  37. var $tags = null;
  38. function isReadOnly($args)
  39. {
  40. return true;
  41. }
  42. function title()
  43. {
  44. if ($this->page == 1) {
  45. if ($this->isOwner()) {
  46. if ($this->arg('private')) {
  47. // TRANS: Title for lists by a user page for a private tag.
  48. return _('Private lists by you');
  49. } else if ($this->arg('public')) {
  50. // TRANS: Title for lists by a user page for a public tag.
  51. return _('Public lists by you');
  52. }
  53. // TRANS: Title for lists by a user page.
  54. return _('Lists by you');
  55. }
  56. // TRANS: Title for lists by a user page.
  57. // TRANS: %s is a user nickname.
  58. return sprintf(_('Lists by %s'), $this->tagger->nickname);
  59. } else {
  60. // TRANS: Title for lists by a user page.
  61. // TRANS: %1$s is a user nickname, %2$d is a page number.
  62. return sprintf(_('Lists by %1$s, page %2$d'), $this->tagger->nickname, $this->page);
  63. }
  64. }
  65. function prepare(array $args = array())
  66. {
  67. parent::prepare($args);
  68. if ($this->arg('public') && $this->arg('private')) {
  69. $this->args['public'] = $this->args['private'] = false;
  70. }
  71. if (common_config('singleuser', 'enabled')) {
  72. $nickname_arg = User::singleUserNickname();
  73. } else {
  74. $nickname_arg = $this->arg('nickname');
  75. }
  76. $nickname = common_canonical_nickname($nickname_arg);
  77. // Permanent redirect on non-canonical nickname
  78. if ($nickname_arg != $nickname) {
  79. $args = $this->getSelfUrlArgs();
  80. if ($this->arg('page') && $this->arg('page') != 1) {
  81. $args['page'] = $this->arg['page'];
  82. }
  83. common_redirect(common_local_url('peopletagsbyuser', $args), 301);
  84. }
  85. $this->user = User::getKV('nickname', $nickname);
  86. if (!$this->user) {
  87. // TRANS: Client error displayed trying to perform an action related to a non-existing user.
  88. $this->clientError(_('No such user.'), 404);
  89. }
  90. $this->tagger = $this->user->getProfile();
  91. if (!$this->tagger) {
  92. // TRANS: Error message displayed when referring to a user without a profile.
  93. $this->serverError(_('User has no profile.'));
  94. }
  95. $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
  96. $offset = ($this->page-1) * PEOPLETAGS_PER_PAGE;
  97. $limit = PEOPLETAGS_PER_PAGE + 1;
  98. $user = common_current_user();
  99. if ($this->arg('public')) {
  100. $this->tags = $this->tagger->getLists(null, $offset, $limit);
  101. } else if ($this->arg('private')) {
  102. if (empty($user)) {
  103. // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
  104. $this->clientError(_('Not logged in.'), 403);
  105. }
  106. if ($this->isOwner()) {
  107. $this->tags = $this->tagger->getPrivateTags($offset, $limit);
  108. } else {
  109. // TRANS: Client error displayed when trying view another user's private lists.
  110. $this->clientError(_('You cannot view others\' private lists'), 403);
  111. }
  112. } else {
  113. $this->tags = $this->tagger->getLists($this->scoped, $offset, $limit);
  114. }
  115. return true;
  116. }
  117. function handle()
  118. {
  119. parent::handle();
  120. # Post from the tag dropdown; redirect to a GET
  121. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  122. common_redirect(common_local_url('peopletagsbyuser', $this->getSelfUrlArgs()), 303);
  123. }
  124. $this->showPage();
  125. }
  126. function showModeSelector()
  127. {
  128. $this->elementStart('dl', array('id'=>'filter_tags'));
  129. // TRANS: Mode selector label.
  130. $this->element('dt', null, _('Mode'));
  131. $this->elementStart('dd');
  132. $this->elementStart('ul');
  133. $this->elementStart('li', array('id' => 'filter_tags_for',
  134. 'class' => 'child_1'));
  135. $this->element('a',
  136. array('href' =>
  137. common_local_url('peopletagsforuser',
  138. array('nickname' => $this->user->nickname))),
  139. // TRANS: Link text to show lists for user %s.
  140. sprintf(_('Lists for %s'), $this->tagger->nickname));
  141. $this->elementEnd('li');
  142. if ($this->isOwner()) {
  143. $this->elementStart('li', array('id'=>'filter_tags_item'));
  144. $this->elementStart('form', array('name' => 'modeselector',
  145. 'id' => 'form_filter_bymode',
  146. 'action' => common_local_url('peopletagsbyuser',
  147. array('nickname' => $this->tagger->nickname)),
  148. 'method' => 'post'));
  149. $this->elementStart('fieldset');
  150. // TRANS: Fieldset legend.
  151. $this->element('legend', null, _('Select tag to filter'));
  152. $priv = $this->arg('private');
  153. $pub = $this->arg('public');
  154. if (!$priv && !$pub) {
  155. $priv = $pub = true;
  156. }
  157. // TRANS: Checkbox label to show private tags.
  158. $this->checkbox('private', _m('LABEL','Private'), $priv,
  159. // TRANS: Checkbox title.
  160. _('Show private tags.'));
  161. // TRANS: Checkbox label to show public tags.
  162. $this->checkbox('public', _m('LABEL','Public'), $pub,
  163. // TRANS: Checkbox title.
  164. _('Show public tags.'));
  165. $this->hidden('nickname', $this->user->nickname);
  166. // TRANS: Submit button text for tag filter form.
  167. $this->submit('submit', _m('BUTTON','Go'));
  168. $this->elementEnd('fieldset');
  169. $this->elementEnd('form');
  170. $this->elementEnd('li');
  171. }
  172. $this->elementEnd('ul');
  173. $this->elementEnd('dd');
  174. $this->elementEnd('dl');
  175. }
  176. function showAnonymousMessage()
  177. {
  178. $notice =
  179. // TRANS: Message displayed for anonymous users on page that displays lists by a user.
  180. // TRANS: This message contains Markdown links in the form [description](links).
  181. // TRANS: %s is a tagger nickname.
  182. sprintf(_('These are lists created by **%s**. ' .
  183. 'Lists are how you sort similar ' .
  184. 'people on %%%%site.name%%%%, a [micro-blogging]' .
  185. '(http://en.wikipedia.org/wiki/Micro-blogging) service ' .
  186. 'based on the Free Software [StatusNet](http://status.net/) tool. ' .
  187. 'You can easily keep track of what they ' .
  188. 'are doing by subscribing to the list\'s timeline.' ), $this->tagger->nickname);
  189. $this->elementStart('div', array('id' => 'anon_notice'));
  190. $this->raw(common_markup_to_html($notice));
  191. $this->elementEnd('div');
  192. }
  193. function showPageNotice()
  194. {
  195. $this->elementStart('div', 'instructions');
  196. $this->showModeSelector();
  197. $this->elementEnd('div');
  198. }
  199. function showContent()
  200. {
  201. #TODO: controls here.
  202. $pl = new PeopletagList($this->tags, $this);
  203. $cnt = $pl->show();
  204. if ($cnt == 0) {
  205. $this->showEmptyListMessage();
  206. }
  207. $this->pagination($this->page > 1, $cnt > PEOPLETAGS_PER_PAGE,
  208. $this->page, 'peopletagsbyuser', $this->getSelfUrlArgs());
  209. }
  210. function getSelfUrlArgs()
  211. {
  212. $args = array();
  213. if ($this->arg('private')) {
  214. $args['private'] = 1;
  215. } else if ($this->arg('public')) {
  216. $args['public'] = 1;
  217. }
  218. $args['nickname'] = $this->trimmed('nickname');
  219. return $args;
  220. }
  221. function isOwner()
  222. {
  223. $user = common_current_user();
  224. return !empty($user) && $user->id == $this->tagger->id;
  225. }
  226. function showObjectNav()
  227. {
  228. $nav = new PeopletagNav($this, $this->tagger);
  229. $nav->show();
  230. }
  231. function showEmptyListMessage()
  232. {
  233. // TRANS: Message displayed on page that displays lists by a user when there are none.
  234. // TRANS: This message contains Markdown links in the form [description](links).
  235. // TRANS: %s is a tagger nickname.
  236. $message = sprintf(_('%s has not created any [lists](%%%%doc.lists%%%%) yet.'), $this->tagger->nickname);
  237. $this->elementStart('div', 'guide');
  238. $this->raw(common_markup_to_html($message));
  239. $this->elementEnd('div');
  240. }
  241. function showProfileBlock()
  242. {
  243. $block = new AccountProfileBlock($this, $this->tagger);
  244. $block->show();
  245. }
  246. function showSections()
  247. {
  248. #TODO: tags with most subscribers
  249. #TODO: tags with most "members"
  250. }
  251. }