Generate ordinal, easy way in PHP

by umarzaffer August 29, 2009

After going through lot of custom funtions for generating ordinal number in PHP, I was finally able to find the best way (so far) for doing it.

$num = 32;
$temp_num = ($num>31)?($num%31)+1:$num;
print $num.date('S', mktime(0,0,0,$temp_num,0,0));

Necessity for using mod function at second line is because date function only considers valid number range from 1 to 31 for day parameter and using mod function this way keeps it in this range and does the trick. You will need to pass the number that you want to show as ordinal as 4th parameter to mktime function.

Hope this saves time.


Comments (View)

Multisite Drupal Install Using Single Database

by umarzaffer May 19, 2009

This post is in continuation to Multisite Installation In Drupal 6.

In the previous post mentioned above, we were using separate databases for each site within the same drupal core. There will be requirements where you will be required to have a single database to be shared among multiple drupal site installs. One important requirement being sharing of user access. It will be quite possible that multiple sites setup on same drupal core will want to share the user base. Also, it will be important that user login sessions be shared among those multiple sub sites. Under these circumstances, you will be required to have a single database with some of the tables (if not all) to be shared among the sub sites.

Below are the steps to do that assuming you have one sub site configured like http://example.com/subsite1/ using database ‘example_db’, and you create another sub site like http://example.com/subsite2/ to use same database. Just before running install.php for subsite2 make below mentioned changes to /subsite2/settings.php file by setting $db_prefix as an array like below

# /subsite2/settings.php
$db_url = 'mysql://user:pwd@localhost/example_db';

$db_prefix = array(
     'default'   => 'subsite2_',
     'users'     => '',
     'sessions'  => '',
     'authmap'   => '',
);
# By setting $db_prefix array like above, we are prefixing every other table with 'subsite2' except for 'users', 'sessions' and 'authmap' tables thereby marking them as shared.

The other way of doing the same thing will be to specify non shared tables like

# /subsite2/settings.php
$db_url = 'mysql://user:pwd@localhost/example_db';

$db_prefix = array(
     'default'   => '',
     'users'     => 'subsite2_',
     'sessions'  => 'subsite2_',
     'authmap'   => 'subsite2_',
);
# By setting $db_prefix array like above, we are sharing every table between 'subsite1' and 'subsite2' except for 'users', 'sessions' and 'authmap' tables.

Now, you should be ready to run install on subsite2.

Nutshell: The only important point for using a single database between multiple drupal sites with some or none shared tables is the ability to specify shared/non shared tables which is as simple as specifying list of tables within $db_prefix as key/value pairs.

Note: if you want to have single database to be used between multiple drupal sites with no tables shared, just specify table prefix as

$db_prefix = 'subsite2_';

Comments (View)

Multisite installation in drupal 6

by umarzaffer May 14, 2009

Assuming you have basic drupal 6 installation already working on a LAMP server. Below are the steps to setup multiple sites to work on same drupal core like site1.com, site2.com etc.

Create site databases

Start by creating databases for each site like site1, site2 etc thereby setting specific credentials to each database created.

Setup drupal site configuration directories

Copy and paste /sites/default directory and rename the copied directories to /sites/site1.com, /sites/site2.com directories. The only important file from the /sites/default directory being settings.php, you can skip all the other files/directories while copying /sites/default directory. Although, later on you might need to create several different directories within each site directory like files, modules, themes etc contents of whom will be specific to that site. Edit settings.php file of each site and set database details specific to each site.

Create virtual hosts for each site under Apache2

Steps for creating virtual hosts under debian/ubuntu based systems. Open terminal use below commands

$ cd /etc/apache2/sites-available
$ sudo gedit site1.com
Put below contents within this file
<VirtualHost 127.0.1.5:80>
ServerAdmin webmaster@localhost
ServerName site1.com

DocumentRoot /home/umar/Work/htdocs/drupal6
<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>
<Directory /home/umar/Work/htdocs/drupal6>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>
 </VirtualHost>

$ sudo a2ensite site1.com

Repeat the above steps for all sites with unique local IP’s for each site. When done with creation of all files reload apache

$ /etc/init.d/apache2 reload

Now edit the /etc/hosts file to include mapping of these new sites like $ sudo gedit /etc/hosts With contents like 127.0.0.1 localhost 127.0.1.5 site1.com 127.0.1.6 site2.com

Thats all there is to it, now go to url like http://site1.com/install.php of each site and follow normal drupal installation procedure.


I will soon be posting article showing usage of single DB between multiple drupal sites configuration.

Cheers


Comments (View)
by mirnazim March 16, 2009

