Example #1
0
 /**
  * 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();
     }
 }
Example #2
0
 /**
  * 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();
     }
 }
Example #3
0
 /**
  * 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();
     }
 }
Example #4
0
 /**
  * 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();
     }
 }
Example #5
0
 static function getAnonProfile()
 {
     $token = $_SESSION['anon_token'];
     $anon = base64_decode($token);
     $profile = null;
     if (!empty($anon) && substr($anon, 0, 5) == 'anon-') {
         $parts = explode('-', $anon);
         $id = $parts[1];
         // Do Profile lookup by ID instead of nickname for safety/performance
         $profile = Profile::staticGet('id', $id);
     } else {
         $profile = AnonymousFavePlugin::createAnonProfile();
         // Obfuscate so it's hard to figure out the Profile ID
         $_SESSION['anon_token'] = base64_encode($profile->nickname);
     }
     return $profile;
 }