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));
}
}