1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Ingo_Storage_Prefs extends Ingo_Storage
14: {
15: 16: 17: 18: 19:
20: public function __construct($params = array())
21: {
22: $this->_params = $params;
23: parent::__construct();
24: }
25:
26: 27: 28: 29: 30: 31: 32: 33: 34:
35: protected function _retrieve($field, $readonly = false)
36: {
37: $prefs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Prefs')->create('ingo', array(
38: 'cache' => false,
39: 'user' => Ingo::getUser()
40: ));
41:
42: switch ($field) {
43: case self::ACTION_BLACKLIST:
44: $ob = new Ingo_Storage_Blacklist();
45: if ($data = @unserialize($prefs->getValue('blacklist'))) {
46: $ob->setBlacklist($data['a'], true);
47: $ob->setBlacklistFolder($data['f']);
48: }
49: break;
50:
51: case self::ACTION_WHITELIST:
52: $ob = new Ingo_Storage_Whitelist();
53: if ($data = @unserialize($prefs->getValue('whitelist'))) {
54: $ob->setWhitelist($data, true);
55: }
56: break;
57:
58: case self::ACTION_FILTERS:
59: $ob = new Ingo_Storage_Filters();
60: if ($data = @unserialize($prefs->getValue('rules'))) {
61: $ob->setFilterlist($data);
62: }
63: break;
64:
65: case self::ACTION_FORWARD:
66: $ob = new Ingo_Storage_Forward();
67: if ($data = @unserialize($prefs->getValue('forward'))) {
68: $ob->setForwardAddresses($data['a'], false);
69: $ob->setForwardKeep($data['k']);
70: }
71: break;
72:
73: case self::ACTION_VACATION:
74: $ob = new Ingo_Storage_Vacation();
75: if ($data = @unserialize($prefs->getValue('vacation'))) {
76: $ob->setVacationAddresses($data['addresses'], false);
77: $ob->setVacationDays($data['days']);
78: $ob->setVacationExcludes($data['excludes'], false);
79: $ob->setVacationIgnorelist($data['ignorelist']);
80: $ob->setVacationReason($data['reason']);
81: $ob->setVacationSubject($data['subject']);
82: if (isset($data['start'])) {
83: $ob->setVacationStart($data['start']);
84: }
85: if (isset($data['end'])) {
86: $ob->setVacationEnd($data['end']);
87: }
88: }
89: break;
90:
91: case self::ACTION_SPAM:
92: $ob = new Ingo_Storage_Spam();
93: if ($data = @unserialize($prefs->getValue('spam'))) {
94: $ob->setSpamFolder($data['folder']);
95: $ob->setSpamLevel($data['level']);
96: }
97: break;
98:
99: default:
100: $ob = false;
101: break;
102: }
103:
104: return $ob;
105: }
106:
107: 108: 109: 110: 111:
112: protected function _store($ob)
113: {
114: $prefs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Prefs')->create('ingo', array(
115: 'cache' => false,
116: 'user' => Ingo::getUser()
117: ));
118:
119: switch ($ob->obType()) {
120: case self::ACTION_BLACKLIST:
121: $data = array(
122: 'a' => $ob->getBlacklist(),
123: 'f' => $ob->getBlacklistFolder(),
124: );
125: $prefs->setValue('blacklist', serialize($data));
126: break;
127:
128: case self::ACTION_FILTERS:
129: $prefs->setValue('rules', serialize($ob->getFilterList()));
130: break;
131:
132: case self::ACTION_FORWARD:
133: $data = array(
134: 'a' => $ob->getForwardAddresses(),
135: 'k' => $ob->getForwardKeep(),
136: );
137: $prefs->setValue('forward', serialize($data));
138: break;
139:
140: case self::ACTION_VACATION:
141: $data = array(
142: 'addresses' => $ob->getVacationAddresses(),
143: 'days' => $ob->getVacationDays(),
144: 'excludes' => $ob->getVacationExcludes(),
145: 'ignorelist' => $ob->getVacationIgnorelist(),
146: 'reason' => $ob->getVacationReason(),
147: 'subject' => $ob->getVacationSubject(),
148: 'start' => $ob->getVacationStart(),
149: 'end' => $ob->getVacationEnd(),
150: );
151: $prefs->setValue('vacation', serialize($data));
152: break;
153:
154: case self::ACTION_WHITELIST:
155: $prefs->setValue('whitelist', serialize($ob->getWhitelist()));
156: break;
157:
158: case self::ACTION_SPAM:
159: $data = array(
160: 'folder' => $ob->getSpamFolder(),
161: 'level' => $ob->getSpamLevel(),
162: );
163: $prefs->setValue('spam', serialize($data));
164: break;
165: }
166: }
167: }
168: