Skip to content

Instantly share code, notes, and snippets.

@zeelorenc
Created August 27, 2015 14:36
Show Gist options
  • Save zeelorenc/091796d5597b7103e3f7 to your computer and use it in GitHub Desktop.
Save zeelorenc/091796d5597b7103e3f7 to your computer and use it in GitHub Desktop.
<?php
// Basic PHP script which shows the 5 (default) most recent revisions to a particular project as an image.
// RevCTRL (c) 2015
// This page creates an image
header("Content-Type: image/png");
// Fetch data through the RevCTRL api
$projectId = $_GET['id']; // The RevCTRL app project id
// Revisions array (change this to translated stuff)
$revisionType = [
'addition' => 'added ',
'removal' => 'removed ',
'change' => 'changed ',
'fix' => 'fixed '
];
// Fetch data through the RevCTRL api
$jsonData = json_decode(file_get_contents('https://www.revctrl.com/api/projects/' . $projectId), true);
// Find latest shit
$jsonData = $jsonData['latest_changelog'];
// How many revisions should we show on the image?
$revisionLimit = count($jsonData['revisions']);
// Create the image and tailor the height to the number of revisions
// If your revisions are lengthy, increase the width or modify the whole code
$im = @imagecreate(780, 12 * $revisionLimit + 2);
// Make the background white and afterwards transparent
$background_color = imagecolorallocate($im, 255, 255, 255);
imagecolortransparent($im, $background_color);
// Text color is by default black
$text_color = imagecolorallocate($im, 0, 0, 0);
// State the project name, version and how many revisions there are
//imagestring($im, 2, 5, 5, 'Latest version for ' . $jsonData['project'] . ' is ' . $jsonData['current_version'] . '. Here\'s the ' . $revisionLimit . ' most recent revisions:', $text_color);
// Loop through every single revision that is the latest.
foreach($jsonData['revisions'] as $id => $key)
{
imagestring($im, 2, 2, 12 * $id, $revisionType[$key['type']] . html_entity_decode(strip_tags($key['revision'])), $text_color);
// Only want to show five results, the below can be removed optionally
if($id > $revisionLimit)
break;
}
// Create and destroy image
imagepng($im);
imagedestroy($im);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment