IPB
By: Joost | Date: May 6 2007 15:51 | Format: PHP | Expires: never | Size: 64 KB | Hits: 2968
- <?php
- /*
- +--------------------------------------------------------------------------
- | Invision Power Board
- | =============================================
- | by Matthew Mecham
- | (c) 2001 - 2006 Invision Power Services, Inc.
- | http://www.invisionpower.com
- | =============================================
- | Web: http://www.invisionboard.com
- | Licence Info: http://www.invisionboard.com/?license
- +---------------------------------------------------------------------------
- | > $Date: 2007-02-05 15:21:24 -0500 (Mon, 05 Feb 2007) $
- | > $Revision: 838 $
- | > $Author: bfarber $
- +---------------------------------------------------------------------------
- |
- | > 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:
- * <code>
- * // 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
- * </code>
- * Recommended method of passing $ipsclass through modules
- * <code>
- * $module = new module();
- * $module->ipsclass =& $ipsclass; // Create reference
- * </code>
- *
- * @package InvisionPowerBoard
- * @author Matt Mecham
- * @copyright Invision Power Services, Inc.
- * @version 2.1
- */
- {
- /**
- * IPSCLASS loaded Flag
- */
- }
- /**
- * 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
- */
- /**
- * _GET _POST Input Array
- *
- * @var array
- */
- '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
- */
- /**
- * Language strings array
- *
- * @var array
- */
- /**
- * Skin variables array
- *
- * @var array
- */
- /**
- * Compiled loaded templates
- *
- * @var array
- */
- /**
- * Loaded templates inc. ID
- *
- * @var array
- */
- /**
- * Cache array
- *
- * @var 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
- */
- /**
- * 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 = '';
- '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';
- {
- }
- else
- {
- $n = $b = $r = '';
- }
- $this->vn_full = $this->acpversion;
- $this->acpversion = $n;
- $this->vn_build_date = $b;
- $this->vn_build_reason = $r;
- //-----------------------------------------
- // Time options
- //-----------------------------------------
- 'SHORT' => $this->vars['clock_short'],
- 'LONG' => $this->vars['clock_long'],
- );
- $this->num_format = ( $this->vars['number_format'] == 'space' ) ? ' ' : $this->vars['number_format'];
- //-----------------------------------------
- // Sort out the accessing IP
- // (Thanks to Cosmos and schickb)
- //-----------------------------------------
- if ( $this->vars['xforward_matching'] )
- {
- {
- {
- $addrs[] = $x_f;
- }
- }
- $addrs[] = $this->my_getenv('HTTP_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 )
- {
- $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
- //-----------------------------------------
- {
- print "Could not determine your IP address";
- }
- #Backwards compat:
- $this->input["IP_ADDRESS"] = $this->ip_address;
- //-----------------------------------------
- // Make a safe query string
- //-----------------------------------------
- $this->query_string_safe = str_replace( '&amp;', '&', $this->parse_clean_value( urldecode($this->my_getenv('QUERY_STRING')) ) );
- //-----------------------------------------
- // Format it..
- //-----------------------------------------
- $this->query_string_formatted = str_replace( $this->vars['board_url'] . '/index.'.$this->vars['php_ext'].'?', '', $this->query_string_safe );
- //-----------------------------------------
- // 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
- //-----------------------------------------
- //-----------------------------------------
- // IPS CLASS INITIATED
- //-----------------------------------------
- {
- }
- //-----------------------------------------
- // 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
- //--------------------------------
- {
- require KERNEL_PATH.'class_cache_diskcache.php';
- $this->cachelib = new cache_lib( $this->vars['board_url'] );
- }
- {
- // There was a problem - not installed maybe?
- $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...
- //--------------------------------
- {
- foreach( $cachearray as $key )
- {
- $temp_cache[$key] = $this->cachelib->do_get( $key );
- if( !$temp_cache[$key] )
- {
- $new_cache_array[] = $key;
- }
- else
- {
- if ( $key == 'settings' )
- {
- {
- foreach( $tmp as $k => $v )
- {
- $this->vars[ $k ] = $v;
- }
- }
- {
- $this->vars['blog_default_view'] = '';
- }
- }
- else
- {
- {
- }
- else if( $temp_cache[$key] == "EMPTY" )
- {
- $this->cache[ $key ] = NULL;
- }
- else
- {
- $this->cache[ $key ] = $temp_cache[$key];
- }
- }
- }
- }
- $cachearray = $new_cache_array;
- }
- //echo "<pre>";print_r($this->cache);exit;
- //--------------------------------
- // Generate cache list
- //--------------------------------
- $cachelist = "";
- {
- }
- //--------------------------------
- // 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' )
- {
- {
- foreach( $tmp as $k => $v )
- {
- $this->vars[ $k ] = $v;
- }
- }
- {
- $this->vars['blog_default_view'] = '';
- }
- }
- else
- {
- if ( $r['cs_array'] )
- {
- }
- else
- {
- $this->cache[ $r['cs_key'] ] = $r['cs_value'];
- }
- }
- {
- if( !$r['cs_value'] )
- {
- $r['cs_value'] = "EMPTY";
- }
- $this->cachelib->do_put( $r['cs_key'], $r['cs_value'] );
- }
- }
- }
- {
- }
- {
- $this->update_forum_cache();
- }
- {
- 'from' => 'groups'
- ) );
- $this->DB->simple_exec();
- while ( $i = $this->DB->fetch_row() )
- {
- $this->cache['group_cache'][ $i['g_id'] ] = $i;
- }
- }
- //--------------------------------
- // Set up cache path
- //--------------------------------
- {
- if ( $this->vars['ipb_cache_path'] )
- {
- }
- else
- {
- }
- }
- //-----------------------------------------
- // IPS CACHE LOADED
- //-----------------------------------------
- {
- }
- //--------------------------------
- // 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()
- {
- $this->vars['sql_driver'] = ! $this->vars['sql_driver'] ? 'mysql' : strtolower($this->vars['sql_driver']);
- {
- 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['use_error_log'] = IN_DEV ? 0 : 1;
- # Debug log - Don't use this on a production board!
- $this->DB->obj['use_debug_log'] = 0;
- //-----------------------------------
- // Load query file
- //-----------------------------------
- {
- $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?
- //-----------------------------------
- {
- foreach( $this->DB->connect_vars as $k => $v )
- {
- }
- }
- //--------------------------------
- // 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
- //--------------------------------
- //--------------------------------
- // Get a DB connection
- //--------------------------------
- $this->DB->connect();
- //-----------------------------------------
- // IPS DB LOADED
- //-----------------------------------------
- {
- }
- }
- /*-------------------------------------------------------------------------*/
- // Get browser
- // Return: unknown, windows, mac
- /*-------------------------------------------------------------------------*/
- /**
- * Fetches the user's operating system
- *
- * @return string
- */
- function fetch_os()
- {
- {
- return 'mac';
- }
- {
- 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";
- //-----------------------------------------
- // Opera...
- //-----------------------------------------
- {
- }
- //-----------------------------------------
- // IE...
- //-----------------------------------------
- {
- }
- //-----------------------------------------
- // Safari...
- //-----------------------------------------
- {
- }
- //-----------------------------------------
- // Mozilla browsers...
- //-----------------------------------------
- {
- }
- //-----------------------------------------
- // Older Mozilla browsers...
- //-----------------------------------------
- {
- }
- //-----------------------------------------
- // Konqueror...
- //-----------------------------------------
- {
- }
- //-----------------------------------------
- // Still here?
- //-----------------------------------------
- }
- /*-------------------------------------------------------------------------*/
- //
- // 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...
- //-----------------------------------------
- {
- return TRUE;
- }
- //-----------------------------------------
- // INIT
- //-----------------------------------------
- $cookie = $this->my_getcookie( 'ipb_stronghold' );
- //-----------------------------------------
- // Check
- //-----------------------------------------
- if ( ! $cookie )
- {
- return FALSE;
- }
- //-----------------------------------------
- // Put it together....
- //-----------------------------------------
- //-----------------------------------------
- // 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...
- //-----------------------------------------
- {
- return FALSE;
- }
- //-----------------------------------------
- // INIT
- //-----------------------------------------
- //-----------------------------------------
- // Put it together....
- //-----------------------------------------
- //-----------------------------------------
- // 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;
- }
- {
- $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)
- {
- $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;
- }
- {
- 'select' => '*',
- 'from' => 'topic_mmod',
- 'order' => 'mm_title'
- ) );
- $this->DB->simple_exec();
- while ($i = $this->DB->fetch_row())
- {
- $this->cache['multimod'][ $i['mm_id'] ] = $i;
- }
- }
- //-----------------------------------------
- // Get the topic mod thingies
- //-----------------------------------------
- {
- foreach( $this->cache['multimod'] as $r )
- {
- {
- }
- }
- }
- 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="" )
- {
- }
- /*-------------------------------------------------------------------------*/
- // 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
- //-----------------------------------------
- //-----------------------------------------
- // Got a member ID?
- //-----------------------------------------
- if ( ! $member_id )
- {
- return FALSE;
- }
- //-----------------------------------------
- // Got anything to update?
- //-----------------------------------------
- {
- return FALSE;
- }
- //-----------------------------------------
- // Got a current cache?
- //-----------------------------------------
- {
- $member = $this->DB->build_and_exec_query( array( 'select' => "members_cache", 'from' => 'members', 'where' => 'id='.$member_id ) );
- }
- //-----------------------------------------
- // Overwrite...
- //-----------------------------------------
- foreach( $new_cache_array as $k => $v )
- {
- $current_cache_array[ $k ] = $v;
- }
- //-----------------------------------------
- // Update...
- //-----------------------------------------
- //-----------------------------------------
- // 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' );
- {
- $ignore_me[] = 'description';
- $ignore_me[] = 'rules_title';
- }
- 'from' => 'forums',
- 'order' => 'parent_id, position'
- ) );
- $this->DB->simple_exec();
- while( $f = $this->DB->fetch_row() )
- {
- //-----------------------------------------
- // 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 )
- {
- {
- continue;
- }
- else
- {
- if ( $v != "" )
- {
- $fr[ $k ] = $v;
- }
- }
- }
- }
- $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
- */
- {
- //-----------------------------------------
- // Don't cache forums?
- //-----------------------------------------
- if ( $v['name'] == 'forum_cache' AND isset($this->vars['no_cache_forums']) AND $this->vars['no_cache_forums'] )
- {
- return;
- }
- //-----------------------------------------
- // Next...
- //-----------------------------------------
- if ( $v['name'] )
- {
- {
- {
- }
- else
- {
- $value = $this->cache[ $v['name'] ];
- }
- }
- else
- {
- {
- }
- else
- {
- $value = $v['value'];
- }
- }
- $this->DB->no_escape_fields['cs_key'] = 1;
- if ( $v['deletefirst'] == 1 )
- {
- if ( $v['donow'] )
- {
- if ( $this->vars['sql_driver'] == 'mysql' )
- {
- $this->DB->query( "REPLACE INTO ".SQL_PREFIX."cache_store SET cs_key='{$v['name']}', cs_value='".$this->DB->add_slashes($value)."', cs_array=".intval($v['array']) );
- }
- else
- {
- $this->DB->simple_construct( array( 'delete' => 'cache_store', 'where' => "cs_key='{$v['name']}'" ) );
- $this->DB->simple_exec();
- }
- }
- else
- {
- if ( $this->vars['sql_driver'] == 'mysql' )
- {
- $this->DB->query( "REPLACE INTO ".SQL_PREFIX."cache_store SET cs_key='{$v['name']}', cs_value='".$this->DB->add_slashes($value)."', cs_array=".intval($v['array']) );
- }
- else
- {
- $this->DB->simple_construct( array( 'delete' => 'cache_store', 'where' => "cs_key='{$v['name']}'" ) );
- $this->DB->simple_shutdown_exec();
- }
- }
- }
- else
- {
- if ( $v['donow'] )
- {
- }
- else
- {
- }
- }
- {
- 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'] )
- {
- {
- //-----------------------------------------
- // 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
- {
- {
- }
- }
- {
- /*---------------------------------------------------------------
- | 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...
- ---------------------------------------------------------------*/
- if( $serverstats )
- {
- }
- }
- else
- {
- {
- $this->server_load = $load[1];
- }
- }
- if ( $this->server_load )
- {
- $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;
- {
- foreach( $this->DB->obj['shutdown_queries'] as $q )
- {
- $this->DB->query( $q );
- }
- }
- $this->DB->return_die = 1;
- $this->DB->close_db();
- {
- // 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;
- 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_exec();
- while ( $r = $this->DB->fetch_row() )
- {
- $data[] = $r;
- $sent_ids[] = $r['mail_id'];
- }
- {
- //-----------------------------------------
- // Delete sent mails and update count
- //-----------------------------------------
- $this->cache['systemvars']['mail_queue'] = $this->cache['systemvars']['mail_queue'] - count($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'];
- $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
- //-----------------------------------------
- require_once( ROOT_PATH."cache/lang_cache/".$this->lang_id."/".$file.".php" );
- {
- foreach ($lang as $k => $v)
- {
- $this->acp_lang[ $k ] = $v;
- }
- }
- }
- /*-------------------------------------------------------------------------*/
- //
- // 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;
- //-----------------------------------------
- // Select ID
- //-----------------------------------------
- if ( ! $id )
- {
- $id = $this->skin['_skincacheid'];
- }
- //-----------------------------------------
- // Full name
- //-----------------------------------------
- $skin_global_name = 'skin_global_'.$id;
- $_name = $name;
- //-----------------------------------------
- // Already got this template loaded?
- //-----------------------------------------
- {
- 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')
- {
- {
- //-----------------------------------------
- // Suck in skin global..
- //-----------------------------------------
- $this->load_template_from_php( 'skin_global', 'skin_global_'.$id, $id );
- //-----------------------------------------
- // Suck in normal file...
- //-----------------------------------------
- $this->load_template_from_php( $_name, $name.'_'.$id, $id );
- }
- else
- {
- //-----------------------------------------
- // Suck in normal file...
- //-----------------------------------------
- $this->load_template_from_php( $_name, $name.'_'.$id, $id );
- }
- }
- else
- {
- if ( $name == 'skin_global' )
- {
- //-----------------------------------------
- // Suck in skin global..
- //-----------------------------------------
- $this->load_template_from_php( 'skin_global', 'skin_global_'.$id, $id );
- return;
- }
- else
- {
- //-----------------------------------------
- // Suck in normal file...
- //-----------------------------------------
- $this->load_template_from_php( $_name, $name.'_'.$id, $id );
- }
- }
- }
- else
- {
- //-----------------------------------------
- // 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...
- //-----------------------------------------
- '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
- //-----------------------------------------
- {
- 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;
- $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..
- //-----------------------------------------
- {
- return;
- }
- //-----------------------------------------
- // Load the skin, man
- //-----------------------------------------
- '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
- //-----------------------------------------
- {
- 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 );
- }
- }
- }
- 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 ( $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' )
- {
- //-----------------------------------------
- // IN_DEV?
- //-----------------------------------------
- if ( IN_DEV AND $id == 1 )
- {
- //-----------------------------------------
- // Get data...
- //-----------------------------------------
- //-----------------------------------------
- // Get template class
- //-----------------------------------------
- {
- 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_profile' ) { print $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;
- 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;
- //-----------------------------------------
- // Do we have a 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
- {
- //-----------------------------------------
- // Do we have a skin for a particular forum?
- //-----------------------------------------
- {
- 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;
- }
- }
- {
- 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 )
- {
- $id = $skin_data['skin_set_id'];
- $skin_set = 1;
- }
- //-----------------------------------------
- // Get the skin
- //-----------------------------------------
- {
- $db_skin = $this->cachelib->do_get( 'Skin_Store_' . $id );
- }
- //print_r($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 ) );
- {
- $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['_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->s
Latest pastes
1 hours ago
11 hours ago
1 days ago
2 days ago
2 days ago