PHP Classes
elePHPant
Icontem

File: template.lib.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of András Zoltán-Gyárfás  >  Pine template  >  template.lib.php  >  Download  
File: template.lib.php
Role: Class source
Content type: text/plain
Description: Main script
Class: Pine template
Template engine that replaces tags in files
Author: By
Last change: some minor changes
Date: 6 years ago
Size: 1,318 bytes
 

Contents

Class file image Download
<?php
/*
Created by Andras Zoltan-Gyarfas from Transilvania in 2007
email: azolee@gmail.com
Use this script as you wish, just please send a notice for me if you do so.
For more questions/suggestions, please contact me.
*/
class tpl
{
// public methods
   
public function display($a, $wh, $clr=true, $ld=true)
    {
    if(
$ld) { $where=tpl::load($wh); }
    else {
$where=$wh; }
       
$ret=$where;
        if(
is_array($a))
        {
            foreach(
$a as $k => $v)
            {
               
$ret=tpl::change($k, $v, $ret);
            }
        }
        if(
$clr)
        {
        return
tpl::clear($ret);
        }
        else
        {
        return
$ret;
        }
    }
// private methods
   
protected function load($fn)
    {
   
$ret="";
        if(
file_exists($fn))
        {
           
$ret = file_get_contents($fn);
        }
        else
        {
           
$ret = "";
        }
        return
$ret;
    }
    public function
change($what, $whit, $where)
    {
        if(!empty(
$where))
        {
           
$ret=ereg_replace("{".strtoupper($what)."}", trim($whit), $where);
        }
        return
$ret;
    }
    protected function
clear($c)
    {
   
$temp = ereg_replace("{([A-Z0-9_]+)}","",$c);
    return
$temp;
    }
}
?>