diff --git a/_test/cases/inc/parser/parser_links.test.php b/_test/cases/inc/parser/parser_links.test.php index 05ea12f64527cc9ee2a4c73fd120895337be103f..86597ba9e036a5ba7d7b824e332db8e8d2e905f3 100644 --- a/_test/cases/inc/parser/parser_links.test.php +++ b/_test/cases/inc/parser/parser_links.test.php @@ -322,6 +322,21 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); } + function testMediaInternalJustlink() { + $this->P->addMode('media',new Doku_Parser_Mode_Media()); + $this->P->parse('Foo {{img.gif?justlink}} Bar'); + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n".'Foo ')), + array('internalmedia',array('img.gif',NULL,NULL,NULL,NULL,'cache','justlink')), + array('cdata',array(' Bar'."\n")), + array('p_close',array()), + array('document_end',array()), + ); + $this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); + } + function testMediaNotImage() { $this->P->addMode('media',new Doku_Parser_Mode_Media()); $this->P->parse('Foo {{foo.txt?10x10|Some File}} Bar'); diff --git a/inc/parser/handler.php b/inc/parser/handler.php index ad2bb6056a0d3658e6f97142549ceb05aa7cbf86..4d3dc5380531f3e3caa27886ddd1239aebb0feb8 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 70e595f82f3d60a88ed7fd3ac964878c7077d94b..774fbd5a27bf9e47be7b38de6a707eb0b7da3846 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 <andi@splitbrain.org> */ 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 .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; - $ret .= ' class="media'.$align.'"'; - - // make left/right alignment for no-CSS view work (feeds) - if($align == 'right') $ret .= ' align="right"'; - if($align == 'left') $ret .= ' align="left"'; - + // first get the $title if (!is_null($title)) { - $ret .= ' title="'.$this->_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 .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; + $ret .= ' class="media'.$align.'"'; + + // make left/right alignment for no-CSS view work (feeds) + if($align == 'right') $ret .= ' align="right"'; + if($align == 'left') $ret .= ' align="left"'; + + if ($title) { + $ret .= ' title="' . $title . '"'; + $ret .= ' alt="' . $title .'"'; }else{ $ret .= ' alt=""'; } @@ -1036,6 +1029,38 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $img['height'], $img['cache']); } + + /** + * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia() + * which returns a basic link to a media. + * + * @author Pierre Spring <pierre.spring@liip.ch> + * @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 :