public static function getEngin() { //echo '{"error":"1","msg":"id=0","found":12}';exit(); // $id = JRequest::getInt('id',0); $id = filter_input(INPUT_GET, 'id'); if ($id < 1) { echo '{"error":"1","msg":"id=0","found":0}'; exit; } $start = date('Y-m-d H:i:s'); $grab = new obGrab(); $res = $grab->start($id); echo '<p>[ Started: ' . $start . ' ][ Source found: ' . $res->total . ' items ]</p>'; echo '<input type="hidden" id="ogb-' . $id . '-efound" name="ogb-' . $id . '-efound" value="' . $res->total . '"/>'; if ($res->total > 0) { echo ' <div class="progress progress-striped" id="ogb-' . $id . '-res-bar"> <div class="progress-bar bar-success" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%; height: 100%"> <small>0% Complete (success)</small> </div> </div> '; echo '<ol id="ogb-' . $id . '-get-rows"> </ol>'; } else { echo ' <p class="alert alert-danger">No data found from the SOURCE.</p> '; } //echo $res->json; if (isset($_GET['x'])) { echo "\n\n<br /><i><b>File:</b>" . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br />\n\n"; echo '<pre>'; print_r($res); echo '</pre>'; } exit; }
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; }