2

Where we can find the default .net tbb code for user generated comments project. Also it would be great if someone can provide any other sample code.

Thanks in advance.

vikas kumar
  • 2,444
  • 15
  • 25

3 Answers3

10

To insert UGC comments you need to add TCDL tags, JSP tag library tags or ASP.NET Server Controls that will be resolved on Content Delivery side.

  • ASP.NET Server Control <ugc:Comments runat="server">
  • JSP Custom Tag <ugc:Comments>
  • TCDL tag <tcdl:Comments>

I suggest you to take a look at the sdllivecontent portal with 2011 documentation (login required). You will find there list of all UGC commands.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • ThanksStan.. I know all these things ... I am looking code for default UGC tbbs like "Enable User Generated Content Processing" – vikas kumar Aug 11 '12 at 09:17
  • 1
    You can always decompile .net assemly with default tbbs to C# code using .NET Reflector, ILSpy or any other decompiler. To find dll with default UGC TBBs in Tridion, open in CME Tridion.Ugc.Templating.DefaultTemplates TBB and save .net assembly to disk. Then you can open it with decompiler and get C# code of default tbbs. – Stan Kroshchenko Aug 13 '12 at 11:24
  • 1
    But of course, you wouldn't do that as it would be a breach of your license! No harm in being aware of the technique though. From a purely theoretical viewpoint, of course. – Dominic Cronin Aug 13 '12 at 13:50
4

Default UGC TBB Code, I hope will be very usefull for you.

namespace Tridion.Ugc.Templating.DefaultTemplates
{
    using System;
    using Tridion.ContentManager;
    using Tridion.ContentManager.Templating;

    public static class Helper
    {
        public static ApplicationData GetApplicationData(Engine engine, Package package)
        {
            IdentifiableObject obj2 = engine.GetObject(package.GetByType(engine.PublishingContext.ResolvedItem.IsComponentPresentation ? ContentType.Component : ContentType.Page));
            ApplicationData data = obj2.LoadApplicationData("ugc:ComponentAndPage");
            if (data == null)
            {
                TemplatingLogger.GetLogger(typeof(EnableUgcProcessing)).Warning(string.Format("No UGC application data for {0} found, UGC output will be disabled", obj2.Id));
            }
            return data;
        }
    }
}



namespace Tridion.Ugc.Templating.DefaultTemplates
{
    using System;
    using System.Text;
    using System.Xml;
    using Tridion.ContentManager;
    using Tridion.ContentManager.Templating;
    using Tridion.ContentManager.Templating.Assembly;

    [TcmTemplateTitle("Enable User Generated Content Processing")]
    public class EnableUgcProcessing : ITemplate
    {
        public void Transform(Engine engine, Package package)
        {
            ApplicationData applicationData = Helper.GetApplicationData(engine, package);
            bool flag = false;
            bool flag2 = false;
            bool flag3 = false;
            bool flag4 = false;
            string innerText = null;
            string str2 = null;
            if (applicationData != null)
            {
                XmlDocument document = new XmlDocument();
                document.LoadXml(Encoding.Unicode.GetString(applicationData.Data));
                XmlNode node = document.SelectSingleNode("*/allowtocomment");
                if (node != null)
                {
                    flag = XmlConvert.ToBoolean(node.InnerText);
                }
                node = document.SelectSingleNode("*/showcomments");
                if (node != null)
                {
                    flag2 = XmlConvert.ToBoolean(node.InnerText);
                }
                node = document.SelectSingleNode("*/allowtorate");
                if (node != null)
                {
                    flag3 = XmlConvert.ToBoolean(node.InnerText);
                }
                node = document.SelectSingleNode("*/showunmoderatedcomments");
                if (node != null)
                {
                    flag4 = XmlConvert.ToBoolean(node.InnerText);
                }
                node = document.SelectSingleNode("*/sortcomments/field");
                if (node != null)
                {
                    innerText = node.InnerText;
                }
                node = document.SelectSingleNode("*/sortcomments/direction");
                if (node != null)
                {
                    str2 = node.InnerText;
                }
            }
            Tridion.ContentManager.Templating.Item item = package.CreateStringItem(ContentType.Text, flag.ToString());
            package.PushItem("allowtocomment", item);
            item = package.CreateStringItem(ContentType.Text, flag2.ToString());
            package.PushItem("showcomments", item);
            item = package.CreateStringItem(ContentType.Text, flag3.ToString());
            package.PushItem("allowtorate", item);
            item = package.CreateStringItem(ContentType.Text, flag4.ToString());
            package.PushItem("showunmoderatedcomments", item);
            if (innerText != null)
            {
                item = package.CreateStringItem(ContentType.Text, innerText);
                package.PushItem("sortcommentsby", item);
            }
            if (str2 != null)
            {
                item = package.CreateStringItem(ContentType.Text, str2);
                package.PushItem("sortdirection", item);
            }
        }
    }
}
Shekhar Gigras
  • 654
  • 3
  • 5
  • You do realize that this is copyrighted code that you CANNOT share? – Nuno Linhares Dec 10 '12 at 13:13
  • interesting answer, could we interest you in committing to the [Area 51 Tridion specific proposal](http://area51.stackexchange.com/proposals/38335/tridion?referrer=gPujQMxthNCNn9xqeeO2NA2). Sign up with the same SO account if you have a moment. – Bart Koopman Dec 10 '12 at 13:13
1

Did you install User Generated Content when you installed Tridion on the server?

Dominic Cronin
  • 6,062
  • 2
  • 23
  • 56