Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

template_handler.php

Go to the documentation of this file.
00001 
00002 /** @file template_handler.php
00003 * Definition of class template_handler.
00004 */
00005 #include "error_logger.php"
00006 /**
00007 * Provides methods to handle templates.
00008 */
00009 class template_handler : public  error_logger
00010 {
00011 public:
00012   /** Entities. */
00013   var entities = array();
00014   /** If we need to correct locations. */
00015   var need_loc_corr = 1;
00016   /** Clear entities. */
00017   function clear()
00018   {
00019     this->entities = array();
00020   }
00021   /**
00022   * Set entity to replacement relation.
00023   * @param string entity - entity (like '@date' or '&time&' )
00024   * @paran string replacement - string to replace entity to
00025   * @see entities
00026   */
00027   function set( entity, replacement )
00028   {
00029     this->entities[ entity ] = replacement;
00030   }
00031   /**
00032   * Process file replacing entities.
00033   * @param string filename - template file name
00034   * @param bool strip_unknown - strip unknown entities
00035   * @param string ent_pattern - entity pattern to strip unknown entities
00036   * @return string with processed template
00037   * @bug relative/absolute paths in templates: xxx://yyy links are coverted to
00038   * <templates>/xxx://yyy
00039   * @todo do something with paths, by now xxx://yyy links are coverted too
00040   */
00041   function process_file( filename, strip_unknown = 0, ent_pattern = '')
00042   {
00043     if( !is_file( filename ) )
00044       return this->err( 'Not a file name given: '.filename, 'process_file', __LINE__, __FILE__ );
00045     template_dir = dirname( filename );
00046     file_content = join( '', file( filename ) );
00047     if( this->need_loc_corr )
00048       file_content = preg_replace(
00049         '/(href|action|src|background)=[\'"]\/(\S*)[\'"]/',
00050         '1=\'2\'',
00051         preg_replace(
00052           '/(href|action|src|background)=[\'"]([^\/]\S*)[\'"]/',
00053           '1=\''.template_dir.'/2\'',
00054           file_content ) );
00055     searches = array();
00056     replacements = array();
00057     foreach( this->entities as search => replacement )
00058     {
00059       searches[] = search;
00060       replacements[] = replacement;
00061     }
00062     file_content = str_replace( searches, replacements, file_content );
00063     if( strip_unknown )
00064       file_content = preg_replace( ent_pattern, '', file_content, -1 );
00065     return file_content;
00066   }
00067 }
00068 X-Powered-By: PHP/4.0.8-dev
00069 Content-type: text/html
00070 
00071 

Generated on Tue Mar 11 08:35:13 2003 for SES by doxygen1.2.16