1<?php 2/** 3 * DokuWiki Plugin stellarium (Syntax Component) 4 * 5 * Replaces <stellarium>TARGET</stellarium> with a link to open Stellarium and focus on TARGET 6 * 7 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 8 * @author Marc Bulling 9 */ 10class syntax_plugin_stellarium extends \dokuwiki\Extension\SyntaxPlugin { 11 /** @inheritDoc */ 12 public function getType() { 13 return 'substition'; 14 } 15 16 /** @inheritDoc */ 17 public function getPType() { 18 return 'normal'; 19 } 20 21 /** @inheritDoc */ 22 public function getSort() { 23 return 500; 24 } 25 26 /** @inheritDoc */ 27 public function connectTo($mode) { 28 $this 29 ->Lexer 30 ->addSpecialPattern('<stellarium>.*?</stellarium>', $mode, 'plugin_stellarium'); 31 } 32 33 /** @inheritDoc */ 34 public function handle($match, $state, $pos, Doku_Handler $handler) { 35 $content = substr($match, 12, -13); // Remove <stellarium> and </stellarium> tags 36 return array( 37 $content 38 ); 39 } 40 41 /** @inheritDoc */ 42 public function render($mode, Doku_Renderer $renderer, $data) { 43 if ($mode !== 'xhtml') { 44 return false; 45 } 46 $content = $data[0]; 47 $buttonId = 'stellarium-button-' . mt_rand(); // Unique button ID 48 $renderer->doc .= "<a href='javascript:void(0)' id='{$buttonId}' data-content='{$content}' onclick=\"sendStellariumRequest('" . $buttonId . "','" . $this->getConf("server") . "','" . $this->getConf("password") . "')\">Open in Stellarium</a>"; 49 return true; 50 } 51} 52 53 54