Switch to new dated email format
parent
5c2a9e6c7c
commit
03feda7baf
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Http\Url;
|
||||
use Kirby\Toolkit\F;
|
||||
|
||||
Kirby::plugin('lukasbestle/dated', [
|
||||
'tags' => [
|
||||
'dated' => [
|
||||
'html' => function($tag) {
|
||||
$dated = dated();
|
||||
return '<a href="mailto:' . $dated . '">' . $dated . '</a>';
|
||||
}
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
/**
|
||||
* Returns the current dated address
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function dated(): string {
|
||||
// date in seven days
|
||||
$date = modifiedJulianDate(time() + 7 * 24 * 60 * 60);
|
||||
|
||||
return 'dated-' . $date . '@' . Url::host();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Modified Julian Date,
|
||||
* which is the Julian Date with the first two digits stripped
|
||||
* and with an offset of one day to compensate for the Julian Date
|
||||
* starting at noon instead of at midnight
|
||||
*
|
||||
* @param int $timestamp Timestamp to calculate from, defaults to the current date
|
||||
* @return int
|
||||
*/
|
||||
function modifiedJulianDate(?int $timestamp = null): int {
|
||||
$timestamp = $timestamp ?? time();
|
||||
|
||||
return gregoriantojd(
|
||||
date('m', $timestamp),
|
||||
date('d', $timestamp),
|
||||
date('Y', $timestamp)
|
||||
) - 2400001;
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Http\Url;
|
||||
use Kirby\Toolkit\F;
|
||||
|
||||
Kirby::plugin('lukasbestle/qdated', [
|
||||
'tags' => [
|
||||
'qdated' => [
|
||||
'html' => function($tag) {
|
||||
$qdated = qdated($tag->qdated);
|
||||
return '<a href="mailto:' . $qdated . '">' . $qdated . '</a>';
|
||||
}
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
/**
|
||||
* Returns the current qdated address
|
||||
* If qdated is not available, returns null
|
||||
*
|
||||
* @param string $destination
|
||||
* @return string
|
||||
*/
|
||||
function qdated(string $destination) {
|
||||
$path = $_SERVER['HOME'] . '/.config/qdated/' . $destination . '/current';
|
||||
if(!is_file($path)) return null;
|
||||
|
||||
return 'dated-' . trim(F::read($path)) . '@' . Url::host();
|
||||
}
|
||||
Loading…
Reference in New Issue