294 lines
8.6 KiB
PHP
294 lines
8.6 KiB
PHP
<?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: 2006-08-01 17:02:55 +0100 (Tue, 01 Aug 2006) $
|
|
| > $Revision: 425 $
|
|
| > $Author: matt $
|
|
+---------------------------------------------------------------------------
|
|
|
|
|
| > AJAX Functions
|
|
| > Module written by Matt Mecham
|
|
| > Date started: Wednesday 2nd August 2006
|
|
|
|
|
+--------------------------------------------------------------------------
|
|
*/
|
|
|
|
if ( ! defined( 'IN_IPB' ) )
|
|
{
|
|
print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
|
|
exit();
|
|
}
|
|
|
|
class class_ajax
|
|
{
|
|
/**
|
|
* Global IPS class
|
|
*/
|
|
var $ipsclass;
|
|
|
|
/**
|
|
* XML output
|
|
*/
|
|
var $xml_output;
|
|
|
|
/**
|
|
* XML Header
|
|
*/
|
|
var $xml_header;
|
|
|
|
/**
|
|
* Character sets
|
|
*/
|
|
var $decode_charsets = array( 'iso-8859-1' => 'ISO-8859-1',
|
|
'iso8859-1' => 'ISO-8859-1',
|
|
'iso-8859-15' => 'ISO-8859-15',
|
|
'iso8859-15' => 'ISO-8859-15',
|
|
'utf-8' => 'UTF-8',
|
|
'cp866' => 'cp866',
|
|
'ibm866' => 'cp866',
|
|
'cp1251' => 'windows-1251',
|
|
'windows-1251' => 'windows-1251',
|
|
'win-1251' => 'windows-1251',
|
|
'cp1252' => 'windows-1252',
|
|
'windows-1252' => 'windows-1252',
|
|
'koi8-r' => 'KOI8-R',
|
|
'koi8-ru' => 'KOI8-R',
|
|
'koi8r' => 'KOI8-R',
|
|
'big5' => 'BIG5',
|
|
'gb2312' => 'GB2312',
|
|
'big5-hkscs' => 'BIG5-HKSCS',
|
|
'shift_jis' => 'Shift_JIS',
|
|
'sjis' => 'Shift_JIS',
|
|
'euc-jp' => 'EUC-JP',
|
|
'eucjp' => 'EUC-JP' );
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
// Initialize the class
|
|
/*-------------------------------------------------------------------------*/
|
|
/**
|
|
* INIT the class
|
|
*/
|
|
function class_init()
|
|
{
|
|
$this->xml_header = "<?xml version=\"1.0\" encoding=\"{$this->ipsclass->vars['gb_char_set']}\"?".'>';
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
// make string XML safe
|
|
/*-------------------------------------------------------------------------*/
|
|
/**
|
|
* Make a string safe for XML transport
|
|
*/
|
|
function _make_safe_for_xml( $t )
|
|
{
|
|
return str_replace( '&#39;', ''', htmlspecialchars( $t ) );
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
// Error handler
|
|
/*-------------------------------------------------------------------------*/
|
|
/**
|
|
* Print an error
|
|
*/
|
|
function error_handler()
|
|
{
|
|
@header( "Content-type: text/xml" );
|
|
$this->print_nocache_headers();
|
|
$this->xml_output = $this->xml_header."\r\n<errors>\r\n";
|
|
$this->xml_output .= "<error><message>You must be logged in to access this feature</message></error>\r\n";
|
|
$this->xml_output .= "</errors>";
|
|
print $this->xml_output;
|
|
exit();
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
// Return NOTHING :o
|
|
/*-------------------------------------------------------------------------*/
|
|
/**
|
|
* Return a NULL result
|
|
*/
|
|
function return_null($val=0)
|
|
{
|
|
@header( "Content-type: text/xml" );
|
|
$this->print_nocache_headers();
|
|
print $this->xml_header."\r\n<null>{$val}</null>";
|
|
exit();
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
// Return string
|
|
/*-------------------------------------------------------------------------*/
|
|
/**
|
|
* Return a string
|
|
*/
|
|
function return_string($string)
|
|
{
|
|
@header( "Content-type: text/plain" );
|
|
$this->print_nocache_headers();
|
|
print $string;
|
|
exit();
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
// Return HTML
|
|
/*-------------------------------------------------------------------------*/
|
|
/**
|
|
* Return a HTML
|
|
*/
|
|
function return_html($string)
|
|
{
|
|
//-----------------------------------------
|
|
// Stop one from removing cookie protection
|
|
//-----------------------------------------
|
|
|
|
$string = ( $string ) ? $string : '<!--nothing-->';
|
|
$string = preg_replace( "#htmldocument\.prototype#is", "HTMLDocument_prototype", $string );
|
|
|
|
// Fix IE bugs
|
|
$string = str_replace( "§", "&sect", $string );
|
|
$string = str_replace( "ì", "“", $string );
|
|
$string = str_replace( "î", "”", $string );
|
|
|
|
// Other stuff
|
|
$string = str_replace( "<#IMG_DIR#>", $this->ipsclass->skin['_imagedir'], $string );
|
|
$string = str_replace( "<#EMO_DIR#>", $this->ipsclass->skin['_emodir'] , $string );
|
|
|
|
@header( "Content-type: text/html;charset=".$this->ipsclass->vars['gb_char_set'] );
|
|
$this->print_nocache_headers();
|
|
print $string;
|
|
exit();
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
// Print no cache headers
|
|
/*-------------------------------------------------------------------------*/
|
|
/**
|
|
* Print nocache headers
|
|
*/
|
|
function print_nocache_headers()
|
|
{
|
|
header("HTTP/1.0 200 OK");
|
|
header("HTTP/1.1 200 OK");
|
|
header("Cache-Control: no-cache, must-revalidate, max-age=0");
|
|
header("Expires: 0");
|
|
header("Pragma: no-cache");
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
// Convert decimal character references to UTF-8
|
|
/*-------------------------------------------------------------------------*/
|
|
/**
|
|
* Convert a decimal character to UTF-8
|
|
*/
|
|
function dec_char_ref_to_utf8($int=0)
|
|
{
|
|
$return = '';
|
|
|
|
if ( $int < 0 )
|
|
{
|
|
return chr(0);
|
|
}
|
|
else if ( $int <= 0x007f )
|
|
{
|
|
$return .= chr($int);
|
|
}
|
|
else if ( $int <= 0x07ff )
|
|
{
|
|
$return .= chr(0xc0 | ($int >> 6));
|
|
$return .= chr(0x80 | ($int & 0x003f));
|
|
}
|
|
else if ( $int <= 0xffff )
|
|
{
|
|
$return .= chr(0xe0 | ($int >> 12));
|
|
$return .= chr(0x80 | (($int >> 6) & 0x003f));
|
|
$return .= chr(0x80 | ($int & 0x003f));
|
|
}
|
|
else if ( $int <= 0x10ffff )
|
|
{
|
|
$return .= chr(0xf0 | ($int >> 18));
|
|
$return .= chr(0x80 | (($int >> 12) & 0x3f));
|
|
$return .= chr(0x80 | (($int >> 6) & 0x3f));
|
|
$return .= chr(0x80 | ($int & 0x3f));
|
|
}
|
|
else
|
|
{
|
|
return chr(0);
|
|
}
|
|
|
|
return $return;
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
// Helper function
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
function dec_char_ref_to_utf8_hexdec( $matches )
|
|
{
|
|
return $this->dec_char_ref_to_utf8( hexdec( $matches[1] ) );
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
// Convert Ajax unicode
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
function convert_unicode($t)
|
|
{
|
|
if ( strtolower($this->ipsclass->vars['gb_char_set']) == 'utf-8' )
|
|
{
|
|
return preg_replace_callback( '#%u([0-9A-F]{1,4})#i', array( $this, 'dec_char_ref_to_utf8_hexdec' ), utf8_encode($t) );
|
|
}
|
|
else
|
|
{
|
|
return preg_replace_callback( '#%u([0-9A-F]{1,4})#i', create_function( '$matches', "return '&#' . hexdec(\$matches[1]) . ';';" ), $t );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Convert HTML entities and respect character sets
|
|
*/
|
|
function convert_html_entities($t)
|
|
{
|
|
//-----------------------------------------
|
|
// Try and fix up HTML entities with missing ;
|
|
//-----------------------------------------
|
|
|
|
$t = preg_replace( "/&#(\d+?)([^\d;])/i", "&#\\1;\\2", $t );
|
|
|
|
//-----------------------------------------
|
|
// Continue...
|
|
//-----------------------------------------
|
|
|
|
if ( strtolower($this->ipsclass->vars['gb_char_set']) != 'iso-8859-1' &&
|
|
strtolower($this->ipsclass->vars['gb_char_set']) != 'utf-8' )
|
|
{
|
|
if ( array_key_exists( strtolower($this->ipsclass->vars['gb_char_set']), $this->decode_charsets ) )
|
|
{
|
|
$this->ipsclass->vars['gb_char_set'] = $this->decode_charsets[strtolower($this->ipsclass->vars['gb_char_set'])];
|
|
$t = html_entity_decode( $t, ENT_NOQUOTES, $this->ipsclass->vars['gb_char_set'] );
|
|
}
|
|
else
|
|
{
|
|
// Take a crack at entities in other character sets
|
|
|
|
$t = str_replace( "&#", "&#", $t );
|
|
}
|
|
}
|
|
|
|
return $t;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
?>
|