publiclib.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. spl_autoload_register(function ($class_name) {
  3. $path = explode('\\', $class_name);
  4. $fileName = $path[sizeof($path)-1];
  5. $path[sizeof($path)-1] = '';
  6. //$path = strtolower(DIR_ROOT. implode(DIRECTORY_SEPARATOR, $path));
  7. $path = DIR_ROOT . strtolower(implode(DIRECTORY_SEPARATOR, $path));
  8. if(is_file($path . $fileName . '.php')){
  9. return include $path . $fileName . '.php';
  10. }
  11. if(is_file(strtolower($path . $fileName . '.php'))){
  12. return include strtolower($path . $fileName . '.php');
  13. }
  14. @include $path . $fileName . '.php';
  15. });
  16. function is_ajax_request() {
  17. if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
  18. return true;
  19. } else {
  20. return false;
  21. }
  22. }
  23. global $_LANG;
  24. $_LANG = Array();
  25. class Lang {
  26. public static function getStrings($module = '', $lang = null){
  27. global $_LANG;
  28. if($lang == null){
  29. $lang = APP_LANG;
  30. }
  31. if (isset($_LANG[$lang][$module])) {
  32. return $_LANG[$lang][$module];
  33. }
  34. return $module;
  35. }
  36. public static function getString($string = '', $module = null, $lang = null) {
  37. global $_LANG;
  38. if($lang == null){
  39. $lang = APP_LANG;
  40. }
  41. if (isset($_LANG[$lang][$string]) && is_string($_LANG[$lang][$string])) {
  42. return $_LANG[$lang][$string];
  43. }
  44. if (isset($_LANG[$lang][$module][$string])) {
  45. return $_LANG[$lang][$module][$string];
  46. }
  47. return $string;
  48. }
  49. public static function buildStrings() {
  50. global $_LANG;
  51. if (isset($_SESSION['cache']['strings']) && CACHE_LANG) {
  52. $_LANG = $_SESSION['cache']['strings'];
  53. return;
  54. }
  55. $rdi = new RecursiveDirectoryIterator(DIR_APP);
  56. foreach (new RecursiveIteratorIterator($rdi) as $file) {
  57. if (preg_match("/lang\/.*\.php$/", $file)) {
  58. $included_lang = explode('/', $file);
  59. $included_lang = end($included_lang);
  60. $included_lang = str_replace('.php', '', $included_lang);
  61. $lang = Array();
  62. include_once $file;
  63. $_LANG[$included_lang] = $lang;
  64. $lang = Array();
  65. }
  66. }
  67. }
  68. }