Facebook Stream module allows publish functionality

27 06 2009

Now Facebook stream drupal module allows users to publish comments, likes and status messages.  For demo check http://drupal.azrisolutions.com/facebook_stream/

To allow users of your application publish posts,  comments, likes you need to apply for the whitelist. Otherwise, the only Facebook users that can grant your application the publish_stream permission are the developers of your application.





Providing default view with your module.

20 06 2009

Recently we released Twitter Search Feeds module. I wanted to provide default view with this module. To do that I did following steps.

1. Implemeted hook_views_api function like this.
function modulename_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'modulename'),
);
}

2. Exported the view that I wanted to keep in my module and stored the exported content in a file with the name MODULENAME.views.inc like this.

function modulename_views_default_views() {
$views = array();
// Start copy and paste of Export tab output.
// End copy and paste of Export tab output.
// Add view to list of views to provide.
$views[$view->name] = $view;
// ...Repeat all of the above for each view the module should provide.
// At the end, return array of default views.
return $views;
}

That’s it, when enable the module, this view will appear in the views list.

In the first step hook_views_api function is telling that we have a default view which is there in the module path.

In the second step we implemented hook_views_default_view with view structure. This function return the array of views. This method is for the views2/drupal6.

There is a very good article explaining this Speed Up and Version Your Views





Using custom template file in your drupal module

20 06 2009

Recently we released Accordion blocks module in drupal. This module should work with all standard drupal modules, otherwise this module is not useful. So to make it work with all themes, I decided to use my custom block.tpl.php which is there in my module. But by default drupal will load block.tpl.php from your theme. If there is not block.tpl.php in the theme then it will load block.tpl.php from the block module.

I used hook_theme_registry_alter() hook to load block.tpl.php from my module. I wrote my hook like this.

function example_module_theme_registry_alter(&$theme_registry) {
// using our own block.tpl.php file.
$theme_registry['block']['template'] = 'block';
$theme_registry['block']['path'] = drupal_get_path('module', 'example_module');
$theme_registry['block']['type'] = 'module';
$theme_registry['block']['theme path'] = drupal_get_path('module', 'example_module');
$theme_registry['block']['theme paths'] = Array();
}

Now after enabling my module every time block.tpl.php from my module is loading. This way we no need to alter any template file in the theme folder. This method only works for drupal6-7

update1: We can over write the theme function also. To over write theme function write theme registry alter hook like this.

function example_module_theme_registry_alter(&$theme_registry) {
// using our own block.tpl.php file.
$theme_registry['block']['function'] = 'theme_custblock'; // your custom theme function name
$theme_registry['block']['path'] = drupal_get_path('module', 'example_module');
$theme_registry['block']['type'] = 'module';
$theme_registry['block']['theme path'] = drupal_get_path('module', 'example_module');
$theme_registry['block']['theme paths'] = Array();
}





Find current theme regions in drupal

17 06 2009

I am working on a accordion_blocks module. For this module I wanted to enable the accordion effect for the blocks appearing in left and right regions. To do that I need to find our the regions of the theme. To find out the regions I used bellow code in the hook_theme_registry_alter function.

global $theme;
// Populate all block regions.
$regions = system_region_list($theme);

In the template_preprocess_page hook, I directly used $variables['left'], $variables['right']





Accordion Blocks module for drupal released

17 06 2009

We recently released Accordion Blocks module in dupal. This module applies the accordion effect for the blocks appearing left and right side. Just install the dependend modules and this module, the accordion effect will apply to the blocks. We can change the theme of the accordion widget by changing the theme at admin/settings/jquery_ui path. These themes can be downloaded from jquery ui theme roller . This module works with all standard drupal themes.

Demo of the accordion blocks module is avaiable at http://drupal.azrisolutions.com/accordion_blocks_demo





Facebook Live Stream module released on drupal.org

13 06 2009

Finally we got cvs login for the drupal.org to put our module in the drupal contributions section. Now facebook like stream module is available at location http://drupal.org/project/facebook_stream

I got cvs login after 11days of applying for the cvs. It is not so easy to get cvs login. I sent request through the http://drupal.org/cvs-application/requirements link. It is must to follow the instructions specified in the above link. I was talking about this in the #drupal IRC channel. Finally got the cvs login.





