Skip to content

Instantly share code, notes, and snippets.

@matdave
matdave / gist:32502ea68e43c3201e8c
Last active August 29, 2015 14:17
nps menu expand
$(document).ready(function() {
$(".btn").click(function() {
if(!$(this).hasClass('close-schools')){
$( ".school-list" ).addClass("expanded");
$(this).addClass("close-schools");
}else{
$(this).removeClass("close-schools");
$(".school-list").removeClass("expanded");
}
});
@matdave
matdave / hideDeleted
Last active June 4, 2017 13:53
HideDeleted
<?php
/* Set plugin to run on "OnManagerPageBeforeRender"
*/
$user = $modx->getUser();
$restricted = true;
if($user) {
$restricted = (!$user->isMember(array('Administrator')));
}
if($restricted){
$modx->regClientStartupHTMLBlock('<style type="text/css">.deleted{display:none;}</style>');
@matdave
matdave / googletranslateclass.js
Last active May 2, 2016 16:32
Google Translate class
$(document).ready(function(){
if(window.location.href.indexOf("google.com") > -1)
{
$("body").addClass("trans");
}
});
<?php
$doc = $modx->newObject('modResource');
$doc->set('createdby', $modx->user->get('id'));
$allFormFields = $hook->getValues();
foreach ($allFormFields as $field=>$value)
{
$doc->set($field, $value);
}
@matdave
matdave / MODX-Upgrade.md
Last active August 31, 2015 20:38
MODX Upgrade on cPanel

The key to upgrading MODX is backup & testing. It is imperative test all features after a major system upgrade, because some packages can break. Before upgrading packages or systems, look for upgrade notes within the website's wiki page or client's job notes if no wiki exists. Also, before upgrading ensure there is enough room on the server for at least double the current file size.

Lock Down the Manager

Either using the Manager or SSH update / create an .htaccess file behind the manager folder with the following command:

order deny,allow
deny from all
allow from YOUR-IP-ADDRESS
@matdave
matdave / success.phtml
Created September 4, 2015 15:47
Magento Ecommerce Snippet
<?php
// Transaction Data
$orderID = $this->getOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($orderID);
$orderTotal = $order->getGrandTotal();
// you can also add affiliation, shipping and tax
$trans = array('id' => $orderID,
'revenue' => $orderTotal);
// List of Items Purchased
@matdave
matdave / devChunk
Last active June 4, 2017 13:56
MODX Output Modifier for Serving an Alternate Chunk
<?php
/** devChunk MODX Output Modifier **
**
** Returns an alternate chunk to users in the groups defined below
** Usage [[$livechunk:devChunk=`alternatechunk`]]
**
**/
$user = $modx->getUser();
$restricted = true;
@matdave
matdave / richIntro
Last active June 4, 2017 14:01
MODX Rich Introtext w/ Toggle
<?php
/*
** richIntro
** Plugin checks if introtext is filled in yet, and hides it if not. Run 'onDocFormRender'
** http://g.recordit.co/VOYqBC3CnS.gif
*/
$introtext = empty($resource->get('introtext'));
if($introtext){
$modx->regClientStartupHTMLBlock('<script>Ext.onReady(function() {
var introtext = Ext.getCmp("modx-resource-introtext");
<?php
// Plugin corrects anchored items when base_ref is set to site root
// Run OnWebPagePrerender
$url = $modx->makeUrl($modx->resource->get('id'));
$modx->resource->_output = str_replace(' href="#', ' href="'.$url.'#', $modx->resource->_output);
@matdave
matdave / CommentMangerIP.plugin.php
Last active August 26, 2016 17:26
MODX Manager IP Log - Log a managers IP when they login
<?php
switch ($modx->event->name) {
case 'OnManagerLogin':
$userinfo =& $modx->event->params['user'];
if(!empty($userinfo)){
$ip = getenv('HTTP_CLIENT_IP')?:
getenv('HTTP_X_FORWARDED_FOR')?:
getenv('HTTP_X_FORWARDED')?:
getenv('HTTP_FORWARDED_FOR')?:
getenv('HTTP_FORWARDED')?: