1<?php
2/*
3 *
4 * Text modules Plugin
5 *
6 * @author: Gero Gothe <gero.gothe@medizindoku.de>
7 * License: GPL2
8 *
9 */
10
11
12class admin_plugin_textmodule extends DokuWiki_Admin_Plugin {
13
14    function getMenuText($language){
15        return $this->getLang("text module");
16    }
17
18    function forAdminOnly() {
19        return false;
20    }
21
22    /* Loads the saved textmodules from the file data/modules/modules.txt
23     *
24     * Format: (per line Basis)
25     * Title 1
26     * Module 1 shortcut:Module t Text
27     * [...]
28     * Module n shortcut: Module n text
29     * [TEXTMODULE DELIMITER]
30     * Title 2
31     * [...]
32    */
33    function _loadModules() {
34        if (file_exists('data/meta/modules.txt')) {
35            $t = file_get_contents('data/meta/modules.txt');
36            $t = explode("\n[TEXT MODULE DELIMITER]\n",$t);
37            foreach ($t as &$m) $m = explode(PHP_EOL,$m);
38            return $t;
39
40        }
41        return Array(Array('',''),Array('',''),Array('',''));
42    }
43
44
45    /* Save the form data */
46    function handle(){
47        if (!isset($_REQUEST)) return;
48
49        if (isset($_REQUEST['Save'])) {
50            $r = $_REQUEST['title1'] . "\n" . trim($_REQUEST['text1']) . "\n[TEXT MODULE DELIMITER]\n" . $_REQUEST['title2'] . "\n" . trim($_REQUEST['text2']) . "\n[TEXT MODULE DELIMITER]\n" . $_REQUEST['title3']. "\n" . trim($_REQUEST['text3']);
51            file_put_contents('data/meta/modules.txt',$r);
52        }
53    }
54
55
56    /* Output HTML for the admin section */
57    function html() {
58        echo '<h1>'.$this->getLang("text module").' Plugin</h1>';
59        echo $this->getLang("admin help").'<br>';
60
61        $m = $this->_loadModules();
62
63        echo '<form action="'.wl($ID).'" method="post">';
64
65        # output hidden values to ensure dokuwiki will return back to this plugin
66        echo '<input type="hidden" name="do"   value="admin" />';
67        echo '<input type="hidden" name="page" value="'.$this->getPluginName().'" />';
68
69        for ($c=1;$c<4;$c++) {
70            echo '<br><br><hr>';
71            echo $this->getLang("title").' '.$c.': <input type="text" name="title'.$c.'" value="'.($m[$c-1][0]).'"><br><br>';
72            echo '<textarea name="text'.$c.'" style="width:100%;height:10vw">'.implode("\n",array_slice($m[$c-1],1)).'</textarea>';
73        }
74
75        echo '<br><br><input name="Save" type="submit" value="Save">';
76        echo '</form>';
77    }
78
79}
80
81