aboutsummaryrefslogtreecommitdiff
path: root/start.php
blob: d83e75bcdd49d6c88d5a3d3780f1bbff0529c89b (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

function html5_init() {
	elgg_extend_view('css', 'html5/css');
	
	elgg_extend_view('js/initialise_elgg', 'js/html5');
}

function html5_get_html_attributes(array $attrs = array(), $quote_style = ENT_COMPAT, $charset = 'UTF-8', $double_encode = TRUE) {
	$attrs = html5_clean_vars($attrs);
	$attributes = array();
	
	if (isset($attrs['js'])) {
		elgg_deprecated_notice("Use of the 'js' attribute was deprecated in 1.8.  You can now use the js attributes directly.", '1.8');
		
		if (!empty($attrs['js'])) {
			$attributes[] = $attrs['js'];
		}
		
		unset($attrs['js']);
	}
	
	foreach ($attrs as $attr => $val) {
		$attr = strtolower($attr);
		
		if ($val === TRUE) {
			$attributes[] = $attr;
		} elseif (!empty($val)) {
			//allow multi-value attributes to be passed as array
			if (is_array($val)) {
				sort($val); //gzip?
				
				$val = implode(' ', $val);
			}
			
			$val = htmlspecialchars($val, $quote_style, $charset, $double_encode);
			$attributes[] = "$attr=\"$val\"";
		}
	}

	sort($attributes); //gzip?
	
	return implode(' ', $attributes);
}

// remove all the junk that elgg_view throws into $vars
function html5_clean_vars(array $vars = array()) {
	unset($vars['config']);
	unset($vars['url']);
	unset($vars['page_owner']);
	unset($vars['page_owner_user']);
	
	foreach ($_SESSION as $key => $value) {
		unset($vars[$key]);
	}
	
	// backwards compatibility code
	if (isset($vars['internalname'])) {
		$vars['name'] = $vars['internalname'];
		unset($vars['internalname']);
	}
	
	if (isset($vars['internalid'])) {
		$vars['id'] = $vars['internalid'];
		unset($vars['internalid']);
	}
	
	return $vars;
}

register_elgg_event_handler('init', 'system', 'html5_init');