diff options
Diffstat (limited to '3rdparty/Sabre/VObject/Reader.php')
-rwxr-xr-x[-rw-r--r--] | 3rdparty/Sabre/VObject/Reader.php | 88 |
1 files changed, 40 insertions, 48 deletions
diff --git a/3rdparty/Sabre/VObject/Reader.php b/3rdparty/Sabre/VObject/Reader.php index 7d1c282838e..eea73fa3dce 100644..100755 --- a/3rdparty/Sabre/VObject/Reader.php +++ b/3rdparty/Sabre/VObject/Reader.php @@ -5,40 +5,22 @@ * * This class reads the vobject file, and returns a full element tree. * + * TODO: this class currently completely works 'statically'. This is pointless, + * and defeats OOP principals. Needs refactoring in a future version. * - * TODO: this class currently completely works 'statically'. This is pointless, - * and defeats OOP principals. Needs refaxtoring in a future version. - * * @package Sabre * @subpackage VObject - * @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved. - * @author Evert Pot (http://www.rooftopsolutions.nl/) + * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved. + * @author Evert Pot (http://www.rooftopsolutions.nl/) * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License */ class Sabre_VObject_Reader { /** - * This array contains a list of Property names that are automatically - * mapped to specific class names. + * Parses the file and returns the top component * - * Adding to this list allows you to specify custom property classes, - * adding extra functionality. - * - * @var array - */ - static public $elementMap = array( - 'DTSTART' => 'Sabre_VObject_Element_DateTime', - 'DTEND' => 'Sabre_VObject_Element_DateTime', - 'COMPLETED' => 'Sabre_VObject_Element_DateTime', - 'DUE' => 'Sabre_VObject_Element_DateTime', - 'EXDATE' => 'Sabre_VObject_Element_MultiDateTime', - ); - - /** - * Parses the file and returns the top component - * - * @param string $data - * @return Sabre_VObject_Element + * @param string $data + * @return Sabre_VObject_Element */ static function read($data) { @@ -63,11 +45,11 @@ class Sabre_VObject_Reader { } unset($lines); - + reset($lines2); return self::readLine($lines2); - + } /** @@ -75,9 +57,9 @@ class Sabre_VObject_Reader { * * This method receives the full array of lines. The array pointer is used * to traverse. - * - * @param array $lines - * @return Sabre_VObject_Element + * + * @param array $lines + * @return Sabre_VObject_Element */ static private function readLine(&$lines) { @@ -88,22 +70,23 @@ class Sabre_VObject_Reader { // Components if (stripos($line,"BEGIN:")===0) { - // This is a component - $obj = new Sabre_VObject_Component(strtoupper(substr($line,6))); + $componentName = strtoupper(substr($line,6)); + $obj = Sabre_VObject_Component::create($componentName); $nextLine = current($lines); while(stripos($nextLine,"END:")!==0) { $obj->add(self::readLine($lines)); + $nextLine = current($lines); - if ($nextLine===false) + if ($nextLine===false) throw new Sabre_VObject_ParseException('Invalid VObject. Document ended prematurely.'); } - // Checking component name of the 'END:' line. + // Checking component name of the 'END:' line. if (substr($nextLine,4)!==$obj->name) { throw new Sabre_VObject_ParseException('Invalid VObject, expected: "END:' . $obj->name . '" got: "' . $nextLine . '"'); } @@ -117,7 +100,7 @@ class Sabre_VObject_Reader { //$result = preg_match('/(?P<name>[A-Z0-9-]+)(?:;(?P<parameters>^(?<!:):))(.*)$/',$line,$matches); - $token = '[A-Z0-9-\/\.]+'; + $token = '[A-Z0-9-\.]+'; $parameters = "(?:;(?P<parameters>([^:^\"]|\"([^\"]*)\")*))?"; $regex = "/^(?P<name>$token)$parameters:(?P<value>.*)$/i"; @@ -128,22 +111,23 @@ class Sabre_VObject_Reader { } $propertyName = strtoupper($matches['name']); - $propertyValue = stripcslashes($matches['value']); - - if (isset(self::$elementMap[$propertyName])) { - $className = self::$elementMap[$propertyName]; - } else { - $className = 'Sabre_VObject_Property'; - } + $propertyValue = preg_replace_callback('#(\\\\(\\\\|N|n|;|,))#',function($matches) { + if ($matches[2]==='n' || $matches[2]==='N') { + return "\n"; + } else { + return $matches[2]; + } + }, $matches['value']); - $obj = new $className($propertyName, $propertyValue); + $obj = Sabre_VObject_Property::create($propertyName, $propertyValue); if ($matches['parameters']) { foreach(self::readParameters($matches['parameters']) as $param) { $obj->add($param); } - } + + } return $obj; @@ -151,12 +135,12 @@ class Sabre_VObject_Reader { } /** - * Reads a parameter list from a property + * Reads a parameter list from a property * * This method returns an array of Sabre_VObject_Parameter * - * @param string $parameters - * @return array + * @param string $parameters + * @return array */ static private function readParameters($parameters) { @@ -179,7 +163,15 @@ class Sabre_VObject_Reader { $value = ''; } - $params[] = new Sabre_VObject_Parameter($match['paramName'], stripcslashes($value)); + $value = preg_replace_callback('#(\\\\(\\\\|N|n|;|,))#',function($matches) { + if ($matches[2]==='n' || $matches[2]==='N') { + return "\n"; + } else { + return $matches[2]; + } + }, $value); + + $params[] = new Sabre_VObject_Parameter($match['paramName'], $value); } |