/**
  * Initialize the class.
  * @access public
  */
 public function __construct()
 {
     if (is_admin()) {
         add_action('admin_init', array($this, 'init_settings'));
     }
     $this->options = Revisr_Admin::options();
 }
Example #2
0
 /**
  * Loads hooks for rendering the WordPress admin.
  * @access public
  */
 public function admin_hooks()
 {
     $admin = new Revisr_Admin();
     if (is_super_admin()) {
         $plugin = $this->plugin;
         $this->options = Revisr_Admin::options();
         add_action('init', array($admin, 'revisr_post_types'));
         add_action('admin_notices', array($admin, 'site5_notice'));
         add_action('load-edit.php', array($admin, 'default_views'));
         add_action('load-post.php', array($admin, 'meta'));
         add_action('load-post-new.php', array($admin, 'meta'));
         add_action('pre_get_posts', array($admin, 'filters'));
         add_action('views_edit-revisr_commits', array($admin, 'custom_views'));
         add_action('post_row_actions', array($admin, 'custom_actions'));
         add_action('admin_menu', array($admin, 'menus'), 2);
         add_action('admin_post_delete_branch_form', array($admin, 'delete_branch_form'));
         add_action('manage_edit-revisr_commits_columns', array($admin, 'columns'));
         add_action('manage_revisr_commits_posts_custom_column', array($admin, 'custom_columns'));
         add_action('admin_enqueue_scripts', array($admin, 'revisr_scripts'));
         add_action('admin_bar_menu', array($admin, 'admin_bar'), 999);
         add_action('admin_enqueue_scripts', array($admin, 'disable_autodraft'));
         add_filter('post_updated_messages', array($admin, 'revisr_commits_custom_messages'));
         add_filter('bulk_post_updated_messages', array($admin, 'revisr_commits_bulk_messages'), 10, 2);
         add_filter('custom_menu_order', array($admin, 'revisr_commits_submenu_order'));
         add_filter("plugin_action_links_{$plugin}", array($admin, 'settings_link'));
         add_action('wp_ajax_recent_activity', array($admin, 'recent_activity'));
         $revisr_settings = new Revisr_Settings();
     }
 }
 /**
  * The main "automatic backup" event.
  * @access public
  */
 public function run_automatic_backup()
 {
     $this->revisr->git = new Revisr_Git();
     $this->revisr->db = new Revisr_DB();
     $date = date("F j, Y");
     $files = $this->revisr->git->status();
     $backup_type = ucfirst($this->revisr->options['automatic_backups']);
     $commit_msg = sprintf(__('%s backup - %s', 'revisr'), $backup_type, $date);
     // In case there are no files to commit.
     if ($files == false) {
         $files = array();
     }
     $this->revisr->git->stage_files($files);
     $this->revisr->git->commit($commit_msg);
     $post = array('post_title' => $commit_msg, 'post_content' => '', 'post_type' => 'revisr_commits', 'post_status' => 'publish');
     $post_id = wp_insert_post($post);
     add_post_meta($post_id, 'branch', $this->revisr->git->branch);
     add_post_meta($post_id, 'commit_hash', $this->revisr->git->current_commit());
     add_post_meta($post_id, 'files_changed', count($files));
     add_post_meta($post_id, 'committed_files', $files);
     $this->revisr->db->backup();
     add_post_meta($post_id, 'db_hash', $this->revisr->git->current_commit());
     $log_msg = sprintf(__('The %s backup was successful.', 'revisr'), $this->revisr->options['automatic_backups']);
     Revisr_Admin::log($log_msg, 'backup');
 }
Example #4
0
 /**
  * Tests the Revisr_Admin::clear_transients() method.
  */
 function test_clear_transients()
 {
     //First set a transient and make sure it exists.
     Revisr_Admin::alert('test_error', true);
     $transient = get_transient('revisr_error');
     $this->assertEquals('test_error', $transient);
     // Clear the transients and make sure they're really gone.
     Revisr_Admin::clear_transients();
     $new_transient = get_transient('revisr_error');
     $this->assertEquals(false, $new_transient);
 }
