Translate Digits/numbers in Drupal 6.x

Hi, first of all, it’s an old tutorial, I don’t use Drupal 6.x any more. Anyway, below goes the procedures.

WARNING: This is done hacking core Drupal files, so be careful when you update Drupal core. All changes might be lost.

Edit file ‘DRUPAL_INSTALL_DIR/includes/common.inc

Add following code snippet at the end of t($string, $args = array(), $langcode = NULL) function:

if($langcode == 'bn'){
return bengaliDigit(strtr($string, $args));
 }else{
return strtr($string, $args);
 }

And define following function somewhere in the page:

function bengaliDigit($numb){
// Credits: Hasan Raihan
$latin = array('1','2','3','4','5','6','7','8','9','0');
$bengali = array('১','২','৩','৪','৫','৬','৭','৮','৯','০',);
return str_replace($latin, $bengali, $numb);
 }

Here, I’m assuming I’m translating English (en) digits to Bengali (bn) Digits.

Advertisements

Update Drupal Modules using FTP in localhost

When you’re going to update Drupal 7 modules using FTP, you need to have a FTP server running in your computer. In Ubuntu/Linux, we can have one named vsftpd (Very secured FTP Daemon) by running following command in the terminal:

Configuration:

Drupal: 7.0+

OS: Ubuntu/Linux

Step 1: Install VSFTPD

sudo apt-get install vsftpd

Step 2: Have an FTP account

Next, we need to add your Ubuntu user account to the FTP group. You can do it either by:

Open Users & Groups > Manage Groups. Double-click on FTP. Put tick-mark on your user-account, and click OK.

In the screenshot above, I’ve added my user account “giga” to the FTP group. So, I can use my username “giga” and my account’s password to run FTP.

3. Configure VSFTPD

Run in terminal:

gksudo gedit /etc/vsftpd.conf

Make sure you have following lines in the configuration file. Also check that they’re not preceeded by a “#”:

listen=YES
local_enable=YES
write_enable=YES
local_umask=022

Save and close the editor. Now we restart vsftpd by the following command:

sudo /etc/init.d/vsftpd restart

Step 4: Own your Drupal site

Run following command to own all of your Drupal scripts.

chown -R your-username /path-to-drupal

Finally…

Yes, we’re done. 🙂 Use your username (“giga” in this example) and system password to connect to FTP while upgrading modules.

 

 

Running many sites on single Drupal installation

Yup, you may call it “multisite installation”. That means, you may run more than one site with only a single Drupal core.

Configurations:

Drupal 7.0+

Linux Machine

Step 1: Create a new virtual host

To run multiple sites, we need to create Virtual Hosts in our machine. For example, If I type http://mydrupal I’ll be taken to my drupal site. For that, first we need to change ‘/etc/hosts’ file. Run following command in terminal and provide root password when promted:

gksudo gedit /etc/hosts

Next, add following line to the file and save the file:

127.0.0.4    mydrupal

Step 2: Restart networking interface

Type in terminal:

sudo /etc/init.d/networking restart

Step 3: Configure Apache2

For the easiest way, go the directory /etc/apache2/sites-enabled. Here, you will see a file named something like 000-default (or whatever), open it for editing. Place following code for opening it for editing:

gksudo gedit /etc/apache2/sites-enabled/000-default

Now, you need to create a <VirtualHost> directive:

<VirtualHost 127.0.0.4:80>
    ServerAdmin [your@email.com]

    DocumentRoot /path-to-your-drupal/

    ServerName mydrupal

    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory /path-to-your-drupal/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

    RewriteEngine On
    RewriteOptions inherit

</VirtualHost>

Note that <VirtualHost 127.0.0.4:80> should contain the IP address you provided in step 1, we chose “127.0.0.4” since it will be pointing to your own machine. Also, note the line ServerName mydrupal – here “mydrupal” is the name we chose in step 1.

Step 4: Restart Apache2

Type in terminal:

sudo /etc/init.d/apache2 restart

Yup, that’s all!

Finally…

