コード例 #1
0
ファイル: Compile_File.php プロジェクト: awwthentic1234/hey
 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));
     }
 }