You are here

hfs.module in Header and Footer Scripts 7

Same filename and directory in other branches
  1. 7.2 hfs.module

Enables Drupal to add scripts and styles from the frontend on all over the site.

File

hfs.module
View source
<?php

/**
 * @file
 * Enables Drupal to add scripts and styles from the frontend on all over the site.
 */

/**
 * Implements hook_menu().
 */
function hfs_menu() {
  $items['admin/config/development/hfs'] = array(
    'title' => 'HFS (Header Footer Scripts)',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'hfs_header_settings_form',
    ),
    'access arguments' => array(
      'administer hfs module',
    ),
    'description' => 'Allow to add scripts and styles from the frontend under Head section.',
    'file' => 'hfs.admin.inc',
    'weight' => 10,
  );
  $items['admin/config/development/hfs/header'] = array(
    'title' => 'Header Scripts',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'hfs_header_settings_form',
    ),
    'access arguments' => array(
      'administer hfs module',
    ),
    'description' => 'Allow to add scripts and styles from the frontend under Head section.',
    'file' => 'hfs.admin.inc',
    'type' => MENU_LOCAL_TASK,
    'weight' => 20,
  );
  $items['admin/config/development/hfs/body'] = array(
    'title' => 'Body Scripts',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'hfs_body_settings_form',
    ),
    'access arguments' => array(
      'administer hfs module',
    ),
    'description' => 'Allow to add scripts and styles from the frontend at the start of BODY Tag.',
    'file' => 'hfs.admin.inc',
    'type' => MENU_LOCAL_TASK,
    'weight' => 30,
  );
  $items['admin/config/development/hfs/footer'] = array(
    'title' => 'Footer Scripts',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'hfs_footer_settings_form',
    ),
    'access arguments' => array(
      'administer hfs module',
    ),
    'description' => 'Allow to add scripts and styles from the frontend just before the end of BODY Tag.',
    'file' => 'hfs.admin.inc',
    'type' => MENU_LOCAL_TASK,
    'weight' => 40,
  );
  return $items;
}

/**
 * Implements hook_permission().
 */
function hfs_permission() {
  $permissions['administer hfs module'] = array(
    'title' => t('Add Scripts all over the site'),
    'restrict access' => TRUE,
    'description' => t('Users who have this permission can add and remove the scripts from the site.'),
  );
  return $permissions;
}

/**
 * Implements hook_process_html().
 *
 * Add scripts on overall the site which are defined on the settings page.
 */
function hfs_process_html(&$variables) {
  $header_scripts = variable_get('hfs_header_scripts');
  $body_scripts = variable_get('hfs_body_scripts');
  $footer_scripts = variable_get('hfs_footer_scripts');
  if (isset($body_scripts) && !empty($body_scripts)) {
    if (!empty($body_scripts['styles'])) {
      $variables['page_top'] .= $body_scripts['styles'] . PHP_EOL;
    }
    if (!empty($body_scripts['scripts'])) {
      $variables['page_top'] .= $body_scripts['scripts'] . PHP_EOL;
    }
  }
  if (isset($header_scripts) && !empty($header_scripts)) {
    if (!empty($header_scripts['styles'])) {
      $variables['styles'] .= $header_scripts['styles'] . PHP_EOL;
    }
    if (!empty($header_scripts['scripts'])) {
      $variables['scripts'] .= $header_scripts['scripts'] . PHP_EOL;
    }
  }
  if (isset($footer_scripts) && !empty($footer_scripts)) {
    if (!empty($footer_scripts['styles'])) {
      $variables['page_bottom'] .= $footer_scripts['styles'] . PHP_EOL;
    }
    if (!empty($footer_scripts['scripts'])) {
      $variables['page_bottom'] .= $footer_scripts['scripts'] . PHP_EOL;
    }
  }
}

Functions

Namesort descending Description
hfs_menu Implements hook_menu().
hfs_permission Implements hook_permission().
hfs_process_html Implements hook_process_html().