Type http://mydrupal in your browser, you will see the new drupal site running! Now you can create all the necessary files (database settings, modules, themes etc.) under sites folder of your Drupal path. Copy the path-to-drupal/sites/default folder and rename it to path-to-drupal/sites/mydrupal.

Next, you can (should):

  • Edit “path-to-drupal/sites/mydrupal/settings.php” – for database settings. Change database username, password, database name etc.
  • Create a new database if necessary, using PHPMyAdmin, or whatever.

Using a View to diplay a single node/content in Drupal 7

Using the View module you can display nodes of any content-types.  Usually, in a “Page” type view you can display many contents/nodes, with pagination support. But what to display only a specific node? perhaps, using an url like http://yoursite.com/viewname/10 where 10 is the Node-ID (nid)

You can achieve this using Contextual Filters. In this example, I’m assuming you want to display a single node of ‘Article’ content type.

1. First, create the View generally, simply in the way you’d create a view for displaying paged Articles. Next, like the image below, Click on Advanced > (Contextual Filters) add.

 

2. In the new window, type “nid” in Search text-field, select Nid as shown in the image below:

3. Look at the image below carefully, and apply all the changes marked.

4. Click on Apply. Contextual filter window will close.

5. Finally, on the main view page, click on Use Pager: Full under PAGER section (see image below).

6. On the new window, select “Display a specified number of items” and click Apply.

7. Type 1 in the “Items per page” text-field. Click Apply. The dialogue window will close.

That’s all. Hit Save on the main page.

Run Python script as CGI program with Apache2 in Linux / Wamp in Windows

If you’ve Apache & Python installed, you can execute your python scripts as CGI programs, which your visitors can access if you host the scripts in a server. You can write your scripts in python (file-name will end with .py) or in perl (extention .pl) or anything else which is compatible.

Step 1 – Write a “Hello, World! ” script in Python

In a text editor, type following code. Give the file name “first.py

#!/usr/bin/env python
print "Content-type: text/html\n"

print "Hello, world!"

The first line is important – it tells where in our computer Python is available. If you’re using windows, use appropriate location, for example, change the first line to something like:

#!C:/Python27/python.exe

Step 2 – Put the script in a suitable directory

Important: If you are in Linux, make your file executable! Type:

chmod +x /path/to/your/first.py

Pretty simple!

  1. Let’s rename the file to first.py and make it executable, if we’re in Linux.
  2. Put it in a directory named “cgi-bin” under our document root. Then, the file may be accessed in the web-browser by simply typing: http://localhost/cgi-bin/first.py

Step 3 – Configure Apache2

Next step is to configure Apache so that it treats our file as a CGI program. Go to the directory where your Apache configuration file exists. In Linux, it resides under /etc/apache2/ and the configuration file is httpd.conf

NOTE: If virtual hosts are enabled (normally the are enabled), changing the httpd.conf will have no effect. You may need to edit particular configuration file for the site which is enabled. Go to the sites-enabled  directory and open the file which is currently enabled (If you have only the file “default” in your /etc/apache2/sites-enabled directory, you should open this file with your text editor)

NOTE: If you are in windows, and using Wamp, you can simply open the httpd.conf file and make following changes.

Edit the configuration file:

Search for the line: ScriptAlias /cgi-bin/ /whatever-path/ – when you find it, comment out the line: that is add a # in front of the line:

#ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

Then,  paste following lines of code:

<Directory "/location/to/your/cgi-bin/">
AddHandler cgi-script .cgi .py
AllowOverride All
Options +Indexes FollowSymLinks +ExecCGI
Order allow,deny
Allow from all
</Directory>

If your first.py is in /var/www/cgi-bin/ folder, then replace the first line by <Directory “/var/www/cgi-bin”>

You’re done! Now restart Apache to activate all changes.

If you’re in Linux, open a terminal and enter sudo /etc/init.d/apache2 reload to restart Apache. If you’re using Wamp in Windows, you can restart Apache clicking appropriate icons!

 

Test…

 

Fire up your web browser, type http://localhost/cgi-bin/first.py and hit Enter…

 

If you find only the text:

Hello, world!

in the page, then congratulations!

