Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed May 18, 2017
2 parents 7543f3e + ffe286e commit f3cecd8
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 26 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# v1.3.0-rc.2
## 05/17/2017

1. [](#new)
* Added new `media` and `vardump` Twig functions
1. [](#improved)
* Put in various checks to ensure Exif is available before trying to use it
* Add timestamp to configuration settings [#1445](https://github.com/getgrav/grav/pull/1445)
1. [](#bugfix)
* Fix an issue saving YAML textarea fields in expert mode [#1480](https://github.com/getgrav/grav/pull/1480)
* Moved `onOutputRendered()` back into Grav core

# v1.3.0-rc.1
## 15/16/2017
## 05/16/2017

1. [](#new)
* Added support for a single array field in the forms
Expand Down
2 changes: 1 addition & 1 deletion system/defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// Some standard defines
define('GRAV', true);
define('GRAV_VERSION', '1.3.0-rc.1');
define('GRAV_VERSION', '1.3.0-rc.2');
define('GRAV_TESTING', true);
define('DS', '/');

Expand Down
19 changes: 18 additions & 1 deletion system/src/Grav/Common/Config/CompiledBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ abstract class CompiledBase
*/
public $checksum;

/**
* @var string Timestamp of compiled configuration
*/
public $timestamp;

/**
* @var string Cache folder to be used.
*/
Expand Down Expand Up @@ -59,9 +64,10 @@ public function __construct($cacheFolder, array $files, $path)
throw new \BadMethodCallException('Cache folder not defined.');
}

$this->path = $path ? rtrim($path, '\\/') . '/' : '';
$this->cacheFolder = $cacheFolder;
$this->files = $files;
$this->path = $path ? rtrim($path, '\\/') . '/' : '';
$this->timestamp = 0;
}

/**
Expand All @@ -84,6 +90,16 @@ public function name($name = null)
*/
public function modified() {}

/**
* Get timestamp of compiled configuration
*
* @return int Timestamp of compiled configuration
*/
public function timestamp()
{
return $this->timestamp ?: time();
}

/**
* Load the configuration.
*
Expand Down Expand Up @@ -196,6 +212,7 @@ protected function loadCompiledFile($filename)
}

$this->createObject($cache['data']);
$this->timestamp = isset($cache['timestamp']) ? $cache['timestamp'] : 0;

$this->finalizeObject();

Expand Down
1 change: 1 addition & 0 deletions system/src/Grav/Common/Config/CompiledConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ protected function createObject(array $data = [])
protected function finalizeObject()
{
$this->object->checksum($this->checksum());
$this->object->timestamp($this->timestamp());
}

/**
Expand Down
1 change: 1 addition & 0 deletions system/src/Grav/Common/Config/CompiledLanguages.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected function createObject(array $data = [])
protected function finalizeObject()
{
$this->object->checksum($this->checksum());
$this->object->timestamp($this->timestamp());
}


Expand Down
10 changes: 10 additions & 0 deletions system/src/Grav/Common/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Config extends Data
{
protected $checksum;
protected $modified = false;
protected $timestamp = 0;

public function key()
{
Expand All @@ -41,6 +42,15 @@ public function modified($modified = null)
return $this->modified;
}

public function timestamp($timestamp = null)
{
if ($timestamp !== null) {
$this->timestamp = $timestamp;
}

return $this->timestamp;
}

public function reload()
{
$grav = Grav::instance();
Expand Down
9 changes: 9 additions & 0 deletions system/src/Grav/Common/Config/Languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ public function modified($modified = null)
return $this->modified;
}

public function timestamp($timestamp = null)
{
if ($timestamp !== null) {
$this->timestamp = $timestamp;
}

return $this->timestamp;
}

public function reformat()
{
if (isset($this->items['plugins'])) {
Expand Down
13 changes: 6 additions & 7 deletions system/src/Grav/Common/Data/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public static function validate($value, array $field)
$field['type'] = 'text';
}

// If this is a YAML field, stop validation
if (isset($field['yaml']) && $field['yaml'] === true) {
return $messages;
}

// Get language class.
$language = Grav::instance()['language'];

Expand Down Expand Up @@ -98,13 +103,7 @@ public static function filter($value, array $field)

// If this is a YAML field, simply parse it and return the value.
if (isset($field['yaml']) && $field['yaml'] === true) {
try {
$yaml = new Parser();

return $yaml->parse($value);
} catch (ParseException $e) {
throw new \RuntimeException($e->getMessage());
}
return $value;
}

// Validate type with fallback type text.
Expand Down
2 changes: 2 additions & 0 deletions system/src/Grav/Common/Grav.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ public function process()
$debugger = $this['debugger'];
$debugger->render();

$this->fireEvent('onOutputRendered');

register_shutdown_function([$this, 'shutdown']);
}

Expand Down
17 changes: 13 additions & 4 deletions system/src/Grav/Common/Helpers/Exif.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,21 @@ class Exif

public function __construct()
{
if (function_exists('exif_read_data') && class_exists('\PHPExif\Reader\Reader')) {
$this->reader = \PHPExif\Reader\Reader::factory(\PHPExif\Reader\Reader::TYPE_NATIVE);
} else {
if (Grav::instance()['config']->get('system.media.auto_metadata_exif')) {
if (Grav::instance()['config']->get('system.media.auto_metadata_exif')) {
if (function_exists('exif_read_data') && class_exists('\PHPExif\Reader\Reader')) {
$this->reader = \PHPExif\Reader\Reader::factory(\PHPExif\Reader\Reader::TYPE_NATIVE);
} else {
throw new \Exception('Please enable the Exif extension for PHP or disable Exif support in Grav system configuration');
}
}
}

public function getReader()
{
if ($this->reader) {
return $this->reader;
}

return false;
}
}
6 changes: 3 additions & 3 deletions system/src/Grav/Common/Page/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function offsetGet($offset)
protected function init()
{
$config = Grav::instance()['config'];
$exif = Grav::instance()['exif'];
$exif_reader = isset(Grav::instance()['exif']) ? Grav::instance()['exif']->getReader() : false;

// Handle special cases where page doesn't exist in filesystem.
if (!is_dir($this->path)) {
Expand Down Expand Up @@ -124,9 +124,9 @@ protected function init()
}

// Read/store Exif metadata as required
if (!empty($types['base']) && $medium->get('mime') === 'image/jpeg' && empty($types['meta']) && $config->get('system.media.auto_metadata_exif')) {
if (!empty($types['base']) && $medium->get('mime') === 'image/jpeg' && empty($types['meta']) && $config->get('system.media.auto_metadata_exif') && $exif_reader) {
$file_path = $types['base']['file'];
$meta = $exif->reader->read($file_path);
$meta = $exif_reader->read($file_path);

if ($meta) {
$meta_path = $file_path . '.meta.yaml';
Expand Down
5 changes: 3 additions & 2 deletions system/src/Grav/Common/Processors/RenderProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public function process()
$container->header();

echo $output;
}

$container->fireEvent('onOutputRendered');
// remove any output
$container->output = '';
}
}
}
61 changes: 54 additions & 7 deletions system/src/Grav/Common/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Grav\Common\Twig;

use Grav\Common\Grav;
use Grav\Common\Page\Media;
use Grav\Common\Utils;
use Grav\Common\Markdown\Parsedown;
use Grav\Common\Markdown\ParsedownExtra;
Expand Down Expand Up @@ -109,6 +110,7 @@ public function getFunctions()
new \Twig_simpleFunction('authorize', [$this, 'authorize']),
new \Twig_SimpleFunction('debug', [$this, 'dump'], ['needs_context' => true, 'needs_environment' => true]),
new \Twig_SimpleFunction('dump', [$this, 'dump'], ['needs_context' => true, 'needs_environment' => true]),
new \Twig_SimpleFunction('vardump', [$this, 'vardumpFunc']),
new \Twig_SimpleFunction('evaluate', [$this, 'evaluateStringFunc'], ['needs_context' => true, 'needs_environment' => true]),
new \Twig_SimpleFunction('evaluate_twig', [$this, 'evaluateTwigFunc'], ['needs_context' => true, 'needs_environment' => true]),
new \Twig_SimpleFunction('gist', [$this, 'gistFunc']),
Expand All @@ -126,6 +128,8 @@ public function getFunctions()
new \Twig_SimpleFunction('range', [$this, 'rangeFunc']),
new \Twig_SimpleFunction('isajaxrequest', [$this, 'isAjaxFunc']),
new \Twig_SimpleFunction('exif', [$this, 'exifFunc']),
new \Twig_SimpleFunction('media', [$this, 'mediaFunc']),

];
}

Expand Down Expand Up @@ -967,17 +971,60 @@ public function isAjaxFunc()
*/
public function exifFunc($image, $raw = false)
{
if (file_exists($image)) {
if (isset($this->grav['exif'])) {

$exif_data = $this->grav['exif']->reader->read($image);
/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];

if ($exif_data) {
if ($raw) {
return $exif_data->getRawData();
} else {
return $exif_data->getData();
if ($locator->isStream($image)) {
$image = $locator->findResource($image);
}

$exif_reader = $this->grav['exif']->getReader();

if (file_exists($image) && $this->config->get('system.media.auto_metadata_exif') && $exif_reader) {

$exif_data = $exif_reader->read($image);

if ($exif_data) {
if ($raw) {
return $exif_data->getRawData();
} else {
return $exif_data->getData();
}
}
}
}
}

/**
* Process a folder as Media and return a media object
*
* @param $media_dir
* @return Media
*/
public function mediaFunc($media_dir)
{
/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];

if ($locator->isStream($media_dir)) {
$media_dir = $locator->findResource($media_dir);
}

if (file_exists($media_dir)) {
return new Media($media_dir);
}

}

/**
* Dump a variable to the browser
*
* @param $var
*/
public function vardumpFunc($var)
{
var_dump($var);
}
}

0 comments on commit f3cecd8

Please sign in to comment.