This repository has been archived by the owner on Jan 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
algolia.php
executable file
·80 lines (66 loc) · 1.92 KB
/
algolia.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
<?php
/**
* Kirby Algolia Plugin
*
* @author Lukas Bestle <[email protected]>
*/
/**
* Autoloader for all Kirby Algolia classes and dependencies
*/
load([
'kirby\\algolia' => __DIR__ . DS . 'lib' . DS . 'algolia.php',
'kirby\\algolia\\results' => __DIR__ . DS . 'lib' . DS . 'algolia' . DS . 'results.php',
// Official Algolia PHP API client
'algoliasearch\\client' => __DIR__ . DS . 'vendor' . DS . 'algolia-client' . DS . 'algoliasearch.php'
]);
/**
* Helper function that returns a Kirby\Algolia instance
*
* @return Algolia
*/
function algolia() {
return Kirby\Algolia::instance();
}
// Register the Panel widget
if(c::get('algolia.widget', true) && function_exists('panel')) {
kirby()->set('widget', 'algolia', __DIR__ . DS . 'widgets' . DS . 'algolia');
// Register the route for the widget
panel()->routes([
[
'pattern' => 'widgets/algolia/index',
'method' => 'GET',
'filter' => 'auth',
'action' => function() {
algolia()->index();
panel()->notify(':)');
panel()->redirect('/');
}
]
]);
}
/**
* Panel hooks
*
* Every page change is automatically synced to Algolia
* Automatic indexing can be disabled with the algolia.autoindex option
*/
if(c::get('algolia.autoindex', true)) {
kirby()->hook('panel.page.create', function($page) {
return algolia()->insertPage($page);
});
kirby()->hook('panel.page.update', function($page) {
return algolia()->updatePage($page);
});
kirby()->hook('panel.page.delete', function($page) {
return algolia()->deletePageRecursive($page);
});
kirby()->hook('panel.page.sort', function($page) {
return algolia()->updatePage($page);
});
kirby()->hook('panel.page.hide', function($page) {
return algolia()->updatePage($page);
});
kirby()->hook('panel.page.move', function($newPage, $oldPage) {
return algolia()->movePage($oldPage, $newPage);
});
}