Compare commits

...

4 commits

Author SHA1 Message Date
fenris 410cf16794 [mod] readme 2025-09-16 12:40:25 +02:00
fenris 085303a94c [del] tools:run 2025-09-16 12:39:25 +02:00
fenris 7ae9bc62e1 [mod] tools:build:auf python umgestellt 2025-09-16 12:38:52 +02:00
fenris 40361269e5 [mod] rename to "davina" 2025-09-16 12:05:35 +02:00
20 changed files with 192 additions and 135 deletions

View file

@ -1,4 +1,4 @@
# davigil
# davina
## Beschreibung
@ -15,8 +15,7 @@
### Anweisungen
- `tools/make-db` ausführen (einmalig)
- `tools/build` ausführen
- `tools/build` ausführen (Schalter `-h` anfügen für Erklärungen)
## Betrieb

View file

@ -1,6 +1,6 @@
<?php
namespace davigil;
namespace davina;
/**

View file

@ -1,6 +1,6 @@
<?php
namespace davigil\conf;
namespace davina\conf;
/**

View file

@ -1,6 +1,6 @@
<?php
namespace davigil\helpers\cache;
namespace davina\helpers\cache;
/**
@ -267,7 +267,7 @@ class class_cache_apcu
{
$options = \array_merge(
[
'prefix' => 'davigil_',
'prefix' => 'davina_',
],
($options ?? [])
);

View file

@ -1,6 +1,6 @@
<?php
namespace davigil\helpers\call;
namespace davina\helpers\call;
/**

View file

@ -1,6 +1,6 @@
<?php
namespace davigil\helpers\ics;
namespace davina\helpers\ics;
require_once('vendor/autoload.php');
require_once('helpers/string.php');
@ -520,7 +520,7 @@ function date_encode(
struct_date $date
) : string
{
return \davigil\helpers\string_\coin(
return \davina\helpers\string_\coin(
'{{year}}{{month}}{{day}}',
[
'year' => \str_pad(\sprintf('%u', $date->year), 4, '0', \STR_PAD_LEFT),
@ -537,7 +537,7 @@ function time_encode(
struct_time $time
) : string
{
return \davigil\helpers\string_\coin(
return \davina\helpers\string_\coin(
'{{hour}}{{minute}}{{second}}{{utc}}',
[
'hour' => \str_pad(\sprintf('%u', $time->hour), 2, '0', \STR_PAD_LEFT),
@ -555,7 +555,7 @@ function datetime_encode(
struct_datetime $datetime
) : string
{
return \davigil\helpers\string_\coin(
return \davina\helpers\string_\coin(
'{{date}}T{{time}}',
[
'date' => date_encode($datetime->date),
@ -574,9 +574,9 @@ function vcalendar_encode(
{
$content_lines = [];
\array_push($content_lines, 'BEGIN:VCALENDAR');
\array_push($content_lines, \davigil\helpers\string_\coin('VERSION:{{version}}', ['version' => $vcalendar->version]));
\array_push($content_lines, \davigil\helpers\string_\coin('PRODID:{{prodid}}', ['prodid' => $vcalendar->prodid]));
\array_push($content_lines, \davigil\helpers\string_\coin('METHOD:{{method}}', ['method' => $vcalendar->method]));
\array_push($content_lines, \davina\helpers\string_\coin('VERSION:{{version}}', ['version' => $vcalendar->version]));
\array_push($content_lines, \davina\helpers\string_\coin('PRODID:{{prodid}}', ['prodid' => $vcalendar->prodid]));
\array_push($content_lines, \davina\helpers\string_\coin('METHOD:{{method}}', ['method' => $vcalendar->method]));
foreach ($vcalendar->events as $vevent)
{
\array_push($content_lines, 'BEGIN:VEVENT');
@ -584,7 +584,7 @@ function vcalendar_encode(
// uid
\array_push(
$content_lines,
\davigil\helpers\string_\coin(
\davina\helpers\string_\coin(
'UID:{{uid}}',
[
'uid' => $vevent->uid,
@ -595,7 +595,7 @@ function vcalendar_encode(
// dtstart
\array_push(
$content_lines,
\davigil\helpers\string_\coin(
\davina\helpers\string_\coin(
'DTSTART:{{dtstart}}',
[
'dtstart' => datetime_encode($vevent->dtstart->value),
@ -608,7 +608,7 @@ function vcalendar_encode(
{
\array_push(
$content_lines,
\davigil\helpers\string_\coin(
\davina\helpers\string_\coin(
'DTEND:{{dtend}}',
[
'dtend' => datetime_encode($vevent->dtend->value),
@ -620,7 +620,7 @@ function vcalendar_encode(
// dtstamp
\array_push(
$content_lines,
\davigil\helpers\string_\coin(
\davina\helpers\string_\coin(
'DTSTAMP:{{dtstamp}}',
[
'dtstamp' => datetime_encode($vevent->dtstamp),
@ -633,7 +633,7 @@ function vcalendar_encode(
{
\array_push(
$content_lines,
\davigil\helpers\string_\coin(
\davina\helpers\string_\coin(
'CLASS:{{class}}',
[
'class' => class_encode($vevent->class),
@ -645,7 +645,7 @@ function vcalendar_encode(
// summary
\array_push(
$content_lines,
\davigil\helpers\string_\coin(
\davina\helpers\string_\coin(
'SUMMARY:{{summary}}',
[
'summary' => $vevent->summary,
@ -658,7 +658,7 @@ function vcalendar_encode(
{
\array_push(
$content_lines,
\davigil\helpers\string_\coin(
\davina\helpers\string_\coin(
'DESCRIPTION:{{description}}',
[
'description' => $vevent->description,
@ -672,7 +672,7 @@ function vcalendar_encode(
{
\array_push(
$content_lines,
\davigil\helpers\string_\coin(
\davina\helpers\string_\coin(
'LOCATION:{{location}}',
[
'location' => $vevent->location,
@ -719,7 +719,7 @@ function vcalendar_encode(
{
\array_push(
$content_lines,
\davigil\helpers\string_\coin(
\davina\helpers\string_\coin(
'CATEGORIES:{{categories}}',
[
'categories' => \implode(',', $vevent->categories),
@ -735,7 +735,7 @@ function vcalendar_encode(
$lines = [];
foreach ($content_lines as $content_line)
{
$slices = \davigil\helpers\string_\slice($content_line, 75 - 1);
$slices = \davina\helpers\string_\slice($content_line, 75 - 1);
\array_push($lines, $slices[0]);
foreach (\array_slice($slices, 1) as $slice)
{
@ -753,11 +753,11 @@ function datetime_to_unix_timestamp(
struct_datetime $datetime
) : int
{
return \davigil\helpers\pit\pit_to_unix_timestamp(
\davigil\helpers\pit\pit_from_datetime(
new \davigil\helpers\pit\struct_datetime(
return \davina\helpers\pit\pit_to_unix_timestamp(
\davina\helpers\pit\pit_from_datetime(
new \davina\helpers\pit\struct_datetime(
0,
new \davigil\helpers\pit\struct_date(
new \davina\helpers\pit\struct_date(
$datetime->date->year,
$datetime->date->month,
$datetime->date->day
@ -767,7 +767,7 @@ function datetime_to_unix_timestamp(
?
null
:
new \davigil\helpers\pit\struct_time(
new \davina\helpers\pit\struct_time(
$datetime->time->hour,
$datetime->time->minute,
$datetime->time->second
@ -785,8 +785,8 @@ function datetime_from_unix_timestamp(
int $unix_timestamp
) : struct_datetime
{
$pit = \davigil\helpers\pit\pit_from_unix_timestamp($unix_timestamp);
$datetime = \davigil\helpers\pit\pit_to_datetime($pit);
$pit = \davina\helpers\pit\pit_from_unix_timestamp($unix_timestamp);
$datetime = \davina\helpers\pit\pit_to_datetime($pit);
return (new struct_datetime(
new struct_date(
$datetime->date->year,

View file

@ -1,6 +1,6 @@
<?php
namespace davigil\helpers\pit;
namespace davina\helpers\pit;
require_once('helpers/call.php');
require_once('helpers/string.php');
@ -90,24 +90,24 @@ function date_to_string(
struct_date $date
) : string
{
return \davigil\helpers\string_\coin(
return \davina\helpers\string_\coin(
'{{year}}{{month}}{{day}}',
[
'year' => \davigil\helpers\call\convey(
'year' => \davina\helpers\call\convey(
$date->year,
[
fn($x) => \sprintf('%u', $x),
fn($x) => \str_pad($x, 4, '0', \STR_PAD_LEFT),
]
),
'month' => \davigil\helpers\call\convey(
'month' => \davina\helpers\call\convey(
$date->month,
[
fn($x) => \sprintf('%u', $x),
fn($x) => \str_pad($x, 2, '0', \STR_PAD_LEFT),
]
),
'day' => \davigil\helpers\call\convey(
'day' => \davina\helpers\call\convey(
$date->day,
[
fn($x) => \sprintf('%u', $x),
@ -125,24 +125,24 @@ function time_to_string(
struct_time $time
) : string
{
return \davigil\helpers\string_\coin(
return \davina\helpers\string_\coin(
'{{hour}}{{minute}}{{second}}',
[
'hour' => \davigil\helpers\call\convey(
'hour' => \davina\helpers\call\convey(
$time->hour,
[
fn($x) => \sprintf('%u', $x),
fn($x) => \str_pad($x, 2, '0', \STR_PAD_LEFT),
]
),
'minute' => \davigil\helpers\call\convey(
'minute' => \davina\helpers\call\convey(
$time->minute,
[
fn($x) => \sprintf('%u', $x),
fn($x) => \str_pad($x, 2, '0', \STR_PAD_LEFT),
]
),
'second' => \davigil\helpers\call\convey(
'second' => \davina\helpers\call\convey(
$time->second,
[
fn($x) => \sprintf('%u', $x),
@ -160,7 +160,7 @@ function datetime_to_string(
struct_datetime $datetime
) : string
{
return \davigil\helpers\string_\coin(
return \davina\helpers\string_\coin(
'{{date}}{{macro_time}}',
[
'date' => date_to_string($datetime->date),
@ -169,7 +169,7 @@ function datetime_to_string(
?
''
:
\davigil\helpers\string_\coin(
\davina\helpers\string_\coin(
'T{{time}}{{utc}}',
[
'time' => time_to_string($datetime->time),

View file

@ -1,6 +1,6 @@
<?php
namespace davigil\helpers\string_;
namespace davina\helpers\string_;
/**

View file

@ -1,6 +1,6 @@
<?php
namespace davigil;
namespace davina;
require_once('vendor/autoload.php');
require_once('base.php');
@ -14,25 +14,25 @@ require_once('conf.php');
function main(
) : void
{
\davigil\conf\load('conf.json');
\davina\conf\load('conf.json');
\davigil\set_parameters([]);
\davina\set_parameters([]);
\date_default_timezone_set(\davigil\conf\get()->settings->timezone);
\date_default_timezone_set(\davina\conf\get()->settings->timezone);
$source = \davigil\sources\make(
$source = \davina\sources\make(
[
'kind' => \davigil\conf\get()->source->kind,
'data' => \davigil\conf\get()->source->data,
'kind' => \davina\conf\get()->source->kind,
'data' => \davina\conf\get()->source->data,
]
);
$principal_backend = new \davigil\overwrites\class_principle_backend();
$principal_backend = new \davina\overwrites\class_principle_backend();
$server = new \Sabre\DAV\Server(
[
new \Sabre\CalDAV\Principal\Collection($principal_backend),
new \Sabre\CalDAV\CalendarRoot($principal_backend, new \davigil\overwrites\class_caldav_backend($source)),
new \Sabre\CalDAV\CalendarRoot($principal_backend, new \davina\overwrites\class_caldav_backend($source)),
]
);
@ -40,11 +40,11 @@ function main(
$server->addPlugin(
new \Sabre\DAV\Auth\Plugin(
\davigil\overwrites\make_auth_backend(
\davina\overwrites\make_auth_backend(
$source,
[
'kind' => \davigil\conf\get()->auth->kind,
'data' => \davigil\conf\get()->auth->data,
'kind' => \davina\conf\get()->auth->kind,
'data' => \davina\conf\get()->auth->data,
]
)
)

View file

@ -1,6 +1,6 @@
<?php
namespace davigil\model;
namespace davina\model;
/**

View file

@ -1,6 +1,6 @@
<?php
namespace davigil\overwrites;
namespace davina\overwrites;
require_once('vendor/autoload.php');
require_once('sources/_interface.php');
@ -11,7 +11,7 @@ require_once('overwrites/auths/basic.php');
/**
*/
function make_auth_backend(
\davigil\sources\interface_source $source,
\davina\sources\interface_source $source,
array $descriptor
) : \Sabre\DAV\Auth\Backend\BackendInterface
{
@ -19,12 +19,12 @@ function make_auth_backend(
{
case 'none':
{
return (new \davigil\overwrites\class_auth_backend_none());
return (new \davina\overwrites\class_auth_backend_none());
break;
}
case 'basic':
{
return (new \davigil\overwrites\class_auth_backend_basic($source));
return (new \davina\overwrites\class_auth_backend_basic($source));
break;
}
default:

View file

@ -1,6 +1,6 @@
<?php
namespace davigil\overwrites;
namespace davina\overwrites;
require_once('vendor/autoload.php');
require_once('base.php');
@ -16,18 +16,18 @@ class class_auth_backend_basic
/**
*/
private \davigil\sources\interface_source $source;
private \davina\sources\interface_source $source;
/**
*/
public function __construct(
\davigil\sources\interface_source $source
\davina\sources\interface_source $source
)
{
// parent::__construct();
$this->source = $source;
$this->setRealm('davigil');
$this->setRealm('davina');
}
@ -45,7 +45,7 @@ class class_auth_backend_basic
/**
* @todo check for security
*/
\davigil\set_parameters($parameters);
\davina\set_parameters($parameters);
$data = $this->source->get(/*$parameters*/[]);
return ($data !== null);
}

View file

@ -1,6 +1,6 @@
<?php
namespace davigil\overwrites;
namespace davina\overwrites;
require_once('vendor/autoload.php');
require_once('sources/_interface.php');

View file

@ -1,6 +1,6 @@
<?php
namespace davigil\overwrites;
namespace davina\overwrites;
require_once('vendor/autoload.php');
require_once('helpers/call.php');
@ -20,13 +20,13 @@ class class_caldav_backend
/**
*/
private \davigil\sources\interface_source $source;
private \davina\sources\interface_source $source;
/**
*/
public function __construct(
\davigil\sources\interface_source $source
\davina\sources\interface_source $source
)
{
// parent::__construct();
@ -50,7 +50,7 @@ class class_caldav_backend
string $tag
) : string
{
return \davigil\helpers\call\convey(
return \davina\helpers\call\convey(
$tag,
[
fn($x) => \strtolower($x),
@ -70,31 +70,31 @@ class class_caldav_backend
* @todo outsource
*/
private function event_to_vevent(
\davigil\model\struct_event $event
) : \davigil\helpers\ics\struct_vevent
\davina\model\struct_event $event
) : \davina\helpers\ics\struct_vevent
{
$vevent = new \davigil\helpers\ics\struct_vevent();
$vevent = new \davina\helpers\ics\struct_vevent();
{
$vevent->uid = $event->id;
$vevent->dtstamp = \davigil\helpers\ics\datetime_from_unix_timestamp($event->begin);
$vevent->dtstart = new \davigil\helpers\ics\struct_dt(
$vevent->dtstamp = \davina\helpers\ics\datetime_from_unix_timestamp($event->begin);
$vevent->dtstart = new \davina\helpers\ics\struct_dt(
'',
\davigil\helpers\ics\datetime_from_unix_timestamp($event->begin)
\davina\helpers\ics\datetime_from_unix_timestamp($event->begin)
);
$vevent->dtend = (
($event->end === null)
?
null
:
new \davigil\helpers\ics\struct_dt(
new \davina\helpers\ics\struct_dt(
'',
\davigil\helpers\ics\datetime_from_unix_timestamp($event->end)
\davina\helpers\ics\datetime_from_unix_timestamp($event->end)
)
);
$vevent->summary = $event->title;
$vevent->location = $event->location;
$vevent->description = $event->description;
$vevent->class = \davigil\helpers\ics\enum_class::public_;
$vevent->class = \davina\helpers\ics\enum_class::public_;
$vevent->categories = $event->tags;
}
return $vevent;
@ -106,15 +106,15 @@ class class_caldav_backend
*/
private function events_to_vcalendar(
array $events
) : \davigil\helpers\ics\struct_vcalendar
) : \davina\helpers\ics\struct_vcalendar
{
$vcalendar = new \davigil\helpers\ics\struct_vcalendar();
$vcalendar = new \davina\helpers\ics\struct_vcalendar();
{
$vcalendar->version = '2.0';
/**
* @todo conf
*/
$vcalendar->prodid = 'davigil';
$vcalendar->prodid = 'davina';
$vcalendar->method = 'PUBLISH';
$vcalendar->events = \array_map(
fn($event) => $this->event_to_vevent($event),
@ -245,7 +245,7 @@ class class_caldav_backend
else
{
$vcalendar = $this->events_to_vcalendar($events);
$ics = \davigil\helpers\ics\vcalendar_encode($vcalendar);
$ics = \davina\helpers\ics\vcalendar_encode($vcalendar);
return [
'calendardata' => $ics,
'uri' => $objectUri,

View file

@ -1,6 +1,6 @@
<?php
namespace davigil\overwrites;
namespace davina\overwrites;
require_once('vendor/autoload.php');

View file

@ -1,6 +1,6 @@
<?php
namespace davigil\sources;
namespace davina\sources;
require_once('sources/ics_feed.php');

View file

@ -1,6 +1,6 @@
<?php
namespace davigil\sources;
namespace davina\sources;
/**
@ -18,7 +18,7 @@ interface interface_source
*/
public function get(
array $parameters
) : \davigil\model\struct_calendar
) : \davina\model\struct_calendar
;
}

View file

@ -1,6 +1,6 @@
<?php
namespace davigil\sources;
namespace davina\sources;
require_once('helpers/string.php');
require_once('helpers/cache.php');
@ -42,18 +42,18 @@ class class_source_ics_feed
$this->url_template = $url_template;
$this->lifetime = $lifetime;
$this->combine = $combine;
$this->cache_file = \davigil\helpers\call\convey(
new \davigil\helpers\cache\class_cache_file('data'),
$this->cache_file = \davina\helpers\call\convey(
new \davina\helpers\cache\class_cache_file('data'),
[
fn($x) => new \davigil\helpers\cache\class_cache_encoded(
fn($x) => new \davina\helpers\cache\class_cache_encoded(
$x,
fn($value) => \json_encode($value),
fn($value_encoded) => \json_decode($value_encoded, true)
),
]
);
$this->cache_memory = \davigil\helpers\call\convey(
(new \davigil\helpers\cache\class_cache_memory()),
$this->cache_memory = \davina\helpers\call\convey(
(new \davina\helpers\cache\class_cache_memory()),
[
]
);
@ -66,7 +66,7 @@ class class_source_ics_feed
$parameters
) : string
{
return \davigil\helpers\string_\coin(
return \davina\helpers\string_\coin(
$this->url_template,
$parameters
);
@ -76,13 +76,13 @@ class class_source_ics_feed
/**
*/
private function vcalendar_to_calendar(
\davigil\helpers\ics\struct_vcalendar $vcalendar
) : \davigil\model\struct_calendar
\davina\helpers\ics\struct_vcalendar $vcalendar
) : \davina\model\struct_calendar
{
return (
new \davigil\model\struct_calendar(
new \davina\model\struct_calendar(
\array_map(
fn($vevent) => (new \davigil\model\struct_event(
fn($vevent) => (new \davina\model\struct_event(
// id
$vevent->uid,
// title
@ -104,14 +104,14 @@ class class_source_ics_feed
$vevent->summary
),
// begin
\davigil\helpers\ics\datetime_to_unix_timestamp($vevent->dtstart->value),
\davina\helpers\ics\datetime_to_unix_timestamp($vevent->dtstart->value),
// end
(
($vevent->dtend === null)
?
null
:
\davigil\helpers\ics\datetime_to_unix_timestamp($vevent->dtend->value)
\davina\helpers\ics\datetime_to_unix_timestamp($vevent->dtend->value)
),
// location
$vevent->location,
@ -153,9 +153,9 @@ class class_source_ics_feed
case 200:
{
$ics = $response->getBody();
$vcalendar = \davigil\helpers\ics\vcalendar_decode($ics);
$vcalendar = \davina\helpers\ics\vcalendar_decode($ics);
$calendar = $this->vcalendar_to_calendar($vcalendar);
$calendar_raw = \davigil\model\calendar_to_raw($calendar);
$calendar_raw = \davina\model\calendar_to_raw($calendar);
return $calendar_raw;
break;
}
@ -180,14 +180,14 @@ class class_source_ics_feed
*/
public function get(
array $parameters
) : \davigil\model\struct_calendar
) : \davina\model\struct_calendar
{
$url = $this->url(\davigil\get_parameters());
$url = $this->url(\davina\get_parameters());
$key = $url;
$f1 = fn() => $this->retrieve(
$url
);
$f2 = fn() => \davigil\helpers\cache\get(
$f2 = fn() => \davina\helpers\cache\get(
$this->cache_file,
$key,
$f1,
@ -195,7 +195,7 @@ class class_source_ics_feed
'ttl' => $this->lifetime,
]
);
$f3 = fn() => \davigil\helpers\cache\get(
$f3 = fn() => \davina\helpers\cache\get(
$this->cache_memory,
$key,
$f2,
@ -203,7 +203,7 @@ class class_source_ics_feed
'ttl' => null,
]
);
return \davigil\model\calendar_from_raw(
return \davina\model\calendar_from_raw(
($f3)()
);
}

View file

@ -1,28 +1,90 @@
#!/usr/bin/env sh
#!/usr/bin/env python3
## consts
dir_lib=lib
dir_source=source
dir_build=build
name=index.php
import os as _os
import shutil as _shutil
import argparse as _argparse
## args
def main():
## consts
conf = {
"dir_lib": "lib",
"dir_source": "source",
"dir_logic": "logic",
}
if [ $# -ge 1 ] ; then profile=$1 && shift ; else profile="" ; fi
## args
argument_parser = _argparse.ArgumentParser(
)
argument_parser.add_argument(
"-o",
"--output-directory",
default = "/tmp/davina",
type = str,
metavar = "<output-directory>",
)
argument_parser.add_argument(
"-c",
"--conf-path",
default = None,
type = str,
metavar = "<conf-path>",
)
args = argument_parser.parse_args()
## exec
### exec:directories
if True:
_os.makedirs(
args.output_directory,
exist_ok = True
)
_os.makedirs(
_os.path.join(args.output_directory, "data"),
exist_ok = True
)
_os.makedirs(
_os.path.join(args.output_directory, "public"),
exist_ok = True
)
### exec:libs
if True:
_shutil.copytree(
_os.path.join(conf["dir_lib"], "composer"),
_os.path.join(args.output_directory, "composer"),
dirs_exist_ok = True
)
### exec:sources
if True:
_shutil.copytree(
conf["dir_source"],
_os.path.join(args.output_directory, conf["dir_logic"]),
dirs_exist_ok = True
)
### exec:index
if True:
path = _os.path.join(args.output_directory, "index.php")
if (not _os.path.exists(path)):
pass
else:
_os.remove(
path
)
_os.symlink(
_os.path.join(conf["dir_logic"], "main.php"),
path
)
### exec:conf
if True:
if (args.conf_path is None):
pass
else:
_shutil.copy(
args.conf_path,
_os.path.join(args.output_directory, "conf.json")
)
print(args.output_directory)
## exec
main()
mkdir -p ${dir_build}
cp -r ${dir_lib}/composer/* ${dir_build}/
mkdir -p ${dir_build}/data
mkdir -p ${dir_build}/public
rm -f ${dir_build}/${name}
cp -r -u -v ${dir_source}/* ${dir_build}/
ln -s main.php ${dir_build}/index.php
test -z ${profile} || cp conf/${profile}.json ${dir_build}/conf.json

View file

@ -1,4 +0,0 @@
#!/usr/bin/env sh
php -S localhost:8000 -t build