Comments (View)
by mirnazim March 12, 2009
Today, due to sudden rush of adrenaline and energy powered by lots of caffeine, I decided to sit down and redesigned our web site ikraftsoft.com, which I have been intending of doing for quite some time now, but procrastinating for one reason or the other. And I am quite satisfied with the result.

I know already that when my team will see the new design, I will have to answer a thousand questions, especially from Irfan(THE CEO). To avoid lot of discussions about my design decisions, I will try to defend my design designs right before they are attacked.

DISCLAIMER: Although, I have always wanted to be a skilled designer, but I am not. I cannot use image manipulation programs for anything more than basic editing like croping, scaling and some retouching of images. So please do not expect any miracles.

Design Goals

Let me first start by describing what I wanted to accomplish and what my goals were.


DON&#8217;T WASTE ANYONE&#8217;S TIME; HIGHLIGHT THE POINT
This was the most important thing, that I wanted to reflect in the final design. Basically, what I wanted to accomplish is(or should be) what a company&#8217;s website is expected to accomplish. &#8216;Provide the necessary information about a company with as less text  as possible&#8217;. I wanted that as soon as a visitor is on our website, what we do should jump on to visitor&#8217;s eyes immediately, preferably without reading each and every written word.
Right from the start, I knew exactly, towards what I wanted to draw the attention of visitors of my site. That is why I made certain things very prominent. Like the main banner that says &#8220;we are passionate about web &amp; we enjoy creating great web applications&#8221;.  This one sentence speaks of our heart. In this one sentence, I tried to make a statement about our passion as a company and what we enjoy.
Secondly, you will notice that words DRUPAL and DJANGO  strongly highlighted. Now, when a new visitor comes to our website he immediately knows that we are doing something with Drupal &amp; Django. And if the visitor is someone who is looking for hiring the Drupal or Django devs, BINGO! We have made ourselves know immediately.
CLEAN IS COOL
Another thing that I wanted is cleanliness and readability. I strongly hold the opinion that cool photoshop/gimp techniques are not the only way to spice up your website. Unfortunately, most of the designers give a second seat to the typography, which should be the primary concern for the designer. Graphics and images should be made to compliment the typography, not the other way round.
That is the reason, I choose a text heavy design, with only two images, one for the logo and other for the arrows for list styles.  I user the font stacks that I talked about in my blog post about my favourite font-stacks
PROVIDE AN EXPLICIT EXIT LOCATION
Now that we have made clear what we do, provide exit locations to the visitors form where they can find more information about us. For that reason, Link to our blog and the email is provided. Address, phone number etc are provided in the footer.

Although, I have layout out my rationale behind design decisions, there is still a room for some unanswered questions. I will try to answer few of those questions and end this looooong post after that.

Why did not I put up a work portfolio?
I definitely will do that, it just I could not envision best way to do so right. So, I decided to give myself a bit of time to think about it and discuss it with my team. May be we will simply publish a portfolio page that describe our major projects. Personally, I am bordering on the idea of having portfolio related posts(properly tagged) in our blog and linking to that page from the main site. But right now, this is an open ended problem.

Why are Django and Drupal not defined?
Let first clarify how we get work.


More that 70% of our work comes from client referrals and not from website. One client referring us to another, who in turn refers us to another client.
Almost all of our clients are techies who understand the technology very well and have come to us with very specific needs and most of them are already aware of Drupal/Django and related technologies.

So, we do not need to say anything about drupal and/or django. Even if some visitor is not aware of drupal/django, both have been duly linked to their respective websites as those sites do a much better job of defining themselves. Visitor can go there and get enlightened.

Why pages like vision/mission/about missing
I wanted people to know about us in the simplest and most concise way. I could not think of better words than &#8220;we develop web apps using drupal and django&#8221;  Rest of the answer has already been explained in previous paras.

That was brief of the rationale behind my design decisions. I would love to hear more from you and my team. Let&#8217;s take the discussion forward from this point.

Today, due to sudden rush of adrenaline and energy powered by lots of caffeine, I decided to sit down and redesigned our web site ikraftsoft.com, which I have been intending of doing for quite some time now, but procrastinating for one reason or the other. And I am quite satisfied with the result.

I know already that when my team will see the new design, I will have to answer a thousand questions, especially from Irfan(THE CEO). To avoid lot of discussions about my design decisions, I will try to defend my design designs right before they are attacked.

DISCLAIMER: Although, I have always wanted to be a skilled designer, but I am not. I cannot use image manipulation programs for anything more than basic editing like croping, scaling and some retouching of images. So please do not expect any miracles.

Design Goals

