Skip to content
Extraits de code Groupes Projets
Valider 0815aed1 rédigé par esj's avatar esj
Parcourir les fichiers

La doc devant bouger (on espère), on raffine la gestion du cache de l'aide qui...

La doc devant bouger (on espère), on raffine la gestion du cache de l'aide qui était faite à la louche. A présent, on compare si le fichier en cache est postérieur à inc_version: si non, on va le chercher sur spipnet, si oui on le prend (s'il a bougé c'est peut-etre a cause d'une version non encore chargée l'utilisateur, il ne faut pas le ramener).

Au passage, evacuation de code mort de l'époque où l'aide était incluse dans la distribution, un plus de conformité W3C (c'était pas difficile...) et les deux balises <style> sont mises sous forme de constantes à part. Romy, si ça te dit de passer ça en CSS, la voie est libre (mais avec les frameset, je t'en souhaite).
parent 5bc74588
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -22,21 +22,17 @@ include_spip('inc/texte'); ...@@ -22,21 +22,17 @@ include_spip('inc/texte');
function help_frame ($aide) { function help_frame ($aide) {
global $spip_lang; 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_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"; $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']) { if ($GLOBALS['spip_lang_rtl']) {
echo '<frameset cols="*,160" border="0" frameborder="0" framespacing="0">'; echo '<frameset cols="*,160" border="0" frameborder="0" framespacing="0">', $frame_body,$frame_menu, '</frameset>';
echo $frame_body.$frame_menu;
} }
else { else {
echo '<frameset cols="160,*" border="0" frameborder="0" framespacing="0">'; echo '<frameset cols="160,*" border="0" frameborder="0" framespacing="0">', $frame_menu,$frame_body, '</frameset>';
echo $frame_menu.$frame_body;
} }
echo '</frameset>';
echo "\n</html>";
} }
...@@ -47,7 +43,8 @@ function help_frame ($aide) { ...@@ -47,7 +43,8 @@ function help_frame ($aide) {
// Erreur aide non disponible // Erreur aide non disponible
function erreur_aide_indisponible() { 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; exit;
} }
...@@ -56,90 +53,34 @@ function fichier_aide($lang_aide = '') { ...@@ -56,90 +53,34 @@ function fichier_aide($lang_aide = '') {
global $help_server; global $help_server;
if (!$lang_aide) $lang_aide = $GLOBALS['spip_lang']; 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 ? // en cache et a jour ?
if (@file_exists($fichier_aide = _DIR_RACINE . "AIDE/aide-$lang_aide-aide.html")) { if (@is_readable($fichier_aide) AND ($lastm >= $lastversion)) {
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;
}
}
}
}
lire_fichier($fichier_aide, $contenu); 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 { } else {
// panneau d'accueil
$html = '<CENTER> // Non, chercher les tables de la loi
<img src="'._DIR_IMG_PACK. if (isset($help_server)) {
'logo-spip.gif" alt="SPIP" width="267" height="170" border="0"> include_spip('inc/distant');
<p /> if ($contenu = recuperer_page("$help_server/$lang_aide-aide.html")) {
<div align="center" style="font-variant: small-caps;"> // mettre en cache (tant pis si on peut pas)
Syst&egrave;me de publication pour l\'Internet ecrire_fichier ($fichier_aide, $contenu);
</div></CENTER> $lastm = time();
<div style="position:absolute; bottom: 10px; right:20px; }
font-size: 12px; ">'.
preg_replace(",<a ,i", "<a target='_new' ",_T('info_copyright_doc')). } else $contenu = '';
'</div>';
} }
// Recherche des images de l'aide if (strlen($contenu) > 500) return array($contenu, $lastm);
$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]));
}
$html .= $suite; // c'est cuit
erreur_aide_indisponible();
}
?> define(_STYLE_AIDE_BODY, '
<style type="text/css"><!-- <style type="text/css"><!--
.spip_cadre { .spip_cadre {
width : 100%; width : 100%;
...@@ -190,9 +131,48 @@ table.spip td { ...@@ -190,9 +131,48 @@ table.spip td {
vertical-align: center; vertical-align: center;
} }
--></style> --></style>');
</head>
<?php 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&egrave;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"'; echo '<body bgcolor="#FFFFFF" text="#000000" TOPMARGIN="24" LEFTMARGIN="24" MARGINWIDTH="24" MARGINHEIGHT="24"';
if ($spip_lang_rtl) if ($spip_lang_rtl)
...@@ -213,12 +193,11 @@ table.spip td { ...@@ -213,12 +193,11 @@ table.spip td {
// Il faut que la langue de typo() soit celle de l'aide en ligne // Il faut que la langue de typo() soit celle de l'aide en ligne
changer_typo($lang_aide); changer_typo($lang_aide);
$html = justifier($html."<p>"); $html = justifier($html . $suite );
// Remplacer les liens externes par des liens ouvrants (a cause des frames) // 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); $html = ereg_replace('<a href="(http://[^"]+)"([^>]*)>', '<a href="\\1"\\2 target="_blank">', $html);
echo $html; echo $html;
} }
...@@ -231,6 +210,8 @@ function help_img($regs) { ...@@ -231,6 +210,8 @@ function help_img($regs) {
list ($cache, $rep, $lang, $file, $ext) = $regs; list ($cache, $rep, $lang, $file, $ext) = $regs;
header("Content-Type: image/$ext"); 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" if ($rep=="IMG" AND $lang=="cache"
AND @file_exists($img_tex = _DIR_IMG.'cache-TeX/'.preg_replace(',^TeX-,', '', $file))) { AND @file_exists($img_tex = _DIR_IMG.'cache-TeX/'.preg_replace(',^TeX-,', '', $file))) {
readfile($img_tex); readfile($img_tex);
...@@ -251,38 +232,31 @@ function help_img($regs) { ...@@ -251,38 +232,31 @@ function help_img($regs) {
exit; 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) '; define('AIDE_STYLE_MENU', '<style type="text/css">
echo '<style type="text/css">
<!-- <!--
a {text-decoration: none; } a {text-decoration: none; }
A:Hover {text-decoration: underline;} A:Hover {text-decoration: underline;}
.article-inactif { .article-inactif {
float: '.$spip_lang_left.'; float: '.$GLOBALS['spip_lang_left'].';
text-align: '.$spip_lang_left.'; text-align: '.$GLOBALS['spip_lang_left'].';
width: 80%; 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; margin: 2px;
padding: 0px; padding: 0px;
padding-'.$spip_lang_left.': 20px; padding-'.$GLOBALS['spip_lang_left'].': 20px;
font-family: Arial, Sans, sans-serif; font-family: Arial, Sans, sans-serif;
font-size: 12px; font-size: 12px;
} }
.article-actif { .article-actif {
float: '.$spip_lang_right.'; float: '.$GLOBALS['spip_lang_right'].';
text-align: '.$spip_lang_right.'; text-align: '.$GLOBALS['spip_lang_right'].';
width: 80%; 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; margin: 4px;
padding: 0px; padding: 0px;
padding-'.$spip_lang_right.': 20px; padding-'.$GLOBALS['spip_lang_right'].': 20px;
font-family: Arial, Sans, sans-serif; font-family: Arial, Sans, sans-serif;
font-size: 12px; font-size: 12px;
font-weight: bold; font-weight: bold;
...@@ -305,8 +279,15 @@ echo '<style type="text/css"> ...@@ -305,8 +279,15 @@ echo '<style type="text/css">
-moz-border-radius: 4px; -moz-border-radius: 4px;
} }
--> -->
</style> </style>');
<script type="text/javascript"><!--
///////////////////////////////////////
// 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; var curr_article;
function activer_article(id) { function activer_article(id) {
if (curr_article) if (curr_article)
...@@ -319,8 +300,8 @@ function activer_article(id) { ...@@ -319,8 +300,8 @@ function activer_article(id) {
//--></script> //--></script>
'; ';
afficher_script_layer(); afficher_script_layer();
echo ' echo '
</head> </head>
<body bgcolor="#FFFFFF" text="#000000" link="#E86519" vlink="#6E003A" alink="#FF9900" TOPMARGIN="5" LEFTMARGIN="5" MARGINWIDTH="5" MARGINHEIGHT="5"'; <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) { ...@@ -430,15 +411,13 @@ function analyse_aide($html, $aide=false) {
preg_match_all(',<h([12])( class="spip")?'. '>([^/]+?)(/(.+?))?</h\1>,ism', preg_match_all(',<h([12])( class="spip")?'. '>([^/]+?)(/(.+?))?</h\1>,ism',
$html, $regs, PREG_SET_ORDER); $html, $regs, PREG_SET_ORDER);
if ($aide) { // pas de sujet precis: retourner le tableau des sujets
unset ($regs); if (!$aide) return $regs;
$preg = ',<h2( class="spip")?'
. ">$aide/(.+?)</h2>(.*)$,ism";
preg_match($preg, $html, $regs);
$regs = preg_replace(',<h[12].*,ism', '', $regs[3]);
}
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) { ...@@ -447,10 +426,6 @@ function analyse_aide($html, $aide=false) {
function exec_aide_index_dist() function exec_aide_index_dist()
{ {
global $img, $frame, $aide, $var_lang, $lang, $help_server; 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 // Recuperer les infos de langue (preferences auteur), si possible
utiliser_langue_visiteur(); utiliser_langue_visiteur();
...@@ -460,33 +435,42 @@ if ($lang) changer_langue($lang); # pour le cas ou on a fait appel au menu de ch ...@@ -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)) if (preg_match(',^([^-.]*)-([^-.]*)-([^\.]*\.(gif|jpg|png))$,', $img, $regs))
help_img($regs); help_img($regs);
else { else {
list($html, $l, $url_aide) = fichier_aide(); list($html, $lastmodified) = fichier_aide();
// On n'a pas d'aide // si on a la doc dans un fichier, controler if_modified_since
if (!$html) { if ($lastmodified) {
// Renvoyer sur l'aide en ligne du serveur externe $gmoddate = gmdate("D, d M Y H:i:s", $lastmodified);
if ($help_server) header("Last-Modified: ".$gmoddate." GMT");
redirige_par_entete("$help_server/?lang=$var_lang&aide=$aide"); if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])
// Sinon message d'erreur # MSoft IIS is dumb
else { AND !preg_match(',IIS/,', $_SERVER['SERVER_SOFTWARE'])) {
erreur_aide_indisponible();
$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 header("Content-Type: text/html; charset=utf-8");
'-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'> echo _DOCTYPE_ECRIRE, "\n",
<html lang='".$GLOBALS['spip_lang']."' dir='".($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr')."'> "<html lang='",
<head> $GLOBALS['spip_lang'],
<title>"._T('info_aide_en_ligne')."</title>\n"; "' dir='",
($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr'),
if ($frame == 'menu') "'>\n";
if ($frame == 'menu')
help_menu($aide, $html); help_menu($aide, $html);
else if ($frame == 'body') else if ($frame == 'body')
help_body($aide, $html); help_body($aide, $html);
else else
help_frame($aide); help_frame($aide);
} echo "\n</html>";
} }
} }
?> ?>
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter