Commit | Line | Data |
---|---|---|
c495c100 P |
1 | <?php |
2 | ||
3 | /***************************************************************************\ | |
4 | * SPIP, Systeme de publication pour l'internet * | |
5 | * * | |
6 | * Copyright (c) 2001-2007 * | |
7 | * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * | |
8 | * * | |
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 | \***************************************************************************/ | |
12 | ||
13 | if (!isset($GLOBALS['_INC_PUBLIC'])) $GLOBALS['_INC_PUBLIC'] = 0; | |
14 | ||
15 | // Distinguer une inclusion d'un appel initial | |
16 | if ($GLOBALS['_INC_PUBLIC']>0) { | |
17 | $GLOBALS['_INC_PUBLIC']++; | |
18 | ||
19 | // $fond passe par INCLURE(){fond=...} | |
20 | if (isset($contexte_inclus['fond'])) | |
21 | $fond = $contexte_inclus['fond']; | |
22 | $subpage = inclure_page($fond, $contexte_inclus); | |
23 | ||
24 | if ($subpage['process_ins'] == 'html') | |
25 | echo $subpage['texte']; | |
26 | else | |
27 | eval('?' . '>' . $subpage['texte']); | |
28 | ||
29 | if ($subpage['lang_select'] === true) | |
30 | lang_dselect(); | |
31 | ||
32 | } else { | |
33 | $GLOBALS['_INC_PUBLIC']++; | |
34 | ||
35 | // | |
36 | // Discriminer les appels | |
37 | // | |
38 | ||
39 | // Faut-il initialiser SPIP ? (oui dans le cas general) | |
40 | if (!defined('_DIR_RESTREINT_ABS')) | |
41 | if (defined('_DIR_RESTREINT') | |
42 | AND @file_exists(_DIR_RESTREINT.'inc_version.php')) { | |
43 | include_once _DIR_RESTREINT.'inc_version.php'; | |
44 | } | |
45 | else | |
46 | die('stupid death...'); | |
47 | ||
48 | ||
49 | // Est-ce une action ? | |
50 | if ($action = _request('action')) { | |
51 | include_spip('inc/autoriser'); // chargement systematique pour les actions | |
52 | include_spip('inc/headers'); | |
53 | $var_f = charger_fonction($action, 'action'); | |
54 | $var_f(); | |
55 | if (isset($redirect) && $redirect) redirige_par_entete(urldecode($redirect)); | |
56 | exit; | |
57 | } | |
58 | ||
59 | // cas normal, $fond defini dans le fichier d'appel | |
60 | // note : securise anti-injection par inc/utils.php | |
61 | else if (isset($fond)) { } | |
62 | ||
63 | // page=xxxx demandee par l'url | |
64 | else if (isset($_GET['page'])) { | |
65 | $fond = $_GET['page']; | |
66 | // Securite | |
67 | if (strstr($fond, '/')) { | |
68 | include_spip('inc/minipres'); | |
69 | echo minipres(); | |
70 | exit; | |
71 | } | |
72 | ||
73 | # par defaut | |
74 | } else { | |
75 | // traiter le cas pathologique d'un upload de document ayant echoue | |
76 | // car trop gros | |
77 | if (empty($_GET) AND empty($_POST) AND empty($_FILES) | |
78 | AND strlen($_SERVER["CONTENT_LENGTH"]) >= 7 | |
79 | AND strstr($_SERVER["CONTENT_TYPE"], "multipart/form-data;")) { | |
80 | include_spip('inc/getdocument'); | |
81 | erreur_upload_trop_gros(); | |
82 | } | |
83 | ||
84 | // mais plus probablement nous sommes dans le cas | |
85 | $fond = 'sommaire'; | |
86 | } | |
87 | ||
88 | // Particularites de certains squelettes | |
89 | if ($fond == 'login') | |
90 | $forcer_lang = true; | |
91 | ||
92 | ||
93 | // | |
94 | // Aller chercher la page | |
95 | // | |
96 | ||
97 | $tableau_des_erreurs = array(); | |
98 | $assembler = charger_fonction('assembler', 'public'); | |
99 | $page = $assembler($fond); | |
100 | ||
101 | if (isset($page['status'])) { | |
102 | include_spip('inc/headers'); | |
103 | http_status($page['status']); | |
104 | } | |
105 | ||
106 | // Content-Type ? | |
107 | if (!isset($page['entetes']['Content-Type'])) { | |
108 | $page['entetes']['Content-Type'] = | |
109 | "text/html; charset=" . $GLOBALS['meta']['charset']; | |
110 | $html = true; | |
111 | } else { | |
112 | $html = preg_match(',^\s*text/html,',$page['entetes']['Content-Type']); | |
113 | } | |
114 | ||
115 | if ($var_preview AND $html) { | |
116 | include_spip('inc/minipres'); | |
117 | $page['texte'] .= afficher_bouton_preview(); | |
118 | } | |
119 | ||
120 | // est-on admin ? | |
121 | if ($affiche_boutons_admin = ( | |
122 | isset($_COOKIE['spip_admin']) | |
123 | AND !$flag_preserver | |
124 | AND ($html OR ($var_mode == 'debug') OR count($tableau_des_erreurs)) | |
125 | AND !_request('var_fragment') | |
126 | )) | |
127 | include_spip('balise/formulaire_admin'); | |
128 | ||
129 | // Execution de la page calculee | |
130 | ||
131 | // decomptage des visites, on peut forcer a oui ou non avec le header X-Spip-Visites | |
132 | // par defaut on ne compte que les pages en html (ce qui exclue les js,css et flux rss) | |
133 | $spip_compter_visites = $html?'oui':'non'; | |
134 | if (isset($page['entetes']['X-Spip-Visites'])){ | |
135 | $spip_compter_visites = in_array($page['entetes']['X-Spip-Visites'],array('oui','non'))?$page['entetes']['X-Spip-Visites']:$spip_compter_visites; | |
136 | unset($page['entetes']['X-Spip-Visites']); | |
137 | } | |
138 | ||
139 | // mise en cache apache | |
140 | ||
141 | // 0. xml-hack | |
142 | if ($xml_hack = isset($page['entetes']['X-Xml-Hack'])) | |
143 | unset($page['entetes']['X-Xml-Hack']); | |
144 | ||
145 | // 1. Cas d'une page contenant uniquement du HTML : | |
146 | if ($page['process_ins'] == 'html') { | |
147 | foreach($page['entetes'] as $k => $v) @header("$k: $v"); | |
148 | } | |
149 | ||
150 | // 2. Cas d'une page contenant du PHP : | |
151 | // Attention cette partie eval() doit imperativement | |
152 | // etre declenchee dans l'espace des globales (donc pas | |
153 | // dans une fonction). | |
154 | else { | |
155 | // Si la retention du flux de sortie est impossible | |
156 | // envoi des entetes | |
157 | if (!$flag_ob) { | |
158 | foreach($page['entetes'] as $k => $v) @header("$k: $v"); | |
159 | ||
160 | // si un fragment est demande, on le provoque ici | |
161 | // (mais ca peut planter) | |
162 | if (($var_fragment=_request('var_fragment'))!==NULL) { | |
163 | preg_match(',<div id="'.preg_quote($var_fragment) | |
164 | .'" class="fragment">(.*)<!-- /'.preg_quote($var_fragment) | |
165 | .' --></div>,Uims', $page['texte'], $r); | |
166 | $page['texte'] = $r[1]; | |
167 | } | |
168 | ||
169 | eval('?' . '>' . $page['texte']); | |
170 | $page['texte'] = ''; | |
171 | } | |
172 | ||
173 | // sinon, inclure_balise_dynamique nous enverra peut-etre | |
174 | // quelques en-tetes de plus (voire qq envoyes directement) | |
175 | else { | |
176 | ob_start(); | |
177 | $res = eval('?' . '>' . $page['texte']); | |
178 | $page['texte'] = ob_get_contents(); | |
179 | ob_end_clean(); | |
180 | ||
181 | foreach($page['entetes'] as $k => $v) @header("$k: $v"); | |
182 | // en cas d'erreur lors du eval, | |
183 | // la memoriser dans le tableau des erreurs | |
184 | // On ne revient pas ici si le nb d'erreurs > 4 | |
185 | if ($res === false AND $affiche_boutons_admin | |
186 | AND $auteur_session['statut'] == '0minirezo') { | |
187 | include_spip('public/debug'); | |
188 | erreur_squelette(_T('zbug_erreur_execution_page')); | |
189 | } | |
190 | } | |
191 | } | |
192 | ||
193 | // Passer la main au debuggueur le cas echeant | |
194 | if ($var_mode == 'debug') { | |
195 | include_spip('public/debug'); | |
196 | debug_dumpfile($var_mode_affiche== 'validation' ? $page['texte'] :"", | |
197 | $var_mode_objet,$var_mode_affiche); | |
198 | } | |
199 | ||
200 | if (count($tableau_des_erreurs) AND $affiche_boutons_admin) | |
201 | $page['texte'] = affiche_erreurs_page($tableau_des_erreurs) | |
202 | . $page['texte']; | |
203 | ||
204 | // | |
205 | // Post-traitements et affichage final | |
206 | // | |
207 | ||
208 | // si un fragment est demande, l'isoler | |
209 | if (($var_fragment=_request('var_fragment'))!==NULL) { | |
210 | preg_match(',<div id="'.preg_quote($var_fragment) | |
211 | .'" class="fragment">(.*)<!-- /'.preg_quote($var_fragment) | |
212 | .' --></div>,Uims', $page['texte'], $r); | |
213 | $page['texte'] = $r[1]; | |
214 | } | |
215 | ||
216 | // Report du hack pour <?xml (cf. public/compiler.php) | |
217 | if ($xml_hack) | |
218 | $page['texte'] = str_replace("<\1?xml", '<'.'?xml', $page['texte']); | |
219 | ||
220 | // (c'est ici qu'on fait var_recherche, tidy, boutons d'admin, | |
221 | // cf. public/assembler.php) | |
222 | echo pipeline('affichage_final', $page['texte']); | |
223 | ||
224 | // Gestion des statistiques du site public | |
225 | if (($GLOBALS['meta']["activer_statistiques"] != "non") | |
226 | AND $spip_compter_visites!='non') { | |
227 | $stats = charger_fonction('stats', 'public'); | |
228 | $stats(); | |
229 | } | |
230 | ||
231 | // Effectuer une tache de fond ? | |
232 | // si #SPIP_CRON est present, on ne le tente que pour les navigateurs | |
233 | // en mode texte (par exemple), et seulement sur les pages web | |
234 | if ($html | |
235 | AND !strstr($page['texte'], '<!-- SPIP-CRON -->') | |
236 | AND !preg_match(',msie|mozilla|opera|konqueror,i', $_SERVER['HTTP_USER_AGENT'])) | |
237 | cron(); | |
238 | } | |
239 | ||
240 | ?> |