Skip to content

Instantly share code, notes, and snippets.

@matdave
matdave / teleport.modxcloud.md
Last active November 29, 2022 22:21
Using teleport in MODX Cloud

Install Composer

SSH into the primary clouds as the cXXXX user, then run the following commands:

> cd www
> curl http://modx.co/scripts/install.sh | sh
> source ~/.profile
<?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 / gitifysetup.md
Last active September 1, 2022 21:15
Hooking up a staging environment to gitify

Hooking up a staging environment to a Gitify Project

Install Gitify

Use composer to install Gitify on your environment

composer global require modmore/gitify:^2

Install a clean MODX environment

@matdave
matdave / autoRotateImage.plugin.php
Last active August 31, 2022 14:50
MODX Auto Rotate Image
<?php
/* Based on https://gist.github.com/OptimusCrime/dac5deec0d65872740c9d7bccdc5e336
** Add system setting named "max_image_dimension" to set a max height or width for images
*/
if(!function_exists(autoRotateImage)) {
function autoRotateImage($image,$max_image_dimension = 0) {
$orientation = $image->getImageOrientation();
switch($orientation) {
case imagick::ORIENTATION_BOTTOMRIGHT:
@matdave
matdave / logid.cfg
Created May 4, 2022 14:22
LogiOps MX Master 2S
devices: (
{
name: "Wireless Mouse MX Master 2S";
smartshift:
{
# Do not enable free scroll
on: true;
threshold: 15; # 7 is ideal for work
};
hiresscroll:
@matdave
matdave / FredPreview.plugin.php
Created April 20, 2022 19:07
Make Fred play nice w/ Preview
<?php
//** On WebPage Pre-Render **//
$corePath = $modx->getOption('preview.core_path', null, $modx->getOption('core_path') . 'components/preview/');
require_once $corePath . '/model/preview/preview.class.php';
$preview = new Preview($modx);
if(!$modx->user->hasSessionContext('mgr')) return; // currently forcing manager context
if(!$modx->getOption('preview.frontendEnabled')) return; // currently forcing manager context
$qsItem = $modx->getOption('preview.previewKey');
$compareItem = $modx->getOption('preview.compareKey');
@matdave
matdave / mailtofix.hook.php
Created June 8, 2018 18:07
MODX FormIt Multi-Email Fix (for dynamic emails)
<?php
$fields = $hook->getValues();
$emailTo = $hook->formit->config['emailTo'];
if(strpos($emailTo,'[[+') !== false){
$emailVar = str_replace('[[+','',$emailTo);
$emailVar = str_replace(']]','',$emailVar);
$hook->formit->config['emailTo'] = $fields[$emailVar];
}
return true;
@matdave
matdave / createdBy.plugin.php
Created August 12, 2020 21:05
MODX change author plugin
<?php
/**
* Plugin to add a "created by" field on a resource form and moves "published on" to document tab
*
* @var modX $modx
* @var array $scriptProperties
*
* @event OnDocFormPrerender
*/
$dateFormat = $modx->getOption('manager_date_format',null,'d.m.Y');
@matdave
matdave / mimeFix.plugin.php
Last active November 16, 2021 15:52
SVG fix for MODX 3 S3 source
<?php
switch ($modx->event->name) {
case "OnFileManagerUpload":
if(!empty($files)){
foreach($files as $file){
$path = $directory . $source->sanitizePath($file['name']);
$object = $source->getObjectContents($path);
if(empty($object) || empty($object['mime']) || empty($object['content'])) continue;
switch($object['mime']) {
case 'image/svg':
@matdave
matdave / index.php
Created November 5, 2021 17:41
PHP to HTML
<?php
$base_path = dirname(__FILE__) . '/content/';
if($_GET['q']) {
$q = explode('?', $_GET['q']);
$file_check = $base_path.preg_replace('"\.html$"', '.php', $q[0]);
if (substr($file_check, -1) == "/") {
$file_check .= "index.php";
}