public function publishAssetFolder($fullLocalPath,$version="")
    {
        $fullLocalPath = Utility::standardizePathSeparator($fullLocalPath);
        $fullLocalPath = Utility::getSymbolicPath($fullLocalPath);
        $assets = Utility::get($this->report->getSettings(), "assets");
        
        $document_root = Utility::getDocumentRoot();
        
        $assetUrl = "";

        if (!$assets) {
            $assetUrl = str_replace($document_root, "", $fullLocalPath);
            if ($assetUrl==$fullLocalPath) {
                /**
                 * Happens when koolreport library is not within document root
                 * setup assets settings that move to the script folder
                 */

                $script_folder = Utility::standardizePathSeparator(
                    realpath(dirname($_SERVER["SCRIPT_FILENAME"]))
                );
                $asset_path = $script_folder."/koolreport_assets";            
                $asset_url = Utility::str_replace_first(
                    $document_root,
                    "",
                    $script_folder
                )."/koolreport_assets";
                if (!is_dir($asset_path)) {
                    mkdir($asset_path, 0755);
                }
                $assets = array(
                    "path"=>$asset_path,
                    "url"=>$asset_url,
                );
                $assetUrl = "";
            }
        }

        if ($assets) {
            $targetAssetPath =  Utility::get($assets, "path");
            $targetAssetUrl = Utility::get($assets, "url");
            if (!$targetAssetPath) {
                throw new \Exception("Could not find path to report's assets folder");
            }
            $reportClassFolder = Utility::standardizePathSeparator(
                dirname(Utility::getClassPath($this->report))
            );

            if (strpos($targetAssetPath, "/")!== 0
                && is_dir($reportClassFolder."/".$targetAssetPath)
            ) {
                //Check if relative targetAssetPath existed
                $targetAssetPath = Utility::standardizePathSeparator(
                    realpath($reportClassFolder."/".$targetAssetPath)
                );
            } else if (is_dir($targetAssetPath)) {
                //Check if full targetAssetPath existed
                $targetAssetPath = Utility::standardizePathSeparator(
                    realpath($targetAssetPath)
                );
            } else {
                throw new \Exception("Report's assets folder not existed");
            }
            //-----------------------

            $objectFolderName = str_replace(
                dirname($fullLocalPath)."/",
                "",
                $fullLocalPath
            );
            
            $objectHashFolderName = crc32(
                "koolreport"
                .$fullLocalPath
                .@filemtime($fullLocalPath)
                .$this->report->version().$version
            );
            $objectHashFolderName = ($objectHashFolderName<0)
                ?abs($objectHashFolderName)."0"
                :"$objectHashFolderName";
            //-------------------------

            $objectTargetPath = $targetAssetPath."/".$objectHashFolderName;
            if (!is_dir($objectTargetPath)) {
                Utility::recurse_copy($fullLocalPath, $objectTargetPath);
            } else {
                //Do the check if file in widgetSourceAssetPath is changed,
                //If there is then copy again.
                //Currently do nothing for now
            }
            
            if ($targetAssetUrl) {
                $assetUrl = $targetAssetUrl."/".$objectHashFolderName;
            } else {
                $assetUrl = str_replace($document_root, "", $objectTargetPath);
            }
        }

        return $assetUrl;
    }
public function publishAssetFolder($fullLocalPath,$version="")
    {
        $fullLocalPath = Utility::standardizePathSeparator($fullLocalPath);
        $fullLocalPath = Utility::getSymbolicPath($fullLocalPath);
        $assets = Utility::get($this->report->getSettings(), "assets");
        
        $document_root = Utility::getDocumentRoot();
        
        $assetUrl = "";

        if (!$assets) {
            $assetUrl = str_replace($document_root, "", $fullLocalPath);
            if ($assetUrl==$fullLocalPath) {
                /**
                 * Happens when koolreport library is not within document root
                 * setup assets settings that move to the script folder
                 */

                $script_folder = Utility::standardizePathSeparator(
                    realpath(dirname($_SERVER["SCRIPT_FILENAME"]))
                );
                $asset_path = $script_folder."/koolreport_assets";            
                $asset_url = Utility::str_replace_first(
                    $document_root,
                    "",
                    $script_folder
                )."/koolreport_assets";
                if (!is_dir($asset_path)) {
                    mkdir($asset_path, 0755);
                }
                $assets = array(
                    "path"=>$asset_path,
                    "url"=>$asset_url,
                );
                $assetUrl = "";
            }
        }

        if ($assets) {
            $targetAssetPath =  Utility::get($assets, "path");
            $targetAssetUrl = Utility::get($assets, "url");
            if (!$targetAssetPath) {
                throw new \Exception("Could not find path to report's assets folder");
            }
            $reportClassFolder = Utility::standardizePathSeparator(
                dirname(Utility::getClassPath($this->report))
            );

            if (strpos($targetAssetPath, "/")!== 0
                && is_dir($reportClassFolder."/".$targetAssetPath)
            ) {
                //Check if relative targetAssetPath existed
                $targetAssetPath = Utility::standardizePathSeparator(
                    realpath($reportClassFolder."/".$targetAssetPath)
                );
            } else if (is_dir($targetAssetPath)) {
                //Check if full targetAssetPath existed
                $targetAssetPath = Utility::standardizePathSeparator(
                    realpath($targetAssetPath)
                );
            } else {
                throw new \Exception("Report's assets folder not existed");
            }
            //-----------------------

            $objectFolderName = str_replace(
                dirname($fullLocalPath)."/",
                "",
                $fullLocalPath
            );
            
            $objectHashFolderName = crc32(
                "koolreport"
                .$fullLocalPath
                .@filemtime($fullLocalPath)
                .$this->report->version().$version
            );
            $objectHashFolderName = ($objectHashFolderName<0)
                ?abs($objectHashFolderName)."0"
                :"$objectHashFolderName";
            //-------------------------

            $objectTargetPath = $targetAssetPath."/".$objectHashFolderName;
            if (!is_dir($objectTargetPath)) {
                Utility::recurse_copy($fullLocalPath, $objectTargetPath);
            } else {
                //Do the check if file in widgetSourceAssetPath is changed,
                //If there is then copy again.
                //Currently do nothing for now
            }
            
            if ($targetAssetUrl) {
                $assetUrl = $targetAssetUrl."/".$objectHashFolderName;
            } else {
                $assetUrl = str_replace($document_root, "", $objectTargetPath);
            }
        }

        return $assetUrl;
    }
