summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorxue <>2005-12-08 17:51:08 +0000
committerxue <>2005-12-08 17:51:08 +0000
commit1bbff5ec853ae88cdfe1446d22c06a87fe305c0f (patch)
treeae353445a282289e947f389f5e7ef306e0b53de9 /framework
parent67512372613e56f223d810af3bc368834167707d (diff)
Diffstat (limited to 'framework')
-rw-r--r--framework/Web/THttpUtility.php8
-rw-r--r--framework/Web/UI/TClientScriptManager.php93
-rw-r--r--framework/Web/UI/TPage.php11
-rw-r--r--framework/Web/UI/TThemeManager.php44
-rw-r--r--framework/Web/UI/WebControls/THead.php72
5 files changed, 143 insertions, 85 deletions
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("<script type=\"text/javascript\" src=\"".THttpUtility::htmlEncode($include)."\"></script>\n");
+ $str.="<script type=\"text/javascript\" src=\"".THttpUtility::htmlEncode($include)."\"></script>\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.="<script type=\"text/javascript\" src=\"".THttpUtility::htmlEncode($url)."\"></script>\n";
+ $writer->write($str);
+ }
+
+ public function renderHeadScripts($writer)
+ {
+ if(count($this->_headScripts))
+ $writer->write("<script type=\"text/javascript\">\n//<![CDATA[\n".implode("\n",$this->_headScripts)."\n//]]>\n</script>\n");
+ }
+
+ public function renderStyleSheetFiles($writer)
+ {
+ $str='';
+ foreach($this->_styleSheetFiles as $url)
+ {
+ $str.="<link rel=\"stylesheet\" type=\"text/css\" href=\"".THttpUtility::htmlEncode($url)."\" />\n";
+ }
+ $writer->write($str);
+ }
+
+ public function renderStyleSheets($writer)
+ {
+ if(count($this->_styleSheets))
+ $writer->write("<style type=\"text/css\">\n".implode("\n",$this->_styleSheets)."\n</style>\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
@@ -59,14 +59,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}
*/
private $_metaTags=array();
@@ -101,28 +93,6 @@ class THead extends TControl
}
/**
- * 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
* @param string the content of the meta tag
@@ -135,28 +105,6 @@ class THead extends TControl
}
/**
- * 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
* @param string the lang of the 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("<head>\n<title>".THttpUtility::htmlEncode($this->getTitle())."</title>\n");
foreach($this->_metaTags as $metaTag)
{
$metaTag->render($writer);
$writer->writeLine();
}
- foreach($this->_scriptFiles as $scriptFile)
- {
- }
- foreach($this->_styleFiles as $styleFile)
- {
- }
+ $cs=$this->getPage()->getClientScript();
+ $cs->renderStyleSheetFiles($writer);
+ $cs->renderStyleSheets($writer);
+ $cs->renderHeadScriptFiles($writer);
+ $cs->renderHeadScripts($writer);
parent::render($writer);
- $writer->renderEndTag();
+ $writer->write("</head>\n");
}
}