3 use dokuwiki\Extension\Event
;
4 use dokuwiki\Extension\SyntaxPlugin
;
5 use dokuwiki\Parsing\Handler\Block
;
6 use dokuwiki\Parsing\Handler\CallWriter
;
7 use dokuwiki\Parsing\Handler\CallWriterInterface
;
8 use dokuwiki\Parsing\Handler\Lists
;
9 use dokuwiki\Parsing\Handler\Nest
;
10 use dokuwiki\Parsing\Handler\Preformatted
;
11 use dokuwiki\Parsing\Handler\Quote
;
12 use dokuwiki\Parsing\Handler\Table
;
18 /** @var CallWriterInterface */
19 protected $callWriter = null;
21 /** @var array The current CallWriter will write directly to this list of calls, Parser reads it */
22 public $calls = array();
24 /** @var array internal status holders for some modes */
25 protected $status = array(
30 /** @var bool should blocks be rewritten? FIXME seems to always be true */
31 protected $rewriteBlocks = true;
34 * Doku_Handler constructor.
36 public function __construct() {
37 $this->callWriter
= new CallWriter($this);
41 * Add a new call by passing it to the current CallWriter
43 * @param string $handler handler method name (see mode handlers below)
44 * @param mixed $args arguments for this call
45 * @param int $pos byte position in the original source file
47 public function addCall($handler, $args, $pos) {
48 $call = array($handler,$args, $pos);
49 $this->callWriter
->writeCall($call);
53 * Accessor for the current CallWriter
55 * @return CallWriterInterface
57 public function getCallWriter() {
58 return $this->callWriter
;
62 * Set a new CallWriter
64 * @param CallWriterInterface $callWriter
66 public function setCallWriter($callWriter) {
67 $this->callWriter
= $callWriter;
71 * Return the current internal status of the given name
73 * @param string $status
76 public function getStatus($status) {
77 if (!isset($this->status
[$status])) return null;
78 return $this->status
[$status];
82 * Set a new internal status
84 * @param string $status
87 public function setStatus($status, $value) {
88 $this->status
[$status] = $value;
91 /** @deprecated 2019-10-31 use addCall() instead */
92 public function _addCall($handler, $args, $pos) {
93 dbg_deprecated('addCall');
94 $this->addCall($handler, $args, $pos);
98 * Similar to addCall, but adds a plugin call
100 * @param string $plugin name of the plugin
101 * @param mixed $args arguments for this call
102 * @param int $state a LEXER_STATE_* constant
103 * @param int $pos byte position in the original source file
104 * @param string $match matched syntax
106 public function addPluginCall($plugin, $args, $state, $pos, $match) {
107 $call = array('plugin',array($plugin, $args, $state, $match), $pos);
108 $this->callWriter
->writeCall($call);
114 * Called from the parser. Calls finalise() on the call writer, closes open
115 * sections, rewrites blocks and adds document_start and document_end calls.
117 * @triggers PARSER_HANDLER_DONE
119 public function finalize(){
120 $this->callWriter
->finalise();
122 if ( $this->status
['section'] ) {
123 $last_call = end($this->calls
);
124 array_push($this->calls
,array('section_close',array(), $last_call[2]));
127 if ( $this->rewriteBlocks
) {
129 $this->calls
= $B->process($this->calls
);
132 Event
::createAndTrigger('PARSER_HANDLER_DONE',$this);
134 array_unshift($this->calls
,array('document_start',array(),0));
135 $last_call = end($this->calls
);
136 array_push($this->calls
,array('document_end',array(),$last_call[2]));
140 * fetch the current call and advance the pointer to the next one
142 * @fixme seems to be unused?
145 public function fetch() {
146 $call = current($this->calls
);
147 if($call !== false) {
148 next($this->calls
); //advance the pointer
156 * Internal function for parsing highlight options.
157 * $options is parsed for key value pairs separated by commas.
158 * A value might also be missing in which case the value will simple
159 * be set to true. Commas in strings are ignored, e.g. option="4,56"
160 * will work as expected and will only create one entry.
162 * @param string $options space separated list of key-value pairs,
163 * e.g. option1=123, option2="456"
164 * @return array|null Array of key-value pairs $array['key'] = 'value';
165 * or null if no entries found
167 protected function parse_highlight_options($options) {
169 preg_match_all('/(\w+(?:="[^"]*"))|(\w+(?:=[^\s]*))|(\w+[^=\s\]])(?:\s*)/', $options, $matches, PREG_SET_ORDER
);
170 foreach ($matches as $match) {
171 $equal_sign = strpos($match [0], '=');
172 if ($equal_sign === false) {
173 $key = trim($match[0]);
176 $key = substr($match[0], 0, $equal_sign);
177 $value = substr($match[0], $equal_sign+
1);
178 $value = trim($value, '"');
179 if (strlen($value) > 0) {
180 $result [$key] = $value;
187 // Check for supported options
188 $result = array_intersect_key(
191 'enable_line_numbers',
192 'start_line_numbers_at',
193 'highlight_lines_extra',
194 'enable_keyword_links')
199 if(isset($result['enable_line_numbers'])) {
200 if($result['enable_line_numbers'] === 'false') {
201 $result['enable_line_numbers'] = false;
203 $result['enable_line_numbers'] = (bool) $result['enable_line_numbers'];
205 if(isset($result['highlight_lines_extra'])) {
206 $result['highlight_lines_extra'] = array_map('intval', explode(',', $result['highlight_lines_extra']));
207 $result['highlight_lines_extra'] = array_filter($result['highlight_lines_extra']);
208 $result['highlight_lines_extra'] = array_unique($result['highlight_lines_extra']);
210 if(isset($result['start_line_numbers_at'])) {
211 $result['start_line_numbers_at'] = (int) $result['start_line_numbers_at'];
213 if(isset($result['enable_keyword_links'])) {
214 if($result['enable_keyword_links'] === 'false') {
215 $result['enable_keyword_links'] = false;
217 $result['enable_keyword_links'] = (bool) $result['enable_keyword_links'];
219 if (count($result) == 0) {
227 * Simplifies handling for the formatting tags which all behave the same
229 * @param string $match matched syntax
230 * @param int $state a LEXER_STATE_* constant
231 * @param int $pos byte position in the original source file
232 * @param string $name actual mode name
234 protected function nestingTag($match, $state, $pos, $name) {
236 case DOKU_LEXER_ENTER
:
237 $this->addCall($name.'_open', array(), $pos);
239 case DOKU_LEXER_EXIT
:
240 $this->addCall($name.'_close', array(), $pos);
242 case DOKU_LEXER_UNMATCHED
:
243 $this->addCall('cdata', array($match), $pos);
250 * The following methods define the handlers for the different Syntax modes
252 * The handlers are called from dokuwiki\Parsing\Lexer\Lexer\invokeParser()
254 * @todo it might make sense to move these into their own class or merge them with the
255 * ParserMode classes some time.
257 // region mode handlers
260 * Special plugin handler
262 * This handler is called for all modes starting with 'plugin_'.
263 * An additional parameter with the plugin name is passed. The plugin's handle()
264 * method is called here
266 * @author Andreas Gohr <andi@splitbrain.org>
268 * @param string $match matched syntax
269 * @param int $state a LEXER_STATE_* constant
270 * @param int $pos byte position in the original source file
271 * @param string $pluginname name of the plugin
272 * @return bool mode handled?
274 public function plugin($match, $state, $pos, $pluginname){
275 $data = array($match);
276 /** @var SyntaxPlugin $plugin */
277 $plugin = plugin_load('syntax',$pluginname);
279 $data = $plugin->handle($match, $state, $pos, $this);
281 if ($data !== false) {
282 $this->addPluginCall($pluginname,$data,$state,$pos,$match);
288 * @param string $match matched syntax
289 * @param int $state a LEXER_STATE_* constant
290 * @param int $pos byte position in the original source file
291 * @return bool mode handled?
293 public function base($match, $state, $pos) {
295 case DOKU_LEXER_UNMATCHED
:
296 $this->addCall('cdata', array($match), $pos);
304 * @param string $match matched syntax
305 * @param int $state a LEXER_STATE_* constant
306 * @param int $pos byte position in the original source file
307 * @return bool mode handled?
309 public function header($match, $state, $pos) {
310 // get level and title
311 $title = trim($match);
312 $level = 7 - strspn($title,'=');
313 if($level < 1) $level = 1;
314 $title = trim($title,'=');
315 $title = trim($title);
317 if ($this->status
['section']) $this->addCall('section_close', array(), $pos);
319 $this->addCall('header', array($title, $level, $pos), $pos);
321 $this->addCall('section_open', array($level), $pos);
322 $this->status
['section'] = true;
327 * @param string $match matched syntax
328 * @param int $state a LEXER_STATE_* constant
329 * @param int $pos byte position in the original source file
330 * @return bool mode handled?
332 public function notoc($match, $state, $pos) {
333 $this->addCall('notoc', array(), $pos);
338 * @param string $match matched syntax
339 * @param int $state a LEXER_STATE_* constant
340 * @param int $pos byte position in the original source file
341 * @return bool mode handled?
343 public function nocache($match, $state, $pos) {
344 $this->addCall('nocache', array(), $pos);
349 * @param string $match matched syntax
350 * @param int $state a LEXER_STATE_* constant
351 * @param int $pos byte position in the original source file
352 * @return bool mode handled?
354 public function linebreak($match, $state, $pos) {
355 $this->addCall('linebreak', array(), $pos);
360 * @param string $match matched syntax
361 * @param int $state a LEXER_STATE_* constant
362 * @param int $pos byte position in the original source file
363 * @return bool mode handled?
365 public function eol($match, $state, $pos) {
366 $this->addCall('eol', array(), $pos);
371 * @param string $match matched syntax
372 * @param int $state a LEXER_STATE_* constant
373 * @param int $pos byte position in the original source file
374 * @return bool mode handled?
376 public function hr($match, $state, $pos) {
377 $this->addCall('hr', array(), $pos);
382 * @param string $match matched syntax
383 * @param int $state a LEXER_STATE_* constant
384 * @param int $pos byte position in the original source file
385 * @return bool mode handled?
387 public function strong($match, $state, $pos) {
388 $this->nestingTag($match, $state, $pos, 'strong');
393 * @param string $match matched syntax
394 * @param int $state a LEXER_STATE_* constant
395 * @param int $pos byte position in the original source file
396 * @return bool mode handled?
398 public function emphasis($match, $state, $pos) {
399 $this->nestingTag($match, $state, $pos, 'emphasis');
404 * @param string $match matched syntax
405 * @param int $state a LEXER_STATE_* constant
406 * @param int $pos byte position in the original source file
407 * @return bool mode handled?
409 public function underline($match, $state, $pos) {
410 $this->nestingTag($match, $state, $pos, 'underline');
415 * @param string $match matched syntax
416 * @param int $state a LEXER_STATE_* constant
417 * @param int $pos byte position in the original source file
418 * @return bool mode handled?
420 public function monospace($match, $state, $pos) {
421 $this->nestingTag($match, $state, $pos, 'monospace');
426 * @param string $match matched syntax
427 * @param int $state a LEXER_STATE_* constant
428 * @param int $pos byte position in the original source file
429 * @return bool mode handled?
431 public function subscript($match, $state, $pos) {
432 $this->nestingTag($match, $state, $pos, 'subscript');
437 * @param string $match matched syntax
438 * @param int $state a LEXER_STATE_* constant
439 * @param int $pos byte position in the original source file
440 * @return bool mode handled?
442 public function superscript($match, $state, $pos) {
443 $this->nestingTag($match, $state, $pos, 'superscript');
448 * @param string $match matched syntax
449 * @param int $state a LEXER_STATE_* constant
450 * @param int $pos byte position in the original source file
451 * @return bool mode handled?
453 public function deleted($match, $state, $pos) {
454 $this->nestingTag($match, $state, $pos, 'deleted');
459 * @param string $match matched syntax
460 * @param int $state a LEXER_STATE_* constant
461 * @param int $pos byte position in the original source file
462 * @return bool mode handled?
464 public function footnote($match, $state, $pos) {
465 if (!isset($this->_footnote
)) $this->_footnote
= false;
468 case DOKU_LEXER_ENTER
:
469 // footnotes can not be nested - however due to limitations in lexer it can't be prevented
470 // we will still enter a new footnote mode, we just do nothing
471 if ($this->_footnote
) {
472 $this->addCall('cdata', array($match), $pos);
475 $this->_footnote
= true;
477 $this->callWriter
= new Nest($this->callWriter
, 'footnote_close');
478 $this->addCall('footnote_open', array(), $pos);
480 case DOKU_LEXER_EXIT
:
481 // check whether we have already exitted the footnote mode, can happen if the modes were nested
482 if (!$this->_footnote
) {
483 $this->addCall('cdata', array($match), $pos);
487 $this->_footnote
= false;
488 $this->addCall('footnote_close', array(), $pos);
490 /** @var Nest $reWriter */
491 $reWriter = $this->callWriter
;
492 $this->callWriter
= $reWriter->process();
494 case DOKU_LEXER_UNMATCHED
:
495 $this->addCall('cdata', array($match), $pos);
502 * @param string $match matched syntax
503 * @param int $state a LEXER_STATE_* constant
504 * @param int $pos byte position in the original source file
505 * @return bool mode handled?
507 public function listblock($match, $state, $pos) {
509 case DOKU_LEXER_ENTER
:
510 $this->callWriter
= new Lists($this->callWriter
);
511 $this->addCall('list_open', array($match), $pos);
513 case DOKU_LEXER_EXIT
:
514 $this->addCall('list_close', array(), $pos);
515 /** @var Lists $reWriter */
516 $reWriter = $this->callWriter
;
517 $this->callWriter
= $reWriter->process();
519 case DOKU_LEXER_MATCHED
:
520 $this->addCall('list_item', array($match), $pos);
522 case DOKU_LEXER_UNMATCHED
:
523 $this->addCall('cdata', array($match), $pos);
530 * @param string $match matched syntax
531 * @param int $state a LEXER_STATE_* constant
532 * @param int $pos byte position in the original source file
533 * @return bool mode handled?
535 public function unformatted($match, $state, $pos) {
536 if ( $state == DOKU_LEXER_UNMATCHED
) {
537 $this->addCall('unformatted', array($match), $pos);
543 * @param string $match matched syntax
544 * @param int $state a LEXER_STATE_* constant
545 * @param int $pos byte position in the original source file
546 * @return bool mode handled?
548 public function php($match, $state, $pos) {
549 if ( $state == DOKU_LEXER_UNMATCHED
) {
550 $this->addCall('php', array($match), $pos);
556 * @param string $match matched syntax
557 * @param int $state a LEXER_STATE_* constant
558 * @param int $pos byte position in the original source file
559 * @return bool mode handled?
561 public function phpblock($match, $state, $pos) {
562 if ( $state == DOKU_LEXER_UNMATCHED
) {
563 $this->addCall('phpblock', array($match), $pos);
569 * @param string $match matched syntax
570 * @param int $state a LEXER_STATE_* constant
571 * @param int $pos byte position in the original source file
572 * @return bool mode handled?
574 public function html($match, $state, $pos) {
575 if ( $state == DOKU_LEXER_UNMATCHED
) {
576 $this->addCall('html', array($match), $pos);
582 * @param string $match matched syntax
583 * @param int $state a LEXER_STATE_* constant
584 * @param int $pos byte position in the original source file
585 * @return bool mode handled?
587 public function htmlblock($match, $state, $pos) {
588 if ( $state == DOKU_LEXER_UNMATCHED
) {
589 $this->addCall('htmlblock', array($match), $pos);
595 * @param string $match matched syntax
596 * @param int $state a LEXER_STATE_* constant
597 * @param int $pos byte position in the original source file
598 * @return bool mode handled?
600 public function preformatted($match, $state, $pos) {
602 case DOKU_LEXER_ENTER
:
603 $this->callWriter
= new Preformatted($this->callWriter
);
604 $this->addCall('preformatted_start', array(), $pos);
606 case DOKU_LEXER_EXIT
:
607 $this->addCall('preformatted_end', array(), $pos);
608 /** @var Preformatted $reWriter */
609 $reWriter = $this->callWriter
;
610 $this->callWriter
= $reWriter->process();
612 case DOKU_LEXER_MATCHED
:
613 $this->addCall('preformatted_newline', array(), $pos);
615 case DOKU_LEXER_UNMATCHED
:
616 $this->addCall('preformatted_content', array($match), $pos);
624 * @param string $match matched syntax
625 * @param int $state a LEXER_STATE_* constant
626 * @param int $pos byte position in the original source file
627 * @return bool mode handled?
629 public function quote($match, $state, $pos) {
633 case DOKU_LEXER_ENTER
:
634 $this->callWriter
= new Quote($this->callWriter
);
635 $this->addCall('quote_start', array($match), $pos);
638 case DOKU_LEXER_EXIT
:
639 $this->addCall('quote_end', array(), $pos);
640 /** @var Lists $reWriter */
641 $reWriter = $this->callWriter
;
642 $this->callWriter
= $reWriter->process();
645 case DOKU_LEXER_MATCHED
:
646 $this->addCall('quote_newline', array($match), $pos);
649 case DOKU_LEXER_UNMATCHED
:
650 $this->addCall('cdata', array($match), $pos);
659 * @param string $match matched syntax
660 * @param int $state a LEXER_STATE_* constant
661 * @param int $pos byte position in the original source file
662 * @return bool mode handled?
664 public function file($match, $state, $pos) {
665 return $this->code($match, $state, $pos, 'file');
669 * @param string $match matched syntax
670 * @param int $state a LEXER_STATE_* constant
671 * @param int $pos byte position in the original source file
672 * @param string $type either 'code' or 'file'
673 * @return bool mode handled?
675 public function code($match, $state, $pos, $type='code') {
676 if ( $state == DOKU_LEXER_UNMATCHED
) {
677 $matches = explode('>',$match,2);
678 // Cut out variable options enclosed in []
679 preg_match('/\[.*\]/', $matches[0], $options);
680 if (!empty($options[0])) {
681 $matches[0] = str_replace($options[0], '', $matches[0]);
683 $param = preg_split('/\s+/', $matches[0], 2, PREG_SPLIT_NO_EMPTY
);
684 while(count($param) < 2) array_push($param, null);
685 // We shortcut html here.
686 if ($param[0] == 'html') $param[0] = 'html4strict';
687 if ($param[0] == '-') $param[0] = null;
688 array_unshift($param, $matches[1]);
689 if (!empty($options[0])) {
690 $param [] = $this->parse_highlight_options ($options[0]);
692 $this->addCall($type, $param, $pos);
698 * @param string $match matched syntax
699 * @param int $state a LEXER_STATE_* constant
700 * @param int $pos byte position in the original source file
701 * @return bool mode handled?
703 public function acronym($match, $state, $pos) {
704 $this->addCall('acronym', array($match), $pos);
709 * @param string $match matched syntax
710 * @param int $state a LEXER_STATE_* constant
711 * @param int $pos byte position in the original source file
712 * @return bool mode handled?
714 public function smiley($match, $state, $pos) {
715 $this->addCall('smiley', array($match), $pos);
720 * @param string $match matched syntax
721 * @param int $state a LEXER_STATE_* constant
722 * @param int $pos byte position in the original source file
723 * @return bool mode handled?
725 public function wordblock($match, $state, $pos) {
726 $this->addCall('wordblock', array($match), $pos);
731 * @param string $match matched syntax
732 * @param int $state a LEXER_STATE_* constant
733 * @param int $pos byte position in the original source file
734 * @return bool mode handled?
736 public function entity($match, $state, $pos) {
737 $this->addCall('entity', array($match), $pos);
742 * @param string $match matched syntax
743 * @param int $state a LEXER_STATE_* constant
744 * @param int $pos byte position in the original source file
745 * @return bool mode handled?
747 public function multiplyentity($match, $state, $pos) {
748 preg_match_all('/\d+/',$match,$matches);
749 $this->addCall('multiplyentity', array($matches[0][0], $matches[0][1]), $pos);
754 * @param string $match matched syntax
755 * @param int $state a LEXER_STATE_* constant
756 * @param int $pos byte position in the original source file
757 * @return bool mode handled?
759 public function singlequoteopening($match, $state, $pos) {
760 $this->addCall('singlequoteopening', array(), $pos);
765 * @param string $match matched syntax
766 * @param int $state a LEXER_STATE_* constant
767 * @param int $pos byte position in the original source file
768 * @return bool mode handled?
770 public function singlequoteclosing($match, $state, $pos) {
771 $this->addCall('singlequoteclosing', array(), $pos);
776 * @param string $match matched syntax
777 * @param int $state a LEXER_STATE_* constant
778 * @param int $pos byte position in the original source file
779 * @return bool mode handled?
781 public function apostrophe($match, $state, $pos) {
782 $this->addCall('apostrophe', array(), $pos);
787 * @param string $match matched syntax
788 * @param int $state a LEXER_STATE_* constant
789 * @param int $pos byte position in the original source file
790 * @return bool mode handled?
792 public function doublequoteopening($match, $state, $pos) {
793 $this->addCall('doublequoteopening', array(), $pos);
794 $this->status
['doublequote']++
;
799 * @param string $match matched syntax
800 * @param int $state a LEXER_STATE_* constant
801 * @param int $pos byte position in the original source file
802 * @return bool mode handled?
804 public function doublequoteclosing($match, $state, $pos) {
805 if ($this->status
['doublequote'] <= 0) {
806 $this->doublequoteopening($match, $state, $pos);
808 $this->addCall('doublequoteclosing', array(), $pos);
809 $this->status
['doublequote'] = max(0, --$this->status
['doublequote']);
815 * @param string $match matched syntax
816 * @param int $state a LEXER_STATE_* constant
817 * @param int $pos byte position in the original source file
818 * @return bool mode handled?
820 public function camelcaselink($match, $state, $pos) {
821 $this->addCall('camelcaselink', array($match), $pos);
826 * @param string $match matched syntax
827 * @param int $state a LEXER_STATE_* constant
828 * @param int $pos byte position in the original source file
829 * @return bool mode handled?
831 public function internallink($match, $state, $pos) {
832 // Strip the opening and closing markup
833 $link = preg_replace(array('/^\[\[/','/\]\]$/u'),'',$match);
835 // Split title from URL
836 $link = explode('|',$link,2);
837 if ( !isset($link[1]) ) {
839 } else if ( preg_match('/^\{\{[^\}]+\}\}$/',$link[1]) ) {
840 // If the title is an image, convert it to an array containing the image details
841 $link[1] = Doku_Handler_Parse_Media($link[1]);
843 $link[0] = trim($link[0]);
845 //decide which kind of link it is
847 if ( link_isinterwiki($link[0]) ) {
849 $interwiki = explode('>',$link[0],2);
852 array($link[0],$link[1],strtolower($interwiki[0]),$interwiki[1]),
855 }elseif ( preg_match('/^\\\\\\\\[^\\\\]+?\\\\/u',$link[0]) ) {
859 array($link[0],$link[1]),
862 }elseif ( preg_match('#^([a-z0-9\-\.+]+?)://#i',$link[0]) ) {
863 // external link (accepts all protocols)
866 array($link[0],$link[1]),
869 }elseif ( preg_match('<'.PREG_PATTERN_VALID_EMAIL
.'>',$link[0]) ) {
870 // E-Mail (pattern above is defined in inc/mail.php)
873 array($link[0],$link[1]),
876 }elseif ( preg_match('!^#.+!',$link[0]) ){
880 array(substr($link[0],1),$link[1]),
887 array($link[0],$link[1]),
896 * @param string $match matched syntax
897 * @param int $state a LEXER_STATE_* constant
898 * @param int $pos byte position in the original source file
899 * @return bool mode handled?
901 public function filelink($match, $state, $pos) {
902 $this->addCall('filelink', array($match, null), $pos);
907 * @param string $match matched syntax
908 * @param int $state a LEXER_STATE_* constant
909 * @param int $pos byte position in the original source file
910 * @return bool mode handled?
912 public function windowssharelink($match, $state, $pos) {
913 $this->addCall('windowssharelink', array($match, null), $pos);
918 * @param string $match matched syntax
919 * @param int $state a LEXER_STATE_* constant
920 * @param int $pos byte position in the original source file
921 * @return bool mode handled?
923 public function media($match, $state, $pos) {
924 $p = Doku_Handler_Parse_Media($match);
928 array($p['src'], $p['title'], $p['align'], $p['width'],
929 $p['height'], $p['cache'], $p['linking']),
936 * @param string $match matched syntax
937 * @param int $state a LEXER_STATE_* constant
938 * @param int $pos byte position in the original source file
939 * @return bool mode handled?
941 public function rss($match, $state, $pos) {
942 $link = preg_replace(array('/^\{\{rss>/','/\}\}$/'),'',$match);
945 list($link,$params) = explode(' ',$link,2);
948 if(preg_match('/\b(\d+)\b/',$params,$match)){
949 $p['max'] = $match[1];
953 $p['reverse'] = (preg_match('/rev/',$params));
954 $p['author'] = (preg_match('/\b(by|author)/',$params));
955 $p['date'] = (preg_match('/\b(date)/',$params));
956 $p['details'] = (preg_match('/\b(desc|detail)/',$params));
957 $p['nosort'] = (preg_match('/\b(nosort)\b/',$params));
959 if (preg_match('/\b(\d+)([dhm])\b/',$params,$match)) {
960 $period = array('d' => 86400, 'h' => 3600, 'm' => 60);
961 $p['refresh'] = max(600,$match[1]*$period[$match[2]]); // n * period in seconds, minimum 10 minutes
963 $p['refresh'] = 14400; // default to 4 hours
966 $this->addCall('rss', array($link, $p), $pos);
971 * @param string $match matched syntax
972 * @param int $state a LEXER_STATE_* constant
973 * @param int $pos byte position in the original source file
974 * @return bool mode handled?
976 public function externallink($match, $state, $pos) {
980 // add protocol on simple short URLs
981 if(substr($url,0,3) == 'ftp' && (substr($url,0,6) != 'ftp://')){
983 $url = 'ftp://'.$url;
985 if(substr($url,0,3) == 'www' && (substr($url,0,7) != 'http://')){
987 $url = 'http://'.$url;
990 $this->addCall('externallink', array($url, $title), $pos);
995 * @param string $match matched syntax
996 * @param int $state a LEXER_STATE_* constant
997 * @param int $pos byte position in the original source file
998 * @return bool mode handled?
1000 public function emaillink($match, $state, $pos) {
1001 $email = preg_replace(array('/^</','/>$/'),'',$match);
1002 $this->addCall('emaillink', array($email, null), $pos);
1007 * @param string $match matched syntax
1008 * @param int $state a LEXER_STATE_* constant
1009 * @param int $pos byte position in the original source file
1010 * @return bool mode handled?
1012 public function table($match, $state, $pos) {
1015 case DOKU_LEXER_ENTER
:
1017 $this->callWriter
= new Table($this->callWriter
);
1019 $this->addCall('table_start', array($pos +
1), $pos);
1020 if ( trim($match) == '^' ) {
1021 $this->addCall('tableheader', array(), $pos);
1023 $this->addCall('tablecell', array(), $pos);
1027 case DOKU_LEXER_EXIT
:
1028 $this->addCall('table_end', array($pos), $pos);
1029 /** @var Table $reWriter */
1030 $reWriter = $this->callWriter
;
1031 $this->callWriter
= $reWriter->process();
1034 case DOKU_LEXER_UNMATCHED
:
1035 if ( trim($match) != '' ) {
1036 $this->addCall('cdata', array($match), $pos);
1040 case DOKU_LEXER_MATCHED
:
1041 if ( $match == ' ' ){
1042 $this->addCall('cdata', array($match), $pos);
1043 } else if ( preg_match('/:::/',$match) ) {
1044 $this->addCall('rowspan', array($match), $pos);
1045 } else if ( preg_match('/\t+/',$match) ) {
1046 $this->addCall('table_align', array($match), $pos);
1047 } else if ( preg_match('/ {2,}/',$match) ) {
1048 $this->addCall('table_align', array($match), $pos);
1049 } else if ( $match == "\n|" ) {
1050 $this->addCall('table_row', array(), $pos);
1051 $this->addCall('tablecell', array(), $pos);
1052 } else if ( $match == "\n^" ) {
1053 $this->addCall('table_row', array(), $pos);
1054 $this->addCall('tableheader', array(), $pos);
1055 } else if ( $match == '|' ) {
1056 $this->addCall('tablecell', array(), $pos);
1057 } else if ( $match == '^' ) {
1058 $this->addCall('tableheader', array(), $pos);
1068 //------------------------------------------------------------------------
1069 function Doku_Handler_Parse_Media($match) {
1071 // Strip the opening and closing markup
1072 $link = preg_replace(array('/^\{\{/','/\}\}$/u'),'',$match);
1074 // Split title from URL
1075 $link = explode('|',$link,2);
1078 $ralign = (bool)preg_match('/^ /',$link[0]);
1079 $lalign = (bool)preg_match('/ $/',$link[0]);
1081 // Logic = what's that ;)...
1082 if ( $lalign & $ralign ) {
1084 } else if ( $ralign ) {
1086 } else if ( $lalign ) {
1093 if ( !isset($link[1]) ) {
1097 //remove aligning spaces
1098 $link[0] = trim($link[0]);
1100 //split into src and parameters (using the very last questionmark)
1101 $pos = strrpos($link[0], '?');
1103 $src = substr($link[0],0,$pos);
1104 $param = substr($link[0],$pos+
1);
1110 //parse width and height
1111 if(preg_match('#(\d+)(x(\d+))?#i',$param,$size)){
1112 !empty($size[1]) ?
$w = $size[1] : $w = null;
1113 !empty($size[3]) ?
$h = $size[3] : $h = null;
1119 //get linking command
1120 if(preg_match('/nolink/i',$param)){
1121 $linking = 'nolink';
1122 }else if(preg_match('/direct/i',$param)){
1123 $linking = 'direct';
1124 }else if(preg_match('/linkonly/i',$param)){
1125 $linking = 'linkonly';
1127 $linking = 'details';
1130 //get caching command
1131 if (preg_match('/(nocache|recache)/i',$param,$cachemode)){
1132 $cache = $cachemode[1];
1137 // Check whether this is a local or remote image or interwiki
1138 if (media_isexternal($src) ||
link_isinterwiki($src)){
1139 $call = 'externalmedia';
1141 $call = 'internalmedia';
1152 'linking'=>$linking,