Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 2aac8c00a1
Fetching contributors…

Cannot retrieve contributors at this time

file 81 lines (73 sloc) 2.209 kb
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
<?php

define("THUMBNAIL_FOLDER", "images/screenshots/thumbnails/");
define("SCREENSHOT_FOLDER", "images/screenshots/");

/**
* Returns an array like array(
* array('thumbnail' => '...', 'image' => '...', 'desc' => ...),
* ...
* )
*/
function getScreenshots()
{
    /**
* Each entry $num => $desc belongs to screenshot number $num with thumbnail images/screenshots/thumbnail/${num}.png
* and image file images/screenshots/${num}.png. $desc will be used as a description.
*/
    $screenshots = array(
        1 => "The projects view",
        2 => "The calendar"
    );
    $ret = array();
    foreach($screenshots as $id => $desc) {
        $ret[] = array(
            'thumbnail' => THUMBNAIL_FOLDER . $id . '.png',
            'image' => SCREENSHOT_FOLDER . $id . '.png',
            'desc' => $desc
        );
    }
    return $ret;
}

function getVersions() {
    static $mtags = false;

    if ($mtags == false) {
        if ('localhost' === $_SERVER['SERVER_NAME']) {
            $mtags = file_get_contents('test.data');
        } else {
            $mtags = file_get_contents('https://api.github.com/repos/Mayflower/PHProjekt/tags');
        }
    }
    if ($mtags === false) {
        // HAELP
        throw new Exception('Could not contact github');
    }

    $tags = json_decode($mtags);
    if (empty($tags)) {
        throw new Exception('No version found!');
    }

    return $tags;
}

/**
* Returns the latest version as returned from github. Looks like stdobject(
* 'name' => '6.1.0',
* 'zipball_url' => '...',
* 'tarball_url' => '...'
* )
*/
function getLatestVersion($includeRC = false)
{
    $tags = getVersions();

    $newest = null;
    foreach ($tags as $t) {
        if (!$includeRC && preg_match('/^\d+\.\d+.\d+$/', $t->name)) {
            if (is_null($newest) || version_compare($newest->name, $t->name, '<')) {
                $newest = $t;
            }
        } else if ($includeRC && preg_match('/^\d+\.\d+.\d+/', $t->name)) {
            if (is_null($newest) || version_compare($newest->name, $t->name, '<')) {
                $newest = $t;
            }
        }
    }
    // Make the newest version the first
    return $newest;
}
Something went wrong with that request. Please try again.