├── Dropshare-LandingPage.html ├── README.md ├── assets ├── css │ ├── bootstrap.min.css │ └── kirbydrop.css ├── images │ ├── archive.png │ ├── audio.png │ ├── code.png │ ├── document.png │ ├── image.png │ ├── other.png │ └── video.png └── js │ ├── bootstrap.min.js │ └── jquery.js ├── content └── uploads │ └── uploads.html ├── kirby └── toolkit │ └── lib │ └── f.php └── site ├── config └── config.php ├── snippets ├── files │ ├── everythingelse.php │ └── image.php ├── filetypes.php ├── footer.php └── header.php └── templates ├── index.php └── uploads.php /Dropshare-LandingPage.html: -------------------------------------------------------------------------------- 1 | Title: __FILENAME__ 2 | 3 | ---- 4 | 5 | Path: __PATH__ 6 | 7 | ---- 8 | 9 | Filesize: __FILESIZE__ 10 | 11 | ---- 12 | 13 | Unixdate: __UNIXSHAREDATE__ 14 | 15 | ---- 16 | 17 | Sharedate: __SHAREDATE__ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kirbydrop - File list theme for Dropshare uploads 2 | 3 | [Kirbydrop](http://cemk.github.io/kirbydrop/) is a [Kirby CMS](http://getkirby.com) theme to list your [Dropshare](http://getdropsha.re) uploads. 4 | 5 | ##Installing Kirby and Kirbydrop 6 | 1) Get Kirby’s plainkit, the barebones Kirby installation. 7 | 8 | git clone --recursive https://github.com/getkirby/plainkit.git . 9 | 10 | 2) Get Kirbydrop, and place the files into the Kirby installation. 11 | ``` 12 | git clone https://github.com/cemk/kirbydrop.git 13 | cd kirbydrop 14 | rsync -r * ../ 15 | ``` 16 | 17 | ##Setting up Dropshare 18 | 3) Create a new *SCP over SSH* connection with your server details. 19 | 4) “Save files at:” should be *[path up to Kirby root]/contents/uploads*. Set “URL to path:” as the root URL of your Kirby installation. 20 | 5) Put the *Dropshare-LandingPage.html* file to your Documents folder, turn on “Create Landing Page for your uploads” from Dropshare settings, and select “Use own design.” 21 | 22 | ###Make sure to... 23 | - Have PHP 5.5+ 24 | - Enable mod_rewrite 25 | - “Completely Randomize” filenames from Dropshare’s Upload settings 26 | - Optionally, install the Relative Date plugin by distantnative 27 | -------------------------------------------------------------------------------- /assets/css/kirbydrop.css: -------------------------------------------------------------------------------- 1 | /* @override 2 | http://localhost:8000/assets/css/kirbydrop.css */ 3 | 4 | /*! 5 | * Start Bootstrap - Shop Homepage HTML Template (http://startbootstrap.com) 6 | * Code licensed under the Apache License v2.0. 7 | * For details, see http://www.apache.org/licenses/LICENSE-2.0. 8 | */ 9 | 10 | body { 11 | padding-top: 70px; /* Required padding for .navbar-fixed-top. Remove if using .navbar-static-top. Change if height of navigation changes. */ 12 | } 13 | 14 | .slide-image { 15 | width: 100%; 16 | } 17 | 18 | .carousel-holder { 19 | margin-bottom: 30px; 20 | } 21 | 22 | .carousel-control, 23 | .item { 24 | border-radius: 4px; 25 | } 26 | 27 | 28 | .imagethumb img { 29 | height: 120px; 30 | object-fit: cover; 31 | background-color: rgba(24, 188, 156, 0.34); 32 | } 33 | 34 | .thumbnail img { 35 | width: 100%; 36 | 37 | } 38 | 39 | 40 | .thumbnail { 41 | padding: 0; 42 | /*height: 200px;*/ 43 | } 44 | 45 | .thumbnail .caption-full { 46 | padding: 9px; 47 | color: #333; 48 | } 49 | 50 | footer { 51 | margin: 50px 0; 52 | } 53 | 54 | .item:nth-child(3n+1){ 55 | clear: both; 56 | } 57 | 58 | p.date { 59 | font-style: italic; 60 | color: #b4b4b4; 61 | } 62 | 63 | p { 64 | word-wrap: break-word; 65 | } 66 | 67 | .filetitle { 68 | font-size: 25px; 69 | word-wrap: break-word; 70 | } 71 | 72 | .titleRow { 73 | padding-bottom: 25px; 74 | padding-top: 15px; 75 | } 76 | 77 | .downloadRow { 78 | padding-bottom: 20px; 79 | } -------------------------------------------------------------------------------- /assets/images/archive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cemk/kirbydrop/8934b5c82ed4f2a01f1d3c754171bb2033c65243/assets/images/archive.png -------------------------------------------------------------------------------- /assets/images/audio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cemk/kirbydrop/8934b5c82ed4f2a01f1d3c754171bb2033c65243/assets/images/audio.png -------------------------------------------------------------------------------- /assets/images/code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cemk/kirbydrop/8934b5c82ed4f2a01f1d3c754171bb2033c65243/assets/images/code.png -------------------------------------------------------------------------------- /assets/images/document.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cemk/kirbydrop/8934b5c82ed4f2a01f1d3c754171bb2033c65243/assets/images/document.png -------------------------------------------------------------------------------- /assets/images/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cemk/kirbydrop/8934b5c82ed4f2a01f1d3c754171bb2033c65243/assets/images/image.png -------------------------------------------------------------------------------- /assets/images/other.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cemk/kirbydrop/8934b5c82ed4f2a01f1d3c754171bb2033c65243/assets/images/other.png -------------------------------------------------------------------------------- /assets/images/video.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cemk/kirbydrop/8934b5c82ed4f2a01f1d3c754171bb2033c65243/assets/images/video.png -------------------------------------------------------------------------------- /assets/js/bootstrap.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap v3.3.4 (http://getbootstrap.com) 3 | * Copyright 2011-2015 Twitter, Inc. 4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) 5 | */ 6 | if("undefined"==typeof jQuery)throw new Error("Bootstrap's JavaScript requires jQuery");+function(a){"use strict";var b=a.fn.jquery.split(" ")[0].split(".");if(b[0]<2&&b[1]<9||1==b[0]&&9==b[1]&&b[2]<1)throw new Error("Bootstrap's JavaScript requires jQuery version 1.9.1 or higher")}(jQuery),+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]};return!1}a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one("bsTransitionEnd",function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b(),a.support.transition&&(a.event.special.bsTransitionEnd={bindType:a.support.transition.end,delegateType:a.support.transition.end,handle:function(b){return a(b.target).is(this)?b.handleObj.handler.apply(this,arguments):void 0}})})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var c=a(this),e=c.data("bs.alert");e||c.data("bs.alert",e=new d(this)),"string"==typeof b&&e[b].call(c)})}var c='[data-dismiss="alert"]',d=function(b){a(b).on("click",c,this.close)};d.VERSION="3.3.4",d.TRANSITION_DURATION=150,d.prototype.close=function(b){function c(){g.detach().trigger("closed.bs.alert").remove()}var e=a(this),f=e.attr("data-target");f||(f=e.attr("href"),f=f&&f.replace(/.*(?=#[^\s]*$)/,""));var g=a(f);b&&b.preventDefault(),g.length||(g=e.closest(".alert")),g.trigger(b=a.Event("close.bs.alert")),b.isDefaultPrevented()||(g.removeClass("in"),a.support.transition&&g.hasClass("fade")?g.one("bsTransitionEnd",c).emulateTransitionEnd(d.TRANSITION_DURATION):c())};var e=a.fn.alert;a.fn.alert=b,a.fn.alert.Constructor=d,a.fn.alert.noConflict=function(){return a.fn.alert=e,this},a(document).on("click.bs.alert.data-api",c,d.prototype.close)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.button"),f="object"==typeof b&&b;e||d.data("bs.button",e=new c(this,f)),"toggle"==b?e.toggle():b&&e.setState(b)})}var c=function(b,d){this.$element=a(b),this.options=a.extend({},c.DEFAULTS,d),this.isLoading=!1};c.VERSION="3.3.4",c.DEFAULTS={loadingText:"loading..."},c.prototype.setState=function(b){var c="disabled",d=this.$element,e=d.is("input")?"val":"html",f=d.data();b+="Text",null==f.resetText&&d.data("resetText",d[e]()),setTimeout(a.proxy(function(){d[e](null==f[b]?this.options[b]:f[b]),"loadingText"==b?(this.isLoading=!0,d.addClass(c).attr(c,c)):this.isLoading&&(this.isLoading=!1,d.removeClass(c).removeAttr(c))},this),0)},c.prototype.toggle=function(){var a=!0,b=this.$element.closest('[data-toggle="buttons"]');if(b.length){var c=this.$element.find("input");"radio"==c.prop("type")&&(c.prop("checked")&&this.$element.hasClass("active")?a=!1:b.find(".active").removeClass("active")),a&&c.prop("checked",!this.$element.hasClass("active")).trigger("change")}else this.$element.attr("aria-pressed",!this.$element.hasClass("active"));a&&this.$element.toggleClass("active")};var d=a.fn.button;a.fn.button=b,a.fn.button.Constructor=c,a.fn.button.noConflict=function(){return a.fn.button=d,this},a(document).on("click.bs.button.data-api",'[data-toggle^="button"]',function(c){var d=a(c.target);d.hasClass("btn")||(d=d.closest(".btn")),b.call(d,"toggle"),c.preventDefault()}).on("focus.bs.button.data-api blur.bs.button.data-api",'[data-toggle^="button"]',function(b){a(b.target).closest(".btn").toggleClass("focus",/^focus(in)?$/.test(b.type))})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},c.DEFAULTS,d.data(),"object"==typeof b&&b),g="string"==typeof b?b:f.slide;e||d.data("bs.carousel",e=new c(this,f)),"number"==typeof b?e.to(b):g?e[g]():f.interval&&e.pause().cycle()})}var c=function(b,c){this.$element=a(b),this.$indicators=this.$element.find(".carousel-indicators"),this.options=c,this.paused=null,this.sliding=null,this.interval=null,this.$active=null,this.$items=null,this.options.keyboard&&this.$element.on("keydown.bs.carousel",a.proxy(this.keydown,this)),"hover"==this.options.pause&&!("ontouchstart"in document.documentElement)&&this.$element.on("mouseenter.bs.carousel",a.proxy(this.pause,this)).on("mouseleave.bs.carousel",a.proxy(this.cycle,this))};c.VERSION="3.3.4",c.TRANSITION_DURATION=600,c.DEFAULTS={interval:5e3,pause:"hover",wrap:!0,keyboard:!0},c.prototype.keydown=function(a){if(!/input|textarea/i.test(a.target.tagName)){switch(a.which){case 37:this.prev();break;case 39:this.next();break;default:return}a.preventDefault()}},c.prototype.cycle=function(b){return b||(this.paused=!1),this.interval&&clearInterval(this.interval),this.options.interval&&!this.paused&&(this.interval=setInterval(a.proxy(this.next,this),this.options.interval)),this},c.prototype.getItemIndex=function(a){return this.$items=a.parent().children(".item"),this.$items.index(a||this.$active)},c.prototype.getItemForDirection=function(a,b){var c=this.getItemIndex(b),d="prev"==a&&0===c||"next"==a&&c==this.$items.length-1;if(d&&!this.options.wrap)return b;var e="prev"==a?-1:1,f=(c+e)%this.$items.length;return this.$items.eq(f)},c.prototype.to=function(a){var b=this,c=this.getItemIndex(this.$active=this.$element.find(".item.active"));return a>this.$items.length-1||0>a?void 0:this.sliding?this.$element.one("slid.bs.carousel",function(){b.to(a)}):c==a?this.pause().cycle():this.slide(a>c?"next":"prev",this.$items.eq(a))},c.prototype.pause=function(b){return b||(this.paused=!0),this.$element.find(".next, .prev").length&&a.support.transition&&(this.$element.trigger(a.support.transition.end),this.cycle(!0)),this.interval=clearInterval(this.interval),this},c.prototype.next=function(){return this.sliding?void 0:this.slide("next")},c.prototype.prev=function(){return this.sliding?void 0:this.slide("prev")},c.prototype.slide=function(b,d){var e=this.$element.find(".item.active"),f=d||this.getItemForDirection(b,e),g=this.interval,h="next"==b?"left":"right",i=this;if(f.hasClass("active"))return this.sliding=!1;var j=f[0],k=a.Event("slide.bs.carousel",{relatedTarget:j,direction:h});if(this.$element.trigger(k),!k.isDefaultPrevented()){if(this.sliding=!0,g&&this.pause(),this.$indicators.length){this.$indicators.find(".active").removeClass("active");var l=a(this.$indicators.children()[this.getItemIndex(f)]);l&&l.addClass("active")}var m=a.Event("slid.bs.carousel",{relatedTarget:j,direction:h});return a.support.transition&&this.$element.hasClass("slide")?(f.addClass(b),f[0].offsetWidth,e.addClass(h),f.addClass(h),e.one("bsTransitionEnd",function(){f.removeClass([b,h].join(" ")).addClass("active"),e.removeClass(["active",h].join(" ")),i.sliding=!1,setTimeout(function(){i.$element.trigger(m)},0)}).emulateTransitionEnd(c.TRANSITION_DURATION)):(e.removeClass("active"),f.addClass("active"),this.sliding=!1,this.$element.trigger(m)),g&&this.cycle(),this}};var d=a.fn.carousel;a.fn.carousel=b,a.fn.carousel.Constructor=c,a.fn.carousel.noConflict=function(){return a.fn.carousel=d,this};var e=function(c){var d,e=a(this),f=a(e.attr("data-target")||(d=e.attr("href"))&&d.replace(/.*(?=#[^\s]+$)/,""));if(f.hasClass("carousel")){var g=a.extend({},f.data(),e.data()),h=e.attr("data-slide-to");h&&(g.interval=!1),b.call(f,g),h&&f.data("bs.carousel").to(h),c.preventDefault()}};a(document).on("click.bs.carousel.data-api","[data-slide]",e).on("click.bs.carousel.data-api","[data-slide-to]",e),a(window).on("load",function(){a('[data-ride="carousel"]').each(function(){var c=a(this);b.call(c,c.data())})})}(jQuery),+function(a){"use strict";function b(b){var c,d=b.attr("data-target")||(c=b.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,"");return a(d)}function c(b){return this.each(function(){var c=a(this),e=c.data("bs.collapse"),f=a.extend({},d.DEFAULTS,c.data(),"object"==typeof b&&b);!e&&f.toggle&&/show|hide/.test(b)&&(f.toggle=!1),e||c.data("bs.collapse",e=new d(this,f)),"string"==typeof b&&e[b]()})}var d=function(b,c){this.$element=a(b),this.options=a.extend({},d.DEFAULTS,c),this.$trigger=a('[data-toggle="collapse"][href="#'+b.id+'"],[data-toggle="collapse"][data-target="#'+b.id+'"]'),this.transitioning=null,this.options.parent?this.$parent=this.getParent():this.addAriaAndCollapsedClass(this.$element,this.$trigger),this.options.toggle&&this.toggle()};d.VERSION="3.3.4",d.TRANSITION_DURATION=350,d.DEFAULTS={toggle:!0},d.prototype.dimension=function(){var a=this.$element.hasClass("width");return a?"width":"height"},d.prototype.show=function(){if(!this.transitioning&&!this.$element.hasClass("in")){var b,e=this.$parent&&this.$parent.children(".panel").children(".in, .collapsing");if(!(e&&e.length&&(b=e.data("bs.collapse"),b&&b.transitioning))){var f=a.Event("show.bs.collapse");if(this.$element.trigger(f),!f.isDefaultPrevented()){e&&e.length&&(c.call(e,"hide"),b||e.data("bs.collapse",null));var g=this.dimension();this.$element.removeClass("collapse").addClass("collapsing")[g](0).attr("aria-expanded",!0),this.$trigger.removeClass("collapsed").attr("aria-expanded",!0),this.transitioning=1;var h=function(){this.$element.removeClass("collapsing").addClass("collapse in")[g](""),this.transitioning=0,this.$element.trigger("shown.bs.collapse")};if(!a.support.transition)return h.call(this);var i=a.camelCase(["scroll",g].join("-"));this.$element.one("bsTransitionEnd",a.proxy(h,this)).emulateTransitionEnd(d.TRANSITION_DURATION)[g](this.$element[0][i])}}}},d.prototype.hide=function(){if(!this.transitioning&&this.$element.hasClass("in")){var b=a.Event("hide.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.dimension();this.$element[c](this.$element[c]())[0].offsetHeight,this.$element.addClass("collapsing").removeClass("collapse in").attr("aria-expanded",!1),this.$trigger.addClass("collapsed").attr("aria-expanded",!1),this.transitioning=1;var e=function(){this.transitioning=0,this.$element.removeClass("collapsing").addClass("collapse").trigger("hidden.bs.collapse")};return a.support.transition?void this.$element[c](0).one("bsTransitionEnd",a.proxy(e,this)).emulateTransitionEnd(d.TRANSITION_DURATION):e.call(this)}}},d.prototype.toggle=function(){this[this.$element.hasClass("in")?"hide":"show"]()},d.prototype.getParent=function(){return a(this.options.parent).find('[data-toggle="collapse"][data-parent="'+this.options.parent+'"]').each(a.proxy(function(c,d){var e=a(d);this.addAriaAndCollapsedClass(b(e),e)},this)).end()},d.prototype.addAriaAndCollapsedClass=function(a,b){var c=a.hasClass("in");a.attr("aria-expanded",c),b.toggleClass("collapsed",!c).attr("aria-expanded",c)};var e=a.fn.collapse;a.fn.collapse=c,a.fn.collapse.Constructor=d,a.fn.collapse.noConflict=function(){return a.fn.collapse=e,this},a(document).on("click.bs.collapse.data-api",'[data-toggle="collapse"]',function(d){var e=a(this);e.attr("data-target")||d.preventDefault();var f=b(e),g=f.data("bs.collapse"),h=g?"toggle":e.data();c.call(f,h)})}(jQuery),+function(a){"use strict";function b(b){b&&3===b.which||(a(e).remove(),a(f).each(function(){var d=a(this),e=c(d),f={relatedTarget:this};e.hasClass("open")&&(e.trigger(b=a.Event("hide.bs.dropdown",f)),b.isDefaultPrevented()||(d.attr("aria-expanded","false"),e.removeClass("open").trigger("hidden.bs.dropdown",f)))}))}function c(b){var c=b.attr("data-target");c||(c=b.attr("href"),c=c&&/#[A-Za-z]/.test(c)&&c.replace(/.*(?=#[^\s]*$)/,""));var d=c&&a(c);return d&&d.length?d:b.parent()}function d(b){return this.each(function(){var c=a(this),d=c.data("bs.dropdown");d||c.data("bs.dropdown",d=new g(this)),"string"==typeof b&&d[b].call(c)})}var e=".dropdown-backdrop",f='[data-toggle="dropdown"]',g=function(b){a(b).on("click.bs.dropdown",this.toggle)};g.VERSION="3.3.4",g.prototype.toggle=function(d){var e=a(this);if(!e.is(".disabled, :disabled")){var f=c(e),g=f.hasClass("open");if(b(),!g){"ontouchstart"in document.documentElement&&!f.closest(".navbar-nav").length&&a('
').insertAfter(a(this)).on("click",b);var h={relatedTarget:this};if(f.trigger(d=a.Event("show.bs.dropdown",h)),d.isDefaultPrevented())return;e.trigger("focus").attr("aria-expanded","true"),f.toggleClass("open").trigger("shown.bs.dropdown",h)}return!1}},g.prototype.keydown=function(b){if(/(38|40|27|32)/.test(b.which)&&!/input|textarea/i.test(b.target.tagName)){var d=a(this);if(b.preventDefault(),b.stopPropagation(),!d.is(".disabled, :disabled")){var e=c(d),g=e.hasClass("open");if(!g&&27!=b.which||g&&27==b.which)return 27==b.which&&e.find(f).trigger("focus"),d.trigger("click");var h=" li:not(.disabled):visible a",i=e.find('[role="menu"]'+h+', [role="listbox"]'+h);if(i.length){var j=i.index(b.target);38==b.which&&j>0&&j--,40==b.which&&jt |
249 | *
250 | * f::write('test.txt', 'hello');
251 | * // creates a new text file with hello as content
252 | *
253 | * // create a new file
254 | * f::write('text.txt', array('test' => 'hello'));
255 | * // creates a new file and encodes the array as json
256 | *
257 | *
258 | *
259 | * @param string $file The path for the new file
260 | * @param mixed $content Either a string, an object or an array. Arrays and objects will be serialized.
261 | * @param boolean $append true: append the content to an exisiting file if available. false: overwrite.
262 | * @return boolean
263 | */
264 | static public function write($file, $content, $append = false) {
265 | if(is_array($content) or is_object($content)) $content = serialize($content);
266 | $mode = ($append) ? FILE_APPEND | LOCK_EX : LOCK_EX;
267 | // if the parent directory does not exist, create it
268 | if(!is_dir(dirname($file))) {
269 | if(!dir::make(dirname($file))) return false;
270 | }
271 | return (@file_put_contents($file, $content, $mode) !== false) ? true : false;
272 | }
273 |
274 | /**
275 | * Appends new content to an existing file
276 | *
277 | * @param string $file The path for the file
278 | * @param mixed $content Either a string or an array. Arrays will be converted to JSON.
279 | * @return boolean
280 | */
281 | static public function append($file, $content) {
282 | return static::write($file,$content,true);
283 | }
284 |
285 | /**
286 | * Reads the content of a file
287 | *
288 | *
289 | *
290 | * $content = f::read('test.txt');
291 | * // i.e. content is hello
292 | *
293 | * $content = f::read('text.txt', 'json');
294 | * // returns an array with the parsed content
295 | *
296 | *
297 | *
298 | * @param string $file The path for the file
299 | * @return mixed
300 | */
301 | static public function read($file) {
302 | return @file_get_contents($file);
303 | }
304 |
305 | /**
306 | * Returns the file content as base64 encoded string
307 | *
308 | * @param string $file The path for the file
309 | * @return string
310 | */
311 | static public function base64($file) {
312 | return base64_encode(f::read($file));
313 | }
314 |
315 | /**
316 | * Returns the file as data uri
317 | *
318 | * @param string $file The path for the file
319 | * @return string
320 | */
321 | static public function uri($file) {
322 | $mime = static::mime($file);
323 | return ($mime) ? 'data:' . $mime . ';base64,' . static::base64($file) : false;
324 | }
325 |
326 | /**
327 | * Moves a file to a new location
328 | *
329 | *
330 | *
331 | * $move = f::move('test.txt', 'super.txt');
332 | *
333 | * if($move) echo 'The file has been moved';
334 | *
335 | *
336 | *
337 | * @param string $old The current path for the file
338 | * @param string $new The path to the new location
339 | * @return boolean
340 | */
341 | static public function move($old, $new) {
342 | if(!file_exists($old) or file_exists($new)) return false;
343 | return @rename($old, $new);
344 | }
345 |
346 | /**
347 | * Copy a file to a new location.
348 | *
349 | * @param string $file
350 | * @param string $target
351 | * @return boolean
352 | */
353 | static public function copy($file, $target) {
354 | if(!file_exists($file) or file_exists($target)) return false;
355 | return @copy($file, $target);
356 | }
357 |
358 | /**
359 | * Deletes a file
360 | *
361 | *
362 | *
363 | * $remove = f::remove('test.txt');
364 | * if($remove) echo 'The file has been removed';
365 | *
366 | *
367 | *
368 | * @param string $file The path for the file
369 | * @return boolean
370 | */
371 | static public function remove($file) {
372 | return file_exists($file) and is_file($file) and !empty($file) ? @unlink($file) : false;
373 | }
374 |
375 | /**
376 | * Gets the extension of a file
377 | *
378 | *
379 | *
380 | * $extension = f::extension('test.txt');
381 | * // extension is txt
382 | *
383 | *
384 | *
385 | * @param string $file The filename or path
386 | * @param string $extension Set an optional extension to overwrite the current one
387 | * @return string
388 | */
389 | static public function extension($file, $extension = false) {
390 |
391 | // overwrite the current extension
392 | if($extension) return static::name($file) . '.' . $extension;
393 |
394 | // return the current extension
395 | return strtolower(pathinfo($file, PATHINFO_EXTENSION));
396 |
397 | }
398 |
399 | /**
400 | * Returns all extensions for a certain file type
401 | *
402 | * @param string $type
403 | * @return array
404 | */
405 | static public function extensions($type = null) {
406 | if(is_null($type)) return array_keys(static::$mimes);
407 | return isset(static::$types[$type]) ? static::$types[$type] : array();
408 | }
409 |
410 | /**
411 | * Extracts the filename from a file path
412 | *
413 | *
414 | *
415 | * $filename = f::filename('/var/www/test.txt');
416 | * // filename is test.txt
417 | *
418 | *
419 | *
420 | * @param string $file The path
421 | * @return string
422 | */
423 | static public function filename($name) {
424 | return pathinfo($name, PATHINFO_BASENAME);
425 | }
426 |
427 | /**
428 | * Extracts the name from a file path or filename without extension
429 | *
430 | *
431 | *
432 | * $name = f::name('/var/www/test.txt');
433 | *
434 | * // name is test
435 | *
436 | *
437 | *
438 | * @param string $file The path or filename
439 | * @return string
440 | */
441 | static public function name($name) {
442 | return pathinfo($name, PATHINFO_FILENAME);
443 | }
444 |
445 | /**
446 | * Just an alternative for dirname() to stay consistent
447 | *
448 | *
449 | *
450 | * $dirname = f::dirname('/var/www/test.txt');
451 | * // dirname is /var/www
452 | *
453 | *
454 | *
455 | * @param string $file The path
456 | * @return string
457 | */
458 | static public function dirname($file) {
459 | return dirname($file);
460 | }
461 |
462 | /**
463 | * Returns the size of a file.
464 | *
465 | *
466 | *
467 | * $size = f::size('/var/www/test.txt');
468 | * // size is ie: 1231939
469 | *
470 | *
471 | *
472 | * @param string $file The path
473 | * @return mixed
474 | */
475 | static public function size($file) {
476 | return filesize($file);
477 | }
478 |
479 | /**
480 | * Converts an integer size into a human readable format
481 | *
482 | *
483 | *
484 | * $niceSize = f::niceSize('/path/to/a/file.txt');
485 | * // nice size is i.e: 212 kb
486 | *
487 | * $niceSize = f::niceSize(1231939);
488 | * // nice size is: 1,2 mb
489 | *
490 | *
491 | *
492 | * @param int $size The file size or a file path
493 | * @return string
494 | */
495 | static public function niceSize($size) {
496 |
497 | // file mode
498 | if(!is_int($size) and file_exists($size)) {
499 | $size = static::size($size);
500 | }
501 |
502 | // make sure it's an int
503 | $size = (int)$size;
504 |
505 | // avoid errors for invalid sizes
506 | if($size <= 0) return '0 kb';
507 |
508 | // available units
509 | $unit = array('b','kb','mb','gb','tb','pb', 'eb', 'zb', 'yb');
510 |
511 | // the math magic
512 | return round($size / pow(1024, ($i = floor(log($size, 1024)))), 2) . ' ' . $unit[$i];
513 |
514 | }
515 |
516 | /**
517 | * Get the file's last modification time.
518 | *
519 | * @param string $file
520 | * @param string $format
521 | * @param string $handler date or strftime
522 | * @return int
523 | */
524 | static public function modified($file, $format = null, $handler = 'date') {
525 | return !is_null($format) ? $handler($format, filemtime($file)) : filemtime($file);
526 | }
527 |
528 | /**
529 | * Returns the mime type of a file
530 | *
531 | * @param string $file
532 | * @return string
533 | */
534 | static public function mime($file) {
535 |
536 | // stop for invalid files
537 | if(!file_exists($file)) return null;
538 |
539 | // Fileinfo is prefered if available
540 | if(function_exists('finfo_file')) {
541 | $finfo = finfo_open(FILEINFO_MIME_TYPE);
542 | $mime = finfo_file($finfo, $file);
543 | finfo_close($finfo);
544 | return $mime;
545 | }
546 |
547 | // for older versions with mime_content_type go for that.
548 | if(function_exists('mime_content_type') and $mime = @mime_content_type($file) !== false) {
549 | return $mime;
550 | }
551 |
552 | // guess the matching mime type by extension
553 | $ext = pathinfo($file, PATHINFO_EXTENSION);
554 | $info = isset(static::$mimes[$ext]) ? static::$mimes[$ext] : null;
555 |
556 | // if there are more than one applicable mimes for the extension, return the first
557 | return is_array($info) ? array_shift($info) : $info;
558 |
559 | }
560 |
561 | /**
562 | * Returns all detectable mime types
563 | *
564 | * @return array
565 | */
566 | static public function mimes() {
567 | return static::$mimes;
568 | }
569 |
570 | /**
571 | * Categorize the file
572 | *
573 | * @param string $file Either the file path or extension
574 | * @return string
575 | */
576 | static public function type($file) {
577 |
578 | $length = strlen($file);
579 |
580 | if($length >= 2 and $length <= 4) {
581 | // use the file name as extension
582 | $extension = $file;
583 | } else {
584 | // get the extension from the filename
585 | $extension = pathinfo($file, PATHINFO_EXTENSION);
586 | }
587 |
588 | if(empty($extension)) {
589 | // detect the mime type first to get the most reliable extension
590 | $mime = static::mime($file);
591 | $extension = static::mimeToExtension($mime);
592 | }
593 |
594 | // sanitize extension
595 | $extension = strtolower($extension);
596 |
597 | foreach(static::$types as $type => $extensions) {
598 | if(in_array($extension, $extensions)) return $type;
599 | }
600 |
601 | return null;
602 |
603 | }
604 |
605 | /**
606 | * Returns an array of all available file types
607 | *
608 | * @return array
609 | */
610 | static public function types() {
611 | return static::$types;
612 | }
613 |
614 | /**
615 | * Checks if a file is of a certain type
616 | *
617 | * @param string $file Full path to the file
618 | * @param string $value An extension or mime type
619 | * @return boolean
620 | */
621 | static public function is($file, $value) {
622 |
623 | if(in_array($value, static::extensions())) {
624 | // check for the extension
625 | return static::extension($file) == $value;
626 | } else if(strpos($value, '/') !== false) {
627 | // check for the mime type
628 | return static::mime($file) == $value;
629 | }
630 |
631 | return false;
632 |
633 | }
634 |
635 | /**
636 | * Converts a mime type to a file extension
637 | *
638 | * @param string $mime
639 | * @return string
640 | */
641 | static public function mimeToExtension($mime) {
642 | foreach(static::$mimes as $key => $value) {
643 | if(is_array($value) and in_array($mime, $value)) return $key;
644 | if($value == $mime) return $key;
645 | }
646 | return null;
647 | }
648 |
649 | /**
650 | * Returns the type for a given mime
651 | *
652 | * @param string $mime
653 | * @return string
654 | */
655 | static public function mimeToType($mime) {
656 | return static::extensionToType(static::mimeToExtension($mime));
657 | }
658 |
659 | /**
660 | * Converts a file extension to a mime type
661 | *
662 | * @param string $extension
663 | * @return string
664 | */
665 | static public function extensionToMime($extension) {
666 | $mime = isset(static::$mimes[$extension]) ? static::$mimes[$extension] : null;
667 | return is_array($mime) ? array_shift($mime) : $mime;
668 | }
669 |
670 | /**
671 | * Returns the file type for a passed extension
672 | *
673 | * @param string $extension
674 | * @return string
675 | */
676 | static public function extensionToType($extension) {
677 |
678 | // get all categorized types
679 | foreach(static::$types as $type => $extensions) {
680 | if(in_array($extension, $extensions)) return $type;
681 | }
682 |
683 | return null;
684 |
685 | }
686 |
687 | /**
688 | * Sanitize a filename to strip unwanted special characters
689 | *
690 | *
691 | *
692 | * $safe = f::safeName('über genious.txt');
693 | * // safe will be ueber-genious.txt
694 | *
695 | *
696 | *
697 | * @param string $string The file name
698 | * @return string
699 | */
700 | static public function safeName($string) {
701 | $name = static::name($string);
702 | $extension = static::extension($string);
703 | $end = !empty($extension) ? '.' . str::slug($extension) : '';
704 | return str::slug($name, '-', 'a-z0-9@._-') . $end;
705 | }
706 |
707 | /**
708 | * Checks if the file is writable
709 | *
710 | * @param string $file
711 | * @return boolean
712 | */
713 | static public function isWritable($file) {
714 | return is_writable($file);
715 | }
716 |
717 | /**
718 | * Checks if the file is readable
719 | *
720 | * @param string $file
721 | * @return boolean
722 | */
723 | static public function isReadable($file) {
724 | return is_readable($file);
725 | }
726 |
727 | /**
728 | * Read and send the file with the correct headers
729 | *
730 | * @param string $file
731 | */
732 | static public function show($file) {
733 |
734 | // stop the download if the file does not exist or is not readable
735 | if(!is_file($file) or !is_readable($file)) return false;
736 |
737 | // send the browser headers
738 | header::type(f::mime($file));
739 |
740 | // send the file
741 | die(f::read($file));
742 |
743 | }
744 |
745 | /*
746 | * Automatically sends all needed headers for the file to be downloaded
747 | * and echos the file's content
748 | *
749 | * @param string $file The root to the file
750 | * @param string $name Optional filename for the download
751 | */
752 | static public function download($file, $name = null) {
753 |
754 | // stop the download if the file does not exist or is not readable
755 | if(!is_file($file) or !is_readable($file)) return false;
756 |
757 | header::download(array(
758 | 'name' => $name ? $name : f::filename($file),
759 | 'size' => f::size($file),
760 | 'mime' => f::mime($file),
761 | 'modified' => f::modified($file)
762 | ));
763 |
764 | die(f::read($file));
765 |
766 | }
767 |
768 | }
769 |
--------------------------------------------------------------------------------
/site/config/config.php:
--------------------------------------------------------------------------------
1 | '(:any)',
39 | 'action' => function($uid) {
40 |
41 | $page = page($uid);
42 |
43 | if(!$page) $page = page('uploads/' . $uid);
44 | if(!$page) $page = site()->errorPage();
45 |
46 | return site()->visit($page);
47 |
48 | }
49 | ),
50 | array(
51 | 'pattern' => 'uploads/(:any)',
52 | 'action' => function($uid) {
53 | go($uid);
54 | }
55 | )
56 | ));
--------------------------------------------------------------------------------
/site/snippets/files/everythingelse.php:
--------------------------------------------------------------------------------
1 | file()->type();
5 |
6 | if(empty($upload->file()->type())) {$filetype = "other";}
7 |
8 | $imageAddress = url('assets/images/'.$filetype.'.png');
9 |
10 | ?>
11 |
12 |
24 |
25 |
--------------------------------------------------------------------------------
/site/snippets/files/image.php:
--------------------------------------------------------------------------------
1 | file()->extension(), $notThumbable) == true) {
6 | $imageUrl = url('assets/images/image.png'); }
7 | else {
8 |
9 | $image = thumb($upload->file(), array('width'=>300));
10 |
11 | $imageUrl = $image->url();
12 |
13 | }
14 | ?>
15 |
16 |
--------------------------------------------------------------------------------
/site/snippets/filetypes.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |