Skip to content
Snippets Groups Projects
Commit b739ff0f authored by Pierre Spring's avatar Pierre Spring
Browse files

media_justlink

darcs-hash:20080221160833-c3d3e-1afe0835f9ba1af27712bd34e8b0b65e6165284f.gz
parent 0deaa5d8
No related branches found
No related tags found
No related merge requests found
...@@ -322,6 +322,21 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser { ...@@ -322,6 +322,21 @@ class TestOfDoku_Parser_Links extends TestOfDoku_Parser {
$this->assertEqual(array_map('stripByteIndex',$this->H->calls),$calls); $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() { function testMediaNotImage() {
$this->P->addMode('media',new Doku_Parser_Mode_Media()); $this->P->addMode('media',new Doku_Parser_Mode_Media());
$this->P->parse('Foo {{foo.txt?10x10|Some File}} Bar'); $this->P->parse('Foo {{foo.txt?10x10|Some File}} Bar');
......
...@@ -686,6 +686,8 @@ function Doku_Handler_Parse_Media($match) { ...@@ -686,6 +686,8 @@ function Doku_Handler_Parse_Media($match) {
$linking = 'nolink'; $linking = 'nolink';
}else if(preg_match('/direct/i',$param)){ }else if(preg_match('/direct/i',$param)){
$linking = 'direct'; $linking = 'direct';
}else if(preg_match('/justlink/i',$param)){
$linking = 'justlink';
}else{ }else{
$linking = 'details'; $linking = 'details';
} }
......
...@@ -665,37 +665,29 @@ class Doku_Renderer_xhtml extends Doku_Renderer { ...@@ -665,37 +665,29 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
$height=NULL, $cache=NULL, $linking=NULL) { $height=NULL, $cache=NULL, $linking=NULL) {
global $conf;
global $ID; global $ID;
resolve_mediaid(getNS($ID),$src, $exists); 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; $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); list($ext,$mime) = mimetype($src);
if(substr($mime,0,5) == 'image'){ if(substr($mime,0,5) == 'image' && $render){
$link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct'));
}elseif($mime == 'application/x-shockwave-flash'){ }elseif($mime == 'application/x-shockwave-flash'){
// don't link flash movies // don't link flash movies
$noLink = true; $noLink = true;
}else{ }else{
// add file icons // add file icons
$class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
$link['class'] .= ' mediafile mf_'.$class; $link['class'] .= ' mediafile mf_'.$class;
$link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true);
} }
$link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache);
//output formatted //output formatted
if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
else $this->doc .= $this->_formatLink($link); else $this->doc .= $this->_formatLink($link);
} }
/** /**
...@@ -703,23 +695,14 @@ class Doku_Renderer_xhtml extends Doku_Renderer { ...@@ -703,23 +695,14 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
*/ */
function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
$height=NULL, $cache=NULL, $linking=NULL) { $height=NULL, $cache=NULL, $linking=NULL) {
global $conf; $noLink = false;
$render = ($linking == 'justlink') ? false : true;
$link = array(); $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
$link['class'] = 'media';
$link['style'] = '';
$link['pre'] = '';
$link['suf'] = '';
$link['more'] = '';
$link['target'] = $conf['target']['media'];
$link['title'] = $this->_xmlEntities($src);
$link['url'] = ml($src,array('cache'=>$cache)); $link['url'] = ml($src,array('cache'=>$cache));
$link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache);
$noLink = false;
list($ext,$mime) = mimetype($src); list($ext,$mime) = mimetype($src);
if(substr($mime,0,5) == 'image'){ if(substr($mime,0,5) == 'image' && $render){
// link only jpeg images // link only jpeg images
// if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true;
}elseif($mime == 'application/x-shockwave-flash'){ }elseif($mime == 'application/x-shockwave-flash'){
...@@ -901,34 +884,44 @@ class Doku_Renderer_xhtml extends Doku_Renderer { ...@@ -901,34 +884,44 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
* @author Andreas Gohr <andi@splitbrain.org> * @author Andreas Gohr <andi@splitbrain.org>
*/ */
function _media ($src, $title=NULL, $align=NULL, $width=NULL, function _media ($src, $title=NULL, $align=NULL, $width=NULL,
$height=NULL, $cache=NULL) { $height=NULL, $cache=NULL, $render = true) {
$ret = ''; $ret = '';
list($ext,$mime) = mimetype($src); list($ext,$mime) = mimetype($src);
if(substr($mime,0,5) == 'image'){ if(substr($mime,0,5) == 'image'){
//add image tag // first get the $title
$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 (!is_null($title)) { if (!is_null($title)) {
$ret .= ' title="'.$this->_xmlEntities($title).'"'; $title = $this->_xmlEntities($title);
$ret .= ' alt="'.$this->_xmlEntities($title).'"';
}elseif($ext == 'jpg' || $ext == 'jpeg'){ }elseif($ext == 'jpg' || $ext == 'jpeg'){
//try to use the caption from IPTC/EXIF //try to use the caption from IPTC/EXIF
require_once(DOKU_INC.'inc/JpegMeta.php'); require_once(DOKU_INC.'inc/JpegMeta.php');
$jpeg =& new JpegMeta(mediaFN($src)); $jpeg =& new JpegMeta(mediaFN($src));
if($jpeg !== false) $cap = $jpeg->getTitle(); if($jpeg !== false) $cap = $jpeg->getTitle();
if($cap){ if($cap){
$ret .= ' title="'.$this->_xmlEntities($cap).'"'; $title = $this->_xmlEntities($cap);
$ret .= ' alt="'.$this->_xmlEntities($cap).'"'; }
}else{ }
$ret .= ' alt=""'; 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{ }else{
$ret .= ' alt=""'; $ret .= ' alt=""';
} }
...@@ -1036,6 +1029,38 @@ class Doku_Renderer_xhtml extends Doku_Renderer { ...@@ -1036,6 +1029,38 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$img['height'], $img['height'],
$img['cache']); $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 : //Setup VIM: ex: et ts=4 enc=utf-8 :
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment