This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Gitium_Submenu_Configure extends Gitium_Menu { public function __construct() { parent::__construct( $this->gitium_menu_slug, $this->gitium_menu_slug ); if ( current_user_can( GITIUM_MANAGE_OPTIONS_CAPABILITY ) ) { add_action( GITIUM_ADMIN_MENU_ACTION, array( $this, 'admin_menu' ) ); add_action( 'admin_init', array( $this, 'regenerate_keypair' ) ); add_action( 'admin_init', array( $this, 'gitium_warning' ) ); add_action( 'admin_init', array( $this, 'init_repo' ) ); add_action( 'admin_init', array( $this, 'choose_branch' ) ); add_action( 'admin_init', array( $this, 'disconnect_repository' ) ); } } public function admin_menu() { add_menu_page( __( 'Git Configuration', 'gitium' ), 'Gitium', GITIUM_MANAGE_OPTIONS_CAPABILITY, $this->menu_slug, array( $this, 'page' ), plugins_url( 'img/gitium.png', dirname( __FILE__ ) ) ); $submenu_hook = add_submenu_page( $this->menu_slug, __( 'Git Configuration', 'gitium' ), __( 'Configuration', 'gitium' ), GITIUM_MANAGE_OPTIONS_CAPABILITY, $this->menu_slug, array( $this, 'page' ) ); new Gitium_Help( $submenu_hook, 'configuration' ); } public function regenerate_keypair() { $submit_keypair = filter_input(INPUT_POST, 'GitiumSubmitRegenerateKeypair', FILTER_SANITIZE_STRING); if ( ! isset( $submit_keypair ) ) { return; } check_admin_referer( 'gitium-admin' ); gitium_get_keypair( true ); $this->success_redirect( __( 'Keypair successfully regenerated.', 'gitium' ) ); } public function gitium_warning() { $submit_warning = filter_input(INPUT_POST, 'GitiumSubmitWarning', FILTER_SANITIZE_STRING); if ( ! isset( $submit_warning ) ) { return; } check_admin_referer( 'gitium-admin' ); $this->git->remove_wp_content_from_version_control(); } public function init_process( $remote_url ) { $git = $this->git; $git->init(); $git->add_remote_url( $remote_url ); $git->fetch_ref(); if ( count( $git->get_remote_branches() ) == 0 ) { $git->add( 'wp-content', '.gitignore' ); $current_user = wp_get_current_user(); $git->commit( __( 'Initial commit', 'gitium' ), $current_user->display_name, $current_user->user_email ); if ( ! $git->push( 'master' ) ) { $git->cleanup(); return false; } } return true; } public function init_repo() { $remote_url = filter_input(INPUT_POST, 'remote_url', FILTER_SANITIZE_STRING); $gitium_submit_fetch = filter_input(INPUT_POST, 'GitiumSubmitFetch', FILTER_SANITIZE_STRING); if ( ! isset( $gitium_submit_fetch ) || ! isset( $remote_url ) ) { return; } check_admin_referer( 'gitium-admin' ); if ( empty( $remote_url ) ) { $this->redirect( __( 'Please specify a valid repo.', 'gitium' ) ); } if ( $this->init_process( $remote_url ) ) { $this->success_redirect( __( 'Repository initialized successfully.', 'gitium' ) ); } else { global $git; $this->redirect( __( 'Could not push to remote: ', 'gitium' ) . $remote_url . ' ERROR: ' . serialize( $git->get_last_error() ) ); } } public function choose_branch() { $gitium_submit_merge_push = filter_input(INPUT_POST, 'GitiumSubmitMergeAndPush', FILTER_SANITIZE_STRING); $tracking_branch = filter_input(INPUT_POST, 'tracking_branch', FILTER_SANITIZE_STRING); if ( ! isset( $gitium_submit_merge_push ) || ! isset( $tracking_branch ) ) { return; } check_admin_referer( 'gitium-admin' ); $this->git->add(); $branch = $tracking_branch; set_transient( 'gitium_remote_tracking_branch', $branch ); $current_user = wp_get_current_user(); $commit = $this->git->commit( __( 'Merged existing code from ', 'gitium' ) . get_home_url(), $current_user->display_name, $current_user->user_email ); if ( ! $commit ) { $this->git->cleanup(); $this->redirect( __( 'Could not create initial commit -> ', 'gitium' ) . $this->git->get_last_error() ); } if ( ! $this->git->merge_initial_commit( $commit, $branch ) ) { $this->git->cleanup(); $this->redirect( __( 'Could not merge the initial commit -> ', 'gitium' ) . $this->git->get_last_error() ); } $this->git->push( $branch ); $this->success_redirect( __( 'Branch selected successfully.', 'gitium' ) ); } private function setup_step_1_remote_url() { ?>
https://user:pass@github.com/user/example.git', 'gitium' ); ?>
github or bitbucket.', 'gitium' ); ?>