working on metabox

This commit is contained in:
John Bintz 2009-09-10 21:20:01 -04:00
parent 2dcd244cf8
commit 497a1ac3b5
4 changed files with 57 additions and 50 deletions

View File

@ -20,9 +20,9 @@ class WDTSTranscriptOptions {
* See if the indicated post is accepting new transcripts. * See if the indicated post is accepting new transcripts.
* @return boolean True if the post is acceptin new transcripts. * @return boolean True if the post is acceptin new transcripts.
*/ */
function get_allow_transcripts() { function are_new_transcripts_allowed() {
$options = $this->_get_transcript_options(); $options = $this->_get_transcript_options();
return issset($options['allow_transcripts']) ? $options['allow_transcripts'] : false; return isset($options['allow_transcripts']) ? $options['allow_transcripts'] : false;
} }
function _get_transcript_options() { function _get_transcript_options() {

View File

@ -194,43 +194,39 @@ class WhatDidTheySayAdmin {
* @param array $info The part of the $_POST array for What Did They Say?!? * @param array $info The part of the $_POST array for What Did They Say?!?
* @return string|false A string if a message is to be displayed, or false if no message. * @return string|false A string if a message is to be displayed, or false if no message.
*/ */
function handle_update_post_transcripts($info) { function handle_update_manage_post_transcripts($info) {
$updated = false; $updated = false;
if (current_user_can('approve_transcriptions')) { if (current_user_can('approve_transcriptions')) {
$options = get_option('what-did-they-say-options'); $options = get_option('what-did-they-say-options');
switch ($info['action']) { $approved_transcript_manager = new WDTSApprovedTranscript($info['post_id']);
case "manage_post_transcripts":
foreach ($info['transcripts'] as $language => $transcript) {
switch ($language) {
case "_allow":
$allow = true;
break;
default:
$this->what_did_they_say->save_transcript($info['post_id'], $language, $transcript);
break;
}
}
$this->what_did_they_say->set_allow_transcripts_for_post($info['post_id'], isset($info['allow_on_post'])); foreach ($info['transcripts'] as $language => $transcript) {
$approved_transcript_manager->save_transcript(array(
$queued_transcriptions = $this->what_did_they_say->get_queued_transcriptions_for_post($info['post_id']); 'language' => $language,
if (is_array($queued_transcriptions)) { 'transcript' => $transcript
$transcriptions_to_delete = array(); ));
foreach ($queued_transcriptions as $transcription) { $transcriptions_to_delete[$transcription->id] = true; }
if (isset($post_transcript_info['queue'])) {
foreach ($post_transcript_info['queue'] as $id => $keep) { unset($transcriptions_to_delete[$id]); }
}
foreach (array_keys($transcriptions_to_delete) as $id) {
$this->what_did_they_say->delete_queued_transcription($id);
}
}
$updated = __('Transcripts updated.', 'what-did-they-say');
break;
} }
$transcript_options = new WDTSTranscriptOptions($info['post_id']);
$transcript_options->set_allow_transcripts(isset($info['allow_on_post']));
$queued_transcriptions = $this->what_did_they_say->get_queued_transcriptions_for_post($info['post_id']);
if (is_array($queued_transcriptions)) {
$transcriptions_to_delete = array();
foreach ($queued_transcriptions as $transcription) { $transcriptions_to_delete[$transcription->id] = true; }
if (isset($post_transcript_info['queue'])) {
foreach ($post_transcript_info['queue'] as $id => $keep) { unset($transcriptions_to_delete[$id]); }
}
foreach (array_keys($transcriptions_to_delete) as $id) {
$this->what_did_they_say->delete_queued_transcription($id);
}
}
$updated = __('Transcripts updated.', 'what-did-they-say');
break;
} }
return $updated; return $updated;
} }
@ -422,9 +418,13 @@ class WhatDidTheySayAdmin {
$options = get_option('what-did-they-say-options'); $options = get_option('what-did-they-say-options');
$transcripts = $this->what_did_they_say->get_transcripts($post->ID); foreach (array('Approved', 'Queued') as $name) {
$queued_transcriptions = $this->what_did_they_say->get_queued_transcriptions_for_post($post->ID); $var_name = strtolower($name);
$class_name = "WDTS${name}Transcript";
${"${var_name}_transcript_manager"} = new $class_name($post->ID);
${"${var_name}_transcripts"} = ${"${var_name}_transcript_manager"}->get_transcripts();
}
$nonce = wp_create_nonce('what-did-they-say'); $nonce = wp_create_nonce('what-did-they-say');
include(dirname(__FILE__) . '/meta-box.inc'); include(dirname(__FILE__) . '/meta-box.inc');
} }

View File

@ -1,5 +1,5 @@
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" /> <input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[action]" value="manage_post_transcripts" /> <input type="hidden" name="wdts[module]" value="manage-post-transcripts" />
<input type="hidden" name="wdts[post_id]" value="<?php echo $post->ID ?>" /> <input type="hidden" name="wdts[post_id]" value="<?php echo $post->ID ?>" />
<p> <p>
<label> <label>
@ -7,24 +7,24 @@
<?php _e('Allow new transcripts to be submitted for this post', 'what-did-they-say') ?> <?php _e('Allow new transcripts to be submitted for this post', 'what-did-they-say') ?>
</label> </label>
</p> </p>
<?php if (is_array($queued_transcriptions) && !empty($queued_transcriptions)) { ?> <?php if (is_array($queued_transcripts) && !empty($queued_transcripts)) { ?>
<p><strong><?php _e('Manage queued transcripts:', 'what-did-they-say') ?></strong></p> <p><strong><?php _e('Manage queued transcripts:', 'what-did-they-say') ?></strong></p>
<?php foreach ($queued_transcriptions as $transcription) { <?php foreach ($queued_transcripts as $transcript) {
$user = get_userdata($transcription->user_id); $user = get_userdata($transcript->user_id);
if (!empty($user)) { ?> if (!empty($user)) { ?>
<div class="queued-transcription-holder"> <div class="queued-transcription-holder">
<input type="hidden" name="wdts[queue][<?php echo $transcription->id ?>]" value="keep" /> <input type="hidden" name="wdts[queue][<?php echo $transcript->id ?>]" value="keep" />
<input type="hidden" name="wdts[language][<?php echo $transcription->id ?>]" value="<?php echo $transcription->language ?>" /> <input type="hidden" name="wdts[language][<?php echo $transcript->id ?>]" value="<?php echo $transcript->language ?>" />
<p><?php <p><?php
printf( printf(
__('From <strong>%s</strong> in <strong>%s</strong>:', 'what-did-they-say'), __('From <strong>%s</strong> in <strong>%s</strong>:', 'what-did-they-say'),
$user->display_name, $user->display_name,
$this->what_did_they_say->get_language_name($transcription->language) $this->what_did_they_say->get_language_name($transcript->language)
) )
?></p> ?></p>
<div class="queued-transcription"><?php echo $transcription->transcript ?></div> <div class="queued-transcription"><?php echo $transcript->transcript ?></div>
<div class="queued-transcription-raw" style="display:none"><?php echo $transcription->transcript ?></div> <div class="queued-transcription-raw" style="display:none"><?php echo $transcript->transcript ?></div>
<div style="padding: 10px 0"> <div style="padding: 10px 0">
<a href="#" class="approve-transcript button">Approve</a> <a href="#" class="approve-transcript button">Approve</a>
<a href="#" class="delete-transcript button">Delete</a> <a href="#" class="delete-transcript button">Delete</a>
@ -44,7 +44,7 @@
</label> </label>
<?php foreach (array_keys($options['languages']) as $code) { ?> <?php foreach (array_keys($options['languages']) as $code) { ?>
<textarea class="transcript" id="wdts-transcripts-<?php echo $code ?>" name="wdts[transcripts][<?php echo $code ?>]" style="display: none; width: 100%; height: 200px"><?php echo $transcripts[$code] ?></textarea> <textarea class="transcript" id="wdts-transcripts-<?php echo $code ?>" name="wdts[transcripts][<?php echo $code ?>]" style="display: none; width: 100%; height: 200px"><?php echo $approved_transcripts[$code] ?></textarea>
<?php } ?> <?php } ?>
</p> </p>
<script type="text/javascript"> <script type="text/javascript">

View File

@ -93,7 +93,7 @@ function the_language_name($language = null) {
* @param string $single_language_message If set, the text that appears when only one transcript exists for this post. * @param string $single_language_message If set, the text that appears when only one transcript exists for this post.
*/ */
function transcripts_display($dropdown_message = null, $single_language_message = null) { function transcripts_display($dropdown_message = null, $single_language_message = null) {
global $post, $what_did_they_say; global $post;
if (is_null($dropdown_message)) { $dropdown_message = __('Select a language:', 'what-did-they-say'); } if (is_null($dropdown_message)) { $dropdown_message = __('Select a language:', 'what-did-they-say'); }
if (is_null($single_language_message)) { $single_language_message = __('%s transcript:', 'what-did-they-say'); } if (is_null($single_language_message)) { $single_language_message = __('%s transcript:', 'what-did-they-say'); }
@ -101,7 +101,10 @@ function transcripts_display($dropdown_message = null, $single_language_message
$output = array(); $output = array();
$transcripts = array(); $transcripts = array();
$post_transcripts = $what_did_they_say->get_transcripts($post->ID);
$approved_transcripts = new WDTSApprovedTranscript($post->ID);
$post_transcripts = $approved_transcripts->get_transcripts();
if (!empty($post_transcripts)) { if (!empty($post_transcripts)) {
foreach ($post_transcripts as $code => $transcript) { foreach ($post_transcripts as $code => $transcript) {
if (substr($code, 0, 1) != "_") { if (substr($code, 0, 1) != "_") {
@ -154,11 +157,15 @@ function the_media_transcript_queue_editor() {
if (current_user_can('submit_transcriptions')) { if (current_user_can('submit_transcriptions')) {
$queued_transcripts_for_user = false; $queued_transcripts_for_user = false;
$queued_transcripts = new WDTSQueuedTranscript($post->ID);
$user = wp_get_current_user(); $user = wp_get_current_user();
if (!empty($user)) { if (!empty($user)) {
$queued_transcripts_for_user = $what_did_they_say->get_queued_transcriptions_for_user_and_post($user->ID, $post->ID); $queued_transcripts_for_user = $queued_transcripts->get_transcripts_for_user($user->ID);
} }
$transcript_options = new WDTSTranscriptOptions($post->ID);
if (is_array($queued_transcripts_for_user)) { if (is_array($queued_transcripts_for_user)) {
if (count($queued_transcripts_for_user) > 0) { ?> if (count($queued_transcripts_for_user) > 0) { ?>
<div class="queued-transcriptions"> <div class="queued-transcriptions">
@ -172,7 +179,7 @@ function the_media_transcript_queue_editor() {
</div> </div>
<?php } ?> <?php } ?>
<?php } ?> <?php } ?>
<?php if ($what_did_they_say->get_allow_transcripts_for_post($post->ID)) { ?> <?php if ($transcript_options->are_new_transcripts_allowed()) { ?>
<form method="post" class="transcript-editor"> <form method="post" class="transcript-editor">
<input type="hidden" name="wdts[_nonce]" value="<?php echo wp_create_nonce('what-did-they-say') ?>" /> <input type="hidden" name="wdts[_nonce]" value="<?php echo wp_create_nonce('what-did-they-say') ?>" />
<input type="hidden" name="wdts[action]" value="submit_queued_transcript" /> <input type="hidden" name="wdts[action]" value="submit_queued_transcript" />