📄 ajax.php
字号:
$_GET['m'] = $_REQUEST['Iframe_XHR_method']; } if (isset($_REQUEST['Iframe_XHR_class'])) { $_GET['c'] = $_REQUEST['Iframe_XHR_class']; } } } /** * Handle a ajax request if needed * * The current check is if GET variables c (class) and m (method) are set, * more options may be available in the future * * @return boolean true if an ajax call was handled, false otherwise */ function handleRequest() { set_error_handler(array(&$this,'_errorHandler')); if (function_exists('set_exception_handler')) { set_exception_handler(array(&$this,'_exceptionHandler')); } if (isset($_GET['px'])) { if ($this->_iframeGrabProxy()) { restore_error_handler(); if (function_exists('restore_exception_handler')) { restore_exception_handler(); } return true; } } $class = strtolower($this->_getVar('c')); $method = $this->_getVar('m'); $phpCallback = $this->_getVar('cb'); if (!empty($class) && !empty($method)) { if (!isset($this->_exportedInstances[$class])) { // handle error trigger_error('Unknown class: '. $class); } if (!in_array(($this->php4CompatCase ? strtolower($method) : $method), $this->_exportedInstances[$class]['exportedMethods'])) { // handle error trigger_error('Unknown method: ' . $method); } } else if (!empty($phpCallback)) { if (strpos($phpCallback, '.') !== false) { $phpCallback = explode('.', $phpCallback); } if (!$this->_validatePhpCallback($phpCallback)) { restore_error_handler(); if (function_exists('restore_exception_handler')) { restore_exception_handler(); } return false; } } else { restore_error_handler(); if (function_exists('restore_exception_handler')) { restore_exception_handler(); } return false; } // auto-detect serializer to use from content-type $type = $this->unserializer; $key = array_search($this->_getClientPayloadContentType(), $this->contentTypeMap); if ($key) { $type = $key; } $unserializer = $this->_getSerializer($type); $args = $unserializer->unserialize($this->_getClientPayload(), $this->_allowedClasses); if (!is_array($args)) { $args = array($args); } if ($this->_interceptor !== false) { $args = $this->_processInterceptor($class, $method, $phpCallback, $args); } if (empty($phpCallback)) { $ret = call_user_func_array(array(&$this->_exportedInstances[$class]['instance'], $method), $args); } else { $ret = call_user_func_array($phpCallback, $args); } restore_error_handler(); $this->_sendResponse($ret); return true; } /** * Determines the content type of the client payload * * @return string * a MIME content type */ function _getClientPayloadContentType() { //OPERA IS STUPID FIX if (isset($_SERVER['HTTP_X_CONTENT_TYPE'])) { $type = $this->_getServer('HTTP_X_CONTENT_TYPE'); $pos = strpos($type, ';'); return strtolower($pos ? substr($type, 0, $pos) : $type); } else if (isset($_SERVER['CONTENT_TYPE'])) { $type = $this->_getServer('CONTENT_TYPE'); $pos = strpos($type, ';'); return strtolower($pos ? substr($type, 0, $pos) : $type); } return 'text/plain'; } /** * Send a reponse adding needed headers and serializing content * * Note: this method echo's output as well as setting headers to prevent caching * Iframe Detection: if this has been detected as an iframe response, it has to * be wrapped in different code and headers changed (quite a mess) * * @param mixed $response content to serialize and send * * @access private * @return void */ function _sendResponse($response) { if (is_object($response) && is_a($response, 'HTML_AJAX_Response')) { $output = $response->getPayload(); $content = $response->getContentType(); } elseif (is_a($response, 'PEAR_Error')) { $serializer = $this->_getSerializer('Error'); $output = $serializer->serialize(array( 'message' => $response->getMessage(), 'userinfo' => $response->getUserInfo(), 'code' => $response->getCode(), 'mode' => $response->getMode() )); $content = $this->contentTypeMap['Error']; } else { $serializer = $this->_getSerializer($this->serializer); $output = $serializer->serialize($response); $serializerType = $this->serializer; // let a serializer change its output type if (isset($serializer->serializerNewType)) { $serializerType = $serializer->serializerNewType; } if (isset($this->contentTypeMap[$serializerType])) { $content = $this->contentTypeMap[$serializerType]; } } // headers to force things not to be cached: $headers = array(); //OPERA IS STUPID FIX if (isset($_SERVER['HTTP_X_CONTENT_TYPE'])) { $headers['X-Content-Type'] = $content; $content = 'text/plain'; } if ($this->_sendContentLength()) { $headers['Content-Length'] = strlen($output); } $headers['Expires'] = 'Mon, 26 Jul 1997 05:00:00 GMT'; $headers['Last-Modified'] = gmdate("D, d M Y H:i:s").'GMT'; $headers['Cache-Control'] = 'no-cache, must-revalidate'; $headers['Pragma'] = 'no-cache'; $headers['Content-Type'] = $content.'; charset=utf-8'; //intercept to wrap iframe return data if ($this->_iframe) { $output = $this->_iframeWrapper($this->_iframe, $output, $headers); $headers['Content-Type'] = 'text/html; charset=utf-8'; } $this->_sendHeaders($headers); echo $output; } /** * Decide if we should send a Content-length header * * @return bool true if it's ok to send the header, false otherwise * @access private */ function _sendContentLength() { if (!$this->sendContentLength) { return false; } $ini_tests = array( "output_handler", "zlib.output_compression", "zlib.output_handler"); foreach ($ini_tests as $test) { if (ini_get($test)) { return false; } } return (ob_get_level() <= 0); } /** * Actually send a list of headers * * @param array $array list of headers to send * * @access private * @return void */ function _sendHeaders($array) { foreach ($array as $header => $value) { header($header . ': ' . $value); } } /** * Get an instance of a serializer class * * @param string $type Last part of the class name * * @access private * @return HTML_AJAX_Serializer */ function _getSerializer($type) { if (isset($this->_serializers[$type])) { return $this->_serializers[$type]; } $class = 'HTML_AJAX_Serializer_'.$type; if ( (version_compare(phpversion(), 5, '>') && !class_exists($class, false)) || (version_compare(phpversion(), 5, '<') && !class_exists($class)) ) { // include the class only if it isn't defined include_once "HTML/AJAX/Serializer/{$type}.php"; } //handle JSON loose typing option for associative arrays if ($type == 'JSON') { $this->_serializers[$type] = new $class($this->jsonLooseType); } else { $this->_serializers[$type] = new $class(); } return $this->_serializers[$type]; } /** * Get payload in its submitted form, currently only supports raw post * * @access private * @return string raw post data */ function _getClientPayload() { if (empty($this->_payload)) { if (isset($GLOBALS['HTTP_RAW_POST_DATA'])) { $this->_payload = $GLOBALS['HTTP_RAW_POST_DATA']; } else if (function_exists('file_get_contents')) { // both file_get_contents() and php://input require PHP >= 4.3.0 $this->_payload = file_get_contents('php://input'); } else { $this->_payload = ''; } } return $this->_payload; } /** * stub for getting get vars - applies strip_tags * * @param string $var variable to get * * @access private * @return string filtered _GET value */ function _getVar($var) { if (!isset($_GET[$var])) { return null; } else { return strip_tags($_GET[$var]); } } /** * stub for getting server vars - applies strip_tags * * @param string $var variable to get * * @access private * @return string filtered _GET value */ function _getServer($var) { if (!isset($_SERVER[$var])) { return null; } else { return strip_tags($_SERVER[$var]); } } /** * Exception handler, passes them to _errorHandler to do the actual work * * @param Exception $ex Exception to be handled * * @access private * @return void */ function _exceptionHandler($ex) { $this->_errorHandler($ex->getCode(), $ex->getMessage(), $ex->getFile(), $ex->getLine()); } /** * Error handler that sends it errors to the client side * * @param int $errno Error number * @param string $errstr Error string * @param string $errfile Error file * @param string $errline Error line * * @access private * @return void */ function _errorHandler($errno, $errstr, $errfile, $errline) { if ($errno & error_reporting()) { $e = new stdClass(); $e->errNo = $errno; $e->errStr = $errstr; $e->errFile = $errfile; $e->errLine = $errline; $this->serializer = 'Error'; $this->_sendResponse($e); if ($this->debugEnabled) { $this->debug = new HTML_AJAX_Debug($errstr, $errline, $errno, $errfile); if ($this->debugSession) { $this->debug->sessionError(); } $this->debug->_saveError(); } die(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -