xref: /plugin/mikioplugin/syntax/card.php (revision 0db6985a925e7f92a0a67ebdb711db77592a5e10)
1<?php
2/**
3 * Mikio Syntax Plugin: Card
4 *
5 * Syntax:  <CARD [width=] [height=] [image=] [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=]></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('width', 'height', 'image', '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');
18
19
20    public function render_lexer_enter(Doku_Renderer $renderer, $data) {
21        $styles = [];
22        $body = true;
23        $classes = $this->buildClassString($data);
24
25        $this->setAttr($styles, 'width', $data);
26        $this->setAttr($styles, 'height', $data);
27
28        $renderer->doc .= '<div class="card ' . $classes . '"' . $this->listAttr('style', $styles) . '>';
29        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'] != '')) {
30            $placeholderData = array('classes' => 'card-img-top');
31            if(array_key_exists('placeholder-text', $data) && $data['placeholder-text'] != '') $placeholderData['text'] = $data['placeholder-text'];
32            if(array_key_exists('placeholder-colour', $data) && $data['placeholder-colour'] != '') $placeholderData['colour'] = $data['placeholder-colour'];
33            if(array_key_exists('placeholder-text-colour', $data) && $data['placeholder-text-colour'] != '') $placeholderData['text-colour'] = $data['placeholder-text-colour'];
34
35            $this->syntaxRender($renderer, 'syntax_plugin_mikioplugin_placeholder', '', $placeholderData);
36
37        } else {
38            if(array_key_exists('image', $data) && $data['image'] != '') $renderer->doc .= '<img src="' . $this->getMediaFile($data['image']) . '" class="card-img-top">';
39        }
40
41        if((array_key_exists('listgroup', $data) && $data['listgroup'] == true) || (array_key_exists('nobody', $data) && $data['nobody'] == true)) $body = false;
42
43        if(array_key_exists('header', $data) && $data['header'] != '') $this->syntaxRender($renderer, 'syntax_plugin_mikioplugin_cardheader', $data['header']);
44
45        if($body) {
46            $renderer->doc .= '<div class="card-body">';
47        }
48
49        if(array_key_exists('title', $data) && $data['title'] != '') $this->syntaxRender($renderer, 'syntax_plugin_mikioplugin_cardtitle', $data['title']);
50        if(array_key_exists('subtitle', $data) && $data['subtitle'] != '') $this->syntaxRender($renderer, 'syntax_plugin_mikioplugin_cardsubtitle', $data['subtitle']);
51    }
52
53
54    public function render_lexer_exit(Doku_Renderer $renderer, $data) {
55        if((!array_key_exists('listgroup', $this->values) || $this->values['listgroup'] == false) && (!array_key_exists('nobody', $this->values) || $this->values['nobody'] == false)) {
56            $renderer->doc .= '</div>';
57        }
58
59        if(array_key_exists('footer', $this->values) && $this->values['footer'] != '') $this->syntaxRender($renderer, 'syntax_plugin_mikioplugin_cardfooter', $this->values['footer']);
60
61        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'] != '')) {
62            $placeholderData = array('classes' => 'card-img-top');
63            if(array_key_exists('footer-placeholder-text', $this->values) && $this->values['footer-placeholder-text'] != '') $placeholderData['text'] = $this->values['footer-placeholder-text'];
64            if(array_key_exists('footer-placeholder-colour', $this->values) && $this->values['footer-placeholder-colour'] != '') $placeholderData['colour'] = $this->values['footer-placeholder-colour'];
65            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'];
66
67            $this->syntaxRender($renderer, 'syntax_plugin_mikioplugin_placeholder', '', $placeholderData);
68
69        } else {
70            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">';
71        }
72
73        $renderer->doc .= '</div>';
74    }
75}
76?>