$Date: 2005-10-10 14:03:20 +0100 (Mon, 10 Oct 2005) $
| > $Revision: 22 $
| > $Author: matt $
+---------------------------------------------------------------------------
|
| > Template Engine module NEW (KERNEL)
| > Module written by Matt Mecham
| > Date started: Wednesday 23rd February 13:53
|
| > Module Version Number: 1.0.0
+--------------------------------------------------------------------------
| New template module to build, rebuild and generate caches of templates
| which include the new IPB HTML Logic system.
| Example:
|
|
| html here
||
| html here
|
|
+--------------------------------------------------------------------------
*/
define( 'IPS_TEMPLATE_DEBUG' , 0 );
define( 'IPS_TEMPLATE_DEBUG_FILE', dirname( __FILE__ ) . '/../cache/template_debug.cgi' );
/**
* Template Engine (NOT USED CURRENTLY: FOR IPB 3.0, IP.Dynamic)
*
* Methods and functions for converting HTML logic into PHP code
*
* @package IPS_KERNEL
* @author Matt Mecham
* @copyright Invision Power Services, Inc.
* @version 1.0
* @ignore
*/
/**
*
*/
/**
* Template Engine (NOT USED CURRENTLY: FOR IPB 3.0, IP.Dynamic)
*
* Methods and functions for converting HTML logic into PHP code
*
* @package IPS_KERNEL
* @author Matt Mecham
* @version 1.0
* @ignore
*/
class class_template
{
# The basics
var $root_path = './';
var $cache_dir = 'skin_cache';
var $cache_id = '1';
var $database_id = '1';
var $cache_path = '';
/**
* Foreach function blocks
* Holds the foreach code
*
* @var array
*/
var $foreach_blocks = array();
/**
* Allow PHP code to execute
*/
var $allow_php_code = 1;
function class_template()
{
$this->cache_path = $this->root_path . $this->cache_dir . '/cacheid_' . $this->cache_id;
}
/*-------------------------------------------------------------------------*/
// Eval on the fly
/*-------------------------------------------------------------------------*/
/**
* convert_cache_to_eval
*
* Takes raw PHP data (from a MASTEr cache class) and formats it ready
* for eval'ing in the scripts.
*
* @param $data string The actual contents of the class, php tags 'an all.
*/
function convert_cache_to_eval($data='', $full_class_name='', $id=1)
{
//-----------------------------------------
// INIT
//-----------------------------------------
$final_content = $this->_return_function_data( $data );
//-----------------------------------------
// Grab "linked" template bits
//-----------------------------------------
/*
<__templatebits__>
skin_global:personal_portal_gender_image
skin_global:personal_portal_online_image
*/
if ( strstr( $data, '<__templatebits__>' ) )
{
$_templates = array();
preg_match( "#<__templatebits__>(.+?)#is", $data, $match );
if ( $match[1] )
{
preg_match_all( "#(.+?)#is", $data, $matches );
for ( $i = 0; $i < count( $matches[0] ); $i++)
{
list( $file, $name ) = explode( ':', $matches[1][$i] );
if ( $file AND $name )
{
$_templates[ $file ][] = $name;
}
}
}
//-----------------------------------------
// Got stuff to load?
//-----------------------------------------
if ( is_array( $_templates ) AND count( $_templates ) )
{
foreach( $_templates as $file => $idx )
{
$_data = implode( '', file( CACHE_PATH."cache/skin_cache/cacheid_".$id."/".$file.".php" ) );
$final_content .= $this->_return_function_data( $_data, $_templates[ $file ] );
}
}
}
//-----------------------------------------
// Return the stuff...
//-----------------------------------------
$out = "class {$full_class_name} {\n\n";
$out .= "\t".'var $ipsclass;'."\n";
$out .= $final_content;
$out .= "\n\n}";
return $out;
}
/**
* _return_function_data
*
* Extracts function data
*
* @param $data string The actual contents of the class, php tags 'an all.
*/
function _return_function_data( $data='', $function_find=array() )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$final_content = '';
//-----------------------------------------
// Remove PHP tags
//-----------------------------------------
$data = preg_replace( "#<"."\?php\n+?(.+?)\n+?\?".">#is", "\\1", $data );
//-----------------------------------------
// Pick through and get all function names
//-----------------------------------------
$data = str_replace( "\r" , "\n", $data );
$data = str_replace( "\n\n", "\n", $data );
//-----------------------------------------
// Continue...
//-----------------------------------------
$farray = explode( "\n", $data );
//-----------------------------------------
// Functions...
//-----------------------------------------
$functions = array();
$script_token = 0;
$flag = 0;
foreach( $farray as $f )
{
//-----------------------------------------
// Skip javascript functions...
//-----------------------------------------
if ( preg_match( "/