Advertisement
sarahn

export_wpml_settings.php

Apr 1st, 2013
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. <?php
  2. $export = $_GET['export'];
  3.  
  4. if($export == '1'){
  5. require( './wp-load.php' );
  6.  
  7.  
  8. if (!class_exists('ICL_Array2XML')) {
  9.  
  10. /**
  11. * Converts array to XML
  12. */
  13. class ICL_Array2XML
  14. {
  15.  
  16. var $text;
  17. var $arrays, $keys, $node_flag, $depth, $xml_parser;
  18.  
  19. function array2xml($array, $root) {
  20. $this->depth = 1;
  21. $this->text = "<?xml version=\"1.0\" encoding=\""
  22. . get_option('blog_charset'). "\"?>\r\n<$root>\r\n";
  23. $this->text .= $this->array_transform($array);
  24. $this->text .="</$root>";
  25. return $this->text;
  26. }
  27.  
  28. function array_transform($array) {
  29. $output = '';
  30. $indent = str_repeat(' ', $this->depth * 4);
  31. $child_key = false;
  32. if (isset($array['__key'])) {
  33. $child_key = $array['__key'];
  34. unset($array['__key']);
  35. }
  36. foreach ($array as $key => $value) {
  37. if (!is_array($value)) {
  38. if (empty($key)) {
  39. continue;
  40. }
  41. $key = $child_key ? $child_key : $key;
  42. $output .= $indent . "<$key>" . htmlspecialchars($value, ENT_QUOTES) . "</$key>\r\n";
  43. } else {
  44. $this->depth++;
  45. $key = $child_key ? $child_key : $key;
  46. $output_temp = $this->array_transform($value);
  47. if (!empty($output_temp)) {
  48. $output .= $indent . "<$key>\r\n";
  49. $output .= $output_temp;
  50. $output .= $indent . "</$key>\r\n";
  51. }
  52. $this->depth--;
  53. }
  54. }
  55. return $output;
  56. }
  57.  
  58. }
  59. }
  60.  
  61. function wpvref_export_wpml_settings() {
  62. global $wpdb;
  63.  
  64. $data = null;
  65. $settings = get_option('icl_sitepress_settings', null);
  66. if ($settings) {
  67. //require_once dirname(__FILE__) . '/includes/array2xml.php';
  68. $xml = new ICL_Array2XML();
  69.  
  70. $settings['translation-management']['__custom_fields_readonly_config_prev']['__key'] = 'item';
  71. $settings['translation-management']['custom_fields_readonly_config']['__key'] = 'item';
  72.  
  73. // Add the active languages.
  74. $settings['active_languages'] = array();
  75. $table_name = $wpdb->prefix.'icl_languages';
  76. if($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") == $table_name){
  77. $results = $wpdb->get_results("SELECT code, active FROM {$wpdb->prefix}icl_languages WHERE 1 ", ARRAY_A);
  78. foreach ($results as $item) {
  79. $settings['wpv_active_languages'][$item['code']] = $item['active'];
  80. }
  81. }
  82.  
  83. $data = $xml->array2xml($settings, 'wpml');
  84.  
  85. }
  86. return $data;
  87. }
  88.  
  89. // Export WPML
  90. $wpml = wpvref_export_wpml_settings();
  91. if ($wpml) {
  92. //file to put the data in
  93. //$wpml_file = ABSPATH . '_wpv_demo/' . basename($site['site_url']) . '/wpml.xml';
  94. $wpml_file = ABSPATH . 'wpml.xml';
  95. if(file_put_contents($wpml_file, $wpml) !== FALSE){
  96. echo "Your wpml settings have been successfully exported. You will find them in the wpml.xml file located in your WordPress root folder.";
  97. }
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement