1<?php
2
3class action_plugin_nspages extends DokuWiki_Action_Plugin {
4
5    /**
6     * Register its handlers with the dokuwiki's event controller
7     */
8    function register(Doku_Event_Handler $controller) {
9        $controller->register_hook('TOOLBAR_DEFINE', 'AFTER',  $this, 'insert_button', array());
10        $controller->register_hook('PLUGIN_POPULARITY_DATA_SETUP', 'AFTER', $this, 'usage_data');
11    }
12
13    function insert_button(& $event, $param) {
14      $event->data[] = array (
15          'type' => 'insert',
16          'title' => 'nspages',
17          'icon' => '../../plugins/nspages/images/tb_nspages.png',
18          'insert' => $this->getConf('toolbar_inserted_markup')
19          );
20    }
21
22    function usage_data(&$event){
23      $plugin_info = $this->getInfo();
24      $event->data['nspages']['version'] = $plugin_info['date'];
25      $event->data['nspages']['legacyModificationDateSyntax'] = $this->used_legacy_syntax_not_too_long_ago() ? 'true' : 'false';
26    }
27
28    private function used_legacy_syntax_not_too_long_ago(){
29      $legacySyntax = io_readFile(action_plugin_nspages::legacySyntaxFilename());
30      if ($legacySyntax){
31        if ($legacySyntax > time() - 365 * 86400){
32          return true;
33        } else {
34          unlink(action_plugin_nspages::legacySyntaxFilename());
35        }
36      }
37    }
38
39    static function logUseLegacySyntax(){
40      $file = action_plugin_nspages::legacySyntaxFilename();
41      io_saveFile($file, time());
42    }
43
44    static function legacySyntaxFilename(){
45      global $conf;
46      return $conf['savedir'] . '/nspages_legacy_syntax.txt';
47    }
48
49}
50