diff options
Diffstat (limited to 'inc/parser')
-rw-r--r-- | inc/parser/action.php | 27 | ||||
-rw-r--r-- | inc/parser/handler.php | 83 | ||||
-rw-r--r-- | inc/parser/xhtml.php | 265 |
3 files changed, 215 insertions, 160 deletions
diff --git a/inc/parser/action.php b/inc/parser/action.php index 4e971ed4a..3935bbeae 100644 --- a/inc/parser/action.php +++ b/inc/parser/action.php @@ -96,9 +96,34 @@ function render_as_xhtml($instructions){ } /** + * Returns a full media id + * + * @author Andreas Gohr <andi@splitbrain.org> + * @todo move to utils? + */ +function resolve_mediaid(&$page,&$exists){ + global $ID; + global $conf; + $ns = getNS($ID); + //if links starts with . add current namespace + if($page{0} == '.'){ + $page = $ns.':'.substr($page,1); + } + + //if link contains no namespace. add current namespace (if any) + if($ns !== false && strpos($page,':') === false){ + $page = $ns.':'.$page; + } + + $page = cleanID($page); + $file = mediaFN($page); + $exists = @file_exists($file); +} + +/** * Returns a full page id * - * @todo move to renderer? + * @todo move to utils? */ function resolve_pageid(&$page,&$exists){ global $ID; diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 75020059e..108a522a5 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -532,62 +532,47 @@ function Doku_Handler_Parse_Media($match) { if ( !isset($link[1]) ) { $link[1] = NULL; } - - // img src url from params - // What if it's an external image where URL contains '?' char? - $src = preg_split('/\?/u',$link[0],2); - - // Strip any alignment whitespace - $src[0] = trim($src[0]); - - // Check for width, height and caching params - if ( isset($src[1]) ) { - - if(preg_match('#(\d*)(x(\d*))?#i',$src[1],$matches)){ - - if(isset($matches[1])) { - $width = $matches[1]; - } else { - $width = NULL; - } - - if(isset($matches[3])) { - $height = $matches[3]; - } else { - $height = NULL; - } - - $cache = !(bool)preg_match('/nocache/i',$src[1]); - } - - } else { - $width = NULL; - $height = NULL; - $cache = TRUE; + + //remove aligning spaces + $link[0] = trim($link[0]); + + //split into src and parameters (using the very last questionmark) + $pos = strrpos($link[0], '?'); + if($pos !== false){ + $src = substr($link[0],0,$pos); + $param = substr($link[0],$pos+1); + }else{ + $src = $link[0]; + $param = ''; } - - // Check whether this is a local or remote image - if ( substr($src[0],0,4) == 'http' ) { - $call = 'external'; - } else { - $call = 'internal'; + + //parse width and height + if(preg_match('#(\d+)(x(\d+))?#i',$param,$size)){ + ($size[1]) ? $w = $size[1] : $w = NULL; + ($size[3]) ? $h = $size[3] : $h = NULL; } - - // Check this is actually an image... - if ( !preg_match('/\.(gif|png|jpe?g)$/',$src[0] ) ) { - // Security implications?... - $call .= 'link'; + + //get caching command + if (preg_match('/(nocache|recache)/i',$param,$cachemode)){ + $cache = $cachemode[1]; + }else{ + $cache = 'cache'; + } + + // Check whether this is a local or remote image + if ( preg_match('#^(https?|ftp)#i',$src) ) { + $call = 'externalmedia'; } else { - $call .= 'media'; + $call = 'internalmedia'; } - + $params = array( 'type'=>$call, - 'src'=>$src[0], + 'src'=>$src, 'title'=>$link[1], 'align'=>$align, - 'width'=>$width, - 'height'=>$height, + 'width'=>$w, + 'height'=>$h, 'cache'=>$cache, ); @@ -1497,4 +1482,4 @@ class Doku_Handler_Toc { } -//Setup VIM: ex: et ts=2 enc=utf-8 : +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index b5c2b5d8d..377b514be 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -39,7 +39,7 @@ class Doku_Renderer_XHTML extends Doku_Renderer { } function document_end() { - // add button for last section if any + // add button for last section if any if($this->lastsec) $this->__secedit($this->lastsec,''); if ( count ($this->footnotes) > 0 ) { @@ -93,13 +93,13 @@ class Doku_Renderer_XHTML extends Doku_Renderer { function header($text, $level, $pos) { global $conf; - //handle section editing + //handle section editing if($level <= $conf['maxseclevel']){ // add button for last section if any if($this->lastsec) $this->__secedit($this->lastsec,$pos-1); - // remember current position - $this->lastsec = $pos; - } + // remember current position + $this->lastsec = $pos; + } echo DOKU_LF.'<a name="'.$this->__headerToLink($text).'"></a><h'.$level.'>'; echo $this->__xmlEntities($text); @@ -247,23 +247,23 @@ class Doku_Renderer_XHTML extends Doku_Renderer { /** */ function php($text) { - global $conf; - if($conf['phpok']){ - eval($text); + global $conf; + if($conf['phpok']){ + eval($text); }else{ - $this->file($text); - } + $this->file($text); + } } /** */ function html($text) { - global $conf; + global $conf; if($conf['htmlok']){ - echo $text; - }else{ - $this->file($text); - } + echo $text; + }else{ + $this->file($text); + } } function preformatted($text) { @@ -291,7 +291,7 @@ class Doku_Renderer_XHTML extends Doku_Renderer { /** */ function code($text, $language = NULL) { - global $conf; + global $conf; if ( is_null($language) ) { $this->preformatted($text); @@ -302,7 +302,7 @@ class Doku_Renderer_XHTML extends Doku_Renderer { $geshi->enable_classes(); $geshi->set_header_type(GESHI_HEADER_PRE); $geshi->set_overall_class('code'); - $geshi->set_link_target($conf['target']['extern']); + $geshi->set_link_target($conf['target']['extern']); $text = $geshi->parse_code(); echo $text; @@ -378,7 +378,7 @@ class Doku_Renderer_XHTML extends Doku_Renderer { /** */ function camelcaselink($link) { - $this->internallink($link,$link); + $this->internallink($link,$link); } /** @@ -386,7 +386,7 @@ class Doku_Renderer_XHTML extends Doku_Renderer { * @TODO correct attributes */ function internallink($id, $name = NULL) { - global $conf; + global $conf; $name = $this->__getLinkTitle($name, $this->__simpleTitle($id), $isImage); resolve_pageid($id,$exists); @@ -401,7 +401,7 @@ class Doku_Renderer_XHTML extends Doku_Renderer { $class='media'; } - //prepare for formating + //prepare for formating $link['target'] = $conf['target']['wiki']; $link['style'] = ''; $link['pre'] = ''; @@ -579,67 +579,103 @@ class Doku_Renderer_XHTML extends Doku_Renderer { } /** - * @TODO Resolve namespaces - * @TODO Add image caching - * @TODO Remove hard coded link to splitbrain.org - */ - function internalmedia ( - $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL - ) { - - // Sort out the namespace here... - if ( strpos($src,':') ) { - $src = explode(':',$src); - $src = $src[1]; - } - echo '<img class="media" src="http://wiki.splitbrain.org/media/wiki/'.$this->__xmlEntities($src).'"'; - - if ( !is_null($title) ) { - echo ' title="'.$this->__xmlEntities($title).'"'; - } - - if ( !is_null($align) ) { - echo ' align="'.$align.'"'; - } - - if ( !is_null($width) ) { - echo ' width="'.$this->__xmlEntities($width).'"'; - } - - if ( !is_null($height) ) { - echo ' height="'.$this->__xmlEntities($height).'"'; - } - - echo '/>'; + * @todo don't add link for flash + */ + function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, + $height=NULL, $cache=NULL) { + resolve_mediaid($src, $exists); + + $this->internallink($src, $title = + array( 'type' => 'internalmedia', + 'src' => $src, + 'title' => $title, + 'align' => $align, + 'width' => $width, + 'height' => $height, + 'cache' => $cache, + 'link' => $link )); } /** - * @TODO Add image caching - */ - function externalmedia ( - $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL - ) { - - echo '<img class="media" src="'.$this->__xmlEntities($src).'"'; - - if ( !is_null($title) ) { - echo ' title="'.$this->__xmlEntities($title).'"'; - } - - if ( !is_null($align) ) { - echo ' align="'.$align.'"'; - } + * @todo don't add link for flash + */ + function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, + $height=NULL, $cache=NULL) { + + $this->externallink($src, $title = + array( 'type' => 'externalmedia', + 'src' => $src, + 'title' => $title, + 'align' => $align, + 'width' => $width, + 'height' => $height, + 'cache' => $cache, + 'link' => $link )); + } + + /** + * Renders internal and external media + * + * @author Andreas Gohr <andi@splitbrain.org> + * @todo handle center align + */ + function __media ($src, $title=NULL, $align=NULL, $width=NULL, + $height=NULL, $cache=NULL) { + + $ret = ''; + + list($ext,$mime) = mimetype($src); + if(substr($mime,0,5) == 'image'){ + //add image tag + $ret .= '<img class="media" src="'. + DOKU_BASE.'fetch.php?media='.urlencode($src). + '&w='.$width.'&h='.$height. + '&cache='.$cache.'"'; + + if (!is_null($title)) + $ret .= ' title="'.$this->__xmlEntities($title).'"'; + - if ( !is_null($width) ) { - echo ' width="'.$this->__xmlEntities($width).'"'; - } + if (!is_null($align)) + $ret .= ' align="'.$align.'"'; #FIXME use class! + + if ( !is_null($width) ) + $ret .= ' width="'.$this->__xmlEntities($width).'"'; - if ( !is_null($height) ) { - echo ' height="'.$this->__xmlEntities($height).'"'; + if ( !is_null($height) ) + $ret .= ' height="'.$this->__xmlEntities($height).'"'; + + $ret .= ' />'; + + }elseif($mime == 'application/x-shockwave-flash'){ + //FIXME default to a higher flash version? + + $ret .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'. + ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"'; + if ( !is_null($width) ) $ret .= ' width="'.$this->__xmlEntities($width).'"'; + if ( !is_null($height) ) $ret .= ' height="'.$this->__xmlEntities($height).'"'; + $ret .= '>'.DOKU_LF; + $ret .= '<param name="movie" value="'.DOKU_BASE.'fetch.php?media='.urlencode($src).'" />'.DOKU_LF; + $ret .= '<param name="quality" value="high" />'.DOKU_LF; + $ret .= '<embed src="'.DOKU_BASE.'fetch.php?media='.urlencode($src).'"'. + ' quality="high" bgcolor="#000000"'; + if ( !is_null($width) ) $ret .= ' width="'.$this->__xmlEntities($width).'"'; + if ( !is_null($height) ) $ret .= ' height="'.$this->__xmlEntities($height).'"'; + $ret .= ' type="application/x-shockwave-flash"'. + ' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi'. + '?P1_Prod_Version=ShockwaveFlash"></embed>'.DOKU_LF; + $ret .= '</object>'.DOKU_LF; + + }elseif(!is_null($title)){ + // well at least we have a title to display + $ret .= $this->__xmlEntities($title); + }else{ + // just show the source + $ret .= $this->__xmlEntities($src); } - - echo '/>'; + + return $ret; } // $numrows not yet implemented @@ -699,27 +735,27 @@ class Doku_Renderer_XHTML extends Doku_Renderer { * @author Andreas Gohr <andi@splitbrain.org> */ function __formatLink($link){ - //make sure the url is XHTML compliant (skip mailto) - if(substr($link['url'],0,7) != 'mailto:'){ - $link['url'] = str_replace('&','&',$link['url']); - $link['url'] = str_replace('&amp;','&',$link['url']); - } - //remove double encodings in titles - $link['title'] = str_replace('&amp;','&',$link['title']); - - $ret = ''; - $ret .= $link['pre']; - $ret .= '<a href="'.$link['url'].'"'; - if($link['class']) $ret .= ' class="'.$link['class'].'"'; - if($link['target']) $ret .= ' target="'.$link['target'].'"'; - if($link['title']) $ret .= ' title="'.$link['title'].'"'; - if($link['style']) $ret .= ' style="'.$link['style'].'"'; - if($link['more']) $ret .= ' '.$link['more']; - $ret .= '>'; - $ret .= $link['name']; - $ret .= '</a>'; - $ret .= $link['suf']; - return $ret; + //make sure the url is XHTML compliant (skip mailto) + if(substr($link['url'],0,7) != 'mailto:'){ + $link['url'] = str_replace('&','&',$link['url']); + $link['url'] = str_replace('&amp;','&',$link['url']); + } + //remove double encodings in titles + $link['title'] = str_replace('&amp;','&',$link['title']); + + $ret = ''; + $ret .= $link['pre']; + $ret .= '<a href="'.$link['url'].'"'; + if($link['class']) $ret .= ' class="'.$link['class'].'"'; + if($link['target']) $ret .= ' target="'.$link['target'].'"'; + if($link['title']) $ret .= ' title="'.$link['title'].'"'; + if($link['style']) $ret .= ' style="'.$link['style'].'"'; + if($link['more']) $ret .= ' '.$link['more']; + $ret .= '>'; + $ret .= $link['name']; + $ret .= '</a>'; + $ret .= $link['suf']; + return $ret; } /** @@ -729,13 +765,13 @@ class Doku_Renderer_XHTML extends Doku_Renderer { * @author Andreas Gohr <andi@splitbrain.org> */ function __simpleTitle($name){ - global $conf; - if($conf['useslash']){ - $nssep = '[:;/]'; - }else{ - $nssep = '[:;]'; - } - return preg_replace('!.*'.$nssep.'!','',$name); + global $conf; + if($conf['useslash']){ + $nssep = '[:;/]'; + }else{ + $nssep = '[:;]'; + } + return preg_replace('!.*'.$nssep.'!','',$name); } @@ -758,9 +794,9 @@ class Doku_Renderer_XHTML extends Doku_Renderer { /** * Adds code for section editing button */ - function __secedit($f, $t){ + function __secedit($f, $t){ print '<!-- SECTION ['.$f.'-'.$t.'] -->'; - } + } function __getLinkTitle($title, $default, & $isImage) { $isImage = FALSE; @@ -781,12 +817,20 @@ class Doku_Renderer_XHTML extends Doku_Renderer { } /** - * @TODO Resolve namespace on internal images - * @TODO Remove hard coded url to splitbrain.org - * @TODO Image caching - */ + * @TODO Resolve namespace on internal images + */ function __imageTitle($img) { - + + //FIXME resolve internal links + + return $this->__media($img['src'], + $img['title'], + $img['align'], + $img['width'], + $img['height'], + $img['cache']); + +/* if ( $img['type'] == 'internalmedia' ) { // Resolve here... @@ -826,6 +870,7 @@ class Doku_Renderer_XHTML extends Doku_Renderer { $imgStr .= '/>'; return $imgStr; +*/ } } @@ -876,4 +921,4 @@ msg("deprecated wikiPageExists called",-1); } -//Setup VIM: ex: et ts=2 enc=utf-8 : +//Setup VIM: ex: et ts=4 enc=utf-8 : |