From 318319731dea58c80dc7e68396574241357ca18e Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 12 Nov 2014 19:19:33 -0700 Subject: [PATCH 01/12] Fix for infinite loop in content() --- system/src/Grav/Common/Page/Page.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 6a49b0a56..53ca9143a 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -315,12 +315,12 @@ public function content($var = null) /** @var Cache $cache */ $cache = self::$grav['cache']; $cache_id = md5('page'.$this->id()); - $content = $cache->fetch($cache_id); + $this->content = $cache->fetch($cache_id); $update_cache = false; - if ($content === false) { + if ($this->content === false) { // Process Markdown - $content = $this->processMarkdown(); + $this->content = $this->processMarkdown(); $update_cache = true; } @@ -332,7 +332,7 @@ public function content($var = null) // Do we want to cache markdown, but process twig in each page? if ($update_cache && $process_twig) { - $cache->save($cache_id, $content); + $cache->save($cache_id, $this->content); $update_cache = false; } @@ -340,24 +340,22 @@ public function content($var = null) if ($update_cache || $process_twig) { /** @var Twig $twig */ $twig = self::$grav['twig']; - $content = $twig->processPage($this, $content); + $this->content = $twig->processPage($this, $this->content); } } // Cache the whole page, including processed content if ($update_cache) { - $cache->save($cache_id, $content); + $cache->save($cache_id, $this->content); } // Handle summary divider - $divider_pos = strpos($content, '

'.SUMMARY_DELIMITER.'

'); + $divider_pos = strpos($this->content, '

'.SUMMARY_DELIMITER.'

'); if ($divider_pos !== false) { $this->summary_size = $divider_pos; - $content = str_replace('

'.SUMMARY_DELIMITER.'

', '', $content); + $this->content = str_replace('

'.SUMMARY_DELIMITER.'

', '', $this->content); } - $this->content = $content; - // Process any post-processing but pre-caching functionality self::$grav->fireEvent('onPageContentProcessed', new Event(['page' => $this])); From 91f43c16131315f4a8ccb7905341eff7e78e3cb0 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 13 Nov 2014 21:08:10 +0200 Subject: [PATCH 02/12] Do not save environmental variables system.base_url_absolute & system.base_url_relative --- system/src/Grav/Common/Config/Config.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/src/Grav/Common/Config/Config.php b/system/src/Grav/Common/Config/Config.php index a93eb63e5..33c26a21c 100644 --- a/system/src/Grav/Common/Config/Config.php +++ b/system/src/Grav/Common/Config/Config.php @@ -166,15 +166,15 @@ public function init() return; } + $this->loadCompiledBlueprints($this->blueprintLookup, $this->pluginLookup, 'master'); + $this->loadCompiledConfig($this->configLookup, $this->pluginLookup, 'master'); + /** @var Uri $uri */ $uri = $this->grav['uri']; // If not set, add manually current base url. $this->def('system.base_url_absolute', $uri->rootUrl(true)); $this->def('system.base_url_relative', $uri->rootUrl(false)); - - $this->loadCompiledBlueprints($this->blueprintLookup, $this->pluginLookup, 'master'); - $this->loadCompiledConfig($this->configLookup, $this->pluginLookup, 'master'); } public function checksum() From dc28ba5d1a253e4b09713371d5f6afc16dd8117b Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 13 Nov 2014 21:16:44 +0200 Subject: [PATCH 03/12] Fix cached configuration (part 2) --- system/src/Grav/Common/Config/Config.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/system/src/Grav/Common/Config/Config.php b/system/src/Grav/Common/Config/Config.php index 33c26a21c..7ae82f998 100644 --- a/system/src/Grav/Common/Config/Config.php +++ b/system/src/Grav/Common/Config/Config.php @@ -163,18 +163,15 @@ public function init() $this->messages[] = 'Configuration checksum mismatch, reloading configuration..'; } else { $this->messages[] = 'Configuration checksum matches, using cached version.'; + $this->defineUrl(); + return; } $this->loadCompiledBlueprints($this->blueprintLookup, $this->pluginLookup, 'master'); $this->loadCompiledConfig($this->configLookup, $this->pluginLookup, 'master'); - /** @var Uri $uri */ - $uri = $this->grav['uri']; - - // If not set, add manually current base url. - $this->def('system.base_url_absolute', $uri->rootUrl(true)); - $this->def('system.base_url_relative', $uri->rootUrl(false)); + $this->defineUrl(); } public function checksum() @@ -209,6 +206,16 @@ public function checksum() return md5(json_encode([$cc, $cb])); } + protected function defineUrl() + { + /** @var Uri $uri */ + $uri = $this->grav['uri']; + + // If not set, add manually current base url. + $this->def('system.base_url_absolute', $uri->rootUrl(true)); + $this->def('system.base_url_relative', $uri->rootUrl(false)); + } + protected function autoDetectEnvironmentConfig($items) { $environment = $this->environment; From edb102b1ddcdb0c64a3cf1f8a379b1183a96def3 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 13 Nov 2014 21:49:46 -0700 Subject: [PATCH 04/12] fixed hostname for config overrides --- system/src/Grav/Common/Uri.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 4dbdb14d0..5658d335c 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -55,10 +55,10 @@ public function __construct() $address = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '::1'; // check for localhost variations - if ($address == '::1' || $address == '127.0.0.1') { + if ($name == 'localhost' || $address == '::1' || $address == '127.0.0.1') { $this->host = 'localhost'; } else { - $this->host = gethostname(); + $this->host = $name; } $this->base = $base; From 376c436318a3292f9ddc8bee48f918cfdf877694 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Fri, 14 Nov 2014 20:31:46 +0200 Subject: [PATCH 05/12] Move base_url variables from configuration into grav container --- system/config/system.yaml | 2 ++ system/src/Grav/Common/Assets.php | 5 ++--- system/src/Grav/Common/Config/Config.php | 14 -------------- system/src/Grav/Common/Grav.php | 10 ++++++++++ .../Grav/Common/Markdown/MarkdownGravLinkTrait.php | 2 +- system/src/Grav/Common/Page/Medium.php | 11 ++++------- system/src/Grav/Common/Themes.php | 2 +- system/src/Grav/Common/Twig.php | 10 ++++------ user/config/system.yaml | 2 ++ 9 files changed, 26 insertions(+), 32 deletions(-) diff --git a/system/config/system.yaml b/system/config/system.yaml index f1bae7697..7cdc6703b 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -1,3 +1,5 @@ +absolute_urls: false # Whether to use absolute URLs. + home: alias: '/home' # Default path for home, ie / diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index 4f332ab36..b23f1465e 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -97,9 +97,8 @@ public function init() { /** @var Config $config */ $config = self::$grav['config']; - $base_url = trim($config->get('system.base_url_relative')); - $theme = trim($config->get('system.pages.theme')); - $asset_config = (array)$config->get('system.assets'); + $base_url = self::$grav['base_url']; + $asset_config = (array) $config->get('system.assets'); $this->config($asset_config); $this->base_url = $base_url . '/'; diff --git a/system/src/Grav/Common/Config/Config.php b/system/src/Grav/Common/Config/Config.php index 7ae82f998..0a6b174d7 100644 --- a/system/src/Grav/Common/Config/Config.php +++ b/system/src/Grav/Common/Config/Config.php @@ -163,15 +163,11 @@ public function init() $this->messages[] = 'Configuration checksum mismatch, reloading configuration..'; } else { $this->messages[] = 'Configuration checksum matches, using cached version.'; - $this->defineUrl(); - return; } $this->loadCompiledBlueprints($this->blueprintLookup, $this->pluginLookup, 'master'); $this->loadCompiledConfig($this->configLookup, $this->pluginLookup, 'master'); - - $this->defineUrl(); } public function checksum() @@ -206,16 +202,6 @@ public function checksum() return md5(json_encode([$cc, $cb])); } - protected function defineUrl() - { - /** @var Uri $uri */ - $uri = $this->grav['uri']; - - // If not set, add manually current base url. - $this->def('system.base_url_absolute', $uri->rootUrl(true)); - $this->def('system.base_url_relative', $uri->rootUrl(false)); - } - protected function autoDetectEnvironmentConfig($items) { $environment = $this->environment; diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 8ed8c499d..ad02ad8dd 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -142,6 +142,16 @@ protected static function load(array $values) return new Browser(); }; + $container['base_url_absolute'] = function ($c) { + return $c['config']->get('system.base_url_absolute') ?: $c['uri']->rootUrl(true); + }; + $container['base_url_relative'] = function ($c) { + return $c['config']->get('system.base_url_relative') ?: $c['uri']->rootUrl(false); + }; + $container['base_url'] = function ($c) { + return $c['config']->get('system.absolute_urls') ? $c['base_url_absolute'] : $c['base_url_relative']; + }; + $container->register(new StreamsServiceProvider); $container->register(new ConfigServiceProvider); diff --git a/system/src/Grav/Common/Markdown/MarkdownGravLinkTrait.php b/system/src/Grav/Common/Markdown/MarkdownGravLinkTrait.php index 1357c686b..1f5b67031 100644 --- a/system/src/Grav/Common/Markdown/MarkdownGravLinkTrait.php +++ b/system/src/Grav/Common/Markdown/MarkdownGravLinkTrait.php @@ -22,7 +22,7 @@ protected function identifyLink($Excerpt) // Run the parent method to get the actual results $Excerpt = parent::identifyLink($Excerpt); $actions = array(); - $this->base_url = trim($config->get('system.base_url_relative')); + $this->base_url = self::$grav['base_url']; // if this is a link if (isset($Excerpt['element']['attributes']['href'])) { diff --git a/system/src/Grav/Common/Page/Medium.php b/system/src/Grav/Common/Page/Medium.php index f98c0d2c3..e12bc9ed7 100644 --- a/system/src/Grav/Common/Page/Medium.php +++ b/system/src/Grav/Common/Page/Medium.php @@ -117,7 +117,7 @@ public function path() /** * Sets the quality of the image * @param Int $quality 0-100 quality - * @return Medium + * @return Medium */ public function quality($quality) { $this->quality = $quality; @@ -131,9 +131,6 @@ public function quality($quality) { */ public function url() { - /** @var Config $config */ - $config = self::$grav['config']; - if ($this->image) { $output = $this->image->cacheFile($this->type, $this->quality); $this->reset(); @@ -142,7 +139,7 @@ public function url() $output = $relPath . '/' . $this->get('filename'); } - return $config->get('system.base_url_relative') . '/'. $output; + return self::$grav['base_url'] . '/'. $output; } /** @@ -212,7 +209,7 @@ public function html($title = null, $class = null, $type = null, $quality = 80) /** @var Config $config */ $config = self::$grav['config']; - $output = 'linkTarget . '"' . $this->linkAttributes. ' class="'. $class . '">' . $output . ''; $this->linkTarget = $this->linkAttributes = null; @@ -241,7 +238,7 @@ public function lightboxRaw($width = null, $height = null) $config = self::$grav['config']; $url = $this->url(); $this->link($width, $height); - $lightbox_url = $config->get('system.base_url_relative') . '/'. $this->linkTarget; + $lightbox_url = self::$grav['base_url'] . '/'. $this->linkTarget; return array('a_url' => $lightbox_url, 'a_rel' => 'lightbox', 'img_url' => $url); } diff --git a/system/src/Grav/Common/Themes.php b/system/src/Grav/Common/Themes.php index f5648391c..e7620cede 100644 --- a/system/src/Grav/Common/Themes.php +++ b/system/src/Grav/Common/Themes.php @@ -97,7 +97,7 @@ public function get($name) $thumb = "themes://{$name}/thumbnail.jpg"; if (file_exists($thumb)) { - $blueprint->set('thumbnail', $this->config->get('system.base_url_relative') . "/user/themes/{$name}/thumbnail.jpg"); + $blueprint->set('thumbnail', $this->grav['base_url'] . "/user/themes/{$name}/thumbnail.jpg"); } // Load default configuration. diff --git a/system/src/Grav/Common/Twig.php b/system/src/Grav/Common/Twig.php index acdf04bd0..417576d31 100644 --- a/system/src/Grav/Common/Twig.php +++ b/system/src/Grav/Common/Twig.php @@ -102,13 +102,10 @@ public function init() } $this->twig->addExtension(new TwigExtension()); - $this->grav->fireEvent('onTwigExtensions'); - $baseUrlAbsolute = $config->get('system.base_url_absolute'); - $baseUrlRelative = $config->get('system.base_url_relative'); $theme = $config->get('system.pages.theme'); - $themeUrl = $baseUrlRelative .'/'. USER_PATH . basename(THEMES_DIR) .'/'. $theme; + $themeUrl = $this->grav['base_url'] .'/'. USER_PATH . basename(THEMES_DIR) .'/'. $theme; // Set some standard variables for twig $this->twig_vars = array( @@ -116,8 +113,9 @@ public function init() 'config' => $config, 'uri' => $this->grav['uri'], 'base_dir' => rtrim(ROOT_DIR, '/'), - 'base_url_absolute' => $baseUrlAbsolute, - 'base_url_relative' => $baseUrlRelative, + 'base_url' => $this->grav['base_url'], + 'base_url_absolute' => $this->grav['base_url_absolute'], + 'base_url_relative' => $this->grav['base_url_relative'], 'theme_dir' => $locator->findResource('theme://'), 'theme_url' => $themeUrl, 'site' => $config->get('site'), diff --git a/user/config/system.yaml b/user/config/system.yaml index bb63b403c..21dd89bf1 100644 --- a/user/config/system.yaml +++ b/user/config/system.yaml @@ -1,3 +1,5 @@ +absolute_urls: false + home: alias: '/home' From 19fc443518005e2f1ce3828a5ab4ce0ec7fbb1de Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 17 Nov 2014 11:14:05 -0700 Subject: [PATCH 06/12] Fix for relative URLs in markdown on installs with no base_url --- system/src/Grav/Common/Markdown/MarkdownGravLinkTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Markdown/MarkdownGravLinkTrait.php b/system/src/Grav/Common/Markdown/MarkdownGravLinkTrait.php index 1f5b67031..a1ab41906 100644 --- a/system/src/Grav/Common/Markdown/MarkdownGravLinkTrait.php +++ b/system/src/Grav/Common/Markdown/MarkdownGravLinkTrait.php @@ -113,7 +113,7 @@ protected function identifyLink($Excerpt) protected function convertUrl($markdown_url) { // if absolue and starts with a base_url move on - if ($this->base_url == '' || strpos($markdown_url, $this->base_url) === 0) { + if ($this->base_url != '' && strpos($markdown_url, $this->base_url) === 0) { $new_url = $markdown_url; // if its absolute with / } elseif (strpos($markdown_url, '/') === 0) { From 87d16e36cba8a91a3470198d3cad94ed0b4bec37 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 17 Nov 2014 13:53:08 -0700 Subject: [PATCH 07/12] Upped the default compression from 80 to 85 --- system/src/Grav/Common/Page/Medium.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Page/Medium.php b/system/src/Grav/Common/Page/Medium.php index e12bc9ed7..e4f78e634 100644 --- a/system/src/Grav/Common/Page/Medium.php +++ b/system/src/Grav/Common/Page/Medium.php @@ -48,9 +48,10 @@ class Medium extends Data protected $image; protected $type = 'guess'; - protected $quality = 80; + protected $quality = 85; - public static $valid_actions = ['resize', 'forceResize', 'cropResize', 'crop', 'cropZoom', 'negate', 'brightness', 'contrast', 'grayscale', 'emboss', 'smooth', 'sharp', 'edge', 'colorize', 'sepia' ]; + public static $valid_actions = ['resize', 'forceResize', 'cropResize', 'crop', 'cropZoom', + 'negate', 'brightness', 'contrast', 'grayscale', 'emboss', 'smooth', 'sharp', 'edge', 'colorize', 'sepia' ]; /** * @var array From 16ce10a5c7785dc33eef02e9d2b2cf4463f8046f Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 17 Nov 2014 13:53:51 -0700 Subject: [PATCH 08/12] PSR formatting fixes --- system/src/Grav/Common/Page/Media.php | 2 +- system/src/Grav/Common/Page/Medium.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Page/Media.php b/system/src/Grav/Common/Page/Media.php index 055552c12..ab119d797 100644 --- a/system/src/Grav/Common/Page/Media.php +++ b/system/src/Grav/Common/Page/Media.php @@ -57,7 +57,7 @@ public function __construct($path) } //set file size - $medium->set('size',$info->getSize()); + $medium->set('size', $info->getSize()); // Assign meta files to the medium. if ($meta) { diff --git a/system/src/Grav/Common/Page/Medium.php b/system/src/Grav/Common/Page/Medium.php index e4f78e634..5ae0dcc60 100644 --- a/system/src/Grav/Common/Page/Medium.php +++ b/system/src/Grav/Common/Page/Medium.php @@ -83,6 +83,8 @@ public function __construct($items = array(), Blueprint $blueprint = null) } else { $this->def('mime', 'application/octet-stream'); } + + } /** @@ -120,7 +122,8 @@ public function path() * @param Int $quality 0-100 quality * @return Medium */ - public function quality($quality) { + public function quality($quality) + { $this->quality = $quality; return $this; } @@ -148,6 +151,7 @@ public function url() * * @param string $type * @param int $quality + * @return $this */ public function format($type = null, $quality = 80) { From 088075888e50bbc5f825d03049f4ab90bc0acb62 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 17 Nov 2014 13:54:13 -0700 Subject: [PATCH 09/12] support uppercase image extensions --- system/src/Grav/Common/Page/Media.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Media.php b/system/src/Grav/Common/Page/Media.php index ab119d797..1f4039813 100644 --- a/system/src/Grav/Common/Page/Media.php +++ b/system/src/Grav/Common/Page/Media.php @@ -84,7 +84,7 @@ public function get($filename, $create = false) $config = self::$grav['config']; // Check if medium type has been configured. - $params = $config->get("media.{$ext}"); + $params = $config->get("media.".strtolower($ext)); if (!$params) { return null; } From a2aaa2ce79c1e60edae31364965827268d28b659 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 17 Nov 2014 13:54:35 -0700 Subject: [PATCH 10/12] force media array sorts to use natural sort ordering --- system/src/Grav/Common/Page/Media.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/system/src/Grav/Common/Page/Media.php b/system/src/Grav/Common/Page/Media.php index 1f4039813..ca175c7b4 100644 --- a/system/src/Grav/Common/Page/Media.php +++ b/system/src/Grav/Common/Page/Media.php @@ -129,6 +129,7 @@ public function get($filename, $create = false) */ public function all() { + ksort($this->instances, SORT_NATURAL | SORT_FLAG_CASE); return $this->instances; } @@ -139,6 +140,7 @@ public function all() */ public function images() { + ksort($this->images, SORT_NATURAL | SORT_FLAG_CASE); return $this->images; } @@ -149,6 +151,7 @@ public function images() */ public function videos() { + ksort($this->videos, SORT_NATURAL | SORT_FLAG_CASE); return $this->videos; } @@ -159,6 +162,7 @@ public function videos() */ public function files() { + ksort($this->files, SORT_NATURAL | SORT_FLAG_CASE); return $this->files; } From 6879a2d54c2fef786e419195afa99e1534a43ae8 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 17 Nov 2014 13:55:09 -0700 Subject: [PATCH 11/12] added filename/thumb/extension to medium properties --- system/src/Grav/Common/Page/Medium.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/system/src/Grav/Common/Page/Medium.php b/system/src/Grav/Common/Page/Medium.php index 5ae0dcc60..85082009f 100644 --- a/system/src/Grav/Common/Page/Medium.php +++ b/system/src/Grav/Common/Page/Medium.php @@ -72,10 +72,15 @@ public function __construct($items = array(), Blueprint $blueprint = null) { parent::__construct($items, $blueprint); + $file_path = $this->get('path') . '/' . $this->get('filename'); + $file_parts = pathinfo($file_path); + + $this->set('thumb', $file_path); + $this->set('extension', $file_parts['extension']); + $this->set('filename', $this->get('filename')); + if ($this->get('type') == 'image') { - $filePath = $this->get('path') . '/' . $this->get('filename'); - $image_info = getimagesize($filePath); - $this->set('thumb', $filePath); + $image_info = getimagesize($file_path); $this->def('width', $image_info[0]); $this->def('height', $image_info[1]); $this->def('mime', $image_info['mime']); From 2d3e452bafeda5052c373cbf8eb196e0206b7e47 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 17 Nov 2014 15:58:26 -0700 Subject: [PATCH 12/12] updated version and changelog --- CHANGELOG.md | 15 +++++++++++++++ system/defines.php | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d81ab63e..4e86e28b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ +# v0.9.6 beta +## 11/17/2014 + +1. [](#improved) + * Moved base_url variables into Grav container + * Forced media sorting to use natural sort order by default + * Various PSR code tidying + * Added filename, extension, thumb to all medium objects +2. [](#bugfix) + * Fix for infinite loop in page.content() + * Fix hostname for configuration overrides + * Fix for cached configuration + * Fix for relative URLs in markdown on installs with no base_url + * Fix for page media images with uppercase extension + # v0.9.5 beta ## 11/09/2014 diff --git a/system/defines.php b/system/defines.php index 8e7b035ef..38b114b95 100644 --- a/system/defines.php +++ b/system/defines.php @@ -2,7 +2,7 @@ // Some standard defines define('GRAV', true); -define('GRAV_VERSION', '0.9.5'); +define('GRAV_VERSION', '0.9.6'); define('DS', '/'); // Directories and Paths