Programmatically attaching image files to nodes in Drupal 7

I found the answer on Stackoverflow.

Simple, right? And this works fine if you’re attaching a brand new image.

I found the answer on Stackoverflow

I found the answer on Stackoverflow.

Simple, right? And this works fine if you’re attaching a brand new image. However, if you’re updating an image you’ll find that the styles don’t update after calling node_save(), and the image will not show up correctly on your site. You need one extra step: call image_path_flush() to regenerate that image’s styles before calling node_save().

//if the image is being updated, flush all its styles
image_path_flush($node->field_image['und'][0]->uri);

Reflections

A couple pics of stuff reflected in downtown Vancouver highrises.

A couple pics of stuff reflected in downtown Vancouver highrises.

The Block Building on Granville Street. I forget what the other building is. Scotiabank?

Block Building

Soft sunset clouds, taken near Georgia and Denman. It was a fine evening, and the light was just perfect.

Soft sunset clouds

Freelance Camp 2012

I attended my second Freelance Camp this weekend. I won’t try to summarise the excellent talks, because I’m still digesting all the nuggets of wisdom and working to put them in practice. I will say that I met some amazing folks who are doing amazing things, and I feel more energised than ever about my freelancing career.

I attended my second Freelance Camp this weekend. I won’t try to summarise the excellent talks, because I’m still digesting all the nuggets of wisdom and pondering all the great tools I learned about and working to put it all in practice. I will say that I met some amazing folks who are doing amazing things, and I feel more energised than ever about my freelancing career.

And of course, since I pretty much never come down to New West except for FLC, I snapped a few photos around the quay.

The world's largest tin soldier

Three Bridges

And a cute photo of a sparrow I took the day before. Such a pretty little thing!

Sparrow in the morning

Dawn and Dusk

My bedroom window, lit by the setting sun. Now that I think about it, I wonder at what hours and times of years it’s lit like that. Never really paid much attention to the Stonehenge that is the West End.

My bedroom window, lit by the setting sun. Now that I think about it, I wonder at what hours and times of years it’s lit like that. Never really paid much attention to the Stonehenge that is the West End. Food for thought, for sure.

My bedroom curtains

A pretty shot of Yaletown, from near Cambie & Pacific. Thank goodness I had my camera with me!

Yaletown dusk

The Sheraton Wall Centre towers, lightly kissed by the morning sun. This late in the year, I go for my workout just as the sun comes up.

Sheraton Wall Centre towers

The Storm Crow

Went to the Storm Crow, a nerd-themed pub on Commercial, for a friend’s birthday. The food was so-so, but cheap, so no complaints there. The real draw is the atmosphere: D&D-style posters, and card/board games to play. Plus, a truly astounding collection of “Choose Your Adventure” books.

Went to the Storm Crow, a nerd-themed pub on Commercial, for a friend’s birthday. The food was so-so, but cheap, so no complaints there. The real draw is the atmosphere: D&D-style posters, and card/board games to play. Plus, a truly astounding collection of “Choose Your Adventure” books. A few photos of the evening:

On the way there:

Leaf turning red

A bench

Playing Building an Elder God:

Building an Elder God

Ubercart 3: Programmatically submitting an order from Canada

I’ve been working on a project that, among other things, involves purchasing a particular item with one click: the order is created, payment information is added (how it’s stored is not important here) and the order is submitted, all automatically.

I’ve been working on a project that, among other things, involves purchasing a particular item with one click: the order is created, payment information is added (how it’s stored is not important here) and the order is submitted, all automatically. After a bit of flailing about on my own, I found this post on the Ubercart forums explaining how it’s done, and it totally saved my bacon. In short:

  1. add item to cart using uc_cart_add_item()
  2. populate and submit form ‘uc_cart_checkout_form’
  3. if things are okay, populate and submit form ‘uc_cart_checkout_review_form’ (which actually submits the order)

However, it’s not quite complete. 3 things are missing, in fact, which took me a bit of experimentation to figure out:

1) You need to enter the credit card info in the form_state array, not just in $_POST

The post says to do this:

// Define the credit card information in the $_POST directly.
  // See uc_payment_method_credit($op = 'cart-process') for why this is necessary.
 

$_POST['cc_number']    = 'XXXXXXXXXXXXXXXX';
  $_POST['cc_exp_month'] = 'XX';
  $_POST['cc_exp_year']  = 'XXXX';
  $_POST['cc_cvv']       = 'XXX';

