4
0

static-globals.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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['commit'] = $getCommit;
  20. }
  21. $GLOBALS['fileHash'] = (isset($GLOBALS['commit'])) ? $GLOBALS['commit'] : $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()
  55. {
  56. if (isset($GLOBALS['quickConfig']['organizrAPI'])) {
  57. if ($GLOBALS['quickConfig']['organizrAPI'] !== '') {
  58. $hash = password_hash(substr($GLOBALS['quickConfig']['organizrHash'], 2, 10), PASSWORD_BCRYPT);
  59. return '<script>local("s","formKey","' . $hash . '");</script>';
  60. }
  61. }
  62. }
  63. function favIcons()
  64. {
  65. $favicon = '
  66. <link rel="apple-touch-icon" sizes="180x180" href="plugins/images/favicon/apple-touch-icon.png">
  67. <link rel="icon" type="image/png" sizes="32x32" href="plugins/images/favicon/favicon-32x32.png">
  68. <link rel="icon" type="image/png" sizes="16x16" href="plugins/images/favicon/favicon-16x16.png">
  69. <link rel="manifest" href="plugins/images/favicon/site.webmanifest">
  70. <link rel="mask-icon" href="plugins/images/favicon/safari-pinned-tab.svg" color="#5bbad5">
  71. <link rel="shortcut icon" href="plugins/images/favicon/favicon.ico">
  72. <meta name="msapplication-TileColor" content="#da532c">
  73. <meta name="msapplication-TileImage" content="plugins/images/favicon/mstile-144x144.png">
  74. <meta name="msapplication-config" content="plugins/images/favicon/browserconfig.xml">
  75. <meta name="theme-color" content="#ffffff">
  76. ';
  77. if (isset($GLOBALS['quickConfig']['favIcon'])) {
  78. if ($GLOBALS['quickConfig']['favIcon'] !== '') {
  79. $favicon = $GLOBALS['quickConfig']['favIcon'];
  80. }
  81. }
  82. return $favicon;
  83. }
  84. function languagePacks($encode = false)
  85. {
  86. $files = array();
  87. foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'langpack' . DIRECTORY_SEPARATOR . "*.json") as $filename) {
  88. if (strpos(basename($filename), '[') !== false) {
  89. $explode = explode('[', basename($filename));
  90. $files[] = array(
  91. 'filename' => basename($filename),
  92. 'code' => $explode[0],
  93. 'language' => matchBrackets(basename($filename))
  94. );
  95. }
  96. }
  97. usort($files, function ($a, $b) {
  98. return $a['language'] <=> $b['language'];
  99. });
  100. return ($encode) ? json_encode($files) : $files;
  101. }
  102. function matchBrackets($text, $brackets = 's')
  103. {
  104. switch ($brackets) {
  105. case 's':
  106. case 'square':
  107. $pattern = '#\[(.*?)\]#';
  108. break;
  109. case 'c':
  110. case 'curly':
  111. $pattern = '#\((.*?)\)#';
  112. break;
  113. default:
  114. return null;
  115. }
  116. preg_match($pattern, $text, $match);
  117. return $match[1];
  118. }