-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.php
62 lines (48 loc) · 1.71 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
<?php
/**
* Multilingual farms
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Jakub Skokan <[email protected]>
*/
if (!defined('DOKU_INC')) die();
class action_plugin_mlfarm extends DokuWiki_Action_Plugin {
public function register(Doku_Event_Handler $controller) {
$controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'onDokuStarted');
$controller->register_hook('PARSER_METADATA_RENDER', 'AFTER', $this, 'onMetadataRender');
}
/**
* Save the current page to the cache file when on master animal.
*/
public function onDokuStarted(Doku_Event $event) {
global $ID, $ACT, $conf;
if (!$ID || $ACT != 'show' || !$this->getConf('master'))
return;
$cache = \dokuwiki\plugin\mlfarm\Cache::getInstance($this->getConf('cache-file'));
$translations = $cache->get($ID);
if ($translations && isset($translations[$conf['lang']]))
return;
$link = wl($ID);
$cache->set($ID, $conf['lang'], array(
'base_url' => DOKU_URL,
'local_id' => $ID,
'link' => $link,
'url' => rtrim(DOKU_URL, '/').$link,
));
}
public function onMetadataRender(Doku_Event $event) {
global $ID, $conf;
if (!$ID)
return;
$gid = $event->data['persistent']['identifier'];
if (!$gid)
return;
$link = wl($ID);
\dokuwiki\plugin\mlfarm\Cache::getInstance($this->getConf('cache-file'))->set($gid, $conf['lang'], array(
'base_url' => DOKU_URL,
'local_id' => $ID,
'link' => $link,
'url' => rtrim(DOKU_URL, '/').$link,
));
}
}