You are here

typekit.module in Typekit 6

Main module file for typekit module

File

typekit.module
View source
<?php

/**
 * @file
 * Main module file for typekit module
 */

/**
 * Implementation of hook_help().
 */
function typekit_help($section) {
  switch ($section) {

    // Help page for Typekit
    case 'admin/help#typekit':
      $output = '<p>' . t('Easy way to include Typekit in your site.') . '</p>';
      return $output;
  }
}

/**
 * Implementation of hook_perm().
 */
function typekit_perm() {
  return array(
    'administer typekit',
  );
}

/**
 * Implementation of hook_menu().
 */
function typekit_menu() {
  $items = array();
  $items['admin/settings/typekit'] = array(
    'title' => 'Typekit',
    'description' => 'Site settings for Typekit.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'typekit_admin_settings',
    ),
    'access arguments' => array(
      'administer typekit',
    ),
    'file' => 'includes/typekit.admin.inc',
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}

/**
 * Implementation of hook_init().
 */
function typekit_init() {
  $enabled = variable_get('typekit_enable', TRUE);
  $key = variable_get('typekit_key', '');
  $visibility = variable_get('typekit_visibility_settings', 0);
  $visibility_pages = variable_get('typekit_visibility_pages', '');

  // Match path if necessary (taken from block module)
  if ($visibility_pages) {
    if ($visibility < 2) {
      $path = drupal_get_path_alias($_GET['q']);

      // Compare with the internal and path alias (if any).
      $page_match = drupal_match_path($path, $visibility_pages);
      if ($path != $_GET['q']) {
        $page_match = $page_match || drupal_match_path($_GET['q'], $visibility_pages);
      }

      // When $visibility has a value of 0, the block is displayed on
      // all pages except those listed in $visibility_pages. When set to 1, it
      // is displayed only on those pages listed in $visibility_pages.
      $page_match = !($visibility xor $page_match);
    }
    else {
      $page_match = drupal_eval($visibility_pages);
    }
  }
  else {
    $page_match = TRUE;
  }

  // Check for key
  if (!empty($key) && $page_match && $enabled) {

    // Include the TypeKit code
    // Note that drupal_add_js does not allow for external scripts so we work around,
    // so we allow the user to choose.
    $method = variable_get('typekit_include_method', 'document_write');
    if ($method == 'document_write') {
      $script = '
        var typekitHost = (("https:" == document.location.protocol) ? "https://" : "http://");
        document.write(unescape("%3Cscript src=\'" + typekitHost + "use.typekit.com/' . check_plain($key) . '.js\' type=\'text/javascript\'%3E%3C/script%3E"));
        ';
      drupal_add_js($script, 'inline', 'header');
    }
    elseif ($method == 'drupal_set_html_head') {
      drupal_set_html_head('<script type="text/javascript" src="http://use.typekit.com/' . check_plain($key) . '.js"></script>');
    }

    // Initialization call
    drupal_add_js('try{Typekit.load();}catch(e){}', 'inline', 'header');
  }
}

Functions

Namesort descending Description
typekit_help Implementation of hook_help().
typekit_init Implementation of hook_init().
typekit_menu Implementation of hook_menu().
typekit_perm Implementation of hook_perm().