PHP Classes

File: class.XTemplateAdaptor.php

Recommend this page to a friend!
  Classes of Jesus M. Castagnetto   Generalized CachedTemplate class   class.XTemplateAdaptor.php   Download  
File: class.XTemplateAdaptor.php
Role: ???
Content type: text/plain
Description: Template adaptor for the XTemplate class
Class: Generalized CachedTemplate class
General Template Caching class
Author: By
Last change:
Date: 24 years ago
Size: 2,271 bytes
 

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 ?>