Пример #1
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
 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
0
 /**
  */
 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
0
 /**
  * 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
0
 /**
  * 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');
 }
Пример #16
0
 /**
  * Return the rendered inline version of the Horde_Mime_Part object.
  *
  * @return array  See parent::render().
  */
 protected function _renderInline()
 {
     $text = Horde_String::convertCharset($this->_mimepart->getContents(), $this->_mimepart->getCharset(), 'UTF-8');
     /* Check for 'flowed' text data. */
     $data = $this->_mimepart->getContentTypeParameter('format') == 'flowed' ? $this->_formatFlowed($text, $this->_mimepart->getContentTypeParameter('delsp')) : $text;
     return $this->_renderReturn($data, 'text/html; charset=UTF-8');
 }
Пример #17
0
 /**
  * Returns the spellchecker instance.
  *
  * @param array $args    Configuration arguments to override the
  *                       defaults.
  * @param string $input  Input text.  If set, allows language detection
  *                       if not automatically set.
  *
  * @return Horde_SpellChecker  The spellchecker instance.
  * @throws Horde_Exception
  */
 public function create(array $args = array(), $input = null)
 {
     global $conf, $language, $registry;
     if (empty($conf['spell']['driver'])) {
         throw new Horde_Exception('No spellcheck driver configured.');
     }
     $args = array_merge(array('localDict' => array()), Horde::getDriverConfig('spell', null), $args);
     if (empty($args['locale'])) {
         if (!is_null($input)) {
             try {
                 $args['locale'] = $this->_injector->getInstance('Horde_Core_Factory_LanguageDetect')->getLanguageCode($input);
             } catch (Horde_Exception $e) {
             }
         }
         if (empty($args['locale']) && isset($language)) {
             $args['locale'] = $language;
         }
     }
     /* Add local dictionary words. */
     try {
         $args['localDict'] = array_merge($args['localDict'], $registry->loadConfigFile('spelling.php', 'ignore_list', 'horde')->config['ignore_list']);
     } catch (Horde_Exception $e) {
     }
     $classname = 'Horde_SpellChecker_' . Horde_String::ucfirst(basename($conf['spell']['driver']));
     if (!class_exists($classname)) {
         throw new Horde_Exception('Spellcheck driver does not exist.');
     }
     return new $classname($args);
 }
Пример #18
0
 /**
  *
  * @throws Horde_Mime_Exception
  */
 protected function _setValue($value)
 {
     /* @todo Implement with traits */
     $rfc822 = new Horde_Mail_Rfc822();
     try {
         $addr_list = $rfc822->parseAddressList($value);
     } catch (Horde_Mail_Exception $e) {
         throw new Horde_Mime_Exception($e);
     }
     foreach ($addr_list as $ob) {
         if ($ob instanceof Horde_Mail_Rfc822_Group) {
             $ob->groupname = $this->_sanityCheck($ob->groupname);
         } else {
             $ob->personal = $this->_sanityCheck($ob->personal);
         }
     }
     switch (Horde_String::lower($this->name)) {
         case 'bcc':
         case 'cc':
         case 'from':
         case 'to':
             /* Catch malformed undisclosed-recipients entries. */
             if (count($addr_list) == 1 && preg_match("/^\\s*undisclosed-recipients:?\\s*\$/i", $addr_list[0]->bare_address)) {
                 $addr_list = new Horde_Mail_Rfc822_List('undisclosed-recipients:;');
             }
             break;
     }
     if ($this->append_addr && $this->_values) {
         $this->_values->add($addr_list);
     } else {
         $this->_values = $addr_list;
     }
 }
Пример #19
0
 /**
  */
 public function configSpecialValues($what)
 {
     switch ($what) {
         case 'apps':
             $apps = Horde_Array::valuesToKeys($GLOBALS['registry']->listApps(array('active')));
             asort($apps);
             return $apps;
         case 'languages':
             $convert_numeric = function ($num) {
                 return Horde_String::convertCharset(pack('H*', $num[1]), 'ucs-2', 'UTF-8');
             };
             $convert_symbolic = function ($symbol) {
                 return Horde_String::convertCharset(html_entity_decode($symbol[1], ENT_COMPAT, 'iso-8859-1'), 'iso-8859-1', 'UTF-8');
             };
             return array_map(function ($val) {
                 return preg_replace_callback(array('/&#x([0-9a-f]{4});/i', '/(&[^;]+;)/'), array($convert_numeric, $convert_symbolic), $val);
             }, $GLOBALS['registry']->nlsconfig->languages);
         case 'blocks':
             return $GLOBALS['injector']->getInstance('Horde_Core_Factory_BlockCollection')->create()->getBlocksList();
         case 'mapsources':
             return array('Google' => 'Google', 'Bing' => 'Bing', 'Cloudmade' => 'CloudMade', 'Mytopo' => 'MyTopo', 'Osm' => 'OpenStreetMap', 'Ocm' => 'OpenCycleMap', 'Mapquest' => 'OpenMapquest');
         case 'geocoders':
             return array('None' => null, 'Google' => 'Google');
     }
 }
Пример #20
0
 /**
  * Return the rendered information about the Horde_Mime_Part object.
  *
  * @return array  See parent::render().
  * @throws Horde_Exception
  */
 protected function _renderInfo()
 {
     $charset = $this->getConfigParam('charset');
     $contents = $this->_mimepart->getContents();
     if (!$this->getConfigParam('zip')) {
         $this->setConfigParam('zip', Horde_Compress::factory('Zip'));
     }
     $zipInfo = $this->getConfigParam('zip')->decompress($contents, array('action' => Horde_Compress_Zip::ZIP_LIST));
     $fileCount = count($zipInfo);
     $name = $this->_mimepart->getName(true);
     if (empty($name)) {
         $name = Horde_Mime_Viewer_Translation::t("unnamed");
     }
     $monospace = $this->getConfigParam('monospace');
     $text = '<table><tr><td align="left"><span ' . ($monospace ? 'class="' . $monospace . '">' : 'style="font-family:monospace">') . $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive Name") . ': ' . $name . "\n" . Horde_Mime_Viewer_Translation::t("Archive File Size") . ': ' . strlen($contents) . " bytes\n" . sprintf(Horde_Mime_Viewer_Translation::ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount) . "\n\n" . str_repeat(' ', 15) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Attributes"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Size"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Modified Date"), 19, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Method"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Ratio"), 10, ' ', STR_PAD_LEFT) . "\n", 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . str_repeat('-', 74) . "\n";
     foreach ($zipInfo as $key => $val) {
         $ratio = empty($val['size']) ? 0 : 100 * ($val['csize'] / $val['size']);
         $val['name'] = Horde_String::pad(Horde_String::truncate($val['name'], 15), 15, ' ', STR_PAD_RIGHT);
         $val['attr'] = Horde_String::pad($val['attr'], 10, ' ', STR_PAD_LEFT);
         $val['size'] = Horde_String::pad($val['size'], 10, ' ', STR_PAD_LEFT);
         $val['date'] = Horde_String::pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT);
         $val['method'] = Horde_String::pad($val['method'], 10, ' ', STR_PAD_LEFT);
         $val['ratio'] = Horde_String::pad(sprintf("%1.1f%%", $ratio), 10, ' ', STR_PAD_LEFT);
         reset($val);
         while (list($k, $v) = each($val)) {
             $val[$k] = $this->_textFilter($v, 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true));
         }
         if (!is_null($this->_callback)) {
             $val = call_user_func($this->_callback, $key, $val);
         }
         $text .= $val['name'] . $val['attr'] . $val['size'] . $val['date'] . $val['method'] . $val['ratio'] . "\n";
     }
     return $this->_renderReturn(nl2br($text . str_repeat('-', 74) . "\n</span></td></tr></table>"), 'text/html; charset=' . $charset);
 }
