xref: /plugin/mikioplugin/syntax/card.php (revision 51a483e83454920ad03b8a5f217b0ef22735901f)
1<?php
2/**
3 * Mikio Syntax Plugin: Card
4 *
5 * Syntax:  <CARD [image=] [image-overlay=] [footer-image=] [title=] [header=] [footer=] [subtitle=] [listgroup] [nobody] [placeholder-text=] [placeholder-colour=] [placeholder-text-colour=] [footer-placeholder-text=] [footer-placeholder-colour=] [footer-placeholder-text-colour=] [horizontal] [footer-small]></CARD>
6 *
7 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author     James Collins <james.collins@outlook.com.au>
9 */
10
11if (!defined('DOKU_INC')) die();
12if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13require_once(dirname(__FILE__).'/core.php');
14
15class syntax_plugin_mikioplugin_card extends syntax_plugin_mikioplugin_core {
16    public $tag                 = 'card';
17    public $options             = array('image', 'overlay', 'title', 'subtitle', 'listgroup', 'nobody', 'header', 'footer', 'placeholder-text', 'placeholder-colour', 'placeholder-text-colour', 'footer-image', 'footer-placeholder-text', 'footer-placeholder-colour', 'footer-placeholder-text-colour', 'horizontal', 'footer-small');
18
19
20    public function render_lexer_enter(Doku_Renderer $renderer, $data) {
21        $body = true;
22        $overlay = false;
23        $horizontal = false;
24        $classes = $this->buildClassString($data);
25
26        if(array_key_exists('overlay', $data) && $data['overlay'] != false) $overlay = true;
27        if(array_key_exists('horizontal', $data) && $data['horizontal'] != false) $horizontal = true;
28
29        $renderer->doc .= '<div class="card ' . $classes . '"' . $this->buildStyleString($data) . '>';
30
31        if($horizontal) $renderer->doc .= '<div class="row no-gutters"><div class="col-md-4">';
32
33        if((array_key_exists('placeholder-text', $data) && $data['placeholder-text'] != '') || (array_key_exists('placeholder-colour', $data) && $data['placeholder-colour'] != '') || (array_key_exists('placeholder-text-colour', $data) && $data['placeholder-text-colour'] != '')) {
34            $placeholderData = array('classes' => ($overlay ? 'card-img' : 'card-img-top'));
35            if(array_key_exists('placeholder-text', $data) && $data['placeholder-text'] != '') $placeholderData['text'] = $data['placeholder-text'];
36            if(array_key_exists('placeholder-colour', $data) && $data['placeholder-colour'] != '') $placeholderData['colour'] = $data['placeholder-colour'];
37            if(array_key_exists('placeholder-text-colour', $data) && $data['placeholder-text-colour'] != '') $placeholderData['text-colour'] = $data['placeholder-text-colour'];
38
39            $this->syntaxRender($renderer, 'syntax_plugin_mikioplugin_placeholder', '', $placeholderData);
40
41        } else {
42            if(array_key_exists('image', $data) && $data['image'] != '') $renderer->doc .= '<img src="' . $this->getMediaFile($data['image']) . '" class="card-img-top">';
43        }
44
45        if($horizontal) $renderer->doc .= '</div><div class="col-md-8">';
46
47        if((array_key_exists('listgroup', $data) && $data['listgroup'] == true) || (array_key_exists('nobody', $data) && $data['nobody'] == true)) $body = false;
48
49        if(array_key_exists('header', $data) && $data['header'] != '') $this->syntaxRender($renderer, 'syntax_plugin_mikioplugin_cardheader', $data['header']);
50
51        if($body) {
52            if($overlay) {
53                $renderer->doc .= '<div class="card-img-overlay">';
54            } else {
55                $renderer->doc .= '<div class="card-body">';
56            }
57        }
58
59        if(array_key_exists('title', $data) && $data['title'] != '') $this->syntaxRender($renderer, 'syntax_plugin_mikioplugin_cardtitle', $data['title']);
60        if(array_key_exists('subtitle', $data) && $data['subtitle'] != '') $this->syntaxRender($renderer, 'syntax_plugin_mikioplugin_cardsubtitle', $data['subtitle']);
61    }
62
63
64    public function render_lexer_exit(Doku_Renderer $renderer, $data) {
65        if((!array_key_exists('listgroup', $this->values) || $this->values['listgroup'] == false) && (!array_key_exists('nobody', $this->values) || $this->values['nobody'] == false)) {
66            $renderer->doc .= '</div>';
67        }
68
69        if(array_key_exists('horizontal', $this->values) && $this->values['horizontal'] != false) {
70            $renderer->doc .= '</div></div>';
71        }
72
73        $footerOptions = array();
74        if(array_key_exists('footer-small', $this->values) && $this->values['footer-small'] != false) $footerOptions['small'] = true;
75
76        if(array_key_exists('footer', $this->values) && $this->values['footer'] != '') {
77            $this->syntaxRender($renderer, 'syntax_plugin_mikioplugin_cardfooter', $this->values['footer'], $footerOptions);
78        }
79
80        if((array_key_exists('footer-placeholder-text', $this->values) && $this->values['footer-placeholder-text'] != '') || (array_key_exists('footer-placeholder-colour', $this->values) && $this->values['footer-placeholder-colour'] != '') || (array_key_exists('footer-placeholder-text-colour', $this->values) && $this->values['footer-placeholder-text-colour'] != '')) {
81            $placeholderData = array('classes' => 'card-img-top');
82            if(array_key_exists('footer-placeholder-text', $this->values) && $this->values['footer-placeholder-text'] != '') $placeholderData['text'] = $this->values['footer-placeholder-text'];
83            if(array_key_exists('footer-placeholder-colour', $this->values) && $this->values['footer-placeholder-colour'] != '') $placeholderData['colour'] = $this->values['footer-placeholder-colour'];
84            if(array_key_exists('footer-placeholder-text-colour', $this->values) && $this->values['footer-placeholder-text-colour'] != '') $placeholderData['text-colour'] = $this->values['footer-placeholder-text-colour'];
85
86            $this->syntaxRender($renderer, 'syntax_plugin_mikioplugin_placeholder', '', $placeholderData);
87
88        } else {
89            if(array_key_exists('footer-image', $this->values) && $this->values['footer-image'] != '') $renderer->doc .= '<img src="' . $this->getMediaFile($this->values['footer-image']) . '" class="card-img-top">';
90        }
91
92        $renderer->doc .= '</div>';
93    }
94}
95?>