/** * Returns whether the specified URL is a valid Github URL. * Used for validating the input of the app/theme installer. * Also returns true if it's a link to a zip file. */ function github_is_valid_url($url) { if (github_parse_url($url) === false) { if (github_is_zip($url)) { return true; } return false; } return true; }
<?php /** * Install an app or theme from a zip or Github repo. */ $page->layout = 'admin'; $this->require_acl('admin', 'designer', 'designer/installer'); $page->title = __('Install App/Theme'); require_once 'apps/designer/lib/Functions.php'; $form = new Form('post', $this); $page->installer_error = false; echo $form->handle(function ($form) use($page, $tpl) { if (!empty($_POST['github'])) { if (github_is_zip($_POST['github'])) { ZipInstaller::clean(); // Retrieve zip file $info = ZipInstaller::fetch($_POST['github']); if (!$info) { ZipInstaller::clean(); $form->failed = array('zip-install'); $page->installer_error = ZipInstaller::$error; return false; } // Import from Zip $res = ZipInstaller::install($info); if (!$res) { ZipInstaller::clean(); $form->failed = array('zip-install'); $page->installer_error = ZipInstaller::$error; return false; }
if (strpos($url, '://') === false && file_exists($url)) { // Install from local zip file ZipInstaller::clean(); // Import from Zip $res = ZipInstaller::install($url); if (!$res) { ZipInstaller::clean(); Cli::out('Error: ' . ZipInstaller::$error, 'error'); return; } ZipInstaller::clean(); Cli::out('Install completed.', 'success'); return; } require_once 'apps/designer/lib/Functions.php'; if (github_is_zip($url)) { ZipInstaller::clean(); // Retrieve zip file $info = ZipInstaller::fetch($url); if (!$info) { ZipInstaller::clean(); Cli::out('Error: ' . ZipInstaller::$error, 'error'); return; } $res = ZipInstaller::install($info); if (!$res) { ZipInstaller::clean(); Cli::out('Error: ' . ZipInstaller::$error, 'error'); return; } ZipInstaller::clean();