1
0

JS error redirect handler function move

needed to find a global available function placement in case of recurring errors and set function call to window.top.fncname() to be seen in plain/iframed pages
This commit is contained in:
Ian
2014-01-05 14:05:16 +01:00
parent 86414d03c8
commit 7cf4c1251b
2 changed files with 24 additions and 19 deletions

View File

@ -99,7 +99,7 @@ if (!function_exists('errorToExceptionHandler')) {
if ($serendipity['production'] === 'debug') { if ($serendipity['production'] === 'debug') {
// We don't want the notices - but everything else ! // We don't want the notices - but everything else !
echo '<p> == FULL DEBUG ERROR MODE == </p>'; echo ' == FULL DEBUG ERROR MODE == ';
echo '<pre>'; echo '<pre>';
// trying to be as detailled as possible - but beware using args containing sensibel data like passwords // trying to be as detailled as possible - but beware using args containing sensibel data like passwords
if (function_exists('debug_backtrace') && version_compare(PHP_VERSION, '5.3.6') >= 0) { if (function_exists('debug_backtrace') && version_compare(PHP_VERSION, '5.3.6') >= 0) {
@ -122,7 +122,7 @@ if (!function_exists('errorToExceptionHandler')) {
exit; // make sure to exit in case of database connection errors. exit; // make sure to exit in case of database connection errors.
} }
if ($serendipity['production'] === false) { if ($serendipity['production'] === false) {
echo '<p> == TESTING ERROR MODE == </p>'; echo ' == TESTING ERROR MODE == ';
echo '<pre>'; echo '<pre>';
// see notes above // see notes above
if (!$serendipity['dbConn'] || version_compare(PHP_VERSION, '5.3', '<')) { if (!$serendipity['dbConn'] || version_compare(PHP_VERSION, '5.3', '<')) {
@ -136,29 +136,20 @@ if (!function_exists('errorToExceptionHandler')) {
if ($serendipity['production'] === true) { if ($serendipity['production'] === true) {
if( $serendipity['serendipityUserlevel'] >= USERLEVEL_ADMIN ) { if( $serendipity['serendipityUserlevel'] >= USERLEVEL_ADMIN ) {
// ToDo: enhance for more special serendipity error needs // ToDo: enhance for more special serendipity error needs
$str = '<p> == SERENDIPITY ERROR == </p>'; $str = " == SERENDIPITY ERROR == ";
$str .= '<p>Please correct:</p>';
$str .= '<p>' . $errStr . ' in ' . $errFile . ' on line ' . $errLine . '</p>'; $str .= '<p>' . $errStr . ' in ' . $errFile . ' on line ' . $errLine . '</p>';
#var_dump(headers_list()); #var_dump(headers_list());
if (headers_sent()) { if (headers_sent()) {
serendipity_die($str); // case HTTP headers: needs to halt with die() here, else it will path through and gets written underneath blog content, which hardly isn't seen by many users serendipity_die($str); // case HTTP headers: needs to halt with die() here, else it will path through and gets written underneath blog content, which hardly isn't seen by many users
} else { } else {
// this also reacts on non eye-displayed errors with following small javascript, while being in tags like <select> to push on top of page, else return non javascript use $str just there // see global include of function in plugin_api.inc.php
echo '<noscript>' . $str . '</noscript>' . "\n<script>" . ' // this also reacts on non eye-displayed errors with following small javascript,
function create(htmlStr) { // while being in tags like <select> to push on top of page, else return non javascript use $str just there
var frag = document.createDocumentFragment(), // sadly we can not use HEREDOC notation here, since this does not execute the javascript after finished writing
temp = document.createElement("div"); echo "\n".'<script>
temp.innerHTML = htmlStr; var fragment = window.top.create("Error redirect: '.addslashes($str).'");
while (temp.firstChild) {
frag.appendChild(temp.firstChild);
}
return frag;
}
var fragment = create("Error redirect: '.addslashes($str).'");
// You can use native DOM methods to insert the fragment:
document.body.insertBefore(fragment, document.body.childNodes[0]); document.body.insertBefore(fragment, document.body.childNodes[0]);
' . "\n</script>\n"; ' . "\n</script>\n<noscript>" . $str . "</noscript>\n";
// sadly we can't use HEREDOC notation here as this does not execute the javascript after finished writing
} }
} }
} }

View File

@ -42,6 +42,20 @@ function serendipity_plugin_api_frontend_header($event_name, &$bag, &$eventData,
</script> </script>
<?php <?php
} }
// add a global available (index.tpl; admin/index.tpl; preview_iframe.tpl) redirect error string function used by errorToExceptionHandler()
?>
<script type="text/javascript">
function create(htmlStr) {
var frag = document.createDocumentFragment(),
temp = document.createElement("div");
temp.innerHTML = htmlStr;
while (temp.firstChild) {
frag.appendChild(temp.firstChild);
}
return frag;
}
</script>
<?php
} }