$modx->log(modX::LOG_LEVEL_ERROR, '[MinifyX] Could not create cache dir "' . $MinifyX->config['cacheFolder'] . '"'); return; } $cacheFolderUrl = MODX_BASE_URL . str_replace(MODX_BASE_PATH, '', $MinifyX->config['cacheFolder']); $array = array('js' => trim($modx->getOption('jsSources', $scriptProperties, '', true)), 'css' => trim($modx->getOption('cssSources', $scriptProperties, '', true))); foreach ($array as $type => $value) { if (empty($value)) { continue; } $filename = $MinifyX->config[$type . 'Filename'] . '_'; $extension = $MinifyX->config[$type . 'Ext']; $register = $MinifyX->config['register' . ucfirst($type)]; $placeholder = !empty($MinifyX->config[$type . 'Placeholder']) ? $MinifyX->config[$type . 'Placeholder'] : ''; $files = $MinifyX->prepareFiles($value); $properties = array('minify' => $MinifyX->config['minify' . ucfirst($type)] ? 'true' : 'false'); $result = $MinifyX->Munee($files, $properties); $file = $MinifyX->saveFile($result, $filename, $extension); // Register file on frontend if (!empty($file) && file_exists($MinifyX->config['cacheFolder'] . $file)) { if ($register == 'placeholder' && $placeholder) { $tag = $type == 'css' ? '<link rel="stylesheet" href="' . $cacheFolderUrl . $file . '" type="text/css" />' : '<script type="text/javascript" src="' . $cacheFolderUrl . $file . '"></script>'; $modx->setPlaceholder($placeholder, $tag); } else { if ($type == 'css') { $modx->regClientCSS($cacheFolderUrl . $file); } else { if ($register == 'startup') { $modx->regClientStartupScript($cacheFolderUrl . $file); } else { $modx->regClientScript($cacheFolderUrl . $file); }
<?php require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/config.core.php'; require_once MODX_CORE_PATH . 'config/' . MODX_CONFIG_KEY . '.inc.php'; if (!defined('MODX_API_MODE')) { define('MODX_API_MODE', true); } require_once MODX_BASE_PATH . 'index.php'; if (!$modx->getService('minifyx', 'MinifyX', MODX_CORE_PATH . 'components/minifyx/model/minifyx/')) { return false; } $MinifyX = new MinifyX($modx, array()); if (!empty($_GET['files'])) { $files = $MinifyX->prepareFiles($_GET['files']); $options = array('image' => array('checkReferrer' => $modx->getOption('munee_checkReferrer', null, 'true', true), 'allowedFiltersTimeLimit' => $modx->getOption('munee_allowedFiltersTimeLimit', null, -1, true), 'numberOfAllowedFilters' => $modx->getOption('munee_numberOfAllowedFilters', null, 100, true), 'imageProcessor' => $modx->getOption('munee_imageProcessor', null, 'GD', true), 'placeholders' => $modx->fromJSON($modx->getOption('munee_placeholders', null, '{"*":"http://placehold.it/500x500/&text=MinifyX"}', true))), 'setHeaders' => true, 'maxAge' => 0); echo $MinifyX->Munee($files, $options); }