<?php /** @var array $scriptProperties */ if (!$modx->getService('minifyx', 'MinifyX', MODX_CORE_PATH . 'components/minifyx/model/minifyx/')) { return; } /** @var MinifyX $MinifyX */ $MinifyX = new MinifyX($modx, $scriptProperties); if (!$MinifyX->prepareCacheFolder()) { $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);
<?php /** * MinifyX for MODX Evolution * created by Agel_Nash * * @category snippet * @version v 2.0 * @internal @legacy_names MinifyX */ $param = is_array($modx->event->params) ? $modx->event->params : array(); $data = array('js' => false, 'css' => false, 'params' => &$param); $process = $useJS = $useCSS = false; include MODX_BASE_PATH . "assets/snippets/MinifyX/MinifyX.core.php"; $MinifyX = new MinifyX($modx); $param['hashName'] = isset($param['hashName']) ? $param['hashName'] : "MinifyX"; // Список исходных файлов через запятую $param['CSSfile'] = isset($param['CSSfile']) ? $param['CSSfile'] : ''; $param['JSfile'] = isset($param['JSfile']) ? $param['JSfile'] : ''; // ID документов с доп.стилями (максимум по 1 документу для JS и CSS) $param['CSSdoc'] = isset($param['CSSdoc']) ? (int) $param['CSSdoc'] : 0; $param['JSdoc'] = isset($param['JSdoc']) ? (int) $param['JSdoc'] : 0; // Необходимо ли сжатие стилей и скриптов (либо же просто объединить в 1 файл) $param['jsCompress'] = isset($param['jsCompress']) ? (int) $param['jsCompress'] : 1; $param['cssCompress'] = isset($param['cssCompress']) ? (int) $param['cssCompress'] : 1; // Подключить ли результатирующий файл к странице средствами MODX $param['inject'] = isset($param['inject']) ? (int) $param['inject'] : 0; // В какую папку положить результатирующий файл if (empty($param['outFolder'])) { $param['outFolder'] = $MinifyX->outFolder; } else {
$included[$key]['js'][] = $tmp[1]; } } } elseif (strpos($v, '<script') !== false) { $raw[$key]['js'][] = trim(preg_replace('#<!--.*?-->(\\n|)#s', '', $v)); } elseif (strpos($v, '<style') !== false) { $raw[$key]['css'][] = trim(preg_replace('#/\\*.*?\\*/(\\n|)#s', '', $v)); } else { $excluded[$key]['html'][] = $v; } } } // Main options for MinifyX $scriptProperties = array('cacheFolder' => $modx->getOption('minifyx_cacheFolder', null, '/assets/components/minifyx/cache/', true), 'forceUpdate' => $modx->getOption('minifyx_forceUpdate', null, false, true), 'minifyJs' => $modx->getOption('minifyx_minifyJs', null, false, true), 'minifyCss' => $modx->getOption('minifyx_minifyCss', null, false, true), 'jsFilename' => $modx->getOption('minifyx_jsFilename', null, 'all', true), 'cssFilename' => $modx->getOption('minifyx_cssFilename', null, 'all', true)); /** @var MinifyX $MinifyX */ $MinifyX = new MinifyX($modx, $scriptProperties); if (!$MinifyX->prepareCacheFolder()) { $this->modx->log(modX::LOG_LEVEL_ERROR, '[MinifyX] Could not create cache dir "' . $scriptProperties['cacheFolder'] . '"'); return; } $cacheFolderUrl = MODX_BASE_URL . str_replace(MODX_BASE_PATH, '', $MinifyX->config['cacheFolder']); // Process raw scripts and styles $tmp_dir = $MinifyX->getTmpDir() . 'resources/' . $modx->resource->id . '/'; foreach ($raw as $key => $value) { foreach ($value as $type => $rows) { $tmp = ''; if ($type == 'css' && $modx->getOption('minifyx_processRawCss', null, false, true) || $type == 'js' && $modx->getOption('minifyx_processRawJs', null, false, true)) { $text = ''; foreach ($rows as $text) { $text = preg_replace('#^<(script|style).*?>#', '', $text); $text = preg_replace('#</(script|style)>$#', '', $text);
<?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); }