/** * Constructor. * * @param string $text The text of the HTML document. * @param string $charset The charset of the HTML document. * * @throws Exception */ public function __construct($text, $charset = null) { if (!extension_loaded('dom')) { throw new Exception('DOM extension is not available.'); } // Bug #9616: Make sure we have valid HTML input. if (!strlen($text)) { $text = '<html></html>'; } $old_error = libxml_use_internal_errors(true); $doc = new DOMDocument(); if (is_null($charset)) { /* If no charset given, charset is whatever libxml tells us the * encoding should be defaulting to 'iso-8859-1'. */ $doc->loadHTML($text); $this->_origCharset = $doc->encoding ? $doc->encoding : 'iso-8859-1'; } else { /* Convert/try with UTF-8 first. */ $this->_origCharset = Horde_String::lower($charset); $this->_xmlencoding = '<?xml encoding="UTF-8"?>'; $doc->loadHTML($this->_xmlencoding . Horde_String::convertCharset($text, $charset, 'UTF-8')); if ($doc->encoding && Horde_String::lower($doc->encoding) != 'utf-8') { /* Convert charset to what the HTML document says it SHOULD * be. */ $doc->loadHTML(Horde_String::convertCharset($text, $charset, $doc->encoding)); $this->_xmlencoding = ''; } } if ($old_error) { libxml_use_internal_errors(false); } $this->dom = $doc; }
/** * 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; }
/** */ 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; }
/** * 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))); }
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); }
/** */ 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); } }
/** * 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); }
/** * * @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; } }
/** * @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; }
/** * 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; }
/** * 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]; } } }
/** * 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; }
/** * 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; }
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); }
/** */ protected function _setSimplifiedType() { if (Horde_String::lower($this->_sqlType) == 'number' && $this->_precision == 1) { $this->_type = 'boolean'; return; } parent::_setSimplifiedType(); }
/** * Constructor. * * @param array $params Parameters specific to this driver: * <ul> * <li>charset: (string) The charset to use for htmlspecialchars() * calls.</li> * <li>class: (string) See Horde_Text_Filter_Linkurls::.</li> * <li>emails: (array) TODO</li> * <li>flowed: (string) For flowed text, the HTML blockquote tag to * insert before each level. * <li>linkurls: (array) TODO</li> * <li>parselevel: (integer) The parselevel of the output. * <ul> * <li>PASSTHRU: No action. Pass-through. Included for * completeness.</li> * <li>SYNTAX: Allow full html, also do line-breaks, in-lining, * syntax-parsing.</li> * <li>MICRO: Micro html (only line-breaks, in-line linking).</li> * <li>MICRO_LINKURL: Micro html (only line-breaks, in-line linking of * URLS; no email addresses are linked).</li> * <li>NOHTML: No html (all stripped, only line-breaks).</li> * <li>NOHTML_NOBREAK: No html whatsoever, no line breaks added. * Included for completeness.</li> * </ul> * </li> * <li>space2html: (array) TODO</li> * </ul> */ public function __construct($params = array()) { parent::__construct($params); // Use ISO-8859-1 instead of US-ASCII if (Horde_String::lower($this->_params['charset']) == 'us-ascii') { $this->_params['charset'] = 'iso-8859-1'; } }
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; }
function __construct($vars, $title = '', $name = null) { if (empty($name)) { $name = Horde_String::lower(get_class($this)); } $this->_vars =& $vars; $this->_title = $title; $this->_name = $name; }
/** * Used to figure out which Sieve server the script will be run * on, and then open a GSSAPI authenticated socket to said server. * * @param string $username The username. * @param string $password The password. * @param string $hostspec The hostspec. * * @return TODO * @throws Ingo_Exception */ public function sivtestSocket($username, $password, $hostspec) { $command = ''; $error_return = null; if (Horde_String::lower($this->_params['logintype']) == 'gssapi' && isset($_SERVER['KRB5CCNAME'])) { $command .= 'KRB5CCNAME=' . $_SERVER['KRB5CCNAME'] . ' '; } $domain_socket = 'unix://' . $this->_params['socket']; $command .= $this->_params['command'] . ' -m ' . $this->_params['logintype'] . ' -u ' . $username . ' -a ' . $username . ' -w ' . $password . ' -p ' . $this->_params['port'] . ' -X ' . $this->_params['socket'] . ' ' . $hostspec; $conn_attempts = 0; while ($conn_attempts++ < 4) { $attempts = 0; if (!file_exists($this->_params['socket'])) { exec($command . ' > /dev/null 2>&1'); sleep(1); while (!file_exists($this->_params['socket'])) { usleep(200000); if ($attempts++ > 5) { $error_return = _("No socket after 10 seconds of trying"); continue 2; } } } try { $socket = new \Horde\Socket\Client($domain_socket, 0, 30); } catch (Horde_Exception $error_return) { break; } // We failed, break this connection. unlink($this->_params['socket']); } if ($error_return) { throw new Ingo_Exception($error_return); } try { $status = $socket->getStatus(); if ($status['eof']) { throw new Ingo_Exception(_("Failed to write to socket: (connection lost!)")); } $socket->write("CAPABILITY\r\n"); } catch (Horde_Exception $e) { throw new Ingo_Exception(sprintf(_("Failed to write to socket:"), $e->getMessage())); } try { $result = rtrim($socket->gets(), "\r\n"); } catch (Horde_Exception $e) { throw new Ingo_Exception(sprintf(_("Failed to read from socket:"), $e->getMessage())); } $socket->close(); if (preg_match('|^bye \\(referral "(sieve://)?([^"]+)|i', $result, $matches)) { $this->sivtestSocket($username, $password, $matches[2]); } else { exec($command . ' > /dev/null 2>&1'); sleep(1); } }
/** * Preserve the internal state of the scheduler object that we are * passed, and save it to the Horde VFS backend. Horde_Scheduler * objects should define __sleep() and __wakeup() serialization * callbacks for anything that needs to be done at object * serialization or deserialization - handling database * connections, etc. * * @param string $id An id to uniquely identify this scheduler from * others of the same class. * * @return boolean Success result. */ public function serialize($id = '') { try { $vfs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create(); $vfs->writeData('.horde/scheduler', Horde_String::lower(get_class($this)) . $id, serialize($this), true); return true; } catch (Horde_Vfs_Exception $e) { Horde::log($e, 'ERR'); return false; } }
/** */ protected function _setSimplifiedType() { if (strpos(Horde_String::lower($this->_sqlType), 'tinyint(1)') !== false) { $this->_type = 'boolean'; return; } elseif (preg_match('/enum/i', $this->_sqlType)) { $this->_type = 'string'; return; } parent::_setSimplifiedType(); }
/** * Constructor. * * @param string $text The search text. * @param string $header The header field. * @param boolean $not If true, do a 'NOT' search of $text. */ public function __construct($text, $header, $not = false) { /* Data element: * h = (string) Header name (lower case). * n = (integer) Do a NOT search? * t = (string) The search text. */ $this->_data = new stdClass(); $this->_data->h = trim(Horde_String::lower($header)); $this->_data->n = intval(!empty($not)); $this->_data->t = $text; }
/** */ protected function _handleAutoCompleter($input) { $ret = array(); // For now, return all resources. $resources = Kronolith::getDriver('Resource')->listResources(Horde_Perms::READ, array(), 'name'); foreach ($resources as $r) { if (strpos(Horde_String::lower($r->get('name')), Horde_String::lower($input)) !== false) { $ret[] = array('name' => $r->get('name'), 'code' => $r->getId()); } } return $ret; }
/** * Returns the user account from the posix information. * * @return array A hash with complete account details. * * @throws Horde_Exception if posix extension is missing. */ protected function _getAccount() { if (!isset($this->_information)) { // This won't work if we don't have posix extensions. if (!Horde_Util::extensionExists('posix')) { throw new Horde_Exception(_("POSIX extension is missing")); } $user = Horde_String::lower($this->getUsername()); $this->_information = posix_getpwnam($user); } return $this->_information; }
/** * Add a header entry. * * @param string $name The name of the header entry. * @param MIME_Headers $msg_header A link to the MIME header handler. * @param array $headerarray The list of current headers. */ function _copyHeader($name, &$msg_headers, &$headerarray) { $lname = Horde_String::lower($name); if (array_key_exists($lname, $headerarray)) { if (is_array($headerarray[$lname])) { foreach ($headerarray[$lname] as $h) { $msg_headers->addHeader($name, $h); } } else { $msg_headers->addHeader($name, $headerarray[$lname]); } } }
/** * @param mixed $value Either a single language or an array of languages. */ protected function _setValue($value) { if ($value instanceof Horde_Mime_Headers_Element) { $value = $value->value; } if (!is_array($value)) { $value = array_map('trim', explode(',', $value)); } $this->_values = array(); foreach ($value as $val) { $this->_values[] = Horde_String::lower($this->_sanityCheck(Horde_Mime::decode($val))); } }
/** * Returns the user account. * * @return array A hash with complete account details. */ protected function _getAccount() { if (!isset($this->_information)) { $user = Horde_String::lower($this->getUsername()); if (!empty($this->_params['host'])) { $user .= '@' . $this->_params['host']; } $command = $this->_params['finger_path'] . ' ' . escapeshellarg($user); exec($command, $output); $this->_information = $this->_parseAccount($output); } return $this->_information; }
public function create(Horde_Injector $injector) { global $conf; if (!empty($conf['activesync']['enabled'])) { $driver = !empty($conf['activesync']['storage']) ? $conf['activesync']['storage'] : 'sql'; switch (Horde_String::lower($driver)) { case 'nosql': $nosql = $injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'activesync'); return new Horde_ActiveSync_State_Mongo(array('connection' => $nosql)); case 'sql': return new Horde_ActiveSync_State_Sql(array('db' => $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'activesync'))); } } throw new Horde_Exception('ActiveSync is disabled.'); }
function test_getAlpha_renders_filtered_items() { $this->callView_List('getAlpha', $numDisplayed, 'j'); $count = 0; foreach ($this->_sortedByLastname as $name) { if (Horde_String::lower($name[0]) == 'j') { $this->assertWantedPattern('/' . preg_quote($name, '/') . '/', $this->_output); $count++; } else { $this->assertNoUnwantedPattern('/' . preg_quote($name, '/') . '/', $this->_output); } } $this->assertEqual($count, $numDisplayed); $this->assertNotEqual(0, $count); }
/** * Attempts to return a concrete instance based on $driver. * * @return Horde_Perms The newly created concrete instance. * @throws Horde_Exception */ public function create(Horde_Injector $injector) { global $conf; $driver = empty($conf['perms']['driver']) ? 'null' : $conf['perms']['driver']; $params = isset($conf['perms']) ? Horde::getDriverConfig('perms', $driver) : array(); switch (Horde_String::lower($driver)) { case 'sql': $params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'perms'); break; } $params['cache'] = new Horde_Cache(new Horde_Cache_Storage_Stack(array('stack' => array(new Horde_Cache_Storage_Memory(), $injector->getInstance('Horde_Cache'))))); $params['logger'] = $injector->getInstance('Horde_Log_Logger'); $class = $this->_getDriverName($driver, 'Horde_Perms'); return new $class($params); }