-
Notifications
You must be signed in to change notification settings - Fork 127
/
Status.php
201 lines (177 loc) · 4.77 KB
/
Status.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
<?php
/**
* Copyright 2011-2017 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 2011-2017 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/
/**
* Provides the object that contains the status data to output when viewing
* MIME parts in IMP.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2011-2017 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/
class IMP_Mime_Status
{
/* Action constants. */
const ERROR = 1;
const SUCCESS = 2;
const WARNING = 3;
/**
* Views to display this status in.
*
* @var array
*/
public $views = array(
Horde_Registry::VIEW_BASIC,
Horde_Registry::VIEW_DYNAMIC
);
/**
* DOM ID to use for the status block.
*
* @var string
*/
protected $_domid;
/**
* Icon image HTML.
*
* @var string
*/
protected $_icon;
/**
* MIME Part that this status object refers to.
*
* @var Horde_Mime_Part
*/
protected $_part;
/**
* List of text to output. Each entry will be output on a newline.
*
* @var array
*/
protected $_text = array();
/**
* Constructor.
*
* @param Horde_Mime_Part $part MIME Part.
* @param mixed $text See addText().
*/
public function __construct($part = null, $text = null)
{
$this->_part = $part;
if (!is_null($text)) {
$this->addText($text);
}
}
/**
* Pre-defined actions.
*
* @param integer $type The action type.
*/
public function action($type)
{
switch ($type) {
case self::ERROR:
$this->icon('alerts/error.png', _("Error"));
break;
case self::SUCCESS:
$this->icon('alerts/success.png', _("Success"));
break;
case self::WARNING:
$this->icon('alerts/warning.png', _("Warning"));
break;
}
}
/**
* Adds text line(s) to the output.
*
* @param mixed $text Either a line of text or an array of lines to add.
*/
public function addText($text)
{
if (!is_array($text)) {
$text = array($text);
}
$this->_text = array_merge($this->_text, $text);
}
/**
* Adds a MIME Viewer action to the status text.
*
* @param string $action Action ID.
* @param string $text Action description.
* @param array $attr Additional attributes.
*/
public function addMimeAction($action, $text, array $attr = array())
{
$attr['mimevieweraction'] = $action;
if (!is_null($this->_part)) {
$attr['mimeviewerid'] = $this->_part->getMimeId();
}
$url = new Horde_Url('#');
$this->addText($url->link($attr) . $text . '</a>');
}
/**
* Set the icon to use for the status block (Default: no icon).
*
* @param string $img The image file.
* @param string $alt ALT text to use.
*/
public function icon($img, $alt = null)
{
$this->_icon = Horde_Themes_Image::tag($img, array('alt' => $alt));
}
/**
* Set a DOM ID for the status block.
*
* @param string $id The DOM ID to use.
*/
public function domid($id = null)
{
$this->_domid = $id;
}
/**
* Output status block HTML.
*
* @return string The formatted status message HTML.
*/
public function __toString()
{
global $registry;
$out = '';
switch ($registry->getView()) {
case $registry::VIEW_SMARTMOBILE:
foreach ($this->_text as $val) {
$out .= '<div>' . $val . '</div>';
}
break;
default:
$out = '<div><table class="mimeStatusMessageTable"' .
(isset($this->_domid) ? (' id="' . $this->_domid . '" ') : '')
. '>';
/* If no image, simply print out the message. */
if (empty($this->_icon)) {
foreach ($this->_text as $val) {
$out .= '<tr><td>' . $val . '</td></tr>';
}
} else {
$out .= '<tr><td class="mimeStatusIcon">' . $this->_icon . '</td><td><table>';
foreach ($this->_text as $val) {
$out .= '<tr><td>' . $val . '</td></tr>';
}
$out .= '</table></td></tr>';
}
$out .= '</table></div>';
break;
}
return '<div class="mimeStatusMessage">' . $out . '</div>';
}
}