@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | include_spip('base/objets'); |
| 23 | 23 | |
@@ -57,106 +57,106 @@ discard block |
||
| 57 | 57 | * |
| 58 | 58 | */ |
| 59 | 59 | function urls_decoder_url($url, $fond = '', $contexte = [], $assembler = false) { |
| 60 | - static $current_base = null; |
|
| 60 | + static $current_base = null; |
|
| 61 | 61 | |
| 62 | - // les anciennes fonctions modifient directement les globales |
|
| 63 | - // on les sauve avant l'appel, et on les retablit apres ! |
|
| 64 | - $save = [ |
|
| 65 | - $GLOBALS['fond'] ?? null, |
|
| 66 | - $GLOBALS['contexte'] ?? null, |
|
| 67 | - $_SERVER['REDIRECT_url_propre'] ?? null, |
|
| 68 | - $_ENV['url_propre'] ?? null, |
|
| 69 | - $GLOBALS['profondeur_url'] |
|
| 70 | - ]; |
|
| 62 | + // les anciennes fonctions modifient directement les globales |
|
| 63 | + // on les sauve avant l'appel, et on les retablit apres ! |
|
| 64 | + $save = [ |
|
| 65 | + $GLOBALS['fond'] ?? null, |
|
| 66 | + $GLOBALS['contexte'] ?? null, |
|
| 67 | + $_SERVER['REDIRECT_url_propre'] ?? null, |
|
| 68 | + $_ENV['url_propre'] ?? null, |
|
| 69 | + $GLOBALS['profondeur_url'] |
|
| 70 | + ]; |
|
| 71 | 71 | |
| 72 | - if (is_null($current_base)) { |
|
| 73 | - include_spip('inc/filtres_mini'); |
|
| 74 | - // le decodage des urls se fait toujours par rapport au site public |
|
| 75 | - $current_base = url_absolue(_DIR_RACINE ?: './'); |
|
| 76 | - } |
|
| 77 | - if (strncmp($url, $current_base, strlen($current_base)) == 0) { |
|
| 78 | - $url = substr($url, strlen($current_base)); |
|
| 79 | - } |
|
| 72 | + if (is_null($current_base)) { |
|
| 73 | + include_spip('inc/filtres_mini'); |
|
| 74 | + // le decodage des urls se fait toujours par rapport au site public |
|
| 75 | + $current_base = url_absolue(_DIR_RACINE ?: './'); |
|
| 76 | + } |
|
| 77 | + if (strncmp($url, $current_base, strlen($current_base)) == 0) { |
|
| 78 | + $url = substr($url, strlen($current_base)); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - // si on est en train d'assembler la page principale, |
|
| 82 | - // recuperer l'url depuis les globales url propres si fournies |
|
| 83 | - // sinon extraire la bonne portion d'url |
|
| 84 | - if ($assembler) { |
|
| 85 | - if (isset($_SERVER['REDIRECT_url_propre'])) { |
|
| 86 | - $url = $_SERVER['REDIRECT_url_propre']; |
|
| 87 | - } elseif (isset($_ENV['url_propre'])) { |
|
| 88 | - $url = $_ENV['url_propre']; |
|
| 89 | - } else { |
|
| 90 | - $qs = explode('?', $url); |
|
| 91 | - // ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee |
|
| 92 | - $url = ltrim($qs[0], '/'); |
|
| 93 | - $url = explode('/', $url); |
|
| 94 | - while (count($url) > $GLOBALS['profondeur_url'] + 1) { |
|
| 95 | - array_shift($url); |
|
| 96 | - } |
|
| 97 | - $qs[0] = implode('/', $url); |
|
| 98 | - $url = implode('?', $qs); |
|
| 99 | - } |
|
| 100 | - } |
|
| 81 | + // si on est en train d'assembler la page principale, |
|
| 82 | + // recuperer l'url depuis les globales url propres si fournies |
|
| 83 | + // sinon extraire la bonne portion d'url |
|
| 84 | + if ($assembler) { |
|
| 85 | + if (isset($_SERVER['REDIRECT_url_propre'])) { |
|
| 86 | + $url = $_SERVER['REDIRECT_url_propre']; |
|
| 87 | + } elseif (isset($_ENV['url_propre'])) { |
|
| 88 | + $url = $_ENV['url_propre']; |
|
| 89 | + } else { |
|
| 90 | + $qs = explode('?', $url); |
|
| 91 | + // ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee |
|
| 92 | + $url = ltrim($qs[0], '/'); |
|
| 93 | + $url = explode('/', $url); |
|
| 94 | + while (count($url) > $GLOBALS['profondeur_url'] + 1) { |
|
| 95 | + array_shift($url); |
|
| 96 | + } |
|
| 97 | + $qs[0] = implode('/', $url); |
|
| 98 | + $url = implode('?', $qs); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - unset($_SERVER['REDIRECT_url_propre']); |
|
| 103 | - unset($_ENV['url_propre']); |
|
| 104 | - include_spip('inc/filtres_mini'); |
|
| 105 | - if (strpos($url, '://') === false) { |
|
| 106 | - $GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/'); |
|
| 107 | - } else { |
|
| 108 | - $GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/')); |
|
| 109 | - } |
|
| 102 | + unset($_SERVER['REDIRECT_url_propre']); |
|
| 103 | + unset($_ENV['url_propre']); |
|
| 104 | + include_spip('inc/filtres_mini'); |
|
| 105 | + if (strpos($url, '://') === false) { |
|
| 106 | + $GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/'); |
|
| 107 | + } else { |
|
| 108 | + $GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/')); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - $url_redirect = ''; |
|
| 112 | - $decoder = charger_fonction_url('decoder'); |
|
| 113 | - if ($decoder) { |
|
| 114 | - $a = $decoder($url, $fond, $contexte); |
|
| 115 | - if (is_array($a)) { |
|
| 116 | - [$ncontexte, $type, $url_redirect, $nfond] = array_pad($a, 4, null); |
|
| 117 | - $url_redirect ??= ''; |
|
| 118 | - if ($url_redirect === $url) { |
|
| 119 | - $url_redirect = ''; |
|
| 120 | - } // securite pour eviter une redirection infinie |
|
| 121 | - if ($assembler and strlen($url_redirect)) { |
|
| 122 | - spip_log("Redirige $url vers $url_redirect"); |
|
| 123 | - include_spip('inc/headers'); |
|
| 124 | - redirige_par_entete($url_redirect, '', 301); |
|
| 125 | - } |
|
| 126 | - if (isset($nfond)) { |
|
| 127 | - $fond = $nfond; |
|
| 128 | - } else { |
|
| 129 | - if ( |
|
| 130 | - $fond == '' |
|
| 131 | - or $fond == 'type_urls' /* compat avec htaccess 2.0.0 */ |
|
| 132 | - ) { |
|
| 133 | - $fond = $type; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - if (isset($ncontexte)) { |
|
| 137 | - $contexte = $ncontexte; |
|
| 138 | - } |
|
| 139 | - if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 140 | - $contexte['type'] = $type; |
|
| 141 | - } |
|
| 142 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 143 | - $contexte['type-page'] = $type; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - } |
|
| 111 | + $url_redirect = ''; |
|
| 112 | + $decoder = charger_fonction_url('decoder'); |
|
| 113 | + if ($decoder) { |
|
| 114 | + $a = $decoder($url, $fond, $contexte); |
|
| 115 | + if (is_array($a)) { |
|
| 116 | + [$ncontexte, $type, $url_redirect, $nfond] = array_pad($a, 4, null); |
|
| 117 | + $url_redirect ??= ''; |
|
| 118 | + if ($url_redirect === $url) { |
|
| 119 | + $url_redirect = ''; |
|
| 120 | + } // securite pour eviter une redirection infinie |
|
| 121 | + if ($assembler and strlen($url_redirect)) { |
|
| 122 | + spip_log("Redirige $url vers $url_redirect"); |
|
| 123 | + include_spip('inc/headers'); |
|
| 124 | + redirige_par_entete($url_redirect, '', 301); |
|
| 125 | + } |
|
| 126 | + if (isset($nfond)) { |
|
| 127 | + $fond = $nfond; |
|
| 128 | + } else { |
|
| 129 | + if ( |
|
| 130 | + $fond == '' |
|
| 131 | + or $fond == 'type_urls' /* compat avec htaccess 2.0.0 */ |
|
| 132 | + ) { |
|
| 133 | + $fond = $type; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + if (isset($ncontexte)) { |
|
| 137 | + $contexte = $ncontexte; |
|
| 138 | + } |
|
| 139 | + if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 140 | + $contexte['type'] = $type; |
|
| 141 | + } |
|
| 142 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 143 | + $contexte['type-page'] = $type; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - // retablir les globales |
|
| 149 | - [$GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']] = $save; |
|
| 148 | + // retablir les globales |
|
| 149 | + [$GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']] = $save; |
|
| 150 | 150 | |
| 151 | - // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 152 | - // d'inversion url => objet |
|
| 153 | - // maintenir pour compat ? |
|
| 154 | - #if ($assembler) { |
|
| 155 | - # unset($_SERVER['REDIRECT_url_propre']); |
|
| 156 | - # unset($_ENV['url_propre']); |
|
| 157 | - #} |
|
| 151 | + // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 152 | + // d'inversion url => objet |
|
| 153 | + // maintenir pour compat ? |
|
| 154 | + #if ($assembler) { |
|
| 155 | + # unset($_SERVER['REDIRECT_url_propre']); |
|
| 156 | + # unset($_ENV['url_propre']); |
|
| 157 | + #} |
|
| 158 | 158 | |
| 159 | - return [$fond, $contexte, $url_redirect]; |
|
| 159 | + return [$fond, $contexte, $url_redirect]; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
@@ -169,20 +169,20 @@ discard block |
||
| 169 | 169 | * @return array|false|string |
| 170 | 170 | */ |
| 171 | 171 | function urls_transition_retrouver_anciennes_url_propres(string $url_propre, string $entite, array $contexte = []): array { |
| 172 | - if ($url_propre) { |
|
| 173 | - if ($GLOBALS['profondeur_url'] <= 0) { |
|
| 174 | - $urls_anciennes = charger_fonction_url('decoder', 'propres'); |
|
| 175 | - } else { |
|
| 176 | - $urls_anciennes = charger_fonction_url('decoder', 'arbo'); |
|
| 177 | - } |
|
| 172 | + if ($url_propre) { |
|
| 173 | + if ($GLOBALS['profondeur_url'] <= 0) { |
|
| 174 | + $urls_anciennes = charger_fonction_url('decoder', 'propres'); |
|
| 175 | + } else { |
|
| 176 | + $urls_anciennes = charger_fonction_url('decoder', 'arbo'); |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - if ($urls_anciennes) { |
|
| 180 | - $urls_anciennes = $urls_anciennes($url_propre, $entite, $contexte); |
|
| 181 | - } |
|
| 182 | - return $urls_anciennes ?: []; |
|
| 183 | - } |
|
| 179 | + if ($urls_anciennes) { |
|
| 180 | + $urls_anciennes = $urls_anciennes($url_propre, $entite, $contexte); |
|
| 181 | + } |
|
| 182 | + return $urls_anciennes ?: []; |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - return []; |
|
| 185 | + return []; |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -195,41 +195,41 @@ discard block |
||
| 195 | 195 | * @return array|false|string |
| 196 | 196 | */ |
| 197 | 197 | function urls_transition_retrouver_anciennes_url_html(string $url, string $entite, array $contexte = []): array { |
| 198 | - // Migration depuis anciennes URLs ? |
|
| 199 | - // traiter les injections domain.tld/spip.php/n/importe/quoi/rubrique23 |
|
| 200 | - if ( |
|
| 201 | - $url |
|
| 202 | - and $GLOBALS['profondeur_url'] <= 0 |
|
| 203 | - ) { |
|
| 204 | - $r = nettoyer_url_page($url, $contexte); |
|
| 205 | - if ($r) { |
|
| 206 | - [$contexte, $type, , , $suite] = $r; |
|
| 207 | - $_id = id_table_objet($type); |
|
| 208 | - $id_objet = $contexte[$_id]; |
|
| 209 | - $url_propre = generer_objet_url($id_objet, $type); |
|
| 210 | - if ( |
|
| 211 | - strlen($url_propre) |
|
| 212 | - and !strstr($url, (string) $url_propre) |
|
| 213 | - and ( |
|
| 214 | - objet_test_si_publie($type, $id_objet) |
|
| 215 | - or (defined('_VAR_PREVIEW') and _VAR_PREVIEW and autoriser('voir', $type, $id_objet)) |
|
| 216 | - ) |
|
| 217 | - ) { |
|
| 218 | - [, $hash] = array_pad(explode('#', $url_propre), 2, ''); |
|
| 219 | - $args = []; |
|
| 220 | - foreach (array_filter(explode('&', $suite ?? '')) as $fragment) { |
|
| 221 | - if ($fragment != "$_id=$id_objet") { |
|
| 222 | - $args[] = $fragment; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - $url_redirect = generer_objet_url($id_objet, $type, join('&', array_filter($args)), $hash); |
|
| 198 | + // Migration depuis anciennes URLs ? |
|
| 199 | + // traiter les injections domain.tld/spip.php/n/importe/quoi/rubrique23 |
|
| 200 | + if ( |
|
| 201 | + $url |
|
| 202 | + and $GLOBALS['profondeur_url'] <= 0 |
|
| 203 | + ) { |
|
| 204 | + $r = nettoyer_url_page($url, $contexte); |
|
| 205 | + if ($r) { |
|
| 206 | + [$contexte, $type, , , $suite] = $r; |
|
| 207 | + $_id = id_table_objet($type); |
|
| 208 | + $id_objet = $contexte[$_id]; |
|
| 209 | + $url_propre = generer_objet_url($id_objet, $type); |
|
| 210 | + if ( |
|
| 211 | + strlen($url_propre) |
|
| 212 | + and !strstr($url, (string) $url_propre) |
|
| 213 | + and ( |
|
| 214 | + objet_test_si_publie($type, $id_objet) |
|
| 215 | + or (defined('_VAR_PREVIEW') and _VAR_PREVIEW and autoriser('voir', $type, $id_objet)) |
|
| 216 | + ) |
|
| 217 | + ) { |
|
| 218 | + [, $hash] = array_pad(explode('#', $url_propre), 2, ''); |
|
| 219 | + $args = []; |
|
| 220 | + foreach (array_filter(explode('&', $suite ?? '')) as $fragment) { |
|
| 221 | + if ($fragment != "$_id=$id_objet") { |
|
| 222 | + $args[] = $fragment; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + $url_redirect = generer_objet_url($id_objet, $type, join('&', array_filter($args)), $hash); |
|
| 226 | 226 | |
| 227 | - return [$contexte, $type, $url_redirect, $type]; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - /* Fin compatibilite anciennes urls */ |
|
| 232 | - return []; |
|
| 227 | + return [$contexte, $type, $url_redirect, $type]; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + /* Fin compatibilite anciennes urls */ |
|
| 232 | + return []; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -242,24 +242,24 @@ discard block |
||
| 242 | 242 | * @return string|array |
| 243 | 243 | */ |
| 244 | 244 | function urls_liste_objets($preg = true) { |
| 245 | - static $url_objets = null; |
|
| 246 | - if (is_null($url_objets)) { |
|
| 247 | - $url_objets = []; |
|
| 248 | - // recuperer les tables_objets_sql declarees |
|
| 249 | - $tables_objets = lister_tables_objets_sql(); |
|
| 250 | - foreach ($tables_objets as $t => $infos) { |
|
| 251 | - if ($infos['page']) { |
|
| 252 | - $url_objets[] = $infos['type']; |
|
| 253 | - $url_objets = array_merge($url_objets, $infos['type_surnoms']); |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - $url_objets = pipeline('declarer_url_objets', $url_objets); |
|
| 257 | - } |
|
| 258 | - if (!$preg) { |
|
| 259 | - return $url_objets; |
|
| 260 | - } |
|
| 245 | + static $url_objets = null; |
|
| 246 | + if (is_null($url_objets)) { |
|
| 247 | + $url_objets = []; |
|
| 248 | + // recuperer les tables_objets_sql declarees |
|
| 249 | + $tables_objets = lister_tables_objets_sql(); |
|
| 250 | + foreach ($tables_objets as $t => $infos) { |
|
| 251 | + if ($infos['page']) { |
|
| 252 | + $url_objets[] = $infos['type']; |
|
| 253 | + $url_objets = array_merge($url_objets, $infos['type_surnoms']); |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + $url_objets = pipeline('declarer_url_objets', $url_objets); |
|
| 257 | + } |
|
| 258 | + if (!$preg) { |
|
| 259 | + return $url_objets; |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - return implode('|', array_map('preg_quote', $url_objets)); |
|
| 262 | + return implode('|', array_map('preg_quote', $url_objets)); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
@@ -273,26 +273,26 @@ discard block |
||
| 273 | 273 | * @return array |
| 274 | 274 | */ |
| 275 | 275 | function nettoyer_url_page($url, $contexte = []) { |
| 276 | - $url_objets = urls_liste_objets(); |
|
| 277 | - $raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,'; |
|
| 278 | - $raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,'; |
|
| 279 | - $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,'; |
|
| 276 | + $url_objets = urls_liste_objets(); |
|
| 277 | + $raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,'; |
|
| 278 | + $raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,'; |
|
| 279 | + $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,'; |
|
| 280 | 280 | |
| 281 | - if ( |
|
| 282 | - preg_match($raccourci_url_page_html, $url, $regs) |
|
| 283 | - or preg_match($raccourci_url_page_id, $url, $regs) |
|
| 284 | - or preg_match($raccourci_url_page_spip, $url, $regs) |
|
| 285 | - ) { |
|
| 286 | - $regs = array_pad($regs, 4, null); |
|
| 287 | - $type = objet_type($regs[1]); |
|
| 288 | - $_id = id_table_objet($type); |
|
| 289 | - $contexte[$_id] = $regs[2]; |
|
| 290 | - $suite = $regs[3]; |
|
| 281 | + if ( |
|
| 282 | + preg_match($raccourci_url_page_html, $url, $regs) |
|
| 283 | + or preg_match($raccourci_url_page_id, $url, $regs) |
|
| 284 | + or preg_match($raccourci_url_page_spip, $url, $regs) |
|
| 285 | + ) { |
|
| 286 | + $regs = array_pad($regs, 4, null); |
|
| 287 | + $type = objet_type($regs[1]); |
|
| 288 | + $_id = id_table_objet($type); |
|
| 289 | + $contexte[$_id] = $regs[2]; |
|
| 290 | + $suite = $regs[3]; |
|
| 291 | 291 | |
| 292 | - return [$contexte, $type, null, $type, $suite]; |
|
| 293 | - } |
|
| 292 | + return [$contexte, $type, null, $type, $suite]; |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | - return []; |
|
| 295 | + return []; |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | /** |
@@ -310,38 +310,38 @@ discard block |
||
| 310 | 310 | * @return string |
| 311 | 311 | */ |
| 312 | 312 | function generer_objet_url_ecrire($id, string $objet, string $args = '', string $ancre = '', ?bool $public = null, string $connect = ''): string { |
| 313 | - static $furls = []; |
|
| 314 | - $id = intval($id); |
|
| 315 | - if (!isset($furls[$objet])) { |
|
| 316 | - if ( |
|
| 317 | - function_exists($f = 'generer_' . $objet . '_url_ecrire') |
|
| 318 | - // ou definie par un plugin |
|
| 319 | - or $f = charger_fonction($f, 'urls', true) |
|
| 320 | - // deprecated |
|
| 321 | - or function_exists($f = 'generer_url_ecrire_' . $objet) or $f = charger_fonction($f, 'urls', true) |
|
| 322 | - ) { |
|
| 323 | - $furls[$objet] = $f; |
|
| 324 | - } else { |
|
| 325 | - $furls[$objet] = ''; |
|
| 326 | - } |
|
| 327 | - } |
|
| 328 | - if ($furls[$objet]) { |
|
| 329 | - return $furls[$objet]($id, $args, $ancre, $public, $connect); |
|
| 330 | - } |
|
| 331 | - // si pas de flag public fourni |
|
| 332 | - // le calculer en fonction de la declaration de statut |
|
| 333 | - if (is_null($public) and !$connect) { |
|
| 334 | - $public = objet_test_si_publie($objet, $id, $connect); |
|
| 335 | - } |
|
| 336 | - if ($public or $connect) { |
|
| 337 | - return generer_objet_url_absolue($id, $objet, $args, $ancre, $public, '', $connect); |
|
| 338 | - } |
|
| 339 | - $a = id_table_objet($objet) . '=' . intval($id); |
|
| 340 | - if (!function_exists('objet_info')) { |
|
| 341 | - include_spip('inc/filtres'); |
|
| 342 | - } |
|
| 313 | + static $furls = []; |
|
| 314 | + $id = intval($id); |
|
| 315 | + if (!isset($furls[$objet])) { |
|
| 316 | + if ( |
|
| 317 | + function_exists($f = 'generer_' . $objet . '_url_ecrire') |
|
| 318 | + // ou definie par un plugin |
|
| 319 | + or $f = charger_fonction($f, 'urls', true) |
|
| 320 | + // deprecated |
|
| 321 | + or function_exists($f = 'generer_url_ecrire_' . $objet) or $f = charger_fonction($f, 'urls', true) |
|
| 322 | + ) { |
|
| 323 | + $furls[$objet] = $f; |
|
| 324 | + } else { |
|
| 325 | + $furls[$objet] = ''; |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | + if ($furls[$objet]) { |
|
| 329 | + return $furls[$objet]($id, $args, $ancre, $public, $connect); |
|
| 330 | + } |
|
| 331 | + // si pas de flag public fourni |
|
| 332 | + // le calculer en fonction de la declaration de statut |
|
| 333 | + if (is_null($public) and !$connect) { |
|
| 334 | + $public = objet_test_si_publie($objet, $id, $connect); |
|
| 335 | + } |
|
| 336 | + if ($public or $connect) { |
|
| 337 | + return generer_objet_url_absolue($id, $objet, $args, $ancre, $public, '', $connect); |
|
| 338 | + } |
|
| 339 | + $a = id_table_objet($objet) . '=' . intval($id); |
|
| 340 | + if (!function_exists('objet_info')) { |
|
| 341 | + include_spip('inc/filtres'); |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | - return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : ''); |
|
| 344 | + return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : ''); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | /** |
@@ -349,5 +349,5 @@ discard block |
||
| 349 | 349 | * @see generer_objet_url_ecrire |
| 350 | 350 | */ |
| 351 | 351 | function generer_url_ecrire_objet($objet, $id, $args = '', $ancre = '', $public = null, string $connect = '') { |
| 352 | - return generer_objet_url_ecrire($id, $objet, $args, $ancre, $public, $connect); |
|
| 352 | + return generer_objet_url_ecrire($id, $objet, $args, $ancre, $public, $connect); |
|
| 353 | 353 | } |