Monday, November 15, 2010

Adding sortable columns to a joomla component

Most of the joomla components have listing of data. And some of them dont have a sorting option in the listing. This tutorial explains that how to add a sortable column in a joomla component. To explain this we are taking the component 'com_profiler'.


The joomla the component 'com_profiler' is very helpful in profile making. It has a user listing in the administrator side. It lists the users list with name, username, groups, email etc. But this section doesnt have a sorting field. Usually you cant sort any fields in 'com_profiler' user list. This section explains how to add a sorting field in the admin section of comprofiler. Now we are going to change the username field in to a 'sorting' field.


Usually the user listing is generated by the comprofiler html page and comprofiler controller page. Path for these pages are as follows.


administrator/components/com_comprofiler/admin.comprofiler.html.php

administrator/components/com_comprofiler/admin.comprofiler.controller.php


Step 1 : Modify the admin.comprofiler.html.php


In admin.comprofiler.html.php there is a function named 'showUsers'. This function generates the list of users. In the showuser function we will add the 'ordering' code



global $mainframe;

$filter_order = $mainframe->getUserStateFromRequest( $option.'filter_order', 'filter_order', 'u.username', 'cmd' );

$filter_order_Dir = $mainframe->getUserStateFromRequest( $option.'filter_order_Dir', 'filter_order_Dir', 'asc','word' );
$lists1['order_Dir'] = $filter_order_Dir;

$lists1['order'] = $filter_order;


So the page will look like as

