3 * Loads libraries/common.inc.php and preforms some additional actions
5 * @package phpMyAdmin-setup
6 * @license http://www.gnu.org/licenses/gpl.html GNU GPL 2.0
11 * Do not include full common.
14 define('PMA_MINIMUM_COMMON', TRUE);
15 define('PMA_SETUP', TRUE);
18 if (!file_exists('./libraries/common.inc.php')) {
19 die('Bad invocation!');
22 require_once './libraries/common.inc.php';
23 require_once './libraries/url_generating.lib.php';
24 require_once './setup/lib/messages.inc.php';
25 require_once './setup/lib/ConfigFile.class.php';
27 // use default error handler
28 restore_error_handler();
30 // Save current language in a cookie, required since we use PMA_MINIMUM_COMMON
31 $GLOBALS['PMA_Config']->setCookie('pma_lang', $GLOBALS['lang']);
33 if (!isset($_SESSION['ConfigFile'])) {
34 $_SESSION['ConfigFile'] = array();
37 // allows for redirection even after sending some data
41 * Returns value of an element in $array given by $path.
42 * $path is a string describing position of an element in an associative array,
43 * eg. Servers/1/host refers to $array[Servers][1][host]
47 * @param mixed $default
48 * @return mixed array element or $default
50 function array_read($path, $array, $default = null)
52 $keys = explode('/', $path);
54 foreach ($keys as $key) {
55 if (!isset($value[$key])) {
58 $value =& $value[$key];
64 * Stores value in an array
67 * @param array &$array
70 function array_write($path, &$array, $value)
72 $keys = explode('/', $path);
73 $last_key = array_pop($keys);
75 foreach ($keys as $key) {
76 if (!isset($a[$key])) {
81 $a[$last_key] = $value;
85 * Removes value from an array
88 * @param array &$array
91 function array_remove($path, &$array)
93 $keys = explode('/', $path);
94 $keys_last = array_pop($keys);
100 // go as deep as required or possible
101 foreach ($keys as $key) {
102 if (!isset($path[$depth][$key])) {
107 $path[$depth] =& $path[$depth-1][$key];
109 // if element found, remove it
111 unset($path[$depth][$keys_last]);
115 // remove empty nested arrays
116 for (; $depth >= 0; $depth--) {
117 if (!isset($path[$depth+
1]) ||
count($path[$depth+
1]) == 0) {
118 unset($path[$depth][$keys[$depth]]);
126 * Returns sanitized language string, taking into account our special codes
127 * for formatting. Takes variable number of arguments.
128 * Based on PMA_sanitize from sanitize.lib.php.
130 * @param string $lang_key key in $GLOBALS WITHOUT 'strSetup' prefix
131 * @param mixed $args arguments for sprintf
134 function PMA_lang($lang_key)
136 static $search, $replace;
138 // some quick cache'ing
139 if ($search === null) {
140 $replace_pairs = array(
145 '[strong]' => '<strong>',
146 '[/strong]' => '</strong>',
147 '[code]' => '<code>',
148 '[/code]' => '</code>',
150 '[/kbd]' => '</kbd>',
153 '[/sup]' => '</sup>');
154 $search = array_keys($replace_pairs);
155 $replace = array_values($replace_pairs);
157 if (!isset($GLOBALS["strSetup$lang_key"])) {
160 $message = str_replace($search, $replace, $GLOBALS["strSetup$lang_key"]);
161 // replace [a@"$1"]$2[/a] with <a href="$1">$2</a>
162 $message = preg_replace('#\[a@("?)([^\]]+)\1\]([^\[]+)\[/a\]#e',
163 "PMA_lang_link_replace('$2', '$3')", $message);
165 if (func_num_args() == 1) {
168 $args = func_get_args();
170 return vsprintf($message, $args);
175 * Returns translated field name
177 * @param string $canonical_path
180 function PMA_lang_name($canonical_path)
182 $lang_key = str_replace(
183 array('Servers/1/', '/'),
184 array('Servers/', '_'),
185 $canonical_path) . '_name';
186 return isset($GLOBALS["strSetup$lang_key"])
187 ?
$GLOBALS["strSetup$lang_key"]
192 * Returns translated field description
194 * @param string $canonical_path
197 function PMA_lang_desc($canonical_path)
199 $lang_key = str_replace(
200 array('Servers/1/', '/'),
201 array('Servers/', '_'),
202 $canonical_path) . '_desc';
203 return isset($GLOBALS["strSetup$lang_key"])
204 ?
PMA_lang($lang_key)
209 * Wraps link in <a> tags and replaces argument separator in internal links
210 * to the one returned by PMA_get_arg_separator()
212 * @param string $link
213 * @param string $text
216 function PMA_lang_link_replace($link, $text)
220 if (!isset($separator)) {
221 $separator = PMA_get_arg_separator('html');
224 if (!preg_match('#^http://#', $link)) {
225 $link = str_replace('&', $separator, $link);
228 return '<a href="' . $link . '">' . $text . '</a>';