From 73654a99f963fb9a01ff80b2f2f6c8772b4b0c67 Mon Sep 17 00:00:00 2001 From: Gert Date: Mon, 11 May 2015 11:43:23 +0200 Subject: [PATCH 01/29] fix for alternative media resolutions --- system/src/Grav/Common/Page/Media.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Media.php b/system/src/Grav/Common/Page/Media.php index d73064618..1b7ac2f0b 100644 --- a/system/src/Grav/Common/Page/Media.php +++ b/system/src/Grav/Common/Page/Media.php @@ -120,7 +120,7 @@ class Media extends Getters } foreach ($types['alternative'] as $ratio => $altMedium) { - $medium->addAlternative($ratio, $altMedium); + $medium->addAlternative($ratio, $altMedium['file']); } } From aa85f20aa9aa0ca148092540f55d8bd081c71b74 Mon Sep 17 00:00:00 2001 From: Gert Date: Wed, 13 May 2015 18:50:13 +0200 Subject: [PATCH 02/29] fix modularTypes key properties --- system/src/Grav/Common/Page/Types.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Types.php b/system/src/Grav/Common/Page/Types.php index 69f61e597..418faba9c 100644 --- a/system/src/Grav/Common/Page/Types.php +++ b/system/src/Grav/Common/Page/Types.php @@ -78,7 +78,7 @@ class Types implements \ArrayAccess, \Iterator, \Countable if (strpos($name, 'modular/') !== 0) { continue; } - $list[$name] = trim(ucfirst(strtr(basename($name), '_', ' '))); + $list[basename($name)] = trim(ucfirst(strtr(basename($name), '_', ' '))); } ksort($list); return $list; From 9382dc9c1032ad0d620e655cfc698151a63ee05c Mon Sep 17 00:00:00 2001 From: Gert Date: Wed, 13 May 2015 18:52:13 +0200 Subject: [PATCH 03/29] add method to set raw markdown on page --- system/src/Grav/Common/Page/Page.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 1d8a80241..7037dfe40 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -361,7 +361,6 @@ class Page $this->id(time().md5($this->filePath())); $this->content = null; } - // If no content, process it if ($this->content === null) { // Get media @@ -568,6 +567,15 @@ class Page return $default; } + public function rawMarkdown($var = null) + { + if ($var !== null) { + $this->raw_content = $var; + } + + return $this->raw_content; + } + /** * Get file object to the page. * From e0a4efe18197e952d15636ada2b1ca01fcd3d259 Mon Sep 17 00:00:00 2001 From: Marcel Eschmann Date: Thu, 14 May 2015 21:10:05 +0200 Subject: [PATCH 04/29] Use global composer install when available --- system/src/Grav/Console/ConsoleTrait.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Console/ConsoleTrait.php b/system/src/Grav/Console/ConsoleTrait.php index a2e80b6e8..e848b2260 100644 --- a/system/src/Grav/Console/ConsoleTrait.php +++ b/system/src/Grav/Console/ConsoleTrait.php @@ -85,7 +85,12 @@ trait ConsoleTrait public function composerUpdate($path, $action = 'install') { - return system('php bin/composer.phar --working-dir="'.$path.'" --no-interaction --no-dev --prefer-dist -o '. $action); + $composer = shell_exec("which composer"); + if (!$composer || !preg_match('/(composer|composer\.phar)$/', $composer)) { + $composer = "bin/composer.phar"; + } + + return system('php '.$composer.' --working-dir="'.$path.'" --no-interaction --no-dev --prefer-dist -o '. $action); } /** From 1f906e6a50b1d8b2220a64cfb117a80231a5ebe7 Mon Sep 17 00:00:00 2001 From: Marcel Eschmann Date: Thu, 14 May 2015 21:37:47 +0200 Subject: [PATCH 05/29] Propagate composer check to all occurences --- bin/gpm | 5 +++- bin/grav | 5 +++- system/src/Grav/Common/Composer.php | 30 ++++++++++++++++++++++++ system/src/Grav/Console/ConsoleTrait.php | 7 ++---- 4 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 system/src/Grav/Common/Composer.php diff --git a/bin/gpm b/bin/gpm index a19fea5d1..1e3376b6b 100755 --- a/bin/gpm +++ b/bin/gpm @@ -6,10 +6,13 @@ if (version_compare($ver = PHP_VERSION, $req = '5.4.0', '<')) { exit(sprintf("You are running PHP %s, but Grav needs at least PHP %s to run.\n", $ver, $req)); } +use Grav\Common\Composer; + if (!file_exists(__DIR__ . '/../vendor')){ // Before we can even start, we need to run composer first + $composer = Composer::getComposerLocation(); echo "Preparing to install vendor dependencies...\n\n"; - echo system('php bin/composer.phar --working-dir="'.__DIR__.'/../" --no-interaction --no-dev --prefer-dist -o install'); + echo system('php '.$composer.' --working-dir="'.__DIR__.'/../" --no-interaction --no-dev --prefer-dist -o install'); echo "\n\n"; } diff --git a/bin/grav b/bin/grav index 1d31dd687..dc839c328 100755 --- a/bin/grav +++ b/bin/grav @@ -6,10 +6,13 @@ if (version_compare($ver = PHP_VERSION, $req = '5.4.0', '<')) { exit(sprintf("You are running PHP %s, but Grav needs at least PHP %s to run.\n", $ver, $req)); } +use Grav\Common\Composer; + if (!file_exists(__DIR__ . '/../vendor')){ // Before we can even start, we need to run composer first + $composer = Composer::getComposerLocation(); echo "Preparing to install vendor dependencies...\n\n"; - echo system('php bin/composer.phar --working-dir="'.__DIR__.'/../" --no-interaction --no-dev --prefer-dist -o install'); + echo system('php '.$composer.' --working-dir="'.__DIR__.'/../" --no-interaction --no-dev --prefer-dist -o install'); echo "\n\n"; } diff --git a/system/src/Grav/Common/Composer.php b/system/src/Grav/Common/Composer.php new file mode 100644 index 000000000..947b66313 --- /dev/null +++ b/system/src/Grav/Common/Composer.php @@ -0,0 +1,30 @@ + Date: Thu, 14 May 2015 23:32:16 +0200 Subject: [PATCH 06/29] Fix line break in command --- system/src/Grav/Common/Composer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Composer.php b/system/src/Grav/Common/Composer.php index 947b66313..991983d58 100644 --- a/system/src/Grav/Common/Composer.php +++ b/system/src/Grav/Common/Composer.php @@ -18,7 +18,7 @@ class Composer public static function getComposerLocation() { // check for global composer install - $path = shell_exec("which composer"); + $path = trim(shell_exec("which composer")); // fall back to grav bundled composer if (!$path || !preg_match('/(composer|composer\.phar)$/', $path)) { From c0855401435005b7c50fe296626004a33bf11013 Mon Sep 17 00:00:00 2001 From: Marcel Eschmann Date: Thu, 14 May 2015 23:56:55 +0200 Subject: [PATCH 07/29] Improve composer location identification --- system/src/Grav/Common/Composer.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Composer.php b/system/src/Grav/Common/Composer.php index 991983d58..d0e181c70 100644 --- a/system/src/Grav/Common/Composer.php +++ b/system/src/Grav/Common/Composer.php @@ -17,8 +17,12 @@ class Composer */ public static function getComposerLocation() { + if (!function_exists('shell_exec')) { + return "bin/composer.phar"; + } + // check for global composer install - $path = trim(shell_exec("which composer")); + $path = trim(shell_exec("command -v composer")); // fall back to grav bundled composer if (!$path || !preg_match('/(composer|composer\.phar)$/', $path)) { From 3c51c0acd45aaa6bad96a68d67e7f501b406e82e Mon Sep 17 00:00:00 2001 From: Marcel Eschmann Date: Fri, 15 May 2015 00:03:48 +0200 Subject: [PATCH 08/29] Move default location to class constant --- system/src/Grav/Common/Composer.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Composer.php b/system/src/Grav/Common/Composer.php index d0e181c70..b6b23cc57 100644 --- a/system/src/Grav/Common/Composer.php +++ b/system/src/Grav/Common/Composer.php @@ -10,6 +10,9 @@ namespace Grav\Common; */ class Composer { + /** @const Default composer location */ + const DEFAULT_PATH = "bin/composer.phar"; + /** * Returns the location of composer. * @@ -18,7 +21,7 @@ class Composer public static function getComposerLocation() { if (!function_exists('shell_exec')) { - return "bin/composer.phar"; + return self::DEFAULT_PATH; } // check for global composer install @@ -26,7 +29,7 @@ class Composer // fall back to grav bundled composer if (!$path || !preg_match('/(composer|composer\.phar)$/', $path)) { - $path = "bin/composer.phar"; + $path = self::DEFAULT_PATH; } return $path; From d8df9ffb53999b362e6dab7dc5d1163412bd1822 Mon Sep 17 00:00:00 2001 From: Marcel Eschmann Date: Fri, 15 May 2015 00:20:08 +0200 Subject: [PATCH 09/29] Remove unnecessary white space --- system/src/Grav/Common/Composer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Composer.php b/system/src/Grav/Common/Composer.php index b6b23cc57..25bf8fc0c 100644 --- a/system/src/Grav/Common/Composer.php +++ b/system/src/Grav/Common/Composer.php @@ -29,7 +29,7 @@ class Composer // fall back to grav bundled composer if (!$path || !preg_match('/(composer|composer\.phar)$/', $path)) { - $path = self::DEFAULT_PATH; + $path = self::DEFAULT_PATH; } return $path; From e883b57ac6de6c4d86fa94c145a9f70ebc6ab5dd Mon Sep 17 00:00:00 2001 From: Gert Date: Fri, 15 May 2015 19:54:33 +0200 Subject: [PATCH 10/29] fix composer execution for various scenarios --- bin/gpm | 8 ++++++-- bin/grav | 8 ++++++-- system/src/Grav/Common/Composer.php | 20 +++++++++++++++++++- system/src/Grav/Console/ConsoleTrait.php | 5 +++-- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/bin/gpm b/bin/gpm index 1e3376b6b..5a039e597 100755 --- a/bin/gpm +++ b/bin/gpm @@ -6,13 +6,17 @@ if (version_compare($ver = PHP_VERSION, $req = '5.4.0', '<')) { exit(sprintf("You are running PHP %s, but Grav needs at least PHP %s to run.\n", $ver, $req)); } +if (!file_exists(__DIR__ . '/../vendor')){ + require_once __DIR__ . '/../system/src/Grav/Common/Composer.php'; +} + use Grav\Common\Composer; if (!file_exists(__DIR__ . '/../vendor')){ // Before we can even start, we need to run composer first - $composer = Composer::getComposerLocation(); + $composer = Composer::getComposerExecutor(); echo "Preparing to install vendor dependencies...\n\n"; - echo system('php '.$composer.' --working-dir="'.__DIR__.'/../" --no-interaction --no-dev --prefer-dist -o install'); + echo system($composer.' --working-dir="'.__DIR__.'/../" --no-interaction --no-dev --prefer-dist -o install'); echo "\n\n"; } diff --git a/bin/grav b/bin/grav index dc839c328..fb101b78f 100755 --- a/bin/grav +++ b/bin/grav @@ -6,13 +6,17 @@ if (version_compare($ver = PHP_VERSION, $req = '5.4.0', '<')) { exit(sprintf("You are running PHP %s, but Grav needs at least PHP %s to run.\n", $ver, $req)); } +if (!file_exists(__DIR__ . '/../vendor')){ + require_once __DIR__ . '/../system/src/Grav/Common/Composer.php'; +} + use Grav\Common\Composer; if (!file_exists(__DIR__ . '/../vendor')){ // Before we can even start, we need to run composer first - $composer = Composer::getComposerLocation(); + $composer = Composer::getComposerExecutor(); echo "Preparing to install vendor dependencies...\n\n"; - echo system('php '.$composer.' --working-dir="'.__DIR__.'/../" --no-interaction --no-dev --prefer-dist -o install'); + echo system($composer.' --working-dir="'.__DIR__.'/../" --no-interaction --no-dev --prefer-dist -o install'); echo "\n\n"; } diff --git a/system/src/Grav/Common/Composer.php b/system/src/Grav/Common/Composer.php index 25bf8fc0c..bda847eef 100644 --- a/system/src/Grav/Common/Composer.php +++ b/system/src/Grav/Common/Composer.php @@ -20,7 +20,7 @@ class Composer */ public static function getComposerLocation() { - if (!function_exists('shell_exec')) { + if (!function_exists('shell_exec') || strtolower(substr(PHP_OS, 0, 3)) === 'win') { return self::DEFAULT_PATH; } @@ -34,4 +34,22 @@ class Composer return $path; } + + public static function getComposerExecutor() + { + $executor = 'php '; + $composer = static::getComposerLocation(); + + if ($composer !== static::DEFAULT_PATH && is_executable($composer)) { + $file = fopen($composer, 'r'); + $firstLine = fgets($file); + fclose($file); + + if (!preg_match('/^#!.+php/i', $firstLine)) { + $executor = ''; + } + } + + return $executor . $composer; + } } diff --git a/system/src/Grav/Console/ConsoleTrait.php b/system/src/Grav/Console/ConsoleTrait.php index 45800b68d..233a5da79 100644 --- a/system/src/Grav/Console/ConsoleTrait.php +++ b/system/src/Grav/Console/ConsoleTrait.php @@ -86,8 +86,9 @@ trait ConsoleTrait public function composerUpdate($path, $action = 'install') { - $composer = Composer::getComposerLocation(); - return system('php '.$composer.' --working-dir="'.$path.'" --no-interaction --no-dev --prefer-dist -o '. $action); + $composer = Composer::getComposerExecutor(); + + return system($composer . ' --working-dir="'.$path.'" --no-interaction --no-dev --prefer-dist -o '. $action); } /** From 81bce07a6e9b64eda3d8c8af5225e02739759e2e Mon Sep 17 00:00:00 2001 From: Gert Date: Fri, 15 May 2015 20:16:42 +0200 Subject: [PATCH 11/29] use PHP_BINARY constant --- system/src/Grav/Common/Composer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Composer.php b/system/src/Grav/Common/Composer.php index bda847eef..5efde8912 100644 --- a/system/src/Grav/Common/Composer.php +++ b/system/src/Grav/Common/Composer.php @@ -37,7 +37,7 @@ class Composer public static function getComposerExecutor() { - $executor = 'php '; + $executor = PHP_BINARY . ' '; $composer = static::getComposerLocation(); if ($composer !== static::DEFAULT_PATH && is_executable($composer)) { From 3f1661965bf4004230f49ea0a1bc8c4f897c6a88 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 18 May 2015 18:54:08 +0200 Subject: [PATCH 12/29] Fix for issue #194 - query string handling --- system/src/Grav/Common/Uri.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index c4297bc20..f904d28bb 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -74,15 +74,27 @@ class Uri { $config = Grav::instance()['config']; + // resets + $this->paths = []; + $this->params = []; + $this->query = []; + + // get any params and remove them $uri = str_replace($this->root, '', $this->url); - // reset params - $this->params = []; - // process params $uri = $this->processParams($uri, $config->get('system.param_sep')); + // split the URL and params + $bits = parse_url($uri); + + // process query string + if (isset($bits['query'])) { + parse_str($bits['query'], $this->query); + $uri = $bits['path']; + } + // remove the extension if there is one set $parts = pathinfo($uri); @@ -96,19 +108,7 @@ class Uri // set the new url $this->url = $this->root . $uri; - - // split into bits - $this->bits = parse_url($uri); - - $this->query = array(); - if (isset($this->bits['query'])) { - parse_str($this->bits['query'], $this->query); - } - - $path = $this->bits['path']; - - $this->paths = array(); - $this->path = $path; + $this->path = $uri; $this->content_path = trim(str_replace($this->base, '', $this->path), '/'); if ($this->content_path != '') { $this->paths = explode('/', $this->content_path); From 1147516dcca93ece48dd7c32be319e3ea99b5026 Mon Sep 17 00:00:00 2001 From: Gert Date: Wed, 20 May 2015 16:07:39 +0200 Subject: [PATCH 13/29] fix for path detection on windows [fix #194] --- system/src/Grav/Common/Uri.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index f904d28bb..2b2da933a 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -102,7 +102,7 @@ class Uri $this->basename = $parts['basename']; if (preg_match("/\.(".$config->get('system.pages.types').")$/", $parts['basename'])) { - $uri = rtrim($parts['dirname'], '/').'/'.$parts['filename']; + $uri = rtrim(str_replace(DIRECTORY_SEPARATOR, DS, $parts['dirname']), DS). '/' .$parts['filename']; $this->extension = $parts['extension']; } From 7afef9073c85996c1b17723346f6f7ba6ab223d4 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 21 May 2015 22:44:11 +0200 Subject: [PATCH 14/29] fix for dot files --- system/src/Grav/Common/Page/Pages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index ac0e9e70f..b4d81daba 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -557,7 +557,7 @@ class Pages $last_modified = $modified; } - if (Utils::endsWith($name, CONTENT_EXT)) { + if (preg_match('/^[^.].*'.CONTENT_EXT.'$/um', $name)) { $page->init($file); $content_exists = true; From f779fc57df787583701dd8c8e02c3dc53c622fd7 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 22 May 2015 11:43:23 +0300 Subject: [PATCH 15/29] removed unneeded flags from reggae --- system/src/Grav/Common/Page/Pages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index b4d81daba..826618b70 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -557,7 +557,7 @@ class Pages $last_modified = $modified; } - if (preg_match('/^[^.].*'.CONTENT_EXT.'$/um', $name)) { + if (preg_match('/^[^.].*'.CONTENT_EXT.'$/', $name)) { $page->init($file); $content_exists = true; From 76b463792e9061da2b70e9bb6eb4b806ebe90598 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 26 May 2015 16:18:59 +0300 Subject: [PATCH 16/29] Fix for #196 - `+` in an image filename --- system/src/Grav/Common/Markdown/ParsedownGravTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index c265bf599..816cadfed 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -257,7 +257,7 @@ trait ParsedownGravTrait $page_path = $full_path; } else { // save the filename if a file is part of the path - $filename_regex = "/([\w\d-_]+\.([a-zA-Z]{2,4}))$/"; + $filename_regex = "/([\w\d-_\+]+\.([a-zA-Z]{2,4}))$/"; if (preg_match($filename_regex, $full_path, $matches)) { if ($matches[2] != 'md') { $filename = '/' . $matches[1]; From 32810efcd901d7405585f33f9daae297c8a41119 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 27 May 2015 14:55:50 +0200 Subject: [PATCH 17/29] optimization to image handling supporting url encoded filenames and removed a regex --- .../Common/Markdown/ParsedownGravTrait.php | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index 816cadfed..f2f3e0bd0 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -229,8 +229,8 @@ trait ParsedownGravTrait $target = null; // see if page is relative to this or absolute if (Utils::startsWith($markdown_url, '/')) { - $normalized_path = Utils::normalizePath($this->pages_dir . $markdown_url); $normalized_url = Utils::normalizePath($this->base_url . $markdown_url); + $normalized_path = Utils::normalizePath($this->pages_dir . $markdown_url); } else { $normalized_url = $this->base_url . Utils::normalizePath($this->page->route() . '/' . $markdown_url); $normalized_path = Utils::normalizePath($this->page->path() . '/' . $markdown_url); @@ -242,43 +242,43 @@ trait ParsedownGravTrait return $normalized_url; } - // if this file exits, get the page and work with that - if ($normalized_path) { - $url_bits = parse_url($normalized_path); - $full_path = $url_bits['path']; + $url_bits = parse_url($normalized_path); + $full_path = ($url_bits['path']); - if ($full_path && file_exists($full_path)) { - $path_info = pathinfo($full_path); - $page_path = $path_info['dirname']; - $filename = ''; + if (file_exists($full_path)) { + // do nothing + } elseif (file_exists(urldecode($full_path))) { + $full_path = urldecode($full_path); + } else { + return $normalized_url; + } + + $path_info = pathinfo($full_path); + $page_path = $path_info['dirname']; + $filename = ''; - if ($markdown_url == '..') { - $page_path = $full_path; - } else { - // save the filename if a file is part of the path - $filename_regex = "/([\w\d-_\+]+\.([a-zA-Z]{2,4}))$/"; - if (preg_match($filename_regex, $full_path, $matches)) { - if ($matches[2] != 'md') { - $filename = '/' . $matches[1]; - } - } else { - $page_path = $full_path; - } - } - - - - // get page instances and try to find one that fits - $instances = $this->pages->instances(); - if (isset($instances[$page_path])) { - $target = $instances[$page_path]; - $url_bits['path'] = $this->base_url . $target->route() . $filename; - return Uri::buildUrl($url_bits); + if ($markdown_url == '..') { + $page_path = $full_path; + } else { + // save the filename if a file is part of the path + if (is_file($full_path)) { + if ($path_info['extension'] != 'md') { + $filename = '/' . $path_info['basename']; } + } else { + $page_path = $full_path; } } + // get page instances and try to find one that fits + $instances = $this->pages->instances(); + if (isset($instances[$page_path])) { + $target = $instances[$page_path]; + $url_bits['path'] = $this->base_url . $target->route() . $filename; + return Uri::buildUrl($url_bits); + } + return $normalized_url; } } From 8127d9cf31079718affd603ed9555b296f86ec50 Mon Sep 17 00:00:00 2001 From: Seebz Date: Thu, 4 Jun 2015 16:46:18 +0200 Subject: [PATCH 18/29] Fix for issue #199 --- system/src/Grav/Common/Assets.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index 2d44912a8..3662f7d98 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -825,7 +825,8 @@ class Assets } else { // Fix to remove relative dir if grav is in one if (($this->base_url != '/') && (strpos($this->base_url, $link) == 0)) { - $relative_path = ltrim(preg_replace($this->base_url, '/', $link, 1), '/'); + $base_url = '#' . preg_quote($this->base_url, '#') . '#'; + $relative_path = ltrim(preg_replace($base_url, '/', $link, 1), '/'); } $relative_dir = dirname($relative_path); From 8ecea3a8c1a9ccb7b26c267016af258897d3f701 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 12 Jun 2015 15:54:20 -0600 Subject: [PATCH 19/29] some more fixes for image handling in certain scenarios --- .../src/Grav/Common/Markdown/ParsedownGravTrait.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index f2f3e0bd0..dd81c262d 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -133,10 +133,9 @@ trait ParsedownGravTrait // get the local path to page media if possible if ($path_parts['dirname'] == $this->page->url()) { - $url['path'] = ltrim(str_replace($this->page->url(), '', $url['path']), '/'); + $url['path'] = $path_parts['basename']; // get the media objects for this page $media = $this->page->media(); - } else { // see if this is an external page to this one $page_route = str_replace($this->base_url, '', $path_parts['dirname']); @@ -220,7 +219,14 @@ trait ParsedownGravTrait protected function convertUrl($markdown_url) { // if absolute and starts with a base_url move on - if ($this->base_url != '' && Utils::startsWith($markdown_url, $this->base_url)) { + if (pathinfo($markdown_url, PATHINFO_DIRNAME) == '.') { + if ($this->page->url() == '/') { + return '/' . $markdown_url; + } else { + return $this->page->url() . '/' . $markdown_url; + } + // no path to convert + } elseif ($this->base_url != '' && Utils::startsWith($markdown_url, $this->base_url)) { return $markdown_url; // if contains only a fragment } elseif (Utils::startsWith($markdown_url, '#')) { From 027c9cdd04acb325f95b472e456b032807f0e0a6 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 12 Jun 2015 22:32:23 -0600 Subject: [PATCH 20/29] updated to latest cache library - should be a little faster! --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b4422074b..24544e1e9 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "symfony/yaml": "~2.6", "symfony/console": "~2.6", "symfony/event-dispatcher": "~2.6", - "doctrine/cache": "~1.3", + "doctrine/cache": "~1.4", "maximebf/debugbar": "dev-master", "filp/whoops": "1.2.*@dev", "monolog/monolog": "~1.0", From bec2ee91b509851d68766ef3edb67b3990722498 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sat, 13 Jun 2015 06:44:17 -0600 Subject: [PATCH 21/29] updated symphony versions --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 24544e1e9..ef937512b 100644 --- a/composer.json +++ b/composer.json @@ -9,9 +9,9 @@ "php": ">=5.4.0", "twig/twig": "~1.16", "erusev/parsedown-extra": "~0.7", - "symfony/yaml": "~2.6", - "symfony/console": "~2.6", - "symfony/event-dispatcher": "~2.6", + "symfony/yaml": "~2.7", + "symfony/console": "~2.7", + "symfony/event-dispatcher": "~2.7", "doctrine/cache": "~1.4", "maximebf/debugbar": "dev-master", "filp/whoops": "1.2.*@dev", From 63456aad85797767f5185f1359dfc92b112f3693 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sat, 13 Jun 2015 06:45:49 -0600 Subject: [PATCH 22/29] reset how symfony libs versions are set in composer --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index ef937512b..ba949a5df 100644 --- a/composer.json +++ b/composer.json @@ -9,9 +9,9 @@ "php": ">=5.4.0", "twig/twig": "~1.16", "erusev/parsedown-extra": "~0.7", - "symfony/yaml": "~2.7", - "symfony/console": "~2.7", - "symfony/event-dispatcher": "~2.7", + "symfony/yaml": "2.7.*", + "symfony/console": "2.7.*", + "symfony/event-dispatcher": "2.7.*", "doctrine/cache": "~1.4", "maximebf/debugbar": "dev-master", "filp/whoops": "1.2.*@dev", From 4d6ecbe618418ce6710c2f8e92b5e461151ef20e Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 14 Jun 2015 17:54:22 -0600 Subject: [PATCH 23/29] Moved convertUrl() from ParsedownGravTrait into Uri as a static method --- .../Common/Markdown/ParsedownGravTrait.php | 80 +---------------- system/src/Grav/Common/Uri.php | 86 +++++++++++++++++++ 2 files changed, 87 insertions(+), 79 deletions(-) diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index dd81c262d..dcf571564 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -204,88 +204,10 @@ trait ParsedownGravTrait // if there is no scheme, the file is local if (!isset($url['scheme']) && (count($url) > 0)) { // convert the URl is required - $excerpt['element']['attributes']['href'] = $this->convertUrl(Uri::buildUrl($url)); + $excerpt['element']['attributes']['href'] = Uri::convertUrl($this->page, Uri::buildUrl($url)); } } return $excerpt; } - - /** - * Converts links from absolute '/' or relative (../..) to a grav friendly format - * @param string $markdown_url the URL as it was written in the markdown - * @return string the more friendly formatted url - */ - protected function convertUrl($markdown_url) - { - // if absolute and starts with a base_url move on - if (pathinfo($markdown_url, PATHINFO_DIRNAME) == '.') { - if ($this->page->url() == '/') { - return '/' . $markdown_url; - } else { - return $this->page->url() . '/' . $markdown_url; - } - // no path to convert - } elseif ($this->base_url != '' && Utils::startsWith($markdown_url, $this->base_url)) { - return $markdown_url; - // if contains only a fragment - } elseif (Utils::startsWith($markdown_url, '#')) { - return $markdown_url; - } else { - $target = null; - // see if page is relative to this or absolute - if (Utils::startsWith($markdown_url, '/')) { - $normalized_url = Utils::normalizePath($this->base_url . $markdown_url); - $normalized_path = Utils::normalizePath($this->pages_dir . $markdown_url); - } else { - $normalized_url = $this->base_url . Utils::normalizePath($this->page->route() . '/' . $markdown_url); - $normalized_path = Utils::normalizePath($this->page->path() . '/' . $markdown_url); - } - - // special check to see if path checking is required. - $just_path = str_replace($normalized_url, '', $normalized_path); - if ($just_path == $this->page->path()) { - return $normalized_url; - } - - $url_bits = parse_url($normalized_path); - $full_path = ($url_bits['path']); - - if (file_exists($full_path)) { - // do nothing - } elseif (file_exists(urldecode($full_path))) { - $full_path = urldecode($full_path); - } else { - return $normalized_url; - } - - $path_info = pathinfo($full_path); - $page_path = $path_info['dirname']; - $filename = ''; - - - if ($markdown_url == '..') { - $page_path = $full_path; - } else { - // save the filename if a file is part of the path - if (is_file($full_path)) { - if ($path_info['extension'] != 'md') { - $filename = '/' . $path_info['basename']; - } - } else { - $page_path = $full_path; - } - } - - // get page instances and try to find one that fits - $instances = $this->pages->instances(); - if (isset($instances[$page_path])) { - $target = $instances[$page_path]; - $url_bits['path'] = $this->base_url . $target->route() . $filename; - return Uri::buildUrl($url_bits); - } - - return $normalized_url; - } - } } diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 2b2da933a..4c159e5b5 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -441,4 +441,90 @@ class Uri $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : ''; return "$scheme$user$pass$host$port$path$query$fragment"; } + + /** + * Converts links from absolute '/' or relative (../..) to a grav friendly format + * + * @param $page the current page to use as reference + * @param string $markdown_url the URL as it was written in the markdown + * + * @return string the more friendly formatted url + */ + public static function convertUrl($page, $markdown_url) + { + $grav = Grav::instance(); + + $pages_dir = $grav['locator']->findResource('page://'); + $base_url = rtrim($grav['base_url'] . $grav['pages']->base(), '/'); + + // if absolute and starts with a base_url move on + if (pathinfo($markdown_url, PATHINFO_DIRNAME) == '.') { + if ($page->url() == '/') { + return '/' . $markdown_url; + } else { + return $page->url() . '/' . $markdown_url; + } + // no path to convert + } elseif ($base_url != '' && Utils::startsWith($markdown_url, $base_url)) { + return $markdown_url; + // if contains only a fragment + } elseif (Utils::startsWith($markdown_url, '#')) { + return $markdown_url; + } else { + $target = null; + // see if page is relative to this or absolute + if (Utils::startsWith($markdown_url, '/')) { + $normalized_url = Utils::normalizePath($base_url . $markdown_url); + $normalized_path = Utils::normalizePath($pages_dir . $markdown_url); + } else { + $normalized_url = $base_url . Utils::normalizePath($page->route() . '/' . $markdown_url); + $normalized_path = Utils::normalizePath($page->path() . '/' . $markdown_url); + } + + // special check to see if path checking is required. + $just_path = str_replace($normalized_url, '', $normalized_path); + if ($just_path == $page->path()) { + return $normalized_url; + } + + $url_bits = parse_url($normalized_path); + $full_path = ($url_bits['path']); + + if (file_exists($full_path)) { + // do nothing + } elseif (file_exists(urldecode($full_path))) { + $full_path = urldecode($full_path); + } else { + return $normalized_url; + } + + $path_info = pathinfo($full_path); + $page_path = $path_info['dirname']; + $filename = ''; + + + if ($markdown_url == '..') { + $page_path = $full_path; + } else { + // save the filename if a file is part of the path + if (is_file($full_path)) { + if ($path_info['extension'] != 'md') { + $filename = '/' . $path_info['basename']; + } + } else { + $page_path = $full_path; + } + } + + // get page instances and try to find one that fits + $instances = $grav['pages']->instances(); + if (isset($instances[$page_path])) { + $target = $instances[$page_path]; + $url_bits['path'] = $base_url . $target->route() . $filename; + return Uri::buildUrl($url_bits); + } + + return $normalized_url; + } + } } From 835c64c173286ea374dd277b1c72ba864c6b10d6 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 15 Jun 2015 14:59:44 -0600 Subject: [PATCH 24/29] comment fix --- system/src/Grav/Common/GPM/Installer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/GPM/Installer.php b/system/src/Grav/Common/GPM/Installer.php index 49d713f04..b153f9c82 100644 --- a/system/src/Grav/Common/GPM/Installer.php +++ b/system/src/Grav/Common/GPM/Installer.php @@ -160,7 +160,7 @@ class Installer /** * Unnstalls one or more given package * - * @param string $package The slug of the package(s) + * @param string $path The slug of the package(s) * @param array $options Options to use for uninstalling * * @return boolean True if everything went fine, False otherwise. From 493567965958e2f89e6bfce6b76a872c08e66f28 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 15 Jun 2015 15:00:49 -0600 Subject: [PATCH 25/29] fix #202 - incorrect slug name causing issues --- system/src/Grav/Console/Gpm/UninstallCommand.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/system/src/Grav/Console/Gpm/UninstallCommand.php b/system/src/Grav/Console/Gpm/UninstallCommand.php index 085612c4f..70eea9e00 100644 --- a/system/src/Grav/Console/Gpm/UninstallCommand.php +++ b/system/src/Grav/Console/Gpm/UninstallCommand.php @@ -117,7 +117,7 @@ class UninstallCommand extends Command $this->output->writeln(''); } else { $this->output->write(" |- Uninstalling package... "); - $uninstall = $this->uninstallPackage($package); + $uninstall = $this->uninstallPackage($slug, $package); if (!$uninstall) { $this->output->writeln(" '- Uninstallation failed or aborted."); @@ -135,12 +135,16 @@ class UninstallCommand extends Command /** + * @param $slug * @param $package + * * @return bool */ - private function uninstallPackage($package) + private function uninstallPackage($slug, $package) { - $path = self::getGrav()['locator']->findResource($package->package_type . '://' . $package->slug); + $locator = self::getGrav()['locator']; + + $path = self::getGrav()['locator']->findResource($package->package_type . '://' .$slug); Installer::uninstall($path); $errorCode = Installer::lastErrorCode(); From fa432cd32f6f071532f77ca9ee744e2ab4e25163 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 15 Jun 2015 16:03:22 -0600 Subject: [PATCH 26/29] Another incorrect slug name --- system/src/Grav/Console/Gpm/UninstallCommand.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/system/src/Grav/Console/Gpm/UninstallCommand.php b/system/src/Grav/Console/Gpm/UninstallCommand.php index 70eea9e00..8d32d685f 100644 --- a/system/src/Grav/Console/Gpm/UninstallCommand.php +++ b/system/src/Grav/Console/Gpm/UninstallCommand.php @@ -110,7 +110,7 @@ class UninstallCommand extends Command $this->output->write(" |- Checking destination... "); - $checks = $this->checkDestination($package); + $checks = $this->checkDestination($slug, $package); if (!$checks) { $this->output->writeln(" '- Installation failed or aborted."); @@ -163,15 +163,17 @@ class UninstallCommand extends Command return true; } + /** + * @param $slug * @param $package * * @return bool */ - private function checkDestination($package) + private function checkDestination($slug, $package) { - $path = self::getGrav()['locator']->findResource($package->package_type . '://' . $package->slug); + $path = self::getGrav()['locator']->findResource($package->package_type . '://' . $slug); $questionHelper = $this->getHelper('question'); $skipPrompt = $this->input->getOption('all-yes'); From 019fdd65e9dc61bc35b1099e450ec12e4dcd1e21 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 16 Jun 2015 09:58:56 -0600 Subject: [PATCH 27/29] added toggles to enable/disable `last_modified` and `etag` headers --- system/config/system.yaml | 2 ++ system/src/Grav/Common/Grav.php | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/system/config/system.yaml b/system/config/system.yaml index 98e183b1a..e438e6b4a 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -32,6 +32,8 @@ pages: '<': 'lt' types: 'txt|xml|html|json|rss|atom' # Pipe separated list of valid page types expires: 0 # Page expires time in seconds (604800 seconds = 7 days) + last_modified: true # Set the last modified header + etag: true # Set the expires header tag cache: enabled: true # Set to true to enable caching diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 710984aca..0c8b5348e 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -312,11 +312,15 @@ class Grav extends Container } // Set the last modified time - $last_modified_date = gmdate('D, d M Y H:i:s', $page->modified()) . ' GMT'; - header('Last-Modified: ' . $last_modified_date); + if ($this['config']->get('system.pages.last_modified')) { + $last_modified_date = gmdate('D, d M Y H:i:s', $page->modified()) . ' GMT'; + header('Last-Modified: ' . $last_modified_date); + } // Calculate a Hash based on the raw file - header('ETag: ' . md5($page->raw().$page->modified())); + if ($this['config']->get('system.pages.etag')) { + header('ETag: ' . md5($page->raw() . $page->modified())); + } // Set debugger data in headers if (!($extension === null || $extension == 'html')) { From 1edabe3b00c6f2a73f287a678b0ea9cda62eaa13 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 16 Jun 2015 10:25:27 -0600 Subject: [PATCH 28/29] added page level overrides of `etag` and `last_modified` header flags --- system/src/Grav/Common/Grav.php | 4 +-- system/src/Grav/Common/Page/Page.php | 42 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 0c8b5348e..806cbaa62 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -312,13 +312,13 @@ class Grav extends Container } // Set the last modified time - if ($this['config']->get('system.pages.last_modified')) { + if ($page->lastModified()) { $last_modified_date = gmdate('D, d M Y H:i:s', $page->modified()) . ' GMT'; header('Last-Modified: ' . $last_modified_date); } // Calculate a Hash based on the raw file - if ($this['config']->get('system.pages.etag')) { + if ($page->eTag()) { header('ETag: ' . md5($page->raw() . $page->modified())); } diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 7037dfe40..c1dbd8e59 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -78,6 +78,8 @@ class Page protected $process; protected $summary_size; protected $markdown_extra; + protected $etag; + protected $last_modified; /** * @var Page Unmodified (original) version of the page. Used for copying and moving the page. @@ -277,6 +279,12 @@ class Page if (isset($this->header->expires)) { $this->expires = intval($this->header->expires); } + if (isset($this->header->etag)) { + $this->etag = (bool)$this->header->etag; + } + if (isset($this->header->last_modified)) { + $this->last_modified = (bool)$this->header->last_modified; + } } @@ -1142,6 +1150,40 @@ class Page return $this->modified; } + /** + * Gets and sets the option to show the etag header for the page. + * + * @param boolean $var show etag header + * @return boolean show etag header + */ + public function eTag($var = null) + { + if ($var !== null) { + $this->etag = $var; + } + if (!isset($this->etag)) { + $this->etag = (bool) self::getGrav()['config']->get('system.pages.etag'); + } + return $this->etag; + } + + /** + * Gets and sets the option to show the last_modified header for the page. + * + * @param boolean $var show last_modified header + * @return boolean show last_modified header + */ + public function lastModified($var = null) + { + if ($var !== null) { + $this->last_modified = $var; + } + if (!isset($this->last_modified)) { + $this->last_modified = (bool) self::getGrav()['config']->get('system.pages.last_modified'); + } + return $this->last_modified; + } + /** * Gets and sets the path to the .md file for this Page object. * From 4132388ddad83c2877a26dd6b75571213a3e2a61 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 16 Jun 2015 16:15:25 -0600 Subject: [PATCH 29/29] version update --- CHANGELOG.md | 24 ++++++++++++++++++++++++ system/defines.php | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e914ad1b..ea1f66a09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,27 @@ +# v0.9.28 +## 06/16/2015 + +1. [](#new) + * Added method to set raw markdown on a page + * Added ability to enabled system and page level `etag` and `last_modified` headers +2. [](#improved) + * Improved image path processing + * Improved query string handling + * Optimization to image handling supporting URL encoded filenames + * Use global `composer` when available rather than Grv provided one + * Use `PHP_BINARY` contant rather than `php` executable + * Updated Doctrine Cache library + * Updated Symfony libraries + * Moved `convertUrl()` method to Uri object +3. [](#bugfix) + * Fix incorrect slug causing problems with CLI `uninstall` + * Fix Twig runtime error with assets pipeline in sufolder installations + * Fix for `+` in image filenames + * Fix for dot files causing issues with page processing + * Fix for Uri path detection on Windows platform + * Fix for atlernative media resolutions + * Fix for modularTypes key properties + # v0.9.27 ## 05/09/2015 diff --git a/system/defines.php b/system/defines.php index 71aa234fd..562e18707 100644 --- a/system/defines.php +++ b/system/defines.php @@ -2,7 +2,7 @@ // Some standard defines define('GRAV', true); -define('GRAV_VERSION', '0.9.27'); +define('GRAV_VERSION', '0.9.28'); define('DS', '/'); // Directories and Paths