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 vertical-align');
39    }
40
41    public function getPType() { return 'normal'; }
42
43    public function render_lexer_enter(Doku_Renderer $renderer, $data) {
44        if($data['attr'] != '') {
45            $data = array_merge($data, $this->callMikioTag('setattr', $data['attr']));
46        }
47
48        $tag = 'div';
49        if($data['url'] != '') $tag = 'a';
50
51        if($data['grid-row-span'] != '') $data['grid-row-end'] = 'span ' . $data['grid-row-span'];
52        if($data['grid-col-span'] != '') $data['grid-col-end'] = 'span ' . $data['grid-col-span'];
53
54        if($data['grid-row'] != '') {
55            $parts = explode(' ', $data['grid-row']);
56            $i = count($parts);
57            if($i == 2 || $i == 3) {
58                $data['grid-row-start'] = filter_var($parts[0], FILTER_VALIDATE_INT);
59            }
60
61            if($i == 2) {
62                $data['grid-row-end'] = filter_var($parts[1], FILTER_VALIDATE_INT);
63            } else {
64                $data['grid-row-end'] = strtolower($parts[1]) . ' ' . filter_var($parts[2], FILTER_VALIDATE_INT);
65            }
66        }
67
68        if($data['grid-col'] != '') {
69            $parts = explode(' ', $data['grid-col']);
70            $i = count($parts);
71            if($i == 2 || $i == 3) {
72                $data['grid-col-start'] = filter_var($parts[0], FILTER_VALIDATE_INT);
73            }
74
75            if($i == 2) {
76                $data['grid-col-end'] = filter_var($parts[1], FILTER_VALIDATE_INT);
77            } else {
78                $data['grid-col-end'] = strtolower($parts[1]) . ' ' . filter_var($parts[2], FILTER_VALIDATE_INT);
79            }
80        }
81
82        $classes = $this->buildClass($data);
83        $styles = $this->buildStyle(array(
84            'width'         => $data['width'],
85            'height'        => $data['height'],
86            'border-radius' => $data['round'],
87            'border-color'  => $data['border-color'],
88            'border-width'  => $data['border-width'],
89            'color'         => $data['color'],
90            'padding'       => $data['padding'],
91            'margin'        => $data['margin'],
92            'grid-row-start'    => $data['grid-row-start'],
93            'grid-row-end'      => $data['grid-row-end'],
94            'grid-column-start'    => $data['grid-col-start'],
95            'grid-column-end'      => $data['grid-col-end'],
96
97        ), TRUE);
98
99        $renderer->doc .= '<' . $tag . ($data['url'] != '' ? ' href="' . $data['url'] . '"' : '') . ' class="' . $this->elemClass . ' ' . $this->classPrefix . 'box'. $classes .'"' . $styles. '>';
100        if($data['reveal']) $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'reveal">' . $data['reveal-text'] . '</div>';
101    }
102
103
104    public function render_lexer_exit(Doku_Renderer $renderer, $data) {
105        $tag = 'div';
106        if($data['url'] != '') $tag = 'a';
107
108        $renderer->doc .= '</' . $tag . '>';
109    }
110}
111?>