コード例 #1
0
ファイル: system.php プロジェクト: janladaking/CodeIgniter
 /**
  * Import keywords and create/update group from file
  * @return json
  * @author Ruslan Ushakov
  */
 public function handle_keyword_groups()
 {
     ini_set("auto_detect_line_endings", true);
     $this->load->model('settings_model');
     $choosen_file = $this->input->post('choosen_file');
     $group_name = $this->input->post('group_name');
     $file = $this->config->item('csv_upload_dir') . $choosen_file;
     $fileHandler = fopen($file, 'r');
     if (!$fileHandler) {
         log_message('ERROR', 'File not open ' . $file);
         return;
     }
     $group_id = 0;
     $term_ids = array();
     if (!empty($group_name)) {
         $this->load->model('ranking_model');
         $group_id = $this->ranking_model->selectOrIKeywordGroup($group_name);
         $this->ranking_model->addKeywordGroupCronJob($group_id, $this->ranking_model->CRON_PERIOD_DAY);
         /*get file extension*/
         $file_arr = explode('.', $file);
         $ext = '';
         if (!empty($file_arr) && count($file_arr) > 1) {
             $ext = $file_arr[count($file_arr) - 1];
         }
         if ($ext == 'txt') {
             $file_read = file($file);
             //each row in this file is a json
             foreach ($file_read as &$item) {
                 $item = trim($item);
                 $term_ids[] = $this->ranking_model->selectOrInsertIdSearchTerms($item, $group_id);
             }
         } elseif ($ext == 'csv') {
             /* read csv data*/
             while (($data = fgetcsv($fileHandler, 1000, ",")) !== FALSE) {
                 foreach ($data as $item) {
                     $term_ids[] = $this->ranking_model->selectOrInsertIdSearchTerms($item, $group_id);
                 }
             }
         }
     }
     $this->output->set_content_type('application/json')->set_output(json_encode(array('status' => 'ok', 'group_id' => $group_id, 'group_name' => $group_name, 'terms' => $term_ids)));
 }
コード例 #2
0
ファイル: crawl.php プロジェクト: janladaking/CodeIgniter
 /**
  * Add new keyword
  * @return json
  * @author Ruslan Ushakov
  */
 function addKeyword()
 {
     $keyword = $this->input->post('keyword');
     $group = (int) $this->input->post('group');
     $res = array();
     $keyword_arr = explode(',', $keyword);
     if (!empty($keyword_arr)) {
         $this->load->model('ranking_model');
         if ($group == -1) {
             $group = $this->ranking_model->selectOrIKeywordGroup('Dont show');
             $this->ranking_model->deleteSearchTermsByGroupId($group);
             $this->ranking_model->addKeywordGroupCronJob($group, $this->ranking_model->CRON_PERIOD_DAY);
         }
         foreach ($keyword_arr as &$kword) {
             $kword = trim($kword);
             if ($kword) {
                 $res[] = $this->ranking_model->selectOrInsertIdSearchTerms($kword, $group);
             }
         }
     }
     $this->output->set_content_type('application/json')->set_output(json_encode(array('status' => 'ok', 'k_ids' => $res, 'group' => $group)));
 }