28bffa76d4e54fb623dd10da2a6c00b102d5c142
[ptitvelo/web/www.git] / www / plugins-dist / textwheel / inc / ressource.php
1 <?php
2
3 /*
4 * transforme un raccourci de ressource en un lien minimaliste
5 *
6 *
7 */
8
9 define('_EXTRAIRE_RESSOURCES', ',' . '<"?(https?://|[^\s][\w -]+\.[\w -]+)[^<]*>'.',UimsS');
10
11
12 function traiter_ressources($r) {
13 if ($ressource = charger_fonction('ressource', 'inc', true)) {
14 $html = $ressource($r[0]);
15 } else {
16 include_spip('inc/lien');
17 $url = explode(' ', trim($r[0], '<>'));
18 $url = $url[0];
19 # <http://url/absolue>
20 if (preg_match(',^https?://,i', $url))
21 $html = propre("<span class='ressource spip_out'>&lt;[->".$url."]&gt;</span>");
22 # <url/relative>
23 else if (false !== strpos($url, '/'))
24 $html = propre("<span class='ressource spip_in'>&lt;[->".$url."]&gt;</span>");
25 # <fichier.rtf>
26 else {
27 preg_match(',\.([^.]+)$,', $url, $regs);
28 if (file_exists($f = _DIR_IMG.$regs[1].'/'.$url)) {
29 $html = propre("<span class='ressource spip_in'>&lt;[".$url."->".$f."]&gt;</span>");
30 } else {
31 $html = propre("<span class='ressource'>&lt;".$url."&gt;</span>");
32 }
33 }
34 }
35
36 return '<html>'.$html.'</html>';
37 }
38
39 ?>