[SPIP][PLUGINS] v3.0-->v3.2
[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 /* pipeline pour typo */
13 function tw_post_typo($t) {
14 if (strpos($t, '<') !== false) {
15 $t = preg_replace_callback(_EXTRAIRE_RESSOURCES, 'tw_traiter_ressources', $t);
16 }
17
18 return $t;
19 }
20
21 /* pipeline pour propre */
22 function tw_pre_liens($t) {
23 if (strpos($t, '<') !== false) {
24 $t = preg_replace_callback(_EXTRAIRE_RESSOURCES, 'tw_traiter_ressources', $t);
25
26 // echapper les autoliens eventuellement inseres (en une seule fois)
27 if (strpos($t, "<html>") !== false) {
28 $t = echappe_html($t);
29 }
30 }
31
32 return $t;
33 }
34
35 function tw_traiter_ressources($r) {
36 $html = null;
37
38 include_spip('inc/lien');
39 $url = explode(' ', trim($r[0], '<>'));
40 $url = $url[0];
41 # <http://url/absolue>
42 if (preg_match(',^https?://,i', $url)) {
43 $html = PtoBR(propre("<span class='ressource spip_out'>&lt;[->" . $url . "]&gt;</span>"));
44 } # <url/relative>
45 else {
46 if (false !== strpos($url, '/')) {
47 $html = PtoBR(propre("<span class='ressource spip_in'>&lt;[->" . $url . "]&gt;</span>"));
48 } # <fichier.rtf>
49 else {
50
51 if (
52 preg_match(',\.([^.]+)$,', $url, $regs)
53 and file_exists($f = _DIR_IMG . $regs[1] . '/' . $url)
54 ) {
55 $html = PtoBR(propre("<span class='ressource spip_in'>&lt;[" . $url . "->" . $f . "]&gt;</span>"));
56 } else {
57 $html = PtoBR(propre("<span class='ressource'>&lt;" . $url . "&gt;</span>"));
58 }
59 }
60 }
61
62 return '<html>' . $html . '</html>';
63 }