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:
- is the term name already a hashtag in the !title? if so, do nothing
- is the term name a word already in the !title? if so, prepend a hash to it to make it a hashtag
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | twitter-n2256651-7.patch | 5.08 KB | damienmckenna |
Comments
Comment #1
josephcheekedit grammar
Comment #2
josephcheekminor edits for clarification
Comment #3
damienmckennaComment #4
damienmckennaComment #5
damienmckennaComment #7
damienmckennaRerolled.
Comment #10
damienmckennaSo, 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.