Archive for the ‘Listy’ Category

Zend Framework: Email templating with layouts & views

Wednesday, December 2nd, 2009

This is a solution that I came up with for sending out welcome emails, comment notifications, etc, with nice standardized HTML & text layouts, using a few components of the Zend Framework.

Basically you create a view (here called $renderer) and a layout ($layout), then render your views and layouts for both HTML and text versions. My file tree looks like this:

application/
	emails/
		welcome.html.phtml
		welcome.text.phtml
		layouts/
			layout.html.phtml
			layout.text.phtml

So, ‘welcome’ would be your template name, with html and text versions. The layout is what you want wrapped around either version of every email you send out (header graphics, font settings, contact info, etc).

I keep all of my mail functions in one class, creating a new function for each email that needs to be sent out regularly in an automatic fashion. You could even use this for newsletters, but I prefer more robust environments like MailChimp or CampaignMonitor for that sort of thing.

This simple function handles all the rendering, file paths, etc. It just needs to be called with the proper template name, and an array of items to be passed to the view renderer.

Here’s the meat of it:

/**
 * getMailContent
 * Renders mailer content in text and html and passes it back as an array('html'=>content,'text'=>content)
 *
 * @param string $templatename the name of the email template to use (APP/emails/[name].[format].phtml)
 * @param array $substitutions key=>value array of variables to pass to the view renderers
 * @return array
 */
public function getMailContent($templatename, $substitutions) {

    // create a view renderer and set it to app_path/emails/
    $renderer = new Zend_View();
    $renderer->setScriptPath(realpath(APPLICATION_PATH . '/emails/'));

    // create a layout object and set it to app_path/emails/layouts
    $layout = new Zend_Layout(APPLICATION_PATH . '/emails/layouts/');
    $layout->setView($renderer); // this probably isn't even necessary

    // assign all substitutions (e.g. view variables) to the view renderer
    foreach ($substitutions as $key => $sub) $renderer->$key = $sub;

    $output = array(); // output array        

    // render text version of template & assign to output['text']
    $layout->content = $renderer->render($templatename . '.text.phtml');
    $layout->setLayout('layout.text');
    $output['text'] = $layout->render();

    // render html version of template & assign to output['html']
    $layout->content = $renderer->render($templatename . '.html.phtml');
    $layout->setLayout('layout.html');
    $output['html'] = $layout->render();

    // all done, return output
    return $output;

}

Nice and simple, huh? All you need to do is call it and then assign the output to your Zend_Mail object like so:

        $bodies = $this->getMailContent('new_comment', array(
            'comment' => $comment,
            'comment_list' => $comment_list,
            'comment_user' => $comment_user,
            'list_owner' => $list_owner
        ));
        $mail->setBodyHtml($bodies['html']);
        $mail->setBodyText($bodies['text']);

Your email template accesses the variables passed to it just as it would a normal view script:

$this->[variable]

Commentary / suggestions / etc welcome in comments.

Post to Twitter Tweet This Post Post to Digg Digg This Post Post to Reddit Reddit Post to StumbleUpon Stumble This Post

Listy.us is live, still a work in progress

Tuesday, November 24th, 2009

For those that have been following my work by means other than my blog (twitter, facebook), you already know that my big project, www.listy.us, is alive and kicking. I’ve been meaning to write an actual blog post about it for some time, since it would seem I forgot to do that back in September when the site actually launched. It’s improved a lot since then, I think.

Listy.us is a AJAXified table-based list making application. You create a list, edit it by clicking fields and entering your data, and it’s updated as you tab from item to item. It’s open-ended enough that you can use it for just about any kind of list you want to make. I designed Listy.us as an application that I would personally enjoy using, and I do use it. My user profile shows some of the lists I’ve made on the site so far – the ones I’ve marked as public, at least.

There have been a lot of features cut out in order to get the application on the internet and getting feedback. User groups, templates, and hypertemplates — templates with extra functionality such as pulling down extra data from outside sources — are all still on the list of “things to put back in ASAP.”

There are a lot of different things in this project to write about, so I’m going to try and break it up into a lot of smaller blog posts over the next couple weeks. What do you want to hear about? The marketing? Writing the editor javascript? The decision to remove advertising? Design revisions? Bits and pieces of Zend Framework code used on the backend?

Next post, I think I’ll share how I’m using some Zend Framework components to create a mail templating system for new user emails, comment notifications, and the like.

Post to Twitter Tweet This Post Post to Digg Digg This Post Post to Reddit Reddit Post to StumbleUpon Stumble This Post

