publiclib.php 4.1 KB

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