From: Andreas Gohr Date: Thu, 21 Jun 2007 13:12:57 +0000 (+0200) Subject: Dynamically decide which attributes to fetch X-Git-Tag: 0.7.1~54 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8901ca2183c08784d801280f975cfbddad6a1c2f;p=contagged Dynamically decide which attributes to fetch List views previously fetched all entry attributes, even when only a few of them where really shown. Now the template is examined first, then only needed attributes are pulled from the server. darcs-hash:20070621131257-6e07b-69f6b8bbf9d0a989620d6d54b85f5824a4a65f15.gz --- diff --git a/inc/functions.php b/inc/functions.php index 52f1016..b0c28f6 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -482,4 +482,28 @@ function utf8_encode_array(&$array) { } } +/** + * Returns all the fields used in the template + * + * Returned fields are already decoded to LDAP internals + */ +function get_fields_from_template($tpl){ + global $smarty; + global $FIELDS; + $tpl = $smarty->template_dir.'/'.$tpl; + $data = @file_get_contents($tpl); + $matches = array(); + preg_match_all('/\$entry\.(\w+)/',$data,$matches); + $matches = array_unique((array) $matches[1]); + $return = array(); + foreach($matches as $f){ + if($FIELDS[$f]){ + $return[] = $FIELDS[$f]; + }elseif($FIELDS["_$f"]){ + $return[] = $FIELDS["_$f"]; + } + } + return $return; +} + ?> diff --git a/index.php b/index.php index 58e4a6f..9eba4f0 100644 --- a/index.php +++ b/index.php @@ -3,24 +3,6 @@ require_once('inc/init.php'); ldap_login(); - //prepare filter - $ldapfilter = _makeldapfilter(); - - //check public addressbook - $sr = ldap_list($LDAP_CON,$conf['publicbook'],$ldapfilter); - $result1 = ldap_get_binentries($LDAP_CON, $sr); - //check users private addressbook - if(!empty($_SESSION['ldapab']['binddn'])){ - $sr = @ldap_list($LDAP_CON, - $conf['privatebook'].','.$_SESSION['ldapab']['binddn'], - $ldapfilter); - $result2 = ldap_get_binentries($LDAP_CON, $sr); - }else{ - $result2 = ''; - } - - $result = array_merge((array)$result1,(array)$result2); - // select entry template if(!empty($_REQUEST['export']) && $_REQUEST['export'] == 'csv'){ $entrytpl = 'list_csv_entry.tpl'; @@ -30,6 +12,16 @@ $entrytpl = 'list_entry.tpl'; } + // check which fields are needed + $fields = get_fields_from_template($entrytpl); + + + //prepare filter + $ldapfilter = _makeldapfilter(); + + // fetch results + $result = ldap_queryabooks($ldapfilter,$fields); + $list = ''; if(count($result)==1 && $_REQUEST['search']){ //only one result on a search -> display page