Exemplo n.º 1
0
/**
 * Implements hook_preprocess_node().
 */
function ctsibamboo_preprocess_node(&$vars)
{
    global $user;
    $node = $vars['node'];
    if (!empty($vars['content']['links'])) {
        foreach ($vars['content']['links'] as $group => &$links) {
            switch ($group) {
                case 'comment':
                    if ($node->comment != COMMENT_NODE_HIDDEN) {
                        if (empty($links['#links']['comment-add']) and $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('Add new comment'), 'href' => "comment/reply/{$node->nid}", 'attributes' => array('title' => t('Add a new comment to this page.')), 'fragment' => 'comment-form');
                        }
                        if (empty($links['#links']['comment-comments'])) {
                            $links['#links']['comment-comments'] = array('title' => empty($node->comment_count) ? 'No comments yet' : format_plural($node->comment_count, '1 comment', '@count comments'), 'href' => "node/{$node->nid}", 'attributes' => array('title' => t('Jump to the first comment of this posting.')), 'fragment' => 'comments', 'html' => TRUE);
                        }
                    }
                    break;
            }
        }
    }
    // 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)));
}
Exemplo n.º 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');
        }
    }
}