Q1. Does UGC have a delivery-side API?
UGC does not appear to have a documented API (I couldn't find one on SDLTridionWorld or within SDLLiveContent), other than a predefined set of server control tags. These can be found in the online documentation here.
For example:
<ugc:Comments runat="server" OrderDescending="true">
<ugc:ForEachComment runat="server">
<div class="comment"><ugc:ContextVariable var="ugcComment.content" runat="server"/></div>
</ugc:ForEachComment>
</ugc:Comments>
Looking through some other Tridion Stack Exchange answers, it appears that you may be able to use the (undocumented) classes in the Tridion.ContentDelivery.UGC
namespace to retrieve the UGC items.
Also, as can be seen in the UGC system diagram (login required), the comments are retrieved from the UGC data store via the Community Web Service
(OData). If you monitor the requests to this service then you may be able to determine the structure of the OData requests being sent and use these within your own code. This would obviously be unsupported too.
Q2. Sorting the comments
According to Changing the appearance of comments on the published Web page in the online documentation, an editor can determine whether to sort the results by:
- Chronological (or reverse chronological) order, or
- By the username of the person making the comment (alphabetically or reverse alphabetically)
However, the UGC Commands -> Comments section of the online documentation (login required) is sketchy about how this is implemented within the server control tag, and only lists a single orderDescending
(JSP or TCDL) or OrderDescending
(ASP.NET) attribute against the Comments
tag:
<ugc:Comments runat="server" OrderDescending="true">
You should be able to determine the attributes used for determining whether to sort on the username or chronologically by looking at the output of the published page (containing a configured comments section).
There does not appear to be a way to sort by "most popular" or "highest rated" (unless it is not documented)