ostatustag.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 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 James Walker <james@status.net>
  22. */
  23. if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
  24. class OStatusTagAction extends OStatusInitAction
  25. {
  26. var $nickname;
  27. var $profile;
  28. var $err;
  29. function prepare(array $args = array())
  30. {
  31. parent::prepare($args);
  32. if (common_logged_in()) {
  33. // TRANS: Client error displayed when trying to list a local object as if it is remote.
  34. $this->clientError(_m('You can use the local list functionality!'));
  35. }
  36. $this->nickname = $this->trimmed('nickname');
  37. // Webfinger or profile URL of the remote user
  38. $this->profile = $this->trimmed('profile');
  39. return true;
  40. }
  41. function showContent()
  42. {
  43. // TRANS: Header for listing a remote object. %s is a remote object's name.
  44. $header = sprintf(_m('List %s'), $this->nickname);
  45. // TRANS: Button text to list a remote object.
  46. $submit = _m('BUTTON','Go');
  47. $this->elementStart('form', array('id' => 'form_ostatus_connect',
  48. 'method' => 'post',
  49. 'class' => 'form_settings',
  50. 'action' => common_local_url('ostatustag')));
  51. $this->elementStart('fieldset');
  52. $this->element('legend', null, $header);
  53. $this->hidden('token', common_session_token());
  54. $this->elementStart('ul', 'form_data');
  55. $this->elementStart('li', array('id' => 'ostatus_nickname'));
  56. // TRANS: Field label.
  57. $this->input('nickname', _m('User nickname'), $this->nickname,
  58. // TRANS: Field title.
  59. _m('Nickname of the user you want to list.'));
  60. $this->elementEnd('li');
  61. $this->elementStart('li', array('id' => 'ostatus_profile'));
  62. // TRANS: Field label.
  63. $this->input('profile', _m('Profile Account'), $this->profile,
  64. // TRANS: Field title.
  65. _m('Your account id (for example user@example.com).'));
  66. $this->elementEnd('li');
  67. $this->elementEnd('ul');
  68. $this->submit('submit', $submit);
  69. $this->elementEnd('fieldset');
  70. $this->elementEnd('form');
  71. }
  72. function connectWebfinger($acct)
  73. {
  74. $target_profile = $this->targetProfile();
  75. $disco = new Discovery;
  76. $xrd = $disco->lookup($acct);
  77. $link = $xrd->get('http://ostatus.org/schema/1.0/tag');
  78. if (!is_null($link)) {
  79. // We found a URL - let's redirect!
  80. if (!empty($link->template)) {
  81. $url = Discovery::applyTemplate($link->template, $target_profile);
  82. } else {
  83. $url = $link->href;
  84. }
  85. common_log(LOG_INFO, "Sending remote subscriber $acct to $url");
  86. common_redirect($url, 303);
  87. }
  88. // TRANS: Client error displayed when remote profile address could not be confirmed.
  89. $this->clientError(_m('Could not confirm remote profile address.'));
  90. }
  91. function connectProfile($subscriber_profile)
  92. {
  93. $target_profile = $this->targetProfile();
  94. // @fixme hack hack! We should look up the remote sub URL from XRDS
  95. $suburl = preg_replace('!^(.*)/(.*?)$!', '$1/main/tagprofile', $subscriber_profile);
  96. $suburl .= '?uri=' . urlencode($target_profile);
  97. common_log(LOG_INFO, "Sending remote subscriber $subscriber_profile to $suburl");
  98. common_redirect($suburl, 303);
  99. }
  100. function title()
  101. {
  102. // TRANS: Title for an OStatus list.
  103. return _m('OStatus list');
  104. }
  105. }