Skip to content

Instantly share code, notes, and snippets.

View jenswittmann's full-sized avatar

Jens Wittmann – Gestaltung & Entwicklung jenswittmann

View GitHub Profile
@jenswittmann
jenswittmann / OnAgendaBeforeRemove.php
Last active October 22, 2025 10:21
Prevents booked Cursus dates from being accidentally deleted via the Agenda CMP. See documentation: https://docs.treehillstudio.de/en/agenda/08_System_Events/
<?php
/**
* @package agenda
* @subpackage plugin
*/
namespace TreehillStudio\Agenda\Plugins\Events;
use TreehillStudio\Agenda\Agenda;
@jenswittmann
jenswittmann / video-autoplay.php
Last active October 2, 2025 13:55
HTML5 Video Autoplay in Safari, Chrome und Co. for 2025
<?php if (preg_match('/safari/i', $_SERVER['HTTP_USER_AGENT']) && !preg_match('/chrome/i', $_SERVER['HTTP_USER_AGENT'])): ?>
<!-- Docs: https://developer.apple.com/documentation/webkit/delivering-video-content-for-safari#Use-MP4-Video-Instead-of-Animated-GIFs -->
<img
src="video.mp4"
width="1600"
height="900"
alt="" />
<?php else: ?>
<video
src="video.mp4"
@jenswittmann
jenswittmann / contentblocks-fenom-field-template.example
Last active September 4, 2025 11:37
Use Fenom via pdoTools in ContentBlocks
[[pdoChunk?
&file=`contentblocks/your-chunk-name.chunk.tpl`
&field=`[[+field]]`
&field_type_idx=`[[+field_type_idx]]` ]]
@jenswittmann
jenswittmann / cbdateinput.plugin.php
Last active September 4, 2025 13:15
MODX ContentBlocks Custom Input Date Type Plugin
<?php
if ($modx->event->name == 'ContentBlocks_RegisterInputs') {
class cbDateInput extends cbBaseInput
{
public $defaultIcon = 'snippet_B';
public $defaultTpl = '';
public function getTemplates()
{
@jenswittmann
jenswittmann / babel-extend.plugin.php
Last active August 11, 2025 09:28
Add switch buttons for each language. When deleting a resource, also delete any connected resources via Babel Extra in MODX.
<?php
$eventName = $modx->event->name;
$babelLanguageLinksTv = $modx->getOption('babel.babelTvName');
$connectedResourcesTv = $resource->getTVValue($babelLanguageLinksTv);
// prevent mixedImage hook in via getTVValue()
//$q = $modx->newQuery('modTemplateVarResource', [
// 'tmplvarid' => 20,
// 'contentid' => $modx->resource->id,
//]);
//$q->select('value');
@jenswittmann
jenswittmann / CurlyRandomGrid.html
Created October 15, 2024 12:49
CurlyRandomGrid
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8" />
<title>CurlyRandomGrid</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
<style>
.grid {
display: grid;
@jenswittmann
jenswittmann / resizeImage.php
Last active October 22, 2023 11:20
MODX resizeImage Snippet (modern pthumb replacement with srcset generation and very low options, but works on IONOS too)
<?php
# vars
$lib = $modx->getOption("resizeImage_imageLib", null, "cli");
$libPath = $modx->getOption("resizeImage_imageLibPath", null, "/Applications/MAMP/Library/bin/convert");
$mode = $modx->getOption("mode", $scriptProperties, "");
$input = $modx->getOption("input", $scriptProperties, "");
$sizes = $modx->getOption("options", $scriptProperties, "");
$quality = $modx->getOption("quality", $scriptProperties, 70);
$cultureKey = $modx->getOption("cultureKey");
@jenswittmann
jenswittmann / pdf2image.php
Last active October 22, 2023 11:16
MODX pdf2image Snippet
<?php
# vars
$filePath = $modx->getOption('input', $scriptProperties, '');
$savePath = "assets/components/phpthumbof/cache/poster_" . md5($filePath) . ".jpg";
# check file exists and is PDF
if (!file_exists(MODX_BASE_PATH . $filePath) || mime_content_type(MODX_BASE_PATH . $filePath) != "application/pdf") {
return $filePath;
}
@jenswittmann
jenswittmann / restirctusermanagement.plugin.php
Created January 22, 2023 19:06
MODX CMP User restriction Plugin
<?php
if ($modx->context->get("key") == "mgr") {
if ($modx->user->get("sudo") || $modx->user->isMember("Administrator")) {
return;
}
switch ($modx->event->name) {
case "OnMODXInit":
$action = $modx->getOption("action", $_REQUEST, "");
@jenswittmann
jenswittmann / migx-filter-by-tv.json
Last active January 11, 2026 11:23
MODX MIGX CMP for News filtering by TV
{
"formtabs":"",
"contextmenus":"",
"actionbuttons":"",
"columnbuttons":"",
"filters":[
{
"MIGX_id":1,
"name":"categorie",
"label":"Kategorie",