1
0
www.mikescher.com/www/commands/site_gitinfo.php

26 lines
986 B
PHP
Raw Permalink Normal View History

2020-02-21 03:46:51 +01:00
<?php
require_once (__DIR__ . '/../internals/website.php');
/** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
if (!isset($API_OPTIONS['field'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; }
2023-09-12 17:43:01 +02:00
$info = $SITE->gitStatus();
function printInfo($v) { if ($v === false) throw new Exception('Failed to query field'); else echo $v; }
2020-02-21 03:46:51 +01:00
2023-09-12 17:43:01 +02:00
$field = strtolower($API_OPTIONS['field']);
2020-02-21 03:46:51 +01:00
2023-09-12 17:43:01 +02:00
if ($field === 'branch') { printInfo($info[0]); return; }
if ($field === 'head') { printInfo($info[1]); return; }
if ($field === 'timestamp') { printInfo($info[3]); return; }
if ($field === 'origin') { printInfo(str_replace(';', "\n", $info[4])); return; }
if ($field === 'message') { printInfo($info[5]); return; }
2020-02-21 03:46:51 +01:00
$FRAME_OPTIONS->statuscode = 400;
echo 'Unknown field';
return;