$Date: 2008-10-02 11:12:17 -0400 (Thu, 02 Oct 2008) $
| > $Revision: 2569 $
| > $Author: matt $
+---------------------------------------------------------------------------
|
| > Multi function library
| > Module written by Matt Mecham
| > Date started: 14th February 2002
|
| > Module Version Number: 1.0.0
| > Quality Checked: Wed 15 Sept. 2004
+--------------------------------------------------------------------------
*/
/**
* Main IPSclass class.
*
* This is the main class which is referenced via $ipsclass throughout
* all the IPB sub-classes and modules. It holds amongst others:
*
* // Object from class_forums.php class
* $ipsclass->forums
* // Object from class_display.php class
* $ipsclass->print
* // Object from SQL classes
* $ipsclass->db
* // Array of parsed caches (from table cache_store)
* $ipsclass->cache
* // Array of settings variables (taken from parsed setting cache)
* $ipsclass->vars
* // Array of member variables (taken from class_session::$member)
* $ipsclass->member
* // Array of sanitized _GET _POST data (run via parse_clean_value)
* $ipsclass->input
* // Array of language strings loaded via separate lang files
* $ipsclass->lang
* // Variable: Full base URL with session ID if required
* $ipsclass->base_url
* // Array of compiled template objects
* $ipsclass->compiled_templates
*
* Recommended method of passing $ipsclass through modules
*
* $module = new module();
* $module->ipsclass =& $ipsclass; // Create reference
*
*
* @package InvisionPowerBoard
* @author Matt Mecham
* @copyright Invision Power Services, Inc.
* @version 2.1
*/
if ( ! defined( 'IPSCLASS_LOADED' ) )
{
/**
* IPSCLASS loaded Flag
*/
define( 'IPSCLASS_LOADED', 1 );
}
/**
* Main ipsclass class.
*
* This class holds all the non-class specific functions
*
* @package InvisionPowerBoard
* @author Matt Mecham
* @version 2.1
*/
class ipsclass {
/**
* HUMAN version string (Eg: v2.1 BETA 1)
*
* @var string
*/
var $version = IPBVERSION;
/**
* LONG version number (Eg: 21000.BUILD_DATE.REASON)
*
* @var string
*/
var $acpversion = IPB_LONG_VERSION;
var $vn_full = '';
var $vn_build_date = '';
var $vn_build_reason = '';
/**
* Member Array
*
* @var array
*/
var $member = array();
/**
* _GET _POST Input Array
*
* @var array
*/
var $input = array( 'st' => 0,
't' => 0,
'f' => 0,
'id' => 0,
'tid' => 0,
'p' => 0,
'pid' => 0,
'gopid' => 0,
'qpid' => 0,
'b' => 0,
'cal_id' => 0,
'act' => NULL,
'L' => 0,
'adsess' => NULL,
'code' => NULL,
'CODE' => NULL,
'mode' => NULL,
'modfilter' => NULL,
'preview' => NULL,
'attachgo' => NULL,
'nocp' => NULL,
'tab' => NULL,
'sort' => NULL,
'dsterror' => 0,
'MID' => 0,
'MSID' => 0,
'uid' => 0,
'ip' => NULL,
'selectedpids' => NULL,
'nav' => NULL,
'calendar_id' => 0, );
/**
* Setting variables array
*
* @var array
*/
var $vars = array( );
/**
* Language strings array
*
* @var array
*/
var $lang = array();
/**
* Skin variables array
*
* @var array
*/
var $skin = array();
/**
* Compiled loaded templates
*
* @var array
*/
var $compiled_templates = array();
/**
* Loaded templates inc. ID
*
* @var array
*/
var $loaded_templates = array();
/**
* Cache array
*
* @var array
*/
var $cache = array();
/**
* Cache Library
*
* @var array
*/
var $cachelib;
/**
* Session ID
*
* @var string
*/
var $session_id = "";
/**
* Base URL
*
* @var string
*/
var $base_url = "";
/**
* Language ID; corresponds to cache/lang_cache/{folder}/
*
* @var string
*/
var $lang_id = "";
/**
* Session type (cookie or url)
*
* @var string
*/
var $session_type = "";
/**#@+
* @access public
* @var string
*/
var $lastclick = "";
var $location = "";
var $debug_html = "";
var $perm_id = "";
var $offset = "";
var $num_format = "";
var $query_string_safe = '';
var $query_string_formatted = '';
/**
* MD5 Check variable
*/
var $md5_check = '';
/**#@-*/
var $server_load = 0;
var $can_use_fancy_js = 0;
var $force_editor_change = 0;
var $offset_set = 0;
var $allow_unicode = 1;
var $get_magic_quotes = 0;
var $no_print_header = 0;
var $today_time;
var $yesterday_time;
/**#@+
* @access public
* @var object
*/
var $converge;
var $print;
var $sess;
var $forums;
var $class_convert_charset;
/**#@-*/
/**#@+
* @access public
* @var array
*/
var $topic_cache = array();
var $time_formats = array();
var $time_options = array();
var $today_array = array();
var $forum_read = array();
var $my_group_helpkey = null;
var $perm_id_array = array();
/**
* User's browser array (version, browser)
*/
var $browser;
var $is_bot = 0;
/**#@-*/
var $main_msg = '';
var $html_help_msg = '';
var $html_help_title = '';
var $kill_menu = 0;
var $body_extra = '';
var $parsed_members = array();
var $work_classes = array( 'class_template_engine' => null,
'class_captcha' => null );
/**
* Sensitive cookies
* var array
*/
var $sensitive_cookies = array( 'ipb_stronghold', 'session_id', 'ipb_admin_session_id', 'member_id', 'pass_hash' );
/*-------------------------------------------------------------------------*/
// Set up some standards to save CPU later
/*-------------------------------------------------------------------------*/
/**
* Initial ipsclass, set up some variables for later
* Populates:
* $this->time_options, $this->num_format, $this->get_magic_quotes, $this->ip_address
* $this->user_agent, $this->browser, $this->operating_system
*
* @return void;
*/
function initiate_ipsclass()
{
//-----------------------------------------
// Version numbers
//-----------------------------------------
//$this->acpversion = '210015.060501.u';
if ( strstr( $this->acpversion , '.' ) )
{
list( $n, $b, $r ) = explode( ".", $this->acpversion );
}
else
{
$n = $b = $r = '';
}
$this->vn_full = $this->acpversion;
$this->acpversion = $n;
$this->vn_build_date = $b;
$this->vn_build_reason = $r;
//-----------------------------------------
// Time options
//-----------------------------------------
$this->time_options = array( 'JOINED' => $this->vars['clock_joined'],
'SHORT' => $this->vars['clock_short'],
'LONG' => $this->vars['clock_long'],
'TINY' => isset($this->vars['clock_tiny']) ? $this->vars['clock_tiny'] : 'j M Y - G:i',
'DATE' => isset($this->vars['clock_date']) ? $this->vars['clock_date'] : 'j M Y',
);
$this->num_format = ( $this->vars['number_format'] == 'space' ) ? ' ' : $this->vars['number_format'];
//-----------------------------------------
// Sort out the accessing IP
// (Thanks to Cosmos and schickb)
//-----------------------------------------
$addrs = array();
if ( $this->vars['xforward_matching'] )
{
foreach( array_reverse( explode( ',', $this->my_getenv('HTTP_X_FORWARDED_FOR') ) ) as $x_f )
{
$x_f = trim($x_f);
if ( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $x_f ) )
{
$addrs[] = $x_f;
}
}
$addrs[] = $this->my_getenv('HTTP_CLIENT_IP');
$addrs[] = $this->my_getenv('HTTP_X_CLUSTER_CLIENT_IP');
$addrs[] = $this->my_getenv('HTTP_PROXY_USER');
}
$addrs[] = $this->my_getenv('REMOTE_ADDR');
//-----------------------------------------
// Do we have one yet?
//-----------------------------------------
foreach ( $addrs as $ip )
{
if ( $ip )
{
preg_match( "/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/", $ip, $match );
$this->ip_address = $match[1].'.'.$match[2].'.'.$match[3].'.'.$match[4];
if ( $this->ip_address AND $this->ip_address != '...' )
{
break;
}
}
}
//-----------------------------------------
// Make sure we take a valid IP address
//-----------------------------------------
if ( ( ! $this->ip_address OR $this->ip_address == '...' ) AND !$this->my_getenv('SHELL') )
{
print "Could not determine your IP address";
exit();
}
#Backwards compat:
$this->input["IP_ADDRESS"] = $this->ip_address;
//-----------------------------------------
// Make a safe query string
//-----------------------------------------
$this->query_string_safe = str_replace( '&', '&', $this->parse_clean_value( urldecode($this->my_getenv('QUERY_STRING')) ) );
$this->query_string_real = str_replace( '&' , '&' , $this->query_string_safe );
//-----------------------------------------
// Format it..
//-----------------------------------------
$this->query_string_formatted = str_replace( $this->vars['board_url'] . '/index.'.$this->vars['php_ext'].'?', '', $this->query_string_safe );
$this->query_string_formatted = preg_replace( "#s=([a-z0-9]){32}#", '', $this->query_string_formatted );
//-----------------------------------------
// Admin dir
//-----------------------------------------
$this->vars['_admin_link'] = $this->vars['board_url'] . '/' . IPB_ACP_DIRECTORY . '/index.php';
//-----------------------------------------
// Upload dir?
//-----------------------------------------
$this->vars['upload_dir'] = $this->vars['upload_dir'] ? $this->vars['upload_dir'] : ROOT_PATH.'uploads';
//-----------------------------------------
// Char set
//-----------------------------------------
$this->vars['gb_char_set'] = $this->vars['gb_char_set'] ? $this->vars['gb_char_set'] : 'iso-8859-1';
//-----------------------------------------
// Max display name length
//-----------------------------------------
$this->vars['max_user_name_length'] = $this->vars['max_user_name_length'] ? $this->vars['max_user_name_length'] : 26;
//-----------------------------------------
// PHP API
//-----------------------------------------
define('IPB_PHP_SAPI', php_sapi_name() );
//-----------------------------------------
// IPS CLASS INITIATED
//-----------------------------------------
if ( ! defined( 'IPSCLASS_INITIATED' ) )
{
define( 'IPSCLASS_INITIATED', 1 );
}
//-----------------------------------------
// Get user-agent, browser and OS
//-----------------------------------------
$this->user_agent = $this->parse_clean_value($this->my_getenv('HTTP_USER_AGENT'));
$this->browser = $this->fetch_browser();
$this->operating_system = $this->fetch_os();
//-----------------------------------------
// Can we use fancy JS? IE6, Safari, Moz
// and opera 7.6
//-----------------------------------------
if ( $this->browser['browser'] == 'ie' AND $this->browser['version'] >= 6.0 )
{
$this->can_use_fancy_js = 1;
}
else if ( $this->browser['browser'] == 'gecko' AND $this->browser['version'] >= 20030312 )
{
$this->can_use_fancy_js = 1;
}
else if ( $this->browser['browser'] == 'mozilla' AND $this->browser['version'] >= 1.3 )
{
$this->can_use_fancy_js = 1;
}
else if ( $this->browser['browser'] == 'opera' AND $this->browser['version'] >= 7.6 )
{
$this->can_use_fancy_js = 1;
}
else if ( $this->browser['browser'] == 'safari' AND $this->browser['version'] >= 120)
{
$this->can_use_fancy_js = 1;
}
//$this->can_use_fancy_js = 0;
}
/*-------------------------------------------------------------------------*/
// INIT: Establish Cache Abstraction
/*-------------------------------------------------------------------------*/
/**
* Determines and establishes cache class
*
* @todo Memcache, mmcache, diskcache
* @param void
* @return void
*/
function init_cache_setup()
{
//--------------------------------
// Eaccelerator...
//--------------------------------
if( function_exists('eaccelerator_get') AND isset($this->vars['use_eaccelerator']) AND $this->vars['use_eaccelerator'] == 1 )
{
require KERNEL_PATH.'class_cache_eaccelerator.php';
$this->cachelib = new cache_lib( $this->vars['board_url'] );
}
//--------------------------------
// Turck-mmcache...
//--------------------------------
if( function_exists('mmcache_get') AND isset($this->vars['use_mmcache']) AND $this->vars['use_mmcache'] == 1 )
{
require KERNEL_PATH.'class_cache_mmcache.php';
$this->cachelib = new cache_lib( $this->vars['board_url'] );
}
//--------------------------------
// Memcache
//--------------------------------
else if( function_exists('memcache_connect') AND isset($this->vars['use_memcache']) AND $this->vars['use_memcache'] == 1 )
{
require KERNEL_PATH.'class_cache_memcache.php';
$this->cachelib = new cache_lib( $this->vars['board_url'] );
$this->cachelib->connect( $this->vars );
}
//--------------------------------
// XCache...
//--------------------------------
else if( function_exists('xcache_get') AND isset($this->vars['use_xcache']) AND $this->vars['use_xcache'] == 1 )
{
require KERNEL_PATH.'class_cache_xcache.php';
$this->cachelib = new cache_lib( $this->vars['board_url'] );
}
//--------------------------------
// APC...
//--------------------------------
else if( function_exists('apc_fetch') AND isset($this->vars['use_apc']) AND $this->vars['use_apc'] == 1 )
{
require KERNEL_PATH.'class_cache_apc.php';
$this->cachelib = new cache_lib( $this->vars['board_url'] );
}
//--------------------------------
// Diskcache
//--------------------------------
else if( isset($this->vars['use_diskcache']) AND $this->vars['use_diskcache'] == 1 )
{
require KERNEL_PATH.'class_cache_diskcache.php';
$this->cachelib = new cache_lib( $this->vars['board_url'] );
}
if( is_object($this->cachelib) AND $this->cachelib->crashed )
{
// There was a problem - not installed maybe?
unset($this->cachelib);
$this->cachelib = NULL;
}
}
/*-------------------------------------------------------------------------*/
// INIT: Load cache
/*-------------------------------------------------------------------------*/
/**
* Loads and parses the required cache elements from the DB
*
* @todo Add in methods to save and write to disk file
* @param array Array of caches to load
* @return void
*/
function init_load_cache( $cachearray=array('settings', 'group_cache', 'systemvars', 'skin_id_cache', 'forum_cache', 'rss_export') )
{
//--------------------------------
// Eaccelerator...
//--------------------------------
if( is_object($this->cachelib) )
{
$temp_cache = array();
$new_cache_array = array();
foreach( $cachearray as $key )
{
$temp_cache[$key] = $this->cachelib->do_get( $key );
if( !$temp_cache[$key] )
{
$new_cache_array[] = $key;
}
else
{
if ( $key == 'settings' )
{
$tmp = unserialize( $temp_cache[$key] );
if ( is_array( $tmp ) and count( $tmp ) )
{
foreach( $tmp as $k => $v )
{
$this->vars[ $k ] = $v;
}
}
if( !isset($this->vars['blog_default_view']) )
{
$this->vars['blog_default_view'] = '';
}
unset( $tmp );
}
else
{
if ( strstr( $temp_cache[$key], "a:" ) )
{
$this->cache[ $key ] = unserialize( $temp_cache[$key] );
}
else if( $temp_cache[$key] == "EMPTY" )
{
$this->cache[ $key ] = NULL;
}
else
{
$this->cache[ $key ] = $temp_cache[$key];
}
}
}
}
$cachearray = $new_cache_array;
unset($new_cache_array, $temp_cache);
}
//echo "
";print_r($this->cache);exit;
//--------------------------------
// Generate cache list
//--------------------------------
$cachelist = "";
if( count($cachearray) )
{
$cachelist = "'".implode( "','", $cachearray )."'";
}
//--------------------------------
// Get from DB...
//--------------------------------
if ( $cachelist )
{
$this->DB->simple_construct( array( 'select' => '*', 'from' => 'cache_store', 'where' => "cs_key IN ( $cachelist )" ) );
$this->DB->simple_exec();
while ( $r = $this->DB->fetch_row() )
{
if ( $r['cs_key'] == 'settings' )
{
$tmp = unserialize( $r['cs_value'] );
if ( is_array( $tmp ) and count( $tmp ) )
{
foreach( $tmp as $k => $v )
{
$this->vars[ $k ] = $v;
}
}
if ( ! isset($this->vars['blog_default_view']) )
{
$this->vars['blog_default_view'] = '';
}
unset( $tmp );
}
else
{
if ( $r['cs_array'] )
{
$this->cache[ $r['cs_key'] ] = unserialize( $r['cs_value'] );
}
else
{
$this->cache[ $r['cs_key'] ] = $r['cs_value'];
}
}
if( is_object($this->cachelib) )
{
if( !$r['cs_value'] )
{
$r['cs_value'] = "EMPTY";
}
$this->cachelib->do_put( $r['cs_key'], $r['cs_value'] );
}
}
}
if ( ! isset( $this->cache['systemvars'] ) OR ! isset( $this->cache['systemvars']['task_next_run']) )
{
$update = array( 'task_next_run' => time() );
$update['loadlimit'] = $this->cache['systemvars']['loadlimit'];
$update['mail_queue'] = $this->cache['systemvars']['mail_queue'];
$update['last_virus_check'] = $this->cache['systemvars']['last_virus_check'];
$update['last_deepscan_check'] = $this->cache['systemvars']['last_deepscan_check'];
$this->update_cache( array( 'deletefirst' => 1, 'donow' => 1, 'name' => 'systemvars', 'array' => 1, 'value' => $update ) );
}
if( ! isset( $this->cache['forum_cache'] ) OR empty( $this->cache['forum_cache']) )
{
$this->update_forum_cache();
}
if( ! isset( $this->cache['group_cache'] ) OR empty( $this->cache['group_cache']) )
{
$this->cache['group_cache'] = array();
$this->DB->simple_construct( array( 'select' => "*",
'from' => 'groups'
) );
$this->DB->simple_exec();
while ( $i = $this->DB->fetch_row() )
{
$this->cache['group_cache'][ $i['g_id'] ] = $i;
}
$this->update_cache( array( 'name' => 'group_cache', 'array' => 1, 'deletefirst' => 1 ) );
}
//--------------------------------
// Set up cache path
//--------------------------------
if( ! defined( 'CACHE_PATH' ) )
{
if ( $this->vars['ipb_cache_path'] )
{
define( 'CACHE_PATH', $this->vars['ipb_cache_path'] );
}
else
{
define( 'CACHE_PATH', ROOT_PATH );
}
}
//-----------------------------------------
// IPS CACHE LOADED
//-----------------------------------------
if ( ! defined( 'IPSCLASS_CACHE_LOADED' ) )
{
define( 'IPSCLASS_CACHE_LOADED', 1 );
}
//--------------------------------
// Set up defaults
//--------------------------------
$this->vars['topic_title_max_len'] = $this->vars['topic_title_max_len'] ? $this->vars['topic_title_max_len'] : 50;
#$this->vars['gb_char_set'] = 'UTF-8';
}
/*-------------------------------------------------------------------------*/
// INIT: DB Connection
/*-------------------------------------------------------------------------*/
/**
* Initializes the database connection and populates $ipsclass->DB
*
* @return void
*/
function init_db_connection()
{
$_pre_load = $this->memory_debug_make_flag();
$this->vars['sql_driver'] = ! $this->vars['sql_driver'] ? 'mysql' : strtolower($this->vars['sql_driver']);
if ( ! class_exists( 'db_main' ) )
{
require_once( KERNEL_PATH.'class_db.php' );
require_once( KERNEL_PATH.'class_db_'.$this->vars['sql_driver'].".php" );
}
$classname = "db_driver_".$this->vars['sql_driver'];
$this->DB = new $classname;
$this->DB->obj['sql_database'] = $this->vars['sql_database'];
$this->DB->obj['sql_user'] = $this->vars['sql_user'];
$this->DB->obj['sql_pass'] = $this->vars['sql_pass'];
$this->DB->obj['sql_host'] = $this->vars['sql_host'];
$this->DB->obj['sql_tbl_prefix'] = $this->vars['sql_tbl_prefix'];
$this->DB->obj['force_new_connection'] = isset($this->vars['sql_force_new_connection']) ? $this->vars['sql_force_new_connection'] : 0;
$this->DB->obj['use_shutdown'] = USE_SHUTDOWN;
# Error log
$this->DB->obj['error_log'] = ROOT_PATH . 'cache/sql_error_log_'.date('m_d_y').'.cgi';
$this->DB->obj['use_error_log'] = IN_DEV ? 0 : 1;
# Debug log - Don't use this on a production board!
$this->DB->obj['debug_log'] = ROOT_PATH . 'cache/sql_debug_log_'.date('m_d_y').'.cgi';
$this->DB->obj['use_debug_log'] = 0;
//-----------------------------------
// Load query file
//-----------------------------------
if ( defined( 'IPB_LOAD_SQL' ) )
{
$this->DB->obj['query_cache_file'] = ROOT_PATH.'sources/sql/'.$this->vars['sql_driver'].'_'. IPB_LOAD_SQL .'.php';
}
else if ( IPB_THIS_SCRIPT == 'admin' )
{
$this->DB->obj['query_cache_file'] = ROOT_PATH.'sources/sql/'.$this->vars['sql_driver'].'_admin_queries.php';
}
else
{
$this->DB->obj['query_cache_file'] = ROOT_PATH.'sources/sql/'.$this->vars['sql_driver'].'_queries.php';
}
//-----------------------------------
// Required vars?
//-----------------------------------
if ( is_array( $this->DB->connect_vars ) and count( $this->DB->connect_vars ) )
{
foreach( $this->DB->connect_vars as $k => $v )
{
$this->DB->connect_vars[ $k ] = isset($this->vars[ $k ]) ? $this->vars[ $k ] : '';
}
}
//--------------------------------
// Backwards compat
//--------------------------------
if ( !isset($this->DB->connect_vars['mysql_tbl_type']) OR !$this->DB->connect_vars['mysql_tbl_type'] )
{
$this->DB->connect_vars['mysql_tbl_type'] = 'myisam';
}
//--------------------------------
// Make CONSTANT
//--------------------------------
define( 'SQL_PREFIX' , $this->DB->obj['sql_tbl_prefix'] );
define( 'SQL_DRIVER' , $this->vars['sql_driver'] );
define( 'IPS_MAIN_DB_CLASS_LOADED', TRUE );
//--------------------------------
// Get a DB connection
//--------------------------------
$this->DB->connect();
//-----------------------------------------
// IPS DB LOADED
//-----------------------------------------
if ( ! defined( 'IPSCLASS_DB_LOADED' ) )
{
define( 'IPSCLASS_DB_LOADED', 1 );
}
//-----------------------------------------
// Clean up
//-----------------------------------------
unset( $classname );
$this->memory_debug_add( "CORE: DB Connection Made", $_pre_load );
}
/*-------------------------------------------------------------------------*/
// Get browser
// Return: unknown, windows, mac
/*-------------------------------------------------------------------------*/
/**
* Fetches the user's operating system
*
* @return string
*/
function fetch_os()
{
$useragent = strtolower($this->my_getenv('HTTP_USER_AGENT'));
if ( strstr( $useragent, 'mac' ) )
{
return 'mac';
}
if ( preg_match( '#wi(n|n32|ndows)#', $useragent ) )
{
return 'windows';
}
return 'unknown';
}
/*-------------------------------------------------------------------------*/
// Get browser
// Return: unknown, opera, IE, mozilla, konqueror, safari
/*-------------------------------------------------------------------------*/
/**
* Fetches the user's browser from their user-agent
*
* @return array [ browser, version ]
*/
function fetch_browser()
{
$version = 0;
$browser = "unknown";
$useragent = strtolower($this->my_getenv('HTTP_USER_AGENT'));
//-----------------------------------------
// Opera...
//-----------------------------------------
if ( strstr( $useragent, 'opera' ) )
{
preg_match( "#opera[ /]([0-9\.]{1,10})#", $useragent, $ver );
return array( 'browser' => 'opera', 'version' => $ver[1] );
}
//-----------------------------------------
// IE...
//-----------------------------------------
if ( strstr( $useragent, 'msie' ) )
{
preg_match( "#msie[ /]([0-9\.]{1,10})#", $useragent, $ver );
return array( 'browser' => 'ie', 'version' => $ver[1] );
}
//-----------------------------------------
// Safari...
//-----------------------------------------
if ( strstr( $useragent, 'safari' ) )
{
preg_match( "#safari/([0-9.]{1,10})#", $useragent, $ver );
return array( 'browser' => 'safari', 'version' => $ver[1] );
}
//-----------------------------------------
// Mozilla browsers...
//-----------------------------------------
if ( strstr( $useragent, 'gecko' ) )
{
preg_match( "#gecko/(\d+)#", $useragent, $ver );
return array( 'browser' => 'gecko', 'version' => $ver[1] );
}
//-----------------------------------------
// Older Mozilla browsers...
//-----------------------------------------
if ( strstr( $useragent, 'mozilla' ) )
{
preg_match( "#^mozilla/[5-9]\.[0-9.]{1,10}.+rv:([0-9a-z.+]{1,10})#", $useragent, $ver );
return array( 'browser' => 'mozilla', 'version' => $ver[1] );
}
//-----------------------------------------
// Konqueror...
//-----------------------------------------
if ( strstr( $useragent, 'konqueror' ) )
{
preg_match( "#konqueror/([0-9.]{1,10})#", $useragent, $ver );
return array( 'browser' => 'konqueror', 'version' => $ver[1] );
}
//-----------------------------------------
// Still here?
//-----------------------------------------
return array( 'browser' => $browser, 'version' => $version );
}
/*-------------------------------------------------------------------------*/
//
// LOAD CLASS: Wrapper to load ..er.. classes
//
/*-------------------------------------------------------------------------*/
/**
* Wrapper function to load a class and pass $this automagically
*
* @param string File name
* @param string Class Name
* @param string Constructor variables
* @return object
*/
function load_class( $file_name, $class_name, $pass_var="" )
{
if ( ! $class_name )
{
$class_name = $file_name;
}
require_once( $file_name );
if ( $pass_var )
{
$class = new $class_name ( $pass_var );
}
else
{
$class = new $class_name;
}
$class->ipsclass =& $this;
return $class;
}
/*-------------------------------------------------------------------------*/
// Stronghold: Check cookie
/*-------------------------------------------------------------------------*/
/**
* Checks auto-log in strong hold cookie
*
* @param int Member's ID
* @param string Member's log in key
* @return boolean
*/
function stronghold_check_cookie( $member_id, $member_log_in_key )
{
//-----------------------------------------
// Check...
//-----------------------------------------
if ( ! isset($this->vars['cookie_stronghold']) OR ! $this->vars['cookie_stronghold'] )
{
return TRUE;
}
//-----------------------------------------
// INIT
//-----------------------------------------
$ip_octets = explode( ".", $this->my_getenv('REMOTE_ADDR') );
$crypt_salt = md5( $this->vars['sql_pass'].$this->vars['sql_user'] );
$cookie = $this->my_getcookie( 'ipb_stronghold' );
//-----------------------------------------
// Check
//-----------------------------------------
if ( ! $cookie )
{
return FALSE;
}
//-----------------------------------------
// Put it together....
//-----------------------------------------
$stronghold = md5( md5( $member_id . "-" . $ip_octets[0] . '-' . $ip_octets[1] . '-' . $member_log_in_key ) . $crypt_salt );
//-----------------------------------------
// Check against cookie
//-----------------------------------------
return $cookie == $stronghold ? TRUE : FALSE;
}
/*-------------------------------------------------------------------------*/
// Stronghold: Create and set cookie
/*-------------------------------------------------------------------------*/
/**
* Creates an auto-log in strong hold cookie
*
* @param int Member's ID
* @param string Member's log in key
* @return boolean
*/
function stronghold_set_cookie( $member_id, $member_log_in_key )
{
//-----------------------------------------
// Check...
//-----------------------------------------
if ( ! isset($this->vars['cookie_stronghold']) OR ! $this->vars['cookie_stronghold'] )
{
return FALSE;
}
//-----------------------------------------
// INIT
//-----------------------------------------
$ip_octets = explode( ".", $this->my_getenv('REMOTE_ADDR') );
$crypt_salt = md5( $this->vars['sql_pass'].$this->vars['sql_user'] );
//-----------------------------------------
// Put it together....
//-----------------------------------------
$stronghold = md5( md5( $member_id . "-" . $ip_octets[0] . '-' . $ip_octets[1] . '-' . $member_log_in_key ) . $crypt_salt );
//-----------------------------------------
// Set cookie
//-----------------------------------------
$this->my_setcookie( 'ipb_stronghold', $stronghold, 1 );
return TRUE;
}
/*-------------------------------------------------------------------------*/
//
// Check mod queue status
//
/*-------------------------------------------------------------------------*/
/**
* Determine if this user / forum combo can manage mod queue
*
* @param integer Forum ID
* @return integer Boolean
*/
function can_queue_posts($fid=0)
{
$return = 0;
if ( $this->member['g_is_supmod'] )
{
$return = 1;
}
else if ( $fid AND isset($this->member['is_mod']) AND $this->member['is_mod'] AND isset($this->member['_moderator'][ $fid ]['post_q']) AND $this->member['_moderator'][ $fid ]['post_q'] )
{
$return = 1;
}
return $return;
}
/*-------------------------------------------------------------------------*/
//
// Check multi mod status
//
/*-------------------------------------------------------------------------*/
/**
* Determine if this user / forum combo can manage multi moderation tasks
* and return mm_array of allowed tasks
*
* @param integer Forum ID
* @return array Allowed tasks
*/
function get_multimod($fid)
{
$mm_array = array();
$pass_go = FALSE;
if ( $this->member['id'] )
{
if ( $this->member['g_is_supmod'] )
{
$pass_go = TRUE;
}
else if ( isset($this->member['_moderator'][ $fid ]['can_mm']) AND $this->member['_moderator'][ $fid ]['can_mm'] == 1 )
{
$pass_go = TRUE;
}
}
if ( $pass_go != TRUE )
{
return $mm_array;
}
if ( ! array_key_exists( 'multimod', $this->cache ) )
{
$this->cache['multimod'] = array();
$this->DB->simple_construct( array(
'select' => '*',
'from' => 'topic_mmod',
'order' => 'mm_title'
) );
$this->DB->simple_exec();
while ($i = $this->DB->fetch_row())
{
$this->cache['multimod'][ $i['mm_id'] ] = $i;
}
$this->update_cache( array( 'name' => 'multimod', 'array' => 1, 'deletefirst' => 1 ) );
}
//-----------------------------------------
// Get the topic mod thingies
//-----------------------------------------
if( count( $this->cache['multimod'] ) AND is_array( $this->cache['multimod'] ) )
{
foreach( $this->cache['multimod'] as $r )
{
if ( $r['mm_forums'] == '*' OR strstr( ",".$r['mm_forums'].",", ",".$fid."," ) )
{
$mm_array[] = array( $r['mm_id'], $r['mm_title'] );
}
}
}
return $mm_array;
}
/*-------------------------------------------------------------------------*/
// UNPACK MEMBER CACHE
/*-------------------------------------------------------------------------*/
/**
* Unpacks a member's cache
*
* Left as a function for any other processing
*
* @param string Serialized cache array
* @return array Unpacked array
*/
function unpack_member_cache( $cache_serialized_array="" )
{
return unserialize( $cache_serialized_array );
}
/*-------------------------------------------------------------------------*/
// PACK MEMBER CACHE
/*-------------------------------------------------------------------------*/
/**
* Packs up member's cache
*
* Takes an existing array and updates member's DB row
* This will overwrite any existing entries by the same
* key and create new entries for non-existing rows
*
* @param integer Member ID
* @param array New array
* @param array Current Array (optional)
* @return boolean
*/
function pack_and_update_member_cache( $member_id, $new_cache_array, $current_cache_array='' )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$member_id = intval( $member_id );
//-----------------------------------------
// Got a member ID?
//-----------------------------------------
if ( ! $member_id )
{
return FALSE;
}
//-----------------------------------------
// Got anything to update?
//-----------------------------------------
if ( ! is_array( $new_cache_array ) OR ! count( $new_cache_array ) )
{
return FALSE;
}
//-----------------------------------------
// Got a current cache?
//-----------------------------------------
if ( ! is_array( $current_cache_array ) )
{
$member = $this->DB->build_and_exec_query( array( 'select' => "members_cache", 'from' => 'members', 'where' => 'id='.$member_id ) );
$member['members_cache'] = $member['members_cache'] ? $member['members_cache'] : array();
$current_cache_array = @unserialize( $member['members_cache'] );
}
//-----------------------------------------
// Overwrite...
//-----------------------------------------
foreach( $new_cache_array as $k => $v )
{
$current_cache_array[ $k ] = $v;
}
//-----------------------------------------
// Update...
//-----------------------------------------
$this->DB->do_update( 'members', array( 'members_cache' => serialize( $current_cache_array ) ), 'id='.$member_id );
//-----------------------------------------
// Set member array right...
//-----------------------------------------
$this->member['_cache'] = $current_cache_array;
}
/*-------------------------------------------------------------------------*/
// UPDATE FORUM CACHE
/*-------------------------------------------------------------------------*/
/**
* Updates forum cache (loads all, recaches all)
*
* @return void
*/
function update_forum_cache()
{
$ignore_me = array( 'redirect_url', 'redirect_loc', 'rules_text', 'permission_custom_error', 'notify_modq_emails' );
if ( isset($this->vars['forum_cache_minimum']) AND $this->vars['forum_cache_minimum'] )
{
$ignore_me[] = 'description';
$ignore_me[] = 'rules_title';
}
$this->cache['forum_cache'] = array();
$this->DB->simple_construct( array( 'select' => '*',
'from' => 'forums',
'order' => 'parent_id, position'
) );
$this->DB->simple_exec();
while( $f = $this->DB->fetch_row() )
{
$fr = array();
$perms = unserialize(stripslashes($f['permission_array']));
//-----------------------------------------
// Stuff we don't need...
//-----------------------------------------
if ( $f['parent_id'] == -1 )
{
$fr['id'] = $f['id'];
$fr['sub_can_post'] = $f['sub_can_post'];
$fr['name'] = $f['name'];
$fr['parent_id'] = $f['parent_id'];
$fr['show_perms'] = $perms['show_perms'];
$fr['skin_id'] = $f['skin_id'];
$fr['permission_showtopic'] = $f['permission_showtopic'];
}
else
{
foreach( $f as $k => $v )
{
if ( in_array( $k, $ignore_me ) )
{
continue;
}
else
{
if ( $v != "" )
{
$fr[ $k ] = $v;
}
}
}
$fr['read_perms'] = isset($perms['read_perms']) ? $perms['read_perms'] : '';
$fr['reply_perms'] = isset($perms['reply_perms']) ? $perms['reply_perms'] : '';
$fr['start_perms'] = isset($perms['start_perms']) ? $perms['start_perms'] : '';
$fr['upload_perms'] = isset($perms['upload_perms']) ? $perms['upload_perms'] : '';
$fr['download_perms'] = isset($perms['download_perms']) ? $perms['download_perms'] : '';
$fr['show_perms'] = isset($perms['show_perms']) ? $perms['show_perms'] : '';
unset($fr['permission_array']);
}
$this->cache['forum_cache'][ $fr['id'] ] = $fr;
}
$this->update_cache( array( 'name' => 'forum_cache', 'array' => 1, 'deletefirst' => 0, 'donow' => 0 ) );
}
/*-------------------------------------------------------------------------*/
//
// UPDATE CACHE
//
/*-------------------------------------------------------------------------*/
/**
* Updates cache
*
* @param array Cache values (name, value, deletefirst, donow)
* @todo remove some of the MySQL specific code
* @return void
*/
function update_cache( $v=array() )
{
//-----------------------------------------
// Don't cache forums?
//-----------------------------------------
if ( $v['name'] == 'forum_cache' AND isset($this->vars['no_cache_forums']) AND $this->vars['no_cache_forums'] )
{
return;
}
$v['donow'] = isset($v['donow']) ? $v['donow'] : 0;
//-----------------------------------------
// Next...
//-----------------------------------------
if ( $v['name'] )
{
if ( ! isset($v['value']) OR !$v['value'] )
{
if ( isset($v['array']) AND $v['array'] )
{
$value = serialize($this->cache[ $v['name'] ]);
}
else
{
$value = $this->cache[ $v['name'] ];
}
}
else
{
if ( isset($v['array']) AND $v['array'] )
{
$value = serialize($v['value']);
}
else
{
$value = $v['value'];
}
}
$this->DB->no_escape_fields['cs_key'] = 1;
if ( $v['deletefirst'] == 1 )
{
if ( $v['donow'] )
{
$this->DB->do_replace_into( 'cache_store', array( 'cs_array' => intval($v['array']), 'cs_key' => $v['name'], 'cs_value' => $value ), array( 'cs_key' ) );
}
else
{
$this->DB->do_shutdown_replace_into( 'cache_store', array( 'cs_array' => intval($v['array']), 'cs_key' => $v['name'], 'cs_value' => $value ), array( 'cs_key' ) );
}
}
else
{
if ( $v['donow'] )
{
$this->DB->do_update( 'cache_store', array( 'cs_array' => intval($v['array']), 'cs_value' => $value ), "cs_key='{$v['name']}'" );
}
else
{
$this->DB->do_shutdown_update( 'cache_store', array( 'cs_array' => intval($v['array']), 'cs_value' => $value ), "cs_key='{$v['name']}'" );
}
}
if( is_object($this->cachelib) )
{
if( !$value )
{
$value = "EMPTY";
}
$this->cachelib->do_remove( $v['name'] );
$this->cachelib->do_put( $v['name'], $value );
}
}
}
/*-------------------------------------------------------------------------*/
//
// MY DECONSTRUCTOR
//
/*-------------------------------------------------------------------------*/
/**
* Manual deconstructor
*
* Runs any SQL shutdown queries and mail tasks
*
* @return void
*/
function my_deconstructor()
{
//-----------------------------------------
// Update Server Load
//-----------------------------------------
if ($this->vars['load_limit'] > 0)
{
$server_load_found = 0;
//-----------------------------------------
// Check cache first...
//-----------------------------------------
if ( $this->cache['systemvars']['loadlimit'] )
{
$loadinfo = explode( "-", $this->cache['systemvars']['loadlimit'] );
if ( intval($loadinfo[1]) > (time() - 10) )
{
//-----------------------------------------
// Cache is less than 1 minute old
//-----------------------------------------
$server_load_found = 1;
}
}
//-----------------------------------------
// No cache or it's old, check real time
//-----------------------------------------
if ( ! $server_load_found )
{
# @ supressor fixes warning in >4.3.2 with open_basedir restrictions
if ( @file_exists('/proc/loadavg') )
{
if ( $fh = @fopen( '/proc/loadavg', 'r' ) )
{
$data = @fread( $fh, 6 );
@fclose( $fh );
$load_avg = explode( " ", $data );
$this->server_load = trim($load_avg[0]);
}
}
else if( strstr( strtolower(PHP_OS), 'win' ) )
{
/*---------------------------------------------------------------
| typeperf is an exe program that is included with Win NT,
| XP Pro, and 2K3 Server. It can be installed on 2K from the
| 2K Resource kit. It will return the real time processor
| Percentage, but will take 1 second processing time to do so.
| This is why we shall cache it, and check every 10 secs.
|
| Can also be obtained from COM, but it's extremely slow...
---------------------------------------------------------------*/
$serverstats = @shell_exec("typeperf \"Processor(_Total)\% Processor Time\" -sc 1");
if( $serverstats )
{
$server_reply = explode( "\n", str_replace( "\r", "", $serverstats ) );
$serverstats = array_slice( $server_reply, 2, 1 );
$statline = explode( ",", str_replace( '"', '', $serverstats[0] ) );
$this->server_load = round( $statline[1], 2 );
}
}
else
{
if ( $serverstats = @exec("uptime") )
{
preg_match( "/(?:averages)?\: ([0-9\.]+)[^0-9\.]+([0-9\.]+)[^0-9\.]+([0-9\.]+)\s*/", $serverstats, $load );
$this->server_load = $load[1];
}
}
if ( $this->server_load )
{
$this->cache['systemvars']['loadlimit'] = $this->server_load."-".time();
$this->update_cache( array( 'array' => 1, 'name' => 'systemvars', 'donow' => 1, 'deletefirst' => 0 ) );
}
}
}
//-----------------------------------------
// Process mail queue
//-----------------------------------------
$this->process_mail_queue();
//-----------------------------------------
// Any shutdown queries
//-----------------------------------------
$this->DB->return_die = 0;
if ( count( $this->DB->obj['shutdown_queries'] ) )
{
foreach( $this->DB->obj['shutdown_queries'] as $q )
{
$this->DB->query( $q );
}
}
$this->DB->return_die = 1;
$this->DB->obj['shutdown_queries'] = array();
$this->DB->close_db();
if( is_object($this->cachelib) )
{
// memcache, primarily, though disconnect will
// happen automatically just like DB anyways
$this->cachelib->disconnect();
}
}
/*-------------------------------------------------------------------------*/
//
// Process Mail Queue
//
/*-------------------------------------------------------------------------*/
/**
* Process mail queue
*
* @return void
*/
function process_mail_queue()
{
//-----------------------------------------
// SET UP
//-----------------------------------------
$this->vars['mail_queue_per_blob'] = isset($this->vars['mail_queue_per_blob']) ? $this->vars['mail_queue_per_blob'] : 5;
$this->cache['systemvars']['mail_queue'] = isset( $this->cache['systemvars']['mail_queue'] ) ? intval( $this->cache['systemvars']['mail_queue'] ) : 0;
$sent_ids = array();
if ( $this->cache['systemvars']['mail_queue'] > 0 )
{
//-----------------------------------------
// Require the emailer...
//-----------------------------------------
require_once( ROOT_PATH . 'sources/classes/class_email.php' );
$emailer = new emailer(ROOT_PATH);
$emailer->ipsclass =& $this;
$emailer->email_init();
//-----------------------------------------
// Get the mail stuck in the queue
//-----------------------------------------
$this->DB->simple_construct( array( 'select' => '*', 'from' => 'mail_queue', 'order' => 'mail_id', 'limit' => array( 0, $this->vars['mail_queue_per_blob'] ) ) );
$this->DB->simple_exec();
while ( $r = $this->DB->fetch_row() )
{
$data[] = $r;
$sent_ids[] = $r['mail_id'];
}
if ( count($sent_ids) )
{
//-----------------------------------------
// Delete sent mails and update count
//-----------------------------------------
$this->cache['systemvars']['mail_queue'] = $this->cache['systemvars']['mail_queue'] - count($sent_ids);
$this->DB->simple_exec_query( array( 'delete' => 'mail_queue', 'where' => 'mail_id IN ('.implode(",", $sent_ids).')' ) );
foreach( $data as $mail )
{
if ( $mail['mail_to'] and $mail['mail_subject'] and $mail['mail_content'] )
{
$emailer->to = $mail['mail_to'];
$emailer->from = $mail['mail_from'] ? $mail['mail_from'] : $this->vars['email_out'];
$emailer->subject = $mail['mail_subject'];
$emailer->message = $mail['mail_content'];
if ( $mail['mail_html_on'] )
{
$emailer->html_email = 1;
}
else
{
$emailer->html_email = 0;
}
$emailer->send_mail();
}
}
}
else
{
//-----------------------------------------
// No mail after all?
//-----------------------------------------
$this->cache['systemvars']['mail_queue'] = 0;
}
//-----------------------------------------
// Update cache with remaning email count
//-----------------------------------------
$this->update_cache( array( 'array' => 1, 'name' => 'systemvars', 'donow' => 1, 'deletefirst' => 0 ) );
}
}
/*-------------------------------------------------------------------------*/
// Load a ACP template file
/*-------------------------------------------------------------------------*/
/**
* Load an ACP skin template file for use
*
* @return object Class object
*/
function acp_load_template( $template )
{
if ( ! $this->skin_acp )
{
$this->skin_acp = 'IPB2_Standard';
}
require_once( ROOT_PATH."skin_acp/".$this->skin_acp."/acp_skin_html/".$template.".php" );
$tmp = new $template();
$tmp->ipsclass =& $this;
return $tmp;
}
/*-------------------------------------------------------------------------*/
// Require, parse and return an array containing the language stuff
/*-------------------------------------------------------------------------*/
/**
* Load an ACP language file. Populates $this->lang
*
* @param string File name
* @return void
* @since 2.1
*/
function acp_load_language( $file="" )
{
if ( ! $this->lang_id )
{
$this->lang_id = $this->member['language'] ? $this->member['language'] : $this->vars['default_language'];
if ( ($this->lang_id != $this->vars['default_language']) and ( ! is_dir( ROOT_PATH."cache/lang_cache/".$this->lang_id ) ) )
{
$this->lang_id = $this->vars['default_language'];
}
//-----------------------------------------
// Still nothing?
//-----------------------------------------
if ( ! $this->lang_id )
{
$this->lang_id = 'en';
}
}
//-----------------------------------------
// Load it
//-----------------------------------------
if( file_exists( ROOT_PATH."cache/lang_cache/".$this->lang_id."/".$file.".php" ) )
{
require_once( ROOT_PATH."cache/lang_cache/".$this->lang_id."/".$file.".php" );
if ( is_array( $lang ) )
{
foreach ($lang as $k => $v)
{
$this->acp_lang[ $k ] = $v;
}
}
}
unset($lang);
}
/*-------------------------------------------------------------------------*/
//
// Load a template file from DB or from PHP file
//
/*-------------------------------------------------------------------------*/
/**
* Load a normal template file from either cached PHP file or
* from the DB. Populates $this->compiled_templates[ _template_name_ ]
*
* @param string Template name
* @param integer Template set ID
* @return void
*/
function load_template( $name, $id='' )
{
$tags = 1;
$loaded = 0;
//-----------------------------------------
// Select ID
//-----------------------------------------
if ( ! $id )
{
$id = $this->skin['_skincacheid'];
}
//-----------------------------------------
// Full name
//-----------------------------------------
$full_name = $name.'_'.intval($id);
$skin_global_name = 'skin_global_'.$id;
$_name = $name;
//-----------------------------------------
// Already got this template loaded?
//-----------------------------------------
if ( in_array( $full_name, $this->loaded_templates ) )
{
return;
}
//-----------------------------------------
// Not running safemode skins?
//-----------------------------------------
if ( $this->vars['safe_mode_skins'] == 0 AND $this->vars['safe_mode'] == 0 )
{
//-----------------------------------------
// Simply require and return
//-----------------------------------------
if ( $name != 'skin_global')
{
if ( ! in_array( $skin_global_name, $this->loaded_templates ) )
{
//-----------------------------------------
// Suck in skin global..
//-----------------------------------------
if( $this->load_template_from_php( 'skin_global', 'skin_global_'.$id, $id ) )
{
$loaded = 1;
}
//-----------------------------------------
// Suck in normal file...
//-----------------------------------------
if( !$this->load_template_from_php( $_name, $name.'_'.$id, $id ) )
{
$loaded = 0;
}
}
else
{
//-----------------------------------------
// Suck in normal file...
//-----------------------------------------
if( $this->load_template_from_php( $_name, $name.'_'.$id, $id ) )
{
$loaded = 1;
}
}
}
else
{
if ( $name == 'skin_global' )
{
//-----------------------------------------
// Suck in skin global..
//-----------------------------------------
if( $this->load_template_from_php( 'skin_global', 'skin_global_'.$id, $id ) )
{
$loaded = 1;
}
return;
}
else
{
//-----------------------------------------
// Suck in normal file...
//-----------------------------------------
if( $this->load_template_from_php( $_name, $name.'_'.$id, $id ) )
{
$loaded = 1;
}
}
}
}
//-----------------------------------------
// safe_mode_skins OR flat file load failed
//-----------------------------------------
if( !$loaded )
{
//-----------------------------------------
// We're using safe mode skins, yippee
// Load the data from the DB
//-----------------------------------------
$skin_global = "";
$other_skin = "";
$this->skin['_type'] = 'Database Skins';
if ( $this->loaded_templates[ $skin_global_name ] == "" and $name != 'skin_global')
{
//-----------------------------------------
// Skin global not loaded...
//-----------------------------------------
$this->DB->simple_construct( array( 'select' => '*',
'from' => 'skin_templates_cache',
'where' => "template_set_id=".$id." AND template_group_name IN ('skin_global', '$name')"
) );
$this->DB->simple_exec();
while ( $r = $this->DB->fetch_row() )
{
if ( $r['template_group_name'] == 'skin_global' )
{
$skin_global = $r['template_group_content'];
}
else
{
$other_skin = $r['template_group_content'];
}
}
if ( IN_DEV AND $id == 1 )
{
//-----------------------------------------
// Get template class
//-----------------------------------------
if ( ! is_object( $this->work_classes['class_template_engine'] ) )
{
require_once( KERNEL_PATH . 'class_template_engine.php' );
$this->work_classes['class_template_engine'] = new class_template();
}
if( $skin_global )
{
$skin_global = $this->work_classes['class_template_engine']->convert_cache_to_eval( $skin_global, 'skin_global_1' );
}
if( $other_skin )
{
$other_skin = $this->work_classes['class_template_engine']->convert_cache_to_eval( $other_skin, $name.'_'.$id );
}
}
//print $other_skin;exit;
eval($skin_global);
$this->compiled_templates['skin_global'] = new $skin_global_name();
$this->compiled_templates['skin_global']->ipsclass =& $this;
# Add to loaded templates
$this->loaded_templates[ $skin_global_name ] = $skin_global_name;
}
else
{
//-----------------------------------------
// Skin global is loaded..
//-----------------------------------------
if ( $name == 'skin_global' and in_array( $skin_global_name, $this->loaded_templates ) )
{
return;
}
//-----------------------------------------
// Load the skin, man
//-----------------------------------------
$this->DB->simple_construct( array( 'select' => '*',
'from' => 'skin_templates_cache',
'where' => "template_set_id=".$id." AND template_group_name='$name'"
) );
$this->DB->simple_exec();
$r = $this->DB->fetch_row();
$other_skin = $r['template_group_content'];
if ( IN_DEV AND $id == 1 )
{
//-----------------------------------------
// Get template class
//-----------------------------------------
if ( ! is_object( $this->work_classes['class_template_engine'] ) )
{
require_once( KERNEL_PATH . 'class_template_engine.php' );
$this->work_classes['class_template_engine'] = new class_template();
}
if( $other_skin )
{
$other_skin = $this->work_classes['class_template_engine']->convert_cache_to_eval( $other_skin, $name.'_'.$id );
}
}
}
eval($other_skin);
if ( $name == 'skin_global' )
{
$this->compiled_templates['skin_global'] = new $skin_global_name();
$this->compiled_templates['skin_global']->ipsclass =& $this;
# Add to loaded templates
$this->loaded_templates[ $skin_global_name ] = $skin_global_name;
}
else
{
$this->compiled_templates[ $name ] = new $full_name();
$this->compiled_templates[ $name ]->ipsclass =& $this;
# Add to loaded templates
$this->loaded_templates[ $full_name ] = $full_name;
}
}
//-----------------------------------------
// LEGACY
//-----------------------------------------
if ( defined('LEGACY_MODE') && LEGACY_MODE == 1 )
{
if ( $name )
{
return $this->compiled_templates[ $name ];
}
}
}
/*-------------------------------------------------------------------------*/
// Load the template bit from the PHP file
/*-------------------------------------------------------------------------*/
/**
* Load the template bit from the PHP file
*
* @var string Name of the PHP file (sans .php)
* @var string Name of the class
* @return boolean
*/
function load_template_from_php( $name='skin_global', $full_name='skin_global_1', $id='1' )
{
$_NOW = $this->memory_debug_make_flag();
//-----------------------------------------
// File exist?
//-----------------------------------------
if( !file_exists( CACHE_PATH."cache/skin_cache/cacheid_".$id."/".$name.".php" ) )
{
return FALSE;
}
//-----------------------------------------
// IN_DEV?
//-----------------------------------------
if ( IN_DEV AND $id == 1 )
{
//-----------------------------------------
// Get data...
//-----------------------------------------
$data = implode( '', file( CACHE_PATH."cache/skin_cache/cacheid_".$id."/".$name.".php" ) );
//-----------------------------------------
// Get template class
//-----------------------------------------
if ( ! is_object( $this->work_classes['class_template_engine'] ) )
{
require_once( KERNEL_PATH . 'class_template_engine.php' );
$this->work_classes['class_template_engine'] = new class_template();
}
$toeval = $this->work_classes['class_template_engine']->convert_cache_to_eval( $data, $full_name );
#if ( $name == 'skin_topic' ) { print $toeval; exit(); }
eval( $toeval );
}
else
{
require_once( CACHE_PATH."cache/skin_cache/cacheid_".$id."/".$name.".php" );
}
$this->compiled_templates[ $name ] = new $full_name();
$this->compiled_templates[ $name ]->ipsclass =& $this;
# Add to loaded templates
$this->loaded_templates[ $full_name ] = $full_name;
$this->memory_debug_add( "IPSCLASS: Loaded skin file - $name", $_NOW );
return TRUE;
}
/*-------------------------------------------------------------------------*/
// SKIN, sort out the skin stuff
/*-------------------------------------------------------------------------*/
/**
* Load a skin, macro, settings, etc
*
* @return array Database row (not really used anymore)
*/
function load_skin()
{
//-----------------------------------------
// INIT
//-----------------------------------------
$id = -1;
$skin_set = 0;
$from_forum = 0;
$this->input['skinid'] = isset($this->input['skinid']) ? intval($this->input['skinid']) : 0;
$this->member['skin'] = isset($this->member['skin']) ? intval($this->member['skin']) : 0;
//-----------------------------------------
// Skin ID 1 is reserved..
//-----------------------------------------
if ( $this->input['skinid'] == 1 )
{
$this->input['skinid'] = 0;
}
//-----------------------------------------
// Do we have a cache?
//-----------------------------------------
if ( ! is_array( $this->cache['skin_id_cache'] ) OR ! count( $this->cache['skin_id_cache'] ) )
{
require_once( ROOT_PATH.'sources/lib/admin_cache_functions.php' );
$admin = new admin_cache_functions();
$admin->ipsclass =& $this;
$this->cache['skin_id_cache'] = $admin->_rebuild_skin_id_cache();
}
//-----------------------------------------
// Search bot?
//-----------------------------------------
if ( ( $this->is_bot == 1 ) and ( $this->vars['spider_suit'] != "" ) )
{
$skin_set = 1;
$id = $this->vars['spider_suit'];
}
else
{
//-----------------------------------------
// URL remapping?
//-----------------------------------------
if ( isset($this->cache['skin_remap']) and is_array( $this->cache['skin_remap'] ) AND count( $this->cache['skin_remap'] ) )
{
foreach( $this->cache['skin_remap'] as $id => $data )
{
if ( $data['map_match_type'] == 'exactly' )
{
if ( strtolower( $data['map_url'] ) == strtolower( $this->query_string_real ) )
{
$skin_set = 1;
$id = $data['map_skin_set_id'];
break;
}
}
else if ( $data['map_match_type'] == 'contains' )
{
if ( stristr( $this->query_string_real, $data['map_url'] ) )
{
$skin_set = 1;
$id = $data['map_skin_set_id'];
break;
}
}
}
}
//-----------------------------------------
// Still not set?
//-----------------------------------------
if ( ! $skin_set )
{
//-----------------------------------------
// Do we have a skin for a particular forum?
//-----------------------------------------
if ( (isset($this->input['f']) AND $this->input['f']) AND (isset($this->input['act']) AND $this->input['act'] != 'UserCP') )
{
if ( isset($this->cache['forum_cache'][ $this->input['f'] ]['skin_id']) AND $this->cache['forum_cache'][ $this->input['f'] ]['skin_id'] > 0 )
{
$id = $this->cache['forum_cache'][ $this->input['f'] ]['skin_id'];
$skin_set = 1;
$from_forum = 1;
}
}
//-----------------------------------------
// Are we allowing user chooseable skins?
//-----------------------------------------
if ( $skin_set != 1 AND $this->vars['allow_skins'] == 1 )
{
if ( $this->input['skinid'] )
{
$id = $this->input['skinid'];
$skin_set = 1;
}
else if ( $this->member['skin'] )
{
$id = $this->member['skin'];
$skin_set = 1;
}
}
}
}
//-----------------------------------------
// Nothing set / hidden and not admin? Choose the default
//-----------------------------------------
if ( isset($this->cache['skin_id_cache'][ $id ]['set_hidden']) AND $this->cache['skin_id_cache'][ $id ]['set_hidden'] )
{
if ( $from_forum )
{
$skin_set = 1;
}
else if ( $this->member['g_access_cp'] )
{
$skin_set = 1;
}
else if ( $this->is_bot )
{
$skin_set = 1;
}
else
{
$skin_set = 0;
}
}
if ( ! $id OR ! $skin_set OR ! is_array($this->cache['skin_id_cache'][ $id ]) )
{
foreach( $this->cache['skin_id_cache'] as $data )
{
if ( $data['set_default'] )
{
$id = $data['set_skin_set_id'];
$skin_set = 1;
}
}
}
//------------------------------------------
// Still no skin? - no default skin set
//------------------------------------------
if( ! $id OR ! $skin_set )
{
$skin_data = reset($this->cache['skin_id_cache']);
$id = $skin_data['skin_set_id'];
$skin_set = 1;
}
//-----------------------------------------
// Get the skin
//-----------------------------------------
$db_skin = array();
if ( is_object( $this->cachelib ) )
{
$db_skin = $this->cachelib->do_get( 'Skin_Store_' . $id );
}
if ( ! is_array($db_skin) OR ! count($db_skin) )
{
$db_skin = $this->DB->simple_exec_query( array( 'select' => 'set_cache_css,set_cache_wrapper,set_cache_macro,set_image_dir,set_emoticon_folder,set_skin_set_id,set_name,set_css_method', 'from' => 'skin_sets', 'where' => 'set_skin_set_id='.$id ) );
if( is_object($this->cachelib) )
{
$this->cachelib->do_put( 'Skin_Store_' . $id, $db_skin, 86400 );
}
}
$this->skin['_css'] = $db_skin['set_cache_css'];
$this->skin['_wrapper'] = $db_skin['set_cache_wrapper'];
$this->skin['_macro'] = $db_skin['set_cache_macro'];
$this->skin['_imagedir'] = $db_skin['set_image_dir'];
$this->skin['_emodir'] = $db_skin['set_emoticon_folder'];
$this->skin['_setid'] = $db_skin['set_skin_set_id'];
$this->skin['_setname'] = $db_skin['set_name'];
$this->skin['_usecsscache'] = $db_skin['set_css_method'] ? 1 : 0;
$this->skin['_macros'] = unserialize(stripslashes($this->skin['_macro']));
$this->skin['_skincacheid'] = $db_skin['set_skin_set_id'];
$this->skin['_csscacheid'] = $db_skin['set_skin_set_id'];
if ( IN_DEV )
{
$this->skin['_skincacheid'] = file_exists( CACHE_PATH.'cache/skin_cache/cacheid_1' ) ? 1 : $db_skin['set_skin_set_id'];
$this->skin['_usecsscache'] = file_exists( CACHE_PATH.'style_images/css_'. $this->skin['_csscacheid'] .'.css' ) ? 1 : 0;
$this->skin['_csscacheid'] = 1;
}
//-----------------------------------------
// Setting the skin?
//-----------------------------------------
if ( isset($this->input['setskin']) AND $this->input['setskin'] AND $this->member['id'] )
{
$this->DB->simple_construct( array( 'update' => 'members',
'set' => "skin=".intval($id),
'where' => "id=".$this->member['id']
) );
$this->DB->simple_exec();
$this->member['skin'] = $id;
}
unset($db_skin);
return;
}
/*-------------------------------------------------------------------------*/
// Require, parse and return an array containing the language stuff
/*-------------------------------------------------------------------------*/
/**
* Load a language file. Populates $this->lang
*
* @param string File name
* @return void
* @since 2.1
*/
function load_language( $file="" )
{
//-----------------------------------------
// Memory
//-----------------------------------------
$_NOW = $this->memory_debug_make_flag();
$this->vars['default_language'] = isset($this->vars['default_language']) ? $this->vars['default_language'] : 'en';
if ( ! $this->lang_id )
{
$this->lang_id = isset($this->member['language']) ? $this->member['language'] : $this->vars['default_language'];
if ( ($this->lang_id != $this->vars['default_language']) and ( ! is_dir( ROOT_PATH."cache/lang_cache/".$this->lang_id ) ) )
{
$this->lang_id = $this->vars['default_language'];
}
//-----------------------------------------
// Still nothing?
//-----------------------------------------
if ( ! $this->lang_id )
{
$this->lang_id = 'en';
}
}
//-----------------------------------------
// Load it
//-----------------------------------------
if ( file_exists( ROOT_PATH."cache/lang_cache/".$this->lang_id."/".$file.".php" ) )
{
require ( ROOT_PATH."cache/lang_cache/".$this->lang_id."/".$file.".php" );
if ( isset($lang) AND is_array( $lang ) )
{
foreach ($lang as $k => $v)
{
$this->lang[ $k ] = $v;
}
}
}
//-----------------------------------------
// Memory
//-----------------------------------------
$this->memory_debug_add( "IPSCLASS: Loaded language file - $file", $_NOW );
//-----------------------------------------
// Clean up
//-----------------------------------------
unset( $lang, $file );
}
/*-------------------------------------------------------------------------*/
// Get new PM notification window
/*-------------------------------------------------------------------------*/
/**
* Get a new PM notification message
*
* @param integer Current offset
* @param integer For Ajax flag
* @return string Parsed Message
* @todo Remove deprecated post_parser.php
* @since 2.0
*/
function get_new_pm_notification( $limit=0, $xmlout = 0 )
{
//-----------------------------------------
// Make sure we have a skin...
//-----------------------------------------
if ( ! $this->compiled_templates['skin_global'] )
{
$this->load_template( 'skin_global' );
}
//-----------------------------------------
// posty parsery
//-----------------------------------------
require_once( ROOT_PATH."sources/handlers/han_parse_bbcode.php" );
$parser = new parse_bbcode();
$parser->ipsclass =& $this;
$parser->allow_update_caches = 0;
$parser->parse_bbcode = 1;
$parser->parse_smilies = 1;
$parser->parse_html = 0;
//-----------------------------------------
// Get last PM details
//-----------------------------------------
$this->DB->cache_add_query( 'msg_get_new_pm_notification', array( 'mid' => $this->member['id'], 'limit_a' => intval($limit) ) );
$this->DB->simple_exec();
$msg = $this->DB->fetch_row();
//-----------------------------------------
// Check...
//-----------------------------------------
if ( ! $msg['msg_id'] and ! $msg['mt_id'] and ! $msg['id'] )
{
return '';
}
//-----------------------------------------
// Strip and wrap
//-----------------------------------------
$msg['msg_post'] = $parser->strip_all_tags( $msg['msg_post'] );
$msg['msg_post'] = preg_replace("#([^\s<>'\"/\.\\-\?&\n\r\%]{80})#i", " \\1"."
", $msg['msg_post']);
$msg['msg_post'] = str_replace( "\n", "
", trim($msg['msg_post']) );
if ( strlen( $msg['msg_post'] ) > 300 )
{
$msg['msg_post'] = substr( $msg['msg_post'], 0, 350 ) . '...';
$msg['msg_post'] = preg_replace( "/&(#(\d+;?)?)?\.\.\.$/", '...', $msg['msg_post'] );
}
//-----------------------------------------
// Add attach icon
//-----------------------------------------
if ( $msg['mt_hasattach'] )
{
$msg['attach_img'] = '<{ATTACH_ICON}> ';
}
//-----------------------------------------
// Date
//-----------------------------------------
$msg['msg_date'] = $this->get_date( $msg['msg_date'], 'TINY' );
//-----------------------------------------
// Next / Total links
//-----------------------------------------
$msg['_cur_num'] = intval($limit) + 1;
$msg['_msg_total'] = intval($this->member['new_msg']) ? intval($this->member['new_msg']) : 1;
//-----------------------------------------
// Return loverly HTML
//-----------------------------------------
$return = $this->compiled_templates['skin_global']->msg_get_new_pm_notification( $msg, $xmlout );
//-----------------------------------------
// XML request?
//-----------------------------------------
return $return;
}
/*-------------------------------------------------------------------------*/
// Content search hightlight
/*-------------------------------------------------------------------------*/
/**
* Replaces text with highlighted blocks
*
* @param string Incoming Content
* @param string HL attribute
* @return string Formatted text
* @since 2.2.0
*/
function content_search_highlight( $text, $highlight )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$highlight = $this->parse_clean_value( urldecode( $highlight ) );
$loosematch = strstr( $highlight, '*' ) ? 1 : 0;
$keywords = str_replace( '*', '', str_replace( "+", " ", str_replace( "++", "+", str_replace( '-', '', trim($highlight) ) ) ) );
$keywords = str_replace( '\\', '\', $keywords );
$word_array = array();
$endmatch = "(.)?";
$beginmatch = "(.)?";
//-----------------------------------------
// Go!
//-----------------------------------------
if ( $keywords )
{
if ( preg_match("/,(and|or),/i", $keywords) )
{
while ( preg_match("/,(and|or),/i", $keywords, $match) )
{
$word_array = explode( ",".$match[1].",", $keywords );
$keywords = str_replace( $match[0], '' ,$keywords );
}
}
else if ( strstr( $keywords, ' ' ) )
{
$word_array = explode( ' ', str_replace( ' ', ' ', $keywords ) );
}
else
{
$word_array[] = $keywords;
}
if ( ! $loosematch )
{
$beginmatch = "(^|\s|\>|;)";
$endmatch = "(\s|,|\.|!|
".$matches[2][$i]."".$matches[3][$i], $text );
}
}
}
}
return $text;
}
/*-------------------------------------------------------------------------*/
// XSS Clean: URLs
/*-------------------------------------------------------------------------*/
/**
* Check a URL to make sure it's not all hacky
*
* @param string Input String
* @return boolean
* @since 2.1.0
*/
function xss_check_url( $url )
{
$url = trim( urldecode( $url ) );
if ( ! preg_match( "#^https?://(?:[^<>*\"]+|[a-z0-9/\._\- !]+)$#iU", $url ) )
{
return FALSE;
}
return TRUE;
}
/*-------------------------------------------------------------------------*/
// XSS Clean: Nasty HTML
/*-------------------------------------------------------------------------*/
/**
* Remove script tags from HTML (well, best shot anyway)
*
* @param string Input HTML
* @return string Cleaned HTML
* @since 2.1.0
*/
function xss_html_clean( $html )
{
//-----------------------------------------
// Opening script tags...
// Check for spaces and new lines...
//-----------------------------------------
$html = preg_replace( "#<(\s+?)?s(\s+?)?c(\s+?)?r(\s+?)?i(\s+?)?p(\s+?)?t#is" , "<script" , $html );
$html = preg_replace( "#<(\s+?)?/(\s+?)?s(\s+?)?c(\s+?)?r(\s+?)?i(\s+?)?p(\s+?)?t#is", "</script", $html );
//-----------------------------------------
// Basics...
//-----------------------------------------
$html = preg_replace( "/javascript/i" , "javascript", $html );
$html = preg_replace( "/alert/i" , "alert" , $html );
$html = preg_replace( "/behavior/i" , "behavior" , $html );
$html = preg_replace( "/e((\/\*.*?\*\/)*)x((\/\*.*?\*\/)*)p((\/\*.*?\*\/)*)r((\/\*.*?\*\/)*)e((\/\*.*?\*\/)*)s((\/\*.*?\*\/)*)s((\/\*.*?\*\/)*)i((\/\*.*?\*\/)*)o((\/\*.*?\*\/)*)n/i" , "expression" , $html );
$html = preg_replace( "/e((\\\|\)*)x((\\\|\)*)p((\\\|\)*)r((\\\|\)*)e((\\\|\)*)s((\\\|\)*)s((\\\|\)*)i((\\\|\)*)o((\\\|\)*)n/i" , "expression" , $html );
$html = preg_replace( "/m((\\\|\)*)o((\\\|\)*)z((\\\|\)*)\-((\\\|\)*)b((\\\|\)*)i((\\\|\)*)n((\\\|\)*)d((\\\|\)*)i((\\\|\)*)n((\\\|\)*)g/i" , "moz-binding" , $html );
$html = preg_replace( "/about:/i" , "about:" , $html );
$html = preg_replace( "/vars['gb_char_set']);
//-----------------------------------------
// Not the same?
//-----------------------------------------
if ( $destination_cset == $original_cset )
{
return $t;
}
//-----------------------------------------
// Do the convert
//-----------------------------------------
/*if ( function_exists( 'mb_convert_encoding' ) )
{
$text = mb_convert_encoding( $text, $destination_cset, $original_cset );
}
else if ( function_exists( 'recode_string' ) )
{
$text = recode_string( $original_cset.'..'.$destination_cset, $text );
}
else if ( function_exists( 'iconv' ) )
{
$text = iconv( $original_cset, $destination_cset.'//TRANSLIT', $text);
}*/
if ( ! is_object( $this->class_convert_charset ) )
{
require_once( KERNEL_PATH.'/class_convert_charset.php' );
$this->class_convert_charset = new class_convert_charset();
}
$text = $this->class_convert_charset->convert_charset( $text, $original_cset, $destination_cset );
return $text ? $text : $t;
}
/*-------------------------------------------------------------------------*/
// Wordwrap text string (multi-byte safe)
/*-------------------------------------------------------------------------*/
/**
* Wordwrap a string at a given length (multi-byte character safe)
*
* @param string Input String
* @param integer Desired break point
* @param string Break point string
* @return string Parsed string
* @since 2.2
*/
function txt_wordwrap( $text, $breakpoint=80, $char='
' )
{
$breakpoint = intval($breakpoint) > 0 ? intval($breakpoint) : 80;
if( $this->vars['multibyte_wordwrap'] )
{
$str_len = $this->txt_mb_strlen( $text );
if( $str_len < $breakpoint )
{
return $text;
}
$str = "";
$str_arr = array();
for( $i=0; $i 128 AND ord( substr( $text, $i, 1 ) ) < 256 )
{
$str_arr[] = substr( $text, $i, 2 );
$i += 1;
}
else if( ord( substr( $text, $i, 1 ) ) > 256 )
{
$str_arr[] = substr( $text, $i, 3 );
$i += 2;
}
else
{
$str_arr[] = substr( $text, $i, 1 );
}
}
$tmp = array_chunk( $str_arr, $breakpoint );
foreach( $tmp as $key => $val )
{
if( preg_match( "/\s+/", implode( "", $val ) ) )
{
$str .= implode( "", $val );
}
else
{
if( preg_match( "/&[a-zA-Z0-9]$/", implode( "", $val ) ) )
{
$str .= preg_replace( "/&[a-zA-Z0-9]$/", " &", implode( "", $val ) );
}
else
{
$str .= implode( "", $val ) . $char;
}
}
}
return $str;
}
else
{
return preg_replace( "#([^\s<>'\"/\\-\?&\n\r\%]{{$breakpoint}})#i", "\\1{$char}", $text );
}
}
/*-------------------------------------------------------------------------*/
// Truncate text string
/*-------------------------------------------------------------------------*/
/**
* Truncate a HTML string without breaking HTML entites
*
* @param string Input String
* @param integer Desired min. length
* @return string Parsed string
* @since 2.0
*/
function txt_truncate($text, $limit=30)
{
$text = str_replace( '&' , '&', $text );
$text = str_replace( '"', '"', $text );
$start_text = $text;
$string_length = $this->txt_mb_strlen( $text );
if ( $string_length > $limit)
{
$text = $this->txt_mbsubstr( $text, 0, $limit );
}
if( $text != $start_text )
{
$text .= "...";
$text = preg_replace( "/&(#{0,}([a-zA-Z0-9]+?)?)?\.\.\.$/", '...', $text );
}
else
{
$text = preg_replace( "/&(#{0,}([a-zA-Z0-9]+?)?)?$/", '', $text );
}
return $text;
}
/*-------------------------------------------------------------------------*/
// Multibyte safe substr
/*-------------------------------------------------------------------------*/
/**
* Substr support for this without mb_substr
*
* @param string Input String
* @param integer Desired min. length
* @return string Parsed string
* @since 2.0
*/
function txt_mbsubstr($text, $start=0, $limit=30)
{
$text = str_replace( '&' , '&', $text );
$text = str_replace( '"', '"', $text );
// Do we have multi-byte functions?
if( function_exists('mb_list_encodings') )
{
// PHP 5, preferred method
$valid_encodings = array();
$valid_encodings = mb_list_encodings();
if( count($valid_encodings) )
{
if( in_array( strtoupper($this->vars['gb_char_set']), $valid_encodings ) )
{
return mb_substr( $text, $start, $limit, strtoupper($this->vars['gb_char_set']) );
}
}
}
else if( function_exists('mb_substr') )
{
// PHP 4 support
// Though this is quite tedious, let's check to see if encoding is supported....
// http://us2.php.net/manual/en/ref.mbstring.php
$valid_encodings = array( 'UCS-4', 'UCS-4BE', 'UCS-4LE', 'UCS-2', 'UCS-2BE', 'UCS-2LE', 'UTF-32', 'UTF-32BE',
'UTF-32LE', 'UTF-16', 'UTF-16BE', 'UTF-16LE', 'UTF-7', 'UTF7-IMAP', 'UTF-8',
'ASCII', 'EUC-JP', 'SJIS', 'EUCJP-WIN', 'SJIS-WIN', 'ISO-2022-JP', 'JIS', 'ISO-8859-1',
'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4', 'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7',
'ISO-8859-8', 'ISO-8859-9', 'ISO-8859-10', 'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15',
'EUC-CN', 'CP936', 'EUC-TW', 'HZ', 'CP950', 'BIG-5', 'EUC-KR', 'CP949', 'ISO-2022-KR',
'WINDOWS-1251', 'CP1251', 'WINDOWS-1252', 'CP1252', 'CP866', 'KOI8-R' );
if( in_array( strtoupper($this->vars['gb_char_set']), $valid_encodings ) )
{
return mb_substr( $text, $start, $limit, strtoupper($this->vars['gb_char_set']) );
}
}
// No? Let's do our handrolled method then
$string_length = $this->txt_mb_strlen( $text );
if ( $string_length > $limit)
{
if( strtoupper($this->vars['gb_char_set']) == 'UTF-8' )
{
// Multi-byte support
$text = @preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,0}'.
'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.intval($start).','.intval($limit).'}).*#s',
'$1',$text);
}
else
{
$text = substr( $text, $start, $limit );
}
$text = preg_replace( "/&(#(\d+?)?)?$/", '', $text );
}
else
{
$text = preg_replace( "/&(#(\d+?)?)?$/", '', $text );
}
return $text;
}
/*-------------------------------------------------------------------------*/
// txt_filename_clean
// ------------------
// Clean filenames...
/*-------------------------------------------------------------------------*/
/**
* Clean a string to prevent file traversal issues
*
* @param string Input String
* @return string Parsed string
* @since 2.1
*/
function txt_filename_clean( $t )
{
$t = $this->txt_alphanumerical_clean( $t, '.' );
$t = preg_replace( '#\.{1,}#s', '.', $t );
return $t;
}
/*-------------------------------------------------------------------------*/
// txt_md5_clean
// ------------------
// Clean up MD5 hashes
/*-------------------------------------------------------------------------*/
/**
* Returns a cleaned MD5 hash
*
* @param string Input String
* @return string Parsed string
* @since 2.1
*/
function txt_md5_clean( $t )
{
return preg_replace( "/[^a-zA-Z0-9]/", "" , substr( $t, 0, 32 ) );
}
/*-------------------------------------------------------------------------*/
// txt_alphanumerical_clean
// ------------------
// Remove non alphas
/*-------------------------------------------------------------------------*/
/**
* Clean a string to remove all non alphanumeric characters
*
* @param string Input String
* @param string Additional tags
* @return string Parsed string
* @since 2.1
*/
function txt_alphanumerical_clean( $t, $additional_tags="" )
{
if ( $additional_tags )
{
$additional_tags = preg_quote( $additional_tags, "/" );
}
return preg_replace( "/[^a-zA-Z0-9\-\_".$additional_tags."]/", "" , $t );
}
/*-------------------------------------------------------------------------*/
// txt_mb_strlen
// ------------------
// Multi byte char string length
/*-------------------------------------------------------------------------*/
/**
* Get the true length of a multi-byte character string
*
* @param string Input String
* @return intger String length
* @since 2.1
*/
function txt_mb_strlen( $t )
{
return strlen( preg_replace("/([0-9]+);/", "-", $this->txt_stripslashes( $t ) ) );
}
/*-------------------------------------------------------------------------*/
// txt_stripslashes
// ------------------
// Make Big5 safe - only strip if not already...
/*-------------------------------------------------------------------------*/
/**
* Remove slashes if magic_quotes enabled
*
* @param string Input String
* @return string Parsed string
* @since 2.0
*/
function txt_stripslashes($t)
{
if ( $this->get_magic_quotes )
{
$t = stripslashes($t);
$t = preg_replace( "/\\\(?!&#|\?#)/", "\", $t );
}
return $t;
}
/*-------------------------------------------------------------------------*/
// txt_raw2form
// ------------------
// makes _POST text safe for text areas
/*-------------------------------------------------------------------------*/
/**
* Convert text for use in a textarea
*
* @param string Input String
* @return string Parsed string
* @since 2.0
*/
function txt_raw2form($t="")
{
$t = str_replace( '$', "$", $t);
if ( $this->get_magic_quotes )
{
$t = stripslashes($t);
}
$t = preg_replace( "/\\\(?!&#|\?#)/", "\", $t );
//---------------------------------------
// Make sure macros aren't converted
//---------------------------------------
$t = preg_replace( "/<{(.+?)}>/", "<{\\1}>", $t );
return $t;
}
/*-------------------------------------------------------------------------*/
// txt_form2raw
// ------------------
// Converts textarea to raw
/*-------------------------------------------------------------------------*/
/**
* Unconvert text for use in a textarea
*
* @param string Input String
* @return string Parsed string
* @since 2.0
*/
function txt_form2raw($t="")
{
$t = str_replace( "$", '$' , $t);
$t = str_replace( "\", '\\', $t );
return $t;
}
/*-------------------------------------------------------------------------*/
// Safe Slashes - ensures slashes are saved correctly
/*-------------------------------------------------------------------------*/
/**
* Attempt to make slashes safe for us in DB (not really needed now?)
*
* @param string Input String
* @return string Parsed string
* @since 2.0
*/
function txt_safeslashes($t="")
{
return str_replace( '\\', "\\\\", $this->txt_stripslashes($t));
}
/*-------------------------------------------------------------------------*/
// txt_htmlspecialchars
// ------------------
// Custom version of htmlspecialchars to take into account mb chars
/*-------------------------------------------------------------------------*/
/**
* htmlspecialchars including multi-byte characters
*
* @param string Input String
* @return string Parsed string
* @since 2.0
*/
function txt_htmlspecialchars($t="")
{
// Use forward look up to only convert & not {
$t = preg_replace("/&(?!#[0-9]+;)/s", '&', $t );
$t = str_replace( "<", "<" , $t );
$t = str_replace( ">", ">" , $t );
$t = str_replace( '"', """, $t );
$t = str_replace( "'", ''', $t );
return $t; // A nice cup of?
}
/*-------------------------------------------------------------------------*/
// txt_UNhtmlspecialchars
// ------------------
// Undoes what the above function does. Yes.
/*-------------------------------------------------------------------------*/
/**
* unhtmlspecialchars including multi-byte characters
*
* @param string Input String
* @return string Parsed string
* @since 2.0
*/
function txt_UNhtmlspecialchars($t="")
{
$t = str_replace( "&" , "&", $t );
$t = str_replace( "<" , "<", $t );
$t = str_replace( ">" , ">", $t );
$t = str_replace( """, '"', $t );
$t = str_replace( "'", "'", $t );
return $t;
}
/*-------------------------------------------------------------------------*/
// txt_wintounix
// ------------------
// Converts \r\n to \n
/*-------------------------------------------------------------------------*/
/**
* Convert windows newlines to unix newlines
*
* @param string Input String
* @return string Parsed string
* @since 2.0
*/
function txt_windowstounix($t="")
{
// windows
$t = str_replace( "\r\n" , "\n", $t );
// Mac OS 9
$t = str_replace( "\r" , "\n", $t );
return $t;
}
/*-------------------------------------------------------------------------*/
// return_md5_check
// ------------------
// md5 hash for server side validation of form / link stuff
/*-------------------------------------------------------------------------*/
/**
* Return MD5 hash for use in forms
*
* @return string MD5 hash
* @since 2.0
*/
function return_md5_check()
{
if ( $this->member['id'] )
{
return md5( $this->member['email'].'&'.$this->member['member_login_key'].'&'.$this->member['joined'] );
}
else
{
return md5("this is only here to prevent it breaking on guests");
}
}
/*-------------------------------------------------------------------------*/
// C.O.C.S (clean old comma-delimeted strings)
// ------------------
// <>
/*-------------------------------------------------------------------------*/
/**
* Remove leading comma from comma delim string
*
* @param string Input String
* @return string Parsed string
* @since 2.0
*/
function trim_leading_comma($t)
{
return preg_replace( "/^,/", "", $t );
}
/**
* Remove trailing comma from comma delim string
*
* @param string Input String
* @return string Parsed string
* @since 2.0
*/
function trim_trailing_comma($t)
{
return preg_replace( "/,$/", "", $t );
}
/**
* Remove dupe commas from comma delim string
*
* @param string Input String
* @return string Parsed string
* @since 2.0
*/
function clean_comma($t)
{
return preg_replace( "/,{2,}/", ",", $t );
}
/**
* Clean perm string (wrapper for comma cleaners)
*
* @param string Input String
* @return string Parsed string
* @since 2.0
*/
function clean_perm_string($t)
{
$t = $this->clean_comma($t);
$t = $this->trim_leading_comma($t);
$t = $this->trim_trailing_comma($t);
return $t;
}
/*-------------------------------------------------------------------------*/
// Calculate max post size
/*-------------------------------------------------------------------------*/
function math_get_post_max_size()
{
$max_file_size = 16777216;
$tmp = 0;
$_post = @ini_get('post_max_size');
$_upload = @ini_get('upload_max_filesize');
if ( $_upload > $_post )
{
$tmp = $_post;
}
else
{
$tmp = $_upload;
}
if ( $tmp )
{
$max_file_size = $tmp;
unset($tmp);
preg_match( "#^(\d+)(\w+)$#", strtolower($max_file_size), $match );
if ( $match[2] == 'm' )
{
$max_file_size = intval( $max_file_size ) * 1024 * 1024;
}
else if ( $match[2] == 'k' )
{
$max_file_size = intval( $max_file_size ) * 1024;
}
else
{
$max_file_size = intval( $max_file_size );
}
}
return $max_file_size;
}
/*-------------------------------------------------------------------------*/
// math_strlen_to_bytes
/*-------------------------------------------------------------------------*/
/**
* Convert strlen to bytes
*
* @param integer string length (no chars)
* @return integer Bytes
* @since 2.0
*/
function math_strlen_to_bytes( $strlen=0 )
{
$dh = pow(10, 0);
return round( $strlen / ( pow(1024, 0) / $dh ) ) / $dh;
}
/*-------------------------------------------------------------------------*/
// size_format
// ------------------
// Give it a byte to eat and it'll return nice stuff!
/*-------------------------------------------------------------------------*/
/**
* Convert bytes into kb, mb, etc
*
* @param integer size in bytes
* @return string Human size
* @since 2.0
*/
function size_format($bytes="")
{
$retval = "";
if ($bytes >= 1048576)
{
$retval = round($bytes / 1048576 * 100 ) / 100 . $this->lang['sf_mb'];
}
else if ($bytes >= 1024)
{
$retval = round($bytes / 1024 * 100 ) / 100 . $this->lang['sf_k'];
}
else
{
$retval = $bytes . $this->lang['sf_bytes'];
}
return $retval;
}
/*-------------------------------------------------------------------------*/
// print_forum_rules
// ------------------
// Checks and prints forum rules (if required)
/*-------------------------------------------------------------------------*/
/**
* Universal routine for printing forum rules
*
* @param array Forum data
* @return string Formatted rules HTML in wrapper
* @since 2.0
*/
function print_forum_rules($forum)
{
$ruleshtml = "";
$rules['fid'] = $forum['id'];
if ( isset($forum['show_rules']) AND $forum['show_rules'] )
{
if ( $forum['show_rules'] == 2 )
{
if ( isset($this->vars['forum_cache_minimum']) AND $this->vars['forum_cache_minimum'] )
{
$tmp = $this->DB->simple_exec_query( array( 'select' => 'rules_title, rules_text', 'from' => 'forums', 'where' => "id=".$forum['id']) );
$rules['title'] = $tmp['rules_title'];
$rules['body'] = $tmp['rules_text'];
}
else
{
$tmp = $this->DB->simple_exec_query( array( 'select' => 'rules_text', 'from' => 'forums', 'where' => "id=".$forum['id']) );
$rules['body'] = $tmp['rules_text'];
$rules['title'] = $forum['rules_title'];
}
$ruleshtml = $this->compiled_templates['skin_global']->forum_show_rules_full($rules);
}
else
{
if ( isset( $this->vars['forum_cache_minimum'] ) AND $this->vars['forum_cache_minimum'] )
{
$tmp = $this->DB->simple_exec_query( array( 'select' => 'rules_title', 'from' => 'forums', 'where' => "id=".$forum['id']) );
$rules['title'] = $tmp['rules_title'];
}
else
{
$rules['title'] = $forum['rules_title'];
}
$ruleshtml = $this->compiled_templates['skin_global']->forum_show_rules_link($rules);
}
}
return $ruleshtml;
}
/*-------------------------------------------------------------------------*/
//
// hdl_ban_line() : Get / set ban info
// Returns array on get and string on "set"
//
/*-------------------------------------------------------------------------*/
/**
* Get / set member's ban info
*
* @param array Ban info (unit, timespan, date_end, date_start)
* @return mixed
* @since 2.0
*/
function hdl_ban_line($bline)
{
if ( is_array( $bline ) )
{
// Set ( 'timespan' 'unit' )
$factor = $bline['unit'] == 'd' ? 86400 : 3600;
$date_end = time() + ( $bline['timespan'] * $factor );
return time() . ':' . $date_end . ':' . $bline['timespan'] . ':' . $bline['unit'];
}
else
{
$arr = array();
list( $arr['date_start'], $arr['date_end'], $arr['timespan'], $arr['unit'] ) = explode( ":", $bline );
return $arr;
}
}
/*-------------------------------------------------------------------------*/
//
// check_perms() : Nice little sub to check perms
// Returns TRUE if access is allowed, FALSE if not.
//
/*-------------------------------------------------------------------------*/
/**
* Check forum permissions
*
* @param string Comma delim. forum permission string (2,4,5,6)
* @return boolean
* @since 2.0
*/
function check_perms($forum_perm="")
{
if ( ! is_array( $this->perm_id_array ) )
{
return FALSE;
}
if ( $forum_perm == "" )
{
return FALSE;
}
else if ( $forum_perm == '*' )
{
return TRUE;
}
else
{
$forum_perm_array = explode( ",", $forum_perm );
foreach( $this->perm_id_array as $u_id )
{
if ( in_array( $u_id, $forum_perm_array ) )
{
return TRUE;
}
}
// Still here? Not a match then.
return FALSE;
}
}
/*-------------------------------------------------------------------------*/
//
// check_perms() : Nice little sub to check perms
// Returns TRUE if access is allowed, FALSE if not.
//
/*-------------------------------------------------------------------------*/
/**
* Check forum permissions
*
* @param string Comma delim. of group IDs (2,4,5,6)
* @return string Comma delim of PERM MASK ids
* @since 2.1.1
*/
function create_perms_from_group( $in_group_ids )
{
$out = "";
if ( $in_group_ids == '*' )
{
foreach( $this->cache['group_cache'] as $data )
{
if ( ! $data['g_id'] )
{
continue;
}
//-----------------------------------------
// Got a perm mask?
//-----------------------------------------
if ( $data['g_perm_id'] )
{
$out .= ',' . $data['g_perm_id'];
}
}
}
else if ( $in_group_ids )
{
$groups_id = explode( ',', $in_group_ids );
if ( count( $groups_id ) )
{
foreach( $groups_id as $pid )
{
if ( ! $this->cache['group_cache'][ $pid ]['g_id'] )
{
continue;
}
//-----------------------------------------
// Got a perm mask?
//-----------------------------------------
if ( $this->cache['group_cache'][ $pid ]['g_perm_id'] )
{
$out .= ',' . $this->cache['group_cache'][ $pid ]['g_perm_id'];
}
}
}
}
//-----------------------------------------
// Tidy perms_id
//-----------------------------------------
$out = $this->clean_perm_string( $out );
return $out;
}
/*-------------------------------------------------------------------------*/
//
// do_number_format() : Nice little sub to handle common stuff
//
/*-------------------------------------------------------------------------*/
/**
* Wrapper for number_format
*
* @param integer Number
* @return string Formatted number
* @since 2.0
*/
function do_number_format($number)
{
if ( $this->vars['number_format'] != 'none' )
{
return number_format($number , 0, '', $this->num_format);
}
else
{
return $number;
}
}
/*-------------------------------------------------------------------------*/
//
// hdl_forum_read_cookie()
//
/*-------------------------------------------------------------------------*/
/**
* Get / set forum read cookie
*
* @param integer set / get flag
* @return boolean
* @since 2.0
*/
function hdl_forum_read_cookie($set="")
{
if ( $set == "" )
{
// Get cookie and return array...
if ( $fread = $this->my_getcookie('forum_read') )
{
if( $fread != "-1" )
{
$farray = unserialize(stripslashes($fread));
if ( is_array($farray) and count($farray) > 0 )
{
foreach( $farray as $id => $stamp )
{
$this->forum_read[ intval($id) ] = intval($stamp);
}
}
}
}
return TRUE;
}
else
{
// Set cookie...
$fread = addslashes(serialize($this->forum_read));
$this->my_setcookie('forum_read', $fread);
return TRUE;
}
}
/*-------------------------------------------------------------------------*/
//
// Return scaled down image
//
/*-------------------------------------------------------------------------*/
/**
* Scale image
*
* @param array
* @todo Direct to kernel/class_image.php?
* @return array
* @since 2.0
*/
function scale_image($arg)
{
// max_width, max_height, cur_width, cur_height
$ret = array(
'img_width' => $arg['cur_width'],
'img_height' => $arg['cur_height']
);
if ( $arg['cur_width'] > $arg['max_width'] )
{
$ret['img_width'] = $arg['max_width'];
$ret['img_height'] = ceil( ( $arg['cur_height'] * ( ( $arg['max_width'] * 100 ) / $arg['cur_width'] ) ) / 100 );
$arg['cur_height'] = $ret['img_height'];
$arg['cur_width'] = $ret['img_width'];
}
if ( $arg['cur_height'] > $arg['max_height'] )
{
$ret['img_height'] = $arg['max_height'];
$ret['img_width'] = ceil( ( $arg['cur_width'] * ( ( $arg['max_height'] * 100 ) / $arg['cur_height'] ) ) / 100 );
}
return $ret;
}
/*-------------------------------------------------------------------------*/
//
// Show NORMAL created security image(s)...
//
/*-------------------------------------------------------------------------*/
/**
* Show anti-spam bot GIF image numbers
*
* @param integer Current number to show
* @return void
* @since 2.0
*/
function show_gif_img($this_number="")
{
$numbers = array( 0 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIUDH5hiKsOnmqSPjtT1ZdnnjCUqBQAOw==',
1 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIUjAEWyMqoXIprRkjxtZJWrz3iCBQAOw==',
2 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIUDH5hiKubnpPzRQvoVbvyrDHiWAAAOw==',
3 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIVDH5hiKbaHgRyUZtmlPtlfnnMiGUFADs=',
4 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIVjAN5mLDtjFJMRjpj1Rv6v1SHN0IFADs=',
5 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIUhA+Bpxn/DITL1SRjnps63l1M9RQAOw==',
6 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIVjIEYyWwH3lNyrQTbnVh2Tl3N5wQFADs=',
7 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIUhI9pwbztAAwP1napnFnzbYEYWAAAOw==',
8 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIVDH5hiKubHgSPWXoxVUxC33FZZCkFADs=',
9 => 'R0lGODlhCAANAJEAAAAAAP////4BAgAAACH5BAQUAP8ALAAAAAAIAA0AAAIVDA6hyJabnnISnsnybXdS73hcZlUFADs=',
);
@header("Content-Type: image/gif");
echo base64_decode($numbers[ $this_number ]);
exit();
}
/*-------------------------------------------------------------------------*/
//
// Show GD created security image...
//
/*-------------------------------------------------------------------------*/
/**
* Show anti-spam bot GD image numbers
*
* @param string Number string
* @return void
* @since 2.0
*/
function show_gd_img($content="")
{
if ( ! is_object( $this->work_classes['class_captcha'] ) )
{
require_once( KERNEL_PATH . 'class_captcha.php' );
$this->work_classes['class_captcha'] = new class_captcha();
$this->work_classes['class_captcha']->ipsclass =& $this;
$this->work_classes['class_captcha']->path_background = ROOT_PATH . 'style_captcha/captcha_backgrounds';
$this->work_classes['class_captcha']->path_fonts = ROOT_PATH . 'style_captcha/captcha_fonts';
}
return $this->work_classes['class_captcha']->captcha_show_gd_img( $content );
}
/*-------------------------------------------------------------------------*/
//
// Convert newlines to
nl2br is buggy with
on early PHP builds
//
/*-------------------------------------------------------------------------*/
/**
*
Safe nl2br (Buggy on old PHP builds)
*
* @param string Input text
* @return string Parsed text
* @since 2.0
*/
function my_nl2br($t="")
{
return str_replace( "\n", "
", $t );
}
/*-------------------------------------------------------------------------*/
//
// Convert
to newlines
//
/*-------------------------------------------------------------------------*/
/**
*
Safe br2nl
*
* @param string Input text
* @return string Parsed text
* @since 2.0
*/
function my_br2nl($t="")
{
$t = preg_replace( "#(?:\n|\r)?
(?:\n|\r)?#", "\n", $t );
$t = preg_replace( "#(?:\n|\r)?
(?:\n|\r)?#" , "\n", $t );
return $t;
}
/*-------------------------------------------------------------------------*/
//
// Creates a profile link if member is a reg. member, else just show name
//
/*-------------------------------------------------------------------------*/
/**
* Create profile link
*
* @param string User's display name
* @param integer User's DB ID
* @return string Parsed a href link
* @since 2.0
*/
function make_profile_link($name, $id="")
{
if ($id > 0)
{
return "$name";
}
else
{
return $name;
}
}
/*-------------------------------------------------------------------------*/
//
// Applies group suffix/prefix to a name
//
/*-------------------------------------------------------------------------*/
/**
* Format name based on group suffix/prefix
*
* @param string User's display name
* @param integer User's group ID
* @param string Optional prefix override
* @param string Optional suffix override
* @return string Formatted name
* @since 2.2
*/
function make_name_formatted($name, $group_id="", $prefix="", $suffix="")
{
if ( isset( $this->vars['ipb_disable_group_psformat'] ) and $this->vars['ipb_disable_group_psformat'] )
{
return $name;
}
if( !$group_id )
{
$group_id = 0;
}
if( !$prefix )
{
if( $this->cache['group_cache'][ $group_id ]['prefix'] )
{
$prefix = $this->cache['group_cache'][ $group_id ]['prefix'];
}
}
if( !$suffix )
{
if( $this->cache['group_cache'][ $group_id ]['suffix'] )
{
$suffix = $this->cache['group_cache'][ $group_id ]['suffix'];
}
}
return $prefix.$name.$suffix;
}
/*-------------------------------------------------------------------------*/
//
// Redirect using HTTP commands, not a page meta tag.
//
/*-------------------------------------------------------------------------*/
/**
* HTTP redirect with out message screen
*
* @param string URL to load
* @return void
* @since 2.0
*/
function boink_it($url)
{
// Ensure &s are taken care of
$url = str_replace( "&", "&", $url );
if ($this->vars['header_redirect'] == 'refresh')
{
@header("Refresh: 0;url=".$url);
}
else if ($this->vars['header_redirect'] == 'html')
{
$url = str_replace( '&', '&', str_replace( '&', '&', $url ) );
echo("");
exit();
}
else
{
@header("Location: ".$url);
}
exit();
}
/*-------------------------------------------------------------------------*/
//
// Create a random 8 character password
//
/*-------------------------------------------------------------------------*/
/**
* Create a random 15 character password
*
* @todo check if we still need this?
* @return string Password
* @since 2.0
*/
function make_password()
{
$pass = "";
// Want it random you say, eh?
// (enter evil laugh)
$unique_id = uniqid( mt_rand(), TRUE );
$prefix = $this->converge->generate_password_salt();
$unique_id .= md5( $prefix );
usleep( mt_rand(15000,1000000) );
// Hmm, wonder how long we slept for
mt_srand( (double)microtime()*1000000 );
$new_uniqueid = uniqid( mt_rand(), TRUE );
$final_rand = md5( $unique_id.$new_uniqueid );
mt_srand(); // Wipe out the seed
for ($i = 0; $i < 15; $i++)
{
$pass .= $final_rand{ mt_rand(0, 31) };
}
return $pass;
}
/*-------------------------------------------------------------------------*/
//
// Generate the appropriate folder icon for a topic
//
/*-------------------------------------------------------------------------*/
/**
* Generate the appropriate folder icon for a topic
*
* @param array Topic data array
* @param string Dot flag
* @param integer Last read time
* @return string Parsed macro
* @since 2.0
*/
function folder_icon($topic, $dot="", $last_time)
{
//-----------------------------------------
// Sort dot
//-----------------------------------------
if ($dot != "")
{
$dot = "_DOT";
}
if ($topic['state'] == 'closed')
{
return "<{B_LOCKED}>";
}
if ($topic['poll_state'])
{
if ( ! $this->member['id'] )
{
return "<{B_POLL_NN".$dot."}>";
}
if ($last_time && ($topic['last_vote'] > $last_time ))
{
return "<{B_POLL".$dot."}>";
}
return "<{B_POLL_NN".$dot."}>";
}
if ($topic['state'] == 'moved' or $topic['state'] == 'link')
{
return "<{B_MOVED}>";
}
if ( ! $this->member['id'] )
{
if ($topic['posts'] + 1 >= $this->vars['hot_topic'])
{
return "<{B_HOT_NN".$dot."}>";
}
else
{
return "<{B_NORM".$dot."}>";
}
}
if (($topic['posts'] + 1 >= $this->vars['hot_topic']) and ( (isset($last_time) ) && ($topic['last_post'] <= $last_time )))
{
return "<{B_HOT_NN".$dot."}>";
}
if ($topic['posts'] + 1 >= $this->vars['hot_topic'])
{
return "<{B_HOT".$dot."}>";
}
if ($last_time && ($topic['last_post'] > $last_time))
{
return "<{B_NEW".$dot."}>";
}
return "<{B_NORM".$dot."}>";
}
/*-------------------------------------------------------------------------*/
// text_tidy:
// Takes raw text from the DB and makes it all nice and pretty - which also
// parses un-HTML'd characters. Use this with caution!
/*-------------------------------------------------------------------------*/
/**
* Takes raw text from the DB and makes it all nice and pretty - which also
* parses un-HTML'd characters. Use this with caution!
*
* @param string Raw text
* @return string Parsed text
* @since 2.0
* @todo Check if we still need this
* @deprecated Since IPB 2.1
*/
function text_tidy($txt = "") {
$trans = get_html_translation_table(HTML_ENTITIES);
$trans = array_flip($trans);
$txt = strtr( $txt, $trans );
$txt = preg_replace( "/\s{2}/" , " " , $txt );
$txt = preg_replace( "/\r/" , "\n" , $txt );
$txt = preg_replace( "/\t/" , " " , $txt );
//$txt = preg_replace( "/\\n/" , "\n" , $txt );
return $txt;
}
/*-------------------------------------------------------------------------*/
// Build up page span links
/*-------------------------------------------------------------------------*/
/**
* Build up page span links
*
* @param array Page data
* @return string Parsed page links HTML
* @since 2.0
*/
function build_pagelinks($data)
{
$data['leave_out'] = isset($data['leave_out']) ? $data['leave_out'] : '';
$data['no_dropdown'] = isset($data['no_dropdown']) ? intval( $data['no_dropdown'] ) : 0;
$data['USE_ST'] = isset($data['USE_ST']) ? $data['USE_ST'] : '';
$work = array( 'pages' => 0, 'page_span' => '', 'st_dots' => '', 'end_dots' => '' );
$section = !$data['leave_out'] ? 2 : $data['leave_out']; // Number of pages to show per section( either side of current), IE: 1 ... 4 5 [6] 7 8 ... 10
$use_st = !$data['USE_ST'] ? 'st' : $data['USE_ST'];
//-----------------------------------------
// Get the number of pages
//-----------------------------------------
if ( $data['TOTAL_POSS'] > 0 )
{
$work['pages'] = ceil( $data['TOTAL_POSS'] / $data['PER_PAGE'] );
}
$work['pages'] = $work['pages'] ? $work['pages'] : 1;
//-----------------------------------------
// Set up
//-----------------------------------------
$work['total_page'] = $work['pages'];
$work['current_page'] = $data['CUR_ST_VAL'] > 0 ? ($data['CUR_ST_VAL'] / $data['PER_PAGE']) + 1 : 1;
//-----------------------------------------
// Next / Previous page linkie poos
//-----------------------------------------
$previous_link = "";
$next_link = "";
if ( $work['current_page'] > 1 )
{
$start = $data['CUR_ST_VAL'] - $data['PER_PAGE'];
$previous_link = $this->compiled_templates['skin_global']->pagination_previous_link("{$data['BASE_URL']}&$use_st=$start");
}
if ( $work['current_page'] < $work['pages'] )
{
$start = $data['CUR_ST_VAL'] + $data['PER_PAGE'];
$next_link = $this->compiled_templates['skin_global']->pagination_next_link("{$data['BASE_URL']}&$use_st=$start");
}
//-----------------------------------------
// Loppy loo
//-----------------------------------------
if ($work['pages'] > 1)
{
$work['first_page'] = $this->compiled_templates['skin_global']->pagination_make_jump($work['pages'], $data['no_dropdown']);
if ( 1 < ($work['current_page'] - $section))
{
$work['st_dots'] = $this->compiled_templates['skin_global']->pagination_start_dots($data['BASE_URL']);
}
for( $i = 0, $j= $work['pages'] - 1; $i <= $j; ++$i )
{
$RealNo = $i * $data['PER_PAGE'];
$PageNo = $i+1;
if ($RealNo == $data['CUR_ST_VAL'])
{
$work['page_span'] .= $this->compiled_templates['skin_global']->pagination_current_page( ceil( $PageNo ) );
}
else
{
if ($PageNo < ($work['current_page'] - $section))
{
// Instead of just looping as many times as necessary doing nothing to get to the next appropriate number, let's just skip there now
$i = $work['current_page'] - $section - 2;
continue;
}
// If the next page is out of our section range, add some dotty dots!
if ($PageNo > ($work['current_page'] + $section))
{
$work['end_dots'] = $this->compiled_templates['skin_global']->pagination_end_dots("{$data['BASE_URL']}&$use_st=".($work['pages']-1) * $data['PER_PAGE']);
break;
}
$work['page_span'] .= $this->compiled_templates['skin_global']->pagination_page_link("{$data['BASE_URL']}&$use_st={$RealNo}", ceil( $PageNo ) );
}
}
$work['return'] = $this->compiled_templates['skin_global']->pagination_compile($work['first_page'],$previous_link,$work['st_dots'],$work['page_span'],$work['end_dots'],$next_link,$data['TOTAL_POSS'],$data['PER_PAGE'], $data['BASE_URL'], $data['no_dropdown'], $use_st);
}
else
{
$work['return'] = $data['L_SINGLE'];
}
return $work['return'];
}
/*-------------------------------------------------------------------------*/
// Build the forum jump menu
/*-------------------------------------------------------------------------*/
/**
* Build