Skip to content

Instantly share code, notes, and snippets.

@bwente
bwente / fmt.fileSize.php
Created May 19, 2023 23:08
MODX output filter to print out the size of a file
<?php
/**
*
* Example usage: [[*filepath:fmt.fileSize=`mb`]]
*
*/
$units = array(
'gb' => array('size' => 1073741824, 'label' => 'GB'),
'mb' => array('size' => 1048576, 'label' => 'MB'),
@bwente
bwente / SummaryAI.php
Created March 30, 2023 12:20
SummaryAI Plugin for MODX (uses OpenAi API)
<?php
$model = $modx->getOption('model', $scriptProperties);
$prompt = $modx->getOption('prompt', $scriptProperties);
$api_url = $modx->getOption('api_url', $scriptProperties);
$api_key = $modx->getOption('api_key', $scriptProperties);
switch($modx->event->name) {
case 'OnDocFormSave':
// Check if the resource has a summary
if (!$resource->get('introtext')) {
@bwente
bwente / lottiePlayer.php
Created March 27, 2023 00:17
Lottie Animation Player for MODX
<?php
$modx->regClientStartupScript('https://cdnjs.cloudflare.com/ajax/libs/lottie-web/5.10.2/lottie.min.js');
$background = $modx->getOption('background', $scriptProperties, 'transparent');
$speed = $modx->getOption('speed', $scriptProperties, 1);
$width = $modx->getOption('width', $scriptProperties, '100%');
$height = $modx->getOption('height', $scriptProperties, '100%');
$loop = $modx->getOption('loop', $scriptProperties, 0);
$autoplay = $modx->getOption('autoplay', $scriptProperties, 1);
$json = $modx->getOption('lottieJSON', $scriptProperties, '');
@bwente
bwente / lottieFilesPlayer.php
Created March 27, 2023 00:16
Lottie Animation Player for MODX
<?php
$modx->regClientStartupScript('https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js');
$background = $modx->getOption('background', $scriptProperties, 'transparent');
$speed = $modx->getOption('speed', $scriptProperties, 1);
$width = $modx->getOption('width', $scriptProperties, '100%');
$height = $modx->getOption('height', $scriptProperties, '100%');
$hover = $modx->getOption('hover', $scriptProperties, 0);
$loop = $modx->getOption('loop', $scriptProperties, 0);
$controls = $modx->getOption('controls', $scriptProperties, 0);
@bwente
bwente / saveContextCss.php
Created March 17, 2023 15:36
cssSweet plugin for MODX Context
<?php
/**
* saveContextCss
* modified @bwente, which was modified by @sottwell
*
* saveCustomCss
* @author @sepiariver
* Copyright 2013 - 2015 by YJ Tso <[email protected]> <[email protected]>
*
* saveCustomCss and cssSweet is free software;
@bwente
bwente / staticPdfResourceFixer.php
Created February 17, 2023 19:06
staticPdfResourceFixer [plug-in]
<?php
/*
*/
switch ($modx->event->name) {
case 'OnBeforeDocFormSave':
if ( $mode == modSystemEvent::MODE_NEW ) {
// stuff to do before saving a new resource
// this example checks the parent document, and updates various resource fields
@bwente
bwente / JSONtoPlaceholders.php
Created January 11, 2022 17:54
JSONtoPlaceholders
<?php
/**
* jsonToPlaceholders snippet for JM Customer Database extra
*
* Copyright 2013 by JM Addington [email protected]
* Created on 04-28-2013
*
* @package jmc
*
@bwente
bwente / getImage.php
Created January 14, 2020 20:33
Run pthumb and return image
<?php
// [[!getImage? &path=`/images/` &image=`email_hero.jpg` &options=`&w=540`]]
$path = $modx->getOption('path', $scriptProperties, '');
$image = $modx->getOption('image', $scriptProperties, '');
$options = $modx->getOption('options', $scriptProperties, '');
$resizer = $modx->getOption('useResizer', $scriptProperties, 1);
$imagePath = $modx->runSnippet('pthumb', array(
@bwente
bwente / getImage.php
Created January 14, 2020 20:32
[[!getImage? &path=`/images/` &image=`email_hero.jpg` &options=`&w=540` ]]
<?php
$path = $modx->getOption('path', $scriptProperties, '');
$image = $modx->getOption('image', $scriptProperties, '');
$options = $modx->getOption('options', $scriptProperties, '');
$resizer = $modx->getOption('useResizer', $scriptProperties, 1);
$imagePath = $modx->runSnippet('pthumb', array(
'input' => $path.$image,
@bwente
bwente / XMLooper.php
Last active January 11, 2022 17:52
Snippet to read and parse XML input
<?php
# Snippet to read and parse XML input
$sourcePath = $scriptProperties['source'];
if (is_numeric($sourcePath))
{
$sourcePath = $modx->makeUrl($sourcePath, '', '', 'full');
}