1<?php 2/** 3 * Syntax Plugin Backlinks 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Michael Klier <chi@chimeric.de> 7 */ 8 9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 11if(!defined('DW_LF')) define('DW_LF',"\n"); 12 13require_once(DOKU_PLUGIN.'syntax.php'); 14 15/** 16 * All DokuWiki plugins to extend the parser/rendering mechanism 17 * need to inherit from this class 18 */ 19class syntax_plugin_backlinks extends DokuWiki_Syntax_Plugin { 20 21 22 /** 23 * General Info 24 */ 25 function getInfo(){ 26 return array( 27 'author' => 'Michael Klier', 28 'email' => 'chi@chimeric.de', 29 'date' => '2006-10-12', 30 'name' => 'Backlinks', 31 'desc' => 'Displays backlinks to a given page.', 32 'url' => 'http://www.chimeric.de/dokuwiki/plugins/backlinks' 33 ); 34 } 35 36 /** 37 * Syntax Type 38 * 39 * Needs to return one of the mode types defined in $PARSER_MODES in parser.php 40 */ 41 function getType() { return 'substition'; } 42 function getPType() { return 'block'; } 43 function getSort() { return 304; } 44 45 /** 46 * Connect pattern to lexer 47 */ 48 function connectTo($mode) { 49 $this->Lexer->addSpecialPattern('\{\{backlinks>.+?\}\}',$mode,'plugin_backlinks'); 50 } 51 52 /** 53 * Handler to prepare matched data for the rendering process 54 */ 55 function handle($match, $state, $pos, &$handler){ 56 global $ID; 57 58 @require_once(DOKU_INC.'inc/fulltext.php'); 59 60 $id = substr($match,12,-2); //strip {{backlinks> from start and }} from end 61 62 if($id == '.') $id = $ID; 63 64 resolve_pageid(getNS($ID),$id,$exits); 65 66 $backlinks = ft_backlinks($id); 67 68 return ($backlinks); 69 } 70 71 /** 72 * Handles the actual output creation. 73 */ 74 function render($mode, &$renderer, $backlinks) { 75 76 if($mode == 'xhtml'){ 77 $renderer->info['cache'] = false; 78 79 if(!empty($backlinks)) { 80 81 $renderer->doc .= '<div id="plugin__backlinks">' . DW_LF; 82 $renderer->doc .= '<ul class="idx">'; 83 84 foreach($backlinks as $backlink){ 85 $renderer->doc .= '<li><div class="li">'; 86 $renderer->doc .= html_wikilink(':'.$backlink,$conf['useheading']?NULL:preg_replace("/.*?:/",'',$backlink)); 87 $renderer->doc .= '</div></li>'; 88 } 89 90 $renderer->doc .= '</ul>'; 91 $renderer->doc .= '</div>' . DW_LF; 92 } 93 94 return true; 95 } 96 return false; 97 } 98} 99//Setup VIM: ex: et ts=4 enc=utf-8 : 100