public function publishAssetFolder ( $ fullLocalPath , $ version = "" ) { $ fullLocalPath = Utility :: standardizePathSeparator ( $ fullLocalPath ) ; $ fullLocalPath = Utility :: getSymbolicPath ( $ fullLocalPath ) ; $ assets = Utility :: get ( $ this -> report -> getSettings ( ) , "assets" ) ; $ document_root = Utility :: getDocumentRoot ( ) ; $ assetUrl = "" ; if ( ! $ assets ) { $ assetUrl = str_replace ( $ document_root , "" , $ fullLocalPath ) ; if ( $ assetUrl == $ fullLocalPath ) { /**
                 * Happens when koolreport library is not within document root
                 * setup assets settings that move to the script folder
                 */ $ script_folder = Utility :: standardizePathSeparator ( realpath ( dirname ( $ _SERVER [ "SCRIPT_FILENAME" ] ) ) ) ; $ asset_path = $ script_folder . "/koolreport_assets" ; $ asset_url = Utility :: str_replace_first ( $ document_root , "" , $ script_folder ) . "/koolreport_assets" ; if ( ! is_dir ( $ asset_path ) ) { mkdir ( $ asset_path , 0755 ) ; } $ assets = array ( "path" => $ asset_path , "url" => $ asset_url , ) ; $ assetUrl = "" ; } } if ( $ assets ) { $ targetAssetPath = Utility :: get ( $ assets , "path" ) ; $ targetAssetUrl = Utility :: get ( $ assets , "url" ) ; if ( ! $ targetAssetPath ) { throw new \ Exception ( "Could not find path to report's assets folder" ) ; } $ reportClassFolder = Utility :: standardizePathSeparator ( dirname ( Utility :: getClassPath ( $ this -> report ) ) ) ; if ( strpos ( $ targetAssetPath , "/" ) !== 0 && is_dir ( $ reportClassFolder . "/" . $ targetAssetPath ) ) { //Check if relative targetAssetPath existed $ targetAssetPath = Utility :: standardizePathSeparator ( realpath ( $ reportClassFolder . "/" . $ targetAssetPath ) ) ; } else if ( is_dir ( $ targetAssetPath ) ) { //Check if full targetAssetPath existed $ targetAssetPath = Utility :: standardizePathSeparator ( realpath ( $ targetAssetPath ) ) ; } else { throw new \ Exception ( "Report's assets folder not existed" ) ; } //----------------------- $ objectFolderName = str_replace ( dirname ( $ fullLocalPath ) . "/" , "" , $ fullLocalPath ) ; $ objectHashFolderName = crc32 ( "koolreport" . $ fullLocalPath . @ filemtime ( $ fullLocalPath ) . $ this -> report -> version ( ) . $ version ) ; $ objectHashFolderName = ( $ objectHashFolderName < 0 ) ? abs ( $ objectHashFolderName ) . "0" : "$objectHashFolderName" ; //------------------------- $ objectTargetPath = $ targetAssetPath . "/" . $ objectHashFolderName ; if ( ! is_dir ( $ objectTargetPath ) ) { Utility :: recurse_copy ( $ fullLocalPath , $ objectTargetPath ) ; } else { //Do the check if file in widgetSourceAssetPath is changed, //If there is then copy again. //Currently do nothing for now } if ( $ targetAssetUrl ) { $ assetUrl = $ targetAssetUrl . "/" . $ objectHashFolderName ; } else { $ assetUrl = str_replace ( $ document_root , "" , $ objectTargetPath ) ; } } return $ assetUrl ; }
Copy private asset folder to public place and return public asset url

@param string $fullLocalPath Full local path to the asset folder
@param string $version       Version of the asset folder, normally
it is the version of widget

@return string The public url to asset folder
Copy private asset folder to public place and return public asset url