ooto.info

Yeah, we're running GraffitiCMS!
  • rss
  • Home
  • My Social / Xbox 360
  • About Adonis
  • Theme Feedback

Sample Community Server Enhancement

Adonis, 29 Apr 2009 3:35 PM

I saw a tweet come across the other day from @adamkranitz:

adamkranitz: I would kill for "Duplicate This Post" button in Telligent CommunityServer blog software.

Hmm… I have a list…  I mean, I think I can figure that out…

So I asked @adamkranitz for some details, pulled down the Community Server 2008.5 SDK and got to work.

image I’m not a developer and you should probably consider that if you take any code off my blog but here is how I chose to solve the “Duplicate This Post” button need.

First, I’m going to do this directly in the UI of the control panel with some server-side code.  I need a “Duplicate” button on the post list page of my site.  The URL is http://localhost/CS2008.5SP1/controlpanel/blogs/postlist.aspx.  In the SDK, I looked at the contents of \source\CommunityServer.Web\ControlPanel\Blogs and found PostList.aspx and PostListControl.ascx.  I made a backup of PostListControl.ascx (an EXTREMELY important step for me…) and took a look.

So – first, I’ve got to add the button.  I noticed that there was a alternating item template in the page so I’ve got to add my button in both sections:

<cp:ResourceButton CommandArgument='<%# DataBinder.Eval(Container.DataItem, "PostID")%>' CommandName="Duplicate" OnCommand="Duplicate_Click" Runat="server" ID="DuplicateButton" Text="Duplicate" />

The CommandArgument was already there in the Delete button above where I wanted my Duplicate button so I got lucky.

The hard part of this whole thing was figuring out what attributes needed to be set to get the post to show up.  There’s a copy() method on a Post entity but I decided to set each value individually.  What I ended up with was the following:

<script runat="server">
    protected void Duplicate_Click(object sender, CommandEventArgs e)
    {
        int PostID;       
        if (int.TryParse(e.CommandArgument.ToString(), out PostID))
            DuplicatePost(PostID);
        else
            return;
    }
    private void DuplicatePost(int PostID)
    {
        WeblogPost orig = WeblogPosts.GetPost(PostID, true, false, true);
        //WeblogPost newpost = (WeblogPost)orig.Copy();

        WeblogPost newpost = new WeblogPost();
        newpost.IsApproved = false;
        newpost.Body = orig.Body;
        newpost.Subject = "Copy of " + orig.Subject;
        newpost.Categories = orig.Categories;
        newpost.PostDate = DateTime.Now;
        newpost.ThreadDate = DateTime.Now;
        newpost.UserTime = DateTime.Now;

        newpost.PostType = orig.PostType;
        //newpost.ApplicationType = orig.ApplicationType;
        newpost.BlogPostType = orig.BlogPostType;
        newpost.Name = "Copy of " + orig.Name;
        //newpost.ExtendedAttributesKeys = orig.ExtendedAttributesKeys;
        newpost.AuthorID = orig.AuthorID;
        newpost.Section = orig.Section;
        newpost.SectionID = orig.SectionID;

        WeblogPosts.Add(newpost, orig.User);
    }
</script>

By the way – to get this working, I had to open up SQL and see what was being stored in the CS_Posts table – I tweaked values in the table to get the posts showing up on the page and then fixed the code in my page to do what I knew needed to be done…

A better way to do this would probably have been through REST but that’s documented – where’s the fun in that?!?!

Ok, the file can be downloaded here if you want the whole control.

Comments
3 Comments
Tags
community-server, telligent, tech-tip

3 responses.

Leo avatar

Leo says:

23 May 2009 at 8:45 PM

Nice. So, can you share tidbits of what's coming ahead in the new CS? :)

Adonis avatar

Adonis says:

27 May 2009 at 12:42 PM

Duuuude - I'd love to - it's kickin'! But... I can't - not yet...

oes tsetnoc avatar

oes tsetnoc says:

13 Nov 2009 at 1:13 PM

Great blog, this could be the best blog I ever visited this month. Never stop to write something useful dude!

Leave a Comment

  • Tags

    christianity community-server dear-tripless devcamp estimation gaming humor mom ooto rant retirement silverlight sldc07 taxes tech tech-tip telligent themes video
  • Recent Posts

    • Tax Time – TurboTax Discount
    • Burning Algae: The Green Crude Revolution
    • Whither Journalism
    • Web 2.0 Summit Recaps – Two great session videos
    • Ordinary
  • Twitter

    • Hey @majornelson / ne1 w/ pull @ #xbox, plz add nickname/notes support to friends. I can't remember who BDub32x is... Oh! that's Kev@Work!
    • Welcome to NFL free agency!! Uncapped year, here we go.
    • @calebjenkins: "You know they have those on-line ADD tests? Yeah, I've never finished one..." #nddnug
    • Chris Patterson's presentation on Event Driven Architecture is now available: http://tr.im/nddnugeda #nddnug
    • Having green eggs and ham for diner in honor of the Suess! Hap Birt (times are tough, can't afford the whole blessing).
    • Follow Me on Twitter
Powered by Graffiti CMS
  • design by jide
  • Theme converted to GraffitiCMS by Adonis Bitar