Version 3.1.4

This commit is contained in:
Neo committed 2025-12-19 00:32:22 -08:00
1 parent 1d4720f3e2
commit ae5c01cc78
2563 files changed
+283048 -240689

No files matched your search

+124 -39
View File
@@ -1,18 +1,21 @@
<?php
/**
* <pre>
* Invision Power Services
* IP.Board v3.0.5
* IP.Board v3.1.4
* Template Parser : Converts HTML "logic" into PHP code
* Last Updated: $Date: 2009-11-24 17:17:08 -0500 (Tue, 24 Nov 2009) $
* Last Updated: $Date: 2010-10-12 18:11:26 -0400 (Tue, 12 Oct 2010) $
* </pre>
*
* @author $Author: josh $
* @author $Author: bfarber $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.iinvisionpower.com/community/board/license.html
* @package Invision Power Services Kernel
* @link http://www.iinvisionpower.com
* @license http://www.invisionpower.com/community/board/license.html
* @package IP.Board
* @subpackage Kernel
* @link http://www.invisionpower.com
* @since Wednesday 23rd February 2005 13:53
* @version $Revision: 346 $
* @version $Revision: 476 $
*
* @todo [Future] Explore converting this to an XSLT parser (ala Digi)
*/
@@ -22,8 +25,8 @@ define( 'IPS_TEMPLATE_DEBUG_FILE', dirname( __FILE__ ) . '/../cache/template_deb
/**
* INTERFACE: Template plugins
* @author: Matt Mecham
* @since: IPB 3.0.0
* @author Matt Mecham
* @since IPB 3.0.0
*/
interface interfaceTemplatePlugins
@@ -172,10 +175,26 @@ class classTemplate
// INIT
//-----------------------------------------
$this->_skinGroup = preg_replace( "#^(.*)_\d+?$#", "\\1", $full_class_name );
$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...
//-----------------------------------------
@@ -198,6 +217,8 @@ function __construct( ipsRegistry \$registry )
\$this->memberData =& \$this->registry->member()->fetchMemberData();
\$this->cache = \$this->registry->cache();
\$this->caches =& \$this->registry->cache()->fetchCaches();
{$funcHooks}
}
EOF;
@@ -229,7 +250,7 @@ EOF;
// Remove PHP tags
//-----------------------------------------
$data = preg_replace( "#<"."\?php\n+?(.+?)\n+?\?".">#is", "\\1", $data );
$data = preg_replace( "#<".'\?php\n+?(.*)\n+?\?>#is', "\\1", $data );
//-----------------------------------------
// Pick through and get all function names
@@ -244,6 +265,7 @@ EOF;
$farray = explode( "\n", $data );
//-----------------------------------------
// Functions...
//-----------------------------------------
@@ -263,7 +285,7 @@ EOF;
$script_token = 1;
}
if ( preg_match( "/<\/script>/i", $f ) )
if ( preg_match( '/<\/script>/i', $f ) )
{
$script_token = 0;
}
@@ -274,7 +296,7 @@ EOF;
if ( $script_token == 0 )
{
if ( preg_match( "/^function\s*([\w\_]+)\s*\((.*)\)/i", $f, $matches ) )
if ( preg_match( '/^function\s*([\w\_]+)\s*\((.*)\)/i', $f, $matches ) )
{
$functions[ $matches[1] ] = '';
$config[ $matches[1] ] = $matches[2];
@@ -314,7 +336,7 @@ EOF;
}
else
{
preg_match( "/".'\$'."IPBHTML\s+?\.?=\s+?<<<EOF(.+?)EOF;\s?/si", $ftext, $matches );
preg_match( "/".'\$'.'IPBHTML\s+?\.?=\s+?<<<EOF(.+?)EOF;\s?/si', $ftext, $matches );
$final_content .= $this->convertHtmlToPhp( $fname, $func_data, isset( $matches[1] ) ? $matches[1] : '' );
}
@@ -384,15 +406,15 @@ EOF;
// Fix up {IPSText::xxxxx}
//-----------------------------------------
$_func_code = preg_replace( "#\{IPS(Data|ActiveMember|Member|Lib|Text)\:\:([^\}]+?)\}#", '" . ' . "IPS\\1::\\2" . ' . "', $_func_code );
$_func_code = preg_replace( "#\{\\\$this->(settings|request)->([^\}]+?)\}#" , '" . ' . "\$this->\\1->\\2" . ' . "', $_func_code );
$_func_code = preg_replace( '#\{IPS(Data|ActiveMember|Member|Lib|Text)\:\:([^\}]+?)\}#', '" . ' . "IPS\\1::\\2" . ' . "', $_func_code );
$_func_code = preg_replace( '#\{\\\$this->(settings|request)->([^\}]+?)\}#' , '" . ' . "\$this->\\1->\\2" . ' . "', $_func_code );
//-----------------------------------------
// Clear up manual escapes not in PHP blocks
// Step One
//-----------------------------------------
$_func_code = preg_replace( "#\\\{1,}\"#s", '\\"', $_func_code );
$_func_code = preg_replace( '#\\\{1,}\"#s', '\\"', $_func_code );
//-----------------------------------------
// Continue...
@@ -404,9 +426,9 @@ EOF;
$top = "/* -- {$func_name} --*/\n";
$start = "function {$func_name}($func_data) {\n\$IPBHTML = \"\";\n";
$middle = '$IPBHTML .= '.$_func_code.';';
$end = "\nreturn \$IPBHTML;\n}\n";
//-------------------------------
// Add foreach blocks...
//-------------------------------
@@ -421,8 +443,8 @@ EOF;
$end = $this->_processPluginTags( $end );
$end = preg_replace( "#\{IPS(Data|ActiveMember|Member|Lib|Text)\:\:([^\}]+?)\}#", '" . ' . "IPS\\1::\\2" . ' . "', $end );
$end = preg_replace( "#\{\\\$this->(settings|request)->([^\}]+?)\}#" , '" . ' . "\$this->\\1->\\2" . ' . "', $end );
$end = preg_replace( '#\{IPS(Data|ActiveMember|Member|Lib|Text)\:\:([^\}]+?)\}#', '" . ' . "IPS\\1::\\2" . ' . "', $end );
$end = preg_replace( '#\{\\\$this->(settings|request)->([^\}]+?)\}#' , '" . ' . "\$this->\\1->\\2" . ' . "', $end );
//----------------------------------------
// Check embedded foreach blocks
@@ -466,6 +488,54 @@ EOF;
$middle = $this->_trimEmptyIfs( $middle );
//-----------------------------------------
// Figure out if we're saving hook data
//-----------------------------------------
$functionArguments = explode( ',', $func_data );
$_funcDataNames = array();
if( is_array( $functionArguments ) )
{
foreach( $functionArguments as $r )
{
if( trim($r) )
{
/* Clean */
$r = str_replace( '$', '', trim($r) );
if( strpos( $r, '=' ) )
{
$r = substr( $r, 0, strpos( $r, '=' ) );
}
$_funcDataNames[] = trim( $r );
}
}
}
$hookPHP = '';
if( isset($this->_hookIds[ $this->_skinGroup ][ $func_name ]) AND is_array( $this->_hookIds[ $this->_skinGroup ][ $func_name ] ) )
{
$__count = '$count_'. md5( $func_name . str_replace( '.', '_', uniqid( mt_rand(), TRUE ) ) );
$hookPHP = <<<EOF
if( IPSLib::locationHasHooks( '{$this->_skinGroup}', \$this->_funcHooks['{$func_name}'] ) )
{
{$__count} = is_array(\$this->functionData['{$func_name}']) ? count(\$this->functionData['{$func_name}']) : 0;\n
EOF;
foreach( $_funcDataNames as $k => $v )
{
$hookPHP .= "\$this->functionData['{$func_name}'][{$__count}]['{$v}'] = \${$v};\n";
}
$hookPHP .= <<<EOF
}\n
EOF;
}
//-----------------------------------------
// Debug?
//-----------------------------------------
@@ -475,8 +545,8 @@ EOF;
//-------------------------------
// Return
//-------------------------------
return $top.$start.$php_tags.$middle.$end;
return $top.$start.$hookPHP.$php_tags.$middle.$end;
}
/**
@@ -611,7 +681,7 @@ EOF;
foreach( $_tmp_func_data as $_i )
{
preg_match( "#".'\$'."(\w+)(=|,|$)#i", $_i, $match );
preg_match( "#".'\$'.'(\w+)(=|,|$)#i', $_i, $match );
if( count($match) )
{
@@ -802,7 +872,7 @@ EOF;
$_normal_func_data .= ",{$keep}=''";
}
}
$block = $this->_processForeachLogic($block, $_normal_func_data, $func_name);
}
@@ -834,7 +904,7 @@ EOF;
$function_name = '__f__'. md5( $__i_count . str_replace( '.', '_', uniqid( mt_rand(), TRUE ) ) );
$php_statement = '<xxforeach_'.$function_name.'xx>$this->'.$function_name.'('.$clean_func_data.')</xxforeach_'.$function_name.'xx>';
$php_block = $this->_processHtmlLogic( addslashes($block), $func_name );
//-----------------------------------------
// PHP tags?
//-----------------------------------------
@@ -846,6 +916,7 @@ EOF;
/* Got a prefix? */
$pre_foreach_hook = '';
$post_foreach_hook = '';
if ( strstr( $statement, ':' ) )
{
list( $prefix, $statement ) = explode( ':', $statement );
@@ -858,26 +929,38 @@ EOF;
$php_block = "<!--hook.foreach.{$this->_skinGroup}.{$func_name}.{$prefix}.inner.pre-->" .
$php_block .
"<!--hook.foreach.{$this->_skinGroup}.{$func_name}.{$prefix}.inner.post-->";
$this->_hookIds[ $this->_skinGroup ][ $func_name ][] = "'{$prefix}'";
}
/* Store foreach data */
// $_tmp = explode( 'as', $statement );
// $_saveV = trim( $_tmp[0] );
$this->foreach_blocks[] = <<<EOF
function {$function_name}($normal_func_data)
{
\$_ips___x_retval = '{$pre_foreach_hook}';
\$__iteratorCount = 0;
foreach( $statement )
{
{$php_tags}
\$__iteratorCount++;
\$_ips___x_retval .= "{$php_block}\n";
}
\$_ips___x_retval .= '{$post_foreach_hook}';
unset( \$__iteratorCount );
return \$_ips___x_retval;
}
EOF;
$template = substr_replace( $template, $php_statement, $found_foreach, $found_end_foreach + strlen($tag_end_foreach) - $found_foreach);
$template = substr_replace( $template, $php_statement, $found_foreach, $found_end_foreach + strlen($tag_end_foreach) - $found_foreach);
/* Reset total length */
$total_length = strlen( $template );
$found_end_foreach = $found_foreach + strlen($php_statement) - 1;
}
return str_replace("\\'", "'", $template);
}
@@ -949,13 +1032,13 @@ EOF;
*
* Call back from the replaceRecursively function
*
* @access public, static
* @access public
* @param string Matched text string
* @param string Opening delimiter
* @param string Closing delimiter
* @return string Converted text
*/
static function _processPluginTagsCallback( $text, $textOpen, $textClose )
static public function _processPluginTagsCallback( $text, $textOpen, $textClose )
{
//-----------------------------------------
// Ok, extract options
@@ -1202,7 +1285,7 @@ EOF;
//----------------------------------------
$statement = $this->unconvertTags( substr( $template, $_start, $_end - $_start ) );
//----------------------------------------
// Not got?
//----------------------------------------
@@ -1378,7 +1461,9 @@ EOF;
$hook_pre_else = "<!--hook.if.{$this->_skinGroup}.{$func_name}.{$prefix}.pre.else-->";
$hook_post_else = "<!--hook.if.{$this->_skinGroup}.{$func_name}.{$prefix}.post.else-->";
$hook_pre_endif = "<!--hook.if.{$this->_skinGroup}.{$func_name}.{$prefix}.pre.endif-->";
$hook_post_endif = "<!--hook.if.{$this->_skinGroup}.{$func_name}.{$prefix}.post.endif-->";
$hook_post_endif = "<!--hook.if.{$this->_skinGroup}.{$func_name}.{$prefix}.post.endif-->";
$this->_hookIds[ $this->_skinGroup ][ $func_name ][] = "'{$prefix}'";
}
//----------------------------------------
@@ -1413,7 +1498,7 @@ EOF;
// Make some tags safe..
//----------------------------------------
$t = preg_replace( "/\{ipb\.vars\[(['\"])?(sql_driver|sql_host|sql_database|sql_pass|sql_user|sql_port|sql_tbl_prefix|smtp_host|smtp_port|smtp_user|smtp_pass|html_dir|base_dir|upload_dir)(['\"])?\]\}/", "" , $t );
$t = preg_replace( '/\{ipb\.vars\[([\'\"])?(sql_driver|sql_host|sql_database|sql_pass|sql_user|sql_port|sql_tbl_prefix|smtp_host|smtp_port|smtp_user|smtp_pass|html_dir|base_dir|upload_dir)([\'\"])?\]\}/', "" , $t );
return $t;
}
@@ -1431,11 +1516,11 @@ EOF;
// Make some tags safe..
//----------------------------------------
$t = preg_replace( "/\{ips\.vars\[(['\"])?(sql_driver|sql_host|sql_database|sql_pass|sql_user|sql_port|sql_tbl_prefix|smtp_host|smtp_port|smtp_user|smtp_pass|html_dir|base_dir|upload_dir)(['\"])?\]\}/", "" , $t );
$t = preg_replace( '/\{ips\.vars\[([\'\"])?(sql_driver|sql_host|sql_database|sql_pass|sql_user|sql_port|sql_tbl_prefix|smtp_host|smtp_port|smtp_user|smtp_pass|html_dir|base_dir|upload_dir)([\'\"])?\]\}/', "" , $t );
# IPB 2.1+ Kernel
$t = preg_replace( "/{ip(s|b|d)\.script_url}/i" , ipsRegistry::$settings['base_url'] , $t);
$t = preg_replace( "/{ip(s|b|d)\.session_id}/i" , '{$this->member->session_id }', $t);
$t = preg_replace( '/{ip(s|b|d)\.script_url}/i' , ipsRegistry::$settings['base_url'] , $t);
$t = preg_replace( '/{ip(s|b|d)\.session_id}/i' , '{$this->member->session_id }', $t);
//$t = preg_replace( "#ip(?:s|b|d)\.(member|vars|skin|lang|input)#i", '$this->ipsclass->\\1' , $t );
return $t;
@@ -1466,7 +1551,7 @@ EOF;
{
$code = $this->_trimSlashes($code);
$code = preg_replace("/".'\$'."IPBHTML\s+?\.?=\s+?<<<EOF(.+?)EOF;\s?/si", "\\1", $code );
$code = preg_replace("/".'\$'.'IPBHTML\s+?\.?=\s+?<<<EOF(.+?)EOF;\s?/si', "\\1", $code );
$code = trim($code);
$code = $this->_trimNewlines($code);
@@ -1497,7 +1582,7 @@ EOF;
*/
private function _trimEmptyIfs($code)
{
return preg_replace("/\"\n\s+?\"/s", "\"\"", $code );
return preg_replace('/\"\n\s+?\"/s', "\"\"", $code );
}
/**