<?php
/**
* @author Benjamin Gillissen <hide@address.com>
*
* **************************************************************
Copyright (C) 2007 Benjamin Gillissen
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details at:
http://www.gnu.org/copyleft/gpl.html
* **************************************************************
*/
class block_tfeat extends tpl_parser {
private static $tagmatch = "#(\{--)(TFEAT)(=)([\w\W]+?)(;)([\w\W]+?)(--})#";
private static $tagfeat = '4';
private static $tagarg = '6';
private $feat;
private $arg;
public function __construct($hdl, $tag, $epos, $depth, $of){
//echo "$depth] New block Tfeat @ ".$tag->start()."<br/>\n";
parent::__construct($hdl, $tag->end(), $epos, $depth, $of);
$this->otag=$tag;
}
public function end(){ return $this->otag->end(); }
public function load_tagargs($tag=NULL){
//echo "$this->depth] Block Lang @ ".$this->otag->start()." : Loading tagargs<br/>\n";
if ( $tag === NULL ){ $tag = $this->otag->read(); }
preg_match(self::$tagmatch, $tag, $result);
if ( FALSE === $result ){
errors::raise('Malformed TFeat tag @ '.$this->otag->start(), CORE_LOG_ERROR, 'TPL');
return FALSE;
}
$this->feat = trim($result[self::$tagfeat]);
$this->arg = trim($result[self::$tagarg]);
return TRUE;
}
public function recurloads(){ return TRUE; }
public function plugparse($l, $g, $return){
//is implented ?
$f = "tfeat_$this->feat::genpart";
if ( $return ){ $r = FALSE; } else { $r = $this->of; }
$o = call_user_func($f, $this->get_sourceval($this->arg, $l, $g), $r);
if ( $return ){ return $o; };
//call_user_func($this->of, $o);
return TRUE;
}
public function plugparse_before($l, $g, $return, $bref){ return $this->plugparse($l, $g, $return); }
private function get_sourceval($k, $l, $g){
if ( $l !== NULL AND ereg('\$', $k) ){
//echo 'Searching in Local Data For '.$k."<br/>\n";
tpl_data::fetch_reset($l);
while( FALSE !== ($data = tpl_data::fetch_strings($l) ) ){
if ( CORE::iserror($data) ){
errors::raise("Invalid Local Data context in lang @ ".$this->otag->start().", no '\$' variable will be available !", CORE_LOG_ERROR, 'TPL');
break;
} elseif ( ereg('\$', $k) ){
$t =$k;
$k = str_replace("$".$data[0], $data[1], $k);
//errors::raise("$t => Replacing '$".$data[0]."' by '".$data[1]."' ==> $k", CORE_LOG_NOTICE, 'TPL');
}
}
}
if ( $g !== NULL AND ereg("%", $k) ){
//echo 'Searching in Global Data For '.$k."<br/>\n";
tpl_data::fetch_reset($g);
while( FALSE !== ($data = tpl_data::fetch_strings($g) ) ){
if ( CORE::iserror($data) ){
errors::raise("Invalid Global Data context in lang @ ".$this->otag->start().", no '%' variable will be available !", CORE_LOG_ERROR, 'TPL');
break;
} elseif ( ereg("%", $k) ){
$t=$k;
$k = str_replace("%".$data[0], $data[1], $k);
//errors::raise("$t => Replacing '%".$data[0]."' by '".$data[1]."' ==> $k", CORE_LOG_NOTICE, 'TPL');
}
}
}
return $k;
}
}
return 1;