/** * Class handler. * * @param array $args query arguments * * @return void */ function handle($args) { parent::handle($args); $profile = AnonymousFavePlugin::getAnonProfile(); if (empty($profile) || $_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_m('Could not disfavor notice! Please make sure your browser has cookies enabled.')); } $id = $this->trimmed('notice'); $notice = Notice::getKV($id); $token = $this->checkSessionToken(); $fave = new Fave(); $fave->user_id = $profile->id; $fave->notice_id = $notice->id; if (!$fave->find(true)) { throw new NoResultException($fave); } $result = $fave->delete(); if (!$result) { common_log_db_error($fave, 'DELETE', __FILE__); // TRANS: Server error. $this->serverError(_m('Could not delete favorite.')); } Fave::blowCacheForProfileId($profile->id); if ($this->boolean('ajax')) { $this->startHTML('text/xml;charset=utf-8'); $this->elementStart('head'); // TRANS: Title. $this->element('title', null, _m('Add to favorites')); $this->elementEnd('head'); $this->elementStart('body'); $favor = new AnonFavorForm($this, $notice); $favor->show(); $this->elementEnd('body'); $this->endHTML(); } else { $this->returnToPrevious(); } }
function onStartShowFaveForm($item) { if (!common_logged_in() && $this->hasAnonFaving($item)) { $profile = AnonymousFavePlugin::getAnonProfile(); if (!empty($profile)) { if ($profile->hasFave($item->notice)) { $disfavor = new AnonDisFavorForm($item->out, $item->notice); $disfavor->show(); } else { $favor = new AnonFavorForm($item->out, $item->notice); $favor->show(); } } } return true; }
/** * Class handler. * * @param array $args query arguments * * @return void */ function handle($args) { parent::handle($args); $profile = AnonymousFavePlugin::getAnonProfile(); if (empty($profile) || $_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_m('Could not disfavor notice! Please make sure your browser has cookies enabled.')); return; } $id = $this->trimmed('notice'); $notice = Notice::staticGet($id); $token = $this->trimmed('token-' . $notice->id); if (!$token || $token != common_session_token()) { // TRANS: Client error. $this->clientError(_m('There was a problem with your session token. Try again, please.')); return; } $fave = new Fave(); $fave->user_id = $profile->id; $fave->notice_id = $notice->id; if (!$fave->find(true)) { // TRANS: Client error. $this->clientError(_m('This notice is not a favorite!')); return; } $result = $fave->delete(); if (!$result) { common_log_db_error($fave, 'DELETE', __FILE__); // TRANS: Server error. $this->serverError(_m('Could not delete favorite.')); return; } $profile->blowFavesCache(); if ($this->boolean('ajax')) { $this->startHTML('text/xml;charset=utf-8'); $this->elementStart('head'); // TRANS: Title. $this->element('title', null, _m('Add to favorites')); $this->elementEnd('head'); $this->elementStart('body'); $favor = new AnonFavorForm($this, $notice); $favor->show(); $this->elementEnd('body'); $this->elementEnd('html'); } else { $this->returnToPrevious(); } }