diff --git a/classes/WhatDidTheySay.php b/classes/WhatDidTheySay.php index 20bf8fd..9adb933 100644 --- a/classes/WhatDidTheySay.php +++ b/classes/WhatDidTheySay.php @@ -80,7 +80,7 @@ class WhatDidTheySay { if (current_user_can('submit_transcriptions')) { $post = get_post($post_id); if (!empty($post)) { - $query = $wpdb->prepare('SELECT * FROM %s WHERE post_id = %d', $this->table, $post_id); + $query = $wpdb->prepare('SELECT * FROM ' . $this->table . ' WHERE post_id = %d', $post_id); $results = $wpdb->get_results($query); if (!empty($results)) { $valid_results = array(); @@ -104,7 +104,7 @@ class WhatDidTheySay { */ function add_queued_transcription_to_post($post_id, $transcript_info) { global $wpdb; - + if (current_user_can('approve_transcriptions')) { $post = get_post($post_id); if (!empty($post)) { @@ -116,11 +116,11 @@ class WhatDidTheySay { } if ($ok) { extract($transcript_info); - $user = get_userdata($user_id); + $user = wp_get_current_user(); if (!empty($user)) { $query = $wpdb->prepare( - "INSERT INTO %s (post_id, user_id, language, transcript) VALUES (%d, %d, %s, %s)", - $this->table, $post_id, $user_id, $language, $transcript + "INSERT INTO " . $this->table . "(post_id, user_id, language, transcript) VALUES (%d, %d, %s, %s)", + $post_id, $user->ID, $language, $transcript ); return $wpdb->query($query); @@ -141,7 +141,7 @@ class WhatDidTheySay { global $wpdb; if (current_user_can('submit_transcriptions')) { - $query = $wpdb->prepare("SELECT * FROM %s WHERE id = %d", $this->table, $update_info['id']); + $query = $wpdb->prepare("SELECT * FROM " . $this->table . " WHERE id = %d", $update_info['id']); $result = $wpdb->get_results($query); if (is_array($result)) { @@ -151,8 +151,8 @@ class WhatDidTheySay { $result->{$field} = $update_info[$field]; } $query = $wpdb->prepare( - "UPDATE %s SET language = %s, transcript = %s WHERE id = %d", - $this->table, $result->language, $result->transcript, $result->id + "UPDATE " . $this->table . " SET language = %s, transcript = %s WHERE id = %d", + $result->language, $result->transcript, $result->id ); $wpdb->query($query); return true; @@ -171,9 +171,9 @@ class WhatDidTheySay { global $wpdb; if (current_user_can('submit_transcriptions')) { - $query = $wpdb->prepare("SELECT id FROM %s WHERE id = %d", $this->table, $transcription_id); + $query = $wpdb->prepare("SELECT id FROM " . $this->table . " WHERE id = %d", $transcription_id); if (!is_null($wpdb->get_var($query))) { - $query = $wpdb->prepare("DELETE FROM %s WHERE id = %d", $this->table, $transcription_id); + $query = $wpdb->prepare("DELETE FROM " . $this->table . " WHERE id = %d", $transcription_id); $wpdb->query($query); return true; @@ -186,7 +186,7 @@ class WhatDidTheySay { global $wpdb; if (current_user_can('approve_transcriptions')) { - $query = $wpdb->prepare("SELECT * from %s WHERE id = %d", $this->table, $transcription_id); + $query = $wpdb->prepare("SELECT * from " . $this->table . " WHERE id = %d", $transcription_id); $result = $wpdb->get_results($query); if (is_array($result)) { if (count($result) == 1) { @@ -196,13 +196,23 @@ class WhatDidTheySay { if (!empty($post)) { $this->save_transcript($result->post_id, $result->language, $result->transcript); - $query = $wpdb->prepare("DELETE FROM %s WHERE id = %d", $this->table, $transcription_id); + $query = $wpdb->prepare("DELETE FROM " . $this->table . " WHERE id = %d", $transcription_id); $result = $wpdb->query($query); } } } } } + + function get_queued_transcriptions_for_user_and_post($user_id, $post_id) { + global $wpdb; + + if (current_user_can('submit_transcriptions')) { + $query = $wpdb->prepare("SELECT * FROM " . $this->table . " WHERE user_id = %d AND post_id = %d", $user_id, $post_id); + return $wpdb->get_results($query); + } + return false; + } function delete_transcript($post_id, $language) { if (current_user_can('approve_transcriptions')) { diff --git a/classes/WhatDidTheySayAdmin.php b/classes/WhatDidTheySayAdmin.php index a0846e3..f8cc24c 100644 --- a/classes/WhatDidTheySayAdmin.php +++ b/classes/WhatDidTheySayAdmin.php @@ -139,7 +139,6 @@ class WhatDidTheySayAdmin { if (current_user_can('submit_transcriptions')) { switch ($queue_transcript_info['action']) { case 'submit_queued_transcript': - var_dump($queue_transcript_info); $result = $this->what_did_they_say->add_queued_transcription_to_post($queue_transcript_info['post_id'], $queue_transcript_info); if ($result) { $updated = __('Transcript added to queue.', 'what-did-they-say'); diff --git a/test/WhatDidTheySayAdminTest.php b/test/WhatDidTheySayAdminTest.php index 108b3ed..ffd6c44 100644 --- a/test/WhatDidTheySayAdminTest.php +++ b/test/WhatDidTheySayAdminTest.php @@ -7,6 +7,7 @@ require_once(dirname(__FILE__) . '/../classes/WhatDidTheySayAdmin.php'); class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase { function setUp() { _reset_wp(); + _set_user_capabilities('submit_transcriptions', 'approve_transcriptions', 'change_languages'); } function testReadLanguageData() { @@ -86,6 +87,7 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase { function testHandleUpdateCapabilities() { $admin = new WhatDidTheySayAdmin(); update_option('what-did-they-say-options', $admin->default_options); + _set_user_capabilities('edit_users'); $admin->handle_update_capabilities(array( 'action' => 'capabilities', diff --git a/test/WhatDidTheySayTest.php b/test/WhatDidTheySayTest.php index 4a27c58..7805f98 100644 --- a/test/WhatDidTheySayTest.php +++ b/test/WhatDidTheySayTest.php @@ -15,7 +15,6 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase { function testSaveTranscription() { wp_insert_post(array('ID' => 1)); - $what = $this->getMock('WhatDidTheySay', array('is_user_allowed_to_update')); $what->save_transcript(1, "en", "This is a transcript"); @@ -110,7 +109,9 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase { wp_insert_user(array('ID' => 1, 'first_name' => 'Test', 'last_name' => 'User')); wp_insert_post(array('ID' => 1)); - $expected_query = sprintf("INSERT INTO '%s' (post_id, user_id, language, transcript) VALUES ('%d', '%d', '%s', '%s')", + wp_set_current_user(1); + + $expected_query = sprintf("INSERT INTO %s (post_id, user_id, language, transcript) VALUES ('%d', '%d', '%s', '%s')", $this->what->table, 1, 1, "en", "This is a transcript"); @@ -120,7 +121,7 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase { ->method('prepare') ->will($this->returnValue($expected_query)); - $what = $this->getMock('WhatDidTheySay', array('is_user_allowed_to_update')); + $what = new WhatDidTheySay(); if ($expected_result === true) { $wpdb->expects($this->once()) @@ -128,11 +129,10 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase { ->with($expected_query) ->will($this->returnValue(true)); } - + $this->assertEquals($expected_result, $what->add_queued_transcription_to_post( 1, array( - 'user_id' => 1, 'language' => 'en', 'transcript' => "This is a transcript" ) diff --git a/what-did-they-say.php b/what-did-they-say.php index a42330d..af28ed6 100644 --- a/what-did-they-say.php +++ b/what-did-they-say.php @@ -116,9 +116,27 @@ function transcripts_display($dropdown_message = null, $single_language_message function the_media_transcript_queue_editor() { global $post, $what_did_they_say; + + $queued_transcripts_for_user = false; + + $user = wp_get_current_user(); + if (!empty($user)) { + $queued_transcripts_for_user = $what_did_they_say->get_queued_transcriptions_for_user_and_post($user->ID, $post->ID); + } if (current_user_can('submit_transcriptions')) { ?> -
+ +
+

+ +

get_language_name($transcript->language) ?>

+
+ transcript ?> +
+ +
+ + @@ -135,7 +153,7 @@ function the_media_transcript_queue_editor() {
- +