Aleksander Machniak
2016-05-16 0b7e26c1bf6bc7a684eb3a214d92d3927306cd8a
commit | author | age
48e9c1 1 <?php
T 2
0ea079 3 require_once(__DIR__ . '/example_addressbook_backend.php');
48e9c1 4
T 5 /**
6  * Sample plugin to add a new address book
7  * with just a static list of contacts
07c6c6 8  *
TB 9  * @license GNU GPLv3+
10  * @author Thomas Bruederli
48e9c1 11  */
T 12 class example_addressbook extends rcube_plugin
13 {
14   private $abook_id = 'static';
15   private $abook_name = 'Static List';
16
17   public function init()
18   {
19     $this->add_hook('addressbooks_list', array($this, 'address_sources'));
20     $this->add_hook('addressbook_get', array($this, 'get_address_book'));
21
22     // use this address book for autocompletion queries
23     // (maybe this should be configurable by the user?)
24     $config = rcmail::get_instance()->config;
25     $sources = (array) $config->get('autocomplete_addressbooks', array('sql'));
26     if (!in_array($this->abook_id, $sources)) {
27       $sources[] = $this->abook_id;
28       $config->set('autocomplete_addressbooks', $sources);
29     }
30   }
31
32   public function address_sources($p)
33   {
34     $abook = new example_addressbook_backend($this->abook_name);
35     $p['sources'][$this->abook_id] = array(
36       'id' => $this->abook_id,
37       'name' => $this->abook_name,
38       'readonly' => $abook->readonly,
39       'groups' => $abook->groups,
40     );
41     return $p;
42   }
43
44   public function get_address_book($p)
45   {
46     if ($p['id'] === $this->abook_id) {
47       $p['instance'] = new example_addressbook_backend($this->abook_name);
48     }
49
50     return $p;
51   }
52
53 }