public function bulk_translate($project_path) { $project_path = urldecode($project_path); $url = gp_url_project($project_path); // If we don't have rights, just redirect back to the project. if (!GP::$user->current()->can('write', 'project')) { gp_redirect($url); } // Create a project class to use to get the project object. $project_class = new GP_Project(); // Get the project object from the project path that was passed in. $project_obj = $project_class->by_path($project_path); // Get the translations sets from the project ID. $translation_sets = GP::$translation_set->by_project_id($project_obj->id); // Loop through all the sets. foreach ($translation_sets as $set) { //Array ( [action] => gtranslate [priority] => 0 [redirect_to] => http://localhost/wp40/gp/projects/sample/bg/my [row-ids] => Array ( [0] => 1 [1] => 2 ) ) $bulk = array('action' => 'gtranslate', 'priority' => 0, 'row-ids' => array()); $translation = new GP_Translation(); $strings = $translation->for_translation($project_obj, $set, null, array('status' => 'untranslated')); foreach ($strings as $string) { $bulk['row-ids'][] .= $string->row_id; } $locale = GP_Locales::by_slug($set->locale); $this->gp_translation_set_bulk_action_post($project_obj, $locale, $set, $bulk); } $url = gp_url_project($project_path); gp_redirect($url); }
function gp_link_project_delete_get($project, $text = false, $attrs = array()) { if (!GP::$permission->current_user_can('delete', 'project', $project->id)) { return ''; } $text = $text ? $text : __('Delete', 'glotpress'); return gp_link_get(gp_url_project($project, '-delete'), $text, gp_attrs_add_class($attrs, 'action edit')); }
function gp_link_project_delete_get($project, $text = false, $attrs = array()) { if (!current_user_can('manage_options')) { return ''; } $text = $text ? $text : __('Delete', 'glotpress'); return gp_link_get(gp_url_project($project, '-delete'), $text, gp_attrs_add_class($attrs, 'action delete')); }
function gp_link_project_delete_get($project, $text = false, $attrs = array()) { if (!GP::$user->current()->can('write', 'project', $project->id)) { return ''; } $text = $text ? $text : __('Delete'); return gp_link_get(gp_url_project($project, '-delete'), $text, gp_attrs_add_class($attrs, 'action delete')); }
function test_gp_url_with_arrays() { $this->assertEquals('baba', gp_url_join(array('baba'))); $this->assertEquals('baba/dyado', gp_url_join(array('baba', 'dyado'))); // test some shortcuts -- arrays instead of gp_url_join calls $this->assertEquals(gp_url_join(gp_url_project('/x'), 'import-originals'), gp_url_project('/x', 'import-originals')); $this->assertEquals(gp_url_project('/x', gp_url_join('slug', 'slugslug', 'import-translations')), gp_url_project('/x', array('slug', 'slugslug', 'import-translations'))); }
function edit_get($set_id) { $items = $this->get_set_project_and_locale_from_set_id_or_404($set_id); if (!$items) { return; } list($set, $project, $locale) = $items; if ($this->cannot_and_redirect('write', 'project', $set->project_id, gp_url_project($project))) { return; } $url = gp_url_project($project, gp_url_join($set->locale, $set->slug)); $this->tmpl('translation-set-edit', get_defined_vars()); }
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 auto_extract($project_path) { // First let's ensure we have decoded the project path for use later. $project_path = urldecode($project_path); // Get the URL to the project for use later. $url = gp_url_project($project_path); // Create a project class to use to get the project object. $project_class = new GP_Project(); // Get the project object from the project path that was passed in. $project_obj = $project_class->by_path($project_path); if (GP::$permission->user_can(wp_get_current_user(), 'write', 'project', $project->id)) { // Get the project settings. $project_settings = (array) get_option('gp_auto_extract', array()); // Since we're running on the front end we need to load the download_url() function from the wp-admin/includes directory. include ABSPATH . 'wp-admin/includes/file.php'; // Extract the strings, the third parameter disables HTML formating of the returned messages as GP doesn't need them. $message = $this->extract_project($project_obj, $project_settings, false); } else { $message = 'You do not have rights to auto extract originals!'; } gp_notice_set($message); // Redirect back to the project home. wp_redirect($url); }
/** * Constructs URL for a project and locale. * /<project-path>/<locale>/<path>/<page> */ function gp_url_project_locale($project_or_path, $locale, $path = '', $query = null) { return gp_url_project($project_or_path, array($locale, $path), $query); }
gp_link_project($project, esc_html($project->name)); ?> <?php gp_link_project_edit($project, null, array('class' => 'btn btn-xs btn-primary')); ?> </li> <?php } ?> </ul> <p> <?php gp_link(gp_url('/languages'), __('Projects by language'), array('class' => 'btn btn-primary')); ?> <?php if (GP::$user->current()->can('write', 'project')) { ?> <?php gp_link(gp_url_project('-new'), __('Create a New Project'), array('class' => 'btn btn-default')); ?> <?php } ?> </p> <?php gp_tmpl_footer();
<a class="ternary" href="#" onclick="jQuery('#personal-options-toggle').click();return false;">Cancel</a> </p> </form> </div> </div> <?php } if ($can_write) { ?> <p class="secondary actionlist"> <?php gp_link(gp_url_project($project, 'import-originals'), __('Import originals')); ?> • <?php gp_link(gp_url_project('', '_new', array('parent_project_id' => $project->id)), __('Create a New Sub-Project')); ?> • <?php gp_link(gp_url('/sets/_new', array('project_id' => $project->id)), __('Create a New Translation Set')); ?> </p> <?php } ?> <script type="text/javascript" charset="utf-8"> $gp.showhide('a.personal-options', 'Personal project options ↓', 'Personal project options ↑', 'div.personal-options', '#source-url-template'); $('div.personal-options').hide(); </script> <?php gp_tmpl_footer();
foreach ($translations as $t) { gp_tmpl_load('translation-row', get_defined_vars()); ?> <?php } if (!$translations) { ?> <tr><td colspan="4">No translations were found!</td></tr> <?php } ?> </table> <?php echo gp_pagination($page, $per_page, $total_translations_count); ?> <p class="clear actionlist secondary"> <?php $footer_links = array(); if ($can_approve) { $footer_links[] = gp_link_get(gp_url_project($project, array($locale->slug, $translation_set->slug, 'import-translations')), __('Import translations')); } if (GP::$user->logged_in()) { $footer_links[] = gp_link_get(gp_url_project($project, array($locale->slug, $translation_set->slug, 'export-translations')), __('Export as PO file')); } $footer_links[] = gp_link_get(gp_url_project($project, array($locale->slug, $translation_set->slug, '_permissions')), 'Permissions'); echo implode(' • ', $footer_links); ?> </p> <?php gp_tmpl_footer();
</div><?php } ?> <div class="box has-warnings"></div> <div><?php _e('with warnings', 'glotpress'); ?> </div> </div> <p class="clear actionlist secondary"> <?php $footer_links = array(); if ($can_approve) { $footer_links[] = gp_link_get(gp_url_project($project, array($locale->slug, $translation_set->slug, 'import-translations')), __('Import translations', 'glotpress')); } $export_url = gp_url_project($project, array($locale->slug, $translation_set->slug, 'export-translations')); $export_link = gp_link_get($export_url, __('Export', 'glotpress'), array('id' => 'export', 'filters' => add_query_arg(array('filters' => $filters), $export_url))); $format_options = array(); foreach (GP::$formats as $slug => $format) { $format_options[$slug] = $format->name; } $what_dropdown = gp_select('what-to-export', array('all' => _x('all current', 'export choice', 'glotpress'), 'filtered' => _x('only matching the filter', 'export choice', 'glotpress')), 'all'); $format_dropdown = gp_select('export-format', $format_options, 'po'); /* translators: 1: export 2: what to export dropdown (all/filtered) 3: export format */ $footer_links[] = sprintf(__('%1$s %2$s as %3$s', 'glotpress'), $export_link, $what_dropdown, $format_dropdown); echo implode(' • ', apply_filters('gp_translations_footer_links', $footer_links, $project, $locale, $translation_set)); ?> </p> <?php gp_tmpl_footer();
function gp_project_options_form($project) { return ' <a href="#" class="personal-options" id="personal-options-toggle"> ' . __('Personal project options ↓') . '</a> <div class="personal-options"> <form action="' . gp_url_project($project, '-personal') . '" method="post"> <dl> <dt><label for="source-url-template">' . __('Source file URL') . '</label></dt> <dd> <input type="text" value="' . esc_html($project->source_url_template()) . '" name="source-url-template" id="source-url-template" /> <small>' . __('URL to a source file in the project. You can use <code>%file%</code> and <code>%line%</code>. Ex. <code>https://trac.example.org/browser/%file%#L%line%</code>') . '</small> </dd> </dl> <p> <input type="submit" name="submit" value="' . esc_attr(__('Save →')) . '" id="save" /> <a class="ternary" href="#" onclick="jQuery(\'#personal-options-toggle\').click();return false;">' . __('Cancel') . '</a> </p> </form> </div>'; }
public function index() { $this->redirect(gp_url_project('')); }
printf(__('Delete project “%s”', 'glotpress'), esc_html($project->name)); ?> </h2> <form action="" method="post"> <p> <?php _e('Note this will delete all translations, translation sets and child projects!', 'glotpress'); ?> </p> <p> <input type="submit" name="submit" value="<?php esc_attr_e('Delete', 'glotpress'); ?> " id="submit" /> <span class="or-cancel"><?php _e('or', 'glotpress'); ?> <a href="<?php echo esc_url(gp_url_project($project)); ?> "><?php _e('Cancel', 'glotpress'); ?> </a></span> </p> <?php gp_route_nonce_field('delete-project_' . $project->id); ?> </form> <?php gp_tmpl_footer();
private function get_translation_set($set) { if (!isset($this->projects[$set->project_id])) { $this->projects[$set->project_id] = GP::$project->get($set->project_id); } $project = $this->projects[$set->project_id]; if (!$project) { return false; } $project_url = gp_url_project($project, gp_url_join($set->locale, $set->slug)); $set_name = gp_project_names_from_root($project) . ' | ' . $set->name_with_locale(); return (object) array('project_id' => $project->id, 'project_url' => $project_url, 'set_name' => $set_name); }
?> </td> <td class="stats translated"><?php gp_link(gp_url_project($set_data->project_path, gp_url_join($locale->slug, $set_data->slug), array('filters[translated]' => 'yes', 'filters[status]' => 'current')), absint($set_data->current_count)); ?> </td> <td class="stats fuzzy"><?php gp_link(gp_url_project($set_data->project_path, gp_url_join($locale->slug, $set_data->slug), array('filters[status]' => 'fuzzy')), absint($set_data->fuzzy_count)); ?> </td> <td class="stats untranslated"><?php gp_link(gp_url_project($set_data->project_path, gp_url_join($locale->slug, $set_data->slug), array('filters[status]' => 'untranslated')), absint($set_data->all_count) - absint($set_data->current_count)); ?> </td> <td class="stats waiting"><?php gp_link(gp_url_project($set_data->project_path, gp_url_join($locale->slug, $set_data->slug), array('filters[translated]' => 'yes', 'filters[status]' => 'waiting')), absint($set_data->waiting_count)); ?> </td> </tr> <?php } //sub project slugs ?> </tr> <?php } //sub projects ?> </tbody> </table> </div>
<li><?php gp_link_project($project, esc_html($project->name)); ?> <?php gp_link_project_edit($project, null, array('class' => 'bubble')); ?> </li> <?php } ?> </ul> <p class="actionlist secondary"> <?php if (GP::$user->current()->can('write', 'project')) { ?> <?php gp_link(gp_url_project('-new'), __('Create a New Project')); ?> • <?php } ?> <?php gp_link(gp_url('/languages'), __('Projects by language')); ?> </p> <?php gp_tmpl_footer();
function permissions_delete($project_path, $locale_slug, $translation_set_slug, $permission_id) { $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_redirect('write', 'project', $project->id); $permission = GP::$permission->get($permission_id); if ($permission) { if ($permission->delete()) { $this->notices[] = 'Permissin was deleted.'; } else { $this->errors[] = 'Error in deleting permission!'; } } else { $this->errors[] = 'Permission wasn’t found!'; } gp_redirect(gp_url_project($project, array($locale->slug, $translation_set->slug, '_permissions'))); }
gp_title(sprintf(__('Edit Project %s < GlotPress', 'glotpress'), $project->name)); gp_breadcrumb_project($project); gp_tmpl_header(); ?> <h2><?php echo wptexturize(sprintf(__('Edit project "%s"', 'glotpress'), esc_html($project->name))); ?> </h2> <form action="" method="post"> <?php gp_tmpl_load('project-form', get_defined_vars()); ?> <p> <input type="submit" name="submit" value="<?php esc_attr_e('Save', 'glotpress'); ?> " id="submit" /> <span class="or-cancel"><?php _e('or', 'glotpress'); ?> <a href="<?php echo gp_url_project($project); ?> "><?php _e('Cancel', 'glotpress'); ?> </a></span> </p> </form> <?php gp_tmpl_footer();
function translations_get($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_or_parent_project($translation_set, $project); $page = gp_get('page', 1); $filters = gp_get('filters', array()); $sort = gp_get('sort', array()); if ('random' == gp_array_get($sort, 'by')) { add_filter('gp_pagination', '__return_null'); } $per_page = get_user_option('gp_per_page'); if (0 == $per_page) { $per_page = GP::$translation->per_page; } else { GP::$translation->per_page = $per_page; } $translations = GP::$translation->for_translation($project, $translation_set, $page, $filters, $sort); $total_translations_count = GP::$translation->found_rows; $can_edit = $this->can('edit', 'translation-set', $translation_set->id); $can_write = $this->can('write', 'project', $project->id); $can_approve = $this->can('approve', 'translation-set', $translation_set->id); $url = gp_url_project($project, gp_url_join($locale->slug, $translation_set->slug)); $set_priority_url = gp_url('/originals/%original-id%/set_priority'); $discard_warning_url = gp_url_project($project, gp_url_join($locale->slug, $translation_set->slug, '-discard-warning')); $set_status_url = gp_url_project($project, gp_url_join($locale->slug, $translation_set->slug, '-set-status')); $bulk_action = gp_url_join($url, '-bulk'); // Add action to use different font for translations add_action('gp_head', function () use($locale) { return gp_preferred_sans_serif_style_tag($locale); }); $this->tmpl('translations', get_defined_vars()); }
function test_gp_url_project_should_join_its_array_arguments() { $url_from_gp_url_project = gp_url_project('/x', array('slug', 'slugslug', 'import-translations')); $url_manually_joined = gp_url_join(gp_url_project('/x'), 'slug', 'slugslug', 'import-translations'); $this->assertEquals($url_manually_joined, $url_from_gp_url_project); }
function index() { gp_redirect(gp_url_project('')); }
<?php if ('originals' == $kind) { $title = sprintf(__('Import Originals < %s < GlotPress', 'glotpress'), esc_html($project->name)); $return_link = gp_url_project($project); } else { $title = sprintf(__('Import Translations < %s < GlotPress', 'glotpress'), esc_html($project->name)); $return_link = gp_url_project_locale($project, $locale->slug, $translation_set->slug); } gp_title($title); gp_breadcrumb_project($project); gp_tmpl_header(); ?> <h2><?php echo $kind == 'originals' ? __('Import Originals', 'glotpress') : __('Import Translations', 'glotpress'); ?> </h2> <form action="" method="post" enctype="multipart/form-data"> <dl> <dt><label for="import-file"><?php _e('Import File:', 'glotpress'); ?> </label></dt> <dd><input type="file" name="import-file" id="import-file" /></dd> <?php $format_options = array(); foreach (GP::$formats as $slug => $format) { $format_options[$slug] = $format->name; } $format_dropdown = gp_select('format', $format_options, 'po');
?> %</td> <td class="stats translated" title="translated"><?php gp_link(gp_url_project($project, gp_url_join($set->locale, $set->slug), array('filters[translated]' => 'yes', 'filters[status]' => 'current')), $set->current_count); ?> </td> <td class="stats fuzzy" title="fuzzy"><?php gp_link(gp_url_project($project, gp_url_join($set->locale, $set->slug), array('filters[status]' => 'fuzzy')), $set->fuzzy_count); ?> </td> <td class="stats untranslated" title="untranslated"><?php gp_link(gp_url_project($project, gp_url_join($set->locale, $set->slug), array('filters[status]' => 'untranslated')), $set->untranslated_count); ?> </td> <td class="stats waiting"><?php gp_link(gp_url_project($project, gp_url_join($set->locale, $set->slug), array('filters[translated]' => 'yes', 'filters[status]' => 'waiting')), $set->waiting_count); ?> </td> <?php if (has_action('gp_project_template_translation_set_extra')) { ?> <td class="extra"> <?php do_action('gp_project_template_translation_set_extra', $set, $project); ?> </td> <?php } ?> </tr> <?php
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)); }
<li><?php gp_link_project($project, esc_html($project->name)); ?> <?php gp_link_project_edit($project, null, array('class' => 'bubble')); ?> </li> <?php } ?> </ul> <p class="actionlist secondary"> <?php if (current_user_can('manage_options')) { ?> <?php gp_link(gp_url_project('-new'), __('Create a New Project', 'glotpress')); ?> • <?php } ?> <?php gp_link(gp_url('/languages'), __('Projects by language', 'glotpress')); ?> </p> <?php gp_tmpl_footer();