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/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/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 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 @@ class Assets { /** @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 a93eb63e5..0a6b174d7 100644 --- a/system/src/Grav/Common/Config/Config.php +++ b/system/src/Grav/Common/Config/Config.php @@ -166,13 +166,6 @@ class Config extends Data return; } - /** @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'); } 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 @@ class Grav extends Container 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..a1ab41906 100644 --- a/system/src/Grav/Common/Markdown/MarkdownGravLinkTrait.php +++ b/system/src/Grav/Common/Markdown/MarkdownGravLinkTrait.php @@ -22,7 +22,7 @@ trait MarkdownGravLinkTrait // 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'])) { @@ -113,7 +113,7 @@ trait MarkdownGravLinkTrait 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) { diff --git a/system/src/Grav/Common/Page/Media.php b/system/src/Grav/Common/Page/Media.php index 055552c12..ca175c7b4 100644 --- a/system/src/Grav/Common/Page/Media.php +++ b/system/src/Grav/Common/Page/Media.php @@ -57,7 +57,7 @@ class Media extends Getters } //set file size - $medium->set('size',$info->getSize()); + $medium->set('size', $info->getSize()); // Assign meta files to the medium. if ($meta) { @@ -84,7 +84,7 @@ class Media extends Getters $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; } @@ -129,6 +129,7 @@ class Media extends Getters */ public function all() { + ksort($this->instances, SORT_NATURAL | SORT_FLAG_CASE); return $this->instances; } @@ -139,6 +140,7 @@ class Media extends Getters */ public function images() { + ksort($this->images, SORT_NATURAL | SORT_FLAG_CASE); return $this->images; } @@ -149,6 +151,7 @@ class Media extends Getters */ public function videos() { + ksort($this->videos, SORT_NATURAL | SORT_FLAG_CASE); return $this->videos; } @@ -159,6 +162,7 @@ class Media extends Getters */ public function files() { + ksort($this->files, SORT_NATURAL | SORT_FLAG_CASE); return $this->files; } diff --git a/system/src/Grav/Common/Page/Medium.php b/system/src/Grav/Common/Page/Medium.php index f98c0d2c3..85082009f 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 @@ -71,10 +72,15 @@ class Medium extends Data { 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']); @@ -82,6 +88,8 @@ class Medium extends Data } else { $this->def('mime', 'application/octet-stream'); } + + } /** @@ -117,9 +125,10 @@ class Medium extends Data /** * Sets the quality of the image * @param Int $quality 0-100 quality - * @return Medium + * @return Medium */ - public function quality($quality) { + public function quality($quality) + { $this->quality = $quality; return $this; } @@ -131,9 +140,6 @@ class Medium extends Data */ 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 +148,7 @@ class Medium extends Data $output = $relPath . '/' . $this->get('filename'); } - return $config->get('system.base_url_relative') . '/'. $output; + return self::$grav['base_url'] . '/'. $output; } /** @@ -150,6 +156,7 @@ class Medium extends Data * * @param string $type * @param int $quality + * @return $this */ public function format($type = null, $quality = 80) { @@ -212,7 +219,7 @@ class Medium extends Data /** @var Config $config */ $config = self::$grav['config']; - $output = 'linkTarget . '"' . $this->linkAttributes. ' class="'. $class . '">' . $output . ''; $this->linkTarget = $this->linkAttributes = null; @@ -241,7 +248,7 @@ class Medium extends Data $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/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 @@ class Page /** @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 @@ class Page // 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 @@ class Page 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])); 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 @@ class Themes extends Iterator $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 @@ class Twig } $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 @@ class Twig '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/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 @@ class Uri $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; 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'