From f05a1cc5fcdb4c2b6ee3cbf499f980f800dbd105 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Thu, 17 Oct 2013 23:11:33 +0200 Subject: Wrap thead around 1st row, when 1st cell at 1st row is tableheader. Implements FS#1764 --- inc/parser/handler.php | 19 +++++++++++++++++-- inc/parser/renderer.php | 4 ++++ inc/parser/xhtml.php | 8 ++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 1de981b48..55f344994 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -1278,6 +1278,7 @@ class Doku_Handler_Table { $lastRow = 0; $lastCell = 0; + $isThead = false; $cellKey = array(); $toDelete = array(); @@ -1292,6 +1293,14 @@ class Doku_Handler_Table { $lastRow++; $lastCell = 0; + + if($lastRow === 1 && $this->tableCalls[$key+1][0] == 'tableheader_open') { + $isThead = true; + + array_splice($this->tableCalls, $key, 0, array( + array('tablethead_open', array(), $call[2]))); + $key += 1; + } break; case 'tablecell_open': @@ -1396,6 +1405,12 @@ class Doku_Handler_Table { $key += 3; } + if($isThead) { + array_splice($this->tableCalls, $key+1, 0, array( + array('tablethead_close', array(), $call[2]))); + + $isThead = false; + } break; } @@ -1437,7 +1452,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', @@ -1447,7 +1462,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/renderer.php b/inc/parser/renderer.php index c697e990c..ee0b2344d 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -245,6 +245,10 @@ class Doku_Renderer extends DokuWiki_Plugin { function table_close($pos = null){} + function tablethead_open(){} + + function tablethead_close(){} + function tablerow_open(){} function tablerow_close(){} diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index fd02c0ce0..e9f2cc037 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -946,6 +946,14 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } } + function tablethead_open(){ + $this->doc .= DOKU_TAB . '' . DOKU_LF; + } + + function tablethead_close(){ + $this->doc .= DOKU_TAB . '' . DOKU_LF; + } + function tablerow_open(){ // initialize the cell counter used for classes $this->_counter['cell_counter'] = 0; -- cgit v1.2.3 From 9060b8b02222ada7d08f4f6b77b4dd1e125fe5a2 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Fri, 18 Oct 2013 14:34:55 +0100 Subject: add to top rows of tables when all cells are --- inc/parser/handler.php | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 55f344994..196cafc57 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -1149,6 +1149,8 @@ class Doku_Handler_Table { var $currentCols = 0; var $firstCell = false; var $lastCellType = 'tablecell'; + var $inTableHead = true; + var $countTableHeadRows = 0; function Doku_Handler_Table(& $CallWriter) { $this->CallWriter = & $CallWriter; @@ -1219,6 +1221,9 @@ class Doku_Handler_Table { } function tableRowClose($call) { + if ($this->inTableHead) { + $this->countTableHeadRows++; + } // Strip off final cell opening and anything after it while ( $discard = array_pop($this->tableCalls ) ) { @@ -1234,6 +1239,9 @@ class Doku_Handler_Table { } function tableCell($call) { + if ($call[0] != 'tableheader') { + $this->inTableHead = false; + } if ( !$this->firstCell ) { // Increase the span @@ -1278,7 +1286,6 @@ class Doku_Handler_Table { $lastRow = 0; $lastCell = 0; - $isThead = false; $cellKey = array(); $toDelete = array(); @@ -1289,18 +1296,18 @@ 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++; $lastCell = 0; - - if($lastRow === 1 && $this->tableCalls[$key+1][0] == 'tableheader_open') { - $isThead = true; - - array_splice($this->tableCalls, $key, 0, array( - array('tablethead_open', array(), $call[2]))); - $key += 1; - } break; case 'tablecell_open': @@ -1366,15 +1373,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)) { @@ -1405,11 +1416,9 @@ class Doku_Handler_Table { $key += 3; } - if($isThead) { + if($this->countTableHeadRows == $lastRow) { array_splice($this->tableCalls, $key+1, 0, array( array('tablethead_close', array(), $call[2]))); - - $isThead = false; } break; -- cgit v1.2.3 From e950d12fe605bb70cca7a030eab49f5e29719f0b Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Thu, 13 Mar 2014 17:55:21 +0000 Subject: improvements to double quote matching --- inc/parser/handler.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'inc/parser') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 8ae991209..dfaf1adaa 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; } -- cgit v1.2.3 From cef031c123914a2d88f125a8363c0917011e8ed0 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Thu, 13 Mar 2014 17:52:03 +0000 Subject: implement rules for when the top rows of a table qualify for a THEAD element 1. TD < 2 in a row 2. TD <= 50% of total cells 3. Not all table rows can be THEAD rows --- inc/parser/handler.php | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index c4104dac9..d8382e7fc 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -1150,6 +1150,7 @@ class Doku_Handler_Table { var $firstCell = false; var $lastCellType = 'tablecell'; var $inTableHead = true; + var $currentRow = array('tableheader' => 0, 'tablecell' => 0); var $countTableHeadRows = 0; function Doku_Handler_Table(& $CallWriter) { @@ -1218,10 +1219,13 @@ 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) { + if ($this->inTableHead && ($this->inTableHead = $this->isTableHeadRow())) { $this->countTableHeadRows++; } // Strip off final cell opening and anything after it @@ -1230,6 +1234,9 @@ class Doku_Handler_Table { 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]); @@ -1238,9 +1245,19 @@ 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 ($call[0] != 'tableheader') { - $this->inTableHead = false; + if ($this->inTableHead) { + $this->currentRow[$call[0]]++; } if ( !$this->firstCell ) { @@ -1289,6 +1306,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 + 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 -- cgit v1.2.3 From 2d338eab8c1f980abd8a8ee35b068b84750867a0 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 24 May 2014 11:18:08 +0200 Subject: removed unset $cache parameter in _audio _video #698 --- inc/parser/xhtml.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index cf36a8175..e4afb9eb8 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -1297,7 +1297,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $poster = media_alternativefiles($src, array('jpg', 'png'), true); $posterUrl = ''; if (!empty($poster)) { - $posterUrl = ml(reset($poster),array('cache'=>$cache),true,'&'); + $posterUrl = ml(reset($poster),'',true,'&'); } $out = ''; @@ -1309,7 +1309,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // output source for each alternative video format foreach($alternatives as $mime => $file) { - $url = ml($file,array('cache'=>$cache),true,'&'); + $url = ml($file,'',true,'&'); $title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(utf8_basename(noNS($file))); $out .= ''.NL; @@ -1345,7 +1345,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // output source for each alternative audio format foreach($alternatives as $mime => $file) { - $url = ml($file,array('cache'=>$cache),true,'&'); + $url = ml($file,'',true,'&'); $title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(utf8_basename(noNS($file))); $out .= ''.NL; -- cgit v1.2.3 From 2c2835c2888035a0b3b1fd8b096a962a0a5c40b5 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 24 May 2014 11:23:52 +0200 Subject: reformatting --- inc/parser/renderer.php | 285 +++++++++++++++++++++++++++++++----------------- 1 file changed, 182 insertions(+), 103 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index e92b81bd7..71eeda952 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -44,7 +44,7 @@ class Doku_Renderer extends DokuWiki_Plugin { * * Has to be overidden by decendend classes */ - function getFormat(){ + function getFormat() { trigger_error('getFormat() not implemented in '.get_class($this), E_USER_WARNING); } @@ -60,15 +60,15 @@ class Doku_Renderer extends DokuWiki_Plugin { /** * handle plugin rendering * - * @param string $name Plugin name - * @param mixed $data custom data set by handler + * @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); + function plugin($name, $data, $state = '', $match = '') { + $plugin = plugin_load('syntax', $name); + if($plugin != null) { + $plugin->render($this->getFormat(), $this, $data); } } @@ -78,9 +78,9 @@ class Doku_Renderer extends DokuWiki_Plugin { */ function nest($instructions) { - foreach ( $instructions as $instruction ) { + foreach($instructions as $instruction) { // execute the callback against ourself - if (method_exists($this,$instruction[0])) { + if(method_exists($this, $instruction[0])) { call_user_func_array(array($this, $instruction[0]), $instruction[1] ? $instruction[1] : array()); } } @@ -89,186 +89,265 @@ class Doku_Renderer extends DokuWiki_Plugin { // dummy closing instruction issued by Doku_Handler_Nest, normally the syntax mode should // override this instruction when instantiating Doku_Handler_Nest - however plugins will not // be able to - as their instructions require data. - function nest_close() {} + function nest_close() { + } - function document_start() {} + function document_start() { + } - function document_end() {} + function document_end() { + } - function render_TOC() { return ''; } + function render_TOC() { + return ''; + } - function toc_additem($id, $text, $level) {} + function toc_additem($id, $text, $level) { + } - function header($text, $level, $pos) {} + function header($text, $level, $pos) { + } - function section_open($level) {} + function section_open($level) { + } - function section_close() {} + function section_close() { + } - function cdata($text) {} + function cdata($text) { + } - function p_open() {} + function p_open() { + } - function p_close() {} + function p_close() { + } - function linebreak() {} + function linebreak() { + } - function hr() {} + function hr() { + } - function strong_open() {} + function strong_open() { + } - function strong_close() {} + function strong_close() { + } - function emphasis_open() {} + function emphasis_open() { + } - function emphasis_close() {} + function emphasis_close() { + } - function underline_open() {} + function underline_open() { + } - function underline_close() {} + function underline_close() { + } - function monospace_open() {} + function monospace_open() { + } - function monospace_close() {} + function monospace_close() { + } - function subscript_open() {} + function subscript_open() { + } - function subscript_close() {} + function subscript_close() { + } - function superscript_open() {} + function superscript_open() { + } - function superscript_close() {} + function superscript_close() { + } - function deleted_open() {} + function deleted_open() { + } - function deleted_close() {} + function deleted_close() { + } - function footnote_open() {} + function footnote_open() { + } - function footnote_close() {} + function footnote_close() { + } - function listu_open() {} + function listu_open() { + } - function listu_close() {} + function listu_close() { + } - function listo_open() {} + function listo_open() { + } - function listo_close() {} + function listo_close() { + } - function listitem_open($level) {} + function listitem_open($level) { + } - function listitem_close() {} + function listitem_close() { + } - function listcontent_open() {} + function listcontent_open() { + } - function listcontent_close() {} + function listcontent_close() { + } - function unformatted($text) {} + function unformatted($text) { + } - function php($text) {} + function php($text) { + } - function phpblock($text) {} + function phpblock($text) { + } - function html($text) {} + function html($text) { + } - function htmlblock($text) {} + function htmlblock($text) { + } - function preformatted($text) {} + function preformatted($text) { + } - function quote_open() {} + function quote_open() { + } - function quote_close() {} + function quote_close() { + } - function file($text, $lang = null, $file = null ) {} + function file($text, $lang = null, $file = null) { + } - function code($text, $lang = null, $file = null ) {} + function code($text, $lang = null, $file = null) { + } - function acronym($acronym) {} + function acronym($acronym) { + } - function smiley($smiley) {} + function smiley($smiley) { + } - function wordblock($word) {} + function wordblock($word) { + } - function entity($entity) {} + function entity($entity) { + } // 640x480 ($x=640, $y=480) - function multiplyentity($x, $y) {} + function multiplyentity($x, $y) { + } - function singlequoteopening() {} + function singlequoteopening() { + } - function singlequoteclosing() {} + function singlequoteclosing() { + } - function apostrophe() {} + function apostrophe() { + } - function doublequoteopening() {} + function doublequoteopening() { + } - function doublequoteclosing() {} + function doublequoteclosing() { + } // $link like 'SomePage' - function camelcaselink($link) {} + function camelcaselink($link) { + } - function locallink($hash, $name = null) {} + function locallink($hash, $name = null) { + } // $link like 'wiki:syntax', $title could be an array (media) - function internallink($link, $title = null) {} + function internallink($link, $title = null) { + } // $link is full URL with scheme, $title could be an array (media) - function externallink($link, $title = null) {} + function externallink($link, $title = null) { + } - function rss ($url,$params) {} + function rss($url, $params) { + } // $link is the original link - probably not much use // $wikiName is an indentifier for the wiki // $wikiUri is the URL fragment to append to some known URL - function interwikilink($link, $title = null, $wikiName, $wikiUri) {} + function interwikilink($link, $title = null, $wikiName, $wikiUri) { + } // Link to file on users OS, $title could be an array (media) - function filelink($link, $title = null) {} + function filelink($link, $title = null) { + } // Link to a Windows share, , $title could be an array (media) - function windowssharelink($link, $title = null) {} + function windowssharelink($link, $title = null) { + } // function email($address, $title = null) {} - function emaillink($address, $name = null) {} + function emaillink($address, $name = null) { + } - function internalmedia ($src, $title=null, $align=null, $width=null, - $height=null, $cache=null, $linking=null) {} + function internalmedia($src, $title = null, $align = null, $width = null, + $height = null, $cache = null, $linking = null) { + } - function externalmedia ($src, $title=null, $align=null, $width=null, - $height=null, $cache=null, $linking=null) {} + function externalmedia($src, $title = null, $align = null, $width = null, + $height = null, $cache = null, $linking = null) { + } - function internalmedialink ( - $src,$title=null,$align=null,$width=null,$height=null,$cache=null - ) {} + function internalmedialink( + $src, $title = null, $align = null, $width = null, $height = null, $cache = null + ) { + } function externalmedialink( - $src,$title=null,$align=null,$width=null,$height=null,$cache=null - ) {} - - function table_open($maxcols = null, $numrows = null, $pos = null){} + $src, $title = null, $align = null, $width = null, $height = null, $cache = null + ) { + } - function table_close($pos = null){} + function table_open($maxcols = null, $numrows = null, $pos = null) { + } - function tablethead_open(){} + function table_close($pos = null) { + } - function tablethead_close(){} + function tablethead_open() { + } - function tablerow_open(){} + function tablethead_close() { + } - function tablerow_close(){} + function tablerow_open() { + } - function tableheader_open($colspan = 1, $align = null, $rowspan = 1){} + function tablerow_close() { + } - function tableheader_close(){} + function tableheader_open($colspan = 1, $align = null, $rowspan = 1) { + } - function tablecell_open($colspan = 1, $align = null, $rowspan = 1){} + function tableheader_close() { + } - function tablecell_close(){} + function tablecell_open($colspan = 1, $align = null, $rowspan = 1) { + } + function tablecell_close() { + } // util functions follow, you probably won't need to reimplement them - /** * Removes any Namespace from the given name but keeps * casing and special chars @@ -294,13 +373,13 @@ class Doku_Renderer extends DokuWiki_Plugin { /** * Resolve an interwikilink */ - function _resolveInterWiki(&$shortcut, $reference, &$exists=null) { + function _resolveInterWiki(&$shortcut, $reference, &$exists = null) { //get interwiki URL if(isset($this->interwiki[$shortcut])) { $url = $this->interwiki[$shortcut]; } else { // Default to Google I'm feeling lucky - $url = 'http://www.google.com/search?q={URL}&btnI=lucky'; + $url = 'http://www.google.com/search?q={URL}&btnI=lucky'; $shortcut = 'go'; } @@ -310,8 +389,8 @@ class Doku_Renderer extends DokuWiki_Plugin { //replace placeholder 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); @@ -321,15 +400,15 @@ class Doku_Renderer extends DokuWiki_Plugin { $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); + $url = wl(cleanID($id), $urlparam); $exists = page_exists($id); } - if($hash) $url .= '#' . rawurlencode($hash); + if($hash) $url .= '#'.rawurlencode($hash); return $url; } -- cgit v1.2.3 From 7783971742e69fbd5ad26b0daf75bd4a3043aff0 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 24 May 2014 13:59:49 +0200 Subject: more reformatting --- inc/parser/code.php | 12 +- inc/parser/metadata.php | 286 ++++++++++++++++++++++++------------------------ 2 files changed, 152 insertions(+), 146 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/code.php b/inc/parser/code.php index d77ffd1aa..00b956c27 100644 --- a/inc/parser/code.php +++ b/inc/parser/code.php @@ -7,25 +7,25 @@ if(!defined('DOKU_INC')) die('meh.'); class Doku_Renderer_code extends Doku_Renderer { - var $_codeblock=0; + var $_codeblock = 0; /** * Send the wanted code block to the browser * * When the correct block was found it exits the script. */ - function code($text, $language = null, $filename='' ) { + function code($text, $language = null, $filename = '') { global $INPUT; if(!$language) $language = 'txt'; if(!$filename) $filename = 'snippet.'.$language; $filename = utf8_basename($filename); $filename = utf8_stripspecials($filename, '_'); - if($this->_codeblock == $INPUT->str('codeblock')){ + if($this->_codeblock == $INPUT->str('codeblock')) { header("Content-Type: text/plain; charset=utf-8"); header("Content-Disposition: attachment; filename=$filename"); header("X-Robots-Tag: noindex"); - echo trim($text,"\r\n"); + echo trim($text, "\r\n"); exit; } @@ -35,7 +35,7 @@ class Doku_Renderer_code extends Doku_Renderer { /** * Wraps around code() */ - function file($text, $language = null, $filename='') { + function file($text, $language = null, $filename = '') { $this->code($text, $language, $filename); } @@ -53,7 +53,7 @@ class Doku_Renderer_code extends Doku_Renderer { * * @returns string 'code' */ - function getFormat(){ + function getFormat() { return 'code'; } } diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index 82a268fd6..e19aa602a 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -6,14 +6,14 @@ */ if(!defined('DOKU_INC')) die('meh.'); -if ( !defined('DOKU_LF') ) { +if(!defined('DOKU_LF')) { // Some whitespace to help View > Source - define ('DOKU_LF',"\n"); + define ('DOKU_LF', "\n"); } -if ( !defined('DOKU_TAB') ) { +if(!defined('DOKU_TAB')) { // Some whitespace to help View > Source - define ('DOKU_TAB',"\t"); + define ('DOKU_TAB', "\t"); } /** @@ -21,55 +21,55 @@ if ( !defined('DOKU_TAB') ) { */ class Doku_Renderer_metadata extends Doku_Renderer { - var $doc = ''; + var $doc = ''; var $meta = array(); var $persistent = array(); var $headers = array(); var $capture = true; - var $store = ''; + var $store = ''; var $firstimage = ''; - function getFormat(){ + function getFormat() { return 'metadata'; } - function document_start(){ + function document_start() { global $ID; $this->headers = array(); // external pages are missing create date - if(!$this->persistent['date']['created']){ + if(!$this->persistent['date']['created']) { $this->persistent['date']['created'] = filectime(wikiFN($ID)); } - if(!isset($this->persistent['user'])){ + if(!isset($this->persistent['user'])) { $this->persistent['user'] = ''; } - if(!isset($this->persistent['creator'])){ + if(!isset($this->persistent['creator'])) { $this->persistent['creator'] = ''; } // reset metadata to persistent values $this->meta = $this->persistent; } - function document_end(){ + function document_end() { global $ID; // store internal info in metadata (notoc,nocache) $this->meta['internal'] = $this->info; - if (!isset($this->meta['description']['abstract'])){ + if(!isset($this->meta['description']['abstract'])) { // cut off too long abstracts $this->doc = trim($this->doc); - if (strlen($this->doc) > 500) + if(strlen($this->doc) > 500) $this->doc = utf8_substr($this->doc, 0, 500).'…'; $this->meta['description']['abstract'] = $this->doc; } $this->meta['relation']['firstimage'] = $this->firstimage; - if(!isset($this->meta['date']['modified'])){ + if(!isset($this->meta['date']['modified'])) { $this->meta['date']['modified'] = filemtime(wikiFN($ID)); } @@ -79,54 +79,57 @@ class Doku_Renderer_metadata extends Doku_Renderer { global $conf; //only add items within configured levels - if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){ + if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']) { // the TOC is one of our standard ul list arrays ;-) $this->meta['description']['tableofcontents'][] = array( - 'hid' => $id, - 'title' => $text, - 'type' => 'ul', - 'level' => $level-$conf['toptoclevel']+1 + 'hid' => $id, + 'title' => $text, + 'type' => 'ul', + 'level' => $level - $conf['toptoclevel'] + 1 ); } } function header($text, $level, $pos) { - if (!isset($this->meta['title'])) $this->meta['title'] = $text; + if(!isset($this->meta['title'])) $this->meta['title'] = $text; // add the header to the TOC - $hid = $this->_headerToLink($text,'true'); + $hid = $this->_headerToLink($text, 'true'); $this->toc_additem($hid, $text, $level); // add to summary - if ($this->capture && ($level > 1)) $this->doc .= DOKU_LF.$text.DOKU_LF; + if($this->capture && ($level > 1)) $this->doc .= DOKU_LF.$text.DOKU_LF; } - function section_open($level){} - function section_close(){} + function section_open($level) { + } + + function section_close() { + } - function cdata($text){ - if ($this->capture) $this->doc .= $text; + function cdata($text) { + if($this->capture) $this->doc .= $text; } - function p_open(){ - if ($this->capture) $this->doc .= DOKU_LF; + function p_open() { + if($this->capture) $this->doc .= DOKU_LF; } - function p_close(){ - if ($this->capture){ - if (strlen($this->doc) > 250) $this->capture = false; + function p_close() { + if($this->capture) { + if(strlen($this->doc) > 250) $this->capture = false; else $this->doc .= DOKU_LF; } } - function linebreak(){ - if ($this->capture) $this->doc .= DOKU_LF; + function linebreak() { + if($this->capture) $this->doc .= DOKU_LF; } - function hr(){ - if ($this->capture){ - if (strlen($this->doc) > 250) $this->capture = false; + function hr() { + if($this->capture) { + if(strlen($this->doc) > 250) $this->capture = false; else $this->doc .= DOKU_LF.'----------'.DOKU_LF; } } @@ -141,7 +144,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { * @author Andreas Gohr */ function footnote_open() { - if ($this->capture){ + if($this->capture) { // move current content to store and record footnote $this->store = $this->doc; $this->doc = ''; @@ -157,141 +160,144 @@ class Doku_Renderer_metadata extends Doku_Renderer { * @author Andreas Gohr */ function footnote_close() { - if ($this->capture){ + if($this->capture) { // restore old content - $this->doc = $this->store; + $this->doc = $this->store; $this->store = ''; } } - function listu_open(){ - if ($this->capture) $this->doc .= DOKU_LF; + function listu_open() { + if($this->capture) $this->doc .= DOKU_LF; } - function listu_close(){ - if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false; + function listu_close() { + if($this->capture && (strlen($this->doc) > 250)) $this->capture = false; } - function listo_open(){ - if ($this->capture) $this->doc .= DOKU_LF; + function listo_open() { + if($this->capture) $this->doc .= DOKU_LF; } - function listo_close(){ - if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false; + function listo_close() { + if($this->capture && (strlen($this->doc) > 250)) $this->capture = false; } - function listitem_open($level){ - if ($this->capture) $this->doc .= str_repeat(DOKU_TAB, $level).'* '; + function listitem_open($level) { + if($this->capture) $this->doc .= str_repeat(DOKU_TAB, $level).'* '; } - function listitem_close(){ - if ($this->capture) $this->doc .= DOKU_LF; + function listitem_close() { + if($this->capture) $this->doc .= DOKU_LF; } - function listcontent_open(){} - function listcontent_close(){} + function listcontent_open() { + } - function unformatted($text){ - if ($this->capture) $this->doc .= $text; + function listcontent_close() { } - function preformatted($text){ - if ($this->capture) $this->doc .= $text; + function unformatted($text) { + if($this->capture) $this->doc .= $text; } - function file($text, $lang = null, $file = null){ - if ($this->capture){ + function preformatted($text) { + if($this->capture) $this->doc .= $text; + } + + function file($text, $lang = null, $file = null) { + if($this->capture) { $this->doc .= DOKU_LF.$text; - if (strlen($this->doc) > 250) $this->capture = false; + if(strlen($this->doc) > 250) $this->capture = false; else $this->doc .= DOKU_LF; } } - function quote_open(){ - if ($this->capture) $this->doc .= DOKU_LF.DOKU_TAB.'"'; + function quote_open() { + if($this->capture) $this->doc .= DOKU_LF.DOKU_TAB.'"'; } - function quote_close(){ - if ($this->capture){ + function quote_close() { + if($this->capture) { $this->doc .= '"'; - if (strlen($this->doc) > 250) $this->capture = false; + if(strlen($this->doc) > 250) $this->capture = false; else $this->doc .= DOKU_LF; } } - function code($text, $language = null, $file = null){ - if ($this->capture){ + function code($text, $language = null, $file = null) { + if($this->capture) { $this->doc .= DOKU_LF.$text; - if (strlen($this->doc) > 250) $this->capture = false; + if(strlen($this->doc) > 250) $this->capture = false; else $this->doc .= DOKU_LF; - } + } } - function acronym($acronym){ - if ($this->capture) $this->doc .= $acronym; + function acronym($acronym) { + if($this->capture) $this->doc .= $acronym; } - function smiley($smiley){ - if ($this->capture) $this->doc .= $smiley; + function smiley($smiley) { + if($this->capture) $this->doc .= $smiley; } - function entity($entity){ - if ($this->capture) $this->doc .= $entity; + function entity($entity) { + if($this->capture) $this->doc .= $entity; } - function multiplyentity($x, $y){ - if ($this->capture) $this->doc .= $x.'×'.$y; + function multiplyentity($x, $y) { + if($this->capture) $this->doc .= $x.'×'.$y; } - function singlequoteopening(){ + function singlequoteopening() { global $lang; - if ($this->capture) $this->doc .= $lang['singlequoteopening']; + if($this->capture) $this->doc .= $lang['singlequoteopening']; } - function singlequoteclosing(){ + function singlequoteclosing() { global $lang; - if ($this->capture) $this->doc .= $lang['singlequoteclosing']; + if($this->capture) $this->doc .= $lang['singlequoteclosing']; } function apostrophe() { global $lang; - if ($this->capture) $this->doc .= $lang['apostrophe']; + if($this->capture) $this->doc .= $lang['apostrophe']; } - function doublequoteopening(){ + function doublequoteopening() { global $lang; - if ($this->capture) $this->doc .= $lang['doublequoteopening']; + if($this->capture) $this->doc .= $lang['doublequoteopening']; } - function doublequoteclosing(){ + function doublequoteclosing() { global $lang; - if ($this->capture) $this->doc .= $lang['doublequoteclosing']; + if($this->capture) $this->doc .= $lang['doublequoteclosing']; } function camelcaselink($link) { $this->internallink($link, $link); } - function locallink($hash, $name = null){ + function locallink($hash, $name = null) { if(is_array($name)) { $this->_firstimage($name['src']); - if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + if($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); } } /** * keep track of internal links in $this->meta['relation']['references'] */ - function internallink($id, $name = null){ + function internallink($id, $name = null) { global $ID; if(is_array($name)) { $this->_firstimage($name['src']); - if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + if($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); } $parts = explode('?', $id, 2); - if (count($parts) === 2) { + if(count($parts) === 2) { $id = $parts[0]; } @@ -307,80 +313,80 @@ class Doku_Renderer_metadata extends Doku_Renderer { // p_set_metadata($id, $data); // add link title to summary - if ($this->capture){ + if($this->capture) { $name = $this->_getLinkTitle($name, $default, $id); $this->doc .= $name; } } - function externallink($url, $name = null){ + function externallink($url, $name = null) { if(is_array($name)) { $this->_firstimage($name['src']); - if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + if($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); } - if ($this->capture){ - $this->doc .= $this->_getLinkTitle($name, '<' . $url . '>'); + if($this->capture) { + $this->doc .= $this->_getLinkTitle($name, '<'.$url.'>'); } } - function interwikilink($match, $name = null, $wikiName, $wikiUri){ + function interwikilink($match, $name = null, $wikiName, $wikiUri) { if(is_array($name)) { $this->_firstimage($name['src']); - if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + if($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); } - if ($this->capture){ + if($this->capture) { list($wikiUri, $hash) = explode('#', $wikiUri, 2); $name = $this->_getLinkTitle($name, $wikiUri); $this->doc .= $name; } } - function windowssharelink($url, $name = null){ + function windowssharelink($url, $name = null) { if(is_array($name)) { $this->_firstimage($name['src']); - if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + if($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); } - if ($this->capture){ - if ($name) $this->doc .= $name; + if($this->capture) { + if($name) $this->doc .= $name; else $this->doc .= '<'.$url.'>'; } } - function emaillink($address, $name = null){ + function emaillink($address, $name = null) { if(is_array($name)) { $this->_firstimage($name['src']); - if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + if($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); } - if ($this->capture){ - if ($name) $this->doc .= $name; + if($this->capture) { + if($name) $this->doc .= $name; else $this->doc .= '<'.$address.'>'; } } - function internalmedia($src, $title=null, $align=null, $width=null, - $height=null, $cache=null, $linking=null){ - if ($this->capture && $title) $this->doc .= '['.$title.']'; + function internalmedia($src, $title = null, $align = null, $width = null, + $height = null, $cache = null, $linking = null) { + if($this->capture && $title) $this->doc .= '['.$title.']'; $this->_firstimage($src); $this->_recordMediaUsage($src); } - function externalmedia($src, $title=null, $align=null, $width=null, - $height=null, $cache=null, $linking=null){ - if ($this->capture && $title) $this->doc .= '['.$title.']'; + function externalmedia($src, $title = null, $align = null, $width = null, + $height = null, $cache = null, $linking = null) { + if($this->capture && $title) $this->doc .= '['.$title.']'; $this->_firstimage($src); } - function rss($url,$params) { + function rss($url, $params) { $this->meta['relation']['haspart'][$url] = true; $this->meta['date']['valid']['age'] = - isset($this->meta['date']['valid']['age']) ? - min($this->meta['date']['valid']['age'],$params['refresh']) : - $params['refresh']; + isset($this->meta['date']['valid']['age']) ? + min($this->meta['date']['valid']['age'], $params['refresh']) : + $params['refresh']; } //---------------------------------------------------------- @@ -392,19 +398,19 @@ class Doku_Renderer_metadata extends Doku_Renderer { * * @author Andreas Gohr */ - function _simpleTitle($name){ + function _simpleTitle($name) { global $conf; if(is_array($name)) return ''; - if($conf['useslash']){ + if($conf['useslash']) { $nssep = '[:;/]'; - }else{ + } else { $nssep = '[:;]'; } - $name = preg_replace('!.*'.$nssep.'!','',$name); + $name = preg_replace('!.*'.$nssep.'!', '', $name); //if there is a hash we use the anchor name only - $name = preg_replace('!.*#!','',$name); + $name = preg_replace('!.*#!', '', $name); return $name; } @@ -415,12 +421,12 @@ class Doku_Renderer_metadata extends Doku_Renderer { * @param boolean $create Create a new unique ID? * @author Andreas Gohr */ - function _headerToLink($title, $create=false) { - if($create){ - return sectionID($title,$this->headers); - }else{ + function _headerToLink($title, $create = false) { + if($create) { + return sectionID($title, $this->headers); + } else { $check = false; - return sectionID($title,$check); + return sectionID($title, $check); } } @@ -429,16 +435,16 @@ class Doku_Renderer_metadata extends Doku_Renderer { * * @author Harry Fuecks */ - function _getLinkTitle($title, $default, $id=null) { + function _getLinkTitle($title, $default, $id = null) { global $conf; $isImage = false; - if (is_array($title)){ + if(is_array($title)) { if($title['title']) return '['.$title['title'].']'; - } else if (is_null($title) || trim($title)==''){ - if (useHeading('content') && $id){ - $heading = p_get_first_heading($id,METADATA_DONT_RENDER); - if ($heading) return $heading; + } else if(is_null($title) || trim($title) == '') { + if(useHeading('content') && $id) { + $heading = p_get_first_heading($id, METADATA_DONT_RENDER); + if($heading) return $heading; } return $default; } else { @@ -446,15 +452,15 @@ class Doku_Renderer_metadata extends Doku_Renderer { } } - function _firstimage($src){ + function _firstimage($src) { if($this->firstimage) return; global $ID; - list($src,$hash) = explode('#',$src,2); - if(!media_isexternal($src)){ - resolve_mediaid(getNS($ID),$src, $exists); + list($src, $hash) = explode('#', $src, 2); + if(!media_isexternal($src)) { + resolve_mediaid(getNS($ID), $src, $exists); } - if(preg_match('/.(jpe?g|gif|png)$/i',$src)){ + if(preg_match('/.(jpe?g|gif|png)$/i', $src)) { $this->firstimage = $src; } } @@ -463,7 +469,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { global $ID; list ($src, $hash) = explode('#', $src, 2); - if (media_isexternal($src)) return; + if(media_isexternal($src)) return; resolve_mediaid(getNS($ID), $src, $exists); $this->meta['relation']['media'][$src] = $exists; } -- cgit v1.2.3 From cfa2b40e6bb053ff32af7199e4177fbbb92b0a57 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 24 May 2014 14:00:43 +0200 Subject: added doc blocks to all functions in renderer --- inc/parser/renderer.php | 492 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 447 insertions(+), 45 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index 71eeda952..a486ed106 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -13,52 +13,79 @@ if(!defined('DOKU_INC')) die('meh.'); * Inherits from DokuWiki_Plugin for giving additional functions to render plugins */ class Doku_Renderer extends DokuWiki_Plugin { - var $info = array( + /** @var array Settings, control the behavior of the renderer */ + public $info = array( 'cache' => true, // may the rendered result cached? 'toc' => true, // render the TOC? ); - var $doc = ''; + /** @var array contains the smiley configuration, set in p_render() */ + public $smileys = array(); + /** @var array contains the entity configuration, set in p_render() */ + public $entities = array(); + /** @var array contains the acronym configuration, set in p_render() */ + public $acronyms = array(); + /** @var array contains the interwiki configuration, set in p_render() */ + public $interwiki = array(); - // keep some config options - var $acronyms = array(); - var $smileys = array(); - var $badwords = array(); - var $entities = array(); - var $interwiki = array(); + /** + * @var string the rendered document, this will be cached after the renderer ran through + */ + public $doc = ''; - // allows renderer to be used again, clean out any per-use values + /** + * clean out any per-use values + * + * This is called before each use of the renderer object and should be used to + * completely reset the state of the renderer to be reused for a new document + */ function reset() { } - function nocache() { - $this->info['cache'] = false; - } - - function notoc() { - $this->info['toc'] = false; + /** + * Allow the plugin to prevent DokuWiki from reusing an instance + * + * Since most renderer plugins fail to implement Doku_Renderer::reset() we default + * to reinstantiating the renderer here + * + * @return bool false if the plugin has to be instantiated + */ + function isSingleton() { + return false; } /** * Returns the format produced by this renderer. * - * Has to be overidden by decendend classes + * Has to be overidden by sub classes + * + * @return string */ function getFormat() { trigger_error('getFormat() not implemented in '.get_class($this), E_USER_WARNING); + return ''; } /** - * Allow the plugin to prevent DokuWiki from reusing an instance + * Disable caching of this renderer's output + */ + function nocache() { + $this->info['cache'] = false; + } + + /** + * Disable TOC generation for this renderer's output * - * @return bool false if the plugin has to be instantiated + * This might not be used for certain sub renderer */ - function isSingleton() { - return false; + function notoc() { + $this->info['toc'] = false; } /** - * handle plugin rendering + * Handle plugin rendering + * + * Most likely this needs NOT to be overwritten by sub classes * * @param string $name Plugin name * @param mixed $data custom data set by handler @@ -66,6 +93,7 @@ class Doku_Renderer extends DokuWiki_Plugin { * @param string $match raw matched syntax */ function plugin($name, $data, $state = '', $match = '') { + /** @var DokuWiki_Syntax_Plugin $plugin */ $plugin = plugin_load('syntax', $name); if($plugin != null) { $plugin->render($this->getFormat(), $this, $data); @@ -75,9 +103,10 @@ class Doku_Renderer extends DokuWiki_Plugin { /** * handle nested render instructions * this method (and nest_close method) should not be overloaded in actual renderer output classes + * + * @param array $instructions */ function nest($instructions) { - foreach($instructions as $instruction) { // execute the callback against ourself if(method_exists($this, $instruction[0])) { @@ -86,267 +115,638 @@ class Doku_Renderer extends DokuWiki_Plugin { } } - // dummy closing instruction issued by Doku_Handler_Nest, normally the syntax mode should - // override this instruction when instantiating Doku_Handler_Nest - however plugins will not - // be able to - as their instructions require data. + /** + * dummy closing instruction issued by Doku_Handler_Nest + * + * normally the syntax mode should override this instruction when instantiating Doku_Handler_Nest - + * however plugins will not be able to - as their instructions require data. + */ function nest_close() { } + #region Syntax modes - sub classes will need to implement them to fill $doc + + /** + * Initialize the document + */ function document_start() { } + /** + * Finalize the document + */ function document_end() { } + /** + * Render the Table of Contents + * + * @return string + */ function render_TOC() { return ''; } + /** + * Add an item to the TOC + * + * @param string $id the hash link + * @param string $text the text to display + * @param int $level the nesting level + */ function toc_additem($id, $text, $level) { } + /** + * Render a heading + * + * @param string $text the text to display + * @param int $level header level + * @param int $pos byte position in the original source + */ function header($text, $level, $pos) { } + /** + * Open a new section + * + * @param int $level section level (as determined by the previous header) + */ function section_open($level) { } + /** + * Close the current section + */ function section_close() { } + /** + * Render plain text data + * + * @param $text + */ function cdata($text) { } + /** + * Open a paragraph + */ function p_open() { } + /** + * Close a paragraph + */ function p_close() { } + /** + * Create a line breake + */ function linebreak() { } + /** + * Create a horizontal line + */ function hr() { } + /** + * Start strong (bold) formatting + */ function strong_open() { } + /** + * Stop strong (bold) formatting + */ function strong_close() { } + /** + * Start emphasis (italics) formatting + */ function emphasis_open() { } + /** + * Stop emphasis (italics) formatting + */ function emphasis_close() { } + /** + * Start underline formatting + */ function underline_open() { } + /** + * Stop underline formatting + */ function underline_close() { } + /** + * Start monospace formatting + */ function monospace_open() { } + /** + * Stop monospace formatting + */ function monospace_close() { } + /** + * Start a subscript + */ function subscript_open() { } + /** + * Stop a subscript + */ function subscript_close() { } + /** + * Start a superscript + */ function superscript_open() { } + /** + * Stop a superscript + */ function superscript_close() { } + /** + * Start deleted (strike-through) formatting + */ function deleted_open() { } + /** + * Stop deleted (strike-through) formatting + */ function deleted_close() { } + /** + * Start a footnote + */ function footnote_open() { } + /** + * Stop a footnote + */ function footnote_close() { } + /** + * Open an unordered list + */ function listu_open() { } + /** + * Close an unordered list + */ function listu_close() { } + /** + * Open an ordered list + */ function listo_open() { } + /** + * Close an ordered list + */ function listo_close() { } + /** + * Open a list item + * + * @param int $level the nesting level + */ function listitem_open($level) { } + /** + * Close a list item + */ function listitem_close() { } + /** + * Start the content of a list item + */ function listcontent_open() { } + /** + * Stop the content of a list item + */ function listcontent_close() { } + /** + * Output unformatted $text + * + * Defaults to $this->cdata() + * + * @param string $text + */ function unformatted($text) { + $this->cdata($text); } + /** + * Output inline PHP code + * + * If $conf['phpok'] is true this should evaluate the given code and append the result + * to $doc + * + * @param string $text The PHP code + */ function php($text) { } + /** + * Output block level PHP code + * + * If $conf['phpok'] is true this should evaluate the given code and append the result + * to $doc + * + * @param string $text The PHP code + */ function phpblock($text) { } + /** + * Output raw inline HTML + * + * If $conf['htmlok'] is true this should add the code as is to $doc + * + * @param string $text The HTML + */ function html($text) { } + /** + * Output raw block-level HTML + * + * If $conf['htmlok'] is true this should add the code as is to $doc + * + * @param string $text The HTML + */ function htmlblock($text) { } + /** + * Output preformatted text + * + * @param string $text + */ function preformatted($text) { } + /** + * Start a block quote + */ function quote_open() { } + /** + * Stop a block quote + */ function quote_close() { } + /** + * Display text as file content, optionally syntax highlighted + * + * @param string $text text to show + * @param string $lang programming language to use for syntax highlighting + * @param string $file file path label + */ function file($text, $lang = null, $file = null) { } + /** + * Display text as code content, optionally syntax highlighted + * + * @param string $text text to show + * @param string $lang programming language to use for syntax highlighting + * @param string $file file path label + */ function code($text, $lang = null, $file = null) { } + /** + * Format an acronym + * + * Uses $this->acronyms + * + * @param string $acronym + */ function acronym($acronym) { } + /** + * Format a smiley + * + * Uses $this->smiley + * + * @param string $smiley + */ function smiley($smiley) { } - function wordblock($word) { - } - + /** + * Format an entity + * + * Entities are basically small text replacements + * + * Uses $this->entities + * + * @param string $entity + */ function entity($entity) { } - // 640x480 ($x=640, $y=480) + /** + * Typographically format a multiply sign + * + * Example: ($x=640, $y=480) should result in "640×480" + * + * @param string|int $x first value + * @param string|int $y second value + */ function multiplyentity($x, $y) { } + /** + * Render an opening single quote char (language specific) + */ function singlequoteopening() { } + /** + * Render a closing single quote char (language specific) + */ function singlequoteclosing() { } + /** + * Render an apostrophe char (language specific) + */ function apostrophe() { } + /** + * Render an opening double quote char (language specific) + */ function doublequoteopening() { } + /** + * Render an closinging double quote char (language specific) + */ function doublequoteclosing() { } - // $link like 'SomePage' + /** + * Render a CamelCase link + * + * @param string $link The link name + * @see http://en.wikipedia.org/wiki/CamelCase + */ function camelcaselink($link) { } + /** + * Render a page local link + * + * @param string $hash hash link identifier + * @param string $name name for the link + */ function locallink($hash, $name = null) { } - // $link like 'wiki:syntax', $title could be an array (media) + /** + * Render a wiki internal link + * + * @param string $link page ID to link to. eg. 'wiki:syntax' + * @param string|array $title name for the link, array for media file + */ function internallink($link, $title = null) { } - // $link is full URL with scheme, $title could be an array (media) + /** + * Render an external link + * + * @param string $link full URL with scheme + * @param string|array $title name for the link, array for media file + */ function externallink($link, $title = null) { } + /** + * Render the output of an RSS feed + * + * @param string $url URL of the feed + * @param array $params Finetuning of the output + */ function rss($url, $params) { } - // $link is the original link - probably not much use - // $wikiName is an indentifier for the wiki - // $wikiUri is the URL fragment to append to some known URL + /** + * Render an interwiki link + * + * You may want to use $this->_resolveInterWiki() here + * + * @param string $link original link - probably not much use + * @param string|array $title name for the link, array for media file + * @param string $wikiName indentifier (shortcut) for the remote wiki + * @param string $wikiUri the fragment parsed from the original link + */ function interwikilink($link, $title = null, $wikiName, $wikiUri) { } - // Link to file on users OS, $title could be an array (media) + /** + * Link to file on users OS + * + * @param string $link the link + * @param string|array $title name for the link, array for media file + */ function filelink($link, $title = null) { } - // Link to a Windows share, , $title could be an array (media) + /** + * Link to windows share + * + * @param string $link the link + * @param string|array $title name for the link, array for media file + */ function windowssharelink($link, $title = null) { } -// function email($address, $title = null) {} + /** + * Render a linked E-Mail Address + * + * Should honor $conf['mailguard'] setting + * + * @param string $address Email-Address + * @param string $name Display name + */ function emaillink($address, $name = null) { } + /** + * Render an internal media file + * + * @param string $src media ID + * @param string $title descriptive text + * @param string $align left|center|right + * @param int $width width of media in pixel + * @param int $height height of media in pixel + * @param string $cache cache|recache|nocache + * @param string $linking linkonly|detail|nolink + */ function internalmedia($src, $title = null, $align = null, $width = null, $height = null, $cache = null, $linking = null) { } + /** + * Render an external media file + * + * @param string $src full media URL + * @param string $title descriptive text + * @param string $align left|center|right + * @param int $width width of media in pixel + * @param int $height height of media in pixel + * @param string $cache cache|recache|nocache + * @param string $linking linkonly|detail|nolink + */ function externalmedia($src, $title = null, $align = null, $width = null, $height = null, $cache = null, $linking = null) { } - function internalmedialink( - $src, $title = null, $align = null, $width = null, $height = null, $cache = null - ) { + /** + * Render a link to an internal media file + * + * @param string $src media ID + * @param string $title descriptive text + * @param string $align left|center|right + * @param int $width width of media in pixel + * @param int $height height of media in pixel + * @param string $cache cache|recache|nocache + */ + function internalmedialink($src, $title = null, $align = null, + $width = null, $height = null, $cache = null) { } - function externalmedialink( - $src, $title = null, $align = null, $width = null, $height = null, $cache = null - ) { + /** + * Render a link to an external media file + * + * @param string $src media ID + * @param string $title descriptive text + * @param string $align left|center|right + * @param int $width width of media in pixel + * @param int $height height of media in pixel + * @param string $cache cache|recache|nocache + */ + function externalmedialink($src, $title = null, $align = null, + $width = null, $height = null, $cache = null) { } + /** + * Start a table + * + * @param int $maxcols maximum number of columns + * @param int $numrows NOT IMPLEMENTED + * @param int $pos byte position in the original source + */ function table_open($maxcols = null, $numrows = null, $pos = null) { } + /** + * Close a table + * + * @param int $pos byte position in the original source + */ function table_close($pos = null) { } + /** + * Open a table header + */ function tablethead_open() { } + /** + * Close a table header + */ function tablethead_close() { } + /** + * Open a table row + */ function tablerow_open() { } + /** + * Close a table row + */ function tablerow_close() { } + /** + * Open a table header cell + * + * @param int $colspan + * @param string $align left|center|right + * @param int $rowspan + */ function tableheader_open($colspan = 1, $align = null, $rowspan = 1) { } + /** + * Close a table header cell + */ function tableheader_close() { } + /** + * Open a table cell + * + * @param int $colspan + * @param string $align left|center|right + * @param int $rowspan + */ function tablecell_open($colspan = 1, $align = null, $rowspan = 1) { } + /** + * Close a table cell + */ function tablecell_close() { } - // util functions follow, you probably won't need to reimplement them + #endregion + + #region util functions, you probably won't need to reimplement them /** * Removes any Namespace from the given name but keeps @@ -412,6 +812,8 @@ class Doku_Renderer extends DokuWiki_Plugin { return $url; } + + #endregion } -- cgit v1.2.3 From 3dd5c2254a659d7d66017f016e3e0d3d89f479c6 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 24 May 2014 15:17:26 +0200 Subject: added doc blocks for xhtml renderer --- inc/parser/renderer.php | 4 +- inc/parser/xhtml.php | 1040 +++++++++++++++++++++++++++++++---------------- 2 files changed, 696 insertions(+), 348 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index a486ed106..5eddc903e 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -202,7 +202,7 @@ class Doku_Renderer extends DokuWiki_Plugin { } /** - * Create a line breake + * Create a line break */ function linebreak() { } @@ -607,7 +607,7 @@ class Doku_Renderer extends DokuWiki_Plugin { * Should honor $conf['mailguard'] setting * * @param string $address Email-Address - * @param string $name Display name + * @param string|array $name name for the link, array for media file */ function emaillink($address, $name = null) { } diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index e4afb9eb8..5c0353688 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -7,37 +7,53 @@ */ if(!defined('DOKU_INC')) die('meh.'); -if ( !defined('DOKU_LF') ) { +if(!defined('DOKU_LF')) { // Some whitespace to help View > Source - define ('DOKU_LF',"\n"); + define ('DOKU_LF', "\n"); } -if ( !defined('DOKU_TAB') ) { +if(!defined('DOKU_TAB')) { // Some whitespace to help View > Source - define ('DOKU_TAB',"\t"); + define ('DOKU_TAB', "\t"); } /** - * The Renderer + * The XHTML Renderer + * + * This is DokuWiki's main renderer used to display page content in the wiki */ class Doku_Renderer_xhtml extends Doku_Renderer { + /** @var array store the table of contents */ + public $toc = array(); + + /** @var array A stack of section edit data */ + protected $sectionedits = array(); - // @access public - var $doc = ''; // will contain the whole document - var $toc = array(); // will contain the Table of Contents + /** @var int last section edit id, used by startSectionEdit */ + protected $lastsecid = 0; - var $sectionedits = array(); // A stack of section edit data - private $lastsecid = 0; // last section edit id, used by startSectionEdit + /** @var array the list of headers used to create unique link ids */ + protected $headers = array(); - var $headers = array(); /** @var array a list of footnotes, list starts at 1! */ - var $footnotes = array(); - var $lastlevel = 0; - var $node = array(0,0,0,0,0); - var $store = ''; + protected $footnotes = array(); + + /** @var int current section level */ + protected $lastlevel = 0; + /** @var array section node tracker */ + protected $node = array(0, 0, 0, 0, 0); + + /** @var string temporary $doc store */ + protected $store = ''; - var $_counter = array(); // used as global counter, introduced for table classes - var $_codeblock = 0; // counts the code and file blocks, used to provide download links + /** @var array global counter, for table classes etc. */ + protected $_counter = array(); // + + /** @var int counts the code and file blocks, used to provide download links */ + protected $_codeblock = 0; + + /** @var array list of allowed URL schemes */ + protected $schemes = null; /** * Register a new edit section range @@ -50,43 +66,53 @@ class Doku_Renderer_xhtml extends Doku_Renderer { */ public function startSectionEdit($start, $type, $title = null) { $this->sectionedits[] = array(++$this->lastsecid, $start, $type, $title); - return 'sectionedit' . $this->lastsecid; + return 'sectionedit'.$this->lastsecid; } /** * Finish an edit section range * - * @param $end int The byte position for the edit end; null for the rest of + * @param $end int The byte position for the edit end; null for the rest of * the page * @author Adrian Lang */ public function finishSectionEdit($end = null) { list($id, $start, $type, $title) = array_pop($this->sectionedits); - if (!is_null($end) && $end <= $start) { + if(!is_null($end) && $end <= $start) { return; } - $this->doc .= "'; + $this->doc .= "[$start-".(is_null($end) ? '' : $end).'] -->'; } - function getFormat(){ + /** + * Returns the format produced by this renderer. + * + * @return string always 'xhtml' + */ + function getFormat() { return 'xhtml'; } - + /** + * Initialize the document + */ function document_start() { //reset some internals $this->toc = array(); $this->headers = array(); } + /** + * Finalize the document + */ function document_end() { // Finish open section edits. - while (count($this->sectionedits) > 0) { - if ($this->sectionedits[count($this->sectionedits) - 1][1] <= 1) { + while(count($this->sectionedits) > 0) { + if($this->sectionedits[count($this->sectionedits) - 1][1] <= 1) { // If there is only one section, do not write a section edit // marker. array_pop($this->sectionedits); @@ -95,12 +121,12 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } } - if ( count ($this->footnotes) > 0 ) { + if(count($this->footnotes) > 0) { $this->doc .= '
'.DOKU_LF; - foreach ( $this->footnotes as $id => $footnote ) { + foreach($this->footnotes as $id => $footnote) { // check its not a placeholder that indicates actual footnote text is elsewhere - if (substr($footnote, 0, 5) != "@@FNT") { + if(substr($footnote, 0, 5) != "@@FNT") { // open the footnote and set the anchor and backlink $this->doc .= '
'; @@ -110,8 +136,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // get any other footnotes that use the same markup $alt = array_keys($this->footnotes, "@@FNT$id"); - if (count($alt)) { - foreach ($alt as $ref) { + if(count($alt)) { + foreach($alt as $ref) { // set anchor and backlink for the other footnotes $this->doc .= ', '; $this->doc .= ($ref).') '.DOKU_LF; @@ -120,7 +146,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // add footnote markup and close this footnote $this->doc .= $footnote; - $this->doc .= '
' . DOKU_LF; + $this->doc .= '
'.DOKU_LF; } } $this->doc .= ''.DOKU_LF; @@ -128,139 +154,221 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // Prepare the TOC global $conf; - if($this->info['toc'] && is_array($this->toc) && $conf['tocminheads'] && count($this->toc) >= $conf['tocminheads']){ + if($this->info['toc'] && is_array($this->toc) && $conf['tocminheads'] && count($this->toc) >= $conf['tocminheads']) { global $TOC; $TOC = $this->toc; } // make sure there are no empty paragraphs - $this->doc = preg_replace('#

