diff --git a/ecrire/exec/aide_index.php b/ecrire/exec/aide_index.php index 5d71900f8eeb75aea70c0831996720bf728b1f2a..187be7eb24f94680151123cc6a9963d0453c14e4 100644 --- a/ecrire/exec/aide_index.php +++ b/ecrire/exec/aide_index.php @@ -22,21 +22,17 @@ include_spip('inc/texte'); function help_frame ($aide) { global $spip_lang; - echo "</head>\n"; + echo "<head><title>", _T('info_aide_en_ligne'), "</title></head>\n"; $frame_menu = "<frame src='" . generer_url_ecrire('aide_index', "aide=$aide&var_lang=$spip_lang&frame=menu", false, true) . "' name=\"gauche\" scrolling=\"auto\" noresize>\n"; $frame_body = "<frame src='" . generer_url_ecrire('aide_index', "aide=$aide&var_lang=$spip_lang&frame=body", false, true) . "' name=\"droite\" scrolling=\"auto\" noresize>\n"; if ($GLOBALS['spip_lang_rtl']) { - echo '<frameset cols="*,160" border="0" frameborder="0" framespacing="0">'; - echo $frame_body.$frame_menu; + echo '<frameset cols="*,160" border="0" frameborder="0" framespacing="0">', $frame_body,$frame_menu, '</frameset>'; } else { - echo '<frameset cols="160,*" border="0" frameborder="0" framespacing="0">'; - echo $frame_menu.$frame_body; + echo '<frameset cols="160,*" border="0" frameborder="0" framespacing="0">', $frame_menu,$frame_body, '</frameset>'; } - echo '</frameset>'; - echo "\n</html>"; } @@ -47,7 +43,8 @@ function help_frame ($aide) { // Erreur aide non disponible function erreur_aide_indisponible() { - install_debut_html(_T('forum_titre_erreur')); echo "<div>"._T('aide_non_disponible')."</div><div align='right'>".menu_langues('var_lang_ecrire')."</div>";install_fin_html(); + global $help_server; + install_debut_html(_T('forum_titre_erreur')); echo "<div>$help_server: "._T('aide_non_disponible')."</div><div align='right'>".menu_langues('var_lang_ecrire')."</div>";install_fin_html(); exit; } @@ -56,90 +53,34 @@ function fichier_aide($lang_aide = '') { global $help_server; if (!$lang_aide) $lang_aide = $GLOBALS['spip_lang']; + $fichier_aide = _DIR_CACHE . "aide-$lang_aide-aide.html"; + $lastm = @filemtime($fichier_aide); + $lastversion = @filemtime(_DIR_INCLUDE . 'inc_version.php'); - // fichier local ? - if (@file_exists($fichier_aide = _DIR_RACINE . "AIDE/aide-$lang_aide-aide.html")) { - return array(spip_file_get_contents($fichier_aide), $lang_aide); - } - - // fichier local ? si reduction ISO du code langue oc_prv_ni => oc - else if (ereg("(.*)_", $lang_aide, $regs) - AND (@file_exists($fichier_aide = _DIR_RACINE . "AIDE/aide-".$regs[1]."-aide.html"))) - return array(spip_file_get_contents($fichier_aide), $regs[1]); - - // Aide internet - else { - // en cache ? - if (!@file_exists( - $fichier_aide = _DIR_CACHE . "aide-$lang_aide-aide.html")) { - if ($help_server) { - include_spip('inc/distant'); - if (ecrire_fichier(_DIR_CACHE . 'aide-test', "test")) { - if ($contenu = - recuperer_page("$help_server/$lang_aide-aide.html")) - ecrire_fichier ($fichier_aide, $contenu); - else { - erreur_aide_indisponible(); - return false; - } - } - } - } - + // en cache et a jour ? + if (@is_readable($fichier_aide) AND ($lastm >= $lastversion)) { lire_fichier($fichier_aide, $contenu); - - if (strlen($contenu) > 500) { - return array($contenu, $lang_aide); - } - - } - - return false; -} - -function help_body($aide, $html) { - global $help_server; - - - // Recuperation du contenu de l'aide demandee - if ($aide) { - $html = analyse_aide($html, $aide); - - if (!$html) { - erreur_aide_indisponible(); - } } else { - // panneau d'accueil - $html = '<CENTER> - <img src="'._DIR_IMG_PACK. - 'logo-spip.gif" alt="SPIP" width="267" height="170" border="0"> - <p /> - <div align="center" style="font-variant: small-caps;"> - Système de publication pour l\'Internet - </div></CENTER> - <div style="position:absolute; bottom: 10px; right:20px; - font-size: 12px; ">'. - preg_replace(",<a ,i", "<a target='_new' ",_T('info_copyright_doc')). - '</div>'; + + // Non, chercher les tables de la loi + if (isset($help_server)) { + include_spip('inc/distant'); + if ($contenu = recuperer_page("$help_server/$lang_aide-aide.html")) { + // mettre en cache (tant pis si on peut pas) + ecrire_fichier ($fichier_aide, $contenu); + $lastm = time(); + } + + } else $contenu = ''; } - // Recherche des images de l'aide - $suite = $html; - $html = ""; - while (preg_match("@(<img([^<>]* +)? src=['\"])" - . "((AIDE|IMG)/([-_a-zA-Z0-9]*/?)([^'\"<>]*))@i", - $suite, $r)) { - $p = strpos($suite, $r[0]); - $img = str_replace('/', '-', $r[3]); - $html .= substr($suite, 0, $p) . - $r[1] . - generer_url_ecrire('aide_index', "img=$img", false, true); - $suite = substr($suite, $p + strlen($r[0])); - } + if (strlen($contenu) > 500) return array($contenu, $lastm); - $html .= $suite; + // c'est cuit + erreur_aide_indisponible(); +} -?> +define(_STYLE_AIDE_BODY, ' <style type="text/css"><!-- .spip_cadre { width : 100%; @@ -190,9 +131,48 @@ table.spip td { vertical-align: center; } ---></style> -</head> -<?php +--></style>'); + +function help_body($aide, $html) { + global $help_server; + + // Recuperation du contenu de l'aide demandee + + if ($aide) { + $html = analyse_aide($html, $aide); + if (!$html) { + erreur_aide_indisponible(); + } + } else { + // panneau d'accueil + $html = '<center> + <img src="'._DIR_IMG_PACK. + 'logo-spip.gif" alt="SPIP" width="267" height="170" border="0"> + <p /> + <div align="center" style="font-variant: small-caps;"> + Système de publication pour l\'Internet + </div></center> + <div style="position:absolute; bottom: 10px; right:20px; + font-size: 12px; ">'. + preg_replace(",<a ,i", "<a target='_new' ",_T('info_copyright_doc')). + '</div>'; + } + + // Recherche des images de l'aide + $suite = $html; + $html = ""; + while (preg_match("@(<img([^<>]* +)? src=['\"])" + . "((AIDE|IMG)/([-_a-zA-Z0-9]*/?)([^'\"<>]*))@i", + $suite, $r)) { + $p = strpos($suite, $r[0]); + $img = str_replace('/', '-', $r[3]); + $html .= substr($suite, 0, $p) . + $r[1] . + generer_url_ecrire('aide_index', "img=$img", false, true); + $suite = substr($suite, $p + strlen($r[0])); + } + + echo "<head><title>",_T('info_aide_en_ligne'), "</title>\n", _STYLE_AIDE_BODY, "</head>\n"; echo '<body bgcolor="#FFFFFF" text="#000000" TOPMARGIN="24" LEFTMARGIN="24" MARGINWIDTH="24" MARGINHEIGHT="24"'; if ($spip_lang_rtl) @@ -213,12 +193,11 @@ table.spip td { // Il faut que la langue de typo() soit celle de l'aide en ligne changer_typo($lang_aide); - $html = justifier($html."<p>"); + $html = justifier($html . $suite ); // Remplacer les liens externes par des liens ouvrants (a cause des frames) $html = ereg_replace('<a href="(http://[^"]+)"([^>]*)>', '<a href="\\1"\\2 target="_blank">', $html); echo $html; - } @@ -231,6 +210,8 @@ function help_img($regs) { list ($cache, $rep, $lang, $file, $ext) = $regs; header("Content-Type: image/$ext"); + header("Expires: ".gmdate("D, d M Y H:i:s", time()+24*3600) .' GMT'); + if ($rep=="IMG" AND $lang=="cache" AND @file_exists($img_tex = _DIR_IMG.'cache-TeX/'.preg_replace(',^TeX-,', '', $file))) { readfile($img_tex); @@ -251,38 +232,31 @@ function help_img($regs) { exit; } -/////////////////////////////////////// -// Le menu de gauche -// -function help_menu($aide, $html) { - global $spip_lang_left, $spip_lang_rtl, $spip_lang_right; -$triangle = "url(" . _DIR_IMG_PACK . 'triangle'.$spip_lang_rtl.'.gif) '; - -echo '<style type="text/css"> +define('AIDE_STYLE_MENU', '<style type="text/css"> <!-- a {text-decoration: none; } A:Hover {text-decoration: underline;} .article-inactif { - float: '.$spip_lang_left.'; - text-align: '.$spip_lang_left.'; + float: '.$GLOBALS['spip_lang_left'].'; + text-align: '.$GLOBALS['spip_lang_left'].'; width: 80%; - background: ' . $triangle . $spip_lang_left.' center no-repeat; + background: ' . "url(" . _DIR_IMG_PACK . 'triangle'.$GLOBALS['spip_lang_rtl'].'.gif) ' . $GLOBALS['spip_lang_left'].' center no-repeat; margin: 2px; padding: 0px; - padding-'.$spip_lang_left.': 20px; + padding-'.$GLOBALS['spip_lang_left'].': 20px; font-family: Arial, Sans, sans-serif; font-size: 12px; } .article-actif { - float: '.$spip_lang_right.'; - text-align: '.$spip_lang_right.'; + float: '.$GLOBALS['spip_lang_right'].'; + text-align: '.$GLOBALS['spip_lang_right'].'; width: 80%; - background: ' . $triangle . $spip_lang_right.' center no-repeat; + background: ' . "url(" . _DIR_IMG_PACK . 'triangle'.$GLOBALS['spip_lang_rtl'].'.gif) ' . $GLOBALS['spip_lang_right'].' center no-repeat; margin: 4px; padding: 0px; - padding-'.$spip_lang_right.': 20px; + padding-'.$GLOBALS['spip_lang_right'].': 20px; font-family: Arial, Sans, sans-serif; font-size: 12px; font-weight: bold; @@ -305,8 +279,15 @@ echo '<style type="text/css"> -moz-border-radius: 4px; } --> -</style> -<script type="text/javascript"><!-- +</style>'); + +/////////////////////////////////////// +// Le menu de gauche +// +function help_menu($aide, $html) { + global $spip_lang_rtl; + + echo "<head><title>",_T('info_aide_en_ligne'), "</title>\n",AIDE_STYLE_MENU, '<script type="text/javascript"><!-- var curr_article; function activer_article(id) { if (curr_article) @@ -319,8 +300,8 @@ function activer_article(id) { //--></script> '; -afficher_script_layer(); -echo ' + afficher_script_layer(); + echo ' </head> <body bgcolor="#FFFFFF" text="#000000" link="#E86519" vlink="#6E003A" alink="#FF9900" TOPMARGIN="5" LEFTMARGIN="5" MARGINWIDTH="5" MARGINHEIGHT="5"'; @@ -430,15 +411,13 @@ function analyse_aide($html, $aide=false) { preg_match_all(',<h([12])( class="spip")?'. '>([^/]+?)(/(.+?))?</h\1>,ism', $html, $regs, PREG_SET_ORDER); - if ($aide) { - unset ($regs); - $preg = ',<h2( class="spip")?' - . ">$aide/(.+?)</h2>(.*)$,ism"; - preg_match($preg, $html, $regs); - $regs = preg_replace(',<h[12].*,ism', '', $regs[3]); - } + // pas de sujet precis: retourner le tableau des sujets + if (!$aide) return $regs; - return $regs; + unset ($regs); + $preg = ',<h2( class="spip")?' . ">$aide/(.+?)</h2>(.*)$,ism"; + preg_match($preg, $html, $regs); + return preg_replace(',<h[12].*,ism', '', $regs[3]); } // @@ -447,10 +426,6 @@ function analyse_aide($html, $aide=false) { function exec_aide_index_dist() { global $img, $frame, $aide, $var_lang, $lang, $help_server; -// Eviter les calculs evitables (surtout en client/serveur sans cache !) - - if (http_last_modified(filemtime(_DIR_INCLUDE . 'inc_version.php'), time() + 24 * 3600)) - exit; // Recuperer les infos de langue (preferences auteur), si possible utiliser_langue_visiteur(); @@ -460,33 +435,42 @@ if ($lang) changer_langue($lang); # pour le cas ou on a fait appel au menu de ch if (preg_match(',^([^-.]*)-([^-.]*)-([^\.]*\.(gif|jpg|png))$,', $img, $regs)) help_img($regs); else { - list($html, $l, $url_aide) = fichier_aide(); - - // On n'a pas d'aide - if (!$html) { - // Renvoyer sur l'aide en ligne du serveur externe - if ($help_server) - redirige_par_entete("$help_server/?lang=$var_lang&aide=$aide"); - // Sinon message d'erreur - else { - erreur_aide_indisponible(); + list($html, $lastmodified) = fichier_aide(); + + // si on a la doc dans un fichier, controler if_modified_since + if ($lastmodified) { + $gmoddate = gmdate("D, d M Y H:i:s", $lastmodified); + header("Last-Modified: ".$gmoddate." GMT"); + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) + # MSoft IIS is dumb + AND !preg_match(',IIS/,', $_SERVER['SERVER_SOFTWARE'])) { + + $if_modified_since = preg_replace('/;.*/', '', + $_SERVER['HTTP_IF_MODIFIED_SINCE']); + $if_modified_since = trim(str_replace('GMT', '', $if_modified_since)); + if ($if_modified_since == $gmoddate) { + include_spip('inc/headers'); + http_status(304); + exit; + } } - } else { - header("Content-Type: text/html; charset=utf-8"); - echo "<!DOCTYPE HTML PUBLIC -'-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'> -<html lang='".$GLOBALS['spip_lang']."' dir='".($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr')."'> -<head> -<title>"._T('info_aide_en_ligne')."</title>\n"; - - if ($frame == 'menu') + } + + header("Content-Type: text/html; charset=utf-8"); + echo _DOCTYPE_ECRIRE, "\n", + "<html lang='", + $GLOBALS['spip_lang'], + "' dir='", + ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr'), + "'>\n"; + + if ($frame == 'menu') help_menu($aide, $html); - else if ($frame == 'body') + else if ($frame == 'body') help_body($aide, $html); - else + else help_frame($aide); - } + echo "\n</html>"; } - } ?>