summaryrefslogtreecommitdiff
path: root/lib/Kolab/Utils/VObjectUtils.php
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2014-05-06 14:28:51 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2014-05-06 14:30:24 (GMT)
commite916334ac8fb840a1156fb7836349e95a6cc80fc (patch)
treee596f4503f64a4a7f6b087578c6445aeda891bdb /lib/Kolab/Utils/VObjectUtils.php
parent1a5d37bdc036f3d062d70cce59dde5988bbaafcc (diff)
downloadiRony-e916334ac8fb840a1156fb7836349e95a6cc80fc.tar.gz
Correctly encode and decode CalDAV/CardDAV object URIs (#3049)
Diffstat (limited to 'lib/Kolab/Utils/VObjectUtils.php')
-rw-r--r--lib/Kolab/Utils/VObjectUtils.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/Kolab/Utils/VObjectUtils.php b/lib/Kolab/Utils/VObjectUtils.php
index f04884e..82f934b 100644
--- a/lib/Kolab/Utils/VObjectUtils.php
+++ b/lib/Kolab/Utils/VObjectUtils.php
@@ -30,6 +30,30 @@ use Sabre\VObject\Property;
*/
class VObjectUtils
{
+ /**
+ * Convert an object URI into a valid UID value
+ */
+ public static function uri2uid($uri, $suffix = '')
+ {
+ $base = basename($uri, $suffix);
+ $uid = strtr($base, array('%2F' => '/'));
+
+ // assume full URL encoding
+ if (preg_match('/%[A-F0-9]{2}/', $uid)) {
+ return urldecode($base);
+ }
+
+ return $uid;
+ }
+
+ /**
+ * Encode an object UID into a valid URI
+ */
+ public static function uid2uri($uid, $suffix = '')
+ {
+ $encode = strpos($uid, '/') !== false;
+ return ($encode ? urlencode($uid) : $uid) . $suffix;
+ }
/**
* Create a Sabre\VObject\Property instance from a PHP DateTime object