lots of cleanup on user submitted transcripts
This commit is contained in:
parent
387d1136cb
commit
11f152a2ec
|
@ -77,6 +77,26 @@ class WDTSTranscriptManager {
|
|||
return false;
|
||||
}
|
||||
|
||||
function update_transcript($info) {
|
||||
if (isset($info['key'])) {
|
||||
if (($transcripts = $this->_get_transcripts_metadata()) !== false) {
|
||||
$new_transcripts = array();
|
||||
foreach ($transcripts as $transcript) {
|
||||
if ($transcript['key'] == $info['key']) {
|
||||
foreach (array('transcript') as $field) {
|
||||
if (isset($info[$field])) {
|
||||
$transcript[$field] = $info[$field];
|
||||
}
|
||||
}
|
||||
}
|
||||
$new_transcripts[] = $transcript;
|
||||
}
|
||||
|
||||
return update_post_meta($this->post_id, $this->key, $new_transcripts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _update_search_field($transcripts) {
|
||||
if (!empty($this->search_key)) {
|
||||
$search_lines = array();
|
||||
|
@ -136,6 +156,13 @@ class WDTSTranscriptManager {
|
|||
return $user_transcripts;
|
||||
}
|
||||
|
||||
function get_transcript_by_key($key) {
|
||||
foreach ($this->get_transcripts() as $transcript) {
|
||||
if ($transcript['key'] == $key) { return $transcript; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function get_languages() {
|
||||
$languages = array();
|
||||
if (($transcripts = $this->_get_transcripts_metadata()) !== false) {
|
||||
|
|
|
@ -73,6 +73,17 @@ class WhatDidTheySayAdmin {
|
|||
add_filter('the_content', array(&$this, 'the_content_automatic_embedding'), 15);
|
||||
}
|
||||
|
||||
foreach (get_class_methods($this) as $method) {
|
||||
if (strpos($method, "shortcode_") === 0) {
|
||||
$shortcode_name = str_replace("_", "-", str_replace("shortcode_", "", $method));
|
||||
add_shortcode($shortcode_name, array(&$this, $method));
|
||||
}
|
||||
}
|
||||
|
||||
add_filter('filter_shortcode_dialog', array(&$this, 'filter_shortcode_dialog'), 10, 4);
|
||||
add_filter('filter_shortcode_scene_action', array(&$this, 'filter_shortcode_scene_action'), 10, 2);
|
||||
add_filter('filter_shortcode_scene_heading', array(&$this, 'filter_shortcode_scene_heading'), 10, 2);
|
||||
|
||||
if (isset($_REQUEST['wdts'])) {
|
||||
if (isset($_REQUEST['wdts']['_nonce'])) {
|
||||
if (wp_verify_nonce($_REQUEST['wdts']['_nonce'], 'what-did-they-say')) {
|
||||
|
@ -137,19 +148,9 @@ class WhatDidTheySayAdmin {
|
|||
if (current_user_can('submit_transcriptions')) {
|
||||
wp_enqueue_script('scriptaculous-effects');
|
||||
wp_enqueue_script('edit-transcript', plugin_dir_url(dirname(__FILE__)) . 'js/edit-transcripts.js', array('scriptaculous-effects'), false, true);
|
||||
wp_enqueue_style('wdts-admin', plugin_dir_url(dirname(__FILE__)) . 'css/wdts-admin.css');
|
||||
}
|
||||
|
||||
foreach (get_class_methods($this) as $method) {
|
||||
if (strpos($method, "shortcode_") === 0) {
|
||||
$shortcode_name = str_replace("_", "-", str_replace("shortcode_", "", $method));
|
||||
add_shortcode($shortcode_name, array(&$this, $method));
|
||||
}
|
||||
}
|
||||
|
||||
add_filter('filter_shortcode_dialog', array(&$this, 'filter_shortcode_dialog'), 10, 4);
|
||||
add_filter('filter_shortcode_scene_action', array(&$this, 'filter_shortcode_scene_action'), 10, 2);
|
||||
add_filter('filter_shortcode_scene_heading', array(&$this, 'filter_shortcode_scene_heading'), 10, 2);
|
||||
|
||||
$options = get_option('what-did-they-say-options');
|
||||
if (!empty($options['load_default_styles'])) {
|
||||
wp_enqueue_style('wdts-defaults', plugin_dir_url(dirname(__FILE__)) . 'css/wdts-defaults.css');
|
||||
|
@ -353,6 +354,27 @@ class WhatDidTheySayAdmin {
|
|||
return $updated;
|
||||
}
|
||||
|
||||
function handle_update_update_queued_transcript($info) {
|
||||
$this->is_ajax = true;
|
||||
|
||||
if ($this->current_user_can_edit_this_transcript($info['post_id'], $info['key'])) {
|
||||
$queued_transcript_manager = new WDTSQueuedTranscript($info['post_id']);
|
||||
$queued_transcript_manager->update_transcript($info);
|
||||
|
||||
$post = get_post($info['post_id']);
|
||||
|
||||
$language_options = new WDTSLanguageOptions();
|
||||
$transcript_options = new WDTSTranscriptOptions($post->ID);
|
||||
|
||||
$transcript = $queued_transcript_manager->get_transcript_by_key($info['key']);
|
||||
$user = wp_get_current_user();
|
||||
|
||||
include(dirname(__FILE__) . '/partials/_queued-transcript-contents.inc');
|
||||
return;
|
||||
}
|
||||
header('HTTP/1.1 401 Unauthorized');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle updates to post transcripts.
|
||||
* @param array $info The part of the $_POST array for What Did They Say?!?
|
||||
|
@ -412,13 +434,33 @@ class WhatDidTheySayAdmin {
|
|||
header('HTTP/1.1 401 Unauthorized');
|
||||
}
|
||||
|
||||
function current_user_can_edit_this_transcript($post_id, $transcript_id) {
|
||||
if (current_user_can('approve_transcriptions')) {
|
||||
$ok = true;
|
||||
} else {
|
||||
$ok = false;
|
||||
if (current_user_can('submit_transcriptions')) {
|
||||
$queued_transcript_manager = new WDTSQueuedTranscript($post_id);
|
||||
$user = wp_get_current_user();
|
||||
|
||||
$transcripts = $queued_transcript_manager->get_transcripts_for_user($user->ID);
|
||||
foreach ($transcripts as $transcript) {
|
||||
if ($transcript['key'] == $transcript_id) {
|
||||
$ok = true; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ok;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle transcript deletion.
|
||||
*/
|
||||
function handle_update_delete_transcript($info) {
|
||||
$this->is_ajax = true;
|
||||
|
||||
if (current_user_can('approve_transcriptions')) {
|
||||
if ($this->current_user_can_edit_this_transcript($info['post_id'], $info['key'])) {
|
||||
$queued_transcript_manager = new WDTSQueuedTranscript($info['post_id']);
|
||||
|
||||
if (($transcript = $queued_transcript_manager->delete_transcript_by_key($info['key'])) !== false) {
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
<div class="queued-transcription-holder">
|
||||
<?php include(dirname(__FILE__) . '/_queued-transcript-contents.inc') ?>
|
||||
</div>
|
|
@ -0,0 +1,19 @@
|
|||
<input type="hidden" name="wdts[language]" value="<?php echo $transcript['language'] ?>" />
|
||||
<input type="hidden" name="wdts[post_id]" value="<?php echo $post->ID ?>" />
|
||||
<input type="hidden" name="wdts[key]" value="<?php echo $transcript['key'] ?>" />
|
||||
<p><?php
|
||||
printf(
|
||||
__('From <strong>%s</strong> in <strong>%s</strong>:', 'what-did-they-say'),
|
||||
$user->display_name,
|
||||
$language_options->get_language_name($transcript['language'])
|
||||
)
|
||||
?></p>
|
||||
<div class="queued-transcription transcript"><?php echo do_shortcode($transcript['transcript']) ?></div>
|
||||
<div class="queued-transcription-raw" style="display:none"><?php echo $transcript['transcript'] ?></div>
|
||||
<div class="transcript-action-links">
|
||||
<?php if (current_user_can('approve_transcriptions')) { ?>
|
||||
<a href="#" class="approve-transcript button">Approve</a> |
|
||||
<?php } ?>
|
||||
<a href="#" class="delete-transcript button">Delete</a> |
|
||||
<a href="#" class="edit-transcript button">Edit</a>
|
||||
</div>
|
|
@ -9,29 +9,12 @@
|
|||
</p>
|
||||
<?php if (is_array($queued_transcripts) && !empty($queued_transcripts)) { ?>
|
||||
<p><strong><?php _e('Manage queued transcripts:', 'what-did-they-say') ?></strong></p>
|
||||
<?php foreach ($queued_transcripts as $transcript) {
|
||||
<?php
|
||||
foreach ($queued_transcripts as $transcript) {
|
||||
$user = get_userdata($transcript['user_id']);
|
||||
if (!empty($user)) { ?>
|
||||
|
||||
<div class="queued-transcription-holder">
|
||||
<input type="hidden" name="wdts[language]" value="<?php echo $transcript['language'] ?>" />
|
||||
<input type="hidden" name="wdts[key]" value="<?php echo $transcript['key'] ?>" />
|
||||
<p><?php
|
||||
printf(
|
||||
__('From <strong>%s</strong> in <strong>%s</strong>:', 'what-did-they-say'),
|
||||
$user->display_name,
|
||||
$language_options->get_language_name($transcript['language'])
|
||||
)
|
||||
?></p>
|
||||
<div class="queued-transcription transcript"><?php echo do_shortcode($transcript['transcript']) ?></div>
|
||||
<div class="queued-transcription-raw" style="display:none"><?php echo $transcript['transcript'] ?></div>
|
||||
<div style="padding: 10px 0">
|
||||
<a href="#" class="approve-transcript button">Approve</a>
|
||||
<a href="#" class="delete-transcript button">Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
if (!empty($user)) { include('_display-queued-transcript.inc'); }
|
||||
}
|
||||
?>
|
||||
<?php } ?>
|
||||
<p>
|
||||
<label>
|
||||
|
@ -44,9 +27,9 @@
|
|||
</label>
|
||||
|
||||
<div id="wdts-shorttags">
|
||||
<button class="wdts-create" id="wdts-scene-heading">Scene Heading</button>
|
||||
<button class="wdts-create" id="wdts-scene-action">Scene Action</button>
|
||||
<button class="wdts-create" id="wdts-dialog">Dialog</button>
|
||||
<button class="wdts-create" id="wdts-scene-heading" onclick="return false">Scene Heading</button>
|
||||
<button class="wdts-create" id="wdts-scene-action" onclick="return false">Scene Action</button>
|
||||
<button class="wdts-create" id="wdts-dialog" onclick="return false">Dialog</button>
|
||||
|
||||
<?php foreach (array_keys($options['languages']) as $code) {
|
||||
$approved_transcript_text = '';
|
||||
|
|
|
@ -65,3 +65,7 @@
|
|||
#wdts-page-introduction label {
|
||||
display: inline
|
||||
}
|
||||
|
||||
.transcript-action-links {
|
||||
padding-top: 0.4em
|
||||
}
|
|
@ -103,7 +103,7 @@ Event.observe(window, 'load', function() {
|
|||
});
|
||||
});
|
||||
|
||||
$$('.approve-transcript').each(function(b) {
|
||||
function wdts_setup_approve_transcript_clicker(b) {
|
||||
b.observe('click', function(e) {
|
||||
Event.stop(e);
|
||||
var lang = b.parentNode.parentNode.select("input[name*=[language]]").shift();
|
||||
|
@ -153,10 +153,10 @@ $$('.approve-transcript').each(function(b) {
|
|||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$$('.delete-transcript').each(function(b) {
|
||||
Event.observe(b, 'click', function(e) {
|
||||
function wdts_setup_delete_transcript_clicker(b) {
|
||||
b.observe('click', function(e) {
|
||||
Event.stop(e);
|
||||
|
||||
if (confirm(messages.delete)) {
|
||||
|
@ -185,7 +185,63 @@ $$('.delete-transcript').each(function(b) {
|
|||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function wdts_setup_edit_transcript_clicker(b) {
|
||||
b.observe('click', function(e) {
|
||||
Event.stop(e);
|
||||
|
||||
var target = b.parentNode.parentNode;
|
||||
|
||||
var transcript = target.select('.transcript').pop();
|
||||
var textnode = new Element('textarea', { style: 'height: 200px; width: 90%' });
|
||||
var action_links = target.select('.transcript-action-links').pop();
|
||||
textnode.value = target.select('.queued-transcription-raw').pop().innerHTML;
|
||||
|
||||
b.parentNode.parentNode.insertBefore(textnode, transcript);
|
||||
transcript.hide();
|
||||
|
||||
var post_id = target.select("input[name*=[post_id]]").shift();
|
||||
var key = target.select("input[name*=[key]]").shift();
|
||||
|
||||
var submitter = new Element('button').update('Update Transcript');
|
||||
submitter.observe('click', function(e) {
|
||||
top.console.log(post_id);
|
||||
top.console.log(key);
|
||||
if (post_id && key) {
|
||||
post_id = post_id.value;
|
||||
key = key.value;
|
||||
|
||||
new Ajax.Updater(target, ajax_url, {
|
||||
'method': 'post',
|
||||
'parameters': {
|
||||
'wdts[_nonce]': nonce,
|
||||
'wdts[module]': 'update-queued-transcript',
|
||||
'wdts[key]': key,
|
||||
'wdts[post_id]': post_id,
|
||||
'wdts[transcript]': textnode.value
|
||||
},
|
||||
'onComplete': function() {
|
||||
new Effect.Highlight(target);
|
||||
wdts_add_clickers(target);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
b.parentNode.parentNode.appendChild(submitter);
|
||||
action_links.parentNode.removeChild(action_links);
|
||||
});
|
||||
}
|
||||
|
||||
function wdts_add_clickers(p) {
|
||||
top.console.log(p);
|
||||
p.select('.edit-transcript').each(function(b) { top.console.log(b); wdts_setup_edit_transcript_clicker(b); });
|
||||
p.select('.approve-transcript').each(function(b) { wdts_setup_approve_transcript_clicker(b); });
|
||||
p.select('.delete-transcript').each(function(b) { wdts_setup_delete_transcript_clicker(b); });
|
||||
}
|
||||
|
||||
wdts_add_clickers($$('body')[0]);
|
||||
|
||||
if (language_selector) {
|
||||
switch_transcript();
|
||||
|
|
|
@ -191,6 +191,40 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
|
|||
|
||||
$this->assertEquals(array('en', 'fr'), $this->w->get_languages());
|
||||
}
|
||||
|
||||
function testUpdateTranscript() {
|
||||
update_post_meta(1, $this->w->key,
|
||||
array(
|
||||
array(
|
||||
'language' => 'en',
|
||||
'transcript' => 'this is a transcript',
|
||||
'user_id' => 1,
|
||||
'key' => 0
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$info = array(
|
||||
'key' => 0,
|
||||
'user_id' => 1,
|
||||
'transcript' => 'hiss hiss hiss',
|
||||
'language' => 'fr'
|
||||
);
|
||||
|
||||
$this->w->update_transcript($info);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
array(
|
||||
'language' => 'en',
|
||||
'transcript' => 'hiss hiss hiss',
|
||||
'user_id' => 1,
|
||||
'key' => 0
|
||||
)
|
||||
),
|
||||
get_post_meta(1, $this->w->key, true)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -221,6 +221,14 @@ function the_media_transcript_queue_editor() {
|
|||
<input type="submit" value="Modify Transcript" />
|
||||
</form>
|
||||
<?php } ?>
|
||||
<?php if ((count($queued_transcripts_for_user) > 0) && !current_user_can('approve_transcriptions')) { ?>
|
||||
<h3 style="margin-top: 0.5em"><?php _e('Your Submitted Transcripts:', 'what-did-they-say') ?></h3>
|
||||
<?php
|
||||
foreach ($queued_transcripts_for_user as $transcript) {
|
||||
include(dirname(__FILE__) . '/classes/partials/_display-queued-transcript.inc');
|
||||
}
|
||||
?>
|
||||
<?php } ?>
|
||||
<?php if (current_user_can('submit_transcriptions')) { ?>
|
||||
<?php if ($transcript_options->are_new_transcripts_allowed()) { ?>
|
||||
<h3 style="margin-top: 0.5em"><?php _e('Submit a new transcript:', 'what-did-they-say') ?></h3>
|
||||
|
|
Loading…
Reference in New Issue