summaryrefslogtreecommitdiff
path: root/inc/parser
diff options
context:
space:
mode:
authorlisps <stummp@loewen.de>2014-09-26 12:48:02 +0200
committerlisps <stummp@loewen.de>2014-09-26 12:48:02 +0200
commit8d39e80d363eda2ef31dac8473bfdab4b9cd7ce5 (patch)
tree7bab1caccbc0de7c30f0e610d1e5ee9b3c67d564 /inc/parser
parent115aab0f5fca76360c50f759f587229ff327105d (diff)
parent7b950f2d59050052c1d9251b0bd9bd40c7441040 (diff)
downloadrpg-8d39e80d363eda2ef31dac8473bfdab4b9cd7ce5.tar.gz
rpg-8d39e80d363eda2ef31dac8473bfdab4b9cd7ce5.tar.bz2
Merge remote-tracking branch master into revisions
Diffstat (limited to 'inc/parser')
-rw-r--r--inc/parser/code.php12
-rw-r--r--inc/parser/handler.php73
-rw-r--r--inc/parser/metadata.php575
-rw-r--r--inc/parser/parser.php5
-rw-r--r--inc/parser/renderer.php763
-rw-r--r--inc/parser/xhtml.php1030
6 files changed, 1791 insertions, 667 deletions
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/handler.php b/inc/parser/handler.php
index 8ae991209..a1040d12e 100644
--- a/inc/parser/handler.php
+++ b/inc/parser/handler.php
@@ -12,6 +12,7 @@ class Doku_Handler {
var $status = array(
'section' => false,
+ 'doublequote' => 0,
);
var $rewriteBlocks = true;
@@ -401,11 +402,17 @@ class Doku_Handler {
function doublequoteopening($match, $state, $pos) {
$this->_addCall('doublequoteopening',array(), $pos);
+ $this->status['doublequote']++;
return true;
}
function doublequoteclosing($match, $state, $pos) {
- $this->_addCall('doublequoteclosing',array(), $pos);
+ if ($this->status['doublequote'] <= 0) {
+ $this->doublequoteopening($match, $state, $pos);
+ } else {
+ $this->_addCall('doublequoteclosing',array(), $pos);
+ $this->status['doublequote'] = max(0, --$this->status['doublequote']);
+ }
return true;
}
@@ -1149,6 +1156,9 @@ class Doku_Handler_Table {
var $currentCols = 0;
var $firstCell = false;
var $lastCellType = 'tablecell';
+ var $inTableHead = true;
+ var $currentRow = array('tableheader' => 0, 'tablecell' => 0);
+ var $countTableHeadRows = 0;
function Doku_Handler_Table(& $CallWriter) {
$this->CallWriter = & $CallWriter;
@@ -1216,15 +1226,24 @@ class Doku_Handler_Table {
$this->firstCell = true;
$this->lastCellType = 'tablecell';
$this->maxRows++;
+ if ($this->inTableHead) {
+ $this->currentRow = array('tablecell' => 0, 'tableheader' => 0);
+ }
}
function tableRowClose($call) {
+ if ($this->inTableHead && ($this->inTableHead = $this->isTableHeadRow())) {
+ $this->countTableHeadRows++;
+ }
// Strip off final cell opening and anything after it
while ( $discard = array_pop($this->tableCalls ) ) {
if ( $discard[0] == 'tablecell_open' || $discard[0] == 'tableheader_open') {
break;
}
+ if (!empty($this->currentRow[$discard[0]])) {
+ $this->currentRow[$discard[0]]--;
+ }
}
$this->tableCalls[] = array('tablerow_close', array(), $call[2]);
@@ -1233,7 +1252,20 @@ class Doku_Handler_Table {
}
}
+ function isTableHeadRow() {
+ $td = $this->currentRow['tablecell'];
+ $th = $this->currentRow['tableheader'];
+
+ if (!$th || $td > 2) return false;
+ if (2*$td > $th) return false;
+
+ return true;
+ }
+
function tableCell($call) {
+ if ($this->inTableHead) {
+ $this->currentRow[$call[0]]++;
+ }
if ( !$this->firstCell ) {
// Increase the span
@@ -1281,6 +1313,13 @@ class Doku_Handler_Table {
$cellKey = array();
$toDelete = array();
+ // if still in tableheader, then there can be no table header
+ // as all rows can't be within <THEAD>
+ if ($this->inTableHead) {
+ $this->inTableHead = false;
+ $this->countTableHeadRows = 0;
+ }
+
// Look for the colspan elements and increment the colspan on the
// previous non-empty opening cell. Once done, delete all the cells
// that contain colspans
@@ -1288,6 +1327,14 @@ class Doku_Handler_Table {
$call = $this->tableCalls[$key];
switch ($call[0]) {
+ case 'table_open' :
+ if($this->countTableHeadRows) {
+ array_splice($this->tableCalls, $key+1, 0, array(
+ array('tablethead_open', array(), $call[2]))
+ );
+ }
+ break;
+
case 'tablerow_open':
$lastRow++;
@@ -1357,15 +1404,19 @@ class Doku_Handler_Table {
} else {
$spanning_cell = null;
- for($i = $lastRow-1; $i > 0; $i--) {
- if ( $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tablecell_open' || $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tableheader_open' ) {
+ // can't cross thead/tbody boundary
+ if (!$this->countTableHeadRows || ($lastRow-1 != $this->countTableHeadRows)) {
+ for($i = $lastRow-1; $i > 0; $i--) {
- if ($this->tableCalls[$cellKey[$i][$lastCell]][1][2] >= $lastRow - $i) {
- $spanning_cell = $i;
- break;
- }
+ if ( $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tablecell_open' || $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tableheader_open' ) {
+
+ if ($this->tableCalls[$cellKey[$i][$lastCell]][1][2] >= $lastRow - $i) {
+ $spanning_cell = $i;
+ break;
+ }
+ }
}
}
if (is_null($spanning_cell)) {
@@ -1396,6 +1447,10 @@ class Doku_Handler_Table {
$key += 3;
}
+ if($this->countTableHeadRows == $lastRow) {
+ array_splice($this->tableCalls, $key+1, 0, array(
+ array('tablethead_close', array(), $call[2])));
+ }
break;
}
@@ -1438,7 +1493,7 @@ class Doku_Handler_Block {
var $blockOpen = array(
'header',
'listu_open','listo_open','listitem_open','listcontent_open',
- 'table_open','tablerow_open','tablecell_open','tableheader_open',
+ 'table_open','tablerow_open','tablecell_open','tableheader_open','tablethead_open',
'quote_open',
'code','file','hr','preformatted','rss',
'htmlblock','phpblock',
@@ -1448,7 +1503,7 @@ class Doku_Handler_Block {
var $blockClose = array(
'header',
'listu_close','listo_close','listitem_close','listcontent_close',
- 'table_close','tablerow_close','tablecell_close','tableheader_close',
+ 'table_close','tablerow_close','tablecell_close','tableheader_close','tablethead_close',
'quote_close',
'code','file','hr','preformatted','rss',
'htmlblock','phpblock',
diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php
index 82a268fd6..25bf3fe3d 100644
--- a/inc/parser/metadata.php
+++ b/inc/parser/metadata.php
@@ -6,129 +6,198 @@
*/
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 MetaData Renderer
+ *
+ * Metadata is additional information about a DokuWiki page that gets extracted mainly from the page's content
+ * but also it's own filesystem data (like the creation time). All metadata is stored in the fields $meta and
+ * $persistent.
+ *
+ * Some simplified rendering to $doc is done to gather the page's (text-only) abstract.
*/
class Doku_Renderer_metadata extends Doku_Renderer {
+ /** the approximate byte lenght to capture for the abstract */
+ const ABSTRACT_LEN = 250;
+
+ /** the maximum UTF8 character length for the abstract */
+ const ABSTRACT_MAX = 500;
+
+ /** @var array transient meta data, will be reset on each rendering */
+ public $meta = array();
+
+ /** @var array persistent meta data, will be kept until explicitly deleted */
+ public $persistent = array();
- var $doc = '';
- var $meta = array();
- var $persistent = array();
+ /** @var array the list of headers used to create unique link ids */
+ protected $headers = array();
- var $headers = array();
- var $capture = true;
- var $store = '';
- var $firstimage = '';
+ /** @var string temporary $doc store */
+ protected $store = '';
- function getFormat(){
+ /** @var string keeps the first image reference */
+ protected $firstimage = '';
+
+ /** @var bool determines if enough data for the abstract was collected, yet */
+ public $capture = true;
+
+ /** @var int number of bytes captured for abstract */
+ protected $captured = 0;
+
+ /**
+ * Returns the format produced by this renderer.
+ *
+ * @return string always 'metadata'
+ */
+ function getFormat() {
return 'metadata';
}
- function document_start(){
+ /**
+ * Initialize the document
+ *
+ * Sets up some of the persistent info about the page if it doesn't exist, yet.
+ */
+ 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(){
+ /**
+ * Finalize the document
+ *
+ * Stores collected data in the metadata
+ */
+ 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)
- $this->doc = utf8_substr($this->doc, 0, 500).'…';
+ if(strlen($this->doc) > self::ABSTRACT_MAX) {
+ $this->doc = utf8_substr($this->doc, 0, self::ABSTRACT_MAX).'…';
+ }
$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));
}
}
+ /**
+ * Render plain text data
+ *
+ * This function takes care of the amount captured data and will stop capturing when
+ * enough abstract data is available
+ *
+ * @param $text
+ */
+ function cdata($text) {
+ if(!$this->capture) return;
+
+ $this->doc .= $text;
+
+ $this->captured += strlen($text);
+ if($this->captured > self::ABSTRACT_LEN) $this->capture = false;
+ }
+
+ /**
+ * 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;
//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
);
}
}
+ /**
+ * 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) {
- 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;
+ $this->cdata(DOKU_LF.$text.DOKU_LF);
}
- function section_open($level){}
- function section_close(){}
-
- function cdata($text){
- if ($this->capture) $this->doc .= $text;
- }
-
- function p_open(){
- if ($this->capture) $this->doc .= DOKU_LF;
+ /**
+ * Open a paragraph
+ */
+ function p_open() {
+ $this->cdata(DOKU_LF);
}
- function p_close(){
- if ($this->capture){
- if (strlen($this->doc) > 250) $this->capture = false;
- else $this->doc .= DOKU_LF;
- }
+ /**
+ * Close a paragraph
+ */
+ function p_close() {
+ $this->cdata(DOKU_LF);
}
- function linebreak(){
- if ($this->capture) $this->doc .= DOKU_LF;
+ /**
+ * Create a line break
+ */
+ function linebreak() {
+ $this->cdata(DOKU_LF);
}
- function hr(){
- if ($this->capture){
- if (strlen($this->doc) > 250) $this->capture = false;
- else $this->doc .= DOKU_LF.'----------'.DOKU_LF;
- }
+ /**
+ * Create a horizontal line
+ */
+ function hr() {
+ $this->cdata(DOKU_LF.'----------'.DOKU_LF);
}
/**
@@ -141,7 +210,7 @@ class Doku_Renderer_metadata extends Doku_Renderer {
* @author Andreas Gohr <andi@splitbrain.org>
*/
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 +226,214 @@ 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_close(){
- if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false;
- }
-
- function listo_open(){
- if ($this->capture) $this->doc .= DOKU_LF;
- }
-
- function listo_close(){
- if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false;
+ /**
+ * Open an unordered list
+ */
+ function listu_open() {
+ $this->cdata(DOKU_LF);
}
- function listitem_open($level){
- if ($this->capture) $this->doc .= str_repeat(DOKU_TAB, $level).'* ';
+ /**
+ * Open an ordered list
+ */
+ function listo_open() {
+ $this->cdata(DOKU_LF);
}
- function listitem_close(){
- if ($this->capture) $this->doc .= DOKU_LF;
+ /**
+ * Open a list item
+ *
+ * @param int $level the nesting level
+ */
+ function listitem_open($level) {
+ $this->cdata(str_repeat(DOKU_TAB, $level).'* ');
}
- function listcontent_open(){}
- function listcontent_close(){}
-
- function unformatted($text){
- if ($this->capture) $this->doc .= $text;
+ /**
+ * Close a list item
+ */
+ function listitem_close() {
+ $this->cdata(DOKU_LF);
}
- function preformatted($text){
- if ($this->capture) $this->doc .= $text;
+ /**
+ * Output preformatted text
+ *
+ * @param string $text
+ */
+ function preformatted($text) {
+ $this->cdata($text);
}
- function file($text, $lang = null, $file = null){
- if ($this->capture){
- $this->doc .= DOKU_LF.$text;
- if (strlen($this->doc) > 250) $this->capture = false;
- else $this->doc .= DOKU_LF;
- }
+ /**
+ * Start a block quote
+ */
+ function quote_open() {
+ $this->cdata(DOKU_LF.DOKU_TAB.'"');
}
- function quote_open(){
- if ($this->capture) $this->doc .= DOKU_LF.DOKU_TAB.'"';
+ /**
+ * Stop a block quote
+ */
+ function quote_close() {
+ $this->cdata('"'.DOKU_LF);
}
- function quote_close(){
- if ($this->capture){
- $this->doc .= '"';
- if (strlen($this->doc) > 250) $this->capture = false;
- else $this->doc .= DOKU_LF;
- }
+ /**
+ * 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) {
+ $this->cdata(DOKU_LF.$text.DOKU_LF);
}
- function code($text, $language = null, $file = null){
- if ($this->capture){
- $this->doc .= DOKU_LF.$text;
- if (strlen($this->doc) > 250) $this->capture = false;
- else $this->doc .= DOKU_LF;
- }
+ /**
+ * 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 $file file path label
+ */
+ function code($text, $language = null, $file = null) {
+ $this->cdata(DOKU_LF.$text.DOKU_LF);
}
- function acronym($acronym){
- if ($this->capture) $this->doc .= $acronym;
+ /**
+ * Format an acronym
+ *
+ * Uses $this->acronyms
+ *
+ * @param string $acronym
+ */
+ function acronym($acronym) {
+ $this->cdata($acronym);
}
- function smiley($smiley){
- if ($this->capture) $this->doc .= $smiley;
+ /**
+ * Format a smiley
+ *
+ * Uses $this->smiley
+ *
+ * @param string $smiley
+ */
+ function smiley($smiley) {
+ $this->cdata($smiley);
}
- function entity($entity){
- if ($this->capture) $this->doc .= $entity;
+ /**
+ * Format an entity
+ *
+ * Entities are basically small text replacements
+ *
+ * Uses $this->entities
+ *
+ * @param string $entity
+ */
+ function entity($entity) {
+ $this->cdata($entity);
}
- function multiplyentity($x, $y){
- if ($this->capture) $this->doc .= $x.'×'.$y;
+ /**
+ * 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->cdata($x.'×'.$y);
}
- function singlequoteopening(){
+ /**
+ * Render an opening single quote char (language specific)
+ */
+ function singlequoteopening() {
global $lang;
- if ($this->capture) $this->doc .= $lang['singlequoteopening'];
+ $this->cdata($lang['singlequoteopening']);
}
- function singlequoteclosing(){
+ /**
+ * Render a closing single quote char (language specific)
+ */
+ function singlequoteclosing() {
global $lang;
- if ($this->capture) $this->doc .= $lang['singlequoteclosing'];
+ $this->cdata($lang['singlequoteclosing']);
}
+ /**
+ * Render an apostrophe char (language specific)
+ */
function apostrophe() {
global $lang;
- if ($this->capture) $this->doc .= $lang['apostrophe'];
+ $this->cdata($lang['apostrophe']);
}
- function doublequoteopening(){
+ /**
+ * Render an opening double quote char (language specific)
+ */
+ function doublequoteopening() {
global $lang;
- if ($this->capture) $this->doc .= $lang['doublequoteopening'];
+ $this->cdata($lang['doublequoteopening']);
}
- function doublequoteclosing(){
+ /**
+ * Render an closinging double quote char (language specific)
+ */
+ function doublequoteclosing() {
global $lang;
- if ($this->capture) $this->doc .= $lang['doublequoteclosing'];
+ $this->cdata($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);
}
- 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) {
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']
+ *
+ * @param string $id page ID to link to. eg. 'wiki:syntax'
+ * @param string|array $name name for the link, array for media file
*/
- 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];
}
@@ -299,7 +441,7 @@ class Doku_Renderer_metadata extends Doku_Renderer {
// first resolve and clean up the $id
resolve_pageid(getNS($ID), $id, $exists);
- @list($page, $hash) = explode('#', $id, 2);
+ @list($page) = explode('#', $id, 2);
// set metadata
$this->meta['relation']['references'][$page] = $exists;
@@ -307,84 +449,141 @@ 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){
+ /**
+ * 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) {
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){
+ /**
+ * 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) {
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){
- list($wikiUri, $hash) = explode('#', $wikiUri, 2);
+ if($this->capture) {
+ list($wikiUri) = explode('#', $wikiUri, 2);
$name = $this->_getLinkTitle($name, $wikiUri);
$this->doc .= $name;
}
}
- function windowssharelink($url, $name = null){
+ /**
+ * 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) {
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){
+ /**
+ * Render a linked E-Mail Address
+ *
+ * Should honor $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) {
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.']';
+ /**
+ * 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) {
+ 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.']';
+ /**
+ * 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) {
+ if($this->capture && $title) $this->doc .= '['.$title.']';
$this->_firstimage($src);
}
- function rss($url,$params) {
+ /**
+ * 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) {
$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'];
}
- //----------------------------------------------------------
- // Utils
+ #region Utils
/**
* Removes any Namespace from the given name but keeps
@@ -392,35 +591,36 @@ class Doku_Renderer_metadata extends Doku_Renderer {
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
- 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;
}
/**
* Creates a linkid from a headline
*
+ * @author Andreas Gohr <andi@splitbrain.org>
* @param string $title The headline title
* @param boolean $create Create a new unique ID?
- * @author Andreas Gohr <andi@splitbrain.org>
+ * @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);
}
}
@@ -428,17 +628,22 @@ class Doku_Renderer_metadata extends Doku_Renderer {
* Construct a title and handle images in titles
*
* @author Harry Fuecks <hfuecks@gmail.com>
+ * @param string|array $title either string title or media array
+ * @param string $default default title if nothing else is found
+ * @param null|string $id linked page id (used to extract title from first heading)
+ * @return string title text
*/
- function _getLinkTitle($title, $default, $id=null) {
- global $conf;
-
- $isImage = false;
- 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;
+ function _getLinkTitle($title, $default, $id = null) {
+ if(is_array($title)) {
+ if($title['title']) {
+ return '['.$title['title'].']';
+ } else {
+ return $default;
+ }
+ } 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,27 +651,39 @@ class Doku_Renderer_metadata extends Doku_Renderer {
}
}
- function _firstimage($src){
+ /**
+ * Remember first image
+ *
+ * @param string $src image URL or ID
+ */
+ 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) = 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;
}
}
+ /**
+ * Store list of used media files in metadata
+ *
+ * @param string $src media ID
+ */
function _recordMediaUsage($src) {
global $ID;
- list ($src, $hash) = explode('#', $src, 2);
- if (media_isexternal($src)) return;
+ list ($src) = explode('#', $src, 2);
+ if(media_isexternal($src)) return;
resolve_mediaid(getNS($ID), $src, $exists);
$this->meta['relation']['media'][$src] = $exists;
}
+
+ #endregion
}
//Setup VIM: ex: et ts=4 :
diff --git a/inc/parser/parser.php b/inc/parser/parser.php
index 252bd9170..df01f3302 100644
--- a/inc/parser/parser.php
+++ b/inc/parser/parser.php
@@ -200,6 +200,11 @@ class Doku_Parser_Mode_Plugin extends DokuWiki_Plugin implements Doku_Parser_Mod
var $Lexer;
var $allowedModes = array();
+ /**
+ * Sort for applying this mode
+ *
+ * @return int
+ */
function getSort() {
trigger_error('getSort() not implemented in '.get_class($this), E_USER_WARNING);
}
diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php
index 0c3c56c56..09294539e 100644
--- a/inc/parser/renderer.php
+++ b/inc/parser/renderer.php
@@ -11,259 +11,748 @@ if(!defined('DOKU_INC')) die('meh.');
* An empty renderer, produces no output
*
* Inherits from DokuWiki_Plugin for giving additional functions to render plugins
+ *
+ * The renderer transforms the syntax instructions created by the parser and handler into the
+ * desired output format. For each instruction a corresponding method defined in this class will
+ * be called. That method needs to produce the desired output for the instruction and add it to the
+ * $doc field. When all instructions are processed, the $doc field contents will be cached by
+ * DokuWiki and sent to the user.
*/
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(){
+ 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
+ * @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 = '') {
+ /** @var DokuWiki_Syntax_Plugin $plugin */
+ $plugin = plugin_load('syntax', $name);
+ if($plugin != null) {
+ $plugin->render($this->getFormat(), $this, $data);
}
}
/**
* 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 ) {
+ 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());
}
}
}
- // 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() {}
+ /**
+ * 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 document_start() {}
+ #region Syntax modes - sub classes will need to implement them to fill $doc
- function document_end() {}
+ /**
+ * Initialize the document
+ */
+ function document_start() {
+ }
- function render_TOC() { return ''; }
+ /**
+ * Finalize the document
+ */
+ function document_end() {
+ }
- function toc_additem($id, $text, $level) {}
+ /**
+ * Render the Table of Contents
+ *
+ * @return string
+ */
+ function render_TOC() {
+ return '';
+ }
- function header($text, $level, $pos) {}
+ /**
+ * 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) {
+ }
- function section_open($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) {
+ }
- function section_close() {}
+ /**
+ * Open a new section
+ *
+ * @param int $level section level (as determined by the previous header)
+ */
+ function section_open($level) {
+ }
- function cdata($text) {}
+ /**
+ * Close the current section
+ */
+ function section_close() {
+ }
- function p_open() {}
+ /**
+ * Render plain text data
+ *
+ * @param $text
+ */
+ function cdata($text) {
+ }
- function p_close() {}
+ /**
+ * Open a paragraph
+ */
+ function p_open() {
+ }
- function linebreak() {}
+ /**
+ * Close a paragraph
+ */
+ function p_close() {
+ }
- function hr() {}
+ /**
+ * Create a line break
+ */
+ function linebreak() {
+ }
- function strong_open() {}
+ /**
+ * Create a horizontal line
+ */
+ function hr() {
+ }
- function strong_close() {}
+ /**
+ * Start strong (bold) formatting
+ */
+ function strong_open() {
+ }
- function emphasis_open() {}
+ /**
+ * Stop strong (bold) formatting
+ */
+ function strong_close() {
+ }
- function emphasis_close() {}
+ /**
+ * Start emphasis (italics) formatting
+ */
+ function emphasis_open() {
+ }
- function underline_open() {}
+ /**
+ * Stop emphasis (italics) formatting
+ */
+ function emphasis_close() {
+ }
- function underline_close() {}
+ /**
+ * Start underline formatting
+ */
+ function underline_open() {
+ }
- function monospace_open() {}
+ /**
+ * Stop underline formatting
+ */
+ function underline_close() {
+ }
- function monospace_close() {}
+ /**
+ * Start monospace formatting
+ */
+ function monospace_open() {
+ }
- function subscript_open() {}
+ /**
+ * Stop monospace formatting
+ */
+ function monospace_close() {
+ }
- function subscript_close() {}
+ /**
+ * Start a subscript
+ */
+ function subscript_open() {
+ }
- function superscript_open() {}
+ /**
+ * Stop a subscript
+ */
+ function subscript_close() {
+ }
- function superscript_close() {}
+ /**
+ * Start a superscript
+ */
+ function superscript_open() {
+ }
- function deleted_open() {}
+ /**
+ * Stop a superscript
+ */
+ function superscript_close() {
+ }
- function deleted_close() {}
+ /**
+ * Start deleted (strike-through) formatting
+ */
+ function deleted_open() {
+ }
- function footnote_open() {}
+ /**
+ * Stop deleted (strike-through) formatting
+ */
+ function deleted_close() {
+ }
- function footnote_close() {}
+ /**
+ * Start a footnote
+ */
+ function footnote_open() {
+ }
- function listu_open() {}
+ /**
+ * Stop a footnote
+ */
+ function footnote_close() {
+ }
- function listu_close() {}
+ /**
+ * Open an unordered list
+ */
+ function listu_open() {
+ }
- function listo_open() {}
+ /**
+ * Close an unordered list
+ */
+ function listu_close() {
+ }
- function listo_close() {}
+ /**
+ * Open an ordered list
+ */
+ function listo_open() {
+ }
- function listitem_open($level) {}
+ /**
+ * Close an ordered list
+ */
+ function listo_close() {
+ }
- function listitem_close() {}
+ /**
+ * Open a list item
+ *
+ * @param int $level the nesting level
+ */
+ function listitem_open($level) {
+ }
- function listcontent_open() {}
+ /**
+ * Close a list item
+ */
+ function listitem_close() {
+ }
- function listcontent_close() {}
+ /**
+ * Start the content of a list item
+ */
+ function listcontent_open() {
+ }
- function unformatted($text) {}
+ /**
+ * Stop the content of a list item
+ */
+ function listcontent_close() {
+ }
- function php($text) {}
+ /**
+ * Output unformatted $text
+ *
+ * Defaults to $this->cdata()
+ *
+ * @param string $text
+ */
+ function unformatted($text) {
+ $this->cdata($text);
+ }
- function phpblock($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) {
+ }
- function html($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) {
+ }
- function htmlblock($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) {
+ }
- function preformatted($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) {
+ }
- function quote_open() {}
+ /**
+ * Output preformatted text
+ *
+ * @param string $text
+ */
+ function preformatted($text) {
+ }
- function quote_close() {}
+ /**
+ * Start a block quote
+ */
+ function quote_open() {
+ }
- function file($text, $lang = null, $file = null ) {}
+ /**
+ * Stop a block quote
+ */
+ function quote_close() {
+ }
- function code($text, $lang = null, $file = null ) {}
+ /**
+ * 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) {
+ }
- function acronym($acronym) {}
+ /**
+ * 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) {
+ }
- function smiley($smiley) {}
+ /**
+ * Format an acronym
+ *
+ * Uses $this->acronyms
+ *
+ * @param string $acronym
+ */
+ function acronym($acronym) {
+ }
- function wordblock($word) {}
+ /**
+ * Format a smiley
+ *
+ * Uses $this->smiley
+ *
+ * @param string $smiley
+ */
+ function smiley($smiley) {
+ }
- function entity($entity) {}
+ /**
+ * Format an entity
+ *
+ * Entities are basically small text replacements
+ *
+ * Uses $this->entities
+ *
+ * @param string $entity
+ */
+ function entity($entity) {
+ }
- // 640x480 ($x=640, $y=480)
- function multiplyentity($x, $y) {}
+ /**
+ * 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) {
+ }
- function singlequoteopening() {}
+ /**
+ * Render an opening single quote char (language specific)
+ */
+ function singlequoteopening() {
+ }
- function singlequoteclosing() {}
+ /**
+ * Render a closing single quote char (language specific)
+ */
+ function singlequoteclosing() {
+ }
- function apostrophe() {}
+ /**
+ * Render an apostrophe char (language specific)
+ */
+ function apostrophe() {
+ }
- function doublequoteopening() {}
+ /**
+ * Render an opening double quote char (language specific)
+ */
+ function doublequoteopening() {
+ }
- function doublequoteclosing() {}
+ /**
+ * Render an closinging double quote char (language specific)
+ */
+ function doublequoteclosing() {
+ }
- // $link like 'SomePage'
- function camelcaselink($link) {}
+ /**
+ * Render a CamelCase link
+ *
+ * @param string $link The link name
+ * @see http://en.wikipedia.org/wiki/CamelCase
+ */
+ function camelcaselink($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) {
+ }
- // $link like 'wiki:syntax', $title could be an array (media)
- function internallink($link, $title = null) {}
+ /**
+ * 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) {
+ }
+
+ /**
+ * 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) {
+ }
- // $link is full URL with scheme, $title could be an array (media)
- 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) {
+ }
- function rss ($url,$params) {}
+ /**
+ * 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 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) {}
+ /**
+ * 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 file on users OS, $title could be an array (media)
- function filelink($link, $title = null) {}
+ /**
+ * 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) {
+ }
- // Link to a Windows share, , $title could be an array (media)
- function windowssharelink($link, $title = null) {}
+ /**
+ * Render a linked E-Mail Address
+ *
+ * Should honor $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) {
+ }
-// function email($address, $title = null) {}
- 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) {
+ }
- 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 externalmedia ($src, $title=null, $align=null, $width=null,
- $height=null, $cache=null, $linking=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 internalmedialink (
- $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) {
+ }
- 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) {
+ }
- 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) {
+ }
- function table_close($pos = null){}
+ /**
+ * Open a table header
+ */
+ function tablethead_open() {
+ }
- function tablerow_open(){}
+ /**
+ * Close a table header
+ */
+ function tablethead_close() {
+ }
- function tablerow_close(){}
+ /**
+ * Open a table row
+ */
+ function tablerow_open() {
+ }
- function tableheader_open($colspan = 1, $align = null, $rowspan = 1){}
+ /**
+ * Close a table row
+ */
+ function tablerow_close() {
+ }
- function tableheader_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) {
+ }
- function tablecell_open($colspan = 1, $align = null, $rowspan = 1){}
+ /**
+ * Close a table header cell
+ */
+ function tableheader_close() {
+ }
- function tablecell_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
@@ -290,13 +779,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}&amp;btnI=lucky';
+ $url = 'http://www.google.com/search?q={URL}&amp;btnI=lucky';
$shortcut = 'go';
}
@@ -306,8 +795,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);
@@ -317,18 +806,20 @@ 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;
}
+
+ #endregion
}
diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php
index dee3c922d..078bb5639 100644
--- a/inc/parser/xhtml.php
+++ b/inc/parser/xhtml.php
@@ -7,38 +7,54 @@
*/
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();
- // @access public
- var $doc = ''; // will contain the whole document
- var $toc = array(); // will contain the Table of Contents
+ /** @var array A stack of section edit data */
+ protected $sectionedits = array();
var $date_at = ''; // link pages and media against this revision
- var $sectionedits = array(); // A stack of section edit data
- private $lastsecid = 0; // last section edit id, used by startSectionEdit
+ /** @var int last section edit id, used by startSectionEdit */
+ protected $lastsecid = 0;
+
+ /** @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
@@ -51,43 +67,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 <lang@cosmocode.de>
*/
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 .= "<!-- EDIT$id " . strtoupper($type) . ' ';
- if (!is_null($title)) {
- $this->doc .= '"' . str_replace('"', '', $title) . '" ';
+ $this->doc .= "<!-- EDIT$id ".strtoupper($type).' ';
+ if(!is_null($title)) {
+ $this->doc .= '"'.str_replace('"', '', $title).'" ';
}
- $this->doc .= "[$start-" . (is_null($end) ? '' : $end) . '] -->';
+ $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);
@@ -96,12 +122,12 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
}
}
- if ( count ($this->footnotes) > 0 ) {
+ if(count($this->footnotes) > 0) {
$this->doc .= '<div class="footnotes">'.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 .= '<div class="fn">';
@@ -111,8 +137,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 .= ', <sup><a href="#fnt__'.($ref).'" id="fn__'.($ref).'" class="fn_bot">';
$this->doc .= ($ref).')</a></sup> '.DOKU_LF;
@@ -121,7 +147,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
// add footnote markup and close this footnote
$this->doc .= $footnote;
- $this->doc .= '</div>' . DOKU_LF;
+ $this->doc .= '</div>'.DOKU_LF;
}
}
$this->doc .= '</div>'.DOKU_LF;
@@ -129,139 +155,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('#<p>\s*</p>#','',$this->doc);
+ $this->doc = preg_replace('#<p>\s*</p>#', '', $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.'<h'.$level;
- if ($level <= $conf['maxseclevel']) {
- $this->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 .= "</h$level>".DOKU_LF;
}
+ /**
+ * Open a new section
+ *
+ * @param int $level section level (as determined by the previous header)
+ */
function section_open($level) {
- $this->doc .= '<div class="level' . $level . '">' . DOKU_LF;
+ $this->doc .= '<div class="level'.$level.'">'.DOKU_LF;
}
+ /**
+ * Close the current section
+ */
function section_close() {
$this->doc .= DOKU_LF.'</div>'.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.'<p>'.DOKU_LF;
}
+ /**
+ * Close a paragraph
+ */
function p_close() {
$this->doc .= DOKU_LF.'</p>'.DOKU_LF;
}
+ /**
+ * Create a line break
+ */
function linebreak() {
$this->doc .= '<br/>'.DOKU_LF;
}
+ /**
+ * Create a horizontal line
+ */
function hr() {
$this->doc .= '<hr />'.DOKU_LF;
}
+ /**
+ * Start strong (bold) formatting
+ */
function strong_open() {
$this->doc .= '<strong>';
}
+ /**
+ * Stop strong (bold) formatting
+ */
function strong_close() {
$this->doc .= '</strong>';
}
+ /**
+ * Start emphasis (italics) formatting
+ */
function emphasis_open() {
$this->doc .= '<em>';
}
+ /**
+ * Stop emphasis (italics) formatting
+ */
function emphasis_close() {
$this->doc .= '</em>';
}
+ /**
+ * Start underline formatting
+ */
function underline_open() {
$this->doc .= '<em class="u">';
}
+ /**
+ * Stop underline formatting
+ */
function underline_close() {
$this->doc .= '</em>';
}
+ /**
+ * Start monospace formatting
+ */
function monospace_open() {
$this->doc .= '<code>';
}
+ /**
+ * Stop monospace formatting
+ */
function monospace_close() {
$this->doc .= '</code>';
}
+ /**
+ * Start a subscript
+ */
function subscript_open() {
$this->doc .= '<sub>';
}
+ /**
+ * Stop a subscript
+ */
function subscript_close() {
$this->doc .= '</sub>';
}
+ /**
+ * Start a superscript
+ */
function superscript_open() {
$this->doc .= '<sup>';
}
+ /**
+ * Stop a superscript
+ */
function superscript_close() {
$this->doc .= '</sup>';
}
+ /**
+ * Start deleted (strike-through) formatting
+ */
function deleted_open() {
$this->doc .= '<del>';
}
+ /**
+ * Stop deleted (strike-through) formatting
+ */
function deleted_close() {
$this->doc .= '</del>';
}
@@ -297,14 +405,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 {
@@ -316,38 +424,71 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$this->doc .= '<sup><a href="#fn__'.$fnid.'" id="fnt__'.$fnid.'" class="fn_top">'.$fnid.')</a></sup>';
}
+ /**
+ * Open an unordered list
+ */
function listu_open() {
$this->doc .= '<ul>'.DOKU_LF;
}
+ /**
+ * Close an unordered list
+ */
function listu_close() {
$this->doc .= '</ul>'.DOKU_LF;
}
+ /**
+ * Open an ordered list
+ */
function listo_open() {
$this->doc .= '<ol>'.DOKU_LF;
}
+ /**
+ * Close an ordered list
+ */
function listo_close() {
$this->doc .= '</ol>'.DOKU_LF;
}
+ /**
+ * Open a list item
+ *
+ * @param int $level the nesting level
+ */
function listitem_open($level) {
$this->doc .= '<li class="level'.$level.'">';
}
+ /**
+ * Close a list item
+ */
function listitem_close() {
$this->doc .= '</li>'.DOKU_LF;
}
+ /**
+ * Start the content of a list item
+ */
function listcontent_open() {
$this->doc .= '<div class="li">';
}
+ /**
+ * Stop the content of a list item
+ */
function listcontent_close() {
$this->doc .= '</div>'.DOKU_LF;
}
+ /**
+ * Output unformatted $text
+ *
+ * Defaults to $this->cdata()
+ *
+ * @param string $text
+ */
function unformatted($text) {
$this->doc .= $this->_xmlEntities($text);
}
@@ -355,15 +496,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 <andi@splitbrain.org>
*/
- 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();
@@ -373,6 +514,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');
}
@@ -380,75 +529,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 <andi@splitbrain.org>
*/
- 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 .= '<blockquote><div class="no">'.DOKU_LF;
}
+ /**
+ * Stop a block quote
+ */
function quote_close() {
$this->doc .= '</div></blockquote>'.DOKU_LF;
}
+ /**
+ * Output preformatted text
+ *
+ * @param string $text
+ */
function preformatted($text) {
- $this->doc .= '<pre class="code">' . trim($this->_xmlEntities($text),"\n\r") . '</pre>'. DOKU_LF;
+ $this->doc .= '<pre class="code">'.trim($this->_xmlEntities($text), "\n\r").'</pre>'.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 <andi@splitbrain.org>
+ * @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 .= '<dl class="'.$type.'">'.DOKU_LF;
- $this->doc .= '<dt><a href="'.exportlink($ID,'code',array('codeblock'=>$this->_codeblock)).'" title="'.$lang['download'].'" class="'.$class.'">';
+ $this->doc .= '<dt><a href="'.exportlink($ID, 'code', array('codeblock' => $this->_codeblock)).'" title="'.$lang['download'].'" class="'.$class.'">';
$this->doc .= hsc($filename);
$this->doc .= '</a></dt>'.DOKU_LF.'<dd>';
}
- 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 .= '<pre class="'.$type.'">'.$this->_xmlEntities($text).'</pre>'.DOKU_LF;
} else {
$class = 'code'; //we always need the code class to make the syntax highlighting apply
@@ -457,16 +641,23 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$this->doc .= "<pre class=\"$class $language\">".p_xhtml_cached_geshi($text, $language, '').'</pre>'.DOKU_LF;
}
- if($filename){
+ if($filename) {
$this->doc .= '</dd></dl>'.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]);
@@ -478,73 +669,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 .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley].
'" class="icon" alt="'.
- $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&times;$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);
@@ -560,23 +787,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 <andi@splitbrain.org>
+ * @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];
}
@@ -584,7 +811,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;
}
@@ -592,22 +819,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,$this->date_at,true);
+ resolve_pageid(getNS($ID), $id, $exists, $this->date_at, true);
$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
@@ -616,9 +843,9 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$link['pre'] = '';
$link['suf'] = '';
// highlight link to current page
- if ($id == $INFO['id']) {
- $link['pre'] = '<span class="curid">';
- $link['suf'] = '</span>';
+ if($id == $INFO['id']) {
+ $link['pre'] = '<span class="curid">';
+ $link['suf'] = '</span>';
}
$link['more'] = '';
$link['class'] = $class;
@@ -629,27 +856,33 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$link['name'] = $name;
$link['title'] = $id;
//add search string
- if($search){
- ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&amp;';
- if(is_array($search)){
- $search = array_map('rawurlencode',$search);
- $link['url'] .= 's[]='.join('&amp;s[]=',$search);
- }else{
+ if($search) {
+ ($conf['userewrite']) ? $link['url'] .= '?' : $link['url'] .= '&amp;';
+ if(is_array($search)) {
+ $search = array_map('rawurlencode', $search);
+ $link['url'] .= 's[]='.join('&amp;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;
@@ -657,21 +890,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
@@ -683,8 +916,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
@@ -692,11 +925,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'] = '';
@@ -705,10 +946,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';
@@ -727,7 +968,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
}
}
- $link['url'] = $url;
+ $link['url'] = $url;
$link['title'] = htmlspecialchars($link['url']);
//output formatted
@@ -735,54 +976,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;
}
@@ -796,73 +1049,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,$this->date_at,true);
+ list($src, $hash) = explode('#', $src, 2);
+ resolve_mediaid(getNS($ID), $src, $exists, $this->date_at, true);
$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,'rev'=>$this->_getLastMediaRevisionAt($src)),($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, 'rev'=>$this->_getLastMediaRevisionAt($src)), ($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,'rev'=>$this->_getLastMediaRevisionAt($src)),true);
- if ($exists) $link['title'] .= ' (' . filesize_h(filesize(mediaFN($src))).')';
+ $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache , 'rev'=>$this->_getLastMediaRevisionAt($src)), 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);
}
@@ -871,7 +1148,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
- function rss ($url,$params){
+ function rss($url, $params) {
global $lang;
global $conf;
@@ -880,17 +1157,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();
@@ -898,36 +1179,38 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
}
$this->doc .= '<ul class="rss">';
- 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 .= '<li><div class="li">';
// 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 .= '<div class="detail">';
- if($conf['htmlok']){
+ if($conf['htmlok']) {
$this->doc .= $item->get_description();
- }else{
+ } else {
$this->doc .= strip_tags($item->get_description());
}
$this->doc .= '</div>';
@@ -935,11 +1218,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$this->doc .= '</div></li>';
}
- }else{
+ } else {
$this->doc .= '<li><div class="li">';
$this->doc .= '<em>'.$lang['rssfailed'].'</em>';
$this->externallink($url);
- if($conf['allowdebug']){
+ if($conf['allowdebug']) {
$this->doc .= '<!--'.hsc($feed->error).'-->';
}
$this->doc .= '</div></li>';
@@ -947,81 +1230,130 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$this->doc .= '</ul>';
}
- // $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 .= '<div class="' . $class . '"><table class="inline">' .
- DOKU_LF;
+ $this->doc .= '<div class="'.$class.'"><table class="inline">'.
+ 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 .= '</table></div>'.DOKU_LF;
- if ($pos !== null) {
+ if($pos !== null) {
$this->finishSectionEdit($pos);
}
}
- function tablerow_open(){
+ /**
+ * Open a table header
+ */
+ function tablethead_open() {
+ $this->doc .= DOKU_TAB.'<thead>'.DOKU_LF;
+ }
+
+ /**
+ * Close a table header
+ */
+ function tablethead_close() {
+ $this->doc .= DOKU_TAB.'</thead>'.DOKU_LF;
+ }
+
+ /**
+ * 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 . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB;
+ $class = 'row'.$this->_counter['row_counter']++;
+ $this->doc .= DOKU_TAB.'<tr class="'.$class.'">'.DOKU_LF.DOKU_TAB.DOKU_TAB;
}
- function tablerow_close(){
- $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF;
+ /**
+ * Close a table row
+ */
+ function tablerow_close() {
+ $this->doc .= DOKU_LF.DOKU_TAB.'</tr>'.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 .= '<th ' . $class;
- if ( $colspan > 1 ) {
- $this->_counter['cell_counter'] += $colspan-1;
+ $this->doc .= '<th '.$class;
+ 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 tableheader_close(){
+ /**
+ * Close a table header cell
+ */
+ function tableheader_close() {
$this->doc .= '</th>';
}
- 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 .= '<td '.$class;
- if ( $colspan > 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 .= '</td>';
}
- //----------------------------------------------------------
- // Utils
+ #region Utility functions
/**
* Build a link
@@ -1030,29 +1362,29 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
- 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('&','&amp;',$link['url']);
- $link['url'] = str_replace('&amp;amp;','&amp;',$link['url']);
+ if(substr($link['url'], 0, 7) != 'mailto:') {
+ $link['url'] = str_replace('&', '&amp;', $link['url']);
+ $link['url'] = str_replace('&amp;amp;', '&amp;', $link['url']);
}
//remove double encodings in titles
- $link['title'] = str_replace('&amp;amp;','&amp;',$link['title']);
+ $link['title'] = str_replace('&amp;amp;', '&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('>'=>'&gt;','<'=>'&lt;','"'=>'&quot;'));
+ $link['url'] = strtr($link['url'], array('>' => '%3E', '<' => '%3C', '"' => '%22'));
+ $link['title'] = strtr($link['title'], array('>' => '&gt;', '<' => '&lt;', '"' => '&quot;'));
- $ret = '';
+ $ret = '';
$ret .= $link['pre'];
$ret .= '<a href="'.$link['url'].'"';
- if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"';
+ if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"';
if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"';
- if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"';
- if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"';
- if(!empty($link['rel'])) $ret .= ' rel="'.$link['rel'].'"';
- if(!empty($link['more'])) $ret .= ' '.$link['more'];
+ if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"';
+ if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"';
+ if(!empty($link['rel'])) $ret .= ' rel="'.$link['rel'].'"';
+ if(!empty($link['more'])) $ret .= ' '.$link['more'];
$ret .= '>';
$ret .= $link['name'];
$ret .= '</a>';
@@ -1064,102 +1396,112 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
* Renders internal and external media
*
* @author Andreas Gohr <andi@splitbrain.org>
+ * @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 .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache,'rev'=>$this->_getLastMediaRevisionAt($src))).'"';
+ $ret .= '<img src="'.ml($src, array('w' => $width, 'h' => $height, 'cache' => $cache, 'rev'=>$this->_getLastMediaRevisionAt($src))).'"';
$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)));
}
@@ -1167,23 +1509,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 <andi@splitbrain.org>
* @param string $title The headline title
* @param boolean $create Create a new unique ID?
- * @author Andreas Gohr <andi@splitbrain.org>
+ * @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);
}
}
@@ -1191,18 +1540,22 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
* Construct a title and handle images in titles
*
* @author Harry Fuecks <hfuecks@gmail.com>
+ * @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);
}
}
@@ -1213,48 +1566,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 <andi@splitbrain.org>
+ * @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,$this->date_at,true);
+ list($img['src']) = explode('#', $img['src'], 2);
+ if($img['type'] == 'internalmedia') {
+ resolve_mediaid(getNS($ID), $img['src'], $exists ,$this->date_at, true);
}
- 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
*
- * @author Pierre Spring <pierre.spring@liip.ch>
- * @param string $src
- * @param string $title
- * @param string $align
- * @param string $width
- * @param string $height
- * @param string $cache
- * @param string $render
- * @access protected
- * @return array
+ * used in internalmedia() and externalmedia()
+ *
+ * @author Pierre Spring <pierre.spring@liip.ch>
+ * @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'] = '';
@@ -1267,50 +1623,49 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
return $link;
}
-
/**
* Embed video(s) in HTML
*
* @author Anika Henke <anika@selfthinker.org>
*
- * @param string $src - ID of video to embed
- * @param int $width - width of the video in pixels
- * @param int $height - height of the video in pixels
- * @param array $atts - additional attributes for the <video> tag
+ * @param string $src - ID of video to embed
+ * @param int $width - width of the video in pixels
+ * @param int $height - height of the video in pixels
+ * @param array $atts - additional attributes for the <video> tag
* @return string
*/
- function _video($src,$width,$height,$atts=null){
+ function _video($src, $width, $height, $atts = null) {
// prepare width and height
if(is_null($atts)) $atts = array();
$atts['width'] = (int) $width;
$atts['height'] = (int) $height;
- if(!$atts['width']) $atts['width'] = 320;
+ if(!$atts['width']) $atts['width'] = 320;
if(!$atts['height']) $atts['height'] = 240;
// prepare alternative formats
- $extensions = array('webm', 'ogv', 'mp4');
+ $extensions = array('webm', 'ogv', 'mp4');
$alternatives = media_alternativefiles($src, $extensions);
- $poster = media_alternativefiles($src, array('jpg', 'png'), true);
- $posterUrl = '';
- if (!empty($poster)) {
- $posterUrl = ml(reset($poster),array('cache'=>$cache),true,'&');
+ $poster = media_alternativefiles($src, array('jpg', 'png'), true);
+ $posterUrl = '';
+ if(!empty($poster)) {
+ $posterUrl = ml(reset($poster), '', true, '&');
}
$out = '';
// open video tag
$out .= '<video '.buildAttributes($atts).' controls="controls"';
- if ($posterUrl) $out .= ' poster="'.hsc($posterUrl).'"';
+ if($posterUrl) $out .= ' poster="'.hsc($posterUrl).'"';
$out .= '>'.NL;
$fallback = '';
// output source for each alternative video format
foreach($alternatives as $mime => $file) {
- $url = ml($file,array('cache'=>$cache),true,'&');
+ $url = ml($file, '', true, '&');
$title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(utf8_basename(noNS($file)));
$out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL;
// alternative content (just a link to the file)
- $fallback .= $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly', $return=true);
+ $fallback .= $this->internalmedia($file, $title, null, null, null, $cache = null, $linking = 'linkonly', $return = true);
}
// finish
@@ -1324,14 +1679,14 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
*
* @author Anika Henke <anika@selfthinker.org>
*
- * @param string $src - ID of audio to embed
- * @param array $atts - additional attributes for the <audio> tag
+ * @param string $src - ID of audio to embed
+ * @param array $atts - additional attributes for the <audio> tag
* @return string
*/
- function _audio($src,$atts=null){
+ function _audio($src, $atts = null) {
// prepare alternative formats
- $extensions = array('ogg', 'mp3', 'wav');
+ $extensions = array('ogg', 'mp3', 'wav');
$alternatives = media_alternativefiles($src, $extensions);
$out = '';
@@ -1341,12 +1696,12 @@ 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 .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL;
// alternative content (just a link to the file)
- $fallback .= $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly', $return=true);
+ $fallback .= $this->internalmedia($file, $title, null, null, null, $cache = null, $linking = 'linkonly', $return = true);
}
// finish
@@ -1370,6 +1725,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
return $pagelog->getLastRevisionAt($this->date_at);
}
+ #endregion
}
//Setup VIM: ex: et ts=4 :