Compare commits

..

No commits in common. "93abd2dfd8cfe30aabe8b04212a0398fb2af2160" and "64c887275a424f6153e6c1181bcd0df252f461a2" have entirely different histories.

19 changed files with 345 additions and 733 deletions

View file

@ -1,39 +0,0 @@
<?php
namespace davina\auths;
require_once(DIR_LOGIC . '/auths/_interface.php');
require_once(DIR_LOGIC . '/auths/pass_through.php');
require_once(DIR_LOGIC . '/auths/static.php');
/**
*/
function make(
string $kind,
$data
) : \davina\auths\interface_auth
{
switch ($kind)
{
case 'pass_through':
{
return (new \davina\auths\class_auth_pass_through(
));
break;
}
case 'static':
{
return (new \davina\auths\class_auth_static(
$data['password']
));
break;
}
default:
{
throw (new \Exception(\sprintf('unhandled auth kind: %s', $kind)));
break;
}
}
}
?>

View file

@ -1,42 +0,0 @@
<?php
namespace davina\auths;
require_once('vendor/autoload.php');
/**
*/
interface interface_auth
{
/**
* @param array $credentials {
* record<
* username:(null|string),
* password:string
* >
* }
*/
function check(
array $credentials
) : bool
;
/**
* @param array $credentials {
* record<
* username:(null|string),
* password:string
* >
* }
*/
function determine_parameters(
array $credentials
) : array
;
}
?>

View file

@ -1,39 +0,0 @@
<?php
namespace davina\auths;
require_once('vendor/autoload.php');
/**
*/
class class_auth_pass_through implements interface_auth
{
/**
* [implementation]
*/
function check(
array $credentials
) : bool
{
return true;
}
/**
* [implementation]
*/
function determine_parameters(
array $credentials
) : array
{
return [
'auth_username' => $credentials['username'],
'auth_password' => $credentials['password'],
];
}
}
?>

View file

@ -1,51 +0,0 @@
<?php
namespace davina\auths;
require_once('vendor/autoload.php');
/**
*/
class class_auth_static implements interface_auth
{
/**
*/
private string $password;
/**
*/
public function __construct(
string $password
)
{
$this->password = $password;
}
/**
* [implementation]
*/
function check(
array $credentials
) : bool
{
return ($credentials['password'] === $this->password);
}
/**
* [implementation]
*/
function determine_parameters(
array $credentials
) : array
{
return [];
}
}
?>

View file

