@@ -30,6 +30,9 @@ discard block |
||
| 30 | 30 | include_spip('inc/filtres_boites'); |
| 31 | 31 | |
| 32 | 32 | // http://code.spip.net/@debut_cadre |
| 33 | +/** |
|
| 34 | + * @param string $style |
|
| 35 | + */ |
|
| 33 | 36 | function debut_cadre($style, $icone = "", $fonction = "", $titre = "", $id = "", $class = "", $padding = true) { |
| 34 | 37 | $style_mapping = array( |
| 35 | 38 | 'r' => 'simple', |
@@ -183,6 +186,10 @@ discard block |
||
| 183 | 186 | function fin_onglet() { return "</ul></div>\n"; } |
| 184 | 187 | |
| 185 | 188 | // http://code.spip.net/@onglet |
| 189 | +/** |
|
| 190 | + * @param string $texte |
|
| 191 | + * @param string $onglet |
|
| 192 | + */ |
|
| 186 | 193 | function onglet($texte, $lien, $onglet_ref, $onglet, $icone = "") { |
| 187 | 194 | return "<li>" |
| 188 | 195 | . ($icone ? http_img_pack($icone, '', " class='cadre-icone'") : '') |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Presentation |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/presentation_mini'); |
@@ -31,44 +31,44 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | // http://code.spip.net/@debut_cadre |
| 33 | 33 | function debut_cadre($style, $icone = "", $fonction = "", $titre = "", $id = "", $class = "", $padding = true) { |
| 34 | - $style_mapping = array( |
|
| 35 | - 'r' => 'simple', |
|
| 36 | - 'e' => 'raccourcis', |
|
| 37 | - 'couleur' => 'basic highlight', |
|
| 38 | - 'couleur-foncee' => 'basic highlight', |
|
| 39 | - 'trait-couleur' => 'important', |
|
| 40 | - 'alerte' => 'notice', |
|
| 41 | - 'info' => 'info', |
|
| 42 | - 'sous_rub' => 'simple sous-rub' |
|
| 43 | - ); |
|
| 44 | - $style_titre_mapping = array('couleur' => 'topper', 'trait-couleur' => 'section'); |
|
| 45 | - $c = isset($style_mapping[$style]) ? $style_mapping[$style] : 'simple'; |
|
| 46 | - $class = $c . ($class ? " $class" : ""); |
|
| 47 | - if (!$padding) { |
|
| 48 | - $class .= ($class ? " " : "") . "no-padding"; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - //($id?"id='$id' ":"") |
|
| 52 | - if (strlen($icone) > 1) { |
|
| 53 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 54 | - list($fond, $fonction) = $icone_renommer($icone, $fonction); |
|
| 55 | - } |
|
| 56 | - $size = 24; |
|
| 57 | - if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i", $fond, $match)) { |
|
| 58 | - $size = $match[1]; |
|
| 59 | - } |
|
| 60 | - if ($fonction) { |
|
| 61 | - // 2 images pour composer l'icone : le fond (article) en background, |
|
| 62 | - // la fonction (new) en image |
|
| 63 | - $icone = http_img_pack($fonction, "", "class='cadre-icone' width='$size' height='$size'\n" . |
|
| 64 | - http_style_background($fond, "no-repeat center center")); |
|
| 65 | - } else { |
|
| 66 | - $icone = http_img_pack($fond, "", "class='cadre-icone' width='$size' height='$size'"); |
|
| 67 | - } |
|
| 68 | - $titre = $icone . $titre; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - return boite_ouvrir($titre, $class, isset($style_titre_mapping[$style]) ? $style_titre_mapping[$style] : '', $id); |
|
| 34 | + $style_mapping = array( |
|
| 35 | + 'r' => 'simple', |
|
| 36 | + 'e' => 'raccourcis', |
|
| 37 | + 'couleur' => 'basic highlight', |
|
| 38 | + 'couleur-foncee' => 'basic highlight', |
|
| 39 | + 'trait-couleur' => 'important', |
|
| 40 | + 'alerte' => 'notice', |
|
| 41 | + 'info' => 'info', |
|
| 42 | + 'sous_rub' => 'simple sous-rub' |
|
| 43 | + ); |
|
| 44 | + $style_titre_mapping = array('couleur' => 'topper', 'trait-couleur' => 'section'); |
|
| 45 | + $c = isset($style_mapping[$style]) ? $style_mapping[$style] : 'simple'; |
|
| 46 | + $class = $c . ($class ? " $class" : ""); |
|
| 47 | + if (!$padding) { |
|
| 48 | + $class .= ($class ? " " : "") . "no-padding"; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + //($id?"id='$id' ":"") |
|
| 52 | + if (strlen($icone) > 1) { |
|
| 53 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 54 | + list($fond, $fonction) = $icone_renommer($icone, $fonction); |
|
| 55 | + } |
|
| 56 | + $size = 24; |
|
| 57 | + if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i", $fond, $match)) { |
|
| 58 | + $size = $match[1]; |
|
| 59 | + } |
|
| 60 | + if ($fonction) { |
|
| 61 | + // 2 images pour composer l'icone : le fond (article) en background, |
|
| 62 | + // la fonction (new) en image |
|
| 63 | + $icone = http_img_pack($fonction, "", "class='cadre-icone' width='$size' height='$size'\n" . |
|
| 64 | + http_style_background($fond, "no-repeat center center")); |
|
| 65 | + } else { |
|
| 66 | + $icone = http_img_pack($fond, "", "class='cadre-icone' width='$size' height='$size'"); |
|
| 67 | + } |
|
| 68 | + $titre = $icone . $titre; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + return boite_ouvrir($titre, $class, isset($style_titre_mapping[$style]) ? $style_titre_mapping[$style] : '', $id); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // http://code.spip.net/@fin_cadre |
@@ -76,66 +76,66 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | |
| 78 | 78 | function debut_cadre_relief( |
| 79 | - $icone = '', |
|
| 80 | - $dummy = '', |
|
| 81 | - $fonction = '', |
|
| 82 | - $titre = '', |
|
| 83 | - $id = "", |
|
| 84 | - $class = "" |
|
| 79 | + $icone = '', |
|
| 80 | + $dummy = '', |
|
| 81 | + $fonction = '', |
|
| 82 | + $titre = '', |
|
| 83 | + $id = "", |
|
| 84 | + $class = "" |
|
| 85 | 85 | ) { |
| 86 | - return debut_cadre('r', $icone, $fonction, $titre, $id, $class); |
|
| 86 | + return debut_cadre('r', $icone, $fonction, $titre, $id, $class); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | function fin_cadre_relief() { return fin_cadre('r'); } |
| 90 | 90 | |
| 91 | 91 | function debut_cadre_enfonce( |
| 92 | - $icone = '', |
|
| 93 | - $dummy = '', |
|
| 94 | - $fonction = '', |
|
| 95 | - $titre = '', |
|
| 96 | - $id = "", |
|
| 97 | - $class = "" |
|
| 92 | + $icone = '', |
|
| 93 | + $dummy = '', |
|
| 94 | + $fonction = '', |
|
| 95 | + $titre = '', |
|
| 96 | + $id = "", |
|
| 97 | + $class = "" |
|
| 98 | 98 | ) { |
| 99 | - return debut_cadre('e', $icone, $fonction, $titre, $id, $class); |
|
| 99 | + return debut_cadre('e', $icone, $fonction, $titre, $id, $class); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | function fin_cadre_enfonce() { return fin_cadre('e'); } |
| 103 | 103 | |
| 104 | 104 | function debut_cadre_sous_rub( |
| 105 | - $icone = '', |
|
| 106 | - $dummy = '', |
|
| 107 | - $fonction = '', |
|
| 108 | - $titre = '', |
|
| 109 | - $id = "", |
|
| 110 | - $class = "" |
|
| 105 | + $icone = '', |
|
| 106 | + $dummy = '', |
|
| 107 | + $fonction = '', |
|
| 108 | + $titre = '', |
|
| 109 | + $id = "", |
|
| 110 | + $class = "" |
|
| 111 | 111 | ) { |
| 112 | - return debut_cadre('sous_rub', $icone, $fonction, $titre, $id, $class); |
|
| 112 | + return debut_cadre('sous_rub', $icone, $fonction, $titre, $id, $class); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | function fin_cadre_sous_rub() { return fin_cadre('sous_rub'); } |
| 116 | 116 | |
| 117 | 117 | function debut_cadre_couleur( |
| 118 | - $icone = '', |
|
| 119 | - $dummy = '', |
|
| 120 | - $fonction = '', |
|
| 121 | - $titre = '', |
|
| 122 | - $id = "", |
|
| 123 | - $class = "" |
|
| 118 | + $icone = '', |
|
| 119 | + $dummy = '', |
|
| 120 | + $fonction = '', |
|
| 121 | + $titre = '', |
|
| 122 | + $id = "", |
|
| 123 | + $class = "" |
|
| 124 | 124 | ) { |
| 125 | - return debut_cadre('couleur', $icone, $fonction, $titre, $id, $class); |
|
| 125 | + return debut_cadre('couleur', $icone, $fonction, $titre, $id, $class); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | function fin_cadre_couleur() { return fin_cadre('couleur'); } |
| 129 | 129 | |
| 130 | 130 | function debut_cadre_trait_couleur( |
| 131 | - $icone = '', |
|
| 132 | - $dummy = '', |
|
| 133 | - $fonction = '', |
|
| 134 | - $titre = '', |
|
| 135 | - $id = "", |
|
| 136 | - $class = "" |
|
| 131 | + $icone = '', |
|
| 132 | + $dummy = '', |
|
| 133 | + $fonction = '', |
|
| 134 | + $titre = '', |
|
| 135 | + $id = "", |
|
| 136 | + $class = "" |
|
| 137 | 137 | ) { |
| 138 | - return debut_cadre('trait-couleur', $icone, $fonction, $titre, $id, $class); |
|
| 138 | + return debut_cadre('trait-couleur', $icone, $fonction, $titre, $id, $class); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | function fin_cadre_trait_couleur() { return fin_cadre('trait-couleur'); } |
@@ -156,18 +156,18 @@ discard block |
||
| 156 | 156 | * @return string Code PHP. |
| 157 | 157 | **/ |
| 158 | 158 | function gros_titre( |
| 159 | - $titre, |
|
| 160 | - $ze_logo = '' |
|
| 159 | + $titre, |
|
| 160 | + $ze_logo = '' |
|
| 161 | 161 | ) { |
| 162 | - return "<h1 class = 'grostitre'>" . $ze_logo . ' ' . typo($titre) . "</h1>\n"; |
|
| 162 | + return "<h1 class = 'grostitre'>" . $ze_logo . ' ' . typo($titre) . "</h1>\n"; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // La boite des raccourcis |
| 166 | 166 | // Se place a droite si l'ecran est en mode panoramique. |
| 167 | 167 | // http://code.spip.net/@bloc_des_raccourcis |
| 168 | 168 | function bloc_des_raccourcis($bloc) { |
| 169 | - return creer_colonne_droite() |
|
| 170 | - . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis') . $bloc . boite_fermer(); |
|
| 169 | + return creer_colonne_droite() |
|
| 170 | + . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis') . $bloc . boite_fermer(); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | // |
@@ -184,10 +184,10 @@ discard block |
||
| 184 | 184 | |
| 185 | 185 | // http://code.spip.net/@onglet |
| 186 | 186 | function onglet($texte, $lien, $onglet_ref, $onglet, $icone = "") { |
| 187 | - return "<li>" |
|
| 188 | - . ($icone ? http_img_pack($icone, '', " class='cadre-icone'") : '') |
|
| 189 | - . lien_ou_expose($lien, $texte, $onglet == $onglet_ref) |
|
| 190 | - . "</li>"; |
|
| 187 | + return "<li>" |
|
| 188 | + . ($icone ? http_img_pack($icone, '', " class='cadre-icone'") : '') |
|
| 189 | + . lien_ou_expose($lien, $texte, $onglet == $onglet_ref) |
|
| 190 | + . "</li>"; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -219,14 +219,14 @@ discard block |
||
| 219 | 219 | * Code HTML du lien |
| 220 | 220 | **/ |
| 221 | 221 | function icone_verticale($texte, $lien, $fond, $fonction = "", $align = "", $javascript = "") { |
| 222 | - // cas d'ajax_action_auteur: faut defaire le boulot |
|
| 223 | - // (il faudrait fusionner avec le cas $javascript) |
|
| 224 | - if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) { |
|
| 225 | - list($x, $lien, $atts, $texte) = $r; |
|
| 226 | - $javascript .= $atts; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align", $javascript); |
|
| 222 | + // cas d'ajax_action_auteur: faut defaire le boulot |
|
| 223 | + // (il faudrait fusionner avec le cas $javascript) |
|
| 224 | + if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) { |
|
| 225 | + list($x, $lien, $atts, $texte) = $r; |
|
| 226 | + $javascript .= $atts; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align", $javascript); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -251,15 +251,15 @@ discard block |
||
| 251 | 251 | * Code HTML du lien |
| 252 | 252 | **/ |
| 253 | 253 | function icone_horizontale($texte, $lien, $fond, $fonction = "", $dummy = "", $javascript = "") { |
| 254 | - $retour = ''; |
|
| 255 | - // cas d'ajax_action_auteur: faut defaire le boulot |
|
| 256 | - // (il faudrait fusionner avec le cas $javascript) |
|
| 257 | - if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) { |
|
| 258 | - list($x, $lien, $atts, $texte) = $r; |
|
| 259 | - $javascript .= $atts; |
|
| 260 | - } |
|
| 254 | + $retour = ''; |
|
| 255 | + // cas d'ajax_action_auteur: faut defaire le boulot |
|
| 256 | + // (il faudrait fusionner avec le cas $javascript) |
|
| 257 | + if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) { |
|
| 258 | + list($x, $lien, $atts, $texte) = $r; |
|
| 259 | + $javascript .= $atts; |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - $retour = icone_base($lien, $texte, $fond, $fonction, "horizontale", $javascript); |
|
| 262 | + $retour = icone_base($lien, $texte, $fond, $fonction, "horizontale", $javascript); |
|
| 263 | 263 | |
| 264 | - return $retour; |
|
| 264 | + return $retour; |
|
| 265 | 265 | } |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | ); |
| 44 | 44 | $style_titre_mapping = array('couleur' => 'topper', 'trait-couleur' => 'section'); |
| 45 | 45 | $c = isset($style_mapping[$style]) ? $style_mapping[$style] : 'simple'; |
| 46 | - $class = $c . ($class ? " $class" : ""); |
|
| 46 | + $class = $c.($class ? " $class" : ""); |
|
| 47 | 47 | if (!$padding) { |
| 48 | - $class .= ($class ? " " : "") . "no-padding"; |
|
| 48 | + $class .= ($class ? " " : "")."no-padding"; |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | //($id?"id='$id' ":"") |
@@ -60,12 +60,12 @@ discard block |
||
| 60 | 60 | if ($fonction) { |
| 61 | 61 | // 2 images pour composer l'icone : le fond (article) en background, |
| 62 | 62 | // la fonction (new) en image |
| 63 | - $icone = http_img_pack($fonction, "", "class='cadre-icone' width='$size' height='$size'\n" . |
|
| 63 | + $icone = http_img_pack($fonction, "", "class='cadre-icone' width='$size' height='$size'\n". |
|
| 64 | 64 | http_style_background($fond, "no-repeat center center")); |
| 65 | 65 | } else { |
| 66 | 66 | $icone = http_img_pack($fond, "", "class='cadre-icone' width='$size' height='$size'"); |
| 67 | 67 | } |
| 68 | - $titre = $icone . $titre; |
|
| 68 | + $titre = $icone.$titre; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | return boite_ouvrir($titre, $class, isset($style_titre_mapping[$style]) ? $style_titre_mapping[$style] : '', $id); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $titre, |
| 160 | 160 | $ze_logo = '' |
| 161 | 161 | ) { |
| 162 | - return "<h1 class = 'grostitre'>" . $ze_logo . ' ' . typo($titre) . "</h1>\n"; |
|
| 162 | + return "<h1 class = 'grostitre'>".$ze_logo.' '.typo($titre)."</h1>\n"; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // La boite des raccourcis |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | // http://code.spip.net/@bloc_des_raccourcis |
| 168 | 168 | function bloc_des_raccourcis($bloc) { |
| 169 | 169 | return creer_colonne_droite() |
| 170 | - . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis') . $bloc . boite_fermer(); |
|
| 170 | + . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis').$bloc.boite_fermer(); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | // |
@@ -415,6 +415,13 @@ |
||
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | |
| 418 | +/** |
|
| 419 | + * @param integer $id |
|
| 420 | + * @param string $type |
|
| 421 | + * @param double $n |
|
| 422 | + * @param string|null $img |
|
| 423 | + * @param string $titre |
|
| 424 | + */ |
|
| 418 | 425 | function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act = '') { |
| 419 | 426 | $h = generer_action_auteur("instituer_objet", "$type-$id-$statut"); |
| 420 | 427 | $h = "selec_statut('$id', '$type', $n, jQuery('img',this).attr('src'), '$h');return false;"; |
@@ -18,18 +18,18 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | if (!defined('_ACTIVER_PUCE_RAPIDE')) { |
| 25 | - /** |
|
| 26 | - * Activer le changement rapide de statut sur les listes d'objets ? |
|
| 27 | - * |
|
| 28 | - * Peut ralentir un site sur des listes très longues. |
|
| 29 | - * |
|
| 30 | - * @var bool |
|
| 31 | - **/ |
|
| 32 | - define('_ACTIVER_PUCE_RAPIDE', true); |
|
| 25 | + /** |
|
| 26 | + * Activer le changement rapide de statut sur les listes d'objets ? |
|
| 27 | + * |
|
| 28 | + * Peut ralentir un site sur des listes très longues. |
|
| 29 | + * |
|
| 30 | + * @var bool |
|
| 31 | + **/ |
|
| 32 | + define('_ACTIVER_PUCE_RAPIDE', true); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -57,31 +57,31 @@ discard block |
||
| 57 | 57 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 58 | 58 | */ |
| 59 | 59 | function inc_puce_statut_dist( |
| 60 | - $id_objet, |
|
| 61 | - $statut, |
|
| 62 | - $id_parent, |
|
| 63 | - $type, |
|
| 64 | - $ajax = false, |
|
| 65 | - $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 60 | + $id_objet, |
|
| 61 | + $statut, |
|
| 62 | + $id_parent, |
|
| 63 | + $type, |
|
| 64 | + $ajax = false, |
|
| 65 | + $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 66 | 66 | ) { |
| 67 | - static $f_puce_statut = array(); |
|
| 68 | - $type = objet_type($type); |
|
| 69 | - // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques |
|
| 70 | - if (!isset($f_puce_statut[$type]) or is_null($f_puce_statut[$type])) { |
|
| 71 | - $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true); |
|
| 72 | - } |
|
| 73 | - if ($f_puce_statut[$type]) { |
|
| 74 | - return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - // si statut_image trouve quelque chose (et '' est quelque chose) |
|
| 78 | - // composer une puce, avec si possible changement rapide |
|
| 79 | - elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) { |
|
| 80 | - return $puce; |
|
| 81 | - } // sinon fausse puce avec le type de l'image |
|
| 82 | - else { |
|
| 83 | - return http_img_pack("$type-16.png", ''); |
|
| 84 | - } |
|
| 67 | + static $f_puce_statut = array(); |
|
| 68 | + $type = objet_type($type); |
|
| 69 | + // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques |
|
| 70 | + if (!isset($f_puce_statut[$type]) or is_null($f_puce_statut[$type])) { |
|
| 71 | + $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true); |
|
| 72 | + } |
|
| 73 | + if ($f_puce_statut[$type]) { |
|
| 74 | + return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // si statut_image trouve quelque chose (et '' est quelque chose) |
|
| 78 | + // composer une puce, avec si possible changement rapide |
|
| 79 | + elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) { |
|
| 80 | + return $puce; |
|
| 81 | + } // sinon fausse puce avec le type de l'image |
|
| 82 | + else { |
|
| 83 | + return http_img_pack("$type-16.png", ''); |
|
| 84 | + } |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -110,41 +110,41 @@ discard block |
||
| 110 | 110 | * null si pas capable de déterminer l'image |
| 111 | 111 | */ |
| 112 | 112 | function statut_image($objet, $statut) { |
| 113 | - $src = null; |
|
| 114 | - $table = table_objet_sql($objet); |
|
| 115 | - $desc = lister_tables_objets_sql($table); |
|
| 116 | - if (isset($desc['statut_images'])) { |
|
| 117 | - // si une declaration statut_images |
|
| 118 | - // mais rien pour le statut demande, ne rien afficher |
|
| 119 | - $src = ''; |
|
| 120 | - if (isset($desc['statut_images'][$statut])) { |
|
| 121 | - $src = $desc['statut_images'][$statut]; |
|
| 122 | - } // sinon image par defaut ? |
|
| 123 | - elseif (isset($desc['statut_images'][0])) { |
|
| 124 | - $src = $desc['statut_images'][0]; |
|
| 125 | - } |
|
| 126 | - } else { |
|
| 127 | - switch ($statut) { |
|
| 128 | - case 'prepa': |
|
| 129 | - $src = 'puce-preparer-8.png'; |
|
| 130 | - break; |
|
| 131 | - case 'prop': |
|
| 132 | - $src = 'puce-proposer-8.png'; |
|
| 133 | - break; |
|
| 134 | - case 'publie': |
|
| 135 | - $src = 'puce-publier-8.png'; |
|
| 136 | - break; |
|
| 137 | - case 'refuse': |
|
| 138 | - $src = 'puce-refuser-8.png'; |
|
| 139 | - break; |
|
| 140 | - case 'poubelle': |
|
| 141 | - case 'poub': |
|
| 142 | - $src = 'puce-supprimer-8.png'; |
|
| 143 | - break; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - return $src; |
|
| 113 | + $src = null; |
|
| 114 | + $table = table_objet_sql($objet); |
|
| 115 | + $desc = lister_tables_objets_sql($table); |
|
| 116 | + if (isset($desc['statut_images'])) { |
|
| 117 | + // si une declaration statut_images |
|
| 118 | + // mais rien pour le statut demande, ne rien afficher |
|
| 119 | + $src = ''; |
|
| 120 | + if (isset($desc['statut_images'][$statut])) { |
|
| 121 | + $src = $desc['statut_images'][$statut]; |
|
| 122 | + } // sinon image par defaut ? |
|
| 123 | + elseif (isset($desc['statut_images'][0])) { |
|
| 124 | + $src = $desc['statut_images'][0]; |
|
| 125 | + } |
|
| 126 | + } else { |
|
| 127 | + switch ($statut) { |
|
| 128 | + case 'prepa': |
|
| 129 | + $src = 'puce-preparer-8.png'; |
|
| 130 | + break; |
|
| 131 | + case 'prop': |
|
| 132 | + $src = 'puce-proposer-8.png'; |
|
| 133 | + break; |
|
| 134 | + case 'publie': |
|
| 135 | + $src = 'puce-publier-8.png'; |
|
| 136 | + break; |
|
| 137 | + case 'refuse': |
|
| 138 | + $src = 'puce-refuser-8.png'; |
|
| 139 | + break; |
|
| 140 | + case 'poubelle': |
|
| 141 | + case 'poub': |
|
| 142 | + $src = 'puce-supprimer-8.png'; |
|
| 143 | + break; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + return $src; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -172,40 +172,40 @@ discard block |
||
| 172 | 172 | * @return string |
| 173 | 173 | */ |
| 174 | 174 | function statut_titre($objet, $statut) { |
| 175 | - $titre = ''; |
|
| 176 | - $table = table_objet_sql($objet); |
|
| 177 | - $desc = lister_tables_objets_sql($table); |
|
| 178 | - if (isset($desc['statut_titres'])) { |
|
| 179 | - // si une declaration statut_titres |
|
| 180 | - // mais rien pour le statut demande, ne rien afficher |
|
| 181 | - if (isset($desc['statut_titres'][$statut])) { |
|
| 182 | - $titre = $desc['statut_titres'][$statut]; |
|
| 183 | - } // sinon image par defaut ? |
|
| 184 | - elseif (isset($desc['statut_titres'][0])) { |
|
| 185 | - $titre = $desc['statut_titres'][0]; |
|
| 186 | - } |
|
| 187 | - } else { |
|
| 188 | - switch ($statut) { |
|
| 189 | - case 'prepa': |
|
| 190 | - $titre = 'texte_statut_en_cours_redaction'; |
|
| 191 | - break; |
|
| 192 | - case 'prop': |
|
| 193 | - $titre = 'texte_statut_propose_evaluation'; |
|
| 194 | - break; |
|
| 195 | - case 'publie': |
|
| 196 | - $titre = 'texte_statut_publie'; |
|
| 197 | - break; |
|
| 198 | - case 'refuse': |
|
| 199 | - $titre = 'texte_statut_refuse'; |
|
| 200 | - break; |
|
| 201 | - case 'poubelle': |
|
| 202 | - case 'poub': |
|
| 203 | - $titre = 'texte_statut_poubelle'; |
|
| 204 | - break; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - return $titre ? _T($titre) : ''; |
|
| 175 | + $titre = ''; |
|
| 176 | + $table = table_objet_sql($objet); |
|
| 177 | + $desc = lister_tables_objets_sql($table); |
|
| 178 | + if (isset($desc['statut_titres'])) { |
|
| 179 | + // si une declaration statut_titres |
|
| 180 | + // mais rien pour le statut demande, ne rien afficher |
|
| 181 | + if (isset($desc['statut_titres'][$statut])) { |
|
| 182 | + $titre = $desc['statut_titres'][$statut]; |
|
| 183 | + } // sinon image par defaut ? |
|
| 184 | + elseif (isset($desc['statut_titres'][0])) { |
|
| 185 | + $titre = $desc['statut_titres'][0]; |
|
| 186 | + } |
|
| 187 | + } else { |
|
| 188 | + switch ($statut) { |
|
| 189 | + case 'prepa': |
|
| 190 | + $titre = 'texte_statut_en_cours_redaction'; |
|
| 191 | + break; |
|
| 192 | + case 'prop': |
|
| 193 | + $titre = 'texte_statut_propose_evaluation'; |
|
| 194 | + break; |
|
| 195 | + case 'publie': |
|
| 196 | + $titre = 'texte_statut_publie'; |
|
| 197 | + break; |
|
| 198 | + case 'refuse': |
|
| 199 | + $titre = 'texte_statut_refuse'; |
|
| 200 | + break; |
|
| 201 | + case 'poubelle': |
|
| 202 | + case 'poub': |
|
| 203 | + $titre = 'texte_statut_poubelle'; |
|
| 204 | + break; |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + return $titre ? _T($titre) : ''; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | |
@@ -225,37 +225,37 @@ discard block |
||
| 225 | 225 | * @return string |
| 226 | 226 | */ |
| 227 | 227 | function statut_texte_instituer($objet, $statut) { |
| 228 | - $texte = ''; |
|
| 229 | - $table = table_objet_sql($objet); |
|
| 230 | - $desc = lister_tables_objets_sql($table); |
|
| 231 | - if (isset($desc['statut_textes_instituer'])) { |
|
| 232 | - // si une declaration statut_titres |
|
| 233 | - // mais rien pour le statut demande, ne rien afficher |
|
| 234 | - if (isset($desc['statut_textes_instituer'][$statut])) { |
|
| 235 | - $texte = $desc['statut_textes_instituer'][$statut]; |
|
| 236 | - } |
|
| 237 | - } else { |
|
| 238 | - switch ($statut) { |
|
| 239 | - case 'prepa': |
|
| 240 | - $texte = 'texte_statut_en_cours_redaction'; |
|
| 241 | - break; |
|
| 242 | - case 'prop': |
|
| 243 | - $texte = 'texte_statut_propose_evaluation'; |
|
| 244 | - break; |
|
| 245 | - case 'publie': |
|
| 246 | - $texte = 'texte_statut_publie'; |
|
| 247 | - break; |
|
| 248 | - case 'refuse': |
|
| 249 | - $texte = 'texte_statut_refuse'; |
|
| 250 | - break; |
|
| 251 | - case 'poubelle': |
|
| 252 | - case 'poub': |
|
| 253 | - $texte = 'texte_statut_poubelle'; |
|
| 254 | - break; |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - return $texte ? _T($texte) : ''; |
|
| 228 | + $texte = ''; |
|
| 229 | + $table = table_objet_sql($objet); |
|
| 230 | + $desc = lister_tables_objets_sql($table); |
|
| 231 | + if (isset($desc['statut_textes_instituer'])) { |
|
| 232 | + // si une declaration statut_titres |
|
| 233 | + // mais rien pour le statut demande, ne rien afficher |
|
| 234 | + if (isset($desc['statut_textes_instituer'][$statut])) { |
|
| 235 | + $texte = $desc['statut_textes_instituer'][$statut]; |
|
| 236 | + } |
|
| 237 | + } else { |
|
| 238 | + switch ($statut) { |
|
| 239 | + case 'prepa': |
|
| 240 | + $texte = 'texte_statut_en_cours_redaction'; |
|
| 241 | + break; |
|
| 242 | + case 'prop': |
|
| 243 | + $texte = 'texte_statut_propose_evaluation'; |
|
| 244 | + break; |
|
| 245 | + case 'publie': |
|
| 246 | + $texte = 'texte_statut_publie'; |
|
| 247 | + break; |
|
| 248 | + case 'refuse': |
|
| 249 | + $texte = 'texte_statut_refuse'; |
|
| 250 | + break; |
|
| 251 | + case 'poubelle': |
|
| 252 | + case 'poub': |
|
| 253 | + $texte = 'texte_statut_poubelle'; |
|
| 254 | + break; |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + return $texte ? _T($texte) : ''; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | |
@@ -275,16 +275,16 @@ discard block |
||
| 275 | 275 | * @return string |
| 276 | 276 | */ |
| 277 | 277 | function puce_statut_auteur_dist($id, $statut, $id_parent, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) { |
| 278 | - $img = statut_image('auteur', $statut); |
|
| 279 | - if (!$img) { |
|
| 280 | - return ''; |
|
| 281 | - } |
|
| 282 | - $alt = statut_titre('auteur', $statut); |
|
| 278 | + $img = statut_image('auteur', $statut); |
|
| 279 | + if (!$img) { |
|
| 280 | + return ''; |
|
| 281 | + } |
|
| 282 | + $alt = statut_titre('auteur', $statut); |
|
| 283 | 283 | |
| 284 | - $fond = ''; |
|
| 285 | - $titre = ''; |
|
| 284 | + $fond = ''; |
|
| 285 | + $titre = ''; |
|
| 286 | 286 | |
| 287 | - /* |
|
| 287 | + /* |
|
| 288 | 288 | if ($type != 'auteur') { |
| 289 | 289 | $img2 = chemin_image('del-16.png'); |
| 290 | 290 | $titre = _T('titre_image_redacteur'); |
@@ -294,12 +294,12 @@ discard block |
||
| 294 | 294 | } |
| 295 | 295 | */ |
| 296 | 296 | |
| 297 | - return http_img_pack($img, $alt, $fond, $alt); |
|
| 297 | + return http_img_pack($img, $alt, $fond, $alt); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | |
| 301 | 301 | function puce_statut_rubrique_dist($id, $statut, $id_rubrique, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) { |
| 302 | - return http_img_pack('rubrique-16.png', ''); |
|
| 302 | + return http_img_pack('rubrique-16.png', ''); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -323,114 +323,114 @@ discard block |
||
| 323 | 323 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 324 | 324 | **/ |
| 325 | 325 | function puce_statut_changement_rapide( |
| 326 | - $id, |
|
| 327 | - $statut, |
|
| 328 | - $id_rubrique, |
|
| 329 | - $type = 'article', |
|
| 330 | - $ajax = false, |
|
| 331 | - $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 326 | + $id, |
|
| 327 | + $statut, |
|
| 328 | + $id_rubrique, |
|
| 329 | + $type = 'article', |
|
| 330 | + $ajax = false, |
|
| 331 | + $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 332 | 332 | ) { |
| 333 | - $src = statut_image($type, $statut); |
|
| 334 | - if (!$src) { |
|
| 335 | - return $src; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - if (!$id |
|
| 339 | - or !_SPIP_AJAX |
|
| 340 | - or !$menu_rapide |
|
| 341 | - ) { |
|
| 342 | - $ajax_node = ''; |
|
| 343 | - } else { |
|
| 344 | - $ajax_node = " class='imgstatut$type$id'"; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - $t = statut_titre($type, $statut); |
|
| 349 | - $inser_puce = http_img_pack($src, $t, $ajax_node, $t); |
|
| 350 | - |
|
| 351 | - if (!$ajax_node) { |
|
| 352 | - return $inser_puce; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - $table = table_objet_sql($type); |
|
| 356 | - $desc = lister_tables_objets_sql($table); |
|
| 357 | - if (!isset($desc['statut_textes_instituer'])) { |
|
| 358 | - return $inser_puce; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - if (!function_exists('autoriser')) { |
|
| 362 | - include_spip('inc/autoriser'); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique) |
|
| 366 | - if ($id_rubrique) { |
|
| 367 | - if (!autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 368 | - return $inser_puce; |
|
| 369 | - } |
|
| 370 | - } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie |
|
| 371 | - else { |
|
| 372 | - if (!autoriser('instituer', $type, $id, null, array('statut' => 'publie'))) { |
|
| 373 | - return $inser_puce; |
|
| 374 | - } |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - $coord = array_flip(array_keys($desc['statut_textes_instituer'])); |
|
| 378 | - if (!isset($coord[$statut])) { |
|
| 379 | - return $inser_puce; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - $unit = 8/*widh de img*/ + 4/*padding*/ |
|
| 383 | - ; |
|
| 384 | - $margin = 4; /* marge a gauche + droite */ |
|
| 385 | - $zero = 1 /*border*/ + $margin / 2 + 2 /*padding*/ |
|
| 386 | - ; |
|
| 387 | - $clip = $zero + ($unit * $coord[$statut]); |
|
| 388 | - |
|
| 389 | - if ($ajax) { |
|
| 390 | - $width = $unit * count($desc['statut_textes_instituer']) + $margin; |
|
| 391 | - $out = "<span class='puce_objet_fixe $type'>" |
|
| 392 | - . $inser_puce |
|
| 393 | - . "</span>" |
|
| 394 | - . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>"; |
|
| 395 | - $i = 0; |
|
| 396 | - foreach ($desc['statut_textes_instituer'] as $s => $t) { |
|
| 397 | - $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
|
| 398 | - } |
|
| 399 | - $out .= "</span>"; |
|
| 400 | - |
|
| 401 | - return $out; |
|
| 402 | - } else { |
|
| 403 | - |
|
| 404 | - $nom = "puce_statut_"; |
|
| 405 | - $action = generer_url_ecrire('puce_statut', "", true); |
|
| 406 | - $action = "if (!this.puce_loaded) { this.puce_loaded = true; prepare_selec_statut(this, '$nom', '$type', '$id', '$action'); }"; |
|
| 407 | - $over = " onmouseover=\"$action\""; |
|
| 408 | - |
|
| 409 | - $lang_dir = lang_dir(lang_typo()); |
|
| 410 | - |
|
| 411 | - return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir'$over>" |
|
| 412 | - . $inser_puce |
|
| 413 | - . '</span>'; |
|
| 414 | - } |
|
| 333 | + $src = statut_image($type, $statut); |
|
| 334 | + if (!$src) { |
|
| 335 | + return $src; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + if (!$id |
|
| 339 | + or !_SPIP_AJAX |
|
| 340 | + or !$menu_rapide |
|
| 341 | + ) { |
|
| 342 | + $ajax_node = ''; |
|
| 343 | + } else { |
|
| 344 | + $ajax_node = " class='imgstatut$type$id'"; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + $t = statut_titre($type, $statut); |
|
| 349 | + $inser_puce = http_img_pack($src, $t, $ajax_node, $t); |
|
| 350 | + |
|
| 351 | + if (!$ajax_node) { |
|
| 352 | + return $inser_puce; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + $table = table_objet_sql($type); |
|
| 356 | + $desc = lister_tables_objets_sql($table); |
|
| 357 | + if (!isset($desc['statut_textes_instituer'])) { |
|
| 358 | + return $inser_puce; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + if (!function_exists('autoriser')) { |
|
| 362 | + include_spip('inc/autoriser'); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique) |
|
| 366 | + if ($id_rubrique) { |
|
| 367 | + if (!autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 368 | + return $inser_puce; |
|
| 369 | + } |
|
| 370 | + } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie |
|
| 371 | + else { |
|
| 372 | + if (!autoriser('instituer', $type, $id, null, array('statut' => 'publie'))) { |
|
| 373 | + return $inser_puce; |
|
| 374 | + } |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + $coord = array_flip(array_keys($desc['statut_textes_instituer'])); |
|
| 378 | + if (!isset($coord[$statut])) { |
|
| 379 | + return $inser_puce; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + $unit = 8/*widh de img*/ + 4/*padding*/ |
|
| 383 | + ; |
|
| 384 | + $margin = 4; /* marge a gauche + droite */ |
|
| 385 | + $zero = 1 /*border*/ + $margin / 2 + 2 /*padding*/ |
|
| 386 | + ; |
|
| 387 | + $clip = $zero + ($unit * $coord[$statut]); |
|
| 388 | + |
|
| 389 | + if ($ajax) { |
|
| 390 | + $width = $unit * count($desc['statut_textes_instituer']) + $margin; |
|
| 391 | + $out = "<span class='puce_objet_fixe $type'>" |
|
| 392 | + . $inser_puce |
|
| 393 | + . "</span>" |
|
| 394 | + . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>"; |
|
| 395 | + $i = 0; |
|
| 396 | + foreach ($desc['statut_textes_instituer'] as $s => $t) { |
|
| 397 | + $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
|
| 398 | + } |
|
| 399 | + $out .= "</span>"; |
|
| 400 | + |
|
| 401 | + return $out; |
|
| 402 | + } else { |
|
| 403 | + |
|
| 404 | + $nom = "puce_statut_"; |
|
| 405 | + $action = generer_url_ecrire('puce_statut', "", true); |
|
| 406 | + $action = "if (!this.puce_loaded) { this.puce_loaded = true; prepare_selec_statut(this, '$nom', '$type', '$id', '$action'); }"; |
|
| 407 | + $over = " onmouseover=\"$action\""; |
|
| 408 | + |
|
| 409 | + $lang_dir = lang_dir(lang_typo()); |
|
| 410 | + |
|
| 411 | + return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir'$over>" |
|
| 412 | + . $inser_puce |
|
| 413 | + . '</span>'; |
|
| 414 | + } |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | |
| 418 | 418 | function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act = '') { |
| 419 | - $h = generer_action_auteur("instituer_objet", "$type-$id-$statut"); |
|
| 420 | - $h = "selec_statut('$id', '$type', $n, jQuery('img',this).attr('src'), '$h');return false;"; |
|
| 421 | - $t = supprimer_tags($titre); |
|
| 419 | + $h = generer_action_auteur("instituer_objet", "$type-$id-$statut"); |
|
| 420 | + $h = "selec_statut('$id', '$type', $n, jQuery('img',this).attr('src'), '$h');return false;"; |
|
| 421 | + $t = supprimer_tags($titre); |
|
| 422 | 422 | |
| 423 | - return "<a href=\"#\" onclick=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . "</a>"; |
|
| 423 | + return "<a href=\"#\" onclick=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . "</a>"; |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | // compat |
| 427 | 427 | // La couleur du statut |
| 428 | 428 | |
| 429 | 429 | function puce_statut($statut, $atts = '') { |
| 430 | - $src = statut_image('article', $statut); |
|
| 431 | - if (!$src) { |
|
| 432 | - return ''; |
|
| 433 | - } |
|
| 430 | + $src = statut_image('article', $statut); |
|
| 431 | + if (!$src) { |
|
| 432 | + return ''; |
|
| 433 | + } |
|
| 434 | 434 | |
| 435 | - return http_img_pack($src, statut_titre('article', $statut), $atts); |
|
| 435 | + return http_img_pack($src, statut_titre('article', $statut), $atts); |
|
| 436 | 436 | } |
@@ -420,7 +420,7 @@ |
||
| 420 | 420 | $h = "selec_statut('$id', '$type', $n, jQuery('img',this).attr('src'), '$h');return false;"; |
| 421 | 421 | $t = supprimer_tags($titre); |
| 422 | 422 | |
| 423 | - return "<a href=\"#\" onclick=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . "</a>"; |
|
| 423 | + return "<a href=\"#\" onclick=\"$h\" title=\"$t\"$act>".http_img_pack($img, $t)."</a>"; |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | // compat |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * Ancien statut de la rubrique |
| 51 | 51 | * @param bool $postdate |
| 52 | 52 | * true pour recalculer aussi la date du prochain article post-daté |
| 53 | - * @return bool |
|
| 53 | + * @return boolean|null |
|
| 54 | 54 | * true si le statut change effectivement |
| 55 | 55 | **/ |
| 56 | 56 | function calculer_rubriques_if($id_rubrique, $modifs, $statut_ancien = '', $postdate = false) { |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | * de la rubrique parente lorsque langue_choisie est différent de oui, |
| 425 | 425 | * et les corrige. |
| 426 | 426 | * |
| 427 | - * @return bool |
|
| 427 | + * @return boolean|string |
|
| 428 | 428 | * true si un changement a eu lieu |
| 429 | 429 | **/ |
| 430 | 430 | function calculer_langues_rubriques_etape() { |
@@ -78,10 +78,12 @@ |
||
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - if ($neuf) // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 81 | + if ($neuf) { |
|
| 82 | + // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 82 | 83 | { |
| 83 | 84 | ecrire_meta("date_calcul_rubriques", date("U")); |
| 84 | 85 | } |
| 86 | + } |
|
| 85 | 87 | |
| 86 | 88 | $langues = calculer_langues_utilisees(); |
| 87 | 89 | ecrire_meta('langues_utilisees', $langues); |
@@ -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 | |
@@ -54,37 +54,37 @@ discard block |
||
| 54 | 54 | * true si le statut change effectivement |
| 55 | 55 | **/ |
| 56 | 56 | function calculer_rubriques_if($id_rubrique, $modifs, $statut_ancien = '', $postdate = false) { |
| 57 | - $neuf = false; |
|
| 58 | - if ($statut_ancien == 'publie') { |
|
| 59 | - if (isset($modifs['statut']) |
|
| 60 | - or isset($modifs['id_rubrique']) |
|
| 61 | - or ($postdate and strtotime($postdate) > time()) |
|
| 62 | - ) { |
|
| 63 | - $neuf |= depublier_branche_rubrique_if($id_rubrique); |
|
| 64 | - } |
|
| 65 | - // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur |
|
| 66 | - if ($postdate) { |
|
| 67 | - calculer_prochain_postdate(true); |
|
| 68 | - $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 69 | - } elseif (isset($modifs['id_rubrique'])) { |
|
| 70 | - $neuf |= publier_branche_rubrique($modifs['id_rubrique']); |
|
| 71 | - } |
|
| 72 | - } elseif (isset($modifs['statut']) and $modifs['statut'] == 'publie') { |
|
| 73 | - if ($postdate) { |
|
| 74 | - calculer_prochain_postdate(true); |
|
| 75 | - $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 76 | - } else { |
|
| 77 | - $neuf |= publier_branche_rubrique($id_rubrique); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - if ($neuf) // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 82 | - { |
|
| 83 | - ecrire_meta("date_calcul_rubriques", date("U")); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - $langues = calculer_langues_utilisees(); |
|
| 87 | - ecrire_meta('langues_utilisees', $langues); |
|
| 57 | + $neuf = false; |
|
| 58 | + if ($statut_ancien == 'publie') { |
|
| 59 | + if (isset($modifs['statut']) |
|
| 60 | + or isset($modifs['id_rubrique']) |
|
| 61 | + or ($postdate and strtotime($postdate) > time()) |
|
| 62 | + ) { |
|
| 63 | + $neuf |= depublier_branche_rubrique_if($id_rubrique); |
|
| 64 | + } |
|
| 65 | + // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur |
|
| 66 | + if ($postdate) { |
|
| 67 | + calculer_prochain_postdate(true); |
|
| 68 | + $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 69 | + } elseif (isset($modifs['id_rubrique'])) { |
|
| 70 | + $neuf |= publier_branche_rubrique($modifs['id_rubrique']); |
|
| 71 | + } |
|
| 72 | + } elseif (isset($modifs['statut']) and $modifs['statut'] == 'publie') { |
|
| 73 | + if ($postdate) { |
|
| 74 | + calculer_prochain_postdate(true); |
|
| 75 | + $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 76 | + } else { |
|
| 77 | + $neuf |= publier_branche_rubrique($id_rubrique); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + if ($neuf) // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 82 | + { |
|
| 83 | + ecrire_meta("date_calcul_rubriques", date("U")); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + $langues = calculer_langues_utilisees(); |
|
| 87 | + ecrire_meta('langues_utilisees', $langues); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | |
@@ -102,19 +102,19 @@ discard block |
||
| 102 | 102 | * true si le statut change effectivement |
| 103 | 103 | */ |
| 104 | 104 | function publier_branche_rubrique($id_rubrique) { |
| 105 | - $id_pred = $id_rubrique; |
|
| 106 | - while (true) { |
|
| 107 | - sql_updateq('spip_rubriques', array('statut' => 'publie', 'date' => date('Y-m-d H:i:s')), |
|
| 108 | - "id_rubrique=" . intval($id_rubrique)); |
|
| 109 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', "R.id_rubrique=" . intval($id_rubrique)); |
|
| 110 | - if (!$id_parent) { |
|
| 111 | - break; |
|
| 112 | - } |
|
| 113 | - $id_rubrique = $id_parent; |
|
| 114 | - } |
|
| 105 | + $id_pred = $id_rubrique; |
|
| 106 | + while (true) { |
|
| 107 | + sql_updateq('spip_rubriques', array('statut' => 'publie', 'date' => date('Y-m-d H:i:s')), |
|
| 108 | + "id_rubrique=" . intval($id_rubrique)); |
|
| 109 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', "R.id_rubrique=" . intval($id_rubrique)); |
|
| 110 | + if (!$id_parent) { |
|
| 111 | + break; |
|
| 112 | + } |
|
| 113 | + $id_rubrique = $id_parent; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | 116 | # spip_log(" publier_branche_rubrique($id_rubrique $id_pred"); |
| 117 | - return $id_pred != $id_rubrique; |
|
| 117 | + return $id_pred != $id_rubrique; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -132,21 +132,21 @@ discard block |
||
| 132 | 132 | * true si le statut change effectivement |
| 133 | 133 | */ |
| 134 | 134 | function depublier_branche_rubrique_if($id_rubrique) { |
| 135 | - $date = date('Y-m-d H:i:s'); // figer la date |
|
| 135 | + $date = date('Y-m-d H:i:s'); // figer la date |
|
| 136 | 136 | |
| 137 | - # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 138 | - $id_pred = $id_rubrique; |
|
| 139 | - while ($id_pred) { |
|
| 137 | + # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 138 | + $id_pred = $id_rubrique; |
|
| 139 | + while ($id_pred) { |
|
| 140 | 140 | |
| 141 | - if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 142 | - return $id_pred != $id_rubrique; |
|
| 143 | - } |
|
| 144 | - // passer au parent si on a depublie |
|
| 145 | - $r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=" . intval($id_pred)); |
|
| 146 | - $id_pred = $r['id_parent']; |
|
| 147 | - } |
|
| 141 | + if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 142 | + return $id_pred != $id_rubrique; |
|
| 143 | + } |
|
| 144 | + // passer au parent si on a depublie |
|
| 145 | + $r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=" . intval($id_pred)); |
|
| 146 | + $id_pred = $r['id_parent']; |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - return $id_pred != $id_rubrique; |
|
| 149 | + return $id_pred != $id_rubrique; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -163,55 +163,55 @@ discard block |
||
| 163 | 163 | * true si la rubrique a été dépubliée |
| 164 | 164 | */ |
| 165 | 165 | function depublier_rubrique_if($id_rubrique, $date = null) { |
| 166 | - if (is_null($date)) { |
|
| 167 | - $date = date('Y-m-d H:i:s'); |
|
| 168 | - } |
|
| 169 | - $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
|
| 170 | - " AND date <= " . sql_quote($date) : ''; |
|
| 171 | - |
|
| 172 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 173 | - return false; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - // verifier qu'elle existe et est bien publiee |
|
| 177 | - $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', "id_rubrique=" . intval($id_rubrique)); |
|
| 178 | - if (!$r or $r['statut'] !== 'publie') { |
|
| 179 | - return false; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - // On met le nombre de chaque type d'enfants dans un tableau |
|
| 183 | - // Le type de l'objet est au pluriel |
|
| 184 | - $compte = array( |
|
| 185 | - 'articles' => sql_countsel("spip_articles", |
|
| 186 | - "id_rubrique=" . intval($id_rubrique) . " AND statut='publie'$postdates"), |
|
| 187 | - 'rubriques' => sql_countsel("spip_rubriques", "id_parent=" . intval($id_rubrique) . " AND statut='publie'"), |
|
| 188 | - 'documents' => sql_countsel("spip_documents_liens", "id_objet=" . intval($id_rubrique) . " AND objet='rubrique'") |
|
| 189 | - ); |
|
| 190 | - |
|
| 191 | - // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 192 | - $compte = pipeline('objet_compte_enfants', |
|
| 193 | - array( |
|
| 194 | - 'args' => array( |
|
| 195 | - 'objet' => 'rubrique', |
|
| 196 | - 'id_objet' => $id_rubrique, |
|
| 197 | - 'statut' => 'publie', |
|
| 198 | - 'date' => $date |
|
| 199 | - ), |
|
| 200 | - 'data' => $compte |
|
| 201 | - ) |
|
| 202 | - ); |
|
| 203 | - |
|
| 204 | - // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 205 | - foreach ($compte as $objet => $n) { |
|
| 206 | - if ($n) { |
|
| 207 | - return false; |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - sql_updateq("spip_rubriques", array("statut" => 'prepa'), "id_rubrique=" . intval($id_rubrique)); |
|
| 166 | + if (is_null($date)) { |
|
| 167 | + $date = date('Y-m-d H:i:s'); |
|
| 168 | + } |
|
| 169 | + $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
|
| 170 | + " AND date <= " . sql_quote($date) : ''; |
|
| 171 | + |
|
| 172 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + // verifier qu'elle existe et est bien publiee |
|
| 177 | + $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', "id_rubrique=" . intval($id_rubrique)); |
|
| 178 | + if (!$r or $r['statut'] !== 'publie') { |
|
| 179 | + return false; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + // On met le nombre de chaque type d'enfants dans un tableau |
|
| 183 | + // Le type de l'objet est au pluriel |
|
| 184 | + $compte = array( |
|
| 185 | + 'articles' => sql_countsel("spip_articles", |
|
| 186 | + "id_rubrique=" . intval($id_rubrique) . " AND statut='publie'$postdates"), |
|
| 187 | + 'rubriques' => sql_countsel("spip_rubriques", "id_parent=" . intval($id_rubrique) . " AND statut='publie'"), |
|
| 188 | + 'documents' => sql_countsel("spip_documents_liens", "id_objet=" . intval($id_rubrique) . " AND objet='rubrique'") |
|
| 189 | + ); |
|
| 190 | + |
|
| 191 | + // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 192 | + $compte = pipeline('objet_compte_enfants', |
|
| 193 | + array( |
|
| 194 | + 'args' => array( |
|
| 195 | + 'objet' => 'rubrique', |
|
| 196 | + 'id_objet' => $id_rubrique, |
|
| 197 | + 'statut' => 'publie', |
|
| 198 | + 'date' => $date |
|
| 199 | + ), |
|
| 200 | + 'data' => $compte |
|
| 201 | + ) |
|
| 202 | + ); |
|
| 203 | + |
|
| 204 | + // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 205 | + foreach ($compte as $objet => $n) { |
|
| 206 | + if ($n) { |
|
| 207 | + return false; |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + sql_updateq("spip_rubriques", array("statut" => 'prepa'), "id_rubrique=" . intval($id_rubrique)); |
|
| 212 | 212 | |
| 213 | 213 | # spip_log("depublier_rubrique $id_pred"); |
| 214 | - return true; |
|
| 214 | + return true; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | |
@@ -234,18 +234,18 @@ discard block |
||
| 234 | 234 | **/ |
| 235 | 235 | function calculer_rubriques() { |
| 236 | 236 | |
| 237 | - calculer_rubriques_publiees(); |
|
| 237 | + calculer_rubriques_publiees(); |
|
| 238 | 238 | |
| 239 | - // Apres chaque (de)publication |
|
| 240 | - // recalculer les langues utilisees sur le site |
|
| 241 | - $langues = calculer_langues_utilisees(); |
|
| 242 | - ecrire_meta('langues_utilisees', $langues); |
|
| 239 | + // Apres chaque (de)publication |
|
| 240 | + // recalculer les langues utilisees sur le site |
|
| 241 | + $langues = calculer_langues_utilisees(); |
|
| 242 | + ecrire_meta('langues_utilisees', $langues); |
|
| 243 | 243 | |
| 244 | - // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 245 | - ecrire_meta("date_calcul_rubriques", date("U")); |
|
| 244 | + // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 245 | + ecrire_meta("date_calcul_rubriques", date("U")); |
|
| 246 | 246 | |
| 247 | - // on calcule la date du prochain article post-date |
|
| 248 | - calculer_prochain_postdate(); |
|
| 247 | + // on calcule la date du prochain article post-date |
|
| 248 | + calculer_prochain_postdate(); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | |
@@ -262,51 +262,51 @@ discard block |
||
| 262 | 262 | **/ |
| 263 | 263 | function calculer_rubriques_publiees() { |
| 264 | 264 | |
| 265 | - // Mettre les compteurs a zero |
|
| 266 | - sql_updateq('spip_rubriques', array('date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa')); |
|
| 267 | - |
|
| 268 | - // |
|
| 269 | - // Publier et dater les rubriques qui ont un article publie |
|
| 270 | - // |
|
| 271 | - |
|
| 272 | - // Afficher les articles post-dates ? |
|
| 273 | - $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
|
| 274 | - "AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 275 | - |
|
| 276 | - $r = sql_select( |
|
| 277 | - "R.id_rubrique AS id, max(A.date) AS date_h", |
|
| 278 | - "spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique", |
|
| 279 | - "A.date>R.date_tmp AND A.statut='publie' $postdates ", "R.id_rubrique"); |
|
| 280 | - while ($row = sql_fetch($r)) { |
|
| 281 | - sql_updateq("spip_rubriques", array("statut_tmp" => 'publie', "date_tmp" => $row['date_h']), |
|
| 282 | - "id_rubrique=" . intval($row['id'])); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - // point d'entree pour permettre a des plugins de gerer le statut |
|
| 286 | - // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 287 | - // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 288 | - // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 289 | - // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 290 | - pipeline('calculer_rubriques', null); |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - // Les rubriques qui ont une rubrique fille plus recente |
|
| 294 | - // on tourne tant que les donnees remontent vers la racine. |
|
| 295 | - do { |
|
| 296 | - $continuer = false; |
|
| 297 | - $r = sql_select( |
|
| 298 | - "R.id_rubrique AS id, max(SR.date_tmp) AS date_h", |
|
| 299 | - "spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent", |
|
| 300 | - "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", "R.id_rubrique"); |
|
| 301 | - while ($row = sql_fetch($r)) { |
|
| 302 | - sql_updateq('spip_rubriques', array('statut_tmp' => 'publie', 'date_tmp' => $row['date_h']), |
|
| 303 | - "id_rubrique=" . intval($row['id'])); |
|
| 304 | - $continuer = true; |
|
| 305 | - } |
|
| 306 | - } while ($continuer); |
|
| 307 | - |
|
| 308 | - // Enregistrement des modifs |
|
| 309 | - sql_update('spip_rubriques', array('date' => 'date_tmp', 'statut' => 'statut_tmp')); |
|
| 265 | + // Mettre les compteurs a zero |
|
| 266 | + sql_updateq('spip_rubriques', array('date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa')); |
|
| 267 | + |
|
| 268 | + // |
|
| 269 | + // Publier et dater les rubriques qui ont un article publie |
|
| 270 | + // |
|
| 271 | + |
|
| 272 | + // Afficher les articles post-dates ? |
|
| 273 | + $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
|
| 274 | + "AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 275 | + |
|
| 276 | + $r = sql_select( |
|
| 277 | + "R.id_rubrique AS id, max(A.date) AS date_h", |
|
| 278 | + "spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique", |
|
| 279 | + "A.date>R.date_tmp AND A.statut='publie' $postdates ", "R.id_rubrique"); |
|
| 280 | + while ($row = sql_fetch($r)) { |
|
| 281 | + sql_updateq("spip_rubriques", array("statut_tmp" => 'publie', "date_tmp" => $row['date_h']), |
|
| 282 | + "id_rubrique=" . intval($row['id'])); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + // point d'entree pour permettre a des plugins de gerer le statut |
|
| 286 | + // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 287 | + // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 288 | + // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 289 | + // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 290 | + pipeline('calculer_rubriques', null); |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + // Les rubriques qui ont une rubrique fille plus recente |
|
| 294 | + // on tourne tant que les donnees remontent vers la racine. |
|
| 295 | + do { |
|
| 296 | + $continuer = false; |
|
| 297 | + $r = sql_select( |
|
| 298 | + "R.id_rubrique AS id, max(SR.date_tmp) AS date_h", |
|
| 299 | + "spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent", |
|
| 300 | + "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", "R.id_rubrique"); |
|
| 301 | + while ($row = sql_fetch($r)) { |
|
| 302 | + sql_updateq('spip_rubriques', array('statut_tmp' => 'publie', 'date_tmp' => $row['date_h']), |
|
| 303 | + "id_rubrique=" . intval($row['id'])); |
|
| 304 | + $continuer = true; |
|
| 305 | + } |
|
| 306 | + } while ($continuer); |
|
| 307 | + |
|
| 308 | + // Enregistrement des modifs |
|
| 309 | + sql_update('spip_rubriques', array('date' => 'date_tmp', 'statut' => 'statut_tmp')); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -321,99 +321,99 @@ discard block |
||
| 321 | 321 | * @return void |
| 322 | 322 | **/ |
| 323 | 323 | function propager_les_secteurs() { |
| 324 | - // Profondeur 0 |
|
| 325 | - // Toutes les rubriques racines sont de profondeur 0 |
|
| 326 | - // et fixer les id_secteur des rubriques racines |
|
| 327 | - sql_update('spip_rubriques', array('id_secteur' => 'id_rubrique', 'profondeur' => 0), "id_parent=0"); |
|
| 328 | - // Toute rubrique non racine est de profondeur >0 |
|
| 329 | - sql_updateq('spip_rubriques', array('profondeur' => 1), "id_parent<>0 AND profondeur=0"); |
|
| 330 | - |
|
| 331 | - // securite : pas plus d'iteration que de rubriques dans la base |
|
| 332 | - $maxiter = sql_countsel("spip_rubriques"); |
|
| 333 | - |
|
| 334 | - // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 335 | - // on fait profondeur par profondeur |
|
| 336 | - |
|
| 337 | - $prof = 0; |
|
| 338 | - do { |
|
| 339 | - $continuer = false; |
|
| 340 | - |
|
| 341 | - // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 342 | - // on fixe le profondeur $prof+1 |
|
| 343 | - |
|
| 344 | - // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 345 | - // on teste A.profondeur > $prof+1 car : |
|
| 346 | - // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 347 | - // - si A.profondeur = $prof+1 c'est bon |
|
| 348 | - // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 349 | - $maxiter2 = $maxiter; |
|
| 350 | - while ($maxiter2-- |
|
| 351 | - and $rows = sql_allfetsel( |
|
| 352 | - "A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur", |
|
| 353 | - "spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique", |
|
| 354 | - "R.profondeur=" . intval($prof) . " AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)", |
|
| 355 | - "", "R.id_secteur", "0,100")) { |
|
| 356 | - |
|
| 357 | - $id_secteur = null; |
|
| 358 | - $ids = array(); |
|
| 359 | - while ($row = array_shift($rows)) { |
|
| 360 | - if ($row['id_secteur'] !== $id_secteur) { |
|
| 361 | - if (count($ids)) { |
|
| 362 | - sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1), |
|
| 363 | - sql_in('id_rubrique', $ids)); |
|
| 364 | - } |
|
| 365 | - $id_secteur = $row['id_secteur']; |
|
| 366 | - $ids = array(); |
|
| 367 | - } |
|
| 368 | - $ids[] = $row['id']; |
|
| 369 | - } |
|
| 370 | - if (count($ids)) { |
|
| 371 | - sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1), |
|
| 372 | - sql_in('id_rubrique', $ids)); |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 378 | - $maxiter2 = $maxiter; |
|
| 379 | - while ($maxiter2-- |
|
| 380 | - and $rows = sql_allfetsel( |
|
| 381 | - "id_rubrique as id", |
|
| 382 | - "spip_rubriques", |
|
| 383 | - "profondeur=" . intval($prof + 1) . " AND id_parent NOT IN (" . sql_get_select("zzz.id_rubrique", |
|
| 384 | - "spip_rubriques AS zzz", "zzz.profondeur=" . intval($prof)) . ")", '', '', '0,100')) { |
|
| 385 | - $rows = array_column($rows, 'id'); |
|
| 386 | - sql_updateq("spip_rubriques", array('profondeur' => $prof + 2), sql_in("id_rubrique", $rows)); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 390 | - // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 391 | - // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 392 | - // on arrete les frais |
|
| 393 | - if (sql_countsel("spip_rubriques", "profondeur=" . intval($prof + 1))) { |
|
| 394 | - $prof++; |
|
| 395 | - $continuer = true; |
|
| 396 | - } |
|
| 397 | - } while ($continuer and $maxiter--); |
|
| 398 | - |
|
| 399 | - // loger si la table des rubriques semble foireuse |
|
| 400 | - // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 401 | - if (sql_countsel("spip_rubriques", "profondeur>" . intval($prof + 1))) { |
|
| 402 | - spip_log("Les rubriques de profondeur>" . ($prof + 1) . " semblent suspectes (branches morte ou reference circulaire dans les parents)", |
|
| 403 | - _LOG_CRITIQUE); |
|
| 404 | - sql_update("spip_rubriques", array('id_secteur' => 0), "profondeur>" . intval($prof + 1)); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - // reparer les articles |
|
| 408 | - $r = sql_select("A.id_article AS id, R.id_secteur AS secteur", "spip_articles AS A, spip_rubriques AS R", |
|
| 409 | - "A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur"); |
|
| 410 | - |
|
| 411 | - while ($row = sql_fetch($r)) { |
|
| 412 | - sql_update("spip_articles", array("id_secteur" => $row['secteur']), "id_article=" . intval($row['id'])); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 416 | - pipeline('trig_propager_les_secteurs', ''); |
|
| 324 | + // Profondeur 0 |
|
| 325 | + // Toutes les rubriques racines sont de profondeur 0 |
|
| 326 | + // et fixer les id_secteur des rubriques racines |
|
| 327 | + sql_update('spip_rubriques', array('id_secteur' => 'id_rubrique', 'profondeur' => 0), "id_parent=0"); |
|
| 328 | + // Toute rubrique non racine est de profondeur >0 |
|
| 329 | + sql_updateq('spip_rubriques', array('profondeur' => 1), "id_parent<>0 AND profondeur=0"); |
|
| 330 | + |
|
| 331 | + // securite : pas plus d'iteration que de rubriques dans la base |
|
| 332 | + $maxiter = sql_countsel("spip_rubriques"); |
|
| 333 | + |
|
| 334 | + // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 335 | + // on fait profondeur par profondeur |
|
| 336 | + |
|
| 337 | + $prof = 0; |
|
| 338 | + do { |
|
| 339 | + $continuer = false; |
|
| 340 | + |
|
| 341 | + // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 342 | + // on fixe le profondeur $prof+1 |
|
| 343 | + |
|
| 344 | + // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 345 | + // on teste A.profondeur > $prof+1 car : |
|
| 346 | + // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 347 | + // - si A.profondeur = $prof+1 c'est bon |
|
| 348 | + // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 349 | + $maxiter2 = $maxiter; |
|
| 350 | + while ($maxiter2-- |
|
| 351 | + and $rows = sql_allfetsel( |
|
| 352 | + "A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur", |
|
| 353 | + "spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique", |
|
| 354 | + "R.profondeur=" . intval($prof) . " AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)", |
|
| 355 | + "", "R.id_secteur", "0,100")) { |
|
| 356 | + |
|
| 357 | + $id_secteur = null; |
|
| 358 | + $ids = array(); |
|
| 359 | + while ($row = array_shift($rows)) { |
|
| 360 | + if ($row['id_secteur'] !== $id_secteur) { |
|
| 361 | + if (count($ids)) { |
|
| 362 | + sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1), |
|
| 363 | + sql_in('id_rubrique', $ids)); |
|
| 364 | + } |
|
| 365 | + $id_secteur = $row['id_secteur']; |
|
| 366 | + $ids = array(); |
|
| 367 | + } |
|
| 368 | + $ids[] = $row['id']; |
|
| 369 | + } |
|
| 370 | + if (count($ids)) { |
|
| 371 | + sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1), |
|
| 372 | + sql_in('id_rubrique', $ids)); |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 378 | + $maxiter2 = $maxiter; |
|
| 379 | + while ($maxiter2-- |
|
| 380 | + and $rows = sql_allfetsel( |
|
| 381 | + "id_rubrique as id", |
|
| 382 | + "spip_rubriques", |
|
| 383 | + "profondeur=" . intval($prof + 1) . " AND id_parent NOT IN (" . sql_get_select("zzz.id_rubrique", |
|
| 384 | + "spip_rubriques AS zzz", "zzz.profondeur=" . intval($prof)) . ")", '', '', '0,100')) { |
|
| 385 | + $rows = array_column($rows, 'id'); |
|
| 386 | + sql_updateq("spip_rubriques", array('profondeur' => $prof + 2), sql_in("id_rubrique", $rows)); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 390 | + // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 391 | + // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 392 | + // on arrete les frais |
|
| 393 | + if (sql_countsel("spip_rubriques", "profondeur=" . intval($prof + 1))) { |
|
| 394 | + $prof++; |
|
| 395 | + $continuer = true; |
|
| 396 | + } |
|
| 397 | + } while ($continuer and $maxiter--); |
|
| 398 | + |
|
| 399 | + // loger si la table des rubriques semble foireuse |
|
| 400 | + // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 401 | + if (sql_countsel("spip_rubriques", "profondeur>" . intval($prof + 1))) { |
|
| 402 | + spip_log("Les rubriques de profondeur>" . ($prof + 1) . " semblent suspectes (branches morte ou reference circulaire dans les parents)", |
|
| 403 | + _LOG_CRITIQUE); |
|
| 404 | + sql_update("spip_rubriques", array('id_secteur' => 0), "profondeur>" . intval($prof + 1)); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + // reparer les articles |
|
| 408 | + $r = sql_select("A.id_article AS id, R.id_secteur AS secteur", "spip_articles AS A, spip_rubriques AS R", |
|
| 409 | + "A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur"); |
|
| 410 | + |
|
| 411 | + while ($row = sql_fetch($r)) { |
|
| 412 | + sql_update("spip_articles", array("id_secteur" => $row['secteur']), "id_article=" . intval($row['id'])); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 416 | + pipeline('trig_propager_les_secteurs', ''); |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | |
@@ -428,17 +428,17 @@ discard block |
||
| 428 | 428 | * true si un changement a eu lieu |
| 429 | 429 | **/ |
| 430 | 430 | function calculer_langues_rubriques_etape() { |
| 431 | - $s = sql_select("A.id_rubrique AS id_rubrique, R.lang AS lang", "spip_rubriques AS A, spip_rubriques AS R", |
|
| 432 | - "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang"); |
|
| 431 | + $s = sql_select("A.id_rubrique AS id_rubrique, R.lang AS lang", "spip_rubriques AS A, spip_rubriques AS R", |
|
| 432 | + "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang"); |
|
| 433 | 433 | |
| 434 | - $t = false; |
|
| 435 | - while ($row = sql_fetch($s)) { |
|
| 436 | - $id_rubrique = $row['id_rubrique']; |
|
| 437 | - $t = sql_updateq('spip_rubriques', array('lang' => $row['lang'], 'langue_choisie' => 'non'), |
|
| 438 | - "id_rubrique=" . intval($id_rubrique)); |
|
| 439 | - } |
|
| 434 | + $t = false; |
|
| 435 | + while ($row = sql_fetch($s)) { |
|
| 436 | + $id_rubrique = $row['id_rubrique']; |
|
| 437 | + $t = sql_updateq('spip_rubriques', array('lang' => $row['lang'], 'langue_choisie' => 'non'), |
|
| 438 | + "id_rubrique=" . intval($id_rubrique)); |
|
| 439 | + } |
|
| 440 | 440 | |
| 441 | - return $t; |
|
| 441 | + return $t; |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | /** |
@@ -458,30 +458,30 @@ discard block |
||
| 458 | 458 | **/ |
| 459 | 459 | function calculer_langues_rubriques() { |
| 460 | 460 | |
| 461 | - // rubriques (recursivite) |
|
| 462 | - sql_updateq("spip_rubriques", array("lang" => $GLOBALS['meta']['langue_site'], "langue_choisie" => 'non'), |
|
| 463 | - "id_parent=0 AND langue_choisie != 'oui'"); |
|
| 464 | - while (calculer_langues_rubriques_etape()) { |
|
| 465 | - ; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - // articles |
|
| 469 | - $s = sql_select("A.id_article AS id_article, R.lang AS lang", "spip_articles AS A, spip_rubriques AS R", |
|
| 470 | - "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang"); |
|
| 471 | - while ($row = sql_fetch($s)) { |
|
| 472 | - $id_article = $row['id_article']; |
|
| 473 | - sql_updateq('spip_articles', array("lang" => $row['lang'], 'langue_choisie' => 'non'), |
|
| 474 | - "id_article=" . intval($id_article)); |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 478 | - |
|
| 479 | - $langues = calculer_langues_utilisees(); |
|
| 480 | - ecrire_meta('langues_utilisees', $langues); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 484 | - pipeline('trig_calculer_langues_rubriques', ''); |
|
| 461 | + // rubriques (recursivite) |
|
| 462 | + sql_updateq("spip_rubriques", array("lang" => $GLOBALS['meta']['langue_site'], "langue_choisie" => 'non'), |
|
| 463 | + "id_parent=0 AND langue_choisie != 'oui'"); |
|
| 464 | + while (calculer_langues_rubriques_etape()) { |
|
| 465 | + ; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + // articles |
|
| 469 | + $s = sql_select("A.id_article AS id_article, R.lang AS lang", "spip_articles AS A, spip_rubriques AS R", |
|
| 470 | + "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang"); |
|
| 471 | + while ($row = sql_fetch($s)) { |
|
| 472 | + $id_article = $row['id_article']; |
|
| 473 | + sql_updateq('spip_articles', array("lang" => $row['lang'], 'langue_choisie' => 'non'), |
|
| 474 | + "id_article=" . intval($id_article)); |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 478 | + |
|
| 479 | + $langues = calculer_langues_utilisees(); |
|
| 480 | + ecrire_meta('langues_utilisees', $langues); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 484 | + pipeline('trig_calculer_langues_rubriques', ''); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | |
@@ -498,77 +498,77 @@ discard block |
||
| 498 | 498 | * Liste des langues utilisées séparées par des virgules |
| 499 | 499 | **/ |
| 500 | 500 | function calculer_langues_utilisees($serveur = '') { |
| 501 | - include_spip('public/interfaces'); |
|
| 502 | - include_spip('public/compiler'); |
|
| 503 | - include_spip('public/composer'); |
|
| 504 | - include_spip('public/phraser_html'); |
|
| 505 | - $langues = array(); |
|
| 506 | - |
|
| 507 | - $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 508 | - |
|
| 509 | - include_spip('base/objets'); |
|
| 510 | - $tables = lister_tables_objets_sql(); |
|
| 511 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 512 | - |
|
| 513 | - foreach (array_keys($tables) as $t) { |
|
| 514 | - $desc = $trouver_table($t, $serveur); |
|
| 515 | - // c'est une table avec des langues |
|
| 516 | - if ($desc['exist'] |
|
| 517 | - and isset($desc['field']['lang']) |
|
| 518 | - and isset($desc['field']['langue_choisie']) |
|
| 519 | - ) { |
|
| 520 | - |
|
| 521 | - $boucle = new Boucle(); |
|
| 522 | - $boucle->show = $desc; |
|
| 523 | - $boucle->nom = 'calculer_langues_utilisees'; |
|
| 524 | - $boucle->id_boucle = $desc['table_objet']; |
|
| 525 | - $boucle->id_table = $desc['table_objet']; |
|
| 526 | - $boucle->sql_serveur = $serveur; |
|
| 527 | - $boucle->select[] = "DISTINCT lang"; |
|
| 528 | - $boucle->from[$desc['table_objet']] = $t; |
|
| 529 | - $boucle->separateur[] = ','; |
|
| 530 | - $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 531 | - $boucle->iterateur = 'sql'; |
|
| 532 | - |
|
| 533 | - $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php |
|
| 534 | - $boucle->descr['sourcefile'] = 'internal'; |
|
| 535 | - |
|
| 536 | - $boucle = pipeline('pre_boucle', $boucle); |
|
| 537 | - |
|
| 538 | - if (isset($desc['statut']) |
|
| 539 | - and $desc['statut'] |
|
| 540 | - ) { |
|
| 541 | - $boucles = array( |
|
| 542 | - 'calculer_langues_utilisees' => $boucle, |
|
| 543 | - ); |
|
| 544 | - // generer un nom de fonction "anonyme" unique |
|
| 545 | - do { |
|
| 546 | - $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . rand(); |
|
| 547 | - } while (function_exists($functionname)); |
|
| 548 | - $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 549 | - $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 550 | - $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 551 | - $res = ''; |
|
| 552 | - eval($code); |
|
| 553 | - $res = explode(',', $res); |
|
| 554 | - foreach ($res as $lang) { |
|
| 555 | - $langues[$lang] = 1; |
|
| 556 | - } |
|
| 557 | - } else { |
|
| 558 | - $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 559 | - while ($row = sql_fetch($res)) { |
|
| 560 | - $langues[$row['lang']] = 1; |
|
| 561 | - } |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - $langues = array_filter(array_keys($langues)); |
|
| 567 | - sort($langues); |
|
| 568 | - $langues = join(',', $langues); |
|
| 569 | - spip_log("langues utilisees: $langues"); |
|
| 570 | - |
|
| 571 | - return $langues; |
|
| 501 | + include_spip('public/interfaces'); |
|
| 502 | + include_spip('public/compiler'); |
|
| 503 | + include_spip('public/composer'); |
|
| 504 | + include_spip('public/phraser_html'); |
|
| 505 | + $langues = array(); |
|
| 506 | + |
|
| 507 | + $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 508 | + |
|
| 509 | + include_spip('base/objets'); |
|
| 510 | + $tables = lister_tables_objets_sql(); |
|
| 511 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 512 | + |
|
| 513 | + foreach (array_keys($tables) as $t) { |
|
| 514 | + $desc = $trouver_table($t, $serveur); |
|
| 515 | + // c'est une table avec des langues |
|
| 516 | + if ($desc['exist'] |
|
| 517 | + and isset($desc['field']['lang']) |
|
| 518 | + and isset($desc['field']['langue_choisie']) |
|
| 519 | + ) { |
|
| 520 | + |
|
| 521 | + $boucle = new Boucle(); |
|
| 522 | + $boucle->show = $desc; |
|
| 523 | + $boucle->nom = 'calculer_langues_utilisees'; |
|
| 524 | + $boucle->id_boucle = $desc['table_objet']; |
|
| 525 | + $boucle->id_table = $desc['table_objet']; |
|
| 526 | + $boucle->sql_serveur = $serveur; |
|
| 527 | + $boucle->select[] = "DISTINCT lang"; |
|
| 528 | + $boucle->from[$desc['table_objet']] = $t; |
|
| 529 | + $boucle->separateur[] = ','; |
|
| 530 | + $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 531 | + $boucle->iterateur = 'sql'; |
|
| 532 | + |
|
| 533 | + $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php |
|
| 534 | + $boucle->descr['sourcefile'] = 'internal'; |
|
| 535 | + |
|
| 536 | + $boucle = pipeline('pre_boucle', $boucle); |
|
| 537 | + |
|
| 538 | + if (isset($desc['statut']) |
|
| 539 | + and $desc['statut'] |
|
| 540 | + ) { |
|
| 541 | + $boucles = array( |
|
| 542 | + 'calculer_langues_utilisees' => $boucle, |
|
| 543 | + ); |
|
| 544 | + // generer un nom de fonction "anonyme" unique |
|
| 545 | + do { |
|
| 546 | + $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . rand(); |
|
| 547 | + } while (function_exists($functionname)); |
|
| 548 | + $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 549 | + $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 550 | + $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 551 | + $res = ''; |
|
| 552 | + eval($code); |
|
| 553 | + $res = explode(',', $res); |
|
| 554 | + foreach ($res as $lang) { |
|
| 555 | + $langues[$lang] = 1; |
|
| 556 | + } |
|
| 557 | + } else { |
|
| 558 | + $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 559 | + while ($row = sql_fetch($res)) { |
|
| 560 | + $langues[$row['lang']] = 1; |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + $langues = array_filter(array_keys($langues)); |
|
| 567 | + sort($langues); |
|
| 568 | + $langues = join(',', $langues); |
|
| 569 | + spip_log("langues utilisees: $langues"); |
|
| 570 | + |
|
| 571 | + return $langues; |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | /** |
@@ -598,9 +598,9 @@ discard block |
||
| 598 | 598 | * incluant les rubriques noeuds et toutes leurs descendances |
| 599 | 599 | */ |
| 600 | 600 | function calcul_branche_in($id) { |
| 601 | - $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 601 | + $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 602 | 602 | |
| 603 | - return $calcul_branche_in($id); |
|
| 603 | + return $calcul_branche_in($id); |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | /** |
@@ -618,9 +618,9 @@ discard block |
||
| 618 | 618 | * incluant les rubriques transmises et toutes leurs parentées |
| 619 | 619 | */ |
| 620 | 620 | function calcul_hierarchie_in($id, $tout = true) { |
| 621 | - $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 621 | + $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 622 | 622 | |
| 623 | - return $calcul_hierarchie_in($id, $tout); |
|
| 623 | + return $calcul_hierarchie_in($id, $tout); |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | |
@@ -641,38 +641,38 @@ discard block |
||
| 641 | 641 | * incluant les rubriques noeuds et toutes leurs descendances |
| 642 | 642 | */ |
| 643 | 643 | function inc_calcul_branche_in_dist($id) { |
| 644 | - static $b = array(); |
|
| 645 | - |
|
| 646 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 647 | - if (!is_array($id)) { |
|
| 648 | - $id = explode(',', $id); |
|
| 649 | - } |
|
| 650 | - $id = join(',', array_map('intval', $id)); |
|
| 651 | - if (isset($b[$id])) { |
|
| 652 | - return $b[$id]; |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - // Notre branche commence par la rubrique de depart |
|
| 656 | - $branche = $r = $id; |
|
| 657 | - |
|
| 658 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 659 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 660 | - $maxiter = 10000; |
|
| 661 | - while ($maxiter-- and $filles = sql_allfetsel( |
|
| 662 | - 'id_rubrique', |
|
| 663 | - 'spip_rubriques', |
|
| 664 | - sql_in('id_parent', $r) . " AND " . sql_in('id_rubrique', $r, 'NOT') |
|
| 665 | - )) { |
|
| 666 | - $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 667 | - $branche .= ',' . $r; |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 671 | - if (strlen($branche) < 10000) { |
|
| 672 | - $b[$id] = $branche; |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - return $branche; |
|
| 644 | + static $b = array(); |
|
| 645 | + |
|
| 646 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 647 | + if (!is_array($id)) { |
|
| 648 | + $id = explode(',', $id); |
|
| 649 | + } |
|
| 650 | + $id = join(',', array_map('intval', $id)); |
|
| 651 | + if (isset($b[$id])) { |
|
| 652 | + return $b[$id]; |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + // Notre branche commence par la rubrique de depart |
|
| 656 | + $branche = $r = $id; |
|
| 657 | + |
|
| 658 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 659 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 660 | + $maxiter = 10000; |
|
| 661 | + while ($maxiter-- and $filles = sql_allfetsel( |
|
| 662 | + 'id_rubrique', |
|
| 663 | + 'spip_rubriques', |
|
| 664 | + sql_in('id_parent', $r) . " AND " . sql_in('id_rubrique', $r, 'NOT') |
|
| 665 | + )) { |
|
| 666 | + $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 667 | + $branche .= ',' . $r; |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 671 | + if (strlen($branche) < 10000) { |
|
| 672 | + $b[$id] = $branche; |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + return $branche; |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | |
@@ -694,43 +694,43 @@ discard block |
||
| 694 | 694 | * incluant les rubriques transmises et toutes leurs parentées |
| 695 | 695 | */ |
| 696 | 696 | function inc_calcul_hierarchie_in_dist($id, $tout = true) { |
| 697 | - static $b = array(); |
|
| 698 | - |
|
| 699 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 700 | - if (!is_array($id)) { |
|
| 701 | - $id = explode(',', $id); |
|
| 702 | - } |
|
| 703 | - $id = join(',', array_map('intval', $id)); |
|
| 704 | - |
|
| 705 | - if (isset($b[$id])) { |
|
| 706 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 707 | - return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - $hier = ""; |
|
| 711 | - |
|
| 712 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 713 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 714 | - $ids_nouveaux_parents = $id; |
|
| 715 | - $maxiter = 10000; |
|
| 716 | - while ($maxiter-- and $parents = sql_allfetsel( |
|
| 717 | - 'id_parent', |
|
| 718 | - 'spip_rubriques', |
|
| 719 | - sql_in('id_rubrique', $ids_nouveaux_parents) . " AND " . sql_in('id_parent', $hier, 'NOT') |
|
| 720 | - )) { |
|
| 721 | - $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 722 | - $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 726 | - if (strlen($hier) < 10000) { |
|
| 727 | - $b[$id] = $hier; |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 731 | - $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 732 | - |
|
| 733 | - return $hier; |
|
| 697 | + static $b = array(); |
|
| 698 | + |
|
| 699 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 700 | + if (!is_array($id)) { |
|
| 701 | + $id = explode(',', $id); |
|
| 702 | + } |
|
| 703 | + $id = join(',', array_map('intval', $id)); |
|
| 704 | + |
|
| 705 | + if (isset($b[$id])) { |
|
| 706 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 707 | + return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + $hier = ""; |
|
| 711 | + |
|
| 712 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 713 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 714 | + $ids_nouveaux_parents = $id; |
|
| 715 | + $maxiter = 10000; |
|
| 716 | + while ($maxiter-- and $parents = sql_allfetsel( |
|
| 717 | + 'id_parent', |
|
| 718 | + 'spip_rubriques', |
|
| 719 | + sql_in('id_rubrique', $ids_nouveaux_parents) . " AND " . sql_in('id_parent', $hier, 'NOT') |
|
| 720 | + )) { |
|
| 721 | + $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 722 | + $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 726 | + if (strlen($hier) < 10000) { |
|
| 727 | + $b[$id] = $hier; |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 731 | + $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 732 | + |
|
| 733 | + return $hier; |
|
| 734 | 734 | } |
| 735 | 735 | |
| 736 | 736 | |
@@ -748,38 +748,38 @@ discard block |
||
| 748 | 748 | * @return void |
| 749 | 749 | **/ |
| 750 | 750 | function calculer_prochain_postdate($check = false) { |
| 751 | - include_spip('base/abstract_sql'); |
|
| 752 | - if ($check) { |
|
| 753 | - $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
|
| 754 | - "AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 755 | - |
|
| 756 | - $r = sql_select("DISTINCT A.id_rubrique AS id", |
|
| 757 | - "spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique", |
|
| 758 | - "R.statut != 'publie' AND A.statut='publie'$postdates"); |
|
| 759 | - while ($row = sql_fetch($r)) { |
|
| 760 | - publier_branche_rubrique($row['id']); |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - pipeline('trig_calculer_prochain_postdate', ''); |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - $t = sql_fetsel("date", "spip_articles", "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), "", "date", |
|
| 767 | - "1"); |
|
| 768 | - |
|
| 769 | - if ($t) { |
|
| 770 | - $t = $t['date']; |
|
| 771 | - if (!isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 772 | - or $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 773 | - ) { |
|
| 774 | - ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 775 | - ecrire_meta('derniere_modif', time()); |
|
| 776 | - } |
|
| 777 | - } else { |
|
| 778 | - effacer_meta('date_prochain_postdate'); |
|
| 779 | - ecrire_meta('derniere_modif', time()); |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - spip_log("prochain postdate: $t"); |
|
| 751 | + include_spip('base/abstract_sql'); |
|
| 752 | + if ($check) { |
|
| 753 | + $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
|
| 754 | + "AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 755 | + |
|
| 756 | + $r = sql_select("DISTINCT A.id_rubrique AS id", |
|
| 757 | + "spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique", |
|
| 758 | + "R.statut != 'publie' AND A.statut='publie'$postdates"); |
|
| 759 | + while ($row = sql_fetch($r)) { |
|
| 760 | + publier_branche_rubrique($row['id']); |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + pipeline('trig_calculer_prochain_postdate', ''); |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + $t = sql_fetsel("date", "spip_articles", "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), "", "date", |
|
| 767 | + "1"); |
|
| 768 | + |
|
| 769 | + if ($t) { |
|
| 770 | + $t = $t['date']; |
|
| 771 | + if (!isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 772 | + or $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 773 | + ) { |
|
| 774 | + ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 775 | + ecrire_meta('derniere_modif', time()); |
|
| 776 | + } |
|
| 777 | + } else { |
|
| 778 | + effacer_meta('date_prochain_postdate'); |
|
| 779 | + ecrire_meta('derniere_modif', time()); |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + spip_log("prochain postdate: $t"); |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | /** |
@@ -804,42 +804,42 @@ discard block |
||
| 804 | 804 | */ |
| 805 | 805 | function creer_rubrique_nommee($titre, $id_parent = 0, $serveur = '') { |
| 806 | 806 | |
| 807 | - // eclater l'arborescence demandee |
|
| 808 | - // echapper les </multi> et autres balises fermantes html |
|
| 809 | - $titre = preg_replace(",</([a-z][^>]*)>,ims", "<@\\1>", $titre); |
|
| 810 | - $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 811 | - include_spip('base/abstract_sql'); |
|
| 812 | - foreach ($arbo as $titre) { |
|
| 813 | - // retablir les </multi> et autres balises fermantes html |
|
| 814 | - $titre = preg_replace(",<@([a-z][^>]*)>,ims", "</\\1>", $titre); |
|
| 815 | - $r = sql_getfetsel("id_rubrique", "spip_rubriques", |
|
| 816 | - "titre = " . sql_quote($titre) . " AND id_parent=" . intval($id_parent), |
|
| 817 | - $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur); |
|
| 818 | - if ($r !== null) { |
|
| 819 | - $id_parent = $r; |
|
| 820 | - } else { |
|
| 821 | - $id_rubrique = sql_insertq('spip_rubriques', array( |
|
| 822 | - 'titre' => $titre, |
|
| 823 | - 'id_parent' => $id_parent, |
|
| 824 | - 'statut' => 'prepa' |
|
| 825 | - ), $desc = array(), $serveur); |
|
| 826 | - if ($id_parent > 0) { |
|
| 827 | - $data = sql_fetsel("id_secteur,lang", "spip_rubriques", "id_rubrique=$id_parent", |
|
| 828 | - $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur); |
|
| 829 | - $id_secteur = $data['id_secteur']; |
|
| 830 | - $lang = $data['lang']; |
|
| 831 | - } else { |
|
| 832 | - $id_secteur = $id_rubrique; |
|
| 833 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 834 | - } |
|
| 835 | - |
|
| 836 | - sql_updateq('spip_rubriques', array('id_secteur' => $id_secteur, "lang" => $lang), |
|
| 837 | - "id_rubrique=" . intval($id_rubrique), $desc = '', $serveur); |
|
| 838 | - |
|
| 839 | - // pour la recursion |
|
| 840 | - $id_parent = $id_rubrique; |
|
| 841 | - } |
|
| 842 | - } |
|
| 843 | - |
|
| 844 | - return intval($id_parent); |
|
| 807 | + // eclater l'arborescence demandee |
|
| 808 | + // echapper les </multi> et autres balises fermantes html |
|
| 809 | + $titre = preg_replace(",</([a-z][^>]*)>,ims", "<@\\1>", $titre); |
|
| 810 | + $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 811 | + include_spip('base/abstract_sql'); |
|
| 812 | + foreach ($arbo as $titre) { |
|
| 813 | + // retablir les </multi> et autres balises fermantes html |
|
| 814 | + $titre = preg_replace(",<@([a-z][^>]*)>,ims", "</\\1>", $titre); |
|
| 815 | + $r = sql_getfetsel("id_rubrique", "spip_rubriques", |
|
| 816 | + "titre = " . sql_quote($titre) . " AND id_parent=" . intval($id_parent), |
|
| 817 | + $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur); |
|
| 818 | + if ($r !== null) { |
|
| 819 | + $id_parent = $r; |
|
| 820 | + } else { |
|
| 821 | + $id_rubrique = sql_insertq('spip_rubriques', array( |
|
| 822 | + 'titre' => $titre, |
|
| 823 | + 'id_parent' => $id_parent, |
|
| 824 | + 'statut' => 'prepa' |
|
| 825 | + ), $desc = array(), $serveur); |
|
| 826 | + if ($id_parent > 0) { |
|
| 827 | + $data = sql_fetsel("id_secteur,lang", "spip_rubriques", "id_rubrique=$id_parent", |
|
| 828 | + $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur); |
|
| 829 | + $id_secteur = $data['id_secteur']; |
|
| 830 | + $lang = $data['lang']; |
|
| 831 | + } else { |
|
| 832 | + $id_secteur = $id_rubrique; |
|
| 833 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 834 | + } |
|
| 835 | + |
|
| 836 | + sql_updateq('spip_rubriques', array('id_secteur' => $id_secteur, "lang" => $lang), |
|
| 837 | + "id_rubrique=" . intval($id_rubrique), $desc = '', $serveur); |
|
| 838 | + |
|
| 839 | + // pour la recursion |
|
| 840 | + $id_parent = $id_rubrique; |
|
| 841 | + } |
|
| 842 | + } |
|
| 843 | + |
|
| 844 | + return intval($id_parent); |
|
| 845 | 845 | } |
@@ -105,8 +105,8 @@ discard block |
||
| 105 | 105 | $id_pred = $id_rubrique; |
| 106 | 106 | while (true) { |
| 107 | 107 | sql_updateq('spip_rubriques', array('statut' => 'publie', 'date' => date('Y-m-d H:i:s')), |
| 108 | - "id_rubrique=" . intval($id_rubrique)); |
|
| 109 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', "R.id_rubrique=" . intval($id_rubrique)); |
|
| 108 | + "id_rubrique=".intval($id_rubrique)); |
|
| 109 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', "R.id_rubrique=".intval($id_rubrique)); |
|
| 110 | 110 | if (!$id_parent) { |
| 111 | 111 | break; |
| 112 | 112 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | return $id_pred != $id_rubrique; |
| 143 | 143 | } |
| 144 | 144 | // passer au parent si on a depublie |
| 145 | - $r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=" . intval($id_pred)); |
|
| 145 | + $r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=".intval($id_pred)); |
|
| 146 | 146 | $id_pred = $r['id_parent']; |
| 147 | 147 | } |
| 148 | 148 | |
@@ -167,14 +167,14 @@ discard block |
||
| 167 | 167 | $date = date('Y-m-d H:i:s'); |
| 168 | 168 | } |
| 169 | 169 | $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
| 170 | - " AND date <= " . sql_quote($date) : ''; |
|
| 170 | + " AND date <= ".sql_quote($date) : ''; |
|
| 171 | 171 | |
| 172 | 172 | if (!$id_rubrique = intval($id_rubrique)) { |
| 173 | 173 | return false; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | // verifier qu'elle existe et est bien publiee |
| 177 | - $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', "id_rubrique=" . intval($id_rubrique)); |
|
| 177 | + $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', "id_rubrique=".intval($id_rubrique)); |
|
| 178 | 178 | if (!$r or $r['statut'] !== 'publie') { |
| 179 | 179 | return false; |
| 180 | 180 | } |
@@ -183,9 +183,9 @@ discard block |
||
| 183 | 183 | // Le type de l'objet est au pluriel |
| 184 | 184 | $compte = array( |
| 185 | 185 | 'articles' => sql_countsel("spip_articles", |
| 186 | - "id_rubrique=" . intval($id_rubrique) . " AND statut='publie'$postdates"), |
|
| 187 | - 'rubriques' => sql_countsel("spip_rubriques", "id_parent=" . intval($id_rubrique) . " AND statut='publie'"), |
|
| 188 | - 'documents' => sql_countsel("spip_documents_liens", "id_objet=" . intval($id_rubrique) . " AND objet='rubrique'") |
|
| 186 | + "id_rubrique=".intval($id_rubrique)." AND statut='publie'$postdates"), |
|
| 187 | + 'rubriques' => sql_countsel("spip_rubriques", "id_parent=".intval($id_rubrique)." AND statut='publie'"), |
|
| 188 | + 'documents' => sql_countsel("spip_documents_liens", "id_objet=".intval($id_rubrique)." AND objet='rubrique'") |
|
| 189 | 189 | ); |
| 190 | 190 | |
| 191 | 191 | // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - sql_updateq("spip_rubriques", array("statut" => 'prepa'), "id_rubrique=" . intval($id_rubrique)); |
|
| 211 | + sql_updateq("spip_rubriques", array("statut" => 'prepa'), "id_rubrique=".intval($id_rubrique)); |
|
| 212 | 212 | |
| 213 | 213 | # spip_log("depublier_rubrique $id_pred"); |
| 214 | 214 | return true; |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | |
| 272 | 272 | // Afficher les articles post-dates ? |
| 273 | 273 | $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
| 274 | - "AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 274 | + "AND A.date <= ".sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 275 | 275 | |
| 276 | 276 | $r = sql_select( |
| 277 | 277 | "R.id_rubrique AS id, max(A.date) AS date_h", |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | "A.date>R.date_tmp AND A.statut='publie' $postdates ", "R.id_rubrique"); |
| 280 | 280 | while ($row = sql_fetch($r)) { |
| 281 | 281 | sql_updateq("spip_rubriques", array("statut_tmp" => 'publie', "date_tmp" => $row['date_h']), |
| 282 | - "id_rubrique=" . intval($row['id'])); |
|
| 282 | + "id_rubrique=".intval($row['id'])); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | // point d'entree pour permettre a des plugins de gerer le statut |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", "R.id_rubrique"); |
| 301 | 301 | while ($row = sql_fetch($r)) { |
| 302 | 302 | sql_updateq('spip_rubriques', array('statut_tmp' => 'publie', 'date_tmp' => $row['date_h']), |
| 303 | - "id_rubrique=" . intval($row['id'])); |
|
| 303 | + "id_rubrique=".intval($row['id'])); |
|
| 304 | 304 | $continuer = true; |
| 305 | 305 | } |
| 306 | 306 | } while ($continuer); |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | and $rows = sql_allfetsel( |
| 352 | 352 | "A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur", |
| 353 | 353 | "spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique", |
| 354 | - "R.profondeur=" . intval($prof) . " AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)", |
|
| 354 | + "R.profondeur=".intval($prof)." AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)", |
|
| 355 | 355 | "", "R.id_secteur", "0,100")) { |
| 356 | 356 | |
| 357 | 357 | $id_secteur = null; |
@@ -380,8 +380,8 @@ discard block |
||
| 380 | 380 | and $rows = sql_allfetsel( |
| 381 | 381 | "id_rubrique as id", |
| 382 | 382 | "spip_rubriques", |
| 383 | - "profondeur=" . intval($prof + 1) . " AND id_parent NOT IN (" . sql_get_select("zzz.id_rubrique", |
|
| 384 | - "spip_rubriques AS zzz", "zzz.profondeur=" . intval($prof)) . ")", '', '', '0,100')) { |
|
| 383 | + "profondeur=".intval($prof + 1)." AND id_parent NOT IN (".sql_get_select("zzz.id_rubrique", |
|
| 384 | + "spip_rubriques AS zzz", "zzz.profondeur=".intval($prof)).")", '', '', '0,100')) { |
|
| 385 | 385 | $rows = array_column($rows, 'id'); |
| 386 | 386 | sql_updateq("spip_rubriques", array('profondeur' => $prof + 2), sql_in("id_rubrique", $rows)); |
| 387 | 387 | } |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
| 391 | 391 | // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
| 392 | 392 | // on arrete les frais |
| 393 | - if (sql_countsel("spip_rubriques", "profondeur=" . intval($prof + 1))) { |
|
| 393 | + if (sql_countsel("spip_rubriques", "profondeur=".intval($prof + 1))) { |
|
| 394 | 394 | $prof++; |
| 395 | 395 | $continuer = true; |
| 396 | 396 | } |
@@ -398,10 +398,10 @@ discard block |
||
| 398 | 398 | |
| 399 | 399 | // loger si la table des rubriques semble foireuse |
| 400 | 400 | // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
| 401 | - if (sql_countsel("spip_rubriques", "profondeur>" . intval($prof + 1))) { |
|
| 402 | - spip_log("Les rubriques de profondeur>" . ($prof + 1) . " semblent suspectes (branches morte ou reference circulaire dans les parents)", |
|
| 401 | + if (sql_countsel("spip_rubriques", "profondeur>".intval($prof + 1))) { |
|
| 402 | + spip_log("Les rubriques de profondeur>".($prof + 1)." semblent suspectes (branches morte ou reference circulaire dans les parents)", |
|
| 403 | 403 | _LOG_CRITIQUE); |
| 404 | - sql_update("spip_rubriques", array('id_secteur' => 0), "profondeur>" . intval($prof + 1)); |
|
| 404 | + sql_update("spip_rubriques", array('id_secteur' => 0), "profondeur>".intval($prof + 1)); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | // reparer les articles |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | "A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur"); |
| 410 | 410 | |
| 411 | 411 | while ($row = sql_fetch($r)) { |
| 412 | - sql_update("spip_articles", array("id_secteur" => $row['secteur']), "id_article=" . intval($row['id'])); |
|
| 412 | + sql_update("spip_articles", array("id_secteur" => $row['secteur']), "id_article=".intval($row['id'])); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | // avertir les plugins qui peuvent faire leur mises a jour egalement |
@@ -435,7 +435,7 @@ discard block |
||
| 435 | 435 | while ($row = sql_fetch($s)) { |
| 436 | 436 | $id_rubrique = $row['id_rubrique']; |
| 437 | 437 | $t = sql_updateq('spip_rubriques', array('lang' => $row['lang'], 'langue_choisie' => 'non'), |
| 438 | - "id_rubrique=" . intval($id_rubrique)); |
|
| 438 | + "id_rubrique=".intval($id_rubrique)); |
|
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | return $t; |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | while ($row = sql_fetch($s)) { |
| 472 | 472 | $id_article = $row['id_article']; |
| 473 | 473 | sql_updateq('spip_articles', array("lang" => $row['lang'], 'langue_choisie' => 'non'), |
| 474 | - "id_article=" . intval($id_article)); |
|
| 474 | + "id_article=".intval($id_article)); |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
@@ -543,11 +543,11 @@ discard block |
||
| 543 | 543 | ); |
| 544 | 544 | // generer un nom de fonction "anonyme" unique |
| 545 | 545 | do { |
| 546 | - $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . rand(); |
|
| 546 | + $functionname = 'f_calculer_langues_utilisees_'.$boucle->id_table.'_'.time().'_'.rand(); |
|
| 547 | 547 | } while (function_exists($functionname)); |
| 548 | 548 | $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
| 549 | - $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 550 | - $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 549 | + $code = '$SP=0; $command=array();$command["connect"] = $connect = "'.$serveur.'"; $Pile=array(0=>array());'."\n".$code; |
|
| 550 | + $code = 'function '.$functionname.'(){'.$code.'};$res = '.$functionname.'();'; |
|
| 551 | 551 | $res = ''; |
| 552 | 552 | eval($code); |
| 553 | 553 | $res = explode(',', $res); |
@@ -661,10 +661,10 @@ discard block |
||
| 661 | 661 | while ($maxiter-- and $filles = sql_allfetsel( |
| 662 | 662 | 'id_rubrique', |
| 663 | 663 | 'spip_rubriques', |
| 664 | - sql_in('id_parent', $r) . " AND " . sql_in('id_rubrique', $r, 'NOT') |
|
| 664 | + sql_in('id_parent', $r)." AND ".sql_in('id_rubrique', $r, 'NOT') |
|
| 665 | 665 | )) { |
| 666 | 666 | $r = join(',', array_column($filles, 'id_rubrique')); |
| 667 | - $branche .= ',' . $r; |
|
| 667 | + $branche .= ','.$r; |
|
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
@@ -704,7 +704,7 @@ discard block |
||
| 704 | 704 | |
| 705 | 705 | if (isset($b[$id])) { |
| 706 | 706 | // Notre branche commence par la rubrique de depart si $tout=true |
| 707 | - return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 707 | + return $tout ? (strlen($b[$id]) ? $b[$id].",$id" : $id) : $b[$id]; |
|
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | $hier = ""; |
@@ -716,10 +716,10 @@ discard block |
||
| 716 | 716 | while ($maxiter-- and $parents = sql_allfetsel( |
| 717 | 717 | 'id_parent', |
| 718 | 718 | 'spip_rubriques', |
| 719 | - sql_in('id_rubrique', $ids_nouveaux_parents) . " AND " . sql_in('id_parent', $hier, 'NOT') |
|
| 719 | + sql_in('id_rubrique', $ids_nouveaux_parents)." AND ".sql_in('id_parent', $hier, 'NOT') |
|
| 720 | 720 | )) { |
| 721 | 721 | $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
| 722 | - $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 722 | + $hier = $ids_nouveaux_parents.(strlen($hier) ? ','.$hier : ''); |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
@@ -751,7 +751,7 @@ discard block |
||
| 751 | 751 | include_spip('base/abstract_sql'); |
| 752 | 752 | if ($check) { |
| 753 | 753 | $postdates = ($GLOBALS['meta']["post_dates"] == "non") ? |
| 754 | - "AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 754 | + "AND A.date <= ".sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 755 | 755 | |
| 756 | 756 | $r = sql_select("DISTINCT A.id_rubrique AS id", |
| 757 | 757 | "spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique", |
@@ -763,7 +763,7 @@ discard block |
||
| 763 | 763 | pipeline('trig_calculer_prochain_postdate', ''); |
| 764 | 764 | } |
| 765 | 765 | |
| 766 | - $t = sql_fetsel("date", "spip_articles", "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), "", "date", |
|
| 766 | + $t = sql_fetsel("date", "spip_articles", "statut='publie' AND date > ".sql_quote(date('Y-m-d H:i:s')), "", "date", |
|
| 767 | 767 | "1"); |
| 768 | 768 | |
| 769 | 769 | if ($t) { |
@@ -813,7 +813,7 @@ discard block |
||
| 813 | 813 | // retablir les </multi> et autres balises fermantes html |
| 814 | 814 | $titre = preg_replace(",<@([a-z][^>]*)>,ims", "</\\1>", $titre); |
| 815 | 815 | $r = sql_getfetsel("id_rubrique", "spip_rubriques", |
| 816 | - "titre = " . sql_quote($titre) . " AND id_parent=" . intval($id_parent), |
|
| 816 | + "titre = ".sql_quote($titre)." AND id_parent=".intval($id_parent), |
|
| 817 | 817 | $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur); |
| 818 | 818 | if ($r !== null) { |
| 819 | 819 | $id_parent = $r; |
@@ -834,7 +834,7 @@ discard block |
||
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | sql_updateq('spip_rubriques', array('id_secteur' => $id_secteur, "lang" => $lang), |
| 837 | - "id_rubrique=" . intval($id_rubrique), $desc = '', $serveur); |
|
| 837 | + "id_rubrique=".intval($id_rubrique), $desc = '', $serveur); |
|
| 838 | 838 | |
| 839 | 839 | // pour la recursion |
| 840 | 840 | $id_parent = $id_rubrique; |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | /** |
| 32 | 32 | * Raccourcis dépendant du sens de la langue |
| 33 | 33 | * |
| 34 | - * @return array Tablea ('','') |
|
| 34 | + * @return string[] Tablea ('','') |
|
| 35 | 35 | */ |
| 36 | 36 | function definir_raccourcis_alineas() { |
| 37 | 37 | return array('', ''); |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | * Ne fait rien ici. Voir plugin Textwheel |
| 355 | 355 | * |
| 356 | 356 | * @param string $letexte |
| 357 | - * @param null $forcer |
|
| 357 | + * @param boolean|null $forcer |
|
| 358 | 358 | * @return string |
| 359 | 359 | */ |
| 360 | 360 | function paragrapher($letexte, $forcer = true) { |
@@ -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('inc/texte_mini'); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @return array Tablea ('','') |
| 35 | 35 | */ |
| 36 | 36 | function definir_raccourcis_alineas() { |
| 37 | - return array('', ''); |
|
| 37 | + return array('', ''); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @return string |
| 48 | 48 | */ |
| 49 | 49 | function traiter_tableau($bloc) { |
| 50 | - return $bloc; |
|
| 50 | + return $bloc; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | 63 | function traiter_listes($texte) { |
| 64 | - return $texte; |
|
| 64 | + return $texte; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -77,16 +77,16 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function traiter_raccourcis($letexte) { |
| 79 | 79 | |
| 80 | - // Appeler les fonctions de pre_traitement |
|
| 81 | - $letexte = pipeline('pre_propre', $letexte); |
|
| 80 | + // Appeler les fonctions de pre_traitement |
|
| 81 | + $letexte = pipeline('pre_propre', $letexte); |
|
| 82 | 82 | |
| 83 | - // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | - // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 83 | + // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | + // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 85 | 85 | |
| 86 | - // Appeler les fonctions de post-traitement |
|
| 87 | - $letexte = pipeline('post_propre', $letexte); |
|
| 86 | + // Appeler les fonctions de post-traitement |
|
| 87 | + $letexte = pipeline('post_propre', $letexte); |
|
| 88 | 88 | |
| 89 | - return $letexte; |
|
| 89 | + return $letexte; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /************************************************************************************************************************* |
@@ -102,19 +102,19 @@ discard block |
||
| 102 | 102 | * @return string |
| 103 | 103 | */ |
| 104 | 104 | function echappe_js($t, $class = ' class = "echappe-js"') { |
| 105 | - foreach (array('script', 'iframe') as $tag) { |
|
| 106 | - if (stripos($t, "<$tag") !== false |
|
| 107 | - and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 108 | - ) { |
|
| 109 | - foreach ($r as $regs) { |
|
| 110 | - $t = str_replace($regs[0], |
|
| 111 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 112 | - $t); |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return $t; |
|
| 105 | + foreach (array('script', 'iframe') as $tag) { |
|
| 106 | + if (stripos($t, "<$tag") !== false |
|
| 107 | + and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 108 | + ) { |
|
| 109 | + foreach ($r as $regs) { |
|
| 110 | + $t = str_replace($regs[0], |
|
| 111 | + "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 112 | + $t); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return $t; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -143,55 +143,55 @@ discard block |
||
| 143 | 143 | * Code protégé |
| 144 | 144 | **/ |
| 145 | 145 | function interdire_scripts($arg, $mode_filtre=null) { |
| 146 | - // on memorise le resultat sur les arguments non triviaux |
|
| 147 | - static $dejavu = array(); |
|
| 148 | - |
|
| 149 | - // Attention, si ce n'est pas une chaine, laisser intact |
|
| 150 | - if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 151 | - return $arg; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - if (is_null($mode_filtre) or !in_array($mode_filtre, array(-1, 0, 1))) { |
|
| 155 | - $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 159 | - return $dejavu[$mode_filtre][$arg]; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - // echapper les tags asp/php |
|
| 163 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 164 | - |
|
| 165 | - // echapper le php |
|
| 166 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 167 | - |
|
| 168 | - // echapper le < script language=php > |
|
| 169 | - $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 170 | - |
|
| 171 | - // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 172 | - switch ($mode_filtre) { |
|
| 173 | - case 0: |
|
| 174 | - if (!_DIR_RESTREINT) { |
|
| 175 | - $t = echappe_js($t); |
|
| 176 | - } |
|
| 177 | - break; |
|
| 178 | - case -1: |
|
| 179 | - $t = echappe_js($t); |
|
| 180 | - break; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - // pas de <base href /> svp ! |
|
| 184 | - $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 185 | - |
|
| 186 | - // Reinserer les echappements des modeles |
|
| 187 | - if (defined('_PROTEGE_JS_MODELES')) { |
|
| 188 | - $t = echappe_retour($t, "javascript" . _PROTEGE_JS_MODELES); |
|
| 189 | - } |
|
| 190 | - if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 191 | - $t = echappe_retour($t, "php" . _PROTEGE_PHP_MODELES); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return $dejavu[$mode_filtre][$arg] = $t; |
|
| 146 | + // on memorise le resultat sur les arguments non triviaux |
|
| 147 | + static $dejavu = array(); |
|
| 148 | + |
|
| 149 | + // Attention, si ce n'est pas une chaine, laisser intact |
|
| 150 | + if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 151 | + return $arg; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + if (is_null($mode_filtre) or !in_array($mode_filtre, array(-1, 0, 1))) { |
|
| 155 | + $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 159 | + return $dejavu[$mode_filtre][$arg]; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + // echapper les tags asp/php |
|
| 163 | + $t = str_replace('<' . '%', '<%', $arg); |
|
| 164 | + |
|
| 165 | + // echapper le php |
|
| 166 | + $t = str_replace('<' . '?', '<?', $t); |
|
| 167 | + |
|
| 168 | + // echapper le < script language=php > |
|
| 169 | + $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 170 | + |
|
| 171 | + // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 172 | + switch ($mode_filtre) { |
|
| 173 | + case 0: |
|
| 174 | + if (!_DIR_RESTREINT) { |
|
| 175 | + $t = echappe_js($t); |
|
| 176 | + } |
|
| 177 | + break; |
|
| 178 | + case -1: |
|
| 179 | + $t = echappe_js($t); |
|
| 180 | + break; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + // pas de <base href /> svp ! |
|
| 184 | + $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 185 | + |
|
| 186 | + // Reinserer les echappements des modeles |
|
| 187 | + if (defined('_PROTEGE_JS_MODELES')) { |
|
| 188 | + $t = echappe_retour($t, "javascript" . _PROTEGE_JS_MODELES); |
|
| 189 | + } |
|
| 190 | + if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 191 | + $t = echappe_retour($t, "php" . _PROTEGE_PHP_MODELES); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return $dejavu[$mode_filtre][$arg] = $t; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | |
@@ -220,64 +220,64 @@ discard block |
||
| 220 | 220 | * Texte transformé |
| 221 | 221 | **/ |
| 222 | 222 | function typo($letexte, $echapper = true, $connect = null, $env = array()) { |
| 223 | - // Plus vite ! |
|
| 224 | - if (!$letexte) { |
|
| 225 | - return $letexte; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 229 | - // prive etant historiquement ecrit sans argment $connect |
|
| 230 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 231 | - // ou il faut passer interdire_script explicitement |
|
| 232 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 233 | - // ne seront pas perturbes |
|
| 234 | - $interdire_script = false; |
|
| 235 | - if (is_null($connect)) { |
|
| 236 | - $connect = ''; |
|
| 237 | - $interdire_script = true; |
|
| 238 | - $env['espace_prive'] = test_espace_prive(); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - // Echapper les codes <html> etc |
|
| 242 | - if ($echapper) { |
|
| 243 | - $letexte = echappe_html($letexte, 'TYPO'); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // |
|
| 247 | - // Installer les modeles, notamment images et documents ; |
|
| 248 | - // |
|
| 249 | - // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 250 | - // cf. inc/lien |
|
| 251 | - |
|
| 252 | - $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env); |
|
| 253 | - if ($letexte != $mem) { |
|
| 254 | - $echapper = true; |
|
| 255 | - } |
|
| 256 | - unset($mem); |
|
| 257 | - |
|
| 258 | - $letexte = corriger_typo($letexte); |
|
| 259 | - $letexte = echapper_faux_tags($letexte); |
|
| 260 | - |
|
| 261 | - // reintegrer les echappements |
|
| 262 | - if ($echapper) { |
|
| 263 | - $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - // Dans les appels directs hors squelette, securiser ici aussi |
|
| 267 | - if ($interdire_script) { |
|
| 268 | - $letexte = interdire_scripts($letexte); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 272 | - // https://core.spip.net/issues/3371 |
|
| 273 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 274 | - // https://core.spip.net/issues/4166 |
|
| 275 | - if ($GLOBALS['filtrer_javascript'] == -1 |
|
| 276 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 277 | - $letexte = echapper_html_suspect($letexte); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - return $letexte; |
|
| 223 | + // Plus vite ! |
|
| 224 | + if (!$letexte) { |
|
| 225 | + return $letexte; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 229 | + // prive etant historiquement ecrit sans argment $connect |
|
| 230 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 231 | + // ou il faut passer interdire_script explicitement |
|
| 232 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 233 | + // ne seront pas perturbes |
|
| 234 | + $interdire_script = false; |
|
| 235 | + if (is_null($connect)) { |
|
| 236 | + $connect = ''; |
|
| 237 | + $interdire_script = true; |
|
| 238 | + $env['espace_prive'] = test_espace_prive(); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + // Echapper les codes <html> etc |
|
| 242 | + if ($echapper) { |
|
| 243 | + $letexte = echappe_html($letexte, 'TYPO'); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // |
|
| 247 | + // Installer les modeles, notamment images et documents ; |
|
| 248 | + // |
|
| 249 | + // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 250 | + // cf. inc/lien |
|
| 251 | + |
|
| 252 | + $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env); |
|
| 253 | + if ($letexte != $mem) { |
|
| 254 | + $echapper = true; |
|
| 255 | + } |
|
| 256 | + unset($mem); |
|
| 257 | + |
|
| 258 | + $letexte = corriger_typo($letexte); |
|
| 259 | + $letexte = echapper_faux_tags($letexte); |
|
| 260 | + |
|
| 261 | + // reintegrer les echappements |
|
| 262 | + if ($echapper) { |
|
| 263 | + $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + // Dans les appels directs hors squelette, securiser ici aussi |
|
| 267 | + if ($interdire_script) { |
|
| 268 | + $letexte = interdire_scripts($letexte); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 272 | + // https://core.spip.net/issues/3371 |
|
| 273 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 274 | + // https://core.spip.net/issues/4166 |
|
| 275 | + if ($GLOBALS['filtrer_javascript'] == -1 |
|
| 276 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 277 | + $letexte = echapper_html_suspect($letexte); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + return $letexte; |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | // Correcteur typographique |
@@ -302,57 +302,57 @@ discard block |
||
| 302 | 302 | */ |
| 303 | 303 | function corriger_typo($letexte, $lang = '') { |
| 304 | 304 | |
| 305 | - // Plus vite ! |
|
| 306 | - if (!$letexte) { |
|
| 307 | - return $letexte; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - $letexte = pipeline('pre_typo', $letexte); |
|
| 311 | - |
|
| 312 | - // Caracteres de controle "illegaux" |
|
| 313 | - $letexte = corriger_caracteres($letexte); |
|
| 314 | - |
|
| 315 | - // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 316 | - if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 317 | - foreach ($regs as $reg) { |
|
| 318 | - $insert = $reg[0]; |
|
| 319 | - // hack: on transforme les caracteres a proteger en les remplacant |
|
| 320 | - // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 321 | - $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 322 | - $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - // trouver les blocs idiomes et les traiter à part |
|
| 327 | - $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 328 | - $ei = ($ei !== $letexte); |
|
| 329 | - |
|
| 330 | - // trouver les blocs multi et les traiter a part |
|
| 331 | - $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 332 | - $em = ($em !== $letexte); |
|
| 333 | - |
|
| 334 | - // Charger & appliquer les fonctions de typographie |
|
| 335 | - $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 336 | - $letexte = $typographie($letexte); |
|
| 337 | - |
|
| 338 | - // Les citations en une autre langue, s'il y a lieu |
|
| 339 | - if ($em) { |
|
| 340 | - $letexte = echappe_retour($letexte, 'multi'); |
|
| 341 | - } |
|
| 342 | - if ($ei) { |
|
| 343 | - $letexte = echappe_retour($letexte, 'idiome'); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - // Retablir les caracteres proteges |
|
| 347 | - $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 348 | - |
|
| 349 | - // pipeline |
|
| 350 | - $letexte = pipeline('post_typo', $letexte); |
|
| 351 | - |
|
| 352 | - # un message pour abs_url - on est passe en mode texte |
|
| 353 | - $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 354 | - |
|
| 355 | - return $letexte; |
|
| 305 | + // Plus vite ! |
|
| 306 | + if (!$letexte) { |
|
| 307 | + return $letexte; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + $letexte = pipeline('pre_typo', $letexte); |
|
| 311 | + |
|
| 312 | + // Caracteres de controle "illegaux" |
|
| 313 | + $letexte = corriger_caracteres($letexte); |
|
| 314 | + |
|
| 315 | + // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 316 | + if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 317 | + foreach ($regs as $reg) { |
|
| 318 | + $insert = $reg[0]; |
|
| 319 | + // hack: on transforme les caracteres a proteger en les remplacant |
|
| 320 | + // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 321 | + $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 322 | + $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + // trouver les blocs idiomes et les traiter à part |
|
| 327 | + $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 328 | + $ei = ($ei !== $letexte); |
|
| 329 | + |
|
| 330 | + // trouver les blocs multi et les traiter a part |
|
| 331 | + $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 332 | + $em = ($em !== $letexte); |
|
| 333 | + |
|
| 334 | + // Charger & appliquer les fonctions de typographie |
|
| 335 | + $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 336 | + $letexte = $typographie($letexte); |
|
| 337 | + |
|
| 338 | + // Les citations en une autre langue, s'il y a lieu |
|
| 339 | + if ($em) { |
|
| 340 | + $letexte = echappe_retour($letexte, 'multi'); |
|
| 341 | + } |
|
| 342 | + if ($ei) { |
|
| 343 | + $letexte = echappe_retour($letexte, 'idiome'); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + // Retablir les caracteres proteges |
|
| 347 | + $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 348 | + |
|
| 349 | + // pipeline |
|
| 350 | + $letexte = pipeline('post_typo', $letexte); |
|
| 351 | + |
|
| 352 | + # un message pour abs_url - on est passe en mode texte |
|
| 353 | + $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 354 | + |
|
| 355 | + return $letexte; |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | * @return string |
| 369 | 369 | */ |
| 370 | 370 | function paragrapher($letexte, $forcer = true) { |
| 371 | - return $letexte; |
|
| 371 | + return $letexte; |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | /** |
@@ -380,11 +380,11 @@ discard block |
||
| 380 | 380 | * @return string Texte |
| 381 | 381 | **/ |
| 382 | 382 | function traiter_retours_chariots($letexte) { |
| 383 | - $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 384 | - $letexte = preg_replace(",<p[>[:space:]],iS", "\n\n\\0", $letexte); |
|
| 385 | - $letexte = preg_replace(",</p[>[:space:]],iS", "\\0\n\n", $letexte); |
|
| 383 | + $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 384 | + $letexte = preg_replace(",<p[>[:space:]],iS", "\n\n\\0", $letexte); |
|
| 385 | + $letexte = preg_replace(",</p[>[:space:]],iS", "\\0\n\n", $letexte); |
|
| 386 | 386 | |
| 387 | - return $letexte; |
|
| 387 | + return $letexte; |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | |
@@ -410,37 +410,37 @@ discard block |
||
| 410 | 410 | * Texte transformé |
| 411 | 411 | **/ |
| 412 | 412 | function propre($t, $connect = null, $env = array()) { |
| 413 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 414 | - // prive etant historiquement ecrits sans argment $connect |
|
| 415 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 416 | - // ou il faut passer interdire_script explicitement |
|
| 417 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 418 | - // ne seront pas perturbes |
|
| 419 | - $interdire_script = false; |
|
| 420 | - if (is_null($connect)) { |
|
| 421 | - $connect = ''; |
|
| 422 | - $interdire_script = true; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - if (!$t) { |
|
| 426 | - return strval($t); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 430 | - // avant echappement des balises <html> |
|
| 431 | - // https://core.spip.net/issues/3371 |
|
| 432 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 433 | - // https://core.spip.net/issues/4166 |
|
| 434 | - if ($interdire_script |
|
| 435 | - or $GLOBALS['filtrer_javascript'] == -1 |
|
| 436 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0) |
|
| 437 | - or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 438 | - $t = echapper_html_suspect($t, false); |
|
| 439 | - } |
|
| 440 | - $t = echappe_html($t); |
|
| 441 | - $t = expanser_liens($t, $connect, $env); |
|
| 442 | - $t = traiter_raccourcis($t); |
|
| 443 | - $t = echappe_retour_modeles($t, $interdire_script); |
|
| 444 | - |
|
| 445 | - return $t; |
|
| 413 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 414 | + // prive etant historiquement ecrits sans argment $connect |
|
| 415 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 416 | + // ou il faut passer interdire_script explicitement |
|
| 417 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 418 | + // ne seront pas perturbes |
|
| 419 | + $interdire_script = false; |
|
| 420 | + if (is_null($connect)) { |
|
| 421 | + $connect = ''; |
|
| 422 | + $interdire_script = true; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + if (!$t) { |
|
| 426 | + return strval($t); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 430 | + // avant echappement des balises <html> |
|
| 431 | + // https://core.spip.net/issues/3371 |
|
| 432 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 433 | + // https://core.spip.net/issues/4166 |
|
| 434 | + if ($interdire_script |
|
| 435 | + or $GLOBALS['filtrer_javascript'] == -1 |
|
| 436 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0) |
|
| 437 | + or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 438 | + $t = echapper_html_suspect($t, false); |
|
| 439 | + } |
|
| 440 | + $t = echappe_html($t); |
|
| 441 | + $t = expanser_liens($t, $connect, $env); |
|
| 442 | + $t = traiter_raccourcis($t); |
|
| 443 | + $t = echappe_retour_modeles($t, $interdire_script); |
|
| 444 | + |
|
| 445 | + return $t; |
|
| 446 | 446 | } |
@@ -104,11 +104,11 @@ discard block |
||
| 104 | 104 | function echappe_js($t, $class = ' class = "echappe-js"') { |
| 105 | 105 | foreach (array('script', 'iframe') as $tag) { |
| 106 | 106 | if (stripos($t, "<$tag") !== false |
| 107 | - and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 107 | + and preg_match_all(',<'.$tag.'.*?($|</'.$tag.'.),isS', $t, $r, PREG_SET_ORDER) |
|
| 108 | 108 | ) { |
| 109 | 109 | foreach ($r as $regs) { |
| 110 | 110 | $t = str_replace($regs[0], |
| 111 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 111 | + "<code$class>".nl2br(spip_htmlspecialchars($regs[0])).'</code>', |
|
| 112 | 112 | $t); |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @return string |
| 143 | 143 | * Code protégé |
| 144 | 144 | **/ |
| 145 | -function interdire_scripts($arg, $mode_filtre=null) { |
|
| 145 | +function interdire_scripts($arg, $mode_filtre = null) { |
|
| 146 | 146 | // on memorise le resultat sur les arguments non triviaux |
| 147 | 147 | static $dejavu = array(); |
| 148 | 148 | |
@@ -160,10 +160,10 @@ discard block |
||
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | // echapper les tags asp/php |
| 163 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 163 | + $t = str_replace('<'.'%', '<%', $arg); |
|
| 164 | 164 | |
| 165 | 165 | // echapper le php |
| 166 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 166 | + $t = str_replace('<'.'?', '<?', $t); |
|
| 167 | 167 | |
| 168 | 168 | // echapper le < script language=php > |
| 169 | 169 | $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
@@ -185,10 +185,10 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | // Reinserer les echappements des modeles |
| 187 | 187 | if (defined('_PROTEGE_JS_MODELES')) { |
| 188 | - $t = echappe_retour($t, "javascript" . _PROTEGE_JS_MODELES); |
|
| 188 | + $t = echappe_retour($t, "javascript"._PROTEGE_JS_MODELES); |
|
| 189 | 189 | } |
| 190 | 190 | if (defined('_PROTEGE_PHP_MODELES')) { |
| 191 | - $t = echappe_retour($t, "php" . _PROTEGE_PHP_MODELES); |
|
| 191 | + $t = echappe_retour($t, "php"._PROTEGE_PHP_MODELES); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | return $dejavu[$mode_filtre][$arg] = $t; |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
| 274 | 274 | // https://core.spip.net/issues/4166 |
| 275 | 275 | if ($GLOBALS['filtrer_javascript'] == -1 |
| 276 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 276 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0)) { |
|
| 277 | 277 | $letexte = echapper_html_suspect($letexte); |
| 278 | 278 | } |
| 279 | 279 | |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | define('_TYPO_PROTEGER', "!':;?~%-"); |
| 285 | 285 | define('_TYPO_PROTECTEUR', "\x1\x2\x3\x4\x5\x6\x7\x8"); |
| 286 | 286 | |
| 287 | -define('_TYPO_BALISE', ",</?[a-z!][^<>]*[" . preg_quote(_TYPO_PROTEGER) . "][^<>]*>,imsS"); |
|
| 287 | +define('_TYPO_BALISE', ",</?[a-z!][^<>]*[".preg_quote(_TYPO_PROTEGER)."][^<>]*>,imsS"); |
|
| 288 | 288 | |
| 289 | 289 | /** |
| 290 | 290 | * Corrige la typographie |
@@ -433,8 +433,8 @@ discard block |
||
| 433 | 433 | // https://core.spip.net/issues/4166 |
| 434 | 434 | if ($interdire_script |
| 435 | 435 | or $GLOBALS['filtrer_javascript'] == -1 |
| 436 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0) |
|
| 437 | - or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 436 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 437 | + or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0)) { |
|
| 438 | 438 | $t = echapper_html_suspect($t, false); |
| 439 | 439 | } |
| 440 | 440 | $t = echappe_html($t); |
@@ -245,7 +245,7 @@ |
||
| 245 | 245 | * @param array $matches |
| 246 | 246 | * Branches de l'arbre validant la rexgep |
| 247 | 247 | * @param bool $init ? |
| 248 | - * @return bool |
|
| 248 | + * @return integer |
|
| 249 | 249 | * false si aucun élément ne valide l'expression régulière, true sinon. |
| 250 | 250 | **/ |
| 251 | 251 | function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true) { |
@@ -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 | |
@@ -47,23 +47,23 @@ discard block |
||
| 47 | 47 | * - false si l'arbre xml ne peut être créé ou est vide |
| 48 | 48 | **/ |
| 49 | 49 | function spip_xml_load($fichier, $strict = true, $clean = true, $taille_max = 1048576, $datas = '', $profondeur = -1) { |
| 50 | - $contenu = ""; |
|
| 51 | - if (tester_url_absolue($fichier)) { |
|
| 52 | - include_spip('inc/distant'); |
|
| 53 | - $contenu = recuperer_page($fichier, false, false, $taille_max, $datas); |
|
| 54 | - } else { |
|
| 55 | - lire_fichier($fichier, $contenu); |
|
| 56 | - } |
|
| 57 | - $arbre = array(); |
|
| 58 | - if ($contenu) { |
|
| 59 | - $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 60 | - } |
|
| 50 | + $contenu = ""; |
|
| 51 | + if (tester_url_absolue($fichier)) { |
|
| 52 | + include_spip('inc/distant'); |
|
| 53 | + $contenu = recuperer_page($fichier, false, false, $taille_max, $datas); |
|
| 54 | + } else { |
|
| 55 | + lire_fichier($fichier, $contenu); |
|
| 56 | + } |
|
| 57 | + $arbre = array(); |
|
| 58 | + if ($contenu) { |
|
| 59 | + $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return count($arbre) ? $arbre : false; |
|
| 62 | + return count($arbre) ? $arbre : false; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | if (!defined('_SPIP_XML_TAG_SPLIT')) { |
| 66 | - define('_SPIP_XML_TAG_SPLIT', "{<([^:>][^>]*?)>}sS"); |
|
| 66 | + define('_SPIP_XML_TAG_SPLIT', "{<([^:>][^>]*?)>}sS"); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -82,151 +82,151 @@ discard block |
||
| 82 | 82 | * - false si l'arbre xml ne peut être créé ou est vide |
| 83 | 83 | **/ |
| 84 | 84 | function spip_xml_parse(&$texte, $strict = true, $clean = true, $profondeur = -1) { |
| 85 | - $out = array(); |
|
| 86 | - // enlever les commentaires |
|
| 87 | - $charset = 'AUTO'; |
|
| 88 | - if ($clean === true) { |
|
| 89 | - if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 90 | - $charset = $regs[2]; |
|
| 91 | - } |
|
| 92 | - $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 93 | - $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 94 | - include_spip('inc/charsets'); |
|
| 95 | - $clean = $charset; |
|
| 96 | - //$texte = importer_charset($texte,$charset); |
|
| 97 | - } |
|
| 98 | - if (is_string($clean)) { |
|
| 99 | - $charset = $clean; |
|
| 100 | - } |
|
| 101 | - $txt = $texte; |
|
| 85 | + $out = array(); |
|
| 86 | + // enlever les commentaires |
|
| 87 | + $charset = 'AUTO'; |
|
| 88 | + if ($clean === true) { |
|
| 89 | + if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 90 | + $charset = $regs[2]; |
|
| 91 | + } |
|
| 92 | + $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 93 | + $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 94 | + include_spip('inc/charsets'); |
|
| 95 | + $clean = $charset; |
|
| 96 | + //$texte = importer_charset($texte,$charset); |
|
| 97 | + } |
|
| 98 | + if (is_string($clean)) { |
|
| 99 | + $charset = $clean; |
|
| 100 | + } |
|
| 101 | + $txt = $texte; |
|
| 102 | 102 | |
| 103 | - // tant qu'il y a des tags |
|
| 104 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 105 | - while (count($chars) >= 2) { |
|
| 106 | - // tag ouvrant |
|
| 107 | - //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 103 | + // tant qu'il y a des tags |
|
| 104 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 105 | + while (count($chars) >= 2) { |
|
| 106 | + // tag ouvrant |
|
| 107 | + //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 108 | 108 | |
| 109 | - // $before doit etre vide ou des espaces uniquements! |
|
| 110 | - $before = trim($chars[0]); |
|
| 109 | + // $before doit etre vide ou des espaces uniquements! |
|
| 110 | + $before = trim($chars[0]); |
|
| 111 | 111 | |
| 112 | - if (strlen($before) > 0) { |
|
| 113 | - return importer_charset($texte, $charset); |
|
| 114 | - }//$texte; // before non vide, donc on est dans du texte |
|
| 112 | + if (strlen($before) > 0) { |
|
| 113 | + return importer_charset($texte, $charset); |
|
| 114 | + }//$texte; // before non vide, donc on est dans du texte |
|
| 115 | 115 | |
| 116 | - $tag = rtrim($chars[1]); |
|
| 117 | - $txt = $chars[2]; |
|
| 116 | + $tag = rtrim($chars[1]); |
|
| 117 | + $txt = $chars[2]; |
|
| 118 | 118 | |
| 119 | - if (strncmp($tag, '![CDATA[', 8) == 0) { |
|
| 120 | - return importer_charset($texte, $charset); |
|
| 121 | - }//$texte; |
|
| 122 | - if (substr($tag, -1) == '/') { // self closing tag |
|
| 123 | - $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 124 | - $out[$tag][] = ""; |
|
| 125 | - } else { |
|
| 126 | - $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 127 | - $closing_tag = reset($closing_tag); |
|
| 128 | - // tag fermant |
|
| 129 | - $ncclos = strlen("</$closing_tag>"); |
|
| 130 | - $p = strpos($txt, "</$closing_tag>"); |
|
| 131 | - if ($p !== false and (strpos($txt, "<") < $p)) { |
|
| 132 | - $nclose = 0; |
|
| 133 | - $nopen = 0; |
|
| 134 | - $d = 0; |
|
| 135 | - while ( |
|
| 136 | - $p !== false |
|
| 137 | - and ($morceau = substr($txt, $d, $p - $d)) |
|
| 138 | - and (($nopen += preg_match_all("{<" . preg_quote($closing_tag) . "(\s*>|\s[^>]*[^/>]>)}is", $morceau, |
|
| 139 | - $matches, PREG_SET_ORDER)) > $nclose) |
|
| 140 | - ) { |
|
| 141 | - $nclose++; |
|
| 142 | - $d = $p + $ncclos; |
|
| 143 | - $p = strpos($txt, "</$closing_tag>", $d); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - if ($p === false) { |
|
| 147 | - if ($strict) { |
|
| 148 | - $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 119 | + if (strncmp($tag, '![CDATA[', 8) == 0) { |
|
| 120 | + return importer_charset($texte, $charset); |
|
| 121 | + }//$texte; |
|
| 122 | + if (substr($tag, -1) == '/') { // self closing tag |
|
| 123 | + $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 124 | + $out[$tag][] = ""; |
|
| 125 | + } else { |
|
| 126 | + $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 127 | + $closing_tag = reset($closing_tag); |
|
| 128 | + // tag fermant |
|
| 129 | + $ncclos = strlen("</$closing_tag>"); |
|
| 130 | + $p = strpos($txt, "</$closing_tag>"); |
|
| 131 | + if ($p !== false and (strpos($txt, "<") < $p)) { |
|
| 132 | + $nclose = 0; |
|
| 133 | + $nopen = 0; |
|
| 134 | + $d = 0; |
|
| 135 | + while ( |
|
| 136 | + $p !== false |
|
| 137 | + and ($morceau = substr($txt, $d, $p - $d)) |
|
| 138 | + and (($nopen += preg_match_all("{<" . preg_quote($closing_tag) . "(\s*>|\s[^>]*[^/>]>)}is", $morceau, |
|
| 139 | + $matches, PREG_SET_ORDER)) > $nclose) |
|
| 140 | + ) { |
|
| 141 | + $nclose++; |
|
| 142 | + $d = $p + $ncclos; |
|
| 143 | + $p = strpos($txt, "</$closing_tag>", $d); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + if ($p === false) { |
|
| 147 | + if ($strict) { |
|
| 148 | + $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 149 | 149 | |
| 150 | - return $out; |
|
| 151 | - } else { |
|
| 152 | - return importer_charset($texte, $charset); |
|
| 153 | - }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 154 | - } |
|
| 155 | - $content = substr($txt, 0, $p); |
|
| 156 | - $txt = substr($txt, $p + $ncclos); |
|
| 157 | - if ($profondeur == 0 or strpos($content, "<") === false) // eviter une recursion si pas utile |
|
| 158 | - { |
|
| 159 | - $out[$tag][] = importer_charset($content, $charset); |
|
| 160 | - }//$content; |
|
| 161 | - else { |
|
| 162 | - $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 166 | - } |
|
| 167 | - if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 168 | - return $out; |
|
| 169 | - } else { |
|
| 170 | - return importer_charset($texte, $charset); |
|
| 171 | - }//$texte; |
|
| 150 | + return $out; |
|
| 151 | + } else { |
|
| 152 | + return importer_charset($texte, $charset); |
|
| 153 | + }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 154 | + } |
|
| 155 | + $content = substr($txt, 0, $p); |
|
| 156 | + $txt = substr($txt, $p + $ncclos); |
|
| 157 | + if ($profondeur == 0 or strpos($content, "<") === false) // eviter une recursion si pas utile |
|
| 158 | + { |
|
| 159 | + $out[$tag][] = importer_charset($content, $charset); |
|
| 160 | + }//$content; |
|
| 161 | + else { |
|
| 162 | + $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 166 | + } |
|
| 167 | + if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 168 | + return $out; |
|
| 169 | + } else { |
|
| 170 | + return importer_charset($texte, $charset); |
|
| 171 | + }//$texte; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // http://code.spip.net/@spip_xml_aplatit |
| 175 | 175 | function spip_xml_aplatit($arbre, $separateur = " ") { |
| 176 | - $s = ""; |
|
| 177 | - if (is_array($arbre)) { |
|
| 178 | - foreach ($arbre as $tag => $feuille) { |
|
| 179 | - if (is_array($feuille)) { |
|
| 180 | - if ($tag !== intval($tag)) { |
|
| 181 | - $f = spip_xml_aplatit($feuille, $separateur); |
|
| 182 | - if (strlen($f)) { |
|
| 183 | - $tagf = explode(" ", $tag); |
|
| 184 | - $tagf = $tagf[0]; |
|
| 185 | - $s .= "<$tag>$f</$tagf>"; |
|
| 186 | - } else { |
|
| 187 | - $s .= "<$tag />"; |
|
| 188 | - } |
|
| 189 | - } else { |
|
| 190 | - $s .= spip_xml_aplatit($feuille); |
|
| 191 | - } |
|
| 192 | - $s .= $separateur; |
|
| 193 | - } else { |
|
| 194 | - $s .= "$feuille$separateur"; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 176 | + $s = ""; |
|
| 177 | + if (is_array($arbre)) { |
|
| 178 | + foreach ($arbre as $tag => $feuille) { |
|
| 179 | + if (is_array($feuille)) { |
|
| 180 | + if ($tag !== intval($tag)) { |
|
| 181 | + $f = spip_xml_aplatit($feuille, $separateur); |
|
| 182 | + if (strlen($f)) { |
|
| 183 | + $tagf = explode(" ", $tag); |
|
| 184 | + $tagf = $tagf[0]; |
|
| 185 | + $s .= "<$tag>$f</$tagf>"; |
|
| 186 | + } else { |
|
| 187 | + $s .= "<$tag />"; |
|
| 188 | + } |
|
| 189 | + } else { |
|
| 190 | + $s .= spip_xml_aplatit($feuille); |
|
| 191 | + } |
|
| 192 | + $s .= $separateur; |
|
| 193 | + } else { |
|
| 194 | + $s .= "$feuille$separateur"; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s; |
|
| 199 | + return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | // http://code.spip.net/@spip_xml_tagname |
| 203 | 203 | function spip_xml_tagname($tag) { |
| 204 | - if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) { |
|
| 205 | - return $reg[1]; |
|
| 206 | - } |
|
| 204 | + if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) { |
|
| 205 | + return $reg[1]; |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - return ""; |
|
| 208 | + return ""; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | // http://code.spip.net/@spip_xml_decompose_tag |
| 212 | 212 | function spip_xml_decompose_tag($tag) { |
| 213 | - $tagname = spip_xml_tagname($tag); |
|
| 214 | - $liste = array(); |
|
| 215 | - $p = strpos($tag, ' '); |
|
| 216 | - $tag = substr($tag, $p); |
|
| 217 | - $p = strpos($tag, '='); |
|
| 218 | - while ($p !== false) { |
|
| 219 | - $attr = trim(substr($tag, 0, $p)); |
|
| 220 | - $tag = ltrim(substr($tag, $p + 1)); |
|
| 221 | - $quote = $tag{0}; |
|
| 222 | - $p = strpos($tag, $quote, 1); |
|
| 223 | - $cont = substr($tag, 1, $p - 1); |
|
| 224 | - $liste[$attr] = $cont; |
|
| 225 | - $tag = substr($tag, $p + 1); |
|
| 226 | - $p = strpos($tag, '='); |
|
| 227 | - } |
|
| 213 | + $tagname = spip_xml_tagname($tag); |
|
| 214 | + $liste = array(); |
|
| 215 | + $p = strpos($tag, ' '); |
|
| 216 | + $tag = substr($tag, $p); |
|
| 217 | + $p = strpos($tag, '='); |
|
| 218 | + while ($p !== false) { |
|
| 219 | + $attr = trim(substr($tag, 0, $p)); |
|
| 220 | + $tag = ltrim(substr($tag, $p + 1)); |
|
| 221 | + $quote = $tag{0}; |
|
| 222 | + $p = strpos($tag, $quote, 1); |
|
| 223 | + $cont = substr($tag, 1, $p - 1); |
|
| 224 | + $liste[$attr] = $cont; |
|
| 225 | + $tag = substr($tag, $p + 1); |
|
| 226 | + $p = strpos($tag, '='); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - return array($tagname, $liste); |
|
| 229 | + return array($tagname, $liste); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -249,21 +249,21 @@ discard block |
||
| 249 | 249 | * false si aucun élément ne valide l'expression régulière, true sinon. |
| 250 | 250 | **/ |
| 251 | 251 | function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true) { |
| 252 | - if ($init) { |
|
| 253 | - $matches = array(); |
|
| 254 | - } |
|
| 255 | - if (is_array($arbre) && count($arbre)) { |
|
| 256 | - foreach (array_keys($arbre) as $tag) { |
|
| 257 | - if (preg_match($regexp, $tag)) { |
|
| 258 | - $matches[$tag] = &$arbre[$tag]; |
|
| 259 | - } |
|
| 260 | - if (is_array($arbre[$tag])) { |
|
| 261 | - foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 262 | - spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - } |
|
| 252 | + if ($init) { |
|
| 253 | + $matches = array(); |
|
| 254 | + } |
|
| 255 | + if (is_array($arbre) && count($arbre)) { |
|
| 256 | + foreach (array_keys($arbre) as $tag) { |
|
| 257 | + if (preg_match($regexp, $tag)) { |
|
| 258 | + $matches[$tag] = &$arbre[$tag]; |
|
| 259 | + } |
|
| 260 | + if (is_array($arbre[$tag])) { |
|
| 261 | + foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 262 | + spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - return (count($matches)); |
|
| 268 | + return (count($matches)); |
|
| 269 | 269 | } |
@@ -135,7 +135,7 @@ |
||
| 135 | 135 | while ( |
| 136 | 136 | $p !== false |
| 137 | 137 | and ($morceau = substr($txt, $d, $p - $d)) |
| 138 | - and (($nopen += preg_match_all("{<" . preg_quote($closing_tag) . "(\s*>|\s[^>]*[^/>]>)}is", $morceau, |
|
| 138 | + and (($nopen += preg_match_all("{<".preg_quote($closing_tag)."(\s*>|\s[^>]*[^/>]>)}is", $morceau, |
|
| 139 | 139 | $matches, PREG_SET_ORDER)) > $nclose) |
| 140 | 140 | ) { |
| 141 | 141 | $nclose++; |
@@ -154,9 +154,11 @@ |
||
| 154 | 154 | } |
| 155 | 155 | $content = substr($txt, 0, $p); |
| 156 | 156 | $txt = substr($txt, $p + $ncclos); |
| 157 | - if ($profondeur == 0 or strpos($content, "<") === false) // eviter une recursion si pas utile |
|
| 157 | + if ($profondeur == 0 or strpos($content, "<") === false) { |
|
| 158 | + // eviter une recursion si pas utile |
|
| 158 | 159 | { |
| 159 | 160 | $out[$tag][] = importer_charset($content, $charset); |
| 161 | + } |
|
| 160 | 162 | }//$content; |
| 161 | 163 | else { |
| 162 | 164 | $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
@@ -235,6 +235,9 @@ |
||
| 235 | 235 | |
| 236 | 236 | |
| 237 | 237 | // http://code.spip.net/@install_premier_auteur |
| 238 | +/** |
|
| 239 | + * @param string $hidden |
|
| 240 | + */ |
|
| 238 | 241 | function install_premier_auteur($email, $login, $nom, $pass, $hidden, $auteur_obligatoire) { |
| 239 | 242 | return info_progression_etape(3, 'etape_', 'install/') . |
| 240 | 243 | info_etape( |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | = spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db); |
| 48 | 48 | |
| 49 | 49 | $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
| 50 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 50 | + = $GLOBALS['spip_'.$server_db.'_functions_'.$GLOBALS['spip_sql_version']]; |
|
| 51 | 51 | |
| 52 | 52 | $fquery = sql_serveur('query', $server_db); |
| 53 | 53 | if ($choix_db == 'new_spip') { |
@@ -57,13 +57,13 @@ discard block |
||
| 57 | 57 | if (!$ok) { |
| 58 | 58 | $re = "Impossible de creer la base $re"; |
| 59 | 59 | spip_log($re); |
| 60 | - return '<p>' . _T('avis_connexion_erreur_creer_base') . "</p><!--\n$re\n-->"; |
|
| 60 | + return '<p>'._T('avis_connexion_erreur_creer_base')."</p><!--\n$re\n-->"; |
|
| 61 | 61 | } |
| 62 | 62 | } else { |
| 63 | 63 | $re = "Le nom de la base doit correspondre a $re"; |
| 64 | 64 | spip_log($re); |
| 65 | 65 | |
| 66 | - return '<p>' . _T('avis_connexion_erreur_nom_base') . "</p><!--\n$re\n-->"; |
|
| 66 | + return '<p>'._T('avis_connexion_erreur_nom_base')."</p><!--\n$re\n-->"; |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db); |
| 75 | 75 | |
| 76 | 76 | $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
| 77 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 77 | + = $GLOBALS['spip_'.$server_db.'_functions_'.$GLOBALS['spip_sql_version']]; |
|
| 78 | 78 | |
| 79 | 79 | // Completer le tableau decrivant la connexion |
| 80 | 80 | |
| 81 | 81 | $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
| 82 | 82 | $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
| 83 | 83 | |
| 84 | - $old = sql_showbase($table_prefix . '_meta', $server_db); |
|
| 84 | + $old = sql_showbase($table_prefix.'_meta', $server_db); |
|
| 85 | 85 | if ($old) { |
| 86 | 86 | $old = sql_fetch($old, $server_db); |
| 87 | 87 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $charset['charset']; |
| 101 | 101 | $charsetbase = $charset['charset']; |
| 102 | 102 | } else { |
| 103 | - spip_log(_DEFAULT_CHARSET . ' inconnu du serveur SQL'); |
|
| 103 | + spip_log(_DEFAULT_CHARSET.' inconnu du serveur SQL'); |
|
| 104 | 104 | $charsetbase = 'standard'; |
| 105 | 105 | } |
| 106 | 106 | spip_log("Creation des tables. Codage $charsetbase"); |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | if ($r) { |
| 151 | 151 | $r = sql_fetch($r, $server_db); |
| 152 | 152 | } |
| 153 | - $version_installee = !$r ? 0 : (double)$r['valeur']; |
|
| 153 | + $version_installee = !$r ? 0 : (double) $r['valeur']; |
|
| 154 | 154 | if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) { |
| 155 | 155 | $fupdateq( |
| 156 | 156 | 'spip_meta', |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | '', |
| 160 | 160 | $server_db |
| 161 | 161 | ); |
| 162 | - spip_log('nouvelle version installee: ' . $GLOBALS['spip_version_base']); |
|
| 162 | + spip_log('nouvelle version installee: '.$GLOBALS['spip_version_base']); |
|
| 163 | 163 | } |
| 164 | 164 | // eliminer la derniere operation d'admin mal terminee |
| 165 | 165 | // notamment la mise a jour |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | if ($chmod_db) { |
| 187 | 187 | install_fichier_connexion( |
| 188 | 188 | _FILE_CHMOD_TMP, |
| 189 | - "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', " . sprintf('0%3o', $chmod_db) . ");\n" |
|
| 189 | + "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', ".sprintf('0%3o', $chmod_db).");\n" |
|
| 190 | 190 | ); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -236,16 +236,16 @@ discard block |
||
| 236 | 236 | |
| 237 | 237 | // http://code.spip.net/@install_premier_auteur |
| 238 | 238 | function install_premier_auteur($email, $login, $nom, $pass, $hidden, $auteur_obligatoire) { |
| 239 | - return info_progression_etape(3, 'etape_', 'install/') . |
|
| 239 | + return info_progression_etape(3, 'etape_', 'install/'). |
|
| 240 | 240 | info_etape( |
| 241 | 241 | _T('info_informations_personnelles'), |
| 242 | - '<b>' . _T('texte_informations_personnelles_1') . '</b>' . |
|
| 243 | - aider('install5', true) . |
|
| 244 | - '<p>' . |
|
| 242 | + '<b>'._T('texte_informations_personnelles_1').'</b>'. |
|
| 243 | + aider('install5', true). |
|
| 244 | + '<p>'. |
|
| 245 | 245 | ($auteur_obligatoire ? |
| 246 | 246 | '' |
| 247 | 247 | : |
| 248 | - _T('texte_informations_personnelles_2') . ' ' . _T('info_laisser_champs_vides') |
|
| 248 | + _T('texte_informations_personnelles_2').' '._T('info_laisser_champs_vides') |
|
| 249 | 249 | ) |
| 250 | 250 | ) |
| 251 | 251 | . generer_form_ecrire('install', ( |
@@ -255,12 +255,12 @@ discard block |
||
| 255 | 255 | _T('info_identification_publique'), |
| 256 | 256 | array( |
| 257 | 257 | 'nom' => array( |
| 258 | - 'label' => '<b>' . _T('entree_signature') . "</b><br />\n" . _T('entree_nom_pseudo_1') . "\n", |
|
| 258 | + 'label' => '<b>'._T('entree_signature')."</b><br />\n"._T('entree_nom_pseudo_1')."\n", |
|
| 259 | 259 | 'valeur' => $nom, |
| 260 | 260 | 'required' => $auteur_obligatoire, |
| 261 | 261 | ), |
| 262 | 262 | 'email' => array( |
| 263 | - 'label' => '<b>' . _T('entree_adresse_email') . "</b>\n", |
|
| 263 | + 'label' => '<b>'._T('entree_adresse_email')."</b>\n", |
|
| 264 | 264 | 'valeur' => $email, |
| 265 | 265 | ) |
| 266 | 266 | ) |
@@ -270,23 +270,23 @@ discard block |
||
| 270 | 270 | _T('entree_identifiants_connexion'), |
| 271 | 271 | array( |
| 272 | 272 | 'login' => array( |
| 273 | - 'label' => '<b>' . _T('entree_login') . "</b><br />\n" . _T( |
|
| 273 | + 'label' => '<b>'._T('entree_login')."</b><br />\n"._T( |
|
| 274 | 274 | 'info_login_trop_court_car_pluriel', |
| 275 | 275 | array('nb' => _LOGIN_TROP_COURT) |
| 276 | - ) . "\n", |
|
| 276 | + )."\n", |
|
| 277 | 277 | 'valeur' => $login, |
| 278 | 278 | 'required' => $auteur_obligatoire, |
| 279 | 279 | ), |
| 280 | 280 | 'pass' => array( |
| 281 | - 'label' => '<b>' . _T('entree_mot_passe') . "</b><br />\n" . _T( |
|
| 281 | + 'label' => '<b>'._T('entree_mot_passe')."</b><br />\n"._T( |
|
| 282 | 282 | 'info_passe_trop_court_car_pluriel', |
| 283 | 283 | array('nb' => _PASS_LONGUEUR_MINI) |
| 284 | - ) . "\n", |
|
| 284 | + )."\n", |
|
| 285 | 285 | 'valeur' => $pass, |
| 286 | 286 | 'required' => $auteur_obligatoire, |
| 287 | 287 | ), |
| 288 | 288 | 'pass_verif' => array( |
| 289 | - 'label' => '<b>' . _T('info_confirmer_passe') . "</b><br />\n", |
|
| 289 | + 'label' => '<b>'._T('info_confirmer_passe')."</b><br />\n", |
|
| 290 | 290 | 'valeur' => $pass, |
| 291 | 291 | 'required' => $auteur_obligatoire, |
| 292 | 292 | ) |
@@ -331,9 +331,9 @@ discard block |
||
| 331 | 331 | |
| 332 | 332 | if ($res) { |
| 333 | 333 | $res = info_progression_etape(2, 'etape_', 'install/', true) |
| 334 | - . "<div class='error'><h3>" . _T('avis_operation_echec') . '</h3>' |
|
| 334 | + . "<div class='error'><h3>"._T('avis_operation_echec').'</h3>' |
|
| 335 | 335 | . $res |
| 336 | - . '<p>' . _T('texte_operation_echec') . '</p>' |
|
| 336 | + . '<p>'._T('texte_operation_echec').'</p>' |
|
| 337 | 337 | . '</div>'; |
| 338 | 338 | } |
| 339 | 339 | } else { |
@@ -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 | include_spip('inc/headers'); |
@@ -20,199 +20,199 @@ discard block |
||
| 20 | 20 | // http://code.spip.net/@install_bases |
| 21 | 21 | function install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db) { |
| 22 | 22 | |
| 23 | - // Prefix des tables : |
|
| 24 | - // S'il n'est pas defini par mes_options/inc/mutualiser, on va le creer |
|
| 25 | - // a partir de ce qui est envoye a l'installation |
|
| 26 | - if (!defined('_INSTALL_TABLE_PREFIX')) { |
|
| 27 | - $table_prefix = ($GLOBALS['table_prefix'] != 'spip') |
|
| 28 | - ? $GLOBALS['table_prefix'] |
|
| 29 | - : preparer_prefixe_tables(_request('tprefix')); |
|
| 30 | - // S'il est vide on remet spip |
|
| 31 | - if (!$table_prefix) { |
|
| 32 | - $table_prefix = 'spip'; |
|
| 33 | - } |
|
| 34 | - } else { |
|
| 35 | - $table_prefix = _INSTALL_TABLE_PREFIX; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - if (preg_match(',(.*):(.*),', $adresse_db, $r)) { |
|
| 39 | - list(, $adresse_db, $port) = $r; |
|
| 40 | - } else { |
|
| 41 | - $port = ''; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $GLOBALS['connexions'][$server_db] |
|
| 45 | - = spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db); |
|
| 46 | - |
|
| 47 | - $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 48 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 49 | - |
|
| 50 | - $fquery = sql_serveur('query', $server_db); |
|
| 51 | - if ($choix_db == 'new_spip') { |
|
| 52 | - $re = ',^[a-z_][a-z_0-9-]*$,i'; |
|
| 53 | - if (preg_match($re, $sel_db)) { |
|
| 54 | - $ok = sql_create_base($sel_db, $server_db); |
|
| 55 | - if (!$ok) { |
|
| 56 | - $re = "Impossible de creer la base $re"; |
|
| 57 | - spip_log($re); |
|
| 58 | - return '<p>' . _T('avis_connexion_erreur_creer_base') . "</p><!--\n$re\n-->"; |
|
| 59 | - } |
|
| 60 | - } else { |
|
| 61 | - $re = "Le nom de la base doit correspondre a $re"; |
|
| 62 | - spip_log($re); |
|
| 63 | - |
|
| 64 | - return '<p>' . _T('avis_connexion_erreur_nom_base') . "</p><!--\n$re\n-->"; |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // on rejoue la connexion apres avoir teste si il faut lui indiquer |
|
| 69 | - // un sql_mode |
|
| 70 | - install_mode_appel($server_db, false); |
|
| 71 | - $GLOBALS['connexions'][$server_db] |
|
| 72 | - = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db); |
|
| 73 | - |
|
| 74 | - $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 75 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 76 | - |
|
| 77 | - // Completer le tableau decrivant la connexion |
|
| 78 | - |
|
| 79 | - $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
|
| 80 | - $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
|
| 81 | - |
|
| 82 | - $old = sql_showbase($table_prefix . '_meta', $server_db); |
|
| 83 | - if ($old) { |
|
| 84 | - $old = sql_fetch($old, $server_db); |
|
| 85 | - } |
|
| 86 | - if (!$old) { |
|
| 87 | - // Si possible, demander au serveur d'envoyer les textes |
|
| 88 | - // dans le codage std de SPIP, |
|
| 89 | - $charset = sql_get_charset(_DEFAULT_CHARSET, $server_db); |
|
| 90 | - |
|
| 91 | - if ($charset) { |
|
| 92 | - sql_set_charset($charset['charset'], $server_db); |
|
| 93 | - $GLOBALS['meta']['charset_sql_base'] = |
|
| 94 | - $charset['charset']; |
|
| 95 | - $GLOBALS['meta']['charset_collation_sql_base'] = |
|
| 96 | - $charset['collation']; |
|
| 97 | - $GLOBALS['meta']['charset_sql_connexion'] = |
|
| 98 | - $charset['charset']; |
|
| 99 | - $charsetbase = $charset['charset']; |
|
| 100 | - } else { |
|
| 101 | - spip_log(_DEFAULT_CHARSET . ' inconnu du serveur SQL'); |
|
| 102 | - $charsetbase = 'standard'; |
|
| 103 | - } |
|
| 104 | - spip_log("Creation des tables. Codage $charsetbase"); |
|
| 105 | - creer_base($server_db); // AT LAST |
|
| 106 | - // memoriser avec quel charset on l'a creee |
|
| 107 | - |
|
| 108 | - if ($charset) { |
|
| 109 | - $t = array( |
|
| 110 | - 'nom' => 'charset_sql_base', |
|
| 111 | - 'valeur' => $charset['charset'], |
|
| 112 | - 'impt' => 'non' |
|
| 113 | - ); |
|
| 114 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 115 | - $t['nom'] = 'charset_collation_sql_base'; |
|
| 116 | - $t['valeur'] = $charset['collation']; |
|
| 117 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 118 | - $t['nom'] = 'charset_sql_connexion'; |
|
| 119 | - $t['valeur'] = $charset['charset']; |
|
| 120 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 121 | - } |
|
| 122 | - $t = array( |
|
| 123 | - 'nom' => 'version_installee', |
|
| 124 | - 'valeur' => $GLOBALS['spip_version_base'], |
|
| 125 | - 'impt' => 'non' |
|
| 126 | - ); |
|
| 127 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 128 | - $t['nom'] = 'nouvelle_install'; |
|
| 129 | - $t['valeur'] = 1; |
|
| 130 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 131 | - // positionner la langue par defaut du site si un cookie de lang a ete mis |
|
| 132 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 133 | - @sql_insertq( |
|
| 134 | - 'spip_meta', |
|
| 135 | - array('nom' => 'langue_site', 'valeur' => $_COOKIE['spip_lang_ecrire']), |
|
| 136 | - '', |
|
| 137 | - $server_db |
|
| 138 | - ); |
|
| 139 | - } |
|
| 140 | - } else { |
|
| 141 | - // pour recreer les tables disparues au besoin |
|
| 142 | - spip_log('Table des Meta deja la. Verification des autres.'); |
|
| 143 | - creer_base($server_db); |
|
| 144 | - $fupdateq = sql_serveur('updateq', $server_db); |
|
| 145 | - |
|
| 146 | - $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='version_installee'", $server_db); |
|
| 147 | - |
|
| 148 | - if ($r) { |
|
| 149 | - $r = sql_fetch($r, $server_db); |
|
| 150 | - } |
|
| 151 | - $version_installee = !$r ? 0 : (double)$r['valeur']; |
|
| 152 | - if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) { |
|
| 153 | - $fupdateq( |
|
| 154 | - 'spip_meta', |
|
| 155 | - array('valeur' => $GLOBALS['spip_version_base'], 'impt' => 'non'), |
|
| 156 | - "nom='version_installee'", |
|
| 157 | - '', |
|
| 158 | - $server_db |
|
| 159 | - ); |
|
| 160 | - spip_log('nouvelle version installee: ' . $GLOBALS['spip_version_base']); |
|
| 161 | - } |
|
| 162 | - // eliminer la derniere operation d'admin mal terminee |
|
| 163 | - // notamment la mise a jour |
|
| 164 | - @$fquery("DELETE FROM spip_meta WHERE nom='import_all' OR nom='admin'", $server_db); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // recuperer le charset de la connexion dans les meta |
|
| 168 | - $charset = ''; |
|
| 169 | - $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='charset_sql_connexion'", $server_db); |
|
| 170 | - if ($r) { |
|
| 171 | - $r = sql_fetch($r, $server_db); |
|
| 172 | - } |
|
| 173 | - if ($r) { |
|
| 174 | - $charset = $r['valeur']; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - $ligne_rappel = install_mode_appel($server_db); |
|
| 178 | - |
|
| 179 | - $result_ok = @$fquery('SELECT COUNT(*) FROM spip_meta', $server_db); |
|
| 180 | - if (!$result_ok) { |
|
| 181 | - return "<!--\nvielle = $old rappel= $ligne_rappel\n-->"; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - if ($chmod_db) { |
|
| 185 | - install_fichier_connexion( |
|
| 186 | - _FILE_CHMOD_TMP, |
|
| 187 | - "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', " . sprintf('0%3o', $chmod_db) . ");\n" |
|
| 188 | - ); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // si ce fichier existe a cette etape c'est qu'il provient |
|
| 192 | - // d'une installation qui ne l'a pas cree correctement. |
|
| 193 | - // Le supprimer pour que _FILE_CONNECT_TMP prime. |
|
| 194 | - |
|
| 195 | - if (_FILE_CONNECT and file_exists(_FILE_CONNECT)) { |
|
| 196 | - spip_unlink(_FILE_CONNECT); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - install_fichier_connexion( |
|
| 200 | - _FILE_CONNECT_TMP, |
|
| 201 | - $ligne_rappel |
|
| 202 | - . install_connexion( |
|
| 203 | - $adresse_db, |
|
| 204 | - $port, |
|
| 205 | - $login_db, |
|
| 206 | - $pass_db, |
|
| 207 | - $sel_db, |
|
| 208 | - $server_db, |
|
| 209 | - $table_prefix, |
|
| 210 | - '', |
|
| 211 | - $charset |
|
| 212 | - ) |
|
| 213 | - ); |
|
| 214 | - |
|
| 215 | - return ''; |
|
| 23 | + // Prefix des tables : |
|
| 24 | + // S'il n'est pas defini par mes_options/inc/mutualiser, on va le creer |
|
| 25 | + // a partir de ce qui est envoye a l'installation |
|
| 26 | + if (!defined('_INSTALL_TABLE_PREFIX')) { |
|
| 27 | + $table_prefix = ($GLOBALS['table_prefix'] != 'spip') |
|
| 28 | + ? $GLOBALS['table_prefix'] |
|
| 29 | + : preparer_prefixe_tables(_request('tprefix')); |
|
| 30 | + // S'il est vide on remet spip |
|
| 31 | + if (!$table_prefix) { |
|
| 32 | + $table_prefix = 'spip'; |
|
| 33 | + } |
|
| 34 | + } else { |
|
| 35 | + $table_prefix = _INSTALL_TABLE_PREFIX; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + if (preg_match(',(.*):(.*),', $adresse_db, $r)) { |
|
| 39 | + list(, $adresse_db, $port) = $r; |
|
| 40 | + } else { |
|
| 41 | + $port = ''; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $GLOBALS['connexions'][$server_db] |
|
| 45 | + = spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db); |
|
| 46 | + |
|
| 47 | + $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 48 | + = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 49 | + |
|
| 50 | + $fquery = sql_serveur('query', $server_db); |
|
| 51 | + if ($choix_db == 'new_spip') { |
|
| 52 | + $re = ',^[a-z_][a-z_0-9-]*$,i'; |
|
| 53 | + if (preg_match($re, $sel_db)) { |
|
| 54 | + $ok = sql_create_base($sel_db, $server_db); |
|
| 55 | + if (!$ok) { |
|
| 56 | + $re = "Impossible de creer la base $re"; |
|
| 57 | + spip_log($re); |
|
| 58 | + return '<p>' . _T('avis_connexion_erreur_creer_base') . "</p><!--\n$re\n-->"; |
|
| 59 | + } |
|
| 60 | + } else { |
|
| 61 | + $re = "Le nom de la base doit correspondre a $re"; |
|
| 62 | + spip_log($re); |
|
| 63 | + |
|
| 64 | + return '<p>' . _T('avis_connexion_erreur_nom_base') . "</p><!--\n$re\n-->"; |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // on rejoue la connexion apres avoir teste si il faut lui indiquer |
|
| 69 | + // un sql_mode |
|
| 70 | + install_mode_appel($server_db, false); |
|
| 71 | + $GLOBALS['connexions'][$server_db] |
|
| 72 | + = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db); |
|
| 73 | + |
|
| 74 | + $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 75 | + = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 76 | + |
|
| 77 | + // Completer le tableau decrivant la connexion |
|
| 78 | + |
|
| 79 | + $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
|
| 80 | + $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
|
| 81 | + |
|
| 82 | + $old = sql_showbase($table_prefix . '_meta', $server_db); |
|
| 83 | + if ($old) { |
|
| 84 | + $old = sql_fetch($old, $server_db); |
|
| 85 | + } |
|
| 86 | + if (!$old) { |
|
| 87 | + // Si possible, demander au serveur d'envoyer les textes |
|
| 88 | + // dans le codage std de SPIP, |
|
| 89 | + $charset = sql_get_charset(_DEFAULT_CHARSET, $server_db); |
|
| 90 | + |
|
| 91 | + if ($charset) { |
|
| 92 | + sql_set_charset($charset['charset'], $server_db); |
|
| 93 | + $GLOBALS['meta']['charset_sql_base'] = |
|
| 94 | + $charset['charset']; |
|
| 95 | + $GLOBALS['meta']['charset_collation_sql_base'] = |
|
| 96 | + $charset['collation']; |
|
| 97 | + $GLOBALS['meta']['charset_sql_connexion'] = |
|
| 98 | + $charset['charset']; |
|
| 99 | + $charsetbase = $charset['charset']; |
|
| 100 | + } else { |
|
| 101 | + spip_log(_DEFAULT_CHARSET . ' inconnu du serveur SQL'); |
|
| 102 | + $charsetbase = 'standard'; |
|
| 103 | + } |
|
| 104 | + spip_log("Creation des tables. Codage $charsetbase"); |
|
| 105 | + creer_base($server_db); // AT LAST |
|
| 106 | + // memoriser avec quel charset on l'a creee |
|
| 107 | + |
|
| 108 | + if ($charset) { |
|
| 109 | + $t = array( |
|
| 110 | + 'nom' => 'charset_sql_base', |
|
| 111 | + 'valeur' => $charset['charset'], |
|
| 112 | + 'impt' => 'non' |
|
| 113 | + ); |
|
| 114 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 115 | + $t['nom'] = 'charset_collation_sql_base'; |
|
| 116 | + $t['valeur'] = $charset['collation']; |
|
| 117 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 118 | + $t['nom'] = 'charset_sql_connexion'; |
|
| 119 | + $t['valeur'] = $charset['charset']; |
|
| 120 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 121 | + } |
|
| 122 | + $t = array( |
|
| 123 | + 'nom' => 'version_installee', |
|
| 124 | + 'valeur' => $GLOBALS['spip_version_base'], |
|
| 125 | + 'impt' => 'non' |
|
| 126 | + ); |
|
| 127 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 128 | + $t['nom'] = 'nouvelle_install'; |
|
| 129 | + $t['valeur'] = 1; |
|
| 130 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 131 | + // positionner la langue par defaut du site si un cookie de lang a ete mis |
|
| 132 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 133 | + @sql_insertq( |
|
| 134 | + 'spip_meta', |
|
| 135 | + array('nom' => 'langue_site', 'valeur' => $_COOKIE['spip_lang_ecrire']), |
|
| 136 | + '', |
|
| 137 | + $server_db |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | + } else { |
|
| 141 | + // pour recreer les tables disparues au besoin |
|
| 142 | + spip_log('Table des Meta deja la. Verification des autres.'); |
|
| 143 | + creer_base($server_db); |
|
| 144 | + $fupdateq = sql_serveur('updateq', $server_db); |
|
| 145 | + |
|
| 146 | + $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='version_installee'", $server_db); |
|
| 147 | + |
|
| 148 | + if ($r) { |
|
| 149 | + $r = sql_fetch($r, $server_db); |
|
| 150 | + } |
|
| 151 | + $version_installee = !$r ? 0 : (double)$r['valeur']; |
|
| 152 | + if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) { |
|
| 153 | + $fupdateq( |
|
| 154 | + 'spip_meta', |
|
| 155 | + array('valeur' => $GLOBALS['spip_version_base'], 'impt' => 'non'), |
|
| 156 | + "nom='version_installee'", |
|
| 157 | + '', |
|
| 158 | + $server_db |
|
| 159 | + ); |
|
| 160 | + spip_log('nouvelle version installee: ' . $GLOBALS['spip_version_base']); |
|
| 161 | + } |
|
| 162 | + // eliminer la derniere operation d'admin mal terminee |
|
| 163 | + // notamment la mise a jour |
|
| 164 | + @$fquery("DELETE FROM spip_meta WHERE nom='import_all' OR nom='admin'", $server_db); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // recuperer le charset de la connexion dans les meta |
|
| 168 | + $charset = ''; |
|
| 169 | + $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='charset_sql_connexion'", $server_db); |
|
| 170 | + if ($r) { |
|
| 171 | + $r = sql_fetch($r, $server_db); |
|
| 172 | + } |
|
| 173 | + if ($r) { |
|
| 174 | + $charset = $r['valeur']; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + $ligne_rappel = install_mode_appel($server_db); |
|
| 178 | + |
|
| 179 | + $result_ok = @$fquery('SELECT COUNT(*) FROM spip_meta', $server_db); |
|
| 180 | + if (!$result_ok) { |
|
| 181 | + return "<!--\nvielle = $old rappel= $ligne_rappel\n-->"; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + if ($chmod_db) { |
|
| 185 | + install_fichier_connexion( |
|
| 186 | + _FILE_CHMOD_TMP, |
|
| 187 | + "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', " . sprintf('0%3o', $chmod_db) . ");\n" |
|
| 188 | + ); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // si ce fichier existe a cette etape c'est qu'il provient |
|
| 192 | + // d'une installation qui ne l'a pas cree correctement. |
|
| 193 | + // Le supprimer pour que _FILE_CONNECT_TMP prime. |
|
| 194 | + |
|
| 195 | + if (_FILE_CONNECT and file_exists(_FILE_CONNECT)) { |
|
| 196 | + spip_unlink(_FILE_CONNECT); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + install_fichier_connexion( |
|
| 200 | + _FILE_CONNECT_TMP, |
|
| 201 | + $ligne_rappel |
|
| 202 | + . install_connexion( |
|
| 203 | + $adresse_db, |
|
| 204 | + $port, |
|
| 205 | + $login_db, |
|
| 206 | + $pass_db, |
|
| 207 | + $sel_db, |
|
| 208 | + $server_db, |
|
| 209 | + $table_prefix, |
|
| 210 | + '', |
|
| 211 | + $charset |
|
| 212 | + ) |
|
| 213 | + ); |
|
| 214 | + |
|
| 215 | + return ''; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -227,169 +227,169 @@ discard block |
||
| 227 | 227 | * @return string Le préfixe corrigé |
| 228 | 228 | */ |
| 229 | 229 | function preparer_prefixe_tables($prefixe) { |
| 230 | - return trim(preg_replace(',^[0-9]+,', '', preg_replace(',[^a-z0-9],', '', strtolower($prefixe)))); |
|
| 230 | + return trim(preg_replace(',^[0-9]+,', '', preg_replace(',[^a-z0-9],', '', strtolower($prefixe)))); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | // http://code.spip.net/@install_propose_ldap |
| 234 | 234 | function install_propose_ldap() { |
| 235 | - return generer_form_ecrire('install', ( |
|
| 236 | - fieldset( |
|
| 237 | - _T('info_authentification_externe'), |
|
| 238 | - array( |
|
| 239 | - 'etape' => array( |
|
| 240 | - 'label' => _T('texte_annuaire_ldap_1'), |
|
| 241 | - 'valeur' => 'ldap1', |
|
| 242 | - 'hidden' => true |
|
| 243 | - ) |
|
| 244 | - ), |
|
| 245 | - bouton_suivant(_T('bouton_acces_ldap')) |
|
| 246 | - ))); |
|
| 235 | + return generer_form_ecrire('install', ( |
|
| 236 | + fieldset( |
|
| 237 | + _T('info_authentification_externe'), |
|
| 238 | + array( |
|
| 239 | + 'etape' => array( |
|
| 240 | + 'label' => _T('texte_annuaire_ldap_1'), |
|
| 241 | + 'valeur' => 'ldap1', |
|
| 242 | + 'hidden' => true |
|
| 243 | + ) |
|
| 244 | + ), |
|
| 245 | + bouton_suivant(_T('bouton_acces_ldap')) |
|
| 246 | + ))); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | |
| 250 | 250 | // http://code.spip.net/@install_premier_auteur |
| 251 | 251 | function install_premier_auteur($email, $login, $nom, $pass, $hidden, $auteur_obligatoire) { |
| 252 | - return info_progression_etape(3, 'etape_', 'install/') . |
|
| 253 | - info_etape( |
|
| 254 | - _T('info_informations_personnelles'), |
|
| 255 | - '<b>' . _T('texte_informations_personnelles_1') . '</b>' . |
|
| 256 | - aider('install5', true) . |
|
| 257 | - '<p>' . |
|
| 258 | - ($auteur_obligatoire ? |
|
| 259 | - '' |
|
| 260 | - : |
|
| 261 | - _T('texte_informations_personnelles_2') . ' ' . _T('info_laisser_champs_vides') |
|
| 262 | - ) |
|
| 263 | - ) |
|
| 264 | - . generer_form_ecrire('install', ( |
|
| 265 | - "\n<input type='hidden' name='etape' value='3b' />" |
|
| 266 | - . $hidden |
|
| 267 | - . fieldset( |
|
| 268 | - _T('info_identification_publique'), |
|
| 269 | - array( |
|
| 270 | - 'nom' => array( |
|
| 271 | - 'label' => '<b>' . _T('entree_signature') . "</b><br />\n" . _T('entree_nom_pseudo_1') . "\n", |
|
| 272 | - 'valeur' => $nom, |
|
| 273 | - 'required' => $auteur_obligatoire, |
|
| 274 | - ), |
|
| 275 | - 'email' => array( |
|
| 276 | - 'label' => '<b>' . _T('entree_adresse_email') . "</b>\n", |
|
| 277 | - 'valeur' => $email, |
|
| 278 | - ) |
|
| 279 | - ) |
|
| 280 | - ) |
|
| 281 | - |
|
| 282 | - . fieldset( |
|
| 283 | - _T('entree_identifiants_connexion'), |
|
| 284 | - array( |
|
| 285 | - 'login' => array( |
|
| 286 | - 'label' => '<b>' . _T('entree_login') . "</b><br />\n" . _T( |
|
| 287 | - 'info_login_trop_court_car_pluriel', |
|
| 288 | - array('nb' => _LOGIN_TROP_COURT) |
|
| 289 | - ) . "\n", |
|
| 290 | - 'valeur' => $login, |
|
| 291 | - 'required' => $auteur_obligatoire, |
|
| 292 | - ), |
|
| 293 | - 'pass' => array( |
|
| 294 | - 'label' => '<b>' . _T('entree_mot_passe') . "</b><br />\n" . _T( |
|
| 295 | - 'info_passe_trop_court_car_pluriel', |
|
| 296 | - array('nb' => _PASS_LONGUEUR_MINI) |
|
| 297 | - ) . "\n", |
|
| 298 | - 'valeur' => $pass, |
|
| 299 | - 'required' => $auteur_obligatoire, |
|
| 300 | - ), |
|
| 301 | - 'pass_verif' => array( |
|
| 302 | - 'label' => '<b>' . _T('info_confirmer_passe') . "</b><br />\n", |
|
| 303 | - 'valeur' => $pass, |
|
| 304 | - 'required' => $auteur_obligatoire, |
|
| 305 | - ) |
|
| 306 | - ) |
|
| 307 | - ) |
|
| 308 | - . bouton_suivant())); |
|
| 252 | + return info_progression_etape(3, 'etape_', 'install/') . |
|
| 253 | + info_etape( |
|
| 254 | + _T('info_informations_personnelles'), |
|
| 255 | + '<b>' . _T('texte_informations_personnelles_1') . '</b>' . |
|
| 256 | + aider('install5', true) . |
|
| 257 | + '<p>' . |
|
| 258 | + ($auteur_obligatoire ? |
|
| 259 | + '' |
|
| 260 | + : |
|
| 261 | + _T('texte_informations_personnelles_2') . ' ' . _T('info_laisser_champs_vides') |
|
| 262 | + ) |
|
| 263 | + ) |
|
| 264 | + . generer_form_ecrire('install', ( |
|
| 265 | + "\n<input type='hidden' name='etape' value='3b' />" |
|
| 266 | + . $hidden |
|
| 267 | + . fieldset( |
|
| 268 | + _T('info_identification_publique'), |
|
| 269 | + array( |
|
| 270 | + 'nom' => array( |
|
| 271 | + 'label' => '<b>' . _T('entree_signature') . "</b><br />\n" . _T('entree_nom_pseudo_1') . "\n", |
|
| 272 | + 'valeur' => $nom, |
|
| 273 | + 'required' => $auteur_obligatoire, |
|
| 274 | + ), |
|
| 275 | + 'email' => array( |
|
| 276 | + 'label' => '<b>' . _T('entree_adresse_email') . "</b>\n", |
|
| 277 | + 'valeur' => $email, |
|
| 278 | + ) |
|
| 279 | + ) |
|
| 280 | + ) |
|
| 281 | + |
|
| 282 | + . fieldset( |
|
| 283 | + _T('entree_identifiants_connexion'), |
|
| 284 | + array( |
|
| 285 | + 'login' => array( |
|
| 286 | + 'label' => '<b>' . _T('entree_login') . "</b><br />\n" . _T( |
|
| 287 | + 'info_login_trop_court_car_pluriel', |
|
| 288 | + array('nb' => _LOGIN_TROP_COURT) |
|
| 289 | + ) . "\n", |
|
| 290 | + 'valeur' => $login, |
|
| 291 | + 'required' => $auteur_obligatoire, |
|
| 292 | + ), |
|
| 293 | + 'pass' => array( |
|
| 294 | + 'label' => '<b>' . _T('entree_mot_passe') . "</b><br />\n" . _T( |
|
| 295 | + 'info_passe_trop_court_car_pluriel', |
|
| 296 | + array('nb' => _PASS_LONGUEUR_MINI) |
|
| 297 | + ) . "\n", |
|
| 298 | + 'valeur' => $pass, |
|
| 299 | + 'required' => $auteur_obligatoire, |
|
| 300 | + ), |
|
| 301 | + 'pass_verif' => array( |
|
| 302 | + 'label' => '<b>' . _T('info_confirmer_passe') . "</b><br />\n", |
|
| 303 | + 'valeur' => $pass, |
|
| 304 | + 'required' => $auteur_obligatoire, |
|
| 305 | + ) |
|
| 306 | + ) |
|
| 307 | + ) |
|
| 308 | + . bouton_suivant())); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | // http://code.spip.net/@install_etape_3_dist |
| 312 | 312 | function install_etape_3_dist() { |
| 313 | - $ldap_present = _request('ldap_present'); |
|
| 314 | - |
|
| 315 | - if (!$ldap_present) { |
|
| 316 | - $adresse_db = defined('_INSTALL_HOST_DB') |
|
| 317 | - ? _INSTALL_HOST_DB |
|
| 318 | - : _request('adresse_db'); |
|
| 319 | - |
|
| 320 | - $login_db = defined('_INSTALL_USER_DB') |
|
| 321 | - ? _INSTALL_USER_DB |
|
| 322 | - : _request('login_db'); |
|
| 323 | - |
|
| 324 | - $pass_db = defined('_INSTALL_PASS_DB') |
|
| 325 | - ? _INSTALL_PASS_DB |
|
| 326 | - : _request('pass_db'); |
|
| 327 | - |
|
| 328 | - $server_db = defined('_INSTALL_SERVER_DB') |
|
| 329 | - ? _INSTALL_SERVER_DB |
|
| 330 | - : _request('server_db'); |
|
| 331 | - |
|
| 332 | - $chmod_db = defined('_SPIP_CHMOD') |
|
| 333 | - ? _SPIP_CHMOD |
|
| 334 | - : _request('chmod'); |
|
| 335 | - |
|
| 336 | - $choix_db = defined('_INSTALL_NAME_DB') |
|
| 337 | - ? _INSTALL_NAME_DB |
|
| 338 | - : _request('choix_db'); |
|
| 339 | - |
|
| 340 | - $sel_db = ($choix_db == 'new_spip') |
|
| 341 | - ? _request('table_new') : $choix_db; |
|
| 342 | - |
|
| 343 | - $res = install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db); |
|
| 344 | - |
|
| 345 | - if ($res) { |
|
| 346 | - $res = info_progression_etape(2, 'etape_', 'install/', true) |
|
| 347 | - . "<div class='error'><h3>" . _T('avis_operation_echec') . '</h3>' |
|
| 348 | - . $res |
|
| 349 | - . '<p>' . _T('texte_operation_echec') . '</p>' |
|
| 350 | - . '</div>'; |
|
| 351 | - } |
|
| 352 | - } else { |
|
| 353 | - $res = ''; |
|
| 354 | - list($adresse_db, $login_db, $pass_db, $sel_db, $server_db) = analyse_fichier_connection(_FILE_CONNECT_TMP); |
|
| 355 | - $GLOBALS['connexions'][$server_db] = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - if (!$res) { |
|
| 359 | - if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 360 | - include(_FILE_CONNECT_TMP); |
|
| 361 | - } else { |
|
| 362 | - redirige_url_ecrire('install'); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - if (file_exists(_FILE_CHMOD_TMP)) { |
|
| 366 | - include(_FILE_CHMOD_TMP); |
|
| 367 | - } else { |
|
| 368 | - redirige_url_ecrire('install'); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - $hidden = predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) |
|
| 372 | - . (defined('_INSTALL_NAME_DB') ? '' |
|
| 373 | - : "\n<input type='hidden' name='sel_db' value='$sel_db' />"); |
|
| 374 | - |
|
| 375 | - $auteur_obligatoire = ($ldap_present ? 0 : !sql_countsel('spip_auteurs', '', '', '', $server_db)); |
|
| 376 | - |
|
| 377 | - $res = "<div class='success'><b>" |
|
| 378 | - . _T('info_base_installee') |
|
| 379 | - . '</b></div>' |
|
| 380 | - . install_premier_auteur( |
|
| 381 | - _request('email'), |
|
| 382 | - _request('login'), |
|
| 383 | - _request('nom'), |
|
| 384 | - _request('pass'), |
|
| 385 | - $hidden, |
|
| 386 | - $auteur_obligatoire |
|
| 387 | - ) |
|
| 388 | - . (($ldap_present or !function_exists('ldap_connect')) |
|
| 389 | - ? '' : install_propose_ldap()); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - echo install_debut_html(); |
|
| 393 | - echo $res; |
|
| 394 | - echo install_fin_html(); |
|
| 313 | + $ldap_present = _request('ldap_present'); |
|
| 314 | + |
|
| 315 | + if (!$ldap_present) { |
|
| 316 | + $adresse_db = defined('_INSTALL_HOST_DB') |
|
| 317 | + ? _INSTALL_HOST_DB |
|
| 318 | + : _request('adresse_db'); |
|
| 319 | + |
|
| 320 | + $login_db = defined('_INSTALL_USER_DB') |
|
| 321 | + ? _INSTALL_USER_DB |
|
| 322 | + : _request('login_db'); |
|
| 323 | + |
|
| 324 | + $pass_db = defined('_INSTALL_PASS_DB') |
|
| 325 | + ? _INSTALL_PASS_DB |
|
| 326 | + : _request('pass_db'); |
|
| 327 | + |
|
| 328 | + $server_db = defined('_INSTALL_SERVER_DB') |
|
| 329 | + ? _INSTALL_SERVER_DB |
|
| 330 | + : _request('server_db'); |
|
| 331 | + |
|
| 332 | + $chmod_db = defined('_SPIP_CHMOD') |
|
| 333 | + ? _SPIP_CHMOD |
|
| 334 | + : _request('chmod'); |
|
| 335 | + |
|
| 336 | + $choix_db = defined('_INSTALL_NAME_DB') |
|
| 337 | + ? _INSTALL_NAME_DB |
|
| 338 | + : _request('choix_db'); |
|
| 339 | + |
|
| 340 | + $sel_db = ($choix_db == 'new_spip') |
|
| 341 | + ? _request('table_new') : $choix_db; |
|
| 342 | + |
|
| 343 | + $res = install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db); |
|
| 344 | + |
|
| 345 | + if ($res) { |
|
| 346 | + $res = info_progression_etape(2, 'etape_', 'install/', true) |
|
| 347 | + . "<div class='error'><h3>" . _T('avis_operation_echec') . '</h3>' |
|
| 348 | + . $res |
|
| 349 | + . '<p>' . _T('texte_operation_echec') . '</p>' |
|
| 350 | + . '</div>'; |
|
| 351 | + } |
|
| 352 | + } else { |
|
| 353 | + $res = ''; |
|
| 354 | + list($adresse_db, $login_db, $pass_db, $sel_db, $server_db) = analyse_fichier_connection(_FILE_CONNECT_TMP); |
|
| 355 | + $GLOBALS['connexions'][$server_db] = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + if (!$res) { |
|
| 359 | + if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 360 | + include(_FILE_CONNECT_TMP); |
|
| 361 | + } else { |
|
| 362 | + redirige_url_ecrire('install'); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + if (file_exists(_FILE_CHMOD_TMP)) { |
|
| 366 | + include(_FILE_CHMOD_TMP); |
|
| 367 | + } else { |
|
| 368 | + redirige_url_ecrire('install'); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + $hidden = predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) |
|
| 372 | + . (defined('_INSTALL_NAME_DB') ? '' |
|
| 373 | + : "\n<input type='hidden' name='sel_db' value='$sel_db' />"); |
|
| 374 | + |
|
| 375 | + $auteur_obligatoire = ($ldap_present ? 0 : !sql_countsel('spip_auteurs', '', '', '', $server_db)); |
|
| 376 | + |
|
| 377 | + $res = "<div class='success'><b>" |
|
| 378 | + . _T('info_base_installee') |
|
| 379 | + . '</b></div>' |
|
| 380 | + . install_premier_auteur( |
|
| 381 | + _request('email'), |
|
| 382 | + _request('login'), |
|
| 383 | + _request('nom'), |
|
| 384 | + _request('pass'), |
|
| 385 | + $hidden, |
|
| 386 | + $auteur_obligatoire |
|
| 387 | + ) |
|
| 388 | + . (($ldap_present or !function_exists('ldap_connect')) |
|
| 389 | + ? '' : install_propose_ldap()); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + echo install_debut_html(); |
|
| 393 | + echo $res; |
|
| 394 | + echo install_fin_html(); |
|
| 395 | 395 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | /** |
| 134 | 134 | * Déclarer les critères exceptions |
| 135 | 135 | * |
| 136 | - * @return array |
|
| 136 | + * @return string[] |
|
| 137 | 137 | */ |
| 138 | 138 | public function exception_des_criteres() { |
| 139 | 139 | return array('tableau'); |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | * pour la syntaxe cf la fonction spip preg_files |
| 788 | 788 | * |
| 789 | 789 | * @param string $dir |
| 790 | - * @param string $regexp |
|
| 790 | + * @param integer $regexp |
|
| 791 | 791 | * @param int $limit |
| 792 | 792 | * @return array|bool |
| 793 | 793 | */ |
@@ -826,7 +826,7 @@ discard block |
||
| 826 | 826 | /** |
| 827 | 827 | * Object -> tableau |
| 828 | 828 | * |
| 829 | - * @param Object $object |
|
| 829 | + * @param SimpleXMLIterator $object |
|
| 830 | 830 | * @return array|bool |
| 831 | 831 | */ |
| 832 | 832 | function XMLObjectToArray($object) { |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | // Si a ce stade on n'a pas de table, il y a un bug |
| 232 | 232 | if (!is_array($this->tableau)) { |
| 233 | 233 | $this->err = true; |
| 234 | - spip_log("erreur datasource " . var_export($command, true)); |
|
| 234 | + spip_log("erreur datasource ".var_export($command, true)); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | // {datapath query.results} |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | if (isset($this->command['sourcemode']) |
| 272 | 272 | and !in_array($this->command['sourcemode'], array('table', 'array', 'tableau')) |
| 273 | 273 | ) { |
| 274 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 274 | + charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | # le premier argument peut etre un array, une URL etc. |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | # avons-nous un cache dispo ? |
| 281 | 281 | $cle = null; |
| 282 | 282 | if (is_string($src)) { |
| 283 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 283 | + $cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'], true)); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | $cache = $this->cache_get($cle); |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | } |
| 348 | 348 | } |
| 349 | 349 | if (!$this->err |
| 350 | - and $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 350 | + and $g = charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true) |
|
| 351 | 351 | ) { |
| 352 | 352 | $args = $this->command['source']; |
| 353 | 353 | $args[0] = $u; |
@@ -482,13 +482,13 @@ discard block |
||
| 482 | 482 | $tv = '%s'; |
| 483 | 483 | } # {par valeur/xx/yy} ?? |
| 484 | 484 | else { |
| 485 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 485 | + $tv = 'table_valeur(%s, '.var_export($r[1], true).')'; |
|
| 486 | 486 | } |
| 487 | 487 | $sortfunc .= ' |
| 488 | - $a = ' . sprintf($tv, '$aa') . '; |
|
| 489 | - $b = ' . sprintf($tv, '$bb') . '; |
|
| 488 | + $a = ' . sprintf($tv, '$aa').'; |
|
| 489 | + $b = ' . sprintf($tv, '$bb').'; |
|
| 490 | 490 | if ($a <> $b) |
| 491 | - return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
|
| 491 | + return ($a ' . (!empty($r[2]) ? '>' : '<').' $b) ? -1 : 1;'; |
|
| 492 | 492 | } |
| 493 | 493 | } |
| 494 | 494 | } |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | */ |
| 642 | 642 | function inc_yql_to_array_dist($u) { |
| 643 | 643 | define('_YQL_ENDPOINT', 'https://query.yahooapis.com/v1/public/yql?&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q='); |
| 644 | - $v = recuperer_url($url = _YQL_ENDPOINT . urlencode($u) . '&format=json'); |
|
| 644 | + $v = recuperer_url($url = _YQL_ENDPOINT.urlencode($u).'&format=json'); |
|
| 645 | 645 | if (!$v['page'] |
| 646 | 646 | or !$w = json_decode($v['page'], true) |
| 647 | 647 | ) { |
@@ -663,7 +663,7 @@ discard block |
||
| 663 | 663 | function inc_sql_to_array_dist($u) { |
| 664 | 664 | # sortir le connecteur de $u |
| 665 | 665 | preg_match(',^(?:(\w+):)?(.*)$,S', $u, $v); |
| 666 | - $serveur = (string)$v[1]; |
|
| 666 | + $serveur = (string) $v[1]; |
|
| 667 | 667 | $req = trim($v[2]); |
| 668 | 668 | if ($s = sql_query($req, $serveur)) { |
| 669 | 669 | $r = array(); |
@@ -687,7 +687,7 @@ discard block |
||
| 687 | 687 | if (is_array($json = json_decode($u)) |
| 688 | 688 | or is_object($json) |
| 689 | 689 | ) { |
| 690 | - return (array)$json; |
|
| 690 | + return (array) $json; |
|
| 691 | 691 | } |
| 692 | 692 | } |
| 693 | 693 | |
@@ -706,13 +706,13 @@ discard block |
||
| 706 | 706 | $i = 1; |
| 707 | 707 | foreach ($entete as $k => $v) { |
| 708 | 708 | if (trim($v) == "") { |
| 709 | - $v = "col" . $i; |
|
| 709 | + $v = "col".$i; |
|
| 710 | 710 | } // reperer des eventuelles cases vides |
| 711 | 711 | if (is_numeric($v) and $v < 0) { |
| 712 | - $v = "__" . $v; |
|
| 712 | + $v = "__".$v; |
|
| 713 | 713 | } // ne pas risquer d'ecraser une cle numerique |
| 714 | 714 | if (is_numeric($v)) { |
| 715 | - $v = "_" . $v; |
|
| 715 | + $v = "_".$v; |
|
| 716 | 716 | } // ne pas risquer d'ecraser une cle numerique |
| 717 | 717 | $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
| 718 | 718 | foreach ($csv as &$item) { |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | * @return array|bool |
| 797 | 797 | */ |
| 798 | 798 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 799 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 799 | + return (array) preg_files($dir, $regexp, $limit); |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | /** |
@@ -811,13 +811,13 @@ discard block |
||
| 811 | 811 | $glob = charger_fonction('glob_to_array', 'inc'); |
| 812 | 812 | $a = $glob($u); |
| 813 | 813 | foreach ($a as &$v) { |
| 814 | - $b = (array)@stat($v); |
|
| 814 | + $b = (array) @stat($v); |
|
| 815 | 815 | foreach ($b as $k => $ignore) { |
| 816 | 816 | if (is_numeric($k)) { |
| 817 | 817 | unset($b[$k]); |
| 818 | 818 | } |
| 819 | 819 | } |
| 820 | - $b['file'] = preg_replace('`/$`','',$v) ; |
|
| 820 | + $b['file'] = preg_replace('`/$`', '', $v); |
|
| 821 | 821 | $v = array_merge( |
| 822 | 822 | pathinfo($v), |
| 823 | 823 | $b |
@@ -837,7 +837,7 @@ discard block |
||
| 837 | 837 | $xml_array = array(); |
| 838 | 838 | for ($object->rewind(); $object->valid(); $object->next()) { |
| 839 | 839 | if (array_key_exists($key = $object->key(), $xml_array)) { |
| 840 | - $key .= '-' . uniqid(); |
|
| 840 | + $key .= '-'.uniqid(); |
|
| 841 | 841 | } |
| 842 | 842 | $vars = get_object_vars($object->current()); |
| 843 | 843 | if (isset($vars['@attributes'])) { |
@@ -17,11 +17,11 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_DATA_SOURCE_MAX_SIZE')) { |
| 24 | - define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576); |
|
| 24 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
@@ -42,17 +42,17 @@ discard block |
||
| 42 | 42 | * Description de la boucle complétée des champs |
| 43 | 43 | */ |
| 44 | 44 | function iterateur_DATA_dist($b) { |
| 45 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | - $b->show = array( |
|
| 47 | - 'field' => array( |
|
| 48 | - 'cle' => 'STRING', |
|
| 49 | - 'valeur' => 'STRING', |
|
| 50 | - '*' => 'ALL' // Champ joker * |
|
| 51 | - ) |
|
| 52 | - ); |
|
| 53 | - $b->select[] = '.valeur'; |
|
| 54 | - |
|
| 55 | - return $b; |
|
| 45 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | + $b->show = array( |
|
| 47 | + 'field' => array( |
|
| 48 | + 'cle' => 'STRING', |
|
| 49 | + 'valeur' => 'STRING', |
|
| 50 | + '*' => 'ALL' // Champ joker * |
|
| 51 | + ) |
|
| 52 | + ); |
|
| 53 | + $b->select[] = '.valeur'; |
|
| 54 | + |
|
| 55 | + return $b; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | |
@@ -62,520 +62,520 @@ discard block |
||
| 62 | 62 | * Pour itérer sur des données quelconques (transformables en tableau) |
| 63 | 63 | */ |
| 64 | 64 | class IterateurDATA implements Iterator { |
| 65 | - /** |
|
| 66 | - * tableau de donnees |
|
| 67 | - * |
|
| 68 | - * @var array |
|
| 69 | - */ |
|
| 70 | - protected $tableau = array(); |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Conditions de filtrage |
|
| 74 | - * ie criteres de selection |
|
| 75 | - * |
|
| 76 | - * @var array |
|
| 77 | - */ |
|
| 78 | - protected $filtre = array(); |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Cle courante |
|
| 83 | - * |
|
| 84 | - * @var null |
|
| 85 | - */ |
|
| 86 | - protected $cle = null; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Valeur courante |
|
| 90 | - * |
|
| 91 | - * @var null |
|
| 92 | - */ |
|
| 93 | - protected $valeur = null; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Erreur presente ? |
|
| 97 | - * |
|
| 98 | - * @var bool |
|
| 99 | - **/ |
|
| 100 | - public $err = false; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Calcul du total des elements |
|
| 104 | - * |
|
| 105 | - * @var int|null |
|
| 106 | - **/ |
|
| 107 | - public $total = null; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Constructeur |
|
| 111 | - * |
|
| 112 | - * @param $command |
|
| 113 | - * @param array $info |
|
| 114 | - */ |
|
| 115 | - public function __construct($command, $info = array()) { |
|
| 116 | - $this->type = 'DATA'; |
|
| 117 | - $this->command = $command; |
|
| 118 | - $this->info = $info; |
|
| 119 | - |
|
| 120 | - $this->select($command); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Revenir au depart |
|
| 125 | - * |
|
| 126 | - * @return void |
|
| 127 | - */ |
|
| 128 | - public function rewind() { |
|
| 129 | - reset($this->tableau); |
|
| 130 | - $this->cle = key($this->tableau); |
|
| 131 | - $this->valeur = current($this->tableau); |
|
| 132 | - next($this->tableau); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Déclarer les critères exceptions |
|
| 137 | - * |
|
| 138 | - * @return array |
|
| 139 | - */ |
|
| 140 | - public function exception_des_criteres() { |
|
| 141 | - return array('tableau'); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Récupérer depuis le cache si possible |
|
| 146 | - * |
|
| 147 | - * @param string $cle |
|
| 148 | - * @return mixed |
|
| 149 | - */ |
|
| 150 | - protected function cache_get($cle) { |
|
| 151 | - if (!$cle) { |
|
| 152 | - return; |
|
| 153 | - } |
|
| 154 | - # utiliser memoization si dispo |
|
| 155 | - if (!function_exists('cache_get')) { |
|
| 156 | - return; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - return cache_get($cle); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Stocker en cache si possible |
|
| 164 | - * |
|
| 165 | - * @param string $cle |
|
| 166 | - * @param int $ttl |
|
| 167 | - * @param null|mixed $valeur |
|
| 168 | - * @return bool |
|
| 169 | - */ |
|
| 170 | - protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 171 | - if (!$cle) { |
|
| 172 | - return; |
|
| 173 | - } |
|
| 174 | - if (is_null($valeur)) { |
|
| 175 | - $valeur = $this->tableau; |
|
| 176 | - } |
|
| 177 | - # utiliser memoization si dispo |
|
| 178 | - if (!function_exists('cache_set')) { |
|
| 179 | - return; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - return cache_set($cle, |
|
| 183 | - array( |
|
| 184 | - 'data' => $valeur, |
|
| 185 | - 'time' => time(), |
|
| 186 | - 'ttl' => $ttl |
|
| 187 | - ), |
|
| 188 | - 3600 + $ttl); |
|
| 189 | - # conserver le cache 1h de plus que la validite demandee, |
|
| 190 | - # pour le cas ou le serveur distant ne reponde plus |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Aller chercher les données de la boucle DATA |
|
| 195 | - * |
|
| 196 | - * @throws Exception |
|
| 197 | - * @param array $command |
|
| 198 | - * @return void |
|
| 199 | - */ |
|
| 200 | - protected function select($command) { |
|
| 201 | - |
|
| 202 | - // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 203 | - // le type se retrouve dans la commande 'from' |
|
| 204 | - // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 205 | - if (isset($this->command['from'][0])) { |
|
| 206 | - if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 207 | - array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 208 | - } |
|
| 209 | - $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // cherchons differents moyens de creer le tableau de donnees |
|
| 213 | - // les commandes connues pour l'iterateur DATA |
|
| 214 | - // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 215 | - |
|
| 216 | - // {source format, [URL], [arg2]...} |
|
| 217 | - if (isset($this->command['source']) |
|
| 218 | - and isset($this->command['sourcemode']) |
|
| 219 | - ) { |
|
| 220 | - $this->select_source(); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - // Critere {liste X1, X2, X3} |
|
| 224 | - if (isset($this->command['liste'])) { |
|
| 225 | - $this->select_liste(); |
|
| 226 | - } |
|
| 227 | - if (isset($this->command['enum'])) { |
|
| 228 | - $this->select_enum(); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // Si a ce stade on n'a pas de table, il y a un bug |
|
| 232 | - if (!is_array($this->tableau)) { |
|
| 233 | - $this->err = true; |
|
| 234 | - spip_log("erreur datasource " . var_export($command, true)); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - // {datapath query.results} |
|
| 238 | - // extraire le chemin "query.results" du tableau de donnees |
|
| 239 | - if (!$this->err |
|
| 240 | - and isset($this->command['datapath']) |
|
| 241 | - and is_array($this->command['datapath']) |
|
| 242 | - ) { |
|
| 243 | - $this->select_datapath(); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // tri {par x} |
|
| 247 | - if ($this->command['orderby']) { |
|
| 248 | - $this->select_orderby(); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - // grouper les resultats {fusion /x/y/z} ; |
|
| 252 | - if ($this->command['groupby']) { |
|
| 253 | - $this->select_groupby(); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - $this->rewind(); |
|
| 257 | - #var_dump($this->tableau); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Aller chercher les donnees de la boucle DATA |
|
| 263 | - * depuis une source |
|
| 264 | - * {source format, [URL], [arg2]...} |
|
| 265 | - */ |
|
| 266 | - protected function select_source() { |
|
| 267 | - # un peu crado : avant de charger le cache il faut charger |
|
| 268 | - # les class indispensables, sinon PHP ne saura pas gerer |
|
| 269 | - # l'objet en cache ; cf plugins/icalendar |
|
| 270 | - # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 271 | - if (isset($this->command['sourcemode']) |
|
| 272 | - and !in_array($this->command['sourcemode'], array('table', 'array', 'tableau')) |
|
| 273 | - ) { |
|
| 274 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - # le premier argument peut etre un array, une URL etc. |
|
| 278 | - $src = $this->command['source'][0]; |
|
| 279 | - |
|
| 280 | - # avons-nous un cache dispo ? |
|
| 281 | - $cle = null; |
|
| 282 | - if (is_string($src)) { |
|
| 283 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - $cache = $this->cache_get($cle); |
|
| 287 | - if (isset($this->command['datacache'])) { |
|
| 288 | - $ttl = intval($this->command['datacache']); |
|
| 289 | - } |
|
| 290 | - if ($cache |
|
| 291 | - and ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl']) |
|
| 292 | - > time()) |
|
| 293 | - and !(_request('var_mode') === 'recalcul' |
|
| 294 | - and include_spip('inc/autoriser') |
|
| 295 | - and autoriser('recalcul') |
|
| 296 | - ) |
|
| 297 | - ) { |
|
| 298 | - $this->tableau = $cache['data']; |
|
| 299 | - } else { |
|
| 300 | - try { |
|
| 301 | - # dommage que ca ne soit pas une option de yql_to_array... |
|
| 302 | - if ($this->command['sourcemode'] == 'yql') { |
|
| 303 | - if (!isset($ttl)) { |
|
| 304 | - $ttl = 3600; |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - if (isset($this->command['sourcemode']) |
|
| 309 | - and in_array($this->command['sourcemode'], |
|
| 310 | - array('table', 'array', 'tableau')) |
|
| 311 | - ) { |
|
| 312 | - if (is_array($a = $src) |
|
| 313 | - or (is_string($a) |
|
| 314 | - and $a = str_replace('"', '"', $a) # fragile! |
|
| 315 | - and is_array($a = @unserialize($a))) |
|
| 316 | - ) { |
|
| 317 | - $this->tableau = $a; |
|
| 318 | - } |
|
| 319 | - } else { |
|
| 320 | - if (tester_url_absolue($src)) { |
|
| 321 | - include_spip('inc/distant'); |
|
| 322 | - $u = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE); |
|
| 323 | - if (!$u) { |
|
| 324 | - throw new Exception("404"); |
|
| 325 | - } |
|
| 326 | - if (!isset($ttl)) { |
|
| 327 | - $ttl = 24 * 3600; |
|
| 328 | - } |
|
| 329 | - } else { |
|
| 330 | - if (@is_dir($src)) { |
|
| 331 | - $u = $src; |
|
| 332 | - if (!isset($ttl)) { |
|
| 333 | - $ttl = 10; |
|
| 334 | - } |
|
| 335 | - } else { |
|
| 336 | - if (@is_readable($src) && @is_file($src)) { |
|
| 337 | - $u = spip_file_get_contents($src); |
|
| 338 | - if (!isset($ttl)) { |
|
| 339 | - $ttl = 10; |
|
| 340 | - } |
|
| 341 | - } else { |
|
| 342 | - $u = $src; |
|
| 343 | - if (!isset($ttl)) { |
|
| 344 | - $ttl = 10; |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - if (!$this->err |
|
| 350 | - and $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 351 | - ) { |
|
| 352 | - $args = $this->command['source']; |
|
| 353 | - $args[0] = $u; |
|
| 354 | - if (is_array($a = call_user_func_array($g, $args))) { |
|
| 355 | - $this->tableau = $a; |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - if (!is_array($this->tableau)) { |
|
| 361 | - $this->err = true; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 365 | - $this->cache_set($cle, $ttl); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - } catch (Exception $e) { |
|
| 369 | - $e = $e->getMessage(); |
|
| 370 | - $err = sprintf("[%s, %s] $e", |
|
| 371 | - $src, |
|
| 372 | - $this->command['sourcemode']); |
|
| 373 | - erreur_squelette(array($err, array())); |
|
| 374 | - $this->err = true; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - # en cas d'erreur, utiliser le cache si encore dispo |
|
| 379 | - if ($this->err |
|
| 380 | - and $cache |
|
| 381 | - ) { |
|
| 382 | - $this->tableau = $cache['data']; |
|
| 383 | - $this->err = false; |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Retourne un tableau donne depuis un critère liste |
|
| 390 | - * |
|
| 391 | - * Critère `{liste X1, X2, X3}` |
|
| 392 | - * |
|
| 393 | - * @see critere_DATA_liste_dist() |
|
| 394 | - * |
|
| 395 | - **/ |
|
| 396 | - protected function select_liste() { |
|
| 397 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 398 | - if (!isset($this->command['liste'][1])) { |
|
| 399 | - if (!is_array($this->command['liste'][0])) { |
|
| 400 | - $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 401 | - } else { |
|
| 402 | - $this->command['liste'] = $this->command['liste'][0]; |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - $this->tableau = $this->command['liste']; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * Retourne un tableau donne depuis un critere liste |
|
| 410 | - * Critere {enum Xmin, Xmax} |
|
| 411 | - * |
|
| 412 | - **/ |
|
| 413 | - protected function select_enum() { |
|
| 414 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 415 | - if (!isset($this->command['enum'][1])) { |
|
| 416 | - if (!is_array($this->command['enum'][0])) { |
|
| 417 | - $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 418 | - } else { |
|
| 419 | - $this->command['enum'] = $this->command['enum'][0]; |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - if (count($this->command['enum']) >= 3) { |
|
| 423 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']), |
|
| 424 | - array_shift($this->command['enum'])); |
|
| 425 | - } else { |
|
| 426 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 427 | - } |
|
| 428 | - $this->tableau = $enum; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * extraire le chemin "query.results" du tableau de donnees |
|
| 434 | - * {datapath query.results} |
|
| 435 | - * |
|
| 436 | - **/ |
|
| 437 | - protected function select_datapath() { |
|
| 438 | - $base = reset($this->command['datapath']); |
|
| 439 | - if (strlen($base = ltrim(trim($base), "/"))) { |
|
| 440 | - $this->tableau = table_valeur($this->tableau, $base); |
|
| 441 | - if (!is_array($this->tableau)) { |
|
| 442 | - $this->tableau = array(); |
|
| 443 | - $this->err = true; |
|
| 444 | - spip_log("datapath '$base' absent"); |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * Ordonner les resultats |
|
| 451 | - * {par x} |
|
| 452 | - * |
|
| 453 | - **/ |
|
| 454 | - protected function select_orderby() { |
|
| 455 | - $sortfunc = ''; |
|
| 456 | - $aleas = 0; |
|
| 457 | - foreach ($this->command['orderby'] as $tri) { |
|
| 458 | - // virer le / initial pour les criteres de la forme {par /xx} |
|
| 459 | - if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 460 | - $r = array_pad($r, 3, null); |
|
| 461 | - |
|
| 462 | - // tri par cle |
|
| 463 | - if ($r[1] == 'cle') { |
|
| 464 | - if (isset($r[2]) and $r[2]) { |
|
| 465 | - krsort($this->tableau); |
|
| 466 | - } else { |
|
| 467 | - ksort($this->tableau); |
|
| 468 | - } |
|
| 469 | - } # {par hasard} |
|
| 470 | - else { |
|
| 471 | - if ($r[1] == 'hasard') { |
|
| 472 | - $k = array_keys($this->tableau); |
|
| 473 | - shuffle($k); |
|
| 474 | - $v = array(); |
|
| 475 | - foreach ($k as $cle) { |
|
| 476 | - $v[$cle] = $this->tableau[$cle]; |
|
| 477 | - } |
|
| 478 | - $this->tableau = $v; |
|
| 479 | - } else { |
|
| 480 | - # {par valeur} |
|
| 481 | - if ($r[1] == 'valeur') { |
|
| 482 | - $tv = '%s'; |
|
| 483 | - } # {par valeur/xx/yy} ?? |
|
| 484 | - else { |
|
| 485 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 486 | - } |
|
| 487 | - $sortfunc .= ' |
|
| 65 | + /** |
|
| 66 | + * tableau de donnees |
|
| 67 | + * |
|
| 68 | + * @var array |
|
| 69 | + */ |
|
| 70 | + protected $tableau = array(); |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Conditions de filtrage |
|
| 74 | + * ie criteres de selection |
|
| 75 | + * |
|
| 76 | + * @var array |
|
| 77 | + */ |
|
| 78 | + protected $filtre = array(); |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Cle courante |
|
| 83 | + * |
|
| 84 | + * @var null |
|
| 85 | + */ |
|
| 86 | + protected $cle = null; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Valeur courante |
|
| 90 | + * |
|
| 91 | + * @var null |
|
| 92 | + */ |
|
| 93 | + protected $valeur = null; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Erreur presente ? |
|
| 97 | + * |
|
| 98 | + * @var bool |
|
| 99 | + **/ |
|
| 100 | + public $err = false; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Calcul du total des elements |
|
| 104 | + * |
|
| 105 | + * @var int|null |
|
| 106 | + **/ |
|
| 107 | + public $total = null; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Constructeur |
|
| 111 | + * |
|
| 112 | + * @param $command |
|
| 113 | + * @param array $info |
|
| 114 | + */ |
|
| 115 | + public function __construct($command, $info = array()) { |
|
| 116 | + $this->type = 'DATA'; |
|
| 117 | + $this->command = $command; |
|
| 118 | + $this->info = $info; |
|
| 119 | + |
|
| 120 | + $this->select($command); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Revenir au depart |
|
| 125 | + * |
|
| 126 | + * @return void |
|
| 127 | + */ |
|
| 128 | + public function rewind() { |
|
| 129 | + reset($this->tableau); |
|
| 130 | + $this->cle = key($this->tableau); |
|
| 131 | + $this->valeur = current($this->tableau); |
|
| 132 | + next($this->tableau); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Déclarer les critères exceptions |
|
| 137 | + * |
|
| 138 | + * @return array |
|
| 139 | + */ |
|
| 140 | + public function exception_des_criteres() { |
|
| 141 | + return array('tableau'); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Récupérer depuis le cache si possible |
|
| 146 | + * |
|
| 147 | + * @param string $cle |
|
| 148 | + * @return mixed |
|
| 149 | + */ |
|
| 150 | + protected function cache_get($cle) { |
|
| 151 | + if (!$cle) { |
|
| 152 | + return; |
|
| 153 | + } |
|
| 154 | + # utiliser memoization si dispo |
|
| 155 | + if (!function_exists('cache_get')) { |
|
| 156 | + return; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + return cache_get($cle); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Stocker en cache si possible |
|
| 164 | + * |
|
| 165 | + * @param string $cle |
|
| 166 | + * @param int $ttl |
|
| 167 | + * @param null|mixed $valeur |
|
| 168 | + * @return bool |
|
| 169 | + */ |
|
| 170 | + protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 171 | + if (!$cle) { |
|
| 172 | + return; |
|
| 173 | + } |
|
| 174 | + if (is_null($valeur)) { |
|
| 175 | + $valeur = $this->tableau; |
|
| 176 | + } |
|
| 177 | + # utiliser memoization si dispo |
|
| 178 | + if (!function_exists('cache_set')) { |
|
| 179 | + return; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + return cache_set($cle, |
|
| 183 | + array( |
|
| 184 | + 'data' => $valeur, |
|
| 185 | + 'time' => time(), |
|
| 186 | + 'ttl' => $ttl |
|
| 187 | + ), |
|
| 188 | + 3600 + $ttl); |
|
| 189 | + # conserver le cache 1h de plus que la validite demandee, |
|
| 190 | + # pour le cas ou le serveur distant ne reponde plus |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Aller chercher les données de la boucle DATA |
|
| 195 | + * |
|
| 196 | + * @throws Exception |
|
| 197 | + * @param array $command |
|
| 198 | + * @return void |
|
| 199 | + */ |
|
| 200 | + protected function select($command) { |
|
| 201 | + |
|
| 202 | + // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 203 | + // le type se retrouve dans la commande 'from' |
|
| 204 | + // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 205 | + if (isset($this->command['from'][0])) { |
|
| 206 | + if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 207 | + array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 208 | + } |
|
| 209 | + $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + // cherchons differents moyens de creer le tableau de donnees |
|
| 213 | + // les commandes connues pour l'iterateur DATA |
|
| 214 | + // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 215 | + |
|
| 216 | + // {source format, [URL], [arg2]...} |
|
| 217 | + if (isset($this->command['source']) |
|
| 218 | + and isset($this->command['sourcemode']) |
|
| 219 | + ) { |
|
| 220 | + $this->select_source(); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + // Critere {liste X1, X2, X3} |
|
| 224 | + if (isset($this->command['liste'])) { |
|
| 225 | + $this->select_liste(); |
|
| 226 | + } |
|
| 227 | + if (isset($this->command['enum'])) { |
|
| 228 | + $this->select_enum(); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // Si a ce stade on n'a pas de table, il y a un bug |
|
| 232 | + if (!is_array($this->tableau)) { |
|
| 233 | + $this->err = true; |
|
| 234 | + spip_log("erreur datasource " . var_export($command, true)); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + // {datapath query.results} |
|
| 238 | + // extraire le chemin "query.results" du tableau de donnees |
|
| 239 | + if (!$this->err |
|
| 240 | + and isset($this->command['datapath']) |
|
| 241 | + and is_array($this->command['datapath']) |
|
| 242 | + ) { |
|
| 243 | + $this->select_datapath(); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // tri {par x} |
|
| 247 | + if ($this->command['orderby']) { |
|
| 248 | + $this->select_orderby(); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + // grouper les resultats {fusion /x/y/z} ; |
|
| 252 | + if ($this->command['groupby']) { |
|
| 253 | + $this->select_groupby(); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + $this->rewind(); |
|
| 257 | + #var_dump($this->tableau); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Aller chercher les donnees de la boucle DATA |
|
| 263 | + * depuis une source |
|
| 264 | + * {source format, [URL], [arg2]...} |
|
| 265 | + */ |
|
| 266 | + protected function select_source() { |
|
| 267 | + # un peu crado : avant de charger le cache il faut charger |
|
| 268 | + # les class indispensables, sinon PHP ne saura pas gerer |
|
| 269 | + # l'objet en cache ; cf plugins/icalendar |
|
| 270 | + # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 271 | + if (isset($this->command['sourcemode']) |
|
| 272 | + and !in_array($this->command['sourcemode'], array('table', 'array', 'tableau')) |
|
| 273 | + ) { |
|
| 274 | + charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + # le premier argument peut etre un array, une URL etc. |
|
| 278 | + $src = $this->command['source'][0]; |
|
| 279 | + |
|
| 280 | + # avons-nous un cache dispo ? |
|
| 281 | + $cle = null; |
|
| 282 | + if (is_string($src)) { |
|
| 283 | + $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + $cache = $this->cache_get($cle); |
|
| 287 | + if (isset($this->command['datacache'])) { |
|
| 288 | + $ttl = intval($this->command['datacache']); |
|
| 289 | + } |
|
| 290 | + if ($cache |
|
| 291 | + and ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl']) |
|
| 292 | + > time()) |
|
| 293 | + and !(_request('var_mode') === 'recalcul' |
|
| 294 | + and include_spip('inc/autoriser') |
|
| 295 | + and autoriser('recalcul') |
|
| 296 | + ) |
|
| 297 | + ) { |
|
| 298 | + $this->tableau = $cache['data']; |
|
| 299 | + } else { |
|
| 300 | + try { |
|
| 301 | + # dommage que ca ne soit pas une option de yql_to_array... |
|
| 302 | + if ($this->command['sourcemode'] == 'yql') { |
|
| 303 | + if (!isset($ttl)) { |
|
| 304 | + $ttl = 3600; |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + if (isset($this->command['sourcemode']) |
|
| 309 | + and in_array($this->command['sourcemode'], |
|
| 310 | + array('table', 'array', 'tableau')) |
|
| 311 | + ) { |
|
| 312 | + if (is_array($a = $src) |
|
| 313 | + or (is_string($a) |
|
| 314 | + and $a = str_replace('"', '"', $a) # fragile! |
|
| 315 | + and is_array($a = @unserialize($a))) |
|
| 316 | + ) { |
|
| 317 | + $this->tableau = $a; |
|
| 318 | + } |
|
| 319 | + } else { |
|
| 320 | + if (tester_url_absolue($src)) { |
|
| 321 | + include_spip('inc/distant'); |
|
| 322 | + $u = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE); |
|
| 323 | + if (!$u) { |
|
| 324 | + throw new Exception("404"); |
|
| 325 | + } |
|
| 326 | + if (!isset($ttl)) { |
|
| 327 | + $ttl = 24 * 3600; |
|
| 328 | + } |
|
| 329 | + } else { |
|
| 330 | + if (@is_dir($src)) { |
|
| 331 | + $u = $src; |
|
| 332 | + if (!isset($ttl)) { |
|
| 333 | + $ttl = 10; |
|
| 334 | + } |
|
| 335 | + } else { |
|
| 336 | + if (@is_readable($src) && @is_file($src)) { |
|
| 337 | + $u = spip_file_get_contents($src); |
|
| 338 | + if (!isset($ttl)) { |
|
| 339 | + $ttl = 10; |
|
| 340 | + } |
|
| 341 | + } else { |
|
| 342 | + $u = $src; |
|
| 343 | + if (!isset($ttl)) { |
|
| 344 | + $ttl = 10; |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + if (!$this->err |
|
| 350 | + and $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 351 | + ) { |
|
| 352 | + $args = $this->command['source']; |
|
| 353 | + $args[0] = $u; |
|
| 354 | + if (is_array($a = call_user_func_array($g, $args))) { |
|
| 355 | + $this->tableau = $a; |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + if (!is_array($this->tableau)) { |
|
| 361 | + $this->err = true; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 365 | + $this->cache_set($cle, $ttl); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + } catch (Exception $e) { |
|
| 369 | + $e = $e->getMessage(); |
|
| 370 | + $err = sprintf("[%s, %s] $e", |
|
| 371 | + $src, |
|
| 372 | + $this->command['sourcemode']); |
|
| 373 | + erreur_squelette(array($err, array())); |
|
| 374 | + $this->err = true; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + # en cas d'erreur, utiliser le cache si encore dispo |
|
| 379 | + if ($this->err |
|
| 380 | + and $cache |
|
| 381 | + ) { |
|
| 382 | + $this->tableau = $cache['data']; |
|
| 383 | + $this->err = false; |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Retourne un tableau donne depuis un critère liste |
|
| 390 | + * |
|
| 391 | + * Critère `{liste X1, X2, X3}` |
|
| 392 | + * |
|
| 393 | + * @see critere_DATA_liste_dist() |
|
| 394 | + * |
|
| 395 | + **/ |
|
| 396 | + protected function select_liste() { |
|
| 397 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 398 | + if (!isset($this->command['liste'][1])) { |
|
| 399 | + if (!is_array($this->command['liste'][0])) { |
|
| 400 | + $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 401 | + } else { |
|
| 402 | + $this->command['liste'] = $this->command['liste'][0]; |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + $this->tableau = $this->command['liste']; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * Retourne un tableau donne depuis un critere liste |
|
| 410 | + * Critere {enum Xmin, Xmax} |
|
| 411 | + * |
|
| 412 | + **/ |
|
| 413 | + protected function select_enum() { |
|
| 414 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 415 | + if (!isset($this->command['enum'][1])) { |
|
| 416 | + if (!is_array($this->command['enum'][0])) { |
|
| 417 | + $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 418 | + } else { |
|
| 419 | + $this->command['enum'] = $this->command['enum'][0]; |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + if (count($this->command['enum']) >= 3) { |
|
| 423 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']), |
|
| 424 | + array_shift($this->command['enum'])); |
|
| 425 | + } else { |
|
| 426 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 427 | + } |
|
| 428 | + $this->tableau = $enum; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * extraire le chemin "query.results" du tableau de donnees |
|
| 434 | + * {datapath query.results} |
|
| 435 | + * |
|
| 436 | + **/ |
|
| 437 | + protected function select_datapath() { |
|
| 438 | + $base = reset($this->command['datapath']); |
|
| 439 | + if (strlen($base = ltrim(trim($base), "/"))) { |
|
| 440 | + $this->tableau = table_valeur($this->tableau, $base); |
|
| 441 | + if (!is_array($this->tableau)) { |
|
| 442 | + $this->tableau = array(); |
|
| 443 | + $this->err = true; |
|
| 444 | + spip_log("datapath '$base' absent"); |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * Ordonner les resultats |
|
| 451 | + * {par x} |
|
| 452 | + * |
|
| 453 | + **/ |
|
| 454 | + protected function select_orderby() { |
|
| 455 | + $sortfunc = ''; |
|
| 456 | + $aleas = 0; |
|
| 457 | + foreach ($this->command['orderby'] as $tri) { |
|
| 458 | + // virer le / initial pour les criteres de la forme {par /xx} |
|
| 459 | + if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 460 | + $r = array_pad($r, 3, null); |
|
| 461 | + |
|
| 462 | + // tri par cle |
|
| 463 | + if ($r[1] == 'cle') { |
|
| 464 | + if (isset($r[2]) and $r[2]) { |
|
| 465 | + krsort($this->tableau); |
|
| 466 | + } else { |
|
| 467 | + ksort($this->tableau); |
|
| 468 | + } |
|
| 469 | + } # {par hasard} |
|
| 470 | + else { |
|
| 471 | + if ($r[1] == 'hasard') { |
|
| 472 | + $k = array_keys($this->tableau); |
|
| 473 | + shuffle($k); |
|
| 474 | + $v = array(); |
|
| 475 | + foreach ($k as $cle) { |
|
| 476 | + $v[$cle] = $this->tableau[$cle]; |
|
| 477 | + } |
|
| 478 | + $this->tableau = $v; |
|
| 479 | + } else { |
|
| 480 | + # {par valeur} |
|
| 481 | + if ($r[1] == 'valeur') { |
|
| 482 | + $tv = '%s'; |
|
| 483 | + } # {par valeur/xx/yy} ?? |
|
| 484 | + else { |
|
| 485 | + $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 486 | + } |
|
| 487 | + $sortfunc .= ' |
|
| 488 | 488 | $a = ' . sprintf($tv, '$aa') . '; |
| 489 | 489 | $b = ' . sprintf($tv, '$bb') . '; |
| 490 | 490 | if ($a <> $b) |
| 491 | 491 | return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
| 492 | - } |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - if ($sortfunc) { |
|
| 498 | - $sortfunc .= "\n return 0;"; |
|
| 499 | - uasort($this->tableau, function($aa, $bb) use ($sortfunc) { |
|
| 500 | - return eval($sortfunc); |
|
| 501 | - }); |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * Grouper les resultats |
|
| 508 | - * {fusion /x/y/z} |
|
| 509 | - * |
|
| 510 | - **/ |
|
| 511 | - protected function select_groupby() { |
|
| 512 | - // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 513 | - if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 514 | - $vu = array(); |
|
| 515 | - foreach ($this->tableau as $k => $v) { |
|
| 516 | - $val = table_valeur($v, $fusion); |
|
| 517 | - if (isset($vu[$val])) { |
|
| 518 | - unset($this->tableau[$k]); |
|
| 519 | - } else { |
|
| 520 | - $vu[$val] = true; |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * L'iterateur est-il encore valide ? |
|
| 529 | - * |
|
| 530 | - * @return bool |
|
| 531 | - */ |
|
| 532 | - public function valid() { |
|
| 533 | - return !is_null($this->cle); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - /** |
|
| 537 | - * Retourner la valeur |
|
| 538 | - * |
|
| 539 | - * @return null |
|
| 540 | - */ |
|
| 541 | - public function current() { |
|
| 542 | - return $this->valeur; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * Retourner la cle |
|
| 547 | - * |
|
| 548 | - * @return null |
|
| 549 | - */ |
|
| 550 | - public function key() { |
|
| 551 | - return $this->cle; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * Passer a la valeur suivante |
|
| 556 | - * |
|
| 557 | - * @return void |
|
| 558 | - */ |
|
| 559 | - public function next() { |
|
| 560 | - if ($this->valid()) { |
|
| 561 | - $this->cle = key($this->tableau); |
|
| 562 | - $this->valeur = current($this->tableau); |
|
| 563 | - next($this->tableau); |
|
| 564 | - } |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * Compter le nombre total de resultats |
|
| 569 | - * |
|
| 570 | - * @return int |
|
| 571 | - */ |
|
| 572 | - public function count() { |
|
| 573 | - if (is_null($this->total)) { |
|
| 574 | - $this->total = count($this->tableau); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - return $this->total; |
|
| 578 | - } |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + if ($sortfunc) { |
|
| 498 | + $sortfunc .= "\n return 0;"; |
|
| 499 | + uasort($this->tableau, function($aa, $bb) use ($sortfunc) { |
|
| 500 | + return eval($sortfunc); |
|
| 501 | + }); |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Grouper les resultats |
|
| 508 | + * {fusion /x/y/z} |
|
| 509 | + * |
|
| 510 | + **/ |
|
| 511 | + protected function select_groupby() { |
|
| 512 | + // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 513 | + if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 514 | + $vu = array(); |
|
| 515 | + foreach ($this->tableau as $k => $v) { |
|
| 516 | + $val = table_valeur($v, $fusion); |
|
| 517 | + if (isset($vu[$val])) { |
|
| 518 | + unset($this->tableau[$k]); |
|
| 519 | + } else { |
|
| 520 | + $vu[$val] = true; |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * L'iterateur est-il encore valide ? |
|
| 529 | + * |
|
| 530 | + * @return bool |
|
| 531 | + */ |
|
| 532 | + public function valid() { |
|
| 533 | + return !is_null($this->cle); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * Retourner la valeur |
|
| 538 | + * |
|
| 539 | + * @return null |
|
| 540 | + */ |
|
| 541 | + public function current() { |
|
| 542 | + return $this->valeur; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * Retourner la cle |
|
| 547 | + * |
|
| 548 | + * @return null |
|
| 549 | + */ |
|
| 550 | + public function key() { |
|
| 551 | + return $this->cle; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * Passer a la valeur suivante |
|
| 556 | + * |
|
| 557 | + * @return void |
|
| 558 | + */ |
|
| 559 | + public function next() { |
|
| 560 | + if ($this->valid()) { |
|
| 561 | + $this->cle = key($this->tableau); |
|
| 562 | + $this->valeur = current($this->tableau); |
|
| 563 | + next($this->tableau); |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * Compter le nombre total de resultats |
|
| 569 | + * |
|
| 570 | + * @return int |
|
| 571 | + */ |
|
| 572 | + public function count() { |
|
| 573 | + if (is_null($this->total)) { |
|
| 574 | + $this->total = count($this->tableau); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + return $this->total; |
|
| 578 | + } |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | /* |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | * @return array |
| 590 | 590 | */ |
| 591 | 591 | function inc_file_to_array_dist($u) { |
| 592 | - return preg_split('/\r?\n/', $u); |
|
| 592 | + return preg_split('/\r?\n/', $u); |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | /** |
@@ -598,9 +598,9 @@ discard block |
||
| 598 | 598 | * @return unknown |
| 599 | 599 | */ |
| 600 | 600 | function inc_plugins_to_array_dist() { |
| 601 | - include_spip('inc/plugin'); |
|
| 601 | + include_spip('inc/plugin'); |
|
| 602 | 602 | |
| 603 | - return liste_chemin_plugin_actifs(); |
|
| 603 | + return liste_chemin_plugin_actifs(); |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | /** |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | * @return array |
| 611 | 611 | */ |
| 612 | 612 | function inc_xml_to_array_dist($u) { |
| 613 | - return @XMLObjectToArray(new SimpleXmlIterator($u)); |
|
| 613 | + return @XMLObjectToArray(new SimpleXmlIterator($u)); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
@@ -622,14 +622,14 @@ discard block |
||
| 622 | 622 | * |
| 623 | 623 | */ |
| 624 | 624 | function inc_object_to_array($object) { |
| 625 | - if (!is_object($object) && !is_array($object)) { |
|
| 626 | - return $object; |
|
| 627 | - } |
|
| 628 | - if (is_object($object)) { |
|
| 629 | - $object = get_object_vars($object); |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - return array_map('inc_object_to_array', $object); |
|
| 625 | + if (!is_object($object) && !is_array($object)) { |
|
| 626 | + return $object; |
|
| 627 | + } |
|
| 628 | + if (is_object($object)) { |
|
| 629 | + $object = get_object_vars($object); |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + return array_map('inc_object_to_array', $object); |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | /** |
@@ -640,18 +640,18 @@ discard block |
||
| 640 | 640 | * @return array|bool |
| 641 | 641 | */ |
| 642 | 642 | function inc_yql_to_array_dist($u) { |
| 643 | - define('_YQL_ENDPOINT', 'https://query.yahooapis.com/v1/public/yql?&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q='); |
|
| 644 | - $v = recuperer_url($url = _YQL_ENDPOINT . urlencode($u) . '&format=json'); |
|
| 645 | - if (!$v['page'] |
|
| 646 | - or !$w = json_decode($v['page'], true) |
|
| 647 | - ) { |
|
| 648 | - throw new Exception('YQL: réponse vide ou mal formée'); |
|
| 649 | - } |
|
| 650 | - if (isset($w['error'])) { |
|
| 651 | - throw new Exception($w['error']['description']); |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - return inc_object_to_array($w); |
|
| 643 | + define('_YQL_ENDPOINT', 'https://query.yahooapis.com/v1/public/yql?&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q='); |
|
| 644 | + $v = recuperer_url($url = _YQL_ENDPOINT . urlencode($u) . '&format=json'); |
|
| 645 | + if (!$v['page'] |
|
| 646 | + or !$w = json_decode($v['page'], true) |
|
| 647 | + ) { |
|
| 648 | + throw new Exception('YQL: réponse vide ou mal formée'); |
|
| 649 | + } |
|
| 650 | + if (isset($w['error'])) { |
|
| 651 | + throw new Exception($w['error']['description']); |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + return inc_object_to_array($w); |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
@@ -661,20 +661,20 @@ discard block |
||
| 661 | 661 | * @return array|bool |
| 662 | 662 | */ |
| 663 | 663 | function inc_sql_to_array_dist($u) { |
| 664 | - # sortir le connecteur de $u |
|
| 665 | - preg_match(',^(?:(\w+):)?(.*)$,S', $u, $v); |
|
| 666 | - $serveur = (string)$v[1]; |
|
| 667 | - $req = trim($v[2]); |
|
| 668 | - if ($s = sql_query($req, $serveur)) { |
|
| 669 | - $r = array(); |
|
| 670 | - while ($t = sql_fetch($s)) { |
|
| 671 | - $r[] = $t; |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - return $r; |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - return false; |
|
| 664 | + # sortir le connecteur de $u |
|
| 665 | + preg_match(',^(?:(\w+):)?(.*)$,S', $u, $v); |
|
| 666 | + $serveur = (string)$v[1]; |
|
| 667 | + $req = trim($v[2]); |
|
| 668 | + if ($s = sql_query($req, $serveur)) { |
|
| 669 | + $r = array(); |
|
| 670 | + while ($t = sql_fetch($s)) { |
|
| 671 | + $r[] = $t; |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + return $r; |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + return false; |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | /** |
@@ -684,11 +684,11 @@ discard block |
||
| 684 | 684 | * @return array|bool |
| 685 | 685 | */ |
| 686 | 686 | function inc_json_to_array_dist($u) { |
| 687 | - if (is_array($json = json_decode($u)) |
|
| 688 | - or is_object($json) |
|
| 689 | - ) { |
|
| 690 | - return (array)$json; |
|
| 691 | - } |
|
| 687 | + if (is_array($json = json_decode($u)) |
|
| 688 | + or is_object($json) |
|
| 689 | + ) { |
|
| 690 | + return (array)$json; |
|
| 691 | + } |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | /** |
@@ -698,30 +698,30 @@ discard block |
||
| 698 | 698 | * @return array|bool |
| 699 | 699 | */ |
| 700 | 700 | function inc_csv_to_array_dist($u) { |
| 701 | - include_spip('inc/csv'); |
|
| 702 | - list($entete, $csv) = analyse_csv($u); |
|
| 703 | - array_unshift($csv, $entete); |
|
| 704 | - |
|
| 705 | - include_spip('inc/charsets'); |
|
| 706 | - $i = 1; |
|
| 707 | - foreach ($entete as $k => $v) { |
|
| 708 | - if (trim($v) == "") { |
|
| 709 | - $v = "col" . $i; |
|
| 710 | - } // reperer des eventuelles cases vides |
|
| 711 | - if (is_numeric($v) and $v < 0) { |
|
| 712 | - $v = "__" . $v; |
|
| 713 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 714 | - if (is_numeric($v)) { |
|
| 715 | - $v = "_" . $v; |
|
| 716 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 717 | - $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 718 | - foreach ($csv as &$item) { |
|
| 719 | - $item[$v] = &$item[$k]; |
|
| 720 | - } |
|
| 721 | - $i++; |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - return $csv; |
|
| 701 | + include_spip('inc/csv'); |
|
| 702 | + list($entete, $csv) = analyse_csv($u); |
|
| 703 | + array_unshift($csv, $entete); |
|
| 704 | + |
|
| 705 | + include_spip('inc/charsets'); |
|
| 706 | + $i = 1; |
|
| 707 | + foreach ($entete as $k => $v) { |
|
| 708 | + if (trim($v) == "") { |
|
| 709 | + $v = "col" . $i; |
|
| 710 | + } // reperer des eventuelles cases vides |
|
| 711 | + if (is_numeric($v) and $v < 0) { |
|
| 712 | + $v = "__" . $v; |
|
| 713 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 714 | + if (is_numeric($v)) { |
|
| 715 | + $v = "_" . $v; |
|
| 716 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 717 | + $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 718 | + foreach ($csv as &$item) { |
|
| 719 | + $item[$v] = &$item[$k]; |
|
| 720 | + } |
|
| 721 | + $i++; |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + return $csv; |
|
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | /** |
@@ -731,12 +731,12 @@ discard block |
||
| 731 | 731 | * @return array|bool |
| 732 | 732 | */ |
| 733 | 733 | function inc_rss_to_array_dist($u) { |
| 734 | - include_spip('inc/syndic'); |
|
| 735 | - if (is_array($rss = analyser_backend($u))) { |
|
| 736 | - $tableau = $rss; |
|
| 737 | - } |
|
| 734 | + include_spip('inc/syndic'); |
|
| 735 | + if (is_array($rss = analyser_backend($u))) { |
|
| 736 | + $tableau = $rss; |
|
| 737 | + } |
|
| 738 | 738 | |
| 739 | - return $tableau; |
|
| 739 | + return $tableau; |
|
| 740 | 740 | } |
| 741 | 741 | |
| 742 | 742 | /** |
@@ -746,9 +746,9 @@ discard block |
||
| 746 | 746 | * @return array|bool |
| 747 | 747 | */ |
| 748 | 748 | function inc_atom_to_array_dist($u) { |
| 749 | - $g = charger_fonction('rss_to_array', 'inc'); |
|
| 749 | + $g = charger_fonction('rss_to_array', 'inc'); |
|
| 750 | 750 | |
| 751 | - return $g($u); |
|
| 751 | + return $g($u); |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | /** |
@@ -759,11 +759,11 @@ discard block |
||
| 759 | 759 | * @return array|bool |
| 760 | 760 | */ |
| 761 | 761 | function inc_glob_to_array_dist($u) { |
| 762 | - $a = glob($u, |
|
| 763 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 764 | - ); |
|
| 762 | + $a = glob($u, |
|
| 763 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 764 | + ); |
|
| 765 | 765 | |
| 766 | - return $a ? $a : array(); |
|
| 766 | + return $a ? $a : array(); |
|
| 767 | 767 | } |
| 768 | 768 | |
| 769 | 769 | /** |
@@ -774,14 +774,14 @@ discard block |
||
| 774 | 774 | * @throws Exception |
| 775 | 775 | */ |
| 776 | 776 | function inc_yaml_to_array_dist($u) { |
| 777 | - include_spip('inc/yaml-mini'); |
|
| 778 | - if (!function_exists("yaml_decode")) { |
|
| 779 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 777 | + include_spip('inc/yaml-mini'); |
|
| 778 | + if (!function_exists("yaml_decode")) { |
|
| 779 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 780 | 780 | |
| 781 | - return false; |
|
| 782 | - } |
|
| 781 | + return false; |
|
| 782 | + } |
|
| 783 | 783 | |
| 784 | - return yaml_decode($u); |
|
| 784 | + return yaml_decode($u); |
|
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | * @return array|bool |
| 797 | 797 | */ |
| 798 | 798 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 799 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 799 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | /** |
@@ -808,23 +808,23 @@ discard block |
||
| 808 | 808 | * @return array|bool |
| 809 | 809 | */ |
| 810 | 810 | function inc_ls_to_array_dist($u) { |
| 811 | - $glob = charger_fonction('glob_to_array', 'inc'); |
|
| 812 | - $a = $glob($u); |
|
| 813 | - foreach ($a as &$v) { |
|
| 814 | - $b = (array)@stat($v); |
|
| 815 | - foreach ($b as $k => $ignore) { |
|
| 816 | - if (is_numeric($k)) { |
|
| 817 | - unset($b[$k]); |
|
| 818 | - } |
|
| 819 | - } |
|
| 820 | - $b['file'] = preg_replace('`/$`','',$v) ; |
|
| 821 | - $v = array_merge( |
|
| 822 | - pathinfo($v), |
|
| 823 | - $b |
|
| 824 | - ); |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - return $a; |
|
| 811 | + $glob = charger_fonction('glob_to_array', 'inc'); |
|
| 812 | + $a = $glob($u); |
|
| 813 | + foreach ($a as &$v) { |
|
| 814 | + $b = (array)@stat($v); |
|
| 815 | + foreach ($b as $k => $ignore) { |
|
| 816 | + if (is_numeric($k)) { |
|
| 817 | + unset($b[$k]); |
|
| 818 | + } |
|
| 819 | + } |
|
| 820 | + $b['file'] = preg_replace('`/$`','',$v) ; |
|
| 821 | + $v = array_merge( |
|
| 822 | + pathinfo($v), |
|
| 823 | + $b |
|
| 824 | + ); |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + return $a; |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | /** |
@@ -834,24 +834,24 @@ discard block |
||
| 834 | 834 | * @return array|bool |
| 835 | 835 | */ |
| 836 | 836 | function XMLObjectToArray($object) { |
| 837 | - $xml_array = array(); |
|
| 838 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 839 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 840 | - $key .= '-' . uniqid(); |
|
| 841 | - } |
|
| 842 | - $vars = get_object_vars($object->current()); |
|
| 843 | - if (isset($vars['@attributes'])) { |
|
| 844 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 845 | - $xml_array[$key][$k] = $v; |
|
| 846 | - } |
|
| 847 | - } |
|
| 848 | - if ($object->hasChildren()) { |
|
| 849 | - $xml_array[$key][] = XMLObjectToArray( |
|
| 850 | - $object->current()); |
|
| 851 | - } else { |
|
| 852 | - $xml_array[$key][] = strval($object->current()); |
|
| 853 | - } |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - return $xml_array; |
|
| 837 | + $xml_array = array(); |
|
| 838 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 839 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 840 | + $key .= '-' . uniqid(); |
|
| 841 | + } |
|
| 842 | + $vars = get_object_vars($object->current()); |
|
| 843 | + if (isset($vars['@attributes'])) { |
|
| 844 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 845 | + $xml_array[$key][$k] = $v; |
|
| 846 | + } |
|
| 847 | + } |
|
| 848 | + if ($object->hasChildren()) { |
|
| 849 | + $xml_array[$key][] = XMLObjectToArray( |
|
| 850 | + $object->current()); |
|
| 851 | + } else { |
|
| 852 | + $xml_array[$key][] = strval($object->current()); |
|
| 853 | + } |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + return $xml_array; |
|
| 857 | 857 | } |
@@ -121,6 +121,10 @@ discard block |
||
| 121 | 121 | // checkbox pour activer ou desactiver |
| 122 | 122 | // si ce n'est pas une extension |
| 123 | 123 | |
| 124 | +/** |
|
| 125 | + * @param integer $id_input |
|
| 126 | + * @param string $file |
|
| 127 | + */ |
|
| 124 | 128 | function plugin_checkbox($id_input, $file, $actif) { |
| 125 | 129 | $name = substr(md5($file), 0, 16); |
| 126 | 130 | |
@@ -185,6 +189,9 @@ discard block |
||
| 185 | 189 | . "</div>"; |
| 186 | 190 | } |
| 187 | 191 | |
| 192 | +/** |
|
| 193 | + * @param string $nom |
|
| 194 | + */ |
|
| 188 | 195 | function plugin_desintalle($plug_file, $nom, $dir_plugins = null) { |
| 189 | 196 | if (!$dir_plugins) { |
| 190 | 197 | $dir_plugins = _DIR_PLUGINS; |
@@ -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 | include_spip('inc/charsets'); |
| 23 | 23 | include_spip('inc/texte'); |
@@ -25,181 +25,181 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | // http://code.spip.net/@ligne_plug |
| 27 | 27 | function plugins_afficher_plugin_dist( |
| 28 | - $url_page, |
|
| 29 | - $plug_file, |
|
| 30 | - $checked, |
|
| 31 | - $actif, |
|
| 32 | - $expose = false, |
|
| 33 | - $class_li = "item", |
|
| 34 | - $dir_plugins = _DIR_PLUGINS |
|
| 28 | + $url_page, |
|
| 29 | + $plug_file, |
|
| 30 | + $checked, |
|
| 31 | + $actif, |
|
| 32 | + $expose = false, |
|
| 33 | + $class_li = "item", |
|
| 34 | + $dir_plugins = _DIR_PLUGINS |
|
| 35 | 35 | ) { |
| 36 | 36 | |
| 37 | - static $id_input = 0; |
|
| 38 | - static $versions = array(); |
|
| 39 | - |
|
| 40 | - $force_reload = (_request('var_mode') == 'recalcul'); |
|
| 41 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 42 | - $info = $get_infos($plug_file, $force_reload, $dir_plugins); |
|
| 43 | - $prefix = $info['prefix']; |
|
| 44 | - $cfg = ""; |
|
| 45 | - $checkable = ($dir_plugins !== _DIR_PLUGINS_DIST); |
|
| 46 | - $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 47 | - $erreur = ""; |
|
| 48 | - |
|
| 49 | - if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 50 | - $info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 51 | - $erreur = http_img_pack("plugin-dis-32.png", _T('plugin_info_non_compatible_spip'), " class='picto_err'", |
|
| 52 | - _T('plugin_info_non_compatible_spip')); |
|
| 53 | - $class_li .= " disabled"; |
|
| 54 | - $checkable = false; |
|
| 55 | - } elseif (isset($info['erreur'])) { |
|
| 56 | - $class_li .= " error"; |
|
| 57 | - $erreur = http_img_pack("plugin-err-32.png", _T('plugin_info_erreur_xml'), " class='picto_err'", |
|
| 58 | - _T('plugin_info_erreur_xml')) |
|
| 59 | - . "<div class='erreur'>" . join('<br >', $info['erreur']) . "</div>"; |
|
| 60 | - $checkable = false; |
|
| 61 | - } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) { |
|
| 62 | - $class_li .= " error"; |
|
| 63 | - $erreur = http_img_pack("plugin-err-32.png", _T('plugin_impossible_activer', array('plugin' => $nom)), |
|
| 64 | - " class='picto_err'", _T('plugin_impossible_activer', array('plugin' => $nom))) |
|
| 65 | - . "<div class='erreur'>" . implode("<br />", |
|
| 66 | - $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file]) . "</div>"; |
|
| 67 | - } else { |
|
| 68 | - $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ""; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // numerotons les occurrences d'un meme prefix |
|
| 72 | - $versions[$prefix] = $id = isset($versions[$prefix]) ? $versions[$prefix] + 1 : ''; |
|
| 73 | - |
|
| 74 | - $class_li .= ($actif ? " actif" : "") . ($expose ? " on" : ""); |
|
| 75 | - |
|
| 76 | - return "<li id='$prefix$id' class='$class_li'>" |
|
| 77 | - . ((!$checkable and !$checked) |
|
| 78 | - ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked)) |
|
| 79 | - . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
|
| 80 | - . $cfg |
|
| 81 | - . $erreur |
|
| 82 | - . (($dir_plugins !== _DIR_PLUGINS_DIST and plugin_est_installe($plug_file)) |
|
| 83 | - ? plugin_desintalle($plug_file, $nom, $dir_plugins) : '') |
|
| 84 | - . "<div class='details'>" // pour l'ajax de exec/info_plugin |
|
| 85 | - . (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins)) |
|
| 86 | - . "</div>" |
|
| 87 | - . "</li>"; |
|
| 37 | + static $id_input = 0; |
|
| 38 | + static $versions = array(); |
|
| 39 | + |
|
| 40 | + $force_reload = (_request('var_mode') == 'recalcul'); |
|
| 41 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 42 | + $info = $get_infos($plug_file, $force_reload, $dir_plugins); |
|
| 43 | + $prefix = $info['prefix']; |
|
| 44 | + $cfg = ""; |
|
| 45 | + $checkable = ($dir_plugins !== _DIR_PLUGINS_DIST); |
|
| 46 | + $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 47 | + $erreur = ""; |
|
| 48 | + |
|
| 49 | + if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 50 | + $info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 51 | + $erreur = http_img_pack("plugin-dis-32.png", _T('plugin_info_non_compatible_spip'), " class='picto_err'", |
|
| 52 | + _T('plugin_info_non_compatible_spip')); |
|
| 53 | + $class_li .= " disabled"; |
|
| 54 | + $checkable = false; |
|
| 55 | + } elseif (isset($info['erreur'])) { |
|
| 56 | + $class_li .= " error"; |
|
| 57 | + $erreur = http_img_pack("plugin-err-32.png", _T('plugin_info_erreur_xml'), " class='picto_err'", |
|
| 58 | + _T('plugin_info_erreur_xml')) |
|
| 59 | + . "<div class='erreur'>" . join('<br >', $info['erreur']) . "</div>"; |
|
| 60 | + $checkable = false; |
|
| 61 | + } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) { |
|
| 62 | + $class_li .= " error"; |
|
| 63 | + $erreur = http_img_pack("plugin-err-32.png", _T('plugin_impossible_activer', array('plugin' => $nom)), |
|
| 64 | + " class='picto_err'", _T('plugin_impossible_activer', array('plugin' => $nom))) |
|
| 65 | + . "<div class='erreur'>" . implode("<br />", |
|
| 66 | + $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file]) . "</div>"; |
|
| 67 | + } else { |
|
| 68 | + $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ""; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // numerotons les occurrences d'un meme prefix |
|
| 72 | + $versions[$prefix] = $id = isset($versions[$prefix]) ? $versions[$prefix] + 1 : ''; |
|
| 73 | + |
|
| 74 | + $class_li .= ($actif ? " actif" : "") . ($expose ? " on" : ""); |
|
| 75 | + |
|
| 76 | + return "<li id='$prefix$id' class='$class_li'>" |
|
| 77 | + . ((!$checkable and !$checked) |
|
| 78 | + ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked)) |
|
| 79 | + . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
|
| 80 | + . $cfg |
|
| 81 | + . $erreur |
|
| 82 | + . (($dir_plugins !== _DIR_PLUGINS_DIST and plugin_est_installe($plug_file)) |
|
| 83 | + ? plugin_desintalle($plug_file, $nom, $dir_plugins) : '') |
|
| 84 | + . "<div class='details'>" // pour l'ajax de exec/info_plugin |
|
| 85 | + . (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins)) |
|
| 86 | + . "</div>" |
|
| 87 | + . "</li>"; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | function plugin_bouton_config($nom, $infos, $dir) { |
| 91 | - // la verification se base sur le filesystem |
|
| 92 | - // il faut donc n'utiliser que des minuscules, par convention |
|
| 93 | - $prefix = strtolower($infos['prefix']); |
|
| 94 | - // si plugin.xml fournit un squelette, le prendre |
|
| 95 | - if (isset($infos['config']) and $infos['config']) { |
|
| 96 | - return recuperer_fond("$dir$nom/" . $infos['config'], |
|
| 97 | - array( |
|
| 98 | - 'script' => 'configurer_' . $prefix, |
|
| 99 | - 'nom' => $nom |
|
| 100 | - )); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // si le plugin CFG est la, l'essayer |
|
| 104 | - if (defined('_DIR_PLUGIN_CFG')) { |
|
| 105 | - if (include_spip('inc/cfg')) // test CFG version >= 1.0.5 |
|
| 106 | - { |
|
| 107 | - if ($cfg = icone_lien_cfg("$dir$nom", "cfg")) { |
|
| 108 | - return "<div class='cfg_link'>$cfg</div>"; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - // sinon prendre le squelette std sur le nom std |
|
| 114 | - return recuperer_fond("prive/squelettes/inclure/cfg", |
|
| 115 | - array( |
|
| 116 | - 'script' => 'configurer_' . $prefix, |
|
| 117 | - 'nom' => $nom |
|
| 118 | - )); |
|
| 91 | + // la verification se base sur le filesystem |
|
| 92 | + // il faut donc n'utiliser que des minuscules, par convention |
|
| 93 | + $prefix = strtolower($infos['prefix']); |
|
| 94 | + // si plugin.xml fournit un squelette, le prendre |
|
| 95 | + if (isset($infos['config']) and $infos['config']) { |
|
| 96 | + return recuperer_fond("$dir$nom/" . $infos['config'], |
|
| 97 | + array( |
|
| 98 | + 'script' => 'configurer_' . $prefix, |
|
| 99 | + 'nom' => $nom |
|
| 100 | + )); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // si le plugin CFG est la, l'essayer |
|
| 104 | + if (defined('_DIR_PLUGIN_CFG')) { |
|
| 105 | + if (include_spip('inc/cfg')) // test CFG version >= 1.0.5 |
|
| 106 | + { |
|
| 107 | + if ($cfg = icone_lien_cfg("$dir$nom", "cfg")) { |
|
| 108 | + return "<div class='cfg_link'>$cfg</div>"; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + // sinon prendre le squelette std sur le nom std |
|
| 114 | + return recuperer_fond("prive/squelettes/inclure/cfg", |
|
| 115 | + array( |
|
| 116 | + 'script' => 'configurer_' . $prefix, |
|
| 117 | + 'nom' => $nom |
|
| 118 | + )); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // checkbox pour activer ou desactiver |
| 122 | 122 | // si ce n'est pas une extension |
| 123 | 123 | |
| 124 | 124 | function plugin_checkbox($id_input, $file, $actif) { |
| 125 | - $name = substr(md5($file), 0, 16); |
|
| 126 | - |
|
| 127 | - return "<div class='check'>\n" |
|
| 128 | - . "<input type='checkbox' name='s$name' id='label_$id_input'" |
|
| 129 | - . ($actif ? " checked='checked'" : "") |
|
| 130 | - . " class='checkbox' value='O' />" |
|
| 131 | - . "\n<label for='label_$id_input'>" . _T('activer_plugin') . "</label>" |
|
| 132 | - . "</div>"; |
|
| 125 | + $name = substr(md5($file), 0, 16); |
|
| 126 | + |
|
| 127 | + return "<div class='check'>\n" |
|
| 128 | + . "<input type='checkbox' name='s$name' id='label_$id_input'" |
|
| 129 | + . ($actif ? " checked='checked'" : "") |
|
| 130 | + . " class='checkbox' value='O' />" |
|
| 131 | + . "\n<label for='label_$id_input'>" . _T('activer_plugin') . "</label>" |
|
| 132 | + . "</div>"; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | function plugin_nom($info, $dir_plugins, $plug_file) { |
| 136 | - $prefix = $info['prefix']; |
|
| 137 | - $dir = "$dir_plugins$plug_file"; |
|
| 138 | - // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom" |
|
| 139 | - if ($info['dtd'] == "paquet") { |
|
| 140 | - $nom = PtoBR(plugin_propre("{$prefix}_nom", "$dir/lang/paquet-$prefix")); |
|
| 141 | - if (!$nom) { |
|
| 142 | - $nom = PtoBR(propre($info['nom'])); |
|
| 143 | - } |
|
| 144 | - } else { |
|
| 145 | - $nom = typo(attribut_html($info['nom'])); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - return trim($nom); |
|
| 136 | + $prefix = $info['prefix']; |
|
| 137 | + $dir = "$dir_plugins$plug_file"; |
|
| 138 | + // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom" |
|
| 139 | + if ($info['dtd'] == "paquet") { |
|
| 140 | + $nom = PtoBR(plugin_propre("{$prefix}_nom", "$dir/lang/paquet-$prefix")); |
|
| 141 | + if (!$nom) { |
|
| 142 | + $nom = PtoBR(propre($info['nom'])); |
|
| 143 | + } |
|
| 144 | + } else { |
|
| 145 | + $nom = typo(attribut_html($info['nom'])); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + return trim($nom); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // Cartouche Resume |
| 152 | 152 | function plugin_resume($info, $dir_plugins, $plug_file, $url_page) { |
| 153 | - $prefix = $info['prefix']; |
|
| 154 | - $dir = "$dir_plugins$plug_file"; |
|
| 155 | - $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix")); |
|
| 156 | - // une seule ligne dans le slogan : couper si besoin |
|
| 157 | - if (($p = strpos($slogan, "<br />")) !== false) { |
|
| 158 | - $slogan = substr($slogan, 0, $p); |
|
| 159 | - } |
|
| 160 | - // couper par securite |
|
| 161 | - $slogan = couper($slogan, 80); |
|
| 162 | - |
|
| 163 | - $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 164 | - |
|
| 165 | - $url = parametre_url($url_page, "plugin", substr($dir, strlen(_DIR_RACINE))); |
|
| 166 | - |
|
| 167 | - if (isset($info['logo']) and $i = trim($info['logo'])) { |
|
| 168 | - include_spip("inc/filtres_images_mini"); |
|
| 169 | - $i = inserer_attribut(image_reduire("$dir/$i", 32), 'alt', ''); |
|
| 170 | - $i = "<div class='icon'><a href='$url' rel='info'>$i</a></div>"; |
|
| 171 | - } else { |
|
| 172 | - $i = ''; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - return "<div class='resume'>" |
|
| 176 | - . "<h3><a href='$url' rel='info'>" |
|
| 177 | - . $nom |
|
| 178 | - . "</a></h3>" |
|
| 179 | - . " <span class='version'>" . $info['version'] . "</span>" |
|
| 180 | - . " <span class='etat'> - " |
|
| 181 | - . plugin_etat_en_clair($info['etat']) |
|
| 182 | - . "</span>" |
|
| 183 | - . "<div class='short'>" . $slogan . "</div>" |
|
| 184 | - . $i |
|
| 185 | - . "</div>"; |
|
| 153 | + $prefix = $info['prefix']; |
|
| 154 | + $dir = "$dir_plugins$plug_file"; |
|
| 155 | + $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix")); |
|
| 156 | + // une seule ligne dans le slogan : couper si besoin |
|
| 157 | + if (($p = strpos($slogan, "<br />")) !== false) { |
|
| 158 | + $slogan = substr($slogan, 0, $p); |
|
| 159 | + } |
|
| 160 | + // couper par securite |
|
| 161 | + $slogan = couper($slogan, 80); |
|
| 162 | + |
|
| 163 | + $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 164 | + |
|
| 165 | + $url = parametre_url($url_page, "plugin", substr($dir, strlen(_DIR_RACINE))); |
|
| 166 | + |
|
| 167 | + if (isset($info['logo']) and $i = trim($info['logo'])) { |
|
| 168 | + include_spip("inc/filtres_images_mini"); |
|
| 169 | + $i = inserer_attribut(image_reduire("$dir/$i", 32), 'alt', ''); |
|
| 170 | + $i = "<div class='icon'><a href='$url' rel='info'>$i</a></div>"; |
|
| 171 | + } else { |
|
| 172 | + $i = ''; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + return "<div class='resume'>" |
|
| 176 | + . "<h3><a href='$url' rel='info'>" |
|
| 177 | + . $nom |
|
| 178 | + . "</a></h3>" |
|
| 179 | + . " <span class='version'>" . $info['version'] . "</span>" |
|
| 180 | + . " <span class='etat'> - " |
|
| 181 | + . plugin_etat_en_clair($info['etat']) |
|
| 182 | + . "</span>" |
|
| 183 | + . "<div class='short'>" . $slogan . "</div>" |
|
| 184 | + . $i |
|
| 185 | + . "</div>"; |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | function plugin_desintalle($plug_file, $nom, $dir_plugins = null) { |
| 189 | - if (!$dir_plugins) { |
|
| 190 | - $dir_plugins = _DIR_PLUGINS; |
|
| 191 | - } |
|
| 189 | + if (!$dir_plugins) { |
|
| 190 | + $dir_plugins = _DIR_PLUGINS; |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - $action = redirige_action_auteur('desinstaller_plugin', "$dir_plugins::$plug_file", 'admin_plugin'); |
|
| 194 | - $text = _T('bouton_desinstaller'); |
|
| 195 | - $text2 = _T('info_desinstaller_plugin'); |
|
| 196 | - $file = basename($plug_file); |
|
| 193 | + $action = redirige_action_auteur('desinstaller_plugin', "$dir_plugins::$plug_file", 'admin_plugin'); |
|
| 194 | + $text = _T('bouton_desinstaller'); |
|
| 195 | + $text2 = _T('info_desinstaller_plugin'); |
|
| 196 | + $file = basename($plug_file); |
|
| 197 | 197 | |
| 198 | - return "<div class='actions'>[" . |
|
| 199 | - "<a href='$action' |
|
| 198 | + return "<div class='actions'>[" . |
|
| 199 | + "<a href='$action' |
|
| 200 | 200 | onclick='return confirm(\"$text $nom ?\\n$text2\")'>" |
| 201 | - . $text |
|
| 202 | - . "</a>]</div>"; |
|
| 201 | + . $text |
|
| 202 | + . "</a>]</div>"; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -213,132 +213,132 @@ discard block |
||
| 213 | 213 | * Traduction de l'état dans la langue en cours |
| 214 | 214 | **/ |
| 215 | 215 | function plugin_etat_en_clair($etat) { |
| 216 | - if (!in_array($etat, array('stable', 'test', 'experimental'))) { |
|
| 217 | - $etat = 'developpement'; |
|
| 218 | - } |
|
| 216 | + if (!in_array($etat, array('stable', 'test', 'experimental'))) { |
|
| 217 | + $etat = 'developpement'; |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - return _T('plugin_etat_' . $etat); |
|
| 220 | + return _T('plugin_etat_' . $etat); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | // http://code.spip.net/@plugin_propre |
| 224 | 224 | function plugin_propre($texte, $module = '') { |
| 225 | - // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine |
|
| 226 | - if (_DIR_RACINE and strncmp($module, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 227 | - $module = substr($module, strlen(_DIR_RACINE)); |
|
| 228 | - } |
|
| 229 | - if (preg_match("|^\w+_[\w_]+$|", $texte)) { |
|
| 230 | - $texte = _T(($module ? "$module:" : '') . $texte, array(), array('force' => false)); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - return propre($texte); |
|
| 225 | + // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine |
|
| 226 | + if (_DIR_RACINE and strncmp($module, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 227 | + $module = substr($module, strlen(_DIR_RACINE)); |
|
| 228 | + } |
|
| 229 | + if (preg_match("|^\w+_[\w_]+$|", $texte)) { |
|
| 230 | + $texte = _T(($module ? "$module:" : '') . $texte, array(), array('force' => false)); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + return propre($texte); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | |
| 237 | 237 | // http://code.spip.net/@affiche_bloc_plugin |
| 238 | 238 | function affiche_bloc_plugin($plug_file, $info, $dir_plugins = null) { |
| 239 | - if (!$dir_plugins) { |
|
| 240 | - $dir_plugins = _DIR_PLUGINS; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - $prefix = $info['prefix']; |
|
| 244 | - $dir = "$dir_plugins$plug_file/lang/paquet-$prefix"; |
|
| 245 | - |
|
| 246 | - $s = ""; |
|
| 247 | - // TODO: le traiter_multi ici n'est pas beau |
|
| 248 | - // cf. description du plugin/_stable_/ortho/plugin.xml |
|
| 249 | - $description = ""; |
|
| 250 | - if (isset($info['description'])) { |
|
| 251 | - $description = plugin_propre($info['description'], $dir); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - if (isset($info['documentation']) |
|
| 255 | - and $lien = $info['documentation'] |
|
| 256 | - ) { |
|
| 257 | - $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>'; |
|
| 258 | - } |
|
| 259 | - $s .= "<dd class='desc'>" . $description . "</dd>\n"; |
|
| 260 | - |
|
| 261 | - if (isset($info['auteur'])) { |
|
| 262 | - if (is_array($info['auteur'])) { |
|
| 263 | - $a = formater_credits($info['auteur'], ', '); |
|
| 264 | - } // pour compat mais ne doit plus arriver |
|
| 265 | - else { |
|
| 266 | - $a = trim($info['auteur']); |
|
| 267 | - } |
|
| 268 | - if ($a) { |
|
| 269 | - $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre($a, |
|
| 270 | - $dir)) . "</dd>\n"; |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - if (isset($info['credit'])) { |
|
| 275 | - if ($a = formater_credits($info['credit'], ', ')) { |
|
| 276 | - $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre($a, |
|
| 277 | - $dir)) . "</dd>\n"; |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - if (isset($info['licence'])) { |
|
| 282 | - if (is_array($info['licence'])) { |
|
| 283 | - $a = formater_credits($info['licence'], ', '); |
|
| 284 | - } // pour compat mais ne doit plus arriver |
|
| 285 | - else { |
|
| 286 | - $a = trim($info['licence']); |
|
| 287 | - } |
|
| 288 | - if ($a) { |
|
| 289 | - $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre($a, |
|
| 290 | - $dir)) . "</dd>\n"; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - $s = "<dl class='description'>$s</dl>"; |
|
| 295 | - |
|
| 296 | - // |
|
| 297 | - // Ajouter les infos techniques |
|
| 298 | - // |
|
| 299 | - $infotech = array(); |
|
| 300 | - |
|
| 301 | - $version = "<dt>" . _T('version') . "</dt><dd>" . $info['version']; |
|
| 302 | - // Version SVN |
|
| 303 | - if ($svn_revision = version_svn_courante($dir_plugins . $plug_file)) { |
|
| 304 | - $version .= ($svn_revision < 0 ? ' SVN' : '') . ' [' . abs($svn_revision) . ']'; |
|
| 305 | - } |
|
| 306 | - $version .= "</dd>"; |
|
| 307 | - $infotech[] = $version; |
|
| 308 | - $infotech[] = "<dt>" . _T('repertoire_plugins') . "</dt><dd>" . joli_repertoire("$dir_plugins$plug_file") . "</dd>"; |
|
| 309 | - // source zip le cas echeant |
|
| 310 | - $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log) |
|
| 311 | - and preg_match(',^source:(.*)$,m', $log, $r)) |
|
| 312 | - ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . "</dd>" |
|
| 313 | - : ''; |
|
| 314 | - |
|
| 315 | - $infotech[] = !$info['necessite'] ? '' : |
|
| 316 | - ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(' ', |
|
| 317 | - array_map('array_shift', $info['necessite'])) . '</dd>'); |
|
| 318 | - |
|
| 319 | - $s .= "<dl class='tech'>" |
|
| 320 | - . join('', $infotech) |
|
| 321 | - . "</dl>"; |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - return $s; |
|
| 239 | + if (!$dir_plugins) { |
|
| 240 | + $dir_plugins = _DIR_PLUGINS; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + $prefix = $info['prefix']; |
|
| 244 | + $dir = "$dir_plugins$plug_file/lang/paquet-$prefix"; |
|
| 245 | + |
|
| 246 | + $s = ""; |
|
| 247 | + // TODO: le traiter_multi ici n'est pas beau |
|
| 248 | + // cf. description du plugin/_stable_/ortho/plugin.xml |
|
| 249 | + $description = ""; |
|
| 250 | + if (isset($info['description'])) { |
|
| 251 | + $description = plugin_propre($info['description'], $dir); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + if (isset($info['documentation']) |
|
| 255 | + and $lien = $info['documentation'] |
|
| 256 | + ) { |
|
| 257 | + $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>'; |
|
| 258 | + } |
|
| 259 | + $s .= "<dd class='desc'>" . $description . "</dd>\n"; |
|
| 260 | + |
|
| 261 | + if (isset($info['auteur'])) { |
|
| 262 | + if (is_array($info['auteur'])) { |
|
| 263 | + $a = formater_credits($info['auteur'], ', '); |
|
| 264 | + } // pour compat mais ne doit plus arriver |
|
| 265 | + else { |
|
| 266 | + $a = trim($info['auteur']); |
|
| 267 | + } |
|
| 268 | + if ($a) { |
|
| 269 | + $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre($a, |
|
| 270 | + $dir)) . "</dd>\n"; |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + if (isset($info['credit'])) { |
|
| 275 | + if ($a = formater_credits($info['credit'], ', ')) { |
|
| 276 | + $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre($a, |
|
| 277 | + $dir)) . "</dd>\n"; |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + if (isset($info['licence'])) { |
|
| 282 | + if (is_array($info['licence'])) { |
|
| 283 | + $a = formater_credits($info['licence'], ', '); |
|
| 284 | + } // pour compat mais ne doit plus arriver |
|
| 285 | + else { |
|
| 286 | + $a = trim($info['licence']); |
|
| 287 | + } |
|
| 288 | + if ($a) { |
|
| 289 | + $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre($a, |
|
| 290 | + $dir)) . "</dd>\n"; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + $s = "<dl class='description'>$s</dl>"; |
|
| 295 | + |
|
| 296 | + // |
|
| 297 | + // Ajouter les infos techniques |
|
| 298 | + // |
|
| 299 | + $infotech = array(); |
|
| 300 | + |
|
| 301 | + $version = "<dt>" . _T('version') . "</dt><dd>" . $info['version']; |
|
| 302 | + // Version SVN |
|
| 303 | + if ($svn_revision = version_svn_courante($dir_plugins . $plug_file)) { |
|
| 304 | + $version .= ($svn_revision < 0 ? ' SVN' : '') . ' [' . abs($svn_revision) . ']'; |
|
| 305 | + } |
|
| 306 | + $version .= "</dd>"; |
|
| 307 | + $infotech[] = $version; |
|
| 308 | + $infotech[] = "<dt>" . _T('repertoire_plugins') . "</dt><dd>" . joli_repertoire("$dir_plugins$plug_file") . "</dd>"; |
|
| 309 | + // source zip le cas echeant |
|
| 310 | + $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log) |
|
| 311 | + and preg_match(',^source:(.*)$,m', $log, $r)) |
|
| 312 | + ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . "</dd>" |
|
| 313 | + : ''; |
|
| 314 | + |
|
| 315 | + $infotech[] = !$info['necessite'] ? '' : |
|
| 316 | + ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(' ', |
|
| 317 | + array_map('array_shift', $info['necessite'])) . '</dd>'); |
|
| 318 | + |
|
| 319 | + $s .= "<dl class='tech'>" |
|
| 320 | + . join('', $infotech) |
|
| 321 | + . "</dl>"; |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + return $s; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | function formater_credits($infos, $sep = ', ') { |
| 328 | - $texte = ''; |
|
| 329 | - |
|
| 330 | - foreach ($infos as $_credit) { |
|
| 331 | - if ($texte) { |
|
| 332 | - $texte .= $sep; |
|
| 333 | - } |
|
| 334 | - // Si le credit en cours n'est pas un array c'est donc un copyright |
|
| 335 | - $texte .= |
|
| 336 | - (!is_array($_credit)) |
|
| 337 | - ? PtoBR(propre($_credit)) |
|
| 338 | - : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 339 | - $_credit['nom'] . |
|
| 340 | - ($_credit['url'] ? '</a>' : ''); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - return $texte; |
|
| 328 | + $texte = ''; |
|
| 329 | + |
|
| 330 | + foreach ($infos as $_credit) { |
|
| 331 | + if ($texte) { |
|
| 332 | + $texte .= $sep; |
|
| 333 | + } |
|
| 334 | + // Si le credit en cours n'est pas un array c'est donc un copyright |
|
| 335 | + $texte .= |
|
| 336 | + (!is_array($_credit)) |
|
| 337 | + ? PtoBR(propre($_credit)) |
|
| 338 | + : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 339 | + $_credit['nom'] . |
|
| 340 | + ($_credit['url'] ? '</a>' : ''); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + return $texte; |
|
| 344 | 344 | } |
@@ -56,14 +56,14 @@ discard block |
||
| 56 | 56 | $class_li .= " error"; |
| 57 | 57 | $erreur = http_img_pack("plugin-err-32.png", _T('plugin_info_erreur_xml'), " class='picto_err'", |
| 58 | 58 | _T('plugin_info_erreur_xml')) |
| 59 | - . "<div class='erreur'>" . join('<br >', $info['erreur']) . "</div>"; |
|
| 59 | + . "<div class='erreur'>".join('<br >', $info['erreur'])."</div>"; |
|
| 60 | 60 | $checkable = false; |
| 61 | - } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) { |
|
| 61 | + } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file])) { |
|
| 62 | 62 | $class_li .= " error"; |
| 63 | 63 | $erreur = http_img_pack("plugin-err-32.png", _T('plugin_impossible_activer', array('plugin' => $nom)), |
| 64 | 64 | " class='picto_err'", _T('plugin_impossible_activer', array('plugin' => $nom))) |
| 65 | - . "<div class='erreur'>" . implode("<br />", |
|
| 66 | - $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file]) . "</div>"; |
|
| 65 | + . "<div class='erreur'>".implode("<br />", |
|
| 66 | + $GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file])."</div>"; |
|
| 67 | 67 | } else { |
| 68 | 68 | $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ""; |
| 69 | 69 | } |
@@ -71,11 +71,11 @@ discard block |
||
| 71 | 71 | // numerotons les occurrences d'un meme prefix |
| 72 | 72 | $versions[$prefix] = $id = isset($versions[$prefix]) ? $versions[$prefix] + 1 : ''; |
| 73 | 73 | |
| 74 | - $class_li .= ($actif ? " actif" : "") . ($expose ? " on" : ""); |
|
| 74 | + $class_li .= ($actif ? " actif" : "").($expose ? " on" : ""); |
|
| 75 | 75 | |
| 76 | 76 | return "<li id='$prefix$id' class='$class_li'>" |
| 77 | 77 | . ((!$checkable and !$checked) |
| 78 | - ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked)) |
|
| 78 | + ? '' : plugin_checkbox(++$id_input, $dir_plugins.$plug_file, $checked)) |
|
| 79 | 79 | . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
| 80 | 80 | . $cfg |
| 81 | 81 | . $erreur |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | $prefix = strtolower($infos['prefix']); |
| 94 | 94 | // si plugin.xml fournit un squelette, le prendre |
| 95 | 95 | if (isset($infos['config']) and $infos['config']) { |
| 96 | - return recuperer_fond("$dir$nom/" . $infos['config'], |
|
| 96 | + return recuperer_fond("$dir$nom/".$infos['config'], |
|
| 97 | 97 | array( |
| 98 | - 'script' => 'configurer_' . $prefix, |
|
| 98 | + 'script' => 'configurer_'.$prefix, |
|
| 99 | 99 | 'nom' => $nom |
| 100 | 100 | )); |
| 101 | 101 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | // sinon prendre le squelette std sur le nom std |
| 114 | 114 | return recuperer_fond("prive/squelettes/inclure/cfg", |
| 115 | 115 | array( |
| 116 | - 'script' => 'configurer_' . $prefix, |
|
| 116 | + 'script' => 'configurer_'.$prefix, |
|
| 117 | 117 | 'nom' => $nom |
| 118 | 118 | )); |
| 119 | 119 | } |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | . "<input type='checkbox' name='s$name' id='label_$id_input'" |
| 129 | 129 | . ($actif ? " checked='checked'" : "") |
| 130 | 130 | . " class='checkbox' value='O' />" |
| 131 | - . "\n<label for='label_$id_input'>" . _T('activer_plugin') . "</label>" |
|
| 131 | + . "\n<label for='label_$id_input'>"._T('activer_plugin')."</label>" |
|
| 132 | 132 | . "</div>"; |
| 133 | 133 | } |
| 134 | 134 | |
@@ -176,11 +176,11 @@ discard block |
||
| 176 | 176 | . "<h3><a href='$url' rel='info'>" |
| 177 | 177 | . $nom |
| 178 | 178 | . "</a></h3>" |
| 179 | - . " <span class='version'>" . $info['version'] . "</span>" |
|
| 179 | + . " <span class='version'>".$info['version']."</span>" |
|
| 180 | 180 | . " <span class='etat'> - " |
| 181 | 181 | . plugin_etat_en_clair($info['etat']) |
| 182 | 182 | . "</span>" |
| 183 | - . "<div class='short'>" . $slogan . "</div>" |
|
| 183 | + . "<div class='short'>".$slogan."</div>" |
|
| 184 | 184 | . $i |
| 185 | 185 | . "</div>"; |
| 186 | 186 | } |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | $text2 = _T('info_desinstaller_plugin'); |
| 196 | 196 | $file = basename($plug_file); |
| 197 | 197 | |
| 198 | - return "<div class='actions'>[" . |
|
| 198 | + return "<div class='actions'>[". |
|
| 199 | 199 | "<a href='$action' |
| 200 | 200 | onclick='return confirm(\"$text $nom ?\\n$text2\")'>" |
| 201 | 201 | . $text |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | $etat = 'developpement'; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - return _T('plugin_etat_' . $etat); |
|
| 220 | + return _T('plugin_etat_'.$etat); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | // http://code.spip.net/@plugin_propre |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | $module = substr($module, strlen(_DIR_RACINE)); |
| 228 | 228 | } |
| 229 | 229 | if (preg_match("|^\w+_[\w_]+$|", $texte)) { |
| 230 | - $texte = _T(($module ? "$module:" : '') . $texte, array(), array('force' => false)); |
|
| 230 | + $texte = _T(($module ? "$module:" : '').$texte, array(), array('force' => false)); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | return propre($texte); |
@@ -254,9 +254,9 @@ discard block |
||
| 254 | 254 | if (isset($info['documentation']) |
| 255 | 255 | and $lien = $info['documentation'] |
| 256 | 256 | ) { |
| 257 | - $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>'; |
|
| 257 | + $description .= "<p><em class='site'><a href='$lien' class='spip_out'>"._T('en_savoir_plus').'</a></em></p>'; |
|
| 258 | 258 | } |
| 259 | - $s .= "<dd class='desc'>" . $description . "</dd>\n"; |
|
| 259 | + $s .= "<dd class='desc'>".$description."</dd>\n"; |
|
| 260 | 260 | |
| 261 | 261 | if (isset($info['auteur'])) { |
| 262 | 262 | if (is_array($info['auteur'])) { |
@@ -266,15 +266,15 @@ discard block |
||
| 266 | 266 | $a = trim($info['auteur']); |
| 267 | 267 | } |
| 268 | 268 | if ($a) { |
| 269 | - $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre($a, |
|
| 270 | - $dir)) . "</dd>\n"; |
|
| 269 | + $s .= "<dt class='auteurs'>"._T('public:par_auteur')."</dt><dd class='auteurs'>".PtoBR(propre($a, |
|
| 270 | + $dir))."</dd>\n"; |
|
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | if (isset($info['credit'])) { |
| 275 | 275 | if ($a = formater_credits($info['credit'], ', ')) { |
| 276 | - $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre($a, |
|
| 277 | - $dir)) . "</dd>\n"; |
|
| 276 | + $s .= "<dt class='credits'>"._T('plugin_info_credit')."</dt><dd class='credits'>".PtoBR(propre($a, |
|
| 277 | + $dir))."</dd>\n"; |
|
| 278 | 278 | } |
| 279 | 279 | } |
| 280 | 280 | |
@@ -286,8 +286,8 @@ discard block |
||
| 286 | 286 | $a = trim($info['licence']); |
| 287 | 287 | } |
| 288 | 288 | if ($a) { |
| 289 | - $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre($a, |
|
| 290 | - $dir)) . "</dd>\n"; |
|
| 289 | + $s .= "<dt class='licence'>"._T('intitule_licence')."</dt><dd class='licence'>".PtoBR(propre($a, |
|
| 290 | + $dir))."</dd>\n"; |
|
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | |
@@ -298,23 +298,22 @@ discard block |
||
| 298 | 298 | // |
| 299 | 299 | $infotech = array(); |
| 300 | 300 | |
| 301 | - $version = "<dt>" . _T('version') . "</dt><dd>" . $info['version']; |
|
| 301 | + $version = "<dt>"._T('version')."</dt><dd>".$info['version']; |
|
| 302 | 302 | // Version SVN |
| 303 | - if ($svn_revision = version_svn_courante($dir_plugins . $plug_file)) { |
|
| 304 | - $version .= ($svn_revision < 0 ? ' SVN' : '') . ' [' . abs($svn_revision) . ']'; |
|
| 303 | + if ($svn_revision = version_svn_courante($dir_plugins.$plug_file)) { |
|
| 304 | + $version .= ($svn_revision < 0 ? ' SVN' : '').' ['.abs($svn_revision).']'; |
|
| 305 | 305 | } |
| 306 | 306 | $version .= "</dd>"; |
| 307 | 307 | $infotech[] = $version; |
| 308 | - $infotech[] = "<dt>" . _T('repertoire_plugins') . "</dt><dd>" . joli_repertoire("$dir_plugins$plug_file") . "</dd>"; |
|
| 308 | + $infotech[] = "<dt>"._T('repertoire_plugins')."</dt><dd>".joli_repertoire("$dir_plugins$plug_file")."</dd>"; |
|
| 309 | 309 | // source zip le cas echeant |
| 310 | - $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log) |
|
| 310 | + $infotech[] = (lire_fichier($dir_plugins.$plug_file.'/install.log', $log) |
|
| 311 | 311 | and preg_match(',^source:(.*)$,m', $log, $r)) |
| 312 | - ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . "</dd>" |
|
| 312 | + ? '<dt>'._T('plugin_source').'</dt><dd>'.trim($r[1])."</dd>" |
|
| 313 | 313 | : ''; |
| 314 | 314 | |
| 315 | - $infotech[] = !$info['necessite'] ? '' : |
|
| 316 | - ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(' ', |
|
| 317 | - array_map('array_shift', $info['necessite'])) . '</dd>'); |
|
| 315 | + $infotech[] = !$info['necessite'] ? '' : ('<dt>'._T('plugin_info_necessite').'</dt><dd>'.join(' ', |
|
| 316 | + array_map('array_shift', $info['necessite'])).'</dd>'); |
|
| 318 | 317 | |
| 319 | 318 | $s .= "<dl class='tech'>" |
| 320 | 319 | . join('', $infotech) |
@@ -335,8 +334,8 @@ discard block |
||
| 335 | 334 | $texte .= |
| 336 | 335 | (!is_array($_credit)) |
| 337 | 336 | ? PtoBR(propre($_credit)) |
| 338 | - : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 339 | - $_credit['nom'] . |
|
| 337 | + : ($_credit['url'] ? '<a href="'.$_credit['url'].'">' : ''). |
|
| 338 | + $_credit['nom']. |
|
| 340 | 339 | ($_credit['url'] ? '</a>' : ''); |
| 341 | 340 | } |
| 342 | 341 | |
@@ -102,10 +102,12 @@ |
||
| 102 | 102 | |
| 103 | 103 | // si le plugin CFG est la, l'essayer |
| 104 | 104 | if (defined('_DIR_PLUGIN_CFG')) { |
| 105 | - if (include_spip('inc/cfg')) // test CFG version >= 1.0.5 |
|
| 105 | + if (include_spip('inc/cfg')) { |
|
| 106 | + // test CFG version >= 1.0.5 |
|
| 106 | 107 | { |
| 107 | 108 | if ($cfg = icone_lien_cfg("$dir$nom", "cfg")) { |
| 108 | 109 | return "<div class='cfg_link'>$cfg</div>"; |
| 110 | + } |
|
| 109 | 111 | } |
| 110 | 112 | } |
| 111 | 113 | } |
@@ -75,11 +75,19 @@ |
||
| 75 | 75 | // vraiment n'importe quoi la gestion des chemins des plugins |
| 76 | 76 | // une fonction pour aider... |
| 77 | 77 | // http://code.spip.net/@chemin_plug |
| 78 | +/** |
|
| 79 | + * @param string $racine |
|
| 80 | + * |
|
| 81 | + * @return string |
|
| 82 | + */ |
|
| 78 | 83 | function chemin_plug($racine, $plug) { |
| 79 | 84 | return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
| 80 | 85 | } |
| 81 | 86 | |
| 82 | 87 | // http://code.spip.net/@tree_open_close_dir |
| 88 | +/** |
|
| 89 | + * @param string $target |
|
| 90 | + */ |
|
| 83 | 91 | function tree_open_close_dir(&$current, $target, $deplie = array()) { |
| 84 | 92 | if ($current == $target) { |
| 85 | 93 | return ""; |
@@ -11,64 +11,64 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // http://code.spip.net/@affiche_arbre_plugins |
| 18 | 18 | function plugins_afficher_repertoires_dist($url_page, $liste_plugins, $liste_plugins_actifs) { |
| 19 | - $ligne_plug = charger_fonction('afficher_plugin', 'plugins'); |
|
| 20 | - $racine = basename(_DIR_PLUGINS); |
|
| 21 | - $init_dir = $current_dir = ""; |
|
| 22 | - // liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif |
|
| 23 | - // des qu'un path est deja note deplie on s'arrete |
|
| 24 | - $deplie = array($racine => true); |
|
| 25 | - $fast_liste_plugins_actifs = array(); |
|
| 26 | - foreach ($liste_plugins_actifs as $key => $plug) { |
|
| 27 | - $chemin_plug = chemin_plug($racine, $plug); |
|
| 28 | - $fast_liste_plugins_actifs[$chemin_plug] = true; |
|
| 29 | - $dir = dirname($chemin_plug); |
|
| 30 | - $maxiter = 100; |
|
| 31 | - while (strlen($dir) && !isset($deplie[$dir]) && $dir != $racine && $maxiter-- > 0) { |
|
| 32 | - $deplie[$dir] = true; |
|
| 33 | - $dir = dirname($dir); |
|
| 34 | - } |
|
| 35 | - } |
|
| 19 | + $ligne_plug = charger_fonction('afficher_plugin', 'plugins'); |
|
| 20 | + $racine = basename(_DIR_PLUGINS); |
|
| 21 | + $init_dir = $current_dir = ""; |
|
| 22 | + // liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif |
|
| 23 | + // des qu'un path est deja note deplie on s'arrete |
|
| 24 | + $deplie = array($racine => true); |
|
| 25 | + $fast_liste_plugins_actifs = array(); |
|
| 26 | + foreach ($liste_plugins_actifs as $key => $plug) { |
|
| 27 | + $chemin_plug = chemin_plug($racine, $plug); |
|
| 28 | + $fast_liste_plugins_actifs[$chemin_plug] = true; |
|
| 29 | + $dir = dirname($chemin_plug); |
|
| 30 | + $maxiter = 100; |
|
| 31 | + while (strlen($dir) && !isset($deplie[$dir]) && $dir != $racine && $maxiter-- > 0) { |
|
| 32 | + $deplie[$dir] = true; |
|
| 33 | + $dir = dirname($dir); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - // index repertoires --> plugin |
|
| 38 | - $dir_index = array(); |
|
| 39 | - foreach ($liste_plugins as $key => $plug) { |
|
| 40 | - $liste_plugins[$key] = chemin_plug($racine, $plug); |
|
| 41 | - $dir_index[dirname($liste_plugins[$key])][] = $key; |
|
| 42 | - } |
|
| 37 | + // index repertoires --> plugin |
|
| 38 | + $dir_index = array(); |
|
| 39 | + foreach ($liste_plugins as $key => $plug) { |
|
| 40 | + $liste_plugins[$key] = chemin_plug($racine, $plug); |
|
| 41 | + $dir_index[dirname($liste_plugins[$key])][] = $key; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - $visible = @isset($deplie[$current_dir]); |
|
| 45 | - $maxiter = 1000; |
|
| 44 | + $visible = @isset($deplie[$current_dir]); |
|
| 45 | + $maxiter = 1000; |
|
| 46 | 46 | |
| 47 | - $res = ''; |
|
| 48 | - while (count($liste_plugins) && $maxiter--) { |
|
| 49 | - // le rep suivant |
|
| 50 | - $dir = dirname(reset($liste_plugins)); |
|
| 51 | - if ($dir != $current_dir) { |
|
| 52 | - $res .= tree_open_close_dir($current_dir, $dir, $deplie); |
|
| 53 | - } |
|
| 47 | + $res = ''; |
|
| 48 | + while (count($liste_plugins) && $maxiter--) { |
|
| 49 | + // le rep suivant |
|
| 50 | + $dir = dirname(reset($liste_plugins)); |
|
| 51 | + if ($dir != $current_dir) { |
|
| 52 | + $res .= tree_open_close_dir($current_dir, $dir, $deplie); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - // d'abord tous les plugins du rep courant |
|
| 56 | - if (isset($dir_index[$current_dir])) { |
|
| 57 | - foreach ($dir_index[$current_dir] as $key) { |
|
| 58 | - $plug = $liste_plugins[$key]; |
|
| 59 | - $actif = @isset($fast_liste_plugins_actifs[$plug]); |
|
| 60 | - $id = substr(md5($plug), 0, 16); |
|
| 61 | - $res .= $ligne_plug($url_page, str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), $actif, |
|
| 62 | - 'menu-entree') . "\n"; |
|
| 63 | - unset($liste_plugins[$key]); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - $res .= tree_open_close_dir($current_dir, $init_dir, true); |
|
| 55 | + // d'abord tous les plugins du rep courant |
|
| 56 | + if (isset($dir_index[$current_dir])) { |
|
| 57 | + foreach ($dir_index[$current_dir] as $key) { |
|
| 58 | + $plug = $liste_plugins[$key]; |
|
| 59 | + $actif = @isset($fast_liste_plugins_actifs[$plug]); |
|
| 60 | + $id = substr(md5($plug), 0, 16); |
|
| 61 | + $res .= $ligne_plug($url_page, str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), $actif, |
|
| 62 | + 'menu-entree') . "\n"; |
|
| 63 | + unset($liste_plugins[$key]); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + $res .= tree_open_close_dir($current_dir, $init_dir, true); |
|
| 68 | 68 | |
| 69 | - return "<ul class='menu-liste plugins'>" |
|
| 70 | - . $res |
|
| 71 | - . "</ul>"; |
|
| 69 | + return "<ul class='menu-liste plugins'>" |
|
| 70 | + . $res |
|
| 71 | + . "</ul>"; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | |
@@ -76,44 +76,44 @@ discard block |
||
| 76 | 76 | // une fonction pour aider... |
| 77 | 77 | // http://code.spip.net/@chemin_plug |
| 78 | 78 | function chemin_plug($racine, $plug) { |
| 79 | - return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
|
| 79 | + return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | // http://code.spip.net/@tree_open_close_dir |
| 83 | 83 | function tree_open_close_dir(&$current, $target, $deplie = array()) { |
| 84 | - if ($current == $target) { |
|
| 85 | - return ""; |
|
| 86 | - } |
|
| 87 | - $tcur = explode("/", $current); |
|
| 88 | - $ttarg = explode("/", $target); |
|
| 89 | - $tcom = array(); |
|
| 90 | - $output = ""; |
|
| 91 | - // la partie commune |
|
| 92 | - while (reset($tcur) == reset($ttarg)) { |
|
| 93 | - $tcom[] = array_shift($tcur); |
|
| 94 | - array_shift($ttarg); |
|
| 95 | - } |
|
| 96 | - // fermer les repertoires courant jusqu'au point de fork |
|
| 97 | - while ($close = array_pop($tcur)) { |
|
| 98 | - $output .= "</ul>\n"; |
|
| 99 | - $output .= fin_block(); |
|
| 100 | - $output .= "</li>\n"; |
|
| 101 | - } |
|
| 102 | - $chemin = ""; |
|
| 103 | - if (count($tcom)) { |
|
| 104 | - $chemin .= implode("/", $tcom) . "/"; |
|
| 105 | - } |
|
| 106 | - // ouvrir les repertoires jusqu'a la cible |
|
| 107 | - while ($open = array_shift($ttarg)) { |
|
| 108 | - $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | - $chemin .= $open . "/"; |
|
| 110 | - $output .= "<li>"; |
|
| 111 | - $output .= bouton_block_depliable($chemin, $visible); |
|
| 112 | - $output .= debut_block_depliable($visible); |
|
| 84 | + if ($current == $target) { |
|
| 85 | + return ""; |
|
| 86 | + } |
|
| 87 | + $tcur = explode("/", $current); |
|
| 88 | + $ttarg = explode("/", $target); |
|
| 89 | + $tcom = array(); |
|
| 90 | + $output = ""; |
|
| 91 | + // la partie commune |
|
| 92 | + while (reset($tcur) == reset($ttarg)) { |
|
| 93 | + $tcom[] = array_shift($tcur); |
|
| 94 | + array_shift($ttarg); |
|
| 95 | + } |
|
| 96 | + // fermer les repertoires courant jusqu'au point de fork |
|
| 97 | + while ($close = array_pop($tcur)) { |
|
| 98 | + $output .= "</ul>\n"; |
|
| 99 | + $output .= fin_block(); |
|
| 100 | + $output .= "</li>\n"; |
|
| 101 | + } |
|
| 102 | + $chemin = ""; |
|
| 103 | + if (count($tcom)) { |
|
| 104 | + $chemin .= implode("/", $tcom) . "/"; |
|
| 105 | + } |
|
| 106 | + // ouvrir les repertoires jusqu'a la cible |
|
| 107 | + while ($open = array_shift($ttarg)) { |
|
| 108 | + $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | + $chemin .= $open . "/"; |
|
| 110 | + $output .= "<li>"; |
|
| 111 | + $output .= bouton_block_depliable($chemin, $visible); |
|
| 112 | + $output .= debut_block_depliable($visible); |
|
| 113 | 113 | |
| 114 | - $output .= "<ul>\n"; |
|
| 115 | - } |
|
| 116 | - $current = $target; |
|
| 114 | + $output .= "<ul>\n"; |
|
| 115 | + } |
|
| 116 | + $current = $target; |
|
| 117 | 117 | |
| 118 | - return $output; |
|
| 118 | + return $output; |
|
| 119 | 119 | } |
@@ -58,8 +58,8 @@ discard block |
||
| 58 | 58 | $plug = $liste_plugins[$key]; |
| 59 | 59 | $actif = @isset($fast_liste_plugins_actifs[$plug]); |
| 60 | 60 | $id = substr(md5($plug), 0, 16); |
| 61 | - $res .= $ligne_plug($url_page, str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), $actif, |
|
| 62 | - 'menu-entree') . "\n"; |
|
| 61 | + $res .= $ligne_plug($url_page, str_replace(_DIR_PLUGINS, '', _DIR_RACINE.$plug), $actif, |
|
| 62 | + 'menu-entree')."\n"; |
|
| 63 | 63 | unset($liste_plugins[$key]); |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -101,12 +101,12 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | $chemin = ""; |
| 103 | 103 | if (count($tcom)) { |
| 104 | - $chemin .= implode("/", $tcom) . "/"; |
|
| 104 | + $chemin .= implode("/", $tcom)."/"; |
|
| 105 | 105 | } |
| 106 | 106 | // ouvrir les repertoires jusqu'a la cible |
| 107 | 107 | while ($open = array_shift($ttarg)) { |
| 108 | - $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | - $chemin .= $open . "/"; |
|
| 108 | + $visible = @isset($deplie[$chemin.$open]); |
|
| 109 | + $chemin .= $open."/"; |
|
| 110 | 110 | $output .= "<li>"; |
| 111 | 111 | $output .= bouton_block_depliable($chemin, $visible); |
| 112 | 112 | $output .= debut_block_depliable($visible); |