This repository has been archived by the owner on Aug 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.php
65 lines (53 loc) · 2.04 KB
/
action.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
<?php
/**
* DokuWiki Plugin searchresultswithpath (Action Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Sam B <sam@s-blu.de>
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
class action_plugin_searchresultswithpath extends DokuWiki_Action_Plugin {
/**
* Registers a callback function for a given event
*
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler $controller) {
$controller->register_hook('SEARCH_QUERY_PAGELOOKUP', 'AFTER', $this, 'handle_search_query_pagelookup');
}
/**
* [Custom event handler which performs action]
*
* @param Doku_Event $event event object by reference
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this
* handler was registered]
* @return void
*/
public function handle_search_query_pagelookup(Doku_Event &$event) {
$useNsHeading = $this->getConf('use_ns_heading');
$showPathOnlyAsHeading = $this->getConf('show_path_only_as_heading');
foreach($event->result as $id => $title){
if (!$useNsHeading) {
$ns = getNS($id);
} else {
//Get Name of the NS Page or NS:start Page, if possible
$ns = p_get_first_heading(getNS($id));
if(!$ns) $ns = p_get_first_heading(getNS($id). ':start');
if (!$ns && !$showPathOnlyAsHeading) {
$ns = getNS($id);
}
}
if($ns) $ns = ' ['.$ns.']';
/*
* Fix #1: Add the pageId to the title, if the page has no heading
* Normally this get handled by Dokuwiki itself, but we always set an title here and
* bypass Dokuwikis handling
*/
if (!$title) $title = noNs($id);
$event->result[$id] = $title . $ns;
}
}
}
// vim:ts=4:sw=4:et: