You are here

function forward_link in Forward 6

Same name and namespace in other branches
  1. 5 forward.module \forward_link()

Generate links for pages

File

./forward.module, line 1043

Code

function forward_link($type, $node = 0, $teaser = 0) {
  if ('comment' == $type && !variable_get('forward_display_comments', FALSE) || 'node' == $type && (!variable_get('forward_display_nodes', TRUE) && !$teaser)) {
    return;
  }
  if (($type == 'node' && variable_get('forward_display_' . $node->type, '1') && variable_get('forward_form_type', 'link') == 'link' || $type == 'comment') && user_access('access forward')) {
    $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'
    if (variable_get('forward_link_type', 0)) {
      $forward_link_type = $type == 'comment' ? t('comment') : node_get_types("name", $node);
    }
    else {
      $forward_link_type = $type == 'comment' ? t('comment') : t('page');
    }
    if (!$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', $img, $title, '', array(
            'class' => 'forward-icon',
          ));
          $html = TRUE;
          break;
        case 2:
          $title = theme('image', $img, $title, '', array(
            'class' => 'forward-icon forward-icon-margin',
          )) . $title;
          $html = TRUE;
          break;
      }
      $form_state['values']['path'] = 'node/' . $node->nid;
      $links['forward_links'] = array(
        'title' => $title,
        'href' => 'forward',
        'html' => $html,
        'attributes' => array(
          'title' => variable_get('forward_email_title', t('Forward this page to a friend')),
          'class' => 'forward-page',
        ),
        'query' => array(
          'path' => $form_state['values']['path'],
        ),
      );
      if (!empty($node->cid)) {
        $links['forward_links']['query']['cid'] = $node->cid;
      }
      return $links;
    }
  }
}