Update of /cvsroot/lambda/lambda/classes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5684/classes
Modified Files:
lambdaTemplate.class.php
Log Message:
Make use of new smarty template system.
Index: lambdaTemplate.class.php
===================================================================
RCS file: /cvsroot/lambda/lambda/classes/lambdaTemplate.class.php,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** lambdaTemplate.class.php 7 Jul 2004 13:05:40 -0000 1.7
--- lambdaTemplate.class.php 7 Jul 2004 13:59:26 -0000 1.8
***************
*** 10,118 ****
**/
/**
* Handles data output
* @package lambdaCore
**/
! class lambdaTemplate extends lambdaObject {
!
! /**
! * @var array Keys (tags) which will be replaced in this template, of the form {KEY}
! **/
! var $keys;
!
! /**
! * @var array The strings that the keys will be replaced with
! **/
! var $values;
!
! /**
! * @var string The (unprocessed) template data
! **/
! var $templateData;
/**
! * @var object Error handler reference
**/
var $handler;
!
! /**
! * Sets the classname, sets up error handler
! **/
function lambdaTemplate() {
global $handler;
$this->handler = $handler;
! $this->setClassName('template');
$this->handler->debug("lambdaTemplate initialised", 2);
}
!
! /**
! * Adds a new template key/value pair
! *
! * @return bool TRUE if successful, FALSE if key already exists
! **/
! function assign($key,$value) {
! if(!in_array($key,$this->keys)) {
! array_push($this->keys,'/\{'.$key.'\}/'); /* Surround key with { and }, and the key*/
! /* must be in the form of a regex, /{$key}/ */
! array_push($this->values,$value);
! return TRUE;
! }else{
! $this->handler->warning('Key value "'.$key.'" already exists in this template, not adding again');
! return FALSE;
! }
! }
!
! /**
! * Removes a key/value pair
! *
! * @return bool TRUE on success, FALSE if the key was not found
! **/
! function unassign($key) {
! if($keyID = array_search($key,$this->keys)) {
! $this->keys[$keyID] = $this->values[$keyID] = NULL;
! return TRUE;
! }else{
! $this->handler->warning('Key "'.$key.'" not found in this template');
! return FALSE;
! }
! }
!
! /**
! * Appends raw template data to $templateData from a template file
! *
! * This will first attempt to open $file for reading, if that fails
! * an error will be displayed and the script will stop. Next the
! * contents of the file are read, and again if that fails the script
! * will stop after an error is displayed.
! *
! * For example, you could add head.tpl followed by body.tpl then
! * foot.tpl; you can pick which template parts you need for a particular page.
! *
! * @return bool TRUE on success, FALSE on failure
! **/
! function addFile($file) {
! if($fp = fopen(LAMBDA_TEMPLATE . $file,r)) {
! if($data = fread($fp,filesize(LAMBDA_TEMPLATE . $file))) {
! $this->templateData .= $data; /* Append data to $templateData */
! fclose($fp);
! return TRUE;
! }else{
! fclose($fp);
! $this->handler->error('Unable to read template data',TRUE);
! return FALSE; /* In practice the script is killed before this, but */
! /* still return for completeness */
! }
! }else{
! $this->handler->error('Unable to open template for reading',TRUE);
! return FALSE;
! }
! }
!
! /**
! * Prints template with data inserted into it
! **/
! function output() {
! print preg_replace($keys,$values,$templateData);
! }
! }
--- 10,39 ----
**/
+ /* Use Smarty */
+ require_once(SMARTY_DIR . "Smarty.class.php");
+
/**
* Handles data output
* @package lambdaCore
**/
! class lambdaTemplate extends Smarty {
/**
! * @var object Local reference to error handler
**/
var $handler;
!
function lambdaTemplate() {
global $handler;
$this->handler = $handler;
!
! /* Initialise Smarty */
! $this->Smarty();
!
! /* Set Smarty settings */
! $this->template_dir = LAMBDA_TEMPLATE;
! $this->compile_dir = LAMBDA_TMP;
$this->handler->debug("lambdaTemplate initialised", 2);
}
! }
\ No newline at end of file
|