first commit

This commit is contained in:
2023-09-12 21:41:04 +02:00
commit 3361a7f053
13284 changed files with 2116755 additions and 0 deletions

View File

@@ -0,0 +1,94 @@
<?php
namespace WPML\TM\Menu\Dashboard;
use WPML\FP\Lst;
use WPML\TM\ATE\Review\ReviewStatus;
class PostJobsRepository {
/**
* @param int $original_element_id
* @param string $element_type
*
* @return array
*/
public function getJobsGroupedByLang( $original_element_id, $element_type ) {
return $this->getJobsFor( $original_element_id, $element_type )
->map( [ $this, 'mapJob' ] )
->keyBy( 'targetLanguage' )
->toArray();
}
/**
* @param int $original_element_id
* @param string $element_type
*
* @return \WPML\Collect\Support\Collection
*/
private function getJobsFor( $original_element_id, $element_type ) {
return \wpml_collect(
wpml_tm_get_jobs_repository()->get( $this->buildSearchParams( $original_element_id, $element_type ) )
);
}
/**
* @param int $original_element_id
* @param string $element_type
*
* @return \WPML_TM_Jobs_Search_Params
*/
private function buildSearchParams( $original_element_id, $element_type ) {
$params = new \WPML_TM_Jobs_Search_Params();
$params->set_original_element_id( $original_element_id );
$params->set_job_types( $element_type );
return $params;
}
/**
* @param \WPML_TM_Post_Job_Entity $job
*
* @return array
*/
public function mapJob( \WPML_TM_Post_Job_Entity $job ) {
return [
'entity_id' => $job->get_id(),
'job_id' => $job->get_translate_job_id(),
'type' => $job->get_type(),
'status' => $this->getJobStatus( $job ),
'targetLanguage' => $job->get_target_language(),
'isLocal' => 'local' === $job->get_translation_service(),
'needsReview' => Lst::includes( $job->get_review_status(), [ ReviewStatus::NEEDS_REVIEW, ReviewStatus::EDITING ] ),
'automatic' => $job->is_automatic(),
'editor' => $job->get_editor(),
];
}
/**
* @param \WPML_TM_Job_Entity $job
*
* @return int
*/
private function getJobStatus( \WPML_TM_Job_Entity $job ) {
if ( $job->does_need_update() ) {
return ICL_TM_NEEDS_UPDATE;
}
if ( $this->postHasTranslationButLatestJobCancelled( $job ) ) {
return ICL_TM_COMPLETE;
}
return $job->get_status();
}
/**
* @param \WPML_TM_Job_Entity $job
*
* @return bool
*/
private function postHasTranslationButLatestJobCancelled( \WPML_TM_Job_Entity $job ) {
return $job->get_status() === ICL_TM_NOT_TRANSLATED && $job->has_completed_translation();
}
}

View File