But that didn’t work for me. It looks like you also need to enter it in the form_state, like so

$uc_cart_checkout_form_state['values']['panes']['payment']['details']['cc_number'] = 'XXXXXXXXXXXXXXXX';
	$uc_cart_checkout_form_state['values']['panes']['payment']['details']['cc_exp_month'] = 'XX';
	$uc_cart_checkout_form_state['values']['panes']['payment']['details']['cc_exp_year'] = 'XXXX';
	$uc_cart_checkout_form_state['values']['panes']['payment']['details']['cc_cvv'] = 'XXX';

2) Entering an address not in the store default country

(This post title says “Canada” because the default default store country is the US and that’s what I was testing with.)

Here’s the problem: if you try to enter a Canadian province in the $uc_cart_checkout_form_state['values']['panes']['billing']['billing_zone'] field, the ‘uc_cart_checkout_form’ form submission will fail with the following error message:

An illegal choice has been detected. Please contact the site administrator

Why? Because when the form is built, the allowed Zone values are based on the selected country. If all you can select are US States but you enter “BC” anyway, Drupal will not accept it, and that’s what the error message means.

Here’s the solution: the billing / shipping address panes are built based on the order country, and by default uc_order_new() creates an order with the billing and shipping countries set to the store default. So, all you need to do is set that field to a different value:

//after $order = uc_order_new()
$order->billing_country = 124; // Canada, or same value entered in $uc_cart_checkout_form_state['values']['panes']['billing']['billing_country']
//do the same for shipping country

This will populate the dropdown with Canadian provinces, and allow you to enter a province in $uc_cart_checkout_form_state['values']['panes']['billing']['billing_zone']

3) If you’re not starting from the cart, you need to change the redirection checks

The code checks if drupal_form_submit('uc_cart_checkout_form', $uc_cart_checkout_form_state) finished correctly like this:

