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
# Conflicts:
#	CHANGELOG.md
#	system/defines.php
  • Loading branch information
mahagr committed Dec 11, 2017
2 parents cc648b8 + 6628bbb commit bfd8a08
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 94 deletions.
19 changes: 17 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,20 @@
1. [](#improved)
* Make it possible to include debug bar also into non-HTML responses

# v1.3.11
## mm/dd/2017

1. [](#bugfix)
* Fixed issue with _illegal scheme offset_ in `Uri::convertUrl()` [page-inject#8](https://github.com/getgrav/grav-plugin-page-inject/issues/8)

# v1.3.10
## 12/06/2017

1. [](#bugfix)
* Reverted GPM Local pull request as it broken admin [#1742](https://github.com/getgrav/grav/issues/1742)

# v1.3.9
## xx/xx/2017
## 12/05/2017

1. [](#new)
* Added new core Twig templates for `partials/metadata.html.twig` and `partials/messages.html.twig`
Expand All @@ -24,7 +36,9 @@
* Added new `force_lowercase_urls` functionality on routes and slugs
* Added new `item-list` filter type to remove empty items
* Added new `setFlashCookieObject()` and `getFlashCookieObject()` methods to `Session` object
* Added new `intl_enabled` option to disable PHP intl module collation when not needed
1. [](#bugfix)
* Fixed an issue with checkbox field validation [form#216](https://github.com/getgrav/grav-plugin-form/issues/216)
* 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)
Expand All @@ -33,12 +47,13 @@
* Fixed typo in `modular.yaml` causing media to be ignored [#1725](https://github.com/getgrav/grav/issues/1725)
* Reverted `case_insensitive_urls` option as it was causing issues with taxonomy [#1733](https://github.com/getgrav/grav/pull/1733)
* Removed an extra `/` in `CompileFile.php` [#1693](https://github.com/getgrav/grav/pull/1693)
* Uri: Encode user and password to prevent issues in browsers
* Uri::Encode user and password to prevent issues in browsers
* Fixed "Invalid AJAX response" When using Built-in PHP Webserver in Windows [#1258](https://github.com/getgrav/grav-plugin-admin/issues/1258)
* 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)
* Forced `field.multiple: true` to allow use of min/max options in `checkboxes.validate`

# v1.3.8
## 10/26/2017
Expand Down
10 changes: 10 additions & 0 deletions system/blueprints/config/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,16 @@ form:
label: PLUGIN_ADMIN.PWD_REGEX
help: PLUGIN_ADMIN.PWD_REGEX_HELP

intl_enabled:
type: toggle
label: PLUGIN_ADMIN.INTL_ENABLED
highlight: 1
help: PLUGIN_ADMIN.INTL_ENABLED_HELP
options:
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
validate:
type: bool

wrapped_site:
type: toggle
Expand Down
1 change: 1 addition & 0 deletions system/config/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ force_lowercase_urls: true # If you want to support mixed
custom_base_url: '' # Set the base_url manually, e.g. http://yoursite.com/yourpath
username_regex: '^[a-z0-9_-]{3,16}$' # Only lowercase chars, digits, dashes, underscores. 3 - 16 chars
pwd_regex: '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}' # At least one number, one uppercase and lowercase letter, and be at least 8+ chars
intl_enabled: true # Special logic for PHP International Extension (mod_intl)

languages:
supported: [] # List of languages supported. eg: [en, fr, de]
Expand Down
15 changes: 8 additions & 7 deletions system/src/Grav/Common/Data/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ public static function validate($value, array $field)
$messages = [];

$validate = isset($field['validate']) ? (array) $field['validate'] : [];
// Validate type with fallback type text.
$type = (string) isset($validate['type']) ? $validate['type'] : $field['type'];
$method = 'type'.strtr($type, '-', '_');

// If value isn't required, we will stop validation if empty value is given.
if (empty($validate['required']) && ($value === null || $value === '')) {
if ((empty($validate['required']) || (isset($validate['required']) && $validate['required'] !== true)) && ($value === null || $value === '' || ($field['type'] === 'checkbox' && $value == false))) {
return $messages;
}

Expand All @@ -46,10 +49,6 @@ public static function validate($value, array $field)
// Get language class.
$language = Grav::instance()['language'];

// Validate type with fallback type text.
$type = (string) isset($field['validate']['type']) ? $field['validate']['type'] : $field['type'];
$method = 'type'.strtr($type, '-', '_');

$name = ucfirst(isset($field['label']) ? $field['label'] : $field['name']);
$message = (string) isset($field['validate']['message'])
? $language->translate($field['validate']['message'])
Expand Down Expand Up @@ -161,7 +160,7 @@ protected static function filterCommaList($value, array $params, array $field)
return is_array($value) ? $value : preg_split('/\s*,\s*/', $value, -1, PREG_SPLIT_NO_EMPTY);
}

protected static function typeCommaList($value, array $params, array $field)
public static function typeCommaList($value, array $params, array $field)
{
return is_array($value) ? true : self::typeText($value, $params, $field);
}
Expand Down Expand Up @@ -230,6 +229,8 @@ public static function typeHidden($value, array $params, array $field)
*/
public static function typeCheckboxes($value, array $params, array $field)
{
// Set multiple: true so checkboxes can easily use min/max counts to control number of options required
$field['multiple'] = true;
return self::typeArray((array) $value, $params, $field);
}

Expand All @@ -253,7 +254,7 @@ public static function typeCheckbox($value, array $params, array $field)
if (!isset($field['value'])) {
$field['value'] = 1;
}
if ($value && $value != $field['value']) {
if (isset($value) && $value != $field['value']) {
return false;
}

Expand Down
38 changes: 6 additions & 32 deletions system/src/Grav/Common/GPM/GPM.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

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

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

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

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

/**
* 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
* Creates a new GPM instance with Local and Remote 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();
$this->shouldRefresh = $refresh;
$this->callback = $callback;
}

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

/**
Expand Down Expand Up @@ -289,7 +268,6 @@ 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 @@ -332,7 +310,6 @@ public function isPluginUpdatable($plugin)
public function getUpdatableThemes()
{
$items = [];
$this->retrieveRemoteRepository();
$repository = $this->repository['themes'];

// local cache to speed things up
Expand Down Expand Up @@ -380,7 +357,6 @@ 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 @@ -429,7 +405,6 @@ public function isTestingRelease($package_name)
*/
public function getRepositoryPlugin($slug)
{
$this->retrieveRemoteRepository();
return @$this->repository['plugins'][$slug];
}

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

Expand Down
8 changes: 4 additions & 4 deletions system/src/Grav/Common/Page/Medium/AudioMedium.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@ public function controlsList($controlsList)
}

/**
* Allows to set the mute attribute
* Allows to set the muted attribute
*
* @param bool $status
* @return $this
*/
public function mute($status = false)
public function muted($status = false)
{
if($status)
{
$this->attributes['mute'] = true;
$this->attributes['muted'] = true;
}
else
{
unset($this->attributes['mute']);
unset($this->attributes['muted']);
}
return $this;
}
Expand Down
9 changes: 8 additions & 1 deletion system/src/Grav/Common/Page/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -1255,14 +1255,21 @@ protected function buildSort($path, array $pages, $order_by = 'default', $manual
$list = $this->arrayShuffle($list);
} else {
// else just sort the list according to specified key
if (extension_loaded('intl')) {
if (extension_loaded('intl') && $this->grav['config']->get('system.intl_enabled')) {
$locale = setlocale(LC_COLLATE, 0); //`setlocale` with a 0 param returns the current locale set
$col = Collator::create($locale);
if ($col) {
if (($sort_flags & SORT_NATURAL) === SORT_NATURAL) {
$list = preg_replace_callback('~([0-9]+)\.~', function($number) {
return sprintf('%032d.', $number[0]);
}, $list);

$list_vals = array_values($list);
if (is_numeric(array_shift($list_vals))) {
$sort_flags = Collator::SORT_REGULAR;
} else {
$sort_flags = Collator::SORT_STRING;
}
}

$col->asort($list, $sort_flags);
Expand Down
11 changes: 6 additions & 5 deletions system/src/Grav/Common/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ public static function convertUrl(Page $page, $url, $type = 'link', $absolute =
}

// handle absolute URLs
if (!$external && ($absolute === true || $grav['config']->get('system.absolute_urls', false))) {
if (is_array($url) && !$external && ($absolute === true || $grav['config']->get('system.absolute_urls', false))) {

$url['scheme'] = $uri->scheme(true);
$url['host'] = $uri->host();
Expand Down Expand Up @@ -983,17 +983,18 @@ public static function convertUrl(Page $page, $url, $type = 'link', $absolute =
}
}

// Handle route only
if ($route_only) {
$url_path = str_replace($base_url, '', $url_path);
}

// transform back to string/array as needed
if (is_array($url)) {
$url['path'] = $url_path;
} else {
$url = $url_path;
}

if ($route_only) {
$url = str_replace($base_url, '', $url);
}

return $url;
}

Expand Down
43 changes: 0 additions & 43 deletions tests/unit/Grav/Common/GPM/GPMTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,47 +320,4 @@ 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 bfd8a08

Please sign in to comment.