Skip to content

Commit

Permalink
Merge branch 'release/0.9.24'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Apr 15, 2015
2 parents 6692704 + 2a56f21 commit 6baf7e0
Show file tree
Hide file tree
Showing 11 changed files with 283 additions and 29 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.24
## 04/15/2015

1. [](#new)
* Added support for chunked downloads of Assets
* Added new `onBeforeDownload()` event
* Added new `download()` and `getMimeType()` methods to Utils class
* Added configuration option for supported page types
* Added assets and media timestamp options (off by default)
* Added page expires configuration option
2. [](#bugfix)
* Fixed issue with Nginx/Gzip and `ob_flush()` throwing error
* Fixed assets actions on 'direct media' URLs
* Fix for 'direct assets` with any parameters

# v0.9.23
## 04/09/2015

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"maximebf/debugbar": "dev-master",
"filp/whoops": "1.2.*@dev",
"monolog/monolog": "~1.0",
"gregwar/image": "~2.0",
"gregwar/image": "~2.0",
"ircmaxell/password-compat": "1.0.*",
"mrclay/minify": "dev-master",
"donatj/phpuseragentparser": "dev-master",
Expand Down
7 changes: 7 additions & 0 deletions system/config/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pages:
special_chars: # List of special characters to automatically convert to entities
'>': 'gt'
'<': 'lt'
types: 'txt|xml|html|json|rss|atom' # Pipe separated list of valid page types
expires: 604800 # Page expires time in seconds (default 7 days)

cache:
enabled: true # Set to true to enable caching
Expand All @@ -40,6 +42,7 @@ cache:
lifetime: 604800 # Lifetime of cached data in seconds (0 = infinite)
gzip: false # GZip compress the page output


twig:
cache: true # Set to true to enable twig caching
debug: false # Enable Twig debug
Expand All @@ -55,6 +58,7 @@ assets: # Configuration for Assets Manager (JS, C
css_rewrite: true # Rewrite any CSS relative URLs during pipelining
js_pipeline: false # The JS pipeline is the unification of multiple JS resources into one file
js_minify: true # Minify the JS during pipelining
enable_asset_timestamp: false # Enable asset timetsamps
collections:
jquery: system://assets/jquery/jquery-2.1.3.min.js

Expand All @@ -71,3 +75,6 @@ debugger:
images:
default_image_quality: 85 # Default image quality to use when resampling images (85%)
debug: false # Show an overlay over images indicating the pixel depth of the image when working with retina for example

media:
enable_media_timestamp: false # Enable media timetsamps
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.23');
define('GRAV_VERSION', '0.9.24');
define('DS', '/');

// Directories and Paths
Expand Down
16 changes: 11 additions & 5 deletions system/src/Grav/Common/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Assets
// Some configuration variables
protected $config;
protected $base_url;
protected $timestamp = '';

// Default values for pipeline settings
protected $css_minify = true;
Expand All @@ -82,7 +83,6 @@ class Assets
protected $css_no_pipeline = array();
protected $js_no_pipeline = array();


public function __construct(array $options = array())
{
// Forward config options
Expand Down Expand Up @@ -154,6 +154,12 @@ public function config(array $config)
}
}

// Set timestamp
if (isset($config['enable_asset_timestamp']) && $config['enable_asset_timestamp'] === true) {
$this->timestamp = '?' . self::getGrav()['cache']->getKey();
}


return $this;
}

Expand Down Expand Up @@ -422,11 +428,11 @@ public function css($attributes = [])
$output .= '<link href="' . $this->pipeline(CSS_ASSET) . '"' . $attributes . ' />' . "\n";

foreach ($this->css_no_pipeline as $file) {
$output .= '<link href="' . $file['asset'] . '"' . $attributes . ' />' . "\n";
$output .= '<link href="' . $file['asset'] . $this->timestamp . '"' . $attributes . ' />' . "\n";
}
} else {
foreach ($this->css as $file) {
$output .= '<link href="' . $file['asset'] . '"' . $attributes . ' />' . "\n";
$output .= '<link href="' . $file['asset'] . $this->timestamp . '"' . $attributes . ' />' . "\n";
}
}