if ($uc_cart_checkout_form_state['redirect'] == 'cart/checkout/review') {
    // We're good to move forward!!

And similarly for drupal_form_submit('uc_cart_checkout_review_form', $uc_cart_checkout_review_form_state)

Function uc_cart_checkout_form_submit($form, &$form_state) (defined in uc_cart/uc_cart.pages.inc) sets the form_state redirect:

function uc_cart_checkout_form_submit($form, &$form_state) {
  if ($form_state['checkout_valid'] === FALSE) {
    $url = $form_state['storage']['base_path'] . '/checkout';
  }
  else {
    $url = $form_state['storage']['base_path'] . '/checkout/review';
    $_SESSION['uc_checkout'][$form_state['storage']['order']->order_id]['do_review'] = TRUE;
  }

  unset($form_state['checkout_valid']);

  $form_state['redirect'] = $url;
}

If you’re starting from the cart, then $form_state['storage']['base_path'] will be equal to ‘cart’. But if your goal is a 1-click purchase, chances are you’ll be starting on a completely different page, and the redirect will be different as well. So you’ve got a couple of options:

  • Change $form_state['storage']['base_path'] somehow (is that possible?)
  • If you know the path of the page you started on, use it in the check:
    if ($uc_cart_checkout_form_state['redirect'] == 'yourpath/checkout/review') {
        // We're good to move forward!!
    
  • Be a little more flexible, and only check the last part:
    if (strpos($uc_cart_checkout_form_state['redirect'],'checkout/review') !== FALSE) {
        // We're good to move forward!!
    

Vancouver Queer Film Festival 2012: Final Thoughts

Well, another festival has come and gone. Some great movies were seen, some wonderful folks were met or caught up with. Let’s recap, by the numbers:

Well, another amazing festival has come and gone. Great movies were seen, wonderful folks were met or caught up with. Let’s recap, by the numbers:

Number of shows I saw: 10*. I had planned to see 18, but I was feeling a bit under the weather for most of the festival, so I had to slow way down.

[* Well, more like 9½, since I left halfway through Romeos.]

Number of awards I won: The new Cineplex Golden Popcorn Award, for being a solid supporter of the festival on Twitter, and especially tweeting my reviews. You could have knocked me over with a feather! I only wrote those reviews for my own pleasure and to keep up my blogging, but it sure is nice that people are enjoying them! I got a VQFF t-shirt, a VQFF mug, and a $50 Cineplex Odeon gift card. Nice! Also, a small amount of fame since I was called up in front of the audience during the closing gala, and mentioned in a few articles.

Number of sites my 2012 VQFF reviews are posted on: New this year, all my 2012 reviews except Romeos have been reposted on GayVancouver. net. Thank you Mark!

Favourite feature-length film: It’s a three-way tie this year!

  • Nate & Margaret: because who can resist Tyler Ross? Plus, he and Natalie West make a dynamite team.
  • La fille de Montréal: sweet and moving, and made me all nostalgic for everything French-Canadian.
  • Mia: obviously!

Favourite short film: A tie between Insert Credit (shown in The Coast is Queer) and I Don’t Want to Go Back Alone / Eu Não Quero Voltar Sozinho (shown in Head of the Class).

Movies I would have liked to see but didn’t:

  • I Want Your Love. I was at the theatre and all ready to see it, but after Nate & Margaret a couple of friends got to chatting with the director, Nathan Adloff, and invited him to the Queer Arts Festival closing party at the Roundhouse. They invited me along too and really, how could I pass that up?
  • The Falls. Bad planning on my part: I got there only five minutes before showtime, saw the length of the passholder hope line, and decided to hang out at Golden Age Collectables until The Green. I didn’t get to catch the second showing on the 26th either.
  • Revoir Julie. Sadly, I was exhausted, so I had to go home after La fille de Montréal.
  • From Coast to Coast is Queer
  • Private Romeo. I had a BBQ on Saturday, but since those two shows were happening at the same time in different theatres, I would have had to make a choice. I think I would have gone to see Private Romeo, since the VGVA was sponsoring it.

Vancouver Queer Film Festival Review: Dirty Girl

Sassy, brassy, all-around retro-flavoured fun! This story of two unlikely friends—the school’s “popular” girl and the withdrawn gay guy—is a celebration of life, love, and 80’s music. Though it does have some dramatic moments, Dirty Girl is mostly a comedy that made me want to laugh and dance, a fantastic conclusion to the 24th VQFF.

Sassy, brassy, all-around retro-flavoured fun! This story of two unlikely friends—the school’s “popular” girl and the withdrawn gay guy—is a celebration of life, love, and 80’s music. Though it does have some dramatic moments, Dirty Girl is mostly a comedy that made me want to laugh and dance, a fantastic conclusion to the 24th VQFF.

The year is 1987. The place is a small-town high school in Oklahoma. After mouthing off to her teacher one too many times, “dirty girl” Danielle is placed in the “Challengers” program for difficult or special-needs students. Here she meets Clarke, hoodied and alone, content to be as invisible as possible and let school pass him by. Paired up to raise a bag of flour as their child, they gradually bond. When Danielle gets a lead on the location of her birth father (until then a mystery), and Clarke’s parents find male centerfolds under his mattress, the two decide to hit the road.

Danielle and Clarke bond and bicker some more, and have your typical road trip adventures, with a gay twist; he picks up a handsome cowboy stripper at a rest stop who gives them a free show and shows Clarke a good time. Then after running out of money, Danielle decides to enter a stripping contest at a local bar. Her moves are good, but the crowd is totally unresponsive. Finally, Clarke puts 2 and 2 together: this is a gay bar! But how will they win that $50 prize now? No problem! Clarke can perform! Though reluctant, he remembers some of the stripper’s lessons and successfully channels his inner diva to win the prize!

Unfortunately, that’s when Clarke’s father catches up with them, and drags Clarke off to military school. Danielle goes on to California to see her birth father. It doesn’t go as well as she’d hoped. He’s a nice enough guy, but already has a family, and isn’t interested in a new teenage daughter. Danielle is devastated at first, but accepts that she gave it her all, and when that’s not enough, you just have to roll with the punches.

We catch up with the teens a few months later. Danielle seems to have given up or at least toned down her “dirty girl” ways, branching out into dance and song. During a heartbreaking rendition of “Don’t Cry Out Loud” for a talent show, who should appear to help her with the chorus? It’s Clarke, looking damn fine in his spiffy uniform! Military school hasn’t broken his spirit, it seems. So the two reconnect, and everybody lives happily ever after.

That’s Dirty Girl, a fantastic ride through 1980’s America as seen through a queer lens. The funny bits were very, very funny—I haven’t even mentioned Clarke and Danielle’s “child” (ie: the bag of flour) which accompanied them on their travels, or all the creepy-funny interactions with Danielle’s mom’s Mormon boyfriend and his children—and the dramatic bits were well done and gripping. As lighthearted as the overall story is, all the main characters have fully fleshed-out personalities, with realistic conflicts and drives.

PS: this movie had some serious star power! Mila Jovovich, Dwight Yoakam, Gary Grubbs, Mary Steenburgen and Tim McGraw? Yes, they were all in this movie. Amazing.

PPS: this is a bit out of left field, but I wonder if protagonists’ mothers will eventually end up together? Clarke’s mother doesn’t seem to like her husband much, and he moves out by the end; Danielle’s mother was only dating that Mormon guy because she feels she needs to get married to someone decent. And in the very last scene, during Danielle’s performance, they were holding hands. I’m just saying…

Vancouver Queer Film Festival Review: The Coast is Queer

A wide selection of truly amazing shorts! Ranging from 1 to 10–12 minutes in length, they cover the gamut from silly to sexy to dead serious. I am always amazed at the amazing filmmakers that call Vancouver home.

A wide selection of truly amazing shorts! Ranging from 1 to 10–12 minutes in length, they cover the gamut from silly to sexy to dead serious. I am always amazed at the excellent filmmakers that call Vancouver home.

Treviano e la Luna

What do you get when you mix bears, opera, coffee and tips on facial grooming? This latest offering by Clark Nikolai is far more ambitious than his previous work (like last year’s silent short Lord Cockworthy) in content, style and camera work, but just as naughty and hilarious. Also, from what little I know the Italian dialog does match the subtitles, so bonus points there!

PS: Treviano e la Luna earned Clark the inaugural GayVancouver.Net Coast is Queer award, celebrating local queer filmmakers!

A Rendezvous

What looks like an awkward first date between two shy women is revealed to be something very different, as they jump together off a rooftop. This was an odd and disturbing film, with no obvious queer content, but I don’t believe that’s necessary to be included in the Queer Film Fest!

Sanity for Beginners

This short, written and directed by, and starring Jan Derbyshire, tells us that sanity isn’t as clear-cut as some professionals think. Again, no actual queer content, which just speaks to the diversity of our queer cinema!

The Other Mother

Pregnancy is a stressful time. It’s just as stressful when your partner’s pregnant, you’re unemployed and you have to choose between gainful employment or following your passion. A funny and touching look at lesbian parenting, and choices everyone has to make, lesbian or not. As a skeptic, I also liked the little digs at New-agey magical thinking. But since things worked out for the best, who knows? Maybe the universe really is looking out for our heroines.

Sunday Morning

Sometimes, you can’t just let go of your old community. And you shouldn’t ask your lover to do it either. An ex-priest, kicked out of his church, and his new lover, argue about why he should still be friendly with some of his old parishioners. Just because the church hierarchy doesn’t want him, that doesn’t negate the fact that (a) he loved his calling, and the kids under his charge, and (b) the kids themselves miss him and want him back.

In The Middle

A woman has to choose between two lovers, one male (and abusive, I think), one female. Which way will she go?

Choices

A simple little film about a woman dumping her boyfriend for an androgynous woman. Quick, sweet, and to the point.

Hooked Up (Reunion)

A young man realises his latest hookup was actually a guy who bashed him in the past. His revenge? Take discreet webcam shots of the two of them making out, then post them on the Web. Creepy and scary, and the only short this year to deal with a really serious topic like bashing.

Insert Credit

Queer nerds represent! This gorgeous animated short by David Nguyen, is an autobiography in the style of an old-school side-scrolling console game: dealing with high school crap, trying to connect with his father, moving to Vancouver, fighting mooses and laser-beam-shooting maple leaves, and finding true close friends.

Insert Credit earned David the Gerry Brunet Memorial Award. Congratulations!

Supa Stition

A funky drag-themed house music video by Michael Venus. The music’s not really my cup of tea, but it was pretty fun.

Freewheel and Fixie

Free-form poetry put to video, celebrating Vancouver’s queer cyclists and the bike culture.

Queers in Canoes

This ultra-short film is about… well, queers in canoes. Shot on a camping trip then later edited and released to hilarious effect. Starring Jen Crothers as the screaming woman in the canoe.

Anniversary

What to get your boyfriend for your one year anniversary? Flowers and candy just won’t do, you need to think outside the box! A sweet little comedy that left me smiling.