Merge branch 'release/0.9.6'

This commit is contained in:
Andy Miller
2014-11-17 15:58:40 -07:00
14 changed files with 75 additions and 47 deletions

View File

@@ -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

View File

@@ -1,3 +1,5 @@
absolute_urls: false # Whether to use absolute URLs.
home:
alias: '/home' # Default path for home, ie /

View File

@@ -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

View File

@@ -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 . '/';

View File

@@ -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');
}

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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;
}

View File

@@ -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 = '<a href="' . $config->get('system.base_url_relative') . '/'. $this->linkTarget
$output = '<a href="' . self::$grav['base_url'] . '/'. $this->linkTarget
. '"' . $this->linkAttributes. ' class="'. $class . '">' . $output . '</a>';
$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);
}

View File

@@ -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, '<p>'.SUMMARY_DELIMITER.'</p>');
$divider_pos = strpos($this->content, '<p>'.SUMMARY_DELIMITER.'</p>');
if ($divider_pos !== false) {
$this->summary_size = $divider_pos;
$content = str_replace('<p>'.SUMMARY_DELIMITER.'</p>', '', $content);
$this->content = str_replace('<p>'.SUMMARY_DELIMITER.'</p>', '', $this->content);
}
$this->content = $content;
// Process any post-processing but pre-caching functionality
self::$grav->fireEvent('onPageContentProcessed', new Event(['page' => $this]));

View File

@@ -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.

View File

@@ -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'),

View File

@@ -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;

View File

@@ -1,3 +1,5 @@
absolute_urls: false
home:
alias: '/home'