I'd like to be able to add a hashtag onto the node title that gets tweeted out. or an @tag.

How do I do this? I've tried adding the tag into the code in a few places, but the automatic urlencoding keeps goofing things up.

Where do I add this to the module?

Comments

icecreamyou’s picture

Status: Active » Fixed

It's not possible to avoid the urlencoding, but you should want it urlencoded. Otherwise it won't be recognized as a character that should be inserted into the textarea. For example, http://twitter.com/home?status=test%23tag will insert test#tag in the textarea, but http://twitter.com/home?status=test#tag will insert simply test.

bflora’s picture

Thanks for the speedy response!

Well let me rephrase that.

How do I automatically add a string into the string that gets sent to twitter? What do I need to do to get "#hashtag" to show up when they click the "Post to Twitter" link.

I refuse to believe it's impossible to do. There's got to be a way to do this.

What line of tweet.module.php do I edit and what do I add to it in order to achieve this?

I tried adding it into about 20 different spots in the module's different functions but could never get it working.

icecreamyou’s picture

Replace line 105 with this:

      $tweet .= ' '. $title .' #hashtag';

Replace line 108 with this:

      $tweet .= ' '. _tweet_get_title($nid) .' #hashtag';

And replace line 113 with this:

    $tweet .= ' #hashtag';

...replace #hashtag with whatever tag you want obviously.

That should add the tag into the 'status' query string.

bflora’s picture

Next time you're in Chicago, I will buy you a beer!

icecreamyou’s picture

Cheers! Glad it works.

bflora’s picture

Well actually, it doesn't.

I read somewhere that Drupal urlencodes any string that gets passed through an array or something. What I'm seeing when I make these edits is %23hashtag rather than #hashtag.

Is there one more line in there somewhere that we need to fix?

icecreamyou’s picture

Like I said already, it's supposed to do that, you want it to do that, in fact you need it to do that or it won't go through as part of the message.

bflora’s picture

I'm not sure I understand.

So I made those changes. Ok.

When i click on the "Post to twitter" link I get this as a URL on the "post to twitter" link

http://twitter.com/home?status=www.zmt85.th8.us%20The%20Future%20of%20Pr...

When I click that I see this in my twitter status box:

www.zmt85.th8.us The Future of Print Could be… Digital Presses | MondayNote [del.icio.us] %23JournMe

Notice that last bit? It's giving me the %23 instead of the #.

Is it possible to get the #?

See if an admin can add a hashtag of their choosing, this module gets A LOT more useful, because now it can help your site go viral by adding a little tag to stories tweeted from it.

But right now, its giving me %23hashtag instead of #hashtag

icecreamyou’s picture

Assigned: Unassigned » icecreamyou
Status: Fixed » Active

Oh, you're getting %2523 instead of%23 in the URL. It's getting encoded twice. Not sure why that would be unless you did it differently than what I suggested but I'll look into it when I get home.

icecreamyou’s picture

Status: Active » Fixed

Okay, so it turns out that the way I was using l() to create links double-urlencodes the '#' sign. Luckily there's a way around it... but instead of just giving you the code here, I added a way to add anything you want to the end of the tweet on the settings page. Tested on and committed to both the 5.x and 6.x branches, so it will be in the next release.

bflora’s picture

PERFECT. A gold star for you.

I think this little added feature will be aces. can't wait until the next release.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.