/** * This can be used to escape a string to provide a valid LDAP-Filter. * * LDAP will only recognise certain characters as the * character istself if they are properly escaped. This is * what this method does. * The method can be called statically, so you can use it outside * for your own purposes (eg for escaping only parts of strings) * * In fact, this is just a shorthand to {@link Net_LDAP_Util::escape_filter_value()}. * For upward compatibiliy reasons you are strongly encouraged to use the escape * methods provided by the Net_LDAP_Util class. * * @param string $value Any string who should be escaped * * @static * @return string The string $string, but escaped * @deprecated Do not use this method anymore, instead use Net_LDAP_Util::escape_filter_value() directly */ function escape($value) { $return = Net_LDAP_Util::escape_filter_value(array($value)); return $return[0]; }
/** * Execute a LDAP query stement and fetch all results. * * @param mixed $query The SQL query as a string or an array. * @param string $configPath The config path; used for exception messages. * * @return array An array of records. * @throws XML_Query2XML_LDAPException If Net_LDAP::search() returns an error. * @see XML_Query2XML_Driver::getAllRecords() */ public function getAllRecords($query, $configPath) { $base = null; $filter = null; $options = array(); if (isset($query['base'])) { $base = $query['base']; } if (isset($query['filter'])) { $filter = $query['filter']; } if (isset($query['options'])) { $options = $query['options']; } if (isset($options['query2xml_placeholder'])) { $placeholder = $options['query2xml_placeholder']; } else { $placeholder = '?'; } unset($options['query2xml_placeholder']); if (isset($query['data']) && is_array($query['data'])) { $data = Net_LDAP_Util::escape_filter_value($query['data']); $base = self::_replacePlaceholders($base, $data, $placeholder); if (is_string($filter)) { $filter = self::_replacePlaceholders($filter, $data, $placeholder); } } $search = $this->_ldap->search($base, $filter, $options); if (PEAR::isError($search)) { /* * unit test: getXML/throwLDAPException_queryError.phpt */ throw new XML_Query2XML_LDAPException($configPath . ': Could not run LDAP search query: ' . $search->toString()); } $records = array(); $entries = $search->entries(); foreach ($entries as $key => $entry) { $records[] = $entry->getValues(); } $search->done(); $records = self::_processMultiValueAttributes($records); // set missing attriubtes to null if (isset($options['attributes']) && is_array($options['attributes'])) { foreach ($options['attributes'] as $attribute) { for ($i = 0; $i < count($records); $i++) { if (!array_key_exists($attribute, $records[$i])) { $records[$i][$attribute] = null; } } } } return $records; }