Auto post to Twitter when publishing in MODx

I was reading the MODx forums and came across an idea/request for the ability to auto post to Twitter when you publish a new document. Having spent some time going over Twitters api I knew this would be a pretty easy task, so I wrote a quick plugin to make it work. This tutorial is for MODx Evolution.

Features

  • A template can be used for your message with placeholders for the pagetitle and the link.
  • Links can be shortened with either TinyUrl, Digg, Is.gdBit.ly (requires an account).
  • When generating the message the length is checked so that it will not exceed 140 characters.
  • This plugin uses PHP5 or greater and requires curl.

Install Instructions

  1. Download the files from here: Twitter Status.

  2. Extract the files into your MODx install directory (i.e. assets/plugins/TwitterStatus).

  3. Copy the contents of the file TwitterStatus.plugin.php into a new plugin named TwitterStatus.

  4. In the comments in the file TwitterStatus.plugin.php there are configuration parameters. Copy these parameters into Plugin Configuration textarea.

  5. Tab/Click out of the configuration field and update the configuration options with your custom settings. If you want to use Bit.ly you must specify your account information (this is now in the BitlyService.class.php file).

  6. On system events tab check the event OnDocPublished.

  7. Save the plugin and you are now ready to use it.

Notes

Due to how MODx handles the event OnDocPublished, the only way to get this to fire is to right click a document in the tree and select publish. If you save/edit a document the event will not be fired. For this plugin this is actually a good thing so that you do not end up with multiple tweets for the same page.

I am thinking about adding a template variable to each page that gets set when you update your Twitter status. This would then be another check to prevent a document from being sent to Twitter more than once.

Any additional suggestions/feature request are welcome. I have not done a lot of testing with this, but have it up and running on my site.

Update - 04/07/2009 - v1.1

  • Added support for Url shorteners: Is.gd & Digg
  • Added fail over to file_get_contents for servers without cUrl (needs testing)
  • Seperated the URL shorteners into seperate classes so it is easy to plugin new ones.

Comments (0)



This thread has been closed from taking new comments.
logoLeaving tracks across the web.