You are here

public function ViewsBaseUrlHandlerBaseUrl::render in Views base url 7

Render site's base url.

Overrides views_handler_field::render

File

includes/views/handlers/views_base_url_handler_base_url.inc, line 169
A handler to output site's base url.

Class

ViewsBaseUrlHandlerBaseUrl
@file A handler to output site's base url.

Code

public function render($values) {
  global $base_url;
  $output = '';
  $link_query = array();
  $tokens = $this
    ->get_render_tokens($output);
  if ($this->options['show_link']) {
    global $language;
    if (!empty($this->options['show_link_options']['link_path'])) {
      $aliased_path = str_replace(array_keys($tokens), $tokens, $this->options['show_link_options']['link_path']);
      $aliased_path = drupal_get_path_alias($aliased_path);
    }

    // Link path.
    $link_path = empty($aliased_path) ? $base_url : $base_url . '/' . $aliased_path;

    // Link text.
    if (empty($this->options['show_link_options']['link_text'])) {
      if (empty($aliased_path)) {
        $link_text = $base_url;
      }
      else {
        $link_text = $base_url . '/' . $aliased_path;
      }
    }
    else {
      $link_text = $this->options['show_link_options']['link_text'];
    }

    // Link class.
    $link_class = empty($this->options['show_link_options']['link_class']) ? array() : explode(' ', $this->options['show_link_options']['link_class']);

    // Link query.
    if (!empty($this->options['show_link_options']['link_query'])) {
      $queries = explode(' ', $this->options['show_link_options']['link_query']);
      foreach ($queries as $query) {
        $param = explode('=', $query);
        $link_query[$param[0]] = $param[1];
      }
    }

    // Create link with options.
    $output = l($link_text, $link_path, array(
      'attributes' => array(
        'class' => $link_class,
        'title' => $this->options['show_link_options']['link_title'],
        'rel' => $this->options['show_link_options']['link_rel'],
        'target' => $this->options['show_link_options']['link_target'],
      ),
      'fragment' => $this->options['show_link_options']['link_fragment'],
      'query' => $link_query,
      'language' => $language,
      'html' => TRUE,
    ));
  }
  else {
    $output = $base_url;
  }

  // Replace token with values and return it as output.
  return str_replace(array_keys($tokens), $tokens, $output);
}