1<?php 2/** 3 * Bootstrap Wrapper Plugin: Panel 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com> 7 * @copyright (C) 2015-2020, Giuseppe Di Terlizzi 8 */ 9 10class syntax_plugin_bootswrapper_panel extends syntax_plugin_bootswrapper_bootstrap 11{ 12 13 public $pattern_start = '<panel.*?>(?=.*?</panel>)'; 14 public $pattern_end = '</panel>'; 15 public $tag_name = 'panel'; 16 public $tag_attributes = array( 17 18 'type' => array( 19 'type' => 'string', 20 'values' => array('default', 'primary', 'success', 'info', 'warning', 'danger'), 21 'required' => true, 22 'default' => 'default'), 23 24 'title' => array( 25 'type' => 'string', 26 'values' => null, 27 'required' => false, 28 'default' => null), 29 30 'footer' => array( 31 'type' => 'string', 32 'values' => null, 33 'required' => false, 34 'default' => null), 35 36 'subtitle' => array( 37 'type' => 'string', 38 'values' => null, 39 'required' => false, 40 'default' => null), 41 42 'icon' => array( 43 'type' => 'string', 44 'values' => null, 45 'required' => false, 46 'default' => null), 47 48 'no-body' => array( 49 'type' => 'boolean', 50 'values' => array(0, 1), 51 'required' => false, 52 'default' => false), 53 54 ); 55 56 public function render($mode, Doku_Renderer $renderer, $data) 57 { 58 59 if (empty($data)) { 60 return false; 61 } 62 63 if ($mode !== 'xhtml') { 64 return false; 65 } 66 67 /** @var Doku_Renderer_xhtml $renderer */ 68 list($state, $match, $pos, $attributes) = $data; 69 70 global $nobody, $footer; 71 72 if ($state == DOKU_LEXER_ENTER) { 73 $type = $attributes['type']; 74 $title = (isset($attributes['title']) ? $attributes['title'] : false); 75 $footer = (isset($attributes['footer']) ? $attributes['footer'] : false); 76 $subtitle = (isset($attributes['subtitle']) ? $attributes['subtitle'] : false); 77 $icon = (isset($attributes['icon']) ? $attributes['icon'] : false); 78 $nobody = (isset($attributes['no-body']) ? $attributes['no-body'] : false); 79 80 $markup = '<div class="bs-wrap bs-wrap-panel panel panel-' . $type . '">'; 81 82 if ($title || $subtitle) { 83 84 if ($icon) { 85 $title = '<i class="' . $icon . '"></i> ' . $title; 86 } 87 88 $markup .= '<div class="panel-heading"><h4 class="panel-title">' . $title . '</h4>' . $subtitle . '</div>'; 89 90 } 91 92 if (!$nobody) { 93 $markup .= '<div class="panel-body">'; 94 } 95 96 if (defined('SEC_EDIT_PATTERN')) { // for DokuWiki Greebo and more recent versions 97 $renderer->startSectionEdit($pos, array('target' => 'plugin_bootswrapper_panel', 'name' => $state)); 98 } else { 99 $renderer->startSectionEdit($pos, 'plugin_bootswrapper_panel', $state); 100 } 101 102 $renderer->doc .= $markup; 103 104 return true; 105 } 106 107 if ($state == DOKU_LEXER_EXIT) { 108 $markup = ''; 109 110 if (!$nobody) { 111 $markup = '</div>'; 112 } 113 114 if ($footer) { 115 $markup .= '<div class="panel-footer">' . $footer . '</div>'; 116 } 117 118 $markup .= '</div>'; 119 $renderer->doc .= $markup; 120 121 $renderer->finishSectionEdit($pos + strlen($match)); 122 123 return true; 124 } 125 126 return true; 127 } 128} 129