[cvs] [Wiki] changed: CustomizingPreferences

Chuck Hagenbuch chuck at horde.org
Mon Jun 5 20:32:30 PDT 2006


chuck  Mon, 05 Jun 2006 20:32:30 -0700

Modified page: http://wiki.horde.org/CustomizingPreferences
New Revision:  2.2
Change log:  remove some unnecessary newlines

@@ -1,79 +1,66 @@
 [[toc]]
 
 + User Contributed Preferences
 
-Perhaps the greatest feature of Horde and all of it's modules is the flexibility to adapt to a myriad of different uses and I would
-expect that eventually, a more integrated system of managing 'defaults' will become part of the code but at this moment in
-time, the only way to effect settings system wide is to edit the various prefs.php file inside each module.
+Perhaps the greatest feature of Horde and all of it's modules is the flexibility to adapt to a myriad of different uses and I would expect that eventually, a more integrated system of managing 'defaults' will become part of the code but at this moment in time, the only way to effect settings system wide is to edit the various prefs.php file inside each module.
 
-I thought it would be interesting to share what people do to the various preferences and it would make a handy reference to
-point people towards if they ask on the various lists.
+I thought it would be interesting to share what people do to the various preferences and it would make a handy reference to point people towards if they ask on the various lists.
 
-The methodology of capturing some of these 'strings' of values is that I usually create the setup exactly how I want it for my 
-'Administrator' user and then copy the values out of the SQL database and paste them into the appropriate spot in the prefs.php file.
+The methodology of capturing some of these 'strings' of values is that I usually create the setup exactly how I want it for my  'Administrator' user and then copy the values out of the SQL database and paste them into the appropriate spot in the prefs.php file.
 
 -----
 
 +++ hooks.php
 
-I have created some hooks for capturing the users Identity and Email address to automatically set their Default identity the 
-first time that they log in. These hooks assume LDAP backend and should be instructive for someone wanting to create their
-own custom hooks...this wasn't easy to figure out.
+I have created some hooks for capturing the users Identity and Email address to automatically set their Default identity the  first time that they log in. These hooks assume LDAP backend and should be instructive for someone wanting to create their own custom hooks...this wasn't easy to figure out.
 
-The first modification I did to hooks.php was to add the following (don't forget to add the
-{{'hook' => 'true',}} to {{$prefs['from_addr']}}).
+The first modification I did to hooks.php was to add the following (don't forget to add the {{'hook' => 'true',}} to {{$prefs['from_addr']}}).
 
 <code type="php">
 if (!function_exists('_prefs_hook_from_addr')) {
+    function _prefs_hook_from_addr($user = null)
+    {
+        $domain_name = 'azapple.com';
+        $ldapServer = 'localhost';
+        $ldapPort = '389';
+        $searchBase = 'ou=People,dc=azapple,dc=com';
+        $ds = @ldap_connect($ldapServer, $ldapPort);
 
-   function _prefs_hook_from_addr($user = null)
-     {
+        if (is_null($user)) {
+            $user = Auth::getAuth();
+        }
 
-       $domain_name = 'azapple.com';
-       $ldapServer = 'localhost';
-       $ldapPort = '389';
-       $searchBase = 'ou=People,dc=azapple,dc=com';
-       $ds = @ldap_connect($ldapServer, $ldapPort);
+        $uid = Auth::getBareAuth();
+        $binddn = 'uid=' . $uid . ',' . $searchBase;
+        $bindpw = Auth::getCredential('password');
 
-       if (is_null($user)) {
-         $user = Auth::getAuth();
-       }
+        if (@ldap_bind($ds, $binddn, $bindpw)) {
+            $searchResult = @ldap_search($ds, $searchBase, 'uid=' . $uid);
+        }
 
-       $uid = Auth::getBareAuth();
-       $binddn = 'uid=' . $uid . ',' . $searchBase;
-       $bindpw = Auth::getCredential('password');
-
-       if (@ldap_bind($ds, $binddn, $bindpw)) {
-         $searchResult = @ldap_search($ds, $searchBase, 'uid=' . $uid);
-       }
-
-       $information = @ldap_get_entries($ds, $searchResult);
+        $information = @ldap_get_entries($ds, $searchResult);
 
         // derive the email address if possible
         if ($information[0]['mail'][0] != '') {
-           $emailname = $information[0]['mail'][0];
+            $emailname = $information[0]['mail'][0];
         } else {
-           $emailname = $information[0]['uid'][0] . '@' . $domain_name;
+            $emailname = $information[0]['uid'][0] . '@' . $domain_name;
         }
 
-         ldap_close($ds);
+        ldap_close($ds);
 
-         return $emailname;
-     }
+        return $emailname;
+    }
 }
 </code>
 
-The second modification I did to hooks.php was to add the following (don't forget to add the
-{{'hook' => 'true',}} to {{$prefs['fullname']}}).
+The second modification I did to hooks.php was to add the following (don't forget to add the {{'hook' => 'true',}} to {{$prefs['fullname']}}).
 
 <code type="php">
 if (!function_exists('_prefs_hook_fullname')) {
-
-
-   function _prefs_hook_fullname($user = null)
-   {
-
+    function _prefs_hook_fullname($user = null)
+    {
         $ldapServer = 'localhost';
         $ldapPort = '389';
         $searchBase = 'ou=People,dc=azapple,dc=com';
         $ds = @ldap_connect($ldapServer, $ldapPort);
@@ -93,17 +80,17 @@
         $information = @ldap_get_entries($ds, $searchResult);
 
         // derive the email address if possible
         if ($information[0]['cn'][0] != '') {
-           $name = $information[0]['cn'][0];
+            $name = $information[0]['cn'][0];
         } else {
-           $name = $information[0]['gecos'][0];
+            $name = $information[0]['gecos'][0];
         }
 
         ldap_close($ds);
 
         return $name;
-   }
+    }
 }
 </code>
 
 CW
@@ -133,11 +120,9 @@
     }
 }
 </code>
 
