summaryrefslogtreecommitdiff
path: root/include/version.php
blob: d1c5e03b506cd7df198b127482bcec2731a01aeb (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
<?php

	/* for package maintainers who don't use git: if version_static.txt exists in tt-rss root
		directory, its contents are displayed instead of git commit-based version, this could be generated
		based on source git tree commit used when creating the package */

	function get_version(&$git_commit = false, &$git_timestamp = false) {
		$version = "UNKNOWN (Unsupported)";

		date_default_timezone_set('UTC');
		$root_dir = dirname(dirname(__FILE__));

		if (file_exists("$root_dir/version_static.txt")) {
			$version = trim(file_get_contents("$root_dir/version_static.txt")) . " (Unsupported)";
		} else if (is_dir("$root_dir/.git")) {
			$rc = 0;
			$output = [];

			exec("git log --pretty='%ct %h' -n1 HEAD " . escapeshellarg($root_dir), $output, $rc);

			if ($rc == 0) {
				if (is_array($output) && count($output) > 0) {
					list ($timestamp, $commit) = explode(" ", $output[0], 2);

					$git_commit = $commit;
					$git_timestamp = $timestamp;

					$version = strftime("%y.%m", $timestamp) . "-$commit";
				}
			}
		}

		return $version;
	}

	define('VERSION', get_version());