[SPIP] ~v3.0.20-->v3.0.25
[lhc/web/clavette_www.git] / www / ecrire / public / evaluer_page.php
index 85f5611..49c7090 100644 (file)
@@ -3,7 +3,7 @@
 /***************************************************************************\
  *  SPIP, Systeme de publication pour l'internet                           *
  *                                                                         *
- *  Copyright (c) 2001-2014                                                *
+ *  Copyright (c) 2001-2016                                                *
  *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
  *                                                                         *
  *  Ce programme est un logiciel libre distribue sous licence GNU/GPL.     *
@@ -52,8 +52,43 @@ if ($page['process_ins'] != 'html') {
        if (strpos($page['texte'],'?xml')!==false)
                $page['texte'] = str_replace('<'.'?xml', "<\1?xml", $page['texte']);
 
-       $res = eval('?' . '>' . $page['texte']);
-       $page['texte'] = ob_get_contents();
+       try {
+               $res = eval('?' . '>' . $page['texte']);
+               // error catching 5.2<=PHP<7
+               if ($res === false
+                 and function_exists('error_get_last')
+                 and ($erreur = error_get_last()) ) {
+                       $code = $page['texte'];
+                       $GLOBALS['numero_ligne_php'] = 1;
+                       if (!function_exists('numerote_ligne_php')){
+                               function numerote_ligne_php($match){
+                                       $GLOBALS['numero_ligne_php']++;
+                                       return "\n/*".str_pad($GLOBALS['numero_ligne_php'],3,"0",STR_PAD_LEFT)."*/";
+                               }
+                       }
+                       $code = "/*001*/".preg_replace_callback(",\n,","numerote_ligne_php",$code);
+                       $code = trim(highlight_string($code,true));
+                       erreur_squelette("L".$erreur['line'].": ".$erreur['message']."<br />".$code,array($page['source'],'',$erreur['file'],'',$GLOBALS['spip_lang']));
+                       $page['texte'] = "<!-- Erreur -->";
+               }
+               else {
+                       $page['texte'] = ob_get_contents();
+               }
+       }
+       catch (Exception $e){
+               $code = $page['texte'];
+               $GLOBALS['numero_ligne_php'] = 1;
+               if (!function_exists('numerote_ligne_php')){
+                       function numerote_ligne_php($match){
+                               $GLOBALS['numero_ligne_php']++;
+                               return "\n/*".str_pad($GLOBALS['numero_ligne_php'],3,"0",STR_PAD_LEFT)."*/";
+                       }
+               }
+               $code = "/*001*/".preg_replace_callback(",\n,","numerote_ligne_php",$code);
+               $code = trim(highlight_string($code,true));
+               erreur_squelette("L".$e->getLine().": ".$e->getMessage()."<br />".$code,array($page['source'],'',$e->getFile(),'',$GLOBALS['spip_lang']));
+               $page['texte'] = "<!-- Erreur -->";
+       }
        ob_end_clean();
 
        $page['process_ins'] = 'html';