Showing posts with label Wordpress. Show all posts
Showing posts with label Wordpress. Show all posts

Thursday, March 26, 2009

Wordpress and Unicode

You type some non-English character in Wordpress or Drupal editors. You save it only to find those characters have become ????. If this describes your problem, then you have an issue with Unicode. You need to turn on Unicode support for Wordpress and Drupal. It will require some change of code. Basically, both Wordpress and Drupal supports Unicode. However, by default, the databases are not configured to store unicode characters.

Wordprss


For Wordpres, the modification is straight-forward.

  1. Open up ‘wp-config.php’ from the root directory of your WordPress installation.

  2. Comment out the following lines by adding ‘//’ at the very beginning of the following two lines:
    define('DB_CHARSET', 'utf8');
    define(’DB_COLLATE’, ”);


So that section should now look like this:
//define('DB_CHARSET', 'utf8');
//define(’DB_COLLATE’, ”);

[Source: http://hansengel.wordpress.com/2007/10/09/wordpress-unicode-and-s/]

Drupal


For Drupal, the change is a bit more involved:

  1. Go to to the root directory of your Drupal installation.

  2. Save the following code in a file named collate_db.php


  3. <?php
    # Do not change anything below this ( :-) <- Rewwrite Editors note.)
    require_once("includes/bootstrap.inc");
    require_once("includes/database.inc");
    require_once("includes/database.mysql.inc");
    $connect_url = 'mysql://user:pwd@server/database';
    $active_db = db_connect($connect_url);
    $sql = 'SHOW TABLES';
    if ( !( $result = db_query( $sql ) ) ) {
    echo '<span >Get SHOW TABLE - SQL Error: ' . $result . '<br>' . "</span>\n";
    }

    while ( $tables = db_fetch_array($result) ) {
    echo $tables[0];
    # Loop through all tables in this database
    $table = $tables[key($tables)];

    if ( !( $result2 = db_query("ALTER TABLE %s COLLATE utf8_general_ci", $table) ) ) {
    echo '<span >UTF SET - SQL Error: <br>' . "</span>\n";

    break;
    }

    print "$table changed to UTF-8 successfully.<br>\n";

    # Now loop through all the fields within this table
    if ( !($result2 = db_query("SHOW COLUMNS FROM %s",$table) ) ) {
    echo '<span >Get Table Columns Query - SQL Error: <br>' . "</span>\n";

    break;
    }

    while ( $column = db_fetch_array( $result2 ) )
    {
    $field_name = $column['Field'];
    $field_type = $column['Type'];

    # Change text based fields
    $skipped_field_types = array('char', 'text', 'enum', 'set');

    foreach ( $skipped_field_types as $type )
    {
    if ( strpos($field_type, $type) !== false )
    {
    $sql4 = "ALTER TABLE $table CHANGE `$field_name` `$field_name` $field_type CHARACTER SET utf8 COLLATE utf8_bin";
    $result4 = db_query($sql4);

    echo "---- $field_name changed to UTF-8 successfully.<br>\n";
    }
    }
    }
    echo "<hr>\n";
    }
    ?>



  4. Look at the red line in the code in red (5th line). You have to replace that part with your installation-specific information.

  5. Open the file sites/default/settings.php under the same Drupal root directory. Copy the rest of the line of
    $db_url =

    and paste it after
    $connect_url = 

    in the above code.

  6. Save collate_db.php

  7. Open a browser window and request the collate_db.php from your browser.

  8. If everything is fine you would see something similar to this:
    access changed to UTF-8 successfully.
    ---- mask changed to UTF-8 successfully.
    ---- type changed to UTF-8 successfully.

    <--- Lines not shown --->

    watchdog changed to UTF-8 successfully.
    ---- type changed to UTF-8 successfully.
    ---- message changed to UTF-8 successfully.
    ---- variables changed to UTF-8 successfully.
    ---- link changed to UTF-8 successfully.
    ---- location changed to UTF-8 successfully.
    ---- referer changed to UTF-8 successfully.
    ---- hostname changed to UTF-8 successfully.


  9. Delete collate_db.php for security.


You are done.

[Source: http://www.urbannatives.net/localtreechild/..._ci_and_tabl ]

Monday, October 15, 2007

New look!

I never blogged seriously. I had a blog, which I called an online journal. I hand-rolled that blogging software. It worked moderately ok with my seldom blogging. I didn't have too many requirements, so it was quite spartan in terms of features. The presentation was done in XML with XSL. You can well guess it was a geeky piece of one-of-a-kind software.

Then I changed my hosting company. It came with blogging software - not just one, but you can choose one from many. I don't expect to be an avid blogger suddenly, though I sure hope to become one. But I decided to install one blogging software - any one - to see the features. The first one listed was Wordpress. I heard the name, so I went with it. I don't regret, actually I am quite impressed with it. Playing with the themes there, I chose something called Almost-Spring. I liked it. I tweaked the color scheme a bit, customized the sidebar, footer and borrowed the edited theme as the theme of my website. The change required changing layout for all the pages. In order to do so, I recoded the PHP pages, so that the next time I need to change the look of the site, I don't need to change each individual file. So, it has become sort of a home-brewed one-of-a-kind CMS. Yes, it is Deja Vu all over again.

So what about my old blog postings? I can possibly hack Wordpress to post backdated. But I do not have too many posts that I care about, and most of them are not time-topical anyway - either way it's not worth the time and effort the hack. I can just cut and paste some of them into this new blog and change the world! Keep checking this space for some earth-shattering old blog posts. Till then, bye.