Drupal 7 release party

January 7, 2011 Leave a comment
Categories: Drupal

Happy New Year 2011

January 1, 2011 Leave a comment

Categories: 1

Truncate text using php

March 19, 2010 2 comments
<?php
function truncate($string, $length='' , $k = ''){
	if( $length == '') $length = 50;
	if( $k == '') $k = '...';
    settype($string, 'string');
    settype($length, 'integer');
    for($a = 0; $a < $length AND $a < strlen($string); $a++){
        $output .= $string[$a];
    }
        if( strlen($string) > $length)
	   $output .= $k;
    return($output);
}
?>
truncate text using php
$my_string = 'I am kajal Mondol.I live in Kolkata.';
echo truncate($my_string);
echo truncate($my_string,10);
echo truncate($my_string,10,',,,');

This will output:

 I am kajal Mondol.I live in Kolkata.
 I am kajal... 
 I am kajal,,, 

This function truncates a variable to a character length, default is 50.
‘…’ is the default text to append if truncation occurs.
Second parameter determines how many characters to truncate to.

Drupal 6 Simple Views Slideshow Setup In Aquia Marina

March 17, 2010 Leave a comment
Categories: Drupal

How to Add a Field to Drupal Contact form

March 9, 2010 5 comments

STEP 1 :

First you have to create a module. Create a folder into /sites/all/modules. Give the folder name your module name. Create a module file into the folder. Give the module a name. I have used “contactus.module”. In contactus.module file write the following lines. If you give different module name then the function name should be function yourmodulename_form_alter(&$form, $form_state).

#title    = Title of the input field.

#type     = Type of the input field (e.g. ‘textfield’ or ‘textarea’ etc.  )

#required = If the field is required then value will be true.

Unset function will disable the particular field. Here, in the example I unset copy field. You can re-order all the fields as per need. Just you have to the $ order array. For more information see http://api.drupal.org/api/function/hook_form_alter.


<?php

function contactus_form_alter(&$form, $form_state) {

$form['company'] = array(

'#title' => t('Your company'),

'#type' => 'textfield',

);

$form['phone'] = array(

'#title' => t('Your phone'),

'#type' => 'textfield',

'#required' =>'true',

);

unset($form['copy']);

// reorder the elements in the form to include the elements being inserted

$order = array('name','mail', 'subject', 'company', 'phone','message','submit');

foreach($order as $key => $field) {

$form[$field]['#weight'] = $key;

}

STEP  2: Now you have to create a info file.File name should be your modulename.info . Here I’ve used contactus.info. Into the .info file write the following lines.

name = “contactus”

description = “contact with us”

dependencies[] = contact

core = 6.x

php = 5.1

Categories: Drupal

Function to create GD thumbnail using Php

March 4, 2010 Leave a comment

Like This!

Add to Google Buzz

function thumbnail($src,$destimagename,$dimension)
{
$src_path=explode("/",$src);
$name=$src_path[count($src_path)-1];
array_pop($src_path);
$oldpath=implode("/",$src_path);
$newpath=$oldpath;
$newpath=$newpath."/".$destimagename;

if(copy($src,$newpath))
{
$name_extension=substr($name,strrpos($name,".")+1);
if (preg_match("/gif/i",$name_extension))
{
$src_img=imagecreatefromgif($newpath);
}
if (preg_match("/jpg|jpeg/i",$name_extension))
{
$src_img=imagecreatefromjpeg($newpath);
}
if (preg_match("/png/i",$name_extension))
{
$src_img=imagecreatefrompng($newpath);
}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);

$thumb_w = $dimension;
$thumb_h = floor(($old_y/$old_x) * $dimension);

$dst_img=@ImageCreateTrueColor($thumb_w,$thumb_h);
@imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);

	if(preg_match("/png/i",$name_extension))
	{
	    @imagepng($dst_img,$newpath);
	}
	if(preg_match("/jpg|jpeg/i",$name_extension))
	{
  	@imagejpeg($dst_img,$newpath);
	}
	if(preg_match("/gif/i",$name_extension))
	{

	@imagegif($dst_img,$newpath);
	}
	@imagedestroy($dst_img);
	@imagedestroy($src_img);

}

}
Categories: Php

PHP Headers and Popular Mime Types

March 3, 2010 Leave a comment

Atom

header('Content-type: application/atom+xml');

Javascript

header('Content-type: text/javascript');

JPEG Image

header('Content-type: image/jpeg');

PDF

header('Content-type: application/pdf');

XML

header('Content-type: text/xml');

RSS

header('Content-Type: application/rss+xml; charset=ISO-8859-1');

CSS

header('Content-type: text/css');
Categories: Php