summaryrefslogtreecommitdiff
path: root/inc/parser/handler.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/parser/handler.php')
-rw-r--r--inc/parser/handler.php224
1 files changed, 111 insertions, 113 deletions
diff --git a/inc/parser/handler.php b/inc/parser/handler.php
index 1cf32aaed..8ae991209 100644
--- a/inc/parser/handler.php
+++ b/inc/parser/handler.php
@@ -4,9 +4,9 @@ if (!defined('DOKU_PARSER_EOL')) define('DOKU_PARSER_EOL',"\n"); // add this t
class Doku_Handler {
- var $Renderer = NULL;
+ var $Renderer = null;
- var $CallWriter = NULL;
+ var $CallWriter = null;
var $calls = array();
@@ -35,8 +35,8 @@ class Doku_Handler {
$this->CallWriter->finalise();
if ( $this->status['section'] ) {
- $last_call = end($this->calls);
- array_push($this->calls,array('section_close',array(), $last_call[2]));
+ $last_call = end($this->calls);
+ array_push($this->calls,array('section_close',array(), $last_call[2]));
}
if ( $this->rewriteBlocks ) {
@@ -70,12 +70,12 @@ class Doku_Handler {
*/
function plugin($match, $state, $pos, $pluginname){
$data = array($match);
- $plugin =& plugin_load('syntax',$pluginname);
+ $plugin = plugin_load('syntax',$pluginname);
if($plugin != null){
$data = $plugin->handle($match, $state, $pos, $this);
}
if ($data !== false) {
- $this->addPluginCall($pluginname,$data,$state,$pos,$match);
+ $this->addPluginCall($pluginname,$data,$state,$pos,$match);
}
return true;
}
@@ -190,8 +190,8 @@ class Doku_Handler {
// footnotes can not be nested - however due to limitations in lexer it can't be prevented
// we will still enter a new footnote mode, we just do nothing
if ($this->_footnote) {
- $this->_addCall('cdata',array($match), $pos);
- break;
+ $this->_addCall('cdata',array($match), $pos);
+ break;
}
$this->_footnote = true;
@@ -203,8 +203,8 @@ class Doku_Handler {
case DOKU_LEXER_EXIT:
// check whether we have already exitted the footnote mode, can happen if the modes were nested
if (!$this->_footnote) {
- $this->_addCall('cdata',array($match), $pos);
- break;
+ $this->_addCall('cdata',array($match), $pos);
+ break;
}
$this->_footnote = false;
@@ -423,7 +423,7 @@ class Doku_Handler {
// Split title from URL
$link = explode('|',$link,2);
if ( !isset($link[1]) ) {
- $link[1] = NULL;
+ $link[1] = null;
} else if ( preg_match('/^\{\{[^\}]+\}\}$/',$link[1]) ) {
// If the title is an image, convert it to an array containing the image details
$link[1] = Doku_Handler_Parse_Media($link[1]);
@@ -433,7 +433,7 @@ class Doku_Handler {
//decide which kind of link it is
if ( preg_match('/^[a-zA-Z0-9\.]+>{1}.*$/u',$link[0]) ) {
- // Interwiki
+ // Interwiki
$interwiki = explode('>',$link[0],2);
$this->_addCall(
'interwikilink',
@@ -441,35 +441,35 @@ class Doku_Handler {
$pos
);
}elseif ( preg_match('/^\\\\\\\\[^\\\\]+?\\\\/u',$link[0]) ) {
- // Windows Share
+ // Windows Share
$this->_addCall(
'windowssharelink',
array($link[0],$link[1]),
$pos
);
}elseif ( preg_match('#^([a-z0-9\-\.+]+?)://#i',$link[0]) ) {
- // external link (accepts all protocols)
+ // external link (accepts all protocols)
$this->_addCall(
'externallink',
array($link[0],$link[1]),
$pos
);
}elseif ( preg_match('<'.PREG_PATTERN_VALID_EMAIL.'>',$link[0]) ) {
- // E-Mail (pattern above is defined in inc/mail.php)
+ // E-Mail (pattern above is defined in inc/mail.php)
$this->_addCall(
'emaillink',
array($link[0],$link[1]),
$pos
);
}elseif ( preg_match('!^#.+!',$link[0]) ){
- // local link
+ // local link
$this->_addCall(
'locallink',
array(substr($link[0],1),$link[1]),
$pos
);
}else{
- // internal link
+ // internal link
$this->_addCall(
'internallink',
array($link[0],$link[1]),
@@ -481,12 +481,12 @@ class Doku_Handler {
}
function filelink($match, $state, $pos) {
- $this->_addCall('filelink',array($match, NULL), $pos);
+ $this->_addCall('filelink',array($match, null), $pos);
return true;
}
function windowssharelink($match, $state, $pos) {
- $this->_addCall('windowssharelink',array($match, NULL), $pos);
+ $this->_addCall('windowssharelink',array($match, null), $pos);
return true;
}
@@ -520,10 +520,10 @@ class Doku_Handler {
$p['details'] = (preg_match('/\b(desc|detail)/',$params));
if (preg_match('/\b(\d+)([dhm])\b/',$params,$match)) {
- $period = array('d' => 86400, 'h' => 3600, 'm' => 60);
- $p['refresh'] = max(600,$match[1]*$period[$match[2]]); // n * period in seconds, minimum 10 minutes
+ $period = array('d' => 86400, 'h' => 3600, 'm' => 60);
+ $p['refresh'] = max(600,$match[1]*$period[$match[2]]); // n * period in seconds, minimum 10 minutes
} else {
- $p['refresh'] = 14400; // default to 4 hours
+ $p['refresh'] = 14400; // default to 4 hours
}
$this->_addCall('rss',array($link,$p),$pos);
@@ -550,7 +550,7 @@ class Doku_Handler {
function emaillink($match, $state, $pos) {
$email = preg_replace(array('/^</','/>$/'),'',$match);
- $this->_addCall('emaillink',array($email, NULL), $pos);
+ $this->_addCall('emaillink',array($email, null), $pos);
return true;
}
@@ -618,7 +618,6 @@ function Doku_Handler_Parse_Media($match) {
// Split title from URL
$link = explode('|',$link,2);
-
// Check alignment
$ralign = (bool)preg_match('/^ /',$link[0]);
$lalign = (bool)preg_match('/ $/',$link[0]);
@@ -631,12 +630,12 @@ function Doku_Handler_Parse_Media($match) {
} else if ( $lalign ) {
$align = 'left';
} else {
- $align = NULL;
+ $align = null;
}
// The title...
if ( !isset($link[1]) ) {
- $link[1] = NULL;
+ $link[1] = null;
}
//remove aligning spaces
@@ -654,11 +653,11 @@ function Doku_Handler_Parse_Media($match) {
//parse width and height
if(preg_match('#(\d+)(x(\d+))?#i',$param,$size)){
- ($size[1]) ? $w = $size[1] : $w = NULL;
- ($size[3]) ? $h = $size[3] : $h = NULL;
+ !empty($size[1]) ? $w = $size[1] : $w = null;
+ !empty($size[3]) ? $h = $size[3] : $h = null;
} else {
- $w = NULL;
- $h = NULL;
+ $w = null;
+ $h = null;
}
//get linking command
@@ -1034,7 +1033,7 @@ class Doku_Handler_Preformatted {
break;
case 'preformatted_end':
if (trim($this->text)) {
- $this->CallWriter->writeCall(array('preformatted',array($this->text),$this->pos));
+ $this->CallWriter->writeCall(array('preformatted',array($this->text),$this->pos));
}
// see FS#1699 & FS#1652, add 'eol' instructions to ensure proper triggering of following p_open
$this->CallWriter->writeCall(array('eol',array(),$this->pos));
@@ -1247,12 +1246,12 @@ class Doku_Handler_Table {
}
$this->tableCalls[] = array($this->lastCellType.'_close',array(),$call[2]);
- $this->tableCalls[] = array($call[0].'_open',array(1,NULL,1),$call[2]);
+ $this->tableCalls[] = array($call[0].'_open',array(1,null,1),$call[2]);
$this->lastCellType = $call[0];
} else {
- $this->tableCalls[] = array($call[0].'_open',array(1,NULL,1),$call[2]);
+ $this->tableCalls[] = array($call[0].'_open',array(1,null,1),$call[2]);
$this->lastCellType = $call[0];
$this->firstCell = false;
@@ -1289,121 +1288,119 @@ class Doku_Handler_Table {
$call = $this->tableCalls[$key];
switch ($call[0]) {
- case 'tablerow_open':
+ case 'tablerow_open':
- $lastRow++;
- $lastCell = 0;
- break;
+ $lastRow++;
+ $lastCell = 0;
+ break;
- case 'tablecell_open':
- case 'tableheader_open':
+ case 'tablecell_open':
+ case 'tableheader_open':
- $lastCell++;
- $cellKey[$lastRow][$lastCell] = $key;
- break;
+ $lastCell++;
+ $cellKey[$lastRow][$lastCell] = $key;
+ break;
- case 'table_align':
+ case 'table_align':
- $prev = in_array($this->tableCalls[$key-1][0], array('tablecell_open', 'tableheader_open'));
- $next = in_array($this->tableCalls[$key+1][0], array('tablecell_close', 'tableheader_close'));
- // If the cell is empty, align left
- if ($prev && $next) {
- $this->tableCalls[$key-1][1][1] = 'left';
+ $prev = in_array($this->tableCalls[$key-1][0], array('tablecell_open', 'tableheader_open'));
+ $next = in_array($this->tableCalls[$key+1][0], array('tablecell_close', 'tableheader_close'));
+ // If the cell is empty, align left
+ if ($prev && $next) {
+ $this->tableCalls[$key-1][1][1] = 'left';
- // If the previous element was a cell open, align right
- } elseif ($prev) {
- $this->tableCalls[$key-1][1][1] = 'right';
+ // If the previous element was a cell open, align right
+ } elseif ($prev) {
+ $this->tableCalls[$key-1][1][1] = 'right';
+
+ // If the next element is the close of an element, align either center or left
+ } elseif ( $next) {
+ if ( $this->tableCalls[$cellKey[$lastRow][$lastCell]][1][1] == 'right' ) {
+ $this->tableCalls[$cellKey[$lastRow][$lastCell]][1][1] = 'center';
+ } else {
+ $this->tableCalls[$cellKey[$lastRow][$lastCell]][1][1] = 'left';
+ }
- // If the next element is the close of an element, align either center or left
- } elseif ( $next) {
- if ( $this->tableCalls[$cellKey[$lastRow][$lastCell]][1][1] == 'right' ) {
- $this->tableCalls[$cellKey[$lastRow][$lastCell]][1][1] = 'center';
- } else {
- $this->tableCalls[$cellKey[$lastRow][$lastCell]][1][1] = 'left';
}
- }
+ // Now convert the whitespace back to cdata
+ $this->tableCalls[$key][0] = 'cdata';
+ break;
- // Now convert the whitespace back to cdata
- $this->tableCalls[$key][0] = 'cdata';
- break;
+ case 'colspan':
- case 'colspan':
+ $this->tableCalls[$key-1][1][0] = false;
- $this->tableCalls[$key-1][1][0] = false;
+ for($i = $key-2; $i >= $cellKey[$lastRow][1]; $i--) {
- for($i = $key-2; $i >= $cellKey[$lastRow][1]; $i--) {
+ if ( $this->tableCalls[$i][0] == 'tablecell_open' || $this->tableCalls[$i][0] == 'tableheader_open' ) {
- if ( $this->tableCalls[$i][0] == 'tablecell_open' || $this->tableCalls[$i][0] == 'tableheader_open' ) {
+ if ( false !== $this->tableCalls[$i][1][0] ) {
+ $this->tableCalls[$i][1][0]++;
+ break;
+ }
- if ( false !== $this->tableCalls[$i][1][0] ) {
- $this->tableCalls[$i][1][0]++;
- break;
}
-
-
}
- }
- $toDelete[] = $key-1;
- $toDelete[] = $key;
- $toDelete[] = $key+1;
- break;
-
- case 'rowspan':
+ $toDelete[] = $key-1;
+ $toDelete[] = $key;
+ $toDelete[] = $key+1;
+ break;
- if ( $this->tableCalls[$key-1][0] == 'cdata' ) {
- // ignore rowspan if previous call was cdata (text mixed with :::) we don't have to check next call as that wont match regex
- $this->tableCalls[$key][0] = 'cdata';
+ case 'rowspan':
- } else {
+ if ( $this->tableCalls[$key-1][0] == 'cdata' ) {
+ // ignore rowspan if previous call was cdata (text mixed with :::) we don't have to check next call as that wont match regex
+ $this->tableCalls[$key][0] = 'cdata';
- $spanning_cell = null;
- for($i = $lastRow-1; $i > 0; $i--) {
+ } else {
- if ( $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tablecell_open' || $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tableheader_open' ) {
+ $spanning_cell = null;
+ 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)) {
- // No spanning cell found, so convert this cell to
- // an empty one to avoid broken tables
- $this->tableCells[$key][1][1] = '';
- continue;
- }
- $this->tableCalls[$cellKey[$spanning_cell][$lastCell]][1][2]++;
+ if (is_null($spanning_cell)) {
+ // No spanning cell found, so convert this cell to
+ // an empty one to avoid broken tables
+ $this->tableCalls[$key][0] = 'cdata';
+ $this->tableCalls[$key][1][0] = '';
+ continue;
+ }
+ $this->tableCalls[$cellKey[$spanning_cell][$lastCell]][1][2]++;
- $this->tableCalls[$key-1][1][2] = false;
+ $this->tableCalls[$key-1][1][2] = false;
- $toDelete[] = $key-1;
- $toDelete[] = $key;
- $toDelete[] = $key+1;
- }
- break;
+ $toDelete[] = $key-1;
+ $toDelete[] = $key;
+ $toDelete[] = $key+1;
+ }
+ break;
- case 'tablerow_close':
+ case 'tablerow_close':
- // Fix broken tables by adding missing cells
- while (++$lastCell < $this->maxCols) {
- array_splice($this->tableCalls, $key, 0, array(
- array('tablecell_open', array(1, null, 1), $call[2]),
- array('cdata', array(''), $call[2]),
- array('tablecell_close', array(), $call[2])));
- $key += 3;
- }
+ // Fix broken tables by adding missing cells
+ while (++$lastCell < $this->maxCols) {
+ array_splice($this->tableCalls, $key, 0, array(
+ array('tablecell_open', array(1, null, 1), $call[2]),
+ array('cdata', array(''), $call[2]),
+ array('tablecell_close', array(), $call[2])));
+ $key += 3;
+ }
- break;
+ break;
}
}
-
// condense cdata
$cnt = count($this->tableCalls);
for( $key = 0; $key < $cnt; $key++){
@@ -1435,6 +1432,7 @@ class Doku_Handler_Table {
class Doku_Handler_Block {
var $calls = array();
var $skipEol = false;
+ var $inParagraph = false;
// Blocks these should not be inside paragraphs
var $blockOpen = array(