Friday, January 20, 2012

PHP Code to remove directory & its files

<?php

function rrmdir($dir) {
  if (is_dir($dir)) {
  if (is_dir($dir)) {
    $objects = scandir($dir);
    foreach ($objects as $object) {
      if ($object != "." && $object != "..") {
        if(filetype($dir."/".$object) == "dir")     rrmdir($dir."/".$object); else unlink($dir."/".$object);
      }
    }
    reset($objects);
    rmdir($dir);
  }
}


?>

Tuesday, January 10, 2012

Theming nodes based on content type in Drupal 7

*The file node.tpl.php is used to theme certain types of nodes.

*This file will be in module/node folder in the root directory.

*To theme individual content types in different ways, you need to create a file node--[type].tpl.php in your theme's folder & copy the content from node.tpl.php to this file, where [type] is the machine readable name of the content type

*only diference between Drupal 6 & Drupal 7 is ,Drupal 7 use two hyphens

node--story.tpl.php
Themes only Story type nodes.

node--forum.tpl.php
Themes only Forum type nodes.

Theming nodes based on content type in Drupal 6

Theming nodes based on content type in drupal 6

*The file node.tpl.php is used to theme certain types of nodes.

*This file will be in module/node folder in the root directory.

*To theme individual content types in different ways, you need to create a file node-[type].tpl.php in your theme's folder & copy the content from node.tpl.php to this file, where [type] is the machine readable name of the content type

node-story.tpl.php
Themes only Story type nodes.

node-forum.tpl.php
Themes only Forum type nodes.

Tuesday, December 27, 2011

Clear cache programmatically in Drupal 7



This will reduce the work by going to performance settings page (admin/settings/performance) & clicking "cleared cached data" by scrolling down

But make sure that this page is only accessed by administrator

For Drupal 7 is same as Drupal 6

<?php
  drupal_flush_all_caches();
  drupal_set_message('cache flushed.');
?>

Clear cache programmatically in Drupal 6


This will reduce the work by going to performance settings page (admin/settings/performance) & clicking "cleared cached data" by scrolling down

But make sure that this page is only accessed by administrator


For Drupal 6 create page with the following code:

<?php
  drupal_flush_all_caches();
  drupal_set_message('cache flushed.');
?>

Clear cache programmatically in Drupal 5



This will reduce the work by going to performance settings page (admin/settings/performance) & clicking "cleared cached data" by scrolling down

But make sure that this page is only accessed by administrator


<?php
// only allow site administrators to visit this page:
if (!user_access('administer site configuration')) {
  drupal_not_found();
}else {
  drupal_clear_css_cache();
  $tables = array('cache','cache_content','cache_filter','cache_menu','cache_page',  'cache_views');
  foreach ($tables as $table) {
    cache_clear_all('*', $table, TRUE);
  }
  drupal_set_message('Cache cleared.');
  drupal_goto();
}
?>