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