API16

JLDAP/search

From Joomla! Documentation

< API16:JLDAP
Revision as of 22:05, 13 May 2013 by JoomlaWikiBot (talk | contribs) (removing red link to edit, no existant pages)

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Perform an LDAP search

[<! removed edit link to red link >]

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

Syntax[edit]

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

Returns[edit]

array Multidimensional array of results public

Defined in[edit]

libraries/joomla/client/ldap.php

Importing[edit]

jimport( 'joomla.client.ldap' );

Source Body[edit]

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[edit]

<CodeExamplesForm />