View source
<?php
define('ADVAGG_CSS_COMPRESSOR', 2);
define('ADVAGG_CSS_COMPRESS_INLINE', 0);
define('ADVAGG_CSS_COMPRESS_INLINE_IF_NOT_CACHEABLE', FALSE);
define('ADVAGG_CSS_COMPRESSOR_FILE_SETTINGS', -10);
function advagg_css_compress_menu() {
$file_path = drupal_get_path('module', 'advagg_css_compress');
$config_path = advagg_admin_config_root_path();
$items[$config_path . '/advagg/css-compress'] = array(
'title' => 'CSS Compression',
'description' => 'Adjust CSS Compression settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'advagg_css_compress_admin_settings_form',
),
'type' => MENU_LOCAL_TASK,
'access arguments' => array(
'administer site configuration',
),
'file path' => $file_path,
'file' => 'advagg_css_compress.admin.inc',
'weight' => 10,
);
return $items;
}
function advagg_css_compress_advagg_current_hooks_hash_array_alter(&$aggregate_settings) {
$aggregate_settings['variables']['advagg_css_compressor'] = variable_get('advagg_css_compressor', ADVAGG_CSS_COMPRESSOR);
$aggregate_settings['variables']['advagg_css_compressor_file_settings'] = variable_get('advagg_css_compressor_file_settings', array());
}
function advagg_css_compress_advagg_modify_css_pre_render_alter(&$children, &$elements) {
$compressor = variable_get('advagg_css_compress_inline', ADVAGG_CSS_COMPRESS_INLINE);
if (empty($compressor)) {
return;
}
if (!variable_get('advagg_css_compress_inline_if_not_cacheable', ADVAGG_CSS_COMPRESS_INLINE_IF_NOT_CACHEABLE) && !drupal_page_is_cacheable()) {
return;
}
module_load_include('inc', 'advagg_css_compress', 'advagg_css_compress.advagg');
if ($compressor == 2) {
foreach ($children as &$values) {
if (!empty($values['#value'])) {
advagg_css_compress_yui_cssmin($values['#value']);
}
}
unset($values);
}
}
function advagg_css_compress_libraries_info() {
$libraries['YUI-CSS-compressor-PHP-port'] = array(
'name' => 'YUI CSS compressor PHP port',
'vendor url' => 'https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port',
'download url' => 'https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port/archive/master.zip',
'version callback' => 'advagg_css_compress_libraries_get_version',
'version arguments' => array(
'file' => 'README.md',
'pattern' => '/###\\s+v([0-9a-zA-Z\\.-]+)/',
'lines' => 1000,
'cols' => 20,
'default_version' => '2.4.8',
),
'local version' => '2.4.8-p10',
'remote' => array(
'callback' => 'advagg_get_github_version_txt',
'url' => 'https://cdn.jsdelivr.net/gh/tubalmartin/YUI-CSS-compressor-PHP-port@master/README.md',
),
'versions' => array(
'2' => array(
'files' => array(
'php' => array(
'cssmin.php',
'data/hex-to-named-color-map.php',
'data/named-to-hex-color-map.php',
),
),
),
'3' => array(
'files' => array(
'php' => array(
'src/Minifier.php',
'src/Utils.php',
'src/Colors.php',
'src/data/hex-to-named-color-map.php',
'src/data/named-to-hex-color-map.php',
),
),
),
'4' => array(
'files' => array(
'php' => array(
'src/Minifier.php',
'src/Utils.php',
'src/Colors.php',
),
),
),
),
);
return $libraries;
}
function advagg_css_compress_libraries_get_version(array $library, array $options) {
$return = libraries_get_version($library, $options);
if (empty($return) && !empty($options['default_version'])) {
$file = DRUPAL_ROOT . '/' . $library['library path'] . '/' . $options['file'];
if (is_readable($file)) {
return $options['default_version'];
}
}
return $return;
}
function advagg_css_compress_configuration() {
$description = '';
$options = array(
-1 => t('Disable Core'),
0 => t('Core'),
2 => t('YUI'),
);
$compressors = array();
$functions = array(
2 => 'advagg_css_compress_yui_cssmin',
);
$options_desc = array(
$options,
$description,
);
drupal_alter('advagg_css_compress_configuration', $options_desc, $compressors, $functions);
list($options, $description) = $options_desc;
return array(
$options,
$description,
$compressors,
$functions,
);
}