From 6e9ce8e76637d86990500598592f3bdc7a113ad3 Mon Sep 17 00:00:00 2001 From: Jonathan Harker Date: Tue, 5 Apr 2011 16:00:21 +1200 Subject: [PATCH] MDL-22308 Update lib/bennu to latest upstream. --- lib/bennu/iCalendar_components.php | 431 ++++++++++++++++++++++++----- lib/bennu/iCalendar_properties.php | 232 ++++++++++++---- lib/bennu/iCalendar_rfc2445.php | 4 + 3 files changed, 546 insertions(+), 121 deletions(-) diff --git a/lib/bennu/iCalendar_components.php b/lib/bennu/iCalendar_components.php index 5a4127d3177..92350981dc0 100644 --- a/lib/bennu/iCalendar_components.php +++ b/lib/bennu/iCalendar_components.php @@ -9,7 +9,6 @@ * See http://bennu.sourceforge.net/ for more information and downloads. * * @author Ioannis Papaioannou - * @version $Id$ * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */ @@ -19,12 +18,13 @@ class iCalendar_component { var $components = NULL; var $valid_properties = NULL; var $valid_components = NULL; + /** + * Added to hold errors from last run of unserialize + * @var $parser_errors array + */ + var $parser_errors = NULL; - function iCalendar_component() { - $this->construct(); - } - - function construct() { + function __construct() { // Initialize the components array if(empty($this->components)) { $this->components = array(); @@ -99,13 +99,13 @@ class iCalendar_component { return false; } - // If this property is restricted to only once, blindly overwrite value - if(!$xname && $this->valid_properties[$name] & RFC2445_ONCE) { - $this->properties[$name] = array($property); - } - - // Otherwise add it to the instance array for this property - else { + // Check if the property already exists, and is limited to one occurrance, + // DON'T overwrite the value - this can be done explicity with set_value() instead. + if(!$xname && $this->valid_properties[$name] & RFC2445_ONCE && isset($this->properties[$name])) { + return false; + } + else { + // Otherwise add it to the instance array for this property $this->properties[$name][] = $property; } @@ -218,13 +218,112 @@ class iCalendar_component { return $string; } + + /** + * unserialize() + * + * I needed a way to convert an iCalendar component back to a Bennu object so I could + * easily access and modify it after it had been stored; if this functionality is already + * present somewhere in the library, I apologize for adding it here unnecessarily; however, + * I couldn't find it so I added it myself. + * @param string $string the iCalendar object to load in to this iCalendar_component + * @return bool true if the file parsed with no errors. False if there were errors. + */ + + function unserialize($string) { + $string = rfc2445_unfold($string); // Unfold any long lines + $lines = explode(RFC2445_CRLF, $string); // Create an array of lines + + $components = array(); // Initialise a stack of components + $this->clear_errors(); + foreach ($lines as $key => $line) { + // Divide the line up into label, parameters and data fields. + if (!preg_match('#^(?P