Skip to content
Permalink
Browse files

🎉 inital commit

Signed-off-by: Bruno Meilick <b@bnomei.com>
  • Loading branch information
bnomei committed Oct 24, 2019
1 parent 02945c6 commit b2538a26662bfaa0bb05598b4821f05107627b6f
Showing with 875 additions and 476 deletions.
  1. +49 −7 README.md
  2. +75 −0 classes/QRCode.php
  3. +8 −2 composer.json
  4. +292 −291 composer.lock
  5. +7 −0 index.php
  6. +57 −0 tests/.htaccess
  7. +57 −0 tests/QRCodeTest.php
  8. 0 tests/content/ukulele/default.txt
  9. +3 −0 tests/index.php
  10. +5 −0 tests/site/templates/default.php
  11. +5 −0 tests/site/templates/default.svg.php
  12. +1 −1 vendor/endroid/qr-code/README.md
  13. +10 −0 vendor/endroid/qr-code/src/Factory/QrCodeFactory.php
  14. +40 −5 vendor/endroid/qr-code/src/QrCode.php
  15. +22 −0 vendor/endroid/qr-code/src/Writer/AbstractWriter.php
  16. +35 −7 vendor/endroid/qr-code/src/Writer/PngWriter.php
  17. +28 −37 vendor/endroid/qr-code/src/Writer/SvgWriter.php
  18. +6 −3 vendor/endroid/qr-code/src/WriterRegistry.php
  19. +2 −0 vendor/endroid/qr-code/src/WriterRegistryInterface.php
  20. +2 −2 vendor/symfony/http-foundation/BinaryFileResponse.php
  21. +1 −1 vendor/symfony/http-foundation/CHANGELOG.md
  22. +16 −5 vendor/symfony/http-foundation/Cookie.php
  23. +2 −0 vendor/symfony/http-foundation/File/MimeType/ExtensionGuesser.php
  24. +3 −3 vendor/symfony/http-foundation/File/MimeType/FileBinaryMimeTypeGuesser.php
  25. +3 −3 vendor/symfony/http-foundation/File/MimeType/FileinfoMimeTypeGuesser.php
  26. +2 −0 vendor/symfony/http-foundation/File/MimeType/MimeTypeGuesser.php
  27. +1 −1 vendor/symfony/http-foundation/File/MimeType/MimeTypeGuesserInterface.php
  28. +18 −5 vendor/symfony/http-foundation/File/UploadedFile.php
  29. +3 −5 vendor/symfony/http-foundation/FileBag.php
  30. +9 −1 vendor/symfony/http-foundation/HeaderBag.php
  31. +0 −1 vendor/symfony/http-foundation/HeaderUtils.php
  32. +1 −1 vendor/symfony/http-foundation/JsonResponse.php
  33. +1 −1 vendor/symfony/http-foundation/ParameterBag.php
  34. +1 −1 vendor/symfony/http-foundation/RedirectResponse.php
  35. +23 −13 vendor/symfony/http-foundation/Request.php
  36. +1 −4 vendor/symfony/http-foundation/RequestMatcher.php
  37. +3 −3 vendor/symfony/http-foundation/RequestStack.php
  38. +6 −6 vendor/symfony/http-foundation/Response.php
  39. +1 −1 vendor/symfony/http-foundation/ServerBag.php
  40. +1 −1 vendor/symfony/http-foundation/Session/Attribute/NamespacedAttributeBag.php
  41. +9 −1 vendor/symfony/http-foundation/Session/Storage/Handler/AbstractSessionHandler.php
  42. +4 −7 vendor/symfony/http-foundation/Session/Storage/Handler/MemcachedSessionHandler.php
  43. +1 −1 vendor/symfony/http-foundation/Session/Storage/Handler/MigratingSessionHandler.php
  44. +1 −1 vendor/symfony/http-foundation/Session/Storage/Handler/MongoDbSessionHandler.php
  45. +1 −1 vendor/symfony/http-foundation/Session/Storage/Handler/NativeFileSessionHandler.php
  46. +1 −1 vendor/symfony/http-foundation/Session/Storage/Handler/NullSessionHandler.php
  47. +5 −5 vendor/symfony/http-foundation/Session/Storage/Handler/PdoSessionHandler.php
  48. +4 −4 vendor/symfony/http-foundation/Session/Storage/Handler/RedisSessionHandler.php
  49. +1 −1 vendor/symfony/http-foundation/Session/Storage/Handler/StrictSessionHandler.php
  50. +14 −9 vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php
  51. +1 −1 vendor/symfony/http-foundation/Session/Storage/Proxy/AbstractProxy.php
  52. +1 −1 vendor/symfony/http-foundation/Session/Storage/Proxy/SessionHandlerProxy.php
  53. +1 −1 vendor/symfony/http-foundation/Session/Storage/SessionStorageInterface.php
  54. +0 −2 vendor/symfony/http-foundation/StreamedResponse.php
  55. +6 −0 vendor/symfony/inflector/Inflector.php
  56. +3 −3 vendor/symfony/mime/Address.php
  57. +8 −4 vendor/symfony/mime/Email.php
  58. +0 −3 vendor/symfony/mime/Header/MailboxHeader.php
  59. +1 −1 vendor/symfony/mime/Header/ParameterizedHeader.php
  60. +4 −4 vendor/symfony/mime/MimeTypes.php
  61. +1 −1 vendor/symfony/mime/NamedAddress.php
  62. +0 −4 vendor/symfony/mime/Resources/bin/update_mime_types.php
  63. +5 −4 vendor/symfony/property-access/PropertyAccessor.php
  64. +0 −2 vendor/symfony/property-access/PropertyAccessorBuilder.php
  65. +1 −1 vendor/symfony/property-access/PropertyPath.php
  66. +1 −1 vendor/symfony/property-access/PropertyPathBuilder.php
  67. +1 −1 vendor/symfony/property-access/PropertyPathInterface.php
