summaryrefslogtreecommitdiff
path: root/lib/Kolab/FreeBusy/SourceURL.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Kolab/FreeBusy/SourceURL.php')
-rw-r--r--lib/Kolab/FreeBusy/SourceURL.php37
1 files changed, 35 insertions, 2 deletions
diff --git a/lib/Kolab/FreeBusy/SourceURL.php b/lib/Kolab/FreeBusy/SourceURL.php
index 1051dbf..d165bd5 100644
--- a/lib/Kolab/FreeBusy/SourceURL.php
+++ b/lib/Kolab/FreeBusy/SourceURL.php
@@ -3,7 +3,7 @@
namespace Kolab\FreeBusy;
/**
- *
+ * Implementation of a Free/Busy data source reading from remote URLs through HTTP
*/
class SourceURL extends Source
{
@@ -14,6 +14,39 @@ class SourceURL extends Source
{
$config = $this->getUserConfig($user);
- // TODO: implement this
+ // prepare HTTP stream context
+ $context = stream_context_create(array(
+ 'http' => array(
+ 'user_agent' => "Kolab Free-Busy Service/0.1.0",
+ 'timeout' => 10,
+ ),
+ ));
+
+ // set HTTP auth credentials
+ if (!empty($config['user'])) {
+ stream_context_set_option($context, array(
+ 'http' => array(
+ 'header' => "Authorization: Basic " . base64_encode($config['user'] . ':' . $config['pass']) . "\r\n",
+ ),
+ ));
+ $config['url'] = self::getUrl($config); // re-compose url without user:pass
+ }
+
+ // TODO: so some logging
+
+ return file_get_contents($config['url'], false, $context);
+ }
+
+ /**
+ * Compose a full url from the given config (previously extracted with parse_url())
+ */
+ private static function getUrl($config)
+ {
+ $scheme = isset($config['scheme']) ? $config['scheme'] . '://' : '';
+ $host = isset($config['host']) ? $config['host'] : '';
+ $port = isset($config['port']) ? ':' . $config['port'] : '';
+ $path = isset($config['path']) ? $config['path'] : '';
+ $query = isset($config['query']) ? '?' . $config['query'] : '';
+ return $scheme . $host . $port . $path . $query;
}
}