Why Chrome Frame is a Necessity

Thursday, October 1st, 2009

With a ton of users being granted access to Google Wave, and Wave suggesting the installation of Chrome Frame, there’s been a bit of griping from Microsoft (and others, but I suspect mostly Microsoft) about not liking the ability for the content to choose the browser agent. I can understand why folks would be irked by this, I really can. It messes with their software

However, as a web designer/developer, I can say for a fact that it is absolutely necessary, and it is Microsoft’s own damned fault that it has come to this. Practically every other browser is up to date, or at least trying to be, with recent web standards. Those that follow my work may have noticed that Listy.us makes use of a bit of CSS3 and is set up in HTML5 for future expansion. I would love to use all the latest bells and whistles of HTML5/CSS3. Full HTML5 support allows awesome web apps like Google Wave. CSS3, among other things, lets you do cool stuff like drop shadows and curved corners without messy hacks and semantics nightmares. I want to use these things, and I’d imagine most other developers and designers do as well. The web would be a better place.

The catch? 34% of my visitors use Internet Explorer. That’s 34% of users that see the site with hard square edges, slow javascript, funky css behaviors, etc. Of those 34%,  43% are still using IE6. IE6 doesn’t even support PNG transparency without a hack. As a lone developer trying to get a web app up to commercial viability, I find myself focusing on development and letting the site degrade nicely (or as well as possible) to IE users – it still works (as long as you have javascript enabled – risky in IE), it’s just not as pretty.

So, why is Google Chrome Frame a necessity? Because it fixes the problem. Because it lets all the IE users out there experience sites like Google Wave the way they’re meant to be experienced. It exists because of those 34% of users still using IE, those 34%*43% still using old-and-broken IE6. It’s Google’s way of saying “Well, crap, we’re ready to go. If you can’t get your browser up to speed, we’ll do it for you.”

I fully support it, and if MS doesn’t get their act together, I’ll be encouraging the use of Chrome Frame on my own projects.

Now, what can Microsoft do about it? Obviously Microsoft has no interest in prolonging the life of IE6, but supporting it until 2014 doesn’t do anyone a service. They’re even offering charitable donations for each upgrade from IE6 (personally, I would’ve skipped the background music, guys). The problem with continuing to support old-and-broken technology like IE6 is that folks like Google and Mozilla will begin to create products like Google Chrome Frame because the web is being held back by Internet Explorer.

I’ll bottom line it for Microsoft: It is next to impossible to find a web designer/developer that does not loathe Internet Explorer with every fiber of their being. This is a problem. It needs to be dealt with. The rapid growth of technology means you should not support an 8-year-old browser that has no business being used on modern websites. If you don’t deal with it, someone else will.

Post to Twitter Tweet This Post Post to Digg Digg This Post Post to Reddit Reddit Post to StumbleUpon Stumble This Post

Implementing Web Apps as Finite State Machines

Saturday, July 11th, 2009

The revelation that a web application meshes well with the design pattern of a Finite-State Machine (wikipedia link) isn’t really new. It’s discussed in a few other places on the web, usually in a scholarly capacity – the google search returns a lot of articles and research papers. Still, this struck me as something that really should be taught to every fledgeling web developer.

Wikipedia defines an FSM as “a model of behavior composed of a finite number of states, transitions between those states, and actions.

In other words, it’s a map of how your application works, with consideration for how you get from point A to B to C. The pattern can be used to design simple to very complicated web applications. Listy.us is currently being built around a fairly simple FSM pattern where every state ultimately  returns to an idle state when finished. Entering the state sets everything up: dynamic elements, events, etc. Exiting tears down the event namespace (see jQuery – Namespaced events) and does any data saving.

You can read about FSMs as applied to game development at this site (it’s more readable than the wiki entry). In fact, if the area of artificial intelligence and/or game development interests you, I’d recommend picking up the book by that site’s author.

Simple example:
start -> state:idle (enter, run)
-> (click field) -> transition:editMode (exit idle, enter editMode, run editMode)
-> (click out/keypress) -> transition:idle (exit editMode, enter idle, run idle)

Maybe I’ll clean up the FSM design and post it sometime.

Post to Twitter Tweet This Post Post to Digg Digg This Post Post to Reddit Reddit Post to StumbleUpon Stumble This Post

Marketing’s Bad Name

Tuesday, June 9th, 2009

I’d like to share an experience I had a few years ago: I was at the supermarket, making smalltalk with the cashier, and she asked what I do for a living. I answered truthfully: “I work in marketing.”

