From d252df4b98c0af82ea76a3ba9abc409138d8cb93 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Thu, 19 Nov 2015 04:48:22 +0100 Subject: [PATCH 1/9] Throw RuntimeException on invalid content dirs --- CHANGELOG.md | 1 + lib/Pico.php | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 912e766..991b2ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Released: - want to parse the contents of a page, use the `content` filter instead * [Changed] Improve documentation * [Changed] Improve table styling in default theme +* [Changed] Throw a RuntimeException when the `content` dir isn't accessible * [Changed] Reuse `ParsedownExtra` object; new `onParsedownRegistration` event * [Fixed] `PicoDeprecated`: Sanitize `content_dir` and `base_url` options when reading `config.php` in Picos root dir diff --git a/lib/Pico.php b/lib/Pico.php index 443e557..3089290 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -266,7 +266,8 @@ class Pico * meta headers, processes Markdown, does Twig processing and returns * the rendered contents. * - * @return string rendered Pico contents + * @return string rendered Pico contents + * @throws RuntimeException thrown when a not recoverable error occurs */ public function run() { @@ -281,6 +282,11 @@ class Pico $this->loadConfig(); $this->triggerEvent('onConfigLoaded', array(&$this->config)); + // check content dir + if (!is_dir($this->getConfig('content_dir'))) { + throw new RuntimeException('Invalid content directory "' . $this->getConfig('content_dir') . '"'); + } + // evaluate request url $this->evaluateRequestUrl(); $this->triggerEvent('onRequestUrl', array(&$this->requestUrl)); From d59dba0b5faf35ecdca0ae65b8a9a72141f4279a Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sat, 21 Nov 2015 22:13:54 +0100 Subject: [PATCH 2/9] Update README.md: Add update instructions for composer users --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e4c2642..1f32a64 100644 --- a/README.md +++ b/README.md @@ -46,11 +46,11 @@ Upgrading Pico is very easy: You just have to replace all of Pico's files - that Pico follows [Semantic Versioning 2.0][SemVer] and uses version numbers like `MAJOR`.`MINOR`.`PATCH`. When we update... -- the `PATCH` version (e.g. `1.0.0` to `1.0.1`), we made backwards-compatible bug fixes. It's then sufficient to extract [Pico's latest release][LatestRelease] to your existing installation directory and overwriting all files. +- the `PATCH` version (e.g. `1.0.0` to `1.0.1`), we made backwards-compatible bug fixes. It's then sufficient to extract [Pico's latest release][LatestRelease] to your existing installation directory and overwriting all files. Alternatively you can either use the [*source code* of Pico's latest release][LatestRelease] or pull from Pico's Git repository, but are then required to update Pico's [composer][] dependencies manually by running `php composer.phar update`. - the `MINOR` version (e.g. `1.0` to `1.1`), we added functionality in a backwards-compatible manner, but anyway recommend you to "install" Pico newly. Backup all of your files, empty your installation directory and install Pico as elucidated above. You can then copy your `config/config.php` and `content` directory without any change. If applicable, you can also copy the folder of your custom theme within the `themes` directory. Provided that you're using plugins, also copy all of your plugins from the `plugins` directory. -- the `MAJOR` version (e.g. `1.0` to `2.0`), a appropriate upgrade tutorial will be provided. +- the `MAJOR` version (e.g. `1.0` to `2.0`), we made incompatible API changes. We will then provide a appropriate upgrade tutorial. Upgrading Pico 0.8 or 0.9 to Pico 1.0 is a special case. The new `PicoDeprecated` plugin ensures backwards compatibility, so you basically can follow the above upgrade instructions as if we updated the `MINOR` version. However, we recommend you to take some further steps to confine the necessity of `PicoDeprecated` as far as possible. For more information about what has changed with Pico 1.0 and a step-by-step upgrade tutorial, please refer to the [upgrade page of our website][HelpUpgrade]. From 60c627c21416d55d0de2a8e3b1e74d4408e10be7 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sun, 22 Nov 2015 14:08:06 +0100 Subject: [PATCH 3/9] Update composer.json: Use latest MINOR versions of Twig/Parsedown/YAML --- composer.json | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index b0d75e1..c8a1355 100644 --- a/composer.json +++ b/composer.json @@ -2,20 +2,31 @@ "name": "picocms/pico", "type": "library", "description": "Pico is a flat file CMS, this means there is no administration backend and database to deal with. You simply create .md files in the \"content\" folder and that becomes a page.", - "keywords": ["cms"], + "keywords": ["flat-file","cms","php","twig","markdown"], "homepage": "http://picocms.org/", "license": "MIT", "authors": [ { "name": "Gilbert Pellegrom", - "email": "gilbert@pellegrom.me" + "email": "gilbert@pellegrom.me", + "role": "Project Founder" + }, + { + "name": "The Pico Community", + "homepage": "https://github.com/picocms/Pico/graphs/contributors", + "role": "Contributors" } ], + "support": { + "docs": "http://picocms.org/docs", + "issues": "https://github.com/picocms/Pico/issues", + "source": "https://github.com/picocms/Pico" + }, "require": { "php": ">=5.3.6", - "twig/twig": "1.18.*", - "erusev/parsedown-extra": "0.7.*", - "symfony/yaml" : "2.3" + "twig/twig": "^1.18", + "erusev/parsedown-extra": "^0.7", + "symfony/yaml" : "^2.3" }, "autoload": { "psr-0": { From c34afad4affb14750ed01abaa9fad7c491ef52f2 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sun, 22 Nov 2015 14:08:35 +0100 Subject: [PATCH 4/9] Fix typo --- lib/Pico.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Pico.php b/lib/Pico.php index 3089290..2a2a383 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -1339,8 +1339,7 @@ class Pico if (!empty($this->plugins)) { foreach ($this->plugins as $plugin) { // only trigger events for plugins that implement PicoPluginInterface - // deprecated events (plugins for Pico 0.9 and older) will be - // triggered by the `PicoPluginDeprecated` plugin + // deprecated events (plugins for Pico 0.9 and older) will be triggered by `PicoDeprecated` if (is_a($plugin, 'PicoPluginInterface')) { $plugin->handleEvent($eventName, $params); } From bd24d518f20b9568aa9625bec27fc93b4db01cf0 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Mon, 23 Nov 2015 21:33:57 +0100 Subject: [PATCH 5/9] Update .gitignore --- .gitignore | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 01cdfee..825c513 100644 --- a/.gitignore +++ b/.gitignore @@ -11,22 +11,22 @@ desktop.ini ._* # Composer -composer.lock -composer.phar -vendor/* +/composer.lock +/composer.phar +/vendor # User config -config/config.php +/config/config.php # User themes -themes/* -!themes/default/* +/themes +!/themes/default # User plugins -plugins/* -!plugins/0?-* -!plugins/1?-* -!plugins/DummyPlugin.php +/plugins +!/plugins/0?-* +!/plugins/1?-* +!/plugins/DummyPlugin.php # User content -content/* +/content From 2982f5deb9565e87c2236f25d0521fb4c8e3100a Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Tue, 24 Nov 2015 19:49:16 +0100 Subject: [PATCH 6/9] Optimize composer autoloader before deploying This converts PSR-0/PSR-4 autoloading to classmap to get a faster autoloader (up to 20% performance increase) --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 01b5c42..331173c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ script: before_deploy: - composer install + - composer dump-autoload --optimize - tar -czf "pico-release-$TRAVIS_TAG.tar.gz" .htaccess README.md CHANGELOG.md CONTRIBUTING.md composer.json composer.lock LICENSE config content-sample lib plugins themes vendor index.php deploy: From 840d41bca5b35ddcb24d5b4cdd3fc14a61c5496e Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Wed, 25 Nov 2015 04:07:46 +0100 Subject: [PATCH 7/9] Improve type hinting --- lib/Pico.php | 2 +- plugins/00-PicoDeprecated.php | 16 ++++++++-------- plugins/01-PicoParsePagesContent.php | 2 +- plugins/02-PicoExcerpt.php | 4 ++-- plugins/DummyPlugin.php | 24 ++++++++++++------------ 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/Pico.php b/lib/Pico.php index 2a2a383..ccc0d55 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -1031,7 +1031,7 @@ class Pico * * @see Pico::readPages() * @see Pico::sortPages() - * @return array|null the data of all pages + * @return array[]|null the data of all pages */ public function getPages() { diff --git a/plugins/00-PicoDeprecated.php b/plugins/00-PicoDeprecated.php index 4866b9e..f646b03 100644 --- a/plugins/00-PicoDeprecated.php +++ b/plugins/00-PicoDeprecated.php @@ -67,7 +67,7 @@ class PicoDeprecated extends AbstractPicoPlugin * * @see DummyPlugin::onPluginsLoaded() */ - public function onPluginsLoaded(&$plugins) + public function onPluginsLoaded(array &$plugins) { if (!empty($plugins)) { foreach ($plugins as $plugin) { @@ -110,7 +110,7 @@ class PicoDeprecated extends AbstractPicoPlugin * @param mixed[] &$realConfig array of config variables * @return void */ - public function onConfigLoaded(&$realConfig) + public function onConfigLoaded(array &$realConfig) { global $config; @@ -167,7 +167,7 @@ class PicoDeprecated extends AbstractPicoPlugin * @param mixed[] &$realConfig array of config variables * @return void */ - protected function loadRootDirConfig(&$realConfig) + protected function loadRootDirConfig(array &$realConfig) { if (file_exists($this->getRootDir() . 'config.php')) { // config.php in Pico::$rootDir is deprecated @@ -284,7 +284,7 @@ class PicoDeprecated extends AbstractPicoPlugin * * @see DummyPlugin::onMetaHeaders() */ - public function onMetaHeaders(&$headers) + public function onMetaHeaders(array &$headers) { $this->triggerEvent('before_read_file_meta', array(&$headers)); } @@ -294,7 +294,7 @@ class PicoDeprecated extends AbstractPicoPlugin * * @see DummyPlugin::onMetaParsed() */ - public function onMetaParsed(&$meta) + public function onMetaParsed(array &$meta) { $this->triggerEvent('file_meta', array(&$meta)); } @@ -328,7 +328,7 @@ class PicoDeprecated extends AbstractPicoPlugin * * @see DummyPlugin::onSinglePageLoaded() */ - public function onSinglePageLoaded(&$pageData) + public function onSinglePageLoaded(array &$pageData) { $this->triggerEvent('get_page_data', array(&$pageData, $pageData['meta'])); } @@ -344,7 +344,7 @@ class PicoDeprecated extends AbstractPicoPlugin * * @see DummyPlugin::onPagesLoaded() */ - public function onPagesLoaded(&$pages, &$currentPage, &$previousPage, &$nextPage) + public function onPagesLoaded(array &$pages, array &$currentPage = null, array &$previousPage = null, array &$nextPage = null) { // remove keys of pages array $plainPages = array(); @@ -391,7 +391,7 @@ class PicoDeprecated extends AbstractPicoPlugin * * @see DummyPlugin::onPageRendering() */ - public function onPageRendering(&$twig, &$twigVariables, &$templateName) + public function onPageRendering(Twig_Environment &$twig, array &$twigVariables, &$templateName) { // template name contains file extension since Pico 1.0 $fileExtension = ''; diff --git a/plugins/01-PicoParsePagesContent.php b/plugins/01-PicoParsePagesContent.php index fd36f0a..db4ed10 100644 --- a/plugins/01-PicoParsePagesContent.php +++ b/plugins/01-PicoParsePagesContent.php @@ -30,7 +30,7 @@ class PicoParsePagesContent extends AbstractPicoPlugin * * @see DummyPlugin::onSinglePageLoaded() */ - public function onSinglePageLoaded(&$pageData) + public function onSinglePageLoaded(array &$pageData) { if (!isset($pageData['content'])) { $pageData['content'] = $this->prepareFileContent($pageData['raw_content'], $pageData['meta']); diff --git a/plugins/02-PicoExcerpt.php b/plugins/02-PicoExcerpt.php index 4ada382..7d0c449 100644 --- a/plugins/02-PicoExcerpt.php +++ b/plugins/02-PicoExcerpt.php @@ -40,7 +40,7 @@ class PicoExcerpt extends AbstractPicoPlugin * * @see DummyPlugin::onConfigLoaded() */ - public function onConfigLoaded(&$config) + public function onConfigLoaded(array &$config) { if (!isset($config['excerpt_length'])) { $config['excerpt_length'] = 50; @@ -53,7 +53,7 @@ class PicoExcerpt extends AbstractPicoPlugin * @see PicoExcerpt::createExcerpt() * @see DummyPlugin::onSinglePageLoaded() */ - public function onSinglePageLoaded(&$pageData) + public function onSinglePageLoaded(array &$pageData) { if (!isset($pageData['excerpt'])) { $pageData['excerpt'] = $this->createExcerpt( diff --git a/plugins/DummyPlugin.php b/plugins/DummyPlugin.php index 9ecd411..60f2f35 100644 --- a/plugins/DummyPlugin.php +++ b/plugins/DummyPlugin.php @@ -40,7 +40,7 @@ class DummyPlugin extends AbstractPicoPlugin * @param object[] &$plugins loaded plugin instances * @return void */ - public function onPluginsLoaded(&$plugins) + public function onPluginsLoaded(array &$plugins) { // your code } @@ -52,7 +52,7 @@ class DummyPlugin extends AbstractPicoPlugin * @param mixed[] &$config array of config variables * @return void */ - public function onConfigLoaded(&$config) + public function onConfigLoaded(array &$config) { // your code } @@ -141,7 +141,7 @@ class DummyPlugin extends AbstractPicoPlugin * array key is later used to access the found value * @return void */ - public function onMetaHeaders(&$headers) + public function onMetaHeaders(array &$headers) { // your code } @@ -155,7 +155,7 @@ class DummyPlugin extends AbstractPicoPlugin * @param string[] &$headers known meta header fields * @return void */ - public function onMetaParsing(&$rawContent, &$headers) + public function onMetaParsing(&$rawContent, array &$headers) { // your code } @@ -167,7 +167,7 @@ class DummyPlugin extends AbstractPicoPlugin * @param string[] &$meta parsed meta data * @return void */ - public function onMetaParsed(&$meta) + public function onMetaParsed(array &$meta) { // your code } @@ -249,7 +249,7 @@ class DummyPlugin extends AbstractPicoPlugin * @param array &$pageData data of the loaded page * @return void */ - public function onSinglePageLoaded(&$pageData) + public function onSinglePageLoaded(array &$pageData) { // your code } @@ -264,13 +264,13 @@ class DummyPlugin extends AbstractPicoPlugin * @see Pico::getCurrentPage() * @see Pico::getPreviousPage() * @see Pico::getNextPage() - * @param array &$pages data of all known pages - * @param array &$currentPage data of the page being served - * @param array &$previousPage data of the previous page - * @param array &$nextPage data of the next page + * @param array[] &$pages data of all known pages + * @param array|null &$currentPage data of the page being served + * @param array|null &$previousPage data of the previous page + * @param array|null &$nextPage data of the next page * @return void */ - public function onPagesLoaded(&$pages, &$currentPage, &$previousPage, &$nextPage) + public function onPagesLoaded(array &$pages, array &$currentPage = null, array &$previousPage = null, array &$nextPage = null) { // your code } @@ -295,7 +295,7 @@ class DummyPlugin extends AbstractPicoPlugin * @param string &$templateName file name of the template * @return void */ - public function onPageRendering(&$twig, &$twigVariables, &$templateName) + public function onPageRendering(Twig_Environment &$twig, array &$twigVariables, &$templateName) { // your code } From 876a500ecfda382a3a3362f4093403372eed8407 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Wed, 25 Nov 2015 04:07:57 +0100 Subject: [PATCH 8/9] Improve .gitignore --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 825c513..f77c917 100644 --- a/.gitignore +++ b/.gitignore @@ -19,11 +19,11 @@ desktop.ini /config/config.php # User themes -/themes +/themes/* !/themes/default # User plugins -/plugins +/plugins/* !/plugins/0?-* !/plugins/1?-* !/plugins/DummyPlugin.php From 20387e0bf980196e3ac1afb61c954062ed14e7dd Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Wed, 25 Nov 2015 04:10:22 +0100 Subject: [PATCH 9/9] Make DummyPlugin class final Plugin developers MUST NOT extend from DummyPlugin, they SHOULD extend from AbstractPicoPlugin --- plugins/DummyPlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/DummyPlugin.php b/plugins/DummyPlugin.php index 60f2f35..6c2a85b 100644 --- a/plugins/DummyPlugin.php +++ b/plugins/DummyPlugin.php @@ -11,7 +11,7 @@ * @license http://opensource.org/licenses/MIT * @version 1.0 */ -class DummyPlugin extends AbstractPicoPlugin +final class DummyPlugin extends AbstractPicoPlugin { /** * This plugin is enabled by default?