aboutsummaryrefslogtreecommitdiff
path: root/views/default/output/url.php
blob: 76bfdc1ef5594b2f40cacf8041f7ceaad2f88c51 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
 * Elgg URL display
 * Displays a URL as a link
 *
 * @package Elgg
 * @subpackage Core
 * @author Curverider Ltd
 * @link http://elgg.org/
 *
 * @uses string $vars['href'] The URL.
 * @uses string $vars['text'] The string between the <a></a> tags.
 * @uses string $vars['target'] Set the target="" attribute.
 * @uses bool $vars['encode_text'] Run $vars['text'] through htmlentities()?
 * @uses string $vars['class'] what to add in class=""
 * @uses string $vars['js'] Javascript to insert in <a> tag
 * @uses string $vars['title'] Title attribute to <a> tag
 * @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']);
}

if (!empty($url)) {
	if (array_key_exists('target', $vars) && $vars['target']) {
		$target = "target = \"{$vars['target']}\"";
	} else {
		$target = '';
	}

	if (array_key_exists('class', $vars) && $vars['class']) {
		$class = "class = \"{$vars['class']}\"";
	} else {
		$class = '';
	}

	if (array_key_exists('js', $vars) && $vars['js']) {
		$js = "{$vars['target']}";
	} else {
		$js = '';
	}

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

	if ((substr_count($url, "http://") == 0) && (substr_count($url, "https://") == 0)) {
		$url = "http://" . $url;
	}

	if (array_key_exists('is_action', $vars) && $vars['is_action']) {
		$url = elgg_add_action_tokens_to_url($url);
	}

	if (isset($vars['title'])) {
		$title = 'title="' . htmlentities($vars['title']) . '"';
	} else {
		$title = '';
	}

	echo "<a href=\"{$url}\" $target $class $js $title>$text</a>";
}