function add_to_head_preprocess_page in Add To Head 6
Implementation of hook_preprocess_page(). This is used to inject any code onto the appropriate pages.
File
- ./
add_to_head.module, line 87 - Add To Head allows abritrary insertion of code into the head of the page based on path selection.
Code
function add_to_head_preprocess_page(&$vars) {
$settings = variable_get('add_to_head_profiles', array());
$output = '';
foreach ($settings as $profile) {
if (empty($profile['paths'])) {
$page_match = TRUE;
}
else {
// NOTE: This code is "borrowed" from block_list().
$path = drupal_get_path_alias($_GET['q']);
// Compare with the internal and path alias (if any).
$page_match = drupal_match_path($path, $profile['paths']);
if ($path != $_GET['q']) {
$page_match = $page_match || drupal_match_path($_GET['q'], $profile['paths']);
}
// When $profile['path_visibility'] has a value of 0, the block is displayed on
// all pages except those listed in $block->pages. When set to 1, it
// is displayed only on those pages listed in $block->pages.
$page_match = !($profile['path_visibility'] xor $page_match);
}
if ($page_match) {
$output .= "\n\n" . $profile['code'];
}
}
if (!empty($output)) {
switch ($profile['scope']) {
case 'head':
drupal_set_html_head($output);
$vars['head'] = drupal_get_html_head();
break;
case 'styles':
case 'scripts':
$vars[$profile['scope']] .= $output;
break;
}
}
}