* as parameters and uses the return value from the hook as the new preference
* value.
*
+ * Username will be null if the user is not authenticated.
+ *
* This hook is ONLY executed on login and preferences are cached during a
* users' session.
*
class Horde_Hooks
{
// // PREFERENCES INIT: See above for documentation.
-// public function prefs_init($pref, $value, $username = null)
+// public function prefs_init($pref, $value, $username)
// {
// switch ($pref) {
// case 'from_addr':
// // address.
//
// // Example #1
-// if (is_null($name)) {
-// $name = $GLOBALS['registry']->getAuth();
+// if (is_null($username)) {
+// return $value;
// }
//
-// if (!empty($name)) {
-// $base_context = 'o=myorg';
-// $scope = 'sub';
-//
-// // You will probably need to replace cd= with uid=; this
-// // syntax is for Netware 5.1 nldap.
-// $cmd = '/usr/bin/ldapsearch -b ' . $base_context . ' -s ' . $scope . ' cn=' .
-// escapeShellCmd($GLOBALS['registry']->getAuth()) .
-// ' | /usr/bin/grep mail | /usr/bin/awk \'{print $2}\'';
-// $mails = `$cmd`;
-// $mail_array = explode("\n", $mails);
+// $base_context = 'o=myorg';
+// $scope = 'sub';
//
-// // Send back the first email found, not the whole list.
-// $mail = $mail_array['0'];
+// // You will probably need to replace cd= with uid=; this
+// // syntax is for Netware 5.1 nldap.
+// $cmd = '/usr/bin/ldapsearch -b ' . $base_context . ' -s ' . $scope . ' cn=' .
+// escapeshellcmd($username) .
+// ' | /usr/bin/grep mail | /usr/bin/awk \'{print $2}\'';
+// $mails = `$cmd`;
+// $mail_array = explode("\n", $mails);
//
-// // If no email address is found, then the login name will
-// // be used.
-// return (empty($mail) ? '' : $mail);
-// }
+// // Send back the first email found, not the whole list.
+// $mail = $mail_array['0'];
//
-// return '';
+// // If no email address is found, then the login name will
+// // be used.
+// return empty($mail)
+// ? ''
+// : $mail;
//
//
// // Example #2
+// if (is_null($username)) {
+// return $value;
+// }
+//
// $ldapServer = '172.31.0.236';
// $ldapPort = '389';
// $searchBase = 'o=myorg';
//
// $ds = @ldap_connect($ldapServer, $ldapPort);
//
-// if (is_null($name)) {
-// $name = $GLOBALS['registry']->getAuth();
-// if ($name === false) {
-// return '';
-// }
-// }
-//
// // You will probably need to replace cn= with uid=; this syntax
// // is for Netware 5.1 nldap.
-// $searchResult = @ldap_search($ds, $searchBase, 'cn=' . $name);
+// $searchResult = @ldap_search($ds, $searchBase, 'cn=' . $username);
// $information = @ldap_get_entries($ds, $searchResult);
// if (($information === false) || ($information['count'] == 0)) {
// $user = '';
//
// ldap_close($ds);
//
-// return empty($user) ? $name : $user;
+// return empty($user)
+// ? $username
+// : $user;
//
//
// case 'fullname':
//
// // Example #1: Set the fullname from the GECOS information in
// // the passwd file.
-// if (is_null($user)) {
-// $user = $GLOBALS['registry']->getAuth('bare');
-// if ($user === false) {
-// return '';
-// }
+// if (is_null($username)) {
+// return $value;
// }
//
+// $user = $GLOBALS['registry']->getAuth('bare');
+//
// $array = posix_getpwnam($user);
// $gecos_array = explode(',', $array['gecos']);
-// return empty($gecos_array) ? $user : $gecos_array[0];
+// return empty($gecos_array)
+// ? $user
+// : $gecos_array[0];
//
//
// // Example #2: Set the fullname from LDAP information. In this
// // example we look if a Spanish name exists and return this or
// // the standard 'cn' entry if not.
+// if (is_null($username)) {
+// return $value;
+// }
+//
// $ldapServer = 'ldap.example.com';
// $ldapPort = '389';
// $searchBase = 'ou=people,o=example.com';
//
// $ds = @ldap_connect($ldapServer, $ldapPort);
//
-// if (is_null($user)) {
-// $user = $GLOBALS['registry']->getAuth();
-// if ($user === false) {
-// return '';
-// }
-// }
-//
-// $searchResult = @ldap_search($ds, $searchBase, 'uid=' . $user);
+// $searchResult = @ldap_search($ds, $searchBase, 'uid=' . $username);
// $information = @ldap_get_entries($ds, $searchResult);
// if (($information === false) || ($information['count'] == 0)) {
// $name = '';
//
// ldap_close($ds);
//
-// return empty($name) ? $user : $name;
+// return empty($user)
+// ? $username
+// : $user;
//
//
// case 'theme':
-// // Example theme init. This shows how you can access things
-// // like the currently logged in user, global variables, server
-// // config, etc. It isn't, however, something you probably want
-// // to actually use in production, by virtue of demonstrating all
-// // those. :)
-// if ($GLOBALS['registry']->getAuth() != 'foo') {
+// // Example theme init.
+// if ($username != 'foo') {
// return 'mozilla';
// }
//
*
* See horde/config/hooks.php.dist for more information.
*/
-// public function prefs_init($pref, $value, $username = null)
+// public function prefs_init($pref, $value, $username)
// {
-// if (!$username) {
-// return;
-// }
-//
// switch ($pref) {
// case 'add_source':
// // Dynamically set the add_source preference.
//
-// // Example #1: Useful hook when using a Turba source with shares
+// // Example: Useful hook when using a Turba source with shares
// // enabled (i.e. the example localsql configuration).
-// return $GLOBALS['registry']->call('contacts/getDefaultShare');
+// return is_null($username)
+// ? $value
+// : $GLOBALS['registry']->call('contacts/getDefaultShare');
//
//
// case 'search_sources':
// // Example #1: Use the list of sources defined in the contacts
// // application (e.g. Turba) to populate the search_sources
// // value.
-// if ($GLOBALS['registry']->hasMethod('contacts/sources')) {
+// if (!is_null($username) &&
+// $GLOBALS['registry']->hasMethod('contacts/sources')) {
// $sources = $GLOBALS['registry']->call('contacts/sources');
// return json_encode(array_keys($sources));
// }