\s*

#','',$this->doc); + $this->doc = preg_replace('#

\s*

#', '', $this->doc); } + /** + * Add an item to the TOC + * + * @param string $id the hash link + * @param string $text the text to display + * @param int $level the nesting level + */ function toc_additem($id, $text, $level) { global $conf; //handle TOC - if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){ - $this->toc[] = html_mktocitem($id, $text, $level-$conf['toptoclevel']+1); + if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']) { + $this->toc[] = html_mktocitem($id, $text, $level - $conf['toptoclevel'] + 1); } } + /** + * Render a heading + * + * @param string $text the text to display + * @param int $level header level + * @param int $pos byte position in the original source + */ function header($text, $level, $pos) { global $conf; if(!$text) return; //skip empty headlines - $hid = $this->_headerToLink($text,true); + $hid = $this->_headerToLink($text, true); //only add items within configured levels $this->toc_additem($hid, $text, $level); // adjust $node to reflect hierarchy of levels - $this->node[$level-1]++; - if ($level < $this->lastlevel) { - for ($i = 0; $i < $this->lastlevel-$level; $i++) { - $this->node[$this->lastlevel-$i-1] = 0; + $this->node[$level - 1]++; + if($level < $this->lastlevel) { + for($i = 0; $i < $this->lastlevel - $level; $i++) { + $this->node[$this->lastlevel - $i - 1] = 0; } } $this->lastlevel = $level; - if ($level <= $conf['maxseclevel'] && + if($level <= $conf['maxseclevel'] && count($this->sectionedits) > 0 && - $this->sectionedits[count($this->sectionedits) - 1][2] === 'section') { + $this->sectionedits[count($this->sectionedits) - 1][2] === 'section' + ) { $this->finishSectionEdit($pos - 1); } // write the header $this->doc .= DOKU_LF.'doc .= ' class="' . $this->startSectionEdit($pos, 'section', $text) . '"'; + if($level <= $conf['maxseclevel']) { + $this->doc .= ' class="'.$this->startSectionEdit($pos, 'section', $text).'"'; } $this->doc .= ' id="'.$hid.'">'; $this->doc .= $this->_xmlEntities($text); $this->doc .= "".DOKU_LF; } + /** + * Open a new section + * + * @param int $level section level (as determined by the previous header) + */ function section_open($level) { - $this->doc .= '
' . DOKU_LF; + $this->doc .= '
'.DOKU_LF; } + /** + * Close the current section + */ function section_close() { $this->doc .= DOKU_LF.'
'.DOKU_LF; } + /** + * Render plain text data + * + * @param $text + */ function cdata($text) { $this->doc .= $this->_xmlEntities($text); } + /** + * Open a paragraph + */ function p_open() { $this->doc .= DOKU_LF.'

