PageRenderTime 24ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/wpml-translation-management/classes/menu/dashboard/class-wpml-tm-dashboard-document-row.php

https://bitbucket.org/oriaxx/wenco
PHP | 269 lines | 241 code | 27 blank | 1 comment | 25 complexity | f44b792e9289f372302fb89033617aa8 MD5 | raw file
Possible License(s): GPL-2.0, MIT, BSD-3-Clause, LGPL-3.0
  1. <?php
  2. class WPML_TM_Dashboard_Document_Row {
  3. private $data;
  4. private $post_types;
  5. private $translation_filter;
  6. private $active_languages;
  7. private $selected;
  8. private $note_text;
  9. private $note_icon_class;
  10. private $post_statuses;
  11. public function __construct( $doc_data, $translation_filter, $post_types, $post_statuses, $active_languages, $selected, &$sitepress, &$wpdb ) {
  12. $this->data = $doc_data;
  13. $this->post_statuses = $post_statuses;
  14. $this->selected = $selected;
  15. $this->post_types = $post_types;
  16. $this->active_languages = $active_languages;
  17. $this->translation_filter = $translation_filter;
  18. $this->sitepress = &$sitepress;
  19. $this->wpdb = &$wpdb;
  20. }
  21. public function get_word_count() {
  22. $current_document = $this->data;
  23. $count = 0;
  24. if ( ! $this->is_external_type() ) {
  25. $wpml_post = new WPML_TM_Post( $current_document->ID, $this->sitepress, $this->wpdb );
  26. $count += $wpml_post->get_words_count();
  27. }
  28. $count = apply_filters( 'wpml_tm_estimated_words_count', $count, $current_document );
  29. return $count;
  30. }
  31. public function get_title() {
  32. return $this->data->title ? $this->data->title : __('(missing title)', 'wpml-translation-management');
  33. }
  34. private function is_external_type() {
  35. $doc = $this->data;
  36. return strpos($doc->translation_element_type, 'post_' ) !== 0;
  37. }
  38. public function get_type_prefix(){
  39. $type = $this->data->translation_element_type;
  40. $type = explode( '_', $type );
  41. if ( count( $type ) > 1 ) {
  42. $type = $type[ 0 ];
  43. }
  44. return $type;
  45. }
  46. public function get_type() {
  47. $type = $this->data->translation_element_type;
  48. $type = explode( '_', $type );
  49. if ( count( $type ) > 1 ) {
  50. unset( $type[ 0 ] );
  51. }
  52. $type = join( '_', $type );
  53. return $type;
  54. }
  55. public function display() {
  56. global $iclTranslationManagement;
  57. $current_document = $this->data;
  58. $count = $this->get_word_count();
  59. $post_actions = array();
  60. $post_actions_link = "";
  61. $element_type = $this->get_type_prefix();
  62. $check_field_name = $element_type;
  63. $post_title = $this->get_title();
  64. $post_view_link = '';
  65. $post_edit_link = '';
  66. if ( ! $this->is_external_type() ) {
  67. $post_link_factory = new WPML_TM_Post_Link_Factory($this->sitepress);
  68. $post_edit_link = $post_link_factory->edit_link_anchor( $current_document->ID, __( 'Edit', 'wpml-translation-management' ));
  69. $post_view_link = $post_link_factory->view_link_anchor( $current_document->ID, __( 'View', 'wpml-translation-management' ));
  70. }
  71. $post_edit_link = apply_filters( 'wpml_document_edit_item_link', $post_edit_link, __( 'Edit', 'wpml-translation-management' ), $current_document, $element_type, $this->get_type() );
  72. if ( $post_edit_link ) {
  73. $post_actions[ ] = "<span class='edit'>" . $post_edit_link . "</span>";
  74. }
  75. $post_view_link = apply_filters( 'wpml_document_view_item_link', $post_view_link, __( 'View', 'wpml-translation-management' ), $current_document, $element_type, $this->get_type());
  76. if ( $post_view_link ) {
  77. $post_actions[ ] = "<span class='view'>" . $post_view_link . "</span>";
  78. }
  79. if ( $post_actions ) {
  80. $post_actions_link .= '<div class="row-actions">' . implode( ' | ', $post_actions ) . '</div>';
  81. }
  82. ?>
  83. <tr id="row_<?php echo sanitize_html_class( $current_document->ID ); ?>" data-word_count="<?php echo $count; ?>">
  84. <td scope="row">
  85. <?php
  86. $checked = checked( true, isset( $_GET[ 'post_id' ] ) || $this->selected, false );
  87. ?>
  88. <input type="checkbox" value="<?php echo $current_document->ID ?>" name="<?php echo $check_field_name; ?>[<?php echo $current_document->ID; ?>][checked]" <?php echo $checked; ?> />
  89. <input type="hidden" value="<?php echo $element_type; ?>" name="<?php echo $check_field_name; ?>[<?php echo $current_document->ID; ?>][type]"/>
  90. </td>
  91. <td scope="row" class="post-title column-title">
  92. <?php
  93. echo esc_html( $post_title );
  94. echo $post_actions_link;
  95. ?>
  96. <div class="icl_post_note" id="icl_post_note_<?php echo $current_document->ID ?>">
  97. <?php
  98. $note = '';
  99. if ( ! $current_document->is_translation ) {
  100. $note = get_post_meta( $current_document->ID, '_icl_translator_note', true );
  101. $this->note_text = '';
  102. if ( $note ) {
  103. $this->note_text = __( 'Edit note for the translators', 'wpml-translation-management' );
  104. $this->note_icon_class = 'otgs-ico-note-edit-o';
  105. } else {
  106. $this->note_text = __( 'Add note for the translators', 'wpml-translation-management' );
  107. $this->note_icon_class = 'otgs-ico-note-add-o';
  108. }
  109. }
  110. ?>
  111. <label for="post_note_<?php echo $current_document->ID ?>">
  112. <?php _e( 'Note for the translators', 'wpml-translation-management' ) ?>
  113. </label>
  114. <textarea id="post_note_<?php echo $current_document->ID ?>" rows="5"><?php echo $note ?></textarea>
  115. <table width="100%">
  116. <tr>
  117. <td style="border-bottom:none">
  118. <input type="button" class="icl_tn_cancel button" value="<?php _e( 'Cancel', 'wpml-translation-management' ) ?>" />
  119. <input class="icl_tn_post_id" type="hidden" value="<?php echo $current_document->ID ?>"/>
  120. </td>
  121. <td align="right" style="border-bottom:none">
  122. <input type="button" class="icl_tn_save button-primary" value="<?php _e( 'Save', 'wpml-translation-management' ) ?>"/>
  123. </td>
  124. </tr>
  125. </table>
  126. </div>
  127. </td>
  128. <td scope="row" class="manage-column wpml-column-type">
  129. <?php
  130. if ( isset( $this->post_types[ $this->get_type() ] ) ) {
  131. $custom_post_type_labels = $this->post_types[ $this->get_type() ]->labels;
  132. if ( $custom_post_type_labels->singular_name != "" ) {
  133. echo $custom_post_type_labels->singular_name;
  134. } else {
  135. echo $custom_post_type_labels->name;
  136. }
  137. } else {
  138. echo $this->get_type();
  139. }
  140. ?>
  141. </td>
  142. <td scope="row" class="manage-column column-active-languages wpml-col-languages">
  143. <?php
  144. foreach ( $this->active_languages as $code => $lang ) {
  145. if ( $code == $this->data->language_code ) {
  146. continue;
  147. }
  148. $status = $this->get_status_in_lang( $code );
  149. switch ( $status ) {
  150. case ICL_TM_NOT_TRANSLATED :
  151. $translation_status_text = esc_attr( __( 'Not translated', 'wpml-translation-management' ) );
  152. break;
  153. case ICL_TM_WAITING_FOR_TRANSLATOR :
  154. $translation_status_text = esc_attr( __( 'Waiting for translator', 'wpml-translation-management' ) );
  155. break;
  156. case ICL_TM_IN_BASKET :
  157. $translation_status_text = esc_attr( __( 'In basket', 'wpml-translation-management' ) );
  158. break;
  159. case ICL_TM_IN_PROGRESS :
  160. $translation_status_text = esc_attr( __( 'In progress', 'wpml-translation-management' ) );
  161. break;
  162. case ICL_TM_DUPLICATE :
  163. $translation_status_text = esc_attr( __( 'Duplicate', 'wpml-translation-management' ) );
  164. break;
  165. case ICL_TM_COMPLETE :
  166. $translation_status_text = esc_attr( __( 'Complete', 'wpml-translation-management' ) );
  167. break;
  168. case ICL_TM_NEEDS_UPDATE :
  169. $translation_status_text = ' - ' . esc_attr( __( 'needs update', 'wpml-translation-management' ) );
  170. break;
  171. default:
  172. $translation_status_text = '';
  173. }
  174. $status_icon_class = $iclTranslationManagement->status2icon_class( $status, ICL_TM_NEEDS_UPDATE === (int) $status );
  175. ?>
  176. <span data-document_status="<?php echo $status; ?>">
  177. <i class="<?php echo $status_icon_class; ?>"
  178. title="<?php echo $lang[ 'display_name' ]; ?>: <?php echo $translation_status_text ?>"></i>
  179. </span>
  180. <?php
  181. }
  182. ?>
  183. </td>
  184. <td scope="row" class="post-date column-date">
  185. <?php
  186. $element_date = $this->get_date();
  187. if ( $element_date ) {
  188. echo date( 'Y-m-d', strtotime( $element_date ) );
  189. }
  190. echo '<br />';
  191. echo $this->get_general_status();
  192. ?>
  193. </td>
  194. <td scope="row" class="icl_tn_link" id="icl_tn_link_<?php echo $current_document->ID ?>">
  195. <?php
  196. if ( ! $current_document->is_translation ) {
  197. ?>
  198. <a title="<?php echo $this->note_text ?>" href="#">
  199. <i class="<?php echo $this->note_icon_class; ?>"></i>
  200. </a>
  201. <?php
  202. }
  203. ?>
  204. </td>
  205. </tr>
  206. <?php
  207. }
  208. private function get_date() {
  209. if ( !$this->is_external_type() ) {
  210. /** @var WP_Post $post */
  211. $post = get_post( $this->data->ID );
  212. $date = get_post_time( 'U', false, $post );
  213. } else {
  214. $date = apply_filters(
  215. 'wpml_tm_dashboard_date',
  216. time(),
  217. $this->data->ID,
  218. $this->data->translation_element_type
  219. );
  220. }
  221. $date = date( 'y-m-d', $date );
  222. return $date;
  223. }
  224. private function get_general_status() {
  225. if ( !$this->is_external_type() ) {
  226. $status = get_post_status( $this->data->ID );
  227. $status_text = isset( $this->post_statuses[ $status ] ) ? $this->post_statuses[ $status ] : $status;
  228. } else {
  229. $status_text = apply_filters(
  230. 'wpml_tm_dashboard_status',
  231. 'external',
  232. $this->data->ID,
  233. $this->data->translation_element_type
  234. );
  235. }
  236. return $status_text;
  237. }
  238. private function get_status_in_lang( $language_code ) {
  239. $status_helper = wpml_get_post_status_helper ();
  240. return $status_helper->get_status ( false, $this->data->trid, $language_code );
  241. }
  242. }