Skip to content

Instantly share code, notes, and snippets.

@matdave
matdave / gitifysetup.md
Last active September 1, 2022 21:15
Hooking up a staging environment to gitify

Hooking up a staging environment to a Gitify Project

Install Gitify

Use composer to install Gitify on your environment

composer global require modmore/gitify:^2

Install a clean MODX environment

@matdave
matdave / logid.cfg
Created May 4, 2022 14:22
LogiOps MX Master 2S
devices: (
{
name: "Wireless Mouse MX Master 2S";
smartshift:
{
# Do not enable free scroll
on: true;
threshold: 15; # 7 is ideal for work
};
hiresscroll:
@matdave
matdave / FredPreview.plugin.php
Created April 20, 2022 19:07
Make Fred play nice w/ Preview
<?php
//** On WebPage Pre-Render **//
$corePath = $modx->getOption('preview.core_path', null, $modx->getOption('core_path') . 'components/preview/');
require_once $corePath . '/model/preview/preview.class.php';
$preview = new Preview($modx);
if(!$modx->user->hasSessionContext('mgr')) return; // currently forcing manager context
if(!$modx->getOption('preview.frontendEnabled')) return; // currently forcing manager context
$qsItem = $modx->getOption('preview.previewKey');
$compareItem = $modx->getOption('preview.compareKey');
@matdave
matdave / index.php
Created November 5, 2021 17:41
PHP to HTML
<?php
$base_path = dirname(__FILE__) . '/content/';
if($_GET['q']) {
$q = explode('?', $_GET['q']);
$file_check = $base_path.preg_replace('"\.html$"', '.php', $q[0]);
if (substr($file_check, -1) == "/") {
$file_check .= "index.php";
}
@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