novia713
10/14/2017 - 3:23 PM

dc_checker.php

<?php

$file = "/Users/leandro/.console/version";
$saved_version = "0";
$saved_date = "";
if (file_exists($file)){
    $fp = fopen($file, 'r');
    list($saved_date, $saved_version) =  explode("|", @fread($fp, filesize($file)));
}

//if never checked or today didn't check
if (date('Ymd') != $saved_date){
    $version =
        @json_decode(
            @file_get_contents(
                "http://api.github.com/repos/hechoendrupal/drupal-console/releases/latest",
                false,
                stream_context_create([ 'http' => [ 'method' => 'GET', 'header' => [ 'User-Agent: PHP' ] ] ])
            ))->tag_name;

    if ( ((int)str_replace(".", "", $version) > (int)str_replace(".", "", $saved_version)) && ($saved_version > 0)){
        print "version $version update available";
    }

    if ($version){
        $fp = fopen($file, 'w');
        fwrite($fp, date('Ymd'). "|". $version);
        fclose($fp);
    }
}