summaryrefslogtreecommitdiff
path: root/lib/Kolab/Utils/VObjectUtils.php
diff options
context:
space:
mode:
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