public function set_community_resources($community_id, $update_first_project_callback = FALSE) { $client = new Lingotek_API(); $refresh_success = array('projects' => FALSE, 'workflows' => FALSE); $api_data = $client->get_projects($community_id); $projects = array(); if ($api_data !== FALSE) { foreach ($api_data->entities as $project) { $projects[$project->properties->id] = $project->properties->title; } if ($api_data->properties->total == 1) { if (!$project->properties->callback_url) { $client->update_callback_url($project->properties->id); } } natcasesort($projects); //order by title (case-insensitive) $refresh_success['projects'] = TRUE; } $api_data = $client->get_workflows($community_id); $default_workflows = array('c675bd20-0688-11e2-892e-0800200c9a66' => 'Machine Translation', 'ddf6e3c0-0688-11e2-892e-0800200c9a66' => 'Machine Translation + Post-Edit', '6ff1b470-33fd-11e2-81c1-0800200c9a66' => 'Machine Translation + Translate', '2b5498e0-f3c7-4c49-9afa-cca4b3345af7' => 'Translation + 1 review', '814172a6-3744-4da7-b932-5857c1c20976' => 'Translation + 2 reviews', '2210b148-0c44-4ae2-91d0-ca2ee47c069e' => 'Translation + 3 reviews', '7993b4d7-4ada-46d0-93d5-858db46c4c7d' => 'Translation Only'); $workflows = array(); if ($api_data) { foreach ($api_data->entities as $workflow) { $workflows[$workflow->properties->id] = $workflow->properties->title; } $diff = array_diff_key($workflows, $default_workflows); if (empty($diff)) { $workflows = array('c675bd20-0688-11e2-892e-0800200c9a66' => 'Machine Translation'); } natcasesort($workflows); //order by title (case-insensitive) $refresh_success['workflows'] = TRUE; } $api_data = $client->get_filters(); $filters = array(); if ($api_data && $api_data->properties->total > 0) { foreach ($api_data->entities as $filter) { if (!$filter->properties->is_public) { $filters[$filter->properties->id] = $filter->properties->title; } if ($filter->properties->title == '*****@*****.**' || $filter->properties->title == '*****@*****.**') { $filters[$filter->properties->id] = $filter->properties->title; } } $primary_filter_id = array_search('*****@*****.**', $filters); $secondary_filter_id = array_search('*****@*****.**', $filters); $defaults = get_option('lingotek_defaults'); if ($defaults == NULL) { $defaults['primary_filter_id'] = $primary_filter_id; $defaults['secondary_filter_id'] = $secondary_filter_id; update_option('lingotek_defaults', $defaults); } } $resources = array('projects' => $projects, 'workflows' => $workflows, 'filters' => $filters); if ($refresh_success['projects'] == TRUE || $refresh_success['workflows'] == TRUE) { update_option('lingotek_community_resources', $resources); $this->ensure_valid_defaults(); } return $refresh_success; }
unset($profiles[$profile_id]['targets'][$language->slug]); } } // hardcode default values for automatic and manual profiles as the process above emptied them $profiles['automatic']['upload'] = $profiles['automatic']['download'] = 'automatic'; $profiles['manual']['upload'] = $profiles['manual']['download'] = 'manual'; $profiles['automatic']['name'] = 'Automatic'; $profiles['manual']['name'] = 'Manual'; $profiles['disabled']['name'] = 'Disabled'; // do not localize names here update_option('lingotek_profiles', $profiles); add_settings_error('lingotek_profile', 'default', __('Your translation profile was sucessfully saved.', 'wp-lingotek'), 'updated'); if (isset($_POST['update_callback'])) { $project_id = isset($profiles[$profile_id]['project_id']) ? $profiles[$profile_id]['project_id'] : $defaults['project_id']; $client = new Lingotek_API(); if ($client->update_callback_url($project_id)) { add_settings_error('lingotek_profile', 'default', __('Your callback url was successfully updated.', 'wp-lingotek'), 'updated'); } } } settings_errors(); } ?> <h3><?php _e('Translation Profiles', 'wp-lingotek'); ?> </h3> <p class="description"><?php _e('Translation profiles allow you to quickly configure and re-use translation settings.', 'wp-lingotek'); ?> </p><?php
} } } } else { $options = array(); $settings = $this->get_profiles_settings(true); foreach ($settings as $key => $setting) { if (isset($_POST[$key])) { $options[$key] = $_POST[$key]; } } update_option('lingotek_defaults', $options); add_settings_error('lingotek_defaults', 'defaultgs', __('Your <i>Defaults</i> were sucessfully saved.', 'wp-lingotek'), 'updated'); if (isset($_POST['update_callback'])) { $client = new Lingotek_API(); if ($client->update_callback_url($options['project_id'])) { add_settings_error('lingotek_defaults', 'defaultgs', __('Your callback url was successfully updated.', 'wp-lingotek'), 'updated'); } } //adds new project if text box is filled out if (!empty($_POST['new_project'])) { $client = new Lingotek_API(); $title = stripslashes($_POST['new_project']); if ($new_id = $client->create_project($title, $community_id)) { add_settings_error('lingotek_defaults', 'defaultgs', __('Your new project was successfully created.', 'wp-lingotek'), 'updated'); $this->set_community_resources($community_id); // updates the cache to include the newly created project $options['project_id'] = $new_id; update_option('lingotek_defaults', $options); } }