From d9f2cd39ecbc0249b7614a17ce4a575f1ce8aa7d Mon Sep 17 00:00:00 2001 From: xue <> Date: Fri, 17 Feb 2006 01:08:16 +0000 Subject: Merged TTarAssetManager into TAssetManager. --- framework/Web/TAssetManager.php | 132 ++++++++++++++++++---- framework/Web/UI/TTarAssetManager.php | 74 ------------ framework/Web/UI/WebControls/THtmlArea.php | 68 ++++++----- framework/Web/UI/WebControls/TTextHighlighter.php | 2 +- 4 files changed, 147 insertions(+), 129 deletions(-) delete mode 100644 framework/Web/UI/TTarAssetManager.php (limited to 'framework/Web') diff --git a/framework/Web/TAssetManager.php b/framework/Web/TAssetManager.php index 5c3fbc60..fedec61f 100644 --- a/framework/Web/TAssetManager.php +++ b/framework/Web/TAssetManager.php @@ -137,6 +137,10 @@ class TAssetManager extends TModule $this->_baseUrl=rtrim($value,'/'); } + /** + * @param string file path + * @return string the URL to the published file path. Null if the file is not published. + */ public function getPublishedUrl($path) { if(($fullpath=realpath($path))!==false) @@ -149,41 +153,60 @@ class TAssetManager extends TModule return null; } - public function isPublished($path) + /** + * @param string file path + * @return boolean whether the specified file path is published or not + */ + public function isFilePathPublished($path,$checkTimestamp=false) { - return $this->getPublishedUrl($path) !== null; + if(!isset($this->_published[$path])) + { + if(($fullpath=realpath($path))===false) + return false; + $dir=$this->hash(dirname($fullpath)); + $file=$this->_basePath.'/'.$dir.'/'.basename($fullpath); + if($checkTimestamp || $this->getApplication()->getMode()!==TApplication::STATE_PERFORMANCE) + { + if(is_file($fullpath)) + return @filemtime($fullpath)<=@filemtime($file); + else + { + } + } + else + return is_file($file) || is_dir($file); + } + else + return true; } /** * 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. + * If the application is not in performance mode, the file modification + * time will be used to make sure the published file is latest or not. + * If not, a file copy will be performed. * @param string the path to be published - * @param boolean whether to use file modify time to ensure every published file is latest + * @param boolean If true, file modification time will be checked even if the application + * is in performance mode. * @return string an absolute URL to the published directory + * @throw TInvalidDataValueException if the file path to be published is invalid */ public function publishFilePath($path,$checkTimestamp=false) { if(isset($this->_published[$path])) return $this->_published[$path]; else if(($fullpath=realpath($path))===false) - return ''; + throw new TInvalidDataValueException('assetmanager_filepath_invalid',$path); else if(is_file($fullpath)) { $dir=$this->hash(dirname($fullpath)); - $file=$this->_basePath.'/'.$dir.'/'.basename($fullpath); - if(!is_file($file) || $checkTimestamp || $this->getApplication()->getMode()!==TApplication::STATE_PERFORMANCE) - { - if(!is_dir($this->_basePath.'/'.$dir)) - @mkdir($this->_basePath.'/'.$dir); - if(!is_file($file) || @filemtime($file)<@filemtime($fullpath)) - { - Prado::trace("Publishing file $fullpath",'System.Web.UI.TAssetManager'); - @copy($fullpath,$file); - } - } - $this->_published[$path]=$this->_baseUrl.'/'.$dir.'/'.basename($fullpath); - return $this->_published[$path]; + $fileName=basename($fullpath); + $dst=$this->_basePath.'/'.$dir; + if(!is_file($dst.'/'.$fileName) || $checkTimestamp || $this->getApplication()->getMode()!==TApplication::STATE_PERFORMANCE) + $this->copyFile($fullpath,$dst); + return $this->_published[$path]=$this->_baseUrl.'/'.$dir.'/'.$fileName; } else { @@ -193,8 +216,7 @@ class TAssetManager extends TModule Prado::trace("Publishing directory $fullpath",'System.Web.UI.TAssetManager'); $this->copyDirectory($fullpath,$this->_basePath.'/'.$dir); } - $this->_published[$path]=$this->_baseUrl.'/'.$dir; - return $this->_published[$path]; + return $this->_published[$path]=$this->_baseUrl.'/'.$dir; } } @@ -209,6 +231,25 @@ class TAssetManager extends TModule return sprintf('%x',crc32($dir)); } + /** + * Copies a file to a directory. + * Copying is done only when the destination file does not exist + * or has an older file modification time. + * @param string source file path + * @param string destination directory (if not exists, it will be created) + */ + protected function copyFile($src,$dst) + { + if(!is_dir($dst)) + @mkdir($dst); + $dstFile=$dst.'/'.basename($src); + if(@filemtime($dstFile)<@filemtime($src)) + { + Prado::trace("Publishing file $src to $dstFile",'System.Web.TAssetManager'); + @copy($src,$dstFile); + } + } + /** * Copies a directory recursively as another. * If the destination directory does not exist, it will be created. @@ -235,6 +276,59 @@ class TAssetManager extends TModule } closedir($folder); } + + /** + * Publish a tar file by extracting its contents to the assets directory. + * Each tar file must be accomplished with its own MD5 check sum file. + * The MD5 file is published when the tar contents are successfully + * extracted to the assets directory. The presence of the MD5 file + * as published asset assumes that the tar file has already been extracted. + * @param string tar filename + * @param string MD5 checksum for the corresponding tar file. + * @return string URL path to the directory where the tar file was extracted. + */ + public function publishTarFile($tarfile, $md5sum, $checkTimestamp=false) + { + if(isset($this->_published[$md5sum])) + return $this->_published[$md5sum]; + else if(($fullpath=realpath($md5sum))===false) + throw new TInvalidDataValueException('assetmanager_tarchecksum_invalid',$md5sum); + else + { + $dir=$this->hash(dirname($fullpath)); + $fileName=basename($fullpath); + $dst=$this->_basePath.'/'.$dir; + if(!is_file($dst.'/'.$fileName) || $checkTimestamp || $this->getApplication()->getMode()!==TApplication::STATE_PERFORMANCE) + { + if(@filemtime($dst.'/'.$fileName)<@filemtime($fullpath)) + { + $this->copyFile($fullpath,$dst); + $this->deployTarFile($tarfile,$dst); + } + } + return $this->_published[$md5sum]=$this->_baseUrl.'/'.$dir; + } + } + + /** + * Extracts the tar file to the destination directory. + * N.B Tar file must not be compressed. + * @param string tar file + * @param string path where the contents of tar file are to be extracted + * @return boolean true if extract successful, false otherwise. + */ + protected function deployTarFile($path,$destination) + { + if(($fullpath=realpath($path))===false) + throw new TIOException('assetmanager_tarfile_invalid',$path); + else + { + Prado::using('System.Data.TTarFileExtractor'); + $tar = new TTarFileExtractor($fullpath); + return $tar->extract($destination); + } + } + } ?> \ No newline at end of file diff --git a/framework/Web/UI/TTarAssetManager.php b/framework/Web/UI/TTarAssetManager.php deleted file mode 100644 index 4a05891e..00000000 --- a/framework/Web/UI/TTarAssetManager.php +++ /dev/null @@ -1,74 +0,0 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Revision: $ $Date: $ - * @package System.Web.UI - */ - -/** - * TTarAssetDeployer class. - * Publish a tar file by extracting its contents to the assets directory. - * Each tar file must be accomplished with its own MD5 check sum file. - * The MD5 file is published when the tar contents are successfully - * extracted to the assets directory. The presence of the MD5 file - * as published asset assumes that the tar file has already been extracted. - * - * Compressed tar files are not supported. - * - * @author Wei Zhuo - * @version $Revision: $ $Date: $ - * @package System.Web.UI - * @since 3.0 - */ -class TTarAssetManager extends TAssetManager -{ - /** - * Publish a tar file by extracting its contents to the assets directory. - * Each tar file must be accomplished with its own MD5 check sum file. - * The MD5 file is published when the tar contents are successfully - * extracted to the assets directory. The presence of the MD5 file - * as published asset assumes that the tar file has already been extracted. - * @param string tar filename - * @param string MD5 checksum for the corresponding tar file. - * @return string URL path to the directory where the tar file was extracted. - */ - public function publishTarFile($tarfile, $md5sum) - { - //if md5 file is published assume tar asset deployed - if(($md5Path = $this->getPublishedUrl($md5sum)) != null) - return dirname($md5Path); - - if(($fullpath=realpath($tarfile))===false) - throw new TIOException('unable_to_locate_tar_file', $tarfile); - else if(is_file($fullpath)) - { - $dir=$this->hash(dirname($fullpath)); - $destination = $this->getBasePath().'/'.$dir.'/'; - if($this->deployTarFile($fullpath, $destination)) - return dirname($this->publishFilePath($md5sum)); - } - - throw new TIOException('unable_to_publish_tar_file', $tarfile); - } - - /** - * Extracts the tar file to the destination directory. - * N.B Tar file must not be compressed. - * @param string tar file - * @param string path where the contents of tar file are to be extracted - * @return boolean true if extract successful, false otherwise. - */ - protected function deployTarFile($fullpath,$destination) - { - Prado::using('System.Data.TTarFileExtractor'); - $tar = new TTarFileExtractor($fullpath); - return $tar->extract($destination); - } -} - -?> \ No newline at end of file diff --git a/framework/Web/UI/WebControls/THtmlArea.php b/framework/Web/UI/WebControls/THtmlArea.php index eb2c452f..d858a90f 100644 --- a/framework/Web/UI/WebControls/THtmlArea.php +++ b/framework/Web/UI/WebControls/THtmlArea.php @@ -17,19 +17,19 @@ * TinyMCE project {@link http://tinymce.moxiecode.com/}. * * THtmlArea displays a WYSIWYG text area on the Web page for user input - * in the HTML format. The text displayed in the THtmlArea component is + * in the HTML format. The text displayed in the THtmlArea component is * specified or determined by using the Text property. * * To enable the visual editting on the client side, set the property * EnableVisualEdit to true (which is default value). - * To set the size of the editor when the visual editting is enabled, + * To set the size of the editor when the visual editting is enabled, * set the Width and Height properties instead of * Columns and Rows because the latter has no meaning * under the situation. * * The default editor gives only the basic tool bar. To change or add * additional tool bars, use the Options property add to additional - * editor options with each options on a new line. + * editor options with each options on a new line. * See http://tinymce.moxiecode.com/tinymce/docs/index.html * for a list of options. The options can be change/added as shown in the * following example. @@ -43,11 +43,11 @@ * * * Compatibility - * The client-side visual editting capability is supported by - * Internet Explorer 5.0+ for Windows and Gecko-based browser. + * The client-side visual editting capability is supported by + * Internet Explorer 5.0+ for Windows and Gecko-based browser. * If the browser does not support the visual editting, * a traditional textarea will be displayed. - * + * * Browser support * * @@ -65,7 +65,7 @@ * * (1) - Partialy working * ---------------------------------------------------- * - * + * * @author Wei Zhuo * @version $Revision: $ $Date: $ * @package System.Web.UI.WebControls @@ -74,44 +74,44 @@ class THtmlArea extends TTextBox { protected $langs = array( - 'da' => array('da'), - 'fa' => array('fa'), + 'da' => array('da'), + 'fa' => array('fa'), 'hu' => array('hu'), 'nb' => array('nb'), 'pt_br' => array('pt_BR'), - 'sk' => array('sk'), + 'sk' => array('sk'), 'zh_tw_utf8' => array('zh_TW', 'zh_HK'), 'ar' => array('ar'), 'de' => array('de'), 'fi' => array('fi'), - 'is' => array('is'), - 'nl' => array('nl'), + 'is' => array('is'), + 'nl' => array('nl'), 'sv' => array('sv'), - 'ca' => array('ca'), - 'el' => array('el'), - 'fr' => array('fr'), - 'it' => array('it'), + 'ca' => array('ca'), + 'el' => array('el'), + 'fr' => array('fr'), + 'it' => array('it'), 'nn' => array('nn'), //what is nn? -// 'ru' => array('ru'), +// 'ru' => array('ru'), 'th' => array('th'), - 'cs' => array('cs'), - 'en' => array('en'), - 'fr_ca' => array('fr_CA'), + 'cs' => array('cs'), + 'en' => array('en'), + 'fr_ca' => array('fr_CA'), 'ja' => array('ja'), - 'pl' => array('pl'), + 'pl' => array('pl'), // 'ru_KOI8-R' => array('ru'), /// what is this? 'zh_cn' => array('zh_CN'), 'cy' => array('cy'), //what is this? - 'es' => array('es'), - 'he' => array('he'), + 'es' => array('es'), + 'he' => array('he'), 'ko' => array('ko'), - 'pt' => array('pt'), + 'pt' => array('pt'), 'ru_UTF-8' => array('ru'), 'tr' => array('tr'), 'si' => array('si'), // 'zh_tw' => array('zh_TW'), ); - + /** * Overrides the parent implementation. * TextMode for THtmlArea control is always 'MultiLine' @@ -235,7 +235,7 @@ class THtmlArea extends TTextBox /** * Adds attribute name-value pairs to renderer. - * This method overrides the parent implementation by registering + * This method overrides the parent implementation by registering * additional javacript code. * @param THtmlWriter the writer used for the rendering purpose */ @@ -248,7 +248,7 @@ class THtmlArea extends TTextBox $this->getStyle()->setWidth($width); if(($height=$this->getHeight()) != '') $this->getStyle()->setHeight($height); - + $this->registerEditorClientScript($writer); } parent::addAttributesToRender($writer); @@ -277,22 +277,20 @@ class THtmlArea extends TTextBox } /** - * Gets the editor script base URL by publishing the tarred source via TTarAssetManager. + * Gets the editor script base URL by publishing the tarred source via TTarAssetManager. * @return string URL base path to the published editor script */ protected function getScriptDeploymentPath() { - $manager = Prado::createComponent('System.Web.UI.TTarAssetManager'); - $manager->init(null); $tarfile = Prado::getPathOfNamespace('System.3rdParty.TinyMCE.tiny_mce', '.tar'); $md5sum = Prado::getPathOfNamespace('System.3rdParty.TinyMCE.tiny_mce', '.md5'); - return $manager->publishTarFile($tarfile, $md5sum); + return $this->getApplication()->getAssetManager()->publishTarFile($tarfile, $md5sum); } /** * Default editor options gives basic tool bar only. * @return array editor initialization options. - */ + */ protected function getEditorOptions() { $options['mode'] = 'exact'; @@ -332,8 +330,8 @@ class THtmlArea extends TTextBox * @return string localized editor interface language extension. */ protected function getLanguageSuffix($culture) - { - $app = $this->getApplication()->getGlobalization(); + { + $app = $this->getApplication()->getGlobalization(); if(empty($culture) && !is_null($app)) $culture = $app->getCulture(); $variants = array(); @@ -352,7 +350,7 @@ class THtmlArea extends TTextBox return $js; } } - + return 'en'; } } diff --git a/framework/Web/UI/WebControls/TTextHighlighter.php b/framework/Web/UI/WebControls/TTextHighlighter.php index 281f131e..22717d05 100644 --- a/framework/Web/UI/WebControls/TTextHighlighter.php +++ b/framework/Web/UI/WebControls/TTextHighlighter.php @@ -85,7 +85,7 @@ class TTextHighlighter extends TWebControl { parent::onPreRender($writer); $this->registerHighlightStyleSheet(); - $this->getPage()->getClientScript()->registerClientScript('prado'); + //$this->getPage()->getClientScript()->registerClientScript('prado'); } /** -- cgit v1.2.3