xref: /plugin/mikioplugin/syntax/card.php (revision 97cb33c149b5657262567f65c977f44d03dff5da)
1<?php
2/**
3 * Mikio Syntax Plugin: Card
4 *
5 * Syntax:  <CARD [width=] [height=] [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('width', 'height', '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        $styles = [];
22        $body = true;
23        $overlay = false;
24        $horizontal = false;
25        $classes = $this->buildClassString($data);
26
27        $this->setAttr($styles, 'width', $data);
28        $this->setAttr($styles, 'height', $data);
29
30        if(array_key_exists('overlay', $data) && $data['overlay'] != false) $overlay = true;
31        if(array_key_exists('horizontal', $data) && $data['horizontal'] != false) $horizontal = true;
32
33        $renderer->doc .= '<div class="card ' . $classes . '"' . $this->listAttr('style', $styles) . '>';
34
35        if($horizontal) $renderer->doc .= '<div class="row no-gutters"><div class="col-md-4">';
36
37        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'] != '')) {
38            $placeholderData = array('classes' => ($overlay ? 'card-img' : 'card-img-top'));
39            if(array_key_exists('placeholder-text', $data) && $data['placeholder-text'] != '') $placeholderData['text'] = $data['placeholder-text'];
40            if(array_key_exists('placeholder-colour', $data) && $data['placeholder-colour'] != '') $placeholderData['colour'] = $data['placeholder-colour'];
41            if(array_key_exists('placeholder-text-colour', $data) && $data['placeholder-text-colour'] != '') $placeholderData['text-colour'] = $data['placeholder-text-colour'];
42
43            $this->syntaxRender($renderer, 'syntax_plugin_mikioplugin_placeholder', '', $placeholderData);
44
45        } else {
46            if(array_key_exists('image', $data) && $data['image'] != '') $renderer->doc .= '<img src="' . $this->getMediaFile($data['image']) . '" class="card-img-top">';
47        }
48
49        if($horizontal) $renderer->doc .= '</div><div class="col-md-8">';
50
51        if((array_key_exists('listgroup', $data) && $data['listgroup'] == true) || (array_key_exists('nobody', $data) && $data['nobody'] == true)) $body = false;
52
53        if(array_key_exists('header', $data) && $data['header'] != '') $this->syntaxRender($renderer, 'syntax_plugin_mikioplugin_cardheader', $data['header']);
54
55        if($body) {
56            if($overlay) {
57                $renderer->doc .= '<div class="card-img-overlay">';
58            } else {
59                $renderer->doc .= '<div class="card-body">';
60            }
61        }
62
63        if(array_key_exists('title', $data) && $data['title'] != '') $this->syntaxRender($renderer, 'syntax_plugin_mikioplugin_cardtitle', $data['title']);
64        if(array_key_exists('subtitle', $data) && $data['subtitle'] != '') $this->syntaxRender($renderer, 'syntax_plugin_mikioplugin_cardsubtitle', $data['subtitle']);
65    }
66
67
68    public function render_lexer_exit(Doku_Renderer $renderer, $data) {
69        if((!array_key_exists('listgroup', $this->values) || $this->values['listgroup'] == false) && (!array_key_exists('nobody', $this->values) || $this->values['nobody'] == false)) {
70            $renderer->doc .= '</div>';
71        }
72
73        if(array_key_exists('horizontal', $this->values) && $this->values['horizontal'] != false) {
74            $renderer->doc .= '</div></div>';
75        }
76
77        $footerOptions = array();
78        if(array_key_exists('footer-small', $this->values) && $this->values['footer-small'] != false) $footerOptions['small'] = true;
79
80        if(array_key_exists('footer', $this->values) && $this->values['footer'] != '') {
81            $this->syntaxRender($renderer, 'syntax_plugin_mikioplugin_cardfooter', $this->values['footer'], $footerOptions);
82        }
83
84        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'] != '')) {
85            $placeholderData = array('classes' => 'card-img-top');
86            if(array_key_exists('footer-placeholder-text', $this->values) && $this->values['footer-placeholder-text'] != '') $placeholderData['text'] = $this->values['footer-placeholder-text'];
87            if(array_key_exists('footer-placeholder-colour', $this->values) && $this->values['footer-placeholder-colour'] != '') $placeholderData['colour'] = $this->values['footer-placeholder-colour'];
88            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'];
89
90            $this->syntaxRender($renderer, 'syntax_plugin_mikioplugin_placeholder', '', $placeholderData);
91
92        } else {
93            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">';
94        }
95
96        $renderer->doc .= '</div>';
97    }
98}
99?>