public static function update_cache($path, $rows) { $data = serialize($rows); $cache = self::get_cache($path); $a = ogbFile::write($path, $cache); return $a; }
function getTotalRow($id) { $path = OGRAB_MEDATA . 'item-' . $id . '.txt'; if (!is_file($path)) { return 2; } return ogbFile::get_content($path); }
public static function write_data($path, $data) { if (class_exists('ogbFile')) { $wr = ogbFile::write($path, $data); } else { $wr = true; if (!is_file($path)) { $wr = self::mkdir($path); } if ($wr) { $wr = file_put_contents($path, $data); } } return $wr; }
/** * Saves this feed as a file on the local disk. After the file is saved, a redirect * header may be sent to redirect the user to the newly created file. * @since 1.4 * * @param filename string optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()). * @param redirect boolean optional send an HTTP redirect header or not. If true, the user will be automatically redirected to the created file. */ function saveFeed($filename = "", $displayContents = true) { jimport('joomla.filesystem.file'); if ($filename == "") { $filename = $this->_generateFilename(); } $res = $this->createFeed(); if (!ogbFile::write($filename, $res)) { echo "<br /><b>Error creating feed file, please check write permissions.</b><br />"; } else { if ($displayContents) { $this->_redirect($filename); } } // var_dump('1bss'); // $feedFile = fopen($filename, "w+"); // if ($feedFile) { // fputs($feedFile,$this->createFeed()); // fclose($feedFile); // if ($displayContents) { // $this->_redirect($filename); // } // return true; // } else { // echo "<br /><b>Error creating feed file, please check write permissions.</b><br />"; // } }
public static function copyImage($contents = '', $itemLink = '', $params) { $matches = array(); $upload_dir = wp_upload_dir(); preg_match_all("#<img*[^\\>]*>#i", $contents, $matches); if (!isset($matches[0][0])) { return $contents; } $searches = $matches[0]; $local_dir = $params->image_local; if (substr($local_dir, 0, 1) == '/') { $local_dir = substr($local_dir, 1); } $upload_path = $upload_dir['basedir']; $url_path = $upload_dir['baseurl'] . DS . $local_dir; $to = array('host' => str_replace("\\", "/", $url_path), 'path' => $local_dir); if (isset($params->origin_url) && $params->origin_url != '') { $origin_url = $params->origin_url; } else { $url_parts = parse_url($itemLink); $origin_url = @$url_parts['scheme'] . "://" . @$url_parts['host']; } $dest_host = isset($to['host']) ? $to['host'] : ''; $more_path = date('Y-m'); $dest_path = isset($to['path']) ? $upload_path . DS . $to['path'] . DS . $more_path : ''; /*if ( ! preg_match( '!^https?://.+!i', $dest_host ) ) { $dest_host = str_replace( "administrator/", "", JURI :: base() ) . $dest_host; }*/ $dest_parts = parse_url($dest_host); $source_urls = array(); $replaces = $searches; $b = explode("'", $searches[0]); $repl = isset($b[1]); $iMin = array(64, 64); if (isset($params->clear_tiny)) { $clear_tiny = explode('x', $params->clear_tiny); $iMin[0] = (int) $clear_tiny[0]; if (isset($clear_tiny[1])) { $iMin[1] = (int) $clear_tiny[1]; } } for ($i = 0; $i < count($searches); $i++) { $remove = false; $img = $searches[$i]; if ($repl) { $img = str_replace("'", '"', $searches[$i]); $contents = str_replace($searches[$i], $img, $contents); $searches[$i] = $replaces[$i] = $img; } preg_match_all('#\\ssrc=\\"*[^\\"]*\\"#', $img, $src); $src = preg_replace("#src\\s*=\\s*\"|\"#", "", @$src[0][0]); if (!preg_match('!https?://.+!i', $src)) { $source_urls[$i] = $origin_url . trim($src); } else { $source_urls[$i] = $src; } if (@$params->special_img_url) { $source_urls[$i] = self::img_url_encode($source_urls[$i]); } $info_file = @get_headers(trim($source_urls[$i]), 1); if (!$info_file) { $curl = self::get_web_page(trim($source_urls[$i])); $info_file['Content-Type'] = $curl['content_type']; $mime = $info_file['Content-Type']; } else { $mime = $info_file['Content-Type']; } if (count($mime) > 1) { $mime = implode("/", $mime); } $temp_arr = explode("/", $mime); if (!in_array('image', $temp_arr)) { //check is image or not continue; } $filename = substr(md5($source_urls[$i]), -10) . '.' . end($temp_arr); $success = false; if ($dest_host && $dest_path) { $s = $source_urls[$i]; $d = $dest_path . DS . $filename; $success = file_exists($d); $unlink = true; //$remove = true; // Debug if (isset($_GET['i'])) { $img_info = array(); echo '<hr /><i><b>File:</b>' . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br /> \n"; echo '[ url_path ]: '; var_dump($url_path); echo '<br />[ <a href="' . $s . '" target="_blank">source_urls</a> ]: ' . $s; echo '<br />[ <a href="' . $url_path . '/' . $filename . '" target="_blank">dest_path</a> ]: ' . $d; if (isset($_GET['y'])) { echo '<br /><br /><i><b>File:</b>' . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br /> \n"; if ($success) { $success = false; $k = unlink($d); echo 'Unlink: '; var_dump($k); } else { echo 'File not exist'; } echo 'dest_path:'; var_dump($k); } } if (!$success) { $aa = ogbFolder::create($dest_path); if ($aa) { $img_c = ogbFile::get_curl(trim($s)); $a = ogbFile::write($d, $img_c); //$a = copy($s, $d); if (is_file($d)) { $size = filesize($d); if ($size > 0) { $img_info = getimagesize(trim($source_urls[$i])); $width = isset($img_info[0]) ? $img_info[0] : 0; $height = isset($img_info[1]) ? $img_info[1] : 0; $remove = $iMin[0] > 0 && $width > 0 && $width < $iMin[0]; if (!$remove) { $remove = $iMin[1] > 0 && $height > 0 && $height < $iMin[1]; } if (!$remove) { $success = true; $unlink = false; } } if ($unlink && !isset($_GET['nodel'])) { unlink($d); } } else { $size = 0; } // Debug if (isset($_GET['i'])) { echo '<br /><i><b>File:</b>' . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br /> \n"; echo 'copy image Success: '; var_dump($a); echo '<br />file image exist: '; var_dump($success); echo '<br />Size: '; var_dump($size); echo '<br />Unlink:'; var_dump($unlink); echo '<pre>'; print_r($iMin); print_r($img_info); echo '</pre>'; } } } } if ($remove) { $replaces[$i] = ''; } else { if ($success) { $replace = "src=\"" . ($dest_host . '/' . $more_path . '/' . $filename) . "\""; } else { if (!preg_match('!^https?://.+!i', $src)) { // if src is not contain host=>add host to src $source_path = $origin_url . '/' . $src; } else { $source_path = $src; } $replace = "src=\"" . $source_urls[$i] . "\""; } $replaces[$i] = preg_replace("#src\\s*=\\s*\"*[^\"]*\"#", $replace, $replaces[$i]); } } $contents = str_replace($searches, $replaces, $contents); // Debug if (isset($_GET['i2'])) { echo '<br /><i><b>File:</b>' . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br /> \n"; echo '$itemLink: '; var_dump($itemLink); echo '<pre>'; echo 'searches:'; print_r($searches); echo 'replaces:'; print_r($replaces); echo '</pre>'; echo '<hr />' . $contents; exit; } return $contents; }
public static function makeLogSave($save) { if ($save->action != 'Save') { return ''; } $host = ogbFile::getHost(); $source = '<a target="_blank" href="' . $save->src_url . '">' . $save->src_name . '</a>'; $view = '[ id: ' . $save->id . ' ][ <a target="_blank" href="' . $host . $save->viewLink . '">View</a> ]'; $edit = '[ <a target="_blank" href="' . $host . 'administrator/' . $save->editLink . '">Edit</a> ]'; $savedInfo = '<li><b>Source: </b>' . $source . '<br />[ Saved at: ' . date('Y-m-d H:i:s') . ' ]'; $savedInfo .= $view . $edit . '[ ID: ' . $save->item_id . ' ]<hr /></li>'; return $savedInfo; }
function write_down_input_processor() { $mod = $this->getModel('pipe'); $id = filter_input(INPUT_GET, 'id'); $processor_id = filter_input(INPUT_GET, 'process_id'); $ordering = filter_input(INPUT_GET, 'ordering'); $input_type = filter_input(INPUT_GET, 'input_type'); $input_value = filter_input(INPUT_GET, 'input_value'); $input_name = filter_input(INPUT_GET, 'input_name'); $current_default = ogb_common::get_default_data('', $id); if ($input_type == 'e') { $input_type = 'so'; } else { $stt = $input_type; $input_type = 'po'; } if (!is_array($current_default->pi)) { $current_default->pi = array(); } if (!is_object($current_default->pi[$ordering])) { $current_default->pi[$ordering] = new stdClass(); } $current_default->pi[$ordering]->{$input_name} = $input_type . ',' . $input_value . ',' . $processor_id; if (isset($stt)) { $current_default->pi[$ordering]->{$input_name} .= ',' . $stt; } $current_default = $mod->get_first_output_processor($current_default, $ordering, $processor_id); $cache = serialize($current_default); $path = OGRAB_EDATA . 'item-' . $id . DS . 'row-default.dat'; ogbFile::write($path, $cache); echo json_encode($current_default->po[$ordering]); exit; /*echo '<pre>';print_r( $current_default );die; $pipe = $mod->get_one_pipe( $processor_id ); $name = $pipe->code; $params = json_decode( $pipe->params ); $class = 'WPPipesPro_' . $name; $datas = ogbLib::call_method( $class, 'process', array( $pipe->params ) );*/ }
public static function get_default_item() { $id = filter_input(INPUT_POST, 'id'); $value_default = filter_input(INPUT_POST, 'val_default'); if ($value_default == '') { return 'Do nothing!'; } $feed = new SimplePie(); $path = OGRAB_EDATA . 'item-' . $id . DS . 'row-default.dat'; $feed->set_feed_url($value_default); $feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE); $feed->set_timeout(20); $feed->enable_cache(false); $feed->set_stupidly_fast(true); $feed->enable_order_by_date(false); // we don't want to do anything to the feed $feed->set_url_replacements(array()); $result = $feed->init(); if (isset($_GET['x'])) { echo "\n\n<br /><i><b>File:</b>" . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br />\n\n"; echo "<p>URL: [{$value_default}]</p>"; echo "<p>Error: [{$feed->error}]</p>"; } $items = $feed->get_items(); $c_items = count($items); if ($c_items == 0) { echo "<p>Error: [{$feed->error}]</p>"; return array(); } $row = new stdclass(); $row->title = html_entity_decode($items[0]->get_title(), ENT_QUOTES, 'UTF-8'); # the title for the post $row->link = $items[0]->get_link(); # a single link for the post $row->description = $items[0]->get_description(); # the content of the post (prefers summaries) $row->author = $items[0]->get_author(); # a single author for the post $row->date = $items[0]->get_date('Y-m-d H:i:s'); $row->enclosures = $items[0]->get_enclosures(); if (!is_file($path)) { $source = new stdClass(); } else { $source = ogb_common::get_default_data('', $id); } $source->so = $row; $cache = serialize($source); if (isset($_GET['x2'])) { //echo "\n\n<br /><i><b>File:</b>".__FILE__.' <b>Line:</b>'.__LINE__."</i><br />\n\n"; echo '<br>Path: ' . $path; } ogbFile::write($path, $cache); exit; }
public static function addSavedLog($info) { if ($info == '') { return; } $name = ''; if (is_file(OGRAB_CACHE . 'savedinfo')) { $name = file_get_contents(OGRAB_CACHE . 'savedinfo'); } if (is_file(OGRAB_CACHE_SAVED . $name) && filesize(OGRAB_CACHE_SAVED . $name) < 102400) { $old = file_get_contents(OGRAB_CACHE_SAVED . $name); } else { $name = date('Y.m.d-H.i.s'); ogbFile::write(OGRAB_CACHE . 'savedinfo', $name); $old = ''; } ogbFile::write(OGRAB_CACHE_SAVED . $name, $info . "\n" . $old); }
public static function get_items_feed($url, $params = null) { $feed = new SimplePie(); $mode = isset($params->mode) ? $params->mode : 0; if ($mode == 0) { $feed->set_feed_url($url); } else { $html = ogbFile::get_curl($url); $feed->set_raw_data($html); } $feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE); $feed->set_timeout(20); $feed->enable_cache(false); $feed->set_stupidly_fast(true); $feed->enable_order_by_date(false); // we don't want to do anything to the feed $feed->set_url_replacements(array()); $feed->force_feed(true); $result = $feed->init(); if (isset($_GET['x'])) { echo "\n\n<br /><i><b>File:</b>" . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br />\n\n"; echo "<p>URL: [{$url}]</p>"; echo "<p>Error: [{$feed->error}]</p>"; } $items = $feed->get_items(); $c_items = count($items); if ($c_items == 0) { echo "<p>Error: [{$feed->error}]</p>"; return array(); } for ($i = 0; $i < count($items); $i++) { $row = new stdclass(); $row->title = $items[$i]->get_title(); # the title for the post $row->link = $items[$i]->get_link(); # a single link for the post $row->description = $items[$i]->get_description(); # the content of the post (prefers summaries) $row->author = $items[$i]->get_author(); # a single author for the post $row->date = $items[$i]->get_date('Y-m-d H:i:s'); $row->enclosures = $items[$i]->get_enclosures(); $rows[] = $row; } return $rows; }
public static function create($path, $mode = 0755) { $path = ogbFile::clean($path); if (is_dir($path)) { return true; } $i = 0; $parent = dirname($path); // JFolder::create(); if (is_dir($parent)) { // First set umask $origmask = @umask(0); // Create the path if (!($ret = @mkdir($path, $mode))) { @umask($origmask); return false; } // Reset umask @umask($origmask); } else { self::create($parent, $mode); self::create($path, $mode); } }