<?php
$tstart = microtime(true);
set_time_limit(0);
require 'config.core.php';
require MODX_CORE_PATH . 'model/modx/modx.class.php';
$modx = modX::getInstance();
$modx->initialize('mgr');
$modx->setLogLevel(modX::LOG_LEVEL_INFO);
$modx->setLogTarget('ECHO');
$modx->log(modX::LOG_LEVEL_INFO, "Regenerating MODX Cache");
try {
$iterator = $modx->getIterator('modContext', array('key:!=' => 'mgr'));
foreach ($iterator as $context) {
if ($modx->switchContext($context->get('key'))) {
$modx->setLogLevel(modX::LOG_LEVEL_INFO);
$modx->setLogTarget('ECHO');
$modx->log(modX::LOG_LEVEL_INFO, "Processing Resources in Context {$context->get('key')}");
$map = array_reverse($modx->context->aliasMap, true);
$modx->log(modX::LOG_LEVEL_INFO, "Processing aliasMap: " . print_r($map, true));
foreach ($map as $uri => $id) {
$resource = $modx->getObject('modResource', $id);
$pubon = $resource->get('publishedon');
$now = time();
$day = 60 * 60 * 24;
if($now - $pubon > $day * 60) { // its older than 60 days
// leave every other group
$rgrs = $modx->getCollection('modResourceGroupResource', array('document'=>$id));
$groups = array();
foreach($rgrs as $rgr) {
$gid = $rgr->get('document_group');
$resource->leaveGroup($gid);
}
// join the appropriate group
$query = $modx->newQuery('modResourceGroup');
$query->where(array('name' => '60DaysGroup'));
$group = $modx->getObject('modResourceGroup',$query);
$joinGroup = $group->get('id');
$resource->joinGroup($joinGroup);
}
}
} else {
$modx->log(modX::LOG_LEVEL_ERROR, "AutoGroup: Could not switchContext({$context->get('key')})");
}
}
} catch (Exception $e) {
$tend = microtime(true);
$totalTime= sprintf("%2.4f seconds", ($tend - $tstart));
$modx->log(modX::LOG_LEVEL_ERROR, "AutoGroup failed in {$totalTime}: {$e->getMessage()}");
}
$tend = microtime(true);
$totalTime= sprintf("%2.4f seconds", ($tend - $tstart));
$modx->log(modX::LOG_LEVEL_INFO, "AutoGroup executed in {$totalTime}");[[!AgeCheck]]
<?php
/* AgeCheck snippet */
$currentUser = $modx->user;
/* make sure user is logged in */
if ($currentUser->hasSessionContext('web')) {
/* get current timestamp */
$now = time();
/* get the page's birth date as a timestamp
(we could use 'publishedon' or 'editedon' here) */
$pageBirthday = strtotime($modx->resource->get('createdon'));
/* Get page age in days */
/* rounds up to nearest day */
$pageAge = ceil(($now - $pageBirthday) / 86400);
/* rounds down to nearest day */
// $pageAge = floor(($now - $pageBirthday) / 86400);
/* Check the user's User Group */
if ($currentUser->isMember('Zero')){
return '';
}
if ($currentUser->isMember('Sixty') && ($pageAge >= 60)) {
return '';
}
if ($currentUser->isMember('Ninety') && ($pageAge >= 90)) {
return '';
}
}
/* User fails all tests, cannot see the current page */
return 'Sorry, you are not authorized to see this page';
// or
$url = 'http://full/url/of/sorry/upgrade-your-subscription/page';
$modx->sendRedirect($url);// add created Resource Group access to created User Group for vendor context
$response = $modx->runProcessor('security/access/usergroup/resourcegroup/create',array(
'action' => 'create',
'target' => $resourceGroup->get('id'),
'context_key' => $context,
'authority' => '6999',
'principal' => $userGroup->get('id'),
'policy' => '4'
));
if ($response->isError()) {
echo $response->getMessage();
}&where=`{"publishedon:<=":"[[!getGroupEndDate]]"}`$groupdays = array(
'group_0'=>'0',
'group_30'=>'30',
'group_60'=>'60',
'group_90'=>'90',
);
foreach ($groupdays as $group=>$days){
if ($modx->user->isMember($group)){
return strftime('%Y-%m-%d %H:%M:%S',time() - ($days * 24 * 60 * 60));
}
}
return strftime('%Y-%m-%d %H:%M:%S',time() - (120 * 24 * 60 * 60));//If user isn't in any of this groups
echo date(strtotime("-60 days"));