array( 'template' => 'node' ), 'oxymoron_comment' => array( 'template' => 'comment' ), 'oxymoron_box' => array( 'template' => 'box' ), 'oxymoron_block' => array( 'template' => 'block' ), 'oxymoron_maintenance_page' => array( 'template' => 'maintenance_page' ), 'oxymoron_search-theme-form' => array( 'template' => 'search-theme-form' ), 'render_primary_links' => array( 'arguments' => array('links' => NULL) ), ); } // We use this to inject a proper page suggestion template for issue nodes. // See http://www.ajaxhacking.com/156/changing_pagetpl_based_on_node_type function oxymoron_preprocess(&$vars, $hook) { switch ($hook) { case 'page': // Add a content-type page template in second to last. if ('node' == arg(0)) { $node_template = array_pop($vars['template_files']); $vars['template_files'][] = 'page-'. $vars['node']->type; $vars['template_files'][] = $node_template; } break; } return $vars; } /** * Implementation of hook preporcess_page(). * Used for intercepting & adding of variables. * @return unknown_type */ function oxymoron_preprocess_page(&$vars) { // Send a new variable, $logged_in, to page.tpl.php to tell us if the current user is logged in or out. // get the currently logged in user global $user; $vars['user'] = $user; $vars['logged_in'] = $user->uid > 0; $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) { $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); // This will show the menu blocks on an 404 page // Only does the check if required if (!$vars['show_blocks']) { global $theme; $regions = system_region_list($theme); foreach (array_keys($regions) as $region) { // Only set left and right regions // Drupal core sets the other blocks already // IMHO this shows a real lack of design considerations for leaving these out! if ($region == 'left' || $region == 'right') { $blocks = theme('blocks', $region); if (isset($variables[$region])) { $vars[$region] .= $blocks; } else { $vars[$region] = $blocks; } } } } // Now define node type-specific variables by calling their own preprocess functions (if they exist) $function = 'oxymoron_preprocess_page'.'_'. $vars['node']->type; if (function_exists($function)) { $function(&$vars); } } function oxymoron_preprocess_page_issue(&$vars) { $foo = 'bar'; $vars['issue_header'] = $vars['node']->issue_header; } /** * Implementation of hook preporcess_node(). * Used for intercepting & adding of variables. * @return unknown_type */ function oxymoron_preprocess_node(&$vars) { // 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' $vars['is_admin'] = in_array('admin', $user->roles); $node_classes = array('node'); if ($vars['sticky']) { $node_classes[] = 'sticky'; } if (!$vars['node']->status) { $node_classes[] = 'node-unpublished'; } $node_classes[] = 'ntype-'. zen_id_safe($vars['node']->type); // implode with spaces $vars['node_classes'] = implode(' ', $node_classes); } /** * Implementation of hook preporcess_comment(). * Used for intercepting & adding of variables. * @return unknown_type */ function oxymoron_preprocess_comment(&$vars, $links = 0) { // 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 = $vars['comment']; $vars['author'] = theme('username', $comment); $vars['comment'] = $comment; $vars['content'] = $comment->comment; $vars['date'] = format_date($comment->timestamp); //-------------------------------------------------------------------------- // In order to remove the 'reply' link, it's necessary to get them again as // an array. By the time this function is called, they have already been // rendered as HTML. if (isset($links)) { $link_array = module_invoke_all('link', 'comment', $comment); $vars['links'] = theme('links', $link_array, array('class' => 'links inline')); } else { $vars['links'] = ''; } $vars['new'] = $comment->new ? t('new') : ''; $vars['picture'] = theme_get_setting('toggle_comment_user_picture') ? theme('user_picture', $comment) : ''; $vars['submitted'] = t('Submitted by !a on @b.', array('!a' => theme('username', $comment), '@b' => format_date($comment->timestamp))); $vars['title'] = l($comment->subject, $_GET['q'], array('fragment' => "comment-$comment->cid")); // from comment.module: // l($comment->subject, comment_node_url() .'/'. $comment->cid, array('fragment' => "comment-$comment->cid")) } /** * Theming for the "maintenance page". */ function oxymoron_preprocess_maintenance_page(&$vars) { $vars['head_title'] = "Maintenance Page"; $vars['title'] = "Maintenance Page"; $vars['styles'] = ''; $vars['picture'] = theme_get_setting('toggle_comment_user_picture') ? theme('user_picture', $comment) : ''; oxymoron_preprocess_page($vars); } /** * Prepare the values passed to the theme_links function * Overwrites theme_links */ function oxymoron_links($links, $attributes = array('class' => 'links')) { $output = ''; // Hack to remove the 'My blog' link if a project owner hides the 'Blog' link foreach ($links as $id => $link) { if ($link['title'] == "My blog") { unset($links[$id]); break; } } if (count($links) > 0) { $output = ''; $num_links = count($links); $i = 1; foreach ($links as $key => $link) { $class = ''; // Automatically add a class to each link and also to each LI if (isset($link['attributes']) && isset($link['attributes']['class'])) { $link['attributes']['class'] .= ' '. $key; $class = $key; } else { $link['attributes']['class'] = $key . ' ' . strtolower($link['title']); $class = $key; } // Add first and last classes to the list of links to help out themers. $extra_class = ''; if ($i == 1) { $extra_class .= 'first '; } if ($i == $num_links) { $extra_class .= 'last '; } $output .= '
  • '; // Is the title HTML? $html = isset($link['html']) && $link['html']; // Initialize fragment and query variables. $link['query'] = isset($link['query']) ? $link['query'] : NULL; $link['fragment'] = isset($link['fragment']) ? $link['fragment'] : NULL; if (isset($link['href'])) { $output .= l($link['title'], $link['href'], array( 'attributes' => $link['attributes'], 'query' => $link['query'], 'fragment' => $link['fragment'], 'html' => $html)); } else if ($link['title']) { //Some links are actually not links, but we wrap these in for adding title and class attributes if (!$html) { $link['title'] = check_plain($link['title']); } $output .= ''. $link['title'] .''; } $i++; $output .= "
  • \n"; } $output .= ''; } return $output; } /** * Custom function for the menu pictures */ function oxymoron_render_primary_links($links) { $output = "\n\n"; } /** * Custom function for the tabs div */ function phptemplate_menu_local_tasks() { $output = ''; if ($primary = menu_primary_local_tasks()) { $output .= "\n\t\t
    \n\t\t\t
    \n\t\t\t\t
      \n". $primary ."\t\t\t\t
    \n\t\t\t
    \n\t\t
    "; } return $output; } /** * Regions defined/used by this theme. * Note that by introducing a custom region, the default-ones have to be explicitly written, too. * @return Associative array containing names descriptions of the regions. */ function oxymoron_regions() { return array( 'header' => t('header'), 'left' => t('left sidebar'), 'content' => t('content'), 'right' => t('right sidebar'), 'footer' => t('footer'), 'origo_left_footer' => t('origo footer'), ); } function oxymoron_search_theme_form($form) { // remove the label from the search box ("Search this site") unset($form['search_theme_form']['#title']); // remove label text // unset($form['submit']); // remove submit button return drupal_render($form); } function oxymoron_preprocess_search_block_form(&$vars, $hook) { // Remove the title of the search form unset($vars['form']['search_block_form']['#title']); // Rebuild the rendered version (search form only, rest remains unchanged) unset($vars['form']['search_block_form']['#printed']); $vars['search']['search_block_form'] = drupal_render($vars['form']['search_block_form']); // Collect all form elements to make it easier to print the whole form. $vars['search_form'] = implode($vars['search']); } /** * Converts a string to a suitable html ID attribute. * - Preceeds initial numeric with 'n' character. * - Replaces space and underscore with dash. * - Converts entire string to lowercase. * - Works for classes too! * * @param string $string * the string * @return * the converted string */ function zen_id_safe($string) { if (is_numeric($string{0})) { $string = 'n'. $string; } return strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string)); }