Giter Site home page Giter Site logo

pico-pages-images's Introduction

Pico Pages Images

Find images corresponding to the current page in Pico CMS.

Installation

Copy PicoPagesImages.php to the plugins/ directory of your Pico Project.

Usage

Images are listed in the Twig variable {{ images }} accessible in your theme.

Example of using a loop :

{% for image in images %}
    <img src="{{ image.url }}" alt="{{ image.name }}" {{ image.size }}>
{% endfor %}

An image corresponding to the page http://mysite.com/foo/bar may contain the following data :

Data Example
image.url http://mysite.com/images/foo/bar/bar-image_01.jpg
image.path images/foo/bar/
image.name bar-image_01
image.ext jpg
image.width 800
image.height 600
image.size width="800" height="600"
image.meta See below

Files location

Images are listed from a directory reproducting the pages path (in images/ next to content by default).

content/
    foo/
        bar.md
images/
    foo/
        foo-image_01.jpg
        foo-image_02.png
        bar/
            bar-image_01.jpg
            bar-image_02.gif

You can specify a different location in the Pico config file with the setting images_path :

images_path: images/

If you want to use your content/ directory as the images path you must also add the following to your .htaccess file :

# Allow loading images
RewriteRule ^.*\.(gif|jpe?g|png|webp)$ - [NC,L]

Files metadata

You can add any metadata to an image by creating a .meta.yml YAML file with the same name next to it.

images/
    bar-image_01.jpg
    bar-image_01.jpg.meta.yml

You could for example store titles, dates and descriptions to be used as image captions in your theme.

title: Fido Playing with his Bone
year: 2018
description: The other day, Fido got a new bone, and he became really captivated by it.

Example loop with metadata captions :

{% for image in images %}
    <img src="{{ image.url }}" alt="{{ image.name }}" {{ image.size }}>
    {% if image.meta %}
        <p>{{ image.meta.title }} ({{ image.meta.year }})<br />{{ image.meta.description }}</p>
    {% endif %}
{% endfor %}

pico-pages-images's People

Contributors

briangon avatar mayamcdougall avatar nliautaud avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pico-pages-images's Issues

Security: Plugin opens arbitrary files outside the images path

$this->path = $this->format($url);

Please keep in mind that $url is the raw user input and not validated in any way. Users might do requests like http://example.com/pico/../../../../../../../../some/sensitive/file/on/your/server ("base dir breakouts"), resulting in accessing files you don't want to be accessed. You should rather rely on the $requestFile variable of the onRequestFile event.

Various possible PHP errors/warnings

$images = glob($images_path . $pattern, GLOB_BRACE);
foreach( $images as $path )
{
list(, $basename, $ext, $filename) = array_values(pathinfo($path));
list($width, $height, $type, $size, $mime) = getimagesize($path);

  • glob() (line 92) might return FALSE, resulting in a PHP Warning: Invalid argument supplied for foreach() on line 94.
  • pathinfo() (line 96) doesn't guarantee to return the array in the order and form you expect it; the code might result in a PHP Notice: Undefined offset or might assign unexpected values to your variables.
  • getimagesize() (line 97) doesn't guarantee to return a array with >= 5 items. Just two items are actually guaranteed (resulting in multiple PHP Notice: Undefined offset). The function might even return FALSE.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.