diff --git a/classes/WDTSLanguageOptions.php b/classes/WDTSLanguageOptions.php index 641820c..c60410c 100644 --- a/classes/WDTSLanguageOptions.php +++ b/classes/WDTSLanguageOptions.php @@ -17,6 +17,30 @@ class WDTSLanguageOptions { return $language; } + function set_default_language($language) { + $options = get_option($this->key); + + if (isset($options['languages'][$language])) { + $ok = true; + if (isset($options['languages'][$language]['default'])) { + $ok = !$options['languages'][$language]['default']; + } + if ($ok) { + $updated_languages = array(); + foreach ($options['languages'] as $code => $info) { + unset($info['default']); + if ($code == $language) { $info['default'] = true; } + $updated_languages[$code] = $info; + } + $options['languages'] = $updated_languages; + update_option($this->key, $options); + + return true; + } + } + return false; + } + /** * Get the name of a language from the language code. * @param string $language The language code to search for. @@ -49,6 +73,7 @@ class WDTSLanguageOptions { if (isset($options['languages'][$code_to_delete])) { $did_delete = $options['languages'][$code_to_delete]; unset($options['languages'][$code_to_delete]); + ksort($options['languages']); } update_option($this->key, $options); @@ -63,11 +88,12 @@ class WDTSLanguageOptions { if (!isset($options['languages'][$code])) { if (!empty($info['name'])) { $options['languages'][$code] = $info; + ksort($options['languages']); $result = true; } } } - + update_option($this->key, $options); return $result; } @@ -86,6 +112,7 @@ class WDTSLanguageOptions { $new_languages[$code] = $info; } $options['languages'] = $new_languages; + ksort($options['languages']); update_option($this->key, $options); } diff --git a/classes/WDTSTranscriptClasses.php b/classes/WDTSTranscriptClasses.php index c79618e..1b16444 100644 --- a/classes/WDTSTranscriptClasses.php +++ b/classes/WDTSTranscriptClasses.php @@ -2,7 +2,7 @@ require_once('WDTSTranscript.php'); -class WDTSQueuedTranscript extends WDTSTranscript { var $key = "queued_transcripts"; } -class WDTSApprovedTranscript extends WDTSTranscript { var $key = "approved_transcripts"; } +class WDTSQueuedTranscript extends WDTSTranscriptManager { var $key = "queued_transcripts"; } +class WDTSApprovedTranscript extends WDTSTranscriptManager { var $key = "approved_transcripts"; } ?> \ No newline at end of file diff --git a/classes/WDTSTranscriptOptions.php b/classes/WDTSTranscriptOptions.php index e12917e..109389b 100644 --- a/classes/WDTSTranscriptOptions.php +++ b/classes/WDTSTranscriptOptions.php @@ -14,20 +14,27 @@ class WDTSTranscriptOptions { * @param int $post_id The post ID to affect. * @param boolean $allow True if the post can accept new queued transcriptions. */ - function set_allow_transcripts_for_post($post_id, $allow = true) { - $current_transcripts = get_post_meta($post_id, "transcript_options", true); - if (!is_array - $current_transcripts['_allow'] = $allow; - update_post_meta($post_id, "provided_transcripts", $current_transcripts); - } + function set_allow_transcripts($allow = true) { $this->_update_option('allow_transcripts', $allow); } /** * See if the indicated post is accepting new transcripts. * @return boolean True if the post is acceptin new transcripts. */ - function get_allow_transcripts_for_post($post_id) { - $current_transcripts = get_post_meta($post_id, "provided_transcripts", true); - return $current_transcripts['_allow']; + function get_allow_transcripts() { + $options = $this->_get_transcript_options(); + return issset($options['allow_transcripts']) ? $options['allow_transcripts'] : false; + } + + function _get_transcript_options() { + $current_transcripts = get_post_meta($this->post_id, "transcript_options", true); + if (!is_array($current_transcripts)) { $current_transcripts = array(); } + return $current_transcripts; + } + + function _update_option($option, $value) { + $current_options = $this->_get_transcript_options(); + $current_transcripts[$option] = $value; + update_post_meta($this->post_id, "transcript_options", $current_transcripts); } } diff --git a/classes/WhatDidTheySayAdmin.php b/classes/WhatDidTheySayAdmin.php index f1616e3..7c9c6e1 100644 --- a/classes/WhatDidTheySayAdmin.php +++ b/classes/WhatDidTheySayAdmin.php @@ -157,11 +157,12 @@ class WhatDidTheySayAdmin { * @param array $info The part of the $_POST array for What Did They Say?!? */ function handle_update($info) { - foreach (get_class_methods($this) as $method) { - if (strpos($method, "handle_update_") === 0) { - $result = $this->{$method}($info); + if (isset($info['module'])) { + $method_name = "handle_update_" . str_replace("-", "_", $info['module']); + if (method_exists($this, $method_name)) { + $result = $this->{$method_name}($info); if (!empty($result)) { $this->notices[] = $result; } - } + } } } @@ -173,9 +174,9 @@ class WhatDidTheySayAdmin { function handle_update_queue_transcript($info) { $updated = false; if (current_user_can('submit_transcriptions')) { - $queued_transcript = new WDTSTranscriptOptions($info['post_id'])); + $queued_transcript = new WDTSTranscriptOptions($info['post_id']); - if ($this->what_did_they_say->get_allow_transcripts_for_post() { + if ($this->what_did_they_say->get_allow_transcripts_for_post()) { switch ($info['action']) { case 'submit_queued_transcript': $result = $this->what_did_they_say->add_queued_transcription_to_post($info['post_id'], $info); @@ -248,35 +249,33 @@ class WhatDidTheySayAdmin { case "delete": if ($result = $language_options->delete_language($info['code'])) { $updated = sprintf(__('%s deleted.', 'what-did-they-say'), $result['name']); + } else { + $updated = sprintf(__('Language not deleted!', 'what-did-they-say')); } break; case "add": $this->read_language_file(); if (isset($this->all_languages[$info['code']])) { - - - $options['languages'][$info['code']] = array('name' => $this->all_languages[$info['code']]); - $updated = sprintf(__('%s added.', 'what-did-they-say'), $this->all_languages[$info['code']]); + if ($language_options->add_language($info['code'], array('name' => $this->all_languages[$info['code']]))) { + $updated = sprintf(__('%s added.', 'what-did-they-say'), $this->all_languages[$info['code']]); + } else { + $updated = sprintf(__('Language not added!', 'what-did-they-say')); + } } break; case "default": - if (isset($options['languages'][$info['code']])) { - foreach ($options['languages'] as $code => $lang_info) { - if ($code == $info['code']) { - $options['languages'][$code]['default'] = true; - $updated = sprintf(__('%s set as default.', 'what-did-they-say'), $lang_info['name']); - } else { - unset($options['languages'][$code]['default']); - } - } + if ($language_options->set_default_language($info['code'])) { + $updated = sprintf(__('%s set as default.', 'what-did-they-say'), $language_options->get_language_name($info['code'])); + } else { + $updated = sprintf(__('Language not set as default!', 'what-did-they-say')); } break; case "rename": - if (isset($options['languages'][$info['code']])) { - if (!empty($info['name'])) { - $updated = sprintf(__('%1$s renamed to %2$s.', 'what-did-they-say'), $options['languages'][$info['code']]['name'], $info['name']); - $options['languages'][$info['code']]['name'] = $info['name']; - } + $original_language_name = $language_options->get_language_name($info['code']); + if ($language_options->rename_language($info['code'], $info['name'])) { + $updated = sprintf(__('%1$s renamed to %2$s.', 'what-did-they-say'), $original_language_name, $info['name']); + } else { + $updated = sprintf(__('Language not renamed!', 'what-did-they-say')); } break; } diff --git a/classes/admin.inc b/classes/admin.inc index be80101..ea74d11 100644 --- a/classes/admin.inc +++ b/classes/admin.inc @@ -37,8 +37,7 @@ - - + @@ -50,17 +49,16 @@ - @@ -69,7 +67,12 @@ - + + + type="submit" + class="button" + value="" /> @@ -84,10 +88,11 @@ -
+
+
- - @@ -77,6 +80,7 @@ +
+
+