1<?php
2/**
3 * Mikio Syntax Plugin: Card
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();
10}
11if (!defined('DOKU_PLUGIN')) { define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
12}
13require_once dirname(__FILE__).'/core.php';
14
15class syntax_plugin_mikioplugin_card extends syntax_plugin_mikioplugin_core
16{
17    public $tag                 = 'card';
18    public $hasEndTag           = true;
19    public $options             = array(
20        'image'                         => array('type' => 'media',     'default'   => ''),
21        'image-cover'                   => array('type' => 'boolean',   'default'   => 'false'),
22        'image-height'                  => array('type' => 'size',      'default'   => ''),
23        'overlay'                       => array('type' => 'boolean',   'default'   => 'false'),
24        'title'                         => array('type' => 'text',      'default'   => ''),
25        'title-text-align'              => array('type' => 'choice',    'data'      => array(
26            'left' => array('text-left'), 'center' => array('text-center'), 'right' => array('text-right')
27        )),
28        'title-text-color'              => array('type' => 'text',      'default'   => ''),
29        'subtitle'                      => array('type' => 'text',      'default'   => ''),
30        'subtitle-text-align'           => array('type' => 'choice',    'data'      => array(
31            'left' => array('text-left'), 'center' => array('text-center'), 'right' => array('text-right')
32        )),
33        'subtitle-text-color'           => array('type' => 'text',      'default'   => ''),
34        'no-body'                       => array('type' => 'boolean',   'default'   => 'false'),
35        'header'                        => array('type' => 'text',      'default'   => ''),
36        'header-text-align'             => array('type' => 'choice',    'data'      => array(
37            'left' => array('text-left'), 'center' => array('text-center'), 'right' => array('text-right')
38        )),
39        'header-text-color'             => array('type' => 'text',      'default'   => ''),
40        'footer'                        => array('type' => 'text',      'default'   => ''),
41        'footer-text-align'             => array('type' => 'choice',    'data'      => array(
42            'left' => array('text-left'), 'center' => array('text-center'), 'right' => array('text-right')
43        )),
44        'footer-text-color'             => array('type' => 'text',      'default'   => ''),
45        'placeholder-text'              => array('type' => 'text',      'default'   => ''),
46        'placeholder-color'             => array('type' => 'text',      'default'   => ''),
47        'placeholder-text-color'        => array('type' => 'text',      'default'   => ''),
48        'placeholder-height'            => array('type' => 'size',      'default'   => ''),
49        'footer-image'                  => array('type' => 'media',     'default'   => ''),
50        'footer-image-cover'            => array('type' => 'boolean',   'default'   => 'false'),
51        'footer-placeholder-text'       => array('type' => 'text',      'default'   => ''),
52        'footer-placeholder-color'      => array('type' => 'text',      'default'   => ''),
53        'footer-placeholder-text-color' => array('type' => 'text',      'default'   => ''),
54        'horizontal'                    => array('type' => 'boolean',   'default'   => 'false'),
55        'footer-small'                  => array('type' => 'boolean',   'default'   => 'false'),
56    );
57
58
59    public function __construct()
60    {
61        $this->addCommonOptions('type shadow width height text-align vertical-align text-color');
62    }
63
64    public function getAllowedTypes()
65    {
66        return array('formatting', 'substition', 'disabled', 'container', 'protected');
67    }
68    public function getPType()
69    {
70        return 'normal';
71    }
72
73    public function render_lexer_enter(Doku_Renderer $renderer, $data)
74    {
75        $classes = $this->buildClass($data, array('overlay', 'horizontal'));
76        $styles = $this->buildStyle(array('height' => $data['height'], 'width' => $data['width']), true);
77
78        $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'card' . $classes . '"' . $styles . '>';
79
80        if($data['horizontal']) { $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'card-horizontal-image">';
81        }
82        if($data['placeholder-text'] != '') {
83            $this->syntaxRender($renderer, 'placeholder', '', $this->arrayRemoveEmpties(array('text' => $data['placeholder-text'], 'color' => $data['placeholder-color'], 'text-color' => $data['placeholder-text-color'], 'height' => $data['placeholder-height'])));
84        } elseif($data['image'] != '') {
85            $style = '';
86            if($data['image-height'] != '') {
87                $style = 'height:' . $data['image-height'] . ';';
88            }
89            $renderer->doc .= '<img src="' . $data['image'] . '" class="' . $this->elemClass . ' ' . $this->classPrefix . 'card-image' . ($data['image-cover'] ? ' ' . $this->classPrefix . 'image-cover' : '') . '" style="' . $style . '">';
90        }
91        if($data['horizontal']) { $renderer->doc .= '</div><div class="' . $this->elemClass . ' ' . $this->classPrefix . 'card-horizontal-body">';
92        }
93
94        if($data['header'] != '') {
95            $this->syntaxRender($renderer, 'cardheader', $data['header'], $this->arrayRemoveEmpties(array('text-align' => $data['header-text-align'], 'text-color' => $data['header-text-color'])));
96        }
97
98        if($data['no-body'] == false) { $this->syntaxRender($renderer, 'cardbody', '', $this->arrayRemoveEmpties(array('vertical-align' => $data['vertical-align'], 'text-color' => $data['text-color'])), MIKIO_LEXER_ENTER);
99        }
100
101        if($data['title'] != '') {
102            $this->syntaxRender($renderer, 'cardtitle', $data['title'], $this->arrayRemoveEmpties(array('text-align' => $data['title-text-align'], 'text-color' => $data['title-text-color'])));
103        }
104
105        if($data['subtitle'] != '') {
106            $this->syntaxRender($renderer, 'cardsubtitle', $data['subtitle'], $this->arrayRemoveEmpties(array('text-align' => $data['subtitle-text-align'], 'text-color' => $data['subtitle-text-color'])));
107        }
108    }
109
110
111    public function render_lexer_exit(Doku_Renderer $renderer, $data)
112    {
113        if($data['no-body'] == false) { $this->syntaxRender($renderer, 'cardbody', '', null, MIKIO_LEXER_EXIT);
114        }
115
116        if($data['footer'] != '') {
117            $this->syntaxRender($renderer, 'cardfooter', $data['footer'], $this->arrayRemoveEmpties(array('small' => $data['footer-small'], 'text-align' => $data['footer-text-align'], 'text-color' => $data['footer-text-color'])));
118        }
119
120        if($data['footer-placeholder-text'] != '') {
121            $this->syntaxRender($renderer, 'placeholder', '', $this->arrayRemoveEmpties(array('text' => $data['footer-placeholder-text'], 'color' => $data['footer-placeholder-color'], 'text-color' => $data['footer-placeholder-text-color'])));
122        } elseif($data['footer-image'] != '') {
123            $renderer->doc .= '<img src="' . $data['footer-image'] . '" class="' . $this->elemClass . ' ' . $this->classPrefix . 'card-image' . ($data['footer-image-cover'] ? ' ' . $this->classPrefix . 'image-cover' : '') .'">';
124        }
125
126        if($data['horizontal']) { $renderer->doc .= '</div>';
127        }
128        $renderer->doc .= '</div>';
129    }
130}
131?>