Wednesday, September 12, 2012

CodeIgniter time ago format achieved

I wrote one custom function to achieve this

function display_time($timestamp) {
  $date_array = explode(',', timespan($timestamp, time()));
  $date = $date_array[0] . ' AGO, ';

Monday, July 9, 2012

Facebook PHP SDK logout : resolved

Facebook sdk is creating one cookie in browser.
Which has to be cleared on logout.
Here is my Codeigniter code to do that.

Logout URL
$this->facebook->getLogoutUrl(array('next' => site_url('user/logout'));

Logout Function

 public function logout() {
    setcookie('PHPSESSID', '', time()-3600, "/");
    redirect('/user', 'refresh');

Friday, June 8, 2012

Codeigniter template structure

class Pages extends CI_Controller {

  public function view($page = 'home') {

    if (!file_exists('application/views/pages/' . $page . '.php')) {
      // Whoops, we don't have a page for that!

    $data['title'] = ucfirst($page); // Capitalize the first letter

    $data['header'] = $this->load->view('templates/header', $data, true);
    $data['body'] = $this->load->view('pages/' . $page, $data, true);
    $data['footer'] = $this->load->view('templates/footer', $data, true);

    $this->load->view('templates/page', $data);



And my page.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
    <base href="<?php echo $this->config->item('base_url') ?>public/" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>CONTINUOUS IMPRESSION</title>
    <link href="css/style.css" rel="stylesheet" type="text/css" />

    <div id="container">
      <div class="main-wrapper">

        <div class="header-wrapper">
          <?php echo $header; ?>

        <div class="content-wrapper">

          <div class="content"><?php echo $body; ?></div>

          <div class="footer">
            <?php echo $footer; ?>

Wednesday, June 6, 2012

Taxonomy add edit form simplified for client

I wanted to clean the taxonomy form for our client.

So i created one custom module. and here is my module file code.

function capo_form_alter(&$form, &$form_state, $form_id){
  switch ($form_id) {
    case 'taxonomy_form_term':

      unset ($form['identification']);
      unset ($form['advanced']);


Monday, May 14, 2012

Executing where Condition in phpcasa

When I start learning about Cassandra, first thing in my mind is how to execute traditional where condition. It may be very simple but it took lot of my effort to figure out.

A very basic example is


$pool = new ConnectionPool('Keyspace1', array('localhost'));

$column_family = new ColumnFamily($pool, 'users');

$index_exp = CassandraUtil::create_index_expression('birth_date',1975);
$index_clause = CassandraUtil::create_index_clause(array($index_exp));
$rows = $column_family->get_indexed_slices($index_clause);

foreach($rows as $key => $columns) {

If this code works for you, you are lucky. If not then, you should learn what is Secondary indexes in cassandra. please go What’s new in Cassandra 0.7: Secondary indexes

Friday, May 11, 2012

Decide Drupal or PHP ?

Both technology, has it's own potential, in their area. First I will brief about the both technology, and what is their area.


This is one of the strongest tool built for php developer. It comes with it's own code base(file & folders) and database. Not only that there are 15,993 third party modules(Free), 1,374 Themes(UI). So basically, Drupal is built with all the generic features which almost 70% web applications requires. Features like user accounts, roles, permissions, Admin CRUD, Generic report.


  1. Development becomes very fast, since instead of writing code developer assembles drupal modules. 
  2. Lot of features are already developed, it has a very active community, available for support. 
  3. It is CMS cum Framework, so when require we can write our own custom module also. 


  1. It has its certain core area (codebase & DB), that is not changeable. 
  2. Even though, one can develop custom modules, but it has to follow drupal standard, which ultimately make a boundary for developer. 

When to use drupal 

  1. When we know we are going to build a generic web applications. Where things are straight forward. 
  2. Client requirement are not stiff. Client is ready to accept our suggestions. 
  3. When we need to make process fast. 

When not use drupal

  1. When your requirement may break the drupal core system. 
  2. When client is more cautious about the quality, rather than time or budget 
  3. When you don't have right resource 


PHP, is the Father of Drupal, and Father is always bigger than child :). What ever we can do with drupal, i.e. also available here, with unlimited freedom. This is pretty similar to command line of any operating system(like linux) and it's GUI alternative. 


  1. Here since you start from scratch, you can plan your core DB & code base. From here your freedom starts. 
  2. PHP also has its own very robust, mature community. these people don't write their contribution in a standard module. but they talk and write in some CMS or framework in which they are good. So you get support but nothing like plug n play module. 
  3. As you are free to work in PHP, at the same time if you can google, and find(not guaranteed) something already written, and same(if not exactly then 80% same) as your project would be. 
  4. Resources are easily available. 


  • Compare to drupal, only thing which is lacking here is, some time for small thing. it takes too much time. 

When to go with PHP 

  1. When your application is using multiple technology. 
  2. Client requirement contains lot of exclusive things. Like some client want to set a new trend with their application. Some time they want to beat Facebook, twitter and even google also :). 
  3. When Your client use words, like pixel perfect, it should be in professional way or It's a common web standard, etc. 

When to not go with PHP 

  1. When Client asks suggestion from you, and you know you can mould in your way.
  2. In your application, there is nothing like you invent something from zero.

Other References:

Sunday, April 8, 2012

Drupal Menu

hook_menu() implementations return an associative array whose keys define paths and whose values are an associative array of properties for each path. (The complete list of properties is in the return value section below.)

Friday, March 2, 2012

Get the path to a Drupal module or theme

Suppose you have a image file in your custom module
Best way to take that image is

<img src="<?php echo base_path().drupal_get_path('module', 'module_name');?>/image_name.jpg" />

Saturday, January 21, 2012 makes few events bold, those are running close to you shows few upcoming events in bold.
I guess they are making them bold country wise. So suppose you are from india, all indian event will be bold for you. It helps site user, to filter out events which is useful for them.

Wednesday, January 11, 2012

Drupal custom status message on node submission

Drupal Content types are used for variety of features in a project. So when user submits a form, s/he gets a generic message "your "typename" has been created".

Best way to change these messages, and get a complete control over them is

function hook_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  global $user;
  switch ($op) {
    case "view":
      global $_SESSION;
      if ($_SESSION['messages']['status']) {
          foreach ($_SESSION['messages']['status'] as &$value) {
            if (substr($value, -17) == 'has been created.') {
              switch ($node->type){
                case 'contact_us_website':
                  $value = "Contact Us form has been submitted. We have received your comments - Hawaii Savvy Team";
                case 'report_problem':
                  $value = "Report problem form has been submitted. We have received your comments - Hawaii Savvy Team";
                case 'event':
                  if(!(user_has_role('Administrator') || $user->uid==1))
                  $value = "Your Event has been submitted. We will publish it very soon  - Hawaii Savvy Team";

For other ways look

Monday, January 9, 2012

Blogger is restricting category/tag pages for search-engines

Google webmaster reported me crawl error, that my blog's robots.txt restrict 14 url to crawl by search engines.

Blogger said robots.txt is here which looks like:

User-agent: *
Disallow: /search
Allow: /
So my all tag urls are not indexable.. damn. And google says you can not change your robots.txt

I feel like this is one of the reason, we should not use blogger for high end seo website.

Monday, January 2, 2012

Converting Timestamp into calendar-clock time values

Dupal and other PHP open sources store time as timestamp into database.
So, while working or debugging on such DB tables, one has to convert it into calendar-clock time format (mm/dd/yy- hh:mm:ss). Reason could be anything.

For this, either write your own php code or use this tool

Unix Timestamp Converter

You should know timezone of your web application.

In drupal 6 it is in admin/settings/date-time

Now to get the GMT offset of this timezone one can use

The World Clock

Type the city name in search city field. Go to city page.

Here you can find your timezone's GMT offset.

So, both tools together helps you to undertand your db table time values.