@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | // |
| 14 | 14 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 15 | - return; |
|
| 15 | + return; |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | // |
@@ -21,54 +21,54 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | function produire_image_math($tex) { |
| 23 | 23 | |
| 24 | - switch ($GLOBALS['traiter_math']) { |
|
| 25 | - // Attention: mathml desactiv'e pour l'instant |
|
| 26 | - case 'mathml': |
|
| 27 | - $ext = '.xhtml'; |
|
| 28 | - $server = $GLOBALS['mathml_server']; |
|
| 29 | - break; |
|
| 30 | - case 'tex': |
|
| 31 | - $ext = '.png'; |
|
| 32 | - $server = $GLOBALS['tex_server']; |
|
| 33 | - break; |
|
| 34 | - default: |
|
| 35 | - return $tex; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 39 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 40 | - @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 41 | - } |
|
| 42 | - $fichier = $dir_tex . md5(trim($tex)) . $ext; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - if (!@file_exists($fichier)) { |
|
| 46 | - // Aller chercher l'image sur le serveur |
|
| 47 | - if ($server) { |
|
| 48 | - spip_log($url = $server . '?' . rawurlencode($tex)); |
|
| 49 | - include_spip('inc/distant'); |
|
| 50 | - recuperer_url($url, ['file' => $fichier]); |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - // Composer la reponse selon presence ou non de l'image |
|
| 56 | - $tex = entites_html($tex); |
|
| 57 | - if (@file_exists($fichier)) { |
|
| 58 | - // MathML |
|
| 59 | - if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 60 | - return implode('', file($fichier)); |
|
| 61 | - } // TeX |
|
| 62 | - else { |
|
| 63 | - [, , , $size] = @spip_getimagesize($fichier); |
|
| 64 | - $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 65 | - |
|
| 66 | - return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 67 | - } |
|
| 68 | - } else // pas de fichier |
|
| 69 | - { |
|
| 70 | - return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 71 | - } |
|
| 24 | + switch ($GLOBALS['traiter_math']) { |
|
| 25 | + // Attention: mathml desactiv'e pour l'instant |
|
| 26 | + case 'mathml': |
|
| 27 | + $ext = '.xhtml'; |
|
| 28 | + $server = $GLOBALS['mathml_server']; |
|
| 29 | + break; |
|
| 30 | + case 'tex': |
|
| 31 | + $ext = '.png'; |
|
| 32 | + $server = $GLOBALS['tex_server']; |
|
| 33 | + break; |
|
| 34 | + default: |
|
| 35 | + return $tex; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 39 | + if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 40 | + @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 41 | + } |
|
| 42 | + $fichier = $dir_tex . md5(trim($tex)) . $ext; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + if (!@file_exists($fichier)) { |
|
| 46 | + // Aller chercher l'image sur le serveur |
|
| 47 | + if ($server) { |
|
| 48 | + spip_log($url = $server . '?' . rawurlencode($tex)); |
|
| 49 | + include_spip('inc/distant'); |
|
| 50 | + recuperer_url($url, ['file' => $fichier]); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + // Composer la reponse selon presence ou non de l'image |
|
| 56 | + $tex = entites_html($tex); |
|
| 57 | + if (@file_exists($fichier)) { |
|
| 58 | + // MathML |
|
| 59 | + if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 60 | + return implode('', file($fichier)); |
|
| 61 | + } // TeX |
|
| 62 | + else { |
|
| 63 | + [, , , $size] = @spip_getimagesize($fichier); |
|
| 64 | + $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 65 | + |
|
| 66 | + return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 67 | + } |
|
| 68 | + } else // pas de fichier |
|
| 69 | + { |
|
| 70 | + return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 71 | + } |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | |
@@ -103,52 +103,52 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | function traiter_math($letexte, $source = '', $defaire_amp = false) { |
| 105 | 105 | |
| 106 | - $texte_a_voir = $letexte; |
|
| 107 | - while (($debut = strpos($texte_a_voir, '<math>')) !== false) { |
|
| 108 | - if (!$fin = strpos($texte_a_voir, '</math>')) { |
|
| 109 | - $fin = strlen($texte_a_voir); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - $texte_debut = substr($texte_a_voir, 0, $debut); |
|
| 113 | - $texte_milieu = substr( |
|
| 114 | - $texte_a_voir, |
|
| 115 | - $debut + strlen('<math>'), |
|
| 116 | - $fin - $debut - strlen('<math>') |
|
| 117 | - ); |
|
| 118 | - $texte_fin = substr( |
|
| 119 | - $texte_a_voir, |
|
| 120 | - $fin + strlen('</math>'), |
|
| 121 | - strlen($texte_a_voir) |
|
| 122 | - ); |
|
| 123 | - |
|
| 124 | - // Les doubles $$x^2$$ en mode 'div' |
|
| 125 | - while ((preg_match(',[$][$]([^$]+)[$][$],', $texte_milieu, $regs))) { |
|
| 126 | - $expression = $regs[1]; |
|
| 127 | - if ($defaire_amp) { |
|
| 128 | - $expression = str_replace('&', '&', $expression); |
|
| 129 | - } |
|
| 130 | - $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 131 | - $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 132 | - $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 133 | - . code_echappement($echap, $source) |
|
| 134 | - . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - // Les simples $x^2$ en mode 'span' |
|
| 138 | - while ((preg_match(',[$]([^$]+)[$],', $texte_milieu, $regs))) { |
|
| 139 | - $expression = $regs[1]; |
|
| 140 | - if ($defaire_amp) { |
|
| 141 | - $expression = str_replace('&', '&', $expression); |
|
| 142 | - } |
|
| 143 | - $echap = produire_image_math($expression); |
|
| 144 | - $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 145 | - $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 146 | - . code_echappement($echap, $source) |
|
| 147 | - . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return $texte_a_voir; |
|
| 106 | + $texte_a_voir = $letexte; |
|
| 107 | + while (($debut = strpos($texte_a_voir, '<math>')) !== false) { |
|
| 108 | + if (!$fin = strpos($texte_a_voir, '</math>')) { |
|
| 109 | + $fin = strlen($texte_a_voir); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + $texte_debut = substr($texte_a_voir, 0, $debut); |
|
| 113 | + $texte_milieu = substr( |
|
| 114 | + $texte_a_voir, |
|
| 115 | + $debut + strlen('<math>'), |
|
| 116 | + $fin - $debut - strlen('<math>') |
|
| 117 | + ); |
|
| 118 | + $texte_fin = substr( |
|
| 119 | + $texte_a_voir, |
|
| 120 | + $fin + strlen('</math>'), |
|
| 121 | + strlen($texte_a_voir) |
|
| 122 | + ); |
|
| 123 | + |
|
| 124 | + // Les doubles $$x^2$$ en mode 'div' |
|
| 125 | + while ((preg_match(',[$][$]([^$]+)[$][$],', $texte_milieu, $regs))) { |
|
| 126 | + $expression = $regs[1]; |
|
| 127 | + if ($defaire_amp) { |
|
| 128 | + $expression = str_replace('&', '&', $expression); |
|
| 129 | + } |
|
| 130 | + $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 131 | + $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 132 | + $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 133 | + . code_echappement($echap, $source) |
|
| 134 | + . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + // Les simples $x^2$ en mode 'span' |
|
| 138 | + while ((preg_match(',[$]([^$]+)[$],', $texte_milieu, $regs))) { |
|
| 139 | + $expression = $regs[1]; |
|
| 140 | + if ($defaire_amp) { |
|
| 141 | + $expression = str_replace('&', '&', $expression); |
|
| 142 | + } |
|
| 143 | + $echap = produire_image_math($expression); |
|
| 144 | + $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 145 | + $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 146 | + . code_echappement($echap, $source) |
|
| 147 | + . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return $texte_a_voir; |
|
| 154 | 154 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -26,70 +26,70 @@ discard block |
||
| 26 | 26 | * @return string Code HTML du cadre dépliable |
| 27 | 27 | **/ |
| 28 | 28 | function cadre_depliable($icone, $titre, $deplie, $contenu, $ids = '', $style_cadre = 'r') { |
| 29 | - $bouton = bouton_block_depliable($titre, $deplie, $ids); |
|
| 30 | - |
|
| 31 | - return |
|
| 32 | - debut_cadre($style_cadre, $icone, '', $bouton, '', '', false) |
|
| 33 | - . debut_block_depliable($deplie, $ids) |
|
| 34 | - . "<div class='cadre_padding'>\n" |
|
| 35 | - . $contenu |
|
| 36 | - . "</div>\n" |
|
| 37 | - . fin_block() |
|
| 38 | - . fin_cadre(); |
|
| 29 | + $bouton = bouton_block_depliable($titre, $deplie, $ids); |
|
| 30 | + |
|
| 31 | + return |
|
| 32 | + debut_cadre($style_cadre, $icone, '', $bouton, '', '', false) |
|
| 33 | + . debut_block_depliable($deplie, $ids) |
|
| 34 | + . "<div class='cadre_padding'>\n" |
|
| 35 | + . $contenu |
|
| 36 | + . "</div>\n" |
|
| 37 | + . fin_block() |
|
| 38 | + . fin_cadre(); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | function block_parfois_visible($nom, $invite, $masque, $style = '', $visible = false) { |
| 42 | - return "\n" |
|
| 43 | - . bouton_block_depliable($invite, $visible, $nom) |
|
| 44 | - . debut_block_depliable($visible, $nom) |
|
| 45 | - . $masque |
|
| 46 | - . fin_block(); |
|
| 42 | + return "\n" |
|
| 43 | + . bouton_block_depliable($invite, $visible, $nom) |
|
| 44 | + . debut_block_depliable($visible, $nom) |
|
| 45 | + . $masque |
|
| 46 | + . fin_block(); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | function debut_block_depliable($deplie, $id = '') { |
| 50 | - $class = ' blocdeplie'; |
|
| 51 | - // si on n'accepte pas js, ne pas fermer |
|
| 52 | - if (!$deplie) { |
|
| 53 | - $class = ' blocreplie'; |
|
| 54 | - } |
|
| 50 | + $class = ' blocdeplie'; |
|
| 51 | + // si on n'accepte pas js, ne pas fermer |
|
| 52 | + if (!$deplie) { |
|
| 53 | + $class = ' blocreplie'; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>"; |
|
| 56 | + return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>"; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | function fin_block() { |
| 60 | - return "<div class='nettoyeur'></div>\n</div>"; |
|
| 60 | + return "<div class='nettoyeur'></div>\n</div>"; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // $texte : texte du bouton |
| 64 | 64 | // $deplie : true (deplie) ou false (plie) ou -1 (inactif) ou 'incertain' pour que le bouton s'auto init au chargement de la page |
| 65 | 65 | // $ids : id des div lies au bouton (facultatif, par defaut c'est le div.bloc_depliable qui suit) |
| 66 | 66 | function bouton_block_depliable($texte, $deplie, $ids = '') { |
| 67 | - $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8); |
|
| 68 | - |
|
| 69 | - $class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie'); |
|
| 70 | - if (strlen($ids)) { |
|
| 71 | - $cible = explode(',', $ids); |
|
| 72 | - $cible = '#' . implode(',#', $cible); |
|
| 73 | - } else { |
|
| 74 | - $cible = "#$bouton_id + div.bloc_depliable"; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $b = (strpos($texte, '<h') === false ? 'h3' : 'div'); |
|
| 78 | - |
|
| 79 | - return "<$b " |
|
| 80 | - . ($bouton_id ? "id='$bouton_id' " : '') |
|
| 81 | - . "class='titrem$class'" |
|
| 82 | - . (($deplie === -1) |
|
| 83 | - ? '' |
|
| 84 | - : " onmouseover=\"jQuery(this).depliant('$cible');\"" |
|
| 85 | - ) |
|
| 86 | - . '>' |
|
| 87 | - // une ancre pour rendre accessible au clavier le depliage du sous bloc |
|
| 88 | - . "<a href='#' onclick=\"return jQuery(this).depliant_clicancre('$cible');\" class='titremancre'></a>" |
|
| 89 | - . "$texte</$b>" |
|
| 90 | - . http_script(($deplie === 'incertain') |
|
| 91 | - ? "jQuery(function($){if ($('$cible').is(':visible')) { $('#$bouton_id').addClass('deplie').removeClass('replie'); }});" |
|
| 92 | - : ''); |
|
| 67 | + $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8); |
|
| 68 | + |
|
| 69 | + $class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie'); |
|
| 70 | + if (strlen($ids)) { |
|
| 71 | + $cible = explode(',', $ids); |
|
| 72 | + $cible = '#' . implode(',#', $cible); |
|
| 73 | + } else { |
|
| 74 | + $cible = "#$bouton_id + div.bloc_depliable"; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $b = (strpos($texte, '<h') === false ? 'h3' : 'div'); |
|
| 78 | + |
|
| 79 | + return "<$b " |
|
| 80 | + . ($bouton_id ? "id='$bouton_id' " : '') |
|
| 81 | + . "class='titrem$class'" |
|
| 82 | + . (($deplie === -1) |
|
| 83 | + ? '' |
|
| 84 | + : " onmouseover=\"jQuery(this).depliant('$cible');\"" |
|
| 85 | + ) |
|
| 86 | + . '>' |
|
| 87 | + // une ancre pour rendre accessible au clavier le depliage du sous bloc |
|
| 88 | + . "<a href='#' onclick=\"return jQuery(this).depliant_clicancre('$cible');\" class='titremancre'></a>" |
|
| 89 | + . "$texte</$b>" |
|
| 90 | + . http_script(($deplie === 'incertain') |
|
| 91 | + ? "jQuery(function($){if ($('$cible').is(':visible')) { $('#$bouton_id').addClass('deplie').removeClass('replie'); }});" |
|
| 92 | + : ''); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // |
@@ -97,66 +97,66 @@ discard block |
||
| 97 | 97 | // |
| 98 | 98 | function verif_butineur() { |
| 99 | 99 | |
| 100 | - preg_match(',^([A-Za-z]+)/([0-9]+\.[0-9]+) (.*)$,', $_SERVER['HTTP_USER_AGENT'], $match); |
|
| 101 | - $GLOBALS['browser_name'] = $match[1]; |
|
| 102 | - $GLOBALS['browser_version'] = $match[2]; |
|
| 103 | - $GLOBALS['browser_description'] = $match[3]; |
|
| 104 | - $GLOBALS['browser_layer'] = ' '; // compat avec vieux scripts qui testent la valeur |
|
| 105 | - $GLOBALS['browser_barre'] = ''; |
|
| 106 | - |
|
| 107 | - if (!preg_match(',opera,i', $GLOBALS['browser_description']) && preg_match(',opera,i', $GLOBALS['browser_name'])) { |
|
| 108 | - $GLOBALS['browser_name'] = 'Opera'; |
|
| 109 | - $GLOBALS['browser_version'] = $match[2]; |
|
| 110 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 111 | - } else { |
|
| 112 | - if (preg_match(',opera,i', $GLOBALS['browser_description'])) { |
|
| 113 | - preg_match(',Opera ([^\ ]*),i', $GLOBALS['browser_description'], $match); |
|
| 114 | - $GLOBALS['browser_name'] = 'Opera'; |
|
| 115 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 116 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 117 | - } else { |
|
| 118 | - if (preg_match(',msie,i', $GLOBALS['browser_description'])) { |
|
| 119 | - preg_match(',MSIE ([^;]*),i', $GLOBALS['browser_description'], $match); |
|
| 120 | - $GLOBALS['browser_name'] = 'MSIE'; |
|
| 121 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 122 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.5); |
|
| 123 | - } else { |
|
| 124 | - if ( |
|
| 125 | - preg_match(',KHTML,i', $GLOBALS['browser_description']) && |
|
| 126 | - preg_match(',Safari/([^;]*),', $GLOBALS['browser_description'], $match) |
|
| 127 | - ) { |
|
| 128 | - $GLOBALS['browser_name'] = 'Safari'; |
|
| 129 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 130 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.0); |
|
| 131 | - } else { |
|
| 132 | - if (preg_match(',mozilla,i', $GLOBALS['browser_name']) and $GLOBALS['browser_version'] >= 5) { |
|
| 133 | - // Numero de version pour Mozilla "authentique" |
|
| 134 | - if (preg_match(',rv:([0-9]+\.[0-9]+),', $GLOBALS['browser_description'], $match)) { |
|
| 135 | - $GLOBALS['browser_rev'] = doubleval($match[1]); |
|
| 136 | - } // Autres Gecko => equivalents 1.4 par defaut (Galeon, etc.) |
|
| 137 | - else { |
|
| 138 | - if ( |
|
| 139 | - strpos($GLOBALS['browser_description'], 'Gecko') and !strpos( |
|
| 140 | - $GLOBALS['browser_description'], |
|
| 141 | - 'KHTML' |
|
| 142 | - ) |
|
| 143 | - ) { |
|
| 144 | - $GLOBALS['browser_rev'] = 1.4; |
|
| 145 | - } // Machins quelconques => equivalents 1.0 par defaut (Konqueror, etc.) |
|
| 146 | - else { |
|
| 147 | - $GLOBALS['browser_rev'] = 1.0; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - $GLOBALS['browser_barre'] = $GLOBALS['browser_rev'] >= 1.3; |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if (!$GLOBALS['browser_name']) { |
|
| 158 | - $GLOBALS['browser_name'] = 'Mozilla'; |
|
| 159 | - } |
|
| 100 | + preg_match(',^([A-Za-z]+)/([0-9]+\.[0-9]+) (.*)$,', $_SERVER['HTTP_USER_AGENT'], $match); |
|
| 101 | + $GLOBALS['browser_name'] = $match[1]; |
|
| 102 | + $GLOBALS['browser_version'] = $match[2]; |
|
| 103 | + $GLOBALS['browser_description'] = $match[3]; |
|
| 104 | + $GLOBALS['browser_layer'] = ' '; // compat avec vieux scripts qui testent la valeur |
|
| 105 | + $GLOBALS['browser_barre'] = ''; |
|
| 106 | + |
|
| 107 | + if (!preg_match(',opera,i', $GLOBALS['browser_description']) && preg_match(',opera,i', $GLOBALS['browser_name'])) { |
|
| 108 | + $GLOBALS['browser_name'] = 'Opera'; |
|
| 109 | + $GLOBALS['browser_version'] = $match[2]; |
|
| 110 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 111 | + } else { |
|
| 112 | + if (preg_match(',opera,i', $GLOBALS['browser_description'])) { |
|
| 113 | + preg_match(',Opera ([^\ ]*),i', $GLOBALS['browser_description'], $match); |
|
| 114 | + $GLOBALS['browser_name'] = 'Opera'; |
|
| 115 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 116 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 117 | + } else { |
|
| 118 | + if (preg_match(',msie,i', $GLOBALS['browser_description'])) { |
|
| 119 | + preg_match(',MSIE ([^;]*),i', $GLOBALS['browser_description'], $match); |
|
| 120 | + $GLOBALS['browser_name'] = 'MSIE'; |
|
| 121 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 122 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.5); |
|
| 123 | + } else { |
|
| 124 | + if ( |
|
| 125 | + preg_match(',KHTML,i', $GLOBALS['browser_description']) && |
|
| 126 | + preg_match(',Safari/([^;]*),', $GLOBALS['browser_description'], $match) |
|
| 127 | + ) { |
|
| 128 | + $GLOBALS['browser_name'] = 'Safari'; |
|
| 129 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 130 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.0); |
|
| 131 | + } else { |
|
| 132 | + if (preg_match(',mozilla,i', $GLOBALS['browser_name']) and $GLOBALS['browser_version'] >= 5) { |
|
| 133 | + // Numero de version pour Mozilla "authentique" |
|
| 134 | + if (preg_match(',rv:([0-9]+\.[0-9]+),', $GLOBALS['browser_description'], $match)) { |
|
| 135 | + $GLOBALS['browser_rev'] = doubleval($match[1]); |
|
| 136 | + } // Autres Gecko => equivalents 1.4 par defaut (Galeon, etc.) |
|
| 137 | + else { |
|
| 138 | + if ( |
|
| 139 | + strpos($GLOBALS['browser_description'], 'Gecko') and !strpos( |
|
| 140 | + $GLOBALS['browser_description'], |
|
| 141 | + 'KHTML' |
|
| 142 | + ) |
|
| 143 | + ) { |
|
| 144 | + $GLOBALS['browser_rev'] = 1.4; |
|
| 145 | + } // Machins quelconques => equivalents 1.0 par defaut (Konqueror, etc.) |
|
| 146 | + else { |
|
| 147 | + $GLOBALS['browser_rev'] = 1.0; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + $GLOBALS['browser_barre'] = $GLOBALS['browser_rev'] >= 1.3; |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if (!$GLOBALS['browser_name']) { |
|
| 158 | + $GLOBALS['browser_name'] = 'Mozilla'; |
|
| 159 | + } |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | verif_butineur(); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | // Les parametres generaux du site sont dans une table SQL; |
@@ -27,51 +27,51 @@ discard block |
||
| 27 | 27 | define('_META_CACHE_TIME', 1 << 24); |
| 28 | 28 | |
| 29 | 29 | function inc_meta_dist($table = 'meta') { |
| 30 | - $new = null; |
|
| 31 | - // Lire les meta, en cache si present, valide et lisible |
|
| 32 | - // en cas d'install ne pas faire confiance au meta_cache eventuel |
|
| 33 | - $cache = cache_meta($table); |
|
| 30 | + $new = null; |
|
| 31 | + // Lire les meta, en cache si present, valide et lisible |
|
| 32 | + // en cas d'install ne pas faire confiance au meta_cache eventuel |
|
| 33 | + $cache = cache_meta($table); |
|
| 34 | 34 | |
| 35 | - if ( |
|
| 36 | - (!$exec = _request('exec') or !autoriser_sans_cookie($exec)) |
|
| 37 | - and $new = jeune_fichier($cache, _META_CACHE_TIME) |
|
| 38 | - and lire_fichier_securise($cache, $meta) |
|
| 39 | - and $meta = @unserialize($meta) |
|
| 40 | - ) { |
|
| 41 | - $GLOBALS[$table] = $meta; |
|
| 42 | - } |
|
| 35 | + if ( |
|
| 36 | + (!$exec = _request('exec') or !autoriser_sans_cookie($exec)) |
|
| 37 | + and $new = jeune_fichier($cache, _META_CACHE_TIME) |
|
| 38 | + and lire_fichier_securise($cache, $meta) |
|
| 39 | + and $meta = @unserialize($meta) |
|
| 40 | + ) { |
|
| 41 | + $GLOBALS[$table] = $meta; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - if ( |
|
| 45 | - isset($GLOBALS[$table]['touch']) |
|
| 46 | - and ($GLOBALS[$table]['touch'] < time() - _META_CACHE_TIME) |
|
| 47 | - ) { |
|
| 48 | - $GLOBALS[$table] = []; |
|
| 49 | - } |
|
| 50 | - // sinon lire en base |
|
| 51 | - if (!$GLOBALS[$table]) { |
|
| 52 | - $new = !lire_metas($table); |
|
| 53 | - } |
|
| 44 | + if ( |
|
| 45 | + isset($GLOBALS[$table]['touch']) |
|
| 46 | + and ($GLOBALS[$table]['touch'] < time() - _META_CACHE_TIME) |
|
| 47 | + ) { |
|
| 48 | + $GLOBALS[$table] = []; |
|
| 49 | + } |
|
| 50 | + // sinon lire en base |
|
| 51 | + if (!$GLOBALS[$table]) { |
|
| 52 | + $new = !lire_metas($table); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - // renouveller l'alea general si trop vieux ou sur demande explicite |
|
| 56 | - if ( |
|
| 57 | - (test_espace_prive() || isset($_GET['renouvelle_alea'])) |
|
| 58 | - and $GLOBALS[$table] |
|
| 59 | - and (time() > _RENOUVELLE_ALEA + ($GLOBALS['meta']['alea_ephemere_date'] ?? 0)) |
|
| 60 | - ) { |
|
| 61 | - // si on n'a pas l'acces en ecriture sur le cache, |
|
| 62 | - // ne pas renouveller l'alea sinon le cache devient faux |
|
| 63 | - if (supprimer_fichier($cache)) { |
|
| 64 | - include_spip('inc/acces'); |
|
| 65 | - renouvelle_alea(); |
|
| 66 | - $new = false; |
|
| 67 | - } else { |
|
| 68 | - spip_log("impossible d'ecrire dans " . $cache); |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - // et refaire le cache si on a du lire en base |
|
| 72 | - if (!$new) { |
|
| 73 | - touch_meta(false, $table); |
|
| 74 | - } |
|
| 55 | + // renouveller l'alea general si trop vieux ou sur demande explicite |
|
| 56 | + if ( |
|
| 57 | + (test_espace_prive() || isset($_GET['renouvelle_alea'])) |
|
| 58 | + and $GLOBALS[$table] |
|
| 59 | + and (time() > _RENOUVELLE_ALEA + ($GLOBALS['meta']['alea_ephemere_date'] ?? 0)) |
|
| 60 | + ) { |
|
| 61 | + // si on n'a pas l'acces en ecriture sur le cache, |
|
| 62 | + // ne pas renouveller l'alea sinon le cache devient faux |
|
| 63 | + if (supprimer_fichier($cache)) { |
|
| 64 | + include_spip('inc/acces'); |
|
| 65 | + renouvelle_alea(); |
|
| 66 | + $new = false; |
|
| 67 | + } else { |
|
| 68 | + spip_log("impossible d'ecrire dans " . $cache); |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + // et refaire le cache si on a du lire en base |
|
| 72 | + if (!$new) { |
|
| 73 | + touch_meta(false, $table); |
|
| 74 | + } |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | // fonctions aussi appelees a l'install ==> spip_query en premiere requete |
@@ -79,39 +79,39 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | function lire_metas($table = 'meta') { |
| 81 | 81 | |
| 82 | - if ($result = spip_query("SELECT nom,valeur FROM spip_$table")) { |
|
| 83 | - include_spip('base/abstract_sql'); |
|
| 84 | - $GLOBALS[$table] = []; |
|
| 85 | - while ($row = sql_fetch($result)) { |
|
| 86 | - $GLOBALS[$table][$row['nom']] = $row['valeur']; |
|
| 87 | - } |
|
| 88 | - sql_free($result); |
|
| 82 | + if ($result = spip_query("SELECT nom,valeur FROM spip_$table")) { |
|
| 83 | + include_spip('base/abstract_sql'); |
|
| 84 | + $GLOBALS[$table] = []; |
|
| 85 | + while ($row = sql_fetch($result)) { |
|
| 86 | + $GLOBALS[$table][$row['nom']] = $row['valeur']; |
|
| 87 | + } |
|
| 88 | + sql_free($result); |
|
| 89 | 89 | |
| 90 | - if ( |
|
| 91 | - !isset($GLOBALS[$table]['charset']) |
|
| 92 | - or !$GLOBALS[$table]['charset'] |
|
| 93 | - or $GLOBALS[$table]['charset'] == '_DEFAULT_CHARSET' // hum, correction d'un bug ayant abime quelques install |
|
| 94 | - ) { |
|
| 95 | - ecrire_meta('charset', _DEFAULT_CHARSET, null, $table); |
|
| 96 | - } |
|
| 90 | + if ( |
|
| 91 | + !isset($GLOBALS[$table]['charset']) |
|
| 92 | + or !$GLOBALS[$table]['charset'] |
|
| 93 | + or $GLOBALS[$table]['charset'] == '_DEFAULT_CHARSET' // hum, correction d'un bug ayant abime quelques install |
|
| 94 | + ) { |
|
| 95 | + ecrire_meta('charset', _DEFAULT_CHARSET, null, $table); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - // noter cette table de configuration dans les meta de SPIP |
|
| 99 | - if ($table !== 'meta') { |
|
| 100 | - $liste = []; |
|
| 101 | - if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 102 | - $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 103 | - } |
|
| 104 | - if (!$liste) { |
|
| 105 | - $liste = []; |
|
| 106 | - } |
|
| 107 | - if (!in_array($table, $liste)) { |
|
| 108 | - $liste[] = $table; |
|
| 109 | - ecrire_meta('tables_config', serialize($liste)); |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - } |
|
| 98 | + // noter cette table de configuration dans les meta de SPIP |
|
| 99 | + if ($table !== 'meta') { |
|
| 100 | + $liste = []; |
|
| 101 | + if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 102 | + $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 103 | + } |
|
| 104 | + if (!$liste) { |
|
| 105 | + $liste = []; |
|
| 106 | + } |
|
| 107 | + if (!in_array($table, $liste)) { |
|
| 108 | + $liste[] = $table; |
|
| 109 | + ecrire_meta('tables_config', serialize($liste)); |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - return $GLOBALS[$table] ?? null; |
|
| 114 | + return $GLOBALS[$table] ?? null; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
@@ -125,22 +125,22 @@ discard block |
||
| 125 | 125 | * Table SQL d'enregistrement des meta. |
| 126 | 126 | **/ |
| 127 | 127 | function touch_meta($antidate = false, $table = 'meta') { |
| 128 | - $file = cache_meta($table); |
|
| 129 | - if (!$antidate or !@touch($file, $antidate)) { |
|
| 130 | - $r = $GLOBALS[$table] ?? []; |
|
| 131 | - if ($table == 'meta') { |
|
| 132 | - unset($r['alea_ephemere']); |
|
| 133 | - unset($r['alea_ephemere_ancien']); |
|
| 134 | - // le secret du site est utilise pour encoder les contextes ajax que l'on considere fiables |
|
| 135 | - // mais le sortir deu cache meta implique une requete sql des qu'on a un form dynamique |
|
| 136 | - // meme si son squelette est en cache |
|
| 137 | - //unset($r['secret_du_site']); |
|
| 138 | - if ($antidate) { |
|
| 139 | - $r['touch'] = $antidate; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - ecrire_fichier_securise($file, serialize($r)); |
|
| 143 | - } |
|
| 128 | + $file = cache_meta($table); |
|
| 129 | + if (!$antidate or !@touch($file, $antidate)) { |
|
| 130 | + $r = $GLOBALS[$table] ?? []; |
|
| 131 | + if ($table == 'meta') { |
|
| 132 | + unset($r['alea_ephemere']); |
|
| 133 | + unset($r['alea_ephemere_ancien']); |
|
| 134 | + // le secret du site est utilise pour encoder les contextes ajax que l'on considere fiables |
|
| 135 | + // mais le sortir deu cache meta implique une requete sql des qu'on a un form dynamique |
|
| 136 | + // meme si son squelette est en cache |
|
| 137 | + //unset($r['secret_du_site']); |
|
| 138 | + if ($antidate) { |
|
| 139 | + $r['touch'] = $antidate; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + ecrire_fichier_securise($file, serialize($r)); |
|
| 143 | + } |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -156,21 +156,21 @@ discard block |
||
| 156 | 156 | * Table SQL d'enregistrement de la meta. |
| 157 | 157 | **/ |
| 158 | 158 | function effacer_meta($nom, $table = 'meta') { |
| 159 | - // section critique sur le cache: |
|
| 160 | - // l'invalider avant et apres la MAJ de la BD |
|
| 161 | - // c'est un peu moins bien qu'un vrai verrou mais ca suffira |
|
| 162 | - // et utiliser une statique pour eviter des acces disques a repetition |
|
| 163 | - static $touch = []; |
|
| 164 | - $antidate = time() - (_META_CACHE_TIME << 4); |
|
| 165 | - if (!isset($touch[$table])) { |
|
| 166 | - touch_meta($antidate, $table); |
|
| 167 | - } |
|
| 168 | - sql_delete('spip_' . $table, "nom='$nom'", '', 'continue'); |
|
| 169 | - unset($GLOBALS[$table][$nom]); |
|
| 170 | - if (!isset($touch[$table])) { |
|
| 171 | - touch_meta($antidate, $table); |
|
| 172 | - $touch[$table] = false; |
|
| 173 | - } |
|
| 159 | + // section critique sur le cache: |
|
| 160 | + // l'invalider avant et apres la MAJ de la BD |
|
| 161 | + // c'est un peu moins bien qu'un vrai verrou mais ca suffira |
|
| 162 | + // et utiliser une statique pour eviter des acces disques a repetition |
|
| 163 | + static $touch = []; |
|
| 164 | + $antidate = time() - (_META_CACHE_TIME << 4); |
|
| 165 | + if (!isset($touch[$table])) { |
|
| 166 | + touch_meta($antidate, $table); |
|
| 167 | + } |
|
| 168 | + sql_delete('spip_' . $table, "nom='$nom'", '', 'continue'); |
|
| 169 | + unset($GLOBALS[$table][$nom]); |
|
| 170 | + if (!isset($touch[$table])) { |
|
| 171 | + touch_meta($antidate, $table); |
|
| 172 | + $touch[$table] = false; |
|
| 173 | + } |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -191,53 +191,53 @@ discard block |
||
| 191 | 191 | **/ |
| 192 | 192 | function ecrire_meta($nom, $valeur, $importable = null, $table = 'meta') { |
| 193 | 193 | |
| 194 | - static $touch = []; |
|
| 195 | - if (!$nom) { |
|
| 196 | - return; |
|
| 197 | - } |
|
| 198 | - include_spip('base/abstract_sql'); |
|
| 199 | - $res = sql_select('*', 'spip_' . $table, 'nom=' . sql_quote($nom), '', '', '', '', '', 'continue'); |
|
| 200 | - // table pas encore installee, travailler en php seulement |
|
| 201 | - if (!$res) { |
|
| 202 | - $GLOBALS[$table][$nom] = $valeur; |
|
| 194 | + static $touch = []; |
|
| 195 | + if (!$nom) { |
|
| 196 | + return; |
|
| 197 | + } |
|
| 198 | + include_spip('base/abstract_sql'); |
|
| 199 | + $res = sql_select('*', 'spip_' . $table, 'nom=' . sql_quote($nom), '', '', '', '', '', 'continue'); |
|
| 200 | + // table pas encore installee, travailler en php seulement |
|
| 201 | + if (!$res) { |
|
| 202 | + $GLOBALS[$table][$nom] = $valeur; |
|
| 203 | 203 | |
| 204 | - return; |
|
| 205 | - } |
|
| 206 | - $row = sql_fetch($res); |
|
| 207 | - sql_free($res); |
|
| 204 | + return; |
|
| 205 | + } |
|
| 206 | + $row = sql_fetch($res); |
|
| 207 | + sql_free($res); |
|
| 208 | 208 | |
| 209 | - // ne pas invalider le cache si affectation a l'identique |
|
| 210 | - // (tant pis si impt aurait du changer) |
|
| 211 | - if ( |
|
| 212 | - $row and $valeur == $row['valeur'] |
|
| 213 | - and isset($GLOBALS[$table][$nom]) |
|
| 214 | - and $GLOBALS[$table][$nom] == $valeur |
|
| 215 | - ) { |
|
| 216 | - return; |
|
| 217 | - } |
|
| 209 | + // ne pas invalider le cache si affectation a l'identique |
|
| 210 | + // (tant pis si impt aurait du changer) |
|
| 211 | + if ( |
|
| 212 | + $row and $valeur == $row['valeur'] |
|
| 213 | + and isset($GLOBALS[$table][$nom]) |
|
| 214 | + and $GLOBALS[$table][$nom] == $valeur |
|
| 215 | + ) { |
|
| 216 | + return; |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - $GLOBALS[$table][$nom] = $valeur; |
|
| 220 | - // cf effacer pour comprendre le double touch |
|
| 221 | - $antidate = time() - (_META_CACHE_TIME << 1); |
|
| 222 | - if (!isset($touch[$table])) { |
|
| 223 | - touch_meta($antidate, $table); |
|
| 224 | - } |
|
| 225 | - $r = ['nom' => sql_quote($nom, '', 'text'), 'valeur' => sql_quote($valeur, '', 'text')]; |
|
| 226 | - // Gaffe aux tables sans impt (vieilles versions de SPIP notamment) |
|
| 227 | - // ici on utilise pas sql_updateq et sql_insertq pour ne pas provoquer trop tot |
|
| 228 | - // de lecture des descriptions des tables |
|
| 229 | - if ($importable and isset($row['impt'])) { |
|
| 230 | - $r['impt'] = sql_quote($importable, '', 'text'); |
|
| 231 | - } |
|
| 232 | - if ($row) { |
|
| 233 | - sql_update('spip_' . $table, $r, 'nom=' . sql_quote($nom)); |
|
| 234 | - } else { |
|
| 235 | - sql_insert('spip_' . $table, '(' . join(',', array_keys($r)) . ')', '(' . join(',', array_values($r)) . ')'); |
|
| 236 | - } |
|
| 237 | - if (!isset($touch[$table])) { |
|
| 238 | - touch_meta($antidate, $table); |
|
| 239 | - $touch[$table] = false; |
|
| 240 | - } |
|
| 219 | + $GLOBALS[$table][$nom] = $valeur; |
|
| 220 | + // cf effacer pour comprendre le double touch |
|
| 221 | + $antidate = time() - (_META_CACHE_TIME << 1); |
|
| 222 | + if (!isset($touch[$table])) { |
|
| 223 | + touch_meta($antidate, $table); |
|
| 224 | + } |
|
| 225 | + $r = ['nom' => sql_quote($nom, '', 'text'), 'valeur' => sql_quote($valeur, '', 'text')]; |
|
| 226 | + // Gaffe aux tables sans impt (vieilles versions de SPIP notamment) |
|
| 227 | + // ici on utilise pas sql_updateq et sql_insertq pour ne pas provoquer trop tot |
|
| 228 | + // de lecture des descriptions des tables |
|
| 229 | + if ($importable and isset($row['impt'])) { |
|
| 230 | + $r['impt'] = sql_quote($importable, '', 'text'); |
|
| 231 | + } |
|
| 232 | + if ($row) { |
|
| 233 | + sql_update('spip_' . $table, $r, 'nom=' . sql_quote($nom)); |
|
| 234 | + } else { |
|
| 235 | + sql_insert('spip_' . $table, '(' . join(',', array_keys($r)) . ')', '(' . join(',', array_values($r)) . ')'); |
|
| 236 | + } |
|
| 237 | + if (!isset($touch[$table])) { |
|
| 238 | + touch_meta($antidate, $table); |
|
| 239 | + $touch[$table] = false; |
|
| 240 | + } |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | /** |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | * Nom du fichier cache |
| 250 | 250 | **/ |
| 251 | 251 | function cache_meta($table = 'meta') { |
| 252 | - return ($table == 'meta') ? _FILE_META : (_DIR_CACHE . $table . '.php'); |
|
| 252 | + return ($table == 'meta') ? _FILE_META : (_DIR_CACHE . $table . '.php'); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -258,14 +258,14 @@ discard block |
||
| 258 | 258 | * @param string $table |
| 259 | 259 | */ |
| 260 | 260 | function installer_table_meta($table) { |
| 261 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 262 | - if (!$trouver_table("spip_$table")) { |
|
| 263 | - include_spip('base/auxiliaires'); |
|
| 264 | - include_spip('base/create'); |
|
| 265 | - creer_ou_upgrader_table("spip_$table", $GLOBALS['tables_auxiliaires']['spip_meta'], false, false); |
|
| 266 | - $trouver_table(''); |
|
| 267 | - } |
|
| 268 | - lire_metas($table); |
|
| 261 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 262 | + if (!$trouver_table("spip_$table")) { |
|
| 263 | + include_spip('base/auxiliaires'); |
|
| 264 | + include_spip('base/create'); |
|
| 265 | + creer_ou_upgrader_table("spip_$table", $GLOBALS['tables_auxiliaires']['spip_meta'], false, false); |
|
| 266 | + $trouver_table(''); |
|
| 267 | + } |
|
| 268 | + lire_metas($table); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -277,47 +277,47 @@ discard block |
||
| 277 | 277 | * @param bool $force |
| 278 | 278 | */ |
| 279 | 279 | function supprimer_table_meta($table, $force = false) { |
| 280 | - if ($table !== 'meta') { |
|
| 281 | - // Vérifier le contenu restant de la table |
|
| 282 | - $nb_variables = sql_countsel("spip_$table"); |
|
| 280 | + if ($table !== 'meta') { |
|
| 281 | + // Vérifier le contenu restant de la table |
|
| 282 | + $nb_variables = sql_countsel("spip_$table"); |
|
| 283 | 283 | |
| 284 | - // Supprimer si : |
|
| 285 | - // - la table est vide |
|
| 286 | - // - ou limitée à la variable charset |
|
| 287 | - // - ou qu'on force la suppression |
|
| 288 | - if ( |
|
| 289 | - $force |
|
| 290 | - or !$nb_variables |
|
| 291 | - or ( |
|
| 292 | - ($nb_variables == 1) |
|
| 293 | - and isset($GLOBALS[$table]['charset']) |
|
| 294 | - ) |
|
| 295 | - ) { |
|
| 296 | - // Supprimer la table des globaleset de la base |
|
| 297 | - unset($GLOBALS[$table]); |
|
| 298 | - sql_drop_table("spip_$table"); |
|
| 299 | - // Supprimer le fichier cache |
|
| 300 | - include_spip('inc/flock'); |
|
| 301 | - $cache = cache_meta($table); |
|
| 302 | - supprimer_fichier($cache); |
|
| 284 | + // Supprimer si : |
|
| 285 | + // - la table est vide |
|
| 286 | + // - ou limitée à la variable charset |
|
| 287 | + // - ou qu'on force la suppression |
|
| 288 | + if ( |
|
| 289 | + $force |
|
| 290 | + or !$nb_variables |
|
| 291 | + or ( |
|
| 292 | + ($nb_variables == 1) |
|
| 293 | + and isset($GLOBALS[$table]['charset']) |
|
| 294 | + ) |
|
| 295 | + ) { |
|
| 296 | + // Supprimer la table des globaleset de la base |
|
| 297 | + unset($GLOBALS[$table]); |
|
| 298 | + sql_drop_table("spip_$table"); |
|
| 299 | + // Supprimer le fichier cache |
|
| 300 | + include_spip('inc/flock'); |
|
| 301 | + $cache = cache_meta($table); |
|
| 302 | + supprimer_fichier($cache); |
|
| 303 | 303 | |
| 304 | - // vider le cache des tables |
|
| 305 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 306 | - $trouver_table(''); |
|
| 304 | + // vider le cache des tables |
|
| 305 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 306 | + $trouver_table(''); |
|
| 307 | 307 | |
| 308 | - // Supprimer la table de la liste des tables de configuration autres que spip_meta |
|
| 309 | - if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 310 | - $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 311 | - $cle = array_search($table, $liste); |
|
| 312 | - if ($cle !== false) { |
|
| 313 | - unset($liste[$cle]); |
|
| 314 | - if ($liste) { |
|
| 315 | - ecrire_meta('tables_config', serialize($liste)); |
|
| 316 | - } else { |
|
| 317 | - effacer_meta('tables_config'); |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - } |
|
| 308 | + // Supprimer la table de la liste des tables de configuration autres que spip_meta |
|
| 309 | + if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 310 | + $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 311 | + $cle = array_search($table, $liste); |
|
| 312 | + if ($cle !== false) { |
|
| 313 | + unset($liste[$cle]); |
|
| 314 | + if ($liste) { |
|
| 315 | + ecrire_meta('tables_config', serialize($liste)); |
|
| 316 | + } else { |
|
| 317 | + effacer_meta('tables_config'); |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | 323 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Les fonctions de toggg pour faire du JSON |
@@ -25,63 +25,63 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | function var2js($var) { |
| 28 | - $asso = false; |
|
| 29 | - switch (true) { |
|
| 30 | - case is_null($var): |
|
| 31 | - return 'null'; |
|
| 32 | - case is_string($var): |
|
| 33 | - return '"' . addcslashes($var, "\"\\\n\r/") . '"'; |
|
| 34 | - case is_bool($var): |
|
| 35 | - return $var ? 'true' : 'false'; |
|
| 36 | - case is_scalar($var): |
|
| 37 | - return (string)$var; |
|
| 38 | - case is_object($var):// blam |
|
| 39 | - $var = get_object_vars($var); |
|
| 40 | - $asso = true; |
|
| 41 | - // $var devient un array, on continue |
|
| 42 | - case is_array($var): |
|
| 43 | - $keys = array_keys($var); |
|
| 44 | - $ikey = count($keys); |
|
| 45 | - while (!$asso && $ikey--) { |
|
| 46 | - $asso = $ikey !== $keys[$ikey]; |
|
| 47 | - } |
|
| 48 | - $sep = ''; |
|
| 49 | - if ($asso) { |
|
| 50 | - $ret = '{'; |
|
| 51 | - foreach ($var as $key => $elt) { |
|
| 52 | - $ret .= $sep . '"' . $key . '":' . var2js($elt); |
|
| 53 | - $sep = ','; |
|
| 54 | - } |
|
| 28 | + $asso = false; |
|
| 29 | + switch (true) { |
|
| 30 | + case is_null($var): |
|
| 31 | + return 'null'; |
|
| 32 | + case is_string($var): |
|
| 33 | + return '"' . addcslashes($var, "\"\\\n\r/") . '"'; |
|
| 34 | + case is_bool($var): |
|
| 35 | + return $var ? 'true' : 'false'; |
|
| 36 | + case is_scalar($var): |
|
| 37 | + return (string)$var; |
|
| 38 | + case is_object($var):// blam |
|
| 39 | + $var = get_object_vars($var); |
|
| 40 | + $asso = true; |
|
| 41 | + // $var devient un array, on continue |
|
| 42 | + case is_array($var): |
|
| 43 | + $keys = array_keys($var); |
|
| 44 | + $ikey = count($keys); |
|
| 45 | + while (!$asso && $ikey--) { |
|
| 46 | + $asso = $ikey !== $keys[$ikey]; |
|
| 47 | + } |
|
| 48 | + $sep = ''; |
|
| 49 | + if ($asso) { |
|
| 50 | + $ret = '{'; |
|
| 51 | + foreach ($var as $key => $elt) { |
|
| 52 | + $ret .= $sep . '"' . $key . '":' . var2js($elt); |
|
| 53 | + $sep = ','; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return $ret . '}'; |
|
| 57 | - } else { |
|
| 58 | - $ret = '['; |
|
| 59 | - foreach ($var as $elt) { |
|
| 60 | - $ret .= $sep . var2js($elt); |
|
| 61 | - $sep = ','; |
|
| 62 | - } |
|
| 56 | + return $ret . '}'; |
|
| 57 | + } else { |
|
| 58 | + $ret = '['; |
|
| 59 | + foreach ($var as $elt) { |
|
| 60 | + $ret .= $sep . var2js($elt); |
|
| 61 | + $sep = ','; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - return $ret . ']'; |
|
| 65 | - } |
|
| 66 | - } |
|
| 64 | + return $ret . ']'; |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - return false; |
|
| 68 | + return false; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | if (!function_exists('json_encode')) { |
| 72 | - function json_encode($v) { |
|
| 73 | - return var2js($v); |
|
| 74 | - } |
|
| 72 | + function json_encode($v) { |
|
| 73 | + return var2js($v); |
|
| 74 | + } |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | function json_export($var) { |
| 78 | - $var = json_encode($var, JSON_THROW_ON_ERROR); |
|
| 78 | + $var = json_encode($var, JSON_THROW_ON_ERROR); |
|
| 79 | 79 | |
| 80 | - // flag indiquant qu'on est en iframe et qu'il faut proteger nos |
|
| 81 | - // donnees dans un <textarea> ; attention $_FILES a ete vide par array_pop |
|
| 82 | - if (defined('FILE_UPLOAD')) { |
|
| 83 | - return '<textarea>' . spip_htmlspecialchars($var) . '</textarea>'; |
|
| 84 | - } else { |
|
| 85 | - return $var; |
|
| 86 | - } |
|
| 80 | + // flag indiquant qu'on est en iframe et qu'il faut proteger nos |
|
| 81 | + // donnees dans un <textarea> ; attention $_FILES a ete vide par array_pop |
|
| 82 | + if (defined('FILE_UPLOAD')) { |
|
| 83 | + return '<textarea>' . spip_htmlspecialchars($var) . '</textarea>'; |
|
| 84 | + } else { |
|
| 85 | + return $var; |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -75,28 +75,28 @@ discard block |
||
| 75 | 75 | * @return |
| 76 | 76 | **/ |
| 77 | 77 | function inc_genie_dist($taches = []) { |
| 78 | - include_spip('inc/queue'); |
|
| 79 | - |
|
| 80 | - if (_request('exec') == 'job_queue') { |
|
| 81 | - return false; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - $force_jobs = []; |
|
| 85 | - // l'ancienne facon de lancer une tache cron immediatement |
|
| 86 | - // etait de la passer en parametre a ing_genie_dist |
|
| 87 | - // on reroute en ajoutant simplement le job a la queue, ASAP |
|
| 88 | - foreach ($taches as $function => $period) { |
|
| 89 | - $force_jobs[] = queue_add_job( |
|
| 90 | - $function, |
|
| 91 | - _T('tache_cron_asap', ['function' => $function]), |
|
| 92 | - [time() - abs($period)], |
|
| 93 | - 'genie/' |
|
| 94 | - ); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // et on passe la main a la gestion de la queue ! |
|
| 98 | - // en forcant eventuellement les jobs ajoute a l'instant |
|
| 99 | - return queue_schedule(count($force_jobs) ? $force_jobs : null); |
|
| 78 | + include_spip('inc/queue'); |
|
| 79 | + |
|
| 80 | + if (_request('exec') == 'job_queue') { |
|
| 81 | + return false; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $force_jobs = []; |
|
| 85 | + // l'ancienne facon de lancer une tache cron immediatement |
|
| 86 | + // etait de la passer en parametre a ing_genie_dist |
|
| 87 | + // on reroute en ajoutant simplement le job a la queue, ASAP |
|
| 88 | + foreach ($taches as $function => $period) { |
|
| 89 | + $force_jobs[] = queue_add_job( |
|
| 90 | + $function, |
|
| 91 | + _T('tache_cron_asap', ['function' => $function]), |
|
| 92 | + [time() - abs($period)], |
|
| 93 | + 'genie/' |
|
| 94 | + ); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // et on passe la main a la gestion de la queue ! |
|
| 98 | + // en forcant eventuellement les jobs ajoute a l'instant |
|
| 99 | + return queue_schedule(count($force_jobs) ? $force_jobs : null); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | // |
@@ -109,33 +109,33 @@ discard block |
||
| 109 | 109 | // |
| 110 | 110 | function taches_generales($taches_generales = []) { |
| 111 | 111 | |
| 112 | - // verifier que toutes les taches cron sont planifiees |
|
| 113 | - // c'est une tache cron ! |
|
| 114 | - $taches_generales['queue_watch'] = 3600 * 24; |
|
| 112 | + // verifier que toutes les taches cron sont planifiees |
|
| 113 | + // c'est une tache cron ! |
|
| 114 | + $taches_generales['queue_watch'] = 3600 * 24; |
|
| 115 | 115 | |
| 116 | - // MAJ des rubriques publiques (cas de la publication post-datee) |
|
| 117 | - // est fait au coup par coup a present |
|
| 118 | - // $taches_generales['rubriques'] = 3600; |
|
| 116 | + // MAJ des rubriques publiques (cas de la publication post-datee) |
|
| 117 | + // est fait au coup par coup a present |
|
| 118 | + // $taches_generales['rubriques'] = 3600; |
|
| 119 | 119 | |
| 120 | - // Optimisation de la base |
|
| 121 | - $taches_generales['optimiser'] = 3600 * 48; |
|
| 120 | + // Optimisation de la base |
|
| 121 | + $taches_generales['optimiser'] = 3600 * 48; |
|
| 122 | 122 | |
| 123 | - // nouveautes |
|
| 124 | - if ( |
|
| 125 | - isset($GLOBALS['meta']['adresse_neuf']) and $GLOBALS['meta']['adresse_neuf'] |
|
| 126 | - and $GLOBALS['meta']['jours_neuf'] |
|
| 127 | - and ($GLOBALS['meta']['quoi_de_neuf'] == 'oui') |
|
| 128 | - ) { |
|
| 129 | - $taches_generales['mail'] = 3600 * 24 * $GLOBALS['meta']['jours_neuf']; |
|
| 130 | - } |
|
| 123 | + // nouveautes |
|
| 124 | + if ( |
|
| 125 | + isset($GLOBALS['meta']['adresse_neuf']) and $GLOBALS['meta']['adresse_neuf'] |
|
| 126 | + and $GLOBALS['meta']['jours_neuf'] |
|
| 127 | + and ($GLOBALS['meta']['quoi_de_neuf'] == 'oui') |
|
| 128 | + ) { |
|
| 129 | + $taches_generales['mail'] = 3600 * 24 * $GLOBALS['meta']['jours_neuf']; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - // maintenance (ajax, verifications diverses) |
|
| 133 | - $taches_generales['maintenance'] = 3600 * 2; |
|
| 132 | + // maintenance (ajax, verifications diverses) |
|
| 133 | + $taches_generales['maintenance'] = 3600 * 2; |
|
| 134 | 134 | |
| 135 | - // verifier si une mise a jour de spip est disponible (2 fois par semaine suffit largement) |
|
| 136 | - $taches_generales['mise_a_jour'] = 3 * 24 * 3600; |
|
| 135 | + // verifier si une mise a jour de spip est disponible (2 fois par semaine suffit largement) |
|
| 136 | + $taches_generales['mise_a_jour'] = 3 * 24 * 3600; |
|
| 137 | 137 | |
| 138 | - return pipeline('taches_generales_cron', $taches_generales); |
|
| 138 | + return pipeline('taches_generales_cron', $taches_generales); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -151,22 +151,22 @@ discard block |
||
| 151 | 151 | * @return int |
| 152 | 152 | */ |
| 153 | 153 | function genie_queue_watch_dist() { |
| 154 | - static $deja_la = false; |
|
| 155 | - if ($deja_la) { |
|
| 156 | - return; |
|
| 157 | - } // re-entrance si l'insertion des jobs echoue (pas de table spip_jobs a l'upgrade par exemple) |
|
| 158 | - $deja_la = true; |
|
| 159 | - $taches = taches_generales(); |
|
| 160 | - $programmees = sql_allfetsel('fonction', 'spip_jobs', sql_in('fonction', array_keys($taches))); |
|
| 161 | - $programmees = array_column($programmees, 'fonction'); |
|
| 162 | - foreach ($taches as $tache => $periode) { |
|
| 163 | - if (!in_array($tache, $programmees)) { |
|
| 164 | - queue_genie_replan_job($tache, $periode, time() - round(random_int(1, $periode)), 0); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - $deja_la = false; |
|
| 168 | - |
|
| 169 | - return 1; |
|
| 154 | + static $deja_la = false; |
|
| 155 | + if ($deja_la) { |
|
| 156 | + return; |
|
| 157 | + } // re-entrance si l'insertion des jobs echoue (pas de table spip_jobs a l'upgrade par exemple) |
|
| 158 | + $deja_la = true; |
|
| 159 | + $taches = taches_generales(); |
|
| 160 | + $programmees = sql_allfetsel('fonction', 'spip_jobs', sql_in('fonction', array_keys($taches))); |
|
| 161 | + $programmees = array_column($programmees, 'fonction'); |
|
| 162 | + foreach ($taches as $tache => $periode) { |
|
| 163 | + if (!in_array($tache, $programmees)) { |
|
| 164 | + queue_genie_replan_job($tache, $periode, time() - round(random_int(1, $periode)), 0); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + $deja_la = false; |
|
| 168 | + |
|
| 169 | + return 1; |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
@@ -187,32 +187,32 @@ discard block |
||
| 187 | 187 | * @return void |
| 188 | 188 | */ |
| 189 | 189 | function queue_genie_replan_job($function, $period, $last = 0, $time = null, $priority = 0) { |
| 190 | - static $done = []; |
|
| 191 | - if (isset($done[$function])) { |
|
| 192 | - return; |
|
| 193 | - } |
|
| 194 | - $done[$function] = true; |
|
| 195 | - if (is_null($time)) { |
|
| 196 | - $time = time(); |
|
| 197 | - if ($last) { |
|
| 198 | - $time = max($last + $period, $time); |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - if (!$last) { |
|
| 202 | - $last = $time - $period; |
|
| 203 | - } |
|
| 204 | - spip_log("replan_job $function $period $last $time $priority", 'queue'); |
|
| 205 | - include_spip('inc/queue'); |
|
| 206 | - // on replanifie un job cron |
|
| 207 | - // uniquement si il n'y en a pas deja un avec le meme nom |
|
| 208 | - // independament de l'argument |
|
| 209 | - queue_add_job( |
|
| 210 | - $function, |
|
| 211 | - _T('tache_cron_secondes', ['function' => $function, 'nb' => $period]), |
|
| 212 | - [$last], |
|
| 213 | - 'genie/', |
|
| 214 | - 'function_only', |
|
| 215 | - $time, |
|
| 216 | - $priority |
|
| 217 | - ); |
|
| 190 | + static $done = []; |
|
| 191 | + if (isset($done[$function])) { |
|
| 192 | + return; |
|
| 193 | + } |
|
| 194 | + $done[$function] = true; |
|
| 195 | + if (is_null($time)) { |
|
| 196 | + $time = time(); |
|
| 197 | + if ($last) { |
|
| 198 | + $time = max($last + $period, $time); |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + if (!$last) { |
|
| 202 | + $last = $time - $period; |
|
| 203 | + } |
|
| 204 | + spip_log("replan_job $function $period $last $time $priority", 'queue'); |
|
| 205 | + include_spip('inc/queue'); |
|
| 206 | + // on replanifie un job cron |
|
| 207 | + // uniquement si il n'y en a pas deja un avec le meme nom |
|
| 208 | + // independament de l'argument |
|
| 209 | + queue_add_job( |
|
| 210 | + $function, |
|
| 211 | + _T('tache_cron_secondes', ['function' => $function, 'nb' => $period]), |
|
| 212 | + [$last], |
|
| 213 | + 'genie/', |
|
| 214 | + 'function_only', |
|
| 215 | + $time, |
|
| 216 | + $priority |
|
| 217 | + ); |
|
| 218 | 218 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('base/serial'); |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * en droit de l'éliminer |
| 28 | 28 | */ |
| 29 | 29 | if (!defined('_AGE_CACHE_ATIME')) { |
| 30 | - define('_AGE_CACHE_ATIME', 3600); |
|
| 30 | + define('_AGE_CACHE_ATIME', 3600); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
@@ -40,31 +40,31 @@ discard block |
||
| 40 | 40 | * @return int Taille approximative en octets |
| 41 | 41 | **/ |
| 42 | 42 | function taille_du_cache() { |
| 43 | - # check dirs until we reach > 500 files |
|
| 44 | - $t = 0; |
|
| 45 | - $n = 0; |
|
| 46 | - $time = $GLOBALS['meta']['cache_mark'] ?? 0; |
|
| 47 | - for ($i = 0; $i < 256; $i++) { |
|
| 48 | - $dir = _DIR_CACHE . sprintf('%02s', dechex($i)); |
|
| 49 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 50 | - while (($f = readdir($d)) !== false) { |
|
| 51 | - if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) { |
|
| 52 | - $n++; |
|
| 53 | - if ($a['mtime'] >= $time) { |
|
| 54 | - if ($a['blocks'] > 0) { |
|
| 55 | - $t += 512 * $a['blocks']; |
|
| 56 | - } else { |
|
| 57 | - $t += $a['size']; |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - if ($n > 500) { |
|
| 64 | - return intval(256 * $t / (1 + $i)); |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - return $t; |
|
| 43 | + # check dirs until we reach > 500 files |
|
| 44 | + $t = 0; |
|
| 45 | + $n = 0; |
|
| 46 | + $time = $GLOBALS['meta']['cache_mark'] ?? 0; |
|
| 47 | + for ($i = 0; $i < 256; $i++) { |
|
| 48 | + $dir = _DIR_CACHE . sprintf('%02s', dechex($i)); |
|
| 49 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 50 | + while (($f = readdir($d)) !== false) { |
|
| 51 | + if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) { |
|
| 52 | + $n++; |
|
| 53 | + if ($a['mtime'] >= $time) { |
|
| 54 | + if ($a['blocks'] > 0) { |
|
| 55 | + $t += 512 * $a['blocks']; |
|
| 56 | + } else { |
|
| 57 | + $t += $a['size']; |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + if ($n > 500) { |
|
| 64 | + return intval(256 * $t / (1 + $i)); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + return $t; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | |
@@ -91,30 +91,30 @@ discard block |
||
| 91 | 91 | * Inutilisé |
| 92 | 92 | **/ |
| 93 | 93 | function inc_suivre_invalideur_dist($cond, $modif = true) { |
| 94 | - if (!$modif) { |
|
| 95 | - return; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - // determiner l'objet modifie : forum, article, etc |
|
| 99 | - if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) { |
|
| 100 | - $objet = objet_type($r[1]); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // stocker la date_modif_$objet (ne sert a rien pour le moment) |
|
| 104 | - if (isset($objet)) { |
|
| 105 | - ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // si $derniere_modif_invalide est un array('article', 'rubrique') |
|
| 109 | - // n'affecter la meta que si un de ces objets est modifie |
|
| 110 | - if (is_array($GLOBALS['derniere_modif_invalide'])) { |
|
| 111 | - if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) { |
|
| 112 | - ecrire_meta('derniere_modif', time()); |
|
| 113 | - } |
|
| 114 | - } // sinon, cas standard, toujours affecter la meta |
|
| 115 | - else { |
|
| 116 | - ecrire_meta('derniere_modif', time()); |
|
| 117 | - } |
|
| 94 | + if (!$modif) { |
|
| 95 | + return; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + // determiner l'objet modifie : forum, article, etc |
|
| 99 | + if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) { |
|
| 100 | + $objet = objet_type($r[1]); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // stocker la date_modif_$objet (ne sert a rien pour le moment) |
|
| 104 | + if (isset($objet)) { |
|
| 105 | + ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // si $derniere_modif_invalide est un array('article', 'rubrique') |
|
| 109 | + // n'affecter la meta que si un de ces objets est modifie |
|
| 110 | + if (is_array($GLOBALS['derniere_modif_invalide'])) { |
|
| 111 | + if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) { |
|
| 112 | + ecrire_meta('derniere_modif', time()); |
|
| 113 | + } |
|
| 114 | + } // sinon, cas standard, toujours affecter la meta |
|
| 115 | + else { |
|
| 116 | + ecrire_meta('derniere_modif', time()); |
|
| 117 | + } |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -139,57 +139,57 @@ discard block |
||
| 139 | 139 | * Nombre de fichiers supprimés |
| 140 | 140 | **/ |
| 141 | 141 | function purger_repertoire($dir, $options = []) { |
| 142 | - if (!is_dir($dir) or !is_readable($dir)) { |
|
| 143 | - return 0; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - // sur certains sites on veut absolument garder certains caches référencés dans un CDN |
|
| 147 | - // on peut donc inhiber la purge de ces répertoires pour eviter tout probleme |
|
| 148 | - if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) { |
|
| 149 | - return 0; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - $handle = opendir($dir); |
|
| 153 | - if (!$handle) { |
|
| 154 | - return 0; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - $total = 0; |
|
| 158 | - |
|
| 159 | - while (($fichier = @readdir($handle)) !== false) { |
|
| 160 | - // Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG |
|
| 161 | - if ($fichier[0] == '.' or $fichier == 'CACHEDIR.TAG') { |
|
| 162 | - continue; |
|
| 163 | - } |
|
| 164 | - $chemin = "$dir/$fichier"; |
|
| 165 | - if (is_file($chemin)) { |
|
| 166 | - if ( |
|
| 167 | - (!isset($options['atime']) or (@fileatime($chemin) < $options['atime'])) |
|
| 168 | - and (!isset($options['mtime']) or (@filemtime($chemin) < $options['mtime'])) |
|
| 169 | - ) { |
|
| 170 | - supprimer_fichier($chemin); |
|
| 171 | - $total++; |
|
| 172 | - } |
|
| 173 | - } else { |
|
| 174 | - if (is_dir($chemin)) { |
|
| 175 | - $opts = $options; |
|
| 176 | - if (isset($options['limit'])) { |
|
| 177 | - $opts['limit'] = $options['limit'] - $total; |
|
| 178 | - } |
|
| 179 | - $total += purger_repertoire($chemin, $opts); |
|
| 180 | - if (isset($options['subdir']) && $options['subdir']) { |
|
| 181 | - spip_unlink($chemin); |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - if (isset($options['limit']) and $total >= $options['limit']) { |
|
| 187 | - break; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - closedir($handle); |
|
| 191 | - |
|
| 192 | - return $total; |
|
| 142 | + if (!is_dir($dir) or !is_readable($dir)) { |
|
| 143 | + return 0; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + // sur certains sites on veut absolument garder certains caches référencés dans un CDN |
|
| 147 | + // on peut donc inhiber la purge de ces répertoires pour eviter tout probleme |
|
| 148 | + if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) { |
|
| 149 | + return 0; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + $handle = opendir($dir); |
|
| 153 | + if (!$handle) { |
|
| 154 | + return 0; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + $total = 0; |
|
| 158 | + |
|
| 159 | + while (($fichier = @readdir($handle)) !== false) { |
|
| 160 | + // Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG |
|
| 161 | + if ($fichier[0] == '.' or $fichier == 'CACHEDIR.TAG') { |
|
| 162 | + continue; |
|
| 163 | + } |
|
| 164 | + $chemin = "$dir/$fichier"; |
|
| 165 | + if (is_file($chemin)) { |
|
| 166 | + if ( |
|
| 167 | + (!isset($options['atime']) or (@fileatime($chemin) < $options['atime'])) |
|
| 168 | + and (!isset($options['mtime']) or (@filemtime($chemin) < $options['mtime'])) |
|
| 169 | + ) { |
|
| 170 | + supprimer_fichier($chemin); |
|
| 171 | + $total++; |
|
| 172 | + } |
|
| 173 | + } else { |
|
| 174 | + if (is_dir($chemin)) { |
|
| 175 | + $opts = $options; |
|
| 176 | + if (isset($options['limit'])) { |
|
| 177 | + $opts['limit'] = $options['limit'] - $total; |
|
| 178 | + } |
|
| 179 | + $total += purger_repertoire($chemin, $opts); |
|
| 180 | + if (isset($options['subdir']) && $options['subdir']) { |
|
| 181 | + spip_unlink($chemin); |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + if (isset($options['limit']) and $total >= $options['limit']) { |
|
| 187 | + break; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + closedir($handle); |
|
| 191 | + |
|
| 192 | + return $total; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
@@ -200,26 +200,26 @@ discard block |
||
| 200 | 200 | // Securite : est sur que c'est un cache |
| 201 | 201 | function retire_cache($cache) { |
| 202 | 202 | |
| 203 | - if ( |
|
| 204 | - preg_match( |
|
| 205 | - ',^([0-9a-f]/)?([0-9]+/)?[0-9a-f]+\.cache(\.gz)?$,i', |
|
| 206 | - $cache |
|
| 207 | - ) |
|
| 208 | - ) { |
|
| 209 | - // supprimer le fichier (de facon propre) |
|
| 210 | - supprimer_fichier(_DIR_CACHE . $cache); |
|
| 211 | - } else { |
|
| 212 | - spip_log("Nom de fichier cache incorrect : $cache"); |
|
| 213 | - } |
|
| 203 | + if ( |
|
| 204 | + preg_match( |
|
| 205 | + ',^([0-9a-f]/)?([0-9]+/)?[0-9a-f]+\.cache(\.gz)?$,i', |
|
| 206 | + $cache |
|
| 207 | + ) |
|
| 208 | + ) { |
|
| 209 | + // supprimer le fichier (de facon propre) |
|
| 210 | + supprimer_fichier(_DIR_CACHE . $cache); |
|
| 211 | + } else { |
|
| 212 | + spip_log("Nom de fichier cache incorrect : $cache"); |
|
| 213 | + } |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | // Supprimer les caches marques "x" |
| 217 | 217 | // A priori dans cette version la fonction ne sera pas appelee, car |
| 218 | 218 | // la meta est toujours false ; mais evitons un bug si elle est appellee |
| 219 | 219 | function inc_retire_caches_dist($chemin = '') { |
| 220 | - if (isset($GLOBALS['meta']['invalider_caches'])) { |
|
| 221 | - effacer_meta('invalider_caches'); |
|
| 222 | - } # concurrence |
|
| 220 | + if (isset($GLOBALS['meta']['invalider_caches'])) { |
|
| 221 | + effacer_meta('invalider_caches'); |
|
| 222 | + } # concurrence |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | ####################################################################### |
@@ -230,9 +230,9 @@ discard block |
||
| 230 | 230 | ## |
| 231 | 231 | |
| 232 | 232 | function retire_caches($chemin = '') { |
| 233 | - if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) { |
|
| 234 | - return $retire_caches($chemin); |
|
| 235 | - } |
|
| 233 | + if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) { |
|
| 234 | + return $retire_caches($chemin); |
|
| 235 | + } |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
@@ -240,10 +240,10 @@ discard block |
||
| 240 | 240 | // (note: si absente, n'est pas appellee) |
| 241 | 241 | |
| 242 | 242 | function calcul_invalideurs($corps, $primary, &$boucles, $id_boucle) { |
| 243 | - if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) { |
|
| 244 | - return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 245 | - } |
|
| 246 | - return $corps; |
|
| 243 | + if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) { |
|
| 244 | + return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 245 | + } |
|
| 246 | + return $corps; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | |
@@ -252,41 +252,41 @@ discard block |
||
| 252 | 252 | // invoquee quand on vide tout le cache en bloc (action/purger) |
| 253 | 253 | // |
| 254 | 254 | function supprime_invalideurs() { |
| 255 | - if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) { |
|
| 256 | - return $supprime_invalideurs(); |
|
| 257 | - } |
|
| 255 | + if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) { |
|
| 256 | + return $supprime_invalideurs(); |
|
| 257 | + } |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
| 261 | 261 | // Calcul des pages : noter dans la base les liens d'invalidation |
| 262 | 262 | function maj_invalideurs($fichier, &$page) { |
| 263 | - if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) { |
|
| 264 | - return $maj_invalideurs($fichier, $page); |
|
| 265 | - } |
|
| 263 | + if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) { |
|
| 264 | + return $maj_invalideurs($fichier, $page); |
|
| 265 | + } |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | |
| 269 | 269 | // les invalideurs sont de la forme "objet/id_objet" |
| 270 | 270 | function insere_invalideur($inval, $fichier) { |
| 271 | - if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) { |
|
| 272 | - return $insere_invalideur($inval, $fichier); |
|
| 273 | - } |
|
| 271 | + if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) { |
|
| 272 | + return $insere_invalideur($inval, $fichier); |
|
| 273 | + } |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | // |
| 277 | 277 | // Marquer les fichiers caches invalides comme etant a supprimer |
| 278 | 278 | // |
| 279 | 279 | function applique_invalideur($depart) { |
| 280 | - if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) { |
|
| 281 | - return $applique_invalideur($depart); |
|
| 282 | - } |
|
| 280 | + if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) { |
|
| 281 | + return $applique_invalideur($depart); |
|
| 282 | + } |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | // |
| 286 | 286 | // Invalider les caches liés à telle condition |
| 287 | 287 | // |
| 288 | 288 | function suivre_invalideur($cond, $modif = true) { |
| 289 | - if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) { |
|
| 290 | - return $suivre_invalideur($cond, $modif); |
|
| 291 | - } |
|
| 289 | + if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) { |
|
| 290 | + return $suivre_invalideur($cond, $modif); |
|
| 291 | + } |
|
| 292 | 292 | } |
@@ -11,187 +11,187 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function trace_query_start() { |
| 18 | - static $trace = '?'; |
|
| 19 | - if ($trace === '?' or defined('_DEBUG_TRACE_QUERIES')) { |
|
| 20 | - if (defined('_DEBUG_TRACE_QUERIES') and _DEBUG_TRACE_QUERIES) { |
|
| 21 | - $trace = true; |
|
| 22 | - } |
|
| 23 | - else { |
|
| 24 | - if (empty($GLOBALS['visiteur_session'])) { |
|
| 25 | - // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 26 | - // car ici on ne sait pas si c'est un hit anonyme |
|
| 27 | - // ou une requete SQL faite avant chargement de la session |
|
| 28 | - $trace = (!empty($_GET['var_profile']) ? '?' : false); |
|
| 29 | - } |
|
| 30 | - else { |
|
| 31 | - include_spip('inc/autoriser'); |
|
| 32 | - // gare au bouclage sur calcul de droits au premier appel |
|
| 33 | - // A fortiori quand on demande une trace |
|
| 34 | - $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 35 | - $trace = (!empty($_GET['var_profile']) and autoriser('debug')); |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - return $trace ? microtime() : 0; |
|
| 18 | + static $trace = '?'; |
|
| 19 | + if ($trace === '?' or defined('_DEBUG_TRACE_QUERIES')) { |
|
| 20 | + if (defined('_DEBUG_TRACE_QUERIES') and _DEBUG_TRACE_QUERIES) { |
|
| 21 | + $trace = true; |
|
| 22 | + } |
|
| 23 | + else { |
|
| 24 | + if (empty($GLOBALS['visiteur_session'])) { |
|
| 25 | + // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 26 | + // car ici on ne sait pas si c'est un hit anonyme |
|
| 27 | + // ou une requete SQL faite avant chargement de la session |
|
| 28 | + $trace = (!empty($_GET['var_profile']) ? '?' : false); |
|
| 29 | + } |
|
| 30 | + else { |
|
| 31 | + include_spip('inc/autoriser'); |
|
| 32 | + // gare au bouclage sur calcul de droits au premier appel |
|
| 33 | + // A fortiori quand on demande une trace |
|
| 34 | + $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 35 | + $trace = (!empty($_GET['var_profile']) and autoriser('debug')); |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + return $trace ? microtime() : 0; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | function trace_query_end($query, $start, $result, $erreur, $serveur = '') { |
| 44 | - static $trace = '?'; |
|
| 45 | - if ($trace === '?') { |
|
| 46 | - if (empty($GLOBALS['visiteur_session'])) { |
|
| 47 | - // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 48 | - // car ici on ne sait pas si c'est un hit anonyme |
|
| 49 | - // ou une requete SQL faite avant chargement de la session |
|
| 50 | - $trace = (!empty($_GET['var_profile']) ? '?' : false); |
|
| 51 | - } |
|
| 52 | - else { |
|
| 53 | - include_spip('inc/autoriser'); |
|
| 54 | - // gare au bouclage sur calcul de droits au premier appel |
|
| 55 | - // A fortiori quand on demande une trace |
|
| 56 | - $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 57 | - $trace = (!empty($_GET['var_profile']) and autoriser('debug')); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - if ($start) { |
|
| 61 | - $end = microtime(); |
|
| 62 | - [$usec, $sec] = explode(' ', $start); |
|
| 63 | - [$usec2, $sec2] = explode(' ', $end); |
|
| 64 | - $dt = $sec2 + $usec2 - $sec - $usec; |
|
| 65 | - pipeline('trig_trace_query', ['query' => $query, 'start' => $start, 'end' => $end, 'time' => $dt, 'result' => $result, 'erreur' => $erreur, 'serveur' => $serveur]); |
|
| 66 | - if ($trace) { |
|
| 67 | - trace_query_chrono($dt, $query, $result, $serveur); |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - // tracer les erreurs, sauf pour select, c'est fait dans abstract_sql |
|
| 71 | - if ($trace and $erreur and !preg_match('/^select\b/i', $query)) { |
|
| 72 | - erreur_squelette([sql_errno($serveur), $erreur, $query]); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - return $result; |
|
| 44 | + static $trace = '?'; |
|
| 45 | + if ($trace === '?') { |
|
| 46 | + if (empty($GLOBALS['visiteur_session'])) { |
|
| 47 | + // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 48 | + // car ici on ne sait pas si c'est un hit anonyme |
|
| 49 | + // ou une requete SQL faite avant chargement de la session |
|
| 50 | + $trace = (!empty($_GET['var_profile']) ? '?' : false); |
|
| 51 | + } |
|
| 52 | + else { |
|
| 53 | + include_spip('inc/autoriser'); |
|
| 54 | + // gare au bouclage sur calcul de droits au premier appel |
|
| 55 | + // A fortiori quand on demande une trace |
|
| 56 | + $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 57 | + $trace = (!empty($_GET['var_profile']) and autoriser('debug')); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + if ($start) { |
|
| 61 | + $end = microtime(); |
|
| 62 | + [$usec, $sec] = explode(' ', $start); |
|
| 63 | + [$usec2, $sec2] = explode(' ', $end); |
|
| 64 | + $dt = $sec2 + $usec2 - $sec - $usec; |
|
| 65 | + pipeline('trig_trace_query', ['query' => $query, 'start' => $start, 'end' => $end, 'time' => $dt, 'result' => $result, 'erreur' => $erreur, 'serveur' => $serveur]); |
|
| 66 | + if ($trace) { |
|
| 67 | + trace_query_chrono($dt, $query, $result, $serveur); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + // tracer les erreurs, sauf pour select, c'est fait dans abstract_sql |
|
| 71 | + if ($trace and $erreur and !preg_match('/^select\b/i', $query)) { |
|
| 72 | + erreur_squelette([sql_errno($serveur), $erreur, $query]); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + return $result; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | function trace_query_chrono($dt, $query, $result, $serveur = '') { |
| 79 | - include_spip('inc/filtres_mini'); |
|
| 80 | - static $tt = 0, $nb = 0; |
|
| 81 | - |
|
| 82 | - $x = _request('var_mode_objet'); |
|
| 83 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 84 | - [, $boucle, $serveur, $contexte] = $GLOBALS['debug']['aucasou']; |
|
| 85 | - if ($x and !preg_match("/$boucle\$/", $x)) { |
|
| 86 | - return; |
|
| 87 | - } |
|
| 88 | - if ($serveur) { |
|
| 89 | - $boucle .= " ($serveur)"; |
|
| 90 | - } |
|
| 91 | - $boucle = "<b>$boucle</b>"; |
|
| 92 | - } else { |
|
| 93 | - if ($x) { |
|
| 94 | - return; |
|
| 95 | - } |
|
| 96 | - $boucle = $contexte = ''; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $tt += $dt; |
|
| 100 | - $nb++; |
|
| 101 | - |
|
| 102 | - $q = preg_replace('/([a-z)`])\s+([A-Z])/', "$1\n<br />$2", spip_htmlentities($query)); |
|
| 103 | - $e = sql_explain($query, $serveur); |
|
| 104 | - $r = str_replace('Resource id ', '', (is_object($result) ? get_class($result) : $result)); |
|
| 105 | - $GLOBALS['tableau_des_temps'][] = [$dt, $nb, $boucle, $q, $e, $r, $contexte]; |
|
| 79 | + include_spip('inc/filtres_mini'); |
|
| 80 | + static $tt = 0, $nb = 0; |
|
| 81 | + |
|
| 82 | + $x = _request('var_mode_objet'); |
|
| 83 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 84 | + [, $boucle, $serveur, $contexte] = $GLOBALS['debug']['aucasou']; |
|
| 85 | + if ($x and !preg_match("/$boucle\$/", $x)) { |
|
| 86 | + return; |
|
| 87 | + } |
|
| 88 | + if ($serveur) { |
|
| 89 | + $boucle .= " ($serveur)"; |
|
| 90 | + } |
|
| 91 | + $boucle = "<b>$boucle</b>"; |
|
| 92 | + } else { |
|
| 93 | + if ($x) { |
|
| 94 | + return; |
|
| 95 | + } |
|
| 96 | + $boucle = $contexte = ''; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $tt += $dt; |
|
| 100 | + $nb++; |
|
| 101 | + |
|
| 102 | + $q = preg_replace('/([a-z)`])\s+([A-Z])/', "$1\n<br />$2", spip_htmlentities($query)); |
|
| 103 | + $e = sql_explain($query, $serveur); |
|
| 104 | + $r = str_replace('Resource id ', '', (is_object($result) ? get_class($result) : $result)); |
|
| 105 | + $GLOBALS['tableau_des_temps'][] = [$dt, $nb, $boucle, $q, $e, $r, $contexte]; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | |
| 109 | 109 | function chrono_requete($temps) { |
| 110 | - $total = 0; |
|
| 111 | - $hors = '<i>' . _T('zbug_hors_compilation') . '</i>'; |
|
| 112 | - $t = $q = $n = $d = []; |
|
| 113 | - // Totaliser les temps et completer le Explain |
|
| 114 | - foreach ($temps as $key => $v) { |
|
| 115 | - [$dt, $nb, $boucle, $query, $explain, $res, $contexte] = $v; |
|
| 116 | - if (is_array($contexte)) { |
|
| 117 | - $k = ($contexte[0] . " $boucle"); |
|
| 118 | - include_spip('public/compiler'); |
|
| 119 | - $env = reconstruire_contexte_compil($contexte); |
|
| 120 | - } else { |
|
| 121 | - $k = $env = $boucle; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - $total += $dt; |
|
| 125 | - $t[$key] = $dt; |
|
| 126 | - $q[$key] = $nb; |
|
| 127 | - if (!isset($d[$k])) { |
|
| 128 | - $d[$k] = 0; |
|
| 129 | - $n[$k] = 0; |
|
| 130 | - } |
|
| 131 | - $d[$k] += $dt; |
|
| 132 | - ++$n[$k]; |
|
| 133 | - |
|
| 134 | - if (!is_array($explain)) { |
|
| 135 | - $explain = []; |
|
| 136 | - } |
|
| 137 | - foreach ($explain as $j => $v) { |
|
| 138 | - $explain[$j] = "<tr><th>$j</th><td>" |
|
| 139 | - . str_replace(';', '<br />', $v) |
|
| 140 | - . '</td></tr>'; |
|
| 141 | - } |
|
| 142 | - $e = "<table class='explain'>" |
|
| 143 | - . '<caption>' |
|
| 144 | - . $query |
|
| 145 | - . '</caption>' |
|
| 146 | - . "<tr><th>Time</th><td>$dt</td></tr>" |
|
| 147 | - . "<tr><th>Order</th><td>$nb</td></tr>" |
|
| 148 | - . "<tr><th>Res</th><td>$res</td></tr>" |
|
| 149 | - . join('', $explain) |
|
| 150 | - . '</table>'; |
|
| 151 | - |
|
| 152 | - $temps[$key] = [$e, $env, $k]; |
|
| 153 | - } |
|
| 154 | - // Trier par temps d'execution decroissant |
|
| 155 | - array_multisort($t, SORT_DESC, $q, $temps); |
|
| 156 | - arsort($d); |
|
| 157 | - $i = 1; |
|
| 158 | - $t = []; |
|
| 159 | - // Fabriquer les liens de navigations dans le tableau des temps |
|
| 160 | - foreach ($temps as $k => $v) { |
|
| 161 | - $titre = strip_tags($v[2]); |
|
| 162 | - $href = quote_amp($GLOBALS['REQUEST_URI']) . "#req$i"; |
|
| 163 | - $href = str_replace("\\'", ''', $href); |
|
| 164 | - |
|
| 165 | - if (!isset($t[$v[2]])) { |
|
| 166 | - $t[$v[2]] = []; |
|
| 167 | - } |
|
| 168 | - $t[$v[2]][] = "<span class='spip-debug-arg'> " |
|
| 169 | - . "<a title='$titre' href='$href'>$i</a>" |
|
| 170 | - . '</span>' |
|
| 171 | - . ((count($t[$v[2]]) % 10 == 9) ? '<br />' : ''); |
|
| 172 | - $i++; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - if ($d['']) { |
|
| 176 | - $d[$hors] = $d['']; |
|
| 177 | - $n[$hors] = $n['']; |
|
| 178 | - $t[$hors] = $t['']; |
|
| 179 | - } |
|
| 180 | - unset($d['']); |
|
| 181 | - // Fabriquer le tableau des liens de navigation dans le grand tableau |
|
| 182 | - foreach ($d as $k => $v) { |
|
| 183 | - $d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 184 | - . join('', $t[$k]); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $navigation = [ |
|
| 188 | - _T('zbug_statistiques'), |
|
| 189 | - '<tr><td>' |
|
| 190 | - . join("</td></tr>\n<tr><td>", $d) |
|
| 191 | - . "</td></tr>\n" |
|
| 192 | - . (# _request('var_mode_objet') ? '' : |
|
| 193 | - ('<tr><td>' . (is_countable($temps) ? count($temps) : 0) . '</td><td>' . _T('info_total') . '</td><td class="time">' . $total . '</td><td></td></tr>')) |
|
| 194 | - ]; |
|
| 195 | - |
|
| 196 | - return [$temps, $navigation]; |
|
| 110 | + $total = 0; |
|
| 111 | + $hors = '<i>' . _T('zbug_hors_compilation') . '</i>'; |
|
| 112 | + $t = $q = $n = $d = []; |
|
| 113 | + // Totaliser les temps et completer le Explain |
|
| 114 | + foreach ($temps as $key => $v) { |
|
| 115 | + [$dt, $nb, $boucle, $query, $explain, $res, $contexte] = $v; |
|
| 116 | + if (is_array($contexte)) { |
|
| 117 | + $k = ($contexte[0] . " $boucle"); |
|
| 118 | + include_spip('public/compiler'); |
|
| 119 | + $env = reconstruire_contexte_compil($contexte); |
|
| 120 | + } else { |
|
| 121 | + $k = $env = $boucle; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + $total += $dt; |
|
| 125 | + $t[$key] = $dt; |
|
| 126 | + $q[$key] = $nb; |
|
| 127 | + if (!isset($d[$k])) { |
|
| 128 | + $d[$k] = 0; |
|
| 129 | + $n[$k] = 0; |
|
| 130 | + } |
|
| 131 | + $d[$k] += $dt; |
|
| 132 | + ++$n[$k]; |
|
| 133 | + |
|
| 134 | + if (!is_array($explain)) { |
|
| 135 | + $explain = []; |
|
| 136 | + } |
|
| 137 | + foreach ($explain as $j => $v) { |
|
| 138 | + $explain[$j] = "<tr><th>$j</th><td>" |
|
| 139 | + . str_replace(';', '<br />', $v) |
|
| 140 | + . '</td></tr>'; |
|
| 141 | + } |
|
| 142 | + $e = "<table class='explain'>" |
|
| 143 | + . '<caption>' |
|
| 144 | + . $query |
|
| 145 | + . '</caption>' |
|
| 146 | + . "<tr><th>Time</th><td>$dt</td></tr>" |
|
| 147 | + . "<tr><th>Order</th><td>$nb</td></tr>" |
|
| 148 | + . "<tr><th>Res</th><td>$res</td></tr>" |
|
| 149 | + . join('', $explain) |
|
| 150 | + . '</table>'; |
|
| 151 | + |
|
| 152 | + $temps[$key] = [$e, $env, $k]; |
|
| 153 | + } |
|
| 154 | + // Trier par temps d'execution decroissant |
|
| 155 | + array_multisort($t, SORT_DESC, $q, $temps); |
|
| 156 | + arsort($d); |
|
| 157 | + $i = 1; |
|
| 158 | + $t = []; |
|
| 159 | + // Fabriquer les liens de navigations dans le tableau des temps |
|
| 160 | + foreach ($temps as $k => $v) { |
|
| 161 | + $titre = strip_tags($v[2]); |
|
| 162 | + $href = quote_amp($GLOBALS['REQUEST_URI']) . "#req$i"; |
|
| 163 | + $href = str_replace("\\'", ''', $href); |
|
| 164 | + |
|
| 165 | + if (!isset($t[$v[2]])) { |
|
| 166 | + $t[$v[2]] = []; |
|
| 167 | + } |
|
| 168 | + $t[$v[2]][] = "<span class='spip-debug-arg'> " |
|
| 169 | + . "<a title='$titre' href='$href'>$i</a>" |
|
| 170 | + . '</span>' |
|
| 171 | + . ((count($t[$v[2]]) % 10 == 9) ? '<br />' : ''); |
|
| 172 | + $i++; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + if ($d['']) { |
|
| 176 | + $d[$hors] = $d['']; |
|
| 177 | + $n[$hors] = $n['']; |
|
| 178 | + $t[$hors] = $t['']; |
|
| 179 | + } |
|
| 180 | + unset($d['']); |
|
| 181 | + // Fabriquer le tableau des liens de navigation dans le grand tableau |
|
| 182 | + foreach ($d as $k => $v) { |
|
| 183 | + $d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 184 | + . join('', $t[$k]); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $navigation = [ |
|
| 188 | + _T('zbug_statistiques'), |
|
| 189 | + '<tr><td>' |
|
| 190 | + . join("</td></tr>\n<tr><td>", $d) |
|
| 191 | + . "</td></tr>\n" |
|
| 192 | + . (# _request('var_mode_objet') ? '' : |
|
| 193 | + ('<tr><td>' . (is_countable($temps) ? count($temps) : 0) . '</td><td>' . _T('info_total') . '</td><td class="time">' . $total . '</td><td></td></tr>')) |
|
| 194 | + ]; |
|
| 195 | + |
|
| 196 | + return [$temps, $navigation]; |
|
| 197 | 197 | } |
@@ -11,96 +11,96 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('auth/ldap'); |
| 18 | 18 | |
| 19 | 19 | function install_etape_ldap4_dist() { |
| 20 | - $adresse_ldap = _request('adresse_ldap'); |
|
| 21 | - $login_ldap = _request('login_ldap'); |
|
| 22 | - $pass_ldap = _request('pass_ldap'); |
|
| 23 | - $port_ldap = _request('port_ldap'); |
|
| 24 | - $base_ldap = _request('base_ldap'); |
|
| 25 | - $base_ldap_text = _request('base_ldap_text'); |
|
| 26 | - if (!$base_ldap) { |
|
| 27 | - $base_ldap = $base_ldap_text; |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"'); |
|
| 31 | - |
|
| 32 | - $ldap_link = ldap_connect($adresse_ldap, $port_ldap); |
|
| 33 | - @ldap_bind($ldap_link, $login_ldap, $pass_ldap); |
|
| 34 | - |
|
| 35 | - // Essayer de verifier le chemin fourni |
|
| 36 | - $r = @ldap_compare($ldap_link, $base_ldap, 'objectClass', ''); |
|
| 37 | - $fail = (ldap_errno($ldap_link) == 32); |
|
| 38 | - |
|
| 39 | - if ($fail) { |
|
| 40 | - echo info_etape(_T('info_chemin_acces_annuaire')), |
|
| 41 | - info_progression_etape(3, 'etape_ldap', 'install/', true), |
|
| 42 | - "<div class='error'><p><b>" . _T('avis_operation_echec') . '</b></p><p>' . _T('avis_chemin_invalide_1'), |
|
| 43 | - ' (<tt>' . spip_htmlspecialchars($base_ldap) . '</tt>) ' . _T('avis_chemin_invalide_2') . '</p></div>'; |
|
| 44 | - } else { |
|
| 45 | - info_etape(_T('info_reglage_ldap')); |
|
| 46 | - echo info_progression_etape(4, 'etape_ldap', 'install/'); |
|
| 47 | - |
|
| 48 | - $statuts = liste_statuts_ldap(); |
|
| 49 | - $statut_ldap = defined('_INSTALL_STATUT_LDAP') |
|
| 50 | - ? _INSTALL_STATUT_LDAP |
|
| 51 | - : $GLOBALS['liste_des_statuts']['info_redacteurs']; |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - $res = install_propager(['adresse_ldap', 'port_ldap', 'login_ldap', 'pass_ldap', 'protocole_ldap', 'tls_ldap']) |
|
| 55 | - . "<input type='hidden' name='etape' value='ldap5' />" |
|
| 56 | - . "<input type='hidden' name='base_ldap' value='" . spip_htmlentities($base_ldap) . "' />" |
|
| 57 | - . fieldset( |
|
| 58 | - _T('info_statut_utilisateurs_1'), |
|
| 59 | - [ |
|
| 60 | - 'statut_ldap' => [ |
|
| 61 | - 'label' => _T('info_statut_utilisateurs_2') . '<br />', |
|
| 62 | - 'valeur' => $statut_ldap, |
|
| 63 | - 'alternatives' => $statuts |
|
| 64 | - ] |
|
| 65 | - ] |
|
| 66 | - ) |
|
| 67 | - . install_ldap_correspondances() |
|
| 68 | - . bouton_suivant(); |
|
| 69 | - |
|
| 70 | - echo generer_form_ecrire('install', $res); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - echo install_fin_html(); |
|
| 20 | + $adresse_ldap = _request('adresse_ldap'); |
|
| 21 | + $login_ldap = _request('login_ldap'); |
|
| 22 | + $pass_ldap = _request('pass_ldap'); |
|
| 23 | + $port_ldap = _request('port_ldap'); |
|
| 24 | + $base_ldap = _request('base_ldap'); |
|
| 25 | + $base_ldap_text = _request('base_ldap_text'); |
|
| 26 | + if (!$base_ldap) { |
|
| 27 | + $base_ldap = $base_ldap_text; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"'); |
|
| 31 | + |
|
| 32 | + $ldap_link = ldap_connect($adresse_ldap, $port_ldap); |
|
| 33 | + @ldap_bind($ldap_link, $login_ldap, $pass_ldap); |
|
| 34 | + |
|
| 35 | + // Essayer de verifier le chemin fourni |
|
| 36 | + $r = @ldap_compare($ldap_link, $base_ldap, 'objectClass', ''); |
|
| 37 | + $fail = (ldap_errno($ldap_link) == 32); |
|
| 38 | + |
|
| 39 | + if ($fail) { |
|
| 40 | + echo info_etape(_T('info_chemin_acces_annuaire')), |
|
| 41 | + info_progression_etape(3, 'etape_ldap', 'install/', true), |
|
| 42 | + "<div class='error'><p><b>" . _T('avis_operation_echec') . '</b></p><p>' . _T('avis_chemin_invalide_1'), |
|
| 43 | + ' (<tt>' . spip_htmlspecialchars($base_ldap) . '</tt>) ' . _T('avis_chemin_invalide_2') . '</p></div>'; |
|
| 44 | + } else { |
|
| 45 | + info_etape(_T('info_reglage_ldap')); |
|
| 46 | + echo info_progression_etape(4, 'etape_ldap', 'install/'); |
|
| 47 | + |
|
| 48 | + $statuts = liste_statuts_ldap(); |
|
| 49 | + $statut_ldap = defined('_INSTALL_STATUT_LDAP') |
|
| 50 | + ? _INSTALL_STATUT_LDAP |
|
| 51 | + : $GLOBALS['liste_des_statuts']['info_redacteurs']; |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + $res = install_propager(['adresse_ldap', 'port_ldap', 'login_ldap', 'pass_ldap', 'protocole_ldap', 'tls_ldap']) |
|
| 55 | + . "<input type='hidden' name='etape' value='ldap5' />" |
|
| 56 | + . "<input type='hidden' name='base_ldap' value='" . spip_htmlentities($base_ldap) . "' />" |
|
| 57 | + . fieldset( |
|
| 58 | + _T('info_statut_utilisateurs_1'), |
|
| 59 | + [ |
|
| 60 | + 'statut_ldap' => [ |
|
| 61 | + 'label' => _T('info_statut_utilisateurs_2') . '<br />', |
|
| 62 | + 'valeur' => $statut_ldap, |
|
| 63 | + 'alternatives' => $statuts |
|
| 64 | + ] |
|
| 65 | + ] |
|
| 66 | + ) |
|
| 67 | + . install_ldap_correspondances() |
|
| 68 | + . bouton_suivant(); |
|
| 69 | + |
|
| 70 | + echo generer_form_ecrire('install', $res); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + echo install_fin_html(); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | function liste_statuts_ldap() { |
| 77 | - $recom = [ |
|
| 78 | - 'info_administrateurs' => ('<b>' . _T('info_administrateur_1') . '</b> ' . _T('info_administrateur_2') . '<br />'), |
|
| 79 | - 'info_redacteurs' => ('<b>' . _T('info_redacteur_1') . '</b> ' . _T('info_redacteur_2') . '<br />'), |
|
| 80 | - 'info_visiteurs' => ('<b>' . _T('info_visiteur_1') . '</b> ' . _T('info_visiteur_2') . '<br />') |
|
| 81 | - ]; |
|
| 82 | - |
|
| 83 | - $res = []; |
|
| 84 | - foreach ($GLOBALS['liste_des_statuts'] as $k => $v) { |
|
| 85 | - if (isset($recom[$k])) { |
|
| 86 | - $res[$v] = $recom[$k]; |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - return $res; |
|
| 77 | + $recom = [ |
|
| 78 | + 'info_administrateurs' => ('<b>' . _T('info_administrateur_1') . '</b> ' . _T('info_administrateur_2') . '<br />'), |
|
| 79 | + 'info_redacteurs' => ('<b>' . _T('info_redacteur_1') . '</b> ' . _T('info_redacteur_2') . '<br />'), |
|
| 80 | + 'info_visiteurs' => ('<b>' . _T('info_visiteur_1') . '</b> ' . _T('info_visiteur_2') . '<br />') |
|
| 81 | + ]; |
|
| 82 | + |
|
| 83 | + $res = []; |
|
| 84 | + foreach ($GLOBALS['liste_des_statuts'] as $k => $v) { |
|
| 85 | + if (isset($recom[$k])) { |
|
| 86 | + $res[$v] = $recom[$k]; |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + return $res; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | function install_ldap_correspondances() { |
| 94 | - $champs = []; |
|
| 95 | - foreach (is_array($GLOBALS['ldap_attributes']) ? $GLOBALS['ldap_attributes'] : [] as $champ => $v) { |
|
| 96 | - $nom = 'ldap_' . $champ; |
|
| 97 | - $val = is_array($v) ? join(',', $v) : strval($v); |
|
| 98 | - $champs[$nom] = [ |
|
| 99 | - 'label' => _T('ldap_correspondance', ['champ' => "<tt>$champ</tt>"]) . '<br />', |
|
| 100 | - 'valeur' => $val |
|
| 101 | - ]; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - return !$champs ? |
|
| 105 | - '' : fieldset(_T('ldap_correspondance_1'), $champs, '', _T('ldap_correspondance_2') . '<br /><br />'); |
|
| 94 | + $champs = []; |
|
| 95 | + foreach (is_array($GLOBALS['ldap_attributes']) ? $GLOBALS['ldap_attributes'] : [] as $champ => $v) { |
|
| 96 | + $nom = 'ldap_' . $champ; |
|
| 97 | + $val = is_array($v) ? join(',', $v) : strval($v); |
|
| 98 | + $champs[$nom] = [ |
|
| 99 | + 'label' => _T('ldap_correspondance', ['champ' => "<tt>$champ</tt>"]) . '<br />', |
|
| 100 | + 'valeur' => $val |
|
| 101 | + ]; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + return !$champs ? |
|
| 105 | + '' : fieldset(_T('ldap_correspondance_1'), $champs, '', _T('ldap_correspondance_2') . '<br /><br />'); |
|
| 106 | 106 | } |
@@ -11,76 +11,76 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function install_etape_ldap3_dist() { |
| 18 | - $info = []; |
|
| 19 | - $adresse_ldap = _request('adresse_ldap'); |
|
| 20 | - $login_ldap = _request('login_ldap'); |
|
| 21 | - $pass_ldap = _request('pass_ldap'); |
|
| 22 | - $port_ldap = _request('port_ldap'); |
|
| 18 | + $info = []; |
|
| 19 | + $adresse_ldap = _request('adresse_ldap'); |
|
| 20 | + $login_ldap = _request('login_ldap'); |
|
| 21 | + $pass_ldap = _request('pass_ldap'); |
|
| 22 | + $port_ldap = _request('port_ldap'); |
|
| 23 | 23 | |
| 24 | - $base_ldap_text = defined('_INSTALL_BASE_LDAP') |
|
| 25 | - ? _INSTALL_BASE_LDAP |
|
| 26 | - : 'ou=users, dc=mon-domaine, dc=com'; |
|
| 24 | + $base_ldap_text = defined('_INSTALL_BASE_LDAP') |
|
| 25 | + ? _INSTALL_BASE_LDAP |
|
| 26 | + : 'ou=users, dc=mon-domaine, dc=com'; |
|
| 27 | 27 | |
| 28 | - echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"'); |
|
| 28 | + echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"'); |
|
| 29 | 29 | |
| 30 | - echo info_etape( |
|
| 31 | - _T('info_chemin_acces_1'), |
|
| 32 | - info_progression_etape(3, 'etape_ldap', 'install/') |
|
| 33 | - ), |
|
| 34 | - _T('info_chemin_acces_2'); |
|
| 30 | + echo info_etape( |
|
| 31 | + _T('info_chemin_acces_1'), |
|
| 32 | + info_progression_etape(3, 'etape_ldap', 'install/') |
|
| 33 | + ), |
|
| 34 | + _T('info_chemin_acces_2'); |
|
| 35 | 35 | |
| 36 | - $ldap_link = @ldap_connect("$adresse_ldap", "$port_ldap"); |
|
| 37 | - if ($ldap_link) { |
|
| 38 | - @ldap_bind($ldap_link, "$login_ldap", "$pass_ldap"); |
|
| 39 | - $result = @ldap_read($ldap_link, '', 'objectclass=*', ['namingContexts']); |
|
| 40 | - $info = @ldap_get_entries($ldap_link, $result); |
|
| 41 | - @ldap_close($ldap_link); |
|
| 42 | - } |
|
| 36 | + $ldap_link = @ldap_connect("$adresse_ldap", "$port_ldap"); |
|
| 37 | + if ($ldap_link) { |
|
| 38 | + @ldap_bind($ldap_link, "$login_ldap", "$pass_ldap"); |
|
| 39 | + $result = @ldap_read($ldap_link, '', 'objectclass=*', ['namingContexts']); |
|
| 40 | + $info = @ldap_get_entries($ldap_link, $result); |
|
| 41 | + @ldap_close($ldap_link); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - $checked = false; |
|
| 45 | - $res = ''; |
|
| 46 | - if (is_array($info) and $info['count'] > 0) { |
|
| 47 | - $res .= '<p>' . _T('info_selection_chemin_acces') . '</p>'; |
|
| 48 | - $res .= '<ul>'; |
|
| 49 | - $n = 0; |
|
| 50 | - for ($i = 0; $i < $info['count']; $i++) { |
|
| 51 | - $names = $info[$i]['namingcontexts']; |
|
| 52 | - if (is_array($names)) { |
|
| 53 | - for ($j = 0; $j < $names['count']; $j++) { |
|
| 54 | - $n++; |
|
| 55 | - $res .= '<li><input name="base_ldap" value="' . spip_htmlspecialchars($names[$j]) . "\" type='radio' id='tab$n'"; |
|
| 56 | - if (!$checked) { |
|
| 57 | - $res .= ' checked="checked"'; |
|
| 58 | - $checked = true; |
|
| 59 | - } |
|
| 60 | - $res .= ' />'; |
|
| 61 | - $res .= "<label for='tab$n'>" . spip_htmlspecialchars($names[$j]) . "</label></li>\n"; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - $res .= '</ul>'; |
|
| 66 | - $res .= _T('info_ou') . ' '; |
|
| 67 | - } |
|
| 68 | - $res .= "<br />\n<input name=\"base_ldap\" value=\"\" type='radio' id='manuel'"; |
|
| 69 | - if (!$checked) { |
|
| 70 | - $res .= ' checked="checked"'; |
|
| 71 | - $checked = true; |
|
| 72 | - } |
|
| 44 | + $checked = false; |
|
| 45 | + $res = ''; |
|
| 46 | + if (is_array($info) and $info['count'] > 0) { |
|
| 47 | + $res .= '<p>' . _T('info_selection_chemin_acces') . '</p>'; |
|
| 48 | + $res .= '<ul>'; |
|
| 49 | + $n = 0; |
|
| 50 | + for ($i = 0; $i < $info['count']; $i++) { |
|
| 51 | + $names = $info[$i]['namingcontexts']; |
|
| 52 | + if (is_array($names)) { |
|
| 53 | + for ($j = 0; $j < $names['count']; $j++) { |
|
| 54 | + $n++; |
|
| 55 | + $res .= '<li><input name="base_ldap" value="' . spip_htmlspecialchars($names[$j]) . "\" type='radio' id='tab$n'"; |
|
| 56 | + if (!$checked) { |
|
| 57 | + $res .= ' checked="checked"'; |
|
| 58 | + $checked = true; |
|
| 59 | + } |
|
| 60 | + $res .= ' />'; |
|
| 61 | + $res .= "<label for='tab$n'>" . spip_htmlspecialchars($names[$j]) . "</label></li>\n"; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + $res .= '</ul>'; |
|
| 66 | + $res .= _T('info_ou') . ' '; |
|
| 67 | + } |
|
| 68 | + $res .= "<br />\n<input name=\"base_ldap\" value=\"\" type='radio' id='manuel'"; |
|
| 69 | + if (!$checked) { |
|
| 70 | + $res .= ' checked="checked"'; |
|
| 71 | + $checked = true; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - $res .= ' />' |
|
| 75 | - . "\n<label for='manuel'>" . _T('entree_chemin_acces') . '</label> ' |
|
| 76 | - . "\n<fieldset>" |
|
| 77 | - . "<input type='text' name='base_ldap_text' class='text' value=\"$base_ldap_text\" size='40' />" |
|
| 78 | - . "\n</fieldset>" |
|
| 79 | - . "\n<input type='hidden' name='etape' value='ldap4' />" |
|
| 80 | - . install_propager(['adresse_ldap', 'port_ldap', 'login_ldap', 'pass_ldap', 'protocole_ldap', 'tls_ldap']) |
|
| 81 | - . bouton_suivant(); |
|
| 74 | + $res .= ' />' |
|
| 75 | + . "\n<label for='manuel'>" . _T('entree_chemin_acces') . '</label> ' |
|
| 76 | + . "\n<fieldset>" |
|
| 77 | + . "<input type='text' name='base_ldap_text' class='text' value=\"$base_ldap_text\" size='40' />" |
|
| 78 | + . "\n</fieldset>" |
|
| 79 | + . "\n<input type='hidden' name='etape' value='ldap4' />" |
|
| 80 | + . install_propager(['adresse_ldap', 'port_ldap', 'login_ldap', 'pass_ldap', 'protocole_ldap', 'tls_ldap']) |
|
| 81 | + . bouton_suivant(); |
|
| 82 | 82 | |
| 83 | - echo generer_form_ecrire('install', $res); |
|
| 83 | + echo generer_form_ecrire('install', $res); |
|
| 84 | 84 | |
| 85 | - echo install_fin_html(); |
|
| 85 | + echo install_fin_html(); |
|
| 86 | 86 | } |