Expand Down Expand Up @@ -480,11 +486,11 @@ public function js($attributes = [])
if ($this->js_pipeline) {
$output .= '<script src="' . $this->pipeline(JS_ASSET) . '"' . $attributes . ' ></script>' . "\n";
foreach ($this->js_no_pipeline as $file) {
$output .= '<script src="' . $file['asset'] . '"' . $attributes . ' ' . $file['loading']. '></script>' . "\n";
$output .= '<script src="' . $file['asset'] . $this->timestamp . '"' . $attributes . ' ' . $file['loading']. '></script>' . "\n";
}
} else {
foreach ($this->js as $file) {
$output .= '<script src="' . $file['asset'] . '"' . $attributes . ' ' . $file['loading'].'></script>' . "\n";
$output .= '<script src="' . $file['asset'] . $this->timestamp . '"' . $attributes . ' ' . $file['loading'].'></script>' . "\n";
}
}

Expand Down
34 changes: 19 additions & 15 deletions system/src/Grav/Common/Grav.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Grav\Common;

use Grav\Common\Filesystem\Folder;
use Grav\Common\Page\Medium\ImageMedium;
use Grav\Common\Page\Pages;
use Grav\Common\Service\ConfigServiceProvider;
use Grav\Common\Service\ErrorServiceProvider;
Expand All @@ -10,7 +11,6 @@
use RocketTheme\Toolbox\DI\Container;
use RocketTheme\Toolbox\Event\Event;
use RocketTheme\Toolbox\Event\EventDispatcher;
use Grav\Common\Page\Medium\Medium;

/**
* Grav
Expand Down Expand Up @@ -99,32 +99,34 @@ protected static function load(array $values)
/** @var Pages $pages */
$pages = $c['pages'];

// If base URI is set, we want to remove it from the URL.
$path = '/' . ltrim(Folder::getRelativePath($c['uri']->route(), $pages->base()), '/');
/** @var Uri $uri */
$uri = $c['uri'];

$path = $uri->path();

$page = $pages->dispatch($path);

