xref: /plugin/mikioplugin/syntax/card.php (revision 062e27261056bc3be0a09046ff5c29e5d913dd66)
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();
10if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11require_once(dirname(__FILE__).'/core.php');
12
13class syntax_plugin_mikioplugin_card extends syntax_plugin_mikioplugin_core {
14    public $tag                 = 'card';
15    public $hasEndTag           = true;
16    public $options             = array(
17        'image'         => array('type'     => 'media',      'default'   => ''),
18        'image-cover' => array('type'     => 'boolean',      'default'   => 'false'),
19        'overlay'       => array('type'     => 'boolean',   'default'   => 'false'),
20        'title'         => array('type'     => 'text',      'default'   => ''),
21        'subtitle'      => array('type'     => 'text',      'default'   => ''),
22        'no-body'        => array('type'     => 'boolean',   'default'   => 'false'),
23        'header'      => array('type'     => 'text',      'default'   => ''),
24        'footer'      => array('type'     => 'text',      'default'   => ''),
25        'placeholder-text'      => array('type'     => 'text',      'default'   => ''),
26        'placeholder-color'      => array('type'     => 'text',      'default'   => ''),
27        'placeholder-text-color'      => array('type'     => 'text',      'default'   => ''),
28        'footer-image'      => array('type'     => 'media',      'default'   => ''),
29        'footer-image-cover' => array('type'     => 'boolean',      'default'   => 'false'),
30        'footer-placeholder-text'      => array('type'     => 'text',      'default'   => ''),
31        'footer-placeholder-color'      => array('type'     => 'text',      'default'   => ''),
32        'footer-placeholder-text-color'      => array('type'     => 'text',      'default'   => ''),
33        'horizontal'            => array('type'     => 'boolean',   'default'   => 'false'),
34        'footer-small'        => array('type'     => 'boolean',   'default'   => 'false'),
35    );
36
37
38    public function __construct() {
39        $this->addCommonOptions('type shadow width height text-align vertical-align text-color');
40    }
41
42    public function getAllowedTypes() { return array('formatting', 'substition', 'disabled', 'container'); }
43    public function getPType() { return 'normal'; }
44
45    public function render_lexer_enter(Doku_Renderer $renderer, $data) {
46        $classes = $this->buildClass($data, array('overlay', 'horizontal'));
47        $styles = $this->buildStyle(array('height' => $data['height'], 'width' => $data['width']), TRUE);
48
49        $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'card' . $classes . '"' . $styles . '>';
50
51        if($data['horizontal']) $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'card-horizontal-image">';
52        if($data['placeholder-text'] != '') {
53            $this->syntaxRender($renderer, 'placeholder', '', $this->arrayRemoveEmpties(array('text' => $data['placeholder-text'], 'color' => $data['placeholder-color'], 'text-color' => $data['placeholder-text-color'])));
54        } elseif($data['image'] != '') {
55            $renderer->doc .= '<img src="' . $data['image'] . '" class="' . $this->elemClass . ' ' . $this->classPrefix . 'card-image' . ($data['image-cover'] ? ' ' . $this->classPrefix . 'image-cover' : '') . '">';
56        }
57        if($data['horizontal']) $renderer->doc .= '</div><div class="' . $this->elemClass . ' ' . $this->classPrefix . 'card-horizontal-body">';
58
59        if($data['header'] != '') $this->syntaxRender($renderer, 'cardheader', $data['header']);
60
61        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);
62
63        if($data['title'] != '') $this->syntaxRender($renderer, 'cardtitle', $data['title']);
64        if($data['subtitle'] != '') $this->syntaxRender($renderer, 'cardsubtitle', $data['subtitle']);
65    }
66
67
68    public function render_lexer_exit(Doku_Renderer $renderer, $data) {
69        if($data['no-body'] == FALSE) $this->syntaxRender($renderer, 'cardbody', '', null, MIKIO_LEXER_EXIT);
70
71        if($data['footer'] != '') {
72            $this->syntaxRender($renderer, 'cardfooter', $data['footer'], $this->arrayRemoveEmpties(array('small' => $data['footer-small'])));
73        }
74
75        if($data['footer-placeholder-text'] != '') {
76            $this->syntaxRender($renderer, 'placeholder', '', $this->arrayRemoveEmpties(array('text' => $data['footer-placeholder-text'], 'color' => $data['footer-placeholder-color'], 'text-color' => $data['footer-placeholder-text-color'])));
77        } elseif($data['footer-image'] != '') {
78            $renderer->doc .= '<img src="' . $data['footer-image'] . '" class="' . $this->elemClass . ' ' . $this->classPrefix . 'card-image' . ($data['footer-image-cover'] ? ' ' . $this->classPrefix . 'image-cover' : '') .'">';
79        }
80
81        if($data['horizontal']) $renderer->doc .= '</div>';
82        $renderer->doc .= '</div>';
83    }
84}
85?>