/**
  * Abstract method for routing GET requests without a primary key passed. Must be defined in your derivative
  * controller. Handles fetching of collections of objects.
  *
  * @abstract
  * @return array
  */
 public function getList()
 {
     $this->getProperties();
     $c = $this->modx->newQuery($this->classKey);
     $c = $this->addSearchQuery($c);
     $c = $this->prepareListQueryBeforeCount($c);
     $total = $this->modx->getCount($this->classKey, $c);
     $alias = !empty($this->classAlias) ? $this->classAlias : $this->classKey;
     $c->select($this->modx->getSelectColumns($this->classKey, $alias));
     $c = $this->prepareListQueryAfterCount($c);
     $c->sortby($this->getProperty($this->getOption('propertySort', 'sort'), $this->defaultSortField), $this->getProperty($this->getOption('propertySortDir', 'dir'), $this->defaultSortDirection));
     $limit = $this->getProperty($this->getOption('propertyLimit', 'limit'), $this->defaultLimit);
     if (empty($limit)) {
         $limit = $this->defaultLimit;
     }
     $c->limit($limit, $this->getProperty($this->getOption('propertyOffset', 'start'), $this->defaultOffset));
     $objects = $this->modx->getCollection($this->classKey, $c);
     if (empty($objects)) {
         $objects = array();
     }
     $list = array();
     /** @var xPDOObject $object */
     foreach ($objects as $object) {
         $list[] = $this->prepareListObject($object);
     }
     return $this->collection($list, $total);
 }
Exemplo n.º 2
0
 /**
  * Build the breadcrumb trail for this thread
  *
  * @param array $defaultTrail
  * @param boolean $showTitle
  * @return array
  */
 public function buildBreadcrumbs($defaultTrail = array(), $showTitle = false)
 {
     $c = $this->xpdo->newQuery('disBoard');
     $c->innerJoin('disBoardClosure', 'Ancestors');
     $c->where(array('Ancestors.descendant' => $this->get('board')));
     $c->sortby('Ancestors.depth', 'DESC');
     $ancestors = $this->xpdo->getCollection('disBoard', $c);
     $idx = 0;
     $total = count($ancestors);
     $trail = empty($defaultTrail) ? array(array('url' => $this->xpdo->discuss->request->makeUrl(), 'text' => $this->xpdo->getOption('discuss.forum_title'), 'last' => $total == 0)) : $defaultTrail;
     $category = false;
     /** @var disBoardClosure $ancestor */
     foreach ($ancestors as $ancestor) {
         if (empty($category)) {
             $category = $ancestor->getOne('Category');
             if ($category) {
                 $trail[] = array('url' => $this->xpdo->discuss->request->makeUrl('', array('type' => 'category', 'category' => $category->get('id'))), 'text' => $category->get('name'), 'last' => false);
             }
         }
         $trail[] = array('url' => $this->xpdo->discuss->request->makeUrl('board', array('board' => $ancestor->get('id'))), 'text' => $ancestor->get('name'), 'last' => empty($showTitle) && $idx >= $total - 1 ? true : false);
         $idx++;
     }
     if ($showTitle) {
         $title = str_replace(array('[', ']'), array('[', ']'), $this->get('title'));
         $trail[] = array('text' => $title, 'active' => true, 'last' => true);
     }
     $trail = $this->xpdo->discuss->hooks->load('breadcrumbs', array('items' => &$trail));
     $this->set('trail', $trail);
     return $trail;
 }
Exemplo n.º 3
0
 /**
  * Overrides xPDOObject::save to handle closure table edits.
  *
  * @param boolean $cacheFlag
  * @return boolean
  */
 public function save($cacheFlag = null)
 {
     $new = $this->isNew();
     if ($new) {
         if (!$this->get('createdon')) {
             $this->set('createdon', strftime('%Y-%m-%d %H:%M:%S'));
         }
         $ip = $this->get('ip');
         if (empty($ip) && !empty($_SERVER['REMOTE_ADDR'])) {
             $this->set('ip', $_SERVER['REMOTE_ADDR']);
         }
     }
     $saved = parent::save($cacheFlag);
     if ($saved && $new) {
         $id = $this->get('id');
         $parent = $this->get('parent');
         /* create self closure */
         $cl = $this->xpdo->newObject('quipCommentClosure');
         $cl->set('ancestor', $id);
         $cl->set('descendant', $id);
         if ($cl->save() === false) {
             $this->remove();
             return false;
         }
         /* create closures and calculate rank */
         $c = $this->xpdo->newQuery('quipCommentClosure');
         $c->where(array('descendant' => $parent, 'ancestor:!=' => 0));
         $c->sortby('depth', 'DESC');
         $gparents = $this->xpdo->getCollection('quipCommentClosure', $c);
         $cgps = count($gparents);
         $gps = array();
         $i = $cgps;
         /** @var quipCommentClosure $gparent */
         foreach ($gparents as $gparent) {
             $gps[] = str_pad($gparent->get('ancestor'), 10, '0', STR_PAD_LEFT);
             /** @var quipCommentClosure $obj */
             $obj = $this->xpdo->newObject('quipCommentClosure');
             $obj->set('ancestor', $gparent->get('ancestor'));
             $obj->set('descendant', $id);
             $obj->set('depth', $i);
             $obj->save();
             $i--;
         }
         $gps[] = str_pad($id, 10, '0', STR_PAD_LEFT);
         /* add self closure too */
         /* add root closure */
         /** @var quipCommentClosure $cl */
         $cl = $this->xpdo->newObject('quipCommentClosure');
         $cl->set('ancestor', 0);
         $cl->set('descendant', $id);
         $cl->set('depth', $cgps);
         $cl->save();
         /* set rank */
         $rank = implode('-', $gps);
         $this->set('rank', $rank);
         $this->save();
     }
     return $saved;
 }
 /**
  * Grab settings (from cache if possible) as key => value pairs.
  * @return array|mixed
  */
 public function getSettings()
 {
     /* Attempt to get from cache */
     $cacheOptions = array(xPDO::OPT_CACHE_KEY => 'system_settings');
     $settings = $this->modx->getCacheManager()->get('clientconfig', $cacheOptions);
     if (empty($settings) && $this->modx->getCount('cgSetting') > 0) {
         $collection = $this->modx->getCollection('cgSetting');
         $settings = array();
         /* @var cgSetting $setting */
         foreach ($collection as $setting) {
             $settings[$setting->get('key')] = $setting->get('value');
         }
         /* Write to cache again */
         $this->modx->cacheManager->set('clientconfig', $settings, 0, $cacheOptions);
     }
     return is_array($settings) ? $settings : array();
 }
Exemplo n.º 5
0
 /**
  * Translate the site into Revolution-style tags
  *
  * @param boolean $save Whether or not to actually save the content changed
  * @param null $classes An array of classes and fields to translate
  * @param array $files An array of files to attempt to translate
  * @param boolean|string $toFile If true, will write the file to the specified log
  * @return void
  */
 public function translateSite($save = false, $classes = null, $files = array(), $toFile = false)
 {
     $parser = $this->getParser();
     $parser->tagTranslation = $this->tagTranslation;
     if ($classes === null) {
         $classes = array('modResource' => array('content', 'pagetitle', 'longtitle', 'description', 'menutitle', 'introtext'), 'modTemplate' => array('content'), 'modChunk' => array('snippet'), 'modSnippet' => array('snippet'), 'modPlugin' => array('plugincode'), 'modTemplateVar' => array('default_text'), 'modTemplateVarResource' => array('value'), 'modSystemSetting' => array('value'));
     }
     ob_start();
     echo "Processing classes: " . print_r($classes, true) . "\n\n\n";
     foreach ($classes as $className => $fields) {
         $resources = $this->modx->getCollection($className);
         if ($resources) {
             foreach ($resources as $resource) {
                 foreach ($fields as $field) {
                     $content = $resource->get($field);
                     if ($content) {
                         echo "[BEGIN TRANSLATING FIELD] {$field}\n";
                         $content = str_replace($this->preTranslationSearch, $this->preTranslationReplace, $content);
                         while ($parser->translate($content, array(), true)) {
                             $resource->set($field, $content);
                         }
                         echo "[END TRANSLATING FIELD] {$field}\n\n";
                     }
                 }
                 if ($save) {
                     $resource->save();
                 }
             }
         }
     }
     if (!empty($files)) {
         echo $this->translateFiles($save, $files);
     }
     $log = ob_get_contents();
     ob_end_clean();
     if ($toFile) {
         $cacheManager = $this->modx->getCacheManager();
         $cacheManager->writeFile($toFile, $log);
     } else {
         echo $log;
     }
 }
Exemplo n.º 6
0
 /**
  * Get a map of MediaSource id => baseUrl
  *
  * @return array
  */
 private function loadSourceMap()
 {
     $sources = $this->modx->getCollection('sources.modMediaSource');
     $sourceMap = array();
     foreach ($sources as $source) {
         /** @var modMediaSource $source */
         $source->initialize();
         $sourceMap[$source->get('id')] = new stdClass();
         $sourceMap[$source->get('id')]->url = $source->getBaseUrl();
     }
     return $sourceMap;
 }
Exemplo n.º 7
0
 /**
  * Get a list of all modAction IDs
  * @param string $namespace
  * @return array
  */
 public function getAllActionIDs($namespace = '')
 {
     $c = array();
     if (!empty($namespace)) {
         $c['namespace'] = $namespace;
     }
     $actions = $this->modx->getCollection('modAction', $c);
     $actionList = array();
     /** @var modAction $action */
     foreach ($actions as $action) {
         $key = ($action->get('namespace') == 'core' ? '' : $action->get('namespace') . ':') . $action->get('controller');
         $actionList[$key] = $action->get('id');
     }
     return $actionList;
 }
Exemplo n.º 8
0
    /**
     * Loads a lexicon topic from the cache. If not found, tries to generate a
     * cache file from the database.
     *
     * @access public
     * @param string $namespace The namespace to load from. Defaults to 'core'.
     * @param string $topic The topic to load. Defaults to 'default'.
     * @param string $language The language to load. Defaults to 'en'.
     * @return array The loaded lexicon array.
     */
    public function loadCache($namespace = 'core', $topic = 'default', $language = '') {
        if (empty($language)) $language = $this->modx->getOption('cultureKey',null,'en');
        $key = $this->getCacheKey($namespace, $topic, $language);
        $enableCache = ($namespace != 'core' && !$this->modx->getOption('cache_noncore_lexicon_topics',null,true)) ? false : true;

        $cached = $this->modx->cacheManager->get($key, array(
            xPDO::OPT_CACHE_KEY => $this->modx->getOption('cache_lexicon_topics_key', null, 'lexicon_topics'),
            xPDO::OPT_CACHE_HANDLER => $this->modx->getOption('cache_lexicon_topics_handler', null, $this->modx->getOption(xPDO::OPT_CACHE_HANDLER)),
            xPDO::OPT_CACHE_FORMAT => (integer) $this->modx->getOption('cache_lexicon_topics_format', null, $this->modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP)),
        ));
        if (!$enableCache || $cached == null) {
            $results= false;

            /* load file-based lexicon */
            $results = $this->getFileTopic($language,$namespace,$topic);
            if ($results === false) { /* default back to en */
                $results = $this->getFileTopic('en',$namespace,$topic);
                if ($results === false) {
                    $results = array();
                }
            }

            /* get DB overrides */
            $c= $this->modx->newQuery('modLexiconEntry');
            $c->innerJoin('modNamespace','Namespace');
            $c->where(array(
                'modLexiconEntry.topic' => $topic,
                'modLexiconEntry.language' => $language,
                'Namespace.name' => $namespace,
            ));
            $c->sortby($this->modx->getSelectColumns('modLexiconEntry','modLexiconEntry','',array('name')),'ASC');
            $entries= $this->modx->getCollection('modLexiconEntry',$c);
            if (!empty($entries)) {
                foreach ($entries as $entry) {
                    $results[$entry->get('name')]= $entry->get('value');
                }
            }
            if ($enableCache) {
                $cached = $this->modx->cacheManager->generateLexiconTopic($key,$results);
            } else {
                $cached = $results;
            }
        }
        if (empty($cached)) {
            $this->modx->log(xPDO::LOG_LEVEL_DEBUG, "An error occurred while trying to cache {$key} (lexicon/language/namespace/topic)");
        }
        return $cached;
    }
