[pmwiki-devel] media links css

adam overton a at plus1plus1plus.org
Mon Feb 1 15:27:13 CST 2010


hi there

a while back, 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| 
pdf";
    $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'  
rel='nofollow'>\$LinkText</a>"
          : $UrlLinkTxtFmt;
      return LinkIMap($pagename,$imap,$path,$title,$txt,$fmt);
    }

the problem i'm running 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:
Attach:Group./image.jpg
image link: [[http://blah.com|Group./image.jpg]]

any ideas what i can do to correct this?
thanks!
adam


# 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/  
folder
$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'] =
     FmtPageName("\$PageUrl?action=upload&amp;upname=$upname",  
$pagename);
   $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",
				  $pagename));
   if (!$fmt)
	$fmt = (preg_match("/($MediaExtPat)$/", $path, $m)) ?
	"<a class='medialink {$m[1]}' href='\$LinkUrl' rel='nofollow'>\ 
$LinkText</a>"
	: $fmt;
   return LinkIMap($pagename, $imap, $path, $alt, $txt, $fmt);
}




More information about the pmwiki-devel mailing list