1<?php 2/** 3 * Mikio Syntax Plugin: Box 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_box extends syntax_plugin_mikioplugin_core { 14 public $tag = 'box'; 15 public $requires_tag = 'grid'; 16 public $hasEndTag = true; 17 public $options = array( 18 'attr' => array('type' => 'text'), 19 'round' => array('type' => 'size', 'default' => '0'), 20 'border-color' => array('type' => 'color', 'default' => ''), 21 'border-width' => array('type' => 'multisize', 'default' => ''), 22 'reveal' => array('type' => 'boolean', 'default' => 'false'), 23 'reveal-text' => array('type' => 'text', 'default' => 'Reveal'), 24 'url' => array('type' => 'url', 'default' => ''), 25 'color' => array('type' => 'color', 'default' => ''), 26 'padding' => array('type' => 'multisize', 'default' => ''), 27 'margin' => array('type' => 'multisize', 'default' => ''), 28 'grid-row' => array('type' => 'text'), 29 'grid-row-start' => array('type' => 'number'), 30 'grid-row-end' => array('type' => 'number'), 31 'grid-row-span' => array('type' => 'number'), 32 'grid-col' => array('type' => 'text'), 33 'grid-col-start' => array('type' => 'number'), 34 'grid-col-end' => array('type' => 'number'), 35 'grid-col-span' => array('type' => 'number'), 36 ); 37 38 public function __construct() { 39 $this->addCommonOptions('width height type shadow text-align links-match vertical-align'); 40 } 41 42 public function getPType() { return 'normal'; } 43 44 public function render_lexer_enter(Doku_Renderer $renderer, $data) { 45 if($data['attr'] != '') { 46 $data = array_merge($data, $this->callMikioTag('setattr', $data['attr'])); 47 } 48 49 $tag = 'div'; 50 if($data['url'] != '') $tag = 'a'; 51 52 if($data['grid-row-span'] != '') $data['grid-row-end'] = 'span ' . $data['grid-row-span']; 53 if($data['grid-col-span'] != '') $data['grid-col-end'] = 'span ' . $data['grid-col-span']; 54 55 if($data['grid-row'] != '') { 56 $parts = explode(' ', $data['grid-row']); 57 $i = count($parts); 58 if($i == 2 || $i == 3) { 59 $data['grid-row-start'] = filter_var($parts[0], FILTER_VALIDATE_INT); 60 } 61 62 if($i == 2) { 63 $data['grid-row-end'] = filter_var($parts[1], FILTER_VALIDATE_INT); 64 } else { 65 $data['grid-row-end'] = strtolower($parts[1]) . ' ' . filter_var($parts[2], FILTER_VALIDATE_INT); 66 } 67 } 68 69 if($data['grid-col'] != '') { 70 $parts = explode(' ', $data['grid-col']); 71 $i = count($parts); 72 if($i == 2 || $i == 3) { 73 $data['grid-col-start'] = filter_var($parts[0], FILTER_VALIDATE_INT); 74 } 75 76 if($i == 2) { 77 $data['grid-col-end'] = filter_var($parts[1], FILTER_VALIDATE_INT); 78 } else { 79 $data['grid-col-end'] = strtolower($parts[1]) . ' ' . filter_var($parts[2], FILTER_VALIDATE_INT); 80 } 81 } 82 83 $classes = $this->buildClass($data); 84 $styles = $this->buildStyle(array( 85 'width' => $data['width'], 86 'height' => $data['height'], 87 'border-radius' => $data['round'], 88 'border-color' => $data['border-color'], 89 'border-width' => $data['border-width'], 90 'color' => $data['color'], 91 'padding' => $data['padding'], 92 'margin' => $data['margin'], 93 'grid-row-start' => $data['grid-row-start'], 94 'grid-row-end' => $data['grid-row-end'], 95 'grid-column-start' => $data['grid-col-start'], 96 'grid-column-end' => $data['grid-col-end'], 97 98 ), TRUE); 99 100 $renderer->doc .= '<' . $tag . ($data['url'] != '' ? ' href="' . $data['url'] . '"' : '') . ' class="' . $this->elemClass . ' ' . $this->classPrefix . 'box'. $classes .'"' . $styles. '>'; 101 if($data['reveal']) $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'reveal">' . $data['reveal-text'] . '</div>'; 102 } 103 104 105 public function render_lexer_exit(Doku_Renderer $renderer, $data) { 106 $tag = 'div'; 107 if($data['url'] != '') $tag = 'a'; 108 109 $renderer->doc .= '</' . $tag . '>'; 110 } 111} 112?>