aboutsummaryrefslogtreecommitdiff
path: root/views/default/output/url.php
blob: 8ea84d3d66057881e1b55d796f96f55f5dc75b50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
 * Elgg URL display
 * Displays a URL as a link
 *
 * @package Elgg
 * @subpackage Core
 *
 * @uses string $vars['text']        The string between the <a></a> tags.
 * @uses string $vars['href']        The unencoded url string
 * @uses bool   $vars['encode_text'] Run $vars['text'] through htmlspecialchars()?
 * @uses bool   $vars['is_action']   Is this a link to an action?
 *
 */

$url = trim($vars['href']);
if (!$url and isset($vars['value'])) {
	$url = trim($vars['value']);
	unset($vars['value']);
}

if (!empty($url)) {
	if (isset($vars['text'])) {
		if (isset($vars['encode_text']) && $vars['encode_text']) {
			$text = htmlspecialchars($vars['text'], ENT_QUOTES, 'UTF-8');
		} else {
			$text = $vars['text'];
		}

		unset($vars['text']);
	} else {
		$text = htmlspecialchars($url, ENT_QUOTES, 'UTF-8');
	}

	unset($vars['encode_text']);

	$url = elgg_normalize_url($url);

	if (isset($vars['is_action'])) {
		$url = elgg_add_action_tokens_to_url($url, FALSE);
		unset($vars['is_action']);
	}

	$vars['href'] = $url;

	$attributes = elgg_format_attributes($vars);
	echo "<a $attributes>$text</a>";
}