ressource.php 1.1 KB

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