Fix various issues introduced with Funambol adjustments; code cleanup

This commit is contained in:
Jörg Lehrke 2010-01-10 19:02:16 +00:00
parent 70aee0a67d
commit 548f5f8c98
4 changed files with 308 additions and 264 deletions

View File

@ -219,6 +219,12 @@ class addressbook_vcal extends addressbook_bo
{ {
$size = $this->clientProperties[$vcardField]['Size']; $size = $this->clientProperties[$vcardField]['Size'];
$noTruncate = $this->clientProperties[$vcardField]['NoTruncate']; $noTruncate = $this->clientProperties[$vcardField]['NoTruncate'];
if ($this->log && $size > 0)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
"() $vcardField Size: $size, NoTruncate: " .
($noTruncate ? 'TRUE' : 'FALSE') . "\n",3,$this->logfile);
}
//Horde::logMessage("vCalAddressbook $vcardField Size: $size, NoTruncate: " . //Horde::logMessage("vCalAddressbook $vcardField Size: $size, NoTruncate: " .
// ($noTruncate ? 'TRUE' : 'FALSE'), __FILE__, __LINE__, PEAR_LOG_DEBUG); // ($noTruncate ? 'TRUE' : 'FALSE'), __FILE__, __LINE__, PEAR_LOG_DEBUG);
} }
@ -292,7 +298,11 @@ class addressbook_vcal extends addressbook_bo
$value = $values[0]; $value = $values[0];
if (strlen($value) > $size) if (strlen($value) > $size)
{ {
error_log(__FILE__ . __LINE__ . __METHOD__ . " vCalAddressbook $vcardField omitted due to maximum size $size"); if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
"() $vcardField omitted due to maximum size $size\n",3,$this->logfile);
}
// Horde::logMessage("vCalAddressbook $vcardField omitted due to maximum size $size", // Horde::logMessage("vCalAddressbook $vcardField omitted due to maximum size $size",
// __FILE__, __LINE__, PEAR_LOG_WARNING); // __FILE__, __LINE__, PEAR_LOG_WARNING);
continue; continue;
@ -332,7 +342,11 @@ class addressbook_vcal extends addressbook_bo
{ {
if ($noTruncate) if ($noTruncate)
{ {
error_log(__FILE__ . __LINE__ . __METHOD__ . " vCalAddressbook $vcardField omitted due to maximum size $size"); if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
"() $vcardField omitted due to maximum size $size\n",3,$this->logfile);
}
// Horde::logMessage("vCalAddressbook $vcardField omitted due to maximum size $size", // Horde::logMessage("vCalAddressbook $vcardField omitted due to maximum size $size",
// __FILE__, __LINE__, PEAR_LOG_WARNING); // __FILE__, __LINE__, PEAR_LOG_WARNING);
continue; continue;
@ -348,7 +362,11 @@ class addressbook_vcal extends addressbook_bo
{ {
$value = ''; $value = '';
} }
error_log(__FILE__ . __LINE__ . __METHOD__ . " vCalAddressbook $vcardField truncated to maximum size $size"); if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
"() $vcardField truncated to maximum size $size\n",3,$this->logfile);
}
//Horde::logMessage("vCalAddressbook $vcardField truncated to maximum size $size", //Horde::logMessage("vCalAddressbook $vcardField truncated to maximum size $size",
// __FILE__, __LINE__, PEAR_LOG_INFO); // __FILE__, __LINE__, PEAR_LOG_INFO);
} }
@ -371,10 +389,6 @@ class addressbook_vcal extends addressbook_bo
} }
elseif ($this->productManufacturer == 'funambol') elseif ($this->productManufacturer == 'funambol')
{ {
if ($this->productName == 'mozilla sync client')
{
$valueData = str_replace( "\n", '\\n', $valueData);
}
$options['ENCODING'] = 'FUNAMBOL-QP'; $options['ENCODING'] = 'FUNAMBOL-QP';
} }
elseif (preg_match('/([\000-\012\015\016\020-\037\075])/', $value)) elseif (preg_match('/([\000-\012\015\016\020-\037\075])/', $value))
@ -683,8 +697,6 @@ class addressbook_vcal extends addressbook_bo
// E.g. ADR will be either ADR;WORK, if no ADR;WORK is given, // E.g. ADR will be either ADR;WORK, if no ADR;WORK is given,
// or else ADR;HOME, if not available elsewhere. // or else ADR;HOME, if not available elsewhere.
//error_log(print_r($rowNames, true));
$finalRowNames = array(); $finalRowNames = array();
foreach ($rowNames as $vcardKey => $rowName) foreach ($rowNames as $vcardKey => $rowName)
@ -836,9 +848,6 @@ class addressbook_vcal extends addressbook_bo
array2string($finalRowNames)."\n",3,$this->logfile); array2string($finalRowNames)."\n",3,$this->logfile);
} }
//error_log(print_r($finalRowNames, true));
$contact = array(); $contact = array();
foreach ($finalRowNames as $key => $vcardKey) foreach ($finalRowNames as $key => $vcardKey)

View File

@ -583,8 +583,14 @@ class calendar_ical extends calendar_boupdate
{ {
$size = $this->clientProperties[$icalFieldName]['Size']; $size = $this->clientProperties[$icalFieldName]['Size'];
$noTruncate = $this->clientProperties[$icalFieldName]['NoTruncate']; $noTruncate = $this->clientProperties[$icalFieldName]['NoTruncate'];
#Horde::logMessage("vCalendar $icalFieldName Size: $size, NoTruncate: " . if ($this->log && $size > 0)
# ($noTruncate ? 'TRUE' : 'FALSE'), __FILE__, __LINE__, PEAR_LOG_DEBUG); {
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
"() $icalFieldName Size: $size, NoTruncate: " .
($noTruncate ? 'TRUE' : 'FALSE') . "\n",3,$this->logfile);
}
//Horde::logMessage("vCalendar $icalFieldName Size: $size, NoTruncate: " .
// ($noTruncate ? 'TRUE' : 'FALSE'), __FILE__, __LINE__, PEAR_LOG_DEBUG);
} }
else else
{ {
@ -597,14 +603,24 @@ class calendar_ical extends calendar_boupdate
{ {
if ($noTruncate) if ($noTruncate)
{ {
Horde::logMessage("vCalendar $icalFieldName omitted due to maximum size $size", if ($this->log)
__FILE__, __LINE__, PEAR_LOG_WARNING); {
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
"() $icalFieldName omitted due to maximum size $size\n",3,$this->logfile);
}
//Horde::logMessage("vCalendar $icalFieldName omitted due to maximum size $size",
// __FILE__, __LINE__, PEAR_LOG_WARNING);
continue; // skip field continue; // skip field
} }
// truncate the value to size // truncate the value to size
$value = substr($value, 0, $size - 1); $value = substr($value, 0, $size - 1);
Horde::logMessage("vCalendar $icalFieldName truncated to maximum size $size", if ($this->log)
__FILE__, __LINE__, PEAR_LOG_INFO); {
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
"() $icalFieldName truncated to maximum size $size\n",3,$this->logfile);
}
//Horde::logMessage("vCalendar $icalFieldName truncated to maximum size $size",
// __FILE__, __LINE__, PEAR_LOG_INFO);
} }
if (!empty($value) || ($size >= 0 && !$noTruncate)) if (!empty($value) || ($size >= 0 && !$noTruncate))
{ {
@ -706,12 +722,11 @@ class calendar_ical extends calendar_boupdate
$GLOBALS['egw']->translation->charset(),'UTF-8'); $GLOBALS['egw']->translation->charset(),'UTF-8');
$valuesData = (array) $GLOBALS['egw']->translation->convert($values[$key], $valuesData = (array) $GLOBALS['egw']->translation->convert($values[$key],
$GLOBALS['egw']->translation->charset(),'UTF-8'); $GLOBALS['egw']->translation->charset(),'UTF-8');
//echo "$key:$valueID: value=$valueData, param=".print_r($paramDate,true)."\n";
// attendees or organizer CN can contain utf-8 content
$paramData['CHARSET'] = 'UTF-8';
if (preg_match('/[^\x20-\x7F]/', $valueData) || if (preg_match('/[^\x20-\x7F]/', $valueData) ||
($paramData['CN'] && preg_match('/[^\x20-\x7F]/', $paramData['CN']))) ($paramData['CN'] && preg_match('/[^\x20-\x7F]/', $paramData['CN'])))
{ {
$paramData['CHARSET'] = 'UTF-8';
switch ($this->productManufacturer) switch ($this->productManufacturer)
{ {
case 'groupdav': case 'groupdav':
@ -733,13 +748,10 @@ class calendar_ical extends calendar_boupdate
} }
break; break;
case 'funambol': case 'funambol':
if ($this->productName == 'mozilla sync client')
{
$valueData = str_replace( "\n", '\\n', $valueData);
}
$paramData['ENCODING'] = 'FUNAMBOL-QP'; $paramData['ENCODING'] = 'FUNAMBOL-QP';
} }
} }
/*
if (preg_match('/([\000-\012])/', $valueData)) if (preg_match('/([\000-\012])/', $valueData))
{ {
if ($this->log) if ($this->log)
@ -748,6 +760,7 @@ class calendar_ical extends calendar_boupdate
"() Has invalid XML data: $valueData",3,$this->logfile); "() Has invalid XML data: $valueData",3,$this->logfile);
} }
} }
*/
$vevent->setAttribute($key, $valueData, $paramData, true, $valuesData); $vevent->setAttribute($key, $valueData, $paramData, true, $valuesData);
} }
} }
@ -1334,7 +1347,6 @@ class calendar_ical extends calendar_boupdate
'owner' => 'owner', 'owner' => 'owner',
'category' => 'category', 'category' => 'category',
'non_blocking' => 'non_blocking', 'non_blocking' => 'non_blocking',
'recurrence' => 'recurrence',
); );
$defaultFields['evolution'] = $defaultFields['basic'] + array( $defaultFields['evolution'] = $defaultFields['basic'] + array(

View File

@ -170,8 +170,14 @@ class infolog_ical extends infolog_bo
{ {
$size = $this->clientProperties[$field]['Size']; $size = $this->clientProperties[$field]['Size'];
$noTruncate = $this->clientProperties[$field]['NoTruncate']; $noTruncate = $this->clientProperties[$field]['NoTruncate'];
#Horde::logMessage("VTODO $field Size: $size, NoTruncate: " . if ($this->log && $size > 0)
# ($noTruncate ? 'TRUE' : 'FALSE'), __FILE__, __LINE__, PEAR_LOG_DEBUG); {
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
"() $field Size: $size, NoTruncate: " .
($noTruncate ? 'TRUE' : 'FALSE') . "\n",3,$this->logfile);
}
//Horde::logMessage("VTODO $field Size: $size, NoTruncate: " .
// ($noTruncate ? 'TRUE' : 'FALSE'), __FILE__, __LINE__, PEAR_LOG_DEBUG);
} }
else else
{ {
@ -183,30 +189,40 @@ class infolog_ical extends infolog_bo
{ {
if ($noTruncate) if ($noTruncate)
{ {
Horde::logMessage("VTODO $field omitted due to maximum size $size", if ($this->log)
__FILE__, __LINE__, PEAR_LOG_WARNING); {
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
"() $field omitted due to maximum size $size\n",3,$this->logfile);
}
//Horde::logMessage("VTODO $field omitted due to maximum size $size",
// __FILE__, __LINE__, PEAR_LOG_WARNING);
continue; // skip field continue; // skip field
} }
// truncate the value to size // truncate the value to size
$value = substr($value, 0, $size -1); $value = substr($value, 0, $size -1);
#Horde::logMessage("VTODO $field truncated to maximum size $size", if ($this->log)
# __FILE__, __LINE__, PEAR_LOG_INFO); {
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
"() $field truncated to maximum size $size\n",3,$this->logfile);
}
//Horde::logMessage("VTODO $field truncated to maximum size $size",
// __FILE__, __LINE__, PEAR_LOG_INFO);
} }
if (empty($value) && ($size < 0 || $noTruncate)) continue; if (empty($value) && ($size < 0 || $noTruncate)) continue;
if ($field == 'RELATED-TO') if ($field == 'RELATED-TO')
{ {
$options = array('RELTYPE' => 'PARENT', $options = array('RELTYPE' => 'PARENT');
'CHARSET' => 'UTF-8');
} }
else else
{ {
$options = array('CHARSET' => 'UTF-8'); $options = array();
} }
if (preg_match('/[^\x20-\x7F]/', $value)) if (preg_match('/[^\x20-\x7F]/', $value))
{ {
$options['CHARSET'] = 'UTF-8';
switch ($this->productManufacturer) switch ($this->productManufacturer)
{ {
case 'groupdav': case 'groupdav':
@ -229,10 +245,6 @@ class infolog_ical extends infolog_bo
} }
break; break;
case 'funambol': case 'funambol':
if ($this->productName == 'mozilla sync client')
{
$value = str_replace( "\n", '\\n', $value);
}
$options['ENCODING'] = 'FUNAMBOL-QP'; $options['ENCODING'] = 'FUNAMBOL-QP';
} }
} }
@ -268,7 +280,7 @@ class infolog_ical extends infolog_bo
} }
else else
{ {
$priority = (int) $this->priority_egw2ical2[$taskData['info_priority']]; $priority = (int) $this->priority_egw2ical[$taskData['info_priority']];
} }
$vevent->setAttribute('PRIORITY', $priority); $vevent->setAttribute('PRIORITY', $priority);
@ -584,9 +596,10 @@ class infolog_ical extends infolog_bo
'CATEGORIES' => $note['info_cat'], 'CATEGORIES' => $note['info_cat'],
) as $field => $value) ) as $field => $value)
{ {
$options = array('CHARSET' => 'UTF-8'); $options = array();
if (preg_match('/[^\x20-\x7F]/', $value)) if (preg_match('/[^\x20-\x7F]/', $value))
{ {
$options['CHARSET'] = 'UTF-8';
switch ($this->productManufacturer) switch ($this->productManufacturer)
{ {
case 'groupdav': case 'groupdav':
@ -609,10 +622,6 @@ class infolog_ical extends infolog_bo
} }
break; break;
case 'funambol': case 'funambol':
if ($this->productName == 'mozilla sync client')
{
$value = str_replace( "\n", '\\n', $value);
}
$options['ENCODING'] = 'FUNAMBOL-QP'; $options['ENCODING'] = 'FUNAMBOL-QP';
} }
} }

