コード例 #1
0
 /**
  * Import originals for a project from a file
  *
  * ## OPTIONS
  *
  * <project>
  * : Project name
  *
  * <file>
  * : File to import from
  *
  * [--format=<format>]
  * : Accepted values: po, mo, android, resx, strings. Default: po
  */
 public function __invoke($args, $assoc_args)
 {
     // Double-check for compatibility
     if ($args[0] === '-p' || $args[1] === '-f') {
         WP_CLI::error(__('-p and -f are no longer required and should be removed.', 'glotpress'));
     }
     $project = GP::$project->by_path($args[0]);
     if (!$project) {
         WP_CLI::error(__('Project not found!', 'glotpress'));
     }
     $format = isset($assoc_args['format']) ? $assoc_args['format'] : 'po';
     $format = gp_array_get(GP::$formats, $format, null);
     if (!$format) {
         WP_CLI::error(__('No such format.', 'glotpress'));
     }
     $translations = $format->read_originals_from_file($args[1], $project);
     if (!$translations) {
         WP_CLI::error(__("Couldn't load translations from file!", 'glotpress'));
     }
     list($originals_added, $originals_existing, $originals_fuzzied, $originals_obsoleted, $originals_error) = GP::$original->import_for_project($project, $translations);
     $notice = sprintf(__('%1$s new strings added, %2$s updated, %3$s fuzzied, and %4$s obsoleted.', 'glotpress'), $originals_added, $originals_existing, $originals_fuzzied, $originals_obsoleted);
     if ($originals_error) {
         $notice = ' ' . sprintf(_n('%s new string was not imported due to an error.', '%s new strings were not imported due to an error.', $originals_error, 'glotpress'), $originals_error);
     }
     WP_CLI::line($notice);
 }
コード例 #2
0
 /**
  * Export the translation set
  *
  * ## OPTIONS
  *
  * <project>
  * : Project path
  *
  * <locale>
  * : Locale to export
  *
  * [--set=<set>]
  * : Translation set slug; default is "default"
  *
  * [--format=<format>]
  * : Format for output (one of "po", "mo", "android", "resx", "strings"; default is "po")
  *
  * [--search=<search>]
  * : Search term
  *
  * [--status=<status>]
  * : Translation string status; default is "current"
  *
  * [--priority=<priorities>]
  * : Original priorities, comma separated. Possible values are "hidden,low,normal,high"
  */
 public function export($args, $assoc_args)
 {
     $set_slug = isset($assoc_args['set']) ? $assoc_args['set'] : 'default';
     $translation_set = $this->get_translation_set($args[0], $args[1], $set_slug);
     if (is_wp_error($translation_set)) {
         WP_CLI::error($translation_set->get_error_message());
     }
     $format = isset($assoc_args['format']) ? $assoc_args['format'] : 'po';
     $format = gp_array_get(GP::$formats, $format, null);
     if (!$format) {
         WP_CLI::error(__('No such format.', 'glotpress'));
     }
     $filters = array();
     if (isset($assoc_args['search'])) {
         $filters['term'] = $assoc_args['search'];
     }
     $filters['status'] = isset($assoc_args['status']) ? $assoc_args['status'] : 'current';
     if (isset($assoc_args['priority'])) {
         $filters['priority'] = array();
         $priorities = explode(',', $assoc_args['priority']);
         $valid_priorities = GP::$original->get_static('priorities');
         foreach ($priorities as $priority) {
             $key = array_search($priority, $valid_priorities);
             if (false === $key) {
                 WP_CLI::warning(sprintf('Invalid priority %s', $priority));
             } else {
                 $filters['priority'][] = $key;
             }
         }
     }
     $entries = GP::$translation->for_export($this->project, $translation_set, $filters);
     WP_CLI::line($format->print_exported_file($this->project, $this->locale, $translation_set, $entries));
 }
コード例 #3
0
ファイル: _main.php プロジェクト: rmccue/GlotPress
 function _options_from_projects($projects)
 {
     // TODO: mark which nodes are editable by the current user
     $tree = array();
     $top = array();
     foreach ($projects as $p) {
         $tree[$p->id]['self'] = $p;
         if ($p->parent_project_id) {
             $tree[$p->parent_project_id]['children'][] = $p->id;
         } else {
             $top[] = $p->id;
         }
     }
     $options = array('' => __('No parent'));
     $stack = array();
     foreach ($top as $top_id) {
         $stack = array($top_id);
         while (!empty($stack)) {
             $id = array_pop($stack);
             $tree[$id]['level'] = gp_array_get($tree[$id], 'level', 0);
             $options[$id] = str_repeat('-', $tree[$id]['level']) . $tree[$id]['self']->name;
             foreach (gp_array_get($tree[$id], 'children', array()) as $child_id) {
                 $stack[] = $child_id;
                 $tree[$child_id]['level'] = $tree[$id]['level'] + 1;
             }
         }
     }
     return $options;
 }
コード例 #4
0
 function run()
 {
     if (!isset($this->options['p'])) {
         $this->usage();
     }
     $project = GP::$project->by_path($this->options['p']);
     if (!$project) {
         $this->error(__('Project not found!'));
     }
     $format = gp_array_get(GP::$formats, isset($this->options['o']) ? $this->options['o'] : 'po', null);
     if (!$format) {
         $this->error(__('No such format.'));
     }
     $translations = $format->read_originals_from_file($this->options['f'], $project);
     if (!$translations) {
         $this->error(__("Couldn't load translations from file!"));
     }
     $disable_propagating = isset($this->options['disable-propagating']);
     $disable_matching = isset($this->options['disable-matching']);
     if ($disable_propagating) {
         add_filter('enable_propagate_translations_across_projects', '__return_false');
     }
     if ($disable_matching) {
         add_filter('enable_add_translations_from_other_projects', '__return_false');
     }
     list($originals_added, $originals_existing, $originals_fuzzied, $originals_obsoleted) = GP::$original->import_for_project($project, $translations);
     if ($disable_matching) {
         remove_filter('enable_add_translations_from_other_projects', '__return_false');
     }
     if ($disable_propagating) {
         remove_filter('enable_propagate_translations_across_projects', '__return_false');
     }
     printf(__('%1$s new strings added, %2$s updated, %3$s fuzzied, and %4$s obsoleted.'), $originals_added, $originals_existing, $originals_fuzzied, $originals_obsoleted);
     echo "\n";
 }
コード例 #5
0
ファイル: url.php プロジェクト: rmccue/GlotPress
function gp_url_current()
{
    // TODO: https
    // TODO: port
    $host = gp_array_get($_SERVER, 'HTTP_HOST');
    $path_and_args = gp_array_get($_SERVER, 'REQUEST_URI');
    return "http://{$host}{$path_and_args}";
}
コード例 #6
0
 function action_on_translation_set($translation_set)
 {
     $format = gp_array_get(GP::$formats, isset($this->options['o']) ? $this->options['o'] : 'po', null);
     if (!$format) {
         $this->error(__('No such format.'));
     }
     $entries = GP::$translation->for_export($this->project, $translation_set, $this->get_filters_for_translation());
     echo $format->print_exported_file($this->project, $this->locale, $translation_set, $entries) . "\n";
 }
コード例 #7
0
ファイル: install-upgrade.php プロジェクト: rmccue/GlotPress
/**
 * Guesses the final installed URI based on the location of the install script
 *
 * @return string The guessed URI
 */
function guess_uri()
{
    $schema = 'http://';
    if (strtolower(gp_array_get($_SERVER, 'HTTPS')) == 'on') {
        $schema = 'https://';
    }
    $uri = preg_replace('|/[^/]*$|i', '/', $schema . gp_array_get($_SERVER, 'HTTP_HOST') . gp_array_get($_SERVER, 'REQUEST_URI'));
    return rtrim($uri, " \t\n\r\v/") . '/';
}
コード例 #8
0
 function prepare_fields_for_save($args)
 {
     $args = (array) $args;
     $args['object_type'] = $this->object_type;
     if (gp_array_get($args, 'project_id') && gp_array_get($args, 'locale_slug') && gp_array_get($args, 'set_slug') && !gp_array_get($args, 'object_id')) {
         $args['object_id'] = $this->object_id($args['project_id'], $args['locale_slug'], $args['set_slug']);
     }
     $args = parent::prepare_fields_for_save($args);
     return $args;
 }
コード例 #9
0
 function can_user($verdict, $args)
 {
     if (!($verdict === false && $args['action'] == 'approve' && $args['object_type'] == GP::$validator_permission->object_type && $args['object_id'] && $args['user'])) {
         return $verdict;
     }
     list($project_id, $locale_slug, $set_slug) = GP::$validator_permission->project_id_locale_slug_set_slug($args['object_id']);
     if (!gp_array_get($this->permissions_map, $project_id)) {
         return $verdict;
     }
     return $args['user']->can('approve', $args['object_type'], GP::$validator_permission->object_id(gp_array_get($this->permissions_map, $project_id), $locale_slug, $set_slug));
 }
コード例 #10
0
ファイル: translation-set.php プロジェクト: akirk/GlotPress
 /**
  * Export the translation set
  *
  * ## OPTIONS
  *
  * <project>
  * : Project path
  *
  * <locale>
  * : Locale to export
  *
  * [--set=<set>]
  * : Translation set slug; default is "default"
  *
  * [--format=<format>]
  * : Format for output (one of "po", "mo", "android", "resx", "strings"; default is "po")
  *
  * [--search=<search>]
  * : Search term
  *
  * [--status=<status>]
  * : Translation string status; default is "current"
  */
 public function export($args, $assoc_args)
 {
     $set_slug = isset($assoc_args['set']) ? $assoc_args['set'] : 'default';
     $translation_set = $this->get_translation_set($args[0], $args[1], $set_slug);
     if (is_wp_error($translation_set)) {
         WP_CLI::error($translation_set->get_error_message());
     }
     $format = isset($assoc_args['format']) ? $assoc_args['format'] : 'po';
     $format = gp_array_get(GP::$formats, $format, null);
     if (!$format) {
         WP_CLI::error(__('No such format.', 'glotpress'));
     }
     $filters = array();
     if (isset($assoc_args['search'])) {
         $filters['term'] = $assoc_args['search'];
     }
     $assoc_args['status'] = isset($assoc_args['status']) ? $assoc_args['status'] : 'current';
     $entries = GP::$translation->for_export($this->project, $translation_set, $filters);
     WP_CLI::line($format->print_exported_file($this->project, $this->locale, $translation_set, $entries));
 }
コード例 #11
0
ファイル: cli.php プロジェクト: ramiy/GlotPress-WP
 public function run()
 {
     if (!isset($this->options['l']) || !isset($this->options['p'])) {
         $this->usage();
     }
     $this->project = GP::$project->by_path($this->options['p']);
     if (!$this->project) {
         $this->error(__('Project not found!', 'glotpress'));
     }
     $this->locale = GP_Locales::by_slug($this->options['l']);
     if (!$this->locale) {
         $this->error(__('Locale not found!', 'glotpress'));
     }
     $this->options['t'] = gp_array_get($this->options, 't', 'default');
     $this->translation_set = GP::$translation_set->by_project_id_slug_and_locale($this->project->id, $this->options['t'], $this->locale->slug);
     if (!$this->translation_set) {
         $this->error(__('Translation set not found!', 'glotpress'));
     }
     $this->action_on_translation_set($this->translation_set);
 }
コード例 #12
0
ファイル: import-originals.php プロジェクト: akirk/GlotPress
 /**
  * Import originals for a project from a file
  *
  * ## OPTIONS
  *
  * <project>
  * : Project name
  *
  * <file>
  * : File to import from
  *
  * [--format=<format>]
  * : Accepted values: po, mo, android, resx, strings. Default: po
  *
  * [--disable-propagating]
  * : If set, propagation will be disabled.
  *
  * [--disable-matching]
  * : If set, matching will be disabled.
  */
 public function __invoke($args, $assoc_args)
 {
     // Double-check for compatibility
     if ($args[0] === '-p' || $args[1] === '-f') {
         WP_CLI::error(__('-p and -f are no longer required and should be removed.', 'glotpress'));
     }
     $project = GP::$project->by_path($args[0]);
     if (!$project) {
         WP_CLI::error(__('Project not found!', 'glotpress'));
     }
     $format = isset($assoc_args['format']) ? $assoc_args['format'] : 'po';
     $format = gp_array_get(GP::$formats, $format, null);
     if (!$format) {
         WP_CLI::error(__('No such format.', 'glotpress'));
     }
     $translations = $format->read_originals_from_file($args[1], $project);
     if (!$translations) {
         WP_CLI::error(__("Couldn't load translations from file!", 'glotpress'));
     }
     $disable_propagating = isset($assoc_args['disable-propagating']);
     $disable_matching = isset($assoc_args['disable-matching']);
     if ($disable_propagating) {
         add_filter('gp_enable_propagate_translations_across_projects', '__return_false');
     }
     if ($disable_matching) {
         add_filter('gp_enable_add_translations_from_other_projects', '__return_false');
     }
     list($originals_added, $originals_existing, $originals_fuzzied, $originals_obsoleted) = GP::$original->import_for_project($project, $translations);
     if ($disable_matching) {
         remove_filter('gp_enable_add_translations_from_other_projects', '__return_false');
     }
     if ($disable_propagating) {
         remove_filter('gp_enable_propagate_translations_across_projects', '__return_false');
     }
     WP_CLI::line(sprintf(__('%1$s new strings added, %2$s updated, %3$s fuzzied, and %4$s obsoleted.', 'glotpress'), $originals_added, $originals_existing, $originals_fuzzied, $originals_obsoleted));
 }
コード例 #13
0
ファイル: translation.php プロジェクト: rmccue/GlotPress
 function translations_get($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();
     }
     $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', create_function('$html', 'return "";'));
     }
     $translations = GP::$translation->for_translation($project, $translation_set, $page, $filters, $sort);
     $total_translations_count = GP::$translation->found_rows;
     $per_page = GP::$translation->per_page;
     $can_edit = GP::$user->logged_in();
     $can_approve = $this->can('approve', 'translation-set', $translation_set->id);
     $url = gp_url_project($project, gp_url_join($locale->slug, $translation_set->slug));
     $discard_warning_url = gp_url_project($project, gp_url_join($locale->slug, $translation_set->slug, '_discard-warning'));
     $approve_action = gp_url_join($url, '_approve');
     gp_tmpl_load('translations', get_defined_vars());
 }
コード例 #14
0
ファイル: translation.php プロジェクト: akirk/GlotPress
 function _bulk_set_priority($project, $locale, $translation_set, $bulk)
 {
     if ($this->cannot_and_redirect('write', 'project', $project->id)) {
         return;
     }
     $ok = $error = 0;
     foreach ($bulk['row-ids'] as $row_id) {
         $original_id = gp_array_get(explode('-', $row_id), 0);
         $original = GP::$original->get($original_id);
         if (!$original) {
             continue;
         }
         $original->priority = $bulk['priority'];
         if (!$original->validate()) {
             return $this->die_with_error('Invalid priority value!');
         }
         if (!$original->save()) {
             $error++;
         } else {
             $ok++;
         }
     }
     if (0 === $error) {
         $this->notices[] = sprintf(_n('Priority of %d original was modified.', 'Priority of %d originals were modified.', $ok, 'glotpress'), $ok);
     } else {
         if ($ok > 0) {
             $message = sprintf(_n('Error modifying priority of %d original.', 'Error modifying priority of %d originals.', $error, 'glotpress'), $error);
             $message .= sprintf(_n('The remaining %d original was modified successfully.', 'The remaining %d originals were modified successfully.', $ok, 'glotpress'), $ok);
             $this->errors[] = $message;
         } else {
             $this->errors[] = sprintf(_n('Error modifying priority of %d original.', 'Error modifying priority of all %d originals.', $error, 'glotpress'), $error);
         }
     }
 }
コード例 #15
0
ファイル: url.php プロジェクト: johnjamesjacoby/GlotPress-WP
/**
 * The URL of the current page
 */
function gp_url_current()
{
    $protocol = is_ssl() ? 'https://' : 'http://';
    $host = gp_array_get($_SERVER, 'HTTP_HOST');
    $path_and_args = gp_array_get($_SERVER, 'REQUEST_URI');
    return $protocol . $host . $path_and_args;
}
コード例 #16
0
		</tr>
		<tr>
			<th><label for="default_sort[by]"><?php 
_e("Default Sort By:");
?>
</label></th>
			<td><?php 
echo gp_radio_buttons('default_sort[by]', array('original_date_added' => __('Date added (original)'), 'translation_date_added' => __('Date added (translation)'), 'original' => __('Original string'), 'translation' => __('Translation'), 'priority' => __('Priority'), 'references' => __('Filename in source'), 'random' => __('Random')), gp_array_get($default_sort, 'by', 'priority'));
?>
</td>
		</tr>
		<tr>
			<th><label for="default_sort[how]"><?php 
_e("Default Sort Order:");
?>
</label></th>
			<td><?php 
echo gp_radio_buttons('default_sort[how]', array('asc' => __('Ascending'), 'desc' => __('Descending')), gp_array_get($default_sort, 'how', 'desc'));
?>
</td>
		</tr>
	</table>
	<br>
	<input type="submit" name="submit" value="<?php 
esc_attr_e("Change Settings");
?>
">
</form>

