function test_gp_link_get_escape() { $this->assertEquals('<a href="http://dir.bg/">Baba & Dyado</a>', gp_link_get('http://dir.bg/', 'Baba & Dyado')); // clean_url() is too restrictive, so it isn't called //$this->assertEquals( '<a href="http://dir.bg/?x=5&y=11">Baba</a>', gp_link_get( 'http://dir.bg/?x=5&y=11', 'Baba' ) ); $this->assertEquals('<a href="http://dir.bg/" a=""">Baba</a>', gp_link_get('http://dir.bg/', 'Baba', array('a' => '"'))); }
public function gp_project_actions($actions, $project) { $project_settings = (array) get_option('gp_auto_extract', array()); if ('none' != $project_settings[$project->id]['type']) { $actions[] .= gp_link_get(gp_url('auto-extract/' . $project->slug), __('Auto Extract')); } return $actions; }
public function gp_pagination($page, $per_page, $objects) { $surrounding = 2; $prev = $first = $prev_dots = $prev_pages = $current = $next_pages = $next_dots = $last = $next = ''; $page = intval($page) ? intval($page) : 1; $pages = ceil($objects / $per_page); if ($page > $pages) { return ''; } if ($page > 1) { $prev = gp_link_get(add_query_arg(array('page' => $page - 1)), '←', array('class' => 'previous', 'before' => '<li>', 'after' => '</li>')); } else { $prev = '<li class="disabled"><span>←</span></li>'; } if ($page < $pages) { $next = gp_link_get(add_query_arg(array('page' => $page + 1)), '→', array('class' => 'next', 'before' => '<li>', 'after' => '</li>')); } else { $next = '<li class="disabled"><span>→</span></li>'; } $current = '<li class="active"><span>' . $page . '</span></li>'; if ($page > 1) { $prev_pages = array(); foreach (range(max(1, $page - $surrounding), $page - 1) as $prev_page) { $prev_pages[] = gp_link_get(add_query_arg(array('page' => $prev_page)), $prev_page, array('before' => '<li>', 'after' => '</li>')); } $prev_pages = implode(' ', $prev_pages); if ($page - $surrounding > 1) { $prev_dots = '<li><span class="dots">…</span></li>'; } } if ($page < $pages) { $next_pages = array(); foreach (range($page + 1, min($pages, $page + $surrounding)) as $next_page) { $next_pages[] = gp_link_get(add_query_arg(array('page' => $next_page)), $next_page, array('before' => '<li>', 'after' => '</li>')); } $next_pages = implode(' ', $next_pages); if ($page + $surrounding < $pages) { $next_dots = '<li><span class="dots">…</span></li>'; } } if ($prev_dots) { $first = gp_link_get(add_query_arg(array('page' => 1)), 1, array('before' => '<li>', 'after' => '</li>')); } if ($next_dots) { $last = gp_link_get(add_query_arg(array('page' => $pages)), $pages, array('before' => '<li>', 'after' => '</li>')); } $html = '<ul class="pagination">'; $html .= "\n\t\t\t{$prev}\n\t\t\t{$first}\n\t\t\t{$prev_dots}\n\t\t\t{$prev_pages}\n\t\t\t{$current}\n\t\t\t{$next_pages}\n\t\t\t{$next_dots}\n\t\t\t{$last}\n\t\t\t{$next}"; $html .= '</ul>'; return apply_filters('gp_pagination', $html, $page, $per_page, $objects); }
<?php gp_title(sprintf(__('Projects translated to %s < GlotPress'), esc_html($locale->english_name))); gp_breadcrumb(array(gp_link_get('/languages', __('Locales')), esc_html($locale->english_name))); gp_tmpl_header(); ?> <h2><?php printf(__('Active Projects translated to %s'), '<span>' . esc_html($locale->english_name) . '</span>'); ?> </h2> <?php if (empty($projects_data)) { _e('No active projects found.'); } ?> <?php foreach ($projects_data as $project_id => $sub_projects) { ?> <div class="locale-project"> <h3><?php echo $projects[$project_id]->name; ?> </h3> <table class="locale-sub-projects table table-striped"> <thead> <tr> <th class="header" <?php
function test_gp_link_get_escape() { $this->assertEquals('<a href="http://dir.bg/">Baba & Dyado</a>', gp_link_get('http://dir.bg/', 'Baba & Dyado')); $this->assertEquals('<a href="http://dir.bg/?x=5&y=11">Baba</a>', gp_link_get('http://dir.bg/?x=5&y=11', 'Baba')); $this->assertEquals('<a href="http://dir.bg/" a=""">Baba</a>', gp_link_get('http://dir.bg/', 'Baba', array('a' => '"'))); }
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();
function gp_project_actions($project, $translation_sets) { $actions = array(gp_link_get(gp_url_project($project, 'import-originals'), __('Import originals')), gp_link_get(gp_url_project($project, array('-permissions')), __('Permissions')), gp_link_get(gp_url_project('', '-new', array('parent_project_id' => $project->id)), __('New Sub-Project')), gp_link_get(gp_url('/sets/-new', array('project_id' => $project->id)), __('New Translation Set')), gp_link_get(gp_url_project($project, array('-mass-create-sets')), __('Mass-create Translation Sets')), gp_link_get(gp_url_project($project, '-branch'), __('Branch Project')), gp_link_with_ays_get(gp_url_project($project, '-delete'), __('Delete Project'), array('ays-text' => 'Do you really want to delete this project?'))); $actions = apply_filters('gp_project_actions', $actions, $project); echo '<ul>'; foreach ($actions as $action) { echo '<li>' . $action . '</li>'; } if ($translation_sets) { echo '<li>' . gp_project_options_form($project) . '</li>'; } echo '</ul>'; }
<?php gp_title(__('View Glossary < GlotPress', 'glotpress')); gp_breadcrumb(array(gp_project_links_from_root($project), gp_link_get(gp_url_project_locale($project->path, $locale->slug, $translation_set->slug), $translation_set->name), __('Glossary', 'glotpress'))); $ge_delete_ays = __('Are you sure you want to delete this entry?', 'glotpress'); $delete_url = $url . '/-delete'; $glossary_options = compact('can_edit', 'url', 'delete_url', 'ge_delete_ays'); gp_enqueue_script('gp-glossary'); wp_localize_script('gp-glossary', '$gp_glossary_options', $glossary_options); gp_tmpl_header(); ?> <h2><?php printf(_x('Glossary for %1$s translation of %2$s', '{language} / { project name}', 'glotpress'), esc_html($translation_set->name), esc_html($project->name)); ?> <?php gp_link_glossary_edit($glossary, $translation_set, __('(edit)', 'glotpress')); ?> </h2> <?php if ($glossary->description) { echo '<p class="description">' . make_clickable(nl2br(wp_kses_post($glossary->description))) . '</p>'; } ?> <table class="glossary" id="glossary"> <thead> <tr> <th style="width:20%"><?php _ex('Item', 'glossary entry', 'glotpress');
function gp_pagination($page, $per_page, $objects) { $surrounding = 2; $prev = $first = $prev_dots = $prev_pages = $current = $next_pages = $next_dots = $last = $next = ''; $page = intval($page) ? intval($page) : 1; $pages = ceil($objects / $per_page); if ($page > $pages) { return ''; } if ($page > 1) { $prev = gp_link_get(add_query_arg(array('page' => $page - 1)), '←', array('class' => 'previous')); } else { $prev = '<span class="previous disabled">←</span>'; } if ($page < $pages) { $next = gp_link_get(add_query_arg(array('page' => $page + 1)), '→', array('class' => 'next')); } else { $next = '<span class="next disabled">→</span>'; } $current = '<span class="current">' . $page . '</span>'; if ($page > 1) { $prev_pages = array(); foreach (range(max(1, $page - $surrounding), $page - 1) as $prev_page) { $prev_pages[] = gp_link_get(add_query_arg(array('page' => $prev_page)), $prev_page); } $prev_pages = implode(' ', $prev_pages); if ($page - $surrounding > 1) { $prev_dots = '<span class="dots">&hellip</span>'; } } if ($page < $pages) { $next_pages = array(); foreach (range($page + 1, min($pages, $page + $surrounding)) as $next_page) { $next_pages[] = gp_link_get(add_query_arg(array('page' => $next_page)), $next_page); } $next_pages = implode(' ', $next_pages); if ($page + $surrounding < $pages) { $next_dots = '<span class="dots">&hellip</span>'; } } if ($prev_dots) { $first = gp_link_get(add_query_arg(array('page' => 1)), 1); } if ($next_dots) { $last = gp_link_get(add_query_arg(array('page' => $pages)), $pages); } $html = <<<HTML \t<div class="paging"> \t\t{$prev} \t\t{$first} \t\t{$prev_dots} \t\t{$prev_pages} \t\t{$current} \t\t{$next_pages} \t\t{$next_dots} \t\t{$last} \t\t{$next} \t</div> HTML; return apply_filters('gp_pagination', $html, $page, $per_page, $objects); }
<?php gp_title(sprintf(__('Projects translated to %s < GlotPress'), esc_html($locale->english_name))); $breadcrumb = array(); $breadcrumb[] = gp_link_get('/languages', __('Locales')); if ('default' == $current_set_slug) { $breadcrumb[] = esc_html($locale->english_name); } else { $breadcrumb[] = gp_link_get(gp_url_join('/languages', $locale->slug), esc_html($locale->english_name)); $breadcrumb[] = $set_list[$current_set_slug]; } gp_breadcrumb($breadcrumb); gp_tmpl_header(); ?> <h2><?php printf(__('Active Projects translated to %s'), '<span>' . esc_html($locale->english_name) . '</span>'); ?> </h2> <?php if (count($set_list) > 1) { ?> <p class="actionlist secondary"> <?php echo implode(' • ', $set_list); ?> </p> <?php } ?>
/** * Creates a HTML link to the delete page for translations sets. * * Does the heavy lifting for gp_link_glossary_delete. * * @since 2.0.0 * * @param GP_Glossary $glossary The glossary to link to. * @param GP_Translation_Set $set The translation set the glossary is for. * @param string $text The text to use for the link. * @param array $attrs Additional attributes to use to determine the classes for the link. * @return string The HTML link. */ function gp_link_glossary_delete_get($glossary, $set, $text = false, $attrs = array()) { if (!GP::$permission->current_user_can('delete', 'translation-set', $set->id)) { return ''; } $text = $text ? $text : __('Delete', 'glotpress'); return gp_link_get(gp_url(gp_url_join('/glossaries', $glossary->id, '-delete')), $text, gp_attrs_add_class($attrs, 'action edit')); }
public function gp_project_actions($actions, $project) { $actions[] .= gp_link_get(gp_url('bulk-translate/' . $project->slug), __('Bulk Google Translate')); return $actions; }
function gp_link_login_get() { return gp_link_get(gp_url('/login'), __('Login'), array('title' => __('Sign into GlotPress'))); }
<?php if ('originals' == $kind) { $title = sprintf(__('Import Originals < %s < GlotPress', 'glotpress'), esc_html($project->name)); $return_link = gp_url_project($project); gp_breadcrumb_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_breadcrumb(array(gp_project_links_from_root($project), gp_link_get($return_link, $translation_set->name))); } gp_title($title); 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(); $format_options['auto'] = __('Auto Detect', 'glotpress'); foreach (GP::$formats as $slug => $format) { $format_options[$slug] = $format->name;
<?php /** * Templates: Delete Translation Set * * @package GlotPress * @subpackage Templates * @since 2.0.0 */ gp_title(sprintf(__('Delete Translation Set < %s < %s < GlotPress', 'glotpress'), $set->name, $project->name)); gp_breadcrumb(array(gp_project_links_from_root($project), gp_link_get($url, $locale->english_name . ('default' !== $set->slug ? ' ' . $set->name : '')))); gp_tmpl_header(); ?> <h2><?php _e('Delete Translation Set', 'glotpress'); ?> </h2> <form action="" method="post"> <p> <?php _e('Note this will delete all translations associated with this set!', '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'); ?>
foreach ($locales as $locale) { $class = 'odd' === $class ? 'even' : 'odd'; ?> <tr class="<?php echo $class; // WPCS: XSS ok. ?> "> <?php echo '<td>' . gp_link_get(gp_url_join(gp_url_current(), $locale->slug), $locale->english_name) . '</td>'; ?> <?php echo '<td>' . gp_link_get(gp_url_join(gp_url_current(), $locale->slug), $locale->native_name) . '</td>'; ?> <?php echo '<td>' . gp_link_get(gp_url_join(gp_url_current(), $locale->slug), $locale->slug) . '</td>'; ?> </tr> <?php } ?> </tbody> </table> <script type="text/javascript" charset="utf-8"> jQuery(document).ready(function($) { $('.locales').tablesorter({ theme: 'glotpress', sortList: [[0,0]], headers: { 0: {
<tbody> <?php foreach ($locales as $locale) { ?> <tr class="<?php echo $parity(); ?> "> <?php echo "<td>" . gp_link_get(gp_url_join(gp_url_current(), $locale->slug), $locale->english_name) . "</td>"; ?> <?php echo "<td>" . gp_link_get(gp_url_join(gp_url_current(), $locale->slug), $locale->native_name) . "</td>"; ?> <?php echo "<td>" . gp_link_get(gp_url_join(gp_url_current(), $locale->slug), $locale->slug) . "</td>"; ?> </tr> <?php } ?> </tbody> </table> <script type="text/javascript" charset="utf-8"> jQuery(document).ready(function($) { $('.locales').tablesorter({ headers: { 0: { sorter: 'text' }
<?php gp_title(sprintf(__('Edit Translation Set < %s < %s < GlotPress'), $set->name, $project->name)); gp_breadcrumb(array(gp_link_project_get($project, $project->name), gp_link_get($url, $locale->english_name . 'default' != $set->slug ? ' ' . $set->name : ''))); gp_tmpl_header(); ?> <h2><?php _e('Edit Translation Set'); ?> </h2> <form action="" method="post"> <?php gp_tmpl_load('translation-set-form', get_defined_vars()); ?> <p> <input type="submit" name="submit" value="<?php echo esc_attr(__('Save')); ?> " id="submit" /> <span class="or-cancel">or <a href="javascript:history.back();">Cancel</a></span> </p> </form> <?php gp_tmpl_footer();
function gp_link_glossary_edit_get($glossary, $set, $text = false, $attrs = array()) { if (!GP::$user->current()->can('approve', 'translation_set', $set->id)) { return ''; } $text = $text ? $text : __('Edit'); return gp_link_get(gp_url(gp_url_join('/glossaries', $glossary->id, '-edit')), $text, gp_attrs_add_class($attrs, 'action edit')); }
public function gp_project_actions($actions, $project) { $actions[] .= gp_link_get(gp_url('bulk-export/' . $project->slug), __('Bulk Export Translations')); return $actions; }
</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();
public function single($locale_slug, $current_set_slug = 'default') { $locale = GP_Locales::by_slug($locale_slug); $sets = GP::$translation_set->by_locale($locale_slug); usort($sets, array($this, 'sort_sets_by_project_id')); $locale_projects = $projects_data = $projects = $parents = $set_slugs = $set_list = array(); //TODO: switch to wp_list_pluck foreach ($sets as $key => $value) { $locale_projects[$key] = $value->project_id; } foreach ($sets as $set) { $set_slugs[$set->slug] = $set; if ($current_set_slug != $set->slug) { continue; } // Store project data for later use if (isset($projects[$set->project_id])) { $set_project = $projects[$set->project_id]; } else { $set_project = GP::$project->get($set->project_id); $projects[$set->project_id] = $set_project; } // We only want to list active projects if (!isset($set_project->active) || $set_project->active == false) { continue; } $parent_id = is_null($set_project->parent_project_id) ? $set_project->id : $set_project->parent_project_id; // Store parent project data for later use if (isset($projects[$parent_id])) { $parent_project = $projects[$parent_id]; } else { $parent_project = GP::$project->get($parent_id); $projects[$parent_id] = $parent_project; } // Store parent id for $parents[$set_project->id] = $parent_id; if (!in_array($set_project->parent_project_id, $locale_projects)) { $projects_data[$parent_id][$set_project->id]['project'] = $set_project; $projects_data[$parent_id][$set_project->id]['sets'][$set->id] = $this->set_data($set, $set_project); $projects_data[$parent_id][$set_project->id]['totals'] = $this->set_data($set, $set_project); if (!isset($projects_data[$parent_id][$set_project->id]['project'])) { $projects_data[$parent_id][$set_project->id]['project'] = $set_project; } } else { while (!in_array($parent_id, array_keys($projects_data)) && isset($parents[$parent_id])) { $previous_parent = $parent_id; $parent_id = $parents[$parent_id]; } //Orphan project - a sub project is set to active, while it's parent isn't if (!isset($projects_data[$parent_id])) { continue; } //For when root project has sets, and sub projects. if (!isset($previous_parent) || !isset($projects_data[$parent_id][$previous_parent])) { $previous_parent = $parent_id; } $set_data = $projects_data[$parent_id][$previous_parent]['totals']; $projects_data[$parent_id][$previous_parent]['sets'][$set->id] = $this->set_data($set, $set_project); $projects_data[$parent_id][$previous_parent]['totals'] = $this->set_data($set, $set_project, $set_data); } } if ('default' !== $current_set_slug && !isset($set_slugs[$current_set_slug])) { return $this->die_with_404(); } if ($set_slugs) { // Make default the first item. if (!empty($set_slugs['default'])) { $default = $set_slugs['default']; unset($set_slugs['default']); array_unshift($set_slugs, $default); } foreach ($set_slugs as $set) { if ('default' == $set->slug) { if ('default' != $current_set_slug) { $set_list[$set->slug] = gp_link_get(gp_url_join('/languages', $locale->slug), __('Default')); } else { $set_list[$set->slug] = __('Default'); } } else { if ($set->slug != $current_set_slug) { $set_list[$set->slug] = gp_link_get(gp_url_join('/languages', $locale->slug, $set->slug), esc_html($set->name)); } else { $set_list[$set->slug] = esc_html($set->name); } } } } $this->tmpl('locale', get_defined_vars()); }
<div class="validates-projects"> <h3><?php _e('Validator to'); ?> </h3> <?php if (count($permissions) >= 1) { ?> <ul> <?php foreach ($permissions as $permission) { ?> <li> <p> <?php echo gp_link_get($permission->project_url, $permission->set_name); ?> </p> </li> <?php } ?> </ul> <?php } else { ?> <p><?php printf('%s is not validating any projects!', $user->display_name); ?> </p> <?php
function gp_project_actions($project, $translation_sets) { $actions = array(gp_link_get(gp_url_project($project, 'import-originals'), __('Import originals', 'glotpress')), gp_link_get(gp_url_project($project, array('-permissions')), __('Permissions', 'glotpress')), gp_link_get(gp_url_project('', '-new', array('parent_project_id' => $project->id)), __('New Sub-Project', 'glotpress')), gp_link_get(gp_url('/sets/-new', array('project_id' => $project->id)), __('New Translation Set', 'glotpress')), gp_link_get(gp_url_project($project, array('-mass-create-sets')), __('Mass-create Translation Sets', 'glotpress')), gp_link_get(gp_url_project($project, '-branch'), __('Branch Project', 'glotpress')), gp_link_get(gp_url_project($project, '-delete'), __('Delete Project', 'glotpress'))); /** * Project action links. * * @since 1.0.0 * * @param array $actions Links as HTML strings. * @param GP_Project $project The project. */ $actions = apply_filters('gp_project_actions', $actions, $project); echo '<ul>'; foreach ($actions as $action) { echo '<li>' . $action . '</li>'; } if ($translation_sets) { echo '<li>' . gp_project_options_form($project) . '</li>'; } echo '</ul>'; }