3 * Loads libraries/common.inc.php and preforms some additional actions
5 * @package phpMyAdmin-setup
6 * @author Piotr Przybylski <piotrprz@gmail.com>
7 * @license http://www.gnu.org/licenses/gpl.html GNU GPL 2.0
12 * Do not include full common.
15 define('PMA_MINIMUM_COMMON', TRUE);
16 define('PMA_SETUP', TRUE);
19 require_once './libraries/common.inc.php';
20 require_once './libraries/url_generating.lib.php';
21 require_once './setup/lib/ConfigFile.class.php';
23 // use default error handler
24 restore_error_handler();
26 // Save current language in a cookie, required since we use PMA_MINIMUM_COMMON
27 PMA_setCookie('pma_lang', $GLOBALS['lang']);
29 if (!isset($_SESSION['ConfigFile'])) {
30 $_SESSION['ConfigFile'] = array();
33 // allows for redirection even after sending some data
37 * Returns value of an element in $array given by $path.
38 * $path is a string describing position of an element in an associative array,
39 * eg. Servers/1/host refers to $array[Servers][1][host]
43 * @param mixed $default
44 * @return mixed array element or $default
46 function array_read($path, $array, $default = null)
48 $keys = explode('/', $path);
50 foreach ($keys as $key) {
51 if (!isset($value[$key])) {
54 $value =& $value[$key];
60 * Stores value in an array
63 * @param array &$array
66 function array_write($path, &$array, $value)
68 $keys = explode('/', $path);
69 $last_key = array_pop($keys);
71 foreach ($keys as $key) {
72 if (!isset($a[$key])) {
77 $a[$last_key] = $value;
81 * Removes value from an array
84 * @param array &$array
87 function array_remove($path, &$array)
89 $keys = explode('/', $path);
90 $keys_last = array_pop($keys);
96 // go as deep as required or possible
97 foreach ($keys as $key) {
98 if (!isset($path[$depth][$key])) {
103 $path[$depth] =& $path[$depth-1][$key];
105 // if element found, remove it
107 unset($path[$depth][$keys_last]);
111 // remove empty nested arrays
112 for (; $depth >= 0; $depth--) {
113 if (!isset($path[$depth+
1]) ||
count($path[$depth+
1]) == 0) {
114 unset($path[$depth][$keys[$depth]]);
122 * Returns sanitized language string, taking into account our special codes
123 * for formatting. Takes variable number of arguments.
124 * Based on PMA_sanitize from sanitize.lib.php.
126 * @param string $lang_key key in $GLOBALS WITHOUT 'strSetup' prefix
127 * @param mixed $args arguments for sprintf
130 function PMA_lang($lang_key)
132 static $search, $replace;
134 // some quick cache'ing
135 if ($search === null) {
136 $replace_pairs = array(
141 '[strong]' => '<strong>',
142 '[/strong]' => '</strong>',
143 '[code]' => '<code>',
144 '[/code]' => '</code>',
146 '[/kbd]' => '</kbd>',
149 '[/sup]' => '</sup>');
150 $search = array_keys($replace_pairs);
151 $replace = array_values($replace_pairs);
153 if (!isset($GLOBALS["strSetup$lang_key"])) {
156 $message = str_replace($search, $replace, $GLOBALS["strSetup$lang_key"]);
157 // replace [a@"$1"]$2[/a] with <a href="$1">$2</a>
158 $message = preg_replace('#\[a@("?)([^\]]+)\1\]([^\[]+)\[/a\]#e',
159 "PMA_lang_link_replace('$2', '$3')", $message);
161 if (func_num_args() == 1) {
164 $args = func_get_args();
166 return vsprintf($message, $args);
171 * Returns translated field name
173 * @param string $canonical_path
176 function PMA_lang_name($canonical_path)
178 $lang_key = str_replace(
179 array('Servers/1/', '/'),
180 array('Servers/', '_'),
181 $canonical_path) . '_name';
182 return isset($GLOBALS["strSetup$lang_key"])
183 ?
$GLOBALS["strSetup$lang_key"]
188 * Returns translated field description
190 * @param string $canonical_path
193 function PMA_lang_desc($canonical_path)
195 $lang_key = str_replace(
196 array('Servers/1/', '/'),
197 array('Servers/', '_'),
198 $canonical_path) . '_desc';
199 return isset($GLOBALS["strSetup$lang_key"])
200 ?
PMA_lang($lang_key)
205 * Wraps link in <a> tags and replaces argument separator in internal links
206 * to the one returned by PMA_get_arg_separator()
208 * @param string $link
209 * @param string $text
212 function PMA_lang_link_replace($link, $text)
216 if (!isset($separator)) {
217 $separator = PMA_get_arg_separator('html');
220 if (!preg_match('#^http://#', $link)) {
221 $link = str_replace('&', $separator, $link);
224 return '<a href="' . $link . '">' . $text . '</a>';