@@ -11,8 +11,7 @@
[![Gitter](https://flat.badgen.net/badge/gitter/chat?color=982ab3)](https://gitter.im/bnomei-kirby-3-plugins/community)
[![Twitter](https://flat.badgen.net/badge/twitter/bnomei?color=66d9ef)](https://twitter.com/bnomei)


@@@TODO@@@
Generate QRCodes easily.

## Commercial Usage

@@ -27,13 +26,56 @@ This plugin is free but if you use it in a commercial project please consider to
- `git submodule add https://github.com/bnomei/kirby3-qrcode.git site/plugins/kirby3-qrcode` or
- `composer require bnomei/kirby3-qrcode`

## Works well with

- [Previews](https://github.com/sylvainjule/kirby-previews)

## Usecase

@@@TODO@@@
### Raw PHP

```php
$qrcodeObject = new \Bnomei\QRCode([
'Text' => 'https://github.com/bnomei/kirby3-qrcode',
]);
echo $qrcodeObject->html();
```

### Page Method

**site/templates/default.php**
```php
// base64 encoded png image tag
// with $page->url() as Text
echo $page->qrcode()->html(
$page->slug() . '.png' // image format detected from extension
);
```

### Trigger download

**site/templates/default.qr.php**
```php
$page->qrcode()->download(
$page->slug() . '.svg'
);
```

### Further customization of the generated image

[Advanced options](https://github.com/endroid/qr-code#advanced-usage) can be set.
```php
echo $page->qrcode([
'Margin' => 10,
'Encoding' => 'UTF-8',
'ForegroundColor' => ['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0],
'BackgroundColor' => ['r' => 255, 'g' => 255, 'b' => 255, 'a' > 0]),
'Label' => ['Scan the code', 16, __DIR__.'/../assets/fons/noto_sans.otf', LabelAlignment::CENTER];
'LogoPath' => __DIR__.'/../assets/images/getkirby.png',
'LogoSize' => [150, 200],
'RoundBlockSize' => true,
])->html(
$page->slug() . '.png'
);
```

> Attention: In this plugin options are single value or an array.
## Dependencies

@@ -4,7 +4,82 @@
namespace Bnomei;
use Kirby\Cms\Html;
use Kirby\Http\Header;
use Kirby\Toolkit\A;
final class QRCode
{
/** @var \Endroid\QrCode\QrCode */
private $qrCode;
/** @var array */
private $options;
/**
* QRCode constructor.
* @param array $options
*/
public function __construct(array $options = [])
{
$this->options = $options;
$text = A::get($this->options, 'Text');
$this->qrCode = new \Endroid\QrCode\QrCode($text);
foreach ($options as $option => $value) {
$setterName = 'set' . $option;
if ($option === 'Text' || method_exists($this->qrCode, $setterName) === false) {
continue;
}
if (in_array($option, ['Label', 'LogoSize'])) {
// call function with params instead of array
call_user_func_array([$this->qrCode, $setterName], $value);
} else {
$this->qrCode->{$setterName}($value);
}
}
}
/**
* @return \Endroid\QrCode\QrCode
*/
public function qrcode()
{
return $this->qrCode;
}
/**
* @param string $name
* @param array $attrs
* @return string
* @throws \Endroid\QrCode\Exception\UnsupportedExtensionException
*/
public function html(string $name, array $attrs = []): string
{
$extension = pathinfo($name, PATHINFO_EXTENSION);
$this->qrCode->setWriterByExtension($extension);
$data = $this->qrCode->writeString();
return Html::tag('img', null, array_merge($attrs, [
'src' => 'data:image/' . $extension . ';base64,' . base64_encode($data)
]));
}
/**
* @param string $name
* @throws \Endroid\QrCode\Exception\UnsupportedExtensionException
*/
public function download(string $name)
{
Header::download([
'mime' => $this->qrCode->getContentType(),
'name' => $name,
]);
// @codeCoverageIgnoreStart
$extension = pathinfo($name, PATHINFO_EXTENSION);
$this->qrCode->setWriterByExtension($extension);
echo $this->qrCode->writeString();
// @codeCoverageIgnoreEnd
}
}
@@ -1,6 +1,6 @@
{
"name": "bnomei/kirby3-qrcode",
"description": "Generate QRCode Files",
"description": "Generate QRCodes",
"type": "kirby-plugin",
"version": "1.0.0",
"license": "MIT",
@@ -17,6 +17,7 @@
"qrcode",
"qr-code",
"image",
"jpg",
"png",
"svg"
],
@@ -51,13 +52,18 @@
"dist": [
"composer install --no-dev --optimize-autoloader",
"git rm -rf --cached .; git add .;"
],
"kirby": [
"composer install",
"composer update",
"composer install --working-dir=tests/kirby --no-dev --optimize-autoloader",
"composer update --working-dir=tests/kirby"
]
},
"extra": {
"kirby-cms-path": "tests/kirby"
},
"suggest": {
"sylvainjule/kirby-previews": "Preview QRCode inside the structure field",
"bnomei/kirby3-janitor": "Provides tools to add a custom Panel button to trigger download of ICS/CSV/QRCode Files"
}
}

0 comments on commit b2538a2

Please sign in to comment.
You can’t perform that action at this time.