/** * Override or insert variables into the node templates. * * @param $vars * An array of variables to pass to the theme template. * @param $hook * The name of the template being rendered ("node" in this case.) */ function zen_preprocess_node(&$vars, $hook) { // Special classes for nodes $classes = array('node'); if ($vars['sticky']) { $classes[] = 'sticky'; } if (!$vars['status']) { $classes[] = 'node-unpublished'; $vars['unpublished'] = TRUE; } else { $vars['unpublished'] = FALSE; } if ($vars['uid'] && $vars['uid'] == $GLOBALS['user']->uid) { $classes[] = 'node-mine'; // Node is authored by current user. } if ($vars['teaser']) { $classes[] = 'node-teaser'; // Node is displayed as teaser. } // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc. $classes[] = zen_id_safe('node-type-' . $vars['type']); $vars['classes'] = implode(' ', $classes); // Concatenate with spaces }
/** * Override or insert variables into the page templates. * * @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 zen_preprocess_page(&$vars, $hook) { // Add an optional title to the end of the breadcrumb. if (theme_get_setting('zen_breadcrumb_title') && $vars['breadcrumb']) { $vars['breadcrumb'] = substr($vars['breadcrumb'], 0, -6) . $vars['title'] . '</div>'; } // Add conditional stylesheets. if (!module_exists('conditional_styles')) { $vars['styles'] .= $vars['conditional_styles'] = variable_get('conditional_styles_' . $GLOBALS['theme'], ''); } // Classes for body element. Allows advanced theming based on context // (home page, node of certain type, etc.) $body_classes = array($vars['body_classes']); if (!$vars['is_front']) { // Add unique classes for each page and website section $path = drupal_get_path_alias($_GET['q']); list($section, ) = explode('/', $path, 2); $body_classes[] = zen_id_safe('page-' . $path); $body_classes[] = zen_id_safe('section-' . $section); if (arg(0) == 'node') { if (arg(1) == 'add') { if ($section == 'node') { array_pop($body_classes); // Remove 'section-node' } $body_classes[] = 'section-node-add'; // Add 'section-node-add' } elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) { if ($section == 'node') { array_pop($body_classes); // Remove 'section-node' } $body_classes[] = 'section-node-' . arg(2); // Add 'section-node-edit' or 'section-node-delete' } } } if (theme_get_setting('zen_wireframes')) { $body_classes[] = 'with-wireframes'; // Optionally add the wireframes style. } $vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces }
/** * Override or insert PHPTemplate variables into the page templates. * * @param $vars * A sequential array of variables to pass to the theme template. */ function zen_preprocess_page(&$vars) { global $theme, $theme_key; // Allow sub-themes to have an ie.css or wireframes.css file. $vars['subtheme_directory'] = path_to_subtheme(); // These next lines add additional CSS files and redefine // the $css and $styles variables available to your page template if ($theme == $theme_key) { // If we're in the main theme // Load the stylesheet for a liquid layout if (theme_get_setting('zen_layout') == 'border-politics-liquid') { drupal_add_css($vars['directory'] . '/layout-liquid.css', 'theme', 'all'); } else { drupal_add_css($vars['directory'] . '/layout-fixed.css', 'theme', 'all'); } drupal_add_css($vars['directory'] . '/html-elements.css', 'theme', 'all'); drupal_add_css($vars['directory'] . '/tabs.css', 'theme', 'all'); drupal_add_css($vars['directory'] . '/zen.css', 'theme', 'all'); // Avoid IE5 bug that always loads @import print stylesheets $vars['head'] = zen_add_print_css($vars['directory'] . '/print.css'); } // Optionally add the block editing styles. if (theme_get_setting('zen_block_editing')) { drupal_add_css($vars['directory'] . '/block-editing.css', 'theme', 'all'); } // Optionally add the wireframes style. if (theme_get_setting('zen_wireframes')) { if ($vars['subtheme_directory'] && file_exists($vars['subtheme_directory'] . '/wireframes.css')) { drupal_add_css($vars['subtheme_directory'] . '/wireframes.css', 'theme', 'all'); } else { drupal_add_css($vars['directory'] . '/wireframes.css', 'theme', 'all'); } } $vars['css'] = drupal_add_css(); $vars['styles'] = drupal_get_css(); // Add an optional title to the end of the breadcrumb. if (theme_get_setting('zen_breadcrumb_title') && $vars['breadcrumb']) { $vars['breadcrumb'] = substr($vars['breadcrumb'], 0, -6) . $vars['title'] . '</div>'; } // Don't display empty help from node_help(). if ($vars['help'] == "<div class=\"help\"><p></p>\n</div>") { $vars['help'] = ''; } // Optionally disabled the primary and secondary links. if (!theme_get_setting('zen_primary_links')) { $vars['primary_links'] = ''; } if (!theme_get_setting('zen_secondary_links')) { $vars['secondary_links'] = ''; } // Classes for body element. Allows advanced theming based on context // (home page, node of certain type, etc.) $classes = array(); $classes[] = $vars['is_front'] ? 'front' : 'not-front'; $classes[] = $vars['logged_in'] ? 'logged-in' : 'not-logged-in'; if ($vars['node']->type) { // If on an individual node page, put the node type in the body classes $classes[] = 'node-type-' . $vars['node']->type; } if ($vars['sidebar_left'] && $vars['sidebar_right']) { $classes[] = 'two-sidebars'; } elseif ($vars['sidebar_left']) { $classes[] = 'one-sidebar sidebar-left'; } elseif ($vars['sidebar_right']) { $classes[] = 'one-sidebar sidebar-right'; } else { $classes[] = 'no-sidebars'; } if (!$vars['is_front']) { // Add unique class for each page. $path = drupal_get_path_alias($_GET['q']); $classes[] = zen_id_safe('page-' . $path); // Add unique class for each website section. list($section, ) = explode('/', $path, 2); if (arg(0) == 'node') { if (arg(1) == 'add') { $section = 'node-add'; } elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) { $section = 'node-' . arg(2); } } $classes[] = zen_id_safe('section-' . $section); } $vars['body_classes_array'] = $classes; $vars['body_classes'] = implode(' ', $classes); // Concatenate with spaces. }
/** * Override or insert PHPTemplate variables into the page templates. * * @param $vars * A sequential array of variables to pass to the theme template. * @param $hook * The name of the theme function being called ("page" in this case.) */ function zen_preprocess_page(&$vars, $hook) { global $theme; // These next lines add additional CSS files and redefine // the $css and $styles variables available to your page template if ($theme == 'zen') { // If we're in the main theme // Load the stylesheet for a liquid layout if (theme_get_setting('zen_layout') == 'border-politics-liquid') { drupal_add_css($vars['directory'] . '/layout-liquid.css', 'theme', 'all'); } else { drupal_add_css($vars['directory'] . '/layout-fixed.css', 'theme', 'all'); } } // Optionally add the block editing styles. if (theme_get_setting('zen_block_editing')) { drupal_add_css(path_to_zentheme() . '/block-editing.css', 'theme', 'all'); } // Optionally add the wireframes style. if (theme_get_setting('zen_wireframes')) { drupal_add_css(path_to_zentheme() . '/wireframes.css', 'theme', 'all'); } $vars['css'] = drupal_add_css(); $vars['styles'] = drupal_get_css(); // Allow sub-themes to have an ie.css file $vars['zentheme_directory'] = path_to_zentheme(); // Add an optional title to the end of the breadcrumb. if (theme_get_setting('zen_breadcrumb_title') && $vars['breadcrumb']) { $vars['breadcrumb'] = substr($vars['breadcrumb'], 0, -6) . $vars['title'] . '</div>'; } // Don't display empty help from node_help(). if ($vars['help'] == "<div class=\"help\"><p></p>\n</div>") { $vars['help'] = ''; } // Classes for body element. Allows advanced theming based on context // (home page, node of certain type, etc.) $body_classes = array($vars['body_classes']); if (!$vars['is_front']) { // Add unique classes for each page and website section $path = drupal_get_path_alias($_GET['q']); list($section, ) = explode('/', $path, 2); $body_classes[] = zen_id_safe('page-' . $path); $body_classes[] = zen_id_safe('section-' . $section); if (arg(0) == 'node') { if (arg(1) == 'add') { if ($section == 'node') { array_pop($body_classes); // Remove 'section-node' } $body_classes[] = 'section-node-add'; // Add 'section-node-add' } elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) { if ($section == 'node') { array_pop($body_classes); // Remove 'section-node' } $body_classes[] = 'section-node-' . arg(2); // Add 'section-node-edit' or 'section-node-delete' } } } $vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces }
/** * Override or insert variables into the page templates. * * @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 nys_preprocess_page(&$vars, $hook) { if ($node = menu_get_object()) { $variables['node'] = $node; } // RANDOM BACKGROUND FOR HEADER - change second number in the rand() function to the amount of background images there are to rotate randomly through srand((double) microtime() * 1000000); $random_number = rand(1, 5); $vars['random_bg'] = 'bg-' . $random_number; $vars['senator'] = nyss_senator(); $vars['senator_theme'] = $vars['senator']->field_theme[0]['value']; if ($vars['senator']->field_senators_district[0]['nid']) { $vars['district'] = node_load($vars['senator']->field_senators_district[0]['nid']); } // CUSTOM SEARCH PAGE TITLE if ($vars['template_files'][1] == 'page-search-nyss_search') { $vars['title'] = 'Senator Search: '; if ($vars['senator']->title != '') { $vars['title'] .= $vars['senator']->title; $vars['instructions'] = '<p>You are searching for content by Senator ' . $vars['senator']->title . '. If you are looking for content by a different senator, search from within their page on ' . l('this list', 'senators') . '.</p>'; } else { $vars['title'] .= 'No Senator Selected'; $vars['instructions'] = '<p>You are searching for senator content, but have not selected a senator. Pick a senator from ' . l('this list', 'senators') . ' and search from within their page.</p>'; } } // Build out the Party Affiliation tag, $party_affiliation_list, as seen in the Senator Header if (is_array($vars['senator']->field_party_affiliation)) { $parties = array(); foreach ($vars['senator']->field_party_affiliation as $party) { if ($party['value']) { $parties[] = $party['value']; } } $vars['party_affiliation_list'] = '(' . implode(', ', $parties) . ')'; } // Create the main navigation menu. if (count($vars['senator']->field_navigation)) { // If we're on content related to a Senator, we'll replace the primary links with a custom sub-menu. $vars['primary_links'] = array(); foreach ($vars['senator']->field_navigation as $count => $link) { // Make our custom URL replacements: [senator] with the senator's path, and [district] with the link to the district node. $link['url'] = str_replace('[senator]', $vars['senator']->field_path[0]['value'], $link['url']); if ($vars['senator']->field_senators_district[0]['nid']) { $link['url'] = str_replace('[district]', 'node/' . $vars['senator']->field_senators_district[0]['nid'], $link['url']); } // Add the link to the primary links array. $vars['primary_links']['menu-senator-' . $count] = array('title' => $link['title'], 'href' => $link['url']); } // Finally, add a link to the main senate home page. //$vars['primary_links']['menu-senator-'. $count + 1] = array('title' => t('NY Senate Homepage'), 'href' => '<front>', 'attributes' => array('id' => 'menu-senator-front-link')); // Render the menu as a standard 'links' menu. $vars['nyss_menu'] = theme('links', $primary_links); } else { // Render the default primary links using nice menu. $vars['nyss_menu'] = theme('nice_menu_primary_links'); } // Build the Section Header variable based on arg() or node type for the page being viewed if ($vars['senator'] == FALSE && ($vars['node']->type == 'blog' || arg(0) == 'blog')) { $vars['section_header'] = 'The New York Senate Blog'; } if ($vars['senator'] == TRUE && (arg(2) == 'blog' || $vars['node']->type == 'blog')) { $vars['section_header'] = $vars['senator']->title . '\'s Blog'; } // Classes for body element. Allows advanced theming based on context // (home page, node of certain type, etc.) $body_classes = array($vars['body_classes']); if (!$vars['is_front']) { // Add unique classes for each page and website section $path = drupal_get_path_alias($_GET['q']); list($section, ) = explode('/', $path, 2); $body_classes[] = zen_id_safe('page-' . $path); $body_classes[] = zen_id_safe('section-' . $section); if (arg(0) == 'node' && is_numeric(arg(1))) { $body_classes[] = 'full-node'; } if (arg(0) != 'node') { $body_classes[] = 'not-node'; } if (arg(0) == 'node') { if (arg(1) == 'add') { if ($section == 'node') { array_pop($body_classes); // Remove 'section-node' } $body_classes[] = 'section-node-add'; // Add 'section-node-add' } elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) { if ($section == 'node') { array_pop($body_classes); // Remove 'section-node' } $body_classes[] = 'section-node-' . arg(2); // Add 'section-node-edit' or 'section-node-delete' } } } if (theme_get_setting('zen_wireframes')) { $body_classes[] = 'with-wireframes'; // Optionally add the wireframes style. } if ($vars['senator'] == TRUE) { $body_classes[] = 'senator'; // Class for a senator } if ($vars['senator'] == FALSE) { $body_classes[] = 'not-senator'; // Class for a non-senator } if ($vars['senator'] == TRUE && arg(2) == 'blog') { $body_classes[] = 'senator_blog'; // Class for a senator's blog } $vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces if (!empty($vars['left_forms'])) { $vars['body_classes'] = str_replace('no-sidebars', 'one-sidebar sidebar-left', $vars['body_classes']); } }
/** * Override or insert variables into the page templates. * * @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 nys_preprocess_page(&$vars, $hook) { if ($node = menu_get_object()) { $vars['node'] = $node; } else { $vars['node'] = FALSE; } // RANDOM BACKGROUND FOR HEADER - change second number in the rand() function to the amount of background images there are to rotate randomly through $random_number = mt_rand(1, 5); $vars['random_bg'] = 'bg-' . $random_number; $vars['senator'] = context_get('nyss', 'senator'); $vars['senator_theme'] = ''; if ($vars['senator']) { $vars['senator_analytics'] = nyss_senator_analytics($vars['senator']->nid); if ($vars['senator']->field_status[0]['value']) { drupal_set_message(nyss_senator_inactive_message($vars['senator']), 'status'); $vars['messages'] .= theme('status_messages'); } if ($vars['senator']->field_status[0]['value'] != 'former') { $vars['senator_theme'] = $vars['senator']->field_theme[0]['value']; } else { $vars['senator_theme'] = 'grey'; } if ($vars['senator']->field_senators_district[0]['nid']) { $vars['district'] = node_load($vars['senator']->field_senators_district[0]['nid']); } } // CUSTOM SEARCH PAGE TITLE if (isset($vars['template_files'][1]) && $vars['template_files'][1] == 'page-search-nyss_search') { $vars['title'] = t('Senator Search: '); if ($vars['senator'] && $vars['senator']->title != '') { $vars['title'] .= $vars['senator']->title; $vars['instructions'] = '<p>' . t('You are searching for content by Senator !title. If you are looking for content by a different senator, search from within their page on !list.', array('!title' => $vars['senator']->title, '!list' => l(t('this list'), 'senators'))) . '</p>'; } else { $vars['title'] .= t('No Senator Selected'); $vars['instructions'] = '<p>' . t('You are searching for senator content, but have not selected a senator. Pick a senator from !list and search from within their page.', array('!list' => l(t('this list'), 'senators'))) . '</p>'; } } // Build out the Party Affiliation tag, $party_affiliation_list, as seen in the Senator Header if ($vars['senator'] && is_array($vars['senator']->field_party_affiliation)) { $parties = array(); foreach ($vars['senator']->field_party_affiliation as $party) { if ($party['value']) { $parties[] = $party['value']; } } $vars['party_affiliation_list'] = '(' . implode(', ', $parties) . ')'; } // Create the main navigation menu. if ($vars['senator'] && count($vars['senator']->field_navigation)) { $vars['nyss_menu'] = nyss_senator_build_menu($vars['senator']); } else { // Render the default primary links using nice menu. $vars['nyss_menu'] = theme('nyss_misc_primary_menu'); } $vars['nyss_footer_menu'] = theme('nyss_misc_footer_menu'); // Build the Section Header variable based on arg() or node type for the page being viewed if ($vars['senator'] == FALSE && arg(0) == 'blog') { $vars['section_header'] = t('The New York Senate Blog'); } if ($vars['senator'] == TRUE && (arg(2) == 'blog' || $vars['node'] && $vars['node']->type == 'blog')) { $vars['section_header'] = t('!title\'s Blog', array('!title' => $vars['senator']->title)); } // Classes for body element. Allows advanced theming based on context // (home page, node of certain type, etc.) $body_classes = array($vars['body_classes']); if (!$vars['is_front']) { // Add unique classes for each page and website section $path = drupal_get_path_alias($_GET['q']); list($section, ) = explode('/', $path, 2); $body_classes[] = 'no-sidebars'; $body_classes[] = zen_id_safe('page-' . $path); $body_classes[] = zen_id_safe('section-' . $section); if (arg(0) == 'node' && is_numeric(arg(1))) { $body_classes[] = 'full-node'; } if (arg(0) != 'node') { $body_classes[] = 'not-node'; } if (arg(0) == 'node') { if (arg(1) == 'add') { if ($section == 'node') { array_pop($body_classes); // Remove 'section-node' } $body_classes[] = 'section-node-add'; // Add 'section-node-add' } elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) { if ($section == 'node') { array_pop($body_classes); // Remove 'section-node' } $body_classes[] = 'section-node-' . arg(2); // Add 'section-node-edit' or 'section-node-delete' } } } if (theme_get_setting('zen_wireframes')) { $body_classes[] = 'with-wireframes'; // Optionally add the wireframes style. } if ($vars['senator'] == TRUE) { $body_classes[] = 'senator'; // Class for a senator $vars['senator_name'] = l($vars['senator']->title . nyss_senator_status_for_title($vars['senator']), $vars['senator']->path); } if ($vars['senator'] == FALSE) { $body_classes[] = 'not-senator'; // Class for a non-senator } if ($vars['senator'] == TRUE && arg(2) == 'blog') { $body_classes[] = 'senator_blog'; // Class for a senator's blog } $vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces if (!empty($vars['left_forms']) || !empty($vars['left'])) { $vars['body_classes'] = str_replace('no-sidebars', 'one-sidebar sidebar-left', $vars['body_classes']); } }
/** * Intercept template variables * * @param $hook * The name of the theme function being executed * @param $vars * A sequential array of variables passed to the theme function. */ function _phptemplate_variables($hook, $vars = array()) { // get the currently logged in user global $user; // set a new $is_admin variable // this is determined by looking at the currently logged in user and seeing if they are in the role 'admin' // the 'admin' will need to have been created manually for this to work // this variable is available to all templates $vars['is_admin'] = in_array('admin', $user->roles); switch ($hook) { // Send a new variable, $logged_in, to page.tpl.php to tell us if the current user is logged in or out. case 'page': global $theme, $theme_key; // if we're in the main theme if ($theme == $theme_key) { // These next lines add additional CSS files and redefine // the $css and $styles variables available to your page template // We had previously used @import declarations in the css files, // but these are incompatible with the CSS caching in Drupal 5 drupal_add_css($vars['directory'] . '/layout.css', 'theme', 'all'); drupal_add_css($vars['directory'] . '/icons.css', 'theme', 'all'); drupal_add_css($vars['directory'] . '/zen.css', 'theme', 'all'); $vars['css'] = drupal_add_css($vars['directory'] . '/print.css', 'theme', 'print'); $vars['styles'] = drupal_get_css(); } // An anonymous user has a user id of zero. if ($user->uid > 0) { // The user is logged in. $vars['logged_in'] = TRUE; } else { // The user has logged out. $vars['logged_in'] = FALSE; } $body_classes = array(); // classes for body element // allows advanced theming based on context (home page, node of certain type, etc.) $body_classes[] = $vars['is_front'] ? 'front' : 'not-front'; $body_classes[] = $vars['logged_in'] ? 'logged-in' : 'not-logged-in'; if ($vars['node']->type) { // if on an individual node page, put the node type in the body classes $body_classes[] = 'ntype-' . zen_id_safe($vars['node']->type); } switch (TRUE) { case $vars['sidebar_left'] && $vars['sidebar_right']: $body_classes[] = 'both-sidebars'; break; case $vars['sidebar_left']: $body_classes[] = 'sidebar-left'; break; case $vars['sidebar_right']: $body_classes[] = 'sidebar-right'; break; } // implode with spaces $vars['body_classes'] = implode(' ', $body_classes); break; case 'node': if ($vars['submitted']) { // we redefine the format for submitted // adding macrotags and $vars['submitted'] = t('Posted <abbr class="created" title="!microdate">@date</abbr> by !username', array('!username' => theme('username', $vars['node']), '@date' => format_date($vars['node']->created, 'custom', "F jS, Y"), '!microdate' => format_date($vars['node']->created, 'custom', "Y-m-d\\TH:i:sO"))); } // special classes for nodes $node_classes = array('node'); if ($vars['sticky']) { $node_classes[] = 'sticky'; } if (!$vars['node']->status) { $node_classes[] = 'node-unpublished'; } if ($vars['node']->uid && $vars['node']->uid == $user->uid) { // node is authored by current user $node_classes[] = 'node-mine'; } // class for node type: "ntype-page", "ntype-story", "ntype-my-custom-type", etc. $node_classes[] = 'ntype-' . zen_id_safe($vars['node']->type); // implode with spaces $vars['node_classes'] = implode(' ', $node_classes); break; case 'comment': // we load the node object that the current comment is attached to $node = node_load($vars['comment']->nid); // if the author of this comment is equal to the author of the node, we set a variable // then in our theme we can theme this comment differently to stand out $vars['author_comment'] = $vars['comment']->uid == $node->uid ? TRUE : FALSE; $comment_classes = array('comment'); // odd/even handling static $comment_odd = TRUE; $comment_classes[] = $comment_odd ? 'odd' : 'even'; $comment_odd = !$comment_odd; if ($vars['comment']->status == COMMENT_NOT_PUBLISHED) { $comment_classes[] = 'comment-unpublished'; } if ($vars['author_comment']) { // comment is by the node author $comment_classes[] = 'comment-by-author'; } if ($vars['comment']->uid == 0) { // comment is by an anonymous user $comment_classes[] = 'comment-by-anon'; } if ($user->uid && $vars['comment']->uid == $user->uid) { // comment was posted by current user $comment_classes[] = 'comment-mine'; } $vars['comment_classes'] = implode(' ', $comment_classes); // if comment subjects are disabled, don't display 'em if (variable_get('comment_subject_field', 1) == 0) { $vars['title'] = ''; } break; } // allow subtheme to add/alter variables if (function_exists('zen_variables')) { $vars = zen_variables($hook, $vars); } return $vars; }