Skip to content

Commit

Permalink
Merge branch 'release/0.9.33'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Jul 21, 2015
2 parents 7029edf + 6d69f03 commit 6d5bb6f
Show file tree
Hide file tree
Showing 15 changed files with 260 additions and 45 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# v0.9.33
## 07/21/2015

1. [](#new)
* Added new `onImageMediumSaved()` event (useful for post-image processing)
* Added `Vary: Accept-Encoding` option
2. [](#improved)
* Multilang-safe delimeter position
* Refactored Twig classes and added optional umask setting
* Removed `pageinit()` timing
* `Page->routable()` now takes `published()` state into account
* Improved how page extension is set
* Support `Language->translate()` method taking string and array
3. [](#bugfix)
* Fixed `backup` command to include empty folders

# v0.9.32
## 07/14/2015

Expand Down
1 change: 1 addition & 0 deletions system/config/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pages:
expires: 604800 # Page expires time in seconds (604800 seconds = 7 days)
last_modified: false # Set the last modified date header based on file modifcation timestamp
etag: false # Set the etag header tag
vary_accept_encoding: false # Add `Vary: Accept-Encoding` header
redirect_default_route: false # Automatically redirect to a page's default route

cache:
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.32');
define('GRAV_VERSION', '0.9.33');
define('DS', '/');

// Directories and Paths
Expand Down
8 changes: 6 additions & 2 deletions system/src/Grav/Common/Backup/ZipBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class ZipBackup
];

protected static $ignoreFolders = [
'.git'
'.git',
'.idea'
];

public static function backup($destination = null, callable $messager = null)
Expand Down Expand Up @@ -97,7 +98,10 @@ private static function folderToZip($folder, \ZipArchive &$zipFile, $exclusiveLe
// Remove prefix from file path before add to zip.
$localPath = substr($filePath, $exclusiveLength);

if (in_array($f, static::$ignoreFolders) || in_array($localPath, static::$ignorePaths)) {
if (in_array($f, static::$ignoreFolders)) {
continue;
} elseif (in_array($localPath, static::$ignorePaths)) {
$zipFile->addEmptyDir($f);
continue;
}

Expand Down
21 changes: 17 additions & 4 deletions system/src/Grav/Common/Grav.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Grav\Common\Service\ErrorServiceProvider;
use Grav\Common\Service\LoggerServiceProvider;
use Grav\Common\Service\StreamsServiceProvider;
use Grav\Common\Twig\Twig;
use RocketTheme\Toolbox\DI\Container;
use RocketTheme\Toolbox\Event\Event;
use RocketTheme\Toolbox\Event\EventDispatcher;
Expand Down Expand Up @@ -219,10 +220,7 @@ public function process()
$this['pages']->init();
$this->fireEvent('onPagesInitialized');
$debugger->stopTimer('pages');

$debugger->startTimer('pageinit', 'Page Initialized');
$this->fireEvent('onPageInitialized');
$debugger->stopTimer('pageinit');

$debugger->addAssets();

Expand Down Expand Up @@ -350,6 +348,11 @@ public function header()
if (isset($this['page']->header()->http_response_code)) {
http_response_code($this['page']->header()->http_response_code);
}

// Vary: Accept-Encoding
if ($this['config']->get('system.pages.vary_accept_encoding', false)) {
header('Vary: Accept-Encoding');
}
}

/**
Expand Down Expand Up @@ -438,7 +441,17 @@ protected function fallbackUrl($page, $path)
}

// unsupported media type, try to download it...
$extension = $uri->extension() ?: isset($path_parts['extension']) ? $path_parts['extension'] : null;
$uri_extension = $uri->extension();
if ($uri_extension) {
$extension = $uri_extension;
} else {
if (isset($path_parts['extension'])) {
$extension = $path_parts['extension'];
} else {
$extension = null;
}
}

if ($extension) {
$download = true;
if (in_array(ltrim($extension, '.'), $this['config']->get('system.media.unsupported_inline_types'))) {
Expand Down
23 changes: 19 additions & 4 deletions system/src/Grav/Common/Language/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,21 @@ public function validate($lang)
/**
* Translate a key and possibly arguments into a string using current lang and fallbacks
*
* @param Array $args first argument is the lookup key value
* @param $args first argument is the lookup key value
* other arguments can be passed and replaced in the translation with sprintf syntax
* @param Array $languages
*
* @return string
*/
public function translate(Array $args, Array $languages = null)
public function translate($args, Array $languages = null)
{
$lookup = array_shift($args);
if (is_array($args)) {
$lookup = array_shift($args);
} else {
$lookup = $args;
$args = [];
}


if ($this->config->get('system.languages.translations', true)) {
if ($this->enabled() && $lookup) {
Expand Down Expand Up @@ -315,6 +321,15 @@ public function translate(Array $args, Array $languages = null)
return '<span class="untranslated">' . $lookup . '</span>';
}

/**
* Translate Array
*
* @param $key
* @param $index
* @param null $languages
*
* @return string
*/
public function translateArray($key, $index, $languages = null)
{
if ($this->config->get('system.languages.translations', true)) {
Expand Down Expand Up @@ -359,7 +374,7 @@ public function getTranslation($lang, $key)
return $translation;
}

function getBrowserLanguages($accept_langs = [])
public function getBrowserLanguages($accept_langs = [])
{
if (empty($this->http_accept_language)) {
if (empty($accept_langs) && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
Expand Down
83 changes: 83 additions & 0 deletions system/src/Grav/Common/Page/Medium/ImageFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
namespace Grav\Common\Page\Medium;

use Grav\Common\GravTrait;
use RocketTheme\Toolbox\Event\Event;

class ImageFile extends \Gregwar\Image\Image
{
use GravTrait;

/**
* This is the same as the Gregwar Image class except this one fires a Grav Event on creation of new cached file
*
* @param string $type the image type
* @param int $quality the quality (for JPEG)
* @param bool $actual
*
* @return mixed|string
*/
public function cacheFile($type = 'jpg', $quality = 80, $actual = false)
{
if ($type == 'guess') {
$type = $this->guessType();
}

if (!count($this->operations) && $type == $this->guessType() && !$this->forceCache) {
return $this->getFilename($this->getFilePath());
}

// Computes the hash
$this->hash = $this->getHash($type, $quality);

// Generates the cache file
$cacheFile = '';

if (!$this->prettyName || $this->prettyPrefix) {
$cacheFile .= $this->hash;
}

if ($this->prettyPrefix) {
$cacheFile .= '-';
}

if ($this->prettyName) {
$cacheFile .= $this->prettyName;
}

$cacheFile .= '.'.$type;

// If the files does not exists, save it
$image = $this;

// Target file should be younger than all the current image
// dependencies
$conditions = array(
'younger-than' => $this->getDependencies()
);

// The generating function
$generate = function ($target) use ($image, $type, $quality) {
$result = $image->save($target, $type, $quality);

if ($result != $target) {
throw new GenerationError($result);
}

self::getGrav()->fireEvent('onImageMediumSaved', new Event(['image' => $target]));
};

// Asking the cache for the cacheFile
try {
$file = $this->cache->getOrCreateFile($cacheFile, $conditions, $generate, $actual);
} catch (GenerationError $e) {
$file = $e->getNewFile();
}

if ($actual) {
return $file;
} else {
return $this->getFilename($file);
}
}
}
9 changes: 5 additions & 4 deletions system/src/Grav/Common/Page/Medium/ImageMedium.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
namespace Grav\Common\Page\Medium;

use Grav\Common\Data\Blueprint;
use Gregwar\Image\Image as ImageFile;

class ImageMedium extends Medium
{
Expand Down Expand Up @@ -364,6 +363,10 @@ protected function saveImage()
return parent::path(false);
}

if (isset($this->result)) {
return $this->result;
}

if ($this->get('debug') && !$this->debug_watermarked) {
$ratio = $this->get('ratio');
if (!$ratio) {
Expand All @@ -375,9 +378,7 @@ protected function saveImage()
$this->image->merge(ImageFile::open($overlay));
}

$result = $this->image->cacheFile($this->format, $this->quality);

return $result;
return $this->image->cacheFile($this->format, $this->quality);
}

/**
Expand Down
55 changes: 32 additions & 23 deletions system/src/Grav/Common/Page/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ public function __construct()
* Initializes the page instance variables based on a file
*
* @param \SplFileInfo $file The file information for the .md file that the page represents
* @return void
* @param string $extension
*/
public function init(\SplFileInfo $file)
public function init(\SplFileInfo $file, $extension = null)
{
$this->filePath($file->getPathName());
$this->modified($file->getMTime());
Expand All @@ -119,25 +119,14 @@ public function init(\SplFileInfo $file)
$this->url();
$this->visible();
$this->modularTwig($this->slug[0] == '_');
$this->setPublishState();
$this->published();

// Handle publishing dates if no explict published option set
if (self::getGrav()['config']->get('system.pages.publish_dates') && !isset($this->header->published)) {
// unpublish if required, if not clear cache right before page should be unpublished
if ($this->unpublishDate()) {
if ($this->unpublishDate() < time()) {
$this->published(false);
} else {
$this->published();
self::getGrav()['cache']->setLifeTime($this->unpublishDate());
}
}
// publish if required, if not clear cache right before page is published
if ($this->publishDate() != $this->modified() && $this->publishDate() > time()) {
$this->published(false);
self::getGrav()['cache']->setLifeTime($this->publishDate());
}
if (empty($extension)) {
$this->extension('.'.$file->getExtension());
} else {
$this->extension($extension);
}
$this->published();
}

/**
Expand Down Expand Up @@ -445,7 +434,7 @@ public function content($var = null)

// Handle summary divider
$delimiter = self::getGrav()['config']->get('site.summary.delimiter', '===');
$divider_pos = strpos($this->content, "<p>{$delimiter}</p>");
$divider_pos = mb_strpos($this->content, "<p>{$delimiter}</p>");
if ($divider_pos !== false) {
$this->summary_size = $divider_pos;
$this->content = str_replace("<p>{$delimiter}</p>", '', $this->content);
Expand Down Expand Up @@ -970,7 +959,8 @@ public function unpublishDate($var = null)

/**
* Gets and Sets whether or not this Page is routable, ie you can reach it
* via a URL
* via a URL.
* The page must be *routable* and *published*
*
* @param bool $var true if the page is routable
* @return bool true if the page is routable
Expand All @@ -980,7 +970,7 @@ public function routable($var = null)
if ($var !== null) {
$this->routable = (bool) $var;
}
return $this->routable;
return $this->routable && $this->published();
}

/**
Expand Down Expand Up @@ -1961,5 +1951,24 @@ protected function doRelocation($reorder)
$this->_original = null;
}


protected function setPublishState()
{
// Handle publishing dates if no explict published option set
if (self::getGrav()['config']->get('system.pages.publish_dates') && !isset($this->header->published)) {
// unpublish if required, if not clear cache right before page should be unpublished
if ($this->unpublishDate()) {
if ($this->unpublishDate() < time()) {
$this->published(false);
} else {
$this->published();
self::getGrav()['cache']->setLifeTime($this->unpublishDate());
}
}
// publish if required, if not clear cache right before page is published
if ($this->publishDate() != $this->modified() && $this->publishDate() > time()) {
$this->published(false);
self::getGrav()['cache']->setLifeTime($this->publishDate());
}
}
}
}
3 changes: 1 addition & 2 deletions system/src/Grav/Common/Page/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,7 @@ protected function recurse($directory, Page &$parent = null)

if ($parent && !empty($page_found)) {
$file = new \SplFileInfo($page_found);
$page->init($file);
$page->extension($page_extension);
$page->init($file, $page_extension);

$content_exists = true;

Expand Down
16 changes: 16 additions & 0 deletions system/src/Grav/Common/Twig/TraceableTwigEnvironment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
namespace Grav\Common\Twig;

use Grav\Common\GravTrait;

/**
* The Twig Environment class is a wrapper that handles configurable permissions
* for the Twig cache files
*
* @author RocketTheme
* @license MIT
*/
class TraceableTwigEnvironment extends \DebugBar\Bridge\Twig\TraceableTwigEnvironment
{
use WriteCacheFileTrait;
}
Loading

0 comments on commit 6d5bb6f

Please sign in to comment.