You are here

function forward_link_create in Forward 7.2

Same name and namespace in other branches
  1. 7.3 forward.module \forward_link_create()

Generate a Forward link for a node or page

2 calls to forward_link_create()
forward_node_view in ./forward.module
Implements hook_node_view().
theme_forward_link in ./forward.module
Theme function for Forward link

File

./forward.module, line 218

Code

function forward_link_create($node = NULL, $path = NULL, $block = FALSE) {
  drupal_add_css(drupal_get_path('module', 'forward') . '/forward.css');
  if ($node) {
    $forward_link_type = variable_get('forward_link_type', 0) ? node_type_get_name($node->type) : t('page');
  }
  else {
    $forward_link_type = t('page');
  }
  $title = check_plain(t(variable_get('forward_link_title', 'Email this !type'), array(
    '!type' => $forward_link_type,
  )));
  $html = FALSE;

  // Always include some text for the block link
  $link_style = variable_get('forward_link_style', 0);
  if ($block && $link_style == 1) {
    $link_style++;
  }

  // Output the correct style of link
  $default_icon = drupal_get_path('module', 'forward') . '/forward.gif';
  $custom_icon = variable_get('forward_link_icon', '');
  switch ($link_style) {

    // text only is a "noop" since the title text is already setup above
    // image only
    case 1:
      $img = $custom_icon ? $custom_icon : $default_icon;
      $title = theme('image', array(
        'path' => $img,
        'alt' => $title,
        'attributes' => array(
          'class' => array(
            'forward-icon',
          ),
        ),
      ));
      $html = TRUE;
      break;

    // image and text
    case 2:
      $img = $custom_icon ? $custom_icon : $default_icon;
      $tag = theme('image', array(
        'path' => $img,
        'alt' => $title,
        'attributes' => array(
          'class' => array(
            'forward-icon',
            'forward-icon-margin',
          ),
        ),
      ));
      $title = $tag . $title;
      $html = TRUE;
      break;
  }
  if ($node) {
    if (variable_get('forward_link_alias', 0)) {
      $path = drupal_get_path_alias('node/' . $node->nid, $node->language);
    }
    else {
      $path = 'node/' . $node->nid;
    }
  }
  else {
    if (!$path) {
      $path = $_GET['q'];
    }
    if (variable_get('forward_link_alias', 0)) {
      $path = drupal_get_path_alias($path);
    }
  }
  $attributes = array(
    'title' => variable_get('forward_email_title', t('Forward this page to a friend')),
    'class' => array(
      'forward-page',
    ),
  );
  if (variable_get('forward_colorbox_enable', 0)) {
    if (module_exists('colorbox_node')) {
      $overlay = 'cboxnode';
      $attributes['class'][] = 'colorbox-node';
    }
    else {
      $overlay = 'cbox';
      $attributes['class'][] = 'colorbox-load';
    }
    $query = array(
      'path' => $path,
      'overlay' => $overlay,
      'width' => variable_get('forward_colorbox_width', 600),
      'height' => variable_get('forward_colorbox_height', 600),
    );
  }
  else {
    $query = array(
      'path' => $path,
    );
  }
  if (variable_get('forward_link_nofollow', 0)) {
    $attributes['rel'] = 'nofollow';
  }
  $content = l($title, 'forward', array(
    'html' => $html,
    'attributes' => $attributes,
    'query' => $query,
  ));
  return array(
    'content' => $content,
    'title' => $title,
    'html' => $html,
    'attributes' => $attributes,
    'query' => $query,
  );
}