Merge branch 'master' of ssh://claritycomic.com/home/john/repositories/what-did-they-say
This commit is contained in:
commit
c0c2d0a9ad
|
@ -214,6 +214,26 @@ class WhatDidTheySay {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_default_language() {
|
||||||
|
$language = false;
|
||||||
|
$options = get_option('what-did-they-say-options');
|
||||||
|
foreach ($options['languages'] as $code => $info) {
|
||||||
|
if (is_null($language)) { $language = $code; }
|
||||||
|
if ($info['default']) { $language = $code; break; }
|
||||||
|
}
|
||||||
|
return $language;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_language_name($language) {
|
||||||
|
$options = get_option('what-did-they-say-options');
|
||||||
|
|
||||||
|
if (isset($options['languages'][$language])) {
|
||||||
|
return $options['languages'][$language]['name'];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -29,6 +29,9 @@ class WhatDidTheySayAdmin {
|
||||||
$this->language_file = dirname(__FILE__) . '/../data/lsr-language.txt';
|
$this->language_file = dirname(__FILE__) . '/../data/lsr-language.txt';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the object.
|
||||||
|
*/
|
||||||
function init() {
|
function init() {
|
||||||
$this->capabilities = array(
|
$this->capabilities = array(
|
||||||
'submit_transcriptions' => __('Submit transcriptions to a post', 'what-did-they-say'),
|
'submit_transcriptions' => __('Submit transcriptions to a post', 'what-did-they-say'),
|
||||||
|
@ -42,6 +45,10 @@ class WhatDidTheySayAdmin {
|
||||||
wp_enqueue_script('prototype');
|
wp_enqueue_script('prototype');
|
||||||
|
|
||||||
add_filter('user_has_cap', array(&$this, 'user_has_cap'), 5, 3);
|
add_filter('user_has_cap', array(&$this, 'user_has_cap'), 5, 3);
|
||||||
|
add_filter('the_media_transcript', array(&$this, 'the_media_transcript'));
|
||||||
|
add_filter('the_language_name', array(&$this, 'the_language_name'));
|
||||||
|
|
||||||
|
add_filter('wp_footer', array(&$this, 'wp_footer'));
|
||||||
|
|
||||||
if (isset($_REQUEST['wdts'])) {
|
if (isset($_REQUEST['wdts'])) {
|
||||||
if (isset($_REQUEST['wdts']['_nonce'])) {
|
if (isset($_REQUEST['wdts']['_nonce'])) {
|
||||||
|
@ -54,6 +61,35 @@ class WhatDidTheySayAdmin {
|
||||||
$this->read_language_file();
|
$this->read_language_file();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function the_media_transcript($transcript) {
|
||||||
|
return '<div class="transcript">' . $transcript . '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
function the_language_name($language) {
|
||||||
|
return '<h3>' . $language . '</h3>';
|
||||||
|
}
|
||||||
|
|
||||||
|
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 }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* user_has_cap filter.
|
||||||
|
*/
|
||||||
function user_has_cap($capabilities, $requested_capabilities, $capability_name) {
|
function user_has_cap($capabilities, $requested_capabilities, $capability_name) {
|
||||||
$options = get_option('what-did-they-say-options');
|
$options = get_option('what-did-they-say-options');
|
||||||
|
|
||||||
|
@ -75,32 +111,50 @@ class WhatDidTheySayAdmin {
|
||||||
return $capabilities;
|
return $capabilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _update_options($which, $value) {
|
/**
|
||||||
$options = get_option('what-did-they-say-options');
|
* Show admin notices.
|
||||||
$options[$which] = $value;
|
*/
|
||||||
update_option('what-did-they-say-options', $options);
|
|
||||||
}
|
|
||||||
|
|
||||||
function admin_notices() {
|
function admin_notices() {
|
||||||
if (!empty($this->notices)) {
|
if (!empty($this->notices)) {
|
||||||
echo '<div class="updated fade">';
|
echo '<div class="updated fade">';
|
||||||
echo implode("<br />", $this->notices);
|
foreach ($this->notices as $notice) { echo "<p>" . $notice . "</p>"; }
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle an update to options.
|
||||||
|
*/
|
||||||
function handle_update($info) {
|
function handle_update($info) {
|
||||||
foreach (array(
|
foreach (get_class_methods($this) as $method) {
|
||||||
'languages', 'capabilities'
|
if (strpos($method, "handle_update_") === 0) {
|
||||||
) as $method) {
|
$result = $this->{$method}($info);
|
||||||
$result = $this->{"handle_update_${method}"}($info);
|
|
||||||
if (!empty($result)) { $this->notices[] = $result; }
|
if (!empty($result)) { $this->notices[] = $result; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_update_post_transcripts($post_transcript_info) {
|
||||||
|
$updated = false;
|
||||||
|
if (current_user_can('approve_transcriptions')) {
|
||||||
|
$options = get_option('what-did-they-say-options');
|
||||||
|
|
||||||
|
switch ($post_transcript_info['action']) {
|
||||||
|
case "manage_post_transcripts":
|
||||||
|
foreach ($post_transcript_info['transcripts'] as $language => $transcript) {
|
||||||
|
$this->what_did_they_say->save_transcript($post_transcript_info['post_id'], $language, $transcript);
|
||||||
|
}
|
||||||
|
$updated = __('Transcripts updated', 'what-did-they-say');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $updated;
|
||||||
|
}
|
||||||
|
|
||||||
function handle_update_languages($language_info) {
|
function handle_update_languages($language_info) {
|
||||||
$options = get_option('what-did-they-say-options');
|
|
||||||
$updated = false;
|
$updated = false;
|
||||||
|
if (current_user_can('change_languages')) {
|
||||||
|
$options = get_option('what-did-they-say-options');
|
||||||
switch ($language_info['action']) {
|
switch ($language_info['action']) {
|
||||||
case "delete":
|
case "delete":
|
||||||
$updated = sprintf(__('%s deleted.', 'what-did-they-say'), $options['languages'][$language_info['code']]['name']);
|
$updated = sprintf(__('%s deleted.', 'what-did-they-say'), $options['languages'][$language_info['code']]['name']);
|
||||||
|
@ -134,14 +188,18 @@ class WhatDidTheySayAdmin {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if ($updated !== false) {
|
||||||
ksort($options['languages']);
|
ksort($options['languages']);
|
||||||
update_option('what-did-they-say-options', $options);
|
update_option('what-did-they-say-options', $options);
|
||||||
|
}
|
||||||
|
}
|
||||||
return $updated;
|
return $updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handle_update_capabilities($capabilities_info) {
|
function handle_update_capabilities($capabilities_info) {
|
||||||
$options = get_option('what-did-they-say-options');
|
|
||||||
$updated = false;
|
$updated = false;
|
||||||
|
if (current_user_can('edit_users')) {
|
||||||
|
$options = get_option('what-did-they-say-options');
|
||||||
switch ($capabilities_info['action']) {
|
switch ($capabilities_info['action']) {
|
||||||
case "capabilities":
|
case "capabilities":
|
||||||
if (isset($capabilities_info['capabilities'])) {
|
if (isset($capabilities_info['capabilities'])) {
|
||||||
|
@ -154,27 +212,13 @@ class WhatDidTheySayAdmin {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if ($updated !== false) {
|
||||||
update_option('what-did-they-say-options', $options);
|
update_option('what-did-they-say-options', $options);
|
||||||
|
}
|
||||||
|
}
|
||||||
return $updated;
|
return $updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handle_update_options($requested_options) {
|
|
||||||
$updated_options = array(
|
|
||||||
'only_allowed_users' => false
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($requested_options as $option => $value) {
|
|
||||||
switch ($option) {
|
|
||||||
case 'only_allowed_users':
|
|
||||||
$updated_options['only_allowed_users'] = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$options = array_merge(get_option('what-did-they-say-options'), $updated_options);
|
|
||||||
update_option('what-did-they-say-options', $options);
|
|
||||||
}
|
|
||||||
|
|
||||||
function read_language_file() {
|
function read_language_file() {
|
||||||
if (file_exists($this->language_file)) {
|
if (file_exists($this->language_file)) {
|
||||||
foreach (file($this->language_file, FILE_IGNORE_NEW_LINES) as $language) {
|
foreach (file($this->language_file, FILE_IGNORE_NEW_LINES) as $language) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<iuput type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
|
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
|
||||||
<iuput type="hidden" name="wdts[action]" value="manage_post_transcripts" />
|
<input type="hidden" name="wdts[action]" value="manage_post_transcripts" />
|
||||||
|
<input type="hidden" name="wdts[post_id]" value="<?php echo $post->ID ?>" />
|
||||||
<p>
|
<p>
|
||||||
<label>
|
<label>
|
||||||
Edit transcript for:
|
Edit transcript for:
|
||||||
|
|
|
@ -59,19 +59,6 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
|
||||||
$this->assertEquals($expected_results, $options['languages']);
|
$this->assertEquals($expected_results, $options['languages']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testHandleUpdateOptions() {
|
|
||||||
$admin = new WhatDidTheySayAdmin();
|
|
||||||
|
|
||||||
update_option('what-did-they-say-options', array('only_allowed_users' => false));
|
|
||||||
|
|
||||||
$admin->handle_update_options(array(
|
|
||||||
'only_allowed_users' => 'yes'
|
|
||||||
));
|
|
||||||
|
|
||||||
$options = get_option('what-did-they-say-options');
|
|
||||||
$this->assertTrue($options['only_allowed_users']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testBuildFullDefaultLanguageInfo() {
|
function testBuildFullDefaultLanguageInfo() {
|
||||||
$admin = new WhatDidTheySayAdmin();
|
$admin = new WhatDidTheySayAdmin();
|
||||||
$admin->all_languages = array(
|
$admin->all_languages = array(
|
||||||
|
|
|
@ -33,4 +33,83 @@ 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, 'install'));
|
||||||
register_activation_hook(__FILE__, array(&$what_did_they_say_admin, 'install'));
|
register_activation_hook(__FILE__, array(&$what_did_they_say_admin, 'install'));
|
||||||
|
|
||||||
|
function get_the_media_transcript($language = null) {
|
||||||
|
global $post, $what_did_they_say;
|
||||||
|
|
||||||
|
if (is_null($language)) { $language = $what_did_they_say->get_default_language(); }
|
||||||
|
|
||||||
|
$transcript = false;
|
||||||
|
$transcripts = $what_did_they_say->get_transcripts($post->ID);
|
||||||
|
if (!empty($transcripts)) {
|
||||||
|
if (isset($transcripts[$language])) { $transcript = $transcripts[$language]; }
|
||||||
|
}
|
||||||
|
return $transcript;
|
||||||
|
}
|
||||||
|
|
||||||
|
function the_media_transcript($language = null) {
|
||||||
|
$transcript = apply_filters('the_media_transcript', get_the_media_transcript());
|
||||||
|
echo $transcript;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_the_language_name($language = null) {
|
||||||
|
global $what_did_they_say;
|
||||||
|
|
||||||
|
if (is_null($language)) { $language = $what_did_they_say->get_default_language(); }
|
||||||
|
return $what_did_they_say->get_language_name($language);
|
||||||
|
}
|
||||||
|
|
||||||
|
function the_language_name($language = null) {
|
||||||
|
$name = apply_filters('the_language_name', get_the_language_name($language));
|
||||||
|
echo $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function the_media_transcript_select_and_display($dropdown_message = null, $single_language_message = null) {
|
||||||
|
global $post, $what_did_they_say;
|
||||||
|
|
||||||
|
if (is_null($dropdown_message)) { $dropdown_message = __('Select a language:', 'what-did-they-say'); }
|
||||||
|
if (is_null($single_language_message)) { $single_language_message = __('%s transcript:', 'what-did-they-say'); }
|
||||||
|
|
||||||
|
$transcripts = array();
|
||||||
|
foreach ($what_did_they_say->get_transcripts($post->ID) as $code => $transcript) {
|
||||||
|
$transcript = trim($transcript);
|
||||||
|
if (!empty($transcript)) {
|
||||||
|
$transcripts[$code] = $transcript;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($transcripts) > 0) {
|
||||||
|
$default_language = $what_did_they_say->get_default_language();
|
||||||
|
|
||||||
|
$output = array();
|
||||||
|
$output[] = '<div class="transcript-bundle">';
|
||||||
|
|
||||||
|
if (count($transcripts) == 1) {
|
||||||
|
list($code, $transcript) = each($transcripts);
|
||||||
|
$output[] = apply_filters('the_language_name', get_the_language_name($code));
|
||||||
|
$output[] = apply_filters('the_media_transcript', $transcript);
|
||||||
|
} else {
|
||||||
|
$output[] = $dropdown_message;
|
||||||
|
$output[] = '<select>';
|
||||||
|
foreach($transcripts as $code => $transcript) {
|
||||||
|
$output[] = '<option value="' . $code . '"' . (($code == $default_language) ? ' selected="selected"' : '') . '>'
|
||||||
|
. get_the_language_name($code)
|
||||||
|
. '</option>';
|
||||||
|
}
|
||||||
|
$output[] = '</select>';
|
||||||
|
foreach ($transcripts as $code => $transcript) {
|
||||||
|
$language_name = apply_filters('the_language_name', get_the_language_name($code));
|
||||||
|
$transcript = apply_filters('the_media_transcript', $transcript);
|
||||||
|
|
||||||
|
$output[] = '<div '
|
||||||
|
. (($code == $default_language) ? 'style="display:none"' : '')
|
||||||
|
. ' class="transcript-holder ' . $code . '">' . $language_name . $transcript . '</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$output[] = '</div>';
|
||||||
|
|
||||||
|
$output = apply_filters('the_media_transcript_select_and_display', implode("\n", $output));
|
||||||
|
echo $output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue