diff --git a/CHANGELOG.md b/CHANGELOG.md index bdea66039d..59659ec6ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +# v1.1.10 +## 12/21/2016 + +1. [](#improved) + * Improve detection of home path. Also allow `~/.grav` on Windows, drop `ConsoleTrait::isWindows()` method, used only for that [#1204](https://github.com/getgrav/grav/pull/1204) + * Reworked PHP CLI router [#1219](https://github.com/getgrav/grav/pull/1219) + * More robust theme/plugin logic in `bin/gpm direct-install` +1. [](#bugfix) + * Fixed case where extracting a package would cause an error during rename + * Fix issue with using `Yaml::parse` direcly on a filename, now deprecated + * Add pattern for frontend validation of folder slugs [#891](https://github.com/getgrav/grav-plugin-admin/issues/891) + * Fix issue with Inflector when translation is disabled [https://github.com/getgrav/grav-plugin-simplesearch/issues/87](https://github.com/getgrav/grav-plugin-simplesearch/issues/87) + * Explicitly expose `array_unique` Twig filter [https://github.com/getgrav/grav-plugin-admin/issues/897](https://github.com/getgrav/grav-plugin-admin/issues/897) + # v1.1.9 ## 12/13/2016 diff --git a/index.php b/index.php index 77725b92a2..8d8d2b62f7 100644 --- a/index.php +++ b/index.php @@ -14,6 +14,12 @@ die("Please run: bin/grav install"); } +if (PHP_SAPI == 'cli-server') { + if (!isset($_SERVER['PHP_CLI_ROUTER'])) { + die("PHP webserver requires a router to run Grav, please use:
php -S {$_SERVER["SERVER_NAME"]}:{$_SERVER["SERVER_PORT"]} system/router.php
"); + } +} + use Grav\Common\Grav; use RocketTheme\Toolbox\Event\Event; diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml index f38957ccff..f42971c3b2 100644 --- a/system/blueprints/pages/default.yaml +++ b/system/blueprints/pages/default.yaml @@ -133,6 +133,7 @@ form: label: PLUGIN_ADMIN.FOLDER_NAME validate: type: slug + pattern: '[a-zа-я][a-zа-я0-9_\-]+' route: type: select diff --git a/system/blueprints/pages/modular_new.yaml b/system/blueprints/pages/modular_new.yaml index 2732923637..44cf231316 100644 --- a/system/blueprints/pages/modular_new.yaml +++ b/system/blueprints/pages/modular_new.yaml @@ -24,6 +24,7 @@ form: validate: type: slug required: true + pattern: '[a-zа-я][a-zа-я0-9_\-]+' route: type: select diff --git a/system/blueprints/pages/modular_raw.yaml b/system/blueprints/pages/modular_raw.yaml index ed25992a39..730809d5cd 100644 --- a/system/blueprints/pages/modular_raw.yaml +++ b/system/blueprints/pages/modular_raw.yaml @@ -73,6 +73,7 @@ form: validate: type: slug required: true + pattern: '[a-zа-я][a-zа-я0-9_\-]+' route: type: select diff --git a/system/blueprints/pages/new.yaml b/system/blueprints/pages/new.yaml index 49b85b7290..df7b0f6932 100644 --- a/system/blueprints/pages/new.yaml +++ b/system/blueprints/pages/new.yaml @@ -26,6 +26,7 @@ form: validate: type: slug required: true + pattern: '[a-zа-я][a-zа-я0-9_\-]+' route: type: select diff --git a/system/blueprints/pages/new_folder.yaml b/system/blueprints/pages/new_folder.yaml index 16024b7493..458fa7498b 100644 --- a/system/blueprints/pages/new_folder.yaml +++ b/system/blueprints/pages/new_folder.yaml @@ -19,6 +19,7 @@ form: validate: type: slug required: true + pattern: '[a-zа-я][a-zа-я0-9_\-]+' route: type: select diff --git a/system/blueprints/pages/raw.yaml b/system/blueprints/pages/raw.yaml index 60870eaf7a..8781c2c319 100644 --- a/system/blueprints/pages/raw.yaml +++ b/system/blueprints/pages/raw.yaml @@ -73,6 +73,7 @@ form: validate: type: slug required: true + pattern: '[a-zа-я][a-zа-я0-9_\-]+' route: type: select diff --git a/system/defines.php b/system/defines.php index 956dd1b1d0..a704963de6 100644 --- a/system/defines.php +++ b/system/defines.php @@ -8,7 +8,7 @@ // Some standard defines define('GRAV', true); -define('GRAV_VERSION', '1.1.9'); +define('GRAV_VERSION', '1.1.10'); define('GRAV_TESTING', false); define('DS', '/'); define('GRAV_PHP_MIN', '5.5.9'); diff --git a/system/router.php b/system/router.php new file mode 100644 index 0000000000..53e0126cf6 --- /dev/null +++ b/system/router.php @@ -0,0 +1,26 @@ + $value) { if (is_array($value)) { $value = implode(',', $value); - } - - $values[$key] = array_map('trim', explode(',', $value)); + $values[$key] = array_map('trim', explode(',', $value)); + } else { + $values[$key] = trim($value); + } } } diff --git a/system/src/Grav/Common/GPM/Installer.php b/system/src/Grav/Common/GPM/Installer.php index add625167b..0e6352147b 100644 --- a/system/src/Grav/Common/GPM/Installer.php +++ b/system/src/Grav/Common/GPM/Installer.php @@ -181,7 +181,7 @@ public static function unZip($zip_file, $destination) return false; } - $package_folder_name = $zip->getNameIndex(0); + $package_folder_name = preg_replace('#\./$#', '', $zip->getNameIndex(0)); $zip->close(); $extracted_folder = $destination . '/' . $package_folder_name; diff --git a/system/src/Grav/Common/Inflector.php b/system/src/Grav/Common/Inflector.php index 17a11e0c48..8fe5512149 100644 --- a/system/src/Grav/Common/Inflector.php +++ b/system/src/Grav/Common/Inflector.php @@ -26,11 +26,11 @@ public function init() { if (empty($this->plural)) { $language = Grav::instance()['language']; - $this->plural = $language->translate('INFLECTOR_PLURALS', null, true); - $this->singular = $language->translate('INFLECTOR_SINGULAR', null, true); - $this->uncountable = $language->translate('INFLECTOR_UNCOUNTABLE', null, true); - $this->irregular = $language->translate('INFLECTOR_IRREGULAR', null, true); - $this->ordinals = $language->translate('INFLECTOR_ORDINALS', null, true); + $this->plural = $language->translate('INFLECTOR_PLURALS', null, true) ?: []; + $this->singular = $language->translate('INFLECTOR_SINGULAR', null, true) ?: []; + $this->uncountable = $language->translate('INFLECTOR_UNCOUNTABLE', null, true) ?: []; + $this->irregular = $language->translate('INFLECTOR_IRREGULAR', null, true) ?: []; + $this->ordinals = $language->translate('INFLECTOR_ORDINALS', null, true) ?: []; } } diff --git a/system/src/Grav/Common/Twig/TwigExtension.php b/system/src/Grav/Common/Twig/TwigExtension.php index aa9f1de04a..fff032e9cf 100644 --- a/system/src/Grav/Common/Twig/TwigExtension.php +++ b/system/src/Grav/Common/Twig/TwigExtension.php @@ -87,6 +87,7 @@ public function getFilters() new \Twig_SimpleFilter('truncate', ['\Grav\Common\Utils', 'truncate']), new \Twig_SimpleFilter('truncate_html', ['\Grav\Common\Utils', 'truncateHTML']), new \Twig_SimpleFilter('json_decode', [$this, 'jsonDecodeFilter']), + new \Twig_SimpleFilter('array_unique', 'array_unique'), ]; } diff --git a/system/src/Grav/Console/Cli/InstallCommand.php b/system/src/Grav/Console/Cli/InstallCommand.php index a3768ba4ed..49b66a097b 100644 --- a/system/src/Grav/Console/Cli/InstallCommand.php +++ b/system/src/Grav/Console/Cli/InstallCommand.php @@ -65,20 +65,15 @@ protected function serve() // fix trailing slash $this->destination = rtrim($this->destination, DS) . DS; $this->user_path = $this->destination . USER_PATH; - - if (false === $this->isWindows()) { - $local_config_file = exec('eval echo ~/.grav/config'); - if (file_exists($local_config_file)) { - $this->local_config = Yaml::parse($local_config_file); - $this->output->writeln('Read local config from ' . $local_config_file . ''); - } + if ($local_config_file = $this->loadLocalConfig()) { + $this->output->writeln('Read local config from ' . $local_config_file . ''); } // Look for dependencies file in ROOT and USER dir if (file_exists($this->user_path . $dependencies_file)) { - $this->config = Yaml::parse($this->user_path . $dependencies_file); + $this->config = Yaml::parse(file_get_contents($this->user_path . $dependencies_file)); } elseif (file_exists($this->destination . $dependencies_file)) { - $this->config = Yaml::parse($this->destination . $dependencies_file); + $this->config = Yaml::parse(file_get_contents($this->destination . $dependencies_file)); } else { $this->output->writeln('ERROR Missing .dependencies file in user/ folder'); } diff --git a/system/src/Grav/Console/ConsoleTrait.php b/system/src/Grav/Console/ConsoleTrait.php index 66ecd07fd9..e03789102a 100644 --- a/system/src/Grav/Console/ConsoleTrait.php +++ b/system/src/Grav/Console/ConsoleTrait.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Yaml\Yaml; trait ConsoleTrait { @@ -113,19 +114,20 @@ public function clearCache($all = []) } /** - * Validate if the system is based on windows or not. + * Load the local config file * - * @return bool + * @return mixed string the local config file name. false if local config does not exist */ - public function isWindows() + public function loadLocalConfig() { - $keys = [ - 'CYGWIN_NT-5.1', - 'WIN32', - 'WINNT', - 'Windows' - ]; - - return array_key_exists(PHP_OS, $keys); + $home_folder = getenv('HOME') ?: getenv('HOMEDRIVE') . getenv('HOMEPATH'); + $local_config_file = $home_folder . '/.grav/config'; + + if (file_exists($local_config_file)) { + $this->local_config = Yaml::parse(file_get_contents($local_config_file)); + return $local_config_file; + } + + return false; } } diff --git a/system/src/Grav/Console/Gpm/DirectInstallCommand.php b/system/src/Grav/Console/Gpm/DirectInstallCommand.php index 54b98d552a..49ad97bb7c 100644 --- a/system/src/Grav/Console/Gpm/DirectInstallCommand.php +++ b/system/src/Grav/Console/Gpm/DirectInstallCommand.php @@ -84,6 +84,7 @@ protected function serve() $this->output->write("\x0D"); $this->output->writeln(" |- Extracting package... ok"); + $type = $this->getPackageType($extracted); if (!$type) { @@ -238,6 +239,9 @@ protected function getPackageName($source) */ protected function getPackageType($source) { + $plugin_regex = '/^class\\s{1,}[a-zA-Z0-9]{1,}\\s{1,}extends.+Plugin/m'; + $theme_regex = '/^class\\s{1,}[a-zA-Z0-9]{1,}\\s{1,}extends.+Theme/m'; + if ( file_exists($source . 'system/defines.php') && file_exists($source . 'system/config/system.yaml') @@ -258,9 +262,9 @@ protected function getPackageType($source) } foreach (glob($source . "*.php") as $filename) { $contents = file_get_contents($filename); - if (Utils::contains($contents, 'Grav\Common\Theme')) { + if (preg_match($theme_regex, $contents)) { return 'theme'; - } elseif (Utils::contains($contents, 'Grav\Common\Plugin')) { + } elseif (preg_match($plugin_regex, $contents)) { return 'plugin'; } } diff --git a/system/src/Grav/Console/Gpm/InstallCommand.php b/system/src/Grav/Console/Gpm/InstallCommand.php index f8103e2c29..bae3dd30a7 100644 --- a/system/src/Grav/Console/Gpm/InstallCommand.php +++ b/system/src/Grav/Console/Gpm/InstallCommand.php @@ -20,7 +20,6 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Question\ConfirmationQuestion; -use Symfony\Component\Yaml\Yaml; define('GIT_REGEX', '/http[s]?:\/\/(?:.*@)?(github|bitbucket)(?:.org|.com)\/.*\/(.*)/'); @@ -112,13 +111,7 @@ protected function serve() $packages = array_map('strtolower', $this->input->getArgument('package')); $this->data = $this->gpm->findPackages($packages); - - if (false === $this->isWindows() && @is_file(getenv("HOME") . '/.grav/config')) { - $local_config_file = exec('eval echo ~/.grav/config'); - if (file_exists($local_config_file)) { - $this->local_config = Yaml::parse($local_config_file); - } - } + $this->loadLocalConfig(); if ( !Installer::isGravInstance($this->destination) ||