static-globals.php 5.5 KB

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