Friday, February 22, 2013

Intro to Drupal image token system (Drupal 7.20 onwards)

In Drupal 7.20, a new token system was introduced for image derivative urls to circumvent a security DOS issue.

An image derivative would have only one token. However, different image derivatives (image styles) of the same main image will have different tokens each.

The image token is generated as a base-64 encoded sha-256 hmac based on the drupal hash salt, image style name & uri in image_style_path_token(). So it remains constant for an image derivative but changes based on the image style name.

The call stack for generating image style links is:

The security check is conducted in image_style_deliver() where it is a valid url request iff;


$_GET[IMAGE_DERIVATIVE_TOKEN] === image_style_path_token($style['name'], $scheme . '://' . $target);

NB: IMAGE_DERIVATIVE_TOKEN is a constant for 'itok'.

Tuesday, December 11, 2012

Thank You, from the bottom of our hearts.

On the morning of Diwali 2012, a day before Teachers Day, my wife and I found ourselves on our way to India. It was not a joyride home though. My father had bid adieu to this world in a sudden respiratory attack.  He was ambulatory, witty and independent to the very end. Also, he was very well loved and respected. Too many people have expressed grief over our loss and as many have been with us so long.

I dedicate this post to everyone who have touched our lives. Right from the very beginning till now. Sometimes it was the most unexpected of people who've shown empathy. Countless times we've been blown away by the tireless compassion shown by you all. My father was blessed in every other way - we'd always say.

My father has shown that Cancer is definitely not a disease. It is not to be frightened about. It is a door to a different world - perhaps painful to the body but enlightening to the soul. It is a world where the smallest of things can bring much happiness. And each peaceful morning is all that matters. Where a smiling face is like the radiating sun and a lending hand lets you cross an ocean.

Truth be told, my father had conquered the disease ages ago. He was never tormented by the pain in as much as a bodily discomfort and helplessness to others, as he only gained in faith and respect as it progressed, thereby giving it only his body in the end but leaving with a very strong and reaffirmed soul than ever before.

We thank each and everyone of you who have shown us this world. We have seen the kindness in your soul. Your empathy and compassion is unforgettable.

We really thank all our doctors at Amritha hospital, Cochin and Adayar Cancer Institute, Chennai - you are all God in different forms, tirelessly working and striving to help others compassionately. Truly yours is a noble profession. I have to especially highlight the work done by Adayar Cancer Institute and Cachar Cancer Center because they are hospitals with world-class doctors freely treating the poor throughout the year. My respect for them goes through the roof. I was only able to contribute as little as I could monetarily but I will make it a point to lend my voluntary help as I can too.

Now to the present and the future.

In the present day, where one in three is affected with this disease, there is not a single neighborhood that is without an affected household. Economic and social conditions aside, this disease affects victims alike. And suffice to be told that a terminal disease afflicts not just the patient, but an entire family.

Gauging from simple research, one can be quite satisfied with the level of cancer awareness spreading throughout the world now. The fight for it is also in good progress with countless agencies and pharmaceuticals in this pursuit. But what is lacking is the continued support, care and voluntary work shown by society - what you have given us and taught the invaluable benefit of. Ongoing cancer support is as much as a necessity as finding a cure. Society needs to mend itself to be more outward and supportive than inward and pleasure seeking nowadays. I now feel if I could spend some of those empty evenings from work at a needy house lending a helping hand, it could do wonders. Way better than procrastinating in front of the television or computer. This is my next journey.

I thank you all from the bottom of my heart once again for being my guide, mentor, friend and strength in times of our deepest sorrow. God Bless.

Monday, September 10, 2012

Keeping focus is necessary

A lot of us loose focus quickly. This is exactly what I don't want to be. Even after my dearest family member has either succeeded or succumbed to cancer, I want to keep fighting and supporting all means of eradicating this killer disease. Need to keep my focus. I pray to continue the good deeds that I involuntarily needed to  support.

Monday, July 23, 2012

Lighter version of loading fields on an entity

Here is an alternative to entity_load() types (node_load(), taxonomy_term_load() etc.) that is useful if you want to bypass all the calls to hook_entity_load()

If you know the entity id, type and 'bundle', then this could reduce load time:


How do you call this function?

For nodes:


For taxonomy terms:


Caveats:
  • Does not call hook_entity_load() hooks.
  • You can implement a caching strategy based on the modules used. For e.g. when entity cache is used, field_attach_load() does not cache data in 'cache_field'

Wednesday, April 11, 2012

Fivestar float rating module - Drupal

I have just created a sandbox module that allows inputting of float values for Fivestar fields, so that it is easy to create ratings such as 2.7/5, 3.1/5 etc.

This module adds a field widget to the Fivestar field, which is a textfield that will take a float value as rating input. The display is unaffected and uses the default Fivestar theme functions. Users can override the theme functions to make use of better floating point precision by affecting the round() function there. See more description in the project page.

Awaiting comments, thoughts and reviews before I decide on the further course of action.

Do read this fivestar feature request first, as to what is missing and why I created this module.

Monday, March 05, 2012

Cache expiration module Alpha1 version released

What a pleasant surprise on a Monday morning to see the Cache expiration module release its alpha1 version, ready for basic use and testing.

Varnish, arguable the most common reverse proxy caching mechanism used with Drupal sites has integration with the Cache expiration module. With this module, it was not possible to selectively expire (purge) urls from Varnish. But now we can (atleast for some most commonly used cases).

Basic testing
Some basic testing gave very good expected results. First your Drupal setup to cache pages for anonymous users at admin/config/development/performance. Then by merely enabling the expire module, and using the default options enabled in its config page (snugged away in admin/config/development/performance/expire), you can see the benefits already:

For e.g:
Assume you have you home page cached by varnish (min cache liftime 5mins). Which means any edit to the homepage in that time will not show up to the anon user, who still sees the cached version. Unless you purge Varnish manually.

Not anymore, with the expire module enabled.

Cache expiration will purge the url of the homepage immediately, because you edited your homepage.

Good stuff already! That is not all. Here is a look at its optional features in the alpha1 release:

Optional features
  • When a node is expired their nodereferences and parent nodes where it is referenced can be expired.
  • When a 'promoted to homepage' node has been expired, the homepage can be expired.
  • Expire the menu(tree) when a node expires
  • Expire the term pages of those terms tagged to an expired node.
Note: 'expired node' refers to a node (url) that is being purged from Varnish on the event of it being edited.

Now, the wait for http://drupal.org/project/views_content_cache just got more exciting!

Thursday, November 24, 2011

JW Player module now supports plugins

The JW Player module, which is currently in development for Drupal 7 has just got the feature of being able to support plugins for presets. With this feature, it is possible to plug in all the add ons availabe from Longtail video.

JW Player plugins

There is also a Drupal preset plugin created for Google Analytics Pro2 JW player available in my sandbox. Custom modules can implement plugins by using the newly introduced hook_jw_player_plugin_info() in the JW Player module. The format to use this hook as described in jw_player.api.php is:

/**
 * Implements hook_jw_player_plugin_info()
 *
 * @return array Associative array of plugins keyed by actual plugin id
 */
function hook_jw_player_plugin_info($preset) {
  // Create a plugin keyed by its actual plugin id
  $plugins['foo'] = array(
    'name' => t('Foobar'),
    'description' => t('A plugin to do foobar'),
    // Note: Each option should be in a valid FAPI format, as it is directly referenced in the preset settings form,
    // except the '#title' may be omitted for the name of the option to be taken as default
    'config options' => array(
      'accountid' => array(
        '#type' => 'textfield',
        '#required' => TRUE,
        '#size' => 15,
        '#default_value' => 'bar'
      ),
      'param2' => array(
        '#type' => 'select',
        '#options' => array('TRUE' => 'TRUE', 'FALSE' => 'FALSE'),
        '#default_value' => 'TRUE',
        '#description' => t('Enables the controls on an item when playing')),
    ),
  );
  return $plugins;
}

As described above, the plugin is an associative array keyed by its actual plugin name as required by the player. The data basically consists of a friendly name and description, followed by configurable options that the site-administrator/editor can set per preset, which would look something like:

JW Player preset settings
If the preset plugin is enabled, when viewing the source code of your page that contains a JW Player video, you should be able to see the plugin added to the player code; something like:


