@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('base/abstract_sql'); |
@@ -23,16 +23,16 @@ discard block |
||
| 23 | 23 | // |
| 24 | 24 | |
| 25 | 25 | function inc_lien_dist( |
| 26 | - $lien, |
|
| 27 | - $texte = '', |
|
| 28 | - $class = '', |
|
| 29 | - $title = '', |
|
| 30 | - $hlang = '', |
|
| 31 | - $rel = '', |
|
| 32 | - string $connect = '', |
|
| 33 | - $env = [] |
|
| 26 | + $lien, |
|
| 27 | + $texte = '', |
|
| 28 | + $class = '', |
|
| 29 | + $title = '', |
|
| 30 | + $hlang = '', |
|
| 31 | + $rel = '', |
|
| 32 | + string $connect = '', |
|
| 33 | + $env = [] |
|
| 34 | 34 | ) { |
| 35 | - return $lien; |
|
| 35 | + return $lien; |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // Regexp des raccourcis, aussi utilisee pour la fusion de sauvegarde Spip |
@@ -43,28 +43,28 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | function expanser_liens($t, string $connect = '', $env = []) { |
| 45 | 45 | |
| 46 | - $t = pipeline('pre_liens', $t); |
|
| 46 | + $t = pipeline('pre_liens', $t); |
|
| 47 | 47 | |
| 48 | - // on passe a traiter_modeles la liste des liens reperes pour lui permettre |
|
| 49 | - // de remettre le texte d'origine dans les parametres du modele |
|
| 50 | - $t = traiter_modeles($t, false, false, $connect); |
|
| 48 | + // on passe a traiter_modeles la liste des liens reperes pour lui permettre |
|
| 49 | + // de remettre le texte d'origine dans les parametres du modele |
|
| 50 | + $t = traiter_modeles($t, false, false, $connect); |
|
| 51 | 51 | |
| 52 | - return $t; |
|
| 52 | + return $t; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | // Meme analyse mais pour eliminer les liens |
| 56 | 56 | // et ne laisser que leur titre, a expliciter si ce n'est fait |
| 57 | 57 | function nettoyer_raccourcis_typo($texte, string $connect = '') { |
| 58 | - return $texte; |
|
| 58 | + return $texte; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | // Repere dans la partie texte d'un raccourci [texte->...] |
| 62 | 62 | // la langue et la bulle eventuelles |
| 63 | 63 | function traiter_raccourci_lien_atts($texte) { |
| 64 | - $bulle = ''; |
|
| 65 | - $hlang = ''; |
|
| 64 | + $bulle = ''; |
|
| 65 | + $hlang = ''; |
|
| 66 | 66 | |
| 67 | - return [trim($texte), $bulle, $hlang]; |
|
| 67 | + return [trim($texte), $bulle, $hlang]; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | define('_RACCOURCI_CHAPO', '/^(\W*)(\W*)(\w*\d+([?#].*)?)$/'); |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * @return string |
| 81 | 81 | */ |
| 82 | 82 | function virtuel_redirige($virtuel, $url = false) { |
| 83 | - return $virtuel; |
|
| 83 | + return $virtuel; |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | // Cherche un lien du type [->raccourci 123] |
@@ -93,121 +93,121 @@ discard block |
||
| 93 | 93 | // 'url': seulement U (i.e. generer_url_RACCOURCI) |
| 94 | 94 | |
| 95 | 95 | function calculer_url($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) { |
| 96 | - $r = traiter_lien_implicite($ref, $texte, $pour, $connect); |
|
| 96 | + $r = traiter_lien_implicite($ref, $texte, $pour, $connect); |
|
| 97 | 97 | |
| 98 | - return $r ?: traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo); |
|
| 98 | + return $r ?: traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | define('_EXTRAIRE_LIEN', ',^\s*(?:' . _PROTOCOLES_STD . '):?/?/?\s*$,iS'); |
| 102 | 102 | |
| 103 | 103 | function traiter_lien_explicite($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) { |
| 104 | - if (preg_match(_EXTRAIRE_LIEN, $ref)) { |
|
| 105 | - return ($pour != 'tout') ? '' : ['', '', '', '']; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - $lien = entites_html(trim($ref)); |
|
| 109 | - |
|
| 110 | - // Liens explicites |
|
| 111 | - if (!$texte) { |
|
| 112 | - $texte = str_replace('"', '', $lien); |
|
| 113 | - // evite l'affichage de trops longues urls. |
|
| 114 | - $lien_court = charger_fonction('lien_court', 'inc'); |
|
| 115 | - $texte = $lien_court($texte); |
|
| 116 | - if ($echappe_typo) { |
|
| 117 | - $texte = '<html>' . quote_amp($texte) . '</html>'; |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - // petites corrections d'URL |
|
| 122 | - if (preg_match('/^www\.[^@]+$/S', $lien)) { |
|
| 123 | - $lien = 'http://' . $lien; |
|
| 124 | - } else { |
|
| 125 | - if (strpos($lien, '@') && email_valide($lien)) { |
|
| 126 | - if (!$texte) { |
|
| 127 | - $texte = $lien; |
|
| 128 | - } |
|
| 129 | - $lien = 'mailto:' . $lien; |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - if ($pour == 'url') { |
|
| 134 | - return $lien; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - if ($pour == 'titre') { |
|
| 138 | - return $texte; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - return ['url' => $lien, 'titre' => $texte]; |
|
| 104 | + if (preg_match(_EXTRAIRE_LIEN, $ref)) { |
|
| 105 | + return ($pour != 'tout') ? '' : ['', '', '', '']; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + $lien = entites_html(trim($ref)); |
|
| 109 | + |
|
| 110 | + // Liens explicites |
|
| 111 | + if (!$texte) { |
|
| 112 | + $texte = str_replace('"', '', $lien); |
|
| 113 | + // evite l'affichage de trops longues urls. |
|
| 114 | + $lien_court = charger_fonction('lien_court', 'inc'); |
|
| 115 | + $texte = $lien_court($texte); |
|
| 116 | + if ($echappe_typo) { |
|
| 117 | + $texte = '<html>' . quote_amp($texte) . '</html>'; |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // petites corrections d'URL |
|
| 122 | + if (preg_match('/^www\.[^@]+$/S', $lien)) { |
|
| 123 | + $lien = 'http://' . $lien; |
|
| 124 | + } else { |
|
| 125 | + if (strpos($lien, '@') && email_valide($lien)) { |
|
| 126 | + if (!$texte) { |
|
| 127 | + $texte = $lien; |
|
| 128 | + } |
|
| 129 | + $lien = 'mailto:' . $lien; |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + if ($pour == 'url') { |
|
| 134 | + return $lien; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + if ($pour == 'titre') { |
|
| 138 | + return $texte; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + return ['url' => $lien, 'titre' => $texte]; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | function liens_implicite_glose_dist($texte, $id, $type, $args, $ancre, string $connect = '') { |
| 145 | - if (function_exists($f = 'glossaire_' . $ancre)) { |
|
| 146 | - $url = $f($texte, $id); |
|
| 147 | - } else { |
|
| 148 | - $url = glossaire_std($texte); |
|
| 149 | - } |
|
| 145 | + if (function_exists($f = 'glossaire_' . $ancre)) { |
|
| 146 | + $url = $f($texte, $id); |
|
| 147 | + } else { |
|
| 148 | + $url = glossaire_std($texte); |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - return $url; |
|
| 151 | + return $url; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | function traiter_lien_implicite($ref, $texte = '', $pour = 'url', string $connect = '') { |
| 155 | - $url = null; |
|
| 156 | - if (!($match = typer_raccourci($ref))) { |
|
| 157 | - return false; |
|
| 158 | - } |
|
| 159 | - [$type, , $id, , $args, , $ancre] = array_pad($match, 7, null); |
|
| 160 | - // attention dans le cas des sites le lien doit pointer non pas sur |
|
| 161 | - // la page locale du site, mais directement sur le site lui-meme |
|
| 162 | - if ($f = charger_fonction("implicite_$type", 'liens', true)) { |
|
| 163 | - $url = $f($texte, $id, $type, $args, $ancre, $connect); |
|
| 164 | - } |
|
| 165 | - if (!$url) { |
|
| 166 | - $url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', null, '', $connect); |
|
| 167 | - } |
|
| 168 | - if (!$url) { |
|
| 169 | - return false; |
|
| 170 | - } |
|
| 171 | - if (is_array($url)) { |
|
| 172 | - [$type, $id] = array_pad($url, 2, null); |
|
| 173 | - $url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', null, '', $connect); |
|
| 174 | - } |
|
| 175 | - if ($pour === 'url') { |
|
| 176 | - return $url; |
|
| 177 | - } |
|
| 178 | - $r = traiter_raccourci_titre($id, $type, $connect); |
|
| 179 | - if ($r) { |
|
| 180 | - $r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in'; |
|
| 181 | - } |
|
| 182 | - if ($texte = trim($texte)) { |
|
| 183 | - $r['titre'] = $texte; |
|
| 184 | - } |
|
| 185 | - if (!@$r['titre']) { |
|
| 186 | - $r['titre'] = _T($type) . " $id"; |
|
| 187 | - } |
|
| 188 | - if ($pour == 'titre') { |
|
| 189 | - return $r['titre']; |
|
| 190 | - } |
|
| 191 | - $r['url'] = $url; |
|
| 192 | - |
|
| 193 | - // dans le cas d'un lien vers un doc, ajouter le type='mime/type' |
|
| 194 | - if ( |
|
| 195 | - $type == 'document' |
|
| 196 | - and $mime = sql_getfetsel( |
|
| 197 | - 'mime_type', |
|
| 198 | - 'spip_types_documents', |
|
| 199 | - 'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')', |
|
| 200 | - '', |
|
| 201 | - '', |
|
| 202 | - '', |
|
| 203 | - '', |
|
| 204 | - $connect |
|
| 205 | - ) |
|
| 206 | - ) { |
|
| 207 | - $r['mime'] = $mime; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - return $r; |
|
| 155 | + $url = null; |
|
| 156 | + if (!($match = typer_raccourci($ref))) { |
|
| 157 | + return false; |
|
| 158 | + } |
|
| 159 | + [$type, , $id, , $args, , $ancre] = array_pad($match, 7, null); |
|
| 160 | + // attention dans le cas des sites le lien doit pointer non pas sur |
|
| 161 | + // la page locale du site, mais directement sur le site lui-meme |
|
| 162 | + if ($f = charger_fonction("implicite_$type", 'liens', true)) { |
|
| 163 | + $url = $f($texte, $id, $type, $args, $ancre, $connect); |
|
| 164 | + } |
|
| 165 | + if (!$url) { |
|
| 166 | + $url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', null, '', $connect); |
|
| 167 | + } |
|
| 168 | + if (!$url) { |
|
| 169 | + return false; |
|
| 170 | + } |
|
| 171 | + if (is_array($url)) { |
|
| 172 | + [$type, $id] = array_pad($url, 2, null); |
|
| 173 | + $url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', null, '', $connect); |
|
| 174 | + } |
|
| 175 | + if ($pour === 'url') { |
|
| 176 | + return $url; |
|
| 177 | + } |
|
| 178 | + $r = traiter_raccourci_titre($id, $type, $connect); |
|
| 179 | + if ($r) { |
|
| 180 | + $r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in'; |
|
| 181 | + } |
|
| 182 | + if ($texte = trim($texte)) { |
|
| 183 | + $r['titre'] = $texte; |
|
| 184 | + } |
|
| 185 | + if (!@$r['titre']) { |
|
| 186 | + $r['titre'] = _T($type) . " $id"; |
|
| 187 | + } |
|
| 188 | + if ($pour == 'titre') { |
|
| 189 | + return $r['titre']; |
|
| 190 | + } |
|
| 191 | + $r['url'] = $url; |
|
| 192 | + |
|
| 193 | + // dans le cas d'un lien vers un doc, ajouter le type='mime/type' |
|
| 194 | + if ( |
|
| 195 | + $type == 'document' |
|
| 196 | + and $mime = sql_getfetsel( |
|
| 197 | + 'mime_type', |
|
| 198 | + 'spip_types_documents', |
|
| 199 | + 'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')', |
|
| 200 | + '', |
|
| 201 | + '', |
|
| 202 | + '', |
|
| 203 | + '', |
|
| 204 | + $connect |
|
| 205 | + ) |
|
| 206 | + ) { |
|
| 207 | + $r['mime'] = $mime; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + return $r; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | // analyse des raccourcis issus de [TITRE->RACCOURCInnn] et connexes |
@@ -215,41 +215,41 @@ discard block |
||
| 215 | 215 | define('_RACCOURCI_URL', '/^\s*(\w*?)\s*(\d+)(\?(.*?))?(#([^\s]*))?\s*$/S'); |
| 216 | 216 | |
| 217 | 217 | function typer_raccourci($lien) { |
| 218 | - if (!preg_match(_RACCOURCI_URL, $lien, $match)) { |
|
| 219 | - return []; |
|
| 220 | - } |
|
| 221 | - $f = $match[1]; |
|
| 222 | - // valeur par defaut et alias historiques |
|
| 223 | - if (!$f) { |
|
| 224 | - $f = 'article'; |
|
| 225 | - } else { |
|
| 226 | - if ($f == 'art') { |
|
| 227 | - $f = 'article'; |
|
| 228 | - } else { |
|
| 229 | - if ($f == 'br') { |
|
| 230 | - $f = 'breve'; |
|
| 231 | - } else { |
|
| 232 | - if ($f == 'rub') { |
|
| 233 | - $f = 'rubrique'; |
|
| 234 | - } else { |
|
| 235 | - if ($f == 'aut') { |
|
| 236 | - $f = 'auteur'; |
|
| 237 | - } else { |
|
| 238 | - if ($f == 'doc' or $f == 'im' or $f == 'img' or $f == 'image' or $f == 'emb') { |
|
| 239 | - $f = 'document'; |
|
| 240 | - } else { |
|
| 241 | - if (preg_match('/^br..?ve$/S', $f)) { |
|
| 242 | - $f = 'breve'; |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - } # accents :( |
|
| 250 | - $match[0] = $f; |
|
| 251 | - |
|
| 252 | - return $match; |
|
| 218 | + if (!preg_match(_RACCOURCI_URL, $lien, $match)) { |
|
| 219 | + return []; |
|
| 220 | + } |
|
| 221 | + $f = $match[1]; |
|
| 222 | + // valeur par defaut et alias historiques |
|
| 223 | + if (!$f) { |
|
| 224 | + $f = 'article'; |
|
| 225 | + } else { |
|
| 226 | + if ($f == 'art') { |
|
| 227 | + $f = 'article'; |
|
| 228 | + } else { |
|
| 229 | + if ($f == 'br') { |
|
| 230 | + $f = 'breve'; |
|
| 231 | + } else { |
|
| 232 | + if ($f == 'rub') { |
|
| 233 | + $f = 'rubrique'; |
|
| 234 | + } else { |
|
| 235 | + if ($f == 'aut') { |
|
| 236 | + $f = 'auteur'; |
|
| 237 | + } else { |
|
| 238 | + if ($f == 'doc' or $f == 'im' or $f == 'img' or $f == 'image' or $f == 'emb') { |
|
| 239 | + $f = 'document'; |
|
| 240 | + } else { |
|
| 241 | + if (preg_match('/^br..?ve$/S', $f)) { |
|
| 242 | + $f = 'breve'; |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + } # accents :( |
|
| 250 | + $match[0] = $f; |
|
| 251 | + |
|
| 252 | + return $match; |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -264,25 +264,25 @@ discard block |
||
| 264 | 264 | * } |
| 265 | 265 | **/ |
| 266 | 266 | function traiter_raccourci_titre($id, $type, $connect = null) { |
| 267 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 268 | - $desc = $trouver_table(table_objet($type)); |
|
| 269 | - if (!($desc and $s = $desc['titre'])) { |
|
| 270 | - return []; |
|
| 271 | - } |
|
| 272 | - $_id = $desc['key']['PRIMARY KEY']; |
|
| 273 | - $r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect); |
|
| 274 | - if (!$r) { |
|
| 275 | - return []; |
|
| 276 | - } |
|
| 277 | - $r['titre'] = supprimer_numero($r['titre']); |
|
| 278 | - if (!$r['titre'] and !empty($r['surnom'])) { |
|
| 279 | - $r['titre'] = $r['surnom']; |
|
| 280 | - } |
|
| 281 | - if (!isset($r['lang'])) { |
|
| 282 | - $r['lang'] = ''; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - return $r; |
|
| 267 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 268 | + $desc = $trouver_table(table_objet($type)); |
|
| 269 | + if (!($desc and $s = $desc['titre'])) { |
|
| 270 | + return []; |
|
| 271 | + } |
|
| 272 | + $_id = $desc['key']['PRIMARY KEY']; |
|
| 273 | + $r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect); |
|
| 274 | + if (!$r) { |
|
| 275 | + return []; |
|
| 276 | + } |
|
| 277 | + $r['titre'] = supprimer_numero($r['titre']); |
|
| 278 | + if (!$r['titre'] and !empty($r['surnom'])) { |
|
| 279 | + $r['titre'] = $r['surnom']; |
|
| 280 | + } |
|
| 281 | + if (!isset($r['lang'])) { |
|
| 282 | + $r['lang'] = ''; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + return $r; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // traite les modeles (dans la fonction typo), en remplacant |
@@ -293,136 +293,136 @@ discard block |
||
| 293 | 293 | // mais on renvoie les params (pour l'indexation par le moteur de recherche) |
| 294 | 294 | |
| 295 | 295 | define( |
| 296 | - '_RACCOURCI_MODELE', |
|
| 297 | - '(<([a-z_-]{3,})' # <modele |
|
| 298 | - . '\s*([0-9]*)\s*' # id |
|
| 299 | - . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>) |
|
| 300 | - . '\s*/?' . '>)' # fin du modele > |
|
| 301 | - . '\s*(<\/a>)?' # eventuel </a> |
|
| 296 | + '_RACCOURCI_MODELE', |
|
| 297 | + '(<([a-z_-]{3,})' # <modele |
|
| 298 | + . '\s*([0-9]*)\s*' # id |
|
| 299 | + . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>) |
|
| 300 | + . '\s*/?' . '>)' # fin du modele > |
|
| 301 | + . '\s*(<\/a>)?' # eventuel </a> |
|
| 302 | 302 | ); |
| 303 | 303 | |
| 304 | 304 | define('_RACCOURCI_MODELE_DEBUT', '@^' . _RACCOURCI_MODELE . '@isS'); |
| 305 | 305 | |
| 306 | 306 | function traiter_modeles($texte, $doublons = false, $echap = '', string $connect = '', $liens = null, $env = []) { |
| 307 | - // preserver la compatibilite : true = recherche des documents |
|
| 308 | - if ($doublons === true) { |
|
| 309 | - $doublons = ['documents' => ['doc', 'emb', 'img']]; |
|
| 310 | - } |
|
| 311 | - // detecter les modeles (rapide) |
|
| 312 | - if ( |
|
| 313 | - strpos($texte, '<') !== false and |
|
| 314 | - preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER) |
|
| 315 | - ) { |
|
| 316 | - include_spip('public/assembler'); |
|
| 317 | - $wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true); |
|
| 318 | - foreach ($matches as $match) { |
|
| 319 | - // Recuperer l'appel complet (y compris un eventuel lien) |
|
| 320 | - |
|
| 321 | - $a = strpos($texte, (string) $match[0]); |
|
| 322 | - preg_match( |
|
| 323 | - _RACCOURCI_MODELE_DEBUT, |
|
| 324 | - substr($texte, $a), |
|
| 325 | - $regs |
|
| 326 | - ); |
|
| 327 | - $regs[] = ''; // s'assurer qu'il y a toujours un 5e arg, eventuellement vide |
|
| 328 | - [, $mod, $type, $id, $params, $fin] = $regs; |
|
| 329 | - if ( |
|
| 330 | - $fin and |
|
| 331 | - preg_match( |
|
| 332 | - '/<a\s[^<>]*>\s*$/i', |
|
| 333 | - substr($texte, 0, $a), |
|
| 334 | - $r |
|
| 335 | - ) |
|
| 336 | - ) { |
|
| 337 | - $lien = [ |
|
| 338 | - 'href' => extraire_attribut($r[0], 'href'), |
|
| 339 | - 'class' => extraire_attribut($r[0], 'class'), |
|
| 340 | - 'mime' => extraire_attribut($r[0], 'type'), |
|
| 341 | - 'title' => extraire_attribut($r[0], 'title'), |
|
| 342 | - 'hreflang' => extraire_attribut($r[0], 'hreflang') |
|
| 343 | - ]; |
|
| 344 | - $n = strlen($r[0]); |
|
| 345 | - $a -= $n; |
|
| 346 | - $cherche = $n + strlen($regs[0]); |
|
| 347 | - } else { |
|
| 348 | - $lien = false; |
|
| 349 | - $cherche = strlen($mod); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - // calculer le modele |
|
| 353 | - # hack indexation |
|
| 354 | - if ($doublons) { |
|
| 355 | - $texte .= preg_replace(',[|][^|=]*,s', ' ', $params); |
|
| 356 | - } # version normale |
|
| 357 | - else { |
|
| 358 | - // si un tableau de liens a ete passe, reinjecter le contenu d'origine |
|
| 359 | - // dans les parametres, plutot que les liens echappes |
|
| 360 | - if (!is_null($liens)) { |
|
| 361 | - $params = str_replace($liens[0], $liens[1], $params); |
|
| 362 | - } |
|
| 363 | - $modele = inclure_modele($type, $id, $params, $lien, $connect, $env); |
|
| 364 | - // en cas d'echec, |
|
| 365 | - // si l'objet demande a une url, |
|
| 366 | - // creer un petit encadre vers elle |
|
| 367 | - if ($modele === false) { |
|
| 368 | - if (!$lien) { |
|
| 369 | - $lien = traiter_lien_implicite("$type$id", '', 'tout', $connect); |
|
| 370 | - } |
|
| 371 | - if ($lien) { |
|
| 372 | - $modele = '<a href="' |
|
| 373 | - . $lien['url'] |
|
| 374 | - . '" class="spip_modele' |
|
| 375 | - . '">' |
|
| 376 | - . sinon($lien['titre'], _T('ecrire:info_sans_titre')) |
|
| 377 | - . '</a>'; |
|
| 378 | - } else { |
|
| 379 | - $modele = ''; |
|
| 380 | - if (test_espace_prive()) { |
|
| 381 | - $modele = entites_html(substr($texte, $a, $cherche)); |
|
| 382 | - if (!is_null($liens)) { |
|
| 383 | - $modele = '<pre>' . str_replace($liens[0], $liens[1], $modele) . '</pre>'; |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - } |
|
| 388 | - // le remplacer dans le texte |
|
| 389 | - if ($modele !== false) { |
|
| 390 | - $modele = protege_js_modeles($modele); |
|
| 391 | - if ($wrap_embed_html) { |
|
| 392 | - $modele = $wrap_embed_html($mod, $modele); |
|
| 393 | - } |
|
| 394 | - $rempl = code_echappement($modele, $echap); |
|
| 395 | - $texte = substr($texte, 0, $a) |
|
| 396 | - . $rempl |
|
| 397 | - . substr($texte, $a + $cherche); |
|
| 398 | - } |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - // hack pour tout l'espace prive |
|
| 402 | - if (((!_DIR_RESTREINT) or ($doublons)) and ($id)) { |
|
| 403 | - foreach ($doublons ?: ['documents' => ['doc', 'emb', 'img']] as $quoi => $modeles) { |
|
| 404 | - if (in_array($type, $modeles)) { |
|
| 405 | - $GLOBALS["doublons_{$quoi}_inclus"][] = $id; |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - return $texte; |
|
| 307 | + // preserver la compatibilite : true = recherche des documents |
|
| 308 | + if ($doublons === true) { |
|
| 309 | + $doublons = ['documents' => ['doc', 'emb', 'img']]; |
|
| 310 | + } |
|
| 311 | + // detecter les modeles (rapide) |
|
| 312 | + if ( |
|
| 313 | + strpos($texte, '<') !== false and |
|
| 314 | + preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER) |
|
| 315 | + ) { |
|
| 316 | + include_spip('public/assembler'); |
|
| 317 | + $wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true); |
|
| 318 | + foreach ($matches as $match) { |
|
| 319 | + // Recuperer l'appel complet (y compris un eventuel lien) |
|
| 320 | + |
|
| 321 | + $a = strpos($texte, (string) $match[0]); |
|
| 322 | + preg_match( |
|
| 323 | + _RACCOURCI_MODELE_DEBUT, |
|
| 324 | + substr($texte, $a), |
|
| 325 | + $regs |
|
| 326 | + ); |
|
| 327 | + $regs[] = ''; // s'assurer qu'il y a toujours un 5e arg, eventuellement vide |
|
| 328 | + [, $mod, $type, $id, $params, $fin] = $regs; |
|
| 329 | + if ( |
|
| 330 | + $fin and |
|
| 331 | + preg_match( |
|
| 332 | + '/<a\s[^<>]*>\s*$/i', |
|
| 333 | + substr($texte, 0, $a), |
|
| 334 | + $r |
|
| 335 | + ) |
|
| 336 | + ) { |
|
| 337 | + $lien = [ |
|
| 338 | + 'href' => extraire_attribut($r[0], 'href'), |
|
| 339 | + 'class' => extraire_attribut($r[0], 'class'), |
|
| 340 | + 'mime' => extraire_attribut($r[0], 'type'), |
|
| 341 | + 'title' => extraire_attribut($r[0], 'title'), |
|
| 342 | + 'hreflang' => extraire_attribut($r[0], 'hreflang') |
|
| 343 | + ]; |
|
| 344 | + $n = strlen($r[0]); |
|
| 345 | + $a -= $n; |
|
| 346 | + $cherche = $n + strlen($regs[0]); |
|
| 347 | + } else { |
|
| 348 | + $lien = false; |
|
| 349 | + $cherche = strlen($mod); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + // calculer le modele |
|
| 353 | + # hack indexation |
|
| 354 | + if ($doublons) { |
|
| 355 | + $texte .= preg_replace(',[|][^|=]*,s', ' ', $params); |
|
| 356 | + } # version normale |
|
| 357 | + else { |
|
| 358 | + // si un tableau de liens a ete passe, reinjecter le contenu d'origine |
|
| 359 | + // dans les parametres, plutot que les liens echappes |
|
| 360 | + if (!is_null($liens)) { |
|
| 361 | + $params = str_replace($liens[0], $liens[1], $params); |
|
| 362 | + } |
|
| 363 | + $modele = inclure_modele($type, $id, $params, $lien, $connect, $env); |
|
| 364 | + // en cas d'echec, |
|
| 365 | + // si l'objet demande a une url, |
|
| 366 | + // creer un petit encadre vers elle |
|
| 367 | + if ($modele === false) { |
|
| 368 | + if (!$lien) { |
|
| 369 | + $lien = traiter_lien_implicite("$type$id", '', 'tout', $connect); |
|
| 370 | + } |
|
| 371 | + if ($lien) { |
|
| 372 | + $modele = '<a href="' |
|
| 373 | + . $lien['url'] |
|
| 374 | + . '" class="spip_modele' |
|
| 375 | + . '">' |
|
| 376 | + . sinon($lien['titre'], _T('ecrire:info_sans_titre')) |
|
| 377 | + . '</a>'; |
|
| 378 | + } else { |
|
| 379 | + $modele = ''; |
|
| 380 | + if (test_espace_prive()) { |
|
| 381 | + $modele = entites_html(substr($texte, $a, $cherche)); |
|
| 382 | + if (!is_null($liens)) { |
|
| 383 | + $modele = '<pre>' . str_replace($liens[0], $liens[1], $modele) . '</pre>'; |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | + // le remplacer dans le texte |
|
| 389 | + if ($modele !== false) { |
|
| 390 | + $modele = protege_js_modeles($modele); |
|
| 391 | + if ($wrap_embed_html) { |
|
| 392 | + $modele = $wrap_embed_html($mod, $modele); |
|
| 393 | + } |
|
| 394 | + $rempl = code_echappement($modele, $echap); |
|
| 395 | + $texte = substr($texte, 0, $a) |
|
| 396 | + . $rempl |
|
| 397 | + . substr($texte, $a + $cherche); |
|
| 398 | + } |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + // hack pour tout l'espace prive |
|
| 402 | + if (((!_DIR_RESTREINT) or ($doublons)) and ($id)) { |
|
| 403 | + foreach ($doublons ?: ['documents' => ['doc', 'emb', 'img']] as $quoi => $modeles) { |
|
| 404 | + if (in_array($type, $modeles)) { |
|
| 405 | + $GLOBALS["doublons_{$quoi}_inclus"][] = $id; |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + return $texte; |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | // |
| 416 | 416 | // Raccourcis ancre [#ancre<-] |
| 417 | 417 | // |
| 418 | 418 | function traiter_raccourci_ancre($letexte) { |
| 419 | - return $letexte; |
|
| 419 | + return $letexte; |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | function traiter_raccourci_glossaire($texte) { |
| 423 | - return $texte; |
|
| 423 | + return $texte; |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | function glossaire_std($terme) { |
| 427 | - return $terme; |
|
| 427 | + return $terme; |
|
| 428 | 428 | } |