From b739ff0f3e184faec86f6b027960b65d33d110e9 Mon Sep 17 00:00:00 2001 From: Pierre Spring Date: Thu, 21 Feb 2008 17:08:33 +0100 Subject: media_justlink darcs-hash:20080221160833-c3d3e-1afe0835f9ba1af27712bd34e8b0b65e6165284f.gz --- inc/parser/handler.php | 2 + inc/parser/xhtml.php | 129 +++++++++++++++++++++++++++++-------------------- 2 files changed, 79 insertions(+), 52 deletions(-) (limited to 'inc') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index ad2bb6056..4d3dc5380 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -686,6 +686,8 @@ function Doku_Handler_Parse_Media($match) { $linking = 'nolink'; }else if(preg_match('/direct/i',$param)){ $linking = 'direct'; + }else if(preg_match('/justlink/i',$param)){ + $linking = 'justlink'; }else{ $linking = 'details'; } diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 70e595f82..774fbd5a2 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -665,37 +665,29 @@ class Doku_Renderer_xhtml extends Doku_Renderer { function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, $height=NULL, $cache=NULL, $linking=NULL) { - global $conf; global $ID; resolve_mediaid(getNS($ID),$src, $exists); - $link = array(); - $link['class'] = 'media'; - $link['style'] = ''; - $link['pre'] = ''; - $link['suf'] = ''; - $link['more'] = ''; - $link['target'] = $conf['target']['media']; $noLink = false; + $render = ($linking == 'justlink') ? false : true; + $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); - $link['title'] = $this->_xmlEntities($src); list($ext,$mime) = mimetype($src); - if(substr($mime,0,5) == 'image'){ - $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); - }elseif($mime == 'application/x-shockwave-flash'){ - // don't link flash movies - $noLink = true; - }else{ - // add file icons - $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); - $link['class'] .= ' mediafile mf_'.$class; - $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); - } - $link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache); + if(substr($mime,0,5) == 'image' && $render){ + $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); + }elseif($mime == 'application/x-shockwave-flash'){ + // don't link flash movies + $noLink = true; + }else{ + // add file icons + $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); + $link['class'] .= ' mediafile mf_'.$class; + $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); + } - //output formatted - if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; - else $this->doc .= $this->_formatLink($link); + //output formatted + if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; + else $this->doc .= $this->_formatLink($link); } /** @@ -703,23 +695,14 @@ class Doku_Renderer_xhtml extends Doku_Renderer { */ function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, $height=NULL, $cache=NULL, $linking=NULL) { - global $conf; - - $link = array(); - $link['class'] = 'media'; - $link['style'] = ''; - $link['pre'] = ''; - $link['suf'] = ''; - $link['more'] = ''; - $link['target'] = $conf['target']['media']; + $noLink = false; + $render = ($linking == 'justlink') ? false : true; + $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); - $link['title'] = $this->_xmlEntities($src); $link['url'] = ml($src,array('cache'=>$cache)); - $link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache); - $noLink = false; list($ext,$mime) = mimetype($src); - if(substr($mime,0,5) == 'image'){ + if(substr($mime,0,5) == 'image' && $render){ // link only jpeg images // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; }elseif($mime == 'application/x-shockwave-flash'){ @@ -901,34 +884,44 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * @author Andreas Gohr */ function _media ($src, $title=NULL, $align=NULL, $width=NULL, - $height=NULL, $cache=NULL) { + $height=NULL, $cache=NULL, $render = true) { $ret = ''; list($ext,$mime) = mimetype($src); if(substr($mime,0,5) == 'image'){ - //add image tag - $ret .= '_xmlEntities($title).'"'; - $ret .= ' alt="'.$this->_xmlEntities($title).'"'; + $title = $this->_xmlEntities($title); }elseif($ext == 'jpg' || $ext == 'jpeg'){ //try to use the caption from IPTC/EXIF require_once(DOKU_INC.'inc/JpegMeta.php'); $jpeg =& new JpegMeta(mediaFN($src)); if($jpeg !== false) $cap = $jpeg->getTitle(); if($cap){ - $ret .= ' title="'.$this->_xmlEntities($cap).'"'; - $ret .= ' alt="'.$this->_xmlEntities($cap).'"'; - }else{ - $ret .= ' alt=""'; + $title = $this->_xmlEntities($cap); + } + } + if (!$render) { + // if the picture is not supposed to be rendered + // return the title of the picture + if (!$title) { + // just show the sourcename + $title = $this->_xmlEntities(basename(noNS($src))); } + return $title; + } + //add image tag + $ret .= ' + * @param string $src + * @param string $title + * @param string $align + * @param string $width + * @param string $height + * @param string $cache + * @param string $render + * @access protected + * @return array + */ + function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) + { + global $conf; + + $link = array(); + $link['class'] = 'media'; + $link['style'] = ''; + $link['pre'] = ''; + $link['suf'] = ''; + $link['more'] = ''; + $link['target'] = $conf['target']['media']; + $link['title'] = $this->_xmlEntities($src); + $link['name'] = $this->_media($src, $title, $align, $width, $height, $cache, $render); + + return $link; + } } //Setup VIM: ex: et ts=4 enc=utf-8 : -- cgit v1.2.3