Please login!` - inline snippets * 2. &ifIds=`1,3` - additional check for users ids. yesChunk will * only be shown to logged-in users in the list. * * ADDED in 3.6.0 by Vasia123: * * 1. &allowedGroups=`Editor,Administrator` - check if user is * in any allowed group * * * Placeholder [[+name]] will show the user's name in the yesChunk or * elsewhere on the page. * * *:::::::::::::::::::::::::::::::::::::::: */ /* @var $modx modX */ /* @var $profile modUserProfile */ /* Prepare params and variables */ $output = ''; $sp =& $scriptProperties; $yesChunk = $modx->getOption('yesChunk',$sp, null); $noChunk = $modx->getOption('noChunk',$scriptProperties, null); $fullName = (bool) $modx->getOption('fullName', $sp, false); $firstName = (bool) $modx->getOption('firstName', $sp, false); $ph = $modx->getOption('ph',$sp, null); $ifIds = $modx->getOption('ifIds',$sp, null); $allowedGroups = $modx->getOption('allowedGroups',$sp, null); $context = $modx->getOption('context', $sp, $modx->context->get('key') ); if( $fullName || $firstName ) { $profile = $modx->user->getOne('Profile'); } /* check if user logged in */ $is_logged_in = $modx->user->hasSessionContext($context); /* Set $ifIds to true if user id is allowed or ifIds is not set */ $ifIds = array_filter(array_map('trim',explode(',',$ifIds))); $ifIds = (!empty($ifIds)) ? in_array($modx->user->get('id'), $ifIds) : true; // Set $groups to true is use in in allowed group or $groups is not set $groups = array_filter(array_map('trim',explode(',',$allowedGroups))); if (!empty($groups)) { $inGroups = false; foreach($groups as $group) { if ($modx->user->isMember($group)) $inGroups = true; } } else { $inGroups = true; } /* Do the work */ if ($is_logged_in && $ifIds && $inGroups) { if (preg_match('/^@CODE:/',$yesChunk)) { $output = substr($yesChunk, 6); } else { $output = $modx->getChunk($yesChunk, $scriptProperties); } if (! empty($ph)) { if ($fullName && $profile) { $name = trim($profile->get('fullname')); } elseif ($firstName && $profile) { $full = trim($profile->get('fullname')); $pos = strpos($full, ' '); $name = ($pos === false) ? $full : substr($full, 0, $pos); } else { $name = $modx->user->get('username'); } if (empty($name)) { $name = $modx->user->get('username'); } $modx->setPlaceholder($ph, $name); } } elseif( !empty ($noChunk) ) { if (preg_match('/^@CODE:/',$noChunk)) { $output = substr($noChunk, 6); } else { $output = $modx->getChunk($noChunk); } } return empty($output)? '': $output;