Skip to content

Instantly share code, notes, and snippets.

@rtripault
rtripault / plugin.php
Created June 23, 2017 08:58
Sample plugin to display the welcome screen to any new member login for the first time in MODX Revolution manager
<?php
/**
* A sample plugin to display the "welcome message" to all users, login for the first time in Revo manager
*
* @var modX $modx
* @var array $scriptProperties
* @var modPlugin $this
*
* @see modPlugin::process()
*
@rtripault
rtripault / plugin.php
Created January 26, 2017 12:13
Plugin to add a "created by" field on a MODX Revolution resource form, listening on the "OnDocFormPrerender" event
<?php
/**
* Sample plugin to add a "created by" field on a resource form
*
* @var modX $modx
* @var array $scriptProperties
*
* @event OnDocFormPrerender
*/

Keybase proof

I hereby claim:

  • I am rtripault on github.
  • I am rtripault (https://keybase.io/rtripault) on keybase.
  • I have a public key ASBH7E3QHCx946gTCPZ1GWj-kkpBY5J_wHFciF6l0Yjgowo

To claim this, I am signing this object:

<?php
/**
* Babel
*
* @package babel
*/
/**
*
* Events:
* OnDocFormPrerender,OnDocFormSave,OnEmptyTrash,OnContextRemove,OnResourceDuplicate
@rtripault
rtripault / formit.hook.php
Created May 4, 2011 20:56
FormIt hook for Doodles extra (MODX Revolution)
<?php
$doodle = $modx->getService('doodles','Doodles',$modx->getOption('doodles.core_path',null,$modx->getOption('core_path').'components/doodles/').'model/doodles/');
if (!($doodle instanceof Doodles)) {
$hook->addError('error_message','Unable to load doodle service.');
return false;
};
$newEntry = $modx->newObject('Doodle');
$newEntry->fromArray($scriptProperties['fields']);
@rtripault
rtripault / index.php
Created April 16, 2011 17:42
Initialize contexts based on http hosts (MODX Revolution) - source: http://modxcms.com/forums/index.php/topic,63406.msg359673.html#msg359673
switch(strtolower(MODX_HTTP_HOST)) {
case 'dns.tld1:80':
case 'dns.tld1':
$modx->initialize('ctx1');
break;
case 'dns.tld2:443':
case 'dns.tld2:80':
case 'dns.tld2':
$modx->initialize('ctx2');
@rtripault
rtripault / redirectUserGroups.php
Created March 27, 2011 15:41
Redirect users according to their group (MODX Revolution). Source : http://modxcms.com/forums/index.php/topic,59821.0.html
<?php
if (isset($redirs)){
$redirs=explode(',',$redirs);
if (count($redirs)>0){
foreach ($redirs as $redir){
$redir=explode(':',$redir);
if (count($redir)==2){
@rtripault
rtripault / Get_Analytics.snippet.php
Created February 25, 2011 07:33
Load analytics tracking code (if user is logged in or not) for MODx Revolution (source: http://modxcms.com/forums/index.php/topic,61561.0.html)
<?php
// Gets the analytics if the person is not logged in
// Must call un-cached.
// [[!Get_Analytics]]
$return = '';
$viewer_logged_in = false;
$viewer = $modx->user;
<?php
// First fetch all the children of the current resource
$children = $modx->resource->getMany('Children');
// Check if there are any. If not, return false
if (!$children) { return false; }
// Check if there is a tpl set, if not return an error
$tpl = $modx->getOption('tpl',$scriptProperties,'');
if (!$tpl) { return 'No template given.'; }
// Start the output
<?php
/* UserGroups snippet*/
$user =& $modx->user;
if ($user->isMember('membres') {
$output = $modx->getChunk('membres');
} elseif ($user->isMember('administrateurs') {
$output = $modx->getChunk('administrateurs');
} elseif ($user->isMember('employés') {
$output = $modx->getChunk('employés');