ostatuspeopletag.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2009-2010, StatusNet, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * @package OStatusPlugin
  21. * @maintainer Brion Vibber <brion@status.net>
  22. */
  23. if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
  24. require_once INSTALLDIR . '/lib/profile/peopletaglist.php';
  25. /**
  26. * Key UI methods:
  27. *
  28. * showInputForm() - form asking for a remote profile account or URL
  29. * We end up back here on errors
  30. *
  31. * showPreviewForm() - surrounding form for preview-and-confirm
  32. * preview() - display profile for a remote group
  33. *
  34. * success() - redirects to groups page on join
  35. */
  36. class OStatusPeopletagAction extends OStatusSubAction
  37. {
  38. protected $profile_uri; // provided acct: or URI of remote entity
  39. protected $oprofile; // Ostatus_profile of remote entity, if valid
  40. function validateRemoteProfile()
  41. {
  42. if (!$this->oprofile->isPeopletag()) {
  43. // Send us to the user subscription form for conf
  44. $target = common_local_url('RemoteFollowSub', array(), array('profile' => $this->profile_uri));
  45. common_redirect($target, 303);
  46. }
  47. }
  48. /**
  49. * Show the initial form, when we haven't yet been given a valid
  50. * remote profile.
  51. */
  52. function showInputForm()
  53. {
  54. $this->elementStart('form', array('method' => 'post',
  55. 'id' => 'form_ostatus_sub',
  56. 'class' => 'form_settings',
  57. 'action' => $this->selfLink()));
  58. $this->hidden('token', common_session_token());
  59. $this->elementStart('fieldset', array('id' => 'settings_feeds'));
  60. $this->elementStart('ul', 'form_data');
  61. $this->elementStart('li');
  62. $this->input('profile',
  63. // TRANS: Field label.
  64. _m('Subscribe to list'),
  65. $this->profile_uri,
  66. // TRANS: Field title.
  67. _m("Address of the OStatus list, like http://example.net/user/all/tag."));
  68. $this->elementEnd('li');
  69. $this->elementEnd('ul');
  70. // TRANS: Button text to continue joining a remote list.
  71. $this->submit('validate', _m('BUTTON','Continue'));
  72. $this->elementEnd('fieldset');
  73. $this->elementEnd('form');
  74. }
  75. /**
  76. * Show a preview for a remote peopletag's profile
  77. * @return boolean true if we're ok to try joining
  78. */
  79. function preview()
  80. {
  81. $oprofile = $this->oprofile;
  82. $ptag = $oprofile->localPeopletag();
  83. $cur = common_current_user();
  84. if ($ptag->hasSubscriber($cur->id)) {
  85. $this->element('div', array('class' => 'error'),
  86. // TRANS: Error text displayed when trying to subscribe to a list already a subscriber to.
  87. _m('You are already subscribed to this list.'));
  88. $ok = false;
  89. } else {
  90. $ok = true;
  91. }
  92. $this->showEntity($ptag);
  93. return $ok;
  94. }
  95. function showEntity($ptag)
  96. {
  97. $this->elementStart('div', 'peopletag');
  98. $widget = new PeopletagListItem($ptag, common_current_user(), $this);
  99. $widget->showCreator();
  100. $widget->showTag();
  101. $widget->showDescription();
  102. $this->elementEnd('div');
  103. }
  104. /**
  105. * Redirect on successful remote people tag subscription
  106. */
  107. function success()
  108. {
  109. $cur = common_current_user();
  110. $url = common_local_url('peopletagsubscriptions', array('nickname' => $cur->nickname));
  111. common_redirect($url, 303);
  112. }
  113. /**
  114. * Attempt to finalize subscription.
  115. * validateFeed must have been run first.
  116. *
  117. * Calls showForm on failure or success on success.
  118. */
  119. function saveFeed()
  120. {
  121. $user = common_current_user();
  122. $ptag = $this->oprofile->localPeopletag();
  123. if ($ptag->hasSubscriber($user->id)) {
  124. // TRANS: OStatus remote group subscription dialog error.
  125. $this->showForm(_m('Already subscribed!'));
  126. return;
  127. }
  128. try {
  129. Profile_tag_subscription::add($ptag, $user);
  130. $this->success();
  131. } catch (Exception $e) {
  132. $this->showForm($e->getMessage());
  133. }
  134. }
  135. /**
  136. * Title of the page
  137. *
  138. * @return string Title of the page
  139. */
  140. function title()
  141. {
  142. // TRANS: Page title for OStatus remote list subscription form
  143. return _m('Confirm subscription to remote list');
  144. }
  145. /**
  146. * Instructions for use
  147. *
  148. * @return instructions for use
  149. */
  150. function getInstructions()
  151. {
  152. // TRANS: Instructions for OStatus list subscription form.
  153. return _m('You can subscribe to lists from other supported sites. Paste the list\'s URI below:');
  154. }
  155. function selfLink()
  156. {
  157. return common_local_url('ostatuspeopletag');
  158. }
  159. }