Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/getgrav/grav into 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Nov 29, 2017
2 parents ddd451b + a1eccfd commit 66d8269
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
## xx/xx/2017

1. [](#new)
* Added ability to work with GPM locally [#1742](https://github.com/getgrav/grav/issues/1742)
* Added new HTML5 audio controls [#1756](https://github.com/getgrav/grav/issues/1756)
* Added `Medium::copy()` method to create a copy of a medium object
* Added new `force_lowercase_urls` functionality on routes and slugs
* Added new `item-list` filter type to remove empty items
1. [](#bugfix)
* Fixed issue with multibyte Markdown link URLs [#1749](https://github.com/getgrav/grav/issues/1749)
* Fixed issue with multibyte folder names [#1751](https://github.com/getgrav/grav/issues/1751)
* Fixed several issues related to `system.custom_base_url` that were broken [#1736](https://github.com/getgrav/grav/issues/1736)
* Dynamically added pages via `Pages::addPage()` were not firing `onPageProcessed()` event causing forms not to be processed
* Fixed `Page::active()` and `Page::activeChild()` to work with UTF-8 characters in the URL [#1727](https://github.com/getgrav/grav/issues/1727)
Expand All @@ -31,6 +36,7 @@
* Remove support for `config.user`, it was broken and bad practise
* Make sure that `clean cache` uses valid path [#1745](https://github.com/getgrav/grav/pull/1745)
* Fixed token creation issue with `Uri` params like `/id:3`
* Fixed CSS Pipeline failing with Google remote fonts if the file was minified [#1261](https://github.com/getgrav/grav-plugin-admin/issues/1261)

# v1.3.8
## 10/26/2017
Expand Down
8 changes: 6 additions & 2 deletions system/src/Grav/Common/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ class Assets
const CSS_URL_REGEX = '{url\(([\'\"]?)(.*?)\1\)}';

/** @const Regex to match CSS sourcemap comments */
const CSS_SOURCEMAP_REGEX = '{\/\*# (.*) \*\/}';
const CSS_SOURCEMAP_REGEX = '{\/\*# (.*?) \*\/}';

/** @const Regex to match CSS import content */
const CSS_IMPORT_REGEX = '{@import(.*);}';
const CSS_IMPORT_REGEX = '{@import(.*?);}';

/**
* @const Regex to match <script> or <style> tag when adding inline style/script. Note that this only supports a
* single tag, so the check is greedy to avoid issues in JS.
*/
const HTML_TAG_REGEX = '#(<([A-Z][A-Z0-9]*)>)+(.*)(<\/\2>)#is';


Expand Down
5 changes: 5 additions & 0 deletions system/src/Grav/Common/Data/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,11 @@ public static function validateArray($value, $params)
&& $value instanceof \Countable);
}

public static function filterItem_List($value, $params)
{
return array_values(array_filter($value, function($v) { return !empty($v); } ));
}

public static function validateJson($value, $params)
{
return (bool) (@json_decode($value));
Expand Down
38 changes: 32 additions & 6 deletions system/src/Grav/Common/GPM/GPM.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

class GPM extends Iterator
{
/** @var callable */
private $callback;

/**
* Local installed Packages
* @var Local\Packages
Expand All @@ -29,6 +32,9 @@ class GPM extends Iterator
*/
private $repository;

/** @var bool */
private $shouldRefresh;

/**
* @var Remote\GravCore
*/
Expand All @@ -47,18 +53,33 @@ class GPM extends Iterator
];

/**
* Creates a new GPM instance with Local and Remote packages available
* Loads Remote Packages available
*/
private function retrieveRemoteRepository()
{
if (!$this->repository) {
$this->repository = new Remote\Packages($this->shouldRefresh, $this->callback);
}
}

/**
* Creates a new GPM instance with Local packages available
* @param boolean $refresh Applies to Remote Packages only and forces a refetch of data
* @param callable $callback Either a function or callback in array notation
*/
public function __construct($refresh = false, $callback = null)
{
$this->installed = new Local\Packages();
try {
$this->repository = new Remote\Packages($refresh, $callback);
$this->grav = new Remote\GravCore($refresh, $callback);
} catch (\Exception $e) {
}
$this->shouldRefresh = $refresh;
$this->callback = $callback;
}

/**
* Loads Remote Grav package available
*/
public function loadRemoteGrav()
{
$this->grav = new Remote\GravCore($this->refresh, $this->callback);
}

/**
Expand Down Expand Up @@ -268,6 +289,7 @@ public function getUpdatablePlugins()
*/
public function getLatestVersionOfPackage($package_name)
{
$this->retrieveRemoteRepository();
$repository = $this->repository['plugins'];
if (isset($repository[$package_name])) {
return $repository[$package_name]->available ?: $repository[$package_name]->version;
Expand Down Expand Up @@ -310,6 +332,7 @@ public function isPluginUpdatable($plugin)
public function getUpdatableThemes()
{
$items = [];
$this->retrieveRemoteRepository();
$repository = $this->repository['themes'];

// local cache to speed things up
Expand Down Expand Up @@ -357,6 +380,7 @@ public function isThemeUpdatable($theme)
*/
public function getReleaseType($package_name)
{
$this->retrieveRemoteRepository();
$repository = $this->repository['plugins'];
if (isset($repository[$package_name])) {
return $repository[$package_name]->release_type;
Expand Down Expand Up @@ -405,6 +429,7 @@ public function isTestingRelease($package_name)
*/
public function getRepositoryPlugin($slug)
{
$this->retrieveRemoteRepository();
return @$this->repository['plugins'][$slug];
}

Expand Down Expand Up @@ -443,6 +468,7 @@ public function getRepositoryThemes()
*/
public function getRepository()
{
$this->retrieveRemoteRepository();
return $this->repository;
}

Expand Down
3 changes: 2 additions & 1 deletion system/src/Grav/Common/Helpers/Excerpts.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Grav\Common\Page\Page;
use Grav\Common\Uri;
use Grav\Common\Page\Medium\Medium;
use Grav\Common\Utils;
use RocketTheme\Toolbox\Event\Event;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;

Expand Down Expand Up @@ -321,7 +322,7 @@ public static function processMediaActions($medium, $url)
*/
protected static function parseUrl($url)
{
$url_parts = parse_url($url);
$url_parts = Utils::multibyteParseUrl($url);

if (isset($url_parts['scheme'])) {
/** @var UniformResourceLocator $locator */
Expand Down
108 changes: 108 additions & 0 deletions system/src/Grav/Common/Page/Medium/AudioMedium.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,114 @@ protected function sourceParsedownElement(array $attributes, $reset = true)
];
}

/**
* Allows to set or remove the HTML5 default controls
*
* @param bool $display
* @return $this
*/
public function controls($display = true)
{
if($display)
{
$this->attributes['controls'] = true;
}
else
{
unset($this->attributes['controls']);
}
return $this;
}

/**
* Allows to set the preload behaviour
*
* @param $preload
* @return $this
*/
public function preload($preload)
{
$validPreloadAttrs = array('auto','metadata','none');

if (in_array($preload, $validPreloadAttrs))
{
$this->attributes['preload'] = $preload;
}
return $this;
}

/**
* Allows to set the controlsList behaviour
* Separate multiple values with a hyphen
*
* @param $controlsList
* @return $this
*/
public function controlsList($controlsList)
{
$controlsList = str_replace('-', ' ', $controlsList);
$this->attributes['controlsList'] = $controlsList;
return $this;
}

/**
* Allows to set the mute attribute
*
* @param bool $status
* @return $this
*/
public function mute($status = false)
{
if($status)
{
$this->attributes['mute'] = true;
}
else
{
unset($this->attributes['mute']);
}
return $this;
}

/**
* Allows to set the loop attribute
*
* @param bool $status
* @return $this
*/
public function loop($status = false)
{
if($status)
{
$this->attributes['loop'] = true;
}
else
{
unset($this->attributes['loop']);
}
return $this;
}

/**
* Allows to set the autoplay attribute
*
* @param bool $status
* @return $this
*/
public function autoplay($status = false)
{
if($status)
{
$this->attributes['autoplay'] = true;
}
else
{
unset($this->attributes['autoplay']);
}
return $this;
}


/**
* Reset medium.
*
Expand Down
2 changes: 1 addition & 1 deletion system/src/Grav/Common/Page/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -2902,7 +2902,7 @@ protected function adjustRouteCase($route)
$case_insensitive = Grav::instance()['config']->get('system.force_lowercase_urls');

if ($case_insensitive) {
return strtolower($route);
return mb_strtolower($route);
} else {
return $route;
}
Expand Down
32 changes: 32 additions & 0 deletions system/src/Grav/Common/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -997,4 +997,36 @@ public static function parseSize($size)
return intval($size);
}
}

/**
* Multibyte-safe Parse URL function
*
* @param $url
* @return mixed
*/
public static function multibyteParseUrl($url)
{
$enc_url = preg_replace_callback(
'%[^:/@?&=#]+%usD',
function ($matches)
{
return urlencode($matches[0]);
},
$url
);

$parts = parse_url($enc_url);

if($parts === false)
{
throw new \InvalidArgumentException('Malformed URL: ' . $url);
}

foreach($parts as $name => $value)
{
$parts[$name] = urldecode($value);
}

return $parts;
}
}
43 changes: 43 additions & 0 deletions tests/unit/Grav/Common/GPM/GPMTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,47 @@ public function testCalculateVersionNumberFromDependencyVersion()
$this->assertSame(null, $this->gpm->calculateVersionNumberFromDependencyVersion('*'));
$this->assertSame('2.0.2', $this->gpm->calculateVersionNumberFromDependencyVersion('2.0.2'));
}

public function testRemoteRepositoryIsEmptyAfterConstruct()
{
$gpm = new GPM();
$reflection = new \ReflectionClass(get_class($gpm));
$repository = $reflection->getProperty('repository');
$repository->setAccessible(true);

$this->assertSame(null, $repository->getValue($gpm));
}

public function testLocalRepositoryIsNotEmptyAfterConstruct()
{
$gpm = new GPM();
$reflection = new \ReflectionClass(get_class($gpm));
$repository = $reflection->getProperty('installed');
$repository->setAccessible(true);

$this->assertInstanceOf( '\Grav\Common\GPM\Local\Packages', $repository->getValue($gpm));
}

public function testGetRepository()
{
$this->assertInstanceOf('\Grav\Common\GPM\Remote\Packages', $this->gpm->getRepository());
}

public function testLatestVersionOfPackage()
{
$gpm = new GPM();
$this->assertNotNull($gpm->getLatestVersionOfPackage('admin'));
}

public function testReleaseType()
{
$gpm = new GPM();
$this->assertNotNull($gpm->getReleaseType('admin'));
}

public function testGetRepositoryPlugin()
{
$gpm = new GPM();
$this->assertNotNull($gpm->getRepositoryPlugin('admin'));
}
}

0 comments on commit 66d8269

Please sign in to comment.