Market::Install PHP Method

Install() public method

public Install ( $type, $name, $repo )
    public function Install($type, $name, $repo)
    {
        if (substr($repo, -4) == '.git') {
            $repo = substr($repo, 0, -4);
        }
        if ($type == '') {
            $file_headers = @get_headers(str_replace('github.com', 'raw.github.com', $repo . '/master/plugin.json'));
            if ($file_headers[0] != 'HTTP/1.1 404 Not Found') {
                $type = 'plugins';
            } else {
                $file_headers = @get_headers(str_replace('github.com', 'raw.github.com', $repo . '/master/theme.json'));
                if ($file_headers[0] != 'HTTP/1.1 404 Not Found') {
                    $type = 'themes';
                } else {
                    die(formatJSEND("error", "Invalid Repository"));
                }
            }
        } else {
            $reponame = explode('/', $repo);
            $tmp = file_get_contents($this->url . '/?t=' . rtrim($type, "s") . '&i=' . str_replace("-master", "", $reponame[sizeof($repo) - 1]));
        }
        if (file_put_contents(BASE_PATH . '/' . $type . '/' . $name . '.zip', fopen($repo . '/archive/master.zip', 'r'))) {
            $zip = new ZipArchive();
            $res = $zip->open(BASE_PATH . '/' . $type . '/' . $name . '.zip');
            // open downloaded archive
            if ($res === true) {
                // extract archive
                if ($zip->extractTo(BASE_PATH . '/' . $type) === true) {
                    $zip->close();
                } else {
                    die(formatJSEND("error", "Unable to open " . $name . ".zip"));
                }
            } else {
                die(formatJSEND("error", "ZIP Extension not found"));
            }
            unlink(BASE_PATH . '/' . $type . '/' . $name . '.zip');
            // Response
            echo formatJSEND("success", null);
        } else {
            die(formatJSEND("error", "Unable to download " . $repo));
        }
    }

Usage Example

Exemplo n.º 1
0
 *  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.market.php';
//////////////////////////////////////////////////////////////////
// Verify Session or Key
//////////////////////////////////////////////////////////////////
checkSession();
$market = new Market();
//////////////////////////////////////////////////////////////////
// Install
//////////////////////////////////////////////////////////////////
if ($_GET['action'] == 'install') {
    if (checkAccess()) {
        $market->Install($_GET['type'], $_GET['name'], $_GET['repo']);
    }
}
//////////////////////////////////////////////////////////////////
// Remove
//////////////////////////////////////////////////////////////////
if ($_GET['action'] == 'remove') {
    if (checkAccess()) {
        $market->Remove($_GET['type'], $_GET['name']);
    }
}
//////////////////////////////////////////////////////////////////
// Update
//////////////////////////////////////////////////////////////////
if ($_GET['action'] == 'update') {
    if (checkAccess()) {