static-globals.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // ===================================
  3. // Organizr Version
  4. $GLOBALS['installedVersion'] = '2.0.0-beta.980';
  5. // ===================================
  6. // Quick php Version check
  7. $GLOBALS['minimumPHP'] = '7.0.0';
  8. if (!(version_compare(PHP_VERSION, $GLOBALS['minimumPHP']) >= 0)) {
  9. die('Organizr needs PHP Version: ' . $GLOBALS['minimumPHP'] . '<br/> You have PHP Version: ' . PHP_VERSION);
  10. }
  11. // Set GLOBALS from config file
  12. $GLOBALS['userConfigPath'] = dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
  13. $GLOBALS['defaultConfigPath'] = dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'default.php';
  14. $GLOBALS['currentTime'] = gmdate("Y-m-d\TH:i:s\Z");
  15. $GLOBALS['docker'] = (file_exists(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'Docker.txt')) ? true : false;
  16. // Quick function for plugins
  17. function pluginFiles($type)
  18. {
  19. $files = '';
  20. switch ($type) {
  21. case 'js':
  22. foreach (glob(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . "*.js") as $filename) {
  23. $files .= '<script src="api/plugins/js/' . basename($filename) . '?v=' . $GLOBALS['installedVersion'] . '" defer="true"></script>';
  24. }
  25. break;
  26. case 'css':
  27. foreach (glob(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . "*.js") as $filename) {
  28. $files .= '<link href="api/plugins/css/' . basename($filename) . $GLOBALS['installedVersion'] . '" rel="stylesheet">';
  29. }
  30. break;
  31. default:
  32. break;
  33. }
  34. return $files;
  35. }
  36. function loadConfigOnce($path = null)
  37. {
  38. $path = ($path) ? $path : $GLOBALS['userConfigPath'];
  39. if (!is_file($path)) {
  40. return null;
  41. } else {
  42. return (array)call_user_func(function () use ($path) {
  43. return include($path);
  44. });
  45. }
  46. }
  47. function favIcons()
  48. {
  49. $favicon = '
  50. <link rel="apple-touch-icon" sizes="180x180" href="plugins/images/favicon/apple-touch-icon.png">
  51. <link rel="icon" type="image/png" sizes="32x32" href="plugins/images/favicon/favicon-32x32.png">
  52. <link rel="icon" type="image/png" sizes="16x16" href="plugins/images/favicon/favicon-16x16.png">
  53. <link rel="manifest" href="plugins/images/favicon/site.webmanifest">
  54. <link rel="mask-icon" href="plugins/images/favicon/safari-pinned-tab.svg" color="#5bbad5">
  55. <link rel="shortcut icon" href="plugins/images/favicon/favicon.ico">
  56. <meta name="msapplication-TileColor" content="#da532c">
  57. <meta name="msapplication-TileImage" content="plugins/images/favicon/mstile-144x144.png">
  58. <meta name="msapplication-config" content="plugins/images/favicon/browserconfig.xml">
  59. <meta name="theme-color" content="#ffffff">
  60. ';
  61. if (file_exists($GLOBALS['userConfigPath'])) {
  62. $config = loadConfigOnce($GLOBALS['userConfigPath']);
  63. if (isset($config['favIcon'])) {
  64. if ($config['favIcon'] !== '') {
  65. $favicon = $config['favIcon'];
  66. }
  67. }
  68. }
  69. return $favicon;
  70. }
  71. function languagePacks($encode = false)
  72. {
  73. $files = array();
  74. foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'langpack' . DIRECTORY_SEPARATOR . "*.json") as $filename) {
  75. if (strpos(basename($filename), '[') !== false) {
  76. $explode = explode('[', basename($filename));
  77. $files[] = array(
  78. 'filename' => basename($filename),
  79. 'code' => $explode[0],
  80. 'language' => matchBrackets(basename($filename))
  81. );
  82. }
  83. }
  84. usort($files, function ($a, $b) {
  85. return $a['language'] <=> $b['language'];
  86. });
  87. return ($encode) ? json_encode($files) : $files;
  88. }
  89. function matchBrackets($text, $brackets = 's')
  90. {
  91. switch ($brackets) {
  92. case 's':
  93. case 'square':
  94. $pattern = '#\[(.*?)\]#';
  95. break;
  96. case 'c':
  97. case 'curly':
  98. $pattern = '#\((.*?)\)#';
  99. break;
  100. default:
  101. return null;
  102. }
  103. preg_match($pattern, $text, $match);
  104. return $match[1];
  105. }