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