Archive for January, 2008

Today I did some modifications to Starbox to let it utilize the power of Prototip. They are both cool JavaScript libraries written by Nick Stakenburg.

Starbox prototip

How does it work? When you hover your mouse on a star, a tip shows you a brief word like “lame” or “great” which helps you with your choice. If the rating box is locked, a single tip is shown wherever you hover on the box. Check out the demo. View its source to see how to get it working.

You can globally set the tips, or specify a group of tips for each specific rating box instance.

Get it

View Diff | Download the modified version

CSS for the tip (included in the zip archive):

.prototip .startip {
 color: infotext;
 background-color: infobackground;
 border: 1px solid infotext;
 padding: 1px;
}

Movable Type 4.1 was just announced. As stated in the blog post, this is a (the first?) stable release of Movable Type Open Source.

The download link given on movabletype.org is a zip file. However if you want gzip format, you can get it here. This version is under the GPL v2 license. And you can also download another version here if you agree to the personal license.

The two files are not identical, if you check them. That makes sense because they include different license agreements in their source code headers. However, they deliver the same code and functionalities as far as I know.

I just upgraded my Movable Type powered blog (not this one) to the latest version of MTOS and I really like the new layout of creating entries. Don’t forget overwriting the old mt-static directory - I missed this step as a novice and the admin page was messed up :)

Yes, I’m still a novice user of Movable Type. I’m very curious about a different approach than WordPress (OK, WP is a different approach than MT).

I saw on the web many discussions about “the best JavaScript editor”. This kind of discussions are quite like “the best PHP editor”. Neither of these two languages has a good editor as other languages like C++/Java. The difficulty in making a good PHP editor is that PHP codes are always mixed with HTML. And the difficulty in making a good JavaScript editor is that JavaScript is too flexible and even worse, different browsers have different implementations.

But there are some good JavaScript editors that’s recommended by people engaged in the discussions. The most mentioned two are JSEclipse and Aptana.

Aptana

I only tried it (the free plugin for Eclipse) for two weeks and gave up.

In Aptana’s editor, you can select a piece of code and press Ctrl+Shift+F to format it, which is like the Java editor. That’s good. But the formatting result is not as good, unfortunately. I couldn’t configure it to generate the same formatting as Java code. So actually this good feature is of no use for me. Even worse, when you press } to close a block, it will “help” you format this block. Clever, but ugly.

Aptana shows its suggestions for you almost every time in type in a character. But the suggestions are absolutely useless most of the times.

Features described on its homepage are quite promising but I didn’t try them all. These two mentioned above are already too annoying. So I switched back to JSEclipse.

JSEclipse

I use JSEclipse most of the time. It’s very simple compared to Aptana. You can see a list of features on its homepage. For me, the most useful feature is that when the cursor is on some identifier (variable, function name, etc.), all occurrences of the same identifier are highlighted. Even though sometimes it will wrongly mark some extra identifiers, it doesn’t matter much.

Sadly it’s acquired by Adobe. You see, the links given above are adobe’s. The original homepage, however, is here. The last update to JSEclipse was on April 2, 2007. So it’s almost dead. It’s really a pity. See this post in Adobe forums.

Anyway, these are only my own experiences and may be full of prejudices. Which editor are you using for editing JavaScript? please comment below.

I followed the official instructions to install Movable Type 4 on this host, but the 500 error page appeared every time I clicked the “begin” button. Besides, the mt-check.cgi script generated an incomplete HTML output - it’s terminated at some point.

The log of the 500 error:

… Out of memory!, referer: http://example.com/cgi-bin/mt/mt-wizard.cgi
… Callback called exit at mt-wizard.cgi line 11., referer: http://example.com/cgi-bin/mt/mt-wizard.cgi
… END failed–call queue aborted at mt-wizard.cgi line 1., referer: http://example.com/cgi-bin/mt/mt-wizard.cgi
… Callback called exit at mt-wizard.cgi line 1., referer: http://example.com/cgi-bin/mt/mt-wizard.cgi
… BEGIN failed–compilation aborted at mt-wizard.cgi line 11., referer: http://example.com/cgi-bin/mt/mt-wizard.cgi
… Premature end of script headers: mt-wizard.cgi, referer: http://example.com/cgi-bin/mt/mt-wizard.cgi

I read through the troubleshooting doc of Movable Type but it seems not to be any of the problems listed there. When I searched for “Premature end of script headers: mt-wizard.cgi“, there’re no answers in English results.

