You are here

function advagg_enabled in Advanced CSS/JS Aggregation 7.2

Same name and namespace in other branches
  1. 8.4 advagg.module \advagg_enabled()
  2. 8.2 advagg.module \advagg_enabled()
  3. 8.3 advagg.module \advagg_enabled()

Function used to see if aggregation is enabled.

Return value

bool The value of the advagg_enabled variable.

32 calls to advagg_enabled()
advagg_add_default_dns_lookups in ./advagg.module
Alter the CSS or JS array adding in DNS domain info.
advagg_ajax_render_alter in ./advagg.module
Implements hook_ajax_render_alter().
advagg_block_view_alter in ./advagg.module
Implements hook_block_view_alter().
advagg_css_alter in advagg_font/advagg_font.module
Implements hook_css_alter().
advagg_fix_type in ./advagg.module
Alter the js array fixing the type key if set incorrectly.

... See full list

5 string references to 'advagg_enabled'
advagg_admin_menu_cache_info in ./advagg.module
Implements hook_admin_menu_cache_info().
advagg_admin_menu_output_alter in ./advagg.module
Implements hook_admin_menu_output_alter().
advagg_admin_settings_form in ./advagg.admin.inc
Form builder; Configure advagg settings.
advagg_install_fast_checks in ./advagg.install
Run various checks that are fast.
advagg_mod_init in advagg_mod/advagg_mod.module
Implements hook_init().

File

./advagg.module, line 3258
Advanced CSS/JS aggregation module.

Code

