-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsearch.php
More file actions
93 lines (74 loc) · 2.72 KB
/
Copy pathsearch.php
File metadata and controls
93 lines (74 loc) · 2.72 KB
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
<?php
/**
* Script to search in uploaded pdf documents
*
* @author Dominik Eckelmann <eckelmann@cosmocode.de>
* @author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
* @author @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
*/
if(!defined('DOKU_INC')) die();
class action_plugin_docsearch_search extends DokuWiki_Action_Plugin {
private $backupConfig;
function register(Doku_Event_Handler $controller) {
$controller->register_hook('TPL_CONTENT_DISPLAY', 'AFTER', $this, 'display', array());
}
function display(Doku_Event &$event, $param) {
global $ACT;
global $conf;
global $QUERY;
global $lang;
// only work with search
if($ACT !== 'search') return;
// backup the config array
$this->backupConfig = $conf;
// change index/pages folder for DocSearch
$conf['indexdir'] = $conf['savedir'] . '/docsearch/index';
$conf['datadir'] = $conf['savedir'] . '/docsearch/pages';
$data = ft_pageSearch($QUERY, $regex);
if(empty($data)) {
$conf = $this->backupConfig;
return;
}
$searchResults = array();
$runs = 0;
foreach($data as $id => $hits) {
$searchResults[$id] = array();
$searchResults[$id]['hits'] = $hits;
if($runs++ < $this->getConf('showSnippets')) {
$searchResults[$id]['snippet'] = ft_snippet($id, $regex);
}
}
$conf = $this->backupConfig;
echo '<div class="search_docsearch">';
echo '<h2>' . hsc($this->getLang('title')) . ':</h2>';
echo '<dl class="search_results">';
$num = 0;
foreach($searchResults as $id => $data) {
if($this->getConf('showUsage') !== 0) {
$usages = ft_mediause($id, $this->getConf('showUsage'));
} else {
$usages = array();
}
echo '<dt><a href="' . ml($id) . '" title="" class="wikilink1">' . hsc($id) . '</a></dt>';
echo '<dd class="meta"><span class="hits">' . hsc($data['hits']) . ' ' . hsc($lang['hits']) . '</span>';
if(!empty($usages)) {
echo '<span class="usage">';
echo ', ' . hsc($this->getLang('usage')) . ' ';
foreach($usages as $usage) {
echo html_wikilink($usage);
}
echo '</span>';
}
echo '</dd>';
if(isset($data['snippet'])) {
echo '<dd class="snippet">';
echo $data['snippet'];
echo '</dd>';
}
echo '<br />';
$num++;
}
echo '</dl>';
echo '</div>';
}
}