-//read events into array
-//data is | delimited, just like addresbook
-//files are structured like this:
-//date|time|length|priority|title|message);
-//files are divide by year for performance increase
+/**
+ * Reads multilined calendar data
+ *
+ * Plugin stores multiline texts converted to single line with PHP nl2br().
+ * Function undoes nl2br() conversion and html encoding of ASCII vertical bar.
+ *
+ * Older plugin versions sanitized data with htmlspecialchars. Since 1.5.1 calendar
+ * data is not sanitized. Output functions must make sure that data is correctly
+ * encoded and sanitized.
+ * @param string $string calendar string
+ * @return string calendar string converted to multiline text
+ * @access private
+ * @since 1.5.1
+ */
+function calendar_readmultiline($string) {
+ /**
+ * replace html line breaks with ASCII line feeds
+ * replace htmlencoded | with ASCII vertical bar
+ */
+ $string = str_replace(array('<br />','<br>','|'),array("\n","\n",'|'),$string);
+ return $string;
+}
+
+/**
+ * Callback function used to sanitize calendar data before saving it to file
+ * @param string $sValue array value
+ * @param string $sKey array key
+ * @access private
+ * @since 1.5.1
+ */
+function calendar_encodedata(&$sValue, $sKey) {
+ /**
+ * add html line breaks
+ * remove original ASCII line feeds and carriage returns
+ * replace ASCII vertical bar with html code in order to sanitize field delimiter
+ */
+ $sValue = str_replace(array("\n","\r",'|'),array('','','|'),nl2br($sValue));
+}
+
+/**
+ * read events into array
+ *
+ * data is | delimited, just like addressbook
+ * files are structured like this:
+ * date|time|length|priority|title|message
+ * files are divided by year for performance increase
+ */