📄 xajax.class.php
字号:
$sPreResponse = $mPreResponse[1];
}
else {
$sPreResponse = $mPreResponse;
}
if (is_a($sPreResponse, "xajaxResponse")) {
$sPreResponse = $sPreResponse->getXML();
}
if ($bEndRequest) $sResponse = $sPreResponse;
}
if (!$bEndRequest) {
if (!$this->_isFunctionCallable($sFunctionName)) {
$objResponse = new xajaxResponse();
$objResponse->addAlert("The Registered Function $sFunctionName Could Not Be Found.");
$sResponse = $objResponse->getXML();
}
else {
if ($bFunctionIsCatchAll) {
$aArgs = array($sFunctionNameForSpecial, $aArgs);
}
$sResponse = $this->_callFunction($sFunctionName, $aArgs);
}
if (is_a($sResponse, "xajaxResponse")) {
$sResponse = $sResponse->getXML();
}
if (!is_string($sResponse) || strpos($sResponse, "<xjx>") === FALSE) {
$objResponse = new xajaxResponse();
$objResponse->addAlert("No XML Response Was Returned By Function $sFunctionName.");
$sResponse = $objResponse->getXML();
}
else if ($sPreResponse != "") {
$sNewResponse = new xajaxResponse($this->sEncoding, $this->bOutputEntities);
$sNewResponse->loadXML($sPreResponse);
$sNewResponse->loadXML($sResponse);
$sResponse = $sNewResponse->getXML();
}
}
}
$sContentHeader = "Content-type: text/xml;";
if ($this->sEncoding && strlen(trim($this->sEncoding)) > 0)
$sContentHeader .= " charset=".$this->sEncoding;
header($sContentHeader);
if ($this->bErrorHandler && !empty( $GLOBALS['xajaxErrorHandlerText'] )) {
$sErrorResponse = new xajaxResponse();
$sErrorResponse->addAlert("** PHP Error Messages: **" . $GLOBALS['xajaxErrorHandlerText']);
if ($this->sLogFile) {
$fH = @fopen($this->sLogFile, "a");
if (!$fH) {
$sErrorResponse->addAlert("** Logging Error **\n\nxajax was unable to write to the error log file:\n" . $this->sLogFile);
}
else {
fwrite($fH, "** xajax Error Log - " . strftime("%b %e %Y %I:%M:%S %p") . " **" . $GLOBALS['xajaxErrorHandlerText'] . "\n\n\n");
fclose($fH);
}
}
$sErrorResponse->loadXML($sResponse);
$sResponse = $sErrorResponse->getXML();
}
if ($this->bCleanBuffer) while (@ob_end_clean());
print $sResponse;
if ($this->bErrorHandler) restore_error_handler();
if ($this->bExitAllowed)
exit();
}
function printJavascript($sJsURI="", $sJsFile=NULL)
{
print $this->getJavascript($sJsURI, $sJsFile);
}
function getJavascript($sJsURI="", $sJsFile=NULL)
{
$html = $this->getJavascriptConfig();
$html .= $this->getJavascriptInclude($sJsURI, $sJsFile);
return $html;
}
function getJavascriptConfig()
{
$html = "\t<script type=\"text/javascript\">\n";
$html .= "var xajaxRequestUri=\"".$this->sRequestURI."\";\n";
$html .= "var xajaxDebug=".($this->bDebug?"true":"false").";\n";
$html .= "var xajaxStatusMessages=".($this->bStatusMessages?"true":"false").";\n";
$html .= "var xajaxWaitCursor=".($this->bWaitCursor?"true":"false").";\n";
$html .= "var xajaxDefinedGet=".XAJAX_GET.";\n";
$html .= "var xajaxDefinedPost=".XAJAX_POST.";\n";
$html .= "var xajaxLoaded=false;\n";
foreach($this->aFunctions as $sFunction => $bExists) {
$html .= $this->_wrap($sFunction,$this->aFunctionRequestTypes[$sFunction]);
}
$html .= "\t</script>\n";
return $html;
}
function getJavascriptInclude($sJsURI="", $sJsFile=NULL)
{
if ($sJsFile == NULL) $sJsFile = "js/xajax.js";
if ($sJsURI != "" && substr($sJsURI, -1) != "/") $sJsURI .= "/";
$html = "\t<script type=\"text/javascript\" src=\"" . $sJsURI . $sJsFile . "\"></script>\n";
$html .= "\t<script type=\"text/javascript\">\n";
$html .= "window.setTimeout(function () { if (!xajaxLoaded) { alert('Error: the xajax Javascript file could not be included. Perhaps the URL is incorrect?\\nURL: {$sJsURI}{$sJsFile}'); } }, 6000);\n";
$html .= "\t</script>\n";
return $html;
}
function autoCompressJavascript($sJsFullFilename=NULL)
{
$sJsFile = "xajax_js/xajax.js";
if ($sJsFullFilename) {
$realJsFile = $sJsFullFilename;
}
else {
$realPath = realpath(dirname(__FILE__));
$realJsFile = $realPath . "/". $sJsFile;
}
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 <b>" . dirname($realJsFile) . "</b> folder. Error ", E_USER_ERROR);
}
#require(dirname(__FILE__)."/xajax_compress.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 <b>" . dirname($realJsFile) . "</b> folder. Error ", E_USER_ERROR);
}
else {
fwrite($fH, $compressedScript);
fclose($fH);
}
}
}
function _detectURI() {
$aURL = array();
if (!empty($_SERVER['REQUEST_URI'])) {
$aURL = parse_url($_SERVER['REQUEST_URI']);
}
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_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'];
}
$sURL = $aURL['scheme'].'://';
if (!empty($aURL['user'])) {
$sURL.= $aURL['user'];
if (!empty($aURL['pass'])) {
$sURL.= ':'.$aURL['pass'];
}
$sURL.= '@';
}
$sURL.= $aURL['host'];
if (!empty($aURL['port']) && (($aURL['scheme'] == 'http' && $aURL['port'] != 80) || ($aURL['scheme'] == 'https' && $aURL['port'] != 443))) {
$sURL.= ':'.$aURL['port'];
}
if($aURL["query"])
{
$sURL.= $aURL['path'].$aURL['query'];
}
else
{
if($_SERVER["QUERY_STRING"])
{
$sURL .= $aURL['path']."?".$_SERVER["QUERY_STRING"];
}
}
unset($aURL);
return $sURL;
}
function _isObjectCallback($sFunction)
{
if (array_key_exists($sFunction, $this->aObjects)) return true;
return false;
}
function _isFunctionCallable($sFunction)
{
if ($this->_isObjectCallback($sFunction)) {
if (is_object($this->aObjects[$sFunction][0])) {
return method_exists($this->aObjects[$sFunction][0], $this->aObjects[$sFunction][1]);
}
else {
return is_callable($this->aObjects[$sFunction]);
}
}
else {
return function_exists($sFunction);
}
}
function _callFunction($sFunction, $aArgs)
{
if ($this->_isObjectCallback($sFunction)) {
$mReturn = call_user_func_array($this->aObjects[$sFunction], $aArgs);
}
else {
$mReturn = call_user_func_array($sFunction, $aArgs);
}
return $mReturn;
}
function _wrap($sFunction,$sRequestType=XAJAX_POST)
{
$js = "function ".$this->sWrapperPrefix."$sFunction(){return xajax.call(\"$sFunction\", arguments, ".$sRequestType.");}\n";
return $js;
}
function _xmlToArray($rootTag, $sXml)
{
$aArray = array();
$sXml = str_replace("<$rootTag>","<$rootTag>|~|",$sXml);
$sXml = str_replace("</$rootTag>","</$rootTag>|~|",$sXml);
$sXml = str_replace("<e>","<e>|~|",$sXml);
$sXml = str_replace("</e>","</e>|~|",$sXml);
$sXml = str_replace("<k>","<k>|~|",$sXml);
$sXml = str_replace("</k>","|~|</k>|~|",$sXml);
$sXml = str_replace("<v>","<v>|~|",$sXml);
$sXml = str_replace("</v>","|~|</v>|~|",$sXml);
$sXml = str_replace("<q>","<q>|~|",$sXml);
$sXml = str_replace("</q>","|~|</q>|~|",$sXml);
$this->aObjArray = explode("|~|",$sXml);
$this->iPos = 0;
$aArray = $this->_parseObjXml($rootTag);
return $aArray;
}
function _parseObjXml($rootTag)
{
$aArray = array();
if ($rootTag == "xjxobj")
{
while(!stristr($this->aObjArray[$this->iPos],"</xjxobj>"))
{
$this->iPos++;
if(stristr($this->aObjArray[$this->iPos],"<e>"))
{
$key = "";
$value = null;
$this->iPos++;
while(!stristr($this->aObjArray[$this->iPos],"</e>"))
{
if(stristr($this->aObjArray[$this->iPos],"<k>"))
{
$this->iPos++;
while(!stristr($this->aObjArray[$this->iPos],"</k>"))
{
$key .= $this->aObjArray[$this->iPos];
$this->iPos++;
}
}
if(stristr($this->aObjArray[$this->iPos],"<v>"))
{
$this->iPos++;
while(!stristr($this->aObjArray[$this->iPos],"</v>"))
{
if(stristr($this->aObjArray[$this->iPos],"<xjxobj>"))
{
$value = $this->_parseObjXml("xjxobj");
$this->iPos++;
}
else
{
$value .= $this->aObjArray[$this->iPos];
if ($this->bDecodeUTF8Input)
{
$value = $this->_decodeUTF8Data($value);
}
}
$this->iPos++;
}
}
$this->iPos++;
}
$aArray[$key]=$value;
}
}
}
if ($rootTag == "xjxquery")
{
$sQuery = "";
$this->iPos++;
while(!stristr($this->aObjArray[$this->iPos],"</xjxquery>"))
{
if (stristr($this->aObjArray[$this->iPos],"<q>") || stristr($this->aObjArray[$this->iPos],"</q>"))
{
$this->iPos++;
continue;
}
$sQuery .= $this->aObjArray[$this->iPos];
$this->iPos++;
}
parse_str($sQuery, $aArray);
if ($this->bDecodeUTF8Input)
{
foreach($aArray as $key => $value)
{
$aArray[$key] = $this->_decodeUTF8Data($value);
}
}
if (get_magic_quotes_gpc() == 1) {
$newArray = array();
foreach ($aArray as $sKey => $sValue) {
if (is_string($sValue))
$newArray[$sKey] = stripslashes($sValue);
else
$newArray[$sKey] = $sValue;
}
$aArray = $newArray;
}
}
return $aArray;
}
function _decodeUTF8Data($sData)
{
$sValue = $sData;
if ($this->bDecodeUTF8Input)
{
$sFuncToUse = NULL;
if (function_exists('iconv'))
{
$sFuncToUse = "iconv";
}
else if (function_exists('mb_convert_encoding'))
{
$sFuncToUse = "mb_convert_encoding";
}
if ($sFuncToUse)
{
if (is_string($sValue))
{
if ($sFuncToUse == "iconv")
{
$sValue = iconv("UTF-8", $this->sEncoding.'//TRANSLIT', $sValue);
}
else if ($sFuncToUse == "mb_convert_encoding")
{
$sValue = mb_convert_encoding($sValue, $this->sEncoding, "UTF-8");
}
}
}
}
return $sValue;
}
}
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 ($errno == E_STRICT) {
return;
}
else {
$errTypeStr = "UNKNOWN: $errno";
}
$GLOBALS['xajaxErrorHandlerText'] .= "\n----\n[$errTypeStr] $errstr\nerror in line $errline of file $errfile";
}
function xajaxCompressJavascript($sJS)
{
$sJS = str_replace("\r","",$sJS);
$literal_strings = array();
$lines = explode("\n",$sJS);
$clean = "";
$inComment = false;
$literal = "";
$inQuote = false;
$escaped = false;
$quoteChar = "";
for($i=0;$i<count($lines);$i++)
{
$line = $lines[$i];
$inNormalComment = false;
for($j=0;$j<strlen($line);$j++)
{
$c = substr($line,$j,1);
$d = substr($line,$j,2);
if(!$inQuote && !$inComment)
{
if(($c=="\"" || $c=="'") && !$inComment && !$inNormalComment)
{
$inQuote = true;
$inComment = false;
$escaped = false;
$quoteChar = $c;
$literal = $c;
}
else if($d=="/*" && !$inNormalComment)
{
$inQuote = false;
$inComment = true;
$escaped = false;
$quoteChar = $d;
$literal = $d;
$j++;
}
else if($d=="//")
{
$inNormalComment = true;
$clean .= $c;
}
else
{
$clean .= $c;
}
}
else
{
if($c == $quoteChar && !$escaped && !$inComment)
{
$inQuote = false;
$literal .= $c;
$clean .= "___" . count($literal_strings) . "___";
array_push($literal_strings,$literal);
}
else if($inComment && $d=="*/")
{
$inComment = false;
$literal .= $d;
$clean .= "___" . count($literal_strings) . "___";
array_push($literal_strings,$literal);
$j++;
}
else if($c == "\\" && !$escaped)
$escaped = true;
else
$escaped = false;
$literal .= $c;
}
}
if($inComment) $literal .= "\n";
$clean .= "\n";
}
$lines = explode("\n",$clean);
for($i=0;$i<count($lines);$i++)
{
$line = $lines[$i];
$line = preg_replace("/\/\/(.*)/","",$line);
$line = trim($line);
$line = preg_replace("/\s+/"," ",$line);
$line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/","\\1",$line);
$lines[$i] = $line;
}
$sJS = implode("\n",$lines);
$sJS = preg_replace("/[\n]+/","\n",$sJS);
$sJS = preg_replace("/;\n/",";",$sJS);
$sJS = preg_replace("/[\n]*\{[\n]*/","{",$sJS);
for($i=0;$i<count($literal_strings);$i++)
$sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);
return $sJS;
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -