Elgg  Version 3.0
url.php
Go to the documentation of this file.
1 <?php
25 $excerpt_length = elgg_extract('excerpt_length', $vars, 100);
26 unset($vars['excerpt_length']);
27 
28 if (!empty($vars['confirm']) && !isset($vars['is_action'])) {
29  $vars['is_action'] = true;
30 }
31 
32 if (!empty($vars['confirm'])) {
33  $vars['data-confirm'] = elgg_extract('confirm', $vars, elgg_echo('question:areyousure'));
34 
35  // if (bool) true use defaults
36  if ($vars['data-confirm'] === true) {
37  $vars['data-confirm'] = elgg_echo('question:areyousure');
38  }
39 }
40 
41 $url = elgg_extract('href', $vars, null);
42 if ($url === false) {
43  $url = 'javascript:void(0);';
44 }
45 
46 if (!$url && isset($vars['value'])) {
47  $url = trim($vars['value']);
48  unset($vars['value']);
49 }
50 
51 if (isset($vars['text'])) {
52  if (elgg_extract('encode_text', $vars, false)) {
53  $text = htmlspecialchars($vars['text'], ENT_QUOTES, 'UTF-8', false);
54  } else {
55  $text = elgg_extract('text', $vars);
56  }
57  unset($vars['text']);
58 } else {
59  $text = htmlspecialchars(elgg_get_excerpt($url, $excerpt_length), ENT_QUOTES, 'UTF-8', false);
60 }
61 
62 unset($vars['encode_text']);
63 
64 if ($url) {
66 
67  if (elgg_extract('is_action', $vars, false)) {
69  }
70 
71  $is_trusted = elgg_extract('is_trusted', $vars);
72  if (!$is_trusted) {
73  $url = strip_tags($url);
74  if (!isset($vars['rel'])) {
75  if ($is_trusted === null) {
76  $url_host = parse_url($url, PHP_URL_HOST);
78  $site_url_host = parse_url($site_url, PHP_URL_HOST);
79  $is_trusted = $url_host == $site_url_host;
80  }
81  if ($is_trusted === false) {
82  // this is an external URL, which we do not want to be indexed by crawlers
83  $vars['rel'] = 'nofollow';
84  }
85  }
86  }
87 
88  $vars['href'] = $url;
89 }
90 
91 if (!isset($vars['title']) && isset($vars['data-confirm'])) {
92  $vars['title'] = elgg_extract('data-confirm', $vars);
93 }
94 
95 unset($vars['is_action']);
96 unset($vars['is_trusted']);
97 unset($vars['confirm']);
98 
99 $vars['class'] = elgg_extract_class($vars, 'elgg-anchor');
100 
101 if ($text !== false && $text !== '') {
102  $text = elgg_format_element('span', [
103  'class' => 'elgg-anchor-label',
104  ], $text);
105 }
106 
107 $icon = elgg_extract('icon', $vars, '');
108 unset($vars['icon']);
109 
110 if ($icon && !preg_match('/^</', $icon)) {
112  'class' => 'elgg-anchor-icon',
113  ]);
114 }
115 
116 $icon_alt = elgg_extract('icon_alt', $vars, '');
117 unset($vars['icon_alt']);
118 
119 if ($icon_alt && !preg_match('/^</', $icon_alt)) {
121  'class' => 'elgg-anchor-icon-alt',
122  ]);
123 }
124 
126 unset($vars['badge']);
127 
128 if (!is_null($badge)) {
130  '#tag_name' => 'span',
131  '#text' => $badge,
132  'class' => 'elgg-badge',
133  ]);
134 }
135 
elgg_add_action_tokens_to_url($url, $html_encode=false)
Adds action tokens to URL.
Definition: elgglib.php:894
if($text!==false &&$text!== '') $icon
Definition: url.php:107
elgg_normalize_url($url)
Definition: output.php:186
$excerpt_length
Definition: url.php:25
if($icon_alt &&!preg_match('/^</', $icon_alt) $badge)
Definition: url.php:125
elgg parse_url
Parse a URL into its parts.
Definition: elgglib.js:442
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:1153
if(!empty($vars['confirm'])&&!isset($vars['is_action'])) if(!empty($vars['confirm'])) $url
Definition: url.php:41
if($icon &&!preg_match('/^</', $icon) $icon_alt)
Definition: url.php:116
$text
Definition: default.php:28
elgg_format_element($tag_name, array $attributes=[], $text= '', array $options=[])
Format an HTML element.
Definition: output.php:168
elgg echo
Translates a string.
Definition: languages.js:43
elgg_get_site_url()
Get the URL for the current (or specified) site, ending with "/".
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:1131
$vars['class']
Definition: url.php:12
elgg_view_icon($name, $vars=[])
View an icon glyph.
Definition: views.php:1552
$site_url
Definition: upgrade.php:3
elgg_get_excerpt($text, $num_chars=250)
Returns an excerpt.
Definition: output.php:74