@ -2,26 +2,58 @@
namespace davina\conf; namespace davina\conf;
require_once(DIR_LOGIC . '/helpers/list.php');
/**
*/
class struct_auth
{
public string $kind;
public $data;
}
/**
*/
class struct_source_data_ics_feed
{
public string $url;
public bool $combined;
public int $lifetime;
}
/**
*/
class struct_source
{
public string $kind;
public $data;
}
/**
*/
class struct_settings
{
public string $timezone;
}
/**
*/
class struct_root
{
public struct_auth $auth;
public struct_source $source;
public struct_settings $settings;
}
/** /**
*/ */
class _state class _state
{ {
public static $data = null; public static ?struct_root $data = null;
}
/**
*/
function validate_realm_name(
string $realm_name
) : string
{
$matchs = null;
$result = preg_match('/^[0-9a-zA-Z]+$/', $realm_name, $matches);
return ($result === 1);
} }
@ -37,86 +69,37 @@ function load(
), ),
true true
); );
_state::$data = [
/**
* @todo check for name duplicates
*/
'realms' => \davina\helpers\list_\map(
$data_raw['realms'],
function ($realm_raw) {
if (! validate_realm_name($realm_raw['name']))
{ {
throw (new \Exception(\sprintf('invalid realm name: "%s"', $realm_raw['name']))); $data = new struct_root();
} // auth
else
{ {
return [ $auth = new struct_auth();
'name' => $realm_raw['name'], $auth->kind = (($data_raw['auth'] ?? [])['kind'] ?? 'none');
'auth' => (function ($auth_raw) use ($realm_raw) { $auth->data = (($data_raw['auth'] ?? [])['data'] ?? null);
switch ($auth_raw['kind']) $data->auth = $auth;
}
// source
{ {
case 'pass_through': $source = new struct_source();
$source->kind = $data_raw['source']['kind'];
$source->data = ($data_raw['source']['data'] ?? null);
$data->source = $source;
}
// settings
{ {
return [ $settings = new struct_settings();
'kind' => 'pass_through', $settings->timezone = (($data_raw['settings'] ?? [])['timezone'] ?? 'UTC');
'data' => null $data->settings = $settings;
];
break;
} }
case 'static': _state::$data = $data;
{
return [
'kind' => 'static',
'data' => [
'username' => ($auth_raw['data']['username'] ?? $realm_raw['name']),
'password' => ($auth_raw['data']['password'] ?? $realm_raw['name']),
]
];
break;
} }
default:
{
throw (new \Exception(\sprintf('invalid auth kind: %s', $auth_raw['kind'])));
break;
}
}
}) ($realm_raw['auth']),
'source' => (function ($source_raw) {
switch ($source_raw['kind'])
{
case 'ics_feed':
{
return [
'kind' => 'ics_feed',
'data' => [
'url' => $source_raw['data']['url'],
'lifetime' => ($source_raw['data']['lifetime'] ?? (60 * 15)),
'conflate' => ($source_raw['data']['conflate'] ?? true),
]
];
break;
}
default:
{
throw (new \Exception(\sprintf('invalid source kind: %s', $source_raw['kind'])));
}
}
}) ($realm_raw['source']),
];
}
}
),
'settings' => [
'timezone' => (($data_raw['settings'] ?? [])['timezone'] ?? 'UTC'),
]
];
} }
/** /**
*/ */
function get( function get(
) ) : struct_root
{ {
if (_state::$data === null) if (_state::$data === null)
{ {

View file

@ -1,35 +0,0 @@
<?php
namespace davina\helpers\list_;
/**
*/
function map(
array $list,
\Closure $function
) : array
{
return \array_map(
$function,
$list
);
}
/**
*/
function filter(
array $list,
\Closure $predicate
) : array
{
return \array_values(
\array_filter(
$list,
$predicate
)
);
}
?>

View file

@ -13,18 +13,7 @@ function coin(
$result = $template; $result = $template;
foreach ($arguments as $key => $value) foreach ($arguments as $key => $value)
{ {
if ($value === null) $result = \str_replace(\sprintf('{{%s}}', $key), $value, $result);
{
// do nothing
}
else
{
$result = \str_replace(
\sprintf('{{%s}}', $key),
$value,
$result
);
}
} }
return $result; return $result;
} }

View file

@ -7,11 +7,9 @@ define("DIR_LOGIC", "logic");
require_once('vendor/autoload.php'); require_once('vendor/autoload.php');
require_once(DIR_LOGIC . '/base.php'); require_once(DIR_LOGIC . '/base.php');
require_once(DIR_LOGIC . '/overwrites/principal_backend.php'); require_once(DIR_LOGIC . '/overwrites/principal_backend.php');
require_once(DIR_LOGIC . '/overwrites/auth_backend.php'); require_once(DIR_LOGIC . '/overwrites/auths/_factory.php');
require_once(DIR_LOGIC . '/overwrites/caldav_backend.php'); require_once(DIR_LOGIC . '/overwrites/caldav_backend.php');
require_once(DIR_LOGIC . '/sources/_factory.php'); require_once(DIR_LOGIC . '/sources/_factory.php');
require_once(DIR_LOGIC . '/auths/_factory.php');
require_once(DIR_LOGIC . '/model.php');
require_once(DIR_LOGIC . '/conf.php'); require_once(DIR_LOGIC . '/conf.php');
@ -22,38 +20,21 @@ function main(
\davina\set_parameters([]); \davina\set_parameters([]);
\date_default_timezone_set(\davina\conf\get()['settings']['timezone']); \date_default_timezone_set(\davina\conf\get()->settings->timezone);
/** $source = \davina\sources\make(
* @todo nicht einfach die realm names als keys verwenden [
*/ 'kind' => \davina\conf\get()->source->kind,
$realms = []; 'data' => \davina\conf\get()->source->data,
foreach (\davina\conf\get()['realms'] as $realm_raw) ]
{
$realms[$realm_raw['name']] = new \davina\model\struct_realm(
$realm_raw['name'],
\davina\auths\make(
$realm_raw['auth']['kind'],
$realm_raw['auth']['data']
),
\davina\sources\make(
$realm_raw['source']['kind'],
$realm_raw['source']['data']
)
); );
}
$principal_backend = new \davina\overwrites\class_principle_backend($realms); $principal_backend = new \davina\overwrites\class_principle_backend();
$server = new \Sabre\DAV\Server( $server = new \Sabre\DAV\Server(
[ [
new \Sabre\CalDAV\Principal\Collection( new \Sabre\CalDAV\Principal\Collection($principal_backend),
$principal_backend new \Sabre\CalDAV\CalendarRoot($principal_backend, new \davina\overwrites\class_caldav_backend($source)),
),
new \Sabre\CalDAV\CalendarRoot(
$principal_backend,
new \davina\overwrites\class_caldav_backend($realms)
),
] ]
); );
@ -61,8 +42,12 @@ function main(
$server->addPlugin( $server->addPlugin(
new \Sabre\DAV\Auth\Plugin( new \Sabre\DAV\Auth\Plugin(
new \davina\overwrites\class_auth_backend( \davina\overwrites\make_auth_backend(
$realms $source,
[
'kind' => \davina\conf\get()->auth->kind,
'data' => \davina\conf\get()->auth->data,
]
) )
) )
); );
@ -79,7 +64,7 @@ function main(
/** /**
* not required * not required
*/ */
// $server->addPlugin(new \Sabre\DAV\Browser\Plugin()); $server->addPlugin(new \Sabre\DAV\Browser\Plugin());
$server->start(); $server->start();
} }

View file

@ -116,40 +116,4 @@ function calendar_from_raw(
)); ));
} }
/**
*/
class struct_realm
{
/**
*/
public string $name;
/**
*/
public \davina\auths\interface_auth $auth;
/**
*/
public \davina\sources\interface_source $source;
/**
*/
public function __construct(
string $name,
\davina\auths\interface_auth $auth,
\davina\sources\interface_source $source
)
{
$this->name = $name;
$this->auth = $auth;
$this->source = $source;
}
}
?> ?>

View file

@ -1,86 +0,0 @@
<?php
namespace davina\overwrites;
require_once('vendor/autoload.php');
require_once(DIR_LOGIC . '/base.php');
/**
*/
class class_auth_backend
extends \Sabre\DAV\Auth\Backend\AbstractBasic
implements \Sabre\DAV\Auth\Backend\BackendInterface
{
/**
* @var array {list<\davina\sources\interface_source>}
*/
private array $realms;
/**
*/
public function __construct(
array $realms
)
{
// parent::__construct();
$this->realms = $realms;
$this->setRealm('davina');
}
/**
*/
protected function validateUserPass(
/*string */$identifier,
/*string */$password
)/* : bool*/
{
$parts = \explode('-', $identifier, 2);
$realm_name = $parts[0];
$credentials = [
'username' => (
(\count($parts) >= 2)
?
$parts[1]
:
null
),
'password' => $password,
];
if (! \array_key_exists($realm_name, $this->realms))
{
return false;
}
else
{
$realm = $this->realms[$realm_name];
if (! $realm->auth->check($credentials))
{
return false;
}
else
{
/**
* @todo check for security
*/
\davina\set_parameters(
\array_merge(
$realm->auth->determine_parameters($credentials),
[
'realm_name' => $realm_name,
]
)
);
$data = $realm->source->read();
return ($data !== null);
}
}
}
}
?>

View file

@ -0,0 +1,37 @@
<?php
namespace davina\overwrites;
require_once('vendor/autoload.php');
require_once(DIR_LOGIC . '/sources/_interface.php');
require_once(DIR_LOGIC . '/overwrites/auths/none.php');
require_once(DIR_LOGIC . '/overwrites/auths/basic.php');
/**
*/
function make_auth_backend(
\davina\sources\interface_source $source,
array $descriptor
) : \Sabre\DAV\Auth\Backend\BackendInterface
{
switch ($descriptor['kind'])
{
case 'none':
{
return (new \davina\overwrites\class_auth_backend_none());
break;
}
case 'basic':
{
return (new \davina\overwrites\class_auth_backend_basic($source));
break;
}
default:
{
throw (new \Exception(\sprintf('unhandled auth backend kind: %s', $descriptor['kind'])));
break;
}
}
}
?>

View file

