working on user permissions and usability

This commit is contained in:
John Bintz 2009-09-25 08:22:24 -04:00
parent ec9d031d2e
commit 387d1136cb
7 changed files with 71 additions and 49 deletions

View File

@ -134,7 +134,10 @@ class WhatDidTheySayAdmin {
*/ */
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('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'); } 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);
}
foreach (get_class_methods($this) as $method) { foreach (get_class_methods($this) as $method) {
if (strpos($method, "shortcode_") === 0) { if (strpos($method, "shortcode_") === 0) {
@ -283,13 +286,13 @@ class WhatDidTheySayAdmin {
function user_has_cap($capabilities, $requested_capabilities, $capability_name) { function user_has_cap($capabilities, $requested_capabilities, $capability_name) {
$options = get_option('what-did-they-say-options'); $options = get_option('what-did-they-say-options');
if (is_array($options)) { if (is_array($options)) {
$role_cascade = array('administrator', 'editor', 'author', 'contributor', 'subscriber'); $role_cascade = array('subscriber', 'contributor', 'author', 'editor', 'administrator');
$allowed_roles = array(); $allowed_roles = array();
$capture_roles = false;
for ($i = 0; $i < count($role_cascade); ++$i) { for ($i = 0; $i < count($role_cascade); ++$i) {
if (in_array($role_cascade, $capabilities)) { $capture_roles = true; } if (isset($capabilities[$role_cascade[$i]])) {
if ($capture_roles) { $allowed_roles[] = $role_cascade[$i]; } $allowed_roles = array_slice($role_cascade, 0, $i + 1); break;
}
} }
foreach ($requested_capabilities as $requested_capability) { foreach ($requested_capabilities as $requested_capability) {
@ -616,7 +619,7 @@ class WhatDidTheySayAdmin {
add_options_page( add_options_page(
__('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?!?', 'what-did-they-say'),
'manage_options', 'submit_transcriptions',
'manage-wdts', 'manage-wdts',
array(&$this, 'manage_admin') array(&$this, 'manage_admin')
); );
@ -645,6 +648,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_script('scriptaculous-effects'); wp_enqueue_script('scriptaculous-effects');
wp_enqueue_script('edit-transcript', plugin_dir_url(dirname(__FILE__)) . 'js/edit-transcripts.js', array('scriptaculous-effects'), false, true);
} }
} }
} }
@ -683,6 +687,7 @@ class WhatDidTheySayAdmin {
$nonce = wp_create_nonce('what-did-they-say'); $nonce = wp_create_nonce('what-did-they-say');
include('partials/meta-box.inc'); include('partials/meta-box.inc');
include('partials/_editor-script.inc');
} }
} }

View File

@ -0,0 +1,16 @@
<script type="text/javascript">
var ajax_url = '<?php echo $_SERVER['REQUEST_URI'] ?>';
var nonce = '<?php echo $nonce ?>';
var messages = {
'overwrite': '<?php _e('This will overwrite the current transcript. Are you sure?', 'what-did-they-say') ?>',
'delete': '<?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') ?>',
'deleted': '<?php _e('Transcript deleted.', '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') ?>',
'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_speech': '<?php _e('Enter what the character is speaking:', 'what-did-they-say') ?>',
};
</script>

View File

@ -15,6 +15,7 @@
<p> <p>
<?php if (current_user_can('manage_options')) { ?> <?php if (current_user_can('manage_options')) { ?>
<?php _e('<strong>What Did They Say?!?</strong> can attempt to embed excerpts into your posts automatically:', 'what-did-they-say') ?> <?php _e('<strong>What Did They Say?!?</strong> can attempt to embed excerpts into your posts automatically:', 'what-did-they-say') ?>
<fieldset>
<label> <label>
<input type="checkbox" <input type="checkbox"
name="wdts[automatic_embedding]" name="wdts[automatic_embedding]"
@ -23,6 +24,7 @@
<?php _e('Enable automatic transcript embedding', 'what-did-they-say') ?> <?php _e('Enable automatic transcript embedding', 'what-did-they-say') ?>
</label> </label>
<input type="submit" class="button" value="<?php _e('Submit', 'what-did-they-say') ?>" /> <input type="submit" class="button" value="<?php _e('Submit', 'what-did-they-say') ?>" />
</fieldset>
<?php } else { ?> <?php } else { ?>
<?php if ($options['automatic_embedding']) { ?> <?php if ($options['automatic_embedding']) { ?>
<?php _e('<strong>What Did They Say?!?</strong> is set to attempt to embed excerpts into your posts automatically.', 'what-did-they-say') ?> <?php _e('<strong>What Did They Say?!?</strong> is set to attempt to embed excerpts into your posts automatically.', 'what-did-they-say') ?>
@ -49,6 +51,7 @@
<?php _e('When someone searches your site, <strong>What Did They Say?!?</strong> can search your transcripts, too.', 'what-did-they-say') ?> <?php _e('When someone searches your site, <strong>What Did They Say?!?</strong> can search your transcripts, too.', 'what-did-they-say') ?>
<?php if (current_user_can('manage_options')) { ?> <?php if (current_user_can('manage_options')) { ?>
<fieldset>
<label> <label>
<input type="checkbox" <input type="checkbox"
name="wdts[search_integration]" name="wdts[search_integration]"
@ -57,6 +60,7 @@
<?php _e('Enable transcript search integration', 'what-did-they-say') ?> <?php _e('Enable transcript search integration', 'what-did-they-say') ?>
</label> </label>
<input type="submit" class="button" value="<?php _e('Submit', 'what-did-they-say') ?>" /> <input type="submit" class="button" value="<?php _e('Submit', 'what-did-they-say') ?>" />
</fieldset>
<?php } else { ?> <?php } else { ?>
<?php if ($options['search_integration']) { ?> <?php if ($options['search_integration']) { ?>
<?php _e('<strong>What Did They Say?!?</strong> is set to search transcripts when your site is searched.', 'what-did-they-say') ?> <?php _e('<strong>What Did They Say?!?</strong> is set to search transcripts when your site is searched.', 'what-did-they-say') ?>

View File

@ -57,22 +57,3 @@
<?php } ?> <?php } ?>
</div> </div>
</p> </p>
<script type="text/javascript">
var language_selector = $('wdts-language');
var ajax_url = '<?php echo $_SERVER['REQUEST_URI'] ?>';
var nonce = '<?php echo $nonce ?>';
var messages = {
'overwrite': '<?php _e('This will overwrite the current transcript. Are you sure?', 'what-did-they-say') ?>',
'delete': '<?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') ?>',
'deleted': '<?php _e('Transcript deleted.', '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') ?>',
'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_speech': '<?php _e('Enter what the character is speaking:', 'what-did-they-say') ?>',
};
</script>
<script type="text/javascript" src="<?php echo plugin_dir_url(dirname(__FILE__)) . '../js/edit-transcripts.js' ?>"></script>

View File

@ -61,3 +61,7 @@
-moz-border-radius: 2px; -moz-border-radius: 2px;
-webkit-border-radius: 2px; -webkit-border-radius: 2px;
} }
#wdts-page-introduction label {
display: inline
}

View File

@ -1,3 +1,5 @@
var language_selector = $('wdts-language');
function switch_transcript() { function switch_transcript() {
$$('.edit-transcript').each(function(t) { $$('.edit-transcript').each(function(t) {
(t.id == "wdts-transcripts-" + $F('wdts-language')) ? t.show() : t.hide(); (t.id == "wdts-transcripts-" + $F('wdts-language')) ? t.show() : t.hide();
@ -28,10 +30,16 @@ var WDTSInjector = Class.create({
}); });
Event.observe(window, 'load', function() { Event.observe(window, 'load', function() {
[ var buttons_to_watch = [];
[ '#wdts-shorttags button', $("wdts-transcripts-" + $F('wdts-language')) ], if ($('wdts-transcript')) {
[ '#wdts-submit-shorttags button', $('wdts-transcript') ] buttons_to_watch.push([ '#wdts-submit-shorttags button', $('wdts-transcript') ]);
].each(function(info) { }
if ($$('select[name=wdts-language]').pop()) {
buttons_to_watch.push([ '#wdts-shorttags button', $("wdts-transcripts-" + $F('wdts-language')) ]);
}
buttons_to_watch.each(function(info) {
$$(info[0]).each(function(b) { $$(info[0]).each(function(b) {
b.observe('click', function(e) { b.observe('click', function(e) {
Event.stop(e); Event.stop(e);
@ -179,6 +187,8 @@ $$('.delete-transcript').each(function(b) {
}); });
}); });
switch_transcript(); if (language_selector) {
Event.observe(window, 'load', switch_transcript); switch_transcript();
Event.observe(language_selector, 'change', switch_transcript); Event.observe(window, 'load', switch_transcript);
Event.observe(language_selector, 'change', switch_transcript);
}

View File

@ -211,6 +211,8 @@ function the_media_transcript_queue_editor() {
$nonce = wp_create_nonce('what-did-they-say'); $nonce = wp_create_nonce('what-did-they-say');
include(dirname(__FILE__) . '/classes/partials/_editor-script.inc');
?> ?>
<?php if (current_user_can('approve_transcriptions')) { ?> <?php if (current_user_can('approve_transcriptions')) { ?>
<h3><?php _e('Manage Transcripts:', 'what-did-they-say') ?></h3> <h3><?php _e('Manage Transcripts:', 'what-did-they-say') ?></h3>