Wednesday, June 29, 2011

List the available hook in drupal 6?

To view all the available hook function in drupal6, please refer the following link:

Thursday, June 23, 2011

Understanding Drupal Cache mechanism

The Basics
Caches are used to improve the performance of your Drupal site. Rather than extracting the same data over and over again every time a page is loaded, caching stores frequently accessed and relatively static data
in a convenient place and format.
Caching has a drawback in that it can lead to "stale" data. This means that the website outputs old data or content from the cache even though newer stuff exists somewhere else. This problem can be particularly troublesome for developers who can get confused as to why changes they expect to see happen arent. Hopefully, by reading this document, you'll have a more pleasant and less confusing Drupal experience.
What gets cached, where it gets cached, and how There are two different ways Drupal stores cached data:
1) Using files
Drupal can consolidate all the css files your site delivers on each page load and place them into a fewer number of files. The resulting files are also compressed. This is important for Drupal sites where its not unusual to have a dozen or more stylesheets associated with each page, depending on how many modules are enabled. Having so many stylesheets will increase page load times because the browser has to make several round trips to the server to download all the stylesheet files. By using the css caching feature, you can consolidate these files into fewer larger files and decrease page load time significantly.
Just like style sheets, javascript files can also be consolidated. However, these files are not compressed.
How to turn on stylesheet and javascript file caching
======================================================

First, be sure you have your "Download method" is set to "Public" (set at admin/settings/file-system). You will not be able to use stylesheet and javascript caching when your "Download method" is set to "Private."
Next, in the navigation menu, select "Administer -> Site Configuration -> Performance" (admin/settings/performance) and scroll down to the "Bandwidth optimizations" fieldset and check off "Enabled" for both CSS files and Javascript files.
Note that turning on stylesheet and javascript caching can interfere with theme development and should only be enabled in a production environment.
2) In your database
The main location where Drupal stores cached data is in special tables in your database. Drupal core sets up seven tables for caching data. Other modules will add additional cache tables to the database as needed. The seven tables set up by core are:
cache
An "all purpose" table that can be shared by various modules. This table is designed for modules that need to store only a few rows of data. Drupal core uses this table to store the following data:
* Variable data. These are variables that are set with the variable_set() function and retrieved with the variable_get() function. When this cache goes stale, it is refereshed by data from the variable table. A call to the variable_set function will trigger a cache refresh.
* Theme registry data. This registry is a listing of all the themes that can be overridden by theme developers. The existance of the theme registry makes it easy to overide themes by allowing a user to simply
drop a tpl.php file in the theme's directory. When this cache goes stale, it's regenerated from the function definitions contained in module and theme files.
* Schema data. This data contains information about the table structure of the database. When this cache goes stale, its regenerated from ???. A visit to the admin/build/modules page will trigger a cache refresh.
cache_block
A table for storing content generated by your blocks. This saves Drupal from having to repeatedly query the database for unchanged block content. When this cache goes stale, it is refreshed by data from the boxes table where block content is stored. Any update to a blocks content will trigger a cache refresh for that block. The
entire cache is refreshed when a node, comment, user, or taxonomy term is added or updated. Module developers have the option of gaining more control over when a particular blocks cache is refreshed using cache
granularity settings for their blocks. Refer to the constants defined at the top of the block.module for further details.
The block cache can be turned on an off at "Administer -> Site Configuration -> Performance" (admin/settings/performance).
Note that block caching is inactive when modules defining content access restrictions are enabled. For example, if organic groups, content access, taxonomy access modules or other modules that restrict
access to certain kinds of content are turned on, block caching will be turned off.
cache_filter
A table for storing filtered pieces of content. This saves Drupal from having to run the same expensive regular expression operations on unchanged content that gets run through the input filters. When this
cache goes stale, it is refreshed by the data in the node_revisions table which contains node content. Cron jobs, updates to nodes, and updates to filter formats will trigger cache refreshes.
cache_form
A table for storing forms generated by the forms api. This saves Drupal from having to rebuild a unchanged forms. When this cache goes stale, it is refreshed by output from the form module.
cache_menu
A table for storing the menu items and menu item hierarchies. This saves Drupal from having to regenerate the data structures needed to define the menu items and their hiearchies each page load. When the data goes stale, the cache is refreshed from the data contained in the menu table.
cache_page
A table for storing pages for anonymous users. This saves Drupal from making dozens or even hundreds of expensive queries needed to generate a page. When the cache for a particular page goes stale, it gets refreshed by the html output for that page. This cache can be turned on an off under "Administer -> Site Configuration -> Performance" (admin/settings/performance).
cache_update
A table used to store information about installed modules and themes. This saves Drupal from having to perform two very expensive operations for listing the installed modules and themes and the status of these modules and releases compared to whats available for download on drupal.org. When this cache goes stale, it is refresed from the data in the system table.

