ready for some testing

This commit is contained in:
John Bintz 2009-09-13 14:46:02 -04:00
parent b97dd56636
commit 7efbe737f0
8 changed files with 272 additions and 87 deletions

View File

@ -39,6 +39,10 @@ class WDTSTranscriptManager {
$transcript_info['user_id'] = $user->ID; $transcript_info['user_id'] = $user->ID;
unset($transcript_info['key']); unset($transcript_info['key']);
foreach (array_keys($transcript_info) as $key) {
if (strpos($key, "_") === 0) { unset($transcript_info[$key]); }
}
if (($transcripts = $this->_get_transcripts_metadata()) !== false) { if (($transcripts = $this->_get_transcripts_metadata()) !== false) {
$max_key = 0; $max_key = 0;
foreach ($transcripts as $transcript) { foreach ($transcripts as $transcript) {

View File

@ -16,7 +16,8 @@ class WhatDidTheySayAdmin {
'submit_transcriptions' => 'administrator', 'submit_transcriptions' => 'administrator',
'approve_transcriptions' => 'administrator', 'approve_transcriptions' => 'administrator',
'change_languages' => 'administrator' 'change_languages' => 'administrator'
) ),
'load_default_styles' => true
); );
var $capabilities = array(); var $capabilities = array();
@ -45,11 +46,15 @@ class WhatDidTheySayAdmin {
'change_languages' => __('Change the available languages', 'what-did-they-say') 'change_languages' => __('Change the available languages', 'what-did-they-say')
); );
$options = get_option('what-did-they-say-options');
if (!is_array($options)) {
$options = $this->default_options;
update_option('what-did-they-say-options', $options);
}
add_action('admin_menu', array(&$this, 'admin_menu')); add_action('admin_menu', array(&$this, 'admin_menu'));
add_action('admin_notices', array(&$this, 'admin_notices')); add_action('admin_notices', array(&$this, 'admin_notices'));
wp_enqueue_script('prototype');
add_filter('user_has_cap', array(&$this, 'user_has_cap'), 5, 3); add_filter('user_has_cap', array(&$this, 'user_has_cap'), 5, 3);
add_filter('the_media_transcript', array(&$this, 'the_media_transcript')); add_filter('the_media_transcript', array(&$this, 'the_media_transcript'));
add_filter('the_language_name', array(&$this, 'the_language_name')); add_filter('the_language_name', array(&$this, 'the_language_name'));
@ -63,18 +68,71 @@ class WhatDidTheySayAdmin {
if ($this->is_ajax) { exit(0); } if ($this->is_ajax) { exit(0); }
} }
} }
}
$this->read_language_file();
if (current_user_can('submit_transcriptions')) {
wp_enqueue_script('scriptaculous-effects');
} }
} }
function template_redirect() { function template_redirect() {
wp_enqueue_script('toggle-transcript', plugin_dir_url(dirname(__FILE__)) . 'toggle-transcript.js', array('prototype'), false, true); wp_enqueue_script('toggle-transcript', plugin_dir_url(dirname(__FILE__)) . 'js/toggle-transcript.js', array('prototype'), false, true);
if (current_user_can('submit_transcriptions')) { wp_enqueue_script('scriptaculous-effects'); }
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');
}
}
function shortcode_dialog($atts, $speech) {
extract(shortcode_atts(array(
'name' => 'Nobody',
'direction' => ''
), $atts));
list($content) = apply_filters('filter_shortcode_dialog', "", $name, $direction, $speech);
return $content;
}
function filter_shortcode_dialog($content, $name, $direction, $speech) {
$content = '<div class="dialog"><span class="name">' . $name . '</span>';
if (!empty($direction)) {
$content .= ' <span class="direction">' . $direction . '</span>';
}
$content .= ' <span class="speech">' . $speech . '</span></div>';
return array($content, $name, $direction, $speech);
}
function shortcode_scene_action($atts, $description) {
extract(shortcode_atts(array(), $atts));
list($content) = apply_filters('filter_shortcode_scene_action', "", $description);
return $content;
}
function filter_shortcode_scene_action($content, $description) {
return array('<div class="scene-action">' . $description . '</div>', $description);
}
function shortcode_scene_heading($atts, $description) {
extract(shortcode_atts(array(), $atts));
list($content) = apply_filters('filter_shortcode_scene_heading', "", $description);
return $content;
}
function filter_shortcode_scene_heading($content, $description) {
return array('<div class="scene-heading">' . $description . '</div>', $description);
} }
/** /**
@ -83,7 +141,7 @@ class WhatDidTheySayAdmin {
* @return string The processed transcription text. * @return string The processed transcription text.
*/ */
function the_media_transcript($transcript) { function the_media_transcript($transcript) {
return '<div class="transcript">' . $transcript . '</div>'; return '<div class="transcript">' . do_shortcode($transcript) . '</div>';
} }
/** /**
@ -180,8 +238,6 @@ class WhatDidTheySayAdmin {
function handle_update_manage_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');
$approved_transcript_manager = new WDTSApprovedTranscript($info['post_id']); $approved_transcript_manager = new WDTSApprovedTranscript($info['post_id']);
foreach ($info['transcripts'] as $language => $transcript) { foreach ($info['transcripts'] as $language => $transcript) {
@ -245,6 +301,19 @@ class WhatDidTheySayAdmin {
header('HTTP/1.1 401 Unauthorized'); header('HTTP/1.1 401 Unauthorized');
} }
function handle_update_default_styles($info) {
$updated = false;
if (current_user_can('edit_themes')) {
$options = get_option('what-did-they-say-options');
$options['load_default_styles'] = isset($info['default_styles']);
update_option('what-did-they-say-options', $options);
$updated = __('Default styles option updated.', 'what-did-they-say');
}
return $updated;
}
/** /**
* Handle updates to languages. * Handle updates to languages.
* @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?!?
@ -391,15 +460,21 @@ class WhatDidTheySayAdmin {
/** /**
* Handle admin_menu action. * Handle admin_menu action.
*/ */
function admin_menu() { function admin_menu() {
if (current_user_can('edit_users')) { global $plugin_page;
if (current_user_can('submit_transcriptions')) {
add_options_page( add_options_page(
__('What Did They Say?!? Settings', 'what-did-they-say'), __('What Did They Say?!?', 'what-did-they-say'),
__('What Did They Say?!?', 'what-did-they-say'), __('What Did They Say?!?', 'what-did-they-say'),
'manage_options', 'manage_options',
'manage-wdts', 'manage-wdts',
array(&$this, 'manage_admin') array(&$this, 'manage_admin')
); );
if ($plugin_page == "manage-wdts") { $this->read_language_file(); }
wp_enqueue_script('scriptaculous-effects');
} }
if (current_user_can('approve_transcriptions')) { if (current_user_can('approve_transcriptions')) {
@ -411,6 +486,8 @@ class WhatDidTheySayAdmin {
'normal', 'normal',
'low' 'low'
); );
wp_enqueue_script('scriptaculous-effects');
} }
} }

