/** * 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') { // TRANS: Client error. $this->clientError(_m('Could not favor notice! Please make sure your browser has cookies enabled.')); } $id = $this->trimmed('notice'); $notice = Notice::getKV($id); $token = $this->checkSessionToken(); // Throws exception $stored = Fave::addNew($profile, $notice); if ($this->boolean('ajax')) { $this->startHTML('text/xml;charset=utf-8'); $this->elementStart('head'); // TRANS: Title. $this->element('title', null, _m('Disfavor favorite')); $this->elementEnd('head'); $this->elementStart('body'); $disfavor = new AnonDisFavorForm($this, $notice); $disfavor->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') { // TRANS: Client error. $this->clientError(_m('Could not favor 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 (empty($token) || $token != common_session_token()) { // TRANS: Client error. $this->clientError(_m('There was a problem with your session token. Try again, please.')); return; } if ($profile->hasFave($notice)) { // TRANS: Client error. $this->clientError(_m('This notice is already a favorite!')); return; } $fave = Fave::addNew($profile, $notice); if (!$fave) { // TRANS: Server error. $this->serverError(_m('Could not create 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('Disfavor favorite')); $this->elementEnd('head'); $this->elementStart('body'); $disfavor = new AnonDisFavorForm($this, $notice); $disfavor->show(); $this->elementEnd('body'); $this->elementEnd('html'); } else { $this->returnToPrevious(); } }