You are here

function forward_link_create in Forward 7.3

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

Generate a Forward link for an entity or page

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

File

./forward.module, line 259
Allows forwarding of entities by email, and provides a record of how often each has been forwarded.

Code

function forward_link_create($entity_type = NULL, $entity = NULL, $path = NULL, $block = FALSE) {
  drupal_add_css(drupal_get_path('module', 'forward') . '/css/forward.css');
  if ($entity_type && $entity) {
    $entity_wrapper = entity_metadata_wrapper($entity_type, $entity);
    $token = _forward_get_token($path, $entity_wrapper);
  }
  else {
    $token = _forward_get_token($path);
  }
  $title = token_replace(check_plain(t(variable_get('forward_link_title', 'Email this [forward:entity-type]'))), $token);
  $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') . '/images/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 ($entity_type && $entity) {
    $uri = entity_uri($entity_type, $entity);
    if (variable_get('forward_link_alias', FALSE)) {
      $path = drupal_get_path_alias($uri['path'], entity_language($entity_type, $entity));
    }
    else {
      $path = $uri['path'];
    }
  }
  else {
    if (!$path) {
      $path = $_GET['q'];
    }
    if (variable_get('forward_link_alias', FALSE)) {
      $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', FALSE)) {
    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', FALSE)) {
    $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,
  );
}