Skip to content

Instantly share code, notes, and snippets.

@matdave
matdave / showrandom.js
Created October 8, 2021 15:32
simple JS randomizer commands
const showrandom = document.querySelectorAll("[showrandom]");
showrandom.forEach(el=>{
const count = el.getAttribute('showrandom') ? el.getAttribute('showrandom') : 1;
const children = el.children;
while(children.length > count){
const random = Math.floor(Math.random() * children.length);
children[random].remove();
}
});
@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 / mimeFix.plugin.php
Last active November 16, 2021 15:52
SVG fix for MODX 3 S3 source
<?php
switch ($modx->event->name) {
case "OnFileManagerUpload":
if(!empty($files)){
foreach($files as $file){
$path = $directory . $source->sanitizePath($file['name']);
$object = $source->getObjectContents($path);
if(empty($object) || empty($object['mime']) || empty($object['content'])) continue;
switch($object['mime']) {
case 'image/svg':
@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 / evo2revo.site_content.sql
Last active December 13, 2022 18:07
Evo to Revo
SELECT id, type, pagetitle, longtitle, description, alias, alias_visible, link_attributes, published, pub_date, unpub_date, parent, isfolder, introtext, content, richtext, template, menuindex, searchable, cacheable, createdby, createdon, editedby, editedon, deleted, deletedon, deletedby, publishedon, publishedby, menutitle, donthit, privateweb, privatemgr, content_dispo, hidemenu, 'MODX\\Revolution\\modDocument' AS class_key, 'web' AS context_key, 1 AS content_type, null AS uri, 0 AS uri_override, 0 AS hide_children_in_tree, 1 AS show_in_tree, null AS properties FROM `modx_site_content`
@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)){