Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/getgrav/grav into featur…
Browse files Browse the repository at this point in the history
…e/session
  • Loading branch information
mahagr committed May 17, 2018
2 parents 78ab2aa + 1976471 commit eae017a
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 40 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
# v1.4.5
## 05/15/2018

1. [](#bugfix)
* Fixed an issue with some users getting **2FA** prompt after upgrade [admin#1442](https://github.com/getgrav/grav-plugin-admin/issues/1442)
* Do not crash when generating URLs with arrays as parameters [#2018](https://github.com/getgrav/grav/pull/2018)
* Utils::truncateHTML removes whitespace when generating summaries [#2004](https://github.com/getgrav/grav/pull/2004)

# v1.4.4
## 05/11/2018

1. [](#new)
* Added support for `Uri::post()` and `Uri::getConentType()`
* Added a new `Medium:thumbnailExists()` function [#1966](https://github.com/getgrav/grav/issues/1966)
* Added `authorized` support for 2FA
1. [](#improved)
* Added default configuration for images [#1979](https://github.com/getgrav/grav/pull/1979)
* Added dedicated PHPUnit assertions [#1990](https://github.com/getgrav/grav/pull/1990)
1. [](#bugfix)
* Use `array_key_exists` instead of `in_array + array_keys` [#1991](https://github.com/getgrav/grav/pull/1991)
* Fixed an issue with `custom_base_url` always causing 404 errors
* Improve support for regex redirects with query and params [#1983](https://github.com/getgrav/grav/issues/1983)
* Changed collection-based date sorting to `SORT_REGULAR` for better server compatibility [#1910](https://github.com/getgrav/grav/issues/1910)
* Fix hardcoded string in modular blueprint [#1933](https://github.com/getgrav/grav/pull/1993)

# v1.4.3
## 04/12/2018

Expand Down
2 changes: 1 addition & 1 deletion system/blueprints/pages/modular.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ form:

modular_title:
type: spacer
title: Modular Setup
title: PLUGIN_ADMIN.MODULAR_SETUP

header.content.items:
type: text
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.4.3');
define('GRAV_VERSION', '1.4.5');
define('GRAV_TESTING', false);
define('DS', '/');

Expand Down
9 changes: 9 additions & 0 deletions system/src/Grav/Common/Helpers/Excerpts.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@ public static function processMediaActions($medium, $url)
if (Grav::instance()['config']->get('system.images.auto_fix_orientation')) {
$actions[] = ['method' => 'fixOrientation', 'params' => ''];
}
$defaults = Grav::instance()['config']->get('system.images.defaults');
if (is_array($defaults) && count($defaults)) {
foreach ($defaults as $method => $params) {
$actions[] = [
'method' => $method,
'params' => $params,
];
}
}

// loop through actions for the image and call them
foreach ($actions as $action) {
Expand Down
20 changes: 18 additions & 2 deletions system/src/Grav/Common/Helpers/Truncator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static function truncateWords($html, $limit = 0, $ellipsis = '')

// Iterate over words.
$words = new DOMWordsIterator($body);
$truncated = false;
foreach ($words as $word) {

// If we have exceeded the limit, we delete the remainder of the content.
Expand All @@ -70,12 +71,19 @@ public static function truncateWords($html, $limit = 0, $ellipsis = '')
self::insertEllipsis($curNode, $ellipsis);
}

$truncated = true;

break;
}

}

return self::innerHTML($body);
// Return original HTML if not truncated.
if ($truncated) {
return self::innerHTML($body);
} else {
return $html;
}
}

/**
Expand All @@ -98,6 +106,7 @@ public static function truncateLetters($html, $limit = 0, $ellipsis = "")

// Iterate over letters.
$letters = new DOMLettersIterator($body);
$truncated = false;
foreach ($letters as $letter) {

// If we have exceeded the limit, we want to delete the remainder of this document.
Expand All @@ -111,11 +120,18 @@ public static function truncateLetters($html, $limit = 0, $ellipsis = "")
self::insertEllipsis($currentText[0], $ellipsis);
}

$truncated = true;

break;
}
}

return self::innerHTML($body);
// Return original HTML if not truncated.
if ($truncated) {
return self::innerHTML($body);
} else {
return $html;
}
}

/**
Expand Down
25 changes: 24 additions & 1 deletion system/src/Grav/Common/Page/Medium/Medium.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Grav\Common\Grav;
use Grav\Common\Data\Data;
use Grav\Common\Data\Blueprint;
use Grav\Common\Utils;

class Medium extends Data implements RenderableInterface
{
Expand Down Expand Up @@ -398,6 +399,22 @@ public function display($mode = 'source')
return $mode === 'thumbnail' ? ($this->getThumbnail() ? $this->getThumbnail()->reset() : null) : $this->reset();
}

/**
* Helper method to determine if this media item has a thumbnail or not
*
* @param string $type;
*
* @return bool
*/
public function thumbnailExists($type = 'page')
{
$thumbs = $this->get('thumbnails');
if (isset($thumbs[$type])) {
return true;
}
return false;
}

/**
* Switch thumbnail.
*
Expand All @@ -420,6 +437,7 @@ public function thumbnail($type = 'auto')
return $this;
}


/**
* Turn the current Medium into a Link
*
Expand Down Expand Up @@ -518,7 +536,12 @@ public function __call($method, $args)
{
$qs = $method;
if (count($args) > 1 || (count($args) == 1 && !empty($args[0]))) {
$qs .= '=' . implode(',', array_map(function ($a) { return rawurlencode($a); }, $args));
$qs .= '=' . implode(',', array_map(function ($a) {
if (is_array($a)) {
$a = '[' . implode(',', $a) . ']';
}
return rawurlencode($a);
}, $args));
}

if (!empty($qs)) {
Expand Down
19 changes: 9 additions & 10 deletions system/src/Grav/Common/Page/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,13 @@ public function dispatch($route, $all = false, $redirect = true)
if ($site_route) {
$page = $this->dispatch($site_route, $all);
} else {
// Try Regex style redirects

/** @var Uri $uri */
$uri = $this->grav['uri'];
$source_url = $route;
$extension = $uri->extension();
if (isset($extension) && !Utils::endsWith($uri->url(), $extension)) {
$source_url.= '.' . $extension;
}
/** @var \Grav\Framework\Uri\Uri $source_url */
$source_url = $uri->uri(false);

// Try Regex style redirects
$site_redirects = $config->get("site.redirects");
if (is_array($site_redirects)) {
foreach ((array)$site_redirects as $pattern => $replace) {
Expand Down Expand Up @@ -1203,19 +1202,19 @@ protected function buildSort($path, array $pages, $order_by = 'default', $manual
break;
case 'date':
$list[$key] = $child->date();
$sort_flags = SORT_NUMERIC;
$sort_flags = SORT_REGULAR;
break;
case 'modified':
$list[$key] = $child->modified();
$sort_flags = SORT_NUMERIC;
$sort_flags = SORT_REGULAR;
break;
case 'publish_date':
$list[$key] = $child->publishDate();
$sort_flags = SORT_NUMERIC;
$sort_flags = SORT_REGULAR;
break;
case 'unpublish_date':
$list[$key] = $child->unpublishDate();
$sort_flags = SORT_NUMERIC;
$sort_flags = SORT_REGULAR;
break;
case 'slug':
$list[$key] = $child->slug();
Expand Down
8 changes: 6 additions & 2 deletions system/src/Grav/Common/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Grav\Common\Twig\TokenParser\TwigTokenParserSwitch;
use Grav\Common\Twig\TokenParser\TwigTokenParserTryCatch;
use Grav\Common\Twig\TokenParser\TwigTokenParserMarkdown;
use Grav\Common\User\User;
use Grav\Common\Utils;
use Grav\Common\Markdown\Parsedown;
use Grav\Common\Markdown\ParsedownExtra;
Expand Down Expand Up @@ -875,7 +876,10 @@ public function translateFunc()
*/
public function authorize($action)
{
if (!$this->grav['user']->authenticated) {
/** @var User $user */
$user = $this->grav['user'];

if (!$user->authenticated || (isset($user->authorized) && !$user->authorized)) {
return false;
}

Expand All @@ -884,7 +888,7 @@ public function authorize($action)
$prefix = is_int($key) ? '' : $key . '.';
$perms = $prefix ? (array) $perms : [$perms => true];
foreach ($perms as $action2 => $authenticated) {
if ($this->grav['user']->authorize($prefix . $action2)) {
if ($user->authorize($prefix . $action2)) {
return $authenticated;
}
}
Expand Down
77 changes: 75 additions & 2 deletions system/src/Grav/Common/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class Uri
protected $root;
protected $root_path;
protected $uri;
protected $content_type;
protected $post;

/**
* Uri constructor.
Expand Down Expand Up @@ -133,7 +135,12 @@ public function init()
$custom_parts = parse_url($custom_base);
$orig_root_path = $this->root_path;
$this->root_path = isset($custom_parts['path']) ? rtrim($custom_parts['path'], '/') : '';
$this->root = isset($custom_parts['scheme']) ? $custom_base : $this->base . $this->root_path;
if (isset($custom_parts['scheme'])) {
$this->base = $custom_parts['scheme'] . '://' . $custom_parts['host'];
$this->root = $custom_base;
} else {
$this->root = $this->base . $this->root_path;
}
$this->uri = Utils::replaceFirstOccurrence($orig_root_path, $this->root_path, $this->uri);
} else {
$this->root = $this->base . $this->root_path;
Expand All @@ -143,6 +150,7 @@ public function init()

$uri = str_replace(static::filterPath($this->root), '', $this->url);


// remove the setup.php based base if set:
$setup_base = $grav['pages']->base();
if ($setup_base) {
Expand Down Expand Up @@ -464,6 +472,23 @@ public function basename()
return $this->basename;
}

/**
* Return the full uri
*
* @param bool $include_root
* @return mixed
*/
public function uri($include_root = true)
{
if ($include_root) {
return $this->uri;
} else {
$uri = str_replace($this->root_path, '', $this->uri);
return $uri;
}

}

/**
* Return the base of the URI
*
Expand Down Expand Up @@ -1185,7 +1210,6 @@ protected function createFromString($url)
if ($this->host) {
$this->host = $this->validateHostname($this->host) ? $this->host : 'unknown';
}

// Filter userinfo, path, query string and fragment.
$this->user = $this->user !== null ? static::filterUserInfo($this->user) : null;
$this->password = $this->password !== null ? static::filterUserInfo($this->password) : null;
Expand Down Expand Up @@ -1213,6 +1237,55 @@ protected function reset()
$this->url = $this->base . $this->uri;
}

/**
* Get's post from either $_POST or JSON response object
* By default returns all data, or can return a single item
*
* @param string $element
* @param string $filter_type
* @return array|mixed|null
*/
public function post($element = null, $filter_type = null)
{
if (!$this->post) {
$content_type = $this->getContentType();
if ($content_type == 'application/json') {
$json = file_get_contents('php://input');
$this->post = json_decode($json, true);
} elseif (!empty($_POST)) {
$this->post = (array)$_POST;
}
}

if ($this->post && !is_null($element)) {
$item = Utils::getDotNotation($this->post, $element);
if ($filter_type) {
$item = filter_var($item, $filter_type);
}
return $item;
}

return $this->post;
}

/**
* Get content type from request
*
* @param bool $short
* @return null|string
*/
private function getContentType($short = true)
{
if (isset($_SERVER['CONTENT_TYPE'])) {
$content_type = $_SERVER['CONTENT_TYPE'];
if ($short) {
return Utils::substrToString($content_type,';');
}
return $content_type;
}
return null;
}

/**
* Get the base URI with port if needed
*
Expand Down
Loading

0 comments on commit eae017a

Please sign in to comment.