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,40 @@
<?php
namespace Kirby\Embed;
use Dir;
class Autoloader {
public static function load($paths) {
foreach($paths as $group => $files) {
// single file
if(!is_array($files)) {
static::loadFile($group . '.php');
// directory
} else {
foreach($files as $file) {
// load all files from this directory
if($file === true) {
foreach(dir::read(dirname(dirname(__DIR__)) . DS . $group) as $file) {
static::loadFile($group . DS . $file);
}
// load specified files
} else {
static::loadFile($group . DS . $file . '.php');
}
}
}
}
}
protected static function loadFile($path) {
$file = dirname(dirname(__DIR__)) . DS . str_replace('/', DS, $path);
if(file_exists($file)) {
require_once($file);
}
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace Kirby\Embed;
class Cache {
public function __construct($plugin, $url) {
$this->plugin = $plugin;
$this->key = md5($url);
// Cache DirectoryIterator
$dir = kirby()->roots()->cache() . DS . $this->plugin;
if(!file_exists($dir)) mkdir($dir);
// Cache setup
$this->cache = \cache::setup('file', ['root' => $dir]);
// Cache clean-up
if($this->cache->expired($this->key)) {
$this->cache->remove($this->key);
}
}
public function __call($name, $args = []) {
return $this->cache->{$name}($this->key, $args);
}
}

View file

@ -0,0 +1,57 @@
<?php
namespace Kirby\Embed;
use C;
use F;
class Thumb {
protected $dir;
protected $root;
protected $url = '';
public function __construct($plugin, $url, $lifetime) {
$this->plugin = $plugin;
$this->source = $url;
$this->lifetime = $lifetime;
$this->root = kirby()->roots()->thumbs() . DS . '_plugins';
$this->dir = $this->root . DS . $this->plugin;
$this->extension = pathinfo(strtok($this->source, '?'), PATHINFO_EXTENSION);
$this->file = md5($this->source) . '.' . $this->extension;
$this->path = $this->dir . DS . $this->file;
$this->url = $url;
$this->cache();
}
public function __toString() {
return $this->url;
}
protected function cache() {
$cache = url('thumbs/_plugins/' . $this->plugin . '/' . $this->file);
if(f::exists($this->path) and !$this->expired()) {
return $this->url = $cache;
} else {
try {
if(is_writable(kirby()->roots()->thumbs())) {
if(!file_exists($this->root)) mkdir($this->root, 0755, true);
if(!file_exists($this->dir)) mkdir($this->dir, 0755, true);
file_put_contents($this->path, file_get_contents($this->source));
$this->url = $cache;
}
} catch (Exception $e) {}
}
}
protected function expired() {
if((f::modified($this->path) + $this->lifetime) < time()) {
return f::remove($this->path);
}
return false;
}
}