1<?php 2/** 3 * Bootstrap Wrapper Plugin: Progress Bar 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author HavocKKS 7 * @author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com> 8 * @copyright (C) 2015-2020, Giuseppe Di Terlizzi 9 */ 10 11class syntax_plugin_bootswrapper_progressbar extends syntax_plugin_bootswrapper_bootstrap 12{ 13 14 public $p_type = 'block'; 15 public $pattern_start = '<(?:bar).*?>(?=.*?</(?:bar)>)'; 16 public $pattern_end = '</(?:bar)>'; 17 public $tag_name = 'bar'; 18 public $tag_attributes = array( 19 20 'type' => array( 21 'type' => 'string', 22 'values' => array('success', 'info', 'warning', 'danger'), 23 'required' => false, 24 'default' => 'info'), 25 26 'value' => array( 27 'type' => 'integer', 28 'min' => 0, 29 'max' => 100, 30 'values' => null, 31 'required' => true, 32 'default' => 0), 33 34 'striped' => array( 35 'type' => 'boolean', 36 'values' => array(0, 1), 37 'required' => false, 38 'default' => false), 39 40 'showvalue' => array( 41 'type' => 'boolean', 42 'values' => array(0, 1), 43 'required' => false, 44 'default' => false), 45 46 'animate' => array( 47 'type' => 'boolean', 48 'values' => array(0, 1), 49 'required' => false, 50 'default' => false), 51 ); 52 53 public function render($mode, Doku_Renderer $renderer, $data) 54 { 55 56 if (empty($data)) { 57 return false; 58 } 59 60 if ($mode !== 'xhtml') { 61 return false; 62 } 63 64 /** @var Doku_Renderer_xhtml $renderer */ 65 list($state, $match, $pos, $attributes) = $data; 66 67 if ($state == DOKU_LEXER_ENTER) { 68 $classes = ""; 69 $striped = (isset($attributes['striped']) ? $attributes['striped'] : $this->tag_attributes['striped']['default']); 70 $animate = (isset($attributes['animate']) ? $attributes['animate'] : $this->tag_attributes['animate']['default']); 71 $showvalue = (isset($attributes['showvalue']) ? $attributes['showvalue'] : $this->tag_attributes['showvalue']['default']); 72 $value = (isset($attributes['value']) ? $attributes['value'] : $this->tag_attributes['value']['default']); 73 $type = (isset($attributes['type']) ? $attributes['type'] : $this->tag_attributes['type']['default']); 74 75 if ($striped) { 76 $classes = "progress-bar-striped"; 77 } 78 79 if ($animate) { 80 $classes .= " active"; 81 } 82 83 $markup = '<div class="bs-wrap bs-wrap-progress-bar progress-bar progress-bar-' . $type . ' ' . $classes . '" role="progressbar" aria-valuenow="' . $value . '" aria-valuemin="0" aria-valuemax="100" style="width:' . $value . '%;' . ($showvalue ? 'min-width: 2em;' : '') . '">'; 84 85 if ($showvalue) { 86 $markup .= "$value%"; 87 } else { 88 $markup .= '<span class="sr-only">' . $value . '%</span> '; 89 } 90 91 $renderer->doc .= $markup; 92 93 return true; 94 } 95 96 if ($state == DOKU_LEXER_EXIT) { 97 $renderer->doc .= '</div>'; 98 return true; 99 } 100 101 return true; 102 } 103} 104