Wednesday, June 22, 2011

what is the difference between MENU_NORMAL_ITEM and MENU_CALLBACK?

MENU_NORMAL_ITEM generates a menu link which will appear in the navigation menu while MENU_CALLBACK does not add a menu link so it wont appear in the menu

How to get theme image path in javascript?

Inside template.php:

drupal_add_css(array('path_to_images' => base_path() . path_to_theme() .'/images'), 'setting');

Then from your script "Drupal.settings.path_to_images" will point to the right path.

$(".myclass").css(background:'url(' + Drupal.settings.path_to_images + '/myimage.png')');

Monday, June 20, 2011

List the SEO modules available in Drupal.

1. Pathauto
2. Nodewords/ Meta tags
3. Service links
4. Google analytics
5. Related Links
6. Search 404
7. Site map
8. Url list

Friday, June 17, 2011

How to detect user coming from mobile device or desktop device?

The following module will help to identify the user agent with device:

Mobile Tools

Browsecap



The Browscap module provides a replacement for PHP's get_browser() function. get_browser() is difficult (or impossible) to configure for most users in shared webhosting situations, and requires attention to keep the underlying data (browscap.ini) up-to-date. This module avoids the configuration issue by storing the data in a database table, and the freshness issue by automatically retrieving the latest data on a weekly basis (if cron.php is run regularly).

Thursday, June 16, 2011

Whats meant by Action in Drupal?

An action is a function that operates like a stored procedure. The function's parameters, if any, are stored in the database and the function is executed by retrieving these stored parameters and calling the function.


Wednesday, June 15, 2011

How to theme cck individual fields?

Please refer the following link:

node field wieghts

In content type we have title, body and so on,....

The 'Title' field has a default weight of -5 that can't be controlled by CCK. If your content type has a body, the body has a weight of 0. If the content type uses taxonomy, the taxonomy has a weight of -3

Tuesday, June 14, 2011

Theming blocks individually, by region, or by module

Designers can create multiple tpl.php files for blocks based on the specific block, the module that created the block, or the region that the block appears in.

Template files are searched in the following order:

  • block-[module]-[delta].tpl.php
  • block-[module].tpl.php
  • block-[region].tpl.php
  • block.tpl.php

For example, the user login block has a delta of '0'. If you put it in the left sidebar, when it's rendered, PHPTemplate will search for the following templates in descending order:

  • block-user-0.tpl.php
  • block-user.tpl.php
  • block-left.tpl.php
  • block.tpl.php

You can find the block's module and delta by looking at the html source of a page: each block's main DIV has the following classes and IDs:

Note that custom blocks created in the admin UI count as coming from block.module, so their template is 'block-block-[delta]'.

How to create dynamic footer message in drupal

Drupal has a nice feature to input a site wide footer message from the administration panel, it can be found at Administer>>Site configuration>>Site informationn scroll down to Footer message:.

The only thing with this is that it is text only, and what you typically want is to be able to add some dynamic content in there.

To get this value use the following code:

Alternate way:

Just create a block, set the input format to "PHP code" and enter the following code:

© print(date(Y)) ?> print(variable_get('site_name', '')) ?>
All rights reserved

After that you can further customize when and where it will appear, if you need special formatting you can add css classes to it and enhance it's display as needed.

Thursday, June 9, 2011

Css hack for IE6, IE7, IE8

To write the css hack for different version of IE, 

