You are here

function forward_node_view in Forward 7

Same name and namespace in other branches
  1. 7.2 forward.module \forward_node_view()

Generate links for pages

File

./forward.module, line 1199

Code

function forward_node_view($node, $view_mode) {
  if (user_access('access forward') && variable_get('forward_display_' . $node->type, '1')) {
    if (variable_get('forward_form_type', 'link') == 'link') {
      $links = array();

      // This var is set in the settings section under the admin/modules/forward section
      // It shows 'email this $nodetype' or 'email this page'
      $forward_link_type = variable_get('forward_link_type', 0) ? node_type_get_name($node->type) : t('page');
      if ($view_mode == 'full' && variable_get('forward_display_nodes', 1) || $view_mode == 'teaser' && variable_get('forward_display_teasers', 0)) {
        drupal_add_css(drupal_get_path('module', 'forward') . '/forward.css');
        $title = check_plain(t(variable_get('forward_link_title', 'Email this !type'), array(
          '!type' => $forward_link_type,
        )));
        $img = drupal_get_path('module', 'forward') . '/forward.gif';
        $html = FALSE;
        switch (variable_get('forward_link_style', 0)) {
          case 1:
            $title = theme('image', array(
              'path' => $img,
              'alt' => $title,
              'title' => '',
              'attributes' => array(
                'class' => array(
                  'forward-icon',
                ),
              ),
            ));
            $html = TRUE;
            break;
          case 2:
            $title = theme('image', array(
              'path' => $img,
              'alt' => $title,
              'title' => '',
              'attributes' => array(
                'class' => array(
                  'forward-icon',
                  'forward-icon-margin',
                ),
              ),
            )) . $title;
            $html = TRUE;
            break;
        }
        $form_state['values']['path'] = 'node/' . $node->nid;
        if (variable_get('forward_link_nofollow', 0)) {
          $links['forward_link'] = array(
            'title' => $title,
            'href' => 'forward',
            'html' => $html,
            'attributes' => array(
              'title' => variable_get('forward_email_title', t('Forward this page to a friend')),
              'class' => array(
                'forward-page',
              ),
              'rel' => 'nofollow',
            ),
            'query' => array(
              'path' => $form_state['values']['path'],
            ),
          );
        }
        else {
          $links['forward_link'] = array(
            'title' => $title,
            'href' => 'forward',
            'html' => $html,
            'attributes' => array(
              'title' => variable_get('forward_email_title', t('Forward this page to a friend')),
              'class' => array(
                'forward-page',
              ),
            ),
            'query' => array(
              'path' => $form_state['values']['path'],
            ),
          );
        }
        $node->content['links']['forward'] = array(
          '#theme' => 'links',
          '#links' => $links,
          '#attributes' => array(
            'class' => array(
              'links',
              'inline',
            ),
          ),
        );
      }
    }
    elseif (variable_get('forward_form_type', 'link') == 'form' && !isset($node->in_preview) && ($view_mode == 'teaser' && variable_get('forward_display_teasers', 0) || $view_mode == 'full' && variable_get('forward_display_nodes', 1))) {
      $output = drupal_get_form('forward_form', 'node/' . $node->nid, $node->title, TRUE);
      $node->content['forward'] = $output;
    }
  }
}