/** * 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'); } }
Create a grade in the name of a user for a notice -u --user nickname of the user who creates the notice -n --noticeid id of the notice to grade -g --grade grade assigned to the notice END_OF_REGISTERUSER_HELP; require_once INSTALLDIR . '/scripts/commandline.inc'; require_once INSTALLDIR . '/local/plugins/Grades/classes/Grades.php'; $nickname = get_option_value('u', 'user'); $noticeid = get_option_value('n', 'noticeid'); $gradeval = get_option_value('g', 'grade'); if (empty($nickname) || empty($noticeid) || empty($gradeval)) { print "Must provide a username, a notice id, and a grade.\n"; exit(1); } try { $user = User::staticGet('nickname', $nickname); if (empty($user)) { throw new Exception("A user named '{$nickname}' must exists."); } $notice = Notice::staticGet('notice', $noticeid); if (empty($notice)) { throw new Exception("A notice with id '{$noticeid}' must exists."); } $grade = Grades::register(array('userid' => $nickname, 'noticeid' => $noticeid, 'grade' => $gradeval)); } catch (Exception $e) { print $e->getMessage() . "\n"; print $e->getTraceAsString(); exit(1); }