[Svn] r2293 - in branches/devel-api: plugins plugins/new_user_identity program/include

trac at roundcube.net trac at roundcube.net
Fri Feb 13 17:50:06 CET 2009


Author: ksteinhoff
Date: 2009-02-13 10:50:05 -0600 (Fri, 13 Feb 2009)
New Revision: 2293

Added:
   branches/devel-api/plugins/new_user_identity/
   branches/devel-api/plugins/new_user_identity/new_user_identity.php
Modified:
   branches/devel-api/program/include/rcube_user.php
Log:
New plugin hook: "create_user" which allows modification of $user_name and $user_email
New plugin: "new_user_identity" Populates a new user's default identity from LDAP on their first visit.


Added: branches/devel-api/plugins/new_user_identity/new_user_identity.php
===================================================================
--- branches/devel-api/plugins/new_user_identity/new_user_identity.php	                        (rev 0)
+++ branches/devel-api/plugins/new_user_identity/new_user_identity.php	2009-02-13 16:50:05 UTC (rev 2293)
@@ -0,0 +1,49 @@
+<?php
+/**
+ * New user identity
+ *
+ * Populates a new user's default identity from LDAP on their first visit.
+ *
+ * This plugin requires that a working public_ldap directory be configured.
+ *
+ * @version 1.0
+ * @author Kris Steinhoff
+ *
+ * Example configuration:
+ *
+ *  // The id of the address book to use to automatically set a new
+ *  // user's full name in their new identity. (This should be an
+ *  // string, which refers to the $rcmail_config['ldap_public'] array.)
+ *  $rcmail_config['new_user_identity_addressbook'] = 'People';
+ *  
+ *  // When automatically setting a new users's full name in their
+ *  // new identity, match the user's login name against this field.
+ *  $rcmail_config['new_user_identity_match'] = 'uid';
+ *  
+ *  // Use the value in this field to automatically set a new users's
+ *  // full name in their new identity.
+ *  $rcmail_config['new_user_identity_field'] = 'name';
+ */
+class new_user_identity extends rcube_plugin
+{
+    function init()
+    {
+        $this->add_hook('create_user', array($this, 'lookup_user_name'));
+    }
+
+    function lookup_user_name($args)
+    {
+        $rcmail = rcmail::get_instance();
+        if ($addressbook = $rcmail->config->get('new_user_identity_addressbook')) {
+            $match = $rcmail->config->get('new_user_identity_match');
+            $ldap = $rcmail->get_address_book($addressbook);
+            $ldap->prop['search_fields'] = array($match);
+            $results = $ldap->search($match, $args['user'], TRUE);
+            if (count($results->records) == 1) {
+                $args['user_name'] = $results->records[0][$rcmail->config->get('new_user_identity_field')];
+            }
+        }
+        return $args;
+    }
+}
+?>

Modified: branches/devel-api/program/include/rcube_user.php
===================================================================
--- branches/devel-api/program/include/rcube_user.php	2009-02-13 14:27:20 UTC (rev 2292)
+++ branches/devel-api/program/include/rcube_user.php	2009-02-13 16:50:05 UTC (rev 2293)
@@ -346,13 +346,20 @@
    */
   static function create($user, $host)
   {
+    $user_name  = '';
     $user_email = '';
     $rcmail = rcmail::get_instance();
+
+    $data = rcmail::get_instance()->plugins->exec_hook('create_user', array('RCMAIL'=>$rcmail, 'user'=>$user, 'user_name'=>$user_name, 'user_email'=>$user_email));
+    $user_name = $data['user_name'];
+    $user_email = $data['user_email'];
+
     $dbh = $rcmail->get_dbh();
 
     // try to resolve user in virtusertable
-    if ($rcmail->config->get('virtuser_file') && !strpos($user, '@'))
+    if ($user_email != '' && $rcmail->config->get('virtuser_file') && !strpos($user, '@')) {
       $user_email = rcube_user::user2email($user);
+    }
 
     $dbh->query(
       "INSERT INTO ".get_table_name('users')."
@@ -370,7 +377,9 @@
       if ($user_email=='')
         $user_email = strpos($user, '@') ? $user : sprintf('%s@%s', $user, $mail_domain);
 
-      $user_name = $user != $user_email ? $user : '';
+      if ($user_name == '') {
+        $user_name = $user != $user_email ? $user : '';
+      }
 
       // try to resolve the e-mail address from the virtuser table
       if (($virtuser_query = $rcmail->config->get('virtuser_query'))

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list