summaryrefslogtreecommitdiff
path: root/auto_prepend.php
blob: 2becb663a594b34d876e770c979b6ed8b24b1a52 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php

/****************** functions for class it_debug **********************/

/**
 * Return string containing names and values of all arguments or stack trace if no args
 */
function D(...$args)
{
	return it_debug::dump($args);
}

/**
 * Echo string containing names and values of all arguments or stack trace if no args
 */
function ED(...$args)
{
	it_debug::setup();
	it_debug::echo($args);
	return $args[0];
}

/**
 * Same as ED(), but if first argument is foo then $GLOBALS['debug_foo'] must be set for output
 * @return boolean indicating whether $GLOBALS['debug_foo'] was set
 */
function EDC($var, ...$args)
{
	$GLOBALS['ULTRADEBUGVARS'][$var] = 1;

	if (($result = $GLOBALS["debug_$var"]))
	{
		if ($args)
		{
			it_debug::setup();
			it_debug::echo($args);
		}

		if (!$result || $result === true)       # Compatibility with old map relying on 0|1
			$result = intval($result);
	}

	return $result;
}

/**
 * Echo string containing names and values of all arguments, then exit
 */
function EDX(...$args)
{
	if ($_SERVER['REMOTE_ADDR'] && !headers_sent())
		header("Content-Type: text/html"); # Not going to be e.g. a valid gif anyway

	it_debug::echo($args);
	exit();
}



/****************** functions for class it_text **********************/

/**
 * Return a text in the selected language
 * Replaces variables of the form {var} with quoted values from argument $values
 * @param $label Label of text to return
 * @param $language Optional value array (will be sent through Q()) or language string
 * @param $values Optional value array (will be sent through Q()) or language string
 * @return Localized text string
 */
function T($label, $language = null, $values = null)
{
	it_text::init();

	if (is_array($language))        # Need to swap params?
		list($language, $values) = array($values, $language);

	return $GLOBALS['it_text']->etext($label, array_map(array("it_html", "Q"), (array)$values), $language, false);
}

/**
 * Return a text in the selected language
 * Replaces variables of the form {var} with value from argument $values
 * @param $label Label of text to return
 * @param $values Associative array containing values to fill in (no quoting)
 * @param $language Optional language to return text in.
 * @return Localized text string with variables replaced by their values
 */
function ET($label, $values = null, $language = null)
{
	it_text::init();
	return $GLOBALS['it_text']->etext($label, $values, $language);
}

/**
 * Change language
 * @param $language New language to set
 */
function T_set_language($language)
{
	it_text::init();
	return $GLOBALS['it_text']->set_language($language);
}

/**
 * Get active language
 * @return currently active language
 */
function T_lang()
{
	it_text::init();
	return $GLOBALS['it_text']->get_language();
}

/**
 * Get active language
 * @return default language of browser
 */
function T_defaultlang()
{
	it_text::init();
	return $GLOBALS['it_text']->get_defaultlanguage();
}

/**
 * Get available languages
 * @return available languages as langcode => langname
 */
function T_languages()
{
	it_text::init();
	return $GLOBALS['it_text']->languages;
}

/**
 * Check if a text entry for a specific label exists
 * @param $label Label to check
 * @return label name if text exists in current (or supplied) language, false otherwise.
 */
function T_exists($label, $language = null)
{
	it_text::init();
	return $GLOBALS['it_text']->text_exists($label, $language);
}

/****************** functions for class it_text **********************/

/**
 * Build an url
 */
function U(...$args)
{
	return is_a($obj = $GLOBALS['it_html'], 'it_html') ? $obj->U(...$args) : it_html::U(...$args);
}




/************************** other functions ***************************/

/**
 * Print an error message and end page
 */
function fail($text)
{
	trigger_error($text, E_USER_ERROR);
	it::fatal($text);
}

/**
 * Global shortcut for $it_debug::debug()
 * @see it_debug::debug()
 */
function debug($text, $level=0)
{
	if (isset($GLOBALS['it_debug']))
		$GLOBALS['it_debug']->debug($text, $level);
}

/**
 * Clone an object and return copy, works for all PHP versions
 */
function &it_clone(&$object)
{
	$result = (is_object($object) && version_compare(zend_version(), 2, '>=')) ? clone($object) : $object;
	return $result;	# PHP internals need a tmp var to return by ref
}

/**
 * Experimental PHP taint support, see ftp://ftp.porcupine.org/pub/php/
 */
if (function_exists("taint"))
{
	function it_untaint($value, $marks = TC_HTML) { untaint($value, $marks); return $value; }
	function it_taintcheck($value, $marks = TC_HTML) { if (istainted($value) & $marks) { untaint($value, $marks); it::error(it_untaint("it_taintcheck($value, $marks) failed")); } return $value; }
}
else
{
	define('TC_HTML', 0);
	define('TC_SHELL', 0);
	define('TC_MYSQL', 0);
	define('TC_MYSQLI', 0);
	define('TC_SELF', 0);
	define('TC_ALL', 0);
	define('TC_NONE', 0);
	function it_untaint($value, $dummy_marks = 0) {  return $value; }
	function it_taintcheck($value, $dummy_marks = 0) { return $value; }
}

# ULTRAHOME is generated in a safe way
$GLOBALS['ULTRAHOME'] = it_untaint($GLOBALS['ULTRAHOME'], TC_ALL);

?>