1<?php 2 3/** 4 * DokuWiki task box plugin 5 * @license GPL-2.0 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html) 6 * @author Sherri W. (http://syntaxseed.com) 7 * 8 * Usage: 9 * 10 * <task> 11 * TITLE: A test task 12 * PRIORITY: High 13 * ESTIMATE: 4h 14 * PROGRESS: 10% 15 * ASSIGNED: Sherri 16 * DESCRIPTION: Some stuff for you. You can have newlines in this part. Description must be the last item. 17 * </task> 18 */ 19 20if (!defined('DOKU_INC')) { 21 define('DOKU_INC', realpath(dirname(__FILE__).'/../../').'/'); 22} 23if (!defined('DOKU_PLUGIN')) { 24 define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/'); 25} 26require_once(DOKU_PLUGIN.'syntax.php'); 27 28class syntax_plugin_avtaskbox extends DokuWiki_Syntax_Plugin 29{ 30 31 /** 32 * return some info 33 */ 34 public function getInfo() 35 { 36 return array( 37 'author' => 'Sherri Wheeler', 38 'email' => 'Use my website: http://syntaxseed.com', 39 'date' => '2022-08-08', 40 'name' => 'AV Task Box', 41 'desc' => 'Creates task/user story table boxes.', 42 'url' => 'https://www.dokuwiki.org/plugin:avtaskbox', 43 ); 44 } 45 46 /** 47 * What kind of syntax are we? 48 */ 49 public function getType() 50 { 51 return 'substition'; 52 } 53 54 /** 55 * Where to sort in? 56 */ 57 public function getSort() 58 { 59 return 999; 60 } 61 62 63 /** 64 * Connect pattern to lexer 65 */ 66 public function connectTo($mode) 67 { 68 $this->Lexer->addEntryPattern('\<task\>', $mode, 'plugin_avtaskbox'); 69 } 70 71 public function postConnect() 72 { 73 $this->Lexer->addExitPattern('\</task\>', 'plugin_avtaskbox'); 74 } 75 76 77 /** 78 * Handle the match 79 */ 80 public function handle($match, $state, $pos, Doku_Handler $handler) 81 { 82 switch ($state) { 83 case DOKU_LEXER_ENTER: 84 return array($state, ''); 85 case DOKU_LEXER_MATCHED: 86 break; 87 case DOKU_LEXER_UNMATCHED: 88 89 $resultStr = '<table class="inline" width="500">'; 90 $progbar = ''; 91 92 preg_match('/^Title:(.*?)$/isxm', $match, $matches); 93 $title = (!empty($matches[1]) && strlen(trim($matches[1]))>0) ? trim($matches[1]) : ' '; 94 95 preg_match('/^Priority:(.*?)$/isxm', $match, $matches); 96 $priority =(!empty($matches[1]) && strlen(trim($matches[1]))>0) ? 'Priority: '.trim($matches[1]) : ' '; 97 98 preg_match('/^Estimate:(.*?)$/isxm', $match, $matches); 99 $estimate = (!empty($matches[1]) && strlen(trim($matches[1]))>0) ? ' of '.trim($matches[1]) : ' '; 100 101 preg_match('/^Assigned:(.*?)$/isxm', $match, $matches); 102 $assigned = (!empty($matches[1]) && strlen(trim($matches[1]))>0) ? '('.trim($matches[1]).')' : ' '; 103 104 preg_match('/^Progress:(.*?)$/isxm', $match, $matches); 105 $progress = (!empty($matches[1]) && strlen(trim($matches[1]))>0) ? intval(preg_replace('[^0-9]', '', $matches[1])) : '0'; 106 107 preg_match('/Description:(.*)/isx', $match, $matches); 108 $description = (!empty($matches[1]) && strlen(trim($matches[1]))>0) ? trim($matches[1]) : ' '; 109 110 if ($progress<0) { 111 $progress=0; 112 } 113 if ($progress>100) { 114 $progress=100; 115 } 116 $sizeLeft = 100-$progress; 117 118 $path = rtrim(dirname($_SERVER['PHP_SELF']), "/"); 119 $blankImagePath = preg_replace('/doku\.php$/', '', $path) . 'lib/images/blank.gif'; 120 121 $progbar .= '<span style="margin-top:3px;padding:0;height:8px;width: 100px;">' . ($progress <= 0 ? '' : '<span style="margin:0;padding:0;background-color:#74a6c9; height:8px; width:' . $progress . '"><img src="' . $blankImagePath . '" height="8" width="' . $progress . '" border="0" title="' . $progress . '%" alt="' . $progress . '%" hspace="0" vspace="0" style="height:8px;" /></span>') . ($progress >= 100 ? '' : '<span style="margin:0;padding:0;background-color: #dee7ec;height:8px;width:' . $sizeLeft . '"><img src="' . $blankImagePath . '" height="8" width="' . $sizeLeft . '" border="0" title="' . $progress . '%" alt="' . $progress . '%" hspace="0" vspace="0" style="height:8px;" /></span>') . '</span>'; 122 123 $resultStr .= '<tr class="row0"><th><b>'.$title.'</b><span style="float:right;font-weight:normal;">'.$assigned.'</span></th></tr>'; 124 $resultStr .= '<tr><td>'.nl2br($description).'</td></tr>'; 125 $resultStr .= '<tr><td><span style="float:right;font-size:0.9em;">('.$progress.'%'.$estimate.') '.$progbar.'</span>'.$priority.'</td></tr>'; 126 127 128 $resultStr .= '</table>'; 129 130 $match = $resultStr; 131 return array($state, $match); 132 133 134 case DOKU_LEXER_EXIT: 135 return array($state, ''); 136 case DOKU_LEXER_SPECIAL: 137 break; 138 } 139 return array(); 140 } 141 142 143 /** 144 * Create output 145 */ 146 public function render($mode, Doku_Renderer $renderer, $data) 147 { 148 if ($mode == 'xhtml') { 149 list($state, $match) = $data; 150 151 switch ($state) { 152 case DOKU_LEXER_ENTER: 153 $renderer->doc .= "<span class='avtaskbox'>"; 154 break; 155 156 case DOKU_LEXER_MATCHED: 157 break; 158 159 case DOKU_LEXER_UNMATCHED: 160 161 $renderer->doc .= $match; break; 162 163 case DOKU_LEXER_EXIT: 164 $renderer->doc .= "</span>"; 165 break; 166 167 case DOKU_LEXER_SPECIAL: 168 break; 169 } 170 return true; 171 } 172 return false; 173 } 174} 175