From 11f152a2ec816376d87999f0beda5ca897c468bf Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 28 Sep 2009 21:54:02 -0400 Subject: [PATCH] lots of cleanup on user submitted transcripts --- classes/WDTSTranscript.inc | 27 +++++++ classes/WhatDidTheySayAdmin.inc | 68 +++++++++++++---- .../partials/_display-queued-transcript.inc | 3 + .../partials/_queued-transcript-contents.inc | 19 +++++ classes/partials/meta-box.inc | 35 +++------ css/wdts-admin.css | 4 + js/edit-transcripts.js | 76 ++++++++++++++++--- test/WDTSTranscriptTest.php | 34 +++++++++ what-did-they-say.php | 8 ++ 9 files changed, 225 insertions(+), 49 deletions(-) create mode 100644 classes/partials/_display-queued-transcript.inc create mode 100644 classes/partials/_queued-transcript-contents.inc diff --git a/classes/WDTSTranscript.inc b/classes/WDTSTranscript.inc index 6f841e1..6ce73c1 100644 --- a/classes/WDTSTranscript.inc +++ b/classes/WDTSTranscript.inc @@ -77,6 +77,26 @@ class WDTSTranscriptManager { return false; } + function update_transcript($info) { + if (isset($info['key'])) { + if (($transcripts = $this->_get_transcripts_metadata()) !== false) { + $new_transcripts = array(); + foreach ($transcripts as $transcript) { + if ($transcript['key'] == $info['key']) { + foreach (array('transcript') as $field) { + if (isset($info[$field])) { + $transcript[$field] = $info[$field]; + } + } + } + $new_transcripts[] = $transcript; + } + + return update_post_meta($this->post_id, $this->key, $new_transcripts); + } + } + } + function _update_search_field($transcripts) { if (!empty($this->search_key)) { $search_lines = array(); @@ -136,6 +156,13 @@ class WDTSTranscriptManager { return $user_transcripts; } + function get_transcript_by_key($key) { + foreach ($this->get_transcripts() as $transcript) { + if ($transcript['key'] == $key) { return $transcript; } + } + return false; + } + function get_languages() { $languages = array(); if (($transcripts = $this->_get_transcripts_metadata()) !== false) { diff --git a/classes/WhatDidTheySayAdmin.inc b/classes/WhatDidTheySayAdmin.inc index 09e2acb..a7ccae7 100644 --- a/classes/WhatDidTheySayAdmin.inc +++ b/classes/WhatDidTheySayAdmin.inc @@ -72,7 +72,18 @@ class WhatDidTheySayAdmin { if ($options['automatic_embedding']) { add_filter('the_content', array(&$this, 'the_content_automatic_embedding'), 15); } - + + foreach (get_class_methods($this) as $method) { + if (strpos($method, "shortcode_") === 0) { + $shortcode_name = str_replace("_", "-", str_replace("shortcode_", "", $method)); + add_shortcode($shortcode_name, array(&$this, $method)); + } + } + + add_filter('filter_shortcode_dialog', array(&$this, 'filter_shortcode_dialog'), 10, 4); + add_filter('filter_shortcode_scene_action', array(&$this, 'filter_shortcode_scene_action'), 10, 2); + add_filter('filter_shortcode_scene_heading', array(&$this, 'filter_shortcode_scene_heading'), 10, 2); + if (isset($_REQUEST['wdts'])) { if (isset($_REQUEST['wdts']['_nonce'])) { if (wp_verify_nonce($_REQUEST['wdts']['_nonce'], 'what-did-they-say')) { @@ -137,19 +148,9 @@ class WhatDidTheySayAdmin { if (current_user_can('submit_transcriptions')) { wp_enqueue_script('scriptaculous-effects'); wp_enqueue_script('edit-transcript', plugin_dir_url(dirname(__FILE__)) . 'js/edit-transcripts.js', array('scriptaculous-effects'), false, true); + wp_enqueue_style('wdts-admin', plugin_dir_url(dirname(__FILE__)) . 'css/wdts-admin.css'); } - foreach (get_class_methods($this) as $method) { - if (strpos($method, "shortcode_") === 0) { - $shortcode_name = str_replace("_", "-", str_replace("shortcode_", "", $method)); - add_shortcode($shortcode_name, array(&$this, $method)); - } - } - - add_filter('filter_shortcode_dialog', array(&$this, 'filter_shortcode_dialog'), 10, 4); - add_filter('filter_shortcode_scene_action', array(&$this, 'filter_shortcode_scene_action'), 10, 2); - add_filter('filter_shortcode_scene_heading', array(&$this, 'filter_shortcode_scene_heading'), 10, 2); - $options = get_option('what-did-they-say-options'); if (!empty($options['load_default_styles'])) { wp_enqueue_style('wdts-defaults', plugin_dir_url(dirname(__FILE__)) . 'css/wdts-defaults.css'); @@ -353,6 +354,27 @@ class WhatDidTheySayAdmin { return $updated; } + function handle_update_update_queued_transcript($info) { + $this->is_ajax = true; + + if ($this->current_user_can_edit_this_transcript($info['post_id'], $info['key'])) { + $queued_transcript_manager = new WDTSQueuedTranscript($info['post_id']); + $queued_transcript_manager->update_transcript($info); + + $post = get_post($info['post_id']); + + $language_options = new WDTSLanguageOptions(); + $transcript_options = new WDTSTranscriptOptions($post->ID); + + $transcript = $queued_transcript_manager->get_transcript_by_key($info['key']); + $user = wp_get_current_user(); + + include(dirname(__FILE__) . '/partials/_queued-transcript-contents.inc'); + return; + } + header('HTTP/1.1 401 Unauthorized'); + } + /** * Handle updates to post transcripts. * @param array $info The part of the $_POST array for What Did They Say?!? @@ -412,13 +434,33 @@ class WhatDidTheySayAdmin { header('HTTP/1.1 401 Unauthorized'); } + function current_user_can_edit_this_transcript($post_id, $transcript_id) { + if (current_user_can('approve_transcriptions')) { + $ok = true; + } else { + $ok = false; + if (current_user_can('submit_transcriptions')) { + $queued_transcript_manager = new WDTSQueuedTranscript($post_id); + $user = wp_get_current_user(); + + $transcripts = $queued_transcript_manager->get_transcripts_for_user($user->ID); + foreach ($transcripts as $transcript) { + if ($transcript['key'] == $transcript_id) { + $ok = true; break; + } + } + } + } + return $ok; + } + /** * Handle transcript deletion. */ function handle_update_delete_transcript($info) { $this->is_ajax = true; - if (current_user_can('approve_transcriptions')) { + if ($this->current_user_can_edit_this_transcript($info['post_id'], $info['key'])) { $queued_transcript_manager = new WDTSQueuedTranscript($info['post_id']); if (($transcript = $queued_transcript_manager->delete_transcript_by_key($info['key'])) !== false) { diff --git a/classes/partials/_display-queued-transcript.inc b/classes/partials/_display-queued-transcript.inc new file mode 100644 index 0000000..2070bf3 --- /dev/null +++ b/classes/partials/_display-queued-transcript.inc @@ -0,0 +1,3 @@ +
+ +
diff --git a/classes/partials/_queued-transcript-contents.inc b/classes/partials/_queued-transcript-contents.inc new file mode 100644 index 0000000..fb62c92 --- /dev/null +++ b/classes/partials/_queued-transcript-contents.inc @@ -0,0 +1,19 @@ + + + +

%s in %s:', 'what-did-they-say'), + $user->display_name, + $language_options->get_language_name($transcript['language']) + ) +?>

+
+ + diff --git a/classes/partials/meta-box.inc b/classes/partials/meta-box.inc index 14a9421..f896411 100644 --- a/classes/partials/meta-box.inc +++ b/classes/partials/meta-box.inc @@ -9,29 +9,12 @@

- - -
- - -

%s in %s:', 'what-did-they-say'), - $user->display_name, - $language_options->get_language_name($transcript['language']) - ) - ?>

-
- -
- Approve - Delete -
-
- - +

- - - + + + assertEquals(array('en', 'fr'), $this->w->get_languages()); } + + function testUpdateTranscript() { + update_post_meta(1, $this->w->key, + array( + array( + 'language' => 'en', + 'transcript' => 'this is a transcript', + 'user_id' => 1, + 'key' => 0 + ) + ) + ); + + $info = array( + 'key' => 0, + 'user_id' => 1, + 'transcript' => 'hiss hiss hiss', + 'language' => 'fr' + ); + + $this->w->update_transcript($info); + + $this->assertEquals( + array( + array( + 'language' => 'en', + 'transcript' => 'hiss hiss hiss', + 'user_id' => 1, + 'key' => 0 + ) + ), + get_post_meta(1, $this->w->key, true) + ); + } } ?> \ No newline at end of file diff --git a/what-did-they-say.php b/what-did-they-say.php index 8bce213..4ab3b1d 100644 --- a/what-did-they-say.php +++ b/what-did-they-say.php @@ -221,6 +221,14 @@ function the_media_transcript_queue_editor() { + 0) && !current_user_can('approve_transcriptions')) { ?> +

+ + are_new_transcripts_allowed()) { ?>