File: prefs.php

package info (click to toggle)
ingo1 1.2.4%2Bdebian0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 6,196 kB
  • ctags: 1,955
  • sloc: php: 8,375; xml: 2,846; sql: 168; makefile: 74; sh: 26
file content (187 lines) | stat: -rw-r--r-- 6,705 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/**
 * Ingo_Storage_prefs:: implements the Ingo_Storage:: API to save Ingo data
 * via the Horde preferences system.
 *
 * $Horde: ingo/lib/Storage/prefs.php,v 1.14.12.14 2009/05/14 13:48:15 jan Exp $
 *
 * See the enclosed file LICENSE for license information (ASL).  If you
 * did not receive this file, see http://www.horde.org/licenses/asl.php.
 *
 * @author  Michael Slusarz <slusarz@horde.org>
 * @author  Jan Schneider <jan@horde.org>
 * @package Ingo
 */
class Ingo_Storage_prefs extends Ingo_Storage {

    /**
     * Constructor.
     *
     * @param array $params  Additional parameters for the subclass.
     */
    function Ingo_Storage_prefs($params = array())
    {
        $this->_params = $params;
    }

    /**
     * Retrieves the specified data from the storage backend.
     *
     * @param integer $field     The field name of the desired data.
     *                           See lib/Storage.php for the available fields.
     * @param boolean $readonly  Whether to disable any write operations.
     *
     * @return Ingo_Storage_rule|Ingo_Storage_filters  The specified data.
     */
    function &_retrieve($field, $readonly = false)
    {
        $prefs = &Prefs::singleton($GLOBALS['conf']['prefs']['driver'],
                                   $GLOBALS['registry']->getApp(),
                                   Ingo::getUser(), '', null, false);
        $prefs->retrieve();

        switch ($field) {
        case INGO_STORAGE_ACTION_BLACKLIST:
            $ob = new Ingo_Storage_blacklist();
            $data = @unserialize($prefs->getValue('blacklist'));
            if ($data) {
                $ob->setBlacklist($data['a'], false);
                $ob->setBlacklistFolder($data['f']);
            }
            break;

        case INGO_STORAGE_ACTION_WHITELIST:
            $ob = new Ingo_Storage_whitelist();
            $data = @unserialize($prefs->getValue('whitelist'));
            if ($data) {
                $ob->setWhitelist($data, false);
            }
            break;

        case INGO_STORAGE_ACTION_FILTERS:
            $ob = new Ingo_Storage_filters();
            $data = @unserialize($prefs->getValue('rules', false));
            if ($data === false) {
                /* Convert rules from the old format. */
                $data = @unserialize($prefs->getValue('rules'));
            } else {
                $data = String::convertCharset($data, $prefs->getCharset(), NLS::getCharset());
            }
            if ($data) {
                $ob->setFilterlist($data);
            }
            break;

        case INGO_STORAGE_ACTION_FORWARD:
            $ob = new Ingo_Storage_forward();
            $data = @unserialize($prefs->getValue('forward'));
            if ($data) {
                $ob->setForwardAddresses($data['a'], false);
                $ob->setForwardKeep($data['k']);
            }
            break;

        case INGO_STORAGE_ACTION_VACATION:
            $ob = new Ingo_Storage_vacation();
            $data = @unserialize($prefs->getValue('vacation', false));
            if ($data === false) {
                /* Convert vacation from the old format. */
                $data = unserialize($prefs->getValue('vacation'));
            } elseif (is_array($data)) {
                $data = $prefs->convertFromDriver($data, NLS::getCharset());
            }
            if ($data) {
                $ob->setVacationAddresses($data['addresses'], false);
                $ob->setVacationDays($data['days']);
                $ob->setVacationExcludes($data['excludes'], false);
                $ob->setVacationIgnorelist($data['ignorelist']);
                $ob->setVacationReason($data['reason']);
                $ob->setVacationSubject($data['subject']);
                if (isset($data['start'])) {
                    $ob->setVacationStart($data['start']);
                }
                if (isset($data['end'])) {
                    $ob->setVacationEnd($data['end']);
                }
            }
            break;

        case INGO_STORAGE_ACTION_SPAM:
            $ob = new Ingo_Storage_spam();
            $data = @unserialize($prefs->getValue('spam'));
            if ($data) {
                $ob->setSpamFolder($data['folder']);
                $ob->setSpamLevel($data['level']);
            }
            break;

        default:
            $ob = false;
            break;
        }

        return $ob;
    }

    /**
     * Stores the specified data in the storage backend.
     *
     * @access private
     *
     * @param Ingo_Storage_rule|Ingo_Storage_filters $ob  The object to store.
     *
     * @return boolean  True on success.
     */
    function _store($ob)
    {
        $prefs = &Prefs::singleton($GLOBALS['conf']['prefs']['driver'],
                                   $GLOBALS['registry']->getApp(),
                                   Ingo::getUser(), '', null, false);
        $prefs->retrieve();

        switch ($ob->obType()) {
        case INGO_STORAGE_ACTION_BLACKLIST:
            $data = array(
                'a' => $ob->getBlacklist(),
                'f' => $ob->getBlacklistFolder(),
            );
            return $prefs->setValue('blacklist', serialize($data));

        case INGO_STORAGE_ACTION_FILTERS:
            return $prefs->setValue('rules', serialize(String::convertCharset($ob->getFilterlist(), NLS::getCharset(), $prefs->getCharset())), false);

        case INGO_STORAGE_ACTION_FORWARD:
            $data = array(
                'a' => $ob->getForwardAddresses(),
                'k' => $ob->getForwardKeep(),
            );
            return $prefs->setValue('forward', serialize($data));

        case INGO_STORAGE_ACTION_VACATION:
            $data = array(
                'addresses' => $ob->getVacationAddresses(),
                'days' => $ob->getVacationDays(),
                'excludes' => $ob->getVacationExcludes(),
                'ignorelist' => $ob->getVacationIgnorelist(),
                'reason' => $ob->getVacationReason(),
                'subject' => $ob->getVacationSubject(),
                'start' => $ob->getVacationStart(),
                'end' => $ob->getVacationEnd(),
            );
            return $prefs->setValue('vacation', serialize($prefs->convertToDriver($data, NLS::getCharset())), false);

        case INGO_STORAGE_ACTION_WHITELIST:
            return $prefs->setValue('whitelist', serialize($ob->getWhitelist()));

        case INGO_STORAGE_ACTION_SPAM:
            $data = array(
                'folder' => $ob->getSpamFolder(),
                'level' => $ob->getSpamLevel(),
            );
            return $prefs->setValue('spam', serialize($data));
        }

        return false;
    }

}