@ -0,0 +1,55 @@
<?php
namespace davina\overwrites;
require_once('vendor/autoload.php');
require_once(DIR_LOGIC . '/base.php');
require_once(DIR_LOGIC . '/sources/_interface.php');
/**
*/
class class_auth_backend_basic
extends \Sabre\DAV\Auth\Backend\AbstractBasic
implements \Sabre\DAV\Auth\Backend\BackendInterface
{
/**
*/
private \davina\sources\interface_source $source;
/**
*/
public function __construct(
\davina\sources\interface_source $source
)
{
// parent::__construct();
$this->source = $source;
$this->setRealm('davina');
}
/**
*/
protected function validateUserPass(
/*string */$username,
/*string */$password
)/* : bool*/
{
$parameters = [
'username' => $username,
'password' => $password,
];
/**
* @todo check for security
*/
\davina\set_parameters($parameters);
$data = $this->source->get(/*$parameters*/[]);
return ($data !== null);
}
}
?>

View file

@ -0,0 +1,39 @@
<?php
namespace davina\overwrites;
require_once('vendor/autoload.php');
require_once(DIR_LOGIC . '/sources/_interface.php');
/**
*/
class class_auth_backend_none
implements \Sabre\DAV\Auth\Backend\BackendInterface
{
/**
* @todo other principal uri?
*/
public function check(
\Sabre\HTTP\RequestInterface $request,
\Sabre\HTTP\ResponseInterface $response
)
{
return [true, 'principals/dummy'];
}
/**
*/
public function challenge(
\Sabre\HTTP\RequestInterface $request,
\Sabre\HTTP\ResponseInterface $response
)
{
// do nothing
}
}
?>

View file

