Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
pluginkit, apikey can be callback
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Meilick <[email protected]>
  • Loading branch information
bnomei committed Feb 6, 2019
1 parent f64aad8 commit 420e996
Show file tree
Hide file tree
Showing 25 changed files with 1,154 additions and 69 deletions.
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[*.{css,scss,less,js,json,ts,sass,html,hbs,mustache,phtml,html.twig,md,yml}]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
indent_size = 4
trim_trailing_whitespace = false

[site/templates/**.php]
indent_size = 2

[site/snippets/**.php]
indent_size = 2

[package.json,.{babelrc,editorconfig,eslintrc,lintstagedrc,stylelintrc}]
indent_style = space
indent_size = 2
31 changes: 27 additions & 4 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
vendor/
/kirby3-thumb-imageoptim.zip
/composer.lock
/kirby
# OS files
.DS_Store
.php_cs.cache

# imageoptim
/vendor/imageoptim/imageoptim/*.png

# files of Composer dependencies that are not needed for the plugin
/vendor/**/.*
/vendor/**/*.json
/vendor/**/*.txt
/vendor/**/*.md
/vendor/**/*.yml
/vendor/**/*.yaml
/vendor/**/*.xml
/vendor/**/*.dist
/vendor/**/readme.php
/vendor/**/LICENSE
/vendor/**/COPYING
/vendor/**/VERSION
/vendor/**/docs/*
/vendor/**/example/*
/vendor/**/examples/*
/vendor/**/test/*
/vendor/**/tests/*
/vendor/**/php4/*
/vendor/getkirby/composer-installer
7 changes: 5 additions & 2 deletions classes/Imageoptim.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class Imageoptim
public static function instance()
{
$apikey = option('bnomei.thumbimageoptim.apikey');
if (is_callable($apikey)) {
$apikey = trimg($apikey());
}
if ($apikey && !static::$instance) {
static::$instance = new \ImageOptim\API($apikey);
}
Expand All @@ -31,9 +34,9 @@ public static function removeFilesOfUnfinishedJobs()
{
$r = kirby()->roots()->cache().'/bnomei/thumbimageoptim';
$cachefiles = \Kirby\Toolkit\Dir::files($r);
foreach($cachefiles as $file) {
foreach ($cachefiles as $file) {
$md5 = basename($file, '.cache');
if($job = kirby()->cache('bnomei.thumbimageoptim')->get($md5)) {
if ($job = kirby()->cache('bnomei.thumbimageoptim')->get($md5)) {
if (is_array($job) && array_key_exists('dst', $job)) {
$dst = $job['dst'];
if (file_exists($dst)) {
Expand Down
25 changes: 3 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "bnomei/kirby3-thumb-imageoptim",
"description": "Kirby 3 Thumb Driver using Imageoptim",
"type": "plugin",
"version": "1.2.0",
"type": "kirby-plugin",
"version": "1.3.0",
"license": "MIT",
"authors": [
{
Expand All @@ -19,12 +19,7 @@
"thumb",
"component"
],
"suggest": {
},
"autoload": {
"files": [
"config.php"
],
"psr-4": {
"Bnomei\\": "classes/"
}
Expand All @@ -35,21 +30,7 @@
},
"require": {
"php": ">=7.1.0",
"getkirby/cms": "^3.0.0-RC-2.0",
"getkirby/composer-installer": "^1.1",
"imageoptim/imageoptim": "^1.3"
},
"conflict": {
"getkirby/kirby": "<3.0"
},
"scripts": {
"zip": [
"touch kirby3-thumb-imageoptim.zip",
"rm kirby3-thumb-imageoptim.zip",
"composer install --no-dev",
"composer remove getkirby/cms",
"composer dumpautoload -o",
"zip -r kirby3-thumb-imageoptim.zip . -x *.git*",
"composer require getkirby/cms:'^3.0.0-RC-2.0'"
]
}
}
105 changes: 105 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 0 additions & 33 deletions config.php

This file was deleted.

34 changes: 33 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
<?php

require_once __DIR__ . '/vendor/autoload.php';
@include_once __DIR__ . '/vendor/autoload.php';

Kirby::plugin('bnomei/thumbimageoptim', [
'options' => [
'optimize' => true,
'forceupload' => false,
'apikey' => null,
'defaults' => [
'io_quality' => 'medium',
'io_dpr' => '1',
],
'timelimit' => 30, // set_time_limit
'log.enabled' => false,
'log' => function (string $msg, string $level = 'info', array $context = []):bool {
if (option('bnomei.thumbimageoptim.log.enabled') && function_exists('kirbyLog')) {
kirbyLog('bnomei.thumbimageoptim.log')->log($msg, $level, $context);
return true;
}
return false;
},
'cache' => true,
],
'components' => [
'thumb' => function ($kirby, $src, $dst, $options) {
return \Bnomei\Imageoptim::thumb($src, $dst, $options);
}
],
'hooks' => [
'route:before' => function () {
\Bnomei\Imageoptim::removeFilesOfUnfinishedJobs();
},
],
]);
18 changes: 11 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Kirby 3 Thumb Imageoptim

![GitHub release](https://img.shields.io/github/release/bnomei/kirby3-thumb-imageoptim.svg?maxAge=1800) ![License](https://img.shields.io/github/license/mashape/apistatus.svg) ![Kirby Version](https://img.shields.io/badge/Kirby-3%2B-black.svg)
![GitHub release](https://img.shields.io/github/release/bnomei/kirby3-thumb-imageoptim.svg?maxAge=1800) ![License](https://img.shields.io/github/license/mashape/apistatus.svg) ![Kirby Version](https://img.shields.io/badge/Kirby-3%2B-black.svg) ![Kirby 3 Pluginkit](https://img.shields.io/badge/Pluginkit-YES-cca000.svg)

Kirby 3 CMS Thumb Component to optimize images using ImageOptim Api.

Expand All @@ -13,11 +13,9 @@ This plugin is free but if you use it in a commercial project please consider to

## Installation

- for devkit-setup use `composer require bnomei/kirby3-thumb-imageoptim` or
- extract latest release of [kirby3-thumb-imageoptim.zip](https://github.com/bnomei/kirby3-thumb-imageoptim/releases/download/v1.2.0/kirby3-thumb-imageoptim.zip) as folder `site/plugins/kirby3-thumb-imageoptim`

> Installation as a gitsubmodule is *not* supported.
- unzip [master.zip](https://github.com/bnomei/kirby3-thumb-imageoptim/archive/master.zip) as folder `site/plugins/kirby3-thumb-imageoptim` or
- `git submodule add https://github.com/bnomei/kirby3-thumb-imageoptim.git site/plugins/kirby3-thumb-imageoptim` or
- `composer require bnomei/kirby3-thumb-imageoptim`

## Requirements

Expand All @@ -42,11 +40,17 @@ echo $img->resize(234)->html();
```

> *TIP:*
> If you want your image to be optimized but retain original size use:
> If you want your image to be optimized but retain their original size use:
> `$img->resize()` without providing a width or height.
## Settings

**apikey**
- default: `null` – your imageoptim apikey as string

> TIP: you can also set a callback if you use the [dotenv Plugin](https://github.com/bnomei/kirby3-dotenv)
> `'bnomei.thumbimageoptim.apikey' => function() { return env('IMAGEOPTIM_APIKEY'); },`
### bnomei.thumbimageoptim.optimize
- default: `true`
- set to `false` to disable optimization with this plugin
Expand Down
7 changes: 7 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit438486ca4052af1f12bcb5232c4ed236::getLoader();
Loading

0 comments on commit 420e996

Please sign in to comment.