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