PHP Classes
Icontem

File: class.XTemplateAdaptor.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jesus M. Castagnetto  >  Generalized CachedTemplate class  >  class.XTemplateAdaptor.php  
File: class.XTemplateAdaptor.php
Role: ???
Content type: text/plain
Description: Template adaptor for the XTemplate class
Class: Generalized CachedTemplate class
General Template Caching class
 

Contents

Class file image Download
<?php

/*
 * Class TemplateAdaptor (XTemplate version)
 * by Jesus M. Castagnetto (jmcastagnetto@zkey.com)
 * (c) 2000. Version 1.1
 *
 * $Id: class.XTemplateAdaptor.php,v 1.4 2000/07/16 19:33:46 jesus Exp $
 *
 * Description:
 * This class extends Barnabás Debreceni [cranx@scene.hu] XTemplate class
 * implementing methods and attributes needed for the CachedTemplate class.
 *
 * The adaptor class needs to implement the getTemplatesList() method that
 * returns an array with the names of the templates loaded, the init() 
 * method used to initialize the constructor of the parent template class,
 * and the getParsedDoc() method which returns the parsed document.
 *
 * Notes:
 * - This adaptor class overrides the original getfiles() method from
 *   XTemplate, in order to create the $TEMPLATES array which is returned
 *   by the getTemplatesList() method.
 *
 * Changes:
 * 2000/06/10 - Initial release.
 * 2000/07/17 - Documentation, new release.
 */


class TemplateAdaptor extends XTemplate {

	var $TEMPLATES = array();

	/*
	 * This method is used to initialize the parent class
	 */

	function init($file, $mainblock="main") {
		$this->XTemplate ($file,$mainblock);
	}


	/*
	 * method to return the list of template names
	 */
	
	function getTemplatesList() {
		return $this->TEMPLATES;
	}

	function getParsedDoc($sect="main") {
		return $this->Text($sect);
	}

	/*
	 * Overrides the original getfile() method to generate an
	 * array of filenames so we can also check for changes
	 * in the template files, and thus decide whether to
	 * reparse the cached file
	*/

	function getfile($file) {
		if (empty($file)) {
			$this->set_error("Empty file name!");
			return "";
		}
		
	
		if (is_file($file)) {
			if (!($fh=fopen($file,"r"))) {
				$this->set_error("Cannot open file: $file");
				return "";
			}

			$file_text=fread($fh,filesize($file));
			fclose($fh);
			
			// this line does the trick, the rest is from XTemplate
			$this->TEMPLATES[] = $file;
		} else { 
			$this->set_error("[$file] does not exist");
			$file_text="<b>__XTemplate fatal error: file [$file] does not exist__</b>";
		}
			
		return $file_text;
	}

} // end of class definition
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products