Exemplo n.º 9
0
function duplicateLevel(modX &$modx, $oldKey, $newKey, $parent = 0, $newParent = 0)
{
    $resources = $modx->getCollection('modResource', array('context_key' => $oldKey, 'parent' => $parent));
    if (count($resources) <= 0) {
        return array();
    }
    foreach ($resources as $oldResource) {
        $oldResourceArray = $oldResource->toArray();
        $newResource = $modx->newObject('modResource');
        $newResource->fromArray($oldResourceArray);
        $newResource->set('parent', $newParent);
        $newResource->set('context_key', $newKey);
        $newResource->save();
        duplicateLevel($modx, $oldKey, $newKey, $oldResourceArray['id'], $newResource->get('id'));
    }
}
Exemplo n.º 10
0
 /**
  * Check to see if the
  * @param modUser|null $user
  * @param string $context
  * @return bool
  */
 public function checkResourceGroupAccess($user = null, $context = '')
 {
     $context = !empty($context) ? $context : '';
     $c = $this->xpdo->newQuery('modResourceGroup');
     $c->innerJoin('modTemplateVarResourceGroup', 'TemplateVarResourceGroups', array('TemplateVarResourceGroups.documentgroup = modResourceGroup.id', 'TemplateVarResourceGroups.tmplvarid' => $this->get('id')));
     $resourceGroups = $this->xpdo->getCollection('modResourceGroup', $c);
     $hasAccess = true;
     if (!empty($resourceGroups)) {
         $hasAccess = false;
         /** @var modResourceGroup $resourceGroup */
         foreach ($resourceGroups as $resourceGroup) {
             if ($resourceGroup->hasAccess($user, $context)) {
                 $hasAccess = true;
                 break;
             }
         }
     }
     return $hasAccess;
 }
 public static function listPackageVersions(modX &$modx, $criteria, $limit = 0, $offset = 0) {
     $result = array('collection' => array(), 'total' => 0);
     $c = $modx->newQuery('transport.modTransportPackage');
     $c->select($modx->getSelectColumns('transport.modTransportPackage','modTransportPackage'));
     $c->select(array('Provider.name AS provider_name'));
     $c->leftJoin('transport.modTransportProvider','Provider');
     $c->where($criteria);
     $result['total'] = $modx->getCount('modTransportPackage',$c);
     $c->sortby('modTransportPackage.version_major', 'DESC');
     $c->sortby('modTransportPackage.version_minor', 'DESC');
     $c->sortby('modTransportPackage.version_patch', 'DESC');
     $c->sortby('IF(modTransportPackage.release = "" OR modTransportPackage.release = "ga" OR modTransportPackage.release = "pl","z",modTransportPackage.release) DESC','');
     $c->sortby('modTransportPackage.release_index', 'DESC');
     if((int)$limit > 0) {
         $c->limit((int)$limit, (int)$offset);
     }
     $result['collection'] = $modx->getCollection('transport.modTransportPackage',$c);
     return $result;
 }
Exemplo n.º 12
0
 /**
  * Truncates a thread.
  * @return boolean
  */
 public function truncate()
 {
     if (!$this->checkPolicy('truncate')) {
         return false;
     }
     $c = $this->xpdo->newQuery('quipComment');
     $c->where(array('thread' => $this->get('name')));
     $comments = $this->xpdo->getCollection('quipComment', $c);
     $truncated = true;
     /** @var quipComment $comment */
     foreach ($comments as $comment) {
         $comment->set('deleted', true);
         $comment->set('deletedon', strftime('%Y-%m-%d %H:%M:%S'));
         if ($this->xpdo instanceof modX) {
             $comment->set('deletedby', $this->xpdo->user->get('id'));
         }
         $truncated = $comment->save();
     }
     return $truncated;
 }
Exemplo n.º 13
0
 /**
  * Get all group settings for the user in array format.
  *
  * Preference is set by group rank + member rank, with primary_group having
  * highest priority.
  *
  * @return array An associative array of group settings.
  */
 public function getUserGroupSettings()
 {
     $settings = array();
     $primary = array();
     $query = $this->xpdo->newQuery('modUserGroupSetting');
     $query->innerJoin('modUserGroup', 'UserGroup', array('UserGroup.id = modUserGroupSetting.group'));
     $query->innerJoin('modUserGroupMember', 'Member', array('Member.member' => $this->get('id'), 'UserGroup.id = Member.user_group'));
     $query->sortby('UserGroup.rank', 'DESC');
     $query->sortby('Member.rank', 'DESC');
     $ugss = $this->xpdo->getCollection('modUserGroupSetting', $query);
     /** @var modUserGroupSetting $ugs */
     foreach ($ugss as $ugs) {
         if ($ugs->get('group') === $this->get('primary_group')) {
             $primary[$ugs->get('key')] = $ugs->get('value');
         } else {
             $settings[$ugs->get('key')] = $ugs->get('value');
         }
     }
     return array_merge($settings, $primary);
 }
Exemplo n.º 14
0
 /**
  * Load all config files and prepare the values.
  *
  * @access public
  * @return void
  */
 public function initialize()
 {
     $configs = $this->modx->getCollection('CustomrequestConfigs');
     // TODO: Caching of the calculated values.
     // import config files
     foreach ($configs as $config) {
         // fill urlParams if defined
         $urlParams = ($tmp = json_decode($config->get('urlparams'))) ? $tmp : array();
         $regEx = $config->get('regex');
         if ($alias = $config->get('alias')) {
             // if alias is defined, calculate the other values
             if ($config->get('resourceid')) {
                 $resourceId = $config->get('resourceid');
             } elseif ($res = $this->modx->getObject('modResource', array('uri' => $config->get('alias')))) {
                 $resourceId = $res->get('id');
             } else {
                 // if resourceId could not be calculated or is not set, don't use that setting
                 if ($this->getOption('debug')) {
                     $this->modx->log(modX::LOG_LEVEL_INFO, 'CustomRequest Plugin: Could not calculate the resourceId for the given alias "' . $alias . '"');
                 }
                 break;
             }
         } elseif ($resourceId = $config->get('resourceid')) {
             // else if resourceId is defined, calculate the other values
             if ($config->get('alias')) {
                 $alias = $config->get('alias');
             } elseif ($resourceId && ($alias = $this->modx->makeUrl($resourceId))) {
                 // cutoff trailing .html or /
                 $alias = trim(str_replace('.html', '', $alias), '/');
             } else {
                 // if alias could not be calculated, don't use that setting
                 if ($this->getOption('debug')) {
                     $this->modx->log(modX::LOG_LEVEL_INFO, 'CustomRequest Plugin: Could not calculate the alias for the given resourceId "' . $resourceId . '"');
                 }
                 break;
             }
         }
         $this->requests[$alias] = array('resourceId' => $resourceId, 'alias' => $alias, 'urlParams' => $urlParams, 'regEx' => $regEx);
     }
     return;
 }
Exemplo n.º 15
0
 public function __construct(modX &$modx, array $config = array())
 {
     $this->modx =& $modx;
     if (!($corePath = $this->modx->getOption('modhybridauth.core_path', $config))) {
         $corePath = $this->modx->getOption('core_path') . 'components/modhybridauth/';
     }
     if (!($assetsPath = $this->modx->getOption('modhybridauth.assets_path', $config))) {
         $assetsPath = $this->modx->getOption('assets_path') . 'components/modhybridauth/';
     }
     if (!($assetsUrl = $this->modx->getOption('modhybridauth.assets_url', $config))) {
         $assetsUrl = $this->modx->getOption('assets_url') . 'components/modhybridauth/';
     }
     // Удаляем слеш в начале УРЛа, так как Яша не понимает двойной слош в УРЛе (не протоколе)
     $assetsUrl = preg_replace('/^\\/+/', '', $assetsUrl);
     $connectorUrl = $assetsUrl . 'connector.php';
     $this->config = array_merge(array('assetsUrl' => $assetsUrl, 'cssUrl' => $assetsUrl . 'css/', 'jsUrl' => $assetsUrl . 'js/', 'imagesUrl' => $assetsUrl . 'images/', 'connectorUrl' => $connectorUrl, 'corePath' => $corePath, 'modelPath' => $corePath . 'model/', 'chunksPath' => $corePath . 'elements/chunks/', 'snippetsPath' => $corePath . 'elements/snippets/', 'processorsPath' => $corePath . 'processors/'), $config);
     /*$this->modx->setLogLevel(xPDO::LOG_LEVEL_INFO);
       $this->modx->setLogTarget('HTML');
       */
     $providers = array();
     $key = "hybridauth_providers";
     if (!($providersCache = $modx->cacheManager->get($key))) {
         if ($providersCollection = $modx->getCollection('modHybridAuthProvider')) {
             foreach ($providersCollection as $provider) {
                 $data = $provider->toArray();
                 $providers[$data['name']] = $data;
             }
             $modx->cacheManager->set($key, $providers);
         }
     } else {
         $providers = $providersCache;
     }
     if (!($base_url = $modx->getOption('modhybridauth.base_url'))) {
         $base_url = $modx->getOption('site_url') . $assetsUrl . 'connectors/profile/auth.php';
         # exit;
     }
     $this->providers_config = array("base_url" => $base_url, "providers" => $providers);
     $this->modx->loadClass('Hybrid_Auth', null, false, true);
 }