function advagg_enabled() {

  // If current_path() doesn't exist then bootstrap Drupal to make it available.
  if (!function_exists('current_path')) {
    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  }
  $init =& drupal_static(__FUNCTION__);
  if (!empty($init)) {
    return variable_get('advagg_enabled', ADVAGG_ENABLED);
  }

  // Set base_path if not set.
  if (empty($GLOBALS['base_path'])) {
    $GLOBALS['base_path'] = rtrim(dirname($_SERVER['SCRIPT_NAME']), '\\/') . '/';
  }
  $init = TRUE;

  // Disable AdvAgg if module needs to be upgraded from 1.x to 2.x.
  if (variable_get('advagg_needs_update', ADVAGG_NEEDS_UPDATE)) {
    if (!db_table_exists('advagg_aggregates_versions')) {
      $GLOBALS['conf']['advagg_enabled'] = FALSE;
      if (user_access('administer site configuration')) {
        drupal_set_message(t('Please run <a href="@link">database updates</a>. AdvAgg will remain disabled until done.', array(
          '@link' => url('update.php'),
        )), 'error');
      }
    }
    else {
      variable_del('advagg_needs_update');
    }
  }
  else {

    // Get values and fill in defaults if needed.
    $config_path = advagg_admin_config_root_path();
    $current_path = current_path();
    $arg = arg();
    $arg += array(
      1 => '',
      2 => '',
      3 => '',
      4 => '',
      5 => '',
    );
    $admin_theme = variable_get('admin_theme');

    // List of all the pages which will not have Advanced Aggregator enabled.
    $list_of_pages = variable_get('advagg_disable_on_listed_pages');
    $pages = trim(drupal_strtolower($list_of_pages));

    // Convert the Drupal path to lowercase.
    $path = drupal_strtolower(drupal_get_path_alias(current_path()));

    // Compare the lowercase internal and lowercase path alias (if any).
    $page_match = drupal_match_path($path, $pages);
    if ($page_match) {
      $GLOBALS['conf']['advagg_enabled'] = FALSE;
      $GLOBALS['conf']['preprocess_css'] = FALSE;
      $GLOBALS['conf']['preprocess_js'] = FALSE;
    }

    // Disable advagg if on admin page and configured to do so.
    // AND theme is admin theme
    // AND NOT /admin/reports/status
    // AND NOT /admin/config/development/performance/.
    // AND NOT /admin/appearance/settings/*.
    // AND NOT /admin/config/development/performance/advagg/*.
    if (variable_get('advagg_disable_on_admin', ADVAGG_DISABLE_ON_ADMIN) && $GLOBALS['theme'] === $admin_theme && path_is_admin($current_path) && !($arg[1] === 'reports' && $arg[2] === 'status') && !($arg[2] === 'development' && $arg[3] === 'performance' && empty($arg[4])) && !($arg[1] === 'appearance' && $arg[2] === 'settings' && !empty($arg[3])) && stripos($current_path, $config_path . '/advagg') !== 0) {
      $GLOBALS['conf']['advagg_enabled'] = FALSE;
      $GLOBALS['conf']['preprocess_css'] = FALSE;
      $GLOBALS['conf']['preprocess_js'] = FALSE;
    }

    // Check if the advagg cookie is set.
    $cookie_name = 'AdvAggDisabled';
    $bypass_cookie = FALSE;
    $key = drupal_hmac_base64('advagg_cookie', drupal_get_private_key() . drupal_get_hash_salt() . variable_get('cron_key', 'drupal'));
    if (!empty($_COOKIE[$cookie_name]) && $_COOKIE[$cookie_name] == $key) {
      $bypass_cookie = TRUE;
    }

    // Allow for AdvAgg to be enabled per request.
    if (isset($_GET['advagg']) && $_GET['advagg'] == 1 && !defined('MAINTENANCE_MODE') && (user_access('bypass advanced aggregation') || $bypass_cookie)) {
      $GLOBALS['conf']['advagg_enabled'] = TRUE;
      $GLOBALS['conf']['preprocess_css'] = TRUE;
      $GLOBALS['conf']['preprocess_js'] = TRUE;
    }

    // Disable AdvAgg if maintenance mode is defined.
    if (defined('MAINTENANCE_MODE')) {
      $GLOBALS['conf']['advagg_enabled'] = FALSE;
    }

    // Only run code below if advagg is enabled.
    if (variable_get('advagg_enabled', ADVAGG_ENABLED)) {

      // Do not use AdvAgg or preprocessing functions if the disable cookie is
      // set.
      if ($bypass_cookie && !isset($_GET['advagg'])) {
        $GLOBALS['conf']['advagg_enabled'] = FALSE;
        $GLOBALS['conf']['preprocess_css'] = FALSE;
        $GLOBALS['conf']['preprocess_js'] = FALSE;
        $bypass_cookie = TRUE;

        // Let the user know that the AdvAgg bypass cookie is currently set.
        static $msg_set;
        if (!isset($msg_set) && variable_get('advagg_show_bypass_cookie_message', ADVAGG_SHOW_BYPASS_COOKIE_MESSAGE)) {
          $msg_set = TRUE;
          if (user_access('administer site configuration')) {
            drupal_set_message(t('The AdvAgg bypass cookie is currently enabled. Turn it off by going to the <a href="@advagg_operations">AdvAgg Operations</a> page and clicking the <em>Toggle the "aggregation bypass cookie" for this browser</em> button.', array(
              '@advagg_operations' => url(advagg_admin_config_root_path() . '/advagg/operations', array(
                'fragment' => 'edit-bypass',
              )),
            )));
          }
          else {
            drupal_set_message(t('The AdvAgg bypass cookie is currently enabled. Turn it off by <a href="@login">logging in</a> with a user with the "administer site configuration" permissions and going to the AdvAgg Operations page (located at @advagg_operations) and clicking the <em>Toggle the "aggregation bypass cookie" for this browser</em> button.', array(
              '@login' => 'user/login',
              '@advagg_operations' => advagg_admin_config_root_path() . '/advagg/operations',
            )));
          }
        }
      }

      // Disable advagg if requested.
      if (isset($_GET['advagg']) && $_GET['advagg'] == -1 && (user_access('bypass advanced aggregation') || $bypass_cookie)) {
        $GLOBALS['conf']['advagg_enabled'] = FALSE;
        $GLOBALS['conf']['preprocess_css'] = FALSE;
        $GLOBALS['conf']['preprocess_js'] = FALSE;
      }

      // Disable core preprocessing if requested.
      if (isset($_GET['advagg-core']) && $_GET['advagg-core'] == 0 && (user_access('bypass advanced aggregation') || $bypass_cookie)) {
        $GLOBALS['conf']['preprocess_css'] = FALSE;
        $GLOBALS['conf']['preprocess_js'] = FALSE;
      }

      // Enable core preprocessing if requested.
      if (isset($_GET['advagg-core']) && $_GET['advagg-core'] == 1 && (user_access('bypass advanced aggregation') || $bypass_cookie)) {
        $GLOBALS['conf']['preprocess_css'] = TRUE;
        $GLOBALS['conf']['preprocess_js'] = TRUE;
      }

      // Enable debugging if requested.
      if (isset($_GET['advagg-debug']) && (user_access('bypass advanced aggregation') || $bypass_cookie)) {

        // Cast to an int.
        $GLOBALS['conf']['advagg_debug'] = (int) $_GET['advagg-debug'];
      }
    }
  }
  return variable_get('advagg_enabled', ADVAGG_ENABLED);
}