You are here

function _lazy_loader_enabled in Image Lazyloader 7.2

Same name and namespace in other branches
  1. 7 lazyloader.module \_lazy_loader_enabled()

Helper function to determine whether the lazyloader is enabled in a page.

Return value

bool

1 call to _lazy_loader_enabled()
theme_lazyloader_image in ./lazyloader.module
Returns HTML for an image.

File

./lazyloader.module, line 205
Lazyloader Module

Code

function _lazy_loader_enabled() {

  // Bail if lazyloader is disabled entirely.
  if (!variable_get('lazyloader_enabled', LAZYLOADER_ENABLED)) {
    return FALSE;
  }

  // This method gets called quite often, so let's cache all the heavy stuff.
  static $enabled;
  if (isset($enabled)) {
    return $enabled;
  }

  // Convert path to lowercase. This allows comparison of the same path
  // with different case. Ex: /Page, /page, /PAGE.
  $pages = drupal_strtolower(variable_get('lazyloader_paths', LAZYLOADER_PATHS));

  // Convert the Drupal path to lowercase
  $path = drupal_strtolower(drupal_get_path_alias($_GET['q']));

  // Compare the lowercase internal and lowercase path alias (if any).
  $path_match = drupal_match_path($path, $pages);
  if ($path != $_GET['q']) {
    $path_match = $path_match || drupal_match_path($_GET['q'], $pages);
  }
  $path_exclude = variable_get('lazyloader_page_exclude_option', LAZYLOADER_PAGE_EXCLUDE_OPTION);
  $enabled = $path_exclude === 'exclude' ? !$path_match : $path_match;

  // Only check content types if Lazyloader is not disabled already.
  if ($enabled && ($node = menu_get_object())) {
    $types = _lazyloader_filter_selected_values(variable_get('lazyloader_content_types', array()));
    if (!empty($types)) {
      $type = node_type_get_type($node);
      $type_match = in_array($type->type, $types);
      $enabled = $type_match;
    }
  }
  return $enabled;
}