diff --git a/CHANGELOG.md b/CHANGELOG.md index 65b15ca7b..c8660a036 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,19 @@ +# v0.9.8 beta +## 12/01/2014 + +1. [](#new) + * Added configuration option to set default lifetime on cache saves + * Added ability to set HTTP status code from page header + * Implemented simple wild-card custom routing +2. [](#improved) + * Fixed elusive double load to fully cache issue (hopefully!) + * Ensure Twig tags are treated as block items in markdown + * Removed some older deprecated methods + * Ensure onPageContentProcessed() event only fires when not cached + * More PSR code fixes +3. [](#bugfix) + * Fix issue with miscalculation of blog separator location `===` + # v0.9.7 beta ## 11/24/2014 diff --git a/system/config/system.yaml b/system/config/system.yaml index 88b979199..bce4b5375 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -27,6 +27,7 @@ cache: method: file # Method to check for updates in pages: file|folder|none driver: auto # One of: auto|file|apc|xcache|memcache|wincache prefix: 'g' # Cache prefix string (prevents cache conflicts) + lifetime: 0 # Lifetime of cached data in seconds (0 = infinite) twig: cache: true # Set to true to enable twig caching diff --git a/system/defines.php b/system/defines.php index 7760c1362..cd474173e 100644 --- a/system/defines.php +++ b/system/defines.php @@ -2,7 +2,7 @@ // Some standard defines define('GRAV', true); -define('GRAV_VERSION', '0.9.7'); +define('GRAV_VERSION', '0.9.8'); define('DS', '/'); // Directories and Paths diff --git a/system/src/Grav/Common/Cache.php b/system/src/Grav/Common/Cache.php index aa6fe940b..50d748b7e 100644 --- a/system/src/Grav/Common/Cache.php +++ b/system/src/Grav/Common/Cache.php @@ -73,7 +73,7 @@ class Cache extends Getters $this->driver = $this->getCacheDriver(); // Set the cache namespace to our unique key - $this->driver->setNamespace($this->key); + // $this->driver->setNamespace($this->key); } /** @@ -154,6 +154,10 @@ class Cache extends Getters public function save($id, $data, $lifetime = null) { if ($this->enabled) { + + if ($lifetime == null) { + $lifetime = $this->config->get('system.cache.lifetime') ?: null; + } $this->driver->save($id, $data, $lifetime); } } diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index b052ff3a7..5f731d742 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -282,6 +282,11 @@ class Grav extends Container $this['debugger']->enabled(false); // $this['debugger']->sendDataInHeaders(); } + + // Set HTTP response code + if (isset($this['page']->header()->http_response_code)) { + http_response_code($this['page']->header()->http_response_code); + } } /** diff --git a/system/src/Grav/Common/Markdown/Markdown.php b/system/src/Grav/Common/Markdown/Markdown.php index f90cd0694..31b8bd815 100644 --- a/system/src/Grav/Common/Markdown/Markdown.php +++ b/system/src/Grav/Common/Markdown/Markdown.php @@ -5,9 +5,10 @@ class Markdown extends \Parsedown { use MarkdownGravLinkTrait; - function __construct($page) + public function __construct($page) { $this->page = $page; + $this->BlockTypes['{'] [] = "TwigTag"; } } diff --git a/system/src/Grav/Common/Markdown/MarkdownExtra.php b/system/src/Grav/Common/Markdown/MarkdownExtra.php index b85516f5a..5bdef3b94 100644 --- a/system/src/Grav/Common/Markdown/MarkdownExtra.php +++ b/system/src/Grav/Common/Markdown/MarkdownExtra.php @@ -5,9 +5,10 @@ class MarkdownExtra extends \ParsedownExtra { use MarkdownGravLinkTrait; - function __construct($page) + public function __construct($page) { parent::__construct(); $this->page = $page; + $this->BlockTypes['{'] [] = "TwigTag"; } } diff --git a/system/src/Grav/Common/Markdown/MarkdownGravLinkTrait.php b/system/src/Grav/Common/Markdown/MarkdownGravLinkTrait.php index 80e051a36..2a2d14a36 100644 --- a/system/src/Grav/Common/Markdown/MarkdownGravLinkTrait.php +++ b/system/src/Grav/Common/Markdown/MarkdownGravLinkTrait.php @@ -14,6 +14,19 @@ trait MarkdownGravLinkTrait { use GravTrait; + /** + * Ensure Twig tags are treated as block level items with no
tags + */ + protected function identifyTwigTag($Line) + { + if (preg_match('/[{%|{{|{#].*[#}|}}|%}]/', $Line['body'], $matches)) { + $Block = array( + 'element' => $Line['body'], + ); + return $Block; + } + } + protected function identifyLink($Excerpt) { /** @var Config $config */ diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 53ca9143a..ffa64c619 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -58,6 +58,7 @@ class Page protected $routable; protected $modified; protected $id; + protected $items; protected $header; protected $frontmatter; protected $content; @@ -128,7 +129,8 @@ class Page * @param string $var Raw content string * @return Object Raw content string */ - public function raw($var = null) { + public function raw($var = null) + { $file = $this->file(); if ($var) { @@ -146,7 +148,8 @@ class Page return $file ? $file->raw() : ''; } - public function frontmatter($var = null) { + public function frontmatter($var = null) + { if ($var) { $this->frontmatter = (string) $var; @@ -244,7 +247,6 @@ class Page $this->process[$process] = $status; } } - } return $this->header; @@ -258,7 +260,6 @@ class Page */ public function summary($size = null) { - $content = $this->content(); // Return calculated summary based on summary divider's position @@ -346,6 +347,8 @@ class Page // Cache the whole page, including processed content if ($update_cache) { + // Process any post-processing but pre-caching functionality + self::$grav->fireEvent('onPageContentProcessed', new Event(['page' => $this])); $cache->save($cache_id, $this->content); } @@ -356,9 +359,6 @@ class Page $this->content = str_replace(''.SUMMARY_DELIMITER.'
', '', $this->content); } - // Process any post-processing but pre-caching functionality - self::$grav->fireEvent('onPageContentProcessed', new Event(['page' => $this])); - } return $this->content; @@ -647,7 +647,7 @@ class Page * * @return string */ - public function child_type() + public function childType() { return isset($this->header->child_type) ? (string) $this->header->child_type : 'default'; } @@ -786,7 +786,7 @@ class Page } // Build an array of meta objects.. - foreach((array)$page_header->metadata as $key => $value) { + foreach ((array)$page_header->metadata as $key => $value) { // If this is a property type metadata: "og", "twitter", "facebook" etc if (is_array($value)) { @@ -1179,73 +1179,6 @@ class Page return $children; } - /** - * @throws \Exception - * @deprecated - */ - public function count() - { - throw new \Exception('Use $page->children()->count() instead.'); - } - - /** - * @param $key - * @throws \Exception - * @deprecated - */ - public function __get($key) - { - throw new \Exception('Use $page->children()->__get() instead.'); - } - - /** - * @param $key - * @param $value - * @throws \Exception - * @deprecated - */ - public function __set($key, $value) - { - throw new \Exception('Use $page->children()->__set() instead.'); - } - - /** - * @throws \Exception - * @deprecated - */ - public function current() - { - throw new \Exception('Use $page->children()->current() instead.'); - } - - /** - * @throws \Exception - * @deprecated - */ - public function next() - { - throw new \Exception('Use $page->children()->next() instead.'); - } - - /** - * @throws \Exception - * @deprecated - */ - public function prev() - { - throw new \Exception('Use $page->children()->prev() instead.'); - } - - /** - * @param string $key - * @throws \Exception - * @deprecated - */ - public function nth($key) - { - throw new \Exception('Use $page->children()->nth($position) instead.'); - } - /** * Check to see if this item is the first in an array of sub-pages. * diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 9b58304e6..53abfa6fc 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -236,14 +236,27 @@ class Pages // Fetch page if there's a defined route to it. $page = isset($this->routes[$url]) ? $this->get($this->routes[$url]) : null; - // If the page cannot be reached, look into site wide routes. + // If the page cannot be reached, look into site wide routes + wildcards if (!$all && (!$page || !$page->routable())) { /** @var Config $config */ $config = $this->grav['config']; + // See if route matches one in the site configuration $route = $config->get("site.routes.{$url}"); if ($route) { $page = $this->dispatch($route, $all); + } else { + // Try looking for wildcards + foreach ($config->get("site.routes") as $alias => $route) { + $match = rtrim($alias, '*'); + if (strpos($alias, '*') !== false && strpos($url, $match) !== false) { + $wildcard_url = str_replace('*', str_replace($match, '', $url), $route); + $page = isset($this->routes[$wildcard_url]) ? $this->get($this->routes[$wildcard_url]) : null; + if ($page) { + return $page; + } + } + } } } diff --git a/system/src/Grav/Common/Plugin.php b/system/src/Grav/Common/Plugin.php index e7b6bc481..6cc46f1a2 100644 --- a/system/src/Grav/Common/Plugin.php +++ b/system/src/Grav/Common/Plugin.php @@ -30,7 +30,8 @@ class Plugin implements EventSubscriberInterface * * @return array */ - public static function getSubscribedEvents() { + public static function getSubscribedEvents() + { $methods = get_class_methods(get_called_class()); $list = array(); diff --git a/system/src/Grav/Common/Plugins.php b/system/src/Grav/Common/Plugins.php index d7a8f6ff5..76164b949 100644 --- a/system/src/Grav/Common/Plugins.php +++ b/system/src/Grav/Common/Plugins.php @@ -19,7 +19,8 @@ class Plugins extends Iterator { protected $grav; - public function __construct(Grav $grav) { + public function __construct(Grav $grav) + { $this->grav = $grav; } @@ -78,7 +79,7 @@ class Plugins extends Iterator * * @return array */ - static public function all() + public static function all() { $list = array(); $iterator = new \DirectoryIterator('plugins://'); @@ -98,7 +99,7 @@ class Plugins extends Iterator return $list; } - static public function get($name) + public static function get($name) { $blueprints = new Blueprints("plugins://{$name}"); $blueprint = $blueprints->get('blueprints'); @@ -117,4 +118,5 @@ class Plugins extends Iterator return $obj; } + } diff --git a/system/src/Grav/Common/TwigExtension.php b/system/src/Grav/Common/TwigExtension.php index 7cc669152..35e627024 100644 --- a/system/src/Grav/Common/TwigExtension.php +++ b/system/src/Grav/Common/TwigExtension.php @@ -222,13 +222,11 @@ class TwigExtension extends \Twig_Extension */ public function urlFunc($input, $domain = false) { - $grav = Grav::instance(); - /** @var UniformResourceLocator $locator */ - $locator = $grav['locator']; + $locator = $this->grav['locator']; /** @var Uri $uri */ - $uri = $grav['uri']; + $uri = $this->grav['uri']; return $uri->rootUrl($domain) .'/'. $locator->findResource($input, false); }