BD Weather: My new facebook app

I have written another facebook app. This simple app using Yahoo Weather API and showing Bangladesh’s different cities weather forecast. In this app I also keep the city selection option so that anyone can select his own city. His selected city’s weather forecast will be shown on his profile and also on the app homepage. If you feel interest you can add this app here.

SMS Sending Gadget for Windows Vista Sidebar

Vista Sidebar Gadgets

Vista Sidebar Gadgets

Some days ago I tried Windows Vista. The first thing I liked is its sidebar. Its transparency and animations also very nice. I was studied the technology behind the sidebar and I found its nothing but a html and an xml file. Yes its that simple. So I tried to make a sidebar for my own. Then I was using Banglalink mobile connection. At that time Banglalink was given 100 free sms for every recharge. I had all free sms and all sms were getting wasted as I feel very annoying to type sms on my mobile and send it to my friends. Then one idea clicked in my mind and think I can build a SMS sending gadget at Vista. It takes me 30 minutes to build this gadget. This gadget has merely a text field to write the recipent’s name and a textarea to write the message and a send button. To build this gadget I used my old is gold Nokia 6650 phone as modem and ActiveXperts SMS and Pager Toolkit v3.2 for SMS sending functionalities. Here I have discussed the steps I did in developing the gadgets. Hope you can find this helpful. Lets first look at the checklist we need to build this gadget:
1. Apache and PHP (that means your localhost)
2. A mobile phone which can be used as a GSM modem with PC connectivity like data cable, infrared or bluetooth with connectivity software (I used my Nokia 6650 with DKU-2 cable with PC Suite).
3. ActiveXperts SMS and Pager Toolkit v3.2

First, Download the ActiveXperts SMS and Pager Toolkit. I have used the ver3.2 of this software. This software is not free. But you can download a one month trial version from here. After downloading the software, install it by taking all default settings. When the software is installing, it will also install some sample applications in different programming languages. You can find these sample applications in the ‘/Samples’ folder of your installation directory. I built this gadget using PHP sample program. You can see the sample application written in PHP. I changed this application to fit my need. You can see my changed php file very shortly. Now copy the php file in your localhost to test and run it.

Then connect your phone to your PC using a datacable or Bluetooth or infrared device whatever your phone supports. I have used my Nokia 6650 phone. Its a very old phone from Nokia having all development tools. Its the first version of phone from when different gorgeous things are started to included with mobile phones like camera, video, bluetooth, infrared, GPRS, Java and so on. I used DKU-2 cable to connect the phone. After a while the PC Suite opens up a small popup window on bottom right corner on system tray saying that ‘Nokia 6650 is connected through USB’. To use your phone please refer to the ActiveXperts website for a list of supported phones. Ok, I left all work for connecting your phone to PC upon you.

After connecting your phone to your PC, run the sample php file from your localhost that you just copied. If everything goes well then you can see a window like this in your browser. In the top drop down box, your phone name will be shown. As here my phone name is shown.

ActiveXperts Test Page

ActiveXperts Test Page

The interface tells you what to do to send a sms from this page. If you are still confused then please read the manual and help file of ActiveXperts SMS and Pager Toolkit. You can found these inside the ‘/Help’ folder of your installation directory. Alternatively you can find this manual from ‘Start->Programs->ActiveXperts Software->SMS and Pager Toolkit’. This help files are very helpful and describes everything you need to run your application using their toolkit.

Now come to the gadget part. Make a new folder at ‘Root Drive:/Program Files/Windows Sidebar’ and name it whatever you want to call to your gadget. If you dont have access to your programe files directory, then you can also create it in your ‘Document and Settings’ folder. Here you can also find a folder named Windows Sidebar. I named it as ‘S16-SMS.Gadget’. Now I have make two files named ‘ajax.html’, ‘gadget.xml’ and a folder named ‘/images’. The html file is the main file which will be shown as gadget on the sidebar and xml file is the manifest file. Before showing you the contents of these files I want to tell you the general scenario. The ajax.html files only contains a form where you will write your sms and the recipents number. When you submit the form it will send a ajax request to your localhost’s php file (remember you copied a php file to your loclhost and tested it???) that will actually send the sms using the ActiveXperts SMS and Pager Toolkit and your attached phone connected to your pc. If sms sent successfully, then it will return a success message otherwise will return an error message. Thats very nice, right? Lets look at ajax.html file:
ajax.html

<html >
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=Unicode” />
<title>Ajax Gadget</title>
<style type=”text/css”>
body
{
margin: 0;
width: 130px;
height: 300px;
font-family: verdana;
font-weight: bold;
font-size: small;
color:#000000;
}

#gadgetContent
{
margin-top: 20px;
width: 130px;
vertical-align: middle;
text-align: center;
overflow: hidden;
}
</style>
<script type=”text/javascript” language=”javascript”>
function init()
{
var oBackground = document.getElementById(“imgBackground”);
oBackground.src = “url(images/background.png)”;
}

var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject()
{
var xmlHttp;

if(window.ActiveXObject)
{
try
{
xmlHttp = new ActiveXObject(“Microsoft.XMLHTTP”);
}
catch(e)
{
xmlHttp = false;
}
}
else
{
try
{
xmlHttp = new XMLHttpRequest();
}
catch (e)
{
xmlHttp = false;
}
}

if(!xmlHttp)
{
alert(“Error creating the XMLHttpRequest object.”);
}
else
{
return xmlHttp;
}
}

