Esempio n. 1
0
 /**
  * 过滤数据,包括tag和special chars
  *
  * @param $value
  * @return array|string
  */
 public static function clean_data($value)
 {
     if (is_array($value)) {
         foreach ($value as $k => $v) {
             $value[$k] = OJ::clean_data($v);
         }
     } else {
         $value = strip_tags($value);
         $value = HTML::chars($value, TRUE);
     }
     return $value;
 }
Esempio n. 2
0
 public function action_submit()
 {
     $current_user = $this->check_login();
     if ($this->request->is_post()) {
         $pid = $this->get_post('pid');
         $cid = $this->get_post('cid', null);
         $cpid = $this->get_post('cpid', -1);
         // if no pid, then it should be contest
         // if contest id set, then this submit a contest problem
         if ($cid and $cpid !== -1) {
             $contest = Model_Contest::find_by_id($cid);
             if ($contest and $contest->can_user_access($current_user)) {
                 $problem = $contest->problem($cpid);
                 if (!$problem) {
                     throw new Exception_Page(__('common.problem_not_found'));
                 }
             } else {
                 throw new Exception_Page(__('common.contest_not_found'));
             }
         } else {
             // so is normal submit
             $problem = Model_Problem::find_by_id($pid);
             if (!$problem or !$problem->can_user_access($current_user)) {
                 throw new Exception_Page(__('common.problem_not_found'));
             }
         }
         $last_submission = $current_user->get_last_submission();
         if ($last_submission) {
             $d_start = strtotime($last_submission);
             $d_end = time();
             $limitation = OJ::get_submit_time();
             if ($d_end - $d_start < $limitation) {
                 throw new Exception_Page(__('common.too_quick_:sec', array(':sec' => $limitation)));
             }
         }
         $source_code = $this->get_raw_post('source');
         $lang = $this->get_post('language');
         $solution = Model_Solution::create($current_user, $problem, $lang, $source_code);
         if ($cid) {
             // set contest info
             $solution->contest_id = $cid;
             $solution->num = $cpid;
         }
         $solution->save();
         // set user favorite language
         $current_user->language = $lang;
         $current_user->save();
         $this->redirect('/status');
         return;
     } else {
         $pid = $this->request->param('id', null);
         $this->template_data['pid'] = OJ::clean_data($pid);
     }
     $this->template_data['cid'] = $this->get_query('cid', null);
     $this->template_data['cpid'] = $this->get_query('pid', null);
     $this->template_data['default_lang'] = $current_user->language;
     $this->template_data['title'] = __('problem.submit.submit_code');
 }
Esempio n. 3
0
 /**
  * all post data
  *
  * @return array
  */
 protected function cleaned_post()
 {
     return OJ::clean_data($this->request->post());
 }