Archive for September, 2011

Contain new line in field when exporting CSV file in php

hi,

It is really strange problem. There is a new line in my address field and when i am adding that value to download in CSV file , all column messed up.

I tried to use nl2br , str_replace , encoding function to find out solution of that mess. But nothing work.

Then I talk with one GURU (Boss 🙂 ) , he told me you need to use ” in place of  ‘  because PHP cant replace new line if it is quoted by single ‘.

I was just surprised,  then i used the function

str_replace(array(“\r\n”, “\n\r”,”\n”,”\r”),” “,$string);

It just work in one sec 🙂

So, I want to share this information to all my PHP developers because many of them might not know so as I . 🙂

 

 

Leave a comment

Set permission to files, folders and subfolders in Shell

Hi,

I  searched google to find out the exact shell command for setting permission to files , folder and all sub folders in one command :

Normally in web Server all folders and sub folders would have 755 permission  Write in your shell.

Command : $ find /var/www -type d -perm 777 -print -exec chmod 755 {} \;

If you want to set all files  permission 644 those have 777 , write in shell:
Command : find /var/www -type f -perm 777 -print -exec chmod 644 {} \;

Ref :http://www.cyberciti.biz/faq/howto-apply-conditional-recursive-chmod-file-permissions/

, ,

Leave a comment

Hook function for email_registration drupal module

Some of the site needs email as sername for their Drupal site. Email Registration module helps to get rid of that problem.
but  it saves username from the email address whatever that is before @.

example : takim.islam@googol.se  save username as : takim.islam

Many people might think , they can update their username from hook_user case ‘Insert’ , but it will not work.
They actually dont need to do anything such that. Because there is already a hook function hook_email_registration_name($edit, $account)
which people can implement from their own module like :

mymodule_email_registration_name($edit, $account)
{

$string = ‘Takim Islam’; // or replace with any value from $account / $edit

return $string;

}

Thats it, your problem is solved!

 

Leave a comment

Translation module for Contact form

I spend lots of time to find out a right way to translate the custom text which is visible on the top of the contact form.

This  custom text we can add from contact setting (admin/build/contact/settings). Then I found out this very helpful module (tContact).

It is very easy to configure and get what you exactly want. Just summarize the tasks you need to follow:

  1.  Download and enable the module
    Add in the setting.php file :  $conf['i18n_variables'][] = 'contact_form_information';
    Go to Add/edit category from : admin/build/contact
    This is important to know , you need to either change your existing categories or Add new category for each  language, otherwise it wont work.
    Final step, go to admin/build/contact/settings , add custom text for each language by switching each language.for example,
    go to English version of your site and custom text, go to Swedish (languages you have in your site) add text for Swedish.
    Now when you will go contact form you will see different custom text in different languages.BINGO 🙂

,

Leave a comment

Nice Jquery tooltip

I worked with many Web project and user interface. Many time, I need some cool jquery tooltip which contains HTML content and
you can change position wherever you want.

This is the sample code and link which will reduce lots of your time to find in internet. Just follow the links.

Details of Tooltip : http://flowplayer.org/tools/demos/tooltip/any-html.html
Configuration of tooptip in jquery function : http://flowplayer.org/tools/tooltip/index.html#configuration

Download right jquery tools  js file from :http://flowplayer.org/tools/download/index.html

 

Hope this is fine enough for developer to understand and use anywhere in their project. It supported almost all major browsers ( Including IE 6 +  🙂 )

 

,

Leave a comment

Multiblock Module

Drupal’s block module is limited by the fact that a block can only have one instance. Each block has a 1:1 relationship with its region, weight, visibility (and other) settings. This means that it is impossible to have blocks in multiple regions or to have blocks that have different settings on different pages.  MultiBlock module solves this problem by allowing you to create multiple Block Instances of already existing blocks.

http://drupal.org/project/multiblock

Leave a comment

Detect frontpage in Drupal module

You can detect whether the current page is frontpage or not by

drupal_is_front_page ()

http://api.drupal.org/api/drupal/includes–path.inc/function/drupal_is_front_page/6

Leave a comment