.color {color: #777;} /* for all browsers */
 * html .color {color: #C39;} /* for IE6 */ 
*+html .color {color: #66F;} /* for IE7 */
 .color {color: #0FC\0/;} /* for IE8, going last */

Wednesday, June 8, 2011

How to get the site email address?

We can get the site email address by using the following default drupal variable,

variable_get('site_mail', 'default_address');

This variable will return whatever the email address we have in the drupal admin under siterconfiguraion->site information->E-mail address

Thursday, June 2, 2011

How to assign the content manually to the region?

Content can be manually assigned to regions with drupal_set_content(). For example, drupal_set_content('header', 'Welcome!') would assign the text 'Welcome!' to the header region.

How to remove the “Search this site” label?

The most common answer to this is to use CSS to a do a display: none; which is OK except of course that it doesn’t completely remove it, but rather just hides it. The good thing about using CSS is that’s its quick to implement, but that’s about it.

Modify Drupals Search form using HOOK_theme()

Normal Drupal 6 way:
/**
* Implementation of HOOK_theme().
*/
function MYTHEME_theme(){
return array(
'search_theme_form' => array(
'arguments' => array('form' => NULL),
),
);
}

// The new theme function called by hook_theme
function MYTHEME_search_theme_form($form) {
// hide the label
$form['search_theme_form']['#title'] = NULL;
return
drupal_render($form);
}
?>

Wednesday, June 1, 2011

How to protect critical user?

To Protect the critical user like uid=1 (admin), use Protect Critical Users

This module protects critical users from being deleted in the following ways:

- Catches user/*/delete requests to protect users 0 (anonymous), 1 (admin) and current user.
- Protects user 1 and current user from being deleted from user administration.
- Removes delete button from user edit form for user 1 and current user.

This module will not be upgraded to Drupal 7 because it looks like it will already protect critical users.


Note:Protect Critical Users is not compatible with User Delete module (ref. #507890).

How to protect email address from spam?

Sometimes, you need to enter email adresses in your content. Good examples are your About page, or even your Contact page. But this the better way to get spammed!

It is strongly recommened to install a module such as SpamSan:

  • Download and activate SpamSan module
  • Go to Site configuration > Input formats

For each of your input format do the following:

  • Click on Edit
  • Check that Hide email addresses is enabled and save
  • Click the Rearrange tab and set Hide email adresses with a super high weight (10 for example)
  • Click Save configuration

All email adresses are now spam protected.

Set your front page

By default Drupal front page lists all nodes promoted to front page. We will often want the front page to display something different (a View, a panel, a node, etc.). To do so:

  • Go to Administer > Site configuration > Site Information
  • Set Default front page to the path of your View, Panel, node or anything.
  • Save your settings

Note that the default value for Default front page is node.

Create Page not found (403) page

Create a node (a page content type for example) with some extra information so that your visitors don't ever fall on the default 403 page not found.

Once this node is created:

  • Remember its node ID,
  • Go to Administer > Site configuration > Error reporting
  • Set Default 403 (not found) page to the node ID you just created
  • Save your settings

Disallow odd username

It is recommended that you prevent users from registering on your website with some odd usernames like:

  • root
  • admin
  • administrator
  • webmaster

To prevent this from happening:

  • Go to Administer > User management > Access rules > Add rule
  • Set Access type to Deny
  • Set Rule type to Username
  • In Mask type root
  • Click the Add rule button

Repeat this for every username you don't want to be created on your site

PHP replacement functions in Drupal

When developping a module, we often use some commonly used PHP functions. As you may not know Drupal provides some overrides for these functions. They are often related to strings, they have the same name as their PHP native equivalent except that they are prefixed with drupal_. Here is a list of PHP functions you should replace with its Drupal equivalent:

  • Replace strlen() with drupal_strlen()
  • Replace strtoupper() with drupal_strtoupper()
  • Replace strtolower() with drupal_strtolower()
  • Replace ucfirst() with drupal_ucfirst()
  • Replace substr() with drupal_substr()
  • Replace eval() with drupal_eval()
  • Replace clone with drupal_clone()

How to turns off error reporting display?

  • Go to Site configuration > Error reporting
  • Set Error reporting list box to Write errors to log
  • Save configuration

Stop logins being remembered

By default Drupal will keep people logged in for 23 days (2000000 seconds) by saving a cookie in their browser. This is nice, but a potential security problem if people are using the site from shared computers.

Consider editing the site's settings.php to have

ini_set('session.cookie_lifetime', 0);

instead of the default

ini_set('session.cookie_lifetime', 2000000);

With the former, the user's login will be forgotten when they close their browser window, even if they forget to log out explicitly.