ostatusgroup.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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')) {
  24. exit(1);
  25. }
  26. /**
  27. * Key UI methods:
  28. *
  29. * showInputForm() - form asking for a remote profile account or URL
  30. * We end up back here on errors
  31. *
  32. * showPreviewForm() - surrounding form for preview-and-confirm
  33. * preview() - display profile for a remote group
  34. *
  35. * success() - redirects to groups page on join
  36. */
  37. class OStatusGroupAction extends OStatusSubAction
  38. {
  39. protected $profile_uri; // provided acct: or URI of remote entity
  40. protected $oprofile; // Ostatus_profile of remote entity, if valid
  41. function validateRemoteProfile()
  42. {
  43. if (!$this->oprofile->isGroup()) {
  44. // Send us to the user subscription form for conf
  45. $target = common_local_url('ostatussub', array(), array('profile' => $this->profile_uri));
  46. common_redirect($target, 303);
  47. }
  48. }
  49. /**
  50. * Show the initial form, when we haven't yet been given a valid
  51. * remote profile.
  52. */
  53. function showInputForm()
  54. {
  55. $this->elementStart('form', array('method' => 'post',
  56. 'id' => 'form_ostatus_sub',
  57. 'class' => 'form_settings',
  58. 'action' => $this->selfLink()));
  59. $this->hidden('token', common_session_token());
  60. $this->elementStart('fieldset', array('id' => 'settings_feeds'));
  61. $this->elementStart('ul', 'form_data');
  62. $this->elementStart('li');
  63. $this->input('profile',
  64. // TRANS: Field label.
  65. _m('Join group'),
  66. $this->profile_uri,
  67. // TRANS: Tooltip for field label "Join group". Do not translate the "example.net"
  68. // TRANS: domain name in the URL, as it is an official standard domain name for examples.
  69. _m("OStatus group's address, like http://example.net/group/nickname."));
  70. $this->elementEnd('li');
  71. $this->elementEnd('ul');
  72. // TRANS: Button text.
  73. $this->submit('validate', _m('BUTTON','Continue'));
  74. $this->elementEnd('fieldset');
  75. $this->elementEnd('form');
  76. }
  77. /**
  78. * Show a preview for a remote group's profile
  79. * @return boolean true if we're ok to try joining
  80. */
  81. function preview()
  82. {
  83. $group = $this->oprofile->localGroup();
  84. if ($this->scoped->isMember($group)) {
  85. $this->element('div', array('class' => 'error'),
  86. // TRANS: Error text displayed when trying to join a remote group the user is already a member of.
  87. _m('You are already a member of this group.'));
  88. $ok = false;
  89. } else {
  90. $ok = true;
  91. }
  92. $this->showEntity($group,
  93. $group->homeUrl(),
  94. $group->homepage_logo,
  95. $group->description);
  96. return $ok;
  97. }
  98. /**
  99. * Redirect on successful remote group join
  100. */
  101. function success()
  102. {
  103. $url = common_local_url('usergroups', array('nickname' => $this->scoped->getNickname()));
  104. common_redirect($url, 303);
  105. }
  106. /**
  107. * Attempt to finalize subscription.
  108. * validateFeed must have been run first.
  109. *
  110. * Calls showForm on failure or success on success.
  111. */
  112. function saveFeed()
  113. {
  114. $group = $this->oprofile->localGroup();
  115. if ($this->scoped->isMember($group)) {
  116. // TRANS: OStatus remote group subscription dialog error.
  117. $this->showForm(_m('Already a member!'));
  118. return;
  119. }
  120. try {
  121. $this->scoped->joinGroup($group);
  122. } catch (Exception $e) {
  123. common_log(LOG_ERR, "Exception on remote group join: " . $e->getMessage());
  124. common_log(LOG_ERR, $e->getTraceAsString());
  125. // TRANS: OStatus remote group subscription dialog error.
  126. $this->showForm(_m('Remote group join failed!'));
  127. return;
  128. }
  129. $this->success();
  130. }
  131. /**
  132. * Title of the page
  133. *
  134. * @return string Title of the page
  135. */
  136. function title()
  137. {
  138. // TRANS: Page title for OStatus remote group join form
  139. return _m('Confirm joining remote group');
  140. }
  141. /**
  142. * Instructions for use
  143. *
  144. * @return instructions for use
  145. */
  146. function getInstructions()
  147. {
  148. // TRANS: Form instructions.
  149. return _m('You can subscribe to groups from other supported sites. Paste the group\'s profile URI below:');
  150. }
  151. function selfLink()
  152. {
  153. return common_local_url('ostatusgroup');
  154. }
  155. }