Location: PHPKode > projects > Simple Way to Usenet > libs/core/parser/blocks/block_define.class.php
<?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_define extends tpl_parser {
	
	private static $tagmatch 		= "#(\{--DEFINE)(=)([\w\W]+?)(--})#";
	private static $tagcb		= '3';
		
	private $arg = Array();
	
	public function __construct($hdl, $tag, $epos, $depth, $of){
		parent::__construct($hdl, $tag->end(), $epos, $depth, $of);
		$this->otag=$tag;
	}

	public function end(){ return $this->otag->end(); }

	public function load_tagargs($tag=NULL){
		if ( $tag === NULL ){ $tag = $this->otag->read(); } 
		preg_match(self::$tagmatch, $tag, $result);
		unset($tag);
		if ( FALSE === $result ){
			errors::raise('Malformed Define tag @ '.$this->otag->start(), CORE_LOG_ERROR, 'TPL');
			return FALSE;
		}
		$tmp = split(',', trim($result[self::$tagcb]));
		unset($result);
		foreach($tmp as $cb ){ $this->arg[] = trim($cb); }
		return TRUE;
	}
	
	public function recurloads(){ return TRUE; }
		
	public function plugparse($l, $g, $return){
		$c=0;
		foreach($this->arg as $cbobj ){
			if ( FALSE === class_exists($cbobj, FALSE) ){ //must be included before eh!
				errors::raise("Block Define could not use callback object '$cbobj', not already included !", CORE_LOG_ERROR, 'TPL');
				return FALSE;
			/*
			} elseif( FALSE === function_exists("$cbobj::template_define") ){
				errors::raise("Block Define could not use callback function '$cbobj::template_define', not set on object !", CORE_LOG_ERROR, 'TPL');
				return FALSE; //FIXME why that do not work? 
			*/
			} else {
				$data = call_user_func("$cbobj::template_define");
				if ( !is_array($data) ){
					errors::raise("Callback function '$cbobj::template_define', return value is not an array !", CORE_LOG_ERROR, 'TPL');
				} else {		
					foreach($data as $k => $val){
						$c++;
						tpl_data::appendata($l, $val, 'DEF_'.$cbobj.'_'.$k);
					}
				}
			}
		}
		errors::raise("Block Define added $c variable(s) in this context", CORE_LOG_NOTICE, 'TPL');
		return TRUE; 
	}

	public function plugparse_before($l, $g, $return, $bref){ return $this->plugparse($l, $g, $return); }
}
return 1;
Return current item: Simple Way to Usenet