xref: /plugin/mikioplugin/syntax/box.php (revision 1766d43cf4685e267cea351d5a11d3dc7672fcf1)
1<?php
2/**
3 * Mikio Syntax Plugin: Box
4 *
5 * @link        http://github.com/nomadjimbob/mikioplugin
6 * @license     GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author      James Collins <james.collins@outlook.com.au>
8 */
9if (!defined('DOKU_INC')) die();
10if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11require_once(dirname(__FILE__).'/core.php');
12
13class syntax_plugin_mikioplugin_box extends syntax_plugin_mikioplugin_core {
14    public $tag                 = 'box';
15    public $hasEndTag           = true;
16    public $options             = array(
17        'attr'          => array('type'     => 'text'),
18        'round'         => array('type'     => 'size',  'default'   => '0'),
19        'border-color'  => array('type'     => 'color', 'default'   => ''),
20        'border-width'  => array('type'     => 'multisize',  'default'   => ''),
21        'reveal'        => array('type'     => 'boolean', 'default' => 'false'),
22        'reveal-text'   => array('type'     => 'text',  'default'   => 'Reveal'),
23        'url'           => array('type'     => 'url',       'default'   => ''),
24        'color'         => array('type'    => 'color',    'default' => ''),
25        'padding'       => array('type'     => 'multisize',  'default'   => ''),
26        'margin'       => array('type'     => 'multisize',  'default'   => ''),
27        'grid-row'          => array('type' => 'text'),
28        'grid-row-start'    => array('type' => 'number'),
29        'grid-row-end'      => array('type' => 'number'),
30        'grid-row-span'     => array('type' => 'number'),
31        'grid-col'          => array('type' => 'text'),
32        'grid-col-start'    => array('type' => 'number'),
33        'grid-col-end'      => array('type' => 'number'),
34        'grid-col-span'     => array('type' => 'number'),
35    );
36
37    public function __construct() {
38        $this->addCommonOptions('width height type shadow text-align links-match');
39    }
40
41    public function render_lexer_enter(Doku_Renderer $renderer, $data) {
42        if($data['attr'] != '') {
43            $data = array_merge($data, $this->callMikioTag('setattr', $data['attr']));
44            // echo '#' . $this->callMikioTag('setattr', $data['attr']) . '#';
45        }
46
47        $tag = 'div';
48        if($data['url'] != '') $tag = 'a';
49
50        if($data['grid-row-span'] != '') $data['grid-row-end'] = 'span ' . $data['grid-row-span'];
51        if($data['grid-col-span'] != '') $data['grid-col-end'] = 'span ' . $data['grid-col-span'];
52
53        if($data['grid-row'] != '') {
54            $parts = explode(' ', $data['grid-row']);
55            $i = count($parts);
56            if($i == 2 || $i == 3) {
57                $data['grid-row-start'] = filter_var($parts[0], FILTER_VALIDATE_INT);
58            }
59
60            if($i == 2) {
61                $data['grid-row-end'] = filter_var($parts[1], FILTER_VALIDATE_INT);
62            } else {
63                $data['grid-row-end'] = strtolower($parts[1]) . ' ' . filter_var($parts[2], FILTER_VALIDATE_INT);
64            }
65        }
66
67        if($data['grid-col'] != '') {
68            $parts = explode(' ', $data['grid-col']);
69            $i = count($parts);
70            if($i == 2 || $i == 3) {
71                $data['grid-col-start'] = filter_var($parts[0], FILTER_VALIDATE_INT);
72            }
73
74            if($i == 2) {
75                $data['grid-col-end'] = filter_var($parts[1], FILTER_VALIDATE_INT);
76            } else {
77                $data['grid-col-end'] = strtolower($parts[1]) . ' ' . filter_var($parts[2], FILTER_VALIDATE_INT);
78            }
79        }
80
81        $classes = $this->buildClass($data);
82        $styles = $this->buildStyle(array(
83            'width'         => $data['width'],
84            'height'        => $data['height'],
85            'border-radius' => $data['round'],
86            'border-color'  => $data['border-color'],
87            'border-width'  => $data['border-width'],
88            'color'         => $data['color'],
89            'padding'       => $data['padding'],
90            'margin'        => $data['margin'],
91            'grid-row-start'    => $data['grid-row-start'],
92            'grid-row-end'      => $data['grid-row-end'],
93            'grid-col-start'    => $data['grid-col-start'],
94            'grid-col-end'      => $data['grid-col-end'],
95
96        ), TRUE);
97
98        $renderer->doc .= '<' . $tag . ($data['url'] != '' ? ' href="' . $data['url'] . '"' : '') . ' class="' . $this->elemClass . ' ' . $this->classPrefix . 'box'. $classes .'"' . $styles. '>';
99        if($data['reveal']) $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'reveal">' . $data['reveal-text'] . '</div>';
100    }
101
102
103    public function render_lexer_exit(Doku_Renderer $renderer, $data) {
104        $tag = 'div';
105        if($data['url'] != '') $tag = 'a';
106
107        $renderer->doc .= '</' . $tag . '>';
108    }
109}
110?>