123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class SubscribeAction extends Action
- {
- var $user;
- var $other;
-
- function prepare($args)
- {
- parent::prepare($args);
-
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
-
-
- $this->clientError(_('This action only accepts POST requests.'));
- }
-
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
-
- $this->clientError(_('There was a problem with your session token.'.
- ' Try again, please.'));
- }
-
- $this->user = common_current_user();
- if (empty($this->user)) {
-
- $this->clientError(_('Not logged in.'));
- }
-
- $other_id = $this->arg('subscribeto');
- $this->other = Profile::getKV('id', $other_id);
- if (empty($this->other)) {
-
- $this->clientError(_('No such profile.'));
- }
- return true;
- }
-
- function handle($args)
- {
-
- $sub = Subscription::start($this->user->getProfile(),
- $this->other);
- if ($this->boolean('ajax')) {
- $this->startHTML('text/xml;charset=utf-8');
- $this->elementStart('head');
-
- $this->element('title', null, _('Subscribed'));
- $this->elementEnd('head');
- $this->elementStart('body');
- if ($sub instanceof Subscription) {
- $form = new UnsubscribeForm($this, $this->other);
- } else {
- $form = new CancelSubscriptionForm($this, $this->other);
- }
- $form->show();
- $this->elementEnd('body');
- $this->endHTML();
- } else {
- $url = common_local_url('subscriptions',
- array('nickname' => $this->user->nickname));
- common_redirect($url, 303);
- }
- }
- }
|