A Better Twitter Widget for BlogEngine.NET 1.6

by Al Bsharah | 02.02.2010 10:04 PM | Comments (11)

I made some tweaks today to the new Twitter Widget that was released with BlogEngine.NET 1.6.  I noticed that @User and #Hash tags were not linked up, so I fixed that.

Below is the code you need to modify.  Any GREEN code is new, any BLACK code is code that was already there.  Should be pretty easy to cut/paste it in place.

Option #1: Download the widget.ascx.cs.zip (2.89 kb) file directly, drop it into your site, refresh.

Option #2: Make the following changes in the file: <root>/Widgets/Twitter/widget.ascx.cs:

Comment this out, or remove it all-together:

//if (title.Contains("@"))
//    continue;

Add the two lines shown here:

twit.Title = ResolveLinks(title);
twit.Title = ResolveUserLinks(twit.Title);
twit.Title = ResolveHashLinks(twit.Title);

Add the green lines below:

    //URL
    private static readonly Regex regex = new Regex("((http://|https://|www\\.)([A-Z0-9.\\-]{1,})\\.[0-9A-Z?;~&\\(\\)#,=\\-_\\./\\+]{2,})", RegexOptions.Compiled | RegexOptions.IgnoreCase);
    private const string link = "<a href=\"{0}{1}\" rel=\"nofollow\">{1}</a>";
    //@User
    private static readonly Regex regex2 = new Regex("@[a-zA-Z0-9]*", RegexOptions.Compiled | RegexOptions.IgnoreCase);
    private const string link2 = "<a href=\"{0}{1}\" rel=\"nofollow\">{2}</a>";
    //#Hash
    private static readonly Regex regex3 = new Regex("#[a-zA-Z0-9]*", RegexOptions.Compiled | RegexOptions.IgnoreCase);
    private const string link3 = "<a href=\"{0}{1}\" rel=\"nofollow\">{2}</a>";

