public function export_to_share() { $mod = $this->getModel('pipes'); $id = isset($_GET['id']) ? $_GET['id'] : ''; if ($id == '') { PIPES::add_message("Please pick up at least 1 pipe first!"); $url = remove_query_arg(array('id', 'action', 'action2'), $_SERVER['HTTP_REFERER']); header('Location: ' . $url); exit; } $set_template = isset($_GET['set_template']) ? $_GET['set_template'] : 0; $res = $mod->export_to_share($id); //PIPES::add_message($res->msg); if (count($res->result) == 1) { $file_name = sanitize_title($res->result[0]->name) . '.pipe'; } else { $file_name = 'pipes-' . date('d-m-Y', time()) . '.pipe'; } $upload_dir = wp_upload_dir(); if ($set_template) { $file_name = $upload_dir['basedir'] . DS . 'wppipes' . DS . 'templates' . DS . $file_name; if (!is_file($file_name)) { ogbFolder::create($upload_dir['basedir'] . DS . 'wppipes' . DS . 'templates'); } } $fp = fopen($file_name, 'w'); foreach ($res->result as $result) { fwrite($fp, json_encode($result) . "\n"); } //var_dump(filesize("$file_name"));die; fclose($fp); if ($set_template) { PIPES::add_message($res->msg); $url = admin_url() . 'admin.php?page=' . PIPES::$__page_prefix . '.pipe&id=' . $id; header('Location: ' . $url); } header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Length: " . filesize("{$file_name}") . ";"); header("Content-Disposition: attachment; filename={$file_name}"); header("Content-Transfer-Encoding: binary"); readfile($file_name); /*$url = remove_query_arg(array('id', 'task', 'action', 'action2'), $_SERVER['HTTP_REFERER']); header('Location: ' . $url);*/ exit; }
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 write($path, $txt = '') { $path = self::clean($path); $folder = dirname($path); if (!is_dir($folder)) { ogbFolder::create($folder); } $ret = is_int(file_put_contents($path, $txt)); return $ret; }