Skip to content

Instantly share code, notes, and snippets.

@Mark-H
Mark-H / connector.php
Created April 12, 2016 11:10
Connector for MODX Revolution with whitelist of permitted actions accessible from the web
<?php
// set context
$_REQUEST['ctx'] = 'web';
require_once dirname(dirname(dirname(dirname(__FILE__)))).'/config.core.php';
require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php';
require_once MODX_CONNECTORS_PATH . 'index.php';
// define allowed actions
$webActions = array(
'one/allowed/action',
@Mark-H
Mark-H / PoweredBy.php
Created January 26, 2016 18:27
MODX X-Powered-By header
<?php
/**
* Add as a plugin
* System Event: OnHandleRequest
*/
if (!headers_sent()) {
header('X-Powered-By: MODX Revolution');
}
@Mark-H
Mark-H / 1_interface_and_base_class.php
Created March 4, 2015 11:57
Object Oriented Snippets for MODX :D There are a couple of files here. The first one (`1_interface_and_base_class.php`) contains an interface and the base abstract class for creating snippets. The second file (`2_example_snippet.php`) is a real basic example of a snippet. The third file (`3_modSnippet.php`) is the code that is in the actual modS…
<?php
namespace mhwd\Donations;
/**
* Interface ObjectOrientedSnippet
*
* @see Snippet class
*
* @package mhwd\Donations
@Mark-H
Mark-H / plugin.php
Created August 20, 2014 22:24
Auto Login Plugin for MODX Demo Sites. Add to OnManagerLoginFormRender event.
<?php
if ($modx->getOption('http_host') == 'YOUR_DOMAIN_HERE') {
$op = '<script type="text/javascript">
Ext.onReady(function() {
document.getElementById("modx-login-username").value = "USER";
document.getElementById("modx-login-password").value = "PASS";
document.getElementById("modx-login-btn").click();
});
</script>';
@Mark-H
Mark-H / compare.lexicon.php
Created June 19, 2014 12:50
compare.lexicon.php - A super useful script for people that want to update translations for MODX (or MODX Extras) and need to get a good at a glance view of the changes. Got it from the forums somewhere in the past, but can't find the original source now. It probably changed a bit over the years too.
<?php
$default = realpath(dirname(__FILE__).'/core/lexicon/en').'/';
$local = realpath(dirname(__FILE__).'/core/lexicon/nl').'/';
$showSame = false;
// find default files
$theFiles = array();
if($handle = opendir($default)) {
while(false !== ($file = readdir($handle))) {
@Mark-H
Mark-H / snippet.php
Created March 4, 2014 10:39
Fix Gallery update to 1.6
<?php
$modelPath = $modx->getOption('gallery.core_path',null,$modx->getOption('core_path').'components/gallery/').'model/';
$modx->addPackage('gallery',$modelPath);
$manager = $modx->getManager();
$manager->addField('galAlbum', 'year');
@Mark-H
Mark-H / 0_reuse_code.js
Created February 3, 2014 14:19
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@Mark-H
Mark-H / a readme.md
Last active November 24, 2022 13:16
modCli; using MODX on the commandline.

modCLI

modCLI is a wrapper for the MODX Revolution Processors, allowing you to pretty much do anything from the commandline that you would normally do within the manager.

To use modCLI, simply download the modcli.php file and put it in the MODX_BASE_PATH of your installation. Next open up the console or terminal, and start firing some commands at it.

Syntax

@Mark-H
Mark-H / benchmark.php
Created December 7, 2012 17:41
MODX Performance Benchmark Snippet
<?php
// Use this line to prevent people from hammering your server.
if (!isset($_GET['super_secret']) || ($_GET['super_secret'] != 'secretpassword')) return 'Not authorized';
// Call this snippet uncached in a resource with template "empty":
// content: "[[!benchmark]]"
// Make sure to tag the resource as uncachable
// The intro
echo '<body style="font-family: sans-serif;">';
@Mark-H
Mark-H / gist:3799296
Created September 28, 2012 11:30
Change template for @datarecall #modx
<?php
$parent = 5;
$resourceWithChildrenTpl = 1;
$resourceWithoutChildrenTpl = 2;
$childs = $modx->getChildIds($parent);
foreach ($modx->getIterator('modResource',array('id:IN' => $childs)) as $resource) {