Initial commit

This commit is contained in:
isUnknown 2026-02-12 15:22:46 +01:00
commit 65e0da7e11
1397 changed files with 596542 additions and 0 deletions

View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016-2017 Joachim Robert
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View file

@ -0,0 +1,10 @@
/*
* Kirby ZipDownload default styles
* author: Joachim Robert <joachim.robert@gmail.com>
* version: 0.1
* changelog:
* O.1 : nothing to see here yet
*
*
*/

View file

@ -0,0 +1,12 @@
<?php
# cron.php
#
# Code copy/pasted from StackOverflow so you *know* it's good code. Right?
# …Right?
# Here's the URL anyways : http://stackoverflow.com/a/13468943
# Stichoza and Ewout, I owe you a beer whenever we meet.
$path = __DIR__ . "/temp/*";
array_map('unlink', ( glob( $path ) ? glob( $path ) : array() ) );
?>

View file

@ -0,0 +1,116 @@
<?php
// -------------------------------------------
// kirby plugin
// Title: ZipDownload
// function: This plugin provides basic capacity to select & download multiple image files as a zip.
// copyright: 2016 Joachim Robert <joachim.robert@gmail.com>
// license: https://creativecommons.org/licenses/by-sa/3.0/ CC BY-SA 3.0
// usage:
// see README.md
// version: 0.1 (14.08.2016)
// changelog:
// O.1 : initial release. Nothing much to see yet.
// -------------------------------------------
# This, you can change :
# No File Selected error message
function zipdl_errormessage_noFileSelected() {
# TODO : add support for multilang
echo "Error : no file was selected :(";
}
# Until the end of the file, you might not want to change :
function zipdl_dl_url() {
echo kirby()->urls()->index() . DS . 'download-zip'; // . basename(__DIR__) . '/download.php';
}
# Set the Download Button snippet
$kirby->set('snippet', 'zipdl_form_btn', __DIR__ . '/snippets/zipdl_form_btn.php');
# Set the Checkbox snippet
$kirby->set('snippet', 'zipdl_checkbox', __DIR__ . '/snippets/zipdl_checkbox.php');
# Set the Asset Gallery snippet
$kirby->set('snippet', 'asset_gallery', __DIR__ . '/snippets/asset_gallery.php');
# Set the /download route
# and define the main Zipping action
$kirby->set('route', array(
'pattern' => 'download-zip',
'method' => 'POST',
'action' => function() {
# get the POST values
# $current_page = strval($_POST["current_page"]);
# $selected_files = explode(',', $_POST["selection"]);
$selected_files = array();
foreach($_POST as $key => $value) {
if ($key == "current_page") {
$current_page = strval($value);
} else if($value=="on") {
# array_push($selected_files, strval(substr($key, 0, -4) . "." . substr($key, -3)));
array_push($selected_files, strval(substr($key, 0, strrpos($key, '_')) . "." . substr($key, strrpos($key, '_')+1)));
}
}
# set up an empty array
$files = array();
# loop through each file name
foreach(site()->page($current_page)->files() as $selected_file){
# check if the selected file exists as a file in the current page
# so it doesn't get abused
if($selected_file) {
# perhaps it would be best if a thumbnail of the image was called
# but I don't know if I can get the root address of the thumbnail
# fill up the main array with the root address of each image
array_push($files, $selected_file->root());
}
}
# only do the zip if we HAVE files
if (!empty($files)){
# this part of the code was adapted from StackOverflow
# http://stackoverflow.com/a/20216192
# Thank you all! I owe you all a beer.
# create new zip opbject
$zip = new ZipArchive();
# create a temp file & open it
$tmp_file = tempnam( kirby()->roots()->index() . '/site/plugins/kirby-zipdownload/temp' ,'');
$zip->open($tmp_file, ZipArchive::CREATE);
# loop through each file
foreach($files as $file){
# download file
$download_file = file_get_contents($file);
#add it to the zip
$zip->addFromString(basename($file),$download_file);
}
# close zip
$zip->close();
# send the file to the browser as a download
$name = site()->page($current_page)->uid().'_'.date('d-m-Y');
header('Content-disposition: attachment; filename='.$name.'.zip');
header('Content-type: application/zip');
readfile($tmp_file);
} else {
# That's a call to the function displaying the error message.
zipdl_errormessage_noFileSelected();
}
return false;
}
));

View file

@ -0,0 +1,8 @@
{
"name": "kirby-zipdownload",
"description": "This plugin provides basic capacity to select & download multiple image files as a zip.",
"author": "Joachim Robert <joachim.robert@gmail.com>",
"version": "0.1",
"type": "kirby-plugin",
"license": "CC BY-SA 3.0"
}

View file

@ -0,0 +1,50 @@
# Kirby ZipDownload
This [Kirby CMS](http://getkirby.com) plugin provides basic capacity to select & download multiple files as a zip.
## Version
0.1 : initial release
## Installation
1. Copy the plugin folder to `site/plugins`.
2. Make the folder `kirby-zipdownload/temp` writable.
3. Setup your server's `cron` file to execute `kirby-zipdownload/cron.php` regularly, so it empties `kirby-zipdownload/temp`.
4. Modify your template files and customize the snippets to your needs.
## Usage
There's two way to use the plugin.
### The simple way
Use the `asset_gallery` snippet, it's adapted from Kirby default theme's Projects template.
### The custom way
Use the `btn_dl` snippet where you want it. It's got an ID attribute so it's better if you don't reuse it.
Then, in the loop calling all the images/documents, use the snippet `checkbox`.
### Going further
The checkboxes can be styled and scripted at will, it's the checked/unchecked state that counts when the form is sent (via a POST request). You can hide the checkboxes and check them in JavaScript through other means.
## TODO
- i18n of the error message
- Using smaller versions of the images to fill the zip through the thumbnail API
(or ask the content editors to upload smaller images?)
- Basic CSS styles
## Copyright
© 2016 Joachim Robert
## License
MIT License

View file

@ -0,0 +1,38 @@
<?php
# Thank you http://stackoverflow.com/posts/2510459/revisions
function formatBytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
// Uncomment one of the following alternatives
$bytes /= pow(1024, $pow);
// $bytes /= (1 << (10 * $pow));
return round($bytes, $precision) . ' ' . $units[$pow];
}
?>
<div class="kirby-zipdl-asset-gallery">
<?php snippet('zipdl_form_btn'); ?>
<?php foreach($page->files()->sortBy('sort', 'asc') as $file): ?>
<?php snippet('zipdl_checkbox', array('file' => $file)); ?>
<?php if($file->type() == 'image'): ?>
<figure>
<img src="<?php echo $file->crop(300, 300)->url() ?>" alt="<?php echo $page->title()->html() ?>">
</figure>
<?php else : ?>
<p>
<a href="<?php echo $file->url() ?>" title="<?php echo $file->filename() ?>"><?php echo $file->name() ?>
<small>(<?php echo $file->extension() ?>, <?php echo formatBytes($file->size()) ?>)</small>
</a>
</p>
<?php endif ?>
<?php endforeach ?>
</div>

View file

@ -0,0 +1 @@
<input class="kirby-zipdl-checkbox" type="checkbox" name="<?php echo $file->filename() ?>" form="kirby-zipdl-form">

View file

@ -0,0 +1,6 @@
<form action="<?php zipdl_dl_url() ?>" method="post" accept-charset="utf-8">
<fieldset>
<input type="hidden" name="current_page" value="<?php echo $page->id() ?>">
<button type="submit"><?= l::get('download.all') ?></button>
</fieldset>
</form>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.