From af689daebea44810dd2dad58a3529cc64b8358e1 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 16 Aug 2009 12:26:54 -0400 Subject: [PATCH 1/7] remove unneeded options setting --- classes/WhatDidTheySayAdmin.php | 17 ----------------- test/WhatDidTheySayAdminTest.php | 13 ------------- 2 files changed, 30 deletions(-) diff --git a/classes/WhatDidTheySayAdmin.php b/classes/WhatDidTheySayAdmin.php index a7880b8..66c8c50 100644 --- a/classes/WhatDidTheySayAdmin.php +++ b/classes/WhatDidTheySayAdmin.php @@ -158,23 +158,6 @@ class WhatDidTheySayAdmin { 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() { if (file_exists($this->language_file)) { foreach (file($this->language_file, FILE_IGNORE_NEW_LINES) as $language) { diff --git a/test/WhatDidTheySayAdminTest.php b/test/WhatDidTheySayAdminTest.php index a7ffa5d..108b3ed 100644 --- a/test/WhatDidTheySayAdminTest.php +++ b/test/WhatDidTheySayAdminTest.php @@ -59,19 +59,6 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase { $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() { $admin = new WhatDidTheySayAdmin(); $admin->all_languages = array( From f962cc2436aceb06b3ac1e56ae2073de9f5533bf Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 16 Aug 2009 12:29:25 -0400 Subject: [PATCH 2/7] make update method call handling more dynamic --- classes/WhatDidTheySayAdmin.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/classes/WhatDidTheySayAdmin.php b/classes/WhatDidTheySayAdmin.php index 66c8c50..3933316 100644 --- a/classes/WhatDidTheySayAdmin.php +++ b/classes/WhatDidTheySayAdmin.php @@ -90,11 +90,11 @@ class WhatDidTheySayAdmin { } 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; } + } } } From 3a0d0572d53de331d382f5eafa4ffcb29e7c4864 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 16 Aug 2009 12:40:54 -0400 Subject: [PATCH 3/7] basic transcription saving working --- classes/WhatDidTheySayAdmin.php | 117 +++++++++++++++++++------------- classes/meta-box.inc | 5 +- 2 files changed, 74 insertions(+), 48 deletions(-) diff --git a/classes/WhatDidTheySayAdmin.php b/classes/WhatDidTheySayAdmin.php index 3933316..3e3217d 100644 --- a/classes/WhatDidTheySayAdmin.php +++ b/classes/WhatDidTheySayAdmin.php @@ -84,7 +84,7 @@ class WhatDidTheySayAdmin { function admin_notices() { if (!empty($this->notices)) { echo '
'; - echo implode("
", $this->notices); + foreach ($this->notices as $notice) { echo "

" . $notice . "

"; } echo '
'; } } @@ -98,63 +98,88 @@ class WhatDidTheySayAdmin { } } - 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; + break; + } + if ($updated !== false) { + update_option('what-did-they-say-options', $options); + } } - update_option('what-did-they-say-options', $options); return $updated; } 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 @@ - - + + +

'; @@ -89,6 +92,9 @@ class WhatDidTheySayAdmin { } } + /** + * Handle an update to options. + */ function handle_update($info) { foreach (get_class_methods($this) as $method) { if (strpos($method, "handle_update_") === 0) { From 1fa6c57221eff801f70eab1bc41ba325e4a2d6f2 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 16 Aug 2009 14:20:37 -0400 Subject: [PATCH 6/7] working on template tags --- classes/WhatDidTheySayAdmin.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/classes/WhatDidTheySayAdmin.php b/classes/WhatDidTheySayAdmin.php index c6f1658..f8b1b75 100644 --- a/classes/WhatDidTheySayAdmin.php +++ b/classes/WhatDidTheySayAdmin.php @@ -45,6 +45,8 @@ 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')); if (isset($_REQUEST['wdts'])) { if (isset($_REQUEST['wdts']['_nonce'])) { @@ -57,6 +59,14 @@ class WhatDidTheySayAdmin { $this->read_language_file(); } + function the_media_transcript($transcript) { + return '
' . $transcript . '
'; + } + + function the_language_name($language) { + return '

' . $language . '

'; + } + /** * user_has_cap filter. */ From 6622b88dfef12729c4b1423ce598f07e4ac14d53 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 16 Aug 2009 16:15:01 -0400 Subject: [PATCH 7/7] language selector working --- classes/WhatDidTheySayAdmin.php | 22 ++++++++++++++- what-did-they-say.php | 49 +++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/classes/WhatDidTheySayAdmin.php b/classes/WhatDidTheySayAdmin.php index f8b1b75..bbfdc40 100644 --- a/classes/WhatDidTheySayAdmin.php +++ b/classes/WhatDidTheySayAdmin.php @@ -48,6 +48,8 @@ class WhatDidTheySayAdmin { 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'])) { if (wp_verify_nonce($_REQUEST['wdts']['_nonce'], 'what-did-they-say')) { @@ -66,7 +68,25 @@ class WhatDidTheySayAdmin { function the_language_name($language) { return '

' . $language . '

'; } - + + function wp_footer() { ?> + + 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[] = '
'; + + 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