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-11-07', 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 $match = substr($match,12,-2); //strip {{backlinks> from start and }} from end 60 $match = ($match == '.') ? cleanID($ID) : cleanID($match); 61 62 resolve_pageid(getNS(cleanID($ID)),$match,$exists); 63 64 return (array($match)); 65 } 66 67 /** 68 * Handles the actual output creation. 69 */ 70 function render($mode, &$renderer, $data) { 71 72 if($mode == 'xhtml'){ 73 $renderer->info['cache'] = false; 74 75 @require_once(DOKU_INC.'inc/fulltext.php'); 76 $backlinks = ft_backlinks($data[0]); 77 78 if(!empty($backlinks)) { 79 80 $renderer->doc .= '<div id="plugin__backlinks">' . DW_LF; 81 $renderer->doc .= '<ul class="idx">'; 82 83 foreach($backlinks as $backlink){ 84 $name = p_get_metadata($backlink,'title'); 85 if(empty($name)) $name = $backlink; 86 $renderer->doc .= '<li><div class="li">'; 87 $renderer->doc .= html_wikilink($backlink,$name,''); 88 $renderer->doc .= '</div></li>'; 89 } 90 91 $renderer->doc .= '</ul>'; 92 $renderer->doc .= '</div>' . DW_LF; 93 } 94 95 return true; 96 } 97 return false; 98 } 99} 100//Setup VIM: ex: et ts=4 enc=utf-8 : 101