View File

@ -1,5 +1,39 @@
<div class="wrap"> <div class="wrap">
<h2><?php _e('What Did They Say?!? Settings', 'what-did-they-sahy') ?></h2> <h2><?php _e('What Did They Say?!?', 'what-did-they-sahy') ?></h2>
<?php if (current_user_can('submit_transcriptions')) { ?>
<h3><?php _e('Transcript Shortcodes', 'what-did-they-say') ?></h3>
<p>
<?php _e('Transcripts can be entered either using straight HTML or by using shortcodes built for What Did They Say?!?', 'what-did-they-say') ?>
<?php _e('Using shortcodes will make your transcripts easier to style.', 'what-did-they-say') ?>
<?php _e('The default styles that come with What Did They Say?!? make your transcripts look like a screenplay.', 'what-did-they-say') ?>
</p>
<h4><?php _e('Available Shortcodes', 'what-did-they-say') ?></h4>
<h5><?php _e('[scene-heading]', 'what-did-they-say') ?></h5>
<p><?php _e('The text that indicates a new scene:', 'what-did-they-say') ?></p>
<p>
<?php _e('<code>[scene-heading]Ext. The Old Man\'s House[/scene-heading]</code> becomes:', 'what-did-they-say') ?>
<span style="text-transform: uppercase; font-weight: bold; font-family: 'Courier New'"><?php _e('Ext. The Old Man\'s House', 'what-did-they-say') ?></span>
</p>
<h5><?php _e('[scene-action]', 'what-did-they-say') ?></h5>
<p><?php _e('The text that indicates action taking place in a scene. One usually occurs underneath of a scene heading:', 'what-did-they-say') ?></p>
<p>
<?php _e('<code>[scene-action]John is walking down to the car parked in the driveway.[/scene-action]</code> becomes:', 'what-did-they-say') ?>
<span style="font-family: 'Courier New'"><?php _e('John is walking down to the car parked in the driveway.', 'what-did-they-say') ?></span>
</p>
<h5><?php _e('[dialog]', 'what-did-they-say') ?></h5>
<p><?php _e('The textfor when a character is speaking in a scene:', 'what-did-they-say') ?></p>
<p>
<?php _e('<code>[dialog name="John" direction="(towards the house)"]Hey, where are the keys?[/dialog]</code> becomes:', 'what-did-they-say') ?>
</p>
<div style="width: 300px; border: solid #333 1px; margin: 10px; text-align: center">
<div style="font-family: 'Courier New'; text-transform: uppercase"><?php _e('John', 'what-did-they-say') ?></div>
<div style="font-family: 'Courier New'; margin-bottom: 10px"><?php _e('(towards the house)', 'what-did-they-say') ?></div>
<div style="font-family: 'Courier New'"><?php _e('Hey, where are the keys?', 'what-did-they-say') ?></div>
</div>
<?php } ?>
<?php if (current_user_can('edit_users') && is_array($options)) { ?> <?php if (current_user_can('edit_users') && is_array($options)) { ?>
<form method="post"> <form method="post">
@ -32,79 +66,108 @@
</form> </form>
<?php } ?> <?php } ?>
<?php if (is_array($options)) { ?> <?php if (current_user_can('edit_themes')) { ?>
<h3><?php _e('Languages', 'what-did-they-say') ?></h3> <?php if (is_array($options)) { ?>
<h3><?php _e('Default Styles', 'what-did-they-say') ?></h3>
<form method="post">
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[module]" value="default-styles" />
<label>
<input type="checkbox"
name="wdts[default_styles]"
value="yes"
<?php echo ($options['load_default_styles'] ? 'checked="checked"' : '') ?> /> <?php _e('Include a set of default CSS styles for transcripts.', 'what-did-they-say') ?>
</label>
<input class="button" type="submit" value="<?php _e('Change default styles', 'what-did-they-say') ?>" />
</form>
<p><?php _e('By default, the following styles are used by What Did They Say?!?:', 'what-did-they-say') ?></p>
<ul>
<li><?php _e('<strong>.transcript</strong>: The container for the transcript', 'what-did-they-say') ?></li>
<li><?php _e('<strong>.dialog</strong>: Character dialog', 'what-did-they-say') ?></li>
<li><?php _e('<strong>.name</strong>: The character\'s name', 'what-did-they-say') ?></li>
<li><?php _e('<strong>.direction</strong>: The direction the characters is speaking in/from (off-stage, to another character)', 'what-did-they-say') ?></li>
<li><?php _e('<strong>.scene-heading</strong>: A scene heading', 'what-did-they-say') ?></li>
<li><?php _e('<strong>.scene-action</strong>: Action within a scene', 'what-did-they-say') ?></li>
</ul>
<?php } ?>
<?php } ?>
<table class="widefat fixed"> <?php if (current_user_can('change_languages')) { ?>
<tr class="thead"> <?php if (is_array($options)) { ?>
<th scope="col" class="manage-col" width="35%"><?php _e('Language', 'what-did-they-say') ?></th> <h3><?php _e('Languages', 'what-did-they-say') ?></h3>
<th scope="col" class="manage-col"><?php _e('Rename?', 'what-did-they-say') ?></th>
<th scope="col" class="manage-col"><?php _e('Make default?', 'what-did-they-say') ?></th> <table class="widefat fixed">
<th scope="col" class="manage-col"><?php _e('Delete?', 'what-did-they-say') ?></th> <tr class="thead">
</tr> <th scope="col" class="manage-col" width="35%"><?php _e('Language', 'what-did-they-say') ?></th>
<?php foreach ($options['languages'] as $code => $info) { <th scope="col" class="manage-col"><?php _e('Rename?', 'what-did-they-say') ?></th>
$default = isset($info['default']); <th scope="col" class="manage-col"><?php _e('Make default?', 'what-did-they-say') ?></th>
$name = $info['name']; <th scope="col" class="manage-col"><?php _e('Delete?', 'what-did-they-say') ?></th>
?> </tr>
<?php foreach ($options['languages'] as $code => $info) {
$default = isset($info['default']);
$name = $info['name'];
?>
<tr>
<th scope="row">
<span><?php echo $name ?></span>
<?php if ($default) { _e('(default)', 'what-did-they-say'); } ?>
<form method="post" style="display: none">
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[code]" value="<?php echo $code ?>" />
<input type="hidden" name="wdts[action]" value="rename" />
<input type="hidden" name="wdts[module]" value="languages" />
<input type="text" name="wdts[name]" value="<?php echo $name ?>" style="width: 50%" />
<input type="submit" class="button" value="Rename" />
</form>
</th>
<td style="vertical-align: inherit">
<a class="rename button" href="#"><?php _e('Rename', 'what-did-they-say') ?></a>
</td>
<td>
<form method="post">
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[code]" value="<?php echo $code ?>" />
<input type="hidden" name="wdts[action]" value="default" />
<input type="hidden" name="wdts[module]" value="languages" />
<input
<?php echo ($default ? 'disabled="disabled"' : '') ?>
type="submit"
class="button"
value="<?php _e('Default', 'what-did-they-say') ?>" />
</form>
</td>
<td>
<form method="post" class="verify">
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[code]" value="<?php echo $code ?>" />
<input type="hidden" name="wdts[action]" value="delete" />
<input type="hidden" name="wdts[module]" value="languages" />
<input type="submit" class="button" value="<?php _e('Delete', 'what-did-they-say') ?>" />
</form>
</td>
</tr>
<?php } ?>
<tr> <tr>
<th scope="row"> <th scope="row"><?php _e('Add new:', 'what-did-they-say') ?></th>
<span><?php echo $name ?></span> <td colspan="3">
<?php if ($default) { _e('(default)', 'what-did-they-say'); } ?>
<form method="post" style="display: none">
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[code]" value="<?php echo $code ?>" />
<input type="hidden" name="wdts[action]" value="rename" />
<input type="hidden" name="wdts[module]" value="languages" />
<input type="text" name="wdts[name]" value="<?php echo $name ?>" style="width: 50%" />
<input type="submit" class="button" value="Rename" />
</form>
</th>
<td style="vertical-align: inherit">
<a class="rename button" href="#"><?php _e('Rename', 'what-did-they-say') ?></a>
</td>
<td>
<form method="post"> <form method="post">
<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[code]" value="<?php echo $code ?>" /> <input type="hidden" name="wdts[action]" value="add" />
<input type="hidden" name="wdts[action]" value="default" />
<input type="hidden" name="wdts[module]" value="languages" /> <input type="hidden" name="wdts[module]" value="languages" />
<input <select name="wdts[code]">
<?php echo ($default ? 'disabled="disabled"' : '') ?> <option value="">-- select --</option>
type="submit" <?php foreach ($this->all_languages as $code => $language) { ?>
class="button" <option value="<?php echo $code ?>"><?php echo $language ?></option>
value="<?php _e('Default', 'what-did-they-say') ?>" /> <?php } ?>
</form> </select>
</td> <input type="submit" value="<?php _e('Add New Language', 'what-did-they-say') ?>" class="button" />
<td>
<form method="post" class="verify">
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[code]" value="<?php echo $code ?>" />
<input type="hidden" name="wdts[action]" value="delete" />
<input type="hidden" name="wdts[module]" value="languages" />
<input type="submit" class="button" value="<?php _e('Delete', 'what-did-they-say') ?>" />
</form> </form>
</td> </td>
</tr> </tr>
<?php } ?> </table>
<tr> <?php } ?>
<th scope="row"><?php _e('Add new:', 'what-did-they-say') ?></th>
<td colspan="3">
<form method="post">
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[action]" value="add" />
<input type="hidden" name="wdts[module]" value="languages" />
<select name="wdts[code]">
<option value="">-- select --</option>
<?php foreach ($this->all_languages as $code => $language) { ?>
<option value="<?php echo $code ?>"><?php echo $language ?></option>
<?php } ?>
</select>
<input type="submit" value="<?php _e('Add New Language', 'what-did-they-say') ?>" class="button" />
</form>
</td>
</tr>
</table>
<?php } ?> <?php } ?>
<?php if (current_user_can('manage_options')) { ?> <?php if (current_user_can('manage_options')) { ?>
<h3><?php _e('Reset Settings to Default', 'what-did-they-say') ?></h3> <h3><?php _e('Reset Settings to Default', 'what-did-they-say') ?></h3>
<p><?php _e('Click the button below to reset capabilities and languages to their defaults. This will not affect any transcriptions you have already created, but some transcriptions may become inaccessible if you don\'t redefine the original language.', 'what-did-they-say') ?></p> <p><?php _e('Click the button below to reset capabilities and languages to their defaults. This will not affect any transcriptions you have already created, but some transcriptions may become inaccessible if you don\'t redefine the original language.', 'what-did-they-say') ?></p>

View File

@ -43,8 +43,12 @@
</select> </select>
</label> </label>
<?php foreach (array_keys($options['languages']) as $code) { ?> <?php foreach (array_keys($options['languages']) as $code) {
<textarea class="edit-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> $approved_transcript_text = '';
foreach ($approved_transcripts as $transcript) {
if ($transcript['language'] == $code) { $approved_transcript_text = $transcript['transcript']; break; }
} ?>
<textarea class="edit-transcript" id="wdts-transcripts-<?php echo $code ?>" name="wdts[transcripts][<?php echo $code ?>]" style="display: none; width: 100%; height: 200px"><?php echo $approved_transcript_text ?></textarea>
<?php } ?> <?php } ?>
</p> </p>
@ -61,6 +65,6 @@
}; };
var s = document.createElement('script'); var s = document.createElement('script');
s.src = '<?php echo plugin_dir_url(dirname(__FILE__)) . 'edit-transcripts.js' ?>'; s.src = '<?php echo plugin_dir_url(dirname(__FILE__)) . 'js/edit-transcripts.js' ?>';
document.getElementsByTagName('head')[0].appendChild(s); document.getElementsByTagName('head')[0].appendChild(s);
</script> </script>

