'String Translation', 'ajax' => false )); $this->languages = fansub_get_qtranslate_x_enabled_languages(); $this->strings = fansub_get_registered_string_language(); $this->active_strings = fansub_get_active_registered_string_language(); if(!is_array($this->active_strings)) { $this->active_strings = array(); } $this->groups = array_unique(wp_list_pluck($this->strings, 'context')); $this->selected_group = empty($_GET['group']) || !in_array($_GET['group'], $this->groups) ? -1 : $_GET['group']; $this->save_translations(); } function get_columns() { $columns = array( 'cb' => '', 'string' => __('String', 'fansub'), 'name' => __('Name', 'fansub'), 'context' => __('Group', 'fansub'), 'translations' => __('Translation', 'fansub'), ); return $columns; } function get_sortable_columns() { return array( 'string' => array('string', false), 'name' => array('name', false), 'context' => array('context', false), ); } protected function usort_reorder($a, $b) { $result = strcmp($a[$_GET['orderby']], $b[$_GET['orderby']]); return (empty($_GET['order']) || 'asc' === $_GET['order']) ? $result : -$result; } function prepare_items() { $data = $this->strings; $active_data = $this->active_strings; $s = empty($_GET['s']) ? '' : wp_unslash($_GET['s']); foreach($data as $key => $row) { if((-1 !== $this->selected_group && $row['context'] !== $this->selected_group) || (!empty($s) && stripos($row['name'], $s) === false && stripos($row['string'], $s) === false)) { unset($data[$key]); } } $count = 0; foreach($data as $key => $row) { $data[$key]['row'] = $count; $mo = new HOCWP_MO(); $translation = $mo->import_from_db($row['string']); $data[$key]['translation'] = $translation; if(!isset($active_data[$key])) { $data[$key]['bulk_action'] = true; } $count++; } $per_page = $this->get_items_per_page('fansub_string_translation_posts_per_page'); $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns()); if(!empty($_GET['orderby'])) { usort($data, array(&$this, 'usort_reorder')); } $total_items = count($data); $this->items = array_slice($data, ($this->get_pagenum() - 1) * $per_page, $per_page); $this->set_pagination_args(array( 'total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page) )); } function get_bulk_actions() { return array('delete' => __('Delete', 'fansub')); } public function current_action() { return empty($_POST['submit']) ? parent::current_action() : false; } function extra_tablenav($which) { if('top' !== $which) { return; } echo '
'; printf('', __( 'Filter by group', 'fansub')); echo ''."\n"; submit_button(__('Filter'), 'button', 'filter_action', false, array('id' => 'post-query-submit')); echo '
'; } public function display_tablenav($which) { ?>
has_items()) : ?>
bulk_actions($which); ?>
extra_tablenav($which); $this->pagination($which); ?>
%2$s', esc_attr(fansub_get_value_by_key($item, 'row')), sprintf(__('Select %s'), format_to_edit($item['string'])), md5($item['string']), empty($item['bulk_action']) ? 'disabled' : '' ); } function column_string($item) { return format_to_edit($item['string']); } function column_translations($item) { $out = ''; $string = fansub_get_value_by_key($item, 'string'); if(!empty($string)) { $input_type = $item['multiline'] ? '' : ''; $out .= sprintf( $input_type, esc_attr(md5($string)), esc_attr($item['row']), format_to_edit($item['translation']) ); } return $out; } }