Let me first start by describing what I wanted to accomplish and what my goals were.

  1. DON’T WASTE ANYONE’S TIME; HIGHLIGHT THE POINT
    This was the most important thing, that I wanted to reflect in the final design. Basically, what I wanted to accomplish is(or should be) what a company’s website is expected to accomplish. ‘Provide the necessary information about a company with as less text as possible’. I wanted that as soon as a visitor is on our website, what we do should jump on to visitor’s eyes immediately, preferably without reading each and every written word.
    Right from the start, I knew exactly, towards what I wanted to draw the attention of visitors of my site. That is why I made certain things very prominent. Like the main banner that says “we are passionate about web & we enjoy creating great web applications”. This one sentence speaks of our heart. In this one sentence, I tried to make a statement about our passion as a company and what we enjoy.
    Secondly, you will notice that words DRUPAL and DJANGO strongly highlighted. Now, when a new visitor comes to our website he immediately knows that we are doing something with Drupal & Django. And if the visitor is someone who is looking for hiring the Drupal or Django devs, BINGO! We have made ourselves know immediately.

  2. CLEAN IS COOL
    Another thing that I wanted is cleanliness and readability. I strongly hold the opinion that cool photoshop/gimp techniques are not the only way to spice up your website. Unfortunately, most of the designers give a second seat to the typography, which should be the primary concern for the designer. Graphics and images should be made to compliment the typography, not the other way round. That is the reason, I choose a text heavy design, with only two images, one for the logo and other for the arrows for list styles. I user the font stacks that I talked about in my blog post about my favourite font-stacks

  3. PROVIDE AN EXPLICIT EXIT LOCATION
    Now that we have made clear what we do, provide exit locations to the visitors form where they can find more information about us. For that reason, Link to our blog and the email is provided. Address, phone number etc are provided in the footer.

Although, I have layout out my rationale behind design decisions, there is still a room for some unanswered questions. I will try to answer few of those questions and end this looooong post after that.

Why did not I put up a work portfolio?
I definitely will do that, it just I could not envision best way to do so right. So, I decided to give myself a bit of time to think about it and discuss it with my team. May be we will simply publish a portfolio page that describe our major projects. Personally, I am bordering on the idea of having portfolio related posts(properly tagged) in our blog and linking to that page from the main site. But right now, this is an open ended problem.

Why are Django and Drupal not defined?
Let first clarify how we get work.

  • More that 70% of our work comes from client referrals and not from website. One client referring us to another, who in turn refers us to another client.

  • Almost all of our clients are techies who understand the technology very well and have come to us with very specific needs and most of them are already aware of Drupal/Django and related technologies.

So, we do not need to say anything about drupal and/or django. Even if some visitor is not aware of drupal/django, both have been duly linked to their respective websites as those sites do a much better job of defining themselves. Visitor can go there and get enlightened.

Why pages like vision/mission/about missing
I wanted people to know about us in the simplest and most concise way. I could not think of better words than “we develop web apps using drupal and django” Rest of the answer has already been explained in previous paras.

That was brief of the rationale behind my design decisions. I would love to hear more from you and my team. Let’s take the discussion forward from this point.


Comments (View)
by mirnazim March 11, 2009

It seems like IE’s successor has been confimed to be “Gazelle”, a browser currently under development at Microsoft Research. It is said to be more secure than FireFox and Chrome; keeping plug-in’s sandboxed within the browser, so it will not affect the PC if you stumble upon some malwar


Comments (View)
by mirnazim March 11, 2009

Comments (View)
by mirnazim March 11, 2009

Comments (View)
by mirnazim March 11, 2009

DHH aka David Heinmeier Hansson(yes I intend what I wrote), as most people know him as the creator of Ruby on Rails framework, is often thought of as an arrogant brat and a guy who blurts out FU at a slights provocation(and sometimes, even without provocation). At least that is what I thought of him until I read this post.

Thanks Peter for showing us real DHH(if it is true).


Comments (View)
by mirnazim March 11, 2009
We are having a Barcamp Kashmir on March 14th, 2009. YIPEEEEEEEEEEEE!

iKraft started Barcamps in Kashmir when we had first Barcamp in Feb 2008. We are among the main organisers this time as well. We are also sponsoring the part of the event expenditure. Thanks to other sponsors as well.

We would love to have your presence there. Do come and take a look at the great stuff we Kashmiris are doing despite countless number of problems.

Visit Barcamp Kashmir event site and subscribe to the mailing list

We are having a Barcamp Kashmir on March 14th, 2009. YIPEEEEEEEEEEEE!

iKraft started Barcamps in Kashmir when we had first Barcamp in Feb 2008. We are among the main organisers this time as well. We are also sponsoring the part of the event expenditure. Thanks to other sponsors as well.

We would love to have your presence there. Do come and take a look at the great stuff we Kashmiris are doing despite countless number of problems.

Visit Barcamp Kashmir event site and subscribe to the mailing list


Comments (View)