<?php 
gp_tmpl_footer();
コード例 #17
0
 function for_translation($project, $translation_set, $page, $filters = array(), $sort = array())
 {
     global $gpdb;
     $locale = GP_Locales::by_slug($translation_set->locale);
     $join_type = 'INNER';
     $sort_bys = array('original' => 'o.singular %s', 'translation' => 't.translation_0 %s', 'priority' => 'o.priority %s, o.date_added DESC', 'random' => 'o.priority DESC, RAND()', 'translation_date_added' => 't.date_added %s', 'original_date_added' => 'o.date_added %s', 'references' => 'o.references');
     $default_sort = GP::$user->current()->sort_defaults();
     $sort_by = gp_array_get($sort_bys, gp_array_get($sort, 'by'), gp_array_get($sort_bys, $default_sort['by']));
     $sort_hows = array('asc' => 'ASC', 'desc' => 'DESC');
     $sort_how = gp_array_get($sort_hows, gp_array_get($sort, 'how'), gp_array_get($sort_hows, $default_sort['how']));
     $where = array();
     if (gp_array_get($filters, 'term')) {
         $like = "LIKE '%" . $gpdb->escape(like_escape(gp_array_get($filters, 'term'))) . "%'";
         $where[] = '(' . implode(' OR ', array_map(function ($x) use($like) {
             return "({$x} {$like})";
         }, array('o.singular', 't.translation_0', 'o.plural', 't.translation_1', 'o.context', 'o.references'))) . ')';
     }
     if (gp_array_get($filters, 'before_date_added')) {
         $where[] = $gpdb->prepare('t.date_added > %s', gp_array_get($filters, 'before_date_added'));
     }
     if (gp_array_get($filters, 'translation_id')) {
         $where[] = $gpdb->prepare('t.id = %d', gp_array_get($filters, 'translation_id'));
     }
     if (gp_array_get($filters, 'original_id')) {
         $where[] = $gpdb->prepare('o.id = %d', gp_array_get($filters, 'original_id'));
     }
     if ('yes' == gp_array_get($filters, 'warnings')) {
         $where[] = 't.warnings IS NOT NULL';
         $where[] = 't.warnings != ""';
     } elseif ('no' == gp_array_get($filters, 'warnings')) {
         $where[] = 't.warnings IS NULL';
     }
     if ('yes' == gp_array_get($filters, 'with_context')) {
         $where[] = 'o.context IS NOT NULL';
     }
     if ('yes' == gp_array_get($filters, 'with_comment')) {
         $where[] = 'o.comment IS NOT NULL AND o.comment <> ""';
     }
     if (gp_array_get($filters, 'user_login')) {
         $user = GP::$user->by_login($filters['user_login']);
         // do not return any entries if the user doesn't exist
         $where[] = $gpdb->prepare('t.user_id = %d', $user && $user->id ? $user->id : -1);
     }
     if (!GP::$user->current()->can('write', 'project', $project->id)) {
         $where[] = 'o.priority > -2';
     }
     $join_where = array();
     $status = gp_array_get($filters, 'status', 'current_or_waiting_or_fuzzy_or_untranslated');
     $statuses = explode('_or_', $status);
     if (in_array('untranslated', $statuses)) {
         if ($statuses == array('untranslated')) {
             $where[] = 't.translation_0 IS NULL';
         }
         $join_type = 'LEFT';
         $join_where[] = 't.status != "rejected"';
         $join_where[] = 't.status != "old"';
         $statuses = array_filter($statuses, function ($x) {
             return $x != 'untranslated';
         });
     }
     $all_statuses = $this->get_static('statuses');
     $statuses = array_filter($statuses, function ($s) use($all_statuses) {
         return in_array($s, $all_statuses);
     });
     if ($statuses) {
         $statuses_where = array();
         foreach ($statuses as $single_status) {
             $statuses_where[] = $gpdb->prepare('t.status = %s', $single_status);
         }
         $statuses_where = '(' . implode(' OR ', $statuses_where) . ')';
         $join_where[] = $statuses_where;
     }
     $where = apply_filters('for_translation_where', $where, $translation_set);
     $where = implode(' AND ', $where);
     if ($where) {
         $where = 'AND ' . $where;
     }
     $join_where = implode(' AND ', $join_where);
     if ($join_where) {
         $join_where = 'AND ' . $join_where;
     }
     $sql_sort = sprintf($sort_by, $sort_how);
     $limit = $this->sql_limit_for_paging($page, $this->per_page);
     $sql_for_translations = "\n\t\t\tSELECT SQL_CALC_FOUND_ROWS t.*, o.*, t.id as id, o.id as original_id, t.status as translation_status, o.status as original_status, t.date_added as translation_added, o.date_added as original_added\n\t\t\tFROM {$gpdb->originals} as o\n\t\t\t{$join_type} JOIN {$gpdb->translations} AS t ON o.id = t.original_id AND t.translation_set_id = " . $gpdb->escape($translation_set->id) . " {$join_where}\n\t\t\tWHERE o.project_id = " . $gpdb->escape($project->id) . " AND o.status LIKE '+%' {$where} ORDER BY {$sql_sort} {$limit}";
     $rows = $this->many_no_map($sql_for_translations);
     $this->found_rows = $this->found_rows();
     $translations = array();
     foreach ((array) $rows as $row) {
         if ($row->user_id && $this->per_page != 'no-limit') {
             $user = GP::$user->get($row->user_id);
             if ($user) {
                 $row->user_login = $user->user_login;
                 $row->user_display_name = $user->display_name;
                 $row->user_nicename = $user->user_nicename;
             }
         } else {
             $row->user_login = $row->user_display_name = $row->user_nicename = '';
         }
         $row->translations = array();
         for ($i = 0; $i < $locale->nplurals; $i++) {
             $row->translations[] = $row->{"translation_" . $i};
         }
         $row->references = preg_split('/\\s+/', $row->references, -1, PREG_SPLIT_NO_EMPTY);
         $row->extracted_comments = $row->comment;
         $row->warnings = $row->warnings ? maybe_unserialize($row->warnings) : null;
         unset($row->comment);
         foreach (range(0, $this->get_static('number_of_plural_translations')) as $i) {
             $member = "translation_{$i}";
             unset($row->{$member});
         }
         $row->row_id = $row->original_id . ($row->id ? "-{$row->id}" : '');
         $translations[] = new Translation_Entry((array) $row);
     }
     unset($rows);
     return $translations;
 }
コード例 #18
0
</label>
				<div class="col-sm-8">
					<?php 
echo GP_Bootstrap_Theme_Hacks::gp_radio_buttons('default_sort[by]', array('original_date_added' => __('Date added (original)'), 'translation_date_added' => __('Date added (translation)'), 'original' => __('Original string'), 'translation' => __('Translation'), 'priority' => __('Priority'), 'references' => __('Filename in source'), 'random' => __('Random')), gp_array_get($default_sort, 'by', 'priority'));
?>
				</div>
			</div>

			<div class="form-group">
				<label for="default_sort[how]" class="col-sm-4 col-md-3 control-label"><?php 
_e("Default Sort Order:");
?>
</label>
				<div class="col-sm-8">
					<?php 
echo GP_Bootstrap_Theme_Hacks::gp_radio_buttons('default_sort[how]', array('asc' => __('Ascending'), 'desc' => __('Descending')), gp_array_get($default_sort, 'how', 'desc'));
?>
				</div>
			</div>


			<div class="form-group">
				<label for="default_theme" class="col-sm-4 col-md-3 control-label"><?php 
_e("Theme:");
?>
</label>
				<div class="col-sm-4">
					<?php 
