0
|
1 <?php
|
|
2
|
|
3 /**
|
|
4 * Roundcube Help Plugin
|
|
5 *
|
|
6 * @author Aleksander 'A.L.E.C' Machniak
|
|
7 * @author Thomas Bruederli <thomas@roundcube.net>
|
|
8 * @license GNU GPLv3+
|
|
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 {
|
|
25 $this->load_config();
|
|
26 $this->add_texts('localization/', false);
|
|
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
|
|
36 $this->add_hook('startup', array($this, 'startup'));
|
|
37 $this->add_hook('error_page', array($this, 'error_page'));
|
|
38 }
|
|
39
|
|
40 function startup($args)
|
|
41 {
|
|
42 $rcmail = rcmail::get_instance();
|
|
43
|
|
44 // add taskbar button
|
|
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');
|
|
52
|
|
53 $this->include_script('help.js');
|
|
54 $rcmail->output->set_env('help_open_extwin', $rcmail->config->get('help_open_extwin', false), true);
|
|
55
|
|
56 // add style for taskbar button (must be here) and Help UI
|
|
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 }
|
|
61 }
|
|
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'),
|
|
70 'tablink' => array($this, 'tablink'),
|
|
71 ));
|
|
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
|
|
83 function tablink($attrib)
|
|
84 {
|
|
85 $rcmail = rcmail::get_instance();
|
|
86
|
|
87 $attrib['name'] = 'helplink' . $attrib['action'];
|
|
88 $attrib['href'] = $rcmail->url(array('_action' => $attrib['action'], '_extwin' => !empty($_REQUEST['_extwin']) ? 1 : null));
|
|
89
|
|
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
|
|
94 return $rcmail->output->button($attrib);
|
|
95 }
|
|
96
|
|
97 function content($attrib)
|
|
98 {
|
|
99 $rcmail = rcmail::get_instance();
|
|
100
|
|
101 switch ($rcmail->action) {
|
|
102 case 'about':
|
|
103 if (is_readable($this->home . '/content/about.html')) {
|
|
104 return @file_get_contents($this->home . '/content/about.html');
|
|
105 }
|
|
106 $default = $rcmail->url(array('_task' => 'settings', '_action' => 'about', '_framed' => 1));
|
|
107 $src = $rcmail->config->get('help_about_url', $default);
|
|
108 break;
|
|
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;
|
|
129 }
|
|
130
|
|
131 // default content: iframe
|
|
132 if (!empty($src)) {
|
|
133 $attrib['src'] = $this->resolve_language($src);
|
|
134 }
|
|
135
|
|
136 if (empty($attrib['id']))
|
|
137 $attrib['id'] = 'rcmailhelpcontent';
|
|
138
|
|
139 $attrib['name'] = $attrib['id'];
|
|
140
|
|
141 return $rcmail->output->frame($attrib);
|
|
142 }
|
|
143
|
|
144 function error_page($args)
|
|
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 }
|
|
154
|
|
155 private function resolve_language($path)
|
|
156 {
|
|
157 // resolve language placeholder
|
|
158 $rcmail = rcmail::get_instance();
|
|
159 $langmap = $rcmail->config->get('help_language_map', array('*' => 'en_US'));
|
|
160 $lang = $langmap[$_SESSION['language']] ?: $langmap['*'];
|
|
161
|
|
162 return str_replace('%l', $lang, $path);
|
|
163 }
|
|
164 }
|