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 May 22, 2017
2 parents 9d918ad + d40cb3c commit 78cb767
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 14 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
* Added `Grav\Framework\Page` interfaces
* Deprecated GravTrait

# v1.3.0-rc.3
## 05/xx/2017

1. [](#new)
* Added `Utils::getPagePathFromToken()` method which is shared in Admin, Forms, etc.
1. [](#improved)
* Optionally remove unpublished pages from the translated languages, move into untranslated list [#1482](https://github.com/getgrav/grav/pull/1482)
* Improved reliability of `hash` filecheck method
1. [](#bugfix)
* Fix output handling in RenderProcessor [#1483](https://github.com/getgrav/grav/pull/1483)

# v1.3.0-rc.2
## 05/17/2017

Expand Down Expand Up @@ -47,7 +58,7 @@
## 04/24/2017

1. [](#improved)
* Added optional ignores for `Installer::sophisticatedInstall()` [#1447](https://github.com/getgrav/grav/issues/1447)
* Added optional ignores for `Installer::sophisticatedInstall()` [#1447](https://github.com/getgrav/grav/issues/1447)
1. [](#bugfix)
* Allow multiple calls to `Themes::initTheme()` without throwing errors
* Fixed querystrings in root pages with multi-lang enabled [#1436](https://github.com/getgrav/grav/issues/1436)
Expand Down
7 changes: 4 additions & 3 deletions system/src/Grav/Common/Filesystem/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ public static function hashAllFiles($path)

$iterator = new \RecursiveIteratorIterator($directory, \RecursiveIteratorIterator::SELF_FIRST);

foreach ($iterator as $filepath => $file) {
$files[] = $file->getPath() . $file->getMTime();
foreach ($iterator as $file) {
$files[] = $file->getPathname() . '?'. $file->getMTime();
}

return md5(serialize($files));
$hash = md5(serialize($files));
return $hash;
}

/**
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 @@ -166,7 +166,7 @@ public function url($reset = true)
$this->reset();
}

return Grav::instance()['base_url'] . $output . $this->querystring() . $this->urlHash();
return Grav::instance()['base_url'] . '/' . ltrim($output . $this->querystring() . $this->urlHash(), '/');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/src/Grav/Common/Page/Medium/Medium.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function url($reset = true)
$this->reset();
}

return Grav::instance()['base_url'] . $output . $this->querystring() . $this->urlHash();
return Grav::instance()['base_url'] . '/' . ltrim($output . $this->querystring() . $this->urlHash(), '/');
}

/**
Expand Down
10 changes: 5 additions & 5 deletions system/src/Grav/Common/Page/Medium/MediumFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public static function fromFile($file, array $params = [])
return null;
}

$path = dirname($file);
$filename = basename($file);
$parts = explode('.', $filename);
$ext = array_pop($parts);
$basename = implode('.', $parts);
$parts = pathinfo($file);
$path = $parts['dirname'];
$filename = $parts['basename'];
$ext = $parts['extension'];
$basename = $parts['filename'];

$config = Grav::instance()['config'];

Expand Down
22 changes: 19 additions & 3 deletions system/src/Grav/Common/Page/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,12 @@ protected function processFrontmatter()

/**
* Return an array with the routes of other translated languages
*
* @param bool $onlyPublished only return published translations
*
* @return array the page translated languages
*/
public function translatedLanguages()
public function translatedLanguages($onlyPublished = false)
{
$filename = substr($this->name, 0, -(strlen($this->extension())));
$config = Grav::instance()['config'];
Expand All @@ -192,6 +195,10 @@ public function translatedLanguages()
$route = $aPage->slug();
}

if ($onlyPublished && !$aPage->published()) {
continue;
}

$translatedLanguages[$language] = $route;
}
}
Expand All @@ -201,9 +208,12 @@ public function translatedLanguages()

/**
* Return an array listing untranslated languages available
*
* @param bool $includeUnpublished also list unpublished translations
*
* @return array the page untranslated languages
*/
public function untranslatedLanguages()
public function untranslatedLanguages($includeUnpublished = false)
{
$filename = substr($this->name, 0, -(strlen($this->extension())));
$config = Grav::instance()['config'];
Expand All @@ -212,7 +222,13 @@ public function untranslatedLanguages()

foreach ($languages as $language) {
$path = $this->path . DS . $this->folder . DS . $filename . '.' . $language . '.md';
if (!file_exists($path)) {
if (file_exists($path)) {
$aPage = new Page();
$aPage->init(new \SplFileInfo($path), $language . '.md');
if ($includeUnpublished && !$aPage->published()) {
$untranslatedLanguages[] = $language;
}
} else {
$untranslatedLanguages[] = $language;
}
}
Expand Down
52 changes: 52 additions & 0 deletions system/src/Grav/Common/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -851,4 +851,56 @@ public static function isWindows() {
public static function isApache() {
return strpos($_SERVER["SERVER_SOFTWARE"], 'Apache') !== false;
}

/**
* Get's path based on a token
*
* @param $path
* @param null $page
* @return string
*/
public static function getPagePathFromToken($path, $page = null)
{
$path_parts = pathinfo($path);
$grav = Grav::instance();

$basename = '';
if (isset($path_parts['extension'])) {
$basename = '/' . $path_parts['basename'];
$path = rtrim($path_parts['dirname'], ':');
}

$regex = '/(@self|self@)|((?:@page|page@):(?:.*))|((?:@theme|theme@):(?:.*))/';
preg_match($regex, $path, $matches);

if ($matches) {
if ($matches[1]) {
if (is_null($page)) {
throw new \RuntimeException('Page not available for this self@ reference');
}
} elseif ($matches[2]) {
// page@
$parts = explode(':', $path);
$route = $parts[1];
$page = $grav['page']->find($route);
} elseif ($matches[3]) {
// theme@
$parts = explode(':', $path);
$route = $parts[1];
$theme = str_replace(ROOT_DIR, '', $grav['locator']->findResource("theme://"));

return $theme . $route . $basename;
}
} else {
return $path . $basename;
}

if (!$page) {
throw new \RuntimeException('Page route not found: ' . $path);
}

$path = str_replace($matches[0], rtrim($page->relativePagePath(), '/'), $path);

return $path . $basename;
}
}

0 comments on commit 78cb767

Please sign in to comment.