Skip to content

Instantly share code, notes, and snippets.

View dubrod's full-sized avatar

Wayne Roddy dubrod

View GitHub Profile
@dubrod
dubrod / gist:418349c05060193e691d404359937d59
Created March 7, 2024 17:30
MODX Delete Old Files on Form Submit
<?php
/**
* A simple function that uses mtime to delete files older than a given age (in seconds)
* Very handy to rotate backup or log files, for example...
*
* $dir String whhere the files are
* $max_age Int in seconds
* return String[] the list of deleted files
*/
@dubrod
dubrod / gist:744422d14739e45028d78e0f7fd06680
Created August 18, 2020 15:53
TimeEncryptor & SpamKiller
TimeEncryptor:
<?php
$encryptedValue = base64_encode(time());
return $encryptedValue;
SpamKiller:
<?php
/*
Custom Spam Killer Functions
used in conjuction with <input type="hidden" name="formitTimeEncryptor" value="[[!TimeEncryptor]]" />
@dubrod
dubrod / MODX ID to JSON
Last active January 23, 2019 21:39
MODX ID to JSON
<?php
header("Content-Type:application/json");
$id = $_GET["id"];
if(empty($id)){ die(); }
$obj = $modx->getObject('modResource', $id);
$output = [];
@dubrod
dubrod / modx-up-title
Created November 30, 2018 00:59
simple ultimate parent title
<?php
//4 levels deep
$title = '';
//first level parent
$parentId = $modx->resource->get('parent');
if($parentId == 0){
$title = $modx->parseChunk('interior-title', array('title' => $modx->resource->get('pagetitle') ));
return $title;
Group 1 = Category | Combo Box
Group 2 = Keywords | Tag field
Category Template
Snippet = [[cateName]]
<?php
$get = modX::sanitize($_GET, $modx->sanitizePatterns);
$tag = ucfirst(urldecode($get['categories']));
$tag = str_replace("-"," ", $tag);
QUERIES
$resources = $modx->getCollection('modResource', array('published'=>'1','hidemenu'=>'0','isfolder'=>'1','parent'=>'16','class_key'=>'modDocument'));
foreach($resources as $resource) {
$id = $resource->get('id');
$thumb = $resource->getTVValue('thumbImage');
}
OR--
https://rtfm.modx.com/revolution/2.x/developing-in-modx/advanced-development/modx-services/modmail
/* modx mail service */
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY,$message);
$modx->mail->set(modMail::MAIL_FROM,$from);
$modx->mail->set(modMail::MAIL_FROM_NAME,'Quick Quote');
$modx->mail->set(modMail::MAIL_SUBJECT,'Lease Quote #'.$id.'');
$modx->mail->address('to','sales@theleaseoutlet.dsmessage.com');
//$modx->mail->address('reply-to','me@xexample.org');
Friendly URL container_suffix must = /
System Setting:
Key: archivist.archive_ids
name empty
namespace: archivist
area lexicon: furls
value: 18:arc_ (18 being resource id)
Archive Template ( needs to be container )
@dubrod
dubrod / modx-form-snips
Created November 30, 2018 00:43
collection of modx form snips
http://rtfm.modx.com/extras/revo/formit/formit.tutorials-and-examples/formit.handling-selects,-checkboxes-and-radios
[[!FormIt?
&hooks=`spam,email,redirect`
&emailTpl=`ContactEmailTpl`
&emailFrom=`[[++emailsender]]`
&emailTo=`wayne@modx.com`
&emailUseFieldForSubject=`1`
&redirectTo=`33`
&validate=`name:required,
@dubrod
dubrod / modx-parent-snips
Created November 30, 2018 00:40
collection of modx parent snippets
GetParentAlias
$output = '';
/* Get the current resource's 'parent' field */
$parentId = $modx->resource->get('parent');
/* Get the parent object */
$parentObj = $modx->getObject('modResource', $parentId);