<?php
/**
 * The Sowmedia WordPress Plugin/Theme Updater Class
 * @author Sowmedia.nl (Steve Lock, Jaco Ruit)
 */

$path = untrailingslashit(dirname(__FILE__));

/** Wrapper for v1 of the Repo API **/
if(!class_exists("\\Sowmedia\\Repo\\API\\v1\\Exception"))
    require($path . "/lib/Sowmedia/Repo/API/v1/Exception.php");
if(!class_exists("\\Sowmedia\\Repo\\API\\v1\\Endpoint"))
    require($path . "/lib/Sowmedia/Repo/API/v1/Endpoint.php");

/** Frotend **/
if(!class_exists("\\Sowmedia\\Repo\\Frontend\\LicensePage"))
    require($path . "/lib/Sowmedia/Repo/Frontend/LicensePage.php");
if(!class_exists("\\Sowmedia\\Repo\\Frontend\\AdminNotices"))
    require($path . "/lib/Sowmedia/Repo/Frontend/AdminNotices.php");

/** Updaters **/
if(!class_exists("\\Sowmedia\\Repo\\Updaters\\LegacyUpdater"))
    require($path . "/lib/Sowmedia/Repo/Updaters/LegacyUpdater.php");
if(!class_exists("\\Sowmedia\\Repo\\Updaters\\GenesisUpdater"))
    require($path . "/lib/Sowmedia/Repo/Updaters/GenesisUpdater.php");

if(!function_exists("sowmedia_init_legacy_updater")){
    /**
     * Instantiate an updatable plugin through Sowmedia
     *
     * @param  multi $passthrough
     * @return object Updater
     */
    function sowmedia_init_legacy_updater($pass_through){
        return new \Sowmedia\Repo\Updaters\LegacyUpdater("http://repo.sowmedia.nl", $pass_through);
    }
}

/** Backwards compatibility **/
if(!function_exists("sowmedia_updater")) {
    function sowmedia_updater($pass_through){
        trigger_error("The function `sowmedia_updater` is deprecated. Please use `sowmedia_init_updater` to enable the modernized updater.");
        return sowmedia_init_legacy_updater($pass_through);
    }
}

if(!function_exists("sowmedia_init_updater")){
    function sowmedia_init_updater($pass_through, $is_free = false) {
        return new \Sowmedia\Repo\Updaters\GenesisUpdater($pass_through, $is_free);
    }
}
