~ubuntu-branches/ubuntu/hardy/squirrelmail/hardy-updates

« back to all changes in this revision

Viewing changes to plugins/calendar/calendar_data.php

  • Committer: Bazaar Package Importer
  • Author(s): Thijs Kinkhorst
  • Date: 2006-07-04 14:49:23 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060704144923-w5l1xdbivclpkmda
Tags: 2:1.4.7-1
* New upstream bugfix release.
  + Addresses some low-impact, theoretical or disputed security bugs,
    for which the code is tightened just-in-case:
    - Possible local file inclusion (Closes: #373731, CVE-2006-2842)
    - XSS in search.php (Closes: #375782, CVE-2006-3174)
  + Adds note to db-backend.txt about postgreSQL (Closes: #376605).

* Checked for standards version to 3.7.2, no changes necessary.
* Update maintainer address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
 
3
3
/**
4
 
 * calendar_data.php
5
 
 *
6
 
 * Copyright (c) 2002-2006 The SquirrelMail Project Team
7
 
 * Licensed under the GNU GPL. For full terms see the file COPYING.
8
 
 *
9
 
 * Originally contrubuted by Michal Szczotka <michal@tuxy.org>
10
 
 *
11
4
 * functions to operate on calendar data files.
12
5
 *
13
 
 * $Id: calendar_data.php,v 1.7.2.10 2006/02/03 22:27:52 jervfors Exp $
 
6
 * @copyright &copy; 2002-2006 The SquirrelMail Project Team
 
7
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 
8
 * @version $Id: calendar_data.php,v 1.7.2.11 2006/05/06 07:52:18 tokul Exp $
 
9
 * @package plugins
 
10
 * @subpackage calendar
14
11
 */
15
12
 
16
 
// this is array that contains all events
17
 
// it is three dimensional array with fallowing structure
18
 
// $calendardata[date][time] = array(length,priority,title,message);
 
13
/**
 
14
 * this is array that contains all events
 
15
 * it is three dimensional array with fallowing structure
 
16
 * $calendardata[date][time] = array(length,priority,title,message,reminder);
 
17
 */
19
18
$calendardata = array();
20
19
 
21
 
//read events into array
22
 
//data is | delimited, just like addresbook
23
 
//files are structured like this:
24
 
//date|time|length|priority|title|message);
25
 
//files are divide by year for performance increase
 
20
/**
 
21
 * Reads multilined calendar data
 
22
 * 
 
23
 * Plugin stores multiline texts converted to single line with PHP nl2br().
 
24
 * Function undoes nl2br() conversion and html encoding of ASCII vertical bar.
 
25
 *
 
26
 * Older plugin versions sanitized data with htmlspecialchars. Since 1.5.1 calendar 
 
27
 * data is not sanitized. Output functions must make sure that data is correctly 
 
28
 * encoded and sanitized.
 
29
 * @param string $string calendar string
 
30
 * @return string calendar string converted to multiline text
 
31
 * @access private
 
32
 * @since 1.5.1 and 1.4.7
 
33
 */
 
34
function calendar_readmultiline($string) {
 
35
    /**
 
36
     * replace html line breaks with ASCII line feeds
 
37
     * replace htmlencoded | with ASCII vertical bar
 
38
     */
 
39
    $string = str_replace(array('<br />','<br>','&#124;'),array("\n","\n",'|'),$string);
 
40
    return $string;
 
41
}
 
42
 
 
43
/**
 
44
 * Callback function used to sanitize calendar data before saving it to file
 
45
 * @param string $sValue array value 
 
46
 * @param string $sKey array key
 
47
 * @access private
 
48
 * @since 1.5.1 and 1.4.7
 
49
 */
 
50
function calendar_encodedata(&$sValue, $sKey) {
 
51
    /**
 
52
     * add html line breaks
 
53
     * remove original ASCII line feeds and carriage returns
 
54
     * replace ASCII vertical bar with html code in order to sanitize field delimiter
 
55
     */
 
56
    $sValue = str_replace(array("\n","\r",'|'),array('','','&#124;'),nl2br($sValue));
 
57
}
 
58
 
 
59
/**
 
60
 * read events into array
 
61
 *
 
62
 * data is | delimited, just like addressbook
 
63
 * files are structured like this:
 
64
 * date|time|length|priority|title|message
 
65
 * files are divided by year for performance increase
 
66
 */
26
67
function readcalendardata() {
27
68
    global $calendardata, $username, $data_dir, $year;
28
69
 
33
74
 
34
75
        if ($fp){
35
76
            while ($fdata = fgetcsv ($fp, 4096, '|')) {
36
 
                $calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
37
 
                                                            'priority' => $fdata[3],
38
 
                                                            'title' => htmlspecialchars($fdata[4],ENT_NOQUOTES),
39
 
                                                            'message' => htmlspecialchars($fdata[5],ENT_NOQUOTES),
40
 
                                                            'reminder' => $fdata[6] );
 
77
                $calendardata[$fdata[0]][$fdata[1]] = array( 'length'   => $fdata[2],
 
78
                                                             'priority' => $fdata[3],
 
79
                                                             'title'    => str_replace("\n",' ',calendar_readmultiline($fdata[4])),
 
80
                                                             'message'  => calendar_readmultiline($fdata[5]),
 
81
                                                             'reminder' => $fdata[6] );
41
82
            }
42
83
            fclose ($fp);
43
84
            // this is to sort the events within a day on starttime
51
92
    }
52
93
}
53
94
 
54
 
//makes events persistant
 
95
/**
 
96
 * Saves calendar data
 
97
 * @return void
 
98
 * @access private
 
99
 */
55
100
function writecalendardata() {
56
101
    global $calendardata, $username, $data_dir, $year, $color;
57
102
 
62
107
        while ( $calfoo = each ($calendardata)) {
63
108
            while ( $calbar = each ($calfoo['value'])) {
64
109
                $calfoobar = $calendardata[$calfoo['key']][$calbar['key']];
 
110
                array_walk($calfoobar,'calendar_encodedata');
 
111
                /**
 
112
                 * Make sure that reminder field is set. Calendar forms don't implement it, 
 
113
                 * but it is still used for calendar data. Backwards compatibility.
 
114
                 */ 
 
115
                if (!isset($calfoobar['reminder'])) $calfoobar['reminder']='';
 
116
 
65
117
                $calstr = "$calfoo[key]|$calbar[key]|$calfoobar[length]|$calfoobar[priority]|$calfoobar[title]|$calfoobar[message]|$calfoobar[reminder]\n";
66
118
                if(sq_fwrite($fp, $calstr, 4096) === FALSE) {
67
 
                        error_box(_("Could not write calendar file %s", "$username.$year.cal.tmp"), $color);
68
 
                }
 
119
                    error_box(_("Could not write calendar file %s", "$username.$year.cal.tmp"), $color);
 
120
                }
69
121
            }
70
122
 
71
123
        }
75
127
    }
76
128
}
77
129
 
