示例#1
0
文件: favor.php 项目: Br3nda/laconica
 /**
  * Class handler.
  * 
  * @param array $args query arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if (!common_logged_in()) {
         $this->clientError(_('Not logged in.'));
         return;
     }
     $user = common_current_user();
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)));
         return;
     }
     $id = $this->trimmed('notice');
     $notice = Notice::staticGet($id);
     $token = $this->trimmed('token-' . $notice->id);
     if (!$token || $token != common_session_token()) {
         $this->clientError(_("There was a problem with your session token. Try again, please."));
         return;
     }
     if ($user->hasFave($notice)) {
         $this->clientError(_('This notice is already a favorite!'));
         return;
     }
     $fave = Fave::addNew($user, $notice);
     if (!$fave) {
         $this->serverError(_('Could not create favorite.'));
         return;
     }
     $this->notify($notice, $user);
     $user->blowFavesCache();
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         $this->element('title', null, _('Disfavor favorite'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $disfavor = new DisFavorForm($this, $notice);
         $disfavor->show();
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)));
     }
 }
 /**
  * Constructor
  *
  * @param HTMLOutputter $out    output channel
  * @param Notice        $notice notice to disfavor
  */
 function __construct($out = null, $notice = null)
 {
     parent::__construct($out, $notice);
 }
示例#3
0
 /**
  * Class handler.
  *
  * @param array $args query arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if (!common_logged_in()) {
         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
         $this->clientError(_('Not logged in.'));
         return;
     }
     $user = common_current_user();
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)));
         return;
     }
     $id = $this->trimmed('notice');
     $notice = Notice::staticGet($id);
     $token = $this->trimmed('token-' . $notice->id);
     if (!$token || $token != common_session_token()) {
         // TRANS: Client error displayed when the session token does not match or is not given.
         $this->clientError(_('There was a problem with your session token. Try again, please.'));
         return;
     }
     if ($user->hasFave($notice)) {
         // TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
         $this->clientError(_('This notice is already a favorite!'));
         return;
     }
     $fave = Fave::addNew($user->getProfile(), $notice);
     if (!$fave) {
         // TRANS: Server error displayed when trying to mark a notice as favorite fails in the database.
         $this->serverError(_('Could not create favorite.'));
         return;
     }
     $this->notify($notice, $user);
     $user->blowFavesCache();
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Page title for page on which favorite notices can be unfavourited.
         $this->element('title', null, _('Disfavor favorite.'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $disfavor = new DisFavorForm($this, $notice);
         $disfavor->show();
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)), 303);
     }
 }