From 788c54ea9c98a5380cbcf1d352ccc7a355507e23 Mon Sep 17 00:00:00 2001 From: Markus Ast Date: Fri, 12 Feb 2016 14:49:06 +0100 Subject: [PATCH 1/5] fix lighttpd config --- webserver-configs/lighttpd.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webserver-configs/lighttpd.conf b/webserver-configs/lighttpd.conf index a4775a555..df77c6902 100644 --- a/webserver-configs/lighttpd.conf +++ b/webserver-configs/lighttpd.conf @@ -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") From 7a1d9e454b4386c9758cfbb5f997adab4bef366c Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 12 Feb 2016 15:33:23 -0700 Subject: [PATCH 2/5] Add support for custom page-level dateformat field (core only) --- system/src/Grav/Common/Page/Page.php | 27 ++++++++++++++++++++++++--- system/src/Grav/Common/Utils.php | 12 ++++++------ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index b9b6db7b8..c0f581fa7 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -75,6 +75,7 @@ class Page protected $max_count; protected $menu; protected $date; + protected $dateformat; protected $taxonomy; protected $order_by; protected $order_dir; @@ -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; @@ -1744,7 +1748,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 +1758,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. * diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index 85702c3e7..e812ba91a 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -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); } From 59b75a339c84b2135ed697954b6e88397c48c3c0 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 12 Feb 2016 17:36:08 -0700 Subject: [PATCH 3/5] sort strings naturally and case insensitively #643 --- system/blueprints/pages/default.yaml | 15 +++++++++++++++ system/src/Grav/Common/Page/Pages.php | 7 ++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml index 6eab5d464..4c9670892 100644 --- a/system/blueprints/pages/default.yaml +++ b/system/blueprints/pages/default.yaml @@ -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 diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index a5d80ea4b..407b964af 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -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); } From afc0559d68548569b33454926307135ed3ac872c Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 12 Feb 2016 17:51:20 -0700 Subject: [PATCH 4/5] log error on invalid slug - only when setting the value from frontmatter --- system/src/Grav/Common/Page/Page.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index c0f581fa7..926ac9da0 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -315,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); @@ -1356,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; } From a1d0494ea264df76a9e4efa96185ee9dd2108f83 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Sun, 14 Feb 2016 08:58:31 +0100 Subject: [PATCH 5/5] :white_check_mark: Test adding media queries --- tests/unit/Grav/Common/AssetsTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/unit/Grav/Common/AssetsTest.php b/tests/unit/Grav/Common/AssetsTest.php index 65ead94d8..37a79b768 100644 --- a/tests/unit/Grav/Common/AssetsTest.php +++ b/tests/unit/Grav/Common/AssetsTest.php @@ -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('' . PHP_EOL, $css); } public function testAddingAssetPropertiesWithArray()