Grab your Google Buzz Status

Here’s how you can get your google buzz status with php. Just put your google username at the right place and do whatever you want.
We have used simpleXML to parse the google’s RSS feed for every user. :)

<?php
$user = "<username>";
$url = "http://buzz.googleapis.com/feeds/".$user."/public/posted";
$data = file_get_contents($url);
$xml = new SimpleXMLElement($data);

$status = $xml->entry[0]->summary;
$time = date('D j M Y g:i a', strtotime($xml->entry[0]->published));
echo "Status: $status <br />";
echo "Time: $time";
Tags: , , ,

Create your own twitter image signature

Many days ago i built two image signature as my forum signature. One of the signature shows the latest post from my blog and another shows my latest twitter update. I was inspired to do that signature by seeing Shiplu Vai’s signature. Originally he was using them and i copied the concept :D

Anyway, here is my latest blog post signature Blog Update Signature and here is my twitter signature Twitter image signature

I will show you the process to create your own twitter image signature like me.

1. At first we will get the latest twitter update by this

<?php
$username = "tareq_cse"; //Twitter Username
$url = "http://twitter.com/statuses/user_timeline/$username.json?count=1"; //json request url
$json = json_decode(file_get_contents($url));
$status = $json[0]->text; //get the status from array/object

2. Now we will get the time distance from now and the twitted time and will format it
Read the rest of this entry »

Sending mail with Gmail’s SMTP server with fsockopen

Today i was trying to find a way to send mail from my localhost (xampp) with Gmails SMTP server. I found some code in popular and also fastest forum engine – punBB.

I got the codes and did some cleanup for working fine as an external script. Here is the codes -

<?php

//this functin processes the server return codes and generates errors if needed
function server_parse($socket, $expected_response)
{
	$server_response = '';
	while (substr($server_response, 3, 1) != ' ')
	{
		if (!($server_response = fgets($socket, 256)))
			echo 'Couldn\'t get mail server response codes. Please contact the forum administrator.', __FILE__, __LINE__;
	}

	if (!(substr($server_response, 0, 3) == $expected_response))
		echo 'Unable to send e-mail. Please contact the forum administrator with the following error message reported by the SMTP server: "'.$server_response.'"', __FILE__, __LINE__;
}

//
// This function was originally a part of the phpBB Group forum software phpBB2 (http://www.phpbb.com).
// They deserve all the credit for writing it. I made small modifications for it to suit PunBB and it's coding standards.
// -------> This message is from punBB developer
//
function smtp_mail($to, $subject, $message, $headers = '')
{
	$recipients = explode(',', $to);
	$user = '<your mail id>';
	$pass = '<your password>';
	$smtp_host = 'ssl://smtp.gmail.com';
	$smtp_port = 465;

	if (!($socket = fsockopen($smtp_host, $smtp_port, $errno, $errstr, 15)))
		echo "Could not connect to smtp host '$smtp_host' ($errno) ($errstr)", __FILE__, __LINE__;

	server_parse($socket, '220');

	fwrite($socket, 'EHLO '.$smtp_host."\r\n");
	server_parse($socket, '250');

	fwrite($socket, 'AUTH LOGIN'."\r\n");
	server_parse($socket, '334');

	fwrite($socket, base64_encode($user)."\r\n");
	server_parse($socket, '334');

	fwrite($socket, base64_encode($pass)."\r\n");
	server_parse($socket, '235');

	fwrite($socket, 'MAIL FROM: <tareq1988@gmail.com>'."\r\n");
	server_parse($socket, '250');

	foreach ($recipients as $email)
	{
		fwrite($socket, 'RCPT TO: <'.$email.'>'."\r\n");
		server_parse($socket, '250');
	}

	fwrite($socket, 'DATA'."\r\n");
	server_parse($socket, '354');

	fwrite($socket, 'Subject: '.$subject."\r\n".'To: <'.implode('>, <', $recipients).'>'."\r\n".$headers."\r\n\r\n".$message."\r\n");

	fwrite($socket, '.'."\r\n");
	server_parse($socket, '250');

	fwrite($socket, 'QUIT'."\r\n");
	fclose($socket);

	return true;
}

