function typekit_init in Typekit 6
Implementation of hook_init().
File
- ./
typekit.module, line 50 - Main module file for typekit module
Code
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');
}
}