$default_theme = 'default' == GP::$user->current()->get_meta('default_theme') ? 'default' : 'bootstrap';
echo gp_select('default_theme', array('default' => __('Default theme'), 'bootstrap' => __('Bootstrap theme')), $default_theme, array('class' => 'form-control'));
?>
コード例 #19
0
function textareas($entry, $permissions, $index = 0)
{
    list($can_edit, $can_approve) = $permissions;
    $disabled = $can_edit ? '' : 'disabled="disabled"';
    ?>
	<div class="textareas">
		<?php 
    if (isset($entry->warnings[$index])) {
        $referenceable = $entry->warnings[$index];
        $warning = each($referenceable);
        ?>
			<div class="warning secondary">
				<?php 
        printf(__('<strong>Warning:</strong> %s'), esc_html($warning['value']));
        ?>

				<?php 
        if ($can_approve) {
            ?>
					<a href="#" class="discard-warning" key="<?php 
            echo $warning['key'];
            ?>
" index="<?php 
            echo $index;
            ?>
"><?php 
            _e('Discard');
            ?>
</a>
				<?php 
        }
        ?>
			</div>
		<?php 
    }
    ?>
		<blockquote><em><small><?php 
    echo esc_translation(gp_array_get($entry->translations, $index));
    ?>
</small></em></blockquote>
		<textarea class="foreign-text" name="translation[<?php 
    echo $entry->original_id;
    ?>
][]" <?php 
    echo $disabled;
    ?>
><?php 
    echo esc_translation(gp_array_get($entry->translations, $index));
    ?>
</textarea>

		<p>
			<?php 
    if ($can_edit) {
        gp_entry_actions();
    } elseif (GP::$user->logged_in()) {
        _e('You are not allowed to edit this translation.');
    } else {
        printf(__('You <a href="%s">have to log in</a> to edit this translation.'), gp_url_login());
    }
    ?>
 
		</p>
	</div>
	<?php 
}
コード例 #20
0
ファイル: translations.php プロジェクト: akirk/GlotPress
		<dd>
		<?php 
$default_sort = get_user_option('gp_default_sort');
if (!is_array($default_sort)) {
    $default_sort = array('by' => 'priority', 'how' => 'desc');
}
echo gp_radio_buttons('sort[by]', array('original_date_added' => __('Date added (original)', 'glotpress'), 'translation_date_added' => __('Date added (translation)', 'glotpress'), 'original' => __('Original string', 'glotpress'), 'translation' => __('Translation', 'glotpress'), 'priority' => __('Priority', 'glotpress'), 'references' => __('Filename in source', 'glotpress'), 'random' => __('Random', 'glotpress')), gp_array_get($sort, 'by', $default_sort['by']));
?>
		</dd>
		<dt><?php 
_e('Order:', 'glotpress');
?>
</dt>
		<dd>
		<?php 
echo gp_radio_buttons('sort[how]', array('asc' => __('Ascending', 'glotpress'), 'desc' => __('Descending', 'glotpress')), gp_array_get($sort, 'how', $default_sort['how']));
?>
		</dd>
		<?php 
do_action('gp_translation_set_filters');
?>
		<dd><input type="submit" value="<?php 
esc_attr_e('Sort', 'glotpress');
?>
" name="sorts" /></dd>
	</dl>
</form>

