From f7f8aa108abca5fe7bb1ef886167a985f08be1e6 Mon Sep 17 00:00:00 2001 From: Gert Date: Mon, 4 May 2015 19:27:44 +0200 Subject: [PATCH 01/76] allow custom context for extending blueprints --- system/src/Grav/Common/Data/Blueprints.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Data/Blueprints.php b/system/src/Grav/Common/Data/Blueprints.php index a92f235f2..84d9ce486 100644 --- a/system/src/Grav/Common/Data/Blueprints.php +++ b/system/src/Grav/Common/Data/Blueprints.php @@ -2,6 +2,7 @@ namespace Grav\Common\Data; use Grav\Common\File\CompiledYamlFile; +use Grav\Common\GravTrait; /** * Blueprints class keeps track on blueprint instances. @@ -11,6 +12,8 @@ use Grav\Common\File\CompiledYamlFile; */ class Blueprints { + use GravTrait; + protected $search; protected $types; protected $instances = array(); @@ -55,8 +58,20 @@ class Blueprints if (isset($blueprints['@extends'])) { // Extend blueprint by other blueprints. $extends = (array) $blueprints['@extends']; - foreach ($extends as $extendType) { - $blueprint->extend($this->get($extendType)); + + if (is_string(key($extends))) { + $extends = [ $extends ]; + } + + foreach ($extends as $extendConfig) { + $type = !is_string($extendConfig) ? empty($extendConfig['type']) ? false : $extendConfig['type'] : $extendConfig; + + if (!$type) { + continue; + } + + $context = is_string($extendConfig) || empty($extendConfig['context']) ? $this : new self(self::getGrav()['locator']->findResource($extendConfig['context'])); + $blueprint->extend($context->get($type)); } } From 4f1a71b14535318e4c49457cad29e66f6e961eae Mon Sep 17 00:00:00 2001 From: Gert Date: Sat, 9 May 2015 14:48:36 +0200 Subject: [PATCH 02/76] fix extra prefix implementation for extra data of blueprints --- system/src/Grav/Common/Data/Blueprint.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Data/Blueprint.php b/system/src/Grav/Common/Data/Blueprint.php index 19448bc58..11c78823d 100644 --- a/system/src/Grav/Common/Data/Blueprint.php +++ b/system/src/Grav/Common/Data/Blueprint.php @@ -117,7 +117,16 @@ class Blueprint { // Initialize data $this->fields(); - return $this->extraArray($data, $this->nested, $prefix); + $rules = $this->nested; + + // Drill down to prefix level + $parts = explode('.', trim($prefix, '.')); + foreach ($parts as $part) { + $rules = isset($rules[$part]) ? $rules[$part] : []; + $data = isset($data[$part]) ? $data[$part] : []; + } + + return $this->extraArray($data, $rules, $prefix); } /** @@ -286,7 +295,7 @@ class Blueprint // Item has been defined in blueprints. } elseif (is_array($field) && is_array($val)) { // Array has been defined in blueprints. - $array += $this->ExtraArray($field, $val, $prefix); + $array += $this->ExtraArray($field, $val, $prefix . $key . '.'); } else { // Undefined/extra item. $array[$prefix.$key] = $field; From ff04b33efd92e982ee49a31ea53a7916551d74a9 Mon Sep 17 00:00:00 2001 From: Gert Date: Sat, 9 May 2015 15:45:56 +0200 Subject: [PATCH 03/76] provide default blueprints for common page types --- system/blueprints/pages/blog.yaml | 74 ++++++++++++ system/blueprints/pages/default.yaml | 170 +++++++++++++++++++++++++++ system/blueprints/pages/item.yaml | 50 ++++++++ system/blueprints/pages/modular.yaml | 52 ++++++++ system/blueprints/pages/page.yaml | 42 ------- 5 files changed, 346 insertions(+), 42 deletions(-) create mode 100644 system/blueprints/pages/blog.yaml create mode 100644 system/blueprints/pages/default.yaml create mode 100644 system/blueprints/pages/item.yaml create mode 100644 system/blueprints/pages/modular.yaml delete mode 100644 system/blueprints/pages/page.yaml diff --git a/system/blueprints/pages/blog.yaml b/system/blueprints/pages/blog.yaml new file mode 100644 index 000000000..8665a3b40 --- /dev/null +++ b/system/blueprints/pages/blog.yaml @@ -0,0 +1,74 @@ +title: Blog +@extends: pages/default + +child_type: item + + +title: Default + +rules: + slug: + pattern: "[a-z][a-z0-9_\-]+" + min: 2 + max: 80 + +form: + fields: + tabs: + type: tabs + active: 1 + + fields: + advanced: + fields: + overrides: + fields: + header.child_type: + default: item + blog: + type: tab + title: Blog List + + fields: + header.content.items: + type: select + label: Items + default: @self.children + options: + @self.children: Children + + header.content.limit: + type: text + label: Max Item Count + default: 5 + validate: + required: true + type: int + min: 1 + + header.content.order.by: + type: select + label: Order By + default: date + options: + folder: Folder + title: Title + date: Date + default: Default + + header.content.order.dir: + type: select + label: Order + default: desc + options: + asc: Ascending + desc: Descending + + header.content.pagination: + type: toggle + label: Pagination + highlight: 1 + default: 1 + options: + 1: Enabled + 0: Disabled diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml new file mode 100644 index 000000000..7c29e18e2 --- /dev/null +++ b/system/blueprints/pages/default.yaml @@ -0,0 +1,170 @@ +title: Default + +rules: + slug: + pattern: "[a-z][a-z0-9_\-]+" + min: 2 + max: 80 + +form: + fields: + type: + type: hidden + label: Page Type + default: default + + tabs: + type: tabs + active: 1 + + fields: + content: + type: tab + title: Content + + fields: + header.title: + type: text + label: Title + validate: + required: true + + header.process: + type: checkboxes + label: Process + default: [markdown: true, twig: true] + options: + markdown: Markdown + twig: Twig + use: keys + + content: + type: markdown + label: Content + validate: + type: textarea + + uploads: + type: uploads + label: Page Media + + meta: + type: tab + title: Meta + + fields: + header.description: + type: textarea + label: Description + validate: + max: 120 + + header.keywords: + type: text + label: Keywords + validate: + max: 120 + + header.robots: + type: checkboxes + label: Robots + options: + noindex: No index + nofollow: No follow + use: keys + + advanced: + type: tab + title: Advanced + + fields: + columns: + type: columns + fields: + column1: + type: column + fields: + folder: + type: text + label: Folder Name + validate: + type: slug + + route: + type: select + label: Parent + classes: fancy + @data-options: '\Grav\Common\Page\Pages::parents' + @data-default: '\Grav\Plugin\admin::route' + options: + '/': '- Root -' + + type: + type: select + classes: fancy + label: Display Template + default: default + @data-options: '\Grav\Common\Page\Pages::types' + + column2: + type: column + + fields: + order: + type: order + label: Ordering + sitemap: + + overrides: + type: section + title: Overrides + underline: true + + fields: + + header.menu: + type: text + label: Menu + + header.slug: + type: text + label: Alias + validate: + rule: slug + + header.cache_enable: + type: toggle + label: Caching + highlight: 1 + options: + '': Global + 1: Enabled + 0: Disabled + validate: + type: bool + + header.routable: + type: toggle + label: Access by URL + highlight: 1 + default: '' + options: + '': Global + 1: Enabled + 0: Disabled + validate: + type: bool + + header.child_type: + type: select + label: Default Child Type + default: default + @data-options: '\Grav\Common\Page\Pages::types' + + header.order_by: + type: hidden + + header.order_manual: + type: hidden + validate: + type: commalist diff --git a/system/blueprints/pages/item.yaml b/system/blueprints/pages/item.yaml new file mode 100644 index 000000000..96793d620 --- /dev/null +++ b/system/blueprints/pages/item.yaml @@ -0,0 +1,50 @@ +title: Item +@extends: pages/default + +form: + fields: + tabs: + + fields: + blog: + type: tab + title: Blog Item + + fields: + header.date: + type: datetime + label: Date + + header.published: + type: toggle + label: Published + highlight: 1 + default: 1 + options: + 1: Yes + 0: No + + + # header.publish_date + # header.unpublish_date + # summary: + # 16: enabled: true # enable or disable summary of page + # 17: format: short # long = summary delimiter will be ignored; short = use the first occurence of delimter or size + # 18: size: 300 # Maximum length of summary (characters) + # 19: delimiter: === # The summary delimiter + + header.taxonomy.category: + type: text + label: Category + default: blog + classes: fancy + validate: + type: commalist + + header.taxonomy.tag: + type: text + label: Tags + size: large + classes: fancy + validate: + type: commalist diff --git a/system/blueprints/pages/modular.yaml b/system/blueprints/pages/modular.yaml new file mode 100644 index 000000000..fdd016d45 --- /dev/null +++ b/system/blueprints/pages/modular.yaml @@ -0,0 +1,52 @@ +title: Modular +@extends: + type: pages/default + +form: + fields: + tabs: + type: tabs + active: 1 + + fields: + content: + fields: + + header.content.items: + type: select + label: Items + default: @self.modular + options: + @self.modular: Children + + header.content.order.by: + type: select + label: Order By + default: date + options: + folder: Folder + title: Title + date: Date + default: Default + + header.content.order.dir: + type: select + label: Order + default: desc + options: + asc: Ascending + desc: Descending + + header.content.custom: + type: text + label: Manual ordering + classes: fancy + validate: + type: commalist + + header.process: + type: hidden + content: + type: hidden + uploads: + type: hidden diff --git a/system/blueprints/pages/page.yaml b/system/blueprints/pages/page.yaml deleted file mode 100644 index 81948231b..000000000 --- a/system/blueprints/pages/page.yaml +++ /dev/null @@ -1,42 +0,0 @@ -rules: - slug: - pattern: "[a-z][a-z0-9_\-]+" - min: 2 - max: 80 - -form: - validation: loose - fields: - - title: - type: text - label: Title - validate: - required: true - - folder: - type: text - label: Folder - validate: - type: slug - required: true - - route: - type: select - label: Parent - classes: fancy - @data-options: '\Grav\Common\Page\Pages::parents' - @data-default: '\Grav\Plugin\admin::route' - options: - '/': '- Root -' - validate: - required: true - - type: - type: select - classes: fancy - label: Display Template - default: default - @data-options: '\Grav\Common\Page\Pages::types' - validate: - required: true From 326f1bc8908b3bb853cce0e2b1ac9af1c3bc5fbf Mon Sep 17 00:00:00 2001 From: Gert Date: Sat, 9 May 2015 16:47:16 +0200 Subject: [PATCH 04/76] update item blueprint --- system/blueprints/pages/item.yaml | 118 ++++++++++++++++++++++-------- 1 file changed, 86 insertions(+), 32 deletions(-) diff --git a/system/blueprints/pages/item.yaml b/system/blueprints/pages/item.yaml index 96793d620..7e4f8f967 100644 --- a/system/blueprints/pages/item.yaml +++ b/system/blueprints/pages/item.yaml @@ -10,41 +10,95 @@ form: type: tab title: Blog Item + fields: - header.date: - type: datetime - label: Date + publishing: + type: section + title: Publishing + underline: true - header.published: - type: toggle - label: Published - highlight: 1 - default: 1 - options: - 1: Yes - 0: No + fields: + header.date: + type: datetime + label: Date + header.publish_date: + type: datetime + label: Publish post on this date - # header.publish_date - # header.unpublish_date - # summary: - # 16: enabled: true # enable or disable summary of page - # 17: format: short # long = summary delimiter will be ignored; short = use the first occurence of delimter or size - # 18: size: 300 # Maximum length of summary (characters) - # 19: delimiter: === # The summary delimiter + header.unpublish_date: + type: datetime + label: Unpublish post on this date - header.taxonomy.category: - type: text - label: Category - default: blog - classes: fancy - validate: - type: commalist + header.published: + type: toggle + label: Published + highlight: 1 + default: 1 + options: + 1: Yes + 0: No - header.taxonomy.tag: - type: text - label: Tags - size: large - classes: fancy - validate: - type: commalist + taxonomy: + type: section + title: Taxonomy + underline: true + + fields: + + header.taxonomy.category: + type: text + label: Category + default: blog + classes: fancy + validate: + type: commalist + + header.taxonomy.tag: + type: text + label: Tags + size: large + classes: fancy + validate: + type: commalist + + summary: + type: section + title: Summary + underline: true + + fields: + + header.summary.enabled: + type: toggle + label: Summary + highlight: 1 + default: 1 + options: + 1: Enabled + 0: Disabled + + header.summary.format: + type: select + label: Format + classes: fancy + default: short + options: + 'short': 'Use the first occurence of delimter or size' + 'long': 'Summary delimiter will be ignored' + + header.summary.size: + type: text + label: Size + classes: large + default: 300 + validate: + type: int + min: 1 + + header.summary.delimiter: + type: text + label: Summary delimiter + classes: large + default: === + placeholder: === From 628ae561d5b4d48c784f0b25cf9e774e789d9295 Mon Sep 17 00:00:00 2001 From: Gert Date: Mon, 11 May 2015 12:33:03 +0200 Subject: [PATCH 05/76] more sensible approach to blueprint::extra prefix handling --- system/src/Grav/Common/Data/Blueprint.php | 1 - system/src/Grav/Common/Page/Page.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Data/Blueprint.php b/system/src/Grav/Common/Data/Blueprint.php index 11c78823d..db830403f 100644 --- a/system/src/Grav/Common/Data/Blueprint.php +++ b/system/src/Grav/Common/Data/Blueprint.php @@ -123,7 +123,6 @@ class Blueprint $parts = explode('.', trim($prefix, '.')); foreach ($parts as $part) { $rules = isset($rules[$part]) ? $rules[$part] : []; - $data = isset($data[$part]) ? $data[$part] : []; } return $this->extraArray($data, $rules, $prefix); diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 1d8a80241..029e5fcb8 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -686,7 +686,7 @@ class Page public function extra() { $blueprints = $this->blueprints(); - return $blueprints->extra($this->toArray(), 'header.'); + return $blueprints->extra($this->toArray()['header'], 'header.'); } /** From ab6c257ba6daf9c272aec870d330a9d8dc53d35c Mon Sep 17 00:00:00 2001 From: Gert Date: Tue, 12 May 2015 00:49:31 +0200 Subject: [PATCH 06/76] use new taxonomy field + for all pages --- system/blueprints/pages/default.yaml | 11 +++++++++++ system/blueprints/pages/item.yaml | 23 ----------------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml index 7c29e18e2..7a8e61fee 100644 --- a/system/blueprints/pages/default.yaml +++ b/system/blueprints/pages/default.yaml @@ -73,6 +73,17 @@ form: nofollow: No follow use: keys + taxonomies: + type: section + title: Taxonomies + underline: true + + fields: + header.taxonomy: + type: taxonomy + label: Taxonomy + taxonomies: [ 'tag', 'category', 'year' ] + advanced: type: tab title: Advanced diff --git a/system/blueprints/pages/item.yaml b/system/blueprints/pages/item.yaml index 7e4f8f967..d21a92dec 100644 --- a/system/blueprints/pages/item.yaml +++ b/system/blueprints/pages/item.yaml @@ -39,29 +39,6 @@ form: 1: Yes 0: No - taxonomy: - type: section - title: Taxonomy - underline: true - - fields: - - header.taxonomy.category: - type: text - label: Category - default: blog - classes: fancy - validate: - type: commalist - - header.taxonomy.tag: - type: text - label: Tags - size: large - classes: fancy - validate: - type: commalist - summary: type: section title: Summary From fe3082c6c99eca658e4a9384ac138a64dfd5c579 Mon Sep 17 00:00:00 2001 From: Gert Date: Wed, 13 May 2015 15:39:37 +0200 Subject: [PATCH 07/76] update taxonomy blueprint --- system/blueprints/pages/default.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml index 7a8e61fee..7f3861fc7 100644 --- a/system/blueprints/pages/default.yaml +++ b/system/blueprints/pages/default.yaml @@ -82,7 +82,8 @@ form: header.taxonomy: type: taxonomy label: Taxonomy - taxonomies: [ 'tag', 'category', 'year' ] + validate: + type: array advanced: type: tab From 4ae01d48ae55372531bb2b46b5ef020639096062 Mon Sep 17 00:00:00 2001 From: Gert Date: Wed, 13 May 2015 18:48:52 +0200 Subject: [PATCH 08/76] fix prefix split on empty prefix --- system/src/Grav/Common/Data/Blueprint.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/system/src/Grav/Common/Data/Blueprint.php b/system/src/Grav/Common/Data/Blueprint.php index db830403f..0df476e00 100644 --- a/system/src/Grav/Common/Data/Blueprint.php +++ b/system/src/Grav/Common/Data/Blueprint.php @@ -120,9 +120,11 @@ class Blueprint $rules = $this->nested; // Drill down to prefix level - $parts = explode('.', trim($prefix, '.')); - foreach ($parts as $part) { - $rules = isset($rules[$part]) ? $rules[$part] : []; + if (!empty($prefix)) { + $parts = explode('.', trim($prefix, '.')); + foreach ($parts as $part) { + $rules = isset($rules[$part]) ? $rules[$part] : []; + } } return $this->extraArray($data, $rules, $prefix); From 4f77ef26b52438446c9fc5db2ff4d7c9b292c7f6 Mon Sep 17 00:00:00 2001 From: Gert Date: Fri, 15 May 2015 11:40:38 +0200 Subject: [PATCH 09/76] fix default values for process header --- system/blueprints/pages/default.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml index 7f3861fc7..309d85141 100644 --- a/system/blueprints/pages/default.yaml +++ b/system/blueprints/pages/default.yaml @@ -32,7 +32,9 @@ form: header.process: type: checkboxes label: Process - default: [markdown: true, twig: true] + default: + markdown: true + twig: false options: markdown: Markdown twig: Twig From 921685ff88054d7ec0bef5bdc26be402efbc2d6e Mon Sep 17 00:00:00 2001 From: Gert Date: Fri, 15 May 2015 17:32:21 +0200 Subject: [PATCH 10/76] fix blueprint type changing when extends --- system/src/Grav/Common/Data/Blueprints.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/src/Grav/Common/Data/Blueprints.php b/system/src/Grav/Common/Data/Blueprints.php index 84d9ce486..a024c87f7 100644 --- a/system/src/Grav/Common/Data/Blueprints.php +++ b/system/src/Grav/Common/Data/Blueprints.php @@ -64,14 +64,14 @@ class Blueprints } foreach ($extends as $extendConfig) { - $type = !is_string($extendConfig) ? empty($extendConfig['type']) ? false : $extendConfig['type'] : $extendConfig; + $extendType = !is_string($extendConfig) ? empty($extendConfig['type']) ? false : $extendConfig['type'] : $extendConfig; - if (!$type) { + if (!$extendType) { continue; } $context = is_string($extendConfig) || empty($extendConfig['context']) ? $this : new self(self::getGrav()['locator']->findResource($extendConfig['context'])); - $blueprint->extend($context->get($type)); + $blueprint->extend($context->get($extendType)); } } From f1e57e0e9c6d5169ad84602c68c3d95f2187f5f2 Mon Sep 17 00:00:00 2001 From: Gert Date: Wed, 20 May 2015 16:45:54 +0200 Subject: [PATCH 11/76] modular type needs to have modular/ prefix --- system/src/Grav/Common/Page/Page.php | 2 +- system/src/Grav/Common/Page/Types.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 3b309832f..e3e632321 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -524,7 +524,7 @@ class Page return preg_replace($regex, '', $this->folder); } if ($name == 'type') { - return basename($this->name(), '.md'); + return $this->template(); } if ($name == 'media') { return $this->media()->all(); diff --git a/system/src/Grav/Common/Page/Types.php b/system/src/Grav/Common/Page/Types.php index 418faba9c..d591b7ad4 100644 --- a/system/src/Grav/Common/Page/Types.php +++ b/system/src/Grav/Common/Page/Types.php @@ -78,9 +78,10 @@ class Types implements \ArrayAccess, \Iterator, \Countable if (strpos($name, 'modular/') !== 0) { continue; } - $list[basename($name)] = trim(ucfirst(strtr(basename($name), '_', ' '))); + $list[$name] = trim(ucfirst(strtr(basename($name), '_', ' '))); } ksort($list); + \Grav\Common\GravTrait::getGrav()['debugger']->addMessage($list); return $list; } } From 71f075701522e297f3d77fa5b265eed08bbda1d0 Mon Sep 17 00:00:00 2001 From: Gert Date: Wed, 20 May 2015 16:52:41 +0200 Subject: [PATCH 12/76] remove debug line --- system/src/Grav/Common/Page/Types.php | 1 - 1 file changed, 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Types.php b/system/src/Grav/Common/Page/Types.php index d591b7ad4..69f61e597 100644 --- a/system/src/Grav/Common/Page/Types.php +++ b/system/src/Grav/Common/Page/Types.php @@ -81,7 +81,6 @@ class Types implements \ArrayAccess, \Iterator, \Countable $list[$name] = trim(ucfirst(strtr(basename($name), '_', ' '))); } ksort($list); - \Grav\Common\GravTrait::getGrav()['debugger']->addMessage($list); return $list; } } From bf61a123cc9b5b7c5f090d302a10115140bc0d20 Mon Sep 17 00:00:00 2001 From: Gert Date: Wed, 20 May 2015 17:13:22 +0200 Subject: [PATCH 13/76] implement blueprints for the list type --- system/src/Grav/Common/Data/Blueprint.php | 2 +- system/src/Grav/Common/Data/Validation.php | 24 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Data/Blueprint.php b/system/src/Grav/Common/Data/Blueprint.php index 0df476e00..cab22b6f8 100644 --- a/system/src/Grav/Common/Data/Blueprint.php +++ b/system/src/Grav/Common/Data/Blueprint.php @@ -323,7 +323,7 @@ class Blueprint $field['name'] = $prefix . $key; $field += $params; - if (isset($field['fields'])) { + if (isset($field['fields']) && $field['type'] !== 'list') { // Recursively get all the nested fields. $newParams = array_intersect_key($this->filter, $field); $this->parseFormFields($field['fields'], $newParams, $prefix, $current[$key]['fields']); diff --git a/system/src/Grav/Common/Data/Validation.php b/system/src/Grav/Common/Data/Validation.php index bd1a34d10..9b185e02b 100644 --- a/system/src/Grav/Common/Data/Validation.php +++ b/system/src/Grav/Common/Data/Validation.php @@ -500,6 +500,30 @@ class Validation return $values; } + public static function typeList($value, array $params, array $field) + { + if (!is_array($value)) { + return false; + } + + if (isset($field['fields'])) { + foreach ($value as $key => $item) { + foreach ($field['fields'] as $subKey => $subField) { + $subKey = trim($subKey, '.'); + $subValue = isset($item[$subKey]) ? $item[$subKey] : null; + self::validate($subValue, $subField); + } + } + } + + return true; + } + + protected static function filterList($value, array $params, array $field) + { + return (array) $value; + } + /** * Custom input: ignore (will not validate) * From e4b65d5d7f3fe93170e6b0d2fbd1830ac13c41b9 Mon Sep 17 00:00:00 2001 From: Gert Date: Wed, 20 May 2015 18:18:32 +0200 Subject: [PATCH 14/76] add check for themes without blueprints/templates folders --- system/src/Grav/Common/Page/Pages.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index ac0e9e70f..f72b27ede 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -392,8 +392,8 @@ class Pages { if (!self::$types) { self::$types = new Types(); - self::$types->scanBlueprints('theme://blueprints/'); - self::$types->scanTemplates('theme://templates/'); + file_exists('theme://blueprints/') && self::$types->scanBlueprints('theme://blueprints/'); + file_exists('theme://templates/') && self::$types->scanTemplates('theme://templates/'); $event = new Event(); $event->types = self::$types; From e6d58b780e85d0a4b2fc2f7e024c8ff3e76fc205 Mon Sep 17 00:00:00 2001 From: Gert Date: Wed, 20 May 2015 20:33:40 +0200 Subject: [PATCH 15/76] load system blueprints as a fallback for pages --- system/src/Grav/Common/Page/Types.php | 40 +++++++++++++++++++-------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/system/src/Grav/Common/Page/Types.php b/system/src/Grav/Common/Page/Types.php index 69f61e597..f6407cadd 100644 --- a/system/src/Grav/Common/Page/Types.php +++ b/system/src/Grav/Common/Page/Types.php @@ -13,27 +13,24 @@ class Types implements \ArrayAccess, \Iterator, \Countable use ArrayAccess, Constructor, Iterator, Countable, Export; protected $items; + protected $systemBlueprints; public function register($type, $blueprint = null) { + if (!$blueprint && $this->systemBlueprints && isset($this->systemBlueprints[$type])) { + $useBlueprint = $this->systemBlueprints[$type]; + } else { + $useBlueprint = $blueprint; + } + if ($blueprint || empty($this->items[$type])) { - $this->items[$type] = $blueprint; + $this->items[$type] = $useBlueprint; } } public function scanBlueprints($path) { - $options = [ - 'compare' => 'Filename', - 'pattern' => '|\.yaml$|', - 'filters' => [ - 'key' => '|\.yaml$|' - ], - 'key' => 'SubPathName', - 'value' => 'PathName', - ]; - - $this->items = Folder::all($path, $options) + $this->items; + $this->items = $this->findBlueprints($path) + $this->items; } public function scanTemplates($path) @@ -48,6 +45,10 @@ class Types implements \ArrayAccess, \Iterator, \Countable 'recursive' => false ]; + if (!$this->systemBlueprints) { + $this->systemBlueprints = $this->findBlueprints('blueprints://pages'); + } + foreach (Folder::all($path, $options) as $type) { $this->register($type); } @@ -83,4 +84,19 @@ class Types implements \ArrayAccess, \Iterator, \Countable ksort($list); return $list; } + + private function findBlueprints($path) + { + $options = [ + 'compare' => 'Filename', + 'pattern' => '|\.yaml$|', + 'filters' => [ + 'key' => '|\.yaml$|' + ], + 'key' => 'SubPathName', + 'value' => 'PathName', + ]; + + return Folder::all($path, $options); + } } From df9a0eeab28ecd5b5adedb90e08cca3fed2dfc0d Mon Sep 17 00:00:00 2001 From: Gert Date: Wed, 20 May 2015 21:30:35 +0200 Subject: [PATCH 16/76] set context for default blueprint extends --- system/blueprints/pages/blog.yaml | 4 +++- system/blueprints/pages/item.yaml | 4 +++- system/blueprints/pages/modular.yaml | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/system/blueprints/pages/blog.yaml b/system/blueprints/pages/blog.yaml index 8665a3b40..b5937f959 100644 --- a/system/blueprints/pages/blog.yaml +++ b/system/blueprints/pages/blog.yaml @@ -1,5 +1,7 @@ title: Blog -@extends: pages/default +@extends: + type: default + context: blueprints://pages child_type: item diff --git a/system/blueprints/pages/item.yaml b/system/blueprints/pages/item.yaml index d21a92dec..f31e9c9a9 100644 --- a/system/blueprints/pages/item.yaml +++ b/system/blueprints/pages/item.yaml @@ -1,5 +1,7 @@ title: Item -@extends: pages/default +@extends: + type: default + context: blueprints://pages form: fields: diff --git a/system/blueprints/pages/modular.yaml b/system/blueprints/pages/modular.yaml index fdd016d45..3ece0b6c7 100644 --- a/system/blueprints/pages/modular.yaml +++ b/system/blueprints/pages/modular.yaml @@ -1,6 +1,7 @@ title: Modular @extends: - type: pages/default + type: default + context: blueprints://pages form: fields: From 6adabb5f71e7a43e9c8c6768830a8ce10a2b16f2 Mon Sep 17 00:00:00 2001 From: Gert Date: Wed, 20 May 2015 21:55:04 +0200 Subject: [PATCH 17/76] add ignore field for removing fields on extended blueprints --- system/blueprints/pages/modular.yaml | 6 +++--- system/src/Grav/Common/Data/Blueprint.php | 4 ++-- system/src/Grav/Common/Data/Validation.php | 5 +++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/system/blueprints/pages/modular.yaml b/system/blueprints/pages/modular.yaml index 3ece0b6c7..4d088138f 100644 --- a/system/blueprints/pages/modular.yaml +++ b/system/blueprints/pages/modular.yaml @@ -46,8 +46,8 @@ form: type: commalist header.process: - type: hidden + type: ignore content: - type: hidden + type: ignore uploads: - type: hidden + type: ignore diff --git a/system/src/Grav/Common/Data/Blueprint.php b/system/src/Grav/Common/Data/Blueprint.php index cab22b6f8..16569231b 100644 --- a/system/src/Grav/Common/Data/Blueprint.php +++ b/system/src/Grav/Common/Data/Blueprint.php @@ -327,7 +327,7 @@ class Blueprint // Recursively get all the nested fields. $newParams = array_intersect_key($this->filter, $field); $this->parseFormFields($field['fields'], $newParams, $prefix, $current[$key]['fields']); - } else { + } else if ($field['type'] !== 'ignore') { // Add rule. $this->rules[$prefix . $key] = &$field; $this->addProperty($prefix . $key); @@ -375,7 +375,7 @@ class Blueprint } // Initialize predefined validation rule. - if (isset($field['validate']['rule'])) { + if (isset($field['validate']['rule']) && $field['type'] !== 'ignore') { $field['validate'] += $this->getRule($field['validate']['rule']); } } diff --git a/system/src/Grav/Common/Data/Validation.php b/system/src/Grav/Common/Data/Validation.php index 9b185e02b..b0e4656fa 100644 --- a/system/src/Grav/Common/Data/Validation.php +++ b/system/src/Grav/Common/Data/Validation.php @@ -537,6 +537,11 @@ class Validation return true; } + public static function filterIgnore($value, array $params, array $field) + { + return $value; + } + // HTML5 attributes (min, max and range are handled inside the types) public static function validateRequired($value, $params) From 370b5db34e5ed6cebf6af9864e58958c8a24ab3a Mon Sep 17 00:00:00 2001 From: Gert Date: Wed, 20 May 2015 22:09:43 +0200 Subject: [PATCH 18/76] remove unexisting option --- system/blueprints/pages/modular.yaml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/system/blueprints/pages/modular.yaml b/system/blueprints/pages/modular.yaml index 4d088138f..84236be45 100644 --- a/system/blueprints/pages/modular.yaml +++ b/system/blueprints/pages/modular.yaml @@ -38,13 +38,6 @@ form: asc: Ascending desc: Descending - header.content.custom: - type: text - label: Manual ordering - classes: fancy - validate: - type: commalist - header.process: type: ignore content: From acbc7efdc87f55122faab8f16796b7a60c550cda Mon Sep 17 00:00:00 2001 From: Gert Date: Mon, 25 May 2015 17:23:24 +0200 Subject: [PATCH 19/76] remove theme selection from general settings --- system/blueprints/config/system.yaml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index 071a5c1b2..91bfc82ab 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -20,13 +20,6 @@ form: show_root: false help: "The page that Grav will use as the default landing page" - pages.theme: - type: themeselect - classes: fancy - size: medium - label: Default Theme - help: "Set the theme (defaults to 'default')" - pages.markdown.extra: type: toggle label: Markdown Extra From b4a0a315391746b6e518c79bc8063959a99ace9a Mon Sep 17 00:00:00 2001 From: Gert Date: Mon, 25 May 2015 17:33:57 +0200 Subject: [PATCH 20/76] fix pages.process defaults --- system/blueprints/config/system.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index 91bfc82ab..40990016b 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -33,7 +33,9 @@ form: pages.process: type: checkboxes label: Process - default: [markdown: true, twig: true] + default: + markdown: true + twig: false options: markdown: Markdown twig: Twig From ff5658e803017ed74bd7f44f64a30ace8855c48e Mon Sep 17 00:00:00 2001 From: Gert Date: Mon, 1 Jun 2015 21:23:53 +0200 Subject: [PATCH 21/76] update blueprints --- system/blueprints/config/site.yaml | 3 +-- system/blueprints/pages/default.yaml | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/system/blueprints/config/site.yaml b/system/blueprints/config/site.yaml index 604be106d..b89fd40a7 100644 --- a/system/blueprints/config/site.yaml +++ b/system/blueprints/config/site.yaml @@ -28,10 +28,9 @@ form: type: email taxonomies: - type: text + type: selectize size: large label: Taxonomy Types - classes: fancy validate: type: commalist diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml index 309d85141..0b9cd8350 100644 --- a/system/blueprints/pages/default.yaml +++ b/system/blueprints/pages/default.yaml @@ -32,6 +32,7 @@ form: header.process: type: checkboxes label: Process + toggleable: true default: markdown: true twig: false From bc1a9b31faa54a4565e04ee7159dfe19da52c700 Mon Sep 17 00:00:00 2001 From: Gert Date: Wed, 3 Jun 2015 16:21:49 +0200 Subject: [PATCH 22/76] add @config directive to get config values from blueprints --- system/blueprints/pages/default.yaml | 1 + system/src/Grav/Common/Data/Blueprint.php | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml index 0b9cd8350..e907e80c6 100644 --- a/system/blueprints/pages/default.yaml +++ b/system/blueprints/pages/default.yaml @@ -33,6 +33,7 @@ form: type: checkboxes label: Process toggleable: true + @config-default: system.pages.process default: markdown: true twig: false diff --git a/system/src/Grav/Common/Data/Blueprint.php b/system/src/Grav/Common/Data/Blueprint.php index 16569231b..bed1cffd8 100644 --- a/system/src/Grav/Common/Data/Blueprint.php +++ b/system/src/Grav/Common/Data/Blueprint.php @@ -1,6 +1,7 @@ get($value, $default); + + if (!is_null($config)) { + $field[$property] = $config; + } + } } // Initialize predefined validation rule. From f1a41394ab0574bcad2104d52e3742029126c96d Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 22 Jul 2015 15:30:27 -0600 Subject: [PATCH 23/76] updates for account validation --- system/blueprints/user/account.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/system/blueprints/user/account.yaml b/system/blueprints/user/account.yaml index 7ed36145a..7f9dfc9dc 100644 --- a/system/blueprints/user/account.yaml +++ b/system/blueprints/user/account.yaml @@ -15,10 +15,12 @@ form: readonly: true email: - type: text + type: email size: large label: Email validate: + type: email + message: Must be a valid email address required: true password: @@ -27,6 +29,8 @@ form: label: Password validate: required: true + message: Password must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters + pattern: '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}' fullname: type: text From 2161daa398a2e46654d44e9623c9c4d86f8c6bd3 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 22 Jul 2015 15:31:05 -0600 Subject: [PATCH 24/76] Prettier validation messages --- system/src/Grav/Common/Data/Validation.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/system/src/Grav/Common/Data/Validation.php b/system/src/Grav/Common/Data/Validation.php index bd1a34d10..fd400fc51 100644 --- a/system/src/Grav/Common/Data/Validation.php +++ b/system/src/Grav/Common/Data/Validation.php @@ -28,14 +28,16 @@ class Validation // Validate type with fallback type text. $type = (string) isset($field['validate']['type']) ? $field['validate']['type'] : $field['type']; $method = 'type'.strtr($type, '-', '_'); + $name = ucfirst($field['label'] ? $field['label'] : $field['name']); + $message = (string) isset($field['validate']['message']) ? $field['validate']['message'] : 'Invalid input in ' . $name; + if (method_exists(__CLASS__, $method)) { $success = self::$method($value, $validate, $field); } else { $success = self::typeText($value, $validate, $field); } if (!$success) { - $name = $field['label'] ? $field['label'] : $field['name']; - throw new \RuntimeException("invalid input in {$name}"); + throw new \RuntimeException($message); } // Check individual rules @@ -43,8 +45,9 @@ class Validation $method = 'validate'.strtr($rule, '-', '_'); if (method_exists(__CLASS__, $method)) { $success = self::$method($value, $params); + if (!$success) { - throw new \RuntimeException('Failed'); + throw new \RuntimeException($message); } } } From cc9f5ed096ca5c5e6336f1e5ff1a9d2f79ee80b5 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 22 Jul 2015 15:31:32 -0600 Subject: [PATCH 25/76] More validation updates --- system/src/Grav/Common/Data/Blueprint.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Data/Blueprint.php b/system/src/Grav/Common/Data/Blueprint.php index 19448bc58..768d8e41d 100644 --- a/system/src/Grav/Common/Data/Blueprint.php +++ b/system/src/Grav/Common/Data/Blueprint.php @@ -75,7 +75,7 @@ class Blueprint try { $this->validateArray($data, $this->nested); } catch (\RuntimeException $e) { - throw new \RuntimeException(sprintf('Page validation failed: %s', $e->getMessage())); + throw new \RuntimeException(sprintf('Validation failed: %s', $e->getMessage())); } } From b64bfc9ab036798ba11af73d6b1ef2e82705983c Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 23 Jul 2015 11:36:26 -0600 Subject: [PATCH 26/76] more progress on system blueprint --- system/blueprints/config/system.yaml | 341 ++++++++++++++++++--------- 1 file changed, 231 insertions(+), 110 deletions(-) diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index 071a5c1b2..c28c0375e 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -25,59 +25,53 @@ form: classes: fancy size: medium label: Default Theme - help: "Set the theme (defaults to 'default')" - - pages.markdown.extra: - type: toggle - label: Markdown Extra - highlight: 1 - options: - 1: Yes - 0: No - validate: - type: bool + help: "Set the default theme for Grav to use (default is Antimatter)" pages.process: type: checkboxes label: Process + help: "Control how pages are processed. Can be set per-page rather than globally" default: [markdown: true, twig: true] options: markdown: Markdown twig: Twig use: keys + + pages.dateformat.short: type: select size: medium classes: fancy label: Short Date Format - help: "Set the short date format" - default: 'jS M Y' + help: "Set the short date format that can be used by themes" + default: "jS M Y" options: - 'F jS \\a\\t g:ia': "January 1st at 11:59pm" - 'l jS of F g:i A': "Monday 1st of January at 11:59 PM" - 'D, m M Y G:i:s': "Mon, 01 Jan 2014 23:59:00" - 'd-m-y G:i': "01-01-14 23:59" - 'jS M Y': "10th Feb 2014" + "F jS \\a\\t g:ia": "January 1st at 11:59pm" + "l jS of F g:i A": "Monday 1st of January at 11:59 PM" + "D, m M Y G:i:s": "Mon, 01 Jan 2014 23:59:00" + "d-m-y G:i": "01-01-14 23:59" + "jS M Y": "10th Feb 2014" pages.dateformat.long: type: select size: medium classes: fancy label: Long Date Format - help: "Set the long date format" + help: "Set the long date format that can be used by themes" options: - 'F jS \a\t g:ia': "January 1st at 11:59pm" - 'l jS of F g:i A': "Monday 1st of January at 11:59 PM" - 'D, m M Y G:i:s': "Mon, 01 Jan 2014 23:59:00" - 'd-m-y G:i': "01-01-14 23:59" - 'jS M Y': "10th Feb 2014" + "F jS \\a\\t g:ia": "January 1st at 11:59pm" + "l jS of F g:i A": "Monday 1st of January at 11:59 PM" + "D, m M Y G:i:s": "Mon, 01 Jan 2014 23:59:00" + "d-m-y G:i": "01-01-14 23:59" + "jS M Y": "10th Feb 2014" pages.order.by: type: select size: medium classes: fancy label: Default Ordering + help: "Pages in a list will render using this order unless it is overridden" options: default: Default - based on folder name folder: Folder - based on prefix-less folder name @@ -89,6 +83,7 @@ form: label: Default Order Direction highlight: asc default: desc + help: "The direction of pages in a list" options: asc: Ascending desc: Descending @@ -96,15 +91,16 @@ form: pages.list.count: type: text size: x-small - label: Default Item Count - help: "Default max pages count" + label: Default Page Count + help: "Default maximum pages count in a list" validate: type: number min: 1 + pages.publish_dates: type: toggle label: Date-based publishing - help: Automatically (un)publish posts based on their date + help: "Automatically (un)publish posts based on their date" highlight: 1 options: 1: Yes @@ -112,28 +108,113 @@ form: validate: type: bool + pages.events: + type: checkboxes + label: Events + help: "Enable or Disable specific events. Disabling these can break plugins" + default: [page: true, twig: true] + options: + page: Page Events + twig: Twig Events + use: keys + pages.redirect_default_route: + type: toggle + label: Redirect Default Route + help: "Automatically redirect to a page's default route" + highlight: 0 + options: + 1: Yes + 0: No + validate: + type: bool - events: + http_headers: type: section - title: Events + title: HTTP Headers underline: true fields: - pages.events.page: + pages.expires: + type: text + size: small + label: Expires + help: "Sets the expires header. The value is in seconds." + validate: + type: number + min: 1 + pages.last_modified: type: toggle - label: Page events - highlight: 1 + label: Last Modified + help: "Sets the last modified header that can help optimize proxy and browser caching" + highlight: 0 + options: + 1: Yes + 0: No + validate: + type: bool + pages.etag: + type: toggle + label: ETag + help: "Sets the etag header to help identify when a page has been modified" + highlight: 0 + options: + 1: Yes + 0: No + validate: + type: bool + pages.vary_accept_encoding: + type: toggle + label: Vary Accept Encoding + help: "Sets the `Vary: Accept Encoding` header to help with proxy and CDN caching" + highlight: 0 options: 1: Yes 0: No validate: type: bool - pages.events.twig: + markdown: + type: section + title: Markdown + underline: true + + fields: + pages.markdown.extra: type: toggle - label: Twig events - highlight: 1 + label: Markdown Extra + help: "Enable default support for Markdown Extra - https://michelf.ca/projects/php-markdown/extra/" + highlight: 0 + options: + 1: Yes + 0: No + validate: + type: bool + pages.markdown.auto_line_breaks: + type: toggle + label: Auto Line Breaks + help: "Enable support for automatic line breaks in markdown" + highlight: 0 + options: + 1: Yes + 0: No + validate: + type: bool + pages.markdown.auto_url_links: + type: toggle + label: Auto URL Links + help: "Enable automatic conversion of URLs into HTML hyperlinks" + highlight: 0 + options: + 1: Yes + 0: No + validate: + type: bool + pages.markdown.escape_markup: + type: toggle + label: Escape Markup + help: "Escape markup tags into HTML entities" + highlight: 0 options: 1: Yes 0: No @@ -149,6 +230,7 @@ form: cache.enabled: type: toggle label: Caching + help: "Global ON/OFF switch to enable/disable Grav caching" highlight: 1 options: 1: Yes @@ -161,6 +243,7 @@ form: size: small classes: fancy label: Cache Check Method + help: "Select the method that Grav uses to check if page files have been modified." options: file: File folder: Folder @@ -170,7 +253,8 @@ form: type: select size: small classes: fancy - label: Cache driver + label: Cache Driver + help: "Choose which cache driver Grav should use. 'Auto Detect' attempts to find the best for you" options: auto: Auto detect file: File @@ -183,37 +267,28 @@ form: type: text size: x-small label: Cache Prefix + help: "An identifier for part of the Grav key. Don't change unless you know what your doing." placeholder: "Derived from base URL (override by entering random string)" + cache.lifetime: + type: text + size: small + label: Lifetime + help: "Sets the cache lifetime in seconds. 0 = infinite" + validate: + type: number + cache.gzip: type: toggle - label: GZIP compression - highlight: 1 + label: Gzip Compression + help: "Enable GZip compression of the Grav page for increased performance." + highlight: 0 options: 1: Yes 0: No validate: type: bool - assets.enable_asset_timestamp: - type: toggle - label: Enable timestamps on assets - highlight: 1 - options: - 1: Yes - 0: No - validate: - type: bool - - media.enable_media_timestamp: - type: toggle - label: Enable timestamps on media - highlight: 1 - options: - 1: Yes - 0: No - validate: - type: bool twig: type: section @@ -223,7 +298,8 @@ form: fields: twig.cache: type: toggle - label: Twig caching + label: Twig Caching + help: "Control the Twig caching mechanism. Leave this enabled for best performance." highlight: 1 options: 1: Yes @@ -233,8 +309,9 @@ form: twig.debug: type: toggle - label: Twig debug - highlight: 1 + label: Twig Debug + help: "Allows the option of not loading the Twig Debugger extension" + highlight: 0 options: 1: Yes 0: No @@ -244,6 +321,7 @@ form: twig.auto_reload: type: toggle label: Detect changes + help: "Twig will automatically recompile the Twig cache if it detects any changes in Twig templates" highlight: 1 options: 1: Yes @@ -254,7 +332,8 @@ form: twig.autoescape: type: toggle label: Autoescape variables - highlight: 1 + help: "Autoescapes all variables. This will break your site most likely" + highlight: 0 options: 1: Yes 0: No @@ -270,7 +349,8 @@ form: assets.css_pipeline: type: toggle label: CSS Pipeline - highlight: 1 + help: "The CSS pipeline is the unification of multiple CSS resources into one file" + highlight: 0 options: 1: Yes 0: No @@ -280,6 +360,7 @@ form: assets.css_minify: type: toggle label: CSS Minify + help: "Minify the CSS during pipelining" highlight: 1 options: 1: Yes @@ -290,7 +371,8 @@ form: assets.css_minify_windows: type: toggle label: CSS Minify Windows Override - highlight: 1 + help: "Minify Override for Windows platforms. False by default due to ThreadStackSize" + highlight: 0 options: 1: Yes 0: No @@ -300,6 +382,7 @@ form: assets.css_rewrite: type: toggle label: CSS Rewrite + help: "Rewrite any CSS relative URLs during pipelining" highlight: 1 options: 1: Yes @@ -310,7 +393,8 @@ form: assets.js_pipeline: type: toggle label: JavaScript Pipeline - highlight: 01 + help: "The JS pipeline is the unification of multiple JS resources into one file" + highlight: 0 options: 1: Yes 0: No @@ -320,6 +404,7 @@ form: assets.js_minify: type: toggle label: JavaScript Minify + help: "Minify the JS during pipelining" highlight: 1 options: 1: Yes @@ -327,6 +412,17 @@ form: validate: type: bool + assets.enable_asset_timestamp: + type: toggle + label: Enable timestamps on assets + help: "Enable asset timestamps" + highlight: 0 + options: + 1: Yes + 0: No + validate: + type: bool + errors: type: section title: Error handler @@ -335,7 +431,8 @@ form: fields: errors.display: type: toggle - label: Display errors + label: Display Errors + help: "Display full backtrace-style error page" highlight: 1 options: 1: Yes @@ -346,6 +443,7 @@ form: errors.log: type: toggle label: Log errors + help: "Log errors to /logs folder" highlight: 1 options: 1: Yes @@ -362,56 +460,18 @@ form: debugger.enabled: type: toggle label: Debugger - highlight: 1 + help: "Enable Grav debugger and following settings" + highlight: 0 options: 1: Yes 0: No validate: type: bool - debugger.mode: - type: select - size: small - classes: fancy - label: Mode - options: - detect: Auto-Detect - development: Development - production: Production - - debugger.strict: + debugger.twig: type: toggle - label: Strict - highlight: 1 - options: - 1: Yes - 0: No - validate: - type: bool - - debugger.max_depth: - type: select - size: small - classes: fancy - label: Detail Level - placeholder: "How many nested levels to display for objects or arrays" - options: - 1: 1 level - 2: 2 levels - 3: 3 levels - 4: 4 levels - 5: 5 levels - 6: 6 levels - 7: 7 levels - 8: 8 levels - 9: 9 levels - 10: 10 levels - validate: - type: number - - debugger.log.enabled: - type: toggle - label: Logging + label: Debug Twig + help: "Enable debugging of Twig templates" highlight: 1 options: 1: Yes @@ -422,6 +482,7 @@ form: debugger.shutdown.close_connection: type: toggle label: Shutdown Close Connection + help: "Close the connection before calling onShutdown(). false for debugging" highlight: 1 options: 1: Yes @@ -438,6 +499,7 @@ form: images.default_image_quality: type: text label: Default image quality + help: "Default image quality to use when resampling images (85%)" classes: x-small validate: type: number @@ -447,7 +509,8 @@ form: images.debug: type: toggle label: Image debug watermark - highlight: 1 + help: "Show an overlay over images indicating the pixel depth of the image when working with retina for example" + highlight: 0 options: 1: Yes 0: No @@ -457,20 +520,77 @@ form: media.upload_limit: type: text label: File upload limit + help: "Set maximum upload size in bytes (0 is unlimited)" classes: small validate: type: number + media.enable_media_timestamp: + type: toggle + label: Enable timestamps on media + help: "Appends a timestamp based on last modified date to each media item" + highlight: 0 + options: + 1: Yes + 0: No + validate: + type: bool + + session: + type: section + title: Session + underline: true + + fields: + session.enabled: + type: toggle + label: Enabled + help: "Enable session support within Grav" + highlight: 1 + options: + 1: Yes + 0: No + validate: + type: bool + + session.timeout: + type: text + size: small + label: Timeout + help: "Sets the session timeout in seconds" + validate: + type: number + min: 1 + + session.name: + type: text + size: small + label: Name + help: "An identifier used to form the name of the session cookie" + + system: type: section title: System underline: true fields: + absolute_urls: + type: toggle + label: Absolute URLs + highlight: 0 + help: "Absolute or relative URLs for `base_url`" + options: + 1: Yes + 0: No + validate: + type: bool + timezone: type: select label: Timezone classes: fancy + help: "The default timezone the server is should based time and dates off" @data-options: '\Grav\Common\Utils::timezones' default: '' options: @@ -480,7 +600,8 @@ form: type: select label: Parameter separator classes: fancy + help: "Separater for passed parameters that can be changed for Apache on Windows" default: '' options: ':': ': (default)' - ';': '; (use this for apache on Windows)' + ';': '; (for Apache running on Windows)' From 8975c2936c1f0a8b108b7c85bbb17c71b39bedef Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 23 Jul 2015 11:36:43 -0600 Subject: [PATCH 27/76] remove unused use that is causing an error --- system/src/Grav/Common/Page/Medium/VideoMedium.php | 1 - 1 file changed, 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Medium/VideoMedium.php b/system/src/Grav/Common/Page/Medium/VideoMedium.php index e67d3fbfc..acc967293 100644 --- a/system/src/Grav/Common/Page/Medium/VideoMedium.php +++ b/system/src/Grav/Common/Page/Medium/VideoMedium.php @@ -7,7 +7,6 @@ use Grav\Common\Grav; use Grav\Common\GravTrait; use Grav\Common\Data\Blueprint; use Grav\Common\Data\Data; -use Gregwar\Image\Image as ImageFile; class VideoMedium extends Medium { From 84eee30d1fb3a1097d2d5b7163a8f838b1256665 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 24 Jul 2015 07:50:18 -0600 Subject: [PATCH 28/76] fix for string/array conversion error --- system/src/Grav/Common/User/User.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/system/src/Grav/Common/User/User.php b/system/src/Grav/Common/User/User.php index b727fa19b..71bbc0fc0 100644 --- a/system/src/Grav/Common/User/User.php +++ b/system/src/Grav/Common/User/User.php @@ -97,6 +97,10 @@ class User extends Data */ public function authorise($action) { + if (empty($this->items)) { + return false; + } + return $this->get("access.{$action}") === true; } } From ad00252a4eb94760519ec07494339ac1951b1aad Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 24 Jul 2015 07:50:35 -0600 Subject: [PATCH 29/76] base translations settings --- system/config/system.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/config/system.yaml b/system/config/system.yaml index 17ef03d8a..e594281a7 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -3,7 +3,8 @@ timezone: '' # Valid values: http://php.net/manual/en/ param_sep: ':' # Parameter separator, use ';' for Apache on windows languages: - translations: true # Enable translations by default + translations: true # Enable translations by default + supported: [] # List of languages supported. eg: [en, fr, de] home: alias: '/home' # Default path for home, ie / From 5be0618b4d47d13ea1ef9cde05f43ef9e701b3c6 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 24 Jul 2015 07:50:47 -0600 Subject: [PATCH 30/76] more blueprints progress --- system/blueprints/config/system.yaml | 50 ++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index c28c0375e..d90de91f6 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -129,6 +129,46 @@ form: validate: type: bool + languages: + type: section + title: Languages + underline: true + + fields: + + languages.supported: + type: text + size: large + label: Supported + help: "Comma separated list of 2 letter language codes (for example 'en,fr,de')" + classes: fancy + validate: + type: commalist + + languages.translations: + type: toggle + label: Translations + help: "Support translations in Grav, plugins and extensions" + highlight: 1 + options: + 1: Yes + 0: No + validate: + type: bool + + languages.session_store_active: + type: toggle + label: Session- + help: "Support translations in Grav, plugins and extensions" + highlight: 0 + options: + 1: Yes + 0: No + validate: + type: bool + + + http_headers: type: section title: HTTP Headers @@ -423,6 +463,12 @@ form: validate: type: bool + assets.collections: + type: array + label: Collections + placeholder_key: collection_name + placeholder_value: collection_path + errors: type: section title: Error handler @@ -569,9 +615,9 @@ form: help: "An identifier used to form the name of the session cookie" - system: + advanced: type: section - title: System + title: Advanced underline: true fields: From bb69656bd7d39faf9778bb16023f13fed52f7b8d Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 24 Jul 2015 08:08:23 -0600 Subject: [PATCH 31/76] added base languages config --- system/config/system.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/system/config/system.yaml b/system/config/system.yaml index e594281a7..1a1365a50 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -3,8 +3,14 @@ timezone: '' # Valid values: http://php.net/manual/en/ param_sep: ':' # Parameter separator, use ';' for Apache on windows languages: - translations: true # Enable translations by default supported: [] # List of languages supported. eg: [en, fr, de] + translations: true # Enable translations by default + translation_fallback: true # Fallback through supported translations if active lang doesn't exist + session_store_active: false # Store active language in session + home_redirect: + include_lang: true # Include language in home redirect (/en) + include_route: false # Include route in home redirect (/blog) + home: alias: '/home' # Default path for home, ie / From 7a2fceaee9e170d3a78e950ca8691ba1a8629dd9 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 24 Jul 2015 08:08:50 -0600 Subject: [PATCH 32/76] renamed translations.fallback property --- system/src/Grav/Common/Language/Language.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Language/Language.php b/system/src/Grav/Common/Language/Language.php index 9c19f59b6..9069c2a10 100644 --- a/system/src/Grav/Common/Language/Language.php +++ b/system/src/Grav/Common/Language/Language.php @@ -295,7 +295,7 @@ class Language if ($this->config->get('system.languages.translations', true)) { if ($this->enabled() && $lookup) { if (empty($languages)) { - if ($this->config->get('system.languages.translations.fallback', true)) { + if ($this->config->get('system.languages.translations_fallback', true)) { $languages = $this->getFallbackLanguages(); } else { $languages = (array)$this->getDefault(); @@ -335,7 +335,7 @@ class Language if ($this->config->get('system.languages.translations', true)) { if ($this->enabled() && $key) { if (empty($languages)) { - if ($this->config->get('system.languages.translations.fallback', true)) { + if ($this->config->get('system.languages.translations_fallback', true)) { $languages = $this->getFallbackLanguages(); } else { $languages = (array)$this->getDefault(); From df99fe007387a871716bb29608956c6f78974c75 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 24 Jul 2015 08:20:36 -0600 Subject: [PATCH 33/76] blueprint updates --- system/blueprints/config/system.yaml | 93 +++++++++++++++++++--------- 1 file changed, 63 insertions(+), 30 deletions(-) diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index d90de91f6..bd9337ec4 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -14,7 +14,7 @@ form: type: pages size: medium classes: fancy - label: Home Page + label: Home page show_all: false show_modular: false show_root: false @@ -24,7 +24,7 @@ form: type: themeselect classes: fancy size: medium - label: Default Theme + label: Default theme help: "Set the default theme for Grav to use (default is Antimatter)" pages.process: @@ -43,7 +43,7 @@ form: type: select size: medium classes: fancy - label: Short Date Format + label: Short date format help: "Set the short date format that can be used by themes" default: "jS M Y" options: @@ -57,7 +57,7 @@ form: type: select size: medium classes: fancy - label: Long Date Format + label: Long date format help: "Set the long date format that can be used by themes" options: "F jS \\a\\t g:ia": "January 1st at 11:59pm" @@ -70,7 +70,7 @@ form: type: select size: medium classes: fancy - label: Default Ordering + label: Default ordering help: "Pages in a list will render using this order unless it is overridden" options: default: Default - based on folder name @@ -80,7 +80,7 @@ form: pages.order.dir: type: toggle - label: Default Order Direction + label: Default order direction highlight: asc default: desc help: "The direction of pages in a list" @@ -91,7 +91,7 @@ form: pages.list.count: type: text size: x-small - label: Default Page Count + label: Default page count help: "Default maximum pages count in a list" validate: type: number @@ -120,7 +120,7 @@ form: pages.redirect_default_route: type: toggle - label: Redirect Default Route + label: Redirect default route help: "Automatically redirect to a page's default route" highlight: 0 options: @@ -147,7 +147,7 @@ form: languages.translations: type: toggle - label: Translations + label: Translations enabled help: "Support translations in Grav, plugins and extensions" highlight: 1 options: @@ -156,9 +156,20 @@ form: validate: type: bool + languages.translations_fallback: + type: toggle + label: Translations fallback + help: "Fallback through supported translations if active language doesn't exist" + highlight: 1 + options: + 1: Yes + 0: No + validate: + type: bool + languages.session_store_active: type: toggle - label: Session- + label: Active language in session help: "Support translations in Grav, plugins and extensions" highlight: 0 options: @@ -167,6 +178,28 @@ form: validate: type: bool + languages.home_redirect.include_lang: + type: toggle + label: Home redirect include language + help: "Include language in home redirect (/en)" + highlight: 1 + options: + 1: Yes + 0: No + validate: + type: bool + + languages.home_redirect.include_route: + type: toggle + label: Home redirect include route + help: "Include route in home redirect (/blog)" + highlight: 0 + options: + 1: Yes + 0: No + validate: + type: bool + http_headers: @@ -185,7 +218,7 @@ form: min: 1 pages.last_modified: type: toggle - label: Last Modified + label: Last modified help: "Sets the last modified header that can help optimize proxy and browser caching" highlight: 0 options: @@ -205,7 +238,7 @@ form: type: bool pages.vary_accept_encoding: type: toggle - label: Vary Accept Encoding + label: Vary accept encoding help: "Sets the `Vary: Accept Encoding` header to help with proxy and CDN caching" highlight: 0 options: @@ -222,7 +255,7 @@ form: fields: pages.markdown.extra: type: toggle - label: Markdown Extra + label: Markdown extra help: "Enable default support for Markdown Extra - https://michelf.ca/projects/php-markdown/extra/" highlight: 0 options: @@ -232,7 +265,7 @@ form: type: bool pages.markdown.auto_line_breaks: type: toggle - label: Auto Line Breaks + label: Auto line breaks help: "Enable support for automatic line breaks in markdown" highlight: 0 options: @@ -242,7 +275,7 @@ form: type: bool pages.markdown.auto_url_links: type: toggle - label: Auto URL Links + label: Auto URL links help: "Enable automatic conversion of URLs into HTML hyperlinks" highlight: 0 options: @@ -252,7 +285,7 @@ form: type: bool pages.markdown.escape_markup: type: toggle - label: Escape Markup + label: Escape markup help: "Escape markup tags into HTML entities" highlight: 0 options: @@ -282,7 +315,7 @@ form: type: select size: small classes: fancy - label: Cache Check Method + label: Cache check method help: "Select the method that Grav uses to check if page files have been modified." options: file: File @@ -293,7 +326,7 @@ form: type: select size: small classes: fancy - label: Cache Driver + label: Cache driver help: "Choose which cache driver Grav should use. 'Auto Detect' attempts to find the best for you" options: auto: Auto detect @@ -306,7 +339,7 @@ form: cache.prefix: type: text size: x-small - label: Cache Prefix + label: Cache prefix help: "An identifier for part of the Grav key. Don't change unless you know what your doing." placeholder: "Derived from base URL (override by entering random string)" @@ -320,7 +353,7 @@ form: cache.gzip: type: toggle - label: Gzip Compression + label: Gzip compression help: "Enable GZip compression of the Grav page for increased performance." highlight: 0 options: @@ -338,7 +371,7 @@ form: fields: twig.cache: type: toggle - label: Twig Caching + label: Twig caching help: "Control the Twig caching mechanism. Leave this enabled for best performance." highlight: 1 options: @@ -349,7 +382,7 @@ form: twig.debug: type: toggle - label: Twig Debug + label: Twig debug help: "Allows the option of not loading the Twig Debugger extension" highlight: 0 options: @@ -388,7 +421,7 @@ form: fields: assets.css_pipeline: type: toggle - label: CSS Pipeline + label: CSS pipeline help: "The CSS pipeline is the unification of multiple CSS resources into one file" highlight: 0 options: @@ -399,7 +432,7 @@ form: assets.css_minify: type: toggle - label: CSS Minify + label: CSS minify help: "Minify the CSS during pipelining" highlight: 1 options: @@ -410,7 +443,7 @@ form: assets.css_minify_windows: type: toggle - label: CSS Minify Windows Override + label: CSS minify Windows override help: "Minify Override for Windows platforms. False by default due to ThreadStackSize" highlight: 0 options: @@ -421,7 +454,7 @@ form: assets.css_rewrite: type: toggle - label: CSS Rewrite + label: CSS rewrite help: "Rewrite any CSS relative URLs during pipelining" highlight: 1 options: @@ -432,7 +465,7 @@ form: assets.js_pipeline: type: toggle - label: JavaScript Pipeline + label: JavaScript pipeline help: "The JS pipeline is the unification of multiple JS resources into one file" highlight: 0 options: @@ -443,7 +476,7 @@ form: assets.js_minify: type: toggle - label: JavaScript Minify + label: JavaScript minify help: "Minify the JS during pipelining" highlight: 1 options: @@ -477,7 +510,7 @@ form: fields: errors.display: type: toggle - label: Display Errors + label: Display errors help: "Display full backtrace-style error page" highlight: 1 options: @@ -527,7 +560,7 @@ form: debugger.shutdown.close_connection: type: toggle - label: Shutdown Close Connection + label: Shutdown close connection help: "Close the connection before calling onShutdown(). false for debugging" highlight: 1 options: From bd08d787f26a6b2a912aefd6282dc48422928fde Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 24 Jul 2015 08:20:46 -0600 Subject: [PATCH 34/76] typo --- system/config/system.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/config/system.yaml b/system/config/system.yaml index 1a1365a50..d8cb1b314 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -5,7 +5,7 @@ param_sep: ':' # Parameter separator, use ';' for Apache languages: supported: [] # List of languages supported. eg: [en, fr, de] translations: true # Enable translations by default - translation_fallback: true # Fallback through supported translations if active lang doesn't exist + translations_fallback: true # Fallback through supported translations if active lang doesn't exist session_store_active: false # Store active language in session home_redirect: include_lang: true # Include language in home redirect (/en) From 16f779c8f519355125f8f5cff0fa335c2d1b54ac Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 24 Jul 2015 10:26:54 -0600 Subject: [PATCH 35/76] changed Inflector from static to class + added multilang support --- system/languages/en.yaml | 58 +++++++ system/src/Grav/Common/GPM/GPM.php | 4 +- system/src/Grav/Common/Grav.php | 2 + system/src/Grav/Common/Inflector.php | 163 ++++++------------ system/src/Grav/Common/Language/Language.php | 34 ++-- system/src/Grav/Common/Plugins.php | 4 +- system/src/Grav/Common/Themes.php | 5 +- system/src/Grav/Common/Twig/TwigExtension.php | 8 +- 8 files changed, 147 insertions(+), 131 deletions(-) create mode 100644 system/languages/en.yaml diff --git a/system/languages/en.yaml b/system/languages/en.yaml new file mode 100644 index 000000000..7ee1ca42b --- /dev/null +++ b/system/languages/en.yaml @@ -0,0 +1,58 @@ +INFLECTOR_PLURALS: + '/(quiz)$/i': '\1zes' + '/^(ox)$/i': '\1en' + '/([m|l])ouse$/i': '\1ice' + '/(matr|vert|ind)ix|ex$/i': '\1ices' + '/(x|ch|ss|sh)$/i': '\1es' + '/([^aeiouy]|qu)ies$/i': '\1y' + '/([^aeiouy]|qu)y$/i': '\1ies' + '/(hive)$/i': '\1s' + '/(?:([^f])fe|([lr])f)$/i': '\1\2ves' + '/sis$/i': 'ses' + '/([ti])um$/i': '\1a' + '/(buffal|tomat)o$/i': '\1oes' + '/(bu)s$/i': '\1ses' + '/(alias|status)/i': '\1es' + '/(octop|vir)us$/i': '\1i' + '/(ax|test)is$/i': '\1es' + '/s$/i': 's' + '/$/': 's' +INFLECTOR_SINGULAR: + '/(quiz)zes$/i': '\1' + '/(matr)ices$/i': '\1ix' + '/(vert|ind)ices$/i': '\1ex' + '/^(ox)en/i': '\1' + '/(alias|status)es$/i': '\1' + '/([octop|vir])i$/i': '\1us' + '/(cris|ax|test)es$/i': '\1is' + '/(shoe)s$/i': '\1' + '/(o)es$/i': '\1' + '/(bus)es$/i': '\1' + '/([m|l])ice$/i': '\1ouse' + '/(x|ch|ss|sh)es$/i': '\1' + '/(m)ovies$/i': '\1ovie' + '/(s)eries$/i': '\1eries' + '/([^aeiouy]|qu)ies$/i': '\1y' + '/([lr])ves$/i': '\1f' + '/(tive)s$/i': '\1' + '/(hive)s$/i': '\1' + '/([^f])ves$/i': '\1fe' + '/(^analy)ses$/i': '\1sis' + '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i': '\1\2sis' + '/([ti])a$/i': '\1um' + '/(n)ews$/i': '\1ews' + '/s$/i': '' +INFLECTOR_UNCOUNTABLE: ['equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'] +INFLECTOR_IRREGULAR: + 'person': 'people' + 'man': 'men' + 'child': 'children' + 'sex': 'sexes' + 'move': 'moves' +INFLECTOR_ORDINALS: + 'default': 'th' + 'first': 'st' + 'second': 'nd' + 'third': 'rd' + + diff --git a/system/src/Grav/Common/GPM/GPM.php b/system/src/Grav/Common/GPM/GPM.php index a6eefce5a..049f0ec8c 100644 --- a/system/src/Grav/Common/GPM/GPM.php +++ b/system/src/Grav/Common/GPM/GPM.php @@ -349,6 +349,8 @@ class GPM extends Iterator public function findPackages($searches = []) { $packages = ['total' => 0, 'not_found' => []]; + $inflector = $this->grav['inflector']; + foreach ($searches as $search) { $repository = ''; @@ -380,7 +382,7 @@ class GPM extends Iterator } $not_found = new \stdClass(); - $not_found->name = Inflector::camelize($search); + $not_found->name = $inflector->camelize($search); $not_found->slug = $search; $not_found->package_type = $type; $not_found->install_path = str_replace('%name%', $search, $this->install_paths[$type]); diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index c145192e4..2bcb9e9cd 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -159,6 +159,8 @@ class Grav extends Container $container->register(new StreamsServiceProvider); $container->register(new ConfigServiceProvider); + $container['inflector'] = new Inflector(); + $container['debugger']->stopTimer('_init'); return $container; diff --git a/system/src/Grav/Common/Inflector.php b/system/src/Grav/Common/Inflector.php index d707448c4..2c89f7313 100644 --- a/system/src/Grav/Common/Inflector.php +++ b/system/src/Grav/Common/Inflector.php @@ -4,6 +4,7 @@ namespace Grav\Common; /** * This file was originally part of the Akelos Framework */ +use Grav\Common\Language\Language; /** * Inflector for pluralize and singularize English nouns. @@ -20,65 +21,55 @@ namespace Grav\Common; class Inflector { + use GravTrait; + + protected $plural; + protected $singular; + protected $uncountable; + protected $irregular; + protected $ordinals; + + public function init() + { + if (empty($this->plural)) { + $language = self::getGrav()['language']; + $this->plural = $language->translate('INFLECTOR_PLURALS', null, true); + $this->singular = $language->translate('INFLECTOR_SINGULAR', null, true); + $this->uncountable = $language->translate('INFLECTOR_UNCOUNTABLE', null, true); + $this->irregular = $language->translate('INFLECTOR_IRREGULAR', null, true); + $this->ordinals = $language->translate('INFLECTOR_ORDINALS', null, true); + } + } /** * Pluralizes English nouns. * - * @access static public - * @static * @param string $word English noun to pluralize * @return string Plural noun */ - public static function pluralize($word, $count = 2) + public function pluralize($word, $count = 2) { + $this->init(); + if ($count == 1) { return $word; } - $plural = array( - '/(quiz)$/i' => '\1zes', - '/^(ox)$/i' => '\1en', - '/([m|l])ouse$/i' => '\1ice', - '/(matr|vert|ind)ix|ex$/i' => '\1ices', - '/(x|ch|ss|sh)$/i' => '\1es', - '/([^aeiouy]|qu)ies$/i' => '\1y', - '/([^aeiouy]|qu)y$/i' => '\1ies', - '/(hive)$/i' => '\1s', - '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', - '/sis$/i' => 'ses', - '/([ti])um$/i' => '\1a', - '/(buffal|tomat)o$/i' => '\1oes', - '/(bu)s$/i' => '\1ses', - '/(alias|status)/i'=> '\1es', - '/(octop|vir)us$/i'=> '\1i', - '/(ax|test)is$/i'=> '\1es', - '/s$/i'=> 's', - '/$/'=> 's'); - - $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); - - $irregular = array( - 'person' => 'people', - 'man' => 'men', - 'child' => 'children', - 'sex' => 'sexes', - 'move' => 'moves'); - $lowercased_word = strtolower($word); - foreach ($uncountable as $_uncountable) { + foreach ($this->uncountable as $_uncountable) { if (substr($lowercased_word, (-1*strlen($_uncountable))) == $_uncountable) { return $word; } } - foreach ($irregular as $_plural => $_singular) { + foreach ($this->irregular as $_plural => $_singular) { if (preg_match('/('.$_plural.')$/i', $word, $arr)) { return preg_replace('/('.$_plural.')$/i', substr($arr[0], 0, 1).substr($_singular, 1), $word); } } - foreach ($plural as $rule => $replacement) { + foreach ($this->plural as $rule => $replacement) { if (preg_match($rule, $word)) { return preg_replace($rule, $replacement, $word); } @@ -94,62 +85,26 @@ class Inflector * @param int $count * @return string Singular noun. */ - public static function singularize($word, $count = 1) + public function singularize($word, $count = 1) { if ($count != 1) { return $word; } - $singular = array ( - '/(quiz)zes$/i' => '\1', - '/(matr)ices$/i' => '\1ix', - '/(vert|ind)ices$/i' => '\1ex', - '/^(ox)en/i' => '\1', - '/(alias|status)es$/i' => '\1', - '/([octop|vir])i$/i' => '\1us', - '/(cris|ax|test)es$/i' => '\1is', - '/(shoe)s$/i' => '\1', - '/(o)es$/i' => '\1', - '/(bus)es$/i' => '\1', - '/([m|l])ice$/i' => '\1ouse', - '/(x|ch|ss|sh)es$/i' => '\1', - '/(m)ovies$/i' => '\1ovie', - '/(s)eries$/i' => '\1eries', - '/([^aeiouy]|qu)ies$/i' => '\1y', - '/([lr])ves$/i' => '\1f', - '/(tive)s$/i' => '\1', - '/(hive)s$/i' => '\1', - '/([^f])ves$/i' => '\1fe', - '/(^analy)ses$/i' => '\1sis', - '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', - '/([ti])a$/i' => '\1um', - '/(n)ews$/i' => '\1ews', - '/s$/i' => '', - ); - - $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); - - $irregular = array( - 'person' => 'people', - 'man' => 'men', - 'child' => 'children', - 'sex' => 'sexes', - 'move' => 'moves'); - $lowercased_word = strtolower($word); - foreach ($uncountable as $_uncountable) { + foreach ($this->uncountable as $_uncountable) { if (substr($lowercased_word, (-1*strlen($_uncountable))) == $_uncountable) { return $word; } } - foreach ($irregular as $_plural => $_singular) { + foreach ($this->irregular as $_plural => $_singular) { if (preg_match('/('.$_singular.')$/i', $word, $arr)) { return preg_replace('/('.$_singular.')$/i', substr($arr[0], 0, 1).substr($_plural, 1), $word); } } - foreach ($singular as $rule => $replacement) { + foreach ($this->singular as $rule => $replacement) { if (preg_match($rule, $word)) { return preg_replace($rule, $replacement, $word); } @@ -162,24 +117,22 @@ class Inflector * Converts an underscored or CamelCase word into a English * sentence. * - * The titleize static public function converts text like "WelcomePage", + * The titleize public function converts text like "WelcomePage", * "welcome_page" or "welcome page" to this "Welcome * Page". * If second parameter is set to 'first' it will only * capitalize the first character of the title. * - * @access static public - * @static * @param string $word Word to format as tile * @param string $uppercase If set to 'first' it will only uppercase the * first character. Otherwise it will uppercase all * the words in the title. * @return string Text formatted as title */ - public static function titleize($word, $uppercase = '') + public function titleize($word, $uppercase = '') { $uppercase = $uppercase == 'first' ? 'ucfirst' : 'ucwords'; - return $uppercase(static::humanize(static::underscorize($word))); + return $uppercase($this->humanize($this->underscorize($word))); } /** @@ -189,13 +142,11 @@ class Inflector * will remove non alphanumeric character from the word, so * "who's online" will be converted to "WhoSOnline" * - * @access static public - * @static * @see variablize * @param string $word Word to convert to camel case * @return string UpperCamelCasedWord */ - public static function camelize($word) + public function camelize($word) { return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word))); } @@ -208,12 +159,10 @@ class Inflector * * This can be really useful for creating friendly URLs. * - * @access static public - * @static * @param string $word Word to underscore * @return string Underscored word */ - public static function underscorize($word) + public function underscorize($word) { $regex1 = preg_replace('/([A-Z]+)([A-Z][a-z])/', '\1_\2', $word); $regex2 = preg_replace('/([a-zd])([A-Z])/', '\1_\2', $regex1); @@ -229,12 +178,10 @@ class Inflector * * This can be really useful for creating friendly URLs. * - * @access static public - * @static * @param string $word Word to hyphenate * @return string hyphenized word */ - public static function hyphenize($word) + public function hyphenize($word) { $regex1 = preg_replace('/([A-Z]+)([A-Z][a-z])/', '\1-\2', $word); $regex2 = preg_replace('/([a-zd])([A-Z])/', '\1-\2', $regex1); @@ -252,14 +199,12 @@ class Inflector * If you need to uppercase all the words you just have to * pass 'all' as a second parameter. * - * @access static public - * @static * @param string $word String to "humanize" * @param string $uppercase If set to 'all' it will uppercase all the words * instead of just the first one. * @return string Human-readable word */ - public static function humanize($word, $uppercase = '') + public function humanize($word, $uppercase = '') { $uppercase = $uppercase == 'all' ? 'ucwords' : 'ucfirst'; return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word))); @@ -272,15 +217,13 @@ class Inflector * will remove non alphanumeric character from the word, so * "who's online" will be converted to "whoSOnline" * - * @access static public - * @static * @see camelize * @param string $word Word to lowerCamelCase * @return string Returns a lowerCamelCasedWord */ - public static function variablize($word) + public function variablize($word) { - $word = static::camelize($word); + $word = $this->camelize($word); return strtolower($word[0]).substr($word, 1); } @@ -290,15 +233,13 @@ class Inflector * * Converts "Person" to "people" * - * @access static public - * @static * @see classify * @param string $class_name Class name for getting related table_name. * @return string plural_table_name */ - public static function tableize($class_name) + public function tableize($class_name) { - return static::pluralize(static::underscore($class_name)); + return $this->pluralize($this->underscore($class_name)); } /** @@ -307,15 +248,13 @@ class Inflector * * Converts "people" to "Person" * - * @access static public - * @static * @see tableize * @param string $table_name Table name for getting related ClassName. * @return string SingularClassName */ - public static function classify($table_name) + public function classify($table_name) { - return static::camelize(static::singularize($table_name)); + return $this->camelize($this->singularize($table_name)); } /** @@ -323,34 +262,32 @@ class Inflector * * This method converts 13 to 13th, 2 to 2nd ... * - * @access static public - * @static * @param integer $number Number to get its ordinal value * @return string Ordinal representation of given string. */ - public static function ordinalize($number) + public function ordinalize($number) { if (in_array(($number % 100), range(11, 13))) { - return $number.'th'; + return $number.$this->ordinals['default']; } else { switch (($number % 10)) { case 1: - return $number.'st'; + return $number.$this->ordinals['first']; break; case 2: - return $number.'nd'; + return $number.$this->ordinals['second']; break; case 3: - return $number.'rd'; + return $number.$this->ordinals['third']; break; default: - return $number.'th'; + return $number.$this->ordinals['default']; break; } } } - public static function monthize($days) + public function monthize($days) { $now = new \DateTime(); $end = new \DateTime(); diff --git a/system/src/Grav/Common/Language/Language.php b/system/src/Grav/Common/Language/Language.php index 9069c2a10..6c890b1bc 100644 --- a/system/src/Grav/Common/Language/Language.php +++ b/system/src/Grav/Common/Language/Language.php @@ -276,13 +276,15 @@ class Language /** * Translate a key and possibly arguments into a string using current lang and fallbacks * - * @param $args first argument is the lookup key value - * other arguments can be passed and replaced in the translation with sprintf syntax + * @param $args first argument is the lookup key value + * other arguments can be passed and replaced in the translation with sprintf syntax * @param Array $languages + * @param bool $array_support + * @param bool $html_out * * @return string */ - public function translate($args, Array $languages = null) + public function translate($args, Array $languages = null, $array_support = false, $html_out = false) { if (is_array($args)) { $lookup = array_shift($args); @@ -306,7 +308,7 @@ class Language } foreach ((array)$languages as $lang) { - $translation = $this->getTranslation($lang, $lookup); + $translation = $this->getTranslation($lang, $lookup, $array_support); if ($translation) { if (count($args) >= 1) { @@ -318,7 +320,11 @@ class Language } } - return '' . $lookup . ''; + if ($html_out) { + return '' . $lookup . ''; + } else { + return $lookup; + } } /** @@ -327,10 +333,11 @@ class Language * @param $key * @param $index * @param null $languages + * @param bool $html_out * * @return string */ - public function translateArray($key, $index, $languages = null) + public function translateArray($key, $index, $languages = null, $html_out = false) { if ($this->config->get('system.languages.translations', true)) { if ($this->enabled() && $key) { @@ -353,21 +360,26 @@ class Language } } - return '' . $key . '[' . $index . ']'; + if ($html_out) { + return '' . $key . '[' . $index . ']'; + } else { + return $key . '[' . $index . ']'; + } } /** * Lookup the translation text for a given lang and key * - * @param $lang lang code - * @param $key key to lookup with + * @param $lang lang code + * @param $key key to lookup with + * @param bool $array_support * * @return string */ - public function getTranslation($lang, $key) + public function getTranslation($lang, $key, $array_support = false) { $translation = $this->config->getLanguages()->get($lang . '.' . $key, null); - if (is_array($translation)) { + if (!$array_support && is_array($translation)) { return (string)array_shift($translation); } diff --git a/system/src/Grav/Common/Plugins.php b/system/src/Grav/Common/Plugins.php index 77a2afa2e..dd5fb74a0 100644 --- a/system/src/Grav/Common/Plugins.php +++ b/system/src/Grav/Common/Plugins.php @@ -32,6 +32,8 @@ class Plugins extends Iterator $config = self::getGrav()['config']; $plugins = (array) $config->get('plugins'); + $inflector = self::getGrav()['inflector']; + /** @var EventDispatcher $events */ $events = self::getGrav()['events']; @@ -52,7 +54,7 @@ class Plugins extends Iterator $pluginClassFormat = [ 'Grav\\Plugin\\'.ucfirst($plugin).'Plugin', - 'Grav\\Plugin\\'.Inflector::camelize($plugin).'Plugin' + 'Grav\\Plugin\\'.$inflector->camelize($plugin).'Plugin' ]; $pluginClassName = false; diff --git a/system/src/Grav/Common/Themes.php b/system/src/Grav/Common/Themes.php index b27a32c87..516a9d2fb 100644 --- a/system/src/Grav/Common/Themes.php +++ b/system/src/Grav/Common/Themes.php @@ -141,15 +141,16 @@ class Themes extends Iterator $locator = $grav['locator']; $file = $locator('theme://theme.php') ?: $locator("theme://{$name}.php"); + $inflector = $grav['inflector']; + if ($file) { // Local variables available in the file: $grav, $config, $name, $file $class = include $file; if (!is_object($class)) { - $themeClassFormat = [ 'Grav\\Theme\\'.ucfirst($name), - 'Grav\\Theme\\'.Inflector::camelize($name) + 'Grav\\Theme\\'.$inflector->camelize($name) ]; $themeClassName = false; diff --git a/system/src/Grav/Common/Twig/TwigExtension.php b/system/src/Grav/Common/Twig/TwigExtension.php index f2cba017f..1e8ef609c 100644 --- a/system/src/Grav/Common/Twig/TwigExtension.php +++ b/system/src/Grav/Common/Twig/TwigExtension.php @@ -194,16 +194,18 @@ class TwigExtension extends \Twig_Extension // TODO: check this and fix the docblock if needed. $action = $action.'ize'; + $inflector = $this->grav['inflector']; + if (in_array( $action, ['titleize','camelize','underscorize','hyphenize', 'humanize','ordinalize','monthize'] )) { - return Inflector::$action($data); + return $inflector->$action($data); } elseif (in_array($action, ['pluralize','singularize'])) { if ($count) { - return Inflector::$action($data, $count); + return $inflector->$action($data, $count); } else { - return Inflector::$action($data); + return $inflector->$action($data); } } else { return $data; From 8e57839271ccdd3f2b2591e94eea01d99df3d0e2 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 24 Jul 2015 10:55:57 -0600 Subject: [PATCH 36/76] missing some init() checks --- system/src/Grav/Common/Inflector.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/system/src/Grav/Common/Inflector.php b/system/src/Grav/Common/Inflector.php index 2c89f7313..ff1030ef7 100644 --- a/system/src/Grav/Common/Inflector.php +++ b/system/src/Grav/Common/Inflector.php @@ -87,6 +87,8 @@ class Inflector */ public function singularize($word, $count = 1) { + $this->init(); + if ($count != 1) { return $word; } @@ -267,6 +269,8 @@ class Inflector */ public function ordinalize($number) { + $this->init(); + if (in_array(($number % 100), range(11, 13))) { return $number.$this->ordinals['default']; } else { From e22655b440b2a2f34f1ef624e9dbc795bd4a6d27 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 24 Jul 2015 15:16:36 -0600 Subject: [PATCH 37/76] updated site.yaml blueprint --- system/blueprints/config/site.yaml | 73 +++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 16 deletions(-) diff --git a/system/blueprints/config/site.yaml b/system/blueprints/config/site.yaml index 604be106d..f29e1b82c 100644 --- a/system/blueprints/config/site.yaml +++ b/system/blueprints/config/site.yaml @@ -13,17 +13,19 @@ form: label: Site Title size: large placeholder: "Site wide title" - help: Default title for your site + help: "Default title for your site, often used in themes" author.name: type: text size: large label: Default Author + help: "A default author name, often used in themes or page content" author.email: type: text size: large label: Default Email + help: "A default email to reference in themes or pages" validate: type: email @@ -32,41 +34,80 @@ form: size: large label: Taxonomy Types classes: fancy + help: "Taxonomy types must be defined here if you wish to use them in pages" validate: type: commalist - metadata: - type: array - label: Metadata - placeholder_key: Name - placeholder_value: Content - - blog: + summary: type: section - title: Blog + title: Page Summary fields: - blog.route: - type: text - size: large - label: Blog URL + summary.enabled: + type: toggle + label: Enabled + highlight: 1 + help: "Enable page summary (the summary returns the same as the page content)" + options: + 1: Yes + 0: No + validate: + type: bool summary.size: type: text size: x-small label: Summary Size + help: "The amount of characters of a page to use as a content summary" validate: type: int min: 0 max: 65536 - routes: + summary.format: + type: toggle + label: Format + classes: fancy + help: "short = use the first occurrence of delimiter or size; long = summary delimiter will be ignored" + highlight: short + options: + 'short': 'Short' + 'long': 'Long' + + summary.delimiter: + type: text + size: x-small + label: Delimiter + help: "The summary delimiter (default '===')" + + metadata: type: section - title: Routes + title: Metadata fields: + metadata: + type: array + label: Metadata + help: "Default metadata values that will be displayed on every page unless overridden by the page" + placeholder_key: Name + placeholder_value: Content + + + routes: + type: section + title: Redirects & Routes + + fields: + redirects: + type: array + label: Custom Redirects + help: "routes to redirect to other pages. Standard Regex replacement is valid" + placeholder_key: /your/alias + placeholder_value: /your/redirect + routes: type: array - label: Custom + label: Custom Routes + help: "routes to alias to other pages. Standard Regex replacement is valid" placeholder_key: /your/alias placeholder_value: /your/route From b23aa1bc4c741c50ac7ff01feb0c58f7df440b73 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 24 Jul 2015 17:29:37 -0600 Subject: [PATCH 38/76] tweaks to system blueprint --- system/blueprints/config/system.yaml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index bd9337ec4..71d371ca6 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -37,7 +37,15 @@ form: twig: Twig use: keys - + timezone: + type: select + label: Timezone + classes: fancy + help: "Override the default timezone the server" + @data-options: '\Grav\Common\Utils::timezones' + default: '' + options: + '': 'Default (Server Timezone)' pages.dateformat.short: type: select @@ -665,15 +673,7 @@ form: validate: type: bool - timezone: - type: select - label: Timezone - classes: fancy - help: "The default timezone the server is should based time and dates off" - @data-options: '\Grav\Common\Utils::timezones' - default: '' - options: - '': '- None -' + param_sep: type: select From e26b80d873d81daa6097adba6a6e918cebab4446 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 27 Jul 2015 08:32:29 -0600 Subject: [PATCH 39/76] removed some extraneous messages --- system/src/Grav/Common/Config/Config.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/system/src/Grav/Common/Config/Config.php b/system/src/Grav/Common/Config/Config.php index 646abee27..cebfc7ec3 100644 --- a/system/src/Grav/Common/Config/Config.php +++ b/system/src/Grav/Common/Config/Config.php @@ -120,7 +120,6 @@ class Config extends Data $setup['streams']['schemes'] += $this->streams; $setup = $this->autoDetectEnvironmentConfig($setup); - $this->messages[] = $setup['streams']['schemes']['config']['prefixes']['']; $this->setup = $setup; parent::__construct($setup); @@ -202,24 +201,20 @@ class Config extends Data // Generate checksum according to the configuration settings. if (!$checkConfig) { - $this->messages[] = 'Check configuration timestamps from system.yaml files.'; // Just check changes in system.yaml files and ignore all the other files. $cc = $checkSystem ? $this->finder->locateConfigFile($this->configLookup, 'system') : []; } else { - $this->messages[] = 'Check configuration timestamps from all configuration files.'; // Check changes in all configuration files. $cc = $this->finder->locateConfigFiles($this->configLookup, $this->pluginLookup); } if ($checkBlueprints) { - $this->messages[] = 'Check blueprint timestamps from all blueprint files.'; $cb = $this->finder->locateBlueprintFiles($this->blueprintLookup, $this->pluginLookup); } else { $cb = []; } if ($checkLanguages) { - $this->messages[] = 'Check language timestamps from all language files.'; $cl = $this->finder->locateLanguageFiles($this->languagesLookup, $this->pluginLookup); } else { $cl = []; From bb4eea7999d16bd5feee9263c8b2ccdb3b970f0b Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 28 Jul 2015 04:54:16 -0600 Subject: [PATCH 40/76] missing use statement - issue #230 --- system/src/Grav/Common/Page/Medium/ImageFile.php | 1 + 1 file changed, 1 insertion(+) diff --git a/system/src/Grav/Common/Page/Medium/ImageFile.php b/system/src/Grav/Common/Page/Medium/ImageFile.php index 9514653f2..bb9ce59aa 100644 --- a/system/src/Grav/Common/Page/Medium/ImageFile.php +++ b/system/src/Grav/Common/Page/Medium/ImageFile.php @@ -2,6 +2,7 @@ namespace Grav\Common\Page\Medium; use Grav\Common\GravTrait; +use Gregwar\Image\Exceptions\GenerationError; use RocketTheme\Toolbox\Event\Event; class ImageFile extends \Gregwar\Image\Image From f30af37faf5e64981c8481f2e6aa969384b67cac Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 28 Jul 2015 11:10:38 -0600 Subject: [PATCH 41/76] php tidy --- system/src/Grav/Common/User/User.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/User/User.php b/system/src/Grav/Common/User/User.php index 71bbc0fc0..6528d9b0c 100644 --- a/system/src/Grav/Common/User/User.php +++ b/system/src/Grav/Common/User/User.php @@ -9,6 +9,9 @@ use Grav\Common\GravTrait; /** * User object * + * @property mixed authenticated + * @property mixed password + * @property bool|string hashed_password * @author RocketTheme * @license MIT */ @@ -57,14 +60,13 @@ class User extends Data // Plain-text is still stored if ($this->password) { - if ($password !== $this->password) { // Plain-text passwords do not match, we know we should fail but execute // verify to protect us from timing attacks and return false regardless of // the result Authentication::verify($password, self::getGrav()['config']->get('system.security.default_hash')); return false; - } else { + } else { // Plain-text does match, we can update the hash and proceed $save = true; From a009c56271e3f8b8979994d8de618db0c590a214 Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Tue, 28 Jul 2015 11:08:37 -0700 Subject: [PATCH 42/76] Supported Language and Taxonomies are now using Selectize tags in admin --- system/blueprints/config/site.yaml | 2 +- system/blueprints/config/system.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/system/blueprints/config/site.yaml b/system/blueprints/config/site.yaml index f29e1b82c..9c74d59d0 100644 --- a/system/blueprints/config/site.yaml +++ b/system/blueprints/config/site.yaml @@ -30,7 +30,7 @@ form: type: email taxonomies: - type: text + type: selectize size: large label: Taxonomy Types classes: fancy diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index 71d371ca6..5949c0a1b 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -145,7 +145,7 @@ form: fields: languages.supported: - type: text + type: selectize size: large label: Supported help: "Comma separated list of 2 letter language codes (for example 'en,fr,de')" From d244442e70288f852af769798dcb9a798a4ccd58 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 28 Jul 2015 12:11:07 -0600 Subject: [PATCH 43/76] fixed translations with multiple plugins --- system/src/Grav/Common/Config/Config.php | 5 ++++- system/src/Grav/Common/Config/ConfigFinder.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Config/Config.php b/system/src/Grav/Common/Config/Config.php index cebfc7ec3..a6bf9c183 100644 --- a/system/src/Grav/Common/Config/Config.php +++ b/system/src/Grav/Common/Config/Config.php @@ -414,7 +414,10 @@ class Config extends Data { foreach ($files as $name => $item) { $file = CompiledYamlFile::instance($item['file']); - $this->languages->join($name, $file->content(), '/'); + $content = $file->content(); + foreach ((array) $content as $key => $value) { + $this->languages->join($key, $value, '/'); + } } } diff --git a/system/src/Grav/Common/Config/ConfigFinder.php b/system/src/Grav/Common/Config/ConfigFinder.php index 7d79b765b..46069410d 100644 --- a/system/src/Grav/Common/Config/ConfigFinder.php +++ b/system/src/Grav/Common/Config/ConfigFinder.php @@ -143,7 +143,7 @@ class ConfigFinder $filename = "{$path}/{$name}/$find"; if (file_exists($filename)) { - $list["plugins"] = ['file' => $filename, 'modified' => filemtime($filename)]; + $list[$name] = ['file' => $filename, 'modified' => filemtime($filename)]; } } } From 1a43d31c50ea275e30613eb07a7ad4ff3af0a779 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 28 Jul 2015 16:23:49 -0600 Subject: [PATCH 44/76] whitespace removal --- system/blueprints/config/system.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index 5949c0a1b..b234a3216 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -208,8 +208,6 @@ form: validate: type: bool - - http_headers: type: section title: HTTP Headers From e97aaccfee32e70a1c571c60d97219710a872ee6 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 28 Jul 2015 20:57:16 -0600 Subject: [PATCH 45/76] added a cache_all option for media images --- system/blueprints/config/system.yaml | 13 ++++++++++- system/config/system.yaml | 1 + .../Grav/Common/Page/Medium/ImageMedium.php | 23 +++++++++++++++++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index b234a3216..322a30358 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -584,13 +584,24 @@ form: images.default_image_quality: type: text label: Default image quality - help: "Default image quality to use when resampling images (85%)" + help: "Default image quality to use when resampling or caching images (85%)" classes: x-small validate: type: number min: 1 max: 100 + images.cache_all: + type: toggle + label: Cache all images + help: "Run all images through Grav's cache system even if they have no media manipulations" + highlight: 0 + options: + 1: Yes + 0: No + validate: + type: bool + images.debug: type: toggle label: Image debug watermark diff --git a/system/config/system.yaml b/system/config/system.yaml index d8cb1b314..77edb1d93 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -87,6 +87,7 @@ debugger: images: default_image_quality: 85 # Default image quality to use when resampling images (85%) + cache_all: false # Cache all image by default debug: false # Show an overlay over images indicating the pixel depth of the image when working with retina for example media: diff --git a/system/src/Grav/Common/Page/Medium/ImageMedium.php b/system/src/Grav/Common/Page/Medium/ImageMedium.php index 05f75da8d..17fd32151 100644 --- a/system/src/Grav/Common/Page/Medium/ImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ImageMedium.php @@ -66,17 +66,23 @@ class ImageMedium extends Medium { parent::__construct($items, $blueprint); + $config = self::$grav['config']; + $image_info = getimagesize($this->get('filepath')); $this->def('width', $image_info[0]); $this->def('height', $image_info[1]); $this->def('mime', $image_info['mime']); - $this->def('debug', self::$grav['config']->get('system.images.debug')); + $this->def('debug', $config->get('system.images.debug')); $this->set('thumbnails.media', $this->get('filepath')); - $this->default_quality = self::$grav['config']->get('system.images.default_image_quality', 85); + $this->default_quality = $config->get('system.images.default_image_quality', 85); $this->reset(); + + if ($config->get('system.images.cache_all', false)) { + $this->cache(); + } } /** @@ -129,6 +135,19 @@ class ImageMedium extends Medium return self::$grav['base_url'] . $output . $this->querystring() . $this->urlHash(); } + /** + * Simply processes with no extra methods. Useful for triggering events. + * + * @return $this + */ + public function cache() + { + if (!$this->image) { + $this->image(); + } + return $this; + } + /** * Return srcset string for this Medium and its alternatives. From baa0e737039bec3d3cb205d3078b236c8f642d8f Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 29 Jul 2015 11:31:50 -0600 Subject: [PATCH 46/76] updated default yaml --- system/blueprints/pages/default.yaml | 134 ++++++++++++++++++++------- 1 file changed, 102 insertions(+), 32 deletions(-) diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml index e907e80c6..7dddbf1a1 100644 --- a/system/blueprints/pages/default.yaml +++ b/system/blueprints/pages/default.yaml @@ -29,19 +29,6 @@ form: validate: required: true - header.process: - type: checkboxes - label: Process - toggleable: true - @config-default: system.pages.process - default: - markdown: true - twig: false - options: - markdown: Markdown - twig: Twig - use: keys - content: type: markdown label: Content @@ -52,30 +39,113 @@ form: type: uploads label: Page Media - meta: + options: type: tab - title: Meta + title: Options fields: - header.description: - type: textarea - label: Description - validate: - max: 120 - header.keywords: - type: text - label: Keywords - validate: - max: 120 + standard: + type: section + title: Standard + underline: true - header.robots: - type: checkboxes - label: Robots - options: - noindex: No index - nofollow: No follow - use: keys + fields: + header.slug: + type: text + label: Slug + toggleable: true + help: "The slug variable allows you to specifically set the page's portion of the URL" + validate: + message: A slug must contain only lowercase alphanumeric characters and dashes + pattern: '^[a-z0-9-]+$' + + header.menu: + type: text + label: Menu + toggleable: true + help: "The string to be used in a menu. If not set, Title will be used." + + header.visible: + type: toggle + label: Visible + help: "Determines if a page is visible in the navigation." + highlight: 1 + default: 1 + options: + 1: Yes + 0: No + validate: + type: bool + + header.date: + type: datetime + label: Date + toggleable: true + help: "The date variable allows you to specifically set a date associated with this page." + + header.published: + type: toggle + label: Published + default: 1 + help: "By default, a page is published unless you explicitly set published: false or via a publish_date being in the future, or unpublish_date in the past" + highlight: 1 + options: + 1: Yes + 0: No + validate: + type: bool + + header.published_date: + type: datetime + label: Published Date + toggleable: true + help: "Can provide a date to automatically trigger publication." + + header.unpublished_date: + type: datetime + label: Unublished Date + toggleable: true + help: "can provide a date to automatically trigger un-publication." + + header.process: + type: checkboxes + label: Process + toggleable: true + @config-default: system.pages.process + default: + markdown: true + twig: false + options: + markdown: Markdown + twig: Twig + use: keys + + meta: + type: section + title: Metadata + underline: true + + fields: + header.metadata.description: + type: textarea + label: Description + validate: + max: 120 + + header.metadata.keywords: + type: text + label: Keywords + validate: + max: 120 + + header.metadata.robots: + type: checkboxes + label: Robots + options: + noindex: No index + nofollow: No follow + use: keys taxonomies: type: section From b9f9570033ff147aca20f0ca75f3490397ce9d31 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 29 Jul 2015 12:19:56 -0600 Subject: [PATCH 47/76] minor reformatting --- system/blueprints/pages/default.yaml | 92 ++++++++++++++-------------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml index 7dddbf1a1..bb3fec913 100644 --- a/system/blueprints/pages/default.yaml +++ b/system/blueprints/pages/default.yaml @@ -45,33 +45,18 @@ form: fields: - standard: + publishing: type: section - title: Standard + title: Publishing underline: true fields: - header.slug: - type: text - label: Slug - toggleable: true - help: "The slug variable allows you to specifically set the page's portion of the URL" - validate: - message: A slug must contain only lowercase alphanumeric characters and dashes - pattern: '^[a-z0-9-]+$' - - header.menu: - type: text - label: Menu - toggleable: true - help: "The string to be used in a menu. If not set, Title will be used." - - header.visible: + header.published: type: toggle - label: Visible - help: "Determines if a page is visible in the navigation." - highlight: 1 + label: Published default: 1 + help: "By default, a page is published unless you explicitly set published: false or via a publish_date being in the future, or unpublish_date in the past" + highlight: 1 options: 1: Yes 0: No @@ -84,17 +69,7 @@ form: toggleable: true help: "The date variable allows you to specifically set a date associated with this page." - header.published: - type: toggle - label: Published - default: 1 - help: "By default, a page is published unless you explicitly set published: false or via a publish_date being in the future, or unpublish_date in the past" - highlight: 1 - options: - 1: Yes - 0: No - validate: - type: bool + header.published_date: type: datetime @@ -108,18 +83,7 @@ form: toggleable: true help: "can provide a date to automatically trigger un-publication." - header.process: - type: checkboxes - label: Process - toggleable: true - @config-default: system.pages.process - default: - markdown: true - twig: false - options: - markdown: Markdown - twig: Twig - use: keys + meta: type: section @@ -139,6 +103,12 @@ form: validate: max: 120 + header.metadata.author: + type: text + label: Author + validate: + max: 120 + header.metadata.robots: type: checkboxes label: Robots @@ -211,13 +181,45 @@ form: header.menu: type: text label: Menu + toggleable: true + help: "The string to be used in a menu. If not set, Title will be used." header.slug: type: text - label: Alias + label: Slug + toggleable: true + help: "The slug variable allows you to specifically set the page's portion of the URL" validate: + message: A slug must contain only lowercase alphanumeric characters and dashes rule: slug + + + header.process: + type: checkboxes + label: Process + toggleable: true + @config-default: system.pages.process + default: + markdown: true + twig: false + options: + markdown: Markdown + twig: Twig + use: keys + + header.visible: + type: toggle + label: Visible + help: "Determines if a page is visible in the navigation." + highlight: 1 + options: + '': Global + 1: Enabled + 0: Disabled + validate: + type: bool + header.cache_enable: type: toggle label: Caching From 0845b5e28a2e08dee8a6326f8b6ba6511d3ee9d2 Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Wed, 29 Jul 2015 20:43:13 -0700 Subject: [PATCH 48/76] Added support for select multiple attribute in array filter --- system/blueprints/pages/default.yaml | 1 + system/src/Grav/Common/Data/Validation.php | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml index bb3fec913..97a4a883a 100644 --- a/system/blueprints/pages/default.yaml +++ b/system/blueprints/pages/default.yaml @@ -126,6 +126,7 @@ form: header.taxonomy: type: taxonomy label: Taxonomy + multiple: true validate: type: array diff --git a/system/src/Grav/Common/Data/Validation.php b/system/src/Grav/Common/Data/Validation.php index d2b7066db..30db908f7 100644 --- a/system/src/Grav/Common/Data/Validation.php +++ b/system/src/Grav/Common/Data/Validation.php @@ -492,6 +492,7 @@ class Validation { $values = (array) $value; $options = isset($field['options']) ? array_keys($field['options']) : array(); + $multi = isset($field['multiple']) ? $field['multiple'] : false; if ($options) { $useKey = isset($field['use']) && $field['use'] == 'keys'; @@ -500,6 +501,12 @@ class Validation } } + if ($multi) { + foreach ($values as $key => $value) { + $values[$key] = explode(',', $value[0]); + } + } + return $values; } From c959fd9c4859adbda6d82aaea42041075fdd58bb Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 29 Jul 2015 21:58:53 -0600 Subject: [PATCH 49/76] rolled back to composer 2.7.1 due to broken CLI choice method --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 2203028c0..93613684a 100644 --- a/composer.json +++ b/composer.json @@ -9,9 +9,9 @@ "php": ">=5.4.0", "twig/twig": "~1.16", "erusev/parsedown-extra": "~0.7", - "symfony/yaml": "2.7.*", - "symfony/console": "2.7.*", - "symfony/event-dispatcher": "2.7.*", + "symfony/yaml": "2.7.1", + "symfony/console": "2.7.1", + "symfony/event-dispatcher": "2.7.1", "doctrine/cache": "~1.4", "maximebf/debugbar": "dev-master", "filp/whoops": "1.2.*@dev", From b201b21e460401fa1b7ba0b4b9400c4356de9052 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 29 Jul 2015 21:59:24 -0600 Subject: [PATCH 50/76] added blueprint hidden field to standard blueprints --- system/blueprints/pages/default.yaml | 3 +++ system/blueprints/pages/modular.yaml | 6 +++--- system/blueprints/pages/modular_new.yaml | 4 ++++ system/blueprints/pages/modular_raw.yaml | 2 ++ system/blueprints/pages/new.yaml | 4 ++++ system/blueprints/pages/raw.yaml | 2 ++ 6 files changed, 18 insertions(+), 3 deletions(-) diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml index bb3fec913..4f1a90794 100644 --- a/system/blueprints/pages/default.yaml +++ b/system/blueprints/pages/default.yaml @@ -256,3 +256,6 @@ form: type: hidden validate: type: commalist + + blueprint: + type: blueprint diff --git a/system/blueprints/pages/modular.yaml b/system/blueprints/pages/modular.yaml index 84236be45..e90f1d2ee 100644 --- a/system/blueprints/pages/modular.yaml +++ b/system/blueprints/pages/modular.yaml @@ -39,8 +39,8 @@ form: desc: Descending header.process: - type: ignore + type: ignore content: - type: ignore + type: ignore uploads: - type: ignore + type: ignore diff --git a/system/blueprints/pages/modular_new.yaml b/system/blueprints/pages/modular_new.yaml index 8951b8899..fe366439a 100644 --- a/system/blueprints/pages/modular_new.yaml +++ b/system/blueprints/pages/modular_new.yaml @@ -52,3 +52,7 @@ form: default: 1 validate: type: bool + + + blueprint: + type: blueprint diff --git a/system/blueprints/pages/modular_raw.yaml b/system/blueprints/pages/modular_raw.yaml index f7877772f..c22efe421 100644 --- a/system/blueprints/pages/modular_raw.yaml +++ b/system/blueprints/pages/modular_raw.yaml @@ -82,3 +82,5 @@ form: type: order label: Ordering + blueprint: + type: blueprint diff --git a/system/blueprints/pages/new.yaml b/system/blueprints/pages/new.yaml index 3d554bff1..b48000f2c 100644 --- a/system/blueprints/pages/new.yaml +++ b/system/blueprints/pages/new.yaml @@ -46,3 +46,7 @@ form: @data-options: '\Grav\Common\Page\Pages::types' validate: required: true + + + blueprint: + type: blueprint diff --git a/system/blueprints/pages/raw.yaml b/system/blueprints/pages/raw.yaml index 311cf77e3..c4f91ac3f 100644 --- a/system/blueprints/pages/raw.yaml +++ b/system/blueprints/pages/raw.yaml @@ -82,3 +82,5 @@ form: type: order label: Ordering + blueprint: + type: blueprint From c4daae2f95e6ffd9488bb1f563d4e7c3cdd7dde7 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 29 Jul 2015 22:00:03 -0600 Subject: [PATCH 51/76] added new blueprintName() method that takes into account blueprint value passed via a form --- system/src/Grav/Common/Page/Page.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 2e4529d37..42f8624a4 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -693,7 +693,19 @@ class Page /** @var Pages $pages */ $pages = self::getGrav()['pages']; - return $pages->blueprints($this->template()); + return $pages->blueprints($this->blueprintName()); + } + + /** + * Get the blueprint name for this page. Use the blueprint form field if set + * + * @return string + */ + public function blueprintName() + { + $blueprint_name = filter_input(INPUT_POST, 'blueprint', FILTER_SANITIZE_STRING) ?: $this->template(); + + return $blueprint_name; } /** From eefb761e9832d3f91c4325c4109ac29536efedd6 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Thu, 30 Jul 2015 19:17:04 +0200 Subject: [PATCH 52/76] Refresh session timeout --- system/src/Grav/Common/Session.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Session.php b/system/src/Grav/Common/Session.php index cdc2e9958..6c353d264 100644 --- a/system/src/Grav/Common/Session.php +++ b/system/src/Grav/Common/Session.php @@ -20,16 +20,20 @@ class Session extends \RocketTheme\Toolbox\Session\Session $uri = $this->grav['uri']; $config = $this->grav['config']; + $session_timeout = $config->get('system.session.timeout', 1800); + $session_path = $config->get('system.session.path', '/' . ltrim($uri->rootUrl(false), '/')); + if ($config->get('system.session.enabled')) { // Define session service. parent::__construct( - $config->get('system.session.timeout', 1800), - $config->get('system.session.path', '/' . ltrim($uri->rootUrl(false), '/')) + $session_timeout, + $session_path ); $site_identifier = $config->get('site.title', 'unkown'); $this->setName($config->get('system.session.name', 'grav_site') . '_' . substr(md5($site_identifier), 0, 7)); $this->start(); + setcookie(session_name(), session_id(), time() + $session_timeout, $session_path); } } } From 8962d2b1e4d70696ce0e9366a028d262b47e8e48 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Fri, 31 Jul 2015 15:48:47 +0200 Subject: [PATCH 53/76] Force english in admin --- system/src/Grav/Common/Language/Language.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Language/Language.php b/system/src/Grav/Common/Language/Language.php index 6c890b1bc..ea644e8af 100644 --- a/system/src/Grav/Common/Language/Language.php +++ b/system/src/Grav/Common/Language/Language.php @@ -295,7 +295,10 @@ class Language if ($this->config->get('system.languages.translations', true)) { - if ($this->enabled() && $lookup) { + + if (isset($this->grav['admin'])) { + $languages = ['en']; + } elseif ($this->enabled() && $lookup) { if (empty($languages)) { if ($this->config->get('system.languages.translations_fallback', true)) { $languages = $this->getFallbackLanguages(); From 656c23a89175b6b7146e31327ab0798f2e2af35a Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Fri, 31 Jul 2015 16:01:52 +0200 Subject: [PATCH 54/76] Correctly instantiate the Inflector $this->grav is not what we expect here. Got a fatal error on `$ bin/gpm` execution --- system/src/Grav/Common/GPM/GPM.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/system/src/Grav/Common/GPM/GPM.php b/system/src/Grav/Common/GPM/GPM.php index 049f0ec8c..1118b2955 100644 --- a/system/src/Grav/Common/GPM/GPM.php +++ b/system/src/Grav/Common/GPM/GPM.php @@ -349,8 +349,7 @@ class GPM extends Iterator public function findPackages($searches = []) { $packages = ['total' => 0, 'not_found' => []]; - $inflector = $this->grav['inflector']; - + $inflector = new Inflector(); foreach ($searches as $search) { $repository = ''; From 7fa3e7bf2899995c8f7888367965003e94d9050f Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Fri, 31 Jul 2015 16:06:02 +0200 Subject: [PATCH 55/76] Move $session_timeout & $session_path inside the if statement --- system/src/Grav/Common/Session.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/src/Grav/Common/Session.php b/system/src/Grav/Common/Session.php index 6c353d264..795fcae09 100644 --- a/system/src/Grav/Common/Session.php +++ b/system/src/Grav/Common/Session.php @@ -20,10 +20,10 @@ class Session extends \RocketTheme\Toolbox\Session\Session $uri = $this->grav['uri']; $config = $this->grav['config']; - $session_timeout = $config->get('system.session.timeout', 1800); - $session_path = $config->get('system.session.path', '/' . ltrim($uri->rootUrl(false), '/')); - if ($config->get('system.session.enabled')) { + $session_timeout = $config->get('system.session.timeout', 1800); + $session_path = $config->get('system.session.path', '/' . ltrim($uri->rootUrl(false), '/')); + // Define session service. parent::__construct( $session_timeout, From 3016e7789750b3e770298bd84753e638b010681f Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 31 Jul 2015 08:35:35 -0600 Subject: [PATCH 56/76] loose validation so un-formed values are not lost --- system/blueprints/pages/default.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml index d4f778a2b..4962d7d39 100644 --- a/system/blueprints/pages/default.yaml +++ b/system/blueprints/pages/default.yaml @@ -7,6 +7,8 @@ rules: max: 80 form: + validation: loose + fields: type: type: hidden From 532e0357244fe65766087660fb69cf8fdae2241b Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Fri, 31 Jul 2015 18:21:06 +0200 Subject: [PATCH 57/76] Load uri before session --- system/src/Grav/Common/Grav.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 2bcb9e9cd..5e4737411 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -174,8 +174,8 @@ class Grav extends Container // Initialize configuration. $debugger->startTimer('_config', 'Configuration'); $this['config']->init(); - $this['session']->init(); $this['uri']->init(); + $this['session']->init(); $this['errors']->resetHandlers(); $debugger->init(); $this['config']->debug(); From dc56f85881fcebbe904299ba9c5d0cf8b7deb59a Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Fri, 31 Jul 2015 18:21:43 +0200 Subject: [PATCH 58/76] Separate sessions for site and admin --- system/src/Grav/Common/Session.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Session.php b/system/src/Grav/Common/Session.php index 795fcae09..c587b6332 100644 --- a/system/src/Grav/Common/Session.php +++ b/system/src/Grav/Common/Session.php @@ -21,6 +21,14 @@ class Session extends \RocketTheme\Toolbox\Session\Session $config = $this->grav['config']; if ($config->get('system.session.enabled')) { + // Only activate admin if we're inside the admin path. + $is_admin = false; + $route = $config->get('plugins.admin.route'); + $base = '/' . trim($route, '/'); + if (substr($uri->route(), 0, strlen($base)) == $base) { + $is_admin = true; + } + $session_timeout = $config->get('system.session.timeout', 1800); $session_path = $config->get('system.session.path', '/' . ltrim($uri->rootUrl(false), '/')); @@ -30,8 +38,8 @@ class Session extends \RocketTheme\Toolbox\Session\Session $session_path ); - $site_identifier = $config->get('site.title', 'unkown'); - $this->setName($config->get('system.session.name', 'grav_site') . '_' . substr(md5($site_identifier), 0, 7)); + $site_identifier = $config->get('site.title', 'unknown'); + $this->setName($config->get('system.session.name', 'grav_site') . '_' . substr(md5($site_identifier), 0, 7) . ($is_admin ? '_admin' : '')); $this->start(); setcookie(session_name(), session_id(), time() + $session_timeout, $session_path); } From c18311eeb261be7f8a0f5c4459b2b0732ef64a74 Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Fri, 31 Jul 2015 13:10:24 -0700 Subject: [PATCH 59/76] Moved blog and blog item blueprints out of Grav and into Antimatter theme --- system/blueprints/pages/blog.yaml | 76 ---------------------------- system/blueprints/pages/item.yaml | 83 ------------------------------- 2 files changed, 159 deletions(-) delete mode 100644 system/blueprints/pages/blog.yaml delete mode 100644 system/blueprints/pages/item.yaml diff --git a/system/blueprints/pages/blog.yaml b/system/blueprints/pages/blog.yaml deleted file mode 100644 index b5937f959..000000000 --- a/system/blueprints/pages/blog.yaml +++ /dev/null @@ -1,76 +0,0 @@ -title: Blog -@extends: - type: default - context: blueprints://pages - -child_type: item - - -title: Default - -rules: - slug: - pattern: "[a-z][a-z0-9_\-]+" - min: 2 - max: 80 - -form: - fields: - tabs: - type: tabs - active: 1 - - fields: - advanced: - fields: - overrides: - fields: - header.child_type: - default: item - blog: - type: tab - title: Blog List - - fields: - header.content.items: - type: select - label: Items - default: @self.children - options: - @self.children: Children - - header.content.limit: - type: text - label: Max Item Count - default: 5 - validate: - required: true - type: int - min: 1 - - header.content.order.by: - type: select - label: Order By - default: date - options: - folder: Folder - title: Title - date: Date - default: Default - - header.content.order.dir: - type: select - label: Order - default: desc - options: - asc: Ascending - desc: Descending - - header.content.pagination: - type: toggle - label: Pagination - highlight: 1 - default: 1 - options: - 1: Enabled - 0: Disabled diff --git a/system/blueprints/pages/item.yaml b/system/blueprints/pages/item.yaml deleted file mode 100644 index f31e9c9a9..000000000 --- a/system/blueprints/pages/item.yaml +++ /dev/null @@ -1,83 +0,0 @@ -title: Item -@extends: - type: default - context: blueprints://pages - -form: - fields: - tabs: - - fields: - blog: - type: tab - title: Blog Item - - - fields: - publishing: - type: section - title: Publishing - underline: true - - fields: - header.date: - type: datetime - label: Date - - header.publish_date: - type: datetime - label: Publish post on this date - - header.unpublish_date: - type: datetime - label: Unpublish post on this date - - header.published: - type: toggle - label: Published - highlight: 1 - default: 1 - options: - 1: Yes - 0: No - - summary: - type: section - title: Summary - underline: true - - fields: - - header.summary.enabled: - type: toggle - label: Summary - highlight: 1 - default: 1 - options: - 1: Enabled - 0: Disabled - - header.summary.format: - type: select - label: Format - classes: fancy - default: short - options: - 'short': 'Use the first occurence of delimter or size' - 'long': 'Summary delimiter will be ignored' - - header.summary.size: - type: text - label: Size - classes: large - default: 300 - validate: - type: int - min: 1 - - header.summary.delimiter: - type: text - label: Summary delimiter - classes: large - default: === - placeholder: === From 333814eab0efa348d028e88fb7964377fb073584 Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Fri, 31 Jul 2015 13:10:51 -0700 Subject: [PATCH 60/76] Reenabled toggleables for Published --- system/blueprints/pages/default.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml index 4962d7d39..20f01ec18 100644 --- a/system/blueprints/pages/default.yaml +++ b/system/blueprints/pages/default.yaml @@ -56,6 +56,7 @@ form: header.published: type: toggle label: Published + toggleable: true default: 1 help: "By default, a page is published unless you explicitly set published: false or via a publish_date being in the future, or unpublish_date in the past" highlight: 1 From ca12c69741869c6ebfcd378c90b06693b7b35c34 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sat, 1 Aug 2015 10:20:15 -0600 Subject: [PATCH 61/76] fix for system lang files --- system/src/Grav/Common/Config/Config.php | 35 ++++++++++++-------- system/src/Grav/Common/File/CompiledFile.php | 2 +- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/system/src/Grav/Common/Config/Config.php b/system/src/Grav/Common/Config/Config.php index a6bf9c183..98a7b3da8 100644 --- a/system/src/Grav/Common/Config/Config.php +++ b/system/src/Grav/Common/Config/Config.php @@ -336,6 +336,11 @@ class Config extends Data $this->items = $cache['data']; } + /** + * @param $languages + * @param $plugins + * @param null $filename + */ protected function loadCompiledLanguages($languages, $plugins, $filename = null) { $checksum = md5(json_encode($languages)); @@ -361,11 +366,24 @@ class Config extends Data // Load languages. $this->languages = new Languages; - foreach ($languageFiles as $files) { - $this->loadLanguagesFiles($files); + + if (isset($languageFiles['user/plugins'])) { + foreach ((array) $languageFiles['user/plugins'] as $plugin => $item) { + $lang_file = CompiledYamlFile::instance($item['file']); + $content = $lang_file->content(); + foreach ((array) $content as $lang => $value) { + $this->languages->join($lang, $value, '/'); + } + } } - $this->languages->reformat(); + if (isset($languageFiles['system/languages'])) { + foreach ((array) $languageFiles['system/languages'] as $lang => $item) { + $lang_file = CompiledYamlFile::instance($item['file']); + $content = $lang_file->content(); + $this->languages->join($lang, $content, '/'); + } + } $cache = [ '@class' => $class, @@ -410,17 +428,6 @@ class Config extends Data } } - public function loadLanguagesFiles(array $files) - { - foreach ($files as $name => $item) { - $file = CompiledYamlFile::instance($item['file']); - $content = $file->content(); - foreach ((array) $content as $key => $value) { - $this->languages->join($key, $value, '/'); - } - } - } - /** * Initialize resource locator by using the configuration. * diff --git a/system/src/Grav/Common/File/CompiledFile.php b/system/src/Grav/Common/File/CompiledFile.php index d9cf58d42..27fffc50b 100644 --- a/system/src/Grav/Common/File/CompiledFile.php +++ b/system/src/Grav/Common/File/CompiledFile.php @@ -25,7 +25,7 @@ trait CompiledFile // If nothing has been loaded, attempt to get pre-compiled version of the file first. if ($var === null && $this->raw === null && $this->content === null) { $key = md5($this->filename); - $file = PhpFile::instance(CACHE_DIR . "/compiled/files/{$key}{$this->extension}.php"); + $file = PhpFile::instance(CACHE_DIR . "compiled/files/{$key}{$this->extension}.php"); $modified = $this->modified(); if (!$modified) { From 49781f9717706d615562601ba80e062998dc84f6 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sat, 1 Aug 2015 13:36:52 -0600 Subject: [PATCH 62/76] made metadata optional --- system/blueprints/pages/default.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml index 20f01ec18..c9b697a7e 100644 --- a/system/blueprints/pages/default.yaml +++ b/system/blueprints/pages/default.yaml @@ -96,24 +96,29 @@ form: fields: header.metadata.description: type: textarea + toggleable: true label: Description + default: validate: - max: 120 + max: 155 header.metadata.keywords: type: text + toggleable: true label: Keywords validate: max: 120 header.metadata.author: type: text + toggleable: true label: Author validate: max: 120 header.metadata.robots: type: checkboxes + toggleable: true label: Robots options: noindex: No index From a7e03c9d5cfcee363d805618cec9a91f27029cd6 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sat, 1 Aug 2015 13:37:12 -0600 Subject: [PATCH 63/76] Stopped storing metadata in page header --- system/src/Grav/Common/Page/Page.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 42f8624a4..1f51f41ec 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -1017,24 +1017,29 @@ class Page if (null === $this->metadata) { $header_tag_http_equivs = ['content-type', 'default-style', 'refresh']; $this->metadata = array(); - $page_header = $this->header; // Set the Generator tag $this->metadata['generator'] = array('name'=>'generator', 'content'=>'GravCMS ' . GRAV_VERSION); - // Safety check to ensure we have a header - if ($page_header) { + + if (isset($this->header->metadata)) { + $page_header = $this->header->metadata; + + + + + // Merge any site.metadata settings in with page metadata $defaults = (array) self::getGrav()['config']->get('site.metadata'); - if (isset($page_header->metadata)) { - $page_header->metadata = array_merge($defaults, $page_header->metadata); + if (isset($page_header)) { + $page_header = array_merge($defaults, $page_header); } else { - $page_header->metadata = $defaults; + $page_header = $defaults; } // Build an array of meta objects.. - foreach ((array)$page_header->metadata as $key => $value) { + foreach ((array)$page_header as $key => $value) { // If this is a property type metadata: "og", "twitter", "facebook" etc if (is_array($value)) { foreach ($value as $property => $prop_value) { From 21beefd3879cdcce32131743e03ec8d6b75ab9fe Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sat, 1 Aug 2015 13:37:32 -0600 Subject: [PATCH 64/76] added `array()` function to cast as an array --- system/src/Grav/Common/Twig/TwigExtension.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/system/src/Grav/Common/Twig/TwigExtension.php b/system/src/Grav/Common/Twig/TwigExtension.php index 1e8ef609c..7addcc223 100644 --- a/system/src/Grav/Common/Twig/TwigExtension.php +++ b/system/src/Grav/Common/Twig/TwigExtension.php @@ -78,6 +78,7 @@ class TwigExtension extends \Twig_Extension new \Twig_SimpleFunction('debug', [$this, 'dump'], ['needs_context' => true, 'needs_environment' => true]), new \Twig_SimpleFunction('gist', [$this, 'gistFunc']), new \Twig_simpleFunction('random_string', [$this, 'randomStringFunc']), + new \Twig_SimpleFunction('array', [$this, 'arrayFunc']), new \Twig_simpleFunction('t', [$this, 'translate']), new \Twig_simpleFunction('ta', [$this, 'translateArray']) ]; @@ -481,6 +482,11 @@ class TwigExtension extends \Twig_Extension return Utils::generateRandomString($count); } + public function arrayFunc($value) + { + return (array) $value; + } + public function translateFunc() { return $this->grav['language']->translate(func_get_args()); From a1a10ab23d22a9ec0f3fe7e4d1e71b5ff3cc5700 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sat, 1 Aug 2015 17:40:58 -0600 Subject: [PATCH 65/76] more tweaks for blueprints --- system/blueprints/config/system.yaml | 2 ++ system/blueprints/pages/default.yaml | 18 +++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index 322a30358..ab1fead2c 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -23,6 +23,7 @@ form: pages.theme: type: themeselect classes: fancy + selectize: true size: medium label: Default theme help: "Set the default theme for Grav to use (default is Antimatter)" @@ -40,6 +41,7 @@ form: timezone: type: select label: Timezone + size: medium classes: fancy help: "Override the default timezone the server" @data-options: '\Grav\Common\Utils::timezones' diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml index c9b697a7e..f2064d0c6 100644 --- a/system/blueprints/pages/default.yaml +++ b/system/blueprints/pages/default.yaml @@ -56,11 +56,11 @@ form: header.published: type: toggle label: Published - toggleable: true - default: 1 help: "By default, a page is published unless you explicitly set published: false or via a publish_date being in the future, or unpublish_date in the past" highlight: 1 + size: medium options: + '': Global 1: Yes 0: No validate: @@ -217,6 +217,14 @@ form: twig: Twig use: keys + header.child_type: + type: select + toggleable: true + label: Default Child Type + default: default + placeholder: Use Global + @data-options: '\Grav\Common\Page\Pages::types' + header.visible: type: toggle label: Visible @@ -252,11 +260,7 @@ form: validate: type: bool - header.child_type: - type: select - label: Default Child Type - default: default - @data-options: '\Grav\Common\Page\Pages::types' + header.order_by: type: hidden From 4f442d1edcad7e876f3c33c1042358ae7a99af09 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 2 Aug 2015 12:13:08 -0600 Subject: [PATCH 66/76] support admin overrides of blueprints --- system/src/Grav/Common/Page/Page.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 1f51f41ec..2f0db1fdc 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -693,7 +693,21 @@ class Page /** @var Pages $pages */ $pages = self::getGrav()['pages']; - return $pages->blueprints($this->blueprintName()); + $blueprint = $pages->blueprints($this->blueprintName()); + + $fields = $blueprint->fields(); + + // override if you only want 'normal' mode + if (empty($fields) && self::getGrav()['admin'] && self::getGrav()['config']->get('plugins.admin.edit_mode', 'auto') == 'normal') { + $blueprint = $pages->blueprints('default'); + } + + // override if you only want 'expert' mode + if (!empty($fields) && self::getGrav()['admin'] && self::getGrav()['config']->get('plugins.admin.edit_mode', 'auto') == 'expert') { + $blueprint = $pages->blueprints(''); + } + + return $blueprint; } /** From 9f254b6c8424cf3c4f531576a85b0cbbc566ecb3 Mon Sep 17 00:00:00 2001 From: franchan Date: Sun, 2 Aug 2015 23:52:48 +0200 Subject: [PATCH 67/76] Fix #240 $page->content() fires the onPageContentRaw event. A plugin handler for this event might want to update the twig variable with additional information during twig rendering. However, $twig_vars takes a copy of $Twig->twig_vars and therefore never sees any later changes in $Twig->twig_vars. By moving the method call $page->content() earlier, potential twig variable changes from a plugin get now inside this local variable copy. --- system/src/Grav/Common/Twig/Twig.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Twig/Twig.php b/system/src/Grav/Common/Twig/Twig.php index 10d8c6539..d8f790962 100644 --- a/system/src/Grav/Common/Twig/Twig.php +++ b/system/src/Grav/Common/Twig/Twig.php @@ -301,13 +301,14 @@ class Twig $this->grav->fireEvent('onTwigSiteVariables'); $pages = $this->grav['pages']; $page = $this->grav['page']; + $content = $page->content(); $twig_vars = $this->twig_vars; $twig_vars['pages'] = $pages->root(); $twig_vars['page'] = $page; $twig_vars['header'] = $page->header(); - $twig_vars['content'] = $page->content(); + $twig_vars['content'] = $content; $ext = '.' . ($format ? $format : 'html') . TWIG_EXT; // determine if params are set, if so disable twig cache From bc5ea13821cc612f3f050af17c3170a652acaa8f Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 3 Aug 2015 10:19:56 +0200 Subject: [PATCH 68/76] Fix moving the page to the root $parent->route() returned null when moving to the root --- system/src/Grav/Common/Page/Page.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 2f0db1fdc..67560a0c7 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -658,9 +658,12 @@ class Page if ($parent->path()) { $clone->path($parent->path() . '/' . $clone->folder()); } + // TODO: make sure we always have the route. if ($parent->route()) { $clone->route($parent->route() . '/'. $clone->slug()); + } else { + $clone->route(self::getGrav()['pages']->root()->route() . '/'. $clone->slug()); } return $clone; From 109d19f02ef5d9e68b3adf81b8615e278e520a1b Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 3 Aug 2015 08:01:27 -0600 Subject: [PATCH 69/76] changed order --- system/blueprints/pages/default.yaml | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml index f2064d0c6..0fa743562 100644 --- a/system/blueprints/pages/default.yaml +++ b/system/blueprints/pages/default.yaml @@ -237,6 +237,19 @@ form: validate: type: bool + header.routable: + type: toggle + label: Routable + help: If this page is reachable by a URL + highlight: 1 + default: '' + options: + '': Global + 1: Enabled + 0: Disabled + validate: + type: bool + header.cache_enable: type: toggle label: Caching @@ -248,17 +261,7 @@ form: validate: type: bool - header.routable: - type: toggle - label: Access by URL - highlight: 1 - default: '' - options: - '': Global - 1: Enabled - 0: Disabled - validate: - type: bool + From 9746c2db5d6180571d73d0bb7533a46146726c9b Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Mon, 3 Aug 2015 12:43:24 -0700 Subject: [PATCH 70/76] Move yaml missing --- system/blueprints/pages/move.yaml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 system/blueprints/pages/move.yaml diff --git a/system/blueprints/pages/move.yaml b/system/blueprints/pages/move.yaml new file mode 100644 index 000000000..cd90dea8d --- /dev/null +++ b/system/blueprints/pages/move.yaml @@ -0,0 +1,17 @@ +rules: + slug: + pattern: "[a-z][a-z0-9_\-]+" + min: 2 + max: 80 + +form: + validation: loose + fields: + route: + type: select + label: Parent + classes: fancy + @data-options: '\Grav\Common\Page\Pages::parents' + @data-default: '\Grav\Plugin\admin::route' + options: + '/': '- Root -' From e142f5ee61846dc4e822d9fcf4fc0705ddae196c Mon Sep 17 00:00:00 2001 From: Sommerregen Date: Mon, 3 Aug 2015 22:08:07 +0200 Subject: [PATCH 71/76] Add language property to page --- system/src/Grav/Common/Page/Page.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 67560a0c7..0691cdd89 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -56,6 +56,7 @@ class Page protected $items; protected $header; protected $frontmatter; + protected $language; protected $content; protected $summary; protected $raw_content; @@ -127,6 +128,10 @@ class Page } else { $this->extension($extension); } + + // Exract page language from page extension + $language = trim(basename($this->extension(), 'md'), '.') ?: null; + $this->language($language); } /** @@ -217,6 +222,9 @@ class Page if (isset($this->header->title)) { $this->title = trim($this->header->title); } + if (isset($this->header->language)) { + $this->language = trim($this->header->language); + } if (isset($this->header->template)) { $this->template = trim($this->header->template); } @@ -281,6 +289,22 @@ class Page return $this->header; } + /** + * Get page language + * + * @param $var + * + * @return mixed + */ + public function language($var = null) + { + if ($var !== null) { + $this->language = $var; + } + + return $this->language; + } + /** * Modify a header value directly * From 75feea3e752de8167e5079f6a6d0dae153110ab9 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 3 Aug 2015 16:10:16 -0600 Subject: [PATCH 72/76] back to Symfony 2.7.3 --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 93613684a..775a77125 100644 --- a/composer.json +++ b/composer.json @@ -9,9 +9,9 @@ "php": ">=5.4.0", "twig/twig": "~1.16", "erusev/parsedown-extra": "~0.7", - "symfony/yaml": "2.7.1", - "symfony/console": "2.7.1", - "symfony/event-dispatcher": "2.7.1", + "symfony/yaml": "2.7.3", + "symfony/console": "2.7.3", + "symfony/event-dispatcher": "2.7.3", "doctrine/cache": "~1.4", "maximebf/debugbar": "dev-master", "filp/whoops": "1.2.*@dev", From bfc9efea927040f1893aea37234fd20d1431e096 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 3 Aug 2015 16:11:02 -0600 Subject: [PATCH 73/76] added new arrayFilterRecursive --- system/src/Grav/Common/Utils.php | 95 ++++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 29 deletions(-) diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index 7262c498c..5c38f97a9 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -13,8 +13,9 @@ abstract class Utils use GravTrait; /** - * @param string $haystack - * @param string $needle + * @param string $haystack + * @param string $needle + * * @return bool */ public static function startsWith($haystack, $needle) @@ -27,14 +28,17 @@ abstract class Utils return $status; } } + return $status; } + return $needle === '' || strpos($haystack, $needle) === 0; } /** - * @param string $haystack - * @param string $needle + * @param string $haystack + * @param string $needle + * * @return bool */ public static function endsWith($haystack, $needle) @@ -47,14 +51,17 @@ abstract class Utils return $status; } } + return $status; } + return $needle === '' || substr($haystack, -strlen($needle)) === $needle; } /** - * @param string $haystack - * @param string $needle + * @param string $haystack + * @param string $needle + * * @return bool */ public static function contains($haystack, $needle) @@ -67,11 +74,12 @@ abstract class Utils * * @param object $obj1 * @param object $obj2 + * * @return object */ public static function mergeObjects($obj1, $obj2) { - return (object) array_merge((array) $obj1, (array) $obj2); + return (object)array_merge((array)$obj1, (array)$obj2); } /** @@ -82,6 +90,7 @@ abstract class Utils * @param string $ending * @param bool $exact * @param bool $considerHtml + * * @return string */ public static function truncateHtml($text, $length = 100, $ending = '...', $exact = false, $considerHtml = true) @@ -100,34 +109,41 @@ abstract class Utils // if there is any html-tag in this line, handle it and add it (uncounted) to the output if (!empty($line_matchings[1])) { // if it's an "empty element" with or without xhtml-conform closing slash - if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $line_matchings[1])) { + if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', + $line_matchings[1])) { // do nothing - // if tag is a closing tag - } else if (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $line_matchings[1], $tag_matchings)) { - // delete tag from $open_tags list - $pos = array_search($tag_matchings[1], $open_tags); - if ($pos !== false) { - unset($open_tags[$pos]); + // if tag is a closing tag + } else { + if (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $line_matchings[1], $tag_matchings)) { + // delete tag from $open_tags list + $pos = array_search($tag_matchings[1], $open_tags); + if ($pos !== false) { + unset($open_tags[$pos]); + } + // if tag is an opening tag + } else { + if (preg_match('/^<\s*([^\s>!]+).*?>$/s', $line_matchings[1], $tag_matchings)) { + // add tag to the beginning of $open_tags list + array_unshift($open_tags, strtolower($tag_matchings[1])); + } } - // if tag is an opening tag - } else if (preg_match('/^<\s*([^\s>!]+).*?>$/s', $line_matchings[1], $tag_matchings)) { - // add tag to the beginning of $open_tags list - array_unshift($open_tags, strtolower($tag_matchings[1])); } // add html-tag to $truncate'd text $truncate .= $line_matchings[1]; } // calculate the length of the plain text part of the line; handle entities as one character - $content_length = strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', $line_matchings[2])); - if ($total_length+$content_length> $length) { + $content_length = strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', + $line_matchings[2])); + if ($total_length + $content_length > $length) { // the number of characters which are left $left = $length - $total_length; $entities_length = 0; // search for html entities - if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', $line_matchings[2], $entities, PREG_OFFSET_CAPTURE)) { + if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', $line_matchings[2], $entities, + PREG_OFFSET_CAPTURE)) { // calculate the real length of all entities in the legal range foreach ($entities[0] as $entity) { - if ($entity[1]+1-$entities_length <= $left) { + if ($entity[1] + 1 - $entities_length <= $left) { $left--; $entities_length += strlen($entity[0]); } else { @@ -136,7 +152,7 @@ abstract class Utils } } } - $truncate .= substr($line_matchings[2], 0, $left+$entities_length); + $truncate .= substr($line_matchings[2], 0, $left + $entities_length); // maximum length is reached, so get off the loop break; } else { @@ -172,6 +188,7 @@ abstract class Utils $truncate .= ''; } } + return $truncate; } @@ -208,7 +225,7 @@ abstract class Utils if ($force_download) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); - header('Content-Disposition: attachment; filename='.$file_parts['basename']); + header('Content-Disposition: attachment; filename=' . $file_parts['basename']); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); @@ -243,14 +260,14 @@ abstract class Utils * Return the mimetype based on filename * * @param $extension Extension of file (eg .txt) + * * @return string */ public static function getMimeType($extension) { $extension = strtolower($extension); - switch($extension) - { + switch ($extension) { case "js": return "application/x-javascript"; @@ -348,6 +365,7 @@ abstract class Utils * Normalize path by processing relative `.` and `..` syntax and merging path * * @param $path + * * @return string */ public static function normalizePath($path) @@ -366,6 +384,7 @@ abstract class Utils array_push($ret, $segment); } } + return $root . implode('/', $ret); } @@ -383,10 +402,9 @@ abstract class Utils asort($offsets); $timezone_list = array(); - foreach( $offsets as $timezone => $offset ) - { + foreach ($offsets as $timezone => $offset) { $offset_prefix = $offset < 0 ? '-' : '+'; - $offset_formatted = gmdate( 'H:i', abs($offset) ); + $offset_formatted = gmdate('H:i', abs($offset)); $pretty_offset = "UTC${offset_prefix}${offset_formatted}"; @@ -396,4 +414,23 @@ abstract class Utils return $timezone_list; } + + public static function arrayFilterRecursive(Array $source, $fn) + { + $result = array(); + foreach ($source as $key => $value) + { + if (is_array($value)) + { + $result[$key] = static::arrayFilterRecursive($value, $fn); + continue; + } + if ($fn($key, $value)) + { + $result[$key] = $value; // KEEP + continue; + } + } + return $result; + } } From 8963d024a66582906580b8e2dbafe373d47a7208 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 4 Aug 2015 09:40:28 -0600 Subject: [PATCH 74/76] more dynamic extension() method --- system/blueprints/pages/default.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml index 0fa743562..64a4bd029 100644 --- a/system/blueprints/pages/default.yaml +++ b/system/blueprints/pages/default.yaml @@ -27,6 +27,7 @@ form: fields: header.title: type: text + style: vertical label: Title validate: required: true From 1401102396122ce49d30e67a91c1f5596f5ba166 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 4 Aug 2015 09:40:59 -0600 Subject: [PATCH 75/76] more extensive extension() method --- system/src/Grav/Common/Page/Page.php | 35 ++++++++++++++-------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 67560a0c7..cdcfbb436 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -605,22 +605,6 @@ class Page return null; } - /** - * Get page extension - * - * @param $var - * - * @return mixed - */ - public function extension($var = null) - { - if ($var !== null) { - $this->extension = $var; - } - - return $this->extension; - } - /** * Save page if there's a file assigned to it. * @param bool $reorder Internal use. @@ -853,11 +837,28 @@ class Page $this->template = $var; } if (empty($this->template)) { - $this->template = ($this->modular() ? 'modular/' : '') . str_replace($this->extension, '', $this->name()); + $this->template = ($this->modular() ? 'modular/' : '') . str_replace($this->extension(), '', $this->name()); } return $this->template; } + /** + * Gets and sets the extension field. + * + * @param null $var + * @return null|string + */ + public function extension($var = null) + { + if ($var !== null) { + $this->extension = $var; + } + if (empty($this->extension)) { + $this->extension = '.' . pathinfo($this->name(), PATHINFO_EXTENSION); + } + return $this->extension; + } + /** * Gets and sets the expires field. If not set will return the default * From aa7a4111e62da03dcca6f60ca44a909fdd76130a Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 4 Aug 2015 16:53:16 -0600 Subject: [PATCH 76/76] version update --- CHANGELOG.md | 20 ++++++++++++++++++++ system/defines.php | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f449a7e83..0a30b4e3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,23 @@ +# v0.9.34 +## 08/04/2015 + +1. [](#new) + * Added new `cache_all` system setting + media `cache()` method + * Added base languages configuration + * Added property language to page to help plugins identify page language + * New `Utils::arrayFilterRecursive()` method +2. [](#improved) + * Improved Session handling to support site and admin independently + * Allow Twig variables to be modified in other events + * Blueprint updates in preparation for Admin plugin + * Changed `Inflector` from static to object and added multi-language support + * Support for admin override of a page's blueprints +3. [](#bugfix) + * Removed unused `use` in `VideoMedium` that was causing error + * Array fix in `User.authorise()` method + * Fix for typo in `translations_fallback` + * Fixed moving page to the root + # v0.9.33 ## 07/21/2015 diff --git a/system/defines.php b/system/defines.php index 851848604..707e7498f 100644 --- a/system/defines.php +++ b/system/defines.php @@ -2,7 +2,7 @@ // Some standard defines define('GRAV', true); -define('GRAV_VERSION', '0.9.33'); +define('GRAV_VERSION', '0.9.34'); define('DS', '/'); // Directories and Paths