BlogEngine to Twitter - Part 2

Published by on
Tags:

A couple of weeks ago I blogged about the BlogEngine to Twitter extension I had written. However since this time I have been playing around with it a noticed a small problem. I would write a post and publish it, but once published I would notice a small mistake. I would then edit the post and publish again. Both these publishes would send a tweet to twitter. If you noticed 2 or 3 mistakes you start to produce twitter spam and everyone you know starts to get annoyed. So I wanted to modify the extension so at the base of the Add Entry page I would have a check box that when checked would send a tweet when the item is published like so:



To get this working on your site is a very simple. We first need to add the check box to the Add Entry page. This can be found in /admin/pages/add_entry.aspx. Insert the checkbox after the other checkboxes like so (line 160)

  157       <td>

  158         <asp:CheckBox runat="server" ID="cbEnableComments" Text="<%$ Resources:labels, enableComments %>" Checked="true" TabIndex="14" />

  159         <asp:CheckBox runat="server" ID="cbPublish" Text="<%$ Resources:labels, publish %>" Checked="true" TabIndex="15" />

  160         <asp:CheckBox runat="server" ID="cbTwitter" Text="<%$ Resources:labels, twitterCheckbox %>" Checked="true" TabIndex="16" />

  161       </td>

Next we need to wire this into the save button click. Open the code behind page for the add entry page (add_entry.ascx.cs) and find the method btnSave_Click. Just after the validation check add line 194:

 

  188   private void btnSave_Click(object sender, EventArgs e)

  189   {

  190     if (!Page.IsValid)

  191       throw new InvalidOperationException("One or more validators are invalid.");

  192 

  193         //Twitter integration

  194         Twitter.SendTweet = cbTwitter.Checked;

Next open the labels.resx file found in /App_GlobalResources and add the entry"twitterCheckbox" with the value "Send as tweet".

All you need to do now is download the new Twitter.cs (3.01 kb) extension file and drop the new one into the Extension directory (/App_Code/Extensions) and you are good to go. Remember from now on a tweet won't be sent unless the "Send as tweet"  check box is checked. By default it is checked.

Happy blogging.

Add comment

 

Projects

Have you read?

Scala Operator Magic



Blogs by date