* Invision Power Services * IP.Board v3.4.8 * Template Parser : Converts HTML "logic" into PHP code * Last Updated: $Date: 2012-10-18 10:27:08 -0400 (Thu, 18 Oct 2012) $ * * * @author $Author: bfarber $ * @copyright (c) 2001 - 2009 Invision Power Services, Inc. * @license http://www.invisionpower.com/company/standards.php#license * @package IP.Board * @subpackage Kernel * @link http://www.invisionpower.com * @since Wednesday 23rd February 2005 13:53 * @version $Revision: 11481 $ * */ define( 'IPS_TEMPLATE_DEBUG' , 0 ); define( 'IPS_TEMPLATE_DEBUG_FILE', dirname( __FILE__ ) . '/../cache/template_debug.cgi' ); /** * INTERFACE: Template plugins * @author Matt Mecham * @since IPB 3.0.0 */ interface interfaceTemplatePlugins { /** * Return information about this modifier * * It MUST contain an array of available options in 'options'. If there are no allowed options, then use an empty array. * Failure to keep this up to date will most likely break your template tag. * * @return @e array */ public function getPluginInfo(); /** * Actually run the modifiers and return the code to insert into the template * * @param mixed Data to pass to plugin * @param mixed Options to pass to plugin * @return @e string */ public function runPlugin( $data, $options ); } class classTemplate { /** * Root path * * @var string */ public $root_path = './'; /** * Skin cache files directory * * @var string */ public $cache_dir = 'skin_cache'; /** * Current ID of skinset * * @var integer */ public $cache_id = 1; /** * Skin set id in database * * @var integer */ public $database_id = 1; /** * Cache path * * @var string */ public $IPS_CACHE_PATH = ''; /** * Foreach function blocks * Holds the foreach code * * @var array */ protected $foreach_blocks = array(); /** * Allow PHP code to execute * * @var boolean */ public $allow_php_code = true; /** * Modifiers path * * @var string */ static protected $template_plugins_class_path; /** * Modifiers clases * * @var array */ static protected $template_plugin_classes = array(); /** * Current skin group * * @var array */ protected $_skinGroup = ''; /** * Escaped double quote replacement * Part of a hackish fix to retain manual escpaes in PHP code blocks * but not elsewhere in the code * * @var string */ protected $_dqReplacement = '{{^|^escapedDQ^|^}}'; /** * Constructor * * @param string Path to template plugins directory * @return @e boolean */ public function __construct( $template_plugins_class_path='' ) { self::$template_plugins_class_path = $template_plugins_class_path; $this->IPS_CACHE_PATH = $this->root_path . $this->cache_dir . '/cacheid_' . $this->cache_id; return true; } /** * Set current skin group * * @param string Skin group name * @return @e void */ public function setWorkingGroup( $group ) { $this->_skinGroup = $group; } /** * Takes raw PHP data (from a MASTER cache class) and formats it ready * for eval'ing in the scripts. * * @param string The actual contents of the class, php tags 'an all. * @param string Full class name * @param integer ID to use * @return @e string */ public function convertCacheToEval( $data='', $full_class_name='', $id=1 ) { //----------------------------------------- // INIT //----------------------------------------- $this->_skinGroup = preg_replace( '#^(.*)_\d+?$#', "\\1", $full_class_name ); $final_content = $this->_returnFunctionData( $data ); //----------------------------------------- // Function Hooks //------------------------------------------ $funcHooks = '$this->_funcHooks = array();' . "\n"; if( is_array( $this->_hookIds[ $this->_skinGroup ] ) ) { foreach( $this->_hookIds[ $this->_skinGroup ] as $func_name => $hookIds ) { if( is_array( $hookIds ) && count( $hookIds ) ) { $funcHooks .= "\$this->_funcHooks['{$func_name}'] = array(".implode( ',', $hookIds ).");\n"; } } } //----------------------------------------- // Return the stuff... //----------------------------------------- $out = "class {$full_class_name} extends skinMaster {\n\n"; $out .= <<|$)#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( "/)#is', $code, $matches ); if ( count( $matches[1] ) ) { foreach( $matches[1] as $m ) { $new = $m; $new = str_replace( '-|(bs)|--|(q)|-' , '\\"' , $new ); $new = str_replace( '-|(q)|-' , '"' , $new ); $new = str_replace( '-|(bs)|-', '\\\\' , $new ); $code = str_replace( $m, $new, $code ); } } /* Now make safe escaped strings */ $code = preg_replace( '#\\\\\$#', "\\$", $code ); return $code; } /** * Slashes and escaped quotes are a PAIN (part one) * * @param string Content * @return @e string */ protected function _preMakeJsSlashesSafe( $code ) { preg_match_all( '#)#is', $code, $matches ); if ( count( $matches[1] ) ) { foreach( $matches[1] as $m ) { $new = str_replace( '\\"' , '-|(q)|-' , $m ); $new = str_replace( '\\' , '-|(bs)|-', $new ); $code = str_replace( $m, $new, $code ); } } return $code; } /** * Add a debug message if debugging enabled * * @param string Message * @return @e mixed */ protected function _addDebug( $msg ) { if ( IPS_TEMPLATE_DEBUG AND IPS_TEMPLATE_DEBUG_FILE ) { $full_msg = "==================================================================\n" . "Date: " . gmdate( 'r' ) . ' - ' . $_SERVER['REMOTE_ADDR'] . "\n" . $msg . "\n" . "==================================================================\n"; if ( $FH = @fopen( IPS_TEMPLATE_DEBUG_FILE, 'a+' ) ) { fwrite( $FH, $full_msg, strlen( $full_msg ) ); fclose( $FH ); } return TRUE; } } }