Transformer les liens texte en liens hypertexte - commentaires fonction eregi_replace déprécie en PHP 5 2010-02-19T15:59:08Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment426654 2010-02-19T15:59:08Z <p>Voici une version actualisée de la fonction qui utilise preg_replace à la place de reregi_replace.</p> <p>Par ailleurs, la prise en compte des liens entre parenthèses (<a href="http://exemple.net" class="spip_url spip_out auto" rel="nofollow external">http://exemple.net</a>) a été jouée.</p> <div class="precode"><pre class="spip_code spip_code_block" dir="ltr" style="text-align:left;"><code>function norm_liens($texte, $target='') { $target = '_'.$target; if ( $target != "_" ) { $texte = preg_replace('@ http://([^ <]*)@i', ' <a href="http://$1" target="'.$target.'">http://$1</a>', $texte); $texte = preg_replace('@ ftp://([^ <]*)@i', ' <a href="ftp://$1" target="'.$target.'">ftp://$1</a>', $texte); $texte = preg_replace('@ www.([^ <]*)@i', ' <a href="http://www.$1" target="'.$target.'">www.$1</a>', $texte); $texte = preg_replace('@ ftp.([^ <]*)@i', ' <a href="ftp://ftp.$1" target="'.$target.'">ftp.$1</a>', $texte); $texte = preg_replace('@\(http://([^ <]*)\)@i', ' (<a href="http://$1" target="'.$target.'">http://$1</a>)', $texte); $texte = preg_replace('@\(ftp://([^ <]*)\)@i', ' (<a href="ftp://$1" target="'.$target.'">ftp://$1</a>)', $texte); $texte = preg_replace('@\(www.([^ <]*)\)@i', ' (<a href="http://www.$1" target="'.$target.'">www.$1</a>)', $texte); $texte = preg_replace('@\(ftp.([^ <]*)\)@i', ' (<a href="ftp://ftp.$1" target="'.$target.'">ftp.$1</a>)', $texte); $texte = preg_replace('@^http://([^ <]*)@i', '<a href="http://$1" target="'.$target.'">http://$1</a>', $texte); $texte = preg_replace('@^ftp://([^ <]*)@i', '<a href="ftp://$1" target="'.$target.'">ftp://$1</a>', $texte); $texte = preg_replace('@^www.([^ <]*)@i', '<a href="http://www.$1" target="'.$target.'">www.$1</a>', $texte); $texte = preg_replace('@^ftp.([^ <]*)@i', '<a href="ftp://ftp.$1" target="'.$target.'">ftp.$1</a>', $texte); $texte = preg_replace('@<p class="spip">http://([^ <]*)@i', '<p class="spip"><a href="http://$1" target="'.$target.'">http://$1</a>', $texte); $texte = preg_replace('@<p class="spip">ftp://([^ <]*)@i', '<p class="spip"><a href="ftp://$1" target="'.$target.'">ftp://$1</a>', $texte); $texte = preg_replace('@<p class="spip">www.([^ <]*)@i', '<p class="spip"><a href="http://www.$1" target="'.$target.'">www.$1</a>', $texte); $texte = preg_replace('@<p class="spip">ftp.([^ <]*)@i', '<p class="spip"><a href="ftp://ftp.$1" target="'.$target.'">ftp.$1</a>', $texte); } else { $texte = preg_replace('@ http://([^ <]*)@i', ' <a href="http://$1">http://$1</a>', $texte); $texte = preg_replace('@ ftp://([^ <]*)@i', ' <a href="ftp://$1">ftp://$1</a>', $texte); $texte = preg_replace('@ www.([^ <]*)@i', ' <a href="http://www.$1">www.$1</a>', $texte); $texte = preg_replace('@ ftp.([^ <]*)@i', ' <a href="ftp://ftp.$1">ftp.$1</a>', $texte); $texte = preg_replace('@\(http://([^ <]*)\)@i', ' (<a href="http://$1">http://$1</a>)', $texte); $texte = preg_replace('@\(ftp://([^ <]*)\)@i', ' (<a href="ftp://$1">ftp://$1</a>)', $texte); $texte = preg_replace('@\(www.([^ <]*)\)@i', ' (<a href="http://www.$1">www.$1</a>)', $texte); $texte = preg_replace('@\(ftp.([^ <]*)\)@i', ' (<a href="ftp://ftp.$1">ftp.$1</a>)', $texte); $texte = preg_replace('@^http://([^ <]*)@i', '<a href="http://$1">http://$1</a>', $texte); $texte = preg_replace('@^ftp://([^ <]*)@i', '<a href="ftp://$1">ftp://$1</a>', $texte); $texte = preg_replace('@^www.([^ <]*)@i', '<a href="http://www.$1">www.$1</a>', $texte); $texte = preg_replace('@^ftp.([^ <]*)@i', '<a href="ftp://ftp.$1">ftp.$1</a>', $texte); $texte = preg_replace('@<p class="spip">http://([^ <]*)@i', '<p class="spip"><a href="http://$1">http://$1</a>', $texte); $texte = preg_replace('@<p class="spip">ftp://([^ <]*)@i', '<p class="spip"><a href="ftp://$1">ftp://$1</a>', $texte); $texte = preg_replace('@<p class="spip">www.([^ <]*)@i', '<p class="spip"><a href="http://www.$1">www.$1</a>', $texte); $texte = preg_replace('@<p class="spip">ftp.([^ <]*)@i', '<a href="ftp://ftp.$1">ftp.$1</a>', $texte); } $texte = preg_replace('#([^ >]*)@([^ ,:!?&<]*)#i', ' <a href="mailto:$1@$2">$1@$2</a>', $texte); return $texte; }</code></pre></div> Transformer les liens texte en liens hypertexte 2007-04-19T00:34:53Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment393134 2007-04-19T00:34:53Z <p>Cette idée de transformer les liens texte en liens hypertexte a été concrétisée dans le plugin <a href='https://files.spip.org/archive-Tweak-SPIP' class="spip_in" rel='nofollow'>[archive] Tweak SPIP</a></p> Transformer les liens texte en liens hypertexte 2007-04-19T00:34:12Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment393133 2007-04-19T00:34:12Z <p>Ce code semble un peu lourd. Cette idée de transformer les liens texte en liens hypertexte a été concrétisée dans le plugin <a href='https://files.spip.org/archive-Tweak-SPIP' class="spip_in" rel='nofollow'>[archive] Tweak SPIP</a></p> Transformer les liens texte en liens hypertexte 2006-07-25T12:59:44Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment386689 2006-07-25T12:59:44Z <p>je suis pas en avance mais j'essaie de faire ca sur une version 1.9 et cela ne marche pas</p> <p>j'ai mes liens dans mes articles en version texte mais ils ne se changent pas en html</p> <p>est ce du a fichier mes_fonctions.php3<small class="fine d-inline"> </small>?</p> > Transformer les liens texte en liens hypertexte 2005-09-20T15:37:20Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment383506 2005-09-20T15:37:20Z <p>un problème avec les url contenant des<small class="fine d-inline"> </small>?<br class="autobr"> un espace est généré rendant la fonction inopérante pour spip</p> > Transformer les liens texte en liens hypertexte 2005-08-03T01:43:50Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment382659 2005-08-03T01:43:50Z <p>Oui c'est une très bonne contrib, très utile.</p> > Transformer les liens texte en liens hypertexte 2005-07-04T07:09:11Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment381995 2005-07-04T07:09:11Z <p>Filtre sympatique mais qui ne fonctionne pas correctement lorsque le lien se situe dans une note. cf résultat depuis le lien. A+.</p> > Transformer les liens texte en liens hypertexte 2005-04-04T08:02:18Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment380006 2005-04-04T08:02:18Z <p>pas autant pour moi, <a href="http://www.langue-fr.net/index/A/au_temps-autant.htm" class="spip_out" rel='nofollow external'>aux temps pour moi</a> .. ou à la rigueur <a href="http://www.langue-fr.net/index/A/au_temps-bis.htm" class="spip_out" rel='nofollow external'>aux tempes pour moi</a></p> > Transformer les liens texte en liens hypertexte 2004-03-27T13:52:47Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment7768 2004-03-27T13:52:47Z <p>>quand au site <a href="http://www.bellaciao.org" class="spip_url spip_out auto" rel="nofollow external">http://www.bellaciao.org</a>, il ne faut pas se >méprendre voir au contraire avec plus de renseignements, >ou alors <a href="http://paris.indymedia.org/articles.php3" class="spip_url spip_out auto" rel="nofollow external">http://paris.indymedia.org/articles.php3</a><small class="fine d-inline"> </small>?>id_article=10000.</p> <p>je comprends pas ta phrase...</p> <p>« quand au site <a href="http://www.bellaciao.org" class="spip_url spip_out auto" rel="nofollow external">http://www.bellaciao.org</a>, il ne faut pas se >méprendre voir au contraire »</p> <p> :))</p> <p>Tip</p> > Transformer les liens texte en liens hypertexte 2004-02-23T16:11:35Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment6722 2004-02-23T16:11:35Z <p>Bonjour,</p> <p>je cherche à créer des liens externes à partir de la boucle DOCUMENTS. Le filtre « liens_ouvrants » n'a pas l'air de s'y appliquer. Et « norm_liens » non plus. Comment faire<small class="fine d-inline"> </small>?</p> > Transformer les liens texte en liens hypertexte 2003-12-06T08:47:35Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment4767 2003-12-06T08:47:35Z <p>Quelle idée aussi de mettre des virgules dans les URLs<small class="fine d-inline"> </small>!<small class="fine d-inline"> </small>;-)</p> <p>Nan, sérieusement, je me pencherais sur les problèmes que tu cites lorsque j'aurai un peu de temps de moi...</p> > Transformer les liens texte en liens hypertexte 2003-12-04T16:37:42Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment4740 2003-12-04T16:37:42Z <p>trés bon, voir même excellent, attention point trop n'en faut.</p> <p>dommage que spipcontrib ne l'utilise pas<small class="fine d-inline"> </small>!</p> <p>http:\<a href="http://www.bachant.net" class="spip_url spip_out auto" rel="nofollow external">www.bachant.net</a></p> > Transformer les liens texte en liens hypertexte 2003-11-25T22:12:37Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment4575 2003-11-25T22:12:37Z <p>autre point : les url complexes comme celle du monde avec des virgules donnet des résultats très bizarre. Essayez celle là :</p> <p>http://www.lemonde.fr/web/article/0,1-0@2-3218,36-343395,0.html</p> > Transformer les liens texte en liens hypertexte 2003-11-25T21:33:37Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment4574 2003-11-25T21:33:37Z <p>milles excuses : pour l'exemple, voilà le texte original.<br class="autobr"> les url doivent donc être séparées par des blancs. nb : une url entre parenthèses ne marche pas (pas clickable).<br class="autobr"> la duxième url bellaciao ne marche pas (à cause de la virgule, de même pour la dernière adress indymedia, polluée par le point final de la phrase). Une adresse email marche (c'est chouette).</p> <p> http://www.bellaciao.org <br> http://paris.indymedia.org/articles.php3?id_article=10000 <br> quand au site http://www.bellaciao.org, il ne faut pas se méprendre voir au contraire (http://paris.indymedia.org/articles.php3?id_article=10000) avec plus de renseignements, ou alors http://paris.indymedia.org/articles.php3?id_article=10000. <br> [et voir ça->http://www.bellaciao.org] <br> mon email : jeppe@no-log.org </p> > Transformer les liens texte en liens hypertexte 2003-11-25T21:21:29Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment4572 2003-11-25T21:21:29Z <p>attention, il y a quelques problèmes avec la ponctuation<br class="autobr"> par exemple si l'adresse est suivie d'une virgule ou d'un point, cette virgule se trouve intégrée dans l'URL et provoque donc une erreur.</p> <p>Autre problème : il y a un conflit avec la façon dont spip gère la typographie, ainsi une url avec articles.php<small class="fine d-inline"> </small>?id_article=100 verra un espace s'intercaler avant le<small class="fine d-inline"> </small>?, et là encore l'url ne marche plus.</p> <p>Exemple de test :</p> <p><a href="http://www.bellaciao.org" class="spip_url spip_out auto" rel="nofollow external">http://www.bellaciao.org</a></p> <p><a href="http://paris.indymedia.org/articles.php3?id_article=10000" class="spip_url spip_out auto" rel="nofollow external">http://paris.indymedia.org/articles.php3?id_article=10000</a></p> <p>quand au site <a href="http://www.bellaciao.org" class="spip_url spip_out auto" rel="nofollow external">http://www.bellaciao.org</a>, il ne faut pas se méprendre<br class="autobr"> voir au contraire <span class="ressource spip_out"><<a href="http://paris.indymedia.org/articles.php3?id_article=10000" class="spip_url spip_out" rel='nofollow external'>http://paris.indymedia.org/articles...</a>></span> avec plus de renseignements, ou alors <a href="http://paris.indymedia.org/articles.php3?id_article=10000" class="spip_url spip_out auto" rel="nofollow external">http://paris.indymedia.org/articles.php3?id_article=10000</a>.</p> > Transformer les liens texte en liens hypertexte 2003-11-21T08:07:19Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment4490 2003-11-21T08:07:19Z <p>Autant pour moi, après vérification il s'agit d'une option qui permet de rajouter une ligne lors de la saisie des articles pour ajouter un lien internet un peu comme ce qui existe déjà dans les brèves et les forums.</p> > Transformer les liens texte en liens hypertexte 2003-11-20T11:07:35Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment4472 2003-11-20T11:07:35Z <p>C'est une option que j'ai vu dans la partie administration de SPIP 1.7b3 et qui s'appelle « liens hypertextes ».</p> <p>Je ne sais pas ce que signifie cette option (case à cocher) mais cela ressemble bigrement à cet article.</p> > Transformer les liens texte en liens hypertexte 2003-11-13T22:29:45Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment4352 2003-11-13T22:29:45Z <p>Je n'ai rien vu à ce sujet dans la v1.7. Tu as vu ça où<small class="fine d-inline"> </small>?</p> > Transformer les liens texte en liens hypertexte 2003-11-09T22:38:55Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment4285 2003-11-09T22:38:55Z <p>Je ne sais pas. J'ai téléchargé la beta, j'irai voir...</p> > Compatibilité avec typo normale 2003-11-09T22:37:15Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment4284 2003-11-09T22:37:15Z <p><cite>Et c'est compatible, si dans le reste du texte on y un lien du type :</cite></p> <p>Oui.</p> > Compatibilité avec typo normale 2003-11-09T21:31:50Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment4283 2003-11-09T21:31:50Z <p>Excellent<small class="fine d-inline"> </small>!</p> <p>Et c'est compatible, si dans le reste du texte on y un lien du type :</p> <div class="precode"><pre class="spip_code spip_code_block" dir="ltr" style="text-align:left;"><code>[Lien->www.lien.com]</code></pre></div> <p><small class="fine d-inline"> </small>?</p> <p>Yiannis</p> > Transformer les liens texte en liens hypertexte 2003-11-07T11:05:15Z https://files.spip.org/Transformer-les-liens-texte-en-liens-hypertexte#comment4253 2003-11-07T11:05:15Z <p>Me trompes-je ou c'est cette fonctionnalité qui est intégrée par défaut dans le futur SPIP1.7<small class="fine d-inline"> </small>? (case à cocher dans la config de SPIP)</p>