[SPIP][PLUGINS] v3.0-->v3.2
[lhc/web/www.git] / www / plugins-dist / textwheel / inc / ressource.php
index d56dc5f..aa6b429 100644 (file)
@@ -6,37 +6,58 @@
  *
  */
 
-define('_EXTRAIRE_RESSOURCES', ',' . '<"?(https?://|[^\s][\w -]+\.[\w -]+)[^<]*>'.',UimsS');
+define('_EXTRAIRE_RESSOURCES', ',' . '<"?(https?://|[^\s][\w -]+\.[\w -]+)[^<]*>' . ',UimsS');
 
 
-function traiter_ressources($r) {
-       $html = null;
-       if ($ressource = charger_fonction('ressource', 'inc', true)) {
-               $html = $ressource($r[0]);
+/* pipeline pour typo */
+function tw_post_typo($t) {
+       if (strpos($t, '<') !== false) {
+               $t = preg_replace_callback(_EXTRAIRE_RESSOURCES, 'tw_traiter_ressources', $t);
+       }
+
+       return $t;
+}
+
+/* pipeline pour propre */
+function tw_pre_liens($t) {
+       if (strpos($t, '<') !== false) {
+               $t = preg_replace_callback(_EXTRAIRE_RESSOURCES, 'tw_traiter_ressources', $t);
+
+               // echapper les autoliens eventuellement inseres (en une seule fois)
+               if (strpos($t, "<html>") !== false) {
+                       $t = echappe_html($t);
+               }
        }
 
-       if (is_null($html)) {
-               include_spip('inc/lien');
-               $url = explode(' ', trim($r[0], '<>'));
-               $url = $url[0];
-               # <http://url/absolue>
-               if (preg_match(',^https?://,i', $url))
-                       $html = PtoBR(propre("<span class='ressource spip_out'>&lt;[->".$url."]&gt;</span>"));
-               # <url/relative>
-               else if (false !== strpos($url, '/'))
-                       $html = PtoBR(propre("<span class='ressource spip_in'>&lt;[->".$url."]&gt;</span>"));
-               # <fichier.rtf>
+       return $t;
+}
+
+function tw_traiter_ressources($r) {
+       $html = null;
+
+       include_spip('inc/lien');
+       $url = explode(' ', trim($r[0], '<>'));
+       $url = $url[0];
+       # <http://url/absolue>
+       if (preg_match(',^https?://,i', $url)) {
+               $html = PtoBR(propre("<span class='ressource spip_out'>&lt;[->" . $url . "]&gt;</span>"));
+       } # <url/relative>
+       else {
+               if (false !== strpos($url, '/')) {
+                       $html = PtoBR(propre("<span class='ressource spip_in'>&lt;[->" . $url . "]&gt;</span>"));
+               } # <fichier.rtf>
                else {
-                       preg_match(',\.([^.]+)$,', $url, $regs);
-                       if (file_exists($f = _DIR_IMG.$regs[1].'/'.$url)) {
-                               $html = PtoBR(propre("<span class='ressource spip_in'>&lt;[".$url."->".$f."]&gt;</span>"));
+
+                       if (
+                               preg_match(',\.([^.]+)$,', $url, $regs)
+                               and file_exists($f = _DIR_IMG . $regs[1] . '/' . $url)
+                       ) {
+                               $html = PtoBR(propre("<span class='ressource spip_in'>&lt;[" . $url . "->" . $f . "]&gt;</span>"));
                        } else {
-                               $html = PtoBR(propre("<span class='ressource'>&lt;".$url."&gt;</span>"));
+                               $html = PtoBR(propre("<span class='ressource'>&lt;" . $url . "&gt;</span>"));
                        }
                }
        }
 
-       return '<html>'.$html.'</html>';
+       return '<html>' . $html . '</html>';
 }
-
-?>