api.compat.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /**
  3. * Some legacy workaround here
  4. */
  5. if (!function_exists('__')) {
  6. /**
  7. * Dummy i18n function
  8. *
  9. * @param string $str
  10. * @return string
  11. */
  12. function __($str) {
  13. return($str);
  14. }
  15. }
  16. if (!function_exists('show_window')) {
  17. /**
  18. * Replace for system content output
  19. *
  20. * @param string $title
  21. * @param string $data
  22. * @param string $align
  23. */
  24. function show_window($title, $data, $align = "left") {
  25. $result = '';
  26. if (!empty($title)) {
  27. $result = $title . "\n";
  28. }
  29. $result .= $data . "\n";
  30. print($result);
  31. }
  32. }
  33. if (!function_exists('curdatetime')) {
  34. /**
  35. * Returns current date and time in mysql DATETIME view
  36. *
  37. * @return string
  38. */
  39. function curdatetime() {
  40. $currenttime = date("Y-m-d H:i:s");
  41. return($currenttime);
  42. }
  43. }
  44. if (!function_exists('rcms_redirect')) {
  45. /**
  46. * Shows redirection javascript.
  47. *
  48. * @param string $url
  49. * @param bool $header
  50. */
  51. function rcms_redirect($url, $header = false) {
  52. if ($header) {
  53. @header('Location: ' . $url);
  54. } else {
  55. echo '<script language="javascript">document.location.href="' . $url . '";</script>';
  56. }
  57. }
  58. }
  59. if (!function_exists('ispos')) {
  60. /**
  61. * Checks for substring in string
  62. *
  63. * @param string $string
  64. * @param string $search
  65. * @return bool
  66. */
  67. function ispos($string, $search) {
  68. if (strpos($string, $search) === false) {
  69. return(false);
  70. } else {
  71. return(true);
  72. }
  73. }
  74. }
  75. /**
  76. * Advanced php5 scandir analog wit some filters
  77. *
  78. * @param string $directory Directory to scan
  79. * @param string $exp Filter expression - like *.ini or *.dat
  80. * @param string $type Filter type - all or dir
  81. * @param bool $do_not_filter
  82. *
  83. * @return array
  84. */
  85. function rcms_scandir($directory, $exp = '', $type = 'all', $do_not_filter = false) {
  86. $dir = $ndir = array();
  87. if (!empty($exp)) {
  88. $exp = '/^' . str_replace('*', '(.*)', str_replace('.', '\\.', $exp)) . '$/';
  89. }
  90. if (!empty($type) && $type !== 'all') {
  91. $func = 'is_' . $type;
  92. }
  93. if (is_dir($directory)) {
  94. $fh = opendir($directory);
  95. while (false !== ($filename = readdir($fh))) {
  96. if (substr($filename, 0, 1) != '.' || $do_not_filter) {
  97. if ((empty($type) || $type == 'all' || $func($directory . '/' . $filename)) && (empty($exp) || preg_match($exp, $filename))) {
  98. $dir[] = $filename;
  99. }
  100. }
  101. }
  102. closedir($fh);
  103. natsort($dir);
  104. }
  105. return $dir;
  106. }
  107. /**
  108. * Parses standard INI-file structure and returns this as key=>value array
  109. *
  110. * @param string $filename Existing file name
  111. * @param bool $blocks Section parsing flag
  112. *
  113. * @return array
  114. */
  115. function rcms_parse_ini_file($filename, $blocks = false) {
  116. $array1 = file($filename);
  117. $section = '';
  118. foreach ($array1 as $filedata) {
  119. $dataline = trim($filedata);
  120. $firstchar = substr($dataline, 0, 1);
  121. if ($firstchar != ';' && !empty($dataline)) {
  122. if ($blocks && $firstchar == '[' && substr($dataline, -1, 1) == ']') {
  123. $section = strtolower(substr($dataline, 1, -1));
  124. } else {
  125. $delimiter = strpos($dataline, '=');
  126. if ($delimiter > 0) {
  127. preg_match("/^[\s]*(.*?)[\s]*[=][\s]*(\"|)(.*?)(\"|)[\s]*$/", $dataline, $matches);
  128. $key = $matches[1];
  129. $value = $matches[3];
  130. if ($blocks) {
  131. if (!empty($section)) {
  132. $array2[$section][$key] = stripcslashes($value);
  133. }
  134. } else {
  135. $array2[$key] = stripcslashes($value);
  136. }
  137. } else {
  138. if ($blocks) {
  139. if (!empty($section)) {
  140. $array2[$section][trim($dataline)] = '';
  141. }
  142. } else {
  143. $array2[trim($dataline)] = '';
  144. }
  145. }
  146. }
  147. }
  148. }
  149. return (!empty($array2)) ? $array2 : false;
  150. }