Exemplo n.º 16
0
 /**
  * Get a list of all modAction IDs
  *
  * @deprecated Has no meaning in 2.3; will be removed in 2.4/3.0
  *
  * @param string $namespace
  * @return array
  */
 public function getAllActionIDs($namespace = '')
 {
     $c = array();
     if (!empty($namespace)) {
         $c['namespace'] = $namespace;
     }
     $actions = $this->modx->getCollection('modAction', $c);
     $actionList = array();
     /** @var modAction $action */
     foreach ($actions as $action) {
         $key = ($action->get('namespace') == 'core' ? '' : $action->get('namespace') . ':') . $action->get('controller');
         $actionList[$key] = $action->get('id');
     }
     // Also add old core actions for backwards compatibility
     $oldActions = array('browser', 'context', 'context/create', 'context/update', 'context/view', 'element', 'element/chunk', 'element/chunk/create', 'element/chunk/update', 'element/plugin', 'element/plugin/create', 'element/plugin/update:', 'element/propertyset/index', 'element/snippet', 'element/snippet/create', 'element/snippet/update', 'element/template', 'element/template/create', 'element/template/tvsort', 'element/template/update', 'element/tv', 'element/tv/create', 'element/tv/update', 'element/view', 'help', 'resource', 'resource/create', 'resource/data', 'resource/empty_recycle_bin', 'resource/site_schedule', 'resource/tvs', 'resource/update', 'search', 'security', 'security/access/policy/template/update', 'security/access/policy/update', 'security/forms', 'security/forms/profile/update', 'security/forms/set/update', 'security/login', 'security/message', 'security/permission', 'security/profile', 'security/resourcegroup/index', 'security/role', 'security/user', 'security/user/create', 'security/user/update', 'security/usergroup/create', 'security/usergroup/update', 'source/create', 'source/index', 'source/update', 'system', 'system/action', 'system/contenttype', 'system/dashboards', 'system/dashboards/create', 'system/dashboards/update', 'system/dashboards/widget/create', 'system/dashboards/widget/update', 'system/event', 'system/file', 'system/file/create', 'system/file/edit', 'system/import', 'system/import/html', 'system/info', 'system/logs/index', 'system/phpinfo', 'system/refresh_site', 'system/settings', 'welcome', 'workspaces', 'workspaces/lexicon', 'workspaces/namespace', 'workspaces/package/view');
     if (empty($namespace) || $namespace == 'core') {
         foreach ($oldActions as $a) {
             $actionList[$a] = $a;
         }
     }
     return $actionList;
 }
Exemplo n.º 17
0
$modx->initialize('mgr');
$modx->setLogLevel(modX::LOG_LEVEL_INFO);
$modx->setLogTarget('ECHO');
/* load Discuss */
$discuss = $modx->getService('discuss', 'Discuss', $modx->getOption('discuss.core_path', null, $modx->getOption('core_path') . 'components/discuss/') . 'model/discuss/');
if (!$discuss instanceof Discuss) {
    return '';
}
/* setup mem limits */
ini_set('memory_limit', '1024M');
set_time_limit(0);
@ob_end_clean();
echo '<pre>';
/* fix num_topics */
$c = $modx->newQuery('disThreadRead');
$c->leftJoin('disThread', 'Thread');
$c->where(array('Thread.board != disThreadRead.board'));
$reads = $modx->getCollection('disThreadRead', $c);
foreach ($reads as $read) {
    $modx->log(modX::LOG_LEVEL_INFO, 'Removing orphaned disThreadRead ID: ' . $read->get('id'));
    $read->remove();
}
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$tend = $mtime;
$totalTime = $tend - $tstart;
$totalTime = sprintf("%2.4f s", $totalTime);
$modx->log(modX::LOG_LEVEL_INFO, "\nExecution time: {$totalTime}\n");
@session_write_close();
die;
Exemplo n.º 18
0
 public static function getList(modX &$modx, array $scriptProperties = array())
 {
     $sort = $modx->getOption('sort', $scriptProperties, 'rank');
     $cacheKey = 'gallery/item/list/' . md5(serialize($scriptProperties));
     if ($modx->getCacheManager() && ($cache = $modx->cacheManager->get($cacheKey))) {
         $items = array();
         foreach ($cache['items'] as $data) {
             /** @var galItem $item */
             $item = $modx->newObject('galItem');
             $item->fromArray($data, '', true, true);
             $items[] = $item;
         }
         if (in_array(strtolower($sort), array('random', 'rand()', 'rand'))) {
             shuffle($items);
         }
         $data = array('items' => $items, 'total' => $cache['total'], 'album' => $cache['album']);
     } else {
         $album = $modx->getOption('album', $scriptProperties, false);
         $tag = $modx->getOption('tag', $scriptProperties, '');
         $limit = $modx->getOption('limit', $scriptProperties, 0);
         $start = $modx->getOption('start', $scriptProperties, 0);
         /* Fix to make it work with getPage which uses "offset" instead of "start" */
         $offset = $modx->getOption('offset', $scriptProperties, 0);
         if ($offset > 0) {
             $start = $offset;
         }
         $sortAlias = $modx->getOption('sortAlias', $scriptProperties, 'galItem');
         if ($sort == 'rank') {
             $sortAlias = 'AlbumItems';
         }
         $dir = $modx->getOption('dir', $scriptProperties, 'ASC');
         $showInactive = $modx->getOption('showInactive', $scriptProperties, false);
         $activeAlbum = array('id' => '', 'name' => '', 'description' => '');
         $tagc = $modx->newQuery('galTag');
         $tagc->setClassAlias('TagsJoin');
         $tagc->select('GROUP_CONCAT(' . $modx->getSelectColumns('galTag', 'TagsJoin', '', array('tag')) . ')');
         $tagc->where($modx->getSelectColumns('galTag', 'TagsJoin', '', array('item')) . ' = ' . $modx->getSelectColumns('galItem', 'galItem', '', array('id')));
         $tagc->prepare();
         $tagSql = $tagc->toSql();
         $c = $modx->newQuery('galItem');
         $c->innerJoin('galAlbumItem', 'AlbumItems');
         $c->innerJoin('galAlbum', 'Album', $modx->getSelectColumns('galAlbumItem', 'AlbumItems', '', array('album')) . ' = ' . $modx->getSelectColumns('galAlbum', 'Album', '', array('id')));
         /* pull by album */
         if (!empty($album)) {
             $albumField = is_numeric($album) ? 'id' : 'name';
             $albumWhere = $albumField == 'name' ? array('name' => $album) : $album;
             /** @var galAlbum $album */
             $album = $modx->getObject('galAlbum', $albumWhere);
             if (empty($album)) {
                 return '';
             }
             $c->where(array('Album.' . $albumField => $album->get($albumField)));
             $activeAlbum['id'] = $album->get('id');
             $activeAlbum['name'] = $album->get('name');
             $activeAlbum['description'] = $album->get('description');
             $activeAlbum['year'] = $album->get('year');
             unset($albumWhere, $albumField);
         }
         if (!empty($tag)) {
             /* pull by tag */
             $c->innerJoin('galTag', 'Tags');
             $c->where(array('Tags.tag' => $tag));
             if (empty($album)) {
                 $activeAlbum['id'] = 0;
                 $activeAlbum['name'] = $tag;
                 $activeAlbum['description'] = '';
             }
         }
         $c->where(array('galItem.mediatype' => $modx->getOption('mediatype', $scriptProperties, 'image')));
         if (!$showInactive) {
             $c->where(array('galItem.active' => true));
         }
         $count = $modx->getCount('galItem', $c);
         $c->select($modx->getSelectColumns('galItem', 'galItem'));
         $c->select(array('(' . $tagSql . ') AS tags'));
         if (in_array(strtolower($sort), array('random', 'rand()', 'rand'))) {
             $c->sortby('RAND()', $dir);
         } else {
             $c->sortby($sortAlias . '.' . $sort, $dir);
         }
         if (!empty($limit)) {
             $c->limit($limit, $start);
         }
         $items = $modx->getCollection('galItem', $c);
         $data = array('items' => $items, 'total' => $count, 'album' => $activeAlbum);
         $cache = array('items' => array(), 'total' => $count, 'album' => $activeAlbum);
         /** @var galItem $item */
         foreach ($items as $item) {
             $cache['items'][] = $item->toArray('', true);
         }
         $modx->cacheManager->set($cacheKey, $cache);
     }
     return $data;
 }
Exemplo n.º 19
0
 /**
  * Create a PDF with the options set in the class
  *
  * @param modResource $resource
  * @param string|boolean $aliasPath
  * @return string
  */
 public function createPDF($resource, $aliasPath)
 {
     // Create folders
     if (!@is_dir($this->getOption('pdfPath'))) {
         if (!@mkdir($this->getOption('pdfPath'), $this->modx->getOption('new_folder_permissions', null, 0775))) {
             $this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not create the pdf output path: ' . $this->getOption('pdfPath'), '', 'PDFResource');
             return '';
         }
     }
     if ($aliasPath && !@is_dir($this->getOption('pdfPath') . $aliasPath)) {
         if (!@mkdir($this->getOption('pdfPath') . $aliasPath, $this->modx->getOption('new_folder_permissions', null, 0775))) {
             $this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not create the pdf alias path: ' . $this->getOption('pdfPath') . $aliasPath, '', 'PDFResource');
             return '';
         }
     }
     // Get options
     $id = $resource->get('id');
     $pdfTpl = $this->getOption('pdfTpl', null, 'tplPDF');
     $cssTpl = $this->getOption('cssTpl', null, 'tplCSS');
     $optionsTV = $this->getOption('pdfTvOptions', null, 'pdf_options');
     $processTVs = $this->getOption('processTVs', null, false);
     $tvPrefix = $this->getOption('tvPrefix', null, 'tv.');
     $placeholder = $resource->toArray();
     // Prepare template variables and resource based options
     $pdfOptions = null;
     $tvs = $this->modx->getCollection('modTemplateVar');
     foreach ($tvs as $tv) {
         /** @var modTemplateVar $tv */
         $placeholder[$tvPrefix . $tv->get('name')] = $processTVs ? $tv->renderOutput($id) : $tv->getValue($id);
         if ($tv->get('name') == $optionsTV && $tv->getValue($id) != '') {
             $pdfOptions = json_decode($tv->getValue($id), true);
             if ($pdfOptions) {
                 $pdfTpl = $this->modx->getOption('pdfTpl', $pdfOptions, $pdfTpl);
                 $cssTpl = $this->modx->getOption('cssTpl', $pdfOptions, $cssTpl);
             }
         }
     }
     // Parse template chunks
     $placeholder['tplPath'] = $this->modx->getOption('assets_path');
     $html = $this->getChunk($pdfTpl, $placeholder);
     $this->modx->getParser()->processElementTags('', $html, false, false, '[[', ']]', array(), $this->modx->getOption('max_iterations'));
     $this->modx->getParser()->processElementTags('', $html, true, true, '[[', ']]', array(), $this->modx->getOption('max_iterations'));
     $css = $this->getChunk($cssTpl, $placeholder);
     unset($placeholder);
     // Generate PDF file
     $this->initPDF(array('mode' => $this->getOption('mode', $pdfOptions, 'utf-8'), 'format' => $this->getOption('format', $pdfOptions, 'A4'), 'defaultFontSize' => intval($this->getOption('defaultFontSize', $pdfOptions, 8)), 'defaultFont' => $this->getOption('defaultFont', $pdfOptions, ''), 'mgl' => intval($this->getOption('mgl', $pdfOptions, 10)), 'mgr' => intval($this->getOption('mgr', $pdfOptions, 10)), 'mgt' => intval($this->getOption('mgt', $pdfOptions, 7)), 'mgb' => intval($this->getOption('mgb', $pdfOptions, 7)), 'mgh' => intval($this->getOption('mgh', $pdfOptions, 10)), 'mgf' => intval($this->getOption('mgf', $pdfOptions, 10)), 'orientation' => $this->getOption('orientation', $pdfOptions, 'P'), 'customFonts' => $this->getOption('customFonts', $pdfOptions, '[]')));
     $this->pdf->SetTitle($resource->get('pagetitle'));
     $this->pdf->SetAuthor($this->getOption('author', $pdfOptions, $this->modx->getOption('site_name')));
     $this->pdf->SetCreator($this->getOption('creator', $pdfOptions, $this->modx->getOption('site_url') . ' powered by PDFResource/mPDF'));
     // Password protection
     $userPassword = $this->getOption('userPassword', $pdfOptions, '');
     $ownerPassword = $this->getOption('ownerPassword', $pdfOptions, '');
     $permissions = json_decode($this->getOption('permissions', $pdfOptions, ''), true);
     if ($userPassword || $ownerPassword) {
         // Set default permissions if needed
         $permissions = $permissions ? $permissions : array();
         // Random owner password if needed
         $ownerPassword = $ownerPassword ? $ownerPassword : null;
         $this->pdf->SetProtection($permissions, $userPassword, $ownerPassword, 128);
     }
     // Call additional mPDF methods
     $mpdfMethods = json_decode($this->getOption('mPDFMethods', $pdfOptions, ''), true);
     $mpdfMethods = is_array($mpdfMethods) ? $mpdfMethods : array();
     foreach ($mpdfMethods as $methodName) {
         $value = $this->getOption($methodName, $pdfOptions, '');
         $value = is_array($value) ? $value : json_decode($value, true);
         if ($value && method_exists($this->pdf, $methodName)) {
             call_user_func_array(array($this->pdf, $methodName), $value);
         }
     }
     $this->pdf->WriteHTML($css, 1);
     $this->pdf->WriteHTML($html, 2);
     if ($aliasPath) {
         return $this->pdf->Output($this->getOption('pdfPath') . $aliasPath . $resource->get('alias') . '.pdf', 'F');
     } else {
         return $this->pdf->Output('', 'S');
     }
 }
Exemplo n.º 20
0
 /**
  * Run the Google SiteMap XML generation, recursively
  *
  * @param int $currentParent The current parent resource the iteration
  * is on
  * @param int $selfId If specified, will exclude this ID
  * @param int $depth
  * @return string The generated XML
  */
 public function run($currentParent, $selfId = -1, $depth = 0)
 {
     if (!empty($this->config['maxDepth']) && $depth >= $this->config['maxDepth']) {
         return '';
     }
     $output = '';
     /* get children */
     $c = $this->getQuery($currentParent);
     $children = $this->modx->getCollection('modResource', $c);
     /** @var modResource $child */
     foreach ($children as $child) {
         $id = $child->get('id');
         if ($selfId == $id) {
             continue;
         }
         $canParse = true;
         if ($this->config['searchable']) {
             $canParse = $canParse && $child->get('searchable');
         }
         if ($this->config['published']) {
             $canParse = $canParse && $child->get('published');
         }
         if ($this->config['hideDeleted']) {
             $canParse = $canParse && !$child->get('deleted');
         }
         if (empty($this->config['showHidden'])) {
             $canParse = $canParse && (!$child->get('hidemenu') || $child->get('class_key') == 'Article');
         }
         if ($canParse) {
             $url = $this->modx->makeUrl($id, '', '', 'full');
             $date = $child->get('editedon') ? $child->get('editedon') : $child->get('createdon');
             $date = date("Y-m-d", strtotime($date));
             /* Get the date difference */
             $datediff = datediff("d", $date, date("Y-m-d"));
             if ($datediff <= 1) {
                 $priority = '1.0';
                 $update = 'daily';
             } elseif ($datediff > 1 && $datediff <= 7) {
                 $priority = '0.75';
                 $update = 'weekly';
             } elseif ($datediff > 7 && $datediff <= 30) {
                 $priority = '0.50';
                 $update = 'weekly';
             } else {
                 $priority = '0.25';
                 $update = 'monthly';
             }
             if (!empty($this->config['priorityTV'])) {
                 $priorityTV = $child->getTVValue($this->config['priorityTV']);
                 if (!empty($priorityTV)) {
                     $priority = $priorityTV;
                 }
             }
             /* add item to output */
             $output .= $this->getChunk($this->config['itemTpl'], array('url' => $url, 'date' => $date, 'update' => $update, 'priority' => $priority)) . $this->config['itemSeparator'];
         }
         /* if children, recurse */
         if ($child->get('children') > 0) {
             $output .= $this->run($child->get('id'), $selfId, $depth + 1);
         }
     }
     return $output;
 }
Exemplo n.º 21
0
$mtime = explode(' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$tstart = $mtime;
set_time_limit(0);
/* override with your own defines here (see build.config.sample.php) */
require_once dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/config.core.php';
require_once MODX_CORE_PATH . 'config/' . MODX_CONFIG_KEY . '.inc.php';
require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
$modx = new modX();
$modx->initialize('mgr');
$modx->setLogLevel(modX::LOG_LEVEL_INFO);
$modx->setLogTarget('ECHO');
$discuss = $modx->getService('discuss', 'Discuss', $modx->getOption('discuss.core_path', null, $modx->getOption('core_path') . 'components/discuss/') . 'model/discuss/');
$c = $modx->newQuery('disBoard');
$c->select(array('disBoard.id', "map" => "GROUP_CONCAT(Descendants.ancestor ORDER BY Descendants.ancestor DESC SEPARATOR '.')"));
$c->innerJoin('disBoardClosure', 'Descendants', 'Descendants.descendant = disBoard.id');
$c->where(array('Descendants.ancestor != disBoard.id'));
$c->groupby('disBoard.id');
$results = $modx->getCollection('disBoard', $c);
foreach ($results as $res) {
    $modx->updateCollection('disBoard', array('map' => $res->map), array('id' => $res->id));
    $maps[$res->id] = array_merge(array($res->id), explode(".", $res->map));
}
foreach ($maps as $map) {
    for ($i = 1; $i < count($map); $i++) {
        if (count($map) == 0) {
            continue;
        }
        $modx->updateCollection('disBoardClosure', array('depth' => $i), array('ancestor' => $map[$i], 'descendant' => $map[0]));
    }
}
Exemplo n.º 22
0
 /**
  * Merge another user into this account
  *
  * @param disUser $oldUser
  * @return boolean
  */
 public function merge(disUser &$oldUser)
 {
     $success = true;
     $user = $this->getOne('User');
     if (empty($user)) {
         return false;
     }
     $oldModxUser = $oldUser->getOne('User');
     if (empty($oldModxUser)) {
         return false;
     }
     $this->xpdo->beginTransaction();
     /* merge post count */
     $posts = $user->get('posts');
     $posts = $posts + $oldUser->get('posts');
     $this->set('posts', $posts);
     /* merge ignore boards */
     $ibs = $this->get('ignore_boards');
     $ibs = explode(',', $ibs);
     $oldIbs = $oldUser->get('ignore_boards');
     $oldIbs = explode(',', $oldIbs);
     $ibs = array_merge($oldIbs, $ibs);
     $this->set('ignore_boards', implode(',', $ibs));
     /* merge signature if needed */
     $signature = $this->get('signature');
     $oldSignature = $oldUser->get('signature');
     if (empty($signature) && !empty($oldSignature)) {
         $this->set('signature', $oldSignature);
     }
     /* merge title if needed */
     $title = $this->get('title');
     $oldTitle = $oldUser->get('title');
     if (empty($title) && !empty($oldTitle)) {
         $this->set('title', $oldTitle);
     }
     /* merge primary_group if needed */
     $pg = $this->get('primary_group');
     $oldPg = $oldUser->get('primary_group');
     if (empty($pg) && !empty($oldPg)) {
         $this->set('primary_group', $oldPg);
     }
     $this->set('integrated_id', $oldUser->get('integrated_id'));
     $this->set('synced', true);
     $this->set('syncedat', $this->xpdo->discuss->now());
     $this->save();
     /* grant old usergroups to this user */
     $oldUserGroups = $this->xpdo->getCollection('modUserGroupMember', array('member' => $oldModxUser->get('id')));
     $ugs = array();
     foreach ($oldUserGroups as $oldUserGroup) {
         $ugs[] = $oldUserGroup->get('user_group');
     }
     $ugs = array_unique($ugs);
     foreach ($ugs as $ug) {
         $user->joinGroup($ug);
     }
     /* merge in posts, change authors */
     $sql = 'UPDATE ' . $this->xpdo->getTableName('disPost') . '
         SET `author` = ' . $this->get('id') . '
         WHERE `author` = ' . $oldUser->get('id') . '
     ';
     $this->xpdo->query($sql);
     $sql = 'UPDATE ' . $this->xpdo->getTableName('disThread') . '
         SET `author_first` = ' . $this->get('id') . '
         WHERE `author_first` = ' . $oldUser->get('id') . '
     ';
     $this->xpdo->query($sql);
     $sql = 'UPDATE ' . $this->xpdo->getTableName('disThread') . '
         SET `author_last` = ' . $this->get('id') . '
         WHERE `author_last` = ' . $oldUser->get('id') . '
     ';
     $this->xpdo->query($sql);
     /* merge in disThreadRead */
     $sql = 'UPDATE ' . $this->xpdo->getTableName('disThreadRead') . '
         SET `user` = ' . $this->get('id') . '
         WHERE `user` = ' . $oldUser->get('id') . '
     ';
     $this->xpdo->query($sql);
     /* merge in disThreadUser */
     $sql = 'UPDATE ' . $this->xpdo->getTableName('disThreadUser') . '
         SET `user` = ' . $this->get('id') . '
         WHERE `user` = ' . $oldUser->get('id') . '
     ';
     $this->xpdo->query($sql);
     /* merge in disUserFriend */
     $sql = 'UPDATE ' . $this->xpdo->getTableName('disUserFriend') . '
         SET `user` = ' . $this->get('id') . '
         WHERE `user` = ' . $oldUser->get('id') . '
     ';
     $this->xpdo->query($sql);
     $sql = 'UPDATE ' . $this->xpdo->getTableName('disUserFriend') . '
         SET `friend` = ' . $this->get('id') . '
         WHERE `friend` = ' . $oldUser->get('id') . '
     ';
     $this->xpdo->query($sql);
     /* merge in disUserNotification */
     $sql = 'UPDATE ' . $this->xpdo->getTableName('disUserNotification') . '
         SET `user` = ' . $this->get('id') . '
         WHERE `user` = ' . $oldUser->get('id') . '
     ';
     $this->xpdo->query($sql);
     /* merge in disModerator */
     $sql = 'UPDATE ' . $this->xpdo->getTableName('disModerator') . '
         SET `user` = ' . $this->get('id') . '
         WHERE `user` = ' . $oldUser->get('id') . '
     ';
     $this->xpdo->query($sql);
     /* remove old user sessions */
     $sql = 'DELETE FROM ' . $this->xpdo->getTableName('disUserFriend') . '
         WHERE `user` = ' . $oldUser->get('id') . '
     ';
     $this->xpdo->query($sql);
     /* merge all PMs users fields for user */
     $c = $this->xpdo->newQuery('disThread');
     $c->innerJoin('disThreadUser', 'Users');
     $c->leftJoin('disThreadRead', 'Reads', 'Reads.user = '******'id') . ' AND disThread.id = Reads.thread');
     $c->where(array('disThread.private' => true, 'Users.user' => $oldUser->get('id')));
     $pms = $this->xpdo->getCollection('disThread', $c);
     foreach ($pms as $pm) {
         $users = $pm->get('users');
         $users = explode(',', $users);
         $users = array_diff($users, array($oldUser->get('id')));
         $users[] = $this->get('id');
         $pm->set('users', implode(',', $users));
         $pm->save();
     }
     /* remove old users */
     $oldUser->remove();
     $oldModxUser->remove();
     /* check for post group advance */
     $this->checkForPostGroupAdvance();
     $this->xpdo->commit();
     return $success;
 }
Exemplo n.º 23
0
 public static function getList(modX &$modx, array $scriptProperties = array())
 {
     $cacheKey = 'gallery/album/list/' . md5(serialize($scriptProperties));
     if ($modx->getCacheManager() && ($cache = $modx->cacheManager->get($cacheKey))) {
         $albums = array();
         foreach ($cache as $data) {
             /** @var galAlbum $album */
             $album = $modx->newObject('galAlbum');
             $album->fromArray($data, '', true, true);
             $albums[] = $album;
         }
     } else {
         $sort = $modx->getOption('sort', $scriptProperties, 'rank');
         $dir = $modx->getOption('dir', $scriptProperties, 'DESC');
         $limit = $modx->getOption('limit', $scriptProperties, 10);
         $start = $modx->getOption('start', $scriptProperties, 0);
         $parent = $modx->getOption('parent', $scriptProperties, 0);
         $showAll = $modx->getOption('showAll', $scriptProperties, false);
         $id = $modx->getOption('id', $scriptProperties, false);
         $showInactive = $modx->getOption('showInactive', $scriptProperties, false);
         $prominentOnly = $modx->getOption('prominentOnly', $scriptProperties, true);
         /* implement tree-style albums*/
         if ($modx->getOption('checkForRequestAlbumVar', $scriptProperties, false)) {
             $albumRequestVar = $modx->getOption('albumRequestVar', $scriptProperties, 'galAlbum');
             if (!empty($_REQUEST[$albumRequestVar])) {
                 $parent = $_REQUEST[$albumRequestVar];
             }
         }
         /* add random sorting for albums */
         if (in_array(strtolower($sort), array('random', 'rand()', 'rand'))) {
             $sort = 'RAND()';
             $dir = '';
         }
         $c = $modx->newQuery('galAlbum');
         if (!$showInactive) {
             $c->where(array('active' => true));
         }
         if ($prominentOnly) {
             $c->where(array('prominent' => true));
         }
         if ($showAll == false) {
             $c->where(array('parent' => $parent));
         }
         $c->sortby($sort, $dir);
         if ($limit > 0) {
             $c->limit($limit, $start);
         }
         if (!empty($id)) {
             $c->where(array('id' => $id));
         }
         $albums = $modx->getCollection('galAlbum', $c);
         if ($sort !== 'RAND()') {
             $cache = array();
             foreach ($albums as $album) {
                 $cache[] = $album->toArray('', true);
             }
             $modx->cacheManager->set($cacheKey, $cache);
         }
     }
     return $albums;
 }