Add the two green functions below:

    /// <summary>
    /// The event handler that is triggered every time a comment is served to a client.
    /// </summary>
    private string ResolveLinks(string body)
    {
        return regex.Replace(body, new MatchEvaluator(Evaluator));
    }
    private string ResolveUserLinks(string body)
    {
        return regex2.Replace(body, new MatchEvaluator(EvaluatorUser));       
    }
    private string ResolveHashLinks(string body)
    {
        return regex3.Replace(body, new MatchEvaluator(EvaluatorHash));
    }

    /// <summary>
    /// Evaluates the replacement for each link match.
    /// </summary>
    public string Evaluator(Match match)
    {
        CultureInfo info = CultureInfo.InvariantCulture;
        if (!match.Value.Contains("://"))
        {
            return string.Format(info, link, "
http://", match.Value);
        }
        else
        {
            return string.Format(info, link, string.Empty, match.Value);
        }
    }
    /// <summary>
    /// Evaluates the replacement for each @User link match.
    /// </summary>   
    public string EvaluatorUser(Match match)
    {
        CultureInfo info = CultureInfo.InvariantCulture;
        String user = Regex.Replace(match.Value, "@", "");
        return string.Format(info, link2, "
http://twitter.com/", user, match.Value);
    }
    /// <summary>
    /// Evaluates the replacement for each #Hash link match.
    /// </summary>   
    public string EvaluatorHash(Match match)
    {
        CultureInfo info = CultureInfo.InvariantCulture;
        String linktag = Regex.Replace(match.Value, "#", "%23");
        return string.Format(info, link3, "
http://search.twitter.com/search?q=", linktag, match.Value);
    }

And that should do it!

Share or Bookmark this Post…
  • E-Mail
  • TwitThis
  • Digg
  • Facebook
  • LinkedIn
  • del.icio.us
  • Google
  • MySpace
  • Ping.fm
  • StumbleUpon
  • Technorati
Categories: Development

Tags: , , , ,

BlogEngine 1.6 Released – Quick Start Help Guide

by Al Bsharah | 02.02.2010 10:34 AM | Comments (8)

BlogEngineLogoBlogEngine 1.6 was just released with substantial SPAM Filtering and Comment Management upgrades.  As well, a number of bug fixes and other new features have been included such as Multiple Widget Zones.

You should follow this upgrade process, but I’ve also added my own summary of the steps I took below.

  1. Make a backup!
  2. Copy your live web to a test web, if you have the ability to test on another URL.
  3. Download the 1.6 files on top of the 1.5 installation.
  4. Delete the ExtensionsManager folder.
  5. Change permissions on App_Data and Web.Config.
  6. If you were using Akismet before, delete the Akismet Extension (leave the new AkismetFilter Extension)
  7. Copy your original 1.5 .xml files from the App_Data folder back into the new 1.6 folder, but take care not to overwrite or delete anything new that was added.  Additionally, make sure you MERGE the settings.xml file as there were additional settings added.  The bottom line on this step?  Analyze the directories and file data to assure you're not losing anything that was added in (and required for) 1.6.
  8. Recycle or restart the web site
  9. Log in
  10. Go to the Extensions admin tab
  11. Disable the “Commentor” Extension if you were using it before (it’s now a part of the core)
  12. Enable the AkismetFilter Extension (if you were using Akismet before, make sure to enter your account information)
  13. Go to the Comments admin tab
  14. Under the Configuration sub-tab, update your settings the way you wish!
  15. Test your theme and other settings thoroughly (make sure you check your CSS in the upgrade process provided by the BE folks)
  16. If all’s well, copy the temporary site to your live site and re-test!

Enjoy the new system.  I’m curious to see if I’ll need to re-add the CAPTCHA Solution, or if this new build will mitigate most SPAM. 

How has your upgrade gone?

Share or Bookmark this Post…
  • E-Mail
  • TwitThis
  • Digg
  • Facebook
  • LinkedIn
  • del.icio.us
  • Google
  • MySpace
  • Ping.fm
  • StumbleUpon
  • Technorati

Add CAPTCHA to Your BlogEngine.NET Installation - Reduce SPAM!

by Al Bsharah | 01.24.2010 06:03 PM | Comments (0)

UPDATE 02.21.2010:  Michael's post was updated to include a minor tweak required for BlogEngine 1.6 support.

no-spamI’ve gotten a fair amount of attention regarding a post which details ways to reduce SPAM within your BlogEngine installation.  Yesterday, I received a comment from Michael Ceranski about a his adaptation of a CAPTCHA implementation

I’ve installed it here, and it seems to work quite nicely.  A well-done and seamless integration within the AJAX commenting system BlogEngine employs.

Nicely done, and THANKS!
(Check it out here if you missed the link above)

Share or Bookmark this Post…
  • E-Mail
  • TwitThis
  • Digg
  • Facebook
  • LinkedIn
  • del.icio.us
  • Google
  • MySpace
  • Ping.fm
  • StumbleUpon
  • Technorati

Controlling the Influx of SPAM on BlogEngine.NET

by Al Bsharah | 07.18.2009 06:34 PM | Comments (18)

BlogEngine.NET implements an “Invisible CAPTCHA” solution that has worked quite well for a considerable amount of time.  As of the past few weeks, those of us using BlogEngine.NET have been pelted with numerous SPAM entries, far too frequent to be human-generated.  It seemed as if someone had found their way around the CAPTCHA solution…and they have as the below video shows.

There is a lot of discussion amongst the developers of BlogEngine.NET on how to combat this, and four lines of code were added in Change Set 28194.  The four lines are below, and are added to the top of the Page_Load in CommentView.ascx.cs.

string generatedFieldName = "txtName" + DateTime.Now.Ticks.ToString();
txtName.ID = generatedFieldName;
CustomValidator1.ControlToValidate = generatedFieldName;
RequiredFieldValidator1.ControlToValidate = generatedFieldName;

The code seems to dynamically generate the submit button name, so that an automated bot can’t just post based on what it knows the submit button’s name to be.

This appears to be something that could theoretically be hacked as well, but is an easy quick fix if you’re having issues.  My understanding is that the BlogEngine.NET team is working diligently to come up with a more substantial solution.

Good luck…

Share or Bookmark this Post…
  • E-Mail
  • TwitThis
  • Digg
  • Facebook
  • LinkedIn
  • del.icio.us
  • Google
  • MySpace
  • Ping.fm
  • StumbleUpon
  • Technorati
Categories: Development

Tags: , , ,

Integrate TweetMeme Button into BlogEngine.NET

by Al Bsharah | 05.12.2009 09:03 PM | Comments (10)

UPDATE 5.13.2009:  Trying to find out why the counter is not incrementing, I know there's at least two out there...and other posts seem to work fine.

UPDATE 5.15.2009:  Appears Tweetmeme might have lost some Tweets and not aggregated them into the system, they did an upgrade and things seem to be better...  (their support response was admirably quick, too!)

Ran across a nice article on Daily Cycle called Re-Tweet Counter For BlogEngine.NET that shows how to add a TweetMeme Button to your site or blog.  This shows how many times your post has been re-tweeted, as well as allowing your readers to easily re-tweet your article.

As you can see, I’ve added the “button” to the left of the body text within each post.  As stated in the Daily Cycle post, all it takes to get up and running is a quick modification of the TweetMeme code and the PostView.aspx file in your theme.  Voila, you’re good to go.

My code is slightly different than that posted on Daily Cycle, so I’ve included it here.

<div style="float: left; padding: 10px;">
  <script type="text/javascript">
    tweetmeme_url = <%="'" %><%=Post.AbsoluteLink %><%="'" %>;
    tweetmeme_source = 'ALBsharah';
  </script>
  <script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script>
</div>

You can also add the following line for a more “compact” version of the button:

tweetmeme_style = 'compact';

Enjoy… Oh, and go click the Re-Tweet button while you’re at it!

TEST BELOW, PLEASE IGNORE:

        Dim dtForum As DataTable = ForumDatasource.IFGetAllForums

        For Each dr As DataRow In dtForum.Rows
            'C.CAT_NAME, F.CAT_ID, F.FORUM_ID, F.F_SUBJECT

            Dim cn As String = dr.Item("CAT_ID")
            Dim fi As String = dr.Item("FORUM_ID")
            Dim fs As String = dr.Item("F_SUBJECT")
            Dim fd As String = dr.Item("F_DESCRIPTION")

        Next
Share or Bookmark this Post…
  • E-Mail
  • TwitThis
  • Digg
  • Facebook
  • LinkedIn
  • del.icio.us
  • Google
  • MySpace
  • Ping.fm
  • StumbleUpon
  • Technorati

BlogEngine.NET Extension - Vimeo Video

by Al Bsharah | 11.15.2008 08:52 AM | Comments (14)

The other day I ran across an incredible video on Vimeo (will share video in an upcoming post...don't want to spoil it!)  In doing so, I realized that I needed to post it on my blog...since I'd already written a YouTube Extension / Plug-In for BlogEngine.NET, I decided to modify this to work for Vimeo and publish it as well.  Enjoy!

Yet again, I should give some credit to Sean Blakemore's Silverlight Extension, since that is what I based my YouTube Extension on.

Version history at end of this post.

So, installation is quite easy:

  1. Take this ZIP file - VimeoPlayer.zip (1.39 kb) - and extract the VimeoPlayer.cs file into your /App_Code/Extensions folder within the root of your BlogEngine installation.
  2. Log into the "Extensions" portion of your admin panel, you should see the VimeoPlayer extension.
  3. Click the Edit link to change settings.  NOTE: You do not need to modify these settings if you don't want, you can skip to step 4.
    • Width and Height are set to the default Vimeo size, but I actually run mine at a larger setting of 600 x 338.
    • Make sure you keep this "aspect ratio" of 400 x 225.  Meaning, the default ratio of 400 / 225 = 1.7778.  My new ratio of 600 / 338 = 1.775 (pretty close).  This will assure that you display wide-screen format in case the Vimeo video you imbed is Hi-Definition content.
  4. Create a new entry and add this code to your blog to insert a Vimeo video:  [ vimeo:YourVideoCodeGoesHere ]  (without the spaces).
    • Note that the "YourVideoCodeGoesHere" part is typically random numbers.  You can see them in the URL of your Vimeo video.

Below is an example of a Standard-Definition (SD) video, as well as a High-Definition (HD) video. 

That being said, the code entered for these two videos are [ vimeo:1098984 ] and [ vimeo:1674177 ]
(minus the spaces)

The SD video looks like this:

The HD video looks like this: 

Enjoy!

 

=================
VERSION HISTORY
=================

11.15.08
Version 1.0, first release
VimeoPlayer.zip (1.39 kb)

Share or Bookmark this Post…
  • E-Mail
  • TwitThis
  • Digg
  • Facebook
  • LinkedIn
  • del.icio.us
  • Google
  • MySpace
  • Ping.fm
  • StumbleUpon
  • Technorati
Categories: Development

Tags: , ,

BlogEngine.NET Extension - YouTube Video

by Al Bsharah | 10.25.2008 07:37 PM | Comments (44)

I was disappointed to see that the YouTube extension for BlogEngine was no longer available for download, so I decided to create my own.

I had recently installed Sean Blakemore's Silverlight Extension, and since I have never coded an extension for BlogEngine I figured I'd learn from a similar application.  Thanks for the head start, Sean!  I really used the base of his code and modified it to work for YouTube videos instead.

UPDATE 10.28.2008: Version 1.1 Released, instructions modified.

Version history at end of this post.

So, installation is quite easy:

  1. Take this ZIP file - YouTubePlayer-1-1.zip (1.39 kb) - and extract the YouTubePlayer.cs file into your /App_Code/Extensions folder within the root of your BlogEngine installation.
  2. Log into the "Extensions" portion of your admin panel, you should see the YouTubePlayer extension.
  3. Click the Edit link to change settings.  NOTE: You do not need to modify these settings if you don't want, you can skip to step 4.
    • Width and Height are set to the default YouTube size, you can change them if you wish but I don't believe it will change the size of the video.
    • Show Border is nice if you want to blend the video border into the color scheme of your website.  By default this is turned off (0).  Turn it on by changing the setting to "1".
    • Primary and Secondary colors are used for the border and need to be entered in Hexidecimal value.  The example below uses 709397 for the secondary (the aqua in this site) and 000000 (black) for the primary.  You can see how it looks below.
  4. Create a new entry and add this code to your blog to insert a YouTube video:  [ youtube:YourVideoCodeGoesHere ]  (without the spaces).
    • Note that the "YourVideoCodeGoesHere" part is typically random characters and letters.  You can see them in the URL of your YouTube video.

That being said, the code entered for this is [ youtube:Ddn4MGaS3N4 ]
(minus the spaces)

The video looks like this:

Enjoy!

 

=================
VERSION HISTORY
=================

10.28.2008
Version 1.1
YouTubePlayer-1-1.zip (1.39 kb) 

Change: Code used within [ youtube: ] tag is no longer the entire URL (i.e. http://www.youtube.com/v/Ddn4MGaS3N4).  On occasion, if the WYSIWYG editor set the URL as a hyperlink, the rendering of the video would fail.  Now, it's only required that the random video code is entered (i.e. Ddn4MGaS3N4)

--------

10.25.2008
Version 1.0, first release

YouTubePlayer.zip (1.36 kb)

Share or Bookmark this Post…
  • E-Mail
  • TwitThis
  • Digg
  • Facebook
  • LinkedIn
  • del.icio.us
  • Google
  • MySpace
  • Ping.fm
  • StumbleUpon
  • Technorati
Categories: Development

Tags: , ,

Powered by BlogEngine.NET 1.6.0.0
Theme by Mads Kristensen

RecentComments

Comment RSS

Calendar

<<  March 2010  >>
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Tag cloud