-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
1 parent
8f87155
commit 285f145
Showing
3 changed files
with
71 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
<?php | ||
/* | ||
* kirby 3 tag - download | ||
* kirby 3 kirbytag - download | ||
* return a beautiful download link for all/ specific/ first/ last file | ||
* | ||
* copyright: Jannik Beyerstedt | http://jannikbeyerstedt.de | [email protected] | ||
* license: http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 License | ||
* | ||
* sample usage: | ||
* (download: $keyword type: $filetype ext: $extension text: $someLinkText) | ||
* $keyword: type "all" for all files in collection, "first" or "last" for first/ last of collection, or specify the filename | ||
* $filetype: filetype to choose: document/ code/ images/ videos | ||
* $extension: filename extension to filter | ||
*/ | ||
|
||
Kirby::plugin('jbeyerstedt/download', [ | ||
'options' => [ | ||
'class' => 'dl', | ||
'warnings' => 'true' | ||
], | ||
'tags' => [ | ||
'download' => [ | ||
'attr' => [ | ||
|
@@ -22,68 +20,69 @@ | |
'ext' | ||
], | ||
'html' => function($tag) { | ||
|
||
$types = array('image', | ||
'document', | ||
'archive', | ||
'code', | ||
'video', | ||
'audio'); | ||
|
||
$files = $tag->parent()->files(); | ||
$class = option('tags.download.class', 'dl'); | ||
$warnings = option('tags.download.warnings', true); | ||
|
||
if ($tag->attr('type') != "") { | ||
if(in_array($tag->attrs['type'], $types)) { | ||
$files = $files->filterBy('type', $tag->attrs['type']); | ||
}else { | ||
return $warnings ? '<b>ERROR: download - no valid type defined</b>' : ''; | ||
} | ||
} | ||
'document', | ||
'archive', | ||
'code', | ||
'video', | ||
'audio'); | ||
|
||
$files = $tag->parent()->files(); | ||
$class = option('jbeyerstedt.download.class'); | ||
$warnings = option('jbeyerstedt.download.warnings'); | ||
|
||
if ($tag->attr('type') != "") { | ||
if(in_array($tag->attrs['type'], $types)) { | ||
$files = $files->filterBy('type', $tag->attrs['type']); | ||
} else { | ||
return $warnings ? '<b>ERROR: download - no valid type defined</b>' : ''; | ||
} | ||
} | ||
|
||
if ($tag->ext != "") { | ||
$files = $files->filterBy('extension', $tag->ext); | ||
} | ||
|
||
if (!$files || $files->count() == 0) { | ||
return $warnings ? '<b>WARNING</b>: no file(s) selected' : ''; | ||
} | ||
|
||
if ($tag->ext != "") { | ||
$files = $files->filterBy('extension', $tag->ext); | ||
} | ||
if ($tag->value == 'first') { | ||
$files = $files->first(); | ||
} else if ($tag->value == 'last') { | ||
$files = $files->last(); | ||
} else if ($tag->value == 'all') { | ||
$files = $files; | ||
} else{ | ||
$files = $files->find($tag->value); | ||
} | ||
|
||
if (!$files || $files->count() == 0) { | ||
return $warnings ? '<b>WARNING</b>: no file(s) selected' : ''; | ||
} | ||
if (!$files) { | ||
return $warnings ? '<b>WARNING</b>: file(s) could not be found.' : ''; | ||
} | ||
|
||
if ($tag->value == 'first') { | ||
$files = $files->first(); | ||
}else if ($tag->value == 'last') { | ||
$files = $files->last(); | ||
}else if ($tag->value == 'all') { | ||
$files = $files; | ||
}else{ | ||
$files = $files->find($tag->value); | ||
} | ||
if ($tag->value == 'all') { | ||
$html = '<ul>'; | ||
foreach ($files as $file) { | ||
$ext = $file->extension(); | ||
$classes = $class . " " . $class . "--" . $ext; // i.e. "dl dl--pdf" | ||
$text = $file->filename(); | ||
$html .= '<li>'; | ||
$html .= '<a class="'. $classes .'" href="'.$file->url().'" data-ext="'. $ext .'" target="_blank" download>'.$text.'</a> <small>('.$file->niceSize().')</small>'; | ||
$html .= '</li>'; | ||
} | ||
|
||
if (!$files) { | ||
return $warnings ? '<b>WARNING</b>: file(s) could not be found.' : ''; | ||
} | ||
$html .= '</ul>'; | ||
|
||
if ($tag->value == 'all') { | ||
$html = '<ul>'; | ||
foreach ($files as $file) { | ||
$ext = $file->extension(); | ||
$classes = $class . " " . $class . "--" . $ext; // i.e. "dl dl--pdf" | ||
$text = $file->filename(); | ||
$html .= '<li>'; | ||
$html .= '<a class="'. $classes .'" href="'.$file->url().'" data-ext="'. $ext .'" target="_blank" download>'.$text.'</a> <small>('.$file->niceSize().')</small>'; | ||
$html .= '</li>'; | ||
} | ||
return $html; | ||
} else { | ||
// switch link text: filename or custom text | ||
$ext = $files->extension(); | ||
$classes = $class . " " . $class . "--" . $ext; // i.e. "dl dl--pdf" | ||
(empty($tag->attrs['text'])) ? $text = $files->filename() : $text = $tag->attrs['text']; | ||
|
||
$html .= '</ul>'; | ||
return $html; | ||
} else{ | ||
// switch link text: filename or custom text | ||
$ext = $files->extension(); | ||
$classes = $class . " " . $class . "--" . $ext; // i.e. "dl dl--pdf" | ||
(empty($tag->attrs['text'])) ? $text = $files->filename() : $text = $tag->attrs['text']; | ||
return '<a class="'. $classes .'" href="'.$files->url().'" data-ext="'. $ext .'" target="_blank" download>'.$text.'</a> <small>('.$files->niceSize().')</small>'; | ||
} | ||
return '<a class="'. $classes .'" href="'.$files->url().'" data-ext="'. $ext .'" target="_blank" download>'.$text.'</a> <small>('.$files->niceSize().')</small>'; | ||
} | ||
|
||
} | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"name": "jbeyerstedt/download", | ||
"description": "Kirbytag to generate beautiful download links for a specific file", | ||
"author": "Jannik Beyerstedt <[email protected]>", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"license": "GNU GPLv3", | ||
"autoload": { | ||
"files": ["config.php"], | ||
|