[pLog-svn] r3455 - plog/trunk/class/template
mark at devel.lifetype.net
mark at devel.lifetype.net
Wed May 24 07:00:56 GMT 2006
Author: mark
Date: 2006-05-24 07:00:55 +0000 (Wed, 24 May 2006)
New Revision: 3455
Modified:
plog/trunk/class/template/templateservice.class.php
Log:
Add config file support to smarty. Now user can use {config_load file="abc.conf} to load his own config file.
Modified: plog/trunk/class/template/templateservice.class.php
===================================================================
--- plog/trunk/class/template/templateservice.class.php 2006-05-24 06:07:01 UTC (rev 3454)
+++ plog/trunk/class/template/templateservice.class.php 2006-05-24 07:00:55 UTC (rev 3455)
@@ -2,7 +2,7 @@
include_once( PLOG_CLASS_PATH.'class/config/config.class.php' );
include_once( PLOG_CLASS_PATH.'class/file/file.class.php' );
-
+
/**
* default permissions used to create temporary template folders. Seems like
* Smarty creates them as 0771 but we have been adviced to create
@@ -39,7 +39,7 @@
* print($template->display());
* </pre>
*/
- class TemplateService
+ class TemplateService
{
/**
@@ -47,7 +47,7 @@
*/
function TemplateService()
{
-
+
}
/**
@@ -56,7 +56,7 @@
*
* @param templateName The name of the template, it is not necessary to provide
* the .template extension.
- * @param layout A predefined layout style, which corresponds with the name of a
+ * @param layout A predefined layout style, which corresponds with the name of a
* folder under the templates/ folder so 'blueish' would mean templates/blueish/
* @param blogInfo If this parameter is not null, then it will be used to locate
* a blog-specific template. Otherwise, we will only look for the template
@@ -71,7 +71,7 @@
$templateInfo = $this->_getTemplateFileInfo( $templateName, $layout, $blogInfo );
$templateFileName = $templateInfo['templateFileName'];
$templateFolder = $templateInfo['templateFolder'];
-
+
// create the template and make sure if we we have to force Smarty
// to look for it somewhere else other than the default folder
$t = new Template( $templateFileName );
@@ -80,9 +80,10 @@
$t->assign( 'templatename', $templateName );
$t->assign( 'blogtemplate', $templateFolder.'/'.$layout );
-
+ $t->config_dir = $templateFolder.'/'.$layout;
+
// change a few things...
- $t = $this->_configureTemplateSettings( $t, $blogInfo, $layout );
+ $t = $this->_configureTemplateSettings( $t, $blogInfo, $layout );
return $t;
}
@@ -92,10 +93,10 @@
*
* @param templateName The name of the template, it is not necessary to provide
* the .template extension.
- * @param layout A predefined layout style, which corresponds with the name of a
+ * @param layout A predefined layout style, which corresponds with the name of a
* folder under the templates/ folder so 'blueish' would mean templates/blueish/
* @param cached Whether the custom template should be cached or not (this will affect
- * the kind of the returned object)
+ * the kind of the returned object)
* @return a Template or CachedTemplate object, depending on whether
* $cached is 'true' or 'false'
*/
@@ -125,7 +126,7 @@
return $t;
}
-
+
/**
* returns a template from the admin folder. It still uses TemplateService::Template but
* exports additional information to the template such as the base template path so that
@@ -136,26 +137,26 @@
* @param blogInfo
* @return A Template object pointing to a template from the templates/admin/ folder
*/
- function AdminTemplate( $templateName, $blogInfo = null )
+ function AdminTemplate( $templateName, $blogInfo = null )
{
include_once( PLOG_CLASS_PATH.'class/template/templatesets/templatesetstorage.class.php' );
$t = $this->Template( $templateName, 'admin', $blogInfo );
$t->assign( 'admintemplatepath', TemplateSetStorage::getAdminTemplateFolder());
-
+
return $t;
}
-
+
/**
* returns a CachedTemplate object, which works in exactly the same way as a Template
* object but its contents will be cached as soon as they are generated. The lifetime
* of cached contents is controlled via the 'template_cache_lifetime' configuration
- * parameter, but contents will be regenerated automatically as soon as
+ * parameter, but contents will be regenerated automatically as soon as
* CacheControll::resetBlogCache() is called.
*
* @param templateName The name of the template, it is not necessary to provide
* the .template extension.
- * @param layout A predefined layout style, which corresponds with the name of a
+ * @param layout A predefined layout style, which corresponds with the name of a
* folder under the templates/ folder so 'blueish' would mean templates/blueish/
* @param blogInfo
* @return a CachedTemplate object pointing to the right .template file in disk
@@ -164,7 +165,7 @@
{
include_once( PLOG_CLASS_PATH.'class/template/cachedtemplate.class.php' );
- // get some information about the folder where the template is and the template file
+ // get some information about the folder where the template is and the template file
$templateInfo = $this->_getTemplateFileInfo( $templateName, $layout, $blogInfo );
$templateFileName = $templateInfo['templateFileName'];
$templateFolder = $templateInfo['templateFolder'];
@@ -176,19 +177,20 @@
$t->setTemplateDir( $templateFolder );
$t->assign( 'templatename', $templateName );
- $t->assign( 'blogtemplate', $templateFolder.'/'.$layout );
+ $t->assign( 'blogtemplate', $templateFolder.'/'.$layout );
+ $t->config_dir = $templateFolder.'/'.$layout;
// change a few things...
$t = $this->_configureTemplateSettings( $t, $blogInfo );
return $t;
}
-
+
/**
* @private
* Factored out from above...
*/
- function _getTemplateFileInfo( $templateName, $layout, $blogInfo )
+ function _getTemplateFileInfo( $templateName, $layout, $blogInfo )
{
include_once( PLOG_CLASS_PATH.'class/template/templatesets/templatesetstorage.class.php' );
@@ -216,13 +218,13 @@
else
$templateFolder = $baseTemplateFolder.'/';
}
-
+
$result['templateFileName'] = $templateFileName;
$result['templateFolder'] = $templateFolder;
-
+
return $result;
}
-
+
/**
* Returns a Template object loaded from a plugin template
* Plugins are different in the sense that they store their templates in the
@@ -248,13 +250,13 @@
$t->assign( 'templatename', $templateName );
$t->assign( 'admintemplatepath', TemplateSetStorage::getAdminTemplateFolder());
$t->assign( 'plugintemplatepath', $templateFolder );
-
+
// change a few things...
- $t = $this->_configureTemplateSettings( $t, $blogInfo );
-
+ $t = $this->_configureTemplateSettings( $t, $blogInfo );
+
return $t;
}
-
+
/**
* Returns a CachedTemplate object loaded from a plugin template
* Plugins are different in the sense that they store their templates in the
@@ -279,34 +281,34 @@
$t->assign( 'templatename', $templateName );
$t->assign( 'admintemplatepath', TemplateSetStorage::getAdminTemplateFolder());
$t->assign( 'plugintemplatepath', $templateFolder );
-
+
// change a few things...
- $t = $this->_configureTemplateSettings( $t, $blogInfo );
-
+ $t = $this->_configureTemplateSettings( $t, $blogInfo );
+
return $t;
}
-
+
/**
* @private
*/
- function _configureTemplateSettings( $t, $blogInfo, $layout = "" )
+ function _configureTemplateSettings( $t, $blogInfo, $layout = "" )
{
// change a few things...
$config =& Config::getConfig();
$tmpFolder = $config->getValue( 'temp_folder' );
- if( $blogInfo == null )
+ if( $blogInfo == null )
$blogTmpFolder = $tmpFolder;
- else {
+ else {
$blogTmpFolder = $tmpFolder.'/'.$blogInfo->getId();
if( !File::exists( $blogTmpFolder )) {
File::createDir( $blogTmpFolder, DEFAULT_TEMPLATE_TEMP_FOLDER_PERMISSIONS );
}
$t->secure_dir[] = "./templates/blog_".$blogInfo->getId()."/$layout";
}
-
+
$t->cache_dir = $blogTmpFolder;
$t->compile_dir = $blogTmpFolder;
-
+
$t->compile_check = $config->getValue( 'template_compile_check' );
return $t;
More information about the pLog-svn
mailing list