Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2529160
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/Kolab/FreeBusy/Source.php b/lib/Kolab/FreeBusy/Source.php
index 1af5ba3..53c4d0f 100644
--- a/lib/Kolab/FreeBusy/Source.php
+++ b/lib/Kolab/FreeBusy/Source.php
@@ -1,65 +1,66 @@
<?php
namespace Kolab\FreeBusy;
/**
* Abstract class to fetch free/busy data from a specific source
*/
abstract class Source
{
protected $config = array();
/**
* Factory method creating an instace of Source according to config
*
* @param array Hash array with config
*/
public static function factory($url)
{
$config = parse_url($url);
+ $config['url'] = $url;
switch ($config['scheme']) {
case 'file': return new SourceFile($config);
case 'imap': return new SourceIMAP($config);
case 'http':
- case 'https': return new SourceURL($url);
+ case 'https': return new SourceURL($config);
}
trigger_error("Invalid source configuration: " . $url, E_USER_ERROR);
return null;
}
/**
* Default constructor
*/
public function __construct($config)
{
$this->config = $config;
}
/**
* Retrieve free/busy data for the given user
*
* @param array Hash array with user attributes
*/
abstract public function getFreeBusyData($user, $extended);
/**
* Replace all %varname strings in config with values from $user
*/
protected function getUserConfig($user)
{
$config = array();
foreach ($this->config as $k => $val) {
if (is_string($val) && strpos($val, '%') !== false) {
$val = preg_replace_callback(
'/%\{?([a-z0-9]+)\}?/',
function($m) use ($user) { return $user[$m[1]]; },
$val);
}
$config[$k] = $val;
}
return $config;
}
}
\ No newline at end of file
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
@@ -1,19 +1,52 @@
<?php
namespace Kolab\FreeBusy;
/**
- *
+ * Implementation of a Free/Busy data source reading from remote URLs through HTTP
*/
class SourceURL extends Source
{
/**
* @see Source::getFreeBusyData()
*/
public function getFreeBusyData($user, $extended)
{
$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;
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Feb 2, 9:34 AM (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
426859
Default Alt Text
(3 KB)
Attached To
Mode
R28 freebusy
Attached
Detach File
Event Timeline
Log In to Comment