[pmwiki-users] media links css

adam overton a at plus1plus1plus.org
Fri Jan 29 19:18:37 CST 2010


hans had worked out the following function so that URLs ending  
in .pdf, mp3, etc, would automatically receive
	<a class='medialink pdf' ...
so that links to such media could be styled.

here's what that looked like:

    $MediaExtPat = "mp3|ogg|aif|wav|mov|avi|mp4|m3u|doc|rtf|ods|txt| 
    $LinkFunctions['http:'] = 'MediaLinkIMap';
    function MediaLinkIMap($pagename,$imap,$path,$title,$txt, 
$fmt=NULL) {
      global $UrlLinkTxtFmt,$MediaExtPat;
      if (!$fmt)
          $fmt = (preg_match("/($MediaExtPat)$/", $path, $m)) ?
          "<a class='medialink {$m[1]}' href='\$LinkUrl'  
          : $UrlLinkTxtFmt;
      return LinkIMap($pagename,$imap,$path,$title,$txt,$fmt);

the problem i ran into is that it worked for full URLs, but not for  
uploaded files displayed via 'Attach:'.
i thought that combining the MediaLinkIMap function with the  
LinkUpload function (from upload.php) would solve this problem (see  
my solution below), and it does in fact add the correct styling - but  
it breaks all my images.

for instance, these don't display anymore:
image link: [[http://blah.com|Group./image.jpg]]

any ideas what i can do to correct this?

# For Attach: -- the MediaLinkIMap function only works for http:, but  
not for Attach:
# this function is taken from the upload.php recipe in the scripts/  
$LinkFunctions['Attach:'] = 'MediaLinkIMap';
function MediaLinkUpload($pagename, $imap, $path, $alt, $txt,  
$fmt=NULL) {
   global $FmtV, $UploadFileFmt, $LinkUploadCreateFmt, $UploadUrlFmt,
     $UploadPrefixFmt, $EnableDirectDownload, $MediaExtPat;
   if (preg_match('!^(.*)/([^/]+)$!', $path, $match)) {
     $pagename = MakePageName($pagename, $match[1]);
     $path = $match[2];
   $upname = MakeUploadName($pagename, $path);
   $filepath = FmtPageName("$UploadFileFmt/$upname", $pagename);
   $FmtV['$LinkUpload'] =
   $FmtV['$LinkText'] = $txt;
   if (!file_exists($filepath))
     return FmtPageName($LinkUploadCreateFmt, $pagename);
   $path = PUE(FmtPageName(IsEnabled($EnableDirectDownload, 1)
				    ? "$UploadUrlFmt$UploadPrefixFmt/$upname"
				    : "{\$PageUrl}?action=download&amp;upname=$upname",
   if (!$fmt)
	$fmt = (preg_match("/($MediaExtPat)$/", $path, $m)) ?
	"<a class='medialink {$m[1]}' href='\$LinkUrl' rel='nofollow'>\ 
	: $fmt;
   return LinkIMap($pagename, $imap, $path, $alt, $txt, $fmt);

More information about the pmwiki-users mailing list