function process()
{
if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
{
textRecipient = encodeURIComponent(document.getElementById(“textRecipient”).value);
textMessage = encodeURIComponent(document.getElementById(“textMessage”).value);
textPincode = encodeURIComponent(document.getElementById(“textPincode”).value);

qry_str = “http://192.168.0.14/process1.php?” + “textRecipient=” + textRecipient + “&textMessage=” + textMessage + “&textPincode=” + textPincode;
//alert(textRecipient);

xmlHttp.open(“GET”, qry_str, true);
xmlHttp.onreadystatechange = handleServerResponse;
xmlHttp.send(null);
}
else
{
// if the connection is busy, try again after one second
setTimeout(‘process()’, 1000);
}
}

function handleServerResponse()
{
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
xmlResponse = xmlHttp.responseText;
// obtain the document element (the root element) of the XML structure
//xmlDocumentElement = xmlResponse.documentElement;
// get the text message, which is in the first child of
// the the document element
message = xmlHttp.responseText;
document.getElementById(“div_message”).value = ” + message + ”;
}// a HTTP status different than 200 signals an error
else
{
document.getElementById(“div_message”).value = ” + xmlHttp.statusText + ”;
}
}
else
{
document.getElementById(“div_message”).value = ‘Sending request…’;
}
}
</script>
</head>

<body onLoad=”javascript:init();”>

<g:background id=”imgBackground”>

<span id=”gadgetContent”>
<form name=”frmMessage” id=”frmMessage”>
<input style=”width: 250px” type=”text” name=”textRecipient” id=”textRecipient” value=”[Recipient]” ><br>
<input style=”width: 250px” type=”text” name=”textMessage” id=”textMessage” value=”[Message]” ><br>
<input type=”hidden” name=”textPincode” id=”textPincode” value=”1234″>
<input type=”button” name=”submit” id=”submit” value=”Submit” onClick=”javascript:process();” /></div>
</form>
<input type=”text” name=”div_message” id=”div_message” value=”" />
</span>

</g:background>

</body>
</html>

Here is the xml manifest file

gadget.xml

<?xml version=”1.0″ encoding=”utf-8″ ?>
<gadget>
<name>S16 SMS Application</name>
<version>1.0.0.0</version>
<author name=”Moshfiqur Rahman”>
<info url=”http://moshfiq.wordpress.com” />
</author>
<copyright>© Moshfiqur Rahman.</copyright>
<description>SMS Application for your desktop</description>
<hosts>
<host name=”sidebar”>
<base type=”HTML” apiVersion=”1.0.0″ src=”ajax.html” />
<permissions>Full</permissions>
<platform minPlatformVersion=”1.0″ />
</host>
</hosts>
</gadget>

Now comes the most hard and important part, the process.php file

process.php

if($_GET['textMessage'] != “”){

$objGsmOut->LogFile = $_GET['logfile'];
$objGsmOut->Device = $_GET['device'];
$objGsmOut->DeviceSpeed = $_GET['baudrate'];

$objGsmOut->EnterPin ( $_GET['pin'] );

$objGsmOut->MessageRecipient = $_GET['recipient'];
$objGsmOut->MessageData = $_GET['message'];

if($objGsmOut->LastError == 0)
{
$objGsmOut->Send;
}

$result = $objGsmOut->GetErrorDescription($objGsmOut->LastError);

return $result;
}
?>

Now browse for available sidebar gadgets from the sidebar control panel. You can find your own gadget in the list. Just add it to your sidebar. Now you can send sms to your friend directly from your desktop. Please ensure that your mobile is connected to your pc and your apache server is running. Hope everything is going fine and you can send sms to your friends. If you find something wrong please drop me a line. Enjoy :D

Caution:

  1. I am no using this gadget because my Nokia 5560 phone is out of order :(
  2. Banglalink is no more providing the free sms :(
  3. And finally, I have formatted my hard drive to get rid of windows vista as its near to kill my poor machine with celeron processor and 512 RAM :(

So you are on your own!!! :D

Picasa albums in Lightbox

If you surf the web frequently then you must have heard the name of Google. If you don’t, then do not proceed, because this post may not have any worth to you. Google has many many great services. And among them, Picasa is a nice photo service provided by google. You can upload as many images as you can at picasa. All you need is a google id. Picasa is a free service. You can upload photos in different albums. You can also make you albums private and public.

So, some days ago I was trying to accessing my picasa albums using google picasa web api. I successfully accessed my public albums and see the images in those albums. So I thought to find some ways to make these photos visible by an Lightbox image album created in Javascript. After a day of work, I can successfully see my picasa albums through lighbox. If you want to see your own album, check this link. Next I am thinking to build this up as a widget to add to any website for its user’s personal use.

Strip all non alpha-numeric characters from a string

Last night I was working on a home project. I was trying to build a lightbox photo gallery from picasa image gallery feed using google api. When I trying to get all photo list by album name, then I found that, google strips all non alpha-numeric characters from the album name and capitalize the first character of each words in the album name. For example, I have an album named “Little angels (1)”. But in the album url, google wrote the name as “LittleAngels1″ (http://picasaweb.google.com/<my_user_name>/LittleAngels1). So I need to write a tiny function to take my actual album name and made it url ready as google. Here is the function:

<?php

function stripNonAlphaNumChars($dirtyStr)
{
$string = ucwords($dirtyStr); // capitalize the first characters of each word in the string
$patterns = ‘/[^a-zA-Z0-9]+/’; // reg. exp. for non alphanumeric characters
$replacements = ”; // replaced with empty string
$cleanStr = preg_replace($patterns, $replacements, $string); // return the clean string

return $cleanStr;
}

echo stripNonAlphaNumChars(‘The little angels (1)’);

// the output is: TheLittleAngels1

?>

Very large function huh ?!