function handleDelete()
 {
     $args = array('profile_tag_id' => $this->list->id, 'profile_id' => $this->auth_user->id);
     $ptag = Profile_tag_subscription::pkeyGet($args);
     if (empty($ptag)) {
         $this->clientError(_('You are not subscribed to this list.'), 400, $this->format);
         return false;
     }
     Profile_tag_subscription::remove($this->list, $this->auth_user);
     if (empty($result)) {
         $this->clientError(_('An error occured.'), 500, $this->format);
         return false;
     }
     switch ($this->format) {
         case 'xml':
             $this->showSingleXmlList($this->list);
             break;
         case 'json':
             $this->showSingleJsonList($this->list);
             break;
         default:
             $this->clientError(_('API method not found.'), 404, $this->format);
             return false;
             break;
     }
     return true;
 }
 function handleDelete()
 {
     $args = array('profile_tag_id' => $this->list->id, 'profile_id' => $this->auth_user->id);
     $ptag = Profile_tag_subscription::pkeyGet($args);
     if (empty($ptag)) {
         // TRANS: Client error displayed when trying to unsubscribe from a non-subscribed list.
         $this->clientError(_('You are not subscribed to this list.'));
     }
     $result = Profile_tag_subscription::remove($this->list, $this->auth_user);
     if (empty($result)) {
         // TRANS: Client error displayed when an unknown error occurs unsubscribing from a list.
         $this->clientError(_('An error occured.'), 500);
     }
     switch ($this->format) {
         case 'xml':
             $this->showSingleXmlList($this->list);
             break;
         case 'json':
             $this->showSingleJsonList($this->list);
             break;
         default:
             // TRANS: Client error displayed when coming across a non-supported API method.
             $this->clientError(_('API method not found.'), 404);
     }
     return true;
 }
 static function remove($peopletag, $profile)
 {
     $sub = Profile_tag_subscription::pkeyGet(array('profile_tag_id' => $peopletag->id, 'profile_id' => $profile->id));
     if (empty($sub)) {
         // silence is golden?
         return true;
     }
     if (Event::handle('StartUnsubscribePeopletag', array($peopletag, $profile))) {
         $result = $sub->delete();
         if (!$result) {
             common_log_db_error($sub, 'DELETE', __FILE__);
             // TRANS: Exception thrown when deleting a list subscription from the database fails.
             throw new Exception(_('Removing list subscription failed.'));
         }
         $peopletag->subscriberCount(true);
         Event::handle('EndUnsubscribePeopletag', array($peopletag, $profile));
         return true;
     }
 }
