summaryrefslogtreecommitdiff
path: root/plugins/help/help.php
blob: 2606b27c5dbeaa9cfe136cd717800c94b3afcbeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php

/**
 * Help Plugin
 *
 * @author Aleksander 'A.L.E.C' Machniak
 * @licence GNU GPL
 *
 * Configuration (see config.inc.php.dist)
 * 
 **/

class help extends rcube_plugin
{
    // all task excluding 'login' and 'logout'
    public $task = '?(?!login|logout).*';

    function init()
    {
        $rcmail = rcmail::get_instance();

        $this->add_texts('localization/', false);

        // register actions
        $this->register_action('plugin.help', array($this, 'action'));
        $this->register_action('plugin.helpabout', array($this, 'action'));
        $this->register_action('plugin.helplicense', array($this, 'action'));

        // add taskbar button
        $this->add_button(array(
	        'name' 	=> 'helptask',
	        'class'	=> 'button-help',
	        'label'	=> 'help.help',
	        'href'	=> './?_task=dummy&_action=plugin.help',
            ), 'taskbar');

        $skin = $rcmail->config->get('skin');
        if (!file_exists($this->home."/skins/$skin/help.css"))
	        $skin = 'default';

        // add style for taskbar button (must be here) and Help UI    
        $this->include_stylesheet("skins/$skin/help.css");
    }

    function action()
    {
        $rcmail = rcmail::get_instance();

        $this->load_config();

        // register UI objects
        $rcmail->output->add_handlers(array(
	        'helpcontent' => array($this, 'content'),
        ));

        if ($rcmail->action == 'plugin.helpabout')
	        $rcmail->output->set_pagetitle($this->gettext('about'));
        else if ($rcmail->action == 'plugin.helplicense')
            $rcmail->output->set_pagetitle($this->gettext('license'));
        else
            $rcmail->output->set_pagetitle($this->gettext('help'));

        $rcmail->output->send('help.help');
    }

    function content($attrib)
    {
        $rcmail = rcmail::get_instance();

        if ($rcmail->action == 'plugin.helpabout') {
	        return @file_get_contents($this->home.'/content/about.html');
        }
        else if ($rcmail->action == 'plugin.helplicense') {
	        return @file_get_contents($this->home.'/content/license.html');
        }

        // default content: iframe

        if ($src = $rcmail->config->get('help_source'))
	        $attrib['src'] = $src;

        if (empty($attrib['id']))
            $attrib['id'] = 'rcmailhelpcontent';
    
        // allow the following attributes to be added to the <iframe> tag
        $attrib_str = create_attrib_string($attrib, array(
            'id', 'class', 'style', 'src', 'width', 'height', 'frameborder'));

        $out = sprintf('<iframe name="%s"%s></iframe>'."\n", $attrib['id'], $attrib_str);
    
        return $out;
    }

}