-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
tour.php
204 lines (172 loc) · 6.04 KB
/
tour.php
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
/**
* Roundcube Plugin Tour
* Plugin for adding a tour to the site.
*
* @version 1.2
* @author Alexander Pushkin <[email protected]>
* @copyright Copyright (c) 2017, Alexander Pushkin
* @link https://github.com/san4op/roundcube_tour
* @license GNU General Public License, version 3
*/
class tour extends rcube_plugin
{
public $task = 'login|mail|settings';
public $noframe = true;
private $rc;
private $prefs;
function init()
{
$this->rc = rcube::get_instance();
// show don't completed tour again after login
if ($this->rc->task == 'login') {
$this->add_hook('login_after', array($this, 'user_login'));
return;
}
// get status of tour
$this->prefs = $this->rc->user->get_prefs();
$this->prefs = (isset($this->prefs['tour']) ? $this->prefs['tour'] : array());
// load config
$this->load_config();
$introjs_theme = $this->rc->config->get('tour_introjs_theme', false);
// load localization
$this->add_texts('localization/', true);
// include styles
$this->include_stylesheet('lib/intro.js/introjs.css');
if ($introjs_theme) {
$this->include_stylesheet('lib/intro.js/themes/introjs-'.$introjs_theme.'.css');
}
$this->include_stylesheet($this->local_skin_path() . '/tour.css');
// include scripts
$this->include_script('lib/intro.js/intro.js');
$this->include_script('tour.js');
// add button
$this->add_button(
array(
'name' => 'tour',
'type' => 'link',
'label' => 'tour.button',
'onclick' => 'if(tour)tour(true);return false',
),
'topline-left'
);
// load config for buttons
$taskbar_buttons = $this->rc->config->get('tour_taskbar_buttons', array('mail' => true, 'addressbook' => true, 'settings' => true));
$toolbar_buttons = $this->rc->config->get('tour_toolbar_buttons', array());
$settings_actions = $this->rc->config->get('tour_settings', array('preferences' => true, 'folders' => true, 'identities' => true, 'responses' => true));
// check loaded plugins
if (version_compare(RCMAIL_VERSION, '1.1') >= 0) {
$plugins = $this->api->active_plugins;
} else {
$plugins = array_filter((array) $this->rc->config->get('plugins'));
}
if (!in_array('cloud_button', $plugins)) {
$taskbar_buttons['cloud'] = false;
}
if (!in_array('calendar', $plugins)) {
$taskbar_buttons['calendar'] = false;
}
if (!in_array('tasklist', $plugins)) {
$taskbar_buttons['tasklist'] = false;
}
if (!in_array('kolab_notes', $plugins)) {
$taskbar_buttons['notes'] = false;
}
if (!in_array('kolab_files', $plugins)) {
$taskbar_buttons['files'] = false;
}
if (!in_array('archive', $plugins) || !$this->rc->config->get('archive_mbox')) {
$toolbar_buttons['archive'] = false;
}
if (!in_array('markasjunk', $plugins) && !in_array('markasjunk2', $plugins)) {
$toolbar_buttons['junk'] = false;
}
if (!in_array('managesieve', $plugins)) {
$settings_actions['pluginmanagesieve'] = false;
$settings_actions['pluginmanagesievevacation'] = false;
} else {
if (version_compare(RCMAIL_VERSION, '1.1') >= 0) {
if (($managesieve = $this->api->get_plugin('managesieve')) instanceof managesieve) {
if ($managesieve->load_config()) {
$vacation_mode = (int) $this->rc->config->get('managesieve_vacation');
if ($vacation_mode === 2) {
$settings_actions['pluginmanagesieve'] = false;
}
if ($vacation_mode === 0) {
$settings_actions['pluginmanagesievevacation'] = false;
}
} else {
$settings_actions['pluginmanagesievevacation'] = false;
}
} else {
$settings_actions['pluginmanagesieve'] = false;
$settings_actions['pluginmanagesievevacation'] = false;
}
unset($managesieve);
} else {
$settings_actions['pluginmanagesieve'] = false;
$settings_actions['pluginmanagesievevacation'] = false;
}
}
if (!in_array('password', $plugins)) {
$settings_actions['pluginpassword'] = false;
}
// make enviroment
$this->api->output->set_env('tour', array(
'welcome' => $this->rc->config->get('tour_welcome', true),
'support' => $this->rc->config->get('tour_support', true),
'taskbar' => $this->rc->config->get('tour_taskbar', true),
'taskbar_buttons' => $taskbar_buttons,
'toolbar' => $this->rc->config->get('tour_toolbar', true),
'toolbar_buttons' => $toolbar_buttons,
'folders' => $this->rc->config->get('tour_folders', true),
'quota' => $this->rc->config->get('tour_quota', true),
'taglist' => $this->rc->config->get('tour_taglist', true),
'messages_view' => $this->rc->config->get('tour_messages_view', true),
'messages_threads' => $this->rc->config->get('tour_messages_threads', true),
'settings' => $settings_actions,
));
// not run again if tour already complete
if (isset($this->prefs[$this->rc->task][$this->rc->action]) && $this->prefs[$this->rc->task][$this->rc->action] > 0) {
return;
}
// register action to process complete of tour
$this->register_action('plugin.tour_complete', array($this, 'complete'));
// show tours
if (!$this->rc->output->ajax_call) {
$this->api->output->set_env('tour_run', 1);
}
}
public function complete()
{
if (!$this->rc->output->ajax_call) {
return;
}
$task = rcube_utils::get_input_value('task', rcube_utils::INPUT_POST);
$action = rcube_utils::get_input_value('action', rcube_utils::INPUT_POST);
$complete = (int) rcube_utils::get_input_value('complete', rcube_utils::INPUT_POST);
if ($complete > 0) {
if (!isset($this->prefs[$task])) {
$this->prefs[$task] = array($action => $complete);
}
elseif (!isset($this->prefs[$task][$action]) || $this->prefs[$task][$action] <> 2) {
$this->prefs[$task][$action] = $complete;
}
$this->rc->user->save_prefs(array('tour' => $this->prefs));
}
}
public function user_login()
{
$prefs = $this->rc->user->get_prefs();
$prefs = (isset($prefs['tour']) ? $prefs['tour'] : array());
foreach ($prefs as $task => $actions) {
foreach ($actions as $action => $complete) {
if($complete == 1) {
$prefs[$task][$action] = 0;
}
}
}
$this->rc->user->save_prefs(array('tour' => $prefs));
}
}
?>