methods = get_class_methods( $this ); } public static function getInstance( $api ) { if ( self::$instance == null ) { self::$instance = new ajax_xajax(); self::$api = $api; self::setConfig(); } return self::$instance; } private function setConfig() { require_once( self::$api->vars['root_path'] . 'lib/kernel/xajax/xajax_core/xajax.inc.php' ); self::$engine = new xajax(); self::$response = self::$engine->getGlobalResponse(); self::$engine->setCharEncoding('utf-8'); self::$engine->setFlag('waitCursor',true); self::$engine->setFlag('decodeUTF8Input',true); //self::$engine->setFlag('debug',true); self::$engine->setWrapperPrefix( '' ); //self::$engine->configure('deferScriptGeneration', true); } /** * Calls ajax function of its own, or of the used framework * awaits an undefined number of values */ private function __call( $sMethod, $aArgs ) { if ( in_array( $sMethod, $this->methods ) ) { $aFunction = array( $this, $sMethod); } else { $aFunction = array(self::$response, $sMethod); } call_user_func_array($aFunction, $aArgs); } /** * Register all ajax functions of an entire class * * @param mixed $class */ public function registerClassMethods( $class ) { $methods = get_class_methods( get_class( $class ) ); foreach ( $methods as $method ) { if ( preg_match( "/^ajax_/", $method) ) { if ( !$this->registered[ $method ] ) { self::$engine->registerFunction(array($method, $class, $method)); $this->registered[ $method ] = true; } } } } /** * Register one ajax function * * @param string $name */ public function registerSimpleFunction( $name ) { self::$engine->registerFunction($name); } public function getJavascript() { self::$engine->processRequest(); return self::$engine->getJavascript( self::$api->vars['root_uri'] . 'lib/kernel/xajax/'); } public function returnResponse() { return self::$response; } public function addWidget( $content ) { $content = preg_replace( "/\\n/", '\\n', $content ); $content = preg_replace( "/\\r/", '\\r', $content ); $content = preg_replace( "/\\t/", '\\t', $content ); $content = utf8_encode( $content ); $content = addslashes( $content ); self::script("addWidget( '{$content}' )"); return self::returnResponse(); } public function alert( $aArgs ) { if ( is_array( $aArgs ) or is_object( $aArgs ) ) { $aArgs = print_r( $aArgs, true ); } self::$response->alert( $aArgs ); } } ?>