Hello,

I am loving twitter.module, especially twitter_post, but wanted to have it take tags that I would add to my blog posts and turn them into hashtags in the tweet. So I wrote a patch to do this for 7.x-5.8, and am currently using it on my blog at www.cheek.com.

Here are some examples of what it does:

  • 'test post' with drupal tags of 'readme' becomes 'test post #readme' (tag is added)
  • 'test post, readme' with drupal tags of 'readme' becomes 'test post, #readme' (existing word in title is tagged)
  • 'test post, #readme' with drupal tags of 'readme' becomes 'test post, #readme' (existing word already tagged in title is left alone)

It does this by adding a 'Vocabulary name' field to /admin/config/services/twitter/post that allows an admin user to select one vocabulary name to use for hashtagging. If one is selected, the code turns term names from that vocabulary into hashtags, populating a !hashtags replacement string in the $replacements string array.

For each term in the specified vocab, as shown above, it checks three things before posting the tweet:

  1. is the term name already a hashtag in the !title? if so, do nothing
  2. is the term name a word already in the !title? if so, prepend a hash to it to make it a hashtag
  3. otherwise, add the tag (with a hash prepended) to the !hashtags string for replacement inside the $status

It also changes the default format string to 'New post: !title !hashtags !tinyurl' (no updates to existing format strings) and also trims and squeezes spaces from the $status. No changes were made to permissions or the security model.

Please consider this for inclusion in the 7.x-5.x-dev branches and future branches.

Comments

josephcheek’s picture

Issue summary: View changes

edit grammar

josephcheek’s picture

Issue summary: View changes

minor edits for clarification

damienmckenna’s picture

Version: 7.x-5.8 » 7.x-5.x-dev
damienmckenna’s picture

Status: Needs review » Needs work
damienmckenna’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, twitter_hashtags.patch, failed testing.

damienmckenna’s picture

Status: Needs work » Needs review
StatusFileSize
new5.08 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 7: twitter-n2256651-7.patch, failed testing.

damienmckenna’s picture

Status: Needs work » Closed (won't fix)

So, thinking this one through some more, this is not functionality I think should be committed to the module. You should be able to do this using hook_twitter_statuses_alter() and just parsing the text before it's saved.