You are here

outdatedbrowser.module in Outdated Browser 7

Same filename and directory in other branches
  1. 8 outdatedbrowser.module

Outdated Browser module file.

File

outdatedbrowser.module
View source
<?php

/**
 * @file
 * Outdated Browser module file.
 */

/**
 * Implements hook_menu().
 */
function outdatedbrowser_menu() {
  $items = array();
  $items['admin/config/services/outdatedbrowser'] = array(
    'title' => 'Outdated Browser',
    'description' => 'Configure Outdated Browser library',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'outdatedbrowser_admin',
    ),
    'access arguments' => array(
      'administer outdatedbrowser',
    ),
    'file' => 'outdatedbrowser.admin.inc',
  );
  return $items;
}

/**
 * Implements hook_permission().
 */
function outdatedbrowser_permission() {
  return array(
    'administer outdatedbrowser' => array(
      'title' => t('Administer Outdated Browser configuration'),
      'description' => t('Configure Outdated Browser module.'),
    ),
  );
}

/**
 * Implements hook_help().
 */
function outdatedbrowser_help($path, $arg) {
  $output = '';
  switch ($path) {
    case 'admin/help#outdatedbrowser':
      $output = file_get_contents(drupal_get_path('module', 'outdatedbrowser') . '/README.txt');
      if (module_exists('markdown')) {
        $output = filter_xss_admin(module_invoke('markdown', 'filter', 'process', 0, -1, $output));
      }
      else {
        $output = '<pre>' . check_plain($output) . '</pre>';
      }
  }
  return $output;
}

/**
 * Implements hook_libraries_info().
 */
function outdatedbrowser_libraries_info() {
  $libraries = array();

  // Registers Outdated Browser library.
  $libraries['outdatedbrowser'] = array(
    'name' => 'Outdated Browser library',
    'vendor url' => 'http://outdatedbrowser.com',
    'download url' => 'https://github.com/burocratik/outdated-browser/archive/develop.zip',
    'path' => 'outdatedbrowser',
    'version arguments' => array(
      'file' => 'outdatedbrowser/outdatedbrowser.js',
      'pattern' => '/(?i:Version:)\\s+([0-9\\.]+)/',
      'lines' => 5,
      'cols' => 50,
    ),
    'files' => array(
      'js' => array(
        'outdatedbrowser.min.js',
      ),
      'css' => array(
        'outdatedbrowser.min.css',
      ),
    ),
    'variants' => array(
      'minified' => array(
        'files' => array(
          'js' => array(
            'outdatedbrowser.min.js',
          ),
          'css' => array(
            'outdatedbrowser.min.css',
          ),
        ),
      ),
      'source' => array(
        'files' => array(
          'js' => array(
            'outdatedbrowser.js',
          ),
          'css' => array(
            'outdatedbrowser.css',
          ),
        ),
      ),
    ),
  );
  return $libraries;
}

/**
 * Implements hook_page_build().
 *
 * Adds the necessary #outdated div element to the page_bottom region
 * and loads the necessary CSS and JS files.
 */
function outdatedbrowser_page_build(&$page) {
  if (path_is_admin(current_path())) {
    return;
  }
  $page['page_bottom']['outdatedbrowser'] = array(
    '#markup' => '<div id="outdated"></div>',
  );
  $variant = variable_get('outdatedbrowser_compression_type', 'minified');
  $library = libraries_load('outdatedbrowser', $variant);
  if ($library['installed']) {
    $module_path = drupal_get_path('module', 'outdatedbrowser');
    $page['page_bottom']['#attached']['js'][] = array(
      'data' => $module_path . '/js/outdatedbrowser.js',
    );
    $js_settings = array(
      'bgColor' => variable_get('outdatedbrowser_bgcolor', '#f25648'),
      'color' => variable_get('outdatedbrowser_color', '#ffffff'),
      'lowerThan' => variable_get('outdatedbrowser_lowerthan', 'transform'),
      'languagePath' => file_create_url(outdatedbrowser_get_language_file_path()),
    );
    $page['page_bottom']['#attached']['js'][] = array(
      'data' => array(
        'outdatedbrowser' => $js_settings,
      ),
      'type' => 'setting',
    );
  }
}

/**
 * Gets the path of the appropriate language file of Outdated Browser plugin.
 */
function outdatedbrowser_get_language_file_path() {
  $result = '';
  $library_path = libraries_get_path('outdatedbrowser');
  $langfile_pattern = $library_path . "/outdatedbrowser/lang/%s.html";
  global $language;
  if (file_exists(drupal_realpath(sprintf($langfile_pattern, $language->language)))) {

    // A translation file for the active interface language was found.
    $result = sprintf($langfile_pattern, $language->language);
  }
  elseif (file_exists(drupal_realpath(sprintf($langfile_pattern, language_default('language'))))) {

    // A translation file for the default system language was found (fallback).
    $result = sprintf($langfile_pattern, language_default('language'));
  }
  elseif (file_exists(drupal_realpath(sprintf($langfile_pattern, 'en')))) {

    // An english translation file was found (second and last fallback method).
    $result = sprintf($langfile_pattern, 'en');
  }
  return $result;
}

/**
 * Checks, if a hexadecimal CSS color string is valid.
 */
function outdatedbrowser_valid_hexadecimal_string($color) {
  return preg_match('/^#([a-f0-9]{3}){1,2}$/iD', $color);
}

Functions

Namesort descending Description
outdatedbrowser_get_language_file_path Gets the path of the appropriate language file of Outdated Browser plugin.
outdatedbrowser_help Implements hook_help().
outdatedbrowser_libraries_info Implements hook_libraries_info().
outdatedbrowser_menu Implements hook_menu().
outdatedbrowser_page_build Implements hook_page_build().
outdatedbrowser_permission Implements hook_permission().
outdatedbrowser_valid_hexadecimal_string Checks, if a hexadecimal CSS color string is valid.