'.DOKU_LF; } + /** + * Close a paragraph + */ function p_close() { $this->doc .= DOKU_LF.'

'.DOKU_LF; } + /** + * Create a line break + */ function linebreak() { $this->doc .= '
'.DOKU_LF; } + /** + * Create a horizontal line + */ function hr() { $this->doc .= '
'.DOKU_LF; } + /** + * Start strong (bold) formatting + */ function strong_open() { $this->doc .= ''; } + /** + * Stop strong (bold) formatting + */ function strong_close() { $this->doc .= ''; } + /** + * Start emphasis (italics) formatting + */ function emphasis_open() { $this->doc .= ''; } + /** + * Stop emphasis (italics) formatting + */ function emphasis_close() { $this->doc .= ''; } + /** + * Start underline formatting + */ function underline_open() { $this->doc .= ''; } + /** + * Stop underline formatting + */ function underline_close() { $this->doc .= ''; } + /** + * Start monospace formatting + */ function monospace_open() { $this->doc .= ''; } + /** + * Stop monospace formatting + */ function monospace_close() { $this->doc .= ''; } + /** + * Start a subscript + */ function subscript_open() { $this->doc .= ''; } + /** + * Stop a subscript + */ function subscript_close() { $this->doc .= ''; } + /** + * Start a superscript + */ function superscript_open() { $this->doc .= ''; } + /** + * Stop a superscript + */ function superscript_close() { $this->doc .= ''; } + /** + * Start deleted (strike-through) formatting + */ function deleted_open() { $this->doc .= ''; } + /** + * Stop deleted (strike-through) formatting + */ function deleted_close() { $this->doc .= ''; } @@ -296,14 +404,14 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $fnid++; // recover footnote into the stack and restore old content - $footnote = $this->doc; - $this->doc = $this->store; + $footnote = $this->doc; + $this->doc = $this->store; $this->store = ''; // check to see if this footnote has been seen before $i = array_search($footnote, $this->footnotes); - if ($i === false) { + if($i === false) { // its a new footnote, add it to the $footnotes array $this->footnotes[$fnid] = $footnote; } else { @@ -315,38 +423,71 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $this->doc .= ''.$fnid.')'; } + /** + * Open an unordered list + */ function listu_open() { $this->doc .= '
    '.DOKU_LF; } + /** + * Close an unordered list + */ function listu_close() { $this->doc .= '
