1<?php 2/** 3 * Mikio Syntax Plugin: Badge 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_badge extends syntax_plugin_mikioplugin_core { 14 public $tag = 'badge'; 15 public $hasEndTag = true; 16 public $options = array( 17 'pill' => array('type' => 'boolean', 'default' => 'false', 'prefix' => 'badge-'), 18 'url' => array('type' => 'url', 'default' => ''), 19 'target' => array('type' => 'text', 'default' => ''), 20 'newtab' => array('type' => 'set', 'option' => 'target', 'data' => '_blank'), 21 'collapse-id' => array('type' => 'text', 'default' => ''), 22 ); 23 24 public function __construct() { 25 $this->addCommonOptions('type shadow width text-align'); 26 $this->options['type']['default'] = 'primary'; 27 } 28 29 public function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); } 30 public function getPType() { return 'normal'; } 31 32 public function render_lexer_enter(Doku_Renderer $renderer, $data) { 33 $classes = $this->buildClass($data, array('type', 'pill')); 34 $styles = $this->buildStyle(array('width' => $data['width']), TRUE); 35 36 $tag = 'span'; 37 $href = ''; 38 if($data['url'] != '') { 39 $tag = 'a'; 40 $href = ' href="' . $data['url'] . '"' . ($data['target'] != '' ? ' target="'.$data['target'].'"' : ''); 41 } 42 43 $renderer->doc .= '<' . $tag . $href . ' class="' . $this->elemClass . ' ' . $this->classPrefix . 'badge' . $classes . '"' . $styles . '>'; 44 } 45 46 47 public function render_lexer_exit(Doku_Renderer $renderer, $data) { 48 if($data['url'] == '') { 49 $renderer->doc .= '</span>'; 50 } else { 51 $renderer->doc .= '</a>'; 52 } 53 } 54} 55?>