Showing posts with label DRUPAL. Show all posts
Showing posts with label DRUPAL. Show all posts

Friday, February 18, 2011

Customizing the Search form - Drupal


To change the label text and text inside the search box and the text on the submit and changing the Submit button image, you can use the following function to do the customizations. You have to add this code in template.php file.

function mytheme_preprocess_search_theme_form(&$vars, $hook) {
// Change the "Search this site" label from the form.
$vars['form']['search_theme_form']['#title'] = t('googling');

// Set a default value for text inside the search box field.
$vars['form']['search_theme_form']['#value'] = t('Find it ..');

// Add a custom class and placeholder text to the search box.
$vars['form']['search_theme_form']['#attributes'] = array('class' => 'NormalTextBox txtSearch', 'onblur' => "if (this.value == '') {this.value = '".$vars['form']['search_theme_form']['#value']."';} ;", 'onfocus' => "if (this.value == '".$vars['form']['search_theme_form']['#value']."') {this.value = '';} ;" );

// Change the text on the submit button
//$vars['form']['submit']['#value'] = t('Go');

// Rebuild the rendered version (search form only, rest remains unchanged)
unset($vars['form']['search_theme_form']['#printed']);
$vars['search']['search_theme_form'] = drupal_render($vars['form']['search_theme_form']);

$vars['form']['submit']['#type'] = 'image_button';
$vars['form']['submit']['#src'] = path_to_theme() . '/images/search.gif';

// Rebuild the rendered version (submit button, rest remains unchanged)
unset($vars['form']['submit']['#printed']);
$vars['search']['submit'] = drupal_render($vars['form']['submit']);

// Collect all form elements to make it easier to print the whole form.
$vars['search_form'] = implode($vars['search']);
}

Wednesday, February 16, 2011

Dfont module - Drupal

The Dfont module is very useful. This module is very useful in cases like when the Client needs the Site in particular font which is also a rare font which wont be available in most of the Users machine, so in that case only the default font will get called this is where the issue raises. In this case few options available are,
  •  We can add the fonts as images, but you cant add every text as Images then the site will be very slow.
  •  Another thing is embedding flash which is also not a good option.
  •  Compartively the Dfont module option is Good. You need to add that font to the server, from there the font will get called, the user's machine doesnt need to have that Font. Therefore every user can view the site in Client requested Font.

Steps for installing this module,
  •  Enable the module asusual.
  •  After enabling, go to the dfont settings page (admin/settings/dfont), there also the instructions will be available.
  •  The Next step is you have to Upload the .ttf and .eot files, for each font, to directory sites/default/files/fonts.
  •  Then Scroll down and click Generate font styles.
  •  Then Enable dynamic font filter in admin/settings/filters and Refresh this page to ensure your fonts are rendered below.

You can download the fonts from http://www.tti-us.com/uvn/p_buyscript.htm. Also to convert the fonts to .eot format, you can use this link to do that http://www.kirsle.net/wizards/ttf2eot.cgi.

Then you have to add some Css properties for including the font family, size etc ...
Ex:
h1, h2, h3, h4, h5, h6 {
   font-family: UVNDamCuoi_H;
}

"UVNDamCuoi_H" is the Font name (which I have used). So after including this, automatically all the header tags (h1,h2 etc ..) will be displayed in the "UVNDamCuoi_H" font. You can also use the default options like [dfont=df1m],[dfont=df1l],[dfont=df1x] in the dfont settings page for various presets.

Tuesday, February 15, 2011

Floating Blocks - Drupal

The Floating block module allows you to keep html blocks or contents, selected using jquery selectors in a fixed position on the page as you scroll.  This means that when a user scrolls the browser, some parts of the site can be maintained in the user's view by fixing their position.

Install the module asusual.
Go to the Floating block admin settings page (admin/settings/floating_block), there you will find a Textarea where you can enter the CSS classes or Id's of the blocks which needs to be floating.

Examples :
#block-chatroom-0
#search
#myarea

