[SPIP] ~maj 3.0.10 --> 3.0.14
[lhc/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 $html = null;
14 if ($ressource = charger_fonction('ressource', 'inc', true)) {
15 $html = $ressource($r[0]);
16 }
17
18 if (is_null($html)) {
19 include_spip('inc/lien');
20 $url = explode(' ', trim($r[0], '<>'));
21 $url = $url[0];
22 # <http://url/absolue>
23 if (preg_match(',^https?://,i', $url))
24 $html = PtoBR(propre("<span class='ressource spip_out'>&lt;[->".$url."]&gt;</span>"));
25 # <url/relative>
26 else if (false !== strpos($url, '/'))
27 $html = PtoBR(propre("<span class='ressource spip_in'>&lt;[->".$url."]&gt;</span>"));
28 # <fichier.rtf>
29 else {
30 preg_match(',\.([^.]+)$,', $url, $regs);
31 if (file_exists($f = _DIR_IMG.$regs[1].'/'.$url)) {
32 $html = PtoBR(propre("<span class='ressource spip_in'>&lt;[".$url."->".$f."]&gt;</span>"));
33 } else {
34 $html = PtoBR(propre("<span class='ressource'>&lt;".$url."&gt;</span>"));
35 }
36 }
37 }
38
39 return '<html>'.$html.'</html>';
40 }
41
42 ?>