public static function getContents($src, $fileLocation) { //---------------------------------------------------------- //init var //---------------------------------------------------------- $chk = array("bool" => true, 'traceID' => "minJs"); //---------------------------------------------------------- $fileLocation = FileFolder::getPathFromFile($fileLocation); //---------------------------------------------------------- $arr = array_pop(explode(".", $src)); if ($arr == "php" || $arr == "js" || $arr == "css" || strpos($src, "js?") !== false || strpos($src, "fonts.googleapis.com") !== false) { if (file_get_contents($src) == "") { $chk['bool'] = false; if (file_get_contents($_SERVER["DOCUMENT_ROOT"] . $fileLocation . $src) == "") { $chk['bool'] = false; $chk['message'] = $src . " and " . $_SERVER["DOCUMENT_ROOT"] . $fileLocation . $src . " does not exist!!!"; } else { $chk['bool'] = true; $src = $_SERVER["DOCUMENT_ROOT"] . $fileLocation . $src; } } if (!$chk['bool']) { die(json_encode($chk)); } else { $code = file_get_contents($src); } } else { $code = $src; } return $code; }
public static function go($fileName, $content, $fileLocation, $force) { //---------------------------------------------------------- //init var //---------------------------------------------------------- $chk = array("bool" => true, "func" => "createFile"); //---------------------------------------------------------- $chk = GenFun::error_CHK(array('fileName' => $fileName, 'content' => $content)); //---------------------------------------------------------- if (!$chk['bool']) { return $chk; } //---------------------------------------------------------- $defaultLocation = $_SERVER["DOCUMENT_ROOT"]; //---------------------------------------------------------- if (substr($defaultLocation, -1) != "/") { $defaultLocation .= "/"; } //---------------------------------------------------------- $fileLocation = is_null($fileLocation) ? $defaultLocation : $defaultLocation . $fileLocation; //---------------------------------------------------------- if (!is_dir($fileLocation)) { if ($force) { $fileLocation = FileFolder::getPathFromFile($fileLocation); } //------------------------------------------ if (!is_dir($fileLocation)) { $chk['bool'] = false; $chk['message'] = $fileLocation . " directory does not exist"; return $chk; } } //---------------------------------------------------------- $file = $fileLocation . $fileName; //---------------------------------------------------------- DupIncluded::createFolderStructure($file); //---------------------------------------------------------- if (file_put_contents($file, $content)) { $chk['message'] = $file . " has been successfully created!!!!!"; } else { $chk['bool'] = false; $chk['message'] = $file . " was not saved or did not save properly."; } //---------------------------------------------------------- return $chk; }
public function getFiles($css, $srcPath) { $srcName = FileFolder::getFileName($srcPath); $newFolder = FileFolder::getPathFromFile($this->fileCss) . $srcName . "/"; //--------------------------------------------------------- $origSrcFolder = FileFolder::getPathFromFile($srcPath); //--------------------------------------------------------- preg_match_all('/(url\\(\\"|url\\(\'|url\\(|src=\')(.*?)(\\)|\'|\\")/s', $css, $files); //--------------------------------------------------------- foreach ($files[2] as $file_key => $origFilePath) { $fileAbPath = NULL; $newAbPath = NULL; $origFilePath = Compile::getBetweenQuot($origFilePath); //----------------------------------------------------- if (strpos($origFilePath, "../") !== false) { $goBack = explode("../", $origFilePath); $goBackAmt = sizeof($goBack); $srcFolderArr = explode("/", $origSrcFolder); $fileLocationArr = array_slice($srcFolderArr, 0, -$goBackAmt); $srcFolder = implode($fileLocationArr, "/") . "/"; $filePath = end($goBack); } else { $srcFolder = $origSrcFolder; $filePath = $origFilePath; if (strpos($filePath, "http://") !== false) { $fileAbPath = $filePath; $filePath = FileFolder::getFileName($filePath, false); $newFilePath = $newFolder . $filePath; } } //----------------------------------------------------- $filePath = FileFolder::getFileName($filePath, false, true); //----------------------------------------------------- if (is_null($fileAbPath)) { $fileAbPath = $srcFolder . $filePath; } if (is_null($newAbPath)) { $newAbPath = $newFolder . $filePath; } //----------------------------------------------------- $newFilePath = $srcName . "/" . $filePath; //----------------------------------------------------- if (file_exists(Import::uber_src_path() . $fileAbPath)) { $fileAbPath = Import::uber_src_path() . $fileAbPath; } //----------------------------------------------------- if ($fileContent = file_get_contents($fileAbPath)) { if (!file_get_contents($newAbPath)) { $css = str_replace($origFilePath, $newFilePath, $css); FileFolder::file_put_contents($newAbPath, $fileContent); FileFolder::file_put_contents(Compile::$unminifiedPath . $this->cleanURL($fileAbPath), $fileContent); } } } return $css; }
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 getImportPath($web = false) { $url = FileFolder::getPathFromFile($_SERVER["SCRIPT_FILENAME"]); return $web ? GenFun::get_full_url($url) : $url; }
public function getDownloadUrl() { return $this->downloadUrl = GenFun::get_full_url(FileFolder::getPathFromFile($_SERVER["SCRIPT_FILENAME"])) . "Download.php"; }
public static function fileExistInFolder($dir, $lookFor, $recursive = false) { $dir = FileFolder::getPathFromFile($dir); $files = array(); $arr = explode("/", $dir); $file_wType = NULL; $path = ""; //$_POST['hey'] = array(); //$_POST['hey']['dir'] = $dir; foreach ($arr as $value) { if ($value != "") { $path .= "/" . $value; if (strpos($path, $_ENV["werm_root"]) !== false) { foreach ($lookFor as $lookFor_file) { if (FileFolder::file_exists($file = $path . "/" . $lookFor_file)) { array_push($files, $file); //break; } } } } } return $files; }
public static function dupIncluded($append = "", $root, $except, $strict = false) { $included_files = get_included_files(); foreach ($included_files as $filename) { $bool = true; if (strpos($filename, ($string = Import::$uber_src_path) . $append) !== false && !$strict || $strict && ($string = Import::$uber_src_path) . $append == FileFolder::getPathFromFile($filename)) { foreach ($except as $value) { if (strpos($filename, $value) !== false) { $bool = false; break; } } //-------------------------------------------------- if ($bool) { /*$txt = file_get_contents($filename); $txt = StringUtil::removeAllComments($txt); preg_match_all('/(Import::|"|\')(.*?)php("|\')/', $txt, $matches); krumo($matches);*/ $copy = str_replace($string, $root, $filename); self::file_put_contents($copy, file_get_contents($filename)); } } } }
public static function extract($file, $extractToPath = NULL) { if (is_null($extractToPath)) { $extractToPath = FileFolder::getPathFromFile($file); } FileFolder::createFolderStructure($extractToPath); $zip = new ZipArchive(); if ($zip->open($file) === TRUE) { $zip->extractTo($extractToPath); $zip->close(); } }