if (!$page || !$page->routable()) {

// special case where a media file is requested
$path_parts = pathinfo($path);

$page = $c['pages']->dispatch($path_parts['dirname'], true);
if ($page) {
$media = $page->media()->all();
$media_file = urldecode($path_parts['basename']);

$parsed_url = parse_url(urldecode($uri->basename()));

$media_file = $parsed_url['path'];

// if this is a media object, try actions first
if (isset($media[$media_file])) {
$medium = $media[$media_file];

// loop through actions for the image and call them
foreach ($c['uri']->query(null, true) as $action => $params) {
if (in_array($action, Medium::$valid_actions)) {
foreach ($uri->query(null, true) as $action => $params) {
if (in_array($action, ImageMedium::$magic_actions)) {
call_user_func_array(array(&$medium, $action), explode(',', $params));
}
}
header('Content-type: '. $medium->get('mime'));
echo file_get_contents($medium->path());
die;
Utils::download($medium->path(), false);
} else {
Utils::download($page->path() . DIRECTORY_SEPARATOR . $uri->basename(), true);
}
}

Expand Down Expand Up @@ -296,6 +298,8 @@ public function header()
$extension = $this['uri']->extension();
header('Content-type: ' . $this->mime($extension));

header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + $this['config']->get('system.pages.expires')));

// Set debugger data in headers
if (!($extension === null || $extension == 'html')) {
$this['debugger']->enabled(false);
Expand Down Expand Up @@ -345,7 +349,7 @@ public function shutdown()
header("Connection: close\r\n");

ob_end_flush(); // regular buffer
ob_flush();
@ob_flush();
flush();

if (function_exists('fastcgi_finish_request')) {
Expand Down
6 changes: 3 additions & 3 deletions system/src/Grav/Common/Page/Medium/ImageMedium.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ImageMedium extends Medium
public static $magic_actions = [
'resize', 'forceResize', 'cropResize', 'crop', 'zoomCrop',
'negate', 'brightness', 'contrast', 'grayscale', 'emboss',
'smooth', 'sharp', 'edge', 'colorize', 'sepia'
'smooth', 'sharp', 'edge', 'colorize', 'sepia', 'enableProgressive'
];

/**
Expand Down Expand Up @@ -127,7 +127,7 @@ public function url($reset = true)
$this->reset();
}

return self::$grav['base_url'] . $output . $this->urlHash();
return self::$grav['base_url'] . $output . $this->querystring() . $this->urlHash();
}


Expand Down Expand Up @@ -299,7 +299,7 @@ public function __call($method, $args)
}

if (!in_array($method, self::$magic_actions)) {
return $this;
return parent::__call($method, $args);
}

// Always initialize image.
Expand Down
43 changes: 42 additions & 1 deletion system/src/Grav/Common/Page/Medium/Medium.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public function __construct($items = [], Blueprint $blueprint = null)
{
parent::__construct($items, $blueprint);

if (self::getGrav()['config']->get('media.enable_media_timestamp', true)) {
$this->querystring('&' . self::getGrav()['cache']->getKey());
}

$this->def('mime', 'application/octet-stream');
$this->reset();
}
Expand Down Expand Up @@ -129,7 +133,33 @@ public function url($reset = true)
$this->reset();
}

return self::$grav['base_url'] . $output . $this->urlHash();
return self::$grav['base_url'] . $output . $this->querystring() . $this->urlHash();
}

/**
* Get/set querystring for the file's url
*
* @param string $hash
* @param boolean $withHash
* @return string
*/
public function querystring($querystring = null, $withQuestionmark = true)
{
if ($querystring) {
$this->set('querystring', ltrim($querystring, '?&'));

foreach ($this->alternatives as $alt) {
$alt->querystring($querystring, $withQuestionmark);
}
}

$querystring = $this->get('querystring', '');

if ($withQuestionmark && !empty($querystring)) {
return '?' . $querystring;
} else {
return $querystring;
}
}

/**
Expand Down Expand Up @@ -337,6 +367,17 @@ public function lightbox($width = null, $height = null, $reset = true)
*/
public function __call($method, $args)
{
$qs = $method;
if (count($args) > 1 || (count($args) == 1 && !empty($args[0]))) {
$qs .= '=' . implode(',', array_map(function ($a) { return urlencode($a); }, $args));
}

if (!empty($qs)) {
$this->querystring($this->querystring(null, false) . '&' . $qs);
}

self::$grav['debugger']->addMessage($this->querystring());

return $this;
}

Expand Down
3 changes: 1 addition & 2 deletions system/src/Grav/Common/Page/Medium/MediumFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ public static function scaledFromMedium($medium, $from, $to)
$debug = $medium->get('debug');
$medium->set('debug', false);

$file = $medium->resize($width, $height)->setPrettyName($basename)->url();
$file = preg_replace('|'. preg_quote(self::getGrav()['base_url_relative']) .'$|', '', GRAV_ROOT) . $file;
$file = $medium->resize($width, $height)->path();

$medium->set('debug', $debug);

Expand Down
19 changes: 18 additions & 1 deletion system/src/Grav/Common/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Uri
{
public $url;

protected $basename;
protected $base;
protected $root;
protected $bits;
Expand Down Expand Up @@ -64,6 +65,7 @@ public function __construct()
$this->base = $base;
$this->root = $base . $root_path;
$this->url = $base . $uri;

}

/**
Expand All @@ -84,7 +86,11 @@ public function init()

// remove the extension if there is one set
$parts = pathinfo($uri);
if (preg_match("/\.(txt|xml|html|json|rss|atom)$/", $parts['basename'])) {

// set the original basename
$this->basename = $parts['basename'];

if (preg_match("/\.(".$config->get('system.pages.types').")$/", $parts['basename'])) {
$uri = rtrim($parts['dirname'], '/').'/'.$parts['filename'];
$this->extension = $parts['extension'];
}
Expand Down Expand Up @@ -282,6 +288,17 @@ public function environment()
return $this->host();
}


/**
* Return the basename of the URI
*
* @return String The basename of the URI
*/
public function basename()
{
return $this->basename;
}

/**
* Return the base of the URI
*
Expand Down
Loading

0 comments on commit 6baf7e0

Please sign in to comment.