Skip to content

Commit

Permalink
Merge branch 'release/0.9.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Nov 17, 2014
2 parents 4b46ea2 + 2d3e452 commit 36688c9
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 47 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 2 additions & 0 deletions system/config/system.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
absolute_urls: false # Whether to use absolute URLs.

home:
alias: '/home' # Default path for home, ie /

Expand Down
2 changes: 1 addition & 1 deletion system/defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions system/src/Grav/Common/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 . '/';
Expand Down
7 changes: 0 additions & 7 deletions system/src/Grav/Common/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,6 @@ public function init()
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');
}
Expand Down
10 changes: 10 additions & 0 deletions system/src/Grav/Common/Grav.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions system/src/Grav/Common/Markdown/MarkdownGravLinkTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions system/src/Grav/Common/Page/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -129,6 +129,7 @@ public function get($filename, $create = false)
*/
public function all()
{
ksort($this->instances, SORT_NATURAL | SORT_FLAG_CASE);
return $this->instances;
}

Expand All @@ -139,6 +140,7 @@ public function all()
*/
public function images()
{
ksort($this->images, SORT_NATURAL | SORT_FLAG_CASE);
return $this->images;
}

Expand All @@ -149,6 +151,7 @@ public function images()
*/
public function videos()
{
ksort($this->videos, SORT_NATURAL | SORT_FLAG_CASE);
return $this->videos;
}

Expand All @@ -159,6 +162,7 @@ public function videos()
*/
public function files()
{
ksort($this->files, SORT_NATURAL | SORT_FLAG_CASE);
return $this->files;
}

Expand Down
33 changes: 20 additions & 13 deletions system/src/Grav/Common/Page/Medium.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -71,17 +72,24 @@ 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']);
$this->reset();
} else {
$this->def('mime', 'application/octet-stream');
}


}

/**
Expand Down Expand Up @@ -117,9 +125,10 @@ public function path()
/**
* 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;
}
Expand All @@ -131,9 +140,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();
Expand All @@ -142,14 +148,15 @@ public function url()
$output = $relPath . '/' . $this->get('filename');
}

return $config->get('system.base_url_relative') . '/'. $output;
return self::$grav['base_url'] . '/'. $output;
}

/**
* Sets image output format.
*
* @param string $type
* @param int $quality
* @return $this
*/
public function format($type = null, $quality = 80)
{
Expand Down Expand Up @@ -212,7 +219,7 @@ public function html($title = null, $class = null, $type = null, $quality = 80)
/** @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;
Expand Down Expand Up @@ -241,7 +248,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);
}
Expand Down
18 changes: 8 additions & 10 deletions system/src/Grav/Common/Page/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -332,32 +332,30 @@ 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;
}

// Do we need to process twig this time?
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]));

Expand Down
2 changes: 1 addition & 1 deletion system/src/Grav/Common/Themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 4 additions & 6 deletions system/src/Grav/Common/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,20 @@ 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(
'grav' => $this->grav,
'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'),
Expand Down
4 changes: 2 additions & 2 deletions system/src/Grav/Common/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions user/config/system.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
absolute_urls: false

home:
alias: '/home'

Expand Down

0 comments on commit 36688c9

Please sign in to comment.