Update::Init PHP Method

Init() public method

public Init ( )
    public function Init()
    {
        $version = array();
        if (!file_exists(DATA . "/version.php")) {
            if (file_exists(BASE_PATH . "/.git/HEAD")) {
                $remote = $this->getRemoteVersion("install_git");
                $local = $this->getLocalVersion();
                $version[] = array("version" => $local[0]['version'], "time" => time(), "optout" => "true", "name" => "");
                saveJSON('version.php', $version);
            } else {
                $remote = $this->getRemoteVersion("install_man");
                $version[] = array("version" => $remote[0]["commit"]["sha"], "time" => time(), "optout" => "true", "name" => "");
                saveJSON('version.php', $version);
            }
        } else {
            $local = $this->getLocalVersion();
            if (file_exists(BASE_PATH . "/.git/HEAD")) {
                $current = getJSON('version.php');
                if ($local[0]['version'] != $current[0]['version']) {
                    $remote = $this->getRemoteVersion("update_git", $local[0]['version']);
                    $version[] = array("version" => $local[0]['version'], "time" => time(), "optout" => "true", "name" => "");
                    saveJSON('version.php', $version);
                }
            } else {
                if ($local[0]['version'] == '' && $local[0]['name'] == $_SESSION['user']) {
                    $remote = $this->getRemoteVersion("update_man", $local[0]['version']);
                    $version[] = array("version" => $remote[0]["commit"]["sha"], "time" => time(), "optout" => "true", "name" => $_SESSION['user']);
                    saveJSON('version.php', $version);
                }
            }
            $local = $this->getLocalVersion();
            if (!isset($local[0]['optout'])) {
                $remote = $this->getRemoteVersion("optout", $local[0]['version']);
                $this->OptOut();
            }
        }
    }

Usage Example

*  Copyright (c) Codiad & daeks (codiad.com), distributed
*  as-is and without warranty under the MIT License. See
*  [root]/license.txt for more. This information must remain intact.
*/
require_once '../../common.php';
require_once 'class.update.php';
//////////////////////////////////////////////////////////////////
// Verify Session or Key
//////////////////////////////////////////////////////////////////
checkSession();
$update = new Update();
//////////////////////////////////////////////////////////////////
// Set Initial Version
//////////////////////////////////////////////////////////////////
if ($_GET['action'] == 'init') {
    $update->Init();
}
//////////////////////////////////////////////////////////////////
// Clear Version
//////////////////////////////////////////////////////////////////
if ($_GET['action'] == 'clear') {
    if (checkAccess()) {
        $update->Clear();
    }
}
//////////////////////////////////////////////////////////////////
// OptOut
//////////////////////////////////////////////////////////////////
if ($_GET['action'] == 'optout') {
    if (checkAccess()) {
        $update->OptOut();