1<?php
2/**
3 * Idcount Plugin
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author: Gero Gothe <gero.gothe@medizindoku.de>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11define('DEBUG',false);
12
13/**
14 * Class action_plugin_searchform
15 */
16class action_plugin_idcount extends DokuWiki_Action_Plugin {
17
18    # Registers a callback function for a given event
19    public function register(Doku_Event_Handler $controller) {
20        $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this,'_ajax_call');
21    }
22
23
24    public function _generate_ID(){
25        if (file_exists(DOKU_INC.'data/meta/idcount.txt')) {
26            $n = intval(file_get_contents(DOKU_INC.'data/meta/idcount.txt'));
27            $n++;
28        } else $n = 1;
29        file_put_contents(DOKU_INC.'data/meta/idcount.txt',$n);
30        $d = intval($this->getConf('digits'));
31        return sprintf('%0'.$d.'d', $n);
32    }
33
34
35    public function _ajax_call(Doku_Event $event, $param) {
36
37        if ($event->data !== 'idcount_generate') {
38            return;
39        }
40
41        # No other ajax call handlers needed
42        $event->stopPropagation();
43        $event->preventDefault();
44
45        echo $this->getConf('prefix').$this->_generate_ID();
46
47    }
48
49}
50
51// vim:ts=4:sw=4:et:
52