Repository navigation
Expand file tree
/
Copy pathaction.php
More file actions
92 lines (77 loc) · 1.96 KB
/
Copy pathaction.php
File metadata and controls
92 lines (77 loc) · 1.96 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
<?php
/**
* Support Twitter Typeahead suggestions
*
* @link https://twitter.github.io/typeahead.js/
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
* @author Mike Frysinger <vapier@gentoo.org>
* @author P.W.G. Brussee <brussee@live.nl>
*/
// must be run within Dokuwiki
use Symfony\Component\HttpFoundation\JsonResponse;
if (!defined('DOKU_INC')) {
die();
}
/**
* Class action_plugin_data
*/
class action_plugin_csrlink extends DokuWiki_Action_Plugin {
/**
* Registers a callback function for a given event
*/
function register(Doku_Event_Handler $controller) {
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, '_handle_ajax');
}
/**
* @param Doku_Event $event
*/
function _handle_ajax(Doku_Event $event) {
if ($event->data !== 'csrlink_wikisuggesties') {
return;
}
$event->stopPropagation();
$event->preventDefault();
global $INPUT;
$query = $INPUT->post->str('q');
if (empty($query)) {
$query = $INPUT->get->str('q');
}
if (empty($query)) {
return;
}
$query = urldecode($query);
$data = ft_pageLookup($query, false, useHeading('navigation'));
$result = array();
foreach ($data as $id => $title) {
$label = false;
if (useHeading('navigation')) {
$name = $title;
} else {
$namespace = getNS($id);
if ($namespace) {
$name = noNS($id);
$label = ucfirst($namespace);
} else {
$name = $id;
}
}
$result[] = array(
'url' => wl($id),
'label' => $label,
'value' => ucfirst($name)
);
}
if (empty($result)) {
$result[] = array(
'url' => '/wiki/hoofdpagina?do=search&id=' . urlencode($query),
'icon' => '<img src="/plaetjes/famfamfam/magnifier.png" class="icon">',
'title' => 'Zoeken in wiki inhoud',
'label' => 'Zoeken in paginainhoud',
'value' => htmlspecialchars($query)
);
}
$view = new JsonResponse($result);
$view->send();
}
}