diff --git a/classes/WhatDidTheySay.php b/classes/WhatDidTheySay.php index fb911e1..7b5cde4 100644 --- a/classes/WhatDidTheySay.php +++ b/classes/WhatDidTheySay.php @@ -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; + } + } } ?> diff --git a/classes/WhatDidTheySayAdmin.php b/classes/WhatDidTheySayAdmin.php index a7880b8..bbfdc40 100644 --- a/classes/WhatDidTheySayAdmin.php +++ b/classes/WhatDidTheySayAdmin.php @@ -29,6 +29,9 @@ class WhatDidTheySayAdmin { $this->language_file = dirname(__FILE__) . '/../data/lsr-language.txt'; } + /** + * Initialize the object. + */ function init() { $this->capabilities = array( 'submit_transcriptions' => __('Submit transcriptions to a post', 'what-did-they-say'), @@ -42,6 +45,10 @@ class WhatDidTheySayAdmin { wp_enqueue_script('prototype'); 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']['_nonce'])) { @@ -54,6 +61,35 @@ class WhatDidTheySayAdmin { $this->read_language_file(); } + function the_media_transcript($transcript) { + return '
' . $transcript . '
'; + } + + function the_language_name($language) { + return '

' . $language . '

'; + } + + function wp_footer() { ?> + + notices)) { echo '
'; - echo implode("
", $this->notices); + foreach ($this->notices as $notice) { echo "

" . $notice . "

"; } echo '
'; } } + /** + * Handle an update to options. + */ function handle_update($info) { - foreach (array( - 'languages', 'capabilities' - ) as $method) { - $result = $this->{"handle_update_${method}"}($info); - if (!empty($result)) { $this->notices[] = $result; } + foreach (get_class_methods($this) as $method) { + if (strpos($method, "handle_update_") === 0) { + $result = $this->{$method}($info); + if (!empty($result)) { $this->notices[] = $result; } + } } } - function handle_update_languages($language_info) { - $options = get_option('what-did-they-say-options'); + function handle_update_post_transcripts($post_transcript_info) { $updated = false; - switch ($language_info['action']) { - case "delete": - $updated = sprintf(__('%s deleted.', 'what-did-they-say'), $options['languages'][$language_info['code']]['name']); - unset($options['languages'][$language_info['code']]); - break; - case "add": - $this->read_language_file(); - if (isset($this->all_languages[$language_info['code']])) { - $options['languages'][$language_info['code']] = array('name' => $this->all_languages[$language_info['code']]); - $updated = sprintf(__('%s added.', 'what-did-they-say'), $this->all_languages[$language_info['code']]); - } - break; - case "default": - if (isset($options['languages'][$language_info['code']])) { - foreach ($options['languages'] as $code => $info) { - if ($code == $language_info['code']) { - $options['languages'][$code]['default'] = true; - $updated = sprintf(__('%s set as default.', 'what-did-they-say'), $info['name']); - } else { - unset($options['languages'][$code]['default']); + 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) { + $updated = false; + if (current_user_can('change_languages')) { + $options = get_option('what-did-they-say-options'); + switch ($language_info['action']) { + case "delete": + $updated = sprintf(__('%s deleted.', 'what-did-they-say'), $options['languages'][$language_info['code']]['name']); + unset($options['languages'][$language_info['code']]); + break; + case "add": + $this->read_language_file(); + if (isset($this->all_languages[$language_info['code']])) { + $options['languages'][$language_info['code']] = array('name' => $this->all_languages[$language_info['code']]); + $updated = sprintf(__('%s added.', 'what-did-they-say'), $this->all_languages[$language_info['code']]); + } + break; + case "default": + if (isset($options['languages'][$language_info['code']])) { + foreach ($options['languages'] as $code => $info) { + if ($code == $language_info['code']) { + $options['languages'][$code]['default'] = true; + $updated = sprintf(__('%s set as default.', 'what-did-they-say'), $info['name']); + } else { + unset($options['languages'][$code]['default']); + } } } - } - break; - case "rename": - if (isset($options['languages'][$language_info['code']])) { - if (!empty($language_info['name'])) { - $updated = sprintf(__('%1$s renamed to %2$s.', 'what-did-they-say'), $options['languages'][$language_info['code']]['name'], $language_info['name']); - $options['languages'][$language_info['code']]['name'] = $language_info['name']; + break; + case "rename": + if (isset($options['languages'][$language_info['code']])) { + if (!empty($language_info['name'])) { + $updated = sprintf(__('%1$s renamed to %2$s.', 'what-did-they-say'), $options['languages'][$language_info['code']]['name'], $language_info['name']); + $options['languages'][$language_info['code']]['name'] = $language_info['name']; + } } - } - break; - } - ksort($options['languages']); - update_option('what-did-they-say-options', $options); + break; + } + if ($updated !== false) { + ksort($options['languages']); + update_option('what-did-they-say-options', $options); + } + } return $updated; } function handle_update_capabilities($capabilities_info) { - $options = get_option('what-did-they-say-options'); $updated = false; - switch ($capabilities_info['action']) { - case "capabilities": - if (isset($capabilities_info['capabilities'])) { - foreach (array_keys($this->default_options['capabilities']) as $capability) { - if (isset($capabilities_info['capabilities'][$capability])) { - $options['capabilities'][$capability] = $capabilities_info['capabilities'][$capability]; + if (current_user_can('edit_users')) { + $options = get_option('what-did-they-say-options'); + switch ($capabilities_info['action']) { + case "capabilities": + if (isset($capabilities_info['capabilities'])) { + foreach (array_keys($this->default_options['capabilities']) as $capability) { + if (isset($capabilities_info['capabilities'][$capability])) { + $options['capabilities'][$capability] = $capabilities_info['capabilities'][$capability]; + } } + $updated = __('User capabilities updated', 'what-did-they-say'); } - $updated = __('User capabilities updated', 'what-did-they-say'); - } - break; - } - update_option('what-did-they-say-options', $options); - 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; } + if ($updated !== false) { + update_option('what-did-they-say-options', $options); + } } - - $options = array_merge(get_option('what-did-they-say-options'), $updated_options); - update_option('what-did-they-say-options', $options); + return $updated; } function read_language_file() { diff --git a/classes/meta-box.inc b/classes/meta-box.inc index ae3d196..c95cf22 100644 --- a/classes/meta-box.inc +++ b/classes/meta-box.inc @@ -1,5 +1,6 @@ - - + + +

'; + + 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[] = ''; + 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[] = '
' . $language_name . $transcript . '
'; + } + } + $output[] = '
'; + + $output = apply_filters('the_media_transcript_select_and_display', implode("\n", $output)); + echo $output; + } +} + ?> \ No newline at end of file