3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2016 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
13 if (!defined('_ECRIRE_INC_VERSION')) return;
16 * Evaluer la page produite par un squelette
18 * Évalue une page pour la transformer en texte statique
19 * Elle peut contenir un < ?xml a securiser avant eval
20 * ou du php d'origine inconnue
22 * Attention cette partie eval() doit impérativement
23 * être déclenchée dans l'espace des globales (donc pas
31 // Cas d'une page contenant du PHP :
32 if ($page['process_ins'] != 'html') {
35 * Teste si on a déjà évalué du PHP
37 * Inclure inc/lang la première fois pour définir spip_lang
38 * si ça n'a pas encore été fait.
40 if (!defined('_EVALUER_PAGE_PHP')) {
41 define('_EVALUER_PAGE_PHP', true);
42 include_spip('inc/lang');
45 // restaurer l'etat des notes avant calcul
46 if (isset($page['notes'])
48 AND $notes = charger_fonction("notes","inc",true)){
49 $notes($page['notes'],'restaurer_etat');
52 if (strpos($page['texte'],'?xml')!==false)
53 $page['texte'] = str_replace('<'.'?xml', "<\1?xml", $page['texte']);
56 $res = eval('?' . '>' . $page['texte']);
57 // error catching 5.2<=PHP<7
59 and function_exists('error_get_last')
60 and ($erreur = error_get_last()) ) {
61 $code = $page['texte'];
62 $GLOBALS['numero_ligne_php'] = 1;
63 if (!function_exists('numerote_ligne_php')){
64 function numerote_ligne_php($match){
65 $GLOBALS['numero_ligne_php']++
;
66 return "\n/*".str_pad($GLOBALS['numero_ligne_php'],3,"0",STR_PAD_LEFT
)."*/";
69 $code = "/*001*/".preg_replace_callback(",\n,","numerote_ligne_php",$code);
70 $code = trim(highlight_string($code,true));
71 erreur_squelette("L".$erreur['line'].": ".$erreur['message']."<br />".$code,array($page['source'],'',$erreur['file'],'',$GLOBALS['spip_lang']));
72 $page['texte'] = "<!-- Erreur -->";
75 $page['texte'] = ob_get_contents();
79 $code = $page['texte'];
80 $GLOBALS['numero_ligne_php'] = 1;
81 if (!function_exists('numerote_ligne_php')){
82 function numerote_ligne_php($match){
83 $GLOBALS['numero_ligne_php']++
;
84 return "\n/*".str_pad($GLOBALS['numero_ligne_php'],3,"0",STR_PAD_LEFT
)."*/";
87 $code = "/*001*/".preg_replace_callback(",\n,","numerote_ligne_php",$code);
88 $code = trim(highlight_string($code,true));
89 erreur_squelette("L".$e->getLine().": ".$e->getMessage()."<br />".$code,array($page['source'],'',$e->getFile(),'',$GLOBALS['spip_lang']));
90 $page['texte'] = "<!-- Erreur -->";
94 $page['process_ins'] = 'html';
96 if (strpos($page['texte'],'?xml')!==false)
97 $page['texte'] = str_replace("<\1?xml", '<'.'?xml', $page['texte']);
100 page_base_href($page['texte']);