Пример #21
0
 /**
  * Return a Nag_Tasklists instance.
  *
  * @return Nag_Tasklists
  */
 public function create()
 {
     if (!isset($GLOBALS['conf']['tasklists']['driver'])) {
         $driver = 'Default';
     } else {
         $driver = Horde_String::ucfirst($GLOBALS['conf']['tasklists']['driver']);
     }
     if (empty($this->_instances[$driver])) {
         $class = 'Nag_Tasklists_' . $driver;
         if (class_exists($class)) {
             $params = array();
             if (!empty($GLOBALS['conf']['share']['auto_create'])) {
                 $params['auto_create'] = true;
             }
             switch ($driver) {
                 case 'Default':
                     $params['identity'] = $this->_injector->getInstance('Horde_Core_Factory_Identity')->create();
                     break;
             }
             $this->_instances[$driver] = new $class($GLOBALS['nag_shares'], $GLOBALS['registry']->getAuth(), $params);
         } else {
             throw new Nag_Exception(sprintf('Unable to load the definition of %s.', $class));
         }
     }
     return $this->_instances[$driver];
 }
Пример #22
0
 /**
  * Gets the driver/params for a given base Horde_Text_Filter driver.
  *
  * @param string $driver  Either a driver name, or the full class name to
  *                        use.
  * @param array $params   A hash containing any additional configuration
  *                        parameters a subclass might need.
  *
  * @return array  Driver as the first value, params list as the second.
  */
 protected function _getDriver($driver, $params)
 {
     $lc_driver = Horde_String::lower($driver);
     switch ($lc_driver) {
         case 'bbcode':
             $driver = 'Horde_Core_Text_Filter_Bbcode';
             break;
         case 'emails':
             $driver = 'Horde_Core_Text_Filter_Emails';
             break;
         case 'emoticons':
             $driver = 'Horde_Core_Text_Filter_Emoticons';
             break;
         case 'highlightquotes':
             $driver = 'Horde_Core_Text_Filter_Highlightquotes';
             break;
         case 'linkurls':
             if (!isset($params['callback'])) {
                 $params['callback'] = 'Horde::externalUrl';
             }
             break;
         case 'text2html':
             $param_copy = $params;
             foreach (array('emails', 'linkurls', 'space2html') as $val) {
                 if (!isset($params[$val])) {
                     $tmp = $this->_getDriver($val, $param_copy);
                     $params[$val] = array($tmp[0] => $tmp[1]);
                 }
             }
             break;
     }
     return array($driver, $params);
 }
Пример #23
0
 public function create(Horde_Injector $injector)
 {
     $driver = Horde_String::ucfirst($GLOBALS['conf']['group']['driver']);
     $params = Horde::getDriverConfig('group', $driver);
     if (!empty($GLOBALS['conf']['group']['cache'])) {
         $params['cache'] = $injector->getInstance('Horde_Cache');
     }
     switch ($driver) {
         case 'Contactlists':
             $class = 'Horde_Group_Contactlists';
             $params['api'] = $GLOBALS['registry']->contacts;
             break;
         case 'Kolab':
             $class = 'Horde_Group_Kolab';
             $params['ldap'] = $injector->getInstance('Horde_Core_Factory_Ldap')->create('horde', 'group');
             break;
         case 'Ldap':
             $class = 'Horde_Core_Group_Ldap';
             $params['ldap'] = $injector->getInstance('Horde_Core_Factory_Ldap')->create('horde', 'group');
             break;
         case 'Sql':
             $class = 'Horde_Group_Sql';
             $params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'group');
             break;
         default:
             $class = $this->_getDriverName($driver, 'Horde_Group');
             break;
     }
     return new $class($params);
 }
