Skip to content

Commit 285f145

Browse files
committed
[CODE] BREAKING CHANGES: config options renamed, new version number
* config options according to the standard * cleanup code format * v2.0 to reflect the breaking changes and incompatibility with Kirby 2
1 parent 8f87155 commit 285f145

File tree

3 files changed

+71
-69
lines changed

3 files changed

+71
-69
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
by Jannik Beyerstedt from Hamburg, Germany
33
[jannikbeyerstedt.de](http://jannikbeyerstedt.de) | [Github](https://github.com/jbeyerstedt)
44
**license:** GNU GPL v3
5-
**version:** v1.0.0
5+
**version:** v2.0.0
66

77
## Notice About Branches and Kirby 2
88
Kirby 3 support was added in the `kirby3` branch, because Kirby 2 and Kirby 3 plugins are quite different.
99
Now that Kirby 3 is released, I changed the default branch to `kirby3` but will keep the `master`, because old Kirby 2 projects might break, if I rename the branches.
1010

11+
**Updating from the Kirby 2 version:** The configuration options are now prefixed by `jbeyerstedt.download` instead of `tags.download`.
12+
This is caused by the new way, how plugins work within Kirby 3.
13+
1114

1215
## Introduction
1316
**Kirbytag to generate beautiful download links for a specific file**
@@ -71,8 +74,8 @@ With the `text` attribute (replace `$someLinkText`) you can set a custom text, w
7174

7275
### Options
7376

74-
* `tags.download.class`: The class appended to the anchor-element (Default: `dl`)
75-
* `tags.download.warnings`: Inlines warnings if for example the given file couldn’t be found or the set is empty. (Default: `true`)
77+
* `jbeyerstedt.download.class`: The class appended to the anchor-element (Default: `dl`)
78+
* `jbeyerstedt.download.warnings`: Inlines warnings if for example the given file couldn’t be found or the set is empty. (Default: `true`)
7679

7780
You can set these in your `config.php` like this:
7881

@@ -92,9 +95,9 @@ A look like this can be achieved with the following CSS:
9295
```CSS
9396
a.dl {
9497
@mixin colored-badge($color: gray) {
95-
border-color: rgba($color, .3);
96-
background: rgba($color, .1);
97-
color: $color;
98+
border-color: rgba($color, .3);
99+
background: rgba($color, .1);
100+
color: $color;
98101
}
99102

100103
&:before {

index.php

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
<?php
22
/*
3-
* kirby 3 tag - download
3+
* kirby 3 kirbytag - download
44
* return a beautiful download link for all/ specific/ first/ last file
55
*
66
* copyright: Jannik Beyerstedt | http://jannikbeyerstedt.de | [email protected]
77
* license: http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 License
8-
*
9-
* sample usage:
10-
* (download: $keyword type: $filetype ext: $extension text: $someLinkText)
11-
* $keyword: type "all" for all files in collection, "first" or "last" for first/ last of collection, or specify the filename
12-
* $filetype: filetype to choose: document/ code/ images/ videos
13-
* $extension: filename extension to filter
148
*/
159

1610
Kirby::plugin('jbeyerstedt/download', [
11+
'options' => [
12+
'class' => 'dl',
13+
'warnings' => 'true'
14+
],
1715
'tags' => [
1816
'download' => [
1917
'attr' => [
@@ -22,68 +20,69 @@
2220
'ext'
2321
],
2422
'html' => function($tag) {
25-
2623
$types = array('image',
27-
'document',
28-
'archive',
29-
'code',
30-
'video',
31-
'audio');
32-
33-
$files = $tag->parent()->files();
34-
$class = option('tags.download.class', 'dl');
35-
$warnings = option('tags.download.warnings', true);
36-
37-
if ($tag->attr('type') != "") {
38-
if(in_array($tag->attrs['type'], $types)) {
39-
$files = $files->filterBy('type', $tag->attrs['type']);
40-
}else {
41-
return $warnings ? '<b>ERROR: download - no valid type defined</b>' : '';
42-
}
43-
}
24+
'document',
25+
'archive',
26+
'code',
27+
'video',
28+
'audio');
29+
30+
$files = $tag->parent()->files();
31+
$class = option('jbeyerstedt.download.class');
32+
$warnings = option('jbeyerstedt.download.warnings');
33+
34+
if ($tag->attr('type') != "") {
35+
if(in_array($tag->attrs['type'], $types)) {
36+
$files = $files->filterBy('type', $tag->attrs['type']);
37+
} else {
38+
return $warnings ? '<b>ERROR: download - no valid type defined</b>' : '';
39+
}
40+
}
41+
42+
if ($tag->ext != "") {
43+
$files = $files->filterBy('extension', $tag->ext);
44+
}
45+
46+
if (!$files || $files->count() == 0) {
47+
return $warnings ? '<b>WARNING</b>: no file(s) selected' : '';
48+
}
4449

45-
if ($tag->ext != "") {
46-
$files = $files->filterBy('extension', $tag->ext);
47-
}
50+
if ($tag->value == 'first') {
51+
$files = $files->first();
52+
} else if ($tag->value == 'last') {
53+
$files = $files->last();
54+
} else if ($tag->value == 'all') {
55+
$files = $files;
56+
} else{
57+
$files = $files->find($tag->value);
58+
}
4859

49-
if (!$files || $files->count() == 0) {
50-
return $warnings ? '<b>WARNING</b>: no file(s) selected' : '';
51-
}
60+
if (!$files) {
61+
return $warnings ? '<b>WARNING</b>: file(s) could not be found.' : '';
62+
}
5263

53-
if ($tag->value == 'first') {
54-
$files = $files->first();
55-
}else if ($tag->value == 'last') {
56-
$files = $files->last();
57-
}else if ($tag->value == 'all') {
58-
$files = $files;
59-
}else{
60-
$files = $files->find($tag->value);
61-
}
64+
if ($tag->value == 'all') {
65+
$html = '<ul>';
66+
foreach ($files as $file) {
67+
$ext = $file->extension();
68+
$classes = $class . " " . $class . "--" . $ext; // i.e. "dl dl--pdf"
69+
$text = $file->filename();
70+
$html .= '<li>';
71+
$html .= '<a class="'. $classes .'" href="'.$file->url().'" data-ext="'. $ext .'" target="_blank" download>'.$text.'</a> <small>('.$file->niceSize().')</small>';
72+
$html .= '</li>';
73+
}
6274

63-
if (!$files) {
64-
return $warnings ? '<b>WARNING</b>: file(s) could not be found.' : '';
65-
}
75+
$html .= '</ul>';
6676

67-
if ($tag->value == 'all') {
68-
$html = '<ul>';
69-
foreach ($files as $file) {
70-
$ext = $file->extension();
71-
$classes = $class . " " . $class . "--" . $ext; // i.e. "dl dl--pdf"
72-
$text = $file->filename();
73-
$html .= '<li>';
74-
$html .= '<a class="'. $classes .'" href="'.$file->url().'" data-ext="'. $ext .'" target="_blank" download>'.$text.'</a> <small>('.$file->niceSize().')</small>';
75-
$html .= '</li>';
76-
}
77+
return $html;
78+
} else {
79+
// switch link text: filename or custom text
80+
$ext = $files->extension();
81+
$classes = $class . " " . $class . "--" . $ext; // i.e. "dl dl--pdf"
82+
(empty($tag->attrs['text'])) ? $text = $files->filename() : $text = $tag->attrs['text'];
7783

78-
$html .= '</ul>';
79-
return $html;
80-
} else{
81-
// switch link text: filename or custom text
82-
$ext = $files->extension();
83-
$classes = $class . " " . $class . "--" . $ext; // i.e. "dl dl--pdf"
84-
(empty($tag->attrs['text'])) ? $text = $files->filename() : $text = $tag->attrs['text'];
85-
return '<a class="'. $classes .'" href="'.$files->url().'" data-ext="'. $ext .'" target="_blank" download>'.$text.'</a> <small>('.$files->niceSize().')</small>';
86-
}
84+
return '<a class="'. $classes .'" href="'.$files->url().'" data-ext="'. $ext .'" target="_blank" download>'.$text.'</a> <small>('.$files->niceSize().')</small>';
85+
}
8786

8887
}
8988
]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "jbeyerstedt/download",
33
"description": "Kirbytag to generate beautiful download links for a specific file",
44
"author": "Jannik Beyerstedt <[email protected]>",
5-
"version": "1.0.0",
5+
"version": "2.0.0",
66
"license": "GNU GPLv3",
77
"autoload": {
88
"files": ["config.php"],

0 commit comments

Comments
 (0)