summaryrefslogtreecommitdiff
path: root/include/version.php
blob: e5f91bd9cf9ce0411a7561debab14ab9593a6c6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
	define('VERSION_STATIC', '18.12');

	function get_version() {
		date_default_timezone_set('UTC');
		$root_dir = dirname(dirname(__FILE__));

		if (is_dir("$root_dir/.git") && file_exists("$root_dir/.git/HEAD")) {
			$head = trim(file_get_contents("$root_dir/.git/HEAD"));

			if ($head) {
				$matches = array();

				if (preg_match("/^ref: (.*)/", $head, $matches)) {
					$ref = $matches[1];

					if (!file_exists("$root_dir/.git/$ref"))
						return VERSION_STATIC;
					$suffix = substr(trim(file_get_contents("$root_dir/.git/$ref")), 0, 7);
					$timestamp = filemtime("$root_dir/.git/$ref");

					define("GIT_VERSION_HEAD", $suffix);
					define("GIT_VERSION_TIMESTAMP", $timestamp);

					return VERSION_STATIC . " ($suffix)";

				} else {
					$suffix = substr(trim($head), 0, 7);
					$timestamp = filemtime("$root_dir/.git/HEAD");

					define("GIT_VERSION_HEAD", $suffix);
					define("GIT_VERSION_TIMESTAMP", $timestamp);

					return VERSION_STATIC . " ($suffix)";
				}
			}
		}

		return VERSION_STATIC;

	}

	define('VERSION', get_version());