예제 #1
0
function phptemplate_preprocess_node(&$vars)
{
    // Build array of handy node classes
    $node_classes = array();
    $node_classes[] = $vars['zebra'];
    // Node is odd or even
    $node_classes[] = !$vars['node']->status ? 'node-unpublished' : '';
    // Node is unpublished
    $node_classes[] = $vars['sticky'] ? 'sticky' : '';
    // Node is sticky
    $node_classes[] = isset($vars['node']->teaser) ? 'teaser' : 'full-node';
    // Node is teaser or full-node
    $node_classes[] = 'node-type-' . $vars['node']->type;
    // Node is type-x, e.g., node-type-page
    $node_classes = array_filter($node_classes);
    // Remove empty elements
    $vars['node_classes'] = implode(' ', $node_classes);
    // Implode class list with spaces
    // Node Theme Settings
    // Node Links
    if (isset($vars['node']->links['node_read_more'])) {
        $node_content_type = theme_get_setting('readmore_enable_content_type') == 1 ? $vars['node']->type : 'default';
        $vars['node']->links['node_read_more'] = array('title' => _themesettings_link(theme_get_setting('readmore_prefix_' . $node_content_type), theme_get_setting('readmore_suffix_' . $node_content_type), t(theme_get_setting('readmore_' . $node_content_type)), 'node/' . $vars['node']->nid, array('attributes' => array('title' => t(theme_get_setting('readmore_title_' . $node_content_type))), 'query' => NULL, 'fragment' => NULL, 'absolute' => FALSE, 'html' => TRUE)), 'attributes' => array('class' => 'readmore-item'), 'html' => TRUE);
    }
    if (isset($vars['node']->links['comment_add'])) {
        $node_content_type = theme_get_setting('comment_enable_content_type') == 1 ? $vars['node']->type : 'default';
        if ($vars['teaser']) {
            $vars['node']->links['comment_add'] = array('title' => _themesettings_link(theme_get_setting('comment_add_prefix_' . $node_content_type), theme_get_setting('comment_add_suffix_' . $node_content_type), t(theme_get_setting('comment_add_' . $node_content_type)), "comment/reply/" . $vars['node']->nid, array('attributes' => array('title' => t(theme_get_setting('comment_add_title_' . $node_content_type))), 'query' => NULL, 'fragment' => 'comment-form', 'absolute' => FALSE, 'html' => TRUE)), 'attributes' => array('class' => 'comment-add-item'), 'html' => TRUE);
        } else {
            $vars['node']->links['comment_add'] = array('title' => _themesettings_link(theme_get_setting('comment_node_prefix_' . $node_content_type), theme_get_setting('comment_node_suffix_' . $node_content_type), t(theme_get_setting('comment_node_' . $node_content_type)), "comment/reply/" . $vars['node']->nid, array('attributes' => array('title' => t(theme_get_setting('comment_node_title_' . $node_content_type))), 'query' => NULL, 'fragment' => 'comment-form', 'absolute' => FALSE, 'html' => TRUE)), 'attributes' => array('class' => 'comment-node-item'), 'html' => TRUE);
        }
    }
    if (isset($vars['node']->links['comment_new_comments'])) {
        $node_content_type = theme_get_setting('comment_enable_content_type') == 1 ? $vars['node']->type : 'default';
        $vars['node']->links['comment_new_comments'] = array('title' => _themesettings_link(theme_get_setting('comment_new_prefix_' . $node_content_type), theme_get_setting('comment_new_suffix_' . $node_content_type), format_plural(comment_num_new($vars['node']->nid), t(theme_get_setting('comment_new_singular_' . $node_content_type)), t(theme_get_setting('comment_new_plural_' . $node_content_type))), "node/" . $vars['node']->nid, array('attributes' => array('title' => t(theme_get_setting('comment_new_title_' . $node_content_type))), 'query' => NULL, 'fragment' => 'new', 'absolute' => FALSE, 'html' => TRUE)), 'attributes' => array('class' => 'comment-new-item'), 'html' => TRUE);
    }
    if (isset($vars['node']->links['comment_comments'])) {
        $node_content_type = theme_get_setting('comment_enable_content_type') == 1 ? $vars['node']->type : 'default';
        $vars['node']->links['comment_comments'] = array('title' => _themesettings_link(theme_get_setting('comment_prefix_' . $node_content_type), theme_get_setting('comment_suffix_' . $node_content_type), format_plural(comment_num_all($vars['node']->nid), t(theme_get_setting('comment_singular_' . $node_content_type)), t(theme_get_setting('comment_plural_' . $node_content_type))), "node/" . $vars['node']->nid, array('attributes' => array('title' => t(theme_get_setting('comment_title_' . $node_content_type))), 'query' => NULL, 'fragment' => 'comments', 'absolute' => FALSE, 'html' => TRUE)), 'attributes' => array('class' => 'comment-item'), 'html' => TRUE);
    }
    $vars['links'] = theme('links', $vars['node']->links, array('class' => 'links inline'));
}
예제 #2
0
/**
 * Implements hook_preprocess_node().
 */
