From cc6840235b7b6f9abb97ff935cc44ea0e13c4ac7 Mon Sep 17 00:00:00 2001 From: Fil <fil@rezo.net> Date: Fri, 27 Sep 2002 20:15:49 +0000 Subject: [PATCH] =?UTF-8?q?fin=20de=20la=20redirection=20:=20dans=20l'uRL?= =?UTF-8?q?=20de=20redirection=20on=20peut=20donc=20mettre,=20au=20choix,?= =?UTF-8?q?=20http://url=5Fsuper=5Flongue............=20et=20ce=20sera=20c?= =?UTF-8?q?oup=C3=A9=20=C3=A0=20l'affichage,=20=C3=A0=2035=20caract=C3=A8r?= =?UTF-8?q?es=20;=20mot2,=20article7=20(pour=20qu'un=20article=20virtuel?= =?UTF-8?q?=20corresponde=20=C3=A0=20une=20rubrique,=20par=20exemple,=20ce?= =?UTF-8?q?=20qui=20peut=20=C3=AAtre=20utile=20quand=20on=20veut=20=C3=A0?= =?UTF-8?q?=20toute=20foirce=20et=20de=20mani=C3=A8re=20exceptionnelle=20f?= =?UTF-8?q?aire=20entrer=20une=20rubrique=20ou=20un=20autre=20objet=20dans?= =?UTF-8?q?=20un=20classement=20"par=20date"=20d'articles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enfin, on ne va pas trop faire la pub de cette "nouveauté", mais au moins comme ça les choses sont cohérentes (sauf bug de ma part ;) --- ecrire/inc_texte.php3 | 178 ++++++++++++++++++++++------------------- inc-public-global.php3 | 7 +- 2 files changed, 103 insertions(+), 82 deletions(-) diff --git a/ecrire/inc_texte.php3 b/ecrire/inc_texte.php3 index 8561d2c2c7..a5f597e096 100644 --- a/ecrire/inc_texte.php3 +++ b/ecrire/inc_texte.php3 @@ -323,6 +323,101 @@ function typo($letexte) { } +// cette fonction est tordue : on lui passe un tableau correspondant au match +// de la regexp ci-dessous, et elle retourne le texte a inserer a la place +// et le lien "brut" a usage eventuel de redirection... +function extraire_lien ($regs) { + if (file_exists('inc-urls.php3')) { + include_local('inc-urls.php3'); + } elseif (file_exists('inc-urls-dist.php3')) { + include_local('inc-urls-dist.php3'); + } else { + include_ecrire('inc_urls.php3'); + } + + $lien_texte = $regs[1]; + $ouvrant = ($regs[2] == '>'); + $lien_url = trim($regs[3]); + $compt_liens++; + $lien_interne = false; + if (ereg('^(art(icle)?|rub(rique)?|br(.ve)?|aut(eur)?|mot|site)? *([[:digit:]]+)$', $lien_url, $match)) { + // Traitement des liens internes + $id_lien = $match[6]; + $type_lien = $match[1]; + $lien_interne=true; + $class_lien = "in"; + switch (substr($type_lien, 0, 2)) { + case 'ru': + $lien_url = generer_url_rubrique($id_lien); + if (!$lien_texte) { + $req = "select titre from spip_rubriques where id_rubrique=$id_lien"; + $row = @mysql_fetch_array(@spip_query($req)); + $lien_texte = $row['titre']; + } + break; + case 'br': + $lien_url = generer_url_breve($id_lien); + if (!$lien_texte) { + $req = "select titre from spip_breves where id_breve=$id_lien"; + $row = @mysql_fetch_array(@spip_query($req)); + $lien_texte = $row['titre']; + } + break; + case 'au': + $lien_url = generer_url_auteur($id_lien); + if (!$lien_texte) { + $req = "select nom from spip_auteurs where id_auteur = $id_lien"; + $row = @mysql_fetch_array(@spip_query($req)); + $lien_texte = $row['nom']; + } + break; + case 'mo': + $lien_url = generer_url_mot($id_lien); + if (!$lien_texte) { + $req = "select titre from spip_mots where id_mot=$id_lien"; + $row = @mysql_fetch_array(@spip_query($req)); + $lien_texte = $row['titre']; + } + break; + case 'si': + $row = @mysql_fetch_array(@spip_query("SELECT nom_site,url_site FROM spip_syndic WHERE id_syndic=$id_lien")); + if ($row) { + $lien_url = $row['url_site']; + if (!$lien_texte) + $lien_texte = typo($row['nom_site']); + } + break; + default: + $lien_url = generer_url_article($id_lien); + if (!$lien_texte) { + $req = "select titre from spip_articles where id_article=$id_lien"; + $row = @mysql_fetch_array(@spip_query($req)); + $lien_texte = $row['titre']; + } + break; + } + } else { // lien non automatique + $class_lien = "out"; + // texte vide ? + if ((!$lien_texte) and (!$lien_interne)) { + $lien_texte = ereg_replace('"', '', $lien_url); + if (strlen($lien_texte)>40) + $lien_texte = substr($lien_texte,0,35).'...'; + $class_lien = "url"; + } + // petites corrections d'URL + if (ereg("^www\.[^@]+$",$lien_url)) + $lien_url = "http://".$lien_url; + else if (email_valide($lien_url)) + $lien_url = "mailto:".trim($lien_url); + } + + $insert = "<a href=\"$lien_url\" class=\"spip_$class_lien\"" + .($ouvrant ? " target='_blank'" : '') + .">".typo($lien_texte)."</a>"; + + return array($insert, $lien_url); +} // // Traitement des listes (merci a Michael Parienti) @@ -468,92 +563,13 @@ function traiter_raccourcis($letexte, $les_echap = false, $traiter_les_notes = ' } // - // Raccourcis liens + // Raccourcis liens (cf. fonction extraire_lien ci-dessus) // $regexp = "\[([^][]*)->(>?)([^]]*)\]"; $texte_a_voir = $letexte; $texte_vu = ''; while (ereg($regexp, $texte_a_voir, $regs)){ - $lien_texte = $regs[1]; - $ouvrant = ($regs[2] == '>'); - $lien_url = trim($regs[3]); - $compt_liens++; - $lien_interne = false; - if (ereg('^(art(icle)?|rub(rique)?|br(.ve)?|aut(eur)?|mot|site)? *([[:digit:]]+)$', $lien_url, $match)) { - // Traitement des liens internes - $id_lien = $match[6]; - $type_lien = $match[1]; - $lien_interne=true; - $class_lien = "in"; - switch (substr($type_lien, 0, 2)) { - case 'ru': - $lien_url = generer_url_rubrique($id_lien); - if (!$lien_texte) { - $req = "select titre from spip_rubriques where id_rubrique=$id_lien"; - $row = @mysql_fetch_array(@spip_query($req)); - $lien_texte = $row['titre']; - } - break; - case 'br': - $lien_url = generer_url_breve($id_lien); - if (!$lien_texte) { - $req = "select titre from spip_breves where id_breve=$id_lien"; - $row = @mysql_fetch_array(@spip_query($req)); - $lien_texte = $row['titre']; - } - break; - case 'au': - $lien_url = generer_url_auteur($id_lien); - if (!$lien_texte) { - $req = "select nom from spip_auteurs where id_auteur = $id_lien"; - $row = @mysql_fetch_array(@spip_query($req)); - $lien_texte = $row['nom']; - } - break; - case 'mo': - $lien_url = generer_url_mot($id_lien); - if (!$lien_texte) { - $req = "select titre from spip_mots where id_mot=$id_lien"; - $row = @mysql_fetch_array(@spip_query($req)); - $lien_texte = $row['titre']; - } - break; - case 'si': - $row = @mysql_fetch_array(@spip_query("SELECT nom_site,url_site FROM spip_syndic WHERE id_syndic=$id_lien")); - if ($row) { - $lien_url = $row['url_site']; - if (!$lien_texte) - $lien_texte = typo($row['nom_site']); - } - break; - default: - $lien_url = generer_url_article($id_lien); - if (!$lien_texte) { - $req = "select titre from spip_articles where id_article=$id_lien"; - $row = @mysql_fetch_array(@spip_query($req)); - $lien_texte = $row['titre']; - } - break; - } - } else { // lien non automatique - $class_lien = "out"; - // texte vide ? - if ((!$lien_texte) and (!$lien_interne)) { - $lien_texte = ereg_replace('"', '', $lien_url); - if (strlen($lien_texte)>40) - $lien_texte = substr($lien_texte,0,35).'...'; - $class_lien = "url"; - } - // petites corrections d'URL - if (ereg("^www\.[^@]+$",$lien_url)) - $lien_url = "http://".$lien_url; - else if (email_valide($lien_url)) - $lien_url = "mailto:".trim($lien_url); - } - - $insert = "<a href=\"$lien_url\" class=\"spip_$class_lien\"" - .($ouvrant ? " target='_blank'" : '') - .">".typo($lien_texte)."</a>"; + list($insert, $lien) = extraire_lien($regs); $zetexte = split($regexp,$texte_a_voir,2); // typo en-dehors des notes diff --git a/inc-public-global.php3 b/inc-public-global.php3 index 67fdb62239..aaf1e48a82 100644 --- a/inc-public-global.php3 +++ b/inc-public-global.php3 @@ -104,6 +104,7 @@ if (!$use_cache) { $calculer_cache = true; + // redirection d'article via le chapo =http... if ($id_article) { $query = "SELECT chapo FROM spip_articles WHERE id_article='$id_article'"; $result = spip_query($query); @@ -111,7 +112,11 @@ if (!$use_cache) { $chapo = $row['chapo']; } if (substr($chapo, 0, 1) == '=') { - $url = substr($chapo, 1); + include_ecrire('inc_texte.php3'); + + $regs = array('','','',substr($chapo, 1)); + list(,$url) = extraire_lien($regs); + $texte = "<"."?php @header (\"Location: $url\"); ?".">"; $calculer_cache = false; if ($GLOBALS['flag_apc']) { -- GitLab