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 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
|
<?php
/**
* Vacation_Driver:: defines an API for implementing vacation backends for the
* vacation module.
*
* $Horde: vacation/lib/Driver.php,v 1.35.2.2 2007/01/02 13:55:21 jan Exp $
*
* Copyright 2001-2007 Eric Rostetter and Mike Cochrane
*
* See the enclosed file LICENSE for license information (BSD). If you
* did not receive this file, see http://www.horde.org/licenses/bsdl.php.
*
* @author Mike Cochrane <mike@graftonhall.co.nz>
* @author Eric Rostetter <eric.rostetter@physics.utexas.edu>
* @package Vacation
*/
class Vacation_Driver {
/**
* Hash containing configuration data.
*
* @var array
*/
var $_params;
/**
* Error string returned to user if an eror occurs.
*
* @var string
*/
var $err_str;
/**
* Constructor.
*
* @param array $params Configuration parameters for the backend.
*/
function Vacation_Driver($params = array())
{
$this->_params = $params;
}
/**
* Return a parameter value.
*
* @param string $param The parameter to check in.
* @param string $realm The realm to retrieve the parameter from.
*
* @return mixed The parameter value, or null if not found.
*/
function getParam($param, $realm = 'default')
{
return isset($this->_params[$realm][$param]) ? $this->_params[$realm][$param] : null;
}
/**
* Setup vacation notices for a user.
*
* @param string $user The username to enable vacation notices for.
* @param string $realm The realm of the user.
* @param string $pass The password for the user.
* @param string $message The text of the vacation notice.
* @param string $alias Alias email address -- Not yet implemented in
* backends.
*
* @return boolean Returns true on success, false on error.
*/
function setVacation($user, $realm = 'default', $pass = '',
$message, $alias = '')
{
return false;
}
/**
* Disables vacation notices for a user.
*
* @param string $user The user to disable vacation notices for.
* @param string $realm The realm of the user.
* @param string $pass The password of the user.
*
* @return boolean Returns true on success, false on error.
*/
function unsetVacation($user, $realm = 'default', $pass = '')
{
return false;
}
/**
* Retrieves status of vacation for a user.
*
* @param string $user The username of the user to check.
* @param string $realm The realm of the user to check.
*
* @return boolean Returns true if vacation is enabled for the user
* or false if vacation is currently disabled.
*/
function isEnabled($user, $realm, $password)
{
// Get current details.
$current_details = $this->_getUserDetails($user, $realm, $password);
if ($current_details === false) {
return false;
}
// Check vacation flag.
if ($current_details['vacation'] == 'y' ||
$current_details['vacation'] == 'Y') {
return 'Y';
} elseif ($current_details['vacation'] == 'n' ||
$current_details['vacation'] == 'N') {
return 'N';
} else {
return false;
}
}
/**
* Retrieves current vacation message.
*
* @param string $user The username of the user.
* @param string $realm The realm of the user.
*
* @return string The current vacation message, or false if none.
*/
function currentMessage($user, $realm, $password)
{
$current_details = $this->_getUserDetails($user, $realm, $password);
// Check current vacation message.
return $current_details['message'];
}
/**
* Retrieve the current vacation details for the user.
*
* @param string $user The username for which to retrieve details.
* @param string $realm The realm (domain) for the user.
* @param string $password The password for user.
*
* @return mixed Vacation details or false.
*/
function _getUserDetails($user, $realm, $password)
{
return false;
}
/**
* Format a password using the current encryption.
*
* @param string $plaintext The plaintext password to encrypt.
*
* @return string The crypted password.
*/
function encryptPassword($plaintext)
{
return Auth::getCryptedPassword($plaintext,
'',
$this->_params['encryption'],
$this->_params['show_encryption']);
}
/**
* Parse an email address list and return it in a known standard form.
* This will attempt to add the domain (realm) to unqualified addresses
* if the realm is non-blank and not 'default'.
*
* @param string $user The email address.
* @param string $realm The domain/realm to add if none is present.
*
* @return string The email address(es) on success, false on error.
*/
function _makeEmailAddress($user, $realm)
{
$domain = ($realm != 'default') ? $realm : '';
$email = '';
if ($this->getParam('norealm', $realm)) {
$domain = '';
}
require_once 'Mail/RFC822.php';
$parser = &new Mail_RFC822();
$parsed_email = $parser->parseAddressList($user, $domain, false, false);
if (is_array($parsed_email) && count($parsed_email) > 0) {
for ($i = 0; $i < count($parsed_email); $i++) {
$email .= !empty($email) ? ',' : '';
if (is_object($parsed_email[$i])) {
$email .= $parsed_email[$i]->mailbox;
$email .= !empty($parsed_email[$i]->host)
? '@' . $parsed_email[$i]->host
: '';
} else {
$email .= $parsed_email[$i];
}
}
} else {
$this->err_str = _("Can't parse your email address");
$email = false;
}
return $email;
}
/**
* Attempts to return a concrete Vacation_Driver instance based on $driver.
*
* @param string $driver The type of concrete Vacation_Driver subclass
* to return. The is based on the vacation
* driver ($driver). The code is dynamically
* included.
*
* @param array $params A hash containing any additional
* configuration or connection parameters a
* subclass might need.
*
* @return mixed The newly created concrete Vacation_Driver instance, or
* false on an error.
*/
function &factory($driver = null, $params = null)
{
if (is_null($driver)) {
$driver = $GLOBALS['conf']['server']['driver'];
}
$driver = basename($driver);
if (is_null($params)) {
$params = Horde::getDriverConfig('server', $driver);
}
require_once dirname(__FILE__) . '/Driver/' . $driver . '.php';
$class = 'Vacation_Driver_' . $driver;
if (class_exists($class)) {
$vacation = &new $class($params);
} else {
$vacation = false;
}
return $vacation;
}
/**
* Attempts to return a reference to a concrete Vacation_Driver instance
* based on $driver. It will only create a new instance if no
* Vacation_Driver instance with the same parameters currently exists.
*
* This should be used if multiple storage sources are required.
*
* This method must be invoked as: $var = &Vacation_Driver::singleton()
*
* @param string $driver The type of concrete Vacation_Driver subclass
* to return. The is based on the vacation
* driver ($driver). The code is dynamically
* included.
*
* @param array $params A hash containing any additional
* configuration or connection parameters a
* subclass might need.
*
* @return mixed The created concrete Vacation_Driver instance, or false
* on error.
*/
function &singleton($driver = null, $params = null)
{
static $instances;
if (is_null($driver)) {
$driver = $GLOBALS['conf']['server']['driver'];
}
if (is_null($params)) {
$params = Horde::getDriverConfig('server', $driver);
}
if (!isset($instances)) {
$instances = array();
}
$signature = serialize(array($driver, $params));
if (!isset($instances[$signature])) {
$instances[$signature] = &Vacation_Driver::factory($driver, $params);
}
return $instances[$signature];
}
}
|