Example #5
0
 /**
  * Tests the Revisr_Admin::get_commit_details() method.
  */
 function test_get_commit_details()
 {
     $commit = Revisr_Admin::get_commit_details(42);
     $this->assertArrayHasKey('branch', $commit);
     $this->assertArrayHasKey('commit_hash', $commit);
     $this->assertArrayHasKey('db_hash', $commit);
     $this->assertArrayHasKey('db_backup_method', $commit);
     $this->assertArrayHasKey('files_changed', $commit);
     $this->assertArrayHasKey('committed_files', $commit);
     $this->assertArrayHasKey('tag', $commit);
 }
 /**
  * Tries to guess the install path to the provided program.
  * @access public
  * @param  string $program The program to check for.
  * @return string
  */
 public static function guess_path($program)
 {
     $os = Revisr_Compatibility::get_os();
     $program = Revisr_Admin::escapeshellarg($program);
     if ($os['code'] !== 'WIN') {
         $path = exec("which {$program}");
     } else {
         $path = exec("where {$program}");
     }
     if ($path) {
         return $path;
     } else {
         return __('Not Found', 'revisr');
     }
 }
Example #7
0
 /**
  * Sends a new HTTP request to the live site.
  * @access public
  */
 public function send_request()
 {
     $body = array('action' => 'revisr_update');
     $args = array('method' => 'POST', 'timeout' => '30', 'redirection' => '5', 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => $body);
     // Get the URL and send the request.
     $get_url = revisr()->git->get_config('revisr', 'webhook-url');
     if ($get_url !== false) {
         $webhook = urldecode($get_url);
         $request = wp_remote_post($webhook, $args);
         if (is_wp_error($request)) {
             Revisr_Admin::log(__('Error contacting webhook URL.', 'revisr'), 'error');
         } else {
             Revisr_Admin::log(__('Sent update request to the webhook.', 'revisr'), 'push');
         }
     }
 }
Example #8
0
 /**
  * The main "automatic backup" event.
  * @access public
  */
 public function run_automatic_backup()
 {
     revisr()->git = new Revisr_Git();
     revisr()->db = new Revisr_DB();
     $backup_type = revisr()->git->get_config('revisr', 'automatic-backups') ? revisr()->git->get_config('revisr', 'automatic-backups') : 'none';
     // Make sure backups have been enabled for this environment.
     if ('none' !== $backup_type) {
         // Defaults.
         $date = date("F j, Y");
         $files = revisr()->git->status() ? revisr()->git->status() : array();
         $commit_msg = sprintf(__('%s backup - %s', 'revisr'), ucfirst($backup_type), $date);
         // Stage the files and commit.
         revisr()->git->stage_files($files);
         revisr()->git->commit($commit_msg);
         // Backup the DB.
         revisr()->db->backup();
         // Log result - TODO: improve error handling as necessary.
         $log_msg = sprintf(__('The %s backup was successful.', 'revisr'), $backup_type);
         Revisr_Admin::log($log_msg, 'backup');
     }
 }
