summaryrefslogtreecommitdiff
path: root/framework/Web/UI
diff options
context:
space:
mode:
authorxue <>2005-11-15 15:34:38 +0000
committerxue <>2005-11-15 15:34:38 +0000
commit4c9067bf7ae89b446bb0e236ab20c5b4fa3ee3e3 (patch)
treebe5b2366fdedd2d2789955deb18ef7e072ca4e6e /framework/Web/UI
parentfdce469afc80e6cf922c07500f9b7bfd5b302c35 (diff)
Added a new template/theme syntax for URL support.
Diffstat (limited to 'framework/Web/UI')
-rw-r--r--framework/Web/UI/TControl.php25
-rw-r--r--framework/Web/UI/TTemplate.php42
-rw-r--r--framework/Web/UI/TTemplateManager.php6
-rw-r--r--framework/Web/UI/TThemeManager.php44
4 files changed, 58 insertions, 59 deletions
diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php
index 21c633c7..fbdc81ee 100644
--- a/framework/Web/UI/TControl.php
+++ b/framework/Web/UI/TControl.php
@@ -69,10 +69,6 @@ class TControl extends TComponent
* prefix to an ID automatically generated
*/
const AUTOMATIC_ID_PREFIX='ctl';
- /**
- * default control asset path
- */
- const ASSET_PATH='assets';
/**
* the stage of lifecycles that the control is currently at
@@ -302,26 +298,11 @@ class TControl extends TComponent
return Prado::getApplication()->getUser();
}
- public function publishFile($file)
- {
- return $this->getService()->getAssetManager()->publishFile($file);
- }
-
- public function publishDirectory($directory)
- {
- return $this->getService()->getAssetManager()->publishDirectory($directory);
- }
-
- public function getAsset($assetName)
+ public function getAsset($assetPath)
{
$class=new ReflectionClass(get_class($this));
- $assetFile=dirname($class->getFileName()).'/'.self::ASSET_PATH.'/'.$assetName;
- if(is_file($assetFile))
- return $this->publishFile($assetFile);
- else if(is_dir($assetFile))
- return $this->publishDirectory($assetFile);
- else
- return '';
+ $assetPath=dirname($class->getFileName()).'/'.$assetPath;
+ return $this->getService()->getAssetManager()->publishFilePath($assetPath);
}
/**
diff --git a/framework/Web/UI/TTemplate.php b/framework/Web/UI/TTemplate.php
index 0e36f2f4..7683bc1b 100644
--- a/framework/Web/UI/TTemplate.php
+++ b/framework/Web/UI/TTemplate.php
@@ -58,14 +58,19 @@ class TTemplate extends TComponent implements ITemplate
* @var array list of directive settings
*/
private $_directive=array();
+ /**
+ * @var string context path
+ */
+ private $_contextPath;
/**
* Constructor.
* The template will be parsed after construction.
* @param string the template string
*/
- public function __construct($template)
+ public function __construct($template,$contextPath)
{
+ $this->_contextPath=$contextPath;
$this->parse($template);
}
@@ -87,6 +92,7 @@ class TTemplate extends TComponent implements ITemplate
public function instantiateIn($tplControl)
{
$page=$tplControl->getPage();
+ $assetManager=$page->getService()->getAssetManager();
$controls=array();
foreach($this->_tpl as $key=>$object)
{
@@ -145,18 +151,28 @@ class TTemplate extends TComponent implements ITemplate
$component->$setter($value);
else if($value[0]===0)
$component->bindProperty($name,$value[1]);
- else
+ else if($value[0]===1)
$component->$setter($component->evaluateExpression($value[1]));
+ else // url
+ {
+ $url=$assetManager->publishFilePath($this->_contextPath.'/'.$value[1]);
+ $component->$setter($url);
+ }
}
else
throw new TTemplateRuntimeException('property_read_only',get_class($component).'.'.$name);
}
else if($component->getAllowCustomAttributes())
{
- if(is_array($value) && $value[0]===1)
- $value=$component->evaluateExpression($value[1]);
- else
- throw new TTemplateRuntimeException('template_attribute_unbindable',$name);
+ if(is_array($value))
+ {
+ if($value[0]===1)
+ $value=$component->evaluateExpression($value[1]);
+ else if($value[0]===2)
+ $value=$assetManager->publishFilePath($this->_contextPath.'/'.$value[1]);
+ else
+ throw new TTemplateRuntimeException('template_attribute_unbindable',$name);
+ }
$component->getAttributes()->add($name,$value);
}
else
@@ -168,8 +184,13 @@ class TTemplate extends TComponent implements ITemplate
$component->setSubProperty($name,$value);
else if($value[0]===0)
$component->bindProperty($name,$value[1]);
- else
+ else if($value[0]===1)
$component->setSubProperty($component->evaluateExpression($value[1]));
+ else
+ {
+ $url=$assetManager->publishFilePath($this->_contextPath.'/'.$value[1]);
+ $component->$setter($url);
+ }
}
}
$parent=isset($controls[$object[0]])?$controls[$object[0]]:$tplControl;
@@ -194,6 +215,11 @@ class TTemplate extends TComponent implements ITemplate
$component->$setter($value);
else if($value[0]===1)
$component->$setter($component->evaluateExpression($value[1]));
+ else if($value[0]===2)
+ {
+ $url=$assetManager->publishFilePath($this->_contextPath.'/'.$value[1]);
+ $component->$setter($url);
+ }
else
throw new TTemplateRuntimeException('template_component_property_unbindable',get_class($component),$name);
}
@@ -498,6 +524,8 @@ class TTemplate extends TComponent implements ITemplate
$attributes[$name]=array(0,substr($value,3,strlen($value)-5));
else if($value[2]==='=') // a dynamic initialization
$attributes[$name]=array(1,substr($value,3,strlen($value)-5));
+ else if($value[2]==='~') // a URL
+ $attributes[$name]=array(2,trim(substr($value,3,strlen($value)-5)));
else
$attributes[$name]=substr($value,2,strlen($value)-4);
}
diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php
index 843d2460..2703500a 100644
--- a/framework/Web/UI/TTemplateManager.php
+++ b/framework/Web/UI/TTemplateManager.php
@@ -40,10 +40,10 @@ class TTemplateManager extends TComponent implements IModule
public function getTemplateByFileName($fileName)
{
- if(is_file($fileName))
+ if(($fileName=realpath($fileName))!==false && is_file($fileName))
{
if(($cache=$this->_application->getCache())===null)
- return new TTemplate(file_get_contents($fileName));
+ return new TTemplate(file_get_contents($fileName),dirname($fileName));
else
{
$array=$cache->get(self::TEMPLATE_CACHE_PREFIX.$fileName);
@@ -53,7 +53,7 @@ class TTemplateManager extends TComponent implements IModule
if(filemtime($fileName)<$timestamp)
return $template;
}
- $template=new TTemplate(file_get_contents($fileName));
+ $template=new TTemplate(file_get_contents($fileName),dirname($fileName));
$cache->set(self::TEMPLATE_CACHE_PREFIX.$fileName,array($template,time()));
return $template;
}
diff --git a/framework/Web/UI/TThemeManager.php b/framework/Web/UI/TThemeManager.php
index 019ccc85..7b370746 100644
--- a/framework/Web/UI/TThemeManager.php
+++ b/framework/Web/UI/TThemeManager.php
@@ -31,7 +31,7 @@ class TThemeManager extends TComponent implements IModule
{
$this->_application=$application;
if($this->_themePath===null)
- $this->_themePath=dirname($application->getConfigurationFile()).'/'.self::DEFAULT_THEME_PATH;
+ $this->_themePath=dirname($application->getRequest()->getPhysicalApplicationPath()).'/'.self::DEFAULT_THEME_PATH;
$this->_initialized=true;
}
@@ -111,14 +111,21 @@ class TThemeManager extends TComponent implements IModule
class TTheme extends TTemplate
{
- const ASSET_PATH='assets';
private $_themePath;
- private $_themeFile;
+ private $_themeUrl;
private $_skins=array();
public function __construct($content,$themePath)
{
- $this->_themePath=$themePath;
+ $this->_themePath=strtr($themePath,'\\','/');
+ $basePath=dirname(Prado::getApplication()->getRequest()->getPhysicalApplicationPath());
+ if(($pos=strpos($this->_themePath,$basePath))===false)
+ throw new TConfigurationException('theme_themepath_invalid',$themePath);
+ else
+ {
+ $baseUrl=dirname(Prado::getApplication()->getRequest()->getApplicationPath());
+ $this->_themeUrl=$baseUrl.'/'.strtr(substr($this->_themePath,strlen($basePath)),'\\','/');
+ }
$theme=&$this->parse($content);
foreach($theme as $skin)
{
@@ -150,7 +157,12 @@ class TTheme extends TTemplate
foreach($this->_skins[$type][$id] as $name=>$value)
{
if(is_array($value))
- $value=$this->evaluateExpression($value[1]);
+ {
+ if($value[0]===1)
+ $value=$this->evaluateExpression($value[1]);
+ else if($value[0]===2)
+ $value=$this->_themeUrl.'/'.$value[1];
+ }
if(strpos($name,'.')===false) // is simple property or custom attribute
{
if($control->hasProperty($name))
@@ -176,28 +188,6 @@ class TTheme extends TTemplate
else
return false;
}
-
- public function publishFile($file)
- {
- return Prado::getApplication()->getService()->getAssetManager()->publishFile($file);
- }
-
- public function publishDirectory($directory)
- {
- return Prado::getApplication()->getService()->getAssetManager()->publishDirectory($directory);
- }
-
- public function getAsset($assetName)
- {
- $assetFile=$this->_themePath.'/'.self::ASSET_PATH.'/'.$assetName;
- if(is_file($assetFile))
- return $this->publishFile($assetFile);
- else if(is_dir($assetFile))
- return $this->publishDirectory($assetFile);
- else
- return '';
- }
-
}