WCML_Store_URLs_UI

Created by OnTheGo Systems.

Defined (1)

The class is defined in the following location(s).

/inc/template-classes/store-urls/class-wcml-store-urls-ui.php  
  1. class WCML_Store_URLs_UI extends WPML_Templates_Factory { 
  2.  
  3. private $woocommerce_wpml; 
  4. private $sitepress; 
  5. private $active_languages; 
  6.  
  7. function __construct( &$woocommerce_wpml, &$sitepress ) { 
  8. parent::__construct(); 
  9.  
  10. $this->woocommerce_wpml = $woocommerce_wpml; 
  11. $this->sitepress = $sitepress; 
  12. $this->active_languages = $this->sitepress->get_active_languages(); 
  13.  
  14. public function get_model() { 
  15.  
  16. $model = array( 
  17. 'data' => array( 
  18. 'flags' => $this->woocommerce_wpml->products->get_translation_flags( $this->active_languages, false, false ),  
  19. ),  
  20. 'shop_base' => array( 
  21. 'flag' => $this->sitepress->get_flag_url( $this->woocommerce_wpml->url_translation->get_source_slug_language( 'shop' ) ),  
  22. 'orig_value' => get_post( get_option('woocommerce_shop_page_id' ) )->post_name,  
  23. 'statuses' => $this->get_base_translations_statuses( 'shop', $this->active_languages ),  
  24. ),  
  25. 'product_base' => array( 
  26. 'flag' => $this->sitepress->get_flag_url( $this->woocommerce_wpml->url_translation->get_source_slug_language( 'product' ) ),  
  27. 'orig_value' => $this->woocommerce_wpml->url_translation->get_woocommerce_product_base(),  
  28. 'statuses' => $this->get_base_translations_statuses( 'product', $this->active_languages ),  
  29. ),  
  30. 'cat_base' => array( 
  31. 'flag' => $this->sitepress->get_flag_url( $this->woocommerce_wpml->url_translation->get_source_slug_language( 'product_cat' ) ),  
  32. 'orig_value' => !empty( $this->woocommerce_wpml->url_translation->wc_permalinks['category_base'] ) ? trim( $this->woocommerce_wpml->url_translation->wc_permalinks['category_base'], '/' ) : 'product-category',  
  33. 'statuses' => $this->get_base_translations_statuses( 'product_cat', $this->active_languages ),  
  34. ),  
  35. 'tag_base' => array( 
  36. 'flag' => $this->sitepress->get_flag_url( $this->woocommerce_wpml->url_translation->get_source_slug_language( 'product_tag' ) ),  
  37. 'orig_value' => !empty( $this->woocommerce_wpml->url_translation->wc_permalinks['tag_base'] ) ? trim( $this->woocommerce_wpml->url_translation->wc_permalinks['tag_base'], '/' ) : 'product-tag',  
  38. 'statuses' => $this->get_base_translations_statuses( 'product_tag', $this->active_languages ),  
  39. ),  
  40. 'attr_base' => array( 
  41. 'flag' => $this->sitepress->get_flag_url( $this->woocommerce_wpml->url_translation->get_source_slug_language( 'attribute' ) ),  
  42. 'orig_value' => trim( $this->woocommerce_wpml->url_translation->wc_permalinks['attribute_base'], '/' ),  
  43. 'statuses' => $this->get_base_translations_statuses( 'attribute', $this->active_languages, $this->woocommerce_wpml->url_translation->wc_permalinks['attribute_base'] ),  
  44. ),  
  45. 'endpoints_base' => $this->get_endpoint_info(),  
  46. 'attribute_slugs'=> $this->get_attribute_slugs_info(),  
  47. 'strings' => array( 
  48. 'notice' => __( 'This page allows you to translate all strings that are being used by WooCommerce in building different type of urls. Translating them enables you to have fully localized urls that match the language of the pages.', 'woocommerce-multilingual' ),  
  49. 'notice_defaults' => sprintf( __( 'You can enter or edit your default values on the %sPermalinks settings%s page or, for the endpoints, on the WooCommerce %sAccount settings%s page.',  
  50. 'woocommerce-multilingual' ),  
  51. '<a href="' . admin_url('options-permalink.php'). '">', '</a>',  
  52. '<a href="' . admin_url('admin.php?page=wc-settings&tab=account') .'">', '</a>' 
  53. ),  
  54. 'perm_settings' => '<a href="'.admin_url('options-permalink.php').'" >' .__( 'permalinks settings', 'woocommerce-multilingual' ).'</a>',  
  55. 'account_settings' => '<a href="admin.php?page=wc-settings&tab=account" >'.__( 'Account settings', 'woocommerce-multilingual' ).'</a>',  
  56. 'slug_type' => __( 'Slug type', 'woocommerce-multilingual' ),  
  57. 'orig_slug' => __( 'Original Slug', 'woocommerce-multilingual' ),  
  58. 'shop' => __( 'Shop page', 'woocommerce-multilingual' ),  
  59. 'product' => __( 'Product base', 'woocommerce-multilingual' ),  
  60. 'category' => __( 'Product category base', 'woocommerce-multilingual' ),  
  61. 'tag' => __( 'Product tag base', 'woocommerce-multilingual' ),  
  62. 'attr' => __( 'Product attribute base', 'woocommerce-multilingual' ),  
  63. 'endpoint' => __( 'Endpoint: %s', 'woocommerce-multilingual' ),  
  64. 'attribute_slug' => __( 'Attribute slug: %s', 'woocommerce-multilingual' ),  
  65. ),  
  66. 'nonces' => array( 
  67. 'edit_base' => wp_nonce_field('wcml_edit_base', 'wcml_edit_base_nonce'),  
  68. 'update_base' => wp_nonce_field('wcml_update_base_translation', 'wcml_update_base_nonce') 
  69. ); 
  70.  
  71. return $model; 
  72.  
  73. public function get_endpoint_info() { 
  74.  
  75. $endpoints_info = array(); 
  76. foreach( WC()->query->query_vars as $key => $endpoint ) { 
  77.  
  78. $endpoints_info[ $key ][ 'key' ] = $key; 
  79. $endpoints_info[ $key ][ 'orig_value' ] = $endpoint; 
  80. $endpoints_info[ $key ][ 'flag' ] = $this->sitepress->get_flag_url( $this->woocommerce_wpml->url_translation->get_source_slug_language( $key ) ); 
  81. $endpoints_info[ $key ][ 'statuses' ] = $this->get_base_translations_statuses( $key, $this->active_languages, $endpoint ); 
  82.  
  83.  
  84. return $endpoints_info; 
  85.  
  86.  
  87. private function get_attribute_slugs_info() { 
  88. $product_attributes = $this->woocommerce_wpml->attributes->get_translatable_attributes(); 
  89.  
  90. $attributes_info = array(); 
  91. foreach( $product_attributes as $attribute ) { 
  92.  
  93. if( $attribute->attribute_public ) { 
  94. $language = $this->woocommerce_wpml->strings->get_string_language( 
  95. $attribute->attribute_name,  
  96. $this->woocommerce_wpml->url_translation->url_strings_context(),  
  97. $this->woocommerce_wpml->url_translation->url_string_name( 'attribute_slug', $attribute->attribute_name ) 
  98. ); 
  99.  
  100. //$this->woocommerce_wpml->url_translation 
  101. $attributes_info[ $attribute->attribute_name ] = array( 
  102. 'label' => $attribute->attribute_label,  
  103. 'orig_value' => $attribute->attribute_name,  
  104. 'flag' => $this->sitepress->get_flag_url( $language ),  
  105. 'statuses' => $this->get_base_translations_statuses( 'attribute_slug-' . $attribute->attribute_name, $this->active_languages, $attribute->attribute_name ) 
  106. ); 
  107.  
  108.  
  109. return $attributes_info; 
  110.  
  111. public function get_base_translations_statuses( $base, $active_languages, $value = true ) { 
  112.  
  113. $statuses = new WCML_Store_URLs_Translation_Statuses_UI( $base, $active_languages, $value, $this->woocommerce_wpml, $this->sitepress ); 
  114.  
  115. return $statuses->get_view(); 
  116.  
  117.  
  118. public function init_template_base_dir() { 
  119. $this->template_paths = array( 
  120. WCML_PLUGIN_PATH . '/templates/store-urls/',  
  121. ); 
  122.  
  123. public function get_template() { 
  124. return 'store-urls.twig';