@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | array_shift($p->param); |
| 53 | 53 | $p->etoile = '*'; |
| 54 | 54 | spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
| 55 | - } elseif (preg_match('/^' . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 55 | + } elseif (preg_match('/^'.NOM_DE_CHAMP.'(.*)$/sS', $nom, $m)) { |
|
| 56 | 56 | $champ = new Champ(); |
| 57 | 57 | $champ->nom_boucle = $m[2]; |
| 58 | 58 | $champ->nom_champ = $m[3]; |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | $p->param[0][1] = [$c]; |
| 129 | 129 | $p->param[0][0] = ''; |
| 130 | 130 | $p->fonctions = []; |
| 131 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 131 | + spip_log('FORMULAIRE_RECHERCHE avec filtre '.$c->texte, 'vieilles_defs'); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Les fonctions de ce fichier sont appelees en certains points |
@@ -25,193 +25,193 @@ discard block |
||
| 25 | 25 | // -> https://www.spip.net/fr_article901.html |
| 26 | 26 | |
| 27 | 27 | function phraser_vieux_logos(&$p) { |
| 28 | - if ($p->param[0][0]) { |
|
| 29 | - $args = ['']; |
|
| 30 | - } else { |
|
| 31 | - $args = array_shift($p->param); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - foreach ($p->param as $couple) { |
|
| 35 | - $nom = trim($couple[0]); |
|
| 36 | - if ($nom == '') { |
|
| 37 | - array_shift($p->param); |
|
| 38 | - break; |
|
| 39 | - } |
|
| 40 | - $r = phraser_logo_faux_filtres($nom); |
|
| 41 | - if ($r === 0) { |
|
| 42 | - $c = new Texte(); |
|
| 43 | - $c->texte = $nom; |
|
| 44 | - $args[] = [$c]; |
|
| 45 | - array_shift($p->param); |
|
| 46 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | - } elseif ($r === 2) { |
|
| 48 | - $p->etoile = '**'; |
|
| 49 | - array_shift($p->param); |
|
| 50 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | - } elseif ($r === 1) { |
|
| 52 | - array_shift($p->param); |
|
| 53 | - $p->etoile = '*'; |
|
| 54 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 55 | - } elseif (preg_match('/^' . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 56 | - $champ = new Champ(); |
|
| 57 | - $champ->nom_boucle = $m[2]; |
|
| 58 | - $champ->nom_champ = $m[3]; |
|
| 59 | - $champ->etoile = $m[5]; |
|
| 60 | - $champ = [$champ]; |
|
| 61 | - if ($m[6]) { |
|
| 62 | - $r = new Texte(); |
|
| 63 | - $r->texte = $m[6]; |
|
| 64 | - $champ[] = $r; |
|
| 65 | - } |
|
| 66 | - $args[] = $champ; |
|
| 67 | - array_shift($p->param); |
|
| 68 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 69 | - } // le cas else est la seule incompatibilite |
|
| 70 | - } |
|
| 71 | - array_unshift($p->param, $args); |
|
| 28 | + if ($p->param[0][0]) { |
|
| 29 | + $args = ['']; |
|
| 30 | + } else { |
|
| 31 | + $args = array_shift($p->param); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + foreach ($p->param as $couple) { |
|
| 35 | + $nom = trim($couple[0]); |
|
| 36 | + if ($nom == '') { |
|
| 37 | + array_shift($p->param); |
|
| 38 | + break; |
|
| 39 | + } |
|
| 40 | + $r = phraser_logo_faux_filtres($nom); |
|
| 41 | + if ($r === 0) { |
|
| 42 | + $c = new Texte(); |
|
| 43 | + $c->texte = $nom; |
|
| 44 | + $args[] = [$c]; |
|
| 45 | + array_shift($p->param); |
|
| 46 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | + } elseif ($r === 2) { |
|
| 48 | + $p->etoile = '**'; |
|
| 49 | + array_shift($p->param); |
|
| 50 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | + } elseif ($r === 1) { |
|
| 52 | + array_shift($p->param); |
|
| 53 | + $p->etoile = '*'; |
|
| 54 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 55 | + } elseif (preg_match('/^' . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 56 | + $champ = new Champ(); |
|
| 57 | + $champ->nom_boucle = $m[2]; |
|
| 58 | + $champ->nom_champ = $m[3]; |
|
| 59 | + $champ->etoile = $m[5]; |
|
| 60 | + $champ = [$champ]; |
|
| 61 | + if ($m[6]) { |
|
| 62 | + $r = new Texte(); |
|
| 63 | + $r->texte = $m[6]; |
|
| 64 | + $champ[] = $r; |
|
| 65 | + } |
|
| 66 | + $args[] = $champ; |
|
| 67 | + array_shift($p->param); |
|
| 68 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 69 | + } // le cas else est la seule incompatibilite |
|
| 70 | + } |
|
| 71 | + array_unshift($p->param, $args); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | function phraser_logo_faux_filtres($nom) { |
| 76 | - switch ($nom) { |
|
| 77 | - case 'top': |
|
| 78 | - case 'left': |
|
| 79 | - case 'right': |
|
| 80 | - case 'center': |
|
| 81 | - case 'bottom': |
|
| 82 | - return 0; |
|
| 83 | - case 'lien': |
|
| 84 | - return 1; |
|
| 85 | - case 'fichier': |
|
| 86 | - return 2; |
|
| 87 | - default: |
|
| 88 | - return $nom; |
|
| 89 | - } |
|
| 76 | + switch ($nom) { |
|
| 77 | + case 'top': |
|
| 78 | + case 'left': |
|
| 79 | + case 'right': |
|
| 80 | + case 'center': |
|
| 81 | + case 'bottom': |
|
| 82 | + return 0; |
|
| 83 | + case 'lien': |
|
| 84 | + return 1; |
|
| 85 | + case 'fichier': |
|
| 86 | + return 2; |
|
| 87 | + default: |
|
| 88 | + return $nom; |
|
| 89 | + } |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | |
| 93 | 93 | // La balise embed_document est a present le modele emb |
| 94 | 94 | |
| 95 | 95 | function phraser_vieux_emb(&$p) { |
| 96 | - if (!is_array($p->param)) { |
|
| 97 | - $p->param = []; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - // Produire le premier argument {emb} |
|
| 101 | - $texte = new Texte(); |
|
| 102 | - $texte->texte = 'emb'; |
|
| 103 | - $param = ['', [$texte]]; |
|
| 104 | - |
|
| 105 | - // Transformer les filtres en arguments |
|
| 106 | - for ($i = 0; $i < (is_countable($p->param) ? count($p->param) : 0); $i++) { |
|
| 107 | - if ($p->param[$i][0]) { |
|
| 108 | - if (!strstr($p->param[$i][0], '=')) { |
|
| 109 | - break; |
|
| 110 | - }# on a rencontre un vrai filtre, c'est fini |
|
| 111 | - $texte = new Texte(); |
|
| 112 | - $texte->texte = $p->param[$i][0]; |
|
| 113 | - $param[] = [$texte]; |
|
| 114 | - } |
|
| 115 | - array_shift($p->param); |
|
| 116 | - } |
|
| 117 | - array_unshift($p->param, $param); |
|
| 118 | - spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 119 | - $p->nom_champ = 'MODELE'; |
|
| 96 | + if (!is_array($p->param)) { |
|
| 97 | + $p->param = []; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // Produire le premier argument {emb} |
|
| 101 | + $texte = new Texte(); |
|
| 102 | + $texte->texte = 'emb'; |
|
| 103 | + $param = ['', [$texte]]; |
|
| 104 | + |
|
| 105 | + // Transformer les filtres en arguments |
|
| 106 | + for ($i = 0; $i < (is_countable($p->param) ? count($p->param) : 0); $i++) { |
|
| 107 | + if ($p->param[$i][0]) { |
|
| 108 | + if (!strstr($p->param[$i][0], '=')) { |
|
| 109 | + break; |
|
| 110 | + }# on a rencontre un vrai filtre, c'est fini |
|
| 111 | + $texte = new Texte(); |
|
| 112 | + $texte->texte = $p->param[$i][0]; |
|
| 113 | + $param[] = [$texte]; |
|
| 114 | + } |
|
| 115 | + array_shift($p->param); |
|
| 116 | + } |
|
| 117 | + array_unshift($p->param, $param); |
|
| 118 | + spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 119 | + $p->nom_champ = 'MODELE'; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // Vieux formulaire de recherch |
| 123 | 123 | |
| 124 | 124 | function phraser_vieux_recherche($p) { |
| 125 | - if ($p->param[0][0]) { |
|
| 126 | - $c = new Texte(); |
|
| 127 | - $c->texte = $p->param[0][0]; |
|
| 128 | - $p->param[0][1] = [$c]; |
|
| 129 | - $p->param[0][0] = ''; |
|
| 130 | - $p->fonctions = []; |
|
| 131 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 132 | - } |
|
| 125 | + if ($p->param[0][0]) { |
|
| 126 | + $c = new Texte(); |
|
| 127 | + $c->texte = $p->param[0][0]; |
|
| 128 | + $p->param[0][1] = [$c]; |
|
| 129 | + $p->param[0][0] = ''; |
|
| 130 | + $p->fonctions = []; |
|
| 131 | + spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 132 | + } |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | // Gerer la notation [(#EXPOSER|on,off)] |
| 136 | 136 | function phraser_vieux_exposer($p) { |
| 137 | - if ($a = $p->fonctions) { |
|
| 138 | - preg_match('#([^,]*)(,(.*))?#', $a[0][0], $regs); |
|
| 139 | - $args = []; |
|
| 140 | - if ($regs[1]) { |
|
| 141 | - $a = new Texte(); |
|
| 142 | - $a->texte = $regs[1]; |
|
| 143 | - $args = ['', [$a]]; |
|
| 144 | - if ($regs[3]) { |
|
| 145 | - $a = new Texte(); |
|
| 146 | - $a->texte = $regs[3]; |
|
| 147 | - $args[] = [$a]; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - $p->param[0] = $args; |
|
| 151 | - $p->fonctions = []; |
|
| 152 | - $p->nom_champ = 'EXPOSE'; |
|
| 153 | - } |
|
| 137 | + if ($a = $p->fonctions) { |
|
| 138 | + preg_match('#([^,]*)(,(.*))?#', $a[0][0], $regs); |
|
| 139 | + $args = []; |
|
| 140 | + if ($regs[1]) { |
|
| 141 | + $a = new Texte(); |
|
| 142 | + $a->texte = $regs[1]; |
|
| 143 | + $args = ['', [$a]]; |
|
| 144 | + if ($regs[3]) { |
|
| 145 | + $a = new Texte(); |
|
| 146 | + $a->texte = $regs[3]; |
|
| 147 | + $args[] = [$a]; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + $p->param[0] = $args; |
|
| 151 | + $p->fonctions = []; |
|
| 152 | + $p->nom_champ = 'EXPOSE'; |
|
| 153 | + } |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | function phraser_vieux_modele($p) { |
| 157 | - normaliser_args_inclumodel($p); |
|
| 157 | + normaliser_args_inclumodel($p); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | function phraser_vieux_inclu($p) { |
| 161 | - normaliser_args_inclumodel($p); |
|
| 161 | + normaliser_args_inclumodel($p); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | function normaliser_args_inclumodel($p) { |
| 165 | - $params = $p->param; |
|
| 166 | - if (!$params) { |
|
| 167 | - return; |
|
| 168 | - } |
|
| 169 | - $args = $params[0]; |
|
| 170 | - if ($args[0]) { |
|
| 171 | - return; |
|
| 172 | - } // filtre immediat |
|
| 173 | - array_shift($p->param); |
|
| 174 | - foreach ($p->param as $l) { |
|
| 175 | - if (!array_shift($l)) { |
|
| 176 | - $args = array_merge($args, $l); |
|
| 177 | - array_shift($p->param); |
|
| 178 | - } else { |
|
| 179 | - break; |
|
| 180 | - } // filtre |
|
| 181 | - } |
|
| 182 | - array_unshift($p->param, $args); |
|
| 165 | + $params = $p->param; |
|
| 166 | + if (!$params) { |
|
| 167 | + return; |
|
| 168 | + } |
|
| 169 | + $args = $params[0]; |
|
| 170 | + if ($args[0]) { |
|
| 171 | + return; |
|
| 172 | + } // filtre immediat |
|
| 173 | + array_shift($p->param); |
|
| 174 | + foreach ($p->param as $l) { |
|
| 175 | + if (!array_shift($l)) { |
|
| 176 | + $args = array_merge($args, $l); |
|
| 177 | + array_shift($p->param); |
|
| 178 | + } else { |
|
| 179 | + break; |
|
| 180 | + } // filtre |
|
| 181 | + } |
|
| 182 | + array_unshift($p->param, $args); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | function normaliser_inclure($champ) { |
| 186 | - normaliser_args_inclumodel($champ); |
|
| 187 | - $l = $champ->param[0]; |
|
| 188 | - if (is_array($l) and !$l[0]) { |
|
| 189 | - foreach ($l as $k => $p) { |
|
| 190 | - if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 191 | - $p[0]->texte = trim($p[0]->texte); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - foreach ($l as $k => $p) { |
|
| 195 | - if ( |
|
| 196 | - !$p or $p[0]->type != 'texte' or |
|
| 197 | - !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 198 | - ) { |
|
| 199 | - continue; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - if ($r[1]) { |
|
| 203 | - $p[0]->texte = $r[1]; |
|
| 204 | - } else { |
|
| 205 | - unset($p[0]); |
|
| 206 | - } |
|
| 207 | - $champ->texte = $p; |
|
| 208 | - unset($champ->param[0][$k]); |
|
| 209 | - if ((is_countable($champ->param[0]) ? count($champ->param[0]) : 0) == 1) { |
|
| 210 | - array_shift($champ->param); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - return; |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - spip_log('inclure sans fond ni fichier'); |
|
| 186 | + normaliser_args_inclumodel($champ); |
|
| 187 | + $l = $champ->param[0]; |
|
| 188 | + if (is_array($l) and !$l[0]) { |
|
| 189 | + foreach ($l as $k => $p) { |
|
| 190 | + if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 191 | + $p[0]->texte = trim($p[0]->texte); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + foreach ($l as $k => $p) { |
|
| 195 | + if ( |
|
| 196 | + !$p or $p[0]->type != 'texte' or |
|
| 197 | + !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 198 | + ) { |
|
| 199 | + continue; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + if ($r[1]) { |
|
| 203 | + $p[0]->texte = $r[1]; |
|
| 204 | + } else { |
|
| 205 | + unset($p[0]); |
|
| 206 | + } |
|
| 207 | + $champ->texte = $p; |
|
| 208 | + unset($champ->param[0][$k]); |
|
| 209 | + if ((is_countable($champ->param[0]) ? count($champ->param[0]) : 0) == 1) { |
|
| 210 | + array_shift($champ->param); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + return; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + spip_log('inclure sans fond ni fichier'); |
|
| 217 | 217 | } |
@@ -207,8 +207,7 @@ discard block |
||
| 207 | 207 | $pagination['type_pagination'] = $modele; |
| 208 | 208 | if (trouver_fond('pagination_' . $modele, 'modeles')) { |
| 209 | 209 | $modele = '_' . $modele; |
| 210 | - } |
|
| 211 | - else { |
|
| 210 | + } else { |
|
| 212 | 211 | $modele = ''; |
| 213 | 212 | } |
| 214 | 213 | } |
@@ -295,8 +294,7 @@ discard block |
||
| 295 | 294 | if ($ids) { |
| 296 | 295 | $ids = array_column($ids, 'id_objet'); |
| 297 | 296 | return implode(',', $ids); |
| 298 | - } |
|
| 299 | - else { |
|
| 297 | + } else { |
|
| 300 | 298 | return '0'; |
| 301 | 299 | } |
| 302 | 300 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $texte = $intro; |
| 85 | 85 | } else { |
| 86 | 86 | if ( |
| 87 | - strpos("\n" . $texte, "\n|") === false |
|
| 87 | + strpos("\n".$texte, "\n|") === false |
|
| 88 | 88 | and strlen($texte) > 2.5 * $longueur |
| 89 | 89 | ) { |
| 90 | 90 | if (strpos($texte, '<multi') !== false) { |
@@ -168,12 +168,12 @@ discard block |
||
| 168 | 168 | if ($pas < 1) { |
| 169 | 169 | return ''; |
| 170 | 170 | } |
| 171 | - $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 172 | - $debut = 'debut' . $nom; // 'debut_articles' |
|
| 171 | + $ancre = 'pagination'.$nom; // #pagination_articles |
|
| 172 | + $debut = 'debut'.$nom; // 'debut_articles' |
|
| 173 | 173 | |
| 174 | 174 | // n'afficher l'ancre qu'une fois |
| 175 | 175 | if (!isset($ancres[$ancre])) { |
| 176 | - $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 176 | + $bloc_ancre = $ancres[$ancre] = "<a id='".$ancre."' class='pagination_ancre'></a>"; |
|
| 177 | 177 | } else { |
| 178 | 178 | $bloc_ancre = ''; |
| 179 | 179 | } |
@@ -205,8 +205,8 @@ discard block |
||
| 205 | 205 | |
| 206 | 206 | if ($modele) { |
| 207 | 207 | $pagination['type_pagination'] = $modele; |
| 208 | - if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 209 | - $modele = '_' . $modele; |
|
| 208 | + if (trouver_fond('pagination_'.$modele, 'modeles')) { |
|
| 209 | + $modele = '_'.$modele; |
|
| 210 | 210 | } |
| 211 | 211 | else { |
| 212 | 212 | $modele = ''; |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | function lister_objets_avec_logos($type) { |
| 292 | 292 | |
| 293 | 293 | $objet = objet_type($type); |
| 294 | - $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet)); |
|
| 294 | + $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode='.sql_quote('logoon').' AND L.objet='.sql_quote($objet)); |
|
| 295 | 295 | if ($ids) { |
| 296 | 296 | $ids = array_column($ids, 'id_objet'); |
| 297 | 297 | return implode(',', $ids); |
@@ -484,7 +484,7 @@ discard block |
||
| 484 | 484 | |
| 485 | 485 | // Classes : on indique le sens de tri et l'item exposé |
| 486 | 486 | if (!$is_sens_fixe) { |
| 487 | - $classe .= ' item-tri item-tri_' . ($tri_sens_actuel === 1 ? 'asc' : 'desc'); |
|
| 487 | + $classe .= ' item-tri item-tri_'.($tri_sens_actuel === 1 ? 'asc' : 'desc'); |
|
| 488 | 488 | } |
| 489 | 489 | if ($champ_ou_sens === $tri_champ) { |
| 490 | 490 | $classe .= ' item-tri_actif'; |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | */ |
| 524 | 524 | function tri_champ_order($t, $from = null, $senstri = '') { |
| 525 | 525 | if (strncmp($t, 'multi ', 6) == 0) { |
| 526 | - return 'multi' . $senstri; |
|
| 526 | + return 'multi'.$senstri; |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | $champ = $t; |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | case 'sinum ': |
| 558 | 558 | return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
| 559 | 559 | default: |
| 560 | - return $champ . $senstri; |
|
| 560 | + return $champ.$senstri; |
|
| 561 | 561 | } |
| 562 | 562 | } |
| 563 | 563 | |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | **/ |
| 24 | 24 | |
| 25 | 25 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 26 | - return; |
|
| 26 | + return; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | // public/interfaces definit des traitements sur les champs qui utilisent des fonctions de inc/texte |
@@ -55,75 +55,75 @@ discard block |
||
| 55 | 55 | * Introduction calculée |
| 56 | 56 | **/ |
| 57 | 57 | function filtre_introduction_dist($descriptif, $texte, $longueur, $connect, $suite = null) { |
| 58 | - // Si un descriptif est envoye, on l'utilise directement |
|
| 59 | - if (strlen($descriptif)) { |
|
| 60 | - return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // De preference ce qui est marque <intro>...</intro> |
|
| 64 | - $intro = ''; |
|
| 65 | - $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules |
|
| 66 | - while ($fin = strpos($texte, '</intro>')) { |
|
| 67 | - $zone = substr($texte, 0, $fin); |
|
| 68 | - $texte = substr($texte, $fin + strlen('</intro>')); |
|
| 69 | - if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') { |
|
| 70 | - $zone = substr($zone, $deb + 7); |
|
| 71 | - } |
|
| 72 | - $intro .= $zone; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 76 | - // qui inclus raccourcis et modeles |
|
| 77 | - // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 78 | - // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 79 | - // des surcharges et enrichissement de propre |
|
| 80 | - // couper doit se faire apres propre |
|
| 81 | - //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 82 | - |
|
| 83 | - // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 84 | - // large et en se mefiant des tableaux #1323 |
|
| 85 | - |
|
| 86 | - if (strlen($intro)) { |
|
| 87 | - $texte = $intro; |
|
| 88 | - } else { |
|
| 89 | - if ( |
|
| 90 | - strpos("\n" . $texte, "\n|") === false |
|
| 91 | - and strlen($texte) > 2.5 * $longueur |
|
| 92 | - ) { |
|
| 93 | - if (strpos($texte, '<multi') !== false) { |
|
| 94 | - $texte = extraire_multi($texte); |
|
| 95 | - } |
|
| 96 | - $texte = couper($texte, 2 * $longueur); |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - // ne pas tenir compte des notes |
|
| 101 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 102 | - $notes('', 'empiler'); |
|
| 103 | - } |
|
| 104 | - // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 105 | - // dans l'introduction. |
|
| 106 | - $texte = supprime_img($texte, ''); |
|
| 107 | - $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect); |
|
| 108 | - |
|
| 109 | - if ($notes) { |
|
| 110 | - $notes('', 'depiler'); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 114 | - $suite = _INTRODUCTION_SUITE; |
|
| 115 | - } |
|
| 116 | - $texte = couper($texte, $longueur, $suite); |
|
| 117 | - // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 118 | - $texte = typo($texte, true, $connect, []); |
|
| 119 | - |
|
| 120 | - // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 121 | - // une introduction a tojours un <p> |
|
| 122 | - if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes |
|
| 123 | - $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - return $texte; |
|
| 58 | + // Si un descriptif est envoye, on l'utilise directement |
|
| 59 | + if (strlen($descriptif)) { |
|
| 60 | + return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // De preference ce qui est marque <intro>...</intro> |
|
| 64 | + $intro = ''; |
|
| 65 | + $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules |
|
| 66 | + while ($fin = strpos($texte, '</intro>')) { |
|
| 67 | + $zone = substr($texte, 0, $fin); |
|
| 68 | + $texte = substr($texte, $fin + strlen('</intro>')); |
|
| 69 | + if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') { |
|
| 70 | + $zone = substr($zone, $deb + 7); |
|
| 71 | + } |
|
| 72 | + $intro .= $zone; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 76 | + // qui inclus raccourcis et modeles |
|
| 77 | + // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 78 | + // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 79 | + // des surcharges et enrichissement de propre |
|
| 80 | + // couper doit se faire apres propre |
|
| 81 | + //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 82 | + |
|
| 83 | + // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 84 | + // large et en se mefiant des tableaux #1323 |
|
| 85 | + |
|
| 86 | + if (strlen($intro)) { |
|
| 87 | + $texte = $intro; |
|
| 88 | + } else { |
|
| 89 | + if ( |
|
| 90 | + strpos("\n" . $texte, "\n|") === false |
|
| 91 | + and strlen($texte) > 2.5 * $longueur |
|
| 92 | + ) { |
|
| 93 | + if (strpos($texte, '<multi') !== false) { |
|
| 94 | + $texte = extraire_multi($texte); |
|
| 95 | + } |
|
| 96 | + $texte = couper($texte, 2 * $longueur); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // ne pas tenir compte des notes |
|
| 101 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 102 | + $notes('', 'empiler'); |
|
| 103 | + } |
|
| 104 | + // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 105 | + // dans l'introduction. |
|
| 106 | + $texte = supprime_img($texte, ''); |
|
| 107 | + $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect); |
|
| 108 | + |
|
| 109 | + if ($notes) { |
|
| 110 | + $notes('', 'depiler'); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 114 | + $suite = _INTRODUCTION_SUITE; |
|
| 115 | + } |
|
| 116 | + $texte = couper($texte, $longueur, $suite); |
|
| 117 | + // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 118 | + $texte = typo($texte, true, $connect, []); |
|
| 119 | + |
|
| 120 | + // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 121 | + // une introduction a tojours un <p> |
|
| 122 | + if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes |
|
| 123 | + $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + return $texte; |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | |
@@ -158,73 +158,73 @@ discard block |
||
| 158 | 158 | * Code HTML de la pagination |
| 159 | 159 | **/ |
| 160 | 160 | function filtre_pagination_dist( |
| 161 | - $total, |
|
| 162 | - $nom, |
|
| 163 | - $position, |
|
| 164 | - $pas, |
|
| 165 | - $liste = true, |
|
| 166 | - $modele = '', |
|
| 167 | - string $connect = '', |
|
| 168 | - $env = [] |
|
| 161 | + $total, |
|
| 162 | + $nom, |
|
| 163 | + $position, |
|
| 164 | + $pas, |
|
| 165 | + $liste = true, |
|
| 166 | + $modele = '', |
|
| 167 | + string $connect = '', |
|
| 168 | + $env = [] |
|
| 169 | 169 | ) { |
| 170 | - static $ancres = []; |
|
| 171 | - if ($pas < 1) { |
|
| 172 | - return ''; |
|
| 173 | - } |
|
| 174 | - $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 175 | - $debut = 'debut' . $nom; // 'debut_articles' |
|
| 176 | - |
|
| 177 | - // n'afficher l'ancre qu'une fois |
|
| 178 | - if (!isset($ancres[$ancre])) { |
|
| 179 | - $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 180 | - } else { |
|
| 181 | - $bloc_ancre = ''; |
|
| 182 | - } |
|
| 183 | - // liste = false : on ne veut que l'ancre |
|
| 184 | - if (!$liste) { |
|
| 185 | - return $ancres[$ancre]; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - $self = (empty($env['self']) ? self() : $env['self']); |
|
| 189 | - $pagination = [ |
|
| 190 | - 'debut' => $debut, |
|
| 191 | - 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 192 | - 'total' => $total, |
|
| 193 | - 'position' => intval($position), |
|
| 194 | - 'pas' => $pas, |
|
| 195 | - 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 196 | - 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 197 | - 'ancre' => $ancre, |
|
| 198 | - 'bloc_ancre' => $bloc_ancre |
|
| 199 | - ]; |
|
| 200 | - if (is_array($env)) { |
|
| 201 | - $pagination = array_merge($env, $pagination); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - // Pas de pagination |
|
| 205 | - if ($pagination['nombre_pages'] <= 1) { |
|
| 206 | - return ''; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - if ($modele) { |
|
| 210 | - $pagination['type_pagination'] = $modele; |
|
| 211 | - if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 212 | - $modele = '_' . $modele; |
|
| 213 | - } |
|
| 214 | - else { |
|
| 215 | - $modele = ''; |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) { |
|
| 220 | - define('_PAGINATION_NOMBRE_LIENS_MAX', 10); |
|
| 221 | - } |
|
| 222 | - if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) { |
|
| 223 | - define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect); |
|
| 170 | + static $ancres = []; |
|
| 171 | + if ($pas < 1) { |
|
| 172 | + return ''; |
|
| 173 | + } |
|
| 174 | + $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 175 | + $debut = 'debut' . $nom; // 'debut_articles' |
|
| 176 | + |
|
| 177 | + // n'afficher l'ancre qu'une fois |
|
| 178 | + if (!isset($ancres[$ancre])) { |
|
| 179 | + $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 180 | + } else { |
|
| 181 | + $bloc_ancre = ''; |
|
| 182 | + } |
|
| 183 | + // liste = false : on ne veut que l'ancre |
|
| 184 | + if (!$liste) { |
|
| 185 | + return $ancres[$ancre]; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + $self = (empty($env['self']) ? self() : $env['self']); |
|
| 189 | + $pagination = [ |
|
| 190 | + 'debut' => $debut, |
|
| 191 | + 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 192 | + 'total' => $total, |
|
| 193 | + 'position' => intval($position), |
|
| 194 | + 'pas' => $pas, |
|
| 195 | + 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 196 | + 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 197 | + 'ancre' => $ancre, |
|
| 198 | + 'bloc_ancre' => $bloc_ancre |
|
| 199 | + ]; |
|
| 200 | + if (is_array($env)) { |
|
| 201 | + $pagination = array_merge($env, $pagination); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + // Pas de pagination |
|
| 205 | + if ($pagination['nombre_pages'] <= 1) { |
|
| 206 | + return ''; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + if ($modele) { |
|
| 210 | + $pagination['type_pagination'] = $modele; |
|
| 211 | + if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 212 | + $modele = '_' . $modele; |
|
| 213 | + } |
|
| 214 | + else { |
|
| 215 | + $modele = ''; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) { |
|
| 220 | + define('_PAGINATION_NOMBRE_LIENS_MAX', 10); |
|
| 221 | + } |
|
| 222 | + if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) { |
|
| 223 | + define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | |
@@ -243,44 +243,44 @@ discard block |
||
| 243 | 243 | * Liste (première page, dernière page). |
| 244 | 244 | **/ |
| 245 | 245 | function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) { |
| 246 | - if ($max <= 0 or $max >= $nombre) { |
|
| 247 | - return [1, $nombre]; |
|
| 248 | - } |
|
| 249 | - if ($max <= 1) { |
|
| 250 | - return [$courante, $courante]; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 254 | - $derniere = min($nombre, $premiere + $max - 2); |
|
| 255 | - $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 256 | - |
|
| 257 | - return [$premiere, $derniere]; |
|
| 246 | + if ($max <= 0 or $max >= $nombre) { |
|
| 247 | + return [1, $nombre]; |
|
| 248 | + } |
|
| 249 | + if ($max <= 1) { |
|
| 250 | + return [$courante, $courante]; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 254 | + $derniere = min($nombre, $premiere + $max - 2); |
|
| 255 | + $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 256 | + |
|
| 257 | + return [$premiere, $derniere]; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | function filtre_pagination_affiche_texte_lien_page_dist($type_pagination, $numero_page, $rang_item) { |
| 261 | - if ($numero_page === 'tous') { |
|
| 262 | - return '∞'; |
|
| 263 | - } |
|
| 264 | - if ($numero_page === 'prev') { |
|
| 265 | - return '<'; |
|
| 266 | - } |
|
| 267 | - if ($numero_page === 'next') { |
|
| 268 | - return '>'; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - switch ($type_pagination) { |
|
| 272 | - case 'resultats': |
|
| 273 | - return $rang_item + 1; // 1 11 21 31... |
|
| 274 | - case 'naturel': |
|
| 275 | - return $rang_item ?: 1; // 1 10 20 30... |
|
| 276 | - case 'rang': |
|
| 277 | - return $rang_item; // 0 10 20 30... |
|
| 278 | - |
|
| 279 | - case 'page': |
|
| 280 | - case 'prive': |
|
| 281 | - default: |
|
| 282 | - return $numero_page; // 1 2 3 4 5... |
|
| 283 | - } |
|
| 261 | + if ($numero_page === 'tous') { |
|
| 262 | + return '∞'; |
|
| 263 | + } |
|
| 264 | + if ($numero_page === 'prev') { |
|
| 265 | + return '<'; |
|
| 266 | + } |
|
| 267 | + if ($numero_page === 'next') { |
|
| 268 | + return '>'; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + switch ($type_pagination) { |
|
| 272 | + case 'resultats': |
|
| 273 | + return $rang_item + 1; // 1 11 21 31... |
|
| 274 | + case 'naturel': |
|
| 275 | + return $rang_item ?: 1; // 1 10 20 30... |
|
| 276 | + case 'rang': |
|
| 277 | + return $rang_item; // 0 10 20 30... |
|
| 278 | + |
|
| 279 | + case 'page': |
|
| 280 | + case 'prive': |
|
| 281 | + default: |
|
| 282 | + return $numero_page; // 1 2 3 4 5... |
|
| 283 | + } |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -293,15 +293,15 @@ discard block |
||
| 293 | 293 | **/ |
| 294 | 294 | function lister_objets_avec_logos($type) { |
| 295 | 295 | |
| 296 | - $objet = objet_type($type); |
|
| 297 | - $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet)); |
|
| 298 | - if ($ids) { |
|
| 299 | - $ids = array_column($ids, 'id_objet'); |
|
| 300 | - return implode(',', $ids); |
|
| 301 | - } |
|
| 302 | - else { |
|
| 303 | - return '0'; |
|
| 304 | - } |
|
| 296 | + $objet = objet_type($type); |
|
| 297 | + $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet)); |
|
| 298 | + if ($ids) { |
|
| 299 | + $ids = array_column($ids, 'id_objet'); |
|
| 300 | + return implode(',', $ids); |
|
| 301 | + } |
|
| 302 | + else { |
|
| 303 | + return '0'; |
|
| 304 | + } |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | |
@@ -317,14 +317,14 @@ discard block |
||
| 317 | 317 | * Code HTML des notes |
| 318 | 318 | **/ |
| 319 | 319 | function calculer_notes() { |
| 320 | - $r = ''; |
|
| 321 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 322 | - $r = $notes([]); |
|
| 323 | - $notes('', 'depiler'); |
|
| 324 | - $notes('', 'empiler'); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - return $r; |
|
| 320 | + $r = ''; |
|
| 321 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 322 | + $r = $notes([]); |
|
| 323 | + $notes('', 'depiler'); |
|
| 324 | + $notes('', 'empiler'); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + return $r; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | |
@@ -341,10 +341,10 @@ discard block |
||
| 341 | 341 | * @return string |
| 342 | 342 | */ |
| 343 | 343 | function retrouver_rang_lien($objet_source, $ids, $objet_lie, $idl, $objet_lien) { |
| 344 | - $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 345 | - $res = array_column($res, 'rang_lien', $objet_source); |
|
| 344 | + $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 345 | + $res = array_column($res, 'rang_lien', $objet_source); |
|
| 346 | 346 | |
| 347 | - return ($res[$ids] ?? ''); |
|
| 347 | + return ($res[$ids] ?? ''); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | |
@@ -361,19 +361,19 @@ discard block |
||
| 361 | 361 | * @private |
| 362 | 362 | */ |
| 363 | 363 | function lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien) { |
| 364 | - static $liens = []; |
|
| 365 | - if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 366 | - include_spip('action/editer_liens'); |
|
| 367 | - // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 368 | - if ($objet_lien == $objet and $objet_lien !== $objet_source) { |
|
| 369 | - $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 370 | - } else { |
|
| 371 | - $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 375 | - } |
|
| 376 | - return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 364 | + static $liens = []; |
|
| 365 | + if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 366 | + include_spip('action/editer_liens'); |
|
| 367 | + // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 368 | + if ($objet_lien == $objet and $objet_lien !== $objet_source) { |
|
| 369 | + $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 370 | + } else { |
|
| 371 | + $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 375 | + } |
|
| 376 | + return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -387,24 +387,24 @@ discard block |
||
| 387 | 387 | * @return int|string |
| 388 | 388 | */ |
| 389 | 389 | function calculer_rang_smart($titre, $objet_source, $id, $env) { |
| 390 | - // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 391 | - // permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens |
|
| 392 | - if ( |
|
| 393 | - isset($env['form']) and $env['form'] |
|
| 394 | - and isset($env['_objet_lien']) and $env['_objet_lien'] |
|
| 395 | - and (function_exists('lien_triables') or include_spip('action/editer_liens')) |
|
| 396 | - and $r = objet_associable($env['_objet_lien']) |
|
| 397 | - and [$p, $table_lien] = $r |
|
| 398 | - and lien_triables($table_lien) |
|
| 399 | - and isset($env['objet']) and $env['objet'] |
|
| 400 | - and isset($env['id_objet']) and $env['id_objet'] |
|
| 401 | - and $objet_source |
|
| 402 | - and $id = intval($id) |
|
| 403 | - ) { |
|
| 404 | - $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 405 | - return ($rang ?: ''); |
|
| 406 | - } |
|
| 407 | - return recuperer_numero($titre); |
|
| 390 | + // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 391 | + // permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens |
|
| 392 | + if ( |
|
| 393 | + isset($env['form']) and $env['form'] |
|
| 394 | + and isset($env['_objet_lien']) and $env['_objet_lien'] |
|
| 395 | + and (function_exists('lien_triables') or include_spip('action/editer_liens')) |
|
| 396 | + and $r = objet_associable($env['_objet_lien']) |
|
| 397 | + and [$p, $table_lien] = $r |
|
| 398 | + and lien_triables($table_lien) |
|
| 399 | + and isset($env['objet']) and $env['objet'] |
|
| 400 | + and isset($env['id_objet']) and $env['id_objet'] |
|
| 401 | + and $objet_source |
|
| 402 | + and $id = intval($id) |
|
| 403 | + ) { |
|
| 404 | + $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 405 | + return ($rang ?: ''); |
|
| 406 | + } |
|
| 407 | + return recuperer_numero($titre); |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | /** |
@@ -431,72 +431,72 @@ discard block |
||
| 431 | 431 | */ |
| 432 | 432 | function calculer_balise_tri(string $champ_ou_sens, string $libelle, string $classe, string $tri_nom, string $tri_champ, string $tri_sens, $liste_tri_sens_defaut): string { |
| 433 | 433 | |
| 434 | - $url = self('&'); |
|
| 435 | - $tri_sens = (int) $tri_sens; |
|
| 436 | - $alias_sens = [ |
|
| 437 | - '<' => -1, |
|
| 438 | - '>' => 1, |
|
| 439 | - 'inverse' => -1, |
|
| 440 | - ]; |
|
| 441 | - |
|
| 442 | - // Normaliser la liste des sens de tri par défaut |
|
| 443 | - // On ajoute un jocker pour les champs non présents dans la liste |
|
| 444 | - // avec la valeur du 1er item de la liste, idem critère {tri} |
|
| 445 | - if (is_array($liste_tri_sens_defaut)) { |
|
| 446 | - $liste_tri_sens_defaut['*'] = array_values($liste_tri_sens_defaut)[0]; |
|
| 447 | - } else { |
|
| 448 | - $liste_tri_sens_defaut = [ |
|
| 449 | - '*' => (int) ($alias_sens[$liste_tri_sens_defaut] ?? $liste_tri_sens_defaut), |
|
| 450 | - ]; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - // Les sens de tri actuel et nouveau : |
|
| 454 | - // Soit c'est un sens fixe donné en paramètre (< ou >) |
|
| 455 | - $is_sens_fixe = array_key_exists($champ_ou_sens, $alias_sens); |
|
| 456 | - if ($is_sens_fixe) { |
|
| 457 | - $tri_sens_actuel = $tri_sens; |
|
| 458 | - $tri_sens_nouveau = $alias_sens[$champ_ou_sens]; |
|
| 459 | - // Soit c'est le champ utilisé actuellement pour le tri → on inverse le sens |
|
| 460 | - } elseif ($champ_ou_sens === $tri_champ) { |
|
| 461 | - $tri_sens_actuel = $tri_sens; |
|
| 462 | - $tri_sens_nouveau = $tri_sens * -1; |
|
| 463 | - // Sinon c'est un nouveau champ, et on prend son tri par défaut |
|
| 464 | - } else { |
|
| 465 | - $tri_sens_actuel = $tri_sens_nouveau = (int) ($liste_tri_sens_defaut[$champ_ou_sens] ?? $liste_tri_sens_defaut['*']); |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - // URL : ajouter le champ sur lequel porte le tri |
|
| 469 | - if (!$is_sens_fixe) { |
|
| 470 | - $param_tri = "tri$tri_nom"; |
|
| 471 | - $url = parametre_url($url, $param_tri, $champ_ou_sens); |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - // URL : n'ajouter le sens de tri que si nécessaire, |
|
| 475 | - // c.à .d différent du sens par défaut pour le champ |
|
| 476 | - $param_sens = "sens$tri_nom"; |
|
| 477 | - $tri_sens_defaut_champ = (int) ($liste_tri_sens_defaut[$champ_ou_sens] ?? $liste_tri_sens_defaut['*']); |
|
| 478 | - if ($tri_sens_nouveau !== $tri_sens_defaut_champ) { |
|
| 479 | - $url = parametre_url($url, $param_sens, $tri_sens_nouveau); |
|
| 480 | - } else { |
|
| 481 | - $url = parametre_url($url, $param_sens, ''); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - // Drapeau pour garder en session ? |
|
| 485 | - $param_memo = (!$is_sens_fixe ? $param_tri : $param_sens); |
|
| 486 | - $url = parametre_url($url, 'var_memotri', strncmp($tri_nom, 'session', 7) == 0 ? $param_memo : ''); |
|
| 487 | - |
|
| 488 | - // Classes : on indique le sens de tri et l'item exposé |
|
| 489 | - if (!$is_sens_fixe) { |
|
| 490 | - $classe .= ' item-tri item-tri_' . ($tri_sens_actuel === 1 ? 'asc' : 'desc'); |
|
| 491 | - } |
|
| 492 | - if ($champ_ou_sens === $tri_champ) { |
|
| 493 | - $classe .= ' item-tri_actif'; |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - // Lien |
|
| 497 | - $balise = lien_ou_expose($url, $libelle, false, $classe); |
|
| 498 | - |
|
| 499 | - return $balise; |
|
| 434 | + $url = self('&'); |
|
| 435 | + $tri_sens = (int) $tri_sens; |
|
| 436 | + $alias_sens = [ |
|
| 437 | + '<' => -1, |
|
| 438 | + '>' => 1, |
|
| 439 | + 'inverse' => -1, |
|
| 440 | + ]; |
|
| 441 | + |
|
| 442 | + // Normaliser la liste des sens de tri par défaut |
|
| 443 | + // On ajoute un jocker pour les champs non présents dans la liste |
|
| 444 | + // avec la valeur du 1er item de la liste, idem critère {tri} |
|
| 445 | + if (is_array($liste_tri_sens_defaut)) { |
|
| 446 | + $liste_tri_sens_defaut['*'] = array_values($liste_tri_sens_defaut)[0]; |
|
| 447 | + } else { |
|
| 448 | + $liste_tri_sens_defaut = [ |
|
| 449 | + '*' => (int) ($alias_sens[$liste_tri_sens_defaut] ?? $liste_tri_sens_defaut), |
|
| 450 | + ]; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + // Les sens de tri actuel et nouveau : |
|
| 454 | + // Soit c'est un sens fixe donné en paramètre (< ou >) |
|
| 455 | + $is_sens_fixe = array_key_exists($champ_ou_sens, $alias_sens); |
|
| 456 | + if ($is_sens_fixe) { |
|
| 457 | + $tri_sens_actuel = $tri_sens; |
|
| 458 | + $tri_sens_nouveau = $alias_sens[$champ_ou_sens]; |
|
| 459 | + // Soit c'est le champ utilisé actuellement pour le tri → on inverse le sens |
|
| 460 | + } elseif ($champ_ou_sens === $tri_champ) { |
|
| 461 | + $tri_sens_actuel = $tri_sens; |
|
| 462 | + $tri_sens_nouveau = $tri_sens * -1; |
|
| 463 | + // Sinon c'est un nouveau champ, et on prend son tri par défaut |
|
| 464 | + } else { |
|
| 465 | + $tri_sens_actuel = $tri_sens_nouveau = (int) ($liste_tri_sens_defaut[$champ_ou_sens] ?? $liste_tri_sens_defaut['*']); |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + // URL : ajouter le champ sur lequel porte le tri |
|
| 469 | + if (!$is_sens_fixe) { |
|
| 470 | + $param_tri = "tri$tri_nom"; |
|
| 471 | + $url = parametre_url($url, $param_tri, $champ_ou_sens); |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + // URL : n'ajouter le sens de tri que si nécessaire, |
|
| 475 | + // c.à .d différent du sens par défaut pour le champ |
|
| 476 | + $param_sens = "sens$tri_nom"; |
|
| 477 | + $tri_sens_defaut_champ = (int) ($liste_tri_sens_defaut[$champ_ou_sens] ?? $liste_tri_sens_defaut['*']); |
|
| 478 | + if ($tri_sens_nouveau !== $tri_sens_defaut_champ) { |
|
| 479 | + $url = parametre_url($url, $param_sens, $tri_sens_nouveau); |
|
| 480 | + } else { |
|
| 481 | + $url = parametre_url($url, $param_sens, ''); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + // Drapeau pour garder en session ? |
|
| 485 | + $param_memo = (!$is_sens_fixe ? $param_tri : $param_sens); |
|
| 486 | + $url = parametre_url($url, 'var_memotri', strncmp($tri_nom, 'session', 7) == 0 ? $param_memo : ''); |
|
| 487 | + |
|
| 488 | + // Classes : on indique le sens de tri et l'item exposé |
|
| 489 | + if (!$is_sens_fixe) { |
|
| 490 | + $classe .= ' item-tri item-tri_' . ($tri_sens_actuel === 1 ? 'asc' : 'desc'); |
|
| 491 | + } |
|
| 492 | + if ($champ_ou_sens === $tri_champ) { |
|
| 493 | + $classe .= ' item-tri_actif'; |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + // Lien |
|
| 497 | + $balise = lien_ou_expose($url, $libelle, false, $classe); |
|
| 498 | + |
|
| 499 | + return $balise; |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | * @return string |
| 513 | 513 | */ |
| 514 | 514 | function tri_protege_champ($t) { |
| 515 | - return preg_replace(',[^\s\w.+\[\]],', '', $t); |
|
| 515 | + return preg_replace(',[^\s\w.+\[\]],', '', $t); |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
@@ -525,43 +525,43 @@ discard block |
||
| 525 | 525 | * @return string |
| 526 | 526 | */ |
| 527 | 527 | function tri_champ_order($t, $from = null, $senstri = '') { |
| 528 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 529 | - return 'multi' . $senstri; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - $champ = $t; |
|
| 533 | - |
|
| 534 | - $prefixe = ''; |
|
| 535 | - foreach (['num ', 'sinum '] as $p) { |
|
| 536 | - if (strpos($t, $p) === 0) { |
|
| 537 | - $champ = substr($t, strlen($p)); |
|
| 538 | - $prefixe = $p; |
|
| 539 | - } |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - // enlever les autres espaces non evacues par tri_protege_champ |
|
| 543 | - $champ = preg_replace(',\s,', '', $champ); |
|
| 544 | - |
|
| 545 | - if (is_array($from)) { |
|
| 546 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 547 | - foreach ($from as $idt => $table_sql) { |
|
| 548 | - if ( |
|
| 549 | - $desc = $trouver_table($table_sql) |
|
| 550 | - and isset($desc['field'][$champ]) |
|
| 551 | - ) { |
|
| 552 | - $champ = "$idt.$champ"; |
|
| 553 | - break; |
|
| 554 | - } |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - switch ($prefixe) { |
|
| 558 | - case 'num ': |
|
| 559 | - return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}"; |
|
| 560 | - case 'sinum ': |
|
| 561 | - return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
|
| 562 | - default: |
|
| 563 | - return $champ . $senstri; |
|
| 564 | - } |
|
| 528 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 529 | + return 'multi' . $senstri; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + $champ = $t; |
|
| 533 | + |
|
| 534 | + $prefixe = ''; |
|
| 535 | + foreach (['num ', 'sinum '] as $p) { |
|
| 536 | + if (strpos($t, $p) === 0) { |
|
| 537 | + $champ = substr($t, strlen($p)); |
|
| 538 | + $prefixe = $p; |
|
| 539 | + } |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + // enlever les autres espaces non evacues par tri_protege_champ |
|
| 543 | + $champ = preg_replace(',\s,', '', $champ); |
|
| 544 | + |
|
| 545 | + if (is_array($from)) { |
|
| 546 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 547 | + foreach ($from as $idt => $table_sql) { |
|
| 548 | + if ( |
|
| 549 | + $desc = $trouver_table($table_sql) |
|
| 550 | + and isset($desc['field'][$champ]) |
|
| 551 | + ) { |
|
| 552 | + $champ = "$idt.$champ"; |
|
| 553 | + break; |
|
| 554 | + } |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + switch ($prefixe) { |
|
| 558 | + case 'num ': |
|
| 559 | + return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}"; |
|
| 560 | + case 'sinum ': |
|
| 561 | + return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
|
| 562 | + default: |
|
| 563 | + return $champ . $senstri; |
|
| 564 | + } |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | /** |
@@ -575,18 +575,18 @@ discard block |
||
| 575 | 575 | * @return string |
| 576 | 576 | */ |
| 577 | 577 | function tri_champ_select($t) { |
| 578 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 579 | - $t = substr($t, 6); |
|
| 580 | - $t = preg_replace(',\s,', '', $t); |
|
| 581 | - $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 582 | - |
|
| 583 | - return $t; |
|
| 584 | - } |
|
| 585 | - if (trim($t) == 'hasard') { |
|
| 586 | - return 'rand() AS hasard'; |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - return "''"; |
|
| 578 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 579 | + $t = substr($t, 6); |
|
| 580 | + $t = preg_replace(',\s,', '', $t); |
|
| 581 | + $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 582 | + |
|
| 583 | + return $t; |
|
| 584 | + } |
|
| 585 | + if (trim($t) == 'hasard') { |
|
| 586 | + return 'rand() AS hasard'; |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + return "''"; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | /** |
@@ -598,16 +598,16 @@ discard block |
||
| 598 | 598 | * @return string |
| 599 | 599 | */ |
| 600 | 600 | function formate_liste_critere_par_ordre_liste($valeurs, $serveur = '') { |
| 601 | - if (!is_array($valeurs)) { |
|
| 602 | - return ''; |
|
| 603 | - } |
|
| 604 | - $f = sql_serveur('quote', $serveur, true); |
|
| 605 | - if (!is_string($f) or !$f) { |
|
| 606 | - return ''; |
|
| 607 | - } |
|
| 608 | - $valeurs = implode(',', array_map($f, array_unique($valeurs))); |
|
| 609 | - |
|
| 610 | - return $valeurs; |
|
| 601 | + if (!is_array($valeurs)) { |
|
| 602 | + return ''; |
|
| 603 | + } |
|
| 604 | + $f = sql_serveur('quote', $serveur, true); |
|
| 605 | + if (!is_string($f) or !$f) { |
|
| 606 | + return ''; |
|
| 607 | + } |
|
| 608 | + $valeurs = implode(',', array_map($f, array_unique($valeurs))); |
|
| 609 | + |
|
| 610 | + return $valeurs; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | /** |
@@ -630,20 +630,20 @@ discard block |
||
| 630 | 630 | * Valeur $defaut sinon. |
| 631 | 631 | **/ |
| 632 | 632 | function appliquer_filtre_sinon($arg, $filtre, $args, $defaut = '') { |
| 633 | - // Si c'est un filtre d'image, on utilise image_filtrer() |
|
| 634 | - // Attention : les 2 premiers arguments sont inversés dans ce cas |
|
| 635 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 636 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 637 | - $args[1] = $args[0]; |
|
| 638 | - $args[0] = $filtre; |
|
| 639 | - return image_graver(image_filtrer($args)); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - $f = chercher_filtre($filtre); |
|
| 643 | - if (!$f) { |
|
| 644 | - return $defaut; |
|
| 645 | - } |
|
| 646 | - array_shift($args); // enlever $arg |
|
| 647 | - array_shift($args); // enlever $filtre |
|
| 648 | - return $f($arg, ...$args); |
|
| 633 | + // Si c'est un filtre d'image, on utilise image_filtrer() |
|
| 634 | + // Attention : les 2 premiers arguments sont inversés dans ce cas |
|
| 635 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 636 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 637 | + $args[1] = $args[0]; |
|
| 638 | + $args[0] = $filtre; |
|
| 639 | + return image_graver(image_filtrer($args)); |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + $f = chercher_filtre($filtre); |
|
| 643 | + if (!$f) { |
|
| 644 | + return $defaut; |
|
| 645 | + } |
|
| 646 | + array_shift($args); // enlever $arg |
|
| 647 | + array_shift($args); // enlever $filtre |
|
| 648 | + return $f($arg, ...$args); |
|
| 649 | 649 | } |
@@ -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 | |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * Code PHP compilé de la boucle |
| 33 | 33 | **/ |
| 34 | 34 | function boucle_DEFAUT_dist($id_boucle, &$boucles) { |
| 35 | - return calculer_boucle($id_boucle, $boucles); |
|
| 35 | + return calculer_boucle($id_boucle, $boucles); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * Code PHP compilé de la boucle |
| 52 | 52 | **/ |
| 53 | 53 | function boucle_BOUCLE_dist($id_boucle, &$boucles) { |
| 54 | - return calculer_boucle($id_boucle, $boucles); |
|
| 54 | + return calculer_boucle($id_boucle, $boucles); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | |
@@ -81,30 +81,30 @@ discard block |
||
| 81 | 81 | * Code PHP compilé de la boucle |
| 82 | 82 | **/ |
| 83 | 83 | function boucle_HIERARCHIE_dist($id_boucle, &$boucles) { |
| 84 | - $boucle = &$boucles[$id_boucle]; |
|
| 85 | - $id_table = $boucle->id_table . '.id_rubrique'; |
|
| 84 | + $boucle = &$boucles[$id_boucle]; |
|
| 85 | + $id_table = $boucle->id_table . '.id_rubrique'; |
|
| 86 | 86 | |
| 87 | - // Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille |
|
| 88 | - // sauf en presence du critere {tout} (vu par phraser_html) |
|
| 89 | - // ou {id_article} qui positionne aussi le {tout} |
|
| 87 | + // Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille |
|
| 88 | + // sauf en presence du critere {tout} (vu par phraser_html) |
|
| 89 | + // ou {id_article} qui positionne aussi le {tout} |
|
| 90 | 90 | |
| 91 | - $boucle->hierarchie = 'if (!($id_rubrique = intval(' |
|
| 92 | - . calculer_argument_precedent($boucle->id_boucle, 'id_rubrique', $boucles) |
|
| 93 | - . ")))\n\t\treturn '';\n\t" |
|
| 94 | - . "include_spip('inc/rubriques');\n\t" |
|
| 95 | - . '$hierarchie = calcul_hierarchie_in($id_rubrique,' |
|
| 96 | - . (isset($boucle->modificateur['tout']) ? 'true' : 'false') |
|
| 97 | - . ");\n\t" |
|
| 98 | - . 'if (!$hierarchie) return "";' . "\n\t"; |
|
| 91 | + $boucle->hierarchie = 'if (!($id_rubrique = intval(' |
|
| 92 | + . calculer_argument_precedent($boucle->id_boucle, 'id_rubrique', $boucles) |
|
| 93 | + . ")))\n\t\treturn '';\n\t" |
|
| 94 | + . "include_spip('inc/rubriques');\n\t" |
|
| 95 | + . '$hierarchie = calcul_hierarchie_in($id_rubrique,' |
|
| 96 | + . (isset($boucle->modificateur['tout']) ? 'true' : 'false') |
|
| 97 | + . ");\n\t" |
|
| 98 | + . 'if (!$hierarchie) return "";' . "\n\t"; |
|
| 99 | 99 | |
| 100 | - $boucle->where[] = ["'IN'", "'$id_table'", '"($hierarchie)"']; |
|
| 100 | + $boucle->where[] = ["'IN'", "'$id_table'", '"($hierarchie)"']; |
|
| 101 | 101 | |
| 102 | - $order = "FIELD($id_table, \$hierarchie)"; |
|
| 103 | - if (!isset($boucle->default_order[0]) or $boucle->default_order[0] != ' DESC') { |
|
| 104 | - $boucle->default_order[] = "\"$order\""; |
|
| 105 | - } else { |
|
| 106 | - $boucle->default_order[0] = "\"$order DESC\""; |
|
| 107 | - } |
|
| 102 | + $order = "FIELD($id_table, \$hierarchie)"; |
|
| 103 | + if (!isset($boucle->default_order[0]) or $boucle->default_order[0] != ' DESC') { |
|
| 104 | + $boucle->default_order[] = "\"$order\""; |
|
| 105 | + } else { |
|
| 106 | + $boucle->default_order[0] = "\"$order DESC\""; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - return calculer_boucle($id_boucle, $boucles); |
|
| 109 | + return calculer_boucle($id_boucle, $boucles); |
|
| 110 | 110 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | **/ |
| 83 | 83 | function boucle_HIERARCHIE_dist($id_boucle, &$boucles) { |
| 84 | 84 | $boucle = &$boucles[$id_boucle]; |
| 85 | - $id_table = $boucle->id_table . '.id_rubrique'; |
|
| 85 | + $id_table = $boucle->id_table.'.id_rubrique'; |
|
| 86 | 86 | |
| 87 | 87 | // Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille |
| 88 | 88 | // sauf en presence du critere {tout} (vu par phraser_html) |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | . '$hierarchie = calcul_hierarchie_in($id_rubrique,' |
| 96 | 96 | . (isset($boucle->modificateur['tout']) ? 'true' : 'false') |
| 97 | 97 | . ");\n\t" |
| 98 | - . 'if (!$hierarchie) return "";' . "\n\t"; |
|
| 98 | + . 'if (!$hierarchie) return "";'."\n\t"; |
|
| 99 | 99 | |
| 100 | 100 | $boucle->where[] = ["'IN'", "'$id_table'", '"($hierarchie)"']; |
| 101 | 101 | |
@@ -18,12 +18,12 @@ discard block |
||
| 18 | 18 | * @package SPIP\Core\SQL\Upgrade |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | $GLOBALS['maj'][21676] = [ |
| 26 | - ['ranger_cache_gd2'], |
|
| 26 | + ['ranger_cache_gd2'], |
|
| 27 | 27 | ]; |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -32,30 +32,30 @@ discard block |
||
| 32 | 32 | * https://core.spip.net/issues/3277 |
| 33 | 33 | */ |
| 34 | 34 | function ranger_cache_gd2() { |
| 35 | - spip_log('ranger_cache_gd2'); |
|
| 36 | - $base = _DIR_VAR . 'cache-gd2/'; |
|
| 37 | - if (is_dir($base) and is_readable($base)) { |
|
| 38 | - if ($dir = opendir($base)) { |
|
| 39 | - while (($f = readdir($dir)) !== false) { |
|
| 40 | - if ( |
|
| 41 | - !is_dir($base . $f) and strncmp($f, '.', 1) !== 0 |
|
| 42 | - and preg_match(',[0-9a-f]{32}\.\w+,', $f) |
|
| 43 | - ) { |
|
| 44 | - $sub = substr($f, 0, 2); |
|
| 45 | - $sub = sous_repertoire($base, $sub); |
|
| 46 | - @rename($base . $f, $sub . substr($f, 2)); |
|
| 47 | - @unlink($base . $f); // au cas ou le rename a foire (collision) |
|
| 48 | - } |
|
| 49 | - if (time() >= _TIME_OUT) { |
|
| 50 | - return; |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - } |
|
| 35 | + spip_log('ranger_cache_gd2'); |
|
| 36 | + $base = _DIR_VAR . 'cache-gd2/'; |
|
| 37 | + if (is_dir($base) and is_readable($base)) { |
|
| 38 | + if ($dir = opendir($base)) { |
|
| 39 | + while (($f = readdir($dir)) !== false) { |
|
| 40 | + if ( |
|
| 41 | + !is_dir($base . $f) and strncmp($f, '.', 1) !== 0 |
|
| 42 | + and preg_match(',[0-9a-f]{32}\.\w+,', $f) |
|
| 43 | + ) { |
|
| 44 | + $sub = substr($f, 0, 2); |
|
| 45 | + $sub = sous_repertoire($base, $sub); |
|
| 46 | + @rename($base . $f, $sub . substr($f, 2)); |
|
| 47 | + @unlink($base . $f); // au cas ou le rename a foire (collision) |
|
| 48 | + } |
|
| 49 | + if (time() >= _TIME_OUT) { |
|
| 50 | + return; |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | |
| 58 | 58 | $GLOBALS['maj'][21742] = [ |
| 59 | - ['sql_alter', "TABLE spip_articles CHANGE url_site url_site text DEFAULT '' NOT NULL"], |
|
| 60 | - ['sql_alter', "TABLE spip_articles CHANGE virtuel virtuel text DEFAULT '' NOT NULL"], |
|
| 59 | + ['sql_alter', "TABLE spip_articles CHANGE url_site url_site text DEFAULT '' NOT NULL"], |
|
| 60 | + ['sql_alter', "TABLE spip_articles CHANGE virtuel virtuel text DEFAULT '' NOT NULL"], |
|
| 61 | 61 | ]; |
@@ -33,18 +33,18 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | function ranger_cache_gd2() { |
| 35 | 35 | spip_log('ranger_cache_gd2'); |
| 36 | - $base = _DIR_VAR . 'cache-gd2/'; |
|
| 36 | + $base = _DIR_VAR.'cache-gd2/'; |
|
| 37 | 37 | if (is_dir($base) and is_readable($base)) { |
| 38 | 38 | if ($dir = opendir($base)) { |
| 39 | 39 | while (($f = readdir($dir)) !== false) { |
| 40 | 40 | if ( |
| 41 | - !is_dir($base . $f) and strncmp($f, '.', 1) !== 0 |
|
| 41 | + !is_dir($base.$f) and strncmp($f, '.', 1) !== 0 |
|
| 42 | 42 | and preg_match(',[0-9a-f]{32}\.\w+,', $f) |
| 43 | 43 | ) { |
| 44 | 44 | $sub = substr($f, 0, 2); |
| 45 | 45 | $sub = sous_repertoire($base, $sub); |
| 46 | - @rename($base . $f, $sub . substr($f, 2)); |
|
| 47 | - @unlink($base . $f); // au cas ou le rename a foire (collision) |
|
| 46 | + @rename($base.$f, $sub.substr($f, 2)); |
|
| 47 | + @unlink($base.$f); // au cas ou le rename a foire (collision) |
|
| 48 | 48 | } |
| 49 | 49 | if (time() >= _TIME_OUT) { |
| 50 | 50 | return; |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @package SPIP\Core\SQL\Upgrade |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('base/medias'); |
@@ -27,27 +27,27 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | // http://archives.rezo.net/archives/spip-zone.mbox/C6RZKNBUNJYN42IOEOC4QKVCA233AMLI/ |
| 29 | 29 | $GLOBALS['maj'][13833] = [ |
| 30 | - ['sql_alter', 'TABLE spip_documents_liens ADD INDEX objet(id_objet,objet)'] |
|
| 30 | + ['sql_alter', 'TABLE spip_documents_liens ADD INDEX objet(id_objet,objet)'] |
|
| 31 | 31 | ]; |
| 32 | 32 | |
| 33 | 33 | // 2.1 |
| 34 | 34 | |
| 35 | 35 | $GLOBALS['maj'][13904] = [ |
| 36 | - ['sql_alter', "TABLE spip_auteurs ADD webmestre varchar(3) DEFAULT 'non' NOT NULL"], |
|
| 37 | - [ |
|
| 38 | - 'sql_update', |
|
| 39 | - 'spip_auteurs', |
|
| 40 | - ['webmestre' => "'oui'"], |
|
| 41 | - sql_in('id_auteur', defined('_ID_WEBMESTRES') ? explode( |
|
| 42 | - ':', |
|
| 43 | - _ID_WEBMESTRES |
|
| 44 | - ) : (autoriser('configurer') ? [$GLOBALS['visiteur_session']['id_auteur']] : [0])) |
|
| 45 | - ] // le webmestre est celui qui fait l'upgrade si rien de defini |
|
| 36 | + ['sql_alter', "TABLE spip_auteurs ADD webmestre varchar(3) DEFAULT 'non' NOT NULL"], |
|
| 37 | + [ |
|
| 38 | + 'sql_update', |
|
| 39 | + 'spip_auteurs', |
|
| 40 | + ['webmestre' => "'oui'"], |
|
| 41 | + sql_in('id_auteur', defined('_ID_WEBMESTRES') ? explode( |
|
| 42 | + ':', |
|
| 43 | + _ID_WEBMESTRES |
|
| 44 | + ) : (autoriser('configurer') ? [$GLOBALS['visiteur_session']['id_auteur']] : [0])) |
|
| 45 | + ] // le webmestre est celui qui fait l'upgrade si rien de defini |
|
| 46 | 46 | ]; |
| 47 | 47 | |
| 48 | 48 | // sites plantes en mode "'su" au lieu de "sus" |
| 49 | 49 | $GLOBALS['maj'][13929] = [ |
| 50 | - ['sql_update', 'spip_syndic', ['syndication' => "'sus'"], "syndication LIKE '\\'%'"] |
|
| 50 | + ['sql_update', 'spip_syndic', ['syndication' => "'sus'"], "syndication LIKE '\\'%'"] |
|
| 51 | 51 | ]; |
| 52 | 52 | |
| 53 | 53 | // Types de fichiers m4a/m4b/m4p/m4u/m4v/dv |
@@ -61,24 +61,24 @@ discard block |
||
| 61 | 61 | // La version 14588 etait une mauvaise piste: |
| 62 | 62 | // Retour en arriere pour ceux qui l'ont subi, ne rien faire sinon |
| 63 | 63 | if (@$GLOBALS['meta']['version_installee'] >= 14588) { |
| 64 | - // "mode" est un mot-cle d'Oracle |
|
| 65 | - $GLOBALS['maj'][14588] = [ |
|
| 66 | - ['sql_alter', 'TABLE spip_documents DROP INDEX mode'], |
|
| 67 | - [ |
|
| 68 | - 'sql_alter', |
|
| 69 | - "TABLE spip_documents CHANGE mode genre ENUM('vignette', 'image', 'document') DEFAULT 'document' NOT NULL" |
|
| 70 | - ], |
|
| 71 | - ['sql_alter', 'TABLE spip_documents ADD INDEX genre(genre)'] |
|
| 72 | - ]; |
|
| 73 | - // solution moins intrusive au pb de mot-cle d'Oracle, retour avant 14588 |
|
| 74 | - $GLOBALS['maj'][14598] = [ |
|
| 75 | - ['sql_alter', 'TABLE spip_documents DROP INDEX genre'], |
|
| 76 | - [ |
|
| 77 | - 'sql_alter', |
|
| 78 | - "TABLE spip_documents CHANGE genre mode ENUM('vignette', 'image', 'document') DEFAULT 'document' NOT NULL" |
|
| 79 | - ], |
|
| 80 | - ['sql_alter', 'TABLE spip_documents ADD INDEX mode(mode)'] |
|
| 81 | - ]; |
|
| 64 | + // "mode" est un mot-cle d'Oracle |
|
| 65 | + $GLOBALS['maj'][14588] = [ |
|
| 66 | + ['sql_alter', 'TABLE spip_documents DROP INDEX mode'], |
|
| 67 | + [ |
|
| 68 | + 'sql_alter', |
|
| 69 | + "TABLE spip_documents CHANGE mode genre ENUM('vignette', 'image', 'document') DEFAULT 'document' NOT NULL" |
|
| 70 | + ], |
|
| 71 | + ['sql_alter', 'TABLE spip_documents ADD INDEX genre(genre)'] |
|
| 72 | + ]; |
|
| 73 | + // solution moins intrusive au pb de mot-cle d'Oracle, retour avant 14588 |
|
| 74 | + $GLOBALS['maj'][14598] = [ |
|
| 75 | + ['sql_alter', 'TABLE spip_documents DROP INDEX genre'], |
|
| 76 | + [ |
|
| 77 | + 'sql_alter', |
|
| 78 | + "TABLE spip_documents CHANGE genre mode ENUM('vignette', 'image', 'document') DEFAULT 'document' NOT NULL" |
|
| 79 | + ], |
|
| 80 | + ['sql_alter', 'TABLE spip_documents ADD INDEX mode(mode)'] |
|
| 81 | + ]; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | // Restauration correcte des types mime des fichiers Ogg |
@@ -18,10 +18,10 @@ |
||
| 18 | 18 | * @package SPIP\Core\SQL\Upgrade |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | $GLOBALS['maj'][23375] = [ |
| 26 | - ['sql_alter', 'TABLE spip_auteurs CHANGE prefs prefs text'], |
|
| 26 | + ['sql_alter', 'TABLE spip_auteurs CHANGE prefs prefs text'], |
|
| 27 | 27 | ]; |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @package SPIP\Core\SQL\Upgrade |
| 21 | 21 | **/ |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | |
@@ -35,49 +35,49 @@ discard block |
||
| 35 | 35 | **/ |
| 36 | 36 | function maj_timestamp_mysql($tables = null) { |
| 37 | 37 | |
| 38 | - include_spip('base/dump'); |
|
| 39 | - if (is_null($tables)) { |
|
| 40 | - $tables = base_lister_toutes_tables(); |
|
| 41 | - } elseif (is_string($tables)) { |
|
| 42 | - $tables = [$tables]; |
|
| 43 | - } elseif (!is_array($tables)) { |
|
| 44 | - return; |
|
| 45 | - } |
|
| 38 | + include_spip('base/dump'); |
|
| 39 | + if (is_null($tables)) { |
|
| 40 | + $tables = base_lister_toutes_tables(); |
|
| 41 | + } elseif (is_string($tables)) { |
|
| 42 | + $tables = [$tables]; |
|
| 43 | + } elseif (!is_array($tables)) { |
|
| 44 | + return; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - // rien a faire si base non mysql |
|
| 48 | - if (strncmp($GLOBALS['connexions'][0]['type'], 'mysql', 5) !== 0) { |
|
| 49 | - return; |
|
| 50 | - } |
|
| 47 | + // rien a faire si base non mysql |
|
| 48 | + if (strncmp($GLOBALS['connexions'][0]['type'], 'mysql', 5) !== 0) { |
|
| 49 | + return; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 53 | - // forcer le vidage de cache |
|
| 54 | - $trouver_table(''); |
|
| 52 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 53 | + // forcer le vidage de cache |
|
| 54 | + $trouver_table(''); |
|
| 55 | 55 | |
| 56 | - foreach ($tables as $table) { |
|
| 57 | - if (time() >= _TIME_OUT) { |
|
| 58 | - return; |
|
| 59 | - } |
|
| 60 | - if ($desc = $trouver_table($table)) { |
|
| 61 | - $fields_corrected = _mysql_remplacements_definitions_table($desc['field']); |
|
| 62 | - $d = array_diff($desc['field'], $fields_corrected); |
|
| 63 | - if ($d) { |
|
| 64 | - spip_log("Table $table TIMESTAMP incorrect", 'maj'); |
|
| 65 | - foreach ($desc['field'] as $field => $type) { |
|
| 66 | - if ($desc['field'][$field] !== $fields_corrected[$field]) { |
|
| 67 | - spip_log("Adaptation TIMESTAMP table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 68 | - sql_alter("table $table change $field $field " . $fields_corrected[$field]); |
|
| 69 | - $trouver_table(''); |
|
| 70 | - $new_desc = $trouver_table($table); |
|
| 71 | - spip_log( |
|
| 72 | - "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 73 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 74 | - ); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - } |
|
| 56 | + foreach ($tables as $table) { |
|
| 57 | + if (time() >= _TIME_OUT) { |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | + if ($desc = $trouver_table($table)) { |
|
| 61 | + $fields_corrected = _mysql_remplacements_definitions_table($desc['field']); |
|
| 62 | + $d = array_diff($desc['field'], $fields_corrected); |
|
| 63 | + if ($d) { |
|
| 64 | + spip_log("Table $table TIMESTAMP incorrect", 'maj'); |
|
| 65 | + foreach ($desc['field'] as $field => $type) { |
|
| 66 | + if ($desc['field'][$field] !== $fields_corrected[$field]) { |
|
| 67 | + spip_log("Adaptation TIMESTAMP table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 68 | + sql_alter("table $table change $field $field " . $fields_corrected[$field]); |
|
| 69 | + $trouver_table(''); |
|
| 70 | + $new_desc = $trouver_table($table); |
|
| 71 | + spip_log( |
|
| 72 | + "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 73 | + 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 74 | + ); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - // forcer le vidage de cache |
|
| 82 | - $trouver_table(''); |
|
| 81 | + // forcer le vidage de cache |
|
| 82 | + $trouver_table(''); |
|
| 83 | 83 | } |
@@ -64,13 +64,13 @@ |
||
| 64 | 64 | spip_log("Table $table TIMESTAMP incorrect", 'maj'); |
| 65 | 65 | foreach ($desc['field'] as $field => $type) { |
| 66 | 66 | if ($desc['field'][$field] !== $fields_corrected[$field]) { |
| 67 | - spip_log("Adaptation TIMESTAMP table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 68 | - sql_alter("table $table change $field $field " . $fields_corrected[$field]); |
|
| 67 | + spip_log("Adaptation TIMESTAMP table $table", 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 68 | + sql_alter("table $table change $field $field ".$fields_corrected[$field]); |
|
| 69 | 69 | $trouver_table(''); |
| 70 | 70 | $new_desc = $trouver_table($table); |
| 71 | 71 | spip_log( |
| 72 | - "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 73 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 72 | + "Apres conversion $table : ".var_export($new_desc['field'], true), |
|
| 73 | + 'maj.'._LOG_INFO_IMPORTANTE |
|
| 74 | 74 | ); |
| 75 | 75 | } |
| 76 | 76 | } |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('maj/legacy/v30'); |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | #if (!$sql_desc) $sql_desc = false; |
| 86 | 86 | #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
| 87 | 87 | if (!$sql_desc) { |
| 88 | - spip_log("Echec creation table $table", 'maj' . _LOG_CRITIQUE); |
|
| 88 | + spip_log("Echec creation table $table", 'maj'._LOG_CRITIQUE); |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | } else { |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | if (isset($desc['field'])) { |
| 98 | 98 | foreach ($desc['field'] as $field => $type) { |
| 99 | 99 | if (!isset($sql_desc['field'][$field])) { |
| 100 | - sql_alter("TABLE $table ADD $field $type" . ($last ? " AFTER $last" : ''), $serveur); |
|
| 100 | + sql_alter("TABLE $table ADD $field $type".($last ? " AFTER $last" : ''), $serveur); |
|
| 101 | 101 | } |
| 102 | 102 | $last = $field; |
| 103 | 103 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Installation |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/acces'); |
@@ -33,18 +33,18 @@ discard block |
||
| 33 | 33 | * @return bool |
| 34 | 34 | */ |
| 35 | 35 | function base_determine_autoinc($table, $desc = []) { |
| 36 | - if ($t = lister_tables_principales() and isset($t[$table])) { |
|
| 37 | - $autoinc = true; |
|
| 38 | - } elseif ($t = lister_tables_auxiliaires() and isset($t[$table])) { |
|
| 39 | - $autoinc = false; |
|
| 40 | - } else { |
|
| 41 | - // essayer de faire au mieux ! |
|
| 42 | - $autoinc = (isset($desc['key']['PRIMARY KEY']) |
|
| 43 | - and !str_contains($desc['key']['PRIMARY KEY'], ',') |
|
| 44 | - and !str_contains($desc['field'][$desc['key']['PRIMARY KEY']], 'default')); |
|
| 45 | - } |
|
| 36 | + if ($t = lister_tables_principales() and isset($t[$table])) { |
|
| 37 | + $autoinc = true; |
|
| 38 | + } elseif ($t = lister_tables_auxiliaires() and isset($t[$table])) { |
|
| 39 | + $autoinc = false; |
|
| 40 | + } else { |
|
| 41 | + // essayer de faire au mieux ! |
|
| 42 | + $autoinc = (isset($desc['key']['PRIMARY KEY']) |
|
| 43 | + and !str_contains($desc['key']['PRIMARY KEY'], ',') |
|
| 44 | + and !str_contains($desc['field'][$desc['key']['PRIMARY KEY']], 'default')); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - return $autoinc; |
|
| 47 | + return $autoinc; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -61,58 +61,58 @@ discard block |
||
| 61 | 61 | * @return void |
| 62 | 62 | */ |
| 63 | 63 | function creer_ou_upgrader_table($table, $desc, $autoinc, $upgrade = false, $serveur = '') { |
| 64 | - #spip_log("creer_ou_upgrader_table table=$table autoinc=$autoinc upgrade=$upgrade","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 65 | - $sql_desc = $upgrade ? sql_showtable($table, true, $serveur) : false; |
|
| 66 | - #if (!$sql_desc) $sql_desc = false; |
|
| 67 | - #spip_log("table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 68 | - if (!$sql_desc) { |
|
| 69 | - if ($autoinc === 'auto') { |
|
| 70 | - $autoinc = base_determine_autoinc($table, $desc); |
|
| 71 | - } |
|
| 72 | - #spip_log("sql_create $table autoinc=$autoinc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 73 | - if (isset($desc['field']) and isset($desc['key'])) { |
|
| 74 | - sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 75 | - } |
|
| 76 | - // verifier la bonne installation de la table (php-fpm es-tu la ?) |
|
| 77 | - $sql_desc = sql_showtable($table, true, $serveur); |
|
| 78 | - #if (!$sql_desc) $sql_desc = false; |
|
| 79 | - #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 80 | - if (!$sql_desc) { |
|
| 81 | - // on retente avec un sleep ? |
|
| 82 | - sleep(1); |
|
| 83 | - sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 84 | - $sql_desc = sql_showtable($table, true, $serveur); |
|
| 85 | - #if (!$sql_desc) $sql_desc = false; |
|
| 86 | - #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 87 | - if (!$sql_desc) { |
|
| 88 | - spip_log("Echec creation table $table", 'maj' . _LOG_CRITIQUE); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } else { |
|
| 92 | - #spip_log("sql_alter $table ... (on s'en fiche)","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 93 | - // ajouter les champs manquants |
|
| 94 | - // on ne supprime jamais les champs, car c'est dangereux |
|
| 95 | - // c'est toujours a faire manuellement |
|
| 96 | - $last = ''; |
|
| 97 | - if (isset($desc['field'])) { |
|
| 98 | - foreach ($desc['field'] as $field => $type) { |
|
| 99 | - if (!isset($sql_desc['field'][$field])) { |
|
| 100 | - sql_alter("TABLE $table ADD $field $type" . ($last ? " AFTER $last" : ''), $serveur); |
|
| 101 | - } |
|
| 102 | - $last = $field; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - if (isset($desc['key'])) { |
|
| 106 | - foreach ($desc['key'] as $key => $type) { |
|
| 107 | - // Ne pas oublier les cas des cles non nommees dans la declaration et qui sont retournees |
|
| 108 | - // par le showtable sous la forme d'un index de tableau "KEY $type" et non "KEY" |
|
| 109 | - if (!isset($sql_desc['key'][$key]) and !isset($sql_desc['key']["$key $type"])) { |
|
| 110 | - sql_alter("TABLE $table ADD $key ($type)", $serveur); |
|
| 111 | - } |
|
| 112 | - $last = $field; |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - } |
|
| 64 | + #spip_log("creer_ou_upgrader_table table=$table autoinc=$autoinc upgrade=$upgrade","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 65 | + $sql_desc = $upgrade ? sql_showtable($table, true, $serveur) : false; |
|
| 66 | + #if (!$sql_desc) $sql_desc = false; |
|
| 67 | + #spip_log("table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 68 | + if (!$sql_desc) { |
|
| 69 | + if ($autoinc === 'auto') { |
|
| 70 | + $autoinc = base_determine_autoinc($table, $desc); |
|
| 71 | + } |
|
| 72 | + #spip_log("sql_create $table autoinc=$autoinc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 73 | + if (isset($desc['field']) and isset($desc['key'])) { |
|
| 74 | + sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 75 | + } |
|
| 76 | + // verifier la bonne installation de la table (php-fpm es-tu la ?) |
|
| 77 | + $sql_desc = sql_showtable($table, true, $serveur); |
|
| 78 | + #if (!$sql_desc) $sql_desc = false; |
|
| 79 | + #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 80 | + if (!$sql_desc) { |
|
| 81 | + // on retente avec un sleep ? |
|
| 82 | + sleep(1); |
|
| 83 | + sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
|
| 84 | + $sql_desc = sql_showtable($table, true, $serveur); |
|
| 85 | + #if (!$sql_desc) $sql_desc = false; |
|
| 86 | + #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 87 | + if (!$sql_desc) { |
|
| 88 | + spip_log("Echec creation table $table", 'maj' . _LOG_CRITIQUE); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + } else { |
|
| 92 | + #spip_log("sql_alter $table ... (on s'en fiche)","dbinstall"._LOG_INFO_IMPORTANTE); |
|
| 93 | + // ajouter les champs manquants |
|
| 94 | + // on ne supprime jamais les champs, car c'est dangereux |
|
| 95 | + // c'est toujours a faire manuellement |
|
| 96 | + $last = ''; |
|
| 97 | + if (isset($desc['field'])) { |
|
| 98 | + foreach ($desc['field'] as $field => $type) { |
|
| 99 | + if (!isset($sql_desc['field'][$field])) { |
|
| 100 | + sql_alter("TABLE $table ADD $field $type" . ($last ? " AFTER $last" : ''), $serveur); |
|
| 101 | + } |
|
| 102 | + $last = $field; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + if (isset($desc['key'])) { |
|
| 106 | + foreach ($desc['key'] as $key => $type) { |
|
| 107 | + // Ne pas oublier les cas des cles non nommees dans la declaration et qui sont retournees |
|
| 108 | + // par le showtable sous la forme d'un index de tableau "KEY $type" et non "KEY" |
|
| 109 | + if (!isset($sql_desc['key'][$key]) and !isset($sql_desc['key']["$key $type"])) { |
|
| 110 | + sql_alter("TABLE $table ADD $key ($type)", $serveur); |
|
| 111 | + } |
|
| 112 | + $last = $field; |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -134,26 +134,26 @@ discard block |
||
| 134 | 134 | * @return void |
| 135 | 135 | */ |
| 136 | 136 | function alterer_base($tables_inc, $tables_noinc, $up = false, $serveur = '') { |
| 137 | - if ($up === false) { |
|
| 138 | - $old = false; |
|
| 139 | - $up = []; |
|
| 140 | - } else { |
|
| 141 | - $old = true; |
|
| 142 | - if (!is_array($up)) { |
|
| 143 | - $up = [$up]; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - foreach ($tables_inc as $k => $v) { |
|
| 147 | - if (!$old or in_array($k, $up)) { |
|
| 148 | - creer_ou_upgrader_table($k, $v, true, $old, $serveur); |
|
| 149 | - } |
|
| 150 | - } |
|
| 137 | + if ($up === false) { |
|
| 138 | + $old = false; |
|
| 139 | + $up = []; |
|
| 140 | + } else { |
|
| 141 | + $old = true; |
|
| 142 | + if (!is_array($up)) { |
|
| 143 | + $up = [$up]; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + foreach ($tables_inc as $k => $v) { |
|
| 147 | + if (!$old or in_array($k, $up)) { |
|
| 148 | + creer_ou_upgrader_table($k, $v, true, $old, $serveur); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - foreach ($tables_noinc as $k => $v) { |
|
| 153 | - if (!$old or in_array($k, $up)) { |
|
| 154 | - creer_ou_upgrader_table($k, $v, false, $old, $serveur); |
|
| 155 | - } |
|
| 156 | - } |
|
| 152 | + foreach ($tables_noinc as $k => $v) { |
|
| 153 | + if (!$old or in_array($k, $up)) { |
|
| 154 | + creer_ou_upgrader_table($k, $v, false, $old, $serveur); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -173,16 +173,16 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | function creer_base($serveur = '') { |
| 175 | 175 | |
| 176 | - // Note: les mises a jour reexecutent ce code pour s'assurer |
|
| 177 | - // de la conformite de la base |
|
| 178 | - // pas de panique sur "already exists" et "duplicate entry" donc. |
|
| 176 | + // Note: les mises a jour reexecutent ce code pour s'assurer |
|
| 177 | + // de la conformite de la base |
|
| 178 | + // pas de panique sur "already exists" et "duplicate entry" donc. |
|
| 179 | 179 | |
| 180 | - alterer_base( |
|
| 181 | - lister_tables_principales(), |
|
| 182 | - lister_tables_auxiliaires(), |
|
| 183 | - false, |
|
| 184 | - $serveur |
|
| 185 | - ); |
|
| 180 | + alterer_base( |
|
| 181 | + lister_tables_principales(), |
|
| 182 | + lister_tables_auxiliaires(), |
|
| 183 | + false, |
|
| 184 | + $serveur |
|
| 185 | + ); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -202,10 +202,10 @@ discard block |
||
| 202 | 202 | * @return void |
| 203 | 203 | */ |
| 204 | 204 | function maj_tables($upgrade_tables = [], $serveur = '') { |
| 205 | - alterer_base( |
|
| 206 | - lister_tables_principales(), |
|
| 207 | - lister_tables_auxiliaires(), |
|
| 208 | - $upgrade_tables, |
|
| 209 | - $serveur |
|
| 210 | - ); |
|
| 205 | + alterer_base( |
|
| 206 | + lister_tables_principales(), |
|
| 207 | + lister_tables_auxiliaires(), |
|
| 208 | + $upgrade_tables, |
|
| 209 | + $serveur |
|
| 210 | + ); |
|
| 211 | 211 | } |