If you find any other text than Hello, world!, something went wrong. Check for your mistakes. Ensure that “cgi_module” Apache module is enabled.

 

You may find this link helpful.

PostgreSQL with PHP in Ubuntu: Step-by-Step How To!

This document is for latest version of PostgreSQL: 8.4, but it should work in any newer versions, as long as you change the commands appropriately, replacing the version mentioned with correct version 🙂

Installation

Install PostgreSQL:

sudo apt-get install postgresql

Install GUI Administration application:

sudo apt-get install pgadmin3

Install PHP based Web Administration site (like phpMyAdmin for MySQL database):

sudo apt-get install phppgadmin

I found this helpful, because it installed all dependant packages required to access postGRE database from PHP 😉

Configuration

Configure so that you can access via localhost:

gksudo gedit /etc/postgresql/8.4/main/postgresql.conf 

It witll open the file for editing, Add following line at the end of the file:

listen_addresses = 'localhost'

Save and close the file. Open another file for editing:

gksuso gedit /etc/postgresql/8.4/main/pg_hba.conf

Replace “local all all ident sameuser” with:

local   all         all                               md5

Change Password for root user

In PostGRE, root user is “postgres” which by default, does not have any password. Enter following line in terminal to set a password for it:

sudo -u postgres psql template1
ALTER USER postgres with encrypted password 'your_password';
\q

Create a new User & a new Database

sudo -u postgres createuser -d -R -P new_username
sudo -u postgres createdb -O new_username new_database_name

This will create a new user, with username “new_username” and create a new database “new_database_name” and set “new_username” it’s owner.

Configure phpPgAdmin

I assume you already installed phpPgAdmin by:

sudo apt-get install phppgadmin

Then, configure Apache:

gksudo gedit /etc/apache2/apache2.conf

Add following line at the end of the file:

Include /etc/phppgadmin/apache.conf

All done! Restart to reflect changes…

sudo /etc/init.d/apache2 restart
sudo /etc/init.d/postgresql-8.4 restart

Access phpPgAdmin

type http://localhost/phppgadmin in your browser & log in by the username you just created (new_username)

Use GUI Administration application

Run following command in terminal:

pgadmin3

Access from Terminal:

psql

References

https://help.ubuntu.com/8.04/serverguide/C/postgresql.html

http://solyaris.wordpress.com/2008/08/09/setup-postgres-in-ubuntu/

https://help.ubuntu.com/community/phpPgAdmin

Preview Image in Current Page on Click with preload effect – jQuery

Live Demonstration!

This jQuery script is based on Mukesh Chapagain’s script. It allows you to show your images on current page without redirecting them to their file locations. When you click the thumbnail on an image, the screen turns black (semitransparent) with animation effect, and a LOADER appears. The loader continues to animate until the image is loaded completely. When loaded completely, the image is shown in the middle of the page. Cool, huh? 😉 I’m sure you want this script!

I worked on Mukesh’s script and made quite a lot of changes, i.e added image loader, stopped scrolling of the page while image is being shown etc. Most of all, I eased the usage. You just need to include the javascript on your page & bingo! You’re done 😀

Download:

1. Download jQuery (Rename to jquery.js)

2. Download Image Preview Script (Rename to ipgb.js)

3. Download the loader image (loading.gif)

Usage:

Put following Code before </Head> tag of your page.

<script src = 'jquery.js'></script>
<script src = 'ipgb.js'></script>

Put all your images in a div, and make that div’s class “thumbnail”. Details:

<div class="thumbnail">
	        <a href="hills.jpg"><img src="hills-thumb.jpg"  /></a>
		<a href="lilies.jpg"><img src="lilies-thumb.jpg"  /></a>
		<a href="sunset.jpg"><img src="sunset-thumb.jpg"  /></a>
		<a href="winter.jpg"><img src="winter-thumb.jpg" /></a>
</div>

Watch the code above carefully! You should put your images as link. You provide original imae in the href attribute of <a> tag, and put thumbnail location in the src attribute in the <img> tag inside it.

Happy Coding!

Download from mirror site

Download Zip