diff options
Diffstat (limited to 'vendor/eluceo/ical/src/Eluceo/iCal/Util')
3 files changed, 157 insertions, 0 deletions
diff --git a/vendor/eluceo/ical/src/Eluceo/iCal/Util/ComponentUtil.php b/vendor/eluceo/ical/src/Eluceo/iCal/Util/ComponentUtil.php new file mode 100644 index 00000000..ca6a2be0 --- /dev/null +++ b/vendor/eluceo/ical/src/Eluceo/iCal/Util/ComponentUtil.php @@ -0,0 +1,48 @@ +<?php + +/* + * This file is part of the eluceo/iCal package. + * + * (c) Markus Poerschke <markus@eluceo.de> + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Eluceo\iCal\Util; + +class ComponentUtil +{ + /** + * Folds a single line. + * + * According to RFC 2445, all lines longer than 75 characters will be folded + * + * @link http://www.ietf.org/rfc/rfc2445.txt + * + * @param $string + * + * @return array + */ + public static function fold($string) + { + $lines = array(); + $array = preg_split('/(?<!^)(?!$)/u', $string); + + $line = ''; + $lineNo = 0; + foreach ($array as $char) { + $charLen = strlen($char); + $lineLen = strlen($line); + if ($lineLen + $charLen > 75) { + $line = ' ' . $char; + ++$lineNo; + } else { + $line .= $char; + } + $lines[$lineNo] = $line; + } + + return $lines; + } +} diff --git a/vendor/eluceo/ical/src/Eluceo/iCal/Util/DateUtil.php b/vendor/eluceo/ical/src/Eluceo/iCal/Util/DateUtil.php new file mode 100644 index 00000000..3bd3367f --- /dev/null +++ b/vendor/eluceo/ical/src/Eluceo/iCal/Util/DateUtil.php @@ -0,0 +1,69 @@ +<?php + +/* + * This file is part of the eluceo/iCal package. + * + * (c) Markus Poerschke <markus@eluceo.de> + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Eluceo\iCal\Util; + +class DateUtil +{ + public static function getDefaultParams(\DateTime $dateTime = null, $noTime = false, $useTimezone = false) + { + $params = array(); + + if ($useTimezone) { + $timeZone = $dateTime->getTimezone()->getName(); + $params['TZID'] = $timeZone; + } + + if ($noTime) { + $params['VALUE'] = 'DATE'; + } + + return $params; + } + + /** + * Returns a formatted date string. + * + * @param \DateTime|null $dateTime The DateTime object + * @param bool $noTime Indicates if the time will be added + * @param bool $useTimezone + * @param bool $useUtc + * + * @return mixed + */ + public static function getDateString(\DateTime $dateTime = null, $noTime = false, $useTimezone = false, $useUtc = false) + { + if (empty($dateTime)) { + $dateTime = new \DateTime(); + } + + return $dateTime->format(self::getDateFormat($noTime, $useTimezone, $useUtc)); + } + + /** + * Returns the date format that can be passed to DateTime::format(). + * + * @param bool $noTime Indicates if the time will be added + * @param bool $useTimezone + * @param bool $useUtc + * + * @return string + */ + public static function getDateFormat($noTime = false, $useTimezone = false, $useUtc = false) + { + // Do not use UTC time (Z) if timezone support is enabled. + if ($useTimezone || !$useUtc) { + return $noTime ? 'Ymd' : 'Ymd\THis'; + } + + return $noTime ? 'Ymd' : 'Ymd\THis\Z'; + } +} diff --git a/vendor/eluceo/ical/src/Eluceo/iCal/Util/PropertyValueUtil.php b/vendor/eluceo/ical/src/Eluceo/iCal/Util/PropertyValueUtil.php new file mode 100644 index 00000000..40538589 --- /dev/null +++ b/vendor/eluceo/ical/src/Eluceo/iCal/Util/PropertyValueUtil.php @@ -0,0 +1,40 @@ +<?php + +/* + * This file is part of the eluceo/iCal package. + * + * (c) Markus Poerschke <markus@eluceo.de> + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Eluceo\iCal\Util; + +class PropertyValueUtil +{ + public static function escapeValue($value) + { + $value = self::escapeValueAllowNewLine($value); + $value = str_replace("\n", '\\n', $value); + + return $value; + } + + public static function escapeValueAllowNewLine($value) + { + $value = str_replace('\\', '\\\\', $value); + $value = str_replace('"', '\\"', $value); + $value = str_replace(',', '\\,', $value); + $value = str_replace(';', '\\;', $value); + $value = str_replace(array( + "\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", + "\x08", "\x09", /* \n*/ "\x0B", "\x0C", "\x0D", "\x0E", "\x0F", + "\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17", + "\x18", "\x19", "\x1A", "\x1B", "\x1C", "\x1D", "\x1E", "\x1F", + "\x7F", + ), '', $value); + + return $value; + } +} |