Implements hook_advagg_context_alter().
Sujets associés
Fichier
-
./
advagg.advagg.inc, line 164
Code
function advagg_advagg_context_alter(&$original, $aggregate_settings, $mode) {
if ($mode == 0) {
// Change context.
$original['base_root'] = $GLOBALS['base_root'];
$original['base_url'] = $GLOBALS['base_url'];
$original['base_path'] = $GLOBALS['base_path'];
$original['is_https'] = $GLOBALS['is_https'];
$original['language'] = isset($GLOBALS['language']) ? $GLOBALS['language'] : NULL;
$GLOBALS['is_https'] = $aggregate_settings['variables']['is_https'];
if ($aggregate_settings['variables']['is_https']) {
$GLOBALS['base_root'] = str_replace('http://', 'https://', $GLOBALS['base_root']);
}
else {
$GLOBALS['base_root'] = str_replace('https://', 'http://', $GLOBALS['base_root']);
}
$GLOBALS['base_path'] = $aggregate_settings['variables']['base_path'];
$GLOBALS['base_url'] = rtrim($GLOBALS['base_root'] . $GLOBALS['base_path'], '/');
if (isset($aggregate_settings['variables']['language'])) {
$languages = language_list();
if (isset($languages[$aggregate_settings['variables']['language']])) {
$GLOBALS['language'] = $languages[$aggregate_settings['variables']['language']];
}
}
}
elseif ($mode == 1) {
// Change context back.
if (isset($original['base_root'])) {
$GLOBALS['base_root'] = $original['base_root'];
}
if (isset($original['base_url'])) {
$GLOBALS['base_url'] = $original['base_url'];
}
if (isset($original['base_path'])) {
$GLOBALS['base_path'] = $original['base_path'];
}
if (isset($original['is_https'])) {
$GLOBALS['is_https'] = $original['is_https'];
}
if (isset($original['language'])) {
$GLOBALS['language'] = $original['language'];
}
}
// Moved this in here due to incomplete bug reports from
// https://www.drupal.org/node/1942230. I can not reproduce the reported
// issues with the patch for the CDN module so I've moved the code into
// advagg.
if (!function_exists('cdn_advagg_context_alter') && module_exists('cdn')) {
if ($mode == 0) {
// Save original context.
$original[CDN_MODE_VARIABLE] = variable_get(CDN_MODE_VARIABLE, CDN_MODE_BASIC);
$original[CDN_BASIC_FARFUTURE_VARIABLE] = variable_get(CDN_BASIC_FARFUTURE_VARIABLE, CDN_BASIC_FARFUTURE_DEFAULT);
$original[CDN_HTTPS_SUPPORT_VARIABLE] = variable_get(CDN_HTTPS_SUPPORT_VARIABLE, FALSE);
$original[CDN_STATUS_VARIABLE] = variable_get(CDN_STATUS_VARIABLE, CDN_DISABLED);
// Set context for file_create_url()/cdn_file_url_alter().
$GLOBALS['conf'][CDN_MODE_VARIABLE] = isset($aggregate_settings['variables'][CDN_MODE_VARIABLE]) ? $aggregate_settings['variables'][CDN_MODE_VARIABLE] : variable_get(CDN_MODE_VARIABLE, CDN_MODE_BASIC);
$GLOBALS['conf'][CDN_BASIC_FARFUTURE_VARIABLE] = isset($aggregate_settings['variables'][CDN_BASIC_FARFUTURE_VARIABLE]) ? $aggregate_settings['variables'][CDN_BASIC_FARFUTURE_VARIABLE] : variable_get(CDN_BASIC_FARFUTURE_VARIABLE, CDN_BASIC_FARFUTURE_DEFAULT);
$GLOBALS['conf'][CDN_HTTPS_SUPPORT_VARIABLE] = isset($aggregate_settings['variables'][CDN_HTTPS_SUPPORT_VARIABLE]) ? $aggregate_settings['variables'][CDN_HTTPS_SUPPORT_VARIABLE] : variable_get(CDN_HTTPS_SUPPORT_VARIABLE, FALSE);
$GLOBALS['conf'][CDN_STATUS_VARIABLE] = isset($aggregate_settings['variables'][CDN_STATUS_VARIABLE]) ? $aggregate_settings['variables'][CDN_STATUS_VARIABLE] : variable_get(CDN_STATUS_VARIABLE, CDN_DISABLED);
// Disable CDN if cdn_check_drupal_path is FALSE.
if (empty($aggregate_settings['variables']['cdn_check_drupal_path'])) {
$original[CDN_STATUS_VARIABLE] = CDN_DISABLED;
}
// Handle HTTPS.
if (!empty($aggregate_settings['variables']['cdn_request_is_https']) && !cdn_request_is_https()) {
if (isset($_SERVER['HTTPS'])) {
$original['HTTPS'] = $_SERVER['HTTPS'];
}
else {
$original['HTTPS'] = FALSE;
}
$_SERVER['HTTPS'] = 'on';
}
}
elseif ($mode == 1) {
// Set context back.
$GLOBALS['conf'][CDN_MODE_VARIABLE] = $original[CDN_MODE_VARIABLE];
$GLOBALS['conf'][CDN_BASIC_FARFUTURE_VARIABLE] = $original[CDN_BASIC_FARFUTURE_VARIABLE];
$GLOBALS['conf'][CDN_HTTPS_SUPPORT_VARIABLE] = $original[CDN_HTTPS_SUPPORT_VARIABLE];
$GLOBALS['conf'][CDN_STATUS_VARIABLE] = $original[CDN_STATUS_VARIABLE];
// Handle HTTPS.
if (isset($original['HTTPS']) && !is_null($original['HTTPS'])) {
$_SERVER['HTTPS'] = $original['HTTPS'];
}
}
}
}