I’ve never seen someone go from friendly and cheerful to all business so quickly. From the reaction, you’d think I’d said “I vivisect puppies.” I haven’t told someone “I work in marketing” since – at least not out of context.

The thing is, they’re partly justified. Think of marketing as a consumer and the first things that come to mind are probably an inbox full of spam, copious handfuls of junk mail (physical spam), phone calls while you’re eating dinner, commercials interrupting your night on the couch, and so on. Hell, why stop there? Don’t forget the bots posting nonsensical links in your blogs, or the bots and slimy “marketers” on Twitter (those guys with 50-100X more “following” than “followers”).

Yeah. Nowadays you’d better clarify: “I work in marketing, but I’m not one of the guys you hate.” Luckily these days I can say “I run my own business through websites,” and folks don’t always realize that that job description includes marketing. Being an entrepreneur is much more smalltalk-friendly than working in marketing.

Rule number 1 of modern marketing: Don’t be a dick.

Don’t send people any marketing materials they didn’t ask for: No spam, no junk mail. Blog comment spam, twitter spammers, etc, are Internet extensions of the old-and-broken mechanic of “I will interrupt people, steal their attention and valuable time, and they will buy my product.” People don’t react like that anymore. They hate you for it. I know I do. Don’t do it.

My projects will never spam you. I refuse to be that guy.

Listy.us will feature Google ads for non-paid accounts. Context sensitivity is it’s main selling point; If I have no choice but to show ads to support a project, I’m going to make sure those ads are something you want to see. As soon as a site can stand on its own without ads, the ads will be gone.

Post to Twitter Tweet This Post Post to Digg Digg This Post Post to Reddit Reddit Post to StumbleUpon Stumble This Post

Virtual Currency and Freemium Services

Sunday, April 19th, 2009

Here’s a monetization idea I’ve been playing with since participating in post-GDC “Idea Exchange: Emerging Trends in Game Development,” a sort of virtual conference that was held in both Metaplace and Second Life via a chat bridge between the two (pretty cool in itself). You can see a side-by-side screen comparison here.

During that chat, a lot of ideas were covered, and Raph briefly touched on how he thought offer-based marketing was a big new trend at GDC. Here’s the chat log, edited for relevance:

(more…)

Post to Twitter Tweet This Post Post to Digg Digg This Post Post to Reddit Reddit Post to StumbleUpon Stumble This Post

New Theme and a Project Name

Tuesday, April 7th, 2009

The new blog theme has been live for a couple days now. It still has a few tweaks to be done (single post page lacks styles for the next/previous links, for example), possibly some component rearranging, but it’s okay for now. The look and feel now matches the background on my twitter page, or you could say the background on the twitter page now matches the blog, as it was the blog that was designed first.

This is probably my first real attempt at a grid-based layout. Vertically it falls short of perfect baseline alignment, simply because I didn’t feel it was worth the effort to get it perfect. This is a blog. If it were a corporate product page, then yes, it would be worth the trouble to get everything in a perfect rhythm, but it’s not.

Also, I have not tested this in IE 6 or 7. Out of curiosity, I tested it in 8 a few seconds ago and it looks fine. Obviously, ignoring IE isn’t a luxury I can afford in the future, but in the current “I just want to get this WP theme done so I’m using something more appropriate than a public theme” context, it works.

(more…)

Post to Twitter Tweet This Post Post to Digg Digg This Post Post to Reddit Reddit Post to StumbleUpon Stumble This Post

A Workspace Photo

Saturday, March 21st, 2009

I spent about 4 hours today on modeling the database for one project. Other time was spent reading up on the Zend framework in order to lighten my load a bit—I figure a couple days learning it will save me weeks of programming work. I also took half an hour to read up on all the manual settings on my camera, and celebrated my newfound knowledge with a photo of my (almost) newly cleaned workspace:

The desk surface in my office

The desk surface in my office

I’ve missed having a camera with manual settings. My most recent before this one didn’t have a fully-manual mode, or manual focus, and was therefore only good for tourist photography—point and click but nothing artsy. New one has a very nice manual mode: It’s a Canon Powershot A590. It’s no DSLR, but for the money (less than $100), it’s pretty damned nice. I still need to do a little Photoshop tweaking to perfect the image, though. 

I guess I should set up a Flickr account, huh?

Post to Twitter Tweet This Post Post to Digg Digg This Post Post to Reddit Reddit Post to StumbleUpon Stumble This Post