From 3a0d0572d53de331d382f5eafa4ffcb29e7c4864 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 16 Aug 2009 12:40:54 -0400 Subject: [PATCH] basic transcription saving working --- classes/WhatDidTheySayAdmin.php | 117 +++++++++++++++++++------------- classes/meta-box.inc | 5 +- 2 files changed, 74 insertions(+), 48 deletions(-) diff --git a/classes/WhatDidTheySayAdmin.php b/classes/WhatDidTheySayAdmin.php index 3933316..3e3217d 100644 --- a/classes/WhatDidTheySayAdmin.php +++ b/classes/WhatDidTheySayAdmin.php @@ -84,7 +84,7 @@ class WhatDidTheySayAdmin { function admin_notices() { if (!empty($this->notices)) { echo '
'; - echo implode("
", $this->notices); + foreach ($this->notices as $notice) { echo "

" . $notice . "

"; } echo '
'; } } @@ -98,63 +98,88 @@ class WhatDidTheySayAdmin { } } - function handle_update_languages($language_info) { - $options = get_option('what-did-they-say-options'); + function handle_update_post_transcripts($post_transcript_info) { $updated = false; - switch ($language_info['action']) { - case "delete": - $updated = sprintf(__('%s deleted.', 'what-did-they-say'), $options['languages'][$language_info['code']]['name']); - unset($options['languages'][$language_info['code']]); - break; - case "add": - $this->read_language_file(); - if (isset($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; - case "default": - if (isset($options['languages'][$language_info['code']])) { - foreach ($options['languages'] as $code => $info) { - if ($code == $language_info['code']) { - $options['languages'][$code]['default'] = true; - $updated = sprintf(__('%s set as default.', 'what-did-they-say'), $info['name']); - } else { - unset($options['languages'][$code]['default']); + if (current_user_can('approve_transcriptions')) { + $options = get_option('what-did-they-say-options'); + + switch ($post_transcript_info['action']) { + case "manage_post_transcripts": + foreach ($post_transcript_info['transcripts'] as $language => $transcript) { + $this->what_did_they_say->save_transcript($post_transcript_info['post_id'], $language, $transcript); + } + $updated = __('Transcripts updated', 'what-did-they-say'); + break; + } + } + return $updated; + } + + function handle_update_languages($language_info) { + $updated = false; + if (current_user_can('change_languages')) { + $options = get_option('what-did-they-say-options'); + switch ($language_info['action']) { + case "delete": + $updated = sprintf(__('%s deleted.', 'what-did-they-say'), $options['languages'][$language_info['code']]['name']); + unset($options['languages'][$language_info['code']]); + break; + case "add": + $this->read_language_file(); + if (isset($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; + case "default": + if (isset($options['languages'][$language_info['code']])) { + foreach ($options['languages'] as $code => $info) { + if ($code == $language_info['code']) { + $options['languages'][$code]['default'] = true; + $updated = sprintf(__('%s set as default.', 'what-did-they-say'), $info['name']); + } else { + unset($options['languages'][$code]['default']); + } } } - } - break; - case "rename": - if (isset($options['languages'][$language_info['code']])) { - 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']; + break; + case "rename": + if (isset($options['languages'][$language_info['code']])) { + 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']; + } } - } - break; - } - ksort($options['languages']); - update_option('what-did-they-say-options', $options); + break; + } + if ($updated !== false) { + ksort($options['languages']); + update_option('what-did-they-say-options', $options); + } + } return $updated; } function handle_update_capabilities($capabilities_info) { - $options = get_option('what-did-they-say-options'); $updated = false; - switch ($capabilities_info['action']) { - case "capabilities": - if (isset($capabilities_info['capabilities'])) { - foreach (array_keys($this->default_options['capabilities']) as $capability) { - if (isset($capabilities_info['capabilities'][$capability])) { - $options['capabilities'][$capability] = $capabilities_info['capabilities'][$capability]; + if (current_user_can('edit_users')) { + $options = get_option('what-did-they-say-options'); + switch ($capabilities_info['action']) { + case "capabilities": + if (isset($capabilities_info['capabilities'])) { + foreach (array_keys($this->default_options['capabilities']) as $capability) { + if (isset($capabilities_info['capabilities'][$capability])) { + $options['capabilities'][$capability] = $capabilities_info['capabilities'][$capability]; + } } + $updated = __('User capabilities updated', 'what-did-they-say'); } - $updated = __('User capabilities updated', 'what-did-they-say'); - } - break; + break; + } + if ($updated !== false) { + update_option('what-did-they-say-options', $options); + } } - update_option('what-did-they-say-options', $options); return $updated; } diff --git a/classes/meta-box.inc b/classes/meta-box.inc index ae3d196..c95cf22 100644 --- a/classes/meta-box.inc +++ b/classes/meta-box.inc @@ -1,5 +1,6 @@ - - + + +