'.DOKU_LF; } + /** + * Open an ordered list + */ function listo_open() { $this->doc .= '
    '.DOKU_LF; } + /** + * Close an ordered list + */ function listo_close() { $this->doc .= '
'.DOKU_LF; } + /** + * Open a list item + * + * @param int $level the nesting level + */ function listitem_open($level) { $this->doc .= '
  • '; } + /** + * Close a list item + */ function listitem_close() { $this->doc .= '
  • '.DOKU_LF; } + /** + * Start the content of a list item + */ function listcontent_open() { $this->doc .= '
    '; } + /** + * Stop the content of a list item + */ function listcontent_close() { $this->doc .= '
    '.DOKU_LF; } + /** + * Output unformatted $text + * + * Defaults to $this->cdata() + * + * @param string $text + */ function unformatted($text) { $this->doc .= $this->_xmlEntities($text); } @@ -354,15 +495,15 @@ class Doku_Renderer_xhtml extends Doku_Renderer { /** * Execute PHP code if allowed * - * @param string $text PHP code that is either executed or printed - * @param string $wrapper html element to wrap result if $conf['phpok'] is okff + * @param string $text PHP code that is either executed or printed + * @param string $wrapper html element to wrap result if $conf['phpok'] is okff * * @author Andreas Gohr */ - function php($text, $wrapper='code') { + function php($text, $wrapper = 'code') { global $conf; - if($conf['phpok']){ + if($conf['phpok']) { ob_start(); eval($text); $this->doc .= ob_get_contents(); @@ -372,6 +513,14 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } } + /** + * Output block level PHP code + * + * If $conf['phpok'] is true this should evaluate the given code and append the result + * to $doc + * + * @param string $text The PHP code + */ function phpblock($text) { $this->php($text, 'pre'); } @@ -379,75 +528,110 @@ class Doku_Renderer_xhtml extends Doku_Renderer { /** * Insert HTML if allowed * - * @param string $text html text - * @param string $wrapper html element to wrap result if $conf['htmlok'] is okff + * @param string $text html text + * @param string $wrapper html element to wrap result if $conf['htmlok'] is okff * * @author Andreas Gohr */ - function html($text, $wrapper='code') { + function html($text, $wrapper = 'code') { global $conf; - if($conf['htmlok']){ + if($conf['htmlok']) { $this->doc .= $text; } else { $this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper); } } + /** + * Output raw block-level HTML + * + * If $conf['htmlok'] is true this should add the code as is to $doc + * + * @param string $text The HTML + */ function htmlblock($text) { $this->html($text, 'pre'); } + /** + * Start a block quote + */ function quote_open() { $this->doc .= '
    '.DOKU_LF; } + /** + * Stop a block quote + */ function quote_close() { $this->doc .= '
    '.DOKU_LF; } + /** + * Output preformatted text + * + * @param string $text + */ function preformatted($text) { - $this->doc .= '
    ' . trim($this->_xmlEntities($text),"\n\r") . '
    '. DOKU_LF; + $this->doc .= '
    '.trim($this->_xmlEntities($text), "\n\r").'
    '.DOKU_LF; } - function file($text, $language=null, $filename=null) { - $this->_highlight('file',$text,$language,$filename); + /** + * Display text as file content, optionally syntax highlighted + * + * @param string $text text to show + * @param string $language programming language to use for syntax highlighting + * @param string $filename file path label + */ + function file($text, $language = null, $filename = null) { + $this->_highlight('file', $text, $language, $filename); } - function code($text, $language=null, $filename=null) { - $this->_highlight('code',$text,$language,$filename); + /** + * Display text as code content, optionally syntax highlighted + * + * @param string $text text to show + * @param string $language programming language to use for syntax highlighting + * @param string $filename file path label + */ + function code($text, $language = null, $filename = null) { + $this->_highlight('code', $text, $language, $filename); } /** * Use GeSHi to highlight language syntax in code and file blocks * * @author Andreas Gohr + * @param string $type code|file + * @param string $text text to show + * @param string $language programming language to use for syntax highlighting + * @param string $filename file path label */ - function _highlight($type, $text, $language=null, $filename=null) { - global $conf; + function _highlight($type, $text, $language = null, $filename = null) { global $ID; global $lang; - if($filename){ + if($filename) { // add icon - list($ext) = mimetype($filename,false); - $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); + list($ext) = mimetype($filename, false); + $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); $class = 'mediafile mf_'.$class; $this->doc .= '
    '.DOKU_LF; - $this->doc .= '
    '; + $this->doc .= '
    '; $this->doc .= hsc($filename); $this->doc .= '
    '.DOKU_LF.'
    '; } - if ($text{0} == "\n") { + if($text{0} == "\n") { $text = substr($text, 1); } - if (substr($text, -1) == "\n") { + if(substr($text, -1) == "\n") { $text = substr($text, 0, -1); } - if ( is_null($language) ) { + if(is_null($language)) { $this->doc .= '
    '.$this->_xmlEntities($text).'
    '.DOKU_LF; } else { $class = 'code'; //we always need the code class to make the syntax highlighting apply @@ -456,16 +640,23 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $this->doc .= "
    ".p_xhtml_cached_geshi($text, $language, '').'
    '.DOKU_LF; } - if($filename){ + if($filename) { $this->doc .= '
    '.DOKU_LF; } $this->_codeblock++; } + /** + * Format an acronym + * + * Uses $this->acronyms + * + * @param string $acronym + */ function acronym($acronym) { - if ( array_key_exists($acronym, $this->acronyms) ) { + if(array_key_exists($acronym, $this->acronyms)) { $title = $this->_xmlEntities($this->acronyms[$acronym]); @@ -477,73 +668,109 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } } + /** + * Format a smiley + * + * Uses $this->smiley + * + * @param string $smiley + */ function smiley($smiley) { - if ( array_key_exists($smiley, $this->smileys) ) { - $title = $this->_xmlEntities($this->smileys[$smiley]); + if(array_key_exists($smiley, $this->smileys)) { $this->doc .= ''.
