You are here

cookie_banner.module in Cookie_Banner 7

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

Main module file.

File

cookie_banner.module
View source
<?php

/**
 * @file
 * Main module file.
 */

/**
 * Implements hook_menu().
 */
function cookie_banner_menu() {
  $items['admin/config/system/cookie-banner'] = array(
    'title' => 'Cookie Banner',
    'description' => 'Comply with the EU Directive on Privacy and Electronic Communications.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'cookie_banner_admin_form',
    ),
    'access arguments' => array(
      'administer cookie banner',
    ),
    'file' => 'cookie_banner.admin.inc',
  );
  return $items;
}

/**
 * Implements hook_permission().
 */
function cookie_banner_permission() {
  return array(
    'administer cookie banner' => array(
      'title' => 'Administer Solas EU Cookie Compliance',
    ),
  );
}

/**
 * Implements hook_preprocess_HOOK().
 */
function cookie_banner_preprocess_page(&$vars) {
  if (!user_is_logged_in()) {
    $lang = $GLOBALS['language']->language;
    $theme_params['use_cookie_message'] = variable_get('cookie_banner_use_cookie_message_' . $lang, 'This site uses cookies to help make it more useful to you.');
    $theme_params['more_info_message'] = variable_get('cookie_banner_more_info_message_' . $lang, 'Find out more about cookies.');
    $theme_params['more_info_url'] = url(variable_get('cookie_banner_more_info_url_' . $lang, 'about/cookie-policy'));
    $jsvars['cookie_banner_message'] = theme('cookie_banner_message', $theme_params);
    $jsvars['cookie_banner_name'] = variable_get('cookie_banner_name_' . $lang, preg_replace("[\\W]", "-", $_SERVER['HTTP_HOST'] . "-eu-cookie"));
    $jsvars['cookie_banner_duration'] = time() + 60 * 60 * 24 * 90;

    // Required CSS.
    drupal_add_css(drupal_get_path('module', 'cookie_banner') . '/css/cookie_banner.css', array(
      'every_page' => TRUE,
      'group' => CSS_THEME,
    ));
    if ($GLOBALS['language']->direction) {
      drupal_add_css(drupal_get_path('module', 'cookie_banner') . '/css/cookie_banner_rtl.css', array(
        'every_page' => TRUE,
        'group' => CSS_THEME,
      ));
    }

    // Required JS.
    drupal_add_js(drupal_get_path('module', 'cookie_banner') . '/js/cookie_banner.js', array(
      'type' => 'file',
    ));

    // Required JS vars.
    drupal_add_js(array(
      'cookie_banner' => $jsvars,
    ), array(
      'type' => 'setting',
      'scope' => 'footer',
    ));
  }
}

/**
 * Implements hook_theme().
 */
function cookie_banner_theme() {
  $path = drupal_get_path('module', 'cookie_banner') . '/templates';
  return array(
    'cookie_banner_message' => array(
      'template' => 'cookie-banner-message',
      'variables' => array(
        'use_cookie_message' => NULL,
        'more_info_message' => NULL,
        'more_info_url' => NULL,
      ),
      'path' => $path,
    ),
  );
}