a bunch mmore script cleanup

This commit is contained in:
John Bintz 2009-10-04 20:09:59 -04:00
parent 4a70567486
commit d5fced6b95
6 changed files with 115 additions and 51 deletions

View File

@ -22,7 +22,11 @@ class WhatDidTheySayAdmin {
'search_integration' => true, 'search_integration' => true,
'excerpt_distance' => 30, 'excerpt_distance' => 30,
'use_nl2br' => false, 'use_nl2br' => false,
'high_insertion_level' => false 'high_insertion_level' => false,
'hide_transcript' => array(
'home' => true,
'single' => false
)
); );
var $capabilities = array(); var $capabilities = array();
@ -92,11 +96,22 @@ class WhatDidTheySayAdmin {
} }
} }
if (current_user_can('submit_transcriptions')) {
add_action('wp_footer', array(&$this, 'wp_footer'));
}
add_filter('filter_shortcode_dialog', array(&$this, 'filter_shortcode_dialog'), 10, 4); 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_action', array(&$this, 'filter_shortcode_scene_action'), 10, 2);
add_filter('filter_shortcode_scene_heading', array(&$this, 'filter_shortcode_scene_heading'), 10, 2); add_filter('filter_shortcode_scene_heading', array(&$this, 'filter_shortcode_scene_heading'), 10, 2);
if (isset($_REQUEST['wdts'])) { if (isset($_REQUEST['wdts'])) {
if (isset($_REQUEST['wdts']['script'])) {
$language_options = new WDTSLanguageOptions();
include('partials/_editor-script.inc');
exit(0);
}
if (isset($_REQUEST['wdts']['_nonce'])) { if (isset($_REQUEST['wdts']['_nonce'])) {
if (wp_verify_nonce($_REQUEST['wdts']['_nonce'], 'what-did-they-say')) { if (wp_verify_nonce($_REQUEST['wdts']['_nonce'], 'what-did-they-say')) {
$this->handle_update($_REQUEST['wdts']); $this->handle_update($_REQUEST['wdts']);
@ -107,11 +122,13 @@ class WhatDidTheySayAdmin {
} }
} }
function include_editor_javascript() { function wp_footer() {
$nonce = wp_create_nonce('what-did-they-say'); $nonce = wp_create_nonce('what-did-they-say');
$language_options = new WDTSLanguageOptions();
include(dirname(__FILE__) . '/partials/_editor-script.inc'); echo '<script type="text/javascript">';
echo 'WhatDidTheySay.ajax_url = "' . addslashes($_SERVER['REQUEST_URI']) . '";';
echo 'WhatDidTheySay.nonce = "' . $nonce . '";';
echo '</script>';
} }
/** /**
@ -163,13 +180,12 @@ class WhatDidTheySayAdmin {
* Action for when a non-admin page is displayed. * Action for when a non-admin page is displayed.
*/ */
function template_redirect() { function template_redirect() {
wp_enqueue_script('toggle-transcript', plugin_dir_url(dirname(__FILE__)) . 'js/toggle-transcript.js', array('prototype'), false, true); wp_enqueue_script('wdts-script', get_bloginfo('url') . '?wdts[script]=true', array('prototype'));
wp_enqueue_script('toggle-transcript', plugin_dir_url(dirname(__FILE__)) . 'js/toggle-transcript.js', array('prototype', 'wdts-script'), false, true);
if (current_user_can('submit_transcriptions')) { if (current_user_can('submit_transcriptions')) {
wp_enqueue_script('scriptaculous-effects'); wp_enqueue_script('scriptaculous-effects');
wp_enqueue_script('edit-transcripts', plugin_dir_url(dirname(__FILE__)) . 'js/edit-transcripts.js', array('scriptaculous-effects')); wp_enqueue_script('edit-transcripts', plugin_dir_url(dirname(__FILE__)) . 'js/edit-transcripts.js', array('scriptaculous-effects', 'wdts-script'));
wp_enqueue_style('wdts-admin', plugin_dir_url(dirname(__FILE__)) . 'css/wdts-admin.css'); wp_enqueue_style('wdts-admin', plugin_dir_url(dirname(__FILE__)) . 'css/wdts-admin.css');
add_action('wp_head', array(&$this, 'include_editor_javascript'));
} }
$options = get_option('what-did-they-say-options'); $options = get_option('what-did-they-say-options');
@ -732,6 +748,8 @@ class WhatDidTheySayAdmin {
function admin_menu() { function admin_menu() {
global $pagenow, $plugin_page; global $pagenow, $plugin_page;
wp_enqueue_script('wdts-script', get_bloginfo('url') . '?wdts[script]=true', array('prototype'));
if (current_user_can('submit_transcriptions')) { if (current_user_can('submit_transcriptions')) {
add_options_page( add_options_page(
__('What Did They Say?!?', 'what-did-they-say'), __('What Did They Say?!?', 'what-did-they-say'),
@ -768,7 +786,7 @@ class WhatDidTheySayAdmin {
wp_enqueue_style('wdts-admin', plugin_dir_url(dirname(__FILE__)) . 'css/wdts-admin.css'); wp_enqueue_style('wdts-admin', plugin_dir_url(dirname(__FILE__)) . 'css/wdts-admin.css');
wp_enqueue_style('wdts-defaults', plugin_dir_url(dirname(__FILE__)) . 'css/wdts-defaults.css'); wp_enqueue_style('wdts-defaults', plugin_dir_url(dirname(__FILE__)) . 'css/wdts-defaults.css');
wp_enqueue_script('scriptaculous-effects'); wp_enqueue_script('scriptaculous-effects');
wp_enqueue_script('edit-transcripts', plugin_dir_url(dirname(__FILE__)) . 'js/edit-transcripts.js', array('scriptaculous-effects')); wp_enqueue_script('edit-transcripts', plugin_dir_url(dirname(__FILE__)) . 'js/edit-transcripts.js', array('scriptaculous-effects', 'wdts-script'));
} }
} }
} }
@ -808,7 +826,6 @@ class WhatDidTheySayAdmin {
$language_options = new WDTSLanguageOptions(); $language_options = new WDTSLanguageOptions();
$nonce = wp_create_nonce('what-did-they-say'); $nonce = wp_create_nonce('what-did-they-say');
include('partials/_editor-script.inc');
include('partials/meta-box.inc'); include('partials/meta-box.inc');
} }
} }

View File

@ -27,6 +27,26 @@
<?php echo ($options['use_nl2br'] ? 'checked="checked"' : '') ?> /> <?php echo ($options['use_nl2br'] ? 'checked="checked"' : '') ?> />
<?php _e('Turn transcript line breaks into HTML new lines (nl2br())', 'what-did-they-say') ?> <?php _e('Turn transcript line breaks into HTML new lines (nl2br())', 'what-did-they-say') ?>
</label> </label>
<p>By default, transcripts should be hidden on these types of pages:</p>
<div style="margin: 0 2em">
<label>
<input type="checkbox"
name="wdts[hide_transcript][home]"
value="yes"
<?php echo ($options['hide_transcript']['home'] ? 'checked="checked"' : '') ?> />
<?php _e('On the home page', 'what-did-they-say') ?>
</label>
<label>
<input type="checkbox"
name="wdts[hide_transcript][single]"
value="yes"
<?php echo ($options['hide_transcript']['single'] ? 'checked="checked"' : '') ?> />
<?php _e('On individual post pages', 'what-did-they-say') ?>
</label>
</div>
<input class="button" type="submit" value="<?php _e('Change default styles', 'what-did-they-say') ?>" /> <input class="button" type="submit" value="<?php _e('Change default styles', 'what-did-they-say') ?>" />
</form> </form>

View File

@ -1,40 +1,39 @@
<script type="text/javascript"> var WhatDidTheySay = Class.create({});
WhatDidTheySay.ajax_url = '<?php echo $_SERVER['REQUEST_URI'] ?>';
WhatDidTheySay.nonce = '<?php echo $nonce ?>';
WhatDidTheySay.messages = { WhatDidTheySay.messages = {
'overwrite': '<?php _e('This will overwrite the current transcript. Are you sure?', 'what-did-they-say') ?>', 'overwrite': '<?php _e('This will overwrite the current transcript. Are you sure?', 'what-did-they-say') ?>',
'delete_message': '<?php _e('This will delete the queued transcript. Are you sure?', 'what-did-they-say') ?>', 'delete_message': '<?php _e('This will delete the queued transcript. Are you sure?', 'what-did-they-say') ?>',
'approved': '<?php _e('Transcript approved and posted. You can further edit it below.', 'what-did-they-say') ?>', 'approved': '<?php _e('Transcript approved and posted. You can further edit it below.', 'what-did-they-say') ?>',
'deleted': '<?php _e('Transcript deleted.', 'what-did-they-say') ?>', 'deleted': '<?php _e('Transcript deleted.', 'what-did-they-say') ?>',
'scene_heading': '<?php _e('Enter the scene heading:', 'what-did-they-say') ?>', 'scene_heading': '<?php _e('Enter the scene heading:', 'what-did-they-say') ?>',
'scene_action': '<?php _e('Enter the scene action:', 'what-did-they-say') ?>', 'scene_action': '<?php _e('Enter the scene action:', 'what-did-they-say') ?>',
'dialog_name': '<?php _e('Enter the character name:', 'what-did-they-say') ?>', 'dialog_name': '<?php _e('Enter the character name:', 'what-did-they-say') ?>',
'dialog_direction': '<?php _e('Enter the direction in which the character is speaking:', 'what-did-they-say') ?>', 'dialog_direction': '<?php _e('Enter the direction in which the character is speaking:', 'what-did-they-say') ?>',
'dialog_speech': '<?php _e('Enter what the character is speaking:', 'what-did-they-say') ?>', 'dialog_speech': '<?php _e('Enter what the character is speaking:', 'what-did-they-say') ?>',
'transcripts_updated': '<?php _e('Transcripts updated. Reload to see them on page.', 'what-did-they-say') ?>', 'transcripts_updated': '<?php _e('Transcripts updated. Reload to see them on page.', 'what-did-they-say') ?>',
'transcripts_failure': '<?php _e('Transcript update failure!', 'what-did-they-say') ?>', 'transcripts_failure': '<?php _e('Transcript update failure!', 'what-did-they-say') ?>',
'bundle_header': '<?php echo apply_filters('the_transcript_format_string', '') ?>' 'bundle_header': '<?php echo apply_filters('the_transcript_format_string', '') ?>',
}; 'show_transcripts': '<?php _e('Show transcripts', 'what-did-they-say') ?>',
'hide_transcripts': '<?php _e('Hide transcripts', 'what-did-they-say') ?>'
};
WhatDidTheySay.button_labels = { WhatDidTheySay.button_labels = {
'scene-heading': '<?php _e('Scene Heading') ?>', 'scene-heading': '<?php _e('Scene Heading') ?>',
'scene-action': '<?php _e('Scene Action') ?>', 'scene-action': '<?php _e('Scene Action') ?>',
'dialog': '<?php _e('Dialog') ?>', 'dialog': '<?php _e('Dialog') ?>',
'approve': '<?php _e('Approve') ?>', 'approve': '<?php _e('Approve') ?>',
'delete': '<?php _e('Delete') ?>', 'delete': '<?php _e('Delete') ?>',
'edit': '<?php _e('Edit') ?>' 'edit': '<?php _e('Edit') ?>'
}; };
WhatDidTheySay.can_approve = <?php echo current_user_can('approve_transcriptions') ? "true" : "false" ?>; WhatDidTheySay.can_approve = <?php echo current_user_can('approve_transcriptions') ? "true" : "false" ?>;
<?php <?php
$language_output = array(); $language_output = array();
foreach ($language_options->get_languages() as $code => $info) { foreach ($language_options->get_languages() as $code => $info) {
$language_output[] = "${code}: '" . addslashes($info['name']) . "'"; $language_output[] = "${code}: '" . addslashes($info['name']) . "'";
} }
?> ?>
WhatDidTheySay.languages = { <?php echo implode(",", $language_output) ?> }; WhatDidTheySay.languages = { <?php echo implode(",", $language_output) ?> };
WhatDidTheySay.default_language = '<?php echo $language_options->get_default_language() ?>'; WhatDidTheySay.default_language = '<?php echo $language_options->get_default_language() ?>';
</script>

View File

@ -1,5 +1,3 @@
var WhatDidTheySay = Class.create({});
/** /**
* Set up a transcript editor widget. * Set up a transcript editor widget.
*/ */

View File

@ -60,6 +60,25 @@ WhatDidTheySay.build_bundle_header = function(bundle) {
bundle.insert({ top: new_header }) bundle.insert({ top: new_header })
} }
$$('.transcript-bundle').each(function(d) { $$('.wdts-transcript-bundle').each(function(d) {
if (d.hasClassName('wdts-hide-transcript')) {
d.hide();
var opener = new Element("a", { 'href': '#', 'className': 'wdts-transcript-opener' }).update(WhatDidTheySay.messages.show_transcripts);
opener.observe('click', function(e) {
Event.stop(e);
if (d.visible()) {
d.hide();
opener.update(WhatDidTheySay.messages.show_transcripts);
} else {
d.show();
opener.update(WhatDidTheySay.messages.hide_transcripts);
}
});
d.insert({before: opener});
}
WhatDidTheySay.build_bundle_header(d); WhatDidTheySay.build_bundle_header(d);
}); });

View File

@ -122,7 +122,7 @@ function the_language_name($language = null) {
* @param string $dropdown_message If set, the text that appears to the left of the language dropdown. * @param string $dropdown_message If set, the text that appears to the left of the language dropdown.
* @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($language_format = null) { function transcripts_display($language_format = null, $show_transcripts_string = null, $hide_transcripts_string = null) {
global $post; global $post;
$output = array(); $output = array();
@ -142,11 +142,21 @@ function transcripts_display($language_format = null) {
} }
$language_options = new WDTSLanguageOptions(); $language_options = new WDTSLanguageOptions();
$options = get_option('what-did-they-say-options');
if (count($transcripts) > 0) { if (count($transcripts) > 0) {
$default_language = $language_options->get_default_language(); $default_language = $language_options->get_default_language();
$output[] = '<div class="transcript-bundle">'; $do_hide = false;
if (is_home() || is_single()) {
foreach ($options['hide_transcript'] as $type => $do_hide) {
if ($do_hide && call_user_func("is_${type}")) {
$do_hide = true; break;
}
}
}
$output[] = '<div class="wdts-transcript-bundle' . ($do_hide ? ' wdts-hide-transcript' : '') . '">';
foreach ($transcripts as $code => $transcript) { foreach ($transcripts as $code => $transcript) {
$transcript = end(apply_filters('the_media_transcript', $transcript)); $transcript = end(apply_filters('the_media_transcript', $transcript));
@ -156,6 +166,7 @@ function transcripts_display($language_format = null) {
$output[] = '<div class="transcript-holder ' . $code . '">' . $transcript . '</div>'; $output[] = '<div class="transcript-holder ' . $code . '">' . $transcript . '</div>';
} }
$output[] = '</div>'; $output[] = '</div>';
} }
} }