@@ -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 | |
@@ -21,28 +21,28 @@ discard block |
||
| 21 | 21 | * @param array $arbre |
| 22 | 22 | */ |
| 23 | 23 | function plugins_extraire_pipelines_dist(&$arbre) { |
| 24 | - $pipes = null; |
|
| 25 | - $tag = null; |
|
| 26 | - $pipeline = []; |
|
| 27 | - if (spip_xml_match_nodes(',^pipeline,', $arbre, $pipes)) { |
|
| 28 | - foreach ($pipes as $tag => $p) { |
|
| 29 | - if (!is_array($p[0])) { |
|
| 30 | - [$tag, $att] = spip_xml_decompose_tag($tag); |
|
| 31 | - $pipeline[] = $att; |
|
| 32 | - } else { |
|
| 33 | - foreach ($p as $pipe) { |
|
| 34 | - $att = []; |
|
| 35 | - if (is_array($pipe)) { |
|
| 36 | - foreach ($pipe as $k => $t) { |
|
| 37 | - $att[$k] = trim(end($t)); |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - $pipeline[] = $att; |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - } |
|
| 44 | - unset($arbre[$tag]); |
|
| 45 | - } |
|
| 24 | + $pipes = null; |
|
| 25 | + $tag = null; |
|
| 26 | + $pipeline = []; |
|
| 27 | + if (spip_xml_match_nodes(',^pipeline,', $arbre, $pipes)) { |
|
| 28 | + foreach ($pipes as $tag => $p) { |
|
| 29 | + if (!is_array($p[0])) { |
|
| 30 | + [$tag, $att] = spip_xml_decompose_tag($tag); |
|
| 31 | + $pipeline[] = $att; |
|
| 32 | + } else { |
|
| 33 | + foreach ($p as $pipe) { |
|
| 34 | + $att = []; |
|
| 35 | + if (is_array($pipe)) { |
|
| 36 | + foreach ($pipe as $k => $t) { |
|
| 37 | + $att[$k] = trim(end($t)); |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + $pipeline[] = $att; |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | + unset($arbre[$tag]); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - return $pipeline; |
|
| 47 | + return $pipeline; |
|
| 48 | 48 | } |
@@ -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 | /** |
@@ -25,64 +25,64 @@ discard block |
||
| 25 | 25 | * @return array |
| 26 | 26 | */ |
| 27 | 27 | function plugins_infos_paquet($desc, $plug = '', $dir_plugins = _DIR_PLUGINS) { |
| 28 | - static $process = [ // tableau constant |
|
| 29 | - 'debut' => 'paquet_debutElement', |
|
| 30 | - 'fin' => 'paquet_finElement', |
|
| 31 | - 'text' => 'paquet_textElement' |
|
| 32 | - ]; |
|
| 33 | - |
|
| 34 | - $valider_xml = charger_fonction('valider', 'xml'); |
|
| 35 | - $vxml = $valider_xml($desc, false, $process, 'paquet.dtd', 'utf-8'); |
|
| 36 | - if (!$vxml->err) { |
|
| 37 | - // On veut toutes les variantes selon la version de SPIP |
|
| 38 | - if (!$plug) { |
|
| 39 | - return $vxml->versions; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - // compatibilite avec l'existant: |
|
| 43 | - $tree = $vxml->versions['0']; |
|
| 44 | - |
|
| 45 | - // l'arbre renvoie parfois un tag vide... etrange. Pas la peine de garder ca. |
|
| 46 | - if (isset($tree['']) and !strlen($tree[''])) { |
|
| 47 | - unset($tree['']); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - $tree['slogan'] = $tree['prefix'] . '_slogan'; |
|
| 51 | - $tree['description'] = $tree['prefix'] . '_description'; |
|
| 52 | - paquet_readable_files($tree, "$dir_plugins$plug/"); |
|
| 53 | - if (!$tree['chemin']) { |
|
| 54 | - $tree['chemin'] = []; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - // On verifie qu'il existe des balises spip qu'il faudrait rajouter dans |
|
| 58 | - // la structure d'infos du paquet en fonction de la version spip courante |
|
| 59 | - if ((is_countable($vxml->versions) ? count($vxml->versions) : 0) > 1) { |
|
| 60 | - $vspip = $GLOBALS['spip_version_branche']; |
|
| 61 | - foreach ($vxml->versions as $_compatibilite => $_version) { |
|
| 62 | - if ( |
|
| 63 | - ($_version['balise'] == 'spip') |
|
| 64 | - and (plugin_version_compatible($_compatibilite, $vspip, 'spip')) |
|
| 65 | - ) { |
|
| 66 | - // on merge les sous-balises de la balise spip compatible avec celles de la |
|
| 67 | - // balise paquet |
|
| 68 | - foreach ($_version as $_index => $_balise) { |
|
| 69 | - if ($_index and $_index != 'balise') { |
|
| 70 | - $tree[$_index] = array_merge($tree[$_index], $_balise); |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - return $tree; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // Prendre les messages d'erreur sans les numeros de lignes |
|
| 81 | - $msg = array_column($vxml->err, 0); |
|
| 82 | - $t = _T('plugins_erreur', ['plugins' => $plug]); |
|
| 83 | - array_unshift($msg, $t . " <ul class='erreur_xml'><li>" . reset($msg) . '</li></ul>'); |
|
| 84 | - |
|
| 85 | - return ['erreur' => $msg]; |
|
| 28 | + static $process = [ // tableau constant |
|
| 29 | + 'debut' => 'paquet_debutElement', |
|
| 30 | + 'fin' => 'paquet_finElement', |
|
| 31 | + 'text' => 'paquet_textElement' |
|
| 32 | + ]; |
|
| 33 | + |
|
| 34 | + $valider_xml = charger_fonction('valider', 'xml'); |
|
| 35 | + $vxml = $valider_xml($desc, false, $process, 'paquet.dtd', 'utf-8'); |
|
| 36 | + if (!$vxml->err) { |
|
| 37 | + // On veut toutes les variantes selon la version de SPIP |
|
| 38 | + if (!$plug) { |
|
| 39 | + return $vxml->versions; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + // compatibilite avec l'existant: |
|
| 43 | + $tree = $vxml->versions['0']; |
|
| 44 | + |
|
| 45 | + // l'arbre renvoie parfois un tag vide... etrange. Pas la peine de garder ca. |
|
| 46 | + if (isset($tree['']) and !strlen($tree[''])) { |
|
| 47 | + unset($tree['']); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + $tree['slogan'] = $tree['prefix'] . '_slogan'; |
|
| 51 | + $tree['description'] = $tree['prefix'] . '_description'; |
|
| 52 | + paquet_readable_files($tree, "$dir_plugins$plug/"); |
|
| 53 | + if (!$tree['chemin']) { |
|
| 54 | + $tree['chemin'] = []; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + // On verifie qu'il existe des balises spip qu'il faudrait rajouter dans |
|
| 58 | + // la structure d'infos du paquet en fonction de la version spip courante |
|
| 59 | + if ((is_countable($vxml->versions) ? count($vxml->versions) : 0) > 1) { |
|
| 60 | + $vspip = $GLOBALS['spip_version_branche']; |
|
| 61 | + foreach ($vxml->versions as $_compatibilite => $_version) { |
|
| 62 | + if ( |
|
| 63 | + ($_version['balise'] == 'spip') |
|
| 64 | + and (plugin_version_compatible($_compatibilite, $vspip, 'spip')) |
|
| 65 | + ) { |
|
| 66 | + // on merge les sous-balises de la balise spip compatible avec celles de la |
|
| 67 | + // balise paquet |
|
| 68 | + foreach ($_version as $_index => $_balise) { |
|
| 69 | + if ($_index and $_index != 'balise') { |
|
| 70 | + $tree[$_index] = array_merge($tree[$_index], $_balise); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + return $tree; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // Prendre les messages d'erreur sans les numeros de lignes |
|
| 81 | + $msg = array_column($vxml->err, 0); |
|
| 82 | + $t = _T('plugins_erreur', ['plugins' => $plug]); |
|
| 83 | + array_unshift($msg, $t . " <ul class='erreur_xml'><li>" . reset($msg) . '</li></ul>'); |
|
| 84 | + |
|
| 85 | + return ['erreur' => $msg]; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -94,11 +94,11 @@ discard block |
||
| 94 | 94 | * @return void |
| 95 | 95 | */ |
| 96 | 96 | function paquet_readable_files(&$tree, $dir) { |
| 97 | - $prefix = strtolower($tree['prefix']); |
|
| 97 | + $prefix = strtolower($tree['prefix']); |
|
| 98 | 98 | |
| 99 | - $tree['options'] = (is_readable($dir . $f = ($prefix . '_options.php'))) ? [$f] : []; |
|
| 100 | - $tree['fonctions'] = (is_readable($dir . $f = ($prefix . '_fonctions.php'))) ? [$f] : []; |
|
| 101 | - $tree['install'] = (is_readable($dir . $f = ($prefix . '_administrations.php'))) ? [$f] : []; |
|
| 99 | + $tree['options'] = (is_readable($dir . $f = ($prefix . '_options.php'))) ? [$f] : []; |
|
| 100 | + $tree['fonctions'] = (is_readable($dir . $f = ($prefix . '_fonctions.php'))) ? [$f] : []; |
|
| 101 | + $tree['install'] = (is_readable($dir . $f = ($prefix . '_administrations.php'))) ? [$f] : []; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -115,35 +115,35 @@ discard block |
||
| 115 | 115 | * @param array $attrs |
| 116 | 116 | */ |
| 117 | 117 | function paquet_debutElement($phraseur, $name, $attrs) { |
| 118 | - xml_debutElement($phraseur, $name, $attrs); |
|
| 119 | - if ($phraseur->err) { |
|
| 120 | - return; |
|
| 121 | - } |
|
| 122 | - if (($name == 'paquet') or ($name == 'spip')) { |
|
| 123 | - if ($name == 'spip') { |
|
| 124 | - $n = $attrs['compatibilite']; |
|
| 125 | - $attrs = []; |
|
| 126 | - } else { |
|
| 127 | - $n = '0'; |
|
| 128 | - $phraseur->contenu['paquet'] = $attrs; |
|
| 129 | - $attrs['menu'] = []; |
|
| 130 | - $attrs['chemin'] = []; |
|
| 131 | - $attrs['necessite'] = []; |
|
| 132 | - $attrs['lib'] = []; |
|
| 133 | - $attrs['onglet'] = []; |
|
| 134 | - $attrs['procure'] = []; |
|
| 135 | - $attrs['pipeline'] = []; |
|
| 136 | - $attrs['utilise'] = []; |
|
| 137 | - $attrs['style'] = []; |
|
| 138 | - $attrs['script'] = []; |
|
| 139 | - $attrs['genie'] = []; |
|
| 140 | - } |
|
| 141 | - $phraseur->contenu['compatible'] = $n; |
|
| 142 | - $phraseur->versions[$phraseur->contenu['compatible']] = $attrs; |
|
| 143 | - } else { |
|
| 144 | - $phraseur->versions[$phraseur->contenu['compatible']][$name][0] = $attrs; |
|
| 145 | - } |
|
| 146 | - $phraseur->versions[$phraseur->contenu['compatible']][''] = ''; |
|
| 118 | + xml_debutElement($phraseur, $name, $attrs); |
|
| 119 | + if ($phraseur->err) { |
|
| 120 | + return; |
|
| 121 | + } |
|
| 122 | + if (($name == 'paquet') or ($name == 'spip')) { |
|
| 123 | + if ($name == 'spip') { |
|
| 124 | + $n = $attrs['compatibilite']; |
|
| 125 | + $attrs = []; |
|
| 126 | + } else { |
|
| 127 | + $n = '0'; |
|
| 128 | + $phraseur->contenu['paquet'] = $attrs; |
|
| 129 | + $attrs['menu'] = []; |
|
| 130 | + $attrs['chemin'] = []; |
|
| 131 | + $attrs['necessite'] = []; |
|
| 132 | + $attrs['lib'] = []; |
|
| 133 | + $attrs['onglet'] = []; |
|
| 134 | + $attrs['procure'] = []; |
|
| 135 | + $attrs['pipeline'] = []; |
|
| 136 | + $attrs['utilise'] = []; |
|
| 137 | + $attrs['style'] = []; |
|
| 138 | + $attrs['script'] = []; |
|
| 139 | + $attrs['genie'] = []; |
|
| 140 | + } |
|
| 141 | + $phraseur->contenu['compatible'] = $n; |
|
| 142 | + $phraseur->versions[$phraseur->contenu['compatible']] = $attrs; |
|
| 143 | + } else { |
|
| 144 | + $phraseur->versions[$phraseur->contenu['compatible']][$name][0] = $attrs; |
|
| 145 | + } |
|
| 146 | + $phraseur->versions[$phraseur->contenu['compatible']][''] = ''; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -155,11 +155,11 @@ discard block |
||
| 155 | 155 | * @param string $data |
| 156 | 156 | */ |
| 157 | 157 | function paquet_textElement($phraseur, $data) { |
| 158 | - xml_textElement($phraseur, $data); |
|
| 159 | - if ($phraseur->err or !(trim($data))) { |
|
| 160 | - return; |
|
| 161 | - } |
|
| 162 | - $phraseur->versions[$phraseur->contenu['compatible']][''] .= $data; |
|
| 158 | + xml_textElement($phraseur, $data); |
|
| 159 | + if ($phraseur->err or !(trim($data))) { |
|
| 160 | + return; |
|
| 161 | + } |
|
| 162 | + $phraseur->versions[$phraseur->contenu['compatible']][''] .= $data; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -171,32 +171,32 @@ discard block |
||
| 171 | 171 | * @param string $name |
| 172 | 172 | */ |
| 173 | 173 | function paquet_finElement($phraseur, $name) { |
| 174 | - if ($phraseur->err) { |
|
| 175 | - return; |
|
| 176 | - } |
|
| 177 | - $n = $phraseur->contenu['compatible']; |
|
| 178 | - |
|
| 179 | - if (isset($phraseur->versions[$n][$name][0]) and is_array($phraseur->versions[$n][$name][0])) { |
|
| 180 | - $attrs = $phraseur->versions[$n][$name][0]; |
|
| 181 | - unset($phraseur->versions[$n][$name][0]); |
|
| 182 | - } else { |
|
| 183 | - $attrs = []; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $texte = trim($phraseur->versions[$n]['']); |
|
| 187 | - $phraseur->versions[$n][''] = ''; |
|
| 188 | - |
|
| 189 | - $f = 'info_paquet_' . $name; |
|
| 190 | - if (function_exists($f)) { |
|
| 191 | - $f($phraseur, $attrs, $texte); |
|
| 192 | - } elseif (!$attrs) { |
|
| 193 | - $phraseur->versions[$n][$name] = $texte; |
|
| 194 | - } else { |
|
| 195 | - // Traitement generique. Si $attrs['nom'] n'existe pas, ce n'est pas normal ici |
|
| 196 | - $phraseur->versions[$n][$name][$attrs['nom']] = $attrs; |
|
| 197 | - # echo("<br>pour $name $n " . $attrs['nom']); var_dump($phraseur->versions[$n]); |
|
| 198 | - } |
|
| 199 | - xml_finElement($phraseur, $name, $attrs); |
|
| 174 | + if ($phraseur->err) { |
|
| 175 | + return; |
|
| 176 | + } |
|
| 177 | + $n = $phraseur->contenu['compatible']; |
|
| 178 | + |
|
| 179 | + if (isset($phraseur->versions[$n][$name][0]) and is_array($phraseur->versions[$n][$name][0])) { |
|
| 180 | + $attrs = $phraseur->versions[$n][$name][0]; |
|
| 181 | + unset($phraseur->versions[$n][$name][0]); |
|
| 182 | + } else { |
|
| 183 | + $attrs = []; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $texte = trim($phraseur->versions[$n]['']); |
|
| 187 | + $phraseur->versions[$n][''] = ''; |
|
| 188 | + |
|
| 189 | + $f = 'info_paquet_' . $name; |
|
| 190 | + if (function_exists($f)) { |
|
| 191 | + $f($phraseur, $attrs, $texte); |
|
| 192 | + } elseif (!$attrs) { |
|
| 193 | + $phraseur->versions[$n][$name] = $texte; |
|
| 194 | + } else { |
|
| 195 | + // Traitement generique. Si $attrs['nom'] n'existe pas, ce n'est pas normal ici |
|
| 196 | + $phraseur->versions[$n][$name][$attrs['nom']] = $attrs; |
|
| 197 | + # echo("<br>pour $name $n " . $attrs['nom']); var_dump($phraseur->versions[$n]); |
|
| 198 | + } |
|
| 199 | + xml_finElement($phraseur, $name, $attrs); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -208,13 +208,13 @@ discard block |
||
| 208 | 208 | * @param string $texte |
| 209 | 209 | */ |
| 210 | 210 | function info_paquet_licence($phraseur, $attrs, $texte) { |
| 211 | - if (isset($attrs['lien'])) { |
|
| 212 | - $lien = $attrs['lien']; |
|
| 213 | - } else { |
|
| 214 | - $lien = ''; |
|
| 215 | - } |
|
| 216 | - $n = $phraseur->contenu['compatible']; |
|
| 217 | - $phraseur->versions[$n]['licence'][] = ['nom' => $texte, 'url' => $lien]; |
|
| 211 | + if (isset($attrs['lien'])) { |
|
| 212 | + $lien = $attrs['lien']; |
|
| 213 | + } else { |
|
| 214 | + $lien = ''; |
|
| 215 | + } |
|
| 216 | + $n = $phraseur->contenu['compatible']; |
|
| 217 | + $phraseur->versions[$n]['licence'][] = ['nom' => $texte, 'url' => $lien]; |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -226,14 +226,14 @@ discard block |
||
| 226 | 226 | * @param string $texte |
| 227 | 227 | */ |
| 228 | 228 | function info_paquet_chemin($phraseur, $attrs, $texte) { |
| 229 | - $n = $phraseur->contenu['compatible']; |
|
| 230 | - if (isset($attrs['path'])) { |
|
| 231 | - if (isset($attrs['type'])) { |
|
| 232 | - $phraseur->versions[$n]['chemin'][] = ['path' => $attrs['path'], 'type' => $attrs['type']]; |
|
| 233 | - } else { |
|
| 234 | - $phraseur->versions[$n]['chemin'][] = ['path' => $attrs['path']]; |
|
| 235 | - } |
|
| 236 | - } |
|
| 229 | + $n = $phraseur->contenu['compatible']; |
|
| 230 | + if (isset($attrs['path'])) { |
|
| 231 | + if (isset($attrs['type'])) { |
|
| 232 | + $phraseur->versions[$n]['chemin'][] = ['path' => $attrs['path'], 'type' => $attrs['type']]; |
|
| 233 | + } else { |
|
| 234 | + $phraseur->versions[$n]['chemin'][] = ['path' => $attrs['path']]; |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | |
@@ -247,24 +247,24 @@ discard block |
||
| 247 | 247 | * @param string $texte |
| 248 | 248 | */ |
| 249 | 249 | function info_paquet_auteur($phraseur, $attrs, $texte) { |
| 250 | - # echo 'auteur ', $texte; var_dump($attrs); |
|
| 251 | - if (isset($attrs['mail'])) { |
|
| 252 | - if (strpos($attrs['mail'], '@')) { |
|
| 253 | - $attrs['mail'] = str_replace('@', ' AT ', $attrs['mail']); |
|
| 254 | - } |
|
| 255 | - $mail = $attrs['mail']; |
|
| 256 | - } else { |
|
| 257 | - $mail = ''; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - if (isset($attrs['lien'])) { |
|
| 261 | - $lien = $attrs['lien']; |
|
| 262 | - } else { |
|
| 263 | - $lien = ''; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - $n = $phraseur->contenu['compatible']; |
|
| 267 | - $phraseur->versions[$n]['auteur'][] = ['nom' => $texte, 'url' => $lien, 'mail' => $mail]; |
|
| 250 | + # echo 'auteur ', $texte; var_dump($attrs); |
|
| 251 | + if (isset($attrs['mail'])) { |
|
| 252 | + if (strpos($attrs['mail'], '@')) { |
|
| 253 | + $attrs['mail'] = str_replace('@', ' AT ', $attrs['mail']); |
|
| 254 | + } |
|
| 255 | + $mail = $attrs['mail']; |
|
| 256 | + } else { |
|
| 257 | + $mail = ''; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + if (isset($attrs['lien'])) { |
|
| 261 | + $lien = $attrs['lien']; |
|
| 262 | + } else { |
|
| 263 | + $lien = ''; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + $n = $phraseur->contenu['compatible']; |
|
| 267 | + $phraseur->versions[$n]['auteur'][] = ['nom' => $texte, 'url' => $lien, 'mail' => $mail]; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -277,14 +277,14 @@ discard block |
||
| 277 | 277 | */ |
| 278 | 278 | function info_paquet_credit($phraseur, $attrs, $texte) { |
| 279 | 279 | |
| 280 | - if (isset($attrs['lien'])) { |
|
| 281 | - $lien = $attrs['lien']; |
|
| 282 | - } else { |
|
| 283 | - $lien = ''; |
|
| 284 | - } |
|
| 280 | + if (isset($attrs['lien'])) { |
|
| 281 | + $lien = $attrs['lien']; |
|
| 282 | + } else { |
|
| 283 | + $lien = ''; |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - $n = $phraseur->contenu['compatible']; |
|
| 287 | - $phraseur->versions[$n]['credit'][] = ['nom' => $texte, 'url' => $lien]; |
|
| 286 | + $n = $phraseur->contenu['compatible']; |
|
| 287 | + $phraseur->versions[$n]['credit'][] = ['nom' => $texte, 'url' => $lien]; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -296,8 +296,8 @@ discard block |
||
| 296 | 296 | * @param string $texte |
| 297 | 297 | */ |
| 298 | 298 | function info_paquet_copyright($phraseur, $attrs, $texte) { |
| 299 | - $n = $phraseur->contenu['compatible']; |
|
| 300 | - $phraseur->versions[$n]['copyright'][] = $texte; |
|
| 299 | + $n = $phraseur->contenu['compatible']; |
|
| 300 | + $phraseur->versions[$n]['copyright'][] = $texte; |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | /** |
@@ -309,9 +309,9 @@ discard block |
||
| 309 | 309 | * @param string $texte |
| 310 | 310 | */ |
| 311 | 311 | function info_paquet_paquet($phraseur, $attrs, $texte) { |
| 312 | - $n = 0; |
|
| 313 | - $phraseur->versions[$n]['dtd'] = 'paquet'; |
|
| 314 | - $phraseur->versions[$n]['balise'] = 'paquet'; |
|
| 312 | + $n = 0; |
|
| 313 | + $phraseur->versions[$n]['dtd'] = 'paquet'; |
|
| 314 | + $phraseur->versions[$n]['balise'] = 'paquet'; |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
@@ -323,8 +323,8 @@ discard block |
||
| 323 | 323 | * @param string $texte |
| 324 | 324 | **/ |
| 325 | 325 | function info_paquet_traduire($phraseur, $attrs, $texte) { |
| 326 | - $n = $phraseur->contenu['compatible']; |
|
| 327 | - $phraseur->versions[$n]['traduire'][] = $attrs; |
|
| 326 | + $n = $phraseur->contenu['compatible']; |
|
| 327 | + $phraseur->versions[$n]['traduire'][] = $attrs; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -336,8 +336,8 @@ discard block |
||
| 336 | 336 | * @param string $texte |
| 337 | 337 | */ |
| 338 | 338 | function info_paquet_spip($phraseur, $attrs, $texte) { |
| 339 | - $n = $phraseur->contenu['compatible']; |
|
| 340 | - $phraseur->versions[$n]['balise'] = 'spip'; |
|
| 339 | + $n = $phraseur->contenu['compatible']; |
|
| 340 | + $phraseur->versions[$n]['balise'] = 'spip'; |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | |
@@ -349,8 +349,8 @@ discard block |
||
| 349 | 349 | * @param string $texte |
| 350 | 350 | */ |
| 351 | 351 | function info_paquet_pipeline($phraseur, $attrs, $texte) { |
| 352 | - $n = $phraseur->contenu['compatible']; |
|
| 353 | - $phraseur->versions[$n]['pipeline'][] = $attrs; |
|
| 352 | + $n = $phraseur->contenu['compatible']; |
|
| 353 | + $phraseur->versions[$n]['pipeline'][] = $attrs; |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | |
@@ -363,23 +363,23 @@ discard block |
||
| 363 | 363 | * @param string $texte |
| 364 | 364 | */ |
| 365 | 365 | function info_paquet_style($phraseur, $attrs, $texte) { |
| 366 | - $lien = $chemin = $type = $media = ''; |
|
| 367 | - |
|
| 368 | - include_spip('inc/utils'); |
|
| 369 | - if (tester_url_absolue($attrs['source'])) { |
|
| 370 | - $lien = $attrs['source']; |
|
| 371 | - } else { |
|
| 372 | - $chemin = $attrs['source']; |
|
| 373 | - } |
|
| 374 | - if (isset($attrs['type'])) { |
|
| 375 | - $type = $attrs['type']; |
|
| 376 | - } |
|
| 377 | - if (isset($attrs['media'])) { |
|
| 378 | - $media = $attrs['media']; |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - $n = $phraseur->contenu['compatible']; |
|
| 382 | - $phraseur->versions[$n]['style'][] = ['url' => $lien, 'path' => $chemin, 'type' => $type, 'media' => $media]; |
|
| 366 | + $lien = $chemin = $type = $media = ''; |
|
| 367 | + |
|
| 368 | + include_spip('inc/utils'); |
|
| 369 | + if (tester_url_absolue($attrs['source'])) { |
|
| 370 | + $lien = $attrs['source']; |
|
| 371 | + } else { |
|
| 372 | + $chemin = $attrs['source']; |
|
| 373 | + } |
|
| 374 | + if (isset($attrs['type'])) { |
|
| 375 | + $type = $attrs['type']; |
|
| 376 | + } |
|
| 377 | + if (isset($attrs['media'])) { |
|
| 378 | + $media = $attrs['media']; |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + $n = $phraseur->contenu['compatible']; |
|
| 382 | + $phraseur->versions[$n]['style'][] = ['url' => $lien, 'path' => $chemin, 'type' => $type, 'media' => $media]; |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | |
@@ -392,20 +392,20 @@ discard block |
||
| 392 | 392 | * @param string $texte |
| 393 | 393 | */ |
| 394 | 394 | function info_paquet_script($phraseur, $attrs, $texte) { |
| 395 | - $lien = $chemin = $type = $media = ''; |
|
| 396 | - |
|
| 397 | - include_spip('inc/utils'); |
|
| 398 | - if (tester_url_absolue($attrs['source'])) { |
|
| 399 | - $lien = $attrs['source']; |
|
| 400 | - } else { |
|
| 401 | - $chemin = $attrs['source']; |
|
| 402 | - } |
|
| 403 | - if (isset($attrs['type'])) { |
|
| 404 | - $type = $attrs['type']; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - $n = $phraseur->contenu['compatible']; |
|
| 408 | - $phraseur->versions[$n]['script'][] = ['url' => $lien, 'path' => $chemin, 'type' => $type]; |
|
| 395 | + $lien = $chemin = $type = $media = ''; |
|
| 396 | + |
|
| 397 | + include_spip('inc/utils'); |
|
| 398 | + if (tester_url_absolue($attrs['source'])) { |
|
| 399 | + $lien = $attrs['source']; |
|
| 400 | + } else { |
|
| 401 | + $chemin = $attrs['source']; |
|
| 402 | + } |
|
| 403 | + if (isset($attrs['type'])) { |
|
| 404 | + $type = $attrs['type']; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + $n = $phraseur->contenu['compatible']; |
|
| 408 | + $phraseur->versions[$n]['script'][] = ['url' => $lien, 'path' => $chemin, 'type' => $type]; |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
@@ -416,6 +416,6 @@ discard block |
||
| 416 | 416 | * @param string $texte |
| 417 | 417 | */ |
| 418 | 418 | function info_paquet_genie($phraseur, $attrs, $texte) { |
| 419 | - $n = $phraseur->contenu['compatible']; |
|
| 420 | - $phraseur->versions[$n]['genie'][] = $attrs; |
|
| 419 | + $n = $phraseur->contenu['compatible']; |
|
| 420 | + $phraseur->versions[$n]['genie'][] = $attrs; |
|
| 421 | 421 | } |
@@ -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 | /** |
@@ -21,31 +21,31 @@ discard block |
||
| 21 | 21 | * @return <type> |
| 22 | 22 | */ |
| 23 | 23 | function plugins_extraire_boutons_dist($arbre) { |
| 24 | - $les_boutons = null; |
|
| 25 | - $ret = ['bouton' => [], 'onglet' => []]; |
|
| 26 | - // recuperer les boutons et onglets si necessaire |
|
| 27 | - spip_xml_match_nodes(',^(bouton|onglet)\s,', $arbre, $les_boutons); |
|
| 28 | - if (is_array($les_boutons) && count($les_boutons)) { |
|
| 29 | - $ret['bouton'] = []; |
|
| 30 | - $ret['onglet'] = []; |
|
| 31 | - foreach ($les_boutons as $bouton => $val) { |
|
| 32 | - $bouton = spip_xml_decompose_tag($bouton); |
|
| 33 | - $type = reset($bouton); |
|
| 34 | - $bouton = end($bouton); |
|
| 35 | - if (isset($bouton['id'])) { |
|
| 36 | - $id = $bouton['id']; |
|
| 37 | - $val = reset($val); |
|
| 38 | - if (is_array($val)) { |
|
| 39 | - $ret[$type][$id]['parent'] = $bouton['parent'] ?? ''; |
|
| 40 | - $ret[$type][$id]['position'] = $bouton['position'] ?? ''; |
|
| 41 | - $ret[$type][$id]['titre'] = isset($val['titre']) ? trim(spip_xml_aplatit($val['titre'])) : ''; |
|
| 42 | - $ret[$type][$id]['icone'] = isset($val['icone']) ? trim(end($val['icone'])) : ''; |
|
| 43 | - $ret[$type][$id]['action'] = isset($val['url']) ? trim(end($val['url'])) : ''; |
|
| 44 | - $ret[$type][$id]['parametres'] = isset($val['args']) ? trim(end($val['args'])) : ''; |
|
| 45 | - } |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - } |
|
| 24 | + $les_boutons = null; |
|
| 25 | + $ret = ['bouton' => [], 'onglet' => []]; |
|
| 26 | + // recuperer les boutons et onglets si necessaire |
|
| 27 | + spip_xml_match_nodes(',^(bouton|onglet)\s,', $arbre, $les_boutons); |
|
| 28 | + if (is_array($les_boutons) && count($les_boutons)) { |
|
| 29 | + $ret['bouton'] = []; |
|
| 30 | + $ret['onglet'] = []; |
|
| 31 | + foreach ($les_boutons as $bouton => $val) { |
|
| 32 | + $bouton = spip_xml_decompose_tag($bouton); |
|
| 33 | + $type = reset($bouton); |
|
| 34 | + $bouton = end($bouton); |
|
| 35 | + if (isset($bouton['id'])) { |
|
| 36 | + $id = $bouton['id']; |
|
| 37 | + $val = reset($val); |
|
| 38 | + if (is_array($val)) { |
|
| 39 | + $ret[$type][$id]['parent'] = $bouton['parent'] ?? ''; |
|
| 40 | + $ret[$type][$id]['position'] = $bouton['position'] ?? ''; |
|
| 41 | + $ret[$type][$id]['titre'] = isset($val['titre']) ? trim(spip_xml_aplatit($val['titre'])) : ''; |
|
| 42 | + $ret[$type][$id]['icone'] = isset($val['icone']) ? trim(end($val['icone'])) : ''; |
|
| 43 | + $ret[$type][$id]['action'] = isset($val['url']) ? trim(end($val['url'])) : ''; |
|
| 44 | + $ret[$type][$id]['parametres'] = isset($val['args']) ? trim(end($val['args'])) : ''; |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return $ret; |
|
| 50 | + return $ret; |
|
| 51 | 51 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -54,96 +54,96 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | function plugins_installer_dist($plug, $action, $dir_type = '_DIR_PLUGINS') { |
| 56 | 56 | |
| 57 | - // Charger les informations du XML du plugin et vérification de l'existence d'une installation |
|
| 58 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 59 | - $infos = $get_infos($plug, false, constant($dir_type)); |
|
| 60 | - if (!isset($infos['install']) or !$infos['install']) { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - // Passer en chemin absolu si possible, c'est plus efficace |
|
| 65 | - $dir = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 66 | - if (!defined($dir)) { |
|
| 67 | - $dir = $dir_type; |
|
| 68 | - } |
|
| 69 | - $dir = constant($dir); |
|
| 70 | - foreach ($infos['install'] as $file) { |
|
| 71 | - $file = $dir . $plug . '/' . trim($file); |
|
| 72 | - if (file_exists($file)) { |
|
| 73 | - include_once($file); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - // Détermination de la table meta et du nom de la meta plugin |
|
| 78 | - $table = 'meta'; |
|
| 79 | - if (isset($infos['meta']) and ($infos['meta'] !== 'meta')) { |
|
| 80 | - $table = $infos['meta']; |
|
| 81 | - // S'assurer que les metas de la table spécifique sont bien accessibles dans la globale |
|
| 82 | - lire_metas($table); |
|
| 83 | - } |
|
| 84 | - $nom_meta = $infos['prefix'] . '_base_version'; |
|
| 85 | - |
|
| 86 | - // Détermination de la fonction à appeler et de ses arguments |
|
| 87 | - $f = $infos['prefix'] . '_install'; |
|
| 88 | - if (!function_exists($f)) { |
|
| 89 | - $f = isset($infos['schema']) ? 'spip_plugin_install' : ''; |
|
| 90 | - $arg = $infos; |
|
| 91 | - // On passe la table et la meta pour éviter de les recalculer dans la fonction appelée |
|
| 92 | - $arg['meta'] = $table; |
|
| 93 | - $arg['nom_meta'] = $nom_meta; |
|
| 94 | - } else { |
|
| 95 | - // Ancienne méthode d'installation - TODO à supprimer à terme |
|
| 96 | - // stupide: info deja dans le nom |
|
| 97 | - $arg = $infos['prefix']; |
|
| 98 | - } |
|
| 99 | - $version = $infos['schema'] ?? ''; |
|
| 100 | - |
|
| 101 | - if (!$f) { |
|
| 102 | - // installation sans operation particuliere |
|
| 103 | - $infos['install_test'] = [true, '']; |
|
| 104 | - return $infos; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - // Tester si l'action demandée est nécessaire ou pas. |
|
| 108 | - $test = $f('test', $arg, $version); |
|
| 109 | - if ($action == 'uninstall') { |
|
| 110 | - $test = !$test; |
|
| 111 | - } |
|
| 112 | - // Si deja fait, on ne fait rien et on ne dit rien |
|
| 113 | - if ($test) { |
|
| 114 | - return true; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - // Si install et que l'on a la meta d'installation, c'est un upgrade. On le consigne dans $infos |
|
| 118 | - // pour renvoyer le bon message en retour de la fonction. |
|
| 119 | - if ($action == 'install' && !empty($GLOBALS[$table][$nom_meta])) { |
|
| 120 | - $infos['upgrade'] = true; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - // executer l'installation ou l'inverse |
|
| 124 | - // et renvoyer la trace (mais il faudrait passer en AJAX plutot) |
|
| 125 | - ob_start(); |
|
| 126 | - $f($action, $arg, $version); |
|
| 127 | - $aff = ob_get_contents(); |
|
| 128 | - ob_end_clean(); |
|
| 129 | - |
|
| 130 | - // vider le cache des descriptions de tables a chaque (de)installation |
|
| 131 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 132 | - $trouver_table(''); |
|
| 133 | - $infos['install_test'] = [$f('test', $arg, $version), $aff]; |
|
| 134 | - |
|
| 135 | - // Si la table meta n'est pas spip_meta et qu'on est dans la première installation du plugin |
|
| 136 | - // on force la création du fichier cache à la date du moment. |
|
| 137 | - // On relit les metas de la table pour être sur que la globale soit à jour pour touch_meta. |
|
| 138 | - if ( |
|
| 139 | - ($table !== 'meta') |
|
| 140 | - and ($action == 'install') |
|
| 141 | - and empty($infos['upgrade']) |
|
| 142 | - ) { |
|
| 143 | - touch_meta(false, $table); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return $infos; |
|
| 57 | + // Charger les informations du XML du plugin et vérification de l'existence d'une installation |
|
| 58 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 59 | + $infos = $get_infos($plug, false, constant($dir_type)); |
|
| 60 | + if (!isset($infos['install']) or !$infos['install']) { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + // Passer en chemin absolu si possible, c'est plus efficace |
|
| 65 | + $dir = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 66 | + if (!defined($dir)) { |
|
| 67 | + $dir = $dir_type; |
|
| 68 | + } |
|
| 69 | + $dir = constant($dir); |
|
| 70 | + foreach ($infos['install'] as $file) { |
|
| 71 | + $file = $dir . $plug . '/' . trim($file); |
|
| 72 | + if (file_exists($file)) { |
|
| 73 | + include_once($file); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // Détermination de la table meta et du nom de la meta plugin |
|
| 78 | + $table = 'meta'; |
|
| 79 | + if (isset($infos['meta']) and ($infos['meta'] !== 'meta')) { |
|
| 80 | + $table = $infos['meta']; |
|
| 81 | + // S'assurer que les metas de la table spécifique sont bien accessibles dans la globale |
|
| 82 | + lire_metas($table); |
|
| 83 | + } |
|
| 84 | + $nom_meta = $infos['prefix'] . '_base_version'; |
|
| 85 | + |
|
| 86 | + // Détermination de la fonction à appeler et de ses arguments |
|
| 87 | + $f = $infos['prefix'] . '_install'; |
|
| 88 | + if (!function_exists($f)) { |
|
| 89 | + $f = isset($infos['schema']) ? 'spip_plugin_install' : ''; |
|
| 90 | + $arg = $infos; |
|
| 91 | + // On passe la table et la meta pour éviter de les recalculer dans la fonction appelée |
|
| 92 | + $arg['meta'] = $table; |
|
| 93 | + $arg['nom_meta'] = $nom_meta; |
|
| 94 | + } else { |
|
| 95 | + // Ancienne méthode d'installation - TODO à supprimer à terme |
|
| 96 | + // stupide: info deja dans le nom |
|
| 97 | + $arg = $infos['prefix']; |
|
| 98 | + } |
|
| 99 | + $version = $infos['schema'] ?? ''; |
|
| 100 | + |
|
| 101 | + if (!$f) { |
|
| 102 | + // installation sans operation particuliere |
|
| 103 | + $infos['install_test'] = [true, '']; |
|
| 104 | + return $infos; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + // Tester si l'action demandée est nécessaire ou pas. |
|
| 108 | + $test = $f('test', $arg, $version); |
|
| 109 | + if ($action == 'uninstall') { |
|
| 110 | + $test = !$test; |
|
| 111 | + } |
|
| 112 | + // Si deja fait, on ne fait rien et on ne dit rien |
|
| 113 | + if ($test) { |
|
| 114 | + return true; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + // Si install et que l'on a la meta d'installation, c'est un upgrade. On le consigne dans $infos |
|
| 118 | + // pour renvoyer le bon message en retour de la fonction. |
|
| 119 | + if ($action == 'install' && !empty($GLOBALS[$table][$nom_meta])) { |
|
| 120 | + $infos['upgrade'] = true; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + // executer l'installation ou l'inverse |
|
| 124 | + // et renvoyer la trace (mais il faudrait passer en AJAX plutot) |
|
| 125 | + ob_start(); |
|
| 126 | + $f($action, $arg, $version); |
|
| 127 | + $aff = ob_get_contents(); |
|
| 128 | + ob_end_clean(); |
|
| 129 | + |
|
| 130 | + // vider le cache des descriptions de tables a chaque (de)installation |
|
| 131 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 132 | + $trouver_table(''); |
|
| 133 | + $infos['install_test'] = [$f('test', $arg, $version), $aff]; |
|
| 134 | + |
|
| 135 | + // Si la table meta n'est pas spip_meta et qu'on est dans la première installation du plugin |
|
| 136 | + // on force la création du fichier cache à la date du moment. |
|
| 137 | + // On relit les metas de la table pour être sur que la globale soit à jour pour touch_meta. |
|
| 138 | + if ( |
|
| 139 | + ($table !== 'meta') |
|
| 140 | + and ($action == 'install') |
|
| 141 | + and empty($infos['upgrade']) |
|
| 142 | + ) { |
|
| 143 | + touch_meta(false, $table); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return $infos; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -159,25 +159,25 @@ discard block |
||
| 159 | 159 | * @return bool|void |
| 160 | 160 | */ |
| 161 | 161 | function spip_plugin_install($action, $infos, $version_cible) { |
| 162 | - $nom_meta = $infos['nom_meta']; |
|
| 163 | - $table = $infos['meta']; |
|
| 164 | - switch ($action) { |
|
| 165 | - case 'test': |
|
| 166 | - return (isset($GLOBALS[$table]) |
|
| 167 | - and isset($GLOBALS[$table][$nom_meta]) |
|
| 168 | - and spip_version_compare($GLOBALS[$table][$nom_meta], $version_cible, '>=')); |
|
| 169 | - break; |
|
| 170 | - case 'install': |
|
| 171 | - if (function_exists($upgrade = $infos['prefix'] . '_upgrade')) { |
|
| 172 | - $upgrade($nom_meta, $version_cible, $table); |
|
| 173 | - } |
|
| 174 | - break; |
|
| 175 | - case 'uninstall': |
|
| 176 | - if (function_exists($vider_tables = $infos['prefix'] . '_vider_tables')) { |
|
| 177 | - $vider_tables($nom_meta, $table); |
|
| 178 | - } |
|
| 179 | - break; |
|
| 180 | - } |
|
| 162 | + $nom_meta = $infos['nom_meta']; |
|
| 163 | + $table = $infos['meta']; |
|
| 164 | + switch ($action) { |
|
| 165 | + case 'test': |
|
| 166 | + return (isset($GLOBALS[$table]) |
|
| 167 | + and isset($GLOBALS[$table][$nom_meta]) |
|
| 168 | + and spip_version_compare($GLOBALS[$table][$nom_meta], $version_cible, '>=')); |
|
| 169 | + break; |
|
| 170 | + case 'install': |
|
| 171 | + if (function_exists($upgrade = $infos['prefix'] . '_upgrade')) { |
|
| 172 | + $upgrade($nom_meta, $version_cible, $table); |
|
| 173 | + } |
|
| 174 | + break; |
|
| 175 | + case 'uninstall': |
|
| 176 | + if (function_exists($vider_tables = $infos['prefix'] . '_vider_tables')) { |
|
| 177 | + $vider_tables($nom_meta, $table); |
|
| 178 | + } |
|
| 179 | + break; |
|
| 180 | + } |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | |
@@ -196,29 +196,29 @@ discard block |
||
| 196 | 196 | * @return array Tableau des plugins actifs |
| 197 | 197 | **/ |
| 198 | 198 | function liste_plugin_actifs() { |
| 199 | - $liste = $GLOBALS['meta']['plugin'] ?? ''; |
|
| 200 | - if (!$liste) { |
|
| 201 | - return []; |
|
| 202 | - } |
|
| 203 | - if (!is_array($liste = unserialize($liste))) { |
|
| 204 | - // compatibilite pre 1.9.2, mettre a jour la meta |
|
| 205 | - spip_log("MAJ meta plugin vieille version : $liste", 'plugin'); |
|
| 206 | - $new = true; |
|
| 207 | - [, $liste] = liste_plugin_valides(explode(',', $liste)); |
|
| 208 | - } else { |
|
| 209 | - $new = false; |
|
| 210 | - // compat au moment d'une migration depuis version anterieure |
|
| 211 | - // si pas de dir_type, alors c'est _DIR_PLUGINS |
|
| 212 | - foreach ($liste as $prefix => $infos) { |
|
| 213 | - if (!isset($infos['dir_type'])) { |
|
| 214 | - $liste[$prefix]['dir_type'] = '_DIR_PLUGINS'; |
|
| 215 | - $new = true; |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - if ($new) { |
|
| 220 | - ecrire_meta('plugin', serialize($liste)); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - return $liste; |
|
| 199 | + $liste = $GLOBALS['meta']['plugin'] ?? ''; |
|
| 200 | + if (!$liste) { |
|
| 201 | + return []; |
|
| 202 | + } |
|
| 203 | + if (!is_array($liste = unserialize($liste))) { |
|
| 204 | + // compatibilite pre 1.9.2, mettre a jour la meta |
|
| 205 | + spip_log("MAJ meta plugin vieille version : $liste", 'plugin'); |
|
| 206 | + $new = true; |
|
| 207 | + [, $liste] = liste_plugin_valides(explode(',', $liste)); |
|
| 208 | + } else { |
|
| 209 | + $new = false; |
|
| 210 | + // compat au moment d'une migration depuis version anterieure |
|
| 211 | + // si pas de dir_type, alors c'est _DIR_PLUGINS |
|
| 212 | + foreach ($liste as $prefix => $infos) { |
|
| 213 | + if (!isset($infos['dir_type'])) { |
|
| 214 | + $liste[$prefix]['dir_type'] = '_DIR_PLUGINS'; |
|
| 215 | + $new = true; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + if ($new) { |
|
| 220 | + ecrire_meta('plugin', serialize($liste)); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + return $liste; |
|
| 224 | 224 | } |
@@ -19,10 +19,10 @@ |
||
| 19 | 19 | * @package SPIP\Core\SQL\Upgrade |
| 20 | 20 | **/ |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | $GLOBALS['maj'][2021_02_18_00] = [ |
| 26 | - ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL" ], |
|
| 27 | - ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL" ], |
|
| 26 | + ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL" ], |
|
| 27 | + ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL" ], |
|
| 28 | 28 | ]; |
@@ -18,18 +18,18 @@ 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'][16428] = [ |
| 26 | - ['maj_liens', 'auteur'], // creer la table liens |
|
| 27 | - ['maj_liens', 'auteur', 'article'], |
|
| 28 | - ['sql_drop_table', 'spip_auteurs_articles'], |
|
| 29 | - ['maj_liens', 'auteur', 'rubrique'], |
|
| 30 | - ['sql_drop_table', 'spip_auteurs_rubriques'], |
|
| 31 | - ['maj_liens', 'auteur', 'message'], |
|
| 32 | - ['sql_drop_table', 'spip_auteurs_messages'], |
|
| 26 | + ['maj_liens', 'auteur'], // creer la table liens |
|
| 27 | + ['maj_liens', 'auteur', 'article'], |
|
| 28 | + ['sql_drop_table', 'spip_auteurs_articles'], |
|
| 29 | + ['maj_liens', 'auteur', 'rubrique'], |
|
| 30 | + ['sql_drop_table', 'spip_auteurs_rubriques'], |
|
| 31 | + ['maj_liens', 'auteur', 'message'], |
|
| 32 | + ['sql_drop_table', 'spip_auteurs_messages'], |
|
| 33 | 33 | ]; |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -55,89 +55,89 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | function maj_liens($pivot, $l = '') { |
| 57 | 57 | |
| 58 | - @define('_LOG_FILTRE_GRAVITE', 8); |
|
| 59 | - |
|
| 60 | - $exceptions_pluriel = ['forum' => 'forum', 'syndic' => 'syndic']; |
|
| 61 | - |
|
| 62 | - $pivot = preg_replace(',[^\w],', '', $pivot); // securite |
|
| 63 | - $pivots = ($exceptions_pluriel[$pivot] ?? $pivot . 's'); |
|
| 64 | - $liens = 'spip_' . $pivots . '_liens'; |
|
| 65 | - $id_pivot = 'id_' . $pivot; |
|
| 66 | - // Creer spip_auteurs_liens |
|
| 67 | - global $tables_auxiliaires; |
|
| 68 | - if (!$l) { |
|
| 69 | - include_spip('base/auxiliaires'); |
|
| 70 | - include_spip('base/create'); |
|
| 71 | - creer_ou_upgrader_table($liens, $tables_auxiliaires[$liens], false); |
|
| 72 | - } else { |
|
| 73 | - // Preparer |
|
| 74 | - $l = preg_replace(',[^\w],', '', $l); // securite |
|
| 75 | - $primary = "id_$l"; |
|
| 76 | - $objet = ($l == 'syndic' ? 'site' : $l); |
|
| 77 | - $ls = ($exceptions_pluriel[$l] ?? $l . 's'); |
|
| 78 | - $ancienne_table = 'spip_' . $pivots . '_' . $ls; |
|
| 79 | - $pool = 400; |
|
| 80 | - |
|
| 81 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 82 | - if (!$desc = $trouver_table($ancienne_table)) { |
|
| 83 | - return; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // securite pour ne pas perdre de donnees |
|
| 87 | - if (!$trouver_table($liens)) { |
|
| 88 | - return; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - $champs = $desc['field']; |
|
| 92 | - if (isset($champs['maj'])) { |
|
| 93 | - unset($champs['maj']); |
|
| 94 | - } |
|
| 95 | - if (isset($champs[$primary])) { |
|
| 96 | - unset($champs[$primary]); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $champs = array_keys($champs); |
|
| 100 | - // ne garder que les champs qui existent sur la table destination |
|
| 101 | - if ($desc_cible = $trouver_table($liens)) { |
|
| 102 | - $champs = array_intersect($champs, array_keys($desc_cible['field'])); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $champs[] = "$primary as id_objet"; |
|
| 106 | - $champs[] = "'$objet' as objet"; |
|
| 107 | - $champs = implode(', ', $champs); |
|
| 108 | - |
|
| 109 | - // Recopier les donnees |
|
| 110 | - $sub_pool = 100; |
|
| 111 | - while ($ids = array_map('reset', sql_allfetsel("$primary", $ancienne_table, '', '', '', "0,$sub_pool"))) { |
|
| 112 | - $insert = []; |
|
| 113 | - foreach ($ids as $id) { |
|
| 114 | - $n = sql_countsel($liens, "objet='$objet' AND id_objet=" . intval($id)); |
|
| 115 | - while ($t = sql_allfetsel($champs, $ancienne_table, "$primary=" . intval($id), '', $id_pivot, "$n,$pool")) { |
|
| 116 | - $n += is_countable($t) ? count($t) : 0; |
|
| 117 | - // empiler en s'assurant a minima de l'unicite |
|
| 118 | - while ($r = array_shift($t)) { |
|
| 119 | - $insert[$r[$id_pivot] . ':' . $r['id_objet']] = $r; |
|
| 120 | - } |
|
| 121 | - if (count($insert) >= $sub_pool) { |
|
| 122 | - maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 123 | - $insert = []; |
|
| 124 | - } |
|
| 125 | - // si timeout, sortir, la relance nous ramenera dans cette fonction |
|
| 126 | - // et on verifiera/repartira de la |
|
| 127 | - if (time() >= _TIME_OUT) { |
|
| 128 | - return; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - if (time() >= _TIME_OUT) { |
|
| 132 | - return; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - if (count($insert)) { |
|
| 136 | - maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 137 | - } |
|
| 138 | - sql_delete($ancienne_table, sql_in($primary, $ids)); |
|
| 139 | - } |
|
| 140 | - } |
|
| 58 | + @define('_LOG_FILTRE_GRAVITE', 8); |
|
| 59 | + |
|
| 60 | + $exceptions_pluriel = ['forum' => 'forum', 'syndic' => 'syndic']; |
|
| 61 | + |
|
| 62 | + $pivot = preg_replace(',[^\w],', '', $pivot); // securite |
|
| 63 | + $pivots = ($exceptions_pluriel[$pivot] ?? $pivot . 's'); |
|
| 64 | + $liens = 'spip_' . $pivots . '_liens'; |
|
| 65 | + $id_pivot = 'id_' . $pivot; |
|
| 66 | + // Creer spip_auteurs_liens |
|
| 67 | + global $tables_auxiliaires; |
|
| 68 | + if (!$l) { |
|
| 69 | + include_spip('base/auxiliaires'); |
|
| 70 | + include_spip('base/create'); |
|
| 71 | + creer_ou_upgrader_table($liens, $tables_auxiliaires[$liens], false); |
|
| 72 | + } else { |
|
| 73 | + // Preparer |
|
| 74 | + $l = preg_replace(',[^\w],', '', $l); // securite |
|
| 75 | + $primary = "id_$l"; |
|
| 76 | + $objet = ($l == 'syndic' ? 'site' : $l); |
|
| 77 | + $ls = ($exceptions_pluriel[$l] ?? $l . 's'); |
|
| 78 | + $ancienne_table = 'spip_' . $pivots . '_' . $ls; |
|
| 79 | + $pool = 400; |
|
| 80 | + |
|
| 81 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 82 | + if (!$desc = $trouver_table($ancienne_table)) { |
|
| 83 | + return; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // securite pour ne pas perdre de donnees |
|
| 87 | + if (!$trouver_table($liens)) { |
|
| 88 | + return; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + $champs = $desc['field']; |
|
| 92 | + if (isset($champs['maj'])) { |
|
| 93 | + unset($champs['maj']); |
|
| 94 | + } |
|
| 95 | + if (isset($champs[$primary])) { |
|
| 96 | + unset($champs[$primary]); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $champs = array_keys($champs); |
|
| 100 | + // ne garder que les champs qui existent sur la table destination |
|
| 101 | + if ($desc_cible = $trouver_table($liens)) { |
|
| 102 | + $champs = array_intersect($champs, array_keys($desc_cible['field'])); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $champs[] = "$primary as id_objet"; |
|
| 106 | + $champs[] = "'$objet' as objet"; |
|
| 107 | + $champs = implode(', ', $champs); |
|
| 108 | + |
|
| 109 | + // Recopier les donnees |
|
| 110 | + $sub_pool = 100; |
|
| 111 | + while ($ids = array_map('reset', sql_allfetsel("$primary", $ancienne_table, '', '', '', "0,$sub_pool"))) { |
|
| 112 | + $insert = []; |
|
| 113 | + foreach ($ids as $id) { |
|
| 114 | + $n = sql_countsel($liens, "objet='$objet' AND id_objet=" . intval($id)); |
|
| 115 | + while ($t = sql_allfetsel($champs, $ancienne_table, "$primary=" . intval($id), '', $id_pivot, "$n,$pool")) { |
|
| 116 | + $n += is_countable($t) ? count($t) : 0; |
|
| 117 | + // empiler en s'assurant a minima de l'unicite |
|
| 118 | + while ($r = array_shift($t)) { |
|
| 119 | + $insert[$r[$id_pivot] . ':' . $r['id_objet']] = $r; |
|
| 120 | + } |
|
| 121 | + if (count($insert) >= $sub_pool) { |
|
| 122 | + maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 123 | + $insert = []; |
|
| 124 | + } |
|
| 125 | + // si timeout, sortir, la relance nous ramenera dans cette fonction |
|
| 126 | + // et on verifiera/repartira de la |
|
| 127 | + if (time() >= _TIME_OUT) { |
|
| 128 | + return; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + if (time() >= _TIME_OUT) { |
|
| 132 | + return; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + if (count($insert)) { |
|
| 136 | + maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 137 | + } |
|
| 138 | + sql_delete($ancienne_table, sql_in($primary, $ids)); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -151,86 +151,86 @@ discard block |
||
| 151 | 151 | * @return void |
| 152 | 152 | **/ |
| 153 | 153 | function maj_liens_insertq_multi_check($table, $couples, $desc = []) { |
| 154 | - $n_before = sql_countsel($table); |
|
| 155 | - sql_insertq_multi($table, $couples, $desc); |
|
| 156 | - $n_after = sql_countsel($table); |
|
| 157 | - if (($n_after - $n_before) == count($couples)) { |
|
| 158 | - return; |
|
| 159 | - } |
|
| 160 | - // si ecart, on recommence l'insertion ligne par ligne... |
|
| 161 | - // moins rapide mais secure : seul le couple en doublon echouera, et non toute la serie |
|
| 162 | - foreach ($couples as $c) { |
|
| 163 | - sql_insertq($table, $c, $desc); |
|
| 164 | - } |
|
| 154 | + $n_before = sql_countsel($table); |
|
| 155 | + sql_insertq_multi($table, $couples, $desc); |
|
| 156 | + $n_after = sql_countsel($table); |
|
| 157 | + if (($n_after - $n_before) == count($couples)) { |
|
| 158 | + return; |
|
| 159 | + } |
|
| 160 | + // si ecart, on recommence l'insertion ligne par ligne... |
|
| 161 | + // moins rapide mais secure : seul le couple en doublon echouera, et non toute la serie |
|
| 162 | + foreach ($couples as $c) { |
|
| 163 | + sql_insertq($table, $c, $desc); |
|
| 164 | + } |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $GLOBALS['maj'][17311] = [ |
| 168 | - [ |
|
| 169 | - 'ecrire_meta', |
|
| 170 | - 'multi_objets', |
|
| 171 | - implode( |
|
| 172 | - ',', |
|
| 173 | - array_diff( |
|
| 174 | - [ |
|
| 175 | - (isset($GLOBALS['meta']['multi_rubriques']) and $GLOBALS['meta']['multi_rubriques'] == 'oui') |
|
| 176 | - ? 'spip_rubriques' : '', |
|
| 177 | - (isset($GLOBALS['meta']['multi_articles']) and $GLOBALS['meta']['multi_articles'] == 'oui') |
|
| 178 | - ? 'spip_articles' : '' |
|
| 179 | - ], |
|
| 180 | - [''] |
|
| 181 | - ) |
|
| 182 | - ) |
|
| 183 | - ], |
|
| 184 | - [ |
|
| 185 | - 'ecrire_meta', |
|
| 186 | - 'gerer_trad_objets', |
|
| 187 | - implode( |
|
| 188 | - ',', |
|
| 189 | - array_diff( |
|
| 190 | - [ |
|
| 191 | - (isset($GLOBALS['meta']['gerer_trad']) and $GLOBALS['meta']['gerer_trad'] == 'oui') |
|
| 192 | - ? 'spip_articles' : '' |
|
| 193 | - ], |
|
| 194 | - [''] |
|
| 195 | - ) |
|
| 196 | - ) |
|
| 197 | - ], |
|
| 168 | + [ |
|
| 169 | + 'ecrire_meta', |
|
| 170 | + 'multi_objets', |
|
| 171 | + implode( |
|
| 172 | + ',', |
|
| 173 | + array_diff( |
|
| 174 | + [ |
|
| 175 | + (isset($GLOBALS['meta']['multi_rubriques']) and $GLOBALS['meta']['multi_rubriques'] == 'oui') |
|
| 176 | + ? 'spip_rubriques' : '', |
|
| 177 | + (isset($GLOBALS['meta']['multi_articles']) and $GLOBALS['meta']['multi_articles'] == 'oui') |
|
| 178 | + ? 'spip_articles' : '' |
|
| 179 | + ], |
|
| 180 | + [''] |
|
| 181 | + ) |
|
| 182 | + ) |
|
| 183 | + ], |
|
| 184 | + [ |
|
| 185 | + 'ecrire_meta', |
|
| 186 | + 'gerer_trad_objets', |
|
| 187 | + implode( |
|
| 188 | + ',', |
|
| 189 | + array_diff( |
|
| 190 | + [ |
|
| 191 | + (isset($GLOBALS['meta']['gerer_trad']) and $GLOBALS['meta']['gerer_trad'] == 'oui') |
|
| 192 | + ? 'spip_articles' : '' |
|
| 193 | + ], |
|
| 194 | + [''] |
|
| 195 | + ) |
|
| 196 | + ) |
|
| 197 | + ], |
|
| 198 | 198 | ]; |
| 199 | 199 | $GLOBALS['maj'][17555] = [ |
| 200 | - ['sql_alter', "TABLE spip_resultats ADD table_objet varchar(30) DEFAULT '' NOT NULL"], |
|
| 201 | - ['sql_alter', "TABLE spip_resultats ADD serveur char(16) DEFAULT '' NOT NULL"], |
|
| 200 | + ['sql_alter', "TABLE spip_resultats ADD table_objet varchar(30) DEFAULT '' NOT NULL"], |
|
| 201 | + ['sql_alter', "TABLE spip_resultats ADD serveur char(16) DEFAULT '' NOT NULL"], |
|
| 202 | 202 | ]; |
| 203 | 203 | |
| 204 | 204 | $GLOBALS['maj'][17563] = [ |
| 205 | - ['sql_alter', "TABLE spip_articles ADD virtuel VARCHAR(255) DEFAULT '' NOT NULL"], |
|
| 206 | - ['sql_update', 'spip_articles', ['virtuel' => 'SUBSTRING(chapo,2)', 'chapo' => "''"], "chapo LIKE '=_%'"], |
|
| 205 | + ['sql_alter', "TABLE spip_articles ADD virtuel VARCHAR(255) DEFAULT '' NOT NULL"], |
|
| 206 | + ['sql_update', 'spip_articles', ['virtuel' => 'SUBSTRING(chapo,2)', 'chapo' => "''"], "chapo LIKE '=_%'"], |
|
| 207 | 207 | ]; |
| 208 | 208 | |
| 209 | 209 | $GLOBALS['maj'][17577] = [ |
| 210 | - ['maj_tables', ['spip_jobs', 'spip_jobs_liens']], |
|
| 210 | + ['maj_tables', ['spip_jobs', 'spip_jobs_liens']], |
|
| 211 | 211 | ]; |
| 212 | 212 | |
| 213 | 213 | $GLOBALS['maj'][17743] = [ |
| 214 | - ['sql_update', 'spip_auteurs', ['prefs' => 'bio', 'bio' => "''"], "statut='nouveau' AND bio<>''"], |
|
| 214 | + ['sql_update', 'spip_auteurs', ['prefs' => 'bio', 'bio' => "''"], "statut='nouveau' AND bio<>''"], |
|
| 215 | 215 | ]; |
| 216 | 216 | |
| 217 | 217 | $GLOBALS['maj'][18219] = [ |
| 218 | - ['sql_alter', 'TABLE spip_rubriques DROP id_import'], |
|
| 219 | - ['sql_alter', 'TABLE spip_rubriques DROP export'], |
|
| 218 | + ['sql_alter', 'TABLE spip_rubriques DROP id_import'], |
|
| 219 | + ['sql_alter', 'TABLE spip_rubriques DROP export'], |
|
| 220 | 220 | ]; |
| 221 | 221 | |
| 222 | 222 | $GLOBALS['maj'][18310] = [ |
| 223 | - ['sql_alter', "TABLE spip_auteurs_liens CHANGE vu vu VARCHAR(6) DEFAULT 'non' NOT NULL"], |
|
| 223 | + ['sql_alter', "TABLE spip_auteurs_liens CHANGE vu vu VARCHAR(6) DEFAULT 'non' NOT NULL"], |
|
| 224 | 224 | ]; |
| 225 | 225 | |
| 226 | 226 | $GLOBALS['maj'][18597] = [ |
| 227 | - ['sql_alter', "TABLE spip_rubriques ADD profondeur smallint(5) DEFAULT '0' NOT NULL"], |
|
| 228 | - ['maj_propager_les_secteurs'], |
|
| 227 | + ['sql_alter', "TABLE spip_rubriques ADD profondeur smallint(5) DEFAULT '0' NOT NULL"], |
|
| 228 | + ['maj_propager_les_secteurs'], |
|
| 229 | 229 | ]; |
| 230 | 230 | |
| 231 | 231 | $GLOBALS['maj'][18955] = [ |
| 232 | - ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX id_objet (id_objet)'], |
|
| 233 | - ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX objet (objet)'], |
|
| 232 | + ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX id_objet (id_objet)'], |
|
| 233 | + ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX objet (objet)'], |
|
| 234 | 234 | ]; |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -239,8 +239,8 @@ discard block |
||
| 239 | 239 | * @uses propager_les_secteurs() |
| 240 | 240 | **/ |
| 241 | 241 | function maj_propager_les_secteurs() { |
| 242 | - include_spip('inc/rubriques'); |
|
| 243 | - propager_les_secteurs(); |
|
| 242 | + include_spip('inc/rubriques'); |
|
| 243 | + propager_les_secteurs(); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -253,87 +253,87 @@ discard block |
||
| 253 | 253 | function maj_collation_sqlite() { |
| 254 | 254 | |
| 255 | 255 | |
| 256 | - include_spip('base/dump'); |
|
| 257 | - $tables = base_lister_toutes_tables(); |
|
| 258 | - |
|
| 259 | - // rien a faire si base non sqlite |
|
| 260 | - if (strncmp($GLOBALS['connexions'][0]['type'], 'sqlite', 6) !== 0) { |
|
| 261 | - return; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 265 | - // forcer le vidage de cache |
|
| 266 | - $trouver_table(''); |
|
| 267 | - |
|
| 268 | - // cas particulier spip_auteurs : retablir le collate binary sur le login |
|
| 269 | - $desc = $trouver_table('spip_auteurs'); |
|
| 270 | - spip_log('spip_auteurs : ' . var_export($desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 271 | - if (stripos($desc['field']['login'], 'BINARY') === false) { |
|
| 272 | - spip_log('Retablir champ login BINARY sur table spip_auteurs', 'maj'); |
|
| 273 | - sql_alter('table spip_auteurs change login login VARCHAR(255) BINARY'); |
|
| 274 | - $trouver_table(''); |
|
| 275 | - $new_desc = $trouver_table('spip_auteurs'); |
|
| 276 | - spip_log('Apres conversion spip_auteurs : ' . var_export($new_desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - foreach ($tables as $table) { |
|
| 280 | - if (time() >= _TIME_OUT) { |
|
| 281 | - return; |
|
| 282 | - } |
|
| 283 | - if ($desc = $trouver_table($table)) { |
|
| 284 | - $desc_collate = _sqlite_remplacements_definitions_table($desc['field']); |
|
| 285 | - if ($d = array_diff($desc['field'], $desc_collate)) { |
|
| 286 | - spip_log("Table $table COLLATE incorrects", 'maj'); |
|
| 287 | - |
|
| 288 | - // cas particulier spip_urls : |
|
| 289 | - // supprimer les doublons avant conversion sinon echec (on garde les urls les plus recentes) |
|
| 290 | - if ($table == 'spip_urls') { |
|
| 291 | - // par date DESC pour conserver les urls les plus recentes |
|
| 292 | - $data = sql_allfetsel('*', 'spip_urls', '', '', 'date DESC'); |
|
| 293 | - $urls = []; |
|
| 294 | - foreach ($data as $d) { |
|
| 295 | - $key = $d['id_parent'] . '::' . strtolower($d['url']); |
|
| 296 | - if (!isset($urls[$key])) { |
|
| 297 | - $urls[$key] = true; |
|
| 298 | - } else { |
|
| 299 | - spip_log( |
|
| 300 | - 'Suppression doublon dans spip_urls avant conversion : ' . serialize($d), |
|
| 301 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 302 | - ); |
|
| 303 | - sql_delete('spip_urls', 'id_parent=' . sql_quote($d['id_parent']) . ' AND url=' . sql_quote($d['url'])); |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - foreach ($desc['field'] as $field => $type) { |
|
| 308 | - if ($desc['field'][$field] !== $desc_collate[$field]) { |
|
| 309 | - spip_log("Conversion COLLATE table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 310 | - sql_alter("table $table change $field $field " . $desc_collate[$field]); |
|
| 311 | - $trouver_table(''); |
|
| 312 | - $new_desc = $trouver_table($table); |
|
| 313 | - spip_log( |
|
| 314 | - "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 315 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 316 | - ); |
|
| 317 | - continue 2; // inutile de continuer pour cette table : un seul alter remet tout a jour en sqlite |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - // forcer le vidage de cache |
|
| 325 | - $trouver_table(''); |
|
| 256 | + include_spip('base/dump'); |
|
| 257 | + $tables = base_lister_toutes_tables(); |
|
| 258 | + |
|
| 259 | + // rien a faire si base non sqlite |
|
| 260 | + if (strncmp($GLOBALS['connexions'][0]['type'], 'sqlite', 6) !== 0) { |
|
| 261 | + return; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 265 | + // forcer le vidage de cache |
|
| 266 | + $trouver_table(''); |
|
| 267 | + |
|
| 268 | + // cas particulier spip_auteurs : retablir le collate binary sur le login |
|
| 269 | + $desc = $trouver_table('spip_auteurs'); |
|
| 270 | + spip_log('spip_auteurs : ' . var_export($desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 271 | + if (stripos($desc['field']['login'], 'BINARY') === false) { |
|
| 272 | + spip_log('Retablir champ login BINARY sur table spip_auteurs', 'maj'); |
|
| 273 | + sql_alter('table spip_auteurs change login login VARCHAR(255) BINARY'); |
|
| 274 | + $trouver_table(''); |
|
| 275 | + $new_desc = $trouver_table('spip_auteurs'); |
|
| 276 | + spip_log('Apres conversion spip_auteurs : ' . var_export($new_desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + foreach ($tables as $table) { |
|
| 280 | + if (time() >= _TIME_OUT) { |
|
| 281 | + return; |
|
| 282 | + } |
|
| 283 | + if ($desc = $trouver_table($table)) { |
|
| 284 | + $desc_collate = _sqlite_remplacements_definitions_table($desc['field']); |
|
| 285 | + if ($d = array_diff($desc['field'], $desc_collate)) { |
|
| 286 | + spip_log("Table $table COLLATE incorrects", 'maj'); |
|
| 287 | + |
|
| 288 | + // cas particulier spip_urls : |
|
| 289 | + // supprimer les doublons avant conversion sinon echec (on garde les urls les plus recentes) |
|
| 290 | + if ($table == 'spip_urls') { |
|
| 291 | + // par date DESC pour conserver les urls les plus recentes |
|
| 292 | + $data = sql_allfetsel('*', 'spip_urls', '', '', 'date DESC'); |
|
| 293 | + $urls = []; |
|
| 294 | + foreach ($data as $d) { |
|
| 295 | + $key = $d['id_parent'] . '::' . strtolower($d['url']); |
|
| 296 | + if (!isset($urls[$key])) { |
|
| 297 | + $urls[$key] = true; |
|
| 298 | + } else { |
|
| 299 | + spip_log( |
|
| 300 | + 'Suppression doublon dans spip_urls avant conversion : ' . serialize($d), |
|
| 301 | + 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 302 | + ); |
|
| 303 | + sql_delete('spip_urls', 'id_parent=' . sql_quote($d['id_parent']) . ' AND url=' . sql_quote($d['url'])); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + foreach ($desc['field'] as $field => $type) { |
|
| 308 | + if ($desc['field'][$field] !== $desc_collate[$field]) { |
|
| 309 | + spip_log("Conversion COLLATE table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 310 | + sql_alter("table $table change $field $field " . $desc_collate[$field]); |
|
| 311 | + $trouver_table(''); |
|
| 312 | + $new_desc = $trouver_table($table); |
|
| 313 | + spip_log( |
|
| 314 | + "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 315 | + 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 316 | + ); |
|
| 317 | + continue 2; // inutile de continuer pour cette table : un seul alter remet tout a jour en sqlite |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + // forcer le vidage de cache |
|
| 325 | + $trouver_table(''); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | |
| 329 | 329 | $GLOBALS['maj'][19236] = [ |
| 330 | - ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom='version_installee'"], // version base principale |
|
| 331 | - ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom LIKE '%_base_version'"], // version base plugins |
|
| 332 | - ['maj_collation_sqlite'], |
|
| 330 | + ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom='version_installee'"], // version base principale |
|
| 331 | + ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom LIKE '%_base_version'"], // version base plugins |
|
| 332 | + ['maj_collation_sqlite'], |
|
| 333 | 333 | ]; |
| 334 | 334 | |
| 335 | 335 | $GLOBALS['maj'][19268] = [ |
| 336 | - ['supprimer_toutes_sessions'], |
|
| 336 | + ['supprimer_toutes_sessions'], |
|
| 337 | 337 | ]; |
| 338 | 338 | |
| 339 | 339 | /** |
@@ -342,13 +342,13 @@ discard block |
||
| 342 | 342 | * Obligera tous les auteurs à se reconnecter ! |
| 343 | 343 | **/ |
| 344 | 344 | function supprimer_toutes_sessions() { |
| 345 | - spip_log('supprimer sessions auteur'); |
|
| 346 | - if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 347 | - while (($f = readdir($dir)) !== false) { |
|
| 348 | - spip_unlink(_DIR_SESSIONS . $f); |
|
| 349 | - if (time() >= _TIME_OUT) { |
|
| 350 | - return; |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - } |
|
| 345 | + spip_log('supprimer sessions auteur'); |
|
| 346 | + if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 347 | + while (($f = readdir($dir)) !== false) { |
|
| 348 | + spip_unlink(_DIR_SESSIONS . $f); |
|
| 349 | + if (time() >= _TIME_OUT) { |
|
| 350 | + return; |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | 354 | } |
@@ -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 | /** |
@@ -37,41 +37,41 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | function action_editer_auteur_dist($arg = null) { |
| 39 | 39 | |
| 40 | - if (is_null($arg)) { |
|
| 41 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 42 | - $arg = $securiser_action(); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - // si id_auteur n'est pas un nombre, c'est une creation |
|
| 47 | - if (!$id_auteur = intval($arg)) { |
|
| 48 | - if (($id_auteur = auteur_inserer()) > 0) { |
|
| 49 | - # cf. GROS HACK |
|
| 50 | - # recuperer l'eventuel logo charge avant la creation |
|
| 51 | - # ils ont un id = 0-id_auteur de la session |
|
| 52 | - $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur']; |
|
| 53 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 54 | - foreach (['on', 'off'] as $type) { |
|
| 55 | - if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) { |
|
| 56 | - if ($logo = reset($logo)) { |
|
| 57 | - rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - // Enregistre l'envoi dans la BD |
|
| 65 | - $err = ''; |
|
| 66 | - if ($id_auteur > 0) { |
|
| 67 | - $err = auteur_modifier($id_auteur); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - if ($err) { |
|
| 71 | - spip_log("echec editeur auteur: $err", _LOG_ERREUR); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return [$id_auteur, $err]; |
|
| 40 | + if (is_null($arg)) { |
|
| 41 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 42 | + $arg = $securiser_action(); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + // si id_auteur n'est pas un nombre, c'est une creation |
|
| 47 | + if (!$id_auteur = intval($arg)) { |
|
| 48 | + if (($id_auteur = auteur_inserer()) > 0) { |
|
| 49 | + # cf. GROS HACK |
|
| 50 | + # recuperer l'eventuel logo charge avant la creation |
|
| 51 | + # ils ont un id = 0-id_auteur de la session |
|
| 52 | + $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur']; |
|
| 53 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 54 | + foreach (['on', 'off'] as $type) { |
|
| 55 | + if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) { |
|
| 56 | + if ($logo = reset($logo)) { |
|
| 57 | + rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + // Enregistre l'envoi dans la BD |
|
| 65 | + $err = ''; |
|
| 66 | + if ($id_auteur > 0) { |
|
| 67 | + $err = auteur_modifier($id_auteur); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + if ($err) { |
|
| 71 | + spip_log("echec editeur auteur: $err", _LOG_ERREUR); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return [$id_auteur, $err]; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -88,44 +88,44 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | function auteur_inserer($source = null, $set = null) { |
| 90 | 90 | |
| 91 | - // Ce qu'on va demander comme modifications |
|
| 92 | - $champs = []; |
|
| 93 | - $champs['source'] = $source ?: 'spip'; |
|
| 94 | - |
|
| 95 | - $champs['login'] = ''; |
|
| 96 | - $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 97 | - $champs['webmestre'] = 'non'; |
|
| 98 | - if (empty($champs['imessage'])) { |
|
| 99 | - $champs['imessage'] = 'oui'; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - if ($set) { |
|
| 103 | - $champs = array_merge($champs, $set); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // Envoyer aux plugins |
|
| 107 | - $champs = pipeline( |
|
| 108 | - 'pre_insertion', |
|
| 109 | - [ |
|
| 110 | - 'args' => [ |
|
| 111 | - 'table' => 'spip_auteurs', |
|
| 112 | - ], |
|
| 113 | - 'data' => $champs |
|
| 114 | - ] |
|
| 115 | - ); |
|
| 116 | - $id_auteur = sql_insertq('spip_auteurs', $champs); |
|
| 117 | - pipeline( |
|
| 118 | - 'post_insertion', |
|
| 119 | - [ |
|
| 120 | - 'args' => [ |
|
| 121 | - 'table' => 'spip_auteurs', |
|
| 122 | - 'id_objet' => $id_auteur |
|
| 123 | - ], |
|
| 124 | - 'data' => $champs |
|
| 125 | - ] |
|
| 126 | - ); |
|
| 127 | - |
|
| 128 | - return $id_auteur; |
|
| 91 | + // Ce qu'on va demander comme modifications |
|
| 92 | + $champs = []; |
|
| 93 | + $champs['source'] = $source ?: 'spip'; |
|
| 94 | + |
|
| 95 | + $champs['login'] = ''; |
|
| 96 | + $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 97 | + $champs['webmestre'] = 'non'; |
|
| 98 | + if (empty($champs['imessage'])) { |
|
| 99 | + $champs['imessage'] = 'oui'; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + if ($set) { |
|
| 103 | + $champs = array_merge($champs, $set); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // Envoyer aux plugins |
|
| 107 | + $champs = pipeline( |
|
| 108 | + 'pre_insertion', |
|
| 109 | + [ |
|
| 110 | + 'args' => [ |
|
| 111 | + 'table' => 'spip_auteurs', |
|
| 112 | + ], |
|
| 113 | + 'data' => $champs |
|
| 114 | + ] |
|
| 115 | + ); |
|
| 116 | + $id_auteur = sql_insertq('spip_auteurs', $champs); |
|
| 117 | + pipeline( |
|
| 118 | + 'post_insertion', |
|
| 119 | + [ |
|
| 120 | + 'args' => [ |
|
| 121 | + 'table' => 'spip_auteurs', |
|
| 122 | + 'id_objet' => $id_auteur |
|
| 123 | + ], |
|
| 124 | + 'data' => $champs |
|
| 125 | + ] |
|
| 126 | + ); |
|
| 127 | + |
|
| 128 | + return $id_auteur; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | |
@@ -150,70 +150,70 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | function auteur_modifier($id_auteur, $set = null, $force_update = false) { |
| 152 | 152 | |
| 153 | - include_spip('inc/modifier'); |
|
| 154 | - include_spip('inc/filtres'); |
|
| 155 | - $c = collecter_requests( |
|
| 156 | - // white list |
|
| 157 | - objet_info('auteur', 'champs_editables'), |
|
| 158 | - // black list |
|
| 159 | - $force_update ? [] : ['webmestre', 'pass', 'login'], |
|
| 160 | - // donnees eventuellement fournies |
|
| 161 | - $set |
|
| 162 | - ); |
|
| 163 | - |
|
| 164 | - if ( |
|
| 165 | - $err = objet_modifier_champs( |
|
| 166 | - 'auteur', |
|
| 167 | - $id_auteur, |
|
| 168 | - [ |
|
| 169 | - 'data' => $set, |
|
| 170 | - 'nonvide' => ['nom' => _T('ecrire:item_nouvel_auteur')] |
|
| 171 | - ], |
|
| 172 | - $c |
|
| 173 | - ) |
|
| 174 | - ) { |
|
| 175 | - return $err; |
|
| 176 | - } |
|
| 177 | - $session = $c; |
|
| 178 | - |
|
| 179 | - $err = ''; |
|
| 180 | - if (!$force_update) { |
|
| 181 | - // Modification de statut, changement de rubrique ? |
|
| 182 | - $c = collecter_requests( |
|
| 183 | - // white list |
|
| 184 | - [ |
|
| 185 | - 'statut', |
|
| 186 | - 'new_login', |
|
| 187 | - 'new_pass', |
|
| 188 | - 'login', |
|
| 189 | - 'pass', |
|
| 190 | - 'webmestre', |
|
| 191 | - 'restreintes', |
|
| 192 | - 'id_parent' |
|
| 193 | - ], |
|
| 194 | - // black list |
|
| 195 | - [], |
|
| 196 | - // donnees eventuellement fournies |
|
| 197 | - $set |
|
| 198 | - ); |
|
| 199 | - if (isset($c['new_login']) and !isset($c['login'])) { |
|
| 200 | - $c['login'] = $c['new_login']; |
|
| 201 | - } |
|
| 202 | - if (isset($c['new_pass']) and !isset($c['pass'])) { |
|
| 203 | - $c['pass'] = $c['new_pass']; |
|
| 204 | - } |
|
| 205 | - $err = auteur_instituer($id_auteur, $c); |
|
| 206 | - $session = array_merge($session, $c); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - // .. mettre a jour les sessions de cet auteur |
|
| 210 | - include_spip('inc/session'); |
|
| 211 | - $session['id_auteur'] = $id_auteur; |
|
| 212 | - unset($session['new_login']); |
|
| 213 | - unset($session['new_pass']); |
|
| 214 | - actualiser_sessions($session); |
|
| 215 | - |
|
| 216 | - return $err; |
|
| 153 | + include_spip('inc/modifier'); |
|
| 154 | + include_spip('inc/filtres'); |
|
| 155 | + $c = collecter_requests( |
|
| 156 | + // white list |
|
| 157 | + objet_info('auteur', 'champs_editables'), |
|
| 158 | + // black list |
|
| 159 | + $force_update ? [] : ['webmestre', 'pass', 'login'], |
|
| 160 | + // donnees eventuellement fournies |
|
| 161 | + $set |
|
| 162 | + ); |
|
| 163 | + |
|
| 164 | + if ( |
|
| 165 | + $err = objet_modifier_champs( |
|
| 166 | + 'auteur', |
|
| 167 | + $id_auteur, |
|
| 168 | + [ |
|
| 169 | + 'data' => $set, |
|
| 170 | + 'nonvide' => ['nom' => _T('ecrire:item_nouvel_auteur')] |
|
| 171 | + ], |
|
| 172 | + $c |
|
| 173 | + ) |
|
| 174 | + ) { |
|
| 175 | + return $err; |
|
| 176 | + } |
|
| 177 | + $session = $c; |
|
| 178 | + |
|
| 179 | + $err = ''; |
|
| 180 | + if (!$force_update) { |
|
| 181 | + // Modification de statut, changement de rubrique ? |
|
| 182 | + $c = collecter_requests( |
|
| 183 | + // white list |
|
| 184 | + [ |
|
| 185 | + 'statut', |
|
| 186 | + 'new_login', |
|
| 187 | + 'new_pass', |
|
| 188 | + 'login', |
|
| 189 | + 'pass', |
|
| 190 | + 'webmestre', |
|
| 191 | + 'restreintes', |
|
| 192 | + 'id_parent' |
|
| 193 | + ], |
|
| 194 | + // black list |
|
| 195 | + [], |
|
| 196 | + // donnees eventuellement fournies |
|
| 197 | + $set |
|
| 198 | + ); |
|
| 199 | + if (isset($c['new_login']) and !isset($c['login'])) { |
|
| 200 | + $c['login'] = $c['new_login']; |
|
| 201 | + } |
|
| 202 | + if (isset($c['new_pass']) and !isset($c['pass'])) { |
|
| 203 | + $c['pass'] = $c['new_pass']; |
|
| 204 | + } |
|
| 205 | + $err = auteur_instituer($id_auteur, $c); |
|
| 206 | + $session = array_merge($session, $c); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + // .. mettre a jour les sessions de cet auteur |
|
| 210 | + include_spip('inc/session'); |
|
| 211 | + $session['id_auteur'] = $id_auteur; |
|
| 212 | + unset($session['new_login']); |
|
| 213 | + unset($session['new_pass']); |
|
| 214 | + actualiser_sessions($session); |
|
| 215 | + |
|
| 216 | + return $err; |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -234,9 +234,9 @@ discard block |
||
| 234 | 234 | * @return string |
| 235 | 235 | */ |
| 236 | 236 | function auteur_associer($id_auteur, $objets, $qualif = null) { |
| 237 | - include_spip('action/editer_liens'); |
|
| 237 | + include_spip('action/editer_liens'); |
|
| 238 | 238 | |
| 239 | - return objet_associer(['auteur' => $id_auteur], $objets, $qualif); |
|
| 239 | + return objet_associer(['auteur' => $id_auteur], $objets, $qualif); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -255,9 +255,9 @@ discard block |
||
| 255 | 255 | * @return string |
| 256 | 256 | */ |
| 257 | 257 | function auteur_dissocier($id_auteur, $objets) { |
| 258 | - include_spip('action/editer_liens'); |
|
| 258 | + include_spip('action/editer_liens'); |
|
| 259 | 259 | |
| 260 | - return objet_dissocier(['auteur' => $id_auteur], $objets); |
|
| 260 | + return objet_dissocier(['auteur' => $id_auteur], $objets); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -278,9 +278,9 @@ discard block |
||
| 278 | 278 | * @return bool|int |
| 279 | 279 | */ |
| 280 | 280 | function auteur_qualifier($id_auteur, $objets, $qualif) { |
| 281 | - include_spip('action/editer_liens'); |
|
| 281 | + include_spip('action/editer_liens'); |
|
| 282 | 282 | |
| 283 | - return objet_qualifier_liens(['auteur' => $id_auteur], $objets, $qualif); |
|
| 283 | + return objet_qualifier_liens(['auteur' => $id_auteur], $objets, $qualif); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | |
@@ -299,139 +299,139 @@ discard block |
||
| 299 | 299 | * @return bool|string |
| 300 | 300 | */ |
| 301 | 301 | function auteur_instituer($id_auteur, $c, $force_webmestre = false) { |
| 302 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 303 | - return false; |
|
| 304 | - } |
|
| 305 | - $erreurs = []; // contiendra les differentes erreurs a traduire par _T() |
|
| 306 | - $champs = []; |
|
| 307 | - |
|
| 308 | - // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 309 | - if (isset($c['login']) and strlen($c['login'])) { |
|
| 310 | - $champs['login'] = $c['login']; |
|
| 311 | - } |
|
| 312 | - if (isset($c['pass']) and strlen($c['pass'])) { |
|
| 313 | - $champs['pass'] = $c['pass']; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 317 | - |
|
| 318 | - if ( |
|
| 319 | - isset($c['statut']) |
|
| 320 | - and (autoriser('modifier', 'auteur', $id_auteur, null, ['statut' => $c['statut']])) |
|
| 321 | - ) { |
|
| 322 | - $statut = $champs['statut'] = $c['statut']; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - // Restreindre avant de declarer l'auteur |
|
| 326 | - // (section critique sur les droits) |
|
| 327 | - if (isset($c['id_parent']) and $c['id_parent']) { |
|
| 328 | - if (is_array($c['restreintes'])) { |
|
| 329 | - $c['restreintes'][] = $c['id_parent']; |
|
| 330 | - } else { |
|
| 331 | - $c['restreintes'] = [$c['id_parent']]; |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - if ( |
|
| 336 | - isset($c['webmestre']) |
|
| 337 | - and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, ['webmestre' => '?'])) |
|
| 338 | - ) { |
|
| 339 | - $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non'; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - // si statut change et n'est pas 0minirezo, on force webmestre a non |
|
| 343 | - if (isset($c['statut']) and $c['statut'] !== '0minirezo') { |
|
| 344 | - $champs['webmestre'] = $c['webmestre'] = 'non'; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - // Envoyer aux plugins |
|
| 348 | - $champs = pipeline( |
|
| 349 | - 'pre_edition', |
|
| 350 | - [ |
|
| 351 | - 'args' => [ |
|
| 352 | - 'table' => 'spip_auteurs', |
|
| 353 | - 'id_objet' => $id_auteur, |
|
| 354 | - 'action' => 'instituer', |
|
| 355 | - 'statut_ancien' => $statut_ancien, |
|
| 356 | - ], |
|
| 357 | - 'data' => $champs |
|
| 358 | - ] |
|
| 359 | - ); |
|
| 360 | - |
|
| 361 | - if ( |
|
| 362 | - isset($c['restreintes']) and is_array($c['restreintes']) |
|
| 363 | - and autoriser('modifier', 'auteur', $id_auteur, null, ['restreint' => $c['restreintes']]) |
|
| 364 | - ) { |
|
| 365 | - $rubriques = array_map('intval', $c['restreintes']); |
|
| 366 | - $rubriques = array_unique($rubriques); |
|
| 367 | - $rubriques = array_diff($rubriques, [0]); |
|
| 368 | - auteur_dissocier($id_auteur, ['rubrique' => '*']); |
|
| 369 | - auteur_associer($id_auteur, ['rubrique' => $rubriques]); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - $flag_ecrire_acces = false; |
|
| 373 | - // commencer par traiter les cas particuliers des logins et pass |
|
| 374 | - // avant les autres ecritures en base |
|
| 375 | - if (isset($champs['login']) or isset($champs['pass'])) { |
|
| 376 | - $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 377 | - include_spip('inc/auth'); |
|
| 378 | - if (isset($champs['login']) and strlen($champs['login'])) { |
|
| 379 | - if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
|
| 380 | - $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - if (isset($champs['pass']) and strlen($champs['pass'])) { |
|
| 384 | - $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 385 | - if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
|
| 386 | - $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - unset($champs['login']); |
|
| 390 | - unset($champs['pass']); |
|
| 391 | - $flag_ecrire_acces = true; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 395 | - return implode(' ', array_map('_T', $erreurs)); |
|
| 396 | - } |
|
| 397 | - sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 398 | - |
|
| 399 | - // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 400 | - if ( |
|
| 401 | - $flag_ecrire_acces |
|
| 402 | - or isset($champs['statut']) |
|
| 403 | - ) { |
|
| 404 | - include_spip('inc/acces'); |
|
| 405 | - ecrire_acces(); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - // Invalider les caches |
|
| 409 | - include_spip('inc/invalideur'); |
|
| 410 | - suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 411 | - |
|
| 412 | - // Pipeline |
|
| 413 | - pipeline( |
|
| 414 | - 'post_edition', |
|
| 415 | - [ |
|
| 416 | - 'args' => [ |
|
| 417 | - 'table' => 'spip_auteurs', |
|
| 418 | - 'id_objet' => $id_auteur, |
|
| 419 | - 'action' => 'instituer', |
|
| 420 | - 'statut_ancien' => $statut_ancien, |
|
| 421 | - ], |
|
| 422 | - 'data' => $champs |
|
| 423 | - ] |
|
| 424 | - ); |
|
| 425 | - |
|
| 426 | - |
|
| 427 | - // Notifications |
|
| 428 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 429 | - $notifications( |
|
| 430 | - 'instituerauteur', |
|
| 431 | - $id_auteur, |
|
| 432 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien] |
|
| 433 | - ); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - return implode(' ', array_map('_T', $erreurs)); |
|
| 302 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 303 | + return false; |
|
| 304 | + } |
|
| 305 | + $erreurs = []; // contiendra les differentes erreurs a traduire par _T() |
|
| 306 | + $champs = []; |
|
| 307 | + |
|
| 308 | + // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 309 | + if (isset($c['login']) and strlen($c['login'])) { |
|
| 310 | + $champs['login'] = $c['login']; |
|
| 311 | + } |
|
| 312 | + if (isset($c['pass']) and strlen($c['pass'])) { |
|
| 313 | + $champs['pass'] = $c['pass']; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 317 | + |
|
| 318 | + if ( |
|
| 319 | + isset($c['statut']) |
|
| 320 | + and (autoriser('modifier', 'auteur', $id_auteur, null, ['statut' => $c['statut']])) |
|
| 321 | + ) { |
|
| 322 | + $statut = $champs['statut'] = $c['statut']; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + // Restreindre avant de declarer l'auteur |
|
| 326 | + // (section critique sur les droits) |
|
| 327 | + if (isset($c['id_parent']) and $c['id_parent']) { |
|
| 328 | + if (is_array($c['restreintes'])) { |
|
| 329 | + $c['restreintes'][] = $c['id_parent']; |
|
| 330 | + } else { |
|
| 331 | + $c['restreintes'] = [$c['id_parent']]; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + if ( |
|
| 336 | + isset($c['webmestre']) |
|
| 337 | + and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, ['webmestre' => '?'])) |
|
| 338 | + ) { |
|
| 339 | + $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non'; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + // si statut change et n'est pas 0minirezo, on force webmestre a non |
|
| 343 | + if (isset($c['statut']) and $c['statut'] !== '0minirezo') { |
|
| 344 | + $champs['webmestre'] = $c['webmestre'] = 'non'; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + // Envoyer aux plugins |
|
| 348 | + $champs = pipeline( |
|
| 349 | + 'pre_edition', |
|
| 350 | + [ |
|
| 351 | + 'args' => [ |
|
| 352 | + 'table' => 'spip_auteurs', |
|
| 353 | + 'id_objet' => $id_auteur, |
|
| 354 | + 'action' => 'instituer', |
|
| 355 | + 'statut_ancien' => $statut_ancien, |
|
| 356 | + ], |
|
| 357 | + 'data' => $champs |
|
| 358 | + ] |
|
| 359 | + ); |
|
| 360 | + |
|
| 361 | + if ( |
|
| 362 | + isset($c['restreintes']) and is_array($c['restreintes']) |
|
| 363 | + and autoriser('modifier', 'auteur', $id_auteur, null, ['restreint' => $c['restreintes']]) |
|
| 364 | + ) { |
|
| 365 | + $rubriques = array_map('intval', $c['restreintes']); |
|
| 366 | + $rubriques = array_unique($rubriques); |
|
| 367 | + $rubriques = array_diff($rubriques, [0]); |
|
| 368 | + auteur_dissocier($id_auteur, ['rubrique' => '*']); |
|
| 369 | + auteur_associer($id_auteur, ['rubrique' => $rubriques]); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + $flag_ecrire_acces = false; |
|
| 373 | + // commencer par traiter les cas particuliers des logins et pass |
|
| 374 | + // avant les autres ecritures en base |
|
| 375 | + if (isset($champs['login']) or isset($champs['pass'])) { |
|
| 376 | + $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 377 | + include_spip('inc/auth'); |
|
| 378 | + if (isset($champs['login']) and strlen($champs['login'])) { |
|
| 379 | + if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
|
| 380 | + $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + if (isset($champs['pass']) and strlen($champs['pass'])) { |
|
| 384 | + $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 385 | + if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
|
| 386 | + $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + unset($champs['login']); |
|
| 390 | + unset($champs['pass']); |
|
| 391 | + $flag_ecrire_acces = true; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 395 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 396 | + } |
|
| 397 | + sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 398 | + |
|
| 399 | + // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 400 | + if ( |
|
| 401 | + $flag_ecrire_acces |
|
| 402 | + or isset($champs['statut']) |
|
| 403 | + ) { |
|
| 404 | + include_spip('inc/acces'); |
|
| 405 | + ecrire_acces(); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + // Invalider les caches |
|
| 409 | + include_spip('inc/invalideur'); |
|
| 410 | + suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 411 | + |
|
| 412 | + // Pipeline |
|
| 413 | + pipeline( |
|
| 414 | + 'post_edition', |
|
| 415 | + [ |
|
| 416 | + 'args' => [ |
|
| 417 | + 'table' => 'spip_auteurs', |
|
| 418 | + 'id_objet' => $id_auteur, |
|
| 419 | + 'action' => 'instituer', |
|
| 420 | + 'statut_ancien' => $statut_ancien, |
|
| 421 | + ], |
|
| 422 | + 'data' => $champs |
|
| 423 | + ] |
|
| 424 | + ); |
|
| 425 | + |
|
| 426 | + |
|
| 427 | + // Notifications |
|
| 428 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 429 | + $notifications( |
|
| 430 | + 'instituerauteur', |
|
| 431 | + $id_auteur, |
|
| 432 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien] |
|
| 433 | + ); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 437 | 437 | } |
@@ -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 | /** |
@@ -29,24 +29,24 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | function action_instituer_objet_dist($arg = null) { |
| 31 | 31 | |
| 32 | - if (is_null($arg)) { |
|
| 33 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 34 | - $arg = $securiser_action(); |
|
| 35 | - } |
|
| 32 | + if (is_null($arg)) { |
|
| 33 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 34 | + $arg = $securiser_action(); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - [$objet, $id_objet, $statut] = preg_split('/\W/', $arg); |
|
| 38 | - if (!$statut) { |
|
| 39 | - $statut = _request('statut_nouv'); |
|
| 40 | - } // cas POST |
|
| 41 | - if (!$statut) { |
|
| 42 | - return; |
|
| 43 | - } // impossible mais sait-on jamais |
|
| 37 | + [$objet, $id_objet, $statut] = preg_split('/\W/', $arg); |
|
| 38 | + if (!$statut) { |
|
| 39 | + $statut = _request('statut_nouv'); |
|
| 40 | + } // cas POST |
|
| 41 | + if (!$statut) { |
|
| 42 | + return; |
|
| 43 | + } // impossible mais sait-on jamais |
|
| 44 | 44 | |
| 45 | - if ( |
|
| 46 | - $id_objet = intval($id_objet) |
|
| 47 | - and autoriser('instituer', $objet, $id_objet, '', ['statut' => $statut]) |
|
| 48 | - ) { |
|
| 49 | - include_spip('action/editer_objet'); |
|
| 50 | - objet_modifier($objet, $id_objet, ['statut' => $statut]); |
|
| 51 | - } |
|
| 45 | + if ( |
|
| 46 | + $id_objet = intval($id_objet) |
|
| 47 | + and autoriser('instituer', $objet, $id_objet, '', ['statut' => $statut]) |
|
| 48 | + ) { |
|
| 49 | + include_spip('action/editer_objet'); |
|
| 50 | + objet_modifier($objet, $id_objet, ['statut' => $statut]); |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | |
| 31 | 31 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 32 | - return; |
|
| 32 | + return; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | // charger la gestion les rôles sur les objets |
@@ -47,22 +47,22 @@ discard block |
||
| 47 | 47 | * - array(clé primaire, nom de la table de lien) si associable |
| 48 | 48 | */ |
| 49 | 49 | function objet_associable($objet) { |
| 50 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 51 | - $table_sql = table_objet_sql($objet); |
|
| 52 | - |
|
| 53 | - $l = ''; |
|
| 54 | - if ( |
|
| 55 | - $primary = id_table_objet($objet) |
|
| 56 | - and $trouver_table($l = $table_sql . '_liens', '', true, ['log_missing' => false]) |
|
| 57 | - and !preg_match(',[^\w],', $primary) |
|
| 58 | - and !preg_match(',[^\w],', $l) |
|
| 59 | - ) { |
|
| 60 | - return [$primary, $l]; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - spip_log("Objet $objet non associable : ne dispose pas d'une cle primaire $primary OU d'une table liens $l"); |
|
| 64 | - |
|
| 65 | - return false; |
|
| 50 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 51 | + $table_sql = table_objet_sql($objet); |
|
| 52 | + |
|
| 53 | + $l = ''; |
|
| 54 | + if ( |
|
| 55 | + $primary = id_table_objet($objet) |
|
| 56 | + and $trouver_table($l = $table_sql . '_liens', '', true, ['log_missing' => false]) |
|
| 57 | + and !preg_match(',[^\w],', $primary) |
|
| 58 | + and !preg_match(',[^\w],', $l) |
|
| 59 | + ) { |
|
| 60 | + return [$primary, $l]; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + spip_log("Objet $objet non associable : ne dispose pas d'une cle primaire $primary OU d'une table liens $l"); |
|
| 64 | + |
|
| 65 | + return false; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -88,13 +88,13 @@ discard block |
||
| 88 | 88 | * @return bool|int |
| 89 | 89 | */ |
| 90 | 90 | function objet_associer($objets_source, $objets_lies, $qualif = null) { |
| 91 | - $modifs = objet_traiter_liaisons('lien_insert', $objets_source, $objets_lies, $qualif); |
|
| 91 | + $modifs = objet_traiter_liaisons('lien_insert', $objets_source, $objets_lies, $qualif); |
|
| 92 | 92 | |
| 93 | - if ($qualif) { |
|
| 94 | - objet_qualifier_liens($objets_source, $objets_lies, $qualif); |
|
| 95 | - } |
|
| 93 | + if ($qualif) { |
|
| 94 | + objet_qualifier_liens($objets_source, $objets_lies, $qualif); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - return $modifs; // pas d'erreur |
|
| 97 | + return $modifs; // pas d'erreur |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | * @return bool|int |
| 129 | 129 | */ |
| 130 | 130 | function objet_dissocier($objets_source, $objets_lies, $cond = null) { |
| 131 | - return objet_traiter_liaisons('lien_delete', $objets_source, $objets_lies, $cond); |
|
| 131 | + return objet_traiter_liaisons('lien_delete', $objets_source, $objets_lies, $cond); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @return bool|int |
| 154 | 154 | */ |
| 155 | 155 | function objet_qualifier_liens($objets_source, $objets_lies, $qualif) { |
| 156 | - return objet_traiter_liaisons('lien_set', $objets_source, $objets_lies, $qualif); |
|
| 156 | + return objet_traiter_liaisons('lien_set', $objets_source, $objets_lies, $qualif); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | * Liste des trouvailles |
| 189 | 189 | */ |
| 190 | 190 | function objet_trouver_liens($objets_source, $objets_lies, $cond = null) { |
| 191 | - return objet_traiter_liaisons('lien_find', $objets_source, $objets_lies, $cond); |
|
| 191 | + return objet_traiter_liaisons('lien_find', $objets_source, $objets_lies, $cond); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
@@ -212,8 +212,8 @@ discard block |
||
| 212 | 212 | * @return int |
| 213 | 213 | */ |
| 214 | 214 | function objet_optimiser_liens($objets_source, $objets_lies) { |
| 215 | - spip_log('objet_optimiser_liens : ' . json_encode($objets_source, JSON_THROW_ON_ERROR) . ', ' . json_encode($objets_lies, JSON_THROW_ON_ERROR), 'genie' . _LOG_DEBUG); |
|
| 216 | - return objet_traiter_liaisons('lien_optimise', $objets_source, $objets_lies); |
|
| 215 | + spip_log('objet_optimiser_liens : ' . json_encode($objets_source, JSON_THROW_ON_ERROR) . ', ' . json_encode($objets_lies, JSON_THROW_ON_ERROR), 'genie' . _LOG_DEBUG); |
|
| 216 | + return objet_traiter_liaisons('lien_optimise', $objets_source, $objets_lies); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | |
@@ -233,37 +233,37 @@ discard block |
||
| 233 | 233 | * Nombre de liens copiés |
| 234 | 234 | */ |
| 235 | 235 | function objet_dupliquer_liens($objet, $id_source, $id_cible, $types = null, $exclure_types = null) { |
| 236 | - include_spip('base/objets'); |
|
| 237 | - $tables = lister_tables_objets_sql(); |
|
| 238 | - $n = 0; |
|
| 239 | - foreach ($tables as $table_sql => $infos) { |
|
| 240 | - if ( |
|
| 241 | - (is_null($types) or in_array($infos['type'], $types)) |
|
| 242 | - and (is_null($exclure_types) or !in_array($infos['type'], $exclure_types)) |
|
| 243 | - ) { |
|
| 244 | - if (objet_associable($infos['type'])) { |
|
| 245 | - $liens = (($infos['type'] == $objet) ? |
|
| 246 | - objet_trouver_liens([$objet => $id_source], '*') |
|
| 247 | - : |
|
| 248 | - objet_trouver_liens([$infos['type'] => '*'], [$objet => $id_source])); |
|
| 249 | - foreach ($liens as $lien) { |
|
| 250 | - $n++; |
|
| 251 | - if ($infos['type'] == $objet) { |
|
| 252 | - if ( |
|
| 253 | - (is_null($types) or in_array($lien['objet'], $types)) |
|
| 254 | - and (is_null($exclure_types) or !in_array($lien['objet'], $exclure_types)) |
|
| 255 | - ) { |
|
| 256 | - objet_associer([$objet => $id_cible], [$lien['objet'] => $lien[$lien['objet']]], $lien); |
|
| 257 | - } |
|
| 258 | - } else { |
|
| 259 | - objet_associer([$infos['type'] => $lien[$infos['type']]], [$objet => $id_cible], $lien); |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - return $n; |
|
| 236 | + include_spip('base/objets'); |
|
| 237 | + $tables = lister_tables_objets_sql(); |
|
| 238 | + $n = 0; |
|
| 239 | + foreach ($tables as $table_sql => $infos) { |
|
| 240 | + if ( |
|
| 241 | + (is_null($types) or in_array($infos['type'], $types)) |
|
| 242 | + and (is_null($exclure_types) or !in_array($infos['type'], $exclure_types)) |
|
| 243 | + ) { |
|
| 244 | + if (objet_associable($infos['type'])) { |
|
| 245 | + $liens = (($infos['type'] == $objet) ? |
|
| 246 | + objet_trouver_liens([$objet => $id_source], '*') |
|
| 247 | + : |
|
| 248 | + objet_trouver_liens([$infos['type'] => '*'], [$objet => $id_source])); |
|
| 249 | + foreach ($liens as $lien) { |
|
| 250 | + $n++; |
|
| 251 | + if ($infos['type'] == $objet) { |
|
| 252 | + if ( |
|
| 253 | + (is_null($types) or in_array($lien['objet'], $types)) |
|
| 254 | + and (is_null($exclure_types) or !in_array($lien['objet'], $exclure_types)) |
|
| 255 | + ) { |
|
| 256 | + objet_associer([$objet => $id_cible], [$lien['objet'] => $lien[$lien['objet']]], $lien); |
|
| 257 | + } |
|
| 258 | + } else { |
|
| 259 | + objet_associer([$infos['type'] => $lien[$infos['type']]], [$objet => $id_cible], $lien); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + return $n; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
@@ -305,38 +305,38 @@ discard block |
||
| 305 | 305 | * @return bool|int|array |
| 306 | 306 | */ |
| 307 | 307 | function objet_traiter_liaisons($operation, $objets_source, $objets_lies, $set = null) { |
| 308 | - // accepter une syntaxe minimale pour supprimer tous les liens |
|
| 309 | - if ($objets_lies == '*') { |
|
| 310 | - $objets_lies = ['*' => '*']; |
|
| 311 | - } |
|
| 312 | - $modifs = 0; // compter le nombre de modifications |
|
| 313 | - $echec = null; |
|
| 314 | - foreach ($objets_source as $objet => $ids) { |
|
| 315 | - if ($a = objet_associable($objet)) { |
|
| 316 | - [$primary, $l] = $a; |
|
| 317 | - if (!is_array($ids)) { |
|
| 318 | - $ids = [$ids]; |
|
| 319 | - } elseif (reset($ids) == 'NOT') { |
|
| 320 | - // si on demande un array('NOT',...) => recuperer la liste d'ids correspondants |
|
| 321 | - $where = lien_where($primary, $ids, '*', '*'); |
|
| 322 | - $ids = sql_allfetsel($primary, $l, $where); |
|
| 323 | - $ids = array_map('reset', $ids); |
|
| 324 | - } |
|
| 325 | - foreach ($ids as $id) { |
|
| 326 | - $res = $operation($objet, $primary, $l, $id, $objets_lies, $set); |
|
| 327 | - if ($res === false) { |
|
| 328 | - spip_log("objet_traiter_liaisons [Echec] : $operation sur $objet/$primary/$l/$id", _LOG_ERREUR); |
|
| 329 | - $echec = true; |
|
| 330 | - } else { |
|
| 331 | - $modifs = ($modifs ? (is_array($res) ? array_merge($modifs, $res) : $modifs + $res) : $res); |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - } else { |
|
| 335 | - $echec = true; |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - return ($echec ? false : $modifs); // pas d'erreur |
|
| 308 | + // accepter une syntaxe minimale pour supprimer tous les liens |
|
| 309 | + if ($objets_lies == '*') { |
|
| 310 | + $objets_lies = ['*' => '*']; |
|
| 311 | + } |
|
| 312 | + $modifs = 0; // compter le nombre de modifications |
|
| 313 | + $echec = null; |
|
| 314 | + foreach ($objets_source as $objet => $ids) { |
|
| 315 | + if ($a = objet_associable($objet)) { |
|
| 316 | + [$primary, $l] = $a; |
|
| 317 | + if (!is_array($ids)) { |
|
| 318 | + $ids = [$ids]; |
|
| 319 | + } elseif (reset($ids) == 'NOT') { |
|
| 320 | + // si on demande un array('NOT',...) => recuperer la liste d'ids correspondants |
|
| 321 | + $where = lien_where($primary, $ids, '*', '*'); |
|
| 322 | + $ids = sql_allfetsel($primary, $l, $where); |
|
| 323 | + $ids = array_map('reset', $ids); |
|
| 324 | + } |
|
| 325 | + foreach ($ids as $id) { |
|
| 326 | + $res = $operation($objet, $primary, $l, $id, $objets_lies, $set); |
|
| 327 | + if ($res === false) { |
|
| 328 | + spip_log("objet_traiter_liaisons [Echec] : $operation sur $objet/$primary/$l/$id", _LOG_ERREUR); |
|
| 329 | + $echec = true; |
|
| 330 | + } else { |
|
| 331 | + $modifs = ($modifs ? (is_array($res) ? array_merge($modifs, $res) : $modifs + $res) : $res); |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + } else { |
|
| 335 | + $echec = true; |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + return ($echec ? false : $modifs); // pas d'erreur |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | |
@@ -365,117 +365,117 @@ discard block |
||
| 365 | 365 | * Nombre d'insertions faites, false si échec. |
| 366 | 366 | */ |
| 367 | 367 | function lien_insert($objet_source, $primary, $table_lien, $id, $objets, $qualif) { |
| 368 | - $ins = 0; |
|
| 369 | - $echec = null; |
|
| 370 | - if (is_null($qualif)) { |
|
| 371 | - $qualif = []; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - foreach ($objets as $objet => $id_objets) { |
|
| 375 | - if (!is_array($id_objets)) { |
|
| 376 | - $id_objets = [$id_objets]; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - // role, colonne, where par défaut |
|
| 380 | - [$role, $colonne_role, $cond] = |
|
| 381 | - roles_trouver_dans_qualif($objet_source, $objet, $qualif); |
|
| 382 | - |
|
| 383 | - foreach ($id_objets as $id_objet) { |
|
| 384 | - $objet = (($objet == '*') ? $objet : objet_type($objet)); # securite |
|
| 385 | - |
|
| 386 | - $insertions = [ |
|
| 387 | - 'id_objet' => $id_objet, |
|
| 388 | - 'objet' => $objet, |
|
| 389 | - $primary => $id |
|
| 390 | - ]; |
|
| 391 | - // rôle en plus s'il est défini |
|
| 392 | - if ($role) { |
|
| 393 | - $insertions += [ |
|
| 394 | - $colonne_role => $role |
|
| 395 | - ]; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - if (lien_triables($table_lien)) { |
|
| 399 | - if (isset($qualif['rang_lien'])) { |
|
| 400 | - $rang = $qualif['rang_lien']; |
|
| 401 | - } |
|
| 402 | - else { |
|
| 403 | - $where = lien_where($primary, $id, $objet, $id_objet); |
|
| 404 | - // si il y a deja un lien pour ce couple (avec un autre role?) on reprend le meme rang si non nul |
|
| 405 | - if (!$rang = intval(sql_getfetsel('rang_lien', $table_lien, $where))) { |
|
| 406 | - $where = lien_rang_where($table_lien, $primary, $id, $objet, $id_objet); |
|
| 407 | - $rang = intval(sql_getfetsel('max(rang_lien)', $table_lien, $where)); |
|
| 408 | - // si aucun lien n'a de rang, on en introduit pas, on garde zero |
|
| 409 | - if ($rang > 0) { |
|
| 410 | - $rang = intval($rang) + 1; |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - $insertions['rang_lien'] = $rang; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - $args = [ |
|
| 418 | - 'table_lien' => $table_lien, |
|
| 419 | - 'objet_source' => $objet_source, |
|
| 420 | - 'id_objet_source' => $id, |
|
| 421 | - 'objet' => $objet, |
|
| 422 | - 'id_objet' => $id_objet, |
|
| 423 | - 'role' => $role, |
|
| 424 | - 'colonne_role' => $colonne_role, |
|
| 425 | - 'action' => 'insert', |
|
| 426 | - ]; |
|
| 427 | - |
|
| 428 | - // Envoyer aux plugins |
|
| 429 | - $insertions = pipeline( |
|
| 430 | - 'pre_edition_lien', |
|
| 431 | - [ |
|
| 432 | - 'args' => $args, |
|
| 433 | - 'data' => $insertions |
|
| 434 | - ] |
|
| 435 | - ); |
|
| 436 | - $args['id_objet'] = $insertions['id_objet']; |
|
| 437 | - |
|
| 438 | - $where = lien_where($primary, $id, $objet, $id_objet, $cond); |
|
| 439 | - |
|
| 440 | - if ( |
|
| 441 | - ($id_objet = intval($insertions['id_objet']) or in_array($objet, ['site', 'rubrique'])) |
|
| 442 | - and !sql_getfetsel($primary, $table_lien, $where) |
|
| 443 | - ) { |
|
| 444 | - if (lien_triables($table_lien) and isset($insertions['rang_lien']) and intval($insertions['rang_lien'])) { |
|
| 445 | - $where_meme_lien = lien_where($primary, $id, $objet, $id_objet); |
|
| 446 | - $where_meme_lien = implode(' AND ', $where_meme_lien); |
|
| 447 | - // on decale les liens de rang_lien>=la valeur inseree pour faire la place |
|
| 448 | - // sauf sur le meme lien avec un role eventuellement different |
|
| 449 | - $w = lien_rang_where($table_lien, $primary, $id, $objet, $id_objet, ['rang_lien>=' . intval($insertions['rang_lien']), "NOT($where_meme_lien)"]); |
|
| 450 | - sql_update($table_lien, ['rang_lien' => 'rang_lien+1'], $w); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - $e = sql_insertq($table_lien, $insertions); |
|
| 454 | - if ($e !== false) { |
|
| 455 | - $ins++; |
|
| 456 | - lien_propage_date_modif($objet, $id_objet); |
|
| 457 | - lien_propage_date_modif($objet_source, $id); |
|
| 458 | - // Envoyer aux plugins |
|
| 459 | - pipeline( |
|
| 460 | - 'post_edition_lien', |
|
| 461 | - [ |
|
| 462 | - 'args' => $args, |
|
| 463 | - 'data' => $insertions |
|
| 464 | - ] |
|
| 465 | - ); |
|
| 466 | - } else { |
|
| 467 | - $echec = true; |
|
| 468 | - } |
|
| 469 | - } |
|
| 470 | - } |
|
| 471 | - } |
|
| 472 | - // si on a fait des insertions, on reordonne les liens concernes |
|
| 473 | - // pas la peine si $qualif['rang_lien'] etait fournie, on va passer dans lien_set a suivre et donc finir le recomptage |
|
| 474 | - if ($ins > 0 and empty($qualif['rang_lien'])) { |
|
| 475 | - lien_ordonner($objet_source, $primary, $table_lien, $id, $objets); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - return ($echec ? false : $ins); |
|
| 368 | + $ins = 0; |
|
| 369 | + $echec = null; |
|
| 370 | + if (is_null($qualif)) { |
|
| 371 | + $qualif = []; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + foreach ($objets as $objet => $id_objets) { |
|
| 375 | + if (!is_array($id_objets)) { |
|
| 376 | + $id_objets = [$id_objets]; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + // role, colonne, where par défaut |
|
| 380 | + [$role, $colonne_role, $cond] = |
|
| 381 | + roles_trouver_dans_qualif($objet_source, $objet, $qualif); |
|
| 382 | + |
|
| 383 | + foreach ($id_objets as $id_objet) { |
|
| 384 | + $objet = (($objet == '*') ? $objet : objet_type($objet)); # securite |
|
| 385 | + |
|
| 386 | + $insertions = [ |
|
| 387 | + 'id_objet' => $id_objet, |
|
| 388 | + 'objet' => $objet, |
|
| 389 | + $primary => $id |
|
| 390 | + ]; |
|
| 391 | + // rôle en plus s'il est défini |
|
| 392 | + if ($role) { |
|
| 393 | + $insertions += [ |
|
| 394 | + $colonne_role => $role |
|
| 395 | + ]; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + if (lien_triables($table_lien)) { |
|
| 399 | + if (isset($qualif['rang_lien'])) { |
|
| 400 | + $rang = $qualif['rang_lien']; |
|
| 401 | + } |
|
| 402 | + else { |
|
| 403 | + $where = lien_where($primary, $id, $objet, $id_objet); |
|
| 404 | + // si il y a deja un lien pour ce couple (avec un autre role?) on reprend le meme rang si non nul |
|
| 405 | + if (!$rang = intval(sql_getfetsel('rang_lien', $table_lien, $where))) { |
|
| 406 | + $where = lien_rang_where($table_lien, $primary, $id, $objet, $id_objet); |
|
| 407 | + $rang = intval(sql_getfetsel('max(rang_lien)', $table_lien, $where)); |
|
| 408 | + // si aucun lien n'a de rang, on en introduit pas, on garde zero |
|
| 409 | + if ($rang > 0) { |
|
| 410 | + $rang = intval($rang) + 1; |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + $insertions['rang_lien'] = $rang; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + $args = [ |
|
| 418 | + 'table_lien' => $table_lien, |
|
| 419 | + 'objet_source' => $objet_source, |
|
| 420 | + 'id_objet_source' => $id, |
|
| 421 | + 'objet' => $objet, |
|
| 422 | + 'id_objet' => $id_objet, |
|
| 423 | + 'role' => $role, |
|
| 424 | + 'colonne_role' => $colonne_role, |
|
| 425 | + 'action' => 'insert', |
|
| 426 | + ]; |
|
| 427 | + |
|
| 428 | + // Envoyer aux plugins |
|
| 429 | + $insertions = pipeline( |
|
| 430 | + 'pre_edition_lien', |
|
| 431 | + [ |
|
| 432 | + 'args' => $args, |
|
| 433 | + 'data' => $insertions |
|
| 434 | + ] |
|
| 435 | + ); |
|
| 436 | + $args['id_objet'] = $insertions['id_objet']; |
|
| 437 | + |
|
| 438 | + $where = lien_where($primary, $id, $objet, $id_objet, $cond); |
|
| 439 | + |
|
| 440 | + if ( |
|
| 441 | + ($id_objet = intval($insertions['id_objet']) or in_array($objet, ['site', 'rubrique'])) |
|
| 442 | + and !sql_getfetsel($primary, $table_lien, $where) |
|
| 443 | + ) { |
|
| 444 | + if (lien_triables($table_lien) and isset($insertions['rang_lien']) and intval($insertions['rang_lien'])) { |
|
| 445 | + $where_meme_lien = lien_where($primary, $id, $objet, $id_objet); |
|
| 446 | + $where_meme_lien = implode(' AND ', $where_meme_lien); |
|
| 447 | + // on decale les liens de rang_lien>=la valeur inseree pour faire la place |
|
| 448 | + // sauf sur le meme lien avec un role eventuellement different |
|
| 449 | + $w = lien_rang_where($table_lien, $primary, $id, $objet, $id_objet, ['rang_lien>=' . intval($insertions['rang_lien']), "NOT($where_meme_lien)"]); |
|
| 450 | + sql_update($table_lien, ['rang_lien' => 'rang_lien+1'], $w); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + $e = sql_insertq($table_lien, $insertions); |
|
| 454 | + if ($e !== false) { |
|
| 455 | + $ins++; |
|
| 456 | + lien_propage_date_modif($objet, $id_objet); |
|
| 457 | + lien_propage_date_modif($objet_source, $id); |
|
| 458 | + // Envoyer aux plugins |
|
| 459 | + pipeline( |
|
| 460 | + 'post_edition_lien', |
|
| 461 | + [ |
|
| 462 | + 'args' => $args, |
|
| 463 | + 'data' => $insertions |
|
| 464 | + ] |
|
| 465 | + ); |
|
| 466 | + } else { |
|
| 467 | + $echec = true; |
|
| 468 | + } |
|
| 469 | + } |
|
| 470 | + } |
|
| 471 | + } |
|
| 472 | + // si on a fait des insertions, on reordonne les liens concernes |
|
| 473 | + // pas la peine si $qualif['rang_lien'] etait fournie, on va passer dans lien_set a suivre et donc finir le recomptage |
|
| 474 | + if ($ins > 0 and empty($qualif['rang_lien'])) { |
|
| 475 | + lien_ordonner($objet_source, $primary, $table_lien, $id, $objets); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + return ($echec ? false : $ins); |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | |
@@ -488,47 +488,47 @@ discard block |
||
| 488 | 488 | * @param array|string $objets |
| 489 | 489 | */ |
| 490 | 490 | function lien_ordonner($objet_source, $primary, $table_lien, $id, $objets) { |
| 491 | - if (!lien_triables($table_lien)) { |
|
| 492 | - return; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - $deja_reordonne = []; |
|
| 496 | - |
|
| 497 | - foreach ($objets as $objet => $id_objets) { |
|
| 498 | - if (!is_array($id_objets)) { |
|
| 499 | - $id_objets = [$id_objets]; |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - foreach ($id_objets as $id_objet) { |
|
| 503 | - if (empty($deja_reordonne[$id][$objet][$id_objet])) { |
|
| 504 | - $objet = (($objet == '*') ? $objet : objet_type($objet)); # securite |
|
| 505 | - |
|
| 506 | - $where = lien_rang_where($table_lien, $primary, $id, $objet, $id_objet); |
|
| 507 | - $liens = sql_allfetsel("$primary, id_objet, objet, rang_lien", $table_lien, $where, '', 'rang_lien'); |
|
| 508 | - |
|
| 509 | - $rangs = array_column($liens, 'rang_lien'); |
|
| 510 | - if (count($rangs) and (max($rangs) > 0 or min($rangs) < 0)) { |
|
| 511 | - $rang = 1; |
|
| 512 | - foreach ($liens as $lien) { |
|
| 513 | - if (empty($deja_reordonne[$lien[$primary]][$lien['objet']][$lien['id_objet']])) { |
|
| 514 | - $where = lien_where($primary, $lien[$primary], $lien['objet'], $lien['id_objet'], ['rang_lien!=' . intval($rang)]); |
|
| 515 | - sql_updateq($table_lien, ['rang_lien' => $rang], $where); |
|
| 516 | - |
|
| 517 | - if (empty($deja_reordonne[$lien[$primary]])) { |
|
| 518 | - $deja_reordonne[$lien[$primary]] = []; |
|
| 519 | - } |
|
| 520 | - if (empty($deja_reordonne[$lien[$primary]][$lien['objet']])) { |
|
| 521 | - $deja_reordonne[$lien[$primary]][$lien['objet']] = []; |
|
| 522 | - } |
|
| 523 | - $deja_reordonne[$lien[$primary]][$lien['objet']][$lien['id_objet']] = $rang; |
|
| 524 | - |
|
| 525 | - $rang++; |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - } |
|
| 530 | - } |
|
| 531 | - } |
|
| 491 | + if (!lien_triables($table_lien)) { |
|
| 492 | + return; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + $deja_reordonne = []; |
|
| 496 | + |
|
| 497 | + foreach ($objets as $objet => $id_objets) { |
|
| 498 | + if (!is_array($id_objets)) { |
|
| 499 | + $id_objets = [$id_objets]; |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + foreach ($id_objets as $id_objet) { |
|
| 503 | + if (empty($deja_reordonne[$id][$objet][$id_objet])) { |
|
| 504 | + $objet = (($objet == '*') ? $objet : objet_type($objet)); # securite |
|
| 505 | + |
|
| 506 | + $where = lien_rang_where($table_lien, $primary, $id, $objet, $id_objet); |
|
| 507 | + $liens = sql_allfetsel("$primary, id_objet, objet, rang_lien", $table_lien, $where, '', 'rang_lien'); |
|
| 508 | + |
|
| 509 | + $rangs = array_column($liens, 'rang_lien'); |
|
| 510 | + if (count($rangs) and (max($rangs) > 0 or min($rangs) < 0)) { |
|
| 511 | + $rang = 1; |
|
| 512 | + foreach ($liens as $lien) { |
|
| 513 | + if (empty($deja_reordonne[$lien[$primary]][$lien['objet']][$lien['id_objet']])) { |
|
| 514 | + $where = lien_where($primary, $lien[$primary], $lien['objet'], $lien['id_objet'], ['rang_lien!=' . intval($rang)]); |
|
| 515 | + sql_updateq($table_lien, ['rang_lien' => $rang], $where); |
|
| 516 | + |
|
| 517 | + if (empty($deja_reordonne[$lien[$primary]])) { |
|
| 518 | + $deja_reordonne[$lien[$primary]] = []; |
|
| 519 | + } |
|
| 520 | + if (empty($deja_reordonne[$lien[$primary]][$lien['objet']])) { |
|
| 521 | + $deja_reordonne[$lien[$primary]][$lien['objet']] = []; |
|
| 522 | + } |
|
| 523 | + $deja_reordonne[$lien[$primary]][$lien['objet']][$lien['id_objet']] = $rang; |
|
| 524 | + |
|
| 525 | + $rang++; |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + } |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | |
@@ -539,18 +539,18 @@ discard block |
||
| 539 | 539 | * @return mixed |
| 540 | 540 | */ |
| 541 | 541 | function lien_triables($table_lien) { |
| 542 | - static $triables = []; |
|
| 543 | - if (!isset($triables[$table_lien])) { |
|
| 544 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 545 | - $desc = $trouver_table($table_lien); |
|
| 546 | - if ($desc and isset($desc['field']['rang_lien'])) { |
|
| 547 | - $triables[$table_lien] = true; |
|
| 548 | - } |
|
| 549 | - else { |
|
| 550 | - $triables[$table_lien] = false; |
|
| 551 | - } |
|
| 552 | - } |
|
| 553 | - return $triables[$table_lien]; |
|
| 542 | + static $triables = []; |
|
| 543 | + if (!isset($triables[$table_lien])) { |
|
| 544 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 545 | + $desc = $trouver_table($table_lien); |
|
| 546 | + if ($desc and isset($desc['field']['rang_lien'])) { |
|
| 547 | + $triables[$table_lien] = true; |
|
| 548 | + } |
|
| 549 | + else { |
|
| 550 | + $triables[$table_lien] = false; |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | + return $triables[$table_lien]; |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | |
@@ -566,52 +566,52 @@ discard block |
||
| 566 | 566 | * @return array Liste des conditions |
| 567 | 567 | */ |
| 568 | 568 | function lien_where($primary, $id_source, $objet, $id_objet, $cond = []) { |
| 569 | - if ( |
|
| 570 | - (!is_array($id_source) and !strlen($id_source)) |
|
| 571 | - or !strlen($objet) |
|
| 572 | - or (!is_array($id_objet) and !strlen($id_objet)) |
|
| 573 | - ) { |
|
| 574 | - return ['0=1']; |
|
| 575 | - } // securite |
|
| 576 | - |
|
| 577 | - $not = ''; |
|
| 578 | - if (is_array($id_source) and reset($id_source) == 'NOT') { |
|
| 579 | - $not = array_shift($id_source); |
|
| 580 | - $id_source = reset($id_source); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - $where = $cond; |
|
| 584 | - |
|
| 585 | - if ($id_source !== '*') { |
|
| 586 | - $where[] = (is_array($id_source) ? sql_in( |
|
| 587 | - addslashes($primary), |
|
| 588 | - array_map('intval', $id_source), |
|
| 589 | - $not |
|
| 590 | - ) : addslashes($primary) . ($not ? '<>' : '=') . intval($id_source)); |
|
| 591 | - } elseif ($not) { |
|
| 592 | - $where[] = '0=1'; |
|
| 593 | - } // idiot mais quand meme |
|
| 594 | - |
|
| 595 | - $not = ''; |
|
| 596 | - if (is_array($id_objet) and reset($id_objet) == 'NOT') { |
|
| 597 | - $not = array_shift($id_objet); |
|
| 598 | - $id_objet = reset($id_objet); |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - if ($objet !== '*') { |
|
| 602 | - $where[] = 'objet=' . sql_quote($objet); |
|
| 603 | - } |
|
| 604 | - if ($id_objet !== '*') { |
|
| 605 | - $where[] = (is_array($id_objet) ? sql_in( |
|
| 606 | - 'id_objet', |
|
| 607 | - array_map('intval', $id_objet), |
|
| 608 | - $not |
|
| 609 | - ) : 'id_objet' . ($not ? '<>' : '=') . intval($id_objet)); |
|
| 610 | - } elseif ($not) { |
|
| 611 | - $where[] = '0=1'; |
|
| 612 | - } // idiot mais quand meme |
|
| 613 | - |
|
| 614 | - return $where; |
|
| 569 | + if ( |
|
| 570 | + (!is_array($id_source) and !strlen($id_source)) |
|
| 571 | + or !strlen($objet) |
|
| 572 | + or (!is_array($id_objet) and !strlen($id_objet)) |
|
| 573 | + ) { |
|
| 574 | + return ['0=1']; |
|
| 575 | + } // securite |
|
| 576 | + |
|
| 577 | + $not = ''; |
|
| 578 | + if (is_array($id_source) and reset($id_source) == 'NOT') { |
|
| 579 | + $not = array_shift($id_source); |
|
| 580 | + $id_source = reset($id_source); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + $where = $cond; |
|
| 584 | + |
|
| 585 | + if ($id_source !== '*') { |
|
| 586 | + $where[] = (is_array($id_source) ? sql_in( |
|
| 587 | + addslashes($primary), |
|
| 588 | + array_map('intval', $id_source), |
|
| 589 | + $not |
|
| 590 | + ) : addslashes($primary) . ($not ? '<>' : '=') . intval($id_source)); |
|
| 591 | + } elseif ($not) { |
|
| 592 | + $where[] = '0=1'; |
|
| 593 | + } // idiot mais quand meme |
|
| 594 | + |
|
| 595 | + $not = ''; |
|
| 596 | + if (is_array($id_objet) and reset($id_objet) == 'NOT') { |
|
| 597 | + $not = array_shift($id_objet); |
|
| 598 | + $id_objet = reset($id_objet); |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + if ($objet !== '*') { |
|
| 602 | + $where[] = 'objet=' . sql_quote($objet); |
|
| 603 | + } |
|
| 604 | + if ($id_objet !== '*') { |
|
| 605 | + $where[] = (is_array($id_objet) ? sql_in( |
|
| 606 | + 'id_objet', |
|
| 607 | + array_map('intval', $id_objet), |
|
| 608 | + $not |
|
| 609 | + ) : 'id_objet' . ($not ? '<>' : '=') . intval($id_objet)); |
|
| 610 | + } elseif ($not) { |
|
| 611 | + $where[] = '0=1'; |
|
| 612 | + } // idiot mais quand meme |
|
| 613 | + |
|
| 614 | + return $where; |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | /** |
@@ -626,13 +626,13 @@ discard block |
||
| 626 | 626 | */ |
| 627 | 627 | function lien_rang_where($table_lien, $primary, $id_source, $objet, $id_objet, $cond = []) { |
| 628 | 628 | |
| 629 | - // si on veut compter les rangs autrement que le core ne le fait par defaut, fournir le where adhoc |
|
| 630 | - if (function_exists($f = 'lien_rang_where_' . $table_lien)) { |
|
| 631 | - return $f($primary, $id_source, $objet, $id_objet, $cond); |
|
| 632 | - } |
|
| 629 | + // si on veut compter les rangs autrement que le core ne le fait par defaut, fournir le where adhoc |
|
| 630 | + if (function_exists($f = 'lien_rang_where_' . $table_lien)) { |
|
| 631 | + return $f($primary, $id_source, $objet, $id_objet, $cond); |
|
| 632 | + } |
|
| 633 | 633 | |
| 634 | - // par defaut c'est un rang compté pour tous les id_source d'un couple objet-id_objet |
|
| 635 | - return lien_where($primary, '*', $objet, $id_objet, $cond); |
|
| 634 | + // par defaut c'est un rang compté pour tous les id_source d'un couple objet-id_objet |
|
| 635 | + return lien_where($primary, '*', $objet, $id_objet, $cond); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | /** |
@@ -663,90 +663,90 @@ discard block |
||
| 663 | 663 | */ |
| 664 | 664 | function lien_delete($objet_source, $primary, $table_lien, $id, $objets, $cond = null) { |
| 665 | 665 | |
| 666 | - $retire = []; |
|
| 667 | - $dels = 0; |
|
| 668 | - $echec = false; |
|
| 669 | - if (is_null($cond)) { |
|
| 670 | - $cond = []; |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - foreach ($objets as $objet => $id_objets) { |
|
| 674 | - $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 675 | - if (!is_array($id_objets) or reset($id_objets) == 'NOT') { |
|
| 676 | - $id_objets = [$id_objets]; |
|
| 677 | - } |
|
| 678 | - foreach ($id_objets as $id_objet) { |
|
| 679 | - [$cond, $colonne_role, $role] = roles_creer_condition_role($objet_source, $objet, $cond); |
|
| 680 | - // id_objet peut valoir '*' |
|
| 681 | - $where = lien_where($primary, $id, $objet, $id_objet, $cond); |
|
| 682 | - |
|
| 683 | - // lire les liens existants pour propager la date de modif |
|
| 684 | - $select = "$primary,id_objet,objet"; |
|
| 685 | - if ($colonne_role) { |
|
| 686 | - $select .= ",$colonne_role"; |
|
| 687 | - } |
|
| 688 | - $liens = sql_allfetsel($select, $table_lien, $where); |
|
| 689 | - |
|
| 690 | - // iterer sur les liens pour permettre aux plugins de gerer |
|
| 691 | - foreach ($liens as $l) { |
|
| 692 | - $args = [ |
|
| 693 | - 'table_lien' => $table_lien, |
|
| 694 | - 'objet_source' => $objet_source, |
|
| 695 | - 'id_objet_source' => $l[$primary], |
|
| 696 | - 'objet' => $l['objet'], |
|
| 697 | - 'id_objet' => $l['id_objet'], |
|
| 698 | - 'colonne_role' => $colonne_role, |
|
| 699 | - 'role' => ($colonne_role ? $l[$colonne_role] : ''), |
|
| 700 | - 'action' => 'delete', |
|
| 701 | - ]; |
|
| 702 | - |
|
| 703 | - // Envoyer aux plugins |
|
| 704 | - $l = pipeline( |
|
| 705 | - 'pre_edition_lien', |
|
| 706 | - [ |
|
| 707 | - 'args' => $args, |
|
| 708 | - 'data' => $l |
|
| 709 | - ] |
|
| 710 | - ); |
|
| 711 | - $args['id_objet'] = $id_o = $l['id_objet']; |
|
| 712 | - |
|
| 713 | - if ($id_o = intval($l['id_objet']) or in_array($l['objet'], ['site', 'rubrique'])) { |
|
| 714 | - $where = lien_where($primary, $l[$primary], $l['objet'], $id_o, $cond); |
|
| 715 | - $e = sql_delete($table_lien, $where); |
|
| 716 | - if ($e !== false) { |
|
| 717 | - $dels += $e; |
|
| 718 | - lien_propage_date_modif($l['objet'], $id_o); |
|
| 719 | - lien_propage_date_modif($objet_source, $l[$primary]); |
|
| 720 | - } else { |
|
| 721 | - $echec = true; |
|
| 722 | - } |
|
| 723 | - $retire[] = [ |
|
| 724 | - 'source' => [$objet_source => $l[$primary]], |
|
| 725 | - 'lien' => [$l['objet'] => $id_o], |
|
| 726 | - 'type' => $l['objet'], |
|
| 727 | - 'role' => ($colonne_role ? $l[$colonne_role] : ''), |
|
| 728 | - 'id' => $id_o |
|
| 729 | - ]; |
|
| 730 | - // Envoyer aux plugins |
|
| 731 | - pipeline( |
|
| 732 | - 'post_edition_lien', |
|
| 733 | - [ |
|
| 734 | - 'args' => $args, |
|
| 735 | - 'data' => $l |
|
| 736 | - ] |
|
| 737 | - ); |
|
| 738 | - } |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - } |
|
| 742 | - // si on a supprime des liens, on reordonne les liens concernes |
|
| 743 | - if ($dels) { |
|
| 744 | - lien_ordonner($objet_source, $primary, $table_lien, $id, $objets); |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - pipeline('trig_supprimer_objets_lies', $retire); |
|
| 748 | - |
|
| 749 | - return ($echec ? false : $dels); |
|
| 666 | + $retire = []; |
|
| 667 | + $dels = 0; |
|
| 668 | + $echec = false; |
|
| 669 | + if (is_null($cond)) { |
|
| 670 | + $cond = []; |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + foreach ($objets as $objet => $id_objets) { |
|
| 674 | + $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 675 | + if (!is_array($id_objets) or reset($id_objets) == 'NOT') { |
|
| 676 | + $id_objets = [$id_objets]; |
|
| 677 | + } |
|
| 678 | + foreach ($id_objets as $id_objet) { |
|
| 679 | + [$cond, $colonne_role, $role] = roles_creer_condition_role($objet_source, $objet, $cond); |
|
| 680 | + // id_objet peut valoir '*' |
|
| 681 | + $where = lien_where($primary, $id, $objet, $id_objet, $cond); |
|
| 682 | + |
|
| 683 | + // lire les liens existants pour propager la date de modif |
|
| 684 | + $select = "$primary,id_objet,objet"; |
|
| 685 | + if ($colonne_role) { |
|
| 686 | + $select .= ",$colonne_role"; |
|
| 687 | + } |
|
| 688 | + $liens = sql_allfetsel($select, $table_lien, $where); |
|
| 689 | + |
|
| 690 | + // iterer sur les liens pour permettre aux plugins de gerer |
|
| 691 | + foreach ($liens as $l) { |
|
| 692 | + $args = [ |
|
| 693 | + 'table_lien' => $table_lien, |
|
| 694 | + 'objet_source' => $objet_source, |
|
| 695 | + 'id_objet_source' => $l[$primary], |
|
| 696 | + 'objet' => $l['objet'], |
|
| 697 | + 'id_objet' => $l['id_objet'], |
|
| 698 | + 'colonne_role' => $colonne_role, |
|
| 699 | + 'role' => ($colonne_role ? $l[$colonne_role] : ''), |
|
| 700 | + 'action' => 'delete', |
|
| 701 | + ]; |
|
| 702 | + |
|
| 703 | + // Envoyer aux plugins |
|
| 704 | + $l = pipeline( |
|
| 705 | + 'pre_edition_lien', |
|
| 706 | + [ |
|
| 707 | + 'args' => $args, |
|
| 708 | + 'data' => $l |
|
| 709 | + ] |
|
| 710 | + ); |
|
| 711 | + $args['id_objet'] = $id_o = $l['id_objet']; |
|
| 712 | + |
|
| 713 | + if ($id_o = intval($l['id_objet']) or in_array($l['objet'], ['site', 'rubrique'])) { |
|
| 714 | + $where = lien_where($primary, $l[$primary], $l['objet'], $id_o, $cond); |
|
| 715 | + $e = sql_delete($table_lien, $where); |
|
| 716 | + if ($e !== false) { |
|
| 717 | + $dels += $e; |
|
| 718 | + lien_propage_date_modif($l['objet'], $id_o); |
|
| 719 | + lien_propage_date_modif($objet_source, $l[$primary]); |
|
| 720 | + } else { |
|
| 721 | + $echec = true; |
|
| 722 | + } |
|
| 723 | + $retire[] = [ |
|
| 724 | + 'source' => [$objet_source => $l[$primary]], |
|
| 725 | + 'lien' => [$l['objet'] => $id_o], |
|
| 726 | + 'type' => $l['objet'], |
|
| 727 | + 'role' => ($colonne_role ? $l[$colonne_role] : ''), |
|
| 728 | + 'id' => $id_o |
|
| 729 | + ]; |
|
| 730 | + // Envoyer aux plugins |
|
| 731 | + pipeline( |
|
| 732 | + 'post_edition_lien', |
|
| 733 | + [ |
|
| 734 | + 'args' => $args, |
|
| 735 | + 'data' => $l |
|
| 736 | + ] |
|
| 737 | + ); |
|
| 738 | + } |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + } |
|
| 742 | + // si on a supprime des liens, on reordonne les liens concernes |
|
| 743 | + if ($dels) { |
|
| 744 | + lien_ordonner($objet_source, $primary, $table_lien, $id, $objets); |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + pipeline('trig_supprimer_objets_lies', $retire); |
|
| 748 | + |
|
| 749 | + return ($echec ? false : $dels); |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | |
@@ -769,67 +769,67 @@ discard block |
||
| 769 | 769 | * @return bool|int |
| 770 | 770 | */ |
| 771 | 771 | function lien_optimise($objet_source, $primary, $table_lien, $id, $objets) { |
| 772 | - include_spip('genie/optimiser'); |
|
| 773 | - $echec = false; |
|
| 774 | - $dels = 0; |
|
| 775 | - foreach ($objets as $objet => $id_objets) { |
|
| 776 | - $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 777 | - if (!is_array($id_objets) or reset($id_objets) == 'NOT') { |
|
| 778 | - $id_objets = [$id_objets]; |
|
| 779 | - } |
|
| 780 | - foreach ($id_objets as $id_objet) { |
|
| 781 | - $where = lien_where($primary, $id, $objet, $id_objet); |
|
| 782 | - # les liens vers un objet inexistant |
|
| 783 | - $r = sql_select('DISTINCT objet', $table_lien, $where); |
|
| 784 | - while ($t = sql_fetch($r)) { |
|
| 785 | - $type = $t['objet']; |
|
| 786 | - $spip_table_objet = table_objet_sql($type); |
|
| 787 | - $id_table_objet = id_table_objet($type); |
|
| 788 | - $res = sql_select( |
|
| 789 | - "L.$primary AS id,L.id_objet", |
|
| 790 | - // la condition de jointure inclue L.objet='xxx' pour ne joindre que les bonnes lignes |
|
| 791 | - // du coups toutes les lignes avec un autre objet ont un id_xxx=NULL puisque LEFT JOIN |
|
| 792 | - // il faut les eliminier en repetant la condition dans le where L.objet='xxx' |
|
| 793 | - "$table_lien AS L |
|
| 772 | + include_spip('genie/optimiser'); |
|
| 773 | + $echec = false; |
|
| 774 | + $dels = 0; |
|
| 775 | + foreach ($objets as $objet => $id_objets) { |
|
| 776 | + $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 777 | + if (!is_array($id_objets) or reset($id_objets) == 'NOT') { |
|
| 778 | + $id_objets = [$id_objets]; |
|
| 779 | + } |
|
| 780 | + foreach ($id_objets as $id_objet) { |
|
| 781 | + $where = lien_where($primary, $id, $objet, $id_objet); |
|
| 782 | + # les liens vers un objet inexistant |
|
| 783 | + $r = sql_select('DISTINCT objet', $table_lien, $where); |
|
| 784 | + while ($t = sql_fetch($r)) { |
|
| 785 | + $type = $t['objet']; |
|
| 786 | + $spip_table_objet = table_objet_sql($type); |
|
| 787 | + $id_table_objet = id_table_objet($type); |
|
| 788 | + $res = sql_select( |
|
| 789 | + "L.$primary AS id,L.id_objet", |
|
| 790 | + // la condition de jointure inclue L.objet='xxx' pour ne joindre que les bonnes lignes |
|
| 791 | + // du coups toutes les lignes avec un autre objet ont un id_xxx=NULL puisque LEFT JOIN |
|
| 792 | + // il faut les eliminier en repetant la condition dans le where L.objet='xxx' |
|
| 793 | + "$table_lien AS L |
|
| 794 | 794 | LEFT JOIN $spip_table_objet AS O |
| 795 | 795 | ON (O.$id_table_objet=L.id_objet AND L.objet=" . sql_quote($type) . ')', |
| 796 | - 'L.objet=' . sql_quote($type) . " AND O.$id_table_objet IS NULL" |
|
| 797 | - ); |
|
| 798 | - // sur une cle primaire composee, pas d'autres solutions que de virer un a un |
|
| 799 | - while ($row = sql_fetch($res)) { |
|
| 800 | - if ($primary === 'id_document' and in_array($type, ['site', 'rubrique']) and !intval($row['id_objet'])) { |
|
| 801 | - continue; // gaffe, c'est le logo du site ou des rubriques! |
|
| 802 | - } |
|
| 803 | - $e = sql_delete( |
|
| 804 | - $table_lien, |
|
| 805 | - ["$primary=" . $row['id'], 'id_objet=' . $row['id_objet'], 'objet=' . sql_quote($type)] |
|
| 806 | - ); |
|
| 807 | - if ($e != false) { |
|
| 808 | - $dels += $e; |
|
| 809 | - spip_log( |
|
| 810 | - 'lien_optimise: Entree ' . $row['id'] . '/' . $row['id_objet'] . "/$type supprimee dans la table $table_lien", |
|
| 811 | - 'genie' . _LOG_INFO_IMPORTANTE |
|
| 812 | - ); |
|
| 813 | - } |
|
| 814 | - } |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - # les liens depuis un objet inexistant |
|
| 818 | - $table_source = table_objet_sql($objet_source); |
|
| 819 | - // filtrer selon $id, $objet, $id_objet eventuellement fournis |
|
| 820 | - // (en general '*' pour chaque) |
|
| 821 | - $where = lien_where("L.$primary", $id, $objet, $id_objet); |
|
| 822 | - $where[] = "O.$primary IS NULL"; |
|
| 823 | - $res = sql_select( |
|
| 824 | - "L.$primary AS id", |
|
| 825 | - "$table_lien AS L LEFT JOIN $table_source AS O ON L.$primary=O.$primary", |
|
| 826 | - $where |
|
| 827 | - ); |
|
| 828 | - $dels += optimiser_sansref($table_lien, $primary, $res); |
|
| 829 | - } |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - return ($echec ? false : $dels); |
|
| 796 | + 'L.objet=' . sql_quote($type) . " AND O.$id_table_objet IS NULL" |
|
| 797 | + ); |
|
| 798 | + // sur une cle primaire composee, pas d'autres solutions que de virer un a un |
|
| 799 | + while ($row = sql_fetch($res)) { |
|
| 800 | + if ($primary === 'id_document' and in_array($type, ['site', 'rubrique']) and !intval($row['id_objet'])) { |
|
| 801 | + continue; // gaffe, c'est le logo du site ou des rubriques! |
|
| 802 | + } |
|
| 803 | + $e = sql_delete( |
|
| 804 | + $table_lien, |
|
| 805 | + ["$primary=" . $row['id'], 'id_objet=' . $row['id_objet'], 'objet=' . sql_quote($type)] |
|
| 806 | + ); |
|
| 807 | + if ($e != false) { |
|
| 808 | + $dels += $e; |
|
| 809 | + spip_log( |
|
| 810 | + 'lien_optimise: Entree ' . $row['id'] . '/' . $row['id_objet'] . "/$type supprimee dans la table $table_lien", |
|
| 811 | + 'genie' . _LOG_INFO_IMPORTANTE |
|
| 812 | + ); |
|
| 813 | + } |
|
| 814 | + } |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + # les liens depuis un objet inexistant |
|
| 818 | + $table_source = table_objet_sql($objet_source); |
|
| 819 | + // filtrer selon $id, $objet, $id_objet eventuellement fournis |
|
| 820 | + // (en general '*' pour chaque) |
|
| 821 | + $where = lien_where("L.$primary", $id, $objet, $id_objet); |
|
| 822 | + $where[] = "O.$primary IS NULL"; |
|
| 823 | + $res = sql_select( |
|
| 824 | + "L.$primary AS id", |
|
| 825 | + "$table_lien AS L LEFT JOIN $table_source AS O ON L.$primary=O.$primary", |
|
| 826 | + $where |
|
| 827 | + ); |
|
| 828 | + $dels += optimiser_sansref($table_lien, $primary, $res); |
|
| 829 | + } |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + return ($echec ? false : $dels); |
|
| 833 | 833 | } |
| 834 | 834 | |
| 835 | 835 | |
@@ -861,92 +861,92 @@ discard block |
||
| 861 | 861 | * Nombre de modifications faites, false si échec. |
| 862 | 862 | */ |
| 863 | 863 | function lien_set($objet_source, $primary, $table_lien, $id, $objets, $qualif) { |
| 864 | - $echec = null; |
|
| 865 | - $ok = 0; |
|
| 866 | - $reordonner = false; |
|
| 867 | - if (!$qualif) { |
|
| 868 | - return false; |
|
| 869 | - } |
|
| 870 | - // nettoyer qualif qui peut venir directement d'un objet_trouver_lien : |
|
| 871 | - unset($qualif[$primary]); |
|
| 872 | - unset($qualif[$objet_source]); |
|
| 873 | - if (isset($qualif['objet'])) { |
|
| 874 | - unset($qualif[$qualif['objet']]); |
|
| 875 | - } |
|
| 876 | - unset($qualif['objet']); |
|
| 877 | - unset($qualif['id_objet']); |
|
| 878 | - foreach ($objets as $objet => $id_objets) { |
|
| 879 | - // role, colonne, where par défaut |
|
| 880 | - [$role, $colonne_role, $cond] = |
|
| 881 | - roles_trouver_dans_qualif($objet_source, $objet, $qualif); |
|
| 882 | - |
|
| 883 | - $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 884 | - if (!is_array($id_objets) or reset($id_objets) == 'NOT') { |
|
| 885 | - $id_objets = [$id_objets]; |
|
| 886 | - } |
|
| 887 | - foreach ($id_objets as $id_objet) { |
|
| 888 | - $args = [ |
|
| 889 | - 'table_lien' => $table_lien, |
|
| 890 | - 'objet_source' => $objet_source, |
|
| 891 | - 'id_objet_source' => $id, |
|
| 892 | - 'objet' => $objet, |
|
| 893 | - 'id_objet' => $id_objet, |
|
| 894 | - 'role' => $role, |
|
| 895 | - 'colonne_role' => $colonne_role, |
|
| 896 | - 'action' => 'modifier', |
|
| 897 | - ]; |
|
| 898 | - |
|
| 899 | - // Envoyer aux plugins |
|
| 900 | - $qualif = pipeline( |
|
| 901 | - 'pre_edition_lien', |
|
| 902 | - [ |
|
| 903 | - 'args' => $args, |
|
| 904 | - 'data' => $qualif, |
|
| 905 | - ] |
|
| 906 | - ); |
|
| 907 | - $args['id_objet'] = $id_objet; |
|
| 908 | - |
|
| 909 | - if (lien_triables($table_lien) and isset($qualif['rang_lien'])) { |
|
| 910 | - if (intval($qualif['rang_lien'])) { |
|
| 911 | - // on decale les liens de rang_lien>=la valeur inseree pour faire la place |
|
| 912 | - // sauf sur le meme lien avec un role eventuellement different |
|
| 913 | - $where_meme_lien = lien_where($primary, $id, $objet, $id_objet); |
|
| 914 | - $where_meme_lien = implode(' AND ', $where_meme_lien); |
|
| 915 | - $w = lien_rang_where($table_lien, $primary, $id, $objet, $id_objet, ['rang_lien>=' . intval($qualif['rang_lien']), "NOT($where_meme_lien)"]); |
|
| 916 | - sql_update($table_lien, ['rang_lien' => 'rang_lien+1'], $w); |
|
| 917 | - } |
|
| 918 | - // tous les liens de même rôle recoivent le rang indiqué aussi |
|
| 919 | - if (roles_colonne($objet_source, $objet)) { |
|
| 920 | - $w = lien_where($primary, $id, $objet, $id_objet); |
|
| 921 | - sql_updateq($table_lien, ['rang_lien' => intval($qualif['rang_lien'])], $w); |
|
| 922 | - } |
|
| 923 | - $reordonner = true; |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - $where = lien_where($primary, $id, $objet, $id_objet, $cond); |
|
| 927 | - $e = sql_updateq($table_lien, $qualif, $where); |
|
| 928 | - |
|
| 929 | - if ($e === false) { |
|
| 930 | - $echec = true; |
|
| 931 | - } else { |
|
| 932 | - // Envoyer aux plugins |
|
| 933 | - pipeline( |
|
| 934 | - 'post_edition_lien', |
|
| 935 | - [ |
|
| 936 | - 'args' => $args, |
|
| 937 | - 'data' => $qualif |
|
| 938 | - ] |
|
| 939 | - ); |
|
| 940 | - $ok++; |
|
| 941 | - } |
|
| 942 | - } |
|
| 943 | - } |
|
| 944 | - // si on a fait des modif de rang, on reordonne les liens concernes |
|
| 945 | - if ($reordonner) { |
|
| 946 | - lien_ordonner($objet_source, $primary, $table_lien, $id, $objets); |
|
| 947 | - } |
|
| 948 | - |
|
| 949 | - return ($echec ? false : $ok); |
|
| 864 | + $echec = null; |
|
| 865 | + $ok = 0; |
|
| 866 | + $reordonner = false; |
|
| 867 | + if (!$qualif) { |
|
| 868 | + return false; |
|
| 869 | + } |
|
| 870 | + // nettoyer qualif qui peut venir directement d'un objet_trouver_lien : |
|
| 871 | + unset($qualif[$primary]); |
|
| 872 | + unset($qualif[$objet_source]); |
|
| 873 | + if (isset($qualif['objet'])) { |
|
| 874 | + unset($qualif[$qualif['objet']]); |
|
| 875 | + } |
|
| 876 | + unset($qualif['objet']); |
|
| 877 | + unset($qualif['id_objet']); |
|
| 878 | + foreach ($objets as $objet => $id_objets) { |
|
| 879 | + // role, colonne, where par défaut |
|
| 880 | + [$role, $colonne_role, $cond] = |
|
| 881 | + roles_trouver_dans_qualif($objet_source, $objet, $qualif); |
|
| 882 | + |
|
| 883 | + $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 884 | + if (!is_array($id_objets) or reset($id_objets) == 'NOT') { |
|
| 885 | + $id_objets = [$id_objets]; |
|
| 886 | + } |
|
| 887 | + foreach ($id_objets as $id_objet) { |
|
| 888 | + $args = [ |
|
| 889 | + 'table_lien' => $table_lien, |
|
| 890 | + 'objet_source' => $objet_source, |
|
| 891 | + 'id_objet_source' => $id, |
|
| 892 | + 'objet' => $objet, |
|
| 893 | + 'id_objet' => $id_objet, |
|
| 894 | + 'role' => $role, |
|
| 895 | + 'colonne_role' => $colonne_role, |
|
| 896 | + 'action' => 'modifier', |
|
| 897 | + ]; |
|
| 898 | + |
|
| 899 | + // Envoyer aux plugins |
|
| 900 | + $qualif = pipeline( |
|
| 901 | + 'pre_edition_lien', |
|
| 902 | + [ |
|
| 903 | + 'args' => $args, |
|
| 904 | + 'data' => $qualif, |
|
| 905 | + ] |
|
| 906 | + ); |
|
| 907 | + $args['id_objet'] = $id_objet; |
|
| 908 | + |
|
| 909 | + if (lien_triables($table_lien) and isset($qualif['rang_lien'])) { |
|
| 910 | + if (intval($qualif['rang_lien'])) { |
|
| 911 | + // on decale les liens de rang_lien>=la valeur inseree pour faire la place |
|
| 912 | + // sauf sur le meme lien avec un role eventuellement different |
|
| 913 | + $where_meme_lien = lien_where($primary, $id, $objet, $id_objet); |
|
| 914 | + $where_meme_lien = implode(' AND ', $where_meme_lien); |
|
| 915 | + $w = lien_rang_where($table_lien, $primary, $id, $objet, $id_objet, ['rang_lien>=' . intval($qualif['rang_lien']), "NOT($where_meme_lien)"]); |
|
| 916 | + sql_update($table_lien, ['rang_lien' => 'rang_lien+1'], $w); |
|
| 917 | + } |
|
| 918 | + // tous les liens de même rôle recoivent le rang indiqué aussi |
|
| 919 | + if (roles_colonne($objet_source, $objet)) { |
|
| 920 | + $w = lien_where($primary, $id, $objet, $id_objet); |
|
| 921 | + sql_updateq($table_lien, ['rang_lien' => intval($qualif['rang_lien'])], $w); |
|
| 922 | + } |
|
| 923 | + $reordonner = true; |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + $where = lien_where($primary, $id, $objet, $id_objet, $cond); |
|
| 927 | + $e = sql_updateq($table_lien, $qualif, $where); |
|
| 928 | + |
|
| 929 | + if ($e === false) { |
|
| 930 | + $echec = true; |
|
| 931 | + } else { |
|
| 932 | + // Envoyer aux plugins |
|
| 933 | + pipeline( |
|
| 934 | + 'post_edition_lien', |
|
| 935 | + [ |
|
| 936 | + 'args' => $args, |
|
| 937 | + 'data' => $qualif |
|
| 938 | + ] |
|
| 939 | + ); |
|
| 940 | + $ok++; |
|
| 941 | + } |
|
| 942 | + } |
|
| 943 | + } |
|
| 944 | + // si on a fait des modif de rang, on reordonne les liens concernes |
|
| 945 | + if ($reordonner) { |
|
| 946 | + lien_ordonner($objet_source, $primary, $table_lien, $id, $objets); |
|
| 947 | + } |
|
| 948 | + |
|
| 949 | + return ($echec ? false : $ok); |
|
| 950 | 950 | } |
| 951 | 951 | |
| 952 | 952 | /** |
@@ -976,23 +976,23 @@ discard block |
||
| 976 | 976 | * @return array |
| 977 | 977 | */ |
| 978 | 978 | function lien_find($objet_source, $primary, $table_lien, $id, $objets, $cond = null) { |
| 979 | - $trouve = []; |
|
| 980 | - foreach ($objets as $objet => $id_objets) { |
|
| 981 | - $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 982 | - // gerer les roles s'il y en a dans $cond |
|
| 983 | - [$cond] = roles_creer_condition_role($objet_source, $objet, $cond, true); |
|
| 984 | - // lien_where prend en charge les $id_objets sous forme int ou array |
|
| 985 | - $where = lien_where($primary, $id, $objet, $id_objets, $cond); |
|
| 986 | - $liens = sql_allfetsel('*', $table_lien, $where); |
|
| 987 | - // ajouter les entrees objet_source et objet cible par convenance |
|
| 988 | - foreach ($liens as $l) { |
|
| 989 | - $l[$objet_source] = $l[$primary]; |
|
| 990 | - $l[$l['objet']] = $l['id_objet']; |
|
| 991 | - $trouve[] = $l; |
|
| 992 | - } |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - return $trouve; |
|
| 979 | + $trouve = []; |
|
| 980 | + foreach ($objets as $objet => $id_objets) { |
|
| 981 | + $objet = ($objet == '*') ? $objet : objet_type($objet); # securite |
|
| 982 | + // gerer les roles s'il y en a dans $cond |
|
| 983 | + [$cond] = roles_creer_condition_role($objet_source, $objet, $cond, true); |
|
| 984 | + // lien_where prend en charge les $id_objets sous forme int ou array |
|
| 985 | + $where = lien_where($primary, $id, $objet, $id_objets, $cond); |
|
| 986 | + $liens = sql_allfetsel('*', $table_lien, $where); |
|
| 987 | + // ajouter les entrees objet_source et objet cible par convenance |
|
| 988 | + foreach ($liens as $l) { |
|
| 989 | + $l[$objet_source] = $l[$primary]; |
|
| 990 | + $l[$l['objet']] = $l['id_objet']; |
|
| 991 | + $trouve[] = $l; |
|
| 992 | + } |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + return $trouve; |
|
| 996 | 996 | } |
| 997 | 997 | |
| 998 | 998 | /** |
@@ -1003,26 +1003,26 @@ discard block |
||
| 1003 | 1003 | * @param array|int $ids |
| 1004 | 1004 | */ |
| 1005 | 1005 | function lien_propage_date_modif($objet, $ids) { |
| 1006 | - static $done = []; |
|
| 1007 | - $hash = md5($objet . serialize($ids)); |
|
| 1008 | - |
|
| 1009 | - // sql_updateq, peut être un rien lent. |
|
| 1010 | - // On évite de l'appeler 2 fois sur les mêmes choses |
|
| 1011 | - if (isset($done[$hash])) { |
|
| 1012 | - return; |
|
| 1013 | - } |
|
| 1014 | - |
|
| 1015 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1016 | - |
|
| 1017 | - $table = table_objet_sql($objet); |
|
| 1018 | - if ( |
|
| 1019 | - $desc = $trouver_table($table) |
|
| 1020 | - and isset($desc['field']['date_modif']) |
|
| 1021 | - ) { |
|
| 1022 | - $primary = id_table_objet($objet); |
|
| 1023 | - $where = (is_array($ids) ? sql_in($primary, array_map('intval', $ids)) : "$primary=" . intval($ids)); |
|
| 1024 | - sql_updateq($table, ['date_modif' => date('Y-m-d H:i:s')], $where); |
|
| 1025 | - } |
|
| 1026 | - |
|
| 1027 | - $done[$hash] = true; |
|
| 1006 | + static $done = []; |
|
| 1007 | + $hash = md5($objet . serialize($ids)); |
|
| 1008 | + |
|
| 1009 | + // sql_updateq, peut être un rien lent. |
|
| 1010 | + // On évite de l'appeler 2 fois sur les mêmes choses |
|
| 1011 | + if (isset($done[$hash])) { |
|
| 1012 | + return; |
|
| 1013 | + } |
|
| 1014 | + |
|
| 1015 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1016 | + |
|
| 1017 | + $table = table_objet_sql($objet); |
|
| 1018 | + if ( |
|
| 1019 | + $desc = $trouver_table($table) |
|
| 1020 | + and isset($desc['field']['date_modif']) |
|
| 1021 | + ) { |
|
| 1022 | + $primary = id_table_objet($objet); |
|
| 1023 | + $where = (is_array($ids) ? sql_in($primary, array_map('intval', $ids)) : "$primary=" . intval($ids)); |
|
| 1024 | + sql_updateq($table, ['date_modif' => date('Y-m-d H:i:s')], $where); |
|
| 1025 | + } |
|
| 1026 | + |
|
| 1027 | + $done[$hash] = true; |
|
| 1028 | 1028 | } |