Skip to content

Instantly share code, notes, and snippets.

View Jako's full-sized avatar

Thomas Jakobi Jako

View GitHub Profile
@Jako
Jako / util.js
Last active November 3, 2024 15:47
ExtJS download utility
// This utility method allows downloading files with a failure and a success callback.
// It uses the following setting in the fields property:
//
// Key | Default | Description
// ------- | ------------------------- | -----------
// url | MODx.config.connector_url | The connector url
// timeout | 30 | Set a polling timeout
// debug | false | Log the polling in the console
// params | {} | Additional params for the connector url
// success | null | Callback called after a successful download,
@Jako
Jako / cbGetLayoutSettings.snippet.php
Last active August 20, 2021 08:46
Get a templated list of ContentBlocks layout settings
<?php
/**
* Use the cbGetLayoutSettings snippet to get a templated list of settings from a particular layout.
* Based on cbGetLayoutSetting snippet https://gist.github.com/sepiariver/302ab3cc7bd47233f0136f4379de89cf
*
* @param (id) &resource allows checking for fields on other resources.
* @param (bool) &showDebug return debugging info as JSON.
* @param (string) &toPlaceholder set a placeholder with this string as key, instead of returning.
* @param (int) &layout - (required) ID of ContentBlocks layout from which to fetch the settings.
* @param (string) &tpl - name of chunk for templating the settings of one layout.
@Jako
Jako / code_patterns.md
Last active March 15, 2021 08:54
Code patterns for Extras compatibility in MODX3 and MODX2

Code patterns for Extras compatibility in MODX3 and MODX2

Use a fqn prefix for modTransport classes:

$modx->getTableName('modTransportPackage')

to

@Jako
Jako / gist:0679e1b23cb8f5c5494c6826eba0f6a9
Created October 18, 2019 17:41
MODX FormIt Email Selector
<?php
$selectField = $modx->getOption('emailSelectField', $scriptProperties, 'department');
$selectTo = $modx->getOption('emailSelectTo', $scriptProperties, '');
$selectTo = ($selectTo) ? explode(',', $selectTo) : array();
if ($selectField && $selectTo) {
$selected = intval($hook->getValue($selectField)) - 1;
if ($selected && isset($selectTo[$selected])) {
$hook->formit->config['emailTo'] = $selectTo[$selected];
}
@Jako
Jako / resolve.access_permissions.php
Created November 20, 2016 12:56
Access permissions resolver for MODX packages
<?php
/**
* Resolve access permissions
*
* @package sample
* @subpackage build
*
* @var mixed $object
* @var array $options
*/
@Jako
Jako / gist:c9ea82324c62c90c15ade95254ac57e1
Created November 16, 2016 14:31
Recursive download with curl and open_basedir
/**
* Load data from URL with curl
*
* @param $url
* @return mixed
*/
public function loadData($url)
{
$curloptHeader = false;
@Jako
Jako / gist:8ba13f097b36e94fe315f505d3003d8b
Created August 30, 2016 06:48
Formit RedirectByValue Hook
<?php
/**
* RedirectByValue
*
* Copyright 2016 by Thomas Jakobi <[email protected]>
*
* Description:
* This FormIt Hook redirects to different targets on base of the
* formItRedirectByValue property. The property has to contain a json encoded
* object of fieldnames, values, redirects and redirect parameters. Only a