37
css/wdts-defaults.css Normal file
View File

@ -0,0 +1,37 @@
div.transcript {
border: solid #333 1px;
padding: 10px;
margin: 10px;
background-color: #e7e7e7
}
div.transcript div, div.transcript span {
font-family: 'Courier New'
}
div.transcript > div {
margin-bottom: 10px
}
div.transcript div.scene-heading {
text-transform: uppercase;
text-align: center;
font-weight: bold;
margin-bottom: 10px
}
div.transcript div.dialog {
text-align: center
}
div.transcript div.dialog span {
display: block
}
div.transcript div.dialog span.name {
text-transform: uppercase
}
div.transcript div.dialog span.speech {
margin: 10px 20px 0
}

View File

@ -176,7 +176,7 @@ function the_media_transcript_queue_editor() {
${"${var_name}_transcript_manager"} = new $class_name($post->ID); ${"${var_name}_transcript_manager"} = new $class_name($post->ID);
${"${var_name}_transcripts"} = ${"${var_name}_transcript_manager"}->get_transcripts(); ${"${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');
?> ?>
@ -184,7 +184,7 @@ function the_media_transcript_queue_editor() {
<h3><?php _e('Manage Transcripts:', 'what-did-they-say') ?></h3> <h3><?php _e('Manage Transcripts:', 'what-did-they-say') ?></h3>
<form method="post" class="transcript-editor"> <form method="post" class="transcript-editor">
<?php include(dirname(__FILE__) . '/classes/meta-box.inc') ?> <?php include(dirname(__FILE__) . '/classes/meta-box.inc') ?>
<input type="submit" value="Submit New" /> <input type="submit" value="Modify Transcript" />
</form> </form>
<?php } ?> <?php } ?>
<?php if (current_user_can('submit_transcriptions')) { ?> <?php if (current_user_can('submit_transcriptions')) { ?>