function showUsers( &$rows, &$pageNav, $search, $option, &$lists, &$pluginColumns ) {

HTML_comprofiler::secureAboveForm('showUsers');

// table ordering

global $mainframe;

$filter_order = $mainframe->getUserStateFromRequest( $option.'filter_order', 'filter_order', 'u.username', 'cmd' );

$filter_order_Dir = $mainframe->getUserStateFromRequest( $option.'filter_order_Dir', 'filter_order_Dir', 'u.username','word' );
$lists1['order_Dir'] = $filter_order_Dir;

$lists1['order'] = $filter_order;

outputCbTemplate( 2 );

outputCbJs( 2 );


Step 2 : Setting the Order Link

After that we can set the sorting link to the username field. Place the following code instead of the 'Usernmae' Title.


<?php echo JHTML::_( 'grid.sort', 'UserName', 'u.username', $lists1['order_Dir'], $lists1['order']); ?>

So the code will look like as follows.


<th width="15%" class="title"><?php echo CBTxt::T('Name'); ?></th>

<th width="10%" class="title">

<?php echo JHTML::_( 'grid.sort', 'UserName', 'u.username', $lists1['order_Dir'], $lists1['order']); ?></th>

<th width="5%" class="title" nowrap="nowrap"><?php echo CBTxt::T('Logged In'); ?></th>

Step 3 : Add the Hidden Fields


Also add the hidden fields to post the sorting field and sorting direction to the controller page. Add the following code before the end of the form


<input type="hidden" name="filter_order" value="<?php echo $lists1['order']; ?>" />

<input type="hidden" name="filter_order_Dir" value="<?php echo $lists1['order_Dir']; ?>" />

now the code will look like as follows.


<input type="hidden" name="option" value="<?php echo $option;?>" />

<input type="hidden" name="task" value="showusers" />

<input type="hidden" name="boxchecked" value="0" />

<input type="hidden" name="filter_order" value="<?php echo $lists1['order']; ?>" />

<input type="hidden" name="filter_order_Dir" value="<?php echo $lists1['order_Dir']; ?>" />
<?php

echo cbGetSpoofInputTag( 'user' );

?>

</form>

Step 4 : Modify the controller code (admin.comprofiler.controller.php)


The controller grabs the data from the database.


So we need to modify the function to list based on the order.


The controller contains a function named 'showUsers'.Edit the function to get the post values submitted from the listng page. Use the post method to assign the values. After placing the code the function will look like as


function showUsers( $option ) {

global $_CB_database, $_CB_framework, $_POST, $_PLUGINS, $_CB_TxtIntStore;

if(isset($_POST['filter_order']))

     $filter_order = $_POST['filter_order'];

else

     $filter_order = "u.username";



if(isset($_POST['filter_order_Dir']))

      $filter_order_Dir = $_POST['filter_order_Dir'];

else

     $filter_order_Dir = "asc";

Also modify the search query to get the ordered data.Add the ' ORDER BY' clause in the search query. After adding the ' ORDER BY ' clause the code will look like as the follow.


$query = "SELECT DISTINCT u.*, g.name AS groupname, ue.approved, ue.confirmed"

. $queryFrom

. " ORDER BY $filter_order $filter_order_Dir "

. "\n LIMIT " . (int) $pageNav->limitstart . ", " . (int) $pageNav->limit

;

That's all. Now in the user listing of the admin panel we have the 'user name ' filed as link. Now we can list the data's either in ascending order or by descending order.

Wednesday, November 10, 2010

Twitter Application development


What is twitter


Twitter is a status-updating or microblogging social networking website. It is a breakthrough in social networking because it takes communication into another level. Before, a person can only update his status (e.g. what he's doing, where he is) at a certain time. But with Twitter and its mobile integration, he can update his status almost all throughout the day and get in touch with people that matters to him the most.



But the functions of Twitter do not stop there. It is now used by various fields. Business, for example, has used Twitter to get in touch with customers on a personal level. It is also a nice place to meet people from different parts of the world that shares the same interests. Furthermore, its possibilities to promote new technology, news and products can't be denied.

Twitter have been used by companies, bloggers and agencies to promote their brand


Advantages and disadvantages of using Twitter for Internet Marketing


Advantages of twitter


Your Internet marketing can be done free of cost if you use Twitter wisely. Your target market is out there for you to seek and understand. Understand from their tweets, their passion and interests. Do your research on your target market by following the tweets of your target market for better understanding. Identify the strategies used by your competitors by following their tweets as well.

Twitter allows you to network efficiently and with large groups of people. Twitter and its third party applications allow you to segregate and interact with your target markets effectively. You can direct your Internet marketing campaigns at relevant groups efficiently by using Twitter

Twitter allows you to communicate directly with your target market instantly. Normally, the process of communication takes time. For example, if you have a Website, the communication would be via polls, which are not personal or though contact forms which are time consuming and impersonal as well. With twitter, you can expect instant communication with your target market. You may have just posted a tweet, but a reply from your target market could come in an instant as well. Twitter helps you to gather real time intelligence from your very own target market as well as obtain valuable feedback. The speed of communication is just fantastic with Twitter. Moreover, your near approach helps to builds lasting relationship as you will come cross as a company that cares for its consumers instead of just hard selling.


Disadvantages of twitter


Twitter is the number one site for spammers. You will have to filter and weed out spammers from your lists from time to time, if you want to have a good gauge of your target market. Otherwise, the followers total will be an inflated number which will not help in your Internet marketing campaigns. Filtering spam tweets is a lot of hard work. Other means of Internet marketing may seem feasible in the long run.



Twitter has no applications rather than other sites like Facebook, Friendster and MySpace. It also has no groups, videos, blogs, classified ads, forums, marketplace and other unique and popular social networking menus. You can only upload one picture, which is your avatar and must be small, compare to other social networks which you can upload pictures as many as you want. You also cannot upload music files here on Twitter, but you can upload on the other social networks.


What does twitter do for businesses?


Twitter is a communication platform that helps businesses stay connected to their customers. As a business, you can use it to quickly share information with people interested in your company, gather real-time market intelligence and feedback, and build relationships with customers, partners and other people who care about your company. As an individual user, you can use Twitter to tell a company (or anyone else) that you've had a great—or disappointing—experience with their business, offer product ideas, and learn about great offers.

How does it work?


Twitter lets you write and read messages of up to 140 characters, or the very length of this sentence, including all punctuation and spaces. The messages are public and you decide what sort of messages you want to receive—Twitter being a recipient driven information network. In addition, you can send and receive Twitter messages, or tweets, equally well from your desktop or your mobile phone.

When you combine messages that are quick to write, easy to read, public, controlled by the recipient and exchangeable anywhere, you’ve got a powerful, real-time way to communicate. And real-time communication is turning out to be ground-breaking for users and businesses alike.


How do businesses use Twitter?


Twitter connects you to your customers right now, in a way that was never before possible. For example, let’s say you work for a custom bike company. If you run a search for your brand, you may find people posting messages about how happy they are riding your bikes in the French Alps—giving you a chance to share tips about cyclist-friendly cafes along their route.

Others may post minor equipment complaints or desired features that they would never bother to contact you about—providing you with invaluable customer feedback that you can respond to right away or use for future planning. Still others may twitter about serious problems with your bikes—letting you offer customer service that can turn around a bad situation.

You don’t have to run a bike shop or a relatively small company to get good stuff out of Twitter. Businesses of all kinds, including major brands, increasingly find that listening and engaging on the service leads to happier customers, passionate advocates, key product improvements and, in many cases, more sales.


A key benefit


One of Twitter’s key benefits is that it gives you the chance to communicate casually with customers on their terms, creating friendly relationships along the way—tough for corporations to do in most other mediums.

But Twitter isn’t just about useful immediacy. The conversational nature of the medium lets you build relationships with customers, partners and other people important to your business. Beyond transactions, Twitter gives your constituents direct access to employees and a way to contribute to your company; as marketers say, it shrinks the emotional distance between your company and your customers. Plus, the platform lends itself to integration with your existing communication channels and strategies. In combination, those factors can make Twitter a critical piece of your company’s bigger digital footprint.

For instance, let’s say you run a big retail website. In addition to learning more about what your customers want, you can provide exclusive Twitter coupon codes, link to key posts on your blog, share tips for shopping online, and announce specials at store locations. And you can take things a step further by occasionally posting messages about fun, quirky events at your HQ, giving others a small but valuable connection with the people in your company.

Tip: Companies sometimes worry that twittering might require a lot of staff time or even hiring new people to maintain an account. In fact, Twitter works best for businesses when you start slow, devoting a few minutes a day to see whether and how it’s valuable to you.


Twitter Application development


We need to use the Twitter API and Twitter Content to develop a Service to search, display, analyze, retrieve, view, and submit information to or on Twitter


Twitter API


http://dev.twitter.com/pages/api_overview

Face book Application Development

Facebook is one of the fastest growing social networking websites and is quickly becoming a powerful and cost effective portal, ideal for organizations to create that ‘brand connection’ in the Web2.0 world.

http://www.facebook.com


What are Facebook applications?


Facebook applications are the software programs that allow users to connect, interact and entertain themselves and their ‘friends’.

Most Facebook users today use 3rd party Facebook applications to add some fun and personality to their Facebook profile. Their purpose is to generate content that the user finds is relevant or of interest to them.

There is virtually an application for everything, ranging from a Facebook application that reminds a user when their favorite band is coming to town to a slide show of a collection of sentimental photos. The great thing about Facebook applications is that if it is to be added to a profile, the users listed as a individual’s ‘friends’ are sent an option of also using it. The application then circulates at such a rapid rate exposure is viral.


Now a day’s most company’s developing facebook applications like gaming, interactive interfaces to promote their products etc.

http://www.facebook.com/apps/directory.php


Many site are integrated their facebook features into their sites

http://developers.facebook.com/showcase/


Facebook Application Development


We can create an application completely focused on our business brand. Think of a travel application that links to booking information on our website or a product catalogue of our latest products. All applications are designed to generate maximum interest on our business and draw continual international traffic to our website.

http://developers.facebook.com/


How to create a Facebook  Application


To create an application we need to register our application with facebook. Also we need to install the facebook developer kit.  Using the facebook application we can access information about the facebook profile even the non public information. For example if a facebook user register with our site , we can use facebook login for registering. If the user login with facebook we can collect the public information of the user including the emailid. So no need to confirm the email again, because it Is already confirmed by facebook. Also we can collect address, phone no, gender etc.


Tutorials to develop a Facebook application

http://developers.facebook.com/


Scope of facebook social plug-in   


A reader on your site, who is logged into her Facebook account, can now give your story a “Thumbs up” by simply clicking this Like button. She will also have to option to publish a snippet of your blog story on to her Facebook profile.

Then you have the Activity widget that shows in near real-time how people are interacting with your stories. If the user is logged into Facebook, the activity widget will show the activity of her friends on your web site else it’ll show everyone’s activity.

However, the most exciting social plug in for Facebook in the new recommendations engine. It shows a list of most popular stories on your blog as determined by the count of Facebook users who have “liked” that story.


To get started, we need to add our domain name to Facebook.


http://www.facebook.com/insights/


We basically need to verify that we are the actual owner of the domain and we can do this by simply adding a unique HTML META tag to our blog header.

Facebook will check the tag in our blog and once it’s verified, we can link the reports to either our Facebook profile or any Facebook page, if we own one.

Once everything is in place, we can revisit the Facebook Insights page to get detailed sharing stats of our blog pages. It will even tell us the top countries / cities of users who are interacting with our stories including the demographics.


If you have a forum or a blog site that requires registration, you may also explore the Sign-on widget that will let user registers on your site using their Facebook ID

This new tools from makes it possible for websites to allow you to connect with your friends and their likings. It helps you get first hand views and reviews from friends about the new movie which is the talk of the town, or the menu in any restaurant or the latest news. Not that it doesn’t allow strangers to give their feedback but it makes it possible for your friends to stand prominently.


The plugins makes it possible to show your action in the following ways you can either ‘like’ content, or you can ‘recommend’ such contents.  This makes it possible for you to connect with any content that you like publicly.


Alternately the tool also helps to remove or ‘unlike’ any new content or previously liked content. Another possible way is through the activity feed. This lets you know what your friends are doing with their likes and recommendations while visiting a particularly popular website.


Social plugins

All social plugins are extensions of Facebook and are specifically designed so none of our data is shared with the sites on which they appear.

We can add these plugins into our site by adding a group of code into our website.


Facebook  Plugins


1: Like Button


The Like button lets a user share your content with friends on Facebook. When the user clicks the Like button on your site, a story appears in the user's friends' News Feed with a link back to your website.


http://developers.facebook.com/docs/reference/plugins/like


2: Activity Feed


The Activity Feed plugin displays the most interesting recent activity taking place on your site. Since the content is hosted by Facebook, the plugin can display personalized content whether or not the user has logged into your site. The activity feed displays stories both when users like content on your site and when users share content from your site back to Facebook.


http://developers.facebook.com/docs/reference/plugins/activity


3: Comments


The Comments Box easily enables your users to comment on your site's content — whether it's for a web page, article, photo, or other piece of content. Then the user can share the comment on Facebook on their Wall and in their friends' streams.


http://developers.facebook.com/docs/reference/plugins/comments


Sample code

<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=APP_ID&amp;xfbml=1"></script><fb:comments xid="1234" width="425"></fb:comments>


4: Facepile


The Facepile plugin shows the Face book profile pictures of the user's friends who have already signed up for your site.

You can specify the maximum number of rows of profile pictures to display. The plugin dynamically sizes its height; for example, if you specify a maximum of four rows, and there are only enough friends to fill two rows, the height of the plugin will be only what is needed for two rows of profile pictures. The plugin doesn't render if the user is logged out of Facebook or doesn't have friends who have signed up for your site using Facebook.


Sample code

<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=APP_ID&amp;xfbml=1"></script><fb:facepile max-rows="5" width="600"></fb:facepile>


http://developers.facebook.com/docs/reference/plugins/facepile


5: Like Box


The Like Box is a social plugin that enables Facebook Page owners to attract and gain Likes from their own website. The Like Box enables users to:



  • See how many users already like this page, and which of their friends like it too

  • Read recent posts from the page

  • Like the page with one click, without needing to visit the page


http://developers.facebook.com/docs/reference/plugins/like-box


6: Live Stream


The Live Stream plugin lets users visiting your site or application share activity and comments in real time. Live Stream works best when you are running a real-time event, like live streaming video for concerts, speeches, or webcasts, live Web chats, webinars, massively multiplayer games.


http://developers.facebook.com/docs/reference/plugins/live-stream


7: Login Button


The Login Button shows profile pictures of the user's friends who have already signed up for your site in addition to a login button.

You can specify the maximum number of rows of faces to display. The plugin dynamically sizes its height; for example, if you specify a maximum of four rows of faces, and there are only enough friends to fill two rows, the height of the plugin will be only what is needed for two rows of faces.


http://developers.facebook.com/docs/reference/plugins/login


8: Recommendations


The Recommendations plugin shows personalized recommendations to your users. Since the content is hosted by Facebook, the plugin can display personalized recommendations whether or not the user has logged into your site. To generate the recommendations, the plugin considers all the social interactions with URLs from your site. For a logged in Facebook user, the plugin will give preference to and highlight objects her friends have interacted with.


http://developers.facebook.com/docs/reference/plugins/recommendations

Replace a string in the mysql database using REPLACE function

Many times we have the need to change the values of database fields. If our table contains thousands of records, its not possible to manually edit the records. So we can use MySQL REPLACE function to replace the string. The syntax to use the replace function is as follows.


UPDATE `table_name` SET `field_name` = REPLACE(`field_name`, 'Keyword to be replaced', 'Replacement String');

For example if we have changed the website name , we also need to change the datas in the downloads table (if we have).


Now we can use a single sql query with REPLACE function , and it will affect the whole records.


UPDATE `tbl_downloads` SET `sitename` = REPLACE(`sitename`, 'www.old-sitename.com', 'www.new-sitename.com');

now all the datas with 'old-sitename' will replace with the new-sitename

Romove the title from the vimeo video.

Usually we are using iframe to embedd a vimeo video.

It similar as the follow.


<iframe src="http://player.vimeo.com/video/123456789" width="400" height="300" frameborder="0"></iframe><p><a href="http://vimeo.com/123456789">Video Title</a> from <a href="http://vimeo.com/user123456">vimeo user</a> on <a href="http://vimeo.com">Vimeo</a>.</p>

While embedding with the iframe code the video title also with the video


If we want to remove the title and video owner name from the vimeo video , we can use embedd code .


The code will similar as the follow.



<object width="400" height="300"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=123456789&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portr ait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=123456789&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portr ait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object><p><a href="http://vimeo.com/123456789">Video Title</a> from <a href="http://vimeo.com/user123456">vimeo user</a> on <a href="http://vimeo.com">Vimeo</a>.</p>

Monday, September 27, 2010

How to check upload file extension using JavaScript ?

The following is a simple JavaScript function to check the extension of an uploading file.
It will help to avoid checking the file extension in server, if the JavaScript is enabled in the browser.

We use a form for file uploading. The form is similar as follows.
<form name="a">
<input type="file" name="shw_image" id="shw_image" onchange="validateFileExtension(this.value)"/>
<input type="hidden" name="tmp_img" id="tmp_img" value="" />
</form>
Next using the JavaScript function we can find out the file extension. We are calling this function in the onchange event of the file filed.
The JavaScript function is as follows.
function validateFileExtension(fld)
{

document.getElementById("tmp_img").value= fld;
var ext = fld;
ext = ext.substring(ext.length-3,ext.length);
ext = ext.toLowerCase();
if((ext != 'jpg')&&(ext != 'gif')&&(ext != 'png')&&(ext != 'jpeg'))
{
alert('You selected a .'+ ext + ' file; \n please select a .jpg/.gif/.png/.jpeg image file');
document.frm.product_image.focus();
document.frm.product_image.value="";
document.getElementById("tmp_img").value="";
return false;
}
}
This function alerts a message if we select a file with the extension other than jpg, gif, png and jpeg.

Tuesday, August 17, 2010

PHP Parser to extract Filezilla FTP details

The following is a PHP program to extract FTP usernames and passwords from the filezilla xml file.
First export the filezilla FTP details using the export option in the filezilla
File - > Export

Save this file as 'FileZilla.xml'

Assign the xml file path to the variable and reun the program. It will list the ftp details . Add or change the xml_key variable to get the other details of FTP details.

Source Code
<?php
$xml_file = "FileZilla.xml";
$xml_host_key = "*FILEZILLA3*SERVERS*SERVER*HOST";
$xml_port_key = "*FILEZILLA3*SERVERS*SERVER*PORT";
$xml_user_key = "*FILEZILLA3*SERVERS*SERVER*USER";
$xml_pass_key = "*FILEZILLA3*SERVERS*SERVER*PASS";
$xml_name_key = "*FILEZILLA3*SERVERS*SERVER*NAME";
$story_array = array();
$counter = 0;
class xml_story{
var $host, $port,$user,$pass;
}
function startTag($parser, $data){
global $current_tag;
$current_tag .= "*$data";
}
function endTag($parser, $data){
global $current_tag;
$tag_key = strrpos($current_tag, '*');
$current_tag = substr($current_tag, 0, $tag_key);
}
function contents($parser, $data){
global $current_tag, $xml_host_key, $xml_port_key, $counter, $story_array,$xml_user_key,$xml_pass_key,$xml_name_key;
switch($current_tag){
case $xml_host_key:
$story_array[$counter] = new xml_story();
$story_array[$counter]->host = $data;
break;
case $xml_port_key:

$story_array[$counter]->port = $data;
//$counter++;
break;
case $xml_user_key:

$story_array[$counter]->user = $data;
// $counter++;
break;
case $xml_pass_key:

$story_array[$counter]->pass = $data;
// $counter++;
break;
case $xml_name_key:

$story_array[$counter]->name = $data;
$counter++;
break;

}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "contents");
$fp = fopen($xml_file, "r") or die("Could not open file");
$data = fread($fp, filesize($xml_file)) or die("Could not read file");
if(!(xml_parse($xml_parser, $data, feof($fp)))){
die("Error on line " . xml_get_current_line_number($xml_parser));
}
xml_parser_free($xml_parser);
fclose($fp);
?>
<html>
<head>
<title>Filezilla Parser</title>
</head>
<body bgcolor="#FFFFFF">
<table width="1001" border="1">
<tr>
<td width="47"><strong>NO</strong></td>
<td width="185"><strong>Name</strong></td>
<td width="229"><strong>Host</strong></td>
<td width="221"><strong>User Name</strong></td>
<td width="125"><strong>Password</strong></td>
<td width="154"><strong>Port</strong></td>
</tr>
<?php
for($x=0;$x<count($story_array);$x++){
?>

<tr>
<td height="38"><?=$x++?></td>
<td><?=$story_array[$x]->name?></td>
<td><?=$story_array[$x]->host?></td>
<td><?=$story_array[$x]->user?></td>
<td><?=$story_array[$x]->pass?></td>
<td><?=$story_array[$x]->port?></td>
</tr>
<?php
}
?>
</table>
</body>
</html>

It will list the FTP host ,FTP username , FTP password and port etc.