',$mode,'plugin_imagecarousel');
// $this->Lexer->addSpecialPattern("\{\{[^\}]+\}\}",$mode,'media');
}
public function postConnect() {
$this->Lexer->addPattern('\n {2,}[\*]','plugin_imagecarousel');
$this->Lexer->addExitPattern('','plugin_imagecarousel');
}
protected $first_item = [];
/**
* Handle matches of the imagecarousel syntax
*
* @param string $match The match of the syntax
* @param int $state The state of the handler
* @param int $pos The position in the document
* @param Doku_Handler $handler The handler
* @return array Data for the renderer
*/
public function handle($match, $state, $pos, Doku_Handler $handler){
global $ID;
$data = array();
$data['state'] = $state;
switch($state) {
case DOKU_LEXER_ENTER:
$match = substr($match, 9,-1); // strip markup
$flags = $this->parseFlags($match);
$flags['slick'] = json_encode(array_merge(
$this->getDefaultFlags(),
$flags['slick']
));
$data['flags'] = $flags;
break;
case DOKU_LEXER_UNMATCHED:
if (trim($match) !== '') {
$handler->_addCall('cdata', array($match), $pos);
}
break;
case DOKU_LEXER_EXIT:
$this->first_item[$ID] = false;
break;
case DOKU_LEXER_MATCHED:
if($match === "\n *") {
if(!isset($this->first_item[$ID]) || !$this->first_item[$ID]) {
$this->first_item[$ID] = true;
$data['first_item'] = true;
}
}
break;
}
return $data;
}
/**
* Render xhtml output or metadata
*
* @param string $mode Renderer mode (supported modes: xhtml)
* @param Doku_Renderer $renderer The renderer
* @param array $data The data from the handler() function
* @return bool If rendering was successful.
*/
public function render($mode, Doku_Renderer $renderer, $data) {
if($mode != 'xhtml') return false;
if($data['state'] === DOKU_LEXER_ENTER) {
$width = ' style="width:'.hsc($data['flags']['self']['width']).'" ';
$renderer->doc .= '';
$renderer->doc .= '
';
} else if($data['state'] === DOKU_LEXER_EXIT) {
$renderer->doc .= '
';
} else if($data['state'] === DOKU_LEXER_MATCHED) {
if(!isset($data['first_item'])) {
$renderer->doc .= '';
$renderer->doc .= '';
}
}
return true;
}
protected function getDefaultFlags() {
$conf = $this->getConf('default');
return $this->parseFlags($conf);
}
protected function parseFlags($confString) {
$confString = explode('&',$confString);
$flags = array(
'slick' => array(),
'self' => array(
'position' => 'center',
'width' => '100%'
),
);
foreach($confString as $flag) {
switch($flag) {
case 'center':
$flags['self']['position'] = 'center';
break;
case 'left':
$flags['self']['position'] = 'left';
break;
}
$tmp = explode('=',$flag,2);
if(count($tmp) === 2) {
switch($tmp[0]) {
case 'width':
$flags['self']['width'] = $tmp[1];
break;
default: //slick parameter
if($tmp[1] === "true") $tmp[1] = true;
else if($tmp[1] === "false") $tmp[1] = false;
else if(is_numeric($tmp[1])) $tmp[1] = intval($tmp[1]);
$flags['slick'][$tmp[0]] = $tmp[1];
break;
}
}
}
return $flags;
}
}
// vim:ts=4:sw=4:et: