= fn(n){n xor 0xFFFF004B eq 0×0 ? n : fn(n – 0×1)}

Archive for March, 2009

My Webklip Plugin For Wordpress: Goes Multiple-RSS!

Sunday, March 29th, 2009

Today I refactory the source code and add new features to Webklip, it becomes 1.2 and, most encouraging, multiple rss supports!

The improvement includes:

  • Uses template engine to show widget. No more embedded HTML.
  • Moves all functions to a util class
  • Supports up to 5 RSS
  • Still reads RSS feed dynamically on client-side

The feature version will be released next day or two, will enhance javascript flexibility. E.g., not compulsorily needs jQuery framework.

You can download the widget on http://www.koumei.net/download/wp-webKlip.zip

Relative article:

Wordpress Widget: Client-side RSS util, The Web Klip Released!



Kimport critical update: v1.5.1

Wednesday, March 25th, 2009

I found a severe bug when uploading an excel with rich-text content on cellular.

At this version I also enhance logs output that you can get more info if uploading fails.

You can download it using SVN or just the package.



Virtuemart: Ajax Effect on IE 8 Fix List based on Virtuemart 1.1.3(stable release since 22, Jan)

Monday, March 23rd, 2009

Virtuemart utilizes Ajax mostly by mooTools. It works fine in many browsers except microsoft newly released browser IE 8. Especially when user try to add a product to shopping cart using Ajax, the mooPrompt (a pop-up window) fails, and nothing happen on that page… Maybe the first thing you are about to do is to upgrade mooTools. Yes, that’s seems a great idea, however mooTools’s updates from 1.11 to 1.21 is totally a nightmare for developer. Many things change, you have to revise the code manually for Virtuemart. 

The following files should be updated (if you want to satisfy IE 8 users):

  • \components\com_virtuemart\js\mootools\mootools-release-1.11.js  (update to 1.21)
  • \components\com_virtuemart\js\mootools\mooPrompt.js (you have to revise it manually. Should change a lot of JS class definitions in accordance with mootools 1.21 syntax)
  • \components\com_virtuemart\js\slimbox (update to slimbox for mootools 1.21)
  • \components\com_virtuemart\themes\default\theme.js (you have to revise it manually. Should fix a bug on line 59, change to var timeoutID = setTimeout( ‘document.boxB.close()’, 3000 );)

Besides updating corresponding files, you can also disable Ajax function on the administration page. Or.. Wait until next stable release of VM). If you need the files above, just leave me a message, and I will pack them up for you.



Web Klip Enhancement – Special Effect Applied

Sunday, March 22nd, 2009

Currect release: 1.1

Download: http://www.koumei.net/download/wp-webKlip.zip

Not too much special effects. In order to make the contents which read from the underneath javascript show themselves up naturally. Not in a harsh.



Wordpress Widget: Client-side RSS util, The Web Klip Released!

Saturday, March 21st, 2009

The original Wordpress (2.7+) provides RSS clip widget from the other website. It looks good but it is server-side script that may occupy the server resource to interpret the RSS. I don’t like that approach. So I decide to create a client-side script that loads rss from other website or blog.

If you want to try, just download the widget on http://www.koumei.net/download/wp-webKlip.zip , then unzip to wp-content/plug-ins/ folder, and activate the plugin and add widget to you wordpress blog.

Before using this widget, there are some notes you should know:

  1. Defects:
    Currently only support ONE RSS excerpt.
    Only shows the first RSS item.
    jQuery should be included on your blog.
  2. Usability:
    Site that provide at least 1 item RSS feed could be refered by this widget.
  3. Extension:
    Multiple-RSS and rollover will be available  on next release.

The Demo:

webklip_1
Picture 1. The plugin will be shown after you copy the unzipped file to your plugin folder
webklip_2
Picture 2. Add the widget to the “Widgets” menu on your administration panel. You can add a RSS feed to this widget

You can  find the demo on the right side of my blog.

:-)



A Simple Rss2Json Service Released!

Friday, March 20th, 2009

Now I simply add a Rss2Json service on my blog, it just return the very first post from the target website as JSON and, of course, the target should be RSS format. The reason why I create this interface is because I would like to utilize cool AJAX to obtain the content from my friend’s blog, yet the browser secure prevent me crossing the boundary to other domain. Could it be working using iFrame? Negative. The only approach to cross the border is using JSON.

The definition of my interface is:

Name: Rss2JSon
Interface: http://www.koumei.net/rss2json/
Method: GET
Parameter 1:  rss  – The URL of the rss content
Parameter 2: cb — The javascript callback function
Return: application/x-javascript
Example: http://www.koumei.net/rss2json/?rss=http://www.blogjava.net/max/rss&cb=<callback>  (A blog of my friend)

The callback function is very significant. Don’t forget to define a callback JS function on your script. The definition of the callback function should be similar as below ( parameter rss is an object, containing “title”, “link” and “description” and so forth<please go through RSS schema on item tag>.)

<script type=”text/javascript”> 

function myCallback(rss){
    var title = rss["title"];   // or rss.title
    var link = rss["link"];  // or rss.link
    var desc = rss["description"];  // or rss.description.
}

</script>

Now, you can embed the script to wherever you need.
<script type=”text/javascript” src=”http://www.koumei.net/rss2json/?rss=http://www.blogjava.net/max/rss&cb=myCallback”></script> 

Enjoy scripting.



Don’t you think that Twitter is so boring …?

Thursday, March 19th, 2009

Twitter is good for the people who’s getting tired for the ordinary life, I guess. The tedious blogging, facebook and other SNS stuffs always rob your brain. Maybe I just don’t need such a thing to keep tracking what I am doing.

But from technician’s view, I like the API provided by Twitter. They are RESTful web services that you can access via http. Cool.



An idea for “Add to Favorite” function for virtuemart

Wednesday, March 18th, 2009

The original Virtuemart provides RSS feed to every product, so that users can “eat” the feed if they like the product. The idea is cool, but actually, I prefer an on-line favorite subscribe function for the user than RSS subscribe. The RSS subscription is good to track back to a single category or a whole website, not so good to track each product. How many chance you would like to change the product’s description or product’s price to let the users know the newest status of product? So your product categories and website will be renew every now and then, even everyday, but not a single product, right? So the single product is good to be traced on the website’s favorite function. Unfortunately, Virtuemart doesn’t come with such a function for people to trace their own favorite product. The favorite products mean the products are probationary, users don’t buy them, but could buy them later. So what I think the “Add to Favorite” function could be specified as:

  1. It’s managable. User could easily add product to favorite list just a single click, better not refresh the page after they click a button.
  2. User can review the favorite list. 
  3. The product in the favorite list will be shown when the product is published.

I think this little gadget could help user shopping with happiness.



Howto: Create “Cash on Delivery” payment Varied from Different Postcodes for Virtuemart

Tuesday, March 17th, 2009

Actually Virtuemart has done a great job on cash on delivery support, but what if cash on delivery cost a fee not only the total amount of purchase but also the different postcode? Here comes a tutorial on how to calculate the different rates based on users’ postcode.

Of course, before doing that, you need to have a workable Virtuemart distribution on joomla. You can find more tutorials on joomla official website or virtuemart website.

There are only two steps of this simple tutorial:

  1. Create a new payment method on Cash on Delivery. Actually the orignal virtuemart comes with an option of “COD”, but at this time I don’t want to ruin its file structure. I prefer to create a new one. Actually creating new payment method helps you to know more about joomla.
  2. Revise “ps_checkout.php” to make it works.

Let’s dive to details.

Create a new payment method on Cash on Delivery.

Sooner or later will you find that creating payment method couldn’t be easier. What you need to do is to create a class, and of course, you write some methods which is recoginzed by joomla framework. You can find bunch of original payment classes on /administrator/components/com_virtuemart/classes/payment/ folder. If you see carefully, you can see each payment class comes with a config file. For instance, you can see a payment class called ps_paypal.php, should come with a config named ps_paypal.cfg.php. I won’t use config file, so I don’t need the cfg.php file. Now here’s my turn on creating such a class:  create a file name “ps_codonpc.php” (which means “Cash On Delivery On PostCodes”), never mind its name, but I think you better follow the naming convention of Virtuemart. Open this file with any kind of text-editor, I recommend to use notepad++. Create a skeleton below.

if( !defined( '_VALID_MOS' ) &amp;&amp; !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
 
class ps_codonpc{
 
var $classname = "ps_codonpc";
var $payment_code = "PU";
 
function show_configuration() {
return false;
}  
 
function has_configuration() {
return false;
}
 
function get_payment_rate($sum, $ship_to_info_id=null) {
}  
 
function configfile_writeable() {
return true;
}
 
function configfile_readable() {
return true;
}
 
function write_configuration( &amp;$d ) {
return true;
}
 
function process_payment($order_number, $order_total, &amp;$d) {
return true;
}
 
}

I know what you must be thinking.  You must be wondering if there is any necessity to create those functions within the class. Yes, you have to. That’s the weakness as well as fexibility of the characteristic  object-oriented of PHP. Well, it makes senses, because PHP is runtime dynamic language, not compile-time language. The payment classes on /payment folder are dynamically recognized by the framework, they use the same functions naming convention to make the polymorphism works.  I mean the ps_paypal.php and ps_paymate.php are of the same functions’ name, and created by the framework, however the framework doesn’t need to know the existance of payment classes and doesn’t know what they are doing. The framework only knows their functions’ name. Confused? Never mind.  Forget this paragraph. You can do the same thing on java using “reflection”.

You can see a function called “get_payment_rate” in this class. Well, not all the classes in /payment folder have this function. Why? That’s because virtuemart framework will only calculate the payment rate if the “get_payment_rate” function is defined. Actually, there is only one parameter is need: $sum, but since we need to calculate the fee by post code, I add an additional paramter(ship_to_info_id)  and give it a default value(null).

Now you need to fill the “get_payment_rate” logic to make it works. I add a simple logic to calculate the payment rate.

function get_payment_rate($sum, $ship_to_info_id=null) {
		//Get the ship_to_info_id if the parameter is null
		//Normally the item is passed from checkout module
		//We need to change ps_payment_method.php to pass the parameter to this object.
		if( empty( $ship_to_info_id )) {
 
		    $sdb = new ps_DB();
 
		    $sdb->setQuery( "SELECT user_info_id FROM #__{vm}_user_info WHERE user_id=".$auth['user_id']." AND address_type='BT'" );
 
		    $ship_to_info_id = $sdb->loadResult();
 
		}
 
		//Get the zip(post code) from user info table
 
if(!empty( $ship_to_info_id )){
 
			$sdb = new ps_DB();
 
			$qry = "SELECT `zip` FROM `#__{vm}_user_info` WHERE user_info_id='".$ship_to_info_id."'";
 
			$sdb->query($qry);
 
			$sdb->next_record();
 
			$postcode = $sdb->f('zip');
		}  
 
		if(!empty($postcode)){
			if($postcode >= '3000' && $postcode < '3050'){
				return 0;  //these areas are free
			}else if($postcode >= '3050' && $postcode < '3150'){
				return floatval( $GLOBALS['CURRENCY']->convert(-5));  //these areas cost $5
			}else{
				return floatval( $GLOBALS['CURRENCY']->convert(-10)); //the othes cost $10
			}
		}else{ //unknow post code, use default
			return floatval( $GLOBALS['CURRENCY']->convert(-10)); //the othes cost $10
		}
}

Can you see the return value? it’s negative, that’s because the get_payment_rate function return the payment discount (according to the definition of this function), the name should be changed to get_payment_discount. Otherwise would be a little bit confused. If you return a positive, the users will get a discount from this payment; a negative, the users will pay an extra fee.

OK. That’s fine.

Revise “ps_checkout.php” to make it works.

And now go to ps_checkout.php, and find a line 1673, change “return $_PAYMENT->get_payment_rate($subtotal);” to

$ship_to_info_id = $_REQUEST['ship_to_info_id'];
return $_PAYMENT->get_payment_rate($subtotal, $ship_to_info_id);
“.

Okey dokey, Now add the Cash On Delivery paymethod on your administration page, and then go through the check out process and find out more excitement. Of course, the logic provided here is very simple, you can judge the rate from a post code data table and apply new features.



Fire with explosion near Kensington station

Monday, March 16th, 2009

10 mins ago I was woken up by an explosion and interval of noise. Then I heard a siren coming far away. I stood up and saw a fire in the park need Kensington station! It was dark, couldn’t see clearly, the noise sounded like a car explosion. I took a picture for this. within a minute the fire was put out. Hopefully nobody gets hurt on this accident.

5oclock



Profile



Submit Your Site To The Web's Top 50 Search Engines for Free!