PageRenderTime 56ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/sitepress-multilingual-cms/inc/functions-troubleshooting.php

https://bitbucket.org/kenaku/karate
PHP | 254 lines | 186 code | 44 blank | 24 comment | 46 complexity | 162d8aed4d99507b07cb9ac2cad9a07e MD5 | raw file
  1. <?php
  2. /*
  3. if ( !function_exists('sys_get_temp_dir')) {
  4. function sys_get_temp_dir() {
  5. if( $temp=getenv('TMP') ) return $temp;
  6. if( $temp=getenv('TEMP') ) return $temp;
  7. if( $temp=getenv('TMPDIR') ) return $temp;
  8. $temp=tempnam(__FILE__,'');
  9. if (file_exists($temp)) {
  10. unlink($temp);
  11. return dirname($temp);
  12. }
  13. return null;
  14. }
  15. }
  16. */
  17. function icl_troubleshooting_dumpdb(){
  18. if($_GET['nonce'] == wp_create_nonce('dbdump') && is_admin() && current_user_can('manage_options')){
  19. ini_set('memory_limit','128M');
  20. $dump = _icl_ts_mysqldump(DB_NAME);
  21. $gzdump = gzencode($dump, 9);
  22. header("Content-Type: application/force-download");
  23. header("Content-Type: application/octet-stream");
  24. header("Content-Type: application/download");
  25. header("Content-Disposition: attachment; filename=" . DB_NAME . ".sql.gz");
  26. //header("Content-Encoding: gzip");
  27. header("Content-Length: ". strlen($gzdump));
  28. echo $gzdump;
  29. exit;
  30. }
  31. }
  32. function _icl_ts_mysqldump($mysql_database)
  33. {
  34. global $wpdb;
  35. $upload_folder = wp_upload_dir();
  36. $dump_tmp_file = $upload_folder['path'] . '/' . '__icl_mysqldump.sql';
  37. $fp = @fopen($dump_tmp_file, 'w');
  38. if(!$fp){
  39. $fp = fopen('php://output', 'w');
  40. ob_start();
  41. }
  42. $sql="SHOW TABLES LIKE '".str_replace('_','\_',$wpdb->prefix)."%';";
  43. $result= mysql_query($sql);
  44. if( $result)
  45. {
  46. while( $row= mysql_fetch_row($result))
  47. {
  48. //_icl_ts_mysqldump_table_structure($row[0]);
  49. //_icl_ts_mysqldump_table_data($row[0]);
  50. _icl_ts_backup_table($row[0], 0, $fp);
  51. }
  52. }
  53. else
  54. {
  55. echo "/* no tables in $mysql_database */\n";
  56. }
  57. mysql_free_result($result);
  58. fclose ($fp);
  59. if(file_exists($dump_tmp_file)){
  60. $data = file_get_contents($dump_tmp_file);
  61. @unlink($dump_tmp_file);
  62. }else{
  63. $data = ob_get_contents();
  64. ob_end_clean();
  65. }
  66. return $data ;
  67. }
  68. if ( ! defined('ROWS_PER_SEGMENT') ) define('ROWS_PER_SEGMENT', 100);
  69. function _icl_ts_stow($query_line, $fp) {
  70. if(! @fwrite($fp, $query_line,strlen($query_line)))
  71. die(__('Error writing query:','sitepress') . ' ' . $query_line);
  72. }
  73. function _icl_ts_backquote($a_name) {
  74. if (!empty($a_name) && $a_name != '*') {
  75. if (is_array($a_name)) {
  76. $result = array();
  77. reset($a_name);
  78. while(list($key, $val) = each($a_name))
  79. $result[$key] = '`' . $val . '`';
  80. return $result;
  81. } else {
  82. return '`' . $a_name . '`';
  83. }
  84. } else {
  85. return $a_name;
  86. }
  87. }
  88. function _icl_ts_backup_table($table, $segment = 'none', $fp) {
  89. global $wpdb;
  90. $table_structure = $wpdb->get_results("DESCRIBE $table");
  91. if(($segment == 'none') || ($segment == 0)) {
  92. _icl_ts_stow("\n\n", $fp);
  93. _icl_ts_stow("DROP TABLE IF EXISTS " . _icl_ts_backquote($table) . ";\n", $fp);
  94. // Table structure
  95. _icl_ts_stow("\n\n", $fp);
  96. $create_table = $wpdb->get_results("SHOW CREATE TABLE $table", ARRAY_N);
  97. _icl_ts_stow($create_table[0][1] . ' ;', $fp);
  98. _icl_ts_stow("\n\n", $fp);
  99. }
  100. if(($segment == 'none') || ($segment >= 0)) {
  101. $defs = array();
  102. $ints = array();
  103. foreach ($table_structure as $struct) {
  104. if ( (0 === strpos($struct->Type, 'tinyint')) ||
  105. (0 === strpos(strtolower($struct->Type), 'smallint')) ||
  106. (0 === strpos(strtolower($struct->Type), 'mediumint')) ||
  107. (0 === strpos(strtolower($struct->Type), 'int')) ||
  108. (0 === strpos(strtolower($struct->Type), 'bigint')) ) {
  109. $defs[strtolower($struct->Field)] = ( null === $struct->Default ) ? 'NULL' : $struct->Default;
  110. $ints[strtolower($struct->Field)] = "1";
  111. }
  112. }
  113. // Batch by $row_inc
  114. if($segment == 'none') {
  115. $row_start = 0;
  116. $row_inc = ROWS_PER_SEGMENT;
  117. } else {
  118. $row_start = $segment * ROWS_PER_SEGMENT;
  119. $row_inc = ROWS_PER_SEGMENT;
  120. }
  121. do {
  122. $table_data = $wpdb->get_results("SELECT * FROM $table LIMIT {$row_start}, {$row_inc}", ARRAY_A);
  123. $entries = 'INSERT INTO ' . _icl_ts_backquote($table) . ' VALUES (';
  124. // \x08\\x09, not required
  125. $search = array("\x00", "\x0a", "\x0d", "\x1a");
  126. $replace = array('\0', '\n', '\r', '\Z');
  127. if($table_data) {
  128. foreach ($table_data as $row) {
  129. $values = array();
  130. foreach ($row as $key => $value) {
  131. if ($ints[strtolower($key)]) {
  132. // make sure there are no blank spots in the insert syntax,
  133. // yet try to avoid quotation marks around integers
  134. $value = ( null === $value || '' === $value) ? $defs[strtolower($key)] : $value;
  135. $values[] = ( '' === $value ) ? "''" : $value;
  136. } else {
  137. $values[] = "'" . str_replace($search, $replace, $wpdb->escape($value)) . "'";
  138. }
  139. }
  140. _icl_ts_stow(" \n" . $entries . implode(', ', $values) . ');', $fp);
  141. }
  142. $row_start += $row_inc;
  143. }
  144. } while((count($table_data) > 0) and ($segment=='none'));
  145. }
  146. if(($segment == 'none') || ($segment < 0)) {
  147. // Create footer/closing comment in SQL-file
  148. _icl_ts_stow("\n", $fp);
  149. }
  150. } // end backup_table()
  151. function icl_reset_wpml($blog_id = false){
  152. global $wpdb;
  153. if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'resetwpml'){
  154. check_admin_referer( 'resetwpml' );
  155. }
  156. if(empty($blog_id)){
  157. $blog_id = isset($_POST['id']) ? $_POST['id'] : $wpdb->blogid;
  158. }
  159. define('ICL_IS_WPML_RESET', true);
  160. if($blog_id || !function_exists('is_multisite') || !is_multisite()){
  161. if(function_exists('is_multisite') && is_multisite()){
  162. switch_to_blog($blog_id);
  163. }
  164. $icl_tables = array(
  165. $wpdb->prefix . 'icl_languages',
  166. $wpdb->prefix . 'icl_languages_translations',
  167. $wpdb->prefix . 'icl_translations',
  168. $wpdb->prefix . 'icl_translation_status',
  169. $wpdb->prefix . 'icl_translate_job',
  170. $wpdb->prefix . 'icl_translate',
  171. $wpdb->prefix . 'icl_locale_map',
  172. $wpdb->prefix . 'icl_flags',
  173. $wpdb->prefix . 'icl_content_status',
  174. $wpdb->prefix . 'icl_core_status',
  175. $wpdb->prefix . 'icl_node',
  176. $wpdb->prefix . 'icl_strings',
  177. $wpdb->prefix . 'icl_string_translations',
  178. $wpdb->prefix . 'icl_string_status',
  179. $wpdb->prefix . 'icl_string_positions',
  180. $wpdb->prefix . 'icl_message_status',
  181. $wpdb->prefix . 'icl_reminders',
  182. );
  183. foreach($icl_tables as $icl_table){
  184. mysql_query("DROP TABLE IF EXISTS " . $icl_table);
  185. }
  186. delete_option('icl_sitepress_settings');
  187. delete_option('icl_sitepress_version');
  188. delete_option('_icl_cache');
  189. delete_option('_icl_admin_option_names');
  190. delete_option('wp_icl_translators_cached');
  191. delete_option('WPLANG');
  192. $wpmu_sitewide_plugins = (array) maybe_unserialize( get_site_option( 'active_sitewide_plugins' ) );
  193. if(!isset($wpmu_sitewide_plugins[ICL_PLUGIN_FOLDER.'/sitepress.php'])){
  194. deactivate_plugins(basename(ICL_PLUGIN_PATH) . '/sitepress.php');
  195. $ra = get_option('recently_activated');
  196. $ra[basename(ICL_PLUGIN_PATH) . '/sitepress.php'] = time();
  197. update_option('recently_activated', $ra);
  198. }else{
  199. update_option('_wpml_inactive', true);
  200. }
  201. if(isset($_REQUEST['submit'])){
  202. wp_redirect(network_admin_url('admin.php?page='.ICL_PLUGIN_FOLDER.'/menu/network.php&updated=true&action=resetwpml'));
  203. exit();
  204. }
  205. if(function_exists('is_multisite') && is_multisite()){
  206. restore_current_blog();
  207. }
  208. }
  209. }
  210. ?>