PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/spip/ecrire/exec/aide_index.php

https://github.com/eyeswebcrea/espace-couture-sittler.fr
PHP | 415 lines | 368 code | 19 blank | 28 comment | 12 complexity | 29e0c93c77a2fd075dd32d5f9ff255bb MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0
  1. <?php
  2. /***************************************************************************\
  3. * SPIP, Systeme de publication pour l'internet *
  4. * *
  5. * Copyright (c) 2001-2010 *
  6. * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
  7. * *
  8. * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
  9. * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
  10. \***************************************************************************/
  11. if (!defined("_ECRIRE_INC_VERSION")) return;
  12. include_spip('inc/headers');
  13. include_spip('inc/texte');
  14. include_spip('inc/layer');
  15. // Les sections d'un fichier aide sont reperees ainsi:
  16. define('_SECTIONS_AIDE', ',<h([12])(?:\s+class="spip")?'. '>([^/]+?)(?:/(.+?))?</h\1>,ism');
  17. // Les appels a soi-meme (notamment les images)
  18. // doivent etre en relatif pour pouvoir creer un cache local
  19. function generer_url_aide($args)
  20. {
  21. return generer_url_ecrire('aide_index', $args, false, true);
  22. }
  23. function help_fichier_contenu ($lang_aide, $path, $help_server) {
  24. $contenu = array();
  25. include_spip('inc/distant');
  26. foreach ($help_server as $k => $server) {
  27. // Remplacer les liens aux images par leur gestionnaire de cache
  28. $url = "$server/$path";
  29. $page = help_replace_img(recuperer_page($url),$k);
  30. // les liens internes ne doivent pas etre deguises en externes
  31. $url = parse_url($url);
  32. $re = '@(<a\b[^>]*\s+href=["\'])' .
  33. '(?:' . $url['scheme'] . '://' . $url['host'] . ')?' .
  34. $url['path'] . '([^"\']*)@ims';
  35. $page = preg_replace($re,'\\1\\2', $page);
  36. preg_match_all(_SECTIONS_AIDE, $page, $sections, PREG_SET_ORDER);
  37. // Fusionner les aides ayant meme nom de section
  38. $vus = array();
  39. foreach ($sections as $section) {
  40. list($tout,$prof, $sujet,) = $section;
  41. if (in_array($sujet, $vus)) continue;
  42. $corps = help_section($sujet, $page, $prof);
  43. foreach ($contenu as $k => $s) {
  44. if ($sujet == $k) {
  45. // Section deja vue qu'il faut completer
  46. // Si le complement a des sous-sections,
  47. // ne pas en tenir compte quand on les rencontrera
  48. // lors des prochains passages dans la boucle
  49. if (preg_match_all(_SECTIONS_AIDE, $corps, $m, PREG_PATTERN_ORDER)) {
  50. if ($m) {$vus = array_merge($vus, $m[2]);}
  51. $contenu[$k] .= $corps;
  52. $corps = '';
  53. break;
  54. } else spip_log("aide $server $section incorrecte");
  55. }
  56. }
  57. // Si totalement nouveau, inserer le titre
  58. // mais pas le corps s'il contient des sous-sections:
  59. // elles vont venir dans les passages suivants
  60. if ($corps) {
  61. $corps = help_section($sujet, $page);
  62. $contenu[$sujet] = $tout . "\n" . $corps;
  63. }
  64. }
  65. }
  66. // Renvoyer les liens vraiment externes dans une autre fenetre
  67. $contenu = preg_replace('@<a href="(http://[^"]+)"([^>]*)>@',
  68. '<a href="\\1"\\2 target="_blank">',
  69. join('',$contenu));
  70. if (strlen($contenu) <= 75) return array(false, false);
  71. // Correction typo dans la langue demandee
  72. changer_typo($lang_aide);
  73. return '<body>' . justifier("<div>$contenu</div>") . '</body>';
  74. }
  75. // http://doc.spip.org/@help_lastmodified
  76. function help_lastmodified($lastmodified)
  77. {
  78. $gmoddate = gmdate("D, d M Y H:i:s", $lastmodified);
  79. header("Last-Modified: ".$gmoddate." GMT");
  80. if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])
  81. # MSoft IIS is dumb
  82. AND !preg_match(',IIS/,', $_SERVER['SERVER_SOFTWARE'])) {
  83. $ims = preg_replace('/;.*/', '',
  84. $_SERVER['HTTP_IF_MODIFIED_SINCE']);
  85. $ims = trim(str_replace('GMT', '', $ims));
  86. if ($ims == $gmoddate) {
  87. http_status(304);
  88. return true;
  89. }
  90. }
  91. return false;
  92. }
  93. // Les aides non mises a jour ont un vieux Path a remplacer
  94. // (mais ce serait bien de le faire en SQL une bonne fois)
  95. define('_REPLACE_IMG_PACK', "@(<img([^<>]* +)?\s*src=['\"])img_pack\/@ims");
  96. // Remplacer les URL des images par l'URL du gestionnaire de cache local
  97. function help_replace_img($contenu, $server=0)
  98. {
  99. $html = "";
  100. $re = "@(<img([^<>]* +)?\s*src=['\"])((AIDE|IMG|local)/([-_a-zA-Z0-9]*/?)([^'\"<>]*))@imsS";
  101. while (preg_match($re, $contenu, $r)) {
  102. $p = strpos($contenu, $r[0]);
  103. $i = $server . ':' . str_replace('/', '-', $r[3]);
  104. $h = generer_url_aide("img=" . $i);
  105. $html .= substr($contenu, 0, $p) . $r[1] . $h;
  106. $contenu = substr($contenu, $p + strlen($r[0]));
  107. }
  108. $html .= $contenu;
  109. // traiter les vieilles doc
  110. return preg_replace(_REPLACE_IMG_PACK,"\\1"._DIR_IMG_PACK, $html);
  111. }
  112. // un bout de squelette qu'il serait bon d'evacuer un jour.
  113. define('_HELP_PANNEAU', "<img src='" .
  114. chemin_image('logo-spip.gif') .
  115. "' alt='SPIP' style='width: 267px; height: 170px; border: 0px' />
  116. <br />
  117. <div align='center' style='font-variant: small-caps;'>
  118. Syst&egrave;me de publication pour l'Internet
  119. </div></div>
  120. <div style='position:absolute; bottom: 10px; right:20px; font-size: 12px; '>");
  121. // Autre squelette qui ne s'avoue pas comme tel
  122. // http://doc.spip.org/@help_body
  123. function help_body($aide) {
  124. if (!$aide) {
  125. $c = _T('info_copyright_doc',
  126. array('spipnet' => $GLOBALS['home_server']
  127. . '/' . $GLOBALS['spip_lang']
  128. . '_'));
  129. return "<div align='center'>" .
  130. _HELP_PANNEAU .
  131. preg_replace(",<a ,i", "<a class='target_blank' ", $c) .
  132. '</div>';
  133. } elseif ($aide == 'spip') {
  134. return "<table border='0' width='100%' height='60%'>
  135. <tr style='width: 100%' height='60%'>
  136. <td style='width: 100%' height='60%' align='center' valign='middle'>
  137. <img src='" . generer_url_aide('img=AIDE--logo-spip.gif').
  138. "' alt='SPIP' style='width: 300px; height: 170px; border: 0px;' />
  139. </td></tr></table>";
  140. } return '';
  141. }
  142. // Extraire la seule section demandee,
  143. // qui commence par son nom entouree d'une balise h2
  144. // et se termine par la prochaine balise h2 ou h1 ou le /body final.
  145. function help_section($aide, $contenu, $prof=2)
  146. {
  147. $maxprof = ($prof >=2) ? "12" : "1";
  148. $r = "@<h$prof" . '(?: class="spip")?' . '>\s*' . $aide
  149. ."\s*(?:/.+?)?</h$prof>(.*?)<(?:(?:h[$maxprof])|/body)@ism";
  150. if (preg_match($r, $contenu, $m))
  151. return $m[1];
  152. return '';
  153. }
  154. // Affichage du menu de gauche avec analyse de la section demandee
  155. // afin d'ouvrir le sous-menu correspondant a l'affichage a droite
  156. // http://doc.spip.org/@help_menu_rubrique
  157. function help_menu_rubrique($aide, $contenu)
  158. {
  159. global $spip_lang;
  160. $afficher = false;
  161. $ligne = $numrub = 0;
  162. $texte = $res = '';
  163. preg_match_all(_SECTIONS_AIDE, $contenu, $sections, PREG_SET_ORDER);
  164. foreach ($sections as $section) {
  165. list(,$prof, $sujet, $bloc) = $section;
  166. if ($prof == '1') {
  167. if ($afficher && $texte)
  168. $res .= block_parfois_visible("block$numrub", "<div class='rubrique'>$titre</div>", "\n$texte",'', $ouvrir);
  169. $afficher = $bloc ? ($bloc == 'redac') : true;
  170. $texte = '';
  171. if ($afficher) {
  172. $numrub++;
  173. $ouvrir = 0;
  174. $titre = $sujet;
  175. }
  176. } else {
  177. ++$ligne;
  178. $id = "ligne$ligne";
  179. if ($aide == $sujet) {
  180. $ouvrir = 1;
  181. $class = "article-actif";
  182. $texte .= http_script("curr_article = '$id';");
  183. } else $class = "article-inactif";
  184. $h = generer_url_aide("aide=$sujet&frame=body&var_lang=$spip_lang");
  185. $texte .= "<a class='$class' target='droite' id='$id' href='$h' onclick=\"activer_article('$id');return true;\">"
  186. . $bloc
  187. . "</a><br style='clear:both;' />\n";
  188. }
  189. }
  190. if ($afficher && $texte)
  191. $res .= block_parfois_visible("block$numrub", "<div class='rubrique'>$titre</div>", "\n$texte",'', $ouvrir);
  192. return $res;
  193. }
  194. function help_frame_menu($titre, $contenu, $lang)
  195. {
  196. global $spip_lang_rtl;
  197. return "<head>\n<title>" .$titre ."</title>\n" .
  198. '<link rel="stylesheet" type="text/css" href="' .
  199. generer_url_public('aide_menu', "ltr=". $GLOBALS['spip_lang_left']) .
  200. "\"/>\n" .
  201. http_script('', 'jquery.js') .
  202. "\n" .
  203. $GLOBALS['browser_layer'] .
  204. http_script('var curr_article;
  205. function activer_article(id) {
  206. if (curr_article)
  207. jQuery("#"+curr_article).removeClass("article-actif").addClass("article-inactif");
  208. if (id) {
  209. jQuery("#"+id).removeClass("article-inactif").addClass("article-actif");
  210. curr_article = id;
  211. }
  212. }
  213. ') . '
  214. </head>
  215. <body bgcolor="#FFFFFF" text="#000000" link="#E86519" vlink="#6E003A" alink="#FF9900" topmargin="5" leftmargin="5" marginwidth="5" marginheight="5"' .
  216. ($spip_lang_rtl ? " dir='rtl'" : '') .
  217. " lang='$lang'" . '>' .
  218. $contenu .
  219. '</body>';
  220. }
  221. function help_frame_body($titre, $aide, $html, $lang_aide='')
  222. {
  223. global $spip_lang_rtl;
  224. $dir = $spip_lang_rtl ? " dir='rtl'" : '';
  225. return "<head>\n<title>$titre</title>\n".
  226. '<link rel="stylesheet" type="text/css" href="'.
  227. url_absolue(find_in_path('aide_body.css')).
  228. "\"/>\n".
  229. "</head>\n".
  230. '<body bgcolor="#FFFFFF" text="#000000" topmargin="24" leftmargin="24" marginwidth="24" marginheight="24"' .
  231. $dir .
  232. " lang='$lang'>".
  233. help_body($aide) .
  234. ($aide ? $html : '').
  235. '</body>';
  236. }
  237. function help_frame_frame($titre, $aide, $lang)
  238. {
  239. global $spip_lang_rtl;
  240. $menu = "<frame src='" . generer_url_aide("aide=$aide&var_lang=$lang&frame=menu") . "' name=\"gauche\" id=\"gauche\" scrolling=\"auto\" />\n";
  241. $body = "<frame src='" . generer_url_aide("aide=$aide&var_lang=$lang&frame=body") . "' name=\"droite\" id=\"droite\" scrolling=\"auto\" />\n";
  242. $seq = $spip_lang_rtl ? "$body$menu" : "$menu$body";
  243. $dim = $spip_lang_rtl ? '*,160' : '160,*';
  244. return "<head>\n<title>$titre</title>\n</head>\n<frameset cols='$dim' border='0' frameborder='0' framespacing='0'>$seq</frameset>";
  245. }
  246. // http://doc.spip.org/@help_img_cache
  247. function help_img_cache($img, $ext)
  248. {
  249. header("Content-Type: image/$ext");
  250. header("Expires: ".gmdate("D, d M Y H:i:s", time()+24*3600) .' GMT');
  251. readfile($img);
  252. }
  253. // Regexp reperant le travail fait par help_replace_img
  254. define('_HELP_PLACE_IMG',',^(\d+:)?(([^-.]*)-([^-.]*)-([^\.]*\.(gif|jpg|png)))$,');
  255. // Distinguer la demande d'une image et la demande d'un texte.
  256. // Si c'est une URL d'image deguisee, on la cherche dans le cache ou on l'y met.
  257. // Voir les differentes localisations possibles dans help_replace_img
  258. //
  259. // http://doc.spip.org/@exec_aide_index_dist
  260. function exec_aide_index_dist()
  261. {
  262. global $help_server;
  263. if (!is_array($help_server)) $help_server = array($help_server);
  264. if (!preg_match(_HELP_PLACE_IMG, _request('img'), $r)) {
  265. aide_index_frame(_request('var_lang_r'),
  266. _request('lang_r'),
  267. _request('frame'),
  268. strtr(_request('aide'),'<>"\'', '____'),
  269. $help_server);
  270. } else {
  271. list (,$server, $cache, $rep, $lang, $file, $ext) = $r;
  272. if ($rep=="IMG" AND $lang=="cache"
  273. AND @file_exists($img = _DIR_VAR.'cache-TeX/'.preg_replace(',^TeX-,', '', $file))) {
  274. help_img_cache($img, $ext);
  275. } else if (@file_exists($img = _DIR_AIDE . $cache)) {
  276. help_img_cache($img, $ext);
  277. } else if (@file_exists($img = _DIR_RACINE . 'AIDE/aide-'.$cache)) {
  278. help_img_cache($img, $ext);
  279. } else {
  280. $server = intval(substr($server, 0, -1));
  281. if ($server = $help_server[$server]) {
  282. include_spip('inc/distant');
  283. sous_repertoire(_DIR_AIDE,'','',true);
  284. $img = "$server/$rep/$lang/$file";
  285. $contenu = recuperer_page($img);
  286. if ($contenu) {
  287. ecrire_fichier (_DIR_AIDE . $cache, $contenu);
  288. // Bug de certains OS:
  289. // le contenu est incompris au premier envoi
  290. // Donc ne pas mettre d'Expire
  291. header("Content-Type: image/$ext");
  292. echo $contenu;
  293. } else redirige_par_entete($img);
  294. } else redirige_par_entete(generer_url_public('404'));
  295. }
  296. }
  297. }
  298. // Determiner la langue L, et en deduire le Path du fichier d'aide.
  299. // Sur le site www.spip.net/, ca donne l'URL www.spip.net/L-aide.html
  300. // reecrit par le htacces suivant:
  301. // http://zone.spip.org/trac/spip-zone/browser/_galaxie_/www.spip.net/squelettes/htaccess.txt
  302. function aide_index_frame($var_lang_r, $lang_r, $frame, $aide, $help_server)
  303. {
  304. global $spip_lang;
  305. if ($var_lang_r)
  306. changer_langue($lang = $var_lang_r);
  307. if ($lang_r)
  308. # pour le cas ou on a fait appel au menu de changement de langue
  309. # (aide absente dans la langue x)
  310. changer_langue($lang = $lang_r);
  311. else $lang = $spip_lang;
  312. // L'aide correspondant a la langue demandee est dans un cache
  313. // reposant sur la date du fichier indiquant la version de SPIP
  314. // (approximatif, mais c'est deja qqch)
  315. $path = $spip_lang . "-aide.html";
  316. $md5 = md5(serialize($help_server));
  317. $fichier = _DIR_AIDE . substr($md5,0,16) . "-" . $path;
  318. $lastm = is_readable($fichier) ? filemtime($fichier) : 0;
  319. $lastversion = @filemtime(_DIR_RESTREINT . 'inc_version.php');
  320. if (!($lastm AND ($lastm >= $lastversion))) {
  321. $contenu = help_fichier_contenu($spip_lang, $path, $help_server);
  322. // mettre en cache (tant pis si echec)
  323. sous_repertoire(_DIR_AIDE,'','',true);
  324. if ($contenu) ecrire_fichier ($fichier, $contenu);
  325. $lastm = time();
  326. }
  327. $titre = _T('info_aide_en_ligne');
  328. if (!$frame) {
  329. echo _DOCTYPE_AIDE, html_lang_attributes();
  330. echo help_frame_frame($titre, $aide, $lang);
  331. echo "\n</html>";
  332. } else {
  333. header("Content-Type: text/html; charset=utf-8");
  334. if (!isset($contenu)) {
  335. lire_fichier($fichier, $contenu);
  336. }
  337. if (!$contenu) {
  338. include_spip('inc/minipres');
  339. echo minipres(_T('forum_titre_erreur'),
  340. "<div><a href='" .
  341. $GLOBALS['home_server'] .
  342. "'>" .
  343. $help_server[0] .
  344. "</a> $aide&nbsp;: ".
  345. _T('aide_non_disponible').
  346. "</div><br /><div align='right'>".
  347. menu_langues('var_lang_ecrire').
  348. "</div>");
  349. // Envoie le not-modified-since si possible, sinon envoie tout
  350. } elseif (!help_lastmodified($lastm)) {
  351. echo _DOCTYPE_AIDE, html_lang_attributes();
  352. if ($frame === 'menu') {
  353. $contenu = help_menu_rubrique($aide, $contenu);
  354. echo help_frame_menu($titre, $contenu, $lang);
  355. } else {
  356. if ($aide) {
  357. $contenu = help_section($aide, $contenu);
  358. if (!$contenu) spip_log("aide inconnue $aide dans " . substr($contenu, 0, 150));
  359. }
  360. echo help_frame_body($titre, $aide, $contenu, $lang);
  361. }
  362. echo "\n</html>";
  363. }
  364. }
  365. }
  366. ?>