PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/sitepress-multilingual-cms/menu/menu-sync/menus-sync.php

https://gitlab.com/woxiprogrammers/infinia-wordpress
PHP | 272 lines | 256 code | 11 blank | 5 comment | 34 complexity | 4a5bca3324a6ea5e59930913e10b18f8 MD5 | raw file
  1. <?php
  2. require 'wpml-menu-sync-display.class.php';
  3. /** @var $sitepress SitePress */
  4. /** @var $icl_menus_sync ICLMenusSync */
  5. $active_languages = $sitepress->get_active_languages();
  6. $def_lang_code = $sitepress->get_default_language();
  7. $def_lang = $sitepress->get_language_details( $def_lang_code );
  8. $secondary_languages = array();
  9. foreach ( $active_languages as $code => $lang ) {
  10. if ( $code !== $def_lang_code ) {
  11. $secondary_languages[ ] = $lang;
  12. }
  13. }
  14. ?>
  15. <!--suppress HtmlFormInputWithoutLabel --><!--suppress HtmlUnknownAttribute -->
  16. <div class="wrap">
  17. <div id="icon-wpml" class="icon32"><br/></div>
  18. <h2><?php echo __( 'WP Menus Sync', 'sitepress' ) ?></h2>
  19. <br/>
  20. <?php
  21. if ( $icl_menus_sync->is_preview ) {
  22. ?>
  23. <form id="icl_msync_confirm_form" method="post">
  24. <input type="hidden" name="action" value="icl_msync_confirm"/>
  25. <table id="icl_msync_confirm" class="widefat icl_msync">
  26. <thead>
  27. <tr>
  28. <th scope="row" class="check-column"><input type="checkbox"/></th>
  29. <th><?php _e( 'Language', 'sitepress' ) ?></th>
  30. <th><?php _e( 'Action', 'sitepress' ) ?></th>
  31. </tr>
  32. </thead>
  33. <tbody>
  34. <?php
  35. if ( empty( $icl_menus_sync->sync_data ) ) {
  36. ?>
  37. <tr>
  38. <td align="center" colspan="3"><?php _e( 'Nothing to sync.', 'sitepress' ) ?></td>
  39. </tr>
  40. <?php
  41. } else {
  42. //Menus
  43. foreach ( $icl_menus_sync->menus as $menu_id => $menu ) {
  44. $menu_sync_display = new WPML_Menu_Sync_Display( $menu_id, $icl_menus_sync );
  45. ?>
  46. <tr class="icl_msync_menu_title">
  47. <td colspan="3"><?php echo $menu[ 'name' ] ?></td>
  48. </tr>
  49. <?php
  50. // Display actions per menu
  51. // menu translations
  52. if ( isset( $icl_menus_sync->sync_data[ 'menu_translations' ] ) && isset( $icl_menus_sync->sync_data[ 'menu_translations' ][ $menu_id ] ) ) {
  53. foreach ( $icl_menus_sync->sync_data[ 'menu_translations' ][ $menu_id ] as $language => $name ) {
  54. $lang_details = $sitepress->get_language_details( $language );
  55. ?>
  56. <tr>
  57. <th scope="row" class="check-column"><input type="checkbox" name="sync[menu_translation][<?php echo $menu_id ?>][<?php echo $language ?>]" value="<?php echo esc_attr( $name ) ?>"/></th>
  58. <td><?php echo $lang_details[ 'display_name' ]; ?></td>
  59. <td><?php printf( __( 'Add menu translation: %s', 'sitepress' ), '<strong>' . $name . '</strong>' ); ?> </td>
  60. </tr>
  61. <?php
  62. }
  63. }
  64. foreach (
  65. array(
  66. 'add',
  67. 'mov',
  68. 'del',
  69. 'label_changed',
  70. 'url_changed',
  71. 'label_missing',
  72. 'url_missing',
  73. 'options_changed'
  74. ) as $sync_type
  75. ) {
  76. $menu_sync_display->print_sync_field ( $sync_type );
  77. }
  78. }
  79. }
  80. ?>
  81. </tbody>
  82. </table>
  83. <p class="submit">
  84. <?php
  85. $icl_menu_sync_submit_disabled = '';
  86. if ( empty( $icl_menus_sync->sync_data ) || ( empty( $icl_menus_sync->sync_data[ 'mov' ] ) && empty( $icl_menus_sync->sync_data[ 'mov' ][ $menu_id ] ) ) ) {
  87. $icl_menu_sync_submit_disabled = 'disabled="disabled"';
  88. }
  89. ?>
  90. <input id="icl_msync_submit"
  91. class="button-primary"
  92. type="button"
  93. value="<?php _e( 'Apply changes' ) ?>"
  94. data-message="<?php _e( 'Syncing menus %1 of %2', 'sitepress' ) ?>"
  95. data-message-complete="<?php _e( 'The selected menus have been synchonized.', 'sitepress' ) ?>"
  96. <?php echo $icl_menu_sync_submit_disabled; ?> />&nbsp;
  97. <input id="icl_msync_cancel" class="button-secondary" type="button" value="<?php _e( 'Cancel' ) ?>"/>
  98. <span id="icl_msync_message"></span>
  99. </p>
  100. <?php wp_nonce_field( '_icl_nonce_menu_sync', '_icl_nonce_menu_sync' ); ?>
  101. </form>
  102. <?php
  103. } else {
  104. $need_sync = 0;
  105. ?>
  106. <form method="post" action="">
  107. <input type="hidden" name="action" value="icl_msync_preview"/>
  108. <table class="widefat icl_msync">
  109. <thead>
  110. <tr>
  111. <th><?php echo $def_lang[ 'display_name' ]; ?></th>
  112. <?php
  113. if ( ! empty( $secondary_languages ) ) {
  114. foreach ( $secondary_languages as $lang ) {
  115. ?>
  116. <th><?php echo $lang[ 'display_name' ]; ?></th>
  117. <?php
  118. }
  119. }
  120. ?>
  121. </tr>
  122. </thead>
  123. <tbody>
  124. <?php
  125. if ( empty( $icl_menus_sync->menus ) ) {
  126. ?>
  127. <tr>
  128. <td align="center" colspan="<?php echo count( $active_languages ) ?>"><?php _e( 'No menus found', 'sitepress' ) ?></td>
  129. </tr>
  130. <?php
  131. } else {
  132. foreach ( $icl_menus_sync->menus as $menu_id => $menu ) {
  133. ?>
  134. <tr class="icl_msync_menu_title">
  135. <td><strong><?php echo $menu[ 'name' ]; ?></strong></td>
  136. <?php
  137. foreach ( $secondary_languages as $l ) {
  138. ?>
  139. <td>
  140. <?php
  141. if ( isset( $menu[ 'translations' ][ $l[ 'code' ] ][ 'name' ] ) ) {
  142. echo $menu[ 'translations' ][ $l[ 'code' ] ][ 'name' ];
  143. } else { // menu is translated in $l[code]
  144. $need_sync++;
  145. ?>
  146. <input type="text" name="sync[menu_translations][<?php echo $menu_id ?>][<?php echo $l[ 'code' ] ?>]" class="icl_msync_add" value="<?php
  147. echo esc_attr( $menu[ 'name' ] ) . ' - ' . $l[ 'display_name' ] ?>"/>
  148. <small><?php _e( 'Auto-generated title. Edit to change.', 'sitepress' ) ?></small>
  149. <input type="hidden" name="sync[menu_options][<?php echo $menu_id ?>][<?php echo $l[ 'code' ] ?>][auto_add]"
  150. value=""/>
  151. <?php
  152. }
  153. if ( isset( $menu[ 'translations' ][ $l[ 'code' ] ][ 'auto_add' ] ) ) {
  154. ?>
  155. <input type="hidden" name="sync[menu_options][<?php echo $menu_id ?>][<?php echo $l[ 'code' ] ?>][auto_add]" value="<?php echo esc_attr( $menu[ 'translations' ][ $l[ 'code' ] ][ 'auto_add' ] ); ?>"/>
  156. <?php
  157. }
  158. ?>
  159. </td>
  160. <?php
  161. } //foreach($secondary_languages as $l):
  162. ?>
  163. </tr>
  164. <?php
  165. $need_sync += $icl_menus_sync->render_items_tree_default( $menu_id );
  166. } //foreach( $icl_menus_sync->menus as $menu_id => $menu):
  167. }
  168. ?>
  169. </tbody>
  170. </table>
  171. <p class="submit">
  172. <?php
  173. if ( $need_sync ) {
  174. ?>
  175. <input id="icl_msync_sync" type="submit" class="button-primary" value="<?php _e( 'Sync', 'sitepress' ); ?>"<?php if ( !$need_sync ): ?> disabled="disabled"<?php endif; ?> />
  176. &nbsp;&nbsp;
  177. <span id="icl_msync_max_input_vars"
  178. style="display:none"
  179. class="icl-admin-message-warning"
  180. data-max_input_vars="<?php echo ini_get( 'max_input_vars' ); ?>">
  181. <?php _e( 'The menus on this page may not sync because it requires more input variables. Please modify the <strong>max_input_vars</strong> setting in your php.ini or .htaccess files to <strong>!NUM!</strong> or more.', 'siteprss'); ?>
  182. </span>
  183. <?php
  184. } else {
  185. ?>
  186. <input id="icl_msync_sync" type="submit" class="button-primary" value="<?php _e( 'Nothing Sync', 'sitepress' ); ?>"<?php if ( !$need_sync ): ?> disabled="disabled"<?php endif; ?> />
  187. <?php
  188. }
  189. ?>
  190. </p>
  191. <?php wp_nonce_field( '_icl_nonce_menu_sync', '_icl_nonce_menu_sync' ); ?>
  192. </form>
  193. <?php
  194. if ( !empty( $icl_menus_sync->operations ) ) {
  195. $show_string_translation_link = false;
  196. foreach ( $icl_menus_sync->operations as $op => $c ) {
  197. if ( $op == 'add' ) {
  198. ?>
  199. <span class="icl_msync_item icl_msync_add"><?php _e( 'Item will be added', 'sitepress' ); ?></span>
  200. <?php
  201. } elseif ( $op == 'del' ) {
  202. ?>
  203. <span class="icl_msync_item icl_msync_del"><?php _e( 'Item will be removed', 'sitepress' ); ?></span>
  204. <?php
  205. } elseif ( $op == 'not' ) {
  206. ?>
  207. <span class="icl_msync_item icl_msync_not"><?php _e( 'Item cannot be added (parent not translated)', 'sitepress' ); ?></span>
  208. <?php
  209. } elseif ( $op == 'mov' ) {
  210. ?>
  211. <span class="icl_msync_item icl_msync_mov"><?php _e( 'Item changed position', 'sitepress' ); ?></span>
  212. <?php
  213. } elseif ( $op == 'copy' ) {
  214. ?>
  215. <span class="icl_msync_item icl_msync_copy"><?php _e( 'Item will be copied', 'sitepress' ); ?></span>
  216. <?php
  217. } elseif ( $op == 'label_changed' ) {
  218. ?>
  219. <span class="icl_msync_item icl_msync_label_changed"><?php _e( 'Strings for menus will be updated', 'sitepress' ); ?></span>
  220. <?php
  221. } elseif ( $op == 'url_changed' ) {
  222. ?>
  223. <span class="icl_msync_item icl_msync_url_changed"><?php _e( 'URLs for menus will be updated', 'sitepress' ); ?></span>
  224. <?php
  225. } elseif ( $op == 'options_changed' ) {
  226. ?>
  227. <span class="icl_msync_item icl_msync_options_changed"><?php _e( 'Menu Options will be updated', 'sitepress' ); ?></span>
  228. <?php
  229. } elseif ( $op == 'label_missing' ) {
  230. ?>
  231. <span class="icl_msync_item icl_msync_label_missing">
  232. <?php _e( 'Untranslated strings for menus', 'sitepress' ); ?>
  233. </span>
  234. <?php
  235. } elseif ( $op == 'url_missing' ) {
  236. ?>
  237. <span class="icl_msync_item icl_msync_url_missing">
  238. <?php _e( 'Untranslated URLs for menus', 'sitepress' ); ?>
  239. </span>
  240. <?php
  241. }
  242. }
  243. }
  244. if ( defined( 'WPML_ST_FOLDER' ) && $icl_menus_sync->string_translation_links ) {
  245. echo '<p>';
  246. echo __( 'Translate menu strings and URLs for:', 'sitepress' ) . ' ';
  247. $url_pattern = ' href="admin.php?page=' . WPML_ST_FOLDER . '/menu/string-translation.php&context=%s"';
  248. $menu_names = array_keys( $icl_menus_sync->string_translation_links );
  249. $menu_links = array();
  250. foreach ( $menu_names as $menu_name ) {
  251. $menu_url_pattern = sprintf($url_pattern, urlencode($menu_name . ' menu'));
  252. $menu_links[ ] = sprintf( __( '<a%s>%s</a>', 'sitepress' ), $menu_url_pattern, $menu_name );
  253. }
  254. $menu_links_string = join( ', ', $menu_links );
  255. echo $menu_links_string;
  256. echo '</p>';
  257. }
  258. }
  259. do_action( 'icl_menu_footer' );
  260. ?>
  261. </div>