예제 #1
0
/**
 * Intercept template variables
 *
 * @param $hook
 *   The name of the theme function being called (name of the .tpl.php file.)
 * @param $vars
 *   A copy of the array containing the variables for the hook.
 * @return
 *   The array containing additional variables to merge with $vars.
 */
function _phptemplate_variables($hook, $vars = array())
{
    global $theme_key;
    // Allow modules to add or alter variables.
    // This construct ensures that we can keep a reference through
    // call_user_func_array.
    $args = array(&$vars, $hook);
    foreach (module_implements('preprocess') as $module) {
        if ($module != 'search') {
            // Don't call search_preprocess().
            $function = $module . '_preprocess';
            call_user_func_array($function, $args);
        }
    }
    foreach (module_implements('preprocess_' . $hook) as $module) {
        $function = $module . '_preprocess_' . $hook;
        call_user_func_array($function, $args);
    }
    // Allow the Zen base theme to add or alter variables.
    if ($theme_key != 'zen') {
        zen_preprocess($vars, $hook);
        $function = 'zen_preprocess_' . $hook;
        if (function_exists($function)) {
            $function($vars, $hook);
        }
    }
    // Allow a sub-theme to add or alter variables.
    $function = $theme_key . '_preprocess';
    if (function_exists($function)) {
        $function($vars, $hook);
    } else {
        $function = 'phptemplate_preprocess';
        if (function_exists($function)) {
            $function($vars, $hook);
        }
    }
    $function = $theme_key . '_preprocess_' . $hook;
    if (function_exists($function)) {
        $function($vars, $hook);
    } else {
        $function = 'phptemplate_preprocess_' . $hook;
        if (function_exists($function)) {
            $function($vars, $hook);
        }
    }
    // The following is a deprecated function included for backwards compatibility
    // with Zen 5.x-0.8 and earlier. New sub-themes should not use this function.
    if (function_exists('zen_variables')) {
        $vars = zen_variables($hook, $vars);
    }
    _zen_hook($hook);
    // Add support for sub-theme template files.
    return $vars;
}
예제 #2
0
/**
 * 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;
}