working on reworking language options
This commit is contained in:
parent
e2c5b30173
commit
852c00f16f
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*~
|
||||||
|
|
@ -1,12 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class WhatDidTheySayAdmin {
|
class WhatDidTheySayAdmin {
|
||||||
var $default_languages = array(
|
var $default_options = array(
|
||||||
array('code' => 'en', 'default' => true),
|
'languages' => array(
|
||||||
'fr',
|
array('code' => 'en', 'default' => true),
|
||||||
'es',
|
'fr',
|
||||||
'it',
|
'es',
|
||||||
'de'
|
'it',
|
||||||
|
'de'
|
||||||
|
),
|
||||||
|
'only_allowed_users' => false,
|
||||||
|
'users' => array()
|
||||||
);
|
);
|
||||||
|
|
||||||
var $language_file;
|
var $language_file;
|
||||||
@ -20,6 +24,7 @@ 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'));
|
||||||
|
wp_enqueue_script('prototype');
|
||||||
|
|
||||||
if (isset($_POST['wdts'])) {
|
if (isset($_POST['wdts'])) {
|
||||||
if (isset($_POST['wdts']['_nonce'])) {
|
if (isset($_POST['wdts']['_nonce'])) {
|
||||||
@ -28,6 +33,8 @@ class WhatDidTheySayAdmin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->read_language_file();
|
||||||
}
|
}
|
||||||
|
|
||||||
function _update_options($which, $value) {
|
function _update_options($which, $value) {
|
||||||
@ -37,6 +44,8 @@ class WhatDidTheySayAdmin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handle_update_languages($language_info) {
|
function handle_update_languages($language_info) {
|
||||||
|
|
||||||
|
|
||||||
$languages = array();
|
$languages = array();
|
||||||
foreach ($language_info as $code => $info) {
|
foreach ($language_info as $code => $info) {
|
||||||
if (isset($this->all_languages[$code])) {
|
if (isset($this->all_languages[$code])) {
|
||||||
@ -90,9 +99,9 @@ class WhatDidTheySayAdmin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function install() {
|
function install() {
|
||||||
$languages = get_option('what-did-they-say-languages');
|
$options = get_option('what-did-they-say-options');
|
||||||
if (empty($languages)) {
|
if (empty($options)) {
|
||||||
update_option('what-did-they-say-languages', $this->default_languages);
|
update_option('what-did-they-say-options', $this->default_options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,6 +129,21 @@ class WhatDidTheySayAdmin {
|
|||||||
|
|
||||||
function manage_transcriptions_admin() {
|
function manage_transcriptions_admin() {
|
||||||
$options = get_option('what-did-they-say-options');
|
$options = get_option('what-did-they-say-options');
|
||||||
|
|
||||||
|
$language_map_pairs = array();
|
||||||
|
$basic_languages = $all_languages = array();
|
||||||
|
foreach ($this->all_languages as $code => $name) {
|
||||||
|
$name = addslashes($name);
|
||||||
|
$language_map_pairs[] = "'${code}': '${name}'";
|
||||||
|
$all_languages[] = "'$code'";
|
||||||
|
if (strlen($code) == 2) {
|
||||||
|
$basic_languages[] = "'$code'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$nonce = wp_create_nonce('what-did-they-say');
|
||||||
|
|
||||||
|
$nonce_url = add_query_arg('wdts[_nonce]', $nonce);
|
||||||
|
|
||||||
include(dirname(__FILE__) . '/admin.inc');
|
include(dirname(__FILE__) . '/admin.inc');
|
||||||
}
|
}
|
||||||
|
@ -3,22 +3,36 @@
|
|||||||
|
|
||||||
<h3>Queued Transcripts</h3>
|
<h3>Queued Transcripts</h3>
|
||||||
|
|
||||||
<h3>Available Languages</h3>
|
<h3>Languages</h3>
|
||||||
|
|
||||||
<ul id="language-holder">
|
<ul id="language-holder">
|
||||||
<?php foreach ($languages as $language) {
|
<?php foreach ($options['languages'] as $language) {
|
||||||
$default = false;
|
$default = false;
|
||||||
if (is_string($language)) { $name = $language; }
|
|
||||||
if (is_array($language)) {
|
if (is_array($language)) {
|
||||||
$name = $language['name'];
|
$default = $language['default'];
|
||||||
$default = $language['default'];
|
$code = $language['code'];
|
||||||
}
|
}
|
||||||
$key = md5($name);
|
if (is_string($language)) { $code = $language; }
|
||||||
?>
|
?>
|
||||||
<li>
|
<li>
|
||||||
<input type="text" name="wdts[language][<?php echo $key ?>]" value="<?php echo $name ?>" />
|
<strong><?php echo $this->all_languages[$code] ?></strong>
|
||||||
<input type="radio" name="wdts[language][_default]" value="<?php echo $key ?>"
|
| <a class="verify" href="<?php echo add_query_arg(array('wdts[code]' => $code, 'wdts[action]' => 'delete'), $nonce_url) ?>">Delete</a>
|
||||||
</li>
|
</li>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var basic_languages = [ <?php echo implode(",", $basic_languages) ?> ];
|
||||||
|
var all_languages = [ <?php echo implode(",", $all_languages) ?> ];
|
||||||
|
|
||||||
|
var language_map = { <?php echo implode(",\n", $language_map_pairs) ?> };
|
||||||
|
|
||||||
|
$$('a.verify').each(function(a) {
|
||||||
|
Event.observe(a, 'click', function(e) {
|
||||||
|
if (!confirm("You are about to delete this language from the available list. Continue?")) {
|
||||||
|
Event.stop(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
@ -14,18 +14,36 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
$this->assertTrue(count($admin->read_language_file()) > 0);
|
$this->assertTrue(count($admin->read_language_file()) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testHandleUpdateLanguages() {
|
function providerTestHandleUpdateLanguages() {
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
array('en' => array('name' => 'English'), 'de' => array('name' => 'German')),
|
||||||
|
array('code' => 'en', 'action' => 'delete'),
|
||||||
|
array('de' => array('name' => 'German'))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerTestHandleUpdateLanguages
|
||||||
|
*/
|
||||||
|
function testHandleUpdateLanguages($original_options, $form_submission, $expected_results) {
|
||||||
$admin = new WhatDidTheySayAdmin();
|
$admin = new WhatDidTheySayAdmin();
|
||||||
$admin->all_languages = array(
|
$admin->all_languages = array(
|
||||||
'en' => 'English',
|
'en' => 'English',
|
||||||
'de' => 'German'
|
'de' => 'German',
|
||||||
|
'fr' => 'French'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
update_option('what-did-they-say-options', array('languages', $original_options));
|
||||||
|
|
||||||
$admin->handle_update_languages(array('en' => array(), 'de' => array('default' => 'yes'), 'meow' => array()));
|
$admin->handle_update_languages($form_submission);
|
||||||
|
|
||||||
$options = get_option('what-did-they-say-options');
|
$options = get_option('what-did-they-say-options');
|
||||||
$this->assertEquals(array('en', array('code' => 'de', 'default' => true)), $options['languages']);
|
$this->assertEquals($expected_results, $options['languages']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testHandleUpdateAllowedUsers() {
|
function testHandleUpdateAllowedUsers() {
|
||||||
|
Loading…
Reference in New Issue
Block a user