Actions

API15

JLDAP/search

From Joomla! Documentation

< API15:JLDAP
Revision as of 13:35, 12 May 2013 by JoomlaWikiBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Perform an LDAP search

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

search($filters, $dnoverride=null)
Parameter Name Default Value Description
$filters Search Filters (array of strings)
$dnoverride null DN Override

Returns

array Multidimensional array of results public

Defined in

libraries/joomla/client/ldap.php

Importing

jimport( 'joomla.client.ldap' );

Source Body

function search($filters, $dnoverride = null)
{
        $attributes = array ();
        if ($dnoverride) {
                $dn = $dnoverride;
        } else {
                $dn = $this->base_dn;
        }
 
        $resource = $this->_resource;
 
        foreach ($filters as $search_filter)
        {
                $search_result = @ldap_search($resource, $dn, $search_filter);
                if ($search_result && ($count = @ldap_count_entries($resource, $search_result)) > 0)
                {
                        for ($i = 0; $i < $count; $i++)
                        {
                                $attributes[$i] = Array ();
                                if (!$i) {
                                        $firstentry = @ldap_first_entry($resource, $search_result);
                                } else {
                                        $firstentry = @ldap_next_entry($resource, $firstentry);
                                }
                                $attributes_array = @ldap_get_attributes($resource, $firstentry); // load user-specified attributes
                                // ldap returns an array of arrays, fit this into attributes result array
                                foreach ($attributes_array as $ki => $ai)
                                {
                                        if (is_array($ai))
                                        {
                                                $subcount = $ai['count'];
                                                $attributes[$i][$ki] = Array ();
                                                for ($k = 0; $k < $subcount; $k++) {
                                                        $attributes[$i][$ki][$k] = $ai[$k];
                                                }
                                        }
                                }
                                $attributes[$i]['dn'] = @ldap_get_dn($resource, $firstentry);
                        }
                }
        }
        return $attributes;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />