function __construct($initialize = true) { $options = json_decode(stripslashes($_REQUEST['options']), true); $default_local_url = GenFun::get_local_url('/Modules/generated_files'); $default_url = GenFun::get_full_url('/Modules/generated_files'); $this->options = array('script_url' => $default_local_url, 'upload_dir' => isset($_REQUEST['dir']) ? $default_local_url . "/" . $_REQUEST['dir'] . '/' : $default_local_url . '/', 'upload_url' => isset($_REQUEST['dir']) ? $default_url . "/" . $_REQUEST['dir'] . '/' : $default_url . '/', 'user_dirs' => false, 'mkdir_mode' => 0755, 'param_name' => 'files', 'delete_type' => 'DELETE', 'access_control_allow_origin' => '*', 'access_control_allow_credentials' => false, 'access_control_allow_methods' => array('OPTIONS', 'HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'), 'access_control_allow_headers' => array('Content-Type', 'Content-Range', 'Content-Disposition'), 'download_via_php' => false, 'inline_file_types' => '/\\.(gif|jpe?g|png)$/i', 'accept_file_types' => '/.+$/i', 'max_file_size' => null, 'min_file_size' => 1, 'max_number_of_files' => null, 'max_width' => null, 'max_height' => null, 'min_width' => 1, 'min_height' => 1, 'discard_aborted_uploads' => true, 'orient_image' => true, 'image_versions' => array('thumbnail' => array('max_width' => 80, 'max_height' => 80))); if ($options) { $this->options = array_merge($this->options, $options); } if ($initialize) { $this->initialize(); } }
public function file_exists_local($file) { if (strpos($file, "http://") !== false) { $file = GenFun::get_local_url($file); } //--------------------------------------------------------- if (file_exists($file)) { } else { if (file_exists(Import::uber_src_path() . $file)) { $file = Import::uber_src_path() . $file; } else { if (file_exists(Import::getImportPath() . $file)) { $file = Import::getImportPath() . $file; } } } return $file; }
public function uploadFile($replaceWhiteSpaceWith = NULL) { Trace::output(self::$traceID, "uploadFile", func_get_args()); //---------------------------------------------------------- //init var //---------------------------------------------------------- $chk = array("bool" => true, 'result' => array(), "func" => "uploadFile"); //---------------------------------------------------------- $upload = $this->uploadClass->post(false); //---------------------------------------------------------- if (is_null($upload["files"][0]->error)) { $orig_path = urldecode(GenFun::get_local_url($upload['files'][0]->url)); //---------------------------------------------------------- $oldName = $upload["files"][0]->name; //---------------------------------------------------------- $newName = is_null($replaceWhiteSpaceWith) ? $oldName : str_replace(' ', '_', $oldName); $arr = explode(".", $newName); $ext = $arr[sizeof($arr) - 1]; $newName = stripslashes($arr[0]); //---------------------------------------------------------- if (!is_null($replaceWhiteSpaceWith)) { $newName = preg_replace('/[^a-z_0-9-]*/i', '', $newName); } //---------------------------------------------------------- $path = FileFolder::getPathFromFile($orig_path); //---------------------------------------------------------- $path = $path . $newName . "." . $ext; //---------------------------------------------------------- rename($orig_path, $path); //---------------------------------------------------------- $local_url = $path; //---------------------------------------------------------- //$hash = MySQL::getNextInsertID('files'); //---------------------------------------------------------- //if (is_object($hash)) return $hash; //---------------------------------------------------------- //$new_local_url = FileFolder::moveToFolder($local_url, $hash."/"); //---------------------------------------------------------- //$upload['files'][0]->url = GenFun::get_full_url($new_local_url); //---------------------------------------------------------- $chk = Upload::insertFile($newName . "." . $ext, json_encode($upload)); //---------------------------------------------------------- if ($chk['bool']) { $hash = $chk['row']['hash']; //---------------------------------------------------------- if (is_object($hash)) { return $hash; } //---------------------------------------------------------- $this->url_local = FileFolder::moveToFolder($local_url, $this->appendToDir . $hash . "/"); //---------------------------------------------------------- $upload['hash'] = $hash; $chk['files'] = $upload['files']; $chk['value'] = $chk['insert_id']; $chk['hash'] = $hash; unset($chk['insert_id']); unset($chk['row']); } } else { $chk = $upload; } return $chk; }
public static function chk($file, $include = true) { //------------------------------------------- //init var //------------------------------------------- $bool = true; //------------------------------------------- foreach (self::$filesLoaded as &$value) { if ($file == $value) { $bool = false; } } //------------------------------------------- if (!file_exists(GenFun::get_local_url($file))) { throw new Exception($file . " does not exist "); } //------------------------------------------- if ($bool) { array_push(self::$filesLoaded, $file); if ($include) { include_once $file; } } //------------------------------------------- return $bool; }
private function compile_CFG($url, $id, $savePath) { $_GET['compile'] = 1; $_GET['refresh'] = 1; $_GET['compile_id'] = $id; //--------------------------------------------------------- $prop = array("url" => $url, "compilePath" => $savePath); //--------------------------------------------------------- if (file_exists($path = GenFun::get_local_url($url) . "compileConfig.js")) { $this->compileObj = json_decode(file_get_contents($path), true); } else { if (class_exists("ProjectGlobal")) { $this->compileObj = ProjectGlobal::$compileObj; } } return $compiler = new Compiler(ArrayUtil::array_replace_recursive($this->compileObj, $prop)); //--------------------------------------------------------- }
public function link_CFG($filePath) { //--------------------------------------------- $replaceArr = array(GlobalMas::$filesPath_absolute . Compiler::$importTmpPath, is_null($this->compilerGlobal) ? NULL : $this->compilerGlobal->url); //--------------------------------------------- $local = str_replace($replaceArr, "", GenFun::get_local_url($filePath)); //--------------------------------------------- if (!is_null($this->applyToFilesIn)) { foreach ($this->applyToFilesIn as $key => $value) { preg_match_all("/{strict}/s", $key, $strict, PREG_SET_ORDER); if (sizeof($strict) > 0) { $key = str_replace($strict[0], "", $key); $strict = true; } else { $strict = NULL; } if (strpos($local, $key) !== false) { if ($strict && strpos($local, $key) == 0 || is_null($strict)) { $this->save_dir = $value['save_dir']; } } } } //--------------------------------------------- if (!is_null($this->save_dir)) { $save_dir = $this->markup_CHK($this->save_dir); } $this->link_compile_file = new Compile_File(array("save_dir" => $this->save_dir, "forceDownload" => $this->forceDownload, "filePath" => $filePath, "src_content_type" => $this->codeType, "compilerGlobal" => $this->compilerGlobal, "compilePath" => $this->compilePath)); //--------------------------------------------- $this->content = $this->link_compile_file->content; //--------------------------------------------- $this->content = $this->removeComments($this->content); //--------------------------------------------- if (!is_null($this->compilerGlobal)) { $this->filesObj = $this->compilerGlobal->files_CHK($filePath); } //--------------------------------------------- if (!is_null($this->content)) { $this->src_path = $filePath; $this->src_path_local = $this->link_compile_file->filePath_local; $path = $this->removeModified($this->link_compile_file->save_path); $this->save_path = $path; $this->save_path_relative = $this->link_compile_file->save_path_relative; } //--------------------------------------------- if (!$this->ignoreIfExistInMatch_CHK()) { $replaceWith = $this->onRemoveMatch_CHK("link"); $this->output_updated = str_replace($this->match[0], $replaceWith, $this->output_updated); } }
public function file_CHK() { //----------------------------------------------------- $content = NULL; $getContent = true; //----------------------------------------------------- if (preg_match('/\\.(jpg|jpeg|png|gif)(?:[\\?\\#].*)?$/i', $this->filePath)) { $this->fileType = "image"; } //----------------------------------------------------- $filePath = explode("?", $this->filePath); $filePath = $filePath[0]; //----------------------------------------------------- if (strpos($filePath, "../") !== false) { $this->filePath_local = FileFolder::getParDirFromSrc($filePath, $this->url_local . $this->src_dir); //--------------------------------------------- if (FileFolder::file_exists($this->filePath_local)) { $this->exist = true; $this->content = $this->getContent($this->filePath_local); } //--------------------------------------------- $result = StringUtil::replaceOverlap($this->url_local, $this->filePath_local, "", "/"); //--------------------------------------------- if ($this->relativeToSrc && $this->exist) { $this->save_path = $this->compilePath . str_replace($this->url_local, "", $this->filePath_local); //----------------------------------------- if ($result['overlap'] != $this->url_local) { krumo($result); krumo($this->filePath_local . " cannot be saved outside of " . $this->compilePath . " ,'relativeToSrc' will be set to 'false'"); //----------------------------------------- $this->relativeToSrc = false; } } //--------------------------------------------- $filePath = str_replace($result["overlap"], "", $this->filePath_local); } else { if (strpos($filePath, "http://") !== false || strpos($filePath, "https://") !== false) { if (FileFolder::file_exists($filePath_local = GenFun::get_local_url($filePath))) { $this->filePath_local = $filePath_local; $this->content = $this->getContent($this->filePath_local); $this->filePath_local_relative = Compiler::cleanURL($this->filePath_local, ""); $filePath = !is_null($this->save_dir) ? basename($this->filePath_local_relative) : $this->filePath_local_relative; $this->exist = true; } else { if (CurlUtil::is_url_exist($this->filePath)) { $this->exist = true; if ($this->forceDownload) { $filePath = (!is_null($this->save_dir) ? "" : "global/forced/") . basename($filePath); $this->content = $this->getContent($this->filePath); $this->forced = true; } else { $this->link = Html::getExtLink($this->filePath); } } } } else { if (!is_null($this->src_save_dir) && $this->src_content_type == "css") { if (FileFolder::file_exists($this->filePath_local = (!is_null($this->src_dir) ? GenFun::get_local_url($this->src_dir) : $this->url_local) . $filePath)) { $this->exist = true; } $this->content = $this->getContent($this->filePath_local); if ($this->relativeToSrc) { $filePath = $this->src_save_dir . $filePath; } $this->save_path = $this->compilePath . $filePath; } else { if (FileFolder::file_exists($this->filePath_local = $this->url_local . $filePath)) { $this->content = $this->getContent($this->filePath_local); $filePath = $this->filePath; $this->exist = true; } } } } //------------------------------------------------- if (!$this->base64 || $this->fileType != "image") { if ($this->relativeToSrc && $this->src_content_type == "css") { $this->save_path_relative = $filePath; } else { if (!is_null($this->filePath_local)) { //--------------------------------------------- $this->save_path_relative = $this->get_savePath($filePath); $this->save_path = $this->compilePath . $this->save_path_relative; } else { //$this->save_path = $filePath; } } //------------------------------------------------- if ($this->relativeToSrc && !is_null($this->src_save_dir)) { $this->save_path_relative = StringUtil::pathRelativeToPath($this->save_path, $this->compilePath . $this->src_save_dir, "/", true); } } else { if ($this->fileType == "image") { $info = getimagesize($this->filePath_local); if ($info['mime'] == "image/png") { $this->base64_content = Image::compress_png($this->filePath_local, $this->quality, true); } else { if ($info['mime'] == "image/jpeg") { $this->base64_content = Image::compress_jpeg($this->filePath_local, $this->quality, true); } else { $this->base64_content = GenFun::fileToBase64($this->filePath_local, $info['mime']); } } } } //------------------------------------------------- if ($this->exist) { $this->src_content_updated = str_replace($this->filePath, !is_null($this->base64_content) ? $this->base64_content : $this->save_path_relative, $this->src_content); } else { $this->existCaseInsensitive = FileFolder::file_exists($this->filePath_local, false); array_push($this->compilerGlobal->notifications, array("existCaseInsensitive" => $this->existCaseInsensitive, "file" => $this->filePath)); } }
public function fileFromCrop() { //---------------------------------------------------------- //init var //---------------------------------------------------------- $chk = array("bool" => true, "func" => "fileFromCrop"); //---------------------------------------------------------- $this->src = urldecode($this->src); //---------------------------------------------------------- if (strrpos($this->src, "://") !== false) { $this->src = GenFun::get_local_url($this->src); } else { $this->src = Import::getImportPath() . $this->src; } //---------------------------------------------------------- clearstatcache(); //---------------------------------------------------------- if (!file_exists($this->src)) { $chk['bool'] = false; $chk['message'] = "{$this->src} does not exist"; return $chk; } //---------------------------------------------------------- $what = getimagesize($this->src); //---------------------------------------------------------- $ratio = $this->curWidth / $what[0]; $this->coor['w'] = $this->coor['w'] / $ratio; $this->coor['h'] = $this->coor['h'] / $ratio; //---------------------------------------------------------- $this->coor['x'] = $this->coor['x'] / $ratio; $this->coor['y'] = $this->coor['y'] / $ratio; //---------------------------------------------------------- if (is_null($this->width)) { $this->width = $this->coor['w']; } if (is_null($this->height)) { $this->height = $this->coor['h']; } //---------------------------------------------------------- $jpeg_quality = 100; //---------------------------------------------------------- if (is_null($this->src)) { $chk['bool'] = false; $chk['message'] = "src is undefined"; return $chk; } //---------------------------------------------------------- $name = explode("/", $this->src); $name = end($name); $name = substr($name, 0, -4); $name = str_replace(' ', '_', $name); //---------------------------------------------------------- switch (strtolower($what['mime'])) { case 'image/png': $img_r = imagecreatefrompng($this->src); $ext = ".png"; break; case 'image/jpeg': $img_r = imagecreatefromjpeg($this->src); $ext = ".jpg"; break; case 'image/gif': $img_r = imagecreatefromgif($this->src); $ext = ".gif"; break; case 'image/jpg': $img_r = imagecreatefromjpeg($this->src); $ext = ".jpg"; break; default: $chk['bool'] = false; $chk['message'] = "ext is not accepted!!!"; return $chk; } //---------------------------------------------------------- $dst_r = ImageCreateTrueColor($this->width, $this->height); //---------------------------------------------------------- imagecopyresampled($dst_r, $img_r, 0, 0, $this->coor['x'], $this->coor['y'], $this->width, $this->height, $this->coor['w'], $this->coor['h']); //---------------------------------------------------------- $hash = MySQL::getNextInsertID('files'); //---------------------------------------------------------- if (is_object($hash)) { return $hash; } //---------------------------------------------------------- $name = $name . "_crop" . $ext; //---------------------------------------------------------- $filePath = ProjectGlobal::$filesLocalPath . $name; //---------------------------------------------------------- header('Content-type: image/jpeg'); imagejpeg($dst_r, $filePath, $jpeg_quality); //---------------------------------------------------------- $filePath = FileFolder::moveToFolder($filePath, $hash . "/"); //---------------------------------------------------------- $chk['file'] = GenFun::get_full_url($filePath); $chk['rel'] = $filePath; $chk['src'] = $this->src; $chk['ratio'] = $ratio; $chk['result'] = Upload::insertFile($hash . "/" . $name); //---------------------------------------------------------- return $chk; }
public static function file_get_contents($file) { //krumo($filePath."||".$content."||".$const); if ($file[0] != "/" && strrpos($file, "https://") === false && strrpos($file, "http://") === false && strrpos($file, "www.") === false) { $file = GenFun::get_local_url($file); } return file_get_contents($file); }
function parse_match() { $index = array(); $num++; $txt = NULL; preg_match_all("/type(?:\\s|)=(?:\\s|)(?:[\\'\"])([\\-A-Za-z\\/_\\d\\.]+)(?:[\\'\"])/s", $this->match[3], $tmpl, PREG_SET_ORDER); if (isset($this->match[3]) && $this->match[3] != "") { preg_match("/src(?:\\s|)=(?:\\s|)[\\'\"](.*?)[\\'\"]/s", $this->match[3], $src); if (isset($src[1]) && $src[1] != "") { $filePath = $src[1]; $this->link_CFG($filePath); } } if (is_null($this->link_compile_file) && isset($this->match[4]) && $this->match[4] != "" && (sizeof($tmpl) == 0 || $tmpl[1] == "text/javascript")) { $this->content = $this->match[4]; $this->content = StringUtil::removeWhiteLines($this->content); //----------------------------------------------------- //krumo($this->content); //$this->content = StringUtil::removeAllJSComments($this->content); //krumo($this->content); //----------------------------------------------------- if ($this->getServices) { preg_match_all('/"([^\'"]*\\.(php)[\'"]?)"/', $txtNoComments, $php); if (sizeof($php[0]) > 0) { foreach ($php[1] as $service) { $bool = false; $service = MarkUp::go($service); if (strpos($service, "/") === false) { $service = Import::getImportPath() . $service; } $service = strpos($service, "http://") === false ? $service : GenFun::get_local_url($service); if (!is_null($this->getServices['except'])) { $bool = ArrayUtil::existIn($this->getServices['except'], $service, false); } if (file_exists($service) && !$bool) { $this->services[] = $service; } } } } } /*if (isset($this->match[4]) && $this->match[4] != "") { $filePath = $this->match[4]; $this->link_CFG($filePath); } else { $this->content = $this->match[5]; $this->content = StringUtil::removeWhiteLines($this->content); //----------------------------------------------------- //krumo($this->content); //$this->content = StringUtil::removeAllJSComments($this->content); //krumo($this->content); //----------------------------------------------------- if ($this->getServices) { preg_match_all('/"([^\'"]*\.(php)[\'"]?)"/', $txtNoComments, $php); if (sizeof($php[0]) > 0){ foreach ($php[1] as $service) { $bool = false; $service = MarkUp::go($service); if(strpos($service, "/") === false) $service = Import::getImportPath().$service; $service = (strpos($service, "http://") === false) ? $service : GenFun::get_local_url($service); if (!is_null($this->getServices['except'])) $bool = ArrayUtil::existIn($this->getServices['except'], $service, false); if (file_exists($service) && !$bool) $this->services[] = $service; } } } }*/ }
public static function createDependantFiles($content) { $arr = array(); $phpArr = array(); preg_match_all('~(["\'])([^"\']+)\\1~', $content, $arr); //---------------------------------------------------------- for ($i = 0; $i < sizeof($arr[0]); $i++) { $pos = strpos($arr[0][$i], ".php?"); //------------------------------------------------------ if (strpos($arr[0][$i], ".php") !== false) { if ($pos !== false) { $arr[0][$i] = substr($arr[0][$i], 0, $pos + 4); } //-------------------------------------------------- if (strpos($arr[0][$i], "{SERVICES_PATH}") !== false) { $arr[0][$i] = str_replace("{SERVICES_PATH}", Import::$uber_src_path . Constants::SERVICES_PATH, $arr[0][$i]); //$arr[0][$i] = $_SERVER["DOCUMENT_ROOT"].$arr[0][$i]; } else { //$arr[0][$i] = GenFun::get_local_url($arr[0][$i]); $arr[0][$i] = GenFun::get_local_url($_SERVER['HTTP_REFERER']) . $arr[0][$i]; $arr[0][$i] = StringUtil::removeQuotes($arr[0][$i]); } //-------------------------------------------------- array_push($phpArr, $arr[0][$i]); } } //---------------------------------------------------------- $phpArr = array_unique($phpArr); //---------------------------------------------------------- for ($i = 0; $i < sizeof($phpArr); $i++) { include_once $phpArr[$i]; } //print_r($phpArr); //krumo($included_files = get_included_files()); DupIncluded::go("Modules/", "min/"); }
public function uploadFile() { $upload = $this->uploadClass->post(false); if (is_null($upload["files"][0]->error)) { $local_url = urldecode(GenFun::get_local_url($upload['files'][0]->url)); //---------------------------------------------------------- $newName = str_replace(' ', '_', $upload["files"][0]->name); $arr = explode(".", $newName); $ext = $arr[sizeof($arr) - 1]; $newName = stripslashes($arr[0]); //---------------------------------------------------------- $newName = preg_replace('/[^a-z_0-9-]*/i', '', $newName); $newName = $newName . "_" . $this->getHash('files'); //---------------------------------------------------------- $arr = explode("/", $local_url); //---------------------------------------------------------- $new_local_url = str_replace($arr[sizeof($arr) - 1], $newName, $local_url); $new_local_url .= "." . $ext; //---------------------------------------------------------- rename($local_url, $new_local_url); //---------------------------------------------------------- $chk = $this->insertFile($newName . "." . $ext, json_encode($upload["files"])); //---------------------------------------------------------- if ($chk['bool']) { $chk['result'] = $upload; $chk['value'] = $chk['insert_id']; unset($chk['insert_id']); } } else { $chk = $upload; } return $chk; }
<?php require_once str_replace('//', '/', dirname(__FILE__) . '/') . "../utils/Import.php"; require_once Import::$uber_src_path . "server/werm/utils/GenFun.php"; $file = GenFun::get_local_url($_GET['url']); if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($file)); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); exit; } else { die("'{$file}' DOES NOT EXIST!!!"); }