From 4c9067bf7ae89b446bb0e236ab20c5b4fa3ee3e3 Mon Sep 17 00:00:00 2001 From: xue <> Date: Tue, 15 Nov 2005 15:34:38 +0000 Subject: Added a new template/theme syntax for URL support. --- framework/Web/TAssetManager.php | 50 +++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) (limited to 'framework/Web/TAssetManager.php') diff --git a/framework/Web/TAssetManager.php b/framework/Web/TAssetManager.php index 4bc52eed..b12bc4df 100644 --- a/framework/Web/TAssetManager.php +++ b/framework/Web/TAssetManager.php @@ -25,7 +25,7 @@ * By default, TAssetManager will not publish a file or directory if it already * exists in the publishing directory. You may require a timestamp checking by * setting CheckTimestamp to true (which is false by default). You may also require - * so when calling {@link publishFile} or {@link publishDirectory). This is usually + * so when calling {@link publishFilePath}. This is usually * very useful during development. In production sites, the timestamp checking * should be turned off to improve performance. * @@ -151,24 +151,36 @@ class TAssetManager extends TComponent implements IModule } /** - * Publishes a directory (recursively). + * Publishes a file or a directory (recursively). * This method will copy the content in a directory (recursively) to * a web accessible directory and returns the URL for the directory. * @param string the path to be published * @param boolean whether to use file modify time to ensure every published file is latest * @return string an absolute URL to the published directory */ - public function publishDirectory($path,$checkTimestamp=false) + public function publishFilePath($path,$checkTimestamp=false) { - if(($fullpath=realpath($path))!==false && is_dir($fullpath)) + if(($fullpath=realpath($path))===false) + throw new TInvalidDataValueException('assetmanager_filepath_invalid',$path); + else if(is_file($fullpath)) + { + $dir=md5(dirname($fullpath)); + $file=$this->_basePath.'/'.$dir.'/'.basename($fullpath); + + if(!is_file($file) || (($checkTimestamp || $this->_checkTimestamp) && filemtime($file)_basePath.'/'.$dir); + copy($fullpath,$file); + } + return $this->_baseUrl.'/'.$dir.'/'.basename($fullpath); + } + else { $dir=md5($fullpath); if(!is_dir($this->_basePath.'/'.$dir) || $checkTimestamp || $this->_checkTimestamp) $this->copyDirectory($fullpath,$this->_basePath.'/'.$dir); return $this->_baseUrl.'/'.$dir; } - else - throw new TInvalidDataValueException('assetmanager_directory_invalid',$path); } /** @@ -196,32 +208,6 @@ class TAssetManager extends TComponent implements IModule } closedir($folder); } - - /** - * Publishes a file. - * This method will copy a file to a web accessible directory and - * returns the URL for the file. - * @param string the file to be published - * @param boolean whether to use file modify time to ensure the published file is latest - * @return string an absolute URL to the published file - */ - public function publishFile($path,$checkTimestamp=false) - { - if(($fullpath=realpath($path))!==false && is_file($fullpath)) - { - $dir=md5(dirname($fullpath)); - $file=$this->_basePath.'/'.$dir.'/'.basename($fullpath); - - if(!is_file($file) || (($checkTimestamp || $this->_checkTimestamp) && filemtime($file)_basePath.'/'.$dir); - copy($fullpath,$file); - } - return $this->_baseUrl.'/'.$dir.'/'.basename($fullpath); - } - else - throw new TInvalidDataValueException('assetmanager_file_invalid',$path); - } } ?> \ No newline at end of file -- cgit v1.2.3