Elgg  Version 2.3
url.php
Go to the documentation of this file.
1 <?php
22 if (!empty($vars['confirm']) && !isset($vars['is_action'])) {
23  $vars['is_action'] = true;
24 }
25 
26 if (!empty($vars['confirm'])) {
27  $vars['data-confirm'] = elgg_extract('confirm', $vars, elgg_echo('question:areyousure'));
28 
29  // if (bool) true use defaults
30  if ($vars['data-confirm'] === true) {
31  $vars['data-confirm'] = elgg_echo('question:areyousure');
32  }
33 }
34 
35 $url = elgg_extract('href', $vars, null);
36 if (!$url && isset($vars['value'])) {
37  $url = trim($vars['value']);
38  unset($vars['value']);
39 }
40 
41 if (isset($vars['text'])) {
42  if (elgg_extract('encode_text', $vars, false)) {
43  $text = htmlspecialchars($vars['text'], ENT_QUOTES, 'UTF-8', false);
44  } else {
45  $text = $vars['text'];
46  }
47  unset($vars['text']);
48 } else {
49  $text = htmlspecialchars($url, ENT_QUOTES, 'UTF-8', false);
50 }
51 
52 unset($vars['encode_text']);
53 
54 if ($url) {
56 
57  if (elgg_extract('is_action', $vars, false)) {
59  }
60 
61  $is_trusted = elgg_extract('is_trusted', $vars);
62  if (!$is_trusted) {
63  $url = strip_tags($url);
64  if (!isset($vars['rel'])) {
65  if ($is_trusted === null) {
66  $url_host = parse_url($url, PHP_URL_HOST);
68  $site_url_host = parse_url($site_url, PHP_URL_HOST);
69  $is_trusted = $url_host == $site_url_host;
70  }
71  if ($is_trusted === false) {
72  // this is an external URL, which we do not want to be indexed by crawlers
73  $vars['rel'] = 'nofollow';
74  }
75  }
76  }
77 
78  $vars['href'] = $url;
79 }
80 
81 if (!isset($vars['title']) && isset($vars['data-confirm'])) {
82  $vars['title'] = $vars['data-confirm'];
83 }
84 
85 unset($vars['is_action']);
86 unset($vars['is_trusted']);
87 unset($vars['confirm']);
88 
90 echo "<a $attributes>$text</a>";
$attributes
Definition: url.php:89
elgg_add_action_tokens_to_url($url, $html_encode=false)
Adds action tokens to URL.
Definition: elgglib.php:1151
elgg_normalize_url($url)
Definition: output.php:280
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
elgg parse_url
Parse a URL into its parts.
Definition: elgglib.js:450
if(!empty($vars['confirm'])&&!isset($vars['is_action'])) if(!empty($vars['confirm'])) $url
Definition: url.php:35
$text
Definition: default.php:25
$site_url
Definition: header_logo.php:8
elgg echo
Translates a string.
Definition: languages.js:48
elgg_get_site_url($site_guid=0)
Get the URL for the current (or specified) site.
elgg_format_attributes(array $attrs=array())
Converts an associative array into a string of well-formed HTML/XML attributes Returns a concatenated...
Definition: output.php:129
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1375
$vars['class']
Definition: url.php:12