123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?php
- if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
- abstract class BaseMirrorAction extends Action
- {
- var $user;
- var $profile;
-
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
- return $this->sharedBoilerplate();
- }
- protected function validateFeedUrl($url)
- {
- if (common_valid_http_url($url)) {
- return $url;
- } else {
-
-
- $this->clientError(sprintf(_m("Invalid feed URL: %s."), $url));
- }
- }
- protected function validateProfile($id)
- {
- $id = intval($id);
- $profile = Profile::getKV('id', $id);
- if ($profile && $profile->id != $this->user->id) {
- return $profile;
- }
-
-
- $this->clientError(_m('Invalid profile for mirroring.'));
- }
-
- protected function profileForFeed($url)
- {
- try {
-
- $oprofile = Ostatus_profile::ensureProfileURL($url);
- } catch (Exception $e) {
-
- $oprofile = Ostatus_profile::ensureFeedURL($url);
- }
- if ($oprofile->isGroup()) {
-
- $this->clientError(_m('Cannot mirror a GNU social group at this time.'));
- }
- $this->oprofile = $oprofile;
- return $oprofile->localProfile();
- }
-
- function sharedBoilerplate()
- {
-
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
-
- $this->clientError(_m('This action only accepts POST requests.'));
- }
-
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
-
- $this->clientError(_m('There was a problem with your session token.'.
- ' Try again, please.'));
- }
-
- $this->user = common_current_user();
- if (empty($this->user)) {
-
- $this->clientError(_m('Not logged in.'));
- }
- return true;
- }
-
- protected function handle()
- {
-
- $this->saveMirror();
- if ($this->boolean('ajax')) {
- $this->startHTML('text/xml;charset=utf-8');
- $this->elementStart('head');
-
- $this->element('title', null, _m('Subscribed'));
- $this->elementEnd('head');
- $this->elementStart('body');
- $unsubscribe = new EditMirrorForm($this, $this->profile);
- $unsubscribe->show();
- $this->elementEnd('body');
- $this->endHTML();
- } else {
- $url = common_local_url('mirrorsettings');
- common_redirect($url, 303);
- }
- }
- abstract protected function saveMirror();
- }
|