]> git.donarmstrong.com Git - roundcube.git/blob - plugins/example_addressbook/example_addressbook.php
Imported Upstream version 0.6+dfsg
[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   private $abook_name = 'Static List';
13
14   public function init()
15   {
16     $this->add_hook('addressbooks_list', array($this, 'address_sources'));
17     $this->add_hook('addressbook_get', array($this, 'get_address_book'));
18
19     // use this address book for autocompletion queries
20     // (maybe this should be configurable by the user?)
21     $config = rcmail::get_instance()->config;
22     $sources = (array) $config->get('autocomplete_addressbooks', array('sql'));
23     if (!in_array($this->abook_id, $sources)) {
24       $sources[] = $this->abook_id;
25       $config->set('autocomplete_addressbooks', $sources);
26     }
27   }
28
29   public function address_sources($p)
30   {
31     $abook = new example_addressbook_backend($this->abook_name);
32     $p['sources'][$this->abook_id] = array(
33       'id' => $this->abook_id,
34       'name' => $this->abook_name,
35       'readonly' => $abook->readonly,
36       'groups' => $abook->groups,
37     );
38     return $p;
39   }
40
41   public function get_address_book($p)
42   {
43     if ($p['id'] === $this->abook_id) {
44       $p['instance'] = new example_addressbook_backend($this->abook_name);
45     }
46
47     return $p;
48   }
49
50 }