Merge remote branch 'origin/core/1.1.1/maint' into core/master
[platal.git] / include / platal.inc.php
index b9e42fd..a638d0d 100644 (file)
@@ -65,6 +65,7 @@ function pl_core_include($file)
 
 function pl_error_handler($errno, $errstr, $errfile, $errline)
 {
+
     static $errortype;
     if (!error_reporting())
         return;
@@ -93,23 +94,17 @@ function pl_error_handler($errno, $errstr, $errfile, $errline)
             return;
         }
     }
-
     $type = isset($errortype[$errno]) ? $errortype[$errno] : $errno;
-    $errstr = utf8_encode(htmlentities($errstr));
-    if (php_sapi_name() == 'cli') {
-        $GLOBALS['pl_errors'] = "$type: $errstr\n  $errfile:$errline\n";
-    } else {
-        $GLOBALS['pl_errors'][] =
-            "<div class='phperror'>".
-            "<strong>{$type}</strong> <em>$errstr</em><br />".
-            "<tt>$errfile : $errline</tt>".
-            "</div>";
-    }
-}
+    $error = strpos($type, 'Warning') !== false || strpos($type, 'Error') !==false;
 
-function pl_clear_errors()
-{
-    unset($GLOBALS['pl_errors']);
+    pl_autoload('PlBacktrace');
+    if (!isset(PlBacktrace::$bt['PHP Errors'])) {
+        new PlBacktrace('PHP Errors');
+    }
+    PlBacktrace::$bt['PHP Errors']->newEvent("$type: $errstr",
+                                             0, $error ? $errstr : null,
+                                             array(array('file' => $errfile,
+                                                         'line' => $errline)));
 }
 
 function pl_dump_env()
@@ -122,15 +117,27 @@ function pl_dump_env()
     echo "</pre></div>";
 }
 
-function pl_print_errors()
+function pl_print_errors($html = false)
 {
-    if (!empty($GLOBALS['pl_errors'])) {
-        print join("\n", $GLOBALS['pl_errors']);
+    if (!isset(PlBacktrace::$bt['PHP Errors'])) {
+        return;
+    }
+    foreach (PlBacktrace::$bt['PHP Errors']->traces as $trace) {
+        if ($html) {
+            echo "<pre>";
+        }
+        print "{$trace['action']}\n";
+        print "  {$trace['data'][0]['file']}: {$trace['data'][0]['line']}\n";
+        if ($html) {
+            echo "</pre>";
+        }
     }
 }
 
 set_error_handler('pl_error_handler', E_ALL | E_STRICT);
-register_shutdown_function('pl_print_errors');
+if (php_sapi_name() == 'cli') {
+    register_shutdown_function('pl_print_errors');
+}
 //register_shutdown_function('pl_dump_env');
 
 /** Check if the string is utf8
@@ -155,9 +162,6 @@ function pl_url($path, $query = null, $fragment = null)
 {
     global $platal;
 
-    if (Env::has('__embedded')) {
-        $path = 'embedded/' . Env::s('__embedded') . '/' . $path;
-    }
     $base = $platal->ns . $path . ($query ? '?'.$query : '');
     return $fragment ? $base.'#'.$fragment : $base;
 }