1<?php
2/*
3 *
4 * Text modules Plugin
5 *
6 * @author: Gero Gothe <gero.gothe@medizindoku.de>
7 * License: GPL2
8 *
9 */
10
11
12if ( !defined( 'DOKU_INC' ) ) die();
13
14if ( !defined( 'DOKU_PLUGIN' ) ) define( 'DOKU_PLUGIN', DOKU_INC . 'lib/plugins/' );
15
16require_once( DOKU_PLUGIN . 'action.php' );
17
18class action_plugin_textmodule extends DokuWiki_Action_Plugin {
19
20    public function register(Doku_Event_Handler $controller) {
21        $controller->register_hook('HTML_EDITFORM_OUTPUT', 'BEFORE', $this,'handle_editform_output');
22    }
23
24
25    /* Create the div-containers for the textmodules */
26    function _format_modules() {
27        if (file_exists('data/meta/modules.txt')) {
28            $t = file_get_contents('data/meta/modules.txt');
29            $t = explode("\n[TEXT MODULE DELIMITER]\n",$t);
30            $r = '';
31            foreach ($t as $m) {
32                $m = explode(PHP_EOL,trim($m));
33
34                if (count($m)>1) {
35
36                    $title = trim($m[0]);
37                    if (strlen($title)==0)  $title = $this->getLang("text module");
38                    $r .= '<div id="textmodule_'.$title.'" class="plugin_textmodule_box" onclick="textmodule_expand(this.id)">';
39                    $r.= '<div style="text-align:center;width:100%">'.$title.'</div>';
40
41
42                    for ($c=1;$c<Count($m);$c++) {
43
44                        # Check for separator ":"
45                        $n = strpos($m[$c],":");
46                        if ($n == 0) {
47                            $t1 = trim($m[$c]);
48                            $t2 = $t1;
49                        } else {
50                            $t1 = trim(substr($m[$c],0,$n));
51                            $t2 = trim(substr($m[$c],$n+1));
52                        }
53
54                        $r .= '<a class="plugin_textmodule_link" onclick="textmodule_snippet(\''.$t2.'\')">'.$t1.'</a> ';
55                    }
56
57                    $r .= '</div>';
58                }
59            }
60            return $r;
61        }
62    }
63
64    /* Create the additional fields for the edit form. */
65    function handle_editform_output( &$event, $param ) {
66        $pos = $event->data->findElementByAttribute( 'type', 'submit' );
67        if ( !$pos ){ return; }
68
69        $out = '<div>';
70        $out .= $this->_format_modules();
71        $out .= '</div>';
72
73        $event->data->insertElement( $pos++, $out );
74    }
75
76}
77