Moved to Wordpress

April 1st, 2008

After a few years using my own blog script –yeah, bleedy script, written from scratch– I finally decided to use Wordpress for this blog.

There are a lot of things to do such as syntax highlight, re-arrange the messy source code inside a blog post etc. But one for sure, you can still access any post using the old URL.

Yes, the URLs are not changed.

Youtube downloader is working!

March 3rd, 2008

Mobi.web.idFor more than a month my youtube downloader script was not working due to youtube changed their layout. Today I’ve rewritten the script and simplified the functionality. Now mobi.web.id is running again and ready to help everyone download videos from Youtube.

Previous script consist of four functions and I’ve shortened into two functions. Please hit the read button to see the full working script.

Here’s the shorten code for youtube downloader: function get_http_header($url){
$uh = curl_init();
curl_setopt($uh, CURLOPT_URL, $url);
curl_setopt($uh, CURLOPT_HEADER, 1);
curl_setopt($uh, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($uh);
curl_close($uh);
return $res;
}

function show_url($http_header){
$arai = explode(”\n”,$http_header);
foreach($arai as $ini){
if(eregi(”location”,$ini)) $url = $ini;
}
list($sampah,$hasil) = explode(”Location:”,$url);
return str_replace(”\n”,”",trim($hasil));
}

function download_youtube($url){
if(ereg(’&',$url)){
if (eregi(”watch\?v=(.*)&”, $url, $out)) {
$video_id = $out[1];
}
}
else{
list($none,$video_id) = explode(’watch?v=’,$url);
}
$secret_link = substr(show_url(get_http_header(’http://youtube.com/v/’.trim($video_id))),11);
$video_url = show_url(get_http_header(’http://youtube.com/get_video?’.$secret_link));
list($dl_url,$sign) = explode(”&signature”,$video_url);
return $dl_url;
}

// EXAMPLE:
echo download_youtube(’http://www.youtube.com/watch?v=5uy7SAidyTM’);
?>

Have phun, may the source be with you! ^_^

PHP code highlight

February 27th, 2008

As you may see in this blog, all PHP codes will be highlighted so they become readable and looking good. This time I will share my script to highlight the code inside a bunch of text.

Yes, it will highlight string inside [code] and [/code] only, like following sample:

Here is a sample of PHP script:
[code]
<?php
if($name == ‘neo’){
    echo ‘Hei you!’;
}
?>
[/code]
then save it as sample.php.

The result will be displayed as follow:

Here is a sample of PHP script:

if($name == 'neo'){
echo 'Hei you!';
}
?>

then save it as sample.php.

Now we see the magic behind the highlighting process:
// function to call
function highlight_code($txt){
$hasil = preg_replace_callback('{\[code\]((.|\n)+?)\[/code\]}i',"replace_code", $txt);
return $hasil;
}

// main function
function replace_code($ketemu){
$hasil = trim($ketemu[1], "\n ");
return highlight_string($hasil, true);
}

// sample of usage:
$string = "It's PHP info: [ code ] [ /code ]“;
echo highlight_code($string);
?>

The main function is the replace_code() function that will highlight the string. But we need to return the the highlighted string back into the full strings. So we use the callback, using highlight_code() function.

Good luck ^_^

Re-claim this blog on technorati

February 26th, 2008

This is just a reclaiming this blog on Technorati Profile. Please ignore.

What Opera Dragonfly could be

February 26th, 2008

Opera DragonflyOpera Watch reported that they’re preparing something called Opera Dragonfly. There’s no clue what the dragonfly could be but a teaser said:

“I won’t say quite yet, but I do think that, in my opinion, it is the most important project we have on going at the moment, and probably since I’ve been at the company. It won’t directly affect everybody, but will hopefully become invaluable for those that it does.”

So I’m thinking that the dragonfly will be a developer tools to dealing with HTML/CSS/Javascript just like firebug in Firefox.

It’s great if the dragonfly is realy a developer tools, since the current developer tools available for Opera is not very handy and rather dificult to use. Let’s wait for the dragonfly.

Get DPI value of an image using PHP

February 19th, 2008

This is a simple function I wrote to get a DPI (dot per inch) value from an image using PHP only, without the need of ImageMagick nor GD library. The script was inspired from denisb post (the third post). At the forum, he described how to get the DPI value stored within the file.

function get_dpi($filename){

// open the file and read first 20 bytes.
$a = fopen($filename,'r');
$string = fread($a,20);
fclose($a);

// get the value of byte 14th up to 18th
$data = bin2hex(substr($string,14,4));
$x = substr($data,0,4);
$y = substr($data,4,4);
return array(hexdec($x),hexdec($y));

}

// output the result:
print_r(get_dpi2('filename.jpg'));
?>

I have tried this function to get DPI value of an image that I generated using Photoshop and worked as expected but failed to get DPI value from an image from any digital camera. It returned weird value instead.

Any idea why this function failed to retrieve DPI value from image that generated by digital camera? Please share your opinion.

Opera Mobile jumps from 8.6 to 9.5

February 8th, 2008

Opera Mobile
You might questioning what happen with Opera Mobile version 9 and why Opera Mobile jumps its version from 8.65 to 9.5.

Opera Mobile is intended to be a replacement for Opera Desktop in a mobile device. To achieve the same browsing experience between desktop and mobile, both browsers must have the same method to display the website. Since the latest version of Opera Desktop is 9.5 so Opera Mobile should have the same version and same rendering engine. Opera Mobile 9.5 using the same rendering engine as Opera Desktop 9.5 called Presto.

By this way, Opera hopes that there’s no difference between browsing using PC or mobile gadgets. Opera also said that this version is a lot faster than previous and the GUI was completely rebuild to increase user experience. And hey, it runs widgets just like Opera for desktop!

Now I’m waiting for Opera Mobile 9.5 to be available for Symbian UIQ 3.

Why don’t they use Opera

January 21st, 2008

I’ve made a simple pool for my blog readers. I ask them why don’t they use Opera as their main browser, and here came across some answers:

  • At first time they used Opera, they found that Opera’s cache is too strong. And it’s a problem for a web developer because they can’t see the change right away. Well, if they know about Shift+F5, it’s not a problem at all.
     
  • They wonder if they can found something like Firefox’s plugins. They don’t want to switch to Opera because they afraid of loosing the plugin’s benefit.
     
  • Some people using glubble to protect their kids from unwanted page, and Opera doesn’t have this such thing.
     
  • Because Opera is not open source. Well, they don’t really need the source code but they afraid if someday Opera company will be closed. Thus, Opera users will be dumped away. But if Opera were open source, there will be another group who would give Opera a re-birth.
     
  • A friend was afraid of intergalactic law violation when using a little trick to open Google Docs

Last but not least, a little sweet girl was saying that this question is the same as “Why Mac users aren’t as many as Windows users”.

From this pool, now I have idea why don’t they use Opera: because they don’t know much about Opera. Then it’s a task for Opera company to spread more information about Opera and its benefits.

I also wrote this at My Opera blog and forward to Daniel Goldman.

Design Inspirations and Opera Mini 5?

January 9th, 2008

Opera MiniI have a plan to re-design my other blog but still have no idea what to do with the color, placement etc. Until I reached Smashing Magazine and found two posts related to design. I also read a news from Opera Watch about an Indian magazine, My Mobile, that wrote about Opera Mini 5.

Here they are the links:

Happy reading, everyone!

Youtube Downloader using PHP

January 7th, 2008

This short tutorial will show you how to download videos from Youtube using PHP. CURL is needed for this script because many webhosting now prohibit remote_fopen.

First function, get HTML content from an URL: function get_content_of_url($url){
$ohyeah = curl_init();
curl_setopt($ohyeah, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ohyeah, CURLOPT_URL, $url);
$data = curl_exec($ohyeah);
curl_close($ohyeah);
return $data;
}
?>

Second function, get string that contain the clue of where the video file is located: function get_flv_link($string) {
if (eregi("watch_fullscreen\?video_id=(.*)&title=", $string, $out)) {
$outdata = $out[1];
}
return 'http://youtube.com/get_video.php?video_id='.$outdata;
}
?>

Next function, “visit” the link that we got from second function above. We will read the header and find out the real file location: function get_http_header($url){
$uh = curl_init();
curl_setopt($uh, CURLOPT_URL, $url);
curl_setopt($uh, CURLOPT_HEADER, 1);
curl_setopt($uh, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($uh);
curl_close($uh);
return $res;
}
?>

Function above will return a bunch of HTTP headers and we don’t need them all. This function will parse the HTTP headers and only return the video location: function show_url($http_header){
$arai = explode("\n",$http_header);
foreach($arai as $ini){
if(eregi("location",$ini)) $url = $ini;
}
list($sampah,$hasil) = explode("Location:",$url);
return str_replace("\n","",trim($hasil));
}
?>

Last thing to do, is bundle all functions above: function download_youtube($url){
$data = get_content_of_url($url);
$next_url = get_flv_link($data);
$data = get_http_header($next_url);
return show_url($data);
}
?>

Wait, how to use the youtube downloader? It’s very simple: $url = "http://youtube.com/watch?v=SAQZ0BDXn48";
echo download_youtube($url);
?>

That’s all folks. It’s a very interesting and chalenging moment when I wrote any kind of grabbing scripts. Hope it helps yo all.