Friday, December 17, 2010

Drupal: Showing related content based on taxonomy

Everyone knows that the taxonomy module allows one to categorize your content using both tags and administrator defined terms and is very flexible for classifying content. You can create one free-tagging vocabulary for everything, or separate controlled vocabularies to define the various properties of your content.

By using views in conjunction with taxonomy, one can easily create a block of related content.

For example on www.OyeStyle.com, we have articles categorized by one vocabulary called as "Main" and another vocabulary called as "Subcategory". These contain a fixed set of terms. We also allow a taxonomy with free-flowing tags for that much more flexibility and further categorization.We wanted to show a block of related articles based on the taxonomy on each page and of-course views was the answer. The link here at http://drupal.org/node/65375 details out as to how to go about it for D5 and D6.

However due to the free-tagging entries, we were ending up with a long list of articles diluting the "meaning" of related content in some ways. Here is how you can pick up related content by using specific taxonomies by avoiding free tags:

After following the instructions above in the drupal link, go to your view and edit the "Taxonomy: Term ID" argument. We then need to modify the PHP code specified for the default argument handling. Modify it thus:

$node = node_load(arg(1));
if ($node && $node->type == 'article' && $node->taxonomy) {
foreach($node->taxonomy as $term) {
$vocab = taxonomy_vocabulary_load($term->vid);
  if (empty($vocab->tags))
      $terms[] = $term->tid;
}
return implode('+' , $terms);
} else { return; }

The key difference in the above code is that for each taxonomy term associated with the node, we are getting the vocabulary associated with it . We then check if this vocabulary allows free tagging and ignore it if so (the empty($vocab->tags) check does this). Do not worry about the performance implications here, the vocabulary will most probably be cached across future calls. One can possibly do other modifications to the above code. For example, lets say you only want terms from a specific vocabulary. That can be done by:

$specific_vocab_name = 'Main';

$vocab = taxonomy_vocabulary_load($term->vid);
  if (strtolower($vocab->name) == strtolower($specific_vocab_name))
      $terms[] = $term->tid;


The above code will only pick terms belonging to the 'Main' vocabulary.Basically modify the vocabulary checks appropriately to get the desired results.

I hope this was useful. Check out the working functionality on Oyestyle by browsing through the articles there! :)

Monday, October 11, 2010

CDN with Drupal and Parallel module

Am getting good exposure to Drupal land and am loving it so far. I have to be hands on for my work and that is the best way to gain knowledge and expertise - be hands on, nothing beats it!

The current speed of www.oyestyle.com is pretty good, but I wanted to be armed for the day we hit bigger numbers :), so I was testing out the possibility of using a CDN to serve out the static javascript, css and image stuff on the site.

First, I also looked at some Indian CDN offerings. Obviously if the data is being served from close to India, it will help the target audience. But both Airtel and Tata offerings seem to be out of the reach of people who are just starting out. I also checked out the Marcellus guys, but they seem to specialize only in videos. Am thinking and looking at MaxCDN guys currently.

Anyways, the article is about setting up a CDN quickly. For this, we are planning to use the Parallel module. It is not strictly a CDN module per se, but what it does is that it allows you to specify [sub]domains that you can use for your js/css/image files. The page preprocessor code then replaces all references with those domains. This is all you need to do to set it up!

If you have a pull-based CDN like MaxCDN on the other side, then you do not have to upload any files to it too. If it cannot find the file, the cdn will fetch it from my server and then serve it from then on. It will handle this transparently! Will get back with my experience soon :)

Wednesday, July 7, 2010

Drupal source code and [g]vim/cscope

When you start looking at modules developed for Drupal - you kinda get lost amidst all the references to different system functions - user_external_load, db_query, etc. It becomes really maddening!

Fortunately a cscope-enable gvim binary will ease out the source code browsing angst to a large extent. Amongst all the other things, here is what I have in my .vimrc

if has("cscope")

   function! CScope_Refresh()
cs kill 0
 !find $PWD -name \*.php > files && cscope -b -i files
!find $PWD -name \*.js >> files && cscope -b -i files
!find $PWD -name \*.module >> files && cscope -b -i files
!find $PWD -name \*.info >> files && cscope -b -i files
!find $PWD -name \*.install >> files && cscope -b -i files
!find $PWD -name \*.inc >> files && cscope -b -i files
cs add .
!rm -f files
endfunction
comm! -nargs=0 R call CScope_Refresh()
endif

After you have sourced your .vimrc again, you can navigate into your Drupal install directory, fire up gvim and just hit :R and you will be able to search for symbols, look for references to functions, look for files etc. using the standard cscope commands:

e.g.:

:cs find g user_menu

The above will lead us to the definition of the user_menu function in user.module. 

Hope, this post will relieve some of your source code browsing pangs :)

Sunday, June 13, 2010

Why Drupal..

The first major decision that we at had to take at Yuva was about which infrastructure piece to use for the first version of our product launch. Our's is a web-based product. We want to incorporate elements that engage and inform the user-base in various interesting and socially-viral ways. We also want to provide group based interaction, public-private access control features etc. etc. I hope you get the drift! :)

Coming up with hand-crafted code to do all the above seemed a daunting and an insurmountable task given that we want to be out there ASAP. It was then that we started looking around for open-source alternatives.

Drupal and Joomla came up trumps in that research. The idea was to take something off-the-shelf, understand it better and then customize, extend it for our needs. Then come the difficult part of actually deciding between these two. Googling up can actually be a frustrating exercise. For every positive reference you will find an equally disparaging remark too. For every positive user case study you will find an equally pulling-my-hair-off-in-frustration use case too. Tough job!

In the end we have decided to go with Drupal. They seem to have a large thriving community and a lot of websites seem to be coming up on its platform. Additionally Drupal 7 (when it will be launched) seems to further improve on the capabilities provided and the user-friendliness aspects too. Finding good Drupal talent (to hire) based out of India has been an issue so far. But we are trying to build the expertise in-house, because this is a core-requirement which we think we  cannot out-source at all.

Will post back on our Drupal experiences in the coming months - stay tuned!

Thursday, February 12, 2009

Me, my phone and my calendar!

Recently, I got the entry level HTC smartphone for myself. The 3400i is a VFM phone with all the bells and whistles one would need in an entry level smartphone. Whenever I change a phone, the biggest headache is moving around the contacts and the calendar information. I tend to forget and rely a lot on the calendar to remind me about important events like birthdays, marriage annivs and the likes.

I was looking forward to a dreary timespan trying to update my calendar on the phone for all those important events. Its just today that I read about GoogleSync for mobile phones. Via GoogleSync one can sync their googlemail contacts and calendar events immediately with their smartphone! I was sceptical but it was a total breeze. I just had to enter my gmail address details in ActiveSync (yes mine is a Windows Mobile phone - no bricks please :P) and lo-and-behold my gmail contacts plus all calendar events were uploaded wirelessly onto my mobile! Nice, I say :D

What are you waiting for, go get your mobile synced up!

Friday, January 2, 2009

FC10 woes

So my last posting mentioned the reasons why I upgraded my laptop from FC8 to FC10. But the recent events have left me flabbergasted :(

Last week, the automatic update system informed me of the availability of a new kernel (kernel 2.6.27.9-159.fc10) and I dutifully installed the upgrades. The machine stopped booting up since then! It would directly go to the GRUB prompt and nothing else would occur. 

I thought I will just boot up using a CD, mount my drive and edit grub.conf to start using the machine again. I did so and thankfully the Linux partition started booting up again normally. But in this process my Windows Vista partition got totally messed up (again due to the grub manipulations I would think) and goes into a recovery and rescue mode on every bootup :(. Attempts to mount the partition from within Linux also comes out with an error! 

Now darned if I had taken a backup ever!  To summarize, I have lost my windows partition along with all the data on it and am now in the process of a re-install of WinVista. That this laptop is where I do my work on is what makes matters worse. 

Lesson learnt - do not upgrade to a bleeding edge technology unless it has settled down or you BLEED like me. Guess I should have gone to FC9 first... 

Wednesday, December 3, 2008

FC 10!

So a while ago, I upgraded my laptop from FC8 to FC10. It was a pretty simple process because the upgrade operation identified my existing FC8 partition and smoothly upgraded in roughly an hour and 30 minutes without asking for too much. Simple, nice and easy I say. Anyways, here are some reasons why you should upgrade to FC 10 (or this is what Redhat claims to be the reasons):

#1. Speeding Up the Boot Process
#2. The Excellent Solar Theme
#3. Making Printing Snappy – and Attractive
#4. Better Webcam Support
#5. Improved Virtualization
#6. Live image creation tools
#7. Global community efforts
#8. PackageKit (user-friendly yum!)

Read more details about the above and some more here. And let me close this entry with this quote that I read somewhere today :)

"Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)"