Esempio n. 1
0
 /**
  * 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('all', array('nickname' => $user->nickname)));
         return;
     }
     $noticeid = $this->trimmed('notice');
     $notice = Notice::staticGet($noticeid);
     $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;
     }
     $gradevalue = $this->trimmed('value');
     $nickname = $user->nickname;
     $exist = Grades::getNoticeGrade($noticeid, $nickname);
     if ($exist != '?') {
         Grades::updateNotice(array('noticeid' => $noticeid, 'grade' => $gradevalue, 'userid' => $nickname));
     } else {
         Grades::register(array('userid' => $nickname, 'noticeid' => $noticeid, 'grade' => $gradevalue));
     }
     if ($this->boolean('ajax')) {
         $this->startHTML('application/xml,text/xml;charset=utf-8');
         $this->elementStart('head');
         $this->element('title', null, _('Disfavor favorite'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $this->element('p');
         $this->elementEnd('body');
         $this->elementEnd('html');
     }
 }