Skip to content

Instantly share code, notes, and snippets.

View bezin's full-sized avatar

Benedict Massolle bezin

View GitHub Profile
@bezin
bezin / migrate-translations.php
Last active September 13, 2024 14:28
Change Kirby default language from English to German with existing content files
<?php declare(strict_types=1);
use Kirby\Cms\ModelWithContent;
/**
* This script assumes English is the default language and German is the translation.
* The goal is to switch this and make German the default language and English the translation.
*
* We want to update all pages, files metadata and the site.
*
@bezin
bezin / set_file_templates.php
Last active August 9, 2023 14:35
Update every image template in Kirby CMS
<?php declare(strict_types=1);
/**
* This script sets a file template 'image' for every image in site() and all pages().
* I had a project without a file blueprint, but then added one later down the road.
* The existing files had no template set, so I hate to update all file metadata manually.
* Now even the existing files make use of the recently added file template.
* The script can easily be adjusted to update other metadata.
*/
@bezin
bezin / capture-canvas.js
Last active April 28, 2023 08:51
Capture a canvas animation and download it as a video
function captureCanvas(canvasSelectorOrElement, captureDuration, userOptions) {
// Create MediaRecorder object and connect it with the canvas stream
const canvas = (typeof canvasSelectorOrElement === 'string') ? document.querySelector(canvasSelectorOrElement) : canvasSelectorOrElement
if (!(canvas instanceof HTMLCanvasElement)) {
throw new Error('Element is not an instance of HTMLCanvasElement')
}
const defaultOptions = {
<territories>
<territory type="001">Welt</territory>
<territory type="002">Afrika</territory>
<territory type="003">Nordamerika</territory>
<territory type="005">Südamerika</territory>
<territory type="009">Ozeanien</territory>
<territory type="011">Westafrika</territory>
<territory type="013">Mittelamerika</territory>
<territory type="014">Ostafrika</territory>
<territory type="015">Nordafrika</territory>
@bezin
bezin / ModelTemplate.php
Last active August 29, 2015 14:25
This template class is used for showing model data. You can bind a model instance to the template object and once you parse the template, the class willl prepare all model data for output, like format timestamps to dates and loading labels from the dca. It also fetches relations and does this preparation recursively.
<?php
namespace PresProg;
use Contao;
class ModelTemplate extends \Template
{
protected $objModel;