Wednesday, November 09, 2011

How to use hook_query_alter() to alter Views in Drupal 7

Sometimes you need to alter a Views query by using the regular SelectQueryInterface methods without having to use the Views data structure in hook_views_query_alter(). It may get tedious at times working out all the views relationships, and arguments separately and adding a simple 'groupby' may get tricky if you do not have aggregation set in the view. It could also be that your hook_views_query_alter() runs a little too early for the $query to be modified.

Luckily, when the Views query is built in views_plugin_query_default::query a unique tag is added to each view of the form 'view_<view_name>':

// Go ahead and build the query. 
// db_select doesn't support to specify the key, so use getConnection directly.
$query = Database::getConnection($target, $key) 
  ->select($this->base_table, $this->base_table, $options) 
  ->addTag('views')
  ->addTag('views_' . $this->view->name);

Note: views_plugin_query_default::execute adds access data to the query which should be used for building access rights to the query during execution.

So, in your hook_query_alter(), you could identify the view based on its tag and modify the query like any other SelectQuery. I found this easier than using hook_views_query_alter() many times.

Example to group by a specific field: 

function hook_query_alter(QueryAlterableInterface $query){
  if ($query->hasTag('view_my_custom_view')) {
    $query->groupBy('n.type');
  }
}

Tuesday, November 08, 2011

Themeing EVA views using custom templates [patch]

Entity Views Attachment lets you attach a view to a Drupal 7 entity. This means when viewing a node, you could display for example, a list of other nodes by the same author. See http://www.theweek.co.uk/columnist/michael-bywater

But due to the way the views plugin was written, it was not possible to use custom templates for EVA views. If you tried to, you would end up with a lot of 'underfined variable' notices for all the variables in your custom template.

E.g.
Notice: Undefined variable: title in include() (line 31 of /../sites/all/themes/../templates/eva-display-entity-view--gallery--entity-view-1.tpl.php).

There is a hard dependency on eva.theme.inc even when overriding eva-display-entity-view.tpl.php to a custom tpl. Due to this, template_preprocess_views_view() is not run.

The patch in http://drupal.org/node/1205008#comment-5130160 fixes the above limitation by removing the dependency from hook_views_plugins().

Sunday, November 06, 2011

Its all a dream they say

In my dream I conjure up characters, including myself. I am very real in the duration of my dream. I do things, I see other people. I feel emotions. Sometimes I also see myself from above doing different things, often connected to me past interactions with people. And then I wake up. All the characters and myself disappear away and I am back to my present self. It was all a dream, they say.

Where did all those characters go? The events in the dream seemed real, even though the colours were not as vibrant and vivid as the non-dream state. We have always pondered about what happens to the soul after death. Life is energy, so it has to transform from one form to another?

I believe the answer to the question of where one 'goes' after death is also similar to what happens to the characters of a dream on waking up.

Hinduism suggests the whole world is Maya (an illusion). Do illusions change form? What if we do not involve the perceptor?

Wednesday, November 02, 2011

Varnish simple purge

So whats a Drupal 7 developer to do if he needs to launch a highly dynamic anonymous site and needs to plan caching strategies? Use Varnish cache of course.

But if your site is as dynamic as mine, Varnish will display stale entries unless its TTL is set to something like 1 hour. For a dynamic news site then, surely you need automatic rules to purge pages from Varnish on new or updated content? For e.g. the homepage is changing constantly! The index pages will also change often.

There are currently two modules in the pipeline that should offer the ability to purge pages (cache ids) from Varnish, instead of the whole Varnish cache (oh God, no!):

  1. Cache Expiration, and
  2. Cache actions

While waiting for these more suited modules to have a stable, usable release on Drupal 7 production sites, I had to create a very simple module -Varnish Simple Purge - that allows site admins/editors to purge individual urls from Varnish.

We don't want to give them too many options, cos by experience we know they will use all :) Finally Varnish will more often be empty - not a good state to be in.

Hence with a Varnish TTL of 1hour and a simple purge mechanism to purge pages immediately if needed, my news site is working way faster than its non Drupal predecessor. Oh did I forget to mention that this site is a port from a bespoke CMS to Drupal?

