/** * Requires the Github reponsitory link (e.g., git://github.com/user/project.git). */ public static function install($source) { list($user, $project) = github_parse_url($source); $github = new GithubFetcher($user, $project); $tree = $github->tree(); // Get config and verify it $found = false; $conf = false; foreach ($tree as $item) { if ($item->path === 'elefant.json') { $data = $github->get($item); if (!$data) { self::$error = i18n_get('Unable to fetch configuration file.'); return false; } $conf = json_decode($data); if (!$conf) { self::$error = i18n_get('Verification failed: Invalid configuration file.'); return false; } if (!self::verify($conf)) { // self::$error already set by verify() return false; } $found = true; break; } } if (!$found) { self::$error = i18n_get('Configuration file not found.'); return false; } // Create new install folder if ($conf->type === 'app') { $dest = 'apps/' . $conf->folder; if (!mkdir($dest)) { self::$error = i18n_get('Unable to write to apps folder.'); return false; } } else { $dest = 'layouts/' . $conf->folder; if (!mkdir($dest)) { self::$error = i18n_get('Unable to write to layouts folder.'); return false; } } // This may take some time for larger apps set_time_limit(120); // Build files from tree foreach ($tree as $n => $item) { if ($item->type === 'tree') { mkdir($dest . '/' . $item->path); } else { $data = $github->get($item); if ($data === false) { self::$error = i18n_get('Unable to fetch file') . ' ' . $item->path; rmdir_recursive($dest); return false; } file_put_contents($dest . '/' . $item->path, $data); // Create our own rate-limiting to be nice with Github $data = null; if ($n % 20 === 0) { sleep(1); } } } chmod_recursive($dest, 0777); return $conf; }
} // Import from Zip $res = ZipInstaller::install($info); 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 { // 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();
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(); Cli::out('Install completed.', 'success'); return; } else { // Import from Github $res = GithubInstaller::install($url); if (!$res) { Cli::out('Error: ' . GithubInstaller::$error, 'error'); return; } Cli::out('Install completed.', 'success'); return; } } if (@file_exists('conf/installed')) { Cli::out('** Error: Installer has already been run.', 'error'); return; } require_once 'apps/cli/lib/Functions.php'; // set the necessary folder permissions system('chmod -R 777 cache conf css files lang layouts');