Formula to calculate number of hours in google spreadsheet

8 06 2009

I was keeping my timesheet on google spread sheet. I was just mentioning start time and end time of particular task. My project manager asked me to add number of hours as another column.

When I search for the formula I found this link http://www.google.com/support/forum/p/Google+Docs/thread?tid=071c90492bf64b75&hl=en . In that link I found solution to my problem.

I need to keep start time in one column(ex: A4 with value 10:50:00), end time in another column(ex.B4 with value 13:42:00). I should maintain time in 24 hours format. I have another column called Hours(ex. D4 should have 2.9 hours).

The cell value for Hours column should be difference of time from B4 and A4 in terms of hours. So I used =ROUND(ABS(B4-A4) * 24, 1) formula in that cell. I got the exact number of hours I spent. Just drag the column with ‘+’ to affect the same formula for the rest of the cells in the hours column.





Implenting YSlow Best practices part 1

7 06 2009

This week we had a discussion in office about how to reduce the page loading time. YSlow is the best tool to check page performance. Current YSlow uses 22 rules. These points are sorted according to the importance. In those 22 rules we decided to start with first 6 points. YSlow documentation describes very well about 6 points. Lets take a look at these 6 points.

Minimize HTTP requests

Now a days we are using more javascript, css, images, flash for the websites to look very rich, and improve the usability. So we are using more images, javascript. If we load each javascript, image file independently there will be more over head of http request and reponse handling between client and server. More number of http requests causes more time to load the page. We can reduce http requests using following points

  1. Use simple UI design.
  2. Combine all javascript files into single file.
  3. Combine all css files into single file.
  4. Use css sprites

Making Simple UI design may not possible for the rich content site, but with simple design we can reduce the requests of images. How we make all javascript and css files into single file. we can right one simple script which read the javascript files and put it in a single file. This script has to execute every time when u change any javascript file and commit it. So best way is to use some build tools which will run these scripts before you commit or after commit is over. I tried using SCons but later used doit I suggest to use individual javascript files for development, and use combined single file in the production environment.

Use a Content Delivery Network

To implementing geographically dispersed content, no need to redesign the application architecture. As a first step start serving your static files from CDN servers.

Add an Expires or a Cache-Control Header

Browsers will store the information in the cache. For browser to store data in the cache server has to send Cache-Control Header. Keep the expiration time very far like after 10 years, so that browser will keep on loading data from the cache without sending request to server. So that loading time of the page will reduce. But first time when a page is loaded it has to send request to server to get data, from the second time onwards the browser will load from cache.

Here there will be another problem, if we change the css, or javascript the browser has to load the changed file rather than loading the file from cache. To do that the url of the static file should have new query string like http://example.com/staticfile.js?q=wer2323dds3dds. The q value should change when ever file is changed. So the server side code has to handle this.

Gzip Components

Browsers can understand the gzip, deflate format of content. So server can send compressed data using gzip or deflate. By compressing the data we can reduce the size of data upto 70%. To compress the data we no need to do any special things in our code. Just specify Content-Encoding: gzip in your server configuration. Apache 1.3 uses mod_gzip, Apache 2.x uses mod_deflate. You can specify this for nginx or lighthttp servers also like this.

Put Stylesheets at the Top

We need to keep style sheets in the header, because the page can render progressively. When the page is loading progressively, user can see the information without waiting for long time. User did not get pissed off.

Put Scripts at the Bottom

Browser can keep 2 connections open with the same server. So browser can load images, css, html simultaneously. When browser loading javascript it can not open parallel connection with server, so by keeping javascript at the bottom, the browser will load html css and user see the site.In some cases it is not possible to move javascript down when you are using document.write, and is a clue to browsers that they can continue rendering. So it is upto the usage of the javascript





strlen vs mb_strlen function in php

7 06 2009

I wrote a simple class in php called cut html string . This class with cut the html string without considering html tags but the output will have the html tags as it is. Here I used strlen function to find the length of string. This function return the number of bytes of the string. If string has some utf8 special characters then it returns wrong value, because those special characters will take more bytes. I want to find the number of characters in the string. mb_strlen function returns the number of characters in string. A multi-byte character is counted as 1. I prefer to use mb_strlen function to find the character count of a string.








Follow

Get every new post delivered to your Inbox.