function opbamboo_preprocess_node(&$vars)
{
    global $user;
    $node = $vars['node'];
    // don't bother during preview
    if (!empty($node->nid) and !empty($vars['content']['links'])) {
        foreach ($vars['content']['links'] as $group => &$links) {
            switch ($group) {
                case 'comment':
                    if (empty($links['#links']['comment-add'])) {
                        if ($node->comment == COMMENT_NODE_OPEN and user_access('post comments') and ($user->uid or variable_get('ctsi_allow_anonymous_comments_' . $node->type, 0))) {
                            $links['#links']['comment-add'] = array('title' => t('Comment'), 'href' => "comment/reply/{$node->nid}", 'attributes' => array('title' => t('Add a new comment to this page.')), 'fragment' => 'comment-form');
                        }
                    } else {
                        $links['#links']['comment-add']['title'] = t('Comment');
                    }
                    // purge these old-style things
                    unset($links['#links']['comment-comments']);
                    unset($links['#links']['comment-new-comments']);
                    break;
                case 'ctsi':
                    // only node subscription link survives
                    foreach (array_keys($links['#links']) as $link_key) {
                        if ($link_key !== 'subscriptions_node_nid_' . $node->nid) {
                            unset($links['#links'][$link_key]);
                        }
                    }
                    break;
            }
        }
        // add image link for comment count
        //  for some reason when the node is displayed by a view
        //    $vars['node']->comment is showing up as FALSE
        //    even though $vars['comment'] has the real value
        if (!empty($node->nid) and $vars['comment'] != COMMENT_NODE_HIDDEN) {
            $comments = $vars['comment_count'];
            if ($new = comment_num_new($node->nid)) {
                $comments .= " ({$new} new)";
            }
            $vars['content']['links']['comment']['#links']['count-comments'] = array('title' => '<span class="count-comments">' . $comments . '</span>', 'html' => TRUE);
        }
        // add image link for follower count
        if ($nodesubs = opg_core_node_subs($node->nid)) {
            $followers = empty($nodesubs['total']) ? 0 : count($nodesubs['total']);
            $vars['content']['links']['ctsi']['#links']['count-follows'] = array('title' => '<span class="count-follows">' . $followers . '</span>', 'html' => TRUE);
        }
        // move likeme to a link
        if (!empty($vars['content']['rate_likeme']['#markup'])) {
            if (empty($vars['content']['links']['rate'])) {
                $vars['content']['links']['rate'] = array('#theme' => 'links__node__rate', '#links' => array()) + $vars['content']['links']['node'];
            }
            $vars['content']['links']['rate']['#links']['ctsi-likeme'] = array('title' => str_replace(array('<div', 'div>'), array('<span', 'span>'), $vars['content']['rate_likeme']['#markup']), 'html' => TRUE);
            unset($vars['content']['rate_likeme']);
        }
    }
    // Show only the username in submitted, the date is handled by node.tpl.php.
    $vars['submitted'] = t('Submitted by !username', array('!username' => ctsi_username_link($node)));
    if (!array_key_exists('primary_author', $vars)) {
        $vars['primary_author'] = null;
    }
    // do not display Rate widget(s) title
    if (!empty($vars['content']['rate_thumbs_up']['#title'])) {
        $vars['content']['rate_thumbs_up']['#title'] = '';
    }
    if (!empty($vars['content']['rate_likeme']['#title'])) {
        $vars['content']['rate_likeme']['#title'] = '';
    }
    if (empty($vars['teaser'])) {
        // dpm('is not teaser');
    } elseif (isset($vars['content']['comments'])) {
        // dpm($vars['content'], 'has comments in content');
    } else {
        if ($group = opg_core_node_in_group($node)) {
            $teaser_comments = 0;
            if ($group_entity = opg_core_get_entity($group)) {
                $wrapper = entity_metadata_wrapper($group['group_type'], $group_entity);
                if (isset($wrapper->field_opg_teaser_comments)) {
                    $teaser_comments = (int) $wrapper->field_opg_teaser_comments->value();
                } else {
                    // dpm(compact('node','group','group_entity'), 'no teaser comments field in group entity');
                }
            } else {
                dpm(compact('node', 'group', 'group_entity'), 'could not get group entity');
            }
            if (isset($_GET['teaser_comments'])) {
                $teaser_comments = $_GET['teaser_comments'];
            }
            if ($teaser_comments) {
                switch ($node->type) {
                    // don't show comments for these content types
                    case 'opg_admin_post':
                        // dpm(compact('node'), 'node type ' . $node->type . ' should not show comments');
                        break;
                    default:
                        // everybody else
                        if ($view = views_get_view('opg_comments')) {
                            $display_id = 'default';
                            if ($view->access($display_id)) {
                                $view->items_per_page = $teaser_comments;
                                $args = array($node->nid);
                                $vars['content']['comments']['#markup'] = $view->preview($display_id, $args);
                            } else {
                                dpm(compact('display_id', 'view'), 'no access to display');
                            }
                        } else {
                            dpm('no such view opg_comments i guess');
                        }
                        break;
                }
            } else {
                // dpm(compact('group','group_entity','teaser_comments'), 'group does not set a number of comments to add to teaser');
            }
        } else {
            // dpm(compact('node','group'), 'node is not part of current group');
        }
    }
}
예제 #3
0
function acquia_marina_preprocess_node(&$vars)
{
    // Build array of handy node classes
    $node_classes = array();
    $node_classes[] = $vars['zebra'];
    // Node is odd or even
    $node_classes[] = !$vars['node']->status ? 'node-unpublished' : '';
    // Node is unpublished
    $node_classes[] = $vars['sticky'] ? 'sticky' : '';
    // Node is sticky
    $node_classes[] = isset($vars['node']->teaser) ? 'teaser' : 'full-node';
    // Node is teaser or full-node
    $node_classes[] = 'node-type-' . $vars['node']->type;
    // Node is type-x, e.g., node-type-page
    $node_classes = array_filter($node_classes);
    // Remove empty elements
    $vars['node_classes'] = implode(' ', $node_classes);
    // Implode class list with spaces
    // Add node_bottom region content
    $vars['node_bottom'] = theme('blocks', 'node_bottom');
    // Node Theme Settings
    // Date & author
    if (!module_exists('submitted_by')) {
        $date = t('Posted ') . format_date($vars['node']->created, 'medium');
        // Format date as small, medium, or large
        $author = theme('username', $vars['node']);
        $author_only_separator = t('Posted by ');
        $author_date_separator = t(' by ');
        $submitted_by_content_type = theme_get_setting('submitted_by_enable_content_type') == 1 ? $vars['node']->type : 'default';
        $date_setting = theme_get_setting('submitted_by_date_' . $submitted_by_content_type) == 1;
        $author_setting = theme_get_setting('submitted_by_author_' . $submitted_by_content_type) == 1;
        $author_separator = $date_setting ? $author_date_separator : $author_only_separator;
        $date_author = $date_setting ? $date : '';
        $date_author .= $author_setting ? $author_separator . $author : '';
        $vars['submitted'] = $date_author;
    }
    // Taxonomy
    $taxonomy_content_type = theme_get_setting('taxonomy_enable_content_type') == 1 ? $vars['node']->type : 'default';
    $taxonomy_display = theme_get_setting('taxonomy_display_' . $taxonomy_content_type);
    $taxonomy_format = theme_get_setting('taxonomy_format_' . $taxonomy_content_type);
    if (module_exists('taxonomy') && ($taxonomy_display == 'all' || $taxonomy_display == 'only' && $vars['page'])) {
        $vocabularies = taxonomy_get_vocabularies($vars['node']->type);
        $output = '';
        $term_delimiter = ', ';
        foreach ($vocabularies as $vocabulary) {
            if (theme_get_setting('taxonomy_vocab_hide_' . $taxonomy_content_type . '_' . $vocabulary->vid) != 1) {
                $terms = taxonomy_node_get_terms_by_vocabulary($vars['node'], $vocabulary->vid);
                if ($terms) {
                    $term_items = '';
                    foreach ($terms as $term) {
                        // Build vocabulary term items
                        $term_link = l($term->name, taxonomy_term_path($term), array('attributes' => array('rel' => 'tag', 'title' => strip_tags($term->description))));
                        $term_items .= '<li class="vocab-term">' . $term_link . $term_delimiter . '</li>';
                    }
                    if ($taxonomy_format == 'vocab') {
                        // Add vocabulary labels if separate
                        $output .= '<li class="vocab vocab-' . $vocabulary->vid . '"><span class="vocab-name">' . $vocabulary->name . ':</span> <ul class="vocab-list">';
                        $output .= substr_replace($term_items, '</li>', -(strlen($term_delimiter) + 5)) . '</ul></li>';
                    } else {
                        $output .= $term_items;
                    }
                }
            }
        }
        if ($output != '') {
            $output = $taxonomy_format == 'list' ? substr_replace($output, '</li>', -(strlen($term_delimiter) + 5)) : $output;
            $output = '<ul class="taxonomy">' . $output . '</ul>';
        }
        $vars['terms'] = $output;
    } else {
        $vars['terms'] = '';
    }
    // Node Links
    if (isset($vars['node']->links['node_read_more'])) {
        $node_content_type = theme_get_setting('readmore_enable_content_type') == 1 ? $vars['node']->type : 'default';
        $vars['node']->links['node_read_more'] = array('title' => acquia_marina_themesettings_link(theme_get_setting('readmore_prefix_' . $node_content_type), theme_get_setting('readmore_suffix_' . $node_content_type), t(theme_get_setting('readmore_' . $node_content_type)), 'node/' . $vars['node']->nid, array('attributes' => array('title' => t(theme_get_setting('readmore_title_' . $node_content_type))), 'query' => NULL, 'fragment' => NULL, 'absolute' => FALSE, 'html' => TRUE)), 'attributes' => array('class' => 'readmore-item'), 'html' => TRUE);
    }
    if (isset($vars['node']->links['comment_add'])) {
        $node_content_type = theme_get_setting('comment_enable_content_type') == 1 ? $vars['node']->type : 'default';
        if ($vars['teaser']) {
            $vars['node']->links['comment_add'] = array('title' => acquia_marina_themesettings_link(theme_get_setting('comment_add_prefix_' . $node_content_type), theme_get_setting('comment_add_suffix_' . $node_content_type), t(theme_get_setting('comment_add_' . $node_content_type)), "comment/reply/" . $vars['node']->nid, array('attributes' => array('title' => t(theme_get_setting('comment_add_title_' . $node_content_type))), 'query' => NULL, 'fragment' => 'comment-form', 'absolute' => FALSE, 'html' => TRUE)), 'attributes' => array('class' => 'comment-add-item'), 'html' => TRUE);
        } else {
            $vars['node']->links['comment_add'] = array('title' => acquia_marina_themesettings_link(theme_get_setting('comment_node_prefix_' . $node_content_type), theme_get_setting('comment_node_suffix_' . $node_content_type), t(theme_get_setting('comment_node_' . $node_content_type)), "comment/reply/" . $vars['node']->nid, array('attributes' => array('title' => t(theme_get_setting('comment_node_title_' . $node_content_type))), 'query' => NULL, 'fragment' => 'comment-form', 'absolute' => FALSE, 'html' => TRUE)), 'attributes' => array('class' => 'comment-node-item'), 'html' => TRUE);
        }
    }
    if (isset($vars['node']->links['comment_new_comments'])) {
        $node_content_type = theme_get_setting('comment_enable_content_type') == 1 ? $vars['node']->type : 'default';
        $vars['node']->links['comment_new_comments'] = array('title' => acquia_marina_themesettings_link(theme_get_setting('comment_new_prefix_' . $node_content_type), theme_get_setting('comment_new_suffix_' . $node_content_type), format_plural(comment_num_new($vars['node']->nid), t(theme_get_setting('comment_new_singular_' . $node_content_type)), t(theme_get_setting('comment_new_plural_' . $node_content_type))), "node/" . $vars['node']->nid, array('attributes' => array('title' => t(theme_get_setting('comment_new_title_' . $node_content_type))), 'query' => NULL, 'fragment' => 'new', 'absolute' => FALSE, 'html' => TRUE)), 'attributes' => array('class' => 'comment-new-item'), 'html' => TRUE);
    }
    if (isset($vars['node']->links['comment_comments'])) {
        $node_content_type = theme_get_setting('comment_enable_content_type') == 1 ? $vars['node']->type : 'default';
        $vars['node']->links['comment_comments'] = array('title' => acquia_marina_themesettings_link(theme_get_setting('comment_prefix_' . $node_content_type), theme_get_setting('comment_suffix_' . $node_content_type), format_plural(comment_num_all($vars['node']->nid), t(theme_get_setting('comment_singular_' . $node_content_type)), t(theme_get_setting('comment_plural_' . $node_content_type))), "node/" . $vars['node']->nid, array('attributes' => array('title' => t(theme_get_setting('comment_title_' . $node_content_type))), 'query' => NULL, 'fragment' => 'comments', 'absolute' => FALSE, 'html' => TRUE)), 'attributes' => array('class' => 'comment-item'), 'html' => TRUE);
    }
    $vars['links'] = theme('links', $vars['node']->links, array('class' => 'links inline'));
}
예제 #4
0
/**
 * Number of new topic replies for user or topic is unread
 * @see forum.module
 */
function _authcache_forum_topic_info($vars) {
  global $user;
  $info = array();

  drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH);
  include_once './modules/node/node.module';  // Need NODE_NEW_LIMIT definition
  include_once './modules/forum/forum.module';
  include_once './modules/comment/comment.module';

  foreach($vars as $nid => $timestamp) {
    $history = _forum_user_last_visit($nid);
    $new_topics = (int)comment_num_new($nid, $history);
    if($new_topics) {
      $info[$nid] = format_plural($new_topics, '1 new', '@count new');
    }
    else if ($timestamp > $history) { // unread
      $info[$nid] = 1;
    }
  }

  return $info;
}