From 59a0cc2f2d204c09d977a59908aa96971d3a8c08 Mon Sep 17 00:00:00 2001 From: nliautaud Date: Mon, 6 Nov 2017 15:24:48 +0100 Subject: [PATCH 1/2] update config documentation to Pico 2.0 YML --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d9ad408..d04ba8d 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,8 @@ Images are listed from a directory reproducting the pages path (in `images/` nex bar-image_01.jpg bar-image_02.gif -You can specify a different location by using the configuration setting `images_path` : +You can specify a different location in the Pico config file with the setting `images_path` : -```php -$config['images_path'] = 'images/'; +```yml +images_path: images/ ``` From 590278255f9bbcfd7a6ed697f4734f37ebcfd8ed Mon Sep 17 00:00:00 2001 From: nliautaud Date: Wed, 4 Jul 2018 16:55:31 +0200 Subject: [PATCH 2/2] PSR2, composer and Pico 2 API --- .gitignore | 1 + PicoPagesImages.php | 67 +++++++++++++++++++++++++-------------------- composer.json | 30 ++++++++++++++++++++ 3 files changed, 69 insertions(+), 29 deletions(-) create mode 100644 .gitignore create mode 100644 composer.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..600d2d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode \ No newline at end of file diff --git a/PicoPagesImages.php b/PicoPagesImages.php index acf22c0..5304c27 100644 --- a/PicoPagesImages.php +++ b/PicoPagesImages.php @@ -1,16 +1,16 @@ + * @license http://opensource.org/licenses/MIT The MIT License * @link http://nliautaud.fr * @link http://picocms.org - * @license http://opensource.org/licenses/MIT The MIT License */ class PicoPagesImages extends AbstractPicoPlugin { - private $path = ''; + const API_VERSION = 2; + private $path; private $root; /** @@ -19,22 +19,27 @@ class PicoPagesImages extends AbstractPicoPlugin * * Triggered after Pico has discovered the content file to serve * - * @see Pico::getBaseUrl() - * @see Pico::getRequestFile() - * @param string &$file absolute path to the content file to serve + * @see Pico::resolveFilePath() + * @see Pico::getRequestFile() + * + * @param string &$file absolute path to the content file to serve + * * @return void */ - public function onRequestFile(&$requestFile) + public function onRequestFile(&$file) { $contentDir = $this->getConfig('content_dir'); $contentDirLength = strlen($contentDir); - if (substr($requestFile, 0, $contentDirLength) !== $contentDir) - return; + if (substr($file, 0, $contentDirLength) !== $contentDir) { + return; + } $contentExt = $this->getConfig('content_ext'); - $this->path = substr($requestFile, $contentDirLength); + $this->path = substr($file, $contentDirLength); $this->path = rtrim($this->path, "index$contentExt"); $this->path = rtrim($this->path, $contentExt); - if ($this->path) $this->path .= '/'; + if ($this->path) { + $this->path .= '/'; + } } /** * Triggered after Pico has read its configuration @@ -45,30 +50,32 @@ public function onRequestFile(&$requestFile) */ public function onConfigLoaded(array &$config) { - if (!empty($config['images_path'])) + if (!empty($config['images_path'])) { $this->root = rtrim($config['images_path'], '/') . '/'; - else $this->root = 'images/'; + } else { + $this->root = 'images/'; + } } /** * Triggered before Pico renders the page * - * @see Pico::getTwig() - * @see DummyPlugin::onPageRendered() - * @param Twig_Environment &$twig twig template engine - * @param array &$twigVariables template variables - * @param string &$templateName file name of the template + * @see DummyPlugin::onPageRendered() + * + * @param string &$templateName file name of the template + * @param array &$twigVariables template variables + * * @return void */ - public function onPageRendering(Twig_Environment &$twig, array &$twigVariables, &$templateName) + public function onPageRendering(&$templateName, array &$twigVariables) { - $twigVariables['images'] = $this->images_list(); + $twigVariables['images'] = $this->getImages(); } /** * Return the list and infos of images in the current directory. * * @return array */ - private function images_list() + private function getImages() { $images_path = $this->root . $this->path; @@ -76,13 +83,16 @@ private function images_list() $pattern = '*.{[jJ][pP][gG],[jJ][pP][eE][gG],[pP][nN][gG],[gG][iI][fF]}'; $images = glob($images_path . $pattern, GLOB_BRACE); - if (!is_array($images)) return array(); + if (!is_array($images)) { + return array(); + } - foreach( $images as $path ) - { + foreach ($images as $path) { $imagesize = getimagesize($path); - if (!is_array($imagesize)) $imagesize = array(); - list($width, $height, $type, $size) = array_pad($imagesize, 4, ''); + if (!is_array($imagesize)) { + $imagesize = array(); + } + list($width, $height,, $size) = array_pad($imagesize, 4, ''); $data[] = array ( 'url' => $this->getBaseUrl() . $images_path . pathinfo($path, PATHINFO_BASENAME), @@ -97,4 +107,3 @@ private function images_list() return $data; } } -?> diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..905f112 --- /dev/null +++ b/composer.json @@ -0,0 +1,30 @@ +{ + "name": "nliautaud/pico-pages-images", + "type": "pico-plugin", + "description": "Get images corresponding to the current page in Pico CMS", + "keywords": [ "pico", "picocms", "picocms-plugin", "pico-pages-images"], + "homepage": "http://picocms.org/", + "license": "MIT", + "authors": [ + { + "name": "Nicolas Liautaud", + "homepage": "https://github.com/nliautaud/pico-pages-images", + "role": "Lead Developer" + }, + { + "name": "Contributors", + "homepage": "https://github.com/nliautaud/pico-pages-images/graphs/contributors" + } + ], + "support": { + "docs": "https://github.com/nliautaud/pico-pages-images/blob/master/README.md", + "issues": "https://github.com/nliautaud/pico-pages-images/issues", + "source": "https://github.com/nliautaud/pico-pages-images" + }, + "require": { + "php": ">=5.4.0" + }, + "autoload": { + "classmap": [ "PicoPagesImages.php" ] + } +} \ No newline at end of file