Drupal SEO (Search Engine Optimization) Modules


, , , , ,

Drupal SEO (Search Engine Optimization) Modules

1. Path – Using Path module, you can set the path for an individual node with the Path module (on the node/add or node edit form) (For More Info http://drupal.org/documentation/modules/path)

2. Pathauto – The Pathauto module automatically generates path aliases for various kinds of content (nodes, categories, users) without requiring the user to manually specify the path alias (For More Info http://drupal.org/project/pathauto)

3. Nodewords/ Meta tags – This Module allows you to add meta tags to Drupal pages, both manually and automatically based on various settings.(For More Info http://drupal.org/project/nodewords)

4. Page Title – This module allows you to set patterns for your Drupal content types (pages, blog posts, stories, articles…). You can also create a unique title for your index page here. (For More Info http://drupal.org/project/page_title)

5. Global Redirect – GlobalRedirect is a simple module which checks the current URL for an alias and does a 301 redirect to it if it is not being used. GlobalRedirect checks the current URL for a trailing slash, removes it if present and repeats check 1 with the new request. GlobalRedirect checks if the current URL is the same as the site_frontpage and redirects to the frontpage if there is a match.(For More info http://drupal.org/project/globalredirect)

6. Path Redirect – This module allows you to specify a redirect from one path to another path or an external URL, using any HTTP redirect status. (For More Info http://drupal.org/project/path_redirect)

7. XML sitemap – The XML sitemap module creates an xml sitemap that you can submit to the search engines.(For Info http://drupal.org/project/xmlsitemap)

8. Service links – Service Links allow the users to submit the contents of your website on social bookmarking sites, blog search engines, social networks and similiar, either add them in the browser, without require external “resources” as other addons do. (For More Info http://drupal.org/project/service_links)

9. Google analytics – This Module Adds the Google Analytics web statistics tracking system to your website. (For More Info http://drupal.org/project/google_analytics)

10. Related Links The related links module enables nodes to display related URLs to the user via blocks. (For More Info http://drupal.org/project/relatedlinks)

11. Search 404 – Instead of showing a standard “404 Page not found”, this module performs a search on the keywords in the URL.(For More Info http://drupal.org/project/search404)

12. Url list – Creates a list of node URLs at /q=urllist.txt or (/urllist.txt for clean URLs) for submitting to search engines (For More Info http://drupal.org/project/urllist)

13. SEO Checklist – This module provides a checklist of recommended Drupal modules and good Drupal SEO (Search Engine Optimization) best practices. (For More Info http://drupal.org/ project/seo_checklist)

JavaScript Password Generator


, , ,

I have written a small piece of code to generate a random password in JavaScript. This function is very good JavaScript Password Generator tool.

JavaScript Password Generator

//JavaScript Password Generator
function generatePassword(passwordLength, specialChars) {
  var iteration = 0;
  var password = "";
  var randomNumber;
  if(specialChars == undefined){
      var specialChars = false;
  while(iteration < passwordLength){
    randomNumber = (Math.floor((Math.random() * 100)) % 94) + 33;
      if ((randomNumber >=33) && (randomNumber <=47)) { continue; }
      if ((randomNumber >=58) && (randomNumber <=64)) { continue; }
      if ((randomNumber >=91) && (randomNumber <=96)) { continue; }
      if ((randomNumber >=123) && (randomNumber <=126)) { continue; }
    password += String.fromCharCode(randomNumber);
  return password;

This function takes two parameters: integer value for password length and optional boolean value true if you want to include special characters in your generated passwords.

How to Use :

// Output : ZMfBhjhM

Core Modules In Drupal


, , , ,

Core Modules In Drupal:

The following is the list of the included Drupal Core modules and which provides the functionality in the installation and configuration processes.

  1. Block — Controls the boxes that are displayed around the main content.(For More Info http://drupal.org/handbook/modules/block)
  2. Filter — Handles the filtering of content in preparation for display. (For More http://drupal.org/handbook/modules/filter)
  3. Node — Allows content to be submitted to the site and displayed on pages. (For More http://drupal.org/handbook/modules/node)
  4. System — Handles general site configuration for administrators. (For More http://drupal.org/handbook/modules/system)
  5. User — Manages the user registration and login system. (For More Info http://drupal.org/handbook/modules/user)

JQuery Tip : Check If JQuery Is Loaded Or Not


, , , ,

To check jQuery is loaded or not we need to check existence of jQuery() / $() function in JavaScript. jQuery() or $() functions will only be defined if they are already loaded into the current document.

So to test if jQuery is loaded or not we can use 2 methods.
Method 1:

// Method 1 to check jQuery is loaded or not
if (jQuery) {
    // jQuery is loaded
} else {
    // jQuery is not loaded

Method 2:

// Method 2 to check jQuery is loaded or not
if (typeof jQuery == 'undefined') {
    // jQuery is not loaded
} else {
    // jQuery is loaded

Reference :

How to convert URLs in string into Links



I want to convert URL in $string into link, that is convert the URL https://avinash6784.wordpress.com to <a href=”https://avinash6784.wordpress.com”>https://avinash6784.wordpress.com</a&gt;. For achive this I have written following helpful PHP code.

Example :

$string = "This is my PHP blog https://avinash6784.wordpress.com";
$output = preg_replace("/(http:\/\/[^\s]+)/", "<a href=\"$1\">$1</a>", $string);
echo $output;

// Output will display – This is my PHP blog <a href=”https://avinash6784.wordpress.com”>https://avinash6784.wordpress.com</a&gt;

Delete Old Files From Directory In PHP


, , ,

I have written a small piece of code for deleting the old files from a directory with the help of filemtime() function. Following piece of code delete the 10 days old files from a root directory. This scripts only delete old files at the root folder not delete files from sub folders. For deleting the sub folders files also we need to modified this script by using recursive function.

Example :

$dir = '/var/www/html/AP/test/';

echo "STARTING<br/>";
if (is_dir($dir)) {
   if ($dh = opendir($dir)) {
      while ($file = readdir($dh)) {
         if(!is_dir($dir.$file)) {
            //if 10 days old, delete
            if (filemtime($dir.$file) < strtotime('-10 days')) { 
               echo "Deleting ".$dir.$file." (old) :";
               echo "(date->".date('Y-m-d',filemtime($dir.$file)).")<br/>";
   } else {
      echo "ERROR. Could not open directory: $dir<br/>";
} else {
   echo "ERROR. Specified path is not a directory: $dir<br/>";
echo "DONE<br/>";

Drupal Website Optimization Tips and Techniques


, , , , , , , ,

Following are the few Tips to optimize and to increase the speed/performance of Drupal based website:

1. Uninstall unneeded modules.

2. Remove unnecessary content.

3. In admin/settings/performance change the Caching Mode to Normal.

4. In admin/settings/performance change “Aggregate and compress CSS files” to Enabled.

5. Install a PHP Accelerator (i.e. eaccelerator, xcache, etc).

6. Analyze database queries. Create indexes for your Drupal database if required. And look for slow queries.

7. Install and configure memcached. Memcached Details can be found here: http://drupal.org/project/memcache

8. Install advanced cache module.

9. Install and Configure QueryCache module. Details can be found here: http://drupal.org/project/querycache

10. Set HTTP headers cache options to optimal values.

How to Calculate a PHP script’s memory usage In PHP


, ,

If you want to know how much memory PHP script uses, then in this case in PHP there is a great in-built function that is memory_get_usage().

memory_get_usage :
memory_get_usage() — Returns the amount of memory allocated to PHP

Description :
int memory_get_usage ([ bool $real_usage = false ] )
Returns the amount of memory, in bytes, that’s currently being allocated to your PHP script.

Parameters :
Set this to TRUE to get the real size of memory allocated from system. If not set or FALSE only the memory used by emalloc() is reported.

Return Values :
Returns the memory amount in bytes.

Example :

// Displays the amount of memory being used as soon as the script runs
echo memory_get_usage() . "<br/>";   // Returns 46552 Bytes

//Your code goes here
$a = str_repeat('Avinash Pawar', 10000);

// Displays the amount of memory being used by your code
echo memory_get_usage() . "<br/>"; // Returns 176636 Bytes

References :

Search And Replace Text From Files In Linux


, , , , , ,

Search & replace a text from a file using perl is very easy.

perl -pi -w -e 's/search/replace/g;' *.php 
  -e means execute the following line of code.
  -i means edit in-place
  -w write warnings
  -p loop

Example :
perl -pi -w -e ‘s/<\/HEAD>/<?php include($_SERVER[DOCUMENT_ROOT].”\/includes\/tips_top.php”);?>\n<\/HEAD>/g;’ *.php

Reference : http://www.liamdelahunty.com/tips/linux_search_and_replace_multiple_files.php