本文整理汇总了PHP中Horde_String类的典型用法代码示例。如果您正苦于以下问题:PHP Horde_String类的具体用法?PHP Horde_String怎么用?PHP Horde_String使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Horde_String类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getId
/**
* Return the Gravatar ID for the specified mail address.
*
* @param string $mail The mail address.
*
* @return string The Gravatar ID.
*/
public function getId($mail)
{
if (!is_string($mail)) {
throw new InvalidArgumentException('The mail address must be a string!');
}
return md5(Horde_String::lower(trim($mail)));
}
示例2: create
/**
* Factory for a log object. Attempts to create a device specific file if
* custom logging is requested.
*
* @param array $properties The property array.
*
* @return Horde_Log_Logger The logger object, correctly configured.
*/
public function create($properties = array())
{
global $conf;
$logger = false;
if ($conf['activesync']['logging']['type'] == 'onefile') {
if (!empty($properties['DeviceId'])) {
$device_id = $properties['DeviceId'];
$format = "%timestamp% {$device_id} %levelName%: %message%" . PHP_EOL;
$formatter = new Horde_Log_Formatter_Simple(array('format' => $format));
$stream = fopen($conf['activesync']['logging']['path'], 'a');
if ($stream) {
$logger = new Horde_Log_Logger(new Horde_Log_Handler_Stream($stream, false, $formatter));
}
}
} elseif ($conf['activesync']['logging']['type'] == 'perdevice') {
if (!empty($properties['DeviceId'])) {
$stream = fopen($conf['activesync']['logging']['path'] . '/' . Horde_String::upper($properties['DeviceId']) . '.txt', 'a');
if ($stream) {
$logger = new Horde_Log_Logger(new Horde_Log_Handler_Stream($stream));
}
}
}
if (!$logger) {
$logger = new Horde_Log_Logger(new Horde_Log_Handler_Null());
}
return $logger;
}
示例3: auth
/**
* Attempt to do LMTP authentication.
*
* @param string The userid to authenticate as.
* @param string The password to authenticate with.
* @param string The requested authentication method. If none is
* specified, the best supported method will be used.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access public
*/
function auth($uid, $pwd, $method = '')
{
if (!isset($this->_esmtp['STARTTLS'])) {
return PEAR::raiseError('LMTP server does not support authentication');
}
if (PEAR::isError($result = $this->_put('STARTTLS'))) {
return $result;
}
if (PEAR::isError($result = $this->_parseResponse(220))) {
return $result;
}
if (PEAR::isError($result = $this->_socket->enableCrypto(true, STREAM_CRYPTO_METHOD_TLS_CLIENT))) {
return $result;
} elseif ($result !== true) {
return PEAR::raiseError('STARTTLS failed');
}
/* Send LHLO again to recieve the AUTH string from the LMTP server. */
$this->_negotiate();
if (empty($this->_esmtp['AUTH'])) {
return PEAR::raiseError('LMTP server does not support authentication');
}
/*
* If no method has been specified, get the name of the best supported
* method advertised by the LMTP server.
*/
if (empty($method) || $method === true) {
if (PEAR::isError($method = $this->_getBestAuthMethod())) {
/* Return the PEAR_Error object from _getBestAuthMethod(). */
return $method;
}
} else {
$method = Horde_String::upper($method);
}
switch ($method) {
case 'DIGEST-MD5':
$result = $this->_authDigest_MD5($uid, $pwd);
break;
case 'CRAM-MD5':
$result = $this->_authCRAM_MD5($uid, $pwd);
break;
case 'LOGIN':
$result = $this->_authLogin($uid, $pwd);
break;
case 'PLAIN':
$result = $this->_authPlain($uid, $pwd);
break;
default:
$result = new PEAR_Error("{$method} is not a supported authentication method");
break;
}
/* If an error was encountered, return the PEAR_Error object. */
if (PEAR::isError($result)) {
return $result;
}
/* RFC-2554 requires us to re-negotiate ESMTP after an AUTH. */
if (PEAR::isError($error = $this->_negotiate())) {
return $error;
}
return true;
}
示例4: verifyIdentity
/**
* Sends a message to an email address supposed to be added to the
* identity.
*
* A message is send to this address containing a time-sensitive link to
* confirm that the address really belongs to that user.
*
* @param integer $id The identity's ID.
* @param string $old_addr The old From: address.
*
* @throws Horde_Mime_Exception
*/
public function verifyIdentity($id, $old_addr)
{
global $injector, $notification, $registry;
$hash = strval(new Horde_Support_Randomid());
$pref = $this->_confirmEmail();
$pref[$hash] = $this->get($id);
$pref[$hash][self::EXPIRE] = time() + self::EXPIRE_SECS;
$this->_confirmEmail($pref);
$new_addr = $this->getValue($this->_prefnames['from_addr'], $id);
$confirm = Horde::url($registry->getServiceLink('emailconfirm')->add('h', $hash)->setRaw(true), true);
$message = sprintf(Horde_Core_Translation::t("You have requested to add the email address \"%s\" to the list of your personal email addresses.\n\nGo to the following link to confirm that this is really your address:\n%s\n\nIf you don't know what this message means, you can delete it."), $new_addr, $confirm);
$msg_headers = new Horde_Mime_Headers();
$msg_headers->addHeaderOb(Horde_Mime_Headers_MessageId::create());
$msg_headers->addHeaderOb(Horde_Mime_Headers_UserAgent::create());
$msg_headers->addHeaderOb(Horde_Mime_Headers_Date::create());
$msg_headers->addHeader('To', $new_addr);
$msg_headers->addHeader('From', $old_addr);
$msg_headers->addHeader('Subject', Horde_Core_Translation::t("Confirm new email address"));
$body = new Horde_Mime_Part();
$body->setType('text/plain');
$body->setContents(Horde_String::wrap($message, 76));
$body->setCharset('UTF-8');
$body->send($new_addr, $msg_headers, $injector->getInstance('Horde_Mail'));
$notification->push(sprintf(Horde_Core_Translation::t("A message has been sent to \"%s\" to verify that this is really your address. The new email address is activated as soon as you confirm this message."), $new_addr), 'horde.message');
}
示例5: getConfig
/**
* Returns the VFS driver parameters for the specified backend.
*
* @param string $name The VFS system name being used.
*
* @return array A hash with the VFS parameters; the VFS driver in 'type'
* and the connection parameters in 'params'.
* @throws Horde_Exception
*/
public function getConfig($name = 'horde')
{
global $conf;
if ($name !== 'horde' && !isset($conf[$name]['type'])) {
throw new Horde_Exception(Horde_Core_Translation::t("You must configure a VFS backend."));
}
$vfs = $name == 'horde' || $conf[$name]['type'] == 'horde' ? $conf['vfs'] : $conf[$name];
switch (Horde_String::lower($vfs['type'])) {
case 'none':
$vfs['params'] = array();
$vfs['type'] = 'null';
break;
case 'nosql':
$nosql = $this->_injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'vfs');
if ($nosql instanceof Horde_Mongo_Client) {
$vfs['params']['mongo_db'] = $nosql;
$vfs['type'] = 'mongo';
}
break;
case 'sql':
case 'sqlfile':
case 'musql':
$config = Horde::getDriverConfig('vfs', 'sql');
unset($config['umask'], $config['vfsroot']);
$vfs['params']['db'] = $this->_injector->getInstance('Horde_Core_Factory_Db')->create('horde', $config);
break;
}
return $vfs;
}
示例6: retrieve
/**
* Retrieves user preferences from the backend.
*
* @throws Sam_Exception
*/
public function retrieve()
{
$attrib = Horde_String::lower($this->_params['attribute']);
try {
$search = $this->_ldap->search($this->_params['basedn'], Horde_Ldap_Filter::create($this->_params['uid'], 'equals', $this->_user), array('attributes' => array($attrib)));
$entry = $search->shiftEntry();
if (!$entry) {
throw new Sam_Exception(sprintf('LDAP user "%s" not found.', $this->_user));
}
foreach ($entry->getValue($attrib, 'all') as $attribute) {
list($a, $v) = explode(' ', $attribute);
$ra = $this->_mapOptionToAttribute($a);
if (is_numeric($v)) {
if (strstr($v, '.')) {
$newoptions[$ra][] = (double) $v;
} else {
$newoptions[$ra][] = (int) $v;
}
} else {
$newoptions[$ra][] = $v;
}
}
} catch (Horde_Ldap_Exception $e) {
throw new Sam_Exception($e);
}
/* Go through new options and pull single values out of their
* arrays. */
foreach ($newoptions as $k => $v) {
if (count($v) > 1) {
$this->_options[$k] = $v;
} else {
$this->_options[$k] = $v[0];
}
}
}
示例7: toRadioButtonTag
public function toRadioButtonTag($tagValue, $options = array())
{
$options = array_merge($this->_defaultRadioOptions, $options);
$options['type'] = 'radio';
$options['value'] = $tagValue;
if (isset($options['checked'])) {
$cv = $options['checked'];
unset($options['checked']);
$checked = $cv == true || $cv == 'checked';
} else {
$checked = $this->isRadioButtonChecked($this->value($this->object()), $tagValue);
}
$options['checked'] = (bool) $checked;
$prettyTagValue = strval($tagValue);
$prettyTagValue = preg_replace('/\\s/', '_', $prettyTagValue);
$prettyTagValue = preg_replace('/\\W/', '', $prettyTagValue);
$prettyTagValue = Horde_String::lower($prettyTagValue);
if (!isset($options['id'])) {
if (isset($this->autoIndex)) {
$options['id'] = "{$this->objectName}_{$this->autoIndex}_{$this->objectProperty}_{$prettyTagValue}";
} else {
$options['id'] = "{$this->objectName}_{$this->objectProperty}_{$prettyTagValue}";
}
}
$options = $this->addDefaultNameAndId($options);
return $this->tag('input', $options);
}
示例8: factory
/**
* Attempts to return a concrete instance.
*
* @param string $renderer Either the tree renderer driver or a full
* class name to use.
* @param array $params Any additional parameters the constructor
* needs. Either 'name' or 'tree' must be
* specified. Common parameters are:
* - name: (string) The name of this tree instance.
* - tree: (Horde_Tree) An existing tree object.
* - session: (array) Callbacks used to store session data. Must define
* two keys: 'get' and 'set'. Function definitions:
* (string) = get([string - Instance], [string - ID]);
* set([string - Instance], [string - ID], [boolean - value]);
* DEFAULT: No session storage
*
* @return Horde_Tree The newly created concrete instance.
* @throws Horde_Tree_Exception
*/
public static function factory($renderer, $params = array())
{
if (!isset($params['tree']) && !isset($params['name'])) {
throw new BadFunctionCallException('Either "name" or "tree" parameters must be specified.');
}
if (isset($params['tree'])) {
$tree = $params['tree'];
unset($params['tree']);
} else {
$tree = new Horde_Tree($params['name'], isset($params['session']) ? $params['session'] : array());
unset($params['name']);
}
unset($params['session']);
$ob = null;
/* Base drivers (in Tree/ directory). */
$class = __CLASS__ . '_' . Horde_String::ucfirst($renderer);
if (class_exists($class)) {
$ob = new $class($tree, $params);
} else {
/* Explicit class name, */
$class = $renderer;
if (class_exists($class)) {
$ob = new $class($tree, $params);
}
}
if ($ob) {
if ($ob->isSupported()) {
return $ob;
}
$params['tree'] = $tree;
return self::factory($ob->fallback(), $params);
}
throw new Horde_Tree_Exception('Horde_Tree renderer not found: ' . $renderer);
}
示例9: __construct
/**
* Constructor.
*
* @throws Horde_Group_Exception
*/
public function __construct($params)
{
$params = array_merge(array('binddn' => '', 'bindpw' => '', 'gid' => 'cn', 'memberuid' => 'memberUid', 'objectclass' => array('posixGroup'), 'newgroup_objectclass' => array('posixGroup')), $params);
/* Check mandatory parameters. */
foreach (array('ldap', 'basedn') as $param) {
if (!isset($params[$param])) {
throw new Horde_Group_Exception('The \'' . $param . '\' parameter is missing.');
}
}
/* Set Horde_Ldap object. */
$this->_ldap = $params['ldap'];
unset($params['ldap']);
/* Lowercase attribute names. */
$params['gid'] = Horde_String::lower($params['gid']);
$params['memberuid'] = Horde_String::lower($params['memberuid']);
if (!is_array($params['newgroup_objectclass'])) {
$params['newgroup_objectclass'] = array($params['newgroup_objectclass']);
}
foreach ($params['newgroup_objectclass'] as &$objectClass) {
$objectClass = Horde_String::lower($objectClass);
}
/* Generate LDAP search filter. */
try {
$this->_filter = Horde_Ldap_Filter::build($params['search']);
} catch (Horde_Ldap_Exception $e) {
throw new Horde_Group_Exception($e);
}
$this->_params = $params;
}
示例10: create
/**
* Return a Horde_Alarm instance.
*
* @return Horde_Alarm
* @throws Horde_Exception
*/
public function create()
{
global $conf;
if (isset($this->_alarm)) {
return $this->_alarm;
}
$driver = empty($conf['alarms']['driver']) ? 'null' : $conf['alarms']['driver'];
$params = Horde::getDriverConfig('alarms', $driver);
switch (Horde_String::lower($driver)) {
case 'sql':
$params['db'] = $this->_injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'alarms');
break;
}
$params['logger'] = $this->_injector->getInstance('Horde_Log_Logger');
$params['loader'] = array($this, 'load');
$this->_ttl = isset($params['ttl']) ? $params['ttl'] : 300;
$class = $this->_getDriverName($driver, 'Horde_Alarm');
$this->_alarm = new $class($params);
$this->_alarm->initialize();
$this->_alarm->gc();
/* Add those handlers that need configuration and can't be auto-loaded
* through Horde_Alarms::handlers(). */
$this->_alarm->addHandler('notify', new Horde_Core_Alarm_Handler_Notify());
$this->_alarm->addHandler('desktop', new Horde_Core_Alarm_Handler_Desktop(array('icon' => new Horde_Core_Alarm_Handler_Desktop_Icon('alerts/alarm.png'), 'js_notify' => array($this->_injector->getInstance('Horde_PageOutput'), 'addInlineScript'))));
$this->_alarm->addHandler('mail', new Horde_Alarm_Handler_Mail(array('identity' => $this->_injector->getInstance('Horde_Core_Factory_Identity'), 'mail' => $this->_injector->getInstance('Horde_Mail'))));
return $this->_alarm;
}
示例11: create
/**
* Return an Kolab_Driver instance.
*
* @return Kolab_Driver
*/
public function create(Horde_Injector $injector)
{
$driver = Horde_String::ucfirst($GLOBALS['conf']['storage']['driver']);
$signature = serialize(array($driver, $GLOBALS['conf']['storage']['params']['driverconfig']));
if (empty($this->_instances[$signature])) {
switch ($driver) {
case 'Sql':
try {
if ($GLOBALS['conf']['storage']['params']['driverconfig'] == 'horde') {
$db = $injector->getInstance('Horde_Db_Adapter');
} else {
$db = $injector->getInstance('Horde_Core_Factory_Db')->create('kolab', 'storage');
}
} catch (Horde_Exception $e) {
throw new Kolab_Exception($e);
}
$params = array('db' => $db);
break;
case 'Ldap':
try {
$params = array('ldap' => $injector->getIntance('Horde_Core_Factory_Ldap')->create('kolab', 'storage'));
} catch (Horde_Exception $e) {
throw new Kolab_Exception($e);
}
break;
}
$class = 'Kolab_Driver_' . $driver;
$this->_instances[$signature] = new $class($params);
}
return $this->_instances[$signature];
}
示例12: create
public function create(Horde_Injector $injector)
{
global $conf, $session;
$driver = empty($conf['token']) ? 'null' : $conf['token']['driver'];
$params = empty($conf['token']) ? array() : Horde::getDriverConfig('token', $conf['token']['driver']);
$params['logger'] = $injector->getInstance('Horde_Log_Logger');
if (!$session->exists('horde', 'token_secret_key')) {
$session->set('horde', 'token_secret_key', strval(new Horde_Support_Randomid()));
}
$params['secret'] = $session->get('horde', 'token_secret_key');
switch (Horde_String::lower($driver)) {
case 'none':
$driver = 'null';
break;
case 'nosql':
$nosql = $injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'token');
if ($nosql instanceof Horde_Mongo_Client) {
$params['mongo_db'] = $nosql;
$driver = 'Horde_Token_Mongo';
}
break;
case 'sql':
$params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'token');
break;
}
if (isset($conf['urls']['token_lifetime'])) {
$params['token_lifetime'] = $conf['urls']['token_lifetime'] * 60;
}
$class = $this->_getDriverName($driver, 'Horde_Token');
return new $class($params);
}
示例13: registerDTD
/**
*/
public function registerDTD($publicIdentifier, $uri, $dtd)
{
$dtd->setDPI($publicIdentifier);
$publicIdentifier = Horde_String::lower($publicIdentifier);
$this->_strDTD[$publicIdentifier] = $dtd;
$this->_strDTDURI[Horde_String::lower($uri)] = $dtd;
}
示例14: execute
/**
* Renames the old sent-mail mailboxes.
*
* Mailbox name: sent-mail-month-year
* month = English: 3 letter abbreviation
* Other Languages: Month value (01-12)
* year = 4 digit year
*
* The mailbox name needs to be in this specific format (as opposed to a
* user-defined one) to ensure that 'delete_sentmail_monthly' processing
* can accurately find all the old sent-mail mailboxes.
*
* @return boolean Whether all sent-mail mailboxes were renamed.
*/
public function execute()
{
global $notification;
$date_format = substr($GLOBALS['language'], 0, 2) == 'en' ? 'M-Y' : 'm-Y';
$datetime = new DateTime();
$now = $datetime->format($date_format);
foreach ($this->_getSentmail() as $sent) {
/* Display a message to the user and rename the mailbox.
* Only do this if sent-mail mailbox currently exists. */
if ($sent->exists) {
$notification->push(sprintf(_("\"%s\" mailbox being renamed at the start of the month."), $sent->display), 'horde.message');
$query = new Horde_Imap_Client_Fetch_Query();
$query->imapDate();
$query->uid();
$imp_imap = $sent->imp_imap;
$res = $imp_imap->fetch($sent, $query);
$msgs = array();
foreach ($res as $val) {
$date_string = $val->getImapDate()->format($date_format);
if (!isset($msgs[$date_string])) {
$msgs[$date_string] = $imp_imap->getIdsOb();
}
$msgs[$date_string]->add($val->getUid());
}
unset($msgs[$now]);
foreach ($msgs as $key => $val) {
$new_mbox = IMP_Mailbox::get(strval($sent) . '-' . Horde_String::lower($key));
$imp_imap->copy($sent, $new_mbox, array('create' => true, 'ids' => $val, 'move' => true));
}
}
}
return true;
}
示例15: __construct
/**
* Constructor.
*
* @param array $config Configuration key-value pairs.
*/
public function __construct($config = array())
{
global $prefs, $registry;
parent::__construct($config);
$blank = new Horde_Url();
$this->addNewButton(_("_New Event"), $blank, array('id' => 'kronolithNewEvent'));
$this->newExtra = $blank->link(array_merge(array('id' => 'kronolithQuickEvent'), Horde::getAccessKeyAndTitle(_("Quick _insert"), false, true)));
$sidebar = $GLOBALS['injector']->createInstance('Horde_View');
/* Minical. */
$today = new Horde_Date($_SERVER['REQUEST_TIME']);
$sidebar->today = $today->format('F Y');
$sidebar->weekdays = array();
for ($i = $prefs->getValue('week_start_monday'), $c = $i + 7; $i < $c; $i++) {
$weekday = Horde_Nls::getLangInfo(constant('DAY_' . ($i % 7 + 1)));
$sidebar->weekdays[$weekday] = Horde_String::substr($weekday, 0, 2);
}
/* Calendars. */
$sidebar->newShares = $registry->getAuth() && !$prefs->isLocked('default_share');
$sidebar->admin = $registry->isAdmin();
$sidebar->resourceAdmin = $registry->isAdmin() || $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('resource_management');
$sidebar->resources = $GLOBALS['conf']['resources']['enabled'];
$sidebar->addRemote = !$prefs->isLocked('remote_cals');
$remotes = unserialize($prefs->getValue('remote_cals'));
$sidebar->showRemote = !($prefs->isLocked('remote_cals') && empty($remotes));
$this->content = $sidebar->render('dynamic/sidebar');
}