Wednesday, January 16, 2008

WordPress MU Optimization Script

WordPress MU will be automatically established more than 10 tables when a new user register, so when a large number of users register will caused a lot of problem. Then I write some performance scripts can delete the WordPress MU inactive users.

The PHP source code as follows:


  $mysql_host = "localhost";
  $mysql_user = "root";
  $mysql_pass = "";
  $mysql_db = "wordpress";
  $mysql_mylink = mysql_connect($mysql_host, $mysql_user, $mysql_pass)
  or die ("Cannot make the connection");
  mysql_select_db($mysql_db, $mysql_mylink)
  or die ("Cannot connect to the database");
  $strsql="select * from wp_blogs where blog_id>2 ";
  $rs_query = mysql_query($strsql);
  $alls=mysql_num_rows($rs_query);
  while (($RS = mysql_fetch_array($rs_query))) {
  extract($RS);
  $blogid=$RS["blog_id"];
  $query2 = "select * from wp_".$blogid."_posts ";
  $result = mysql_query($query2);
  $num= mysql_num_rows($result);
  //print $num;
  if ($num<=2) {
  print "DROP TABLE IF EXISTS wp_".$blogid."_comments;";
  print "DROP TABLE IF EXISTS wp_".$blogid."_links ;";
  print "DROP TABLE IF EXISTS wp_".$blogid."_options ;";
  print "DROP TABLE IF EXISTS wp_".$blogid."_postmeta ;";
  print "DROP TABLE IF EXISTS wp_".$blogid."_posts ;";
  print "DROP TABLE IF EXISTS wp_".$blogid."_terms ;";
  print "DROP TABLE IF EXISTS wp_".$blogid."_term_relationships ;";
  print "DROP TABLE IF EXISTS wp_".$blogid."_term_taxonomy ;";
  print "DELETE from wp_blogs where blog_id=".$blogid.";";
  }
  }
  mysql_close ();

Wednesday, January 9, 2008

Custom WordPress Database Error Page

From what i have mentioned before, we can use a program to monitor the WordPress MySQL server, when the server is down, WordPress will auto send an e-mail and write to a text log file in a recorded. Now, WordPress 2.3.2, the latest version of the popular blogging platform allows you to define a custom database error page.

It is very simple. Just follow the following steps and within a few minutes your custom database error page is ready!

First, upload a file named log.txt to the WordPress root directory, chmod it to 666.

Second, Download the file db-error.php and upload it to WordPress content directory(wp-content/db-error.php).

Finally, replace the e-mail address of the code to your own e-mail.

That's it! From now on this error file will be report the error whenever your WordPress blog has encountered some trouble connecting to the database server.

Monday, December 31, 2007

Best of Moonlight Blog 2007

