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/src/Grav/Common/Twig/TwigExtension.php
  • Loading branch information
mahagr committed Aug 29, 2017
2 parents 96ee41a + 7a3f136 commit 0644eac
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 34 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@
1. [](#improved)
* Make it possible to include debug bar also into non-HTML responses

# v1.3.3
## xx/xx/2017

1. [](#new)
* Added support for 2-Factor Authentication in admin profile
* Added `gaussianBlur` media method [#1623](https://github.com/getgrav/grav/pull/1623)
* Added new `|chunk_split()` Twig filter
* Added new `tl` Twig filter/function to spport specific translations [#1618](https://github.com/getgrav/grav/issues/1618)
1. [](#improved)
* Added options to `Page::summary()` to support size without HTML tags [#1554](https://github.com/getgrav/grav/issues/1554)
* Forced `natsort` on plugins to ensure consistent plugin load ordering across platforms [#1614](https://github.com/getgrav/grav/issues/1614)
* Use new `multilevel` field to handle Asset Collections [#1201](https://github.com/getgrav/grav-plugin-admin/issues/1201)
* Added support for redis `password` option [#1620](https://github.com/getgrav/grav/issues/1620)
* Use 302 rather than 301 redirects by default [#1619](https://github.com/getgrav/grav/issues/1619)
1. [](#bugfix)
* Fixed UTF8 2 character support in `Page::summary()` [#1554](https://github.com/getgrav/grav/issues/1554)

# v1.3.2
## 08/16/2017

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"filp/whoops": "~2.0",
"matthiasmullie/minify": "^1.3",
"monolog/monolog": "~1.0",
"gregwar/image": "~2.0",
"gregwar/image": "2.*",
"donatj/phpuseragentparser": "~0.3",
"pimple/pimple": "~3.0",
"rockettheme/toolbox": "~1.3",
Expand Down
10 changes: 9 additions & 1 deletion system/blueprints/config/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,12 @@ form:
help: PLUGIN_ADMIN.REDIS_PORT_HELP
placeholder: "6379"

cache.redis.password:
type: text
size: small
label: PLUGIN_ADMIN.REDIS_PASSWORD



twig:
type: section
Expand Down Expand Up @@ -806,10 +812,12 @@ form:
type: bool

assets.collections:
type: array
type: multilevel
label: PLUGIN_ADMIN.COLLECTIONS
placeholder_key: collection_name
placeholder_value: collection_path
validate:
type: array

errors:
type: section
Expand Down
31 changes: 31 additions & 0 deletions system/blueprints/user/account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,37 @@ form:
default: 'en'
help: PLUGIN_ADMIN.LANGUAGE_HELP

twofa_check:
type: conditional
condition: config.plugins.admin.twofa_enabled

fields:

twofa:
title: PLUGIN_ADMIN.2FA_TITLE
type: section
underline: true

twofa_enabled:
type: toggle
label: PLUGIN_ADMIN.2FA_ENABLED
classes: twofa-toggle
highlight: 1
default: 0
options:
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
validate:
type: bool


twofa_secret:
type: 2fa_secret
outerclasses: 'twofa-secret'
label: PLUGIN_ADMIN.2FA_SECRET
sublabel: PLUGIN_ADMIN.2FA_SECRET_HELP


security:
title: PLUGIN_ADMIN.ACCESS_LEVELS
type: section
Expand Down
4 changes: 2 additions & 2 deletions system/config/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ pages:
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
redirect_default_code: 301 # Default code to use for redirects
redirect_trailing_slash: true # Handle automatically or 301 redirect a trailing / URL
redirect_default_code: 302 # Default code to use for redirects
redirect_trailing_slash: true # Handle automatically or 302 redirect a trailing / URL
ignore_files: [.DS_Store] # Files to ignore in Pages
ignore_folders: [.git, .idea] # Folders to ignore in Pages
ignore_hidden: true # Ignore all Hidden files and folders
Expand Down
6 changes: 6 additions & 0 deletions system/src/Grav/Common/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public function getCacheDriver()
case 'redis':
$redis = new \Redis();
$socket = $this->config->get('system.cache.redis.socket', false);
$password = $this->config->get('system.cache.redis.password', false);

if ($socket) {
$redis->connect($socket);
Expand All @@ -248,6 +249,11 @@ public function getCacheDriver()
$this->config->get('system.cache.redis.port', 6379));
}

// Authenticate with password if set
if ($password && !$redis->auth($password)) {
throw new \RedisException('Redis authentication failed');
}

$driver = new DoctrineCache\RedisCache();
$driver->setRedis($redis);
break;
Expand Down
2 changes: 1 addition & 1 deletion system/src/Grav/Common/Grav.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function redirect($route, $code = null)
}

if ($code === null) {
$code = $this['config']->get('system.pages.redirect_default_code', 301);
$code = $this['config']->get('system.pages.redirect_default_code', 302);
}

if (isset($this['session'])) {
Expand Down
2 changes: 1 addition & 1 deletion system/src/Grav/Common/Page/Medium/ImageMedium.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ImageMedium extends Medium
'resize', 'forceResize', 'cropResize', 'crop', 'zoomCrop',
'negate', 'brightness', 'contrast', 'grayscale', 'emboss',
'smooth', 'sharp', 'edge', 'colorize', 'sepia', 'enableProgressive',
'rotate', 'flip', 'fixOrientation'
'rotate', 'flip', 'fixOrientation', 'gaussianBlur'
];

/**
Expand Down
73 changes: 49 additions & 24 deletions system/src/Grav/Common/Page/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ 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
* @param string $extension
* @param string $extension
*
* @return $this
*/
Expand Down Expand Up @@ -331,7 +331,8 @@ public function header($var = null)
$frontmatter_file = $this->path . '/' . $this->folder . '/frontmatter.yaml';
if (file_exists($frontmatter_file)) {
$frontmatter_data = (array)Yaml::parse(file_get_contents($frontmatter_file));
$this->header = (object)array_replace_recursive($frontmatter_data, (array)$this->header);
$this->header = (object)array_replace_recursive($frontmatter_data,
(array)$this->header);
}
// Process frontmatter with Twig if enabled
if (Grav::instance()['config']->get('system.pages.frontmatter.process_twig') === true) {
Expand Down Expand Up @@ -485,9 +486,11 @@ public function modifyHeader($key, $value)
*
* @param int $size Max summary size.
*
* @param boolean $textOnly Only count text size.
*
* @return string
*/
public function summary($size = null)
public function summary($size = null, $textOnly = false)
{
$config = (array)Grav::instance()['config']->get('site.summary');
if (isset($this->header->summary)) {
Expand All @@ -501,11 +504,12 @@ public function summary($size = null)

// Set up variables to process summary from page or from custom summary
if ($this->summary === null) {
$content = $this->content();
$content = $textOnly ? strip_tags($this->content()) : $this->content();
$summary_size = $this->summary_size;
} else {
$content = $this->summary;
$summary_size = mb_strlen($this->summary);
$content = strip_tags($this->summary);
// Use mb_strwidth to deal with the 2 character widths characters
$summary_size = mb_strwidth($content, 'utf-8');
}

// Return calculated summary based on summary divider's position
Expand All @@ -514,7 +518,12 @@ public function summary($size = null)
if (!in_array($format, ['short', 'long'])) {
return $content;
} elseif (($format === 'short') && isset($summary_size)) {
return mb_substr($content, 0, $summary_size);
// Use mb_strimwidth to slice the string
if (mb_strwidth($content, 'utf8') > $summary_size) {
return mb_strimwidth($content, 0, $summary_size);
} else {
return $content;
}
}

// Get summary size from site config's file
Expand All @@ -530,6 +539,15 @@ public function summary($size = null)
$size = 300;
}

// Only return string but not html, wrap whatever html tag you want when using
if ($textOnly) {
if (mb_strwidth($content, 'utf-8') <= $size) {
return $content;
}

return mb_strimwidth($content, 0, $size, '...', 'utf-8');
}

$summary = Utils::truncateHTML($content, $size);

return html_entity_decode($summary);
Expand Down Expand Up @@ -590,7 +608,7 @@ public function content($var = null)


$process_markdown = $this->shouldProcess('markdown');
$process_twig = $this->shouldProcess('twig') || $this->modularTwig() ;
$process_twig = $this->shouldProcess('twig') || $this->modularTwig();

$cache_enable = isset($this->header->cache_enable) ? $this->header->cache_enable : $config->get('system.cache.enabled',
true);
Expand Down Expand Up @@ -801,7 +819,7 @@ public function setRawContent($content)
* Get value from a page variable (used mostly for creating edit forms).
*
* @param string $name Variable name.
* @param mixed $default
* @param mixed $default
*
* @return mixed
*/
Expand Down Expand Up @@ -1078,7 +1096,7 @@ public function extra()
public function toArray()
{
return [
'header' => (array)$this->header(),
'header' => (array)$this->header(),
'content' => (string)$this->value('content')
];
}
Expand Down Expand Up @@ -1486,9 +1504,9 @@ public function metadata($var = null)
foreach ($value as $property => $prop_value) {
$prop_key = $key . ":" . $property;
$this->metadata[$prop_key] = [
'name' => $prop_key,
'name' => $prop_key,
'property' => $prop_key,
'content' => htmlspecialchars($prop_value, ENT_QUOTES, 'UTF-8')
'content' => htmlspecialchars($prop_value, ENT_QUOTES, 'UTF-8')
];
}
} else {
Expand All @@ -1497,15 +1515,18 @@ public function metadata($var = null)
if (in_array($key, $header_tag_http_equivs)) {
$this->metadata[$key] = [
'http_equiv' => $key,
'content' => htmlspecialchars($value, ENT_QUOTES, 'UTF-8')
'content' => htmlspecialchars($value, ENT_QUOTES, 'UTF-8')
];
} elseif ($key == 'charset') {
$this->metadata[$key] = ['charset' => htmlspecialchars($value, ENT_QUOTES, 'UTF-8')];
} else {
// if it's a social metadata with separator, render as property
$separator = strpos($key, ':');
$hasSeparator = $separator && $separator < strlen($key) - 1;
$entry = ['name' => $key, 'content' => htmlspecialchars($value, ENT_QUOTES, 'UTF-8')];
$entry = [
'name' => $key,
'content' => htmlspecialchars($value, ENT_QUOTES, 'UTF-8')
];

if ($hasSeparator) {
$entry['property'] = $key;
Expand Down Expand Up @@ -1589,6 +1610,7 @@ public function permalink()
* Returns the canonical URL for a page
*
* @param bool $include_lang
*
* @return string
*/
public function canonical($include_lang = true)
Expand All @@ -1603,6 +1625,7 @@ public function canonical($include_lang = true)
* @param bool $canonical true to return the canonical URL
* @param bool $include_lang
* @param bool $raw_route
*
* @return string The url.
*/
public function url($include_host = false, $canonical = false, $include_lang = true, $raw_route = false)
Expand Down Expand Up @@ -2327,7 +2350,7 @@ public function root()
* Helper method to return an ancestor page.
*
* @param string $url The url of the page
* @param bool $lookup Name of the parent folder
* @param bool $lookup Name of the parent folder
*
* @return \Grav\Common\Page\Page page you were looking for if it exists
*/
Expand All @@ -2343,7 +2366,7 @@ public function ancestor($lookup = null)
* Helper method to return an ancestor page to inherit from. The current
* page object is returned.
*
* @param string $field Name of the parent folder
* @param string $field Name of the parent folder
*
* @return Page
*/
Expand All @@ -2355,11 +2378,12 @@ public function inherited($field)

return $inherited;
}

/**
* Helper method to return an ancestor field only to inherit from. The
* first occurrence of an ancestor field will be returned if at all.
*
* @param string $field Name of the parent folder
* @param string $field Name of the parent folder
*
* @return array
*/
Expand All @@ -2373,7 +2397,7 @@ public function inheritedField($field)
/**
* Method that contains shared logic for inherited() and inheritedField()
*
* @param string $field Name of the parent folder
* @param string $field Name of the parent folder
*
* @return array
*/
Expand All @@ -2383,19 +2407,20 @@ protected function getInheritedParams($field)

/** @var Pages $pages */
$inherited = $pages->inherited($this->route, $field);
$inheritedParams = (array) $inherited->value('header.' . $field);
$currentParams = (array) $this->value('header.' . $field);
if($inheritedParams && is_array($inheritedParams)) {
$inheritedParams = (array)$inherited->value('header.' . $field);
$currentParams = (array)$this->value('header.' . $field);
if ($inheritedParams && is_array($inheritedParams)) {
$currentParams = array_replace_recursive($inheritedParams, $currentParams);
}

return [$inherited, $currentParams];
}

/**
* Helper method to return a page.
*
* @param string $url the url of the page
* @param bool $all
* @param bool $all
*
* @return \Grav\Common\Page\Page page you were looking for if it exists
*/
Expand All @@ -2411,7 +2436,7 @@ public function find($url, $all = false)
* Get a collection of pages in the current context.
*
* @param string|array $params
* @param boolean $pagination
* @param boolean $pagination
*
* @return Collection
* @throws \InvalidArgumentException
Expand Down Expand Up @@ -2747,7 +2772,7 @@ protected function doReorder($new_order)

// Reorder all moved pages.
foreach ($siblings as $slug => $page) {
$order = intval(trim($page->order(),'.'));
$order = intval(trim($page->order(), '.'));
$counter++;

if ($order) {
Expand Down
Loading

0 comments on commit 0644eac

Please sign in to comment.