<table id="translations" class="translations clear<?php 
if ('rtl' == $locale->text_direction) {
    echo ' translation-sets-rtl';
コード例 #21
0
ファイル: template.php プロジェクト: rmccue/glotpress-plugin
function gp_projects_dropdown($name_and_id, $selected_project_id = null, $attrs = array())
{
    $projects = GP::$project->all();
    // TODO: mark which nodes are editable by the current user
    $tree = array();
    $top = array();
    foreach ($projects as $p) {
        $tree[$p->id]['self'] = $p;
        if ($p->parent_project_id) {
            $tree[$p->parent_project_id]['children'][] = $p->id;
        } else {
            $top[] = $p->id;
        }
    }
    $options = array('' => __('&mdash; No parent &mdash;'));
    foreach ($top as $top_id) {
        $stack = array($top_id);
        while (!empty($stack)) {
            $id = array_pop($stack);
            $tree[$id]['level'] = gp_array_get($tree[$id], 'level', 0);
            $options[$id] = str_repeat('-', $tree[$id]['level']) . $tree[$id]['self']->name;
            foreach (gp_array_get($tree[$id], 'children', array()) as $child_id) {
                $stack[] = $child_id;
                $tree[$child_id]['level'] = $tree[$id]['level'] + 1;
            }
        }
    }
    return gp_select($name_and_id, $options, $selected_project_id, $attrs);
}
コード例 #22
0
ファイル: misc.php プロジェクト: ramiy/GlotPress-WP
/**
 * Determines the format to use based on the selected format type or by auto detection based on the file name.
 *
 * Used during import of translations and originals.
 *
 * @param string $selected_format The format that the user selected on the import page.
 * @param string $filename The filname that was uploaded by the user.
 * @return object|null A GP_Format child object or null if not found.
 */
function gp_get_import_file_format($selected_format, $filename)
{
    $format = gp_array_get(GP::$formats, $selected_format, null);
    if (!$format) {
        $matched_ext_len = 0;
        foreach (GP::$formats as $format_entry) {
            $format_extensions = $format_entry->get_file_extensions();
            foreach ($format_extensions as $extension) {
                $current_ext_len = strlen($extension);
                if (gp_endswith($filename, $extension) && $current_ext_len > $matched_ext_len) {
                    $format = $format_entry;
                    $matched_ext_len = $current_ext_len;
                }
            }
        }
    }
    return $format;
}
コード例 #23
0
ファイル: translation.php プロジェクト: ramiy/GlotPress-WP
 public function for_translation($project, $translation_set, $page, $filters = array(), $sort = array())
 {
     global $wpdb;
     $locale = GP_Locales::by_slug($translation_set->locale);
     $join_type = 'INNER';
     $sort_bys = wp_list_pluck(gp_get_sort_by_fields(), 'sql_sort_by');
     $default_sort = get_user_option('gp_default_sort');
     if (!is_array($default_sort)) {
         $default_sort = array('by' => 'priority', 'how' => 'desc');
     }
     $sort_by = gp_array_get($sort_bys, gp_array_get($sort, 'by'), gp_array_get($sort_bys, $default_sort['by']));
     $sort_hows = array('asc' => 'ASC', 'desc' => 'DESC');
     $sort_how = gp_array_get($sort_hows, gp_array_get($sort, 'how'), gp_array_get($sort_hows, $default_sort['how']));
     $collation = 'yes' === gp_array_get($filters, 'case_sensitive') ? 'BINARY' : '';
     $where = array();
     if (gp_array_get($filters, 'term')) {
         $like = "LIKE {$collation} '%" . esc_sql($wpdb->esc_like(gp_array_get($filters, 'term'))) . "%'";
         $where[] = '(' . implode(' OR ', array_map(function ($x) use($like) {
             return "({$x} {$like})";
         }, array('o.singular', 't.translation_0', 'o.plural', 't.translation_1', 'o.context', 'o.references'))) . ')';
     }
     if (gp_array_get($filters, 'before_date_added')) {
         $where[] = $wpdb->prepare('t.date_added > %s', gp_array_get($filters, 'before_date_added'));
     }
     if (gp_array_get($filters, 'translation_id')) {
         $where[] = $wpdb->prepare('t.id = %d', gp_array_get($filters, 'translation_id'));
     }
     if (gp_array_get($filters, 'original_id')) {
         $where[] = $wpdb->prepare('o.id = %d', gp_array_get($filters, 'original_id'));
     }
     if ('yes' == gp_array_get($filters, 'warnings')) {
         $where[] = 't.warnings IS NOT NULL';
         $where[] = 't.warnings != ""';
     } elseif ('no' == gp_array_get($filters, 'warnings')) {
         $where[] = 't.warnings IS NULL';
     }
     if ('yes' == gp_array_get($filters, 'with_context')) {
         $where[] = 'o.context IS NOT NULL';
     }
     if ('yes' == gp_array_get($filters, 'with_comment')) {
         $where[] = 'o.comment IS NOT NULL AND o.comment <> ""';
     }
     if (gp_array_get($filters, 'user_login')) {
         $user = get_user_by('login', $filters['user_login']);
         // do not return any entries if the user doesn't exist
         $where[] = $wpdb->prepare('t.user_id = %d', $user && $user->ID ? $user->ID : -1);
     }
     if (!GP::$permission->current_user_can('write', 'project', $project->id)) {
         $where[] = 'o.priority > -2';
     }
     $priorities = gp_array_get($filters, 'priority');
     if ($priorities) {
         $valid_priorities = array_keys(GP::$original->get_static('priorities'));
         $priorities = array_filter(gp_array_get($filters, 'priority'), function ($p) use($valid_priorities) {
             return in_array($p, $valid_priorities, true);
         });
         $priorities_where = array();
         foreach ($priorities as $single_priority) {
             $priorities_where[] = $wpdb->prepare('o.priority = %s', $single_priority);
         }
         if (!empty($priorities_where)) {
             $priorities_where = '(' . implode(' OR ', $priorities_where) . ')';
             $where[] = $priorities_where;
         }
     }
     $join_where = array();
     $status = gp_array_get($filters, 'status', 'current_or_waiting_or_fuzzy_or_untranslated');
     $statuses = explode('_or_', $status);
     if (in_array('untranslated', $statuses)) {
         if ($statuses == array('untranslated')) {
             $where[] = 't.translation_0 IS NULL';
         }
         $join_type = 'LEFT';
         $join_where[] = 't.status != "rejected"';
         $join_where[] = 't.status != "old"';
         $statuses = array_filter($statuses, function ($x) {
             return $x != 'untranslated';
         });
     }
     $all_statuses = $this->get_static('statuses');
     $statuses = array_filter($statuses, function ($s) use($all_statuses) {
         return in_array($s, $all_statuses);
     });
     if (!empty($statuses)) {
         $statuses_where = array();
         foreach ($statuses as $single_status) {
             $statuses_where[] = $wpdb->prepare('t.status = %s', $single_status);
         }
         $statuses_where = '(' . implode(' OR ', $statuses_where) . ')';
         $join_where[] = $statuses_where;
     }
     /**
      * Filter the SQL WHERE clause to get available translations.
      *
      * @since 1.0.0
      *
      * @param array              $where           An array of where conditions.
      * @param GP_Translation_Set $translation_set Current translation set.
      */
     $where = apply_filters('gp_for_translation_where', $where, $translation_set);
     $where = implode(' AND ', $where);
     if ($where) {
         $where = 'AND ' . $where;
     }
     $join_where = implode(' AND ', $join_where);
     if ($join_where) {
         $join_where = 'AND ' . $join_where;
     }
     $sql_sort = sprintf($sort_by, $sort_how);
     $limit = $this->sql_limit_for_paging($page, $this->per_page);
     $sql_for_translations = "\n\t\t\tSELECT SQL_CALC_FOUND_ROWS t.*, o.*, t.id as id, o.id as original_id, t.status as translation_status, o.status as original_status, t.date_added as translation_added, o.date_added as original_added\n\t\t\tFROM {$wpdb->gp_originals} as o\n\t\t\t{$join_type} JOIN {$wpdb->gp_translations} AS t ON o.id = t.original_id AND t.translation_set_id = " . (int) $translation_set->id . " {$join_where}\n\t\t\tWHERE o.project_id = " . (int) $project->id . " AND o.status = '+active' {$where} ORDER BY {$sql_sort} {$limit}";
     $rows = $this->many_no_map($sql_for_translations);
     $this->found_rows = $this->found_rows();
     $translations = array();
     foreach ((array) $rows as $row) {
         $row->user = $row->user_last_modified = null;
         if ($row->user_id && 'no-limit' !== $this->per_page) {
             $row->user = get_userdata($row->user_id);
         }
         if ($row->user_id_last_modified && 'no-limit' !== $this->per_page) {
             $row->user_last_modified = get_userdata($row->user_id_last_modified);
         }
         $row->translations = array();
         for ($i = 0; $i < $locale->nplurals; $i++) {
             $row->translations[] = $row->{"translation_" . $i};
         }
         $row->references = preg_split('/\\s+/', $row->references, -1, PREG_SPLIT_NO_EMPTY);
         $row->extracted_comments = $row->comment;
         $row->warnings = $row->warnings ? maybe_unserialize($row->warnings) : null;
         unset($row->comment);
         foreach (range(0, $this->get_static('number_of_plural_translations')) as $i) {
             $member = "translation_{$i}";
             unset($row->{$member});
         }
         $row->row_id = $row->original_id . ($row->id ? "-{$row->id}" : '');
         $translations[] = new Translation_Entry((array) $row);
     }
     unset($rows);
     return $translations;
 }
コード例 #24
0
			    <dt><?php 
_e('Priority of the original:', 'glotpress');
?>
</dt>
			<?php 
if ($can_write) {
    ?>
				<dd><?php 
    echo gp_select('priority-' . $t->original_id, GP::$original->get_static('priorities'), $t->priority, array('class' => 'priority', 'tabindex' => '-1', 'data-nonce' => wp_create_nonce('set-priority_' . $t->original_id)));
    ?>
</dd>
			<?php 
} else {
    ?>
				<dd><?php 
    echo gp_array_get(GP::$original->get_static('priorities'), $t->priority, 'unknown');
    // WPCS: XSS ok.
    ?>
</dd>
			<?php 
}
?>
			</dl>

			<?php 
$extra_args = $t->translation_status ? array('filters[translation_id]' => $t->id) : array();
?>
			<dl>
			<?php 
$permalink_filters = $t->translation_status ? array('filters[status]' => 'either', 'filters[original_id]' => $t->original_id) : array('filters[original_id]' => $t->original_id);
$permalink = gp_url_project_locale($project, $locale->slug, $translation_set->slug, array_merge($permalink_filters, $extra_args));
コード例 #25
0
ファイル: misc.php プロジェクト: akirk/GlotPress
/**
 * Retrieves a notice message, set by {@link gp_notice()}
 *
 * @param string $key Optional. Message key. The default is 'notice'
 */
function gp_notice($key = 'notice')
{
    // Sanitize fields
    $allowed_tags = array('a' => array('href' => true), 'abbr' => array(), 'acronym' => array(), 'b' => array(), 'br' => array(), 'button' => array('disabled' => true, 'name' => true, 'type' => true, 'value' => true), 'em' => array(), 'i' => array(), 'img' => array('src' => true, 'width' => true, 'height' => true), 'p' => array(), 'pre' => array(), 's' => array(), 'strike' => array(), 'strong' => array(), 'sub' => array(), 'sup' => array(), 'u' => array());
    // Adds class, id, style, title, role attributes to all of the above allowed tags.
    $allowed_tags = array_map('_wp_add_global_attributes', $allowed_tags);
    return wp_kses(gp_array_get(GP::$redirect_notices, $key), $allowed_tags);
}
コード例 #26
0
ファイル: wporg-help.php プロジェクト: serhi/wordpress-sites
 function is_notice_hidden()
 {
     return gp_array_get($_COOKIE, $this->hide_notice) || GP::$user->logged_in() && GP::$user->get_meta($this->hide_notice);
 }
コード例 #27
0
 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));
 }
コード例 #28
0
ファイル: project.php プロジェクト: rmccue/GlotPress
 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'));
     }
 }
コード例 #29
0
 private function _placeholders_counts($string, $re)
 {
     $counts = array();
     preg_match_all("/{$re}/", $string, $matches);
     foreach ($matches[0] as $match) {
         $counts[$match] = gp_array_get($counts, $match, 0) + 1;
     }
     return $counts;
 }
コード例 #30
0
ファイル: validation.php プロジェクト: ramiy/GlotPress-WP
 public static function get($key)
 {
     return gp_array_get(self::$callbacks, $key, null);
 }