As we move into 2008 I thought it might be fun to look back quickly on the year that was with a top 20 post of the most popular posts published on Moonlight Blog this year (according to page views on Google Analytics). I hope you enjoy this trip back through the year of 2007 at Moonlight Blog.
  • Wordpress Plugin: Chinese PinYin Slug - 2,467 views

  • Survival For Standalone Blogs - 1,682 views

  • China Internet Censorship Goes Crazy - 1,682 views

  • The Secret Of Internet Censorship In China - 1,461 views

  • FeedBurner Blocked By China - 1,276 views

  • FeedBurner Is Completely Blocked In China - 1,201 views

  • Google Answers Censorship In China - 1,082 views

  • About This Blog - 1,041 views

  • Baidu Hijacking Google, Yahoo, Microsoft In China - 1,019 views

  • Google Launches Chinese Blog Search - 1,014 views

  • YouTube Blocked In China - 986 views

  • WordPress MU AdSense Plugin - 944 views

  • WordPress Plugin: Post2Mail, Send Post to Email - 693 views

  • How To Visit Google BlogSpot In China - 670 views

  • WordPress Plugin: Yearly Blog Stats - 625 views

  • Wordpress Plugin: Keyword Filter - 615 views

  • WordPress Plugin: MySQL Server Crash Monitor - 552 views

  • YouTube, Have a Merry Halloween - 540 views

  • WordPress Plugin: WP-PostViews JavaScript Edition - 526 views

  • About - 520 views 

  • All in all it was a fairly busy but very satisfying year of blogging here at Moonlight Blog. Thanks to the many readers who have contributed either with guest posts, comments, emails and tip offs. I'm looking forward to yet another great year in 2008.

    Saturday, December 29, 2007

    WordPress Plugin: Yearly Blog Stats

    Yearly Blog Stats is the easy way to display the total year number of blog posts, comments and other stats from anywhere within your blog. One file, easy to use.

    With Yearly Blog Stats, you display only the information you want, where you want. This plugin is highly flexible, simple to use, and completely free.

    Display any or all of the provided site statistics — customize your own set to provide only the statistics you want.

    Features:

    1. Total number of posts in this year
    2. Total number of comments in this year
    3. Most views post each month in this year

    Installation and Usage

    Unzip wp-stats.zip and copy wp-stats.php to your WordPress root directory.

    Download Latest:

    Click here to download the latest version of WordPress Yearly Blog Stats Plugin.

    Wednesday, December 26, 2007

    WordPress Plugin: SimpleTags Modification

    WordPress SimpleTags is a WordPress plugin that will allow you to easily manage tags of your blog. However, I found some of bugs of WordPress SimpleTags, here is my modification.

    1. Search terms problem:

    SimpleTags use of the full text of the search, as long as the article contains the keyword matching, which can lead to large errors match, I modify it only match of the headlines.

    Open file simple-tags\inc\simple-tags.admin.php, in line 1466, replace:

    $search_sql = "AND ( (post_title LIKE '%{$search}%') OR (post_content LIKE '%{$search}%') )";

    to:

    $search_sql = "AND ( (post_title LIKE '%{$search}%') OR (post_title LIKE '%{$search}%') )";

    2. Untagged only problem:

    When blog have large numbers of the article, the untagged only function will return errors, I change some of original code in the SQL statement , greatly improving the efficiency of search and speed.

    Open file simple-tags\inc\simple-tags.admin.php, in line 1475, replace:

    $p_id_used = $wpdb->get_col("
    SELECT DISTINCT term_relationships.object_id
    FROM {$wpdb->term_taxonomy} term_taxonomy, {$wpdb->term_relationships} term_relationships, {$wpdb->posts} posts
    WHERE term_taxonomy.taxonomy = 'post_tag'
    AND term_taxonomy.term_taxonomy_id = term_relationships.term_taxonomy_id
    AND term_relationships.object_id = posts.ID
    AND posts.post_type = '{$type}'");
    $filter_sql = 'AND ID NOT IN ("'.implode( '", "', $p_id_used ).'")';


    to:

    $p_id_used = "SELECT DISTINCT term_relationships.object_id
    FROM {$wpdb->term_taxonomy} term_taxonomy, {$wpdb->term_relationships} term_relationships, {$wpdb->posts} posts
    WHERE term_taxonomy.taxonomy = 'post_tag'
    AND term_taxonomy.term_taxonomy_id = term_relationships.term_taxonomy_id
    AND term_relationships.object_id = posts.ID
    AND posts.post_type = '{$type}'";
    $filter_sql = 'AND ID NOT IN ('.$p_id_used.')';

    Saturday, December 22, 2007

    WordPress Plugin: Post2Mail, Send Post to Email

    Some of WordPress user needed a plugin to send an e-mail to a mailing list whenever a post was published to the blog. Here is a modified version of the "Post2Mail" plugin which can email the post to a mailing list or email address.

    WordPress Post2Mail plugin allows you to automatically e-mail selected people when a post is published on your blog. Also useful for alerting an administrator when a post has been published on the blog. Configuration is done in the post2mail.config.php file which has comments to get you started.

    This modified plugin have the following Features:

    1. Support Far East Characters (such as Chinese Characters). Use base64 to encode email title to support Chinese Characters.

    2. Fix some Security bug.

    Installation / Configuration Instructions:

    1. Edit post2mail.config.php to add the email address or mailing list address.

    2. Upload post2mail.php and post2mail.config.php to your WordPress plugin directory.

    3. Activate the plugin.

    Download Latest:

    Click here to download the latest version of WordPress Post2Mail Plugin.

    Monday, December 17, 2007

    WordPress Plugin: WP-PostViews JavaScript Edition

    Lester Chan develop a greate WordPress plugin - WP-PostViews, can enable user to display how many times a post/page had been viewed. It's base on PHP. But if you active WP-Cache plugin, you will found that  WP-PostViews not working. So I develop a new javascript version of WP-PostViews, that can work fine with WP-Cache or WP Super Cache plugin.

    Installation / Configuration Instructions:

    1. Install normal version of WP-PostViews 1.20.

    2. Upload postviews.php to your WordPress plugin directory(wp-content\plugins\postviews).

    3. Upload wp-counter.php to your WordPress root directory.

    4. Activate the WP-PostViews plugin.

    Download Latest:

    Click here to download the latest version of WP-PostViews JavaScript Version plugin.