import working, now adding user credit support

This commit is contained in:
John Bintz 2009-10-25 15:53:55 -04:00
parent cc7200986c
commit b6888da24c
7 changed files with 121 additions and 14 deletions

View File

@ -34,10 +34,14 @@ class WDTSTranscriptManager {
* @return bool True if the transcript was saved, false otherwise.
*/
function save_transcript($transcript_info) {
$user = wp_get_current_user();
if (!empty($user)) {
$transcript_info = (array)$transcript_info;
$transcript_info['user_id'] = $user->ID;
$transcript_info = (array)$transcript_info;
if (!isset($transcript_info['user_id'])) {
$user = wp_get_current_user();
if (!empty($user)) {
$transcript_info['user_id'] = $user->ID;
}
}
if (isset($transcript_info['user_id'])) {
unset($transcript_info['key']);
foreach (array_keys($transcript_info) as $key) {

View File

@ -709,10 +709,11 @@ class WhatDidTheySayAdmin {
if (current_user_can('approve_transcriptions')) {
$approved_transcript_manager = new WDTSApprovedTranscript($info['post_id']);
foreach ($info['transcripts'] as $language => $transcript) {
foreach ($info['transcripts'] as $language => $transcript_info) {
$approved_transcript_manager->save_transcript(array(
'language' => $language,
'transcript' => $transcript
'language' => $language,
'transcript' => $transcript_info['transcript'],
'user_id' => $transcript_info['user_id']
));
}
@ -1076,6 +1077,8 @@ class WhatDidTheySayAdmin {
$language_options = new WDTSLanguageOptions();
$users = $wpdb->get_results("SELECT ID, user_login from $wpdb->users ORDER BY user_login");
$nonce = wp_create_nonce('what-did-they-say');
include('partials/meta-box.inc');
}

View File

@ -0,0 +1,88 @@
<?php
?><div class="wrap">
<h2><?php _e('Import Transcripts', 'what-did-they-say') ?></h2>
<p>
<?php _e('Import transcripts from your current setup into <strong>What Did They Say?!?</strong>', 'what-did-they-say') ?>
<?php _e('Currently, the import supports pulling transcripts from the &quot;transcript&quot; metadata field.', 'what-did-they-say') ?>
<?php _e('This field is used by some webcomic themes to store and display transcripts.', 'what-did-they-say') ?>
</p>
<?php if ($legacy_transcript_count == 0) { ?>
<p>
<?php _e('<strong>You have no legacy transcripts!</strong>', 'what-did-they-say') ?>
</p>
<?php } else { ?>
<p>
<?php printf(__('<strong>You have %d legacy transcripts.</strong< Click the button below to import them into <strong>What Did They Say?!?</strong>', 'what-did-they-say'), $legacy_transcript_count) ?>
<?php _e('<strong>Make sure you\'ve backed up your database first!</strong>', 'what-did-they-say') ?>
<?php _e('<strong>This will also overwrite any WDTS? transcripts that are already in the chosen language for each modified post!</strong>', 'what-did-they-say') ?>
</p>
<form>
<label>
<?php _e('Language:', 'what-did-they-say') ?>
<select id="wdts-language" name="wdts[language]" class="wdts-transcript-selector">
<?php foreach ($options['languages'] as $code => $info) { ?>
<option value="<?php echo $code ?>" <?php echo $info['default'] ? 'selected="selected"' : '' ?>><?php echo $info['name'] ?></option>
<?php } ?>
</select>
</label>
<button id="wdts-<?php echo $id = md5(rand()) ?>">
<?php _e('Import transcripts', 'what-did-they-say') ?>
</button>
<span class="wdts-updater" style="display:none" id="wdts-updater-<?php echo $id ?>"></span>
</form>
<style type="text/css">
.wdts-updater {
border: solid #500 1px;
padding: 2px;
background-color: #eab
}
</style>
<script type="text/javascript">
var total_transcripts = <?php echo $legacy_transcript_count ?>;
var total_imported = 0;
var use_language;
var do_transcript_import;
do_transcript_import = function() {
var updater = $('wdts-updater-<?php echo $id ?>');
updater.update(total_imported + '/' + total_transcripts + ' <?php _e('imported...', 'what-did-they-say') ?>');
if (!updater.visible()) {
new Effect.BlindDown(updater, { duration: 0.5 });
}
new Ajax.Request('<?php echo addslashes($_SERVER['REQUEST_URI']) ?>', {
method: 'post',
parameters: {
'wdts[_nonce]': '<?php echo $nonce ?>',
'wdts[module]': 'import-legacy',
'wdts[language]': use_language
},
onSuccess: function(r) {
var count = r.headerJSON;
if (count == 'false') {
updater.update('<?php _e('There was a problem during import!', 'what-did-they-say') ?>');
} else {
count = Number(count);
if (count > 0) {
total_imported += count;
do_transcript_import();
} else {
updater.update('<?php _e('Import complete! Total number imported:', 'what-did-they-say') ?> ' + total_imported);
}
}
}
});
};
$('wdts-<?php echo $id ?>').observe('click', function(e) {
Event.stop(e);
use_language = $F('wdts-language')
do_transcript_import();
e.target.disabled = true;
});
</script>
<?php } ?>
</div>

View File

@ -48,7 +48,16 @@
foreach ($approved_transcripts as $transcript) {
if ($transcript['language'] == $code) { $approved_transcript_text = $transcript['transcript']; break; }
} ?>
<textarea class="edit-transcript" name="wdts[transcripts][<?php echo $code ?>]" style="display: none; width: 99%; height: 200px"><?php echo $approved_transcript_text ?></textarea>
<div class="edit-transcript-<?php echo $code ?> edit-transcript" style="display: none">
<textarea name="wdts[transcripts][<?php echo $code ?>][transcript]" style="width: 99%; height: 200px"><?php echo $approved_transcript_text ?></textarea>
<?php _e('User to credit: ', 'what-did-they-say') ?>
<select name="wdts[transcripts][<?php echo $code ?>][user_id]">
</select>
<?php
?>
</div>
<?php } ?>
<?php if (!is_admin()) { ?>
<input type="button" class="wdts-modify-transcript button" value="<?php _e('Update All Transcripts', 'what-did-they-say') ?>" />

View File

@ -14,8 +14,8 @@ WhatDidTheySay.setup_transcript_editor = function(container) {
if (language_selector) {
var switch_transcripts = function() {
container.select('.edit-transcript').each(function(t) {
(t.name == 'wdts[transcripts][' + $F(language_selector) + ']') ? t.show() : t.hide();
container.select('.edit-transcript').each(function(h) {
h.hasClassName('edit-transcript-' + $F(language_selector)) ? h.show() : h.hide();
});
};

View File

@ -41,7 +41,8 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
$this->w->save_transcript(array(
'language' => 'en',
'transcript' => 'this is another transcript'
'transcript' => 'this is another transcript',
'user_id' => 2
));
$this->assertEquals(
@ -49,7 +50,7 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
array(
'language' => 'en',
'transcript' => 'this is another transcript',
'user_id' => 1,
'user_id' => 2,
'key' => 0
)
),
@ -68,7 +69,7 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
array(
'language' => 'en',
'transcript' => 'this is another transcript',
'user_id' => 1,
'user_id' => 2,
'key' => 0
),
array(
@ -95,7 +96,7 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
array(
'language' => 'en',
'transcript' => 'this is another transcript',
'user_id' => 1,
'user_id' => 2,
'key' => 0
),
array(

View File

@ -193,6 +193,8 @@ function the_media_transcript_queue_editor() {
$options = get_option('what-did-they-say-options');
$users = $wpdb->get_results("SELECT ID, user_login from $wpdb->users ORDER BY user_login");
foreach (array('Approved', 'Queued') as $name) {
$var_name = strtolower($name);
$class_name = "WDTS${name}Transcript";