Skip to content

Instantly share code, notes, and snippets.

@matdave
matdave / delayClearCache.plugin.php
Created October 16, 2019 20:35
Delay Clearing Cache on Resource Save
<?php
switch ($modx->event->name) {
case 'OnBeforeDocFormSave':
$now = mktime();
$lastcache = $modx->cacheManager->get('delaycache');
if(!empty($lastcache) && ($now - $lastcache) < 300){
$_POST['syncsite'] = 0;
}
return;
break;
@matdave
matdave / sp.nginx
Created August 8, 2019 21:24
Stackpath nginx Real IP
#list of trusted IPs
set_real_ip_from 69.16.133.0/24
set_real_ip_from 69.16.176.0/20
set_real_ip_from 69.16.182.0/24
set_real_ip_from 69.16.184.0/24
set_real_ip_from 69.16.188.0/24
set_real_ip_from 74.209.134.0/24
set_real_ip_from 74.209.134.128/25
set_real_ip_from 81.171.60.0/24
set_real_ip_from 81.171.61.0/24
@matdave
matdave / list_all_tags.chunk.tpl
Last active February 21, 2019 16:08
getResource with NO tags
[[TaggerGetTags? &groups=`2` &parents=`5` &rowTpl=`tag_groups_tpl`]]
[[getResources:toPlaceholder=`uncategorized`?
&parents=`5`
&limit=`0`
&tpl=`list_row_tpl`
&sortby=`publishedon`
&sortdir=`DESC`
&includeContent=`1`
&includeTVs=`1` &processTVs=`1` &tvPrefix=`tv.`
&where=`["NOT EXISTS (SELECT 1 FROM `modx_tagger_tag_resources` r WHERE r.resource = modResource.id)"]`
@matdave
matdave / pdftojpeg.snippet.php
Last active January 29, 2019 20:26 — forked from netProphET/pdftojpeg.snippet.php
PDF Thumbnailing in MODX - Proof of Concept
<?php
/**
* Warning: this code is for demonstration purposes only
*/
if (!preg_match("/\.pdf$/", $input)) {
return "PDF file not specified.";
}
$options = explode('&', $modx->getOption('options', $scriptProperties, null));
if(empty($options)){
@matdave
matdave / formtabs.json
Last active December 13, 2022 19:22
Convert Maxi to MIGX
[
{"caption":"Image", "fields":[
{"field":"image","caption":"Image","inputTVtype":"image"}
]},
{"caption":"Info", "fields": [
{"field":"title","caption":"Title"},
{"field":"description","caption":"Description","inputTVtype":"richtext"}
]}
]
@matdave
matdave / evoURI.plugin.php
Created October 19, 2018 18:58
Evo to Revo URI Plugin
<?php
/**
** OnPageNotFound
**/
$URI = $_SERVER['REQUEST_URI'];
if(strpos($URI, '.html') !== false){
$URI = ltrim(str_replace('.html','/',$URI), '/');
$resource = $modx->getObject('modResource', array('uri:='=>$URI, 'context_key:='=> $modx->context->key));
@matdave
matdave / maxi.import.php
Last active October 11, 2019 15:14
Maxi to MIGX
<?php
ini_set('max_execution_time', 72000);
ini_set('memory_limit', '2048M');
define('MODX_CORE_PATH', '/home/www/core/');
require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
if(!function_exists('csv2array')){
function csv2array($filename = '', $delimiter = ',', $asHash = true)
{
@matdave
matdave / filesModifiedSince.snippet.php
Last active October 12, 2018 21:01
filesModifiedSince
<?php
function filesModifiedSince($dir = "/", $modified = 0, $exclude = array()) {
$result = array();
$exclude = array_merge(array(".",".."), $exclude);
$limit = time() - $modified;
$cdir = scandir($dir);
foreach ($cdir as $key => $value)
{
if (!in_array($value,$exclude))
@matdave
matdave / keybase.md
Created October 1, 2018 10:44
keybase.md

Keybase proof

I hereby claim:

  • I am matdave on github.
  • I am matjones (https://keybase.io/matjones) on keybase.
  • I have a public key whose fingerprint is 844B 38BB 2C5A 974B 5667 F125 3AED 15C3 A370 EE19

To claim this, I am signing this object:

@matdave
matdave / fixjson.php
Last active September 27, 2018 18:48
Fix Media Sources
<?php
function fixJSON($array, $mediaSources) {
$fix = array();
foreach( $array as $key => $value) {
if (is_array($value)) {
$fix[$key] = fixJSON($value);
} else{
if(in_array($key, array('mediaSource','imageMediaSource')){
if(!empty($mediaSources[$value])){
$value = $mediaSources[$value];