publiclib.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. class Connection {
  17. private function __construct() {
  18. }
  19. public static function open($connection_info = null) {
  20. $user = isset($connection_info['user']) ? $connection_info['user'] : NULL;
  21. $pass = isset($connection_info['pass']) ? $connection_info['pass'] : NULL;
  22. $name = isset($connection_info['name']) ? $connection_info['name'] : NULL;
  23. $host = isset($connection_info['host']) ? $connection_info['host'] : NULL;
  24. $driver = isset($connection_info['driver']) ? $connection_info['driver'] : NULL;
  25. $port = isset($connection_info['port']) ? $connection_info['port'] : NULL;
  26. $prefix = isset($connection_info['prefix']) ? $connection_info['prefix'] : '';
  27. switch ($driver) {
  28. case 'pgsql':
  29. $port = $port ? $port : '5432';
  30. $conn = new PDO("pgsql:dbname={$name}; user={$user}; password={$pass};host=$host;port={$port}");
  31. break;
  32. case 'mysql':
  33. $port = $port ? $port : '3306';
  34. $conn = new PDO("mysql:host={$host};port={$port};dbname={$name}", $user, $pass);
  35. break;
  36. case 'sqlite':
  37. $conn = new PDO("sqlite:{$name}");
  38. break;
  39. case 'ibase':
  40. $conn = new PDO("firebird:dbname={$name}", $user, $pass);
  41. break;
  42. case 'oci8':
  43. $conn = new PDO("oci:dbname={$name}", $user, $pass);
  44. break;
  45. case 'mssql':
  46. $conn = new PDO("mssql:host={$host},1433;dbname={$name}", $user, $pass);
  47. break;
  48. }
  49. $conn->prefix = $prefix;
  50. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  51. return $conn;
  52. }
  53. }
  54. function is_ajax_request() {
  55. if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
  56. return true;
  57. } else {
  58. return false;
  59. }
  60. }
  61. function last_class() {
  62. $class = get_declared_classes()[sizeof(get_declared_classes()) - 1];
  63. return new $class;
  64. }
  65. global $_LANG;
  66. $_LANG = Array();
  67. class Lang {
  68. public static function getStrings($module = '', $lang = null){
  69. global $_LANG;
  70. if($lang == null){
  71. $lang = APP_LANG;
  72. }
  73. if (isset($_LANG[$lang][$module])) {
  74. return $_LANG[$lang][$module];
  75. }
  76. return $module;
  77. }
  78. public static function getString($string = '', $module = null, $lang = null) {
  79. global $_LANG;
  80. if($lang == null){
  81. $lang = APP_LANG;
  82. }
  83. if (isset($_LANG[$lang][$string]) && is_string($_LANG[$lang][$string])) {
  84. return $_LANG[$lang][$string];
  85. }
  86. if (isset($_LANG[$lang][$module][$string])) {
  87. return $_LANG[$lang][$module][$string];
  88. }
  89. return $string;
  90. }
  91. public static function buildStrings() {
  92. global $_LANG;
  93. if (isset($_SESSION['cache']['strings']) && CACHE_LANG) {
  94. $_LANG = $_SESSION['cache']['strings'];
  95. return;
  96. }
  97. $rdi = new RecursiveDirectoryIterator(DIR_APP);
  98. foreach (new RecursiveIteratorIterator($rdi) as $file) {
  99. if (preg_match("/lang\/.*\.php$/", $file)) {
  100. $included_lang = explode('/', $file);
  101. $included_lang = end($included_lang);
  102. $included_lang = str_replace('.php', '', $included_lang);
  103. $lang = Array();
  104. include_once $file;
  105. $_LANG[$included_lang] = $lang;
  106. $lang = Array();
  107. }
  108. }
  109. }
  110. }
  111. abstract class Controller {
  112. }