1: <?php
2: 3: 4: 5: 6: 7:
8: class Sam_Api extends Horde_Registry_Api
9: {
10: 11: 12: 13: 14:
15: public $links = array(
16: 'showBlacklist' => '%application%/blacklist.php',
17: 'showWhitelist' => '%application%/whitelist.php',
18: );
19:
20: public function whitelistFrom($addresses)
21: {
22: $this->_listFrom($addresses, 'white');
23: }
24:
25: public function blacklistFrom($addresses)
26: {
27: $this->_listFrom($addresses, 'black');
28: }
29:
30: protected function _listFrom($addresses, $what)
31: {
32: $sam_driver = $GLOBALS['injector']->getInstance('Sam_Driver');
33:
34: if (!$sam_driver->hasCapability($what . 'list_from')) {
35: return false;
36: }
37:
38: $sam_driver->retrieve();
39: $list = $sam_driver->getListOption($what . 'list_from');
40: $list = explode("\n", $list);
41:
42: if (is_array($addresses)) {
43: foreach ($addresses as $address) {
44: if (!in_array($address, $list)) {
45: $list[] = $address;
46: }
47: }
48: } elseif (!in_array($address, $list)) {
49: $list[] = $addresses;
50: }
51:
52: $sam_driver->setListOption($what . 'list_from', implode("\n", $list));
53:
54: $sam_driver->store();
55: }
56: }
57: