/** * Create conversations map * * @return array|false False if cache is off */ public function conversationsMap() { /** * If disabled caching return False */ if (!$this->modx->getCacheManager()) { return false; } /** * If a map is present in the cache, then just return it */ $map = $this->modx->cacheManager->get('conversations_map', array(xPDO::OPT_CACHE_KEY => 'modxtalks')); if ($map) { return $map; } /** * If the map is not in the cache, we all topics from the database and build the map */ $map = array(); $c = $this->modx->newQuery('modxTalksConversation'); $c->select(array('id', 'rid', 'conversation')); if ($c->prepare() && $c->stmt->execute()) { $conversations = $c->stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($conversations as $c) { $map[$c['rid']][$c['id']] = $c['conversation']; } $this->modx->cacheManager->set('conversations_map', $map, 0, array(xPDO::OPT_CACHE_KEY => 'modxtalks')); } return $map; }
/** * Sets the cache path for this Smarty instance * * @access public * @param string $path The path to set. Defaults to '', which in turn * defaults to $this->modx->cachePath. */ public function setCachePath($path = '') { $path = $this->modx->getOption(xPDO::OPT_CACHE_PATH) . $path; if (!is_dir($path)) { $this->modx->getCacheManager(); $this->modx->cacheManager->writeTree($path); } $this->compile_dir = $path; }
/** * Translate specific files * * @param boolean $save If true, will save the translation * @param array $files An array of files to translate * @return string */ public function translateFiles($save = false, $files = array()) { $output = ''; if (is_array($files) && !empty($files)) { $parser = $this->getParser(); $parser->tagTranslation = $this->tagTranslation; $cacheManager = $this->modx->getCacheManager(); $output .= "Processing files: " . print_r($files, true) . "\n\n\n"; ob_start(); foreach ($files as $file) { if (file_exists($file)) { echo "[BEGIN TRANSLATING FILE] {$file}\n"; $content = file_get_contents($file); if ($content !== false) { $content = str_replace($this->preTranslationSearch, $this->preTranslationReplace, $content); while ($parser->translate($content, array(), true)) { } if ($save) { $cacheManager->writeFile($file, $content); } } echo "[END TRANSLATING FILE] {$file}\n"; } } $output .= ob_get_contents(); ob_end_clean(); } return $output; }
/** * Move a thread to a new board * * @param int $boardId * @return boolean True if successful */ public function move($boardId) { $oldBoard = $this->getOne('Board'); $newBoard = is_object($boardId) && $boardId instanceof disBoard ? $boardId : $this->xpdo->getObject('disBoard', $boardId); if (!$oldBoard || !$newBoard) { return false; } $this->addOne($newBoard); if ($this->save()) { /* readjust all posts */ $posts = $this->getMany('Posts'); foreach ($posts as $post) { $post->set('board', $newBoard->get('id')); $post->save(); } /* adjust old board topics/reply counts */ $oldBoard->set('num_topics', $oldBoard->get('num_topics') - 1); $replies = $oldBoard->get('num_replies') - $this->get('replies'); $oldBoard->set('num_replies', $replies); $total_posts = $oldBoard->get('total_posts') - $this->get('replies') - 1; $oldBoard->set('total_posts', $total_posts); /* recalculate latest post */ $oldBoardLastPost = $this->xpdo->getObject('disPost', array('id' => $oldBoard->get('last_post'))); if ($oldBoardLastPost && $oldBoardLastPost->get('id') == $this->get('post_last')) { $newLastPost = $oldBoard->get2ndLatestPost(); if ($newLastPost) { $oldBoard->set('last_post', $newLastPost->get('id')); $oldBoard->addOne($newLastPost, 'LastPost'); } } $oldBoard->save(); /* adjust new board topics/reply counts */ $newBoard->set('num_topics', $oldBoard->get('num_topics') - 1); $replies = $newBoard->get('num_replies') + $this->get('replies'); $newBoard->set('num_replies', $replies); $total_posts = $newBoard->get('total_posts') + $this->get('replies') + 1; $newBoard->set('total_posts', $total_posts); /* recalculate latest post */ $newBoardLastPost = $this->xpdo->getObject('disPost', array('id' => $newBoard->get('last_post'))); $thisThreadPost = $this->getOne('LastPost'); if ($newBoardLastPost && $thisThreadPost && $newBoardLastPost->get('createdon') < $thisThreadPost->get('createdon')) { $newBoard->set('last_post', $thisThreadPost->get('id')); $newBoard->addOne($thisThreadPost, 'LastPost'); } $newBoard->save(); /* Update ThreadRead board field */ $this->xpdo->exec('UPDATE ' . $this->xpdo->getTableName('disThreadRead') . ' SET ' . $this->xpdo->escape('board') . ' = ' . $newBoard->get('id') . ' WHERE ' . $this->xpdo->escape('thread') . ' = ' . $this->get('id') . ' '); /* clear caches */ if (!defined('DISCUSS_IMPORT_MODE')) { $this->xpdo->getCacheManager(); $this->xpdo->cacheManager->delete('discuss/thread/' . $this->get('id')); $this->xpdo->cacheManager->delete('discuss/board/' . $newBoard->get('id')); $this->xpdo->cacheManager->delete('discuss/board/' . $oldBoard->get('id')); } } return true; }
/** * Push a source to a specified target location. * * @param string $source A valid file or stream location source. * @param string $target A valid file or stream location target. * * @return bool Returns true if the source was pushed successfully to the target, false otherwise. */ public function push($source, $target) { $pushed = false; if ($this->modx->getCacheManager()) { $pushed = $this->modx->cacheManager->copyFile($source, $target, array('copy_preserve_permissions' => true)); } return $pushed; }
/** * 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(); }
/** * Sets data to cache * * @param mixed $data * @param mixed $options * * @return string $cacheKey */ public function setCache($data = array(), $options = array()) { $cacheKey = $this->getCacheKey($options); $cacheOptions = $this->getCacheOptions($options); if (!empty($cacheKey) && !empty($cacheOptions) && $this->modx->getCacheManager()) { $this->modx->cacheManager->set($cacheKey, $data, $cacheOptions[xPDO::OPT_CACHE_EXPIRES], $cacheOptions); $this->addTime('Saved data to cache "' . $cacheOptions[xPDO::OPT_CACHE_KEY] . '/' . $cacheKey . '"'); } return $cacheKey; }
/** * @param array $options * * @return bool */ public function clearCache($options = array()) { $cacheKey = $this->getCacheKey($options); $cacheOptions = $this->getCacheOptions($options); if (!empty($cacheKey)) { $cacheOptions['cache_key'] .= $cacheKey; } if (!empty($cacheOptions) and $this->modx->getCacheManager()) { return $this->modx->cacheManager->clean($cacheOptions); } return false; }
public static function loadCache(modX $modx) { if (!$modx->getCacheManager()) { return array(); } $cacheKey = 'namespaces'; $cache = $modx->cacheManager->get($cacheKey, array(xPDO::OPT_CACHE_KEY => $modx->getOption('cache_namespaces_key', null, 'namespaces'), xPDO::OPT_CACHE_HANDLER => $modx->getOption('cache_namespaces_handler', null, $modx->getOption(xPDO::OPT_CACHE_HANDLER)), xPDO::OPT_CACHE_FORMAT => (int) $modx->getOption('cache_namespaces_format', null, $modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP)))); if (empty($cache)) { $cache = $modx->cacheManager->generateNamespacesCache($cacheKey); } return $cache; }
/** * @param mixed $payload * @param array $options */ public function send($payload, $options = array(), $metadata = array()) { // return the original data $return = $payload; // set to project specified in MODX system settings if (!isset($options['project'])) { $options['project'] = $this->project; } // if empty metadata, do a backtrace if (empty($metadata)) { $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); $backtrace = array_shift($backtrace); $metadata['file'] = $backtrace['file']; $metadata['line'] = $backtrace['line']; } // fix array keys to match phpconsole api if (isset($metadata['file'])) { $metadata['fileName'] = $metadata['file']; unset($metadata['file']); } if (isset($metadata['line'])) { $metadata['lineNumber'] = $metadata['line']; unset($metadata['line']); } // if $payload is a xPDO Object, convert it to an array if ($payload instanceof xPDOObject) { $payload = $payload->toArray(); } // make sure phpconsole was initialized if (!$this->phpconsole) { // save to normal error log file if phpconsole is not available if ($this->modx->getCacheManager()) { $filepath = $this->modx->getCachePath() . xPDOCacheManager::LOG_DIR . 'error.log'; $this->modx->cacheManager->writeFile($filepath, var_export($payload, true) . "\n", 'a'); } } else { // call send method of phpconsole try { $this->phpconsole->send($payload, $options, $metadata); } catch (Exception $e) { if ($this->modx->getCacheManager()) { $filepath = $this->modx->getCachePath() . xPDOCacheManager::LOG_DIR . 'error.log'; $this->modx->cacheManager->writeFile($filepath, '[Phpconsole] Exception ' . $e->getCode() . ': ' . $e->getMessage() . "\n", 'a'); } } } return $return; }
/** * 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; if (!$this->modx->cacheManager) { $this->modx->getCacheManager(); } $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 => (int) $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)) { /** @var modLexiconEntry $entry */ 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; }
// include 'mycomponentproject.class.php'; require_once $modx->getOption('mc.core_path', null, $modx->getOption('core_path') . 'components/mycomponent/') . 'model/mycomponent/mycomponentproject.class.php'; $props = isset($scriptProperties) ? $scriptProperties : array(); $project = new MyComponentProject($modx); $project->init($props); //$project->removeObjects(); $dryRun = false; /* true is the default -- set to false for actual import */ /* Comma-separated list of elements to process (snippets,plugins,chunks,templates) */ $toProcess = 'snippets,plugins,chunks,templates'; /* path to elements directory to import -- if empty, project's elements dir will be used */ /*$directory = $modx->getOption('mc.core', null, $modx->getOption('core_path') . 'components/example/') . 'elements/';*/ $directory = ''; $project->importObjects($toProcess, $directory, $dryRun); $cm = $modx->getCacheManager(); $cm->refresh(); // echo print_r(ObjectAdapter::$myObjects, true); $output = $project->helpers->getOutput(); $output .= "\n\n" . $modx->lexicon('mc_initial_memory_used') . ': ' . round($mem_usage / 1048576, 2) . ' ' . $modx->lexicon('mc_megabytes'); $mem_usage = memory_get_usage(); $peak_usage = memory_get_peak_usage(true); $output .= "\n" . $modx->lexicon('mc_final_memory_used') . ': ' . round($mem_usage / 1048576, 2) . ' ' . $modx->lexicon('mc_megabytes'); $output .= "\n" . $modx->lexicon('mc_peak_memory_used') . ': ' . round($peak_usage / 1048576, 2) . ' ' . $modx->lexicon('mc_megabytes'); /* report how long it took */ $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $tend = $mtime; $totalTime = $tend - $tstart; $totalTime = sprintf("%2.4f s", $totalTime);
/** * Transfers the package from one directory to another. * * @access public * @param string $sourceFile The file to transfer. * @param string $targetDir The directory to transfer into. * @return boolean True if successful. */ public function transferPackage($sourceFile, $targetDir) { $transferred = false; $content = ''; if (is_dir($targetDir) && is_writable($targetDir)) { if (!is_array($this->xpdo->version)) { $this->xpdo->getVersionData(); } $productVersion = $this->xpdo->version['code_name'] . '-' . $this->xpdo->version['full_version']; $source = $this->get('service_url') . $sourceFile . (strpos($sourceFile, '?') !== false ? '&' : '?') . 'revolution_version=' . $productVersion; /* see if user has allow_url_fopen on and is not behind a proxy */ $proxyHost = $this->xpdo->getOption('proxy_host', null, ''); if (ini_get('allow_url_fopen') && empty($proxyHost)) { if ($handle = @fopen($source, 'rb')) { $filesize = @filesize($source); $memory_limit = @ini_get('memory_limit'); if (!$memory_limit) { $memory_limit = '8M'; } $byte_limit = $this->_bytes($memory_limit) * 0.5; if (strpos($source, '://') !== false || $filesize > $byte_limit) { $content = @file_get_contents($source); } else { $content = @fread($handle, $filesize); } @fclose($handle); } else { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $this->xpdo->lexicon('package_err_file_read', array('source' => $source))); } /* if not, try curl */ } else { if (function_exists('curl_init')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $source); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 180); $safeMode = @ini_get('safe_mode'); $openBasedir = @ini_get('open_basedir'); if (empty($safeMode) && empty($openBasedir)) { curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); } $proxyHost = $this->xpdo->getOption('proxy_host', null, ''); if (!empty($proxyHost)) { $proxyPort = $this->xpdo->getOption('proxy_port', null, ''); curl_setopt($ch, CURLOPT_PROXY, $proxyHost); curl_setopt($ch, CURLOPT_PROXYPORT, $proxyPort); $proxyUsername = $this->xpdo->getOption('proxy_username', null, ''); if (!empty($proxyUsername)) { $proxyAuth = $this->xpdo->getOption('proxy_auth_type', null, 'BASIC'); $proxyAuth = $proxyAuth == 'NTLM' ? CURLAUTH_NTLM : CURLAUTH_BASIC; curl_setopt($ch, CURLOPT_PROXYAUTH, $proxyAuth); $proxyPassword = $this->xpdo->getOption('proxy_password', null, ''); $up = $proxyUsername . (!empty($proxyPassword) ? ':' . $proxyPassword : ''); curl_setopt($ch, CURLOPT_PROXYUSERPWD, $up); } } $content = curl_exec($ch); curl_close($ch); /* and as last-ditch resort, try fsockopen */ } else { $content = $this->_getByFsockopen($source); } } if ($content) { if ($cacheManager = $this->xpdo->getCacheManager()) { $filename = $this->signature . '.transport.zip'; $target = $targetDir . $filename; $transferred = $cacheManager->writeFile($target, $content); } } else { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'MODX could not download the file. You must enable allow_url_fopen, cURL or fsockopen to use remote transport packaging.'); } } else { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $this->xpdo->lexicon('package_err_target_write', array('targetDir' => $targetDir))); } return $transferred; }
/** * @param modX $modx */ function __construct(modX $modx) { $this->modx =& $modx; $this->cacheManager = $modx->getCacheManager(); }
/** * Clear the cache for this User * * @return void */ public function clearCache() { if (!defined('DISCUSS_IMPORT_MODE')) { $this->xpdo->getCacheManager(); $this->xpdo->cacheManager->delete('discuss/user/' . $this->get('id')); $this->xpdo->cacheManager->delete('discuss/board/user/' . $this->get('id')); } }
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; }
/** * Clear the caches of all sources * @param array $options * @return void */ public function clearCache(array $options = array()) { /** @var modCacheManager $cacheManager */ $cacheManager = $this->xpdo->getCacheManager(); if (empty($cacheManager)) { return; } $c = $this->xpdo->newQuery('modContext'); $c->select($this->xpdo->escape('key')); $options[xPDO::OPT_CACHE_KEY] = $this->getOption('cache_media_sources_key', $options, 'media_sources'); $options[xPDO::OPT_CACHE_HANDLER] = $this->getOption('cache_media_sources_handler', $options, $this->getOption(xPDO::OPT_CACHE_HANDLER, $options)); $options[xPDO::OPT_CACHE_FORMAT] = (int) $this->getOption('cache_media_sources_format', $options, $this->getOption(xPDO::OPT_CACHE_FORMAT, $options, xPDOCacheManager::CACHE_PHP)); $options[xPDO::OPT_CACHE_ATTEMPTS] = (int) $this->getOption('cache_media_sources_attempts', $options, $this->getOption(xPDO::OPT_CACHE_ATTEMPTS, $options, 10)); $options[xPDO::OPT_CACHE_ATTEMPT_DELAY] = (int) $this->getOption('cache_media_sources_attempt_delay', $options, $this->getOption(xPDO::OPT_CACHE_ATTEMPT_DELAY, $options, 1000)); if ($c->prepare() && $c->stmt->execute()) { while ($row = $c->stmt->fetch(PDO::FETCH_ASSOC)) { if ($row && !empty($row['key'])) { $cacheManager->delete($row['key'] . '/source', $options); } } } }
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; }
$mtime = $mtime[1] + $mtime[0]; $tstart = $mtime; // get rid of time limit set_time_limit(0); // override with your own defines here (see build.config.sample.php) @(require_once dirname(__FILE__) . '/build.config.php'); if (!defined('MODX_CORE_PATH')) { define('MODX_CORE_PATH', dirname(dirname(__FILE__)) . '/core/'); } 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";