Switch to new dated email format
parent
bf2468b8c6
commit
c384c7369a
@ -1,42 +1,59 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current qdated address
|
* Returns the current dated address
|
||||||
* If qdated is not available, returns null
|
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function qdated() {
|
function dated(): string {
|
||||||
$path = $_SERVER['HOME'] . '/.config/qdated/cddmail2/current';
|
// date in seven days
|
||||||
if(!is_file($path)) return null;
|
$date = modifiedJulianDate(time() + 7 * 24 * 60 * 60);
|
||||||
|
|
||||||
return 'dated-' . trim(f::read($path)) . '@' . url::host();
|
return 'dated-' . $date . '@' . url::host();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an HTML a mailto tag with the current qdated address
|
* Returns an HTML a mailto tag with the current dated address
|
||||||
* If qdated is not available, returns an HTML error message
|
* If dated is not available, returns an HTML error message
|
||||||
*
|
*
|
||||||
* @param mixed $text Optional text for the link
|
* @param mixed $text Optional text for the link
|
||||||
* Can also be true to use the email
|
* Can also be true to use the email
|
||||||
* address but put a line break in it
|
* address but put a line break in it
|
||||||
* @return string HTML code
|
* @return string HTML code
|
||||||
*/
|
*/
|
||||||
function qdatedHtml($text = false) {
|
function datedHtml($text = false) {
|
||||||
$email = qdated();
|
$email = dated();
|
||||||
if(!$email) return '<p><strong>' . l::get('qdated.error') . '</strong></p>';
|
|
||||||
|
|
||||||
if($text === true) $text = str_replace('@', '<br>@', $email);
|
if($text === true) $text = str_replace('@', '<br>@', $email);
|
||||||
return str::email($email, $text);
|
return str::email($email, $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* qdated Kirbytag
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dated Kirbytag
|
||||||
*
|
*
|
||||||
* Usage: (qdated: Optional link text)
|
* Usage: (dated: Optional link text)
|
||||||
*/
|
*/
|
||||||
kirby()->set('tag', 'qdated', [
|
kirby()->set('tag', 'dated', [
|
||||||
'html' => function($tag) {
|
'html' => function($tag) {
|
||||||
return qdatedHtml($tag->attr('qdated'));
|
return datedHtml($tag->attr('dated'));
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
Loading…
Reference in New Issue