Aleksander Machniak
2015-11-22 9f1f754daf4b57a0d0d3aea95d2321716d218cf5
commit | author | age
48e9c1 1 <?php
T 2
3 /**
08167e 4  * Roundcube Help Plugin
48e9c1 5  *
T 6  * @author Aleksander 'A.L.E.C' Machniak
08167e 7  * @author Thomas Bruederli <thomas@roundcube.net>
48e9c1 8  * @license GNU GPLv3+
T 9  *
10  * Configuration (see config.inc.php.dist)
11  * 
12  **/
13
14 class help extends rcube_plugin
15 {
16     // all task excluding 'login' and 'logout'
17     public $task = '?(?!login|logout).*';
18     // we've got no ajax handlers
19     public $noajax = true;
20     // skip frames
21     public $noframe = true;
22
23     function init()
24     {
08167e 25         $this->load_config();
48e9c1 26         $this->add_texts('localization/', false);
T 27
28         // register task
29         $this->register_task('help');
30
31         // register actions
32         $this->register_action('index', array($this, 'action'));
33         $this->register_action('about', array($this, 'action'));
34         $this->register_action('license', array($this, 'action'));
35
c35395 36         $this->add_hook('startup', array($this, 'startup'));
b9ac6e 37         $this->add_hook('error_page', array($this, 'error_page'));
c35395 38     }
TB 39
40     function startup($args)
41     {
08167e 42         $rcmail = rcmail::get_instance();
TB 43
48e9c1 44         // add taskbar button
T 45         $this->add_button(array(
46             'command'    => 'help',
47             'class'      => 'button-help',
48             'classsel'   => 'button-help button-selected',
49             'innerclass' => 'button-inner',
50             'label'      => 'help.help',
51         ), 'taskbar');
08167e 52
TB 53         $this->include_script('help.js');
54         $rcmail->output->set_env('help_open_extwin', $rcmail->config->get('help_open_extwin', false), true);
48e9c1 55
bc92ca 56         // add style for taskbar button (must be here) and Help UI
AM 57         $skin_path = $this->local_skin_path();
58         if (is_file($this->home . "/$skin_path/help.css")) {
59             $this->include_stylesheet("$skin_path/help.css");
60         }
48e9c1 61     }
T 62
63     function action()
64     {
65         $rcmail = rcmail::get_instance();
66
67         // register UI objects
68         $rcmail->output->add_handlers(array(
69             'helpcontent' => array($this, 'content'),
d8e101 70             'tablink' => array($this, 'tablink'),
48e9c1 71         ));
T 72
73         if ($rcmail->action == 'about')
74             $rcmail->output->set_pagetitle($this->gettext('about'));
75         else if ($rcmail->action == 'license')
76             $rcmail->output->set_pagetitle($this->gettext('license'));
77         else
78             $rcmail->output->set_pagetitle($this->gettext('help'));
79
80         $rcmail->output->send('help.help');
81     }
82
d8e101 83     function tablink($attrib)
TB 84     {
85         $rcmail = rcmail::get_instance();
af6e47 86
d8e101 87         $attrib['name'] = 'helplink' . $attrib['action'];
TB 88         $attrib['href'] = $rcmail->url(array('_action' => $attrib['action'], '_extwin' => !empty($_REQUEST['_extwin']) ? 1 : null));
af6e47 89
AM 90         // title might be already translated here, so revert to it's initial value
91         // so button() will translate it correctly
92         $attrib['title'] = $attrib['label'];
93
d8e101 94         return $rcmail->output->button($attrib);
TB 95     }
96
48e9c1 97     function content($attrib)
T 98     {
99         $rcmail = rcmail::get_instance();
100
08167e 101         switch ($rcmail->action) {
TB 102             case 'about':
103                 if (is_readable($this->home . '/content/about.html')) {
104                     return @file_get_contents($this->home . '/content/about.html');
105                 }
eabc05 106                 $default = $rcmail->url(array('_task' => 'settings', '_action' => 'about', '_framed' => 1));
AM 107                 $src     = $rcmail->config->get('help_about_url', $default);
08167e 108                 break;
TB 109
110             case 'license':
111                 if (is_readable($this->home . '/content/license.html')) {
112                     return @file_get_contents($this->home . '/content/license.html');
113                 }
114                 $src = $rcmail->config->get('help_license_url', 'http://www.gnu.org/licenses/gpl-3.0-standalone.html');
115                 break;
116
117             default:
118                 $src = $rcmail->config->get('help_source');
119
120                 // resolve task/action for depp linking
121                 $index_map = $rcmail->config->get('help_index_map', array());
122                 $rel = $_REQUEST['_rel'];
123                 list($task,$action) = explode('/', $rel);
124                 if ($add = $index_map[$rel])
125                     $src .= $add;
126                 else if ($add = $index_map[$task])
127                     $src .= $add;
128                 break;
48e9c1 129         }
T 130
131         // default content: iframe
08167e 132         if (!empty($src)) {
TB 133             $attrib['src'] = $this->resolve_language($src);
134         }
48e9c1 135
T 136         if (empty($attrib['id']))
137             $attrib['id'] = 'rcmailhelpcontent';
138
139         $attrib['name'] = $attrib['id'];
140
28de39 141         return $rcmail->output->frame($attrib);
48e9c1 142     }
T 143
b9ac6e 144     function error_page($args)
TB 145     {
146         $rcmail = rcmail::get_instance();
147
148         if ($args['code'] == 403 && $rcmail->request_status == rcube::REQUEST_ERROR_URL && ($url = $rcmail->config->get('help_csrf_info'))) {
149             $args['text'] .= '<p>' . html::a(array('href' => $url, 'target' => '_blank'), $this->gettext('csrfinfo')) . '</p>';
150         }
151
152         return $args;
153     }
08167e 154
TB 155     private function resolve_language($path)
156     {
157         // resolve language placeholder
9f1f75 158         $rcmail  = rcmail::get_instance();
08167e 159         $langmap = $rcmail->config->get('help_language_map', array('*' => 'en_US'));
9f1f75 160         $lang    = $langmap[$_SESSION['language']] ?: $langmap['*'];
AM 161
08167e 162         return str_replace('%l', $lang, $path);
TB 163     }
48e9c1 164 }