├── .gitignore ├── autobuster.php ├── package.json ├── LICENSE.md ├── README.md └── lib ├── css.php └── js.php /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /autobuster.php: -------------------------------------------------------------------------------- 1 | __DIR__ . DS . 'lib' . DS . 'css.php', 7 | 'kirby\\autobuster\\js' => __DIR__ . DS . 'lib' . DS . 'js.php' 8 | ]); 9 | 10 | kirby()->set('component', 'css', 'Kirby\\Autobuster\\CSS'); 11 | kirby()->set('component', 'js', 'Kirby\\Autobuster\\JS'); 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "autobuster", 3 | "description": "Kirby Autobuster Plugin", 4 | "version": "2.2.0", 5 | "type": "kirby-plugin", 6 | "contributors": [ 7 | "Bastian Allgeier (https://getkirby.com)", 8 | "Lukas Bestle (https://getkirby.com)", 9 | "Sonja Broda (https://getkirby.com)", 10 | "Lukas Kleinschmidt (https://github.com/lukaskleinschmidt)", 11 | "James Steel (https://hashandsalt.com)" 12 | ], 13 | "license": "MIT", 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/HashandSalt/autobuster" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2018 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kirby Autobuster Plugin 2 | 3 | This plugin is based on the original Cachebuster by Bastian Allgeier, the modified version by Lukas Kleinschmidt with further modifications & enhancemnets by Sonja Broda & James Steel. 4 | 5 | Original plugin did not cache bust autoloaded Javascript or CSS. This plugin does. 6 | 7 | ## Commerical Usage 8 | 9 | This plugin is free but if you use it in a commercial project please consider to 10 | - [make a donation 🍻](https://paypal.me/hashandsalt?locale.x=en_GB) or 11 | - [buy a Kirby license using this affiliate link](https://a.paddle.com/v2/click/1129/36141?link=1170) 12 | 13 | ## Features 14 | 15 | * No longer requires modifications to server configuration files 16 | * Will cache bust auto loaded CSS & JavaScript 17 | 18 | ## Requirements 19 | 20 | This plugin requires Kirby 2.4+ 21 | 22 | ## Installation 23 | 24 | To use this plugin, place all the files in `site/plugins/autobuster`. 25 | 26 | Now you can activate the plugin with following line in your `config.php`. 27 | 28 | ``` 29 | c::set('autobuster', true); 30 | ``` 31 | 32 | ## Authors 33 | 34 | Bastian Allgeier, Lukas Bestle, Lukas Kleinschmidt, Sonja Broda & James Steel 35 | -------------------------------------------------------------------------------- /lib/css.php: -------------------------------------------------------------------------------- 1 | 12 | * @link http://getkirby.com 13 | * @copyright Bastian Allgeier 14 | * @license http://getkirby.com/license 15 | */ 16 | class CSS extends \Kirby\Component\CSS { 17 | 18 | /** 19 | * Builds the html link tag for the given css file 20 | * 21 | * @param string $url 22 | * @param null|string $media 23 | * @return string 24 | */ 25 | public function tag($url, $media = null) { 26 | 27 | if(is_array($url)) { 28 | $css = array(); 29 | foreach($url as $u) $css[] = $this->tag($u, $media); 30 | return implode(PHP_EOL, $css) . PHP_EOL; 31 | } 32 | 33 | // auto template css files 34 | if ($url == '@auto') { 35 | $template = $this->kirby->site()->page()->template(); 36 | $file = $template . '.css'; 37 | $root = $this->kirby->roots()->autocss() . DS . $file; 38 | if (file_exists($root)) { 39 | $mod = f::modified($root); 40 | $url = $this->kirby->urls()->autocss() . '/' . $template . '.css' . '?v=' . $mod; 41 | } else { 42 | return false; 43 | } 44 | } else { 45 | $file = kirby()->roots()->index() . DS . $url; 46 | 47 | if (file_exists($file)) { 48 | $mod = f::modified($file); 49 | $url = dirname($url) . '/' . f::filename($url) . '?v=' . $mod; 50 | } 51 | } 52 | 53 | 54 | return parent::tag($url, $media); 55 | 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /lib/js.php: -------------------------------------------------------------------------------- 1 | 14 | * @link http://getkirby.com 15 | * @copyright Bastian Allgeier 16 | * @license http://getkirby.com/license 17 | */ 18 | class JS extends \Kirby\Component\JS 19 | { 20 | /** 21 | * Builds the html script tag for the given javascript file 22 | * 23 | * @param string $src 24 | * @param boolean async 25 | * @return string 26 | */ 27 | public function tag($src, $async = false) 28 | { 29 | if (is_array($src)) { 30 | $js = array(); 31 | foreach ($src as $s) { 32 | $js[] = $this->tag($s, $async); 33 | } 34 | return implode(PHP_EOL, $js) . PHP_EOL; 35 | } 36 | 37 | // auto template js files 38 | if ($src == '@auto') { 39 | $template = $this->kirby->site()->page()->template(); 40 | $file = $template . '.js'; 41 | $root = $this->kirby->roots()->autojs() . DS . $file; 42 | if (file_exists($root)) { 43 | $mod = f::modified($root); 44 | $src = $this->kirby->urls()->autojs() . '/' . $template . '.js' . '?v=' . $mod; 45 | } else { 46 | return false; 47 | } 48 | } else { 49 | $file = kirby()->roots()->index() . DS . $src; 50 | 51 | if (file_exists($file)) { 52 | $mod = f::modified($file); 53 | $src = dirname($src) . '/' . f::filename($src) . '?v=' . $mod; 54 | } 55 | } 56 | 57 | // build the array of HTML attributes 58 | $attr = array('src' => url($src)); 59 | if (is_array($async)) { 60 | $attr = array_merge($attr, $async); 61 | } elseif ($async === true) { 62 | $attr['async'] = true; 63 | } 64 | return html::tag('script', '', $attr); 65 | } 66 | } 67 | --------------------------------------------------------------------------------