Example #1
0
function mothership_preprocess_page(&$vars, $hook)
{
    // Define the content width
    // Add HTML tag name for title tag.
    $vars['site_name_element'] = $vars['is_front'] ? 'h1' : 'div';
    // 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[] = mothership_id_safe('page-' . $path);
        $body_classes[] = mothership_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
}
Example #2
0
/**
 * Preprocess page template variables.
 */
function dynamo_preprocess_page(&$vars)
{
    //adds a class to the body with the last path of the url
    $body_classes = array($vars['body_classes']);
    $path = explode('/', $_SERVER['REQUEST_URI']);
    $body_classes[] = mothership_id_safe('ding-' . arg(0) . ' ' . arg(1));
    $body_classes[] = mothership_id_safe('ding-' . end($path));
    $body_classes[] = mothership_id_safe('ding-' . arg(2));
    // Concatenate with spaces
    $vars['body_classes'] = implode(' ', $body_classes);
}
Example #3
0
/**
 * Implements theme_menu_item_link()
 * yup original is from zen and we humbly say thanx :)
 */
function moshpit_menu_item_link($link)
{
    if (empty($link['localized_options'])) {
        $link['localized_options'] = array();
    }
    //define a class for each tab
    //TODO check out the multilang hell....
    $linkclass = mothership_id_safe($link['title']);
    // If an item is a LOCAL TASK, render it as a tab
    if ($link['type'] & MENU_IS_LOCAL_TASK) {
        $link['title'] = '<span class="tab ' . $linkclass . ' ">' . check_plain($link['title']) . '</span>';
        $link['localized_options']['html'] = TRUE;
        $link['localized_options']['attributes'] = array('class' => $linkclass);
    }
    return l($link['title'], $link['href'], $link['localized_options']);
}
function mothership_table($header, $rows, $attributes = array(), $caption = NULL)
{
    // Add sticky headers, if applicable.
    if (count($header)) {
        drupal_add_js('misc/tableheader.js');
        // Add 'sticky-enabled' class to the table to identify it for JS.
        // This is needed to target tables constructed by this function.
        $attributes['class'] = empty($attributes['class']) ? 'sticky-enabled' : $attributes['class'] . ' sticky-enabled';
    }
    $output = '<table' . drupal_attributes($attributes) . ">\n";
    if (isset($caption)) {
        $output .= '<caption>' . $caption . "</caption>\n";
    }
    // Format the table header:
    if (count($header)) {
        $ts = tablesort_init($header);
        // HTML requires that the thead tag has tr tags in it follwed by tbody
        // tags. Using ternary operator to check and see if we have any rows.
        $output .= count($rows) ? ' <thead><tr>' : ' <tr>';
        $i = 0;
        //header count
        foreach ($header as $cell) {
            // adds odd even, count and name for a th
            $zebra = $i % 2 ? 'even' : 'odd';
            /*add classnames + a count*/
            $zebra .= " count-" . $i . ' ' . mothership_id_safe($cell);
            if (is_array($cell)) {
                //print_r($cell['data']);
                if (isset($cell['class'])) {
                    $cell['class'] .= $zebra;
                } else {
                    $cell['class'] = $zebra;
                }
            } else {
                $cell = array('data' => $cell, 'class' => $zebra);
            }
            $cell = tablesort_header($cell, $header, $ts);
            $output .= _theme_table_cell($cell, TRUE);
            $i++;
        }
        // Using ternary operator to close the tags based on whether or not there are rows
        $output .= count($rows) ? " </tr></thead>\n" : "</tr>\n";
    } else {
        $ts = array();
    }
    // Format the table rows:
    if (count($rows)) {
        $output .= "<tbody>\n";
        $flip = array('even' => 'odd', 'odd' => 'even');
        $class = 'even';
        foreach ($rows as $number => $row) {
            $attributes = array();
            // Check if we're dealing with a simple or complex row
            if (isset($row['data'])) {
                foreach ($row as $key => $value) {
                    if ($key == 'data') {
                        $cells = $value;
                    } else {
                        $attributes[$key] = $value;
                    }
                }
            } else {
                $cells = $row;
            }
            if (count($cells)) {
                // Add odd/even class
                $class = $flip[$class];
                if (isset($attributes['class'])) {
                    $attributes['class'] .= ' ' . $class;
                } else {
                    $attributes['class'] = $class;
                }
                // Build row
                $output .= ' <tr' . drupal_attributes($attributes) . '>';
                $i = 0;
                foreach ($cells as $cell) {
                    $cell = tablesort_cell($cell, $header, $ts, $i++);
                    $output .= _theme_table_cell($cell);
                }
                $output .= " </tr>\n";
            }
        }
        $output .= "</tbody>\n";
    }
    $output .= "</table>\n";
    return $output;
}
/**
 * preprocess
 */
function mothership_preprocess(&$vars, $hook)
{
    if ($hook == "page") {
        // =======================================| page |========================================
        // Add HTML tag name for title tag. so it can shift from a h1 to a div if its the frontpage
        $vars['site_name_element'] = $vars['is_front'] ? 'h1' : 'div';
        // ** ------------------------------------------------------------------------ **
        //  <body> classes
        // ** ------------------------------------------------------------------------ **
        //lets add some more template files
        if (isset($vars['node'])) {
            $vars['template_files'][] = 'page-' . $vars['node']->type;
        }
        //BOdy classes
        $body_classes = array($vars['body_classes']);
        //do we wanna kill all the goodies that comes from drupal?
        if (theme_get_setting('mothership_cleanup_body_remove')) {
            //clean the body_classes
            $body_classes = " ";
            $body_classes = array();
            //front
            if (theme_get_setting('mothership_cleanup_body_front')) {
                $body_classes[] = $vars['is_front'] ? 'front' : '';
            }
            if (theme_get_setting('mothership_cleanup_body_front_not')) {
                $body_classes[] = $vars['is_front'] ? '' : 'not-front';
            }
            //logged-in
            if (theme_get_setting('mothership_cleanup_body_loggedin')) {
                $body_classes[] = $vars['logged_in'] ? 'logged-in' : '';
            }
            if (theme_get_setting('mothership_cleanup_body_loggedin_not')) {
                $body_classes[] = $vars['logged_in'] ? '' : 'not-logged-in';
            }
            //node-type-[TYPE]
            if (theme_get_setting('mothership_cleanup_body_nodetype')) {
                // If on an individual node page, add the node type.
                if (isset($vars['node']) && $vars['node']->type) {
                    $body_classes[] = 'node-type-' . $vars['node']->type;
                }
            }
            //layout
            if (theme_get_setting('mothership_cleanup_body_layout')) {
                // Add information about the number of sidebars.
                if ($vars['layout'] == 'both') {
                    $body_classes[] = 'two-sidebars';
                } elseif ($vars['layout'] == 'none') {
                    $body_classes[] = 'no-sidebars';
                } else {
                    $body_classes[] = 'one-sidebar sidebar-' . $vars['layout'];
                }
            }
        }
        $path = drupal_get_path_alias($_GET['q']);
        if ($path) {
            // Add unique path classes for each page
            if (theme_get_setting('mothership_cleanup_body_add_path')) {
                $body_classes[] = mothership_id_safe('path-' . $path);
            }
        }
        $path_requist = explode('/', $_SERVER['REQUEST_URI']);
        //pathlast
        if (theme_get_setting('mothership_cleanup_body_add_last') and !$vars['is_front']) {
            $body_classes[] = mothership_id_safe('pathlast-' . end($path_requist));
        }
        if (theme_get_setting('mothership_cleanup_body_pagearg_one')) {
            $body_classes[] = mothership_id_safe('page-' . $path_requist['1']);
        }
        //adds class user-foobar without user id
        if (arg(0) == "user") {
            $body_classes[] = mothership_id_safe($path, 'remove-numbers');
        }
        //class action-node
        if (theme_get_setting('mothership_cleanup_body_actions')) {
            if (arg(0) == 'node') {
                if (arg(1) == 'add') {
                    $body_classes[] = 'action-node-add';
                } elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
                    $body_classes[] = 'action-node-' . arg(2);
                    // Add 'action-node-edit' or 'action-node-delete'
                }
            }
        }
        //is the admin module active
        if (!empty($vars['admin']) and theme_get_setting('mothership_cleanup_body_admin')) {
            $body_classes[] = "adminmenu";
        }
        $vars['body_classes'] = implode(' ', $body_classes);
        // Concatenate with spaces
        //    kpr($vars['body_classes']);
        // ** ------------------------------------------------------------------------ **
        // style sheets load order & ie fix
        // kudos to al-steffen for figuring this out :)
        // http://pingv.com/blog/al-steffen/2009/using-themes-info-file-add-order-conditions-stylesheets
        // conditional styles
        // xpressions documentation  -> http://msdn.microsoft.com/en-us/library/ms537512.aspx
        // syntax for .info
        // top stylesheets[all][] = style/reset.css
        // ie stylesheets[ condition ][all][] = ie6.css
        // ------------------------------------------------------------------------
        if (theme_get_setting('mothership_stylesheet_load_order') or theme_get_setting('mothership_stylesheet_conditional')) {
            global $theme_info;
            // Get the path to the theme to make the code more efficient and simple.
            $path = drupal_get_path('theme', $theme_info->name);
        }
        if (theme_get_setting('mothership_stylesheet_load_order')) {
            // Check if there are stylesheets to be placed at the top of the stack.
            if (isset($theme_info->info['top stylesheets'])) {
                $top_css = array();
                // Format the stylesheets to work with drupal_get_css().
                foreach ($theme_info->info['top stylesheets'] as $media => $styles) {
                    foreach ($styles as $style) {
                        $top_css[$media][$path . '/' . $style] = TRUE;
                    }
                    // Add the stylesheets to the top of the proper media type.
                    array_unshift($vars['css'][$media], $top_css[$media]);
                }
                // Replace $styles with the new string.
                $vars['styles'] = drupal_get_css($vars['css']);
            }
        }
        // Check for IE conditional stylesheets.
        if (isset($theme_info->info['ie stylesheets']) and theme_get_setting('mothership_stylesheet_conditional')) {
            $ie_css = array();
            // Format the array to be compatible with drupal_get_css().
            foreach ($theme_info->info['ie stylesheets'] as $condition => $media) {
                foreach ($media as $type => $styles) {
                    foreach ($styles as $style) {
                        $ie_css[$condition][$type]['theme'][$path . '/' . $style] = TRUE;
                    }
                }
            }
            // Append the stylesheets to $styles, grouping by IE version and applying
            // the proper wrapper.
            foreach ($ie_css as $condition => $styles) {
                $vars['styles'] .= '<!--[' . $condition . ']>' . "\n" . drupal_get_css($styles) . '<![endif]-->' . "\n";
            }
        }
        // =======================================| /PAGE |========================================
    } elseif ($hook == "node") {
        // =======================================| NODE |========================================
        // create css classes for the node
        $classes = array();
        //sticky
        if (theme_get_setting('mothership_cleanup_node_sticky')) {
            if ($vars['sticky']) {
                $classes[] = 'sticky';
            }
        }
        //published
        if (theme_get_setting('mothership_cleanup_node_published')) {
            if (!$vars['status']) {
                $classes[] = 'node-unpublished';
                $vars['unpublished'] = TRUE;
            } else {
                $vars['unpublished'] = FALSE;
            }
        }
        //promoted
        if (theme_get_setting('mothership_cleanup_node_promoted')) {
            if ($vars['promote']) {
                $classes[] = 'promoted';
            }
        }
        //node or teaser Class for node type: "node-page", "node-story", "node-teaser-page","node-teaser-story",
        if ($vars['teaser']) {
            if (theme_get_setting('mothership_cleanup_node_node')) {
                $classes[] = 'node-teaser';
                //  $classes[] = 'node';
            }
            if (theme_get_setting('mothership_cleanup_node_content_type')) {
                $classes[] = 'node-teaser-' . $vars['type'];
                $classes[] = 'node-' . $vars['type'];
            }
        } else {
            if (theme_get_setting('mothership_cleanup_node_node')) {
                $classes[] = 'node';
            }
            if (theme_get_setting('mothership_cleanup_node_content_type')) {
                $classes[] = 'node-' . $vars['type'];
            }
        }
        //clearfix
        if (theme_get_setting('mothership_cleanup_node_clearfix')) {
            $classes[] = 'clearfix';
        }
        //skinr
        if (module_exists('skinr')) {
            $classes[] = $vars['skinr'];
        }
        $vars['classes'] = implode(' ', $classes);
        // css id for the node
        if (theme_get_setting('mothership_cleanup_node_id')) {
            $id_node = array();
            $id_node[] = 'node';
            $id_node[] = $vars['nid'];
            if ($vars['nid']) {
                $vars['id_node'] = implode(' ', $id_node);
                $vars['id_node'] = mothership_id_safe($vars['id_node']);
            }
        }
        //Add 2 regions to the node?
        if (theme_get_setting('mothership_cleanup_node_regions') and $vars['page'] == TRUE) {
            if ($vars['page'] == TRUE) {
                $vars['node_region_one'] = theme('blocks', 'node_region_one');
                $vars['node_region_two'] = theme('blocks', 'node_region_two');
            }
        }
        //-----------------------------------------------------
        //lets grap $links array and throw em into some vars we actually can use
        //comments
        if ($vars['node']->links['comment_comments']) {
            $vars['link_comment'] = l($vars['node']->links['comment_comments']['title'], $vars['node']->links['comment_comments']['href'], array('attributes' => array('class' => 'comment', 'title' => $vars['node']->links['comment_comments']['attributes']['title']), 'fragment' => $vars['node']->links['comment_comments']['fragment']));
        }
        //comment_add
        if ($vars['node']->links['comment_add']) {
            $vars['link_comment_add'] = l($vars['node']->links['comment_add']['title'], $vars['node']->links['comment_add']['href'], array('attributes' => array('class' => 'comment-add', 'title' => $vars['node']->links['comment_add']['attributes']['title']), 'fragment' => 'comment-form'));
        }
        //attachments
        if ($vars['node']->links['upload_attachments']) {
            $vars['link_attachments'] = l($vars['node']->links['upload_attachments']['title'], $vars['node']->links['upload_attachments']['href'], array('attributes' => array('class' => 'attachments', 'title' => $vars['node']->links['upload_attachments']['attributes']['title'])));
        }
        //read more
        if ($vars['node']->links['node_read_more']) {
            $vars['link_read_more'] = l($vars['node']->links['node_read_more']['title'], $vars['node']->links['node_read_more']['href'], array('attributes' => array('class' => 'read-more', 'title' => $vars['node']->links['node_read_more']['attributes']['title'])));
        }
        //statistics_counter
        if ($vars['node']->links['statistics_counter']) {
            $vars['statistics_counter'] = $vars['node']->links['statistics_counter']['title'];
        }
        return $vars['template_files'];
        // =======================================| /NODE |========================================
    } elseif ($hook == "block") {
        // =======================================| BLOCK |========================================
        //  classes for blocks.
        $block = $vars['block'];
        $classes = array();
        if (theme_get_setting('mothership_cleanup_block_block')) {
            $classes[] = 'block';
        }
        if (theme_get_setting('mothership_cleanup_block_module')) {
            $classes[] = 'block-' . mothership_id_safe($block->module);
        }
        if (theme_get_setting('mothership_cleanup_block_region_zebra')) {
            $classes[] = 'region-' . $vars['block_zebra'];
        }
        if (theme_get_setting('mothership_cleanup_block_region_count')) {
            $classes[] = 'region-count-' . mothership_id_safe($vars['block_id']);
        }
        if (theme_get_setting('mothership_cleanup_block_zebra')) {
            $classes[] = $vars['zebra'];
        }
        if (theme_get_setting('mothership_cleanup_block_count')) {
            $classes[] = 'count-' . mothership_id_safe($vars['id']);
        }
        if (theme_get_setting('mothership_cleanup_block_front')) {
            if ($vars['is_front']) {
                $classes[] = 'block-front';
            }
        }
        if (theme_get_setting('mothership_cleanup_block_loggedin')) {
            if ($vars['logged_in']) {
                $classes[] = 'block-logged-in';
            }
        }
        //skinr
        if (module_exists(skinr)) {
            $classes[] = $vars['skinr'];
        }
        // Render block classes.
        $vars['classes'] = implode(' ', $classes);
        // $vars['classes'] =  mothership_id_safe($vars['classes']);
        // id for block
        if (theme_get_setting('mothership_cleanup_block_id')) {
            $id_block = array();
            $id_block[] = 'block';
            $id_block[] = $block->module;
            if ($block->delta) {
                $id_block[] = $block->delta;
            }
            $vars['id_block'] = implode(' ', $id_block);
            $vars['id_block'] = mothership_id_safe($vars['id_block']);
        }
        // =======================================| /BLOCK |========================================
    } elseif ($hook == "comment") {
        // =======================================| COMMENT |========================================
        //dsm($vars);
        // Add an "unpublished" flag.
        $vars['unpublished'] = $vars['comment']->status == COMMENT_NOT_PUBLISHED;
        // If comment subjects are disabled, don't display them.
        if (variable_get('comment_subject_field_' . $vars['node']->type, 1) == 0) {
            $vars['title'] = '';
        }
        // Special classes for comments.
        $classes = array();
        if (theme_get_setting('mothership_cleanup_comment_comment')) {
            $classes[] = 'comment';
        }
        if ($vars['comment']->new and theme_get_setting('mothership_cleanup_comment_new')) {
            $classes[] = 'comment-new';
        }
        if (theme_get_setting('mothership_cleanup_comment_status')) {
            $classes[] = $vars['status'];
        }
        if (theme_get_setting('mothership_cleanup_comment_zebra')) {
            $classes[] = $vars['zebra'];
        }
        //first last
        if (theme_get_setting('mothership_cleanup_comment_first')) {
            if ($vars['id'] == 1) {
                $classes[] = 'first';
            }
        }
        if ($vars['id'] == $vars['node']->comment_count and theme_get_setting('mothership_cleanup_comment_last')) {
            $classes[] = 'last';
        }
        if (theme_get_setting('mothership_cleanup_comment_user')) {
            if ($vars['comment']->uid == 0) {
                // Comment is by an anonymous user.
                $classes[] = 'by-anonymous';
            } else {
                if ($vars['comment']->uid == $vars['node']->uid) {
                    // Comment is by the node author.
                    $classes[] = 'by-author';
                }
                if ($vars['comment']->uid == $GLOBALS['user']->uid) {
                    // Comment was posted by current user.
                    $classes[] = 'by-me';
                }
            }
        }
        if (theme_get_setting('mothership_cleanup_comment_front')) {
            if ($vars['is_front']) {
                $classes[] = 'front';
            }
        }
        if (theme_get_setting('mothership_cleanup_comment_loggedin')) {
            if ($vars['logged_in']) {
                $classes[] = 'logged-in';
            }
        }
        $vars['classes'] = implode(' ', $classes);
        // =======================================| /COMMENT |========================================
    } elseif ($hook == "comment_wrapper") {
        // =======================================| COMMENTWRAPPER |========================================
        $id_commentwrap = array();
        $id_commentwrap[] = 'comments';
        $vars['id_commentwrap'] = implode(' ', $id_commentwrap);
        $vars['id_commentwrap'] = mothership_id_safe($vars['id_commentwrap']);
        $classes = array();
        //skinr
        if (module_exists(skinr)) {
            $classes[] = $vars['skinr'];
        }
        $vars['classes'] = implode(' ', $classes);
        // =======================================| COMMENTWRAPPER |========================================
    }
}