mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-03 12:39:25 +01:00
exception handler for xajax and ability to use static methods as ajax callbacks eg. filemanager_ui::ajax_check_something
This commit is contained in:
parent
241e844f4b
commit
b40382df80
@ -1424,4 +1424,7 @@ function egw_exception_handler(Exception $e)
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
set_exception_handler('egw_exception_handler');
|
if (!isset($GLOBALS['egw_info']['flags']['no_exception_handler']) || !$GLOBALS['egw_info']['flags']['no_exception_handler'])
|
||||||
|
{
|
||||||
|
set_exception_handler('egw_exception_handler');
|
||||||
|
}
|
||||||
|
39
xajax.php
39
xajax.php
@ -33,6 +33,29 @@
|
|||||||
$GLOBALS['egw']->common->egw_exit();
|
$GLOBALS['egw']->common->egw_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception handler for xajax, return the message (and trace) as alert() to the user
|
||||||
|
*
|
||||||
|
* Does NOT return!
|
||||||
|
*
|
||||||
|
* @param Exception $e
|
||||||
|
*/
|
||||||
|
function ajax_exception_handler(Exception $e)
|
||||||
|
{
|
||||||
|
$response =& new xajaxResponse();
|
||||||
|
$response->addAlert($e->getMessage()."\n\n".$e->getTraceAsString());
|
||||||
|
header('Content-type: text/xml; charset='.(is_object($GLOBALS['egw'])?$GLOBALS['egw']->translation->charset():'utf-8'));
|
||||||
|
echo $response->getXML();
|
||||||
|
if (is_object($GLOBALS['egw']))
|
||||||
|
{
|
||||||
|
$GLOBALS['egw']->common->egw_exit();
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set our own exception handler, to not get the html from eGW's default one
|
||||||
|
set_exception_handler('ajax_exception_handler');
|
||||||
|
|
||||||
function doXMLHTTP()
|
function doXMLHTTP()
|
||||||
{
|
{
|
||||||
$numargs = func_num_args();
|
$numargs = func_num_args();
|
||||||
@ -55,7 +78,16 @@
|
|||||||
}
|
}
|
||||||
//error_log("xajax_doXMLHTTP('$arg0',...)");
|
//error_log("xajax_doXMLHTTP('$arg0',...)");
|
||||||
|
|
||||||
@list($appName, $className, $functionName, $handler) = explode('.',$arg0);
|
if (strpos($arg0,'::') !== false && strpos($arg0,'.') === false) // static method name app_something::method
|
||||||
|
{
|
||||||
|
list($className,$functionName,$handler) = explode('::',$arg0);
|
||||||
|
list($appName) = explode('_',$className);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
@list($appName, $className, $functionName, $handler) = explode('.',$arg0);
|
||||||
|
}
|
||||||
|
error_log("xajax.php: appName=$appName, className=$className, functionName=$functionName, handler=$handler");
|
||||||
|
|
||||||
$GLOBALS['egw_info'] = array(
|
$GLOBALS['egw_info'] = array(
|
||||||
'flags' => array(
|
'flags' => array(
|
||||||
@ -63,6 +95,7 @@
|
|||||||
'noheader' => True,
|
'noheader' => True,
|
||||||
'disable_Template_class' => True,
|
'disable_Template_class' => True,
|
||||||
'autocreate_session_callback' => 'xajax_redirect',
|
'autocreate_session_callback' => 'xajax_redirect',
|
||||||
|
'no_exception_handler' => true, // we already installed our own
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
include('./header.inc.php');
|
include('./header.inc.php');
|
||||||
@ -93,10 +126,12 @@
|
|||||||
}
|
}
|
||||||
if(substr($className,0,4) != 'ajax' && substr($className,-4) != 'ajax' &&
|
if(substr($className,0,4) != 'ajax' && substr($className,-4) != 'ajax' &&
|
||||||
$arg0 != 'etemplate.etemplate.process_exec' && substr($functionName,0,4) != 'ajax' ||
|
$arg0 != 'etemplate.etemplate.process_exec' && substr($functionName,0,4) != 'ajax' ||
|
||||||
!preg_match('/^[A-Za-z0-9_]+\.[A-Za-z0-9_]+\.[A-Za-z0-9_]+$/',$arg0))
|
!preg_match('/^[A-Za-z0-9_]+(\.[A-Za-z0-9_]+\.|::)[A-Za-z0-9_]+$/',$arg0))
|
||||||
{
|
{
|
||||||
// stopped for security reasons
|
// stopped for security reasons
|
||||||
error_log($_SERVER['PHP_SELF']. ' stopped for security reason. '.$arg0.' is not valid. class- or function-name must start with ajax!!!');
|
error_log($_SERVER['PHP_SELF']. ' stopped for security reason. '.$arg0.' is not valid. class- or function-name must start with ajax!!!');
|
||||||
|
// send message also to the user
|
||||||
|
throw new Exception($_SERVER['PHP_SELF']. ' stopped for security reason. '.$arg0.' is not valid. class- or function-name must start with ajax!!!');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
$ajaxClass =& CreateObject($appName.'.'.$className);
|
$ajaxClass =& CreateObject($appName.'.'.$className);
|
||||||
|
Loading…
Reference in New Issue
Block a user