You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

example_addressbook.php 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. require_once(__DIR__ . '/example_addressbook_backend.php');
  3. /**
  4. * Sample plugin to add a new address book
  5. * with just a static list of contacts
  6. *
  7. * @license GNU GPLv3+
  8. * @author Thomas Bruederli
  9. */
  10. class example_addressbook extends rcube_plugin
  11. {
  12. private $abook_id = 'static';
  13. private $abook_name = 'Static List';
  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. // 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. public function address_sources($p)
  28. {
  29. $abook = new example_addressbook_backend($this->abook_name);
  30. $p['sources'][$this->abook_id] = array(
  31. 'id' => $this->abook_id,
  32. 'name' => $this->abook_name,
  33. 'readonly' => $abook->readonly,
  34. 'groups' => $abook->groups,
  35. );
  36. return $p;
  37. }
  38. public function get_address_book($p)
  39. {
  40. if ($p['id'] === $this->abook_id) {
  41. $p['instance'] = new example_addressbook_backend($this->abook_name);
  42. }
  43. return $p;
  44. }
  45. }