Example #9
0
    /**
     * Makes sure that Revisr is compatible in the current environment.
     * @access public
     */
    public function check_compatibility()
    {
        if (!function_exists('exec')) {
            Revisr_Admin::alert(__('It appears that you don\'t have the PHP exec() function enabled on your server. This can be enabled in your php.ini.
				Check with your web host if you\'re not sure what this means.', 'revisr'), true);
            return false;
        }
        $git = new Revisr_Git();
        if (is_dir($git->dir . '/.git/') && !is_writeable($git->dir . '/.git/')) {
            Revisr_Admin::alert(__('Revisr requires write permissions to the repository. The recommended settings are 755 for directories, and 644 for files.', 'revisr'), true);
            return false;
        }
        return true;
    }
 /**
  * Processes the request to revert to an earlier commit.
  * @access public
  */
 public function process_revert()
 {
     if (isset($_GET['revert_nonce']) && wp_verify_nonce($_GET['revert_nonce'], 'revert')) {
         $branch = $_GET['branch'];
         $commit = $_GET['commit_hash'];
         $commit_msg = sprintf(__('Reverted to commit: #%s.', 'revisr'), $commit);
         if ($branch != $this->git->branch) {
             $this->git->checkout($branch);
         }
         $this->git->reset('--hard', 'HEAD', true);
         $this->git->reset('--hard', $commit);
         $this->git->reset('--soft', 'HEAD@{1}');
         $this->git->run('add -A');
         $this->git->commit($commit_msg);
         $this->git->auto_push();
         $post_url = get_admin_url() . "post.php?post=" . $_GET['post_id'] . "&action=edit";
         $msg = sprintf(__('Reverted to commit <a href="%s">#%s</a>.', 'revisr'), $post_url, $commit);
         $email_msg = sprintf(__('%s was reverted to commit #%s', 'revisr'), get_bloginfo(), $commit);
         Revisr_Admin::log($msg, 'revert');
         Revisr_Admin::notify(get_bloginfo() . __(' - Commit Reverted', 'revisr'), $email_msg);
         $redirect = get_admin_url() . "admin.php?page=revisr";
         wp_redirect($redirect);
     } else {
         wp_die(__('You are not authorized to access this page.', 'revisr'));
     }
 }
 /**
  * Stages the array of files passed through the New Commit screen.
  * @access public
  * @param  array $staged_files The files to add/remove
  */
 public function stage_files($staged_files)
 {
     $errors = array();
     foreach ($staged_files as $result) {
         $file = substr($result, 3);
         $status = Revisr_Git::get_status(substr($result, 0, 2));
         if ($status == __('Deleted', 'revisr')) {
             if ($this->run("rm {$file}") === false) {
                 $errors[] = $file;
             }
         } else {
             if ($this->run("add {$file}") === false) {
                 $errors[] = $file;
             }
         }
     }
     if (!empty($errors)) {
         $msg = __('There was an error staging the files. Please check the settings and try again.', 'revisr');
         Revisr_Admin::alert($msg, true);
         Revisr_Admin::log(__('Error staging files.', 'revisr'), 'error');
     }
 }
Example #12
0
/**
 * revert-form.php
 *
 * Displays the form to revert to a specific commit.
 *
 * @package 	Revisr
 * @license 	GPLv3
 * @link 		https://revisr.io
 * @copyright 	Expanded Fronts, LLC
 */
// Disallow direct access.
if (!defined('ABSPATH')) {
    exit;
}
$commit = Revisr_Admin::get_commit_details($_GET['commit_id']);
$styles_url = REVISR_URL . 'assets/css/thickbox.css?02162015';
?>

	<link href="<?php 
echo $styles_url;
?>
" rel="stylesheet" type="text/css">

	<form action="<?php 
echo get_admin_url() . 'admin-post.php';
?>
" method="post">

		<div class="revisr-tb-description">
Example #13
0
 /**
  * Stages the array of files passed through the New Commit screen.
  * @access public
  * @param  array 	$staged_files 	An array of files to add/remove.
  * @param  boolean 	$stage_all 		If set to true, skip the loop and add -A.
  * @return boolean
  */
 public function stage_files($staged_files, $stage_all = false)
 {
     // An empty array for errors.
     $errors = array();
     if (true === $stage_all) {
         if ($this->run('add', array('-A')) === false) {
             $errors[] = $staged_files;
         }
     } else {
         foreach ($staged_files as $result) {
             $file = substr($result, 3);
             $status = self::get_status(substr($result, 0, 2));
             if ($status == __('Deleted', 'revisr')) {
                 if ($this->run('rm', array($file)) === false) {
                     $errors[] = $file;
                 }
             } else {
                 if ($this->run('add', array($file)) === false) {
                     $errors[] = $file;
                 }
             }
         }
     }
     if (!empty($errors)) {
         $msg = __('There was an error staging the files. Please check the settings and try again.', 'revisr');
         Revisr_Admin::alert($msg, true);
         Revisr_Admin::log(__('Error staging files.', 'revisr'), 'error');
         return false;
     }
     return true;
 }
Example #14
0
						<th><?php 
_e('Branch', 'revisr');
?>
</th>
						<th class="center-td"><?php 
_e('Commits', 'revisr');
?>
</th>
						<th class="center-td"><?php 
_e('Actions', 'revisr');
?>
</th>
					</tr>
				</thead>
					<?php 
$admin = new Revisr_Admin();
$output = Revisr_Git::run('branch');
if (is_array($output)) {
    foreach ($output as $key => $value) {
        $branch = substr($value, 2);
        $num_commits = $admin->count_commits($branch);
        if (substr($value, 0, 1) === "*") {
            echo "<tr>\n\t\t\t\t\t\t\t\t\t<td><strong>{$branch} (current branch)</strong></td>\n\t\t\t\t\t\t\t\t\t<td class='center-td'>{$num_commits}</td>\n\t\t\t\t\t\t\t\t\t<td class='center-td'>\n\t\t\t\t\t\t\t\t\t\t<a class='button disabled branch-btn' onclick='preventDefault()' href='#'>Checkout</a>\n\t\t\t\t\t\t\t\t\t\t<a class='button disabled branch-btn' onclick='preventDefault()' href='#'>Delete</a>\n\t\t\t\t\t\t\t\t\t</td></tr>";
        } else {
            $checkout_url = get_admin_url() . "admin-post.php?action=checkout&branch={$branch}";
            $delete_url = get_admin_url() . "admin-post.php?action=delete_branch_form&branch={$branch}&TB_iframe=true&width=350&height=150";
            ?>
									<tr>
									<td><?php 
            echo $branch;
            ?>
    /**
     * Displays/updates the "Git Path" settings field.
     * @access public
     */
    public function git_path_callback()
    {
        $git_path = defined('REVISR_GIT_PATH') ? REVISR_GIT_PATH : '';
        if (isset($_GET['settings-updated'])) {
            $dir = revisr()->options['git_path'];
            $line = "define('REVISR_GIT_PATH', '{$dir}');";
            Revisr_Admin::replace_config_line('define *\\( *\'REVISR_GIT_PATH\'', $line);
            $git_path = revisr()->options['git_path'];
        }
        printf('<input type="text" id="git_path" name="revisr_general_settings[git_path]" class="regular-text revisr-text" value="%s" />
			<p class="description revisr-description">%s</p>', esc_attr($git_path), __('If necessary, you can define the installation path to Git here.', 'revisr'));
    }
 /**
  * Returns if a push failed.
  * @access public
  */
 public function null_push($output = '', $args = '')
 {
     $msg = __('Error pushing to the remote repository. The remote repository could be ahead, or there may be an authentication issue.', 'revisr');
     Revisr_Admin::alert($msg, true);
     Revisr_Admin::log(__('Error pushing changes to the remote repository.', 'revisr'), 'error');
     return;
 }
Example #17
0
 /**
  * Downloads the system info.
  * @access public
  */
 public function download_sysinfo()
 {
     Revisr_Admin::verify_nonce($_REQUEST['revisr_info_nonce'], 'process_download_sysinfo');
     if (!current_user_can(Revisr::get_capability())) {
         return;
     }
     nocache_headers();
     header('Content-Type: text/plain');
     header('Content-Disposition: attachment; filename="revisr-system-info.txt"');
     echo wp_strip_all_tags($_POST['revisr-sysinfo']);
     die;
 }
    /**
     * Displays the "Commit Details" meta box on a previous commit.
     * @access public
     */
    public function view_commit_meta()
    {
        $post_id = get_the_ID();
        $commit = Revisr_Admin::get_commit_details($post_id);
        $revert_url = get_admin_url() . "admin-post.php?action=revert_form&commit_id=" . $post_id . "&TB_iframe=true&width=350&height=200";
        $time_format = __('M j, Y @ G:i');
        $timestamp = sprintf(__('Committed on: <strong>%s</strong>', 'revisr'), date_i18n($time_format, get_the_time('U')));
        if (false !== $commit['error_details']) {
            $details = ' <a class="thickbox" title="' . __('Error Details', 'revisr') . '" href="' . wp_nonce_url(admin_url('admin-post.php?action=revisr_view_error&post_id=' . $post_id . '&TB_iframe=true&width=350&height=300'), 'revisr_view_error', 'revisr_error_nonce') . '">View Details</a>';
            $revert_btn = '<a class="button button-primary disabled" href="#">' . __('Revert to this Commit', 'revisr') . '</a>';
        } else {
            $revert_btn = '<a class="button button-primary thickbox" href="' . $revert_url . '" title="' . __('Revert', 'revisr') . '">' . __('Revert to this Commit', 'revisr') . '</a>';
            $details = '';
        }
        ?>
		<div id="minor-publishing">
			<div id="misc-publishing-actions">

				<div class="misc-pub-section revisr-pub-status">
					<label for="post_status"><?php 
        _e('Status:', 'revisr');
        ?>
</label>
					<span><strong><?php 
        echo $commit['status'] . $details;
        ?>
</strong></span>
				</div>

				<div class="misc-pub-section revisr-pub-branch">
					<label for="revisr-branch"><?php 
        _e('Branch:', 'revisr');
        ?>
</label>
					<span><strong><?php 
        echo $commit['branch'];
        ?>
</strong></span>
				</div>

				<div class="misc-pub-section curtime misc-pub-curtime">
					<span id="timestamp" class="revisr-timestamp"><?php 
        echo $timestamp;
        ?>
</span>
				</div>

				<?php 
        if ($commit['tag'] !== '') {
            ?>
				<div class="misc-pub-section revisr-git-tag">
					<label for="revisr-tag"><?php 
            _e('Tagged:', 'revisr');
            ?>
</label>
					<span><strong><?php 
            echo $commit['tag'];
            ?>
</strong></span>
				</div>
				<?php 
        }
        ?>

			</div><!-- /#misc-publishing-actions -->
		</div>

		<div id="major-publishing-actions">
			<div id="delete-action"></div>
			<div id="publishing-action">
				<span class="spinner"></span>
				<?php 
        echo $revert_btn;
        ?>
			</div>
			<div class="clear"></div>
		</div>
		<?php 
    }
 /**
  * Unsets unused views, replaced with branches.
  * @access public
  * @param  array $views The global views for the post type.
  */
 public function custom_views($views)
 {
     $output = $this->git->run('branch');
     global $wp_query;
     if (is_array($output)) {
         foreach ($output as $key => $value) {
             $branch = substr($value, 2);
             $class = $wp_query->query_vars['meta_value'] == $branch ? ' class="current"' : '';
             $views["{$branch}"] = sprintf(__('<a href="%s"' . $class . '>' . ucwords($branch) . ' <span class="count">(%d)</span></a>'), admin_url('edit.php?post_type=revisr_commits&branch=' . $branch), Revisr_Admin::count_commits($branch));
         }
         $class = '';
         if ($_GET['branch'] == 'all') {
             $class = ' class="current"';
         }
         $views['all'] = sprintf(__('<a href="%s"%s>All Branches <span class="count">(%d)</span></a>', 'revisr'), admin_url('edit.php?post_type=revisr_commits&branch=all'), $class, Revisr_Admin::count_commits('all'));
         unset($views['publish']);
         unset($views['draft']);
         unset($views['trash']);
         if (isset($views)) {
             return $views;
         }
     }
 }
Example #20
0
 /**
  * Runs an import of all tracked tables, importing any new tables
  * if tracking all_tables, or providing a link to import new tables
  * if necessary.
  * @access public
  * @param  array $tables The tables to import.
  * @return boolean
  */
 public function import($tables = array())
 {
     // The tables currently being tracked.
     $tracked_tables = $this->get_tracked_tables();
     // Tables that have import files but aren't in the database.
     $new_tables = $this->get_tables_not_in_db();
     // All tables.
     $all_tables = array_unique(array_merge($new_tables, $tracked_tables));
     // The URL to replace during import.
     $replace_url = $this->revisr->git->get_config('revisr', 'dev-url') ? $this->revisr->git->get_config('revisr', 'dev-url') : '';
     if (empty($tables)) {
         if (!empty($new_tables)) {
             // If there are new tables that were imported.
             if (isset($this->revisr->options['db_tracking']) && $this->revisr->options['db_tracking'] == 'all_tables') {
                 // If the user is tracking all tables, import all tables.
                 $import = $this->run('import', $all_tables, $replace_url);
             } else {
                 // Import only tracked tables, but provide a warning and import link.
                 $import = $this->run('import', $tracked_tables, $replace_url);
                 $url = wp_nonce_url(get_admin_url() . 'admin-post.php?action=import_tables_form&TB_iframe=true&width=350&height=200', 'import_table_form', 'import_nonce');
                 $msg = sprintf(__('New database tables detected. <a class="thickbox" title="Import Tables" href="%s">Click here</a> to view and import.', 'revisr'), $url);
                 Revisr_Admin::log($msg, 'db');
             }
         } else {
             // If there are no new tables, go ahead and import the tracked tables.
             $import = $this->run('import', $tracked_tables, $replace_url);
         }
     } else {
         // Import the provided tables.
         $import = $this->run('import', $tables, $replace_url);
     }
     return $import;
 }
Example #21
0
 /**
  * Adapated from interconnect/it's search/replace script.
  *
  * @link https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
  *
  * Take a serialised array and unserialise it replacing elements as needed and
  * unserialising any subordinate arrays and performing the replace on those too.
  *
  * @access private
  * @param  string $from       String we're looking to replace.
  * @param  string $to         What we want it to be replaced with.
  * @param  array  $data       Used to pass any subordinate arrays back to in.
  * @param  bool   $serialised Does the array passed via $data need serialising.
  *
  * @return string|array	The original array with all elements replaced as needed.
  */
 private function recursive_unserialize_replace($from = '', $to = '', $data = '', $serialised = false)
 {
     try {
         if (is_string($data) && ($unserialized = @unserialize($data)) !== false) {
             $data = $this->recursive_unserialize_replace($from, $to, $unserialized, true);
         } elseif (is_array($data)) {
             $_tmp = array();
             foreach ($data as $key => $value) {
                 $_tmp[$key] = $this->recursive_unserialize_replace($from, $to, $value, false);
             }
             $data = $_tmp;
             unset($_tmp);
         } elseif (is_object($data)) {
             // $data_class = get_class( $data );
             $_tmp = $data;
             // new $data_class( );
             $props = get_object_vars($data);
             foreach ($props as $key => $value) {
                 $_tmp->{$key} = $this->recursive_unserialize_replace($from, $to, $value, false);
             }
             $data = $_tmp;
             unset($_tmp);
         } else {
             if (is_string($data)) {
                 $data = str_replace($from, $to, $data);
             }
         }
         if ($serialised) {
             return serialize($data);
         }
     } catch (Exception $error) {
         Revisr_Admin::log($error, 'error');
     }
     return $data;
 }
Example #22
0
<?php

/**
 * Displays the settings page.
 *
 * @package   Revisr
 * @license   GPLv3
 * @link      https://revisr.io
 * @copyright 2014 Expanded Fronts, LLC
 */
if (isset($_GET['settings-updated']) && $_GET['settings-updated'] == "true") {
    $git = new Revisr_Git();
    $options = Revisr_Admin::options();
    if (isset($options['gitignore'])) {
        chdir(ABSPATH);
        file_put_contents(".gitignore", $options['gitignore']);
    }
    if (isset($options['username']) && $options['username'] != "") {
        Revisr_Git::run('config user.name "' . $options['username'] . '"');
    }
    if (isset($options['email']) && $options['email'] != "") {
        Revisr_Git::run('config user.email "' . $options['email'] . '"');
    }
    if (isset($options['remote_url']) && $options['remote_url'] != "") {
        Revisr_Git::run('config remote.origin.url ' . $options['remote_url']);
    }
    Revisr_Git::run("add .gitignore");
    $commit_msg = __('Updated .gitignore.', 'revisr');
    Revisr_Git::run("commit -m \"{$commit_msg}\"");
    $git->auto_push();
    chdir($git->dir);
 /**
  * Processes the results and alerts the user as necessary.
  * @access public
  * @param  array $args An array containing the results of the backup.
  * @return boolean
  */
 public function callback($args)
 {
     if (in_array(false, $args)) {
         $msg = __('Error backing up the database.', 'revisr');
         Revisr_Admin::alert($msg, true);
         Revisr_Admin::log($msg, 'error');
     } else {
         $msg = __('Successfully backed up the database.', 'revisr');
         Revisr_Admin::alert($msg);
         Revisr_Admin::log($msg, 'backup');
         return true;
     }
     return false;
 }
 /**
  * Processes the request to revert to an earlier commit.
  * @access public
  */
 public function process_revert_files($redirect = true)
 {
     if (!wp_verify_nonce($_REQUEST['revisr_revert_nonce'], 'revisr_revert_nonce')) {
         wp_die(__('Cheatin&#8217; uh?', 'revisr'));
     }
     $branch = $_REQUEST['branch'];
     $commit = $_REQUEST['commit_hash'];
     $commit_msg = sprintf(__('Reverted to commit: #%s.', 'revisr'), $commit);
     if ($branch != $this->revisr->git->branch) {
         $this->revisr->git->checkout($branch);
     }
     $this->revisr->git->reset('--hard', 'HEAD', true);
     $this->revisr->git->reset('--hard', $commit);
     $this->revisr->git->reset('--soft', 'HEAD@{1}');
     $this->revisr->git->run('add', array('-A'));
     $this->revisr->git->commit($commit_msg);
     $this->revisr->git->auto_push();
     $post_url = get_admin_url() . "post.php?post=" . $_REQUEST['post_id'] . "&action=edit";
     $msg = sprintf(__('Reverted to commit <a href="%s">#%s</a>.', 'revisr'), $post_url, $commit);
     $email_msg = sprintf(__('%s was reverted to commit #%s', 'revisr'), get_bloginfo(), $commit);
     Revisr_Admin::log($msg, 'revert');
     Revisr_Admin::notify(get_bloginfo() . __(' - Commit Reverted', 'revisr'), $email_msg);
     if (true === $redirect) {
         $redirect = get_admin_url() . "admin.php?page=revisr";
         wp_safe_redirect($redirect);
     }
 }
Example #25
0
 /**
  * Restores the database to an earlier version if it exists.
  * @access public
  * @param boolean $restore_branch True if restoring the database from another branch.
  */
 public function restore($restore_branch = false)
 {
     if (isset($_GET['revert_db_nonce']) && wp_verify_nonce($_GET['revert_db_nonce'], 'revert_db')) {
         $branch = $_GET['branch'];
         if ($branch != $this->branch) {
             $this->git->checkout($branch);
         }
         if ($this->verify_backup() === false) {
             wp_die(__('The backup file does not exist or has been corrupted.', 'revisr'));
         }
         clearstatcache();
         $this->backup();
         $commit = escapeshellarg($_GET['db_hash']);
         $current_temp = Revisr_Git::run("log --pretty=format:'%h' -n 1");
         $checkout = Revisr_Git::run("checkout {$commit} {$this->upload_dir['basedir']}/{$this->sql_file}", true);
         if ($checkout !== 1) {
             exec("{$this->path}mysql {$this->conn} < {$this->sql_file}");
             Revisr_Git::run("checkout {$this->branch} {$this->upload_dir['basedir']}/{$this->sql_file}");
             if (is_array($current_temp)) {
                 $current_commit = str_replace("'", "", $current_temp);
                 $undo_nonce = wp_nonce_url(admin_url("admin-post.php?action=revert_db&db_hash={$current_commit[0]}&branch={$_GET['branch']}"), 'revert_db', 'revert_db_nonce');
                 $msg = sprintf(__('Reverted the database to a previous commit. <a href="%s">Undo</a>', 'revisr'), $undo_nonce);
                 Revisr_Admin::log($msg, 'revert');
                 $redirect = get_admin_url() . "admin.php?page=revisr&revert_db=success&prev_commit={$current_commit[0]}";
                 wp_redirect($redirect);
             } else {
                 wp_die(__('Something went wrong. Check your settings and try again.', 'revisr'));
             }
         } else {
             wp_die(__('Failed to revert the database to an earlier commit.', 'revisr'));
         }
     } else {
         if ($restore_branch === true) {
             exec("{$this->path}mysql {$this->conn} < {$this->sql_file}");
         } else {
             wp_die(__('You are not authorized to perform this action.', 'revisr'));
         }
     }
 }
Example #26
0
// Prevent direct access.
if (!defined('ABSPATH')) {
    exit;
}
?>

<div class="wrap">

    <h1><?php 
_e('New Commit', 'revisr');
?>
</h1>

    <?php 
if (isset($_GET['error'])) {
    Revisr_Admin::render_alert(true);
}
?>

    <form id="revisr-commit-form" method="post" action="<?php 
echo get_admin_url();
?>
admin-post.php">

        <input type="hidden" name="action" value="process_commit">
        <?php 
wp_nonce_field('process_commit', 'revisr_commit_nonce');
// Save metabox order, state
wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
?>
Example #27
0
 /**
  * Filters the display order of the menu pages.
  * @access public
  */
 public function submenu_order($menu_ord)
 {
     global $submenu;
     $arr = array();
     if (isset($submenu['revisr']) && !Revisr_Admin::is_doing_setup()) {
         $arr[] = $submenu['revisr'][0];
         $arr[] = $submenu['revisr'][1];
         $arr[] = $submenu['revisr'][2];
         $arr[] = $submenu['revisr'][3];
         $submenu['revisr'] = $arr;
     }
     return $menu_ord;
 }
Example #28
0
 /**
  * Reverts to a specified commit.
  * @access public
  */
 public function revert()
 {
     if (isset($_GET['revert_nonce']) && wp_verify_nonce($_GET['revert_nonce'], 'revert')) {
         $branch = $_GET['branch'];
         if ($branch != $this->branch) {
             $this->checkout($branch);
         }
         $commit = $_GET['commit_hash'];
         $esc_commit = escapeshellarg($commit);
         $commit_msg = escapeshellarg("Reverted to commit: #{$commit}");
         Revisr_Git::run('reset --hard HEAD');
         Revisr_Git::run('clean -f -d');
         Revisr_Git::run("reset --hard {$esc_commit}");
         Revisr_Git::run("reset --soft HEAD@{1}");
         Revisr_Git::run("add -A");
         Revisr_Git::run("commit -am {$commit_msg}");
         $this->auto_push();
         $post_url = get_admin_url() . "post.php?post=" . $_GET['post_id'] . "&action=edit";
         $msg = sprintf(__('Reverted to commit <a href="%s">#%s</a>.', 'revisr'), $post_url, $commit);
         $email_msg = sprintf(__('%s was reverted to commit #%s', 'revisr'), get_bloginfo(), $commit);
         Revisr_Admin::log($msg, 'revert');
         Revisr_Admin::notify(get_bloginfo() . __(' - Commit Reverted', 'revisr'), $email_msg);
         $redirect = get_admin_url() . "admin.php?page=revisr&revert=success&commit={$commit}&id=" . $_GET['post_id'];
         wp_redirect($redirect);
     } else {
         wp_die(__('You are not authorized to access this page.', 'revisr'));
     }
 }
Example #29
0
 * @license   GPLv3
 * @link      https://revisr.io
 * @copyright Expanded Fronts, LLC
 */
// Prevent direct access.
if (!defined('ABSPATH')) {
    exit;
}
$loader_url = REVISR_URL . 'assets/img/loader.gif';
$discard_url = get_admin_url() . 'admin-post.php?action=revisr_discard_form&TB_iframe=true&width=400&height=225';
$push_url = get_admin_url() . 'admin-post.php?action=revisr_push_form&TB_iframe=true&width=400&height=225';
$pull_url = get_admin_url() . 'admin-post.php?action=revisr_pull_form&TB_iframe=true&width=400&height=225';
?>

<?php 
if (Revisr_Admin::is_doing_setup()) {
    ?>

<script>
	window.location.href = "<?php 
    echo get_admin_url();
    ?>
admin.php?page=revisr_setup";
</script>

<?php 
} else {
    ?>

<?php 
    // Prepare the wp_list_table.
Example #30
0
_e('Commits', 'revisr');
?>
</th>
						<th class="center-td"><?php 
_e('Actions', 'revisr');
?>
</th>
					</tr>
				</thead>
					<?php 
$output = $revisr->git->get_branches();
$admin_url = get_admin_url();
if (is_array($output)) {
    foreach ($output as $key => $value) {
        $branch = substr($value, 2);
        $num_commits = Revisr_Admin::count_commits($branch);
        if (substr($value, 0, 1) === "*") {
            ?>
									<tr>
										<td><strong><?php 
            printf(__('%s (current branch)', 'revisr'), $branch);
            ?>
</strong></td>
										<td class='center-td'><?php 
            echo $num_commits;
            ?>
</td>
										<td class="center-td">
											<a class="button disabled branch-btn" onclick="preventDefault()" href="#"><?php 
            _e('Checkout', 'revisr');
            ?>