-                    $this->_xmlEntities($smiley).''; + $this->_xmlEntities($smiley).'" />'; } else { $this->doc .= $this->_xmlEntities($smiley); } } - /* - * not used - function wordblock($word) { - if ( array_key_exists($word, $this->badwords) ) { - $this->doc .= '** BLEEP **'; - } else { - $this->doc .= $this->_xmlEntities($word); - } - } - */ - + /** + * Format an entity + * + * Entities are basically small text replacements + * + * Uses $this->entities + * + * @param string $entity + */ function entity($entity) { - if ( array_key_exists($entity, $this->entities) ) { + if(array_key_exists($entity, $this->entities)) { $this->doc .= $this->entities[$entity]; } else { $this->doc .= $this->_xmlEntities($entity); } } + /** + * Typographically format a multiply sign + * + * Example: ($x=640, $y=480) should result in "640×480" + * + * @param string|int $x first value + * @param string|int $y second value + */ function multiplyentity($x, $y) { $this->doc .= "$x×$y"; } + /** + * Render an opening single quote char (language specific) + */ function singlequoteopening() { global $lang; $this->doc .= $lang['singlequoteopening']; } + /** + * Render a closing single quote char (language specific) + */ function singlequoteclosing() { global $lang; $this->doc .= $lang['singlequoteclosing']; } + /** + * Render an apostrophe char (language specific) + */ function apostrophe() { global $lang; $this->doc .= $lang['apostrophe']; } + /** + * Render an opening double quote char (language specific) + */ function doublequoteopening() { global $lang; $this->doc .= $lang['doublequoteopening']; } + /** + * Render an closinging double quote char (language specific) + */ function doublequoteclosing() { global $lang; $this->doc .= $lang['doublequoteclosing']; } /** + * Render a CamelCase link + * + * @param string $link The link name + * @see http://en.wikipedia.org/wiki/CamelCase */ function camelcaselink($link) { - $this->internallink($link,$link); + $this->internallink($link, $link); } - - function locallink($hash, $name = null){ + /** + * Render a page local link + * + * @param string $hash hash link identifier + * @param string $name name for the link + */ + function locallink($hash, $name = null) { global $ID; $name = $this->_getLinkTitle($name, $hash, $isImage); $hash = $this->_headerToLink($hash); @@ -559,23 +786,23 @@ 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 + * @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 */ - function internallink($id, $name = null, $search=null,$returnonly=false,$linktype='content') { + function internallink($id, $name = null, $search = null, $returnonly = false, $linktype = 'content') { global $conf; global $ID; global $INFO; $params = ''; - $parts = explode('?', $id, 2); - if (count($parts) === 2) { - $id = $parts[0]; + $parts = explode('?', $id, 2); + if(count($parts) === 2) { + $id = $parts[0]; $params = $parts[1]; } @@ -583,7 +810,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // We need this check because _simpleTitle needs // correct $id and resolve_pageid() use cleanID($id) // (some things could be lost) - if ($id === '') { + if($id === '') { $id = $ID; } @@ -591,22 +818,22 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $default = $this->_simpleTitle($id); // now first resolve and clean up the $id - resolve_pageid(getNS($ID),$id,$exists); + resolve_pageid(getNS($ID), $id, $exists); $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype); - if ( !$isImage ) { - if ( $exists ) { - $class='wikilink1'; + if(!$isImage) { + if($exists) { + $class = 'wikilink1'; } else { - $class='wikilink2'; - $link['rel']='nofollow'; + $class = 'wikilink2'; + $link['rel'] = 'nofollow'; } } else { - $class='media'; + $class = 'media'; } //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 @@ -615,37 +842,43 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $link['pre'] = ''; $link['suf'] = ''; // highlight link to current page - if ($id == $INFO['id']) { - $link['pre'] = ''; - $link['suf'] = ''; + if($id == $INFO['id']) { + $link['pre'] = ''; + $link['suf'] = ''; } - $link['more'] = ''; - $link['class'] = $class; - $link['url'] = wl($id, $params); - $link['name'] = $name; - $link['title'] = $id; + $link['more'] = ''; + $link['class'] = $class; + $link['url'] = wl($id, $params); + $link['name'] = $name; + $link['title'] = $id; //add search string - if($search){ - ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&'; - if(is_array($search)){ - $search = array_map('rawurlencode',$search); - $link['url'] .= 's[]='.join('&s[]=',$search); - }else{ + if($search) { + ($conf['userewrite']) ? $link['url'] .= '?' : $link['url'] .= '&'; + if(is_array($search)) { + $search = array_map('rawurlencode', $search); + $link['url'] .= 's[]='.join('&s[]=', $search); + } else { $link['url'] .= 's='.rawurlencode($search); } } //keep hash - if($hash) $link['url'].='#'.$hash; + if($hash) $link['url'] .= '#'.$hash; //output formatted - if($returnonly){ + if($returnonly) { return $this->_formatLink($link); - }else{ + } else { $this->doc .= $this->_formatLink($link); } } + /** + * Render an external link + * + * @param string $url full URL with scheme + * @param string|array $name name for the link, array for media file + */ function externallink($url, $name = null) { global $conf; @@ -653,21 +886,21 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // url might be an attack vector, only allow registered protocols if(is_null($this->schemes)) $this->schemes = getSchemes(); - list($scheme) = explode('://',$url); + list($scheme) = explode('://', $url); $scheme = strtolower($scheme); - if(!in_array($scheme,$this->schemes)) $url = ''; + if(!in_array($scheme, $this->schemes)) $url = ''; // is there still an URL? - if(!$url){ + if(!$url) { $this->doc .= $name; return; } // set class - if ( !$isImage ) { - $class='urlextern'; + if(!$isImage) { + $class = 'urlextern'; } else { - $class='media'; + $class = 'media'; } //prepare for formating @@ -679,8 +912,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $link['class'] = $class; $link['url'] = $url; - $link['name'] = $name; - $link['title'] = $this->_xmlEntities($url); + $link['name'] = $name; + $link['title'] = $this->_xmlEntities($url); if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; //output formatted @@ -688,11 +921,19 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } /** + * Render an interwiki link + * + * You may want to use $this->_resolveInterWiki() here + * + * @param string $match original link - probably not much use + * @param string|array $name name for the link, array for media file + * @param string $wikiName indentifier (shortcut) for the remote wiki + * @param string $wikiUri the fragment parsed from the original link */ function interwikilink($match, $name = null, $wikiName, $wikiUri) { global $conf; - $link = array(); + $link = array(); $link['target'] = $conf['target']['interwiki']; $link['pre'] = ''; $link['suf'] = ''; @@ -701,10 +942,10 @@ class Doku_Renderer_xhtml extends Doku_Renderer { //get interwiki URL $exists = null; - $url = $this->_resolveInterWiki($wikiName, $wikiUri, $exists); + $url = $this->_resolveInterWiki($wikiName, $wikiUri, $exists); if(!$isImage) { - $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $wikiName); + $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $wikiName); $link['class'] = "interwiki iw_$class"; } else { $link['class'] = 'media'; @@ -723,7 +964,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } } - $link['url'] = $url; + $link['url'] = $url; $link['title'] = htmlspecialchars($link['url']); //output formatted @@ -731,54 +972,66 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } /** + * Link to windows share + * + * @param string $url the link + * @param string|array $name name for the link, array for media file */ function windowssharelink($url, $name = null) { global $conf; - global $lang; + //simple setup $link['target'] = $conf['target']['windows']; $link['pre'] = ''; - $link['suf'] = ''; + $link['suf'] = ''; $link['style'] = ''; $link['name'] = $this->_getLinkTitle($name, $url, $isImage); - if ( !$isImage ) { + if(!$isImage) { $link['class'] = 'windows'; } else { $link['class'] = 'media'; } $link['title'] = $this->_xmlEntities($url); - $url = str_replace('\\','/',$url); - $url = 'file:///'.$url; - $link['url'] = $url; + $url = str_replace('\\', '/', $url); + $url = 'file:///'.$url; + $link['url'] = $url; //output formatted $this->doc .= $this->_formatLink($link); } + /** + * Render a linked E-Mail Address + * + * Honors $conf['mailguard'] setting + * + * @param string $address Email-Address + * @param string|array $name name for the link, array for media file + */ function emaillink($address, $name = null) { global $conf; //simple setup - $link = array(); + $link = array(); $link['target'] = ''; $link['pre'] = ''; - $link['suf'] = ''; + $link['suf'] = ''; $link['style'] = ''; $link['more'] = ''; $name = $this->_getLinkTitle($name, '', $isImage); - if ( !$isImage ) { - $link['class']='mail'; + if(!$isImage) { + $link['class'] = 'mail'; } else { - $link['class']='media'; + $link['class'] = 'media'; } $address = $this->_xmlEntities($address); $address = obfuscate($address); $title = $address; - if(empty($name)){ + if(empty($name)) { $name = $address; } @@ -792,73 +1045,97 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $this->doc .= $this->_formatLink($link); } - function internalmedia ($src, $title=null, $align=null, $width=null, - $height=null, $cache=null, $linking=null, $return=NULL) { + /** + * Render an internal media file + * + * @param string $src media ID + * @param string $title descriptive text + * @param string $align left|center|right + * @param int $width width of media in pixel + * @param int $height height of media in pixel + * @param string $cache cache|recache|nocache + * @param string $linking linkonly|detail|nolink + * @param bool $return return HTML instead of adding to $doc + * @return void|string + */ + function internalmedia($src, $title = null, $align = null, $width = null, + $height = null, $cache = null, $linking = null, $return = false) { global $ID; - list($src,$hash) = explode('#',$src,2); - resolve_mediaid(getNS($ID),$src, $exists); + list($src, $hash) = explode('#', $src, 2); + resolve_mediaid(getNS($ID), $src, $exists); $noLink = false; $render = ($linking == 'linkonly') ? false : true; - $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); + $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); - 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' || media_supportedav($mime)) && $render){ + list($ext, $mime) = 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' || media_supportedav($mime)) && $render) { // don't link movies $noLink = true; - }else{ + } else { // 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['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); - if ($exists) $link['title'] .= ' (' . filesize_h(filesize(mediaFN($src))).')'; + $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache), true); + if($exists) $link['title'] .= ' ('.filesize_h(filesize(mediaFN($src))).')'; } if($hash) $link['url'] .= '#'.$hash; //markup non existing files - if (!$exists) { + if(!$exists) { $link['class'] .= ' wikilink2'; } //output formatted - if ($return) { - if ($linking == 'nolink' || $noLink) return $link['name']; + if($return) { + if($linking == 'nolink' || $noLink) return $link['name']; else return $this->_formatLink($link); } else { - if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; + if($linking == 'nolink' || $noLink) $this->doc .= $link['name']; else $this->doc .= $this->_formatLink($link); } } - function externalmedia ($src, $title=null, $align=null, $width=null, - $height=null, $cache=null, $linking=null) { - list($src,$hash) = explode('#',$src,2); + /** + * Render an external media file + * + * @param string $src full media URL + * @param string $title descriptive text + * @param string $align left|center|right + * @param int $width width of media in pixel + * @param int $height height of media in pixel + * @param string $cache cache|recache|nocache + * @param string $linking linkonly|detail|nolink + */ + function externalmedia($src, $title = null, $align = null, $width = null, + $height = null, $cache = null, $linking = null) { + list($src, $hash) = explode('#', $src, 2); $noLink = false; $render = ($linking == 'linkonly') ? false : true; - $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); + $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); - $link['url'] = ml($src,array('cache'=>$cache)); + $link['url'] = ml($src, array('cache' => $cache)); - list($ext,$mime,$dl) = mimetype($src,false); - if(substr($mime,0,5) == 'image' && $render){ + list($ext, $mime) = mimetype($src, false); + if(substr($mime, 0, 5) == 'image' && $render) { // link only jpeg images // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; - }elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render){ + } elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render) { // don't link movies $noLink = true; - }else{ + } else { // add file icons - $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); + $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); $link['class'] .= ' mediafile mf_'.$class; } if($hash) $link['url'] .= '#'.$hash; //output formatted - if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; + if($linking == 'nolink' || $noLink) $this->doc .= $link['name']; else $this->doc .= $this->_formatLink($link); } @@ -867,7 +1144,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * * @author Andreas Gohr */ - function rss ($url,$params){ + function rss($url, $params) { global $lang; global $conf; @@ -876,17 +1153,21 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $feed->set_feed_url($url); //disable warning while fetching - if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } + if(!defined('DOKU_E_LEVEL')) { + $elvl = error_reporting(E_ERROR); + } $rc = $feed->init(); - if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } + if(isset($elvl)) { + error_reporting($elvl); + } //decide on start and end - if($params['reverse']){ - $mod = -1; - $start = $feed->get_item_quantity()-1; + if($params['reverse']) { + $mod = -1; + $start = $feed->get_item_quantity() - 1; $end = $start - ($params['max']); $end = ($end < -1) ? -1 : $end; - }else{ + } else { $mod = 1; $start = 0; $end = $feed->get_item_quantity(); @@ -894,36 +1175,38 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } $this->doc .= '
      '; - if($rc){ - for ($x = $start; $x != $end; $x += $mod) { + if($rc) { + for($x = $start; $x != $end; $x += $mod) { $item = $feed->get_item($x); $this->doc .= '
    • '; // support feeds without links $lnkurl = $item->get_permalink(); - if($lnkurl){ + if($lnkurl) { // title is escaped by SimplePie, we unescape here because it // is escaped again in externallink() FS#1705 - $this->externallink($item->get_permalink(), - html_entity_decode($item->get_title(), ENT_QUOTES, 'UTF-8')); - }else{ + $this->externallink( + $item->get_permalink(), + html_entity_decode($item->get_title(), ENT_QUOTES, 'UTF-8') + ); + } else { $this->doc .= ' '.$item->get_title(); } - if($params['author']){ + if($params['author']) { $author = $item->get_author(0); - if($author){ + if($author) { $name = $author->get_name(); if(!$name) $name = $author->get_email(); if($name) $this->doc .= ' '.$lang['by'].' '.$name; } } - if($params['date']){ + if($params['date']) { $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')'; } - if($params['details']){ + if($params['details']) { $this->doc .= '
      '; - if($conf['htmlok']){ + if($conf['htmlok']) { $this->doc .= $item->get_description(); - }else{ + } else { $this->doc .= strip_tags($item->get_description()); } $this->doc .= '
      '; @@ -931,11 +1214,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $this->doc .= '
    • '; } - }else{ + } else { $this->doc .= '
    • '; $this->doc .= ''.$lang['rssfailed'].''; $this->externallink($url); - if($conf['allowdebug']){ + if($conf['allowdebug']) { $this->doc .= ''; } $this->doc .= '
    • '; @@ -943,89 +1226,130 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $this->doc .= '
    '; } - // $numrows not yet implemented - function table_open($maxcols = null, $numrows = null, $pos = null){ - global $lang; + /** + * Start a table + * + * @param int $maxcols maximum number of columns + * @param int $numrows NOT IMPLEMENTED + * @param int $pos byte position in the original source + */ + function table_open($maxcols = null, $numrows = null, $pos = null) { // initialize the row counter used for classes $this->_counter['row_counter'] = 0; - $class = 'table'; - if ($pos !== null) { - $class .= ' ' . $this->startSectionEdit($pos, 'table'); + $class = 'table'; + if($pos !== null) { + $class .= ' '.$this->startSectionEdit($pos, 'table'); } - $this->doc .= '
    ' . - DOKU_LF; + $this->doc .= '
    '. + DOKU_LF; } - function table_close($pos = null){ + /** + * Close a table + * + * @param int $pos byte position in the original source + */ + function table_close($pos = null) { $this->doc .= '
    '.DOKU_LF; - if ($pos !== null) { + if($pos !== null) { $this->finishSectionEdit($pos); } } - function tablethead_open(){ - $this->doc .= DOKU_TAB . '' . DOKU_LF; + /** + * Open a table header + */ + function tablethead_open() { + $this->doc .= DOKU_TAB.''.DOKU_LF; } - function tablethead_close(){ - $this->doc .= DOKU_TAB . '' . DOKU_LF; + /** + * Close a table header + */ + function tablethead_close() { + $this->doc .= DOKU_TAB.''.DOKU_LF; } - function tablerow_open(){ + /** + * Open a table row + */ + function tablerow_open() { // initialize the cell counter used for classes $this->_counter['cell_counter'] = 0; - $class = 'row' . $this->_counter['row_counter']++; - $this->doc .= DOKU_TAB . '' . DOKU_LF . DOKU_TAB . DOKU_TAB; + $class = 'row'.$this->_counter['row_counter']++; + $this->doc .= DOKU_TAB.''.DOKU_LF.DOKU_TAB.DOKU_TAB; } - function tablerow_close(){ - $this->doc .= DOKU_LF . DOKU_TAB . '' . DOKU_LF; + /** + * Close a table row + */ + function tablerow_close() { + $this->doc .= DOKU_LF.DOKU_TAB.''.DOKU_LF; } - function tableheader_open($colspan = 1, $align = null, $rowspan = 1){ - $class = 'class="col' . $this->_counter['cell_counter']++; - if ( !is_null($align) ) { + /** + * Open a table header cell + * + * @param int $colspan + * @param string $align left|center|right + * @param int $rowspan + */ + function tableheader_open($colspan = 1, $align = null, $rowspan = 1) { + $class = 'class="col'.$this->_counter['cell_counter']++; + if(!is_null($align)) { $class .= ' '.$align.'align'; } $class .= '"'; - $this->doc .= ' 1 ) { - $this->_counter['cell_counter'] += $colspan-1; + $this->doc .= ' 1) { + $this->_counter['cell_counter'] += $colspan - 1; $this->doc .= ' colspan="'.$colspan.'"'; } - if ( $rowspan > 1 ) { + if($rowspan > 1) { $this->doc .= ' rowspan="'.$rowspan.'"'; } $this->doc .= '>'; } - function tableheader_close(){ + /** + * Close a table header cell + */ + function tableheader_close() { $this->doc .= ''; } - function tablecell_open($colspan = 1, $align = null, $rowspan = 1){ - $class = 'class="col' . $this->_counter['cell_counter']++; - if ( !is_null($align) ) { + /** + * Open a table cell + * + * @param int $colspan + * @param string $align left|center|right + * @param int $rowspan + */ + function tablecell_open($colspan = 1, $align = null, $rowspan = 1) { + $class = 'class="col'.$this->_counter['cell_counter']++; + if(!is_null($align)) { $class .= ' '.$align.'align'; } $class .= '"'; $this->doc .= ' 1 ) { - $this->_counter['cell_counter'] += $colspan-1; + if($colspan > 1) { + $this->_counter['cell_counter'] += $colspan - 1; $this->doc .= ' colspan="'.$colspan.'"'; } - if ( $rowspan > 1 ) { + if($rowspan > 1) { $this->doc .= ' rowspan="'.$rowspan.'"'; } $this->doc .= '>'; } - function tablecell_close(){ + /** + * Close a table cell + */ + function tablecell_close() { $this->doc .= ''; } - //---------------------------------------------------------- - // Utils + #region Utility functions /** * Build a link @@ -1034,29 +1358,29 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * * @author Andreas Gohr */ - function _formatLink($link){ + 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']); + 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']); + $link['title'] = str_replace('&amp;', '&', $link['title']); // be sure there are no bad chars in url or title // (we can't do this for name because it can contain an img tag) - $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); - $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); + $link['url'] = strtr($link['url'], array('>' => '%3E', '<' => '%3C', '"' => '%22')); + $link['title'] = strtr($link['title'], array('>' => '>', '<' => '<', '"' => '"')); - $ret = ''; + $ret = ''; $ret .= $link['pre']; $ret .= ' + * @param string $src media ID + * @param string $title descriptive text + * @param string $align left|center|right + * @param int $width width of media in pixel + * @param int $height height of media in pixel + * @param string $cache cache|recache|nocache + * @param bool $render should the media be embedded inline or just linked + * @return string */ - function _media ($src, $title=null, $align=null, $width=null, - $height=null, $cache=null, $render = true) { + function _media($src, $title = null, $align = null, $width = null, + $height = null, $cache = null, $render = true) { $ret = ''; - list($ext,$mime,$dl) = mimetype($src); - if(substr($mime,0,5) == 'image'){ + list($ext, $mime) = mimetype($src); + if(substr($mime, 0, 5) == 'image') { // first get the $title - if (!is_null($title)) { - $title = $this->_xmlEntities($title); - }elseif($ext == 'jpg' || $ext == 'jpeg'){ + if(!is_null($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)); + $jpeg = new JpegMeta(mediaFN($src)); if($jpeg !== false) $cap = $jpeg->getTitle(); - if($cap){ + if(!empty($cap)) { $title = $this->_xmlEntities($cap); } } - if (!$render) { + if(!$render) { // if the picture is not supposed to be rendered // return the title of the picture - if (!$title) { + if(!$title) { // just show the sourcename $title = $this->_xmlEntities(utf8_basename(noNS($src))); } return $title; } //add image tag - $ret .= ' $width, 'h' => $height, 'cache' => $cache)).'"'; $ret .= ' class="media'.$align.'"'; - if ($title) { - $ret .= ' title="' . $title . '"'; - $ret .= ' alt="' . $title .'"'; - }else{ + if($title) { + $ret .= ' title="'.$title.'"'; + $ret .= ' alt="'.$title.'"'; + } else { $ret .= ' alt=""'; } - if ( !is_null($width) ) + if(!is_null($width)) $ret .= ' width="'.$this->_xmlEntities($width).'"'; - if ( !is_null($height) ) + if(!is_null($height)) $ret .= ' height="'.$this->_xmlEntities($height).'"'; $ret .= ' />'; - }elseif(media_supportedav($mime, 'video') || media_supportedav($mime, 'audio')){ + } elseif(media_supportedav($mime, 'video') || media_supportedav($mime, 'audio')) { // first get the $title $title = !is_null($title) ? $this->_xmlEntities($title) : false; - if (!$render) { + 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 = array(); $att['class'] = "media$align"; - if ($title) { + if($title) { $att['title'] = $title; } - if (media_supportedav($mime, 'video')) { + if(media_supportedav($mime, 'video')) { //add video $ret .= $this->_video($src, $width, $height, $att); } - if (media_supportedav($mime, 'audio')) { + if(media_supportedav($mime, 'audio')) { //add audio $ret .= $this->_audio($src, $att); } - }elseif($mime == 'application/x-shockwave-flash'){ - if (!$render) { + } elseif($mime == 'application/x-shockwave-flash') { + if(!$render) { // if the flash is not supposed to be rendered // return the title of the flash - if (!$title) { + if(!$title) { // just show the sourcename $title = utf8_basename(noNS($src)); } return $this->_xmlEntities($title); } - $att = array(); + $att = array(); $att['class'] = "media$align"; if($align == 'right') $att['align'] = 'right'; - if($align == 'left') $att['align'] = 'left'; - $ret .= html_flashobject(ml($src,array('cache'=>$cache),true,'&'),$width,$height, - array('quality' => 'high'), - null, - $att, - $this->_xmlEntities($title)); - }elseif($title){ + if($align == 'left') $att['align'] = 'left'; + $ret .= html_flashobject( + ml($src, array('cache' => $cache), true, '&'), $width, $height, + array('quality' => 'high'), + null, + $att, + $this->_xmlEntities($title) + ); + } elseif($title) { // well at least we have a title to display $ret .= $this->_xmlEntities($title); - }else{ + } else { // just show the sourcename $ret .= $this->_xmlEntities(utf8_basename(noNS($src))); } @@ -1171,23 +1505,30 @@ class Doku_Renderer_xhtml extends Doku_Renderer { return $ret; } + /** + * Escape string for output + * + * @param $string + * @return string + */ function _xmlEntities($string) { - return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); + return htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); } /** * Creates a linkid from a headline * + * @author Andreas Gohr * @param string $title The headline title * @param boolean $create Create a new unique ID? - * @author Andreas Gohr + * @return string */ - function _headerToLink($title,$create=false) { - if($create){ - return sectionID($title,$this->headers); - }else{ + function _headerToLink($title, $create = false) { + if($create) { + return sectionID($title, $this->headers); + } else { $check = false; - return sectionID($title,$check); + return sectionID($title, $check); } } @@ -1195,18 +1536,22 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * Construct a title and handle images in titles * * @author Harry Fuecks + * @param string|array $title either string title or media array + * @param string $default default title if nothing else is found + * @param bool $isImage will be set to true if it's a media file + * @param null|string $id linked page id (used to extract title from first heading) + * @param string $linktype content|navigation + * @return string HTML of the title, might be full image tag or just escaped text */ - function _getLinkTitle($title, $default, & $isImage, $id=null, $linktype='content') { - global $conf; - + function _getLinkTitle($title, $default, &$isImage, $id = null, $linktype = 'content') { $isImage = false; - if ( is_array($title) ) { + if(is_array($title)) { $isImage = true; return $this->_imageTitle($title); - } elseif ( is_null($title) || trim($title)=='') { - if (useHeading($linktype) && $id) { + } elseif(is_null($title) || trim($title) == '') { + if(useHeading($linktype) && $id) { $heading = p_get_first_heading($id); - if ($heading) { + if($heading) { return $this->_xmlEntities($heading); } } @@ -1217,48 +1562,51 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } /** - * Returns an HTML code for images used in link titles + * Returns HTML code for images used in link titles * - * @todo Resolve namespace on internal images * @author Andreas Gohr + * @param string $img + * @return string HTML img tag or similar */ function _imageTitle($img) { global $ID; // some fixes on $img['src'] // see internalmedia() and externalmedia() - list($img['src'],$hash) = explode('#',$img['src'],2); - if ($img['type'] == 'internalmedia') { - resolve_mediaid(getNS($ID),$img['src'],$exists); + list($img['src']) = explode('#', $img['src'], 2); + if($img['type'] == 'internalmedia') { + resolve_mediaid(getNS($ID), $img['src'], $exists); } - return $this->_media($img['src'], - $img['title'], - $img['align'], - $img['width'], - $img['height'], - $img['cache']); + return $this->_media( + $img['src'], + $img['title'], + $img['align'], + $img['width'], + $img['height'], + $img['cache'] + ); } /** - * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia() - * which returns a basic link to a media. + * helperfunction to return a basic link to a media + * + * used in internalmedia() and externalmedia() * - * @author Pierre Spring - * @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 + * @author Pierre Spring + * @param string $src media ID + * @param string $title descriptive text + * @param string $align left|center|right + * @param int $width width of media in pixel + * @param int $height height of media in pixel + * @param string $cache cache|recache|nocache + * @param bool $render should the media be embedded inline or just linked + * @return array associative array with link config */ function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) { global $conf; - $link = array(); + $link = array(); $link['class'] = 'media'; $link['style'] = ''; $link['pre'] = ''; @@ -1271,50 +1619,49 @@ class Doku_Renderer_xhtml extends Doku_Renderer { return $link; } - /** * Embed video(s) in HTML * * @author Anika Henke * - * @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