public function save_changes() { if (!isset($_POST['GitiumSubmitSaveChanges'])) { return; } check_admin_referer('gitium-admin'); gitium_enable_maintenance_mode() or wp_die(__('Could not enable the maintenance mode!', 'gitium')); $this->git->add(); $commitmsg = sprintf(__('Merged changes from %s on %s', 'gitium'), get_site_url(), date('m.d.Y')); if (isset($_POST['commitmsg']) && !empty($_POST['commitmsg'])) { $commitmsg = $_POST['commitmsg']; } $current_user = wp_get_current_user(); $commit = $this->git->commit($commitmsg, $current_user->display_name, $current_user->user_email); if (!$commit) { $this->redirect(__('Could not commit!', 'gitium')); } $merge_success = gitium_merge_and_push($commit); gitium_disable_maintenance_mode(); if (!$merge_success) { $this->redirect(__('Merge failed: ', 'gitium') . $this->git->get_last_error()); } $this->success_redirect(sprintf(__('Pushed commit: `%s`', 'gitium'), $commitmsg)); }
header('Content-Type: text/html'); define('SHORTINIT', true); $wordpress_loader = $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php'; require_once $wordpress_loader; require_once __DIR__ . '/gitium.php'; function exit_with_error($message) { gitium_disable_maintenance_mode(); wp_die($message); } $webhook_key = get_option('gitium_webhook_key', ''); if (!empty($webhook_key) && isset($_GET['key']) && $webhook_key == $_GET['key']) { '1.7' <= substr($git->get_version(), 0, 3) or wp_die('Gitium plugin require minimum `git version 1.7`!'); list($git_public_key, $git_private_key) = gitium_get_keypair(); $git->set_key($git_private_key); gitium_enable_maintenance_mode() or wp_die('Could not enable the maintenance mode!...'); $commitmsg = sprintf('Merged changes from %s on %s', $_SERVER['SERVER_NAME'], date('m.d.Y')); $commits = array(); if ($git->is_dirty() && $git->add() > 0) { $commits[] = $git->commit($commitmsg) or wp_die('Could not commit local changes!'); } $git->fetch_ref() or exit_with_error('Cound not fetch from remote repo.'); $git->merge_with_accept_mine($commits) or exit_with_error('Could not merge changes.'); gitium_disable_maintenance_mode(); if (!$git->push()) { wp_die('Push failed!' . ' <pre>' . $git->get_last_error() . '</pre>'); } wp_die($commitmsg, 'Pull done!', array('response' => 200)); } else { wp_die('Cheating uh?', 'Cheating uh?', array('response' => 403)); }