Esempio n. 1
0
 public function store_check($input_arr = array())
 {
     $input_arr['action'] = 'creating';
     if (!$this->validate($input_arr)) {
         //$this->format_error_messages($input_arr['type'],($input_arr['type'] == 'dns') ? $input_arr['host'] : $input_arr['url'], 'creating');
         return false;
     }
     $option = isset($input_arr['edit_options']) && $input_arr['edit_options'] == 'change' ? $input_arr['options'] : ($option = json_encode(array('phrases_to_match' => $input_arr['phrases'], 'post_body' => $input_arr['post_body'], 'url_path' => Check::getPathFromURLString($input_arr['url']))));
     $this->user_id = intval($input_arr['user_id']);
     $this->url = $input_arr['type'] == 'https' ? str_replace('http://', 'https://', $input_arr['url']) : $input_arr['url'];
     $this->domain = Check::getDomainFromURLString($input_arr['url']);
     $this->type = $input_arr['type'];
     $this->host = $this->type == 'dns' ? $input_arr['host'] : '';
     $this->options = $option;
     $this->create_time = time();
     //Log::info("Json error:".json_last_error().' '.JSON_ERROR_NONE);
     if ($this->save()) {
         $MongoAPI = new MongoAPI();
         $this->mongo_id = $MongoAPI->saveSiteInfoToMongo($this->type, 'KUU-' . $this->user_id . '-' . $this->check_id, $this->domain . (($s = Check::getPathFromURLString($this->url)) != 'Homepage' ? '/' . $s : ''), $this->get_match());
         if ($this->mongo_id && $this->save()) {
             return true;
         } else {
             array_push($this->validate_errors, 'Check information was not saved.');
             $this->delete();
             return false;
         }
     } else {
         array_push($this->validate_errors, 'Check information was not saved.');
         return false;
     }
 }
 public function postAddSiteInfoAuto()
 {
     $input = \Input::all();
     $error_messages = array();
     $types = array('http', 'https', 'dns');
     $i = 0;
     foreach ($types as $type) {
         $parameters = array('type' => $type, 'url' => $input['url'], 'edit_options' => 'change', 'options' => '', 'host' => $type == 'dns' ? gethostbyname(Check::getDomainFromURLString($input['url'])) : '');
         $check = new Check();
         if (!$check->user_store_check($parameters)) {
             $error_messages = array_merge($error_messages, $check->validate_errors);
         } else {
             $i++;
             $mess = $this->user_save_check_alert_emails($check->check_id);
             if ($i == 1) {
                 foreach ($mess as $error_message) {
                     array_push($error_messages, $error_message);
                 }
             }
         }
     }
     Session::flash('error_messages', $error_messages);
     $user_check_count = Check::get_user_check()->count();
     return Response::json(array('status' => 'OK', 'is_add_enable' => $user_check_count < $this->check_create_limit_num ? true : false));
 }