@ -4,9 +4,9 @@ namespace davina\overwrites;
require_once('vendor/autoload.php'); require_once('vendor/autoload.php');
require_once(DIR_LOGIC . '/helpers/call.php'); require_once(DIR_LOGIC . '/helpers/call.php');
require_once(DIR_LOGIC . '/helpers/list.php');
require_once(DIR_LOGIC . '/helpers/ics.php'); require_once(DIR_LOGIC . '/helpers/ics.php');
require_once(DIR_LOGIC . '/model.php'); require_once(DIR_LOGIC . '/model.php');
require_once(DIR_LOGIC . '/sources/_interface.php');
require_once(DIR_LOGIC . '/conf.php'); require_once(DIR_LOGIC . '/conf.php');
@ -19,25 +19,50 @@ class class_caldav_backend
/** /**
* @var array {map<string, \davina\model\struct_realm>}
*/ */
private array $realms; private \davina\sources\interface_source $source;
/**
*/
private ?string $selected_realm_name;
/** /**
*/ */
public function __construct( public function __construct(
array $realms \davina\sources\interface_source $source
) )
{ {
// parent::__construct(); // parent::__construct();
$this->realms = $realms; $this->source = $source;
$this->selected_realm_name = null; }
/**
*/
private function hash_tag(
string $tag
) : string
{
return \hash('sha256', $tag);
}
/**
*/
private function encode_tag(
string $tag
) : string
{
return \davina\helpers\call\convey(
$tag,
[
fn($x) => \strtolower($x),
fn($x) => \preg_replace('/ä/', 'ae', $x),
fn($x) => \preg_replace('/ö/', 'oe', $x),
fn($x) => \preg_replace('/ü/', 'ue', $x),
fn($x) => \preg_replace('/ß/', 'sz', $x),
fn($x) => \preg_replace('/\-/', '', $x),
fn($x) => \preg_replace('/ /', '-', $x),
fn($x) => \preg_replace('/[^a-zA-Z0-9_\-]/s', '_', $x),
]
);
} }
@ -100,118 +125,6 @@ class class_caldav_backend
} }
/**
*/
private function encode_tag(
?string $tag
) : ?string
{
if ($tag === null)
{
return null;
}
else
{
return \davina\helpers\call\convey(
$tag,
[
fn($x) => \strtolower($x),
fn($x) => \preg_replace('/ä/', 'ae', $x),
fn($x) => \preg_replace('/ö/', 'oe', $x),
fn($x) => \preg_replace('/ü/', 'ue', $x),
fn($x) => \preg_replace('/ß/', 'sz', $x),
fn($x) => \preg_replace('/\-/', '', $x),
fn($x) => \preg_replace('/ /', '-', $x),
fn($x) => \preg_replace('/[^a-zA-Z0-9_\-]/s', '_', $x),
]
);
}
}
/**
* @param array $parameters {
* record<
* realm_name:string,
* calendar_name:(null|string),
* >
* }
*/
private function encode_calendar_identifier(
array $parameters
) : string
{
$str = $parameters['realm_name'];
if ($parameters['calendar_name'] === null)
{
// do nothing
}
else
{
$str .= \sprintf(
'-%s',
$parameters['calendar_name']
);
}
return $str;
}
/**
* @return array {
* record<
* realm_name:string,
* calendar_name:(null|string),
* >
* }
*/
private function decode_calendar_identifier(
string $str
) : array
{
$parts = \explode('-', $str, 2);
return [
'realm_name' => $parts[0],
'calendar_name' => (
(count($parts) < 2)
?
null
:
$parts[1]
),
];
}
/**
*/
private function get_source(
string $realm_name
) : \davina\sources\interface_source
{
if (
($this->selected_realm_name === null)
||
($this->selected_realm_name === $realm_name)
)
{
$this->selected_realm_name = $realm_name;
if (! \array_key_exists($realm_name, $this->realms))
{
throw (new \Exception(\sprintf('no such realm: %s', $realm_name)));
}
else
{
return $this->realms[$realm_name]->source;
}
}
else
{
throw (new \Exception('may not change source'));
}
}
/** /**
* [implementation] * [implementation]
*/ */
@ -219,11 +132,7 @@ class class_caldav_backend
$principalUri $principalUri
) )
{ {
// $source = $this->source; $calendar = $this->source->get([]);
// $realm_name = \explode('/', $principalUri)[1];
$realm_name = \davina\get_parameters()['realm_name'];
$source = $this->get_source($realm_name);
$calendar = $source->read();
$tags = []; $tags = [];
foreach ($calendar->events as $event) foreach ($calendar->events as $event)
{ {
@ -232,42 +141,18 @@ class class_caldav_backend
$tags[$tag] = null; $tags[$tag] = null;
} }
} }
return \davina\helpers\call\convey( $result = \array_map(
$tags,
[
fn($x) => (
(\count($x) <= 0)
?
[null]
:
\array_keys($x)
),
fn($x) => \davina\helpers\list_\map(
$x,
fn($tag) => [ fn($tag) => [
'id' => $this->encode_calendar_identifier( 'id' => $this->hash_tag($tag),
[ 'uri' => $this->encode_tag($tag),
'realm_name' => $realm_name,
'calendar_name' => $this->encode_tag($tag),
]
),
// 'uri' => $this->encode_tag($tag),
'uri' => $this->encode_calendar_identifier(
[
'realm_name' => $realm_name,
'calendar_name' => $this->encode_tag($tag),
]
),
'principaluri' => $principalUri, 'principaluri' => $principalUri,
'{DAV:}displayname' => ($tag ?? $realm_name), '{DAV:}displayname' => $tag,
\sprintf( \sprintf('{%s}supported-calendar-component-set', \Sabre\CalDAV\Plugin::NS_CALDAV) => new \Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet(['VEVENT']),
'{%s}supported-calendar-component-set',
\Sabre\CalDAV\Plugin::NS_CALDAV
) => new \Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet(['VEVENT']),
]
),
], ],
\array_keys($tags)
); );
// \error_log(\json_encode($result, \JSON_PRETTY_PRINT));
return $result;
} }
@ -302,32 +187,9 @@ class class_caldav_backend
$calendarId $calendarId
) )
{ {
$calendar_identifier = $this->decode_calendar_identifier($calendarId); $tag = $calendarId;
// $realm_name = $calendar_identifier['realm_name']; $calendar = $this->source->get([]);
$realm_name = \davina\get_parameters()['realm_name']; $result = \array_map(
$source = $this->get_source($realm_name);
$tag = $calendar_identifier['calendar_name'];
$calendar = $source->read();
return \davina\helpers\call\convey(
$calendar->events,
[
fn($x) => \davina\helpers\list_\filter(
$x,
fn($event) => (
(\count($event->tags) <= 0)
||
\in_array(
$tag,
\davina\helpers\list_\map(
$event->tags,
fn($x) => $this->encode_tag($x)
)
)
)
),
fn($x) => \davina\helpers\list_\map(
$x,
fn($event) => [ fn($event) => [
'calendarid' => $calendarId, 'calendarid' => $calendarId,
'id' => $event->id, 'id' => $event->id,
@ -339,9 +201,20 @@ class class_caldav_backend
'component' => 'vevent', 'component' => 'vevent',
'{DAV:}displayname' => $event->title, '{DAV:}displayname' => $event->title,
], ],
), \array_values(
] \array_filter(
$calendar->events,
fn($event) => \in_array(
$tag,
\array_map(
fn($x) => $this->hash_tag($x),
$event->tags
)
)
)
)
); );
return $result;
} }
@ -354,16 +227,12 @@ class class_caldav_backend
) )
{ {
$id = $objectUri; $id = $objectUri;
$calendar_identifier = $this->decode_calendar_identifier($calendarId); $calendar = $this->source->get([]);
// $realm_name = $calendar_identifier['realm_name']; $events = \array_values(
$realm_name = \davina\get_parameters()['realm_name']; \array_filter(
$source = $this->get_source($realm_name);
$tag = $calendar_identifier['calendar_name'];
$calendar = $source->read();
$events = \davina\helpers\list_\filter(
$calendar->events, $calendar->events,
fn($event) => ($event->id === $id) fn($event) => ($event->id === $id)
)
); );
if (\count($events) < 1) if (\count($events) < 1)
{ {

View file

@ -3,7 +3,6 @@
namespace davina\overwrites; namespace davina\overwrites;
require_once('vendor/autoload.php'); require_once('vendor/autoload.php');
require_once(DIR_LOGIC . '/helpers/list.php');
/** /**
@ -13,33 +12,17 @@ class class_principle_backend
{ {
/** /**
* @var array {map<string, \davina\model\struct_realm>}
*/ */
private array $realms; public function getPrincipalsByPrefix($prefixPath)
/**
*/
public function __construct(
array $realms
)
{
$this->realms = $realms;
}
/**
*/
public function getPrincipalsByPrefix(
$prefixPath
)
{ {
throw (new \Exception('not implemented: getPrincipalsByPrefix'));
/*
return [ return [
[ [
'uri' => 'principals/-', 'uri' => 'principals/dummy',
'{DAV:}displayname' => 'default', ]
],
]; ];
*/
} }
@ -49,6 +32,7 @@ class class_principle_backend
$path $path
) )
{ {
// throw (new \Exception('not implemented: getPrincipalByPath'));
$parts = \explode('/', $path); $parts = \explode('/', $path);
$username = $parts[1]; $username = $parts[1];
return [ return [

View file

@ -2,26 +2,30 @@
namespace davina\sources; namespace davina\sources;
require_once(DIR_LOGIC . '/sources/_interface.php');
require_once(DIR_LOGIC . '/sources/ics_feed.php'); require_once(DIR_LOGIC . '/sources/ics_feed.php');
/** /**
* @param array $descriptor {
* record<
* kind:string,
* data:any
* >
* }
*/ */
function make( function make(
string $kind, array $descriptor
$data
) : interface_source ) : interface_source
{ {
switch ($kind) switch ($descriptor['kind'])
{ {
case 'ics_feed': case 'ics_feed':
{ {
return ( return (
new class_source_ics_feed( new class_source_ics_feed(
$data['url'], $descriptor['data']['url'],
$data['lifetime'], ($descriptor['data']['lifetime'] ?? (60 * 15)),
$data['conflate'] ($descriptor['data']['combine'] ?? false)
) )
); );
} }
@ -31,7 +35,7 @@ function make(
new \Exception( new \Exception(
\sprintf( \sprintf(
'unhandled source kind: %s', 'unhandled source kind: %s',
$kind $descriptor['kind']
) )
) )
); );
@ -40,4 +44,4 @@ function make(
} }
} }
?>

View file

@ -9,8 +9,15 @@ interface interface_source
{ {
/** /**
* @param array $parameters {
* record<
* username:(null|string),
* password:(null|string),
* >
* }
*/ */
public function read( public function get(
array $parameters
) : \davina\model\struct_calendar ) : \davina\model\struct_calendar
; ;

View file

@ -7,7 +7,6 @@ require_once(DIR_LOGIC . '/helpers/cache.php');
require_once(DIR_LOGIC . '/helpers/pit.php'); require_once(DIR_LOGIC . '/helpers/pit.php');
require_once(DIR_LOGIC . '/helpers/ics.php'); require_once(DIR_LOGIC . '/helpers/ics.php');
require_once(DIR_LOGIC . '/base.php'); require_once(DIR_LOGIC . '/base.php');
require_once(DIR_LOGIC . '/sources/_interface.php');
require_once(DIR_LOGIC . '/model.php'); require_once(DIR_LOGIC . '/model.php');
@ -29,7 +28,7 @@ class class_source_ics_feed
/** /**
*/ */
private bool $conflate; private bool $combine;
/** /**
@ -37,12 +36,12 @@ class class_source_ics_feed
public function __construct( public function __construct(
string $url_template, string $url_template,
?int $lifetime, ?int $lifetime,
bool $conflate bool $combine
) )
{ {
$this->url_template = $url_template; $this->url_template = $url_template;
$this->lifetime = $lifetime; $this->lifetime = $lifetime;
$this->conflate = $conflate; $this->combine = $combine;
$this->cache_file = \davina\helpers\call\convey( $this->cache_file = \davina\helpers\call\convey(
new \davina\helpers\cache\class_cache_file('data'), new \davina\helpers\cache\class_cache_file('data'),
[ [
@ -69,10 +68,7 @@ class class_source_ics_feed
{ {
return \davina\helpers\string_\coin( return \davina\helpers\string_\coin(
$this->url_template, $this->url_template,
[ $parameters
'username' => ($parameters['auth_username'] ?? null),
'password' => ($parameters['auth_password'] ?? null),
]
); );
} }
@ -80,8 +76,7 @@ class class_source_ics_feed
/** /**
*/ */
private function vcalendar_to_calendar( private function vcalendar_to_calendar(
\davina\helpers\ics\struct_vcalendar $vcalendar, \davina\helpers\ics\struct_vcalendar $vcalendar
?string $realm_name
) : \davina\model\struct_calendar ) : \davina\model\struct_calendar
{ {
return ( return (
@ -92,10 +87,8 @@ class class_source_ics_feed
$vevent->uid, $vevent->uid,
// title // title
( (
(! $this->conflate) $this->combine
? ?
$vevent->summary
:
\sprintf( \sprintf(
'%s%s', '%s%s',
$vevent->summary, $vevent->summary,
@ -107,6 +100,8 @@ class class_source_ics_feed
) )
) )
) )
:
$vevent->summary
), ),
// begin // begin
\davina\helpers\ics\datetime_to_unix_timestamp($vevent->dtstart->value), \davina\helpers\ics\datetime_to_unix_timestamp($vevent->dtstart->value),
@ -124,11 +119,11 @@ class class_source_ics_feed
$vevent->description, $vevent->description,
// 'tags // 'tags
( (
(! $this->conflate) $this->combine
? ?
$vevent->categories ['combined']
: :
[] $vevent->categories
) )
)), )),
$vcalendar->events $vcalendar->events
@ -141,8 +136,7 @@ class class_source_ics_feed
/** /**
*/ */
private function retrieve( private function retrieve(
string $url, string $url
?string $realm_name
) )
{ {
$client = new \Sabre\HTTP\Client(); $client = new \Sabre\HTTP\Client();
@ -160,7 +154,7 @@ class class_source_ics_feed
{ {
$ics = $response->getBody(); $ics = $response->getBody();
$vcalendar = \davina\helpers\ics\vcalendar_decode($ics); $vcalendar = \davina\helpers\ics\vcalendar_decode($ics);
$calendar = $this->vcalendar_to_calendar($vcalendar, $realm_name); $calendar = $this->vcalendar_to_calendar($vcalendar);
$calendar_raw = \davina\model\calendar_to_raw($calendar); $calendar_raw = \davina\model\calendar_to_raw($calendar);
return $calendar_raw; return $calendar_raw;
break; break;
@ -184,19 +178,14 @@ class class_source_ics_feed
/** /**
* [implementation] * [implementation]
*/ */
public function read( public function get(
array $parameters
) : \davina\model\struct_calendar ) : \davina\model\struct_calendar
{ {
$parameters = \davina\get_parameters(); $url = $this->url(\davina\get_parameters());
$url = $this->url($parameters); $key = $url;
$key = \sprintf(
'%s:%u',
$url,
$this->conflate
);
$f1 = fn() => $this->retrieve( $f1 = fn() => $this->retrieve(
$url, $url
$parameters['realm_name']
); );
$f2 = fn() => \davina\helpers\cache\get( $f2 = fn() => \davina\helpers\cache\get(
$this->cache_file, $this->cache_file,

View file

@ -47,7 +47,6 @@ def main():
"--links", "--links",
"--verbose", "--verbose",
"--exclude='conf.json'", "--exclude='conf.json'",
"--exclude='data'",
("%s/" % args.build_directory), ("%s/" % args.build_directory),
( (
("%s" % args.target_directory) ("%s" % args.target_directory)