/** * Implementing hook_process_page() */ function jjamerson_lc_preprocess_page(&$variables) { $base_theme = 'jjamerson'; global $base_url, $base_path, $user; global $_bss_section_information; if (isset($_bss_section_information['tid'])) { $site_section_tid = $_bss_section_information['tid']; } if (isset($node['language'])) { $lang = $node['language']; } else { $lang = 'und'; } // Set a current node variable, because otherwise actions that rely on field data will affect // both the draft & published version of the page. if (function_exists('workbench_moderation_node_current_load')) { if (substr($_GET['q'], -strlen('/draft')) === '/draft') { $current_node = workbench_moderation_node_current_load($variables['node']); } else { $current_node = $variables['node']; } } else { $current_node = $variables['node']; } // Check to see if this is a stand-alone site section. First we fetch the site section ID, if // it's available (if the section menu block exists, then it should be available): if (isset($variables['page']['sidebar_first']['berklee_site_section_menu']['#block']->tid)) { $site_section = taxonomy_term_load($site_section_tid); $section_parent_link = drupal_get_path_alias('node/' . $_bss_section_information['parent_node_id']); } /* If this is a development environment, rebuild the minified JS file. For the automatic JS minification to occur: 1. PHP needs write permissions for /js/jjamerson_lc.min.js 2. The development_environment variable needs to be defined. You can do this either in a local settings file (e.g. settings.local.php) or via a drush command: drush vset development_environment 1 */ $dev_env = variable_get('development_environment'); if ($dev_env == 1) { //require_once drupal_get_path('theme', $base_theme) . '/third-party/class.JavaScriptPacker.php'; $source = ''; if ($directory_handle = opendir(dirname(__FILE__) . '/js/source')) { while (($file = readdir($directory_handle)) !== false) { // Only load JS extensions. This prevents issues with the packer loading .DS_Store files, at the least. if (substr($file, -3) === '.js') { $source .= file_get_contents(dirname(__FILE__) . '/js/source/' . $file) . "\n"; } } closedir($directory_handle); } $packer = new JavaScriptPacker($source, 'None', true, false); $packed = $packer->pack(); file_put_contents(dirname(__FILE__) . '/js/jjamerson_lc.min.js', $packed); } elseif ($dev_env == 2) { /* Alternatively, just add each JS file via drupal_add_js. Better for hunting down errors because the console will tell you the offending file & line number: */ if ($directory_handle = opendir(dirname(__FILE__) . '/js/source')) { while (($file = readdir($directory_handle)) !== false) { if (preg_match('/.js$/', $file)) { drupal_add_js(path_to_theme() . '/js/source/' . $file); } } closedir($directory_handle); } } if (drupal_is_front_page()) { drupal_add_js('//maps.googleapis.com/maps/api/js?libraries=geometry', array('type' => 'external')); // VideoJS components: drupal_add_js('//vjs.zencdn.net/4.12/video.js', array('type' => 'external', 'scope' => 'footer')); drupal_add_css('//vjs.zencdn.net/4.12/video-js.css', array('type' => 'external')); } /* Allows you to use node-type, and node ID base page templates: */ if (!empty($variables['node'])) { $variables['theme_hook_suggestions'][] = 'page__' . $variables['node']->type; $variables['theme_hook_suggestions'][] = 'page__' . $variables['node']->vid; } elseif (drupal_get_http_header('status')) { $variables['theme_hook_suggestions'][] = 'page__404'; } /* Place logo: */ if (isset($_GET['render-only']) && isset($_GET['unlink-logo'])) { $logo = "<img src='{$variables['logo']}' alt='Berklee logo' id='logo'>"; } else { $logo = l("<img src='{$variables['logo']}' alt='Berklee Logo' title='Berklee Homepage'>", $base_url . $base_path, array('attributes' => array('id' => 'logo', 'rel' => 'home', 'title' => t('Home'), 'tabindex' => '1'), 'html' => TRUE)); } $logo_array = array('logo' => array('#markup' => $logo, '#type' => 'markup', '#weight' => -100)); $share_links = array('share_links' => array('#markup' => '<div class="share-holder"> <!-- AddThis Button BEGIN --> <div class="addthis_toolbox addthis_default_style "> <a class="addthis_button_facebook_like at300b" fb:like:layout="button_count"></a> <a class="addthis_counter addthis_pill_style"></a> </div> <script type="text/javascript">var addthis_config = {"data_track_addressbar":false};</script> <script type="text/javascript" src="//s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4fbe4da869545ef5"></script> <!-- AddThis Button END --> </div>', '#type' => 'markup', '#weight' => 1001)); if (isset($variables['page']['header']) && is_array($variables['page']['header'])) { $variables['page']['header'] = $logo_array + $variables['page']['header'] + $share_links; } /* Add a pretitle page variable, primarily for the sponsorship field */ $variables['pretitle'] = ''; if ($variables['page']['#type'] === 'page' && isset($variables['node'])) { if (isset($variables['node']->field_sponsorship) && count($variables['node']->field_sponsorship)) { $variables['pretitle'] = $variables['node']->field_sponsorship[$lang][0]['safe_value']; $variables['pretitle'] = "<span class='pretitle'>{$variables['pretitle']}</span>"; } } /* Add a subtitle page variable */ $variables['subtitle'] = ''; if (isset($variables['node']) && $variables['node']->type === 'bt_cover') { $variables['pretitle'] = "<span class='pretitle previous-link'>"; $variables['pretitle'] .= "<a href='/alumni'>Alumni Affairs</a>/"; $variables['pretitle'] .= "<a href='/berklee-today/archives'>See All BT Issues</a>"; $variables['pretitle'] .= "</span>"; $variables['subtitle'] = "<span class='subtitle'>A Magazine for Contemporary Music and Musicians</span>"; } if (isset($variables['node']) && $variables['node']->type === 'bt_article') { if (isset($variables['page']['sidebar_first']['berklee_site_section_breadcrumb'])) { $new_crumb = '<ul class="breadcrumb"><li><a href="/alumni">Alumni Affairs</a></li><li><a href="/berklee-today/archives">All BT Issues</a></li></ul>'; $variables['page']['sidebar_first']['berklee_site_section_breadcrumb']['#markup'] = $new_crumb; } } if (isset($variables['theme_hook_suggestions'][0]) && $variables['theme_hook_suggestions'][0] == 'page__directory') { $variables['title'] = 'Berklee Directory'; $variables['subtitle'] = "<span class='subtitle'>Faculty, Staff, and Departments</span>"; } /* Return unformatted content if notemplate variable is defined */ if (isset($_GET['content-only'])) { unset($variables['page']['header']); unset($variables['page']['top_nav']); unset($variables['page']['offscreen_sidebar']); unset($variables['page']['offscreen_overlay']); unset($variables['page']['sidebar_first']); unset($variables['page']['sidebar_second']); unset($variables['page']['content']['berklee_info_block_berklee_info_block']); unset($variables['page']['page_top']); unset($variables['page']['page_bottom']); unset($variables['page']['footer']); /* check if this is an ajax request. if so, return just the page content: */ if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { echo drupal_render($variables['page']['content']); echo drupal_render($variables['page']['content_bottom']); die; } } // Check to see if this page can be used as a lead page: if (isset($site_section->field_base_url) && isset($site_section->field_banner_image_large[$lang][0]['uri']) && $site_section->description) { $site_section_home = $site_section->field_base_url[$lang][0]['value']; if (drupal_get_path_alias() == $site_section_home) { $header_image = $site_section->field_banner_image_large[$lang][0]['uri']; $header_image_src = file_create_url($header_image); // store the image source in an array element in the header, to be used by marshall_preprocess_region() // to set the background image: $variables['page']['header']['#lead-page']['header-image'] = $header_image_src; $summary = $site_section->description; $header_copy = "<div class='lead-page-intro'><h1>{$site_section->name}</h1><div class='lead-page-summary'>{$summary}</div></div>"; $header_copy_array = array('lead-page-intro' => array('#markup' => $header_copy, '#type' => 'markup', '#weight' => -100)); $variables['page']['header'] += $header_copy_array; } } }
/** * Implementing hook_process_page() */ function jjamerson_preprocess_page(&$variables) { //dsm($variables); global $base_url, $base_path, $user; if (isset($node['language'])) { $lang = $node['language']; } else { $lang = 'und'; } // Set a current node variable, because otherwise actions that rely on field data will affect // both the draft & published version of the page. if (function_exists('workbench_moderation_node_current_load')) { if (substr($_GET['q'], -strlen('/draft')) === '/draft') { $current_node = workbench_moderation_node_current_load($variables['node']); } else { $current_node = $variables['node']; } } else { $current_node = $variables['node']; } /* Return unformatted content if notemplate variable is defined */ if (isset($_GET['notemplate']) && $_GET['notemplate'] === '1') { drupal_static_reset('drupal_add_css'); drupal_static_reset('drupal_add_js'); echo render($variables['page']['content']['system_main']['main']); die; // Ich sterbe. } /* Hide tabs from users that aren't included in workbench moderation */ if (module_exists('workbench_moderation') && !user_access('view moderation history')) { $variables['tabs'] = array(); } /* If this is a development environment, rebuild the minified JS file. For the automatic JS minification to occur: 1. PHP needs write permissions for /js/jjamerson.min.js 2. The development_environment variable needs to be defined. You can do this either in a local settings file (e.g. settings.local.php) or via a drush command: drush vset development_environment 1 */ $dev_env = variable_get('development_environment'); if ($dev_env == 1) { require dirname(__FILE__) . '/third-party/class.JavaScriptPacker.php'; $source = ''; if ($directory_handle = opendir(dirname(__FILE__) . '/js/source')) { while (($file = readdir($directory_handle)) !== false) { // Only load JS extensions. This prevents issues with the packer loading .DS_Store files, at the least. if (substr($file, -3) === '.js') { $source .= file_get_contents(dirname(__FILE__) . '/js/source/' . $file) . "\n"; } } closedir($directory_handle); } $packer = new JavaScriptPacker($source, 'None', true, false); $packed = $packer->pack(); file_put_contents(dirname(__FILE__) . '/js/jjamerson.min.js', $packed); } elseif ($dev_env == 2) { /* Alternatively, just add each JS file via drupal_add_js. Better for hunting down errors because the console will tell you the offending file & line number: */ if ($directory_handle = opendir(dirname(__FILE__) . '/js/source')) { while (($file = readdir($directory_handle)) !== false) { if (preg_match('/.js$/', $file)) { drupal_add_js(drupal_get_path('theme', 'jjamerson') . '/js/source/' . $file); } } closedir($directory_handle); } } //drupal_add_css( path_to_theme() . '/third-party/bootstrap/bootstrap-combined.no-icons.min.css'); drupal_add_css(drupal_get_path('theme', 'jjamerson') . '/fonts/font-awesome/css/font-awesome.min.css'); drupal_add_js(drupal_get_path('theme', 'jjamerson') . '/third-party/html5shiv-printshiv.js'); drupal_add_js(drupal_get_path('theme', 'jjamerson') . '/third-party/respond.min.js', array('scope' => 'footer')); drupal_add_js(drupal_get_path('theme', 'jjamerson') . '/third-party/soundcloud-api.js', array('scrope' => 'footer')); drupal_add_js(drupal_get_path('theme', 'jjamerson') . '/third-party/jquery.dataTables.min.js'); /* Allows you to use node-type, and node ID base page templates: */ if (!empty($variables['node'])) { $variables['theme_hook_suggestions'][] = 'page__' . $variables['node']->type; $variables['theme_hook_suggestions'][] = 'page__' . $variables['node']->vid; } elseif (drupal_get_http_header('status')) { $variables['theme_hook_suggestions'][] = 'page__404'; } /* Add a pretitle page variable */ $variables['pretitle'] = ''; if ($variables['page']['#type'] === 'page' && isset($variables['node'])) { if (isset($variables['node']->field_pretitle) && count($variables['node']->field_pretitle)) { $variables['pretitle'] = $variables['node']->field_pretitle[$lang][0]['safe_value']; $variables['pretitle'] = "<span class='pretitle'>{$variables['pretitle']}</span>"; } } /* Return unformatted content if notemplate variable is defined */ if (isset($_GET['content-only'])) { unset($variables['page']['header']); unset($variables['page']['sidebar_first']); unset($variables['page']['sidebar_second']); unset($variables['page']['content']['berklee_info_block_berklee_info_block']); unset($variables['page']['page_top']); unset($variables['page']['page_bottom']); unset($variables['page']['footer']); /* check if this is an ajax request. if so, return just the page content: */ if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { echo drupal_render($variables['page']['content']); echo drupal_render($variables['page']['content_bottom']); die; } } if (isset($_GET['render-only'])) { $renderable_regions = explode('--', $_GET['render-only']); foreach ($variables['page'] as $page_array_item => $bla) { if (strpos($page_array_item, '#') !== 0) { $unset_region = true; foreach ($renderable_regions as $region_name) { if ($region_name === $page_array_item) { $unset_region = false; } } if ($unset_region) { unset($variables['page'][$page_array_item]); } } } if (!in_array('tabs', $renderable_regions)) { unset($variables['tabs']); } if (!in_array('content', $renderable_regions)) { $variables['title'] = ''; unset($variables['page']['header']['share_links']); } } }
/** * Override or insert variables into the page template. * * @param $vars * An array of variables to pass to the theme template. * @param $hook * The name of the template being rendered ("page" in this case.) */ function unity_lab_preprocess_page(&$vars) { if (isset($vars['node'])) { $path = $_GET['q']; if (substr($path, -6) === '/draft') { $vars['node'] = workbench_moderation_node_current_load($vars['node']); } // dpm($wbm); $vars['theme_hook_suggestions'][] = 'page__sections'; $vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type; $vars['theme_hook_suggestions'][] = 'page__node__' . $vars['node']->nid; //get hero section from node; $hero = field_get_items('node', $vars['node'], 'field_hero_section'); if ($hero) { $heroRender = field_view_value('node', $vars['node'], 'field_hero_section', $hero[0]); $vars['page']['banner'] = $heroRender; } else { //if there is no hero defined, then clear banner. $vars['page']['banner'] = ''; } $introduction = field_get_items('node', $vars['node'], 'field_introduction'); if (!empty($introduction)) { $introduction = field_view_value('node', $vars['node'], 'field_introduction', $introduction[0]); $vars['page']['introduction'] = render($introduction); } else { $vars['page']['introduction'] = ''; } $audDisplay = array('label' => 'hidden', 'type' => 'textformatter_list', 'settings' => array('textformatter_class' => 'textformatter-list', 'textformatter_comma_and' => 1, 'textformatter_comma_full_stop' => 0, 'textformatter_comma_override' => 0, 'textformatter_comma_tag' => '', 'textformatter_contrib' => array(), 'textformatter_separator_custom' => '', 'textformatter_separator_custom_class' => '', 'textformatter_separator_custom_tag' => 'span', 'textformatter_term_plain' => 1, 'textformatter_type' => 'comma')); $audience = field_get_items('node', $vars['node'], 'field_audience'); $audience = field_view_field('node', $vars['node'], 'field_audience', $audDisplay); if (!empty($audience)) { $audience = render($audience); $vars['page']['introduction'] .= '<p>Audience: ' . $audience . '</p>'; } /* $audDisplay = array('type'=>'plaintext'); if(!empty($audience)) { $audienceString = ''; foreach($audience as $audienceItem) { $audienceItem = field_view_value('node', $vars['node'], 'field_audience', $audienceItem, $audDisplay); dpm($audienceItem); $audienceString .= render($audienceItem) . ", "; } $audienceString = rtrim($audienceString, ', '); */ // $vars['page']['introduction'] .= '<p><strong>Audience:</strong> ' . $audienceString . '</p>'; // } $jumpMenu = field_get_items('node', $vars['node'], 'field_jump_menu'); if (!empty($jumpMenu)) { $vars['page']['jump-menu']['type'] = $jumpMenu[0]['value']; unity_lab_jump_menu($vars); } else { $vars['page']['jump-menu'] = ''; } } else { if (!empty($vars['page']['main_prefix']) && !empty($vars['page']['main_postfix'])) { $vars['theme_hook_suggestions'][] = 'page__three_col'; } else { if (!empty($vars['page']['main_postfix'])) { $vars['theme_hook_suggestions'][] = 'page__postfix'; } else { if (!empty($vars['page']['main_prefix'])) { $vars['theme_hook_suggestions'][] = 'page__prefix'; } else { $vars['theme_hook_suggestions'][] = 'page'; } } } } }
<?php global $language; if (!($language_prefix = $language->prefix)) { $language_prefix = 'und'; } if (function_exists('workbench_moderation_node_current_load')) { if (substr($_GET['q'], -strlen('/draft')) === '/draft') { $current_node = workbench_moderation_node_current_load($node); } else { $current_node = $node; } } $nid = $node->nid; // Setup the stripes region manually, if it doesn't already exist if (count($page['stripes']) == 0) { $page['stripes'] = array('#sorted' => TRUE, '#theme_wrappers' => array(0 => 'region'), '#region' => 'stripes'); } // Wrap HH "block" field content with their respective CSS classes (from the "Block Class" field) and // move blocks with the class 'width-full' to the stripes region for ($i = 0; $i < count($current_node->field_block_class[$language_prefix]); $i++) { if (isset($current_node->field_block_class[$language_prefix][$i])) { $block_classes = $current_node->field_block_class[$language_prefix][$i]['safe_value']; if (strpos($block_classes, 'width-full') > -1) { $page['stripes']["field_block_{$i}"] = $page['content']['system_main']['nodes'][$nid]['field_block'][$i]; $page['stripes']["field_block_{$i}"]['#markup'] = "<div class='{$block_classes}'>" . $page['content']['system_main']['nodes'][$nid]['field_block'][$i]['#markup'] . "</div>"; unset($page['content']['system_main']['nodes'][$nid]['field_block'][$i]); } else { $page['content']['system_main']['nodes'][$nid]['field_block'][$i]['#markup'] = "<div class='{$block_classes}'>" . $page['content']['system_main']['nodes'][$nid]['field_block'][$i]['#markup'] . "</div>"; } } else {