]> git.donarmstrong.com Git - roundcube.git/blob - plugins/example_addressbook/example_addressbook.php
c50f8d8cec82be7862173d6679611a0c6cbc7c88
[roundcube.git] / plugins / example_addressbook / example_addressbook.php
1 <?php
2
3 require_once(dirname(__FILE__) . '/example_addressbook_backend.php');
4
5 /**
6  * Sample plugin to add a new address book
7  * with just a static list of contacts
8  */
9 class example_addressbook extends rcube_plugin
10 {
11   private $abook_id = 'static';
12   
13   public function init()
14   {
15     $this->add_hook('addressbooks_list', array($this, 'address_sources'));
16     $this->add_hook('addressbook_get', array($this, 'get_address_book'));
17     
18     // use this address book for autocompletion queries
19     // (maybe this should be configurable by the user?)
20     $config = rcmail::get_instance()->config;
21     $sources = (array) $config->get('autocomplete_addressbooks', array('sql'));
22     if (!in_array($this->abook_id, $sources)) {
23       $sources[] = $this->abook_id;
24       $config->set('autocomplete_addressbooks', $sources);
25     }
26   }
27   
28   public function address_sources($p)
29   {
30     $abook = new example_addressbook_backend;
31     $p['sources'][$this->abook_id] = array(
32       'id' => $this->abook_id,
33       'name' => 'Static List',
34       'readonly' => $abook->readonly,
35       'groups' => $abook->groups,
36     );
37     return $p;
38   }
39   
40   public function get_address_book($p)
41   {
42     if ($p['id'] === $this->abook_id) {
43       $p['instance'] = new example_addressbook_backend;
44     }
45     
46     return $p;
47   }
48   
49 }