62 lines
1.5 KiB
PHP
62 lines
1.5 KiB
PHP
|
<?php
|
||
|
|
||
|
/*
|
||
|
* transforme un raccourci de ressource en un joli html a embed
|
||
|
*
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
define('_EXTRAIRE_RESSOURCES', ',' . '<"?(https?://|[\w][\w -]*\.[\w -]+).*>' . ',UimsS');
|
||
|
|
||
|
|
||
|
/* pipeline pour typo, evitons une erreur dans les logs */
|
||
|
function tw_post_typo($t){
|
||
|
return $t;
|
||
|
}
|
||
|
|
||
|
/* pipeline pour propre, evitons une erreur dans les logs */
|
||
|
function tw_pre_liens($t){
|
||
|
return $t;
|
||
|
}
|
||
|
|
||
|
function traiter_ressources($r){
|
||
|
if ($ressource = charger_fonction('ressource', 'inc', true)){
|
||
|
$html = $ressource($r[0]);
|
||
|
} else {
|
||
|
$html = htmlspecialchars($r[0]);
|
||
|
}
|
||
|
|
||
|
return $html;
|
||
|
}
|
||
|
|
||
|
function inc_ressource_dist($html){
|
||
|
return tw_traiter_ressources(array(0 => $html));
|
||
|
}
|
||
|
|
||
|
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'><[->" . $url . ']></span>'));
|
||
|
} # <url/relative>
|
||
|
else {
|
||
|
if (false!==strpos($url, '/')){
|
||
|
$html = PtoBR(propre("<span class='ressource spip_in'><[->" . $url . ']></span>'));
|
||
|
} # <fichier.rtf>
|
||
|
else {
|
||
|
if (preg_match(',\.([^.]+)$,', $url, $regs)
|
||
|
and file_exists($f = _DIR_IMG . $regs[1] . '/' . $url)){
|
||
|
$html = PtoBR(propre("<span class='ressource spip_in'><[" . $url . '->' . $f . ']></span>'));
|
||
|
} else {
|
||
|
$html = PtoBR(propre("<span class='ressource'><" . $url . '></span>'));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return '<html>' . $html . '</html>';
|
||
|
}
|