@@ -0,0 +1,375 @@
<?php
use WPML\FP\Obj;
use WPML\Element\API\Languages;
use WPML\Setup\Option;
use WPML\API\PostTypes;
use WPML\FP\Lst;
class WPML_TM_Dashboard_Display_Filter {
const PARENT_TAXONOMY_CONTAINER = 'parent-taxonomy-container';
const PARENT_SELECT_ID = 'parent-filter-control';
const PARENT_SELECT_NAME = 'filter[parent_type]';
const PARENT_OR_TAXONOMY_ITEM_CONTAINER = 'parent-taxonomy-item-container';
private $active_languages = array();
private $translation_filter;
private $post_types;
private $post_statuses;
private $source_language_code;
private $priorities;
/** @var wpdb $wpdb */
private $wpdb;
public function __construct(
$active_languages,
$source_language_code,
$translation_filter,
$post_types,
$post_statuses,
array $priorities,
wpdb $wpdb
) {
$this->active_languages = $active_languages;
$this->translation_filter = $translation_filter;
$this->source_language_code = $source_language_code;
$this->post_types = $post_types;
$this->post_statuses = $post_statuses;
$this->priorities = $priorities;
$this->wpdb = $wpdb;
}
private function from_lang_select() {
$select_attributes_id = 'icl_language_selector';
$select_attributes_name = 'filter[from_lang]';
$select_attributes_label = __( 'in', 'wpml-translation-management' );
$fromLang = $this->get_language_from();
if ( $fromLang && ! Obj::prop( $fromLang, $this->active_languages ) ) {
$this->active_languages [ $fromLang ] = Languages::getLanguageDetails( $fromLang );
}
?>
<label for="<?php echo esc_attr( $select_attributes_id ); ?>">
<?php echo esc_html( $select_attributes_label ); ?>
</label>
<?php
if ( $this->source_language_code ) {
$tooltip = $this->get_from_language_filter_lock_message_if_required();
?>
<input type="hidden" id="<?php echo esc_attr( $select_attributes_id ); ?>" name="<?php echo esc_attr( $select_attributes_name ); ?>" value="<?php echo esc_attr( $this->get_language_from() ); ?>"/>
<span class="wpml-tm-filter-disabled js-otgs-popover-tooltip" title="<?php echo esc_attr( $tooltip ); ?>"><?php echo esc_html( $this->active_languages[ $this->get_language_from() ]['display_name'] ); ?></span>
<?php
} else {
?>
<select id="<?php echo esc_attr( $select_attributes_id ); ?>" name="<?php echo esc_attr( $select_attributes_name ); ?>" title="<?php echo esc_attr( $select_attributes_label ); ?>">
<?php
foreach ( $this->active_languages as $lang ) {
$selected = '';
if ( $this->get_language_from() && $lang['code'] == $this->get_language_from() ) {
$selected = 'selected="selected"';
}
?>
<option value="<?php echo esc_attr( $lang['code'] ); ?>" <?php echo $selected; ?>>
<?php
echo esc_html( $lang['display_name'] );
?>
</option>
<?php
}
?>
</select>
<?php
}
?>
<?php
}
private function get_language_from() {
$languages_from = $this->source_language_code;
if ( ! $languages_from ) {
$languages_from = $this->get_language_from_filter();
}
return $languages_from;
}
private function get_language_from_filter() {
if ( array_key_exists( 'from_lang', $this->translation_filter ) && $this->translation_filter['from_lang'] ) {
return $this->translation_filter['from_lang'];
}
return null;
}
private function to_lang_select() {
?>
<label for="filter_to_lang">
<?php esc_html_e( 'translated to', 'wpml-translation-management' ); ?>
</label>
<select id="filter_to_lang" name="filter[to_lang]">
<option value=""><?php esc_html_e( 'Any language', 'wpml-translation-management' ); ?></option>
<?php
foreach ( $this->active_languages as $lang ) {
$selected = selected( $this->translation_filter['to_lang'], $lang['code'], false );
?>
<option value="<?php echo esc_attr( $lang['code'] ); ?>" <?php echo $selected; ?>>
<?php echo esc_html( $lang['display_name'] ); ?>
</option>
<?php
}
?>
</select>
<?php
}
private function translation_status_select() {
?>
<select id="filter_tstatus" name="filter[tstatus]" title="<?php esc_attr_e( 'Translation status', 'wpml-translation-management' ); ?>">
<?php
$option_status = array(
-1 => esc_html__( 'All translation statuses', 'wpml-translation-management' ),
ICL_TM_NOT_TRANSLATED => esc_html__( 'Not translated', 'wpml-translation-management' ),
ICL_TM_NOT_TRANSLATED . '_' . ICL_TM_NEEDS_UPDATE => esc_html__(
'Not translated or needs updating',
'wpml-translation-management'
),
ICL_TM_NEEDS_UPDATE => esc_html__( 'Needs updating', 'wpml-translation-management' ),
ICL_TM_IN_PROGRESS => esc_html__( 'Translation in progress', 'wpml-translation-management' ),
ICL_TM_COMPLETE => esc_html__( 'Translation complete', 'wpml-translation-management' ),
);
foreach ( $option_status as $status_key => $status_value ) {
$selected = selected( $this->translation_filter['tstatus'], $status_key, false );
?>
<option value="<?php echo $status_key; ?>" <?php echo $selected; ?>><?php echo $status_value; ?></option>
<?php
}
?>
</select>
<?php
}
private function get_from_language_filter_lock_message_if_required() {
$basket_locked_string = null;
if ( $this->source_language_code && isset( $this->active_languages[ $this->source_language_code ] ) ) {
$language_name = $this->active_languages[ $this->source_language_code ]['display_name'];
$basket_locked_string = '<p>';
$basket_locked_string .= sprintf(
esc_html__(
'Language filtering has been disabled because you already have items in %s in the basket.',
'wpml-translation-management'
),
$language_name
);
$basket_locked_string .= '<br/>';
$basket_locked_string .= esc_html__(
'To re-enable it, please empty the basket or send it for translation.',
'wpml-translation-management'
);
$basket_locked_string .= '</p>';
}
return $basket_locked_string;
}
private function display_post_type_select() {
$selected_type = isset( $this->translation_filter['type'] ) ? $this->translation_filter['type'] : false;
?>
<select id="filter_type" name="filter[type]" title="<?php esc_attr_e( 'Element type', 'wpml-translation-management' ); ?>">
<option value=""><?php esc_html_e( 'All types', 'wpml-translation-management' ); ?></option>
<?php
foreach ( $this->post_types as $post_type_key => $post_type ) {
$filter_type_selected = selected( $selected_type, $post_type_key, false );
$hierarchical = is_post_type_hierarchical( $post_type_key ) ? 'true' : 'false';
$taxonomy_string = '';
foreach ( get_object_taxonomies( $post_type_key, 'objects' ) as $taxonomy => $taxonomy_object ) {
if ( $this->has_taxonomy_terms_in_any_language( $taxonomy ) ) {
if ( $taxonomy_string ) {
$taxonomy_string .= ',';
}
$taxonomy_string .= $taxonomy . '=' . $taxonomy_object->label;
}
}
?>
<option
value="<?php echo $post_type_key; ?>"
data-parent="<?php echo $hierarchical; ?>"
data-taxonomy="<?php echo $taxonomy_string; ?>"
<?php echo $filter_type_selected; ?>
>
<?php
echo $post_type->labels->singular_name != '' ? $post_type->labels->singular_name
: $post_type->labels->name;
?>
</option>
<?php
}
?>
</select>
<?php
}
private function display_parent_taxonomy_controls() {
?>
<span id="<?php echo self::PARENT_TAXONOMY_CONTAINER; ?>" style="display:none;">
<label for="<?php echo self::PARENT_SELECT_ID; ?>">
<?php esc_html_e( 'parent', 'wpml-translation-management' ); ?>
</label>
<select
id="<?php echo self::PARENT_SELECT_ID; ?>"
name="<?php echo self::PARENT_SELECT_NAME; ?>"
data-original="<?php echo isset( $this->translation_filter['parent_type'] ) ? $this->translation_filter['parent_type'] : 'any'; ?>"
>
</select>
<span name="<?php echo self::PARENT_OR_TAXONOMY_ITEM_CONTAINER; ?>" class="<?php echo self::PARENT_OR_TAXONOMY_ITEM_CONTAINER; ?>">
<input type="hidden" name="filter[parent_id]" value="<?php echo isset( $this->translation_filter['parent_id'] ) ? $this->translation_filter['parent_id'] : ''; ?>"/>
</span>
</span>
<?php
}
private function filter_title_textbox() {
$title = isset( $this->translation_filter['title'] ) ? $this->translation_filter['title'] : '';
?>
<input type="text" id="filter_title" name="filter[title]"
value="<?php echo esc_attr( $title ); ?>"
placeholder="<?php esc_attr_e( 'Title', 'wpml-translation-management' ); ?>"
/>
<?php
}
private function display_post_statuses_select() {
$filter_post_status = isset( $this->translation_filter['status'] ) ? $this->translation_filter['status']
: false;
?>
<select id="filter_status" name="filter[status]" title="<?php esc_attr_e( 'Publish status', 'wpml-translation-management' ); ?>">
<option value=""><?php esc_html_e( 'All statuses', 'wpml-translation-management' ); ?></option>
<?php
foreach ( $this->post_statuses as $post_status_k => $post_status ) {
$post_status_selected = selected( $filter_post_status, $post_status_k, false );
?>
<option value="<?php echo $post_status_k; ?>" <?php echo $post_status_selected; ?>>
<?php echo $post_status; ?>
</option>
<?php
}
?>
</select>
<?php
}
private function display_post_translation_priority_select() {
$filter_translation_priority = isset( $this->translation_filter['translation_priority'] ) ? $this->translation_filter['translation_priority']
: false;
?>
<select id="filter_translation_priority" name="filter[translation_priority]" title="<?php esc_attr_e( 'Priority', 'wpml-translation-management' ); ?>">
<option value=""><?php esc_html_e( 'All Translation Priorities', 'wpml-translation-management' ); ?></option>
<?php
foreach ( $this->priorities as $priority ) {
$translation_priority_selected = selected( $filter_translation_priority, $priority->term_id, false );
?>
<option value="<?php echo esc_attr( $priority->term_id ); ?>" <?php echo $translation_priority_selected; ?>>
<?php echo esc_html( $priority->name ); ?>
</option>
<?php
}
?>
</select>
<?php
}
private function display_button() {
$reset_url = $this->get_admin_page_url(
array(
'page' => WPML_TM_FOLDER . '/menu/main.php',
'sm' => 'dashboard',
'icl_tm_action' => 'reset_dashboard_filters',
)
);
?>
<input id="translation_dashboard_filter" name="translation_dashboard_filter"
class="button-secondary" type="submit"
value="<?php esc_attr_e( 'Filter', 'wpml-translation-management' ); ?>"/>
<a type="reset" href="<?php echo esc_url( $reset_url ); ?>" class="wpml-reset-filter"><i class="otgs-ico-close"> </i><?php esc_html_e( 'Reset filter', 'wpml-translation-management' ); ?></a>
<?php
}
public function display() {
$form_url = $this->get_admin_page_url(
array(
'page' => WPML_TM_FOLDER . '/menu/main.php',
'sm' => 'dashboard',
)
);
$postTypes = Lst::joinWithCommasAndAnd( PostTypes::withNames( PostTypes::getAutomaticTranslatable() ) );
?>
<?php echo \WPML\TM\ATE\Loader::getWpmlAutoTranslateContainer(); ?>
<?php if ( Option::shouldTranslateEverything() ): ?>
<h2 class="wpml-tm-dashboard-h2">
<?php _e( 'Translate other content', 'wpml-translation-management' ); ?>
</h2>
<p class="wpml-tm-dashboard-paragraph-extra-space-bottom">
<?php echo sprintf( __( 'WPML is automatically translating published %s.', 'wpml-translation-management' ), $postTypes ); ?>
<br />
<?php _e( 'To translate other content, select your items for translation and your preferred translation options below.', 'wpml-translation-management' ); ?>
</p>
<?php endif; ?>
<form method="post" name="translation-dashboard-filter" class="wpml-tm-dashboard-filter" action="<?php echo esc_url( $form_url ); ?>">
<input type="hidden" name="icl_tm_action" value="dashboard_filter"/>
<?php
do_action( 'display_basket_notification', 'tm_dashboard_top' );
$this->heading( __( '1. Select items for translation', 'wpml-translation-management' ) );
$this->display_post_type_select();
$this->display_parent_taxonomy_controls();
$this->from_lang_select();
$this->to_lang_select();
$this->translation_status_select();
$this->display_post_statuses_select();
$this->display_post_translation_priority_select();
$this->filter_title_textbox();
$this->display_button();
?>
</form>
<?php
}
private function has_taxonomy_terms_in_any_language( $taxonomy ) {
return $this->wpdb->get_var(
$this->wpdb->prepare(
"SELECT COUNT(translation_id) FROM {$this->wpdb->prefix}icl_translations WHERE element_type=%s",
'tax_' . $taxonomy
)
) > 0;
}
private function heading( $text ) {
?>
<h3 class="wpml-tm-section-header wpml-tm-dashboard-h3"><?php echo esc_html( $text ); ?></h3>
<?php
}
private function get_admin_page_url( array $query_args ) {
$base_url = admin_url( 'admin.php' );
return add_query_arg( $query_args, $base_url );
}
}

