示例#1
0
文件: post.php 项目: kosir/wp-pipes
 public static function saveAdapter()
 {
     sleep(1);
     $id = filter_input(INPUT_GET, 'id');
     $row = filter_input(INPUT_GET, 'row');
     require_once PIPES_PATH . DS . 'grab.php';
     $grab = new obGrab();
     $res = $grab->storeItems($id, $row);
     $log = self::makeInfo($res);
     echo $log;
     exit;
 }
示例#2
0
 public static function runCron()
 {
     $ip = isset($_GET['ip']) ? $_GET['ip'] : '1.1.1.1';
     $ip = "[ ip: {$ip} ]";
     $new_start = true;
     /*Check pie from cache. If isset pieID, It will run this pieID.
     		If not It will stop: Default data: 0:0:0
     		{0 position 1:pieID}{{0 position 2:Number data what is imported}{{0 position 3: Total datas what be got by engine }
     		File name: runing.info
     		*/
     if (!is_file(OGRAB_CACHE_DATA_RUNING)) {
         $run_id = 0;
         $crun = $mrun = 0;
     } else {
         $run_info = self::get_content(OGRAB_CACHE_DATA_RUNING);
         if (isset($_GET['x'])) {
             echo "\n\n<br /><i><b>File:</b>" . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br />\n\n";
             echo '$run_info: ';
             var_dump($run_info);
         }
         $run_info = explode(':', $run_info);
         $run_id = (int) $run_info[0];
         $crun = (int) $run_info[1];
         $mrun = (int) $run_info[2];
         if ($crun < $mrun) {
             $new_start = false;
         }
     }
     if ($new_start) {
         $run_id = self::getNextRunId($run_id);
         $run_item_time = self::getTimeSchedule($run_id);
         if (isset($_GET['x'])) {
             echo "\n\n<br /><i><b>File:</b>" . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br />\n\n";
             echo 'run time: ' . $run_item_time;
         }
         if ($run_id == 0) {
             self::set_data_run("0:0:0");
             self::setDone('1');
             $log = "\n\n<hr /><b style=\"color:#555555;\">" . date('Y-m-d H:i:s') . ' - Done</b> ' . $ip . '<hr />';
             self::addLog($log, true);
             return $log;
         }
     }
     $start = time();
     $log = "<hr/>[ " . date('Y-m-d H:i:s', $start) . '  - Start ]' . $ip;
     /*Include obGrab class. What will call engine, adapter, store plugin content*/
     require_once OBGRAB_SITE . 'grab.php';
     $grab = new obGrab();
     $info = '';
     if (isset($_GET['x'])) {
         echo "\n\n<br /><i><b>File:</b>" . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br />\n\n";
         echo '<br />New start:' . $new_start;
     }
     if ($new_start) {
         /*Check time for each pie. If pie's nextime less now. Pie will run'*/
         if ($run_item_time < $start) {
             if (isset($_GET['x'])) {
                 echo "\n\n<br /><i><b>File:</b>" . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br />\n\n";
             }
             $res = $grab->start($run_id);
         }
         $crun = 0;
         $mrun = $res->total;
         //$info	= $res->info;
         self::set_data_run("{$run_id}:{$crun}:{$mrun}");
         if (isset($_GET['x'])) {
             echo "\n\n<br /><i><b>File:</b>" . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br />\n\n";
             echo '$new_start: ';
             var_dump($new_start);
             echo '<pre>';
             print_r($res);
             echo '</pre>';
             echo "{$run_id}:{$crun}:{$mrun}";
         }
         $edit_url = "admin.php?page=pipes.pipe&id={$run_id}";
         $a_edit = "<a href=\"{$edit_url}\" target=\"_blank\">{$run_id} - {$res->pipe}</a>";
         $log2 = "<hr /><b>Pipe: {$a_edit}</b><br/ >" . '[ ' . date('Y-m-d H:i:s') . ' ]';
         $log2 .= "[ Engine: {$res->name} ][ Found: {$mrun} articles ]<br/ >\n";
         self::addLog($log2, true);
         self::addLog('');
         $log2 .= $mrun > 0 ? '<ol>' : '<br/>' . date('Y-m-d H:i:s') . " Stop: [{$run_id}:{$crun}/{$mrun}]";
         $log .= $log2;
         if ($mrun < 1 || self::outTime($start)) {
             return $log;
         }
     }
     $savedInfo = '';
     /*Storedata what is got by engine into database*/
     for ($i = $crun; $i < $mrun; $i++) {
         $info = $grab->storeItems($run_id, $i);
         $savedInfo .= self::makeLogSave($info);
         $log .= self::makeLogCron($info);
         if (isset($_GET['x'])) {
             echo "\n\n<br /><i><b>File:</b>" . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br />\n\n";
             echo 'crun: ' . $i;
         }
         if (self::outTime($start) || isset($_GET['st'])) {
             $i++;
             break;
         }
     }
     self::addSavedLog($savedInfo);
     /*Write cache next ID runing.info. If not write, It will not run next time*/
     self::set_data_run("{$run_id}:{$i}:{$mrun}");
     $log .= ($i == $mrun ? '</ol>' : '') . '[ ' . date('Y-m-d H:i:s') . ' - Stop ]';
     $log .= '[ Pipe id: ' . $run_id . ' - (' . $crun . '->' . $i . ')/' . $mrun . ' ]';
     return $log;
 }