123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
- }
- class ApprovesubAction extends Action
- {
- var $profile = null;
-
- function prepare(array $args = array())
- {
- parent::prepare($args);
- $cur = common_current_user();
- if (empty($cur)) {
-
- $this->clientError(_('Must be logged in.'), 403);
- }
- if ($this->arg('profile_id')) {
- $this->profile = Profile::getKV('id', $this->arg('profile_id'));
- } else {
-
- $this->clientError(_('Must specify a profile.'));
- }
- $this->request = Subscription_queue::pkeyGet(array('subscriber' => $this->profile->id,
- 'subscribed' => $cur->id));
- if (empty($this->request)) {
-
-
- $this->clientError(sprintf(_('%s is not in the moderation queue for your subscriptions.'), $this->profile->nickname), 403);
- }
- $this->approve = (bool)$this->arg('approve');
- $this->cancel = (bool)$this->arg('cancel');
- if (!$this->approve && !$this->cancel) {
-
- $this->clientError(_('Internal error: received neither cancel nor abort.'));
- }
- if ($this->approve && $this->cancel) {
-
- $this->clientError(_('Internal error: received both cancel and abort.'));
- }
- return true;
- }
-
- function handle()
- {
- parent::handle();
- $cur = common_current_user();
- try {
- if ($this->approve) {
- $this->request->complete();
- } elseif ($this->cancel) {
- $this->request->abort();
- }
- } catch (Exception $e) {
- common_log(LOG_ERR, "Exception canceling sub: " . $e->getMessage());
-
-
- $this->serverError(sprintf(_('Could not cancel or approve request for user %1$s to join group %2$s.'),
- $this->profile->nickname, $cur->nickname));
- return;
- }
- if ($this->boolean('ajax')) {
- $this->startHTML('text/xml;charset=utf-8');
- $this->elementStart('head');
-
-
- $this->element('title', null, sprintf(_m('TITLE','%1$s\'s request'),
- $this->profile->nickname));
- $this->elementEnd('head');
- $this->elementStart('body');
- if ($this->approve) {
-
- $this->element('p', 'success', _('Subscription approved.'));
- } elseif ($this->cancel) {
-
- $this->element('p', 'success', _('Subscription canceled.'));
- }
- $this->elementEnd('body');
- $this->endHTML();
- } else {
- common_redirect(common_local_url('subqueue', array('nickname' =>
- $cur->nickname)),
- 303);
- }
- }
- }
|