-I have an "events calendar" that all of my users have read-only access to.  This hook makes sure they see that calendar by default.  
-I had previously just put the pref value in prefs.php, but then a new user's default calendar would not be created and they would not 
-have a "New Event" link in their menu.  (don't forget to add the {{'hook' => 'true'}} to {{$prefs['display_cals']}}).
+I have an "events calendar" that all of my users have read-only access to.  This hook makes sure they see that calendar by default.   I had previously just put the pref value in prefs.php, but then a new user's default calendar would not be created and they would not have a "New Event" link in their menu.  (don't forget to add the {{'hook' => 'true'}} to {{$prefs['display_cals']}}).
 
 <code type="php">
 if (!function_exists('_prefs_hook_display_cals')) {
     function _prefs_hook_display_cals($uid = null)
@@ -200,57 +185,55 @@
 Here are some cleaned up hook functions, for populating from_addr and fullname:
 
 <code type="php">
 if (!function_exists('_prefs_hook_from_addr')) {
-
-   function _prefs_hook_from_addr($uid = null)
-     {
-       global $conf;
-       $domain_name = 'yourdomain'; // could also use $conf['mailer']['params']['localhost']
-       $ldapServer = 'yourdirectoryserver';
-       $ldapPort = '389';
-       $searchBase = 'yoursearchbase';
-       $ds = @ldap_connect($ldapServer, $ldapPort);
+    function _prefs_hook_from_addr($uid = null)
+    {
+        global $conf;
+        $domain_name = 'yourdomain'; // could also use $conf['mailer']['params']['localhost']
+        $ldapServer = 'yourdirectoryserver';
+        $ldapPort = '389';
+        $searchBase = 'yoursearchbase';
+        $ds = @ldap_connect($ldapServer, $ldapPort);
        
-       if (is_null($uid) {
+        if (is_null($uid) {
             $uid = Auth:getAuth();
-       }
+        }
 
-       // If your search scope is more than one, substitute ldap_search for ldap_list
-       if (@ldap_bind($ds)) {
-         $searchResult = @ldap_list($ds, $searchBase, $conf['auth']['params']['uid'] . '=' . $uid);
-       }
+        // If your search scope is more than one, substitute ldap_search for ldap_list
+        if (@ldap_bind($ds)) {
+            $searchResult = @ldap_list($ds, $searchBase, $conf['auth']['params']['uid'] . '=' . $uid);
+        }
 
-       $information = @ldap_get_entries($ds, $searchResult);
+        $information = @ldap_get_entries($ds, $searchResult);
 
         // derive the email address if possible
         if ($information[0]['mail'][0] != '') {
-           $emailname = $information[0]['mail'][0];
+            $emailname = $information[0]['mail'][0];
         } else {
-           $emailname = $information[0]['uid'][0] . '@' . $domain_name;
+            $emailname = $information[0]['uid'][0] . '@' . $domain_name;
         }
 
-         ldap_close($ds);
+        ldap_close($ds);
 
-         return $emailname;
-     }
+        return $emailname;
+    }
 }
 </code>
 
 <code type="php">
 if (!function_exists('_prefs_hook_fullname')) {
-
    function _prefs_hook_fullname($uid = null)
    {
         global $conf;
         $ldapServer = 'yourdirectoryserver';
         $ldapPort = '389';
         $searchBase = 'yoursearchbase';
         $ds = @ldap_connect($ldapServer, $ldapPort);
 
-       if (is_null($uid)) {
+        if (is_null($uid)) {
             $uid = Auth::getAuth();
-       }
+        }
 
         if (@ldap_bind($ds)) {
             $searchResult = @ldap_list($ds, $searchBase, 'uid=' . $uid);
         }
@@ -258,36 +241,27 @@
         $information = @ldap_get_entries($ds, $searchResult);
 
         // Get the cn or GECOS value; could also pull givenName + sn but that usually == cn
         if ($information[0]['cn'][0] != '') {
-           $name = $information[0]['cn'][0];
+            $name = $information[0]['cn'][0];
         } else {
-           $name = $information[0]['gecos'][0];
+            $name = $information[0]['gecos'][0];
         }
 
         ldap_close($ds);
 
         return $name;
-   }
+    }
 }
 </code>
 
 KMM
 
 -----
 
-For the environments where users are authenticated against IMAP server and all users have at least one email address 
-with the same domain name like others in the form username at domain.name, you can create a hook which adds this 
-implicit address to the default identity. This can be usefull for Horde modules like WHUPS operate with default e-mail 
-addresses of users. I didn't use preference hook for "from_addr" because what I really needed is not the default address 
-for new identities, but the value for the default identity, even when the identity already exists. From prefes hook I was unable 
-to write to other preferences (do not know why), so I created a postauthentication hook which does everything needed. 
-The only thing I have not resolved is how to tell the preferences cache to update the data immediatelly. But in the database 
-everything is stored so this resolves at the next login automatically.
+For the environments where users are authenticated against IMAP server and all users have at least one email address  with the same domain name like others in the form username at domain.name, you can create a hook which adds this implicit address to the default identity. This can be usefull for Horde modules like WHUPS operate with default e-mail addresses of users. I didn't use preference hook for "from_addr" because what I really needed is not the default address for new identities, but the value for the default identity, even when the identity already exists. From prefs hook I was unable to write to other preferences (do not know why), so I created a postauthentication hook which does everything needed. The only thing I have not resolved is how to tell the preferences cache to update the data immediatelly. But in the database everything is stored so this resolves at the next login automatically.
 
-The code works following way: if you have no default identity yet, it is created for you. If you have no e-mail address 
-in the default identity, it is stored there as a composition of your username and default domain name (more complicated 
-algorithms can be used here as well).
+The code works following way: if you have no default identity yet, it is created for you. If you have no e-mail address in the default identity, it is stored there as a composition of your username and default domain name (more complicated algorithms can be used here as well).
 
 <code type="php">
 require_once('Horde/Identity.php');
 if (!function_exists('_horde_hook_postauthenticate')) {
@@ -346,11 +320,9 @@
 -----
 
 +++ Horde
 
-I have created entries for common categories and common colors for the categories and labels. I am figuring that the entire 
-yellow->orange range is available for people to use for their own purposes and making appointment types in the blue range, 
-personal items in the green spectrum and finally the group categories in red.
+I have created entries for common categories and common colors for the categories and labels. I am figuring that the entire yellow->orange range is available for people to use for their own purposes and making appointment types in the blue range, personal items in the green spectrum and finally the group categories in red.
 
 <code type="php">
 // categories
 $_prefs['categories'] = array(
@@ -370,10 +342,9 @@
     'type' => 'implicit'
 );
 </code>
 
-Next - and certainly what I think is the most important customization of all possible, is the portal page itself...the main Horde page. This is the sizzle of the steak.
-This gets people's attention. Of course the weather is for my neck of the woods...
+Next - and certainly what I think is the most important customization of all possible, is the portal page itself...the main Horde page. This is the sizzle of the steak. This gets people's attention. Of course the weather is for my neck of the woods...
 
 <code type="php">
 // the layout of the portal page.
 $_prefs['portal_layout'] = array(
@@ -393,10 +364,9 @@
 -----
 
 +++ IMP
 
-I haven't done much with IMP but all my users have these mailboxes and I want them to be 'polled' for new mail
-when they log on to system (especially the public mail - if there is any 'unseen' mail).
+I haven't done much with IMP but all my users have these mailboxes and I want them to be 'polled' for new mail when they log on to system (especially the public mail - if there is any 'unseen' mail).
 
 <code type="php">
 // list of folders to poll for new mail
 $_prefs['nav_poll'] = array(
@@ -415,10 +385,9 @@
 -----
 
 +++ Ingo
 
-Ingo is very clever and it gives you some defaults automatically, but I want to redirect mail already tagged as spam or virus (virus removed naturally) into
-their respective folders which I have already created for them in my imap configuration. Thus, the default rules additions.
+Ingo is very clever and it gives you some defaults automatically, but I want to redirect mail already tagged as spam or virus (virus removed naturally) into their respective folders which I have already created for them in my imap configuration. Thus, the default rules additions.
 
 <code type="php">
 // filter rules
 $_prefs['rules'] = array(


More information about the cvs mailing list