public function remote_url_callback()
    {
        $check_remote = Revisr_Git::run('config --get remote.origin.url');
        if (isset($this->options['remote_url']) && $this->options['remote_url'] != '') {
            $remote_url = esc_attr($this->options['remote_url']);
        } elseif ($check_remote != false) {
            $remote_url = $check_remote[0];
        } else {
            $remote_url = '';
        }
        printf('<input type="text" id="remote_url" name="revisr_remote_settings[remote_url]" value="%s" class="regular-text" placeholder="https://*****:*****@host.com/user/example.git" /><span id="verify-remote"></span>
			<br><span class="description">Useful if you need to authenticate over "https://" instead of SSH, or if the remote has not already been set through Git.</span>', $remote_url);
    }
예제 #2
0
    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);
}
?>

<div class="wrap">
	<div id="revisr_settings">
		<h2><?php 
_e('Revisr - Settings', 'revisr');
?>
</h2>
		<?php 
$active_tab = isset($_GET['tab']) ? $_GET['tab'] : 'general_settings';
if (isset($_GET['settings-updated']) && $_GET['settings-updated'] == "true") {
    _e('<div id="revisr_alert" class="updated"><p>Settings updated successfully.</p></div>', 'revisr');
예제 #3
0
 /**
  * Commits the database to the repository and pushes if needed.
  * @access public
  * @param boolean $insert_post Whether to insert a new commit custom_post_type.
  */
 public function commit_db($insert_post = false)
 {
     $commit_msg = escapeshellarg(__('Backed up the database with Revisr.', 'revisr'));
     $file = $this->upload_dir['basedir'] . '/' . $this->sql_file;
     $add = Revisr_Git::run("add {$file}");
     $commit = Revisr_Git::run("commit -m {$commit_msg}");
     if ($add === false || $commit === false) {
         $error = __('There was an error committing the database.', 'revisr');
         $this->maybe_return($error);
     }
     //Insert the corresponding post if necessary.
     if ($insert_post === true) {
         $post = array('post_title' => $commit_msg, 'post_content' => '', 'post_type' => 'revisr_commits', 'post_status' => 'publish');
         $post_id = wp_insert_post($post);
         $commit_hash = Revisr_Git::run('rev-parse --short HEAD');
         add_post_meta($post_id, 'commit_hash', $commit_hash[0]);
         add_post_meta($post_id, 'db_hash', $commit_hash[0]);
         add_post_meta($post_id, 'branch', $this->branch);
         add_post_meta($post_id, 'files_changed', '0');
         add_post_meta($post_id, 'committed_files', array());
     }
     //Push changes if necessary.
     $this->git->auto_push();
 }
예제 #4
0
 /**
  * Reverts a table to an earlier commit.
  * @access private
  * @param  string $table  The table to revert.
  * @param  string $commit The commit to revert to.
  * @return boolean
  */
 private function revert_table($table, $commit)
 {
     $checkout = $this->git->run("checkout {$commit} {$this->upload_dir['basedir']}/revisr-backups/revisr_{$table}.sql");
     return $checkout;
 }
예제 #5
0
_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;
            ?>
</td>
예제 #6
0
 /**
  * Checks to see if the provided URL for a remote repository is valid.
  * @access public
  */
 public function verify_remote()
 {
     //"Ping" the remote repository to verify that it exists.
     $ping = Revisr_Git::run("ls-remote " . $_REQUEST['remote'] . " HEAD");
     if ($ping === false) {
         _e('Remote not found...', 'revisr');
     } else {
         _e('Success!', 'revisr');
     }
     exit;
 }
예제 #7
0
 /**
  * Unsets unused views, replaced with branches.
  * @access public
  * @param array $views The global views for the post type.
  */
 public function custom_views($views)
 {
     $output = Revisr_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), $this->count_commits($branch));
         }
         if ($_GET['branch'] == "all") {
             $class = 'class="current"';
         } else {
             $class = '';
         }
         $views['all'] = sprintf(__('<a href="%s"' . $class . '>All Branches <span class="count">(%d)</span></a>', 'revisr'), admin_url('edit.php?post_type=revisr_commits&branch=all'), $this->count_commits("all"));
         unset($views['publish']);
         unset($views['draft']);
         unset($views['trash']);
         if (isset($views)) {
             return $views;
         }
     }
 }
예제 #8
0
    /**
     * Checks to make sure that exec is enabled and Git is installed correctly on the server.
     * @access public
     */
    public static function check_compatibility()
    {
        $error = '';
        if (!function_exists('exec')) {
            $error .= __('<p><strong>WARNING:</strong> Your server does not appear to support php exec() and/or passthru(). <br> 
			These functions are necessary for Revisr to work correctly. Contact your web host if you\'re not sure how to activate these functions.</p>', 'revisr');
            return $error;
        }
        if (Revisr_Git::run('version') === false || Revisr_Git::run('status') === false) {
            $error .= __('<p><strong>WARNING:</strong> No Git repository detected. Revisr requires that Git be installed on the server and the parent WordPress installation be in the root directory of a Git repository.</p>', 'revisr');
            return $error;
        }
        $top_level = Revisr_Git::run('rev-parse --show-toplevel');
        $git_dir = $top_level[0] . '/.git/';
        if (!is_writable($git_dir)) {
            $error .= __('<p><strong>WARNING:</strong> Revisr cannot write to the ".git/" directory.<br>Please make sure that write permissions are set for this directory. The recommended settings are 755 for directories, and 644 for files.');
            return $error;
        }
    }