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