function cpaglobal_preprocess_page(&$vars) {
$vars['styles'] = drupal_get_css_custom();
$vars['scripts'] = drupal_get_js_custom();
}
function drupal_get_css_custom($css = NULL) {
$output = ”;
if (!isset($css)) {
$css = drupal_add_css();
}
$url = explode( “/”, $_REQUEST['q'] );
if( $url[0] == ‘ip-review-online’ )
{
$css['all']['theme'][drupal_get_path('theme', 'cpaglobal').'/ipreview.css'] = 1;
$css['all']['theme'][drupal_get_path('theme', 'cpaglobal').'/articles.css'] = 1;
$css['all']['theme'][drupal_get_path('theme', 'cpaglobal').'/dropdown_ipreview.css'] = 1;
}
else
{
$css['all']['theme'][drupal_get_path('theme', 'cpaglobal').'/dropdown.css'] = 1;
}
$no_module_preprocess = ”;
$no_theme_preprocess = ”;
$preprocess_css = (variable_get(‘preprocess_css’, FALSE) && (!defined(‘MAINTENANCE_MODE’) || MAINTENANCE_MODE != ‘update’));
$directory = file_directory_path();
$is_writable = is_dir($directory) && is_writable($directory);
// A dummy query-string is added to filenames, to gain control over
// browser-caching. The string changes on every update or full cache
// flush, forcing browsers to load a new copy of the files, as the
// URL changed.
$query_string = ‘?’. substr(variable_get(‘css_js_query_string’, ’0′), 0, 1);
foreach ($css as $media => $types) {
// If CSS preprocessing is off, we still need to output the styles.
// Additionally, go through any remaining styles if CSS preprocessing is on and output the non-cached ones.
foreach ($types as $type => $files) {
if ($type == ‘module’) {
// Setup theme overrides for module styles.
$theme_styles = array();
foreach (array_keys($css[$media]['theme']) as $theme_style) {
$theme_styles[] = basename($theme_style);
}
}
foreach ($types[$type] as $file => $preprocess) {
// If the theme supplies its own style using the name of the module style, skip its inclusion.
// This includes any RTL styles associated with its main LTR counterpart.
if ($type == ‘module’ && in_array(str_replace(‘-rtl.css’, ‘.css’, basename($file)), $theme_styles)) {
// Unset the file to prevent its inclusion when CSS aggregation is enabled.
unset($types[$type][$file]);
continue;
}
// Only include the stylesheet if it exists.
if (file_exists($file)) {
if (!$preprocess || !($is_writable && $preprocess_css)) {
// If a CSS file is not to be preprocessed and it’s a module CSS file, it needs to *always* appear at the *top*,
// regardless of whether preprocessing is on or off.
if (!$preprocess && $type == ‘module’) {
$no_module_preprocess .= ‘<link type=”text/css” rel=”stylesheet” media=”‘. $media .’” href=”‘. base_path() . $file . $query_string .’” />’.”\n”;
}
// If a CSS file is not to be preprocessed and it’s a theme CSS file, it needs to *always* appear at the *bottom*,
// regardless of whether preprocessing is on or off.
else if (!$preprocess && $type == ‘theme’) {
$no_theme_preprocess .= ‘<link type=”text/css” rel=”stylesheet” media=”‘. $media .’” href=”‘. base_path() . $file . $query_string .’” />’.”\n”;
}
else {
$output .= ‘<link type=”text/css” rel=”stylesheet” media=”‘. $media .’” href=”‘. base_path() . $file . $query_string .’” />’.”\n”;
}
}
}
}
}
if ($is_writable && $preprocess_css) {
$filename = md5(serialize($types) . $query_string) .’.css’;
$preprocess_file = drupal_build_css_cache($types, $filename);
$output .= ‘<link type=”text/css” rel=”stylesheet” media=”‘. $media .’” href=”‘. base_path() . $preprocess_file .’” />’.”\n”;
}
}
return $no_module_preprocess . $output . $no_theme_preprocess;
}
function drupal_get_js_custom($scope = ‘header’, $javascript = NULL) {
if ((!defined(‘MAINTENANCE_MODE’) || MAINTENANCE_MODE != ‘update’) && function_exists(‘locale_update_js_files’)) {
locale_update_js_files();
}
if (!isset($javascript)) {
$javascript = drupal_add_js(NULL, NULL, $scope);
}
if (empty($javascript)) {
return ”;
}
$output = ”;
$preprocessed = ”;
$no_preprocess = array(‘core’ => ”, ‘module’ => ”, ‘theme’ => ”);
$files = array();
$preprocess_js = (variable_get(‘preprocess_js’, FALSE) && (!defined(‘MAINTENANCE_MODE’) || MAINTENANCE_MODE != ‘update’));
$directory = file_directory_path();
$is_writable = is_dir($directory) && is_writable($directory);
// A dummy query-string is added to filenames, to gain control over
// browser-caching. The string changes on every update or full cache
// flush, forcing browsers to load a new copy of the files, as the
// URL changed. Files that should not be cached (see drupal_add_js())
// get time() as query-string instead, to enforce reload on every
// page request.
$query_string = ‘?’. substr(variable_get(‘css_js_query_string’, ’0′), 0, 1);
// For inline Javascript to validate as XHTML, all Javascript containing
// XHTML needs to be wrapped in CDATA. To make that backwards compatible
// with HTML 4, we need to comment out the CDATA-tag.
$embed_prefix = “\n<!–//–><![CDATA[//><!--\n";
$embed_suffix = "\n//--><!]]>\n”;
foreach ($javascript as $type => $data) {
if (!$data) continue;
switch ($type) {
case ‘setting’:
$output .= ‘<script type=”text/javascript”>’ . $embed_prefix . ‘jQuery.extend(Drupal.settings, ‘ . drupal_to_js(call_user_func_array(‘array_merge_recursive’, $data)) . “);” . $embed_suffix . “</script>\n”;
break;
case ‘inline’:
foreach ($data as $info) {
$output .= ‘<script type=”text/javascript”‘ . ($info['defer'] ? ‘ defer=”defer”‘ : ”) . ‘>’ . $embed_prefix . $info['code'] . $embed_suffix . “</script>\n”;
}
break;
default:
// If JS preprocessing is off, we still need to output the scripts.
// Additionally, go through any remaining scripts if JS preprocessing is on and output the non-cached ones.
foreach ($data as $path => $info) {
$path_parts = explode(‘/’, $path);
if (in_array(“wysiwyg”, $path_parts)) $info['preprocess'] = ”;
if (!$info['preprocess'] || !$is_writable || !$preprocess_js) {
$no_preprocess[$type] .= ‘<script type=”text/javascript”‘. ($info['defer'] ? ‘ defer=”defer”‘ : ”) .’ src=”‘. base_path() . $path . ($info['cache'] ? $query_string : ‘?’. time()) .”\”></script>\n”;
}
else {
$files[$path] = $info;
}
}
}
}
// Aggregate any remaining JS files that haven’t already been output.
if ($is_writable && $preprocess_js && count($files) > 0) {
$filename = md5(serialize($files) . $query_string) .’.js’;
$preprocess_file = drupal_build_js_cache($files, $filename);
$preprocessed .= ‘<script type=”text/javascript” src=”‘. base_path() . $preprocess_file .’”></script>’.”\n”;
}
// Keep the order of JS files consistent as some are preprocessed and others are not.
// Make sure any inline or JS setting variables appear last after libraries have loaded.
$output = $preprocessed . implode(”, $no_preprocess) . $output;
return $output;
}