From f9c413d85a9e04b9c4b0645936b9d9024208686b Mon Sep 17 00:00:00 2001 From: Vincent LAURENT Date: Sat, 20 May 2023 02:05:24 +0200 Subject: [PATCH] Retrieving the current commit number to display it in the footer of each page --- app.php | 22 ++++++++++++++++++++++ templates/metadata.html.php | 6 +++--- templates/organization.html.php | 6 +++--- templates/signature.html.php | 6 +++--- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/app.php b/app.php index 32e11c0..b8d857d 100644 --- a/app.php +++ b/app.php @@ -10,6 +10,8 @@ $f3->set('XFRAME', null); // Allow use in an iframe $f3->set('ROOT', __DIR__); $f3->set('UI', $f3->get('ROOT')."/templates/"); $f3->set('UPLOADS', sys_get_temp_dir()."/"); +$f3->set('COMMIT', getCommit()); + $f3->config(__DIR__.'/config/config.ini'); if($f3->get('PDF_STORAGE_PATH') && !preg_match('|/$|', $f3->get('PDF_STORAGE_PATH'))) { @@ -359,6 +361,26 @@ $f3->route('GET /metadata', } ); +function getCommit() { + if(!file_exists(__DIR__.'/.git/HEAD')) { + + return null; + } + + $head = str_replace(["ref: ", "\n"], "", file_get_contents(__DIR__.'/.git/HEAD')); + $commit = null; + + if(strpos($head, "refs/") !== 0) { + $commit = $head; + } + + if(file_exists(__DIR__.'/.git/'.$head)) { + $commit = str_replace("\n", "", file_get_contents(__DIR__.'/.git/'.$head)); + } + + return substr($commit, 0, 7); +} + function convertPHPSizeToBytes($sSize) { $sSuffix = strtoupper(substr($sSize, -1)); diff --git a/templates/metadata.html.php b/templates/metadata.html.php index 4f525ba..c842ee1 100644 --- a/templates/metadata.html.php +++ b/templates/metadata.html.php @@ -7,7 +7,7 @@ - + " rel="stylesheet"> Édition des métadonnées d'un PDF @@ -45,7 +45,7 @@
@@ -102,6 +102,6 @@ - + diff --git a/templates/organization.html.php b/templates/organization.html.php index ae69acf..0eef40a 100644 --- a/templates/organization.html.php +++ b/templates/organization.html.php @@ -7,7 +7,7 @@ - + " rel="stylesheet"> Organiser un PDF @@ -45,7 +45,7 @@
@@ -157,6 +157,6 @@ - + diff --git a/templates/signature.html.php b/templates/signature.html.php index ef41345..5764c22 100644 --- a/templates/signature.html.php +++ b/templates/signature.html.php @@ -7,7 +7,7 @@ - + " rel="stylesheet"> Signature PDF @@ -45,7 +45,7 @@
@@ -265,6 +265,6 @@ hash = ""; - +