xref: /plugin/mikioplugin/syntax/card.php (revision 6a8ce132ee7f679af64d1f8610f000730ef93359)
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        'subtitle'      => array('type'     => 'text',      'default'   => ''),
26        'no-body'        => array('type'     => 'boolean',   'default'   => 'false'),
27        'header'      => array('type'     => 'text',      'default'   => ''),
28        'footer'      => array('type'     => 'text',      'default'   => ''),
29        'placeholder-text'      => array('type'     => 'text',      'default'   => ''),
30        'placeholder-color'      => array('type'     => 'text',      'default'   => ''),
31        'placeholder-text-color'      => array('type'     => 'text',      'default'   => ''),
32        'placeholder-height' => array('type' => 'size', 'default' => ''),
33        'footer-image'      => array('type'     => 'media',      'default'   => ''),
34        'footer-image-cover' => array('type'     => 'boolean',      'default'   => 'false'),
35        'footer-placeholder-text'      => array('type'     => 'text',      'default'   => ''),
36        'footer-placeholder-color'      => array('type'     => 'text',      'default'   => ''),
37        'footer-placeholder-text-color'      => array('type'     => 'text',      'default'   => ''),
38        'horizontal'            => array('type'     => 'boolean',   'default'   => 'false'),
39        'footer-small'        => array('type'     => 'boolean',   'default'   => 'false'),
40    );
41
42
43    public function __construct()
44    {
45        $this->addCommonOptions('type shadow width height text-align vertical-align text-color');
46    }
47
48    public function getAllowedTypes()
49    {
50        return array('formatting', 'substition', 'disabled', 'container', 'protected');
51    }
52    public function getPType()
53    {
54        return 'normal';
55    }
56
57    public function render_lexer_enter(Doku_Renderer $renderer, $data)
58    {
59        $classes = $this->buildClass($data, array('overlay', 'horizontal'));
60        $styles = $this->buildStyle(array('height' => $data['height'], 'width' => $data['width']), true);
61
62        $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'card' . $classes . '"' . $styles . '>';
63
64        if($data['horizontal']) { $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'card-horizontal-image">';
65        }
66        if($data['placeholder-text'] != '') {
67            $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'])));
68        } elseif($data['image'] != '') {
69            $style = '';
70            if($data['image-height'] != '') {
71                $style = 'height:' . $data['image-height'] . ';';
72            }
73            $renderer->doc .= '<img src="' . $data['image'] . '" class="' . $this->elemClass . ' ' . $this->classPrefix . 'card-image' . ($data['image-cover'] ? ' ' . $this->classPrefix . 'image-cover' : '') . '" style="' . $style . '">';
74        }
75        if($data['horizontal']) { $renderer->doc .= '</div><div class="' . $this->elemClass . ' ' . $this->classPrefix . 'card-horizontal-body">';
76        }
77
78        if($data['header'] != '') { $this->syntaxRender($renderer, 'cardheader', $data['header']);
79        }
80
81        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);
82        }
83
84        if($data['title'] != '') { $this->syntaxRender($renderer, 'cardtitle', $data['title']);
85        }
86        if($data['subtitle'] != '') { $this->syntaxRender($renderer, 'cardsubtitle', $data['subtitle']);
87        }
88    }
89
90
91    public function render_lexer_exit(Doku_Renderer $renderer, $data)
92    {
93        if($data['no-body'] == false) { $this->syntaxRender($renderer, 'cardbody', '', null, MIKIO_LEXER_EXIT);
94        }
95
96        if($data['footer'] != '') {
97            $this->syntaxRender($renderer, 'cardfooter', $data['footer'], $this->arrayRemoveEmpties(array('small' => $data['footer-small'])));
98        }
99
100        if($data['footer-placeholder-text'] != '') {
101            $this->syntaxRender($renderer, 'placeholder', '', $this->arrayRemoveEmpties(array('text' => $data['footer-placeholder-text'], 'color' => $data['footer-placeholder-color'], 'text-color' => $data['footer-placeholder-text-color'])));
102        } elseif($data['footer-image'] != '') {
103            $renderer->doc .= '<img src="' . $data['footer-image'] . '" class="' . $this->elemClass . ' ' . $this->classPrefix . 'card-image' . ($data['footer-image-cover'] ? ' ' . $this->classPrefix . 'image-cover' : '') .'">';
104        }
105
106        if($data['horizontal']) { $renderer->doc .= '</div>';
107        }
108        $renderer->doc .= '</div>';
109    }
110}
111?>