From 1bbff5ec853ae88cdfe1446d22c06a87fe305c0f Mon Sep 17 00:00:00 2001 From: xue <> Date: Thu, 8 Dec 2005 17:51:08 +0000 Subject: --- .gitattributes | 1 + demos/controls/themes/BlueTheme/simple.css | 1 + framework/Web/THttpUtility.php | 8 +-- framework/Web/UI/TClientScriptManager.php | 93 ++++++++++++++++++++++++++++-- framework/Web/UI/TPage.php | 11 ++++ framework/Web/UI/TThemeManager.php | 44 ++++++++++---- framework/Web/UI/WebControls/THead.php | 72 +++-------------------- 7 files changed, 145 insertions(+), 85 deletions(-) create mode 100644 demos/controls/themes/BlueTheme/simple.css diff --git a/.gitattributes b/.gitattributes index f5e0de8c..83dde48a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -16,6 +16,7 @@ demos/controls/protected/pages/private/config.xml -text demos/controls/themes/BlueTheme/buttons.skin -text demos/controls/themes/BlueTheme/icon_profile.gif -text demos/controls/themes/BlueTheme/labels.skin -text +demos/controls/themes/BlueTheme/simple.css -text demos/personal/index.php -text demos/personal/protected/Modules/DataModule.php -text demos/personal/protected/Pages/HomePage.php -text diff --git a/demos/controls/themes/BlueTheme/simple.css b/demos/controls/themes/BlueTheme/simple.css new file mode 100644 index 00000000..22df4a9e --- /dev/null +++ b/demos/controls/themes/BlueTheme/simple.css @@ -0,0 +1 @@ +body {background-color: silver;} \ No newline at end of file diff --git a/framework/Web/THttpUtility.php b/framework/Web/THttpUtility.php index 8951cbe7..c3ef2b4c 100644 --- a/framework/Web/THttpUtility.php +++ b/framework/Web/THttpUtility.php @@ -2,7 +2,7 @@ class THttpUtility { - private static $entityTable=null; + private static $_entityTable=null; public static function htmlEncode($s) { @@ -11,14 +11,14 @@ class THttpUtility public static function htmlDecode($s) { - if(!self::$entityTable) + if(!self::$_entityTable) self::buildEntityTable(); - return strtr($s,self::$entityTable); + return strtr($s,self::$_entityTable); } private static function buildEntityTable() { - self::$entityTable=array_flip(get_html_translation_table(HTML_ENTITIES,ENT_QUOTES)); + self::$_entityTable=array_flip(get_html_translation_table(HTML_ENTITIES,ENT_QUOTES)); } public static function quoteJavaScriptString($js,$forUrl=false) diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php index e42a0b20..0701a245 100644 --- a/framework/Web/UI/TClientScriptManager.php +++ b/framework/Web/UI/TClientScriptManager.php @@ -79,6 +79,10 @@ class TClientScriptManager extends TComponent private $_beginScripts=array(); private $_endScripts=array(); private $_scriptFiles=array(); + private $_headScriptFiles=array(); + private $_headScripts=array(); + private $_styleSheetFiles=array(); + private $_styleSheets=array(); private $_onSubmitStatements=array(); private $_arrayDeclares=array(); private $_expandoAttributes=array(); @@ -97,7 +101,10 @@ class TClientScriptManager extends TComponent if(!$options || (!$options->getPerformValidation() && !$options->getTrackFocus() && $options->getClientSubmit() && $options->getActionUrl()=='')) { $this->registerPostBackScript(); - $formID=$this->_page->getForm()->getClientID(); + if(($form=$this->_page->getForm())!==null) + $formID=$form->getClientID(); + else + throw new TInvalidConfigurationException('clientscriptmanager_form_required'); $postback=self::POSTBACK_FUNC.'(\''.$formID.'\',\''.$control->getUniqueID().'\',\''.THttpUtility::quoteJavaScriptString($parameter).'\')'; if($options && $options->getAutoPostBack()) $postback='setTimeout(\''.THttpUtility::quoteJavaScriptString($postback).'\',0)'; @@ -146,7 +153,10 @@ class TClientScriptManager extends TComponent if(!$flag) return ''; $this->registerPostBackScript(); - $formID=$this->_page->getForm()->getUniqueID(); + if(($form=$this->_page->getForm())!==null) + $formID=$form->getClientID(); + else + throw new TInvalidConfigurationException('clientscriptmanager_form_required'); $postback=self::POSTBACK_FUNC.'(\''.$formID.'\',\''.$control->getUniqueID().'\',\''.THttpUtility::quoteJavaScriptString($parameter).'\''.$opt.')'; if($options && $options->getAutoPostBack()) $postback='setTimeout(\''.THttpUtility::quoteJavaScriptString($postback).'\',0)'; @@ -213,9 +223,9 @@ class TClientScriptManager extends TComponent return isset($this->_hiddenFields[$key]); } - public function isScriptBlockRegistered($key) + public function isScriptRegistered($key) { - return isset($this->_scriptBlocks[$key]); + return isset($this->_scripts[$key]); } public function isScriptFileRegistered($key) @@ -233,6 +243,26 @@ class TClientScriptManager extends TComponent return isset($this->_endScripts[$key]); } + public function isHeadScriptFileRegistered($key) + { + return isset($this->_headScriptFiles[$key]); + } + + public function isHeadScriptRegistered($key) + { + return isset($this->_headScripts[$key]); + } + + public function isStyleSheetFileRegistered($key) + { + return isset($this->_styleSheetFiles[$key]); + } + + public function isStyleSheetRegistered($key) + { + return isset($this->_styleSheets[$key]); + } + public function isOnSubmitStatementRegistered($key) { return isset($this->_onSubmitStatements[$key]); @@ -268,6 +298,26 @@ class TClientScriptManager extends TComponent $this->_endScripts[$key]=$script; } + public function registerHeadScriptFile($key,$url) + { + $this->_headScriptFiles[$key]=$url; + } + + public function registerHeadScript($key,$script) + { + $this->_headScripts[$key]=$script; + } + + public function registerStyleSheetFile($key,$url) + { + $this->_styleSheetFiles[$key]=$url; + } + + public function registerStyleSheet($key,$css) + { + $this->_styleSheets[$key]=$css; + } + public function registerExpandoAttribute($controlID,$name,$value) { $this->_expandoAttributes[$controlID][$name]=$value; @@ -287,8 +337,10 @@ class TClientScriptManager extends TComponent public function renderScriptFiles($writer) { + $str=''; foreach($this->_scriptFiles as $include) - $writer->write("\n"); + $str.="\n"; + $writer->write($str); } public function renderOnSubmitStatements($writer) @@ -341,6 +393,36 @@ class TClientScriptManager extends TComponent } } + public function renderHeadScriptFiles($writer) + { + $str=''; + foreach($this->_styleSheetFiles as $url) + $str.="\n"; + $writer->write($str); + } + + public function renderHeadScripts($writer) + { + if(count($this->_headScripts)) + $writer->write("\n"); + } + + public function renderStyleSheetFiles($writer) + { + $str=''; + foreach($this->_styleSheetFiles as $url) + { + $str.="\n"; + } + $writer->write($str); + } + + public function renderStyleSheets($writer) + { + if(count($this->_styleSheets)) + $writer->write("\n"); + } + public function getHasHiddenFields() { return count($this->_hiddenFields)>0; @@ -353,7 +435,6 @@ class TClientScriptManager extends TComponent /* - internal void RenderWebFormsScript(HtmlTextWriter writer) private void EnsureEventValidationFieldLoaded(); internal string GetEventValidationFieldValue(); public string GetWebResourceUrl(Type type, string resourceName); diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php index e2565291..f9d8f879 100644 --- a/framework/Web/UI/TPage.php +++ b/framework/Web/UI/TPage.php @@ -446,6 +446,17 @@ class TPage extends TTemplateControl protected function onPreRenderComplete($param) { $this->raiseEvent('PreRenderComplete',$this,$param); + $cs=$this->getClientScript(); + if($this->_theme) + { + foreach($this->_theme->getStyleSheetFiles() as $url) + $cs->registerStyleSheetFile($url,$url); + } + if($this->_styleSheet) + { + foreach($this->_styleSheet->getStyleSheetFiles() as $url) + $cs->registerStyleSheetFile($url,$url); + } } /** diff --git a/framework/Web/UI/TThemeManager.php b/framework/Web/UI/TThemeManager.php index 746e36cb..cc406305 100644 --- a/framework/Web/UI/TThemeManager.php +++ b/framework/Web/UI/TThemeManager.php @@ -197,6 +197,10 @@ class TTheme extends TComponent * @var string theme name */ private $_name=''; + /** + * @var array list of css files + */ + private $_cssFiles=array(); /** * Constructor. @@ -214,24 +218,32 @@ class TTheme extends TComponent $array=$cache->get(self::THEME_CACHE_PREFIX.$themePath); if(is_array($array)) { - list($skins,$timestamp)=$array; + list($skins,$cssFiles,$timestamp)=$array; $cacheValid=true; if($application->getMode()!=='Performance') { - if(($dir=opendir($themePath))===false) - throw new TIOException('theme_path_inexistent',$themePath); - while(($file=readdir($dir))!==false) + if(filemtime($themePath)>$timestamp) + $cacheValid=false; + else { - if(basename($file,self::SKIN_FILE_EXT)!==$file && filemtime($themePath.'/'.$file)>$timestamp) + if(($dir=opendir($themePath))===false) + throw new TIOException('theme_path_inexistent',$themePath); + while(($file=readdir($dir))!==false) { - $cacheValid=false; - break; + if(basename($file,self::SKIN_FILE_EXT)!==$file && filemtime($themePath.'/'.$file)>$timestamp) + { + $cacheValid=false; + break; + } } + closedir($dir); } - closedir($dir); } if($cacheValid) + { $this->_skins=$skins; + $this->_cssFiles=$cssFiles; + } } } if($this->_skins===null) @@ -240,7 +252,11 @@ class TTheme extends TComponent throw new TIOException('theme_path_inexistent',$themePath); while(($file=readdir($dir))!==false) { - if(basename($file,self::SKIN_FILE_EXT)!==$file) + if($file==='.' || $file==='..') + continue; + else if(basename($file,'.css')!==$file) // is a css file + $this->_cssFiles[]=$themeUrl.'/'.$file; + else if(basename($file,self::SKIN_FILE_EXT)!==$file) { $template=new TTemplate(file_get_contents($themePath.'/'.$file),$themePath,$themePath.'/'.$file); foreach($template->getItems() as $skin) @@ -265,7 +281,7 @@ class TTheme extends TComponent } closedir($dir); if($cache!==null) - $cache->set(self::THEME_CACHE_PREFIX.$themePath,array($this->_skins,time())); + $cache->set(self::THEME_CACHE_PREFIX.$themePath,array($this->_skins,$this->_cssFiles,time())); } } @@ -327,6 +343,14 @@ class TTheme extends TComponent else return false; } + + /** + * @return array list of CSS files (URL) in the theme + */ + public function getStyleSheetFiles() + { + return $this->_cssFiles; + } } ?> \ No newline at end of file diff --git a/framework/Web/UI/WebControls/THead.php b/framework/Web/UI/WebControls/THead.php index 0e074519..e9381432 100644 --- a/framework/Web/UI/WebControls/THead.php +++ b/framework/Web/UI/WebControls/THead.php @@ -58,14 +58,6 @@ */ class THead extends TControl { - /** - * @var array list of javascript files to be loaded by {@link THead} - */ - private $_scriptFiles=array(); - /** - * @var array list of CSS style files to be loaded by {@link THead} - */ - private $_styleFiles=array(); /** * @var array list of meta name tags to be loaded by {@link THead} */ @@ -100,28 +92,6 @@ class THead extends TControl $this->getPage()->setTitle($value); } - /** - * Registers a javascript file to be loaded in client side - * @param string a key that identifies the script file to avoid repetitive registration - * @param string the javascript file which can be relative or absolute URL - * @see isScriptFileRegistered() - */ - public function registerScriptFile($key,$scriptFile) - { - $this->_scriptFiles[$key] = $scriptFile; - } - - /** - * Registers a CSS style file to be imported with the page body - * @param string a key that identifies the style file to avoid repetitive registration - * @param string the javascript file which can be relative or absolute URL - * @see isStyleFileRegistered() - */ - public function registerStyleFile($key,$styleFile) - { - $this->_styleFiles[$key] = $styleFile; - } - /** * Registers a meta tag to be imported with the page body * @param string a key that identifies the meta tag to avoid repetitive registration @@ -134,28 +104,6 @@ class THead extends TControl $this->_metaTags[$key] = $metaTag; } - /** - * Indicates whether the named scriptfile has been registered before. - * @param string the name of the scriptfile - * @return boolean - * @see registerScriptFile() - */ - public function isScriptFileRegistered($key) - { - return isset($this->_scriptFiles[$key]); - } - - /** - * Indicates whether the named CSS style file has been registered before. - * @param string the name of the style file - * @return boolean - * @see registerStyleFile() - */ - public function isStyleFileRegistered($key) - { - return isset($this->_styleFiles[$key]); - } - /** * Indicates whether the named meta tag has been registered before. * @param string the name of tag @@ -174,25 +122,19 @@ class THead extends TControl */ public function render($writer) { - $writer->renderBeginTag('head'); - $writer->writeLine(); - $writer->renderBeginTag('title'); - $writer->write($this->getPage()->getTitle()); - $writer->renderEndTag(); - $writer->writeLine(); + $writer->write("
\n