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 error_reporting(E_ALL | E_STRICT
);
14 define('PMA_MINIMUM_COMMON', TRUE);
15 define('PMA_SETUP', TRUE);
18 require_once './libraries/common.inc.php';
19 require_once './libraries/url_generating.lib.php';
20 require_once './setup/lib/ConfigFile.class.php';
23 restore_error_handler();
24 if ($error_handler->countErrors() > 0) {
25 $error_handler->dispAllErrors();
28 // Save current language in a cookie, required since we use PMA_MINIMUM_COMMON
29 PMA_setCookie('pma_lang', $GLOBALS['lang']);
31 if (!isset($_SESSION['ConfigFile'])) {
32 $_SESSION['ConfigFile'] = array();
35 // allows for redirection even after sending some data
39 * Returns value of an element in $array given by $path.
40 * $path is a string describing position of an element in an associative array,
41 * eg. Servers/1/host refers to $array[Servers][1][host]
45 * @param mixed $default
46 * @return mixed array element or $default
48 function array_read($path, $array, $default = null)
50 $keys = explode('/', $path);
52 foreach ($keys as $key) {
53 if (!isset($value[$key])) {
56 $value =& $value[$key];
62 * Stores value in an array
65 * @param array &$array
68 function array_write($path, &$array, $value)
70 $keys = explode('/', $path);
71 $last_key = array_pop($keys);
73 foreach ($keys as $key) {
74 if (!isset($a[$key])) {
79 $a[$last_key] = $value;
83 * Removes value from an array
86 * @param array &$array
89 function array_remove($path, &$array)
91 $keys = explode('/', $path);
92 $keys_last = array_pop($keys);
98 // go as deep as required or possible
99 foreach ($keys as $key) {
100 if (!isset($path[$depth][$key])) {
105 $path[$depth] =& $path[$depth-1][$key];
107 // if element found, remove it
109 unset($path[$depth][$keys_last]);
113 // remove empty nested arrays
114 for (; $depth >= 0; $depth--) {
115 if (!isset($path[$depth+
1]) ||
count($path[$depth+
1]) == 0) {
116 unset($path[$depth][$keys[$depth]]);
124 * Returns sanitized language string, taking into account our special codes
125 * for formatting. Takes variable number of arguments.
126 * Based on PMA_sanitize from sanitize.lib.php.
128 * @param string $lang_key key in $GLOBALS WITHOUT 'strSetup' prefix
129 * @param mixed $args arguments for sprintf
132 function PMA_lang($lang_key)
134 static $search, $replace;
136 // some quick cache'ing
137 if ($search === null) {
138 $replace_pairs = array(
143 '[strong]' => '<strong>',
144 '[/strong]' => '</strong>',
145 '[code]' => '<code>',
146 '[/code]' => '</code>',
148 '[/kbd]' => '</kbd>',
151 '[/sup]' => '</sup>');
152 $search = array_keys($replace_pairs);
153 $replace = array_values($replace_pairs);
155 if (!isset($GLOBALS["strSetup$lang_key"])) {
158 $message = str_replace($search, $replace, $GLOBALS["strSetup$lang_key"]);
159 // replace [a@"$1"]$2[/a] with <a href="$1">$2</a>
160 $message = preg_replace('#\[a@("?)([^\]]+)\1\]([^\[]+)\[/a\]#e',
161 "PMA_lang_link_replace('$2', '$3')", $message);
163 if (func_num_args() == 1) {
166 $args = func_get_args();
168 return vsprintf($message, $args);
173 * Returns translated field name
175 * @param string $canonical_path
178 function PMA_lang_name($canonical_path)
180 $lang_key = str_replace(
181 array('Servers/1/', '/'),
182 array('Servers/', '_'),
183 $canonical_path) . '_name';
184 return isset($GLOBALS["strSetup$lang_key"])
185 ?
$GLOBALS["strSetup$lang_key"]
190 * Returns translated field description
192 * @param string $canonical_path
195 function PMA_lang_desc($canonical_path)
197 $lang_key = str_replace(
198 array('Servers/1/', '/'),
199 array('Servers/', '_'),
200 $canonical_path) . '_desc';
201 return isset($GLOBALS["strSetup$lang_key"])
202 ?
PMA_lang($lang_key)
207 * Wraps link in <a> tags and replaces argument separator in internal links
208 * to the one returned by PMA_get_arg_separator()
210 * @param string $link
211 * @param string $text
214 function PMA_lang_link_replace($link, $text)
218 if (!isset($separator)) {
219 $separator = PMA_get_arg_separator('html');
222 if (!preg_match('#^http://#', $link)) {
223 $link = str_replace('&', $separator, $link);
226 return '<a href="' . $link . '">' . $text . '</a>';