View File

@ -649,224 +649,224 @@ class Horde_iCalendar {
if (isset($params['BASE64'])) { if (isset($params['BASE64'])) {
$params['ENCODING'] = 'BASE64'; $params['ENCODING'] = 'BASE64';
} }
if (isset($params['ENCODING'])) { if (isset($params['ENCODING'])) {
switch (String::upper($params['ENCODING'])) { switch (String::upper($params['ENCODING'])) {
case 'Q': case 'Q':
case 'QUOTED-PRINTABLE': case 'QUOTED-PRINTABLE':
$value = quoted_printable_decode($value); $value = quoted_printable_decode($value);
if (isset($params['CHARSET'])) { if (isset($params['CHARSET'])) {
$value = $GLOBALS['egw']->translation->convert($value, $params['CHARSET']); $value = $GLOBALS['egw']->translation->convert($value, $params['CHARSET']);
} else { } else {
$value = $GLOBALS['egw']->translation->convert($value, $value = $GLOBALS['egw']->translation->convert($value,
empty($charset) ? ($this->isOldFormat() ? 'iso-8859-1' : 'utf-8') : $charset); empty($charset) ? ($this->isOldFormat() ? 'iso-8859-1' : 'utf-8') : $charset);
} }
// Funambol hack :-( // Funambol hack :-(
$value = str_replace('\\\\n', "\n", $value); $value = str_replace('\\\\n', "\n", $value);
break; break;
case 'B': case 'B':
case 'BASE64': case 'BASE64':
$value = base64_decode($value); $value = base64_decode($value);
break; break;
} }
} elseif (isset($params['CHARSET'])) { } elseif (isset($params['CHARSET'])) {
$value = $GLOBALS['egw']->translation->convert($value, $params['CHARSET']); $value = $GLOBALS['egw']->translation->convert($value, $params['CHARSET']);
} else { } else {
// As per RFC 2279, assume UTF8 if we don't have an // As per RFC 2279, assume UTF8 if we don't have an
// explicit charset parameter. // explicit charset parameter.
$value = $GLOBALS['egw']->translation->convert($value, $value = $GLOBALS['egw']->translation->convert($value,
empty($charset) ? ($this->isOldFormat() ? 'iso-8859-1' : 'utf-8') : $charset); empty($charset) ? ($this->isOldFormat() ? 'iso-8859-1' : 'utf-8') : $charset);
} }
// Get timezone info for date fields from $params. // Get timezone info for date fields from $params.
$tzid = isset($params['TZID']) ? trim($params['TZID'], '\"') : false; $tzid = isset($params['TZID']) ? trim($params['TZID'], '\"') : false;
switch ($tag) { switch ($tag) {
case 'VERSION': // already processed case 'VERSION': // already processed
break;
// Date fields.
case 'COMPLETED':
case 'CREATED':
case 'LAST-MODIFIED':
$this->setAttribute($tag, $this->_parseDateTime($value, $tzid), $params);
break;
case 'BDAY':
case 'X-SYNCJE-ANNIVERSARY':
$this->setAttribute($tag, $value, $params, true, $this->_parseDate($value));
break;
case 'DTEND':
case 'DTSTART':
case 'DTSTAMP':
case 'DUE':
case 'AALARM':
case 'DALARM':
case 'RECURRENCE-ID':
case 'X-RECURRENCE-ID':
// types like AALARM may contain additional data after a ;
// ignore these.
$ts = explode(';', $value);
if (isset($params['VALUE']) && $params['VALUE'] == 'DATE') {
$isDate = true;
$this->setAttribute($tag, $this->_parseDateTime($ts[0], $tzid), $params, true, $this->_parseDate($ts[0]));
} else {
$this->setAttribute($tag, $this->_parseDateTime($ts[0], $tzid), $params);
}
break;
case 'TRIGGER':
if (isset($params['VALUE'])) {
if ($params['VALUE'] == 'DATE-TIME') {
$this->setAttribute($tag, $this->_parseDateTime($value, $tzid), $params);
} else {
$this->setAttribute($tag, $this->_parseDuration($value), $params);
}
} else {
$this->setAttribute($tag, $this->_parseDuration($value), $params);
}
break;
// Comma or semicolon seperated dates.
case 'EXDATE':
case 'RDATE':
$dates = array();
preg_match_all('/[;,]([^;,]*)/', ';' . $value, $values);
foreach ($values[1] as $value) {
if ((isset($params['VALUE'])
&& $params['VALUE'] == 'DATE') || (!isset($params['VALUE']) && $isDate)) {
$dates[] = $this->_parseDate($value);
} else {
$dates[] = $this->_parseDateTime($value, $tzid);
}
}
$this->setAttribute($tag, isset($dates[0]) ? $dates[0] : null, $params, true, $dates);
break;
// Duration fields.
case 'DURATION':
$this->setAttribute($tag, $this->_parseDuration($value), $params);
break;
// Period of time fields.
case 'FREEBUSY':
$periods = array();
preg_match_all('/,([^,]*)/', ',' . $value, $values);
foreach ($values[1] as $value) {
$periods[] = $this->_parsePeriod($value);
}
$this->setAttribute($tag, isset($periods[0]) ? $periods[0] : null, $params, true, $periods);
break;
// UTC offset fields.
case 'TZOFFSETFROM':
case 'TZOFFSETTO':
$this->setAttribute($tag, $this->_parseUtcOffset($value), $params);
break;
// Integer fields.
case 'PERCENT-COMPLETE':
case 'PRIORITY':
case 'REPEAT':
case 'SEQUENCE':
$this->setAttribute($tag, intval($value), $params);
break;
// Geo fields.
case 'GEO':
if ($this->isOldFormat()) {
$floats = explode(',', $value);
$value = array('latitude' => floatval($floats[1]),
'longitude' => floatval($floats[0]));
} else {
$floats = explode(';', $value);
$value = array('latitude' => floatval($floats[0]),
'longitude' => floatval($floats[1]));
}
$this->setAttribute($tag, $value, $params);
break;
// Recursion fields. # add more flexibility
#case 'EXRULE':
#case 'RRULE':
# $this->setAttribute($tag, trim($value), $params);
# break;
// Binary fields.
case 'PHOTO':
$this->setAttribute($tag, $value, $params);
break;
// ADR, ORG and N are lists seperated by unescaped semicolons
// with a specific number of slots.
case 'ADR':
case 'N':
case 'ORG':
$value = trim($value);
// As of rfc 2426 2.4.2 semicolon, comma, and colon must
// be escaped (comma is unescaped after splitting below).
$value = str_replace(array('\\n', '\\N', '\\;', '\\:'),
array("\n", "\n", ';', ':'),
$value);
// Split by unescaped semicolons:
$values = preg_split('/(?<!\\\\);/', $value);
$value = str_replace('\\;', ';', $value);
$values = str_replace('\\;', ';', $values);
$value = str_replace('\\,', ',', $value);
$values = str_replace('\\,', ',', $values);
$this->setAttribute($tag, trim($value), $params, true, $values);
break;
// CATEGORIES is a lists seperated by unescaped commas
// with a unspecific number of slots.
case 'CATEGORIES':
$value = trim($value);
// As of rfc 2426 2.4.2 semicolon, comma, and colon must
// be escaped (semicolon is unescaped after splitting below).
$value = str_replace(array('\\n', '\\N', '\\,', '\\:'),
array("\n", "\n", ',', ':'),
$value);
// Split by unescaped commas:
$values = preg_split('/(?<!\\\\),/', $value);
$value = str_replace('\\;', ';', $value);
$values = str_replace('\\;', ';', $values);
$value = str_replace('\\,', ',', $value);
$values = str_replace('\\,', ',', $values);
$this->setAttribute($tag, trim($value), $params, true, $values);
break;
// String fields.
default:
if ($this->isOldFormat()) {
// vCalendar 1.0 and vCard 2.1 only escape semicolons
// and use unescaped semicolons to create lists.
$value = trim($value);
// Split by unescaped semicolons:
$values = preg_split('/(?<!\\\\);/', $value);
$value = str_replace('\\;', ';', $value);
$values = str_replace('\\;', ';', $values);
$this->setAttribute($tag, trim($value), $params, true, $values);
} else {
$value = trim($value);
// As of rfc 2426 2.4.2 semicolon, comma, and colon
// must be escaped (comma is unescaped after splitting
// below).
$value = str_replace(array('\\n', '\\N', '\\;', '\\:', '\\\\'),
array("\n", "\n", ';', ':', '\\'),
$value);
// Split by unescaped commas.
$values = preg_split('/(?<!\\\\),/', $value);
$value = str_replace('\\,', ',', $value);
$values = str_replace('\\,', ',', $values);
$this->setAttribute($tag, trim($value), $params, true, $values);
}
break; break;
// Date fields. }
case 'COMPLETED':
case 'CREATED':
case 'LAST-MODIFIED':
$this->setAttribute($tag, $this->_parseDateTime($value, $tzid), $params);
break;
case 'BDAY':
case 'X-SYNCJE-ANNIVERSARY':
$this->setAttribute($tag, $value, $params, true, $this->_parseDate($value));
break;
case 'DTEND':
case 'DTSTART':
case 'DTSTAMP':
case 'DUE':
case 'AALARM':
case 'DALARM':
case 'RECURRENCE-ID':
case 'X-RECURRENCE-ID':
// types like AALARM may contain additional data after a ;
// ignore these.
$ts = explode(';', $value);
if (isset($params['VALUE']) && $params['VALUE'] == 'DATE') {
$isDate = true;
$this->setAttribute($tag, $this->_parseDateTime($ts[0], $tzid), $params, true, $this->_parseDate($ts[0]));
} else {
$this->setAttribute($tag, $this->_parseDateTime($ts[0], $tzid), $params);
}
break;
case 'TRIGGER':
if (isset($params['VALUE'])) {
if ($params['VALUE'] == 'DATE-TIME') {
$this->setAttribute($tag, $this->_parseDateTime($value, $tzid), $params);
} else {
$this->setAttribute($tag, $this->_parseDuration($value), $params);
}
} else {
$this->setAttribute($tag, $this->_parseDuration($value), $params);
}
break;
// Comma or semicolon seperated dates.
case 'EXDATE':
case 'RDATE':
$dates = array();
preg_match_all('/[;,]([^;,]*)/', ';' . $value, $values);
foreach ($values[1] as $value) {
if ((isset($params['VALUE'])
&& $params['VALUE'] == 'DATE') || (!isset($params['VALUE']) && $isDate)) {
$dates[] = $this->_parseDate($value);
} else {
$dates[] = $this->_parseDateTime($value, $tzid);
}
}
$this->setAttribute($tag, isset($dates[0]) ? $dates[0] : null, $params, true, $dates);
break;
// Duration fields.
case 'DURATION':
$this->setAttribute($tag, $this->_parseDuration($value), $params);
break;
// Period of time fields.
case 'FREEBUSY':
$periods = array();
preg_match_all('/,([^,]*)/', ',' . $value, $values);
foreach ($values[1] as $value) {
$periods[] = $this->_parsePeriod($value);
}
$this->setAttribute($tag, isset($periods[0]) ? $periods[0] : null, $params, true, $periods);
break;
// UTC offset fields.
case 'TZOFFSETFROM':
case 'TZOFFSETTO':
$this->setAttribute($tag, $this->_parseUtcOffset($value), $params);
break;
// Integer fields.
case 'PERCENT-COMPLETE':
case 'PRIORITY':
case 'REPEAT':
case 'SEQUENCE':
$this->setAttribute($tag, intval($value), $params);
break;
// Geo fields.
case 'GEO':
if ($this->isOldFormat()) {
$floats = explode(',', $value);
$value = array('latitude' => floatval($floats[1]),
'longitude' => floatval($floats[0]));
} else {
$floats = explode(';', $value);
$value = array('latitude' => floatval($floats[0]),
'longitude' => floatval($floats[1]));
}
$this->setAttribute($tag, $value, $params);
break;
// Recursion fields. # add more flexibility
#case 'EXRULE':
#case 'RRULE':
# $this->setAttribute($tag, trim($value), $params);
# break;
// Binary fields.
case 'PHOTO':
$this->setAttribute($tag, $value, $params);
break;
// ADR, ORG and N are lists seperated by unescaped semicolons
// with a specific number of slots.
case 'ADR':
case 'N':
case 'ORG':
$value = trim($value);
// As of rfc 2426 2.4.2 semicolon, comma, and colon must
// be escaped (comma is unescaped after splitting below).
$value = str_replace(array('\\n', '\\N', '\\;', '\\:'),
array("\n", "\n", ';', ':'),
$value);
// Split by unescaped semicolons:
$values = preg_split('/(?<!\\\\);/', $value);
$value = str_replace('\\;', ';', $value);
$values = str_replace('\\;', ';', $values);
$value = str_replace('\\,', ',', $value);
$values = str_replace('\\,', ',', $values);
$this->setAttribute($tag, trim($value), $params, true, $values);
break;
// CATEGORIES is a lists seperated by unescaped commas
// with a unspecific number of slots.
case 'CATEGORIES':
$value = trim($value);
// As of rfc 2426 2.4.2 semicolon, comma, and colon must
// be escaped (semicolon is unescaped after splitting below).
$value = str_replace(array('\\n', '\\N', '\\,', '\\:'),
array("\n", "\n", ',', ':'),
$value);
// Split by unescaped commas:
$values = preg_split('/(?<!\\\\),/', $value);
$value = str_replace('\\;', ';', $value);
$values = str_replace('\\;', ';', $values);
$value = str_replace('\\,', ',', $value);
$values = str_replace('\\,', ',', $values);
$this->setAttribute($tag, trim($value), $params, true, $values);
break;
// String fields.
default:
if ($this->isOldFormat()) {
// vCalendar 1.0 and vCard 2.1 only escape semicolons
// and use unescaped semicolons to create lists.
$value = trim($value);
// Split by unescaped semicolons:
$values = preg_split('/(?<!\\\\);/', $value);
$value = str_replace('\\;', ';', $value);
$values = str_replace('\\;', ';', $values);
$this->setAttribute($tag, trim($value), $params, true, $values);
} else {
$value = trim($value);
// As of rfc 2426 2.4.2 semicolon, comma, and colon
// must be escaped (comma is unescaped after splitting
// below).
$value = str_replace(array('\\n', '\\N', '\\;', '\\:', '\\\\'),
array("\n", "\n", ';', ':', '\\'),
$value);
// Split by unescaped commas.
$values = preg_split('/(?<!\\\\),/', $value);
$value = str_replace('\\,', ',', $value);
$values = str_replace('\\,', ',', $values);
$this->setAttribute($tag, trim($value), $params, true, $values);
}
break;
}
} }
} }
@ -1128,10 +1128,17 @@ class Horde_iCalendar {
} }
} }
if (!empty($params['ENCODING']) && strlen(trim($value))) { $encoding = (!empty($params['ENCODING']) && strlen(trim($value)) > 0);
if ($encoding) {
switch($params['ENCODING']) { switch($params['ENCODING']) {
case 'Q': case 'Q':
case 'QUOTED-PRINTABLE': case 'QUOTED-PRINTABLE':
if (!$this->isOldFormat())
{
$enconding = false;
break;
}
$params_str .= ';ENCODING=' . $params['ENCODING']; $params_str .= ';ENCODING=' . $params['ENCODING'];
$value = str_replace("\r", '', $value); $value = str_replace("\r", '', $value);
$result .= $name . $params_str . ':' $result .= $name . $params_str . ':'
@ -1140,9 +1147,14 @@ class Horde_iCalendar {
. $this->_newline; . $this->_newline;
break; break;
case 'FUNAMBOL-QP': case 'FUNAMBOL-QP':
// Funambol does not support wrapping and needs some special quoting // Funambol needs some special quoting
$params_str .= ';ENCODING=QUOTED-PRINTABLE';
$value = str_replace(array('<', "\r"), array('&lt;', ''), $value); $value = str_replace(array('<', "\r"), array('&lt;', ''), $value);
if (!$this->isOldFormat())
{
$encoding = false;
break;
}
$params_str .= ';ENCODING=QUOTED-PRINTABLE';
$result .= $name . $params_str . ':' $result .= $name . $params_str . ':'
. str_replace('=0A', '=0D=0A', . str_replace('=0A', '=0D=0A',
$this->_quotedPrintableEncode($value, false)) $this->_quotedPrintableEncode($value, false))
@ -1159,7 +1171,9 @@ class Horde_iCalendar {
$result .= $this->_newline; // Append an empty line $result .= $this->_newline; // Append an empty line
} }
} }
} else { }
if (!$encoding) {
$value = str_replace(array("\r", "\n"), array('', '\\n'), $value); $value = str_replace(array("\r", "\n"), array('', '\\n'), $value);
$attr_string = $name . $params_str; $attr_string = $name . $params_str;
if (strlen($value) > 0) { if (strlen($value) > 0) {