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 / Mobile Device Detect
Last active January 5, 2023 16:33
A simple mobile device detector in PHP . If $mobile_browser == true ....
<?
$mobile_browser = false; // set mobile browser as false till we can prove otherwise
$user_agent = $_SERVER['HTTP_USER_AGENT']; // get the user agent value - this should be cleaned to ensure no nefarious input gets executed
$accept = $_SERVER['HTTP_ACCEPT']; // get the content accept value - this should be cleaned to ensure no nefarious input gets executed
switch(true){ // using a switch against the following statements which could return true is more efficient than the previous method of using if statements
case (preg_match('/ipad/i',$user_agent)); // we find the word ipad in the user agent
$mobile_browser = false; // mobile browser is either true or false depending on the setting of ipad when calling the function
$status = 'Apple iPad';
@dubrod
dubrod / modx-youtube-api
Created October 5, 2016 16:21
Pass a you Video ID or comma separated string of IDS to output a thumbnail and title and a link
//chunk youtube-video-tpl
<div class="col-1-3">
<a class="mediabox" rel="ytv" href="http://www.youtube.com/embed/[[+id]]">
<img src="[[+thumb]]" alt="">
<h3>[[+title]]</h3>
</a>
</div>
//Snippet
<?php
@dubrod
dubrod / Call Google Geocoding API with jQuery
Created August 30, 2013 17:32
Call the Google Geocoding API with jQuery. Get the formatted address, the LAT & LONG, the County, all the official google map data for an address.
<label>Street Address #: <small>123</small></label><br>
<input type="text" id="stAddNum"><br>
<label>Street Address Name: <small>Elm</small></label><br>
<input type="text" id="stAdd"><br>
<label>Address Type: <small>St, Ave, Ln, Rd, etc</small></label><br>
<input type="text" id="stAddPrefix"><br>
<label>City: </label><br>
<input type="text" id="city"><br>
<label>State: <small>Abbreviation</small></label><br>
<input type="text" id="state"><br>
@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 / Commonly Used MODX Head Tags
Last active January 7, 2019 17:51
Commonly Used MODX Head Tags for use in my Public Snapshots
<title>[[*pagetitle]]</title>
<title>[[*longtitle:default=`[[*pagetitle]]`]]</title>
<meta name="description" content="[[*description]]">
<meta name="keywords" content="[[*keywords]]">
<meta itemprop="url" content="[[~[[*id? &scheme=`full`]]]]">
<meta itemprop="name headline" content="[[*pagetitle]]">
<meta itemprop="description" content="[[*description]]">
<meta itemprop="image" content="">
<!-- Twitter -->
@dubrod
dubrod / 2013 Adaptive CSS Containers
Last active December 15, 2018 19:01
2013 Adaptive CSS Containers Snippet. From 1600+ to Mobile. This snippet will keep a nice margin on the sides of your container for browser size most used in 2012. It's not a Responsive Snippet, that would be using %.
/*~~~~ CONTAINERS December 2013 - http://www.w3counter.com/globalstats.php ~~~~*/
/* 1600x900 4.09% */
.container{
margin: 0 auto;
padding:0;
height:auto;
width:1410px; /* 3 Columns would be 470px */
}
/* 1440x900 5.26% */
@media (max-width: 1440px){ .container{width: 1230px; /* 3 Columns would be 410px */ } }
@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);