Compare commits
No commits in common. 'f3eb83d0b90583fc2ba4821c0d5f80ae2076406c' and '8148b004542490c5a74fab2cb657c2381899068e' have entirely different histories.
f3eb83d0b9
...
8148b00454
@ -1 +1 @@
|
|||||||
Subproject commit 29e082427d39ff7b51384ce7b6e2b963ce80e7ab
|
Subproject commit 70635b48ad0dca4ee51ac33bb2cdd1297367bbc5
|
||||||
@ -1,59 +1,42 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current dated address
|
* Returns the current qdated address
|
||||||
|
* If qdated is not available, returns null
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function dated(): string {
|
function qdated() {
|
||||||
// date in seven days
|
$path = $_SERVER['HOME'] . '/.config/qdated/cddmail2/current';
|
||||||
$date = modifiedJulianDate(time() + 7 * 24 * 60 * 60);
|
if(!is_file($path)) return null;
|
||||||
|
|
||||||
return 'dated-' . $date . '@' . url::host();
|
return 'dated-' . trim(f::read($path)) . '@' . url::host();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an HTML a mailto tag with the current dated address
|
* Returns an HTML a mailto tag with the current qdated address
|
||||||
* If dated is not available, returns an HTML error message
|
* If qdated 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 datedHtml($text = false) {
|
function qdatedHtml($text = false) {
|
||||||
$email = dated();
|
$email = qdated();
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Modified Julian Date,
|
* qdated Kirbytag
|
||||||
* 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)
|
* Usage: (qdated: Optional link text)
|
||||||
*/
|
*/
|
||||||
kirby()->set('tag', 'dated', [
|
kirby()->set('tag', 'qdated', [
|
||||||
'html' => function($tag) {
|
'html' => function($tag) {
|
||||||
return datedHtml($tag->attr('dated'));
|
return qdatedHtml($tag->attr('qdated'));
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|||||||
Loading…
Reference in New Issue