diff --git a/classes/WDTSLanguageOptions.php b/classes/WDTSLanguageOptions.php index c60410c..ff1a3ce 100644 --- a/classes/WDTSLanguageOptions.php +++ b/classes/WDTSLanguageOptions.php @@ -12,7 +12,9 @@ class WDTSLanguageOptions { $options = get_option($this->key); foreach ($options['languages'] as $code => $info) { if (is_null($language)) { $language = $code; } - if ($info['default']) { $language = $code; break; } + if (isset($info['default'])) { + if ($info['default']) { $language = $code; break; } + } } return $language; } diff --git a/classes/WDTSTranscript.php b/classes/WDTSTranscript.php index 006e7fd..73cd2e8 100644 --- a/classes/WDTSTranscript.php +++ b/classes/WDTSTranscript.php @@ -3,6 +3,7 @@ class WDTSTranscriptManager { var $key = null; var $post_id = null; + var $allow_multiple = false; function __construct($post_id = null) { if (is_numeric($post_id)) { $this->post_id = $post_id; } @@ -36,36 +37,63 @@ class WDTSTranscriptManager { if (!empty($user)) { $transcript_info = (array)$transcript_info; $transcript_info['user_id'] = $user->ID; + unset($transcript_info['key']); - if (($transcripts = $this->_get_transcripts_metadata()) !== false) { - $new_transcripts = array(); - $was_added = false; + if (($transcripts = $this->_get_transcripts_metadata()) !== false) { + $max_key = 0; foreach ($transcripts as $transcript) { - if ($transcript['language'] == $transcript_info['language']) { - $was_added = true; - $new_transcripts[] = $transcript_info; - } else { - $new_transcripts[] = $transcript; - } + $max_key = max($max_key, $transcript['key']) + 1; } - 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; } 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) { $new_transcripts = array(); + $deleted_transcript = false; 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() { diff --git a/classes/WDTSTranscriptClasses.php b/classes/WDTSTranscriptClasses.php index 1b16444..177c64a 100644 --- a/classes/WDTSTranscriptClasses.php +++ b/classes/WDTSTranscriptClasses.php @@ -2,7 +2,13 @@ require_once('WDTSTranscript.php'); -class WDTSQueuedTranscript extends WDTSTranscriptManager { var $key = "queued_transcripts"; } -class WDTSApprovedTranscript extends WDTSTranscriptManager { var $key = "approved_transcripts"; } +class WDTSQueuedTranscript extends WDTSTranscriptManager { + var $key = "queued_transcripts"; + var $allow_multiple = true; +} + +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 eb9ca55..8aa7b11 100644 --- a/classes/WDTSTranscriptOptions.php +++ b/classes/WDTSTranscriptOptions.php @@ -26,15 +26,15 @@ class WDTSTranscriptOptions { } 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; + $current_options = get_post_meta($this->post_id, "transcript_options", true); + if (!is_array($current_options)) { $current_options = array(); } + return $current_options; } 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); + $current_options[$option] = $value; + update_post_meta($this->post_id, "transcript_options", $current_options); } } diff --git a/classes/WhatDidTheySayAdmin.php b/classes/WhatDidTheySayAdmin.php index 285a3d7..9226b1b 100644 --- a/classes/WhatDidTheySayAdmin.php +++ b/classes/WhatDidTheySayAdmin.php @@ -25,6 +25,8 @@ class WhatDidTheySayAdmin { var $all_languages = array(); var $notices = array(); + var $is_ajax = false; + /** * Initialize the admin interface. * @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_notices', array(&$this, 'admin_notices')); - add_action('admin_init', array(&$this, 'admin_init')); wp_enqueue_script('prototype'); @@ -53,24 +54,27 @@ 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')); + add_filter('template_redirect', array(&$this, 'template_redirect')); if (isset($_REQUEST['wdts'])) { if (isset($_REQUEST['wdts']['_nonce'])) { if (wp_verify_nonce($_REQUEST['wdts']['_nonce'], 'what-did-they-say')) { $this->handle_update($_REQUEST['wdts']); + + if ($this->is_ajax) { exit(0); } } } } $this->read_language_file(); + + if (current_user_can('submit_transcriptions')) { + wp_enqueue_script('scriptaculous-effects'); + } } - /** - * Handle admin_init action. - */ - function admin_init() { - wp_enqueue_script('scriptaculous-effects'); + function template_redirect() { + wp_enqueue_script('toggle-transcript', plugin_dir_url(dirname(__FILE__)) . 'toggle-transcript.js', array('prototype'), false, true); } /** @@ -90,27 +94,6 @@ class WhatDidTheySayAdmin { function the_language_name($language) { return '
user_id); + $user = get_userdata($transcript['user_id']); if (!empty($user)) { ?>
%s in %s:', 'what-did-they-say'), $user->display_name, - $this->what_did_they_say->get_language_name($transcript->language) + $language_options->get_language_name($transcript['language']) ) ?>
-