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' => '2026-06-16', 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) ? hsc(trim($matches[1])) : ' '; 94 95 preg_match('/^Priority:(.*?)$/isxm', $match, $matches); 96 $priority =(!empty($matches[1]) && strlen(trim($matches[1]))>0) ? 'Priority: '.hsc(trim($matches[1])) : ' '; 97 $priority = hsc($priority); 98 99 preg_match('/^Estimate:(.*?)$/isxm', $match, $matches); 100 $estimate = (!empty($matches[1]) && strlen(trim($matches[1]))>0) ? ' of '.hsc(trim($matches[1])) : ' '; 101 $estimate = hsc($estimate); 102 103 preg_match('/^Assigned:(.*?)$/isxm', $match, $matches); 104 $assigned = (!empty($matches[1]) && strlen(trim($matches[1]))>0) ? '('.hsc(trim($matches[1])).')' : ' '; 105 $assigned = hsc($assigned); 106 107 preg_match('/^Progress:(.*?)$/isxm', $match, $matches); 108 $progress = (!empty($matches[1]) && strlen(trim($matches[1]))>0) ? intval(preg_replace('[^0-9]', '', $matches[1])) : '0'; 109 110 preg_match('/Description:(.*)/isx', $match, $matches); 111 $description = (!empty($matches[1]) && strlen(trim($matches[1]))>0) ? hsc(trim($matches[1])) : ' '; 112 113 if ($progress<0) { 114 $progress=0; 115 } 116 if ($progress>100) { 117 $progress=100; 118 } 119 $sizeLeft = 100-$progress; 120 121 $path = rtrim(dirname($_SERVER['PHP_SELF']), "/"); 122 $blankImagePath = preg_replace('/doku\.php$/', '', $path) . 'lib/images/blank.gif'; 123 124 $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>'; 125 126 $resultStr .= '<tr class="row0"><th><b>'.$title.'</b><span style="float:right;font-weight:normal;">'.$assigned.'</span></th></tr>'; 127 $resultStr .= '<tr><td>'.nl2br($description).'</td></tr>'; 128 $resultStr .= '<tr><td><span style="float:right;font-size:0.9em;">('.$progress.'%'.$estimate.') '.$progbar.'</span>'.$priority.'</td></tr>'; 129 130 131 $resultStr .= '</table>'; 132 133 $match = $resultStr; 134 return array($state, $match); 135 136 137 case DOKU_LEXER_EXIT: 138 return array($state, ''); 139 case DOKU_LEXER_SPECIAL: 140 break; 141 } 142 return array(); 143 } 144 145 146 /** 147 * Create output 148 */ 149 public function render($mode, Doku_Renderer $renderer, $data) 150 { 151 if ($mode == 'xhtml') { 152 list($state, $match) = $data; 153 154 switch ($state) { 155 case DOKU_LEXER_ENTER: 156 $renderer->doc .= "<span class='avtaskbox'>"; 157 break; 158 159 case DOKU_LEXER_MATCHED: 160 break; 161 162 case DOKU_LEXER_UNMATCHED: 163 164 $renderer->doc .= $match; break; 165 166 case DOKU_LEXER_EXIT: 167 $renderer->doc .= "</span>"; 168 break; 169 170 case DOKU_LEXER_SPECIAL: 171 break; 172 } 173 return true; 174 } 175 return false; 176 } 177} 178