Skip to content

Instantly share code, notes, and snippets.

@matdave
matdave / ogimage.snippet.php
Created September 30, 2021 16:20
Simple OG Image- MODX output modifier
<?php
if(empty($input)) return;
$url = rtrim($modx->getOption('site_url'), '/').'/'.ltrim($input,'/');
echo "<meta name=\"image\" property=\"og:image\" content=\"$url\" />";
$path = rtrim($modx->getOption('base_path'), '/').'/'.ltrim($input,'/');
$size = @getimagesize($path);
if ($size) {
$width = $size[0];
@matdave
matdave / elFinderPlugins.plugin.php
Created June 18, 2021 18:47
MODX Fred elFinder Configure Plugins
<?php
/** elFinder Plugin Options **/
switch ($modx->event->name) {
case 'FredOnElfinderRoots':
$params = $modx->getOption('params', $scriptProperties);
if (empty($params)) return false;
// Enable Sanitizer
$params->bind['upload.pre mkdir.pre mkfile.pre rename.pre archive.pre ls.pre'][] = 'Plugin.Sanitizer.cmdPreprocess';
$params->bind['paste.copyfrom upload.presave'][] = 'Plugin.Sanitizer.onUpLoadPreSave';
$params->plugin['Sanitizer'] = [
@matdave
matdave / location.nginx
Created May 5, 2021 20:16
rewrite file path for language subfolders
location ~* \.(?:ico|css|js|jpe?g|png|gif|svg|pdf|mov|mp4|mp3|woff|woff2|otf|ttf)$ {
expires 7d;
add_header Pragma public;
add_header Cache-Control "public";
gzip_vary on;
rewrite ^/(it|de|es|fr|cz)(/.*)$ $2 last;
}
@matdave
matdave / fixinvalidchars.snippet.php
Created April 2, 2021 17:28
Fix Non UTF Characters in a MODX Resource
<?php
$regex = <<<'END'
/
(
(?: [\x00-\x7F] # single-byte sequences 0xxxxxxx
| [\xC0-\xDF][\x80-\xBF] # double-byte sequences 110xxxxx 10xxxxxx
| [\xE0-\xEF][\x80-\xBF]{2} # triple-byte sequences 1110xxxx 10xxxxxx * 2
| [\xF0-\xF7][\x80-\xBF]{3} # quadruple-byte sequence 11110xxx 10xxxxxx * 3
){1,100} # ...one or more times
<?php
/**
* FixedPreLite plugin
*
* *
* Updated by matdave <https://matdave.com>
* *
* Original author Bob Ray <http://bobsguides.com>
* Copyright 2011-2014 Bob Ray
* 3/23/11
@matdave
matdave / showUrl.plugin.php
Last active March 5, 2021 17:09
showUrl MODX
<?php
/**
* Plugin to add a read only "url" field to the document tab
*
* @var modX $modx
* @var array $scriptProperties
*
* @event OnDocFormPrerender
*/
if(!$resource || !$mode || $modx == "new") return;
@matdave
matdave / bulkChange.snippet.php
Created February 9, 2021 16:12
bulkChange Snippet for MODX
<?php
// Choose the Parent ID for the bulk changes
$parent = 12393;
// Set how deep we want to search into sub-pages
$depth = 3;
// Grab all the IDs
$children = $modx->getChildIds($parent, $depth, array('context' => 'web'));
if(!empty($children)){
@matdave
matdave / Creative One Page Theme.template.html
Created January 27, 2021 21:23
Fred (Creative One Page Theme)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
@matdave
matdave / Shadow of the Ninja (USA).cht
Created January 15, 2021 19:41
Shadow of the Ninja Cheats
SCf55d:a5:c6:Infinite continues
SCac6d:2c:9d:Don't lose energy from enemy attacks
SC9564:00:04:Don't lose energy from falling
SC8c19:10:04:Maximum energy gained from potion
SC8c31:28:14:40 throwing stars on pick-up
SC8c46:14:05:20 bombs on pick-up
@matdave
matdave / recaptchav3.post.snippet.php
Last active April 14, 2020 22:36
MODX reCaptchaV3 POST
<?php
/**
* recaptchav3 POST Validator for use with MODX form processors
*
* Based on https://github.com/google/recaptcha
*
* @copyright Copyright (c) 2014, Google Inc.
* @link http://www.google.com/recaptcha
*
* Ported to MODX by YJ Tso @sepiariver