Show
Ignore:
Timestamp:
06/20/07 16:05:14 (1 year ago)
Author:
gerd
Message:

Clean up gode from last revision :-(
Support for placeholders in default attributes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/patTemplate.php

    r463 r464  
    1 <?PHP 
     1<?php 
    22/** 
    33 * patTemplate 
     
    77 * powerful templating engine 
    88 * 
    9  * @version     3.1.0 
     9 * @version     3.2.0 
    1010 * @package     patTemplate 
    1111 * @author      Stephan Schmidt <schst@php.net> 
     12 * @author      gERD Schaufelberger <gerd@php-tools.net> 
    1213 * @license     LGPL 
    1314 * @link        http://www.php-tools.net 
     
    5960 * powerful templating engine 
    6061 * 
    61  * @version     3.1.0 
     62 * @version     3.2.0 
    6263 * @package     patTemplate 
    6364 * @author      Stephan Schmidt <schst@php.net> 
     65 * @author      gERD Schaufelberger <gerd@php-tools.net> 
    6466 * @license     LGPL 
    6567 * @link        http://www.php-tools.net 
     
    7375    var $_systemVars            =   array( 
    7476                                        'appName'       =>  'patTemplate', 
    75                                         'appVersion'    =>  '3.1.0', 
     77                                        'appVersion'    =>  '3.2.0', 
    7678                                        'author'        =>  array( 
    77                                                                     'Stephan Schmidt <schst@php.net>' 
     79                                                                    'Stephan Schmidt <schst@php.net>', 
     80                                                                    'gERD Schaufelberger <gerd@php-tools.net>' 
    7881                                                                 ) 
    7982                                    ); 
     
    8588    */ 
    8689    var $_defaultAttributes =   array( 
    87                                         'type'          =>  'standard', 
    88                                         'visibility'    =>  'visible', 
    89                                         'loop'          =>  1, 
    90                                         'unusedvars'    =>  'strip', 
    91                                         'whitespace'    =>  'keep', 
    92                                         'autoclear'     =>  'off', 
    93                                         'autoload'      =>  'on' 
     90                                    'type'                  =>  'standard', 
     91                                    'visibility'            =>  'visible', 
     92                                    'loop'                  =>  1, 
     93                                    'unusedvars'            =>  'strip', 
     94                                    'whitespace'            =>  'keep', 
     95                                    'autoclear'             =>  'off', 
     96                                    'autoload'              =>  'on', 
     97                                    'attributeplaceholder'  =>  'ignore', 
    9498                                    ); 
    9599 
     
    12181222                } 
    12191223 
    1220                 $this->addVar( $name, $varname, $varspec['default'] ); 
     1224                // $this->addVar( $name, $varname, $varspec['default'] ); 
    12211225            } 
    12221226 
     
    20032007            case 'simplecondition': 
    20042008                foreach ($this->_templates[$template]['attributes']['requiredvars'] as $var) { 
     2009 
    20052010                    // different template scope 
    20062011                    if( $var[0] !== $template ) { 
     
    22272232        } 
    22282233 
    2229  
    22302234        $iteration = $this->_templates[$template]['iteration']; 
    22312235 
     
    22612265            $vars = array_merge( $vars, $this->_vars[$template]['rows'][$iteration] ); 
    22622266        } 
     2267 
     2268        /** 
     2269         * add global vars 
     2270         */ 
     2271        if( !empty( $this->_globals ) ) { 
     2272            $vars = array_merge( $this->_globals, $vars ); 
     2273        } 
     2274 
     2275        /** 
     2276         * add default variables 
     2277         */ 
     2278        if( !empty( $this->_templates[$template]['defaultVars'] ) ) { 
     2279            $vars = array_merge( $this->_templates[$template]['defaultVars'], $vars ); 
     2280        } 
    22632281 
    22642282        /** 
     
    22992317        } 
    23002318 
    2301         $this->_templates[$template]['vars'] = $vars; 
    2302         if( empty( $this->_templates[$template]['defaultVars'] ) ) { 
     2319        if( empty( $this->_templates[$template]['defaultVars'] ) || $this->_templates[$template]['attributes']['attributeplaceholder'] != 'replace' ) { 
     2320            $this->_templates[$template]['vars'] = $vars; 
    23032321            return true; 
    23042322        } 
     
    23122330        } 
    23132331 
    2314         foreach( $this->_templates[$template]['defaultVars'] as $k => &$v ) { 
     2332        foreach( $this->_templates[$template]['defaultVars'] as $k => $v ) { 
     2333            // check if replace is required and variable is still default 
    23152334            if( !strstr( $v, $this->_endTag ) ) { 
    23162335                continue; 
    23172336            } 
    2318             $v  =   str_replace( $search, $replace, $v ); 
     2337 
     2338            if( $v != $vars[$k] ) { 
     2339                continue; 
     2340            } 
     2341 
     2342            $vars[$k]   =   str_replace( $search, $replace, $v ); 
    23192343        } 
    23202344         
     2345        $this->_templates[$template]['vars'] = $vars; 
    23212346        return true; 
    23222347    }