Exemplo n.º 24
0
/*
	2. Files 
*/
$vehicle->resolve('file', array('source' => $sources['source_core'], 'target' => "return MODX_CORE_PATH . 'components/';"));
$vehicle->resolve('file', array('source' => $sources['source_assets'], 'target' => "return MODX_ASSETS_PATH . 'components/';"));
$vehicle->resolve('php', array('source' => $sources['resolvers'] . 'setupoptions.resolver.php'));
// install the tables:
$vehicle->resolve('php', array('source' => $sources['resolvers'] . 'tables.resolver.php'));
$builder->putVehicle($vehicle);
/*
	3. Data - table rows
*/
// This will add the package to xPDO, and allow you to use all of xPDO's functions with your model.
$modx->addPackage('churchevents', $sources['model']);
// Get the Calendar Options:
$cals = $modx->getCollection('chCalendar');
$attributes = array(xPDOTransport::UNIQUE_KEY => 'id', xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => false);
foreach ($cals as $chCalendar) {
    $vehicle = $builder->createVehicle($chCalendar, $attributes);
    $builder->putVehicle($vehicle);
}
// Get the Category Options:
$cats = $modx->getCollection('chECategory');
foreach ($cats as $chECategory) {
    $vehicle = $builder->createVehicle($chECategory, $attributes);
    $builder->putVehicle($vehicle);
}
/* load lexicon strings */
$builder->buildLexicon($sources['lexicon']);
/* now pack in the license file, readme and setup options */
$builder->setPackageAttributes(array('license' => file_get_contents($sources['docs'] . 'license.txt'), 'readme' => file_get_contents($sources['docs'] . 'readme.txt'), 'setup-options' => array('source' => $sources['build'] . 'setup.options.php')));
Exemplo n.º 25
0
}
if (!defined('MODX_CONFIG_KEY')) {
    define('MODX_CONFIG_KEY', 'config');
}
require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
$modx = new modX();
$modx->initialize('mgr');
$cacheManager = $modx->getCacheManager();
$modx->setLogLevel(xPDO::LOG_LEVEL_ERROR);
$modx->setLogTarget('ECHO');
// Get all Actions
$content = "<?php\n";
$query = $modx->newQuery('modAction');
$query->where(array('namespace' => 'core'));
$query->sortby('id');
$collection = $modx->getCollection('modAction', $query);
foreach ($collection as $key => $c) {
    $content .= $cacheManager->generateObject($c, "collection['{$key}']", false, false, 'xpdo');
}
$cacheManager->writeFile(dirname(__FILE__) . '/data/transport.core.actions.php', $content);
unset($content, $collection, $key, $c);
// Get all Menus
$content = "<?php\n";
$query = $modx->newQuery('modMenu');
$query->sortby('id');
$collection = $modx->getCollection('modMenu', $query);
foreach ($collection as $key => $c) {
    $content .= $cacheManager->generateObject($c, "collection['{$key}']", false, false, 'xpdo');
}
$cacheManager->writeFile(dirname(__FILE__) . '/data/transport.core.menus.php', $content);
unset($content, $collection, $key, $c);
Exemplo n.º 26
0
// setting up modx access
require_once '/PATH_TO_MODX/config.core.php';
require_once '/PATH_TO_MODX_CORE/model/modx/modx.class.php';
$modx = new modX();
$modx->initialize('web');
$modx->getService('error', 'error.modError');
// define locations  UPDATE BEFORE USING!
// base file path to where static files will be saved
$basepath = '/FULL_SERVER_PATH/public_html/';
// url to your modx install
$mdxurl = 'http://URL-TO-MODX-INSTALL/';
// - - - - - - - - - end configuration - - - - - - - - -
// getting the published ids
// get collection of resources, determine id and if published
$docs = $modx->getCollection('modResource');
foreach ($docs as $doc) {
    $pub = $doc->get('published');
    $folder = $doc->get('isfolder');
    $rid = $doc->get('id');
    $web_url = $doc->get('uri');
    // if published, fetch url and build static webpage
    if ($pub == '1' && $folder == '0') {
        // determine if folders exist and create if not
        $path_parts = pathinfo($basepath . $web_url);
        $target_path = $path_parts['dirname'];
        if (!file_exists($target_path)) {
            mkdir($target_path, 0755, true);
        }
        // get the webpage from MODX
        $contents = file_get_contents($mdxurl . 'index.php?id=' . $rid);
Exemplo n.º 27
0
/**
 * Paths for types of elements
 *
 * @var array $elements [type_name => path_to_files]
 */
$types = ['snippets' => ['modSnippet', '.php', 'name', "<?php\n"], 'templates' => ['modTemplate', '.html', 'templatename', ''], 'chunks' => ['modChunk', '.html', 'name', ''], 'plugins' => ['modPlugin', '.php', 'name', "<?php\n"]];
foreach (array_keys($types) as $type) {
    $elements[$type] = $type . '/';
    $cat_paths[$type][0] = $elements[$type];
}
/**
 * Paths for categories
 *
 * @var array $cat_paths [type][category_id => relative_path_to_category]
 */
$cc = $modx->getCollection('modCategory');
$cat_list = [];
foreach ($elements as $key => $value) {
    foreach ($cc as $c) {
        $croot = $value . pathTo($c, $cc);
        $cat_paths[$key][$c->id] = $croot . '/';
        $cat_list[$c->id] = $c->category;
    }
}
// if (count($cat_list)) $cat_list = array_flip($cat_list);
/**
 * Save content of non-static elements into files
 */
foreach ($types as $key => $value) {
    $et = $modx->getCollection($value[0]);
    foreach ($et as &$element) {
Exemplo n.º 28
-1
 /**
  * Migrate ignore boards into Users
  * 
  * @return void
  */
 public function migrateIgnoreBoards()
 {
     $this->log('Migrating Ignore Boards...');
     $this->log('Collecting User cache...');
     $c = $this->modx->newQuery('disUser');
     $c->sortby('username', 'ASC');
     $c->where(array('ignore_boards:!=' => ''));
     $users = $this->modx->getCollection('disUser', $c);
     /** @var disUser $user */
     foreach ($users as $user) {
         $boards = explode(',', $user->get('ignore_boards'));
         if (!empty($boards)) {
             $this->log('Migrating ' . count($boards) . ' boards for ' . $user->get('username'));
             $newBoards = array();
             foreach ($boards as $board) {
                 /** @var disBoard $b */
                 $b = $this->modx->getObject('disBoard', array('integrated_id' => $board));
                 if ($b) {
                     $newBoards[] = $b->get('id');
                 }
             }
             if (!empty($newBoards)) {
                 $user->set('ignore_boards', implode(',', $newBoards));
                 if ($this->config['live']) {
                     $user->save();
                 }
             }
         }
     }
 }