/** * 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')); } }
/** * Displays/updates the "Reset DB" settings field. * @access public */ public function reset_db_callback() { if (isset($_GET['settings-updated'])) { if (isset($this->options['reset_db'])) { $this->git->config_revisr_option('import-checkouts', 'true'); } else { $this->git->run('config --unset-all revisr.import-checkouts'); } if (isset($this->options['import_db'])) { $this->git->config_revisr_option('import-pulls', 'true'); } else { $this->git->run('config --unset-all revisr.import-pulls'); } } $get_reset = $this->git->run('config revisr.import-checkouts'); $get_import = $this->git->run('config revisr.import-pulls'); printf('<input type="checkbox" id="reset_db" name="revisr_database_settings[reset_db]" %s /><label for="reset_db">%s</label><br><br> <input type="checkbox" id="import_db" name="revisr_database_settings[import_db]" %s /><label for="import_db">%s</label><br><br> <p class="description revisr-description">%s</p>', is_array($get_reset) ? "checked" : '', __('Import database when changing branches?', 'revisr'), is_array($get_import) ? "checked" : '', __('Import database when pulling commits?', 'revisr'), __('If checked, Revisr will automatically import the above tracked tables while pulling from or checking out a branch. The tracked tables will be backed up beforehand to provide a restore point immediately prior to the import. Use this feature with caution and only after verifying that you have a full backup of your website.', 'revisr')); }
/** * 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; } } }
/** * Processes a diff request. * @access public */ public function view_diff() { ?> <html> <head><title><?php _e('View Diff', 'revisr'); ?> </title> </head> <body> <?php if (isset($_REQUEST['commit'])) { $diff = $this->git->run("show {$_REQUEST['commit']} {$_REQUEST['file']}"); } else { $diff = $this->git->run("diff {$_REQUEST['file']}"); } if (is_array($diff)) { foreach ($diff as $line) { if (substr($line, 0, 1) === "+") { echo "<span class='diff_added' style='background-color:#cfc;'>" . htmlspecialchars($line) . "</span><br>"; } else { if (substr($line, 0, 1) === "-") { echo "<span class='diff_removed' style='background-color:#fdd;'>" . htmlspecialchars($line) . "</span><br>"; } else { echo htmlspecialchars($line) . "<br>"; } } } } else { _e('Failed to render the diff.', 'revisr'); } ?> </body> </html> <?php exit; }