Beispiel #4
0
 function handle($args)
 {
     parent::handle($args);
     $arr = array('profile_tag_id' => $this->list->id, 'profile_id' => $this->user->id);
     $sub = Profile_tag_subscription::pkeyGet($arr);
     if (empty($sub)) {
         $this->clientError(_('The specified user is not a subscriber of this list.'), 400, $this->format);
     }
     $user = $this->twitterUserArray($this->user->getProfile(), true);
     switch ($this->format) {
         case 'xml':
             $this->showTwitterXmlUser($user, 'user', true);
             break;
         case 'json':
             $this->showSingleJsonUser($user);
             break;
         default:
             $this->clientError(_('API method not found.'), 404, $this->format);
             break;
     }
 }
 function handle($args)
 {
     parent::handle($args);
     $arr = array('profile_tag_id' => $this->list->id, 'profile_id' => $this->target->id);
     $sub = Profile_tag_subscription::pkeyGet($arr);
     if (empty($sub)) {
         // TRANS: Client error displayed when a membership check for a user is nagative.
         $this->clientError(_('The specified user is not a subscriber of this list.'));
     }
     $user = $this->twitterUserArray($this->target, true);
     switch ($this->format) {
         case 'xml':
             $this->showTwitterXmlUser($user, 'user', true);
             break;
         case 'json':
             $this->showSingleJsonUser($user);
             break;
         default:
             $this->clientError(_('API method not found.'), 404, $this->format);
             break;
     }
 }
 function trySave()
 {
     $tag = common_canonical_tag($this->trimmed('tag'));
     $description = $this->trimmed('description');
     $private = $this->boolean('private');
     $delete = $this->arg('delete');
     $confirm = $this->arg('confirm');
     $cancel = $this->arg('cancel');
     if ($delete && $cancel) {
         // TRANS: Form validation error displayed if the form data for deleting a tag was incorrect.
         $this->showForm(_('Delete aborted.'));
         return;
     }
     $set_private = $private && $this->peopletag->private != $private;
     if ($delete && !$confirm) {
         // TRANS: Text in confirmation dialog for deleting a tag.
         $this->showConfirm(_('Deleting this tag will permanantly remove ' . 'all its subscription and membership records. ' . 'Do you still want to continue?'), array('delete' => 1));
         return;
     } else {
         if (common_valid_tag($tag)) {
             // TRANS: Form validation error displayed if a given tag is invalid.
             $this->showForm(_('Invalid tag.'));
             return;
         } else {
             if ($tag != $this->peopletag->tag && $this->tagExists($tag)) {
                 // TRANS: Form validation error displayed if a given tag is already present.
                 // TRANS: %s is the already present tag.
                 $this->showForm(sprintf(_('You already have a tag named %s.'), $tag));
                 return;
             } else {
                 if (Profile_list::descriptionTooLong($description)) {
                     $this->showForm(sprintf(_m('Description is too long (maximum %d character).', 'Description is too long (maximum %d characters).', Profile_list::maxDescription()), Profile_list::maxDescription()));
                     return;
                 } else {
                     if ($set_private && !$confirm && !$cancel) {
                         $fwd = array('tag' => $tag, 'description' => $description, 'private' => (int) $private);
                         // TRANS: Text in confirmation dialog for setting a tag from public to private.
                         $this->showConfirm(_('Setting a public tag as private will ' . 'permanently remove all the existing ' . 'subscriptions to it. Do you still want to continue?'), $fwd);
                         return;
                     }
                 }
             }
         }
     }
     $this->peopletag->query('BEGIN');
     $orig = clone $this->peopletag;
     $this->peopletag->tag = $tag;
     $this->peopletag->description = $description;
     if (!$set_private || $confirm) {
         $this->peopletag->private = $private;
     }
     $result = $this->peopletag->update($orig);
     if (!$result) {
         common_log_db_error($this->group, 'UPDATE', __FILE__);
         // TRANS: Server error displayed when updating a list fails.
         $this->serverError(_('Could not update list.'));
     }
     $this->peopletag->query('COMMIT');
     if ($set_private && $confirm) {
         Profile_tag_subscription::cleanup($this->peopletag);
     }
     if ($delete) {
         // This might take quite a bit of time.
         $this->peopletag->delete();
         // send home.
         common_redirect(common_local_url('all', array('nickname' => $this->tagger->nickname)), 303);
     }
     if ($tag != $orig->tag) {
         common_redirect(common_local_url('editpeopletag', array('tagger' => $this->tagger->nickname, 'tag' => $tag)), 303);
     } else {
         // TRANS: Edit list form success message.
         $this->showForm(_('Options saved.'));
     }
 }
 /**
  * get the cached number of profiles subscribed to this
  * people tag, re-count if the argument is true.
  *
  * @param boolean $recount  whether to ignore cache
  *
  * @return integer count
  */
 function subscriberCount($recount = false)
 {
     $keypart = sprintf('profile_list:subscriber_count:%d', $this->id);
     $count = self::cacheGet($keypart);
     if ($count === false) {
         $sub = new Profile_tag_subscription();
         $sub->profile_tag_id = $this->id;
         $count = (int) $sub->count('distinct profile_id');
         self::cacheSet($keypart, $count);
     }
     return $count;
 }
 /**
  * Handle the request
  *
  * On POST, add the current user to the group
  *
  * @param array $args unused
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $cur = common_current_user();
     Profile_tag_subscription::remove($this->peopletag, $cur);
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Page title for form that allows unsubscribing from a list.
         // TRANS: %1$s is a nickname, %2$s is a list, %3$s is a tagger nickname.
         $this->element('title', null, sprintf(_('%1$s unsubscribed from list %2$s by %3$s'), $cur->nickname, $this->peopletag->tag, $this->tagger->nickname));
         $this->elementEnd('head');
         $this->elementStart('body');
         $lf = new SubscribePeopletagForm($this, $this->peopletag);
         $lf->show();
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         if (common_get_returnto()) {
             common_redirect(common_get_returnto(), 303);
             return true;
         }
         common_redirect(common_local_url('peopletagsbyuser', array('nickname' => $this->tagger->nickname)), 303);
     }
 }
 /**
  * A remote user unsubscribed from our list.
  *
  * @return void
  * @throws Exception through clientError and serverError
  */
 function handleUnsubscribe()
 {
     if ($this->oprofile->isGroup()) {
         // TRANS: Client error displayed when trying to unsubscribe a group from a list.
         $this->clientError(_m('Groups cannot subscribe to lists.'));
     }
     common_log(LOG_INFO, sprintf('Remote profile %s unsubscribing from local peopletag %s', $this->oprofile->getUri(), $this->peopletag->getBestName()));
     try {
         Profile_tag_subscription::remove($this->peopletag->tagger, $this->peopletag->tag, $this->actor->id);
     } catch (Exception $e) {
         // TRANS: Client error displayed when trying to unsubscribe a remote user from a list fails.
         // TRANS: %1$s is a profile URL, %2$s is a list name.
         $this->serverError(sprintf(_m('Could not unsubscribe remote user %1$s from list %2$s.'), $this->oprofile->getUri(), $this->peopletag->getBestName()));
     }
 }
 /**
  * Handle the request
  *
  * On POST, add the current user to the group
  *
  * @param array $args unused
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $cur = common_current_user();
     try {
         Profile_tag_subscription::add($this->peopletag, $cur);
     } catch (Exception $e) {
         // TRANS: Server error displayed subscribing to a list fails.
         // TRANS: %1$s is a user nickname, %2$s is a list, %3$s is the error message (no period).
         $this->serverError(sprintf(_('Could not subscribe user %1$s to list %2$s: %3$s'), $cur->nickname, $this->peopletag->tag), $e->getMessage());
     }
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Title of form to subscribe to a list.
         // TRANS: %1%s is a user nickname, %2$s is a list, %3$s is a tagger nickname.
         $this->element('title', null, sprintf(_('%1$s subscribed to list %2$s by %3$s'), $cur->nickname, $this->peopletag->tag, $this->tagger->nickname));
         $this->elementEnd('head');
         $this->elementStart('body');
         $lf = new UnsubscribePeopletagForm($this, $this->peopletag);
         $lf->show();
         $this->elementEnd('body');
         $this->endHTML();
     } else {
         common_redirect(common_local_url('peopletagsubscribers', array('tagger' => $this->tagger->nickname, 'tag' => $this->peopletag->tag)), 303);
     }
 }
 /**
  * Attempt to finalize subscription.
  * validateFeed must have been run first.
  *
  * Calls showForm on failure or success on success.
  */
 function saveFeed()
 {
     $user = common_current_user();
     $ptag = $this->oprofile->localPeopletag();
     if ($ptag->hasSubscriber($user->id)) {
         // TRANS: OStatus remote group subscription dialog error.
         $this->showForm(_m('Already subscribed!'));
         return;
     }
     try {
         Profile_tag_subscription::add($ptag, $user);
         $this->success();
     } catch (Exception $e) {
         $this->showForm($e->getMessage());
     }
 }
Beispiel #12
0
 /**
  * A remote user unsubscribed from our list.
  */
 function handleUnsubscribe()
 {
     $oprofile = $this->ensureProfile();
     if (!$oprofile) {
         // TRANS: Client error displayed when trying to unsubscribe from non-existing list.
         $this->clientError(_m('Cannot read profile to cancel list subscription.'));
     }
     if ($oprofile->isGroup()) {
         // TRANS: Client error displayed when trying to unsubscribe a group from a list.
         $this->clientError(_m('Groups cannot subscribe to lists.'));
     }
     common_log(LOG_INFO, "Remote profile {$oprofile->uri} unsubscribing from local peopletag " . $this->peopletag->getBestName());
     $profile = $oprofile->localProfile();
     try {
         Profile_tag_subscription::remove($this->peopletag->tagger, $this->peopletag->tag, $profile->id);
     } catch (Exception $e) {
         // TRANS: Client error displayed when trying to unsubscribe a remote user from a list fails.
         // TRANS: %1$s is a profile URL, %2$s is a list name.
         $this->serverError(sprintf(_m('Could not unsubscribe remote user %1$s from list %2$s.'), $oprofile->uri, $this->peopletag->getBestName()));
         return;
     }
 }