diff --git a/CHANGELOG.md b/CHANGELOG.md index fb68689467..1efc2e58b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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) diff --git a/system/src/Grav/Common/Filesystem/Folder.php b/system/src/Grav/Common/Filesystem/Folder.php index 7d239018d2..df9dec045d 100644 --- a/system/src/Grav/Common/Filesystem/Folder.php +++ b/system/src/Grav/Common/Filesystem/Folder.php @@ -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; } /** diff --git a/system/src/Grav/Common/Page/Medium/ImageMedium.php b/system/src/Grav/Common/Page/Medium/ImageMedium.php index 9b0632c136..732df70deb 100644 --- a/system/src/Grav/Common/Page/Medium/ImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ImageMedium.php @@ -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(), '/'); } /** diff --git a/system/src/Grav/Common/Page/Medium/Medium.php b/system/src/Grav/Common/Page/Medium/Medium.php index 77396d6959..d6f1475100 100644 --- a/system/src/Grav/Common/Page/Medium/Medium.php +++ b/system/src/Grav/Common/Page/Medium/Medium.php @@ -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(), '/'); } /** diff --git a/system/src/Grav/Common/Page/Medium/MediumFactory.php b/system/src/Grav/Common/Page/Medium/MediumFactory.php index 2f1a72b0fc..9c6a0a536c 100644 --- a/system/src/Grav/Common/Page/Medium/MediumFactory.php +++ b/system/src/Grav/Common/Page/Medium/MediumFactory.php @@ -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']; diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index a3fc3dc5e1..c177a6a843 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -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']; @@ -192,6 +195,10 @@ public function translatedLanguages() $route = $aPage->slug(); } + if ($onlyPublished && !$aPage->published()) { + continue; + } + $translatedLanguages[$language] = $route; } } @@ -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']; @@ -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; } } diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index 8ceddd366b..6c88981039 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -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; + } }