// Send the mail
if(smtp_mail('tareq1988@gmail.com', 'Hi! Test Mail', 'This is a test mail from xampp with fsockopen()'))
{
	echo "Mail sent";
}
else
{
	echo "Some error occured";
}
?>
Tags: , , ,

বাংলা তারিখ ভুলে যান? আর ভোলার চান্স নাই

বাংলা তারিখ নিয়ে প্রথমে কাজ করেছিলাম প্রজন্ম ফোরামের জন্যে। সেখানে হেডারে প্রতিদিনের বাংলা তারিখ দেখানো হয়। এরপর করলাম একটা জাভাস্ক্রিপ্ট উইজেট, যেটা দিয়ে আপনি আপনার যেকোন সাইটে বাংলা তারিখ যুক্ত করতে পারেন। অনেকদিন ধরেই চিন্তা করছিলাম ফেসবুকের জন্যে একটা অ্যাপ্লিকেশন বানালে মন্দ হয় না, কিন্তু সময় আর করে উঠতে পারিনি।

ফেসবুকে বাংলা তারিখ

ফেসবুকে বাংলা তারিখ

এই অ্যাপ্লিকেশন দিয়ে আপনি আপনার ফেসবুকের প্রোফাইলে আজকের বাংলা তারিখটি দেখাতে পারবেন। অ্যাপ্লিকেশনটি রয়েছে এখানে http://apps.facebook.com/bangladate/

Google Transliteration plugin for Wordpress & punBB

What is Google Transliterate?

Google offers an automatic transliteration option that converts Roman characters to the characters used in Arabic, Bengali, Gujarati, Hindi, Kannada, Malayalam, Marathi, Nepali, Punjabi, Tamil, Telugu and Urdu. This feature lets you type these languages phonetically in English letters, but they’ll appear in their correct alphabet. Keep in mind that transliteration is different from translation; the sound of the words is converted from one alphabet to the other, not the meaning.

What I did?
I did a integration of Google Transliterate with Wordpress & punBB. My plugin allows you to write phonetically with the help of Google Transliteration in the Wordpress post editor and also in punBB post box. This will not work in rich text editor mode in wordpress, you need to switch on HTML mode.

How does it work?
The bellow images tells you everything

  • You can select your desired language from the list
  • transliterate

  • After Selecting the language, active the google transliteration option by clicking the text.
  • transliterate1

  • Type the words phonetically. Once you type a space or a punctuation mark, the letters will be converted to corresponding language characters, like this:
  • transliterate2transliterate3

  • If you need to correct a transliterated word, click the word; you’ll see a menu of alternate spellings, in addition to an option to switch back to the Roman characters you typed. If you type the same word again, it will then be transliterated correctly based on your saved preference. transliterate4
Download Google Tranliteration for Wordpress (70)
Download Google Tranliteration for punBB (69)

Custom Content Gallery – My first wordpress plugin

Recently I thought to make a wordpress plugin, but was not getting any idea about what to make? I asked Lenin vai for some idea and that was not a bad one :P

I named it, sorry that name was also given by Lenin vai, ha ha ha. It’s name is “Custom Content Gallery”. It’s work is simple, it will just show some latest title and description from some chosen category. You just need to insert the shortcode/keyword

[custom_gallery cat="1, 2, 3"]

. Here “1, 2, 3” is the category ID. So that post/page will show the latest 5 posts from each category. That was a very simple plugin and yeah, it’s size is under 1024 bytes :P

Wordpress Custom Content Gallery

Wordpress Custom Content Gallery

Download punBB 1.3.2 Bangla Language Pack (159)

Image upload & Validation: My first class to phpclasses.org

Recently i had to work with image uploading on my some projects. The issue was to upload the user avatar and rename the avatar’s with their userid. So that it will be easy to work with avatar system.

I first used this idea to one of my project and i did this with procedural method. But again on my current projects i need this facility again. So i thought to finish the job for the last time and decided to make a class to re-use the codes. So here i go…

Firstly, i use my class constructor to define the maximum file size, width, height and also the upload directory. So now create a instance of my class like this-

<?php
//$image = new ImageUloader($max_size, $max_width, $max_height, $upload_dir)
$image = new ImageUploader(26, 200, 150, 'images/avatar/');
?>

Now you need to set the image name to upload. Don’t be afraid, it’s the file input field name of your html form if you have a input file name like this -

