aFunctions = array(); $this->aCallableObjects = array(); $this->aEvents = array( "beforeProcessing" => array(), "afterProcessing" => array(), "onMissingFunction" => array(), "onProcessingError" => array() ); $this->sRequestURI = $sRequestURI; if ($this->sRequestURI == "") $this->sRequestURI = $this->_detectURI(); $this->sWrapperPrefix = "xajax_"; $this->setFlags(array( "debug" => false, "statusMessages" => false, "waitCursor" => true, "exitAllowed" => true, "errorHandler" => false, "cleanBuffer" => false, "decodeUTF8Input" => false, "outputEntities" => false, "allowBlankResponse" => false)); $this->sLogFile = ""; $this->setCharEncoding(XAJAX_DEFAULT_CHAR_ENCODING); $this->iTimeout = 6000; // Setup plugin manager $oPluginManager =& xajaxPluginManager::getInstance(); $sMandatoryPluginFolder = dirname(__FILE__) . "/plugin_layer"; $oPluginManager->addPluginFolder($sMandatoryPluginFolder); $sOptionalPluginFolder = dirname(dirname(__FILE__))."/xajax_plugins"; if ($oPluginManager->addPluginFolder($sOptionalPluginFolder)) { // TODO...load plugins? } $oPluginManager->loadPluginFile("xajaxDefaultRequestProcessorPlugin"); $oPluginManager->registerRequestProcessorPlugin(new xajaxDefaultRequestProcessorPlugin()); $oPluginManager->loadPluginFile("xajaxDefaultIncludePlugin"); $oPluginManager->registerIncludePlugin(new xajaxDefaultIncludePlugin()); } /** * Returns an {@link xajaxResponse} object set up with this xajax object's * encoding and entity settings. Use this for singleton-pattern response * development. * * @return xajaxResponse */ function &getGlobalResponse() { static $obj; if (!$obj) { $obj = new xajaxResponse($this->sEncoding, $this->bOutputEntities); } return $obj; } /** * Returns the current xajax version. * * @return string */ function getVersion() { return 'xajax 0.5 Beta 1'; } /** * Sets multiple flags based on the supplied associative array (see * {@link xajax::setFlag()} for flag names) * * @param array */ function setFlags($flags) { foreach ($flags as $name => $value) { $this->setFlag($name, $value); } } /** * Sets a flag (boolean true or false). Available flags with their defaults * are as follows: * *
tags in your HTML page. * Remember, if you only want to obtain the result of this function, use * {@link xajax::getJavascript()} instead. (executes Javascript include * plugin) * * Usage: *
*
* ...
* < ?php $xajax->printJavascript(); ? >
*
*
* @param string the relative address of the folder where xajax has been
* installed. For instance, if your PHP file is
* "http://www.myserver.com/myfolder/mypage.php"
* and xajax was installed in
* "http://www.myserver.com/anotherfolder", then $sJsURI
* should be set to "../anotherfolder". Defaults to assuming
* xajax is in the same folder as your PHP file.
* @param string the relative folder/file pair of the xajax Javascript
* engine located within the xajax installation folder.
* Defaults to xajax_js/xajax.js.
*/
function printJavascript($sJsURI="", $sJsFile=NULL)
{
$objPluginManager =& xajaxPluginManager::getInstance();
$objInclude = $objPluginManager->getIncludePlugin();
$objInclude->setXajax($this);
$objInclude->setFunctions($this->aFunctions);
print $objInclude->getJavascript($sJsURI, $sJsFile);
}
/**
* Returns the xajax Javascript code that should be added to your HTML page
* between the tags. (executes Javascript include
* plugin)
*
* Usage:
*
* < ?php $xajaxJSHead = $xajax->getJavascript(); ? >
*
* ...
* < ?php echo $xajaxJSHead; ? >
*
*
* @param string the relative address of the folder where xajax has been
* installed. For instance, if your PHP file is
* "http://www.myserver.com/myfolder/mypage.php"
* and xajax was installed in
* "http://www.myserver.com/anotherfolder", then $sJsURI
* should be set to "../anotherfolder". Defaults to assuming
* xajax is in the same folder as your PHP file.
* @param string the relative folder/file pair of the xajax Javascript
* engine located within the xajax installation folder.
* Defaults to xajax_js/xajax.js.
* @return string
*/
function getJavascript($sJsURI="", $sJsFile=NULL)
{
$objPluginManager =& xajaxPluginManager::getInstance();
$objInclude = $objPluginManager->getIncludePlugin();
$objInclude->setXajax($this);
$objInclude->setFunctions($this->aFunctions);
return $objInclude->getJavascript($sJsURI, $sJsFile);
}
/**
* Returns a string containing inline Javascript that sets up the xajax
* runtime (typically called internally by xajax from get/printJavascript).
* (executes Javascript include plugin)
*
* @return string
*/
function getJavascriptConfig()
{
$objPluginManager =& xajaxPluginManager::getInstance();
$objInclude = $objPluginManager->getIncludePlugin();
$objInclude->setXajax($this);
$objInclude->setFunctions($this->aFunctions);
return $objInclude->getJavascriptConfig();
}
/**
* Returns a string containing a Javascript include of the xajax.js file
* along with a check to see if the file loaded after six seconds
* (typically called internally by xajax from get/printJavascript).
* (executes Javascript include plugin)
*
* @param string the relative address of the folder where xajax has been
* installed. For instance, if your PHP file is
* "http://www.myserver.com/myfolder/mypage.php"
* and xajax was installed in
* "http://www.myserver.com/anotherfolder", then $sJsURI
* should be set to "../anotherfolder". Defaults to assuming
* xajax is in the same folder as your PHP file.
* @param string the relative folder/file pair of the xajax Javascript
* engine located within the xajax installation folder.
* Defaults to xajax_js/xajax.js.
* @return string
*/
function getJavascriptInclude($sJsURI="", $sJsFile=NULL)
{
$objPluginManager =& xajaxPluginManager::getInstance();
$objInclude = $objPluginManager->getIncludePlugin();
$objInclude->setXajax($this);
$objInclude->setFunctions($this->aFunctions);
return $objInclude->getJavascriptInclude($sJsURI, $sJsFile);
}
/**
* This method can be used to create a new xajax.js file out of the
* xajax_uncompressed.js file (which will only happen if xajax.js doesn't
* already exist on the filesystem).
*
* @param string an optional argument containing the full server file path
* of xajax.js.
*/
function autoCompressJavascript($sJsFullFilename=NULL)
{
$sJsFile = "xajax_js/xajax.js";
if ($sJsFullFilename) {
$realJsFile = $sJsFullFilename;
}
else {
$realPath = realpath(dirname(dirname(__FILE__)));
$realJsFile = $realPath . "/". $sJsFile;
}
// Create a compressed file if necessary
if (!file_exists($realJsFile)) {
$srcFile = str_replace(".js", "_uncompressed.js", $realJsFile);
if (!file_exists($srcFile)) {
trigger_error("The xajax uncompressed Javascript file could not be found in the " . dirname($realJsFile) . " folder. Error ", E_USER_ERROR);
}
require(dirname(__FILE__)."/xajaxCompress.inc.php");
$javaScript = implode('', file($srcFile));
$compressedScript = xajaxCompressJavascript($javaScript);
$fH = @fopen($realJsFile, "w");
if (!$fH) {
trigger_error("The xajax compressed javascript file could not be written in the " . dirname($realJsFile) . " folder. Error ", E_USER_ERROR);
}
else {
fwrite($fH, $compressedScript);
fclose($fH);
}
}
}
/**
* Returns the current URL based upon the SERVER vars.
*
* @access private
* @return string
*/
function _detectURI() {
$aURL = array();
// Try to get the request URL
if (!empty($_SERVER['REQUEST_URI'])) {
$aURL = parse_url($_SERVER['REQUEST_URI']);
}
// Fill in the empty values
if (empty($aURL['scheme'])) {
if (!empty($_SERVER['HTTP_SCHEME'])) {
$aURL['scheme'] = $_SERVER['HTTP_SCHEME'];
} else {
$aURL['scheme'] = (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') ? 'https' : 'http';
}
}
if (empty($aURL['host'])) {
if (!empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
if (strpos($_SERVER['HTTP_X_FORWARDED_HOST'], ':') > 0) {
list($aURL['host'], $aURL['port']) = explode(':', $_SERVER['HTTP_X_FORWARDED_HOST']);
} else {
$aURL['host'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
}
} else if (!empty($_SERVER['HTTP_HOST'])) {
if (strpos($_SERVER['HTTP_HOST'], ':') > 0) {
list($aURL['host'], $aURL['port']) = explode(':', $_SERVER['HTTP_HOST']);
} else {
$aURL['host'] = $_SERVER['HTTP_HOST'];
}
} else if (!empty($_SERVER['SERVER_NAME'])) {
$aURL['host'] = $_SERVER['SERVER_NAME'];
} else {
print "xajax Error: xajax failed to automatically identify your Request URI.";
print "Please set the Request URI explicitly when you instantiate the xajax object.";
exit();
}
}
if (empty($aURL['port']) && !empty($_SERVER['SERVER_PORT'])) {
$aURL['port'] = $_SERVER['SERVER_PORT'];
}
if (empty($aURL['path'])) {
if (!empty($_SERVER['PATH_INFO'])) {
$sPath = parse_url($_SERVER['PATH_INFO']);
} else {
$sPath = parse_url($_SERVER['PHP_SELF']);
}
$aURL['path'] = $sPath['path'];
unset($sPath);
}
if (!empty($aURL['query'])) {
$aURL['query'] = '?'.$aURL['query'];
}
// Build the URL: Start with scheme, user and pass
$sURL = $aURL['scheme'].'://';
if (!empty($aURL['user'])) {
$sURL.= $aURL['user'];
if (!empty($aURL['pass'])) {
$sURL.= ':'.$aURL['pass'];
}
$sURL.= '@';
}
// Add the host
$sURL.= $aURL['host'];
// Add the port if needed
if (!empty($aURL['port']) && (($aURL['scheme'] == 'http' && $aURL['port'] != 80) || ($aURL['scheme'] == 'https' && $aURL['port'] != 443))) {
$sURL.= ':'.$aURL['port'];
}
// Add the path and the query string
$sURL.= $aURL['path'].@$aURL['query'];
// Clean up
unset($aURL);
return $sURL;
}
}// end class xajax
/**
* This function is registered with PHP's set_error_handler() function if
* the xajax error handling system is turned on.
*/
function xajaxErrorHandler($errno, $errstr, $errfile, $errline)
{
$errorReporting = error_reporting();
if (($errno & $errorReporting) == 0) return;
if ($errno == E_NOTICE) {
$errTypeStr = "NOTICE";
}
else if ($errno == E_WARNING) {
$errTypeStr = "WARNING";
}
else if ($errno == E_USER_NOTICE) {
$errTypeStr = "USER NOTICE";
}
else if ($errno == E_USER_WARNING) {
$errTypeStr = "USER WARNING";
}
else if ($errno == E_USER_ERROR) {
$errTypeStr = "USER FATAL ERROR";
}
else if (defined('E_STRICT') && $errno == E_STRICT) {
return;
}
else {
$errTypeStr = "UNKNOWN: $errno";
}
$GLOBALS['xajaxErrorHandlerText'] .= "\n----\n[$errTypeStr] $errstr\nerror in line $errline of file $errfile";
}
?>