publiclib.php 3.6 KB

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