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.

Features

Install Instructions

  1. Download the files from the link in the right side-bar.

  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
If you have trouble reading the code, click on the code itself to generate a new random code.
Security Code:
 
Required fields are marked with *.
Showing comments 1 to 10 of 15 | Next | Last
Comment

15

Thanks! Matt Sun March 14, 2010, 16:44:30

This looks like a sweet plugin. Running Evolution, and this will be very easy to customize. Thanks a lot!

Comment

14

Adding Twitter Status to my site Michael Sat February 27, 2010, 03:30:11

Hi I have followed your instruction above I was wondering what call I have to add to me chunk to allow Twitter Status to appear similar to the one you have on your site on the top right...

Thanks for this plugin i hope i can get it to work like yours

Comment

13

Thx style-nes Wed February 24, 2010, 23:00:08

Thx for plugins! Nice work!

Comment

12

Select a Blog folder? Simon Brown Thu February 18, 2010, 07:30:01

Is it possible to tell the Plugin to only publish twitter feeds from a desired directory?... Example on publish twitter feeds from the Blog directory in MODx

Comment

11

Multiple Placeholders James Fri February 12, 2010, 17:33:32

How do I include longtitle in addition to pagetitle? Below is what I have tried and it still doesn't work.

Thank you.

PHP:
public function parseTemplate($template,$longtitle,$pagetitle,$link) {
$placeholders = array('','','');
$templateLength = strlen($template) - strlen($placholders[0]) - strlen($placeholders[1]) - strlen($placeholders[2]);

if ($templateLength < 1 || $templateLength > 140) {
$template = ' ';
$templateLength = strlen($template) - strlen($placholders[0]) - strlen($placeholders[1]) - strlen($placeholders[2]);
}

$fullLength = $templateLength + strlen($longtitle) + strlen($pagetitle) + strlen($link);

if ($fullLength > 140) {
$extraChars = 140 - $fullLength;
$pagetitle = substr($pagetitle, 0, ($extraChars + 3) * -1) . '...';
$longtitle = substr($longtitle, 0, ($extraChars + 3) * -1) . '...';
}

$values = array($longtitle,$pagetitle,$link);
return str_replace($placeholders, $values, $template);
}
}

Plugin:
$message = $ts->parseTemplate($template,$pageInfo['longtitle'],$pageInfo['pagetitle'],$link);

Comment

10

thanks digitalbart Tue December 22, 2009, 12:46:09

Nice plugin this works great! Thanks for it. Do you know if there is a facebook plugin for modx of similar nature?

Comment

9

Re: stacy Wed December 09, 2009, 21:53:33

I want to remove Name: input at my template. How can i do?

Comment

8

this plugin stops working on modx 1.0.2 goldsky Sun November 08, 2009, 23:58:24

I just upgraded to modx 1.0.2, and this plugin seems stop working.

Comment

7

Re: user Fri September 18, 2009, 08:50:21

Hi,
nice Plugin. Is it possible to use it with this plugin: http://modxcms.com/extras/package/572

Its better to use your own "tinyurl-service" than other.

Comment

6

Brilliant plugin! Maarten Wolzak Wed September 09, 2009, 05:02:26

Thanks Kyle!
Another great piece of beautiful code. Very easy to hack to my needs :-)

Implemented it on handleOpenURL.com

Showing comments 1 to 10 of 15 | Next | Last
logoLeaving tracks across the web.