<form enctype="multipart/form-data" action="" method="POST">
	<input name="input_field_name" type="file" />
    <input type="submit" name="submit" value="Change Avatar" />
</form>

Then you need to setup the image name like this

<?php
$image->setImage('input_field_name');
?>

Now it’s time for validation process :D
you can check the image size, width, height and also file type by the following method

<?php
$image->checkSize();
$image->checkHeight();
$image->checkWidth();
$image->checkExt();
?>

This method’s return true, if the condition are passed. We have permitted to use only jpg, jped, png and gif files. So lets use them

<?php
if(!$image->checkSize())
	$errors[] = "File size is Big";

if(!$image->checkHeight())
	$errors[] = "File height is Big";

if(!$image->checkWidth())
	$errors[] = "File width is Big";

if(!$image->checkExt())
	$errors[] = "File ext is not supported";
?>

So if the condition are passed, we will set the name of the file to be uploaded and now it’s the time to check if there any file with the same user id. If their is any file with same user id, we delete them for the sake of our need and upload them. By deleting the existing file with same user id clears the confusion of repeating same file name with same user id. Because, their is a possibility to found images with same file name but with different extensions.

<?php
if(!isset($errors)){
		$image->setImageName($userid);
		$image->deleteExisting();
		$image->upload();

		echo "<h2>Avatar Changed Successfully</h2>";
	}
	else{
		echo "<h2>You must correct the errors to proceed</h2><br>";
		print_r($errors);
	}
?>

So here is the complete code for validating and uploading

<?php
if(isset($_POST['submit'])){
	require 'class.imageupload.php';

	//$image = new ImageUloader($max_size, $max_width, $max_height, $upload_dir)
	$image = new ImageUploader(26, 200, 150, 'images/avatar/');
	$image->setImage('input_field_name');

	if(!$image->checkSize())
		$errors[] = "File size is Big";

	if(!$image->checkHeight())
		$errors[] = "File height is Big";

	if(!$image->checkWidth())
		$errors[] = "File width is Big";

	if(!$image->checkExt())
		$errors[] = "File ext is not supported";

	if(!isset($errors)){
		$image->setImageName($userid);
		$image->deleteExisting();
		$image->upload();

		echo "<h2>Avatar Changed Successfully</h2>";
	}
	else{
		echo "<h2>You must correct the errors to proceed</h2><br>";
		print_r($errors);
	}
}
?>

<form enctype="multipart/form-data" action="" method="POST">
	<input name="input_field_name" type="file" />
    <input type="submit" name="submit" value="Change Avatar" />
</form>

Download the class form here

Yahoo! smiles in Pidgin

I didn’t like pidgin for it’s smilies and didn’t use it. I use yahoo messenger and gtalk separately. But later i came to know that i can use yahoo smilies to pidgin. So, i switched to pidgin with my yahoo, gtalk and msn accounts.
Firstly i used yahoo smilies that i found here. But this smilies of yahoo 8.1. But it’s a bit old smilies. So i made a new smiley pack
for pidgin that is used in yahoo 9. I used some code to convert the yahoo smiley code’s to the new theme pack. I parsed the yahoo messenger’s
smiley xml file. That was a chance to purse the xml file and write e new blog post, ha ha ha ha.

I opened my Yahoo’s xml file from here C:\Program Files\Yahoo!\Messenger\Media\Smileys\emoticons.xml

I wrote the code to parse the file and get the file name with it’s corresponding code.

<?php
echo "Name=Yahoo!<br>\n";
echo "Description=Yahoo 9.0 smileys<br>\n";
echo "Icon=4.gif<br>\n";
echo "Author=Tareq Hasan<br>\n";

echo "<br>[default]";

$load = simplexml_load_file('emoticons.xml');
echo "<pre>";

foreach($load->emoticon as $key)
{
echo $key['id'].".gif";
echo "\t";
foreach($key->shortcuts->shortcut as $symbol)
{
echo $symbol." ";
}
echo "<br>";
}
echo "</pre>";
?>

This code generates the following file

Name=Yahoo!
Description=Yahoo 9.0 smileys
Icon=4.gif
Author=Tareq Hasan

[default]

1.gif    :) :-) (-: (:) :)
2.gif    :( :-( :(
3.gif    ;) ;-) ;)
…………….
…………….
113.gif    :-bd
114.gif    ^#(^
115.gif    :bz

