$Date: 2005-10-10 16:01:09 +0100 (Mon, 10 Oct 2005) $
| > $Revision: 5 $
| > $Author: josh $
+---------------------------------------------------------------------------
|
| > 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 = "v2.1.2";
/**
* LONG version number (Eg: 21000)
*
* @var string
*/
var $acpversion = '21008';
/**
* Member Array
*
* @var array
*/
var $member = array();
/**
* _GET _POST Input Array
*
* @var array
*/
var $input = array();
/**
* 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();
/**
* 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 = '';
/**
* MD5 Check variable
*/
var $md5_check = '';
/**#@-*/
var $server_load = 0;
var $can_use_fancy_js = 0;
var $offset_set = 0;
var $allow_unicode = 1;
var $get_magic_quotes = 0;
/**#@+
* @access public
* @var object
*/
var $converge;
var $print;
var $sess;
var $forums;
/**#@-*/
/**#@+
* @access public
* @var array
*/
var $topic_cache = array();
var $time_formats = array();
var $time_options = array();
var $today_array = array();
/**
* User's browser array (version, browser)
*/
var $browser;
/**#@-*/
/*-------------------------------------------------------------------------*/
// 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()
{
$this->time_options = array( 'JOINED' => $this->vars['clock_joined'],
'SHORT' => $this->vars['clock_short'],
'LONG' => $this->vars['clock_long'],
'TINY' => $this->vars['clock_tiny'] ? $this->vars['clock_tiny'] : 'j M Y - G:i',
'DATE' => $this->vars['clock_date'] ? $this->vars['clock_date'] : 'j M Y',
);
$this->num_format = ($this->vars['number_format'] == 'space') ? ' ' : $this->vars['number_format'];
$this->get_magic_quotes = get_magic_quotes_gpc();
//-----------------------------------------
// 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_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 == '...' )
{
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 );
//-----------------------------------------
// Upload dir?
//-----------------------------------------
$this->vars['upload_dir'] = $this->vars['upload_dir'] ? $this->vars['upload_dir'] : INS_ROOT_PATH.'uploads';
//-----------------------------------------
// Char set
//-----------------------------------------
$this->vars['gb_char_set'] = $this->vars['gb_char_set'] ? $this->vars['gb_char_set'] : 'iso-8859-1';
//-----------------------------------------
// 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: 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') )
{
//--------------------------------
// Generate cache list
//--------------------------------
$cachelist = "'".implode( "','", $cachearray )."'";
//--------------------------------
// Get...
//--------------------------------
$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;
}
}
unset( $tmp );
}
else
{
if ( $r['cs_array'] )
{
$this->cache[ $r['cs_key'] ] = unserialize( stripslashes($r['cs_value']) );
}
else
{
$this->cache[ $r['cs_key'] ] = $r['cs_value'];
}
}
}
if ( ! isset( $this->cache['systemvars'] ) )
{
$this->DB->simple_exec_query( array( 'delete' => 'cache_store', 'where' => "cs_key='systemvars'" ) );
$this->DB->do_insert( 'cache_store', array( 'cs_key' => 'systemvars', 'cs_value' => addslashes(serialize(array())), 'cs_array' => 1 ) );
}
//--------------------------------
// Set up cache path
//--------------------------------
if ( $this->vars['ipb_cache_path'] )
{
define( 'CACHE_PATH', $this->vars['ipb_cache_path'] );
}
else
{
define( 'CACHE_PATH', INS_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;
}
/*-------------------------------------------------------------------------*/
// INIT: DB Connection
/*-------------------------------------------------------------------------*/
/**
* Initializes the database connection and populates $ipsclass->DB
*
* @return void
*/
function init_db_connection( $db, $user, $pass, $host, $pre, $driver='mysql' )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$file = '';
//-----------------------------------------
// Cache file?
//-----------------------------------------
if ( defined( 'INS_SQL_FILE' ) )
{
$file = str_replace( '<%driver%>', $driver, INS_SQL_FILE );
}
$classname = "db_driver_".$driver;
$this->DB = new $classname;
$this->DB->obj['sql_database'] = $db;
$this->DB->obj['sql_user'] = $user;
$this->DB->obj['sql_pass'] = $pass;
$this->DB->obj['sql_host'] = $host;
$this->DB->obj['sql_tbl_prefix'] = $pre;
$this->DB->obj['use_shutdown'] = 0;
if ( $file )
{
$this->DB->obj['query_cache_file'] = $file;
}
if ( ! defined( 'SQL_PREFIX' ) )
{
define( 'SQL_PREFIX', $pre );
}
//-----------------------------------
// 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 ] = $this->vars[ $k ];
}
}
//--------------------------------
// Get a DB connection
//--------------------------------
$this->DB->connect();
//-----------------------------------------
// IPS DB LOADED
//-----------------------------------------
if ( ! defined( 'IPSCLASS_DB_LOADED' ) )
{
define( 'IPSCLASS_DB_LOADED', 1 );
}
}
/*-------------------------------------------------------------------------*/
// 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;
}
/*-------------------------------------------------------------------------*/
// 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 ( $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...
//-----------------------------------------
foreach( $f as $k => $v )
{
if ( in_array( $k, $ignore_me ) )
{
continue;
}
else
{
if ( $v != "" )
{
$fr[ $k ] = $v;
}
}
}
$fr['read_perms'] = $perms['read_perms'];
$fr['reply_perms'] = $perms['reply_perms'];
$fr['start_perms'] = $perms['start_perms'];
$fr['upload_perms'] = $perms['upload_perms'];
$fr['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' => 1, 'donow' => 1 ) );
}
/*-------------------------------------------------------------------------*/
//
// 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 $this->vars['no_cache_forums'] )
{
return;
}
//-----------------------------------------
// Next...
//-----------------------------------------
if ( $v['name'] )
{
if ( ! $v['value'] )
{
$value = $this->DB->add_slashes(serialize($this->cache[ $v['name'] ]));
}
$this->DB->manual_addslashes = 1;
$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']}'" );
}
}
$this->DB->manual_addslashes = 0;
}
}
/*-------------------------------------------------------------------------*/
//
// MY DECONSTRUCTOR
//
/*-------------------------------------------------------------------------*/
/**
* Manual deconstructor
*
* Runs any SQL shutdown queries and mail tasks
*
* @return void
*/
function my_deconstructor()
{
//-----------------------------------------
// 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();
//-----------------------------------------
// Process mail queue
//-----------------------------------------
$this->process_mail_queue();
$this->DB->close_db();
}
/*-------------------------------------------------------------------------*/
// txt_alphanumerical_clean
// ------------------
// Remove non alphas
/*-------------------------------------------------------------------------*/
/**
* Clean a string to remove all non alphanumeric characters
*
* @param string Input String
* @return string Parsed string
* @since 2.1
*/
function txt_alphanumerical_clean( $t )
{
return preg_replace( "/[^a-zA-Z0-9\-\_]/", "" , $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;
}
/*-------------------------------------------------------------------------*/
// 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;
}
/*-------------------------------------------------------------------------*/
//
// 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;
}
/*-------------------------------------------------------------------------*/
//
// 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')
{
echo("