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
  • Loading branch information
mahagr committed Oct 18, 2017
2 parents 731fe50 + 2842b8f commit 98dca95
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 79 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
1. [](#improved)
* Make it possible to include debug bar also into non-HTML responses

# v1.3.7
## mm/dd/2017

1. [](#bugfix)
* Regressionin Uri: `base_url_absolute` always has the port number (#1690)
* Uri: Prefer using REQUEST_SCHEME instead of HTTPS (#1698)
* Fixed routing paths with urlencoded spaces and non-latin letters (#1688)

# v1.3.6
## 10/12/2017

Expand Down
97 changes: 49 additions & 48 deletions system/src/Grav/Common/Page/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function init(\SplFileInfo $file, $extension = null)
$this->metadata();
$this->url();
$this->visible();
$this->modularTwig($this->slug[0] == '_');
$this->modularTwig($this->slug[0] === '_');
$this->setPublishState();
$this->published();
$this->urlExtension();
Expand Down Expand Up @@ -517,25 +517,27 @@ public function summary($size = null, $textOnly = false)
// Return entire page content on wrong/ unknown format
if (!in_array($format, ['short', 'long'])) {
return $content;
} elseif (($format === 'short') && isset($summary_size)) {
}
if (($format === 'short') && isset($summary_size)) {
// Use mb_strimwidth to slice the string
if (mb_strwidth($content, 'utf8') > $summary_size) {
return mb_substr($content, 0, $summary_size);
} else {
return $content;
}

return $content;
}

// Get summary size from site config's file
if (is_null($size)) {
if ($size === null) {
$size = $config['size'];
}

// If the size is zero, return the entire page content
if ($size === 0) {
return $content;
// Return calculated summary based on defaults
} elseif (!is_numeric($size) || ($size < 0)) {
}
if (!is_numeric($size) || ($size < 0)) {
$size = 300;
}

Expand Down Expand Up @@ -726,10 +728,9 @@ public function getContentMeta($name = null)
if ($name) {
if (isset($this->content_meta[$name])) {
return $this->content_meta[$name];
} else {
return null;
}

return null;
}

return $this->content_meta;
Expand Down Expand Up @@ -825,27 +826,27 @@ public function setRawContent($content)
*/
public function value($name, $default = null)
{
if ($name == 'content') {
if ($name === 'content') {
return $this->raw_content;
}
if ($name == 'route') {
if ($name === 'route') {
return $this->parent()->rawRoute();
}
if ($name == 'order') {
if ($name === 'order') {
$order = $this->order();

return $order ? (int)$this->order() : '';
}
if ($name == 'ordering') {
if ($name === 'ordering') {
return (bool)$this->order();
}
if ($name == 'folder') {
if ($name === 'folder') {
return preg_replace(PAGE_ORDER_PREFIX_REGEX, '', $this->folder);
}
if ($name == 'slug') {
if ($name === 'slug') {
return $this->slug();
}
if ($name == 'name') {
if ($name === 'name') {
$language = $this->language() ? '.' . $this->language() : '';
$name_val = str_replace($language . '.md', '', $this->name());
if ($this->modular()) {
Expand All @@ -854,30 +855,30 @@ public function value($name, $default = null)

return $name_val;
}
if ($name == 'media') {
if ($name === 'media') {
return $this->media()->all();
}
if ($name == 'media.file') {
if ($name === 'media.file') {
return $this->media()->files();
}
if ($name == 'media.video') {
if ($name === 'media.video') {
return $this->media()->videos();
}
if ($name == 'media.image') {
if ($name === 'media.image') {
return $this->media()->images();
}
if ($name == 'media.audio') {
if ($name === 'media.audio') {
return $this->media()->audios();
}

$path = explode('.', $name);
$scope = array_shift($path);

if ($name == 'frontmatter') {
if ($name === 'frontmatter') {
return $this->frontmatter;
}

if ($scope == 'header') {
if ($scope === 'header') {
$current = $this->header();
foreach ($path as $field) {
if (is_object($current) && isset($current->{$field})) {
Expand Down Expand Up @@ -969,7 +970,7 @@ public function move(Page $parent)

$this->_action = 'move';

if ($this->route() == $parent->route()) {
if ($this->route() === $parent->route()) {
throw new Exception('Failed: Cannot set page parent to self');
}
if (Utils::startsWith($parent->rawRoute(), $this->rawRoute())) {
Expand Down Expand Up @@ -1029,12 +1030,12 @@ public function blueprints()
$edit_mode = isset($grav['admin']) ? $grav['config']->get('plugins.admin.edit_mode') : null;

// override if you only want 'normal' mode
if (empty($fields) && ($edit_mode == 'auto' || $edit_mode == 'normal')) {
if (empty($fields) && ($edit_mode === 'auto' || $edit_mode === 'normal')) {
$blueprint = $pages->blueprints('default');
}

// override if you only want 'expert' mode
if (!empty($fields) && $edit_mode == 'expert') {
if (!empty($fields) && $edit_mode === 'expert') {
$blueprint = $pages->blueprints('');
}

Expand Down Expand Up @@ -1459,9 +1460,9 @@ public function debugger()
{
if (isset($this->debugger) && $this->debugger === false) {
return false;
} else {
return true;
}

return true;
}

/**
Expand Down Expand Up @@ -1502,7 +1503,7 @@ public function metadata($var = null)
// Backward compatibility for nested arrays in metas
if (is_array($value)) {
foreach ($value as $property => $prop_value) {
$prop_key = $key . ":" . $property;
$prop_key = $key . ':' . $property;
$this->metadata[$prop_key] = [
'name' => $prop_key,
'property' => $prop_key,
Expand All @@ -1517,7 +1518,7 @@ public function metadata($var = null)
'http_equiv' => $key,
'content' => htmlspecialchars($value, ENT_QUOTES, 'UTF-8')
];
} elseif ($key == 'charset') {
} 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
Expand Down Expand Up @@ -1552,7 +1553,7 @@ public function metadata($var = null)
*/
public function slug($var = null)
{
if ($var !== null && $var !== "") {
if ($var !== null && $var !== '') {
$this->slug = $var;
}

Expand Down Expand Up @@ -1679,7 +1680,7 @@ public function url($include_host = false, $canonical = false, $include_lang = t
$url = rtrim($url, '/');
}

return $url;
return Uri::filterPath($url);
}

/**
Expand All @@ -1702,7 +1703,7 @@ public function route($var = null)
// calculate route based on parent slugs
$parent = $this->parent();
if (isset($parent)) {
if ($this->hide_home_route && $parent->route() == $this->home_route) {
if ($this->hide_home_route && $parent->route() === $this->home_route) {
$baseRoute = '';
} else {
$baseRoute = (string)$parent->route();
Expand Down Expand Up @@ -1770,9 +1771,9 @@ public function routeAliases($var = null)

if (!empty($this->routes) && isset($this->routes['aliases'])) {
return $this->routes['aliases'];
} else {
return [];
}

return [];
}

/**
Expand Down Expand Up @@ -2298,7 +2299,7 @@ public function active()
$routes = Grav::instance()['pages']->routes();

if (isset($routes[$uri_path])) {
if ($routes[$uri_path] == $this->path()) {
if ($routes[$uri_path] === $this->path()) {
return true;
}

Expand All @@ -2325,7 +2326,7 @@ public function activeChild()
$child_page = $pages->dispatch($uri->route())->parent();
if ($child_page) {
while (!$child_page->root()) {
if ($this->path() == $child_page->path()) {
if ($this->path() === $child_page->path()) {
return true;
}
$child_page = $child_page->parent();
Expand All @@ -2344,7 +2345,7 @@ public function activeChild()
public function home()
{
$home = Grav::instance()['config']->get('system.home.alias');
$is_home = ($this->route() == $home || $this->rawRoute() == $home);
$is_home = ($this->route() === $home || $this->rawRoute() === $home);

return $is_home;
}
Expand All @@ -2358,9 +2359,9 @@ public function root()
{
if (!$this->parent && !$this->name && !$this->visible) {
return true;
} else {
return false;
}

return false;
}

/**
Expand Down Expand Up @@ -2587,7 +2588,7 @@ public function collection($params = 'content', $pagination = true)
}

/**
* @param string $value
* @param string|array $value
*
* @return mixed
* @internal
Expand All @@ -2605,7 +2606,7 @@ public function evaluate($value)
$params = (array)current($value);
} else {
$result = [];
foreach ($value as $key => $val) {
foreach ((array)$value as $key => $val) {
if (is_int($key)) {
$result = $result + $this->evaluate($val)->toArray();
} else {
Expand Down Expand Up @@ -2711,7 +2712,7 @@ public function evaluate($value)

case 'root@':
case '@root':
if (!empty($parts) && $parts[0] == 'descendants') {
if (!empty($parts) && $parts[0] === 'descendants') {
$results = $pages->all($pages->root())->nonModular()->published();
} else {
$results = $pages->root()->children()->nonModular()->published();
Expand Down Expand Up @@ -2824,11 +2825,11 @@ protected function doReorder($new_order)

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

if ($order) {
if ($page->path() == $this->path() && $this->folderExists()) {
if ($page->path() === $this->path() && $this->folderExists()) {
// Handle current page; we do want to change ordering number, but nothing else.
$this->order($counter);
$this->save(false);
Expand Down Expand Up @@ -2859,14 +2860,14 @@ protected function doRelocation()
}

if (is_dir($this->_original->path())) {
if ($this->_action == 'move') {
if ($this->_action === 'move') {
Folder::move($this->_original->path(), $this->path());
} elseif ($this->_action == 'copy') {
} elseif ($this->_action === 'copy') {
Folder::copy($this->_original->path(), $this->path());
}
}

if ($this->name() != $this->_original->name()) {
if ($this->name() !== $this->_original->name()) {
$path = $this->path();
if (is_file($path . '/' . $this->_original->name())) {
rename($path . '/' . $this->_original->name(), $path . '/' . $this->name());
Expand All @@ -2889,7 +2890,7 @@ protected function setPublishState()
}
}
// publish if required, if not clear cache right before page is published
if ($this->publishDate() && $this->publishDate() && $this->publishDate() > time()) {
if ($this->publishDate() && $this->publishDate() > time()) {
$this->published(false);
Grav::instance()['cache']->setLifeTime($this->publishDate());
}
Expand Down
Loading

0 comments on commit 98dca95

Please sign in to comment.