/
Base.php
212 lines (181 loc) · 5.66 KB
/
Base.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
205
206
207
208
209
210
211
212
<?php
/**
* Copyright 2012-2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @category Horde
* @copyright 2012-2014 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/
/**
* Base class for dynamic view pages.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2012-2014 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/
abstract class IMP_Dynamic_Base
{
/**
* @var IMP_Indices_Mailbox
*/
public $indices;
/**
* @var array
*/
public $js_conf = array();
/**
* @var array
*/
public $js_context = array();
/**
* @var array
*/
public $js_text = array();
/**
* @var string
*/
public $title = '';
/**
* @var Horde_Variables
*/
public $vars;
/**
* @var Horde_View
*/
public $view;
/**
* @var array
*/
protected $_pages = array(
'header'
);
/**
*/
public function __construct(Horde_Variables $vars)
{
global $page_output;
$this->vars = $vars;
$this->view = $this->getEmptyView();
$this->indices = new IMP_Indices_Mailbox($vars);
$this->_addBaseVars();
$page_output->addScriptFile('dimpcore.js');
$page_output->addScriptFile('viewport_utils.js');
$page_output->addScriptFile('contextsensitive.js', 'horde');
$page_output->addScriptFile('imple.js', 'horde');
$mimecss = new Horde_Themes_Element('mime.css');
$page_output->addStylesheet($mimecss->fs, $mimecss->uri);
$page_output->sidebar = $page_output->topbar = false;
$this->_init();
$page_output->addInlineJsVars(array(
'DimpCore.conf' => $this->js_conf,
'DimpCore.context' => $this->js_context,
'DimpCore.text' => $this->js_text
), array('top' => true));
}
/**
*/
public function render()
{
foreach ($this->_pages as $val) {
echo $this->view->render($val);
}
}
/**
* Return a View object.
*
* @return Horde_View View object.
*/
public function getEmptyView()
{
$view = new Horde_View(array(
'templatePath' => IMP_TEMPLATES . '/dynamic'
));
$view->addHelper('Text');
$view->addHelper('IMP_Dynamic_Helper_Base');
return $view;
}
/**
* Add base javascript variables to the page.
*/
protected function _addBaseVars()
{
global $prefs, $registry, $session;
/* Variables used in core javascript files. */
$this->js_conf = array_filter(array(
// URL variables
'MAX_FILE_SIZE' => intval($session->get('imp', 'file_upload')),
'URI_COMPOSE' => strval(IMP_Dynamic_Compose::url()->setRaw(true)),
'URI_VIEW' => strval(Horde::url('view.php')->add(IMP_Contents_View::addToken())),
// Other variables
'disable_compose' => !IMP_Compose::canCompose(),
'pref_prefix' => hash(
(PHP_MINOR_VERSION >= 4) ? 'fnv132' : 'sha1',
$registry->getAuth() . '|' . $_SERVER['SERVER_NAME']
)
));
/* Context menu definitions.
* Keys:
* - Begin with '_mbox': A mailbox name container entry
* - Begin with '_sep': A separator
* - Begin with '_sub': All subitems wrapped in a DIV
* - Begin with a '*': No icon
*/
$context = array(
'ctx_contacts' => array(
// Empty sub item needs to be a javascript object
'_sub1' => new stdClass,
'new' => _("New Message"),
'add' => _("Add to Address Book"),
'copy' => _("Copy to Clipboard")
),
'ctx_reply' => array(
'reply' => _("To Sender"),
'reply_all' => _("To All"),
'reply_list' => _("To List")
)
);
if ($registry->hasLink('mail/newEmailFilter')) {
$context['ctx_contacts']['addfilter'] = _("Create Filter");
}
/* Forward context menu. */
$context['ctx_forward'] = array(
'attach' => _("As Attachment"),
'body' => _("In Body Text"),
'both' => _("Attachment and Body Text"),
'_sep1' => null,
'editasnew' => _("Edit as New"),
'_sep2' => null,
'redirect' => _("Redirect")
);
if ($prefs->isLocked('forward_default')) {
unset(
$context['ctx_forward']['attach'],
$context['ctx_forward']['body'],
$context['ctx_forward']['both'],
$context['ctx_forward']['_sep1']
);
}
$this->js_context = $context;
/* Gettext strings used in core javascript files. */
$this->js_text = array(
'allparts_label' => _("Parts"),
'emailcopy' => _("Your browser security settings don't permit the editor to copy to the clipboard.") . "\n" . _("You need to manually use the keyboard instead (Ctrl/Cmd + C)."),
'loading' => _("Loading..."),
'strip_warn' => _("Are you sure you wish to PERMANENTLY delete this attachment?"),
'verify' => _("Verifying...")
);
}
static public function url(array $opts = array())
{
throw new Exception('Missing implementation for url method.');
}
/**
*/
abstract protected function _init();
}