Browse Source

remove version.php and VERSION global constant, do version-related things in a slightly less ridiculous way

Andrew Dolgov 6 months ago
parent
commit
72d0fac80c
8 changed files with 43 additions and 56 deletions
  1. 1 2
      classes/handler/public.php
  2. 40 1
      include/functions.php
  3. 0 1
      include/sessions.php
  4. 0 36
      include/version.php
  5. 0 5
      index.php
  6. 1 1
      plugins/af_comics/init.php
  7. 1 9
      prefs.php
  8. 0 1
      update_daemon2.php

+ 1 - 2
classes/handler/public.php

@@ -85,7 +85,7 @@ class Handler_Public extends Handler {
 			$tpl->readTemplateFromFile("templates/generated_feed.txt");
 
 			$tpl->setVariable('FEED_TITLE', $feed_title, true);
-			$tpl->setVariable('VERSION', VERSION, true);
+			$tpl->setVariable('VERSION', get_version(), true);
 			$tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
 
 			$tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
@@ -180,7 +180,6 @@ class Handler_Public extends Handler {
 			$feed = array();
 
 			$feed['title'] = $feed_title;
-			$feed['version'] = VERSION;
 			$feed['feed_url'] = $feed_self_url;
 
 			$feed['self_url'] = get_self_url_prefix();

+ 40 - 1
include/functions.php

@@ -151,7 +151,6 @@
 	}
 
 	require_once 'db-prefs.php';
-	require_once 'version.php';
 	require_once 'controls.php';
 
 	define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . VERSION . ' (http://tt-rss.org/)');
@@ -1882,3 +1881,43 @@
 
 		return $ts;
 	}
+
+	/* 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) {
+		global $ttrss_version;
+
+		if (isset($ttrss_version))
+			return $ttrss_version;
+
+		$ttrss_version = "UNKNOWN (Unsupported)";
+
+		date_default_timezone_set('UTC');
+		$root_dir = dirname(dirname(__FILE__));
+
+		if (file_exists("$root_dir/version_static.txt")) {
+			$ttrss_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=".escapeshellarg('%ct %h')." -n1 HEAD " . escapeshellarg($root_dir) . ' 2>&1', $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;
+
+					$ttrss_version = strftime("%y.%m", $timestamp) . "-$commit";
+				}
+			} else {
+				user_error("Unable to determine version: " . implode("\n", $output), E_USER_WARNING);
+			}
+		}
+
+		return $ttrss_version;
+	}

+ 0 - 1
include/sessions.php

@@ -7,7 +7,6 @@
 	require_once "errorhandler.php";
 	require_once "lib/accept-to-gettext.php";
 	require_once "lib/gettext/gettext.inc";
-	require_once "version.php";
 
 	$session_expire = min(2147483647 - time() - 1, max(SESSION_COOKIE_LIFETIME, 86400));
 	$session_name = (!defined('TTRSS_SESSION_NAME')) ? "ttrss_sid" : TTRSS_SESSION_NAME;

+ 0 - 36
include/version.php

@@ -1,36 +0,0 @@
-<?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());

+ 0 - 5
index.php

@@ -23,7 +23,6 @@
 	require_once "sessions.php";
 	require_once "functions.php";
 	require_once "sanity_check.php";
-	require_once "version.php";
 	require_once "config.php";
 	require_once "db-prefs.php";
 
@@ -40,10 +39,6 @@
 	<title>Tiny Tiny RSS</title>
     <meta name="viewport" content="initial-scale=1,width=device-width" />
 
-	<script type="text/javascript">
-		var __ttrss_version = "<?php echo VERSION ?>"
-	</script>
-
 	<?php if ($_SESSION["uid"]) {
 		$theme = get_pref("USER_CSS_THEME", false, false);
 		if ($theme && theme_exists("$theme")) {

+ 1 - 1
plugins/af_comics/init.php

@@ -110,7 +110,7 @@ class Af_Comics extends Plugin {
 			$tpl->readTemplateFromFile('templates/generated_feed.txt');
 
 			$tpl->setVariable('FEED_TITLE', $feed_title, true);
-			$tpl->setVariable('VERSION', VERSION, true);
+			$tpl->setVariable('VERSION', get_version(), true);
 			$tpl->setVariable('FEED_URL', htmlspecialchars($fetch_url), true);
 			$tpl->setVariable('SELF_URL', $site_url, true);
 

+ 1 - 9
prefs.php

@@ -16,7 +16,6 @@
 	require_once "sessions.php";
 	require_once "functions.php";
 	require_once "sanity_check.php";
-	require_once "version.php";
 	require_once "config.php";
 	require_once "db-prefs.php";
 
@@ -32,10 +31,6 @@
 	<title>Tiny Tiny RSS : <?php echo __("Preferences") ?></title>
     <meta name="viewport" content="initial-scale=1,width=device-width" />
 
-	<script type="text/javascript">
-		var __ttrss_version = "<?php echo VERSION ?>"
-	</script>
-
 	<?php if ($_SESSION["uid"]) {
 		$theme = get_pref("USER_CSS_THEME", false, false);
 		if ($theme && theme_exists("$theme")) {
@@ -164,10 +159,7 @@
         </div>
     <div id="footer" dojoType="dijit.layout.ContentPane" region="bottom">
         <a class="text-muted" target="_blank" href="http://tt-rss.org/">
-        Tiny Tiny RSS</a>
-        <?php if (!defined('HIDE_VERSION')) { ?>
-             v<?php echo VERSION ?>
-        <?php } ?>
+        Tiny Tiny RSS</a> v<?php echo get_version() ?>
         &copy; 2005-<?php echo date('Y') ?>
         <a class="text-muted" target="_blank"
         href="http://fakecake.org/">Andrew Dolgov</a>

+ 0 - 1
update_daemon2.php

@@ -8,7 +8,6 @@
 
 	define('DISABLE_SESSIONS', true);
 
-	require_once "version.php";
 	require_once "autoload.php";
 	require_once "functions.php";
 	require_once "config.php";