Skip to content

Instantly share code, notes, and snippets.

@bwente
bwente / pingX.php
Created June 7, 2016 17:54
MODX snippet to ping a site
<?php
// [[pingX? &url=`www.google.com` &offline=`site down`]]
$url = $modx->getOption('url', $scriptProperties, '');
$offline = $modx->getOption('offline', $scriptProperties, '');
$timeout = $modx->getOption('timeout', $scriptProperties, '30');
$port = $modx->getOption('port', $scriptProperties, '80');
if (!$socket = @fsockopen($url, $port, $errno, $errstr, $timeout)) {
// Offline
$result = $offline;
@bwente
bwente / form_date_selects.php
Created September 26, 2016 15:11
MODX FormIt date selections
<select name="dob-day" id="dob-day">
<option value="">Day</option>
<option value="">---</option>
<option value="01" [[!+fi.dob-day:FormItIsSelected=`01`]]>01</option>
<option value="02" [[!+fi.dob-day:FormItIsSelected=`02`]]>02</option>
<option value="03" [[!+fi.dob-day:FormItIsSelected=`03`]]>03</option>
<option value="04" [[!+fi.dob-day:FormItIsSelected=`04`]]>04</option>
<option value="05" [[!+fi.dob-day:FormItIsSelected=`05`]]>05</option>
<option value="06" [[!+fi.dob-day:FormItIsSelected=`06`]]>06</option>
<option value="07" [[!+fi.dob-day:FormItIsSelected=`07`]]>07</option>
@bwente
bwente / FormItNumberRanges.php
Last active March 28, 2018 19:05
FormItNumberRanges
<?php
// [[!FormItNumberRanges? &numberStart=`50000` &numberStop=`200000` &numberStep=`10000` &numberSeparator=` – ` &fieldName=`loanAmount` &fieldValue=`low` ]]
$numberStart = $modx->getOption('numberStart',$scriptProperties,'50000');
$numberStop = $modx->getOption('numberStop',$scriptProperties,'200000');
$numberStep = $modx->getOption('numberStep',$scriptProperties,'10000');
$numberSeparator = $modx->getOption('numberSeparator',$scriptProperties,' – ');
$numberFormat = $modx->getOption('numberFormat',$scriptProperties,'USD');
$fieldName = $modx->getOption('fieldName',$scriptProperties,'');
$fieldValue = $modx->getOption('fieldValue',$scriptProperties,'low');
@bwente
bwente / fmt.Contains.php
Created March 23, 2017 15:19
MODX output filter for finding matching strings
<?php
$parameters = explode(',',$options);
$test = $parameters[0];
$success = $parameters[1];
$output = " "; // needed a space to make this work
if (stristr($input, $test) !== false) {
$output = $success;
}
@bwente
bwente / fmt.stopString.php
Created September 20, 2017 16:14
Truncates string prior to the stop string.
<?php
return substr($input, 0, strpos($input, $options));
@bwente
bwente / WebHook.php
Created November 8, 2017 15:55
Very basic webhook for MODX, posts JSON to a URL. Works well with Zapier.
<?php
// [[!WebHook? &secret=`dh730>soteW` &runsnippet=`updateSettings` &params=`setting=savings`]]
$mySecret = $modx->getOption('secret', $scriptProperties);
$mySnippet = $modx->getOption('runsnippet', $scriptProperties);
$myParams = $modx->getOption('params', $scriptProperties);
$achunks = array_chunk(preg_split('/(=|,)/', $myParams), 2);
$myParams = array_combine(array_column($achunks, 0), array_column($achunks, 1));
$webhookContent = "";
@bwente
bwente / NotePad.php
Created November 8, 2017 15:57
MODX snippet to write to a text file.
<?php
$content = $modx->getOption('content', $scriptProperties, 'eof');
$filename = $modx->getOption('filename', $scriptProperties, 'text.txt');
$filedir = $modx->getOption('filedir', $scriptProperties, 'assets');
$append = $modx->getOption('append', $scriptProperties, false);
$fopen = "w";
if ($append > 0){
$fopen = "a";
};
@bwente
bwente / updateSetting.php
Created November 8, 2017 15:58
Snippet to update a MODX system setting
<?php
$setting = $modx->getOption('setting', $scriptProperties);
$value = $modx->getOption('value', $scriptProperties);
$systemSetting = $modx->getObject('modSystemSetting', $setting);
$systemSetting->set('value',$value);
$systemSetting->save();
$modx->reloadConfig();
return true;
@bwente
bwente / FormItPDF.php
Created November 27, 2017 15:29
FormItPDF
<?php
$fileIn = $hook->formit->config['fileIn'];
$fileOut = $hook->formit->config['fileOut'];
$fileInPath = $modx->config['base_path'].$fileIn;
$fileOutPath = $modx->config['base_path'].$fileOut;
$formData = $hook->getValues();
// FDF header section
@bwente
bwente / months2years.php
Created August 30, 2018 17:09
MODX output filter to convert months to years
<?php
$years = floor($input/12);
$months = $input%12;
$yearsDisplay = $years.($years > 1 ? ' years' : ' year');
if($years == 0) {
$yearsDisplay = '';
}
$monthsDisplay = $months.($months > 1 ? ' months' : ' month');
if($months == 0) {