You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.4 KiB
PHP
60 lines
1.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 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 an HTML a mailto tag with the current dated address
|
|
* If dated is not available, returns an HTML error message
|
|
*
|
|
* @param mixed $text Optional text for the link
|
|
* Can also be true to use the email
|
|
* address but put a line break in it
|
|
* @return string HTML code
|
|
*/
|
|
function datedHtml($text = false) {
|
|
$email = dated();
|
|
|
|
if($text === true) $text = str_replace('@', '<br>@', $email);
|
|
return str::email($email, $text);
|
|
}
|
|
|
|
/**
|
|
* 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: (dated: Optional link text)
|
|
*/
|
|
kirby()->set('tag', 'dated', [
|
|
'html' => function($tag) {
|
|
return datedHtml($tag->attr('dated'));
|
|
}
|
|
]);
|