X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fcancelsubscription.php;h=35e775ab1ddfb2ebb1e322a5011e3e4c3d8a2b3c;hb=e8d1bb25469fe1ef0cbcb32c3022010997aca4b0;hp=367fbfa1386542f29959432616ceb682db684266;hpb=e862dcdb8a9cfc21cf00513d76f40d20dd3b1b7a;p=quix0rs-gnu-social.git diff --git a/actions/cancelsubscription.php b/actions/cancelsubscription.php index 367fbfa138..35e775ab1d 100644 --- a/actions/cancelsubscription.php +++ b/actions/cancelsubscription.php @@ -2,7 +2,7 @@ /** * StatusNet, the distributed open-source microblogging tool * - * Leave a group + * Cancel the subscription of a profile * * PHP version 5 * @@ -27,92 +27,64 @@ * @link http://status.net/ */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** - * Leave a group - * - * This is the action for leaving a group. It works more or less like the subscribe action - * for users. + * Cancel the subscription of a profile * - * @category Group + * @category Subscription * @package StatusNet * @author Evan Prodromou + * @author Mikael Nordfeldth * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ -class CancelsubscriptionAction extends Action +class CancelsubscriptionAction extends FormAction { + protected $needPost = true; - function handle($args) + protected function prepare(array $args=array()) { - parent::handle($args); - if ($this->boolean('ajax')) { - StatusNet::setApi(true); - } - if (!common_logged_in()) { - $this->clientError(_('Not logged in.')); - return; - } - - $user = common_current_user(); - - if ($_SERVER['REQUEST_METHOD'] != 'POST') { - common_redirect(common_local_url('subscriptions', - array('nickname' => $user->nickname))); - return; - } - - /* Use a session token for CSRF protection. */ - - $token = $this->trimmed('token'); + parent::prepare($args); - if (!$token || $token != common_session_token()) { - $this->clientError(_('There was a problem with your session token. ' . - 'Try again, please.')); - return; + $profile_id = $this->int('unsubscribeto'); + $this->target = Profile::getKV('id', $profile_id); + if (!$this->target instanceof Profile) { + throw new NoProfileException($profile_id); } - $other_id = $this->arg('unsubscribeto'); - - if (!$other_id) { - $this->clientError(_('No profile ID in request.')); - return; - } - - $other = Profile::staticGet('id', $other_id); - - if (!$other) { - $this->clientError(_('No profile with that ID.')); - return; - } - - $this->request = Subscription_queue::pkeyGet(array('subscriber' => $user->id, - 'subscribed' => $other->id)); + return true; + } - if (empty($this->request)) { - // TRANS: Client error displayed when trying to approve a non-existing group join request. - // TRANS: %s is a user nickname. - $this->clientError(sprintf(_('%s is not in the moderation queue for this group.'), $this->profile->nickname), 403); + protected function handlePost() + { + parent::handlePost(); + + try { + $request = Subscription_queue::pkeyGet(array('subscriber' => $this->scoped->id, + 'subscribed' => $this->target->id)); + if ($request instanceof Subscription_queue) { + $request->abort(); + } + } catch (AlreadyFulfilledException $e) { + common_debug('Tried to cancel a non-existing pending subscription'); } - $this->request->abort(); - - if ($this->boolean('ajax')) { + if (StatusNet::isAjax()) { $this->startHTML('text/xml;charset=utf-8'); $this->elementStart('head'); - $this->element('title', null, _('Unsubscribed')); + // TRANS: Title after unsubscribing from a group. + $this->element('title', null, _m('TITLE','Unsubscribed')); $this->elementEnd('head'); $this->elementStart('body'); - $subscribe = new SubscribeForm($this, $other); + $subscribe = new SubscribeForm($this, $this->target); $subscribe->show(); $this->elementEnd('body'); - $this->elementEnd('html'); + $this->endHTML(); + exit(); } else { common_redirect(common_local_url('subscriptions', - array('nickname' => $user->nickname)), + array('nickname' => $this->scoped->nickname)), 303); } }