Zardoz

A Blog

A compound field example for CCK 2 & Drupal 6

leave a comment »

For anyone attempting to create a compound field (meaning a single CCK field that is made up of multiple sub-fields) in Drupal, but are lost in a sea of poorly documented hooks and functions so abstracted as to have lost nearly all meaning, like I was for the last two days, I offer you the following example module. This is tested to work on an Acquia Drupal 6.14 build with CCK version 6.x-2.5. By “work”, I mean that your form will have a compound field that saves data and is available in your $node object. There are no settings, no validation or sanitizing or views integration. This is provided merely as a starting point for your own custom module.

For your own use, you’ll want to start with these four functions:

  • compoundfield_field_settings to declare your database structure;
  • compoundfield_process to declare the Form API structure (as you would any other Drupal form);
  • theme_compoundfield to theme the form HTML;
  • and theme_compoundfield_formatter_default to theme the frontend HTML.

Suggestions, questions, and comments are all welcome. This code is mostly a combination of the link module, Karen Stevenson’s very helpful Lullabot article, and this article by Jennifer Hodgdon.

Written by Andrew

November 9, 2009 at 3:21 pm

Posted in Drupal

Tagged with , ,

Migrating from Gmail to Google Apps

with 2 comments

Here I hope to help you avoid the pain of trying to migrate a Gmail account (or two) to Google Apps without knowing how, which appears to be completely undocumented and unsupported. There are various other methods but none of them worked for me, so here we are.

One caveat with this method: all of your email will be “archived”, meaning if you’re one of those people that keeps everything in the inbox, your inbox will be empty when all is said and done. Some people think that’s a good thing, and I agree – though the line between organizing 99% of your mail and 100% happens to overlap the line between sanity and insanity. The line between love and hate is also nearby.

Preparations

  1. You’ll need to set up a Google Apps “Premier Edition” account. They have a 30-day trial so you can do all of this and then cancel before being charged.
  2. Set up your user and your email account.
  3. Recreate your gmail filters and labels before migrating – this way your migrated email will be filtered and labeled as it comes in. Contacts can be exported/imported easily.

Migration

  1. Go to the Google Apps dashboard > Advanced Tools > Set up mail (IMAP) migration.
  2. Set up the Google Apps <> Gmail connection like so:

    You can of course change the number of connections but it should probably be kept low, otherwise you risk a lockdown in sector 4.
  3. Enter your Account username and password and test the connection. You should only see “All Mail” under “Folders Found”. (This is important because the migration program thinks labels are folders, so if a particular email has 3 labels attached to it and if you were to import the entire gmail account, you’d end up with 3 duplicates of that email.) Click Start migration. Enjoy knowing that you didn’t have to waste hours figuring all of this out on your own. You bastard.
  4. The migration should create two new labels, “Migrated” and “Migrated/All Mail”. After migration is 100% complete, delete those labels and you’re done.

Written by Andrew

August 20, 2008 at 3:40 pm

Posted in Google

Tagged with , ,

Better Windows behavior through software

leave a comment »

If you’ve ever wanted to be able to install a font simply by right-clicking on it in Windows, this InBev’s for you.

Written by Andrew

July 29, 2008 at 9:49 pm

Posted in Windows, usability

Minimizing TCP connections: Drupal’s Lightbox2 module

leave a comment »

I’ve been trying to cut down on TCP connections per pageview for a Drupal 5 site which uses the Lightbox2 module. I noticed that the following images are loaded, even if none of the images on the page are lightboxed:

/sites/all/modules/lightbox2/images/loading.gif
/sites/all/modules/lightbox2/images/blank.gif
/sites/all/modules/lightbox2/images/prev.gif
/sites/all/modules/lightbox2/images/next.gif
/sites/all/modules/lightbox2/images/close.gif
/sites/all/modules/lightbox2/images/expand.gif
/sites/all/modules/lightbox2/images/pause.gif
/sites/all/modules/lightbox2/images/contract.gif
/sites/all/modules/lightbox2/images/play.gif

It’s possible that Firefox and IE (and/or Safari) behave differently in this case, where an image is called by the CSS background property but the containing element is set to display: none. I don’t see these as loaded in Firebug, but I do see them in “Page Info”, under Media, as well as in the HTTP access log.

Since I’m only using the loading.gif image for preloading (clicking the image itself or the overlay closes the lightbox), I want to keep from loading the rest. The solution here is to comment out the background property definitions in the lightbox2/css/lightbox.css file that call the remaining images. Having done that, the TCP connections needed for each non-cached pageview is reduced by 8.

Written by Andrew

July 29, 2008 at 5:05 am

Posted in Drupal, browsers

Limiting qmail-smtpd instances

leave a comment »

Two of my Media Temple (dv) servers were getting hit by a botnet-like spam attack this morning, causing a significant number of concurrent SMTP connections. There was a rapid succession of /var/qmail/bin/relaylock entries in the maillog (checking that with tail -f /usr/local/psa/var/log/maillog), but the real problem was the number of qmail-smtpd instances running (found through either top or ps aufx), each of which was eating into the available kmemsize.

I think I’ve managed I thought I managed to limit the number of simultaneous qmail-smtpd instances by changing the number of instances from 60 to 10 in /etc/xinetd.conf and restarting xinetd & qmail. I tried changing the instances of both /etc/xinetd.d/smtp_psa and /etc/xinetd.d/smtps_psa to 10 (from the default UNLIMITED) as well, but that didn’t seem to have any effect. After both changes I restarted xinetd and then qmail like so:

/etc/init.d/xinetd restart
/etc/init.d/qmail restart

Update:

On further investigation, this measure didn’t work out, qmail-smtpd instances were still going overboard and causing kmemsize problems. However I did find another option which seems to be having a slight effect: adding a “per source” to smtp_psa and smtps_psa, which means each IP can only have one connection at a time (doesn’t do much for spam flooding in from hundreds of different IPs, but still):

service smtp
{
socket_type = stream
protocol = tcp
wait = no
disable = no
user = root
instances = 10
per_source = 1
server = /var/qmail/bin/tcp-env
server_args = -Rt0 /var/qmail/bin/relaylock /var/qmail/bin/qmail-smtpd /var/qmail/bin/smtp_auth /var/qmail/bin/true /var/qmail/bin /cmd5checkpw /var/qmail/bin/true
}

Written by Andrew

July 29, 2008 at 4:46 am

Posted in plesk, qmail, servers

Internet Explorer 7

leave a comment »

Let me put it to you this way: only Internet Explorer 7 and Phoenix 0.1 put the refresh and stop buttons to the right of the address bar. Mozilla developers quickly realized how stupid that was and fixed it in Phoenix 0.3; but Microsoft, who had the correct idea since IE 1.0, decided after 9 years to unfix it in IE 7.

Written by Andrew

May 30, 2008 at 4:39 pm

Posted in browsers, usability

“Quick Sketch” Functionality

leave a comment »

Email clients would benefit from a simple pluggable “sketchpad” interface that would allow the user to quickly (specifically, quicker than doing it in photoshop and uploading and attaching the image) sketch something out and embed it directly into the email. I think the drawing interface is possible in javascript, the image generation would happen server-side. I haven’t seen anything like this yet (a javascript sketchpad that outputs a gif/png in its place via AJAX), but correct me if I’m wrong.

This could also have applications in blogging, project management, groupware – any online application where ideas would be more efficiently or effectively communicated visually.

Written by Andrew

April 30, 2008 at 6:59 pm

Posted in suggestions