Changeset 438 for trunk/patTemplate

Show
Ignore:
Timestamp:
08/08/06 22:50:46 (2 years ago)
Author:
schst
Message:

Implemented request #154: functions can be used as default values

Files:

Legend:

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

    r437 r438  
    3131 */ 
    3232define( 'PATTEMPLATE_READER_ERROR_NO_CLOSING_TAG', 6003 ); 
    33   
     33 
    3434/** 
    3535 * Invalid closing tag 
     
    112112    */ 
    113113    var $_templates =   array(); 
    114      
     114 
    115115   /** 
    116116    * path to the template 
     
    119119    */ 
    120120    var $_path  =   array(); 
    121      
     121 
    122122   /** 
    123123    * start tag for variables 
     
    126126    */ 
    127127    var $_startTag; 
    128      
     128 
    129129   /** 
    130130    * end tag for variables 
     
    133133    */ 
    134134    var $_endTag; 
    135      
     135 
    136136   /** 
    137137    * default attributes 
     
    200200    */ 
    201201    var $_funcAliases = array(); 
    202      
     202 
    203203   /** 
    204204    * options 
     
    208208    */ 
    209209    var $_options = array(); 
    210      
     210 
    211211   /** 
    212212    * reader is in use 
     
    216216    */ 
    217217    var $_inUse = false; 
    218      
     218 
    219219   /** 
    220220    * set a reference to the patTemplate object that instantiated the reader 
     
    229229 
    230230   /** 
    231     * read templates from any input  
     231    * read templates from any input 
    232232    * 
    233233    * @abstract must be implemented in the template readers 
     
    243243 
    244244   /** 
    245     * load template from any input  
     245    * load template from any input 
    246246    * 
    247247    * If the a template is loaded, the content will not get 
     
    271271 
    272272        $this->_options  = $options; 
    273          
     273 
    274274        if (isset($options['functionAliases'])) { 
    275275            $this->_funcAliases = $options['functionAliases']; 
     
    289289        $this->_funcAliases[strtolower($alias)] = $function; 
    290290    } 
    291      
     291 
    292292   /** 
    293293    * set the root attributes 
     
    316316         */ 
    317317        $string = $this->_tmpl->applyInputFilters( $string ); 
    318          
     318 
    319319        $this->_inheritAtts   = array(); 
    320320        $this->_elStack       = array(); 
     
    325325        $this->_path          = array(); 
    326326        $this->_processedData = ''; 
    327          
     327 
    328328        $this->_defaultAtts = $this->_tmpl->getDefaultAttributes(); 
    329          
     329 
    330330        if( !isset( $this->_defaultAtts['autoload'] ) ) { 
    331331            $this->_defaultAtts['autoload'] = 'on'; 
     
    337337        $attributes         = $this->_rootAtts; 
    338338        $attributes['name'] = '__ptroot'; 
    339          
     339 
    340340        $rootTemplate = $this->_initTemplate( $attributes ); 
    341341        $this->_root  = null; 
     
    429429 
    430430        $this->_closeTemplate( $rootTemplate, $this->_data[0] ); 
    431          
     431 
    432432        /** 
    433433         * check for tags that are still open 
     
    442442 
    443443        $this->_inUse = false; 
    444          
     444 
    445445        return  $this->_templates; 
    446446    } 
    447      
     447 
    448448   /** 
    449449    * parse an attribute string and build an array 
     
    509509            case 'sub': 
    510510                $result =   $this->_initSubTemplate( $attributes ); 
    511                 break;      
     511                break; 
    512512 
    513513            /** 
     
    516516            case 'link': 
    517517                $result =   $this->_initLink( $attributes ); 
    518                 break;      
     518                break; 
    519519 
    520520            /** 
     
    523523            case 'var': 
    524524                $result =   false; 
    525                 break;  
     525                break; 
    526526 
    527527            /** 
     
    531531            case 'comment': 
    532532                $result =   false; 
    533                 break;  
     533                break; 
    534534 
    535535            /** 
     
    541541                } 
    542542                $name = ucfirst( $name ); 
    543                  
     543 
    544544                if( !$this->_tmpl->moduleExists( 'Function', $name ) ) { 
    545545 
     
    565565            return  $result; 
    566566        } 
    567          
     567 
    568568        array_push( $this->_tmplStack, $result ); 
    569569        return true; 
    570570    } 
    571      
     571 
    572572   /** 
    573573    * handle end element 
     
    588588            ); 
    589589        } 
    590          
     590 
    591591        $tmpl   =   array_pop( $this->_tmplStack ); 
    592592 
     
    635635            case 'comment': 
    636636                $this->_handleComment( $el['attributes'], $data ); 
    637                 break;  
     637                break; 
    638638 
    639639            /** 
     
    642642            default: 
    643643                $name = ucfirst( $tmpl['function'] ); 
    644                  
     644 
    645645                if( !isset( $this->_functions[$name] ) ) { 
    646646                    $this->_functions[$name] = $this->_tmpl->loadModule( 'Function', $name ); 
    647647                    $this->_functions[$name]->setReader( $this ); 
    648648                } 
    649                  
     649 
    650650                $result = $this->_functions[$name]->call( $tmpl['attributes'], $data ); 
    651651 
     
    653653                    return $result; 
    654654                } 
    655                  
     655 
    656656                if( is_string( $result ) ) { 
    657657                    $this->_characterData( $result, false ); 
     
    678678        return  true; 
    679679    } 
    680      
     680 
    681681   /** 
    682682    * handle a Link 
     
    697697                                                ); 
    698698        } 
    699          
     699 
    700700        /** 
    701701         * create a new template 
     
    727727        } 
    728728 
    729         return true;    
    730     } 
    731      
     729        return true; 
     730    } 
     731 
    732732   /** 
    733733    * create a new template 
     
    748748            unset( $attributes['name'] ); 
    749749        } 
    750          
     750 
    751751        /** 
    752752         * name must be unique 
     
    779779                                            ) 
    780780                 ); 
    781          
     781 
    782782        /** 
    783783         * create a new template 
     
    831831            return $attributes; 
    832832        } 
    833              
     833 
    834834        $attributes = $this->_inheritAttributes( $attributes ); 
    835835 
     
    844844            $attributes['rowoffset'] = 1; 
    845845        } 
    846          
     846 
    847847        if( !isset( $attributes['addsystemvars'] ) ) { 
    848848            $attributes['addsystemvars'] = false; 
     
    862862            } 
    863863        } 
    864          
     864 
    865865        /** 
    866866         * external template 
     
    891891                $attributes['varscope'] = $this->_getFromParentTemplate('name'); 
    892892            } 
    893           
     893 
    894894            $attributes['varscope'] = strtolower( $attributes['varscope'] ); 
    895895            if (strstr($attributes['varscope'], ',')) { 
     
    936936                $attributes['requiredvars']   = array(); 
    937937                foreach( $tmp as $var ) { 
    938                      
     938 
    939939                    $pos = strpos( $var, '=' ); 
    940940                    if ($pos !== false) { 
     
    957957                                ); 
    958958                    } 
    959                          
     959 
    960960                } 
    961961                $attributes['autoclear'] = 'yes'; 
    962962                break; 
    963                  
     963 
    964964            /** 
    965965             * oddeven => switch to new modulo syntax 
     
    970970                $attributes['autoclear'] = 'yes'; 
    971971                break; 
    972                  
     972 
    973973            /** 
    974974             * modulo => requires a module attribute 
     
    10021002 
    10031003        $attributes['__prepared'] = true; 
    1004          
     1004 
    10051005        return $attributes; 
    10061006    } 
    1007      
     1007 
    10081008   /** 
    10091009    * build a template name 
     
    10111011    * @access   private 
    10121012    * @return   string  new template name 
    1013     */  
     1013    */ 
    10141014    function _buildTemplateName() 
    10151015    { 
     
    10301030 
    10311031        array_pop( $this->_inheritAtts ); 
    1032          
     1032 
    10331033        /** 
    10341034         * check for special templates 
     
    10511051                break; 
    10521052        } 
    1053          
     1053 
    10541054        /** 
    10551055         * store the content 
    10561056         */ 
    10571057        $tmpl['content'] = $data; 
    1058          
     1058 
    10591059        /** 
    10601060         * No external template 
     
    10691069         if( !empty( $this->_tmplStack ) ) { 
    10701070            $this->_addToParentTag( 'dependencies', $name ); 
    1071              
     1071 
    10721072            if( isset( $tmpl['attributes']['placeholder'] ) ) { 
    10731073                // maintain BC 
     
    10751075                    $tmpl['attributes']['placeholder'] = '__none'; 
    10761076                } 
    1077                  
     1077 
    10781078                if( $tmpl['attributes']['placeholder'] !== '__none' ) { 
    10791079                    $this->_characterData( $this->_startTag.(strtoupper( $tmpl['attributes']['placeholder'] ) ).$this->_endTag ); 
     
    10861086        unset( $tmpl['name'] ); 
    10871087        unset( $tmpl['tag'] ); 
    1088          
     1088 
    10891089        $this->_templates[$name] = $tmpl; 
    1090           
     1090 
    10911091        return true; 
    10921092    } 
     
    11421142        array_push( $this->_tmplStack, $parent ); 
    11431143        if ($parent['attributes']['type'] == 'modulo') { 
    1144              
     1144 
    11451145            if( preg_match( '/^\d$/', $attributes['condition'] ) ) { 
    11461146                if( (integer)$attributes['condition'] >= $parent['attributes']['modulo'] ) { 
     
    11801180    { 
    11811181        $data               =   $this->_adjustWhitespace( $data, $subTmpl['attributes']['whitespace'] ); 
    1182          
     1182 
    11831183        $subTmpl['data']    =   $data; 
    11841184        $condition          =   $subTmpl['condition']; 
     
    11911191        return true; 
    11921192    } 
    1193      
     1193 
    11941194   /** 
    11951195    * handle a variable 
     
    12091209        } 
    12101210 
    1211         $specs = array();       
    1212          
     1211        $specs = array(); 
     1212 
    12131213        /** 
    12141214         * get name 
     
    12281228            $specs['default']   =   $data; 
    12291229        } 
    1230          
     1230 
    12311231        /** 
    12321232         * add it to template, if it's not hidden 
     
    12351235            $this->_characterData( $this->_startTag . strtoupper( $name ) . $this->_endTag ); 
    12361236        } 
    1237          
     1237 
    12381238        if( isset( $attributes['hidden'] ) ) { 
    12391239            unset( $attributes['hidden'] ); 
     
    12421242        /** 
    12431243         * copy value from any other variable 
    1244          */     
     1244         */ 
    12451245        if (isset( $attributes['copyfrom'] )) { 
    12461246            $specs['copyfrom'] = strtoupper( $attributes['copyfrom'] ); 
    1247              
     1247 
    12481248            if (strstr( $specs['copyfrom'], '.' )) {          
    12491249                $specs['copyfrom']    = explode( '.', $specs['copyfrom'] ); 
     
    12551255                }             
    12561256            } 
    1257              
     1257 
    12581258            unset( $attributes['copyfrom'] ); 
    12591259        } 
    1260          
     1260 
    12611261        if( isset( $attributes['modifier'] ) ) { 
    12621262            $modifier = $attributes['modifier']; 
     
    12701270            $specs['modifier'] = array( 'mod' => $modifier, 'type' => $type, 'params' => $attributes ); 
    12711271        } 
    1272          
     1272 
    12731273        if (!empty( $specs )) { 
    12741274            $this->_addToParentTemplate( 
     
    13201320    { 
    13211321        $cnt = count( $this->_tmplStack ); 
    1322          
     1322 
    13231323        if ($cnt === 0) { 
    13241324            return false; 
     
    13311331                continue; 
    13321332            } 
    1333              
     1333 
    13341334            if ($key === null) { 
    1335                  
     1335 
    13361336                if (!in_array( $value, $this->_tmplStack[$pos][$property] )) { 
    13371337                    array_push( $this->_tmplStack[$pos][$property], $value ); 
     
    13431343            return true; 
    13441344        } 
    1345          
     1345 
    13461346        return  false; 
    13471347    } 
     
    13581358    { 
    13591359        $cnt = count( $this->_tmplStack ); 
    1360          
     1360 
    13611361        if ($cnt === 0) { 
    13621362            return false; 
     
    13911391    { 
    13921392        $cnt = count( $this->_tmplStack ); 
    1393          
     1393 
    13941394        if ($cnt === 0) { 
    13951395            return false; 
     
    13971397 
    13981398        $pos = $cnt - 1; 
    1399              
     1399 
    14001400        if ($key === null) { 
    1401              
     1401 
    14021402            if (!in_array( $value, $this->_tmplStack[$pos][$property] )) { 
    14031403                array_push( $this->_tmplStack[$pos][$property], $value ); 
     
    14551455 
    14561456        $attributes = array_merge( $parent, $attributes ); 
    1457          
     1457 
    14581458        return  $attributes; 
    14591459    } 
     
    14761476        } 
    14771477        array_push( $this->_tmplStack, $parent ); 
    1478          
     1478 
    14791479        if( $parent['type'] == $type ) { 
    14801480            return true; 
    14811481        } 
    1482              
     1482 
    14831483        return false; 
    14841484    } 
     
    15221522        return $this->_currentInput; 
    15231523    } 
    1524      
     1524 
    15251525   /** 
    15261526    * tests whether the reader should maintain backwards compatibility 
     
    15521552        return $this->_inUse; 
    15531553    } 
    1554      
     1554 
    15551555   /** 
    15561556    * get the template root for this reader