' . t('This is a simple module that provides the mechanism to minify JavaScript files, ');
$output .= t('which ultimately reduces the file size and load time.') . '
';
$output .= '' . t('In Operations column,
Minify => Generate the minified version,
');
$output .= t('Refresh => Refresh/regenerate the minified version,
');
$output .= t('Revert => Delete the minified file and use original file.') . '
';
$output .= '' . t('In Status column,
');
$output .= t('Need to refresh => Original file is updated, click Refresh to update minified file.') . '
';
return $output;
}
}
/**
* Implements hook_menu()
*/
function minify_menu() {
$items['admin/config/development/performance/default'] = array(
'title' => 'Performance',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 1,
);
$items['admin/config/development/performance/minifyjs'] = array(
'title' => 'Minify JavaScript files',
'access arguments' => array('administer minify'),
'page callback' => 'drupal_get_form',
'page arguments' => array('minify_js_callback'),
'type' => MENU_LOCAL_TASK,
'weight' => 2,
'file' => 'minify.admin.inc',
);
$items['admin/config/development/performance/minifyjs/revert'] = array(
'title' => 'Revert Minify JS',
'access arguments' => array('administer minify'),
'page callback' => '_minify_js_revert_callback',
'file' => 'minify.admin.inc',
'type' => MENU_CALLBACK,
);
$items['admin/config/development/performance/minifyjs/refresh'] = array(
'title' => 'Minify JS',
'access arguments' => array('administer minify'),
'page callback' => '_minify_js_refresh_callback',
'file' => 'minify.admin.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implements hook_permission()
*/
function minify_permission() {
return array(
'administer minify' => array(
'title' => t('Administer minify'),
'description' => t('Perform administration tasks for minify module.'),
),
);
}
/**
* Implements hook_FORM_ID_alter().
*
* @param type $form
* @param type $form_state
*/
function minify_form_system_performance_settings_alter(&$form, &$form_state, $form_id) {
if (user_access('administer minify')) {
$m_cnt = 0;
$cache = variable_get('minify_captured_js', array());
foreach ($cache as $key => $value) {
if ($cache[$key]['status']) {
$m_cnt++;
}
}
$description = t('Select Minify JavaScript files tab at top of the page or ')
. l('Click here', 'admin/config/development/performance/minifyjs')
. t(' to manage minified JavaScript files.')
. t('
Out of @cnt only @m_cnt JavaScript files are minified.', array('@cnt' => count($cache), '@m_cnt' => $m_cnt));
$form['bandwidth_optimization']['minify_html'] = array(
'#type' => 'checkbox',
'#title' => t('Minify HTML.'),
'#default_value' => intval(variable_get('minify_html', 0)),
);
$form['bandwidth_optimization']['minify_js'] = array(
'#type' => 'checkbox',
'#title' => t('Use Minified JavaScript files.'),
'#description' => $description,
'#default_value' => intval(variable_get('minify_js', 0)),
);
}
}
/**
* Implements hook_process_html()
*/
function minify_process_html(&$variables) {
global $theme;
$theme_default = variable_get('theme_default', null);
/* Check Monify HTML is selected and it is for front end theme */
if (intval(variable_get('minify_html', 0)) && $theme == $theme_default) {
/* Constant used as replacement tag key in global placeholders array */
define('REPLACEMENT_HASH', 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']));
/* Get active theme regions */
$visible_theme_region = system_region_list($theme_default, REGIONS_ALL);
/* Add page region to array */
$visible_theme_region = array_merge(array('page' => 'Page', 'page_top' => 'Page top', 'page_bottom' => 'Page bottom'), $visible_theme_region);
/* Prase and check if region is exist then minify HTML */
foreach ($visible_theme_region as $key => $value) {
if (isset($variables[$key])) {
$variables[$key] = _minify_html($variables[$key]);
}
}
}
}
/**
* Helper function to minify HTML
*/
function _minify_html($buffer) {
/* Replace