dokuwiki-plugin-bootstyle/syntax/container.php

94 lines
3.1 KiB
PHP
Raw Permalink Normal View History

2021-07-12 18:22:41 +02:00
<?php
/**
* Bootstrap Wrapper Plugin: Container (grid alias)
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
* @copyright (C) 2015-2020, Giuseppe Di Terlizzi
*/
class syntax_plugin_bootstyle_container extends syntax_plugin_bootswrapper_bootstrap
{
public $p_type = 'block';
public $pattern_start = '<container.*?>(?=[\w\W]*?</container>)';
public $pattern_end = '</container>';
public $tag_name = 'container';
public $tag_attributes = array(
'fluid' => array(
'type' => 'string',
'values' => array("0", "1", "2"),
'required' => false,
'default' => false
),
);
public function connectTo($mode)
{
$this->Lexer->addEntryPattern($this->pattern_start, $mode, 'plugin_bootstyle_' . $this->getPluginComponent());
}
public function postConnect()
{
$this->Lexer->addExitPattern($this->pattern_end, 'plugin_bootstyle_' . $this->getPluginComponent());
$this->Lexer->addPattern($this->header_pattern, 'plugin_bootstyle_' . $this->getPluginComponent());
}
public function removeClass($class, $classes) {
$containerIndex = array_search($class, $classes);
if($containerIndex !== false) {
unset($classes[$containerIndex]);
}
return $classes;
}
public function render($mode, Doku_Renderer $renderer, $data)
{
if (empty($data)) {
return false;
}
if ($mode !== 'xhtml') {
return false;
}
/** @var Doku_Renderer_xhtml $renderer */
$data["target"] = "container";
list($state, $match, $pos, $attributes) = $data;
//print_r($data);
if ($state == DOKU_LEXER_ENTER) {
extract($attributes);
$this->wrapInner = (isset($attributes['fluid']) ? $attributes['fluid'] == 2 : false);
$html_attributes = $this->mergeCoreAttributes($attributes);
if(isset($attributes["fluid"]) && $attributes["fluid"] > 0) {
$html_attributes["class"][] = "container-fluid";
} else {
$html_attributes["class"][] = "container";
}
if(isset($html_attributes["fluid"])) {
unset($html_attributes["fluid"]);
}
$html_attributes["class"][] = $renderer->startSectionEdit($pos, $data);
$renderer->doc .= '<div ' . $this->buildAttributes($html_attributes) . '>';
if($this->wrapInner) {
$renderer->doc .= '<div class="container">';
}
return true;
}
if ($state == DOKU_LEXER_EXIT) {
// TODO: only the first container gets the button at the correct spot.
$renderer->finishSectionEdit($pos+strlen("</container>"));
if($this->wrapInner) {
$renderer->doc .= '</div>';
}
$renderer->doc .= '</div>';
return true;
}
return true;
}
}