/
Base.php
229 lines (200 loc) · 5.4 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
/**
* Copyright 2010-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 2010-2014 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/
/**
* This class provides the data structure for a message flag.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2010-2014 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*
* @property string $bgcolor The background color.
* @property-read boolean $bgdefault Is the background color the default?
* @property-read boolean $canset Can this flag be set by the user?
* @property-read string $css The CSS class for the icon when the flag is
* set.
* @property-read string $cssicon The CSS class for the icon.
* @property-read string $fgcolor The foreground (text) color.
* @property-read string $form_set Form value to use when setting flag.
* @property-read string $form_unset Form value to use when unsetting flag.
* @property-read string $hash Unique hash of this flag.
* @property-read string $id Unique ID.
* @property-read string $label The query label.
* @property-read string $span Return SPAN HTML to output the icon for use in
* a mailbox row.
*/
abstract class IMP_Flag_Base implements Serializable
{
/* Default background color. */
const DEFAULT_BG = '#fff';
/**
* The background color.
*
* @var string
*/
protected $_bgcolor = '';
/**
* Is this flag settable by the user?
*
* @var boolean
*/
protected $_canset = false;
/**
* The CSS class.
*
* @var string
*/
protected $_css = '';
/**
* The CSS class for the icon.
*
* @var string
*/
protected $_cssIcon = '';
/**
* Unique ID.
*
* @var string
*/
protected $_id = '';
/**
*/
public function __get($name)
{
switch ($name) {
case 'bgcolor':
return $this->_bgcolor
? $this->_bgcolor
: self::DEFAULT_BG;
case 'bgdefault':
return ($this->bgcolor == self::DEFAULT_BG);
case 'canset':
return $this->_canset;
case 'css':
return $this->_css;
case 'cssicon':
return $this->_cssIcon
? $this->_cssIcon
: $this->_css;
case 'span':
return $this->_css
? '<span class="iconImg msgflags ' . $this->css . '" title="' . htmlspecialchars($this->label) . '"> </span>'
: '';
case 'fgcolor':
return (Horde_Image::brightness($this->bgcolor) < 128)
? '#f6f6f6'
: '#000';
case 'form_set':
return $this->id;
case 'form_unset':
return '0\\' . $this->id;
case 'hash':
return hash(
(PHP_MINOR_VERSION >= 4) ? 'fnv132' : 'sha1',
$this->id
);
case 'id':
return $this->_id;
case 'label':
return $this->getLabel();
}
}
/**
* Set properties.
*
* @param string $name Available properties:
* - bgcolor: (string) The background color.
* @param string $value Property value.
*/
public function __set($name, $value)
{
switch ($name) {
case 'bgcolor':
$this->_bgcolor = ($value == self::DEFAULT_BG)
? ''
: $value;
break;
}
}
/**
* Given a list of flag objects, determines if this flag's status has
* changed.
*
* @param array $obs A list of IMP_Flag_Base objects.
* @param boolean $add True if these flags were added, false if they were
* removed.
*
* @return mixed Null if no change, true if flag is added, false if flag
* is removed.
*/
public function changed($obs, $add)
{
return null;
}
/**
* Return the flag label.
*
* @param boolean $set Return label for setting the flag?
*
* @return string The label.
*/
public function getLabel($set = true)
{
return $set
? $this->_getLabel()
: sprintf(_("Not %s"), $this->_getLabel());
}
/**
* Determines if the flag exists given some input data.
*
* @param mixed $data The input data to check.
*
* @return boolean True if flag exists.
*/
public function match($data)
{
return false;
}
/**
* Return the flag label.
* Necessary evil as gettext strings can not be set directly to object
* properties.
*
* @return string The label.
*/
abstract protected function _getLabel();
/* Magic methods. */
/**
* String representation of the object.
*
* @return string String representation (Flag ID).
*/
public function __toString()
{
return $this->id;
}
/* Serializable methods. */
/**
*/
public function serialize()
{
return $this->_bgcolor;
}
/**
*/
public function unserialize($data)
{
$this->_bgcolor = $data;
}
}