1<?php 2 3/** 4 * Linkback Plugin 5 * 6 * Enables/disables linkback features. 7 * 8 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 9 * @author Gina Haeussge <osd@foosel.net> 10 */ 11 12class syntax_plugin_linkback extends DokuWiki_Syntax_Plugin { 13 14 function getType() { 15 return 'substition'; 16 } 17 function getPType() { 18 return 'block'; 19 } 20 function getSort() { 21 return 333; 22 } 23 24 /** 25 * Connect pattern to lexer 26 */ 27 function connectTo($mode) { 28 if ($mode == 'base') { 29 $this->Lexer->addSpecialPattern('~~LINKBACK(?:|:off|:closed)~~', $mode, 'plugin_linkback'); 30 } 31 } 32 33 /** 34 * Handle the match 35 * 36 * @param string $match The text matched by the patterns 37 * @param int $state The lexer state for the match 38 * @param int $pos The character position of the matched text 39 * @param Doku_Handler $handler The Doku_Handler object 40 * @return bool|array Return an array with all data you want to use in render, false don't add an instruction 41 */ 42 function handle($match, $state, $pos, Doku_Handler $handler) { 43 global $ID; 44 45 // don't show linkback section on blog mainpages 46 if (defined('IS_BLOG_MAINPAGE')) 47 return false; 48 49 // don't allow usage of syntax in comments 50 if (isset($_REQUEST['comment'])) 51 return false; 52 53 // get linkback meta file name 54 $file = metaFN($ID, '.linkbacks'); 55 56 $data = array ( 57 'send' => false, 58 'receive' => false, 59 'display' => false, 60 'sentpings' => array (), 61 'receivedpings' => array (), 62 'number' => 0, 63 64 ); 65 if (@ file_exists($file)) 66 $data = unserialize(io_readFile($file, false)); 67 if ($match == '~~LINKBACK~~') { 68 $data['receive'] = true; 69 $data['display'] = true; 70 } else { 71 $data['receive'] = false; 72 if ($match == '~~LINKBACK:off~~') { 73 $data['display'] = false; 74 } else { 75 $data['display'] = true; 76 } 77 } 78 io_saveFile($file, serialize($data)); 79 return []; 80 } 81 82 /** 83 * @param string $format 84 * @param Doku_Renderer $renderer 85 * @param string $data 86 * @return bool 87 */ 88 function render($format, Doku_Renderer $renderer, $data) { 89 // do nothing, everything is handled in the action components 90 return true; 91 } 92 93} 94