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