Elgg  Version 1.12
url.php
Go to the documentation of this file.
1 <?php
20 if (!empty($vars['confirm']) && !isset($vars['is_action'])) {
21  $vars['is_action'] = true;
22 }
23 
24 if (!empty($vars['confirm'])) {
25  $vars['data-confirm'] = elgg_extract('confirm', $vars, elgg_echo('question:areyousure'));
26 
27  // if (bool) true use defaults
28  if ($vars['data-confirm'] === true) {
29  $vars['data-confirm'] = elgg_echo('question:areyousure');
30  }
31 }
32 
33 $url = elgg_extract('href', $vars, null);
34 if (!$url && isset($vars['value'])) {
35  $url = trim($vars['value']);
36  unset($vars['value']);
37 }
38 
39 if (isset($vars['text'])) {
40  if (elgg_extract('encode_text', $vars, false)) {
41  $text = htmlspecialchars($vars['text'], ENT_QUOTES, 'UTF-8', false);
42  } else {
43  $text = $vars['text'];
44  }
45  unset($vars['text']);
46 } else {
47  $text = htmlspecialchars($url, ENT_QUOTES, 'UTF-8', false);
48 }
49 
50 unset($vars['encode_text']);
51 
52 if ($url) {
54 
55  if (elgg_extract('is_action', $vars, false)) {
57  }
58 
59  $is_trusted = elgg_extract('is_trusted', $vars);
60  if (!$is_trusted) {
61  $url = strip_tags($url);
62  if (!isset($vars['rel'])) {
63  if ($is_trusted === null) {
64  $url_host = parse_url($url, PHP_URL_HOST);
66  $site_url_host = parse_url($site_url, PHP_URL_HOST);
67  $is_trusted = $url_host == $site_url_host;
68  }
69  if ($is_trusted === false) {
70  // this is an external URL, which we do not want to be indexed by crawlers
71  $vars['rel'] = 'nofollow';
72  }
73  }
74  }
75 
76  $vars['href'] = $url;
77 }
78 
79 if (!isset($vars['title']) && isset($vars['data-confirm'])) {
80  $vars['title'] = $vars['data-confirm'];
81 }
82 
83 unset($vars['is_action']);
84 unset($vars['is_trusted']);
85 unset($vars['confirm']);
86 
88 echo "<a $attributes>$text</a>";
$attributes
Definition: url.php:87
elgg_add_action_tokens_to_url($url, $html_encode=false)
Adds action tokens to URL.
Definition: elgglib.php:1084
elgg_normalize_url($url)
Definition: output.php:311
elgg parse_url
Parse a URL into its parts.
Definition: elgglib.js:421
if(!empty($vars['confirm'])&&!isset($vars['is_action'])) if(!empty($vars['confirm'])) $url
Definition: url.php:33
$text
Definition: default.php:25
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
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 attributes.
Definition: output.php:139
$site_url
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:1271
$vars['class']
Definition: url.php:12