Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 846 lines (789 sloc) 24.723 kb
667bfec4 » jakubvrana
2007-07-02 Decomposition
1 <?php
9a176b0c » jakubvrana
2009-08-31 Comments
2 /** Get database connection
3 * @return Min_DB
4 */
64d616c0 » jakubvrana
2009-09-22 Rename get_dbh to connection
5 function connection() {
6 // can be used in customization, $connection is minified
7 global $connection;
8 return $connection;
c64c4fd1 » jakubvrana
2009-07-27 Adminer class
9 }
10
9a176b0c » jakubvrana
2009-08-31 Comments
11 /** Unescape database identifier
12 * @param string text inside ``
13 * @return string
14 */
667bfec4 » jakubvrana
2007-07-02 Decomposition
15 function idf_unescape($idf) {
a29ac72c » jakubvrana
2010-04-21 Improve drivers
16 $last = substr($idf, -1);
17 return str_replace($last . $last, $last, substr($idf, 1, -1));
667bfec4 » jakubvrana
2007-07-02 Decomposition
18 }
19
5e01a627 » jakubvrana
2009-10-16 Prepare for SQLite
20 /** Escape string to use inside ''
21 * @param string
22 * @return string
23 */
24 function escape_string($val) {
7e644b43 »
2010-10-13 Save bytes ($connection->quote shortcut)
25 return substr(q($val), 1, -1);
5e01a627 » jakubvrana
2009-10-16 Prepare for SQLite
26 }
27
72f4d9e2 »
2010-07-26 Function parse_str respects magic_quotes_gpc (bug #3034575)
28 /** Disable magic_quotes_gpc
29 * @param array e.g. (&$_GET, &$_POST, &$_COOKIE)
30 * @return null modified in place
31 */
32 function remove_slashes($process) {
33 if (get_magic_quotes_gpc()) {
34 while (list($key, $val) = each($process)) {
35 foreach ($val as $k => $v) {
36 unset($process[$key][$k]);
37 if (is_array($v)) {
38 $process[$key][stripslashes($k)] = $v;
39 $process[] = &$process[$key][stripslashes($k)];
40 } else {
41 $process[$key][stripslashes($k)] = ($filter ? $v : stripslashes($v));
42 }
43 }
44 }
45 }
46 }
47
9a176b0c » jakubvrana
2009-08-31 Comments
48 /** Escape or unescape string to use inside form []
49 * @param string
50 * @param bool
51 * @return string
52 */
667bfec4 » jakubvrana
2007-07-02 Decomposition
53 function bracket_escape($idf, $back = false) {
64ba9242 » jakubvrana
2009-06-21 Comments
54 // escape brackets inside name="x[]"
73e8631b » jakubvrana
2007-07-09 Move stuff to functions.inc.php
55 static $trans = array(':' => ':1', ']' => ':2', '[' => ':3');
667bfec4 » jakubvrana
2007-07-02 Decomposition
56 return strtr($idf, ($back ? array_flip($trans) : $trans));
57 }
58
9a176b0c » jakubvrana
2009-08-31 Comments
59 /** Escape for HTML
60 * @param string
61 * @return string
62 */
689699aa » jakubvrana
2009-07-28 Shortcut for htmlspecialchars
63 function h($string) {
64 return htmlspecialchars($string, ENT_QUOTES);
65 }
66
9a176b0c » jakubvrana
2009-08-31 Comments
67 /** Escape for TD
68 * @param string
69 * @return string
70 */
c1969850 » jakubvrana
2009-08-25 Function nbsp
71 function nbsp($string) {
7352c281 » jakubvrana
2010-01-09 Replace strlen() by != ""
72 return (trim($string) != "" ? h($string) : "&nbsp;");
c1969850 » jakubvrana
2009-08-25 Function nbsp
73 }
74
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
75 /** Convert \n to <br>
76 * @param string
77 * @return string
78 */
79 function nl_br($string) {
80 return str_replace("\n", "<br>", $string); // nl2br() uses XHTML before PHP 5.3
81 }
82
6b30cfa7 » jakubvrana
2009-09-25 Separate checkbox
83 /** Generate HTML checkbox
84 * @param string
85 * @param string
86 * @param bool
87 * @param string
88 * @param string
89 * @return string
90 */
91 function checkbox($name, $value, $checked, $label = "", $onclick = "") {
c4fe12a1 » jakubvrana
2009-09-26 Clickable labels in IE6
92 static $id = 0;
93 $id++;
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
94 $return = "<input type='checkbox'" . ($name ? " name='$name' value='" . h($value) . "'" : "") . ($checked ? " checked" : "") . ($onclick ? " onclick=\"$onclick\"" : "") . " id='checkbox-$id'>";
7352c281 » jakubvrana
2010-01-09 Replace strlen() by != ""
95 return ($label != "" ? "<label for='checkbox-$id'>$return" . h($label) . "</label>" : $return);
6b30cfa7 » jakubvrana
2009-09-25 Separate checkbox
96 }
97
9a176b0c » jakubvrana
2009-08-31 Comments
98 /** Generate list of HTML options
99 * @param array array of strings or arrays (creates optgroup)
100 * @param mixed
101 * @param bool always use array keys for value="", otherwise only string keys are used
102 * @return string
103 */
1e4d11e9 » jakubvrana
2009-07-23 Select from foreign keys in Editor
104 function optionlist($options, $selected = null, $use_keys = false) {
667bfec4 » jakubvrana
2007-07-02 Decomposition
105 $return = "";
106 foreach ($options as $k => $v) {
107 if (is_array($v)) {
689699aa » jakubvrana
2009-07-28 Shortcut for htmlspecialchars
108 $return .= '<optgroup label="' . h($k) . '">';
667bfec4 » jakubvrana
2007-07-02 Decomposition
109 }
ced9de9d » jakubvrana
2009-07-02 Create single column foreign key in table structure
110 foreach ((is_array($v) ? $v : array($k => $v)) as $key => $val) {
cb6d36c0 » jakubvrana
2009-07-28 HTML instead of XHTML
111 $return .= '<option' . ($use_keys || is_string($key) ? ' value="' . h($key) . '"' : '') . (($use_keys || is_string($key) ? (string) $key : $val) === $selected ? ' selected' : '') . '>' . h($val);
667bfec4 » jakubvrana
2007-07-02 Decomposition
112 }
113 if (is_array($v)) {
114 $return .= '</optgroup>';
115 }
116 }
117 return $return;
118 }
119
098b74b6 » jakubvrana
2009-11-09 Move function
120 /** Generate HTML radio list
121 * @param string
122 * @param array
123 * @param string
124 * @param string true for no onchange, false for radio
125 * @return string
126 */
127 function html_select($name, $options, $value = "", $onchange = true) {
128 if ($onchange) {
129 return "<select name='" . h($name) . "'" . (is_string($onchange) ? " onchange=\"$onchange\"" : "") . ">" . optionlist($options, $value) . "</select>";
130 }
131 $return = "";
132 foreach ($options as $key => $val) {
133 $return .= "<label><input type='radio' name='" . h($name) . "' value='" . h($key) . "'" . ($key == $value ? " checked" : "") . ">" . h($val) . "</label>";
134 }
135 return $return;
136 }
137
a93bc191 »
2010-10-18 Create confirm function
138 /** Get onclick confirmation
139 * @param string JavaScript expression
b7cd6520 »
2010-11-26 No AJAX in drop table, drop database and logout
140 * @param bool stop event propagation
a93bc191 »
2010-10-18 Create confirm function
141 * @return string
142 */
b7cd6520 »
2010-11-26 No AJAX in drop table, drop database and logout
143 function confirm($count = "", $stop = false) {
144 return " onclick=\"" . ($stop ? "eventStop(event); " : "") . "return confirm('" . lang('Are you sure?') . ($count ? " (' + $count + ')" : "") . "');\"";
a93bc191 »
2010-10-18 Create confirm function
145 }
146
28f21aaa »
2010-10-22 Escape JavaScript strings (bug #3093243)
147 /** Escape string for JavaScript apostrophes
148 * @param string
149 * @return string
150 */
151 function js_escape($string) {
152 return addcslashes($string, "\r\n'\\/"); // slash for <script>
153 }
154
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
155 /** Get INI boolean value
156 * @param string
157 * @return bool
158 */
159 function ini_bool($ini) {
160 $val = ini_get($ini);
161 return (eregi('^(on|true|yes)$', $val) || (int) $val); // boolean values set by php_value are strings
162 }
163
f30fd121 »
2010-12-20 Work without session.use_cookies (bug #3138640)
164 /** Check if SID is neccessary
165 * @return bool
166 */
167 function sid() {
876af589 »
2010-12-29 Fix sid function
168 static $return;
169 if (!isset($return)) { // restart_session() defines SID
170 $return = (SID && !($_COOKIE && ini_bool("session.use_cookies"))); // $_COOKIE - don't pass SID with permanent login
171 }
172 return $return;
f30fd121 »
2010-12-20 Work without session.use_cookies (bug #3138640)
173 }
174
175 /** Shortcut for $connection->quote($string)
176 * @param string
177 * @return string
178 */
7e644b43 »
2010-10-13 Save bytes ($connection->quote shortcut)
179 function q($string) {
180 global $connection;
181 return $connection->quote($string);
182 }
183
9a176b0c » jakubvrana
2009-08-31 Comments
184 /** Get list of values from database
185 * @param string
186 * @param mixed
187 * @return array
188 */
0bd864ea » jakubvrana
2009-05-21 Allow specifying column in get_vals
189 function get_vals($query, $column = 0) {
64d616c0 » jakubvrana
2009-09-22 Rename get_dbh to connection
190 global $connection;
7769f2c6 » jakubvrana
2007-07-11 Separate get_vals
191 $return = array();
64d616c0 » jakubvrana
2009-09-22 Rename get_dbh to connection
192 $result = $connection->query($query);
b84252fc » jakubvrana
2010-04-21 Display SQLite compile options
193 if (is_object($result)) {
49f7886f » jakubvrana
2008-09-30 SHOW DATABASES can be revoked
194 while ($row = $result->fetch_row()) {
0bd864ea » jakubvrana
2009-05-21 Allow specifying column in get_vals
195 $return[] = $row[$column];
49f7886f » jakubvrana
2008-09-30 SHOW DATABASES can be revoked
196 }
7769f2c6 » jakubvrana
2007-07-11 Separate get_vals
197 }
198 return $return;
199 }
200
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
201 /** Get keys from first column and values from second
202 * @param string
203 * @param Min_DB
204 * @return array
205 */
206 function get_key_vals($query, $connection2 = null) {
207 global $connection;
208 if (!is_object($connection2)) {
209 $connection2 = $connection;
210 }
211 $return = array();
212 $result = $connection2->query($query);
e26b1864 »
2011-01-31 Avoid fatal error (bug #3110257)
213 if (is_object($result)) {
214 while ($row = $result->fetch_row()) {
215 $return[$row[0]] = $row[1];
216 }
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
217 }
218 return $return;
219 }
220
b0d637b6 »
2010-10-13 Avoid fatal errors
221 /** Get all rows of result
222 * @param string
223 * @return array associative
224 */
96544baf »
2010-10-13 Report errors in get_rows()
225 function get_rows($query, $connection2 = null, $error = "<p class='error'>") {
b0d637b6 »
2010-10-13 Avoid fatal errors
226 global $connection;
227 if (!is_object($connection2)) {
228 $connection2 = $connection;
229 }
230 $return = array();
231 $result = $connection2->query($query);
232 if (is_object($result)) { // can return true
233 while ($row = $result->fetch_assoc()) {
234 $return[] = $row;
235 }
850d1aa1 »
2010-12-29 Report errors only
236 } elseif (!$result && $connection->error && $error && defined("PAGE_HEADER")) {
96544baf »
2010-10-13 Report errors in get_rows()
237 echo $error . error() . "\n";
b0d637b6 »
2010-10-13 Avoid fatal errors
238 }
239 return $return;
240 }
241
9a176b0c » jakubvrana
2009-08-31 Comments
242 /** Find unique identifier of a row
243 * @param array
244 * @param array result of indexes()
35ec64c6 » jakubvrana
2010-04-02 Link COUNT(*) result to listing
245 * @return array
9a176b0c » jakubvrana
2009-08-31 Comments
246 */
35ec64c6 » jakubvrana
2010-04-02 Link COUNT(*) result to listing
247 function unique_array($row, $indexes) {
720f5fc8 » jakubvrana
2007-07-05 Restructure indexes
248 foreach ($indexes as $index) {
4b3d569a » jakubvrana
2009-10-07 Save bytes
249 if (ereg("PRIMARY|UNIQUE", $index["type"])) {
720f5fc8 » jakubvrana
2007-07-05 Restructure indexes
250 $return = array();
251 foreach ($index["columns"] as $key) {
64ba9242 » jakubvrana
2009-06-21 Comments
252 if (!isset($row[$key])) { // NULL is ambiguous
720f5fc8 » jakubvrana
2007-07-05 Restructure indexes
253 continue 2;
667bfec4 » jakubvrana
2007-07-02 Decomposition
254 }
35ec64c6 » jakubvrana
2010-04-02 Link COUNT(*) result to listing
255 $return[$key] = $row[$key];
667bfec4 » jakubvrana
2007-07-02 Decomposition
256 }
720f5fc8 » jakubvrana
2007-07-05 Restructure indexes
257 return $return;
667bfec4 » jakubvrana
2007-07-02 Decomposition
258 }
259 }
260 $return = array();
261 foreach ($row as $key => $val) {
26c9d64b » jakubvrana
2009-08-19 Fix long SQL query crash (bug #2839231)
262 if (!preg_match('~^(COUNT\\((\\*|(DISTINCT )?`(?:[^`]|``)+`)\\)|(AVG|GROUP_CONCAT|MAX|MIN|SUM)\\(`(?:[^`]|``)+`\\))$~', $key)) { //! columns looking like functions
35ec64c6 » jakubvrana
2010-04-02 Link COUNT(*) result to listing
263 $return[$key] = $val;
988a29fc » jakubvrana
2009-07-28 Don't use aggregation functions in unique_idf
264 }
430034c3 » jakubvrana
2007-07-09 Cottage homework
265 }
266 return $return;
267 }
268
9a176b0c » jakubvrana
2009-08-31 Comments
269 /** Create SQL condition from parsed query string
270 * @param array parsed query string
271 * @return string
272 */
9ea31125 » jakubvrana
2008-08-08 Mandatory $where in where()
273 function where($where) {
1a8d7f17 »
2010-10-16 Use LIKE for text comparison in MS SQL (bug #3088222)
274 global $jush;
430034c3 » jakubvrana
2007-07-09 Cottage homework
275 $return = array();
341362a8 » jakubvrana
2010-04-23 Driver specific INSERT INTO
276 foreach ((array) $where["where"] as $key => $val) {
66ff1531 » jakubvrana
2010-04-26 Use bracket_escape function
277 $return[] = idf_escape(bracket_escape($key, 1)) // 1 - back
1a8d7f17 »
2010-10-16 Use LIKE for text comparison in MS SQL (bug #3088222)
278 . (ereg('\\.', $val) || $jush == "mssql" ? " LIKE " . exact_value(addcslashes($val, "%_")) : " = " . exact_value($val)) // LIKE because of floats, but slow with ints, in MS SQL because of text
66ff1531 » jakubvrana
2010-04-26 Use bracket_escape function
279 ; //! enum and set
341362a8 » jakubvrana
2010-04-23 Driver specific INSERT INTO
280 }
281 foreach ((array) $where["null"] as $key) {
282 $return[] = idf_escape($key) . " IS NULL";
667bfec4 » jakubvrana
2007-07-02 Decomposition
283 }
c16c57b1 » jakubvrana
2009-07-11 E-mail sending
284 return implode(" AND ", $return);
667bfec4 » jakubvrana
2007-07-02 Decomposition
285 }
286
9a176b0c » jakubvrana
2009-08-31 Comments
287 /** Create SQL condition from query string
288 * @param string
289 * @return string
290 */
0cd2afbb » jakubvrana
2009-06-07 Remove single item clone
291 function where_check($val) {
292 parse_str($val, $check);
72f4d9e2 »
2010-07-26 Function parse_str respects magic_quotes_gpc (bug #3034575)
293 remove_slashes(array(&$check));
0cd2afbb » jakubvrana
2009-06-07 Remove single item clone
294 return where($check);
295 }
296
9a176b0c » jakubvrana
2009-08-31 Comments
297 /** Create query string where condition from value
298 * @param int condition order
299 * @param string column identifier
300 * @param string
301 * @return string
186c0589 » jakubvrana
2010-04-15 Utilize where_link function
302 * @return string
9a176b0c » jakubvrana
2009-08-31 Comments
303 */
186c0589 » jakubvrana
2010-04-15 Utilize where_link function
304 function where_link($i, $column, $value, $operator = "=") {
305 return "&where%5B$i%5D%5Bcol%5D=" . urlencode($column) . "&where%5B$i%5D%5Bop%5D=" . urlencode($operator) . "&where%5B$i%5D%5Bval%5D=" . urlencode($value);
c42c46a2 » jakubvrana
2009-07-15 Table relations
306 }
307
319cba4b » jakubvrana
2009-09-09 Save e-mail from to cookie
308 /** Set cookie valid for 1 month
309 * @param string
310 * @param string
311 * @return bool
312 */
313 function cookie($name, $value) {
2cec7584 »
2010-05-25 Direct links from HTTPS to HTTP
314 global $HTTPS;
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
315 $params = array(
316 $name,
317 (ereg("\n", $value) ? "" : $value), // HTTP Response Splitting protection in PHP < 5.1.2
318 time() + 2592000, // 2592000 - 30 days
319 preg_replace('~\\?.*~', '', $_SERVER["REQUEST_URI"]),
320 "",
2cec7584 »
2010-05-25 Direct links from HTTPS to HTTP
321 $HTTPS
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
322 );
c2334dbc » jakubvrana
2009-12-18 Secure cookies
323 if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
324 $params[] = true; // HttpOnly
325 }
326 return call_user_func_array('setcookie', $params);
319cba4b » jakubvrana
2009-09-09 Save e-mail from to cookie
327 }
328
f9a20232 » jakubvrana
2009-11-02 Improve concurrency
329 /** Restart stopped session
330 * @return null
331 */
332 function restart_session() {
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
333 if (!ini_bool("session.use_cookies")) {
f9a20232 » jakubvrana
2009-11-02 Improve concurrency
334 session_start();
335 }
336 }
337
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
338 /** Get session variable for current server
339 * @param string
340 * @return mixed
341 */
342 function &get_session($key) {
343 return $_SESSION[$key][DRIVER][SERVER][$_GET["username"]];
344 }
345
346 /** Set session variable for current server
347 * @param string
348 * @param mixed
349 * @return mixed
350 */
351 function set_session($key, $val) {
352 $_SESSION[$key][DRIVER][SERVER][$_GET["username"]] = $val; // used also in auth.inc.php
353 }
354
605b0930 »
2010-05-06 List authentications
355 /** Get authenticated URL
356 * @param string
357 * @param string
358 * @param string
359 * @return string
360 */
361 function auth_url($driver, $server, $username) {
362 global $drivers;
363 preg_match('~([^?]*)\\??(.*)~', remove_from_uri(implode("|", array_keys($drivers)) . "|username|" . session_name()), $match);
364 return "$match[1]?"
f30fd121 »
2010-12-20 Work without session.use_cookies (bug #3138640)
365 . (sid() ? SID . "&" : "")
605b0930 »
2010-05-06 List authentications
366 . ($driver != "server" || $server != "" ? urlencode($driver) . "=" . urlencode($server) . "&" : "")
367 . "username=" . urlencode($username)
368 . ($match[2] ? "&$match[2]" : "")
369 ;
370 }
371
390e38b8 »
2010-10-18 Load long texts for inline-edit by AJAX
372 /** Find whether it is an AJAX request
373 * @return bool
374 */
375 function is_ajax() {
fdea1970 »
2011-01-25 Simplify AJAX redirect
376 return ($_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest");
390e38b8 »
2010-10-18 Load long texts for inline-edit by AJAX
377 }
378
9a176b0c » jakubvrana
2009-08-31 Comments
379 /** Send Location header and exit
9bb1909f » jakubvrana
2010-04-15 Fix Save and continue edit
380 * @param string null to only set a message
9a176b0c » jakubvrana
2009-08-31 Comments
381 * @param string
382 * @return null
383 */
430034c3 » jakubvrana
2007-07-09 Cottage homework
384 function redirect($location, $message = null) {
385 if (isset($message)) {
be49e08b » jakubvrana
2009-11-03 Improve session restarting
386 restart_session();
ff74bf07 » jakubvrana
2008-04-18 Allow multiple messages
387 $_SESSION["messages"][] = $message;
430034c3 » jakubvrana
2007-07-09 Cottage homework
388 }
de24145d »
2010-10-18 Clear POST with AJAX redirect
389 if (isset($location)) {
b5358536 »
2010-11-12 Full AJAX only with pushState to work correctly with history
390 if ($location == "") {
391 $location = ".";
392 }
fdea1970 »
2011-01-25 Simplify AJAX redirect
393 header((is_ajax() ? "X-AJAX-Redirect" : "Location") . ": $location");
38894b29 »
2010-11-23 Send all forms by AJAX
394 exit;
9bb1909f » jakubvrana
2010-04-15 Fix Save and continue edit
395 }
430034c3 » jakubvrana
2007-07-09 Cottage homework
396 }
397
9a176b0c » jakubvrana
2009-08-31 Comments
398 /** Execute query and redirect if successful
399 * @param string
400 * @param string
401 * @param string
402 * @param bool
403 * @param bool
404 * @param bool
405 * @return bool
406 */
748ee836 » jakubvrana
2008-09-03 Print SQL command with multiple queries
407 function query_redirect($query, $location, $message, $redirect = true, $execute = true, $failed = false) {
64d616c0 » jakubvrana
2009-09-22 Rename get_dbh to connection
408 global $connection, $error, $adminer;
f9a20232 » jakubvrana
2009-11-02 Improve concurrency
409 if ($execute) {
410 $failed = !$connection->query($query);
411 }
10bdbed1 » jakubvrana
2009-06-04 Save queries to history
412 $sql = "";
413 if ($query) {
c64c4fd1 » jakubvrana
2009-07-27 Adminer class
414 $sql = $adminer->messageQuery($query);
10bdbed1 » jakubvrana
2009-06-04 Save queries to history
415 }
748ee836 » jakubvrana
2008-09-03 Print SQL command with multiple queries
416 if ($failed) {
c1130ed5 » jakubvrana
2009-12-17 Simplify SQL syntax errors everywhere
417 $error = error() . $sql;
c48a017e » jakubvrana
2008-09-02 Print SQL query by error
418 return false;
f91b2c4b » jakubvrana
2008-09-02 Print SQL query by message
419 }
c48a017e » jakubvrana
2008-09-02 Print SQL query by error
420 if ($redirect) {
421 redirect($location, $message . $sql);
422 }
423 return true;
f91b2c4b » jakubvrana
2008-09-02 Print SQL query by message
424 }
425
9a176b0c » jakubvrana
2009-08-31 Comments
426 /** Execute and remember query
427 * @param string null to return remembered queries
428 * @return Min_Result
429 */
748ee836 » jakubvrana
2008-09-03 Print SQL command with multiple queries
430 function queries($query = null) {
64d616c0 » jakubvrana
2009-09-22 Rename get_dbh to connection
431 global $connection;
748ee836 » jakubvrana
2008-09-03 Print SQL command with multiple queries
432 static $queries = array();
433 if (!isset($query)) {
64ba9242 » jakubvrana
2009-06-21 Comments
434 // return executed queries without parameter
36950ebe » jakubvrana
2008-09-25 Tables and views
435 return implode(";\n", $queries);
748ee836 » jakubvrana
2008-09-03 Print SQL command with multiple queries
436 }
437 $queries[] = $query;
64d616c0 » jakubvrana
2009-09-22 Rename get_dbh to connection
438 return $connection->query($query);
748ee836 » jakubvrana
2008-09-03 Print SQL command with multiple queries
439 }
440
f9bb1c5c »
2010-05-17 Introduce apply_queries function
441 /** Apply command to all array items
442 * @param string
443 * @param array
444 * @param callback
445 * @return bool
446 */
447 function apply_queries($query, $tables, $escape = 'table') {
448 foreach ($tables as $table) {
449 if (!queries("$query " . $escape($table))) {
450 return false;
451 }
452 }
453 return true;
454 }
455
dbdd40a1 » jakubvrana
2009-10-13 Introduce queries_redirect function
456 /** Redirect by remembered queries
457 * @param string
458 * @param string
459 * @param bool
52b9820e »
2010-10-15 Comment
460 * @return bool
dbdd40a1 » jakubvrana
2009-10-13 Introduce queries_redirect function
461 */
462 function queries_redirect($location, $message, $redirect) {
463 return query_redirect(queries(), $location, $message, $redirect, false, !$redirect);
464 }
465
9a176b0c » jakubvrana
2009-08-31 Comments
466 /** Remove parameter from query string
467 * @param string
468 * @return string
469 */
d41d4460 » jakubvrana
2007-07-27 remove_from_uri()
470 function remove_from_uri($param = "") {
483d7dc0 » jakubvrana
2009-12-08 Remove session_name() only without SID (bug #2910681)
471 return substr(preg_replace("~(?<=[?&])($param" . (SID ? "" : "|" . session_name()) . ")=[^&]*&~", '', "$_SERVER[REQUEST_URI]&"), 0, -1);
d41d4460 » jakubvrana
2007-07-27 remove_from_uri()
472 }
473
9a176b0c » jakubvrana
2009-08-31 Comments
474 /** Generate page number for pagination
475 * @param int
476 * @return string
477 */
bd252953 » jakubvrana
2010-04-22 Don't redirect from last page
478 function pagination($page, $current) {
6585b23b »
2010-11-22 Generic AJAX links
479 return " " . ($page == $current ? $page + 1 : '<a href="' . h(remove_from_uri("page") . ($page ? "&page=$page" : "")) . '">' . ($page + 1) . "</a>");
1456283e » jakubvrana
2008-08-07 Pages on last page
480 }
481
3e9b1ba1 » jakubvrana
2009-11-21 Don't store files in hidden fields
482 /** Get file contents from $_FILES
9a176b0c » jakubvrana
2009-08-31 Comments
483 * @param string
484 * @param bool
3e9b1ba1 » jakubvrana
2009-11-21 Don't store files in hidden fields
485 * @return mixed int for error, string otherwise
9a176b0c » jakubvrana
2009-08-31 Comments
486 */
25f01d35 » jakubvrana
2009-08-28 Compress export and import
487 function get_file($key, $decompress = false) {
488 $file = $_FILES[$key];
489 if (!$file || $file["error"]) {
490 return $file["error"];
430034c3 » jakubvrana
2007-07-09 Cottage homework
491 }
0a2d81d7 » jakubvrana
2009-08-29 Bzip2 import
492 return file_get_contents($decompress && ereg('\\.gz$', $file["name"]) ? "compress.zlib://$file[tmp_name]"
493 : ($decompress && ereg('\\.bz2$', $file["name"]) ? "compress.bzip2://$file[tmp_name]"
494 : $file["tmp_name"]
495 )); //! may not be reachable because of open_basedir
430034c3 » jakubvrana
2007-07-09 Cottage homework
496 }
497
9a176b0c » jakubvrana
2009-08-31 Comments
498 /** Determine upload error
499 * @param int
500 * @return string
501 */
e2a03c08 » jakubvrana
2009-07-16 Show upload_max_filesize
502 function upload_error($error) {
503 $max_size = ($error == UPLOAD_ERR_INI_SIZE ? ini_get("upload_max_filesize") : null); // post_max_size is checked in index.php
b2a7c7ac » jakubvrana
2009-08-25 Execute SQL file stored on server disk
504 return ($error ? lang('Unable to upload a file.') . ($max_size ? " " . lang('Maximum allowed file size is %sB.', $max_size) : "") : lang('File does not exist.'));
e2a03c08 » jakubvrana
2009-07-16 Show upload_max_filesize
505 }
506
9a176b0c » jakubvrana
2009-08-31 Comments
507 /** Generate class for odd rows
508 * @param string return this for odd rows, empty to reset counter
509 * @return string
510 */
511 function odd($return = ' class="odd"') {
4e5b1262 » jakubvrana
2009-04-30 Highlight odd and hover rows
512 static $i = 0;
9a176b0c » jakubvrana
2009-08-31 Comments
513 if (!$return) { // reset counter
1b97f48e » jakubvrana
2009-05-18 Reset odd() for each result
514 $i = -1;
4e5b1262 » jakubvrana
2009-04-30 Highlight odd and hover rows
515 }
9a176b0c » jakubvrana
2009-08-31 Comments
516 return ($i++ % 2 ? $return : '');
4e5b1262 » jakubvrana
2009-04-30 Highlight odd and hover rows
517 }
518
c313dd83 »
2010-10-19 Deferred operations by AJAX instead of JS (doesn't require sending to…
519 /** Print one row in JSON object
520 * @param string or "" to close the object
521 * @param string
522 * @return null
523 */
524 function json_row($key, $val = null) {
525 static $first = true;
526 if ($first) {
527 echo "{";
528 }
529 if ($key != "") {
be58b9cd »
2010-12-16 Escape \n in JSON
530 echo ($first ? "" : ",") . "\n\t\"" . addcslashes($key, "\r\n\"\\") . '": ' . (isset($val) ? '"' . addcslashes($val, "\r\n\"\\") . '"' : 'undefined');
c313dd83 »
2010-10-19 Deferred operations by AJAX instead of JS (doesn't require sending to…
531 $first = false;
532 } else {
533 echo "\n}\n";
534 $first = true;
535 }
536 }
537
9a176b0c » jakubvrana
2009-08-31 Comments
538 /** Check whether the string is in UTF-8
539 * @param string
540 * @return bool
541 */
017ffb51 » jakubvrana
2009-06-11 Better UTF-8 detection
542 function is_utf8($val) {
64ba9242 » jakubvrana
2009-06-21 Comments
543 // don't print control chars except \t\r\n
017ffb51 » jakubvrana
2009-06-11 Better UTF-8 detection
544 return (preg_match('~~u', $val) && !preg_match('~[\\0-\\x8\\xB\\xC\\xE-\\x1F]~', $val));
545 }
546
13155372 »
2011-01-10 No error for big text length (bug #264133)
547 /** Create repeat pattern for preg
548 * @param string
549 * @param int
550 * @return string
551 */
552 function repeat_pattern($pattern, $length) {
553 // fix for Compilation failed: number too big in {} quantifier
554 return str_repeat("$pattern{0,65535}", $length / 65535) . "$pattern{0," . ($length % 65535) . "}"; // can create {0,0} which is OK
555 }
556
9a176b0c » jakubvrana
2009-08-31 Comments
557 /** Shorten UTF-8 string
558 * @param string
559 * @param int
560 * @param string
561 * @return string escaped string with appended ...
562 */
cd075842 » jakubvrana
2009-06-15 Save SQL query to history
563 function shorten_utf8($string, $length = 80, $suffix = "") {
13155372 »
2011-01-10 No error for big text length (bug #264133)
564 if (!preg_match("(^(" . repeat_pattern("[\t\r\n -\x{FFFF}]", $length) . ")($)?)u", $string, $match)) { // ~s causes trash in $match[2] under some PHP versions, (.|\n) is slow
565 preg_match("(^(" . repeat_pattern("[\t\r\n -~]", $length) . ")($)?)", $string, $match);
95764b01 » jakubvrana
2009-08-25 Shorten binary strings
566 }
687b3fdd »
2010-05-20 Replace <strong> by <b> and <em> by <i>
567 return h($match[1]) . $suffix . (isset($match[2]) ? "" : "<i>...</i>");
02a851c7 » jakubvrana
2007-08-24 Shorten texts in PHP
568 }
3920ebbe » jakubvrana
2008-10-03 Remove InnoDB table comment in Tables and views
569
9a176b0c » jakubvrana
2009-08-31 Comments
570 /** Generate friendly URL
571 * @param string
572 * @return string
573 */
82518960 » jakubvrana
2009-06-11 Downloaded file name
574 function friendly_url($val) {
64ba9242 » jakubvrana
2009-06-21 Comments
575 // used for blobs and export
82518960 » jakubvrana
2009-06-11 Downloaded file name
576 return preg_replace('~[^a-z0-9_]~i', '-', $val);
577 }
578
9a176b0c » jakubvrana
2009-08-31 Comments
579 /** Print hidden fields
580 * @param array
581 * @param array
582 * @return null
583 */
820c8820 » jakubvrana
2008-10-09 Bulk clone
584 function hidden_fields($process, $ignore = array()) {
5d7071a5 » jakubvrana
2008-10-03 Choose language through option-list
585 while (list($key, $val) = each($process)) {
586 if (is_array($val)) {
587 foreach ($val as $k => $v) {
588 $process[$key . "[$k]"] = $v;
589 }
590 } elseif (!in_array($key, $ignore)) {
689699aa » jakubvrana
2009-07-28 Shortcut for htmlspecialchars
591 echo '<input type="hidden" name="' . h($key) . '" value="' . h($val) . '">';
5d7071a5 » jakubvrana
2008-10-03 Choose language through option-list
592 }
593 }
594 }
61640ee6 » jakubvrana
2009-07-03 Move common functions
595
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
596 /** Print hidden fields for GET forms
597 * @return null
598 */
599 function hidden_fields_get() {
f30fd121 »
2010-12-20 Work without session.use_cookies (bug #3138640)
600 echo (sid() ? '<input type="hidden" name="' . session_name() . '" value="' . h(session_id()) . '">' : '');
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
601 echo (SERVER !== null ? '<input type="hidden" name="' . DRIVER . '" value="' . h(SERVER) . '">' : "");
602 echo '<input type="hidden" name="username" value="' . h($_GET["username"]) . '">';
603 }
604
9a176b0c » jakubvrana
2009-08-31 Comments
605 /** Find out foreign keys for each column
606 * @param string
607 * @return array array($col => array())
608 */
1e4d11e9 » jakubvrana
2009-07-23 Select from foreign keys in Editor
609 function column_foreign_keys($table) {
753909ec »
2010-10-29 Support for virtual foreign keys
610 global $adminer;
1e4d11e9 » jakubvrana
2009-07-23 Select from foreign keys in Editor
611 $return = array();
753909ec »
2010-10-29 Support for virtual foreign keys
612 foreach ($adminer->foreignKeys($table) as $foreign_key) {
1e4d11e9 » jakubvrana
2009-07-23 Select from foreign keys in Editor
613 foreach ($foreign_key["source"] as $val) {
614 $return[$val][] = $foreign_key;
615 }
616 }
617 return $return;
618 }
619
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
620 /** Print enum input field
621 * @param string "radio"|"checkbox"
622 * @param string
623 * @param array
624 * @param mixed int|string|array
684e70d0 »
2011-01-21 Search for empty enum
625 * @param string
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
626 * @return null
627 */
684e70d0 »
2011-01-21 Search for empty enum
628 function enum_input($type, $attrs, $field, $value, $empty = null) {
c0682062 »
2011-01-18 Use $adminer->editVal in enum_input function
629 global $adminer;
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
630 preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
684e70d0 »
2011-01-21 Search for empty enum
631 $return = (isset($empty) ? "<label><input type='$type'$attrs value='$empty'" . ((is_array($value) ? in_array($empty, $value) : $value === 0) ? " checked" : "") . "><i>" . lang('empty') . "</i></label>" : "");
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
632 foreach ($matches[1] as $i => $val) {
633 $val = stripcslashes(str_replace("''", "'", $val));
634 $checked = (is_int($value) ? $value == $i+1 : (is_array($value) ? in_array($i+1, $value) : $value === $val));
c0682062 »
2011-01-18 Use $adminer->editVal in enum_input function
635 $return .= " <label><input type='$type'$attrs value='" . ($i+1) . "'" . ($checked ? ' checked' : '') . '>' . h($adminer->editVal($val, $field)) . '</label>';
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
636 }
fe069085 »
2010-10-23 Allow redefining editInput for enum (bug #3048711)
637 return $return;
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
638 }
639
9a176b0c » jakubvrana
2009-08-31 Comments
640 /** Print edit input field
641 * @param array one field from fields()
642 * @param mixed
643 * @param string
644 * @return null
645 */
1e4d11e9 » jakubvrana
2009-07-23 Select from foreign keys in Editor
646 function input($field, $value, $function) {
e6726941 »
2010-05-07 Rename $driver to $jush
647 global $types, $adminer, $jush;
689699aa » jakubvrana
2009-07-28 Shortcut for htmlspecialchars
648 $name = h(bracket_escape($field["field"]));
61640ee6 » jakubvrana
2009-07-03 Move common functions
649 echo "<td class='function'>";
9f69d7ae »
2010-11-28 MS SQL: Do not update AI value
650 $reset = ($jush == "mssql" && $field["auto_increment"]);
651 if ($reset && !$_POST["save"]) {
652 $function = null;
653 }
654 $functions = (isset($_GET["select"]) || $reset ? array("orig" => lang('original')) : array()) + $adminer->editFunctions($field);
454c80f8 »
2010-09-09 Save bytes
655 $attrs = " name='fields[$name]'";
61640ee6 » jakubvrana
2009-07-03 Move common functions
656 if ($field["type"] == "enum") {
fe069085 »
2010-10-23 Allow redefining editInput for enum (bug #3048711)
657 echo nbsp($functions[""]) . "<td>" . $adminer->editInput($_GET["edit"], $field, $attrs, $value);
61640ee6 » jakubvrana
2009-07-03 Move common functions
658 } else {
99039467 » jakubvrana
2009-09-08 Use original values in Editor multi edit
659 $first = 0;
660 foreach ($functions as $key => $val) {
661 if ($key === "" || !$val) {
662 break;
663 }
664 $first++;
665 }
28f21aaa »
2010-10-22 Escape JavaScript strings (bug #3093243)
666 $onchange = ($first ? " onchange=\"var f = this.form['function[" . js_escape($name) . "]']; if ($first > f.selectedIndex) f.selectedIndex = $first;\"" : "");
454c80f8 »
2010-09-09 Save bytes
667 $attrs .= $onchange;
c5a1a770 »
2010-08-03 Functions translation
668 echo (count($functions) > 1 ? html_select("function[$name]", $functions, !isset($function) || in_array($function, $functions) || isset($functions[$function]) ? $function : "") : nbsp(reset($functions))) . '<td>';
a5612526 » jakubvrana
2009-11-09 Use distinct name for blob inputs
669 $input = $adminer->editInput($_GET["edit"], $field, $attrs, $value); // usage in call is without a table
7352c281 » jakubvrana
2010-01-09 Replace strlen() by != ""
670 if ($input != "") {
e1abcda0 » jakubvrana
2009-07-28 Treat tinyint(1) as boolean
671 echo $input;
1e4d11e9 » jakubvrana
2009-07-23 Select from foreign keys in Editor
672 } elseif ($field["type"] == "set") { //! 64 bits
26c9d64b » jakubvrana
2009-08-19 Fix long SQL query crash (bug #2839231)
673 preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
61640ee6 » jakubvrana
2009-07-03 Move common functions
674 foreach ($matches[1] as $i => $val) {
675 $val = stripcslashes(str_replace("''", "'", $val));
676 $checked = (is_int($value) ? ($value >> $i) & 1 : in_array($val, explode(",", $value), true));
4cead560 » jakubvrana
2009-08-21 Edit default values directly in table creation
677 echo " <label><input type='checkbox' name='fields[$name][$i]' value='" . (1 << $i) . "'" . ($checked ? ' checked' : '') . "$onchange>" . h($val) . '</label>';
61640ee6 » jakubvrana
2009-07-03 Move common functions
678 }
5a73c012 »
2010-09-28 Treat binary type as hex
679 } elseif (ereg('blob|bytea|raw|file', $field["type"]) && ini_bool("file_uploads")) {
a5612526 » jakubvrana
2009-11-09 Use distinct name for blob inputs
680 echo "<input type='file' name='fields-$name'$onchange>";
375a5c8e »
2010-05-26 Non-MySQL binary types
681 } elseif (ereg('text|lob', $field["type"])) {
71438d57 »
2010-11-19 Handle keypress instead of keydown (bug #3112458)
682 echo "<textarea " . ($jush != "sqlite" || ereg("\n", $value) ? "cols='50' rows='12'" : "cols='30' rows='1' style='height: 1.2em;'") . "$attrs onkeypress='return textareaKeypress(this, event);'>" . h($value) . '</textarea>'; // 1.2em - line-height
61640ee6 » jakubvrana
2009-07-03 Move common functions
683 } else {
684 // int(3) is only a display hint
5002b89b »
2010-10-23 Big numbers without E
685 $maxlength = (!ereg('int', $field["type"]) && preg_match('~^(\\d+)(,(\\d+))?$~', $field["length"], $match) ? ((ereg("binary", $field["type"]) ? 2 : 1) * $match[1] + ($match[3] ? 1 : 0) + ($match[2] && !$field["unsigned"] ? 1 : 0)) : ($types[$field["type"]] ? $types[$field["type"]] + ($field["unsigned"] ? 0 : 1) : 0));
5a73c012 »
2010-09-28 Treat binary type as hex
686 echo "<input value='" . h($value) . "'" . ($maxlength ? " maxlength='$maxlength'" : "") . (ereg('char|binary', $field["type"]) && $maxlength > 20 ? " size='40'" : "") . "$attrs>";
61640ee6 » jakubvrana
2009-07-03 Move common functions
687 }
688 }
689 }
690
9a176b0c » jakubvrana
2009-08-31 Comments
691 /** Process edit input field
692 * @param one field from fields()
693 * @return string
694 */
a0def479 » jakubvrana
2009-07-27 Date localization
695 function process_input($field) {
7e644b43 »
2010-10-13 Save bytes ($connection->quote shortcut)
696 global $adminer;
a0def479 » jakubvrana
2009-07-27 Date localization
697 $idf = bracket_escape($field["field"]);
61640ee6 » jakubvrana
2009-07-03 Move common functions
698 $function = $_POST["function"][$idf];
699 $value = $_POST["fields"][$idf];
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
700 if ($field["type"] == "enum") {
701 if ($value == -1) {
702 return false;
703 }
704 if ($value == "") {
705 return "NULL";
706 }
04eccbad »
2010-10-22 Allow bigger numbers under 32 bits
707 return +$value;
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
708 }
709 if ($field["auto_increment"] && $value == "") {
710 return null;
711 }
712 if ($function == "orig") {
61640ee6 » jakubvrana
2009-07-03 Move common functions
713 return false;
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
714 }
715 if ($function == "NULL") {
61640ee6 » jakubvrana
2009-07-03 Move common functions
716 return "NULL";
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
717 }
718 if ($field["type"] == "set") {
4cead560 » jakubvrana
2009-08-21 Edit default values directly in table creation
719 return array_sum((array) $value);
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
720 }
5a73c012 »
2010-09-28 Treat binary type as hex
721 if (ereg('blob|bytea|raw|file', $field["type"]) && ini_bool("file_uploads")) {
a5612526 » jakubvrana
2009-11-09 Use distinct name for blob inputs
722 $file = get_file("fields-$idf");
61640ee6 » jakubvrana
2009-07-03 Move common functions
723 if (!is_string($file)) {
724 return false; //! report errors
725 }
7e644b43 »
2010-10-13 Save bytes ($connection->quote shortcut)
726 return q($file);
61640ee6 » jakubvrana
2009-07-03 Move common functions
727 }
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
728 return $adminer->processInput($field, $value, $function);
61640ee6 » jakubvrana
2009-07-03 Move common functions
729 }
730
db07325e » jakubvrana
2010-02-16 Search in all tables
731 /** Print results of search in all tables
732 * @uses $_GET["where"][0]
733 * @uses $_POST["tables"]
734 * @return null
735 */
736 function search_tables() {
737 global $adminer, $connection;
dfa6cbf4 »
2010-10-07 Show tables overview in Editor
738 $_GET["where"][0]["op"] = "LIKE %%";
739 $_GET["where"][0]["val"] = $_POST["query"];
db07325e » jakubvrana
2010-02-16 Search in all tables
740 $found = false;
741 foreach (table_status() as $table => $table_status) {
742 $name = $adminer->tableName($table_status);
743 if (isset($table_status["Engine"]) && $name != "" && (!$_POST["tables"] || in_array($table, $_POST["tables"]))) {
ee3e0459 »
2010-05-14 Separate $where in limit function
744 $result = $connection->query("SELECT" . limit("1 FROM " . table($table), " WHERE " . implode(" AND ", $adminer->selectSearchProcess(fields($table), array())), 1));
782921b6 »
2010-05-27 Finish SQLite
745 if ($result->fetch_row()) {
db07325e » jakubvrana
2010-02-16 Search in all tables
746 if (!$found) {
747 echo "<ul>\n";
748 $found = true;
749 }
750 echo "<li><a href='" . h(ME . "select=" . urlencode($table) . "&where[0][op]=" . urlencode($_GET["where"][0]["op"]) . "&where[0][val]=" . urlencode($_GET["where"][0]["val"])) . "'>" . h($name) . "</a>\n";
751 }
752 }
753 }
754 echo ($found ? "</ul>" : "<p class='message'>" . lang('No tables.')) . "\n";
755 }
756
9a176b0c » jakubvrana
2009-08-31 Comments
757 /** Print CSV row
758 * @param array
759 * @return null
760 */
61640ee6 » jakubvrana
2009-07-03 Move common functions
761 function dump_csv($row) {
762 foreach ($row as $key => $val) {
e225d22f »
2010-10-29 TSV export and import (bug #3097657)
763 if (preg_match("~[\"\n,;\t]~", $val) || $val === "") {
61640ee6 » jakubvrana
2009-07-03 Move common functions
764 $row[$key] = '"' . str_replace('"', '""', $val) . '"';
765 }
766 }
02d6b908 »
2010-12-01 CR+LF in CSV export
767 echo implode(($_POST["format"] == "csv" ? "," : ($_POST["format"] == "tsv" ? "\t" : ";")), $row) . "\r\n";
61640ee6 » jakubvrana
2009-07-03 Move common functions
768 }
c16c57b1 » jakubvrana
2009-07-11 E-mail sending
769
9a176b0c » jakubvrana
2009-08-31 Comments
770 /** Apply SQL function
771 * @param string
772 * @param string escaped column identifier
773 * @return string
774 */
e3310672 » jakubvrana
2009-08-18 Move apply_sql_function
775 function apply_sql_function($function, $column) {
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
776 return ($function ? ($function == "unixepoch" ? "DATETIME($column, '$function')" : ($function == "count distinct" ? "COUNT(DISTINCT " : strtoupper("$function(")) . "$column)") : $column);
e3310672 » jakubvrana
2009-08-18 Move apply_sql_function
777 }
778
4ba2d856 »
2010-05-06 Allow permanent login without customization
779 /** Read password from file adminer.key in temporary directory or create one
780 * @return string or false if the file can not be created
781 */
782 function password_file() {
783 $dir = ini_get("upload_tmp_dir"); // session_save_path() may contain other storage path
784 if (!$dir) {
785 if (function_exists('sys_get_temp_dir')) {
786 $dir = sys_get_temp_dir();
787 } else {
788 $filename = @tempnam("", ""); // @ - temp directory can be disabled by open_basedir
789 if (!$filename) {
790 return false;
791 }
792 $dir = dirname($filename);
793 unlink($filename);
794 }
795 }
796 $filename = "$dir/adminer.key";
797 $return = @file_get_contents($filename); // @ - can not exist
798 if ($return) {
799 return $return;
800 }
801 $fp = @fopen($filename, "w"); // @ - can have insufficient rights //! is not atomic
802 if ($fp) {
803 $return = md5(uniqid(mt_rand(), true));
804 fwrite($fp, $return);
805 fclose($fp);
806 }
807 return $return;
808 }
809
9a176b0c » jakubvrana
2009-08-31 Comments
810 /** Check whether the string is e-mail address
811 * @param string
812 * @return bool
813 */
1cf374bf »
2010-10-16 Rename functions (avoid conflict with WordPress)
814 function is_mail($email) {
c16c57b1 » jakubvrana
2009-07-11 E-mail sending
815 $atom = '[-a-z0-9!#$%&\'*+/=?^_`{|}~]'; // characters of local-name
816 $domain = '[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])'; // one domain component
28e1dd28 » jakubvrana
2010-04-21 Allow multiple e-mails
817 $pattern = "$atom+(\\.$atom+)*@($domain?\\.)+$domain";
818 return preg_match("(^$pattern(,\\s*$pattern)*\$)i", $email);
c16c57b1 » jakubvrana
2009-07-11 E-mail sending
819 }
dc667ea1 » jakubvrana
2009-09-11 Hide select export and import
820
bc78866a » jakubvrana
2009-10-02 Link URLs in select
821 /** Check whether the string is URL address
822 * @param string
2cec7584 »
2010-05-25 Direct links from HTTPS to HTTP
823 * @return string "http", "https" or ""
bc78866a » jakubvrana
2009-10-02 Link URLs in select
824 */
825 function is_url($string) {
2cec7584 »
2010-05-25 Direct links from HTTPS to HTTP
826 $domain = '[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])'; // one domain component //! IDN
5002b89b »
2010-10-23 Big numbers without E
827 return (preg_match("~^(https?)://($domain?\\.)+$domain(:\\d+)?(/.*)?(\\?.*)?(#.*)?\$~i", $string, $match) ? strtolower($match[1]) : ""); //! restrict path, query and fragment characters
bc78866a » jakubvrana
2009-10-02 Link URLs in select
828 }
829
dc667ea1 » jakubvrana
2009-09-11 Hide select export and import
830 /** Print header for hidden fieldset (close by </div></fieldset>)
831 * @param string
832 * @param string
833 * @param bool
834 * @return null
835 */
836 function print_fieldset($id, $legend, $visible = false) {
837 echo "<fieldset><legend><a href='#fieldset-$id' onclick=\"return !toggle('fieldset-$id');\">$legend</a></legend><div id='fieldset-$id'" . ($visible ? "" : " class='hidden'") . ">\n";
838 }
94a2be52 » jakubvrana
2009-11-26 Highlight current links
839
8ad4809b »
2010-11-22 Use class="active" instead of <b>
840 /** Return class='active' if $bold is true
94a2be52 » jakubvrana
2009-11-26 Highlight current links
841 * @param bool
842 * @return string
843 */
8ad4809b »
2010-11-22 Use class="active" instead of <b>
844 function bold($bold) {
845 return ($bold ? " class='active'" : "");
94a2be52 » jakubvrana
2009-11-26 Highlight current links
846 }
Something went wrong with that request. Please try again.