You are here

hfs.module in Header and Footer Scripts 7.2

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

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

File

hfs.module
View source
<?php

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

/**
 * Implements hook_menu().
 */
function hfs_menu() {
  $items['admin/config/development/header-and-footer-scripts'] = array(
    'title' => 'Header and Footer Scripts',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'hfs_header_settings',
    ),
    '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/header-and-footer-scripts/header'] = array(
    'title' => 'Header Scripts',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'hfs_header_settings',
    ),
    '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/header-and-footer-scripts/body'] = array(
    'title' => 'Body Scripts',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'hfs_body_settings',
    ),
    '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/header-and-footer-scripts/footer'] = array(
    'title' => 'Footer Scripts',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'hfs_footer_settings',
    ),
    '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_help().
 */
function hfs_help($path, $arg) {
  switch ($path) {
    case 'admin/help#header_and_footer_scripts':
      $filepath = dirname(__FILE__) . '/README.txt';
      if (file_exists($filepath)) {
        $readme = file_get_contents($filepath);
      }
      if (!isset($readme)) {
        return NULL;
      }
      if (module_exists('markdown')) {
        $filters = module_invoke('markdown', 'filter_info');
        $info = $filters['filter_markdown'];
        if (function_exists($info['process callback'])) {
          $output = $info['process callback']($readme, NULL);
        }
        else {
          $output = '<pre>' . $readme . '</pre>';
        }
      }
      else {
        $output = '<pre>' . $readme . '</pre>';
      }
      return $output;
  }
}

/**
 * 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('header_and_footer_scripts_header_settings');
  $body_scripts = variable_get('header_and_footer_scripts_body_settings');
  $footer_scripts = variable_get('header_and_footer_scripts_footer_settings');
  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_help Implements hook_help().
hfs_menu Implements hook_menu().
hfs_permission Implements hook_permission().
hfs_process_html Implements hook_process_html().