Advertisement
SergeyBiryukov

WordPress Search and Replace Tool charset fix

Oct 4th, 2011
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.09 KB | None | 0 0
  1. --- searchreplacedb2-original.php   Fri Aug 26 16:00:48 2011
  2. +++ searchreplacedb2.php    Tue Oct  4 21:52:04 2011
  3. @@ -239,7 +239,7 @@
  4.         @fclose( $file );
  5.     }
  6.  
  7. -   preg_match_all( '/define\s*?\(\s*?([\'"])(DB_NAME|DB_USER|DB_PASSWORD|DB_HOST)\s*?,\s*?([\'"])([^\3]*?)\3\s*?\)\s*?;/si', $file_content, $defines );
  8. +   preg_match_all( '/define\s*?\(\s*?([\'"])(DB_NAME|DB_USER|DB_PASSWORD|DB_HOST|DB_CHARSET)\s*?,\s*?([\'"])([^\3]*?)\3\s*?\)\s*?;/si', $file_content, $defines );
  9.  
  10.     if ( ( isset( $defines[ 2 ] ) && ! empty( $defines[ 2 ] ) ) && ( isset( $defines[ 4 ] ) && ! empty( $defines[ 4 ] ) ) ) {
  11.         foreach( $defines[ 2 ] as $key => $define ) {
  12. @@ -257,11 +257,14 @@
  13.                 case 'DB_HOST':
  14.                     $host = $defines[ 4 ][ $key ];
  15.                     break;
  16. +               case 'DB_CHARSET':
  17. +                   $char = $defines[ 4 ][ $key ];
  18. +                   break;
  19.             }
  20.         }
  21.     }
  22.  
  23. -   return array( $host, $name, $user, $pass );
  24. +   return array( $host, $name, $user, $pass, $char );
  25.  }
  26.  
  27.  /*
  28. @@ -279,6 +282,7 @@
  29.  $data = isset( $_POST[ 'data' ] ) ? stripcslashes( $_POST[ 'data' ] ) : '';    // your database
  30.  $user = isset( $_POST[ 'user' ] ) ? stripcslashes( $_POST[ 'user' ] ) : '';    // your db userid
  31.  $pass = isset( $_POST[ 'pass' ] ) ? stripcslashes( $_POST[ 'pass' ] ) : '';    // your db password
  32. +$char = isset( $_POST[ 'char' ] ) ? stripcslashes( $_POST[ 'char' ] ) : '';    // your db charset
  33.  // Search replace details
  34.  $srch = isset( $_POST[ 'srch' ] ) ? stripcslashes( $_POST[ 'srch' ] ) : '';
  35.  $rplc = isset( $_POST[ 'rplc' ] ) ? stripcslashes( $_POST[ 'rplc' ] ) : '';
  36. @@ -291,7 +295,7 @@
  37.  
  38.  // Scan wp-config for the defines. We can't just include it as it will try and load the whole of wordpress.
  39.  if ( $loadwp && file_exists( dirname( __FILE__ ) . '/wp-config.php' ) )
  40. -   list( $host, $data, $user, $pass ) = icit_srdb_define_find( 'wp-config.php' );
  41. +   list( $host, $data, $user, $pass, $char ) = icit_srdb_define_find( 'wp-config.php' );
  42.  
  43.  // Check the db connection else go back to step two.
  44.  if ( $step >= 3 ) {
  45. @@ -301,6 +305,13 @@
  46.         $step = 2;
  47.     }
  48.  
  49. +   if ( ! empty( $char ) ) {
  50. +       if ( function_exists( 'mysql_set_charset' ) )
  51. +           mysql_set_charset( $char, $connection );
  52. +       else
  53. +           mysql_query( 'SET NAMES ' . $char, $connection );
  54. +   }
  55. +
  56.     // Do we have any tables and if so build the all tables array
  57.     $all_tables = array( );
  58.     $all_tables_mysql = mysql_db_query( $data, 'SHOW TABLES', $connection );
  59. @@ -511,6 +522,11 @@
  60.                     <label for="pass">Password:</label>
  61.                     <input class="text" type="password" name="pass" id="pass" value="<?php esc_html_attr( $pass, true ) ?>" />
  62.                 </p>
  63. +
  64. +               <p>
  65. +                   <label for="pass">Charset:</label>
  66. +                   <input class="text" type="text" name="char" id="char" value="<?php esc_html_attr( $char, true ) ?>" />
  67. +               </p>
  68.                 <?php icit_srdb_submit( 'Submit DB details' ); ?>
  69.             </fieldset>
  70.         </form> <?php
  71. @@ -528,6 +544,7 @@
  72.                 <input type="hidden" name="data" value="<?php esc_html_attr( $data, true ) ?>" />
  73.                 <input type="hidden" name="user" value="<?php esc_html_attr( $user, true ) ?>" />
  74.                 <input type="hidden" name="pass" value="<?php esc_html_attr( $pass, true ) ?>" />
  75. +               <input type="hidden" name="char" value="<?php esc_html_attr( $char, true ) ?>" />
  76.                 <p>
  77.                     <label for="tables">Tables:</label>
  78.                     <select id="tables" name="tables[]" multiple="multiple" class="multi"><?php
  79. @@ -551,7 +568,8 @@
  80.                 <input type="hidden" name="host" id="host" value="<?php esc_html_attr( $host, true ) ?>" />
  81.                 <input type="hidden" name="data" id="data" value="<?php esc_html_attr( $data, true ) ?>" />
  82.                 <input type="hidden" name="user" id="user" value="<?php esc_html_attr( $user, true ) ?>" />
  83. -               <input type="hidden" name="pass" id="pass" value="<?php esc_html_attr( $pass, true ) ?>" /> <?php
  84. +               <input type="hidden" name="pass" id="pass" value="<?php esc_html_attr( $pass, true ) ?>" />
  85. +               <input type="hidden" name="char" id="char" value="<?php esc_html_attr( $char, true ) ?>" /> <?php
  86.  
  87.                 foreach( $tables as $i => $tab ) {
  88.                     printf( '<input type="hidden" name="tables[%s]" value="%s" />', esc_html_attr( $i, false ), esc_html_attr( $tab, false ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement