diff options
author | Guy Brand <gb@unistra.fr> | 2014-05-05 22:51:26 +0200 |
---|---|---|
committer | Guy Brand <gb@unistra.fr> | 2014-05-05 22:51:26 +0200 |
commit | 43a2e077a27740ebb0f0bc49e4a3d288c8811d78 (patch) | |
tree | e22f94855951702e622d4c40ac44f3031b3d5819 /inc/parser | |
parent | c6af9e94ed5d7f7713359faac18543db9a9aee48 (diff) | |
parent | 75930869ddcb31470ea7617eddfb882de02645df (diff) | |
download | rpg-43a2e077a27740ebb0f0bc49e4a3d288c8811d78.tar.gz rpg-43a2e077a27740ebb0f0bc49e4a3d288c8811d78.tar.bz2 |
Merge branch 'master' into stable
Diffstat (limited to 'inc/parser')
-rw-r--r-- | inc/parser/code.php | 1 | ||||
-rw-r--r-- | inc/parser/handler.php | 73 | ||||
-rw-r--r-- | inc/parser/metadata.php | 4 | ||||
-rw-r--r-- | inc/parser/parser.php | 80 | ||||
-rw-r--r-- | inc/parser/renderer.php | 64 | ||||
-rw-r--r-- | inc/parser/xhtml.php | 168 | ||||
-rw-r--r-- | inc/parser/xhtmlsummary.php | 1 |
7 files changed, 320 insertions, 71 deletions
diff --git a/inc/parser/code.php b/inc/parser/code.php index 0b8e3ee02..d77ffd1aa 100644 --- a/inc/parser/code.php +++ b/inc/parser/code.php @@ -5,7 +5,6 @@ * @author Andreas Gohr <andi@splitbrain.org> */ if(!defined('DOKU_INC')) die('meh.'); -require_once DOKU_INC . 'inc/parser/renderer.php'; class Doku_Renderer_code extends Doku_Renderer { var $_codeblock=0; diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 8ae991209..a1040d12e 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -12,6 +12,7 @@ class Doku_Handler { var $status = array( 'section' => false, + 'doublequote' => 0, ); var $rewriteBlocks = true; @@ -401,11 +402,17 @@ class Doku_Handler { function doublequoteopening($match, $state, $pos) { $this->_addCall('doublequoteopening',array(), $pos); + $this->status['doublequote']++; return true; } function doublequoteclosing($match, $state, $pos) { - $this->_addCall('doublequoteclosing',array(), $pos); + if ($this->status['doublequote'] <= 0) { + $this->doublequoteopening($match, $state, $pos); + } else { + $this->_addCall('doublequoteclosing',array(), $pos); + $this->status['doublequote'] = max(0, --$this->status['doublequote']); + } return true; } @@ -1149,6 +1156,9 @@ class Doku_Handler_Table { var $currentCols = 0; var $firstCell = false; var $lastCellType = 'tablecell'; + var $inTableHead = true; + var $currentRow = array('tableheader' => 0, 'tablecell' => 0); + var $countTableHeadRows = 0; function Doku_Handler_Table(& $CallWriter) { $this->CallWriter = & $CallWriter; @@ -1216,15 +1226,24 @@ class Doku_Handler_Table { $this->firstCell = true; $this->lastCellType = 'tablecell'; $this->maxRows++; + if ($this->inTableHead) { + $this->currentRow = array('tablecell' => 0, 'tableheader' => 0); + } } function tableRowClose($call) { + if ($this->inTableHead && ($this->inTableHead = $this->isTableHeadRow())) { + $this->countTableHeadRows++; + } // Strip off final cell opening and anything after it while ( $discard = array_pop($this->tableCalls ) ) { if ( $discard[0] == 'tablecell_open' || $discard[0] == 'tableheader_open') { break; } + if (!empty($this->currentRow[$discard[0]])) { + $this->currentRow[$discard[0]]--; + } } $this->tableCalls[] = array('tablerow_close', array(), $call[2]); @@ -1233,7 +1252,20 @@ class Doku_Handler_Table { } } + function isTableHeadRow() { + $td = $this->currentRow['tablecell']; + $th = $this->currentRow['tableheader']; + + if (!$th || $td > 2) return false; + if (2*$td > $th) return false; + + return true; + } + function tableCell($call) { + if ($this->inTableHead) { + $this->currentRow[$call[0]]++; + } if ( !$this->firstCell ) { // Increase the span @@ -1281,6 +1313,13 @@ class Doku_Handler_Table { $cellKey = array(); $toDelete = array(); + // if still in tableheader, then there can be no table header + // as all rows can't be within <THEAD> + if ($this->inTableHead) { + $this->inTableHead = false; + $this->countTableHeadRows = 0; + } + // Look for the colspan elements and increment the colspan on the // previous non-empty opening cell. Once done, delete all the cells // that contain colspans @@ -1288,6 +1327,14 @@ class Doku_Handler_Table { $call = $this->tableCalls[$key]; switch ($call[0]) { + case 'table_open' : + if($this->countTableHeadRows) { + array_splice($this->tableCalls, $key+1, 0, array( + array('tablethead_open', array(), $call[2])) + ); + } + break; + case 'tablerow_open': $lastRow++; @@ -1357,15 +1404,19 @@ class Doku_Handler_Table { } else { $spanning_cell = null; - for($i = $lastRow-1; $i > 0; $i--) { - if ( $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tablecell_open' || $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tableheader_open' ) { + // can't cross thead/tbody boundary + if (!$this->countTableHeadRows || ($lastRow-1 != $this->countTableHeadRows)) { + for($i = $lastRow-1; $i > 0; $i--) { - if ($this->tableCalls[$cellKey[$i][$lastCell]][1][2] >= $lastRow - $i) { - $spanning_cell = $i; - break; - } + if ( $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tablecell_open' || $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tableheader_open' ) { + + if ($this->tableCalls[$cellKey[$i][$lastCell]][1][2] >= $lastRow - $i) { + $spanning_cell = $i; + break; + } + } } } if (is_null($spanning_cell)) { @@ -1396,6 +1447,10 @@ class Doku_Handler_Table { $key += 3; } + if($this->countTableHeadRows == $lastRow) { + array_splice($this->tableCalls, $key+1, 0, array( + array('tablethead_close', array(), $call[2]))); + } break; } @@ -1438,7 +1493,7 @@ class Doku_Handler_Block { var $blockOpen = array( 'header', 'listu_open','listo_open','listitem_open','listcontent_open', - 'table_open','tablerow_open','tablecell_open','tableheader_open', + 'table_open','tablerow_open','tablecell_open','tableheader_open','tablethead_open', 'quote_open', 'code','file','hr','preformatted','rss', 'htmlblock','phpblock', @@ -1448,7 +1503,7 @@ class Doku_Handler_Block { var $blockClose = array( 'header', 'listu_close','listo_close','listitem_close','listcontent_close', - 'table_close','tablerow_close','tablecell_close','tableheader_close', + 'table_close','tablerow_close','tablecell_close','tableheader_close','tablethead_close', 'quote_close', 'code','file','hr','preformatted','rss', 'htmlblock','phpblock', diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index 8ba159d62..82a268fd6 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -16,8 +16,6 @@ if ( !defined('DOKU_TAB') ) { define ('DOKU_TAB',"\t"); } -require_once DOKU_INC . 'inc/parser/renderer.php'; - /** * The Renderer */ @@ -301,7 +299,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { // first resolve and clean up the $id resolve_pageid(getNS($ID), $id, $exists); - list($page, $hash) = explode('#', $id, 2); + @list($page, $hash) = explode('#', $id, 2); // set metadata $this->meta['relation']['references'][$page] = $exists; diff --git a/inc/parser/parser.php b/inc/parser/parser.php index 1f14b98a3..252bd9170 100644 --- a/inc/parser/parser.php +++ b/inc/parser/parser.php @@ -125,43 +125,91 @@ class Doku_Parser { } //------------------------------------------------------------------- + /** - * This class and all the subclasses below are - * used to reduce the effort required to register - * modes with the Lexer. For performance these - * could all be eliminated later perhaps, or - * the Parser could be serialized to a file once - * all modes are registered + * Class Doku_Parser_Mode_Interface * - * @author Harry Fuecks <hfuecks@gmail.com> + * Defines a mode (syntax component) in the Parser */ -class Doku_Parser_Mode { +interface Doku_Parser_Mode_Interface { + /** + * returns a number used to determine in which order modes are added + */ + public function getSort(); + + /** + * Called before any calls to connectTo + */ + function preConnect(); + + /** + * Connects the mode + * + * @param string $mode + */ + function connectTo($mode); /** + * Called after all calls to connectTo + */ + function postConnect(); + + /** + * Check if given mode is accepted inside this mode + * + * @param string $mode + * @return bool + */ + function accepts($mode); +} + +/** + * This class and all the subclasses below are used to reduce the effort required to register + * modes with the Lexer. + * + * @author Harry Fuecks <hfuecks@gmail.com> + */ +class Doku_Parser_Mode implements Doku_Parser_Mode_Interface { + /** * @var Doku_Lexer $Lexer */ var $Lexer; - var $allowedModes = array(); - // returns a number used to determine in which order modes are added function getSort() { trigger_error('getSort() not implemented in '.get_class($this), E_USER_WARNING); } - // Called before any calls to connectTo function preConnect() {} - - // Connects the mode function connectTo($mode) {} - - // Called after all calls to connectTo function postConnect() {} - function accepts($mode) { return in_array($mode, (array) $this->allowedModes ); } +} + +/** + * Basically the same as Doku_Parser_Mode but extends from DokuWiki_Plugin + * + * Adds additional functions to syntax plugins + */ +class Doku_Parser_Mode_Plugin extends DokuWiki_Plugin implements Doku_Parser_Mode_Interface { + /** + * @var Doku_Lexer $Lexer + */ + var $Lexer; + var $allowedModes = array(); + + function getSort() { + trigger_error('getSort() not implemented in '.get_class($this), E_USER_WARNING); + } + function preConnect() {} + function connectTo($mode) {} + function postConnect() {} + function accepts($mode) { + return in_array($mode, (array) $this->allowedModes ); + } } //------------------------------------------------------------------- diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index c697e990c..e92b81bd7 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -6,8 +6,6 @@ * @author Andreas Gohr <andi@splitbrain.org> */ if(!defined('DOKU_INC')) die('meh.'); -require_once DOKU_INC . 'inc/plugin.php'; -require_once DOKU_INC . 'inc/pluginutils.php'; /** * An empty renderer, produces no output @@ -59,9 +57,15 @@ class Doku_Renderer extends DokuWiki_Plugin { return false; } - - //handle plugin rendering - function plugin($name,$data){ + /** + * handle plugin rendering + * + * @param string $name Plugin name + * @param mixed $data custom data set by handler + * @param string $state matched state if any + * @param string $match raw matched syntax + */ + function plugin($name,$data,$state='',$match=''){ $plugin = plugin_load('syntax',$name); if($plugin != null){ $plugin->render($this->getFormat(),$this,$data); @@ -245,6 +249,10 @@ class Doku_Renderer extends DokuWiki_Plugin { function table_close($pos = null){} + function tablethead_open(){} + + function tablethead_close(){} + function tablerow_open(){} function tablerow_close(){} @@ -267,17 +275,17 @@ class Doku_Renderer extends DokuWiki_Plugin { * * @author Andreas Gohr <andi@splitbrain.org> */ - function _simpleTitle($name){ + function _simpleTitle($name) { global $conf; //if there is a hash we use the ancor name only - list($name,$hash) = explode('#',$name,2); + @list($name, $hash) = explode('#', $name, 2); if($hash) return $hash; - if($conf['useslash']){ - $name = strtr($name,';/',';:'); - }else{ - $name = strtr($name,';',':'); + if($conf['useslash']) { + $name = strtr($name, ';/', ';:'); + } else { + $name = strtr($name, ';', ':'); } return noNSorNS($name); @@ -286,9 +294,9 @@ class Doku_Renderer extends DokuWiki_Plugin { /** * Resolve an interwikilink */ - function _resolveInterWiki(&$shortcut,$reference){ + function _resolveInterWiki(&$shortcut, $reference, &$exists=null) { //get interwiki URL - if ( isset($this->interwiki[$shortcut]) ) { + if(isset($this->interwiki[$shortcut])) { $url = $this->interwiki[$shortcut]; } else { // Default to Google I'm feeling lucky @@ -297,25 +305,31 @@ class Doku_Renderer extends DokuWiki_Plugin { } //split into hash and url part - list($reference,$hash) = explode('#',$reference,2); + @list($reference, $hash) = explode('#', $reference, 2); //replace placeholder - if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){ + if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#', $url)) { //use placeholders - $url = str_replace('{URL}',rawurlencode($reference),$url); - $url = str_replace('{NAME}',$reference,$url); + $url = str_replace('{URL}', rawurlencode($reference), $url); + $url = str_replace('{NAME}', $reference, $url); $parsed = parse_url($reference); if(!$parsed['port']) $parsed['port'] = 80; - $url = str_replace('{SCHEME}',$parsed['scheme'],$url); - $url = str_replace('{HOST}',$parsed['host'],$url); - $url = str_replace('{PORT}',$parsed['port'],$url); - $url = str_replace('{PATH}',$parsed['path'],$url); - $url = str_replace('{QUERY}',$parsed['query'],$url); - }else{ + $url = str_replace('{SCHEME}', $parsed['scheme'], $url); + $url = str_replace('{HOST}', $parsed['host'], $url); + $url = str_replace('{PORT}', $parsed['port'], $url); + $url = str_replace('{PATH}', $parsed['path'], $url); + $url = str_replace('{QUERY}', $parsed['query'], $url); + } else { //default - $url = $url.rawurlencode($reference); + $url = $url . rawurlencode($reference); + } + //handle as wiki links + if($url{0} === ':') { + list($id, $urlparam) = explode('?', $url, 2); + $url = wl(cleanID($id), $urlparam); + $exists = page_exists($id); } - if($hash) $url .= '#'.rawurlencode($hash); + if($hash) $url .= '#' . rawurlencode($hash); return $url; } diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index fd02c0ce0..cf36a8175 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -17,9 +17,6 @@ if ( !defined('DOKU_TAB') ) { define ('DOKU_TAB',"\t"); } -require_once DOKU_INC . 'inc/parser/renderer.php'; -require_once DOKU_INC . 'inc/html.php'; - /** * The Renderer */ @@ -562,6 +559,12 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * $search,$returnonly & $linktype are not for the renderer but are used * elsewhere - no need to implement them in other renderers * + * @param string $id pageid + * @param string|null $name link name + * @param string|null $search adds search url param + * @param bool $returnonly whether to return html or write to doc attribute + * @param string $linktype type to set use of headings + * @return void|string writes to doc attribute or returns html depends on $returnonly * @author Andreas Gohr <andi@splitbrain.org> */ function internallink($id, $name = null, $search=null,$returnonly=false,$linktype='content') { @@ -603,7 +606,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } //keep hash anchor - list($id,$hash) = explode('#',$id,2); + @list($id,$hash) = explode('#',$id,2); if(!empty($hash)) $hash = $this->_headerToLink($hash); //prepare for formating @@ -685,7 +688,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } /** - */ + */ function interwikilink($match, $name = null, $wikiName, $wikiUri) { global $conf; @@ -697,19 +700,28 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); //get interwiki URL - $url = $this->_resolveInterWiki($wikiName,$wikiUri); + $exists = null; + $url = $this->_resolveInterWiki($wikiName, $wikiUri, $exists); - if ( !$isImage ) { - $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); + if(!$isImage) { + $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $wikiName); $link['class'] = "interwiki iw_$class"; } else { $link['class'] = 'media'; } //do we stay at the same server? Use local target - if( strpos($url,DOKU_URL) === 0 ){ + if(strpos($url, DOKU_URL) === 0 OR strpos($url, DOKU_BASE) === 0) { $link['target'] = $conf['target']['wiki']; } + if($exists !== null && !$isImage) { + if($exists) { + $link['class'] .= ' wikilink1'; + } else { + $link['class'] .= ' wikilink2'; + $link['rel'] = 'nofollow'; + } + } $link['url'] = $url; $link['title'] = htmlspecialchars($link['url']); @@ -781,7 +793,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } function internalmedia ($src, $title=null, $align=null, $width=null, - $height=null, $cache=null, $linking=null) { + $height=null, $cache=null, $linking=null, $return=NULL) { global $ID; list($src,$hash) = explode('#',$src,2); resolve_mediaid(getNS($ID),$src, $exists); @@ -793,8 +805,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer { list($ext,$mime,$dl) = mimetype($src,false); if(substr($mime,0,5) == 'image' && $render){ $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); - }elseif($mime == 'application/x-shockwave-flash' && $render){ - // don't link flash movies + }elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render){ + // don't link movies $noLink = true; }else{ // add file icons @@ -812,8 +824,13 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } //output formatted - if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; - else $this->doc .= $this->_formatLink($link); + if ($return) { + if ($linking == 'nolink' || $noLink) return $link['name']; + else return $this->_formatLink($link); + } else { + if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; + else $this->doc .= $this->_formatLink($link); + } } function externalmedia ($src, $title=null, $align=null, $width=null, @@ -829,8 +846,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer { if(substr($mime,0,5) == 'image' && $render){ // link only jpeg images // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; - }elseif($mime == 'application/x-shockwave-flash' && $render){ - // don't link flash movies + }elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render){ + // don't link movies $noLink = true; }else{ // add file icons @@ -946,6 +963,14 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } } + function tablethead_open(){ + $this->doc .= DOKU_TAB . '<thead>' . DOKU_LF; + } + + function tablethead_close(){ + $this->doc .= DOKU_TAB . '</thead>' . DOKU_LF; + } + function tablerow_open(){ // initialize the cell counter used for classes $this->_counter['cell_counter'] = 0; @@ -1091,6 +1116,30 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $ret .= ' />'; + }elseif(media_supportedav($mime, 'video') || media_supportedav($mime, 'audio')){ + // first get the $title + $title = !is_null($title) ? $this->_xmlEntities($title) : false; + if (!$render) { + // if the file is not supposed to be rendered + // return the title of the file (just the sourcename if there is no title) + return $title ? $title : $this->_xmlEntities(utf8_basename(noNS($src))); + } + + $att = array(); + $att['class'] = "media$align"; + if ($title) { + $att['title'] = $title; + } + + if (media_supportedav($mime, 'video')) { + //add video + $ret .= $this->_video($src, $width, $height, $att); + } + if (media_supportedav($mime, 'audio')) { + //add audio + $ret .= $this->_audio($src, $att); + } + }elseif($mime == 'application/x-shockwave-flash'){ if (!$render) { // if the flash is not supposed to be rendered @@ -1223,6 +1272,93 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } + /** + * Embed video(s) in HTML + * + * @author Anika Henke <anika@selfthinker.org> + * + * @param string $src - ID of video to embed + * @param int $width - width of the video in pixels + * @param int $height - height of the video in pixels + * @param array $atts - additional attributes for the <video> tag + * @return string + */ + function _video($src,$width,$height,$atts=null){ + // prepare width and height + if(is_null($atts)) $atts = array(); + $atts['width'] = (int) $width; + $atts['height'] = (int) $height; + if(!$atts['width']) $atts['width'] = 320; + if(!$atts['height']) $atts['height'] = 240; + + // prepare alternative formats + $extensions = array('webm', 'ogv', 'mp4'); + $alternatives = media_alternativefiles($src, $extensions); + $poster = media_alternativefiles($src, array('jpg', 'png'), true); + $posterUrl = ''; + if (!empty($poster)) { + $posterUrl = ml(reset($poster),array('cache'=>$cache),true,'&'); + } + + $out = ''; + // open video tag + $out .= '<video '.buildAttributes($atts).' controls="controls"'; + if ($posterUrl) $out .= ' poster="'.hsc($posterUrl).'"'; + $out .= '>'.NL; + $fallback = ''; + + // output source for each alternative video format + foreach($alternatives as $mime => $file) { + $url = ml($file,array('cache'=>$cache),true,'&'); + $title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(utf8_basename(noNS($file))); + + $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL; + // alternative content (just a link to the file) + $fallback .= $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly', $return=true); + } + + // finish + $out .= $fallback; + $out .= '</video>'.NL; + return $out; + } + + /** + * Embed audio in HTML + * + * @author Anika Henke <anika@selfthinker.org> + * + * @param string $src - ID of audio to embed + * @param array $atts - additional attributes for the <audio> tag + * @return string + */ + function _audio($src,$atts=null){ + + // prepare alternative formats + $extensions = array('ogg', 'mp3', 'wav'); + $alternatives = media_alternativefiles($src, $extensions); + + $out = ''; + // open audio tag + $out .= '<audio '.buildAttributes($atts).' controls="controls">'.NL; + $fallback = ''; + + // output source for each alternative audio format + foreach($alternatives as $mime => $file) { + $url = ml($file,array('cache'=>$cache),true,'&'); + $title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(utf8_basename(noNS($file))); + + $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL; + // alternative content (just a link to the file) + $fallback .= $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly', $return=true); + } + + // finish + $out .= $fallback; + $out .= '</audio>'.NL; + return $out; + } + } //Setup VIM: ex: et ts=4 : diff --git a/inc/parser/xhtmlsummary.php b/inc/parser/xhtmlsummary.php index 95f86cbef..867b71f6a 100644 --- a/inc/parser/xhtmlsummary.php +++ b/inc/parser/xhtmlsummary.php @@ -1,6 +1,5 @@ <?php if(!defined('DOKU_INC')) die('meh.'); -require_once DOKU_INC . 'inc/parser/xhtml.php'; /** * The summary XHTML form selects either up to the first two paragraphs |