Skip to content

Instantly share code, notes, and snippets.

View netProphET's full-sized avatar

Mike Schell netProphET

  • MODX, LLC
  • Bancroft, Ontario, Canada
View GitHub Profile
@netProphET
netProphET / pdftojpeg.snippet.php
Created October 4, 2018 20:43
proof of concept for converting PDF to image in MODX Cloud
<?php
/**
* Proof of Concept of PDF to image conversion, working in MODX Cloud
*/
$file = $scriptProperties['file'];
$targetFolder = $modx->getOption('target', $scriptProperties, '/assets/images');
$fullTargetFolderPath = MODX_BASE_PATH . $targetFolder;
if (!preg_match("/\.pdf$/", $file)) {
@netProphET
netProphET / web_rules.conf
Last active November 25, 2015 19:42
Used in the "web rules" in MODX Cloud, this set of directives allows you to serve robots.txt requests from MODX for your production hostnames, but blocks robot access on the modxcloud.com hostnames. This can be useful if you have a multi-context site and wish to serve different robots.txt responses per context/hostname.
# Pass robots.txt requests to MODX unless the hostname matches modxcloud.com
# Note: robots.txt files on the filesystem will be completely ignored
set $roboloco "@modx-rewrite";
if ($host ~* modxcloud\.com) {
set $roboloco "@robots-disallow";
}
location ~ ^/robots\.txt$ {
try_files foobar $roboloco;
}
@netProphET
netProphET / simplesearch.snippet.php
Last active May 20, 2018 19:14
first draft at solving MODX SimpleSearch FR #7
<?php
/**
* SimpleSearch
*
* Copyright 2010-11 by Shaun McCormick <[email protected]>
*
* This file is part of SimpleSearch, a simple search component for MODx
* Revolution. It is loosely based off of AjaxSearch for MODx Evolution by
* coroico/kylej, minus the ajax.
*
@netProphET
netProphET / nginx.conf
Created November 2, 2013 12:10
phpThumbStatCache rewrite rules for MODX Cloud
location ~ ^/i/(.*) {
error_log /c0324/log/image.log notice;
rewrite_log on;
set $phptfn $1;
rewrite ^(.*?)\/w\/(\d+)\/(.*)$ $1/$3?w=$2&$args;
rewrite ^(.*?)\/h\/(\d+)\/(.*)$ $1/$3?h=$2&$args;
rewrite ^(.*?)\/new\/(\d+)\/(.*)$ $1/$3?new=$2&$args;
rewrite ^(.*?)\/wp\/(\d+)\/(.*)$ $1/$3?wp=$2&$args;
rewrite ^(.*?)\/hp\/(\d+)\/(.*)$ $1/$3?hp=$2&$args;
rewrite ^(.*?)\/w1\/(\d+)\/(.*)$ $1/$3?w1=$2&$args;
@netProphET
netProphET / nginx.conf
Created April 8, 2013 17:30
MODX Cloud Nginx "Web Rule" for Adaptive Images script https://github.com/MattWilcox/Adaptive-Images
# Adaptive-Images rewrite
# this example bypasses requests for any images in the root assets and ai-cache folders
rewrite ^/(?!assets|ai-cache).*\.(jpe?g|gif|png)$ /adaptive-images.php last;
location / {
try_files $uri $uri/ @modx-rewrite;
}
@netProphET
netProphET / babelContextRouter.plugin.php
Last active October 19, 2023 07:08
MODX Cloud web rules example for Babel with two languages.In this example, German is the default language with resources in the 'web' context; English is the secondary language, set up in the 'en' context.This technique is based on the "SEO Friendly Multilingual Websites" article archived here: https://web.archive.org/web/20180927220103/http://w…
<?php
if($modx->context->get('key') != "mgr"){
/* grab the current langauge from the cultureKey request var */
switch ($_REQUEST['cultureKey']) {
case 'en':
/* switch the context */
$modx->switchContext('en');
break;
default:
/* Set the default context here */
@netProphET
netProphET / manager_leftpanel_width.plugin.php
Created June 22, 2012 15:05
plugin fragment for setting width of MODX Manager left panel
<?php
/**
* plugin fragment for setting width of MODX Manager left panel
*/
if($modx->event->name == 'OnBeforeManagerPageInit') {
// update layout manager state
$state = $modx->controller->getDefaultState();
$state['modx-leftbar-tabs']['width'] = 525;
$response = $modx->runProcessor('system/registry/register/send',array(
'register' => 'state',
@netProphET
netProphET / autoResourceSelect.html
Created November 25, 2011 21:04
select element of resources, will take user to resource selected
<select name="mySelect" id="mySelectId" onchange="el=document.getElementById('mySelectId');u=el.options[el.selectedIndex].value;if(u!=''){window.location.href=u;}">
[[getResources? &parents=`0` &tpl=`selectOption.tpl`]]
</select>
@netProphET
netProphET / migx_modx-2.2.diff
Created October 6, 2011 04:22
MIGX diff for MODX2.2
--------------- core/components/migx/elements/tv/input/migx.php ---------------
index 11a9c2d..53370a5 100644
@@ -133,6 +133,7 @@ $lang = $this->xpdo->lexicon->fetch();
$lang['mig_add'] = !empty($properties['btntext'])?$properties['btntext']:$lang['mig_add'];
$modx->smarty->assign('i18n', $lang);
$this->xpdo->smarty->assign('properties', $properties);
+$this->xpdo->smarty->assign('resource', is_object($this->xpdo->resource) ? $this->xpdo->resource->toArray() : array());
$this->xpdo->smarty->assign('pathconfigs', $this->xpdo->toJSON($pathconfigs));
$this->xpdo->smarty->assign('columns', $this->xpdo->toJSON($cols));
$this->xpdo->smarty->assign('fields', $this->xpdo->toJSON($fields));
<?php
if ($modx->event->name == 'OnManagerPageInit') {
$script = <<<SCRIPT
<script type="text/javascript">
Ext.ComponentMgr.onAvailable('modx-panel-resource', function(){
Ext.getCmp('modx-panel-resource').on('ready', function(){
window.setTimeout(function(){Ext.getCmp('modx-panel-resource').markDirty()}, 250);
})
})
</script>