—————————————————————————–

Then i copied the *.gif files to a new folder. I copied the text, generated by the code to a file named “theme” with no extension.
Then compressed the folder in tar.gz format. Now it’s ready for a smiley theme package. So easy :D .

Download Yahoo 9 smiley (219)
Tags: , ,

Playing with twitter JSON using PHP

Now twitter is playing a major roll to our day. Many of us is using twitter. Now lets play something with it. Today i will use JSON to play with twitter LOL.

Lets play with our statuses. If you are using twitter, then your status url is http://twitter.com/status/user_timeline/YOUR_USERNAME.json. So if your twitter id is tareq_cse then the url will be http://twitter.com/status/user_timeline/tareq_cse.json. Now i will add a extra parameter here and this is count. This url shows the last 20 status update of yours. So if i need only 5 update then? Then we will add a count variable there. So the url will be http://twitter.com/status/user_timeline/tareq_cse.json?count=5

Now come to the php code.

<?php
$json = file_get_contents("http://twitter.com/status/user_timeline/tareq_cse.json?count=10", true); //getting the file content
$decode = json_decode($json, true); //getting the file content as array

echo "<pre>";
print_r($decode);
echo "</pre>";
?>

Now run the code and see. You will get output like this

Array
(
    [0] => Array
        (
            [text] => is digging wordpress
            [in_reply_to_user_id] =>
            [user] => Array
                (
                    [notifications] =>
                    [time_zone] => Dhaka
                    [description] => A blogger, microblogger and learner
                    [following] =>
                    [utc_offset] => 21600
						...............
						...............
                    [profile_text_color] => 666666
                    [location] => Rajshahi, Bangladesh
                    [id] => 15842888
                    [profile_background_image_url] => http://static.twitter.com/images/themes/theme9/bg.gif
                    [profile_link_color] => 2FC2EF
                )

            [favorited] =>
            [in_reply_to_screen_name] =>
            [truncated] =>
            [created_at] => Sun May 03 20:56:00 +0000 2009
            [id] => 1689697302
            [in_reply_to_status_id] =>
            [source] => TwitterFox
        )
)

Now get some usefull data from this. If we need the last 10 twitter update write the code

<?php
$json = file_get_contents("http://twitter.com/status/user_timeline/tareq_cse.json?count=10", true);
$decode = json_decode($json, true);

echo "<pre>";
$count = count($decode); //counting the number of status
for($i=0;$i<$count;$i++){
echo $decode[$i][text]."<br>";
}
echo "</pre>";
?>

Lets pull some userdata

<?php
$json = file_get_contents("http://twitter.com/status/user_timeline/tareq_cse.json?count=10", true);
$decode = json_decode($json, true);

echo "<img src=\"".$decode[0][user][profile_image_url]."\"</img><br>"; //getting the profile image
echo "Name: ".$decode[0][user][name]."<br>"; //getting the username
echo "Web: ".$decode[0][user][url]."<br>"; //getting the web site address
echo "Location: ".$decode[0][user][location]."<br>"; //user location
echo "Updates: ".$decode[0][user][statuses_count]."<br>"; //number of updates
echo "Follower: ".$decode[0][user][followers_count]."<br>"; //number of followers
echo "Following: ".$decode[0][user][friends_count]."<br>"; // following
echo "Description: ".$decode[0][user][description]."<br>"; //user description
?>

Following this method, you can pull any data by analyzing the first output

Tags: , ,

যে কোন সাইটে দেখান বাংলা তারিখ

আপনারা জানেন, পানবিবির জন্যে আমি বাংলা তারিখের একটা এক্সটেনশন বানিয়েছি। তারপর চিন্তা করলাম যে কোন সাইটে লাগানোর ব্যবস্থা করলে মন্দ হয় না। তাই, সব ওয়েব সাইটে যাতে বাংলা তারিখ দেখানো যায় সেই জন্যে আজ একটা জাভাস্ক্রিপ্ট উইডগেট বানালাম। শুধু যেকোন পাতায় নিচের কোডটুকু পেস্ট করে দিন। ব্যস, আপনার সাইটে বাংলা তারিখ দেখুন।

<script type="text/javascript" src="http://tareq.wedevs.com/bangla_date_widget.php">
</script>

উদাহরণঃ