Theming Flashvideo Thumbnails with Imagecache in Views

People using the fantastic Flashvideo module, which uses FFMPEG to transcode your videos to flash for you, get only one shot to make a thumbnail image when the upload is processing.

The problem is, you rarely get a thumbnail size that applies globally. What you'd rather do is make a thumbnail image that's the largest size you want, and then use imagecache to put the thumbnails at different sizes around your site.

Stashing stuff in $_SESSION in your form's _submit handler in Drupal

Today I was trying to figure out why in the name of all that good in the world why I couldn't use $_SESSION in my form's _submit handler.

As it turns out, I actually CAN put stuff into $_SESSION, it's just that when you want to pull something OUT of $_SESSION later, that's not where it is.

Instead, it's on the $user object in Drupal, in $user->session. After some studying, it seems this is a pipe-delimited and semi-colon delimited list of variable names and their serialized values.

Here's a function to pull stuff off of $user->session:

<?php
/**

Views "rewrite output" and you wish you had PHP? Don't always resort to customfield!

First of all, let me tell you how much I love and appreciate the Views_Customfield module, which lets you (among other things), write PHP to print out a field using views. When I need to, I can do some complex conditional-writing based on two other views fields, or I can do things like calculate a thumbnail for a photo gallery based on grabbing some fields using a raw db_query that aren't available through views, and other such craziness (note: be wary of doing this it can kill your site performance!).

Ubuntu 10.4 Based Drupal VM Partition File System ext4 to ext3 Conversion

Due to the nature of our business, we have to test our sites on all different types of OSes and browsers. I have a Macbook, for example, on which I run OS X, Ubuntu 10.4 and Windows XP.

Using drupal_execute but it's not working? Load that include!

I was struggling to use drupal_execute in a custom services call I was writing. After some time rifling through form.inc I was able to conclude that function_exists('my_submit_handler') was returning false.

But... but... my module is loading, I promise!

Doesn't matter, the .inc files aren't necessarily pulled in until they're told. Before you call that drupal_execute, make sure to include the .inc file where that submit handler resides (if there is such a thing). I was trying to automatically create a mailhandler mailbox using a services call, so I had to:

Could Not Find Custom CiviCRM Report Template

If you get the following message when attempting to create a report based on a custom CiviCRM CiviReport template,

Could not find the report template. Make sure the report template is registered and / or url is correct.

this is likely caused by an invalid template class value.

To fix this:

  1. Navigate to Administer > CiviReport > Manage Templates and click "Edit" on your custom template.

Show / Hide Fields In A Views-Generated Drupal RSS Feed

If you want to modify the fields included in a RSS feed generated by the Views 2 module, you have a few options including themeing the view, but the easiest way to simply show or hide certain fields and/or their labels is to simply go to the "RSS" tab when editing a content type's "Display Fields" settings. That's it. Below, I set a couple fields to not be included in my RSS feed since I didn't want, for example, the image name from showing up in the feed.

Format Drupal Calendar Module Mini Calendar Title View/Block

Theming the Date and Calendar modules can sometimes be a little tricky. I wanted to change the title display for a "mini" calendar in a block from "Month" to "Month YYYY" (e.g., "October 2010"). In order to do this you need to first learn how to override a theme function.

Now that you're up to par on theme overrides, we can override this theme function: /modules/date/theme/theme.inc: theme_date_nav_title. You'll have something that looks like this in Drupal 6.x.

Getting mailto links to open in Chrome on Ubuntu

I've been looking on Craig's List for a car as of late, and realize that when I want to go talk to people I have to click on a mailto: link. By default, this opens in on Ubuntu using Evolution. With the "System > Preferences > Preferred Applications," though, you can change that. It can either be a custom shell script, or just a command or link.

Since my default browser is already set to Chrome, all I need to do is "gnome-open" gmail's "compose" URL. My full command is:

gnome-open https://mail.google.com/mail/?extsrc=mailto&url=%u

OpenAtrium-beta8 + mailhandler/mailcomment = segmentation fault

A week or two ago, we upgraded our support site to the latest OpenAtrium beta8, up from beta4. We make use of the mailcomment plugin so our clients (and of course ourselves) can easily reply to notification emails. As long as we're not changing any of the other fields of the case (priority, assignee, etc), it's very convenient, and matches a lot of the greatness that BaseCamp provides.

The changing widths of CiviCRM

CiviCRM can often have some pretty wide pages, either because it's a multi-step wizard, or a large table of contacts, etc. For this reason, you might use one of the classes on your body tag to style CiviCRM pages differently... something like:

.page-civicrm #wrapper { width: 100% }

The problem, however, is that sometimes you can have some CiviCRM pages which are "front-facing," and you want THOSE CiviCRM pages to look consistent with the rest of your site. Unfortunately, you don't have a body class for that! Enter the template preprocessor for page.

Mapping additional fields (ex.g. feed original source) with Feeds

The relatively new "Feeds" module, successor to Feed API and others, is unquestionably a move in the right direction. But sometimes, the documentation and examples aren't quite there yet. I had been trying to figure out how to map an additional "source" node in an Atom feed to a CCK field. There's a lot of terminology involved with feeds, and I will assume you know what that is (if not, brush up on the Feeds Glossary).

CiviCRM Mailing Not Being Sent To All In Group

If you create a CiviCRM group with, say, 1,000 contacts in it and then go to create a mailing using the same group and it only says it will send it to 750, it's likely because some of those contacts are "on hold." On hold simply means that the system has determined the email address associated with the contact to be not worth sending to (i.e., dead). This could be caused by the emails bouncing for any number of reasons.

To avoid unnecessary continued bouncing, CiviCRM flags them as On Hold and prevents them from being included on future mailings.

Create a Redirect in Drupal's .htaccess For The Base URL

I recently needed to redirect a client's traffic from their old URL to a new one. In this case, they wanted any traffic going to plain example1.com to go to example2.com/blog and all other traffic to go to example2.com/[equivalent URI] (e.g., example1.com/about --> example2.com/about).

To do this, I messed around with rewrite rules and conditions for a while, until I decided on what seems to be a fairly straight forward solution:


# Redirect example1.com to example2.com/blog
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule ^$ http://example2.com/blog [r=301,L]

A GTD "trusted system" -- todo.sh

The Rave

Yesterday was the birthday of a shell script that Gina Trapani uses to (her words) "run her life." I am a huge Lifehacker fan, and when Gina started Smarterware I subscribed to its RSS as well. Though a lot of posts overlap, some do not - and it's good to keep up with what else Gina is doing. She's a very smart woman.

Uh-oh, I upgraded to Lucid Lynx but need PHP 5.2 for Drupal!

Last night I hastily decided to upgrade to Lucid Lynx on my main development machine. Generally, I try and wait a few months till things settle, but nearly 100% of the time that doesn't work. After a short battle with my wireless and some other small things, I finally settled back into "work mode" and wanted to get started working on a project I'm working on for Appalachian State University.

Network At DrupalCon

Networking in most social situations is difficult enough, but when you throw thousands of (often) socially awkward and introverted geeks together, the task becomes even more overwhelming. And these aren’t just any geeks, these are Drupal geeks, which means you’ve got a ton of smart, dedicated and interesting people to meet -- it’s just that some might need a little nudge. If you haven’t already, I highly recommend “Work the Pond!” by Darcy Rezac -- it, along with my own experiences, is what powers the following advice:

Introduce Yourself

Drupal notifications that don't work for ___ (comments, nodes, whatever)?

I spent a few hours wading through something yesterday that I hope will save some other people some headaches.

I had the notifications module on, and it was sending notifications for node creations and updates just fine, but it seemingly wasn't sending anything when I commented on a node. It would TELL ME it did ("notification sent to x other users") but I would never get an email.

Theming Webform Emails

Wow, it seems that Drupal's Webform module has come a long way since I last used it (which I believe was Drupal 5.x). It's so convenient and really latches onto the new template hints and stuff from Drupal 6 (here I am talking about it while Webchick announced yesterday the D7 criticals queue is under 200, w00t!).

Private and Public File Access in Drupal

If you're like us, we usually only want to have SOME files "private" and not ALL files as Drupal is limited to all-or-nothing out of the box. There are some modules out there that do this, but honestly it's pretty easy to do yourself.

Let's say you don't want anonymous users (or search engines) to download any files in your sites/default/files/private folder. Create a .htaccess file in the folder you wish to protect and add the following and save (this is for Apache, but similar for Windows systems):


RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^GET$ [NC]

Using drupal_execute vs. node_save

There seems to be much debate regarding when to use node_save versus drupal_execute. Personally, I like the idea of drupal_execute, since it's just like the regular form executing--it handles validation for you, for example. This is an example of where I had to use node_save, but still needed validation.

Resolving Drupal CVS Merge Conflicts

We manage our sites via SVN by first checking core and contributed Drupal modules from cvs.drupal.org. An explanation for this deserves its own post (coming soon...), but basically we check out from cvs.drupal.org and then import that into our SVN repository.

SVN add Updated Drupal Modules With Ease

With modules such as CCK, you'll often notice that after updating it via CVS that you are left with a bunch of new objects (new translation, css, and other files) in folders and subfolders. Rather than svn add'ing each file and/or subfolder independently, try this in the root folder of the module you updated:

svn add * --force

That will add all the new files you acquired with your most recent CVS update.

Hide The Drupal Files Folder From SVN

It's best practice to hide your "files" folder from SVN since you probably don't want to inundate your repository with and endless number of updates. If you do this:

svn propset svn:ignore "*" sites/default/files
svn commit -m "Hide the files folder"

Then you should be all set, and you won't see any more "?" when you do a svn status command.

Why Can't I Edit a Drupal Node That I Have Permission to Edit?

Okay, this one gets me all the time. I grant a role the ability to edit certain nodes and when they log in and try to edit a page, there's no edit tab!

Chances are that if you've tried everything else, you need to grant that role permission to use whichever input type you've set for that node or set of nodes. To do so:

  1. Edit your node and check what input type it is set to use
  2. Go to Site Configuration > Input Formats and then make sure that the corresponding input type is configured to allow the role to use that type.

Database Migration Script

Here's a handy BASH script I wrote to pull down one copy of a database to a local version using an SSH tunnel. It's not super-secure, so it kind of assume that you have the script hosted on a local machine, securely (the DB password is in the script!).

First, go put a host named "tunnel" in your hosts file (usually /etc/hosts on *nix-type environments), that points to localhost 127.0.0.1 (mysql can get cranky when you try to connect to "localhost" - it always tries to use a local socket when you say that, so this is a bit of a workaround to make it work through the tunnel.

Remove CiviCRM Contacts From One Group Who Have Unsubscribed From Another

We run several CiviCRM instances with our Drupal sites. One issue we ran into recently concerned contacts who unsubscribe from one group which was a subset of a larger group of contacts (of which they also belonged). When they would unsubscribe from one, they would still be subscribed to the other and thus were still receiving the newsletter. Aside from the fact that the group/newsletter setup was a bit un-ideal, we had to address the issue and manually unsubscribe the contacts from the other group. Here's how we did it:

Replicate MySQL's MD5() Function in SQL Server 2005 Using HASHBYTES()

MySQL and PostgreSQL's MD5() functions are nice, simple, ways to hash your data. Unfortunately, SQL Server 2005 and up (sorry, in order to get it working in SQL Server 2000, you'll need to try a stored proceedure), you can use the HASHBYTES() function.

In a recent SQL Server port of the Actions module for Drupal 5, I ran into the following MySQL query:


SELECT aid FROM {actions} WHERE MD5(aid) = '%s'

Taking Care of Those Pesky CVS Entries.Log Files After Updating Your Drupal Module !

Sometimes when I update a Drupal module or core install, some CVS files are removed - namely Entries.Log files. When you go to svn up your changes, it will complain saying that there are files in your repository that no longer exist in your working copy (signified by the ! mark). To get rid of these, try using the following bash script (you can put this in your .bashrc file in *nix, if you're using the bash shell of course):

Drupal CVS Checkout Shortcuts

I've recently found myself having to constantly search for the CVS checkout command for drupal modules. Rather than memorizing it, I figured it was easier to create a script that does checkouts for me. Better yet, I found others who have already done that part for me. Here are some really slick .bashrc or .bash_profile scripts for dealing with CVS, SVN, and Drupal:

Checking Out a Module