1<?php 2/** 3 * DokuWiki Plugin dw2pdf (Syntax Component) 4 * 5 * For marking changes in page orientation. 6 * 7 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 8 * @author Sam Wilson <sam@samwilson.id.au> 9 */ 10 11use dokuwiki\File\PageResolver; 12 13/** 14 * Syntax for page specific directions for mpdf library 15 */ 16class syntax_plugin_dw2pdf_exportlink extends DokuWiki_Syntax_Plugin 17{ 18 19 /** 20 * Syntax Type 21 * 22 * Needs to return one of the mode types defined in $PARSER_MODES in parser.php 23 * 24 * @return string 25 */ 26 public function getType() 27 { 28 return 'substition'; 29 } 30 31 /** 32 * Sort for applying this mode 33 * 34 * @return int 35 */ 36 public function getSort() 37 { 38 return 41; 39 } 40 41 /** 42 * @param string $mode 43 */ 44 public function connectTo($mode) 45 { 46 $this->Lexer->addSpecialPattern('~~PDFNS>(?:.*?)\|(?:.*?)~~', $mode, 'plugin_dw2pdf_exportlink'); 47 } 48 49 /** 50 * Handler to prepare matched data for the rendering process 51 * 52 * @param string $match The text matched by the patterns 53 * @param int $state The lexer state for the match 54 * @param int $pos The character position of the matched text 55 * @param Doku_Handler $handler The Doku_Handler object 56 * @return array Return an array with all data you want to use in render, false don't add an instruction 57 */ 58 public function handle($match, $state, $pos, Doku_Handler $handler) 59 { 60 global $ID; 61 $ns = substr($match, 8, strpos($match, '|') - 8); 62 $id = $ns . ':start'; 63 $resolver = new PageResolver($ID); 64 $page = $resolver->resolveId($id); 65 $ns = getNS($page); 66 $title = substr($match, strpos($match, '|') + 1, -2); 67 $link = '?do=export_pdfns&book_ns=' . $ns . '&book_title=' . $title; 68 69 // check if there is an ampersand in the title 70 $amp = strpos($title, '&'); 71 if ($amp !== false) { 72 $title = substr($title, 0, $amp); 73 } 74 75 return [ 76 'link' => $link, 77 'title' => sprintf($this->getLang('export_ns'), $ns, $title), 78 $state, 79 $pos 80 ]; 81 } 82 83 /** 84 * Handles the actual output creation. 85 * 86 * @param string $format output format being rendered 87 * @param Doku_Renderer $renderer the current renderer object 88 * @param array $data data created by handler() 89 * @return boolean rendered correctly? (however, returned value is not used at the moment) 90 */ 91 public function render($format, Doku_Renderer $renderer, $data) 92 { 93 if ($format == 'xhtml' && !is_a($renderer, 'renderer_plugin_dw2pdf')) { 94 $renderer->internallink($data['link'], $data['title']); 95 return true; 96 } 97 return false; 98 } 99 100} 101