static-globals.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. // ===================================
  3. // Organizr Version
  4. $GLOBALS['installedVersion'] = '2.0.32';
  5. // ===================================
  6. // Quick php Version check
  7. $GLOBALS['minimumPHP'] = '7.1.3';
  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. if ($GLOBALS['docker']) {
  17. $getCommit = file_get_contents(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'Github.txt');
  18. $getCommit = (empty($getCommit)) ? 'n/a' : $getCommit;
  19. $GLOBALS['quickCommit'] = $getCommit;
  20. }
  21. $GLOBALS['fileHash'] = (isset($GLOBALS['quickCommit'])) ? $GLOBALS['quickCommit'] : $GLOBALS['installedVersion'];
  22. $GLOBALS['quickConfig'] = (file_exists($GLOBALS['userConfigPath'])) ? loadConfigOnce($GLOBALS['userConfigPath']) : null;
  23. // Quick function for plugins
  24. function pluginFiles($type)
  25. {
  26. $files = '';
  27. switch ($type) {
  28. case 'js':
  29. foreach (glob(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . "*.js") as $filename) {
  30. $files .= '<script src="api/plugins/js/' . basename($filename) . '?v=' . $GLOBALS['fileHash'] . '" defer="true"></script>';
  31. }
  32. break;
  33. case 'css':
  34. foreach (glob(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . "*.js") as $filename) {
  35. $files .= '<link href="api/plugins/css/' . basename($filename) . $GLOBALS['fileHash'] . '" rel="stylesheet">';
  36. }
  37. break;
  38. default:
  39. break;
  40. }
  41. return $files;
  42. }
  43. function loadConfigOnce($path = null)
  44. {
  45. $path = ($path) ? $path : $GLOBALS['userConfigPath'];
  46. if (!is_file($path)) {
  47. return null;
  48. } else {
  49. return (array)call_user_func(function () use ($path) {
  50. return include($path);
  51. });
  52. }
  53. }
  54. function formKey($script = true)
  55. {
  56. if (isset($GLOBALS['quickConfig']['organizrHash'])) {
  57. if ($GLOBALS['quickConfig']['organizrHash'] !== '') {
  58. $hash = password_hash(substr($GLOBALS['quickConfig']['organizrHash'], 2, 10), PASSWORD_BCRYPT);
  59. return ($script) ? '<script>local("s","formKey","' . $hash . '");</script>' : $hash;
  60. }
  61. }
  62. }
  63. function checkFormKey($formKey = '')
  64. {
  65. return password_verify(substr($GLOBALS['quickConfig']['organizrHash'], 2, 10), $formKey);
  66. }
  67. function favIcons()
  68. {
  69. $favicon = '
  70. <link rel="apple-touch-icon" sizes="180x180" href="plugins/images/favicon/apple-touch-icon.png">
  71. <link rel="icon" type="image/png" sizes="32x32" href="plugins/images/favicon/favicon-32x32.png">
  72. <link rel="icon" type="image/png" sizes="16x16" href="plugins/images/favicon/favicon-16x16.png">
  73. <link rel="manifest" href="plugins/images/favicon/site.webmanifest">
  74. <link rel="mask-icon" href="plugins/images/favicon/safari-pinned-tab.svg" color="#5bbad5">
  75. <link rel="shortcut icon" href="plugins/images/favicon/favicon.ico">
  76. <meta name="msapplication-TileColor" content="#da532c">
  77. <meta name="msapplication-TileImage" content="plugins/images/favicon/mstile-144x144.png">
  78. <meta name="msapplication-config" content="plugins/images/favicon/browserconfig.xml">
  79. <meta name="theme-color" content="#ffffff">
  80. ';
  81. if (isset($GLOBALS['quickConfig']['favIcon'])) {
  82. if ($GLOBALS['quickConfig']['favIcon'] !== '') {
  83. $favicon = $GLOBALS['quickConfig']['favIcon'];
  84. }
  85. }
  86. return $favicon;
  87. }
  88. function languagePacks($encode = false)
  89. {
  90. $files = array();
  91. foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'langpack' . DIRECTORY_SEPARATOR . "*.json") as $filename) {
  92. if (strpos(basename($filename), '[') !== false) {
  93. $explode = explode('[', basename($filename));
  94. $files[] = array(
  95. 'filename' => basename($filename),
  96. 'code' => $explode[0],
  97. 'language' => matchBrackets(basename($filename))
  98. );
  99. }
  100. }
  101. usort($files, function ($a, $b) {
  102. return $a['language'] <=> $b['language'];
  103. });
  104. return ($encode) ? json_encode($files) : $files;
  105. }
  106. function matchBrackets($text, $brackets = 's')
  107. {
  108. switch ($brackets) {
  109. case 's':
  110. case 'square':
  111. $pattern = '#\[(.*?)\]#';
  112. break;
  113. case 'c':
  114. case 'curly':
  115. $pattern = '#\((.*?)\)#';
  116. break;
  117. default:
  118. return null;
  119. }
  120. preg_match($pattern, $text, $match);
  121. return $match[1];
  122. }