1<?php 2/** 3 * Jira-links syntax plugin for DokuWiki 4 * 5 * @author christian studer <christian.studer@meteotest.ch> 6 * @license GPL2 http://www.gnu.org/licenses/gpl-2.0.html 7 */ 8 9// Must be run within DokuWiki 10if (!defined('DOKU_INC')) die(); 11if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 12 13require_once DOKU_PLUGIN.'syntax.php'; 14 15/** 16 * The Jira-links syntax plugin itself 17 * 18 * @author christian studer <christian.studer@meteotest.ch> 19 */ 20class syntax_plugin_jiralinks extends DokuWiki_Syntax_Plugin { 21 /** 22 * Gets plugin type 23 * 24 * @return string 25 */ 26 public function getType() { 27 return 'substition'; 28 } 29 30 /** 31 * Gets plugin sort order 32 * 33 * @return number 34 */ 35 public function getSort() { 36 return 331; // Belongs to externallink somehow 37 } 38 39 40 /** 41 * Plugin mode connection 42 * 43 * @param string $mode 44 */ 45 public function connectTo($mode) { 46 // Detect all KEYS-123 47 $this->Lexer->addSpecialPattern('[A-Z]+?-[0-9]+', $mode, 'plugin_jiralinks'); 48 } 49 50 /** 51 * Match handling 52 * 53 * @param string $match 54 * @param string $state 55 * @param int $pos 56 * @param Doku_Handler $handler 57 * @return array 58 */ 59 public function handle($match, $state, $pos, &$handler){ 60 // Return all matches 61 return array($match); 62 } 63 64 /** 65 * Render the output 66 * 67 * @param string $mode 68 * @param Doku_Renderer $renderer 69 * @param array $data 70 * @return boolean 71 */ 72 public function render($mode, &$renderer, $data) { 73 // Only render to xhtml 74 if($mode != 'xhtml') return false; 75 76 // Append the link to the issue 77 $url = $this->getConf('jiraserver') . $data[0]; 78 $renderer->doc .= $renderer->external_link($url, $data[0], 'jiralink'); 79 80 return true; 81 } 82} 83