View File

@@ -0,0 +1,378 @@
<?php
use WPML\TM\Menu\Dashboard\PostJobsRepository;
use WPML\TM\API\Jobs;
class WPML_TM_Dashboard_Document_Row {
/** @var stdClass $data */
private $data;
private $post_types;
private $active_languages;
private $selected;
private $note_text;
private $note_icon_class;
private $post_statuses;
/** @var SitePress $sitepress */
private $sitepress;
/** @var WPML_TM_Translatable_Element_Provider $translatable_element_provider */
private $translatable_element_provider;
public function __construct(
$doc_data,
$post_types,
$post_statuses,
$active_languages,
$selected,
SitePress $sitepress,
WPML_TM_Translatable_Element_Provider $translatable_element_provider
) {
$this->data = $doc_data;
$this->post_statuses = $post_statuses;
$this->selected = $selected;
$this->post_types = $post_types;
$this->active_languages = $active_languages;
$this->sitepress = $sitepress;
$this->translatable_element_provider = $translatable_element_provider;
}
public function get_word_count() {
$current_document = $this->data;
$type = 'post';
if ( $this->is_external_type() ) {
$type = 'package';
}
$translatable_element = $this->translatable_element_provider->get_from_type( $type, $current_document->ID );
return apply_filters(
'wpml_tm_estimated_words_count',
$translatable_element->get_words_count(),
$current_document
);
}
public function get_title() {
return $this->data->title ? $this->data->title : __( '(missing title)', 'wpml-translation-management' );
}
private function is_external_type() {
$doc = $this->data;
return strpos( $doc->translation_element_type, 'post_' ) !== 0;
}
public function get_type_prefix() {
$type = $this->data->translation_element_type;
$type = explode( '_', $type );
if ( count( $type ) > 1 ) {
$type = $type[0];
}
return $type;
}
public function get_type() {
$type = $this->data->translation_element_type;
$type = explode( '_', $type );
if ( count( $type ) > 1 ) {
unset( $type[0] );
}
$type = join( '_', $type );
return $type;
}
public function display() {
global $iclTranslationManagement;
$current_document = $this->data;
$count = $this->get_word_count();
$post_actions = array();
$post_actions_link = '';
$element_type = $this->get_type_prefix();
$check_field_name = $element_type;
$post_title = $this->get_title();
$post_status = $this->get_general_status() === $this->post_statuses['draft'] ? ' — ' . $this->post_statuses['draft'] : '';
$post_view_link = '';
$post_edit_link = '';
if ( ! $this->is_external_type() ) {
$post_link_factory = new WPML_TM_Post_Link_Factory( $this->sitepress );
$post_edit_link = $post_link_factory->edit_link_anchor( $current_document->ID, __( 'Edit', 'wpml-translation-management' ) );
$post_view_link = $post_link_factory->view_link_anchor( $current_document->ID, __( 'View', 'wpml-translation-management' ) );
}
$jobs = ( new PostJobsRepository() )->getJobsGroupedByLang( $current_document->ID, $element_type );
$post_edit_link = apply_filters( 'wpml_document_edit_item_link', $post_edit_link, __( 'Edit', 'wpml-translation-management' ), $current_document, $element_type, $this->get_type() );
if ( $post_edit_link ) {
$post_actions[] = "<span class='edit'>" . $post_edit_link . '</span>';
}
$post_view_link = apply_filters( 'wpml_document_view_item_link', $post_view_link, __( 'View', 'wpml-translation-management' ), $current_document, $element_type, $this->get_type() );
if ( $post_view_link ) {
$post_actions[] = "<span class='view'>" . $post_view_link . '</span>';
}
if ( $post_actions ) {
$post_actions_link .= '<div class="row-actions">' . implode( ' | ', $post_actions ) . '</div>';
}
$row_data = apply_filters( 'wpml_translation_dashboard_row_data', array( 'word_count' => $count ), $this->data );
$row_data_str = '';
foreach ( $row_data as $key => $value ) {
$row_data_str .= 'data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '" ';
}
?>
<tr id="row_<?php echo sanitize_html_class( $current_document->ID ); ?>" <?php echo $row_data_str; ?>>
<td scope="row">
<?php
$checked = checked( true, isset( $_GET['post_id'] ) || $this->selected, false );
?>
<input type="checkbox" value="<?php echo $current_document->ID; ?>" name="<?php echo $check_field_name; ?>[<?php echo $current_document->ID; ?>][checked]" <?php echo $checked; ?> />
<input type="hidden" value="<?php echo $element_type; ?>" name="<?php echo $check_field_name; ?>[<?php echo $current_document->ID; ?>][type]"/>
</td>
<td scope="row" class="post-title column-title">
<?php
echo esc_html( $post_title );
echo esc_html( $post_status );
echo $post_actions_link;
?>
<div class="icl_post_note" id="icl_post_note_<?php echo $current_document->ID; ?>">
<?php
$note = '';
if ( ! $current_document->is_translation ) {
$note = WPML_TM_Translator_Note::get( $current_document->ID );
$this->note_text = '';
if ( $note ) {
$this->note_text = __( 'Edit note for the translators', 'wpml-translation-management' );
$this->note_icon_class = 'otgs-ico-note-edit-o';
} else {
$this->note_text = __( 'Add note for the translators', 'wpml-translation-management' );
$this->note_icon_class = 'otgs-ico-note-add-o';
}
}
?>
<label for="post_note_<?php echo $current_document->ID; ?>">
<?php _e( 'Note for the translators', 'wpml-translation-management' ); ?>
</label>
<textarea id="post_note_<?php echo $current_document->ID; ?>" rows="5"><?php echo $note; ?></textarea>
<table width="100%">
<tr>
<td style="border-bottom:none">
<input type="button" class="icl_tn_cancel button" value="<?php _e( 'Cancel', 'wpml-translation-management' ); ?>" />
<input class="icl_tn_post_id" type="hidden" value="<?php echo $current_document->ID; ?>"/>
</td>
<td align="right" style="border-bottom:none">
<input type="button" class="icl_tn_save button-primary" value="<?php _e( 'Save', 'wpml-translation-management' ); ?>"/>
</td>
</tr>
</table>
</div>
</td>
<td scope="row" class="manage-column wpml-column-type">
<?php
if ( isset( $this->post_types[ $this->get_type() ] ) ) {
$custom_post_type_labels = $this->post_types[ $this->get_type() ]->labels;
if ( $custom_post_type_labels->singular_name != '' ) {
echo $custom_post_type_labels->singular_name;
} else {
echo $custom_post_type_labels->name;
}
} else {
echo $this->get_type();
}
?>
</td>
<td scope="row" class="manage-column column-active-languages wpml-col-languages">
<?php
$has_jobs_in_progress = false;
foreach ( $this->active_languages as $code => $lang ) {
if ( $code == $this->data->language_code ) {
continue;
}
$needsReview = false;
if ( isset( $jobs[ $code ] ) ) {
$job = $jobs[ $code ];
$status = $job['status'] ?: $this->get_status_in_lang( $code );
$job_entity_id = $job['entity_id'];
$job_id = $job['job_id'];
$needsReview = $job['needsReview'];
$automatic = $job['automatic'];
$shouldBeSynced = Jobs::shouldBeATESynced( $job );
} else {
$status = $this->get_status_in_lang( $code );
$job_entity_id = 0;
$job_id = 0;
$automatic = false;
$shouldBeSynced = false;
}
if ( $needsReview ) {
$translation_status_text = esc_attr( __( 'Needs review', 'wpml-translation-management' ) );
} else {
switch ( $status ) {
case ICL_TM_NOT_TRANSLATED:
$translation_status_text = esc_attr( __( 'Not translated', 'wpml-translation-management' ) );
break;
case ICL_TM_WAITING_FOR_TRANSLATOR:
$translation_status_text = $automatic
? esc_attr( __( 'Waiting for automatic translation', 'wpml-translation-management' ) )
: esc_attr( __( 'Waiting for translator', 'wpml-translation-management' ) );
break;
case ICL_TM_IN_BASKET:
$translation_status_text = esc_attr( __( 'In basket', 'wpml-translation-management' ) );
break;
case ICL_TM_IN_PROGRESS:
$translation_status_text = esc_attr( __( 'Waiting for translation service', 'wpml-translation-management' ) );
$has_jobs_in_progress = true;
break;
case ICL_TM_TRANSLATION_READY_TO_DOWNLOAD:
$translation_status_text = esc_attr(
__(
'Translation ready to download',
'wpml-translation-management'
)
);
$has_jobs_in_progress = true;
break;
case ICL_TM_DUPLICATE:
$translation_status_text = esc_attr( __( 'Duplicate of default language', 'wpml-translation-management' ) );
break;
case ICL_TM_COMPLETE:
$translation_status_text = esc_attr( __( 'Translation completed', 'wpml-translation-management' ) );
break;
case ICL_TM_NEEDS_UPDATE:
$translation_status_text = esc_attr( __( 'Needs update', 'wpml-translation-management' ) );
break;
case ICL_TM_ATE_NEEDS_RETRY:
$translation_status_text = esc_attr( __( 'In progress', 'wpml-translation-management' ) ) . ' - ' . esc_attr( __( 'needs retry', 'wpml-translation-management' ) );
break;
default:
$translation_status_text = '';
}
}
$status_icon_class = $iclTranslationManagement->status2icon_class( $status, ICL_TM_NEEDS_UPDATE === (int) $status, $needsReview );
?>
<span data-document_status="<?php echo $status; ?>"
id="wpml-job-status-<?php echo esc_attr( $job_entity_id ); ?>"
class="js-wpml-translate-link"
data-tm-job-id="<?php echo esc_attr( $job_id ); ?>"
data-automatic="<?php echo esc_attr( $automatic ); ?>"
data-wpmlcc-lang="<?php echo esc_attr( $code ); ?>"
data-should-ate-sync="<?php echo $shouldBeSynced ? '1' : '0' ?>"
>
<i class="<?php echo esc_attr( $status_icon_class ); ?> js-otgs-popover-tooltip"
title="<?php echo esc_attr( $lang['display_name'] ); ?>: <?php echo $translation_status_text; ?>"
data-original-title="<?php echo esc_attr( $lang['display_name'] ); ?>: <?php echo $translation_status_text; ?>"
></i>
</span>
<?php
}
?>
</td>
<td scope="row" class="post-date column-date">
<?php
$element_date = $this->get_date();
if ( $element_date ) {
echo date( 'Y-m-d', strtotime( $element_date ) );
}
echo '<br />';
echo $this->get_general_status();
?>
</td>
<td class="column-actions" scope="row" >
<?php
if ( ! $current_document->is_translation ) {
?>
<a title="<?php echo $this->note_text; ?>" href="#" class="icl_tn_link" id="icl_tn_link_<?php echo $current_document->ID; ?>" >
<i class="<?php echo $this->note_icon_class; ?>"></i>
</a>
<?php
if ( $has_jobs_in_progress && $this->has_remote_jobs( $jobs ) ) {
?>
<a class="otgs-ico-refresh wpml-sync-and-download-translation"
data-element-id="<?php echo $current_document->ID; ?>"
data-element-type="<?php echo esc_attr( $element_type ); ?>"
data-jobs="<?php echo htmlspecialchars( json_encode( array_values( $jobs ) ) ); ?>"
data-icons="
<?php
echo htmlspecialchars(
json_encode(
array(
'completed' => $iclTranslationManagement->status2icon_class( ICL_TM_COMPLETE, false ),
'canceled' => $iclTranslationManagement->status2icon_class( ICL_TM_NOT_TRANSLATED, false ),
'progress' => $iclTranslationManagement->status2icon_class( ICL_TM_IN_PROGRESS, false ),
)
)
)
?>
"
title="<?php esc_attr_e( 'Check status and get translations', 'wpml-translation-management' ); ?>"
</a>
<?php
}
}
?>
</td>
</tr>
<?php
}
private function get_date() {
if ( ! $this->is_external_type() ) {
/** @var WP_Post $post */
$post = get_post( $this->data->ID );
$date = get_post_time( 'U', false, $post );
} else {
$date = apply_filters(
'wpml_tm_dashboard_date',
time(),
$this->data->ID,
$this->data->translation_element_type
);
}
$date = date( 'y-m-d', $date );
return $date;
}
private function has_remote_jobs( $jobs ) {
foreach ( $jobs as $job ) {
if ( ! $job['isLocal'] ) {
return true;
}
}
return false;
}
private function get_general_status() {
if ( ! $this->is_external_type() ) {
$status = get_post_status( $this->data->ID );
$status_text = isset( $this->post_statuses[ $status ] ) ? $this->post_statuses[ $status ] : $status;
} else {
$status_text = apply_filters(
'wpml_tm_dashboard_status',
'external',
$this->data->ID,
$this->data->translation_element_type
);
}
return $status_text;
}
private function get_status_in_lang( $language_code ) {
$status_helper = wpml_get_post_status_helper();
return $status_helper->get_status( false, $this->data->trid, $language_code );
}
}

