Changeset 2386 in subversion


Ignore:
Timestamp:
Apr 13, 2009 12:11:06 PM (4 years ago)
Author:
thomasb
Message:

Add hooks for additional address books + simple example plugin

Location:
branches/devel-api
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-api/program/include/main.inc

    r2297 r2386  
    684684 
    685685  // convert attributes to an associative array (name => value) 
    686   if ($regs) 
    687     foreach ($regs as $attr) 
    688       { 
    689       $attrib[strtolower($attr[1])] = $attr[3] . $attr[4]; 
    690       } 
     686  if ($regs) { 
     687    foreach ($regs as $attr) { 
     688      $attrib[strtolower($attr[1])] = html_entity_decode($attr[3] . $attr[4]); 
     689    } 
     690  } 
    691691 
    692692  return $attrib; 
  • branches/devel-api/program/include/rcmail.php

    r2372 r2386  
    260260    $ldap_config = (array)$this->config->get('ldap_public'); 
    261261    $abook_type = strtolower($this->config->get('address_book_type')); 
    262      
    263     if ($id && $ldap_config[$id]) { 
     262 
     263    $plugin = $this->plugins->exec_hook('get_address_book', array('id' => $id, 'writeable' => $writeable)); 
     264     
     265    // plugin returned instance of a rcube_addressbook 
     266    if ($plugin['instance'] instanceof rcube_addressbook) { 
     267      $contacts = $plugin['instance']; 
     268    } 
     269    else if ($id && $ldap_config[$id]) { 
    264270      $contacts = new rcube_ldap($ldap_config[$id]); 
     271    } 
     272    else if ($id === '0') { 
     273      $contacts = new rcube_contacts($this->db, $this->user->ID); 
    265274    } 
    266275    else if ($abook_type == 'ldap') { 
  • branches/devel-api/program/steps/addressbook/func.inc

    r1939 r2386  
    4343if (strtolower($CONFIG['address_book_type']) != 'ldap') { 
    4444  // We are using the DB address book, add it. 
    45   $js_list = array("0" => array('id' => 0, 'readonly' => false)); 
     45  $js_list['0'] = array('id' => 0, 'name' => rcube_label('personaladrbook'), 'readonly' => false); 
    4646} 
    4747if (is_array($CONFIG['ldap_public'])) { 
    4848  foreach ($CONFIG['ldap_public'] as $id => $prop) 
    49     $js_list[$id] = array('id' => $id, 'readonly' => !$prop['writable']); 
     49    $js_list[$id] = array('id' => $id, 'name' => $prop['name'], 'readonly' => !$prop['writable']); 
    5050} 
    51 $OUTPUT->set_env('address_sources', $js_list); 
     51 
     52$plugin = $RCMAIL->plugins->exec_hook('address_sources', array('sources' => $js_list)); 
     53$OUTPUT->set_env('address_sources', $plugin['sources']); 
    5254 
    5355 
    5456function rcmail_directory_list($attrib) 
    5557{ 
    56   global $CONFIG, $OUTPUT; 
     58  global $RCMAIL, $OUTPUT; 
    5759   
    5860  if (!$attrib['id']) 
     
    6466  $line_templ = html::tag('li', array('id' => 'rcmli%s', 'class' => '%s'), 
    6567    html::a(array('href' => '%s', 'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s')); 
    66      
    67   if (strtolower($CONFIG['address_book_type']) != 'ldap') { 
    68     $out .= sprintf($line_templ, $local_id, (!$current ? 'selected' : ''), 
    69       Q(rcmail_url(null, array('_source' => $local_id))), $local_id, rcube_label('personaladrbook')); 
    70   } // end if 
    71   else { 
     68 
     69  if (!$current && strtolower($RCMAIL->config->get('address_book_type', 'sql')) != 'ldap') { 
     70    $current = '0'; 
     71  } 
     72  else if (!$current) { 
    7273    // DB address book not used, see if a source is set, if not use the 
    7374    // first LDAP directory. 
    74     if (!$current) { 
    75       $current = key((array)$CONFIG['ldap_public']); 
    76     } // end if 
    77   } // end else 
    78    
    79   foreach ((array)$CONFIG['ldap_public'] as $id => $prop) { 
     75    $current = key((array)$RCMAIL->config->get('ldap_public', array())); 
     76  } 
     77 
     78  foreach ((array)$OUTPUT->env['address_sources'] as $j => $source) { 
     79    $id = $source['id'] ? $source['id'] : $j; 
    8080    $js_id = JQ($id); 
    8181    $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id); 
    8282    $out .= sprintf($line_templ, $dom_id, ($current == $id ? 'selected' : ''), 
    83       Q(rcmail_url(null, array('_source' => $id))), $js_id, (!empty($prop['name']) ? Q($prop['name']) : Q($id))); 
    84   } 
    85    
     83      Q(rcmail_url(null, array('_source' => $id))), $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id))); 
     84  } 
     85 
    8686  $OUTPUT->add_gui_object('folderlist', $attrib['id']); 
    8787   
  • branches/devel-api/skins/default/templates/addressbook.html

    r1861 r2386  
    88 
    99<style type="text/css"> 
    10 <roundcube:if condition="config:ldap_public == false" /> 
     10<roundcube:if condition="count(env:address_sources) &lt;= 1" /> 
    1111#abookcountbar { left: 20px;} 
    1212#mainscreen { left:20px; /* IE hack */ width:expression((parseInt(document.documentElement.clientWidth)-40)+'px') } 
     
    4545</div> 
    4646 
    47 <roundcube:if condition="config:ldap_public" /> 
     47<roundcube:if condition="count(env:address_sources) &gt; 1" /> 
    4848<div id="directorylist"> 
    4949<div id="groups-title"><roundcube:label name="groups" /></div> 
Note: See TracChangeset for help on using the changeset viewer.