78
 
//deletes event from file
 
130
/**
 
131
 * deletes event from file
 
132
 * @return void
 
133
 * @access private
 
134
 */
79
135
function delete_event($date, $time) {
80
136
    global $calendardata, $username, $data_dir, $year;
81
137
 
84
140
    if ($fp){
85
141
        while ($fdata = fgetcsv ($fp, 4096, "|")) {
86
142
            if (($fdata[0]==$date) && ($fdata[1]==$time)){
87
 
            // do nothing
 
143
                // do nothing
88
144
            } else {
89
 
                $calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
 
145
                $calendardata[$fdata[0]][$fdata[1]] = array( 'length'   => $fdata[2],
90
146
                                                             'priority' => $fdata[3],
91
 
                                                             'title' => $fdata[4],
92
 
                                                             'message' => $fdata[5],
 
147
                                                             'title'    => $fdata[4],
 
148
                                                             'message'  => $fdata[5],
93
149
                                                             'reminder' => $fdata[6] );
94
150
            }
95
151
        }
96
152
        fclose ($fp);
97
153
    }
98
154
    writecalendardata();
99
 
 
100
155
}
101
156
 
102
 
// same as delete but not saves calendar
103
 
// saving is done inside event_edit.php
 
157
/**
 
158
 * same as delete but does not save calendar
 
159
 * saving is done inside event_edit.php
 
160
 * @return void
 
161
 * @access private
 
162
 * @todo code reuse
 
163
 */
104
164
function update_event($date, $time) {
105
165
    global $calendardata, $username, $data_dir, $year;
106
166
 
109
169
    if ($fp){
110
170
        while ($fdata = fgetcsv ($fp, 4096, '|')) {
111
171
            if (($fdata[0]==$date) && ($fdata[1]==$time)){
112
 
            // do nothing
 
172
                // do nothing
113
173
            } else {
114
 
                $calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
 
174
                $calendardata[$fdata[0]][$fdata[1]] = array( 'length'   => $fdata[2],
115
175
                                                             'priority' => $fdata[3],
116
 
                                                             'title' => $fdata[4],
117
 
                                                             'message' => $fdata[5],
 
176
                                                             'title'    => $fdata[4],
 
177
                                                             'message'  => $fdata[5],
118
178
                                                             'reminder' => $fdata[6] );
119
179
            }
120
180
        }
122
182
    }
123
183
}
124
184
 
125
 
 
126
185
?>
 
 
b'\\ No newline at end of file'