Other cache clearing mechanisms we use are time based views cache (in-built in views). What we would really love is this port of Views Content cache.

Wednesday, August 03, 2011

Managing optional features in a Drupal Distro

So you need to build a comprehensive distro using features to export data into code. Fair enough. What could be one of the most common problems in trying to create a common solution for all sites?

Problems:
  1. 20% of the sites would want additional fields

    In your distro, say content type 'article' has 10 fields and needs 2 optional fields. All sites will use the 10 'core' fields and the 2 optional fields may or may not be used.

  2. Some sites want to alter field labels and change display settings on content types

Solutions:

  1. Separate overridable feature for extra fields per content type

    Export the main content with 10 fields into one feature and the optional fields into another feature. Site builders can leave the main feature alone and modify the extra feature only (change field permissions, usage, labels etc.)

    Perhaps its not easy to export the content type with the extra fields left out. In that case, manually remove the field's references from the export files. Usually those will be in *.features.field.inc & *.info files.

    Then export the extra fields in a separate content type and manually add a dependency to the main feature.

  2. template_preprocess hooks.

    Consider encouraging site-builders to place all field alterations in appropriate hooks such as hook_form_alter() and hook_template_preprocess_page()

  3. Override field display settings

    This module is still in its infancy but its possible to export field display settings separately into a feature. A comprehensive guide can be found here - http://www.agileapproach.com/blog-entry/new-paradigm-overriding-drupal-features

Monday, July 11, 2011

Space shuttle cockpit

A few years ago, I remember posting this interactive view of the Airbus A380 cockpit.

And now I am as thrilled to get this link for the Space shuttle cockpit

Friday, April 01, 2011

Google's April fool 2011 - Google motion

Its always a pleasure to blog about the April fool's joke played by Google each year. For 2011, its the Google motion way of communication.

Wonder if anybody would really start doing the 'motion's! Good exercise anyway!

Friday, November 05, 2010

The thing about documentation

I love agile methodology and extreme programming. I used to work in a team that loved it and lived by its core philosophy. To top it of we had a strong technical manager who was a certified scrum master and new the approach inside out. Life was good.

Then our manager left. We got a lot of new recruits, many who had never worked in a core agile environment. Our teams got shaken up. Ultimately, the loudest voices got heard. 6 months into it, we have sort of become a mess. To sort of patch up the mess, somebody suggested documenting processes, because to some people, agile meant chaos. Of course agile methodology minimises documentation. Its not that we hate documentation. But I hate certain kinds of documentation. Documentation of processes.

How can you encapsulate all the nuances about human activities - interactive communicative and effective procedures - into words? Documenting processes is like making humans machines. Without creativity or without thought. Processes always are evolving and no two situations can be asked to follow the same text. People need to think on their feet each time. Agreed - some process documentation come with a disclaimer that these are just guidelines and to use proper judgement before following them. Now a poor new recruit new to the agile world would ask - where is that documented?

I believe in mentor-ship and process mentor-ship that encourages and teaches the ideology behind thought. Perhaps putting this ideology into text would not be bad since it does just that - captures ideology.

Anyway, I do like documentation on one important aspect - requirements. Although requirements may change in the real world, they still need to be documented. Because requirements need to be translated into code, which a machine needs to understand. Quite unlike process documentation which a human needs to understand, assimilate and generate an effective action out of.

Friday, October 22, 2010

Are we doing enough, or are we sinners?

In the colonial era, my countrymen, Indians, with our peaceful ideology and treating-guests-like-kings mentality eventually got overpowered by the mighty British forces who had been thinking of and investing in arms and destruction years before.

In fact, the British powered over so many other peaceful regions and these innocent people paid the price for.. being innocent? The British in this case can of course be seen as barbarous and used their technological advantage to power over other (weaker) human beings. Nothing too different from Hitler and others who abused powers and got blinded by greed, possession and sense of omnipotence.

Question is: why did the peace-loving, God loving people have to pay the price for not having destructive weapons? They did not waste time polluting their minds thinking about exploitation, murder, destruction and such evil thoughts. Was it their fault that they were abiding by God's teachings?

I could not come up with a good answer to this easily. After pondering for quite a while, the most reasonable explanation I could come up was:

'The good' & the 'innocent' did not do enough to take over the world and spread their goodness. Evil took over the world quite easily. Why? Because the good was dormant. They perhaps did not do enough and did not think for other people in other lands so as to spread the wealth of their knowledge and values to other cultures. It is the duty of every 'good' person to spread the message about their ideologies. If they think its not worth spreading, then they probably are vagabonds without a purpose in life and in doing so, are committing a sin.

So it all boils down to each one of us. Are we doing enough to spread our message of our view of the world? Are we doing enough to share our thoughts and beliefs in the hope that it will help humanity? What are we doing for mankind? Are we doing enough?

Thursday, October 21, 2010

Autocomplete paths and themes in Drupal

It is very important that any AHAH callback menu item is of the same theme loading menu execution path as that of the parent. Otherwise you will have themes conflicting and overriding each other.

Here's a case in point:

Say you are using 'rubik' theme for admin pages (node edit & add pages). And lets assume you are using Garland as the front end theme for other users.

If you happen to have an autocomplete or AHAH form element in the node edit page like so:
$form['book']['submit_book'] = array(
'#type' => 'submit',
'#value' => t('Select book'),
'#weight' => -4,
'#attributes' => array('class' => 'book-title-select'),
'#ahah' => array(
'path' => 'mybooks/js',
'wrapper' => 'edit-book-plid-wrapper',
'effect' => 'slide',
),
);

This will cause the Garland theme to be loaded to the current page when the AHAH callback 'mybooks/js' executes. If the callback happened to add new elements into the form, then they would be rendered in Garland. Not what you would really want! You could go around in circles with your UI team over this and waste a lot of time like I did!

Wednesday, September 29, 2010

Eclipse crashing & workspace in use?

I use Eclipse with PDT at work. True it may be a memory hog but I love using it now.

I usually edit the eclipse.ini file in the eclipse/ folder and increase the memory usage of it.

For e.g. for 512MB RAM, I set:

-Xms256m -Xmx256m -XX:PermSize=64m -XX:MaxPermSize=64m

Here are some more configurations.

Another common problem is eclipse crashing. When you restart it, it may say that your current workspace is in use and you need to choose another workspace.

This is because there is a .lock file hidden in your .metadata/ folder in your eclipse/ directory. This file is created when eclipse starts and is deleted at every proper shutdown of eclipse. So if eclipse crashed, sometimes it would not have deleted .lock file and hence it thinks there is another eclipse program running. Delete the .lock file and you are on your way.

Tuesday, October 20, 2009

Google new home page (A/B testing I think)


I happened to hit a Google A/B testing page from UK today.

They seem to be loading just the Google logo and the search bar first. Then once you move your mouse onto the page, the top header and footers appear. Some javascript funkiness to a simple page. ~Why?

Also if you notice, the "Search" and "I'm feeling lucky" buttons have disappeared.

The live search suggestions work from the search bar still.

I'm feeling this may be one of the new Google home pages we may be seeing in the near future.

Thursday, March 19, 2009

Changing the scenario of global development: The great economic crisis of modern times

Will the current economic crisis just be a short circuit for the current development trends of the world, and will the same technologies and advancements continue in hoping for a quick recovery? I don't think so.

Economic trends of money generation and consumer satisfaction are based on unforeseen habits that can quickly catch up. Like in art and architecture, they are parts of the current age. They are born, live a span of life (based on various acceptance and factors of chance) and also face death. I am analysing the impending of the current Information Technology age advancements in niche areas. True, the Internet was a revolutionary invention. People are so dependent on it. But not all its seedlings are going to be properly nourished or going to have a market in the future. The economic crisis has forced us to look inwards on the basic needs of life and sustenance.

Humanity is going to reinvent its business-space. Looking inwards, we are going to realize the basic necessities of sustenance in Food, agriculture, and its related areas. People will be less concerned about technology except for the most widely used areas (like e-commerce). The basis of business is going to be reshaped. Organic farming is going to be the most popular choice. Service based industries will pop up their heads but will be difficult to survive for long as customers are less cash-rich.