View File

@@ -0,0 +1,88 @@
<?php
/**
* Class WPML_TM_Dashboard_Pagination
*/
class WPML_TM_Dashboard_Pagination {
private $postLimitNumber = 0;
public function add_hooks() {
add_action( 'wpml_tm_dashboard_pagination', array( $this, 'add_tm_dashboard_pagination' ), 10, 2 );
add_filter( 'wpml_tm_dashboard_post_query_args', array( $this, 'filter_dashboard_post_query_args_for_pagination' ), 10, 2 );
}
public function filter_dashboard_post_query_args_for_pagination( $query_args, $args ) {
if ( ! empty( $args['type'] ) ) {
unset( $query_args['no_found_rows'] );
}
}
/**
* Sets value for posts limit query to be used in post_limits filter
*
* @param int $value
*
* @see https://onthegosystems.myjetbrains.com/youtrack/issue/wpmldev-616
*/
public function setPostsLimitValue( $value ) {
$this->postLimitNumber = ( is_int( $value ) && $value > 0 ) ? $value : $this->postLimitNumber;
}
/**
* Resets value of posts limit variable.
*
* @see https://onthegosystems.myjetbrains.com/youtrack/issue/wpmldev-616
*/
public function resetPostsLimitValue() {
$this->postLimitNumber = 0;
}
/**
* Custom callback that's hooked into 'post_limits' filter to set custom limit of retrieved posts.
*
* @see https://onthegosystems.myjetbrains.com/youtrack/issue/wpmldev-616
*
* @return string
*/
public function getPostsLimitQueryValue() {
return 'LIMIT ' . $this->postLimitNumber;
}
/**
* @param integer $posts_per_page
* @param integer $found_documents
*/
public function add_tm_dashboard_pagination( $posts_per_page, $found_documents ) {
$found_documents = $found_documents;
$total_pages = ceil( $found_documents / $posts_per_page );
$paged = array_key_exists( 'paged', $_GET ) ? filter_var( $_GET['paged'], FILTER_SANITIZE_NUMBER_INT ) : false;
$paged = $paged ? $paged : 1;
$page_links = paginate_links(
array(
'base' => add_query_arg( 'paged', '%#%' ),
'format' => '',
'prev_text' => '&laquo;',
'next_text' => '&raquo;',
'total' => $total_pages,
'current' => $paged,
)
);
if ( $page_links ) {
?>
<div class="tablenav-pages">
<?php
$page_from = number_format_i18n( ( $paged - 1 ) * $posts_per_page + 1 );
$page_to = number_format_i18n( min( $paged * $posts_per_page, $found_documents ) );
$page_total = number_format_i18n( $found_documents );
?>
<span class="displaying-num">
<?php echo sprintf( esc_html__( 'Displaying %1$s&#8211;%2$s of %3$s', 'wpml-translation-management' ), $page_from, $page_to, $page_total ); ?>
</span>
<?php echo $page_links; ?>
</div>
<?php
}
}
}

View File

@@ -0,0 +1,19 @@
<?php
/**
* Created by PhpStorm.
* User: bruce
* Date: 20/04/17
* Time: 11:39 AM
*/
class WPML_TM_WP_Query extends WP_Query {
public function get_found_count() {
return $this->found_posts;
}
public function getPostCount() {
return $this->post_count;
}
}