what-did-they-say/classes/WDTSLanguageOptions.inc

127 lines
3.3 KiB
PHP
Raw Permalink Normal View History

2009-08-09 16:39:52 +00:00
<?php
2009-09-06 15:04:38 +00:00
class WDTSLanguageOptions {
2009-09-06 22:15:37 +00:00
var $key = "what-did-they-say-options";
2009-08-19 23:58:24 +00:00
/**
* Get the default transcript language for this blog.
* @return string The language code representing the default language.
*/
2009-08-16 18:14:07 +00:00
function get_default_language() {
$language = false;
2009-09-06 22:15:37 +00:00
$options = get_option($this->key);
2009-08-16 18:14:07 +00:00
foreach ($options['languages'] as $code => $info) {
if (is_null($language)) { $language = $code; }
2009-09-13 16:35:20 +00:00
if (isset($info['default'])) {
if ($info['default']) { $language = $code; break; }
}
2009-08-16 18:14:07 +00:00
}
return $language;
}
2009-08-19 23:58:24 +00:00
2009-09-11 01:00:10 +00:00
function set_default_language($language) {
$options = get_option($this->key);
if (isset($options['languages'][$language])) {
$ok = true;
if (isset($options['languages'][$language]['default'])) {
$ok = !$options['languages'][$language]['default'];
}
if ($ok) {
$updated_languages = array();
foreach ($options['languages'] as $code => $info) {
unset($info['default']);
if ($code == $language) { $info['default'] = true; }
$updated_languages[$code] = $info;
}
$options['languages'] = $updated_languages;
update_option($this->key, $options);
return true;
}
}
return false;
}
2009-08-19 23:58:24 +00:00
/**
* Get the name of a language from the language code.
* @param string $language The language code to search for.
* @return string|false The name of the language as defined in the options, or false if the language was not found.
*/
2009-08-16 18:14:07 +00:00
function get_language_name($language) {
2009-09-06 22:15:37 +00:00
$options = get_option($this->key);
2009-08-16 18:14:07 +00:00
if (isset($options['languages'][$language])) {
return $options['languages'][$language]['name'];
} else {
return false;
}
}
2009-08-19 23:58:24 +00:00
/**
* Get all available languages.
* @return array An array of languages.
*/
2009-08-16 20:54:11 +00:00
function get_languages() {
2009-09-06 22:15:37 +00:00
$options = get_option($this->key);
2009-08-16 20:54:11 +00:00
return $options['languages'];
}
2009-09-06 22:15:37 +00:00
function delete_language($code_to_delete) {
$options = get_option($this->key);
2009-09-06 22:28:43 +00:00
$did_delete = false;
if (isset($options['languages'][$code_to_delete])) {
2009-09-09 12:20:07 +00:00
$did_delete = $options['languages'][$code_to_delete];
2009-09-06 22:28:43 +00:00
unset($options['languages'][$code_to_delete]);
2009-09-11 01:00:10 +00:00
ksort($options['languages']);
2009-09-06 22:15:37 +00:00
}
update_option($this->key, $options);
2009-09-06 22:28:43 +00:00
return $did_delete;
2009-09-06 22:15:37 +00:00
}
function add_language($code, $info) {
2009-09-06 22:28:43 +00:00
$options = get_option($this->key);
$result = false;
if (!empty($code) && is_array($info)) {
if (!isset($options['languages'][$code])) {
if (!empty($info['name'])) {
$options['languages'][$code] = $info;
2009-09-11 01:00:10 +00:00
ksort($options['languages']);
2009-09-06 22:28:43 +00:00
$result = true;
}
}
}
2009-09-11 01:00:10 +00:00
2009-09-06 22:15:37 +00:00
update_option($this->key, $options);
2009-09-06 22:28:43 +00:00
return $result;
2009-09-06 22:15:37 +00:00
}
function rename_language($code_to_rename, $new_name) {
$options = get_option($this->key);
$found = false;
if (!empty($code_to_rename) && !empty($new_name)) {
$new_languages = array();
foreach ($options['languages'] as $code => $info) {
if ($code == $code_to_rename) {
$info['name'] = $new_name;
$found = true;
}
$new_languages[$code] = $info;
}
$options['languages'] = $new_languages;
2009-09-11 01:00:10 +00:00
ksort($options['languages']);
2009-09-06 22:15:37 +00:00
update_option($this->key, $options);
}
return $found;
}
2009-08-09 16:39:52 +00:00
}
?>