static-globals.php 4.8 KB

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