It has to be entered one by one as above, as you can see the first and second Css Id's are drupal blocks from contributed modules while the third one is customely added DIV by me, which means it also works for the Custom DIV's or regions not only the Drupal Blocks.

Friday, February 11, 2011

Drupal - Module hooks invoke procedure


How does all the hooks inside all the modules (custom & contributed) gets invoked and executed,

module_implements() - this is the function which Determine which modules are implementing a hook.

function module_implements($hook, $sort = FALSE, $refresh = FALSE) {
  static $implementations;

  if ($refresh) {
    $implementations = array();
    return;
  }

  if (!isset($implementations[$hook])) {
    $implementations[$hook] = array();
    $list = module_list(FALSE, TRUE, $sort);
    foreach ($list as $module) {
      if (module_hook($module, $hook)) {
        $implementations[$hook][] = $module;
      }
    }
  }


In this function it will call the module_list() function which returns all the enabled modules, further on which module_hook() function is called which checks whether the module uses that hook function

function module_hook($module, $hook) {
  return function_exists($module .'_'. $hook);
}

Tuesday, February 8, 2011

Perfomance tunings for Drupal Websites


Steps to follow to increase the site's performance,

Install a PHP script cache - eAccelerator

Turn on MySQL query caching

Turn on Drupal page caching

Compress your content

combine your CSS using Css aggregator

Combine your JS using js aggregator

Y-slow can be used for checking the performance.

For more information, visit the following link

http://nadeausoftware.com/articles/2007/01/essential_performance_tuning_drupal_web_sites

Tuesday, January 11, 2011

Autosave - Drupal module

The Autosave module automatically saves a snapshot of your content type form using AJAX. If the user's browser or machine dies while editing a node; the edits will be presented to the user the next time they return to the node. The user may toggle back and forth between the last saved version and the version with the edits that were lost and select which of these they would like to continue with.

This is a very useful module in situations like when your machine is corrupted before saving your article or news in these situations this module will have the backup of your content.

Database tweaks - Drupal module

This module allow you to enable and change following settings in database:

- SQL_BIG_SELECTS
- MAX_JOIN_SIZE
- MAX_ALLOWED_PACKET
- WAIT_TIMEOUT

and changing SQL_MODES.

This module is very useful in situations like, when the DB is overloaded with too many fields in CCK or very big queries (cache queries) it will throw "mysql gone away" error in drupal. This is actually a common error in these situations. The Fix is we need to increase the Packet size in my.cnf or my.ini file in Mysql folder. But in situations like if in Live sites where we don't have access to these files "my.cnf" if the error comes it will be difficult to handle in those situations you can use this module.
You can find the module at : http://drupal.org/project/db_tweaks

Drupal for Firebug - Drupal module

Drupal for Firebug module:

This module is a helper module for a customized Firefox plugin that displays Drupal debugging and SQL query information. Very Useful module, to checkout the node contents you don't need to put node_load or some functions like this module will load and display all the Node properties and Values through Firebug.

You can find the module at : http://drupal.org/project/drupalforfirebug.

Tuesday, March 3, 2009

Taxonomy Functions

Avoid queries to display the content which are associated with a particular taxonomy term or vocabulary.
Try Using the taxonomy related functions like ,
1. taxonomy_get_children
-- Find all children of a term ID.
2. taxonomy_get_parents
-- Find all parents of a given term ID.
3. taxonomy_get_parents_all
-- Find all ancestors of a given term ID.
4. taxonomy_get_related
-- Find all term objects related to a given term ID.
5. taxonomy_get_term
-- Return the term object matching a term ID.
6. taxonomy_get_term_by_name
-- Try to map a string to an existing term, as for glossary use.
7. taxonomy_get_tree
-- Create a hierarchical representation of a vocabulary.
8. taxonomy_node_get_terms
-- Find all terms associated with the given node, ordered by vocabulary and term weight.

Customizing the Search form - Drupal

To change the label text and text inside the search box and the text on the submit and changing the Submit button image, you can use the fo...