PageRenderTime 57ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/phpmyadmin/libraries/core.lib.php

https://bitbucket.org/rdown/openemr
PHP | 802 lines | 447 code | 53 blank | 302 comment | 90 complexity | 9a4dafaa565e2a39408551fdd56c40e5 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-3.0, BSD-3-Clause, GPL-2.0, MPL-2.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Core functions used all over the scripts.
  5. * This script is distinct from libraries/common.inc.php because this
  6. * script is called from /test.
  7. *
  8. * @package PhpMyAdmin
  9. */
  10. if (! defined('PHPMYADMIN')) {
  11. exit;
  12. }
  13. /**
  14. * checks given $var and returns it if valid, or $default of not valid
  15. * given $var is also checked for type being 'similar' as $default
  16. * or against any other type if $type is provided
  17. *
  18. * <code>
  19. * // $_REQUEST['db'] not set
  20. * echo PMA_ifSetOr($_REQUEST['db'], ''); // ''
  21. * // $_REQUEST['sql_query'] not set
  22. * echo PMA_ifSetOr($_REQUEST['sql_query']); // null
  23. * // $cfg['ForceSSL'] not set
  24. * echo PMA_ifSetOr($cfg['ForceSSL'], false, 'boolean'); // false
  25. * echo PMA_ifSetOr($cfg['ForceSSL']); // null
  26. * // $cfg['ForceSSL'] set to 1
  27. * echo PMA_ifSetOr($cfg['ForceSSL'], false, 'boolean'); // false
  28. * echo PMA_ifSetOr($cfg['ForceSSL'], false, 'similar'); // 1
  29. * echo PMA_ifSetOr($cfg['ForceSSL'], false); // 1
  30. * // $cfg['ForceSSL'] set to true
  31. * echo PMA_ifSetOr($cfg['ForceSSL'], false, 'boolean'); // true
  32. * </code>
  33. *
  34. * @param mixed &$var param to check
  35. * @param mixed $default default value
  36. * @param mixed $type var type or array of values to check against $var
  37. *
  38. * @return mixed $var or $default
  39. *
  40. * @see PMA_isValid()
  41. */
  42. function PMA_ifSetOr(&$var, $default = null, $type = 'similar')
  43. {
  44. if (! PMA_isValid($var, $type, $default)) {
  45. return $default;
  46. }
  47. return $var;
  48. }
  49. /**
  50. * checks given $var against $type or $compare
  51. *
  52. * $type can be:
  53. * - false : no type checking
  54. * - 'scalar' : whether type of $var is integer, float, string or boolean
  55. * - 'numeric' : whether type of $var is any number repesentation
  56. * - 'length' : whether type of $var is scalar with a string length > 0
  57. * - 'similar' : whether type of $var is similar to type of $compare
  58. * - 'equal' : whether type of $var is identical to type of $compare
  59. * - 'identical' : whether $var is identical to $compare, not only the type!
  60. * - or any other valid PHP variable type
  61. *
  62. * <code>
  63. * // $_REQUEST['doit'] = true;
  64. * PMA_isValid($_REQUEST['doit'], 'identical', 'true'); // false
  65. * // $_REQUEST['doit'] = 'true';
  66. * PMA_isValid($_REQUEST['doit'], 'identical', 'true'); // true
  67. * </code>
  68. *
  69. * NOTE: call-by-reference is used to not get NOTICE on undefined vars,
  70. * but the var is not altered inside this function, also after checking a var
  71. * this var exists nut is not set, example:
  72. * <code>
  73. * // $var is not set
  74. * isset($var); // false
  75. * functionCallByReference($var); // false
  76. * isset($var); // true
  77. * functionCallByReference($var); // true
  78. * </code>
  79. *
  80. * to avoid this we set this var to null if not isset
  81. *
  82. * @param mixed &$var variable to check
  83. * @param mixed $type var type or array of valid values to check against $var
  84. * @param mixed $compare var to compare with $var
  85. *
  86. * @return boolean whether valid or not
  87. *
  88. * @todo add some more var types like hex, bin, ...?
  89. * @see http://php.net/gettype
  90. */
  91. function PMA_isValid(&$var, $type = 'length', $compare = null)
  92. {
  93. if (! isset($var)) {
  94. // var is not even set
  95. return false;
  96. }
  97. if ($type === false) {
  98. // no vartype requested
  99. return true;
  100. }
  101. if (is_array($type)) {
  102. return in_array($var, $type);
  103. }
  104. // allow some aliaes of var types
  105. $type = strtolower($type);
  106. switch ($type) {
  107. case 'identic' :
  108. $type = 'identical';
  109. break;
  110. case 'len' :
  111. $type = 'length';
  112. break;
  113. case 'bool' :
  114. $type = 'boolean';
  115. break;
  116. case 'float' :
  117. $type = 'double';
  118. break;
  119. case 'int' :
  120. $type = 'integer';
  121. break;
  122. case 'null' :
  123. $type = 'NULL';
  124. break;
  125. }
  126. if ($type === 'identical') {
  127. return $var === $compare;
  128. }
  129. // whether we should check against given $compare
  130. if ($type === 'similar') {
  131. switch (gettype($compare)) {
  132. case 'string':
  133. case 'boolean':
  134. $type = 'scalar';
  135. break;
  136. case 'integer':
  137. case 'double':
  138. $type = 'numeric';
  139. break;
  140. default:
  141. $type = gettype($compare);
  142. }
  143. } elseif ($type === 'equal') {
  144. $type = gettype($compare);
  145. }
  146. // do the check
  147. if ($type === 'length' || $type === 'scalar') {
  148. $is_scalar = is_scalar($var);
  149. if ($is_scalar && $type === 'length') {
  150. return (bool) strlen($var);
  151. }
  152. return $is_scalar;
  153. }
  154. if ($type === 'numeric') {
  155. return is_numeric($var);
  156. }
  157. if (gettype($var) === $type) {
  158. return true;
  159. }
  160. return false;
  161. }
  162. /**
  163. * Removes insecure parts in a path; used before include() or
  164. * require() when a part of the path comes from an insecure source
  165. * like a cookie or form.
  166. *
  167. * @param string $path The path to check
  168. *
  169. * @return string The secured path
  170. *
  171. * @access public
  172. */
  173. function PMA_securePath($path)
  174. {
  175. // change .. to .
  176. $path = preg_replace('@\.\.*@', '.', $path);
  177. return $path;
  178. } // end function
  179. /**
  180. * displays the given error message on phpMyAdmin error page in foreign language,
  181. * ends script execution and closes session
  182. *
  183. * loads language file if not loaded already
  184. *
  185. * @param string $error_message the error message or named error message
  186. * @param string|array $message_args arguments applied to $error_message
  187. * @param boolean $delete_session whether to delete session cookie
  188. *
  189. * @return exit
  190. */
  191. function PMA_fatalError(
  192. $error_message, $message_args = null, $delete_session = true
  193. ) {
  194. /* Use format string if applicable */
  195. if (is_string($message_args)) {
  196. $error_message = sprintf($error_message, $message_args);
  197. } elseif (is_array($message_args)) {
  198. $error_message = vsprintf($error_message, $message_args);
  199. }
  200. if ($GLOBALS['is_ajax_request']) {
  201. $response = PMA_Response::getInstance();
  202. $response->isSuccess(false);
  203. $response->addJSON('message', PMA_Message::error($error_message));
  204. } else {
  205. $error_message = strtr($error_message, array('<br />' => '[br]'));
  206. /* Define fake gettext for fatal errors */
  207. if (!function_exists('__')) {
  208. function __($text)
  209. {
  210. return $text;
  211. }
  212. }
  213. // these variables are used in the included file libraries/error.inc.php
  214. $error_header = __('Error');
  215. $lang = $GLOBALS['available_languages'][$GLOBALS['lang']][1];
  216. $dir = $GLOBALS['text_dir'];
  217. // on fatal errors it cannot hurt to always delete the current session
  218. if ($delete_session
  219. && isset($GLOBALS['session_name'])
  220. && isset($_COOKIE[$GLOBALS['session_name']])
  221. ) {
  222. $GLOBALS['PMA_Config']->removeCookie($GLOBALS['session_name']);
  223. }
  224. // Displays the error message
  225. include './libraries/error.inc.php';
  226. }
  227. if (! defined('TESTSUITE')) {
  228. exit;
  229. }
  230. }
  231. /**
  232. * Returns a link to the PHP documentation
  233. *
  234. * @param string $target anchor in documentation
  235. *
  236. * @return string the URL
  237. *
  238. * @access public
  239. */
  240. function PMA_getPHPDocLink($target)
  241. {
  242. /* List of PHP documentation translations */
  243. $php_doc_languages = array(
  244. 'pt_BR', 'zh', 'fr', 'de', 'it', 'ja', 'pl', 'ro', 'ru', 'fa', 'es', 'tr'
  245. );
  246. $lang = 'en';
  247. if (in_array($GLOBALS['lang'], $php_doc_languages)) {
  248. $lang = $GLOBALS['lang'];
  249. }
  250. return PMA_linkURL('http://php.net/manual/' . $lang . '/' . $target);
  251. }
  252. /**
  253. * Warn or fail on missing extension.
  254. *
  255. * @param string $extension Extension name
  256. * @param bool $fatal Whether the error is fatal.
  257. * @param string $extra Extra string to append to messsage.
  258. *
  259. * @return void
  260. */
  261. function PMA_warnMissingExtension($extension, $fatal = false, $extra = '')
  262. {
  263. /* Gettext does not have to be loaded yet here */
  264. if (function_exists('__')) {
  265. $message = __(
  266. 'The %s extension is missing. Please check your PHP configuration.'
  267. );
  268. } else {
  269. $message
  270. = 'The %s extension is missing. Please check your PHP configuration.';
  271. }
  272. $doclink = PMA_getPHPDocLink('book.' . $extension . '.php');
  273. $message = sprintf(
  274. $message,
  275. '[a@' . $doclink . '@Documentation][em]' . $extension . '[/em][/a]'
  276. );
  277. if ($extra != '') {
  278. $message .= ' ' . $extra;
  279. }
  280. if ($fatal) {
  281. PMA_fatalError($message);
  282. } else {
  283. $GLOBALS['error_handler']->addError(
  284. $message,
  285. E_USER_WARNING,
  286. '',
  287. '',
  288. false
  289. );
  290. }
  291. }
  292. /**
  293. * returns count of tables in given db
  294. *
  295. * @param string $db database to count tables for
  296. *
  297. * @return integer count of tables in $db
  298. */
  299. function PMA_getTableCount($db)
  300. {
  301. $tables = PMA_DBI_try_query(
  302. 'SHOW TABLES FROM ' . PMA_Util::backquote($db) . ';',
  303. null, PMA_DBI_QUERY_STORE
  304. );
  305. if ($tables) {
  306. $num_tables = PMA_DBI_num_rows($tables);
  307. PMA_DBI_free_result($tables);
  308. } else {
  309. $num_tables = 0;
  310. }
  311. return $num_tables;
  312. }
  313. /**
  314. * Converts numbers like 10M into bytes
  315. * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
  316. * (renamed with PMA prefix to avoid double definition when embedded
  317. * in Moodle)
  318. *
  319. * @param string $size size
  320. *
  321. * @return integer $size
  322. */
  323. function PMA_getRealSize($size = 0)
  324. {
  325. if (! $size) {
  326. return 0;
  327. }
  328. $scan['gb'] = 1073741824; //1024 * 1024 * 1024;
  329. $scan['g'] = 1073741824; //1024 * 1024 * 1024;
  330. $scan['mb'] = 1048576;
  331. $scan['m'] = 1048576;
  332. $scan['kb'] = 1024;
  333. $scan['k'] = 1024;
  334. $scan['b'] = 1;
  335. foreach ($scan as $unit => $factor) {
  336. if (strlen($size) > strlen($unit)
  337. && strtolower(substr($size, strlen($size) - strlen($unit))) == $unit
  338. ) {
  339. return substr($size, 0, strlen($size) - strlen($unit)) * $factor;
  340. }
  341. }
  342. return $size;
  343. } // end function PMA_getRealSize()
  344. /**
  345. * merges array recursive like array_merge_recursive() but keyed-values are
  346. * always overwritten.
  347. *
  348. * array PMA_arrayMergeRecursive(array $array1[, array $array2[, array ...]])
  349. *
  350. * @return array merged array
  351. *
  352. * @see http://php.net/array_merge
  353. * @see http://php.net/array_merge_recursive
  354. */
  355. function PMA_arrayMergeRecursive()
  356. {
  357. switch(func_num_args()) {
  358. case 0 :
  359. return false;
  360. break;
  361. case 1 :
  362. // when does that happen?
  363. return func_get_arg(0);
  364. break;
  365. case 2 :
  366. $args = func_get_args();
  367. if (! is_array($args[0]) || ! is_array($args[1])) {
  368. return $args[1];
  369. }
  370. foreach ($args[1] as $key2 => $value2) {
  371. if (isset($args[0][$key2]) && !is_int($key2)) {
  372. $args[0][$key2] = PMA_arrayMergeRecursive(
  373. $args[0][$key2], $value2
  374. );
  375. } else {
  376. // we erase the parent array, otherwise we cannot override
  377. // a directive that contains array elements, like this:
  378. // (in config.default.php)
  379. // $cfg['ForeignKeyDropdownOrder']= array('id-content','content-id');
  380. // (in config.inc.php)
  381. // $cfg['ForeignKeyDropdownOrder']= array('content-id');
  382. if (is_int($key2) && $key2 == 0) {
  383. unset($args[0]);
  384. }
  385. $args[0][$key2] = $value2;
  386. }
  387. }
  388. return $args[0];
  389. break;
  390. default :
  391. $args = func_get_args();
  392. $args[1] = PMA_arrayMergeRecursive($args[0], $args[1]);
  393. array_shift($args);
  394. return call_user_func_array('PMA_arrayMergeRecursive', $args);
  395. break;
  396. }
  397. }
  398. /**
  399. * calls $function for every element in $array recursively
  400. *
  401. * this function is protected against deep recursion attack CVE-2006-1549,
  402. * 1000 seems to be more than enough
  403. *
  404. * @param array &$array array to walk
  405. * @param string $function function to call for every array element
  406. * @param bool $apply_to_keys_also whether to call the function for the keys also
  407. *
  408. * @return void
  409. *
  410. * @see http://www.php-security.org/MOPB/MOPB-02-2007.html
  411. * @see http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-1549
  412. */
  413. function PMA_arrayWalkRecursive(&$array, $function, $apply_to_keys_also = false)
  414. {
  415. static $recursive_counter = 0;
  416. if (++$recursive_counter > 1000) {
  417. PMA_fatalError(__('possible deep recursion attack'));
  418. }
  419. foreach ($array as $key => $value) {
  420. if (is_array($value)) {
  421. PMA_arrayWalkRecursive($array[$key], $function, $apply_to_keys_also);
  422. } else {
  423. $array[$key] = $function($value);
  424. }
  425. if ($apply_to_keys_also && is_string($key)) {
  426. $new_key = $function($key);
  427. if ($new_key != $key) {
  428. $array[$new_key] = $array[$key];
  429. unset($array[$key]);
  430. }
  431. }
  432. }
  433. $recursive_counter--;
  434. }
  435. /**
  436. * boolean phpMyAdmin.PMA_checkPageValidity(string &$page, array $whitelist)
  437. *
  438. * checks given given $page against given $whitelist and returns true if valid
  439. * it ignores optionaly query paramters in $page (script.php?ignored)
  440. *
  441. * @param string &$page page to check
  442. * @param array $whitelist whitelist to check page against
  443. *
  444. * @return boolean whether $page is valid or not (in $whitelist or not)
  445. */
  446. function PMA_checkPageValidity(&$page, $whitelist)
  447. {
  448. if (! isset($page) || !is_string($page)) {
  449. return false;
  450. }
  451. if (in_array($page, $whitelist)) {
  452. return true;
  453. } elseif (in_array(substr($page, 0, strpos($page . '?', '?')), $whitelist)) {
  454. return true;
  455. } else {
  456. $_page = urldecode($page);
  457. if (in_array(substr($_page, 0, strpos($_page . '?', '?')), $whitelist)) {
  458. return true;
  459. }
  460. }
  461. return false;
  462. }
  463. /**
  464. * tries to find the value for the given environment variable name
  465. *
  466. * searches in $_SERVER, $_ENV then tries getenv() and apache_getenv()
  467. * in this order
  468. *
  469. * @param string $var_name variable name
  470. *
  471. * @return string value of $var or empty string
  472. */
  473. function PMA_getenv($var_name)
  474. {
  475. if (isset($_SERVER[$var_name])) {
  476. return $_SERVER[$var_name];
  477. } elseif (isset($_ENV[$var_name])) {
  478. return $_ENV[$var_name];
  479. } elseif (getenv($var_name)) {
  480. return getenv($var_name);
  481. } elseif (function_exists('apache_getenv')
  482. && apache_getenv($var_name, true)) {
  483. return apache_getenv($var_name, true);
  484. }
  485. return '';
  486. }
  487. /**
  488. * Send HTTP header, taking IIS limits into account (600 seems ok)
  489. *
  490. * @param string $uri the header to send
  491. * @param bool $use_refresh whether to use Refresh: header when running on IIS
  492. *
  493. * @return boolean always true
  494. */
  495. function PMA_sendHeaderLocation($uri, $use_refresh = false)
  496. {
  497. if (PMA_IS_IIS && strlen($uri) > 600) {
  498. include_once './libraries/js_escape.lib.php';
  499. PMA_Response::getInstance()->disable();
  500. echo '<html><head><title>- - -</title>' . "\n";
  501. echo '<meta http-equiv="expires" content="0">' . "\n";
  502. echo '<meta http-equiv="Pragma" content="no-cache">' . "\n";
  503. echo '<meta http-equiv="Cache-Control" content="no-cache">' . "\n";
  504. echo '<meta http-equiv="Refresh" content="0;url='
  505. . htmlspecialchars($uri) . '">' . "\n";
  506. echo '<script type="text/javascript">' . "\n";
  507. echo '//<![CDATA[' . "\n";
  508. echo 'setTimeout("window.location = unescape(\'"'
  509. . PMA_escapeJsString($uri) . '"\')", 2000);' . "\n";
  510. echo '//]]>' . "\n";
  511. echo '</script>' . "\n";
  512. echo '</head>' . "\n";
  513. echo '<body>' . "\n";
  514. echo '<script type="text/javascript">' . "\n";
  515. echo '//<![CDATA[' . "\n";
  516. echo 'document.write(\'<p><a href="' . htmlspecialchars($uri) . '">'
  517. . __('Go') . '</a></p>\');' . "\n";
  518. echo '//]]>' . "\n";
  519. echo '</script></body></html>' . "\n";
  520. } else {
  521. if (SID) {
  522. if (strpos($uri, '?') === false) {
  523. header('Location: ' . $uri . '?' . SID);
  524. } else {
  525. $separator = PMA_get_arg_separator();
  526. header('Location: ' . $uri . $separator . SID);
  527. }
  528. } else {
  529. session_write_close();
  530. if (headers_sent()) {
  531. if (function_exists('debug_print_backtrace')) {
  532. echo '<pre>';
  533. debug_print_backtrace();
  534. echo '</pre>';
  535. }
  536. trigger_error(
  537. 'PMA_sendHeaderLocation called when headers are already sent!',
  538. E_USER_ERROR
  539. );
  540. }
  541. // bug #1523784: IE6 does not like 'Refresh: 0', it
  542. // results in a blank page
  543. // but we need it when coming from the cookie login panel)
  544. if (PMA_IS_IIS && $use_refresh) {
  545. header('Refresh: 0; ' . $uri);
  546. } else {
  547. header('Location: ' . $uri);
  548. }
  549. }
  550. }
  551. }
  552. /**
  553. * Outputs headers to prevent caching in browser (and on the way).
  554. *
  555. * @return void
  556. */
  557. function PMA_noCacheHeader()
  558. {
  559. if (defined('TESTSUITE')) {
  560. return;
  561. }
  562. // rfc2616 - Section 14.21
  563. header('Expires: ' . date(DATE_RFC1123));
  564. // HTTP/1.1
  565. header(
  566. 'Cache-Control: no-store, no-cache, must-revalidate,'
  567. . ' pre-check=0, post-check=0, max-age=0'
  568. );
  569. if (PMA_USR_BROWSER_AGENT == 'IE') {
  570. /* On SSL IE sometimes fails with:
  571. *
  572. * Internet Explorer was not able to open this Internet site. The
  573. * requested site is either unavailable or cannot be found. Please
  574. * try again later.
  575. *
  576. * Adding Pragma: public fixes this.
  577. */
  578. header('Pragma: public');
  579. } else {
  580. header('Pragma: no-cache'); // HTTP/1.0
  581. // test case: exporting a database into a .gz file with Safari
  582. // would produce files not having the current time
  583. // (added this header for Safari but should not harm other browsers)
  584. header('Last-Modified: ' . date(DATE_RFC1123));
  585. }
  586. }
  587. /**
  588. * Sends header indicating file download.
  589. *
  590. * @param string $filename Filename to include in headers if empty,
  591. * none Content-Disposition header will be sent.
  592. * @param string $mimetype MIME type to include in headers.
  593. * @param int $length Length of content (optional)
  594. * @param bool $no_cache Whether to include no-caching headers.
  595. *
  596. * @return void
  597. */
  598. function PMA_downloadHeader($filename, $mimetype, $length = 0, $no_cache = true)
  599. {
  600. if ($no_cache) {
  601. PMA_noCacheHeader();
  602. }
  603. /* Replace all possibly dangerous chars in filename */
  604. $filename = str_replace(array(';', '"', "\n", "\r"), '-', $filename);
  605. if (!empty($filename)) {
  606. header('Content-Description: File Transfer');
  607. header('Content-Disposition: attachment; filename="' . $filename . '"');
  608. }
  609. header('Content-Type: ' . $mimetype);
  610. header('Content-Transfer-Encoding: binary');
  611. if ($length > 0) {
  612. header('Content-Length: ' . $length);
  613. }
  614. }
  615. /**
  616. * Returns value of an element in $array given by $path.
  617. * $path is a string describing position of an element in an associative array,
  618. * eg. Servers/1/host refers to $array[Servers][1][host]
  619. *
  620. * @param string $path path in the arry
  621. * @param array $array the array
  622. * @param mixed $default default value
  623. *
  624. * @return mixed array element or $default
  625. */
  626. function PMA_arrayRead($path, $array, $default = null)
  627. {
  628. $keys = explode('/', $path);
  629. $value =& $array;
  630. foreach ($keys as $key) {
  631. if (! isset($value[$key])) {
  632. return $default;
  633. }
  634. $value =& $value[$key];
  635. }
  636. return $value;
  637. }
  638. /**
  639. * Stores value in an array
  640. *
  641. * @param string $path path in the array
  642. * @param array &$array the array
  643. * @param mixed $value value to store
  644. *
  645. * @return void
  646. */
  647. function PMA_arrayWrite($path, &$array, $value)
  648. {
  649. $keys = explode('/', $path);
  650. $last_key = array_pop($keys);
  651. $a =& $array;
  652. foreach ($keys as $key) {
  653. if (! isset($a[$key])) {
  654. $a[$key] = array();
  655. }
  656. $a =& $a[$key];
  657. }
  658. $a[$last_key] = $value;
  659. }
  660. /**
  661. * Removes value from an array
  662. *
  663. * @param string $path path in the array
  664. * @param array &$array the array
  665. *
  666. * @return void
  667. */
  668. function PMA_arrayRemove($path, &$array)
  669. {
  670. $keys = explode('/', $path);
  671. $keys_last = array_pop($keys);
  672. $path = array();
  673. $depth = 0;
  674. $path[0] =& $array;
  675. $found = true;
  676. // go as deep as required or possible
  677. foreach ($keys as $key) {
  678. if (! isset($path[$depth][$key])) {
  679. $found = false;
  680. break;
  681. }
  682. $depth++;
  683. $path[$depth] =& $path[$depth-1][$key];
  684. }
  685. // if element found, remove it
  686. if ($found) {
  687. unset($path[$depth][$keys_last]);
  688. $depth--;
  689. }
  690. // remove empty nested arrays
  691. for (; $depth >= 0; $depth--) {
  692. if (! isset($path[$depth+1]) || count($path[$depth+1]) == 0) {
  693. unset($path[$depth][$keys[$depth]]);
  694. } else {
  695. break;
  696. }
  697. }
  698. }
  699. /**
  700. * Returns link to (possibly) external site using defined redirector.
  701. *
  702. * @param string $url URL where to go.
  703. *
  704. * @return string URL for a link.
  705. */
  706. function PMA_linkURL($url)
  707. {
  708. if (!preg_match('#^https?://#', $url) || defined('PMA_SETUP')) {
  709. return $url;
  710. } else {
  711. if (!function_exists('PMA_generate_common_url')) {
  712. include_once './libraries/url_generating.lib.php';
  713. }
  714. $params = array();
  715. $params['url'] = $url;
  716. return './url.php' . PMA_generate_common_url($params);
  717. }
  718. }
  719. /**
  720. * Adds JS code snippets to be displayed by the PMA_Response class.
  721. * Adds a newline to each snippet.
  722. *
  723. * @param string $str Js code to be added (e.g. "token=1234;")
  724. *
  725. * @return void
  726. */
  727. function PMA_addJSCode($str)
  728. {
  729. $response = PMA_Response::getInstance();
  730. $header = $response->getHeader();
  731. $scripts = $header->getScripts();
  732. $scripts->addCode($str);
  733. }
  734. /**
  735. * Adds JS code snippet for variable assignment
  736. * to be displayed by the PMA_Response class.
  737. *
  738. * @param string $key Name of value to set
  739. * @param mixed $value Value to set, can be either string or array of strings
  740. * @param bool $escape Whether to escape value or keep it as it is
  741. * (for inclusion of js code)
  742. *
  743. * @return void
  744. */
  745. function PMA_addJSVar($key, $value, $escape = true)
  746. {
  747. PMA_addJSCode(PMA_getJsValue($key, $value, $escape));
  748. }
  749. ?>