url stuff worked out

This commit is contained in:
John Bintz 2009-08-14 13:45:50 -04:00
parent 8baeead4fc
commit 41609b8ae2
2 changed files with 38 additions and 16 deletions

View File

@ -15,6 +15,7 @@ class WhatDidTheySayAdmin {
var $language_file; var $language_file;
var $all_languages = array(); var $all_languages = array();
var $notices = array();
function WhatDidTheySayAdmin() { function WhatDidTheySayAdmin() {
$this->language_file = dirname(__FILE__) . '/../data/lsr-language.txt'; $this->language_file = dirname(__FILE__) . '/../data/lsr-language.txt';
@ -24,12 +25,13 @@ class WhatDidTheySayAdmin {
$this->what_did_they_say = $what_did_they_say; $this->what_did_they_say = $what_did_they_say;
add_action('admin_menu', array(&$this, 'admin_menu')); add_action('admin_menu', array(&$this, 'admin_menu'));
add_action('admin_notices', array(&$this, 'admin_notices'));
wp_enqueue_script('prototype'); wp_enqueue_script('prototype');
if (isset($_POST['wdts'])) { if (isset($_REQUEST['wdts'])) {
if (isset($_POST['wdts']['_nonce'])) { if (isset($_REQUEST['wdts']['_nonce'])) {
if (wp_verify_nonce('what-did-they-say', $_POST['wdts']['_nonce'])) { if (wp_verify_nonce($_REQUEST['wdts']['_nonce'], 'what-did-they-say')) {
$this->handle_update($_POST['wdts']); $this->handle_update($_REQUEST['wdts']);
} }
} }
} }
@ -43,15 +45,33 @@ class WhatDidTheySayAdmin {
update_option('what-did-they-say-options', $options); update_option('what-did-they-say-options', $options);
} }
function admin_notices() {
if (!empty($this->notices)) {
echo '<div class="updated fade">';
echo implode("<br />", $this->notices);
echo '</div>';
}
}
function handle_update($info) {
$result = $this->handle_update_languages($info);
if (!empty($result)) {
$this->notices[] = $result;
}
}
function handle_update_languages($language_info) { function handle_update_languages($language_info) {
$options = get_option('what-did-they-say-options'); $options = get_option('what-did-they-say-options');
$updated = false;
switch ($language_info['action']) { switch ($language_info['action']) {
case "delete": case "delete":
$updated = sprintf(__('%s deleted.', 'what-did-they-say'), $options['languages'][$language_info['code']]['name']);
unset($options['languages'][$language_info['code']]); unset($options['languages'][$language_info['code']]);
break; break;
case "add": case "add":
if (isset($this->all_languages[$language_info['code']])) { if (isset($this->all_languages[$language_info['code']])) {
$options['languages'][$language_info['code']] = array('name' => $this->all_languages[$language_info['code']]); $options['languages'][$language_info['code']] = array('name' => $this->all_languages[$language_info['code']]);
$updated = sprintf(__('%s added.', 'what-did-they-say'), $this->all_languages[$language_info['code']]);
} }
break; break;
case "default": case "default":
@ -59,6 +79,7 @@ class WhatDidTheySayAdmin {
foreach ($options['languages'] as $code => $info) { foreach ($options['languages'] as $code => $info) {
if ($code == $language_info['code']) { if ($code == $language_info['code']) {
$options['languages'][$code]['default'] = true; $options['languages'][$code]['default'] = true;
$updated = sprintf(__('%s set as default.', 'what-did-they-say'), $info['name']);
} else { } else {
unset($options['languages'][$code]['default']); unset($options['languages'][$code]['default']);
} }
@ -68,12 +89,14 @@ class WhatDidTheySayAdmin {
case "rename": case "rename":
if (isset($options['languages'][$language_info['code']])) { if (isset($options['languages'][$language_info['code']])) {
if (!empty($language_info['name'])) { if (!empty($language_info['name'])) {
$updated = sprintf(__('%1$s renamed to %2$s.', 'what-did-they-say'), $options['languages'][$language_info['code']]['name'], $language_info['name']);
$options['languages'][$language_info['code']]['name'] = $language_info['name']; $options['languages'][$language_info['code']]['name'] = $language_info['name'];
} }
} }
break; break;
} }
update_option('what-did-they-say-options', $options); update_option('what-did-they-say-options', $options);
return $updated;
} }
function handle_update_allowed_users($users) { function handle_update_allowed_users($users) {
@ -185,7 +208,9 @@ class WhatDidTheySayAdmin {
$nonce = wp_create_nonce('what-did-they-say'); $nonce = wp_create_nonce('what-did-they-say');
$nonce_url = add_query_arg('wdts[_nonce]', $nonce); $url = 'edit-comments.php?page=manage-transcriptions-wdts';
$nonce_url = add_query_arg('wdts[_nonce]', $nonce, $url);
include(dirname(__FILE__) . '/admin.inc'); include(dirname(__FILE__) . '/admin.inc');
} }
@ -195,10 +220,6 @@ class WhatDidTheySayAdmin {
var_dump($post->ID); var_dump($post->ID);
} }
function handle_update($info) {
}
} }
?> ?>

View File

@ -1,9 +1,9 @@
<div class="wrap"> <div class="wrap">
<h2>Manage Transcripts</h2> <h2><?php _e('Manage Transcripts', 'what-did-they-sahy') ?></h2>
<h3>Queued Transcripts</h3> <h3><?php _e('Queued Transcripts', 'what-did-they-say') ?></h3>
<h3>Languages</h3> <h3><?php _e('Languages', 'what-did-they-say') ?></h3>
<ul id="language-holder"> <ul id="language-holder">
<?php foreach ($options['languages'] as $code => $info) { <?php foreach ($options['languages'] as $code => $info) {
@ -13,9 +13,10 @@
<li> <li>
<strong> <strong>
<?php echo $name ?> <?php echo $name ?>
<?php if ($ <?php if ($default) { _e('(default)', 'what-did-they-say'); } ?>
</strong> </strong>
| <a class="verify" href="<?php echo add_query_arg(array('wdts[code]' => $code, 'wdts[action]' => 'delete'), $nonce_url) ?>">Delete</a> | <a href="<?php echo add_query_arg(array('wdts[code]' => $code, 'wdts[action]' => 'default'), $nonce_url) ?>"><?php _e('Default', 'what-did-they-say') ?></a>
| <a class="verify" href="<?php echo add_query_arg(array('wdts[code]' => $code, 'wdts[action]' => 'delete'), $nonce_url) ?>"><?php _e('Delete', 'what-did-they-say') ?></a>
</li> </li>
<?php } ?> <?php } ?>
</ul> </ul>
@ -28,7 +29,7 @@
$$('a.verify').each(function(a) { $$('a.verify').each(function(a) {
Event.observe(a, 'click', function(e) { Event.observe(a, 'click', function(e) {
if (!confirm("You are about to delete this language from the available list. Continue?")) { if (!confirm("<?php _e('You are about to delete this language from the available list. Continue?', 'what-did-they-say') ?>")) {
Event.stop(e); Event.stop(e);
} }
}); });