} else { // Import from Github $res = GithubInstaller::install($_POST['github']); if (!$res) { $form->failed = array('github-install'); $page->installer_error = GithubInstaller::$error; return false; } // App/theme successfully installed $page->title = __('Install completed'); echo $tpl->render('designer/installed', $res); } } elseif (is_uploaded_file($_FILES['zipfile']['tmp_name'])) { ZipInstaller::clean(); // Import from Zip $res = ZipInstaller::install($_FILES['zipfile']); if (!$res) { ZipInstaller::clean(); $form->failed = array('zip-install'); $page->installer_error = ZipInstaller::$error; return false; } // Zip successfully installed ZipInstaller::clean(); $page->title = __('Install completed'); echo $tpl->render('designer/installed', $res); } else { $form->failed = array('other'); return false; } });
/** * Fetch a zip file from a link. */ public static function fetch($url) { $path = parse_url($url, PHP_URL_PATH); if (strpos($path, '/zipball/') !== false) { // Fix zip file links from Github $path = current(explode('/zipball/', $path)) . '.zip'; } $base = basename($path); $tmp = 'cache/zip/' . $base; if (!is_dir('cache/zip')) { mkdir('cache/zip'); chmod('cache/zip', 0777); } if (extension_loaded('curl')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_MAXREDIRS, 3); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_FAILONERROR, 0); curl_setopt($ch, CURLOPT_URL, $url); curl_setproxy($ch, $url); $res = curl_exec($ch); curl_close($ch); } else { $res = file_get_contents($url); } if ($res === false) { self::$error = __('Failed to retrieve the file at the specified link.'); return false; } if (!file_put_contents($tmp, $res)) { self::$error = __('Unable to write to cache folder.'); return false; } chmod($tmp, 0777); return array('tmp_name' => $tmp, 'name' => $base); }