Пример #24
0
 /**
  */
 protected function _setValue($value)
 {
     parent::_setValue(trim($value));
     $val = $this->value;
     $encoding = Horde_String::lower($val);
     switch ($encoding) {
         case '7bit':
         case '8bit':
         case 'base64':
         case 'binary':
         case 'quoted-printable':
             // Valid encodings
             break;
         default:
             /* RFC 2045 [6.3] - Valid non-standardized encodings must begin
              * with 'x-'. */
             if (substr($encoding, 0, 2) !== 'x-') {
                 $encoding = self::UNKNOWN_ENCODING;
             }
             break;
     }
     if ($encoding !== $val) {
         parent::_setValue($encoding);
     }
 }
Пример #25
0
 /**
  * Constructor.
  *
  * @param array $vars  Any required parameters.
  */
 public function __construct($vars = array())
 {
     $this->_vars['folder'] = isset($vars['folder']) ? $vars['folder'] : '';
     if (empty($vars['utf8'])) {
         $this->_vars['folder'] = Horde_String::convertCharset($this->_vars['folder'], 'UTF-8', 'UTF7-IMAP');
     }
 }
Пример #26
0
 /**
  * @return Horde_Core_History
  * @throws Horde_Exception
  */
 public function create(Horde_Injector $injector)
 {
     global $conf;
     // For BC, default to 'Sql' driver.
     $driver = empty($conf['history']['driver']) ? 'Sql' : $conf['history']['driver'];
     $history = null;
     $user = $injector->getInstance('Horde_Registry')->getAuth();
     switch (Horde_String::lower($driver)) {
         case 'nosql':
             $nosql = $injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'history');
             if ($nosql instanceof Horde_History_Mongo) {
                 $history = new Horde_History_Mongo($user, array('mongo_db' => $nosql));
             }
             break;
         case 'sql':
             try {
                 $history = new Horde_History_Sql($user, $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'history'));
             } catch (Exception $e) {
             }
             break;
     }
     if (is_null($history)) {
         $history = new Horde_History_Null($user);
     } elseif ($cache = $injector->getInstance('Horde_Cache')) {
         $history->setCache($cache);
         $history = new Horde_Core_History($history);
     }
     return $history;
 }
Пример #27
0
 public function skip($ob)
 {
     $name = Turba::formatName($ob, $this->_format);
     if ($this->_alpha != '*' && Horde_String::lower(substr($name, 0, 1)) != $this->_alpha) {
         return true;
     }
     return false;
 }
Пример #28
0
 /**
  */
 protected function _setSimplifiedType()
 {
     if (Horde_String::lower($this->_sqlType) == 'number' && $this->_precision == 1) {
         $this->_type = 'boolean';
         return;
     }
     parent::_setSimplifiedType();
 }
Пример #29
0
 /**
  * Attempts to return a concrete instance based on $driver.
  *
  * @deprecated
  *
  * @param mixed $driver  The type of concrete subclass to return. This
  *                       is based on the storage driver ($driver). The
  *                       code is dynamically included.
  * @param array $params  A hash containing any additional configuration or
  *                       connection parameters a subclass might need.
  *
  * @return VFS  The newly created concrete VFS instance.
  * @throws Horde_Vfs_Exception
  */
 public static function factory($driver, $params = array())
 {
     $class = 'Horde_Vfs_' . basename(Horde_String::ucfirst($driver));
     if (class_exists($class)) {
         return new $class($params);
     }
     throw new Horde_Vfs_Exception('Class definition of ' . $class . ' not found.');
 }
Пример #30
0
 public function testBug9992()
 {
     $text = base64_decode('dGVzdDogtbno6bvtu+nt/eHpu7797Txicj4K');
     $expected = '<p>test: ľščéťíťéíýáéťžýí<br/></p>';
     $dom = new Horde_Domhtml($text, 'iso-8859-2');
     $this->assertEquals(Horde_String::convertCharset($expected, 'UTF-8', 'iso-8859-2'), strtr(trim($dom->returnBody()), array("\n" => '')));
     $this->assertEquals('UTF-8', $dom->getCharset());
 }