I asked the support of this hosting company but at first they said it must be the problem of the script. Oh I’m using the stable release of MT4 and it’s used widely across the world. I wouldn’t believe it.

Then suddenly I received a message from root in the secure shell:

Please try to do your installation again.
We have identified a problem which has been corrected.

Yes, it worked like a charm. Soon I received a the problem description from support:

The problem appears to be related to memory limitation set in the apache configuration. This Apache limitation has been removed and memory is now controlled via PHP.

There’re quite a lot people stuck by this error when trying to start the Movable Type tour as I see. Most people don’t believe that the memory out error is true but indeed it is in my case. Hope this helps someone.

When I started working on the Neighbor Post Preview plugin, I expected WordPress to have a built-in function to get an excerpt from an arbitrary post. But it doesn’t have one, sadly.

There is only an the_excerpt tag for use within The Loop. It’s defined in wp-includes/post-template.php (version 2.3.2 code):

function the_excerpt() {
	echo apply_filters('the_excerpt', get_the_excerpt());
}

function get_the_excerpt($deprecated = true) {
	global $id, $post;
	$output = '';
	$output = $post->post_excerpt;
	if ( !empty($post->post_password) ) { // if there's a password
		if ( $_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password ) {  // and it doesn't match the cookie
			$output = __('There is no excerpt because this is a protected post.');
			return $output;
		}
	}

	return apply_filters('get_the_excerpt', $output);
}

See the bad code? I don’t know who wrote this, but the line “$output = $post->post_excerpt;” should be placed after the if block. OK, this is out of topic :) .

Generally the function retrieves the explicit post excerpt and apply filters “get_the_excerpt” and “the_excerpt”. What is the explicit excerpt? When you’re writing or editing a post, its input is right below your editing area. I never wrote one, though. Most bloggers don’t write excerpts, I believe. So what happens when we apply filter “get_the_excerpt” to an empty string?

Let’s have a look at the code in wp-includes/default-filters.php:

add_filter('the_excerpt', 'wptexturize');
add_filter('the_excerpt', 'convert_smilies');
add_filter('the_excerpt', 'convert_chars');
add_filter('the_excerpt', 'wpautop');
add_filter('get_the_excerpt', 'wp_trim_excerpt');

By default, the string is processed only by the function wp_trim_excerpt (defined in wp-includes/formatting.php) before applying “the_excerpt” filters:

function wp_trim_excerpt($text) { // Fakes an excerpt if needed
	global $post;
	if ( '' == $text ) {
		$text = get_the_content('');
		$text = apply_filters('the_content', $text);
		$text = str_replace(']]>', ']]>', $text);
		$text = strip_tags($text);
		$excerpt_length = 55;
		$words = explode(' ', $text, $excerpt_length + 1);
		if (count($words) > $excerpt_length) {
			array_pop($words);
			array_push($words, '[...]');
			$text = implode(' ', $words);
		}
	}
	return $text;
}

If the string is empty, the excerpt is faked using the content of the global $post. After that, the excerpt is filtered by some functions to make some “clean” text.

So I wrote this helper function for use in the plugin:

function tlnpp_excerpt($text, $excerpt_length = 55) {
	$text = str_replace(']]>', ']]>', $text);
	$text = strip_tags($text);
	$words = explode(' ', $text, $excerpt_length + 1);
	if (count($words) > $excerpt_length) {
		array_pop($words);
		array_push($words, '[...]');
		$text = implode(' ', $words);
	}

	return apply_filters('the_excerpt', $text);
}

This function truncate an arbitrary piece of text to 55 words by default, and process the result using the default WordPress filter functions (converts smiley’s, for example). It truncates text by words not characters, and the result is safe.

For more information, have a look at the code of the plugin. It’s very simple. Any suggestions?

I assume you’re reading this post on its own page (i.e. the permalink). If you’re on the front page, or in an RSS reader, please go to its own page.

Above the title of this post, there is the previous/next post navigation bar. Now hover your mouse on the previous post link, but don’t click :) . Did you see the little bubble showing the excerpt of the previous post? That’s it!

Sometimes title is not enough for visitors to determine whether the post is worth reading. With an excerpt, more information is provided. Some posts with great titles are worthless, while some great stories are under unromantic titles.

I just made the plugin Neighbor Post Preview to do this thing. Visit its page for download and installation instructions.

Thanks to the great JavaScript libraries - Prototype and Prototip.

Hope you enjoy this plugin and I welcome all feedbacks and suggestions.