Created
January 19, 2010 19:38
-
-
Save sproutventure/281211 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Adds the admin page to the wp-admin navigation | |
function sv_svn_update_pages() { | |
add_options_page('SVN Update', 'SVN Update', 8, __FILE__, 'sv_svn_update_page'); | |
} | |
add_action('admin_menu', 'sv_svn_update_pages'); | |
// Returns array with revision number and path | |
function sv_template_svn_info() { | |
$result = array(); | |
$info = shell_exec('svn info ' . trailingslashit(TEMPLATEPATH)); | |
if (preg_match('/Revision: (.*)/', $info, $matches)) | |
$result['revision'] = intval($matches[1]); | |
if (preg_match('/URL: (.*)/', $info, $matches)) | |
$result['url'] = $matches[1]; | |
if (preg_match('/Path: (.*)/', $info, $matches)) | |
$result['path'] = $matches[1]; | |
return $result; | |
} | |
function sv_svn_info($url) { | |
$result = array(); | |
$info = shell_exec('svn info ' . $url ); | |
if (preg_match('/Revision: (.*)/', $info, $matches)) | |
$result['revision'] = intval($matches[1]); | |
return $result; | |
} | |
// Updates the path submitted | |
function sv_svn_update($path = '') { | |
passthru('svn update ' . $path ); | |
} | |
// Admin Page | |
function sv_svn_update_page() { | |
$info = sv_template_svn_info(); | |
$svn_info = sv_svn_info($info['url']); | |
?> | |
<div class="wrap"> | |
<h2><?php _e('SVN Update') ?></h2> | |
<?php if (isset($_GET['update'])) : ?> | |
<h3><?php _e('Updating') ?></h3> | |
<pre style="white-space:pre-wrap;"><?php sv_svn_update($_GET['path']) ?></pre> | |
<?php else : ?> | |
<h3><?php _e('SVN Update') ?></h3> | |
<form method="get" action="options-general.php"> | |
<table class="form-table"> | |
<tbody> | |
<tr> | |
<th scope="row"><?php _e('Current Revision') ?></th> | |
<td> | |
<?php echo htmlspecialchars($svn_info['revision']) ?> | |
</td> | |
</tr> | |
<th scope="row"><?php _e('Local Revision') ?></th> | |
<td> | |
<?php echo htmlspecialchars($info['revision']) ?> | |
</td> | |
</tr> | |
<tr> | |
<th scope="row"><?php _e('Path to update') ?></th> | |
<td> | |
<input type="text" id="path" name="path" size="62" value="<?php echo htmlspecialchars($info['path']) ?>" /> | |
<p><small><?php _e('Change to any local path to update. Defaults to template path.'); ?></small></p> | |
</td> | |
</tr> | |
</tbody> | |
</table> | |
<p class="submit"> | |
<input type="hidden" name="page" value="<?php echo htmlspecialchars($_GET['page']) ?>" /> | |
<input type="submit" name="update" value="<?php _e('Update') ?>" /> | |
</p> | |
<h3><?php _e('SVN Info - Template Path') ?></h3> | |
<?php | |
echo '<pre style="white-space:pre-wrap;">'; | |
print_r( shell_exec('svn info '. trailingslashit(TEMPLATEPATH)) ); | |
echo '</pre>'; | |
?> | |
<h3><?php _e('SVN Info - WordPress Install') ?></h3> | |
<?php | |
echo '<pre style="white-space:pre-wrap;">'; | |
print_r( shell_exec('svn info ..') ); | |
echo '</pre>'; | |
?> | |
</form> | |
<?php endif; ?> | |
</div> | |
<? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment