[ Index ] |
|
Code source de SPIP Agora 1.4 |
1 <?php 2 /***************************************************** 3 * This file is part of Agora, web based content management system. 4 * 5 * Agora is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; version 2 of the License. 8 * 9 * Agora is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details (file "COPYING"). 13 * 14 * Copyright © Arnaud Martin, Antoine Pitrou et Philippe Rivière. 15 * List of authors detailed in "copyright_fr.html" file. 16 * E-mail : agora@sig.premier-ministre.gouv.fr 17 * Web site : http://www.agora.gouv.fr 18 *****************************************************/ 19 /** 20 * @version $Id$ 21 */ 22 23 // die si le site n'est pas configuré 24 // TODO : ce n'est pas dommage de le faire a chaque fois ? 25 if (!file_exists(dirname(__FILE__)."/ecrire/include/bd/inc_config_metier.php")) { 26 $GLOBALS['db_ok'] = false; 27 include_once ("ecrire/inc_version.php"); 28 include_once ("ecrire/inc_presentation.php"); 29 install_debut_html(_T('info_travaux_titre')); 30 echo "<p>"._T('info_travaux_texte')."</p>"; 31 install_fin_html(); 32 exit; 33 } 34 35 include_once ("ecrire/inc_version.php"); // TODO : serait il possible de se passer de cet inclusion a cet endroit ? 36 //We use safehtml on $_POST and $_GET 37 //We can't call this before, because inc_version threat GET and POST GLOBAL 38 define('XML_HTMLSAX3', dirname(__FILE__). "/safehtml-1.3.7/classes/"); 39 require_once ('safehtml-1.3.7/classes/safehtml.php'); 40 41 function traiteSafeHtml (&$object) { 42 if (is_array($object)) 43 foreach ($object as $key => $value) { 44 traiteSafeHtml ($object[$key]); 45 } 46 else { 47 $safehtml = &new safehtml(); 48 $object = htmlentities($safehtml->parse($object)); 49 } 50 } 51 52 traiteSafeHtml ($_POST); 53 traiteSafeHtml ($_GET); 54 55 foreach ($_GET as $key => $value) 56 $GLOBALS[$key] = $value; 57 58 foreach ($_POST as $key => $value) 59 $GLOBALS[$key] = $value; 60 61 if (file_exists("mes_fonctions.php")) { 62 //include_local ("mes_fonctions.php"); 63 include_once ("mes_fonctions.php"); 64 } 65 else { 66 //include_local ("mes_fonctions-dist.php"); 67 include_once ("mes_fonctions-dist.php"); 68 } 69 70 //if ($INSECURE['fond'] || $INSECURE['delais']) exit; 71 72 // 73 // Authentification 74 // 75 //XXX spip_session hardcoded? 76 /********** Modification SPIP_COOKIE johnny.muller@ypok.com **********/ 77 if ($HTTP_COOKIE_VARS[$GLOBALS['cookie_prefix']. '_session']OR ($PHP_AUTH_USER AND !$ignore_auth_http)) { 78 //if ($HTTP_COOKIE_VARS['spip_session'] OR ($PHP_AUTH_USER AND !$ignore_auth_http)) { 79 /********** Fin modification SPIP_COOKIE johnny.muller@ypok.com **********/ 80 //include_ecrire ("inc_session.php"); 81 require_once ("ecrire/inc_connect.php"); 82 include_once ("ecrire/inc_session.php"); 83 verifier_visiteur(); 84 } 85 86 // On force le recalcul du cache de personnalisation 87 include_once ('ecrire/include/cacheHTML/inc_cacheHTML_factory.php'); 88 89 if ($recalcul_personnalisation == 'oui') { 90 $cacheHTML = &recuperer_instance_cacheHTML(null, null, null, null, true, $GLOBALS['auteur_session']['id_auteur']); 91 $cacheHTML->destroyCache(); 92 } 93 94 // 95 // Gestion du cache et calcul de la page 96 // 97 // Instanciation d'un cacheHTML object 98 $cacheHTML = &recuperer_instance_cacheHTML($fond, $GLOBALS['HTTP_GET_VARS'], $GLOBALS['HTTP_POST_VARS'], $delais, 99 $personnalisation, $GLOBALS['auteur_session']['id_auteur']); 100 unset ($personnalisation); 101 102 // On surcharge le délai par la méta correspondante avec un délai global 103 if (lire_meta('surcharge_delais_ok') == 'oui') { 104 $cacheHTML->setDelais(intval(lire_meta('surcharge_delais'))); 105 } 106 107 // On force l'utilisation du CACHE si la base de données est indisponible 108 if (!($use_cache = $cacheHTML->useCache())) { // bien forcé, il faut se connecter 109 include_once ("ecrire/inc_version.php"); 110 require_once ("ecrire/inc_connect.php"); 111 112 if ($INSECURE['fond'] || $INSECURE['delais']) 113 exit; // TODO : pas très explicite 114 if (!$GLOBALS['db_ok']) { 115 $cacheHTML->setUseCacheAbsolutely(true); 116 } 117 } 118 119 // 120 // Ajouter un forum 121 // 122 if ($ajout_forum) { // je dois verifier que je peux me connecter 123 require_once ("ecrire/inc_connect.php"); 124 if ($GLOBALS['db_ok']) { 125 include_local ("inc-forum.php"); 126 ajout_forum(); 127 } 128 } 129 130 $ecraser_cache = false; 131 132 //TODO A comprendre 133 $cache_supprimes = array(); 134 135 if (!($use_cache = $cacheHTML->useCache())) { 136 require_once ("ecrire/inc_connect.php"); // on va se connecter 137 $article_redirection = false; 138 $lastmodified = time(); 139 140 if ((!$GLOBALS['db_ok'])) { // ne pas se fatiguer 141 // Message d'erreur base de donnees 142 include_once ('ecrire/inc_presentation.php'); 143 install_debut_html (_T('info_travaux_titre')); 144 echo "<p>" . _T('titre_probleme_technique'). "</p>\n"; 145 install_fin_html(); 146 exit(); 147 } 148 149 // On définit les metas 150 //if (!defined("_ECRIRE_INC_META_CACHE")) { 151 //include_ecrire("inc_meta.php"); 152 // TODO : pas necessaire ici ... fait dans inc_version ! ;-) 153 // include_once ("ecrire/inc_meta.php"); // c pas une autre methode maintenant pour ecrire les metas ? 154 //} 155 156 // Gestion '=chapo' 157 // + ne pas cacher si l'URL d'un article est demande avant sa publication 158 // (une seule requete, deux usages) 159 if ($id_article = intval($id_article)) { 160 require_once (dirname(__FILE__). "/ecrire/include/bd/inc_article_factory.php"); 161 $articleMetier = &recuperer_instance_article(); 162 $loadLightWeightIfStatut = $articleMetier->loadLightWeightIfStatut($id_article, 'publie'); 163 if (PEAR::isError($loadLightWeightIfStatut)) { 164 die ($loadLightWeightIfStatut->getMessage()); 165 } 166 else { 167 if ($loadLightWeightIfStatut != -1) { 168 if (substr($articleMetier->getChapo(), 0, 1) == '=') { 169 $article_redirection = true; 170 include_once ('ecrire/inc_texte.php'); 171 172 $regs = array('', '', '', substr($articleMetier->getChapo(), 1)); 173 list(, $url) = extraire_lien($regs); 174 $url = addslashes($url); 175 $texte = "<" . "?php @header (\"Location: $url\"); ?" . ">"; 176 $calculer_cache = false; 177 spip_log ("redirection: $url"); 178 $cacheHTML->save($texte); 179 } 180 } 181 else { 182 $ecraser_cache = true; 183 } 184 } 185 } 186 /******* Ajout PREVIEW guillaume.grason@diplomatie.gouv.fr *******/ 187 if ($GLOBALS['preview'] == 'oui') { 188 $effacer_cache = true; 189 $ecraser_cache = true; 190 } 191 /******* Fin Ajout PREVIEW guillaume.grason@diplomatie.gouv.fr *******/ 192 193 if (!$article_redirection) { 194 //include_local ("inc-calcul.php"); 195 require_once ("inc-calcul.php"); 196 $timer_a = explode(" ", microtime()); 197 $page = calculer_page_globale($fond); 198 $timer_b = explode(" ", microtime()); 199 if ($page) { 200 $timer = ceil(1000 * ($timer_b[0] + $timer_b[1] - $timer_a[0] - $timer_a[1])); 201 $taille = ceil(strlen($page) / 1024); 202 spip_log 203 ("calcul ($timer ms): " . $cacheHTML->getGroupId(). "/" . $cacheHTML->getCacheName(). " ($taille ko, delai: $delais s)"); 204 $cacheHTML->save($page); 205 } 206 } 207 } 208 209 // TODO a faire surlignagne recherche 210 // 211 // si $var_recherche est positionnee, on met en rouge les mots cherches (php4 uniquement) 212 // 213 214 if ($var_recherche AND $flag_ob AND $flag_pcre AND !$flag_preserver AND !$mode_surligne) { 215 include_once ("ecrire/inc_surligne.php"); 216 $mode_surligne = 'auto'; 217 timeout(false, true, false); // no lock, action, no mysql 218 ob_start(); 219 } 220 else { 221 unset ($var_recherche); 222 unset ($mode_surligne); 223 } 224 225 // 226 // Inclusion du cache pour envoyer la page au client 227 // 228 229 // TODO : je ne suis pas sur que ce soit compatible avec la nvelle gestion du cache ? 230 //vrai si delai =0 231 if ($delais == 0) 232 $effacer_cache = true; 233 234 // ecraser le cache de l'article x s'il n'est pas publie 235 if ($effacer_cache && $ecraser_cache) 236 $effacer_cache = true; 237 238 // Envoyer les entetes 239 // TODO A comprendre ... 240 $headers_only = ($HTTP_SERVER_VARS['REQUEST_METHOD'] == 'HEAD'); 241 242 /******* Modification PREVIEW guillaume.grason@diplomatie.gouv.fr *******/ 243 if (!$effacer_cache && !$flag_dynamique && $recalcul != 'oui' && $preview != 'oui' && !$HTTP_COOKIE_VARS['spip_admin']) { 244 //if (!$effacer_cache && !$flag_dynamique && $recalcul != 'oui' && !$HTTP_COOKIE_VARS['spip_admin']) { 245 /******* Fin Modification PREVIEW guillaume.grason@diplomatie.gouv.fr *******/ 246 if ($lastmodified) 247 $headers_only |= http_last_modified($lastmodified, $lastmodified + $delais); 248 } 249 else { 250 @Header ("Expires: 0"); 251 @Header ("Cache-Control: no-cache,must-revalidate"); 252 @Header ("Pragma: no-cache"); 253 } 254 255 // TODO A comprendre ... 256 $flag_preserver |= $headers_only; // ne pas se fatiguer a envoyer des donnees 257 258 if (!$flag_preserver) { 259 @Header ("Content-Type: text/html; charset=" . lire_meta('charset')); 260 } 261 262 // Envoyer la page 263 if ($cacheHTML->cacheExist()) { 264 ob_start(); 265 266 //if (!$headers_only) $cacheHTML->includeCache(); 267 if (!$headers_only) 268 include ($cacheHTML->_container->_cacheHTMLFile); // TODO : faire un GET 269 if ($GLOBALS['auteur_session']['id_auteur'] && lire_meta('activer_derniere_page_vue') == 'oui') { 270 require_once ("ecrire/inc_connect.php"); 271 272 if ($GLOBALS['db_ok']) { 273 $flux = ob_get_contents(); 274 $debut = strpos($flux, '<title>'); 275 $fin = strpos($flux, '</title>'); 276 277 if ($debut !== false && $fin !== false) { 278 $titre = substr($flux, $debut + 7, $fin - $debut - 7); 279 } 280 else { 281 $titre = _T('page_sans_titre'); 282 } 283 284 require_once (dirname(__FILE__). "/ecrire/include/bd/inc_dernieres_visites_factory.php"); 285 $visites = &recuperer_instance_dernieres_visites(); 286 $visites->setIdPers($GLOBALS['auteur_session']['id_auteur']); 287 $visites->setUrl($_SERVER['REQUEST_URI']); 288 $visites->setTitre($titre); 289 $createOK = $visites->create(); 290 if (PEAR::isError($createOK)) { 291 die ("->" . $createOK->getMessage()); 292 } 293 } 294 295 ob_end_clean(); 296 ob_start(); 297 echo $flux; 298 } 299 } 300 else if (!$flag_preserver) { 301 // Message d'erreur base de donnees 302 //include_ecrire('inc_presentation.php'); 303 include_once ('ecrire/inc_presentation.php'); 304 install_debut_html (_T('info_travaux_titre')); 305 echo "<p>" . _T('titre_probleme_technique'). "</p>\n"; 306 install_fin_html(); 307 spip_log ('le fichier cache ' . $cache_inclus . ' correspondant a ' . $fond . ' n\'existe pas '); 308 } 309 else { 310 spip_log ('le fichier cache ' . $cache_inclus . ' correspondant a ' . $fond . ' n\'existe pas '); 311 } 312 313 // TODO a faire surlignagne recherch suite... 314 // suite et fin mots en rouge 315 if ($var_recherche) 316 fin_surligne($var_recherche, $mode_surligne); 317 318 // nettoie 319 if ($effacer_cache) 320 $cacheHTML->destroyCache(); 321 322 //TODO A comprendre 323 while (list(, $chemin_cache_supprime) = each($cache_supprimes)) 324 @unlink ($chemin_cache_supprime); 325 326 // 327 // Fonctionnalites administrateur (declenchees par le cookie admin, authentifie ou non) 328 // 329 330 if ($HTTP_COOKIE_VARS['spip_admin']AND !$flag_preserver AND !$flag_boutons_admin AND $GLOBALS['db_ok']) { 331 include ("inc-admin.php"); 332 afficher_boutons_admin(); 333 } 334 335 /******* Ajout PREVIEW guillaume.grason@diplomatie.gouv.fr *******/ 336 if ($GLOBALS['preview'] == 'oui') { 337 $previsualisation = _T('previsualisation'); 338 echo '<div style=" 339 display: block; 340 color: #eeeeee; 341 background-color: #111111; 342 padding-right: 5px; 343 padding-top: 2px; 344 padding-bottom: 5px; 345 font-size: 20px; 346 top: 0px; 347 left: 0px; 348 position: absolute; 349 "><img src="ecrire/img_pack/naviguer-site.gif" alt="'.$previsualisation.'" /> '.$previsualisation.'</div>'; 350 } 351 /******* Fin Ajout PREVIEW guillaume.grason@diplomatie.gouv.fr *******/ 352 353 // envoyer la page si possible 354 @flush(); 355 356 // --------------------------------------------------------------------------------------------- 357 // Taches de fond 358 359 if ($use_cache) { 360 // Gestion de l'embargo de données 361 // l'embargo est il configure ? 362 if (file_exists(dirname(__FILE__). '/ecrire/include/embargo/embargo.conf.php')) { 363 include dirname(__FILE__). '/ecrire/include/embargo/embargo.conf.php'; 364 } 365 if ((is_array($fonds))and (count($fonds) > 0)) { 366 include_once (dirname(__FILE__). '/ecrire/include/embargo/embargo.php'); 367 clearCache ($GLOBALS['embargo_squelettes']); 368 } 369 } 370 371 // Gestion des taches de fond 372 if (lire_meta('activer_tache_fond') != 'non') { 373 define("FRONT", true); 374 require_once (dirname(__FILE__). "/ecrire/cron/taches_fond.php"); 375 } 376 else { // Lancer l'indexation malgre tout 377 if (lire_meta('activer_moteur') == 'oui') { 378 require_once (dirname(__FILE__). "/ecrire/inc_index.php"); 379 alimenter_fichier_index (false); 380 } 381 } 382 383 // 384 // Gestion des statistiques du site public 385 // (a la fin pour ne pas forcer le $db_ok) 386 // 387 if ($GLOBALS['db_ok']) { 388 if (lire_meta("activer_statistiques") != "non") { 389 include_local ("inc-stats.php"); 390 ecrire_stats(); 391 } 392 } 393 394 // 395 // Inclusions de squelettes 396 // 397 function inclure_fichier ($fond, $delais, $contexte_inclus = array(), $personnalisation = false) { 398 //enrichissementContexteInclus(&$contexte_inclus); 399 // Instanciation d'un cacheHTML object 400 $cacheHTML = &recuperer_instance_cacheHTML($fond, $contexte_inclus, $GLOBALS['HTTP_POST_VARS'], $delais, $personnalisation, $GLOBALS['auteur_session']['id_auteur']); 401 402 //ajout du facteur global $delais 403 if (lire_meta('surcharge_delais_ok') == 'oui') { 404 $cacheHTML->setDelais(intval(lire_meta('surcharge_delais'))); 405 } 406 407 if (!$cacheHTML->useCache()) { 408 if (!$GLOBALS['db_ok']) 409 $use_cache = true; 410 411 // TODO a réécrire 412 /* 413 if (($delais < 0) and (file_exists("CACHE/$fichier_cache")) and ($GLOBALS['recalcul'] != 'oui')) { 414 $use_cache = true; 415 } 416 */ 417 418 //if (!$use_cache) { 419 //echo $delais. ' calcul de '.$fond.'<br />'; 420 include_local ("inc-calcul.php"); 421 $timer_a = explode(" ", microtime()); 422 $fond = chercher_squelette($fond, $contexte_inclus['id_rubrique']); 423 $page = calculer_page($fond, $contexte_inclus); 424 $timer_b = explode(" ", microtime()); 425 if ($page) { 426 $timer = ceil(1000 * ($timer_b[0] + $timer_b[1] - $timer_a[0] - $timer_a[1])); 427 $taille = ceil(strlen($page) / 1024); 428 spip_log ("inclus ($timer ms): " . $cacheHTML->getGroupId(). "/" . $cacheHTML->getCacheName(). " ($taille ko, delai: $delais s)"); 429 $cacheHTML->save($page); 430 } 431 //} 432 } 433 434 // $cacheHTML->includeCache(); 435 //include ($cacheHTML->getCacheHTMLFile()); 436 //include ($cacheHTML->_container->_cacheHTMLFile); // TODO : faire un get 437 return $cacheHTML->_container->_cacheHTMLFile; 438 } 439 440 function enrichissementContexteInclus ($contexte_inclus) { 441 if ($contexte_inclus['id_rubrique'] > 0) { 442 $rubriqueMetier = &recuperer_instance_rubrique(); 443 $loadOK = $rubriqueMetier->load($contexte_inclus['id_rubrique']); 444 if (!PEAR::isError($loadOK)) { 445 if ($rubriqueMetier->getLang()) 446 $contexte_inclus['lang'] = $rubriqueMetier->getLang(); 447 } 448 } 449 else if ($contexte_inclus['id_breve'] > 0) { 450 $breveMetier = &recuperer_instance_breve(); 451 $loadOK = $breveMetier->load($contexte_inclus['id_breve']); 452 if (!PEAR::isError($loadOK)) { 453 $contexte_inclus['id_rubrique'] = $breveMetier->getRubriqueId(); 454 $rubriqueMetier = &recuperer_instance_rubrique(); 455 $loadOK = $rubriqueMetier->load($contexte_inclus['id_rubrique']); 456 if (!PEAR::isError($loadOK)) { 457 if ($rubriqueMetier->getLang()) 458 $contexte_inclus['lang'] = $rubriqueMetier->getLang(); 459 } 460 } 461 } 462 else if ($contexte_inclus['id_syndic'] > 0) { 463 $syndicMetier = &recuperer_instance_syndic(); 464 $loadOK = $syndicMetier->load($contexte_inclus['id_syndic']); 465 if (!PEAR::isError($loadOK)) { 466 $contexte_inclus['id_rubrique'] = $syndicMetier->getRubriqueId(); 467 $rubriqueMetier = &recuperer_instance_rubrique(); 468 $loadOK = $rubriqueMetier->load($contexte_inclus['id_rubrique']); 469 if (!PEAR::isError($loadOK)) { 470 if ($rubriqueMetier->getLang()) 471 $contexte_inclus['lang'] = $rubriqueMetier->getLang(); 472 } 473 } 474 } 475 else if ($contexte_inclus['id_article'] > 0) { 476 $articleMetier = &recuperer_instance_article(); 477 $loadOK = $articleMetier->loadLightWeight($contexte_inclus['id_article']); 478 if (!PEAR::isError($loadOK)) { 479 $contexte_inclus['id_rubrique'] = $articleMetier->getRubriqueId(); 480 if ($articleMetier->getLang()) 481 $contexte_inclus['lang'] = $articleMetier->getLang(); 482 } 483 } 484 else { 485 $contexte_inclus['id_rubrique'] = 0; 486 } 487 488 return $contexte_inclus; 489 } 490 491 function genererContexte ($contexte_inclus) { 492 $codePHP = ''; 493 494 while (list($key, $param) = each($contexte_inclus)) { 495 if ($param) 496 $codePHP .= " \$contexte_inclus[$key] = '" . addslashes($param). "';\n"; 497 else 498 $codePHP .= " \$contexte_inclus[$key] = '" . addslashes($contexte[$key]). "';\n"; 499 } 500 501 return $codePHP; 502 } 503 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 14:40:03 2007 | par Balluche grâce à PHPXref 0.7 |