mirror of
https://github.com/getgrav/grav.git
synced 2026-01-30 19:30:18 +01:00
Merge branches 'develop' and 'feature/blueprints-update' of https://github.com/getgrav/grav into feature/blueprints-update
This commit is contained in:
@@ -178,6 +178,21 @@ form:
|
||||
|
||||
fields:
|
||||
|
||||
header.dateformat:
|
||||
toggleable: true
|
||||
type: select
|
||||
size: medium
|
||||
selectize:
|
||||
create: true
|
||||
label: PLUGIN_ADMIN.DEFAULT_DATE_FORMAT
|
||||
help: PLUGIN_ADMIN.DEFAULT_DATE_FORMAT_HELP
|
||||
placeholder: PLUGIN_ADMIN.DEFAULT_DATE_FORMAT_PLACEHOLDER
|
||||
'@data-options': '\Grav\Common\Utils::dateFormats'
|
||||
options:
|
||||
"": Auto Guess or Enter Custom
|
||||
validate:
|
||||
type: string
|
||||
|
||||
header.menu:
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.MENU
|
||||
|
||||
@@ -75,6 +75,7 @@ class Page
|
||||
protected $max_count;
|
||||
protected $menu;
|
||||
protected $date;
|
||||
protected $dateformat;
|
||||
protected $taxonomy;
|
||||
protected $order_by;
|
||||
protected $order_dir;
|
||||
@@ -314,7 +315,7 @@ class Page
|
||||
|
||||
if ($var) {
|
||||
if (isset($this->header->slug)) {
|
||||
$this->slug = trim($this->header->slug);
|
||||
$this->slug(($this->header->slug));
|
||||
}
|
||||
if (isset($this->header->routes)) {
|
||||
$this->routes = (array)($this->header->routes);
|
||||
@@ -349,6 +350,9 @@ class Page
|
||||
if (isset($this->header->order_manual)) {
|
||||
$this->order_manual = (array)$this->header->order_manual;
|
||||
}
|
||||
if (isset($this->header->dateformat)) {
|
||||
$this->dateformat($this->header->dateformat);
|
||||
}
|
||||
if (isset($this->header->date)) {
|
||||
$this->date($this->header->date);
|
||||
}
|
||||
@@ -1208,7 +1212,7 @@ class Page
|
||||
public function publishDate($var = null)
|
||||
{
|
||||
if ($var !== null) {
|
||||
$this->publish_date = Utils::date2timestamp($var);
|
||||
$this->publish_date = Utils::date2timestamp($var, $this->dateformat);
|
||||
}
|
||||
|
||||
return $this->publish_date;
|
||||
@@ -1224,7 +1228,7 @@ class Page
|
||||
public function unpublishDate($var = null)
|
||||
{
|
||||
if ($var !== null) {
|
||||
$this->unpublish_date = Utils::date2timestamp($var);
|
||||
$this->unpublish_date = Utils::date2timestamp($var, $this->dateformat);
|
||||
}
|
||||
|
||||
return $this->unpublish_date;
|
||||
@@ -1352,12 +1356,17 @@ class Page
|
||||
{
|
||||
if ($var !== null) {
|
||||
$this->slug = $var;
|
||||
if(!preg_match('/^[a-z0-9][-a-z0-9]*$/', $this->slug)){
|
||||
Grav::instance()['log']->notice("Invalid slug set in YAML frontmatter: " . $this->rawRoute() . " => ". $this->slug);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($this->slug)) {
|
||||
$this->slug = preg_replace(PAGE_ORDER_PREFIX_REGEX, '', $this->folder);
|
||||
$this->slug = strtolower(preg_replace(PAGE_ORDER_PREFIX_REGEX, '', $this->folder));
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $this->slug;
|
||||
}
|
||||
|
||||
@@ -1744,7 +1753,7 @@ class Page
|
||||
public function date($var = null)
|
||||
{
|
||||
if ($var !== null) {
|
||||
$this->date = Utils::date2timestamp($var);
|
||||
$this->date = Utils::date2timestamp($var, $this->dateformat);
|
||||
}
|
||||
|
||||
if (!$this->date) {
|
||||
@@ -1754,6 +1763,23 @@ class Page
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets and sets the date format for this Page object. This is typically passed in via the page headers
|
||||
* using typical PHP date string structure - http://php.net/manual/en/function.date.php
|
||||
*
|
||||
* @param string $var string representation of a date format
|
||||
*
|
||||
* @return string string representation of a date format
|
||||
*/
|
||||
public function dateformat($var = null)
|
||||
{
|
||||
if ($var !== null) {
|
||||
$this->dateformat = $var;
|
||||
}
|
||||
|
||||
return $this->dateformat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets and sets the order by which any sub-pages should be sorted.
|
||||
*
|
||||
|
||||
@@ -955,6 +955,7 @@ class Pages
|
||||
$list = [];
|
||||
$header_default = null;
|
||||
$header_query = null;
|
||||
$sort_flags = SORT_NATURAL | SORT_FLAG_CASE;
|
||||
|
||||
// do this header query work only once
|
||||
if (strpos($order_by, 'header.') === 0) {
|
||||
@@ -976,9 +977,11 @@ class Pages
|
||||
break;
|
||||
case 'date':
|
||||
$list[$key] = $child->date();
|
||||
$sort_flags = SORT_REGULAR;
|
||||
break;
|
||||
case 'modified':
|
||||
$list[$key] = $child->modified();
|
||||
$sort_flags = SORT_REGULAR;
|
||||
break;
|
||||
case 'slug':
|
||||
$list[$key] = $child->slug();
|
||||
@@ -994,11 +997,13 @@ class Pages
|
||||
} else {
|
||||
$list[$key] = $header_default ?: $key;
|
||||
}
|
||||
$sort_flags = SORT_REGULAR;
|
||||
break;
|
||||
case 'manual':
|
||||
case 'default':
|
||||
default:
|
||||
$list[$key] = $key;
|
||||
$sort_flags = SORT_REGULAR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1007,7 +1012,7 @@ class Pages
|
||||
$list = $this->arrayShuffle($list);
|
||||
} else {
|
||||
// else just sort the list according to specified key
|
||||
asort($list);
|
||||
asort($list, $sort_flags);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ abstract class Utils
|
||||
$date_formats = [
|
||||
'd-m-Y H:i' => 'd-m-Y H:i (e.g. '.$now->format('d-m-Y H:i').')',
|
||||
'Y-m-d H:i' => 'Y-m-d H:i (e.g. '.$now->format('Y-m-d H:i').')',
|
||||
'm/d/Y h:i a' => 'm/d/Y h:i (e.g. '.$now->format('m/d/Y h:i a').')',
|
||||
'm/d/Y h:i a' => 'm/d/Y h:i a (e.g. '.$now->format('m/d/Y h:i a').')',
|
||||
'H:i d-m-Y' => 'H:i d-m-Y (e.g. '.$now->format('H:i d-m-Y').')',
|
||||
'h:i a m/d/Y' => 'h:i a m/d/Y (e.g. '.$now->format('h:i a m/d/Y').')',
|
||||
];
|
||||
@@ -416,17 +416,17 @@ abstract class Utils
|
||||
*
|
||||
* @param string $date a String expressed in the system.pages.dateformat.default format, with fallback to a
|
||||
* strtotime argument
|
||||
*
|
||||
* @param string $format a date format to use if possible
|
||||
* @return int the timestamp
|
||||
*/
|
||||
public static function date2timestamp($date)
|
||||
public static function date2timestamp($date, $format = null)
|
||||
{
|
||||
$config = self::getGrav()['config'];
|
||||
$default_dateformat = $config->get('system.pages.dateformat.default');
|
||||
$dateformat = $format ?: $config->get('system.pages.dateformat.default');
|
||||
|
||||
// try to use DateTime and default format
|
||||
if ($default_dateformat) {
|
||||
$datetime = DateTime::createFromFormat($default_dateformat, $date);
|
||||
if ($dateformat) {
|
||||
$datetime = DateTime::createFromFormat($dateformat, $date);
|
||||
} else {
|
||||
$datetime = new DateTime($date);
|
||||
}
|
||||
|
||||
@@ -151,6 +151,12 @@ class AssetsTest extends \Codeception\TestCase\Test
|
||||
'loading' => 'defer',
|
||||
'group' => 'head'
|
||||
], reset($array));
|
||||
|
||||
//Test adding media queries
|
||||
$this->assets->reset();
|
||||
$this->assets->add('test.css', ['media' => 'only screen and (min-width: 640px)']);
|
||||
$css = $this->assets->css();
|
||||
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" media="only screen and (min-width: 640px)" />' . PHP_EOL, $css);
|
||||
}
|
||||
|
||||
public function testAddingAssetPropertiesWithArray()
|
||||
|
||||
@@ -36,7 +36,7 @@ $HTTP["url"] =~ "^/grav_path/(.git|cache|bin|logs|backup|tests)/(.*)" {
|
||||
$HTTP["url"] =~ "^/grav_path/(system|user|vendor)/(.*)\.(txt|md|html|yaml|php|twig|sh|bat)$" {
|
||||
url.access-deny = ("")
|
||||
}
|
||||
$HTTP["url"] =~ "^/grav_path/(\.(.*))|(\.(.*)/)" {
|
||||
$HTTP["url"] =~ "^/grav_path/(\.(.*))" {
|
||||
url.access-deny = ("")
|
||||
}
|
||||
url.access-deny = (".md","~",".inc")
|
||||
|
||||
Reference in New Issue
Block a user