function edit_post($glossary_id) { $glossary = GP::$glossary->get($glossary_id); $new_glossary = new GP_Glossary(gp_post('glossary')); if ($this->cannot_edit_glossary_and_redirect($glossary)) { return; } if (!$glossary->update($new_glossary)) { $this->errors[] = __('Error in updating glossary!'); $this->redirect(); return; } $this->notices[] = __('The glossary was updated!'); $translation_set = $new_glossary->translation_set_id ? GP::$translation_set->get($new_glossary->translation_set_id) : null; $set_project = GP::$project->get($translation_set->project_id); $this->redirect(gp_url_join(gp_url_project($set_project, array($translation_set->locale, $translation_set->slug)), array('glossary'))); }
function new_post() { $new_set = new GP_Translation_Set(gp_post('set')); if ($new_set->project_id) { $this->can_or_redirect('write', 'project', $new_set->project_id, gp_url_project(GP::$project->get($new_set->project_id))); } else { $this->can_or_redirect('write', 'project', null, gp_url_project('')); } $this->validate_or_redirect($new_set, gp_url('/sets/_new', array('project_id' => $new_set->project_id))); $set = GP::$translation_set->create_and_select($new_set); $project = GP::$project->get($set->project_id); if (!$set) { $this->errors[] = __('Error in creating translation set!'); gp_redirect(gp_url('/sets/_new', array('project_id' => $new_set['project_id']))); } else { $this->notices[] = __('The translation set was created!'); gp_redirect(gp_url_project_locale($project, $set->locale, $set->slug)); } }
public function set_priority($original_id) { $original = GP::$original->get($original_id); if (!$original) { return $this->die_with_404(); } $project = GP::$project->get($original->project_id); if (!$project) { return $this->die_with_404(); } $this->can_or_forbidden('write', 'project', $project->id); $original->priority = gp_post('priority'); if (!$original->validate()) { return $this->die_with_error('Invalid priority value!'); } if (!$original->save()) { return $this->die_with_error('Error in saving original!'); } }
function login_post() { global $wp_users_object, $wp_auth_object; $user = GP::$user->by_login($_POST['user_login']); if (!$user || is_wp_error($user)) { $this->errors[] = __("Invalid username!"); gp_redirect(gp_url('/login')); return; } if ($user->login($_POST['user_pass'])) { if (gp_post('redirect_to') && gp_startswith(gp_post('redirect_to'), gp_url_base())) { gp_redirect(gp_post('redirect_to')); } else { $this->notices[] = sprintf(__("Welcome, %s!"), $_POST['user_login']); gp_redirect(gp_url('/')); } } else { $this->errors[] = __("Invalid password!"); gp_redirect(gp_url('/login')); } }
function login_post() { global $wp_users_object, $wp_auth_object; $user = GP::$user->by_login($_POST['user_login']); if (!$user || is_wp_error($user)) { $this->errors[] = __("Invalid username!"); $this->redirect(gp_url_login()); return; } if ($user->login(gp_post('user_pass'))) { if (gp_post('redirect_to')) { $this->redirect(gp_post('redirect_to')); } else { $this->notices[] = sprintf(__("Welcome, %s!"), $_POST['user_login']); $this->redirect(gp_url_public_root()); } } else { $this->errors[] = __("Invalid password!"); $this->redirect(gp_url_login()); } }
public function set_priority($original_id) { $original = GP::$original->get($original_id); if (!$original) { return $this->die_with_404(); } if (!$this->verify_nonce('set-priority_' . $original_id)) { return $this->die_with_error(__('An error has occurred. Please try again.', 'glotpress'), 403); } $project = GP::$project->get($original->project_id); if (!$project) { return $this->die_with_404(); } $this->can_or_forbidden('write', 'project', $project->id); $original->priority = gp_post('priority'); if (!$original->validate()) { return $this->die_with_error('Invalid priority value!'); } if (!$original->save()) { return $this->die_with_error('Error in saving original!'); } }
function edit_post($set_id) { $items = $this->get_set_project_and_locale_from_set_id_or_404($set_id); if (!$items) { return; } list($set, $project, $locale) = $items; $new_set = new GP_Translation_Set(gp_post('set', array())); if ($this->cannot_edit_set_and_redirect($new_set)) { return; } if ($this->invalid_and_redirect($new_set, gp_url('/sets/-new'))) { return; } if (!$set->update($new_set)) { $this->errors[] = __('Error in updating translation set!'); $this->redirect(); return; } $project = GP::$project->get($new_set->project_id); $this->notices[] = __('The translation set was updated!'); $this->redirect(gp_url_project_locale($project, $new_set->locale, $new_set->slug)); }
private function set_status_edit_function($project, $locale, $translation_set, $translation) { $res = $translation->set_status(gp_post('status')); if (!$res) { return $this->die_with_error('Error in saving the translation status!'); } }
public function glossary_entry_delete_post($project_path, $locale_slug, $translation_set_slug) { $ge = array_shift(gp_post('glossary_entry')); $glossary_entry = GP::$glossary_entry->get(absint($ge['glossary_entry_id'])); if (!$glossary_entry) { return $this->die_with_error(__('The glossary entry cannot be found', 'glotpress'), 200); } $glossary = GP::$glossary->get($glossary_entry->glossary_id); $translation_set = GP::$translation_set->get($glossary->translation_set_id); $can_edit = $this->can('approve', 'translation-set', $translation_set->id); if (!$can_edit) { return $this->die_with_error(__('Forbidden', 'glotpress'), 403); } if (!$glossary_entry->delete()) { $this->errors[] = __('Error in deleting glossary entry!', 'glotpress'); } if ($this->errors) { $error_output = '<ul>'; foreach ($this->errors as $error) { $error_output .= '<li>' . $error . '</li>'; } $error_output .= '</ul>'; return $this->die_with_error($error_output, 200); } exit; }
function new_post() { $post = gp_post('project'); $parent_project_id = gp_array_get($post, 'parent_project_id', null); $this->can_or_redirect('write', 'project', $parent_project_id); $new_project = new GP_Project($post); $this->validate_or_redirect($new_project); $project = GP::$project->create_and_select($new_project); if (!$project) { $project = new GP_Project(); $this->errors[] = __('Error in creating project!'); $all_project_options = self::_options_from_projects(GP::$project->all()); gp_tmpl_load('project-new', get_defined_vars()); } else { $this->notices[] = __('The project was created!'); gp_redirect(gp_url_project($project, '_edit')); } }
public function branch_project_post($project_path) { $post = gp_post('project'); $project = GP::$project->by_path($project_path); if (!$project) { return $this->die_with_404(); } $parent_project_id = gp_array_get($post, 'parent_project_id', null); if ($this->cannot_and_redirect('write', 'project', $parent_project_id)) { return; } $new_project_data = new GP_Project($post); if ($this->invalid_and_redirect($new_project_data)) { return; } $new_project_data->active = $project->active; $new_project = GP::$project->create_and_select($new_project_data); if (!$new_project) { $new_project = new GP_Project(); $this->errors[] = __('Error in creating project!', 'glotpress'); $this->tmpl('project-branch', get_defined_vars()); } else { $new_project->duplicate_project_contents_from($project); } $this->redirect(gp_url_project($new_project)); }
function discard_warning($project_path, $locale_slug, $translation_set_slug) { $project = GP::$project->by_path($project_path); $locale = GP_Locales::by_slug($locale_slug); $translation_set = GP::$translation_set->by_project_id_slug_and_locale($project->id, $translation_set_slug, $locale_slug); if (!$project || !$locale || !$translation_set) { gp_tmpl_404(); } $this->can_or_forbidden('write', 'project', $project->id); $translation = GP::$translation->get(gp_post('translation_id')); if (!$translation) { $this->die_with_error('Translation doesn’t exist!'); } if (!isset($translation->warnings[gp_post('index')][gp_post('key')])) { $this->die_with_error('The warning doesn’exist!'); } unset($translation->warnings[gp_post('index')][gp_post('key')]); if (empty($translation->warnings[gp_post('index')])) { unset($translation->warnings[gp_post('index')]); } $res = $translation->save(); if (!$res) { $this->die_with_error('Error in saving the translation!'); } $translations = GP::$translation->for_translation($project, $translation_set, 'no-limit', array('translation_id' => gp_post('translation_id')), array()); if ($translations) { $t = $translations[0]; $parity = returner('even'); $can_edit = GP::$user->logged_in(); $can_approve = $this->can('approve', 'translation-set', $translation_set->id); gp_tmpl_load('translation-row', get_defined_vars()); } else { $this->die_with_error('Error in retrieving translation!'); } }
private function extract_project($project, $project_settings, $format_message = true) { $url_name = sprintf($this->source_type_templates[$project_settings[$project->id]['type']], $project_settings[$project->id]['setting']); $source_file = download_url($url_name); if (!is_wp_error($source_file)) { include dirname(__FILE__) . '/include/extract/makepot.php'; // Get a temporary file, use gpa as the first four letters of it. $temp_dir = tempnam(sys_get_temp_dir(), 'gpa'); $temp_pot = tempnam(sys_get_temp_dir(), 'gpa'); // Now delete the file and recreate it as a directory. unlink($temp_dir); mkdir($temp_dir); $zip = new ZipArchive(); if ($zip->open($source_file) === TRUE) { $zip->extractTo($temp_dir); $zip->close(); unlink($source_file); } else { unlink($source_file); return '<div class="notice updated"><p>' . sprintf(__('Failed to extract zip file: "%s".'), $source_file) . '</p></div>'; } $makepot = new MakePOT(); $makepot->generic($temp_dir, $temp_pot); $format = gp_array_get(GP::$formats, gp_post('format', 'po'), null); $translations = $format->read_originals_from_file($temp_pot); $this->delTree($temp_dir); unlink($temp_pot); if (FALSE === $translations) { return '<div class="notice updated"><p>' . __('Failed to read strings from source code.') . '</p></div>'; } list($originals_added, $originals_existing, $originals_fuzzied, $originals_obsoleted) = GP::$original->import_for_project($project, $translations); if (true === $format_message) { $message = '<div class="notice updated"><p>'; } $message .= sprintf(__('%1$s new strings added, %2$s updated, %3$s fuzzied, and %4$s obsoleted in the "%5$s" project.'), $originals_added, $originals_existing, $originals_fuzzied, $originals_obsoleted, $project->name); if (true === $format_message) { $message .= '</p></div>'; } } else { if (true === $format_message) { $message = '<div class="notice updated"><p>'; } $message .= sprintf(__('Failed to download "%s".'), $url_name) . '</p></div>'; if (true === $format_message) { $message .= '</p></div>'; } } return $message; }
public function import_glossary_entries_post($project_path, $locale_slug, $translation_set_slug) { $project = GP::$project->by_path($project_path); $locale = GP_Locales::by_slug($locale_slug); if (!$project || !$locale) { return $this->die_with_404(); } $translation_set = GP::$translation_set->by_project_id_slug_and_locale($project->id, $translation_set_slug, $locale_slug); if (!$translation_set) { return $this->die_with_404(); } $glossary = GP::$glossary->by_set_id($translation_set->id); if (!$glossary) { return $this->die_with_404(); } if ($this->invalid_nonce_and_redirect('import-glossary-entries_' . $project_path . $locale_slug . $translation_set_slug)) { return; } if ($this->cannot_and_redirect('approve', 'translation-set', $translation_set->id)) { return; } if (!is_uploaded_file($_FILES['import-file']['tmp_name'])) { $this->redirect_with_error(__('Error uploading the file.', 'glotpress')); return; } $replace = gp_post('import-flush'); if ('on' === $replace && $this->can('write', 'project', $project->id)) { GP::$glossary_entry->delete_many(array('glossary_id', $glossary->id)); } $glossary_entries_added = $this->read_glossary_entries_from_file($_FILES['import-file']['tmp_name'], $glossary->id, $locale->slug); if (empty($this->errors) && is_int($glossary_entries_added)) { $this->notices[] = sprintf(__('%s glossary entries were added', 'glotpress'), $glossary_entries_added); } $this->redirect(gp_url_join(gp_url_project_locale($project_path, $locale_slug, $translation_set_slug), array('glossary'))); }