Upgrade to rc5

This commit is contained in:
Bastian Allgeier
2020-12-10 11:24:42 +01:00
parent 3fec0d7c93
commit c378376bc9
257 changed files with 13009 additions and 1846 deletions

View File

@@ -66,16 +66,16 @@ function csrf(string $check = null)
if (func_num_args() === 0) {
// no arguments, generate/return a token
$token = $session->get('csrf');
$token = $session->get('kirby.csrf');
if (is_string($token) !== true) {
$token = bin2hex(random_bytes(32));
$session->set('csrf', $token);
$session->set('kirby.csrf', $token);
}
return $token;
} elseif (is_string($check) === true && is_string($session->get('csrf')) === true) {
} elseif (is_string($check) === true && is_string($session->get('kirby.csrf')) === true) {
// argument has been passed, check the token
return hash_equals($session->get('csrf'), $check) === true;
return hash_equals($session->get('kirby.csrf'), $check) === true;
}
return false;
@@ -747,10 +747,10 @@ function tc($key, int $count)
* by the defined step
*
* @param string $date
* @param int $step
* @param int $step array of `unit` and `size` to round to nearest
* @return string|null
*/
function timestamp(string $date = null, int $step = null): ?string
function timestamp(string $date = null, $step = null): ?string
{
if (V::date($date) === false) {
return null;
@@ -762,13 +762,46 @@ function timestamp(string $date = null, int $step = null): ?string
return $date;
}
$hours = date('H', $date);
$minutes = date('i', $date);
$minutes = floor($minutes / $step) * $step;
$minutes = str_pad($minutes, 2, 0, STR_PAD_LEFT);
$date = date('Y-m-d', $date) . ' ' . $hours . ':' . $minutes;
if (is_int($step) === true) {
$step = [
'unit' => 'minute',
'size' => 1
];
}
return strtotime($date);
if (is_array($step) === false) {
return $date;
}
$parts = [
'second' => date('s', $date),
'minute' => date('i', $date),
'hour' => date('H', $date),
'day' => date('d', $date),
'month' => date('m', $date),
'year' => date('Y', $date),
];
$current = $parts[$step['unit']];
$nearest = round($current / $step['size']) * $step['size'];
$parts[$step['unit']] = $nearest;
foreach ($parts as $part => $value) {
if ($part === $step['unit']) {
break;
}
$parts[$part] = 0;
}
return strtotime(
$parts['year'] . '-' .
str_pad($parts['month'], 2, 0, STR_PAD_LEFT) . '-' .
str_pad($parts['day'], 2, 0, STR_PAD_LEFT) . ' ' .
str_pad($parts['hour'], 2, 0, STR_PAD_LEFT) . ':' .
str_pad($parts['minute'], 2, 0, STR_PAD_LEFT) . ':' .
str_pad($parts['second'], 2, 0, STR_PAD_LEFT)
);
}
/**
@@ -829,6 +862,36 @@ function url(string $path = null, $options = null): string
return Url::to($path, $options);
}
/**
* Creates a compliant v4 UUID
* Taken from: https://github.com/symfony/polyfill
*
* @return string
*/
function uuid(): string
{
$uuid = bin2hex(random_bytes(16));
return sprintf(
'%08s-%04s-4%03s-%04x-%012s',
// 32 bits for "time_low"
substr($uuid, 0, 8),
// 16 bits for "time_mid"
substr($uuid, 8, 4),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
substr($uuid, 13, 3),
// 16 bits:
// * 8 bits for "clk_seq_hi_res",
// * 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
hexdec(substr($uuid, 16, 4)) & 0x3fff | 0x8000,
// 48 bits for "node"
substr($uuid, 20, 12)
);
}
/**
* Creates a video embed via iframe for Youtube or Vimeo
* videos. The embed Urls are automatically detected from