aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/inc/parser/handler.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/parser/handler.php')
-rw-r--r--inc/parser/handler.php625
1 files changed, 336 insertions, 289 deletions
diff --git a/inc/parser/handler.php b/inc/parser/handler.php
index 1ef9ffdd5..c68190442 100644
--- a/inc/parser/handler.php
+++ b/inc/parser/handler.php
@@ -14,18 +14,19 @@ use dokuwiki\Parsing\Handler\Table;
/**
* Class Doku_Handler
*/
-class Doku_Handler {
+class Doku_Handler
+{
/** @var CallWriterInterface */
- protected $callWriter = null;
+ protected $callWriter;
/** @var array The current CallWriter will write directly to this list of calls, Parser reads it */
- public $calls = array();
+ public $calls = [];
/** @var array internal status holders for some modes */
- protected $status = array(
+ protected $status = [
'section' => false,
- 'doublequote' => 0,
- );
+ 'doublequote' => 0
+ ];
/** @var bool should blocks be rewritten? FIXME seems to always be true */
protected $rewriteBlocks = true;
@@ -38,7 +39,8 @@ class Doku_Handler {
/**
* Doku_Handler constructor.
*/
- public function __construct() {
+ public function __construct()
+ {
$this->callWriter = new CallWriter($this);
}
@@ -47,10 +49,11 @@ class Doku_Handler {
*
* @param string $handler handler method name (see mode handlers below)
* @param mixed $args arguments for this call
- * @param int $pos byte position in the original source file
+ * @param int $pos byte position in the original source file
*/
- public function addCall($handler, $args, $pos) {
- $call = array($handler,$args, $pos);
+ public function addCall($handler, $args, $pos)
+ {
+ $call = [$handler, $args, $pos];
$this->callWriter->writeCall($call);
}
@@ -59,7 +62,8 @@ class Doku_Handler {
*
* @return CallWriterInterface
*/
- public function getCallWriter() {
+ public function getCallWriter()
+ {
return $this->callWriter;
}
@@ -68,7 +72,8 @@ class Doku_Handler {
*
* @param CallWriterInterface $callWriter
*/
- public function setCallWriter($callWriter) {
+ public function setCallWriter($callWriter)
+ {
$this->callWriter = $callWriter;
}
@@ -78,7 +83,8 @@ class Doku_Handler {
* @param string $status
* @return mixed|null
*/
- public function getStatus($status) {
+ public function getStatus($status)
+ {
if (!isset($this->status[$status])) return null;
return $this->status[$status];
}
@@ -89,12 +95,14 @@ class Doku_Handler {
* @param string $status
* @param mixed $value
*/
- public function setStatus($status, $value) {
+ public function setStatus($status, $value)
+ {
$this->status[$status] = $value;
}
/** @deprecated 2019-10-31 use addCall() instead */
- public function _addCall($handler, $args, $pos) {
+ public function _addCall($handler, $args, $pos)
+ {
dbg_deprecated('addCall');
$this->addCall($handler, $args, $pos);
}
@@ -108,8 +116,9 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @param string $match matched syntax
*/
- public function addPluginCall($plugin, $args, $state, $pos, $match) {
- $call = array('plugin',array($plugin, $args, $state, $match), $pos);
+ public function addPluginCall($plugin, $args, $state, $pos, $match)
+ {
+ $call = ['plugin', [$plugin, $args, $state, $match], $pos];
$this->callWriter->writeCall($call);
}
@@ -121,24 +130,25 @@ class Doku_Handler {
*
* @triggers PARSER_HANDLER_DONE
*/
- public function finalize(){
+ public function finalize()
+ {
$this->callWriter->finalise();
- if ( $this->status['section'] ) {
+ if ($this->status['section']) {
$last_call = end($this->calls);
- array_push($this->calls,array('section_close',array(), $last_call[2]));
+ $this->calls[] = ['section_close', [], $last_call[2]];
}
- if ( $this->rewriteBlocks ) {
+ if ($this->rewriteBlocks) {
$B = new Block();
$this->calls = $B->process($this->calls);
}
- Event::createAndTrigger('PARSER_HANDLER_DONE',$this);
+ Event::createAndTrigger('PARSER_HANDLER_DONE', $this);
- array_unshift($this->calls,array('document_start',array(),0));
+ array_unshift($this->calls, ['document_start', [], 0]);
$last_call = end($this->calls);
- array_push($this->calls,array('document_end',array(),$last_call[2]));
+ $this->calls[] = ['document_end', [], $last_call[2]];
}
/**
@@ -147,9 +157,10 @@ class Doku_Handler {
* @fixme seems to be unused?
* @return bool|mixed
*/
- public function fetch() {
+ public function fetch()
+ {
$call = current($this->calls);
- if($call !== false) {
+ if ($call !== false) {
next($this->calls); //advance the pointer
return $call;
}
@@ -169,8 +180,9 @@ class Doku_Handler {
* @return array|null Array of key-value pairs $array['key'] = 'value';
* or null if no entries found
*/
- protected function parse_highlight_options($options) {
- $result = array();
+ protected function parse_highlight_options($options)
+ {
+ $result = [];
preg_match_all('/(\w+(?:="[^"]*"))|(\w+(?:=[^\s]*))|(\w+[^=\s\]])(?:\s*)/', $options, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$equal_sign = strpos($match [0], '=');
@@ -179,7 +191,7 @@ class Doku_Handler {
$result [$key] = 1;
} else {
$key = substr($match[0], 0, $equal_sign);
- $value = substr($match[0], $equal_sign+1);
+ $value = substr($match[0], $equal_sign + 1);
$value = trim($value, '"');
if (strlen($value) > 0) {
$result [$key] = $value;
@@ -192,34 +204,34 @@ class Doku_Handler {
// Check for supported options
$result = array_intersect_key(
$result,
- array_flip(array(
- 'enable_line_numbers',
- 'start_line_numbers_at',
- 'highlight_lines_extra',
- 'enable_keyword_links')
- )
+ array_flip([
+ 'enable_line_numbers',
+ 'start_line_numbers_at',
+ 'highlight_lines_extra',
+ 'enable_keyword_links'
+ ])
);
// Sanitize values
- if(isset($result['enable_line_numbers'])) {
- if($result['enable_line_numbers'] === 'false') {
+ if (isset($result['enable_line_numbers'])) {
+ if ($result['enable_line_numbers'] === 'false') {
$result['enable_line_numbers'] = false;
}
- $result['enable_line_numbers'] = (bool) $result['enable_line_numbers'];
+ $result['enable_line_numbers'] = (bool)$result['enable_line_numbers'];
}
- if(isset($result['highlight_lines_extra'])) {
+ if (isset($result['highlight_lines_extra'])) {
$result['highlight_lines_extra'] = array_map('intval', explode(',', $result['highlight_lines_extra']));
$result['highlight_lines_extra'] = array_filter($result['highlight_lines_extra']);
$result['highlight_lines_extra'] = array_unique($result['highlight_lines_extra']);
}
- if(isset($result['start_line_numbers_at'])) {
- $result['start_line_numbers_at'] = (int) $result['start_line_numbers_at'];
+ if (isset($result['start_line_numbers_at'])) {
+ $result['start_line_numbers_at'] = (int)$result['start_line_numbers_at'];
}
- if(isset($result['enable_keyword_links'])) {
- if($result['enable_keyword_links'] === 'false') {
+ if (isset($result['enable_keyword_links'])) {
+ if ($result['enable_keyword_links'] === 'false') {
$result['enable_keyword_links'] = false;
}
- $result['enable_keyword_links'] = (bool) $result['enable_keyword_links'];
+ $result['enable_keyword_links'] = (bool)$result['enable_keyword_links'];
}
if (count($result) == 0) {
return null;
@@ -236,16 +248,17 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @param string $name actual mode name
*/
- protected function nestingTag($match, $state, $pos, $name) {
- switch ( $state ) {
+ protected function nestingTag($match, $state, $pos, $name)
+ {
+ switch ($state) {
case DOKU_LEXER_ENTER:
- $this->addCall($name.'_open', array(), $pos);
+ $this->addCall($name . '_open', [], $pos);
break;
case DOKU_LEXER_EXIT:
- $this->addCall($name.'_close', array(), $pos);
+ $this->addCall($name . '_close', [], $pos);
break;
case DOKU_LEXER_UNMATCHED:
- $this->addCall('cdata', array($match), $pos);
+ $this->addCall('cdata', [$match], $pos);
break;
}
}
@@ -268,23 +281,24 @@ class Doku_Handler {
* An additional parameter with the plugin name is passed. The plugin's handle()
* method is called here
*
- * @author Andreas Gohr <andi@splitbrain.org>
- *
* @param string $match matched syntax
* @param int $state a LEXER_STATE_* constant
* @param int $pos byte position in the original source file
* @param string $pluginname name of the plugin
* @return bool mode handled?
+ * @author Andreas Gohr <andi@splitbrain.org>
+ *
*/
- public function plugin($match, $state, $pos, $pluginname){
- $data = array($match);
+ public function plugin($match, $state, $pos, $pluginname)
+ {
+ $data = [$match];
/** @var SyntaxPlugin $plugin */
- $plugin = plugin_load('syntax',$pluginname);
- if($plugin != null){
+ $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;
}
@@ -295,12 +309,11 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function base($match, $state, $pos) {
- switch ( $state ) {
- case DOKU_LEXER_UNMATCHED:
- $this->addCall('cdata', array($match), $pos);
- return true;
- break;
+ public function base($match, $state, $pos)
+ {
+ if ($state === DOKU_LEXER_UNMATCHED) {
+ $this->addCall('cdata', [$match], $pos);
+ return true;
}
return false;
}
@@ -311,19 +324,20 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function header($match, $state, $pos) {
+ public function header($match, $state, $pos)
+ {
// get level and title
$title = trim($match);
- $level = 7 - strspn($title,'=');
- if($level < 1) $level = 1;
- $title = trim($title,'=');
+ $level = 7 - strspn($title, '=');
+ if ($level < 1) $level = 1;
+ $title = trim($title, '=');
$title = trim($title);
- if ($this->status['section']) $this->addCall('section_close', array(), $pos);
+ if ($this->status['section']) $this->addCall('section_close', [], $pos);
- $this->addCall('header', array($title, $level, $pos), $pos);
+ $this->addCall('header', [$title, $level, $pos], $pos);
- $this->addCall('section_open', array($level), $pos);
+ $this->addCall('section_open', [$level], $pos);
$this->status['section'] = true;
return true;
}
@@ -334,8 +348,9 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function notoc($match, $state, $pos) {
- $this->addCall('notoc', array(), $pos);
+ public function notoc($match, $state, $pos)
+ {
+ $this->addCall('notoc', [], $pos);
return true;
}
@@ -345,8 +360,9 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function nocache($match, $state, $pos) {
- $this->addCall('nocache', array(), $pos);
+ public function nocache($match, $state, $pos)
+ {
+ $this->addCall('nocache', [], $pos);
return true;
}
@@ -356,8 +372,9 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function linebreak($match, $state, $pos) {
- $this->addCall('linebreak', array(), $pos);
+ public function linebreak($match, $state, $pos)
+ {
+ $this->addCall('linebreak', [], $pos);
return true;
}
@@ -367,8 +384,9 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function eol($match, $state, $pos) {
- $this->addCall('eol', array(), $pos);
+ public function eol($match, $state, $pos)
+ {
+ $this->addCall('eol', [], $pos);
return true;
}
@@ -378,8 +396,9 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function hr($match, $state, $pos) {
- $this->addCall('hr', array(), $pos);
+ public function hr($match, $state, $pos)
+ {
+ $this->addCall('hr', [], $pos);
return true;
}
@@ -389,7 +408,8 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function strong($match, $state, $pos) {
+ public function strong($match, $state, $pos)
+ {
$this->nestingTag($match, $state, $pos, 'strong');
return true;
}
@@ -400,7 +420,8 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function emphasis($match, $state, $pos) {
+ public function emphasis($match, $state, $pos)
+ {
$this->nestingTag($match, $state, $pos, 'emphasis');
return true;
}
@@ -411,7 +432,8 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function underline($match, $state, $pos) {
+ public function underline($match, $state, $pos)
+ {
$this->nestingTag($match, $state, $pos, 'underline');
return true;
}
@@ -422,7 +444,8 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function monospace($match, $state, $pos) {
+ public function monospace($match, $state, $pos)
+ {
$this->nestingTag($match, $state, $pos, 'monospace');
return true;
}
@@ -433,7 +456,8 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function subscript($match, $state, $pos) {
+ public function subscript($match, $state, $pos)
+ {
$this->nestingTag($match, $state, $pos, 'subscript');
return true;
}
@@ -444,7 +468,8 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function superscript($match, $state, $pos) {
+ public function superscript($match, $state, $pos)
+ {
$this->nestingTag($match, $state, $pos, 'superscript');
return true;
}
@@ -455,7 +480,8 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function deleted($match, $state, $pos) {
+ public function deleted($match, $state, $pos)
+ {
$this->nestingTag($match, $state, $pos, 'deleted');
return true;
}
@@ -466,39 +492,40 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function footnote($match, $state, $pos) {
+ public function footnote($match, $state, $pos)
+ {
if (!isset($this->footnote)) $this->footnote = false;
- switch ( $state ) {
+ switch ($state) {
case DOKU_LEXER_ENTER:
// 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);
+ $this->addCall('cdata', [$match], $pos);
break;
}
$this->footnote = true;
$this->callWriter = new Nest($this->callWriter, 'footnote_close');
- $this->addCall('footnote_open', array(), $pos);
- break;
+ $this->addCall('footnote_open', [], $pos);
+ break;
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);
+ $this->addCall('cdata', [$match], $pos);
break;
}
$this->footnote = false;
- $this->addCall('footnote_close', array(), $pos);
+ $this->addCall('footnote_close', [], $pos);
/** @var Nest $reWriter */
$reWriter = $this->callWriter;
$this->callWriter = $reWriter->process();
- break;
+ break;
case DOKU_LEXER_UNMATCHED:
- $this->addCall('cdata', array($match), $pos);
- break;
+ $this->addCall('cdata', [$match], $pos);
+ break;
}
return true;
}
@@ -509,24 +536,25 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function listblock($match, $state, $pos) {
- switch ( $state ) {
+ public function listblock($match, $state, $pos)
+ {
+ switch ($state) {
case DOKU_LEXER_ENTER:
$this->callWriter = new Lists($this->callWriter);
- $this->addCall('list_open', array($match), $pos);
- break;
+ $this->addCall('list_open', [$match], $pos);
+ break;
case DOKU_LEXER_EXIT:
- $this->addCall('list_close', array(), $pos);
+ $this->addCall('list_close', [], $pos);
/** @var Lists $reWriter */
$reWriter = $this->callWriter;
$this->callWriter = $reWriter->process();
- break;
+ break;
case DOKU_LEXER_MATCHED:
- $this->addCall('list_item', array($match), $pos);
- break;
+ $this->addCall('list_item', [$match], $pos);
+ break;
case DOKU_LEXER_UNMATCHED:
- $this->addCall('cdata', array($match), $pos);
- break;
+ $this->addCall('cdata', [$match], $pos);
+ break;
}
return true;
}
@@ -537,9 +565,10 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function unformatted($match, $state, $pos) {
- if ( $state == DOKU_LEXER_UNMATCHED ) {
- $this->addCall('unformatted', array($match), $pos);
+ public function unformatted($match, $state, $pos)
+ {
+ if ($state == DOKU_LEXER_UNMATCHED) {
+ $this->addCall('unformatted', [$match], $pos);
}
return true;
}
@@ -550,24 +579,25 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function preformatted($match, $state, $pos) {
- switch ( $state ) {
+ public function preformatted($match, $state, $pos)
+ {
+ switch ($state) {
case DOKU_LEXER_ENTER:
$this->callWriter = new Preformatted($this->callWriter);
- $this->addCall('preformatted_start', array(), $pos);
- break;
+ $this->addCall('preformatted_start', [], $pos);
+ break;
case DOKU_LEXER_EXIT:
- $this->addCall('preformatted_end', array(), $pos);
+ $this->addCall('preformatted_end', [], $pos);
/** @var Preformatted $reWriter */
$reWriter = $this->callWriter;
$this->callWriter = $reWriter->process();
- break;
+ break;
case DOKU_LEXER_MATCHED:
- $this->addCall('preformatted_newline', array(), $pos);
- break;
+ $this->addCall('preformatted_newline', [], $pos);
+ break;
case DOKU_LEXER_UNMATCHED:
- $this->addCall('preformatted_content', array($match), $pos);
- break;
+ $this->addCall('preformatted_content', [$match], $pos);
+ break;
}
return true;
@@ -579,30 +609,29 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function quote($match, $state, $pos) {
-
- switch ( $state ) {
+ public function quote($match, $state, $pos)
+ {
+ switch ($state) {
case DOKU_LEXER_ENTER:
$this->callWriter = new Quote($this->callWriter);
- $this->addCall('quote_start', array($match), $pos);
- break;
+ $this->addCall('quote_start', [$match], $pos);
+ break;
case DOKU_LEXER_EXIT:
- $this->addCall('quote_end', array(), $pos);
+ $this->addCall('quote_end', [], $pos);
/** @var Lists $reWriter */
$reWriter = $this->callWriter;
$this->callWriter = $reWriter->process();
- break;
+ break;
case DOKU_LEXER_MATCHED:
- $this->addCall('quote_newline', array($match), $pos);
- break;
+ $this->addCall('quote_newline', [$match], $pos);
+ break;
case DOKU_LEXER_UNMATCHED:
- $this->addCall('cdata', array($match), $pos);
- break;
-
+ $this->addCall('cdata', [$match], $pos);
+ break;
}
return true;
@@ -614,7 +643,8 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function file($match, $state, $pos) {
+ public function file($match, $state, $pos)
+ {
return $this->code($match, $state, $pos, 'file');
}
@@ -625,22 +655,23 @@ class Doku_Handler {
* @param string $type either 'code' or 'file'
* @return bool mode handled?
*/
- public function code($match, $state, $pos, $type='code') {
- if ( $state == DOKU_LEXER_UNMATCHED ) {
- $matches = sexplode('>',$match,2,'');
+ public function code($match, $state, $pos, $type = 'code')
+ {
+ if ($state == DOKU_LEXER_UNMATCHED) {
+ $matches = sexplode('>', $match, 2, '');
// Cut out variable options enclosed in []
preg_match('/\[.*\]/', $matches[0], $options);
if (!empty($options[0])) {
$matches[0] = str_replace($options[0], '', $matches[0]);
}
$param = preg_split('/\s+/', $matches[0], 2, PREG_SPLIT_NO_EMPTY);
- while(count($param) < 2) array_push($param, null);
+ while (count($param) < 2) $param[] = null;
// We shortcut html here.
if ($param[0] == 'html') $param[0] = 'html4strict';
if ($param[0] == '-') $param[0] = null;
array_unshift($param, $matches[1]);
if (!empty($options[0])) {
- $param [] = $this->parse_highlight_options ($options[0]);
+ $param [] = $this->parse_highlight_options($options[0]);
}
$this->addCall($type, $param, $pos);
}
@@ -653,8 +684,9 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function acronym($match, $state, $pos) {
- $this->addCall('acronym', array($match), $pos);
+ public function acronym($match, $state, $pos)
+ {
+ $this->addCall('acronym', [$match], $pos);
return true;
}
@@ -664,8 +696,9 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function smiley($match, $state, $pos) {
- $this->addCall('smiley', array($match), $pos);
+ public function smiley($match, $state, $pos)
+ {
+ $this->addCall('smiley', [$match], $pos);
return true;
}
@@ -675,8 +708,9 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function wordblock($match, $state, $pos) {
- $this->addCall('wordblock', array($match), $pos);
+ public function wordblock($match, $state, $pos)
+ {
+ $this->addCall('wordblock', [$match], $pos);
return true;
}
@@ -686,8 +720,9 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function entity($match, $state, $pos) {
- $this->addCall('entity', array($match), $pos);
+ public function entity($match, $state, $pos)
+ {
+ $this->addCall('entity', [$match], $pos);
return true;
}
@@ -697,9 +732,10 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function multiplyentity($match, $state, $pos) {
- preg_match_all('/\d+/',$match,$matches);
- $this->addCall('multiplyentity', array($matches[0][0], $matches[0][1]), $pos);
+ public function multiplyentity($match, $state, $pos)
+ {
+ preg_match_all('/\d+/', $match, $matches);
+ $this->addCall('multiplyentity', [$matches[0][0], $matches[0][1]], $pos);
return true;
}
@@ -709,8 +745,9 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function singlequoteopening($match, $state, $pos) {
- $this->addCall('singlequoteopening', array(), $pos);
+ public function singlequoteopening($match, $state, $pos)
+ {
+ $this->addCall('singlequoteopening', [], $pos);
return true;
}
@@ -720,8 +757,9 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function singlequoteclosing($match, $state, $pos) {
- $this->addCall('singlequoteclosing', array(), $pos);
+ public function singlequoteclosing($match, $state, $pos)
+ {
+ $this->addCall('singlequoteclosing', [], $pos);
return true;
}
@@ -731,8 +769,9 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function apostrophe($match, $state, $pos) {
- $this->addCall('apostrophe', array(), $pos);
+ public function apostrophe($match, $state, $pos)
+ {
+ $this->addCall('apostrophe', [], $pos);
return true;
}
@@ -742,8 +781,9 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function doublequoteopening($match, $state, $pos) {
- $this->addCall('doublequoteopening', array(), $pos);
+ public function doublequoteopening($match, $state, $pos)
+ {
+ $this->addCall('doublequoteopening', [], $pos);
$this->status['doublequote']++;
return true;
}
@@ -754,11 +794,12 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function doublequoteclosing($match, $state, $pos) {
+ public function doublequoteclosing($match, $state, $pos)
+ {
if ($this->status['doublequote'] <= 0) {
$this->doublequoteopening($match, $state, $pos);
} else {
- $this->addCall('doublequoteclosing', array(), $pos);
+ $this->addCall('doublequoteclosing', [], $pos);
$this->status['doublequote'] = max(0, --$this->status['doublequote']);
}
return true;
@@ -770,8 +811,9 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function camelcaselink($match, $state, $pos) {
- $this->addCall('camelcaselink', array($match), $pos);
+ public function camelcaselink($match, $state, $pos)
+ {
+ $this->addCall('camelcaselink', [$match], $pos);
return true;
}
@@ -781,15 +823,16 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function internallink($match, $state, $pos) {
+ public function internallink($match, $state, $pos)
+ {
// Strip the opening and closing markup
- $link = preg_replace(array('/^\[\[/','/\]\]$/u'),'',$match);
+ $link = preg_replace(['/^\[\[/', '/\]\]$/u'], '', $match);
// Split title from URL
- $link = sexplode('|',$link,2);
- if ( $link[1] === null ) {
+ $link = sexplode('|', $link, 2);
+ if ($link[1] === null) {
$link[1] = null;
- } else if ( preg_match('/^\{\{[^\}]+\}\}$/',$link[1]) ) {
+ } elseif (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]);
}
@@ -797,49 +840,49 @@ class Doku_Handler {
//decide which kind of link it is
- if ( link_isinterwiki($link[0]) ) {
+ if (link_isinterwiki($link[0])) {
// Interwiki
- $interwiki = sexplode('>',$link[0],2,'');
+ $interwiki = sexplode('>', $link[0], 2, '');
$this->addCall(
'interwikilink',
- array($link[0],$link[1],strtolower($interwiki[0]),$interwiki[1]),
+ [$link[0], $link[1], strtolower($interwiki[0]), $interwiki[1]],
$pos
- );
- }elseif ( preg_match('/^\\\\\\\\[^\\\\]+?\\\\/u',$link[0]) ) {
+ );
+ } elseif (preg_match('/^\\\\\\\\[^\\\\]+?\\\\/u', $link[0])) {
// Windows Share
$this->addCall(
'windowssharelink',
- array($link[0],$link[1]),
+ [$link[0], $link[1]],
$pos
- );
- }elseif ( preg_match('#^([a-z0-9\-\.+]+?)://#i',$link[0]) ) {
+ );
+ } elseif (preg_match('#^([a-z0-9\-\.+]+?)://#i', $link[0])) {
// external link (accepts all protocols)
$this->addCall(
- 'externallink',
- array($link[0],$link[1]),
- $pos
- );
- }elseif ( preg_match('<'.PREG_PATTERN_VALID_EMAIL.'>',$link[0]) ) {
+ 'externallink',
+ [$link[0], $link[1]],
+ $pos
+ );
+ } elseif (preg_match('<' . PREG_PATTERN_VALID_EMAIL . '>', $link[0])) {
// E-Mail (pattern above is defined in inc/mail.php)
$this->addCall(
'emaillink',
- array($link[0],$link[1]),
+ [$link[0], $link[1]],
$pos
- );
- }elseif ( preg_match('!^#.+!',$link[0]) ){
+ );
+ } elseif (preg_match('!^#.+!', $link[0])) {
// local link
$this->addCall(
'locallink',
- array(substr($link[0],1),$link[1]),
+ [substr($link[0], 1), $link[1]],
$pos
- );
- }else{
+ );
+ } else {
// internal link
$this->addCall(
'internallink',
- array($link[0],$link[1]),
+ [$link[0], $link[1]],
$pos
- );
+ );
}
return true;
@@ -851,8 +894,9 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function filelink($match, $state, $pos) {
- $this->addCall('filelink', array($match, null), $pos);
+ public function filelink($match, $state, $pos)
+ {
+ $this->addCall('filelink', [$match, null], $pos);
return true;
}
@@ -862,8 +906,9 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function windowssharelink($match, $state, $pos) {
- $this->addCall('windowssharelink', array($match, null), $pos);
+ public function windowssharelink($match, $state, $pos)
+ {
+ $this->addCall('windowssharelink', [$match, null], $pos);
return true;
}
@@ -873,15 +918,15 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function media($match, $state, $pos) {
+ public function media($match, $state, $pos)
+ {
$p = Doku_Handler_Parse_Media($match);
$this->addCall(
- $p['type'],
- array($p['src'], $p['title'], $p['align'], $p['width'],
- $p['height'], $p['cache'], $p['linking']),
- $pos
- );
+ $p['type'],
+ [$p['src'], $p['title'], $p['align'], $p['width'], $p['height'], $p['cache'], $p['linking']],
+ $pos
+ );
return true;
}
@@ -891,32 +936,33 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function rss($match, $state, $pos) {
- $link = preg_replace(array('/^\{\{rss>/','/\}\}$/'),'',$match);
+ public function rss($match, $state, $pos)
+ {
+ $link = preg_replace(['/^\{\{rss>/', '/\}\}$/'], '', $match);
// get params
- list($link, $params) = sexplode(' ', $link, 2, '');
+ [$link, $params] = sexplode(' ', $link, 2, '');
- $p = array();
- if(preg_match('/\b(\d+)\b/',$params,$match)){
+ $p = [];
+ if (preg_match('/\b(\d+)\b/', $params, $match)) {
$p['max'] = $match[1];
- }else{
+ } else {
$p['max'] = 8;
}
- $p['reverse'] = (preg_match('/rev/',$params));
- $p['author'] = (preg_match('/\b(by|author)/',$params));
- $p['date'] = (preg_match('/\b(date)/',$params));
- $p['details'] = (preg_match('/\b(desc|detail)/',$params));
- $p['nosort'] = (preg_match('/\b(nosort)\b/',$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
+ $p['reverse'] = (preg_match('/rev/', $params));
+ $p['author'] = (preg_match('/\b(by|author)/', $params));
+ $p['date'] = (preg_match('/\b(date)/', $params));
+ $p['details'] = (preg_match('/\b(desc|detail)/', $params));
+ $p['nosort'] = (preg_match('/\b(nosort)\b/', $params));
+
+ if (preg_match('/\b(\d+)([dhm])\b/', $params, $match)) {
+ $period = ['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
}
- $this->addCall('rss', array($link, $p), $pos);
+ $this->addCall('rss', [$link, $p], $pos);
return true;
}
@@ -926,21 +972,22 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function externallink($match, $state, $pos) {
- $url = $match;
+ public function externallink($match, $state, $pos)
+ {
+ $url = $match;
$title = null;
// add protocol on simple short URLs
- if(substr($url,0,3) == 'ftp' && (substr($url,0,6) != 'ftp://')){
+ if (str_starts_with($url, 'ftp') && !str_starts_with($url, 'ftp://')) {
$title = $url;
- $url = 'ftp://'.$url;
+ $url = 'ftp://' . $url;
}
- if(substr($url,0,3) == 'www' && (substr($url,0,7) != 'http://')){
+ if (str_starts_with($url, 'www')) {
$title = $url;
- $url = 'http://'.$url;
+ $url = 'http://' . $url;
}
- $this->addCall('externallink', array($url, $title), $pos);
+ $this->addCall('externallink', [$url, $title], $pos);
return true;
}
@@ -950,9 +997,10 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function emaillink($match, $state, $pos) {
- $email = preg_replace(array('/^</','/>$/'),'',$match);
- $this->addCall('emaillink', array($email, null), $pos);
+ public function emaillink($match, $state, $pos)
+ {
+ $email = preg_replace(['/^</', '/>$/'], '', $match);
+ $this->addCall('emaillink', [$email, null], $pos);
return true;
}
@@ -962,55 +1010,54 @@ class Doku_Handler {
* @param int $pos byte position in the original source file
* @return bool mode handled?
*/
- public function table($match, $state, $pos) {
- switch ( $state ) {
-
+ public function table($match, $state, $pos)
+ {
+ switch ($state) {
case DOKU_LEXER_ENTER:
-
$this->callWriter = new Table($this->callWriter);
- $this->addCall('table_start', array($pos + 1), $pos);
- if ( trim($match) == '^' ) {
- $this->addCall('tableheader', array(), $pos);
+ $this->addCall('table_start', [$pos + 1], $pos);
+ if (trim($match) == '^') {
+ $this->addCall('tableheader', [], $pos);
} else {
- $this->addCall('tablecell', array(), $pos);
+ $this->addCall('tablecell', [], $pos);
}
- break;
+ break;
case DOKU_LEXER_EXIT:
- $this->addCall('table_end', array($pos), $pos);
+ $this->addCall('table_end', [$pos], $pos);
/** @var Table $reWriter */
$reWriter = $this->callWriter;
$this->callWriter = $reWriter->process();
- break;
+ break;
case DOKU_LEXER_UNMATCHED:
- if ( trim($match) != '' ) {
- $this->addCall('cdata', array($match), $pos);
+ if (trim($match) != '') {
+ $this->addCall('cdata', [$match], $pos);
}
- break;
+ break;
case DOKU_LEXER_MATCHED:
- if ( $match == ' ' ){
- $this->addCall('cdata', array($match), $pos);
- } else if ( preg_match('/:::/',$match) ) {
- $this->addCall('rowspan', array($match), $pos);
- } else if ( preg_match('/\t+/',$match) ) {
- $this->addCall('table_align', array($match), $pos);
- } else if ( preg_match('/ {2,}/',$match) ) {
- $this->addCall('table_align', array($match), $pos);
- } else if ( $match == "\n|" ) {
- $this->addCall('table_row', array(), $pos);
- $this->addCall('tablecell', array(), $pos);
- } else if ( $match == "\n^" ) {
- $this->addCall('table_row', array(), $pos);
- $this->addCall('tableheader', array(), $pos);
- } else if ( $match == '|' ) {
- $this->addCall('tablecell', array(), $pos);
- } else if ( $match == '^' ) {
- $this->addCall('tableheader', array(), $pos);
+ if ($match == ' ') {
+ $this->addCall('cdata', [$match], $pos);
+ } elseif (preg_match('/:::/', $match)) {
+ $this->addCall('rowspan', [$match], $pos);
+ } elseif (preg_match('/\t+/', $match)) {
+ $this->addCall('table_align', [$match], $pos);
+ } elseif (preg_match('/ {2,}/', $match)) {
+ $this->addCall('table_align', [$match], $pos);
+ } elseif ($match == "\n|") {
+ $this->addCall('table_row', [], $pos);
+ $this->addCall('tablecell', [], $pos);
+ } elseif ($match == "\n^") {
+ $this->addCall('table_row', [], $pos);
+ $this->addCall('tableheader', [], $pos);
+ } elseif ($match == '|') {
+ $this->addCall('tablecell', [], $pos);
+ } elseif ($match == '^') {
+ $this->addCall('tableheader', [], $pos);
}
- break;
+ break;
}
return true;
}
@@ -1019,31 +1066,32 @@ class Doku_Handler {
}
//------------------------------------------------------------------------
-function Doku_Handler_Parse_Media($match) {
+function Doku_Handler_Parse_Media($match)
+{
// Strip the opening and closing markup
- $link = preg_replace(array('/^\{\{/','/\}\}$/u'),'',$match);
+ $link = preg_replace(['/^\{\{/', '/\}\}$/u'], '', $match);
// Split title from URL
$link = sexplode('|', $link, 2);
// Check alignment
- $ralign = (bool)preg_match('/^ /',$link[0]);
- $lalign = (bool)preg_match('/ $/',$link[0]);
+ $ralign = (bool)preg_match('/^ /', $link[0]);
+ $lalign = (bool)preg_match('/ $/', $link[0]);
// Logic = what's that ;)...
- if ( $lalign & $ralign ) {
+ if ($lalign & $ralign) {
$align = 'center';
- } else if ( $ralign ) {
+ } elseif ($ralign) {
$align = 'right';
- } else if ( $lalign ) {
+ } elseif ($lalign) {
$align = 'left';
} else {
$align = null;
}
// The title...
- if ( !isset($link[1]) ) {
+ if (!isset($link[1])) {
$link[1] = null;
}
@@ -1052,59 +1100,58 @@ function Doku_Handler_Parse_Media($match) {
//split into src and parameters (using the very last questionmark)
$pos = strrpos($link[0], '?');
- if($pos !== false){
- $src = substr($link[0],0,$pos);
- $param = substr($link[0],$pos+1);
- }else{
- $src = $link[0];
+ if ($pos !== false) {
+ $src = substr($link[0], 0, $pos);
+ $param = substr($link[0], $pos + 1);
+ } else {
+ $src = $link[0];
$param = '';
}
//parse width and height
- if(preg_match('#(\d+)(x(\d+))?#i',$param,$size)){
- !empty($size[1]) ? $w = $size[1] : $w = null;
- !empty($size[3]) ? $h = $size[3] : $h = null;
+ if (preg_match('#(\d+)(x(\d+))?#i', $param, $size)) {
+ $w = empty($size[1]) ? null : $size[1];
+ $h = empty($size[3]) ? null : $size[3];
} else {
$w = null;
$h = null;
}
//get linking command
- if(preg_match('/nolink/i',$param)){
+ if (preg_match('/nolink/i', $param)) {
$linking = 'nolink';
- }else if(preg_match('/direct/i',$param)){
+ } elseif (preg_match('/direct/i', $param)) {
$linking = 'direct';
- }else if(preg_match('/linkonly/i',$param)){
+ } elseif (preg_match('/linkonly/i', $param)) {
$linking = 'linkonly';
- }else{
+ } else {
$linking = 'details';
}
//get caching command
- if (preg_match('/(nocache|recache)/i',$param,$cachemode)){
+ if (preg_match('/(nocache|recache)/i', $param, $cachemode)) {
$cache = $cachemode[1];
- }else{
+ } else {
$cache = 'cache';
}
// Check whether this is a local or remote image or interwiki
- if (media_isexternal($src) || link_isinterwiki($src)){
+ if (media_isexternal($src) || link_isinterwiki($src)) {
$call = 'externalmedia';
} else {
$call = 'internalmedia';
}
- $params = array(
- 'type'=>$call,
- 'src'=>$src,
- 'title'=>$link[1],
- 'align'=>$align,
- 'width'=>$w,
- 'height'=>$h,
- 'cache'=>$cache,
- 'linking'=>$linking,
- );
+ $params = [
+ 'type' => $call,
+ 'src' => $src,
+ 'title' => $link[1],
+ 'align' => $align,
+ 'width' => $w,
+ 'height' => $h,
+ 'cache' => $cache,
+ 'linking' => $linking
+ ];
return $params;
}
-