The Evil of All Image Newsletters

I sometimes have designers give me a newsletter that's about impossible to render well as html, other than slicing the entire thing up as images and putting it in a table. This often happens with print designers trying to do web stuff.

What's wrong with that? Everything. Consider the following, which I just got from a major retailer (sensitive text blurred out):

newsletter with images off

Why should I care about this? I should be able to get at least something that entices me to click the "download images" button in my email program. Unless you have a stellar subject line, chances are that won't happen. And what about people using some sort of screen reader/assistive device? They're totally out of luck.

OK, so in this case the subject line promised 20% off my next order, that's a good incentive to see what this is all about, so I downloaded the images, and here's what I saw:

This is supposed to have images displayed, but not

Still nothing - either the newsletter server is slow delivering those images, or my connection is slow, or whatever. Is this how you want to present your brand?

So please, if you're doing an HTML newsletter, put some good old text in there, and use images like the frosting on the cake. Cheers.

Posted in newsletter | Leave a comment

Finally, A Great HTML Parser for PHP

I'm blown away by the PHP Simple HTML DOM Parser. It's like Beautiful Soup, the Python HTML/XML parser, but for PHP and has some nice jQuery-like syntax. It also seems just incredibly fast, but maybe that's also because I'm better at PHP than Python, no longer using any templating engine (was using Cheetah), and it also could be my new blazingly fast web host. I highly, highly recommend this tool if you need to do any web-scraping type stuff.

I redid the entire TWOP One-Pager using this (which also reminded of how badly this site needs a redesign). For more on that, check out this post. I added in some jQuery/ajax goodness this time around to make the page feel more responsive.

 

Posted in General Code, PHP | Leave a comment

Linux: Get Current Directory Size in MB

I forget this every time, so am posting for myself as well as others :)

On the command line, simply change into the directory you want the size of, and the following command will return the size of the directory (and all its files/sub-directories) in human readable format:

du -sh

More info on the du command and options here. Cheers.

Posted in Linux | Leave a comment

Drupal 6: Redirecting the User Destination After Registration

Scenario: An unregistered user visits a page that only logged in users can visit. Say it's this page:

http://www.your-site.com/protected/page

Drupal throws up the login form, but the URL above remains the same - good as we're going to use that. If they login, they are brought right back to this page, no problem. But what if they have to register? Assuming you have your User Settings set so that new users are logged in right away (no email confirmation, etc.), you'd of course like to redirect them back to the page they wanted originally. Instead, they just go to their new user account page, and that kinda sucks.

Figuring out a solution to this kinda sucked. After exploring numerous attempts at redirecting the form and using hook_user() - I finally just set a cookie, and blamo, it works. This needs to go into a custom module of yours:

// Implementaion of hook_user
function yourModule_user($op, &$edit, &$account, $category = NULL) {
    $refer = rtrim($_SERVER['HTTP_REFERER'], '/'); // removes any trailing slash
    $refer_array = explode('/', $refer); 
    $len = count($refer_array);
    if ($refer_array[$len - 1] == 'protected' && $refer_array[$len - 2] == 'page') {
        setcookie("YourDrupalDest", 'protected/page/', time()+200);  /* expire in 7.5 minutes */
    }
    switch ($op) {
        case 'insert':
            if ($_COOKIE["YourDrupalDest"]) {
                $_REQUEST['destination'] = 'protected/page/';
            }
            break;
 
        default:
            # code...
            break;
    }
}

Anyways, hope that helps point someone in the right, erm, destination.

Posted in Drupal | Leave a comment

Tweaking Drupal Date-Popup Format in an Exposed View

* Note this entry only pertains to the Date-Popup boxes when used in a Views filter, not a regular node-based form.

views-filter-calToday I needed to change the format of the date-popup box on an exposed views filter. It normally defaults to YYYY-MM-DD as shown to the left there. Most us 'merican folks don't like that much. Unfortunately, it only seems to be changeable via creating your own module.

Once you know how to create a Drupal module, just add this to it. With the below code, I reformat the date to the more familiar MM/DD/YYYY format for both the "from date" (min) and "to date" (max) values:

/**
* This will change the date format on all views-exposed forms
*/
function YOUR_MOD_NAME_form_views_exposed_form_alter(&$form, $form_state) {
  $form['date_filter']['min']['#date_format'] = 'm/d/Y';
  $form['date_filter']['max']['#date_format'] = 'm/d/Y';
}

As the comment says, this will change the date formatting for any view that uses these date boxes across the site, which I'm fine with. Whereas with hook_form_alter() we can target a form by incorporating the form id value into a specialized function name, all view IDs are views_exposed_form and that's just that. If you need to get more specific, you can var_dump($form) the form from within the function and glean some unique info that would allow you to target that particular form using some conditionals, again within the function.

Hope that helps someone else out! Took me a bit to figure that out - cheers.

Posted in Drupal | 1 Comment

Trouble Installing PECL’s uploadprogress On OS X – MAMP?

Note - this assumes you are running MAMP on a Mac. For this I'm using Leopard 10.5.8.

All you want to do is get this installed so you can have fancy upload bars in your Drupal 7 installation. So you follow the instructions and only get a bunch of errors. Maybe you see stuff like this:

make: *** [uploadprogress.lo] Error 1

And toward the top of your "make" you see stuff like this:

error: php.h: No such file or directory

I was seriously stumped. I knew this was probably related to having both the default version of PHP that comes with OS X enabled, as well as the MAMP version - but it's the same stuff, right? Nope - MAMP does not come with everything needed to compile a PECL installation, at least not with my setup (MAMP version 1.7.2 running PHP 5.2.x).

So what you have to whip out the command line and specifically setup your installation environment by explicitly declaring which PHP environment to use. So fire up your Terminal!

OK - MAMP does come with the phpize command, but it'll setup the wrong environment for our needs. So head into the uploadprogress directory that your downloaded and untarred, and run:

/usr/bin/phpize
./configure --with-php-config=/usr/bin/php-config

Next up:

make
sudo make install

If all went well, you should have no errors, and you'll have some output telling you the extension directory it placed uploadprogress.so in.

You'll need to open up MAMP's php.ini file and make some changes now. For me, this is in MAMP/conf/php5

Around line 428 - you'll need to put something like this in:

extension_dir = "(insert the outputted extension directory from after you ran the make install command)"

(If you're like me and already had this setup from installing xdebug, then you'll need to just move the uploadprogress.so file into the defined directory.)

Now we need to tell php to load this extension. Around line 540 or so, add this:

extension=uploadprogress.so

Now restart MAMP, and you should be all loaded up! If you head over to your Drupal status report, you should see PECL is now installed (image below, my frickin' badge of honor). Boy, hopefully this is easier on the production server!

pecl-success1

Later that day...

So looks like now that this is up and running, I've discovered that Drupal 7.0 has a bug that prevents the progress bar from showing. Hopefully we'll get this fixed in 7.1.

Later later that day...

This was actually much easier on my Red Hat production server, the commands were pretty much the same. Here it is working with Drupal 6.20:
Uploading... graphic

Posted in Drupal, OS X, PHP | Leave a comment