BLOB streaming documentation
[phpmyadmin/crack.git] / setup / lib / common.inc.php
blob654f61195bb550629cb9e152a24d2cc0647cf75a
1 <?php
2 /**
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
8 * @version $Id$
9 */
11 // TODO: remove
12 error_reporting(E_ALL | E_STRICT);
14 define('PMA_MINIMUM_COMMON', TRUE);
15 define('PMA_SETUP', TRUE);
16 chdir('..');
18 require_once './libraries/common.inc.php';
19 require_once './libraries/url_generating.lib.php';
20 require_once './setup/lib/ConfigFile.class.php';
22 // TODO: remove
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
36 ob_start();
38 /**
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]
43 * @param string $path
44 * @param array $array
45 * @param mixed $default
46 * @return mixed array element or $default
48 function array_read($path, $array, $default = null)
50 $keys = explode('/', $path);
51 $value =& $array;
52 foreach ($keys as $key) {
53 if (!isset($value[$key])) {
54 return $default;
56 $value =& $value[$key];
58 return $value;
61 /**
62 * Stores value in an array
64 * @param string $path
65 * @param array &$array
66 * @param mixed $value
68 function array_write($path, &$array, $value)
70 $keys = explode('/', $path);
71 $last_key = array_pop($keys);
72 $a =& $array;
73 foreach ($keys as $key) {
74 if (!isset($a[$key])) {
75 $a[$key] = array();
77 $a =& $a[$key];
79 $a[$last_key] = $value;
82 /**
83 * Removes value from an array
85 * @param string $path
86 * @param array &$array
87 * @param mixed $value
89 function array_remove($path, &$array)
91 $keys = explode('/', $path);
92 $keys_last = array_pop($keys);
93 $path = array();
94 $depth = 0;
96 $path[0] =& $array;
97 $found = true;
98 // go as deep as required or possible
99 foreach ($keys as $key) {
100 if (!isset($path[$depth][$key])) {
101 $found = false;
102 break;
104 $depth++;
105 $path[$depth] =& $path[$depth-1][$key];
107 // if element found, remove it
108 if ($found) {
109 unset($path[$depth][$keys_last]);
110 $depth--;
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]]);
117 } else {
118 break;
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
130 * @return string
132 function PMA_lang($lang_key)
134 static $search, $replace;
136 // some quick cache'ing
137 if ($search === null) {
138 $replace_pairs = array(
139 '<' => '&lt;',
140 '>' => '&gt;',
141 '[em]' => '<em>',
142 '[/em]' => '</em>',
143 '[strong]' => '<strong>',
144 '[/strong]' => '</strong>',
145 '[code]' => '<code>',
146 '[/code]' => '</code>',
147 '[kbd]' => '<kbd>',
148 '[/kbd]' => '</kbd>',
149 '[br]' => '<br />',
150 '[sup]' => '<sup>',
151 '[/sup]' => '</sup>');
152 $search = array_keys($replace_pairs);
153 $replace = array_values($replace_pairs);
155 if (!isset($GLOBALS["strSetup$lang_key"])) {
156 return $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) {
164 return $message;
165 } else {
166 $args = func_get_args();
167 array_shift($args);
168 return vsprintf($message, $args);
173 * Returns translated field name
175 * @param string $canonical_path
176 * @return string
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"]
186 : $lang_key;
190 * Returns translated field description
192 * @param string $canonical_path
193 * @return string
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)
203 : '';
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
212 * @return string
214 function PMA_lang_link_replace($link, $text)
216 static $separator;
218 if (!isset($separator)) {
219 $separator = PMA_get_arg_separator('html');
222 if (!preg_match('#^http://#', $link)) {
223 $link = str_replace('&amp;', $separator, $link);
226 return '<a href="' . $link . '">' . $text . '</a>';