[imp] Hooks for search_sources/search_fields

Marco falon at csi.it
Thu Jun 9 10:18:40 UTC 2011


Jan Schneider <jan <at> horde.org> writes:

> The search_fields preference expects a json-encoded array. Just pass  
> $out through json_encode().
> 
> Jan.

I already encoded it, my hook is:

     public function prefs_init($pref, $value, $username, $scope_ob)
    {
        switch ($pref) {
        case 'add_source':
            // Dynamically set the add_source preference.
            return is_null($username)
                ? $value
                : $GLOBALS['registry']->call('contacts/getDefaultShare');

        case 'search_fields':
        case 'search_sources':
            // Dynamically set the search_fields/search_sources preferences.
            if (!is_null($username)) {
                $sources = $GLOBALS['registry']->call('contacts/sources');

                if ($pref == 'search_fields') {
                    $out = array();
                    foreach (array_keys($sources) as $source) {
                        foreach ($GLOBALS['registry']->call('contacts/fields',
array($source)) as $field)
                           if ($field['search']) $out[$source][] = 
$field['name'];
                    }
                } else {
                    $out = array_keys($sources);
                }

                return json_encode($out);
            }

            return $value;
        }
    }

It seems that with this:
{"939e0d883993d2a7a36e0b4bc68d3bbe":["name","email"],"localldap":
["name","email"]}

autocomplete doesn't work: no search has done.

Into web IMP addressbook preferences I see my addressbooks on right panel with
only "name" and "email" selected, as desired.

Autocomplete during "compose" mail works only if I leave default hook with this
result:

{"939e0d883993d2a7a36e0b4bc68d3bbe":
["firstname","lastname","middlenames","namePrefix","nameSuffix","name","alias",
"birthday","photo","phototype","homeStreet","homePOBox","homeCity",
"homeProvince","homePostalCode","homeCountry","homeAddress","workStreet",
"workPOBox","workCity","workProvince","workPostalCode","workCountry",
"workAddress","timezone","email","homePhone","workPhone","cellPhone","fax",
"pager","title","role","company","logo","logotype","category","notes","website"
,"freebusyUrl","pgpPublicKey","smimePublicKey"],"localldap":
["name","email","firstname","lastname","freebusyUrl"]}

(but in web preferences address book have still have only "name" and "email"
selected, ...I'm confused)

Many thanks
Marco




More information about the imp mailing list