big ui cleanups
This commit is contained in:
parent
334ee3bc4c
commit
b97dd56636
@ -12,7 +12,9 @@ class WDTSLanguageOptions {
|
|||||||
$options = get_option($this->key);
|
$options = get_option($this->key);
|
||||||
foreach ($options['languages'] as $code => $info) {
|
foreach ($options['languages'] as $code => $info) {
|
||||||
if (is_null($language)) { $language = $code; }
|
if (is_null($language)) { $language = $code; }
|
||||||
if ($info['default']) { $language = $code; break; }
|
if (isset($info['default'])) {
|
||||||
|
if ($info['default']) { $language = $code; break; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $language;
|
return $language;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
class WDTSTranscriptManager {
|
class WDTSTranscriptManager {
|
||||||
var $key = null;
|
var $key = null;
|
||||||
var $post_id = null;
|
var $post_id = null;
|
||||||
|
var $allow_multiple = false;
|
||||||
|
|
||||||
function __construct($post_id = null) {
|
function __construct($post_id = null) {
|
||||||
if (is_numeric($post_id)) { $this->post_id = $post_id; }
|
if (is_numeric($post_id)) { $this->post_id = $post_id; }
|
||||||
@ -36,36 +37,63 @@ class WDTSTranscriptManager {
|
|||||||
if (!empty($user)) {
|
if (!empty($user)) {
|
||||||
$transcript_info = (array)$transcript_info;
|
$transcript_info = (array)$transcript_info;
|
||||||
$transcript_info['user_id'] = $user->ID;
|
$transcript_info['user_id'] = $user->ID;
|
||||||
|
unset($transcript_info['key']);
|
||||||
|
|
||||||
if (($transcripts = $this->_get_transcripts_metadata()) !== false) {
|
if (($transcripts = $this->_get_transcripts_metadata()) !== false) {
|
||||||
$new_transcripts = array();
|
$max_key = 0;
|
||||||
$was_added = false;
|
|
||||||
foreach ($transcripts as $transcript) {
|
foreach ($transcripts as $transcript) {
|
||||||
if ($transcript['language'] == $transcript_info['language']) {
|
$max_key = max($max_key, $transcript['key']) + 1;
|
||||||
$was_added = true;
|
|
||||||
$new_transcripts[] = $transcript_info;
|
|
||||||
} else {
|
|
||||||
$new_transcripts[] = $transcript;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!$was_added) { $new_transcripts[] = $transcript_info; }
|
$transcript_info['key'] = $max_key;
|
||||||
|
|
||||||
return update_post_meta($this->post_id, $this->key, $new_transcripts);
|
if ($this->allow_multiple) {
|
||||||
|
$transcripts[] = $transcript_info;
|
||||||
|
} else {
|
||||||
|
$new_transcripts = array();
|
||||||
|
$was_added = false;
|
||||||
|
foreach ($transcripts as $transcript) {
|
||||||
|
if ($transcript['language'] == $transcript_info['language']) {
|
||||||
|
$was_added = true;
|
||||||
|
$transcript_info['key']--;
|
||||||
|
$new_transcripts[] = $transcript_info;
|
||||||
|
} else {
|
||||||
|
$new_transcripts[] = $transcript;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$was_added) { $new_transcripts[] = $transcript_info; }
|
||||||
|
$transcripts = $new_transcripts;
|
||||||
|
}
|
||||||
|
|
||||||
|
return update_post_meta($this->post_id, $this->key, $transcripts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete_transcript($language = null) {
|
function delete_transcript($language = null) {
|
||||||
|
return $this->_delete_transcript_by_field('language', $language);
|
||||||
|
}
|
||||||
|
|
||||||
|
function delete_transcript_by_key($key = null) {
|
||||||
|
return $this->_delete_transcript_by_field('key', $key);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _delete_transcript_by_field($field, $value) {
|
||||||
if (($transcripts = $this->_get_transcripts_metadata()) !== false) {
|
if (($transcripts = $this->_get_transcripts_metadata()) !== false) {
|
||||||
$new_transcripts = array();
|
$new_transcripts = array();
|
||||||
|
$deleted_transcript = false;
|
||||||
foreach ($transcripts as $transcript) {
|
foreach ($transcripts as $transcript) {
|
||||||
if ($transcript['language'] != $language) { $new_transcripts[] = $transcript; }
|
if ($transcript[$field] != $value) {
|
||||||
|
$new_transcripts[] = $transcript;
|
||||||
|
} else {
|
||||||
|
$deleted_transcript = $transcript;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return update_post_meta($this->post_id, $this->key, $new_transcripts);
|
update_post_meta($this->post_id, $this->key, $new_transcripts);
|
||||||
|
return $deleted_transcript;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_transcripts() {
|
function get_transcripts() {
|
||||||
|
@ -2,7 +2,13 @@
|
|||||||
|
|
||||||
require_once('WDTSTranscript.php');
|
require_once('WDTSTranscript.php');
|
||||||
|
|
||||||
class WDTSQueuedTranscript extends WDTSTranscriptManager { var $key = "queued_transcripts"; }
|
class WDTSQueuedTranscript extends WDTSTranscriptManager {
|
||||||
class WDTSApprovedTranscript extends WDTSTranscriptManager { var $key = "approved_transcripts"; }
|
var $key = "queued_transcripts";
|
||||||
|
var $allow_multiple = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
class WDTSApprovedTranscript extends WDTSTranscriptManager {
|
||||||
|
var $key = "approved_transcripts";
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@ -26,15 +26,15 @@ class WDTSTranscriptOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _get_transcript_options() {
|
function _get_transcript_options() {
|
||||||
$current_transcripts = get_post_meta($this->post_id, "transcript_options", true);
|
$current_options = get_post_meta($this->post_id, "transcript_options", true);
|
||||||
if (!is_array($current_transcripts)) { $current_transcripts = array(); }
|
if (!is_array($current_options)) { $current_options = array(); }
|
||||||
return $current_transcripts;
|
return $current_options;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _update_option($option, $value) {
|
function _update_option($option, $value) {
|
||||||
$current_options = $this->_get_transcript_options();
|
$current_options = $this->_get_transcript_options();
|
||||||
$current_transcripts[$option] = $value;
|
$current_options[$option] = $value;
|
||||||
update_post_meta($this->post_id, "transcript_options", $current_transcripts);
|
update_post_meta($this->post_id, "transcript_options", $current_options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@ class WhatDidTheySayAdmin {
|
|||||||
var $all_languages = array();
|
var $all_languages = array();
|
||||||
var $notices = array();
|
var $notices = array();
|
||||||
|
|
||||||
|
var $is_ajax = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the admin interface.
|
* Initialize the admin interface.
|
||||||
* @param WhatDidTheySay $what_did_they_say The WhatDidTheySay object to use for all transcript transactions.
|
* @param WhatDidTheySay $what_did_they_say The WhatDidTheySay object to use for all transcript transactions.
|
||||||
@ -45,7 +47,6 @@ class WhatDidTheySayAdmin {
|
|||||||
|
|
||||||
add_action('admin_menu', array(&$this, 'admin_menu'));
|
add_action('admin_menu', array(&$this, 'admin_menu'));
|
||||||
add_action('admin_notices', array(&$this, 'admin_notices'));
|
add_action('admin_notices', array(&$this, 'admin_notices'));
|
||||||
add_action('admin_init', array(&$this, 'admin_init'));
|
|
||||||
|
|
||||||
wp_enqueue_script('prototype');
|
wp_enqueue_script('prototype');
|
||||||
|
|
||||||
@ -53,24 +54,27 @@ class WhatDidTheySayAdmin {
|
|||||||
add_filter('the_media_transcript', array(&$this, 'the_media_transcript'));
|
add_filter('the_media_transcript', array(&$this, 'the_media_transcript'));
|
||||||
add_filter('the_language_name', array(&$this, 'the_language_name'));
|
add_filter('the_language_name', array(&$this, 'the_language_name'));
|
||||||
|
|
||||||
add_filter('wp_footer', array(&$this, 'wp_footer'));
|
add_filter('template_redirect', array(&$this, 'template_redirect'));
|
||||||
|
|
||||||
if (isset($_REQUEST['wdts'])) {
|
if (isset($_REQUEST['wdts'])) {
|
||||||
if (isset($_REQUEST['wdts']['_nonce'])) {
|
if (isset($_REQUEST['wdts']['_nonce'])) {
|
||||||
if (wp_verify_nonce($_REQUEST['wdts']['_nonce'], 'what-did-they-say')) {
|
if (wp_verify_nonce($_REQUEST['wdts']['_nonce'], 'what-did-they-say')) {
|
||||||
$this->handle_update($_REQUEST['wdts']);
|
$this->handle_update($_REQUEST['wdts']);
|
||||||
|
|
||||||
|
if ($this->is_ajax) { exit(0); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->read_language_file();
|
$this->read_language_file();
|
||||||
|
|
||||||
|
if (current_user_can('submit_transcriptions')) {
|
||||||
|
wp_enqueue_script('scriptaculous-effects');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function template_redirect() {
|
||||||
* Handle admin_init action.
|
wp_enqueue_script('toggle-transcript', plugin_dir_url(dirname(__FILE__)) . 'toggle-transcript.js', array('prototype'), false, true);
|
||||||
*/
|
|
||||||
function admin_init() {
|
|
||||||
wp_enqueue_script('scriptaculous-effects');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,27 +94,6 @@ class WhatDidTheySayAdmin {
|
|||||||
function the_language_name($language) {
|
function the_language_name($language) {
|
||||||
return '<h3 class="transcript-language">' . $language . '</h3>';
|
return '<h3 class="transcript-language">' . $language . '</h3>';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle the wp_footer action.
|
|
||||||
*/
|
|
||||||
function wp_footer() { ?>
|
|
||||||
<script type="text/javascript">
|
|
||||||
$$('.transcript-bundle').each(function(d) {
|
|
||||||
var select = d.select("select");
|
|
||||||
if (select.length == 1) {
|
|
||||||
select = select[0];
|
|
||||||
var toggle_transcripts = function() {
|
|
||||||
d.select(".transcript-holder").each(function(div) {
|
|
||||||
div.hasClassName($F(select)) ? div.show() : div.hide();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
Event.observe(select, 'change', toggle_transcripts);
|
|
||||||
Event.observe(window, 'load', toggle_transcripts)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
<?php }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the user_has_cap filter.
|
* Handle the user_has_cap filter.
|
||||||
@ -218,19 +201,50 @@ class WhatDidTheySayAdmin {
|
|||||||
$transcripts_to_delete = array();
|
$transcripts_to_delete = array();
|
||||||
|
|
||||||
foreach ($queued_transcriptions as $transcription) { $transcripts_to_delete[$transcription->id] = true; }
|
foreach ($queued_transcriptions as $transcription) { $transcripts_to_delete[$transcription->id] = true; }
|
||||||
if (isset($post_transcript_info['queue'])) {
|
if (isset($info['queue'])) {
|
||||||
foreach ($post_transcript_info['queue'] as $id => $keep) { unset($transcripts_to_delete[$id]); }
|
foreach ($info['queue'] as $id => $keep) { unset($transcripts_to_delete[$id]); }
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (array_keys($transcripts_to_delete) as $id) { $queued_transcripts->delete_transcript($id); }
|
foreach (array_keys($transcripts_to_delete) as $id) { $queued_transcripts->delete_transcript($id); }
|
||||||
}
|
}
|
||||||
|
|
||||||
$updated = __('Transcripts updated.', 'what-did-they-say');
|
$updated = __('Transcripts updated.', 'what-did-they-say');
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return $updated;
|
return $updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handle_update_approve_transcript($info) {
|
||||||
|
$this->is_ajax = true;
|
||||||
|
|
||||||
|
if (current_user_can('approve_transcriptions')) {
|
||||||
|
$approved_transcript_manager = new WDTSApprovedTranscript($info['post_id']);
|
||||||
|
$queued_transcript_manager = new WDTSQueuedTranscript($info['post_id']);
|
||||||
|
|
||||||
|
if (($transcript = $queued_transcript_manager->delete_transcript_by_key($info['key'])) !== false) {
|
||||||
|
$approved_transcript_manager->save_transcript($transcript);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
header('HTTP/1.1 500 Internal Server Error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
header('HTTP/1.1 401 Unauthorized');
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_update_delete_transcript($info) {
|
||||||
|
$this->is_ajax = true;
|
||||||
|
|
||||||
|
if (current_user_can('approve_transcriptions')) {
|
||||||
|
$queued_transcript_manager = new WDTSQueuedTranscript($info['post_id']);
|
||||||
|
|
||||||
|
if (($transcript = $queued_transcript_manager->delete_transcript_by_key($info['key'])) !== false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
header('HTTP/1.1 500 Internal Server Error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
header('HTTP/1.1 401 Unauthorized');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle updates to languages.
|
* Handle updates to languages.
|
||||||
* @param array $info The part of the $_POST array for What Did They Say?!?
|
* @param array $info The part of the $_POST array for What Did They Say?!?
|
||||||
@ -329,7 +343,7 @@ class WhatDidTheySayAdmin {
|
|||||||
if (file_exists($this->language_file)) {
|
if (file_exists($this->language_file)) {
|
||||||
foreach (file($this->language_file) as $language) {
|
foreach (file($this->language_file) as $language) {
|
||||||
$language = trim($language);
|
$language = trim($language);
|
||||||
list($code, $date_added, $name, $additional) = explode("\t", $language);
|
list($code, $date_added, $name) = explode("\t", $language);
|
||||||
$this->all_languages[$code] = $name;
|
$this->all_languages[$code] = $name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -425,6 +439,8 @@ class WhatDidTheySayAdmin {
|
|||||||
${"${var_name}_transcripts"} = ${"${var_name}_transcript_manager"}->get_transcripts();
|
${"${var_name}_transcripts"} = ${"${var_name}_transcript_manager"}->get_transcripts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$transcript_options = new WDTSTranscriptOptions($post->ID);
|
||||||
|
|
||||||
$nonce = wp_create_nonce('what-did-they-say');
|
$nonce = wp_create_nonce('what-did-they-say');
|
||||||
include(dirname(__FILE__) . '/meta-box.inc');
|
include(dirname(__FILE__) . '/meta-box.inc');
|
||||||
}
|
}
|
||||||
|
@ -3,28 +3,28 @@
|
|||||||
<input type="hidden" name="wdts[post_id]" value="<?php echo $post->ID ?>" />
|
<input type="hidden" name="wdts[post_id]" value="<?php echo $post->ID ?>" />
|
||||||
<p>
|
<p>
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" name="wdts[allow_on_post]" value="yes" <?php echo ($transcripts['_allow']) ? 'checked="checked"' : '' ?> />
|
<input type="checkbox" name="wdts[allow_on_post]" value="yes" <?php echo ($transcript_options->are_new_transcripts_allowed()) ? 'checked="checked"' : '' ?> />
|
||||||
<?php _e('Allow new transcripts to be submitted for this post', 'what-did-they-say') ?>
|
<?php _e('Allow new transcripts to be submitted for this post', 'what-did-they-say') ?>
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
<?php if (is_array($queued_transcripts) && !empty($queued_transcripts)) { ?>
|
<?php if (is_array($queued_transcripts) && !empty($queued_transcripts)) { ?>
|
||||||
<p><strong><?php _e('Manage queued transcripts:', 'what-did-they-say') ?></strong></p>
|
<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);
|
$user = get_userdata($transcript['user_id']);
|
||||||
if (!empty($user)) { ?>
|
if (!empty($user)) { ?>
|
||||||
|
|
||||||
<div class="queued-transcription-holder">
|
<div class="queued-transcription-holder">
|
||||||
<input type="hidden" name="wdts[queue][<?php echo $transcript->id ?>]" value="keep" />
|
<input type="hidden" name="wdts[language]" value="<?php echo $transcript['language'] ?>" />
|
||||||
<input type="hidden" name="wdts[language][<?php echo $transcript->id ?>]" value="<?php echo $transcript->language ?>" />
|
<input type="hidden" name="wdts[key]" value="<?php echo $transcript['key'] ?>" />
|
||||||
<p><?php
|
<p><?php
|
||||||
printf(
|
printf(
|
||||||
__('From <strong>%s</strong> in <strong>%s</strong>:', 'what-did-they-say'),
|
__('From <strong>%s</strong> in <strong>%s</strong>:', 'what-did-they-say'),
|
||||||
$user->display_name,
|
$user->display_name,
|
||||||
$this->what_did_they_say->get_language_name($transcript->language)
|
$language_options->get_language_name($transcript['language'])
|
||||||
)
|
)
|
||||||
?></p>
|
?></p>
|
||||||
<div class="queued-transcription"><?php echo $transcript->transcript ?></div>
|
<div class="queued-transcription"><?php echo $transcript['transcript'] ?></div>
|
||||||
<div class="queued-transcription-raw" style="display:none"><?php echo $transcript->transcript ?></div>
|
<div class="queued-transcription-raw" style="display:none"><?php echo $transcript['transcript'] ?></div>
|
||||||
<div style="padding: 10px 0">
|
<div style="padding: 10px 0">
|
||||||
<a href="#" class="approve-transcript button">Approve</a>
|
<a href="#" class="approve-transcript button">Approve</a>
|
||||||
<a href="#" class="delete-transcript button">Delete</a>
|
<a href="#" class="delete-transcript button">Delete</a>
|
||||||
@ -44,54 +44,23 @@
|
|||||||
</label>
|
</label>
|
||||||
|
|
||||||
<?php foreach (array_keys($options['languages']) as $code) { ?>
|
<?php foreach (array_keys($options['languages']) as $code) { ?>
|
||||||
<textarea class="transcript" id="wdts-transcripts-<?php echo $code ?>" name="wdts[transcripts][<?php echo $code ?>]" style="display: none; width: 100%; height: 200px"><?php echo $approved_transcripts[$code] ?></textarea>
|
<textarea class="edit-transcript" id="wdts-transcripts-<?php echo $code ?>" name="wdts[transcripts][<?php echo $code ?>]" style="display: none; width: 100%; height: 200px"><?php echo $approved_transcripts[$code] ?></textarea>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function switch_transcript() {
|
var language_selector = $('wdts-language');
|
||||||
$$('.transcript').each(function(t) {
|
var ajax_url = '<?php echo $_SERVER['REQUEST_URI'] ?>';
|
||||||
(t.id == "wdts-transcripts-" + $F('wdts-language')) ? t.show() : t.hide();
|
var nonce = '<?php echo $nonce ?>';
|
||||||
});
|
|
||||||
}
|
var messages = {
|
||||||
switch_transcript();
|
'overwrite': '<?php _e('This will overwrite the current transcript. Are you sure?', 'what-did-they-say') ?>',
|
||||||
Event.observe($('wdts-language'), 'change', switch_transcript);
|
'delete': '<?php _e('This will delete the queued transcript. Are you sure?', 'what-did-they-say') ?>',
|
||||||
|
'approved': '<?php _e('Transcript approved and posted. You can further edit it below.', 'what-did-they-say') ?>',
|
||||||
$$('.approve-transcript').each(function(b) {
|
'deleted': '<?php _e('Transcript deleted.', 'what-did-they-say') ?>'
|
||||||
Event.observe(b, 'click', function(e) {
|
};
|
||||||
Event.stop(e);
|
|
||||||
var lang = b.parentNode.parentNode.select("input[name*=[language]]").shift();
|
var s = document.createElement('script');
|
||||||
if (lang) {
|
s.src = '<?php echo plugin_dir_url(dirname(__FILE__)) . 'edit-transcripts.js' ?>';
|
||||||
lang = lang.value;
|
document.getElementsByTagName('head')[0].appendChild(s);
|
||||||
var editor = $('wdts-transcripts-' + lang);
|
|
||||||
|
|
||||||
var raw_transcript = b.parentNode.parentNode.select(".queued-transcription-raw").shift();
|
|
||||||
if (raw_transcript && editor) {
|
|
||||||
var ok = true;
|
|
||||||
if (editor.value.match(/[^ ]/)) {
|
|
||||||
ok = confirm('<?php _e('This will overwrite the current transcript. Are you sure?', 'what-did-they-say') ?>');
|
|
||||||
}
|
|
||||||
if (ok) {
|
|
||||||
editor.value = raw_transcript.innerHTML;
|
|
||||||
var p = b.parentNode.parentNode;
|
|
||||||
new Effect.Fade(p, {
|
|
||||||
'afterFinish': function() { p.parentNode.removeChild(p); }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$$('.delete-transcript').each(function(b) {
|
|
||||||
Event.observe(b, 'click', function(e) {
|
|
||||||
Event.stop(e);
|
|
||||||
|
|
||||||
if (confirm('<?php _e('This will delete the queued transcript. Are you sure?', 'what-did-they-say') ?>')) {
|
|
||||||
var p = b.parentNode.parentNode;
|
|
||||||
new Effect.Fade(p, {
|
|
||||||
'afterFinish': function() { p.parentNode.removeChild(p); }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
91
edit-transcripts.js
Normal file
91
edit-transcripts.js
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
function switch_transcript() {
|
||||||
|
$$('.edit-transcript').each(function(t) {
|
||||||
|
(t.id == "wdts-transcripts-" + $F('wdts-language')) ? t.show() : t.hide();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
switch_transcript();
|
||||||
|
Event.observe(language_selector, 'change', switch_transcript);
|
||||||
|
|
||||||
|
$$('.approve-transcript').each(function(b) {
|
||||||
|
Event.observe(b, 'click', function(e) {
|
||||||
|
Event.stop(e);
|
||||||
|
var lang = b.parentNode.parentNode.select("input[name*=[language]]").shift();
|
||||||
|
var post_id = b.parentNode.parentNode.parentNode.select("input[name*=[post_id]]").shift();
|
||||||
|
var key = b.parentNode.parentNode.select("input[name*=[key]]").shift();
|
||||||
|
if (lang && post_id && key) {
|
||||||
|
lang = lang.value;
|
||||||
|
post_id = post_id.value;
|
||||||
|
key = key.value;
|
||||||
|
var editor = $('wdts-transcripts-' + lang);
|
||||||
|
|
||||||
|
var raw_transcript = b.parentNode.parentNode.select(".queued-transcription-raw").shift();
|
||||||
|
if (raw_transcript && editor) {
|
||||||
|
var ok = true;
|
||||||
|
if (editor.value.match(/[^ ]/)) {
|
||||||
|
ok = confirm(messages.overwrite);
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
editor.value = raw_transcript.innerHTML;
|
||||||
|
var p = b.parentNode.parentNode;
|
||||||
|
|
||||||
|
new Ajax.Request(
|
||||||
|
ajax_url, {
|
||||||
|
'method': 'post',
|
||||||
|
'parameters': {
|
||||||
|
'wdts[_nonce]': nonce,
|
||||||
|
'wdts[module]': 'approve-transcript',
|
||||||
|
'wdts[key]': key,
|
||||||
|
'wdts[post_id]': post_id
|
||||||
|
},
|
||||||
|
'onSuccess': function() {
|
||||||
|
p.update(messages.approved);
|
||||||
|
new Effect.Highlight(p);
|
||||||
|
var i,il;
|
||||||
|
|
||||||
|
for (i = 0, il = language_selector.options.length; i < il; ++i) {
|
||||||
|
if (language_selector.options[i].value == lang) {
|
||||||
|
language_selector.selectedIndex = i;
|
||||||
|
switch_transcript();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$$('.delete-transcript').each(function(b) {
|
||||||
|
Event.observe(b, 'click', function(e) {
|
||||||
|
Event.stop(e);
|
||||||
|
|
||||||
|
if (confirm(messages.delete)) {
|
||||||
|
var post_id = b.parentNode.parentNode.parentNode.select("input[name*=[post_id]]").shift();
|
||||||
|
var key = b.parentNode.parentNode.select("input[name*=[key]]").shift();
|
||||||
|
if (post_id && key) {
|
||||||
|
post_id = post_id.value;
|
||||||
|
key = key.value;
|
||||||
|
var p = b.parentNode.parentNode;
|
||||||
|
|
||||||
|
new Ajax.Request(
|
||||||
|
ajax_url, {
|
||||||
|
'method': 'post',
|
||||||
|
'parameters': {
|
||||||
|
'wdts[_nonce]': nonce,
|
||||||
|
'wdts[module]': 'delete-transcript',
|
||||||
|
'wdts[key]': key,
|
||||||
|
'wdts[post_id]': post_id
|
||||||
|
},
|
||||||
|
'onSuccess': function() {
|
||||||
|
p.update(messages.deleted);
|
||||||
|
new Effect.Highlight(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
@ -17,6 +17,8 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testSaveTranscript() {
|
function testSaveTranscript() {
|
||||||
|
$this->w->allow_multiple = false;
|
||||||
|
|
||||||
$this->w->save_transcript(array(
|
$this->w->save_transcript(array(
|
||||||
'language' => 'en',
|
'language' => 'en',
|
||||||
'transcript' => 'this is a transcript'
|
'transcript' => 'this is a transcript'
|
||||||
@ -27,7 +29,8 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
|
|||||||
array(
|
array(
|
||||||
'language' => 'en',
|
'language' => 'en',
|
||||||
'transcript' => 'this is a transcript',
|
'transcript' => 'this is a transcript',
|
||||||
'user_id' => 1
|
'user_id' => 1,
|
||||||
|
'key' => 0
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
get_post_meta(1, $this->w->key, true)
|
get_post_meta(1, $this->w->key, true)
|
||||||
@ -43,7 +46,8 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
|
|||||||
array(
|
array(
|
||||||
'language' => 'en',
|
'language' => 'en',
|
||||||
'transcript' => 'this is another transcript',
|
'transcript' => 'this is another transcript',
|
||||||
'user_id' => 1
|
'user_id' => 1,
|
||||||
|
'key' => 0
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
get_post_meta(1, $this->w->key, true)
|
get_post_meta(1, $this->w->key, true)
|
||||||
@ -59,39 +63,101 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
|
|||||||
array(
|
array(
|
||||||
'language' => 'en',
|
'language' => 'en',
|
||||||
'transcript' => 'this is another transcript',
|
'transcript' => 'this is another transcript',
|
||||||
'user_id' => 1
|
'user_id' => 1,
|
||||||
|
'key' => 0
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'language' => 'fr',
|
'language' => 'fr',
|
||||||
'transcript' => "il s'agit d'une nouvelle transcription",
|
'transcript' => "il s'agit d'une nouvelle transcription",
|
||||||
'user_id' => 1
|
'user_id' => 1,
|
||||||
|
'key' => 1
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
get_post_meta(1, $this->w->key, true)
|
get_post_meta(1, $this->w->key, true)
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
$this->w->allow_multiple = true;
|
||||||
|
|
||||||
|
$this->w->save_transcript(array(
|
||||||
|
'language' => 'en',
|
||||||
|
'transcript' => 'this is yet another transcript'
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'language' => 'en',
|
||||||
|
'transcript' => 'this is another transcript',
|
||||||
|
'user_id' => 1,
|
||||||
|
'key' => 0
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'language' => 'fr',
|
||||||
|
'transcript' => "il s'agit d'une nouvelle transcription",
|
||||||
|
'user_id' => 1,
|
||||||
|
'key' => 1
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'language' => 'en',
|
||||||
|
'transcript' => 'this is yet another transcript',
|
||||||
|
'user_id' => 1,
|
||||||
|
'key' => 2
|
||||||
|
),
|
||||||
|
),
|
||||||
|
get_post_meta(1, $this->w->key, true)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function testDeleteTranscript() {
|
function testDeleteTranscript() {
|
||||||
update_post_meta(1, $this->w->key, array(
|
$this->w->save_transcript(array(
|
||||||
array(
|
'language' => 'en',
|
||||||
'language' => 'en',
|
'transcript' => 'this is another transcript'
|
||||||
'transcript' => 'this is another transcript',
|
|
||||||
'user_id' => 1
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'language' => 'fr',
|
|
||||||
'transcript' => "il s'agit d'une nouvelle transcription",
|
|
||||||
'user_id' => 1
|
|
||||||
),
|
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$this->w->save_transcript(array(
|
||||||
|
'language' => 'fr',
|
||||||
|
'transcript' => "il s'agit d'une nouvelle transcription",
|
||||||
|
));
|
||||||
|
|
||||||
$this->w->delete_transcript('en');
|
$this->w->delete_transcript('en');
|
||||||
|
|
||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
array(
|
array(
|
||||||
'language' => 'fr',
|
'language' => 'fr',
|
||||||
'transcript' => "il s'agit d'une nouvelle transcription",
|
'transcript' => "il s'agit d'une nouvelle transcription",
|
||||||
'user_id' => 1
|
'user_id' => 1,
|
||||||
|
'key' => 1
|
||||||
|
),
|
||||||
|
), get_post_meta(1, $this->w->key, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
function testDeleteTranscriptByKey() {
|
||||||
|
$this->w->save_transcript(array(
|
||||||
|
'language' => 'en',
|
||||||
|
'transcript' => 'this is another transcript'
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->w->save_transcript(array(
|
||||||
|
'language' => 'fr',
|
||||||
|
'transcript' => "il s'agit d'une nouvelle transcription",
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$this->w->delete_transcript_by_key(0),
|
||||||
|
array(
|
||||||
|
'language' => 'en',
|
||||||
|
'transcript' => "this is another transcript",
|
||||||
|
'user_id' => 1,
|
||||||
|
'key' => 0
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(array(
|
||||||
|
array(
|
||||||
|
'language' => 'fr',
|
||||||
|
'transcript' => "il s'agit d'une nouvelle transcription",
|
||||||
|
'user_id' => 1,
|
||||||
|
'key' => 1
|
||||||
),
|
),
|
||||||
), get_post_meta(1, $this->w->key, true));
|
), get_post_meta(1, $this->w->key, true));
|
||||||
}
|
}
|
||||||
|
13
toggle-transcript.js
Normal file
13
toggle-transcript.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
$$('.transcript-bundle').each(function(d) {
|
||||||
|
var select = d.select("select");
|
||||||
|
if (select.length == 1) {
|
||||||
|
select = select[0];
|
||||||
|
var toggle_transcripts = function() {
|
||||||
|
d.select(".transcript-holder").each(function(div) {
|
||||||
|
div.hasClassName($F(select)) ? div.show() : div.hide();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
Event.observe(select, 'change', toggle_transcripts);
|
||||||
|
Event.observe(window, 'load', toggle_transcripts)
|
||||||
|
}
|
||||||
|
});
|
@ -26,11 +26,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||||||
|
|
||||||
foreach (glob(dirname(__FILE__) . '/classes/*.php') as $file) { require_once($file); }
|
foreach (glob(dirname(__FILE__) . '/classes/*.php') as $file) { require_once($file); }
|
||||||
|
|
||||||
$what_did_they_say_admin =& new WhatDidTheySayAdmin(&$what_did_they_say);
|
$what_did_they_say_admin = new WhatDidTheySayAdmin(&$what_did_they_say);
|
||||||
|
|
||||||
add_action('init', array(&$what_did_they_say_admin, 'init'));
|
add_action('init', array(&$what_did_they_say_admin, 'init'));
|
||||||
register_activation_hook(__FILE__, array(&$what_did_they_say, 'install'));
|
|
||||||
register_activation_hook(__FILE__, array(&$what_did_they_say_admin, 'install'));
|
|
||||||
|
|
||||||
// template tags
|
// template tags
|
||||||
// please, if you use any of these, wrap them in function_exists() so your site doesn't
|
// please, if you use any of these, wrap them in function_exists() so your site doesn't
|
||||||
@ -72,10 +70,10 @@ function the_media_transcript($language = null) {
|
|||||||
* @return string The name of the requested language.
|
* @return string The name of the requested language.
|
||||||
*/
|
*/
|
||||||
function get_the_language_name($language = null) {
|
function get_the_language_name($language = null) {
|
||||||
global $what_did_they_say;
|
$language_options = new WDTSLanguageOptions();
|
||||||
|
|
||||||
if (is_null($language)) { $language = $what_did_they_say->get_default_language(); }
|
if (is_null($language)) { $language = $language_options->get_default_language(); }
|
||||||
return $what_did_they_say->get_language_name($language);
|
return $language_options->get_language_name($language);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -106,19 +104,21 @@ function transcripts_display($dropdown_message = null, $single_language_message
|
|||||||
$post_transcripts = $approved_transcripts->get_transcripts();
|
$post_transcripts = $approved_transcripts->get_transcripts();
|
||||||
|
|
||||||
if (!empty($post_transcripts)) {
|
if (!empty($post_transcripts)) {
|
||||||
foreach ($post_transcripts as $code => $transcript) {
|
foreach ($post_transcripts as $transcript) {
|
||||||
if (substr($code, 0, 1) != "_") {
|
extract($transcript, EXTR_PREFIX_ALL, "transcript");
|
||||||
$transcript = trim($transcript);
|
$transcript_transcript = trim($transcript_transcript);
|
||||||
if (!empty($transcript)) {
|
if (!empty($transcript_transcript)) {
|
||||||
$transcripts[$code] = $transcript;
|
$transcripts[$transcript_language] = $transcript_transcript;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$language_options = new WDTSLanguageOptions();
|
||||||
|
|
||||||
if (count($transcripts) > 0) {
|
if (count($transcripts) > 0) {
|
||||||
$default_language = $what_did_they_say->get_default_language();
|
$default_language = $language_options->get_default_language();
|
||||||
|
|
||||||
$output[] = '<div class="transcript-bundle">';
|
$output[] = '<div class="transcript-bundle">';
|
||||||
|
|
||||||
if (count($transcripts) == 1) {
|
if (count($transcripts) == 1) {
|
||||||
list($code, $transcript) = each($transcripts);
|
list($code, $transcript) = each($transcripts);
|
||||||
$output[] = apply_filters('the_language_name', get_the_language_name($code));
|
$output[] = apply_filters('the_language_name', get_the_language_name($code));
|
||||||
@ -152,7 +152,7 @@ function transcripts_display($dropdown_message = null, $single_language_message
|
|||||||
* If you're allowing users to submit transcripts to the post transcript queue, use this tag in your Loop.
|
* If you're allowing users to submit transcripts to the post transcript queue, use this tag in your Loop.
|
||||||
*/
|
*/
|
||||||
function the_media_transcript_queue_editor() {
|
function the_media_transcript_queue_editor() {
|
||||||
global $post, $what_did_they_say;
|
global $post;
|
||||||
|
|
||||||
if (current_user_can('submit_transcriptions')) {
|
if (current_user_can('submit_transcriptions')) {
|
||||||
$queued_transcripts_for_user = false;
|
$queued_transcripts_for_user = false;
|
||||||
@ -164,40 +164,50 @@ function the_media_transcript_queue_editor() {
|
|||||||
$queued_transcripts_for_user = $queued_transcripts->get_transcripts_for_user($user->ID);
|
$queued_transcripts_for_user = $queued_transcripts->get_transcripts_for_user($user->ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
$transcript_options = new WDTSTranscriptOptions($post->ID);
|
$language_options = new WDTSLanguageOptions();
|
||||||
|
|
||||||
if (is_array($queued_transcripts_for_user)) {
|
$transcript_options = new WDTSTranscriptOptions($post->ID);
|
||||||
if (count($queued_transcripts_for_user) > 0) { ?>
|
|
||||||
<div class="queued-transcriptions">
|
$options = get_option('what-did-they-say-options');
|
||||||
<h3><?php _e('Your queued transcriptions', 'what-did-they-say') ?></h3>
|
|
||||||
<?php foreach ($queued_transcripts_for_user as $transcript) { ?>
|
foreach (array('Approved', 'Queued') as $name) {
|
||||||
<h4><?php echo $what_did_they_say->get_language_name($transcript->language) ?></h4>
|
$var_name = strtolower($name);
|
||||||
<div>
|
$class_name = "WDTS${name}Transcript";
|
||||||
<?php echo $transcript->transcript ?>
|
${"${var_name}_transcript_manager"} = new $class_name($post->ID);
|
||||||
</div>
|
${"${var_name}_transcripts"} = ${"${var_name}_transcript_manager"}->get_transcripts();
|
||||||
<?php } ?>
|
}
|
||||||
</div>
|
|
||||||
<?php } ?>
|
$nonce = wp_create_nonce('what-did-they-say');
|
||||||
<?php } ?>
|
|
||||||
<?php if ($transcript_options->are_new_transcripts_allowed()) { ?>
|
?>
|
||||||
|
<?php if (current_user_can('approve_transcriptions')) { ?>
|
||||||
|
<h3><?php _e('Manage Transcripts:', 'what-did-they-say') ?></h3>
|
||||||
<form method="post" class="transcript-editor">
|
<form method="post" class="transcript-editor">
|
||||||
<input type="hidden" name="wdts[_nonce]" value="<?php echo wp_create_nonce('what-did-they-say') ?>" />
|
<?php include(dirname(__FILE__) . '/classes/meta-box.inc') ?>
|
||||||
<input type="hidden" name="wdts[action]" value="submit_queued_transcript" />
|
<input type="submit" value="Submit New" />
|
||||||
<input type="hidden" name="wdts[post_id]" value="<?php echo $post->ID ?>" />
|
</form>
|
||||||
<h3><?php _e('Submit a new transcription:', 'what-did-they-say') ?></h3>
|
<?php } ?>
|
||||||
<label>
|
<?php if (current_user_can('submit_transcriptions')) { ?>
|
||||||
<?php _e('Language:', 'what-did-they-say') ?>
|
<?php if ($transcript_options->are_new_transcripts_allowed()) { ?>
|
||||||
<select name="wdts[language]">
|
<h3><?php _e('Submit a new transcript:', 'what-did-they-say') ?></h3>
|
||||||
<?php foreach ($what_did_they_say->get_languages() as $code => $info) { ?>
|
<form method="post" class="transcript-editor">
|
||||||
<option value="<?php echo $code ?>"><?php echo $info['name'] ?></option>
|
<input type="hidden" name="wdts[_nonce]" value="<?php echo wp_create_nonce('what-did-they-say') ?>" />
|
||||||
<?php } ?>
|
<input type="hidden" name="wdts[module]" value="queue-transcript" />
|
||||||
</select>
|
<input type="hidden" name="wdts[post_id]" value="<?php echo $post->ID ?>" />
|
||||||
</label><br />
|
<label>
|
||||||
<label>
|
<?php _e('Language:', 'what-did-they-say') ?>
|
||||||
<?php _e('Transcription:', 'what-did-they-say') ?><br />
|
<select name="wdts[language]">
|
||||||
<textarea style="height: 200px; width: 90%" name="wdts[transcript]"></textarea>
|
<?php foreach ($language_options->get_languages() as $code => $info) { ?>
|
||||||
</label>
|
<option value="<?php echo $code ?>"><?php echo $info['name'] ?></option>
|
||||||
<input type="submit" value="<?php _e('Submit New Transcription', 'what-did-they-say') ?>" />
|
<?php } ?>
|
||||||
|
</select>
|
||||||
|
</label><br />
|
||||||
|
<label>
|
||||||
|
<?php _e('Transcription:', 'what-did-they-say') ?><br />
|
||||||
|
<textarea style="height: 200px; width: 90%" name="wdts[transcript]"></textarea>
|
||||||
|
</label>
|
||||||
|
<input type="submit" value="<?php _e('Submit For Approval', 'what-did-they-say') ?>" />
|
||||||
|
<?php } ?>
|
||||||
</form>
|
</form>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<?php }
|
<?php }
|
||||||
|
Loading…
Reference in New Issue
Block a user