version.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. define('VERSION_STATIC', '17.12');
  3. function get_version() {
  4. date_default_timezone_set('UTC');
  5. $root_dir = dirname(dirname(__FILE__));
  6. if (is_dir("$root_dir/.git") && file_exists("$root_dir/.git/HEAD")) {
  7. $head = trim(file_get_contents("$root_dir/.git/HEAD"));
  8. if ($head) {
  9. $matches = array();
  10. if (preg_match("/^ref: (.*)/", $head, $matches)) {
  11. $ref = $matches[1];
  12. if (!file_exists("$root_dir/.git/$ref"))
  13. return VERSION_STATIC;
  14. $suffix = substr(trim(file_get_contents("$root_dir/.git/$ref")), 0, 7);
  15. $timestamp = filemtime("$root_dir/.git/$ref");
  16. define("GIT_VERSION_HEAD", $suffix);
  17. define("GIT_VERSION_TIMESTAMP", $timestamp);
  18. return VERSION_STATIC . " ($suffix)";
  19. } else {
  20. $suffix = substr(trim($head), 0, 7);
  21. $timestamp = filemtime("$root_dir/.git/HEAD");
  22. define("GIT_VERSION_HEAD", $suffix);
  23. define("GIT_VERSION_TIMESTAMP", $timestamp);
  24. return VERSION_STATIC . " ($suffix)";
  25. }
  26. }
  27. }
  28. return VERSION_STATIC;
  29. }
  30. define('VERSION', get_version());